@llman-sdd/core 0.8.2 → 0.10.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 (89) hide show
  1. package/package.json +1 -1
  2. package/src/archive/freeze.ts +15 -15
  3. package/src/archive/frozenCard.ts +3 -2
  4. package/src/change/collect.ts +17 -14
  5. package/src/change/deps.ts +54 -0
  6. package/src/change/frontmatter.ts +36 -5
  7. package/src/change/lifecycle.ts +124 -20
  8. package/src/change/nextId.ts +21 -7
  9. package/src/config/changeId.ts +0 -6
  10. package/src/config/load.ts +36 -2
  11. package/src/config/schema.ts +3 -7
  12. package/src/context/indexStore.ts +14 -14
  13. package/src/context/sddState.ts +1 -13
  14. package/src/context/tree.ts +9 -19
  15. package/src/git/spawnGit.ts +5 -1
  16. package/src/index.ts +37 -12
  17. package/src/init/defaultConfig.ts +14 -31
  18. package/src/init/init.ts +92 -30
  19. package/src/locale.ts +33 -0
  20. package/src/project/migrations.ts +196 -60
  21. package/src/report/graph/deps.ts +3 -38
  22. package/src/report/graph/nodes.ts +13 -19
  23. package/src/report/graph/types.ts +2 -6
  24. package/src/report/show.ts +16 -8
  25. package/src/report/specHelpers.ts +22 -28
  26. package/src/review/review.ts +18 -31
  27. package/src/self/completion.ts +206 -0
  28. package/src/spec/assignSpecIds.ts +9 -1
  29. package/src/spec/authoring.ts +11 -11
  30. package/src/spec/parser.ts +3 -1
  31. package/src/templates/skills.ts +3 -23
  32. package/src/util/datedId.ts +18 -0
  33. package/src/util/fsPort.ts +24 -0
  34. package/src/util/nextNumber.ts +30 -0
  35. package/src/util/semver.ts +21 -0
  36. package/src/validation/changeCheck.ts +133 -67
  37. package/src/validation/crossRoot.ts +86 -0
  38. package/src/validation/discover.ts +22 -13
  39. package/src/validation/roots.ts +2 -5
  40. package/src/validation/validate.ts +10 -19
  41. package/src/validation/{transitions.ts → xstateTransitions.ts} +81 -69
  42. package/templates/zh-Hans/skills/llman-sdd-apply-cycle.md +9 -7
  43. package/templates/zh-Hans/skills/llman-sdd-apply.md +5 -5
  44. package/templates/zh-Hans/skills/llman-sdd-archive.md +11 -2
  45. package/templates/zh-Hans/skills/llman-sdd-continue.md +1 -1
  46. package/templates/zh-Hans/skills/llman-sdd-draft.md +1 -1
  47. package/templates/zh-Hans/skills/llman-sdd-explore.md +2 -2
  48. package/templates/zh-Hans/skills/llman-sdd-ff.md +1 -1
  49. package/templates/zh-Hans/skills/llman-sdd-propose.md +8 -6
  50. package/templates/zh-Hans/skills/llman-sdd-quick.md +1 -1
  51. package/templates/zh-Hans/skills/llman-sdd-validate.md +1 -1
  52. package/templates/zh-Hans/skills/llman-sdd-verify.md +2 -2
  53. package/templates/zh-Hans/skills/llman-sdd-wayfinder.md +1 -1
  54. package/templates/zh-Hans/units/skills/git-native-flow.md +12 -6
  55. package/templates/zh-Hans/units/skills/index-fallback.md +1 -0
  56. package/templates/zh-Hans/units/skills/structured-protocol.md +1 -6
  57. package/templates/zh-Hans/units/spec/feature-contract.md +5 -33
  58. package/src/templates/locale.ts +0 -24
  59. package/templates/en/agents-root-stub.md +0 -9
  60. package/templates/en/llmanspec-agents-stub.md +0 -6
  61. package/templates/en/skills/llman-sdd-apply-cycle.md +0 -67
  62. package/templates/en/skills/llman-sdd-apply.md +0 -117
  63. package/templates/en/skills/llman-sdd-arch-review.md +0 -58
  64. package/templates/en/skills/llman-sdd-archive.md +0 -70
  65. package/templates/en/skills/llman-sdd-continue.md +0 -34
  66. package/templates/en/skills/llman-sdd-draft.md +0 -53
  67. package/templates/en/skills/llman-sdd-explore.md +0 -64
  68. package/templates/en/skills/llman-sdd-ff.md +0 -33
  69. package/templates/en/skills/llman-sdd-graph.md +0 -56
  70. package/templates/en/skills/llman-sdd-propose.md +0 -105
  71. package/templates/en/skills/llman-sdd-quick.md +0 -41
  72. package/templates/en/skills/llman-sdd-research.md +0 -35
  73. package/templates/en/skills/llman-sdd-specs-compact.md +0 -41
  74. package/templates/en/skills/llman-sdd-validate.md +0 -28
  75. package/templates/en/skills/llman-sdd-verify.md +0 -77
  76. package/templates/en/skills/llman-sdd-wayfinder.md +0 -83
  77. package/templates/en/units/skills/cli-footer.md +0 -2
  78. package/templates/en/units/skills/ethics-governance.md +0 -6
  79. package/templates/en/units/skills/git-native-flow-brief.md +0 -10
  80. package/templates/en/units/skills/git-native-flow.md +0 -50
  81. package/templates/en/units/skills/human-readable-summary.md +0 -9
  82. package/templates/en/units/skills/stage-guard.md +0 -17
  83. package/templates/en/units/skills/structured-protocol.md +0 -24
  84. package/templates/en/units/skills/validation-hints.md +0 -20
  85. package/templates/en/units/skills/version-drift.md +0 -3
  86. package/templates/en/units/spec/feature-contract.md +0 -38
  87. package/templates/en/units/workflow/archive-freeze-guidance.md +0 -9
  88. package/templates/zh-Hans/units/skills/git-native-flow-brief.md +0 -10
  89. package/templates/zh-Hans/units/workflow/archive-freeze-guidance.md +0 -10
