@sddio/cli 0.2.0 → 0.3.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @sddio/cli
2
2
 
3
- **Spec-driven development for coding agents, kept in your repo.**
3
+ **A spec-driven development tool for coding agents. The spec lives in your repo.**
4
4
 
5
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
 
@@ -27,16 +27,17 @@ Read `.sddio/context/instructions.md` and follow it.
27
27
  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
- `config.json` has no baseline yet, so the state is `unknown`.
30
+ `config.json` has no baseline yet, so the cursor is `unknown`.
31
31
  2. Bootstrap as described in `instructions/bootstrap.md`, but do not describe the
32
32
  code back to me. Record only what the repository cannot say: a reversed
33
33
  decision and why, an outside constraint and its deadline, an abandoned path.
34
34
  At most six SPEC entries, each ending with `Not in the code:`.
35
35
  3. Ask me up to three questions whose answers would change future work, and
36
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).
37
+
38
+ Report what you recorded, then set `reconcileCursor.lastProcessedCommit` in
39
+ `.sddio/context/config.json` to `HEAD` and commit it with the entries.
40
+ Amending that commit is safe: the baseline is recomputed from history each run.
40
41
 
41
42
  Then answer this: <your first task>
42
43
  ```
@@ -48,7 +49,7 @@ Finally, commit `.sddio/` and `sddio_docs/` together with your next change. That
48
49
  | Situation | Prompt | Why |
49
50
  | --------- | ------ | --- |
50
51
  | First run, files created | bootstrap | the workspace is empty; the agent derives the first SPEC and records the first open question |
51
- | Only `.sddio/` changed | reconcile | package upgrade; existing knowledge may now be stale |
52
+ | Only `.sddio/` changed | reconcile | package upgrade; the rules may have changed, the knowledge did not |
52
53
  | Nothing changed | none | already up to date |
53
54
  | `--dry-run` | none | nothing was written, so there is nothing to hand over |
54
55
 
@@ -59,9 +60,9 @@ npm install --save-dev @sddio/cli@latest
59
60
  npx sddio init
60
61
  ```
61
62
 
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
+ `.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. The cursor survives the upgrade: it describes this project's history, not the package's, so nothing is stale merely because you upgraded.
63
64
 
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.
65
+ Two fields survive the refresh in `.sddio/context/config.json`: the `hooks` array and `reconcileCursor`. An upgrade must not silently re-wire the project to a caller it abandoned, or forget the commit it last reconciled against.
65
66
 
66
67
  ## Commands
67
68
 
@@ -70,7 +71,7 @@ sddio init [--dir <path>] [--hook <name>] [--no-install] [--yes] [--force] [--dr
70
71
  sddio start [<path>...] # cursor, hint and brief in one call
71
72
  sddio brief [<path>...] # entries that name those paths
72
73
  sddio show <id> # one entry, body included
73
- sddio check [--json] # behind HEAD? did a moved file go unrecorded?
74
+ sddio check [--json] [--strict] [--claims] # behind HEAD? did a moved file go unrecorded?
74
75
  sddio diff [--json] # the worklist: what each moved file touches
75
76
  ```
76
77
 
@@ -80,16 +81,17 @@ sddio diff [--json] # the worklist: what each moved file touches
80
81
  | `start` | The one call a hook makes: cursor state, a hint, and a brief, in ten lines or fewer |
81
82
  | `brief` | Titles of the entries that name the given paths. Reads nothing else |
82
83
  | `show` | One entry by ID, body included |
83
- | `check` | Cursor state plus the files nobody wrote about. Exits 1 when behind, for CI |
84
+ | `check` | Cursor state plus the files nobody wrote about. Prints, exits 0; `--strict` is the gate |
85
+ | `--claims` | Run the `- Check:` commands a SPEC bullet carries; drift exits 1 |
84
86
  | `diff` | Which entries name a moved file, and which files nobody named. Prints; never writes |
85
87
  | `--dir <path>` | Target project root (default: current directory) |
86
- | `--hook <name>` | `flow-trail` (default) or `none`. Naming one installs it unless `--no-install` is given |
88
+ | `--hook <name>` | `none` (default) or `flow-trail`. Naming `flow-trail` installs it unless `--no-install` is given |
87
89
  | `--no-install` | Declare the hook in `config.json` without running its installer |
88
- | `--yes` | Take the default hook without asking, and install it |
90
+ | `--yes` | Take the default (`none`) without asking |
89
91
  | `--force` | Overwrite existing files, including `sddio_docs/` seeds |
90
92
  | `--dry-run` | Report what would change without writing |
91
93
 
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.
94
+ With a terminal attached, `init` asks one question: which hook should keep the workspace current. The default is `none`, so a first run installs nothing and fetches nothing. Choosing `flow-trail` runs its own bootstrap in the target project — a card board in `flow-trail/`, a pointer in `AGENTS.md`. `--no-install` declares it without the fetch, for CI. A project that has already answered is not asked again, and an upgrade never re-downloads the hook.
93
95
 
