@llman-sdd/core 0.9.0 → 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 +14 -6
- package/src/config/changeId.ts +0 -6
- package/src/config/load.ts +2 -2
- package/src/config/schema.ts +3 -1
- package/src/context/indexStore.ts +14 -14
- package/src/context/sddState.ts +1 -13
- package/src/context/tree.ts +9 -19
- package/src/index.ts +25 -9
- package/src/init/defaultConfig.ts +14 -31
- package/src/init/init.ts +25 -27
- package/src/locale.ts +33 -0
- package/src/project/migrations.ts +79 -9
- 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 -30
- 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 +4 -9
- package/src/validation/xstateTransitions.ts +0 -32
- 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
|
/**
|
|
@@ -76,8 +76,17 @@ export function harvestUniqueNumbers(io: NextIdIo, root: string): IdHarvest {
|
|
|
76
76
|
* r35 (issue #8): `prunable` worktree entries and kept entries whose
|
|
77
77
|
* `llmanspec/` directory is absent count as empty trees — silently skipped,
|
|
78
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.
|
|
79
84
|
*/
|
|
80
|
-
export function harvestAcrossWorktrees(
|
|
85
|
+
export function harvestAcrossWorktrees(
|
|
86
|
+
git: GitLike,
|
|
87
|
+
io: NextIdIo,
|
|
88
|
+
instanceDirRel: string,
|
|
89
|
+
): IdHarvest {
|
|
81
90
|
const warnings: string[] = [];
|
|
82
91
|
let paths: string[] | null;
|
|
83
92
|
try {
|
|
@@ -97,7 +106,7 @@ export function harvestAcrossWorktrees(git: GitLike, io: NextIdIo, root: string)
|
|
|
97
106
|
`worktree list failed: ${(error as Error).message} — scanned the current tree only`,
|
|
98
107
|
);
|
|
99
108
|
}
|
|
100
|
-
const trees = paths === null ? [
|
|
109
|
+
const trees = paths === null ? [instanceDirRel] : paths.map((p) => `${p}/${instanceDirRel}`);
|
|
101
110
|
const perTree = trees
|
|
102
111
|
.filter((at) => io.isDirectory(at))
|
|
103
112
|
.map((at) => ({ at, ...collectNumbers(io, at) }));
|
|
@@ -117,6 +126,5 @@ export function harvestAcrossWorktrees(git: GitLike, io: NextIdIo, root: string)
|
|
|
117
126
|
}
|
|
118
127
|
}
|
|
119
128
|
const all = perTree.flatMap((tree) => tree.numbers);
|
|
120
|
-
|
|
121
|
-
return { maxNumber, nextNumber: maxNumber === null ? 1 : maxNumber + 1, warnings };
|
|
129
|
+
return { maxNumber: maxUsedNumber(all), nextNumber: nextNumber(all), warnings };
|
|
122
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
|
@@ -91,8 +91,8 @@ export function stripLegacyCheckTransitions(data: unknown): { data: unknown; str
|
|
|
91
91
|
* Load + validate, returning the parsed config and whether a legacy `bdd:`
|
|
92
92
|
* section was elevated. The CLI surfaces the migration warning from the flag.
|
|
93
93
|
* `localeExplicit` reports whether the raw mapping carried a `locale` key at
|
|
94
|
-
* all — the schema default (
|
|
95
|
-
* for the effective-locale precedence chain (init-generators r50).
|
|
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).
|
|
96
96
|
*/
|
|
97
97
|
export function loadConfigDetail(source: string): {
|
|
98
98
|
config: 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',
|
|
@@ -74,7 +76,7 @@ export const changeIdSchema = z.object({
|
|
|
74
76
|
|
|
75
77
|
export const sddConfigSchema = z.object({
|
|
76
78
|
schema: z.literal('spec-driven').describe('Schema identifier. Must be "spec-driven".'),
|
|
77
|
-
locale: z.string().default(
|
|
79
|
+
locale: z.string().default(DEFAULT_LOCALE).describe('Locale used for SDD templates and skills.'),
|
|
78
80
|
extra_skills: z
|
|
79
81
|
.array(z.enum(EXTRA_SKILLS))
|
|
80
82
|
.nullish()
|
|
@@ -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
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
currentPid
|
|
26
|
-
|
|
27
|
-
|
|
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;
|
package/src/context/sddState.ts
CHANGED
|
@@ -46,16 +46,4 @@ export function readSddState(io: Pick<StateIo, 'exists' | 'readText'>): SddState
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
|
|
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';
|