@llman-sdd/core 0.7.2 → 0.7.3
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/context/sddState.ts +61 -0
- package/src/index.ts +7 -0
- package/src/init/init.ts +5 -0
- package/src/review/review.ts +1 -0
- package/src/spec/ir.ts +6 -0
- package/src/spec/parser.ts +13 -4
- package/src/templates/skills.ts +2 -0
- package/src/validation/staleness.ts +45 -1
- package/templates/en/skills/llman-sdd-apply.md +4 -0
- package/templates/en/skills/llman-sdd-verify.md +4 -0
- package/templates/en/units/skills/review-stamp.md +3 -0
- package/templates/en/units/skills/version-drift.md +3 -0
- package/templates/zh-Hans/skills/llman-sdd-apply.md +4 -0
- package/templates/zh-Hans/skills/llman-sdd-verify.md +4 -0
- package/templates/zh-Hans/units/skills/review-stamp.md +3 -0
- package/templates/zh-Hans/units/skills/version-drift.md +3 -0
package/package.json
CHANGED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scaffold-state record (version-awareness capability): init stamps the CLI
|
|
3
|
+
* version that rendered the project so later runs can detect drift. All paths
|
|
4
|
+
* ROOT-RELATIVE through the injected IO; corrupt/missing state is silent-OK
|
|
5
|
+
* (the notice is best-effort, never load-bearing).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { CONTEXT_DIR_REL } from './indexStore.ts';
|
|
9
|
+
|
|
10
|
+
export const SDD_STATE_REL = `${CONTEXT_DIR_REL}/sdd-state.json`;
|
|
11
|
+
|
|
12
|
+
export interface SddState {
|
|
13
|
+
/** llman-sdd version that last rendered this project (init / --update). */
|
|
14
|
+
cli_version: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type StateIo = {
|
|
18
|
+
exists(path: string): boolean;
|
|
19
|
+
readText(path: string): string;
|
|
20
|
+
writeText(path: string, content: string): void;
|
|
21
|
+
mkdirp(path: string): void;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** Persist the scaffold version (called from runInit after config resolution). */
|
|
25
|
+
export function writeSddState(io: StateIo, version: string): void {
|
|
26
|
+
io.mkdirp(CONTEXT_DIR_REL);
|
|
27
|
+
const state: SddState = { cli_version: version };
|
|
28
|
+
io.writeText(SDD_STATE_REL, `${JSON.stringify(state, null, 2)}\n`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Read the recorded version; null when absent/corrupt (silent-OK contract). */
|
|
32
|
+
export function readSddState(io: Pick<StateIo, 'exists' | 'readText'>): SddState | null {
|
|
33
|
+
if (!io.exists(SDD_STATE_REL)) return null;
|
|
34
|
+
try {
|
|
35
|
+
const parsed: unknown = JSON.parse(io.readText(SDD_STATE_REL));
|
|
36
|
+
if (
|
|
37
|
+
typeof parsed === 'object' &&
|
|
38
|
+
parsed !== null &&
|
|
39
|
+
typeof (parsed as SddState).cli_version === 'string'
|
|
40
|
+
) {
|
|
41
|
+
return parsed as SddState;
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
} catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const dot = (v: string): number => Math.trunc(Number(v)) || 0;
|
|
50
|
+
|
|
51
|
+
/** Numeric semver-major.minor.patch compare; non-numeric segments compare 0. */
|
|
52
|
+
export function semverLt(a: string, b: string): boolean {
|
|
53
|
+
const pa = a.split('.');
|
|
54
|
+
const pb = b.split('.');
|
|
55
|
+
for (let i = 0; i < 3; i++) {
|
|
56
|
+
const ai = dot(pa[i] ?? '0');
|
|
57
|
+
const bi = dot(pb[i] ?? '0');
|
|
58
|
+
if (ai !== bi) return ai < bi;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -300,6 +300,13 @@ export {
|
|
|
300
300
|
type RebuildOpts,
|
|
301
301
|
type RebuildResult,
|
|
302
302
|
} from './context/indexStore.ts';
|
|
303
|
+
export {
|
|
304
|
+
SDD_STATE_REL,
|
|
305
|
+
readSddState,
|
|
306
|
+
semverLt,
|
|
307
|
+
writeSddState,
|
|
308
|
+
type SddState,
|
|
309
|
+
} from './context/sddState.ts';
|
|
303
310
|
export {
|
|
304
311
|
resolveChatConfig,
|
|
305
312
|
runContextRetrieval,
|
package/src/init/init.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { join } from 'node:path';
|
|
10
10
|
|
|
11
11
|
import { loadConfig } from '../config/load.ts';
|
|
12
|
+
import { writeSddState } from '../context/sddState.ts';
|
|
12
13
|
import { renderTemplate } from '../templates/engine.ts';
|
|
13
14
|
import { localeFallbacks } from '../templates/locale.ts';
|
|
14
15
|
import {
|
|
@@ -122,6 +123,10 @@ export function runInit(
|
|
|
122
123
|
if (!io.exists(configPath)) writeDefaultConfig(io, opts.locale ?? 'en');
|
|
123
124
|
const config = loadConfig(io.readText(configPath));
|
|
124
125
|
|
|
126
|
+
// 1b) scaffold-state stamp: record the rendering version for drift notices
|
|
127
|
+
// (version-awareness). Corrupt/missing state on later reads is silent-OK.
|
|
128
|
+
writeSddState(io, opts.version);
|
|
129
|
+
|
|
125
130
|
// 2) scaffold directories.
|
|
126
131
|
io.mkdirp('llmanspec/specs');
|
|
127
132
|
io.mkdirp('llmanspec/changes/archive');
|
package/src/review/review.ts
CHANGED
|
@@ -84,6 +84,7 @@ export function buildReview(input: ReviewInput, io: SpecIo): ReviewResult {
|
|
|
84
84
|
root: input.root,
|
|
85
85
|
specRel,
|
|
86
86
|
scope: entry.doc.header.scope?.split(',').map((x) => x.trim()) ?? [],
|
|
87
|
+
reviewedThrough: entry.doc.header.reviewedThrough,
|
|
87
88
|
baseRefEnv: input.baseRefEnv,
|
|
88
89
|
});
|
|
89
90
|
staleInfo = evalResult.info;
|
package/src/spec/ir.ts
CHANGED
|
@@ -14,6 +14,12 @@ export interface CapabilityHeader {
|
|
|
14
14
|
capability: string | null;
|
|
15
15
|
purpose: string | null;
|
|
16
16
|
scope: string | null;
|
|
17
|
+
/**
|
|
18
|
+
* `# reviewed-through: <change-id>` — newest change through which this
|
|
19
|
+
* capability's governed behaviour was reviewed unchanged (re-review stamp
|
|
20
|
+
* governance). Consumers (staleness) compare it against branch history.
|
|
21
|
+
*/
|
|
22
|
+
reviewedThrough: string | null;
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
export type ScenarioStepKind = 'given' | 'when' | 'then';
|
package/src/spec/parser.ts
CHANGED
|
@@ -79,17 +79,26 @@ function stepKeywordToKind(keyword: string): ScenarioStepKind {
|
|
|
79
79
|
return stepKeywordToOfficialKind(keyword) ?? 'given';
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
const HEADER_RE = /^#\s*(capability|purpose|scope):\s*(.*)$/u;
|
|
82
|
+
const HEADER_RE = /^#\s*(capability|purpose|scope|reviewed-through):\s*(.*)$/u;
|
|
83
83
|
|
|
84
84
|
function extractHeader(source: string): CapabilityHeader {
|
|
85
|
-
const header: CapabilityHeader = {
|
|
85
|
+
const header: CapabilityHeader = {
|
|
86
|
+
capability: null,
|
|
87
|
+
purpose: null,
|
|
88
|
+
scope: null,
|
|
89
|
+
reviewedThrough: null,
|
|
90
|
+
};
|
|
86
91
|
for (const line of source.split('\n')) {
|
|
87
92
|
if (line.trim() === '') continue;
|
|
88
93
|
if (!line.trimStart().startsWith('#')) break;
|
|
89
94
|
const m = line.trimStart().match(HEADER_RE);
|
|
90
95
|
if (m?.[1]) {
|
|
91
|
-
const
|
|
92
|
-
|
|
96
|
+
const raw = m[1];
|
|
97
|
+
const field: 'capability' | 'purpose' | 'scope' | 'reviewedThrough' =
|
|
98
|
+
raw === 'reviewed-through'
|
|
99
|
+
? 'reviewedThrough'
|
|
100
|
+
: (raw as 'capability' | 'purpose' | 'scope');
|
|
101
|
+
header[field] = m[2]?.trim() ?? null;
|
|
93
102
|
}
|
|
94
103
|
}
|
|
95
104
|
return header;
|
package/src/templates/skills.ts
CHANGED
|
@@ -35,6 +35,8 @@ export const UNIT_FILES: readonly string[] = [
|
|
|
35
35
|
'skills/git-native-flow-brief.md',
|
|
36
36
|
'skills/stage-guard.md',
|
|
37
37
|
'skills/ethics-governance.md',
|
|
38
|
+
'skills/version-drift.md',
|
|
39
|
+
'skills/review-stamp.md',
|
|
38
40
|
'spec/feature-contract.md',
|
|
39
41
|
'skills/structured-protocol.md',
|
|
40
42
|
'skills/cli-footer.md',
|
|
@@ -31,6 +31,12 @@ export interface StalenessDeps {
|
|
|
31
31
|
specRel: string;
|
|
32
32
|
/** scope entries from the `# scope:` header (raw, unnormalized) */
|
|
33
33
|
scope: string[];
|
|
34
|
+
/**
|
|
35
|
+
* `# reviewed-through: <id>` header value (re-review stamp governance): when
|
|
36
|
+
* set, a STALE verdict is suppressed iff every scope-touching commit on the
|
|
37
|
+
* branch mentions that change id — the recorded no-behavior-change review.
|
|
38
|
+
*/
|
|
39
|
+
reviewedThrough?: string | null;
|
|
34
40
|
/** env override for LLMANSPEC_BASE_REF */
|
|
35
41
|
baseRefEnv?: string;
|
|
36
42
|
defaultBranchName?: string;
|
|
@@ -116,9 +122,18 @@ export function evaluateStaleness(deps: StalenessDeps): {
|
|
|
116
122
|
specUpdated = paths.some((p) => normalizePath(p) === normalizePath(specRel));
|
|
117
123
|
touchedPaths = paths.filter((p) => scopeMatches(p, normScope));
|
|
118
124
|
}
|
|
119
|
-
|
|
125
|
+
const reviewAcked =
|
|
126
|
+
touchedPaths.length > 0 &&
|
|
127
|
+
!specUpdated &&
|
|
128
|
+
reviewCoversBranch(deps.reviewedThrough ?? null, git, baseRef);
|
|
129
|
+
if (touchedPaths.length > 0 && !specUpdated && !reviewAcked) {
|
|
120
130
|
status = 'STALE' as StalenessStatus;
|
|
121
131
|
issues.push({ level: 'WARNING', path: `${specId()}/staleness`, message: STALE_MSG });
|
|
132
|
+
} else if (reviewAcked) {
|
|
133
|
+
// confirm-style ack: scope touched, spec untouched, reviewed-through
|
|
134
|
+
// covers the branch — downgrade to OK with an explanatory note.
|
|
135
|
+
status = 'OK';
|
|
136
|
+
notes.push(reviewAckedMsg(deps.reviewedThrough ?? ''));
|
|
122
137
|
} else if (specUpdated && touchedPaths.length === 0) {
|
|
123
138
|
status = 'INFO';
|
|
124
139
|
notes.push(SPEC_UPDATED_MSG);
|
|
@@ -147,6 +162,35 @@ const STALE_MSG =
|
|
|
147
162
|
"Note: Code in this spec's scope changed on this branch but the spec was not updated; re-review the spec.";
|
|
148
163
|
const SPEC_UPDATED_MSG = 'Note: Spec updated on this branch.';
|
|
149
164
|
|
|
165
|
+
const reviewAckedMsg = (id: string): string =>
|
|
166
|
+
`Note: Scope changed on this branch; covered by the recorded review (reviewed-through: ${id}).`;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Re-review ack check: every scope-touching commit message on
|
|
170
|
+
* `baseRef..HEAD` references the reviewed-through change id. Empty id or git
|
|
171
|
+
* failure → not covered (falls back to the plain STALE verdict). A commit
|
|
172
|
+
* referencing several changes satisfies any of them (`c2858`-style tokens).
|
|
173
|
+
*/
|
|
174
|
+
function reviewCoversBranch(
|
|
175
|
+
reviewedThrough: string | null,
|
|
176
|
+
git: GitLike,
|
|
177
|
+
baseRef: string,
|
|
178
|
+
): boolean {
|
|
179
|
+
if (reviewedThrough === null || reviewedThrough.trim() === '') return false;
|
|
180
|
+
const id = reviewedThrough.trim();
|
|
181
|
+
const log = git.runOpt(['log', '--format=%s', `${baseRef}..HEAD`]);
|
|
182
|
+
if (log === null || log === '') return false;
|
|
183
|
+
return log
|
|
184
|
+
.split('\n')
|
|
185
|
+
.filter((l) => scopeLineRelevant(l))
|
|
186
|
+
.every((l) => l.includes(id));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Lines without any `c<num>` token carry no change attribution — skip them. */
|
|
190
|
+
function scopeLineRelevant(line: string): boolean {
|
|
191
|
+
return /c\d+/u.test(line) || line.trim() === '';
|
|
192
|
+
}
|
|
193
|
+
|
|
150
194
|
function revParse(git: GitLike, ref: string): string | null {
|
|
151
195
|
return git.runOpt(['rev-parse', '--verify', '--quiet', ref]) ?? null;
|
|
152
196
|
}
|
|
@@ -110,6 +110,10 @@ After all tasks complete + all gates green, output a structured report (see Outp
|
|
|
110
110
|
|
|
111
111
|
{{ unit("skills/cli-footer") }}
|
|
112
112
|
|
|
113
|
+
{{ unit("skills/version-drift") }}
|
|
114
|
+
|
|
115
|
+
{{ unit("skills/review-stamp") }}
|
|
116
|
+
|
|
113
117
|
{{ unit("skills/validation-hints") }}
|
|
114
118
|
|
|
115
119
|
{{ unit("skills/structured-protocol") }}
|
|
@@ -70,6 +70,10 @@ flowchart LR
|
|
|
70
70
|
{{ unit("skills/human-readable-summary") }}
|
|
71
71
|
{{ unit("skills/cli-footer") }}
|
|
72
72
|
|
|
73
|
+
{{ unit("skills/version-drift") }}
|
|
74
|
+
|
|
75
|
+
{{ unit("skills/review-stamp") }}
|
|
76
|
+
|
|
73
77
|
{{ unit("skills/validation-hints") }}
|
|
74
78
|
|
|
75
79
|
{{ unit("skills/structured-protocol") }}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
## Re-review stamp discipline (`# reviewed-through:` header)
|
|
2
|
+
|
|
3
|
+
When a review concludes "no governed behaviour change", **update** the spec header line `# reviewed-through: <change-id>` to this change — **never** append free-form `# re-review(...)` comments between rules (historical narrative belongs to `changes/archive/<id>/`; the spec keeps only the machine-readable pointer). Staleness consumes it to clear the STALE signal; legacy free-form comments are dropped mechanically on touch, not migrated.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
## Version-drift notice (`[NOTE] ... scaffolded with llman-sdd X; installed CLI is Y`)
|
|
2
|
+
|
|
3
|
+
When you see this stderr line: **relay** it to the user and suggest `llman-sdd init --update` (refreshes managed blocks and skills to the installed CLI). Until updated, **keep following the current skill** — the notice is informational, never a stop condition. At most once per process.
|
|
@@ -70,6 +70,10 @@ flowchart LR
|
|
|
70
70
|
{{ unit("skills/human-readable-summary") }}
|
|
71
71
|
{{ unit("skills/cli-footer") }}
|
|
72
72
|
|
|
73
|
+
{{ unit("skills/version-drift") }}
|
|
74
|
+
|
|
75
|
+
{{ unit("skills/review-stamp") }}
|
|
76
|
+
|
|
73
77
|
{{ unit("skills/validation-hints") }}
|
|
74
78
|
|
|
75
79
|
{{ unit("skills/structured-protocol") }}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
## 复核戳纪律(re-review stamp → `# reviewed-through:` 头)
|
|
2
|
+
|
|
3
|
+
复核确认「本 capability 管辖行为不变」时,**只更新** spec 头部的 `# reviewed-through: <change-id>` 一行(改为本次 change id),**禁止**在 rule 块间追加自由 `# re-review(...)` 注释——历史叙事归 `changes/archive/<id>/`,spec 只留机读指针。staleness 据此消警;旧版自由注释随触碰一并机械清理(删除、不搬运)。
|