@hongmaple0820/scale-engine 0.33.0 → 0.38.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/README.en.md +86 -376
- package/README.md +89 -549
- package/dist/api/cli.js +185 -12
- package/dist/api/cli.js.map +1 -1
- package/dist/api/doctor.d.ts +38 -3
- package/dist/api/doctor.js +269 -44
- package/dist/api/doctor.js.map +1 -1
- package/dist/api/mcp.js +2 -2
- package/dist/api/mcp.js.map +1 -1
- package/dist/api/quickstart.d.ts +34 -4
- package/dist/api/quickstart.js +90 -73
- package/dist/api/quickstart.js.map +1 -1
- package/dist/bootstrap/DependencyBootstrap.d.ts +89 -0
- package/dist/bootstrap/DependencyBootstrap.js +441 -0
- package/dist/bootstrap/DependencyBootstrap.js.map +1 -0
- package/dist/capabilities/InstalledSkillsIntegration.js +14 -6
- package/dist/capabilities/InstalledSkillsIntegration.js.map +1 -1
- package/dist/codegraph/CodeIntelligence.d.ts +12 -0
- package/dist/codegraph/CodeIntelligence.js +251 -30
- package/dist/codegraph/CodeIntelligence.js.map +1 -1
- package/dist/config/profiles.d.ts +12 -0
- package/dist/config/profiles.js +39 -4
- package/dist/config/profiles.js.map +1 -1
- package/dist/core/ExternalCommand.d.ts +9 -0
- package/dist/core/ExternalCommand.js +56 -0
- package/dist/core/ExternalCommand.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/knowledge/CerebrumManager.d.ts +2 -2
- package/dist/knowledge/CerebrumManager.js.map +1 -1
- package/dist/knowledge/GraphifyKnowledgeBase.d.ts +38 -0
- package/dist/knowledge/GraphifyKnowledgeBase.js +409 -0
- package/dist/knowledge/GraphifyKnowledgeBase.js.map +1 -0
- package/dist/memory/MemoryFabric.js +1 -0
- package/dist/memory/MemoryFabric.js.map +1 -1
- package/dist/memory/MemoryIntelligence.d.ts +42 -0
- package/dist/memory/MemoryIntelligence.js +215 -0
- package/dist/memory/MemoryIntelligence.js.map +1 -0
- package/dist/memory/MemoryProviders.d.ts +22 -0
- package/dist/memory/MemoryProviders.js +138 -5
- package/dist/memory/MemoryProviders.js.map +1 -1
- package/dist/memory/index.d.ts +1 -0
- package/dist/memory/index.js +1 -0
- package/dist/memory/index.js.map +1 -1
- package/dist/runtime/AiOsRuntime.d.ts +2 -0
- package/dist/runtime/AiOsRuntime.js +2 -0
- package/dist/runtime/AiOsRuntime.js.map +1 -1
- package/dist/runtime/ExecutionLedger.d.ts +46 -0
- package/dist/runtime/ExecutionLedger.js +71 -0
- package/dist/runtime/ExecutionLedger.js.map +1 -0
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/index.js.map +1 -1
- package/dist/skills/SkillRepository.js +5 -5
- package/dist/skills/SkillRepository.js.map +1 -1
- package/dist/skills/routing/SkillPolicy.js +2 -2
- package/dist/skills/routing/SkillPolicy.js.map +1 -1
- package/dist/tools/RtkRuntime.d.ts +9 -0
- package/dist/tools/RtkRuntime.js +43 -0
- package/dist/tools/RtkRuntime.js.map +1 -0
- package/dist/tools/ToolCapabilityRegistry.d.ts +1 -0
- package/dist/tools/ToolCapabilityRegistry.js +68 -11
- package/dist/tools/ToolCapabilityRegistry.js.map +1 -1
- package/dist/tools/ToolOrchestrator.js +6 -4
- package/dist/tools/ToolOrchestrator.js.map +1 -1
- package/dist/tools/ToolPolicy.js +16 -1
- package/dist/tools/ToolPolicy.js.map +1 -1
- package/dist/workflow/AdaptiveWorkflowRouter.d.ts +1 -0
- package/dist/workflow/AdaptiveWorkflowRouter.js +3 -0
- package/dist/workflow/AdaptiveWorkflowRouter.js.map +1 -1
- package/dist/workflow/CommitDiscipline.d.ts +68 -0
- package/dist/workflow/CommitDiscipline.js +327 -0
- package/dist/workflow/CommitDiscipline.js.map +1 -0
- package/dist/workflow/CrossRepoOrchestrator.d.ts +92 -0
- package/dist/workflow/CrossRepoOrchestrator.js +400 -0
- package/dist/workflow/CrossRepoOrchestrator.js.map +1 -0
- package/dist/workflow/GovernanceRoi.d.ts +52 -0
- package/dist/workflow/GovernanceRoi.js +204 -0
- package/dist/workflow/GovernanceRoi.js.map +1 -0
- package/dist/workflow/GovernanceTemplates.js +2 -2
- package/dist/workflow/McpGovernance.d.ts +63 -0
- package/dist/workflow/McpGovernance.js +198 -0
- package/dist/workflow/McpGovernance.js.map +1 -0
- package/dist/workflow/SessionCoordinator.d.ts +103 -0
- package/dist/workflow/SessionCoordinator.js +401 -0
- package/dist/workflow/SessionCoordinator.js.map +1 -0
- package/dist/workflow/TaskDependencyGraph.d.ts +73 -0
- package/dist/workflow/TaskDependencyGraph.js +245 -0
- package/dist/workflow/TaskDependencyGraph.js.map +1 -0
- package/dist/workflow/WorkflowTemplates.d.ts +38 -0
- package/dist/workflow/WorkflowTemplates.js +371 -0
- package/dist/workflow/WorkflowTemplates.js.map +1 -0
- package/dist/workflow/WorkspacePolicy.d.ts +46 -0
- package/dist/workflow/WorkspacePolicy.js +141 -0
- package/dist/workflow/WorkspacePolicy.js.map +1 -0
- package/dist/workflow/gates/GateSystem.js +12 -9
- package/dist/workflow/gates/GateSystem.js.map +1 -1
- package/dist/workflow/index.d.ts +7 -0
- package/dist/workflow/index.js +7 -0
- package/dist/workflow/index.js.map +1 -1
- package/docs/CODE_INTELLIGENCE.md +22 -5
- package/docs/EXTERNAL_REFERENCES.md +5 -2
- package/docs/MEMORY_FABRIC.md +7 -3
- package/docs/SKILL-REPOSITORY.md +3 -3
- package/docs/start/quickstart.md +11 -0
- package/docs/workflow/templates/skill-plan.md +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// SCALE Engine — Task Dependency Graph (v0.36.0)
|
|
2
|
+
// Dependency declaration, topological sort, cycle detection for parallel task coordination
|
|
3
|
+
export class TaskDependencyGraph {
|
|
4
|
+
constructor(options = {}) {
|
|
5
|
+
this.nodes = new Map();
|
|
6
|
+
this.edges = [];
|
|
7
|
+
this.maxTasks = options.maxTasks ?? 100;
|
|
8
|
+
}
|
|
9
|
+
addTask(task) {
|
|
10
|
+
if (this.nodes.size >= this.maxTasks && !this.nodes.has(task.taskId)) {
|
|
11
|
+
throw new Error(`Task graph capacity (${this.maxTasks}) reached`);
|
|
12
|
+
}
|
|
13
|
+
this.nodes.set(task.taskId, task);
|
|
14
|
+
}
|
|
15
|
+
removeTask(taskId) {
|
|
16
|
+
this.nodes.delete(taskId);
|
|
17
|
+
this.edges = this.edges.filter(e => e.from !== taskId && e.to !== taskId);
|
|
18
|
+
}
|
|
19
|
+
addDependency(edge) {
|
|
20
|
+
if (!this.nodes.has(edge.from)) {
|
|
21
|
+
return { ok: false, error: `Source task "${edge.from}" not found` };
|
|
22
|
+
}
|
|
23
|
+
if (!this.nodes.has(edge.to)) {
|
|
24
|
+
return { ok: false, error: `Target task "${edge.to}" not found` };
|
|
25
|
+
}
|
|
26
|
+
if (edge.from === edge.to) {
|
|
27
|
+
return { ok: false, error: 'Self-dependency is not allowed' };
|
|
28
|
+
}
|
|
29
|
+
// Check for duplicate
|
|
30
|
+
const exists = this.edges.some(e => e.from === edge.from && e.to === edge.to);
|
|
31
|
+
if (exists)
|
|
32
|
+
return { ok: true };
|
|
33
|
+
// Check if adding this edge creates a cycle
|
|
34
|
+
const cycle = this.detectCycleWithEdge(edge);
|
|
35
|
+
if (cycle) {
|
|
36
|
+
return { ok: false, error: `Dependency creates cycle: ${cycle.join(' → ')}` };
|
|
37
|
+
}
|
|
38
|
+
this.edges.push(edge);
|
|
39
|
+
return { ok: true };
|
|
40
|
+
}
|
|
41
|
+
getTask(taskId) {
|
|
42
|
+
return this.nodes.get(taskId);
|
|
43
|
+
}
|
|
44
|
+
updateTaskStatus(taskId, status) {
|
|
45
|
+
const node = this.nodes.get(taskId);
|
|
46
|
+
if (!node)
|
|
47
|
+
return;
|
|
48
|
+
node.status = status;
|
|
49
|
+
if (status === 'done' || status === 'failed') {
|
|
50
|
+
node.completedAt = new Date().toISOString();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
getDependencies(taskId) {
|
|
54
|
+
return this.edges.filter(e => e.to === taskId);
|
|
55
|
+
}
|
|
56
|
+
getDependents(taskId) {
|
|
57
|
+
return this.edges.filter(e => e.from === taskId);
|
|
58
|
+
}
|
|
59
|
+
getBlockedTasks() {
|
|
60
|
+
const blocked = [];
|
|
61
|
+
for (const [taskId, node] of this.nodes) {
|
|
62
|
+
if (node.status === 'done' || node.status === 'failed')
|
|
63
|
+
continue;
|
|
64
|
+
const deps = this.getDependencies(taskId);
|
|
65
|
+
const waitingFor = [];
|
|
66
|
+
const reason = [];
|
|
67
|
+
for (const dep of deps) {
|
|
68
|
+
const depNode = this.nodes.get(dep.from);
|
|
69
|
+
if (depNode && depNode.status !== 'done') {
|
|
70
|
+
waitingFor.push(dep.from);
|
|
71
|
+
reason.push(`${dep.from} (${depNode.status}): ${dep.reason}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (waitingFor.length > 0) {
|
|
75
|
+
blocked.push({ taskId, waitingFor, reason });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return blocked;
|
|
79
|
+
}
|
|
80
|
+
getReadyTasks() {
|
|
81
|
+
const ready = [];
|
|
82
|
+
for (const [taskId, node] of this.nodes) {
|
|
83
|
+
if (node.status !== 'planned')
|
|
84
|
+
continue;
|
|
85
|
+
const deps = this.getDependencies(taskId);
|
|
86
|
+
const allMet = deps.every(dep => {
|
|
87
|
+
const depNode = this.nodes.get(dep.from);
|
|
88
|
+
return depNode?.status === 'done';
|
|
89
|
+
});
|
|
90
|
+
if (allMet)
|
|
91
|
+
ready.push(taskId);
|
|
92
|
+
}
|
|
93
|
+
return ready;
|
|
94
|
+
}
|
|
95
|
+
topologicalSort() {
|
|
96
|
+
const ids = [...this.nodes.keys()];
|
|
97
|
+
const inDegree = new Map();
|
|
98
|
+
const adjList = new Map();
|
|
99
|
+
for (const id of ids) {
|
|
100
|
+
inDegree.set(id, 0);
|
|
101
|
+
adjList.set(id, []);
|
|
102
|
+
}
|
|
103
|
+
for (const edge of this.edges) {
|
|
104
|
+
adjList.get(edge.from).push(edge.to);
|
|
105
|
+
inDegree.set(edge.to, (inDegree.get(edge.to) ?? 0) + 1);
|
|
106
|
+
}
|
|
107
|
+
// Kahn's algorithm with level tracking
|
|
108
|
+
const queue = [];
|
|
109
|
+
for (const [id, deg] of inDegree) {
|
|
110
|
+
if (deg === 0)
|
|
111
|
+
queue.push(id);
|
|
112
|
+
}
|
|
113
|
+
const order = [];
|
|
114
|
+
const levels = [];
|
|
115
|
+
while (queue.length > 0) {
|
|
116
|
+
const levelSize = queue.length;
|
|
117
|
+
const currentLevel = [];
|
|
118
|
+
for (let i = 0; i < levelSize; i++) {
|
|
119
|
+
const current = queue.shift();
|
|
120
|
+
currentLevel.push(current);
|
|
121
|
+
order.push(current);
|
|
122
|
+
for (const neighbor of adjList.get(current) ?? []) {
|
|
123
|
+
const newDeg = inDegree.get(neighbor) - 1;
|
|
124
|
+
inDegree.set(neighbor, newDeg);
|
|
125
|
+
if (newDeg === 0)
|
|
126
|
+
queue.push(neighbor);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
levels.push(currentLevel);
|
|
130
|
+
}
|
|
131
|
+
if (order.length !== ids.length) {
|
|
132
|
+
// Find the cycle
|
|
133
|
+
const cycle = this.findCycle();
|
|
134
|
+
return { order, levels, hasCycle: true, cyclePath: cycle ?? undefined };
|
|
135
|
+
}
|
|
136
|
+
return { order, levels, hasCycle: false };
|
|
137
|
+
}
|
|
138
|
+
summarize() {
|
|
139
|
+
const nodes = [...this.nodes.values()];
|
|
140
|
+
const totalTasks = nodes.length;
|
|
141
|
+
const completedTasks = nodes.filter(n => n.status === 'done').length;
|
|
142
|
+
const activeTasks = nodes.filter(n => n.status === 'active').length;
|
|
143
|
+
const blockedTasks = this.getBlockedTasks().length;
|
|
144
|
+
const readyTasks = this.getReadyTasks();
|
|
145
|
+
const longestPath = this.computeLongestPath();
|
|
146
|
+
return {
|
|
147
|
+
totalTasks,
|
|
148
|
+
totalEdges: this.edges.length,
|
|
149
|
+
completedTasks,
|
|
150
|
+
activeTasks,
|
|
151
|
+
blockedTasks,
|
|
152
|
+
readyTasks,
|
|
153
|
+
longestPath,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
listTasks() {
|
|
157
|
+
return [...this.nodes.values()];
|
|
158
|
+
}
|
|
159
|
+
listEdges() {
|
|
160
|
+
return [...this.edges];
|
|
161
|
+
}
|
|
162
|
+
toJSON() {
|
|
163
|
+
return { nodes: this.listTasks(), edges: this.listEdges() };
|
|
164
|
+
}
|
|
165
|
+
static fromJSON(data) {
|
|
166
|
+
const graph = new TaskDependencyGraph({ maxTasks: data.nodes.length + 50 });
|
|
167
|
+
for (const node of data.nodes)
|
|
168
|
+
graph.addTask(node);
|
|
169
|
+
for (const edge of data.edges)
|
|
170
|
+
graph.addDependency(edge);
|
|
171
|
+
return graph;
|
|
172
|
+
}
|
|
173
|
+
// --- Private ---
|
|
174
|
+
detectCycleWithEdge(newEdge) {
|
|
175
|
+
this.edges.push(newEdge);
|
|
176
|
+
const cycle = this.findCycle();
|
|
177
|
+
this.edges.pop();
|
|
178
|
+
return cycle;
|
|
179
|
+
}
|
|
180
|
+
findCycle() {
|
|
181
|
+
const visited = new Set();
|
|
182
|
+
const inStack = new Set();
|
|
183
|
+
const parent = new Map();
|
|
184
|
+
const adjList = new Map();
|
|
185
|
+
for (const id of this.nodes.keys())
|
|
186
|
+
adjList.set(id, []);
|
|
187
|
+
for (const edge of this.edges)
|
|
188
|
+
adjList.get(edge.from)?.push(edge.to);
|
|
189
|
+
for (const start of this.nodes.keys()) {
|
|
190
|
+
if (visited.has(start))
|
|
191
|
+
continue;
|
|
192
|
+
const result = this.dfsCycle(start, visited, inStack, parent, adjList);
|
|
193
|
+
if (result)
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
dfsCycle(current, visited, inStack, parent, adjList) {
|
|
199
|
+
visited.add(current);
|
|
200
|
+
inStack.add(current);
|
|
201
|
+
for (const neighbor of adjList.get(current) ?? []) {
|
|
202
|
+
if (!visited.has(neighbor)) {
|
|
203
|
+
parent.set(neighbor, current);
|
|
204
|
+
const result = this.dfsCycle(neighbor, visited, inStack, parent, adjList);
|
|
205
|
+
if (result)
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
else if (inStack.has(neighbor)) {
|
|
209
|
+
// Reconstruct cycle
|
|
210
|
+
const cycle = [neighbor, current];
|
|
211
|
+
let node = current;
|
|
212
|
+
while (node !== neighbor) {
|
|
213
|
+
node = parent.get(node);
|
|
214
|
+
cycle.push(node);
|
|
215
|
+
}
|
|
216
|
+
return cycle.reverse();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
inStack.delete(current);
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
computeLongestPath() {
|
|
223
|
+
const topo = this.topologicalSort();
|
|
224
|
+
if (topo.hasCycle)
|
|
225
|
+
return -1;
|
|
226
|
+
const dist = new Map();
|
|
227
|
+
for (const id of this.nodes.keys())
|
|
228
|
+
dist.set(id, 0);
|
|
229
|
+
const adjList = new Map();
|
|
230
|
+
for (const id of this.nodes.keys())
|
|
231
|
+
adjList.set(id, []);
|
|
232
|
+
for (const edge of this.edges)
|
|
233
|
+
adjList.get(edge.from)?.push(edge.to);
|
|
234
|
+
for (const node of topo.order) {
|
|
235
|
+
for (const neighbor of adjList.get(node) ?? []) {
|
|
236
|
+
dist.set(neighbor, Math.max(dist.get(neighbor), dist.get(node) + 1));
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
let max = 0;
|
|
240
|
+
for (const d of dist.values())
|
|
241
|
+
max = Math.max(max, d);
|
|
242
|
+
return max;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
//# sourceMappingURL=TaskDependencyGraph.js.map
|
|
@@ -0,0 +1 @@
|
|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AQ,CAAE,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAE,GAAG,CAAC,CAAC,CAAC,CAAA;YACxE,CAAC;QACH,CAAC;QAED,IAAI,GAAG,GAAG,CAAC,CAAA;QACX,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE;YAAE,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;QACrD,OAAO,GAAG,CAAA;IACZ,CAAC;CACF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { WorkflowProfile } from './AdaptiveWorkflowRouter.js';
|
|
2
|
+
export type TemplateStepType = 'explore' | 'plan' | 'build' | 'verify' | 'review' | 'ship';
|
|
3
|
+
export type TemplateRiskLevel = 'low' | 'medium' | 'high' | 'critical';
|
|
4
|
+
export interface WorkflowStepTemplate {
|
|
5
|
+
id: string;
|
|
6
|
+
type: TemplateStepType;
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
required: boolean;
|
|
10
|
+
riskLevel: TemplateRiskLevel;
|
|
11
|
+
estimatedDuration: string;
|
|
12
|
+
evidenceRequired: string[];
|
|
13
|
+
tools: string[];
|
|
14
|
+
skipConditions?: string[];
|
|
15
|
+
}
|
|
16
|
+
export interface WorkflowTemplate {
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
description: string;
|
|
20
|
+
profile: WorkflowProfile;
|
|
21
|
+
riskLevel: TemplateRiskLevel;
|
|
22
|
+
steps: WorkflowStepTemplate[];
|
|
23
|
+
exitCriteria: string[];
|
|
24
|
+
tags: string[];
|
|
25
|
+
}
|
|
26
|
+
export interface WorkflowTemplateInput {
|
|
27
|
+
profile: WorkflowProfile;
|
|
28
|
+
task: string;
|
|
29
|
+
level: string;
|
|
30
|
+
files?: string[];
|
|
31
|
+
riskFactors?: string[];
|
|
32
|
+
}
|
|
33
|
+
export declare const WORKFLOW_TEMPLATES: Record<string, WorkflowTemplate>;
|
|
34
|
+
export declare function selectTemplate(input: WorkflowTemplateInput): WorkflowTemplate;
|
|
35
|
+
export declare function customizeTemplate(template: WorkflowTemplate, overrides: Partial<WorkflowTemplate>): WorkflowTemplate;
|
|
36
|
+
export declare function listTemplates(): WorkflowTemplate[];
|
|
37
|
+
export declare function getTemplateSteps(templateId: string): WorkflowStepTemplate[];
|
|
38
|
+
export declare function formatTemplateForAgent(template: WorkflowTemplate): string;
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
// SCALE Engine — Adaptive Workflow Templates (v0.35.0)
|
|
2
|
+
// Composable workflow template system with profile-based selection
|
|
3
|
+
// ============================================================================
|
|
4
|
+
// Built-in Templates
|
|
5
|
+
// ============================================================================
|
|
6
|
+
const LIGHT_DOCS = {
|
|
7
|
+
id: 'light-docs',
|
|
8
|
+
name: 'Light Documentation',
|
|
9
|
+
description: 'Lightweight template for documentation and config changes',
|
|
10
|
+
profile: 'light',
|
|
11
|
+
riskLevel: 'low',
|
|
12
|
+
steps: [
|
|
13
|
+
{
|
|
14
|
+
id: 'explore',
|
|
15
|
+
type: 'explore',
|
|
16
|
+
name: 'Explore',
|
|
17
|
+
description: 'Understand existing documentation structure',
|
|
18
|
+
required: true,
|
|
19
|
+
riskLevel: 'low',
|
|
20
|
+
estimatedDuration: '5min',
|
|
21
|
+
evidenceRequired: [],
|
|
22
|
+
tools: ['Read', 'Glob'],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: 'build',
|
|
26
|
+
type: 'build',
|
|
27
|
+
name: 'Build',
|
|
28
|
+
description: 'Write or update documentation',
|
|
29
|
+
required: true,
|
|
30
|
+
riskLevel: 'low',
|
|
31
|
+
estimatedDuration: '15min',
|
|
32
|
+
evidenceRequired: [],
|
|
33
|
+
tools: ['Edit', 'Write'],
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: 'verify',
|
|
37
|
+
type: 'verify',
|
|
38
|
+
name: 'Verify',
|
|
39
|
+
description: 'Check links, formatting, and accuracy',
|
|
40
|
+
required: false,
|
|
41
|
+
riskLevel: 'low',
|
|
42
|
+
estimatedDuration: '5min',
|
|
43
|
+
evidenceRequired: [],
|
|
44
|
+
tools: ['Read'],
|
|
45
|
+
skipConditions: ['No structural changes'],
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
exitCriteria: ['Documentation updated and readable'],
|
|
49
|
+
tags: ['docs', 'config', 'lightweight'],
|
|
50
|
+
};
|
|
51
|
+
const STANDARD_CODE = {
|
|
52
|
+
id: 'standard-code',
|
|
53
|
+
name: 'Standard Code',
|
|
54
|
+
description: 'Standard template for typical code changes',
|
|
55
|
+
profile: 'standard',
|
|
56
|
+
riskLevel: 'medium',
|
|
57
|
+
steps: [
|
|
58
|
+
{
|
|
59
|
+
id: 'explore',
|
|
60
|
+
type: 'explore',
|
|
61
|
+
name: 'Explore',
|
|
62
|
+
description: 'Understand codebase structure and dependencies',
|
|
63
|
+
required: true,
|
|
64
|
+
riskLevel: 'low',
|
|
65
|
+
estimatedDuration: '10min',
|
|
66
|
+
evidenceRequired: [],
|
|
67
|
+
tools: ['Read', 'Glob', 'Grep'],
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: 'plan',
|
|
71
|
+
type: 'plan',
|
|
72
|
+
name: 'Plan',
|
|
73
|
+
description: 'Design implementation approach',
|
|
74
|
+
required: true,
|
|
75
|
+
riskLevel: 'low',
|
|
76
|
+
estimatedDuration: '10min',
|
|
77
|
+
evidenceRequired: [],
|
|
78
|
+
tools: ['Read'],
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: 'build',
|
|
82
|
+
type: 'build',
|
|
83
|
+
name: 'Build',
|
|
84
|
+
description: 'Implement changes with tests',
|
|
85
|
+
required: true,
|
|
86
|
+
riskLevel: 'medium',
|
|
87
|
+
estimatedDuration: '30min',
|
|
88
|
+
evidenceRequired: [],
|
|
89
|
+
tools: ['Edit', 'Write', 'Bash'],
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
id: 'verify',
|
|
93
|
+
type: 'verify',
|
|
94
|
+
name: 'Verify',
|
|
95
|
+
description: 'Run tests and type checks',
|
|
96
|
+
required: true,
|
|
97
|
+
riskLevel: 'medium',
|
|
98
|
+
estimatedDuration: '10min',
|
|
99
|
+
evidenceRequired: ['test-results', 'typecheck-results'],
|
|
100
|
+
tools: ['Bash'],
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
id: 'review',
|
|
104
|
+
type: 'review',
|
|
105
|
+
name: 'Review',
|
|
106
|
+
description: 'Code review for quality and security',
|
|
107
|
+
required: false,
|
|
108
|
+
riskLevel: 'medium',
|
|
109
|
+
estimatedDuration: '10min',
|
|
110
|
+
evidenceRequired: [],
|
|
111
|
+
tools: ['Read', 'Grep'],
|
|
112
|
+
skipConditions: ['Trivial changes under 20 lines'],
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
exitCriteria: ['All tests pass', 'Type check clean', 'Code reviewed'],
|
|
116
|
+
tags: ['code', 'standard', 'feature'],
|
|
117
|
+
};
|
|
118
|
+
const STRICT_FEATURE = {
|
|
119
|
+
id: 'strict-feature',
|
|
120
|
+
name: 'Strict Feature',
|
|
121
|
+
description: 'Strict template for high-risk features with full gates',
|
|
122
|
+
profile: 'strict',
|
|
123
|
+
riskLevel: 'high',
|
|
124
|
+
steps: [
|
|
125
|
+
{
|
|
126
|
+
id: 'explore',
|
|
127
|
+
type: 'explore',
|
|
128
|
+
name: 'Explore',
|
|
129
|
+
description: 'Deep codebase analysis with dependency mapping',
|
|
130
|
+
required: true,
|
|
131
|
+
riskLevel: 'low',
|
|
132
|
+
estimatedDuration: '15min',
|
|
133
|
+
evidenceRequired: [],
|
|
134
|
+
tools: ['Read', 'Glob', 'Grep'],
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
id: 'plan',
|
|
138
|
+
type: 'plan',
|
|
139
|
+
name: 'Plan',
|
|
140
|
+
description: 'Detailed implementation plan with risk assessment',
|
|
141
|
+
required: true,
|
|
142
|
+
riskLevel: 'medium',
|
|
143
|
+
estimatedDuration: '15min',
|
|
144
|
+
evidenceRequired: ['risk-assessment'],
|
|
145
|
+
tools: ['Read'],
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
id: 'build',
|
|
149
|
+
type: 'build',
|
|
150
|
+
name: 'Build',
|
|
151
|
+
description: 'Implement with TDD and defensive coding',
|
|
152
|
+
required: true,
|
|
153
|
+
riskLevel: 'high',
|
|
154
|
+
estimatedDuration: '60min',
|
|
155
|
+
evidenceRequired: [],
|
|
156
|
+
tools: ['Edit', 'Write', 'Bash'],
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
id: 'verify',
|
|
160
|
+
type: 'verify',
|
|
161
|
+
name: 'Verify',
|
|
162
|
+
description: 'Full test suite + coverage + type check',
|
|
163
|
+
required: true,
|
|
164
|
+
riskLevel: 'high',
|
|
165
|
+
estimatedDuration: '15min',
|
|
166
|
+
evidenceRequired: ['test-results', 'typecheck-results', 'coverage-report'],
|
|
167
|
+
tools: ['Bash'],
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
id: 'review',
|
|
171
|
+
type: 'review',
|
|
172
|
+
name: 'Review',
|
|
173
|
+
description: 'Multi-role review (eng-manager + security-reviewer)',
|
|
174
|
+
required: true,
|
|
175
|
+
riskLevel: 'high',
|
|
176
|
+
estimatedDuration: '15min',
|
|
177
|
+
evidenceRequired: ['review-report'],
|
|
178
|
+
tools: ['Read', 'Grep'],
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
id: 'ship',
|
|
182
|
+
type: 'ship',
|
|
183
|
+
name: 'Ship',
|
|
184
|
+
description: 'Ship pipeline with version bump and PR',
|
|
185
|
+
required: false,
|
|
186
|
+
riskLevel: 'high',
|
|
187
|
+
estimatedDuration: '10min',
|
|
188
|
+
evidenceRequired: ['ship-report'],
|
|
189
|
+
tools: ['Bash'],
|
|
190
|
+
skipConditions: ['Not ready for release'],
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
exitCriteria: ['All tests pass', 'Coverage >= 80%', 'Security review passed', 'Code reviewed by 2+ roles'],
|
|
194
|
+
tags: ['feature', 'strict', 'high-risk'],
|
|
195
|
+
};
|
|
196
|
+
const CRITICAL_SECURITY = {
|
|
197
|
+
id: 'critical-security',
|
|
198
|
+
name: 'Critical Security',
|
|
199
|
+
description: 'Maximum security template for auth, crypto, and sensitive changes',
|
|
200
|
+
profile: 'critical',
|
|
201
|
+
riskLevel: 'critical',
|
|
202
|
+
steps: [
|
|
203
|
+
{
|
|
204
|
+
id: 'explore',
|
|
205
|
+
type: 'explore',
|
|
206
|
+
name: 'Explore',
|
|
207
|
+
description: 'Full codebase audit with OWASP/STRIDE analysis',
|
|
208
|
+
required: true,
|
|
209
|
+
riskLevel: 'medium',
|
|
210
|
+
estimatedDuration: '20min',
|
|
211
|
+
evidenceRequired: [],
|
|
212
|
+
tools: ['Read', 'Glob', 'Grep'],
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
id: 'plan',
|
|
216
|
+
type: 'plan',
|
|
217
|
+
name: 'Plan',
|
|
218
|
+
description: 'Security-focused plan with threat model',
|
|
219
|
+
required: true,
|
|
220
|
+
riskLevel: 'high',
|
|
221
|
+
estimatedDuration: '20min',
|
|
222
|
+
evidenceRequired: ['threat-model', 'risk-assessment'],
|
|
223
|
+
tools: ['Read'],
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
id: 'build',
|
|
227
|
+
type: 'build',
|
|
228
|
+
name: 'Build',
|
|
229
|
+
description: 'Implement with security-first patterns',
|
|
230
|
+
required: true,
|
|
231
|
+
riskLevel: 'critical',
|
|
232
|
+
estimatedDuration: '60min',
|
|
233
|
+
evidenceRequired: [],
|
|
234
|
+
tools: ['Edit', 'Write', 'Bash'],
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
id: 'verify',
|
|
238
|
+
type: 'verify',
|
|
239
|
+
name: 'Verify',
|
|
240
|
+
description: 'Full test suite + security audit + dependency audit',
|
|
241
|
+
required: true,
|
|
242
|
+
riskLevel: 'critical',
|
|
243
|
+
estimatedDuration: '20min',
|
|
244
|
+
evidenceRequired: ['test-results', 'typecheck-results', 'security-audit', 'dependency-audit'],
|
|
245
|
+
tools: ['Bash'],
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
id: 'review',
|
|
249
|
+
type: 'review',
|
|
250
|
+
name: 'Review',
|
|
251
|
+
description: 'Security-reviewer + eng-manager mandatory review',
|
|
252
|
+
required: true,
|
|
253
|
+
riskLevel: 'critical',
|
|
254
|
+
estimatedDuration: '20min',
|
|
255
|
+
evidenceRequired: ['security-review-report', 'architecture-review-report'],
|
|
256
|
+
tools: ['Read', 'Grep'],
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
id: 'ship',
|
|
260
|
+
type: 'ship',
|
|
261
|
+
name: 'Ship',
|
|
262
|
+
description: 'Controlled ship with rollback plan',
|
|
263
|
+
required: true,
|
|
264
|
+
riskLevel: 'critical',
|
|
265
|
+
estimatedDuration: '15min',
|
|
266
|
+
evidenceRequired: ['ship-report', 'rollback-plan'],
|
|
267
|
+
tools: ['Bash'],
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
exitCriteria: [
|
|
271
|
+
'All tests pass',
|
|
272
|
+
'Security audit clean',
|
|
273
|
+
'OWASP Top 10 checked',
|
|
274
|
+
'STRIDE analysis done',
|
|
275
|
+
'Dependency audit clean',
|
|
276
|
+
'Reviewed by security-reviewer',
|
|
277
|
+
'Rollback plan documented',
|
|
278
|
+
],
|
|
279
|
+
tags: ['security', 'critical', 'auth', 'crypto'],
|
|
280
|
+
};
|
|
281
|
+
export const WORKFLOW_TEMPLATES = {
|
|
282
|
+
'light-docs': LIGHT_DOCS,
|
|
283
|
+
'standard-code': STANDARD_CODE,
|
|
284
|
+
'strict-feature': STRICT_FEATURE,
|
|
285
|
+
'critical-security': CRITICAL_SECURITY,
|
|
286
|
+
};
|
|
287
|
+
const PROFILE_TEMPLATE_MAP = {
|
|
288
|
+
light: 'light-docs',
|
|
289
|
+
standard: 'standard-code',
|
|
290
|
+
strict: 'strict-feature',
|
|
291
|
+
critical: 'critical-security',
|
|
292
|
+
};
|
|
293
|
+
// ============================================================================
|
|
294
|
+
// Public API
|
|
295
|
+
// ============================================================================
|
|
296
|
+
export function selectTemplate(input) {
|
|
297
|
+
const { profile, task, level, riskFactors } = input;
|
|
298
|
+
// Check for security keywords → force critical template
|
|
299
|
+
const securityKeywords = ['auth', 'security', 'crypto', 'password', 'token', 'secret', 'credential', 'oauth', 'jwt'];
|
|
300
|
+
const taskLower = task.toLowerCase();
|
|
301
|
+
if (securityKeywords.some(kw => taskLower.includes(kw))) {
|
|
302
|
+
return WORKFLOW_TEMPLATES['critical-security'];
|
|
303
|
+
}
|
|
304
|
+
// Check for doc keywords → prefer light template
|
|
305
|
+
const docKeywords = ['readme', 'docs', 'documentation', 'changelog', 'comment'];
|
|
306
|
+
if (docKeywords.some(kw => taskLower.includes(kw)) && profile === 'light') {
|
|
307
|
+
return WORKFLOW_TEMPLATES['light-docs'];
|
|
308
|
+
}
|
|
309
|
+
// Risk factor escalation
|
|
310
|
+
if (riskFactors && riskFactors.length >= 3 && profileRank(profile) < profileRank('strict')) {
|
|
311
|
+
return WORKFLOW_TEMPLATES['strict-feature'];
|
|
312
|
+
}
|
|
313
|
+
// Level-based escalation
|
|
314
|
+
if ((level === 'CRITICAL' || level === 'L') && profileRank(profile) < profileRank('strict')) {
|
|
315
|
+
return WORKFLOW_TEMPLATES['strict-feature'];
|
|
316
|
+
}
|
|
317
|
+
// Default: use profile mapping
|
|
318
|
+
const templateId = PROFILE_TEMPLATE_MAP[profile] ?? 'standard-code';
|
|
319
|
+
return WORKFLOW_TEMPLATES[templateId];
|
|
320
|
+
}
|
|
321
|
+
export function customizeTemplate(template, overrides) {
|
|
322
|
+
return {
|
|
323
|
+
...template,
|
|
324
|
+
...overrides,
|
|
325
|
+
steps: overrides.steps ?? template.steps,
|
|
326
|
+
exitCriteria: overrides.exitCriteria ?? template.exitCriteria,
|
|
327
|
+
tags: overrides.tags ?? template.tags,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
export function listTemplates() {
|
|
331
|
+
return Object.values(WORKFLOW_TEMPLATES);
|
|
332
|
+
}
|
|
333
|
+
export function getTemplateSteps(templateId) {
|
|
334
|
+
return WORKFLOW_TEMPLATES[templateId]?.steps ?? [];
|
|
335
|
+
}
|
|
336
|
+
export function formatTemplateForAgent(template) {
|
|
337
|
+
const lines = [
|
|
338
|
+
`# Workflow Template: ${template.name}`,
|
|
339
|
+
'',
|
|
340
|
+
`**Profile:** ${template.profile} | **Risk:** ${template.riskLevel}`,
|
|
341
|
+
`**Description:** ${template.description}`,
|
|
342
|
+
'',
|
|
343
|
+
'## Steps',
|
|
344
|
+
'',
|
|
345
|
+
];
|
|
346
|
+
for (const step of template.steps) {
|
|
347
|
+
const required = step.required ? '*(required)*' : '*(optional)*';
|
|
348
|
+
lines.push(`### ${step.name} ${required}`);
|
|
349
|
+
lines.push(`- **Type:** ${step.type}`);
|
|
350
|
+
lines.push(`- **Risk:** ${step.riskLevel}`);
|
|
351
|
+
lines.push(`- **Duration:** ${step.estimatedDuration}`);
|
|
352
|
+
lines.push(`- **Description:** ${step.description}`);
|
|
353
|
+
if (step.evidenceRequired.length > 0) {
|
|
354
|
+
lines.push(`- **Evidence:** ${step.evidenceRequired.join(', ')}`);
|
|
355
|
+
}
|
|
356
|
+
if (step.skipConditions && step.skipConditions.length > 0) {
|
|
357
|
+
lines.push(`- **Skip when:** ${step.skipConditions.join('; ')}`);
|
|
358
|
+
}
|
|
359
|
+
lines.push('');
|
|
360
|
+
}
|
|
361
|
+
lines.push('## Exit Criteria');
|
|
362
|
+
for (const criteria of template.exitCriteria) {
|
|
363
|
+
lines.push(`- ${criteria}`);
|
|
364
|
+
}
|
|
365
|
+
return lines.join('\n');
|
|
366
|
+
}
|
|
367
|
+
function profileRank(profile) {
|
|
368
|
+
const order = ['light', 'standard', 'strict', 'critical'];
|
|
369
|
+
return order.indexOf(profile);
|
|
370
|
+
}
|
|
371
|
+
//# sourceMappingURL=WorkflowTemplates.js.map
|