@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,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single requirement-reference coordinate system (unify-req-ref-and-clean-graph-dsl).
|
|
3
|
+
*
|
|
4
|
+
* One `REQ_ID_RE`, one `parseReqRef`, one tokenizer and one allocator serve every
|
|
5
|
+
* surface that names a requirement: `.feature` `@req:` handles, `@nodes` 引用 cells,
|
|
6
|
+
* `@flow` 验证 cells and source-code `@llmanspec:req:` anchors.
|
|
7
|
+
*
|
|
8
|
+
* Pure — zero I/O, zero `node:*`, zero wall-clock calls (core-zero-io).
|
|
9
|
+
*/
|
|
10
|
+
import { nextNumber } from '../util/nextNumber.ts';
|
|
11
|
+
|
|
12
|
+
/** The only legal requirement id shape: `r` followed by digits. */
|
|
13
|
+
export const REQ_ID_RE = /^r\d+$/u;
|
|
14
|
+
|
|
15
|
+
export interface ReqRef {
|
|
16
|
+
/** Parsed requirement id; empty string marks a syntactically invalid cell. */
|
|
17
|
+
reqId: string;
|
|
18
|
+
/** Scenario name when the reference pins one, `null` for a rule-level reference. */
|
|
19
|
+
scenarioName: string | null;
|
|
20
|
+
/** Original cell text, trimmed. */
|
|
21
|
+
raw: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const REF_PREFIX_RE = /^@?(?:llmanspec:)?req:/u;
|
|
25
|
+
const REQ_TAG_RE = /^@?req:(.+)$/u;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Which prefix a reference cell must carry.
|
|
29
|
+
* - `spec`: `.feature` cells (`引用` / `验证`) must be exactly `@req:...`.
|
|
30
|
+
* - `anchor`: source-code anchors must be exactly `@llmanspec:req:...`.
|
|
31
|
+
* - `payload`: bare `rN[#场景名]` payload (already prefix-stripped).
|
|
32
|
+
*/
|
|
33
|
+
export type ReqRefMode = 'spec' | 'anchor' | 'payload';
|
|
34
|
+
|
|
35
|
+
/** Extract the requirement id from a Gherkin tag name (`@req:r12` / `req:r12`). */
|
|
36
|
+
export function reqIdFromTag(tagName: string): string | null {
|
|
37
|
+
const m = REQ_TAG_RE.exec(tagName.trim());
|
|
38
|
+
if (!m?.[1]) return null;
|
|
39
|
+
return REQ_ID_RE.test(m[1]) ? m[1] : null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function parseScenarioName(raw: string): string | null {
|
|
43
|
+
if (/^\s/u.test(raw)) return null;
|
|
44
|
+
const text = raw.trim();
|
|
45
|
+
if (text === '') return null;
|
|
46
|
+
if (text.startsWith('"')) {
|
|
47
|
+
if (text.length < 3 || !text.endsWith('"')) return null;
|
|
48
|
+
const inner = text.slice(1, -1);
|
|
49
|
+
if (inner.trim() === '' || inner.includes('"') || /[\r\n]/u.test(inner)) return null;
|
|
50
|
+
return inner;
|
|
51
|
+
}
|
|
52
|
+
if (text.includes('"')) return null;
|
|
53
|
+
if (/\s/u.test(text)) return null;
|
|
54
|
+
return text;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Parse a requirement reference payload — with or without the `@req:` /
|
|
59
|
+
* `@llmanspec:req:` prefix: `r12`, `r12#待办生命周期`, `r12#"Studio Web 主态流转"`.
|
|
60
|
+
* Empty cell → `null`; syntactically invalid cell → `{ reqId: '', ... }`.
|
|
61
|
+
*/
|
|
62
|
+
export function parseReqRef(cell: string, mode: ReqRefMode = 'payload'): ReqRef | null {
|
|
63
|
+
const raw = cell.trim();
|
|
64
|
+
if (raw === '') return null;
|
|
65
|
+
let payload: string;
|
|
66
|
+
if (mode === 'spec') {
|
|
67
|
+
if (!raw.startsWith('@req:')) return { reqId: '', scenarioName: null, raw };
|
|
68
|
+
payload = raw.slice('@req:'.length);
|
|
69
|
+
} else if (mode === 'anchor') {
|
|
70
|
+
if (!raw.startsWith('@llmanspec:req:')) return { reqId: '', scenarioName: null, raw };
|
|
71
|
+
payload = raw.slice('@llmanspec:req:'.length);
|
|
72
|
+
} else {
|
|
73
|
+
payload = raw.replace(REF_PREFIX_RE, '');
|
|
74
|
+
}
|
|
75
|
+
const hashAt = payload.indexOf('#');
|
|
76
|
+
const idPart = hashAt === -1 ? payload : payload.slice(0, hashAt);
|
|
77
|
+
if (!REQ_ID_RE.test(idPart)) return { reqId: '', scenarioName: null, raw };
|
|
78
|
+
if (hashAt === -1) return { reqId: idPart, scenarioName: null, raw };
|
|
79
|
+
const scenarioName = parseScenarioName(payload.slice(hashAt + 1));
|
|
80
|
+
if (scenarioName === null) return { reqId: '', scenarioName: null, raw };
|
|
81
|
+
return { reqId: idPart, scenarioName, raw };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Split a whitespace-separated `验证` cell into reference tokens.
|
|
86
|
+
* Whitespace inside double quotes never splits:
|
|
87
|
+
* `@req:r1#"主态 流转" @req:r2` → 2 tokens.
|
|
88
|
+
*/
|
|
89
|
+
export function tokenizeReqRefs(cell: string): string[] {
|
|
90
|
+
const tokens: string[] = [];
|
|
91
|
+
let current = '';
|
|
92
|
+
let quoted = false;
|
|
93
|
+
for (const ch of cell.trim()) {
|
|
94
|
+
if (ch === '"') {
|
|
95
|
+
quoted = !quoted;
|
|
96
|
+
current += ch;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (!quoted && /\s/u.test(ch)) {
|
|
100
|
+
if (current !== '') {
|
|
101
|
+
tokens.push(current);
|
|
102
|
+
current = '';
|
|
103
|
+
}
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
current += ch;
|
|
107
|
+
}
|
|
108
|
+
if (current !== '') tokens.push(current);
|
|
109
|
+
return tokens;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Wrap a scenario name in double quotes when it carries whitespace. */
|
|
113
|
+
export function quoteScenarioName(scenarioName: string): string {
|
|
114
|
+
return /\s/u.test(scenarioName) ? `"${scenarioName}"` : scenarioName;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Render `@req:rN` / `@req:rN#场景名` / `@req:rN#"带空格 场景"`. */
|
|
118
|
+
export function formatReqRef(reqId: string, scenarioName?: string | null): string {
|
|
119
|
+
const name = scenarioName?.trim() ?? '';
|
|
120
|
+
if (name === '') return `@req:${reqId}`;
|
|
121
|
+
return `@req:${reqId}#${quoteScenarioName(name)}`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Allocate the repo-wide next requirement id (`r<max+1>`).
|
|
126
|
+
* Retired ranges are never reused (align-next-req-id-max-plus-one).
|
|
127
|
+
*/
|
|
128
|
+
export function allocateNextReqId(existingReqIds: Iterable<string>): string {
|
|
129
|
+
const used: number[] = [];
|
|
130
|
+
for (const id of existingReqIds) {
|
|
131
|
+
const trimmed = id.trim();
|
|
132
|
+
if (REQ_ID_RE.test(trimmed)) used.push(Math.trunc(Number(trimmed.slice(1))));
|
|
133
|
+
}
|
|
134
|
+
return `r${String(nextNumber(used))}`;
|
|
135
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe pure helpers for Studio change-scoped spec view (studio-web r199, r200).
|
|
3
|
+
* Strictly zero I/O and zero wall-clock calls.
|
|
4
|
+
*/
|
|
5
|
+
import type { StudioChangeScope } from './contracts.ts';
|
|
6
|
+
|
|
7
|
+
export type StudioScopeViewMode = 'changed' | 'all';
|
|
8
|
+
|
|
9
|
+
export interface ChangeScopeActivationInput {
|
|
10
|
+
isDefaultBranch: boolean;
|
|
11
|
+
hasCommittedSpecDiff: boolean;
|
|
12
|
+
hasUncommittedSpecDiff: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ChangeScopeActivationDecision {
|
|
16
|
+
active: boolean;
|
|
17
|
+
defaultViewMode: StudioScopeViewMode;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const EMPTY_CHANGE_SCOPE: StudioChangeScope = {
|
|
21
|
+
active: false,
|
|
22
|
+
branch: null,
|
|
23
|
+
baseBranch: null,
|
|
24
|
+
mergeBaseSha: null,
|
|
25
|
+
boundChangeId: null,
|
|
26
|
+
boundChangeTitle: null,
|
|
27
|
+
touchedSpecs: [],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Pure decision table for `studio-web` r199 ("变更视图激活判定"):
|
|
32
|
+
* - Default branch + no uncommitted diff -> inactive, all specs
|
|
33
|
+
* - Default branch + uncommitted diff -> active, changed view
|
|
34
|
+
* - Feature branch + no diffs -> active, all specs (with gentle empty-diff notice)
|
|
35
|
+
* - Feature branch + any committed/uncommitted diff -> active, changed view
|
|
36
|
+
*/
|
|
37
|
+
export function resolveChangeScopeActivation(
|
|
38
|
+
input: ChangeScopeActivationInput,
|
|
39
|
+
): ChangeScopeActivationDecision {
|
|
40
|
+
const hasAnyDiff = input.hasCommittedSpecDiff || input.hasUncommittedSpecDiff;
|
|
41
|
+
if (input.isDefaultBranch) {
|
|
42
|
+
return input.hasUncommittedSpecDiff
|
|
43
|
+
? { active: true, defaultViewMode: 'changed' }
|
|
44
|
+
: { active: false, defaultViewMode: 'all' };
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
active: true,
|
|
48
|
+
defaultViewMode: hasAnyDiff ? 'changed' : 'all',
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import type { CapabilityDoc, RuleIR } from '../spec/ir.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Pure-domain `.feature` fine-grained diff extractor for Studio change scope (studio-web r199).
|
|
4
|
+
* Extracts touched `@req` IDs and graph anchors (`@state` / `@flow` / `@decision_table`)
|
|
5
|
+
* with strictly zero I/O or wall-clock dependencies.
|
|
6
|
+
*/
|
|
7
|
+
import { parseCapability } from '../spec/parser.ts';
|
|
8
|
+
import type { SpecEntry } from '../validation/validate.ts';
|
|
9
|
+
import type { StudioChangeItemStatus } from './contracts.ts';
|
|
10
|
+
import { extractDecisionTables } from './decisionTree.ts';
|
|
11
|
+
import { extractStudioMachines } from './extract.ts';
|
|
12
|
+
import type { StudioMachineIR } from './model.ts';
|
|
13
|
+
|
|
14
|
+
export interface FeatureChangeDiffResult {
|
|
15
|
+
touchedReqIds: string[];
|
|
16
|
+
reqStatuses: Record<string, StudioChangeItemStatus>;
|
|
17
|
+
touchedGraphIds: string[];
|
|
18
|
+
graphStatuses: Record<string, StudioChangeItemStatus>;
|
|
19
|
+
baseMachines: Record<string, StudioMachineIR>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function serializeRule(rule: RuleIR): string {
|
|
23
|
+
return JSON.stringify({
|
|
24
|
+
reqId: rule.reqId,
|
|
25
|
+
title: rule.title.trim(),
|
|
26
|
+
description: rule.description.trim(),
|
|
27
|
+
tags: [...rule.tags].sort(),
|
|
28
|
+
scenarios: rule.scenarios.map((sc) => ({
|
|
29
|
+
name: sc.name.trim(),
|
|
30
|
+
tags: [...sc.tags].sort(),
|
|
31
|
+
steps: sc.steps.map((s) => `${s.kind} ${s.text.trim()}`),
|
|
32
|
+
examples: (sc.examples ?? []).map((ex) => ({
|
|
33
|
+
headers: ex.headers.map((h) => h.trim()),
|
|
34
|
+
rows: ex.rows.map((r) => r.map((c) => c.trim())),
|
|
35
|
+
})),
|
|
36
|
+
})),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function parseDocSafe(raw: string | null): CapabilityDoc | null {
|
|
41
|
+
if (!raw || raw.trim() === '') return null;
|
|
42
|
+
try {
|
|
43
|
+
return parseCapability(raw);
|
|
44
|
+
} catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function extractGraphFingerprints(
|
|
50
|
+
doc: CapabilityDoc | null,
|
|
51
|
+
capId: string,
|
|
52
|
+
): { fingerprints: Map<string, string>; machines: Map<string, StudioMachineIR> } {
|
|
53
|
+
const fingerprints = new Map<string, string>();
|
|
54
|
+
const machines = new Map<string, StudioMachineIR>();
|
|
55
|
+
if (!doc) return { fingerprints, machines };
|
|
56
|
+
|
|
57
|
+
const entry: SpecEntry = {
|
|
58
|
+
fileName: `${capId}.feature`,
|
|
59
|
+
specId: capId,
|
|
60
|
+
doc,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
for (const extracted of extractStudioMachines([entry])) {
|
|
64
|
+
const m = extracted.machine;
|
|
65
|
+
machines.set(m.machineKey, m);
|
|
66
|
+
fingerprints.set(
|
|
67
|
+
m.machineKey,
|
|
68
|
+
JSON.stringify({
|
|
69
|
+
graphKind: m.graphKind ?? 'machine',
|
|
70
|
+
reqId: m.reqId,
|
|
71
|
+
ruleTitle: m.ruleTitle,
|
|
72
|
+
scenarioName: m.scenarioName,
|
|
73
|
+
states: m.states.map((s) => ({
|
|
74
|
+
name: s.name,
|
|
75
|
+
nodeKind: s.nodeKind ?? null,
|
|
76
|
+
actor: s.actor ?? null,
|
|
77
|
+
nestKey: s.nestKey ?? null,
|
|
78
|
+
summary: s.summary ?? null,
|
|
79
|
+
})),
|
|
80
|
+
transitions: m.transitions.map((t) => ({
|
|
81
|
+
from: m.states.find((s) => s.uid === t.fromUid)?.name ?? t.fromUid,
|
|
82
|
+
to: m.states.find((s) => s.uid === t.toUid)?.name ?? t.toUid,
|
|
83
|
+
event: t.event,
|
|
84
|
+
condition: t.condition ?? null,
|
|
85
|
+
action: t.action ?? null,
|
|
86
|
+
actor: t.actor ?? null,
|
|
87
|
+
edgeKind: t.edgeKind ?? null,
|
|
88
|
+
verify: t.verify ?? null,
|
|
89
|
+
})),
|
|
90
|
+
}),
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
for (const dt of extractDecisionTables(doc)) {
|
|
95
|
+
fingerprints.set(
|
|
96
|
+
`decision:${dt.id}`,
|
|
97
|
+
JSON.stringify({
|
|
98
|
+
reqId: dt.reqId,
|
|
99
|
+
title: dt.title,
|
|
100
|
+
headers: dt.headers,
|
|
101
|
+
rows: dt.rows,
|
|
102
|
+
}),
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return { fingerprints, machines };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Pure domain diff between `baseRaw` (merge-base version or null when newly added)
|
|
111
|
+
* and `currentRaw` (working-tree version or null when deleted).
|
|
112
|
+
*/
|
|
113
|
+
export function computeFeatureChangeDiff(
|
|
114
|
+
baseRaw: string | null,
|
|
115
|
+
currentRaw: string | null,
|
|
116
|
+
capId = 'spec',
|
|
117
|
+
): FeatureChangeDiffResult {
|
|
118
|
+
const baseDoc = parseDocSafe(baseRaw);
|
|
119
|
+
const currentDoc = parseDocSafe(currentRaw);
|
|
120
|
+
|
|
121
|
+
const effectiveCapId = currentDoc?.featureName?.trim() || baseDoc?.featureName?.trim() || capId;
|
|
122
|
+
|
|
123
|
+
const baseRules = new Map<string, string>();
|
|
124
|
+
for (const r of baseDoc?.rules ?? []) {
|
|
125
|
+
if (r.reqId) baseRules.set(r.reqId, serializeRule(r));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const currentRules = new Map<string, string>();
|
|
129
|
+
const currentRuleOrder: string[] = [];
|
|
130
|
+
for (const r of currentDoc?.rules ?? []) {
|
|
131
|
+
if (r.reqId) {
|
|
132
|
+
currentRules.set(r.reqId, serializeRule(r));
|
|
133
|
+
currentRuleOrder.push(r.reqId);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const touchedReqIds: string[] = [];
|
|
138
|
+
const reqStatuses: Record<string, StudioChangeItemStatus> = {};
|
|
139
|
+
|
|
140
|
+
for (const reqId of currentRuleOrder) {
|
|
141
|
+
const prev = baseRules.get(reqId);
|
|
142
|
+
const next = currentRules.get(reqId)!;
|
|
143
|
+
if (prev === undefined) {
|
|
144
|
+
touchedReqIds.push(reqId);
|
|
145
|
+
reqStatuses[reqId] = 'added';
|
|
146
|
+
} else if (prev !== next) {
|
|
147
|
+
touchedReqIds.push(reqId);
|
|
148
|
+
reqStatuses[reqId] = 'modified';
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
for (const [reqId] of baseRules) {
|
|
153
|
+
if (!currentRules.has(reqId)) {
|
|
154
|
+
touchedReqIds.push(reqId);
|
|
155
|
+
reqStatuses[reqId] = 'deleted';
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const baseExtracted = extractGraphFingerprints(baseDoc, effectiveCapId);
|
|
160
|
+
const currentExtracted = extractGraphFingerprints(currentDoc, effectiveCapId);
|
|
161
|
+
const baseGraphs = baseExtracted.fingerprints;
|
|
162
|
+
const currentGraphs = currentExtracted.fingerprints;
|
|
163
|
+
|
|
164
|
+
const touchedGraphIds: string[] = [];
|
|
165
|
+
const graphStatuses: Record<string, StudioChangeItemStatus> = {};
|
|
166
|
+
const baseMachines: Record<string, StudioMachineIR> = {};
|
|
167
|
+
|
|
168
|
+
for (const [graphId, fp] of currentGraphs) {
|
|
169
|
+
const prev = baseGraphs.get(graphId);
|
|
170
|
+
if (prev === undefined) {
|
|
171
|
+
touchedGraphIds.push(graphId);
|
|
172
|
+
graphStatuses[graphId] = 'added';
|
|
173
|
+
} else if (prev !== fp) {
|
|
174
|
+
touchedGraphIds.push(graphId);
|
|
175
|
+
graphStatuses[graphId] = 'modified';
|
|
176
|
+
const baseIr = baseExtracted.machines.get(graphId);
|
|
177
|
+
if (baseIr) baseMachines[graphId] = baseIr;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
for (const [graphId] of baseGraphs) {
|
|
182
|
+
if (!currentGraphs.has(graphId)) {
|
|
183
|
+
touchedGraphIds.push(graphId);
|
|
184
|
+
graphStatuses[graphId] = 'deleted';
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
touchedReqIds,
|
|
190
|
+
reqStatuses,
|
|
191
|
+
touchedGraphIds,
|
|
192
|
+
graphStatuses,
|
|
193
|
+
baseMachines,
|
|
194
|
+
};
|
|
195
|
+
}
|