@llman-sdd/core 0.9.0 → 0.10.1
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 +2 -1
- package/src/archive/freeze.ts +45 -22
- package/src/archive/frozenCard.ts +3 -2
- package/src/archive/ignoreChain.ts +167 -0
- package/src/archive/sevenzip.ts +17 -8
- 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 +33 -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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@llman-sdd/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Pure domain logic for llman-sdd (config, gherkin specs, validation, templates)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"@cucumber/messages": "^34.2.1",
|
|
30
30
|
"@statelyai/graph": "^2.6.0",
|
|
31
31
|
"@toon-format/toon": "^4.1.1",
|
|
32
|
+
"ignore": "^7.0.12",
|
|
32
33
|
"nunjucks": "^3.2.4",
|
|
33
34
|
"xstate": "^5.33.2",
|
|
34
35
|
"yaml": "^2.9.1",
|
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,
|
|
@@ -17,27 +19,26 @@ import {
|
|
|
17
19
|
frozenCardName,
|
|
18
20
|
isFrozenCard,
|
|
19
21
|
} from './frozenCard.ts';
|
|
22
|
+
import { collectFilteredEntries } from './ignoreChain.ts';
|
|
20
23
|
import type { SevenZipPort } from './sevenzip.ts';
|
|
21
24
|
|
|
22
25
|
export const FREEZE_ARCHIVE_NAME = 'freezed_changes.7z.archived';
|
|
23
26
|
export const ARCHIVE_DIR_REL = 'llmanspec/changes/archive';
|
|
24
27
|
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
removeDir
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
moveDir(from: string, to: string): void;
|
|
38
|
-
}
|
|
28
|
+
export type FreezeIo = Pick<
|
|
29
|
+
FsPort,
|
|
30
|
+
| 'exists'
|
|
31
|
+
| 'listDir'
|
|
32
|
+
| 'readText'
|
|
33
|
+
| 'writeText'
|
|
34
|
+
| 'isDirectory'
|
|
35
|
+
| 'removeDir'
|
|
36
|
+
| 'remove'
|
|
37
|
+
| 'mkdirp'
|
|
38
|
+
| 'moveDir'
|
|
39
|
+
>;
|
|
39
40
|
|
|
40
|
-
const DATED_RE =
|
|
41
|
+
const DATED_RE = DATED_PREFIX_RE;
|
|
41
42
|
|
|
42
43
|
/**
|
|
43
44
|
* r24: freeze candidates = date-prefixed entries that are directories with a
|
|
@@ -65,6 +66,9 @@ export interface FreezeOpts {
|
|
|
65
66
|
before?: string;
|
|
66
67
|
keepRecent?: number;
|
|
67
68
|
dryRun?: boolean;
|
|
69
|
+
/** r120: absolute paths of extra gitignore-format files (highest
|
|
70
|
+
* precedence in the layered evaluation; nonexistent file is an error). */
|
|
71
|
+
ignoreFiles?: string[];
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
export interface FreezeRunResult {
|
|
@@ -96,6 +100,24 @@ export async function runFreeze(
|
|
|
96
100
|
// Card = authoritative record that bodies are in the cold backup. Write
|
|
97
101
|
// cards first; on `7z add` failure roll them back and keep the original dirs.
|
|
98
102
|
const archiveAbs = join(rootAbs, ARCHIVE_DIR_REL, FREEZE_ARCHIVE_NAME);
|
|
103
|
+
const archiveBase = join(rootAbs, ARCHIVE_DIR_REL);
|
|
104
|
+
|
|
105
|
+
// r120: layered gitignore filtering runs before any mutation — user-file
|
|
106
|
+
// existence errors and the zero-files guard must leave the tree untouched.
|
|
107
|
+
const packed: string[] = [];
|
|
108
|
+
let excludedTotal = 0;
|
|
109
|
+
for (const c of candidates) {
|
|
110
|
+
const { files, excluded } = collectFilteredEntries(io, {
|
|
111
|
+
rootAbs,
|
|
112
|
+
candidateAbs: join(archiveBase, c),
|
|
113
|
+
userIgnoreFiles: opts.ignoreFiles ?? [],
|
|
114
|
+
});
|
|
115
|
+
if (files.length === 0) {
|
|
116
|
+
throw new Error(`candidate has no packable files after ignore filtering: ${c}`);
|
|
117
|
+
}
|
|
118
|
+
excludedTotal += excluded;
|
|
119
|
+
packed.push(...files.map((f) => `${c}/${f}`));
|
|
120
|
+
}
|
|
99
121
|
|
|
100
122
|
const cards: Array<{ datedId: string; source: string }> = [];
|
|
101
123
|
for (const c of candidates) {
|
|
@@ -116,7 +138,7 @@ export async function runFreeze(
|
|
|
116
138
|
io.writeText(`${ARCHIVE_DIR_REL}/${frozenCardName(card.datedId)}`, card.source);
|
|
117
139
|
}
|
|
118
140
|
try {
|
|
119
|
-
await sz.add(archiveAbs,
|
|
141
|
+
await sz.add(archiveAbs, archiveBase, packed);
|
|
120
142
|
} catch (error) {
|
|
121
143
|
for (const card of cards) io.remove(`${ARCHIVE_DIR_REL}/${frozenCardName(card.datedId)}`);
|
|
122
144
|
throw error;
|
|
@@ -124,12 +146,13 @@ export async function runFreeze(
|
|
|
124
146
|
for (const c of candidates) {
|
|
125
147
|
io.removeDir(`${ARCHIVE_DIR_REL}/${c}`);
|
|
126
148
|
}
|
|
127
|
-
|
|
128
|
-
candidates
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
149
|
+
const lines = [
|
|
150
|
+
`Froze ${candidates.length} archived changes into ./${ARCHIVE_DIR_REL}/${FREEZE_ARCHIVE_NAME}`,
|
|
151
|
+
];
|
|
152
|
+
if (excludedTotal > 0) {
|
|
153
|
+
lines.push(`Excluded ${excludedTotal} ignored file(s) via gitignore chain`);
|
|
154
|
+
}
|
|
155
|
+
return { candidates, lines };
|
|
133
156
|
}
|
|
134
157
|
|
|
135
158
|
/**
|
|
@@ -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 {
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* r120 freeze content filter: git-style layered .gitignore evaluation for
|
|
3
|
+
* `archive freeze` (review-freeze capability). For each candidate directory
|
|
4
|
+
* the packer walks the tree and keeps only files no ignore layer decides
|
|
5
|
+
* against: user-supplied `--ignore-file` layers first (highest precedence),
|
|
6
|
+
* then `.gitignore` files found while descending (deeper wins), then the
|
|
7
|
+
* ancestor chain from the candidate dir up to the discovered project root
|
|
8
|
+
* (nearest ancestor holding `.git`; the instance root when absent).
|
|
9
|
+
*
|
|
10
|
+
* Purity: filesystem access flows through the injected IgnoreChainIo; the
|
|
11
|
+
* `ignore` package is a pure pattern engine. All paths are absolute here;
|
|
12
|
+
* POSIX relativization happens per layer (anchoring base = the layer's own
|
|
13
|
+
* directory, exactly like git).
|
|
14
|
+
*/
|
|
15
|
+
import { dirname, join, relative, sep } from 'node:path';
|
|
16
|
+
|
|
17
|
+
import * as ignoreModule from 'ignore';
|
|
18
|
+
|
|
19
|
+
import type { FsPort } from '../util/fsPort.ts';
|
|
20
|
+
|
|
21
|
+
type Ignore = ignoreModule.Ignore;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* CJS `export =` interop: both Bun and Node surface the factory on
|
|
25
|
+
* `.default` while the ESM namespace itself is not callable — and under
|
|
26
|
+
* verbatimModuleSyntax tsc types the namespace import as a pure namespace,
|
|
27
|
+
* so the callable is recovered through a structural cast against the
|
|
28
|
+
* package's own `Ignore` interface.
|
|
29
|
+
*/
|
|
30
|
+
const createIgnore = (ignoreModule as unknown as { default: () => Ignore }).default;
|
|
31
|
+
|
|
32
|
+
export type IgnoreChainIo = Pick<FsPort, 'exists' | 'listDir' | 'readText' | 'isDirectory'>;
|
|
33
|
+
|
|
34
|
+
export class IgnoreChainError extends Error {}
|
|
35
|
+
|
|
36
|
+
/** One `.gitignore`-style rule set; `base` is the anchoring directory. */
|
|
37
|
+
interface Layer {
|
|
38
|
+
base: string;
|
|
39
|
+
ig: Ignore;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface FilteredCandidate {
|
|
43
|
+
/** POSIX file paths relative to the candidate dir (7z entry base). */
|
|
44
|
+
files: string[];
|
|
45
|
+
/** Files excluded by ignore rules (pruned directories count recursively). */
|
|
46
|
+
excluded: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function toPosix(p: string): string {
|
|
50
|
+
return sep === '/' ? p : p.split(sep).join('/');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function relPosix(from: string, to: string): string {
|
|
54
|
+
return toPosix(relative(from, to));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Outermost ignore root: the nearest ancestor of `start` (inclusive) holding
|
|
59
|
+
* `.git` (a directory, or the file git uses for worktrees); when the tree is
|
|
60
|
+
* not inside a git repository the instance root `start` itself is the
|
|
61
|
+
* outermost layer (r120 fallback semantics).
|
|
62
|
+
*/
|
|
63
|
+
export function discoverIgnoreRoot(io: IgnoreChainIo, start: string): string {
|
|
64
|
+
let cur = start;
|
|
65
|
+
for (;;) {
|
|
66
|
+
if (io.exists(join(cur, '.git'))) return cur;
|
|
67
|
+
const parent = dirname(cur);
|
|
68
|
+
if (parent === cur) return start;
|
|
69
|
+
cur = parent;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function loadLayer(io: IgnoreChainIo, base: string): Layer | null {
|
|
74
|
+
const path = join(base, '.gitignore');
|
|
75
|
+
if (!io.exists(path)) return null;
|
|
76
|
+
return { base, ig: createIgnore().add(io.readText(path)) };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** First decisive layer wins: user files → deepest walk layer → ancestors. */
|
|
80
|
+
function decide(
|
|
81
|
+
user: readonly Layer[],
|
|
82
|
+
walk: readonly Layer[],
|
|
83
|
+
ancestors: readonly Layer[],
|
|
84
|
+
pathAbs: string,
|
|
85
|
+
isDir: boolean,
|
|
86
|
+
): boolean {
|
|
87
|
+
const layers: Layer[] = [...user];
|
|
88
|
+
for (let i = walk.length - 1; i >= 0; i--) layers.push(walk[i]!);
|
|
89
|
+
layers.push(...ancestors);
|
|
90
|
+
for (const layer of layers) {
|
|
91
|
+
let rel = relPosix(layer.base, pathAbs);
|
|
92
|
+
// A .gitignore governs only its own subtree (git semantics); layers the
|
|
93
|
+
// path lies outside of cannot decide and must not be consulted.
|
|
94
|
+
if (rel === '' || rel === '..' || rel.startsWith('../')) continue;
|
|
95
|
+
if (isDir) rel = `${rel}/`;
|
|
96
|
+
const verdict = layer.ig.test(rel);
|
|
97
|
+
if (verdict.ignored || verdict.unignored) return verdict.ignored;
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function countFiles(io: IgnoreChainIo, dirAbs: string): number {
|
|
103
|
+
let n = 0;
|
|
104
|
+
for (const name of io.listDir(dirAbs)) {
|
|
105
|
+
if (name === '.git') continue;
|
|
106
|
+
const abs = join(dirAbs, name);
|
|
107
|
+
n += io.isDirectory(abs) ? countFiles(io, abs) : 1;
|
|
108
|
+
}
|
|
109
|
+
return n;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface CollectFilteredOpts {
|
|
113
|
+
/** Instance root (absolute) — ignore-root discovery starts here. */
|
|
114
|
+
rootAbs: string;
|
|
115
|
+
/** Candidate change directory (absolute, under the instance root). */
|
|
116
|
+
candidateAbs: string;
|
|
117
|
+
/** Absolute paths of extra gitignore-format files (highest precedence,
|
|
118
|
+
* anchored at the candidate dir — extras describe per-change junk). */
|
|
119
|
+
userIgnoreFiles: string[];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function collectFilteredEntries(
|
|
123
|
+
io: IgnoreChainIo,
|
|
124
|
+
opts: CollectFilteredOpts,
|
|
125
|
+
): FilteredCandidate {
|
|
126
|
+
const user: Layer[] = [];
|
|
127
|
+
for (const file of opts.userIgnoreFiles) {
|
|
128
|
+
if (!io.exists(file)) {
|
|
129
|
+
throw new IgnoreChainError(`ignore file not found: ${file}`);
|
|
130
|
+
}
|
|
131
|
+
user.push({ base: opts.candidateAbs, ig: createIgnore().add(io.readText(file)) });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Ancestor chain: candidate dir first (highest of the fixed layers), then
|
|
135
|
+
// each parent up to the discovered ignore root (outermost, last).
|
|
136
|
+
const outer = discoverIgnoreRoot(io, opts.rootAbs);
|
|
137
|
+
const ancestors: Layer[] = [];
|
|
138
|
+
for (let cur = opts.candidateAbs; ; cur = dirname(cur)) {
|
|
139
|
+
const layer = loadLayer(io, cur);
|
|
140
|
+
if (layer) ancestors.push(layer);
|
|
141
|
+
if (cur === outer) break;
|
|
142
|
+
const parent = dirname(cur);
|
|
143
|
+
if (parent === cur) break; // defensive: ignore root not an ancestor
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const walk: Layer[] = [];
|
|
147
|
+
const files: string[] = [];
|
|
148
|
+
let excluded = 0;
|
|
149
|
+
const visit = (dirAbs: string): void => {
|
|
150
|
+
const layer = loadLayer(io, dirAbs);
|
|
151
|
+
if (layer) walk.push(layer);
|
|
152
|
+
for (const name of io.listDir(dirAbs).toSorted()) {
|
|
153
|
+
if (name === '.git') continue; // git never packs .git metadata (r120)
|
|
154
|
+
const abs = join(dirAbs, name);
|
|
155
|
+
const isDir = io.isDirectory(abs);
|
|
156
|
+
if (decide(user, walk, ancestors, abs, isDir)) {
|
|
157
|
+
excluded += isDir ? countFiles(io, abs) : 1;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (isDir) visit(abs);
|
|
161
|
+
else files.push(relPosix(opts.candidateAbs, abs));
|
|
162
|
+
}
|
|
163
|
+
if (layer) walk.pop();
|
|
164
|
+
};
|
|
165
|
+
visit(opts.candidateAbs);
|
|
166
|
+
return { files, excluded };
|
|
167
|
+
}
|
package/src/archive/sevenzip.ts
CHANGED
|
@@ -82,10 +82,15 @@ function mount(mod: EmscriptenModule, seq: number, hostDir: string): string {
|
|
|
82
82
|
return mountpoint;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
/** 7z `l` listing: header/footer dashed rules around fixed-ish columns
|
|
86
|
-
*
|
|
85
|
+
/** 7z `l` listing: header/footer dashed rules around fixed-ish columns.
|
|
86
|
+
* Column offsets come from the header row, NOT whitespace splitting — solid
|
|
87
|
+
* blocks leave the Compressed cell empty for every file after the block
|
|
88
|
+
* head, which collapses the column count and silently dropped those rows
|
|
89
|
+
* (surfaced by r120's explicit file lists; our entry names are space-free). */
|
|
87
90
|
function parseListNames(lines: string[]): string[] {
|
|
88
91
|
const names: string[] = [];
|
|
92
|
+
let nameCol = -1;
|
|
93
|
+
let attrCol = -1;
|
|
89
94
|
let inTable = false;
|
|
90
95
|
let rulesSeen = 0;
|
|
91
96
|
for (const line of lines) {
|
|
@@ -95,14 +100,18 @@ function parseListNames(lines: string[]): string[] {
|
|
|
95
100
|
if (rulesSeen === 3) break;
|
|
96
101
|
continue;
|
|
97
102
|
}
|
|
98
|
-
if (inTable) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const name = parts.slice(5).join(' ');
|
|
103
|
-
if (name !== '' && !attr.includes('D')) names.push(name);
|
|
103
|
+
if (!inTable) {
|
|
104
|
+
if (/\bDate\s+Time\s+Attr\b/u.test(line)) {
|
|
105
|
+
nameCol = line.lastIndexOf('Name');
|
|
106
|
+
attrCol = line.lastIndexOf('Attr');
|
|
104
107
|
}
|
|
108
|
+
continue;
|
|
105
109
|
}
|
|
110
|
+
if (nameCol < 0 || attrCol < 0 || line.trim() === '') continue;
|
|
111
|
+
// Attr cells are fixed-width 5 chars (e.g. `....A`, `D....`).
|
|
112
|
+
const attr = line.slice(attrCol, attrCol + 5);
|
|
113
|
+
const name = line.slice(nameCol).trim();
|
|
114
|
+
if (name !== '' && !attr.includes('D')) names.push(name);
|
|
106
115
|
}
|
|
107
116
|
return names;
|
|
108
117
|
}
|
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 {
|