self-evolving-workflow 0.0.0-stage → 0.1.3
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 +27 -0
- package/README.md +90 -2
- package/dist/agent-memory-prompts.d.ts +13 -0
- package/dist/agent-memory-prompts.js +55 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +6 -0
- package/dist/closeout.d.ts +105 -0
- package/dist/closeout.js +479 -0
- package/dist/code.d.ts +39 -0
- package/dist/code.js +124 -0
- package/dist/common.d.ts +9 -0
- package/dist/common.js +42 -0
- package/dist/context-envelope.d.ts +59 -0
- package/dist/context-envelope.js +23 -0
- package/dist/host-adapters.d.ts +34 -0
- package/dist/host-adapters.js +151 -0
- package/dist/http.d.ts +3 -0
- package/dist/http.js +90 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +13 -0
- package/dist/knowledge-cli.d.ts +183 -0
- package/dist/knowledge-cli.js +654 -0
- package/dist/knowledge-reads.d.ts +71 -0
- package/dist/knowledge-reads.js +193 -0
- package/dist/memory.d.ts +97 -0
- package/dist/memory.js +250 -0
- package/dist/retrospective.d.ts +57 -0
- package/dist/retrospective.js +248 -0
- package/dist/search.d.ts +36 -0
- package/dist/search.js +112 -0
- package/dist/skill-addition.d.ts +25 -0
- package/dist/skill-addition.js +89 -0
- package/dist/skill-design.d.ts +96 -0
- package/dist/skill-design.js +226 -0
- package/dist/skill-replay.d.ts +55 -0
- package/dist/skill-replay.js +451 -0
- package/dist/skill-route.d.ts +30 -0
- package/dist/skill-route.js +75 -0
- package/dist/transcript-evidence.d.ts +3 -0
- package/dist/transcript-evidence.js +58 -0
- package/dist/upstream/chunker.d.ts +24 -0
- package/dist/upstream/chunker.js +96 -0
- package/dist/upstream/file-protocol.d.ts +45 -0
- package/dist/upstream/file-protocol.js +117 -0
- package/dist/upstream/frontmatter.d.ts +47 -0
- package/dist/upstream/frontmatter.js +86 -0
- package/dist/upstream/graph-search.d.ts +33 -0
- package/dist/upstream/graph-search.js +67 -0
- package/dist/upstream/l1-extraction.d.ts +26 -0
- package/dist/upstream/l1-extraction.js +405 -0
- package/dist/upstream/llm.d.ts +8 -0
- package/dist/upstream/llm.js +1 -0
- package/dist/upstream/merge.d.ts +50 -0
- package/dist/upstream/merge.js +153 -0
- package/dist/upstream/prompts.d.ts +53 -0
- package/dist/upstream/prompts.js +185 -0
- package/dist/upstream/search-utils.d.ts +34 -0
- package/dist/upstream/search-utils.js +55 -0
- package/dist/upstream/slug.d.ts +26 -0
- package/dist/upstream/slug.js +103 -0
- package/dist/upstream/template.d.ts +29 -0
- package/dist/upstream/template.js +80 -0
- package/dist/upstream/tokenize.d.ts +4 -0
- package/dist/upstream/tokenize.js +29 -0
- package/dist/wiki-change.d.ts +76 -0
- package/dist/wiki-change.js +299 -0
- package/dist/wiki-entry.d.ts +26 -0
- package/dist/wiki-entry.js +93 -0
- package/dist/wiki-ingest.d.ts +12 -0
- package/dist/wiki-ingest.js +126 -0
- package/dist/wiki-migration.d.ts +16 -0
- package/dist/wiki-migration.js +268 -0
- package/dist/wiki-tokens.d.ts +1 -0
- package/dist/wiki-tokens.js +46 -0
- package/dist/wiki.d.ts +103 -0
- package/dist/wiki.js +330 -0
- package/dist/workflow-cli.d.ts +2 -0
- package/dist/workflow-cli.js +258 -0
- package/dist/workflow-install.d.ts +36 -0
- package/dist/workflow-install.js +148 -0
- package/dist/workflow-knowledge.d.ts +16 -0
- package/dist/workflow-knowledge.js +24 -0
- package/dist/workflow-mcp.d.ts +2 -0
- package/dist/workflow-mcp.js +144 -0
- package/dist/workflow-names.d.ts +4 -0
- package/dist/workflow-names.js +18 -0
- package/dist/workflow-runtime.d.ts +622 -0
- package/dist/workflow-runtime.js +627 -0
- package/dist/workflow-skills.d.ts +48 -0
- package/dist/workflow-skills.js +141 -0
- package/package.json +76 -4
- package/skills/ew-odyssey/SKILL.md +237 -0
- package/skills/ew-odyssey/references/audit-artifacts.md +7 -0
- package/skills/ew-odyssey/references/odyssey-base-codex.md +3 -0
- package/skills/ew-odyssey/references/odyssey-base.md +278 -0
- package/skills/ew-odyssey/references/odyssey-debug.codex.md +305 -0
- package/skills/ew-odyssey/references/odyssey-debug.md +283 -0
- package/skills/ew-odyssey/references/odyssey-defensive.codex.md +395 -0
- package/skills/ew-odyssey/references/odyssey-defensive.md +369 -0
- package/skills/ew-odyssey/references/odyssey-improve.codex.md +270 -0
- package/skills/ew-odyssey/references/odyssey-improve.md +248 -0
- package/skills/ew-odyssey/references/odyssey-planex.codex.md +352 -0
- package/skills/ew-odyssey/references/odyssey-planex.md +312 -0
- package/skills/ew-odyssey/references/odyssey-review.codex.md +283 -0
- package/skills/ew-odyssey/references/odyssey-review.md +251 -0
- package/skills/ew-odyssey/references/odyssey-security.md +249 -0
- package/skills/ew-odyssey/references/odyssey-ui.codex.md +294 -0
- package/skills/ew-odyssey/references/odyssey-ui.md +250 -0
- package/skills/ew-odyssey/references/prepare/odyssey-debug.md +105 -0
- package/skills/ew-odyssey/references/prepare/odyssey-defensive.md +121 -0
- package/skills/ew-odyssey/references/prepare/odyssey-improve.md +93 -0
- package/skills/ew-odyssey/references/prepare/odyssey-planex.md +104 -0
- package/skills/ew-odyssey/references/prepare/odyssey-review.md +98 -0
- package/skills/ew-odyssey/references/prepare/odyssey-security.md +94 -0
- package/skills/ew-odyssey/references/prepare/odyssey-ui.md +87 -0
- package/skills/ew-orchestrate/SKILL.md +236 -0
- package/skills/ew-orchestrate/references/auto-policy.md +165 -0
- package/skills/ew-orchestrate/references/companion-route.md +52 -0
- package/skills/ew-orchestrate/references/ew-orchestrate.md +27 -0
- package/skills/ew-orchestrate/references/goal.md +53 -0
- package/skills/ew-orchestrate/references/knowledge-route.md +163 -0
- package/skills/ew-orchestrate/references/orchestrator-run-loop.md +36 -0
- package/skills/ew-orchestrate/references/planning.md +137 -0
- package/skills/ew-orchestrate/steps/ew-analyze/SKILL.md +62 -0
- package/skills/ew-orchestrate/steps/ew-analyze/references/boundary-grill.md +50 -0
- package/skills/ew-orchestrate/steps/ew-analyze/references/issue-gaps-analyze.md +59 -0
- package/skills/ew-orchestrate/steps/ew-analyze/references/prepare.md +42 -0
- package/skills/ew-orchestrate/steps/ew-analyze/references/workflow.md +401 -0
- package/skills/ew-orchestrate/steps/ew-brainstorm/SKILL.md +32 -0
- package/skills/ew-orchestrate/steps/ew-companion/SKILL.md +9 -0
- package/skills/ew-orchestrate/steps/ew-execute/SKILL.md +71 -0
- package/skills/ew-orchestrate/steps/ew-execute/references/prepare.md +69 -0
- package/skills/ew-orchestrate/steps/ew-execute/references/workflow.md +373 -0
- package/skills/ew-orchestrate/steps/ew-plan/SKILL.md +102 -0
- package/skills/ew-orchestrate/steps/ew-plan/references/boundary-grill.md +50 -0
- package/skills/ew-orchestrate/steps/ew-plan/references/prepare.md +51 -0
- package/skills/ew-orchestrate/steps/ew-plan/references/tdd.md +53 -0
- package/skills/ew-orchestrate/steps/ew-plan/references/workflow.md +278 -0
- package/skills/ew-orchestrate/steps/ew-review/SKILL.md +44 -0
- package/skills/ew-orchestrate/steps/ew-review/references/odyssey-base-codex.md +3 -0
- package/skills/ew-orchestrate/steps/ew-review/references/prepare.md +76 -0
- package/skills/ew-orchestrate/steps/ew-review/references/workflow.md +283 -0
- package/skills/ew-skill-design/SKILL.md +28 -0
- package/skills/ew-skill-design/references/package-contract.md +28 -0
- package/skills/ew-skill-design/references/validation.md +7 -0
- package/skills/team-swarm/SKILL.md +231 -0
- package/skills/team-swarm/references/mcp-coordination.md +10 -0
- package/skills/team-swarm/roles/analyst/role.md +181 -0
- package/skills/team-swarm/roles/ant/role.md +149 -0
- package/skills/team-swarm/roles/coordinator/commands/converge.md +154 -0
- package/skills/team-swarm/roles/coordinator/commands/init-swarm.md +134 -0
- package/skills/team-swarm/roles/coordinator/commands/iterate.md +202 -0
- package/skills/team-swarm/roles/coordinator/role.md +228 -0
- package/skills/team-swarm/roles/scorer/role.md +150 -0
- package/skills/team-swarm/scripts/aco.py +646 -0
- package/skills/team-swarm/scripts/pheromone.py +144 -0
- package/skills/team-swarm/scripts/scoring.py +111 -0
- package/skills/team-swarm/scripts/test_aco.py +606 -0
- package/skills/team-swarm/specs/ant-output-schema.md +127 -0
- package/skills/team-swarm/specs/convergence-criteria.md +108 -0
- package/skills/team-swarm/specs/pheromone-schema.md +125 -0
- package/skills/team-swarm/specs/swarm-config-template.json +71 -0
- package/skills/team-swarm/specs/swarm-protocol.md +123 -0
- package/skills/workflow-closeout/SKILL.md +10 -0
- package/skills/workflow-evolve/SKILL.md +79 -0
- package/skills/workflow-evolve/references/agy-gate.md +27 -0
- package/skills/workflow-evolve/references/auto-loop.md +20 -0
- package/skills/workflow-evolve/references/history-review.md +14 -0
- package/skills/workflow-evolve/scripts/codex-memory-replay.mjs +76 -0
- package/skills/workflow-evolve/scripts/codex-replay.mjs +1 -0
- package/skills/workflow-evolve/scripts/evolve-loop.mjs +259 -0
- package/skills/workflow-evolve/scripts/memory-codex-mcp.mjs +124 -0
- package/workflows/index.json +23 -0
package/dist/wiki.js
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
// Adapts the TencentDB Agent Memory Wiki manager and per-wiki index (MIT).
|
|
2
|
+
import { existsSync, lstatSync, readdirSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { basename, join, resolve } from 'node:path';
|
|
4
|
+
import { UndirectedGraph } from 'graphology';
|
|
5
|
+
import { InputError, NotFoundError, openDb, requireText, searchLimit, transaction } from './common.js';
|
|
6
|
+
import { parseFrontmatter, readSources } from './upstream/frontmatter.js';
|
|
7
|
+
import { graphMultiHopSearch } from './upstream/graph-search.js';
|
|
8
|
+
import { slugify } from './upstream/slug.js';
|
|
9
|
+
import { tokenizeWiki } from './wiki-tokens.js';
|
|
10
|
+
import { appliesToContext, contextSpecificity, readWikiEntryMetadata } from './wiki-entry.js';
|
|
11
|
+
export const structuralPages = new Set(['wiki/index.md', 'wiki/schema.md', 'wiki/purpose.md', 'wiki/log.md', 'wiki/overview.md']);
|
|
12
|
+
export function readWikiPages(root, entriesOnly = false) {
|
|
13
|
+
const pages = [];
|
|
14
|
+
function walk(dir, prefix) {
|
|
15
|
+
const entries = readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
|
|
16
|
+
for (const entry of entries) {
|
|
17
|
+
const full = join(dir, entry.name);
|
|
18
|
+
const path = `${prefix}/${entry.name}`;
|
|
19
|
+
if (!entriesOnly && entry.isDirectory() && entry.name !== 'media')
|
|
20
|
+
walk(full, path);
|
|
21
|
+
if (!entry.isFile() || !/\.md$/i.test(entry.name) || structuralPages.has(path.toLowerCase()))
|
|
22
|
+
continue;
|
|
23
|
+
const content = readFileSync(full, 'utf8').replace(/^\uFEFF/, '');
|
|
24
|
+
const { frontmatter, body } = parseFrontmatter(content);
|
|
25
|
+
const title = typeof frontmatter.title === 'string' && frontmatter.title.trim()
|
|
26
|
+
? frontmatter.title.trim()
|
|
27
|
+
: body.match(/^#\s+(.+)$/m)?.[1].trim() || basename(entry.name).replace(/\.md$/i, '').replaceAll('-', ' ');
|
|
28
|
+
const snippet = typeof frontmatter.description === 'string' && frontmatter.description.trim()
|
|
29
|
+
? frontmatter.description.trim()
|
|
30
|
+
: [...body.replace(/^#+\s+.*$/gm, '').trim()].slice(0, 160).join('').replace(/\s+/g, ' ');
|
|
31
|
+
pages.push({
|
|
32
|
+
id: path.slice(5, -3), title, type: frontmatter.type.toLowerCase(), path, snippet,
|
|
33
|
+
sources: readSources(content), body,
|
|
34
|
+
...(path.startsWith('wiki/entries/') ? { entry: readWikiEntryMetadata(path, frontmatter, body) } : {}),
|
|
35
|
+
links: [...body.matchAll(/\[\[([^\]|#]+)(?:#[^\]|]*)?(?:\|[^\]]*)?\]\]/g)].map(link => link[1].trim()),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (entriesOnly) {
|
|
40
|
+
const wiki = lstatSync(join(root, 'wiki'), { throwIfNoEntry: false });
|
|
41
|
+
if (!wiki)
|
|
42
|
+
return pages;
|
|
43
|
+
const entries = wiki.isDirectory() ? lstatSync(join(root, 'wiki', 'entries'), { throwIfNoEntry: false }) : undefined;
|
|
44
|
+
if (!wiki.isDirectory() || (entries && !entries.isDirectory()))
|
|
45
|
+
throw new InputError('Expected a regular Wiki entries directory');
|
|
46
|
+
if (entries)
|
|
47
|
+
walk(join(root, 'wiki', 'entries'), 'wiki/entries');
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
walk(join(root, 'wiki'), 'wiki');
|
|
51
|
+
}
|
|
52
|
+
return pages;
|
|
53
|
+
}
|
|
54
|
+
function findEntry(pages, id) {
|
|
55
|
+
const key = requireText(id, 'wiki entry ID').toLowerCase();
|
|
56
|
+
const matches = pages.filter(page => page.entry && (page.id.toLowerCase() === key || page.id.toLowerCase() === `entries/${key}` ||
|
|
57
|
+
page.entry.aliases.some(alias => alias.toLowerCase() === key)));
|
|
58
|
+
if (matches.length > 1)
|
|
59
|
+
throw new InputError(`Ambiguous Wiki entry ID: ${id}`);
|
|
60
|
+
const page = matches[0];
|
|
61
|
+
if (!page)
|
|
62
|
+
return null;
|
|
63
|
+
const { links: _links, ...entry } = page;
|
|
64
|
+
return entry;
|
|
65
|
+
}
|
|
66
|
+
function resolveEdges(pages) {
|
|
67
|
+
const visible = pages.filter(page => page.type !== 'query');
|
|
68
|
+
const byId = new Map(visible.map(page => [page.id.toLowerCase(), page.id]));
|
|
69
|
+
const aliases = new Map();
|
|
70
|
+
const stableAliases = new Map();
|
|
71
|
+
for (const page of visible) {
|
|
72
|
+
for (const key of new Set([slugify(page.title), slugify(page.id.split('/').at(-1))])) {
|
|
73
|
+
if (key)
|
|
74
|
+
aliases.set(key, aliases.has(key) ? undefined : page.id);
|
|
75
|
+
}
|
|
76
|
+
for (const alias of page.entry?.aliases ?? []) {
|
|
77
|
+
const key = alias.toLowerCase();
|
|
78
|
+
const previous = byId.get(key) ?? byId.get(`entries/${key}`) ?? stableAliases.get(key);
|
|
79
|
+
if (previous && previous !== page.id)
|
|
80
|
+
throw new InputError(`Duplicate Wiki alias: ${alias}`);
|
|
81
|
+
stableAliases.set(key, page.id);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return visible.flatMap(page => {
|
|
85
|
+
const targets = new Set();
|
|
86
|
+
for (const link of page.links) {
|
|
87
|
+
const key = link.replaceAll('\\', '/').replace(/^wiki\//i, '').replace(/\.md$/i, '');
|
|
88
|
+
const target = byId.get(key.toLowerCase()) ?? stableAliases.get(key.toLowerCase()) ?? aliases.get(slugify(key));
|
|
89
|
+
if (target && target !== page.id)
|
|
90
|
+
targets.add(target);
|
|
91
|
+
}
|
|
92
|
+
return [...targets].map(target => ({ source: page.id, target }));
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
export class Wiki {
|
|
96
|
+
root;
|
|
97
|
+
indexPath;
|
|
98
|
+
constructor(root) {
|
|
99
|
+
this.root = resolve(root);
|
|
100
|
+
this.indexPath = join(this.root, 'index.db');
|
|
101
|
+
}
|
|
102
|
+
async ingest(source, options) {
|
|
103
|
+
const { ingestWiki } = await import('./wiki-ingest.js');
|
|
104
|
+
return ingestWiki(this, source, options);
|
|
105
|
+
}
|
|
106
|
+
constraints(context = {}) {
|
|
107
|
+
if (!existsSync(join(this.root, 'wiki')))
|
|
108
|
+
return [];
|
|
109
|
+
return readWikiPages(this.root).filter(page => page.entry?.mode === 'constraint' && page.entry.status === 'active' && appliesToContext(page.entry, context, page.body)).sort((left, right) => contextSpecificity(right.entry, context) - contextSpecificity(left.entry, context))
|
|
110
|
+
.map(({ links: _links, ...page }) => page);
|
|
111
|
+
}
|
|
112
|
+
getEntry(id, options = {}) {
|
|
113
|
+
if (!existsSync(join(this.root, 'wiki')))
|
|
114
|
+
return null;
|
|
115
|
+
const entry = findEntry(readWikiPages(this.root), id);
|
|
116
|
+
if (entry && options.knowledgeReads) {
|
|
117
|
+
options.knowledgeReads.recordRead({
|
|
118
|
+
kind: 'wiki', id: entry.id, fromSearchId: options.fromSearchId,
|
|
119
|
+
content: entry.body,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return entry;
|
|
123
|
+
}
|
|
124
|
+
visibleReferences(context) {
|
|
125
|
+
return readWikiPages(this.root, true).filter(page => page.entry?.mode === 'reference' &&
|
|
126
|
+
page.entry.status === 'active' && appliesToContext(page.entry, context, page.body));
|
|
127
|
+
}
|
|
128
|
+
getReference(id, context = {}, options = {}) {
|
|
129
|
+
const entry = findEntry(this.visibleReferences(context), id);
|
|
130
|
+
if (entry && options.knowledgeReads) {
|
|
131
|
+
options.knowledgeReads.recordRead({
|
|
132
|
+
kind: 'wiki', id: entry.id, fromSearchId: options.fromSearchId,
|
|
133
|
+
content: entry.body,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return entry;
|
|
137
|
+
}
|
|
138
|
+
references(query, context = {}, options = {}) {
|
|
139
|
+
if (existsSync(this.indexPath)) {
|
|
140
|
+
const pages = new Map(readWikiPages(this.root, true).map(page => [page.id, page]));
|
|
141
|
+
const db = openDb(this.indexPath, true);
|
|
142
|
+
try {
|
|
143
|
+
db.exec('BEGIN');
|
|
144
|
+
const result = searchIndex(db, query, {
|
|
145
|
+
...options,
|
|
146
|
+
limit: 100,
|
|
147
|
+
includeHistory: false,
|
|
148
|
+
entryMode: 'reference',
|
|
149
|
+
});
|
|
150
|
+
const filtered = result.results.filter(hit => {
|
|
151
|
+
const page = pages.get(hit.id);
|
|
152
|
+
return page?.entry?.mode === 'reference' && page.entry.status === 'active' &&
|
|
153
|
+
appliesToContext(page.entry, context, page.body);
|
|
154
|
+
});
|
|
155
|
+
const limit = searchLimit(options.limit);
|
|
156
|
+
const results = filtered
|
|
157
|
+
.map(hit => ({ ...hit, score: hit.score + contextSpecificity(pages.get(hit.id).entry, context) / 100 }))
|
|
158
|
+
.sort((left, right) => right.score - left.score || left.id.localeCompare(right.id))
|
|
159
|
+
.slice(0, limit);
|
|
160
|
+
const included = new Set(results.map(result => result.id));
|
|
161
|
+
return {
|
|
162
|
+
results,
|
|
163
|
+
links: result.links.filter(link => {
|
|
164
|
+
const source = link.source.replace(/^wiki\//, '').replace(/\.md$/i, '');
|
|
165
|
+
const target = link.target.replace(/^wiki\//, '').replace(/\.md$/i, '');
|
|
166
|
+
return included.has(source) && included.has(target);
|
|
167
|
+
}),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
finally {
|
|
171
|
+
db.close();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const db = openDb(':memory:');
|
|
175
|
+
try {
|
|
176
|
+
transaction(db, () => indexPages(db, this.visibleReferences(context)));
|
|
177
|
+
return searchIndex(db, query, options);
|
|
178
|
+
}
|
|
179
|
+
finally {
|
|
180
|
+
db.close();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
getEntryByExactBody(body) {
|
|
184
|
+
const matches = this.getEntriesByExactBody(body);
|
|
185
|
+
return matches.length === 1 ? matches[0] : null;
|
|
186
|
+
}
|
|
187
|
+
getEntriesByExactBody(body) {
|
|
188
|
+
if (!existsSync(join(this.root, 'wiki')))
|
|
189
|
+
return [];
|
|
190
|
+
const normalized = body.trim().replace(/\s+/g, ' ');
|
|
191
|
+
return readWikiPages(this.root).filter(page => page.entry?.status === 'active' && page.body.trim().replace(/\s+/g, ' ') === normalized);
|
|
192
|
+
}
|
|
193
|
+
build() {
|
|
194
|
+
if (!existsSync(join(this.root, 'wiki')))
|
|
195
|
+
throw new NotFoundError('Missing wiki/ directory');
|
|
196
|
+
const db = openDb(this.indexPath);
|
|
197
|
+
try {
|
|
198
|
+
return transaction(db, () => indexPages(db, readWikiPages(this.root)));
|
|
199
|
+
}
|
|
200
|
+
finally {
|
|
201
|
+
db.close();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
search(query, options = {}) {
|
|
205
|
+
if (!existsSync(this.indexPath))
|
|
206
|
+
throw new NotFoundError('Wiki index missing. Run wiki build first.');
|
|
207
|
+
const db = openDb(this.indexPath, true);
|
|
208
|
+
try {
|
|
209
|
+
db.exec('BEGIN');
|
|
210
|
+
return searchIndex(db, query, options);
|
|
211
|
+
}
|
|
212
|
+
finally {
|
|
213
|
+
db.close();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function indexPages(db, pages) {
|
|
218
|
+
const edges = resolveEdges(pages);
|
|
219
|
+
db.exec(`
|
|
220
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS wiki_fts USING fts5(
|
|
221
|
+
page_id UNINDEXED, title_tok, content_tok, tokenize='unicode61 remove_diacritics 0'
|
|
222
|
+
);
|
|
223
|
+
CREATE TABLE IF NOT EXISTS page_meta (
|
|
224
|
+
page_id TEXT PRIMARY KEY, title TEXT, type TEXT, rel_path TEXT, snippet TEXT
|
|
225
|
+
);
|
|
226
|
+
CREATE TABLE IF NOT EXISTS page_sources (page_id TEXT PRIMARY KEY, sources TEXT NOT NULL);
|
|
227
|
+
CREATE TABLE IF NOT EXISTS wiki_entries (
|
|
228
|
+
page_id TEXT PRIMARY KEY, status TEXT NOT NULL, metadata TEXT NOT NULL
|
|
229
|
+
);
|
|
230
|
+
CREATE TABLE IF NOT EXISTS graph_edge (
|
|
231
|
+
source_id TEXT NOT NULL, target_id TEXT NOT NULL, PRIMARY KEY (source_id, target_id)
|
|
232
|
+
);
|
|
233
|
+
DELETE FROM wiki_fts;
|
|
234
|
+
DELETE FROM page_meta;
|
|
235
|
+
DELETE FROM page_sources;
|
|
236
|
+
DELETE FROM wiki_entries;
|
|
237
|
+
DELETE FROM graph_edge;
|
|
238
|
+
`);
|
|
239
|
+
const fts = db.prepare('INSERT INTO wiki_fts(page_id, title_tok, content_tok) VALUES (?, ?, ?)');
|
|
240
|
+
const meta = db.prepare('INSERT INTO page_meta(page_id, title, type, rel_path, snippet) VALUES (?, ?, ?, ?, ?)');
|
|
241
|
+
const source = db.prepare('INSERT INTO page_sources(page_id, sources) VALUES (?, ?)');
|
|
242
|
+
const edge = db.prepare('INSERT INTO graph_edge(source_id, target_id) VALUES (?, ?)');
|
|
243
|
+
const entry = db.prepare('INSERT INTO wiki_entries(page_id, status, metadata) VALUES (?, ?, ?)');
|
|
244
|
+
for (const page of pages) {
|
|
245
|
+
fts.run(page.id, tokenizeWiki(page.title).join(' '), tokenizeWiki(page.body).join(' '));
|
|
246
|
+
meta.run(page.id, page.title, page.type, page.path, page.snippet);
|
|
247
|
+
source.run(page.id, JSON.stringify(page.sources));
|
|
248
|
+
if (page.entry)
|
|
249
|
+
entry.run(page.id, page.entry.status, JSON.stringify(page.entry));
|
|
250
|
+
}
|
|
251
|
+
for (const { source, target } of edges)
|
|
252
|
+
edge.run(source, target);
|
|
253
|
+
return { pages: pages.length, edges: edges.length };
|
|
254
|
+
}
|
|
255
|
+
function searchIndex(db, query, options) {
|
|
256
|
+
const tokens = [...new Set(tokenizeWiki(requireText(query, 'query')))];
|
|
257
|
+
const limit = searchLimit(options.limit);
|
|
258
|
+
const { hop = 0, decay = 0.5 } = options;
|
|
259
|
+
if (!Number.isInteger(hop) || hop < 0 || hop > 5) {
|
|
260
|
+
throw new InputError('hop must be an integer between 0 and 5');
|
|
261
|
+
}
|
|
262
|
+
if (!Number.isFinite(decay) || decay <= 0 || decay > 1) {
|
|
263
|
+
throw new InputError('decay must be greater than 0 and at most 1');
|
|
264
|
+
}
|
|
265
|
+
if (!tokens.length)
|
|
266
|
+
return { results: [], links: [] };
|
|
267
|
+
const expression = tokens.map(token => '"' + token.replaceAll('"', '""') + '"*').join(' OR ');
|
|
268
|
+
const entries = db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='wiki_entries'").get();
|
|
269
|
+
const visibility = entries && !options.includeHistory
|
|
270
|
+
? "AND page_id NOT IN (SELECT page_id FROM wiki_entries WHERE status <> 'active')"
|
|
271
|
+
: '';
|
|
272
|
+
const modeVisibility = entries && options.entryMode
|
|
273
|
+
? "AND page_id IN (SELECT page_id FROM wiki_entries WHERE json_extract(metadata, '$.mode') = ?)"
|
|
274
|
+
: '';
|
|
275
|
+
const seedArgs = options.entryMode ? [expression, options.entryMode, hop ? limit * 2 : limit] : [expression, hop ? limit * 2 : limit];
|
|
276
|
+
const seeds = db.prepare(`
|
|
277
|
+
SELECT page_id AS id, -bm25(wiki_fts, 0.0, 5.0, 1.0) AS score
|
|
278
|
+
FROM wiki_fts WHERE wiki_fts MATCH ? ${visibility} ${modeVisibility} ORDER BY score DESC, page_id LIMIT ?
|
|
279
|
+
`).all(...seedArgs);
|
|
280
|
+
if (!seeds.length)
|
|
281
|
+
return { results: [], links: [] };
|
|
282
|
+
return readHits(db, seeds, limit, hop, decay, Boolean(entries), Boolean(options.includeHistory), options.entryMode);
|
|
283
|
+
}
|
|
284
|
+
function readHits(db, seeds, limit, hop, decay, hasEntries, includeHistory, entryMode) {
|
|
285
|
+
const hasSources = db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='page_sources'").get();
|
|
286
|
+
const modeVisibility = hasEntries && entryMode
|
|
287
|
+
? "AND json_extract(e.metadata, '$.mode') = ?"
|
|
288
|
+
: '';
|
|
289
|
+
const pageArgs = entryMode ? [entryMode] : [];
|
|
290
|
+
const rows = db.prepare(`SELECT m.page_id AS id, m.title, m.type, m.rel_path AS path, m.snippet,
|
|
291
|
+
${hasSources ? "COALESCE(s.sources, '[]')" : "'[]'"} AS sources,
|
|
292
|
+
${hasEntries ? 'e.metadata' : 'NULL'} AS metadata
|
|
293
|
+
FROM page_meta m ${hasSources ? 'LEFT JOIN page_sources s USING(page_id)' : ''}
|
|
294
|
+
${hasEntries ? 'LEFT JOIN wiki_entries e USING(page_id)' : ''}
|
|
295
|
+
${hasEntries && !includeHistory ? `WHERE (e.status IS NULL OR e.status = 'active') ${modeVisibility}` : modeVisibility ? `WHERE ${modeVisibility.slice(4)}` : ''}`)
|
|
296
|
+
.all(...pageArgs);
|
|
297
|
+
const pages = new Map(rows.map(({ metadata, ...row }) => [row.id, {
|
|
298
|
+
...row, path: row.path.replaceAll('\\', '/'), sources: JSON.parse(row.sources),
|
|
299
|
+
...(metadata ? { entry: JSON.parse(metadata) } : {}),
|
|
300
|
+
}]));
|
|
301
|
+
const graph = new UndirectedGraph();
|
|
302
|
+
const outgoing = new Map();
|
|
303
|
+
for (const page of pages.values()) {
|
|
304
|
+
graph.addNode(page.id, { label: page.title });
|
|
305
|
+
outgoing.set(page.id, new Set());
|
|
306
|
+
}
|
|
307
|
+
const edges = db.prepare('SELECT source_id AS source, target_id AS target FROM graph_edge ORDER BY source_id, target_id')
|
|
308
|
+
.all();
|
|
309
|
+
for (const { source, target } of edges) {
|
|
310
|
+
if (source === target || !graph.hasNode(source) || !graph.hasNode(target))
|
|
311
|
+
continue;
|
|
312
|
+
graph.mergeUndirectedEdge(source, target);
|
|
313
|
+
outgoing.get(source).add(target);
|
|
314
|
+
}
|
|
315
|
+
const expanded = graphMultiHopSearch(graph, seeds, { hop, decay, minScore: 0 }).slice(0, limit);
|
|
316
|
+
const results = expanded.map(({ id, score, hop, via }) => ({
|
|
317
|
+
...pages.get(id), score, hop, via,
|
|
318
|
+
related: graph.neighbors(id).sort((a, b) => graph.degree(b) - graph.degree(a) || a.localeCompare(b)).slice(0, 10)
|
|
319
|
+
.map(neighbor => ({
|
|
320
|
+
id: neighbor,
|
|
321
|
+
title: pages.get(neighbor).title,
|
|
322
|
+
path: pages.get(neighbor).path,
|
|
323
|
+
direction: outgoing.get(id).has(neighbor) ? (outgoing.get(neighbor).has(id) ? 'both' : 'out') : 'in',
|
|
324
|
+
})),
|
|
325
|
+
}));
|
|
326
|
+
const included = new Set(results.map(result => result.id));
|
|
327
|
+
const links = edges.filter(({ source, target }) => included.has(source) && included.has(target))
|
|
328
|
+
.map(({ source, target }) => ({ source: pages.get(source).path, target: pages.get(target).path }));
|
|
329
|
+
return { results, links };
|
|
330
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { existsSync, lstatSync, readFileSync, realpathSync } from 'node:fs';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { join, resolve } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { parseArgs } from 'node:util';
|
|
8
|
+
import { CodeGraph } from './code.js';
|
|
9
|
+
import { InputError, requireText } from './common.js';
|
|
10
|
+
import { knowledgeHelp, knowledgeOptions, runKnowledgeCli } from './knowledge-cli.js';
|
|
11
|
+
import { WorkflowStore, workflowId } from './workflow-runtime.js';
|
|
12
|
+
import { bindWorkflowSkill, commandNames, workflowHash } from './workflow-skills.js';
|
|
13
|
+
import { serveWorkflowRun } from './workflow-mcp.js';
|
|
14
|
+
import { Wiki } from './wiki.js';
|
|
15
|
+
import { migrateLegacyWiki } from './wiki-migration.js';
|
|
16
|
+
import { wikiLookupScope } from './workflow-knowledge.js';
|
|
17
|
+
import { installSkills, installWorkflow, workflowDocument, workflowDocuments } from './workflow-install.js';
|
|
18
|
+
const string = { type: 'string' };
|
|
19
|
+
const strings = { type: 'string', multiple: true };
|
|
20
|
+
const bool = { type: 'boolean' };
|
|
21
|
+
const options = {
|
|
22
|
+
root: string, db: string, id: string, session: string, run: string, actor: string, participant: string,
|
|
23
|
+
'request-id': string, reason: string, evidence: strings, json: bool, help: { ...bool, short: 'h' }, advance: bool,
|
|
24
|
+
'expected-orchestration-revision': string, 'expected-run-revision': string,
|
|
25
|
+
'definition-of-done': string, chain: strings, 'step-id': string, command: string, arg: strings, 'after-step': string,
|
|
26
|
+
'decision-ref': string, 'goal-ref': string, stage: string, gate: strings, from: string, verdict: string, summary: string,
|
|
27
|
+
to: string, tool: string, role: string, mode: string, model: string, cd: string, 'prompt-file': string, path: string,
|
|
28
|
+
project: string, global: bool, apply: bool, 'knowhow-only': bool,
|
|
29
|
+
scope: string, host: string, skill: strings, yes: bool,
|
|
30
|
+
};
|
|
31
|
+
const usage = [
|
|
32
|
+
'evolve session open <objective> --id <id> [--chain <commands>] --actor <id>',
|
|
33
|
+
'evolve session status|amend|complete --session <id>',
|
|
34
|
+
'evolve session list|resume-view',
|
|
35
|
+
'evolve session chain insert|replace|skip --session <id> --step-id <id>',
|
|
36
|
+
'evolve run next|brief|check|skill-read|artifact-read|complete|transition|cancel|decide --session <id>',
|
|
37
|
+
'evolve run artifact-read <run> <alias> --session <id> [--scope <Wiki scope JSON>]',
|
|
38
|
+
'evolve team controller|assign|report|cancel|list --session <id> --run <id>',
|
|
39
|
+
'evolve skills [install <package>... | validate <command>]',
|
|
40
|
+
'evolve install [--scope project|user | --global] [--host codex|claude] [--skill <package>] [--root <project>] [--yes]',
|
|
41
|
+
'evolve workflows [show <id>]',
|
|
42
|
+
'evolve knowledge import [<source>] [--root <destination>] [--project <legacy-id>] [--global] [--knowhow-only] [--apply]',
|
|
43
|
+
'evolve mcp --session <id> --run <id>',
|
|
44
|
+
'evolve delegate <prompt> --to codex|agy --mode analysis|write',
|
|
45
|
+
].join('\n');
|
|
46
|
+
const knowledgeCommands = new Set(['code', 'wiki', 'memory', 'search', 'context', 'serve', 'closeout', 'skill-design']);
|
|
47
|
+
const skillEvolutionActions = new Set(['review', 'draft', 'replay', 'apply', 'rollback']);
|
|
48
|
+
async function main(argv) {
|
|
49
|
+
// 路由保留选项及参数顺序,具体命令仍使用各自的严格参数定义。
|
|
50
|
+
const { positionals: [group, action], tokens } = parseArgs({
|
|
51
|
+
args: argv, options: { ...knowledgeOptions, ...options }, allowPositionals: true, strict: false, tokens: true,
|
|
52
|
+
});
|
|
53
|
+
if (knowledgeCommands.has(group) || (group === 'session' && action === 'review')) {
|
|
54
|
+
return runKnowledgeCli(argv, 'evolve');
|
|
55
|
+
}
|
|
56
|
+
if (group === 'skills' && skillEvolutionActions.has(action)) {
|
|
57
|
+
const command = tokens.find(token => token.kind === 'positional');
|
|
58
|
+
if (command)
|
|
59
|
+
argv[command.index] = 'evolve';
|
|
60
|
+
return runKnowledgeCli(argv, 'evolve');
|
|
61
|
+
}
|
|
62
|
+
return runWorkflowCli(argv);
|
|
63
|
+
}
|
|
64
|
+
function revision(value) {
|
|
65
|
+
if (value === undefined)
|
|
66
|
+
return;
|
|
67
|
+
const result = Number(value);
|
|
68
|
+
if (!/^\d+$/.test(value) || !Number.isSafeInteger(result))
|
|
69
|
+
throw new InputError('Invalid revision: ' + value);
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
function select(value, choices, label) {
|
|
73
|
+
if (choices.some(item => item === value))
|
|
74
|
+
return value;
|
|
75
|
+
throw new InputError(label + ' must be one of: ' + choices.join(', '));
|
|
76
|
+
}
|
|
77
|
+
function importLegacyKnowledge(root, sourceArg, values) {
|
|
78
|
+
const scope = values.global ? 'global' : 'project';
|
|
79
|
+
const source = realpathSync(sourceArg ?? (values.global ? join(homedir(), '.maestro') : root));
|
|
80
|
+
if (!lstatSync(source).isDirectory())
|
|
81
|
+
throw new InputError('Legacy knowledge source must be a directory');
|
|
82
|
+
const destination = values.root ? root : values.global ? join(homedir(), '.evolve') : source;
|
|
83
|
+
const project = values.project ?? (values.global && !sourceArg ? 'maestro-global' : 'legacy-' + workflowHash(source).slice(7, 23));
|
|
84
|
+
const entries = migrateLegacyWiki(new Wiki(destination), source, project, values.apply, {
|
|
85
|
+
scope, knowhowOnly: values['knowhow-only'],
|
|
86
|
+
});
|
|
87
|
+
return { source, destination, project, scope, applied: values.apply ?? false,
|
|
88
|
+
new_entries: entries.filter(entry => !entry.existing).length,
|
|
89
|
+
existing_entries: entries.filter(entry => entry.existing).length,
|
|
90
|
+
needs_review: entries.filter(entry => entry.status === 'needs_review').length, entries };
|
|
91
|
+
}
|
|
92
|
+
function delegate(root, values, args) {
|
|
93
|
+
const tool = select(values.to ?? values.tool ?? 'codex', ['codex', 'agy'], 'executor');
|
|
94
|
+
const mode = select(values.mode ?? 'analysis', ['analysis', 'write'], 'mode');
|
|
95
|
+
const cwd = resolve(root, values.cd ?? '.');
|
|
96
|
+
const prompt = requireText(values['prompt-file'] ? readFileSync(resolve(cwd, values['prompt-file']), 'utf8') : args.join(' '), 'prompt');
|
|
97
|
+
const cli = tool === 'codex'
|
|
98
|
+
? process.env.CODEX_REPLAY_EXECUTABLE ?? (process.platform === 'win32' ? 'codex.exe' : 'codex')
|
|
99
|
+
: process.env.AGY_EXECUTABLE ?? 'agy';
|
|
100
|
+
const model = values.model ? ['--model', values.model] : [];
|
|
101
|
+
if ((values.session === undefined) !== (values.run === undefined))
|
|
102
|
+
throw new InputError('Supply both Session and Run identifiers');
|
|
103
|
+
const bound = values.session && values.run ? [
|
|
104
|
+
'-c', 'mcp_servers.evolve_run.command=' + JSON.stringify(process.execPath),
|
|
105
|
+
'-c', 'mcp_servers.evolve_run.args=' + JSON.stringify([fileURLToPath(import.meta.url), 'mcp', '--root', root,
|
|
106
|
+
'--session', workflowId(values.session, 'Session ID'), '--run', workflowId(values.run, 'Run ID')]),
|
|
107
|
+
'-c', 'mcp_servers.evolve_run.required=true',
|
|
108
|
+
'-c', 'mcp_servers.evolve_run.default_tools_approval_mode="writes"',
|
|
109
|
+
] : [];
|
|
110
|
+
if (bound.length && tool !== 'codex')
|
|
111
|
+
throw new InputError('Use Codex for a bound Evolve worker');
|
|
112
|
+
const childArgs = tool === 'codex'
|
|
113
|
+
? ['-a', 'never', 'exec', '--ephemeral', '--ignore-user-config', '--skip-git-repo-check',
|
|
114
|
+
'--sandbox', mode === 'analysis' ? 'read-only' : 'workspace-write', ...model, ...bound, '-']
|
|
115
|
+
: ['--mode', mode === 'analysis' ? 'plan' : 'accept-edits', '--output-format', 'text', ...model, '--print=' + prompt];
|
|
116
|
+
const child = spawnSync(cli, childArgs, { cwd, input: tool === 'codex' ? prompt : undefined, encoding: 'utf8',
|
|
117
|
+
windowsHide: true, stdio: ['pipe', 'pipe', 'inherit'], maxBuffer: 8 * 1024 * 1024 });
|
|
118
|
+
if (child.error)
|
|
119
|
+
throw child.error;
|
|
120
|
+
if (child.status !== 0)
|
|
121
|
+
throw new InputError(tool + ' exited with status ' + child.status);
|
|
122
|
+
return { executor: tool, output: child.stdout };
|
|
123
|
+
}
|
|
124
|
+
async function runWorkflowCli(argv) {
|
|
125
|
+
const { positionals: [group, action, ...args], values } = parseArgs({ options, args: argv, allowPositionals: true });
|
|
126
|
+
if (!group || values.help) {
|
|
127
|
+
process.stdout.write(usage + '\n\n' + knowledgeHelp('evolve'));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const root = resolve(values.root ?? '.');
|
|
131
|
+
const print = (value) => process.stdout.write(JSON.stringify(value, null, 2) + '\n');
|
|
132
|
+
if (group === 'capabilities')
|
|
133
|
+
return print({ schema_version: 'evolve-workflow/1.0', session: 'evolve-session/1.0',
|
|
134
|
+
features: ['revision-cas', 'request-receipts', 'git-skill-binding', 'atomic-artifact-seal', 'run-knowledge', 'swarm-coordination'] });
|
|
135
|
+
if (group === 'knowledge') {
|
|
136
|
+
if (action !== 'import' || args.length > 1) {
|
|
137
|
+
throw new InputError('Usage: evolve knowledge import [<source>] [--knowhow-only] [--apply]');
|
|
138
|
+
}
|
|
139
|
+
return print(importLegacyKnowledge(root, args[0], values));
|
|
140
|
+
}
|
|
141
|
+
if (group === 'workflows') {
|
|
142
|
+
if (!action)
|
|
143
|
+
return print(workflowDocuments());
|
|
144
|
+
if (action === 'show' && args.length === 1) {
|
|
145
|
+
process.stdout.write(workflowDocument(args[0]));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
throw new InputError('Usage: evolve workflows [show <id>]');
|
|
149
|
+
}
|
|
150
|
+
if (group === 'install' && !action) {
|
|
151
|
+
if (values.global && values.scope === 'project')
|
|
152
|
+
throw new InputError('--global selects the user scope');
|
|
153
|
+
const scope = values.global ? 'user'
|
|
154
|
+
: values.scope === undefined ? undefined : select(values.scope, ['project', 'user'], 'Install scope');
|
|
155
|
+
return print(await installWorkflow(root, {
|
|
156
|
+
scope,
|
|
157
|
+
host: values.host === undefined ? undefined : select(values.host, ['codex', 'claude'], 'Install host'),
|
|
158
|
+
skill: values.skill, yes: values.yes,
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
161
|
+
if (group === 'skills') {
|
|
162
|
+
if (action === 'install')
|
|
163
|
+
return print(installSkills(root, args));
|
|
164
|
+
if (action === 'validate')
|
|
165
|
+
return print(bindWorkflowSkill(root, requireText(args[0], 'Skill command')));
|
|
166
|
+
if (!action)
|
|
167
|
+
return print(commandNames.map(command => ({ command })));
|
|
168
|
+
throw new InputError('Unknown Skills command: ' + action);
|
|
169
|
+
}
|
|
170
|
+
if (group === 'delegate')
|
|
171
|
+
return print(delegate(root, values, action === undefined ? args : [action, ...args]));
|
|
172
|
+
const store = new WorkflowStore(root);
|
|
173
|
+
const id = () => workflowId(values.session ?? values.id, 'Session ID');
|
|
174
|
+
const runId = () => workflowId(values.run ?? args[0], 'Run ID');
|
|
175
|
+
const mutation = () => {
|
|
176
|
+
const actor = workflowId(values.actor ?? values.participant, 'actor');
|
|
177
|
+
if (values.participant && values.participant !== actor)
|
|
178
|
+
throw new InputError('Participant must match the actor');
|
|
179
|
+
return { actor, requestId: values['request-id'], revision: revision(values['expected-orchestration-revision']),
|
|
180
|
+
runRevision: revision(values['expected-run-revision']), evidence: values.evidence, reason: values.reason };
|
|
181
|
+
};
|
|
182
|
+
const makeStep = (command, step) => ({
|
|
183
|
+
id: step, command, args: values.arg ?? [], decision_ref: values['decision-ref'],
|
|
184
|
+
goal_ref: values['goal-ref'], stage: values.stage,
|
|
185
|
+
});
|
|
186
|
+
try {
|
|
187
|
+
if (group === 'session') {
|
|
188
|
+
if (action === 'list' || action === 'resume-view')
|
|
189
|
+
return print(store.list());
|
|
190
|
+
if (action === 'status')
|
|
191
|
+
return print(store.status(id()));
|
|
192
|
+
if (action === 'amend')
|
|
193
|
+
return print(store.amend(id(), requireText(args[0], 'amended objective'), values['definition-of-done'], mutation()));
|
|
194
|
+
if (action === 'open') {
|
|
195
|
+
const chain = [...values.chain ?? [], ...args.slice(1)].flatMap(value => value.split(/[\s,]+/)).filter(Boolean);
|
|
196
|
+
const steps = chain.map((command, index) => ({ id: command + '-' + (index + 1), command, args: [] }));
|
|
197
|
+
const session = store.open(id(), requireText(args[0], 'objective'), values['definition-of-done'] ?? '', steps, mutation());
|
|
198
|
+
if (existsSync(join(root, '.git'))) {
|
|
199
|
+
try {
|
|
200
|
+
await new CodeGraph(root).refresh();
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
console.warn('Code graph refresh failed: ' + (error instanceof Error ? error.message : String(error)));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return print(session);
|
|
207
|
+
}
|
|
208
|
+
if (action === 'chain') {
|
|
209
|
+
const change = select(args[0], ['insert', 'replace', 'skip'], 'chain action');
|
|
210
|
+
return print(store.chain(id(), change, makeStep(change === 'skip' ? '' : requireText(values.command, 'command'), workflowId(values['step-id'], 'step ID')), values['after-step'], mutation()));
|
|
211
|
+
}
|
|
212
|
+
if (action === 'complete')
|
|
213
|
+
return print(store.completeSession(id(), mutation()));
|
|
214
|
+
}
|
|
215
|
+
if (group === 'run') {
|
|
216
|
+
const gates = values.gate ?? [];
|
|
217
|
+
if (action === 'next' || action === 'create')
|
|
218
|
+
return print(store.next(id(), mutation(), gates, values['step-id']));
|
|
219
|
+
if (action === 'brief')
|
|
220
|
+
return print(store.brief(id(), runId()));
|
|
221
|
+
if (action === 'check')
|
|
222
|
+
return print(store.check(id(), runId(), gates));
|
|
223
|
+
if (action === 'skill-read')
|
|
224
|
+
return print(store.readSkill(id(), runId(), values.from, args[1]));
|
|
225
|
+
if (action === 'artifact-read')
|
|
226
|
+
return print(store.readArtifact(id(), runId(), requireText(args[1], 'artifact ID or alias'), wikiLookupScope(values.scope === undefined ? undefined : JSON.parse(values.scope))));
|
|
227
|
+
if (action === 'complete')
|
|
228
|
+
return print(store.completeRun(id(), runId(), requireText(values.summary, 'Run summary'), select(values.verdict ?? 'done', ['done', 'done_with_concerns'], 'verdict'), gates, mutation()));
|
|
229
|
+
if (action === 'transition' || action === 'cancel')
|
|
230
|
+
return print(store.transition(id(), runId(), action === 'cancel' ? 'cancelled' : select(args[1], ['running', 'blocked', 'failed'], 'Run status'), requireText(values.reason ?? values.summary, 'transition reason'), mutation()));
|
|
231
|
+
if (action === 'decide')
|
|
232
|
+
return print(store.decide(id(), workflowId(args[0], 'decision ID'), select(values.verdict, ['proceed', 'fix', 'escalate'], 'decision'), requireText(values.summary, 'decision summary'), mutation()));
|
|
233
|
+
}
|
|
234
|
+
if (group === 'team') {
|
|
235
|
+
if (action === 'list')
|
|
236
|
+
return print(store.teamList(id(), runId()));
|
|
237
|
+
if (action === 'controller')
|
|
238
|
+
return print(store.swarmController(id(), runId()));
|
|
239
|
+
const operation = select(action, ['assign', 'report', 'cancel'], 'team operation');
|
|
240
|
+
return print(store.team(id(), workflowId(values.run, 'Run ID'), operation, {
|
|
241
|
+
id: workflowId(values.id ?? args[0], 'assignment ID'),
|
|
242
|
+
role: operation === 'assign' ? workflowId(values.role, 'worker role') : '',
|
|
243
|
+
path: operation === 'assign' ? requireText(values.path, 'artifact path') : '',
|
|
244
|
+
...(operation === 'report' ? { result: { summary: requireText(values.summary, 'assignment summary'), sha256: '' } } : {}),
|
|
245
|
+
}, mutation()));
|
|
246
|
+
}
|
|
247
|
+
if (group === 'mcp')
|
|
248
|
+
return await serveWorkflowRun(store, id(), workflowId(values.run, 'Run ID'), values.db);
|
|
249
|
+
throw new InputError('Unknown workflow command: ' + [group, action].filter(Boolean).join(' '));
|
|
250
|
+
}
|
|
251
|
+
finally {
|
|
252
|
+
store.close();
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
main(process.argv.slice(2)).catch((error) => {
|
|
256
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
257
|
+
process.exitCode = 1;
|
|
258
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
declare const hosts: {
|
|
2
|
+
readonly codex: readonly [".codex", "AGENTS.md"];
|
|
3
|
+
readonly claude: readonly [".claude", "CLAUDE.md"];
|
|
4
|
+
};
|
|
5
|
+
type InstallScope = 'project' | 'user';
|
|
6
|
+
type InstallHost = keyof typeof hosts;
|
|
7
|
+
interface InstallOptions {
|
|
8
|
+
scope?: InstallScope;
|
|
9
|
+
host?: InstallHost;
|
|
10
|
+
skill?: string[];
|
|
11
|
+
yes?: boolean;
|
|
12
|
+
}
|
|
13
|
+
interface WorkflowDocument {
|
|
14
|
+
id: string;
|
|
15
|
+
path: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function workflowDocuments(): WorkflowDocument[];
|
|
18
|
+
export declare function workflowDocument(id: string): string;
|
|
19
|
+
export declare function installSkills(root: string, requested: string[]): {
|
|
20
|
+
skills: string[];
|
|
21
|
+
installed: string[];
|
|
22
|
+
};
|
|
23
|
+
export declare function installWorkflow(root: string, options: InstallOptions): Promise<{
|
|
24
|
+
status: string;
|
|
25
|
+
} | {
|
|
26
|
+
kept: string[];
|
|
27
|
+
workflows: WorkflowDocument[];
|
|
28
|
+
skills: string[];
|
|
29
|
+
installed: string[];
|
|
30
|
+
root: string;
|
|
31
|
+
instructions: string;
|
|
32
|
+
host?: "codex" | "claude" | undefined;
|
|
33
|
+
status: string;
|
|
34
|
+
scope: InstallScope;
|
|
35
|
+
}>;
|
|
36
|
+
export {};
|