@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.
Files changed (112) hide show
  1. package/package.json +6 -3
  2. package/src/archive/freeze.ts +0 -13
  3. package/src/archive/frozenCard.ts +1 -10
  4. package/src/archive/ignoreChain.ts +2 -6
  5. package/src/archive/sevenzip.ts +0 -1
  6. package/src/change/closeOutHarness.ts +17 -0
  7. package/src/change/collect.ts +0 -5
  8. package/src/change/frontmatter.ts +15 -7
  9. package/src/change/id.ts +0 -2
  10. package/src/change/lifecycle.ts +1 -38
  11. package/src/config/changeId.ts +0 -2
  12. package/src/config/load.ts +0 -4
  13. package/src/config/schema.ts +24 -0
  14. package/src/git/spawnGit.ts +0 -3
  15. package/src/hints/jitHints.ts +82 -0
  16. package/src/index.ts +455 -3
  17. package/src/init/defaultConfig.ts +2 -0
  18. package/src/init/init.ts +61 -20
  19. package/src/init/uncommentConfig.ts +909 -0
  20. package/src/locale.ts +0 -2
  21. package/src/project/migrateNotes.ts +0 -9
  22. package/src/project/migrations.ts +70 -0
  23. package/src/report/graph/analysis.ts +0 -4
  24. package/src/report/graph/nodes.ts +0 -6
  25. package/src/report/show.ts +7 -23
  26. package/src/report/specHelpers.ts +10 -14
  27. package/src/review/review.ts +0 -12
  28. package/src/spec/assignSpecIds.ts +0 -3
  29. package/src/spec/authoring.ts +14 -26
  30. package/src/spec/ir.ts +14 -5
  31. package/src/spec/keywords.ts +0 -2
  32. package/src/spec/machineKey.ts +49 -0
  33. package/src/spec/migrateNative.ts +4 -18
  34. package/src/spec/parser.ts +10 -19
  35. package/src/spec/reqRef.ts +135 -0
  36. package/src/studio/changeScope.ts +50 -0
  37. package/src/studio/changeScopeDiff.ts +195 -0
  38. package/src/studio/contracts.ts +493 -0
  39. package/src/studio/decisionTree.ts +206 -0
  40. package/src/studio/deeplink.ts +116 -0
  41. package/src/studio/demos.ts +167 -0
  42. package/src/studio/diff.ts +494 -0
  43. package/src/studio/drift.ts +738 -0
  44. package/src/studio/extract.ts +360 -0
  45. package/src/studio/featureSync.ts +592 -0
  46. package/src/studio/forest.ts +570 -0
  47. package/src/studio/index.ts +32 -0
  48. package/src/studio/model.ts +254 -0
  49. package/src/studio/revisions.ts +476 -0
  50. package/src/studio/search.ts +337 -0
  51. package/src/studio/store.ts +811 -0
  52. package/src/studio/sync.ts +912 -0
  53. package/src/studio/textfold.ts +72 -0
  54. package/src/studio/time.ts +107 -0
  55. package/src/studio/validate.ts +363 -0
  56. package/src/templates/embedded.ts +4 -6
  57. package/src/templates/engine.ts +1 -1
  58. package/src/templates/skills.ts +71 -49
  59. package/src/theorems/guard.ts +52 -0
  60. package/src/theorems/index.ts +56 -0
  61. package/src/theorems/migrate.ts +133 -0
  62. package/src/theorems/schema.ts +67 -0
  63. package/src/theorems/scope.ts +68 -0
  64. package/src/theorems/serialize.ts +60 -0
  65. package/src/theorems/transactionMachine.ts +247 -0
  66. package/src/theorems/validate.ts +141 -0
  67. package/src/util/nextNumber.ts +0 -2
  68. package/src/validation/changeCheck.ts +0 -24
  69. package/src/validation/flowAndNesting.ts +434 -0
  70. package/src/validation/harness.ts +108 -65
  71. package/src/validation/validate.ts +26 -12
  72. package/src/validation/xstateTransitions.ts +483 -184
  73. package/templates/zh-Hans/llmanspec-agents-stub.md +17 -2
  74. package/templates/zh-Hans/skills/llman-sdd-autopilot/SKILL.md +34 -0
  75. package/templates/zh-Hans/skills/llman-sdd-change/SKILL.md +44 -0
  76. package/templates/zh-Hans/skills/llman-sdd-change/playbooks/archive.md +15 -0
  77. package/templates/zh-Hans/skills/llman-sdd-change/playbooks/draft.md +9 -0
  78. package/templates/zh-Hans/skills/llman-sdd-review/SKILL.md +71 -0
  79. package/templates/zh-Hans/skills/llman-sdd-specs/SKILL.md +70 -0
  80. package/templates/zh-Hans/skills/llman-sdd-specs/playbooks/compact.md +12 -0
  81. package/templates/zh-Hans/skills/llman-sdd-specs/playbooks/doctor.md +26 -0
  82. package/templates/zh-Hans/skills/llman-sdd-specs/references/graph-dsl.md +33 -0
  83. package/templates/zh-Hans/skills/llman-sdd-studio/SKILL.md +33 -0
  84. package/templates/zh-Hans/skills/llman-sdd-studio/playbooks/collab.md +20 -0
  85. package/templates/zh-Hans/skills/llman-sdd-studio/playbooks/drift.md +52 -0
  86. package/templates/zh-Hans/skills/llman-sdd-studio/playbooks/onboard.md +33 -0
  87. package/templates/zh-Hans/units/skills/cli-footer.md +2 -2
  88. package/templates/zh-Hans/agents-root-stub.md +0 -9
  89. package/templates/zh-Hans/skills/llman-sdd-apply-cycle.md +0 -69
  90. package/templates/zh-Hans/skills/llman-sdd-apply.md +0 -116
  91. package/templates/zh-Hans/skills/llman-sdd-arch-review.md +0 -58
  92. package/templates/zh-Hans/skills/llman-sdd-archive.md +0 -78
  93. package/templates/zh-Hans/skills/llman-sdd-continue.md +0 -34
  94. package/templates/zh-Hans/skills/llman-sdd-draft.md +0 -53
  95. package/templates/zh-Hans/skills/llman-sdd-explore.md +0 -63
  96. package/templates/zh-Hans/skills/llman-sdd-ff.md +0 -34
  97. package/templates/zh-Hans/skills/llman-sdd-graph.md +0 -56
  98. package/templates/zh-Hans/skills/llman-sdd-propose.md +0 -106
  99. package/templates/zh-Hans/skills/llman-sdd-quick.md +0 -40
  100. package/templates/zh-Hans/skills/llman-sdd-research.md +0 -35
  101. package/templates/zh-Hans/skills/llman-sdd-specs-compact.md +0 -42
  102. package/templates/zh-Hans/skills/llman-sdd-validate.md +0 -28
  103. package/templates/zh-Hans/skills/llman-sdd-verify.md +0 -77
  104. package/templates/zh-Hans/skills/llman-sdd-wayfinder.md +0 -83
  105. package/templates/zh-Hans/units/skills/ethics-governance.md +0 -6
  106. package/templates/zh-Hans/units/skills/git-native-flow.md +0 -56
  107. package/templates/zh-Hans/units/skills/human-readable-summary.md +0 -9
  108. package/templates/zh-Hans/units/skills/stage-guard.md +0 -17
  109. package/templates/zh-Hans/units/skills/structured-protocol.md +0 -19
  110. package/templates/zh-Hans/units/skills/validation-hints.md +0 -20
  111. package/templates/zh-Hans/units/skills/version-drift.md +0 -3
  112. package/templates/zh-Hans/units/spec/feature-contract.md +0 -8
