@llman-sdd/core 0.10.1 → 0.12.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.
Files changed (119) hide show
  1. package/package.json +11 -8
  2. package/src/archive/freeze.ts +41 -15
  3. package/src/archive/frozenCard.ts +57 -9
  4. package/src/archive/ignoreChain.ts +2 -6
  5. package/src/archive/sevenzip.ts +0 -1
  6. package/src/change/closeOutHarness.ts +17 -0
  7. package/src/change/collect.ts +0 -5
  8. package/src/change/frontmatter.ts +15 -7
  9. package/src/change/id.ts +0 -2
  10. package/src/change/lifecycle.ts +53 -94
  11. package/src/config/changeId.ts +0 -2
  12. package/src/config/load.ts +0 -4
  13. package/src/config/schema.ts +24 -13
  14. package/src/config/surface.ts +2 -12
  15. package/src/context/sddState.ts +23 -18
  16. package/src/git/spawnGit.ts +0 -3
  17. package/src/hints/jitHints.ts +82 -0
  18. package/src/index.ts +462 -39
  19. package/src/init/defaultConfig.ts +4 -13
  20. package/src/init/init.ts +108 -36
  21. package/src/init/skillCheck.ts +60 -0
  22. package/src/init/uncommentConfig.ts +909 -0
  23. package/src/locale.ts +0 -2
  24. package/src/project/migrateNotes.ts +0 -9
  25. package/src/project/migrations.ts +151 -9
  26. package/src/report/graph/analysis.ts +0 -4
  27. package/src/report/graph/nodes.ts +0 -6
  28. package/src/report/show.ts +7 -23
  29. package/src/report/specHelpers.ts +10 -14
  30. package/src/review/review.ts +0 -12
  31. package/src/spec/assignSpecIds.ts +0 -3
  32. package/src/spec/authoring.ts +16 -24
  33. package/src/spec/ir.ts +14 -5
  34. package/src/spec/keywords.ts +0 -2
  35. package/src/spec/machineKey.ts +49 -0
  36. package/src/spec/migrateNative.ts +4 -18
  37. package/src/spec/parser.ts +10 -19
  38. package/src/spec/reqRef.ts +135 -0
  39. package/src/studio/changeScope.ts +50 -0
  40. package/src/studio/changeScopeDiff.ts +195 -0
  41. package/src/studio/contracts.ts +493 -0
  42. package/src/studio/decisionTree.ts +206 -0
  43. package/src/studio/deeplink.ts +116 -0
  44. package/src/studio/demos.ts +167 -0
  45. package/src/studio/diff.ts +494 -0
  46. package/src/studio/drift.ts +738 -0
  47. package/src/studio/extract.ts +360 -0
  48. package/src/studio/featureSync.ts +592 -0
  49. package/src/studio/forest.ts +570 -0
  50. package/src/studio/index.ts +32 -0
  51. package/src/studio/model.ts +254 -0
  52. package/src/studio/revisions.ts +476 -0
  53. package/src/studio/search.ts +337 -0
  54. package/src/studio/store.ts +811 -0
  55. package/src/studio/sync.ts +912 -0
  56. package/src/studio/textfold.ts +72 -0
  57. package/src/studio/time.ts +107 -0
  58. package/src/studio/validate.ts +363 -0
  59. package/src/templates/embedded.ts +4 -6
  60. package/src/templates/engine.ts +1 -1
  61. package/src/templates/skills.ts +76 -51
  62. package/src/theorems/guard.ts +52 -0
  63. package/src/theorems/index.ts +56 -0
  64. package/src/theorems/migrate.ts +133 -0
  65. package/src/theorems/schema.ts +67 -0
  66. package/src/theorems/scope.ts +68 -0
  67. package/src/theorems/serialize.ts +60 -0
  68. package/src/theorems/transactionMachine.ts +247 -0
  69. package/src/theorems/validate.ts +141 -0
  70. package/src/util/nextNumber.ts +0 -2
  71. package/src/validation/changeCheck.ts +0 -24
  72. package/src/validation/flowAndNesting.ts +434 -0
  73. package/src/validation/harness.ts +108 -65
  74. package/src/validation/validate.ts +26 -12
  75. package/src/validation/xstateTransitions.ts +483 -184
  76. package/templates/zh-Hans/llmanspec-agents-stub.md +17 -2
  77. package/templates/zh-Hans/skills/llman-sdd-autopilot/SKILL.md +34 -0
  78. package/templates/zh-Hans/skills/llman-sdd-change/SKILL.md +44 -0
  79. package/templates/zh-Hans/skills/llman-sdd-change/playbooks/archive.md +15 -0
  80. package/templates/zh-Hans/skills/llman-sdd-change/playbooks/draft.md +9 -0
  81. package/templates/zh-Hans/skills/llman-sdd-review/SKILL.md +71 -0
  82. package/templates/zh-Hans/skills/llman-sdd-specs/SKILL.md +70 -0
  83. package/templates/zh-Hans/skills/llman-sdd-specs/playbooks/compact.md +12 -0
  84. package/templates/zh-Hans/skills/llman-sdd-specs/playbooks/doctor.md +26 -0
  85. package/templates/zh-Hans/skills/llman-sdd-specs/references/graph-dsl.md +33 -0
  86. package/templates/zh-Hans/skills/llman-sdd-studio/SKILL.md +33 -0
  87. package/templates/zh-Hans/skills/llman-sdd-studio/playbooks/collab.md +20 -0
  88. package/templates/zh-Hans/skills/llman-sdd-studio/playbooks/drift.md +52 -0
  89. package/templates/zh-Hans/skills/llman-sdd-studio/playbooks/onboard.md +33 -0
  90. package/templates/zh-Hans/units/skills/cli-footer.md +2 -2
  91. package/src/context/indexStore.ts +0 -171
  92. package/src/context/retrieve.ts +0 -332
  93. package/src/context/tree.ts +0 -112
  94. package/templates/zh-Hans/agents-root-stub.md +0 -9
  95. package/templates/zh-Hans/skills/llman-sdd-apply-cycle.md +0 -69
  96. package/templates/zh-Hans/skills/llman-sdd-apply.md +0 -117
  97. package/templates/zh-Hans/skills/llman-sdd-arch-review.md +0 -58
  98. package/templates/zh-Hans/skills/llman-sdd-archive.md +0 -79
  99. package/templates/zh-Hans/skills/llman-sdd-continue.md +0 -34
  100. package/templates/zh-Hans/skills/llman-sdd-draft.md +0 -53
  101. package/templates/zh-Hans/skills/llman-sdd-explore.md +0 -64
  102. package/templates/zh-Hans/skills/llman-sdd-ff.md +0 -33
  103. package/templates/zh-Hans/skills/llman-sdd-graph.md +0 -56
  104. package/templates/zh-Hans/skills/llman-sdd-propose.md +0 -107
  105. package/templates/zh-Hans/skills/llman-sdd-quick.md +0 -41
  106. package/templates/zh-Hans/skills/llman-sdd-research.md +0 -35
  107. package/templates/zh-Hans/skills/llman-sdd-specs-compact.md +0 -41
  108. package/templates/zh-Hans/skills/llman-sdd-validate.md +0 -28
  109. package/templates/zh-Hans/skills/llman-sdd-verify.md +0 -77
  110. package/templates/zh-Hans/skills/llman-sdd-wayfinder.md +0 -83
  111. package/templates/zh-Hans/units/skills/ethics-governance.md +0 -6
  112. package/templates/zh-Hans/units/skills/git-native-flow.md +0 -56
  113. package/templates/zh-Hans/units/skills/human-readable-summary.md +0 -9
  114. package/templates/zh-Hans/units/skills/index-fallback.md +0 -1
  115. package/templates/zh-Hans/units/skills/stage-guard.md +0 -17
  116. package/templates/zh-Hans/units/skills/structured-protocol.md +0 -19
  117. package/templates/zh-Hans/units/skills/validation-hints.md +0 -20
  118. package/templates/zh-Hans/units/skills/version-drift.md +0 -3
  119. package/templates/zh-Hans/units/spec/feature-contract.md +0 -8
