universal-dev-standards 6.15.0-beta.2 → 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 +38 -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 +2 -2
- 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 +38 -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 +2 -2
- 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/bundled/skills/.claude-plugin/plugin.json +1 -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
|
@@ -1,533 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync, unlinkSync, readdirSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
// Future: import { config } from '../utils/config-manager.js';
|
|
4
|
-
import { MicroSpec } from '../vibe/micro-spec.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Mission types supported by UDS
|
|
8
|
-
*/
|
|
9
|
-
export const MissionType = {
|
|
10
|
-
GENESIS: 'genesis', // New project from scratch (greenfield)
|
|
11
|
-
RENOVATE: 'renovate', // Refactor/improve existing code
|
|
12
|
-
MEDIC: 'medic', // Fix bugs, debug issues
|
|
13
|
-
EXODUS: 'exodus', // Migration (framework, language, etc.)
|
|
14
|
-
GUARDIAN: 'guardian' // Security audit, compliance check
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Mission states for the state machine
|
|
19
|
-
*/
|
|
20
|
-
export const MissionState = {
|
|
21
|
-
CREATED: 'created',
|
|
22
|
-
PLANNING: 'planning',
|
|
23
|
-
SPEC_PENDING: 'spec_pending',
|
|
24
|
-
SPEC_CONFIRMED: 'spec_confirmed',
|
|
25
|
-
IN_PROGRESS: 'in_progress',
|
|
26
|
-
REVIEW: 'review',
|
|
27
|
-
COMPLETED: 'completed',
|
|
28
|
-
PAUSED: 'paused',
|
|
29
|
-
CANCELLED: 'cancelled',
|
|
30
|
-
// Terminal failure state (T11 / XSPEC-292 §9.2): a mission that cannot
|
|
31
|
-
// proceed (unrecoverable error / abandoned). Like COMPLETED and CANCELLED it
|
|
32
|
-
// is terminal and cannot be resumed.
|
|
33
|
-
FAILED: 'failed'
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Valid state transitions.
|
|
38
|
-
* Any active (non-terminal) state may transition to FAILED; terminal states
|
|
39
|
-
* (COMPLETED / CANCELLED / FAILED) have no outgoing transitions.
|
|
40
|
-
*/
|
|
41
|
-
const STATE_TRANSITIONS = {
|
|
42
|
-
[MissionState.CREATED]: [MissionState.PLANNING, MissionState.CANCELLED, MissionState.FAILED],
|
|
43
|
-
[MissionState.PLANNING]: [MissionState.SPEC_PENDING, MissionState.PAUSED, MissionState.CANCELLED, MissionState.FAILED],
|
|
44
|
-
[MissionState.SPEC_PENDING]: [MissionState.SPEC_CONFIRMED, MissionState.PLANNING, MissionState.CANCELLED, MissionState.FAILED],
|
|
45
|
-
[MissionState.SPEC_CONFIRMED]: [MissionState.IN_PROGRESS, MissionState.PAUSED, MissionState.CANCELLED, MissionState.FAILED],
|
|
46
|
-
[MissionState.IN_PROGRESS]: [MissionState.REVIEW, MissionState.PAUSED, MissionState.CANCELLED, MissionState.FAILED],
|
|
47
|
-
[MissionState.REVIEW]: [MissionState.COMPLETED, MissionState.IN_PROGRESS, MissionState.CANCELLED, MissionState.FAILED],
|
|
48
|
-
[MissionState.PAUSED]: [MissionState.PLANNING, MissionState.IN_PROGRESS, MissionState.CANCELLED, MissionState.FAILED],
|
|
49
|
-
[MissionState.COMPLETED]: [],
|
|
50
|
-
[MissionState.CANCELLED]: [],
|
|
51
|
-
[MissionState.FAILED]: []
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* MissionManager - State machine for goal-oriented development
|
|
56
|
-
*
|
|
57
|
-
* Manages mission lifecycle:
|
|
58
|
-
* created → planning → spec_pending → spec_confirmed → in_progress → review → completed
|
|
59
|
-
*/
|
|
60
|
-
export class MissionManager {
|
|
61
|
-
constructor(options = {}) {
|
|
62
|
-
this.cwd = options.cwd || process.cwd();
|
|
63
|
-
this.missionsDir = join(this.cwd, '.uds', 'missions');
|
|
64
|
-
this.currentMissionFile = join(this.missionsDir, 'current.json');
|
|
65
|
-
this.historyDir = join(this.missionsDir, 'history');
|
|
66
|
-
this.microSpec = new MicroSpec({ cwd: this.cwd });
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Generate unique mission ID
|
|
71
|
-
* @param {string} type - Mission type
|
|
72
|
-
* @returns {string} Mission ID
|
|
73
|
-
*/
|
|
74
|
-
generateId(type) {
|
|
75
|
-
const date = new Date().toISOString().split('T')[0];
|
|
76
|
-
const random = Math.random().toString(36).substring(2, 8);
|
|
77
|
-
return `${type}-${date}-${random}`;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Create a new mission
|
|
82
|
-
* @param {string} type - Mission type (genesis, renovate, medic, exodus, guardian)
|
|
83
|
-
* @param {string} intent - Natural language description of the goal
|
|
84
|
-
* @param {Object} options - Additional options
|
|
85
|
-
* @returns {Object} Created mission object
|
|
86
|
-
*/
|
|
87
|
-
create(type, intent, options = {}) {
|
|
88
|
-
// Validate mission type
|
|
89
|
-
const validTypes = Object.values(MissionType);
|
|
90
|
-
const normalizedType = type.toLowerCase();
|
|
91
|
-
|
|
92
|
-
if (!validTypes.includes(normalizedType)) {
|
|
93
|
-
throw new Error(`Invalid mission type: ${type}. Valid types: ${validTypes.join(', ')}`);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Check for active mission
|
|
97
|
-
const current = this.getCurrent();
|
|
98
|
-
if (current && !this.isTerminalState(current.state)) {
|
|
99
|
-
throw new Error(`Active mission exists: ${current.id}. Complete or cancel it first.`);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Ensure directories exist
|
|
103
|
-
mkdirSync(this.missionsDir, { recursive: true });
|
|
104
|
-
mkdirSync(this.historyDir, { recursive: true });
|
|
105
|
-
|
|
106
|
-
const mission = {
|
|
107
|
-
id: this.generateId(normalizedType),
|
|
108
|
-
type: normalizedType,
|
|
109
|
-
intent,
|
|
110
|
-
state: MissionState.CREATED,
|
|
111
|
-
createdAt: new Date().toISOString(),
|
|
112
|
-
updatedAt: new Date().toISOString(),
|
|
113
|
-
steps: [],
|
|
114
|
-
specs: [],
|
|
115
|
-
checkpoints: [],
|
|
116
|
-
metadata: options.metadata || {}
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
// Save as current mission
|
|
120
|
-
writeFileSync(this.currentMissionFile, JSON.stringify(mission, null, 2));
|
|
121
|
-
|
|
122
|
-
return mission;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Get current active mission
|
|
127
|
-
* @returns {Object|null} Current mission or null
|
|
128
|
-
*/
|
|
129
|
-
getCurrent() {
|
|
130
|
-
if (!existsSync(this.currentMissionFile)) {
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
return JSON.parse(readFileSync(this.currentMissionFile, 'utf8'));
|
|
136
|
-
} catch {
|
|
137
|
-
return null;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Get mission by ID from history
|
|
143
|
-
* @param {string} id - Mission ID
|
|
144
|
-
* @returns {Object|null} Mission or null
|
|
145
|
-
*/
|
|
146
|
-
get(id) {
|
|
147
|
-
// Check current mission first
|
|
148
|
-
const current = this.getCurrent();
|
|
149
|
-
if (current && current.id === id) {
|
|
150
|
-
return current;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Check history
|
|
154
|
-
const historyFile = join(this.historyDir, `${id}.json`);
|
|
155
|
-
if (existsSync(historyFile)) {
|
|
156
|
-
try {
|
|
157
|
-
return JSON.parse(readFileSync(historyFile, 'utf8'));
|
|
158
|
-
} catch {
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Check if state is terminal (completed, cancelled, or failed)
|
|
168
|
-
* @param {string} state - Mission state
|
|
169
|
-
* @returns {boolean}
|
|
170
|
-
*/
|
|
171
|
-
isTerminalState(state) {
|
|
172
|
-
return state === MissionState.COMPLETED
|
|
173
|
-
|| state === MissionState.CANCELLED
|
|
174
|
-
|| state === MissionState.FAILED;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Check if transition is valid
|
|
179
|
-
* @param {string} fromState - Current state
|
|
180
|
-
* @param {string} toState - Target state
|
|
181
|
-
* @returns {boolean}
|
|
182
|
-
*/
|
|
183
|
-
canTransition(fromState, toState) {
|
|
184
|
-
const allowedTransitions = STATE_TRANSITIONS[fromState];
|
|
185
|
-
return allowedTransitions && allowedTransitions.includes(toState);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Transition mission to new state
|
|
190
|
-
* @param {string} toState - Target state
|
|
191
|
-
* @param {Object} options - Transition options
|
|
192
|
-
* @returns {Object} Updated mission
|
|
193
|
-
*/
|
|
194
|
-
transition(toState, options = {}) {
|
|
195
|
-
const mission = this.getCurrent();
|
|
196
|
-
if (!mission) {
|
|
197
|
-
throw new Error('No active mission found');
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// Resume guard (T11 / XSPEC-292 §9.2): terminal states are final. A
|
|
201
|
-
// completed / cancelled / failed mission must never be revived — fail
|
|
202
|
-
// loudly instead of silently re-activating an archived mission.
|
|
203
|
-
if (this.isTerminalState(mission.state)) {
|
|
204
|
-
throw new Error(
|
|
205
|
-
`Mission ${mission.id} is in terminal state '${mission.state}' and cannot be transitioned or resumed.`
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (!this.canTransition(mission.state, toState)) {
|
|
210
|
-
throw new Error(
|
|
211
|
-
`Invalid transition: ${mission.state} → ${toState}. ` +
|
|
212
|
-
`Allowed: ${STATE_TRANSITIONS[mission.state].join(', ') || 'none'}`
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const previousState = mission.state;
|
|
217
|
-
mission.state = toState;
|
|
218
|
-
mission.updatedAt = new Date().toISOString();
|
|
219
|
-
|
|
220
|
-
// Add checkpoint
|
|
221
|
-
mission.checkpoints.push({
|
|
222
|
-
timestamp: mission.updatedAt,
|
|
223
|
-
fromState: previousState,
|
|
224
|
-
toState,
|
|
225
|
-
reason: options.reason || '',
|
|
226
|
-
metadata: options.metadata || {}
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
// Handle terminal states
|
|
230
|
-
if (this.isTerminalState(toState)) {
|
|
231
|
-
this.archiveMission(mission);
|
|
232
|
-
} else {
|
|
233
|
-
writeFileSync(this.currentMissionFile, JSON.stringify(mission, null, 2));
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return mission;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Archive completed/cancelled mission to history
|
|
241
|
-
* @param {Object} mission - Mission to archive
|
|
242
|
-
*/
|
|
243
|
-
archiveMission(mission) {
|
|
244
|
-
mkdirSync(this.historyDir, { recursive: true });
|
|
245
|
-
|
|
246
|
-
const historyFile = join(this.historyDir, `${mission.id}.json`);
|
|
247
|
-
writeFileSync(historyFile, JSON.stringify(mission, null, 2));
|
|
248
|
-
|
|
249
|
-
// Remove current mission file
|
|
250
|
-
if (existsSync(this.currentMissionFile)) {
|
|
251
|
-
unlinkSync(this.currentMissionFile);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Add a step to the current mission
|
|
257
|
-
* @param {Object} step - Step object
|
|
258
|
-
* @returns {Object} Updated mission
|
|
259
|
-
*/
|
|
260
|
-
addStep(step) {
|
|
261
|
-
const mission = this.getCurrent();
|
|
262
|
-
if (!mission) {
|
|
263
|
-
throw new Error('No active mission found');
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const stepWithId = {
|
|
267
|
-
id: `step-${mission.steps.length + 1}`,
|
|
268
|
-
createdAt: new Date().toISOString(),
|
|
269
|
-
status: 'pending',
|
|
270
|
-
...step
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
mission.steps.push(stepWithId);
|
|
274
|
-
mission.updatedAt = new Date().toISOString();
|
|
275
|
-
writeFileSync(this.currentMissionFile, JSON.stringify(mission, null, 2));
|
|
276
|
-
|
|
277
|
-
return mission;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Update step status
|
|
282
|
-
* @param {string} stepId - Step ID
|
|
283
|
-
* @param {string} status - New status (pending, in_progress, completed, failed)
|
|
284
|
-
* @param {Object} result - Optional result data
|
|
285
|
-
* @returns {Object} Updated mission
|
|
286
|
-
*/
|
|
287
|
-
updateStep(stepId, status, result = null) {
|
|
288
|
-
const mission = this.getCurrent();
|
|
289
|
-
if (!mission) {
|
|
290
|
-
throw new Error('No active mission found');
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
const step = mission.steps.find(s => s.id === stepId);
|
|
294
|
-
if (!step) {
|
|
295
|
-
throw new Error(`Step not found: ${stepId}`);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
step.status = status;
|
|
299
|
-
step.updatedAt = new Date().toISOString();
|
|
300
|
-
if (result) {
|
|
301
|
-
step.result = result;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
mission.updatedAt = new Date().toISOString();
|
|
305
|
-
writeFileSync(this.currentMissionFile, JSON.stringify(mission, null, 2));
|
|
306
|
-
|
|
307
|
-
return mission;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Link a micro-spec to the mission
|
|
312
|
-
* @param {string} specId - Micro-spec ID
|
|
313
|
-
* @returns {Object} Updated mission
|
|
314
|
-
*/
|
|
315
|
-
linkSpec(specId) {
|
|
316
|
-
const mission = this.getCurrent();
|
|
317
|
-
if (!mission) {
|
|
318
|
-
throw new Error('No active mission found');
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// Verify spec exists
|
|
322
|
-
const spec = this.microSpec.get(specId);
|
|
323
|
-
if (!spec) {
|
|
324
|
-
throw new Error(`Micro-spec not found: ${specId}`);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
if (!mission.specs.includes(specId)) {
|
|
328
|
-
mission.specs.push(specId);
|
|
329
|
-
mission.updatedAt = new Date().toISOString();
|
|
330
|
-
writeFileSync(this.currentMissionFile, JSON.stringify(mission, null, 2));
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
return mission;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* Get mission status summary
|
|
338
|
-
* @returns {Object} Status summary
|
|
339
|
-
*/
|
|
340
|
-
getStatus() {
|
|
341
|
-
const mission = this.getCurrent();
|
|
342
|
-
if (!mission) {
|
|
343
|
-
return {
|
|
344
|
-
active: false,
|
|
345
|
-
message: 'No active mission'
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
const completedSteps = mission.steps.filter(s => s.status === 'completed').length;
|
|
350
|
-
const totalSteps = mission.steps.length;
|
|
351
|
-
|
|
352
|
-
return {
|
|
353
|
-
active: true,
|
|
354
|
-
id: mission.id,
|
|
355
|
-
type: mission.type,
|
|
356
|
-
state: mission.state,
|
|
357
|
-
intent: mission.intent,
|
|
358
|
-
progress: totalSteps > 0 ? `${completedSteps}/${totalSteps} steps` : 'No steps defined',
|
|
359
|
-
specs: mission.specs.length,
|
|
360
|
-
startedAt: mission.createdAt,
|
|
361
|
-
lastUpdate: mission.updatedAt
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* List all missions from history
|
|
367
|
-
* @param {Object} options - Filter options
|
|
368
|
-
* @returns {Array} List of missions
|
|
369
|
-
*/
|
|
370
|
-
list(options = {}) {
|
|
371
|
-
const missions = [];
|
|
372
|
-
|
|
373
|
-
// Add current mission if exists
|
|
374
|
-
const current = this.getCurrent();
|
|
375
|
-
if (current) {
|
|
376
|
-
missions.push({ ...current, isCurrent: true });
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// Add historical missions
|
|
380
|
-
if (existsSync(this.historyDir)) {
|
|
381
|
-
const files = readdirSync(this.historyDir);
|
|
382
|
-
for (const file of files) {
|
|
383
|
-
if (file.endsWith('.json')) {
|
|
384
|
-
try {
|
|
385
|
-
const mission = JSON.parse(readFileSync(join(this.historyDir, file), 'utf8'));
|
|
386
|
-
missions.push({ ...mission, isCurrent: false });
|
|
387
|
-
} catch {
|
|
388
|
-
// Skip invalid files
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
// Apply filters
|
|
395
|
-
let filtered = missions;
|
|
396
|
-
|
|
397
|
-
if (options.type) {
|
|
398
|
-
filtered = filtered.filter(m => m.type === options.type);
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
if (options.state) {
|
|
402
|
-
filtered = filtered.filter(m => m.state === options.state);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
// Sort by creation date (newest first)
|
|
406
|
-
filtered.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt));
|
|
407
|
-
|
|
408
|
-
return filtered;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* Pause current mission
|
|
413
|
-
* @param {string} reason - Reason for pausing
|
|
414
|
-
* @returns {Object} Updated mission
|
|
415
|
-
*/
|
|
416
|
-
pause(reason = '') {
|
|
417
|
-
return this.transition(MissionState.PAUSED, { reason });
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
/**
|
|
421
|
-
* Resume paused mission
|
|
422
|
-
* @returns {Object} Updated mission
|
|
423
|
-
*/
|
|
424
|
-
resume() {
|
|
425
|
-
const mission = this.getCurrent();
|
|
426
|
-
if (!mission) {
|
|
427
|
-
throw new Error('No active mission found');
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
if (mission.state !== MissionState.PAUSED) {
|
|
431
|
-
throw new Error('Mission is not paused');
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
// Resume to previous state before pause
|
|
435
|
-
const lastCheckpoint = [...mission.checkpoints].reverse().find(
|
|
436
|
-
cp => cp.toState === MissionState.PAUSED
|
|
437
|
-
);
|
|
438
|
-
|
|
439
|
-
const resumeState = lastCheckpoint?.fromState || MissionState.PLANNING;
|
|
440
|
-
return this.transition(resumeState, { reason: 'Resumed from pause' });
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
/**
|
|
444
|
-
* Cancel current mission
|
|
445
|
-
* @param {string} reason - Reason for cancellation
|
|
446
|
-
* @returns {Object} Cancelled mission
|
|
447
|
-
*/
|
|
448
|
-
cancel(reason = '') {
|
|
449
|
-
return this.transition(MissionState.CANCELLED, { reason });
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* Mark current mission as FAILED (terminal).
|
|
454
|
-
*
|
|
455
|
-
* Used when a mission cannot proceed — an unrecoverable error or an abandoned
|
|
456
|
-
* run. Unlike {@link pause}, a failed mission is archived to history and can
|
|
457
|
-
* never be resumed (see the resume guard in {@link transition}).
|
|
458
|
-
*
|
|
459
|
-
* @param {string} reason - Reason for the failure
|
|
460
|
-
* @returns {Object} Failed mission
|
|
461
|
-
*/
|
|
462
|
-
fail(reason = '') {
|
|
463
|
-
return this.transition(MissionState.FAILED, { reason });
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
* Complete current mission
|
|
468
|
-
* @param {Object} summary - Completion summary
|
|
469
|
-
* @returns {Object} Completed mission
|
|
470
|
-
*/
|
|
471
|
-
complete(summary = {}) {
|
|
472
|
-
const mission = this.getCurrent();
|
|
473
|
-
if (!mission) {
|
|
474
|
-
throw new Error('No active mission found');
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
// Must be in review state to complete
|
|
478
|
-
if (mission.state !== MissionState.REVIEW) {
|
|
479
|
-
throw new Error('Mission must be in review state to complete');
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
mission.completionSummary = {
|
|
483
|
-
...summary,
|
|
484
|
-
completedAt: new Date().toISOString()
|
|
485
|
-
};
|
|
486
|
-
|
|
487
|
-
return this.transition(MissionState.COMPLETED, {
|
|
488
|
-
reason: summary.notes || 'Mission completed'
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
/**
|
|
493
|
-
* Get workflow suggestions based on mission type
|
|
494
|
-
* @param {string} type - Mission type
|
|
495
|
-
* @returns {Object} Workflow configuration
|
|
496
|
-
*/
|
|
497
|
-
getWorkflowConfig(type) {
|
|
498
|
-
const configs = {
|
|
499
|
-
[MissionType.GENESIS]: {
|
|
500
|
-
steps: ['scaffold', 'setup', 'implement', 'test', 'document'],
|
|
501
|
-
hitlThreshold: 2,
|
|
502
|
-
autoSpec: true,
|
|
503
|
-
description: 'Create a new project from scratch'
|
|
504
|
-
},
|
|
505
|
-
[MissionType.RENOVATE]: {
|
|
506
|
-
steps: ['analyze', 'plan', 'refactor', 'test', 'review'],
|
|
507
|
-
hitlThreshold: 2,
|
|
508
|
-
autoSpec: true,
|
|
509
|
-
description: 'Refactor and improve existing code'
|
|
510
|
-
},
|
|
511
|
-
[MissionType.MEDIC]: {
|
|
512
|
-
steps: ['diagnose', 'reproduce', 'fix', 'verify', 'prevent'],
|
|
513
|
-
hitlThreshold: 1,
|
|
514
|
-
autoSpec: false,
|
|
515
|
-
description: 'Debug and fix issues'
|
|
516
|
-
},
|
|
517
|
-
[MissionType.EXODUS]: {
|
|
518
|
-
steps: ['audit', 'plan', 'migrate', 'validate', 'cleanup'],
|
|
519
|
-
hitlThreshold: 1,
|
|
520
|
-
autoSpec: true,
|
|
521
|
-
description: 'Migrate to new technology/framework'
|
|
522
|
-
},
|
|
523
|
-
[MissionType.GUARDIAN]: {
|
|
524
|
-
steps: ['scan', 'assess', 'remediate', 'verify', 'report'],
|
|
525
|
-
hitlThreshold: 1,
|
|
526
|
-
autoSpec: false,
|
|
527
|
-
description: 'Security audit and compliance check'
|
|
528
|
-
}
|
|
529
|
-
};
|
|
530
|
-
|
|
531
|
-
return configs[type] || null;
|
|
532
|
-
}
|
|
533
|
-
}
|