@llman-sdd/core 0.11.0 → 0.12.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 +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,493 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Zod v4 API, SSE, Hub, and Deep-Link contracts for Studio Web & CLI Hub (studio-web r144, r145).
|
|
3
|
+
* Single source of truth: both Hono server handlers and Studio frontend client derive TS types via z.infer
|
|
4
|
+
* and validate payloads at runtime to surface contract drift immediately. Pure — zero I/O.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
THEOREM_LOCK_STRENGTHS,
|
|
10
|
+
TheoremSeveritySchema,
|
|
11
|
+
TheoremStatusSchema,
|
|
12
|
+
TheoremVerifySchema,
|
|
13
|
+
} from '../theorems/index.ts';
|
|
14
|
+
import { forestEdgeEvidenceSchema, studioViewsDocSchema } from './forest.ts';
|
|
15
|
+
import { machineIrSchema, studioStateDocSchema } from './store.ts';
|
|
16
|
+
|
|
17
|
+
export const studioGraphKindSchema = z.enum(['machine', 'flow']);
|
|
18
|
+
export const studioGraphItemKindSchema = z.enum(['machine', 'flow', 'decision', 'doc']);
|
|
19
|
+
export const studioSpecKindSchema = z.enum(['machine', 'flow', 'decision', 'doc', 'composite']);
|
|
20
|
+
export const verificationHardnessSchema = z.enum(['doc', 'tested', 'drift-guarded', 'formal']);
|
|
21
|
+
|
|
22
|
+
export const hubInfoSchema = z.object({
|
|
23
|
+
pid: z.number().int().positive(),
|
|
24
|
+
port: z.number().int().min(1).max(65535),
|
|
25
|
+
host: z.string().min(1),
|
|
26
|
+
token: z.string().min(1),
|
|
27
|
+
version: z.string().min(1),
|
|
28
|
+
startedAt: z.string().min(1),
|
|
29
|
+
});
|
|
30
|
+
export type HubInfo = z.infer<typeof hubInfoSchema>;
|
|
31
|
+
|
|
32
|
+
export const healthResponseSchema = z.object({
|
|
33
|
+
ok: z.literal(true),
|
|
34
|
+
service: z.literal('llman-sdd-studio'),
|
|
35
|
+
version: z.string().min(1),
|
|
36
|
+
pid: z.number().int().positive(),
|
|
37
|
+
workspaceCount: z.number().int().nonnegative(),
|
|
38
|
+
});
|
|
39
|
+
export type HealthResponse = z.infer<typeof healthResponseSchema>;
|
|
40
|
+
|
|
41
|
+
export const workspaceItemSchema = z.object({
|
|
42
|
+
wsKey: z.string().min(1),
|
|
43
|
+
repo: z.string().min(1),
|
|
44
|
+
branch: z.string().min(1),
|
|
45
|
+
worktreePath: z.string().min(1),
|
|
46
|
+
instanceRoot: z.string().min(1),
|
|
47
|
+
instanceRel: z.string().min(1),
|
|
48
|
+
protected: z.boolean(),
|
|
49
|
+
specCount: z.number().int().nonnegative(),
|
|
50
|
+
});
|
|
51
|
+
export type WorkspaceItem = z.infer<typeof workspaceItemSchema>;
|
|
52
|
+
|
|
53
|
+
export const workspacesResponseSchema = z.object({
|
|
54
|
+
activeWsKey: z.string().min(1),
|
|
55
|
+
workspaces: z.array(workspaceItemSchema),
|
|
56
|
+
});
|
|
57
|
+
export type WorkspacesResponse = z.infer<typeof workspacesResponseSchema>;
|
|
58
|
+
|
|
59
|
+
export const registerWorkspaceRequestSchema = z.object({
|
|
60
|
+
directory: z.string().min(1),
|
|
61
|
+
});
|
|
62
|
+
export type RegisterWorkspaceRequest = z.infer<typeof registerWorkspaceRequestSchema>;
|
|
63
|
+
|
|
64
|
+
export const specGraphItemSchema = z.object({
|
|
65
|
+
id: z.string().min(1),
|
|
66
|
+
kind: studioGraphItemKindSchema,
|
|
67
|
+
title: z.string().min(1),
|
|
68
|
+
reqId: z.string().nullable(),
|
|
69
|
+
machineKey: z.string().optional(),
|
|
70
|
+
decisionTableId: z.string().optional(),
|
|
71
|
+
ruleCount: z.number().int().nonnegative().optional(),
|
|
72
|
+
stateCount: z.number().int().nonnegative().optional(),
|
|
73
|
+
rowCount: z.number().int().nonnegative().optional(),
|
|
74
|
+
nests: z.array(z.string()).optional(),
|
|
75
|
+
nestedBy: z.array(z.string()).optional(),
|
|
76
|
+
});
|
|
77
|
+
export type SpecGraphItem = z.infer<typeof specGraphItemSchema>;
|
|
78
|
+
|
|
79
|
+
export const specKindCountsSchema = z.object({
|
|
80
|
+
flow: z.number().int().nonnegative(),
|
|
81
|
+
machine: z.number().int().nonnegative(),
|
|
82
|
+
decision: z.number().int().nonnegative(),
|
|
83
|
+
doc: z.number().int().nonnegative(),
|
|
84
|
+
});
|
|
85
|
+
export type SpecKindCounts = z.infer<typeof specKindCountsSchema>;
|
|
86
|
+
|
|
87
|
+
export const specIndexItemSchema = z.object({
|
|
88
|
+
id: z.string().min(1),
|
|
89
|
+
title: z.string().min(1),
|
|
90
|
+
file: z.string().min(1),
|
|
91
|
+
kind: studioSpecKindSchema,
|
|
92
|
+
hardness: verificationHardnessSchema,
|
|
93
|
+
ruleCount: z.number().int().nonnegative(),
|
|
94
|
+
scenarioCount: z.number().int().nonnegative(),
|
|
95
|
+
decisionTableCount: z.number().int().nonnegative(),
|
|
96
|
+
machineKeys: z.array(z.string()),
|
|
97
|
+
graphItems: z.array(specGraphItemSchema).optional(),
|
|
98
|
+
kindCounts: specKindCountsSchema.optional(),
|
|
99
|
+
summary: z.string(),
|
|
100
|
+
reqPreview: z.array(z.string()),
|
|
101
|
+
tags: z.array(z.string()),
|
|
102
|
+
stale: z.boolean(),
|
|
103
|
+
});
|
|
104
|
+
export type SpecIndexItem = z.infer<typeof specIndexItemSchema>;
|
|
105
|
+
|
|
106
|
+
export const specIndexEdgeSchema = z.object({
|
|
107
|
+
id: z.string().min(1),
|
|
108
|
+
from: z.string().min(1),
|
|
109
|
+
to: z.string().min(1),
|
|
110
|
+
label: z.string(),
|
|
111
|
+
kind: z.enum(['spec-ref', 'manual']),
|
|
112
|
+
evidence: z.array(forestEdgeEvidenceSchema).optional(),
|
|
113
|
+
});
|
|
114
|
+
export type SpecIndexEdge = z.infer<typeof specIndexEdgeSchema>;
|
|
115
|
+
|
|
116
|
+
export const putViewsRequestSchema = z.object({
|
|
117
|
+
viewsDoc: studioViewsDocSchema,
|
|
118
|
+
});
|
|
119
|
+
export type PutViewsRequest = z.infer<typeof putViewsRequestSchema>;
|
|
120
|
+
|
|
121
|
+
export const viewsResponseSchema = z.object({
|
|
122
|
+
ok: z.literal(true),
|
|
123
|
+
viewsDoc: studioViewsDocSchema,
|
|
124
|
+
});
|
|
125
|
+
export type ViewsResponse = z.infer<typeof viewsResponseSchema>;
|
|
126
|
+
|
|
127
|
+
export const studioTheoremSchema = z.object({
|
|
128
|
+
id: z.string().min(1),
|
|
129
|
+
title: z.string().min(1),
|
|
130
|
+
statement: z.string().min(1),
|
|
131
|
+
rationale: z.string().min(1),
|
|
132
|
+
severity: TheoremSeveritySchema,
|
|
133
|
+
status: TheoremStatusSchema,
|
|
134
|
+
scope: z.array(z.string()).optional(),
|
|
135
|
+
tags: z.array(z.string()).optional(),
|
|
136
|
+
verify: TheoremVerifySchema.optional(),
|
|
137
|
+
filePath: z.string().min(1),
|
|
138
|
+
lockStrength: z.enum(THEOREM_LOCK_STRENGTHS),
|
|
139
|
+
});
|
|
140
|
+
export type StudioTheoremDto = z.infer<typeof studioTheoremSchema>;
|
|
141
|
+
|
|
142
|
+
export const theoremProtectionSummarySchema = z.object({
|
|
143
|
+
stateCode: z.enum([
|
|
144
|
+
'S0_ABSENT',
|
|
145
|
+
'S1_EMPTY',
|
|
146
|
+
'S2_LOCKED_STRONG',
|
|
147
|
+
'S3_LOCKED_WEAK',
|
|
148
|
+
'S4_UNLOCKED',
|
|
149
|
+
'S5_SPLIT_BRAIN',
|
|
150
|
+
'S6_SCHEMA_INVALID',
|
|
151
|
+
'S7_LEGACY_CONFLICT',
|
|
152
|
+
'S8_UNSUPPORTED_FS',
|
|
153
|
+
]),
|
|
154
|
+
total: z.number().int().nonnegative(),
|
|
155
|
+
strongLocked: z.number().int().nonnegative(),
|
|
156
|
+
weakLocked: z.number().int().nonnegative(),
|
|
157
|
+
unlocked: z.number().int().nonnegative(),
|
|
158
|
+
});
|
|
159
|
+
export type TheoremProtectionSummary = z.infer<typeof theoremProtectionSummarySchema>;
|
|
160
|
+
export const studioChangeItemStatusSchema = z.enum(['added', 'modified', 'deleted']);
|
|
161
|
+
export type StudioChangeItemStatus = z.infer<typeof studioChangeItemStatusSchema>;
|
|
162
|
+
|
|
163
|
+
export const studioTouchedSpecSchema = z.object({
|
|
164
|
+
capId: z.string().min(1),
|
|
165
|
+
status: studioChangeItemStatusSchema,
|
|
166
|
+
hasUncommitted: z.boolean(),
|
|
167
|
+
touchedReqIds: z.array(z.string()),
|
|
168
|
+
reqStatuses: z.record(z.string(), studioChangeItemStatusSchema),
|
|
169
|
+
touchedGraphIds: z.array(z.string()),
|
|
170
|
+
graphStatuses: z.record(z.string(), studioChangeItemStatusSchema),
|
|
171
|
+
});
|
|
172
|
+
export type StudioTouchedSpec = z.infer<typeof studioTouchedSpecSchema>;
|
|
173
|
+
|
|
174
|
+
export const studioChangeScopeSchema = z.object({
|
|
175
|
+
active: z.boolean(),
|
|
176
|
+
branch: z.string().nullable(),
|
|
177
|
+
baseBranch: z.string().nullable(),
|
|
178
|
+
mergeBaseSha: z.string().nullable(),
|
|
179
|
+
boundChangeId: z.string().nullable(),
|
|
180
|
+
boundChangeTitle: z.string().nullable(),
|
|
181
|
+
touchedSpecs: z.array(studioTouchedSpecSchema),
|
|
182
|
+
baseMachines: z.record(z.string(), machineIrSchema).optional(),
|
|
183
|
+
});
|
|
184
|
+
export type StudioChangeScope = z.infer<typeof studioChangeScopeSchema>;
|
|
185
|
+
|
|
186
|
+
export const bootstrapResponseSchema = z.object({
|
|
187
|
+
workspace: workspaceItemSchema,
|
|
188
|
+
demoMode: z.boolean(),
|
|
189
|
+
token: z.string().min(1),
|
|
190
|
+
activeStateId: z.string().min(1),
|
|
191
|
+
stateDoc: studioStateDocSchema,
|
|
192
|
+
specs: z.array(specIndexItemSchema),
|
|
193
|
+
edges: z.array(specIndexEdgeSchema),
|
|
194
|
+
staleFiles: z.array(z.string()),
|
|
195
|
+
peerWorktrees: z.array(workspaceItemSchema),
|
|
196
|
+
graphMermaid: z.string(),
|
|
197
|
+
theorems: z.array(studioTheoremSchema),
|
|
198
|
+
theoremProtectionSummary: theoremProtectionSummarySchema,
|
|
199
|
+
changeScope: studioChangeScopeSchema,
|
|
200
|
+
});
|
|
201
|
+
export type BootstrapResponse = z.infer<typeof bootstrapResponseSchema>;
|
|
202
|
+
|
|
203
|
+
export const decisionTreeNodeSchema = z.object({
|
|
204
|
+
id: z.string().min(1),
|
|
205
|
+
kind: z.enum(['condition', 'outcome']),
|
|
206
|
+
label: z.string(),
|
|
207
|
+
rowIndices: z.array(z.number().int().nonnegative()),
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
export const decisionTreeEdgeSchema = z.object({
|
|
211
|
+
id: z.string().min(1),
|
|
212
|
+
from: z.string().min(1),
|
|
213
|
+
to: z.string().min(1),
|
|
214
|
+
label: z.string(),
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
export const studioDecisionTableSchema = z.object({
|
|
218
|
+
id: z.string().min(1),
|
|
219
|
+
reqId: z.string().nullable(),
|
|
220
|
+
title: z.string(),
|
|
221
|
+
headers: z.array(z.string()),
|
|
222
|
+
rows: z.array(z.array(z.string())),
|
|
223
|
+
tree: z.object({
|
|
224
|
+
nodes: z.array(decisionTreeNodeSchema),
|
|
225
|
+
edges: z.array(decisionTreeEdgeSchema),
|
|
226
|
+
}),
|
|
227
|
+
});
|
|
228
|
+
export type StudioDecisionTableDto = z.infer<typeof studioDecisionTableSchema>;
|
|
229
|
+
|
|
230
|
+
export const specRuleItemSchema = z.object({
|
|
231
|
+
reqId: z.string().nullable(),
|
|
232
|
+
title: z.string(),
|
|
233
|
+
description: z.string(),
|
|
234
|
+
hardness: verificationHardnessSchema,
|
|
235
|
+
scenarioCount: z.number().int().nonnegative(),
|
|
236
|
+
scenarios: z.array(
|
|
237
|
+
z.object({
|
|
238
|
+
name: z.string(),
|
|
239
|
+
steps: z.array(z.string()),
|
|
240
|
+
}),
|
|
241
|
+
),
|
|
242
|
+
});
|
|
243
|
+
export type SpecRuleItem = z.infer<typeof specRuleItemSchema>;
|
|
244
|
+
|
|
245
|
+
export const convertibleHintSchema = z.object({
|
|
246
|
+
targetKind: z.enum(['machine', 'flow', 'decision']),
|
|
247
|
+
reason: z.string(),
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
export const specDetailResponseSchema = z.object({
|
|
251
|
+
id: z.string().min(1),
|
|
252
|
+
file: z.string().min(1),
|
|
253
|
+
purpose: z.string(),
|
|
254
|
+
kind: studioSpecKindSchema,
|
|
255
|
+
baseHash: z.string().min(1),
|
|
256
|
+
rawText: z.string(),
|
|
257
|
+
foldLevels: z.array(z.string()).length(5),
|
|
258
|
+
rules: z.array(specRuleItemSchema),
|
|
259
|
+
decisionTables: z.array(studioDecisionTableSchema),
|
|
260
|
+
machineKeys: z.array(z.string()),
|
|
261
|
+
convertibleHint: convertibleHintSchema.nullable(),
|
|
262
|
+
});
|
|
263
|
+
export type SpecDetailResponse = z.infer<typeof specDetailResponseSchema>;
|
|
264
|
+
|
|
265
|
+
export const putStateRequestSchema = z.object({
|
|
266
|
+
doc: studioStateDocSchema,
|
|
267
|
+
expectedRevision: z.number().int().nonnegative().optional(),
|
|
268
|
+
});
|
|
269
|
+
export type PutStateRequest = z.infer<typeof putStateRequestSchema>;
|
|
270
|
+
|
|
271
|
+
export const putStateResponseSchema = z.object({
|
|
272
|
+
ok: z.literal(true),
|
|
273
|
+
revision: z.number().int().nonnegative(),
|
|
274
|
+
updatedAt: z.string().min(1),
|
|
275
|
+
});
|
|
276
|
+
export type PutStateResponse = z.infer<typeof putStateResponseSchema>;
|
|
277
|
+
|
|
278
|
+
export const putLayoutRequestSchema = z.object({
|
|
279
|
+
positions: z.record(z.string(), z.object({ x: z.number().finite(), y: z.number().finite() })),
|
|
280
|
+
edgeBends: z
|
|
281
|
+
.record(z.string(), z.object({ dx: z.number().finite(), dy: z.number().finite() }))
|
|
282
|
+
.optional(),
|
|
283
|
+
});
|
|
284
|
+
export type PutLayoutRequest = z.infer<typeof putLayoutRequestSchema>;
|
|
285
|
+
|
|
286
|
+
export const textfoldRequestSchema = z.object({
|
|
287
|
+
content: z.string(),
|
|
288
|
+
capability: z.string().optional(),
|
|
289
|
+
endpoint: z.string().url().optional(),
|
|
290
|
+
});
|
|
291
|
+
export type TextfoldRequest = z.infer<typeof textfoldRequestSchema>;
|
|
292
|
+
|
|
293
|
+
export const textfoldResponseSchema = z.object({
|
|
294
|
+
provider: z.enum(['local-ast', 'external-serve']),
|
|
295
|
+
cached: z.boolean(),
|
|
296
|
+
sha256: z.string().min(1),
|
|
297
|
+
levels: z.array(z.string()).length(5),
|
|
298
|
+
});
|
|
299
|
+
export type TextfoldResponse = z.infer<typeof textfoldResponseSchema>;
|
|
300
|
+
|
|
301
|
+
export const exportProposalRequestSchema = z.object({
|
|
302
|
+
changeId: z.string().min(1),
|
|
303
|
+
title: z.string().min(1),
|
|
304
|
+
why: z.string().min(1),
|
|
305
|
+
dependsOn: z.array(z.string()).optional(),
|
|
306
|
+
});
|
|
307
|
+
export type ExportProposalRequest = z.infer<typeof exportProposalRequestSchema>;
|
|
308
|
+
|
|
309
|
+
export const exportProposalResponseSchema = z.object({
|
|
310
|
+
ok: z.literal(true),
|
|
311
|
+
changeId: z.string().min(1),
|
|
312
|
+
proposalPath: z.string().min(1),
|
|
313
|
+
});
|
|
314
|
+
export type ExportProposalResponse = z.infer<typeof exportProposalResponseSchema>;
|
|
315
|
+
|
|
316
|
+
export const previewDiffResponseSchema = z.object({
|
|
317
|
+
diffs: z.array(
|
|
318
|
+
z.object({
|
|
319
|
+
machineKey: z.string(),
|
|
320
|
+
sourceFile: z.string(),
|
|
321
|
+
unifiedDiff: z.string(),
|
|
322
|
+
semanticDiff: z.string(),
|
|
323
|
+
stale: z.boolean(),
|
|
324
|
+
}),
|
|
325
|
+
),
|
|
326
|
+
});
|
|
327
|
+
export type PreviewDiffResponse = z.infer<typeof previewDiffResponseSchema>;
|
|
328
|
+
|
|
329
|
+
export const studioSseEventSchema = z.discriminatedUnion('type', [
|
|
330
|
+
z.object({
|
|
331
|
+
type: z.literal('state-updated'),
|
|
332
|
+
wsKey: z.string(),
|
|
333
|
+
stateId: z.string(),
|
|
334
|
+
revision: z.number().int().nonnegative(),
|
|
335
|
+
originClientId: z.string().nullable(),
|
|
336
|
+
}),
|
|
337
|
+
z.object({
|
|
338
|
+
type: z.literal('specs-changed'),
|
|
339
|
+
wsKey: z.string(),
|
|
340
|
+
changedFiles: z.array(z.string()),
|
|
341
|
+
}),
|
|
342
|
+
z.object({
|
|
343
|
+
type: z.literal('git-head-changed'),
|
|
344
|
+
wsKey: z.string(),
|
|
345
|
+
branch: z.string(),
|
|
346
|
+
protected: z.boolean(),
|
|
347
|
+
}),
|
|
348
|
+
z.object({
|
|
349
|
+
type: z.literal('views-updated'),
|
|
350
|
+
wsKey: z.string(),
|
|
351
|
+
originClientId: z.string().nullable(),
|
|
352
|
+
}),
|
|
353
|
+
z.object({
|
|
354
|
+
type: z.literal('ping'),
|
|
355
|
+
ts: z.string(),
|
|
356
|
+
}),
|
|
357
|
+
]);
|
|
358
|
+
export type StudioSseEvent = z.infer<typeof studioSseEventSchema>;
|
|
359
|
+
|
|
360
|
+
export const studioFocusObjectSchema = z.object({
|
|
361
|
+
kind: z.enum(['forest', 'macro-edge', 'state', 'edge']),
|
|
362
|
+
id: z.string().min(1),
|
|
363
|
+
});
|
|
364
|
+
export type StudioFocusObject = z.infer<typeof studioFocusObjectSchema>;
|
|
365
|
+
|
|
366
|
+
export const studioFocusContextSchema = z.object({
|
|
367
|
+
wsKey: z.string(),
|
|
368
|
+
repo: z.string(),
|
|
369
|
+
branch: z.string(),
|
|
370
|
+
targetKind: z.enum(['macro', 'machine', 'doc', 'state', 'edge']),
|
|
371
|
+
targetId: z.string(),
|
|
372
|
+
canonicalUrl: z.string(),
|
|
373
|
+
summary: z.string(),
|
|
374
|
+
nest: z.array(z.string().min(1)).optional(),
|
|
375
|
+
focus: studioFocusObjectSchema.optional(),
|
|
376
|
+
});
|
|
377
|
+
export type StudioFocusContext = z.infer<typeof studioFocusContextSchema>;
|
|
378
|
+
|
|
379
|
+
export const studioDeepLinkJsonSchema = z.object({
|
|
380
|
+
focus: studioFocusContextSchema,
|
|
381
|
+
workspace: workspaceItemSchema,
|
|
382
|
+
specs: z.array(specIndexItemSchema),
|
|
383
|
+
edges: z.array(specIndexEdgeSchema),
|
|
384
|
+
});
|
|
385
|
+
export type StudioDeepLinkJson = z.infer<typeof studioDeepLinkJsonSchema>;
|
|
386
|
+
|
|
387
|
+
export const studioSearchTargetKindSchema = z.enum([
|
|
388
|
+
'spec',
|
|
389
|
+
'rule',
|
|
390
|
+
'state',
|
|
391
|
+
'edge',
|
|
392
|
+
'decision',
|
|
393
|
+
'comment',
|
|
394
|
+
'timeline',
|
|
395
|
+
'theorem',
|
|
396
|
+
]);
|
|
397
|
+
|
|
398
|
+
export const studioSearchRequestSchema = z.object({
|
|
399
|
+
query: z.string().trim().min(1),
|
|
400
|
+
topK: z.number().int().min(1).max(50).optional(),
|
|
401
|
+
endpoint: z.string().url().optional(),
|
|
402
|
+
});
|
|
403
|
+
export type StudioSearchRequest = z.infer<typeof studioSearchRequestSchema>;
|
|
404
|
+
|
|
405
|
+
export const studioSearchHitSchema = z.object({
|
|
406
|
+
id: z.string().min(1),
|
|
407
|
+
targetKind: studioSearchTargetKindSchema,
|
|
408
|
+
targetId: z.string().min(1),
|
|
409
|
+
capId: z.string().min(1),
|
|
410
|
+
machineKey: z.string().optional(),
|
|
411
|
+
title: z.string().min(1),
|
|
412
|
+
snippet: z.string(),
|
|
413
|
+
score: z.number(),
|
|
414
|
+
source: z.enum(['local-bm25', 'rag-serve']),
|
|
415
|
+
});
|
|
416
|
+
export type StudioSearchHit = z.infer<typeof studioSearchHitSchema>;
|
|
417
|
+
|
|
418
|
+
export const studioSearchResponseSchema = z.object({
|
|
419
|
+
provider: z.enum(['local-bm25', 'rag-serve']),
|
|
420
|
+
cached: z.boolean(),
|
|
421
|
+
degradedReason: z.string().optional(),
|
|
422
|
+
totalIndexed: z.number().int().nonnegative(),
|
|
423
|
+
hits: z.array(studioSearchHitSchema),
|
|
424
|
+
});
|
|
425
|
+
export type StudioSearchResponse = z.infer<typeof studioSearchResponseSchema>;
|
|
426
|
+
|
|
427
|
+
export const syncPickSchema = z.enum(['ours', 'theirs', 'both']);
|
|
428
|
+
export type SyncPickDto = z.infer<typeof syncPickSchema>;
|
|
429
|
+
|
|
430
|
+
export const syncItemKindSchema = z.enum([
|
|
431
|
+
'state',
|
|
432
|
+
'transition',
|
|
433
|
+
'condition',
|
|
434
|
+
'doc-rule',
|
|
435
|
+
'nest',
|
|
436
|
+
'kind',
|
|
437
|
+
'node-meta',
|
|
438
|
+
]);
|
|
439
|
+
|
|
440
|
+
export const syncTransitionPayloadSchema = z.object({
|
|
441
|
+
from: z.string().min(1),
|
|
442
|
+
event: z.string(),
|
|
443
|
+
condition: z.string().optional(),
|
|
444
|
+
to: z.string().min(1),
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
export const nodeMetaFieldSchema = z.enum(['summary', 'actor', 'done']);
|
|
448
|
+
|
|
449
|
+
export const syncItemSchema = z.object({
|
|
450
|
+
id: z.string().min(1),
|
|
451
|
+
kind: syncItemKindSchema,
|
|
452
|
+
machineKey: z.string().min(1).optional(),
|
|
453
|
+
sourceFile: z.string().min(1),
|
|
454
|
+
oursPresent: z.boolean(),
|
|
455
|
+
theirsPresent: z.boolean(),
|
|
456
|
+
labelOurs: z.string().nullable(),
|
|
457
|
+
labelTheirs: z.string().nullable(),
|
|
458
|
+
defaultPick: syncPickSchema.nullable(),
|
|
459
|
+
oursStateName: z.string().optional(),
|
|
460
|
+
theirsStateName: z.string().optional(),
|
|
461
|
+
oursTransition: syncTransitionPayloadSchema.optional(),
|
|
462
|
+
theirsTransition: syncTransitionPayloadSchema.optional(),
|
|
463
|
+
oursNest: z.string().nullable().optional(),
|
|
464
|
+
theirsNest: z.string().nullable().optional(),
|
|
465
|
+
oursNodeKind: z.string().nullable().optional(),
|
|
466
|
+
theirsNodeKind: z.string().nullable().optional(),
|
|
467
|
+
metaField: nodeMetaFieldSchema.optional(),
|
|
468
|
+
oursNodeMeta: z.string().nullable().optional(),
|
|
469
|
+
theirsNodeMeta: z.string().nullable().optional(),
|
|
470
|
+
oursText: z.string().optional(),
|
|
471
|
+
theirsText: z.string().optional(),
|
|
472
|
+
});
|
|
473
|
+
export type SyncItemDto = z.infer<typeof syncItemSchema>;
|
|
474
|
+
|
|
475
|
+
export const syncPreviewResponseSchema = z.object({
|
|
476
|
+
stale: z.boolean(),
|
|
477
|
+
staleFiles: z.array(z.string()),
|
|
478
|
+
items: z.array(syncItemSchema),
|
|
479
|
+
snapshotTaken: z.boolean(),
|
|
480
|
+
});
|
|
481
|
+
export type SyncPreviewResponse = z.infer<typeof syncPreviewResponseSchema>;
|
|
482
|
+
|
|
483
|
+
export const syncApplyRequestSchema = z.object({
|
|
484
|
+
picks: z.record(z.string(), syncPickSchema),
|
|
485
|
+
});
|
|
486
|
+
export type SyncApplyRequest = z.infer<typeof syncApplyRequestSchema>;
|
|
487
|
+
|
|
488
|
+
export const syncApplyResponseSchema = z.object({
|
|
489
|
+
ok: z.literal(true),
|
|
490
|
+
doc: studioStateDocSchema,
|
|
491
|
+
blocked: z.array(z.object({ itemId: z.string(), reason: z.string() })),
|
|
492
|
+
});
|
|
493
|
+
export type SyncApplyResponse = z.infer<typeof syncApplyResponseSchema>;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic 0-LLM Decision Table -> Decision Tree compiler and structural conversion detector
|
|
3
|
+
* (studio-web r146). Pure — zero I/O, zero LLM calls.
|
|
4
|
+
*/
|
|
5
|
+
import type { CapabilityDoc, ScenarioIR } from '../spec/ir.ts';
|
|
6
|
+
import { DECISION_TABLE_TAG, resolveGraphScope } from '../validation/xstateTransitions.ts';
|
|
7
|
+
|
|
8
|
+
export interface DecisionTreeNode {
|
|
9
|
+
id: string;
|
|
10
|
+
kind: 'condition' | 'outcome';
|
|
11
|
+
label: string;
|
|
12
|
+
rowIndices: number[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface DecisionTreeEdge {
|
|
16
|
+
id: string;
|
|
17
|
+
from: string;
|
|
18
|
+
to: string;
|
|
19
|
+
label: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface DecisionTreeGraph {
|
|
23
|
+
nodes: DecisionTreeNode[];
|
|
24
|
+
edges: DecisionTreeEdge[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface StudioDecisionTable {
|
|
28
|
+
id: string;
|
|
29
|
+
reqId: string | null;
|
|
30
|
+
title: string;
|
|
31
|
+
headers: string[];
|
|
32
|
+
rows: string[][];
|
|
33
|
+
tree: DecisionTreeGraph;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ConvertibleStructureHint {
|
|
37
|
+
targetKind: 'machine' | 'flow' | 'decision';
|
|
38
|
+
reason: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Compile a truth/decision table (condition columns 0..k-2, outcome column k-1) into a
|
|
43
|
+
* deterministic decision tree graph with zero LLM calls.
|
|
44
|
+
*/
|
|
45
|
+
export function compileDecisionTableToTree(
|
|
46
|
+
headers: readonly string[],
|
|
47
|
+
rows: readonly (readonly string[])[],
|
|
48
|
+
): DecisionTreeGraph {
|
|
49
|
+
const nodes: DecisionTreeNode[] = [];
|
|
50
|
+
const edges: DecisionTreeEdge[] = [];
|
|
51
|
+
if (headers.length < 2 || rows.length === 0) {
|
|
52
|
+
return { nodes, edges };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const outCol = headers.length - 1;
|
|
56
|
+
let seq = 0;
|
|
57
|
+
const nextId = (prefix: string): string => {
|
|
58
|
+
seq += 1;
|
|
59
|
+
return `${prefix}_${String(seq)}`;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
function buildSubtree(rowIndices: number[], usedCols: Set<number>): string {
|
|
63
|
+
const outcomes = new Set(rowIndices.map((idx) => (rows[idx]?.[outCol] ?? '').trim()));
|
|
64
|
+
if (outcomes.size === 1) {
|
|
65
|
+
const outcomeLabel = [...outcomes][0] ?? '—';
|
|
66
|
+
const id = nextId('out');
|
|
67
|
+
nodes.push({ id, kind: 'outcome', label: outcomeLabel, rowIndices });
|
|
68
|
+
return id;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let bestCol = -1;
|
|
72
|
+
let bestScore = -1;
|
|
73
|
+
for (let col = 0; col < outCol; col += 1) {
|
|
74
|
+
if (usedCols.has(col)) continue;
|
|
75
|
+
const groups = new Map<string, number[]>();
|
|
76
|
+
let wildcards = 0;
|
|
77
|
+
for (const rIdx of rowIndices) {
|
|
78
|
+
const val = (rows[rIdx]?.[col] ?? '').trim() || '—';
|
|
79
|
+
if (val === '—' || val === '-' || val === '*') wildcards += 1;
|
|
80
|
+
const list = groups.get(val) ?? [];
|
|
81
|
+
list.push(rIdx);
|
|
82
|
+
groups.set(val, list);
|
|
83
|
+
}
|
|
84
|
+
if (groups.size < 2) continue;
|
|
85
|
+
let pureGroups = 0;
|
|
86
|
+
for (const grp of groups.values()) {
|
|
87
|
+
const grpOuts = new Set(grp.map((i) => (rows[i]?.[outCol] ?? '').trim()));
|
|
88
|
+
if (grpOuts.size === 1) pureGroups += 1;
|
|
89
|
+
}
|
|
90
|
+
const score = pureGroups * 100 - wildcards * 20 - groups.size;
|
|
91
|
+
if (score > bestScore) {
|
|
92
|
+
bestScore = score;
|
|
93
|
+
bestCol = col;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (bestCol === -1) {
|
|
98
|
+
const merged = [...outcomes].join(' / ');
|
|
99
|
+
const id = nextId('out');
|
|
100
|
+
nodes.push({ id, kind: 'outcome', label: merged, rowIndices });
|
|
101
|
+
return id;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const condId = nextId('cond');
|
|
105
|
+
nodes.push({
|
|
106
|
+
id: condId,
|
|
107
|
+
kind: 'condition',
|
|
108
|
+
label: headers[bestCol] ?? `条件 ${String(bestCol + 1)}`,
|
|
109
|
+
rowIndices,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const groups = new Map<string, number[]>();
|
|
113
|
+
for (const rIdx of rowIndices) {
|
|
114
|
+
const val = (rows[rIdx]?.[bestCol] ?? '').trim() || '—';
|
|
115
|
+
const list = groups.get(val) ?? [];
|
|
116
|
+
list.push(rIdx);
|
|
117
|
+
groups.set(val, list);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const nextUsed = new Set(usedCols);
|
|
121
|
+
nextUsed.add(bestCol);
|
|
122
|
+
for (const [branchVal, subRows] of groups.entries()) {
|
|
123
|
+
const childId = buildSubtree(subRows, nextUsed);
|
|
124
|
+
edges.push({
|
|
125
|
+
id: nextId('dt_e'),
|
|
126
|
+
from: condId,
|
|
127
|
+
to: childId,
|
|
128
|
+
label: branchVal,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return condId;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
buildSubtree(
|
|
135
|
+
rows.map((_, idx) => idx),
|
|
136
|
+
new Set(),
|
|
137
|
+
);
|
|
138
|
+
return { nodes, edges };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function isDecisionScenario(scenario: ScenarioIR): boolean {
|
|
142
|
+
return resolveGraphScope(scenario) === DECISION_TABLE_TAG;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Extract @decision_table Examples tables from a parsed CapabilityDoc. */
|
|
146
|
+
export function extractDecisionTables(doc: CapabilityDoc): StudioDecisionTable[] {
|
|
147
|
+
const tables: StudioDecisionTable[] = [];
|
|
148
|
+
let idx = 0;
|
|
149
|
+
|
|
150
|
+
const inspectScenario = (scenario: ScenarioIR, reqId: string | null): void => {
|
|
151
|
+
if (!isDecisionScenario(scenario)) return;
|
|
152
|
+
for (const block of scenario.examples ?? []) {
|
|
153
|
+
idx += 1;
|
|
154
|
+
tables.push({
|
|
155
|
+
id: `dt_${String(idx)}`,
|
|
156
|
+
reqId,
|
|
157
|
+
title: block.name ? `${scenario.name} · ${block.name}` : scenario.name,
|
|
158
|
+
headers: [...block.headers],
|
|
159
|
+
rows: block.rows.map((r) => [...r]),
|
|
160
|
+
tree: compileDecisionTableToTree(block.headers, block.rows),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
for (const rule of doc.rules) {
|
|
166
|
+
for (const sc of rule.scenarios) {
|
|
167
|
+
inspectScenario(sc, rule.reqId);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
for (const sc of doc.orphans) {
|
|
171
|
+
inspectScenario(sc, null);
|
|
172
|
+
}
|
|
173
|
+
return tables;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Deterministic structural hint detecting when a rule-only spec describes clear state transitions,
|
|
178
|
+
* sequential gates, or mutually exclusive decision branches.
|
|
179
|
+
*/
|
|
180
|
+
export function detectConvertibleStructure(
|
|
181
|
+
doc: CapabilityDoc,
|
|
182
|
+
hasMachines: boolean,
|
|
183
|
+
hasDecisionTables: boolean,
|
|
184
|
+
): ConvertibleStructureHint | null {
|
|
185
|
+
if (hasMachines || hasDecisionTables) return null;
|
|
186
|
+
const joined = doc.rules.map((r) => `${r.title} ${r.description}`).join('\n');
|
|
187
|
+
if (/(状态|流转|终态|回滚|生命周期|transition|state)/iu.test(joined) && doc.rules.length >= 3) {
|
|
188
|
+
return {
|
|
189
|
+
targetKind: 'machine',
|
|
190
|
+
reason: '检测到多条规则描述了状态迁移或生命周期阶段,可转为状态机解锁 E1–E4 门禁与单步推演。',
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
if (/(优先级|互斥|否则|组合|分支|priority|conflict)/iu.test(joined) && doc.rules.length >= 3) {
|
|
194
|
+
return {
|
|
195
|
+
targetKind: 'decision',
|
|
196
|
+
reason: '检测到规则包含互斥条件与优先级分支,可转为决策树/真值表便于直观对照。',
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
if (/(步骤|前置|依次|流水线|熔断|pipeline|step)/iu.test(joined) && doc.rules.length >= 2) {
|
|
200
|
+
return {
|
|
201
|
+
targetKind: 'flow',
|
|
202
|
+
reason: '检测到前置校验与顺序处理步骤,可转为流程图直观审视正常与异常出口。',
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
return null;
|
|
206
|
+
}
|