@pazmo/ai-workflow-kit 3.1.1 → 4.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.ko.md +206 -0
- package/README.md +130 -223
- package/assets/graph.mjs +10 -0
- package/assets/readme/workflow-en.png +0 -0
- package/assets/readme/workflow-en.svg +41 -0
- package/assets/readme/workflow-ko.png +0 -0
- package/assets/readme/workflow-ko.svg +41 -0
- package/bin/ai-workflow-kit.mjs +38 -2
- package/package.json +9 -3
- package/skills/workflow/EVALS.md +45 -0
- package/skills/workflow/SKILL.md +5 -5
- package/skills/workflow/references/execution.md +31 -5
- package/skills/workflow/references/graph-engineering.md +120 -0
- package/skills/workflow/references/intake.md +6 -2
- package/skills/workflow/references/role-graphs.md +136 -0
- package/skills/workflow/references/skill-integration.md +55 -0
- package/skills/workflow/references/understanding-gate.md +2 -0
- package/src/git-visibility.mjs +19 -12
- package/src/graph/cli.mjs +157 -0
- package/src/graph/executor.mjs +92 -0
- package/src/graph/index.mjs +17 -0
- package/src/graph/planning-graph.mjs +16 -0
- package/src/graph/roles.mjs +62 -0
- package/src/graph/scheduler.mjs +99 -0
- package/src/graph/storage.mjs +76 -0
- package/src/graph/task-graph.mjs +125 -0
- package/src/graph/workflow.mjs +153 -0
- package/src/install-transaction.mjs +1 -0
- package/src/install.mjs +16 -0
- package/src/managed-block.mjs +3 -1
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
export class GraphValidationError extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = 'GraphValidationError';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function requireNonEmptyString(value, label) {
|
|
11
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
12
|
+
throw new GraphValidationError(`${label} must be a non-empty string.`);
|
|
13
|
+
}
|
|
14
|
+
return value.trim();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function createTaskGraph({ id = 'task-graph', nodes = [], edges = [] } = {}) {
|
|
18
|
+
const graphId = requireNonEmptyString(id, 'graph.id');
|
|
19
|
+
if (!Array.isArray(nodes) || nodes.length === 0) {
|
|
20
|
+
throw new GraphValidationError('graph.nodes must contain at least one node.');
|
|
21
|
+
}
|
|
22
|
+
if (!Array.isArray(edges)) {
|
|
23
|
+
throw new GraphValidationError('graph.edges must be an array.');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const nodeIds = new Set();
|
|
27
|
+
const normalizedNodes = nodes.map((node, index) => {
|
|
28
|
+
if (!node || typeof node !== 'object' || Array.isArray(node)) {
|
|
29
|
+
throw new GraphValidationError(`graph.nodes[${index}] must be an object.`);
|
|
30
|
+
}
|
|
31
|
+
const nodeId = requireNonEmptyString(node.id, `graph.nodes[${index}].id`);
|
|
32
|
+
if (['__proto__', 'constructor', 'prototype'].includes(nodeId)) {
|
|
33
|
+
throw new GraphValidationError(`reserved node id: ${nodeId}`);
|
|
34
|
+
}
|
|
35
|
+
if (node.access !== undefined && !['read', 'write'].includes(node.access)) {
|
|
36
|
+
throw new GraphValidationError(`invalid access for node: ${nodeId}`);
|
|
37
|
+
}
|
|
38
|
+
if (nodeIds.has(nodeId)) {
|
|
39
|
+
throw new GraphValidationError(`duplicate node id: ${nodeId}`);
|
|
40
|
+
}
|
|
41
|
+
nodeIds.add(nodeId);
|
|
42
|
+
return Object.freeze({ ...node, id: nodeId });
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const edgeKeys = new Set();
|
|
46
|
+
const normalizedEdges = edges.map((edge, index) => {
|
|
47
|
+
if (!edge || typeof edge !== 'object' || Array.isArray(edge)) {
|
|
48
|
+
throw new GraphValidationError(`graph.edges[${index}] must be an object.`);
|
|
49
|
+
}
|
|
50
|
+
const from = requireNonEmptyString(edge.from, `graph.edges[${index}].from`);
|
|
51
|
+
const to = requireNonEmptyString(edge.to, `graph.edges[${index}].to`);
|
|
52
|
+
if (!nodeIds.has(from)) throw new GraphValidationError(`edge references missing node: ${from}`);
|
|
53
|
+
if (!nodeIds.has(to)) throw new GraphValidationError(`edge references missing node: ${to}`);
|
|
54
|
+
if (from === to) throw new GraphValidationError(`self edge is not allowed: ${from}`);
|
|
55
|
+
const key = JSON.stringify([from, to]);
|
|
56
|
+
if (edgeKeys.has(key)) throw new GraphValidationError(`duplicate edge: ${from} -> ${to}`);
|
|
57
|
+
edgeKeys.add(key);
|
|
58
|
+
return Object.freeze({ from, to });
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const graph = Object.freeze({
|
|
62
|
+
id: graphId,
|
|
63
|
+
nodes: Object.freeze(normalizedNodes),
|
|
64
|
+
edges: Object.freeze(normalizedEdges),
|
|
65
|
+
});
|
|
66
|
+
assertAcyclic(graph);
|
|
67
|
+
return graph;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function nodeById(graph, nodeId) {
|
|
71
|
+
const node = graph.nodes.find((candidate) => candidate.id === nodeId);
|
|
72
|
+
if (!node) throw new GraphValidationError(`unknown node: ${nodeId}`);
|
|
73
|
+
return node;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function graphFingerprint(graph) {
|
|
77
|
+
return createHash('sha256').update(JSON.stringify(graph)).digest('hex');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function dependencyIds(graph, nodeId) {
|
|
81
|
+
nodeById(graph, nodeId);
|
|
82
|
+
return graph.edges.filter((edge) => edge.to === nodeId).map((edge) => edge.from);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function descendantIds(graph, nodeIds) {
|
|
86
|
+
const seeds = new Set(nodeIds);
|
|
87
|
+
for (const nodeId of seeds) nodeById(graph, nodeId);
|
|
88
|
+
|
|
89
|
+
const descendants = new Set(seeds);
|
|
90
|
+
const queue = [...seeds];
|
|
91
|
+
while (queue.length) {
|
|
92
|
+
const current = queue.shift();
|
|
93
|
+
for (const edge of graph.edges) {
|
|
94
|
+
if (edge.from !== current || descendants.has(edge.to)) continue;
|
|
95
|
+
descendants.add(edge.to);
|
|
96
|
+
queue.push(edge.to);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return descendants;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function assertAcyclic(graph) {
|
|
103
|
+
const indegree = new Map(graph.nodes.map((node) => [node.id, 0]));
|
|
104
|
+
const outgoing = new Map(graph.nodes.map((node) => [node.id, []]));
|
|
105
|
+
for (const edge of graph.edges) {
|
|
106
|
+
indegree.set(edge.to, indegree.get(edge.to) + 1);
|
|
107
|
+
outgoing.get(edge.from).push(edge.to);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const queue = graph.nodes.filter((node) => indegree.get(node.id) === 0).map((node) => node.id);
|
|
111
|
+
let visited = 0;
|
|
112
|
+
while (queue.length) {
|
|
113
|
+
const current = queue.shift();
|
|
114
|
+
visited += 1;
|
|
115
|
+
for (const next of outgoing.get(current)) {
|
|
116
|
+
indegree.set(next, indegree.get(next) - 1);
|
|
117
|
+
if (indegree.get(next) === 0) queue.push(next);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (visited !== graph.nodes.length) {
|
|
122
|
+
throw new GraphValidationError('graph must be a DAG; a dependency cycle was found.');
|
|
123
|
+
}
|
|
124
|
+
return graph;
|
|
125
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { createTaskGraph, dependencyIds, descendantIds, nodeById } from './task-graph.mjs';
|
|
3
|
+
import { assertRunState, blockedNodeIds, createRunState, selectReadyNodes } from './scheduler.mjs';
|
|
4
|
+
import { digest, readProjectFile } from './storage.mjs';
|
|
5
|
+
import { assertRoleOutput, assertRoleRun } from './roles.mjs';
|
|
6
|
+
|
|
7
|
+
export const MAX_ATTEMPTS = 3;
|
|
8
|
+
export const MAX_QUESTIONS = 3;
|
|
9
|
+
const REVIEW = 'workflow-review';
|
|
10
|
+
const VERIFY = 'workflow-verify';
|
|
11
|
+
|
|
12
|
+
export function storyContract(text) {
|
|
13
|
+
// Progress metadata is mutable; requirements and human decisions are not.
|
|
14
|
+
const content = text.split(/\r?\n/).filter(line => !/^(?:Status:|Understanding gate \(G[134]\):|G4:)/i.test(line)).join('\n').trim();
|
|
15
|
+
const sectionIds = (heading, prefix) => {
|
|
16
|
+
const body = text.match(new RegExp(`^##\\s+${heading}\\s*$([\\s\\S]*?)(?=^##\\s|$(?![\\s\\S]))`, 'im'))?.[1] ?? '';
|
|
17
|
+
return [...body.matchAll(new RegExp(`^[-*]\\s+(${prefix}-?\\d+)\\b`, 'gim'))].map(match => match[1].toUpperCase());
|
|
18
|
+
};
|
|
19
|
+
return { fingerprint: digest(content), ids: [...sectionIds('MUST', 'M'), ...sectionIds('Verify', 'V')] };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function createWorkflowGraph(plan, ids) {
|
|
23
|
+
const draft = plan ?? { id: 'delivery', nodes: [{ id: 'implement', description: 'Implement the approved Story, demonstrate RED/GREEN and simplify while green.', access: 'write', covers: ids, verify: 'Run related checks and record the changed files and evidence.' }], edges: [] };
|
|
24
|
+
const base = createTaskGraph(draft);
|
|
25
|
+
const covered = new Set();
|
|
26
|
+
for (const node of base.nodes) {
|
|
27
|
+
if ([REVIEW, VERIFY].includes(node.id)) throw new Error(`Reserved workflow node: ${node.id}`);
|
|
28
|
+
for (const field of ['description', 'verify']) {
|
|
29
|
+
if (typeof node[field] !== 'string' || !node[field].trim()) throw new Error(`Node ${node.id} needs ${field}.`);
|
|
30
|
+
}
|
|
31
|
+
if (!['read', 'write'].includes(node.access)) throw new Error(`Node ${node.id} needs read/write access.`);
|
|
32
|
+
if (!Array.isArray(node.covers) || !node.covers.length) throw new Error(`Node ${node.id} needs Story M/V references.`);
|
|
33
|
+
for (const id of node.covers) {
|
|
34
|
+
if (!ids.includes(id)) throw new Error(`Unknown Story reference: ${id}`);
|
|
35
|
+
covered.add(id);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
for (const id of ids) if (!covered.has(id)) throw new Error(`Plan does not cover Story ${id}.`);
|
|
39
|
+
const sinks = base.nodes.filter(node => !base.edges.some(edge => edge.from === node.id));
|
|
40
|
+
return createTaskGraph({ id: base.id, nodes: [
|
|
41
|
+
...base.nodes,
|
|
42
|
+
{ id: REVIEW, access: 'read', covers: ids, description: 'Review the final diff against the Story, including failure paths.', verify: 'Record findings and evidence; fail with the corrective action if changes are needed.' },
|
|
43
|
+
{ id: VERIFY, access: 'read', covers: ids, description: 'Run fresh verification after review fixes; prepare raw evidence for G4.', verify: 'Record actual commands, exit codes, changed-file scope and unproven boundaries.' },
|
|
44
|
+
], edges: [...base.edges, ...sinks.map(node => ({ from: node.id, to: REVIEW })), { from: REVIEW, to: VERIFY }] });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function newWorkflowRun(graph, story, contract) {
|
|
48
|
+
return { version: 1, runId: randomUUID(), graph, state: createRunState(graph), story: { path: story, fingerprint: contract.fingerprint }, history: [] };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function assertWorkflowRun(run) {
|
|
52
|
+
if (![1, 2].includes(run?.version) || typeof run.runId !== 'string' || !run.runId.trim()
|
|
53
|
+
|| !run.graph || !run.story?.path || !Array.isArray(run.history)) throw new Error('Invalid workflow run.');
|
|
54
|
+
const graph = createTaskGraph(run.graph);
|
|
55
|
+
assertRunState(graph, run.state);
|
|
56
|
+
if (run.question && (run.state.nodes[run.question.nodeId]?.status !== 'running'
|
|
57
|
+
|| typeof run.question.id !== 'string' || !run.question.id
|
|
58
|
+
|| typeof run.question.text !== 'string' || !run.question.text.trim()
|
|
59
|
+
|| run.question.token !== taskToken(run, run.question.nodeId))) throw new Error('Invalid pending question.');
|
|
60
|
+
if (run.version === 2) {
|
|
61
|
+
assertRoleRun(run);
|
|
62
|
+
return graph;
|
|
63
|
+
}
|
|
64
|
+
if (!graph.nodes.some(node => node.id === REVIEW) || !graph.nodes.some(node => node.id === VERIFY)) throw new Error('Workflow review/verification nodes are missing.');
|
|
65
|
+
if (!dependencyIds(graph, VERIFY).includes(REVIEW)
|
|
66
|
+
|| graph.nodes.some(node => node.id !== VERIFY && !descendantIds(graph, [node.id]).has(VERIFY))) {
|
|
67
|
+
throw new Error('Every workflow node must precede final verification.');
|
|
68
|
+
}
|
|
69
|
+
return graph;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function taskToken(run, nodeId) {
|
|
73
|
+
return digest(JSON.stringify([run.runId, run.state.fingerprint, run.story.fingerprint, nodeId,
|
|
74
|
+
run.state.nodes[nodeId].attempts, run.state.nodes[nodeId].revision,
|
|
75
|
+
dependencyIds(run.graph, nodeId).map(id => run.state.nodes[id]),
|
|
76
|
+
...(run.version === 2 ? [run.assignment.fingerprint] : []) ]));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function revisionToken(run) {
|
|
80
|
+
return digest(JSON.stringify([run.runId, run.story, run.assignment, run.state]));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export async function evidenceHashes(root, evidence) {
|
|
84
|
+
if (!Array.isArray(evidence) || evidence.length === 0) throw new Error('Node output requires evidence files.');
|
|
85
|
+
const hashes = {};
|
|
86
|
+
for (const file of evidence) {
|
|
87
|
+
const body = await readProjectFile(root, file);
|
|
88
|
+
if (!body.trim()) throw new Error(`Empty evidence file: ${file}`);
|
|
89
|
+
Object.defineProperty(hashes, file, { value: digest(body), enumerable: true, configurable: true });
|
|
90
|
+
}
|
|
91
|
+
return hashes;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function checkRunEvidence(root, run) {
|
|
95
|
+
for (const event of run.history.filter(entry => ['answer', 'feedback'].includes(entry.event))) {
|
|
96
|
+
const actual = await evidenceHashes(root, event.evidence);
|
|
97
|
+
if (JSON.stringify(actual) !== JSON.stringify(event.evidenceHashes)) throw new Error('Conversation evidence changed; preserve the original answer/feedback.');
|
|
98
|
+
}
|
|
99
|
+
for (const node of run.graph.nodes) {
|
|
100
|
+
const state = run.state.nodes[node.id];
|
|
101
|
+
if (!['completed', 'failed'].includes(state.status)) continue;
|
|
102
|
+
if (typeof state.output?.summary !== 'string' || !state.output.summary.trim()) throw new Error(`Missing output summary: ${node.id}`);
|
|
103
|
+
if (state.status === 'completed') assertRoleOutput(run, node.id, state.output);
|
|
104
|
+
const actual = await evidenceHashes(root, state.output.evidence);
|
|
105
|
+
if (JSON.stringify(actual) !== JSON.stringify(state.evidenceHashes)) throw new Error(`Node evidence changed: ${node.id}; reset affected work.`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function workflowStatus(run) {
|
|
110
|
+
const graph = assertWorkflowRun(run);
|
|
111
|
+
const nodes = Object.entries(run.state.nodes);
|
|
112
|
+
const failed = nodes.filter(([, state]) => state.status === 'failed').map(([id, state]) => ({ id, action: state.evaluation?.action ?? 'fix', feedback: state.error }));
|
|
113
|
+
const running = nodes.filter(([, state]) => state.status === 'running').map(([id]) => id);
|
|
114
|
+
const exhausted = nodes.some(([, state]) => ['pending', 'failed'].includes(state.status) && state.attempts >= MAX_ATTEMPTS);
|
|
115
|
+
let action;
|
|
116
|
+
if (exhausted) action = 'stop';
|
|
117
|
+
else if (failed.some(node => node.action === 'human')) action = 'human';
|
|
118
|
+
else if (failed.some(node => node.action === 'replan')) action = 'replan';
|
|
119
|
+
else if (run.question) action = 'question';
|
|
120
|
+
else if (failed.length) action = 'fix';
|
|
121
|
+
else if (nodes.every(([, state]) => state.status === 'completed')) action = run.version === 2 ? 'role-complete' : 'g4';
|
|
122
|
+
else action = 'execute';
|
|
123
|
+
const ready = ['execute', 'fix'].includes(action) ? selectReadyNodes(graph, run.state, 4).map(node => taskInput(run, node.id)) : [];
|
|
124
|
+
if (action === 'execute' && ready.length === 0 && running.length) action = 'wait';
|
|
125
|
+
return { runId: run.runId, revisionToken: revisionToken(run), action, ready, running, failed, blocked: blockedNodeIds(graph, run.state),
|
|
126
|
+
...(run.version === 2 ? { assignment: run.assignment.value } : {}),
|
|
127
|
+
...(run.question ? { question: run.question } : {}),
|
|
128
|
+
...(action === 'role-complete' ? { submission: { nodeId: graph.nodes.at(-1).id, output: run.state.nodes[graph.nodes.at(-1).id].output } } : {}),
|
|
129
|
+
completed: nodes.filter(([, state]) => state.status === 'completed').map(([id]) => id),
|
|
130
|
+
gate: 'Graph evidence never approves G3/G4. G4 remains human-owned.', maxAttempts: MAX_ATTEMPTS, maxQuestionsPerNode: MAX_QUESTIONS };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function taskInput(run, nodeId) {
|
|
134
|
+
const affected = descendantIds(run.graph, [nodeId]);
|
|
135
|
+
return { ...nodeById(run.graph, nodeId), token: taskToken(run, nodeId), input: {
|
|
136
|
+
story: run.story.path,
|
|
137
|
+
...(run.version === 2 ? { assignment: run.assignment.value } : {}),
|
|
138
|
+
messages: run.history.flatMap(entry => {
|
|
139
|
+
if (entry.event === 'record' && affected.has(entry.nodeId) && entry.result.evaluation?.passed === false) {
|
|
140
|
+
return [{ event: 'failure', nodeId: entry.nodeId, feedback: entry.result.evaluation.feedback, output: entry.result.output }];
|
|
141
|
+
}
|
|
142
|
+
return (['question', 'answer'].includes(entry.event) && entry.nodeId === nodeId)
|
|
143
|
+
|| (entry.event === 'feedback' && entry.affected.includes(nodeId)) ? [entry] : [];
|
|
144
|
+
}),
|
|
145
|
+
dependencies: Object.fromEntries(dependencyIds(run.graph, nodeId).map(id => [id, run.state.nodes[id].output])),
|
|
146
|
+
} };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function requireReady(run, nodeId, token) {
|
|
150
|
+
nodeById(run.graph, nodeId);
|
|
151
|
+
if (!workflowStatus(run).ready.some(node => node.id === nodeId)) throw new Error(`Node is not ready: ${nodeId}`);
|
|
152
|
+
if (token !== taskToken(run, nodeId)) throw new Error('Stale or missing task token; read fresh status.');
|
|
153
|
+
}
|
|
@@ -8,6 +8,7 @@ const PATHS = Object.freeze([
|
|
|
8
8
|
'AGENTS.md', 'CLAUDE.md', '.agents/skills/workflow', '.claude/skills/workflow',
|
|
9
9
|
'templates/ai-workflow/STORY.md', 'templates/ai-workflow/TASK.md',
|
|
10
10
|
'.ai-workflow/bin/check.mjs', '.ai-workflow/config.json',
|
|
11
|
+
'.ai-workflow/bin/graph.mjs', '.ai-workflow/graph',
|
|
11
12
|
]);
|
|
12
13
|
const JOURNAL = '.ai-workflow-install';
|
|
13
14
|
|
package/src/install.mjs
CHANGED
|
@@ -17,9 +17,11 @@ import { installTransaction } from './install-transaction.mjs';
|
|
|
17
17
|
const modulePackageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
18
18
|
const CONFIG_PATH = '.ai-workflow/config.json';
|
|
19
19
|
const CHECKER_PATH = '.ai-workflow/bin/check.mjs';
|
|
20
|
+
const GRAPH_PATH = '.ai-workflow/graph';
|
|
20
21
|
const TEMPLATE_PATHS = Object.freeze([
|
|
21
22
|
['skills/workflow/assets/STORY.md', 'templates/ai-workflow/STORY.md'],
|
|
22
23
|
['skills/workflow/assets/TASK.md', 'templates/ai-workflow/TASK.md'],
|
|
24
|
+
['assets/graph.mjs', '.ai-workflow/bin/graph.mjs'],
|
|
23
25
|
]);
|
|
24
26
|
|
|
25
27
|
async function exists(file) {
|
|
@@ -181,6 +183,11 @@ async function installPrepared({
|
|
|
181
183
|
}));
|
|
182
184
|
}
|
|
183
185
|
|
|
186
|
+
const graphPlan = await inspectManagedTree({
|
|
187
|
+
source: path.join(packageRoot, 'src/graph'), target: projectPath(root, GRAPH_PATH),
|
|
188
|
+
previousHash: previous?.managedTrees?.[GRAPH_PATH], relative: GRAPH_PATH,
|
|
189
|
+
});
|
|
190
|
+
|
|
184
191
|
const instructionPlans = new Map();
|
|
185
192
|
for (const [host, hostConfig] of Object.entries(HOSTS)) {
|
|
186
193
|
const file = projectPath(root, hostConfig.instructionFile);
|
|
@@ -212,6 +219,11 @@ async function installPrepared({
|
|
|
212
219
|
}
|
|
213
220
|
|
|
214
221
|
const managedTrees = {};
|
|
222
|
+
const graphResult = await applyManagedTree(graphPlan);
|
|
223
|
+
managedTrees[GRAPH_PATH] = graphResult.hash;
|
|
224
|
+
changed = graphResult.changed || changed;
|
|
225
|
+
if (graphResult.changed) installed.push(GRAPH_PATH);
|
|
226
|
+
if (graphResult.preserved) preserved.push(GRAPH_PATH);
|
|
215
227
|
for (const host of selectedHosts) {
|
|
216
228
|
const relative = HOSTS[host].skillDir;
|
|
217
229
|
const result = await applyManagedTree(treePlans.get(host));
|
|
@@ -313,6 +325,10 @@ async function removePrepared({ root = process.cwd() } = {}) {
|
|
|
313
325
|
if (removed) await removeEmptyParents(projectPath(root, relative), root);
|
|
314
326
|
}
|
|
315
327
|
|
|
328
|
+
const graphRemoved = await removeTreeIfUnchanged(root, GRAPH_PATH, config?.managedTrees?.[GRAPH_PATH], preserved);
|
|
329
|
+
changed = graphRemoved || changed;
|
|
330
|
+
if (graphRemoved) await removeEmptyParents(projectPath(root, GRAPH_PATH), root);
|
|
331
|
+
|
|
316
332
|
for (const [, targetRelative] of TEMPLATE_PATHS) {
|
|
317
333
|
const expectedHash = config?.managedFiles?.[targetRelative]
|
|
318
334
|
?? config?.templateHashes?.[targetRelative];
|
package/src/managed-block.mjs
CHANGED
|
@@ -8,7 +8,9 @@ export const MANAGED_BLOCK = `${START_MARKER}
|
|
|
8
8
|
- Keep one concise canonical Story contract: Goal, Domain, MUST, SHOULD, OUT, Decisions, Verify.
|
|
9
9
|
- Ask only blocking behavior questions; label safe defaults \`ASSUMED\` instead of silently inventing scope.
|
|
10
10
|
- Keep Tasks at most 30 non-empty lines and reference Story M/V IDs; HOW belongs to the repository-grounded plan.
|
|
11
|
-
-
|
|
11
|
+
- After G1, automatically initialize/resume the installed graph with \`node .ai-workflow/bin/graph.mjs\`. Follow the workflow graph reference; record node evidence, route failures and require graph readiness before G4. No separate npm dependency or Graph opt-in is needed.
|
|
12
|
+
- Within an assigned kit graph node, apply only its role/task procedure and return evidence to that run. Office assigns roles and launches agents; the kit graph still controls readiness, joins and failure routing. Do not recursively start full delivery workflows.
|
|
13
|
+
- Use compatible Superpowers focused TDD, diagnosis and fresh-verification skills with CE caller-owned planning, \`ce-simplify-code\`, report-only review and verified learning capture. Read the workflow skill-integration reference for exact modes, direct fallback and host limits. Do not nest end-to-end workflows or repeat approved plans. High-risk work retains G3.
|
|
12
14
|
- Do not merge non-trivial changes until the workflow's G4 question gate records that a human understands behavior, an invariant/failure path, and the evidence boundary.
|
|
13
15
|
- Gates are satisfied by evidence, not by assertion. Verify with \`node .ai-workflow/bin/check.mjs story <story-file>\` and report the exit code; exit 0 is the only pass.
|
|
14
16
|
${END_MARKER}`;
|