Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .ai/agent-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,24 @@ the check). If it's stale, correct or delete it in the same pass rather than rep
Fix exactly what was asked. When a task names N specific findings, apply N fixes — no
unrelated cleanup, no rewriting adjacent prose "while you're in there". If you notice something
else that's wrong, say so in the HANDOFF; don't fix it silently.

## Doc verification audit

Every week, an agent runs `node scripts/doc-staleness.js --limit 3` from the
repository root and audits the listed docs against the current main commit.
For each doc, inventory every statement as TRUE, FALSE or UNVERIFIABLE.
Trace the whole flow, including callers and downstream effects, before calling
a statement false. Describe current behaviour only; do not add historical notes.

Search existing issues first with `gh issue list --repo devsuitup/switchboard --state all --search "<statement>"`.
Open one issue per wrong statement with `gh issue create --repo devsuitup/switchboard`,
or reuse the matching issue. Include the statement, the code evidence and the
correct current behaviour. An UNVERIFIABLE statement needs evidence or corrected
wording before the doc can be marked verified.

Once every statement is verified or corrected, open a PR limited to the necessary
doc fixes and advancing `verified: <sha> <YYYY-MM-DD>` in front matter. Use the
main commit actually checked and its commit date, not the future PR commit.
Keep unrelated docs unstamped. If the doc is already correct, change only its
stamp. Have the other engine cross-review the audit and corrections (Claude for
Codex work, Codex for Claude work). Repeat weekly, independently of releases.
1 change: 1 addition & 0 deletions .ai/contexts/activitywatch.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
verified: f9e691b7 2026-11-29
covers:
- "public/activity-reporting-panel.js"
- "src/main/integrations/activitywatch/activitywatch-client.js"
Expand Down
1 change: 1 addition & 0 deletions .ai/contexts/app-dialogs.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
verified: ece9003a 2026-11-29
covers:
- "public/choice-dialog.js"
- "public/resume-guard.js"
Expand Down
1 change: 1 addition & 0 deletions .ai/contexts/bg-agents.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
verified: d56a4ae3 2026-11-29
covers:
- "claude-binary.js"
- "delete-session-guard.js"
Expand Down
1 change: 1 addition & 0 deletions .ai/contexts/changes-view.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
verified: 7156c294 2026-11-29
covers:
- "public/file-panel.js"
- "src/main/changes/git-changes-file.js"
Expand Down
1 change: 1 addition & 0 deletions .ai/contexts/cli-session-state.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
verified: d6587dae 2026-11-29
covers:
- "bridge-session-id.js"
- "cli-session-state.js"
Expand Down
31 changes: 29 additions & 2 deletions .ai/contexts/fast-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
covers:
- ".husky/pre-commit"
- "Taskfile.yaml"
- "scripts/check-doc-refs.js"
- "scripts/check-docs.js"
- "scripts/*doc*.js"
- "scripts/check-fast.js"
- "scripts/run-tests.js"
---
Expand Down Expand Up @@ -79,3 +78,31 @@ The hub owner sets are deliberately narrow:

The PR template and checker accept `- no docs: <reason>` on its own line with
the exact `no-docs` label. Replace the placeholder with a nonempty reason.

## Documentation verification stamps

Coverage front matter accepts `covers` and an optional `verified` string:
`verified: a024e9ef 2026-11-29`. The SHA is 7–40 hexadecimal characters, followed
by one space and a date in YYYY-MM-DD form. The checker validates the shape,
without resolving the SHA, so shallow CI checkouts can validate docs. Other keys
remain errors. Adding or moving a stamp never satisfies the PR gate's body-change
requirement.

`node scripts/doc-staleness.js` reports tracked coverage docs from the working
tree, using the exported `coverageMap` and `isCoverageDoc` from
`scripts/check-docs.js`. The coverage map also returns each doc's optional stamp.
The report matches the same coverage patterns against the current tracked-file
list, then passes the matching paths as literal Git pathspecs to
`git rev-list --count <verified-sha>..HEAD -- <paths>`. Each commit counts once
even if it changes several covered files or patterns overlap. Empty coverage
counts zero; deleted files absent from the current tracked list are not counted.
Uncommitted code changes are outside the commit count.

