@llman-sdd/core 0.11.0 → 0.12.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 +6 -3
- package/src/archive/freeze.ts +0 -13
- package/src/archive/frozenCard.ts +1 -10
- package/src/archive/ignoreChain.ts +2 -6
- package/src/archive/sevenzip.ts +0 -1
- package/src/change/closeOutHarness.ts +17 -0
- package/src/change/collect.ts +0 -5
- package/src/change/frontmatter.ts +15 -7
- package/src/change/id.ts +0 -2
- package/src/change/lifecycle.ts +1 -38
- package/src/config/changeId.ts +0 -2
- package/src/config/load.ts +0 -4
- package/src/config/schema.ts +24 -0
- package/src/git/spawnGit.ts +0 -3
- package/src/hints/jitHints.ts +82 -0
- package/src/index.ts +455 -3
- package/src/init/defaultConfig.ts +2 -0
- package/src/init/init.ts +61 -20
- package/src/init/uncommentConfig.ts +909 -0
- package/src/locale.ts +0 -2
- package/src/project/migrateNotes.ts +0 -9
- package/src/project/migrations.ts +70 -0
- package/src/report/graph/analysis.ts +0 -4
- package/src/report/graph/nodes.ts +0 -6
- package/src/report/show.ts +7 -23
- package/src/report/specHelpers.ts +10 -14
- package/src/review/review.ts +0 -12
- package/src/spec/assignSpecIds.ts +0 -3
- package/src/spec/authoring.ts +14 -26
- package/src/spec/ir.ts +14 -5
- package/src/spec/keywords.ts +0 -2
- package/src/spec/machineKey.ts +49 -0
- package/src/spec/migrateNative.ts +4 -18
- package/src/spec/parser.ts +10 -19
- package/src/spec/reqRef.ts +135 -0
- package/src/studio/changeScope.ts +50 -0
- package/src/studio/changeScopeDiff.ts +195 -0
- package/src/studio/contracts.ts +493 -0
- package/src/studio/decisionTree.ts +206 -0
- package/src/studio/deeplink.ts +116 -0
- package/src/studio/demos.ts +167 -0
- package/src/studio/diff.ts +494 -0
- package/src/studio/drift.ts +738 -0
- package/src/studio/extract.ts +360 -0
- package/src/studio/featureSync.ts +592 -0
- package/src/studio/forest.ts +570 -0
- package/src/studio/index.ts +32 -0
- package/src/studio/model.ts +254 -0
- package/src/studio/revisions.ts +476 -0
- package/src/studio/search.ts +337 -0
- package/src/studio/store.ts +811 -0
- package/src/studio/sync.ts +912 -0
- package/src/studio/textfold.ts +72 -0
- package/src/studio/time.ts +107 -0
- package/src/studio/validate.ts +363 -0
- package/src/templates/embedded.ts +4 -6
- package/src/templates/engine.ts +1 -1
- package/src/templates/skills.ts +71 -49
- package/src/theorems/guard.ts +52 -0
- package/src/theorems/index.ts +56 -0
- package/src/theorems/migrate.ts +133 -0
- package/src/theorems/schema.ts +67 -0
- package/src/theorems/scope.ts +68 -0
- package/src/theorems/serialize.ts +60 -0
- package/src/theorems/transactionMachine.ts +247 -0
- package/src/theorems/validate.ts +141 -0
- package/src/util/nextNumber.ts +0 -2
- package/src/validation/changeCheck.ts +0 -24
- package/src/validation/flowAndNesting.ts +434 -0
- package/src/validation/harness.ts +108 -65
- package/src/validation/validate.ts +26 -12
- package/src/validation/xstateTransitions.ts +483 -184
- package/templates/zh-Hans/llmanspec-agents-stub.md +17 -2
- package/templates/zh-Hans/skills/llman-sdd-autopilot/SKILL.md +34 -0
- package/templates/zh-Hans/skills/llman-sdd-change/SKILL.md +44 -0
- package/templates/zh-Hans/skills/llman-sdd-change/playbooks/archive.md +15 -0
- package/templates/zh-Hans/skills/llman-sdd-change/playbooks/draft.md +9 -0
- package/templates/zh-Hans/skills/llman-sdd-review/SKILL.md +71 -0
- package/templates/zh-Hans/skills/llman-sdd-specs/SKILL.md +70 -0
- package/templates/zh-Hans/skills/llman-sdd-specs/playbooks/compact.md +12 -0
- package/templates/zh-Hans/skills/llman-sdd-specs/playbooks/doctor.md +26 -0
- package/templates/zh-Hans/skills/llman-sdd-specs/references/graph-dsl.md +33 -0
- package/templates/zh-Hans/skills/llman-sdd-studio/SKILL.md +33 -0
- package/templates/zh-Hans/skills/llman-sdd-studio/playbooks/collab.md +20 -0
- package/templates/zh-Hans/skills/llman-sdd-studio/playbooks/drift.md +52 -0
- package/templates/zh-Hans/skills/llman-sdd-studio/playbooks/onboard.md +33 -0
- package/templates/zh-Hans/units/skills/cli-footer.md +2 -2
- package/templates/zh-Hans/agents-root-stub.md +0 -9
- package/templates/zh-Hans/skills/llman-sdd-apply-cycle.md +0 -69
- package/templates/zh-Hans/skills/llman-sdd-apply.md +0 -116
- package/templates/zh-Hans/skills/llman-sdd-arch-review.md +0 -58
- package/templates/zh-Hans/skills/llman-sdd-archive.md +0 -78
- package/templates/zh-Hans/skills/llman-sdd-continue.md +0 -34
- package/templates/zh-Hans/skills/llman-sdd-draft.md +0 -53
- package/templates/zh-Hans/skills/llman-sdd-explore.md +0 -63
- package/templates/zh-Hans/skills/llman-sdd-ff.md +0 -34
- package/templates/zh-Hans/skills/llman-sdd-graph.md +0 -56
- package/templates/zh-Hans/skills/llman-sdd-propose.md +0 -106
- package/templates/zh-Hans/skills/llman-sdd-quick.md +0 -40
- package/templates/zh-Hans/skills/llman-sdd-research.md +0 -35
- package/templates/zh-Hans/skills/llman-sdd-specs-compact.md +0 -42
- package/templates/zh-Hans/skills/llman-sdd-validate.md +0 -28
- package/templates/zh-Hans/skills/llman-sdd-verify.md +0 -77
- package/templates/zh-Hans/skills/llman-sdd-wayfinder.md +0 -83
- package/templates/zh-Hans/units/skills/ethics-governance.md +0 -6
- package/templates/zh-Hans/units/skills/git-native-flow.md +0 -56
- package/templates/zh-Hans/units/skills/human-readable-summary.md +0 -9
- package/templates/zh-Hans/units/skills/stage-guard.md +0 -17
- package/templates/zh-Hans/units/skills/structured-protocol.md +0 -19
- package/templates/zh-Hans/units/skills/validation-hints.md +0 -20
- package/templates/zh-Hans/units/skills/version-drift.md +0 -3
- package/templates/zh-Hans/units/spec/feature-contract.md +0 -8
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { createAsyncLogic, setup, types } from 'xstate';
|
|
2
|
+
|
|
3
|
+
export const THEOREM_TRANSACTION_SPEC_STATES = [
|
|
4
|
+
'TTY交互门禁检查',
|
|
5
|
+
'拒绝并输出升级提示',
|
|
6
|
+
'环境探针与预演',
|
|
7
|
+
'报告S8并打印原生建议',
|
|
8
|
+
'副本编辑与向导录入',
|
|
9
|
+
'纯域YAML与ID校验',
|
|
10
|
+
'放弃草稿原锁未动',
|
|
11
|
+
'Diff与免责声明确认',
|
|
12
|
+
'提权解锁并原子覆写',
|
|
13
|
+
'回滚自动重锁原文件',
|
|
14
|
+
'立即重锁并复核锁态',
|
|
15
|
+
'高危告警并打印原生锁命令',
|
|
16
|
+
'[结束:已安全重锁]',
|
|
17
|
+
'[结束:取消或待人工恢复]',
|
|
18
|
+
] as const;
|
|
19
|
+
|
|
20
|
+
export type TheoremTransactionSpecState = (typeof THEOREM_TRANSACTION_SPEC_STATES)[number];
|
|
21
|
+
|
|
22
|
+
export const THEOREM_TRANSACTION_FINAL_STATES = [
|
|
23
|
+
'[结束:已安全重锁]',
|
|
24
|
+
'[结束:取消或待人工恢复]',
|
|
25
|
+
] as const;
|
|
26
|
+
|
|
27
|
+
export const THEOREM_CONFIRM_STATE = 'Diff与免责声明确认';
|
|
28
|
+
|
|
29
|
+
export const MAX_EDIT_ROUNDS = 5;
|
|
30
|
+
|
|
31
|
+
export interface TheoremTransactionContext {
|
|
32
|
+
reason: string;
|
|
33
|
+
validationIssues: string[];
|
|
34
|
+
editRounds: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface TheoremTransactionEventMap {
|
|
38
|
+
START: {};
|
|
39
|
+
TTY_OK: {};
|
|
40
|
+
TTY_DENIED: {};
|
|
41
|
+
PROBE_OK: {};
|
|
42
|
+
PROBE_S8: {};
|
|
43
|
+
DRAFT_READY: {};
|
|
44
|
+
VALIDATION_FAILED: { issues: string[] };
|
|
45
|
+
VERIFY_FAILED: { issues: string[] };
|
|
46
|
+
CONFIRM: {};
|
|
47
|
+
CANCEL: {};
|
|
48
|
+
ABANDON: {};
|
|
49
|
+
PRIVILEGE_CANCELLED: {};
|
|
50
|
+
WRITE_FAILED: { reason: string };
|
|
51
|
+
WRITE_OK: {};
|
|
52
|
+
RELOCK_OK: {};
|
|
53
|
+
RELOCK_FAILED: {};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type TheoremTransactionEvent = {
|
|
57
|
+
[K in keyof TheoremTransactionEventMap]: { type: K } & TheoremTransactionEventMap[K];
|
|
58
|
+
}[keyof TheoremTransactionEventMap];
|
|
59
|
+
|
|
60
|
+
export interface TheoremTransactionActors {
|
|
61
|
+
checkTty: () => Promise<boolean>;
|
|
62
|
+
probeLockCapability: () => Promise<boolean>;
|
|
63
|
+
collectDraft: () => Promise<string[]>;
|
|
64
|
+
confirmDiff: () => Promise<boolean>;
|
|
65
|
+
unlockAndWrite: () => Promise<boolean>;
|
|
66
|
+
rollbackAndRelock: () => Promise<boolean>;
|
|
67
|
+
relockAndInspect: () => Promise<boolean>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function doneOutput(event: unknown): unknown {
|
|
71
|
+
if (typeof event !== 'object' || event === null) return undefined;
|
|
72
|
+
return 'output' in event ? (event as { output: unknown }).output : undefined;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function issuesFrom(event: unknown): string[] {
|
|
76
|
+
const output = doneOutput(event);
|
|
77
|
+
return Array.isArray(output) ? (output as string[]) : [];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const theoremTransactionMachine = setup({
|
|
81
|
+
schemas: {
|
|
82
|
+
context: types<TheoremTransactionContext>(),
|
|
83
|
+
events: {
|
|
84
|
+
START: types<{}>(),
|
|
85
|
+
TTY_OK: types<{}>(),
|
|
86
|
+
TTY_DENIED: types<{}>(),
|
|
87
|
+
PROBE_OK: types<{}>(),
|
|
88
|
+
PROBE_S8: types<{}>(),
|
|
89
|
+
DRAFT_READY: types<{}>(),
|
|
90
|
+
VALIDATION_FAILED: types<{ issues: string[] }>(),
|
|
91
|
+
VERIFY_FAILED: types<{ issues: string[] }>(),
|
|
92
|
+
CONFIRM: types<{}>(),
|
|
93
|
+
CANCEL: types<{}>(),
|
|
94
|
+
ABANDON: types<{}>(),
|
|
95
|
+
PRIVILEGE_CANCELLED: types<{}>(),
|
|
96
|
+
WRITE_FAILED: types<{ reason: string }>(),
|
|
97
|
+
WRITE_OK: types<{}>(),
|
|
98
|
+
RELOCK_OK: types<{}>(),
|
|
99
|
+
RELOCK_FAILED: types<{}>(),
|
|
100
|
+
},
|
|
101
|
+
meta: types<{ specState: string }>(),
|
|
102
|
+
},
|
|
103
|
+
actors: {
|
|
104
|
+
checkTty: createAsyncLogic({ schemas: { output: types<boolean>() }, run: async () => true }),
|
|
105
|
+
probeLockCapability: createAsyncLogic({
|
|
106
|
+
schemas: { output: types<boolean>() },
|
|
107
|
+
run: async () => true,
|
|
108
|
+
}),
|
|
109
|
+
collectDraft: createAsyncLogic({
|
|
110
|
+
schemas: { output: types<string[]>() },
|
|
111
|
+
run: async () => [],
|
|
112
|
+
}),
|
|
113
|
+
confirmDiff: createAsyncLogic({
|
|
114
|
+
schemas: { output: types<boolean>() },
|
|
115
|
+
run: async () => false,
|
|
116
|
+
}),
|
|
117
|
+
unlockAndWrite: createAsyncLogic({
|
|
118
|
+
schemas: { output: types<boolean>() },
|
|
119
|
+
run: async () => false,
|
|
120
|
+
}),
|
|
121
|
+
rollbackAndRelock: createAsyncLogic({
|
|
122
|
+
schemas: { output: types<boolean>() },
|
|
123
|
+
run: async () => true,
|
|
124
|
+
}),
|
|
125
|
+
relockAndInspect: createAsyncLogic({
|
|
126
|
+
schemas: { output: types<boolean>() },
|
|
127
|
+
run: async () => true,
|
|
128
|
+
}),
|
|
129
|
+
},
|
|
130
|
+
}).createMachine({
|
|
131
|
+
id: 'theoremTransaction',
|
|
132
|
+
initial: 'TTY交互门禁检查',
|
|
133
|
+
context: { reason: '', validationIssues: [], editRounds: 0 },
|
|
134
|
+
states: {
|
|
135
|
+
TTY交互门禁检查: {
|
|
136
|
+
meta: { specState: 'TTY交互门禁检查' },
|
|
137
|
+
invoke: {
|
|
138
|
+
src: 'checkTty',
|
|
139
|
+
onDone: ({ event }) =>
|
|
140
|
+
doneOutput(event) === true
|
|
141
|
+
? { target: '环境探针与预演' }
|
|
142
|
+
: { target: '拒绝并输出升级提示' },
|
|
143
|
+
onError: { target: '拒绝并输出升级提示' },
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
拒绝并输出升级提示: {
|
|
147
|
+
meta: { specState: '拒绝并输出升级提示' },
|
|
148
|
+
always: { target: '[结束:取消或待人工恢复]' },
|
|
149
|
+
},
|
|
150
|
+
环境探针与预演: {
|
|
151
|
+
meta: { specState: '环境探针与预演' },
|
|
152
|
+
invoke: {
|
|
153
|
+
src: 'probeLockCapability',
|
|
154
|
+
onDone: ({ event }) =>
|
|
155
|
+
doneOutput(event) === true
|
|
156
|
+
? { target: '副本编辑与向导录入' }
|
|
157
|
+
: { target: '报告S8并打印原生建议' },
|
|
158
|
+
onError: { target: '报告S8并打印原生建议' },
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
报告S8并打印原生建议: {
|
|
162
|
+
meta: { specState: '报告S8并打印原生建议' },
|
|
163
|
+
always: { target: '[结束:取消或待人工恢复]' },
|
|
164
|
+
},
|
|
165
|
+
副本编辑与向导录入: {
|
|
166
|
+
meta: { specState: '副本编辑与向导录入' },
|
|
167
|
+
invoke: {
|
|
168
|
+
src: 'collectDraft',
|
|
169
|
+
onDone: ({ event, context }) => ({
|
|
170
|
+
target: '纯域YAML与ID校验',
|
|
171
|
+
context: { validationIssues: issuesFrom(event), editRounds: context.editRounds + 1 },
|
|
172
|
+
}),
|
|
173
|
+
onError: { target: '放弃草稿原锁未动' },
|
|
174
|
+
},
|
|
175
|
+
on: { ABANDON: { target: '放弃草稿原锁未动' } },
|
|
176
|
+
},
|
|
177
|
+
纯域YAML与ID校验: {
|
|
178
|
+
meta: { specState: '纯域YAML与ID校验' },
|
|
179
|
+
type: 'choice',
|
|
180
|
+
choice: ({ context }) => {
|
|
181
|
+
if (context.validationIssues.length === 0) return { target: 'Diff与免责声明确认' };
|
|
182
|
+
if (context.editRounds >= MAX_EDIT_ROUNDS) return { target: '放弃草稿原锁未动' };
|
|
183
|
+
return { target: '副本编辑与向导录入' };
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
放弃草稿原锁未动: {
|
|
187
|
+
meta: { specState: '放弃草稿原锁未动' },
|
|
188
|
+
always: { target: '[结束:取消或待人工恢复]' },
|
|
189
|
+
},
|
|
190
|
+
Diff与免责声明确认: {
|
|
191
|
+
meta: { specState: 'Diff与免责声明确认' },
|
|
192
|
+
entry: () => ({ context: { validationIssues: [] } }),
|
|
193
|
+
invoke: {
|
|
194
|
+
src: 'confirmDiff',
|
|
195
|
+
onDone: ({ event }) =>
|
|
196
|
+
doneOutput(event) === true
|
|
197
|
+
? { target: '提权解锁并原子覆写' }
|
|
198
|
+
: { target: '放弃草稿原锁未动' },
|
|
199
|
+
onError: { target: '放弃草稿原锁未动' },
|
|
200
|
+
},
|
|
201
|
+
on: { CANCEL: { target: '放弃草稿原锁未动' } },
|
|
202
|
+
},
|
|
203
|
+
提权解锁并原子覆写: {
|
|
204
|
+
meta: { specState: '提权解锁并原子覆写' },
|
|
205
|
+
invoke: {
|
|
206
|
+
src: 'unlockAndWrite',
|
|
207
|
+
onDone: ({ event }) =>
|
|
208
|
+
doneOutput(event) === true
|
|
209
|
+
? { target: '立即重锁并复核锁态' }
|
|
210
|
+
: { target: '放弃草稿原锁未动' },
|
|
211
|
+
onError: { target: '回滚自动重锁原文件' },
|
|
212
|
+
},
|
|
213
|
+
on: { PRIVILEGE_CANCELLED: { target: '放弃草稿原锁未动' } },
|
|
214
|
+
},
|
|
215
|
+
回滚自动重锁原文件: {
|
|
216
|
+
meta: { specState: '回滚自动重锁原文件' },
|
|
217
|
+
invoke: {
|
|
218
|
+
src: 'rollbackAndRelock',
|
|
219
|
+
onDone: { target: '[结束:取消或待人工恢复]' },
|
|
220
|
+
onError: { target: '[结束:取消或待人工恢复]' },
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
立即重锁并复核锁态: {
|
|
224
|
+
meta: { specState: '立即重锁并复核锁态' },
|
|
225
|
+
invoke: {
|
|
226
|
+
src: 'relockAndInspect',
|
|
227
|
+
onDone: ({ event }) =>
|
|
228
|
+
doneOutput(event) === true
|
|
229
|
+
? { target: '[结束:已安全重锁]' }
|
|
230
|
+
: { target: '高危告警并打印原生锁命令' },
|
|
231
|
+
onError: { target: '高危告警并打印原生锁命令' },
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
高危告警并打印原生锁命令: {
|
|
235
|
+
meta: { specState: '高危告警并打印原生锁命令' },
|
|
236
|
+
always: { target: '[结束:取消或待人工恢复]' },
|
|
237
|
+
},
|
|
238
|
+
'[结束:已安全重锁]': {
|
|
239
|
+
type: 'final',
|
|
240
|
+
meta: { specState: '[结束:已安全重锁]' },
|
|
241
|
+
},
|
|
242
|
+
'[结束:取消或待人工恢复]': {
|
|
243
|
+
type: 'final',
|
|
244
|
+
meta: { specState: '[结束:取消或待人工恢复]' },
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
});
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { parse as parseYaml } from 'yaml';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
THEOREM_LEGACY_LOCK_FILE,
|
|
5
|
+
TheoremDocumentSchema,
|
|
6
|
+
type TheoremEntry,
|
|
7
|
+
type TheoremIssue,
|
|
8
|
+
type TheoremSourceFile,
|
|
9
|
+
type TheoremValidationResult,
|
|
10
|
+
} from './schema.ts';
|
|
11
|
+
|
|
12
|
+
export interface TheoremDiscoverIo {
|
|
13
|
+
exists(path: string): boolean;
|
|
14
|
+
isDirectory(path: string): boolean;
|
|
15
|
+
listDir(path: string): string[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const THEOREM_EXTENSIONS = ['.yaml', '.yml'] as const;
|
|
19
|
+
|
|
20
|
+
function isTheoremFile(name: string): boolean {
|
|
21
|
+
return THEOREM_EXTENSIONS.some((ext) => name.endsWith(ext));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function baseNameWithoutExt(name: string): string {
|
|
25
|
+
const dot = name.lastIndexOf('.');
|
|
26
|
+
return dot <= 0 ? name : name.slice(0, dot);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Recursive depth-first discovery of theorem YAML files under `theoremsDir`.
|
|
31
|
+
* Hidden directories (leading dot) are skipped; every other subdirectory is
|
|
32
|
+
* scanned so natural grouping (`architecture/`, `data/`, ...) works. Sorted for
|
|
33
|
+
* deterministic output regardless of filesystem order.
|
|
34
|
+
*/
|
|
35
|
+
export function discoverTheoremFiles(theoremsDir: string, io: TheoremDiscoverIo): string[] {
|
|
36
|
+
const normDir = theoremsDir.replace(/\\/gu, '/').replace(/\/+$/u, '');
|
|
37
|
+
const walk = (dir: string): string[] => {
|
|
38
|
+
if (!io.exists(dir) || !io.isDirectory(dir)) return [];
|
|
39
|
+
const out: string[] = [];
|
|
40
|
+
for (const name of io.listDir(dir).toSorted()) {
|
|
41
|
+
if (name.startsWith('.')) continue;
|
|
42
|
+
const full = `${dir}/${name}`;
|
|
43
|
+
if (io.isDirectory(full)) out.push(...walk(full));
|
|
44
|
+
else if (isTheoremFile(name)) out.push(full);
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
};
|
|
48
|
+
return walk(normDir);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Legacy leftovers under the theorems directory: old `*.md` entries and any
|
|
53
|
+
* `.theorems.lock.json` manifest. Their presence is `S7_LEGACY_CONFLICT`.
|
|
54
|
+
*/
|
|
55
|
+
export function findLegacyTheoremFiles(theoremsDir: string, io: TheoremDiscoverIo): string[] {
|
|
56
|
+
const normDir = theoremsDir.replace(/\\/gu, '/').replace(/\/+$/u, '');
|
|
57
|
+
const walk = (dir: string): string[] => {
|
|
58
|
+
if (!io.exists(dir) || !io.isDirectory(dir)) return [];
|
|
59
|
+
const out: string[] = [];
|
|
60
|
+
for (const name of io.listDir(dir).toSorted()) {
|
|
61
|
+
const full = `${dir}/${name}`;
|
|
62
|
+
if (io.isDirectory(full)) {
|
|
63
|
+
if (!name.startsWith('.')) out.push(...walk(full));
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (name.endsWith('.md') || name === THEOREM_LEGACY_LOCK_FILE) out.push(full);
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
};
|
|
70
|
+
return walk(normDir);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Validate a set of theorem source files: YAML syntax, Zod contract, filename vs
|
|
75
|
+
* `id` agreement, and global id uniqueness. Pure — no filesystem access.
|
|
76
|
+
*/
|
|
77
|
+
export function validateTheoremSet(files: readonly TheoremSourceFile[]): TheoremValidationResult {
|
|
78
|
+
const theorems: TheoremEntry[] = [];
|
|
79
|
+
const issues: TheoremIssue[] = [];
|
|
80
|
+
const seen = new Map<string, string>();
|
|
81
|
+
|
|
82
|
+
for (const file of files) {
|
|
83
|
+
let raw: unknown;
|
|
84
|
+
try {
|
|
85
|
+
raw = parseYaml(file.content);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
issues.push({
|
|
88
|
+
code: 'yaml-parse',
|
|
89
|
+
filePath: file.filePath,
|
|
90
|
+
message: `YAML parse error: ${error instanceof Error ? error.message : String(error)}`,
|
|
91
|
+
});
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const parsed = TheoremDocumentSchema.safeParse(raw);
|
|
96
|
+
if (!parsed.success) {
|
|
97
|
+
const detail = parsed.error.issues
|
|
98
|
+
.map((issue) => `${issue.path.join('.') || '<root>'}: ${issue.message}`)
|
|
99
|
+
.join('; ');
|
|
100
|
+
issues.push({ code: 'schema', filePath: file.filePath, message: detail });
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const doc = parsed.data;
|
|
105
|
+
const base = baseNameWithoutExt(file.filePath.split('/').pop() ?? file.filePath);
|
|
106
|
+
if (base !== doc.id) {
|
|
107
|
+
issues.push({
|
|
108
|
+
code: 'id-mismatch',
|
|
109
|
+
filePath: file.filePath,
|
|
110
|
+
message: `file base name \`${base}\` must equal id \`${doc.id}\``,
|
|
111
|
+
});
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const previous = seen.get(doc.id);
|
|
116
|
+
if (previous !== undefined) {
|
|
117
|
+
issues.push({
|
|
118
|
+
code: 'duplicate-id',
|
|
119
|
+
filePath: file.filePath,
|
|
120
|
+
message: `duplicate theorem id \`${doc.id}\` (already defined in ${previous})`,
|
|
121
|
+
});
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
seen.set(doc.id, file.filePath);
|
|
125
|
+
|
|
126
|
+
theorems.push({
|
|
127
|
+
id: doc.id,
|
|
128
|
+
title: doc.title,
|
|
129
|
+
statement: doc.statement,
|
|
130
|
+
rationale: doc.rationale,
|
|
131
|
+
severity: doc.severity,
|
|
132
|
+
status: doc.status,
|
|
133
|
+
...(doc.scope !== undefined ? { scope: doc.scope } : {}),
|
|
134
|
+
tags: doc.tags ?? [],
|
|
135
|
+
...(doc.verify !== undefined ? { verify: doc.verify } : {}),
|
|
136
|
+
filePath: file.filePath,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return { ok: issues.length === 0, theorems, issues, legacyFiles: [] };
|
|
141
|
+
}
|
package/src/util/nextNumber.ts
CHANGED
|
@@ -22,8 +22,6 @@ export function nextNumber(used: Iterable<number>): number {
|
|
|
22
22
|
export function maxUsedNumber(used: Iterable<number>): number | null {
|
|
23
23
|
let max: number | null = null;
|
|
24
24
|
for (const n of used) {
|
|
25
|
-
// Non-finite noise (NaN/±Infinity) never wins the fold; an empty (or
|
|
26
|
-
// fully non-numeric) set has no maximum.
|
|
27
25
|
if (Number.isFinite(n) && (max === null || n > max)) max = n;
|
|
28
26
|
}
|
|
29
27
|
return max;
|
|
@@ -26,12 +26,8 @@ import { datedCardIdOf, datedIdOf } from '../util/datedId.ts';
|
|
|
26
26
|
* `.yaml` stripping in three places).
|
|
27
27
|
*/
|
|
28
28
|
function archivedEntryId(name: string): string | null {
|
|
29
|
-
// Card form first: `2026-02-02-card.yaml` must yield `card`, not `card.yaml`.
|
|
30
29
|
const card = datedCardIdOf(name, '.yaml');
|
|
31
30
|
if (card !== null) return card;
|
|
32
|
-
// Then the directory grammar on the card suffix stripped, so a card name
|
|
33
|
-
// without an id (`2026-02-02-.yaml`) stays unparsed instead of yielding
|
|
34
|
-
// `.yaml` (the predecessor form produced '' there and skipped it).
|
|
35
31
|
return datedIdOf(name.endsWith('.yaml') ? name.slice(0, -'.yaml'.length) : name);
|
|
36
32
|
}
|
|
37
33
|
|
|
@@ -116,7 +112,6 @@ function resolveChangeRef(
|
|
|
116
112
|
if (active) return 'active';
|
|
117
113
|
const archive = `${changesRoot}/archive`;
|
|
118
114
|
const entries = io.exists(archive) && io.isDirectory(archive) ? io.listDir(archive) : [];
|
|
119
|
-
// `YYYY-MM-DD-` is 11 chars; the remainder must equal the id exactly.
|
|
120
115
|
const archived = entries.some((name) => archivedEntryId(name) === id);
|
|
121
116
|
return archived ? 'archived' : 'unknown';
|
|
122
117
|
}
|
|
@@ -240,8 +235,6 @@ export function validateChange(
|
|
|
240
235
|
const dir = `${root}/${CHANGES_DIR}/${id}/`;
|
|
241
236
|
const baseDir = `${root}/${CHANGES_DIR}`;
|
|
242
237
|
const proposal = `${dir}proposal.md`;
|
|
243
|
-
// Probed once here: shared by the stage inference below and the --stage
|
|
244
|
-
// artifact gate at the end (predecessor issue order preserved).
|
|
245
238
|
const hasDesign = io.exists(`${dir}design.md`);
|
|
246
239
|
const hasTasks = io.exists(`${dir}tasks.md`);
|
|
247
240
|
if (!io.exists(proposal)) {
|
|
@@ -251,9 +244,6 @@ export function validateChange(
|
|
|
251
244
|
const fm = extractFrontmatter(text) ?? '';
|
|
252
245
|
const fmLines = fm.split('\n').map((l) => l.trim());
|
|
253
246
|
|
|
254
|
-
// T22: depends_on rides the single reader (strict policy) — quoting, block
|
|
255
|
-
// /flow styles and numeric entries collapse into one parse. `blocks` keeps
|
|
256
|
-
// the structural line scan (no shared reader; list-of-strings only).
|
|
257
247
|
const deps = readDepsStrict(text);
|
|
258
248
|
if (deps.kind === 'malformed') {
|
|
259
249
|
push(
|
|
@@ -325,7 +315,6 @@ export function validateChange(
|
|
|
325
315
|
}
|
|
326
316
|
}
|
|
327
317
|
|
|
328
|
-
// Unknown frontmatter field gate (predecessor).
|
|
329
318
|
for (const l of fmLines) {
|
|
330
319
|
if (l === '' || l.startsWith('-') || l.startsWith('#')) continue;
|
|
331
320
|
const m = l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\s*:/u);
|
|
@@ -338,8 +327,6 @@ export function validateChange(
|
|
|
338
327
|
}
|
|
339
328
|
}
|
|
340
329
|
|
|
341
|
-
// r99 title gate: active changes require a non-empty frontmatter title
|
|
342
|
-
// (archived proposals never reach validateChange — archive is exempt).
|
|
343
330
|
if (readFrontmatterTitle(fm) === '') {
|
|
344
331
|
push(
|
|
345
332
|
'ERROR',
|
|
@@ -349,7 +336,6 @@ export function validateChange(
|
|
|
349
336
|
}
|
|
350
337
|
|
|
351
338
|
const binding = readBinding(text);
|
|
352
|
-
// stageFor (change/collect) is the monotonic stage SSOT (r34).
|
|
353
339
|
const stage = stageFor(hasDesign, hasTasks, binding !== null);
|
|
354
340
|
|
|
355
341
|
if (hasTasks && !hasDesign) {
|
|
@@ -370,11 +356,6 @@ export function validateChange(
|
|
|
370
356
|
`${n} unchecked task(s) in tasks.md`,
|
|
371
357
|
);
|
|
372
358
|
}
|
|
373
|
-
// D9/B23 (active changes only — validate domain): an unchecked task whose
|
|
374
|
-
// title starts with a close-out verb is a pipeline-step pseudo-task; the
|
|
375
|
-
// task gate requires every task checked, so it can never legitimately
|
|
376
|
-
// stay as a task. Match on the leading verb only, so "fix finalize task
|
|
377
|
-
// gate" (a task ABOUT close-out) is not flagged.
|
|
378
359
|
for (const line of closeOutTaskLines(pendingLines)) {
|
|
379
360
|
const title = line.replace(/^-\s+\[ \]\s*/u, '').trim();
|
|
380
361
|
push(
|
|
@@ -385,13 +366,11 @@ export function validateChange(
|
|
|
385
366
|
}
|
|
386
367
|
}
|
|
387
368
|
|
|
388
|
-
// completeness INFO (predecessor surface).
|
|
389
369
|
push('INFO', 'completeness', COMPLETENESS[stage] ?? '');
|
|
390
370
|
|
|
391
371
|
// r63: Full-but-not-ready WARNING with skill guidance (predecessor r1 surface).
|
|
392
372
|
if (opts.git !== undefined && binding !== null && stage === 'full') {
|
|
393
373
|
const needs = readNeedsSpecsChange(fm);
|
|
394
|
-
// r119: judged under the change's own instance prefix.
|
|
395
374
|
const specsPrefix = opts.specsPrefix ?? DEFAULT_SPECS_PREFIX;
|
|
396
375
|
const landed = specsLanded(opts.git, binding, specsPrefix);
|
|
397
376
|
if (!landed && needs) {
|
|
@@ -404,12 +383,9 @@ export function validateChange(
|
|
|
404
383
|
}
|
|
405
384
|
}
|
|
406
385
|
|
|
407
|
-
// pattern gate (predecessor change-id path). loadConfig compiles the pattern
|
|
408
|
-
// first on the CLI path; this defends direct core callers that bypass it.
|
|
409
386
|
for (const issue of patternGate(id, config.change_id_pattern))
|
|
410
387
|
push(issue.level, issue.path, issue.message);
|
|
411
388
|
|
|
412
|
-
// stage gate (predecessor --stage: artifact presence per gate).
|
|
413
389
|
if (opts.stage !== undefined) {
|
|
414
390
|
if (opts.stage === 'designed' && !hasDesign) {
|
|
415
391
|
push('ERROR', 'design.md', `Stage forced to 'designed' but design.md is missing`);
|