@@ -1,3 +1,4 @@
1
+ import { type FsPort } from '../util/fsPort.ts';
1
2
  /**
2
3
  * Index orchestration (context-index capability, r26): rebuild writes the
3
4
  * pageindex tree under a create-new lock; check compares the stored spec_hash
@@ -12,20 +13,19 @@ export const TREE_JSON_REL = `${PAGEINDEX_DIR_REL}/tree.json`;
12
13
  export const REBUILD_LOCK_REL = `${PAGEINDEX_DIR_REL}/.rebuild.lock`;
13
14
  const LOCK_MAX_AGE_MS = 6 * 60 * 60 * 1000;
14
15
 
15
- export interface IndexIo {
16
- exists(path: string): boolean;
17
- readText(path: string): string;
18
- writeText(path: string, content: string): void;
19
- remove(path: string): void;
20
- isDirectory(path: string): boolean;
21
- listDir(path: string): string[];
22
- mkdirp(path: string): void;
23
- processAlive(pid: number): boolean;
24
- /** Current process id for the rebuild lock (side effect injected, r3). */
25
- currentPid(): number;
26
- /** Wall clock for lock timestamps / staleness (side effect injected, r3). */
27
- now(): Date;
28
- }
16
+ export type IndexIo = Pick<
17
+ FsPort,
18
+ | 'exists'
19
+ | 'readText'
20
+ | 'writeText'
21
+ | 'remove'
22
+ | 'isDirectory'
23
+ | 'listDir'
24
+ | 'mkdirp'
25
+ | 'processAlive'
26
+ | 'currentPid'
27
+ | 'now'
28
+ >;
29
29
 
30
30
  export interface RebuildOpts {
31
31
  chatModel: string;
@@ -46,16 +46,4 @@ export function readSddState(io: Pick<StateIo, 'exists' | 'readText'>): SddState
46
46
  }