@@ -0,0 +1,254 @@
1
+ /**
2
+ * Studio pure domain IR and state document models (studio-core r128, r131, r132).
3
+ * Pure types and deterministic helpers — zero filesystem I/O, zero wall-clock calls.
4
+ */
5
+ /**
6
+ * Machine-key authority lives in `spec/machineKey.ts` so `validation/` can reuse it
7
+ * without importing `studio/` (r72). Re-exported here as the Studio-facing surface.
8
+ */
9
+ export { makeMachineKey, splitMachineKey, type ParsedMachineKey } from '../spec/machineKey.ts';
10
+
11
+ export type StudioGraphKind = 'machine' | 'flow';
12
+
13
+ export interface StudioStateNode {
14
+ /** Stable draft-scoped identifier used for rename tracking and edge binding. */
15
+ uid: string;
16
+ /** Business state or flowchart step name written to .feature Examples tables. */
17
+ name: string;
18
+ /** Node kind: 常规|判断|并行|汇聚|终态|异常终态 */
19
+ nodeKind?: string;
20
+ /** Nested sub-machine/sub-flow key for drilldown. */
21
+ nestKey?: string;
22
+ summary?: string;
23
+ done?: string;
24
+ actor?: string;
25
+ }
26
+
27
+ export interface StudioTransitionEdge {
28
+ uid: string;
29
+ fromUid: string;
30
+ event: string;
31
+ condition?: string;
32
+ action?: string;
33
+ actor?: string;
34
+ edgeKind?: string;
35
+ meta?: string;
36
+ verify?: string;
37
+ toUid: string;
38
+ }
39
+
40
+ export interface StudioMachineColumns {
41
+ source: string;
42
+ label: string;
43
+ target: string;
44
+ condition?: string;
45
+ action?: string;
46
+ actor?: string;
47
+ edgeKind?: string;
48
+ meta?: string;
49
+ verify?: string;
50
+ }
51
+
52
+ export interface StudioMachineIR {
53
+ machineKey: string;
54
+ capability: string;
55
+ reqId: string | null;
56
+ ruleTitle: string;
57
+ scenarioName: string;
58
+ /** Optional graph dialect ('machine' default, or 'flow' for flowchart). */
59
+ graphKind?: StudioGraphKind;
60
+ /** Initial state uid (corresponds to first Examples row's source). */
61
+ initialStateUid: string | null;
62
+ /** Preserved zh-Hans column header family. */
63
+ columns: StudioMachineColumns;
64
+ states: StudioStateNode[];
65
+ transitions: StudioTransitionEdge[];
66
+ }
67
+
68
+ export type MachineDraftMode = 'modify' | 'create' | 'remove';
69
+
70
+ export interface MachineDraft {
71
+ mode: MachineDraftMode;
72
+ baseline: StudioMachineIR | null;
73
+ current: StudioMachineIR | null;
74
+ /** Instance-relative .feature path (e.g. `llmanspec/specs/order.feature`). */
75
+ sourceFile: string;
76
+ }
77
+
78
+ export type SemanticAnchor =
79
+ | { kind: 'machine'; machineKey: string }
80
+ | { kind: 'state'; machineKey: string; stateUid: string }
81
+ | { kind: 'edge'; machineKey: string; edgeUid: string }
82
+ | { kind: 'forest'; capability: string }
83
+ | { kind: 'macro-edge'; edgeId: string }
84
+ | { kind: 'doc'; capability: string; reqId?: string };
85
+
86
+ export interface StudioComment {
87
+ id: string;
88
+ anchor: SemanticAnchor;
89
+ author: 'human' | 'agent';
90
+ body: string;
91
+ createdAt: string;
92
+ status: 'open' | 'resolved';
93
+ replyTo?: string;
94
+ /** Optional "请谁看" tag; defaults to `author` when omitted. */
95
+ watchTag?: string;
96
+ }
97
+
98
+ export type RevisionOp =
99
+ | { op: 'add_state'; name: string }
100
+ | { op: 'remove_state'; stateName: string }
101
+ | { op: 'rename_state'; from: string; to: string }
102
+ | { op: 'add_transition'; from: string; event: string; condition?: string; to: string }
103
+ | { op: 'remove_transition'; from: string; event: string; condition?: string; to: string }
104
+ | {
105
+ op: 'update_transition';
106
+ match: { from: string; event: string; condition?: string; to: string };
107
+ next: { from?: string; event?: string; condition?: string; to?: string };
108
+ };
109
+
110
+ export interface StudioRevisionProposal {
111
+ id: string;
112
+ machineKey: string;
113
+ author: 'agent';
114
+ source?: 'agent' | 'drift-trace';
115
+ rationale: string;
116
+ ops: RevisionOp[];
117
+ createdAt: string;
118
+ status: 'pending' | 'accepted' | 'rejected';
119
+ }
120
+
121
+ export type TimelineActor = 'human' | 'agent';
122
+
123
+ export interface TimelineEntry {
124
+ seq: number;
125
+ id: string;
126
+ label: string;
127
+ createdAt: string;
128
+ isBase: boolean;
129
+ mode: MachineDraftMode;
130
+ snapshot: StudioMachineIR | null;
131
+ /** Parent entry id for non-destructive multi-branch Worldline trees (null for BASE). */
132
+ parentId?: string | null;
133
+ /** Who created this snapshot node ('human' or 'agent'). */
134
+ actor?: TimelineActor;
135
+ /** Optional Git branch/worktree label associated with this snapshot. */
136
+ branchRef?: string;
137
+ /** True when this commit only touched human annotation fields (summary/done/actor/action/meta). */
138
+ annotation?: boolean;
139
+ }
140
+
141
+ export interface MachineTimeline {
142
+ entries: TimelineEntry[];
143
+ headIdx: number;
144
+ }
145
+
146
+ export interface NodePosition {
147
+ x: number;
148
+ y: number;
149
+ }
150
+
151
+ export interface EdgeBendOffset {
152
+ dx: number;
153
+ dy: number;
154
+ }
155
+
156
+ export type DocDraftChangeKind = 'wording' | 'semantic';
157
+
158
+ export interface StudioDocDraft {
159
+ sourceFile: string;
160
+ baseHash: string;
161
+ currentText: string;
162
+ changeKind: DocDraftChangeKind;
163
+ }
164
+
165
+ export interface StudioStateDoc {
166
+ version: 1;
167
+ id: string;
168
+ title: string;
169
+ createdAt: string;
170
+ updatedAt: string;
171
+ /** Monotonic optimistic-lock revision number for concurrent multi-tab & Agent writes. */
172
+ revision?: number;
173
+ /** Source file SHA-256 baseline hashes for stale-baseline detection. */
174
+ baseHashes?: Record<string, string>;
175
+ machines: Record<string, MachineDraft>;
176
+ /** Non-state-machine spec drafts (rules / decision tables) for unified Scheme C drafting. */
177
+ docDrafts?: Record<string, StudioDocDraft>;
178
+ timelines: Record<string, MachineTimeline>;
179
+ /** Cold layout coordinates decoupled from semantic MachineDraft (zero diff noise). */
180
+ layouts: Record<string, Record<string, NodePosition>>;
181
+ /** Cold manual edge bend offsets per machine/scope (zero diff noise). */
182
+ edgeBends?: Record<string, Record<string, EdgeBendOffset>>;
183
+ comments: StudioComment[];
184
+ revisions: StudioRevisionProposal[];
185
+ /** Open file-sync sessions: machineKey → worldline snapshot entry id. */
186
+ syncOpen?: Record<string, string>;
187
+ }
188
+
189
+ export function cloneMachineIR(machine: StudioMachineIR): StudioMachineIR {
190
+ return {
191
+ machineKey: machine.machineKey,
192
+ capability: machine.capability,
193
+ reqId: machine.reqId,
194
+ ruleTitle: machine.ruleTitle,
195
+ scenarioName: machine.scenarioName,
196
+ ...(machine.graphKind !== undefined ? { graphKind: machine.graphKind } : {}),
197
+ initialStateUid: machine.initialStateUid,
198
+ columns: {
199
+ source: machine.columns.source,
200
+ label: machine.columns.label,
201
+ target: machine.columns.target,
202
+ ...(machine.columns.condition !== undefined ? { condition: machine.columns.condition } : {}),
203
+ ...(machine.columns.action !== undefined ? { action: machine.columns.action } : {}),
204
+ ...(machine.columns.actor !== undefined ? { actor: machine.columns.actor } : {}),
205
+ ...(machine.columns.edgeKind !== undefined ? { edgeKind: machine.columns.edgeKind } : {}),
206
+ ...(machine.columns.meta !== undefined ? { meta: machine.columns.meta } : {}),
207
+ ...(machine.columns.verify !== undefined ? { verify: machine.columns.verify } : {}),
208
+ },
209
+ states: machine.states.map((s) => ({
210
+ uid: s.uid,
211
+ name: s.name,
212
+ ...(s.nodeKind !== undefined ? { nodeKind: s.nodeKind } : {}),
213
+ ...(s.nestKey !== undefined ? { nestKey: s.nestKey } : {}),
214
+ ...(s.summary !== undefined ? { summary: s.summary } : {}),
215
+ ...(s.done !== undefined ? { done: s.done } : {}),
216
+ ...(s.actor !== undefined ? { actor: s.actor } : {}),
217
+ })),
218
+ transitions: machine.transitions.map((t) => ({
219
+ uid: t.uid,
220
+ fromUid: t.fromUid,
221
+ event: t.event,
222
+ ...(t.condition !== undefined ? { condition: t.condition } : {}),
223
+ ...(t.action !== undefined ? { action: t.action } : {}),
224
+ ...(t.actor !== undefined ? { actor: t.actor } : {}),
225
+ ...(t.edgeKind !== undefined ? { edgeKind: t.edgeKind } : {}),
226
+ ...(t.meta !== undefined ? { meta: t.meta } : {}),
227
+ ...(t.verify !== undefined ? { verify: t.verify } : {}),
228
+ toUid: t.toUid,
229
+ })),
230
+ };
231
+ }
232
+
233
+ export function cloneMachineDraft(draft: MachineDraft): MachineDraft {
234
+ return {
235
+ mode: draft.mode,
236
+ baseline: draft.baseline ? cloneMachineIR(draft.baseline) : null,
237
+ current: draft.current ? cloneMachineIR(draft.current) : null,
238
+ sourceFile: draft.sourceFile,
239
+ };
240
+ }
241
+
242
+ export function nextPrefixedUid(prefix: string, existingUids: Iterable<string>): string {
243
+ let maxNum = 0;
244
+ for (const uid of existingUids) {
245
+ if (uid.startsWith(prefix)) {
246
+ const rest = uid.slice(prefix.length);
247
+ if (/^\d+$/u.test(rest)) {
248
+ const n = Math.trunc(Number(rest));
249
+ if (n > maxNum) maxNum = n;
250
+ }
251
+ }
252
+ }
253
+ return `${prefix}${String(maxNum + 1)}`;
254
+ }