Unstamped docs and unresolved commit SHAs rank first, labelled `unstamped` and
`unknown sha`, with an unknown count rather than zero. Remaining docs sort by
descending count; ties sort by doc path. `--json` emits rows with `doc`, `stamp`,
`status` and `commitsSince` (null for unknown counts); `--limit N` selects the
first N rows, and `--repo-root <dir>` selects a checkout (default: current
directory). Staleness exits zero; invalid arguments, malformed metadata and
Git failures exit nonzero. The report is advisory and does not run in the PR gate.
The weekly procedure is in [agent-practices.md](../agent-practices.md#doc-verification-audit).
1 change: 1 addition & 0 deletions .ai/contexts/panel-terminal.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
verified: a0d43823 2026-11-29
covers:
- "public/panel-terminal.js"
- "public/file-panel.js"
Expand Down
1 change: 1 addition & 0 deletions .ai/contexts/plain-terminal.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
verified: 688565ff 2026-11-29
covers:
- "src/main/terminals/plain-terminal-shell.js"
- "src/main/terminals/shell-profiles.js"
Expand Down
1 change: 1 addition & 0 deletions .ai/contexts/project-delete.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
verified: 93b54955 2026-11-29
covers:
- "derive-project-path.js"
- "public/archived-manager.js"
Expand Down
1 change: 1 addition & 0 deletions .ai/contexts/schedule-runner.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
verified: 2217ee18 2026-11-29
covers:
- "src/main/shared/normalize-project-path.js"
- "public/schedules-view.js"
Expand Down
1 change: 1 addition & 0 deletions .ai/contexts/session-state.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
verified: 944791ad 2026-11-29
covers:
- "public/index.html"
- "cli-session-state.js"
Expand Down
1 change: 1 addition & 0 deletions .ai/contexts/subagent-observability.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
verified: e52cc6ec 2026-11-29
covers:
- "public/grid-view.js"
- "public/jsonl-viewer.js"
Expand Down
1 change: 1 addition & 0 deletions .ai/contexts/terminal-path-links.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
verified: 9df983e1 2026-11-29
covers:
- "public/terminal-path-links.js"
- "src/main/terminals/terminal-path-target.js"
Expand Down
1 change: 1 addition & 0 deletions .ai/contexts/theme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
verified: a024e9ef 2026-11-29
covers:
- "public/setting-defaults.js"
- "public/style.css"
Expand Down
1 change: 1 addition & 0 deletions .ai/contexts/tool-bar.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
verified: a1d6d37a 2026-11-29
covers:
- "public/style.css"
- "public/tool-bar.js"
Expand Down
1 change: 1 addition & 0 deletions .ai/contexts/touched-files.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
verified: 32983283 2026-11-29
covers:
- "public/file-panel.js"
- "public/touched-files-view.js"
Expand Down
1 change: 1 addition & 0 deletions .ai/contexts/updater-relaunch.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
verified: 65989837 2026-11-29
covers:
- "src/main/app/linux-startup.js"
- "src/main/app/relaunch.js"
Expand Down
1 change: 1 addition & 0 deletions .ai/contexts/viewer-panel.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
verified: 8d7792bc 2026-11-29
covers:
- "file-lists-worker-client.js"
- "file-lists.js"
Expand Down
1 change: 1 addition & 0 deletions .ai/contexts/window-frame.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
verified: 62134edb 2026-11-29
covers:
- "main.js"
- "preload.js"
Expand Down
14 changes: 10 additions & 4 deletions scripts/check-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function coverPattern(glob) {

function coverageMap(documents, trackedFiles) {
const coverage = new Map();
const verified = new Map();
const errors = [];
for (const [doc, text] of Object.entries(documents)) {
if (!isCoverageDoc(doc)) continue;
Expand All @@ -58,15 +59,20 @@ function coverageMap(documents, trackedFiles) {
if (!front) throw new Error('unterminated front matter');
const data = yaml.load(front[1], { schema: yaml.JSON_SCHEMA });
if (!data || typeof data !== 'object' || Array.isArray(data)
|| Object.keys(data).some(key => key !== 'covers') || !Array.isArray(data.covers)) {
throw new Error('front matter must contain only covers: an array of source paths/globs');
|| Object.keys(data).some(key => key !== 'covers' && key !== 'verified') || !Array.isArray(data.covers)) {
throw new Error('front matter must contain only covers: an array of source paths/globs and optional verified');
}
if (Object.hasOwn(data, 'verified') && (typeof data.verified !== 'string'
|| !/^[0-9a-fA-F]{7,40} [0-9]{4}-[0-9]{2}-[0-9]{2}$/.test(data.verified))) {
throw new Error('verified must be a string matching <hex sha 7-40> <YYYY-MM-DD> with one space');
}
const patterns = data.covers.map(glob => {
const pattern = coverPattern(glob);
if (!trackedFiles.some(file => pattern.test(file))) throw new Error('covers pattern matches no tracked file: ' + glob);
return pattern;
});
coverage.set(doc, patterns);
verified.set(doc, data.verified ?? null);
} catch (err) {
errors.push(doc + ': ' + err.message);
}
Expand All @@ -75,7 +81,7 @@ function coverageMap(documents, trackedFiles) {
const owners = [...coverage].filter(([, patterns]) => patterns.some(pattern => pattern.test(file))).map(([doc]) => doc);
if (owners.length > 4) errors.push(file + ': covered by ' + owners.length + ' docs (maximum 4): ' + owners.join(', '));
}
return { coverage, errors };
return { coverage, verified, errors };
}

function checkDocs({ files, labels, body = '', documents = {}, previousDocuments = {}, trackedFiles = files }) {
Expand Down Expand Up @@ -170,4 +176,4 @@ if (require.main === module) {
}
}

module.exports = { checkDocs, coverageMap };
module.exports = { checkDocs, coverageMap, isCoverageDoc };
90 changes: 90 additions & 0 deletions scripts/doc-staleness.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env node
'use strict';

const fs = require('node:fs');
const path = require('node:path');
const { execFileSync } = require('node:child_process');
const { coverageMap, isCoverageDoc } = require('./check-docs');

const USAGE = 'usage: doc-staleness.js [--json] [--limit <positive integer>] [--repo-root <dir>]';

function parseArgs(argv) {
const opts = { repoRoot: process.cwd(), json: false };
for (let i = 0; i < argv.length; i++) {
const arg = argv[i];
if (arg === '--json') {
opts.json = true;
} else if (arg === '--limit') {
const value = argv[++i];
if (!/^[1-9][0-9]*$/.test(value) || !Number.isSafeInteger(Number(value))) throw new Error(USAGE);
opts.limit = Number(value);
} else if (arg === '--repo-root') {
const value = argv[++i];
if (!value || value.startsWith('--')) throw new Error(USAGE);
opts.repoRoot = path.resolve(value);
} else {
throw new Error(USAGE);
}
}
return opts;
}

function collectStaleness(repoRoot) {
const git = args => execFileSync('git', args, {
cwd: repoRoot, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 16 * 1024 * 1024,
}).trim();
git(['rev-parse', '--verify', 'HEAD^{commit}']);
const trackedFiles = git(['ls-files', '-z', '--cached']).split('\0').filter(Boolean);
const documents = Object.fromEntries(trackedFiles.filter(isCoverageDoc)
.filter(file => fs.existsSync(path.join(repoRoot, file)))
.map(file => [file, fs.readFileSync(path.join(repoRoot, file), 'utf8')]));
const { coverage, verified, errors } = coverageMap(documents, trackedFiles);
if (errors.length) throw new Error(errors.join('\n'));
const rows = [];
for (const [doc, patterns] of coverage) {
const stamp = verified.get(doc);
let status = 'unstamped';
let commitsSince = null;
if (stamp !== null) {
let commit;
try {
commit = git(['rev-parse', '--verify', '--quiet', stamp.split(' ')[0] + '^{commit}']);
} catch (err) {
if (err.status !== 1) throw err;
}
status = commit ? 'verified' : 'unknown sha';
if (commit) {
const files = trackedFiles.filter(file => patterns.some(pattern => pattern.test(file)));
commitsSince = files.length
? Number(git(['rev-list', '--count', commit + '..HEAD', '--', ...files.map(file => ':(literal)' + file)]))
: 0;
}
}
rows.push({ doc, stamp, status, commitsSince });
}
return rows.sort((a, b) => Number(a.commitsSince !== null) - Number(b.commitsSince !== null)
|| (b.commitsSince ?? 0) - (a.commitsSince ?? 0)
|| (a.doc < b.doc ? -1 : a.doc > b.doc ? 1 : 0));
}

function formatTable(rows) {
const cells = [['Doc', 'Stamp', 'Commits since'], ...rows.map(row => [
row.doc, row.stamp ?? 'unstamped', row.commitsSince === null ? row.status : String(row.commitsSince),
])];
const widths = [0, 1].map(column => Math.max(...cells.map(row => row[column].length)));
return cells.map(row => row[0].padEnd(widths[0]) + ' ' + row[1].padEnd(widths[1]) + ' ' + row[2]).join('\n');
}

if (require.main === module) {
try {
const opts = parseArgs(process.argv.slice(2));
const rows = collectStaleness(opts.repoRoot).slice(0, opts.limit);
console.log(opts.json ? JSON.stringify(rows, null, 2) : formatTable(rows));
process.exitCode = 0;
} catch (err) {
console.error(err.message);
process.exitCode = 2;
}
}

module.exports = { collectStaleness };
38 changes: 38 additions & 0 deletions test/check-docs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,41 @@ test('GIVEN replay 3f382b5f WHEN checking current owners THEN its documentation
const result = checkDocs({ files, labels: [], documents: realDocuments, trackedFiles: realFiles });
assert.equal(result.ok, true, result.message);
});

for (const stamp of ['abcdef0 2026-11-29', 'ABCDEF01'.repeat(5) + ' 2026-01-02']) {
test('GIVEN valid verified stamp ' + stamp + ' WHEN validating THEN it is accepted without resolving git', () => {
const result = checkDocs({ files: [], labels: [], trackedFiles: ['main.js'],
documents: { 'docs/stamped.md': '---\ncovers: ["main.js"]\nverified: ' + stamp + '\n---\n# Doc' } });
assert.equal(result.ok, true, result.message);
});
}

for (const value of ['null', 'true', '123', '[]', '{}', '""', '"abcdef 2026-11-29"',
'"' + 'a'.repeat(41) + ' 2026-11-29"', '"ghijklm 2026-11-29"', '"abcdef0 2026-1-29"',
'"abcdef0 2026-11-29"', '"abcdef0\\t2026-11-29"', '"abcdef0 2026-11-29 extra"', '" abcdef0 2026-11-29"', '"abcdef0 2026-11-29\\n"']) {
test('GIVEN malformed verified ' + value + ' WHEN validating THEN the doc and stamp reason are reported', () => {
const result = checkDocs({ files: [], labels: [], trackedFiles: ['main.js'],
documents: { 'docs/stamped.md': '---\ncovers: ["main.js"]\nverified: ' + value + '\n---\n# Doc' } });
assert.equal(result.ok, false);
assert.match(result.message, /docs\/stamped\.md: verified must be a string/);
});
}

test('GIVEN a valid verified stamp WHEN another unknown key is present THEN it is still rejected', () => {
const result = checkDocs({ files: [], labels: [], trackedFiles: ['main.js'],
documents: { 'docs/stamped.md': '---\ncovers: ["main.js"]\nverified: abcdef0 2026-11-29\nother: true\n---\n# Doc' } });
assert.equal(result.ok, false);
assert.match(result.message, /docs\/stamped\.md:.*only covers.*verified/);
});

test('GIVEN a stamp-only edit WHEN covered code changes THEN the DoD gate still requires a body change', () => {
const doc = 'docs/terminal.md';
const previousDocuments = { [doc]: TERMINAL_DOC.replace('covers:', 'verified: abcdef0 2026-11-28\ncovers:') };
const documents = { [doc]: previousDocuments[doc].replace('abcdef0 2026-11-28', '1234567 2026-11-29') };
const options = { files: ['public/terminal.js', doc], trackedFiles: ['public/terminal.js', doc], documents, previousDocuments };
const result = runCli([...REFS, '--labels', '[]'], options);
assert.equal(result.code, 1);
assert.match(result.output, /This PR changes the app without documentation/);
assert.doesNotMatch(result.output, /front matter must/);
assert.equal(runCli([...REFS, '--labels', '[]'], { ...options, documents: { [doc]: documents[doc] + '\nCorrected behavior.' } }).code, 0);
});
Loading
Loading