package/src/init/init.ts CHANGED
@@ -15,6 +15,8 @@ import { writeSddState } from '../context/sddState.ts';
15
15
  import { DEFAULT_LOCALE, localeFallbacks, normalizeLocale } from '../locale.ts';
16
16
  import { renderTemplate } from '../templates/engine.ts';
17
17
  import {
18
+ MANUAL_INVOCATION_SKILLS,
19
+ OPENAI_EXPLICIT_POLICY,
18
20
  buildTemplateVars,
19
21
  enforceEthicsGovernance,
20
22
  loadLocaleResource,
@@ -24,6 +26,11 @@ import {
24
26
  } from '../templates/skills.ts';
25
27
  import { type FsPort } from '../util/fsPort.ts';
26
28
  import { DEFAULT_CONFIGS, LLMANSPEC_SCHEMA_URL, prependSchemaHeader } from './defaultConfig.ts';
29
+ import {
30
+ findUncommentConfig,
31
+ patchUncommentConfig,
32
+ type UncommentPatchResult,
33
+ } from './uncommentConfig.ts';
27
34
 
28
35
  const MARKER_START = '<!-- LLMANSPEC:START -->';
29
36
  const MARKER_END = '<!-- LLMANSPEC:END -->';
@@ -49,7 +56,32 @@ export function updateFileWithMarkers(content: string, body: string): string {
49
56
  return `${MARKER_START}\n\n${body}\n${MARKER_END}\n\n${content}`;
50
57
  }
51
58
 
52
- /** END-boundary suffix, guaranteed blank-line-separated from following content. */
59
+ /** Drop a root AGENTS.md managed block. `null` means the file should be removed. */
60
+ export function stripManagedBlock(content: string): string | null {
61
+ const start = content.indexOf(MARKER_START);
62
+ const end = content.indexOf(MARKER_END);
63
+ if (start === -1 && end === -1) return content;
64
+ if (start === -1 || end === -1 || end < start) {
65
+ if (start !== -1 && end !== -1 && end < start) {
66
+ throw new Error('Invalid marker state: end marker appears before start marker.');
67
+ }
68
+ return content;
69
+ }
70
+ const before = content.slice(0, start);
71
+ let after = content.slice(end + MARKER_END.length);
72
+ if (before === '') after = after.replace(/^(?:\r?\n)+/u, '');
73
+ else after = after.replace(/^(?:\r?\n)/u, '');
74
+ const rest = before + after;
75
+ if (rest.trim() === '') return null;
76
+ return rest.endsWith('\n') ? rest : `${rest}\n`;
77
+ }
78
+
79
+ function stripRootAgents(io: InitIo): void {
80
+ if (!io.exists('AGENTS.md')) return;
81
+ const next = stripManagedBlock(io.readText('AGENTS.md'));
82
+ if (next === null) io.remove('AGENTS.md');
83
+ else if (next !== io.readText('AGENTS.md')) io.writeText('AGENTS.md', next);
84
+ }
53
85
  function separatorAfterEndMarker(suffix: string): string {
54
86
  const br = /^\r?\n/u.exec(suffix);
55
87
  if (br === null) return suffix === '' ? '\n' : `\n\n${suffix}`;
@@ -63,7 +95,7 @@ export const TEMPLATES_ROOT = join(import.meta.dirname, '..', '..', 'templates')
63
95
  /** Repo-root-relative filesystem effects needed by the init flow. */
64
96
  export type InitIo = Pick<
65
97
  FsPort,
66
- 'exists' | 'readText' | 'writeText' | 'mkdirp' | 'listDir' | 'removeDir'
98
+ 'exists' | 'readText' | 'writeText' | 'mkdirp' | 'listDir' | 'removeDir' | 'remove'
67
99
  >;
68
100
 
69
101
  function writeDefaultConfig(io: InitIo, locale: string): void {
@@ -120,11 +152,21 @@ export interface InitResult {
120
152
  /** llman-sdd-* directories removed by --update namespace cleanup. */
121
153
  removed: string[];
122
154
  configPath: string;
155
+ /** Outcome of the idempotent uncomment-config patch (absent when no config file exists). */
156
+ uncomment?: UncommentConfigOutcome;
157
+ }
158
+
159
+ export interface UncommentConfigOutcome {
160
+ path: string;
161
+ changed: boolean;
162
+ addedPreserve: string[];
163
+ addedExclude: string[];
164
+ warning?: string;
123
165
  }
124
166
 
125
167
  const SKILLS_BASE = '.agents/skills';
126
168
 
127
- /** Managed AGENTS.md marker blocks (root + llmanspec), content-preserving. */
169
+ /** Managed llmanspec/AGENTS.md block, plus removal of a root AGENTS.md block. */
128
170
  function writeManagedBlocks(
129
171
  io: InitIo,
130
172
  templates: TemplateIo,
@@ -133,22 +175,22 @@ function writeManagedBlocks(
133
175
  ): void {
134
176
  const vars = buildTemplateVars(config, version);
135
177
  const locales = localeFallbacks(config.locale);
136
- for (const [stubPath, agentsPath] of [
137
- ['agents-root-stub.md', 'AGENTS.md'],
138
- ['llmanspec-agents-stub.md', 'llmanspec/AGENTS.md'],
139
- ] as const) {
140
- const stubRaw = loadLocaleResource(templates, TEMPLATES_ROOT, locales, stubPath);
141
- if (stubRaw === null) {
142
- // r19/r18: a missing built-in resource is a broken installation, not a
143
- // no-op — silent skips shipped AGENTS.md-less workspaces before.
144
- throw new Error(
145
- `template resource missing: ${stubPath} (locales tried: ${locales.join(', ')})`,
146
- );
147
- }
148
- const existing = io.exists(agentsPath) ? io.readText(agentsPath) : '';
149
- const body = renderTemplate(stubRaw, new Map(), vars);
150
- io.writeText(agentsPath, updateFileWithMarkers(existing, body));
178
+ const stubRaw = loadLocaleResource(
179
+ templates,
180
+ TEMPLATES_ROOT,
181
+ locales,
182
+ 'llmanspec-agents-stub.md',
183
+ );
184
+ if (stubRaw === null) {
185
+ throw new Error(
186
+ `template resource missing: llmanspec-agents-stub.md (locales tried: ${locales.join(', ')})`,
187
+ );
151
188
  }
189
+ const agentsPath = 'llmanspec/AGENTS.md';
190
+ const existing = io.exists(agentsPath) ? io.readText(agentsPath) : '';
191
+ const body = renderTemplate(stubRaw, new Map(), vars);
192
+ io.writeText(agentsPath, updateFileWithMarkers(existing, body));
193
+ stripRootAgents(io);
152
194
  }
153
195
 
154
196
  export function runInit(
@@ -159,12 +201,12 @@ export function runInit(
159
201
  locale?: string;
160
202
  version: string;
161
203
  skills: boolean;
204
+ uncomment?: boolean;
162
205
  onWarning?: (message: string) => void;
163
206
  },
164
207
  ): InitResult {
165
208
  io.mkdirp('llmanspec');
166
209
 
167
- // 1) config: create with defaults if missing, then always load.
168
210
  const configPath = 'llmanspec/config.yaml';
169
211
  const configExisted = io.exists(configPath);
170
212
  if (!configExisted) writeDefaultConfig(io, opts.locale ?? DEFAULT_LOCALE);
@@ -175,11 +217,11 @@ export function runInit(
175
217
  opts.onWarning,
176
218
  );
177
219
 
178
- // 1b) scaffold-state stamp: record the rendering version for drift notices
179
- // (version-awareness). Corrupt/missing state on later reads is silent-OK.
180
220
  writeSddState(io, opts.version);
181
221
 
182
- // 2) scaffold directories.
222
+ const uncomment =
223
+ opts.uncomment === false ? undefined : patchExistingUncommentConfig(io, opts.onWarning);
224
+
183
225
  io.mkdirp(SPECS_DIR);
184
226
  io.mkdirp(`${CHANGES_DIR}/archive`);
185
227
  if (!io.exists('llmanspec/specs/.gitkeep')) io.writeText('llmanspec/specs/.gitkeep', '');
@@ -187,18 +229,15 @@ export function runInit(
187
229
  io.writeText(`${CHANGES_DIR}/archive/.gitkeep`, '');
188
230
  }
189
231
 
190
- // 3) AGENTS.md managed blocks (root + llmanspec), preserving content.
191
232
  writeManagedBlocks(io, templates, config, opts.version);
192
233
  const vars = buildTemplateVars(config, opts.version);
193
234
  const skillTemplates = loadSkillTemplates(templates, TEMPLATES_ROOT, config, vars);
194
235
  enforceEthicsGovernance(skillTemplates);
195
236
 
196
- // 4) skills namespace cleanup (--update only): remove llman-sdd-* dirs
197
- // outside the candidate set; un-prefixed custom skills stay untouched.
198
237
  const removed: string[] = [];
199
238
  if (opts.skills && opts.update && io.exists(SKILLS_BASE)) {
200
- const candidates = new Set(skillCandidates(config).map((f) => f.replace(/\.md$/u, '')));
201
- for (const entry of io.listDir(SKILLS_BASE)) {
239
+ const candidates = new Set(skillCandidates(config));
240
+ for (const entry of io.listDir(SKILLS_BASE).toSorted()) {
202
241
  if (entry.startsWith('llman-sdd-') && !candidates.has(entry)) {
203
242
  io.removeDir(`${SKILLS_BASE}/${entry}`);
204
243
  removed.push(entry);
@@ -206,20 +245,53 @@ export function runInit(
206
245
  }
207
246
  }
208
247
 
209
- // 5) write candidates: rendered product trimmed + single trailing newline.
210
- // Sub-root instances default to no skills injection (r93): the agent skill
211
- // surface stays at the repo root and sub-root navigation lives in the
212
- // managed blocks; --skills opts a sub-root in.
213
248
  if (!opts.skills) {
214
- return { skills: [], removed, configPath };
249
+ return { skills: [], removed, configPath, ...(uncomment === undefined ? {} : { uncomment }) };
215
250
  }
216
251
  for (const t of skillTemplates) {
217
- const dirName = t.name.replace(/\.md$/u, '');
218
- io.mkdirp(`${SKILLS_BASE}/${dirName}`);
219
- io.writeText(`${SKILLS_BASE}/${dirName}/SKILL.md`, `${t.content.trimEnd()}\n`);
252
+ const dirName = t.name;
253
+ const skillDir = `${SKILLS_BASE}/${dirName}`;
254
+ if (opts.update && io.exists(skillDir)) {
255
+ io.removeDir(skillDir);
256
+ }
257
+ io.mkdirp(skillDir);
258
+ io.writeText(`${skillDir}/SKILL.md`, `${t.content.trimEnd()}\n`);
259
+ for (const nested of t.files) {
260
+ const target = `${skillDir}/${nested.relativePath}`;
261
+ const slashIdx = target.lastIndexOf('/');
262
+ if (slashIdx > 0) io.mkdirp(target.slice(0, slashIdx));
263
+ io.writeText(target, `${nested.content.trimEnd()}\n`);
264
+ }
265
+ if (MANUAL_INVOCATION_SKILLS.includes(dirName)) {
266
+ io.mkdirp(`${skillDir}/agents`);
267
+ io.writeText(`${skillDir}/agents/openai.yaml`, OPENAI_EXPLICIT_POLICY);
268
+ }
220
269
  }
221
270
 
222
- return { skills: skillTemplates.map((t) => t.name.replace(/\.md$/u, '')), removed, configPath };
271
+ return {
272
+ skills: skillTemplates.map((t) => t.name),
273
+ removed,
274
+ configPath,
275
+ ...(uncomment === undefined ? {} : { uncomment }),
276
+ };
277
+ }
278
+
279
+ function patchExistingUncommentConfig(
280
+ io: InitIo,
281
+ onWarning: ((message: string) => void) | undefined,
282
+ ): UncommentConfigOutcome | undefined {
283
+ const path = findUncommentConfig((candidate) => io.exists(candidate));
284
+ if (path === null) return undefined;
285
+ const patched: UncommentPatchResult = patchUncommentConfig(io.readText(path));
286
+ if (patched.warning !== undefined) onWarning?.(`WARNING: ${path}: ${patched.warning}`);
287
+ if (patched.changed) io.writeText(path, patched.content);
288
+ return {
289
+ path,
290
+ changed: patched.changed,
291
+ addedPreserve: patched.addedPreserve,
292
+ addedExclude: patched.addedExclude,
293
+ ...(patched.warning === undefined ? {} : { warning: patched.warning }),
294
+ };
223
295
  }
224
296
 
225
297
  /**
@@ -0,0 +1,60 @@
1
+ /**
2
+ * `init --check`: installed llman-sdd skill versions must share the CLI's
3
+ * major.minor. Patch may differ. Missing or unreadable versions fail.
4
+ */
5
+
6
+ const VERSION_RE = /version:\s*["']?(\d+\.\d+(?:\.\d+)?)["']?/u;
7
+
8
+ export function readSkillVersion(markdown: string): string | null {
9
+ if (!markdown.startsWith('---')) return null;
10
+ const end = markdown.indexOf('\n---', 3);
11
+ if (end < 0) return null;
12
+ const match = VERSION_RE.exec(markdown.slice(0, end));
13
+ return match?.[1] ?? null;
14
+ }
15
+
16
+ function part(version: string, index: number): number {
17
+ return Math.trunc(Number(version.split('.')[index] ?? '0')) || 0;
18
+ }
19
+
20
+ /** Compatible when major and minor both match. */
21
+ export function skillVersionCompatible(skillVersion: string, cliVersion: string): boolean {
22
+ return (
23
+ part(skillVersion, 0) === part(cliVersion, 0) && part(skillVersion, 1) === part(cliVersion, 1)
24
+ );
25
+ }
26
+
27
+ export interface SkillVersionCheck {
28
+ ok: boolean;
29
+ message: string;
30
+ }
31
+
32
+ export function checkSkillVersions(
33
+ skills: readonly { name: string; markdown: string }[],
34
+ cliVersion: string,
35
+ ): SkillVersionCheck {
36
+ if (skills.length === 0) {
37
+ return {
38
+ ok: false,
39
+ message: `no llman-sdd skills installed; run \`llman-sdd init --update\``,
40
+ };
41
+ }
42
+ const problems: string[] = [];
43
+ for (const skill of skills) {
44
+ const found = readSkillVersion(skill.markdown);
45
+ if (found === null) {
46
+ problems.push(`${skill.name}: metadata.version missing`);
47
+ continue;
48
+ }
49
+ if (!skillVersionCompatible(found, cliVersion)) {
50
+ problems.push(`${skill.name}: ${found} is outside ${cliVersion} (same major.minor required)`);
51
+ }
52
+ }
53
+ if (problems.length > 0) {
54
+ return {
55
+ ok: false,
56
+ message: `${problems.join('\n')}\nrun \`llman-sdd init --update\``,
57
+ };
58
+ }
59
+ return { ok: true, message: `skill versions match llman-sdd ${cliVersion}` };
60
+ }