@hongmaple0820/scale-engine 0.1.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/LICENSE +15 -0
- package/README.md +64 -0
- package/dist/adapters/ClaudeCodeAdapter.d.ts +48 -0
- package/dist/adapters/ClaudeCodeAdapter.js +188 -0
- package/dist/adapters/ClaudeCodeAdapter.js.map +1 -0
- package/dist/adapters/CodexAdapter.d.ts +14 -0
- package/dist/adapters/CodexAdapter.js +153 -0
- package/dist/adapters/CodexAdapter.js.map +1 -0
- package/dist/api/cli.d.ts +2 -0
- package/dist/api/cli.js +396 -0
- package/dist/api/cli.js.map +1 -0
- package/dist/api/doctor.d.ts +28 -0
- package/dist/api/doctor.js +182 -0
- package/dist/api/doctor.js.map +1 -0
- package/dist/api/mcp.d.ts +32 -0
- package/dist/api/mcp.js +227 -0
- package/dist/api/mcp.js.map +1 -0
- package/dist/artifact/fsm.d.ts +36 -0
- package/dist/artifact/fsm.js +199 -0
- package/dist/artifact/fsm.js.map +1 -0
- package/dist/artifact/fsmDefinitions.d.ts +18 -0
- package/dist/artifact/fsmDefinitions.js +243 -0
- package/dist/artifact/fsmDefinitions.js.map +1 -0
- package/dist/artifact/sqliteStore.d.ts +61 -0
- package/dist/artifact/sqliteStore.js +394 -0
- package/dist/artifact/sqliteStore.js.map +1 -0
- package/dist/artifact/store.d.ts +49 -0
- package/dist/artifact/store.js +118 -0
- package/dist/artifact/store.js.map +1 -0
- package/dist/artifact/types.d.ts +333 -0
- package/dist/artifact/types.js +50 -0
- package/dist/artifact/types.js.map +1 -0
- package/dist/context/ContextBuilder.d.ts +36 -0
- package/dist/context/ContextBuilder.js +53 -0
- package/dist/context/ContextBuilder.js.map +1 -0
- package/dist/core/container.d.ts +14 -0
- package/dist/core/container.js +33 -0
- package/dist/core/container.js.map +1 -0
- package/dist/core/eventBus.d.ts +60 -0
- package/dist/core/eventBus.js +158 -0
- package/dist/core/eventBus.js.map +1 -0
- package/dist/core/logger.d.ts +3 -0
- package/dist/core/logger.js +12 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/evolution/BehaviorTracker.d.ts +38 -0
- package/dist/evolution/BehaviorTracker.js +52 -0
- package/dist/evolution/BehaviorTracker.js.map +1 -0
- package/dist/evolution/EvolutionEngine.d.ts +99 -0
- package/dist/evolution/EvolutionEngine.js +321 -0
- package/dist/evolution/EvolutionEngine.js.map +1 -0
- package/dist/guardrails/Gateway.d.ts +26 -0
- package/dist/guardrails/Gateway.js +57 -0
- package/dist/guardrails/Gateway.js.map +1 -0
- package/dist/guardrails/advancedDetectors.d.ts +26 -0
- package/dist/guardrails/advancedDetectors.js +138 -0
- package/dist/guardrails/advancedDetectors.js.map +1 -0
- package/dist/guardrails/detectors.d.ts +25 -0
- package/dist/guardrails/detectors.js +170 -0
- package/dist/guardrails/detectors.js.map +1 -0
- package/dist/guardrails/roles.d.ts +4 -0
- package/dist/guardrails/roles.js +54 -0
- package/dist/guardrails/roles.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/knowledge/KnowledgeBase.d.ts +25 -0
- package/dist/knowledge/KnowledgeBase.js +81 -0
- package/dist/knowledge/KnowledgeBase.js.map +1 -0
- package/dist/orchestration/EffectsWiring.d.ts +8 -0
- package/dist/orchestration/EffectsWiring.js +87 -0
- package/dist/orchestration/EffectsWiring.js.map +1 -0
- package/dist/routing/ModelRouter.d.ts +30 -0
- package/dist/routing/ModelRouter.js +69 -0
- package/dist/routing/ModelRouter.js.map +1 -0
- package/dist/tasks/TaskEngine.d.ts +97 -0
- package/dist/tasks/TaskEngine.js +269 -0
- package/dist/tasks/TaskEngine.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { ArtifactId } from '../artifact/types.js';
|
|
2
|
+
import type { IArtifactStore } from '../artifact/store.js';
|
|
3
|
+
import type { IFSM } from '../artifact/fsm.js';
|
|
4
|
+
import type { IEventBus } from '../core/eventBus.js';
|
|
5
|
+
export interface Checkpoint {
|
|
6
|
+
id: string;
|
|
7
|
+
taskId: ArtifactId;
|
|
8
|
+
timestamp: number;
|
|
9
|
+
state: CheckpointState;
|
|
10
|
+
description?: string;
|
|
11
|
+
canResume: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface CheckpointState {
|
|
14
|
+
context: Record<string, unknown>;
|
|
15
|
+
currentStep: number;
|
|
16
|
+
completedSteps: string[];
|
|
17
|
+
failedSteps: string[];
|
|
18
|
+
}
|
|
19
|
+
export interface TaskStep {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
handler: StepHandler;
|
|
23
|
+
timeout?: number;
|
|
24
|
+
retries?: number;
|
|
25
|
+
checkpoint?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export type StepResult = {
|
|
28
|
+
success: true;
|
|
29
|
+
output?: unknown;
|
|
30
|
+
} | {
|
|
31
|
+
success: false;
|
|
32
|
+
error: string;
|
|
33
|
+
retryable?: boolean;
|
|
34
|
+
};
|
|
35
|
+
export type StepHandler = (ctx: StepContext) => Promise<StepResult>;
|
|
36
|
+
export interface StepContext {
|
|
37
|
+
taskId: ArtifactId;
|
|
38
|
+
stepId: string;
|
|
39
|
+
stepIndex: number;
|
|
40
|
+
get: (key: string) => unknown;
|
|
41
|
+
set: (key: string, value: unknown) => void;
|
|
42
|
+
emit: (type: string, payload: unknown) => void;
|
|
43
|
+
log: (msg: string) => void;
|
|
44
|
+
}
|
|
45
|
+
export interface TaskDecomposition {
|
|
46
|
+
parentTaskId: ArtifactId;
|
|
47
|
+
subtasks: Array<{
|
|
48
|
+
title: string;
|
|
49
|
+
payload: unknown;
|
|
50
|
+
dependencies?: string[];
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
53
|
+
export interface ITaskEngine {
|
|
54
|
+
schedule(taskId: ArtifactId): Promise<void>;
|
|
55
|
+
execute(taskId: ArtifactId, steps?: TaskStep[]): Promise<ExecutionResult>;
|
|
56
|
+
pause(taskId: ArtifactId, reason: string): Promise<void>;
|
|
57
|
+
resume(taskId: ArtifactId, steps?: TaskStep[]): Promise<ExecutionResult>;
|
|
58
|
+
cancel(taskId: ArtifactId, reason: string): Promise<void>;
|
|
59
|
+
checkpoint(taskId: ArtifactId, label?: string): Promise<Checkpoint>;
|
|
60
|
+
restoreFromCheckpoint(taskId: ArtifactId, checkpointId?: string): Promise<CheckpointState>;
|
|
61
|
+
decompose(decomposition: TaskDecomposition): Promise<ArtifactId[]>;
|
|
62
|
+
getContext(taskId: ArtifactId): Record<string, unknown>;
|
|
63
|
+
setContext(taskId: ArtifactId, key: string, value: unknown): void;
|
|
64
|
+
}
|
|
65
|
+
export interface ExecutionResult {
|
|
66
|
+
taskId: ArtifactId;
|
|
67
|
+
success: boolean;
|
|
68
|
+
completedSteps: string[];
|
|
69
|
+
failedStep?: string;
|
|
70
|
+
error?: string;
|
|
71
|
+
duration: number;
|
|
72
|
+
}
|
|
73
|
+
export declare class TaskEngine implements ITaskEngine {
|
|
74
|
+
private store;
|
|
75
|
+
private fsm;
|
|
76
|
+
private eventBus;
|
|
77
|
+
private runtimes;
|
|
78
|
+
private checkpointsDir;
|
|
79
|
+
constructor(store: IArtifactStore, fsm: IFSM, eventBus: IEventBus, opts?: {
|
|
80
|
+
checkpointsDir?: string;
|
|
81
|
+
});
|
|
82
|
+
schedule(taskId: ArtifactId): Promise<void>;
|
|
83
|
+
execute(taskId: ArtifactId, steps?: TaskStep[]): Promise<ExecutionResult>;
|
|
84
|
+
pause(taskId: ArtifactId, reason: string): Promise<void>;
|
|
85
|
+
resume(taskId: ArtifactId, steps?: TaskStep[]): Promise<ExecutionResult>;
|
|
86
|
+
cancel(taskId: ArtifactId, reason: string): Promise<void>;
|
|
87
|
+
checkpoint(taskId: ArtifactId, label?: string): Promise<Checkpoint>;
|
|
88
|
+
restoreFromCheckpoint(taskId: ArtifactId, checkpointId?: string): Promise<CheckpointState>;
|
|
89
|
+
decompose(decomposition: TaskDecomposition): Promise<ArtifactId[]>;
|
|
90
|
+
getContext(taskId: ArtifactId): Record<string, unknown>;
|
|
91
|
+
setContext(taskId: ArtifactId, key: string, value: unknown): void;
|
|
92
|
+
private getOrCreateRuntime;
|
|
93
|
+
private executeStep;
|
|
94
|
+
private timeoutPromise;
|
|
95
|
+
/** resume 后继续执行剩余步骤(不再走 start transition) */
|
|
96
|
+
private executeFromRuntime;
|
|
97
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// SCALE Engine — Task Engine (W4 完整实现)
|
|
2
|
+
// 长时任务: 步骤执行 + Checkpoint + Resume + 超时熔断 + 子任务分解
|
|
3
|
+
// 设计参考:docs/03-CORE-MODULES.md §3.3
|
|
4
|
+
import { logger } from '../core/logger.js';
|
|
5
|
+
import { writeFileSync, readFileSync, mkdirSync, existsSync, readdirSync } from 'node:fs';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
const SYSTEM_ACTOR = { kind: 'system', component: 'TaskEngine' };
|
|
8
|
+
const DEFAULT_STEP_TIMEOUT = 5 * 60 * 1000; // 5 minutes
|
|
9
|
+
const MAX_STEP_TIMEOUT = 30 * 60 * 1000; // 30 minutes
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// TaskEngine
|
|
12
|
+
// ============================================================================
|
|
13
|
+
export class TaskEngine {
|
|
14
|
+
store;
|
|
15
|
+
fsm;
|
|
16
|
+
eventBus;
|
|
17
|
+
runtimes = new Map();
|
|
18
|
+
checkpointsDir;
|
|
19
|
+
constructor(store, fsm, eventBus, opts = {}) {
|
|
20
|
+
this.store = store;
|
|
21
|
+
this.fsm = fsm;
|
|
22
|
+
this.eventBus = eventBus;
|
|
23
|
+
this.checkpointsDir = opts.checkpointsDir ?? '.scale/checkpoints';
|
|
24
|
+
if (!existsSync(this.checkpointsDir))
|
|
25
|
+
mkdirSync(this.checkpointsDir, { recursive: true });
|
|
26
|
+
}
|
|
27
|
+
// ===== Schedule =====
|
|
28
|
+
async schedule(taskId) {
|
|
29
|
+
await this.fsm.transition(taskId, 'schedule', { actor: SYSTEM_ACTOR });
|
|
30
|
+
this.runtimes.set(taskId, { context: {}, currentStep: 0, completedSteps: [], failedSteps: [] });
|
|
31
|
+
this.eventBus.emit('task.scheduled', { taskId }, { artifactId: taskId });
|
|
32
|
+
}
|
|
33
|
+
// ===== Execute =====
|
|
34
|
+
async execute(taskId, steps = []) {
|
|
35
|
+
const startTime = Date.now();
|
|
36
|
+
// 确保 task 在 READY 状态
|
|
37
|
+
const task = await this.store.get(taskId);
|
|
38
|
+
if (!task)
|
|
39
|
+
throw new Error(`Task not found: ${taskId}`);
|
|
40
|
+
// READY → RUNNING
|
|
41
|
+
await this.fsm.transition(taskId, 'start', { actor: SYSTEM_ACTOR });
|
|
42
|
+
this.eventBus.emit('task.started', { taskId, stepCount: steps.length }, { artifactId: taskId });
|
|
43
|
+
// 获取或创建运行时
|
|
44
|
+
const runtime = this.getOrCreateRuntime(taskId);
|
|
45
|
+
// 如果 resume,从上次的 currentStep 继续
|
|
46
|
+
const startStep = runtime.currentStep;
|
|
47
|
+
// 逐步执行
|
|
48
|
+
for (let i = startStep; i < steps.length; i++) {
|
|
49
|
+
const step = steps[i];
|
|
50
|
+
runtime.currentStep = i;
|
|
51
|
+
logger.info({ taskId, step: step.id, index: i }, 'Executing step');
|
|
52
|
+
this.eventBus.emit('task.step_started', { taskId, stepId: step.id, index: i }, { artifactId: taskId });
|
|
53
|
+
// 执行步骤(带超时和重试)
|
|
54
|
+
const result = await this.executeStep(taskId, step, runtime);
|
|
55
|
+
if (result.success) {
|
|
56
|
+
runtime.completedSteps.push(step.id);
|
|
57
|
+
this.eventBus.emit('task.step_completed', { taskId, stepId: step.id, output: result.output }, { artifactId: taskId });
|
|
58
|
+
// 自动 checkpoint(默认开启)
|
|
59
|
+
if (step.checkpoint !== false) {
|
|
60
|
+
await this.checkpoint(taskId, `after-${step.id}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
runtime.failedSteps.push(step.id);
|
|
65
|
+
this.eventBus.emit('task.step_failed', { taskId, stepId: step.id, error: result.error }, { artifactId: taskId });
|
|
66
|
+
// 步骤失败 → 整个任务 fail
|
|
67
|
+
await this.fsm.transition(taskId, 'fail', { actor: SYSTEM_ACTOR, reason: result.error });
|
|
68
|
+
this.eventBus.emit('task.failed', { taskId, stepId: step.id, error: result.error }, { artifactId: taskId });
|
|
69
|
+
return {
|
|
70
|
+
taskId,
|
|
71
|
+
success: false,
|
|
72
|
+
completedSteps: [...runtime.completedSteps],
|
|
73
|
+
failedStep: step.id,
|
|
74
|
+
error: result.error,
|
|
75
|
+
duration: Date.now() - startTime,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// 所有步骤通过 → complete
|
|
80
|
+
runtime.currentStep = steps.length;
|
|
81
|
+
await this.fsm.transition(taskId, 'complete', { actor: SYSTEM_ACTOR });
|
|
82
|
+
this.eventBus.emit('task.completed', { taskId, stepCount: steps.length }, { artifactId: taskId });
|
|
83
|
+
return {
|
|
84
|
+
taskId,
|
|
85
|
+
success: true,
|
|
86
|
+
completedSteps: [...runtime.completedSteps],
|
|
87
|
+
duration: Date.now() - startTime,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// ===== Pause / Resume / Cancel =====
|
|
91
|
+
async pause(taskId, reason) {
|
|
92
|
+
await this.checkpoint(taskId, 'auto-pause');
|
|
93
|
+
await this.fsm.transition(taskId, 'pause', { actor: SYSTEM_ACTOR, reason });
|
|
94
|
+
this.eventBus.emit('task.paused', { taskId, reason }, { artifactId: taskId });
|
|
95
|
+
}
|
|
96
|
+
async resume(taskId, steps = []) {
|
|
97
|
+
const state = await this.restoreFromCheckpoint(taskId);
|
|
98
|
+
// 注回运行时
|
|
99
|
+
this.runtimes.set(taskId, state);
|
|
100
|
+
await this.fsm.transition(taskId, 'resume', { actor: SYSTEM_ACTOR });
|
|
101
|
+
this.eventBus.emit('task.resumed', { taskId, fromStep: state.currentStep }, { artifactId: taskId });
|
|
102
|
+
// 继续从断点执行(FSM: RUNNING → 继续步骤循环)
|
|
103
|
+
// resume 后 task 回到 RUNNING,但 execute 需要 READY→RUNNING
|
|
104
|
+
// 所以这里直接走步骤循环
|
|
105
|
+
return this.executeFromRuntime(taskId, steps, state);
|
|
106
|
+
}
|
|
107
|
+
async cancel(taskId, reason) {
|
|
108
|
+
await this.fsm.transition(taskId, 'cancel', { actor: SYSTEM_ACTOR, reason });
|
|
109
|
+
this.runtimes.delete(taskId);
|
|
110
|
+
this.eventBus.emit('task.cancelled', { taskId, reason }, { artifactId: taskId });
|
|
111
|
+
}
|
|
112
|
+
// ===== Checkpoint =====
|
|
113
|
+
async checkpoint(taskId, label) {
|
|
114
|
+
const runtime = this.runtimes.get(taskId) ?? { context: {}, currentStep: 0, completedSteps: [], failedSteps: [] };
|
|
115
|
+
const checkpoint = {
|
|
116
|
+
id: `CKP-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
|
|
117
|
+
taskId,
|
|
118
|
+
timestamp: Date.now(),
|
|
119
|
+
state: {
|
|
120
|
+
context: { ...runtime.context },
|
|
121
|
+
currentStep: runtime.currentStep,
|
|
122
|
+
completedSteps: [...runtime.completedSteps],
|
|
123
|
+
failedSteps: [...runtime.failedSteps],
|
|
124
|
+
},
|
|
125
|
+
description: label,
|
|
126
|
+
canResume: true,
|
|
127
|
+
};
|
|
128
|
+
const dir = join(this.checkpointsDir, taskId);
|
|
129
|
+
mkdirSync(dir, { recursive: true });
|
|
130
|
+
writeFileSync(join(dir, `${checkpoint.id}.json`), JSON.stringify(checkpoint, null, 2));
|
|
131
|
+
this.eventBus.emit('task.checkpointed', { taskId, checkpointId: checkpoint.id, label }, { artifactId: taskId });
|
|
132
|
+
logger.info({ taskId, checkpointId: checkpoint.id, label }, 'Checkpoint saved');
|
|
133
|
+
return checkpoint;
|
|
134
|
+
}
|
|
135
|
+
async restoreFromCheckpoint(taskId, checkpointId) {
|
|
136
|
+
const dir = join(this.checkpointsDir, taskId);
|
|
137
|
+
if (!existsSync(dir))
|
|
138
|
+
throw new Error(`No checkpoints for task ${taskId}`);
|
|
139
|
+
let file;
|
|
140
|
+
if (checkpointId) {
|
|
141
|
+
file = `${checkpointId}.json`;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
// 找最新的
|
|
145
|
+
const files = readdirSync(dir).filter((f) => f.endsWith('.json')).sort();
|
|
146
|
+
const latest = files.pop();
|
|
147
|
+
if (!latest)
|
|
148
|
+
throw new Error(`No checkpoint files found for task ${taskId}`);
|
|
149
|
+
file = latest;
|
|
150
|
+
}
|
|
151
|
+
const data = JSON.parse(readFileSync(join(dir, file), 'utf-8'));
|
|
152
|
+
if (!data.canResume)
|
|
153
|
+
throw new Error(`Checkpoint ${data.id} is not resumable`);
|
|
154
|
+
this.runtimes.set(taskId, { ...data.state });
|
|
155
|
+
this.eventBus.emit('task.restored', { taskId, checkpointId: data.id }, { artifactId: taskId });
|
|
156
|
+
logger.info({ taskId, checkpointId: data.id, currentStep: data.state.currentStep }, 'Checkpoint restored');
|
|
157
|
+
return data.state;
|
|
158
|
+
}
|
|
159
|
+
// ===== Decompose =====
|
|
160
|
+
async decompose(decomposition) {
|
|
161
|
+
const { parentTaskId, subtasks } = decomposition;
|
|
162
|
+
const ids = [];
|
|
163
|
+
for (const sub of subtasks) {
|
|
164
|
+
const artifact = await this.store.create({
|
|
165
|
+
type: 'Task',
|
|
166
|
+
title: sub.title,
|
|
167
|
+
payload: { ...sub.payload, dependencies: sub.dependencies },
|
|
168
|
+
parents: [parentTaskId],
|
|
169
|
+
initialStatus: 'PENDING',
|
|
170
|
+
createdBy: SYSTEM_ACTOR,
|
|
171
|
+
});
|
|
172
|
+
ids.push(artifact.id);
|
|
173
|
+
}
|
|
174
|
+
this.eventBus.emit('task.decomposed', {
|
|
175
|
+
parentTaskId,
|
|
176
|
+
subtaskIds: ids,
|
|
177
|
+
count: ids.length,
|
|
178
|
+
}, { artifactId: parentTaskId });
|
|
179
|
+
logger.info({ parentTaskId, subtaskCount: ids.length }, 'Task decomposed');
|
|
180
|
+
return ids;
|
|
181
|
+
}
|
|
182
|
+
// ===== Context =====
|
|
183
|
+
getContext(taskId) {
|
|
184
|
+
const runtime = this.runtimes.get(taskId);
|
|
185
|
+
return runtime ? { ...runtime.context } : {};
|
|
186
|
+
}
|
|
187
|
+
setContext(taskId, key, value) {
|
|
188
|
+
const runtime = this.getOrCreateRuntime(taskId);
|
|
189
|
+
runtime.context[key] = value;
|
|
190
|
+
}
|
|
191
|
+
// ===== Internal =====
|
|
192
|
+
getOrCreateRuntime(taskId) {
|
|
193
|
+
let runtime = this.runtimes.get(taskId);
|
|
194
|
+
if (!runtime) {
|
|
195
|
+
runtime = { context: {}, currentStep: 0, completedSteps: [], failedSteps: [] };
|
|
196
|
+
this.runtimes.set(taskId, runtime);
|
|
197
|
+
}
|
|
198
|
+
return runtime;
|
|
199
|
+
}
|
|
200
|
+
async executeStep(taskId, step, runtime) {
|
|
201
|
+
const timeout = Math.min(step.timeout ?? DEFAULT_STEP_TIMEOUT, MAX_STEP_TIMEOUT);
|
|
202
|
+
const maxRetries = step.retries ?? 0;
|
|
203
|
+
const ctx = {
|
|
204
|
+
taskId,
|
|
205
|
+
stepId: step.id,
|
|
206
|
+
stepIndex: runtime.currentStep,
|
|
207
|
+
get: (key) => runtime.context[key],
|
|
208
|
+
set: (key, value) => { runtime.context[key] = value; },
|
|
209
|
+
emit: (type, payload) => {
|
|
210
|
+
this.eventBus.emit(`task.custom.${type}`, { taskId, stepId: step.id, ...payload }, { artifactId: taskId });
|
|
211
|
+
},
|
|
212
|
+
log: (msg) => { logger.info({ taskId, step: step.id }, msg); },
|
|
213
|
+
};
|
|
214
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
215
|
+
try {
|
|
216
|
+
const result = await Promise.race([
|
|
217
|
+
step.handler(ctx),
|
|
218
|
+
this.timeoutPromise(timeout, step.id),
|
|
219
|
+
]);
|
|
220
|
+
if (result.success || !result.retryable || attempt === maxRetries) {
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
223
|
+
logger.warn({ taskId, step: step.id, attempt: attempt + 1 }, 'Step failed, retrying...');
|
|
224
|
+
this.eventBus.emit('task.step_retrying', { taskId, step: step.id, attempt: attempt + 1 }, { artifactId: taskId });
|
|
225
|
+
}
|
|
226
|
+
catch (err) {
|
|
227
|
+
if (attempt === maxRetries) {
|
|
228
|
+
return { success: false, error: err instanceof Error ? err.message : String(err) };
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return { success: false, error: 'Exhausted retries' };
|
|
233
|
+
}
|
|
234
|
+
timeoutPromise(ms, stepId) {
|
|
235
|
+
return new Promise((_, reject) => {
|
|
236
|
+
setTimeout(() => reject(new Error(`Step ${stepId} timed out after ${ms}ms`)), ms);
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
/** resume 后继续执行剩余步骤(不再走 start transition) */
|
|
240
|
+
async executeFromRuntime(taskId, steps, state) {
|
|
241
|
+
const startTime = Date.now();
|
|
242
|
+
const runtime = this.getOrCreateRuntime(taskId);
|
|
243
|
+
for (let i = state.currentStep; i < steps.length; i++) {
|
|
244
|
+
const step = steps[i];
|
|
245
|
+
runtime.currentStep = i;
|
|
246
|
+
this.eventBus.emit('task.step_started', { taskId, stepId: step.id, index: i }, { artifactId: taskId });
|
|
247
|
+
const result = await this.executeStep(taskId, step, runtime);
|
|
248
|
+
if (result.success) {
|
|
249
|
+
runtime.completedSteps.push(step.id);
|
|
250
|
+
if (step.checkpoint !== false)
|
|
251
|
+
await this.checkpoint(taskId, `after-${step.id}`);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
runtime.failedSteps.push(step.id);
|
|
255
|
+
await this.fsm.transition(taskId, 'fail', { actor: SYSTEM_ACTOR, reason: result.error });
|
|
256
|
+
return {
|
|
257
|
+
taskId, success: false, completedSteps: [...runtime.completedSteps],
|
|
258
|
+
failedStep: step.id, error: result.error, duration: Date.now() - startTime,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
runtime.currentStep = steps.length;
|
|
263
|
+
await this.fsm.transition(taskId, 'complete', { actor: SYSTEM_ACTOR });
|
|
264
|
+
return {
|
|
265
|
+
taskId, success: true, completedSteps: [...runtime.completedSteps], duration: Date.now() - startTime,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
//# sourceMappingURL=TaskEngine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TaskEngine.js","sourceRoot":"","sources":["../../src/tasks/TaskEngine.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kDAAkD;AAClD,oCAAoC;AAMpC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACzF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAmFhC,MAAM,YAAY,GAAG,EAAE,IAAI,EAAE,QAAiB,EAAE,SAAS,EAAE,YAAY,EAAE,CAAA;AACzE,MAAM,oBAAoB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAA,CAAC,YAAY;AACvD,MAAM,gBAAgB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA,CAAK,aAAa;AAEzD,+EAA+E;AAC/E,aAAa;AACb,+EAA+E;AAE/E,MAAM,OAAO,UAAU;IAKX;IACA;IACA;IANF,QAAQ,GAAG,IAAI,GAAG,EAA4B,CAAA;IAC9C,cAAc,CAAQ;IAE9B,YACU,KAAqB,EACrB,GAAS,EACT,QAAmB,EAC3B,OAAoC,EAAE;QAH9B,UAAK,GAAL,KAAK,CAAgB;QACrB,QAAG,GAAH,GAAG,CAAM;QACT,aAAQ,GAAR,QAAQ,CAAW;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MAAM,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;gBACxF,OAAO;oBACL,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC;oBACnE,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;iBAC3E,CAAA;YACH,CAAC;QACH,CAAC;QAED,OAAO,CAAC,WAAW,GAAG,KAAK,CAAC,MAAM,CAAA;QAClC,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,CAAA;QAEtE,OAAO;YACL,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;SACrG,CAAA;IACH,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hongmaple0820/scale-engine",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "AI engineering scaffold engine: artifacts, FSM, guardrails, knowledge, evolution",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"scale": "./dist/api/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"dev": "bun --watch src/api/cli.ts",
|
|
17
|
+
"test": "vitest",
|
|
18
|
+
"typecheck": "tsc --noEmit",
|
|
19
|
+
"lint": "eslint src/**/*.ts",
|
|
20
|
+
"mcp": "node dist/api/mcp.js",
|
|
21
|
+
"serve": "node dist/api/http.js"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
25
|
+
"better-sqlite3": "^11.10.0",
|
|
26
|
+
"chokidar": "^3.6.0",
|
|
27
|
+
"citty": "^0.1.6",
|
|
28
|
+
"drizzle-orm": "^0.32.2",
|
|
29
|
+
"execa": "^9.3.0",
|
|
30
|
+
"hono": "^4.5.0",
|
|
31
|
+
"js-yaml": "^4.1.0",
|
|
32
|
+
"pino": "^9.3.0",
|
|
33
|
+
"pino-pretty": "^11.2.0",
|
|
34
|
+
"zod": "^3.23.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/better-sqlite3": "^7.6.0",
|
|
38
|
+
"@types/js-yaml": "^4.0.9",
|
|
39
|
+
"@types/node": "^20.14.0",
|
|
40
|
+
"eslint": "^9.0.0",
|
|
41
|
+
"tsx": "^4.21.0",
|
|
42
|
+
"typescript": "^5.5.0",
|
|
43
|
+
"vitest": "^2.0.0"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=20.0.0"
|
|
47
|
+
}
|
|
48
|
+
}
|