Skip to content

100x is a skill by a former Cursor engineer that turns prompts into formally verified, production-ready code

Fix the review findings in the verification ledger

Dead Internetce61275c1545
diff --git a/docs/cli.md b/docs/cli.md
index 06934fa..97a9fde 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -10,6 +10,7 @@ Back to the [README](../README.md).
|---|---|
| `init` | Scaffold `.100x/` in a project, keep it out of git, detect the stack. |
| `prompt` | Check the prompt in `project.md`, or print it as one text to paste into another chat. |
+| `verify` | Keep the verified properties of the code in a ledger in the project (`verify/ledger.tsv`, tracked by git), run their checks, and say which rule covers a piece of code. |
| `ref` | Print one of the suite's shared references by name, such as `100x ref apps`. A skill installed on its own reads them this way. |
| `install` | Link the skills and bootstrap `~/.100x`, or undo it. |
| `config` | Show or change settings. `config preset lite` or `medium` moves three settings for a smaller plan, `config preset standard` takes them back. |
diff --git a/lib/commands/verify.mjs b/lib/commands/verify.mjs
index 7c0c54b..6594372 100644
--- a/lib/commands/verify.mjs
+++ b/lib/commands/verify.mjs
@@ -78,6 +78,8 @@ export default {
if (!list.length) throw new CliError('the ledger holds no property to run. Add one with 100x verify add.');
let failed = 0;
for (const row of list) {
+ // The command comes from the ledger, a file in the project, like a script in package.json. Say what runs.
+ console.log('$ ' + row.command);
const result = runRow(root, row);
console.log((result.ok ? 'pass' : 'FAIL') + ' ' + row.id + '. ' + row.kind + ', ' + row.level + ', ' + result.note);
if (!result.ok) {
@@ -126,7 +128,7 @@ export default {
if (hit.length) console.log('covered ' + file + ' by ' + hit.map((row) => row.id + (row.kind === 'waived' ? ' (waived)' : '')).join(', '));
else { uncovered += 1; console.log('NO RULE ' + file); }
}
- if (sub === 'gaps' && !files.length) console.log('No changed code since ' + gaps(root, values.base).base + '.');
+ if (sub === 'gaps' && !files.length) { const { base } = gaps(root, values.base); console.log(base ? 'No changed code since ' + base + '.' : 'No code files in the project.'); }
if (uncovered) console.log('\n' + PROCEDURE);
process.exitCode = uncovered ? (sub === 'cover' ? 2 : 1) : 0;
return undefined;
diff --git a/lib/verify.mjs b/lib/verify.mjs
index 2b63e14..10c6f00 100644
--- a/lib/verify.mjs
+++ b/lib/verify.mjs
@@ -51,7 +51,9 @@ export const splitCovers = (text) => String(text ?? '').split(',').map((part) =>
function walk(root, entry, out) {
const full = path.join(root, entry);
let stat;
- try { stat = fs.statSync(full); } catch { return false; }
+ try { stat = fs.lstatSync(full); } catch { return false; }
+ // A link is not followed: a loop would walk the same folder again, and a link out of the project is not this project's code.
+ if (stat.isSymbolicLink()) return fs.existsSync(full);
if (stat.isFile()) { out.push(entry); return true; }
if (!stat.isDirectory()) return false;
for (const name of fs.readdirSync(full).sort()) {
@@ -71,8 +73,8 @@ export function hashCovers(root, covers) {
return { hash: short(hash.digest('hex')), files: files.length, missing };
}
-export function redProof(root, id) {
- const file = redFile(root, id);
+export function redProof(root, id, named) {
+ const file = named && !path.isAbsolute(named) && !named.split('/').includes('..') ? path.join(root, named) : redFile(root, id);
if (!fs.existsSync(file)) return { ok: false, why: 'no failing run in ' + rel(root, file) + '. Seed one defect in a throwaway copy of the covered code, run the check, and save the failing output there' };
const text = fs.readFileSync(file, 'utf8');
if (!/^FAIL\s+\S/m.test(text)) return { ok: false, why: rel(root, file) + ' has no FAIL line, so it does not show the check failing' };
@@ -89,7 +91,7 @@ export function rowState(root, row) {
if (now.missing.length) return { state: 'stale', why: 'covered path is gone: ' + now.missing.join(', ') };
if (now.hash !== row.covers_hash) return { state: 'stale', why: 'the covered code changed after the last sync. Read what changed, run the check, then sync' };
if (row.status !== 'holds') return { state: 'unchecked', why: 'never run' };
- const red = redProof(root, row.id);
+ const red = redProof(root, row.id, row.red);
if (!red.ok) return { state: 'unproven', why: red.why };
return { state: 'holds', why: '' };
}
@@ -129,8 +131,9 @@ export function waive(root, paths, why, now = new Date()) {
const added = [];
for (const entry of paths.flatMap(splitCovers)) {
if (!fs.existsSync(path.join(root, entry))) return { errors: ['no such path: ' + entry] };
- const id = 'waived-' + entry.replace(/[^a-z0-9]+/gi, '-').toLowerCase().replace(/^-|-$/g, '');
- if (rows.some((row) => row.id === id)) continue;
+ let id = 'waived-' + entry.replace(/[^a-z0-9]+/gi, '-').toLowerCase().replace(/^-|-$/g, '');
+ if (rows.some((row) => row.id === id && row.covers === entry)) continue;
+ for (let n = 2; rows.some((row) => row.id === id); n += 1) id = id.replace(/-\d+$/, '') + '-' + n;
rows.push({ id, kind: 'waived', property: reason, covers: entry, covers_hash: hashCovers(root, [entry]).hash, command: '', level: '', red: '', status: 'waived', checked_at: timestamp(now), commit: headShort(root), ran_hash: '' });
appendHistory(root, { id, event: 'waive', commit: headShort(root), hash: '', note: reason, result: 'waived' }, now);
added.push(id);
@@ -143,7 +146,10 @@ export function waive(root, paths, why, now = new Date()) {
// describes new code, only that the old description still holds. sync is the step that says someone read the change.
export function runRow(root, row, { timeoutMs = 600000, now = new Date() } = {}) {
const started = Date.now();
- const result = spawnSync('sh', ['-c', row.command], { cwd: root, encoding: 'utf8', timeout: timeoutMs, maxBuffer: 64 * 1024 * 1024, env: { ...process.env, NODE_TEST_CONTEXT: '' } });
+ // The command is the shell's, so it works with the shell of the machine. NODE_TEST_CONTEXT is removed so a check that uses node --test is not read as part of this process's own test run.
+ const env = { ...process.env };
+ delete env.NODE_TEST_CONTEXT;
+ const result = spawnSync(row.command, { shell: true, cwd: root, encoding: 'utf8', timeout: timeoutMs, killSignal: 'SIGKILL', maxBuffer: 64 * 1024 * 1024, env });
const output = (result.stdout ?? '') + (result.stderr ?? '');
let ok = result.status === 0;
let note = ok ? 'exit 0' : result.error?.code === 'ETIMEDOUT' ? 'timed out after ' + Math.round(timeoutMs / 1000) + ' s' : 'exit ' + result.status;
@@ -198,12 +204,26 @@ export function retireRow(root, id, why, now = new Date()) {
export const covering = (rows, file) => rows.filter((row) => splitCovers(row.covers).some((entry) => file === entry || file.startsWith(entry + '/')));
// Code that changed on this branch since base, that a reader would expect a rule for. Tests, config and the ledger itself are left out.
+// On the main branch, or with no main to compare with, there is no branch to diff, and code that was committed is as much without a rule as code
+// that was not. Then the whole project counts. The base is null and the messages say "in the project". On another branch, or with --base, only
+// what changed since the base counts.
export function changedCode(root, base) {
- const ref = base ?? ['main', 'master'].find((name) => git(root, ['rev-parse', '--verify', '--quiet', name]) !== null) ?? 'HEAD';
- const mergeBase = ref === 'HEAD' ? 'HEAD' : git(root, ['merge-base', ref, 'HEAD']) ?? ref;
- const changed = (git(root, ['diff', '--name-only', mergeBase]) ?? '').split('\n');
+ const main = ['main', 'master'].find((name) => git(root, ['rev-parse', '--verify', '--quiet', name]) !== null);
+ const branch = git(root, ['rev-parse', '--abbrev-ref', 'HEAD']);
+ const whole = base === undefined && (!main || branch === main || branch === 'HEAD');
+ const ref = base ?? main ?? null;
+ const mergeBase = whole ? null : git(root, ['merge-base', ref, 'HEAD']) ?? ref;
+ const listed = whole ? (git(root, ['ls-files']) ?? '').split('\n') : (git(root, ['diff', '--name-only', mergeBase]) ?? '').split('\n');
const fresh = (git(root, ['ls-files', '--others', '--exclude-standard']) ?? '').split('\n');
- return { base: ref, files: [...new Set([...changed, ...fresh])].filter((file) => file && CODE.test(file) && !TEST_FILE.test(file) && !file.startsWith('verify/') && !file.split('/').some((part) => SKIP_DIRS.has(part)) && fs.existsSync(path.join(root, file))).sort() };
+ const wanted = (file) => file && CODE.test(file) && !TEST_FILE.test(file) && !file.startsWith('verify/') && !file.split('/').some((part) => SKIP_DIRS.has(part)) && fs.existsSync(path.join(root, file));
+ return { base: whole ? null : ref, files: [...new Set([...listed, ...fresh])].filter(wanted).sort() };
+}
+
+// The code files a waiver covers. A waiver says nothing there can be stated, so the report names how much it excuses.
+export function waivedCode(root, rows) {
+ const files = [];
+ for (const row of rows.filter((item) => item.kind === 'waived')) walk(root, splitCovers(row.covers)[0] ?? '', files);
+ return [...new Set(files)].filter((file) => CODE.test(file) && !TEST_FILE.test(file)).sort();
}
export function gaps(root, base) {
@@ -212,7 +232,7 @@ export function gaps(root, base) {
return { base: used, files, uncovered: files.filter((file) => covering(rows, file).length === 0) };
}
-export const PROCEDURE = 'No rule covers this code, so start the verification procedure: read skills/100x/references/properties.md (100x ref properties). Extract what can exist (state), how it changes (transitions), when a step is allowed (preconditions), what is true after it (postconditions), what always holds (invariants) and what must eventually happen under stated assumptions (liveness). Check them with assets/property-checker.mjs or a tool that fits, show each fail on a seeded defect, then 100x verify add. Code with no rule to extract, such as layout or copy, gets 100x verify waive with the reason.';
+export const PROCEDURE = 'No rule covers this code, so start the verification procedure: run `100x ref properties` and follow it. Extract what can exist (state), how it changes (transitions), when a step is allowed (preconditions), what is true after it (postconditions), what always holds (invariants) and what must eventually happen under stated assumptions (liveness). Check them with the property checker from the 100x skill (skills/100x/assets/property-checker.mjs) or a tool that fits, show each fail on a seeded defect, then 100x verify add. Code with no rule to extract, such as layout or copy, gets 100x verify waive with the reason.';
// What 100x finish asks of the ledger. required is 'properties' when the one thing that must not break is its properties (a real property is
// needed), 'any' when property checks are on (a property or a waiver with its reason is needed), or false when the owner switched them off.
@@ -230,10 +250,12 @@ export function checkLedger(root, { required = false, base } = {}) {
if (rows.length || required) {
const found = gaps(root, base);
if (found.uncovered.length) {
- const text = found.uncovered.length + ' changed code file' + (found.uncovered.length === 1 ? ' has' : 's have') + ' no rule and no waiver since ' + found.base + ': ' + found.uncovered.slice(0, 6).join(', ') + (found.uncovered.length > 6 ? ' and ' + (found.uncovered.length - 6) + ' more' : '') + '. 100x verify gaps says what to do';
+ const text = found.uncovered.length + ' changed code file' + (found.uncovered.length === 1 ? ' has' : 's have') + ' no rule and no waiver ' + (found.base ? 'since ' + found.base : 'in the project') + ': ' + found.uncovered.slice(0, 6).join(', ') + (found.uncovered.length > 6 ? ' and ' + (found.uncovered.length - 6) + ' more' : '') + '. 100x verify gaps says what to do';
if (required === 'properties') errors.push(text);
else warnings.push(text);
}
}
+ const waived = waivedCode(root, rows);
+ if (waived.length) warnings.push(waived.length + ' code file' + (waived.length === 1 ? ' is' : 's are') + ' waived, so no property was written for ' + (waived.length === 1 ? 'it' : 'them') + ': ' + waived.slice(0, 6).join(', ') + (waived.length > 6 ? ' and ' + (waived.length - 6) + ' more' : '') + '. Say so in the report');
return { errors, warnings, rows };
}
diff --git a/skills/100x/assets/property-checker.mjs b/skills/100x/assets/property-checker.mjs
index aeb2b3d..efe6200 100644
--- a/skills/100x/assets/property-checker.mjs
+++ b/skills/100x/assets/property-checker.mjs
@@ -299,13 +299,12 @@ function checkLiveness(property) {
if (closed && members.every((v) => !goal[v])) for (const v of members) seeds.add(v);
});
} else {
- const { comp, comps } = components((v) => !goal[v]);
+ const { comps } = components((v) => !goal[v]);
comps.forEach((members) => {
const loops = members.length > 1 || out[members[0]].some(([, w]) => w === members[0]);
if (loops) for (const v of members) seeds.add(v);
});
states.forEach((_, v) => { if (!goal[v] && out[v].length === 0) seeds.add(v); });
- void comp;
}
// Every state that can reach a seed without passing through to.
const doomed = new Set(seeds);
diff --git a/skills/100x/references/properties.md b/skills/100x/references/properties.md
index d09c3fb..37b946a 100644
--- a/skills/100x/references/properties.md
+++ b/skills/100x/references/properties.md
@@ -58,6 +58,7 @@ The ledger (`verify/ledger.tsv`, tracked by git) and the log (`verify/history.ts
- **The promise changed on purpose.** `100x verify amend <id> --evidence "<commit, test or doc>" --property "<new sentence>"`. The old wording and the evidence go to the log, and the row is unchecked until it runs again. A property is never edited in place to get green.
- **No longer applies.** `100x verify retire <id> --why "<reason>"`.
- A green run does not move the hash. Only `sync` does, and it needs a green run and a written note.
+- `100x verify run` runs the `command` of each row, as `npm test` runs a script of package.json. It prints the command first. Read the ledger of a project you did not write before you run it. `status`, `cover` and `gaps` run nothing, and neither does `100x finish`.
## Report it
diff --git a/test/verify.test.mjs b/test/verify.test.mjs
index 16616f2..90cd922 100644
--- a/test/verify.test.mjs
+++ b/test/verify.test.mjs
@@ -27,7 +27,8 @@ test('a property is unchecked until it runs, unproven until it has failed once,
const run = verify(box, 'run');
assert.equal(run.code, 0, run.out);
- assert.match(run.out, /^pass {2}order-money\. invariant, exhaustive, exit 0/);
+ assert.match(run.out, /^pass {2}order-money\. invariant, exhaustive, exit 0/m);
+ assert.match(run.out, /^\$ node verify\/check\.mjs/m, 'the command that runs is printed first');
const unproven = verify(box, 'status');
assert.match(unproven.out, /^unproven +order-money.*no failing run in verify\/red\/order-money\.txt/);
assert.equal(unproven.code, 1);
@@ -83,7 +84,7 @@ test('a failing check is broken, and an exhaustive claim is refused when the che
verify(box, 'amend', 'order-money', '--evidence', 'the model is too big for a full search, commit abc1234', '--level', 'bounded');
const honest = verify(box, 'run');
assert.equal(honest.code, 0, honest.out);
- assert.match(honest.out, /^pass {2}order-money\. invariant, bounded, exit 0/);
+ assert.match(honest.out, /^pass {2}order-money\. invariant, bounded, exit 0/m);
assert.match(verify(box, 'status').out, /^holds +order-money +invariant, bounded/);
box.cleanup();
});
@@ -116,7 +117,7 @@ test('code with no rule starts the procedure, and a waiver or a property ends th
const cover = verify(box, 'cover', 'src/rules.mjs');
assert.equal(cover.code, 2);
assert.match(cover.out, /^NO RULE {2}src\/rules\.mjs/m);
- assert.match(cover.out, /No rule covers this code, so start the verification procedure: read skills\/100x\/references\/properties\.md/);
+ assert.match(cover.out, /No rule covers this code, so start the verification procedure: run `100x ref properties` and follow it/);
const gaps = verify(box, 'gaps');
assert.equal(gaps.code, 1);
@@ -161,7 +162,6 @@ test('the planner asks for Properties by default, and the owner can turn that of
assert.notEqual(without, PROMPT_MD);
const box = sandbox();
makeProject(box, { projectMd: without, prompted: true, ledger: false });
- const env = { ...process.env, ...box.env };
const keep = Object.fromEntries(Object.keys(box.env).map((key) => [key, process.env[key]]));
Object.assign(process.env, box.env);
try {
@@ -180,11 +180,39 @@ test('the planner asks for Properties by default, and the owner can turn that of
assert.deepEqual(checkPrompt(box.project).problems, []);
} finally {
for (const [key, value] of Object.entries(keep)) { if (value === undefined) delete process.env[key]; else process.env[key] = value; }
- void env;
box.cleanup();
}
});
+test('code that was committed on main with no rule is a gap, so a project built by committing as it goes is not let through', () => {
+ const { box, add } = project();
+ sh(box.project, 'git init -q -b main && git config user.email t@t && git config user.name t');
+ write(path.join(box.project, 'src', 'rules.mjs'), 'export const fee = (c) => Math.floor(c * 0.03);\n');
+ sh(box.project, 'git add -A && git commit -qm all');
+ const whole = verify(box, 'gaps');
+ assert.equal(whole.code, 1, whole.out);
+ assert.match(whole.out, /NO RULE {2}src\/rules\.mjs/);
+ assert.match(checkLedger(box.project, { required: 'properties' }).errors.join('\n'), /no rule and no waiver in the project: .*src\/rules\.mjs/);
+ assert.equal(verify(box, 'gaps', '--base', 'main').out.includes('src/rules.mjs'), false, 'with --base the diff against that branch decides, and main against itself is empty');
+ box.cleanup();
+});
+
+test('a waiver is named in the report with the code it excuses, two paths never share an id, and a link loop is not walked', () => {
+ const { box } = project();
+ write(path.join(box.project, 'src', 'a-b.mjs'), 'export const a = 1;\n');
+ write(path.join(box.project, 'src', 'a', 'b.mjs'), 'export const b = 2;\n');
+ assert.equal(verify(box, 'waive', 'src/a-b.mjs', 'src/a', '--why', 'constants, nothing to state').code, 0);
+ const ids = readLedger(box.project).map((row) => row.id);
+ assert.equal(new Set(ids).size, ids.length, ids.join());
+ assert.equal(ids.length, 2);
+ const warning = checkLedger(box.project, { required: 'any' }).warnings.join('\n');
+ assert.match(warning, /2 code files are waived, so no property was written for them: src\/a-b\.mjs, src\/a\/b\.mjs\. Say so in the report/);
+ fs.symlinkSync('..', path.join(box.project, 'src', 'a', 'loop'));
+ const hashed = hashCovers(box.project, ['src']);
+ assert.equal(hashed.files, 2, 'the link is not followed');
+ box.cleanup();
+});
+
test('the pre-flight tells the owner what will be checked, inside its twelve lines', () => {
const open = fs.readFileSync(path.join(ROOT, 'skills', '100x', 'references', 'open.md'), 'utf8');
const router = fs.readFileSync(path.join(ROOT, 'skills', '100x', 'SKILL.md'), 'utf8');