codex-taskflow 0.1.4 → 0.1.6
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/README.md +120 -27
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/bin.d.ts +2 -1
- package/dist/mcp/bin.d.ts.map +1 -1
- package/dist/mcp/bin.js +3 -2
- package/dist/mcp/bin.js.map +1 -1
- package/dist/mcp/server.d.ts +8 -24
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +12 -392
- package/dist/mcp/server.js.map +1 -1
- package/package.json +22 -9
- package/dist/codex-runner.d.ts +0 -59
- package/dist/codex-runner.d.ts.map +0 -1
- package/dist/codex-runner.js +0 -332
- package/dist/codex-runner.js.map +0 -1
- package/dist/mcp/jsonrpc.d.ts +0 -54
- package/dist/mcp/jsonrpc.d.ts.map +0 -1
- package/dist/mcp/jsonrpc.js +0 -118
- package/dist/mcp/jsonrpc.js.map +0 -1
- package/dist/mcp/svg.d.ts +0 -50
- package/dist/mcp/svg.d.ts.map +0 -1
- package/dist/mcp/svg.js +0 -310
- package/dist/mcp/svg.js.map +0 -1
package/dist/codex-runner.js
DELETED
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Codex subagent runner — the Codex host's `SubagentRunner` implementation.
|
|
3
|
-
*
|
|
4
|
-
* Spawns an isolated `codex exec --json` process per task and folds its JSONL
|
|
5
|
-
* event stream into the same host-neutral `RunResult` the pi runner produces,
|
|
6
|
-
* so the engine (runtime.ts) treats a Codex subagent identically to a pi one.
|
|
7
|
-
*
|
|
8
|
-
* Real codex JSONL schema (codex-cli ≥ 0.142), observed empirically:
|
|
9
|
-
* {"type":"thread.started","thread_id":"…"}
|
|
10
|
-
* {"type":"turn.started"}
|
|
11
|
-
* {"type":"item.started", "item":{"id","type":"command_execution","command","status":"in_progress",…}}
|
|
12
|
-
* {"type":"item.completed","item":{"id","type":"command_execution","command","exit_code","status":"completed",…}}
|
|
13
|
-
* {"type":"item.completed","item":{"id","type":"agent_message","text":"…"}} ← final answer
|
|
14
|
-
* {"type":"item.completed","item":{"id","type":"error","message":"…"}} ← warning OR fatal
|
|
15
|
-
* {"type":"turn.completed","usage":{"input_tokens","cached_input_tokens","output_tokens","reasoning_output_tokens"}}
|
|
16
|
-
*
|
|
17
|
-
* Mapping to the pi contract:
|
|
18
|
-
* - output = text of the LAST `agent_message` item
|
|
19
|
-
* - usage.input = input_tokens; usage.output = output_tokens + reasoning_output_tokens;
|
|
20
|
-
* usage.cacheRead = cached_input_tokens; turns = number of `turn.completed`
|
|
21
|
-
* - lastActivity for streaming = latest agent_message text or a one-line
|
|
22
|
-
* command summary
|
|
23
|
-
* - benign warnings (the "Under-development features" / "Skill descriptions"
|
|
24
|
-
* notices) are NOT treated as failures — only a fatal error item or a
|
|
25
|
-
* non-zero exit is.
|
|
26
|
-
*
|
|
27
|
-
* Process handling (idle watchdog, abort, signal-kill detection, stderr cap,
|
|
28
|
-
* error sanitization) mirrors the pi runner so behavior is uniform across hosts.
|
|
29
|
-
*/
|
|
30
|
-
import { spawn } from "node:child_process";
|
|
31
|
-
import { emptyUsage, isFailed, sanitizeErrorMessage, TRANSPORT_ERROR_PLACEHOLDER, } from "taskflow-core";
|
|
32
|
-
const activeChildren = new Set();
|
|
33
|
-
const killAll = () => {
|
|
34
|
-
for (const pid of activeChildren) {
|
|
35
|
-
try {
|
|
36
|
-
process.kill(pid, "SIGKILL");
|
|
37
|
-
}
|
|
38
|
-
catch { /* already dead */ }
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
process.on("exit", killAll);
|
|
42
|
-
/** Same idle window as the pi runner: a child silent this long is wedged. */
|
|
43
|
-
const DEFAULT_IDLE_TIMEOUT_MS = 5 * 60_000;
|
|
44
|
-
/** Benign codex `error` items that are warnings, not failures. Matched as a
|
|
45
|
-
* prefix/substring so version drift in the message tail still classifies. */
|
|
46
|
-
const BENIGN_ERROR_MARKERS = [
|
|
47
|
-
"Under-development features",
|
|
48
|
-
"Skill descriptions were shortened",
|
|
49
|
-
];
|
|
50
|
-
function isBenignCodexError(message) {
|
|
51
|
-
return BENIGN_ERROR_MARKERS.some((m) => message.includes(m));
|
|
52
|
-
}
|
|
53
|
-
export function newCodexAccumulator(model) {
|
|
54
|
-
return { usage: emptyUsage(), model, finalText: "", lastActivity: "" };
|
|
55
|
-
}
|
|
56
|
-
function shortCmd(cmd) {
|
|
57
|
-
const s = String(cmd ?? "").replace(/\s+/g, " ").trim();
|
|
58
|
-
return s.length > 64 ? `${s.slice(0, 64)}…` : s;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Fold one codex JSONL line into the accumulator. Returns a LiveUpdate when the
|
|
62
|
-
* stream produced new activity (for streaming), else null. Empty/malformed
|
|
63
|
-
* lines are ignored — robust to partial buffers and noise, unit-testable
|
|
64
|
-
* without spawning a process.
|
|
65
|
-
*/
|
|
66
|
-
export function foldCodexEventLine(acc, line) {
|
|
67
|
-
if (!line.trim())
|
|
68
|
-
return null;
|
|
69
|
-
let event;
|
|
70
|
-
try {
|
|
71
|
-
event = JSON.parse(line);
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
let activity = "";
|
|
77
|
-
if (event.type === "turn.completed" && event.usage) {
|
|
78
|
-
const u = event.usage;
|
|
79
|
-
acc.usage.turns++;
|
|
80
|
-
acc.usage.input += u.input_tokens || 0;
|
|
81
|
-
acc.usage.output += (u.output_tokens || 0) + (u.reasoning_output_tokens || 0);
|
|
82
|
-
acc.usage.cacheRead += u.cached_input_tokens || 0;
|
|
83
|
-
acc.usage.contextTokens = (u.input_tokens || 0) + (u.output_tokens || 0);
|
|
84
|
-
}
|
|
85
|
-
else if (event.type === "item.completed" || event.type === "item.started") {
|
|
86
|
-
const item = event.item;
|
|
87
|
-
if (!item)
|
|
88
|
-
return null;
|
|
89
|
-
switch (item.type) {
|
|
90
|
-
case "agent_message":
|
|
91
|
-
if (typeof item.text === "string" && item.text.trim()) {
|
|
92
|
-
// Final answer is the LAST agent_message; keep overwriting.
|
|
93
|
-
if (event.type === "item.completed")
|
|
94
|
-
acc.finalText = item.text;
|
|
95
|
-
activity = item.text.trim();
|
|
96
|
-
}
|
|
97
|
-
break;
|
|
98
|
-
case "command_execution":
|
|
99
|
-
activity = `$ ${shortCmd(item.command)}`;
|
|
100
|
-
break;
|
|
101
|
-
case "error":
|
|
102
|
-
if (typeof item.message === "string" && !isBenignCodexError(item.message)) {
|
|
103
|
-
acc.fatalError = item.message;
|
|
104
|
-
activity = `error: ${item.message}`;
|
|
105
|
-
}
|
|
106
|
-
break;
|
|
107
|
-
default:
|
|
108
|
-
// file_change / reasoning / mcp_tool_call / etc. — note generically.
|
|
109
|
-
if (typeof item.type === "string")
|
|
110
|
-
activity = item.type;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
return null; // thread.started / turn.started — nothing to fold.
|
|
115
|
-
}
|
|
116
|
-
if (activity)
|
|
117
|
-
acc.lastActivity = activity.replace(/\s+/g, " ").trim();
|
|
118
|
-
return { text: acc.lastActivity, usage: { ...acc.usage }, model: acc.model };
|
|
119
|
-
}
|
|
120
|
-
/** Override the codex binary (tests / unusual installs). */
|
|
121
|
-
function codexBin() {
|
|
122
|
-
return process.env.PI_TASKFLOW_CODEX_BIN || "codex";
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Map a phase's tool whitelist to a codex sandbox mode. Codex has no per-tool
|
|
126
|
-
* whitelist; it has sandbox policies. The conservative mapping: a phase that
|
|
127
|
-
* only reads (no write/edit/bash in its whitelist) gets `read-only`; anything
|
|
128
|
-
* else gets `workspace-write`. No whitelist → workspace-write (the engine's
|
|
129
|
-
* default-capable agent). `danger-full-access` is never selected automatically.
|
|
130
|
-
*/
|
|
131
|
-
function sandboxForTools(tools) {
|
|
132
|
-
if (!tools || tools.length === 0)
|
|
133
|
-
return "workspace-write";
|
|
134
|
-
const mutating = new Set(["write", "edit", "bash", "apply_patch"]);
|
|
135
|
-
const canMutate = tools.some((t) => mutating.has(t));
|
|
136
|
-
return canMutate ? "workspace-write" : "read-only";
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Run a single subagent task via `codex exec --json`. Resolves the agent from
|
|
140
|
-
* `agents` by name; returns the same structured `RunResult` the pi runner does.
|
|
141
|
-
*/
|
|
142
|
-
export async function runCodexAgentTask(defaultCwd, agents, agentName, task, opts, globalThinking) {
|
|
143
|
-
const agent = agents.find((a) => a.name === agentName);
|
|
144
|
-
if (!agent) {
|
|
145
|
-
const available = agents.map((a) => `"${a.name}"`).join(", ") || "none";
|
|
146
|
-
return {
|
|
147
|
-
agent: agentName,
|
|
148
|
-
task,
|
|
149
|
-
exitCode: 1,
|
|
150
|
-
output: "",
|
|
151
|
-
stderr: `Unknown agent: "${agentName}". Available: ${available}.`,
|
|
152
|
-
usage: emptyUsage(),
|
|
153
|
-
errorMessage: `Unknown agent: ${agentName}`,
|
|
154
|
-
stopReason: "error",
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
const model = opts.model ?? agent.model;
|
|
158
|
-
const tools = opts.tools ?? agent.tools;
|
|
159
|
-
const sandbox = sandboxForTools(tools);
|
|
160
|
-
void globalThinking; // codex has no thinking-level flag on exec; reserved.
|
|
161
|
-
// The agent.model comes from the shared modelRoles table, which is written in
|
|
162
|
-
// the pi provider format (e.g. "openrouter/deepseek/...", "anthropic/glm-5.2:xhigh"
|
|
163
|
-
// — note the `/` provider prefix and `:thinking` suffix). Those ids are pi's
|
|
164
|
-
// namespacing and Codex does not recognise them ("Model metadata for ... not
|
|
165
|
-
// found"). Codex model ids are flat (e.g. "gpt-5.5", "claude-sonnet-4-6"). So:
|
|
166
|
-
// if the resolved model still looks like a pi-provider path (contains "/"),
|
|
167
|
-
// drop it and let `codex exec` fall back to its own configured default model.
|
|
168
|
-
// A user who wants a specific Codex model can set it directly (no "/") and it
|
|
169
|
-
// will be passed through. Likewise an unresolved {{placeholder}} is dropped.
|
|
170
|
-
const codexModel = model && !model.includes("/") && !/^\{\{.*\}\}$/.test(model) ? model : undefined;
|
|
171
|
-
// codex exec [PROMPT] --json --skip-git-repo-check -s <sandbox> [-m model] [-C cwd]
|
|
172
|
-
// The agent's system prompt is prepended to the task as guidance, since
|
|
173
|
-
// `codex exec` has no separate append-system-prompt flag. We keep it compact.
|
|
174
|
-
const fullPrompt = agent.systemPrompt.trim()
|
|
175
|
-
? `${agent.systemPrompt.trim()}\n\n---\n\nTask: ${task}`
|
|
176
|
-
: `Task: ${task}`;
|
|
177
|
-
const args = ["exec", "--json", "--skip-git-repo-check", "-s", sandbox];
|
|
178
|
-
if (codexModel)
|
|
179
|
-
args.push("-m", codexModel);
|
|
180
|
-
const cwd = opts.cwd ?? defaultCwd;
|
|
181
|
-
if (cwd)
|
|
182
|
-
args.push("-C", cwd);
|
|
183
|
-
args.push(fullPrompt);
|
|
184
|
-
const acc = newCodexAccumulator(model);
|
|
185
|
-
const result = {
|
|
186
|
-
agent: agentName,
|
|
187
|
-
task,
|
|
188
|
-
exitCode: 0,
|
|
189
|
-
output: "",
|
|
190
|
-
stderr: "",
|
|
191
|
-
usage: emptyUsage(),
|
|
192
|
-
model,
|
|
193
|
-
};
|
|
194
|
-
let wasAborted = false;
|
|
195
|
-
let idleTimedOut = false;
|
|
196
|
-
let killedBySignal;
|
|
197
|
-
const exitCode = await new Promise((resolve) => {
|
|
198
|
-
const proc = spawn(codexBin(), args, {
|
|
199
|
-
cwd,
|
|
200
|
-
shell: false,
|
|
201
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
202
|
-
env: { ...process.env },
|
|
203
|
-
});
|
|
204
|
-
if (proc.pid)
|
|
205
|
-
activeChildren.add(proc.pid);
|
|
206
|
-
let buffer = "";
|
|
207
|
-
let idleTimer;
|
|
208
|
-
let forceTimer;
|
|
209
|
-
const idleMs = opts.idleTimeoutMs ?? DEFAULT_IDLE_TIMEOUT_MS;
|
|
210
|
-
const clearTimers = () => {
|
|
211
|
-
if (idleTimer)
|
|
212
|
-
clearTimeout(idleTimer);
|
|
213
|
-
if (forceTimer)
|
|
214
|
-
clearTimeout(forceTimer);
|
|
215
|
-
};
|
|
216
|
-
const hardKill = () => {
|
|
217
|
-
idleTimedOut = true;
|
|
218
|
-
proc.kill("SIGTERM");
|
|
219
|
-
forceTimer = setTimeout(() => proc.kill("SIGKILL"), 5000);
|
|
220
|
-
forceTimer.unref();
|
|
221
|
-
};
|
|
222
|
-
const armIdle = () => {
|
|
223
|
-
if (idleTimer)
|
|
224
|
-
clearTimeout(idleTimer);
|
|
225
|
-
if (idleMs <= 0)
|
|
226
|
-
return;
|
|
227
|
-
idleTimer = setTimeout(hardKill, idleMs);
|
|
228
|
-
idleTimer.unref();
|
|
229
|
-
};
|
|
230
|
-
armIdle();
|
|
231
|
-
const processLine = (line) => {
|
|
232
|
-
const live = foldCodexEventLine(acc, line);
|
|
233
|
-
if (live && opts.onLive)
|
|
234
|
-
opts.onLive(live);
|
|
235
|
-
};
|
|
236
|
-
proc.stdout.on("data", (data) => {
|
|
237
|
-
armIdle();
|
|
238
|
-
buffer += data.toString();
|
|
239
|
-
const lines = buffer.split("\n");
|
|
240
|
-
buffer = lines.pop() || "";
|
|
241
|
-
for (const line of lines)
|
|
242
|
-
processLine(line);
|
|
243
|
-
});
|
|
244
|
-
const STDERR_MAX_LEN = 64 * 1024;
|
|
245
|
-
let stderrCapped = false;
|
|
246
|
-
proc.stderr.on("data", (data) => {
|
|
247
|
-
if (!stderrCapped) {
|
|
248
|
-
result.stderr += data.toString();
|
|
249
|
-
if (result.stderr.length >= STDERR_MAX_LEN) {
|
|
250
|
-
result.stderr = result.stderr.slice(0, STDERR_MAX_LEN) + "\n[...stderr truncated at 64KB]";
|
|
251
|
-
stderrCapped = true;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
proc.on("close", (code, signal) => {
|
|
256
|
-
if (proc.pid)
|
|
257
|
-
activeChildren.delete(proc.pid);
|
|
258
|
-
clearTimers();
|
|
259
|
-
if (buffer.trim())
|
|
260
|
-
processLine(buffer);
|
|
261
|
-
if (code === null && signal)
|
|
262
|
-
killedBySignal = signal;
|
|
263
|
-
resolve(code ?? 0);
|
|
264
|
-
});
|
|
265
|
-
proc.on("error", (err) => {
|
|
266
|
-
clearTimers();
|
|
267
|
-
if (!result.stderr)
|
|
268
|
-
result.stderr = err.message;
|
|
269
|
-
if (!result.errorMessage)
|
|
270
|
-
result.errorMessage = err.message;
|
|
271
|
-
resolve(1);
|
|
272
|
-
});
|
|
273
|
-
if (opts.signal) {
|
|
274
|
-
const kill = () => {
|
|
275
|
-
wasAborted = true;
|
|
276
|
-
proc.kill("SIGTERM");
|
|
277
|
-
const forceKill = setTimeout(() => proc.kill("SIGKILL"), 5000);
|
|
278
|
-
forceKill.unref();
|
|
279
|
-
};
|
|
280
|
-
if (opts.signal.aborted)
|
|
281
|
-
kill();
|
|
282
|
-
else
|
|
283
|
-
opts.signal.addEventListener("abort", kill, { once: true });
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
result.exitCode = exitCode;
|
|
287
|
-
result.usage = acc.usage;
|
|
288
|
-
result.model = acc.model;
|
|
289
|
-
result.output = acc.finalText;
|
|
290
|
-
if (acc.fatalError) {
|
|
291
|
-
result.exitCode = result.exitCode || 1;
|
|
292
|
-
result.stopReason = "error";
|
|
293
|
-
result.errorMessage = acc.fatalError;
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
result.stopReason = exitCode === 0 ? "end" : "error";
|
|
297
|
-
}
|
|
298
|
-
if (exitCode === 0 && killedBySignal && !idleTimedOut && !wasAborted) {
|
|
299
|
-
result.exitCode = 1;
|
|
300
|
-
result.stopReason = "error";
|
|
301
|
-
result.errorMessage = `Subagent killed by signal ${killedBySignal}`;
|
|
302
|
-
}
|
|
303
|
-
if (idleTimedOut) {
|
|
304
|
-
result.stopReason = "error";
|
|
305
|
-
result.idleTimeout = true;
|
|
306
|
-
result.errorMessage = `Subagent stalled: no output for ${Math.round((opts.idleTimeoutMs ?? DEFAULT_IDLE_TIMEOUT_MS) / 1000)}s (idle timeout) — killed`;
|
|
307
|
-
}
|
|
308
|
-
else if (wasAborted) {
|
|
309
|
-
result.stopReason = "aborted";
|
|
310
|
-
result.errorMessage = "Subagent was aborted";
|
|
311
|
-
}
|
|
312
|
-
if (isFailed(result)) {
|
|
313
|
-
if (!result.output) {
|
|
314
|
-
result.output = TRANSPORT_ERROR_PLACEHOLDER;
|
|
315
|
-
if (!result.errorMessage) {
|
|
316
|
-
result.errorMessage =
|
|
317
|
-
result.stderr || `Subagent exited with code ${result.exitCode} (stopReason: ${result.stopReason ?? "unknown"})`;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
if (result.errorMessage)
|
|
321
|
-
result.errorMessage = sanitizeErrorMessage(result.errorMessage);
|
|
322
|
-
}
|
|
323
|
-
return result;
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* The Codex host's `SubagentRunner`. Drops into `RuntimeDeps.runTask` exactly
|
|
327
|
-
* like `piSubagentRunner`, so the engine runs unchanged on Codex.
|
|
328
|
-
*/
|
|
329
|
-
export const codexSubagentRunner = {
|
|
330
|
-
runTask: runCodexAgentTask,
|
|
331
|
-
};
|
|
332
|
-
//# sourceMappingURL=codex-runner.js.map
|
package/dist/codex-runner.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codex-runner.js","sourceRoot":"","sources":["../src/codex-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EACN,UAAU,EACV,QAAQ,EACR,oBAAoB,EACpB,2BAA2B,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,CAAC;IAC9B,CAAC;SAAM,IAAI,UAAU,EAAE,CAAC;QACvB,MAAM,CAAC,UAAU,GAAG,SAAS,CAAC;QAC9B,MAAM,CAAC,YAAY,GAAG,sBAAsB,CAAC;IAC9C,CAAC;IAED,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACtB,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACpB,MAAM,CAAC,MAAM,GAAG,2BAA2B,CAAC;YAC5C,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;gBAC1B,MAAM,CAAC,YAAY;oBAClB,MAAM,CAAC,MAAM,IAAI,6BAA6B,MAAM,CAAC,QAAQ,iBAAiB,MAAM,CAAC,UAAU,IAAI,SAAS,GAAG,CAAC;YAClH,CAAC;QACF,CAAC;QACD,IAAI,MAAM,CAAC,YAAY;YAAE,MAAM,CAAC,YAAY,GAAG,oBAAoB,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAC1F,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAgC;IAC/D,OAAO,EAAE,iBAAiB;CAC1B,CAAC"}
|
package/dist/mcp/jsonrpc.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Minimal, dependency-free stdio JSON-RPC 2.0 transport for an MCP server.
|
|
3
|
-
*
|
|
4
|
-
* pi-taskflow ships ZERO runtime dependencies (a core selling point), so we do
|
|
5
|
-
* NOT pull in `@modelcontextprotocol/sdk`. MCP's stdio transport is just
|
|
6
|
-
* newline-delimited JSON-RPC 2.0 over stdin/stdout — small enough to implement
|
|
7
|
-
* on Node built-ins. This module handles framing + dispatch only; the MCP
|
|
8
|
-
* method semantics live in server.ts.
|
|
9
|
-
*
|
|
10
|
-
* Wire format: one JSON object per line on stdin (a request or notification),
|
|
11
|
-
* one JSON object per line on stdout (a response). Notifications (no `id`) get
|
|
12
|
-
* no response. Anything we can't parse is answered with a JSON-RPC parse error
|
|
13
|
-
* when an id is recoverable, else dropped (never crash the loop).
|
|
14
|
-
*/
|
|
15
|
-
export interface JsonRpcRequest {
|
|
16
|
-
jsonrpc: "2.0";
|
|
17
|
-
id?: string | number | null;
|
|
18
|
-
method: string;
|
|
19
|
-
params?: unknown;
|
|
20
|
-
}
|
|
21
|
-
export interface JsonRpcError {
|
|
22
|
-
code: number;
|
|
23
|
-
message: string;
|
|
24
|
-
data?: unknown;
|
|
25
|
-
}
|
|
26
|
-
/** Standard JSON-RPC / MCP error codes we use. */
|
|
27
|
-
export declare const RPC: {
|
|
28
|
-
readonly PARSE_ERROR: -32700;
|
|
29
|
-
readonly INVALID_REQUEST: -32600;
|
|
30
|
-
readonly METHOD_NOT_FOUND: -32601;
|
|
31
|
-
readonly INVALID_PARAMS: -32602;
|
|
32
|
-
readonly INTERNAL_ERROR: -32603;
|
|
33
|
-
};
|
|
34
|
-
/** Thrown by a handler to return a structured JSON-RPC error to the client. */
|
|
35
|
-
export declare class RpcError extends Error {
|
|
36
|
-
code: number;
|
|
37
|
-
data?: unknown;
|
|
38
|
-
constructor(code: number, message: string, data?: unknown);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* A method handler. Return a JSON-serializable result, or throw `RpcError` for
|
|
42
|
-
* a structured failure. Returning `undefined` for a request (has id) sends
|
|
43
|
-
* `result: null`; for a notification it is ignored.
|
|
44
|
-
*/
|
|
45
|
-
export type RpcHandler = (params: unknown) => Promise<unknown> | unknown;
|
|
46
|
-
/**
|
|
47
|
-
* Run a JSON-RPC stdio loop over the given streams (defaults to process
|
|
48
|
-
* stdin/stdout). Resolves when the input stream ends (client disconnect).
|
|
49
|
-
*/
|
|
50
|
-
export declare function serveStdio(handlers: Record<string, RpcHandler>, io?: {
|
|
51
|
-
input?: NodeJS.ReadableStream;
|
|
52
|
-
output?: NodeJS.WritableStream;
|
|
53
|
-
}): Promise<void>;
|
|
54
|
-
//# sourceMappingURL=jsonrpc.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jsonrpc.d.ts","sourceRoot":"","sources":["../../src/mcp/jsonrpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,cAAc;IAC9B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CACf;AAED,kDAAkD;AAClD,eAAO,MAAM,GAAG;;;;;;CAMN,CAAC;AAEX,+EAA+E;AAC/E,qBAAa,QAAS,SAAQ,KAAK;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;gBACH,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;CAMzD;AAED;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;AAEzE;;;GAGG;AACH,wBAAgB,UAAU,CACzB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,EACpC,EAAE,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAA;CAAO,GACxE,OAAO,CAAC,IAAI,CAAC,CA+Ef"}
|
package/dist/mcp/jsonrpc.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Minimal, dependency-free stdio JSON-RPC 2.0 transport for an MCP server.
|
|
3
|
-
*
|
|
4
|
-
* pi-taskflow ships ZERO runtime dependencies (a core selling point), so we do
|
|
5
|
-
* NOT pull in `@modelcontextprotocol/sdk`. MCP's stdio transport is just
|
|
6
|
-
* newline-delimited JSON-RPC 2.0 over stdin/stdout — small enough to implement
|
|
7
|
-
* on Node built-ins. This module handles framing + dispatch only; the MCP
|
|
8
|
-
* method semantics live in server.ts.
|
|
9
|
-
*
|
|
10
|
-
* Wire format: one JSON object per line on stdin (a request or notification),
|
|
11
|
-
* one JSON object per line on stdout (a response). Notifications (no `id`) get
|
|
12
|
-
* no response. Anything we can't parse is answered with a JSON-RPC parse error
|
|
13
|
-
* when an id is recoverable, else dropped (never crash the loop).
|
|
14
|
-
*/
|
|
15
|
-
/** Standard JSON-RPC / MCP error codes we use. */
|
|
16
|
-
export const RPC = {
|
|
17
|
-
PARSE_ERROR: -32700,
|
|
18
|
-
INVALID_REQUEST: -32600,
|
|
19
|
-
METHOD_NOT_FOUND: -32601,
|
|
20
|
-
INVALID_PARAMS: -32602,
|
|
21
|
-
INTERNAL_ERROR: -32603,
|
|
22
|
-
};
|
|
23
|
-
/** Thrown by a handler to return a structured JSON-RPC error to the client. */
|
|
24
|
-
export class RpcError extends Error {
|
|
25
|
-
code;
|
|
26
|
-
data;
|
|
27
|
-
constructor(code, message, data) {
|
|
28
|
-
super(message);
|
|
29
|
-
this.name = "RpcError";
|
|
30
|
-
this.code = code;
|
|
31
|
-
this.data = data;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Run a JSON-RPC stdio loop over the given streams (defaults to process
|
|
36
|
-
* stdin/stdout). Resolves when the input stream ends (client disconnect).
|
|
37
|
-
*/
|
|
38
|
-
export function serveStdio(handlers, io = {}) {
|
|
39
|
-
const input = io.input ?? process.stdin;
|
|
40
|
-
const output = io.output ?? process.stdout;
|
|
41
|
-
const write = (obj) => {
|
|
42
|
-
output.write(JSON.stringify(obj) + "\n");
|
|
43
|
-
};
|
|
44
|
-
const respondOk = (id, result) => {
|
|
45
|
-
write({ jsonrpc: "2.0", id, result: result === undefined ? null : result });
|
|
46
|
-
};
|
|
47
|
-
const respondErr = (id, err) => {
|
|
48
|
-
write({ jsonrpc: "2.0", id, error: err });
|
|
49
|
-
};
|
|
50
|
-
const handleLine = async (line) => {
|
|
51
|
-
const trimmed = line.trim();
|
|
52
|
-
if (!trimmed)
|
|
53
|
-
return;
|
|
54
|
-
let msg;
|
|
55
|
-
try {
|
|
56
|
-
msg = JSON.parse(trimmed);
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
// No recoverable id — per JSON-RPC, a parse error uses id:null.
|
|
60
|
-
respondErr(null, { code: RPC.PARSE_ERROR, message: "Parse error" });
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
const isNotification = msg.id === undefined || msg.id === null;
|
|
64
|
-
const id = (msg.id ?? null);
|
|
65
|
-
if (msg.jsonrpc !== "2.0" || typeof msg.method !== "string") {
|
|
66
|
-
if (!isNotification)
|
|
67
|
-
respondErr(id, { code: RPC.INVALID_REQUEST, message: "Invalid Request" });
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
const handler = handlers[msg.method];
|
|
71
|
-
if (!handler) {
|
|
72
|
-
// Unknown notifications are silently ignored (e.g. notifications/*).
|
|
73
|
-
if (!isNotification)
|
|
74
|
-
respondErr(id, { code: RPC.METHOD_NOT_FOUND, message: `Method not found: ${msg.method}` });
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
try {
|
|
78
|
-
const result = await handler(msg.params);
|
|
79
|
-
if (!isNotification)
|
|
80
|
-
respondOk(id, result);
|
|
81
|
-
}
|
|
82
|
-
catch (e) {
|
|
83
|
-
if (isNotification)
|
|
84
|
-
return; // can't report errors for notifications
|
|
85
|
-
if (e instanceof RpcError) {
|
|
86
|
-
respondErr(id, { code: e.code, message: e.message, data: e.data });
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
const message = e instanceof Error ? e.message : String(e);
|
|
90
|
-
respondErr(id, { code: RPC.INTERNAL_ERROR, message });
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
return new Promise((resolve) => {
|
|
95
|
-
let buffer = "";
|
|
96
|
-
// Serialize line handling so responses are emitted in request order even
|
|
97
|
-
// when handlers are async (MCP clients tolerate interleaving, but ordered
|
|
98
|
-
// output is simpler to reason about and test).
|
|
99
|
-
let chain = Promise.resolve();
|
|
100
|
-
input.on("data", (data) => {
|
|
101
|
-
buffer += data.toString();
|
|
102
|
-
let i;
|
|
103
|
-
while ((i = buffer.indexOf("\n")) >= 0) {
|
|
104
|
-
const line = buffer.slice(0, i);
|
|
105
|
-
buffer = buffer.slice(i + 1);
|
|
106
|
-
chain = chain.then(() => handleLine(line));
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
input.on("end", () => {
|
|
110
|
-
chain = chain.then(() => {
|
|
111
|
-
if (buffer.trim())
|
|
112
|
-
return handleLine(buffer);
|
|
113
|
-
}).then(() => resolve());
|
|
114
|
-
});
|
|
115
|
-
input.on("close", () => resolve());
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
//# sourceMappingURL=jsonrpc.js.map
|
package/dist/mcp/jsonrpc.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jsonrpc.js","sourceRoot":"","sources":["../../src/mcp/jsonrpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAeH,kDAAkD;AAClD,MAAM,CAAC,MAAM,GAAG,GAAG;IAClB,WAAW,EAAE,CAAC,KAAK;IACnB,eAAe,EAAE,CAAC,KAAK;IACvB,gBAAgB,EAAE,CAAC,KAAK;IACxB,cAAc,EAAE,CAAC,KAAK;IACtB,cAAc,EAAE,CAAC,KAAK;CACb,CAAC;AAEX,+EAA+E;AAC/E,MAAM,OAAO,QAAS,SAAQ,KAAK;IAClC,IAAI,CAAS;IACb,IAAI,CAAW;IACf,YAAY,IA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,IAAI,CAAC,GAAG,EAAE;gBACvB,IAAI,MAAM,CAAC,IAAI,EAAE;oBAAE,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;YAC9C,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/mcp/svg.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Render a taskflow DAG for the Codex hosts, in two forms:
|
|
3
|
-
*
|
|
4
|
-
* - `renderFlowSvg` — a self-contained SVG "card" for the Codex **desktop
|
|
5
|
-
* app**, which renders an MCP `image` content block
|
|
6
|
-
* as `<img src="data:…">` in Chromium (an inline SVG
|
|
7
|
-
* data URI shows as an actual diagram).
|
|
8
|
-
* - `renderFlowOutline` — a compact monospace ASCII outline for the Codex
|
|
9
|
-
* **CLI/TUI**, which cannot render images: the Rust
|
|
10
|
-
* binary substitutes a bare `<image content>`
|
|
11
|
-
* placeholder for image blocks, so a picture is
|
|
12
|
-
* useless there (and a vision-less model would see
|
|
13
|
-
* only that placeholder). The outline is plain text
|
|
14
|
-
* that reads in the terminal AND feeds the model.
|
|
15
|
-
*
|
|
16
|
-
* We can't tell the two hosts apart from inside the server (every Codex
|
|
17
|
-
* frontend connects with the same MCP client id, `codex-mcp-client`), so
|
|
18
|
-
* `taskflow_compile` returns BOTH blocks: the desktop app shows the image and
|
|
19
|
-
* ignores the trailing text, while the CLI/TUI shows the text and renders the
|
|
20
|
-
* image as a harmless placeholder. One payload, correct on every host.
|
|
21
|
-
*
|
|
22
|
-
* This is host presentation, so it lives in the codex adapter — core keeps its
|
|
23
|
-
* portable Mermaid/markdown artifact (`compileTaskflow`) and its zero-runtime
|
|
24
|
-
* -deps guarantee. Both renderers reuse core's exported `topoLayers` (layout)
|
|
25
|
-
* and `dependenciesOf` (edges) so they share the engine's exact DAG semantics.
|
|
26
|
-
* Pure functions, no I/O.
|
|
27
|
-
*/
|
|
28
|
-
import { type Taskflow, type VerificationResult } from "taskflow-core";
|
|
29
|
-
/** Above this phase count the card stops being legible once scaled — the caller
|
|
30
|
-
* should fall back to the text report instead of embedding a postage stamp. */
|
|
31
|
-
export declare const SVG_PHASE_LIMIT = 60;
|
|
32
|
-
/**
|
|
33
|
-
* Render `flow` (annotated with `verification`) as an SVG string. Layered
|
|
34
|
-
* top-down using core's `topoLayers`; edges follow `dependenciesOf`. Returns a
|
|
35
|
-
* complete `<svg …>…</svg>` document (no XML prolog — it's inlined as a data
|
|
36
|
-
* URI). Returns `null` when the flow is too large to render legibly.
|
|
37
|
-
*/
|
|
38
|
-
export declare function renderFlowSvg(flow: Taskflow, verification: VerificationResult): string | null;
|
|
39
|
-
/** Base64 of an SVG string, for an MCP `image` content block (`image/svg+xml`). */
|
|
40
|
-
export declare function svgToBase64(svg: string): string;
|
|
41
|
-
/**
|
|
42
|
-
* Render the DAG as a compact monospace outline: one line per phase, grouped by
|
|
43
|
-
* topological layer (phases in the same layer run concurrently), each showing
|
|
44
|
-
* its id, type tag, agent, and upstream deps. This is the CLI/TUI counterpart
|
|
45
|
-
* to `renderFlowSvg` — it degrades to readable text where images can't render,
|
|
46
|
-
* and (unlike an image placeholder) still tells a vision-less model the shape
|
|
47
|
-
* of the graph. Deterministic; issue markers mirror the SVG overlay.
|
|
48
|
-
*/
|
|
49
|
-
export declare function renderFlowOutline(flow: Taskflow, verification: VerificationResult): string;
|
|
50
|
-
//# sourceMappingURL=svg.d.ts.map
|
package/dist/mcp/svg.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"svg.d.ts","sourceRoot":"","sources":["../../src/mcp/svg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAMN,KAAK,QAAQ,EACb,KAAK,kBAAkB,EAEvB,MAAM,eAAe,CAAC;AAmBvB;gFACgF;AAChF,eAAO,MAAM,eAAe,KAAK,CAAC;AAqHlC;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,kBAAkB,GAAG,MAAM,GAAG,IAAI,CA2H7F;AAED,mFAAmF;AACnF,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE/C;AAYD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,kBAAkB,GAAG,MAAM,CA0B1F"}
|