@llman-sdd/core 0.10.1 → 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 (119) hide show
  1. package/package.json +11 -8
  2. package/src/archive/freeze.ts +41 -15
  3. package/src/archive/frozenCard.ts +57 -9
  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 +53 -94
  11. package/src/config/changeId.ts +0 -2
  12. package/src/config/load.ts +0 -4
  13. package/src/config/schema.ts +24 -13
  14. package/src/config/surface.ts +2 -12
  15. package/src/context/sddState.ts +23 -18
  16. package/src/git/spawnGit.ts +0 -3
  17. package/src/hints/jitHints.ts +82 -0
  18. package/src/index.ts +462 -39
  19. package/src/init/defaultConfig.ts +4 -13
  20. package/src/init/init.ts +108 -36
  21. package/src/init/skillCheck.ts +60 -0
  22. package/src/init/uncommentConfig.ts +909 -0
  23. package/src/locale.ts +0 -2
  24. package/src/project/migrateNotes.ts +0 -9
  25. package/src/project/migrations.ts +151 -9
  26. package/src/report/graph/analysis.ts +0 -4
  27. package/src/report/graph/nodes.ts +0 -6
  28. package/src/report/show.ts +7 -23
  29. package/src/report/specHelpers.ts +10 -14
  30. package/src/review/review.ts +0 -12
  31. package/src/spec/assignSpecIds.ts +0 -3
  32. package/src/spec/authoring.ts +16 -24
  33. package/src/spec/ir.ts +14 -5
  34. package/src/spec/keywords.ts +0 -2
  35. package/src/spec/machineKey.ts +49 -0
  36. package/src/spec/migrateNative.ts +4 -18
  37. package/src/spec/parser.ts +10 -19
  38. package/src/spec/reqRef.ts +135 -0
  39. package/src/studio/changeScope.ts +50 -0
  40. package/src/studio/changeScopeDiff.ts +195 -0
  41. package/src/studio/contracts.ts +493 -0
  42. package/src/studio/decisionTree.ts +206 -0
  43. package/src/studio/deeplink.ts +116 -0
  44. package/src/studio/demos.ts +167 -0
  45. package/src/studio/diff.ts +494 -0
  46. package/src/studio/drift.ts +738 -0
  47. package/src/studio/extract.ts +360 -0
  48. package/src/studio/featureSync.ts +592 -0
  49. package/src/studio/forest.ts +570 -0
  50. package/src/studio/index.ts +32 -0
  51. package/src/studio/model.ts +254 -0
  52. package/src/studio/revisions.ts +476 -0
  53. package/src/studio/search.ts +337 -0
  54. package/src/studio/store.ts +811 -0
  55. package/src/studio/sync.ts +912 -0
  56. package/src/studio/textfold.ts +72 -0
  57. package/src/studio/time.ts +107 -0
  58. package/src/studio/validate.ts +363 -0
  59. package/src/templates/embedded.ts +4 -6
  60. package/src/templates/engine.ts +1 -1
  61. package/src/templates/skills.ts +76 -51
  62. package/src/theorems/guard.ts +52 -0
  63. package/src/theorems/index.ts +56 -0
  64. package/src/theorems/migrate.ts +133 -0
  65. package/src/theorems/schema.ts +67 -0
  66. package/src/theorems/scope.ts +68 -0
  67. package/src/theorems/serialize.ts +60 -0
  68. package/src/theorems/transactionMachine.ts +247 -0
  69. package/src/theorems/validate.ts +141 -0
  70. package/src/util/nextNumber.ts +0 -2
  71. package/src/validation/changeCheck.ts +0 -24
  72. package/src/validation/flowAndNesting.ts +434 -0
  73. package/src/validation/harness.ts +108 -65
  74. package/src/validation/validate.ts +26 -12
  75. package/src/validation/xstateTransitions.ts +483 -184
  76. package/templates/zh-Hans/llmanspec-agents-stub.md +17 -2
  77. package/templates/zh-Hans/skills/llman-sdd-autopilot/SKILL.md +34 -0
  78. package/templates/zh-Hans/skills/llman-sdd-change/SKILL.md +44 -0
  79. package/templates/zh-Hans/skills/llman-sdd-change/playbooks/archive.md +15 -0
  80. package/templates/zh-Hans/skills/llman-sdd-change/playbooks/draft.md +9 -0
  81. package/templates/zh-Hans/skills/llman-sdd-review/SKILL.md +71 -0
  82. package/templates/zh-Hans/skills/llman-sdd-specs/SKILL.md +70 -0
  83. package/templates/zh-Hans/skills/llman-sdd-specs/playbooks/compact.md +12 -0
  84. package/templates/zh-Hans/skills/llman-sdd-specs/playbooks/doctor.md +26 -0
  85. package/templates/zh-Hans/skills/llman-sdd-specs/references/graph-dsl.md +33 -0
  86. package/templates/zh-Hans/skills/llman-sdd-studio/SKILL.md +33 -0
  87. package/templates/zh-Hans/skills/llman-sdd-studio/playbooks/collab.md +20 -0
  88. package/templates/zh-Hans/skills/llman-sdd-studio/playbooks/drift.md +52 -0
  89. package/templates/zh-Hans/skills/llman-sdd-studio/playbooks/onboard.md +33 -0
  90. package/templates/zh-Hans/units/skills/cli-footer.md +2 -2
  91. package/src/context/indexStore.ts +0 -171
  92. package/src/context/retrieve.ts +0 -332
  93. package/src/context/tree.ts +0 -112
  94. package/templates/zh-Hans/agents-root-stub.md +0 -9
  95. package/templates/zh-Hans/skills/llman-sdd-apply-cycle.md +0 -69
  96. package/templates/zh-Hans/skills/llman-sdd-apply.md +0 -117
  97. package/templates/zh-Hans/skills/llman-sdd-arch-review.md +0 -58
  98. package/templates/zh-Hans/skills/llman-sdd-archive.md +0 -79
  99. package/templates/zh-Hans/skills/llman-sdd-continue.md +0 -34
  100. package/templates/zh-Hans/skills/llman-sdd-draft.md +0 -53
  101. package/templates/zh-Hans/skills/llman-sdd-explore.md +0 -64
  102. package/templates/zh-Hans/skills/llman-sdd-ff.md +0 -33
  103. package/templates/zh-Hans/skills/llman-sdd-graph.md +0 -56
  104. package/templates/zh-Hans/skills/llman-sdd-propose.md +0 -107
  105. package/templates/zh-Hans/skills/llman-sdd-quick.md +0 -41
  106. package/templates/zh-Hans/skills/llman-sdd-research.md +0 -35
  107. package/templates/zh-Hans/skills/llman-sdd-specs-compact.md +0 -41
  108. package/templates/zh-Hans/skills/llman-sdd-validate.md +0 -28
  109. package/templates/zh-Hans/skills/llman-sdd-verify.md +0 -77
  110. package/templates/zh-Hans/skills/llman-sdd-wayfinder.md +0 -83
  111. package/templates/zh-Hans/units/skills/ethics-governance.md +0 -6
  112. package/templates/zh-Hans/units/skills/git-native-flow.md +0 -56
  113. package/templates/zh-Hans/units/skills/human-readable-summary.md +0 -9
  114. package/templates/zh-Hans/units/skills/index-fallback.md +0 -1
  115. package/templates/zh-Hans/units/skills/stage-guard.md +0 -17
  116. package/templates/zh-Hans/units/skills/structured-protocol.md +0 -19
  117. package/templates/zh-Hans/units/skills/validation-hints.md +0 -20
  118. package/templates/zh-Hans/units/skills/version-drift.md +0 -3
  119. package/templates/zh-Hans/units/spec/feature-contract.md +0 -8
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Canonical Studio deep-link parse/format (studio-web nest path + focus).
3
+ * Pure: no I/O, no wall clock. Query `kind`/`target` stay backward compatible.
4
+ */
5
+
6
+ export const STUDIO_FOCUS_KINDS = ['forest', 'macro-edge', 'state', 'edge'] as const;
7
+ export type StudioFocusKind = (typeof STUDIO_FOCUS_KINDS)[number];
8
+
9
+ export interface StudioDeepLinkFocus {
10
+ kind: StudioFocusKind;
11
+ id: string;
12
+ }
13
+
14
+ export interface StudioDeepLink {
15
+ kind: string;
16
+ target: string;
17
+ nest: string[];
18
+ focus: StudioDeepLinkFocus | null;
19
+ }
20
+
21
+ const FOCUS_KIND_SET = new Set<string>(STUDIO_FOCUS_KINDS);
22
+
23
+ export function parseStudioFocusToken(raw: string | null | undefined): StudioDeepLinkFocus | null {
24
+ const text = (raw ?? '').trim();
25
+ if (text === '') return null;
26
+ const colon = text.indexOf(':');
27
+ if (colon <= 0) return null;
28
+ const kind = text.slice(0, colon);
29
+ const id = text.slice(colon + 1);
30
+ if (!FOCUS_KIND_SET.has(kind) || id === '') return null;
31
+ return { kind: kind as StudioFocusKind, id };
32
+ }
33
+
34
+ export function formatStudioFocusToken(focus: StudioDeepLinkFocus): string {
35
+ return `${focus.kind}:${focus.id}`;
36
+ }
37
+
38
+ export function parseStudioNestToken(raw: string | null | undefined): string[] {
39
+ if (raw === null || raw === undefined || raw.trim() === '') return [];
40
+ return raw
41
+ .split(',')
42
+ .map((p) => p.trim())
43
+ .filter((p) => p !== '');
44
+ }
45
+
46
+ export function formatStudioNestToken(nest: readonly string[]): string {
47
+ return nest.filter((k) => k !== '').join(',');
48
+ }
49
+
50
+ function readParam(
51
+ search: URLSearchParams,
52
+ hashParams: URLSearchParams,
53
+ key: string,
54
+ ): string | null {
55
+ const fromHash = hashParams.get(key);
56
+ if (fromHash !== null && fromHash !== '') return fromHash;
57
+ const fromQuery = search.get(key);
58
+ return fromQuery !== null && fromQuery !== '' ? fromQuery : null;
59
+ }
60
+
61
+ /** Parse query + optional `#hash` (hash wins for nest/focus/kind/target). */
62
+ export function parseStudioDeepLink(
63
+ search: string | URLSearchParams,
64
+ hash?: string,
65
+ ): StudioDeepLink {
66
+ const query =
67
+ typeof search === 'string'
68
+ ? new URLSearchParams(search.startsWith('?') ? search.slice(1) : search)
69
+ : search;
70
+ const hashText = (hash ?? '').replace(/^#/u, '');
71
+ const hashParams = new URLSearchParams(hashText.includes('=') ? hashText : '');
72
+ const kind = readParam(query, hashParams, 'kind') ?? 'macro';
73
+ const target = readParam(query, hashParams, 'target') ?? 'default';
74
+ const tab = readParam(query, hashParams, 'tab');
75
+ let resolvedKind = kind;
76
+ let resolvedTarget = target;
77
+ if (tab !== null && tab.startsWith('m:')) {
78
+ resolvedKind = 'machine';
79
+ resolvedTarget = tab.slice(2);
80
+ } else if (tab !== null && tab.startsWith('doc:')) {
81
+ resolvedKind = 'doc';
82
+ resolvedTarget = tab.slice(4);
83
+ } else if (tab === 'default') {
84
+ resolvedKind = 'macro';
85
+ resolvedTarget = 'default';
86
+ }
87
+ const nest = parseStudioNestToken(readParam(query, hashParams, 'nest'));
88
+ const focus = parseStudioFocusToken(readParam(query, hashParams, 'focus'));
89
+ return { kind: resolvedKind, target: resolvedTarget, nest, focus };
90
+ }
91
+
92
+ export function formatStudioDeepLinkQuery(link: StudioDeepLink): string {
93
+ const params = new URLSearchParams();
94
+ const nest = formatStudioNestToken(link.nest);
95
+ const isDefaultMacro = link.kind === 'macro' && (link.target === 'default' || link.target === '');
96
+ if (!isDefaultMacro || nest !== '' || link.focus !== null) {
97
+ if (link.kind !== '') params.set('kind', link.kind);
98
+ if (link.target !== '') params.set('target', link.target);
99
+ }
100
+ if (nest !== '') params.set('nest', nest);
101
+ if (link.focus) params.set('focus', formatStudioFocusToken(link.focus));
102
+ return params.toString();
103
+ }
104
+
105
+ export function nestStackFromPath(nest: readonly string[]): string[] {
106
+ return nest.length <= 1 ? [] : nest.slice(1);
107
+ }
108
+
109
+ export function nestPathFromStack(tabRootKey: string, nestedKeys: readonly string[]): string[] {
110
+ if (tabRootKey === '') return [...nestedKeys];
111
+ return [tabRootKey, ...nestedKeys.filter((k) => k !== '')];
112
+ }
113
+
114
+ export function nestLevelLabel(nestStackLength: number): string {
115
+ return `L${String(nestStackLength + 1)}`;
116
+ }
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Built-in demo state machines for zero-table repos (`--demo`) and unit tests (studio-core r132).
3
+ * Both demos are guaranteed to pass validateMachineGraph with zero blocking errors.
4
+ */
5
+ import { createMachineDraft } from './extract.ts';
6
+ import type { MachineDraft } from './model.ts';
7
+
8
+ export function buildDemoReimbursementDraft(): MachineDraft {
9
+ return createMachineDraft({
10
+ capability: 'demo-reimbursement',
11
+ reqId: 'r1',
12
+ ruleTitle: '报销审批状态流转',
13
+ scenarioName: '报销审批主流程',
14
+ sourceFile: 'llmanspec/specs/demo-reimbursement.feature',
15
+ columns: { source: '当前', label: '触发', target: '目标', condition: '条件' },
16
+ states: [
17
+ { name: '草稿', initial: true },
18
+ { name: '待审批' },
19
+ { name: '已通过' },
20
+ { name: '已驳回' },
21
+ ],
22
+ transitions: [
23
+ { from: '草稿', event: '提交', to: '待审批' },
24
+ { from: '待审批', event: '批准', condition: '金额<=5000', to: '已通过' },
25
+ { from: '待审批', event: '批准', condition: '老板审批', to: '已通过' },
26
+ { from: '待审批', event: '驳回', to: '已驳回' },
27
+ { from: '已驳回', event: '修改重提', to: '待审批' },
28
+ ],
29
+ });
30
+ }
31
+
32
+ export function buildDemoJobRunnerDraft(): MachineDraft {
33
+ return createMachineDraft({
34
+ capability: 'demo-job-runner',
35
+ reqId: 'r2',
36
+ ruleTitle: '任务执行与重试状态流转',
37
+ scenarioName: '任务生命周期',
38
+ sourceFile: 'llmanspec/specs/demo-job-runner.feature',
39
+ columns: { source: '当前', label: '触发', target: '目标', condition: '条件' },
40
+ states: [
41
+ { name: 'queued', initial: true },
42
+ { name: 'running' },
43
+ { name: 'succeeded' },
44
+ { name: 'failed' },
45
+ { name: 'cancelled' },
46
+ ],
47
+ transitions: [
48
+ { from: 'queued', event: 'start', to: 'running' },
49
+ { from: 'queued', event: 'cancel', to: 'cancelled' },
50
+ { from: 'running', event: 'succeed', to: 'succeeded' },
51
+ { from: 'running', event: 'retry', condition: 'retry_left>0', to: 'running' },
52
+ { from: 'running', event: 'fail', condition: 'retry_left==0', to: 'failed' },
53
+ { from: 'running', event: 'cancel', to: 'cancelled' },
54
+ ],
55
+ });
56
+ }
57
+
58
+ export function buildDemoStudioWebDrafts(): MachineDraft[] {
59
+ const l1 = createMachineDraft({
60
+ capability: 'studio-web',
61
+ reqId: 'r143',
62
+ ruleTitle: '自举 Studio Web 主状态流转',
63
+ scenarioName: 'Studio Web 主态流转',
64
+ sourceFile: 'llmanspec/specs/studio-web.feature',
65
+ columns: { source: '当前', label: '触发', target: '目标', condition: '条件' },
66
+ states: [
67
+ { name: '启动与工作区就绪', initial: true },
68
+ { name: '主视图与导航态' },
69
+ { name: '画布直编与草稿态' },
70
+ { name: '推演试跑态' },
71
+ { name: '世界线与验收闭环' },
72
+ { name: '写保护与保存变更' },
73
+ ],
74
+ transitions: [
75
+ { from: '启动与工作区就绪', event: '打开主视图或深链', to: '主视图与导航态' },
76
+ { from: '主视图与导航态', event: '切换工作区或标签', to: '启动与工作区就绪' },
77
+ { from: '主视图与导航态', event: '进入规格编辑', to: '画布直编与草稿态' },
78
+ { from: '画布直编与草稿态', event: '启动单步推演', to: '推演试跑态' },
79
+ { from: '推演试跑态', event: '退出推演', to: '画布直编与草稿态' },
80
+ { from: '画布直编与草稿态', event: '打开世界线与对比', to: '世界线与验收闭环' },
81
+ { from: '世界线与验收闭环', event: '回到画布继续微调', to: '画布直编与草稿态' },
82
+ {
83
+ from: '世界线与验收闭环',
84
+ event: '校验通过保存变更',
85
+ condition: '门禁全绿',
86
+ to: '写保护与保存变更',
87
+ },
88
+ { from: '写保护与保存变更', event: '确认生效返回', to: '主视图与导航态' },
89
+ ],
90
+ });
91
+
92
+ const l2Edit = createMachineDraft({
93
+ capability: 'studio-web',
94
+ reqId: 'r144',
95
+ ruleTitle: '画布直编子机',
96
+ scenarioName: '画布直编子流程',
97
+ sourceFile: 'llmanspec/specs/studio-web.feature',
98
+ columns: { source: '当前', label: '触发', target: '目标', condition: '条件' },
99
+ states: [
100
+ { name: '画布空闲', initial: true },
101
+ { name: '选中图元' },
102
+ { name: '就地编辑文字' },
103
+ { name: '端口拖线连接' },
104
+ { name: '统一评论浮窗' },
105
+ ],
106
+ transitions: [
107
+ { from: '画布空闲', event: '单击节点或连线', to: '选中图元' },
108
+ { from: '选中图元', event: '双击或回车', to: '就地编辑文字' },
109
+ { from: '就地编辑文字', event: '提交防抖保存', to: '画布空闲' },
110
+ { from: '选中图元', event: '拖拽端口圆点', to: '端口拖线连接' },
111
+ { from: '端口拖线连接', event: '松手吸附或选建', to: '画布空闲' },
112
+ { from: '选中图元', event: '右键留评论', to: '统一评论浮窗' },
113
+ { from: '统一评论浮窗', event: '关闭浮窗', to: '画布空闲' },
114
+ ],
115
+ });
116
+
117
+ const l3Wire = createMachineDraft({
118
+ capability: 'studio-web',
119
+ reqId: 'r145',
120
+ ruleTitle: '拖线连接与选建子机',
121
+ scenarioName: '端口拖线微循环',
122
+ sourceFile: 'llmanspec/specs/studio-web.feature',
123
+ columns: { source: '当前', label: '触发', target: '目标', condition: '条件' },
124
+ states: [
125
+ { name: '拉出临时虚线', initial: true },
126
+ { name: '吸附目标节点' },
127
+ { name: '拖空选建圆盘' },
128
+ { name: '写入本地草稿' },
129
+ ],
130
+ transitions: [
131
+ { from: '拉出临时虚线', event: '悬停目标节点', to: '吸附目标节点' },
132
+ { from: '吸附目标节点', event: '松手建边', to: '写入本地草稿' },
133
+ { from: '拉出临时虚线', event: '空白处松手', to: '拖空选建圆盘' },
134
+ { from: '拖空选建圆盘', event: '选建新节点并连线', to: '写入本地草稿' },
135
+ { from: '拖空选建圆盘', event: '按 Esc 取消', to: '拉出临时虚线' },
136
+ { from: '写入本地草稿', event: '继续拖线', to: '拉出临时虚线' },
137
+ ],
138
+ });
139
+
140
+ if (l1.current) {
141
+ const editNode = l1.current.states.find((s) => s.name === '画布直编与草稿态');
142
+ if (editNode && l2Edit.current) editNode.nestKey = l2Edit.current.machineKey;
143
+ }
144
+ if (l2Edit.current) {
145
+ const wireNode = l2Edit.current.states.find((s) => s.name === '端口拖线连接');
146
+ if (wireNode && l3Wire.current) wireNode.nestKey = l3Wire.current.machineKey;
147
+ }
148
+
149
+ return [l1, l2Edit, l3Wire];
150
+ }
151
+
152
+ export function buildDemoStudioDrafts(): MachineDraft[] {
153
+ return [buildDemoReimbursementDraft(), buildDemoJobRunnerDraft()];
154
+ }
155
+
156
+ /** Merge built-in nest/demo drafts onto extracted specs. Same machineKey is skipped. */
157
+ export function mergeDemoDraftsWithExtracted(extracted: readonly MachineDraft[]): MachineDraft[] {
158
+ const demos = [...buildDemoStudioWebDrafts(), ...buildDemoStudioDrafts()];
159
+ const taken = new Set(
160
+ extracted.flatMap((d) => (d.current?.machineKey ? [d.current.machineKey] : [])),
161
+ );
162
+ const extra = demos.filter((d) => {
163
+ const key = d.current?.machineKey;
164
+ return key !== undefined && !taken.has(key);
165
+ });
166
+ return [...extracted, ...extra];
167
+ }