@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.
- package/package.json +1 -1
- package/src/archive/freeze.ts +15 -15
- package/src/archive/frozenCard.ts +3 -2
- package/src/change/collect.ts +17 -14
- package/src/change/deps.ts +54 -0
- package/src/change/frontmatter.ts +36 -5
- package/src/change/lifecycle.ts +124 -20
- package/src/change/nextId.ts +21 -7
- package/src/config/changeId.ts +0 -6
- package/src/config/load.ts +36 -2
- package/src/config/schema.ts +3 -7
- package/src/context/indexStore.ts +14 -14
- package/src/context/sddState.ts +1 -13
- package/src/context/tree.ts +9 -19
- package/src/git/spawnGit.ts +5 -1
- package/src/index.ts +37 -12
- package/src/init/defaultConfig.ts +14 -31
- package/src/init/init.ts +92 -30
- package/src/locale.ts +33 -0
- package/src/project/migrations.ts +196 -60
- package/src/report/graph/deps.ts +3 -38
- package/src/report/graph/nodes.ts +13 -19
- package/src/report/graph/types.ts +2 -6
- package/src/report/show.ts +16 -8
- package/src/report/specHelpers.ts +22 -28
- package/src/review/review.ts +18 -31
- package/src/self/completion.ts +206 -0
- package/src/spec/assignSpecIds.ts +9 -1
- package/src/spec/authoring.ts +11 -11
- package/src/spec/parser.ts +3 -1
- package/src/templates/skills.ts +3 -23
- package/src/util/datedId.ts +18 -0
- package/src/util/fsPort.ts +24 -0
- package/src/util/nextNumber.ts +30 -0
- package/src/util/semver.ts +21 -0
- package/src/validation/changeCheck.ts +133 -67
- package/src/validation/crossRoot.ts +86 -0
- package/src/validation/discover.ts +22 -13
- package/src/validation/roots.ts +2 -5
- package/src/validation/validate.ts +10 -19
- package/src/validation/{transitions.ts → xstateTransitions.ts} +81 -69
- package/templates/zh-Hans/skills/llman-sdd-apply-cycle.md +9 -7
- package/templates/zh-Hans/skills/llman-sdd-apply.md +5 -5
- package/templates/zh-Hans/skills/llman-sdd-archive.md +11 -2
- package/templates/zh-Hans/skills/llman-sdd-continue.md +1 -1
- package/templates/zh-Hans/skills/llman-sdd-draft.md +1 -1
- package/templates/zh-Hans/skills/llman-sdd-explore.md +2 -2
- package/templates/zh-Hans/skills/llman-sdd-ff.md +1 -1
- package/templates/zh-Hans/skills/llman-sdd-propose.md +8 -6
- package/templates/zh-Hans/skills/llman-sdd-quick.md +1 -1
- package/templates/zh-Hans/skills/llman-sdd-validate.md +1 -1
- package/templates/zh-Hans/skills/llman-sdd-verify.md +2 -2
- package/templates/zh-Hans/skills/llman-sdd-wayfinder.md +1 -1
- package/templates/zh-Hans/units/skills/git-native-flow.md +12 -6
- package/templates/zh-Hans/units/skills/index-fallback.md +1 -0
- package/templates/zh-Hans/units/skills/structured-protocol.md +1 -6
- package/templates/zh-Hans/units/spec/feature-contract.md +5 -33
- package/src/templates/locale.ts +0 -24
- package/templates/en/agents-root-stub.md +0 -9
- package/templates/en/llmanspec-agents-stub.md +0 -6
- package/templates/en/skills/llman-sdd-apply-cycle.md +0 -67
- package/templates/en/skills/llman-sdd-apply.md +0 -117
- package/templates/en/skills/llman-sdd-arch-review.md +0 -58
- package/templates/en/skills/llman-sdd-archive.md +0 -70
- package/templates/en/skills/llman-sdd-continue.md +0 -34
- package/templates/en/skills/llman-sdd-draft.md +0 -53
- package/templates/en/skills/llman-sdd-explore.md +0 -64
- package/templates/en/skills/llman-sdd-ff.md +0 -33
- package/templates/en/skills/llman-sdd-graph.md +0 -56
- package/templates/en/skills/llman-sdd-propose.md +0 -105
- package/templates/en/skills/llman-sdd-quick.md +0 -41
- package/templates/en/skills/llman-sdd-research.md +0 -35
- package/templates/en/skills/llman-sdd-specs-compact.md +0 -41
- package/templates/en/skills/llman-sdd-validate.md +0 -28
- package/templates/en/skills/llman-sdd-verify.md +0 -77
- package/templates/en/skills/llman-sdd-wayfinder.md +0 -83
- package/templates/en/units/skills/cli-footer.md +0 -2
- package/templates/en/units/skills/ethics-governance.md +0 -6
- package/templates/en/units/skills/git-native-flow-brief.md +0 -10
- package/templates/en/units/skills/git-native-flow.md +0 -50
- package/templates/en/units/skills/human-readable-summary.md +0 -9
- package/templates/en/units/skills/stage-guard.md +0 -17
- package/templates/en/units/skills/structured-protocol.md +0 -24
- package/templates/en/units/skills/validation-hints.md +0 -20
- package/templates/en/units/skills/version-drift.md +0 -3
- package/templates/en/units/spec/feature-contract.md +0 -38
- package/templates/en/units/workflow/archive-freeze-guidance.md +0 -9
- package/templates/zh-Hans/units/skills/git-native-flow-brief.md +0 -10
- package/templates/zh-Hans/units/workflow/archive-freeze-guidance.md +0 -10
package/package.json
CHANGED
package/src/archive/freeze.ts
CHANGED
|
@@ -10,6 +10,8 @@ import { join } from 'node:path';
|
|
|
10
10
|
|
|
11
11
|
import { firstH1 } from '../change/collect.ts';
|
|
12
12
|
import { extractFrontmatter, readFrontmatterTitle } from '../change/frontmatter.ts';
|
|
13
|
+
import { DATED_PREFIX_RE } from '../util/datedId.ts';
|
|
14
|
+
import { type FsPort } from '../util/fsPort.ts';
|
|
13
15
|
import {
|
|
14
16
|
FROZEN_CARD_EXT,
|
|
15
17
|
composeFrozenCard,
|
|
@@ -22,22 +24,20 @@ import type { SevenZipPort } from './sevenzip.ts';
|
|
|
22
24
|
export const FREEZE_ARCHIVE_NAME = 'freezed_changes.7z.archived';
|
|
23
25
|
export const ARCHIVE_DIR_REL = 'llmanspec/changes/archive';
|
|
24
26
|
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
removeDir
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
moveDir(from: string, to: string): void;
|
|
38
|
-
}
|
|
27
|
+
export type FreezeIo = Pick<
|
|
28
|
+
FsPort,
|
|
29
|
+
| 'exists'
|
|
30
|
+
| 'listDir'
|
|
31
|
+
| 'readText'
|
|
32
|
+
| 'writeText'
|
|
33
|
+
| 'isDirectory'
|
|
34
|
+
| 'removeDir'
|
|
35
|
+
| 'remove'
|
|
36
|
+
| 'mkdirp'
|
|
37
|
+
| 'moveDir'
|
|
38
|
+
>;
|
|
39
39
|
|
|
40
|
-
const DATED_RE =
|
|
40
|
+
const DATED_RE = DATED_PREFIX_RE;
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* r24: freeze candidates = date-prefixed entries that are directories with a
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
* Pure string logic — all filesystem effects live in freeze.ts (FreezeIo).
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
+
import { datedCardIdOf } from '../util/datedId.ts';
|
|
26
|
+
|
|
25
27
|
export const FROZEN_CARD_EXT = '.yaml';
|
|
26
28
|
|
|
27
29
|
/** `2026-01-01-old` → `2026-01-01-old.yaml` */
|
|
@@ -31,8 +33,7 @@ export function frozenCardName(datedId: string): string {
|
|
|
31
33
|
|
|
32
34
|
/** id for a card filename (`2026-01-01-old.yaml` → `old`); null when not a card. */
|
|
33
35
|
export function frozenCardIdOf(name: string): string | null {
|
|
34
|
-
|
|
35
|
-
return m?.[1] ?? null;
|
|
36
|
+
return datedCardIdOf(name, '.yaml');
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
export function isFrozenCard(name: string): boolean {
|
package/src/change/collect.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type FsPort } from '../util/fsPort.ts';
|
|
2
|
+
import { extractFrontmatter, readBinding, readFrontmatterTitle } from './frontmatter.ts';
|
|
2
3
|
/**
|
|
3
4
|
* Change collection + stage derivation (change domain, peripheral-commands
|
|
4
5
|
* capability r20/r34 shapes; predecessor commands/list.rs port). Pure — IO injected.
|
|
@@ -8,20 +9,13 @@ import { readBinding } from './frontmatter.ts';
|
|
|
8
9
|
import { CHANGES_DIR } from './lifecycle.ts';
|
|
9
10
|
import { parseTaskCheckboxes } from './tasks.ts';
|
|
10
11
|
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
readText
|
|
14
|
-
|
|
15
|
-
isDirectory(path: string): boolean;
|
|
16
|
-
mtimeMs(path: string): number;
|
|
17
|
-
}
|
|
12
|
+
export type ChangeFsIo = Pick<
|
|
13
|
+
FsPort,
|
|
14
|
+
'exists' | 'readText' | 'listDir' | 'isDirectory' | 'mtimeMs'
|
|
15
|
+
>;
|
|
18
16
|
|
|
19
17
|
/** Minimal structural io for the active-change walk (r58/r73 shared caliber). */
|
|
20
|
-
export
|
|
21
|
-
exists(path: string): boolean;
|
|
22
|
-
listDir(path: string): string[];
|
|
23
|
-
isDirectory(path: string): boolean;
|
|
24
|
-
}
|
|
18
|
+
export type ChangeScanIo = Pick<FsPort, 'exists' | 'listDir' | 'isDirectory'>;
|
|
25
19
|
|
|
26
20
|
/**
|
|
27
21
|
* r58/r73 shared walk: visits every active change dir (a dir directly holding
|
|
@@ -95,6 +89,15 @@ export function firstH1(md: string): string {
|
|
|
95
89
|
return '';
|
|
96
90
|
}
|
|
97
91
|
|
|
92
|
+
/**
|
|
93
|
+
* r99 authoritative change title: frontmatter `title` when non-empty, the
|
|
94
|
+
* first H1 otherwise (legacy fallback, empty when neither). Single point for
|
|
95
|
+
* every title consumer — collect (list) and show must never drift.
|
|
96
|
+
*/
|
|
97
|
+
export function changeTitle(proposal: string): string {
|
|
98
|
+
return readFrontmatterTitle(extractFrontmatter(proposal)) || firstH1(proposal);
|
|
99
|
+
}
|
|
100
|
+
|
|
98
101
|
export function collectChanges(
|
|
99
102
|
io: ChangeFsIo,
|
|
100
103
|
root: string,
|
|
@@ -124,7 +127,7 @@ export function collectChanges(
|
|
|
124
127
|
out.push({
|
|
125
128
|
name,
|
|
126
129
|
path: name,
|
|
127
|
-
title:
|
|
130
|
+
title: changeTitle(io.readText(proposal)),
|
|
128
131
|
stage: stageFor(hasDesign, hasTasks, hasBinding),
|
|
129
132
|
hasBinding,
|
|
130
133
|
completedTasks: completed,
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T22 single depends_on reader, two policies over one parse (design 3.1):
|
|
3
|
+
*
|
|
4
|
+
* - lenient (graph, peripheral-commands r30): missing/malformed/parse-failure
|
|
5
|
+
* all degrade to `[]`, non-string entries dropped, never throws.
|
|
6
|
+
* - strict (validate, validation r73): non-list frontmatter reports
|
|
7
|
+
`must be a list of change ID strings`; unknown refs are the caller's
|
|
8
|
+
concern (the raw string list is returned for it to check).
|
|
9
|
+
*
|
|
10
|
+
* Parsing keys on the `yaml` package (parseDocument) via extractFrontmatter,
|
|
11
|
+
* so quoting, block/flow styles, comments and numeric entries collapse into
|
|
12
|
+
* one code path. A bare `depends_on:` (YAML null) reads as `[]` in both modes.
|
|
13
|
+
*/
|
|
14
|
+
import { parseDocument } from 'yaml';
|
|
15
|
+
|
|
16
|
+
import { extractFrontmatter } from './frontmatter.ts';
|
|
17
|
+
|
|
18
|
+
export type DepsList = { kind: 'list'; items: string[] } | { kind: 'malformed' };
|
|
19
|
+
|
|
20
|
+
function readDepsNode(frontmatter: string | null): DepsList {
|
|
21
|
+
if (frontmatter === null) return { kind: 'list', items: [] };
|
|
22
|
+
if (frontmatter.trim() === '') return { kind: 'list', items: [] };
|
|
23
|
+
const doc = parseDocument(frontmatter);
|
|
24
|
+
if (doc.errors.length > 0) return { kind: 'malformed' };
|
|
25
|
+
const value = doc.toJS({ json: true }) as Record<string, unknown>;
|
|
26
|
+
const node = value['depends_on'];
|
|
27
|
+
if (node === undefined || node === null) return { kind: 'list', items: [] };
|
|
28
|
+
if (!Array.isArray(node)) return { kind: 'malformed' };
|
|
29
|
+
return {
|
|
30
|
+
kind: 'list',
|
|
31
|
+
items: node.filter((x): x is string => typeof x === 'string'),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Lenient policy (graph): never throws, missing/malformed → []. */
|
|
36
|
+
export function readDepsLenient(text: string): string[] {
|
|
37
|
+
const parsed = readDepsNode(extractFrontmatter(text) ?? cardYamlSource(text));
|
|
38
|
+
return parsed.kind === 'list' ? parsed.items : [];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* r54 dual-format card reading: a fence-free frozen card is a plain YAML doc
|
|
43
|
+
* whose FIRST line opens with `title:`/`depends_on:` — feed the whole text.
|
|
44
|
+
* Proposal bodies never open with those keys, so no misfire.
|
|
45
|
+
*/
|
|
46
|
+
function cardYamlSource(input: string): string | null {
|
|
47
|
+
const firstLine = input.trimStart().split('\n')[0] ?? '';
|
|
48
|
+
return /^(title|depends_on):/u.test(firstLine) ? input : null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Strict policy (validate): malformed frontmatter is reported, not swallowed. */
|
|
52
|
+
export function readDepsStrict(proposal: string): DepsList {
|
|
53
|
+
return readDepsNode(extractFrontmatter(proposal));
|
|
54
|
+
}
|
|
@@ -65,14 +65,45 @@ export function readNeedsSpecsChange(frontmatter: string | null): boolean {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
*
|
|
69
|
-
* `diff --name-only <base_branch>...<branch
|
|
70
|
-
* `
|
|
68
|
+
* r119: live specs landed on the bound branch — per-line prefix match on
|
|
69
|
+
* `diff --name-only <base_branch>...<branch>`. The prefix is the change's
|
|
70
|
+
* instance-relative specs dir (`llmanspec/specs/` for the repo-root instance,
|
|
71
|
+
* `packages/tui/llmanspec/specs/` for a sub-project one); a path like
|
|
72
|
+
* `docs/llmanspec/specs/x` must not count as landed. Edits to ANOTHER
|
|
73
|
+
* instance's specs never match this instance's prefix (strictly own-instance,
|
|
74
|
+
* mirroring the r116 write constraint).
|
|
71
75
|
*/
|
|
72
|
-
|
|
76
|
+
/** r119: the repo-root instance's specs prefix — the default every caller
|
|
77
|
+
* degrades to (single-root byte parity). One constant, five call sites. */
|
|
78
|
+
export const DEFAULT_SPECS_PREFIX = 'llmanspec/specs/';
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* r119: instance dir relative to the git toplevel, derived from a specs
|
|
82
|
+
* prefix ('llmanspec/specs/' → '', 'packages/tui/llmanspec/specs/' →
|
|
83
|
+
* 'packages/tui') — the inverse of `specsPrefixOfInstance`. One module owns
|
|
84
|
+
* both directions so the close-out gate and the io redirects can never
|
|
85
|
+
* disagree about which `llmanspec/` tree a change belongs to.
|
|
86
|
+
*/
|
|
87
|
+
export function instanceDirRelOf(specsPrefix: string): string {
|
|
88
|
+
// `\/?` eats the separator too, so the round-trip
|
|
89
|
+
// instanceDirRelOf(specsPrefixOfInstance(rel)) === rel holds exactly
|
|
90
|
+
// ('a/b/llmanspec/specs/' → 'a/b', not 'a/b/').
|
|
91
|
+
return specsPrefix.replace(/\/?llmanspec\/specs\/$/u, '');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** r119: the specs prefix of an instance dir rel ('' → 'llmanspec/specs/'). */
|
|
95
|
+
export function specsPrefixOfInstance(instanceDirRel: string): string {
|
|
96
|
+
return instanceDirRel === '' ? DEFAULT_SPECS_PREFIX : `${instanceDirRel}/llmanspec/specs/`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function specsLanded(
|
|
100
|
+
git: GitLike,
|
|
101
|
+
binding: ChangeBinding,
|
|
102
|
+
specsPrefix = DEFAULT_SPECS_PREFIX,
|
|
103
|
+
): boolean {
|
|
73
104
|
const touched =
|
|
74
105
|
git.runOpt(['diff', '--name-only', `${binding.baseBranch}...${binding.branch}`]) ?? '';
|
|
75
|
-
return touched.split('\n').some((line) => line.startsWith(
|
|
106
|
+
return touched.split('\n').some((line) => line.startsWith(specsPrefix));
|
|
76
107
|
}
|
|
77
108
|
|
|
78
109
|
export function readBinding(proposal: string): ChangeBinding | null {
|
package/src/change/lifecycle.ts
CHANGED
|
@@ -12,7 +12,17 @@ import {
|
|
|
12
12
|
worktreeList,
|
|
13
13
|
type GitLike,
|
|
14
14
|
} from '../git/spawnGit.ts';
|
|
15
|
-
import {
|
|
15
|
+
import { type FsPort } from '../util/fsPort.ts';
|
|
16
|
+
import {
|
|
17
|
+
extractFrontmatter,
|
|
18
|
+
instanceDirRelOf,
|
|
19
|
+
readBinding,
|
|
20
|
+
readNeedsSpecsChange,
|
|
21
|
+
DEFAULT_SPECS_PREFIX,
|
|
22
|
+
specsLanded,
|
|
23
|
+
writeBinding,
|
|
24
|
+
type ChangeBinding,
|
|
25
|
+
} from './frontmatter.ts';
|
|
16
26
|
/**
|
|
17
27
|
* Change lifecycle (change-lifecycle capability): new / start / attach /
|
|
18
28
|
* finalize with the predecessor git-native contract (r14-r16). All effects flow
|
|
@@ -23,14 +33,7 @@ import { readBinding, writeBinding } from './frontmatter.ts';
|
|
|
23
33
|
import { DRAFT_PROPOSAL_TEMPLATE, deriveChangeId } from './id.ts';
|
|
24
34
|
import { CLOSE_OUT_TASK_HINT, closeOutTaskLines, parseTaskCheckboxes } from './tasks.ts';
|
|
25
35
|
|
|
26
|
-
export
|
|
27
|
-
exists(path: string): boolean;
|
|
28
|
-
readText(path: string): string;
|
|
29
|
-
/** writeText creates parent directories as needed. */
|
|
30
|
-
writeText(path: string, content: string): void;
|
|
31
|
-
rename(from: string, to: string): void;
|
|
32
|
-
listDir(path: string): string[];
|
|
33
|
-
}
|
|
36
|
+
export type FsIo = Pick<FsPort, 'exists' | 'readText' | 'writeText' | 'rename' | 'listDir'>;
|
|
34
37
|
|
|
35
38
|
export class LifecycleError extends Error {}
|
|
36
39
|
|
|
@@ -45,6 +48,8 @@ const onDefaultBranch = (cmd: string, def: string): string =>
|
|
|
45
48
|
const dirtyTree = (cmd: string): string => `\`${cmd}\` requires a clean working tree`;
|
|
46
49
|
|
|
47
50
|
export const CHANGES_DIR = 'llmanspec/changes';
|
|
51
|
+
/** Instance-relative live-specs dir (single SSOT with CHANGES_DIR). */
|
|
52
|
+
export const SPECS_DIR = 'llmanspec/specs';
|
|
48
53
|
const proposalPath = (id: string): string => `${CHANGES_DIR}/${id}/proposal.md`;
|
|
49
54
|
|
|
50
55
|
/** `change new [id] --from DESC --force`: derive a legal id and write the draft shell. */
|
|
@@ -170,6 +175,8 @@ export function startChange(
|
|
|
170
175
|
worktreeRoot?: string;
|
|
171
176
|
/** Config sdd.worktree_naming. */
|
|
172
177
|
worktreeNaming?: 'id' | 'hash';
|
|
178
|
+
/** r119: instance dir relative to the git toplevel ('' at the repo root). */
|
|
179
|
+
instanceDirRel?: string;
|
|
173
180
|
} = {},
|
|
174
181
|
): StartResult {
|
|
175
182
|
const path = proposalPath(id);
|
|
@@ -220,12 +227,18 @@ export function startChange(
|
|
|
220
227
|
// checkout stays byte-identical (zero writes through the original io).
|
|
221
228
|
// The clean-tree gate guaranteed the proposal is committed at HEAD, so it
|
|
222
229
|
// is present in the fresh worktree; a missing one rolls everything back.
|
|
223
|
-
|
|
230
|
+
// r119: the io is anchored at the INSTANCE root; redirecting into the new
|
|
231
|
+
// worktree must re-attach that offset relative to its toplevel (a sub-root
|
|
232
|
+
// change's proposal lives at <wt>/<rel>/llmanspec/changes/<id>), same
|
|
233
|
+
// shape as the mergeRenameCommit holder redirect.
|
|
234
|
+
const instanceDirRel = opts.instanceDirRel ?? '';
|
|
235
|
+
const wtRoot = instanceDirRel === '' ? worktreePath : `${worktreePath}/${instanceDirRel}`;
|
|
236
|
+
const wtIo = ioAt(io, wtRoot);
|
|
224
237
|
if (!wtIo.exists(path)) {
|
|
225
238
|
git.run(['worktree', 'remove', '--force', worktreePath]);
|
|
226
239
|
git.run(['branch', '-D', branch]);
|
|
227
240
|
throw new LifecycleError(
|
|
228
|
-
`proposal not found in the new worktree: ${
|
|
241
|
+
`proposal not found in the new worktree: ${wtRoot}/${path} — commit the change docs before \`change start --worktree\``,
|
|
229
242
|
);
|
|
230
243
|
}
|
|
231
244
|
const baseSha = mergeBase(gitAt(git, worktreePath), 'HEAD', baseBranch);
|
|
@@ -309,31 +322,91 @@ export function archiveTaskGate(tasksMd: string | null): ArchiveTaskGate {
|
|
|
309
322
|
return { blocked: false, pendingLines: [] };
|
|
310
323
|
}
|
|
311
324
|
|
|
325
|
+
/**
|
|
326
|
+
* T34 close-out gate (decision D): seal-off requires the specs-landed verdict
|
|
327
|
+
* (`specsLanded || !needsSpecsChange`) plus every checked task when tasks.md
|
|
328
|
+
* exists. `reason === null` means pass; otherwise it is the human message.
|
|
329
|
+
* Zero-write: callers run this before any merge/rename/commit.
|
|
330
|
+
*/
|
|
331
|
+
export function closeOutGate(change: {
|
|
332
|
+
git: GitLike;
|
|
333
|
+
io: FsIo;
|
|
334
|
+
id: string;
|
|
335
|
+
binding: ChangeBinding | null;
|
|
336
|
+
/** r119: instance-relative specs prefix of the change's own root. */
|
|
337
|
+
specsPrefix?: string;
|
|
338
|
+
}): { ok: boolean; reason: string | null } {
|
|
339
|
+
const { git, io, id, binding } = change;
|
|
340
|
+
const specsPrefix = change.specsPrefix ?? DEFAULT_SPECS_PREFIX;
|
|
341
|
+
// task gate first: the unchecked list is the most actionable feedback and
|
|
342
|
+
// keeps the predecessor "blocked by unchecked tasks" surface primary.
|
|
343
|
+
const tasksPath = `${CHANGES_DIR}/${id}/tasks.md`;
|
|
344
|
+
const gate = archiveTaskGate(io.exists(tasksPath) ? io.readText(tasksPath) : null);
|
|
345
|
+
if (gate.blocked) {
|
|
346
|
+
const closeOutLines = closeOutTaskLines(gate.pendingLines);
|
|
347
|
+
return {
|
|
348
|
+
ok: false,
|
|
349
|
+
reason: [
|
|
350
|
+
`close-out blocked by unchecked tasks (${gate.pendingLines.length} pending)`,
|
|
351
|
+
...gate.pendingLines,
|
|
352
|
+
...(closeOutLines.length > 0
|
|
353
|
+
? [
|
|
354
|
+
`task "${closeOutLines[0]?.replace(/^-\s+\[ \]\s*/u, '').trim() ?? ''}" looks like a close-out step; ${CLOSE_OUT_TASK_HINT}`,
|
|
355
|
+
]
|
|
356
|
+
: []),
|
|
357
|
+
].join('\n'),
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
const proposal = io.readText(`${CHANGES_DIR}/${id}/proposal.md`);
|
|
361
|
+
const needsSpecsChange = readNeedsSpecsChange(extractFrontmatter(proposal));
|
|
362
|
+
if (binding !== null) {
|
|
363
|
+
const landed = specsLanded(git, binding, specsPrefix);
|
|
364
|
+
if (!landed && needsSpecsChange) {
|
|
365
|
+
return {
|
|
366
|
+
ok: false,
|
|
367
|
+
reason: `close-out blocked: no changes under ${specsPrefix} on the bound branch (or set needs_specs_change to false)`,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return { ok: true, reason: null };
|
|
372
|
+
}
|
|
373
|
+
|
|
312
374
|
/** `change finalize`: merge (squash default) + archive rename + close-out commit. */
|
|
313
375
|
export function finalizeChange(
|
|
314
376
|
git: GitLike,
|
|
315
377
|
io: FsIo,
|
|
316
378
|
id: string,
|
|
317
|
-
opts: {
|
|
379
|
+
opts: {
|
|
380
|
+
into?: string;
|
|
381
|
+
method?: 'squash' | 'ff';
|
|
382
|
+
today: string;
|
|
383
|
+
noCommit?: boolean;
|
|
384
|
+
/** r119: instance-relative specs prefix of the change's own root. */
|
|
385
|
+
specsPrefix?: string;
|
|
386
|
+
},
|
|
318
387
|
): FinalizeResult {
|
|
319
388
|
const path = proposalPath(id);
|
|
320
389
|
const binding = readBinding(io.readText(path));
|
|
321
390
|
if (binding === null) {
|
|
322
391
|
throw new LifecycleError(`change \`${id}\` has no branch binding — run start/attach first`);
|
|
323
392
|
}
|
|
324
|
-
//
|
|
393
|
+
// T34 close-out gate before any write: specs-landed verdict + task gate.
|
|
394
|
+
const closeOut = closeOutGate({ git, io, id, binding, specsPrefix: opts.specsPrefix });
|
|
395
|
+
if (!closeOut.ok) {
|
|
396
|
+
throw new LifecycleError(closeOut.reason as string);
|
|
397
|
+
}
|
|
398
|
+
// r40 unchecked-task detail lines (D9 close-out pseudo-task hint).
|
|
325
399
|
const tasksPath = `${CHANGES_DIR}/${id}/tasks.md`;
|
|
326
400
|
const gate = archiveTaskGate(io.exists(tasksPath) ? io.readText(tasksPath) : null);
|
|
327
401
|
if (gate.blocked) {
|
|
328
|
-
|
|
329
|
-
const closeOut = closeOutTaskLines(gate.pendingLines);
|
|
402
|
+
const closeOutLines = closeOutTaskLines(gate.pendingLines);
|
|
330
403
|
throw new LifecycleError(
|
|
331
404
|
[
|
|
332
405
|
`finalize blocked by unchecked tasks (${gate.pendingLines.length} pending)`,
|
|
333
406
|
...gate.pendingLines,
|
|
334
|
-
...(
|
|
407
|
+
...(closeOutLines.length > 0
|
|
335
408
|
? [
|
|
336
|
-
`task "${
|
|
409
|
+
`task "${closeOutLines[0]?.replace(/^-\s+\[ \]\s*/u, '').trim() ?? ''}" looks like a close-out step; ${CLOSE_OUT_TASK_HINT}`,
|
|
337
410
|
]
|
|
338
411
|
: []),
|
|
339
412
|
].join('\n'),
|
|
@@ -347,7 +420,17 @@ export function finalizeChange(
|
|
|
347
420
|
}
|
|
348
421
|
const method = opts.method ?? 'squash';
|
|
349
422
|
const target = opts.into ?? binding.baseBranch ?? defaultBranch(git);
|
|
350
|
-
return mergeRenameCommit(
|
|
423
|
+
return mergeRenameCommit(
|
|
424
|
+
git,
|
|
425
|
+
io,
|
|
426
|
+
id,
|
|
427
|
+
binding.branch,
|
|
428
|
+
target,
|
|
429
|
+
method,
|
|
430
|
+
opts.today,
|
|
431
|
+
opts.noCommit,
|
|
432
|
+
instanceDirRelOf(opts.specsPrefix ?? DEFAULT_SPECS_PREFIX),
|
|
433
|
+
);
|
|
351
434
|
}
|
|
352
435
|
|
|
353
436
|
/** r69: GitLike view bound to another worktree via `git -C <path>` prefixing. */
|
|
@@ -388,6 +471,8 @@ function mergeRenameCommit(
|
|
|
388
471
|
method: 'squash' | 'ff',
|
|
389
472
|
today: string,
|
|
390
473
|
noCommit?: boolean,
|
|
474
|
+
/** r119: instance dir relative to the git toplevel ('' at the repo root). */
|
|
475
|
+
instanceDirRel = '',
|
|
391
476
|
): FinalizeResult {
|
|
392
477
|
const warnings: string[] = [];
|
|
393
478
|
// r69: when the target branch is checked out in another worktree, `git
|
|
@@ -411,7 +496,11 @@ function mergeRenameCommit(
|
|
|
411
496
|
);
|
|
412
497
|
}
|
|
413
498
|
execGit = gitAt(git, holder);
|
|
414
|
-
|
|
499
|
+
// r119/W1: the io is anchored at the INSTANCE root; redirecting onto the
|
|
500
|
+
// holding worktree must re-attach the instance offset relative to its
|
|
501
|
+
// toplevel, or a sub-root rename would target <holder>/llmanspec (the
|
|
502
|
+
// repo-root instance) and fail ENOENT mid-close-out (merge already run).
|
|
503
|
+
execIo = ioAt(io, instanceDirRel === '' ? holder : `${holder}/${instanceDirRel}`);
|
|
415
504
|
executedIn = holder;
|
|
416
505
|
}
|
|
417
506
|
// r96: in-place close-out — merging a branch into itself is always a no-op
|
|
@@ -463,6 +552,8 @@ export function archiveChange(
|
|
|
463
552
|
/** CLI already enforced a clean tree before the acceptance command ran. */
|
|
464
553
|
skipCleanTree?: boolean;
|
|
465
554
|
today: string;
|
|
555
|
+
/** r119: instance-relative specs prefix of the change's own root. */
|
|
556
|
+
specsPrefix?: string;
|
|
466
557
|
},
|
|
467
558
|
): FinalizeResult {
|
|
468
559
|
const path = proposalPath(id);
|
|
@@ -471,6 +562,9 @@ export function archiveChange(
|
|
|
471
562
|
throw new LifecycleError(`change \`${id}\` has no branch binding — run start/attach first`);
|
|
472
563
|
}
|
|
473
564
|
if (!opts.force) {
|
|
565
|
+
// T34: shared close-out verdict before any write (archive honors --force).
|
|
566
|
+
const closeOut = closeOutGate({ git, io, id, binding, specsPrefix: opts.specsPrefix });
|
|
567
|
+
if (!closeOut.ok) throw new LifecycleError(closeOut.reason as string);
|
|
474
568
|
const tasksPath = `${CHANGES_DIR}/${id}/tasks.md`;
|
|
475
569
|
const gate = archiveTaskGate(io.exists(tasksPath) ? io.readText(tasksPath) : null);
|
|
476
570
|
if (gate.blocked) {
|
|
@@ -507,7 +601,17 @@ export function archiveChange(
|
|
|
507
601
|
}
|
|
508
602
|
const method = opts.method ?? 'squash';
|
|
509
603
|
const target = opts.into ?? binding?.baseBranch ?? defaultBranch(git);
|
|
510
|
-
return mergeRenameCommit(
|
|
604
|
+
return mergeRenameCommit(
|
|
605
|
+
git,
|
|
606
|
+
io,
|
|
607
|
+
id,
|
|
608
|
+
binding?.branch as string,
|
|
609
|
+
target,
|
|
610
|
+
method,
|
|
611
|
+
opts.today,
|
|
612
|
+
undefined,
|
|
613
|
+
instanceDirRelOf(opts.specsPrefix ?? DEFAULT_SPECS_PREFIX),
|
|
614
|
+
);
|
|
511
615
|
}
|
|
512
616
|
|
|
513
617
|
/** `change diff <id>`: full diff of the bound branch vs base. */
|
package/src/change/nextId.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { worktreeList, type GitLike } from '../git/spawnGit.ts';
|
|
11
|
+
import { maxUsedNumber, nextNumber } from '../util/nextNumber.ts';
|
|
11
12
|
|
|
12
13
|
export interface NextIdIo {
|
|
13
14
|
listDir(path: string): string[];
|
|
@@ -63,8 +64,7 @@ export function collectNumbers(
|
|
|
63
64
|
|
|
64
65
|
export function harvestUniqueNumbers(io: NextIdIo, root: string): IdHarvest {
|
|
65
66
|
const { numbers, warnings } = collectNumbers(io, root);
|
|
66
|
-
|
|
67
|
-
return { maxNumber, nextNumber: maxNumber === null ? 1 : maxNumber + 1, warnings };
|
|
67
|
+
return { maxNumber: maxUsedNumber(numbers), nextNumber: nextNumber(numbers), warnings };
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
/**
|
|
@@ -73,14 +73,27 @@ export function harvestUniqueNumbers(io: NextIdIo, root: string): IdHarvest {
|
|
|
73
73
|
* failure degrades to the current tree only (best-effort, same grade as the
|
|
74
74
|
* archive sweep) with the cause recorded in warnings; the same number visible
|
|
75
75
|
* in more than one worktree raises a warning naming it and the worktrees.
|
|
76
|
+
* r35 (issue #8): `prunable` worktree entries and kept entries whose
|
|
77
|
+
* `llmanspec/` directory is absent count as empty trees — silently skipped,
|
|
78
|
+
* never warned; only real read errors reach warnings.
|
|
79
|
+
*
|
|
80
|
+
* r118: `instanceDirRel` is the harvested instance directory *relative to each
|
|
81
|
+
* worktree root* (`llmanspec` for the repo-root instance, e.g.
|
|
82
|
+
* `packages/tui/llmanspec` for a sub-project instance). Linked worktrees share
|
|
83
|
+
* one layout, so the same relative path addresses each checkout's own instance.
|
|
76
84
|
*/
|
|
77
|
-
export function harvestAcrossWorktrees(
|
|
85
|
+
export function harvestAcrossWorktrees(
|
|
86
|
+
git: GitLike,
|
|
87
|
+
io: NextIdIo,
|
|
88
|
+
instanceDirRel: string,
|
|
89
|
+
): IdHarvest {
|
|
78
90
|
const warnings: string[] = [];
|
|
79
91
|
let paths: string[] | null;
|
|
80
92
|
try {
|
|
81
93
|
const seen = new Set<string>();
|
|
82
94
|
paths = [];
|
|
83
95
|
for (const entry of worktreeList(git)) {
|
|
96
|
+
if (entry.prunable) continue;
|
|
84
97
|
const path = entry.path.replace(/\/+$/u, '');
|
|
85
98
|
if (!seen.has(path)) {
|
|
86
99
|
seen.add(path);
|
|
@@ -93,8 +106,10 @@ export function harvestAcrossWorktrees(git: GitLike, io: NextIdIo, root: string)
|
|
|
93
106
|
`worktree list failed: ${(error as Error).message} — scanned the current tree only`,
|
|
94
107
|
);
|
|
95
108
|
}
|
|
96
|
-
const trees = paths === null ? [
|
|
97
|
-
const perTree = trees
|
|
109
|
+
const trees = paths === null ? [instanceDirRel] : paths.map((p) => `${p}/${instanceDirRel}`);
|
|
110
|
+
const perTree = trees
|
|
111
|
+
.filter((at) => io.isDirectory(at))
|
|
112
|
+
.map((at) => ({ at, ...collectNumbers(io, at) }));
|
|
98
113
|
for (const tree of perTree) warnings.push(...tree.warnings);
|
|
99
114
|
const where = new Map<number, Set<string>>();
|
|
100
115
|
for (const tree of perTree) {
|
|
@@ -111,6 +126,5 @@ export function harvestAcrossWorktrees(git: GitLike, io: NextIdIo, root: string)
|
|
|
111
126
|
}
|
|
112
127
|
}
|
|
113
128
|
const all = perTree.flatMap((tree) => tree.numbers);
|
|
114
|
-
|
|
115
|
-
return { maxNumber, nextNumber: maxNumber === null ? 1 : maxNumber + 1, warnings };
|
|
129
|
+
return { maxNumber: maxUsedNumber(all), nextNumber: nextNumber(all), warnings };
|
|
116
130
|
}
|
package/src/config/changeId.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* template rendering (Strict via templates/engine.ts) with the predecessor preset vars.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { harvestUniqueNumbers, type NextIdIo } from '../change/nextId.ts';
|
|
8
7
|
import { renderTemplate } from '../templates/engine.ts';
|
|
9
8
|
|
|
10
9
|
export class ChangeIdError extends Error {}
|
|
@@ -58,11 +57,6 @@ export function renderChangeIdTemplate(template: string, vars: ChangeIdVars): st
|
|
|
58
57
|
return rendered;
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
/** Whole-tree next free number for the llman_sdd_unique_id preset var. */
|
|
62
|
-
export function nextUniqueNumber(io: NextIdIo, llmanspecRoot: string): number {
|
|
63
|
-
return harvestUniqueNumbers(io, llmanspecRoot).nextNumber;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
60
|
const VERB_TABLE = ['add', 'update', 'remove', 'refactor', 'fix'] as const;
|
|
67
61
|
|
|
68
62
|
/**
|
package/src/config/load.ts
CHANGED
|
@@ -66,13 +66,39 @@ export function elevateLegacyBdd(data: unknown): { data: unknown; legacyBddEleva
|
|
|
66
66
|
return { data: rec, legacyBddElevated: true };
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Removed-key stripping (config-schema r102): `specs.check_transitions` is
|
|
71
|
+
* gone — transition validation is tag-scoped per scenario (validation r104).
|
|
72
|
+
* Any value (booleans included) is dropped before schema parsing and the
|
|
73
|
+
* caller surfaces the migration warning. Pure — never mutates the input.
|
|
74
|
+
*/
|
|
75
|
+
export function stripLegacyCheckTransitions(data: unknown): { data: unknown; stripped: boolean } {
|
|
76
|
+
if (typeof data !== 'object' || data === null || Array.isArray(data)) {
|
|
77
|
+
return { data, stripped: false };
|
|
78
|
+
}
|
|
79
|
+
const rec = data as Record<string, unknown>;
|
|
80
|
+
const specs = rec['specs'];
|
|
81
|
+
if (typeof specs !== 'object' || specs === null || Array.isArray(specs)) {
|
|
82
|
+
return { data, stripped: false };
|
|
83
|
+
}
|
|
84
|
+
if (!('check_transitions' in specs)) return { data, stripped: false };
|
|
85
|
+
const nextSpecs: Record<string, unknown> = { ...(specs as Record<string, unknown>) };
|
|
86
|
+
delete nextSpecs['check_transitions'];
|
|
87
|
+
return { data: { ...rec, specs: nextSpecs }, stripped: true };
|
|
88
|
+
}
|
|
89
|
+
|
|
69
90
|
/**
|
|
70
91
|
* Load + validate, returning the parsed config and whether a legacy `bdd:`
|
|
71
92
|
* section was elevated. The CLI surfaces the migration warning from the flag.
|
|
93
|
+
* `localeExplicit` reports whether the raw mapping carried a `locale` key at
|
|
94
|
+
* all — the schema default (r18-normalized `zh-Hans`) erases that distinction,
|
|
95
|
+
* but init needs it for the effective-locale precedence chain (init-generators r50).
|
|
72
96
|
*/
|
|
73
97
|
export function loadConfigDetail(source: string): {
|
|
74
98
|
config: SddConfig;
|
|
75
99
|
legacyBddElevated: boolean;
|
|
100
|
+
legacyCheckTransitionsStripped: boolean;
|
|
101
|
+
localeExplicit: boolean;
|
|
76
102
|
} {
|
|
77
103
|
let data: unknown;
|
|
78
104
|
try {
|
|
@@ -82,8 +108,11 @@ export function loadConfigDetail(source: string): {
|
|
|
82
108
|
`YAML parse error: ${error instanceof Error ? error.message : String(error)}`,
|
|
83
109
|
]);
|
|
84
110
|
}
|
|
111
|
+
const localeExplicit =
|
|
112
|
+
typeof data === 'object' && data !== null && !Array.isArray(data) && 'locale' in data;
|
|
85
113
|
const elevated = elevateLegacyBdd(data);
|
|
86
|
-
const
|
|
114
|
+
const stripped = stripLegacyCheckTransitions(elevated.data);
|
|
115
|
+
const result = sddConfigSchema.safeParse(stripped.data);
|
|
87
116
|
if (!result.success) {
|
|
88
117
|
const issues = result.error.issues.map((iss) => {
|
|
89
118
|
const path = iss.path.map(String).join('/');
|
|
@@ -104,7 +133,12 @@ export function loadConfigDetail(source: string): {
|
|
|
104
133
|
throw new ConfigValidationError([(error as Error).message]);
|
|
105
134
|
}
|
|
106
135
|
}
|
|
107
|
-
return {
|
|
136
|
+
return {
|
|
137
|
+
config: result.data,
|
|
138
|
+
legacyBddElevated: elevated.legacyBddElevated,
|
|
139
|
+
legacyCheckTransitionsStripped: stripped.stripped,
|
|
140
|
+
localeExplicit,
|
|
141
|
+
};
|
|
108
142
|
}
|
|
109
143
|
|
|
110
144
|
export function loadConfig(source: string): SddConfig {
|
package/src/config/schema.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { z } from 'zod';
|
|
8
8
|
|
|
9
|
+
import { DEFAULT_LOCALE } from '../locale.ts';
|
|
10
|
+
|
|
9
11
|
export const EXTRA_SKILLS = [
|
|
10
12
|
'llman-sdd-continue',
|
|
11
13
|
'llman-sdd-ff',
|
|
@@ -29,12 +31,6 @@ export const specsSchema = z.object({
|
|
|
29
31
|
'Spec verification command executed by validate for spec targets (opt-in via --check; default skips). Placeholders: {feature_path}, {feature_dir}, {feature_name}; without placeholders it runs once per validate invocation (batch-once). Legacy `bdd.run_command` is elevated onto this key at load time.',
|
|
30
32
|
),
|
|
31
33
|
verify_prompt: z.string().nullish().describe('Extra prompt text injected during verify phase.'),
|
|
32
|
-
check_transitions: z
|
|
33
|
-
.boolean()
|
|
34
|
-
.nullish()
|
|
35
|
-
.describe(
|
|
36
|
-
'When true, automatically discovers Gherkin Scenario Outline state transition tables (from/event/to) and enforces strict XState graph gates (determinism, reachability, deadlock, and step placeholder binding). Default: false.',
|
|
37
|
-
),
|
|
38
34
|
});
|
|
39
35
|
|
|
40
36
|
export const archiveSchema = z.object({
|
|
@@ -80,7 +76,7 @@ export const changeIdSchema = z.object({
|
|
|
80
76
|
|
|
81
77
|
export const sddConfigSchema = z.object({
|
|
82
78
|
schema: z.literal('spec-driven').describe('Schema identifier. Must be "spec-driven".'),
|
|
83
|
-
locale: z.string().default(
|
|
79
|
+
locale: z.string().default(DEFAULT_LOCALE).describe('Locale used for SDD templates and skills.'),
|
|
84
80
|
extra_skills: z
|
|
85
81
|
.array(z.enum(EXTRA_SKILLS))
|
|
86
82
|
.nullish()
|