47
47
  }
48
48
 
49
- const dot = (v: string): number => Math.trunc(Number(v)) || 0;
50
-
51
- /** Numeric semver-major.minor.patch compare; non-numeric segments compare 0. */
52
- export function semverLt(a: string, b: string): boolean {
53
- const pa = a.split('.');
54
- const pb = b.split('.');
55
- for (let i = 0; i < 3; i++) {
56
- const ai = dot(pa[i] ?? '0');
57
- const bi = dot(pb[i] ?? '0');
58
- if (ai !== bi) return ai < bi;
59
- }
60
- return false;
61
- }
49
+ export { semverLt } from '../util/semver.ts';
@@ -4,9 +4,10 @@
4
4
  * predecessor's tree.json so retrieval IDs stay comparable.
5
5
  */
6
6
  import { createHash } from 'node:crypto';
7
- import { join } from 'node:path';
8
7
 
9
8
  import { specIdOf } from '../spec/ir.ts';
9
+ import { type FsPort } from '../util/fsPort.ts';
10
+ import { discoverFeatureFiles } from '../validation/discover.ts';
10
11
  import type { SpecEntry } from '../validation/validate.ts';
11
12
 
12
13
  export const TREE_VERSION = 1;
@@ -96,27 +97,16 @@ export function buildTreeIndex(
96
97
  };
97
98
  }
98
99
 
99
- export interface HashIo {
100
- exists(p: string): boolean;
101
- isDirectory(p: string): boolean;
102
- listDir(p: string): string[];
103
- readText(p: string): string;
104
- }
100
+ export type HashIo = Pick<FsPort, 'exists' | 'isDirectory' | 'listDir' | 'readText'>;
105
101
 
106
102
  /** sha256 over all .feature files, sorted by path (r26 freshness anchor). */
107
103
  export function computeSpecHash(specsDir: string, io: HashIo): string {
108
104
  const hash = createHash('sha256');
109
- const walk = (dir: string): void => {
110
- if (!io.exists(dir) || !io.isDirectory(dir)) return;
111
- for (const name of io.listDir(dir).toSorted()) {
112
- const full = join(dir, name);
113
- if (io.isDirectory(full)) walk(full);
114
- else if (name.endsWith('.feature')) {
115
- hash.update(full);
116
- hash.update(io.readText(full));
117
- }
118
- }
119
- };
120
- walk(specsDir);
105
+ // T24: shared discovery — the hashed path set/order is exactly the parser's,
106
+ // so editing specs cannot desynchronize freshness from parse coverage.
107
+ for (const full of discoverFeatureFiles(specsDir.replace(/\\/g, '/').replace(/\/$/u, ''), io)) {
108
+ hash.update(full);
109
+ hash.update(io.readText(full));
110
+ }
121
111
  return hash.digest('hex');
122
112
  }
@@ -141,6 +141,8 @@ export interface WorktreeEntry {
141
141
  head: string | null;
142
142
  /** Checked-out local branch (`refs/heads/` stripped); null when detached/bare. */
143
143
  branch: string | null;
144
+ /** `prunable` porcelain attribute: the worktree directory is missing or broken. */
145
+ prunable: boolean;
144
146
  }
145
147
 
146
148
  /** Parse `git worktree list --porcelain` into entries (r69 held-target detection). */
