@agentic-workflow-kit/orchestrator 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/analysis/runAnalyzer.d.ts +22 -0
- package/dist/analysis/runAnalyzer.d.ts.map +1 -0
- package/dist/analysis/runAnalyzer.js +177 -0
- package/dist/artifacts/FileArtifactStore.d.ts +9 -0
- package/dist/artifacts/FileArtifactStore.d.ts.map +1 -0
- package/dist/artifacts/FileArtifactStore.js +21 -0
- package/dist/cli/args.d.ts +5 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +213 -0
- package/dist/cli.d.ts +9 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +284 -0
- package/dist/clock/SystemClock.d.ts +6 -0
- package/dist/clock/SystemClock.d.ts.map +1 -0
- package/dist/clock/SystemClock.js +8 -0
- package/dist/config/configLoader.d.ts +5 -0
- package/dist/config/configLoader.d.ts.map +1 -0
- package/dist/config/configLoader.js +105 -0
- package/dist/config/generate-schema.d.ts +2 -0
- package/dist/config/generate-schema.d.ts.map +1 -0
- package/dist/config/generate-schema.js +8 -0
- package/dist/config/jsonSchema.d.ts +3 -0
- package/dist/config/jsonSchema.d.ts.map +1 -0
- package/dist/config/jsonSchema.js +44 -0
- package/dist/config/preset.d.ts +16 -0
- package/dist/config/preset.d.ts.map +1 -0
- package/dist/config/preset.js +14 -0
- package/dist/config/resolve.d.ts +12 -0
- package/dist/config/resolve.d.ts.map +1 -0
- package/dist/config/resolve.js +30 -0
- package/dist/config/schema.d.ts +68 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +80 -0
- package/dist/drivers/StoryRunner.d.ts +24 -0
- package/dist/drivers/StoryRunner.d.ts.map +1 -0
- package/dist/drivers/StoryRunner.js +1 -0
- package/dist/drivers/codex-mcp/CodexMcpStoryRunner.d.ts +25 -0
- package/dist/drivers/codex-mcp/CodexMcpStoryRunner.d.ts.map +1 -0
- package/dist/drivers/codex-mcp/CodexMcpStoryRunner.js +145 -0
- package/dist/drivers/codex-mcp/schemaValidation.d.ts +7 -0
- package/dist/drivers/codex-mcp/schemaValidation.d.ts.map +1 -0
- package/dist/drivers/codex-mcp/schemaValidation.js +43 -0
- package/dist/drivers/codex-mcp/toolInput.d.ts +12 -0
- package/dist/drivers/codex-mcp/toolInput.d.ts.map +1 -0
- package/dist/drivers/codex-mcp/toolInput.js +82 -0
- package/dist/git/GitInspector.d.ts +34 -0
- package/dist/git/GitInspector.d.ts.map +1 -0
- package/dist/git/GitInspector.js +73 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/internal/guards.d.ts +4 -0
- package/dist/internal/guards.d.ts.map +1 -0
- package/dist/internal/guards.js +9 -0
- package/dist/logging/ConsoleLogger.d.ts +7 -0
- package/dist/logging/ConsoleLogger.d.ts.map +1 -0
- package/dist/logging/ConsoleLogger.js +16 -0
- package/dist/metrics/aggregate.d.ts +6 -0
- package/dist/metrics/aggregate.d.ts.map +1 -0
- package/dist/metrics/aggregate.js +32 -0
- package/dist/metrics/liveMetrics.d.ts +16 -0
- package/dist/metrics/liveMetrics.d.ts.map +1 -0
- package/dist/metrics/liveMetrics.js +16 -0
- package/dist/runner/CompletionGate.d.ts +25 -0
- package/dist/runner/CompletionGate.d.ts.map +1 -0
- package/dist/runner/CompletionGate.js +49 -0
- package/dist/runner/MetricsCollector.d.ts +27 -0
- package/dist/runner/MetricsCollector.d.ts.map +1 -0
- package/dist/runner/MetricsCollector.js +49 -0
- package/dist/runner/RunJournal.d.ts +32 -0
- package/dist/runner/RunJournal.d.ts.map +1 -0
- package/dist/runner/RunJournal.js +78 -0
- package/dist/runner/WorkflowRunner.d.ts +45 -0
- package/dist/runner/WorkflowRunner.d.ts.map +1 -0
- package/dist/runner/WorkflowRunner.js +289 -0
- package/dist/scheduler/scheduler.d.ts +8 -0
- package/dist/scheduler/scheduler.d.ts.map +1 -0
- package/dist/scheduler/scheduler.js +8 -0
- package/dist/tracks/markdownTracker.d.ts +29 -0
- package/dist/tracks/markdownTracker.d.ts.map +1 -0
- package/dist/tracks/markdownTracker.js +349 -0
- package/dist/types.d.ts +222 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +75 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Arye Kogan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TokenTotals } from '../types.js';
|
|
2
|
+
interface AnalyzeOptions {
|
|
3
|
+
sessionRoots?: string[];
|
|
4
|
+
}
|
|
5
|
+
export interface WorkflowRunAnalysis {
|
|
6
|
+
runId: string;
|
|
7
|
+
status: string;
|
|
8
|
+
blockedReason: string | null;
|
|
9
|
+
children: AnalyzedChild[];
|
|
10
|
+
commandCounts: Record<string, number>;
|
|
11
|
+
subagentCounts: Record<string, number>;
|
|
12
|
+
tokenTotals: TokenTotals | null;
|
|
13
|
+
}
|
|
14
|
+
interface AnalyzedChild {
|
|
15
|
+
storyId: string;
|
|
16
|
+
ok: boolean;
|
|
17
|
+
sessionId: string | null;
|
|
18
|
+
sessionLogPath: string | null;
|
|
19
|
+
}
|
|
20
|
+
export declare function analyzeWorkflowRun(runDirectory: string, options?: AnalyzeOptions): Promise<WorkflowRunAnalysis>;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=runAnalyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runAnalyzer.d.ts","sourceRoot":"","sources":["../../src/analysis/runAnalyzer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,UAAU,cAAc;IACtB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;CACjC;AAED,UAAU,aAAa;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,OAAO,CAAC;IACZ,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED,wBAAsB,kBAAkB,CACtC,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,mBAAmB,CAAC,CA+C9B"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { readdir, readFile, stat } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { isNodeError, isRecord } from '../internal/guards.js';
|
|
4
|
+
import { addTokenTotals, emptyTokenTotals, mergeCounts } from '../metrics/aggregate.js';
|
|
5
|
+
export async function analyzeWorkflowRun(runDirectory, options = {}) {
|
|
6
|
+
const state = await readJsonObject(path.join(runDirectory, 'state.json'));
|
|
7
|
+
const children = await readChildren(path.join(runDirectory, 'children'));
|
|
8
|
+
const sessionLogs = await findSessionLogs(options.sessionRoots ?? defaultSessionRoots());
|
|
9
|
+
const logsBySession = await mapSessionLogsByThread(sessionLogs);
|
|
10
|
+
const commandCounts = {};
|
|
11
|
+
const subagentCounts = {};
|
|
12
|
+
let tokenTotals = emptyTokenTotals();
|
|
13
|
+
let sawTokens = false;
|
|
14
|
+
const analyzedChildren = [];
|
|
15
|
+
for (const child of children) {
|
|
16
|
+
const sessionId = typeof child.sessionId === 'string'
|
|
17
|
+
? child.sessionId
|
|
18
|
+
: typeof child.threadId === 'string'
|
|
19
|
+
? child.threadId
|
|
20
|
+
: null;
|
|
21
|
+
const sessionLogPath = sessionId ? (logsBySession.get(sessionId) ?? null) : null;
|
|
22
|
+
analyzedChildren.push({
|
|
23
|
+
storyId: readString(child.storyId, 'child.storyId'),
|
|
24
|
+
ok: child.ok === true,
|
|
25
|
+
sessionId,
|
|
26
|
+
sessionLogPath,
|
|
27
|
+
});
|
|
28
|
+
if (!sessionLogPath)
|
|
29
|
+
continue;
|
|
30
|
+
const sessionMetrics = await analyzeSessionLog(sessionLogPath);
|
|
31
|
+
mergeCounts(commandCounts, sessionMetrics.commandCounts);
|
|
32
|
+
mergeCounts(subagentCounts, sessionMetrics.subagentCounts);
|
|
33
|
+
if (sessionMetrics.tokenTotals) {
|
|
34
|
+
sawTokens = true;
|
|
35
|
+
tokenTotals = addTokenTotals(tokenTotals, sessionMetrics.tokenTotals);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
runId: readString(state.runId, 'state.runId'),
|
|
40
|
+
status: readString(state.status, 'state.status'),
|
|
41
|
+
blockedReason: typeof state.blockedReason === 'string' ? state.blockedReason : null,
|
|
42
|
+
children: analyzedChildren,
|
|
43
|
+
commandCounts,
|
|
44
|
+
subagentCounts,
|
|
45
|
+
tokenTotals: sawTokens ? tokenTotals : null,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async function readChildren(childrenDirectory) {
|
|
49
|
+
let names;
|
|
50
|
+
try {
|
|
51
|
+
names = await readdir(childrenDirectory);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (isNodeError(error) && error.code === 'ENOENT')
|
|
55
|
+
return [];
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
const childFiles = names
|
|
59
|
+
.filter((name) => name.endsWith('.json') && !name.endsWith('.raw.json') && !name.endsWith('.metrics.json'))
|
|
60
|
+
.sort();
|
|
61
|
+
return await Promise.all(childFiles.map((name) => readJsonObject(path.join(childrenDirectory, name))));
|
|
62
|
+
}
|
|
63
|
+
async function findSessionLogs(roots) {
|
|
64
|
+
const logs = [];
|
|
65
|
+
for (const root of roots) {
|
|
66
|
+
if (!(await pathExists(root)))
|
|
67
|
+
continue;
|
|
68
|
+
await walkJsonl(root, logs);
|
|
69
|
+
}
|
|
70
|
+
return logs;
|
|
71
|
+
}
|
|
72
|
+
async function walkJsonl(directory, logs) {
|
|
73
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
74
|
+
for (const entry of entries) {
|
|
75
|
+
const entryPath = path.join(directory, entry.name);
|
|
76
|
+
if (entry.isDirectory()) {
|
|
77
|
+
await walkJsonl(entryPath, logs);
|
|
78
|
+
}
|
|
79
|
+
else if (entry.isFile() && entry.name.endsWith('.jsonl')) {
|
|
80
|
+
logs.push(entryPath);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function mapSessionLogsByThread(sessionLogs) {
|
|
85
|
+
const byThread = new Map();
|
|
86
|
+
for (const sessionLog of sessionLogs) {
|
|
87
|
+
const content = await readFile(sessionLog, 'utf8');
|
|
88
|
+
for (const line of content.split('\n')) {
|
|
89
|
+
const entry = parseJsonLine(line);
|
|
90
|
+
if (entry?.type !== 'session_meta' || !isRecord(entry.payload))
|
|
91
|
+
continue;
|
|
92
|
+
const id = entry.payload.id;
|
|
93
|
+
if (typeof id === 'string' && !byThread.has(id)) {
|
|
94
|
+
byThread.set(id, sessionLog);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return byThread;
|
|
99
|
+
}
|
|
100
|
+
async function analyzeSessionLog(sessionLog) {
|
|
101
|
+
const commandCounts = {};
|
|
102
|
+
const subagentCounts = {};
|
|
103
|
+
let tokenTotals = null;
|
|
104
|
+
const content = await readFile(sessionLog, 'utf8');
|
|
105
|
+
for (const line of content.split('\n')) {
|
|
106
|
+
const entry = parseJsonLine(line);
|
|
107
|
+
if (!entry || !isRecord(entry.payload))
|
|
108
|
+
continue;
|
|
109
|
+
if (entry.type === 'response_item' && isRecord(entry.payload)) {
|
|
110
|
+
const payload = entry.payload;
|
|
111
|
+
if ((payload.type === 'function_call' || payload.type === 'custom_tool_call') &&
|
|
112
|
+
typeof payload.name === 'string') {
|
|
113
|
+
increment(commandCounts, payload.name);
|
|
114
|
+
}
|
|
115
|
+
if (payload.type === 'function_call' && payload.name === 'spawn_agent' && typeof payload.arguments === 'string') {
|
|
116
|
+
const parsedArgs = parseJsonLine(payload.arguments);
|
|
117
|
+
if (parsedArgs && typeof parsedArgs.agent_type === 'string') {
|
|
118
|
+
increment(subagentCounts, parsedArgs.agent_type);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (entry.type === 'event_msg' && entry.payload.type === 'token_count' && isRecord(entry.payload.info)) {
|
|
123
|
+
const usage = entry.payload.info.total_token_usage;
|
|
124
|
+
if (isRecord(usage)) {
|
|
125
|
+
tokenTotals = {
|
|
126
|
+
inputTokens: readNumber(usage.input_tokens),
|
|
127
|
+
cachedInputTokens: readNumber(usage.cached_input_tokens),
|
|
128
|
+
outputTokens: readNumber(usage.output_tokens),
|
|
129
|
+
reasoningOutputTokens: readNumber(usage.reasoning_output_tokens),
|
|
130
|
+
totalTokens: readNumber(usage.total_tokens),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return { commandCounts, subagentCounts, tokenTotals };
|
|
136
|
+
}
|
|
137
|
+
function defaultSessionRoots() {
|
|
138
|
+
const home = process.env.HOME;
|
|
139
|
+
return home ? [path.join(home, '.codex', 'sessions'), path.join(home, '.codex', 'archived_sessions')] : [];
|
|
140
|
+
}
|
|
141
|
+
async function readJsonObject(filePath) {
|
|
142
|
+
const parsed = JSON.parse(await readFile(filePath, 'utf8'));
|
|
143
|
+
if (!isRecord(parsed))
|
|
144
|
+
throw new Error(`${filePath} must contain a JSON object`);
|
|
145
|
+
return parsed;
|
|
146
|
+
}
|
|
147
|
+
async function pathExists(filePath) {
|
|
148
|
+
try {
|
|
149
|
+
await stat(filePath);
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function parseJsonLine(line) {
|
|
157
|
+
if (line.trim().length === 0)
|
|
158
|
+
return null;
|
|
159
|
+
try {
|
|
160
|
+
const parsed = JSON.parse(line);
|
|
161
|
+
return isRecord(parsed) ? parsed : null;
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function increment(target, key) {
|
|
168
|
+
target[key] = (target[key] ?? 0) + 1;
|
|
169
|
+
}
|
|
170
|
+
function readString(value, name) {
|
|
171
|
+
if (typeof value !== 'string')
|
|
172
|
+
throw new Error(`${name} must be a string`);
|
|
173
|
+
return value;
|
|
174
|
+
}
|
|
175
|
+
function readNumber(value) {
|
|
176
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : 0;
|
|
177
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ArtifactStore, RunEvent } from '../types.js';
|
|
2
|
+
export declare class FileArtifactStore implements ArtifactStore {
|
|
3
|
+
private readonly root;
|
|
4
|
+
constructor(root: string);
|
|
5
|
+
writeJson(relativePath: string, value: unknown): Promise<void>;
|
|
6
|
+
writeText(relativePath: string, value: string): Promise<void>;
|
|
7
|
+
appendEvent(event: RunEvent): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=FileArtifactStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileArtifactStore.d.ts","sourceRoot":"","sources":["../../src/artifacts/FileArtifactStore.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE3D,qBAAa,iBAAkB,YAAW,aAAa;IACzC,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,MAAM;IAEnC,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9D,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM7D,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CAKlD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { appendFile, mkdir, writeFile } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export class FileArtifactStore {
|
|
4
|
+
root;
|
|
5
|
+
constructor(root) {
|
|
6
|
+
this.root = root;
|
|
7
|
+
}
|
|
8
|
+
async writeJson(relativePath, value) {
|
|
9
|
+
await this.writeText(relativePath, `${JSON.stringify(value, null, 2)}\n`);
|
|
10
|
+
}
|
|
11
|
+
async writeText(relativePath, value) {
|
|
12
|
+
const filePath = path.join(this.root, relativePath);
|
|
13
|
+
await mkdir(path.dirname(filePath), { recursive: true });
|
|
14
|
+
await writeFile(filePath, value);
|
|
15
|
+
}
|
|
16
|
+
async appendEvent(event) {
|
|
17
|
+
const filePath = path.join(this.root, 'events.ndjson');
|
|
18
|
+
await mkdir(path.dirname(filePath), { recursive: true });
|
|
19
|
+
await appendFile(filePath, `${JSON.stringify(event)}\n`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CliOverrides, WorkflowCommand } from '../types.js';
|
|
2
|
+
export declare function parseCommand(argv: string[]): WorkflowCommand;
|
|
3
|
+
export declare function getHelpText(): string;
|
|
4
|
+
export declare function resolveInvocationCwd(overrides: Pick<CliOverrides, 'cwd'>): string;
|
|
5
|
+
//# sourceMappingURL=args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../src/cli/args.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAkB,YAAY,EAAe,eAAe,EAAE,MAAM,aAAa,CAAC;AAK9F,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,eAAe,CAkC5D;AAED,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAiJD,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,GAAG,MAAM,CAGjF"}
|
package/dist/cli/args.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import { Command, CommanderError, InvalidArgumentError, Option } from 'commander';
|
|
4
|
+
const APPROVAL_POLICIES = new Set(['untrusted', 'on-failure', 'on-request', 'never']);
|
|
5
|
+
const SANDBOX_MODES = new Set(['read-only', 'workspace-write', 'danger-full-access']);
|
|
6
|
+
export function parseCommand(argv) {
|
|
7
|
+
const args = argv.filter((arg) => arg !== '--');
|
|
8
|
+
if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
|
|
9
|
+
return { kind: 'help' };
|
|
10
|
+
}
|
|
11
|
+
if (args[0].startsWith('-')) {
|
|
12
|
+
throw new Error(`Unknown command: ${args[0]}`);
|
|
13
|
+
}
|
|
14
|
+
if (args[0] === 'mcp' && args[1] !== 'check') {
|
|
15
|
+
throw new Error('Expected `mcp check`');
|
|
16
|
+
}
|
|
17
|
+
if (args[0] === 'run-story' && (!args[1] || args[1].startsWith('-'))) {
|
|
18
|
+
throw new Error('run-story requires a story id');
|
|
19
|
+
}
|
|
20
|
+
if (args[0] === 'watch-run' && (!args[1] || args[1].startsWith('-'))) {
|
|
21
|
+
throw new Error('watch-run requires a run directory');
|
|
22
|
+
}
|
|
23
|
+
if (args[0] === 'analyze-run' && (!args[1] || args[1].startsWith('-'))) {
|
|
24
|
+
throw new Error('analyze-run requires a run directory');
|
|
25
|
+
}
|
|
26
|
+
let parsed;
|
|
27
|
+
const program = buildProgram((command) => {
|
|
28
|
+
parsed = command;
|
|
29
|
+
});
|
|
30
|
+
try {
|
|
31
|
+
program.parse(args, { from: 'user' });
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw mapCommanderError(error);
|
|
35
|
+
}
|
|
36
|
+
if (parsed)
|
|
37
|
+
return parsed;
|
|
38
|
+
throw new Error(`Unknown command: ${args[0]}`);
|
|
39
|
+
}
|
|
40
|
+
export function getHelpText() {
|
|
41
|
+
return buildProgram(() => undefined).helpInformation();
|
|
42
|
+
}
|
|
43
|
+
function buildProgram(setParsed) {
|
|
44
|
+
const program = new Command('agentic-workflow-kit')
|
|
45
|
+
.exitOverride()
|
|
46
|
+
.configureOutput({ writeOut: () => undefined, writeErr: () => undefined })
|
|
47
|
+
.helpOption(false)
|
|
48
|
+
.allowUnknownOption(false)
|
|
49
|
+
.allowExcessArguments(false);
|
|
50
|
+
withOptions(program.command('list-tracks')).action((options) => {
|
|
51
|
+
setParsed({ kind: 'list-tracks', overrides: toOverrides(options) });
|
|
52
|
+
});
|
|
53
|
+
withOptions(program.command('list-stories')).action((options) => {
|
|
54
|
+
setParsed({ kind: 'list-stories', overrides: toOverrides(options) });
|
|
55
|
+
});
|
|
56
|
+
withOptions(program.command('list-eligible')).action((options) => {
|
|
57
|
+
setParsed({ kind: 'list-eligible', overrides: toOverrides(options) });
|
|
58
|
+
});
|
|
59
|
+
withOptions(program.command('run-story').argument('<storyId>')).action((storyId, options) => {
|
|
60
|
+
setParsed({ kind: 'run-story', storyId, overrides: toOverrides(options) });
|
|
61
|
+
});
|
|
62
|
+
withOptions(program.command('run-eligible')).action((options) => {
|
|
63
|
+
setParsed({ kind: 'run-eligible', overrides: toOverrides(options) });
|
|
64
|
+
});
|
|
65
|
+
withOptions(program.command('watch-run').argument('<runPath>')).action((runPath, options) => {
|
|
66
|
+
setParsed({ kind: 'watch-run', runPath, overrides: toOverrides(options) });
|
|
67
|
+
});
|
|
68
|
+
withOptions(program.command('analyze-run').argument('<runPath>')).action((runPath, options) => {
|
|
69
|
+
setParsed({ kind: 'analyze-run', runPath, overrides: toOverrides(options) });
|
|
70
|
+
});
|
|
71
|
+
const mcp = program.command('mcp').allowExcessArguments(false);
|
|
72
|
+
withOptions(mcp.command('check')).action((options) => {
|
|
73
|
+
setParsed({ kind: 'mcp-check', overrides: toOverrides(options) });
|
|
74
|
+
});
|
|
75
|
+
return program;
|
|
76
|
+
}
|
|
77
|
+
function withOptions(command) {
|
|
78
|
+
return command
|
|
79
|
+
.allowUnknownOption(false)
|
|
80
|
+
.allowExcessArguments(false)
|
|
81
|
+
.option('--config <path>')
|
|
82
|
+
.option('--json')
|
|
83
|
+
.option('--force')
|
|
84
|
+
.option('--dry-run')
|
|
85
|
+
.option('--watch')
|
|
86
|
+
.addOption(new Option('--max-parallel <n>').argParser(parsePositiveInteger))
|
|
87
|
+
.addOption(new Option('--child-timeout-ms <n>').argParser(parseChildTimeoutMs))
|
|
88
|
+
.option('--track <id>')
|
|
89
|
+
.option('--tracks-dir <path>')
|
|
90
|
+
.option('--model <model>')
|
|
91
|
+
.option('--reasoning <effort>')
|
|
92
|
+
.addOption(new Option('--approval-policy <policy>').argParser(parseApprovalPolicy))
|
|
93
|
+
.addOption(new Option('--sandbox <mode>').argParser(parseSandbox))
|
|
94
|
+
.option('--cwd <path>')
|
|
95
|
+
.option('--session-root <path>');
|
|
96
|
+
}
|
|
97
|
+
function toOverrides(options) {
|
|
98
|
+
const overrides = {};
|
|
99
|
+
if (options.config !== undefined)
|
|
100
|
+
overrides.configPath = options.config;
|
|
101
|
+
if (options.json)
|
|
102
|
+
overrides.json = true;
|
|
103
|
+
if (options.force)
|
|
104
|
+
overrides.force = true;
|
|
105
|
+
if (options.dryRun)
|
|
106
|
+
overrides.dryRun = true;
|
|
107
|
+
if (options.watch)
|
|
108
|
+
overrides.watch = true;
|
|
109
|
+
if (options.maxParallel !== undefined)
|
|
110
|
+
overrides.maxParallel = options.maxParallel;
|
|
111
|
+
if (options.childTimeoutMs !== undefined)
|
|
112
|
+
overrides.childTimeoutMs = options.childTimeoutMs;
|
|
113
|
+
if (options.track !== undefined)
|
|
114
|
+
overrides.track = options.track;
|
|
115
|
+
if (options.tracksDir !== undefined)
|
|
116
|
+
overrides.tracksDir = options.tracksDir;
|
|
117
|
+
if (options.model !== undefined)
|
|
118
|
+
overrides.model = options.model;
|
|
119
|
+
if (options.reasoning !== undefined)
|
|
120
|
+
overrides.reasoning = options.reasoning;
|
|
121
|
+
if (options.approvalPolicy !== undefined)
|
|
122
|
+
overrides.approvalPolicy = options.approvalPolicy;
|
|
123
|
+
if (options.sandbox !== undefined)
|
|
124
|
+
overrides.sandbox = options.sandbox;
|
|
125
|
+
if (options.cwd !== undefined)
|
|
126
|
+
overrides.cwd = options.cwd;
|
|
127
|
+
if (options.sessionRoot !== undefined)
|
|
128
|
+
overrides.sessionRoot = options.sessionRoot;
|
|
129
|
+
return overrides;
|
|
130
|
+
}
|
|
131
|
+
function parseApprovalPolicy(value) {
|
|
132
|
+
if (!APPROVAL_POLICIES.has(value)) {
|
|
133
|
+
throw new InvalidArgumentError('--approval-policy must be one of untrusted, on-failure, on-request, never');
|
|
134
|
+
}
|
|
135
|
+
return value;
|
|
136
|
+
}
|
|
137
|
+
function parseSandbox(value) {
|
|
138
|
+
if (!SANDBOX_MODES.has(value)) {
|
|
139
|
+
throw new InvalidArgumentError('--sandbox must be one of read-only, workspace-write, danger-full-access');
|
|
140
|
+
}
|
|
141
|
+
return value;
|
|
142
|
+
}
|
|
143
|
+
function parsePositiveInteger(value) {
|
|
144
|
+
if (value === '') {
|
|
145
|
+
throw new InvalidArgumentError('--max-parallel requires a value');
|
|
146
|
+
}
|
|
147
|
+
const parsed = Number.parseInt(value, 10);
|
|
148
|
+
if (!Number.isInteger(parsed) || parsed < 1 || String(parsed) !== value) {
|
|
149
|
+
throw new InvalidArgumentError('--max-parallel must be a positive integer');
|
|
150
|
+
}
|
|
151
|
+
return parsed;
|
|
152
|
+
}
|
|
153
|
+
function parseChildTimeoutMs(value) {
|
|
154
|
+
return parsePositiveIntegerFlag(value, '--child-timeout-ms');
|
|
155
|
+
}
|
|
156
|
+
function parsePositiveIntegerFlag(value, flag) {
|
|
157
|
+
if (value === '') {
|
|
158
|
+
throw new InvalidArgumentError(`${flag} requires a value`);
|
|
159
|
+
}
|
|
160
|
+
const parsed = Number.parseInt(value, 10);
|
|
161
|
+
if (!Number.isInteger(parsed) || parsed < 1 || String(parsed) !== value) {
|
|
162
|
+
throw new InvalidArgumentError(`${flag} must be a positive integer`);
|
|
163
|
+
}
|
|
164
|
+
return parsed;
|
|
165
|
+
}
|
|
166
|
+
export function resolveInvocationCwd(overrides) {
|
|
167
|
+
if (overrides.cwd)
|
|
168
|
+
return path.resolve(overrides.cwd);
|
|
169
|
+
return process.env.INIT_CWD ? path.resolve(process.env.INIT_CWD) : process.cwd();
|
|
170
|
+
}
|
|
171
|
+
function mapCommanderError(error) {
|
|
172
|
+
if (!(error instanceof CommanderError)) {
|
|
173
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
174
|
+
}
|
|
175
|
+
const message = error.message;
|
|
176
|
+
const unknownOption = message.match(/unknown option '([^']+)'/);
|
|
177
|
+
if (unknownOption)
|
|
178
|
+
return new Error(`Unknown argument: ${unknownOption[1]}`);
|
|
179
|
+
const unknownCommand = message.match(/unknown command '([^']+)'/);
|
|
180
|
+
if (unknownCommand)
|
|
181
|
+
return new Error(`Unknown command: ${unknownCommand[1]}`);
|
|
182
|
+
const missingOptionValue = message.match(/option '([^']+)' argument missing/);
|
|
183
|
+
if (missingOptionValue) {
|
|
184
|
+
const flag = missingOptionValue[1].split(/\s+/)[0];
|
|
185
|
+
return new Error(`${flag} requires a value`);
|
|
186
|
+
}
|
|
187
|
+
const excessArgument = message.match(/too many arguments .* got \d+: ([^.]+)\./);
|
|
188
|
+
if (excessArgument) {
|
|
189
|
+
const extra = excessArgument[1].split(',').at(-1)?.trim() ?? excessArgument[1];
|
|
190
|
+
return new Error(`Unknown argument: ${extra}`);
|
|
191
|
+
}
|
|
192
|
+
if (message.includes("missing required argument 'storyId'"))
|
|
193
|
+
return new Error('run-story requires a story id');
|
|
194
|
+
if (message.includes('--max-parallel requires a value')) {
|
|
195
|
+
return new Error('--max-parallel requires a value');
|
|
196
|
+
}
|
|
197
|
+
if (message.includes('--max-parallel must be a positive integer')) {
|
|
198
|
+
return new Error('--max-parallel must be a positive integer');
|
|
199
|
+
}
|
|
200
|
+
if (message.includes('--child-timeout-ms requires a value')) {
|
|
201
|
+
return new Error('--child-timeout-ms requires a value');
|
|
202
|
+
}
|
|
203
|
+
if (message.includes('--child-timeout-ms must be a positive integer')) {
|
|
204
|
+
return new Error('--child-timeout-ms must be a positive integer');
|
|
205
|
+
}
|
|
206
|
+
if (message.includes('--approval-policy must be one of')) {
|
|
207
|
+
return new Error('--approval-policy must be one of untrusted, on-failure, on-request, never');
|
|
208
|
+
}
|
|
209
|
+
if (message.includes('--sandbox must be one of')) {
|
|
210
|
+
return new Error('--sandbox must be one of read-only, workspace-write, danger-full-access');
|
|
211
|
+
}
|
|
212
|
+
return new Error(message.replace(/^error: /, ''));
|
|
213
|
+
}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { type CodexMcpStoryRunnerOptions } from './drivers/codex-mcp/CodexMcpStoryRunner.js';
|
|
3
|
+
export interface RunCliOptions {
|
|
4
|
+
stdout?: (line: string) => void;
|
|
5
|
+
createCodexMcpClient?: CodexMcpStoryRunnerOptions['createClient'];
|
|
6
|
+
}
|
|
7
|
+
export declare function runCli(argv?: string[], options?: RunCliOptions): Promise<void>;
|
|
8
|
+
export declare function isDirectCliExecution(entrypoint?: string, moduleUrl?: string): boolean;
|
|
9
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAaA,OAAO,EAAuB,KAAK,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AAQlH,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,oBAAoB,CAAC,EAAE,0BAA0B,CAAC,cAAc,CAAC,CAAC;CACnE;AAED,wBAAsB,MAAM,CAAC,IAAI,WAAwB,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAwGrG;AA2MD,wBAAgB,oBAAoB,CAAC,UAAU,SAAkB,EAAE,SAAS,SAAkB,GAAG,OAAO,CAOvG"}
|