@sddio/cli 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -40
- package/dist/agents.js +3 -1
- package/dist/brief.js +104 -0
- package/dist/check.js +109 -0
- package/dist/claims.js +60 -0
- package/dist/cli.js +222 -21
- package/dist/cursor.js +65 -0
- package/dist/events.js +37 -0
- package/dist/hooks.js +68 -0
- package/dist/init.js +62 -7
- package/dist/prompt.js +13 -11
- package/dist/repo.js +93 -0
- package/dist/workspace.js +3 -8
- package/package.json +3 -3
- package/templates/.sddio/context/README.md +0 -1
- package/templates/.sddio/context/config.json +14 -3
- package/templates/.sddio/context/instructions/adr.md +7 -0
- package/templates/.sddio/context/instructions/bootstrap.md +28 -16
- package/templates/.sddio/context/instructions/entries.md +10 -0
- package/templates/.sddio/context/instructions/reconciliation.md +12 -12
- package/templates/.sddio/context/instructions/spec.md +15 -0
- package/templates/.sddio/context/instructions.md +35 -120
- package/templates/.sddio/context/routes/routes.md +3 -2
- package/templates/.sddio/context/writing.md +80 -0
- package/dist/skill.js +0 -18
- package/templates/.sddio/context/instructions/flow.md +0 -45
- package/templates/.sddio/context/principles.md +0 -46
- package/templates/.sddio/skill/SKILL.md +0 -33
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**Spec-driven development for coding agents, kept in your repo.**
|
|
4
4
|
|
|
5
|
-
`sddio` writes a context layer and a workspace into a project, then hands your agent the first instruction it needs. All of it is plain Markdown committed with your code: what the project requires (`SPEC`), why it's built this way (`ADR`), what's still unresolved (`DISCUSSION`)
|
|
5
|
+
`sddio` writes a context layer and a workspace into a project, then hands your agent the first instruction it needs. All of it is plain Markdown committed with your code: what the project requires (`SPEC`), why it's built this way (`ADR`), and what's still unresolved (`DISCUSSION`). Work in progress is deliberately not one of them — that belongs to your board.
|
|
6
6
|
|
|
7
7
|
[Repository](https://github.com/benxgao/sddio) · [FAQ](https://github.com/benxgao/sddio/blob/master/docs/faq.md) · [How it works](https://github.com/benxgao/sddio#readme) · Node ≥ 18 · MIT
|
|
8
8
|
|
|
@@ -28,19 +28,20 @@ This project has just been initialised with sddio. Before any other work:
|
|
|
28
28
|
|
|
29
29
|
1. Run the commit check in `.sddio/context/instructions/reconciliation.md`.
|
|
30
30
|
`config.json` has no baseline yet, so the state is `unknown`.
|
|
31
|
-
2. Bootstrap
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
2. Bootstrap as described in `instructions/bootstrap.md`, but do not describe the
|
|
32
|
+
code back to me. Record only what the repository cannot say: a reversed
|
|
33
|
+
decision and why, an outside constraint and its deadline, an abandoned path.
|
|
34
|
+
At most six SPEC entries, each ending with `Not in the code:`.
|
|
35
|
+
3. Ask me up to three questions whose answers would change future work, and
|
|
36
|
+
record at least one DISCUSSION (SPEC-016) for what stays open.
|
|
37
|
+
4. Report what you recorded, then set `reconcileCursor.lastProcessedCommit` to
|
|
38
|
+
`HEAD` and `reconcileCursor.previousCommit` to `HEAD^` in
|
|
39
|
+
`.sddio/context/config.json` (`null` at a root commit).
|
|
39
40
|
|
|
40
41
|
Then answer this: <your first task>
|
|
41
42
|
```
|
|
42
43
|
|
|
43
|
-
Finally, commit `.sddio/` and `
|
|
44
|
+
Finally, commit `.sddio/` and `sddio_docs/` together with your next change. That's the whole install. `init` writes nothing outside the project, doesn't touch an agent's config directory, and runs no git command.
|
|
44
45
|
|
|
45
46
|
## What `init` prints
|
|
46
47
|
|
|
@@ -58,24 +59,39 @@ npm install --save-dev @sddio/cli@latest
|
|
|
58
59
|
npx sddio init
|
|
59
60
|
```
|
|
60
61
|
|
|
61
|
-
`.sddio/` is refreshed in place, and `
|
|
62
|
+
`.sddio/` is refreshed in place, and `sddio_docs/` is left alone. `init` then prints the reconcile prompt, so paste it in and let the agent update only the artefacts the upgrade affects. An upgrade resets the reconciliation cursor to `null`, so this step isn't optional. Without it the workspace stays `unknown` and every session re-checks from scratch.
|
|
63
|
+
|
|
64
|
+
One field survives the refresh: the `hooks` array in `.sddio/context/config.json`. An upgrade must not silently re-wire the project to a caller it abandoned, so `init` keeps the declared hooks and only replaces the rest of the file.
|
|
62
65
|
|
|
63
66
|
## Commands
|
|
64
67
|
|
|
65
68
|
```text
|
|
66
|
-
sddio init [--dir <path>] [--force] [--dry-run]
|
|
67
|
-
sddio
|
|
69
|
+
sddio init [--dir <path>] [--hook <name>] [--no-install] [--yes] [--force] [--dry-run]
|
|
70
|
+
sddio start [<path>...] # cursor, hint and brief in one call
|
|
71
|
+
sddio brief [<path>...] # entries that name those paths
|
|
72
|
+
sddio show <id> # one entry, body included
|
|
73
|
+
sddio check [--json] # behind HEAD? did a moved file go unrecorded?
|
|
74
|
+
sddio diff [--json] # the worklist: what each moved file touches
|
|
68
75
|
```
|
|
69
76
|
|
|
70
77
|
| Command / flag | Effect |
|
|
71
78
|
| -------------- | ------ |
|
|
72
|
-
| `init` | Create `.sddio/`, `
|
|
73
|
-
| `
|
|
79
|
+
| `init` | Create `.sddio/`, `sddio_docs/` and the seed collections; register `AGENTS.md`; ask which hook to use; print the next step |
|
|
80
|
+
| `start` | The one call a hook makes: cursor state, a hint, and a brief, in ten lines or fewer |
|
|
81
|
+
| `brief` | Titles of the entries that name the given paths. Reads nothing else |
|
|
82
|
+
| `show` | One entry by ID, body included |
|
|
83
|
+
| `check` | Cursor state plus the files nobody wrote about. Exits 1 when behind, for CI |
|
|
84
|
+
| `diff` | Which entries name a moved file, and which files nobody named. Prints; never writes |
|
|
74
85
|
| `--dir <path>` | Target project root (default: current directory) |
|
|
75
|
-
| `--
|
|
86
|
+
| `--hook <name>` | `flow-trail` (default) or `none`. Naming one installs it unless `--no-install` is given |
|
|
87
|
+
| `--no-install` | Declare the hook in `config.json` without running its installer |
|
|
88
|
+
| `--yes` | Take the default hook without asking, and install it |
|
|
89
|
+
| `--force` | Overwrite existing files, including `sddio_docs/` seeds |
|
|
76
90
|
| `--dry-run` | Report what would change without writing |
|
|
77
91
|
|
|
78
|
-
|
|
92
|
+
With a terminal attached, `init` asks one question: which hook should keep the workspace current. The default is `flow-trail`, and choosing it runs flow-trail's own bootstrap in the target project — a card board in `flow-trail/`, a pointer in `AGENTS.md`. `--yes` gives the same answer without the question, so a script that wants the default spells it `--yes`; `--no-install` is the CI escape when the fetch must not happen. A project that has already answered is not asked again, and an upgrade never re-downloads the hook.
|
|
93
|
+
|
|
94
|
+
`.sddio/` belongs to the package and gets refreshed on init. `sddio_docs/` is yours and is only touched with `--force`. A run that finds everything up to date reports all files as skipped.
|
|
79
95
|
|
|
80
96
|
`--force` resets the workspace seeds to empty files — it is meant for re-initialising a project, not for merging.
|
|
81
97
|
|
|
@@ -83,35 +99,16 @@ sddio skill --print
|
|
|
83
99
|
|
|
84
100
|
```text
|
|
85
101
|
.sddio/ # context layer, identical to the sddio repository's own .sddio/
|
|
86
|
-
context
|
|
87
|
-
|
|
102
|
+
context/ # instructions, schema, routes, preferences, roadmap, writing
|
|
103
|
+
sddio_docs/ # the user's workspace: layout only, empty seeds
|
|
88
104
|
spec/spec_100.md # → 0 bytes
|
|
89
105
|
adr/adr_100.md # → 0 bytes
|
|
90
106
|
discussions/discussions_100.md
|
|
91
|
-
flow/active/template.md
|
|
92
|
-
flow/completed/ # empty directories, created explicitly
|
|
93
|
-
flow/reconciliation/
|
|
94
107
|
AGENTS.md # sddio snippet appended, existing content preserved
|
|
95
108
|
```
|
|
96
109
|
|
|
97
110
|
The workspace ships no starter prose on purpose. It belongs to your project, and placeholder text would be rewritten immediately anyway. See ADR-005 in the sddio repository.
|
|
98
111
|
|
|
99
|
-
## Agent skill
|
|
100
|
-
|
|
101
|
-
Agents that support skills can discover sddio without reading `AGENTS.md` first. `skill --print` writes the skill to stdout and nothing else; hints go to stderr, so it can be redirected straight into a skills directory:
|
|
102
|
-
|
|
103
|
-
```bash
|
|
104
|
-
# your agent's skills directory — the CLI neither knows nor guesses it
|
|
105
|
-
SKILLS_DIR="$HOME/.config/your-agent/skills"
|
|
106
|
-
|
|
107
|
-
mkdir -p "$SKILLS_DIR/sddio"
|
|
108
|
-
npx sddio skill --print > "$SKILLS_DIR/sddio/SKILL.md"
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
The skill is a router, not a copy of the rules. It names the paths, the invariants and the `grep` that lists entries, then hands the detail to `.sddio/context/instructions.md`, so an upgraded context layer doesn't invalidate it.
|
|
112
|
-
|
|
113
|
-
The CLI never scans or writes agent configuration directories, and never edits files outside the project. `init` also leaves the file at `.sddio/skill/SKILL.md`, so you can copy it without running anything.
|
|
114
|
-
|
|
115
112
|
## Requirements
|
|
116
113
|
|
|
117
114
|
- Node ≥ 18. No Python, no global install.
|
|
@@ -119,11 +116,11 @@ The CLI never scans or writes agent configuration directories, and never edits f
|
|
|
119
116
|
|
|
120
117
|
## Questions
|
|
121
118
|
|
|
122
|
-
**Does it need a specific agent?** No. `init` writes `AGENTS.md` and nothing else agent-specific; any agent that reads repository files works, and the prompt it prints is plain text.
|
|
119
|
+
**Does it need a specific agent?** No. `init` writes `AGENTS.md` and nothing else agent-specific; any agent that reads repository files works, and the prompt it prints is plain text. No skill is installed and no agent configuration directory is read or written.
|
|
123
120
|
|
|
124
121
|
**Does it send anything anywhere?** No account, no server, no telemetry, no update check. It reads and writes files inside the target directory and runs no git command.
|
|
125
122
|
|
|
126
|
-
**What does it not do?** It does not write code, search or index the workspace, or enforce its rules
|
|
123
|
+
**What does it not do?** It does not write code, search or index the workspace, or enforce its rules on its own. `check` can fail CI when knowledge falls behind `HEAD`, but nothing can decide whether an entry still says the right thing — that stays the agent's reading. Entries are Markdown; `grep` is the query language.
|
|
127
124
|
|
|
128
125
|
See [`docs/faq.md`](https://github.com/benxgao/sddio/blob/master/docs/faq.md) for the rest.
|
|
129
126
|
|
package/dist/agents.js
CHANGED
|
@@ -9,7 +9,9 @@ export const AGENTS_BEGIN = '<!-- sddio:begin -->';
|
|
|
9
9
|
export const AGENTS_END = '<!-- sddio:end -->';
|
|
10
10
|
export const AGENTS_SNIPPET = [
|
|
11
11
|
AGENTS_BEGIN,
|
|
12
|
-
'This project uses sddio
|
|
12
|
+
'This project uses sddio: the repository keeps what the code cannot say.',
|
|
13
|
+
'Run `npx sddio start` before changing code — it prints the entries that constrain this work.',
|
|
14
|
+
'Read only what it names. No command? Read `.sddio/context/instructions.md` instead.',
|
|
13
15
|
AGENTS_END,
|
|
14
16
|
].join('\n');
|
|
15
17
|
export function ensureAgentsSnippet(existing) {
|
package/dist/brief.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sddio brief` — the answering half (P1).
|
|
3
|
+
*
|
|
4
|
+
* One screen, computed from the workspace: what the cursor says, which entries
|
|
5
|
+
* name the paths in front of you, and which paths nobody has written about. It
|
|
6
|
+
* reads; it never decides, and it never prints a body — `show <id>` is one
|
|
7
|
+
* keystroke away and half of progressive disclosure is making that the default.
|
|
8
|
+
*/
|
|
9
|
+
import { cursor, describe } from './cursor.js';
|
|
10
|
+
import { entryNames, readConfig, readEntries } from './repo.js';
|
|
11
|
+
const BUDGET = 60;
|
|
12
|
+
const PER_PATH = 3;
|
|
13
|
+
const WIDTH = 58;
|
|
14
|
+
function trimming(text, width = WIDTH) {
|
|
15
|
+
return text.length > width ? `${text.slice(0, width - 1)}…` : text;
|
|
16
|
+
}
|
|
17
|
+
function row(kind, entry) {
|
|
18
|
+
return `${kind.padEnd(8)}${entry.id.padEnd(10)}${trimming(entry.title)}`.trimEnd();
|
|
19
|
+
}
|
|
20
|
+
/** `load` on the first row of a group, blanks after it, so columns line up. */
|
|
21
|
+
function group(label, index, rest) {
|
|
22
|
+
return `${(index === 0 ? label : '').padEnd(8)}${rest}`.trimEnd();
|
|
23
|
+
}
|
|
24
|
+
function counts(entries) {
|
|
25
|
+
const spec = entries.filter((entry) => entry.kind === 'SPEC').length;
|
|
26
|
+
const adr = entries.filter((entry) => entry.kind === 'ADR').length;
|
|
27
|
+
const disc = entries.filter((entry) => entry.kind === 'DISC').length;
|
|
28
|
+
return `${spec} SPEC, ${adr} ADR, ${disc} DISC`;
|
|
29
|
+
}
|
|
30
|
+
/** Entries with the most inbound references: the load-bearing ones. */
|
|
31
|
+
function loadBearing(entries) {
|
|
32
|
+
const inbound = new Map();
|
|
33
|
+
for (const entry of entries) {
|
|
34
|
+
for (const ref of entry.refs) {
|
|
35
|
+
inbound.set(ref, (inbound.get(ref) ?? 0) + 1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return [...inbound.entries()]
|
|
39
|
+
.sort((a, b) => b[1] - a[1])
|
|
40
|
+
.slice(0, 3)
|
|
41
|
+
.map(([id]) => entries.find((entry) => entry.id === id))
|
|
42
|
+
.filter((entry) => entry !== undefined);
|
|
43
|
+
}
|
|
44
|
+
function openQuestions(entries) {
|
|
45
|
+
return entries.filter((entry) => entry.kind === 'DISC' && entry.status !== 'resolved').slice(0, 2);
|
|
46
|
+
}
|
|
47
|
+
export function renderBrief(root, paths, options = {}) {
|
|
48
|
+
const targets = paths.filter((path) => path !== '.' && path !== './');
|
|
49
|
+
const entries = readEntries(root);
|
|
50
|
+
const state = cursor(root, readConfig(root));
|
|
51
|
+
const lines = [];
|
|
52
|
+
const ids = [];
|
|
53
|
+
const stale = state.state === 'behind' || state.state === 'rewritten' || state.state === 'lost';
|
|
54
|
+
lines.push(`${(options.label ?? 'brief').padEnd(6)} ${targets.length === 0 ? '.' : targets.join(' ')}`);
|
|
55
|
+
lines.push(`cursor ${describe(state)}`);
|
|
56
|
+
if (options.hint === true && stale) {
|
|
57
|
+
lines.push('hint sddio diff lists what moved and which entry names it');
|
|
58
|
+
}
|
|
59
|
+
if (targets.length === 0) {
|
|
60
|
+
lines.push(`entries ${counts(entries)}`);
|
|
61
|
+
for (const [index, entry] of loadBearing(entries).entries()) {
|
|
62
|
+
const count = entry.refs.length;
|
|
63
|
+
const refs = count === 0 ? '' : ` (${count} ref${count === 1 ? '' : 's'})`;
|
|
64
|
+
lines.push(group('load', index, `${entry.id.padEnd(10)}${trimming(entry.title, 40)}${refs}`));
|
|
65
|
+
ids.push(entry.id);
|
|
66
|
+
}
|
|
67
|
+
for (const [index, entry] of openQuestions(entries).entries()) {
|
|
68
|
+
lines.push(group('open', index, `${entry.id.padEnd(10)}${trimming(entry.title, 44)}`));
|
|
69
|
+
ids.push(entry.id);
|
|
70
|
+
}
|
|
71
|
+
if (entries.length > 0) {
|
|
72
|
+
lines.push('');
|
|
73
|
+
lines.push('read `sddio brief <path>` for the files you are about to touch');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
const unnamed = [];
|
|
78
|
+
for (const path of targets) {
|
|
79
|
+
const matched = entries
|
|
80
|
+
.filter((entry) => entryNames(entry, path))
|
|
81
|
+
.filter((entry) => !ids.includes(entry.id))
|
|
82
|
+
.slice(0, PER_PATH);
|
|
83
|
+
if (matched.length === 0) {
|
|
84
|
+
unnamed.push(path);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
for (const entry of matched) {
|
|
88
|
+
lines.push(row(entry.kind.toLowerCase(), entry));
|
|
89
|
+
ids.push(entry.id);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
for (const path of unnamed) {
|
|
93
|
+
lines.push(`none ${path}`);
|
|
94
|
+
}
|
|
95
|
+
if (ids.length === 0 && unnamed.length > 0) {
|
|
96
|
+
lines.push(' nothing names these; if it matters, that is an entry nobody wrote');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return { text: `${lines.slice(0, options.budget ?? BUDGET).join('\n')}\n`, ids };
|
|
100
|
+
}
|
|
101
|
+
export function renderEntry(entry) {
|
|
102
|
+
const refs = entry.refs.length === 0 ? '' : `refs: ${entry.refs.join(', ')}\n\n`;
|
|
103
|
+
return `## ${entry.id} ${entry.title}\n\n${refs}${entry.body}\n`;
|
|
104
|
+
}
|
package/dist/check.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sddio check` and `sddio diff` — the accusing half (P2, P3).
|
|
3
|
+
*
|
|
4
|
+
* Both read the same three facts: the cursor, the files that moved since it, and
|
|
5
|
+
* the entries that name those files. `check` turns that into an exit code for CI;
|
|
6
|
+
* `diff` turns it into a worklist and stops there. Neither writes.
|
|
7
|
+
*/
|
|
8
|
+
import { execFileSync } from 'node:child_process';
|
|
9
|
+
import { cursor, describe } from './cursor.js';
|
|
10
|
+
import { entryNames, readConfig, readEntries } from './repo.js';
|
|
11
|
+
/** Files that are never "unmentioned": the workspace and the board document themselves. */
|
|
12
|
+
const NOT_CODE = /^(sddio_docs|flow-trail|\.sddio)\//;
|
|
13
|
+
function git(root, args) {
|
|
14
|
+
try {
|
|
15
|
+
return execFileSync('git', args, { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** The commits a reconciliation should look at, given the cursor state. */
|
|
22
|
+
function range(root, state, config) {
|
|
23
|
+
const last = state.last;
|
|
24
|
+
const previous = config.reconcileCursor?.previousCommit ?? null;
|
|
25
|
+
switch (state.state) {
|
|
26
|
+
case 'behind':
|
|
27
|
+
return last === null ? null : `${last}..HEAD`;
|
|
28
|
+
case 'rewritten':
|
|
29
|
+
return last === null ? null : `${last}...HEAD`;
|
|
30
|
+
case 'lost':
|
|
31
|
+
return previous === null ? null : `${previous}..HEAD`;
|
|
32
|
+
case 'unknown':
|
|
33
|
+
return 'HEAD';
|
|
34
|
+
default:
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function inspect(root) {
|
|
39
|
+
const config = readConfig(root);
|
|
40
|
+
const state = cursor(root, config);
|
|
41
|
+
const entries = readEntries(root);
|
|
42
|
+
const span = range(root, state, config);
|
|
43
|
+
if (span === null) {
|
|
44
|
+
return { cursor: state, changed: [], named: [], unmentioned: [] };
|
|
45
|
+
}
|
|
46
|
+
const changed = (git(root, ['diff', '--name-only', span]) ?? '')
|
|
47
|
+
.split('\n')
|
|
48
|
+
.map((file) => file.trim())
|
|
49
|
+
.filter((file) => file !== '');
|
|
50
|
+
const named = [];
|
|
51
|
+
for (const entry of entries) {
|
|
52
|
+
const files = changed.filter((file) => entryNames(entry, file));
|
|
53
|
+
if (files.length > 0) {
|
|
54
|
+
named.push({ entry, files });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const owned = new Set(named.flatMap((group) => group.files));
|
|
58
|
+
const unmentioned = changed.filter((file) => !owned.has(file) && !NOT_CODE.test(file) && file.includes('/'));
|
|
59
|
+
return { cursor: state, changed, named, unmentioned };
|
|
60
|
+
}
|
|
61
|
+
export function renderCheck(report) {
|
|
62
|
+
const lines = [];
|
|
63
|
+
const ids = [];
|
|
64
|
+
lines.push(`cursor ${describe(report.cursor)}`);
|
|
65
|
+
if (report.changed.length === 0) {
|
|
66
|
+
lines.push('changed nothing');
|
|
67
|
+
return { text: `${lines.join('\n')}\n`, ids, exit: 0 };
|
|
68
|
+
}
|
|
69
|
+
lines.push(`changed ${report.changed.length} file${report.changed.length === 1 ? '' : 's'}`);
|
|
70
|
+
const shown = report.named.slice(0, 5);
|
|
71
|
+
const more = report.named.length - shown.length;
|
|
72
|
+
const list = shown.map((group) => group.entry.id).join(', ');
|
|
73
|
+
lines.push(`named by ${report.named.length} entr${report.named.length === 1 ? 'y' : 'ies'}` +
|
|
74
|
+
(list === '' ? '' : ` (${list}${more > 0 ? `, +${more} more` : ''})`));
|
|
75
|
+
for (const group of report.named) {
|
|
76
|
+
ids.push(group.entry.id);
|
|
77
|
+
}
|
|
78
|
+
if (report.unmentioned.length > 0) {
|
|
79
|
+
lines.push(`unmentioned ${report.unmentioned.length}: ${report.unmentioned.slice(0, 5).join(', ')}`);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
lines.push('unmentioned none');
|
|
83
|
+
}
|
|
84
|
+
const exit = report.cursor.state === 'current' || report.cursor.state === 'nogit' ? 0 : 1;
|
|
85
|
+
return { text: `${lines.join('\n')}\n`, ids, exit };
|
|
86
|
+
}
|
|
87
|
+
export function renderDiff(report) {
|
|
88
|
+
const lines = [`cursor ${describe(report.cursor)}`];
|
|
89
|
+
const ids = [];
|
|
90
|
+
const ordered = [...report.named].sort((a, b) => b.files.length - a.files.length);
|
|
91
|
+
const updates = ordered.slice(0, 10);
|
|
92
|
+
for (const group of updates) {
|
|
93
|
+
lines.push(`update ${group.entry.id.padEnd(10)}${group.files.slice(0, 2).join(', ')}`);
|
|
94
|
+
ids.push(group.entry.id);
|
|
95
|
+
}
|
|
96
|
+
if (ordered.length > updates.length) {
|
|
97
|
+
lines.push(`… ${ordered.length - updates.length} more entries name a moved file`);
|
|
98
|
+
}
|
|
99
|
+
for (const file of report.unmentioned.slice(0, 10)) {
|
|
100
|
+
lines.push(`add ${''.padEnd(10)}${file}`);
|
|
101
|
+
}
|
|
102
|
+
if (report.unmentioned.length > 10) {
|
|
103
|
+
lines.push(`… ${report.unmentioned.length - 10} more files nobody names`);
|
|
104
|
+
}
|
|
105
|
+
if (report.named.length === 0 && report.unmentioned.length === 0) {
|
|
106
|
+
lines.push('none nothing moved');
|
|
107
|
+
}
|
|
108
|
+
return { text: `${lines.join('\n')}\n`, ids, exit: 0 };
|
|
109
|
+
}
|
package/dist/claims.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sddio check --claims` — falsifiability, executed (P7).
|
|
3
|
+
*
|
|
4
|
+
* A `SPEC` bullet may carry one line:
|
|
5
|
+
*
|
|
6
|
+
* - Check: <command> → <expected substring>
|
|
7
|
+
*
|
|
8
|
+
* The command runs at the repository root; the claim holds when the output
|
|
9
|
+
* contains the expected text. A claim whose command fails is drift, not an
|
|
10
|
+
* error — the whole point is that the knowledge says so before a person does.
|
|
11
|
+
*/
|
|
12
|
+
import { execSync } from 'node:child_process';
|
|
13
|
+
import { readEntries } from './repo.js';
|
|
14
|
+
const LINE = /^-\s+Check:\s*(.+?)\s*(?:→|->)\s*(.+?)\s*$/;
|
|
15
|
+
export function readClaims(root) {
|
|
16
|
+
const claims = [];
|
|
17
|
+
for (const entry of readEntries(root)) {
|
|
18
|
+
if (entry.kind !== 'SPEC') {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
for (const line of entry.body.split('\n')) {
|
|
22
|
+
const match = LINE.exec(line.trim());
|
|
23
|
+
if (match !== null) {
|
|
24
|
+
claims.push({ id: entry.id, command: match[1] ?? '', expected: match[2] ?? '' });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return claims;
|
|
29
|
+
}
|
|
30
|
+
export function runClaim(root, claim) {
|
|
31
|
+
try {
|
|
32
|
+
const output = execSync(claim.command, {
|
|
33
|
+
cwd: root,
|
|
34
|
+
encoding: 'utf8',
|
|
35
|
+
timeout: 20_000,
|
|
36
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
37
|
+
});
|
|
38
|
+
return { ...claim, ok: output.includes(claim.expected), actual: output.trim() };
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
const failure = error;
|
|
42
|
+
const output = `${failure.stdout ?? ''}${failure.stderr ?? ''}`.trim() || (failure.message ?? '');
|
|
43
|
+
return { ...claim, ok: output.includes(claim.expected), actual: output.split('\n')[0] ?? '' };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function runClaims(root, claims) {
|
|
47
|
+
return claims.map((claim) => runClaim(root, claim));
|
|
48
|
+
}
|
|
49
|
+
export function renderClaims(results) {
|
|
50
|
+
if (results.length === 0) {
|
|
51
|
+
return { text: 'no claims — a SPEC bullet may carry one: `- Check: <command> → <expected>`\n', exit: 0, drift: 0 };
|
|
52
|
+
}
|
|
53
|
+
const drift = results.filter((result) => !result.ok);
|
|
54
|
+
const lines = [`${results.length} claims, ${results.length - drift.length} ok, ${drift.length} drift`];
|
|
55
|
+
for (const result of drift) {
|
|
56
|
+
lines.push(`drift ${result.id} ${result.command}`);
|
|
57
|
+
lines.push(` expect "${result.expected}" actual "${result.actual.slice(0, 60)}"`);
|
|
58
|
+
}
|
|
59
|
+
return { text: `${lines.join('\n')}\n`, exit: drift.length === 0 ? 0 : 1, drift: drift.length };
|
|
60
|
+
}
|