universal-dev-standards 6.15.0 → 6.16.0-beta.2
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/bin/uds.js +2 -0
- package/bundled/locales/zh-CN/CHANGELOG.md +34 -4
- package/bundled/locales/zh-CN/CLAUDE.md +2 -2
- package/bundled/locales/zh-CN/README.md +17 -14
- package/bundled/locales/zh-CN/SECURITY.md +1 -0
- package/bundled/locales/zh-CN/docs/CHEATSHEET.md +1 -1
- package/bundled/locales/zh-CN/docs/CLI-INIT-OPTIONS.md +24 -2
- package/bundled/locales/zh-CN/docs/FEATURE-REFERENCE.md +3 -1
- package/bundled/locales/zh-TW/CHANGELOG.md +34 -4
- package/bundled/locales/zh-TW/CLAUDE.md +2 -2
- package/bundled/locales/zh-TW/README.md +17 -14
- package/bundled/locales/zh-TW/SECURITY.md +1 -0
- package/bundled/locales/zh-TW/docs/CHEATSHEET.md +1 -1
- package/bundled/locales/zh-TW/docs/CLI-INIT-OPTIONS.md +24 -2
- package/bundled/locales/zh-TW/docs/FEATURE-REFERENCE.md +3 -1
- package/package.json +3 -3
- package/src/commands/skills.js +9 -0
- package/src/commands/update.js +223 -2
- package/src/reconciler/desired-state-calculator.js +11 -2
- package/src/utils/optional-skills-report.js +86 -0
- package/src/utils/optional-skills.js +20 -0
- package/src/utils/skill-selection.js +137 -0
- package/src/utils/skills-installer.js +11 -4
- package/standards-registry.json +7 -7
- package/src/core/agent-communication-protocol.js +0 -257
- package/src/flow/condition-evaluator.js +0 -86
- package/src/flow/flow-bundler.js +0 -80
- package/src/flow/flow-commands.js +0 -107
- package/src/flow/flow-engine.js +0 -154
- package/src/flow/flow-inheritance.js +0 -100
- package/src/flow/flow-parser.js +0 -104
- package/src/flow/flow-validator.js +0 -37
- package/src/flow/gate-checker.js +0 -82
- package/src/flow/gate-loader.js +0 -52
- package/src/missions/MissionManager.js +0 -533
- package/src/utils/e2e-analyzer.js +0 -471
- package/src/utils/e2e-detector.js +0 -132
- package/src/utils/hook-stats.js +0 -151
- package/src/utils/workflow-executor.js +0 -870
- package/src/utils/workflows-installer.js +0 -545
- package/src/vibe/auto-sweep.js +0 -349
package/standards-registry.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.16.0-beta.2",
|
|
4
4
|
"lastUpdated": "2026-05-13",
|
|
5
5
|
"description": "Standards registry for universal-dev-standards with integrated skills and AI-optimized formats",
|
|
6
6
|
"formats": {
|
|
@@ -58,14 +58,14 @@
|
|
|
58
58
|
"standards": {
|
|
59
59
|
"name": "universal-dev-standards",
|
|
60
60
|
"url": "https://github.com/AsiaOstrich/universal-dev-standards",
|
|
61
|
-
"version": "6.
|
|
61
|
+
"version": "6.16.0-beta.2"
|
|
62
62
|
},
|
|
63
63
|
"skills": {
|
|
64
64
|
"name": "universal-dev-standards",
|
|
65
65
|
"url": "https://github.com/AsiaOstrich/universal-dev-standards",
|
|
66
66
|
"localPath": "skills",
|
|
67
67
|
"rawUrl": "https://raw.githubusercontent.com/AsiaOstrich/universal-dev-standards/main/skills",
|
|
68
|
-
"version": "6.
|
|
68
|
+
"version": "6.16.0-beta.2",
|
|
69
69
|
"note": "Skills are now included in the main repository under skills/"
|
|
70
70
|
}
|
|
71
71
|
},
|
|
@@ -2327,7 +2327,7 @@
|
|
|
2327
2327
|
"id": "license-compliance",
|
|
2328
2328
|
"name": "License Compliance Standards",
|
|
2329
2329
|
"nameZh": "授權合規標準",
|
|
2330
|
-
"version": "6.
|
|
2330
|
+
"version": "6.16.0-beta.2",
|
|
2331
2331
|
"source": {
|
|
2332
2332
|
"human": "core/license-compliance.md",
|
|
2333
2333
|
"ai": "ai/standards/license-compliance.ai.yaml"
|
|
@@ -2339,7 +2339,7 @@
|
|
|
2339
2339
|
"id": "verification-oracle",
|
|
2340
2340
|
"name": "Verification Oracle Standards",
|
|
2341
2341
|
"nameZh": "驗證 Oracle 標準",
|
|
2342
|
-
"version": "6.
|
|
2342
|
+
"version": "6.16.0-beta.2",
|
|
2343
2343
|
"source": {
|
|
2344
2344
|
"human": "core/verification-oracle.md",
|
|
2345
2345
|
"ai": "ai/standards/verification-oracle.ai.yaml"
|
|
@@ -2351,7 +2351,7 @@
|
|
|
2351
2351
|
"id": "model-provenance",
|
|
2352
2352
|
"name": "Model Provenance Policy Standards",
|
|
2353
2353
|
"nameZh": "模型來源政策標準",
|
|
2354
|
-
"version": "6.
|
|
2354
|
+
"version": "6.16.0-beta.2",
|
|
2355
2355
|
"source": {
|
|
2356
2356
|
"human": "core/model-provenance.md",
|
|
2357
2357
|
"ai": "ai/standards/model-provenance.ai.yaml"
|
|
@@ -2363,7 +2363,7 @@
|
|
|
2363
2363
|
"id": "resource-cost-boundary",
|
|
2364
2364
|
"name": "Resource / Cost Boundary Declaration Standards",
|
|
2365
2365
|
"nameZh": "資源/成本邊界宣告標準",
|
|
2366
|
-
"version": "6.
|
|
2366
|
+
"version": "6.16.0-beta.2",
|
|
2367
2367
|
"source": {
|
|
2368
2368
|
"human": "core/resource-cost-boundary.md",
|
|
2369
2369
|
"ai": "ai/standards/resource-cost-boundary.ai.yaml"
|
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent Communication Protocol v1.0
|
|
3
|
-
* Source: core/agent-communication-protocol.md
|
|
4
|
-
* Spec: SPEC-AGENT-COMM-001
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
// ─── Unified Status Codes ────────────────────────────
|
|
8
|
-
|
|
9
|
-
export const UNIFIED_STATUSES = [
|
|
10
|
-
'success', 'success_partial', 'failed', 'blocked',
|
|
11
|
-
'needs_context', 'skipped', 'timeout', 'unknown',
|
|
12
|
-
];
|
|
13
|
-
|
|
14
|
-
// Reference status mappings. `uds` is UDS's own native status set;
|
|
15
|
-
// the other two entries are illustrative example mappings showing how
|
|
16
|
-
// adoption-layer runtimes can plug their own status vocabularies into
|
|
17
|
-
// the unified status code set. Adoption layers should add their own
|
|
18
|
-
// keys (or call mapStatus with their own project name) — these example
|
|
19
|
-
// keys are not endorsements of any specific downstream product.
|
|
20
|
-
const STATUS_MAP = {
|
|
21
|
-
uds: {
|
|
22
|
-
DONE: 'success',
|
|
23
|
-
DONE_WITH_CONCERNS: 'success_partial',
|
|
24
|
-
NEEDS_CONTEXT: 'needs_context',
|
|
25
|
-
BLOCKED: 'blocked',
|
|
26
|
-
},
|
|
27
|
-
adapter_example_a: {
|
|
28
|
-
success: 'success',
|
|
29
|
-
failed: 'failed',
|
|
30
|
-
skipped: 'skipped',
|
|
31
|
-
timeout: 'timeout',
|
|
32
|
-
done_with_concerns: 'success_partial',
|
|
33
|
-
needs_context: 'needs_context',
|
|
34
|
-
blocked: 'blocked',
|
|
35
|
-
},
|
|
36
|
-
adapter_example_b: {
|
|
37
|
-
success: 'success',
|
|
38
|
-
partial: 'success_partial',
|
|
39
|
-
failure: 'failed',
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Map a project-specific status to unified status code.
|
|
45
|
-
* Unknown statuses map to 'unknown' with a warning.
|
|
46
|
-
* @param {string} status - Project-specific status code
|
|
47
|
-
* @param {string} project - Source project (e.g. 'uds', 'adapter_example_a',
|
|
48
|
-
* 'adapter_example_b', or any custom adoption-layer project key)
|
|
49
|
-
* @returns {{ unified: string, warning?: { original: string, project: string } }}
|
|
50
|
-
*/
|
|
51
|
-
export function mapStatus(status, project) {
|
|
52
|
-
const projectMap = STATUS_MAP[project];
|
|
53
|
-
if (!projectMap) {
|
|
54
|
-
return {
|
|
55
|
-
unified: 'unknown',
|
|
56
|
-
warning: { original: status, project, reason: `unknown project: ${project}` },
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const unified = projectMap[status];
|
|
61
|
-
if (unified) {
|
|
62
|
-
return { unified };
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
unified: 'unknown',
|
|
67
|
-
warning: { original: status, project, reason: `unmapped status: ${status}` },
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// ─── Envelope Validation ─────────────────────────────
|
|
72
|
-
|
|
73
|
-
const REQUIRED_ENVELOPE_FIELDS = [
|
|
74
|
-
'envelope_version',
|
|
75
|
-
'message_id',
|
|
76
|
-
'source',
|
|
77
|
-
'status',
|
|
78
|
-
'timestamp',
|
|
79
|
-
'payload',
|
|
80
|
-
];
|
|
81
|
-
|
|
82
|
-
const REQUIRED_SOURCE_FIELDS = ['agent_id', 'agent_type', 'project'];
|
|
83
|
-
const REQUIRED_PAYLOAD_FIELDS = ['artifact_type', 'artifact_id'];
|
|
84
|
-
const VALID_ARTIFACT_TYPES = ['spec', 'code', 'test', 'review', 'plan', 'design'];
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Validate an envelope message against v1.0 schema.
|
|
88
|
-
* @param {object} envelope - The envelope to validate
|
|
89
|
-
* @returns {{ valid: boolean, error?: string, missingFields?: string[] }}
|
|
90
|
-
*/
|
|
91
|
-
export function validateEnvelope(envelope) {
|
|
92
|
-
if (!envelope || typeof envelope !== 'object') {
|
|
93
|
-
return { valid: false, error: 'INVALID_ENVELOPE', missingFields: REQUIRED_ENVELOPE_FIELDS };
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const missing = [];
|
|
97
|
-
|
|
98
|
-
for (const field of REQUIRED_ENVELOPE_FIELDS) {
|
|
99
|
-
if (envelope[field] === undefined || envelope[field] === null) {
|
|
100
|
-
missing.push(field);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (envelope.source && typeof envelope.source === 'object') {
|
|
105
|
-
for (const field of REQUIRED_SOURCE_FIELDS) {
|
|
106
|
-
if (!envelope.source[field]) {
|
|
107
|
-
missing.push(`source.${field}`);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (envelope.payload && typeof envelope.payload === 'object') {
|
|
113
|
-
for (const field of REQUIRED_PAYLOAD_FIELDS) {
|
|
114
|
-
if (!envelope.payload[field]) {
|
|
115
|
-
missing.push(`payload.${field}`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (envelope.payload.artifact_type && !VALID_ARTIFACT_TYPES.includes(envelope.payload.artifact_type)) {
|
|
119
|
-
return {
|
|
120
|
-
valid: false,
|
|
121
|
-
error: 'INVALID_ENVELOPE',
|
|
122
|
-
missingFields: [],
|
|
123
|
-
details: `invalid artifact_type: ${envelope.payload.artifact_type}`,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (missing.length > 0) {
|
|
129
|
-
return { valid: false, error: 'INVALID_ENVELOPE', missingFields: missing };
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (!UNIFIED_STATUSES.includes(envelope.status)) {
|
|
133
|
-
return {
|
|
134
|
-
valid: false,
|
|
135
|
-
error: 'INVALID_ENVELOPE',
|
|
136
|
-
missingFields: [],
|
|
137
|
-
details: `invalid status: ${envelope.status}`,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return { valid: true };
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Parse an envelope, extracting only v1.0 known fields.
|
|
146
|
-
* Unknown fields are preserved in _extra.
|
|
147
|
-
* @param {object} envelope - Raw envelope
|
|
148
|
-
* @param {string} supportedMajor - Supported major version (e.g. '1')
|
|
149
|
-
* @returns {object} Parsed envelope with _extra for unknown fields
|
|
150
|
-
*/
|
|
151
|
-
export function parseEnvelope(envelope, supportedMajor = '1') {
|
|
152
|
-
const versionCheck = checkVersion(envelope.envelope_version, `${supportedMajor}.x`);
|
|
153
|
-
if (!versionCheck.compatible) {
|
|
154
|
-
throw new Error(versionCheck.error);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const knownFields = [
|
|
158
|
-
'envelope_version', 'message_id', 'source', 'target',
|
|
159
|
-
'status', 'timestamp', 'payload',
|
|
160
|
-
'correlation_id', 'parent_message_id', 'metadata', 'concerns',
|
|
161
|
-
];
|
|
162
|
-
|
|
163
|
-
const parsed = {};
|
|
164
|
-
const extra = {};
|
|
165
|
-
|
|
166
|
-
for (const [key, value] of Object.entries(envelope)) {
|
|
167
|
-
if (knownFields.includes(key)) {
|
|
168
|
-
parsed[key] = value;
|
|
169
|
-
} else {
|
|
170
|
-
extra[key] = value;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (Object.keys(extra).length > 0) {
|
|
175
|
-
parsed._extra = extra;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return parsed;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// ─── Structured Handoff ──────────────────────────────
|
|
182
|
-
|
|
183
|
-
const REQUIRED_DECISION_FIELDS = ['decision', 'reason', 'agent_id', 'timestamp'];
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Create a handoff object with selective artifact references.
|
|
187
|
-
* @param {object} options
|
|
188
|
-
* @param {object} options.from - Sender { agent_id, agent_type, message_id }
|
|
189
|
-
* @param {object} options.to - Receiver { agent_type }
|
|
190
|
-
* @param {string[]} options.artifactIds - IDs of artifacts to include
|
|
191
|
-
* @param {object[]} options.availableArtifacts - All available artifacts
|
|
192
|
-
* @param {object[]} [options.decisionLog] - Decision log entries
|
|
193
|
-
* @param {object[]} [options.pendingItems] - Pending items
|
|
194
|
-
* @param {string[]} [options.constraints] - Constraint strings
|
|
195
|
-
* @returns {object} Handoff object
|
|
196
|
-
*/
|
|
197
|
-
export function createHandoff({ from, to, artifactIds, availableArtifacts, decisionLog, pendingItems, constraints }) {
|
|
198
|
-
const artifacts = availableArtifacts.filter(a => artifactIds.includes(a.artifact_id));
|
|
199
|
-
|
|
200
|
-
const handoff = { from, to, artifacts };
|
|
201
|
-
|
|
202
|
-
if (decisionLog) {
|
|
203
|
-
for (const entry of decisionLog) {
|
|
204
|
-
const result = validateDecisionEntry(entry);
|
|
205
|
-
if (!result.valid) {
|
|
206
|
-
throw new Error(`Invalid decision_log entry: missing ${result.missingFields.join(', ')}`);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
handoff.decision_log = decisionLog;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (pendingItems) {
|
|
213
|
-
handoff.pending_items = pendingItems;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if (constraints) {
|
|
217
|
-
handoff.constraints = constraints;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
return handoff;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Validate a decision_log entry.
|
|
225
|
-
* @param {object} entry
|
|
226
|
-
* @returns {{ valid: boolean, missingFields?: string[] }}
|
|
227
|
-
*/
|
|
228
|
-
export function validateDecisionEntry(entry) {
|
|
229
|
-
const missing = REQUIRED_DECISION_FIELDS.filter(f => !entry[f]);
|
|
230
|
-
if (missing.length > 0) {
|
|
231
|
-
return { valid: false, missingFields: missing };
|
|
232
|
-
}
|
|
233
|
-
return { valid: true };
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// ─── Protocol Versioning ─────────────────────────────
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Check if an incoming protocol version is compatible.
|
|
240
|
-
* @param {string} incoming - Incoming version (e.g. '2.0')
|
|
241
|
-
* @param {string} supported - Supported range (e.g. '1.x')
|
|
242
|
-
* @returns {{ compatible: boolean, error?: string, supportedRange?: string }}
|
|
243
|
-
*/
|
|
244
|
-
export function checkVersion(incoming, supported) {
|
|
245
|
-
const incomingMajor = parseInt(incoming.split('.')[0], 10);
|
|
246
|
-
const supportedMajor = parseInt(supported.split('.')[0], 10);
|
|
247
|
-
|
|
248
|
-
if (incomingMajor !== supportedMajor) {
|
|
249
|
-
return {
|
|
250
|
-
compatible: false,
|
|
251
|
-
error: 'VERSION_INCOMPATIBLE',
|
|
252
|
-
supportedRange: supported,
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
return { compatible: true };
|
|
257
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Condition Evaluator — SPEC-FLOW-001
|
|
3
|
-
*
|
|
4
|
-
* 評估 Flow step 的 `when` 條件。
|
|
5
|
-
* 支援兩級語法:命名條件(字串)和屬性比對(物件)。
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { minimatch } from 'minimatch';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 內建命名條件的評估器。
|
|
12
|
-
* @type {Record<string, (context: object) => boolean>}
|
|
13
|
-
*/
|
|
14
|
-
const NAMED_CONDITIONS = {
|
|
15
|
-
scope_includes_api: (ctx) => Array.isArray(ctx.scope) && ctx.scope.includes('api'),
|
|
16
|
-
scope_includes_database: (ctx) => Array.isArray(ctx.scope) && ctx.scope.includes('database'),
|
|
17
|
-
scope_includes_frontend: (ctx) => Array.isArray(ctx.scope) && ctx.scope.includes('frontend'),
|
|
18
|
-
has_spec: (ctx) => !!ctx.has_spec,
|
|
19
|
-
has_tests: (ctx) => !!ctx.has_tests,
|
|
20
|
-
is_hotfix: (ctx) => !!ctx.is_hotfix
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 評估條件是否滿足。
|
|
25
|
-
* @param {string|object} condition - 命名條件(字串)或屬性比對(物件)
|
|
26
|
-
* @param {object} context - 當前執行環境
|
|
27
|
-
* @returns {boolean} 條件是否滿足
|
|
28
|
-
*/
|
|
29
|
-
export function evaluateCondition(condition, context) {
|
|
30
|
-
// Level 1:命名條件
|
|
31
|
-
if (typeof condition === 'string') {
|
|
32
|
-
const evaluator = NAMED_CONDITIONS[condition];
|
|
33
|
-
return evaluator ? evaluator(context) : false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Level 2:屬性比對(AND 語義)
|
|
37
|
-
if (typeof condition === 'object' && condition !== null) {
|
|
38
|
-
return Object.entries(condition).every(([key, expr]) => {
|
|
39
|
-
return evaluateExpression(key, expr, context);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* 評估單一屬性比對表達式。
|
|
48
|
-
* @param {string} key - 屬性名稱
|
|
49
|
-
* @param {string} expr - 表達式(如 "includes api"、"equals feature"、"matches **\/*.js")
|
|
50
|
-
* @param {object} context - 當前環境
|
|
51
|
-
* @returns {boolean}
|
|
52
|
-
*/
|
|
53
|
-
function evaluateExpression(key, expr, context) {
|
|
54
|
-
const spaceIndex = expr.indexOf(' ');
|
|
55
|
-
if (spaceIndex === -1) return false;
|
|
56
|
-
|
|
57
|
-
const operator = expr.substring(0, spaceIndex);
|
|
58
|
-
const value = expr.substring(spaceIndex + 1);
|
|
59
|
-
const contextValue = context[key];
|
|
60
|
-
|
|
61
|
-
switch (operator) {
|
|
62
|
-
case 'includes':
|
|
63
|
-
if (Array.isArray(contextValue)) {
|
|
64
|
-
return contextValue.includes(value);
|
|
65
|
-
}
|
|
66
|
-
if (typeof contextValue === 'string') {
|
|
67
|
-
return contextValue.includes(value);
|
|
68
|
-
}
|
|
69
|
-
return false;
|
|
70
|
-
|
|
71
|
-
case 'equals':
|
|
72
|
-
return contextValue === value;
|
|
73
|
-
|
|
74
|
-
case 'matches':
|
|
75
|
-
if (Array.isArray(contextValue)) {
|
|
76
|
-
return contextValue.some(item => minimatch(item, value));
|
|
77
|
-
}
|
|
78
|
-
if (typeof contextValue === 'string') {
|
|
79
|
-
return minimatch(contextValue, value);
|
|
80
|
-
}
|
|
81
|
-
return false;
|
|
82
|
-
|
|
83
|
-
default:
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
}
|
package/src/flow/flow-bundler.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flow Bundler — SPEC-FLOW-001
|
|
3
|
-
*
|
|
4
|
-
* Export/Import flow bundles:打包 flow + gates 為可分享的單一檔案。
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 匯出 flow 為 bundle。
|
|
9
|
-
* @param {object} flow - Flow 物件
|
|
10
|
-
* @param {Record<string, object>} allGates - 所有可用 gate 定義
|
|
11
|
-
* @param {object} [options]
|
|
12
|
-
* @param {string} [options.projectName] - 專案名稱
|
|
13
|
-
* @returns {object} Bundle 物件
|
|
14
|
-
*/
|
|
15
|
-
export function exportBundle(flow, allGates = {}, options = {}) {
|
|
16
|
-
// 收集 flow 引用的 gate refs
|
|
17
|
-
const referencedGateIds = new Set();
|
|
18
|
-
for (const stage of (flow.stages || [])) {
|
|
19
|
-
for (const gate of (stage.gates || [])) {
|
|
20
|
-
if (gate.ref) {
|
|
21
|
-
referencedGateIds.add(gate.ref);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const gates = [...referencedGateIds]
|
|
27
|
-
.map(id => allGates[id])
|
|
28
|
-
.filter(Boolean);
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
bundle_version: '1.0',
|
|
32
|
-
exported_at: new Date().toISOString(),
|
|
33
|
-
exported_from: options.projectName || '',
|
|
34
|
-
flow,
|
|
35
|
-
gates
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 匯入 bundle,解壓為 flow 和 gates。
|
|
41
|
-
* @param {object} bundle - Bundle 物件
|
|
42
|
-
* @param {object} [options]
|
|
43
|
-
* @param {string[]} [options.existingFlowIds] - 已存在的 flow IDs(用於衝突偵測)
|
|
44
|
-
* @returns {{flow: object, gates: object[], conflicts: string[]}}
|
|
45
|
-
*/
|
|
46
|
-
export function importBundle(bundle, options = {}) {
|
|
47
|
-
const { existingFlowIds = [] } = options;
|
|
48
|
-
|
|
49
|
-
const conflicts = [];
|
|
50
|
-
if (existingFlowIds.includes(bundle.flow.id)) {
|
|
51
|
-
conflicts.push(bundle.flow.id);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
flow: bundle.flow,
|
|
56
|
-
gates: bundle.gates || [],
|
|
57
|
-
conflicts
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* 驗證 bundle 的完整性。
|
|
63
|
-
* @param {object} bundle - Bundle 物件
|
|
64
|
-
* @param {object} [options]
|
|
65
|
-
* @param {string[]} [options.availableBaseFlows] - 可用的 base flow IDs
|
|
66
|
-
* @returns {Array<{type: string, message: string}>}
|
|
67
|
-
*/
|
|
68
|
-
export function validateBundle(bundle, options = {}) {
|
|
69
|
-
const errors = [];
|
|
70
|
-
const { availableBaseFlows = [] } = options;
|
|
71
|
-
|
|
72
|
-
if (bundle.flow.extends && !availableBaseFlows.includes(bundle.flow.extends)) {
|
|
73
|
-
errors.push({
|
|
74
|
-
type: 'missing_base_flow',
|
|
75
|
-
message: `Base flow "${bundle.flow.extends}" 不存在,請先安裝`
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return errors;
|
|
80
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flow Commands — SPEC-FLOW-001
|
|
3
|
-
*
|
|
4
|
-
* 核心邏輯函式,供 CLI 命令呼叫:list、validate、diff。
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { validateFlow } from './flow-validator.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 列出所有可用流程。
|
|
11
|
-
* @param {object[]} flows - Flow 物件陣列(含 _source 標記)
|
|
12
|
-
* @returns {Array<{id, name, label, stageCount, extends?}>}
|
|
13
|
-
*/
|
|
14
|
-
export function listFlows(flows) {
|
|
15
|
-
return flows.map(flow => ({
|
|
16
|
-
id: flow.id,
|
|
17
|
-
name: flow.name,
|
|
18
|
-
label: flow._source === 'built-in' ? 'built-in' : 'custom',
|
|
19
|
-
stageCount: flow.stages?.length || 0,
|
|
20
|
-
...(flow.extends ? { extends: flow.extends } : {})
|
|
21
|
-
}));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 驗證指定 flow 的邏輯正確性。
|
|
26
|
-
* @param {string} flowId - Flow ID
|
|
27
|
-
* @param {Record<string, object>} flowRegistry - 所有 flow 的 id → flow 對映
|
|
28
|
-
* @param {object} options
|
|
29
|
-
* @param {string[]} options.availableCommands
|
|
30
|
-
* @returns {{valid: boolean, errors: Array<{type: string, message: string}>}}
|
|
31
|
-
*/
|
|
32
|
-
export function validateFlowById(flowId, flowRegistry, options = {}) {
|
|
33
|
-
const flow = flowRegistry[flowId];
|
|
34
|
-
if (!flow) {
|
|
35
|
-
return {
|
|
36
|
-
valid: false,
|
|
37
|
-
errors: [{ type: 'not_found', message: `流程 "${flowId}" 不存在` }]
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const errors = [];
|
|
42
|
-
|
|
43
|
-
// 檢查 stage ID 唯一性
|
|
44
|
-
if (flow.stages) {
|
|
45
|
-
const seenIds = new Set();
|
|
46
|
-
for (const stage of flow.stages) {
|
|
47
|
-
if (seenIds.has(stage.id)) {
|
|
48
|
-
errors.push({
|
|
49
|
-
type: 'duplicate_stage',
|
|
50
|
-
message: `重複的 stage ID: "${stage.id}"`
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
seenIds.add(stage.id);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// 委託 validateFlow 做命令引用檢查
|
|
58
|
-
const validatorErrors = validateFlow(flow, options);
|
|
59
|
-
errors.push(...validatorErrors);
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
valid: errors.length === 0,
|
|
63
|
-
errors
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* 比較兩個 flow 的差異。
|
|
69
|
-
* @param {object} flowA - 基準 flow
|
|
70
|
-
* @param {object} flowB - 比較 flow
|
|
71
|
-
* @returns {{stages: {added: string[], removed: string[]}, steps: {modified: Array<{stageId, added, removed}>}}}
|
|
72
|
-
*/
|
|
73
|
-
export function diffFlows(flowA, flowB) {
|
|
74
|
-
const stageIdsA = (flowA.stages || []).map(s => s.id);
|
|
75
|
-
const stageIdsB = (flowB.stages || []).map(s => s.id);
|
|
76
|
-
|
|
77
|
-
const added = stageIdsB.filter(id => !stageIdsA.includes(id));
|
|
78
|
-
const removed = stageIdsA.filter(id => !stageIdsB.includes(id));
|
|
79
|
-
|
|
80
|
-
// 比較共同 stages 的 steps 差異
|
|
81
|
-
const commonStageIds = stageIdsA.filter(id => stageIdsB.includes(id));
|
|
82
|
-
const modified = [];
|
|
83
|
-
|
|
84
|
-
for (const stageId of commonStageIds) {
|
|
85
|
-
const stageA = flowA.stages.find(s => s.id === stageId);
|
|
86
|
-
const stageB = flowB.stages.find(s => s.id === stageId);
|
|
87
|
-
|
|
88
|
-
const cmdsA = (stageA.steps || []).map(s => s.command);
|
|
89
|
-
const cmdsB = (stageB.steps || []).map(s => s.command);
|
|
90
|
-
|
|
91
|
-
const addedCmds = cmdsB.filter(c => !cmdsA.includes(c));
|
|
92
|
-
const removedCmds = cmdsA.filter(c => !cmdsB.includes(c));
|
|
93
|
-
|
|
94
|
-
if (addedCmds.length > 0 || removedCmds.length > 0) {
|
|
95
|
-
modified.push({
|
|
96
|
-
stageId,
|
|
97
|
-
added: addedCmds,
|
|
98
|
-
removed: removedCmds
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return {
|
|
104
|
-
stages: { added, removed },
|
|
105
|
-
steps: { modified }
|
|
106
|
-
};
|
|
107
|
-
}
|