94
96
  `.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.
95
97
 
@@ -98,8 +100,8 @@ With a terminal attached, `init` asks one question: which hook should keep the w
98
100
  ## What lands in a project
99
101
 
100
102
  ```text
101
- .sddio/ # context layer, identical to the sddio repository's own .sddio/
102
- context/ # instructions, schema, routes, preferences, roadmap, writing
103
+ .sddio/ # context layer, generated from the sddio repository's own .sddio/
104
+ context/ # instructions, schema, routes, writing
103
105
  sddio_docs/ # the user's workspace: layout only, empty seeds
104
106
  spec/spec_100.md # → 0 bytes
105
107
  adr/adr_100.md # → 0 bytes
package/dist/brief.js CHANGED
@@ -38,8 +38,8 @@ function loadBearing(entries) {
38
38
  return [...inbound.entries()]
39
39
  .sort((a, b) => b[1] - a[1])
40
40
  .slice(0, 3)
41
- .map(([id]) => entries.find((entry) => entry.id === id))
42
- .filter((entry) => entry !== undefined);
41
+ .map(([id, count]) => ({ entry: entries.find((entry) => entry.id === id), inbound: count }))
42
+ .filter((row) => row.entry !== undefined);
43
43
  }
44
44
  function openQuestions(entries) {
45
45
  return entries.filter((entry) => entry.kind === 'DISC' && entry.status !== 'resolved').slice(0, 2);
@@ -50,7 +50,7 @@ export function renderBrief(root, paths, options = {}) {
50
50
  const state = cursor(root, readConfig(root));
51
51
  const lines = [];
52
52
  const ids = [];
53
- const stale = state.state === 'behind' || state.state === 'rewritten' || state.state === 'lost';
53
+ const stale = state.state === 'behind' || state.state === 'recovered';
54
54
  lines.push(`${(options.label ?? 'brief').padEnd(6)} ${targets.length === 0 ? '.' : targets.join(' ')}`);
55
55
  lines.push(`cursor ${describe(state)}`);
56
56
  if (options.hint === true && stale) {
@@ -58,11 +58,10 @@ export function renderBrief(root, paths, options = {}) {
58
58
  }
59
59
  if (targets.length === 0) {
60
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);
61
+ for (const [index, row] of loadBearing(entries).entries()) {
62
+ const refs = row.inbound === 0 ? '' : ` (${row.inbound} ref${row.inbound === 1 ? '' : 's'})`;
63
+ lines.push(group('load', index, `${row.entry.id.padEnd(10)}${trimming(row.entry.title, 40)}${refs}`));
64
+ ids.push(row.entry.id);
66
65
  }
67
66
  for (const [index, entry] of openQuestions(entries).entries()) {
68
67
  lines.push(group('open', index, `${entry.id.padEnd(10)}${trimming(entry.title, 44)}`));
package/dist/check.js CHANGED
@@ -1,52 +1,32 @@
1
1
  /**
2
- * `sddio check` and `sddio diff` — the accusing half (P2, P3).
2
+ * `sddio check` and `sddio diff` — the accusing half.
3
3
  *
4
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.
5
+ * the entries that name those files. `check` prints and stays out of the way;
6
+ * `--strict` turns the same report into an exit code for CI. `diff` turns it
7
+ * into a worklist and stops there. Neither writes.
8
+ *
9
+ * The accusation is deliberately narrower than "a file moved". Prose, images and
10
+ * the layers that document themselves are not entry material, and listing them
11
+ * is how a signal becomes a wall (ADR-010).
7
12
  */
8
- import { execFileSync } from 'node:child_process';
9
13
  import { cursor, describe } from './cursor.js';
10
14
  import { entryNames, readConfig, readEntries } from './repo.js';
11
15
  /** Files that are never "unmentioned": the workspace and the board document themselves. */
12
16
  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
- }
17
+ /** Prose and assets: an entry about them would restate the diff (ADR-012). */
18
+ const PROSE = /\.(md|mdx|txt|svg|png|jpe?g|gif|webp|ico)$/i;
19
+ /** Can an entry be written about this path at all? */
20
+ export function entryMaterial(file) {
21
+ return !NOT_CODE.test(file) && !PROSE.test(file);
37
22
  }
38
23
  export function inspect(root) {
39
- const config = readConfig(root);
40
- const state = cursor(root, config);
24
+ const state = cursor(root, readConfig(root));
41
25
  const entries = readEntries(root);
42
- const span = range(root, state, config);
43
- if (span === null) {
44
- return { cursor: state, changed: [], named: [], unmentioned: [] };
26
+ const changed = state.changed;
27
+ if (changed.length === 0) {
28
+ return { cursor: state, changed, named: [], unmentioned: [] };
45
29
  }
46
- const changed = (git(root, ['diff', '--name-only', span]) ?? '')
47
- .split('\n')
48
- .map((file) => file.trim())
49
- .filter((file) => file !== '');
50
30
  const named = [];
51
31
  for (const entry of entries) {
52
32
  const files = changed.filter((file) => entryNames(entry, file));
@@ -55,16 +35,22 @@ export function inspect(root) {
55
35
  }
56
36
  }
57
37
  const owned = new Set(named.flatMap((group) => group.files));
58
- const unmentioned = changed.filter((file) => !owned.has(file) && !NOT_CODE.test(file) && file.includes('/'));
38
+ const unmentioned = changed.filter((file) => !owned.has(file) && entryMaterial(file));
59
39
  return { cursor: state, changed, named, unmentioned };
60
40
  }
61
41
  export function renderCheck(report) {
62
42
  const lines = [];
63
43
  const ids = [];
64
44
  lines.push(`cursor ${describe(report.cursor)}`);
45
+ if (report.cursor.from !== null && report.cursor.subject !== '') {
46
+ lines.push(`baseline ${report.cursor.from.slice(0, 7)} ${report.cursor.subject}`);
47
+ }
48
+ if (report.cursor.state === 'recovered') {
49
+ lines.push('note the stored cursor no longer exists; the knowledge commit was used');
50
+ }
65
51
  if (report.changed.length === 0) {
66
52
  lines.push('changed nothing');
67
- return { text: `${lines.join('\n')}\n`, ids, exit: 0 };
53
+ return { text: `${lines.join('\n')}\n`, ids, strict: 0 };
68
54
  }
69
55
  lines.push(`changed ${report.changed.length} file${report.changed.length === 1 ? '' : 's'}`);
70
56
  const shown = report.named.slice(0, 5);
@@ -81,8 +67,8 @@ export function renderCheck(report) {
81
67
  else {
82
68
  lines.push('unmentioned none');
83
69
  }
84
- const exit = report.cursor.state === 'current' || report.cursor.state === 'nogit' ? 0 : 1;
85
- return { text: `${lines.join('\n')}\n`, ids, exit };
70
+ const strict = report.cursor.state === 'current' && report.unmentioned.length === 0 ? 0 : 1;
71
+ return { text: `${lines.join('\n')}\n`, ids, strict };
86
72
  }
87
73
  export function renderDiff(report) {
88
74
  const lines = [`cursor ${describe(report.cursor)}`];
@@ -105,5 +91,5 @@ export function renderDiff(report) {
105
91
  if (report.named.length === 0 && report.unmentioned.length === 0) {
106
92
  lines.push('none nothing moved');
107
93
  }
108
- return { text: `${lines.join('\n')}\n`, ids, exit: 0 };
94
+ return { text: `${lines.join('\n')}\n`, ids, strict: 0 };
109
95
  }
package/dist/cli.js CHANGED
@@ -23,7 +23,7 @@ Usage:
23
23
  [--force] [--dry-run]
24
24
  sddio brief [<path>...]
25
25
  sddio show <id>
26
- sddio check [--json]
26
+ sddio check [--json] [--strict] [--claims]
27
27
  sddio diff [--json]
28
28
  sddio start [<path>...]
29
29
  sddio --version
@@ -37,17 +37,18 @@ Commands:
37
37
  only; use show for a body. Reads nothing else.
38
38
  show Print one entry by ID.
39
39
  check Is the workspace behind HEAD, and did any moved file go unrecorded.
40
- Exit 1 when behind, for CI.
40
+ Prints, exits 0. --strict exits 1 when it would gate; --claims
41
+ runs the checks a SPEC bullet carries.
41
42
  diff The worklist: which entries name a moved file, and which files
42
43
  nobody has written about. Prints; never writes.
43
44
  start One call for a hook: the cursor, a hint, and the brief.
44
45
 
45
46
  Options:
46
47
  --dir <path> Target project root (default: current directory)
47
- --hook <name> Hook to declare: flow-trail (default) or none. Naming one
48
- installs it into the project unless --no-install is given.
48
+ --hook <name> Hook to declare: none (default) or flow-trail. Naming
49
+ flow-trail installs it unless --no-install is given.
49
50
  --no-install Declare the hook without running its installer
50
- --yes Take the default hook without asking, and install it
51
+ --yes Take the default hook (none) without asking
51
52
  --force Overwrite existing files, including sddio_docs
52
53
  --dry-run Report what would happen without writing anything
53
54
  -h, --help Show this help
@@ -128,10 +129,10 @@ async function askHook() {
128
129
  const rl = createInterface({ input: process.stdin, output: process.stdout });
129
130
  try {
130
131
  console.log('\nWhich hook should trigger reconciliation?');
131
- console.log(' 1) flow-trail (default) — a card board in `flow-trail/`; installed into this project');
132
- console.log(' 2) none — nothing calls sddio; you run the check yourself');
132
+ console.log(' 1) none (default) — nothing calls sddio; you run the check yourself');
133
+ console.log(' 2) flow-trail — a card board in `flow-trail/`; installed into this project');
133
134
  const answer = (await rl.question('Choose [1]: ')).trim().toLowerCase();
134
- return answer === '2' || answer === 'none' ? 'none' : 'flow-trail';
135
+ return answer === '2' || answer === 'flow-trail' ? 'flow-trail' : 'none';
135
136
  }
136
137
  finally {
137
138
  rl.close();
@@ -243,10 +244,19 @@ async function commandCheck(args) {
243
244
  return rendered.exit;
244
245
  }
245
246
  if (args.includes('--json')) {
246
- process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
247
- return renderCheck(report).exit;
247
+ const text = `${JSON.stringify(report, null, 2)}\n`;
248
+ process.stdout.write(text);
249
+ recordEvent(root, readVersion(), {
250
+ cmd: 'check --json',
251
+ cursor: report.cursor.state,
252
+ out: measure(text, []),
253
+ exit: args.includes('--strict') ? renderCheck(report).strict : 0,
254
+ ms: Date.now() - started,
255
+ });
256
+ return args.includes('--strict') ? renderCheck(report).strict : 0;
248
257
  }
249
- const { text, ids, exit } = renderCheck(report);
258
+ const { text, ids, strict } = renderCheck(report);
259
+ const exit = args.includes('--strict') ? strict : 0;
250
260
  process.stdout.write(text);
251
261
  recordEvent(root, readVersion(), {
252
262
  cmd: 'check',
package/dist/cursor.js CHANGED
@@ -1,10 +1,25 @@
1
1
  /**
2
- * The cursor, resolved against git (SPEC-010).
2
+ * The baseline, resolved against git (SPEC-010).
3
3
  *
4
- * One implementation for `brief`, `check`, `diff` and `start`, so four commands
5
- * cannot disagree about whether the workspace is behind.
4
+ * The baseline is the commit the knowledge was last reconciled against. Two
5
+ * facts can name it, and the baseline is whichever is newer:
6
+ *
7
+ * - the newest commit that changed `sddio_docs/` — the record of a reconcile;
8
+ * - the cursor, for the case where a reconcile found nothing to write.
9
+ *
10
+ * Taking the newer one is what makes an amend a non-event. Writing `HEAD` into
11
+ * the cursor and committing makes that commit the newest knowledge commit, and
12
+ * its parent the stored cursor; the comparison then starts at the commit itself,
13
+ * not one behind it, and amending it changes neither side of that comparison.
14
+ *
15
+ * Nothing is verified for existence before it is used. A cursor whose object is
16
+ * gone — rebase, `gc`, a fresh clone — falls back to the knowledge commit and
17
+ * says so, instead of reporting rewritten history (ADR-013).
6
18
  */
7
19
  import { execFileSync } from 'node:child_process';
20
+ export const KNOWLEDGE = 'sddio_docs/';
21
+ /** The context layer documents itself; a commit touching only it is not a change. */
22
+ const CONTEXT = ':(exclude).sddio';
8
23
  function run(root, args) {
9
24
  try {
10
25
  return execFileSync('git', args, { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
@@ -13,52 +28,76 @@ function run(root, args) {
13
28
  return null;
14
29
  }
15
30
  }
16
- function ok(root, args) {
17
- try {
18
- execFileSync('git', args, { cwd: root, stdio: ['ignore', 'ignore', 'ignore'] });
19
- return true;
20
- }
21
- catch {
22
- return false;
23
- }
24
- }
25
31
  function exists(root, sha) {
26
- return ok(root, ['cat-file', '-e', `${sha}^{commit}`]);
32
+ return run(root, ['cat-file', '-e', `${sha}^{commit}`]) !== null;
33
+ }
34
+ function isAncestor(root, older, newer) {
35
+ return run(root, ['merge-base', '--is-ancestor', older, newer]) !== null;
36
+ }
37
+ function lines(text) {
38
+ return (text ?? '')
39
+ .split('\n')
40
+ .map((line) => line.trim())
41
+ .filter((line) => line !== '');
27
42
  }
28
43
  export function cursor(root, config) {
29
- const last = config.reconcileCursor?.lastProcessedCommit ?? null;
30
- const previous = config.reconcileCursor?.previousCommit ?? null;
31
- if (run(root, ['rev-parse', '--git-dir']) === null || run(root, ['rev-parse', 'HEAD']) === null) {
32
- return { state: 'nogit', behind: 0, last };
44
+ const base = {
45
+ state: 'unknown',
46
+ behind: 0,
47
+ from: null,
48
+ changed: [],
49
+ subject: '',
50
+ date: '',
51
+ };
52
+ if (run(root, ['rev-parse', '--git-dir']) === null) {
53
+ return { ...base, state: 'nogit' };
33
54
  }
34
- if (last === null) {
35
- return { state: 'unknown', behind: 0, last };
55
+ const head = run(root, ['rev-parse', 'HEAD']);
56
+ if (head === null) {
57
+ return { ...base, state: 'nogit' };
36
58
  }
37
- if (!exists(root, last)) {
38
- if (previous !== null && exists(root, previous) && ok(root, ['merge-base', '--is-ancestor', previous, 'HEAD'])) {
39
- return { state: 'lost', behind: 0, last };
40
- }
41
- return { state: 'unknown', behind: 0, last };
59
+ const knowledge = run(root, ['log', '-1', '--format=%H', '--', KNOWLEDGE]);
60
+ if (knowledge === null) {
61
+ return base;
42
62
  }
43
- if (!ok(root, ['merge-base', '--is-ancestor', last, 'HEAD'])) {
44
- return { state: 'rewritten', behind: 0, last };
63
+ const stored = config.reconcileCursor?.lastProcessedCommit ?? null;
64
+ if (stored === null) {
65
+ return base;
45
66
  }
46
- const behind = Number(run(root, ['rev-list', '--count', `${last}..HEAD`]) ?? '0');
47
- return { state: behind === 0 ? 'current' : 'behind', behind, last };
67
+ const resolvable = exists(root, stored);
68
+ const from = !resolvable
69
+ ? knowledge
70
+ : isAncestor(root, stored, knowledge)
71
+ ? knowledge
72
+ : isAncestor(root, knowledge, stored)
73
+ ? stored
74
+ : knowledge;
75
+ const [subject = '', date = ''] = lines(run(root, ['log', '-1', '--format=%s%n%cs', from]));
76
+ const span = `${from}..${head}`;
77
+ // A commit that only moves the cursor changed nothing to reconcile. The
78
+ // context layer documents itself, so it is not part of the accusation.
79
+ const behind = Number(run(root, ['rev-list', '--count', span, '--', '.', CONTEXT]) ?? '0');
80
+ return {
81
+ state: !resolvable ? 'recovered' : behind === 0 ? 'current' : 'behind',
82
+ behind,
83
+ from,
84
+ changed: lines(run(root, ['diff', '--name-only', from, head, '--', '.', CONTEXT])),
85
+ subject,
86
+ date,
87
+ };
48
88
  }
49
- /** The one clause a command prints about the cursor. */
89
+ /** One clause, used by `brief` and `start` where the screen is tight. */
50
90
  export function describe(state) {
91
+ const at = state.from === null ? '' : `${state.from.slice(0, 7)}${state.date === '' ? '' : ` (${state.date})`}`;
51
92
  switch (state.state) {
52
93
  case 'current':
53
- return 'current';
94
+ return at === '' ? 'current' : `current — baseline ${at}`;
54
95
  case 'behind':
55
- return `${state.behind} commit${state.behind === 1 ? '' : 's'} behind`;
56
- case 'rewritten':
57
- return 'history rewritten — reconcile both sides';
58
- case 'lost':
59
- return 'anchor lost — reconcile from previousCommit';
96
+ return `${state.behind} commit${state.behind === 1 ? '' : 's'} behind ${at}`;
97
+ case 'recovered':
98
+ return `cursor gone — using ${at}`;
60
99
  case 'unknown':
61
- return 'no baseline';
100
+ return 'no baseline yet';
62
101
  case 'nogit':
63
102
  return 'not a git repository';
64
103
  }
package/dist/hooks.js CHANGED
@@ -6,9 +6,11 @@
6
6
  * bootstrap this repository uses — the integration is dogfooded or it is not
7
7
  * tested at all.
8
8
  *
9
- * Only `flow-trail` is offered today. The list exists so a second hook is a row
10
- * rather than a branch, and so the declared shape (`id`, `kind`, `events`)
11
- * matches what is actually consumed.
9
+ * Only `flow-trail` is offered today, and it is never the default: installing it
10
+ * fetches and runs a script from the network, which a first run must not do
11
+ * unasked (SPEC-018). The list exists so a second hook is a row rather than a
12
+ * branch, and so the declared shape (`id`, `kind`, `events`) matches what is
13
+ * actually consumed.
12
14
  */
13
15
  import { spawnSync } from 'node:child_process';
14
16
  import { readFileSync } from 'node:fs';
@@ -21,7 +23,7 @@ export const HOOKS = [
21
23
  summary: 'a board of folders in git; calls sddio when a card closes',
22
24
  },
23
25
  ];
24
- export const DEFAULT_HOOK = 'flow-trail';
26
+ export const DEFAULT_HOOK = 'none';
25
27
  /** The paste block flow-trail publishes; kept verbatim so both routes install the same thing. */
26
28
  export const FLOW_TRAIL_BOOTSTRAP = 'bash -c "$(curl -fsSL https://raw.githubusercontent.com/benxgao/flow-trail/HEAD/scripts/bootstrap.sh)"';
27
29
  export function hookEntry(id) {
package/dist/init.js CHANGED
@@ -39,9 +39,10 @@ async function listFiles(root, prefix = '') {
39
39
  }
40
40
  /**
41
41
  * `config.json` is the one package-owned file that carries a user choice: the
42
- * hooks that call sddio. The template ships the cursor empty and the default
43
- * hook list, but a refresh must keep the hooks the project already declared —
44
- * otherwise an upgrade silently re-wires the project to a caller it abandoned.
42
+ * hooks that call sddio, and the commit the project last reconciled against.
43
+ * The template ships the cursor empty, but a refresh must keep what the project
44
+ * already recorded — the cursor describes this project's history, and the
45
+ * package knows nothing about it (ADR-013).
45
46
  */
46
47
  const CONFIG_FILE = 'context/config.json';
47
48
  function mergeConfig(existing, incoming, chosen) {
@@ -59,7 +60,8 @@ function mergeConfig(existing, incoming, chosen) {
59
60
  previous = {};
60
61
  }
61
62
  const declared = chosen ?? (Array.isArray(previous.hooks) ? previous.hooks : template.hooks);
62
- return `${JSON.stringify({ ...template, hooks: declared }, null, 2)}\n`;
63
+ const cursor = previous.reconcileCursor ?? template.reconcileCursor;
64
+ return `${JSON.stringify({ ...template, hooks: declared, reconcileCursor: cursor }, null, 2)}\n`;
63
65
  }
64
66
  /** `.sddio/` — package-owned, copied as `templates/.sddio/<path>` → `.sddio/<path>`. */
65
67
  async function copyContext(target, dryRun, chosen, result) {
package/dist/prompt.js CHANGED
@@ -17,34 +17,29 @@ export const BOOTSTRAP_PROMPT = [
17
17
  'This project has just been initialised with sddio. Before any other work:',
18
18
  '',
19
19
  '1. Run the commit check in `.sddio/context/instructions/reconciliation.md`.',
20
- ' `config.json` has no baseline yet, so the state is `unknown`.',
20
+ ' `config.json` has no baseline yet, so the cursor is `unknown`.',
21
21
  '2. Bootstrap as described in `instructions/bootstrap.md`, but do not describe the',
22
22
  ' code back to me. Record only what the repository cannot say: a reversed',
23
23
  ' decision and why, an outside constraint and its deadline, an abandoned path.',
24
24
  ' At most six SPEC entries, each ending with `Not in the code:`.',
25
25
  '3. Ask me up to three questions whose answers would change future work, and',
26
26
  ' record at least one DISCUSSION (SPEC-016) for what stays open.',
27
- '4. Report what you recorded, then set `reconcileCursor.lastProcessedCommit` to',
28
- ' `HEAD` and `reconcileCursor.previousCommit` to `HEAD^` in',
29
- ' `.sddio/context/config.json` (`null` at a root commit).',
27
+ '',
28
+ 'Report what you recorded, then set `reconcileCursor.lastProcessedCommit` in',
29
+ '`.sddio/context/config.json` to `HEAD` and commit it with the entries.',
30
+ 'Amending that commit is safe: the baseline is recomputed from history each run.',
30
31
  '',
31
32
  'Then answer this: <your first task>',
32
33
  ].join('\n');
33
34
  export const RECONCILE_PROMPT = [
34
35
  'Read `.sddio/context/instructions.md` and follow it.',
35
36
  '',
36
- 'The sddio context layer in `.sddio/` was just refreshed by a package upgrade,',
37
- 'and `config.json` now carries no baseline (`null`). Before any other work, run',
38
- 'the commit check and reconcile: `.sddio/context/instructions/reconciliation.md`.',
39
- '',
40
- 'The cursor state is `unknown`, so there is no range to diff: verify the existing',
41
- 'artifacts against the current implementation. Do not rescan unrelated areas, and',
42
- 'do not rewrite artifacts that are still accurate.',
37
+ 'The sddio context layer in `.sddio/` was just replaced by a package upgrade.',
38
+ 'The cursor was kept, so nothing is stale merely because of the upgrade.',
43
39
  '',
44
- 'Report what you understood and what you changed, then set',
45
- '`reconcileCursor.lastProcessedCommit` to `HEAD` and `reconcileCursor.previousCommit`',
46
- 'to `HEAD^` in `.sddio/context/config.json` (`null` at a root commit), so the next',
47
- 'session resumes from a baseline.',
40
+ 'If the new rules change what an existing entry is allowed to say, fix that',
41
+ 'entry only. Do not rescan the repository, and do not rewrite entries that are',
42
+ 'still accurate.',
48
43
  '',
49
44
  'Then answer this: <your first task>',
50
45
  ].join('\n');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sddio/cli",
3
- "version": "0.2.0",
4
- "description": "Spec-driven development for coding agents: keep SPEC, ADR and DISCUSSION in your repo so the reasoning survives session restarts.",
3
+ "version": "0.3.0",
4
+ "description": "A spec-driven development tool for coding agents: keep SPEC, ADR and DISCUSSION in your repo so the reasoning survives session restarts.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "bin": {
@@ -1,16 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 3,
3
3
  "reconcileCursor": {
4
- "lastProcessedCommit": null,
5
- "previousCommit": null
4
+ "lastProcessedCommit": null
6
5
  },
7
- "hooks": [
8
- {
9
- "id": "flow-trail",
10
- "kind": "external",
11
- "events": [
12
- "knowledge.reconcile"
13
- ]
14
- }
15
- ]
6
+ "hooks": []
16
7
  }
@@ -11,42 +11,44 @@ Reconciliation keeps durable project knowledge consistent with implementation.
11
11
 
12
12
  ## Commit Check
13
13
 
14
- Read `reconcileCursor` in `.sddio/context/config.json`, then resolve it with git.
15
-
16
- - `HEAD` — `git rev-parse HEAD`
17
- - Exists — `git cat-file -e <sha>^{commit}`
18
- - Ancestor — `git merge-base --is-ancestor <sha> HEAD`
19
-
20
- Evaluate in order; stop at the first match.
21
-
22
- | State | Condition | Range |
23
- | --------- | ------------------------------------------------ | ---------------- |
24
- | current | `reconcileCursor.lastProcessedCommit` equals `HEAD` | none |
25
- | ahead | it is an ancestor of `HEAD` | `last..HEAD` |
26
- | rewritten | it exists, is not an ancestor | `last...HEAD` |
27
- | lost | it is gone, `previousCommit` is an ancestor | `previous..HEAD` |
28
- | unknown | `null`, absent, or unresolvable | current state |
14
+ Read `reconcileCursor.lastProcessedCommit` in `.sddio/context/config.json`, then pick the commit
15
+ to compare it with:
16
+
17
+ - The newest knowledge commit is `git log -1 --format=%H -- sddio_docs/`.
18
+ - If that commit is `HEAD`, compare with `HEAD^` — that commit carried the cursor, and its parent
19
+ is the commit actually reconciled against.
20
+ - Otherwise compare with `HEAD`, so the newest change is never skipped.
21
+
22
+ | State | Condition | Range |
23
+ | --------- | ---------------------------------------------------- | --------------------------- |
24
+ | current | no commit sits between the cursor and the reference | none |
25
+ | behind | commits sit between them | `cursor..reference` |
26
+ | recovered | the cursor commit no longer exists | `newestKnowledge..reference` |
27
+ | unknown | the cursor is `null` or absent | current state |
28
+ | nogit | no repository, or no git binary | none |
29
29
 
30
30
  - `current` — no reconciliation; continue with the request.
31
- - `ahead` — reconcile only the new commits.
32
- - `rewritten` — amended, rebased, or reset history; reconcile both sides.
33
- - `lost` — the anchor survives but the tip does not; reconcile from the anchor.
34
- - `unknown` — verify artifacts against the current implementation, not the whole repository.
35
- - A shallow clone with a missing cursor commit is `unknown`, never `rewritten`.
36
- - No git repository, or no git binary — skip the check, leave the cursor untouched.
37
- - Report the state and the reconciled range; do not reconcile silently.
31
+ - `behind` — reconcile only the new commits.
32
+ - `recovered` — a rebase, `gc` or a fresh clone removed the cursor; say so, and reconcile from
33
+ the newest knowledge commit instead of treating it as an error.
34
+ - `unknown` — first session, or an unfinished bootstrap: verify the artifacts you touch, not the
35
+ whole repository.
36
+ - `nogit` — skip the check and leave the cursor untouched.
37
+ - No ancestry test is needed: the reference is chosen from `HEAD`, so it always resolves.
38
+ - Report the state and the range; do not reconcile silently.
38
39
 
39
40
  ## Cursor Update
40
41
 
41
- After reconciliation completes:
42
+ After reconciliation completes, in the same commit as the entries:
42
43
 
43
- 1. `reconcileCursor.previousCommit` ← `HEAD^`; `null` at a root commit.
44
- 2. `reconcileCursor.lastProcessedCommit` ← `HEAD`.
45
- 3. Preserve `schemaVersion` and `hooks`.
46
- 4. Write nothing when the state was `current`.
44
+ 1. `reconcileCursor.lastProcessedCommit` ← `HEAD`.
45
+ 2. Preserve `schemaVersion` and `hooks`.
46
+ 3. Write nothing when the state was `current`.
47
47
 
48
48
  - Write only after the artifacts are updated.
49
49
  - Do not advance the cursor when reconciliation is skipped, partial, or abandoned.
50
+ - Amending the commit that carries the cursor is safe: until the next commit lands, the check
51
+ compares against its parent.
50
52
  - The cursor holds commits only; uncommitted work is re-examined on the next run.
51
53
 
52
54
  ## Process
@@ -3,18 +3,19 @@
3
3
  ## Startup
4
4
 
5
5
  1. Run `npx sddio start`, and read what it prints.
6
- 2. Read `preferences.md`.
7
- 3. Read `writing.md` when you are about to create or change an entry — not before.
8
- 4. Load `instructions/<artifact>.md` only for the artifact you are writing.
6
+ 2. Read `writing.md` when you are about to create or change an entry — not before.
7
+ 3. Load `instructions/<artifact>.md` only for the artifact you are writing.
9
8
 
10
9
  If no usable `SPEC` exists, load `instructions/bootstrap.md`.
11
10
 
12
11
  ## The cursor
13
12
 
14
- `config.json` holds `reconcileCursor` and `hooks`. `start` resolves the first and prints the
15
- second's effect. States, ranges and edge cases: `instructions/reconciliation.md`.
13
+ `config.json` holds one commit — the one the knowledge was last reconciled against — and the
14
+ hooks. `start` resolves the first and prints the second's effect. Rules: `reconciliation.md`.
16
15
 
17
- - Behind or rewritten — reconcile before the next decision, not after the next commit.
16
+ - Behind — reconcile before the next decision, not after the next commit.
17
+ - The tip is skipped while it is the newest knowledge commit, so amending it changes nothing.
18
+ - A cursor whose commit is gone is not an error: the newest knowledge commit is used instead.
18
19
  - The cursor records commits, not uncommitted work.
19
20
  - A hook is a declaration. sddio never calls one.
20
21
 
@@ -1,81 +0,0 @@
1
- # sddio
2
-
3
- sddio is a lightweight project context system for AI-assisted software development.
4
-
5
- It keeps the project's **requirements, decisions, discussions, and development direction** in a small set of structured, human-readable Markdown files.
6
-
7
- ## Why
8
-
9
- AI can write code quickly, but often lacks reliable project context.
10
-
11
- Important context is usually scattered across:
12
-
13
- - conversations
14
- - code
15
- - tickets
16
- - documents
17
- - decisions
18
- - developer preferences
19
-
20
- sddio provides a small, persistent layer of project context that AI can read and maintain.
21
-
22
- ## How it works
23
-
24
- sddio separates project context into a few focused artifacts:
25
-
26
- - **SPEC** — what the system should do
27
- - **ADR** — why important technical decisions were made
28
- - **DISCUSSION** — unresolved questions, concerns, suggestions, and ideas
29
- - **ROADMAP** — future direction
30
- - **PREFERENCES** — stable project or user context
31
-
32
- AI uses these artifacts to:
33
-
34
- 1. understand the project
35
- 2. identify the user's intent
36
- 3. load only relevant context
37
- 4. create or update the appropriate artifact
38
- 5. keep project knowledge consistent over time
39
-
40
- The goal is not to document everything.
41
-
42
- The goal is to preserve the **smallest amount of context that meaningfully improves AI work**.
43
-
44
- ## Design Principles
45
-
46
- sddio follows a few simple rules:
47
-
48
- - Keep artifacts minimal.
49
- - Prefer structure over prose.
50
- - Make information easy for both humans and AI to parse.
51
- - Keep each artifact focused on one purpose.
52
- - Avoid unnecessary metadata, nesting, duplication, and abstraction.
53
- - Load context only when it is relevant.
54
- - Let AI maintain the context whenever possible.
55
- - Prefer the smallest structure that works well for both humans and AI.
56
-
57
- > **Do the least necessary.**
58
-
59
- ## What sddio Is Not
60
-
61
- sddio is not:
62
-
63
- - a replacement for Git
64
- - a project management system
65
- - a documentation platform
66
- - a database of every AI conversation
67
- - a requirement to document every change
68
-
69
- It is a **context layer between the project and AI**.
70
-
71
- ## The Desired Experience
72
-
73
- After sddio is installed, the developer should not need to manage the system manually.
74
-
75
- AI should be able to discover the project context, maintain the relevant artifacts, and keep them useful as the project evolves.
76
-
77
- The developer should primarily focus on the project itself.
78
-
79
- ---
80
-
81
- sddio provides **just enough structure for AI to understand, remember, and evolve a project without creating another system to manage.**
@@ -1,16 +0,0 @@
1
- # Preferences
2
-
3
- ## Preferences
4
-
5
- - Documentation: concise
6
- - Code style: minimal
7
- - Dependencies: avoid unnecessary dependencies
8
- - Communication: direct
9
- - Planning: incremental
10
- - Context: prefer targeted retrieval
11
-
12
- ## Project
13
-
14
- - Package manager: pnpm (not now, preferred later)
15
- - Architecture: monorepo (not now, preferred later)
16
- - Source of truth: repository artifacts
@@ -1,28 +0,0 @@
1
- # Roadmap
2
-
3
- <!--
4
- Possible future directions, not current requirements or commitments.
5
-
6
- When working on current tasks:
7
- - Do not implement roadmap items unless explicitly requested.
8
- - Do not treat roadmap items as requirements.
9
- - Avoid decisions that unnecessarily block roadmap directions.
10
- - Ask before adding extension points solely for roadmap directions.
11
- - Do not add abstractions solely for speculative roadmap items.
12
- - Before implementing a roadmap item, create the required discussion and ADR.
13
- - Remove the roadmap item once it becomes an active requirement.
14
- -->
15
-
16
- ## Near
17
-
18
- * Local UI for browsing and querying project knowledge.
19
- * MCP-based retrieval of project context.
20
-
21
- ## Later
22
-
23
- * Cross-repository knowledge.
24
-
25
- ## Explore
26
-
27
- * Automatic reconciliation between git history and project records.
28
- * Evaluation of SDD effectiveness over time.