@@ -151,13 +153,15 @@ export function worktreeList(git: GitLike): WorktreeEntry[] {
151
153
  for (const line of out.split('\n')) {
152
154
  if (line.startsWith('worktree ')) {
153
155
  if (current !== null) entries.push(current);
154
- current = { path: line.slice('worktree '.length), head: null, branch: null };
156
+ current = { path: line.slice('worktree '.length), head: null, branch: null, prunable: false };
155
157
  } else if (current === null) {
156
158
  continue;
157
159
  } else if (line.startsWith('HEAD ')) {
158
160
  current.head = line.slice('HEAD '.length);
159
161
  } else if (line.startsWith('branch ')) {
160
162
  current.branch = line.slice('branch '.length).replace(/^refs\/heads\//u, '');
163
+ } else if (line.startsWith('prunable')) {
164
+ current.prunable = true;
161
165
  }
162
166
  // `detached` / `bare` marker lines leave branch null on purpose.
163
167
  }
package/src/index.ts CHANGED
@@ -18,7 +18,6 @@ export {
18
18
  export {
19
19
  ChangeIdError,
20
20
  compileChangeIdPattern,
21
- nextUniqueNumber,
22
21
  renderChangeIdTemplate,
23
22
  } from './config/changeId.ts';
24
23
  export { renderConfigOverview, skillsJson } from './config/surface.ts';
@@ -64,12 +63,15 @@ export {
64
63
  export { stripLegacyHeaderLines } from './spec/migrateScope.ts';
65
64
  export {
66
65
  MIGRATIONS,
67
- findMigration,
68
- knownMigrationIds,
69
- isValidMigrationExpr,
70
- migrationPrompt,
66
+ compareVersions,
67
+ isValidVersion,
68
+ knownMigrationVersions,
71
69
  migrationOverviewLines,
72
- type MigrationEntry,
70
+ migrationPrompt,
71
+ parseVersionExpr,
72
+ resolveMigrations,
73
+ type MigrationDoc,
74
+ type MigrationItem,
73
75
  } from './project/migrations.ts';
74
76
  export {
75
77
  MIGRATE_KINDS,
@@ -89,7 +91,6 @@ export {
89
91
  } from './spec/authoring.ts';
90
92
  export type {
91
93
  SpecEntry,
92
- SpecIo,
93
94
  SpecVerdict,
94
95
  ValidationItem,
95
96
  ValidationLevel,
@@ -98,16 +99,17 @@ export type {
98
99
  export { validateAllSpecs, validateCapability } from './validation/validate.ts';
99
100
  export { buildDuplicatesFor, formatTotals } from './validation/validate.ts';
100
101
  export {
102
+ TRANSITIONS_INTROSPECTION,
101
103
  isTransitionOutline,
102
- parseTransitionExpr,
103
- validateTransitionScenario,
104
+ type TransitionDecision,
104
105
  type TransitionEdge,
105
- } from './validation/transitions.ts';
106
+ } from './validation/xstateTransitions.ts';
106
107
  export { splitVerb } from './config/changeId.ts';
107
108
  export {
108
109
  checkChangeDoc,
109
110
  validateChange,
110
111
  checkGlobalChangeIdUniqueness,
112
+ collectChangeIdValues,
111
113
  STAGE_ORDER,
112
114
  type ChangeCheckConfig,
113
115
  type ChangeCheckInput,
@@ -125,6 +127,12 @@ export {
125
127
  type RootEntry,
126
128
  type RootsIo,
127
129
  } from './validation/roots.ts';
130
+ export {
131
+ computeCrossRootCollisions,
132
+ type CrossRootCollision,
133
+ type CrossRootNamespace,
134
+ type RootNamespaceValues,
135
+ } from './validation/crossRoot.ts';
128
136
  export {
129
137
  expandRunCommand,
130
138
  runHarnessForSpecs,
@@ -140,6 +148,7 @@ export {
140
148
  extractFrontmatter,
141
149
  readFrontmatterTitle,
142
150
  readNeedsSpecsChange,
151
+ specsPrefixOfInstance,
143
152
  } from './change/frontmatter.ts';
144
153
  export {
145
154
  GitError,
@@ -184,7 +193,7 @@ export {
184
193
  archiveTaskGate,
185
194
  changeDiffInfo,
186
195
  } from './change/lifecycle.ts';
187
- export { normalizeLocale, localeFallbacks } from './templates/locale.ts';
196
+ export { normalizeLocale, localeFallbacks, DEFAULT_LOCALE } from './locale.ts';
188
197
  export {
189
198
  MAX_UNIT_NESTING_DEPTH,
190
199
  renderTemplate,
@@ -194,7 +203,6 @@ export {
194
203
  export {
195
204
  ETHICS_KEYS,
196
205
  buildTemplateVars,
197
- effectiveCheckCommand,
198
206
  enforceEthicsGovernance,
199
207
  loadLocaleResource,
200
208
  loadSkillTemplates,
@@ -212,12 +220,14 @@ export {
212
220
  export {
213
221
  TEMPLATES_ROOT,
214
222
  refreshSubRootBlocks,
223
+ resolveEffectiveLocale,
215
224
  runInit,
216
225
  updateFileWithMarkers,
217
226
  type InitIo,
218
227
  type InitResult,
219
228
  } from './init/init.ts';
220
229
  export {
230
+ changeTitle,
221
231
  collectChanges,
222
232
  statusFor,
223
233
  stageFor,
@@ -327,3 +337,18 @@ export {
327
337
  type TierEntry,
328
338
  type TreeToolDeps,
329
339
  } from './context/retrieve.ts';
340
+ export { maxUsedNumber, nextNumber } from './util/nextNumber.ts';
341
+ export {
342
+ COMPLETION_BIN,
343
+ COMPLETION_MARKER_END,
344
+ COMPLETION_MARKER_START,
345
+ COMPLETION_SHELLS,
346
+ collectFlags,
347
+ completionBlock,
348
+ isCompletionShell,
349
+ renderCompletionScript,
350
+ resolveBashRc,
351
+ upsertCompletionBlock,
352
+ type CompletionCommandSpec,
353
+ type CompletionShell,
354
+ } from './self/completion.ts';
@@ -1,39 +1,13 @@
1
1
  /**
2
- * Default llmanspec/config.yaml templates, extracted verbatim from predecessor
3
- * (crates/llman-sdd/src/sdd/project/config.rs DEFAULT_CONFIG_EN/ZH_HANS).
2
+ * Default llmanspec/config.yaml body (init-generators r19/r50): one built-in
3
+ * locale (zh-Hans), ported from the predecessor (crates/llman-sdd/src/sdd/
4
+ * project/config.rs DEFAULT_CONFIG_ZH_HANS).
4
5
  */
6
+ import { DEFAULT_LOCALE } from '../locale.ts';
7
+
5
8
  export const LLMANSPEC_SCHEMA_URL =
6
9
  'https://raw.githubusercontent.com/StrayDragon/llman/main/artifacts/schema/configs/en/llmanspec-config.schema.json';
7
10
 
8
- export const DEFAULT_CONFIG_EN = `schema: spec-driven
9
- locale: en
10
-
11
- # Optional extra skills (disabled by default, uncomment to enable).
12
- # On \`llman-sdd init --update\`, managed candidates are:
13
- # default workflow skills + entries listed here (extra_skills extend).
14
- # Then \`.agents/skills/llman-sdd-*\` is scanned: anything not in that candidate
15
- # set is removed first, then candidates are written/updated. Only the
16
- # \`llman-sdd-\` prefix is touched (custom skills without that prefix are kept).
17
- # Deprecated shipped skills (e.g. removed from defaults) are cleaned this way.
18
- # extra_skills:
19
- # - llman-sdd-continue
20
- # - llman-sdd-ff
21
- # - llman-sdd-validate
22
- # - llman-sdd-arch-review
23
- # - llman-sdd-wayfinder
24
- # - llman-sdd-research
25
-
26
- # Spec verification (optional, uncomment to enable)
27
- # specs:
28
- # framework: pytest-bdd
29
- # # Filtered runners: include {feature_*} so validate --all/--specs runs per capability.
30
- # # check_command: "pytest {feature_dir} -k {feature_name} -v"
31
- # # Project-wide runners (no placeholders): validate --all/--specs runs the suite once (batch-once).
32
- # # check_command: "cargo test --features bdd"
33
- # # verify_prompt: |
34
- # # Map test failures to requirement IDs.
35
- `;
36
-
37
11
  export const DEFAULT_CONFIG_ZH_HANS = `schema: spec-driven
38
12
  locale: zh-Hans
39
13
 
@@ -67,3 +41,12 @@ export function prependSchemaHeader(content: string, schemaUrl: string): string
67
41
  if (content === '') return `${header}\n`;
68
42
  return `${header}\n${content}`;
69
43
  }
44
+
45
+ /**
46
+ * Built-in default config bodies by normalized locale. The lookup keeps the
47
+ * single-source shape of the locale chain (r18/r50): a locale is normalized
48
+ * first, then resolved; no exact-string comparison on the raw input.
49
+ */
50
+ export const DEFAULT_CONFIGS: Readonly<Record<string, string>> = {
51
+ [DEFAULT_LOCALE]: DEFAULT_CONFIG_ZH_HANS,
52
+ };
package/src/init/init.ts CHANGED
@@ -8,10 +8,12 @@
8
8
  */
9
9
  import { join } from 'node:path';
10
10
 
11
- import { loadConfig } from '../config/load.ts';
11
+ import { CHANGES_DIR, SPECS_DIR } from '../change/lifecycle.ts';
12
+ import { loadConfigDetail } from '../config/load.ts';
13
+ import type { SddConfig } from '../config/schema.ts';
12
14
  import { writeSddState } from '../context/sddState.ts';
15
+ import { DEFAULT_LOCALE, localeFallbacks, normalizeLocale } from '../locale.ts';
13
16
  import { renderTemplate } from '../templates/engine.ts';
14
- import { localeFallbacks } from '../templates/locale.ts';
15
17
  import {
16
18
  buildTemplateVars,
17
19
  enforceEthicsGovernance,
@@ -20,14 +22,8 @@ import {
20
22
  skillCandidates,
21
23
  type TemplateIo,
22
24
  } from '../templates/skills.ts';
23
- import {
24
- DEFAULT_CONFIG_EN,
25
- DEFAULT_CONFIG_ZH_HANS,
26
- LLMANSPEC_SCHEMA_URL,
27
- prependSchemaHeader,
28
- } from './defaultConfig.ts';
29
-
30
- export { effectiveCheckCommand } from '../templates/skills.ts';
25
+ import { type FsPort } from '../util/fsPort.ts';
26
+ import { DEFAULT_CONFIGS, LLMANSPEC_SCHEMA_URL, prependSchemaHeader } from './defaultConfig.ts';
31
27
 
32
28
  const MARKER_START = '<!-- LLMANSPEC:START -->';
33
29
  const MARKER_END = '<!-- LLMANSPEC:END -->';
@@ -65,21 +61,59 @@ function separatorAfterEndMarker(suffix: string): string {
65
61
  export const TEMPLATES_ROOT = join(import.meta.dirname, '..', '..', 'templates');
66
62
 
67
63
  /** Repo-root-relative filesystem effects needed by the init flow. */
68
- export interface InitIo {
69
- exists(path: string): boolean;
70
- readText(path: string): string;
71
- writeText(path: string, content: string): void;
72
- mkdirp(path: string): void;
73
- listDir(path: string): string[];
74
- removeDir(path: string): void;
75
- }
64
+ export type InitIo = Pick<
65
+ FsPort,
66
+ 'exists' | 'readText' | 'writeText' | 'mkdirp' | 'listDir' | 'removeDir'
67
+ >;
76
68
 
77
69
  function writeDefaultConfig(io: InitIo, locale: string): void {
78
- const raw = locale === 'zh-Hans' ? DEFAULT_CONFIG_ZH_HANS : DEFAULT_CONFIG_EN;
70
+ const raw = DEFAULT_CONFIGS[normalizeLocale(locale)] ?? DEFAULT_CONFIGS[DEFAULT_LOCALE]!;
79
71
  io.mkdirp('llmanspec');
80
72
  io.writeText('llmanspec/config.yaml', prependSchemaHeader(raw, LLMANSPEC_SCHEMA_URL));
81
73
  }
82
74
 
75
+ /**
76
+ * Effective-locale precedence (init-generators r50): an explicit `locale` key
77
+ * in the workspace config wins; a CLI option fills a missing key; the built-in
78
+ * default (r18-normalized `zh-Hans`, already baked into config.locale here) is
79
+ * the floor. Per-instance: callers resolve per workspace root, no
80
+ * cross-instance inheritance.
81
+ */
82
+ export function resolveEffectiveLocale(input: {
83
+ configLocale: string;
84
+ configLocaleExplicit: boolean;
85
+ optionLocale?: string;
86
+ }): string {
87
+ if (input.configLocaleExplicit) return input.configLocale;
88
+ return input.optionLocale ?? input.configLocale;
89
+ }
90
+
91
+ /**
92
+ * Config as rendered: resolve the effective locale per r50 and attach the
93
+ * missing-key WARNING when an existing config lacks the key (a freshly
94
+ * written default config always carries the key, so no warning there).
95
+ */
96
+ function withEffectiveLocale(
97
+ detail: ReturnType<typeof loadConfigDetail>,
98
+ optionLocale: string | undefined,
99
+ configExisted: boolean,
100
+ onWarning: ((message: string) => void) | undefined,
101
+ ): SddConfig {
102
+ const { config, localeExplicit } = detail;
103
+ if (localeExplicit) return config;
104
+ const effective = resolveEffectiveLocale({
105
+ configLocale: config.locale,
106
+ configLocaleExplicit: false,
107
+ optionLocale,
108
+ });
109
+ if (configExisted) {
110
+ onWarning?.(
111
+ `WARNING: config.yaml has no explicit 'locale' key; rendering fell back to '${effective}' (set locale: in config.yaml or pass --locale)`,
112
+ );
113
+ }
114
+ return { ...config, locale: effective };
115
+ }
116
+
83
117
  export interface InitResult {
84
118
  /** Skill dirs written, in render order ([] when skills injection is off). */
85
119
  skills: string[];
@@ -94,7 +128,7 @@ const SKILLS_BASE = '.agents/skills';
94
128
  function writeManagedBlocks(
95
129
  io: InitIo,
96
130
  templates: TemplateIo,
97
- config: ReturnType<typeof loadConfig>,
131
+ config: SddConfig,
98
132
  version: string,
99
133
  ): void {
100
134
  const vars = buildTemplateVars(config, version);
@@ -104,7 +138,13 @@ function writeManagedBlocks(
104
138
  ['llmanspec-agents-stub.md', 'llmanspec/AGENTS.md'],
105
139
  ] as const) {
106
140
  const stubRaw = loadLocaleResource(templates, TEMPLATES_ROOT, locales, stubPath);
107
- if (stubRaw === null) continue;
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
+ }
108
148
  const existing = io.exists(agentsPath) ? io.readText(agentsPath) : '';
109
149
  const body = renderTemplate(stubRaw, new Map(), vars);
110
150
  io.writeText(agentsPath, updateFileWithMarkers(existing, body));
@@ -114,25 +154,37 @@ function writeManagedBlocks(
114
154
  export function runInit(
115
155
  io: InitIo,
116
156
  templates: TemplateIo,
117
- opts: { update: boolean; locale?: string; version: string; skills: boolean },
157
+ opts: {
158
+ update: boolean;
159
+ locale?: string;
160
+ version: string;
161
+ skills: boolean;
162
+ onWarning?: (message: string) => void;
163
+ },
118
164
  ): InitResult {
119
165
  io.mkdirp('llmanspec');
120
166
 
121
167
  // 1) config: create with defaults if missing, then always load.
122
168
  const configPath = 'llmanspec/config.yaml';
123
- if (!io.exists(configPath)) writeDefaultConfig(io, opts.locale ?? 'en');
124
- const config = loadConfig(io.readText(configPath));
169
+ const configExisted = io.exists(configPath);
170
+ if (!configExisted) writeDefaultConfig(io, opts.locale ?? DEFAULT_LOCALE);
171
+ const config = withEffectiveLocale(
172
+ loadConfigDetail(io.readText(configPath)),
173
+ opts.locale,
174
+ configExisted,
175
+ opts.onWarning,
176
+ );
125
177
 
126
178
  // 1b) scaffold-state stamp: record the rendering version for drift notices
127
179
  // (version-awareness). Corrupt/missing state on later reads is silent-OK.
128
180
  writeSddState(io, opts.version);
129
181
 
130
182
  // 2) scaffold directories.
131
- io.mkdirp('llmanspec/specs');
132
- io.mkdirp('llmanspec/changes/archive');
183
+ io.mkdirp(SPECS_DIR);
184
+ io.mkdirp(`${CHANGES_DIR}/archive`);
133
185
  if (!io.exists('llmanspec/specs/.gitkeep')) io.writeText('llmanspec/specs/.gitkeep', '');
134
- if (!io.exists('llmanspec/changes/archive/.gitkeep')) {
135
- io.writeText('llmanspec/changes/archive/.gitkeep', '');
186
+ if (!io.exists(`${CHANGES_DIR}/archive/.gitkeep`)) {
187
+ io.writeText(`${CHANGES_DIR}/archive/.gitkeep`, '');
136
188
  }
137
189
 
138
190
  // 3) AGENTS.md managed blocks (root + llmanspec), preserving content.
@@ -175,10 +227,20 @@ export function runInit(
175
227
  * (blocks only — no scaffold, no config touch, no skills). Returns false for
176
228
  * a missing config (discovery guarantees validity; a race is not fatal).
177
229
  */
178
- export function refreshSubRootBlocks(io: InitIo, templates: TemplateIo, version: string): boolean {
230
+ export function refreshSubRootBlocks(
231
+ io: InitIo,
232
+ templates: TemplateIo,
233
+ version: string,
234
+ onWarning?: (message: string) => void,
235
+ ): boolean {
179
236
  const configPath = 'llmanspec/config.yaml';
180
237
  if (!io.exists(configPath)) return false;
181
- const config = loadConfig(io.readText(configPath));
238
+ const config = withEffectiveLocale(
239
+ loadConfigDetail(io.readText(configPath)),
240
+ undefined,
241
+ true,
242
+ onWarning,
243
+ );
182
244
  writeManagedBlocks(io, templates, config, version);
183
245
  return true;
184
246
  }
package/src/locale.ts ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Locale normalization + fallback chain (init-generators capability, r18).
3
+ * Single built-in locale: every recognizable prefix (zh / zh-cn / zh-hans and
4
+ * the en family) and every unknown value normalizes to `zh-Hans`. The branch
5
+ * shape is kept so an English template pack can be re-added later without
6
+ * touching callers.
7
+ */
8
+
9
+ /** The one built-in template locale: default value, fallback tail and CLI floor. */
10
+ export const DEFAULT_LOCALE = 'zh-Hans';
11
+
12
+ export function normalizeLocale(value: string): string {
13
+ const trimmed = value.trim();
14
+ if (trimmed === '') return DEFAULT_LOCALE;
15
+ const lower = trimmed.toLowerCase();
16
+ if (lower === 'zh' || lower.startsWith('zh-hans') || lower === 'zh-cn') return DEFAULT_LOCALE;
17
+ if (lower.startsWith('en')) return DEFAULT_LOCALE;
18
+ // Unknown values normalize instead of passing through: with no English pack,
19
+ // an unlisted locale would render nothing at all.
20
+ return DEFAULT_LOCALE;
21
+ }
22
+
23
+ export function localeFallbacks(locale: string): string[] {
24
+ const normalized = normalizeLocale(locale);
25
+ const locales: string[] = [normalized];
26
+ const dash = normalized.indexOf('-');
27
+ if (dash !== -1) {
28
+ const lang = normalized.slice(0, dash);
29
+ if (!locales.includes(lang)) locales.push(lang);
30
+ }
31
+ if (!locales.includes(DEFAULT_LOCALE)) locales.push(DEFAULT_LOCALE);
32
+ return locales;
33
+ }