@sddio/cli 0.1.0 → 0.2.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 +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/dist/cli.js
CHANGED
|
@@ -6,29 +6,50 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { readFileSync } from 'node:fs';
|
|
8
8
|
import { join, resolve } from 'node:path';
|
|
9
|
+
import { createInterface } from 'node:readline/promises';
|
|
9
10
|
import { runInit } from './init.js';
|
|
11
|
+
import { DEFAULT_HOOK, hasDeclaredHooks } from './hooks.js';
|
|
12
|
+
import { renderBrief, renderEntry } from './brief.js';
|
|
13
|
+
import { inspect, renderCheck, renderDiff } from './check.js';
|
|
14
|
+
import { readClaims, renderClaims, runClaims } from './claims.js';
|
|
15
|
+
import { measure, recordEvent } from './events.js';
|
|
16
|
+
import { findRoot, readEntries } from './repo.js';
|
|
10
17
|
import { packageRoot } from './paths.js';
|
|
11
18
|
import { renderNextStep, selectNextStep } from './prompt.js';
|
|
12
|
-
import { readSkill, skillPath } from './skill.js';
|
|
13
19
|
const USAGE = `sddio — spec-driven development artifacts for a project
|
|
14
20
|
|
|
15
21
|
Usage:
|
|
16
|
-
sddio init [--dir <path>] [--
|
|
17
|
-
|
|
22
|
+
sddio init [--dir <path>] [--hook <name>] [--no-install] [--yes]
|
|
23
|
+
[--force] [--dry-run]
|
|
24
|
+
sddio brief [<path>...]
|
|
25
|
+
sddio show <id>
|
|
26
|
+
sddio check [--json]
|
|
27
|
+
sddio diff [--json]
|
|
28
|
+
sddio start [<path>...]
|
|
18
29
|
sddio --version
|
|
19
30
|
sddio --help
|
|
20
31
|
|
|
21
32
|
Commands:
|
|
22
|
-
init Copy .sddio and
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
init Copy .sddio and sddio_docs templates into the target project,
|
|
34
|
+
register the sddio snippet in AGENTS.md, and record the hook that
|
|
35
|
+
triggers reconciliation.
|
|
36
|
+
brief What the workspace knows about the paths in front of you. Titles
|
|
37
|
+
only; use show for a body. Reads nothing else.
|
|
38
|
+
show Print one entry by ID.
|
|
39
|
+
check Is the workspace behind HEAD, and did any moved file go unrecorded.
|
|
40
|
+
Exit 1 when behind, for CI.
|
|
41
|
+
diff The worklist: which entries name a moved file, and which files
|
|
42
|
+
nobody has written about. Prints; never writes.
|
|
43
|
+
start One call for a hook: the cursor, a hint, and the brief.
|
|
26
44
|
|
|
27
45
|
Options:
|
|
28
46
|
--dir <path> Target project root (default: current directory)
|
|
29
|
-
--
|
|
47
|
+
--hook <name> Hook to declare: flow-trail (default) or none. Naming one
|
|
48
|
+
installs it into the project unless --no-install is given.
|
|
49
|
+
--no-install Declare the hook without running its installer
|
|
50
|
+
--yes Take the default hook without asking, and install it
|
|
51
|
+
--force Overwrite existing files, including sddio_docs
|
|
30
52
|
--dry-run Report what would happen without writing anything
|
|
31
|
-
--print Print the skill (skill only)
|
|
32
53
|
-h, --help Show this help
|
|
33
54
|
-v, --version Show the version
|
|
34
55
|
`;
|
|
@@ -37,7 +58,7 @@ function readVersion() {
|
|
|
37
58
|
return JSON.parse(manifest).version;
|
|
38
59
|
}
|
|
39
60
|
function parseInitArgs(args) {
|
|
40
|
-
const parsed = { cwd: process.cwd(), force: false, dryRun: false };
|
|
61
|
+
const parsed = { cwd: process.cwd(), force: false, dryRun: false, yes: false, noInstall: false };
|
|
41
62
|
for (let index = 0; index < args.length; index += 1) {
|
|
42
63
|
const argument = args[index];
|
|
43
64
|
if (argument === '--force') {
|
|
@@ -46,6 +67,20 @@ function parseInitArgs(args) {
|
|
|
46
67
|
else if (argument === '--dry-run') {
|
|
47
68
|
parsed.dryRun = true;
|
|
48
69
|
}
|
|
70
|
+
else if (argument === '--yes') {
|
|
71
|
+
parsed.yes = true;
|
|
72
|
+
}
|
|
73
|
+
else if (argument === '--no-install') {
|
|
74
|
+
parsed.noInstall = true;
|
|
75
|
+
}
|
|
76
|
+
else if (argument === '--hook') {
|
|
77
|
+
const value = args[index + 1];
|
|
78
|
+
if (value === undefined) {
|
|
79
|
+
throw new Error('--hook requires a name: flow-trail or none');
|
|
80
|
+
}
|
|
81
|
+
parsed.hook = value;
|
|
82
|
+
index += 1;
|
|
83
|
+
}
|
|
49
84
|
else if (argument === '--dir') {
|
|
50
85
|
const value = args[index + 1];
|
|
51
86
|
if (value === undefined) {
|
|
@@ -74,6 +109,9 @@ function report(result) {
|
|
|
74
109
|
console.log(` ${label('skipped')}${file}`);
|
|
75
110
|
}
|
|
76
111
|
console.log(`\ncreated ${result.created.length}, overwritten ${result.overwritten.length}, skipped ${result.skipped.length}`);
|
|
112
|
+
if (result.hook !== null) {
|
|
113
|
+
console.log(`hook: ${result.hook}${result.install === null ? ' (declared, not installed)' : ''}`);
|
|
114
|
+
}
|
|
77
115
|
if (result.dryRun) {
|
|
78
116
|
console.log('dry run: nothing was written');
|
|
79
117
|
}
|
|
@@ -81,8 +119,48 @@ function report(result) {
|
|
|
81
119
|
console.error(`error: ${error}`);
|
|
82
120
|
}
|
|
83
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* One question, one default. The alternative is a flag nobody reads, and the
|
|
124
|
+
* choice has to be written into `config.json` either way. A project that has
|
|
125
|
+
* already answered is not asked again: an upgrade is not a re-interview.
|
|
126
|
+
*/
|
|
127
|
+
async function askHook() {
|
|
128
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
129
|
+
try {
|
|
130
|
+
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');
|
|
133
|
+
const answer = (await rl.question('Choose [1]: ')).trim().toLowerCase();
|
|
134
|
+
return answer === '2' || answer === 'none' ? 'none' : 'flow-trail';
|
|
135
|
+
}
|
|
136
|
+
finally {
|
|
137
|
+
rl.close();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
84
140
|
async function commandInit(args) {
|
|
85
|
-
const
|
|
141
|
+
const options = parseInitArgs(args);
|
|
142
|
+
const alreadyDeclared = hasDeclaredHooks(options.cwd);
|
|
143
|
+
const interactive = options.hook === undefined &&
|
|
144
|
+
!options.yes &&
|
|
145
|
+
!alreadyDeclared &&
|
|
146
|
+
process.stdin.isTTY === true &&
|
|
147
|
+
process.stdout.isTTY === true;
|
|
148
|
+
if (interactive) {
|
|
149
|
+
options.hook = await askHook();
|
|
150
|
+
}
|
|
151
|
+
// `--yes` takes the same default the question offers. On an upgrade the
|
|
152
|
+
// question is not asked and the existing declaration stands, so a second
|
|
153
|
+
// `--yes` does not re-download anything.
|
|
154
|
+
if (options.hook === undefined && options.yes && !alreadyDeclared) {
|
|
155
|
+
options.hook = DEFAULT_HOOK;
|
|
156
|
+
}
|
|
157
|
+
const result = await runInit({
|
|
158
|
+
cwd: options.cwd,
|
|
159
|
+
force: options.force,
|
|
160
|
+
dryRun: options.dryRun,
|
|
161
|
+
hook: options.hook,
|
|
162
|
+
install: options.hook !== undefined && !options.noInstall,
|
|
163
|
+
});
|
|
86
164
|
report(result);
|
|
87
165
|
if (result.errors.length > 0) {
|
|
88
166
|
return 1;
|
|
@@ -94,15 +172,130 @@ async function commandInit(args) {
|
|
|
94
172
|
console.log(`\n${renderNextStep(selectNextStep(result.created.length, result.overwritten.length))}`);
|
|
95
173
|
return 0;
|
|
96
174
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
175
|
+
/** Every read-side command starts here: no workspace, no output, one message. */
|
|
176
|
+
function workspaceRoot() {
|
|
177
|
+
return findRoot(process.cwd());
|
|
178
|
+
}
|
|
179
|
+
async function commandBrief(args) {
|
|
180
|
+
const root = workspaceRoot();
|
|
181
|
+
if (root === null) {
|
|
182
|
+
console.error('no .sddio/context/config.json above this directory');
|
|
183
|
+
return 1;
|
|
184
|
+
}
|
|
185
|
+
const started = Date.now();
|
|
186
|
+
const { text, ids } = renderBrief(root, args);
|
|
187
|
+
process.stdout.write(text);
|
|
188
|
+
recordEvent(root, readVersion(), {
|
|
189
|
+
cmd: 'brief',
|
|
190
|
+
args: { paths: args },
|
|
191
|
+
out: measure(text, ids),
|
|
192
|
+
exit: 0,
|
|
193
|
+
ms: Date.now() - started,
|
|
194
|
+
});
|
|
195
|
+
return 0;
|
|
196
|
+
}
|
|
197
|
+
async function commandShow(args) {
|
|
198
|
+
const root = workspaceRoot();
|
|
199
|
+
if (root === null) {
|
|
200
|
+
console.error('no .sddio/context/config.json above this directory');
|
|
201
|
+
return 1;
|
|
202
|
+
}
|
|
203
|
+
const id = args[0];
|
|
204
|
+
if (id === undefined) {
|
|
205
|
+
throw new Error('show requires an entry ID, for example: sddio show ADR-012');
|
|
206
|
+
}
|
|
207
|
+
const entry = readEntries(root).find((candidate) => candidate.id.toLowerCase() === id.toLowerCase());
|
|
208
|
+
if (entry === undefined) {
|
|
209
|
+
console.error(`no entry with ID ${id}`);
|
|
210
|
+
return 1;
|
|
211
|
+
}
|
|
212
|
+
const started = Date.now();
|
|
213
|
+
const text = renderEntry(entry);
|
|
214
|
+
process.stdout.write(text);
|
|
215
|
+
recordEvent(root, readVersion(), {
|
|
216
|
+
cmd: 'show',
|
|
217
|
+
args: { id: entry.id },
|
|
218
|
+
out: measure(text, [entry.id]),
|
|
219
|
+
exit: 0,
|
|
220
|
+
ms: Date.now() - started,
|
|
221
|
+
});
|
|
222
|
+
return 0;
|
|
223
|
+
}
|
|
224
|
+
async function commandCheck(args) {
|
|
225
|
+
const root = workspaceRoot();
|
|
226
|
+
if (root === null) {
|
|
227
|
+
console.error('no .sddio/context/config.json above this directory');
|
|
228
|
+
return 1;
|
|
229
|
+
}
|
|
230
|
+
const started = Date.now();
|
|
231
|
+
const report = inspect(root);
|
|
232
|
+
if (args.includes('--claims')) {
|
|
233
|
+
const results = runClaims(root, readClaims(root));
|
|
234
|
+
const rendered = renderClaims(results);
|
|
235
|
+
process.stdout.write(rendered.text);
|
|
236
|
+
recordEvent(root, readVersion(), {
|
|
237
|
+
cmd: 'check --claims',
|
|
238
|
+
cursor: report.cursor.state,
|
|
239
|
+
out: measure(rendered.text, results.map((result) => result.id)),
|
|
240
|
+
exit: rendered.exit,
|
|
241
|
+
ms: Date.now() - started,
|
|
242
|
+
});
|
|
243
|
+
return rendered.exit;
|
|
244
|
+
}
|
|
245
|
+
if (args.includes('--json')) {
|
|
246
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
247
|
+
return renderCheck(report).exit;
|
|
248
|
+
}
|
|
249
|
+
const { text, ids, exit } = renderCheck(report);
|
|
250
|
+
process.stdout.write(text);
|
|
251
|
+
recordEvent(root, readVersion(), {
|
|
252
|
+
cmd: 'check',
|
|
253
|
+
cursor: report.cursor.state,
|
|
254
|
+
out: measure(text, ids),
|
|
255
|
+
exit,
|
|
256
|
+
ms: Date.now() - started,
|
|
257
|
+
});
|
|
258
|
+
return exit;
|
|
259
|
+
}
|
|
260
|
+
async function commandDiff(args) {
|
|
261
|
+
const root = workspaceRoot();
|
|
262
|
+
if (root === null) {
|
|
263
|
+
console.error('no .sddio/context/config.json above this directory');
|
|
264
|
+
return 1;
|
|
265
|
+
}
|
|
266
|
+
const started = Date.now();
|
|
267
|
+
const report = inspect(root);
|
|
268
|
+
if (args.includes('--json')) {
|
|
269
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
270
|
+
return 0;
|
|
271
|
+
}
|
|
272
|
+
const { text, ids } = renderDiff(report);
|
|
273
|
+
process.stdout.write(text);
|
|
274
|
+
recordEvent(root, readVersion(), {
|
|
275
|
+
cmd: 'diff',
|
|
276
|
+
cursor: report.cursor.state,
|
|
277
|
+
out: measure(text, ids),
|
|
278
|
+
exit: 0,
|
|
279
|
+
ms: Date.now() - started,
|
|
280
|
+
});
|
|
281
|
+
return 0;
|
|
282
|
+
}
|
|
283
|
+
async function commandStart(args) {
|
|
284
|
+
const root = workspaceRoot();
|
|
285
|
+
if (root === null) {
|
|
286
|
+
console.error('no .sddio/context/config.json above this directory');
|
|
287
|
+
return 1;
|
|
102
288
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
289
|
+
const started = Date.now();
|
|
290
|
+
const { text, ids } = renderBrief(root, args, { label: 'start', hint: true, budget: 10 });
|
|
291
|
+
process.stdout.write(text);
|
|
292
|
+
recordEvent(root, readVersion(), {
|
|
293
|
+
cmd: 'start',
|
|
294
|
+
args: { paths: args },
|
|
295
|
+
out: measure(text, ids),
|
|
296
|
+
exit: 0,
|
|
297
|
+
ms: Date.now() - started,
|
|
298
|
+
});
|
|
106
299
|
return 0;
|
|
107
300
|
}
|
|
108
301
|
async function main(args) {
|
|
@@ -123,8 +316,16 @@ async function main(args) {
|
|
|
123
316
|
switch (command) {
|
|
124
317
|
case 'init':
|
|
125
318
|
return await commandInit(rest);
|
|
126
|
-
case '
|
|
127
|
-
return await
|
|
319
|
+
case 'brief':
|
|
320
|
+
return await commandBrief(rest);
|
|
321
|
+
case 'show':
|
|
322
|
+
return await commandShow(rest);
|
|
323
|
+
case 'check':
|
|
324
|
+
return await commandCheck(rest);
|
|
325
|
+
case 'diff':
|
|
326
|
+
return await commandDiff(rest);
|
|
327
|
+
case 'start':
|
|
328
|
+
return await commandStart(rest);
|
|
128
329
|
default:
|
|
129
330
|
console.error(`Unknown command: ${command}\n`);
|
|
130
331
|
console.log(USAGE);
|
package/dist/cursor.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cursor, resolved against git (SPEC-010).
|
|
3
|
+
*
|
|
4
|
+
* One implementation for `brief`, `check`, `diff` and `start`, so four commands
|
|
5
|
+
* cannot disagree about whether the workspace is behind.
|
|
6
|
+
*/
|
|
7
|
+
import { execFileSync } from 'node:child_process';
|
|
8
|
+
function run(root, args) {
|
|
9
|
+
try {
|
|
10
|
+
return execFileSync('git', args, { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
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
|
+
function exists(root, sha) {
|
|
26
|
+
return ok(root, ['cat-file', '-e', `${sha}^{commit}`]);
|
|
27
|
+
}
|
|
28
|
+
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 };
|
|
33
|
+
}
|
|
34
|
+
if (last === null) {
|
|
35
|
+
return { state: 'unknown', behind: 0, last };
|
|
36
|
+
}
|
|
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 };
|
|
42
|
+
}
|
|
43
|
+
if (!ok(root, ['merge-base', '--is-ancestor', last, 'HEAD'])) {
|
|
44
|
+
return { state: 'rewritten', behind: 0, last };
|
|
45
|
+
}
|
|
46
|
+
const behind = Number(run(root, ['rev-list', '--count', `${last}..HEAD`]) ?? '0');
|
|
47
|
+
return { state: behind === 0 ? 'current' : 'behind', behind, last };
|
|
48
|
+
}
|
|
49
|
+
/** The one clause a command prints about the cursor. */
|
|
50
|
+
export function describe(state) {
|
|
51
|
+
switch (state.state) {
|
|
52
|
+
case 'current':
|
|
53
|
+
return 'current';
|
|
54
|
+
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';
|
|
60
|
+
case 'unknown':
|
|
61
|
+
return 'no baseline';
|
|
62
|
+
case 'nogit':
|
|
63
|
+
return 'not a git repository';
|
|
64
|
+
}
|
|
65
|
+
}
|
package/dist/events.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local observation log (contract 12).
|
|
3
|
+
*
|
|
4
|
+
* One JSON object per command call, appended to `.sddio/evals/events.jsonl`.
|
|
5
|
+
* The file is gitignored, never leaves the machine, and nothing reads it to do
|
|
6
|
+
* work — deleting it costs history and nothing else.
|
|
7
|
+
*
|
|
8
|
+
* Recording must never change what a command does. Every failure in here is
|
|
9
|
+
* swallowed: an observation that can break a command is worse than a missing
|
|
10
|
+
* observation.
|
|
11
|
+
*/
|
|
12
|
+
import { appendFileSync, mkdirSync } from 'node:fs';
|
|
13
|
+
import { dirname, join } from 'node:path';
|
|
14
|
+
export function eventsPath(root) {
|
|
15
|
+
return join(root, '.sddio', 'evals', 'events.jsonl');
|
|
16
|
+
}
|
|
17
|
+
export function recordEvent(root, version, event) {
|
|
18
|
+
if (process.env.SDDIO_NO_EVENTS === '1') {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const path = eventsPath(root);
|
|
23
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
24
|
+
appendFileSync(path, `${JSON.stringify({ ts: new Date().toISOString(), v: version, ...event })}\n`, 'utf8');
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
// Silent by design; see the header.
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** Measure an output before it is printed, so the log and the screen agree. */
|
|
31
|
+
export function measure(text, ids) {
|
|
32
|
+
return {
|
|
33
|
+
lines: text.split('\n').length - (text.endsWith('\n') ? 1 : 0),
|
|
34
|
+
bytes: Buffer.byteLength(text, 'utf8'),
|
|
35
|
+
ids,
|
|
36
|
+
};
|
|
37
|
+
}
|
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook selection (SPEC-018).
|
|
3
|
+
*
|
|
4
|
+
* A hook decides when sddio is told to reconcile; sddio never calls one. `init`
|
|
5
|
+
* records the choice in `config.json` and, for `flow-trail`, runs the same
|
|
6
|
+
* bootstrap this repository uses — the integration is dogfooded or it is not
|
|
7
|
+
* tested at all.
|
|
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.
|
|
12
|
+
*/
|
|
13
|
+
import { spawnSync } from 'node:child_process';
|
|
14
|
+
import { readFileSync } from 'node:fs';
|
|
15
|
+
import { join } from 'node:path';
|
|
16
|
+
export const HOOKS = [
|
|
17
|
+
{
|
|
18
|
+
id: 'flow-trail',
|
|
19
|
+
kind: 'external',
|
|
20
|
+
events: ['knowledge.reconcile'],
|
|
21
|
+
summary: 'a board of folders in git; calls sddio when a card closes',
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
export const DEFAULT_HOOK = 'flow-trail';
|
|
25
|
+
/** The paste block flow-trail publishes; kept verbatim so both routes install the same thing. */
|
|
26
|
+
export const FLOW_TRAIL_BOOTSTRAP = 'bash -c "$(curl -fsSL https://raw.githubusercontent.com/benxgao/flow-trail/HEAD/scripts/bootstrap.sh)"';
|
|
27
|
+
export function hookEntry(id) {
|
|
28
|
+
const hook = HOOKS.find((candidate) => candidate.id === id);
|
|
29
|
+
if (hook === undefined) {
|
|
30
|
+
throw new Error(`Unknown hook: ${id}. Known hooks: ${HOOKS.map((h) => h.id).join(', ')}, none`);
|
|
31
|
+
}
|
|
32
|
+
return hook;
|
|
33
|
+
}
|
|
34
|
+
export function declarationsFor(id) {
|
|
35
|
+
if (id === 'none') {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
const { id: hookId, kind, events } = hookEntry(id);
|
|
39
|
+
return [{ id: hookId, kind, events }];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Has this project already answered? An empty array is an answer — "none" —
|
|
43
|
+
* so the presence of the key decides, not its length.
|
|
44
|
+
*/
|
|
45
|
+
export function hasDeclaredHooks(cwd) {
|
|
46
|
+
try {
|
|
47
|
+
const config = JSON.parse(readFileSync(join(cwd, '.sddio', 'context', 'config.json'), 'utf8'));
|
|
48
|
+
return Array.isArray(config.hooks);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Runs the hook's own installer in the target project. `stdio: inherit` is
|
|
56
|
+
* deliberate: the bootstrap prints every path it touches, and hiding that
|
|
57
|
+
* behind a spinner would leave the user guessing what landed in their repo.
|
|
58
|
+
*/
|
|
59
|
+
export function installFlowTrail(cwd) {
|
|
60
|
+
const result = spawnSync('bash', ['-c', FLOW_TRAIL_BOOTSTRAP], { cwd, stdio: 'inherit' });
|
|
61
|
+
if (result.error !== undefined) {
|
|
62
|
+
return { ok: false, message: result.error.message };
|
|
63
|
+
}
|
|
64
|
+
if (result.status !== 0) {
|
|
65
|
+
return { ok: false, message: `installer exited with ${String(result.status)}` };
|
|
66
|
+
}
|
|
67
|
+
return { ok: true, message: 'flow-trail installed' };
|
|
68
|
+
}
|
package/dist/init.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `sddio init` — lay down `.sddio/` and `
|
|
2
|
+
* `sddio init` — lay down `.sddio/` and `sddio_docs/` in a project.
|
|
3
3
|
*
|
|
4
4
|
* Ownership rules (ADR-001, SPEC-003):
|
|
5
5
|
* - `.sddio/` is package-owned: refreshed on every run, so upgrades carry the
|
|
6
6
|
* current context layer.
|
|
7
|
-
* - `
|
|
7
|
+
* - `sddio_docs/` is user-owned: created once, never overwritten unless
|
|
8
8
|
* `--force`.
|
|
9
9
|
*
|
|
10
10
|
* The two roots are produced differently on purpose (ADR-005). `.sddio/` is
|
|
11
|
-
* copied from the tarball. `
|
|
11
|
+
* copied from the tarball. `sddio_docs/` is only a layout — directories
|
|
12
12
|
* plus empty seed files — so it is built from `lib/workspace.ts` rather than
|
|
13
13
|
* from template files, and empty directories survive because they are created
|
|
14
14
|
* explicitly rather than carried by the package.
|
|
@@ -17,6 +17,7 @@ import { copyFile, mkdir, readdir, readFile, writeFile } from 'node:fs/promises'
|
|
|
17
17
|
import { existsSync } from 'node:fs';
|
|
18
18
|
import { dirname, join, resolve } from 'node:path';
|
|
19
19
|
import { ensureAgentsSnippet } from './agents.js';
|
|
20
|
+
import { declarationsFor, installFlowTrail } from './hooks.js';
|
|
20
21
|
import { contextTemplateRoot } from './paths.js';
|
|
21
22
|
import { WORKSPACE_DIRS, WORKSPACE_SEEDS } from './workspace.js';
|
|
22
23
|
function toSegments(relativePath) {
|
|
@@ -36,13 +37,51 @@ async function listFiles(root, prefix = '') {
|
|
|
36
37
|
}
|
|
37
38
|
return files.sort();
|
|
38
39
|
}
|
|
40
|
+
/**
|
|
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.
|
|
45
|
+
*/
|
|
46
|
+
const CONFIG_FILE = 'context/config.json';
|
|
47
|
+
function mergeConfig(existing, incoming, chosen) {
|
|
48
|
+
const template = JSON.parse(incoming);
|
|
49
|
+
if (existing === null) {
|
|
50
|
+
return chosen === null
|
|
51
|
+
? incoming
|
|
52
|
+
: `${JSON.stringify({ ...template, hooks: chosen }, null, 2)}\n`;
|
|
53
|
+
}
|
|
54
|
+
let previous;
|
|
55
|
+
try {
|
|
56
|
+
previous = JSON.parse(existing);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
previous = {};
|
|
60
|
+
}
|
|
61
|
+
const declared = chosen ?? (Array.isArray(previous.hooks) ? previous.hooks : template.hooks);
|
|
62
|
+
return `${JSON.stringify({ ...template, hooks: declared }, null, 2)}\n`;
|
|
63
|
+
}
|
|
39
64
|
/** `.sddio/` — package-owned, copied as `templates/.sddio/<path>` → `.sddio/<path>`. */
|
|
40
|
-
async function copyContext(target, dryRun, result) {
|
|
65
|
+
async function copyContext(target, dryRun, chosen, result) {
|
|
41
66
|
for (const relativePath of await listFiles(contextTemplateRoot)) {
|
|
42
67
|
const source = join(contextTemplateRoot, ...toSegments(relativePath));
|
|
43
68
|
const destination = join(target, '.sddio', ...toSegments(relativePath));
|
|
44
69
|
const exists = existsSync(destination);
|
|
45
70
|
try {
|
|
71
|
+
if (relativePath === CONFIG_FILE) {
|
|
72
|
+
const current = exists ? await readFile(destination, 'utf8') : null;
|
|
73
|
+
const merged = mergeConfig(current, await readFile(source, 'utf8'), chosen);
|
|
74
|
+
if (current === merged) {
|
|
75
|
+
result.skipped.push(`.sddio/${relativePath}`);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (!dryRun) {
|
|
79
|
+
await mkdir(dirname(destination), { recursive: true });
|
|
80
|
+
await writeFile(destination, merged, 'utf8');
|
|
81
|
+
}
|
|
82
|
+
(exists ? result.overwritten : result.created).push(`.sddio/${relativePath}`);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
46
85
|
if (exists && (await readFile(destination)).equals(await readFile(source))) {
|
|
47
86
|
result.skipped.push(`.sddio/${relativePath}`);
|
|
48
87
|
continue;
|
|
@@ -58,7 +97,7 @@ async function copyContext(target, dryRun, result) {
|
|
|
58
97
|
}
|
|
59
98
|
}
|
|
60
99
|
}
|
|
61
|
-
/** `
|
|
100
|
+
/** `sddio_docs/` — user-owned: directories plus empty seeds. */
|
|
62
101
|
async function seedWorkspace(target, options, result) {
|
|
63
102
|
const dryRun = options.dryRun === true;
|
|
64
103
|
for (const directory of WORKSPACE_DIRS) {
|
|
@@ -106,12 +145,28 @@ async function registerAgents(target, dryRun, result) {
|
|
|
106
145
|
export async function runInit(options) {
|
|
107
146
|
const target = resolve(options.cwd);
|
|
108
147
|
const dryRun = options.dryRun === true;
|
|
109
|
-
const
|
|
148
|
+
const chosen = options.hook === undefined ? null : declarationsFor(options.hook);
|
|
149
|
+
const result = {
|
|
150
|
+
target,
|
|
151
|
+
dryRun,
|
|
152
|
+
created: [],
|
|
153
|
+
skipped: [],
|
|
154
|
+
overwritten: [],
|
|
155
|
+
errors: [],
|
|
156
|
+
hook: options.hook ?? null,
|
|
157
|
+
install: null,
|
|
158
|
+
};
|
|
110
159
|
if (!existsSync(contextTemplateRoot)) {
|
|
111
160
|
throw new Error(`Templates are missing from the package: ${contextTemplateRoot}`);
|
|
112
161
|
}
|
|
113
|
-
await copyContext(target, dryRun, result);
|
|
162
|
+
await copyContext(target, dryRun, chosen, result);
|
|
114
163
|
await seedWorkspace(target, options, result);
|
|
115
164
|
await registerAgents(target, dryRun, result);
|
|
165
|
+
if (!dryRun && options.install === true && options.hook === 'flow-trail') {
|
|
166
|
+
result.install = installFlowTrail(target);
|
|
167
|
+
if (!result.install.ok) {
|
|
168
|
+
result.errors.push(`flow-trail: ${result.install.message}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
116
171
|
return result;
|
|
117
172
|
}
|
package/dist/prompt.js
CHANGED
|
@@ -18,14 +18,15 @@ export const BOOTSTRAP_PROMPT = [
|
|
|
18
18
|
'',
|
|
19
19
|
'1. Run the commit check in `.sddio/context/instructions/reconciliation.md`.',
|
|
20
20
|
' `config.json` has no baseline yet, so the state is `unknown`.',
|
|
21
|
-
'2. Bootstrap
|
|
22
|
-
'
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
'
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'
|
|
21
|
+
'2. Bootstrap as described in `instructions/bootstrap.md`, but do not describe the',
|
|
22
|
+
' code back to me. Record only what the repository cannot say: a reversed',
|
|
23
|
+
' decision and why, an outside constraint and its deadline, an abandoned path.',
|
|
24
|
+
' At most six SPEC entries, each ending with `Not in the code:`.',
|
|
25
|
+
'3. Ask me up to three questions whose answers would change future work, and',
|
|
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).',
|
|
29
30
|
'',
|
|
30
31
|
'Then answer this: <your first task>',
|
|
31
32
|
].join('\n');
|
|
@@ -40,9 +41,10 @@ export const RECONCILE_PROMPT = [
|
|
|
40
41
|
'artifacts against the current implementation. Do not rescan unrelated areas, and',
|
|
41
42
|
'do not rewrite artifacts that are still accurate.',
|
|
42
43
|
'',
|
|
43
|
-
'Report what you understood and what you changed, then set
|
|
44
|
-
'to `HEAD` and `previousCommit`
|
|
45
|
-
'(`null` at a root commit), so the next
|
|
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.',
|
|
46
48
|
'',
|
|
47
49
|
'Then answer this: <your first task>',
|
|
48
50
|
].join('\n');
|