poe-code 3.0.174 → 3.0.176
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/dist/cli/commands/spawn.js +25 -3
- package/dist/cli/commands/spawn.js.map +1 -1
- package/dist/index.js +1653 -1565
- package/dist/index.js.map +4 -4
- package/dist/providers/claude-code.js +34 -28
- package/dist/providers/claude-code.js.map +4 -4
- package/dist/providers/codex.js +34 -28
- package/dist/providers/codex.js.map +4 -4
- package/dist/providers/goose.js +34 -28
- package/dist/providers/goose.js.map +4 -4
- package/dist/providers/kimi.js +34 -28
- package/dist/providers/kimi.js.map +4 -4
- package/dist/providers/opencode.js +34 -28
- package/dist/providers/opencode.js.map +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -737,11 +737,11 @@ var init_parse = __esm({
|
|
|
737
737
|
function mergeLayers(layers) {
|
|
738
738
|
return mergeObjectLayers(layers, []);
|
|
739
739
|
}
|
|
740
|
-
function mergeObjectLayers(layers,
|
|
740
|
+
function mergeObjectLayers(layers, path55) {
|
|
741
741
|
const data = {};
|
|
742
742
|
const sources = {};
|
|
743
743
|
for (const key of collectKeys(layers)) {
|
|
744
|
-
const resolved = resolveKey(layers, key,
|
|
744
|
+
const resolved = resolveKey(layers, key, path55);
|
|
745
745
|
if (resolved === void 0) {
|
|
746
746
|
continue;
|
|
747
747
|
}
|
|
@@ -759,7 +759,7 @@ function collectKeys(layers) {
|
|
|
759
759
|
}
|
|
760
760
|
return [...keys];
|
|
761
761
|
}
|
|
762
|
-
function resolveKey(layers, key,
|
|
762
|
+
function resolveKey(layers, key, path55) {
|
|
763
763
|
let winningSource;
|
|
764
764
|
let winningValue;
|
|
765
765
|
const objectLayers = [];
|
|
@@ -789,9 +789,9 @@ function resolveKey(layers, key, path54) {
|
|
|
789
789
|
if (winningSource === void 0) {
|
|
790
790
|
return void 0;
|
|
791
791
|
}
|
|
792
|
-
const fullPath = buildPath(
|
|
792
|
+
const fullPath = buildPath(path55, key);
|
|
793
793
|
if (isPlainObject(winningValue)) {
|
|
794
|
-
const merged = mergeObjectLayers(objectLayers, [...
|
|
794
|
+
const merged = mergeObjectLayers(objectLayers, [...path55, key]);
|
|
795
795
|
return {
|
|
796
796
|
value: merged.data,
|
|
797
797
|
sources: {
|
|
@@ -816,8 +816,8 @@ function isWinningCandidate(key, value) {
|
|
|
816
816
|
}
|
|
817
817
|
return true;
|
|
818
818
|
}
|
|
819
|
-
function buildPath(
|
|
820
|
-
return [...
|
|
819
|
+
function buildPath(path55, key) {
|
|
820
|
+
return [...path55, key].join(".");
|
|
821
821
|
}
|
|
822
822
|
function isPlainObject(value) {
|
|
823
823
|
if (value === null || Array.isArray(value) || typeof value !== "object") {
|
|
@@ -1495,16 +1495,16 @@ function getConfigFormat(pathOrFormat) {
|
|
|
1495
1495
|
}
|
|
1496
1496
|
return formatRegistry[formatName];
|
|
1497
1497
|
}
|
|
1498
|
-
function detectFormat2(
|
|
1499
|
-
const ext = getExtension(
|
|
1498
|
+
function detectFormat2(path55) {
|
|
1499
|
+
const ext = getExtension(path55);
|
|
1500
1500
|
return extensionMap[ext];
|
|
1501
1501
|
}
|
|
1502
|
-
function getExtension(
|
|
1503
|
-
const lastDot =
|
|
1502
|
+
function getExtension(path55) {
|
|
1503
|
+
const lastDot = path55.lastIndexOf(".");
|
|
1504
1504
|
if (lastDot === -1) {
|
|
1505
1505
|
return "";
|
|
1506
1506
|
}
|
|
1507
|
-
return
|
|
1507
|
+
return path55.slice(lastDot).toLowerCase();
|
|
1508
1508
|
}
|
|
1509
1509
|
var formatRegistry, extensionMap;
|
|
1510
1510
|
var init_formats = __esm({
|
|
@@ -2604,38 +2604,38 @@ import { createTwoFilesPatch } from "diff";
|
|
|
2604
2604
|
import chalk from "chalk";
|
|
2605
2605
|
function createDryRunFileSystem(base, recorder) {
|
|
2606
2606
|
const proxy = {
|
|
2607
|
-
async readFile(
|
|
2607
|
+
async readFile(path55, encoding) {
|
|
2608
2608
|
if (encoding) {
|
|
2609
|
-
return base.readFile(
|
|
2609
|
+
return base.readFile(path55, encoding);
|
|
2610
2610
|
}
|
|
2611
|
-
return base.readFile(
|
|
2611
|
+
return base.readFile(path55);
|
|
2612
2612
|
},
|
|
2613
|
-
async writeFile(
|
|
2614
|
-
const previousContent = await tryReadText(base,
|
|
2613
|
+
async writeFile(path55, data, options) {
|
|
2614
|
+
const previousContent = await tryReadText(base, path55);
|
|
2615
2615
|
const nextContent = formatData(data, options?.encoding);
|
|
2616
2616
|
recorder.record({
|
|
2617
2617
|
type: "writeFile",
|
|
2618
|
-
path:
|
|
2618
|
+
path: path55,
|
|
2619
2619
|
nextContent,
|
|
2620
2620
|
previousContent
|
|
2621
2621
|
});
|
|
2622
2622
|
},
|
|
2623
|
-
async mkdir(
|
|
2624
|
-
recorder.record({ type: "mkdir", path:
|
|
2623
|
+
async mkdir(path55, options) {
|
|
2624
|
+
recorder.record({ type: "mkdir", path: path55, options });
|
|
2625
2625
|
},
|
|
2626
|
-
async stat(
|
|
2627
|
-
return base.stat(
|
|
2626
|
+
async stat(path55) {
|
|
2627
|
+
return base.stat(path55);
|
|
2628
2628
|
},
|
|
2629
|
-
async unlink(
|
|
2630
|
-
recorder.record({ type: "unlink", path:
|
|
2629
|
+
async unlink(path55) {
|
|
2630
|
+
recorder.record({ type: "unlink", path: path55 });
|
|
2631
2631
|
},
|
|
2632
|
-
async readdir(
|
|
2633
|
-
return base.readdir(
|
|
2632
|
+
async readdir(path55) {
|
|
2633
|
+
return base.readdir(path55);
|
|
2634
2634
|
}
|
|
2635
2635
|
};
|
|
2636
2636
|
if (typeof base.rm === "function") {
|
|
2637
|
-
proxy.rm = async (
|
|
2638
|
-
recorder.record({ type: "rm", path:
|
|
2637
|
+
proxy.rm = async (path55, options) => {
|
|
2638
|
+
recorder.record({ type: "rm", path: path55, options });
|
|
2639
2639
|
};
|
|
2640
2640
|
}
|
|
2641
2641
|
if (typeof base.copyFile === "function") {
|
|
@@ -2725,8 +2725,8 @@ function describeWriteChange(previous, next) {
|
|
|
2725
2725
|
}
|
|
2726
2726
|
return "update";
|
|
2727
2727
|
}
|
|
2728
|
-
function renderWriteCommand(
|
|
2729
|
-
const command = `cat > ${
|
|
2728
|
+
function renderWriteCommand(path55, change) {
|
|
2729
|
+
const command = `cat > ${path55}`;
|
|
2730
2730
|
if (change === "create") {
|
|
2731
2731
|
return renderOperationCommand(command, chalk.green, "# create");
|
|
2732
2732
|
}
|
|
@@ -2888,9 +2888,9 @@ function redactTomlLine(line) {
|
|
|
2888
2888
|
}
|
|
2889
2889
|
return line;
|
|
2890
2890
|
}
|
|
2891
|
-
async function tryReadText(base,
|
|
2891
|
+
async function tryReadText(base, path55) {
|
|
2892
2892
|
try {
|
|
2893
|
-
return await base.readFile(
|
|
2893
|
+
return await base.readFile(path55, "utf8");
|
|
2894
2894
|
} catch (error2) {
|
|
2895
2895
|
if (isNotFound(error2)) {
|
|
2896
2896
|
return null;
|
|
@@ -4645,10 +4645,10 @@ function renderTableTerminal(options) {
|
|
|
4645
4645
|
}
|
|
4646
4646
|
function renderTableMarkdown(options) {
|
|
4647
4647
|
const { columns, rows } = options;
|
|
4648
|
-
const header = `| ${columns.map((
|
|
4649
|
-
const separator = `| ${columns.map((
|
|
4648
|
+
const header = `| ${columns.map((c2) => c2.title).join(" | ")} |`;
|
|
4649
|
+
const separator = `| ${columns.map((c2) => c2.alignment === "right" ? "---:" : ":---").join(" | ")} |`;
|
|
4650
4650
|
const dataRows = rows.map(
|
|
4651
|
-
(row) => `| ${columns.map((
|
|
4651
|
+
(row) => `| ${columns.map((c2) => stripAnsi2(row[c2.name] ?? "").replace(/\|/g, "\\|")).join(" | ")} |`
|
|
4652
4652
|
);
|
|
4653
4653
|
return [header, separator, ...dataRows].join("\n");
|
|
4654
4654
|
}
|
|
@@ -8239,6 +8239,42 @@ var init_dashboard2 = __esm({
|
|
|
8239
8239
|
}
|
|
8240
8240
|
});
|
|
8241
8241
|
|
|
8242
|
+
// node_modules/fast-string-truncated-width/dist/utils.js
|
|
8243
|
+
var init_utils = __esm({
|
|
8244
|
+
"node_modules/fast-string-truncated-width/dist/utils.js"() {
|
|
8245
|
+
}
|
|
8246
|
+
});
|
|
8247
|
+
|
|
8248
|
+
// node_modules/fast-string-truncated-width/dist/index.js
|
|
8249
|
+
var EMOJI_RE, MODIFIER_RE;
|
|
8250
|
+
var init_dist = __esm({
|
|
8251
|
+
"node_modules/fast-string-truncated-width/dist/index.js"() {
|
|
8252
|
+
init_utils();
|
|
8253
|
+
EMOJI_RE = new RegExp("[\\u{1F1E6}-\\u{1F1FF}]{2}|\\u{1F3F4}[\\u{E0061}-\\u{E007A}]{2}[\\u{E0030}-\\u{E0039}\\u{E0061}-\\u{E007A}]{1,3}\\u{E007F}|(?:\\p{Emoji}\\uFE0F\\u20E3?|\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation})(?:\\u200D(?:\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation}|\\p{Emoji}\\uFE0F\\u20E3?))*", "yu");
|
|
8254
|
+
MODIFIER_RE = new RegExp("\\p{M}+", "gu");
|
|
8255
|
+
}
|
|
8256
|
+
});
|
|
8257
|
+
|
|
8258
|
+
// node_modules/fast-string-width/dist/index.js
|
|
8259
|
+
var init_dist2 = __esm({
|
|
8260
|
+
"node_modules/fast-string-width/dist/index.js"() {
|
|
8261
|
+
init_dist();
|
|
8262
|
+
}
|
|
8263
|
+
});
|
|
8264
|
+
|
|
8265
|
+
// node_modules/fast-wrap-ansi/lib/main.js
|
|
8266
|
+
var ANSI_ESCAPE_BELL, ANSI_CSI, ANSI_OSC, ANSI_ESCAPE_LINK, GROUP_REGEX;
|
|
8267
|
+
var init_main = __esm({
|
|
8268
|
+
"node_modules/fast-wrap-ansi/lib/main.js"() {
|
|
8269
|
+
init_dist2();
|
|
8270
|
+
ANSI_ESCAPE_BELL = "\x07";
|
|
8271
|
+
ANSI_CSI = "[";
|
|
8272
|
+
ANSI_OSC = "]";
|
|
8273
|
+
ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
8274
|
+
GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
|
|
8275
|
+
}
|
|
8276
|
+
});
|
|
8277
|
+
|
|
8242
8278
|
// node_modules/sisteransi/src/index.js
|
|
8243
8279
|
var require_src = __commonJS({
|
|
8244
8280
|
"node_modules/sisteransi/src/index.js"(exports, module) {
|
|
@@ -8247,16 +8283,16 @@ var require_src = __commonJS({
|
|
|
8247
8283
|
var CSI = `${ESC}[`;
|
|
8248
8284
|
var beep = "\x07";
|
|
8249
8285
|
var cursor = {
|
|
8250
|
-
to(x,
|
|
8251
|
-
if (!
|
|
8252
|
-
return `${CSI}${
|
|
8286
|
+
to(x, y2) {
|
|
8287
|
+
if (!y2) return `${CSI}${x + 1}G`;
|
|
8288
|
+
return `${CSI}${y2 + 1};${x + 1}H`;
|
|
8253
8289
|
},
|
|
8254
|
-
move(x,
|
|
8290
|
+
move(x, y2) {
|
|
8255
8291
|
let ret = "";
|
|
8256
8292
|
if (x < 0) ret += `${CSI}${-x}D`;
|
|
8257
8293
|
else if (x > 0) ret += `${CSI}${x}C`;
|
|
8258
|
-
if (
|
|
8259
|
-
else if (
|
|
8294
|
+
if (y2 < 0) ret += `${CSI}${-y2}A`;
|
|
8295
|
+
else if (y2 > 0) ret += `${CSI}${y2}B`;
|
|
8260
8296
|
return ret;
|
|
8261
8297
|
},
|
|
8262
8298
|
up: (count = 1) => `${CSI}${count}A`,
|
|
@@ -8296,30 +8332,24 @@ var require_src = __commonJS({
|
|
|
8296
8332
|
});
|
|
8297
8333
|
|
|
8298
8334
|
// node_modules/@clack/core/dist/index.mjs
|
|
8299
|
-
import {
|
|
8300
|
-
import
|
|
8301
|
-
import
|
|
8302
|
-
import
|
|
8303
|
-
|
|
8304
|
-
|
|
8305
|
-
|
|
8306
|
-
|
|
8307
|
-
var
|
|
8335
|
+
import { styleText as y } from "node:util";
|
|
8336
|
+
import { stdout as S, stdin as $ } from "node:process";
|
|
8337
|
+
import * as _ from "node:readline";
|
|
8338
|
+
import P from "node:readline";
|
|
8339
|
+
import { ReadStream as D } from "node:tty";
|
|
8340
|
+
function q(r) {
|
|
8341
|
+
return r === C;
|
|
8342
|
+
}
|
|
8343
|
+
var import_sisteransi, E, G, u, Y, C;
|
|
8344
|
+
var init_dist3 = __esm({
|
|
8308
8345
|
"node_modules/@clack/core/dist/index.mjs"() {
|
|
8346
|
+
init_main();
|
|
8309
8347
|
import_sisteransi = __toESM(require_src(), 1);
|
|
8310
|
-
|
|
8311
|
-
|
|
8312
|
-
|
|
8313
|
-
|
|
8314
|
-
|
|
8315
|
-
Q = "[";
|
|
8316
|
-
dt = "]";
|
|
8317
|
-
U = `${dt}8;;`;
|
|
8318
|
-
et = new RegExp(`(?:\\${Q}(?<code>\\d+)m|\\${U}(?<uri>.*)${j})`, "y");
|
|
8319
|
-
At = ["up", "down", "left", "right", "space", "enter", "cancel"];
|
|
8320
|
-
_ = { actions: new Set(At), aliases: /* @__PURE__ */ new Map([["k", "up"], ["j", "down"], ["h", "left"], ["l", "right"], ["", "cancel"], ["escape", "cancel"]]), messages: { cancel: "Canceled", error: "Something went wrong" }, withGuide: true };
|
|
8321
|
-
bt = globalThis.process.platform.startsWith("win");
|
|
8322
|
-
z = /* @__PURE__ */ Symbol("clack:cancel");
|
|
8348
|
+
E = ["up", "down", "left", "right", "space", "enter", "cancel"];
|
|
8349
|
+
G = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
8350
|
+
u = { actions: new Set(E), aliases: /* @__PURE__ */ new Map([["k", "up"], ["j", "down"], ["h", "left"], ["l", "right"], ["", "cancel"], ["escape", "cancel"]]), messages: { cancel: "Canceled", error: "Something went wrong" }, withGuide: true, date: { monthNames: [...G], messages: { required: "Please enter a valid date", invalidMonth: "There are only 12 months in a year", invalidDay: (r, t) => `There are only ${r} days in ${t}`, afterMin: (r) => `Date must be on or after ${r.toISOString().slice(0, 10)}`, beforeMax: (r) => `Date must be on or before ${r.toISOString().slice(0, 10)}` } } };
|
|
8351
|
+
Y = globalThis.process.platform.startsWith("win");
|
|
8352
|
+
C = /* @__PURE__ */ Symbol("clack:cancel");
|
|
8323
8353
|
}
|
|
8324
8354
|
});
|
|
8325
8355
|
|
|
@@ -8336,7 +8366,7 @@ function cancel(msg = "") {
|
|
|
8336
8366
|
var init_cancel = __esm({
|
|
8337
8367
|
"packages/design-system/src/prompts/primitives/cancel.ts"() {
|
|
8338
8368
|
"use strict";
|
|
8339
|
-
|
|
8369
|
+
init_dist3();
|
|
8340
8370
|
init_output_format();
|
|
8341
8371
|
}
|
|
8342
8372
|
});
|
|
@@ -8584,7 +8614,7 @@ async function confirm2(opts) {
|
|
|
8584
8614
|
}
|
|
8585
8615
|
async function confirmOrCancel(opts) {
|
|
8586
8616
|
const result = await confirm2(opts);
|
|
8587
|
-
if (
|
|
8617
|
+
if (q(result)) {
|
|
8588
8618
|
cancel("Operation cancelled.");
|
|
8589
8619
|
throw new PromptCancelledError();
|
|
8590
8620
|
}
|
|
@@ -8738,6 +8768,126 @@ var init_src6 = __esm({
|
|
|
8738
8768
|
}
|
|
8739
8769
|
});
|
|
8740
8770
|
|
|
8771
|
+
// packages/agent-spawn/src/acp/session-update-converter.ts
|
|
8772
|
+
function createToolRenderState() {
|
|
8773
|
+
return {
|
|
8774
|
+
startedToolCalls: /* @__PURE__ */ new Set(),
|
|
8775
|
+
toolCallKinds: /* @__PURE__ */ new Map(),
|
|
8776
|
+
toolCallTitles: /* @__PURE__ */ new Map()
|
|
8777
|
+
};
|
|
8778
|
+
}
|
|
8779
|
+
function toRenderKind(kind) {
|
|
8780
|
+
if (kind === "execute") return "exec";
|
|
8781
|
+
if (kind === "write") return "edit";
|
|
8782
|
+
if (kind === "read") return "read";
|
|
8783
|
+
return "other";
|
|
8784
|
+
}
|
|
8785
|
+
function toToolTitle(title, locations) {
|
|
8786
|
+
if (locations && locations.length > 0 && locations[0].path) {
|
|
8787
|
+
return locations[0].path;
|
|
8788
|
+
}
|
|
8789
|
+
return title;
|
|
8790
|
+
}
|
|
8791
|
+
function toToolOutput(value) {
|
|
8792
|
+
if (typeof value === "string") return value;
|
|
8793
|
+
if (value === void 0 || value === null) return "";
|
|
8794
|
+
try {
|
|
8795
|
+
return JSON.stringify(value);
|
|
8796
|
+
} catch {
|
|
8797
|
+
return String(value);
|
|
8798
|
+
}
|
|
8799
|
+
}
|
|
8800
|
+
function extractToolOutputText(update) {
|
|
8801
|
+
const raw = toToolOutput(update.rawOutput);
|
|
8802
|
+
if (raw) return raw;
|
|
8803
|
+
if (!update.content) return "";
|
|
8804
|
+
return update.content.filter((c2) => c2.type === "text" && c2.text).map((c2) => c2.text).join("");
|
|
8805
|
+
}
|
|
8806
|
+
function sessionUpdateToEvents(update, state) {
|
|
8807
|
+
if (update.sessionUpdate === "agent_message_chunk" && update.content.type === "text") {
|
|
8808
|
+
return [{ event: "agent_message", text: update.content.text }];
|
|
8809
|
+
}
|
|
8810
|
+
if (update.sessionUpdate === "agent_thought_chunk" && update.content.type === "text") {
|
|
8811
|
+
return [{ event: "reasoning", text: update.content.text }];
|
|
8812
|
+
}
|
|
8813
|
+
if (update.sessionUpdate === "usage_update") {
|
|
8814
|
+
const cachedTokens = Math.max(0, update.size - update.used);
|
|
8815
|
+
const usage = {
|
|
8816
|
+
event: "usage",
|
|
8817
|
+
inputTokens: update.used,
|
|
8818
|
+
outputTokens: 0
|
|
8819
|
+
};
|
|
8820
|
+
if (cachedTokens > 0) {
|
|
8821
|
+
usage.cachedTokens = cachedTokens;
|
|
8822
|
+
}
|
|
8823
|
+
if (update.cost && update.cost.currency === "USD") {
|
|
8824
|
+
usage.costUsd = update.cost.amount;
|
|
8825
|
+
}
|
|
8826
|
+
return [usage];
|
|
8827
|
+
}
|
|
8828
|
+
if (update.sessionUpdate === "tool_call") {
|
|
8829
|
+
const renderKind = toRenderKind(update.kind);
|
|
8830
|
+
const title = toToolTitle(update.title, update.locations);
|
|
8831
|
+
state.toolCallKinds.set(update.toolCallId, renderKind);
|
|
8832
|
+
state.toolCallTitles.set(update.toolCallId, title);
|
|
8833
|
+
if (state.startedToolCalls.has(update.toolCallId)) {
|
|
8834
|
+
return [];
|
|
8835
|
+
}
|
|
8836
|
+
state.startedToolCalls.add(update.toolCallId);
|
|
8837
|
+
return [{
|
|
8838
|
+
event: "tool_start",
|
|
8839
|
+
kind: renderKind,
|
|
8840
|
+
title,
|
|
8841
|
+
id: update.toolCallId
|
|
8842
|
+
}];
|
|
8843
|
+
}
|
|
8844
|
+
if (update.sessionUpdate === "tool_call_update") {
|
|
8845
|
+
const renderKind = toRenderKind(update.kind ?? void 0) || state.toolCallKinds.get(update.toolCallId) || "other";
|
|
8846
|
+
state.toolCallKinds.set(update.toolCallId, renderKind);
|
|
8847
|
+
const events = [];
|
|
8848
|
+
const toolTitle = toToolTitle(
|
|
8849
|
+
state.toolCallTitles.get(update.toolCallId) ?? update.toolCallId,
|
|
8850
|
+
update.locations
|
|
8851
|
+
);
|
|
8852
|
+
state.toolCallTitles.set(update.toolCallId, toolTitle);
|
|
8853
|
+
const status = update.status;
|
|
8854
|
+
const shouldStart = !state.startedToolCalls.has(update.toolCallId) && (status === "pending" || status === "in_progress");
|
|
8855
|
+
if (shouldStart) {
|
|
8856
|
+
state.startedToolCalls.add(update.toolCallId);
|
|
8857
|
+
events.push({
|
|
8858
|
+
event: "tool_start",
|
|
8859
|
+
kind: renderKind,
|
|
8860
|
+
title: toolTitle,
|
|
8861
|
+
id: update.toolCallId
|
|
8862
|
+
});
|
|
8863
|
+
}
|
|
8864
|
+
if (status === "completed" || status === "failed" || status === "cancelled") {
|
|
8865
|
+
if (!state.startedToolCalls.has(update.toolCallId)) {
|
|
8866
|
+
state.startedToolCalls.add(update.toolCallId);
|
|
8867
|
+
events.push({
|
|
8868
|
+
event: "tool_start",
|
|
8869
|
+
kind: renderKind,
|
|
8870
|
+
title: toolTitle,
|
|
8871
|
+
id: update.toolCallId
|
|
8872
|
+
});
|
|
8873
|
+
}
|
|
8874
|
+
events.push({
|
|
8875
|
+
event: "tool_complete",
|
|
8876
|
+
kind: renderKind,
|
|
8877
|
+
path: extractToolOutputText(update),
|
|
8878
|
+
id: update.toolCallId
|
|
8879
|
+
});
|
|
8880
|
+
}
|
|
8881
|
+
return events;
|
|
8882
|
+
}
|
|
8883
|
+
return [];
|
|
8884
|
+
}
|
|
8885
|
+
var init_session_update_converter = __esm({
|
|
8886
|
+
"packages/agent-spawn/src/acp/session-update-converter.ts"() {
|
|
8887
|
+
"use strict";
|
|
8888
|
+
}
|
|
8889
|
+
});
|
|
8890
|
+
|
|
8741
8891
|
// packages/agent-spawn/src/acp/renderer.ts
|
|
8742
8892
|
function writeLine2(line) {
|
|
8743
8893
|
process.stdout.write(`${line}
|
|
@@ -8828,910 +8978,221 @@ var init_renderer2 = __esm({
|
|
|
8828
8978
|
"packages/agent-spawn/src/acp/renderer.ts"() {
|
|
8829
8979
|
"use strict";
|
|
8830
8980
|
init_src6();
|
|
8981
|
+
init_session_update_converter();
|
|
8831
8982
|
}
|
|
8832
8983
|
});
|
|
8833
8984
|
|
|
8834
|
-
// packages/
|
|
8835
|
-
|
|
8836
|
-
|
|
8837
|
-
|
|
8838
|
-
|
|
8839
|
-
|
|
8840
|
-
|
|
8985
|
+
// packages/poe-acp-client/src/types.ts
|
|
8986
|
+
function isObjectRecord(value) {
|
|
8987
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8988
|
+
}
|
|
8989
|
+
function isAcpErrorCode(value) {
|
|
8990
|
+
return typeof value === "number" && Number.isInteger(value) && value >= -2147483648 && value <= 2147483647;
|
|
8991
|
+
}
|
|
8992
|
+
function isAcpError(value) {
|
|
8993
|
+
if (value instanceof AcpError) {
|
|
8994
|
+
return true;
|
|
8995
|
+
}
|
|
8996
|
+
if (!isObjectRecord(value)) {
|
|
8997
|
+
return false;
|
|
8998
|
+
}
|
|
8999
|
+
if (!isAcpErrorCode(value.code) || typeof value.message !== "string") {
|
|
9000
|
+
return false;
|
|
9001
|
+
}
|
|
9002
|
+
return value.data === void 0 || Object.prototype.hasOwnProperty.call(value, "data");
|
|
9003
|
+
}
|
|
9004
|
+
var ACP_ERROR_CODE_PARSE, ACP_ERROR_CODE_INVALID_REQUEST, ACP_ERROR_CODE_METHOD_NOT_FOUND, ACP_ERROR_CODE_INVALID_PARAMS, ACP_ERROR_CODE_INTERNAL, ACP_ERROR_CODE_RESOURCE_NOT_FOUND, AcpError;
|
|
9005
|
+
var init_types3 = __esm({
|
|
9006
|
+
"packages/poe-acp-client/src/types.ts"() {
|
|
8841
9007
|
"use strict";
|
|
8842
|
-
|
|
9008
|
+
ACP_ERROR_CODE_PARSE = -32700;
|
|
9009
|
+
ACP_ERROR_CODE_INVALID_REQUEST = -32600;
|
|
9010
|
+
ACP_ERROR_CODE_METHOD_NOT_FOUND = -32601;
|
|
9011
|
+
ACP_ERROR_CODE_INVALID_PARAMS = -32602;
|
|
9012
|
+
ACP_ERROR_CODE_INTERNAL = -32603;
|
|
9013
|
+
ACP_ERROR_CODE_RESOURCE_NOT_FOUND = -32002;
|
|
9014
|
+
AcpError = class extends Error {
|
|
9015
|
+
code;
|
|
9016
|
+
data;
|
|
9017
|
+
constructor(code, message2, data) {
|
|
9018
|
+
super(message2);
|
|
9019
|
+
this.name = "AcpError";
|
|
9020
|
+
this.code = code;
|
|
9021
|
+
if (data !== void 0) {
|
|
9022
|
+
this.data = data;
|
|
9023
|
+
}
|
|
9024
|
+
}
|
|
9025
|
+
};
|
|
8843
9026
|
}
|
|
8844
9027
|
});
|
|
8845
9028
|
|
|
8846
|
-
// packages/
|
|
8847
|
-
function
|
|
8848
|
-
|
|
8849
|
-
if (maxLength <= 3) return text4.slice(0, maxLength);
|
|
8850
|
-
return `${text4.slice(0, maxLength - 3)}...`;
|
|
9029
|
+
// packages/poe-acp-client/src/jsonrpc-message-layer.ts
|
|
9030
|
+
function isObjectRecord2(value) {
|
|
9031
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8851
9032
|
}
|
|
8852
|
-
function
|
|
8853
|
-
return
|
|
9033
|
+
function hasOwn2(value, property) {
|
|
9034
|
+
return Object.prototype.hasOwnProperty.call(value, property);
|
|
8854
9035
|
}
|
|
8855
|
-
function
|
|
8856
|
-
|
|
8857
|
-
const obj = value;
|
|
8858
|
-
const maybeThreadId = isNonEmptyString(obj.thread_id) && obj.thread_id || isNonEmptyString(obj.threadId) && obj.threadId || isNonEmptyString(obj.threadID) && obj.threadID || isNonEmptyString(obj.session_id) && obj.session_id || isNonEmptyString(obj.sessionId) && obj.sessionId || isNonEmptyString(obj.sessionID) && obj.sessionID;
|
|
8859
|
-
return maybeThreadId || void 0;
|
|
9036
|
+
function isRequestId(value) {
|
|
9037
|
+
return value === null || typeof value === "string" || typeof value === "number";
|
|
8860
9038
|
}
|
|
8861
|
-
|
|
8862
|
-
|
|
8863
|
-
|
|
9039
|
+
function toRequestId(value) {
|
|
9040
|
+
return isRequestId(value) ? value : null;
|
|
9041
|
+
}
|
|
9042
|
+
function parseError() {
|
|
9043
|
+
return new AcpError(ACP_ERROR_CODE_PARSE, "Parse error");
|
|
9044
|
+
}
|
|
9045
|
+
function invalidRequest() {
|
|
9046
|
+
return new AcpError(ACP_ERROR_CODE_INVALID_REQUEST, "Invalid Request");
|
|
9047
|
+
}
|
|
9048
|
+
function methodNotFound(method) {
|
|
9049
|
+
return new AcpError(
|
|
9050
|
+
ACP_ERROR_CODE_METHOD_NOT_FOUND,
|
|
9051
|
+
`Method not found: "${method}"`
|
|
9052
|
+
);
|
|
9053
|
+
}
|
|
9054
|
+
function internalError(message2) {
|
|
9055
|
+
return new AcpError(ACP_ERROR_CODE_INTERNAL, message2);
|
|
9056
|
+
}
|
|
9057
|
+
function isJsonRpcErrorObject(value) {
|
|
9058
|
+
if (!isObjectRecord2(value)) {
|
|
9059
|
+
return false;
|
|
8864
9060
|
}
|
|
8865
|
-
|
|
8866
|
-
|
|
8867
|
-
|
|
8868
|
-
|
|
8869
|
-
|
|
8870
|
-
|
|
8871
|
-
|
|
8872
|
-
|
|
8873
|
-
|
|
8874
|
-
|
|
8875
|
-
|
|
9061
|
+
if (!isAcpErrorCode(value.code) || typeof value.message !== "string") {
|
|
9062
|
+
return false;
|
|
9063
|
+
}
|
|
9064
|
+
return value.data === void 0 || hasOwn2(value, "data");
|
|
9065
|
+
}
|
|
9066
|
+
function toResponseError(error2) {
|
|
9067
|
+
return new AcpError(error2.code, error2.message, error2.data);
|
|
9068
|
+
}
|
|
9069
|
+
function toDispatchError(error2) {
|
|
9070
|
+
if (error2 instanceof AcpError) {
|
|
9071
|
+
return error2;
|
|
9072
|
+
}
|
|
9073
|
+
if (isAcpError(error2)) {
|
|
9074
|
+
return new AcpError(error2.code, error2.message, error2.data);
|
|
9075
|
+
}
|
|
9076
|
+
if (error2 instanceof Error && error2.message.length > 0) {
|
|
9077
|
+
return internalError(error2.message);
|
|
9078
|
+
}
|
|
9079
|
+
return internalError("Internal error");
|
|
9080
|
+
}
|
|
9081
|
+
function chunkToString(chunk) {
|
|
9082
|
+
if (typeof chunk === "string") {
|
|
9083
|
+
return chunk;
|
|
9084
|
+
}
|
|
9085
|
+
if (chunk instanceof Uint8Array) {
|
|
9086
|
+
return Buffer.from(chunk).toString("utf8");
|
|
9087
|
+
}
|
|
9088
|
+
return String(chunk);
|
|
9089
|
+
}
|
|
9090
|
+
function normalizeLine(line) {
|
|
9091
|
+
return line.endsWith("\r") ? line.slice(0, -1) : line;
|
|
9092
|
+
}
|
|
9093
|
+
async function* readLines(stream) {
|
|
9094
|
+
let buffer = "";
|
|
9095
|
+
for await (const chunk of stream) {
|
|
9096
|
+
buffer += chunkToString(chunk);
|
|
9097
|
+
while (true) {
|
|
9098
|
+
const newlineIndex = buffer.indexOf("\n");
|
|
9099
|
+
if (newlineIndex === -1) {
|
|
9100
|
+
break;
|
|
8876
9101
|
}
|
|
9102
|
+
const line = buffer.slice(0, newlineIndex);
|
|
9103
|
+
buffer = buffer.slice(newlineIndex + 1);
|
|
9104
|
+
yield normalizeLine(line);
|
|
8877
9105
|
}
|
|
8878
9106
|
}
|
|
8879
|
-
|
|
9107
|
+
if (buffer.length > 0) {
|
|
9108
|
+
yield normalizeLine(buffer);
|
|
9109
|
+
}
|
|
8880
9110
|
}
|
|
8881
|
-
|
|
8882
|
-
|
|
8883
|
-
|
|
8884
|
-
|
|
8885
|
-
|
|
8886
|
-
|
|
8887
|
-
|
|
8888
|
-
|
|
8889
|
-
|
|
8890
|
-
|
|
8891
|
-
|
|
8892
|
-
|
|
8893
|
-
|
|
8894
|
-
|
|
8895
|
-
const stack = error2 instanceof Error ? error2.stack : void 0;
|
|
8896
|
-
yield {
|
|
8897
|
-
event: "error",
|
|
8898
|
-
message: `[adaptClaude] Malformed JSON line: ${truncate2(line, 200)}`,
|
|
8899
|
-
stack
|
|
8900
|
-
};
|
|
8901
|
-
continue;
|
|
8902
|
-
}
|
|
8903
|
-
const eventType = event.type;
|
|
8904
|
-
if (!isNonEmptyString(eventType)) continue;
|
|
8905
|
-
if (!emittedSessionStart) {
|
|
8906
|
-
const threadId = extractThreadId(event);
|
|
8907
|
-
emittedSessionStart = true;
|
|
8908
|
-
yield { event: "session_start", threadId };
|
|
8909
|
-
}
|
|
8910
|
-
if (eventType === "result") {
|
|
8911
|
-
const usage = event.usage ?? {};
|
|
8912
|
-
const inputTokens = typeof usage.input_tokens === "number" ? usage.input_tokens : typeof event.input_tokens === "number" ? event.input_tokens : typeof event.num_input_tokens === "number" ? event.num_input_tokens : 0;
|
|
8913
|
-
const outputTokens = typeof usage.output_tokens === "number" ? usage.output_tokens : typeof event.output_tokens === "number" ? event.output_tokens : typeof event.num_output_tokens === "number" ? event.num_output_tokens : 0;
|
|
8914
|
-
const costUsd = typeof usage.cost_usd === "number" ? usage.cost_usd : typeof event.cost_usd === "number" ? event.cost_usd : void 0;
|
|
8915
|
-
yield { event: "usage", inputTokens, outputTokens, costUsd };
|
|
8916
|
-
continue;
|
|
8917
|
-
}
|
|
8918
|
-
if (eventType !== "assistant" && eventType !== "user") continue;
|
|
8919
|
-
const message2 = event.message ?? null;
|
|
8920
|
-
if (!message2 || typeof message2 !== "object") continue;
|
|
8921
|
-
const content = message2.content ?? null;
|
|
8922
|
-
if (!Array.isArray(content)) continue;
|
|
8923
|
-
for (const block of content) {
|
|
8924
|
-
const item = block;
|
|
8925
|
-
if (!item || typeof item !== "object") continue;
|
|
8926
|
-
const blockType = item.type;
|
|
8927
|
-
if (!isNonEmptyString(blockType)) continue;
|
|
8928
|
-
if (eventType === "assistant") {
|
|
8929
|
-
if (blockType === "text" && isNonEmptyString(item.text)) {
|
|
8930
|
-
yield {
|
|
8931
|
-
event: "agent_message",
|
|
8932
|
-
text: item.text
|
|
8933
|
-
};
|
|
8934
|
-
continue;
|
|
8935
|
-
}
|
|
8936
|
-
if (blockType === "tool_use" && isNonEmptyString(item.id) && isNonEmptyString(item.name)) {
|
|
8937
|
-
const kind = TOOL_KIND_MAP[item.name] ?? "other";
|
|
8938
|
-
toolKindsById.set(item.id, kind);
|
|
8939
|
-
yield {
|
|
8940
|
-
event: "tool_start",
|
|
8941
|
-
id: item.id,
|
|
8942
|
-
kind,
|
|
8943
|
-
title: extractTitle(item.name, item.input),
|
|
8944
|
-
input: item.input
|
|
8945
|
-
};
|
|
8946
|
-
}
|
|
8947
|
-
continue;
|
|
8948
|
-
}
|
|
8949
|
-
if (eventType === "user") {
|
|
8950
|
-
if (!isNonEmptyString(item.tool_use_id)) continue;
|
|
8951
|
-
if (blockType !== "tool_result") continue;
|
|
8952
|
-
const kind = toolKindsById.get(item.tool_use_id);
|
|
8953
|
-
toolKindsById.delete(item.tool_use_id);
|
|
8954
|
-
let path54;
|
|
8955
|
-
if (typeof item.content === "string") {
|
|
8956
|
-
path54 = item.content;
|
|
8957
|
-
} else {
|
|
8958
|
-
try {
|
|
8959
|
-
path54 = JSON.stringify(item.content);
|
|
8960
|
-
} catch {
|
|
8961
|
-
path54 = String(item.content);
|
|
8962
|
-
}
|
|
8963
|
-
}
|
|
8964
|
-
yield {
|
|
8965
|
-
event: "tool_complete",
|
|
8966
|
-
id: item.tool_use_id,
|
|
8967
|
-
kind,
|
|
8968
|
-
path: path54
|
|
8969
|
-
};
|
|
8970
|
-
}
|
|
9111
|
+
function createResponseMessage(id, result) {
|
|
9112
|
+
return {
|
|
9113
|
+
jsonrpc: "2.0",
|
|
9114
|
+
id,
|
|
9115
|
+
result: result === void 0 ? null : result
|
|
9116
|
+
};
|
|
9117
|
+
}
|
|
9118
|
+
function createJsonRpcErrorResponse(id, error2) {
|
|
9119
|
+
const response = {
|
|
9120
|
+
jsonrpc: "2.0",
|
|
9121
|
+
id,
|
|
9122
|
+
error: {
|
|
9123
|
+
code: error2.code,
|
|
9124
|
+
message: error2.message
|
|
8971
9125
|
}
|
|
9126
|
+
};
|
|
9127
|
+
if (error2.data !== void 0) {
|
|
9128
|
+
response.error.data = error2.data;
|
|
8972
9129
|
}
|
|
9130
|
+
return response;
|
|
8973
9131
|
}
|
|
8974
|
-
|
|
8975
|
-
|
|
8976
|
-
|
|
8977
|
-
|
|
8978
|
-
|
|
8979
|
-
|
|
8980
|
-
|
|
8981
|
-
|
|
8982
|
-
|
|
8983
|
-
|
|
8984
|
-
|
|
8985
|
-
|
|
8986
|
-
|
|
8987
|
-
Task: "think"
|
|
9132
|
+
function serializeJsonRpcMessage(message2) {
|
|
9133
|
+
return `${JSON.stringify(message2)}
|
|
9134
|
+
`;
|
|
9135
|
+
}
|
|
9136
|
+
function parseJsonRpcMessage(line) {
|
|
9137
|
+
let parsed;
|
|
9138
|
+
try {
|
|
9139
|
+
parsed = JSON.parse(line);
|
|
9140
|
+
} catch {
|
|
9141
|
+
return {
|
|
9142
|
+
type: "invalid",
|
|
9143
|
+
id: null,
|
|
9144
|
+
error: parseError()
|
|
8988
9145
|
};
|
|
8989
|
-
|
|
8990
|
-
|
|
8991
|
-
|
|
8992
|
-
|
|
8993
|
-
|
|
8994
|
-
|
|
8995
|
-
Glob: ["pattern"],
|
|
8996
|
-
Grep: ["pattern"],
|
|
8997
|
-
Task: ["description", "prompt"]
|
|
9146
|
+
}
|
|
9147
|
+
if (!isObjectRecord2(parsed)) {
|
|
9148
|
+
return {
|
|
9149
|
+
type: "invalid",
|
|
9150
|
+
id: null,
|
|
9151
|
+
error: invalidRequest()
|
|
8998
9152
|
};
|
|
8999
9153
|
}
|
|
9000
|
-
|
|
9001
|
-
|
|
9002
|
-
|
|
9003
|
-
|
|
9004
|
-
|
|
9005
|
-
|
|
9006
|
-
|
|
9007
|
-
|
|
9008
|
-
|
|
9009
|
-
|
|
9010
|
-
|
|
9011
|
-
|
|
9012
|
-
|
|
9013
|
-
|
|
9014
|
-
|
|
9015
|
-
|
|
9016
|
-
message: `[adaptCodex] Malformed JSON line: ${truncate2(line, 200)}`,
|
|
9017
|
-
stack
|
|
9154
|
+
const id = toRequestId(parsed.id);
|
|
9155
|
+
if (parsed.jsonrpc !== "2.0") {
|
|
9156
|
+
return {
|
|
9157
|
+
type: "invalid",
|
|
9158
|
+
id,
|
|
9159
|
+
error: invalidRequest()
|
|
9160
|
+
};
|
|
9161
|
+
}
|
|
9162
|
+
const hasMethod = hasOwn2(parsed, "method");
|
|
9163
|
+
const hasId = hasOwn2(parsed, "id");
|
|
9164
|
+
if (hasMethod) {
|
|
9165
|
+
if (typeof parsed.method !== "string") {
|
|
9166
|
+
return {
|
|
9167
|
+
type: "invalid",
|
|
9168
|
+
id,
|
|
9169
|
+
error: invalidRequest()
|
|
9018
9170
|
};
|
|
9019
|
-
continue;
|
|
9020
|
-
}
|
|
9021
|
-
const eventType = event.type;
|
|
9022
|
-
if (!isNonEmptyString(eventType)) continue;
|
|
9023
|
-
if (eventType === "thread.started") {
|
|
9024
|
-
const maybeThreadId = extractThreadId(event);
|
|
9025
|
-
yield { event: "session_start", threadId: maybeThreadId };
|
|
9026
|
-
continue;
|
|
9027
|
-
}
|
|
9028
|
-
if (eventType === "turn.started") {
|
|
9029
|
-
continue;
|
|
9030
9171
|
}
|
|
9031
|
-
if (
|
|
9032
|
-
|
|
9033
|
-
|
|
9034
|
-
|
|
9035
|
-
|
|
9036
|
-
|
|
9037
|
-
|
|
9172
|
+
if (hasId) {
|
|
9173
|
+
if (!isRequestId(parsed.id)) {
|
|
9174
|
+
return {
|
|
9175
|
+
type: "invalid",
|
|
9176
|
+
id: null,
|
|
9177
|
+
error: invalidRequest()
|
|
9178
|
+
};
|
|
9179
|
+
}
|
|
9180
|
+
const request = {
|
|
9181
|
+
jsonrpc: "2.0",
|
|
9182
|
+
id: parsed.id,
|
|
9183
|
+
method: parsed.method
|
|
9184
|
+
};
|
|
9185
|
+
if (hasOwn2(parsed, "params")) {
|
|
9186
|
+
request.params = parsed.params;
|
|
9187
|
+
}
|
|
9188
|
+
return { type: "request", message: request };
|
|
9038
9189
|
}
|
|
9039
|
-
|
|
9040
|
-
|
|
9041
|
-
|
|
9042
|
-
|
|
9043
|
-
|
|
9044
|
-
|
|
9045
|
-
if (!item || typeof item !== "object") continue;
|
|
9046
|
-
const itemType = item.type;
|
|
9047
|
-
if (!isNonEmptyString(itemType)) continue;
|
|
9048
|
-
if (eventType === "item.started") {
|
|
9049
|
-
if (!isNonEmptyString(item.id)) continue;
|
|
9050
|
-
let kind;
|
|
9051
|
-
let title;
|
|
9052
|
-
if (itemType === "command_execution") {
|
|
9053
|
-
kind = "exec";
|
|
9054
|
-
title = truncate2(isNonEmptyString(item.command) ? item.command : "", 80);
|
|
9055
|
-
} else if (itemType === "file_edit") {
|
|
9056
|
-
kind = "edit";
|
|
9057
|
-
title = isNonEmptyString(item.path) ? item.path : "";
|
|
9058
|
-
} else if (itemType === "thinking") {
|
|
9059
|
-
kind = "think";
|
|
9060
|
-
title = "thinking...";
|
|
9061
|
-
} else if (itemType === "mcp_tool_call") {
|
|
9062
|
-
const server = isNonEmptyString(item.server) ? item.server : "unknown";
|
|
9063
|
-
const tool = isNonEmptyString(item.tool) ? item.tool : "unknown";
|
|
9064
|
-
kind = "other";
|
|
9065
|
-
title = `${server}.${tool}`;
|
|
9066
|
-
}
|
|
9067
|
-
if (kind && title !== void 0) {
|
|
9068
|
-
toolTitleById.set(item.id, title);
|
|
9069
|
-
toolKindById.set(item.id, kind);
|
|
9070
|
-
yield { event: "tool_start", id: item.id, kind, title };
|
|
9071
|
-
}
|
|
9072
|
-
continue;
|
|
9073
|
-
}
|
|
9074
|
-
if (eventType === "item.completed") {
|
|
9075
|
-
if (itemType === "agent_message") {
|
|
9076
|
-
if (!isNonEmptyString(item.text)) continue;
|
|
9077
|
-
yield { event: "agent_message", text: item.text };
|
|
9078
|
-
continue;
|
|
9079
|
-
}
|
|
9080
|
-
if (itemType === "reasoning") {
|
|
9081
|
-
const text4 = isNonEmptyString(item.text) ? item.text : isNonEmptyString(item.content) ? item.content : isNonEmptyString(item.summary) ? item.summary : void 0;
|
|
9082
|
-
if (!text4) continue;
|
|
9083
|
-
yield { event: "reasoning", text: text4 };
|
|
9084
|
-
continue;
|
|
9085
|
-
}
|
|
9086
|
-
if (!isNonEmptyString(item.id)) continue;
|
|
9087
|
-
if (itemType === "command_execution" || itemType === "file_edit" || itemType === "mcp_tool_call") {
|
|
9088
|
-
const kindFromStart = toolKindById.get(item.id);
|
|
9089
|
-
const kind = kindFromStart ?? (itemType === "command_execution" ? "exec" : itemType === "file_edit" ? "edit" : "other");
|
|
9090
|
-
const titleFromEvent = isNonEmptyString(item.path) ? item.path : itemType === "mcp_tool_call" ? `${isNonEmptyString(item.server) ? item.server : "unknown"}.${isNonEmptyString(item.tool) ? item.tool : "unknown"}` : void 0;
|
|
9091
|
-
const path54 = titleFromEvent ?? toolTitleById.get(item.id) ?? "";
|
|
9092
|
-
toolTitleById.delete(item.id);
|
|
9093
|
-
toolKindById.delete(item.id);
|
|
9094
|
-
yield { event: "tool_complete", id: item.id, kind, path: path54 };
|
|
9095
|
-
}
|
|
9096
|
-
}
|
|
9097
|
-
}
|
|
9098
|
-
}
|
|
9099
|
-
function extractErrorMessage(event) {
|
|
9100
|
-
if (isNonEmptyString(event.message)) return event.message;
|
|
9101
|
-
const error2 = event.error;
|
|
9102
|
-
if (isNonEmptyString(error2)) return error2;
|
|
9103
|
-
if (typeof error2 === "object" && error2 !== null) {
|
|
9104
|
-
const errorObj = error2;
|
|
9105
|
-
if (isNonEmptyString(errorObj.message)) return errorObj.message;
|
|
9106
|
-
}
|
|
9107
|
-
if (isNonEmptyString(event.reason)) return event.reason;
|
|
9108
|
-
return void 0;
|
|
9109
|
-
}
|
|
9110
|
-
var init_codex3 = __esm({
|
|
9111
|
-
"packages/agent-spawn/src/adapters/codex.ts"() {
|
|
9112
|
-
"use strict";
|
|
9113
|
-
init_utils();
|
|
9114
|
-
}
|
|
9115
|
-
});
|
|
9116
|
-
|
|
9117
|
-
// packages/agent-spawn/src/adapters/kimi.ts
|
|
9118
|
-
async function* adaptKimi(lines) {
|
|
9119
|
-
let emittedSessionStart = false;
|
|
9120
|
-
for await (const rawLine of lines) {
|
|
9121
|
-
const line = rawLine.trim();
|
|
9122
|
-
if (!line) continue;
|
|
9123
|
-
let event;
|
|
9124
|
-
try {
|
|
9125
|
-
event = JSON.parse(line);
|
|
9126
|
-
} catch (error2) {
|
|
9127
|
-
const stack = error2 instanceof Error ? error2.stack : void 0;
|
|
9128
|
-
yield {
|
|
9129
|
-
event: "error",
|
|
9130
|
-
message: `[adaptKimi] Malformed JSON line: ${truncate2(line, 200)}`,
|
|
9131
|
-
stack
|
|
9132
|
-
};
|
|
9133
|
-
continue;
|
|
9134
|
-
}
|
|
9135
|
-
if (!event || typeof event !== "object") continue;
|
|
9136
|
-
if (!emittedSessionStart) {
|
|
9137
|
-
const threadId = extractThreadId(event);
|
|
9138
|
-
if (threadId) {
|
|
9139
|
-
emittedSessionStart = true;
|
|
9140
|
-
yield { event: "session_start", threadId };
|
|
9141
|
-
}
|
|
9142
|
-
}
|
|
9143
|
-
const role = event.role;
|
|
9144
|
-
if (!isNonEmptyString(role) || role !== "assistant") continue;
|
|
9145
|
-
const content = event.content;
|
|
9146
|
-
if (!isNonEmptyString(content)) continue;
|
|
9147
|
-
yield { event: "agent_message", text: content };
|
|
9148
|
-
}
|
|
9149
|
-
}
|
|
9150
|
-
var init_kimi3 = __esm({
|
|
9151
|
-
"packages/agent-spawn/src/adapters/kimi.ts"() {
|
|
9152
|
-
"use strict";
|
|
9153
|
-
init_utils();
|
|
9154
|
-
}
|
|
9155
|
-
});
|
|
9156
|
-
|
|
9157
|
-
// packages/agent-spawn/src/adapters/native.ts
|
|
9158
|
-
async function* adaptNative(lines) {
|
|
9159
|
-
for await (const rawLine of lines) {
|
|
9160
|
-
const line = rawLine.trim();
|
|
9161
|
-
if (!line) continue;
|
|
9162
|
-
let event;
|
|
9163
|
-
try {
|
|
9164
|
-
event = JSON.parse(line);
|
|
9165
|
-
} catch (error2) {
|
|
9166
|
-
const stack = error2 instanceof Error ? error2.stack : void 0;
|
|
9167
|
-
yield {
|
|
9168
|
-
event: "error",
|
|
9169
|
-
message: `[adaptNative] Malformed JSON line: ${truncate2(line, 200)}`,
|
|
9170
|
-
stack
|
|
9171
|
-
};
|
|
9172
|
-
continue;
|
|
9173
|
-
}
|
|
9174
|
-
const maybeEventType = event?.event;
|
|
9175
|
-
if (!isNonEmptyString(maybeEventType)) {
|
|
9176
|
-
yield {
|
|
9177
|
-
event: "error",
|
|
9178
|
-
message: `[adaptNative] Line missing string "event" field: ${truncate2(line, 200)}`
|
|
9179
|
-
};
|
|
9180
|
-
continue;
|
|
9181
|
-
}
|
|
9182
|
-
yield event;
|
|
9183
|
-
}
|
|
9184
|
-
}
|
|
9185
|
-
var init_native = __esm({
|
|
9186
|
-
"packages/agent-spawn/src/adapters/native.ts"() {
|
|
9187
|
-
"use strict";
|
|
9188
|
-
init_utils();
|
|
9189
|
-
}
|
|
9190
|
-
});
|
|
9191
|
-
|
|
9192
|
-
// packages/agent-spawn/src/adapters/opencode.ts
|
|
9193
|
-
function guessToolKind(toolName) {
|
|
9194
|
-
const normalized = toolName.toLowerCase();
|
|
9195
|
-
if (normalized === "bash" || normalized === "shell" || normalized === "sh") return "exec";
|
|
9196
|
-
if (normalized.includes("read")) return "read";
|
|
9197
|
-
if (normalized.includes("write") || normalized.includes("edit") || normalized.includes("patch")) {
|
|
9198
|
-
return "edit";
|
|
9199
|
-
}
|
|
9200
|
-
if (normalized.includes("search") || normalized.includes("grep") || normalized.includes("glob") || normalized.includes("find")) {
|
|
9201
|
-
return "search";
|
|
9202
|
-
}
|
|
9203
|
-
if (normalized.includes("think") || normalized.includes("task")) return "think";
|
|
9204
|
-
return "other";
|
|
9205
|
-
}
|
|
9206
|
-
function safeStringify(value) {
|
|
9207
|
-
if (typeof value === "string") return value;
|
|
9208
|
-
try {
|
|
9209
|
-
return JSON.stringify(value);
|
|
9210
|
-
} catch {
|
|
9211
|
-
return String(value);
|
|
9212
|
-
}
|
|
9213
|
-
}
|
|
9214
|
-
async function* adaptOpenCode(lines) {
|
|
9215
|
-
let emittedSessionStart = false;
|
|
9216
|
-
const toolKindById = /* @__PURE__ */ new Map();
|
|
9217
|
-
for await (const rawLine of lines) {
|
|
9218
|
-
const line = rawLine.trim();
|
|
9219
|
-
if (!line) continue;
|
|
9220
|
-
let event;
|
|
9221
|
-
try {
|
|
9222
|
-
event = JSON.parse(line);
|
|
9223
|
-
} catch (error2) {
|
|
9224
|
-
const stack = error2 instanceof Error ? error2.stack : void 0;
|
|
9225
|
-
yield {
|
|
9226
|
-
event: "error",
|
|
9227
|
-
message: `[adaptOpenCode] Malformed JSON line: ${truncate2(line, 200)}`,
|
|
9228
|
-
stack
|
|
9229
|
-
};
|
|
9230
|
-
continue;
|
|
9231
|
-
}
|
|
9232
|
-
if (!event || typeof event !== "object") continue;
|
|
9233
|
-
const sessionID = extractThreadId(event);
|
|
9234
|
-
if (!emittedSessionStart && isNonEmptyString(sessionID)) {
|
|
9235
|
-
emittedSessionStart = true;
|
|
9236
|
-
yield { event: "session_start", threadId: sessionID };
|
|
9237
|
-
}
|
|
9238
|
-
const eventType = event.type;
|
|
9239
|
-
if (!isNonEmptyString(eventType)) continue;
|
|
9240
|
-
if (eventType === "text") {
|
|
9241
|
-
const part = event.part ?? null;
|
|
9242
|
-
if (!part || typeof part !== "object") continue;
|
|
9243
|
-
if (!isNonEmptyString(part.text)) continue;
|
|
9244
|
-
yield { event: "agent_message", text: part.text };
|
|
9245
|
-
continue;
|
|
9246
|
-
}
|
|
9247
|
-
if (eventType === "tool_use") {
|
|
9248
|
-
const part = event.part ?? null;
|
|
9249
|
-
if (!part || typeof part !== "object") continue;
|
|
9250
|
-
if (!isNonEmptyString(part.callID) || !isNonEmptyString(part.tool)) continue;
|
|
9251
|
-
const state = part.state ?? null;
|
|
9252
|
-
if (!state || typeof state !== "object") continue;
|
|
9253
|
-
const kind = guessToolKind(part.tool);
|
|
9254
|
-
const status = state.status;
|
|
9255
|
-
const terminal = status === "completed" || status === "failed";
|
|
9256
|
-
if (!toolKindById.has(part.callID)) {
|
|
9257
|
-
toolKindById.set(part.callID, kind);
|
|
9258
|
-
let title = part.tool;
|
|
9259
|
-
const maybeInput = state.input;
|
|
9260
|
-
if (kind === "exec" && maybeInput && typeof maybeInput === "object") {
|
|
9261
|
-
const command = maybeInput.command;
|
|
9262
|
-
if (isNonEmptyString(command)) {
|
|
9263
|
-
title = truncate2(command, 80);
|
|
9264
|
-
}
|
|
9265
|
-
}
|
|
9266
|
-
yield {
|
|
9267
|
-
event: "tool_start",
|
|
9268
|
-
id: part.callID,
|
|
9269
|
-
kind,
|
|
9270
|
-
title,
|
|
9271
|
-
input: state.input
|
|
9272
|
-
};
|
|
9273
|
-
}
|
|
9274
|
-
if (terminal) {
|
|
9275
|
-
const kindFromStart = toolKindById.get(part.callID) ?? kind;
|
|
9276
|
-
toolKindById.delete(part.callID);
|
|
9277
|
-
yield {
|
|
9278
|
-
event: "tool_complete",
|
|
9279
|
-
id: part.callID,
|
|
9280
|
-
kind: kindFromStart,
|
|
9281
|
-
path: safeStringify(state.output)
|
|
9282
|
-
};
|
|
9283
|
-
}
|
|
9284
|
-
continue;
|
|
9285
|
-
}
|
|
9286
|
-
if (eventType === "step_finish") {
|
|
9287
|
-
const part = event.part ?? null;
|
|
9288
|
-
if (!part || typeof part !== "object") continue;
|
|
9289
|
-
const tokens = part.tokens ?? null;
|
|
9290
|
-
if (!tokens || typeof tokens !== "object") continue;
|
|
9291
|
-
const inputTokens = typeof tokens.input === "number" ? tokens.input : 0;
|
|
9292
|
-
const outputTokens = typeof tokens.output === "number" ? tokens.output : 0;
|
|
9293
|
-
const cache = tokens.cache ?? null;
|
|
9294
|
-
const cachedTokens = cache && typeof cache === "object" && typeof cache.read === "number" ? cache.read : void 0;
|
|
9295
|
-
if (inputTokens === 0 && outputTokens === 0 && cachedTokens === void 0) continue;
|
|
9296
|
-
yield { event: "usage", inputTokens, outputTokens, cachedTokens };
|
|
9297
|
-
continue;
|
|
9298
|
-
}
|
|
9299
|
-
}
|
|
9300
|
-
}
|
|
9301
|
-
var init_opencode3 = __esm({
|
|
9302
|
-
"packages/agent-spawn/src/adapters/opencode.ts"() {
|
|
9303
|
-
"use strict";
|
|
9304
|
-
init_utils();
|
|
9305
|
-
}
|
|
9306
|
-
});
|
|
9307
|
-
|
|
9308
|
-
// packages/agent-spawn/src/adapters/index.ts
|
|
9309
|
-
function getAdapter(type) {
|
|
9310
|
-
const adapter = adapters[type];
|
|
9311
|
-
if (!adapter) {
|
|
9312
|
-
throw new Error(`Unknown adapter "${String(type)}".`);
|
|
9313
|
-
}
|
|
9314
|
-
return adapter;
|
|
9315
|
-
}
|
|
9316
|
-
var adapters;
|
|
9317
|
-
var init_adapters = __esm({
|
|
9318
|
-
"packages/agent-spawn/src/adapters/index.ts"() {
|
|
9319
|
-
"use strict";
|
|
9320
|
-
init_claude();
|
|
9321
|
-
init_codex3();
|
|
9322
|
-
init_kimi3();
|
|
9323
|
-
init_native();
|
|
9324
|
-
init_opencode3();
|
|
9325
|
-
init_codex3();
|
|
9326
|
-
init_claude();
|
|
9327
|
-
init_kimi3();
|
|
9328
|
-
init_native();
|
|
9329
|
-
init_opencode3();
|
|
9330
|
-
adapters = {
|
|
9331
|
-
codex: adaptCodex,
|
|
9332
|
-
claude: adaptClaude,
|
|
9333
|
-
kimi: adaptKimi,
|
|
9334
|
-
native: adaptNative,
|
|
9335
|
-
opencode: adaptOpenCode
|
|
9336
|
-
};
|
|
9337
|
-
}
|
|
9338
|
-
});
|
|
9339
|
-
|
|
9340
|
-
// packages/agent-spawn/src/acp/line-reader.ts
|
|
9341
|
-
function chunkToString(chunk) {
|
|
9342
|
-
if (typeof chunk === "string") return chunk;
|
|
9343
|
-
if (chunk instanceof Uint8Array) return Buffer.from(chunk).toString("utf8");
|
|
9344
|
-
return String(chunk);
|
|
9345
|
-
}
|
|
9346
|
-
async function* readLines(stream) {
|
|
9347
|
-
let buffer = "";
|
|
9348
|
-
for await (const chunk of stream) {
|
|
9349
|
-
buffer += chunkToString(chunk);
|
|
9350
|
-
while (true) {
|
|
9351
|
-
const newlineIndex = buffer.indexOf("\n");
|
|
9352
|
-
if (newlineIndex === -1) break;
|
|
9353
|
-
yield buffer.slice(0, newlineIndex);
|
|
9354
|
-
buffer = buffer.slice(newlineIndex + 1);
|
|
9355
|
-
}
|
|
9356
|
-
}
|
|
9357
|
-
if (buffer.length > 0) {
|
|
9358
|
-
yield buffer;
|
|
9359
|
-
}
|
|
9360
|
-
}
|
|
9361
|
-
var init_line_reader = __esm({
|
|
9362
|
-
"packages/agent-spawn/src/acp/line-reader.ts"() {
|
|
9363
|
-
"use strict";
|
|
9364
|
-
}
|
|
9365
|
-
});
|
|
9366
|
-
|
|
9367
|
-
// packages/agent-spawn/src/acp/spawn.ts
|
|
9368
|
-
import { spawn as spawnChildProcess3 } from "node:child_process";
|
|
9369
|
-
function createAbortError2() {
|
|
9370
|
-
const error2 = new Error("Agent spawn aborted");
|
|
9371
|
-
error2.name = "AbortError";
|
|
9372
|
-
return error2;
|
|
9373
|
-
}
|
|
9374
|
-
function createActivityTimeoutError2(timeoutMs) {
|
|
9375
|
-
const error2 = new Error(
|
|
9376
|
-
`Agent spawn timed out after ${timeoutMs / 1e3}s of inactivity`
|
|
9377
|
-
);
|
|
9378
|
-
error2.name = "ActivityTimeoutError";
|
|
9379
|
-
return error2;
|
|
9380
|
-
}
|
|
9381
|
-
function isAcpEvent(value) {
|
|
9382
|
-
return !!value && typeof value === "object" && "event" in value;
|
|
9383
|
-
}
|
|
9384
|
-
function getDefaultArgsPosition2(config) {
|
|
9385
|
-
return config.defaultArgsPosition ?? "afterPrompt";
|
|
9386
|
-
}
|
|
9387
|
-
function getMcpArgsPosition2(config) {
|
|
9388
|
-
if (config.mcpArgsPosition) {
|
|
9389
|
-
return config.mcpArgsPosition;
|
|
9390
|
-
}
|
|
9391
|
-
return config.mcpArgsBeforeCommand ? "beforeCommand" : "afterCommand";
|
|
9392
|
-
}
|
|
9393
|
-
function spawnStreaming(options) {
|
|
9394
|
-
if (options.signal?.aborted) {
|
|
9395
|
-
throw createAbortError2();
|
|
9396
|
-
}
|
|
9397
|
-
const { agentId, binaryName, spawnConfig } = resolveConfig(options.agentId);
|
|
9398
|
-
if (spawnConfig === void 0) {
|
|
9399
|
-
throw new Error(`Agent "${agentId}" has no spawn config.`);
|
|
9400
|
-
}
|
|
9401
|
-
if (spawnConfig.kind !== "cli") {
|
|
9402
|
-
throw new Error(`Agent "${agentId}" does not support CLI spawn.`);
|
|
9403
|
-
}
|
|
9404
|
-
if (!binaryName) {
|
|
9405
|
-
throw new Error(`Agent "${agentId}" has no binaryName.`);
|
|
9406
|
-
}
|
|
9407
|
-
const mcpArgs = getMcpArgs(spawnConfig, options.mcpServers);
|
|
9408
|
-
const mcpEnvVars = getMcpEnv(spawnConfig, options.mcpServers);
|
|
9409
|
-
const defaultArgsPosition = getDefaultArgsPosition2(spawnConfig);
|
|
9410
|
-
const mcpArgsPosition = getMcpArgsPosition2(spawnConfig);
|
|
9411
|
-
const args = [];
|
|
9412
|
-
if (mcpArgsPosition === "beforeCommand") {
|
|
9413
|
-
args.push(...mcpArgs);
|
|
9414
|
-
}
|
|
9415
|
-
if (defaultArgsPosition === "beforePrompt") {
|
|
9416
|
-
args.push(...spawnConfig.defaultArgs);
|
|
9417
|
-
}
|
|
9418
|
-
if (mcpArgsPosition === "beforePrompt") {
|
|
9419
|
-
args.push(...mcpArgs);
|
|
9420
|
-
}
|
|
9421
|
-
args.push(spawnConfig.promptFlag);
|
|
9422
|
-
const useStdin = !!options.useStdin && !!spawnConfig.stdinMode;
|
|
9423
|
-
if (!useStdin || !spawnConfig.stdinMode?.omitPrompt) {
|
|
9424
|
-
args.push(options.prompt);
|
|
9425
|
-
}
|
|
9426
|
-
if (options.model && spawnConfig.modelFlag) {
|
|
9427
|
-
let model = spawnConfig.modelStripProviderPrefix ? stripModelNamespace(options.model) : options.model;
|
|
9428
|
-
if (spawnConfig.modelTransform) model = spawnConfig.modelTransform(model);
|
|
9429
|
-
args.push(spawnConfig.modelFlag, model);
|
|
9430
|
-
}
|
|
9431
|
-
if (defaultArgsPosition === "afterPrompt") {
|
|
9432
|
-
args.push(...spawnConfig.defaultArgs);
|
|
9433
|
-
}
|
|
9434
|
-
if (mcpArgsPosition === "afterCommand") {
|
|
9435
|
-
args.push(...mcpArgs);
|
|
9436
|
-
}
|
|
9437
|
-
const modeResolved = resolveModeConfig(spawnConfig.modes[options.mode ?? "yolo"]);
|
|
9438
|
-
args.push(...modeResolved.args);
|
|
9439
|
-
if (useStdin) {
|
|
9440
|
-
args.push(...spawnConfig.stdinMode.extraArgs);
|
|
9441
|
-
}
|
|
9442
|
-
if (options.args && options.args.length > 0) {
|
|
9443
|
-
args.push(...options.args);
|
|
9444
|
-
}
|
|
9445
|
-
const envOverrides = { ...mcpEnvVars, ...modeResolved.env };
|
|
9446
|
-
const child = spawnChildProcess3(binaryName, args, {
|
|
9447
|
-
cwd: options.cwd,
|
|
9448
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
9449
|
-
env: Object.keys(envOverrides).length > 0 ? { ...process.env, ...envOverrides } : void 0
|
|
9450
|
-
});
|
|
9451
|
-
let aborted = false;
|
|
9452
|
-
let timedOut = false;
|
|
9453
|
-
const onAbort = () => {
|
|
9454
|
-
aborted = true;
|
|
9455
|
-
child.kill("SIGTERM");
|
|
9456
|
-
};
|
|
9457
|
-
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
9458
|
-
let activityTimer;
|
|
9459
|
-
const resetActivityTimer = options.activityTimeoutMs ? () => {
|
|
9460
|
-
if (activityTimer) clearTimeout(activityTimer);
|
|
9461
|
-
activityTimer = setTimeout(() => {
|
|
9462
|
-
timedOut = true;
|
|
9463
|
-
child.kill("SIGTERM");
|
|
9464
|
-
}, options.activityTimeoutMs);
|
|
9465
|
-
} : void 0;
|
|
9466
|
-
resetActivityTimer?.();
|
|
9467
|
-
const result = { stdout: "", stderr: "", exitCode: 1 };
|
|
9468
|
-
child.stderr.setEncoding("utf8");
|
|
9469
|
-
child.stderr.on("data", (chunk) => {
|
|
9470
|
-
result.stderr += chunk;
|
|
9471
|
-
resetActivityTimer?.();
|
|
9472
|
-
});
|
|
9473
|
-
if (useStdin) {
|
|
9474
|
-
child.stdin.write(options.prompt);
|
|
9475
|
-
}
|
|
9476
|
-
child.stdin.end();
|
|
9477
|
-
const adapter = getAdapter(spawnConfig.adapter);
|
|
9478
|
-
const events = (async function* () {
|
|
9479
|
-
for await (const output of adapter(readLines(child.stdout))) {
|
|
9480
|
-
if (!isAcpEvent(output)) continue;
|
|
9481
|
-
resetActivityTimer?.();
|
|
9482
|
-
yield output;
|
|
9483
|
-
}
|
|
9484
|
-
})();
|
|
9485
|
-
const done = new Promise((resolve2, reject) => {
|
|
9486
|
-
child.on("error", (error2) => {
|
|
9487
|
-
options.signal?.removeEventListener("abort", onAbort);
|
|
9488
|
-
if (activityTimer) clearTimeout(activityTimer);
|
|
9489
|
-
if (aborted) {
|
|
9490
|
-
reject(createAbortError2());
|
|
9491
|
-
return;
|
|
9492
|
-
}
|
|
9493
|
-
reject(error2);
|
|
9494
|
-
});
|
|
9495
|
-
child.on("close", (code) => {
|
|
9496
|
-
options.signal?.removeEventListener("abort", onAbort);
|
|
9497
|
-
if (activityTimer) clearTimeout(activityTimer);
|
|
9498
|
-
if (aborted) {
|
|
9499
|
-
reject(createAbortError2());
|
|
9500
|
-
return;
|
|
9501
|
-
}
|
|
9502
|
-
if (timedOut) {
|
|
9503
|
-
reject(createActivityTimeoutError2(options.activityTimeoutMs));
|
|
9504
|
-
return;
|
|
9505
|
-
}
|
|
9506
|
-
result.exitCode = code ?? 1;
|
|
9507
|
-
resolve2(result);
|
|
9508
|
-
});
|
|
9509
|
-
});
|
|
9510
|
-
return { events, done };
|
|
9511
|
-
}
|
|
9512
|
-
var init_spawn2 = __esm({
|
|
9513
|
-
"packages/agent-spawn/src/acp/spawn.ts"() {
|
|
9514
|
-
"use strict";
|
|
9515
|
-
init_adapters();
|
|
9516
|
-
init_line_reader();
|
|
9517
|
-
init_resolve_config();
|
|
9518
|
-
init_mcp_args();
|
|
9519
|
-
init_model_utils();
|
|
9520
|
-
init_types2();
|
|
9521
|
-
}
|
|
9522
|
-
});
|
|
9523
|
-
|
|
9524
|
-
// packages/poe-acp-client/src/types.ts
|
|
9525
|
-
function isObjectRecord(value) {
|
|
9526
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9527
|
-
}
|
|
9528
|
-
function isAcpErrorCode(value) {
|
|
9529
|
-
return typeof value === "number" && Number.isInteger(value) && value >= -2147483648 && value <= 2147483647;
|
|
9530
|
-
}
|
|
9531
|
-
function isAcpError(value) {
|
|
9532
|
-
if (value instanceof AcpError) {
|
|
9533
|
-
return true;
|
|
9534
|
-
}
|
|
9535
|
-
if (!isObjectRecord(value)) {
|
|
9536
|
-
return false;
|
|
9537
|
-
}
|
|
9538
|
-
if (!isAcpErrorCode(value.code) || typeof value.message !== "string") {
|
|
9539
|
-
return false;
|
|
9540
|
-
}
|
|
9541
|
-
return value.data === void 0 || Object.prototype.hasOwnProperty.call(value, "data");
|
|
9542
|
-
}
|
|
9543
|
-
var ACP_ERROR_CODE_PARSE, ACP_ERROR_CODE_INVALID_REQUEST, ACP_ERROR_CODE_METHOD_NOT_FOUND, ACP_ERROR_CODE_INVALID_PARAMS, ACP_ERROR_CODE_INTERNAL, ACP_ERROR_CODE_RESOURCE_NOT_FOUND, AcpError;
|
|
9544
|
-
var init_types3 = __esm({
|
|
9545
|
-
"packages/poe-acp-client/src/types.ts"() {
|
|
9546
|
-
"use strict";
|
|
9547
|
-
ACP_ERROR_CODE_PARSE = -32700;
|
|
9548
|
-
ACP_ERROR_CODE_INVALID_REQUEST = -32600;
|
|
9549
|
-
ACP_ERROR_CODE_METHOD_NOT_FOUND = -32601;
|
|
9550
|
-
ACP_ERROR_CODE_INVALID_PARAMS = -32602;
|
|
9551
|
-
ACP_ERROR_CODE_INTERNAL = -32603;
|
|
9552
|
-
ACP_ERROR_CODE_RESOURCE_NOT_FOUND = -32002;
|
|
9553
|
-
AcpError = class extends Error {
|
|
9554
|
-
code;
|
|
9555
|
-
data;
|
|
9556
|
-
constructor(code, message2, data) {
|
|
9557
|
-
super(message2);
|
|
9558
|
-
this.name = "AcpError";
|
|
9559
|
-
this.code = code;
|
|
9560
|
-
if (data !== void 0) {
|
|
9561
|
-
this.data = data;
|
|
9562
|
-
}
|
|
9563
|
-
}
|
|
9564
|
-
};
|
|
9565
|
-
}
|
|
9566
|
-
});
|
|
9567
|
-
|
|
9568
|
-
// packages/poe-acp-client/src/jsonrpc-message-layer.ts
|
|
9569
|
-
function isObjectRecord2(value) {
|
|
9570
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9571
|
-
}
|
|
9572
|
-
function hasOwn2(value, property) {
|
|
9573
|
-
return Object.prototype.hasOwnProperty.call(value, property);
|
|
9574
|
-
}
|
|
9575
|
-
function isRequestId(value) {
|
|
9576
|
-
return value === null || typeof value === "string" || typeof value === "number";
|
|
9577
|
-
}
|
|
9578
|
-
function toRequestId(value) {
|
|
9579
|
-
return isRequestId(value) ? value : null;
|
|
9580
|
-
}
|
|
9581
|
-
function parseError() {
|
|
9582
|
-
return new AcpError(ACP_ERROR_CODE_PARSE, "Parse error");
|
|
9583
|
-
}
|
|
9584
|
-
function invalidRequest() {
|
|
9585
|
-
return new AcpError(ACP_ERROR_CODE_INVALID_REQUEST, "Invalid Request");
|
|
9586
|
-
}
|
|
9587
|
-
function methodNotFound(method) {
|
|
9588
|
-
return new AcpError(
|
|
9589
|
-
ACP_ERROR_CODE_METHOD_NOT_FOUND,
|
|
9590
|
-
`Method not found: "${method}"`
|
|
9591
|
-
);
|
|
9592
|
-
}
|
|
9593
|
-
function internalError(message2) {
|
|
9594
|
-
return new AcpError(ACP_ERROR_CODE_INTERNAL, message2);
|
|
9595
|
-
}
|
|
9596
|
-
function isJsonRpcErrorObject(value) {
|
|
9597
|
-
if (!isObjectRecord2(value)) {
|
|
9598
|
-
return false;
|
|
9599
|
-
}
|
|
9600
|
-
if (!isAcpErrorCode(value.code) || typeof value.message !== "string") {
|
|
9601
|
-
return false;
|
|
9602
|
-
}
|
|
9603
|
-
return value.data === void 0 || hasOwn2(value, "data");
|
|
9604
|
-
}
|
|
9605
|
-
function toResponseError(error2) {
|
|
9606
|
-
return new AcpError(error2.code, error2.message, error2.data);
|
|
9607
|
-
}
|
|
9608
|
-
function toDispatchError(error2) {
|
|
9609
|
-
if (error2 instanceof AcpError) {
|
|
9610
|
-
return error2;
|
|
9611
|
-
}
|
|
9612
|
-
if (isAcpError(error2)) {
|
|
9613
|
-
return new AcpError(error2.code, error2.message, error2.data);
|
|
9614
|
-
}
|
|
9615
|
-
if (error2 instanceof Error && error2.message.length > 0) {
|
|
9616
|
-
return internalError(error2.message);
|
|
9617
|
-
}
|
|
9618
|
-
return internalError("Internal error");
|
|
9619
|
-
}
|
|
9620
|
-
function chunkToString2(chunk) {
|
|
9621
|
-
if (typeof chunk === "string") {
|
|
9622
|
-
return chunk;
|
|
9623
|
-
}
|
|
9624
|
-
if (chunk instanceof Uint8Array) {
|
|
9625
|
-
return Buffer.from(chunk).toString("utf8");
|
|
9626
|
-
}
|
|
9627
|
-
return String(chunk);
|
|
9628
|
-
}
|
|
9629
|
-
function normalizeLine(line) {
|
|
9630
|
-
return line.endsWith("\r") ? line.slice(0, -1) : line;
|
|
9631
|
-
}
|
|
9632
|
-
async function* readLines2(stream) {
|
|
9633
|
-
let buffer = "";
|
|
9634
|
-
for await (const chunk of stream) {
|
|
9635
|
-
buffer += chunkToString2(chunk);
|
|
9636
|
-
while (true) {
|
|
9637
|
-
const newlineIndex = buffer.indexOf("\n");
|
|
9638
|
-
if (newlineIndex === -1) {
|
|
9639
|
-
break;
|
|
9640
|
-
}
|
|
9641
|
-
const line = buffer.slice(0, newlineIndex);
|
|
9642
|
-
buffer = buffer.slice(newlineIndex + 1);
|
|
9643
|
-
yield normalizeLine(line);
|
|
9644
|
-
}
|
|
9645
|
-
}
|
|
9646
|
-
if (buffer.length > 0) {
|
|
9647
|
-
yield normalizeLine(buffer);
|
|
9648
|
-
}
|
|
9649
|
-
}
|
|
9650
|
-
function createResponseMessage(id, result) {
|
|
9651
|
-
return {
|
|
9652
|
-
jsonrpc: "2.0",
|
|
9653
|
-
id,
|
|
9654
|
-
result: result === void 0 ? null : result
|
|
9655
|
-
};
|
|
9656
|
-
}
|
|
9657
|
-
function createJsonRpcErrorResponse(id, error2) {
|
|
9658
|
-
const response = {
|
|
9659
|
-
jsonrpc: "2.0",
|
|
9660
|
-
id,
|
|
9661
|
-
error: {
|
|
9662
|
-
code: error2.code,
|
|
9663
|
-
message: error2.message
|
|
9664
|
-
}
|
|
9665
|
-
};
|
|
9666
|
-
if (error2.data !== void 0) {
|
|
9667
|
-
response.error.data = error2.data;
|
|
9668
|
-
}
|
|
9669
|
-
return response;
|
|
9670
|
-
}
|
|
9671
|
-
function serializeJsonRpcMessage(message2) {
|
|
9672
|
-
return `${JSON.stringify(message2)}
|
|
9673
|
-
`;
|
|
9674
|
-
}
|
|
9675
|
-
function parseJsonRpcMessage(line) {
|
|
9676
|
-
let parsed;
|
|
9677
|
-
try {
|
|
9678
|
-
parsed = JSON.parse(line);
|
|
9679
|
-
} catch {
|
|
9680
|
-
return {
|
|
9681
|
-
type: "invalid",
|
|
9682
|
-
id: null,
|
|
9683
|
-
error: parseError()
|
|
9684
|
-
};
|
|
9685
|
-
}
|
|
9686
|
-
if (!isObjectRecord2(parsed)) {
|
|
9687
|
-
return {
|
|
9688
|
-
type: "invalid",
|
|
9689
|
-
id: null,
|
|
9690
|
-
error: invalidRequest()
|
|
9691
|
-
};
|
|
9692
|
-
}
|
|
9693
|
-
const id = toRequestId(parsed.id);
|
|
9694
|
-
if (parsed.jsonrpc !== "2.0") {
|
|
9695
|
-
return {
|
|
9696
|
-
type: "invalid",
|
|
9697
|
-
id,
|
|
9698
|
-
error: invalidRequest()
|
|
9699
|
-
};
|
|
9700
|
-
}
|
|
9701
|
-
const hasMethod = hasOwn2(parsed, "method");
|
|
9702
|
-
const hasId = hasOwn2(parsed, "id");
|
|
9703
|
-
if (hasMethod) {
|
|
9704
|
-
if (typeof parsed.method !== "string") {
|
|
9705
|
-
return {
|
|
9706
|
-
type: "invalid",
|
|
9707
|
-
id,
|
|
9708
|
-
error: invalidRequest()
|
|
9709
|
-
};
|
|
9710
|
-
}
|
|
9711
|
-
if (hasId) {
|
|
9712
|
-
if (!isRequestId(parsed.id)) {
|
|
9713
|
-
return {
|
|
9714
|
-
type: "invalid",
|
|
9715
|
-
id: null,
|
|
9716
|
-
error: invalidRequest()
|
|
9717
|
-
};
|
|
9718
|
-
}
|
|
9719
|
-
const request = {
|
|
9720
|
-
jsonrpc: "2.0",
|
|
9721
|
-
id: parsed.id,
|
|
9722
|
-
method: parsed.method
|
|
9723
|
-
};
|
|
9724
|
-
if (hasOwn2(parsed, "params")) {
|
|
9725
|
-
request.params = parsed.params;
|
|
9726
|
-
}
|
|
9727
|
-
return { type: "request", message: request };
|
|
9728
|
-
}
|
|
9729
|
-
const notification = {
|
|
9730
|
-
jsonrpc: "2.0",
|
|
9731
|
-
method: parsed.method
|
|
9732
|
-
};
|
|
9733
|
-
if (hasOwn2(parsed, "params")) {
|
|
9734
|
-
notification.params = parsed.params;
|
|
9190
|
+
const notification = {
|
|
9191
|
+
jsonrpc: "2.0",
|
|
9192
|
+
method: parsed.method
|
|
9193
|
+
};
|
|
9194
|
+
if (hasOwn2(parsed, "params")) {
|
|
9195
|
+
notification.params = parsed.params;
|
|
9735
9196
|
}
|
|
9736
9197
|
return {
|
|
9737
9198
|
type: "notification",
|
|
@@ -9860,7 +9321,7 @@ var init_jsonrpc_message_layer = __esm({
|
|
|
9860
9321
|
}
|
|
9861
9322
|
async consumeInput() {
|
|
9862
9323
|
try {
|
|
9863
|
-
for await (const line of
|
|
9324
|
+
for await (const line of readLines(this.input)) {
|
|
9864
9325
|
if (this.disposed || line.length === 0) {
|
|
9865
9326
|
continue;
|
|
9866
9327
|
}
|
|
@@ -9949,7 +9410,7 @@ var init_jsonrpc_message_layer = __esm({
|
|
|
9949
9410
|
|
|
9950
9411
|
// packages/poe-acp-client/src/acp-transport.ts
|
|
9951
9412
|
import {
|
|
9952
|
-
spawn as
|
|
9413
|
+
spawn as spawnChildProcess3
|
|
9953
9414
|
} from "node:child_process";
|
|
9954
9415
|
function assertExtensionMethod(method) {
|
|
9955
9416
|
if (!method.startsWith("_")) {
|
|
@@ -9977,7 +9438,7 @@ var init_acp_transport = __esm({
|
|
|
9977
9438
|
cwd,
|
|
9978
9439
|
env,
|
|
9979
9440
|
firstRequestId,
|
|
9980
|
-
spawn: spawn9 =
|
|
9441
|
+
spawn: spawn9 = spawnChildProcess3
|
|
9981
9442
|
} = options;
|
|
9982
9443
|
this.command = command;
|
|
9983
9444
|
this.closed = new Promise((resolve2) => {
|
|
@@ -10099,8 +9560,8 @@ function resourceNotFound(resource) {
|
|
|
10099
9560
|
`Resource not found: ${resource}`
|
|
10100
9561
|
);
|
|
10101
9562
|
}
|
|
10102
|
-
function assertAbsolutePath(
|
|
10103
|
-
if (!isAbsolute(
|
|
9563
|
+
function assertAbsolutePath(path55) {
|
|
9564
|
+
if (!isAbsolute(path55)) {
|
|
10104
9565
|
throw invalidParams('"path" must be an absolute path');
|
|
10105
9566
|
}
|
|
10106
9567
|
}
|
|
@@ -10483,492 +9944,1076 @@ var init_acp_client = __esm({
|
|
|
10483
9944
|
);
|
|
10484
9945
|
this.hasRegisteredFsWriteHandler = true;
|
|
10485
9946
|
}
|
|
10486
|
-
if (!this.hasRegisteredTerminalHandlers && capabilities?.terminal === true && this.terminalHandler) {
|
|
10487
|
-
const terminalHandler = this.terminalHandler;
|
|
10488
|
-
this.transport.onRequest(
|
|
10489
|
-
"terminal/create",
|
|
10490
|
-
async (params) => {
|
|
10491
|
-
const terminalId = await terminalHandler.create({
|
|
10492
|
-
sessionId: params.sessionId,
|
|
10493
|
-
command: params.command,
|
|
10494
|
-
args: params.args,
|
|
10495
|
-
cwd: params.cwd,
|
|
10496
|
-
env: params.env,
|
|
10497
|
-
outputByteLimit: params.outputByteLimit
|
|
10498
|
-
});
|
|
10499
|
-
this.trackTerminal(params.sessionId, terminalId);
|
|
10500
|
-
return { terminalId };
|
|
10501
|
-
}
|
|
10502
|
-
);
|
|
10503
|
-
this.transport.onRequest(
|
|
10504
|
-
"terminal/output",
|
|
10505
|
-
async (params) => {
|
|
10506
|
-
this.assertKnownTerminal(params.sessionId, params.terminalId);
|
|
10507
|
-
return terminalHandler.output({
|
|
10508
|
-
sessionId: params.sessionId,
|
|
10509
|
-
terminalId: params.terminalId
|
|
10510
|
-
});
|
|
10511
|
-
}
|
|
10512
|
-
);
|
|
10513
|
-
this.transport.onRequest(
|
|
10514
|
-
"terminal/wait_for_exit",
|
|
10515
|
-
async (params) => {
|
|
10516
|
-
this.assertKnownTerminal(params.sessionId, params.terminalId);
|
|
10517
|
-
return terminalHandler.waitForExit({
|
|
10518
|
-
sessionId: params.sessionId,
|
|
10519
|
-
terminalId: params.terminalId
|
|
10520
|
-
});
|
|
10521
|
-
}
|
|
10522
|
-
);
|
|
10523
|
-
this.transport.onRequest(
|
|
10524
|
-
"terminal/kill",
|
|
10525
|
-
async (params) => {
|
|
10526
|
-
this.assertKnownTerminal(params.sessionId, params.terminalId);
|
|
10527
|
-
await terminalHandler.kill({
|
|
10528
|
-
sessionId: params.sessionId,
|
|
10529
|
-
terminalId: params.terminalId
|
|
10530
|
-
});
|
|
10531
|
-
return {};
|
|
10532
|
-
}
|
|
10533
|
-
);
|
|
10534
|
-
this.transport.onRequest(
|
|
10535
|
-
"terminal/release",
|
|
10536
|
-
async (params) => {
|
|
10537
|
-
this.assertKnownTerminal(params.sessionId, params.terminalId);
|
|
10538
|
-
await terminalHandler.release({
|
|
10539
|
-
sessionId: params.sessionId,
|
|
10540
|
-
terminalId: params.terminalId
|
|
10541
|
-
});
|
|
10542
|
-
this.untrackTerminal(params.sessionId, params.terminalId);
|
|
10543
|
-
return {};
|
|
10544
|
-
}
|
|
10545
|
-
);
|
|
10546
|
-
this.hasRegisteredTerminalHandlers = true;
|
|
9947
|
+
if (!this.hasRegisteredTerminalHandlers && capabilities?.terminal === true && this.terminalHandler) {
|
|
9948
|
+
const terminalHandler = this.terminalHandler;
|
|
9949
|
+
this.transport.onRequest(
|
|
9950
|
+
"terminal/create",
|
|
9951
|
+
async (params) => {
|
|
9952
|
+
const terminalId = await terminalHandler.create({
|
|
9953
|
+
sessionId: params.sessionId,
|
|
9954
|
+
command: params.command,
|
|
9955
|
+
args: params.args,
|
|
9956
|
+
cwd: params.cwd,
|
|
9957
|
+
env: params.env,
|
|
9958
|
+
outputByteLimit: params.outputByteLimit
|
|
9959
|
+
});
|
|
9960
|
+
this.trackTerminal(params.sessionId, terminalId);
|
|
9961
|
+
return { terminalId };
|
|
9962
|
+
}
|
|
9963
|
+
);
|
|
9964
|
+
this.transport.onRequest(
|
|
9965
|
+
"terminal/output",
|
|
9966
|
+
async (params) => {
|
|
9967
|
+
this.assertKnownTerminal(params.sessionId, params.terminalId);
|
|
9968
|
+
return terminalHandler.output({
|
|
9969
|
+
sessionId: params.sessionId,
|
|
9970
|
+
terminalId: params.terminalId
|
|
9971
|
+
});
|
|
9972
|
+
}
|
|
9973
|
+
);
|
|
9974
|
+
this.transport.onRequest(
|
|
9975
|
+
"terminal/wait_for_exit",
|
|
9976
|
+
async (params) => {
|
|
9977
|
+
this.assertKnownTerminal(params.sessionId, params.terminalId);
|
|
9978
|
+
return terminalHandler.waitForExit({
|
|
9979
|
+
sessionId: params.sessionId,
|
|
9980
|
+
terminalId: params.terminalId
|
|
9981
|
+
});
|
|
9982
|
+
}
|
|
9983
|
+
);
|
|
9984
|
+
this.transport.onRequest(
|
|
9985
|
+
"terminal/kill",
|
|
9986
|
+
async (params) => {
|
|
9987
|
+
this.assertKnownTerminal(params.sessionId, params.terminalId);
|
|
9988
|
+
await terminalHandler.kill({
|
|
9989
|
+
sessionId: params.sessionId,
|
|
9990
|
+
terminalId: params.terminalId
|
|
9991
|
+
});
|
|
9992
|
+
return {};
|
|
9993
|
+
}
|
|
9994
|
+
);
|
|
9995
|
+
this.transport.onRequest(
|
|
9996
|
+
"terminal/release",
|
|
9997
|
+
async (params) => {
|
|
9998
|
+
this.assertKnownTerminal(params.sessionId, params.terminalId);
|
|
9999
|
+
await terminalHandler.release({
|
|
10000
|
+
sessionId: params.sessionId,
|
|
10001
|
+
terminalId: params.terminalId
|
|
10002
|
+
});
|
|
10003
|
+
this.untrackTerminal(params.sessionId, params.terminalId);
|
|
10004
|
+
return {};
|
|
10005
|
+
}
|
|
10006
|
+
);
|
|
10007
|
+
this.hasRegisteredTerminalHandlers = true;
|
|
10008
|
+
}
|
|
10009
|
+
}
|
|
10010
|
+
assertMcpServerCapabilitySupport(mcpServers) {
|
|
10011
|
+
const mcpCapabilities = this.negotiatedAgentCapabilities?.mcpCapabilities;
|
|
10012
|
+
for (const mcpServer of mcpServers) {
|
|
10013
|
+
if (!("type" in mcpServer)) {
|
|
10014
|
+
continue;
|
|
10015
|
+
}
|
|
10016
|
+
if (mcpServer.type === "http" && mcpCapabilities?.http !== true) {
|
|
10017
|
+
throw new Error('Agent does not support MCP server type "http".');
|
|
10018
|
+
}
|
|
10019
|
+
if (mcpServer.type === "sse" && mcpCapabilities?.sse !== true) {
|
|
10020
|
+
throw new Error('Agent does not support MCP server type "sse".');
|
|
10021
|
+
}
|
|
10022
|
+
}
|
|
10023
|
+
}
|
|
10024
|
+
handleSessionUpdateNotification(notification) {
|
|
10025
|
+
const activePrompt = this.activePromptUpdates.get(notification.sessionId);
|
|
10026
|
+
if (!activePrompt) {
|
|
10027
|
+
return;
|
|
10028
|
+
}
|
|
10029
|
+
activePrompt.push({
|
|
10030
|
+
jsonrpc: "2.0",
|
|
10031
|
+
method: "session/update",
|
|
10032
|
+
params: notification
|
|
10033
|
+
});
|
|
10034
|
+
}
|
|
10035
|
+
trackTerminal(sessionId, terminalId) {
|
|
10036
|
+
const sessionTerminals = this.trackedTerminalIds.get(sessionId);
|
|
10037
|
+
if (sessionTerminals) {
|
|
10038
|
+
sessionTerminals.add(terminalId);
|
|
10039
|
+
return;
|
|
10040
|
+
}
|
|
10041
|
+
this.trackedTerminalIds.set(sessionId, /* @__PURE__ */ new Set([terminalId]));
|
|
10042
|
+
}
|
|
10043
|
+
assertKnownTerminal(sessionId, terminalId) {
|
|
10044
|
+
const sessionTerminals = this.trackedTerminalIds.get(sessionId);
|
|
10045
|
+
if (sessionTerminals?.has(terminalId) === true) {
|
|
10046
|
+
return;
|
|
10047
|
+
}
|
|
10048
|
+
throw resourceNotFound(`terminal "${terminalId}"`);
|
|
10049
|
+
}
|
|
10050
|
+
untrackTerminal(sessionId, terminalId) {
|
|
10051
|
+
const sessionTerminals = this.trackedTerminalIds.get(sessionId);
|
|
10052
|
+
if (!sessionTerminals) {
|
|
10053
|
+
return;
|
|
10054
|
+
}
|
|
10055
|
+
sessionTerminals.delete(terminalId);
|
|
10056
|
+
if (sessionTerminals.size === 0) {
|
|
10057
|
+
this.trackedTerminalIds.delete(sessionId);
|
|
10058
|
+
}
|
|
10059
|
+
}
|
|
10060
|
+
assertPromptContentCapabilitySupport(content) {
|
|
10061
|
+
const promptCapabilities = this.negotiatedAgentCapabilities?.promptCapabilities;
|
|
10062
|
+
for (const block of content) {
|
|
10063
|
+
if (block.type === "image" && promptCapabilities?.image !== true) {
|
|
10064
|
+
throw new Error('Agent does not support prompt content type "image".');
|
|
10065
|
+
}
|
|
10066
|
+
if (block.type === "audio" && promptCapabilities?.audio !== true) {
|
|
10067
|
+
throw new Error('Agent does not support prompt content type "audio".');
|
|
10068
|
+
}
|
|
10069
|
+
if (block.type === "resource" && promptCapabilities?.embeddedContext !== true) {
|
|
10070
|
+
throw new Error('Agent does not support prompt content type "resource".');
|
|
10071
|
+
}
|
|
10072
|
+
}
|
|
10073
|
+
}
|
|
10074
|
+
};
|
|
10075
|
+
}
|
|
10076
|
+
});
|
|
10077
|
+
|
|
10078
|
+
// packages/poe-acp-client/src/jsonrpc.ts
|
|
10079
|
+
var init_jsonrpc = __esm({
|
|
10080
|
+
"packages/poe-acp-client/src/jsonrpc.ts"() {
|
|
10081
|
+
"use strict";
|
|
10082
|
+
}
|
|
10083
|
+
});
|
|
10084
|
+
|
|
10085
|
+
// packages/poe-acp-client/src/stream-helpers.ts
|
|
10086
|
+
async function extractUsageFromSessionUpdateStream(stream) {
|
|
10087
|
+
const updates = [];
|
|
10088
|
+
for await (const entry of stream) {
|
|
10089
|
+
const update = toSessionUpdate(entry);
|
|
10090
|
+
if (update.sessionUpdate === "usage_update") {
|
|
10091
|
+
updates.push(update);
|
|
10092
|
+
}
|
|
10093
|
+
}
|
|
10094
|
+
return updates;
|
|
10095
|
+
}
|
|
10096
|
+
async function extractToolCallSummariesFromSessionUpdateStream(stream) {
|
|
10097
|
+
const summaries = /* @__PURE__ */ new Map();
|
|
10098
|
+
for await (const entry of stream) {
|
|
10099
|
+
const update = toSessionUpdate(entry);
|
|
10100
|
+
if (update.sessionUpdate === "tool_call") {
|
|
10101
|
+
const summary = {
|
|
10102
|
+
toolCallId: update.toolCallId,
|
|
10103
|
+
title: update.title
|
|
10104
|
+
};
|
|
10105
|
+
if (update.kind !== void 0) {
|
|
10106
|
+
summary.kind = update.kind;
|
|
10107
|
+
}
|
|
10108
|
+
if (update.status !== void 0) {
|
|
10109
|
+
summary.status = update.status;
|
|
10110
|
+
}
|
|
10111
|
+
if (update.rawInput !== void 0) {
|
|
10112
|
+
summary.rawInput = update.rawInput;
|
|
10113
|
+
}
|
|
10114
|
+
if (update.rawOutput !== void 0) {
|
|
10115
|
+
summary.rawOutput = update.rawOutput;
|
|
10116
|
+
}
|
|
10117
|
+
summaries.set(update.toolCallId, summary);
|
|
10118
|
+
continue;
|
|
10119
|
+
}
|
|
10120
|
+
if (update.sessionUpdate === "tool_call_update") {
|
|
10121
|
+
const existing = summaries.get(update.toolCallId);
|
|
10122
|
+
const summary = existing ?? {
|
|
10123
|
+
toolCallId: update.toolCallId,
|
|
10124
|
+
title: toTitle(update.title, update.toolCallId)
|
|
10125
|
+
};
|
|
10126
|
+
if (update.title !== null && update.title !== void 0 && update.title.length > 0) {
|
|
10127
|
+
summary.title = update.title;
|
|
10128
|
+
}
|
|
10129
|
+
if (update.kind !== null && update.kind !== void 0) {
|
|
10130
|
+
summary.kind = update.kind;
|
|
10131
|
+
}
|
|
10132
|
+
if (update.status !== null && update.status !== void 0) {
|
|
10133
|
+
summary.status = update.status;
|
|
10134
|
+
}
|
|
10135
|
+
if (update.rawInput !== void 0) {
|
|
10136
|
+
summary.rawInput = update.rawInput;
|
|
10137
|
+
}
|
|
10138
|
+
if (update.rawOutput !== void 0) {
|
|
10139
|
+
summary.rawOutput = update.rawOutput;
|
|
10140
|
+
}
|
|
10141
|
+
summaries.set(update.toolCallId, summary);
|
|
10142
|
+
}
|
|
10143
|
+
}
|
|
10144
|
+
return Array.from(summaries.values());
|
|
10145
|
+
}
|
|
10146
|
+
function toSessionUpdate(entry) {
|
|
10147
|
+
if (isSessionUpdateNotification(entry)) {
|
|
10148
|
+
return entry.params.update;
|
|
10149
|
+
}
|
|
10150
|
+
return entry;
|
|
10151
|
+
}
|
|
10152
|
+
function isSessionUpdateNotification(entry) {
|
|
10153
|
+
return typeof entry.jsonrpc === "string" && entry.method === "session/update";
|
|
10154
|
+
}
|
|
10155
|
+
function toTitle(value, fallback) {
|
|
10156
|
+
if (typeof value === "string" && value.length > 0) {
|
|
10157
|
+
return value;
|
|
10158
|
+
}
|
|
10159
|
+
return fallback;
|
|
10160
|
+
}
|
|
10161
|
+
var init_stream_helpers = __esm({
|
|
10162
|
+
"packages/poe-acp-client/src/stream-helpers.ts"() {
|
|
10163
|
+
"use strict";
|
|
10164
|
+
}
|
|
10165
|
+
});
|
|
10166
|
+
|
|
10167
|
+
// packages/poe-acp-client/src/run-report.ts
|
|
10168
|
+
import * as fsPromises from "node:fs/promises";
|
|
10169
|
+
import { homedir as homedir2 } from "node:os";
|
|
10170
|
+
import { join } from "node:path";
|
|
10171
|
+
async function generateRunReportFromSessionUpdateStream(stream, options = {}) {
|
|
10172
|
+
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
10173
|
+
const bufferedEntries = [];
|
|
10174
|
+
let runIdFromStream;
|
|
10175
|
+
for await (const entry of stream) {
|
|
10176
|
+
bufferedEntries.push(entry);
|
|
10177
|
+
if (runIdFromStream) {
|
|
10178
|
+
continue;
|
|
10179
|
+
}
|
|
10180
|
+
if (isSessionUpdateNotification2(entry)) {
|
|
10181
|
+
const sessionId = toNonEmptyString(entry.params.sessionId);
|
|
10182
|
+
if (sessionId) {
|
|
10183
|
+
runIdFromStream = sessionId;
|
|
10184
|
+
}
|
|
10185
|
+
}
|
|
10186
|
+
}
|
|
10187
|
+
const runId = toNonEmptyString(options.runId) ?? runIdFromStream;
|
|
10188
|
+
if (!runId) {
|
|
10189
|
+
throw new Error("Run id is required via options.runId or session/update stream items");
|
|
10190
|
+
}
|
|
10191
|
+
const startTime = normalizeTime(options.startTime, now);
|
|
10192
|
+
const endTime = normalizeTime(options.endTime, now);
|
|
10193
|
+
const toolCalls = await extractToolCallSummariesFromSessionUpdateStream(bufferedEntries);
|
|
10194
|
+
const usageUpdates = await extractUsageFromSessionUpdateStream(bufferedEntries);
|
|
10195
|
+
const usage = summarizeUsage(usageUpdates);
|
|
10196
|
+
const errors = collectErrors(toolCalls, options.errors);
|
|
10197
|
+
const exitStatus = options.exitStatus ?? (errors.length > 0 ? "failed" : "success");
|
|
10198
|
+
return {
|
|
10199
|
+
runId,
|
|
10200
|
+
startTime,
|
|
10201
|
+
endTime,
|
|
10202
|
+
exitStatus,
|
|
10203
|
+
toolCalls,
|
|
10204
|
+
usage,
|
|
10205
|
+
errors
|
|
10206
|
+
};
|
|
10207
|
+
}
|
|
10208
|
+
function isSessionUpdateNotification2(entry) {
|
|
10209
|
+
return typeof entry.jsonrpc === "string" && entry.method === "session/update";
|
|
10210
|
+
}
|
|
10211
|
+
function normalizeTime(value, now) {
|
|
10212
|
+
if (value instanceof Date) {
|
|
10213
|
+
return value.toISOString();
|
|
10214
|
+
}
|
|
10215
|
+
if (typeof value === "string" && value.length > 0) {
|
|
10216
|
+
const parsed = new Date(value);
|
|
10217
|
+
if (!Number.isNaN(parsed.getTime())) {
|
|
10218
|
+
return parsed.toISOString();
|
|
10219
|
+
}
|
|
10220
|
+
}
|
|
10221
|
+
return now().toISOString();
|
|
10222
|
+
}
|
|
10223
|
+
function summarizeUsage(updates) {
|
|
10224
|
+
let used = 0;
|
|
10225
|
+
let size = 0;
|
|
10226
|
+
let cost;
|
|
10227
|
+
for (const update of updates) {
|
|
10228
|
+
used += update.used;
|
|
10229
|
+
size += update.size;
|
|
10230
|
+
if (update.cost !== void 0) {
|
|
10231
|
+
cost = update.cost;
|
|
10232
|
+
}
|
|
10233
|
+
}
|
|
10234
|
+
const usage = {
|
|
10235
|
+
used,
|
|
10236
|
+
size,
|
|
10237
|
+
updates: updates.length
|
|
10238
|
+
};
|
|
10239
|
+
if (cost !== void 0) {
|
|
10240
|
+
usage.cost = cost;
|
|
10241
|
+
}
|
|
10242
|
+
return usage;
|
|
10243
|
+
}
|
|
10244
|
+
function collectErrors(toolCalls, additionalErrors) {
|
|
10245
|
+
const errors = [];
|
|
10246
|
+
for (const toolCall of toolCalls) {
|
|
10247
|
+
if (toolCall.status !== "failed") {
|
|
10248
|
+
continue;
|
|
10249
|
+
}
|
|
10250
|
+
errors.push({
|
|
10251
|
+
toolCallId: toolCall.toolCallId,
|
|
10252
|
+
message: toErrorMessage(toolCall)
|
|
10253
|
+
});
|
|
10254
|
+
}
|
|
10255
|
+
if (additionalErrors) {
|
|
10256
|
+
for (const message2 of additionalErrors) {
|
|
10257
|
+
const text4 = toNonEmptyString(message2);
|
|
10258
|
+
if (text4) {
|
|
10259
|
+
errors.push({ message: text4 });
|
|
10260
|
+
}
|
|
10261
|
+
}
|
|
10262
|
+
}
|
|
10263
|
+
return errors;
|
|
10264
|
+
}
|
|
10265
|
+
function toErrorMessage(toolCall) {
|
|
10266
|
+
if (typeof toolCall.rawOutput === "string" && toolCall.rawOutput.length > 0) {
|
|
10267
|
+
return toolCall.rawOutput;
|
|
10268
|
+
}
|
|
10269
|
+
if (toolCall.rawOutput instanceof Error && toolCall.rawOutput.message.length > 0) {
|
|
10270
|
+
return toolCall.rawOutput.message;
|
|
10271
|
+
}
|
|
10272
|
+
if (toolCall.rawOutput !== void 0 && toolCall.rawOutput !== null) {
|
|
10273
|
+
const encoded = trySerialize(toolCall.rawOutput);
|
|
10274
|
+
if (encoded) {
|
|
10275
|
+
return encoded;
|
|
10276
|
+
}
|
|
10277
|
+
}
|
|
10278
|
+
return `${toolCall.title} failed`;
|
|
10279
|
+
}
|
|
10280
|
+
function trySerialize(value) {
|
|
10281
|
+
try {
|
|
10282
|
+
const serialized = JSON.stringify(value);
|
|
10283
|
+
if (typeof serialized === "string" && serialized.length > 0) {
|
|
10284
|
+
return serialized;
|
|
10285
|
+
}
|
|
10286
|
+
} catch {
|
|
10287
|
+
return void 0;
|
|
10288
|
+
}
|
|
10289
|
+
return void 0;
|
|
10290
|
+
}
|
|
10291
|
+
function toNonEmptyString(value) {
|
|
10292
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
10293
|
+
return void 0;
|
|
10294
|
+
}
|
|
10295
|
+
return value;
|
|
10296
|
+
}
|
|
10297
|
+
var init_run_report = __esm({
|
|
10298
|
+
"packages/poe-acp-client/src/run-report.ts"() {
|
|
10299
|
+
"use strict";
|
|
10300
|
+
init_stream_helpers();
|
|
10301
|
+
}
|
|
10302
|
+
});
|
|
10303
|
+
|
|
10304
|
+
// packages/poe-acp-client/src/index.ts
|
|
10305
|
+
var init_src7 = __esm({
|
|
10306
|
+
"packages/poe-acp-client/src/index.ts"() {
|
|
10307
|
+
"use strict";
|
|
10308
|
+
init_acp_client();
|
|
10309
|
+
init_acp_transport();
|
|
10310
|
+
init_types3();
|
|
10311
|
+
init_jsonrpc_message_layer();
|
|
10312
|
+
init_jsonrpc();
|
|
10313
|
+
init_run_report();
|
|
10314
|
+
init_stream_helpers();
|
|
10315
|
+
}
|
|
10316
|
+
});
|
|
10317
|
+
|
|
10318
|
+
// packages/agent-spawn/src/acp/replay.ts
|
|
10319
|
+
import path9 from "node:path";
|
|
10320
|
+
import { homedir as homedir3 } from "node:os";
|
|
10321
|
+
import { open, readdir } from "node:fs/promises";
|
|
10322
|
+
import { createInterface as createInterface2 } from "node:readline";
|
|
10323
|
+
var init_replay = __esm({
|
|
10324
|
+
"packages/agent-spawn/src/acp/replay.ts"() {
|
|
10325
|
+
"use strict";
|
|
10326
|
+
init_src7();
|
|
10327
|
+
init_renderer2();
|
|
10328
|
+
}
|
|
10329
|
+
});
|
|
10330
|
+
|
|
10331
|
+
// packages/agent-spawn/src/adapters/utils.ts
|
|
10332
|
+
function truncate2(text4, maxLength) {
|
|
10333
|
+
if (text4.length <= maxLength) return text4;
|
|
10334
|
+
if (maxLength <= 3) return text4.slice(0, maxLength);
|
|
10335
|
+
return `${text4.slice(0, maxLength - 3)}...`;
|
|
10336
|
+
}
|
|
10337
|
+
function isNonEmptyString(value) {
|
|
10338
|
+
return typeof value === "string" && value.length > 0;
|
|
10339
|
+
}
|
|
10340
|
+
function extractThreadId(value) {
|
|
10341
|
+
if (!value || typeof value !== "object") return;
|
|
10342
|
+
const obj = value;
|
|
10343
|
+
const maybeThreadId = isNonEmptyString(obj.thread_id) && obj.thread_id || isNonEmptyString(obj.threadId) && obj.threadId || isNonEmptyString(obj.threadID) && obj.threadID || isNonEmptyString(obj.session_id) && obj.session_id || isNonEmptyString(obj.sessionId) && obj.sessionId || isNonEmptyString(obj.sessionID) && obj.sessionID;
|
|
10344
|
+
return maybeThreadId || void 0;
|
|
10345
|
+
}
|
|
10346
|
+
var init_utils2 = __esm({
|
|
10347
|
+
"packages/agent-spawn/src/adapters/utils.ts"() {
|
|
10348
|
+
"use strict";
|
|
10349
|
+
}
|
|
10350
|
+
});
|
|
10351
|
+
|
|
10352
|
+
// packages/agent-spawn/src/adapters/claude.ts
|
|
10353
|
+
function extractTitle(name, input) {
|
|
10354
|
+
const keys = TITLE_KEYS[name];
|
|
10355
|
+
if (keys && input && typeof input === "object") {
|
|
10356
|
+
const obj = input;
|
|
10357
|
+
for (const key of keys) {
|
|
10358
|
+
const value = obj[key];
|
|
10359
|
+
if (typeof value === "string" && value.length > 0) {
|
|
10360
|
+
return truncate2(value, 80);
|
|
10361
|
+
}
|
|
10362
|
+
}
|
|
10363
|
+
}
|
|
10364
|
+
return name;
|
|
10365
|
+
}
|
|
10366
|
+
async function* adaptClaude(lines) {
|
|
10367
|
+
const toolKindsById = /* @__PURE__ */ new Map();
|
|
10368
|
+
let emittedSessionStart = false;
|
|
10369
|
+
for await (const rawLine of lines) {
|
|
10370
|
+
const line = rawLine.trim();
|
|
10371
|
+
if (!line) continue;
|
|
10372
|
+
const firstChar = line[0];
|
|
10373
|
+
if (firstChar !== "{" && firstChar !== "[") {
|
|
10374
|
+
continue;
|
|
10375
|
+
}
|
|
10376
|
+
let event;
|
|
10377
|
+
try {
|
|
10378
|
+
event = JSON.parse(line);
|
|
10379
|
+
} catch (error2) {
|
|
10380
|
+
const stack = error2 instanceof Error ? error2.stack : void 0;
|
|
10381
|
+
yield {
|
|
10382
|
+
event: "error",
|
|
10383
|
+
message: `[adaptClaude] Malformed JSON line: ${truncate2(line, 200)}`,
|
|
10384
|
+
stack
|
|
10385
|
+
};
|
|
10386
|
+
continue;
|
|
10387
|
+
}
|
|
10388
|
+
const eventType = event.type;
|
|
10389
|
+
if (!isNonEmptyString(eventType)) continue;
|
|
10390
|
+
if (!emittedSessionStart) {
|
|
10391
|
+
const threadId = extractThreadId(event);
|
|
10392
|
+
emittedSessionStart = true;
|
|
10393
|
+
yield { event: "session_start", threadId };
|
|
10394
|
+
}
|
|
10395
|
+
if (eventType === "result") {
|
|
10396
|
+
const usage = event.usage ?? {};
|
|
10397
|
+
const inputTokens = typeof usage.input_tokens === "number" ? usage.input_tokens : typeof event.input_tokens === "number" ? event.input_tokens : typeof event.num_input_tokens === "number" ? event.num_input_tokens : 0;
|
|
10398
|
+
const outputTokens = typeof usage.output_tokens === "number" ? usage.output_tokens : typeof event.output_tokens === "number" ? event.output_tokens : typeof event.num_output_tokens === "number" ? event.num_output_tokens : 0;
|
|
10399
|
+
const costUsd = typeof usage.cost_usd === "number" ? usage.cost_usd : typeof event.cost_usd === "number" ? event.cost_usd : void 0;
|
|
10400
|
+
yield { event: "usage", inputTokens, outputTokens, costUsd };
|
|
10401
|
+
continue;
|
|
10402
|
+
}
|
|
10403
|
+
if (eventType !== "assistant" && eventType !== "user") continue;
|
|
10404
|
+
const message2 = event.message ?? null;
|
|
10405
|
+
if (!message2 || typeof message2 !== "object") continue;
|
|
10406
|
+
const content = message2.content ?? null;
|
|
10407
|
+
if (!Array.isArray(content)) continue;
|
|
10408
|
+
for (const block of content) {
|
|
10409
|
+
const item = block;
|
|
10410
|
+
if (!item || typeof item !== "object") continue;
|
|
10411
|
+
const blockType = item.type;
|
|
10412
|
+
if (!isNonEmptyString(blockType)) continue;
|
|
10413
|
+
if (eventType === "assistant") {
|
|
10414
|
+
if (blockType === "text" && isNonEmptyString(item.text)) {
|
|
10415
|
+
yield {
|
|
10416
|
+
event: "agent_message",
|
|
10417
|
+
text: item.text
|
|
10418
|
+
};
|
|
10419
|
+
continue;
|
|
10420
|
+
}
|
|
10421
|
+
if (blockType === "tool_use" && isNonEmptyString(item.id) && isNonEmptyString(item.name)) {
|
|
10422
|
+
const kind = TOOL_KIND_MAP[item.name] ?? "other";
|
|
10423
|
+
toolKindsById.set(item.id, kind);
|
|
10424
|
+
yield {
|
|
10425
|
+
event: "tool_start",
|
|
10426
|
+
id: item.id,
|
|
10427
|
+
kind,
|
|
10428
|
+
title: extractTitle(item.name, item.input),
|
|
10429
|
+
input: item.input
|
|
10430
|
+
};
|
|
10547
10431
|
}
|
|
10432
|
+
continue;
|
|
10548
10433
|
}
|
|
10549
|
-
|
|
10550
|
-
|
|
10551
|
-
|
|
10552
|
-
|
|
10553
|
-
|
|
10554
|
-
|
|
10555
|
-
|
|
10556
|
-
|
|
10557
|
-
|
|
10558
|
-
|
|
10559
|
-
|
|
10434
|
+
if (eventType === "user") {
|
|
10435
|
+
if (!isNonEmptyString(item.tool_use_id)) continue;
|
|
10436
|
+
if (blockType !== "tool_result") continue;
|
|
10437
|
+
const kind = toolKindsById.get(item.tool_use_id);
|
|
10438
|
+
toolKindsById.delete(item.tool_use_id);
|
|
10439
|
+
let path55;
|
|
10440
|
+
if (typeof item.content === "string") {
|
|
10441
|
+
path55 = item.content;
|
|
10442
|
+
} else {
|
|
10443
|
+
try {
|
|
10444
|
+
path55 = JSON.stringify(item.content);
|
|
10445
|
+
} catch {
|
|
10446
|
+
path55 = String(item.content);
|
|
10560
10447
|
}
|
|
10561
10448
|
}
|
|
10449
|
+
yield {
|
|
10450
|
+
event: "tool_complete",
|
|
10451
|
+
id: item.tool_use_id,
|
|
10452
|
+
kind,
|
|
10453
|
+
path: path55
|
|
10454
|
+
};
|
|
10562
10455
|
}
|
|
10563
|
-
|
|
10564
|
-
|
|
10565
|
-
|
|
10566
|
-
|
|
10567
|
-
|
|
10568
|
-
|
|
10569
|
-
|
|
10570
|
-
|
|
10571
|
-
|
|
10572
|
-
|
|
10456
|
+
}
|
|
10457
|
+
}
|
|
10458
|
+
}
|
|
10459
|
+
var TOOL_KIND_MAP, TITLE_KEYS;
|
|
10460
|
+
var init_claude = __esm({
|
|
10461
|
+
"packages/agent-spawn/src/adapters/claude.ts"() {
|
|
10462
|
+
"use strict";
|
|
10463
|
+
init_utils2();
|
|
10464
|
+
TOOL_KIND_MAP = {
|
|
10465
|
+
Read: "read",
|
|
10466
|
+
Write: "edit",
|
|
10467
|
+
Edit: "edit",
|
|
10468
|
+
NotebookEdit: "edit",
|
|
10469
|
+
Bash: "exec",
|
|
10470
|
+
Glob: "search",
|
|
10471
|
+
Grep: "search",
|
|
10472
|
+
Task: "think"
|
|
10473
|
+
};
|
|
10474
|
+
TITLE_KEYS = {
|
|
10475
|
+
Bash: ["command"],
|
|
10476
|
+
Read: ["file_path"],
|
|
10477
|
+
Write: ["file_path"],
|
|
10478
|
+
Edit: ["file_path"],
|
|
10479
|
+
NotebookEdit: ["notebook_path"],
|
|
10480
|
+
Glob: ["pattern"],
|
|
10481
|
+
Grep: ["pattern"],
|
|
10482
|
+
Task: ["description", "prompt"]
|
|
10483
|
+
};
|
|
10484
|
+
}
|
|
10485
|
+
});
|
|
10486
|
+
|
|
10487
|
+
// packages/agent-spawn/src/adapters/codex.ts
|
|
10488
|
+
async function* adaptCodex(lines) {
|
|
10489
|
+
const toolTitleById = /* @__PURE__ */ new Map();
|
|
10490
|
+
const toolKindById = /* @__PURE__ */ new Map();
|
|
10491
|
+
for await (const rawLine of lines) {
|
|
10492
|
+
const line = rawLine.trim();
|
|
10493
|
+
if (!line) continue;
|
|
10494
|
+
let event;
|
|
10495
|
+
try {
|
|
10496
|
+
event = JSON.parse(line);
|
|
10497
|
+
} catch (error2) {
|
|
10498
|
+
const stack = error2 instanceof Error ? error2.stack : void 0;
|
|
10499
|
+
yield {
|
|
10500
|
+
event: "error",
|
|
10501
|
+
message: `[adaptCodex] Malformed JSON line: ${truncate2(line, 200)}`,
|
|
10502
|
+
stack
|
|
10503
|
+
};
|
|
10504
|
+
continue;
|
|
10505
|
+
}
|
|
10506
|
+
const eventType = event.type;
|
|
10507
|
+
if (!isNonEmptyString(eventType)) continue;
|
|
10508
|
+
if (eventType === "thread.started") {
|
|
10509
|
+
const maybeThreadId = extractThreadId(event);
|
|
10510
|
+
yield { event: "session_start", threadId: maybeThreadId };
|
|
10511
|
+
continue;
|
|
10512
|
+
}
|
|
10513
|
+
if (eventType === "turn.started") {
|
|
10514
|
+
continue;
|
|
10515
|
+
}
|
|
10516
|
+
if (eventType === "turn.completed") {
|
|
10517
|
+
const usage = event.usage ?? {};
|
|
10518
|
+
const inputTokens = typeof usage.input_tokens === "number" ? usage.input_tokens : 0;
|
|
10519
|
+
const outputTokens = typeof usage.output_tokens === "number" ? usage.output_tokens : 0;
|
|
10520
|
+
const cachedTokens = typeof usage.cached_input_tokens === "number" ? usage.cached_input_tokens : 0;
|
|
10521
|
+
yield { event: "usage", inputTokens, outputTokens, cachedTokens };
|
|
10522
|
+
continue;
|
|
10523
|
+
}
|
|
10524
|
+
if (eventType === "turn.failed") {
|
|
10525
|
+
const message2 = extractErrorMessage(event) ?? "Turn failed";
|
|
10526
|
+
yield { event: "error", message: message2 };
|
|
10527
|
+
continue;
|
|
10528
|
+
}
|
|
10529
|
+
const item = event.item ?? null;
|
|
10530
|
+
if (!item || typeof item !== "object") continue;
|
|
10531
|
+
const itemType = item.type;
|
|
10532
|
+
if (!isNonEmptyString(itemType)) continue;
|
|
10533
|
+
if (eventType === "item.started") {
|
|
10534
|
+
if (!isNonEmptyString(item.id)) continue;
|
|
10535
|
+
let kind;
|
|
10536
|
+
let title;
|
|
10537
|
+
if (itemType === "command_execution") {
|
|
10538
|
+
kind = "exec";
|
|
10539
|
+
title = truncate2(isNonEmptyString(item.command) ? item.command : "", 80);
|
|
10540
|
+
} else if (itemType === "file_edit") {
|
|
10541
|
+
kind = "edit";
|
|
10542
|
+
title = isNonEmptyString(item.path) ? item.path : "";
|
|
10543
|
+
} else if (itemType === "thinking") {
|
|
10544
|
+
kind = "think";
|
|
10545
|
+
title = "thinking...";
|
|
10546
|
+
} else if (itemType === "mcp_tool_call") {
|
|
10547
|
+
const server = isNonEmptyString(item.server) ? item.server : "unknown";
|
|
10548
|
+
const tool = isNonEmptyString(item.tool) ? item.tool : "unknown";
|
|
10549
|
+
kind = "other";
|
|
10550
|
+
title = `${server}.${tool}`;
|
|
10573
10551
|
}
|
|
10574
|
-
|
|
10575
|
-
|
|
10576
|
-
|
|
10577
|
-
|
|
10578
|
-
return;
|
|
10579
|
-
}
|
|
10580
|
-
this.trackedTerminalIds.set(sessionId, /* @__PURE__ */ new Set([terminalId]));
|
|
10552
|
+
if (kind && title !== void 0) {
|
|
10553
|
+
toolTitleById.set(item.id, title);
|
|
10554
|
+
toolKindById.set(item.id, kind);
|
|
10555
|
+
yield { event: "tool_start", id: item.id, kind, title };
|
|
10581
10556
|
}
|
|
10582
|
-
|
|
10583
|
-
|
|
10584
|
-
|
|
10585
|
-
|
|
10586
|
-
|
|
10587
|
-
|
|
10557
|
+
continue;
|
|
10558
|
+
}
|
|
10559
|
+
if (eventType === "item.completed") {
|
|
10560
|
+
if (itemType === "agent_message") {
|
|
10561
|
+
if (!isNonEmptyString(item.text)) continue;
|
|
10562
|
+
yield { event: "agent_message", text: item.text };
|
|
10563
|
+
continue;
|
|
10588
10564
|
}
|
|
10589
|
-
|
|
10590
|
-
const
|
|
10591
|
-
if (!
|
|
10592
|
-
|
|
10593
|
-
|
|
10594
|
-
sessionTerminals.delete(terminalId);
|
|
10595
|
-
if (sessionTerminals.size === 0) {
|
|
10596
|
-
this.trackedTerminalIds.delete(sessionId);
|
|
10597
|
-
}
|
|
10565
|
+
if (itemType === "reasoning") {
|
|
10566
|
+
const text4 = isNonEmptyString(item.text) ? item.text : isNonEmptyString(item.content) ? item.content : isNonEmptyString(item.summary) ? item.summary : void 0;
|
|
10567
|
+
if (!text4) continue;
|
|
10568
|
+
yield { event: "reasoning", text: text4 };
|
|
10569
|
+
continue;
|
|
10598
10570
|
}
|
|
10599
|
-
|
|
10600
|
-
|
|
10601
|
-
|
|
10602
|
-
|
|
10603
|
-
|
|
10604
|
-
|
|
10605
|
-
|
|
10606
|
-
|
|
10607
|
-
|
|
10608
|
-
if (block.type === "resource" && promptCapabilities?.embeddedContext !== true) {
|
|
10609
|
-
throw new Error('Agent does not support prompt content type "resource".');
|
|
10610
|
-
}
|
|
10611
|
-
}
|
|
10571
|
+
if (!isNonEmptyString(item.id)) continue;
|
|
10572
|
+
if (itemType === "command_execution" || itemType === "file_edit" || itemType === "mcp_tool_call") {
|
|
10573
|
+
const kindFromStart = toolKindById.get(item.id);
|
|
10574
|
+
const kind = kindFromStart ?? (itemType === "command_execution" ? "exec" : itemType === "file_edit" ? "edit" : "other");
|
|
10575
|
+
const titleFromEvent = isNonEmptyString(item.path) ? item.path : itemType === "mcp_tool_call" ? `${isNonEmptyString(item.server) ? item.server : "unknown"}.${isNonEmptyString(item.tool) ? item.tool : "unknown"}` : void 0;
|
|
10576
|
+
const path55 = titleFromEvent ?? toolTitleById.get(item.id) ?? "";
|
|
10577
|
+
toolTitleById.delete(item.id);
|
|
10578
|
+
toolKindById.delete(item.id);
|
|
10579
|
+
yield { event: "tool_complete", id: item.id, kind, path: path55 };
|
|
10612
10580
|
}
|
|
10613
|
-
}
|
|
10581
|
+
}
|
|
10582
|
+
}
|
|
10583
|
+
}
|
|
10584
|
+
function extractErrorMessage(event) {
|
|
10585
|
+
if (isNonEmptyString(event.message)) return event.message;
|
|
10586
|
+
const error2 = event.error;
|
|
10587
|
+
if (isNonEmptyString(error2)) return error2;
|
|
10588
|
+
if (typeof error2 === "object" && error2 !== null) {
|
|
10589
|
+
const errorObj = error2;
|
|
10590
|
+
if (isNonEmptyString(errorObj.message)) return errorObj.message;
|
|
10591
|
+
}
|
|
10592
|
+
if (isNonEmptyString(event.reason)) return event.reason;
|
|
10593
|
+
return void 0;
|
|
10594
|
+
}
|
|
10595
|
+
var init_codex3 = __esm({
|
|
10596
|
+
"packages/agent-spawn/src/adapters/codex.ts"() {
|
|
10597
|
+
"use strict";
|
|
10598
|
+
init_utils2();
|
|
10614
10599
|
}
|
|
10615
10600
|
});
|
|
10616
10601
|
|
|
10617
|
-
// packages/
|
|
10618
|
-
|
|
10619
|
-
|
|
10602
|
+
// packages/agent-spawn/src/adapters/kimi.ts
|
|
10603
|
+
async function* adaptKimi(lines) {
|
|
10604
|
+
let emittedSessionStart = false;
|
|
10605
|
+
for await (const rawLine of lines) {
|
|
10606
|
+
const line = rawLine.trim();
|
|
10607
|
+
if (!line) continue;
|
|
10608
|
+
let event;
|
|
10609
|
+
try {
|
|
10610
|
+
event = JSON.parse(line);
|
|
10611
|
+
} catch (error2) {
|
|
10612
|
+
const stack = error2 instanceof Error ? error2.stack : void 0;
|
|
10613
|
+
yield {
|
|
10614
|
+
event: "error",
|
|
10615
|
+
message: `[adaptKimi] Malformed JSON line: ${truncate2(line, 200)}`,
|
|
10616
|
+
stack
|
|
10617
|
+
};
|
|
10618
|
+
continue;
|
|
10619
|
+
}
|
|
10620
|
+
if (!event || typeof event !== "object") continue;
|
|
10621
|
+
if (!emittedSessionStart) {
|
|
10622
|
+
const threadId = extractThreadId(event);
|
|
10623
|
+
if (threadId) {
|
|
10624
|
+
emittedSessionStart = true;
|
|
10625
|
+
yield { event: "session_start", threadId };
|
|
10626
|
+
}
|
|
10627
|
+
}
|
|
10628
|
+
const role = event.role;
|
|
10629
|
+
if (!isNonEmptyString(role) || role !== "assistant") continue;
|
|
10630
|
+
const content = event.content;
|
|
10631
|
+
if (!isNonEmptyString(content)) continue;
|
|
10632
|
+
yield { event: "agent_message", text: content };
|
|
10633
|
+
}
|
|
10634
|
+
}
|
|
10635
|
+
var init_kimi3 = __esm({
|
|
10636
|
+
"packages/agent-spawn/src/adapters/kimi.ts"() {
|
|
10620
10637
|
"use strict";
|
|
10638
|
+
init_utils2();
|
|
10621
10639
|
}
|
|
10622
10640
|
});
|
|
10623
10641
|
|
|
10624
|
-
// packages/
|
|
10625
|
-
async function
|
|
10626
|
-
const
|
|
10627
|
-
|
|
10628
|
-
|
|
10629
|
-
|
|
10630
|
-
|
|
10642
|
+
// packages/agent-spawn/src/adapters/native.ts
|
|
10643
|
+
async function* adaptNative(lines) {
|
|
10644
|
+
for await (const rawLine of lines) {
|
|
10645
|
+
const line = rawLine.trim();
|
|
10646
|
+
if (!line) continue;
|
|
10647
|
+
let event;
|
|
10648
|
+
try {
|
|
10649
|
+
event = JSON.parse(line);
|
|
10650
|
+
} catch (error2) {
|
|
10651
|
+
const stack = error2 instanceof Error ? error2.stack : void 0;
|
|
10652
|
+
yield {
|
|
10653
|
+
event: "error",
|
|
10654
|
+
message: `[adaptNative] Malformed JSON line: ${truncate2(line, 200)}`,
|
|
10655
|
+
stack
|
|
10656
|
+
};
|
|
10657
|
+
continue;
|
|
10631
10658
|
}
|
|
10659
|
+
const maybeEventType = event?.event;
|
|
10660
|
+
if (!isNonEmptyString(maybeEventType)) {
|
|
10661
|
+
yield {
|
|
10662
|
+
event: "error",
|
|
10663
|
+
message: `[adaptNative] Line missing string "event" field: ${truncate2(line, 200)}`
|
|
10664
|
+
};
|
|
10665
|
+
continue;
|
|
10666
|
+
}
|
|
10667
|
+
yield event;
|
|
10632
10668
|
}
|
|
10633
|
-
return updates;
|
|
10634
10669
|
}
|
|
10635
|
-
|
|
10636
|
-
|
|
10637
|
-
|
|
10638
|
-
|
|
10639
|
-
|
|
10640
|
-
|
|
10641
|
-
|
|
10642
|
-
|
|
10670
|
+
var init_native = __esm({
|
|
10671
|
+
"packages/agent-spawn/src/adapters/native.ts"() {
|
|
10672
|
+
"use strict";
|
|
10673
|
+
init_utils2();
|
|
10674
|
+
}
|
|
10675
|
+
});
|
|
10676
|
+
|
|
10677
|
+
// packages/agent-spawn/src/adapters/opencode.ts
|
|
10678
|
+
function guessToolKind(toolName) {
|
|
10679
|
+
const normalized = toolName.toLowerCase();
|
|
10680
|
+
if (normalized === "bash" || normalized === "shell" || normalized === "sh") return "exec";
|
|
10681
|
+
if (normalized.includes("read")) return "read";
|
|
10682
|
+
if (normalized.includes("write") || normalized.includes("edit") || normalized.includes("patch")) {
|
|
10683
|
+
return "edit";
|
|
10684
|
+
}
|
|
10685
|
+
if (normalized.includes("search") || normalized.includes("grep") || normalized.includes("glob") || normalized.includes("find")) {
|
|
10686
|
+
return "search";
|
|
10687
|
+
}
|
|
10688
|
+
if (normalized.includes("think") || normalized.includes("task")) return "think";
|
|
10689
|
+
return "other";
|
|
10690
|
+
}
|
|
10691
|
+
function safeStringify(value) {
|
|
10692
|
+
if (typeof value === "string") return value;
|
|
10693
|
+
try {
|
|
10694
|
+
return JSON.stringify(value);
|
|
10695
|
+
} catch {
|
|
10696
|
+
return String(value);
|
|
10697
|
+
}
|
|
10698
|
+
}
|
|
10699
|
+
async function* adaptOpenCode(lines) {
|
|
10700
|
+
let emittedSessionStart = false;
|
|
10701
|
+
const toolKindById = /* @__PURE__ */ new Map();
|
|
10702
|
+
for await (const rawLine of lines) {
|
|
10703
|
+
const line = rawLine.trim();
|
|
10704
|
+
if (!line) continue;
|
|
10705
|
+
let event;
|
|
10706
|
+
try {
|
|
10707
|
+
event = JSON.parse(line);
|
|
10708
|
+
} catch (error2) {
|
|
10709
|
+
const stack = error2 instanceof Error ? error2.stack : void 0;
|
|
10710
|
+
yield {
|
|
10711
|
+
event: "error",
|
|
10712
|
+
message: `[adaptOpenCode] Malformed JSON line: ${truncate2(line, 200)}`,
|
|
10713
|
+
stack
|
|
10643
10714
|
};
|
|
10644
|
-
if (update.kind !== void 0) {
|
|
10645
|
-
summary.kind = update.kind;
|
|
10646
|
-
}
|
|
10647
|
-
if (update.status !== void 0) {
|
|
10648
|
-
summary.status = update.status;
|
|
10649
|
-
}
|
|
10650
|
-
if (update.rawInput !== void 0) {
|
|
10651
|
-
summary.rawInput = update.rawInput;
|
|
10652
|
-
}
|
|
10653
|
-
if (update.rawOutput !== void 0) {
|
|
10654
|
-
summary.rawOutput = update.rawOutput;
|
|
10655
|
-
}
|
|
10656
|
-
summaries.set(update.toolCallId, summary);
|
|
10657
10715
|
continue;
|
|
10658
10716
|
}
|
|
10659
|
-
if (
|
|
10660
|
-
|
|
10661
|
-
|
|
10662
|
-
|
|
10663
|
-
|
|
10664
|
-
|
|
10665
|
-
|
|
10666
|
-
|
|
10667
|
-
|
|
10668
|
-
|
|
10669
|
-
|
|
10670
|
-
|
|
10671
|
-
|
|
10672
|
-
|
|
10673
|
-
|
|
10674
|
-
|
|
10675
|
-
|
|
10717
|
+
if (!event || typeof event !== "object") continue;
|
|
10718
|
+
const sessionID = extractThreadId(event);
|
|
10719
|
+
if (!emittedSessionStart && isNonEmptyString(sessionID)) {
|
|
10720
|
+
emittedSessionStart = true;
|
|
10721
|
+
yield { event: "session_start", threadId: sessionID };
|
|
10722
|
+
}
|
|
10723
|
+
const eventType = event.type;
|
|
10724
|
+
if (!isNonEmptyString(eventType)) continue;
|
|
10725
|
+
if (eventType === "text") {
|
|
10726
|
+
const part = event.part ?? null;
|
|
10727
|
+
if (!part || typeof part !== "object") continue;
|
|
10728
|
+
if (!isNonEmptyString(part.text)) continue;
|
|
10729
|
+
yield { event: "agent_message", text: part.text };
|
|
10730
|
+
continue;
|
|
10731
|
+
}
|
|
10732
|
+
if (eventType === "tool_use") {
|
|
10733
|
+
const part = event.part ?? null;
|
|
10734
|
+
if (!part || typeof part !== "object") continue;
|
|
10735
|
+
if (!isNonEmptyString(part.callID) || !isNonEmptyString(part.tool)) continue;
|
|
10736
|
+
const state = part.state ?? null;
|
|
10737
|
+
if (!state || typeof state !== "object") continue;
|
|
10738
|
+
const kind = guessToolKind(part.tool);
|
|
10739
|
+
const status = state.status;
|
|
10740
|
+
const terminal = status === "completed" || status === "failed";
|
|
10741
|
+
if (!toolKindById.has(part.callID)) {
|
|
10742
|
+
toolKindById.set(part.callID, kind);
|
|
10743
|
+
let title = part.tool;
|
|
10744
|
+
const maybeInput = state.input;
|
|
10745
|
+
if (kind === "exec" && maybeInput && typeof maybeInput === "object") {
|
|
10746
|
+
const command = maybeInput.command;
|
|
10747
|
+
if (isNonEmptyString(command)) {
|
|
10748
|
+
title = truncate2(command, 80);
|
|
10749
|
+
}
|
|
10750
|
+
}
|
|
10751
|
+
yield {
|
|
10752
|
+
event: "tool_start",
|
|
10753
|
+
id: part.callID,
|
|
10754
|
+
kind,
|
|
10755
|
+
title,
|
|
10756
|
+
input: state.input
|
|
10757
|
+
};
|
|
10676
10758
|
}
|
|
10677
|
-
if (
|
|
10678
|
-
|
|
10759
|
+
if (terminal) {
|
|
10760
|
+
const kindFromStart = toolKindById.get(part.callID) ?? kind;
|
|
10761
|
+
toolKindById.delete(part.callID);
|
|
10762
|
+
yield {
|
|
10763
|
+
event: "tool_complete",
|
|
10764
|
+
id: part.callID,
|
|
10765
|
+
kind: kindFromStart,
|
|
10766
|
+
path: safeStringify(state.output)
|
|
10767
|
+
};
|
|
10679
10768
|
}
|
|
10680
|
-
|
|
10769
|
+
continue;
|
|
10770
|
+
}
|
|
10771
|
+
if (eventType === "step_finish") {
|
|
10772
|
+
const part = event.part ?? null;
|
|
10773
|
+
if (!part || typeof part !== "object") continue;
|
|
10774
|
+
const tokens = part.tokens ?? null;
|
|
10775
|
+
if (!tokens || typeof tokens !== "object") continue;
|
|
10776
|
+
const inputTokens = typeof tokens.input === "number" ? tokens.input : 0;
|
|
10777
|
+
const outputTokens = typeof tokens.output === "number" ? tokens.output : 0;
|
|
10778
|
+
const cache = tokens.cache ?? null;
|
|
10779
|
+
const cachedTokens = cache && typeof cache === "object" && typeof cache.read === "number" ? cache.read : void 0;
|
|
10780
|
+
if (inputTokens === 0 && outputTokens === 0 && cachedTokens === void 0) continue;
|
|
10781
|
+
yield { event: "usage", inputTokens, outputTokens, cachedTokens };
|
|
10782
|
+
continue;
|
|
10681
10783
|
}
|
|
10682
10784
|
}
|
|
10683
|
-
return Array.from(summaries.values());
|
|
10684
10785
|
}
|
|
10685
|
-
|
|
10686
|
-
|
|
10687
|
-
|
|
10786
|
+
var init_opencode3 = __esm({
|
|
10787
|
+
"packages/agent-spawn/src/adapters/opencode.ts"() {
|
|
10788
|
+
"use strict";
|
|
10789
|
+
init_utils2();
|
|
10688
10790
|
}
|
|
10689
|
-
|
|
10690
|
-
|
|
10691
|
-
|
|
10692
|
-
|
|
10693
|
-
|
|
10694
|
-
|
|
10695
|
-
|
|
10696
|
-
return value;
|
|
10791
|
+
});
|
|
10792
|
+
|
|
10793
|
+
// packages/agent-spawn/src/adapters/index.ts
|
|
10794
|
+
function getAdapter(type) {
|
|
10795
|
+
const adapter = adapters[type];
|
|
10796
|
+
if (!adapter) {
|
|
10797
|
+
throw new Error(`Unknown adapter "${String(type)}".`);
|
|
10697
10798
|
}
|
|
10698
|
-
return
|
|
10799
|
+
return adapter;
|
|
10699
10800
|
}
|
|
10700
|
-
var
|
|
10701
|
-
|
|
10801
|
+
var adapters;
|
|
10802
|
+
var init_adapters = __esm({
|
|
10803
|
+
"packages/agent-spawn/src/adapters/index.ts"() {
|
|
10702
10804
|
"use strict";
|
|
10805
|
+
init_claude();
|
|
10806
|
+
init_codex3();
|
|
10807
|
+
init_kimi3();
|
|
10808
|
+
init_native();
|
|
10809
|
+
init_opencode3();
|
|
10810
|
+
init_codex3();
|
|
10811
|
+
init_claude();
|
|
10812
|
+
init_kimi3();
|
|
10813
|
+
init_native();
|
|
10814
|
+
init_opencode3();
|
|
10815
|
+
adapters = {
|
|
10816
|
+
codex: adaptCodex,
|
|
10817
|
+
claude: adaptClaude,
|
|
10818
|
+
kimi: adaptKimi,
|
|
10819
|
+
native: adaptNative,
|
|
10820
|
+
opencode: adaptOpenCode
|
|
10821
|
+
};
|
|
10703
10822
|
}
|
|
10704
10823
|
});
|
|
10705
10824
|
|
|
10706
|
-
// packages/
|
|
10707
|
-
|
|
10708
|
-
|
|
10709
|
-
|
|
10710
|
-
|
|
10711
|
-
|
|
10712
|
-
|
|
10713
|
-
let
|
|
10714
|
-
for await (const
|
|
10715
|
-
|
|
10716
|
-
|
|
10717
|
-
|
|
10718
|
-
|
|
10719
|
-
|
|
10720
|
-
|
|
10721
|
-
if (sessionId) {
|
|
10722
|
-
runIdFromStream = sessionId;
|
|
10723
|
-
}
|
|
10825
|
+
// packages/agent-spawn/src/acp/line-reader.ts
|
|
10826
|
+
function chunkToString2(chunk) {
|
|
10827
|
+
if (typeof chunk === "string") return chunk;
|
|
10828
|
+
if (chunk instanceof Uint8Array) return Buffer.from(chunk).toString("utf8");
|
|
10829
|
+
return String(chunk);
|
|
10830
|
+
}
|
|
10831
|
+
async function* readLines2(stream) {
|
|
10832
|
+
let buffer = "";
|
|
10833
|
+
for await (const chunk of stream) {
|
|
10834
|
+
buffer += chunkToString2(chunk);
|
|
10835
|
+
while (true) {
|
|
10836
|
+
const newlineIndex = buffer.indexOf("\n");
|
|
10837
|
+
if (newlineIndex === -1) break;
|
|
10838
|
+
yield buffer.slice(0, newlineIndex);
|
|
10839
|
+
buffer = buffer.slice(newlineIndex + 1);
|
|
10724
10840
|
}
|
|
10725
10841
|
}
|
|
10726
|
-
|
|
10727
|
-
|
|
10728
|
-
throw new Error("Run id is required via options.runId or session/update stream items");
|
|
10842
|
+
if (buffer.length > 0) {
|
|
10843
|
+
yield buffer;
|
|
10729
10844
|
}
|
|
10730
|
-
const startTime = normalizeTime(options.startTime, now);
|
|
10731
|
-
const endTime = normalizeTime(options.endTime, now);
|
|
10732
|
-
const toolCalls = await extractToolCallSummariesFromSessionUpdateStream(bufferedEntries);
|
|
10733
|
-
const usageUpdates = await extractUsageFromSessionUpdateStream(bufferedEntries);
|
|
10734
|
-
const usage = summarizeUsage(usageUpdates);
|
|
10735
|
-
const errors = collectErrors(toolCalls, options.errors);
|
|
10736
|
-
const exitStatus = options.exitStatus ?? (errors.length > 0 ? "failed" : "success");
|
|
10737
|
-
return {
|
|
10738
|
-
runId,
|
|
10739
|
-
startTime,
|
|
10740
|
-
endTime,
|
|
10741
|
-
exitStatus,
|
|
10742
|
-
toolCalls,
|
|
10743
|
-
usage,
|
|
10744
|
-
errors
|
|
10745
|
-
};
|
|
10746
10845
|
}
|
|
10747
|
-
|
|
10748
|
-
|
|
10749
|
-
|
|
10750
|
-
function normalizeTime(value, now) {
|
|
10751
|
-
if (value instanceof Date) {
|
|
10752
|
-
return value.toISOString();
|
|
10753
|
-
}
|
|
10754
|
-
if (typeof value === "string" && value.length > 0) {
|
|
10755
|
-
const parsed = new Date(value);
|
|
10756
|
-
if (!Number.isNaN(parsed.getTime())) {
|
|
10757
|
-
return parsed.toISOString();
|
|
10758
|
-
}
|
|
10846
|
+
var init_line_reader = __esm({
|
|
10847
|
+
"packages/agent-spawn/src/acp/line-reader.ts"() {
|
|
10848
|
+
"use strict";
|
|
10759
10849
|
}
|
|
10760
|
-
|
|
10850
|
+
});
|
|
10851
|
+
|
|
10852
|
+
// packages/agent-spawn/src/acp/spawn.ts
|
|
10853
|
+
import { spawn as spawnChildProcess4 } from "node:child_process";
|
|
10854
|
+
function createAbortError2() {
|
|
10855
|
+
const error2 = new Error("Agent spawn aborted");
|
|
10856
|
+
error2.name = "AbortError";
|
|
10857
|
+
return error2;
|
|
10761
10858
|
}
|
|
10762
|
-
function
|
|
10763
|
-
|
|
10764
|
-
|
|
10765
|
-
|
|
10766
|
-
|
|
10767
|
-
|
|
10768
|
-
size += update.size;
|
|
10769
|
-
if (update.cost !== void 0) {
|
|
10770
|
-
cost = update.cost;
|
|
10771
|
-
}
|
|
10772
|
-
}
|
|
10773
|
-
const usage = {
|
|
10774
|
-
used,
|
|
10775
|
-
size,
|
|
10776
|
-
updates: updates.length
|
|
10777
|
-
};
|
|
10778
|
-
if (cost !== void 0) {
|
|
10779
|
-
usage.cost = cost;
|
|
10780
|
-
}
|
|
10781
|
-
return usage;
|
|
10859
|
+
function createActivityTimeoutError2(timeoutMs) {
|
|
10860
|
+
const error2 = new Error(
|
|
10861
|
+
`Agent spawn timed out after ${timeoutMs / 1e3}s of inactivity`
|
|
10862
|
+
);
|
|
10863
|
+
error2.name = "ActivityTimeoutError";
|
|
10864
|
+
return error2;
|
|
10782
10865
|
}
|
|
10783
|
-
function
|
|
10784
|
-
|
|
10785
|
-
|
|
10786
|
-
|
|
10787
|
-
|
|
10788
|
-
|
|
10789
|
-
|
|
10790
|
-
|
|
10791
|
-
|
|
10792
|
-
});
|
|
10793
|
-
}
|
|
10794
|
-
if (additionalErrors) {
|
|
10795
|
-
for (const message2 of additionalErrors) {
|
|
10796
|
-
const text4 = toNonEmptyString(message2);
|
|
10797
|
-
if (text4) {
|
|
10798
|
-
errors.push({ message: text4 });
|
|
10799
|
-
}
|
|
10800
|
-
}
|
|
10866
|
+
function isAcpEvent(value) {
|
|
10867
|
+
return !!value && typeof value === "object" && "event" in value;
|
|
10868
|
+
}
|
|
10869
|
+
function getDefaultArgsPosition2(config) {
|
|
10870
|
+
return config.defaultArgsPosition ?? "afterPrompt";
|
|
10871
|
+
}
|
|
10872
|
+
function getMcpArgsPosition2(config) {
|
|
10873
|
+
if (config.mcpArgsPosition) {
|
|
10874
|
+
return config.mcpArgsPosition;
|
|
10801
10875
|
}
|
|
10802
|
-
return
|
|
10876
|
+
return config.mcpArgsBeforeCommand ? "beforeCommand" : "afterCommand";
|
|
10803
10877
|
}
|
|
10804
|
-
function
|
|
10805
|
-
if (
|
|
10806
|
-
|
|
10878
|
+
function spawnStreaming(options) {
|
|
10879
|
+
if (options.signal?.aborted) {
|
|
10880
|
+
throw createAbortError2();
|
|
10807
10881
|
}
|
|
10808
|
-
|
|
10809
|
-
|
|
10882
|
+
const { agentId, binaryName, spawnConfig } = resolveConfig(options.agentId);
|
|
10883
|
+
if (spawnConfig === void 0) {
|
|
10884
|
+
throw new Error(`Agent "${agentId}" has no spawn config.`);
|
|
10810
10885
|
}
|
|
10811
|
-
if (
|
|
10812
|
-
|
|
10813
|
-
if (encoded) {
|
|
10814
|
-
return encoded;
|
|
10815
|
-
}
|
|
10886
|
+
if (spawnConfig.kind !== "cli") {
|
|
10887
|
+
throw new Error(`Agent "${agentId}" does not support CLI spawn.`);
|
|
10816
10888
|
}
|
|
10817
|
-
|
|
10818
|
-
}
|
|
10819
|
-
function trySerialize(value) {
|
|
10820
|
-
try {
|
|
10821
|
-
const serialized = JSON.stringify(value);
|
|
10822
|
-
if (typeof serialized === "string" && serialized.length > 0) {
|
|
10823
|
-
return serialized;
|
|
10824
|
-
}
|
|
10825
|
-
} catch {
|
|
10826
|
-
return void 0;
|
|
10889
|
+
if (!binaryName) {
|
|
10890
|
+
throw new Error(`Agent "${agentId}" has no binaryName.`);
|
|
10827
10891
|
}
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
|
|
10831
|
-
|
|
10832
|
-
|
|
10892
|
+
const mcpArgs = getMcpArgs(spawnConfig, options.mcpServers);
|
|
10893
|
+
const mcpEnvVars = getMcpEnv(spawnConfig, options.mcpServers);
|
|
10894
|
+
const defaultArgsPosition = getDefaultArgsPosition2(spawnConfig);
|
|
10895
|
+
const mcpArgsPosition = getMcpArgsPosition2(spawnConfig);
|
|
10896
|
+
const args = [];
|
|
10897
|
+
if (mcpArgsPosition === "beforeCommand") {
|
|
10898
|
+
args.push(...mcpArgs);
|
|
10833
10899
|
}
|
|
10834
|
-
|
|
10835
|
-
|
|
10836
|
-
var init_run_report = __esm({
|
|
10837
|
-
"packages/poe-acp-client/src/run-report.ts"() {
|
|
10838
|
-
"use strict";
|
|
10839
|
-
init_stream_helpers();
|
|
10900
|
+
if (defaultArgsPosition === "beforePrompt") {
|
|
10901
|
+
args.push(...spawnConfig.defaultArgs);
|
|
10840
10902
|
}
|
|
10841
|
-
|
|
10842
|
-
|
|
10843
|
-
// packages/poe-acp-client/src/index.ts
|
|
10844
|
-
var init_src7 = __esm({
|
|
10845
|
-
"packages/poe-acp-client/src/index.ts"() {
|
|
10846
|
-
"use strict";
|
|
10847
|
-
init_acp_client();
|
|
10848
|
-
init_acp_transport();
|
|
10849
|
-
init_types3();
|
|
10850
|
-
init_jsonrpc_message_layer();
|
|
10851
|
-
init_jsonrpc();
|
|
10852
|
-
init_run_report();
|
|
10853
|
-
init_stream_helpers();
|
|
10903
|
+
if (mcpArgsPosition === "beforePrompt") {
|
|
10904
|
+
args.push(...mcpArgs);
|
|
10854
10905
|
}
|
|
10855
|
-
|
|
10856
|
-
|
|
10857
|
-
|
|
10858
|
-
|
|
10859
|
-
if (kind === "execute") return "exec";
|
|
10860
|
-
if (kind === "write") return "edit";
|
|
10861
|
-
if (kind === "read") return "read";
|
|
10862
|
-
return "other";
|
|
10863
|
-
}
|
|
10864
|
-
function toToolTitle(title, locations) {
|
|
10865
|
-
if (locations && locations.length > 0 && locations[0].path) {
|
|
10866
|
-
return locations[0].path;
|
|
10906
|
+
args.push(spawnConfig.promptFlag);
|
|
10907
|
+
const useStdin = !!options.useStdin && !!spawnConfig.stdinMode;
|
|
10908
|
+
if (!useStdin || !spawnConfig.stdinMode?.omitPrompt) {
|
|
10909
|
+
args.push(options.prompt);
|
|
10867
10910
|
}
|
|
10868
|
-
|
|
10869
|
-
|
|
10870
|
-
|
|
10871
|
-
|
|
10872
|
-
if (value === void 0 || value === null) return "";
|
|
10873
|
-
try {
|
|
10874
|
-
return JSON.stringify(value);
|
|
10875
|
-
} catch {
|
|
10876
|
-
return String(value);
|
|
10911
|
+
if (options.model && spawnConfig.modelFlag) {
|
|
10912
|
+
let model = spawnConfig.modelStripProviderPrefix ? stripModelNamespace(options.model) : options.model;
|
|
10913
|
+
if (spawnConfig.modelTransform) model = spawnConfig.modelTransform(model);
|
|
10914
|
+
args.push(spawnConfig.modelFlag, model);
|
|
10877
10915
|
}
|
|
10878
|
-
|
|
10879
|
-
|
|
10880
|
-
const raw = toToolOutput(update.rawOutput);
|
|
10881
|
-
if (raw) return raw;
|
|
10882
|
-
if (!update.content) return "";
|
|
10883
|
-
return update.content.filter((c) => c.type === "text" && c.text).map((c) => c.text).join("");
|
|
10884
|
-
}
|
|
10885
|
-
function toEventsFromSessionUpdate(notification, state) {
|
|
10886
|
-
const update = notification.params.update;
|
|
10887
|
-
if (update.sessionUpdate === "agent_message_chunk" && update.content.type === "text") {
|
|
10888
|
-
return [{ event: "agent_message", text: update.content.text }];
|
|
10916
|
+
if (defaultArgsPosition === "afterPrompt") {
|
|
10917
|
+
args.push(...spawnConfig.defaultArgs);
|
|
10889
10918
|
}
|
|
10890
|
-
if (
|
|
10891
|
-
|
|
10919
|
+
if (mcpArgsPosition === "afterCommand") {
|
|
10920
|
+
args.push(...mcpArgs);
|
|
10892
10921
|
}
|
|
10893
|
-
|
|
10894
|
-
|
|
10895
|
-
|
|
10896
|
-
|
|
10897
|
-
inputTokens: update.used,
|
|
10898
|
-
outputTokens: 0
|
|
10899
|
-
};
|
|
10900
|
-
if (cachedTokens > 0) {
|
|
10901
|
-
usage.cachedTokens = cachedTokens;
|
|
10902
|
-
}
|
|
10903
|
-
if (update.cost && update.cost.currency === "USD") {
|
|
10904
|
-
usage.costUsd = update.cost.amount;
|
|
10905
|
-
}
|
|
10906
|
-
return [usage];
|
|
10922
|
+
const modeResolved = resolveModeConfig(spawnConfig.modes[options.mode ?? "yolo"]);
|
|
10923
|
+
args.push(...modeResolved.args);
|
|
10924
|
+
if (useStdin) {
|
|
10925
|
+
args.push(...spawnConfig.stdinMode.extraArgs);
|
|
10907
10926
|
}
|
|
10908
|
-
if (
|
|
10909
|
-
|
|
10910
|
-
const title = toToolTitle(update.title, update.locations);
|
|
10911
|
-
state.toolCallKinds.set(update.toolCallId, renderKind);
|
|
10912
|
-
state.toolCallTitles.set(update.toolCallId, title);
|
|
10913
|
-
if (state.startedToolCalls.has(update.toolCallId)) {
|
|
10914
|
-
return [];
|
|
10915
|
-
}
|
|
10916
|
-
state.startedToolCalls.add(update.toolCallId);
|
|
10917
|
-
return [{
|
|
10918
|
-
event: "tool_start",
|
|
10919
|
-
kind: renderKind,
|
|
10920
|
-
title,
|
|
10921
|
-
id: update.toolCallId
|
|
10922
|
-
}];
|
|
10927
|
+
if (options.args && options.args.length > 0) {
|
|
10928
|
+
args.push(...options.args);
|
|
10923
10929
|
}
|
|
10924
|
-
|
|
10925
|
-
|
|
10926
|
-
|
|
10927
|
-
|
|
10928
|
-
|
|
10929
|
-
|
|
10930
|
-
|
|
10931
|
-
|
|
10932
|
-
|
|
10933
|
-
|
|
10934
|
-
|
|
10935
|
-
|
|
10936
|
-
|
|
10937
|
-
|
|
10938
|
-
|
|
10939
|
-
|
|
10940
|
-
|
|
10941
|
-
|
|
10942
|
-
|
|
10930
|
+
const envOverrides = { ...mcpEnvVars, ...modeResolved.env };
|
|
10931
|
+
const child = spawnChildProcess4(binaryName, args, {
|
|
10932
|
+
cwd: options.cwd,
|
|
10933
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
10934
|
+
env: Object.keys(envOverrides).length > 0 ? { ...process.env, ...envOverrides } : void 0
|
|
10935
|
+
});
|
|
10936
|
+
let aborted = false;
|
|
10937
|
+
let timedOut = false;
|
|
10938
|
+
const onAbort = () => {
|
|
10939
|
+
aborted = true;
|
|
10940
|
+
child.kill("SIGTERM");
|
|
10941
|
+
};
|
|
10942
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
10943
|
+
let activityTimer;
|
|
10944
|
+
const resetActivityTimer = options.activityTimeoutMs ? () => {
|
|
10945
|
+
if (activityTimer) clearTimeout(activityTimer);
|
|
10946
|
+
activityTimer = setTimeout(() => {
|
|
10947
|
+
timedOut = true;
|
|
10948
|
+
child.kill("SIGTERM");
|
|
10949
|
+
}, options.activityTimeoutMs);
|
|
10950
|
+
} : void 0;
|
|
10951
|
+
resetActivityTimer?.();
|
|
10952
|
+
const result = { stdout: "", stderr: "", exitCode: 1 };
|
|
10953
|
+
child.stderr.setEncoding("utf8");
|
|
10954
|
+
child.stderr.on("data", (chunk) => {
|
|
10955
|
+
result.stderr += chunk;
|
|
10956
|
+
resetActivityTimer?.();
|
|
10957
|
+
});
|
|
10958
|
+
if (useStdin) {
|
|
10959
|
+
child.stdin.write(options.prompt);
|
|
10960
|
+
}
|
|
10961
|
+
child.stdin.end();
|
|
10962
|
+
const adapter = getAdapter(spawnConfig.adapter);
|
|
10963
|
+
const events = (async function* () {
|
|
10964
|
+
for await (const output of adapter(readLines2(child.stdout))) {
|
|
10965
|
+
if (!isAcpEvent(output)) continue;
|
|
10966
|
+
resetActivityTimer?.();
|
|
10967
|
+
yield output;
|
|
10943
10968
|
}
|
|
10944
|
-
|
|
10945
|
-
|
|
10946
|
-
|
|
10947
|
-
|
|
10948
|
-
|
|
10949
|
-
|
|
10950
|
-
|
|
10951
|
-
|
|
10952
|
-
});
|
|
10969
|
+
})();
|
|
10970
|
+
const done = new Promise((resolve2, reject) => {
|
|
10971
|
+
child.on("error", (error2) => {
|
|
10972
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
10973
|
+
if (activityTimer) clearTimeout(activityTimer);
|
|
10974
|
+
if (aborted) {
|
|
10975
|
+
reject(createAbortError2());
|
|
10976
|
+
return;
|
|
10953
10977
|
}
|
|
10954
|
-
|
|
10955
|
-
|
|
10956
|
-
|
|
10957
|
-
|
|
10958
|
-
|
|
10959
|
-
|
|
10960
|
-
|
|
10961
|
-
|
|
10962
|
-
|
|
10963
|
-
|
|
10978
|
+
reject(error2);
|
|
10979
|
+
});
|
|
10980
|
+
child.on("close", (code) => {
|
|
10981
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
10982
|
+
if (activityTimer) clearTimeout(activityTimer);
|
|
10983
|
+
if (aborted) {
|
|
10984
|
+
reject(createAbortError2());
|
|
10985
|
+
return;
|
|
10986
|
+
}
|
|
10987
|
+
if (timedOut) {
|
|
10988
|
+
reject(createActivityTimeoutError2(options.activityTimeoutMs));
|
|
10989
|
+
return;
|
|
10990
|
+
}
|
|
10991
|
+
result.exitCode = code ?? 1;
|
|
10992
|
+
resolve2(result);
|
|
10993
|
+
});
|
|
10994
|
+
});
|
|
10995
|
+
return { events, done };
|
|
10964
10996
|
}
|
|
10997
|
+
var init_spawn2 = __esm({
|
|
10998
|
+
"packages/agent-spawn/src/acp/spawn.ts"() {
|
|
10999
|
+
"use strict";
|
|
11000
|
+
init_adapters();
|
|
11001
|
+
init_line_reader();
|
|
11002
|
+
init_resolve_config();
|
|
11003
|
+
init_mcp_args();
|
|
11004
|
+
init_model_utils();
|
|
11005
|
+
init_types2();
|
|
11006
|
+
}
|
|
11007
|
+
});
|
|
11008
|
+
|
|
11009
|
+
// packages/agent-spawn/src/acp/spawn-acp.ts
|
|
10965
11010
|
function toAcpMcpServers(servers) {
|
|
10966
11011
|
if (!servers) return [];
|
|
10967
11012
|
return Object.entries(servers).map(([name, server]) => ({
|
|
10968
11013
|
name,
|
|
10969
11014
|
command: server.command,
|
|
10970
11015
|
args: server.args ?? [],
|
|
10971
|
-
env: server.env ? Object.entries(server.env).map(([
|
|
11016
|
+
env: server.env ? Object.entries(server.env).map(([k, v]) => ({ name: k, value: v })) : []
|
|
10972
11017
|
}));
|
|
10973
11018
|
}
|
|
10974
11019
|
function createAbortError3() {
|
|
@@ -11009,11 +11054,7 @@ function spawnAcp(options) {
|
|
|
11009
11054
|
void client.dispose();
|
|
11010
11055
|
};
|
|
11011
11056
|
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
11012
|
-
const toolState =
|
|
11013
|
-
startedToolCalls: /* @__PURE__ */ new Set(),
|
|
11014
|
-
toolCallKinds: /* @__PURE__ */ new Map(),
|
|
11015
|
-
toolCallTitles: /* @__PURE__ */ new Map()
|
|
11016
|
-
};
|
|
11057
|
+
const toolState = createToolRenderState();
|
|
11017
11058
|
let sessionId = "";
|
|
11018
11059
|
let assistantText = "";
|
|
11019
11060
|
let lastToolOutput = "";
|
|
@@ -11069,7 +11110,11 @@ function spawnAcp(options) {
|
|
|
11069
11110
|
if (update.sessionUpdate === "agent_message_chunk" && update.content.type === "text") {
|
|
11070
11111
|
assistantText += update.content.text;
|
|
11071
11112
|
}
|
|
11072
|
-
|
|
11113
|
+
const events2 = sessionUpdateToEvents(update, toolState);
|
|
11114
|
+
if (events2.length > 0) {
|
|
11115
|
+
events2[0]._meta = { ...events2[0]._meta ?? {}, raw: update };
|
|
11116
|
+
}
|
|
11117
|
+
for (const event of events2) {
|
|
11073
11118
|
if (event.event === "tool_complete") {
|
|
11074
11119
|
const output = event.path;
|
|
11075
11120
|
if (output) {
|
|
@@ -11128,6 +11173,7 @@ var init_spawn_acp = __esm({
|
|
|
11128
11173
|
init_src2();
|
|
11129
11174
|
init_src7();
|
|
11130
11175
|
init_configs();
|
|
11176
|
+
init_session_update_converter();
|
|
11131
11177
|
}
|
|
11132
11178
|
});
|
|
11133
11179
|
|
|
@@ -11209,7 +11255,7 @@ function updateSessionFromEvent(ctx, event, toolCallsById) {
|
|
|
11209
11255
|
}
|
|
11210
11256
|
const id = readString(event.id);
|
|
11211
11257
|
const kind = readString(event.kind);
|
|
11212
|
-
const
|
|
11258
|
+
const path55 = readString(event.path);
|
|
11213
11259
|
let toolCall = id ? toolCallsById.get(id) : void 0;
|
|
11214
11260
|
if (!toolCall) {
|
|
11215
11261
|
toolCall = {};
|
|
@@ -11224,8 +11270,8 @@ function updateSessionFromEvent(ctx, event, toolCallsById) {
|
|
|
11224
11270
|
if (kind) {
|
|
11225
11271
|
toolCall.kind = kind;
|
|
11226
11272
|
}
|
|
11227
|
-
if (
|
|
11228
|
-
toolCall.path =
|
|
11273
|
+
if (path55) {
|
|
11274
|
+
toolCall.path = path55;
|
|
11229
11275
|
}
|
|
11230
11276
|
}
|
|
11231
11277
|
var sessionCapture;
|
|
@@ -11378,7 +11424,9 @@ var init_spawn_log = __esm({
|
|
|
11378
11424
|
if (!this.fileHandle) {
|
|
11379
11425
|
return;
|
|
11380
11426
|
}
|
|
11381
|
-
|
|
11427
|
+
const meta = event._meta;
|
|
11428
|
+
const toLog = meta?.raw ?? event;
|
|
11429
|
+
await this.fileHandle.appendFile(`${JSON.stringify(toLog)}
|
|
11382
11430
|
`, "utf8");
|
|
11383
11431
|
} catch {
|
|
11384
11432
|
this.isDisabled = true;
|
|
@@ -11717,14 +11765,14 @@ function parseDockerLocator(input) {
|
|
|
11717
11765
|
throw new Error(`Invalid docker workspace locator "${input}".`);
|
|
11718
11766
|
}
|
|
11719
11767
|
const container = input.slice(0, slashIndex);
|
|
11720
|
-
const
|
|
11721
|
-
if (container.length === 0 ||
|
|
11768
|
+
const path55 = input.slice(slashIndex);
|
|
11769
|
+
if (container.length === 0 || path55.length === 0) {
|
|
11722
11770
|
throw new Error(`Invalid docker workspace locator "${input}".`);
|
|
11723
11771
|
}
|
|
11724
11772
|
return {
|
|
11725
11773
|
scheme: "docker",
|
|
11726
11774
|
container,
|
|
11727
|
-
path:
|
|
11775
|
+
path: path55
|
|
11728
11776
|
};
|
|
11729
11777
|
}
|
|
11730
11778
|
function splitOnce(input, separator) {
|
|
@@ -13611,21 +13659,21 @@ function createSdkContainer(options) {
|
|
|
13611
13659
|
});
|
|
13612
13660
|
loggerFactory.setErrorLogger(errorLogger);
|
|
13613
13661
|
const asyncFs = {
|
|
13614
|
-
readFile: ((
|
|
13662
|
+
readFile: ((path55, encoding) => {
|
|
13615
13663
|
if (encoding) {
|
|
13616
|
-
return fs2.readFile(
|
|
13664
|
+
return fs2.readFile(path55, encoding);
|
|
13617
13665
|
}
|
|
13618
|
-
return fs2.readFile(
|
|
13666
|
+
return fs2.readFile(path55);
|
|
13619
13667
|
}),
|
|
13620
|
-
writeFile: (
|
|
13621
|
-
mkdir: (
|
|
13668
|
+
writeFile: (path55, data, opts) => fs2.writeFile(path55, data, opts),
|
|
13669
|
+
mkdir: (path55, opts) => fs2.mkdir(path55, opts).then(() => {
|
|
13622
13670
|
}),
|
|
13623
|
-
stat: (
|
|
13624
|
-
rm: (
|
|
13625
|
-
unlink: (
|
|
13626
|
-
readdir: (
|
|
13671
|
+
stat: (path55) => fs2.stat(path55),
|
|
13672
|
+
rm: (path55, opts) => fs2.rm(path55, opts),
|
|
13673
|
+
unlink: (path55) => fs2.unlink(path55),
|
|
13674
|
+
readdir: (path55) => fs2.readdir(path55),
|
|
13627
13675
|
copyFile: (src, dest) => fs2.copyFile(src, dest),
|
|
13628
|
-
chmod: (
|
|
13676
|
+
chmod: (path55, mode) => fs2.chmod(path55, mode)
|
|
13629
13677
|
};
|
|
13630
13678
|
const contextFactory = createCommandContextFactory({ fs: asyncFs });
|
|
13631
13679
|
const authFs = {
|
|
@@ -14014,7 +14062,7 @@ function createAbortError4() {
|
|
|
14014
14062
|
error2.name = "AbortError";
|
|
14015
14063
|
return error2;
|
|
14016
14064
|
}
|
|
14017
|
-
var
|
|
14065
|
+
var init_utils3 = __esm({
|
|
14018
14066
|
"packages/pipeline/src/utils.ts"() {
|
|
14019
14067
|
"use strict";
|
|
14020
14068
|
}
|
|
@@ -14240,7 +14288,7 @@ var init_loader = __esm({
|
|
|
14240
14288
|
"packages/pipeline/src/config/loader.ts"() {
|
|
14241
14289
|
"use strict";
|
|
14242
14290
|
init_src3();
|
|
14243
|
-
|
|
14291
|
+
init_utils3();
|
|
14244
14292
|
}
|
|
14245
14293
|
});
|
|
14246
14294
|
|
|
@@ -14386,7 +14434,7 @@ function parsePlan(yamlContent, options = {}) {
|
|
|
14386
14434
|
var init_parser2 = __esm({
|
|
14387
14435
|
"packages/pipeline/src/plan/parser.ts"() {
|
|
14388
14436
|
"use strict";
|
|
14389
|
-
|
|
14437
|
+
init_utils3();
|
|
14390
14438
|
}
|
|
14391
14439
|
});
|
|
14392
14440
|
|
|
@@ -14588,7 +14636,7 @@ var init_discovery = __esm({
|
|
|
14588
14636
|
"use strict";
|
|
14589
14637
|
init_loader();
|
|
14590
14638
|
init_parser2();
|
|
14591
|
-
|
|
14639
|
+
init_utils3();
|
|
14592
14640
|
}
|
|
14593
14641
|
});
|
|
14594
14642
|
|
|
@@ -14968,12 +15016,12 @@ function hasErrorCode(error2, code) {
|
|
|
14968
15016
|
}
|
|
14969
15017
|
function createDefaultFs2() {
|
|
14970
15018
|
return {
|
|
14971
|
-
mkdir: async (
|
|
14972
|
-
await fsPromises3.mkdir(
|
|
15019
|
+
mkdir: async (path55, options) => {
|
|
15020
|
+
await fsPromises3.mkdir(path55, options);
|
|
14973
15021
|
},
|
|
14974
15022
|
rmdir: fsPromises3.rmdir,
|
|
14975
|
-
stat: async (
|
|
14976
|
-
const stat15 = await fsPromises3.stat(
|
|
15023
|
+
stat: async (path55) => {
|
|
15024
|
+
const stat15 = await fsPromises3.stat(path55);
|
|
14977
15025
|
return {
|
|
14978
15026
|
isFile: () => stat15.isFile(),
|
|
14979
15027
|
isDirectory: () => stat15.isDirectory(),
|
|
@@ -15647,7 +15695,7 @@ var init_pipeline = __esm({
|
|
|
15647
15695
|
init_parser2();
|
|
15648
15696
|
init_writer();
|
|
15649
15697
|
init_runner();
|
|
15650
|
-
|
|
15698
|
+
init_utils3();
|
|
15651
15699
|
}
|
|
15652
15700
|
});
|
|
15653
15701
|
|
|
@@ -17880,6 +17928,7 @@ var init_ralph = __esm({
|
|
|
17880
17928
|
this.kind = kind;
|
|
17881
17929
|
this.name = "RalphWorkflowStopError";
|
|
17882
17930
|
}
|
|
17931
|
+
kind;
|
|
17883
17932
|
};
|
|
17884
17933
|
}
|
|
17885
17934
|
});
|
|
@@ -18073,6 +18122,8 @@ var init_journal = __esm({
|
|
|
18073
18122
|
this.journalPath = journalPath;
|
|
18074
18123
|
this.fs = fs3;
|
|
18075
18124
|
}
|
|
18125
|
+
journalPath;
|
|
18126
|
+
fs;
|
|
18076
18127
|
async init() {
|
|
18077
18128
|
await this.fs.mkdir(dirname2(this.journalPath), { recursive: true });
|
|
18078
18129
|
try {
|
|
@@ -19272,11 +19323,11 @@ function assertValidEnumValues(values) {
|
|
|
19272
19323
|
throw new Error("Enum schema values must be unique");
|
|
19273
19324
|
}
|
|
19274
19325
|
}
|
|
19275
|
-
var
|
|
19326
|
+
var S2;
|
|
19276
19327
|
var init_src17 = __esm({
|
|
19277
19328
|
"packages/cmdkit-schema/src/index.ts"() {
|
|
19278
19329
|
"use strict";
|
|
19279
|
-
|
|
19330
|
+
S2 = {
|
|
19280
19331
|
String(options = {}) {
|
|
19281
19332
|
return {
|
|
19282
19333
|
kind: "string",
|
|
@@ -20373,7 +20424,7 @@ async function selectAutomationName(message2, automations) {
|
|
|
20373
20424
|
message: message2,
|
|
20374
20425
|
options: automations.map((a) => ({ label: a.label ?? formatLabel(a.name), value: a.name }))
|
|
20375
20426
|
});
|
|
20376
|
-
if (
|
|
20427
|
+
if (q(selected)) {
|
|
20377
20428
|
cancel("Operation cancelled.");
|
|
20378
20429
|
throw new UserError("Operation cancelled.");
|
|
20379
20430
|
}
|
|
@@ -20417,12 +20468,12 @@ var init_commands = __esm({
|
|
|
20417
20468
|
name: "run",
|
|
20418
20469
|
description: "Run a GitHub automation.",
|
|
20419
20470
|
positional: ["name"],
|
|
20420
|
-
params:
|
|
20421
|
-
name:
|
|
20422
|
-
agent:
|
|
20423
|
-
model:
|
|
20424
|
-
mode:
|
|
20425
|
-
cwd:
|
|
20471
|
+
params: S2.Object({
|
|
20472
|
+
name: S2.Optional(S2.String({ description: "Automation name to run" })),
|
|
20473
|
+
agent: S2.Optional(S2.String({ description: "Agent to run the automation with" })),
|
|
20474
|
+
model: S2.Optional(S2.String({ description: "Model override for the agent" })),
|
|
20475
|
+
mode: S2.Optional(S2.Enum(["yolo", "edit", "read"], { description: "Permission mode (yolo | edit | read)" })),
|
|
20476
|
+
cwd: S2.Optional(S2.String({ description: "Working directory for the automation" }))
|
|
20426
20477
|
}),
|
|
20427
20478
|
secrets: {
|
|
20428
20479
|
poeApiKey: { env: "POE_API_KEY" },
|
|
@@ -20503,7 +20554,7 @@ var init_commands = __esm({
|
|
|
20503
20554
|
listCommand = defineCommand({
|
|
20504
20555
|
name: "list",
|
|
20505
20556
|
description: "List available automations.",
|
|
20506
|
-
params:
|
|
20557
|
+
params: S2.Object({}),
|
|
20507
20558
|
scope: ["cli", "sdk"],
|
|
20508
20559
|
handler: async () => discoverAutomations(await resolveBuiltInPromptsDir(), ...projectPromptDirs(resolveCwd())),
|
|
20509
20560
|
render: {
|
|
@@ -20531,9 +20582,9 @@ var init_commands = __esm({
|
|
|
20531
20582
|
name: "install",
|
|
20532
20583
|
description: "Install one or all automation workflows into the current repo.",
|
|
20533
20584
|
positional: ["name"],
|
|
20534
|
-
params:
|
|
20535
|
-
name:
|
|
20536
|
-
|
|
20585
|
+
params: S2.Object({
|
|
20586
|
+
name: S2.Optional(
|
|
20587
|
+
S2.Enum(installableAutomations, {
|
|
20537
20588
|
description: "Pick a GitHub workflow to install",
|
|
20538
20589
|
loadOptions: async () => {
|
|
20539
20590
|
const automations = await discoverAutomations(await resolveBuiltInPromptsDir());
|
|
@@ -20541,7 +20592,7 @@ var init_commands = __esm({
|
|
|
20541
20592
|
}
|
|
20542
20593
|
})
|
|
20543
20594
|
),
|
|
20544
|
-
eject:
|
|
20595
|
+
eject: S2.Optional(S2.Boolean())
|
|
20545
20596
|
}),
|
|
20546
20597
|
scope: ["cli"],
|
|
20547
20598
|
handler: async ({ params }) => {
|
|
@@ -20590,8 +20641,8 @@ var init_commands = __esm({
|
|
|
20590
20641
|
name: "uninstall",
|
|
20591
20642
|
description: "Remove an installed automation workflow from the current repo.",
|
|
20592
20643
|
positional: ["name"],
|
|
20593
|
-
params:
|
|
20594
|
-
name:
|
|
20644
|
+
params: S2.Object({
|
|
20645
|
+
name: S2.Enum(installableAutomations, {
|
|
20595
20646
|
description: "Pick a GitHub workflow to uninstall",
|
|
20596
20647
|
loadOptions: async () => {
|
|
20597
20648
|
const automations = await discoverAutomations(await resolveBuiltInPromptsDir());
|
|
@@ -20625,8 +20676,8 @@ var init_commands = __esm({
|
|
|
20625
20676
|
name: "require-user-allow",
|
|
20626
20677
|
description: "Fail when COMMENT_AUTHOR_ASSOCIATION is not allowed by the automation frontmatter.",
|
|
20627
20678
|
positional: ["name"],
|
|
20628
|
-
params:
|
|
20629
|
-
name:
|
|
20679
|
+
params: S2.Object({
|
|
20680
|
+
name: S2.String()
|
|
20630
20681
|
}),
|
|
20631
20682
|
scope: ["cli"],
|
|
20632
20683
|
handler: async ({ params, env }) => {
|
|
@@ -20639,8 +20690,8 @@ var init_commands = __esm({
|
|
|
20639
20690
|
name: "require-comment-prefix",
|
|
20640
20691
|
description: "Fail when COMMENT_BODY does not start with the automation prefix frontmatter.",
|
|
20641
20692
|
positional: ["name"],
|
|
20642
|
-
params:
|
|
20643
|
-
name:
|
|
20693
|
+
params: S2.Object({
|
|
20694
|
+
name: S2.String()
|
|
20644
20695
|
}),
|
|
20645
20696
|
scope: ["cli"],
|
|
20646
20697
|
handler: async ({ params, env }) => {
|
|
@@ -20653,8 +20704,8 @@ var init_commands = __esm({
|
|
|
20653
20704
|
name: "prepare",
|
|
20654
20705
|
description: "Install and configure the agent required by a workflow automation.",
|
|
20655
20706
|
positional: ["name"],
|
|
20656
|
-
params:
|
|
20657
|
-
name:
|
|
20707
|
+
params: S2.Object({
|
|
20708
|
+
name: S2.String()
|
|
20658
20709
|
}),
|
|
20659
20710
|
scope: ["cli"],
|
|
20660
20711
|
handler: async ({ params, env }) => {
|
|
@@ -20675,8 +20726,8 @@ var init_commands = __esm({
|
|
|
20675
20726
|
name: "prompt-preview",
|
|
20676
20727
|
description: "Preview the resolved prompt for an automation.",
|
|
20677
20728
|
positional: ["name"],
|
|
20678
|
-
params:
|
|
20679
|
-
name:
|
|
20729
|
+
params: S2.Object({
|
|
20730
|
+
name: S2.String()
|
|
20680
20731
|
}),
|
|
20681
20732
|
scope: ["cli", "sdk"],
|
|
20682
20733
|
handler: async ({ params, env }) => {
|
|
@@ -20698,7 +20749,7 @@ var init_commands = __esm({
|
|
|
20698
20749
|
variablesCommand = defineCommand({
|
|
20699
20750
|
name: "variables",
|
|
20700
20751
|
description: "List shared prompt variables and where each value comes from.",
|
|
20701
|
-
params:
|
|
20752
|
+
params: S2.Object({}),
|
|
20702
20753
|
scope: ["cli", "sdk"],
|
|
20703
20754
|
handler: async () => {
|
|
20704
20755
|
const cwd = resolveCwd();
|
|
@@ -25057,7 +25108,7 @@ function createEventQueue() {
|
|
|
25057
25108
|
}
|
|
25058
25109
|
};
|
|
25059
25110
|
}
|
|
25060
|
-
function
|
|
25111
|
+
function createToolRenderState2() {
|
|
25061
25112
|
return {
|
|
25062
25113
|
startedToolCalls: /* @__PURE__ */ new Set(),
|
|
25063
25114
|
toolCallKinds: /* @__PURE__ */ new Map(),
|
|
@@ -25209,7 +25260,7 @@ function toPromptText2(prompt) {
|
|
|
25209
25260
|
}
|
|
25210
25261
|
return lines.join("\n");
|
|
25211
25262
|
}
|
|
25212
|
-
function
|
|
25263
|
+
function toEventsFromSessionUpdate(notification, state) {
|
|
25213
25264
|
const update = notification.params.update;
|
|
25214
25265
|
if (update.sessionUpdate === "agent_message_chunk" && update.content.type === "text") {
|
|
25215
25266
|
return [{ event: "agent_message", text: update.content.text }];
|
|
@@ -25407,7 +25458,7 @@ function createInMemoryAcpTransport2(options) {
|
|
|
25407
25458
|
}
|
|
25408
25459
|
async function runPoeAgentAcpLifecycle(options) {
|
|
25409
25460
|
const sessionUpdates = [];
|
|
25410
|
-
const toolState =
|
|
25461
|
+
const toolState = createToolRenderState2();
|
|
25411
25462
|
let sessionId = "";
|
|
25412
25463
|
let assistantText = "";
|
|
25413
25464
|
const transport = createInMemoryAcpTransport2({
|
|
@@ -25432,7 +25483,7 @@ async function runPoeAgentAcpLifecycle(options) {
|
|
|
25432
25483
|
if (update.sessionUpdate === "agent_message_chunk" && update.content.type === "text") {
|
|
25433
25484
|
assistantText += update.content.text;
|
|
25434
25485
|
}
|
|
25435
|
-
for (const event of
|
|
25486
|
+
for (const event of toEventsFromSessionUpdate(notification, toolState)) {
|
|
25436
25487
|
emitEvent(options.onEvent, event);
|
|
25437
25488
|
}
|
|
25438
25489
|
}
|
|
@@ -25734,11 +25785,11 @@ function formatSegment(segment, casing) {
|
|
|
25734
25785
|
const separator = casing === "snake" ? "_" : "-";
|
|
25735
25786
|
return splitWords(segment).join(separator);
|
|
25736
25787
|
}
|
|
25737
|
-
function toOptionFlag(
|
|
25738
|
-
return `--${
|
|
25788
|
+
function toOptionFlag(path55, casing) {
|
|
25789
|
+
return `--${path55.map((segment) => formatSegment(segment, casing)).join(".")}`;
|
|
25739
25790
|
}
|
|
25740
|
-
function toOptionAttribute(
|
|
25741
|
-
return
|
|
25791
|
+
function toOptionAttribute(path55, casing) {
|
|
25792
|
+
return path55.map((segment) => {
|
|
25742
25793
|
const formatted = formatSegment(segment, casing);
|
|
25743
25794
|
if (casing === "snake") {
|
|
25744
25795
|
return formatted;
|
|
@@ -25749,13 +25800,13 @@ function toOptionAttribute(path54, casing) {
|
|
|
25749
25800
|
).join("");
|
|
25750
25801
|
}).join(".");
|
|
25751
25802
|
}
|
|
25752
|
-
function toDisplayPath3(
|
|
25753
|
-
return
|
|
25803
|
+
function toDisplayPath3(path55) {
|
|
25804
|
+
return path55.join(".");
|
|
25754
25805
|
}
|
|
25755
|
-
function collectFields(schema, casing,
|
|
25806
|
+
function collectFields(schema, casing, path55 = [], inheritedOptional = false) {
|
|
25756
25807
|
const fields = [];
|
|
25757
25808
|
for (const [key, rawChildSchema] of Object.entries(schema.shape)) {
|
|
25758
|
-
const nextPath = [...
|
|
25809
|
+
const nextPath = [...path55, key];
|
|
25759
25810
|
const optional = inheritedOptional || rawChildSchema.kind === "optional";
|
|
25760
25811
|
const childSchema = unwrapOptional(rawChildSchema);
|
|
25761
25812
|
if (childSchema.kind === "object") {
|
|
@@ -25778,9 +25829,9 @@ function collectFields(schema, casing, path54 = [], inheritedOptional = false) {
|
|
|
25778
25829
|
}
|
|
25779
25830
|
return fields;
|
|
25780
25831
|
}
|
|
25781
|
-
function toCommanderOptionAttribute(
|
|
25782
|
-
const optionAttribute = toOptionAttribute(
|
|
25783
|
-
const optionFlag = toOptionFlag(
|
|
25832
|
+
function toCommanderOptionAttribute(path55, casing) {
|
|
25833
|
+
const optionAttribute = toOptionAttribute(path55, casing);
|
|
25834
|
+
const optionFlag = toOptionFlag(path55, casing);
|
|
25784
25835
|
if (!GLOBAL_LONG_OPTION_FLAGS.has(optionFlag)) {
|
|
25785
25836
|
return optionAttribute;
|
|
25786
25837
|
}
|
|
@@ -26228,10 +26279,10 @@ function addGlobalOptions(command) {
|
|
|
26228
26279
|
throw new InvalidArgumentError('Invalid value for "--output". Expected one of: rich, md, json.');
|
|
26229
26280
|
}).option("--verbose", "Print stack traces for unexpected errors.");
|
|
26230
26281
|
}
|
|
26231
|
-
function setNestedValue(target,
|
|
26282
|
+
function setNestedValue(target, path55, value) {
|
|
26232
26283
|
let cursor = target;
|
|
26233
|
-
for (let index = 0; index <
|
|
26234
|
-
const segment =
|
|
26284
|
+
for (let index = 0; index < path55.length - 1; index += 1) {
|
|
26285
|
+
const segment = path55[index] ?? "";
|
|
26235
26286
|
const existing = cursor[segment];
|
|
26236
26287
|
if (typeof existing === "object" && existing !== null) {
|
|
26237
26288
|
cursor = existing;
|
|
@@ -26241,7 +26292,7 @@ function setNestedValue(target, path54, value) {
|
|
|
26241
26292
|
cursor[segment] = next;
|
|
26242
26293
|
cursor = next;
|
|
26243
26294
|
}
|
|
26244
|
-
const leaf =
|
|
26295
|
+
const leaf = path55[path55.length - 1];
|
|
26245
26296
|
if (leaf !== void 0) {
|
|
26246
26297
|
cursor[leaf] = value;
|
|
26247
26298
|
}
|
|
@@ -26267,7 +26318,7 @@ async function promptForField(field) {
|
|
|
26267
26318
|
options,
|
|
26268
26319
|
initialValue: field.hasDefault ? field.defaultValue : void 0
|
|
26269
26320
|
});
|
|
26270
|
-
if (
|
|
26321
|
+
if (q(selected)) {
|
|
26271
26322
|
cancel("Operation cancelled.");
|
|
26272
26323
|
throw new UserError("Operation cancelled.");
|
|
26273
26324
|
}
|
|
@@ -26278,7 +26329,7 @@ async function promptForField(field) {
|
|
|
26278
26329
|
message: field.displayPath,
|
|
26279
26330
|
initialValue: field.hasDefault ? Boolean(field.defaultValue) : void 0
|
|
26280
26331
|
});
|
|
26281
|
-
if (
|
|
26332
|
+
if (q(selected)) {
|
|
26282
26333
|
cancel("Operation cancelled.");
|
|
26283
26334
|
throw new UserError("Operation cancelled.");
|
|
26284
26335
|
}
|
|
@@ -26288,7 +26339,7 @@ async function promptForField(field) {
|
|
|
26288
26339
|
message: field.displayPath,
|
|
26289
26340
|
initialValue: field.hasDefault && field.defaultValue !== void 0 ? formatResolvedValue(field.defaultValue) : void 0
|
|
26290
26341
|
});
|
|
26291
|
-
if (
|
|
26342
|
+
if (q(entered)) {
|
|
26292
26343
|
cancel("Operation cancelled.");
|
|
26293
26344
|
throw new UserError("Operation cancelled.");
|
|
26294
26345
|
}
|
|
@@ -26331,13 +26382,13 @@ async function withOutputFormat2(output, fn) {
|
|
|
26331
26382
|
}
|
|
26332
26383
|
function createFs() {
|
|
26333
26384
|
return {
|
|
26334
|
-
readFile: async (
|
|
26335
|
-
writeFile: async (
|
|
26336
|
-
await writeFile7(
|
|
26385
|
+
readFile: async (path55, encoding = "utf8") => readFile12(path55, { encoding }),
|
|
26386
|
+
writeFile: async (path55, contents) => {
|
|
26387
|
+
await writeFile7(path55, contents);
|
|
26337
26388
|
},
|
|
26338
|
-
exists: async (
|
|
26389
|
+
exists: async (path55) => {
|
|
26339
26390
|
try {
|
|
26340
|
-
await access2(
|
|
26391
|
+
await access2(path55);
|
|
26341
26392
|
return true;
|
|
26342
26393
|
} catch {
|
|
26343
26394
|
return false;
|
|
@@ -26358,9 +26409,9 @@ function isPlainObject2(value) {
|
|
|
26358
26409
|
function hasFieldValue(value) {
|
|
26359
26410
|
return value !== void 0;
|
|
26360
26411
|
}
|
|
26361
|
-
function hasNestedField(fields,
|
|
26412
|
+
function hasNestedField(fields, path55) {
|
|
26362
26413
|
return fields.some(
|
|
26363
|
-
(field) =>
|
|
26414
|
+
(field) => path55.length < field.path.length && path55.every((segment, index) => field.path[index] === segment)
|
|
26364
26415
|
);
|
|
26365
26416
|
}
|
|
26366
26417
|
function describeExpectedPresetValue(schema) {
|
|
@@ -26444,9 +26495,9 @@ async function loadPresetValues(fields, presetPath) {
|
|
|
26444
26495
|
}
|
|
26445
26496
|
const fieldByPath = new Map(fields.map((field) => [field.displayPath, field]));
|
|
26446
26497
|
const presetValues = {};
|
|
26447
|
-
function visitObject(current,
|
|
26498
|
+
function visitObject(current, path55) {
|
|
26448
26499
|
for (const [key, value] of Object.entries(current)) {
|
|
26449
|
-
const nextPath = [...
|
|
26500
|
+
const nextPath = [...path55, key];
|
|
26450
26501
|
const displayPath = toDisplayPath3(nextPath);
|
|
26451
26502
|
const field = fieldByPath.get(displayPath);
|
|
26452
26503
|
if (field !== void 0) {
|
|
@@ -26851,7 +26902,7 @@ async function executeCommand(state, services, requirementOptions) {
|
|
|
26851
26902
|
message: "Proceed?",
|
|
26852
26903
|
initialValue: true
|
|
26853
26904
|
});
|
|
26854
|
-
if (
|
|
26905
|
+
if (q(proceed)) {
|
|
26855
26906
|
cancel("Operation cancelled.");
|
|
26856
26907
|
throw new UserError("Operation cancelled.");
|
|
26857
26908
|
}
|
|
@@ -27060,7 +27111,7 @@ function createCliContainer(dependencies) {
|
|
|
27060
27111
|
checkAuth: async (apiKey) => await checkAuth({ apiKey }) !== null,
|
|
27061
27112
|
confirm: async (message2) => {
|
|
27062
27113
|
const result = await confirm2({ message: message2 });
|
|
27063
|
-
if (
|
|
27114
|
+
if (q(result)) {
|
|
27064
27115
|
cancel("Operation cancelled.");
|
|
27065
27116
|
throw new OperationCancelledError();
|
|
27066
27117
|
}
|
|
@@ -27557,13 +27608,19 @@ var init_agent2 = __esm({
|
|
|
27557
27608
|
});
|
|
27558
27609
|
|
|
27559
27610
|
// src/cli/commands/spawn.ts
|
|
27611
|
+
import path43 from "node:path";
|
|
27560
27612
|
import { Option as Option2 } from "commander";
|
|
27561
27613
|
function registerSpawnCommand(program, container, options = {}) {
|
|
27562
27614
|
const spawnServices = container.registry.list().filter((service) => typeof service.spawn === "function" || getSpawnConfig(service.name));
|
|
27563
27615
|
const extraServices = options.extraServices ?? [];
|
|
27564
27616
|
const serviceList = listSpawnServiceNames(spawnServices, extraServices);
|
|
27565
27617
|
const serviceDescription = `Agent to spawn${formatServiceList(serviceList)}`;
|
|
27566
|
-
program.command("spawn").alias("s").description("Run a single prompt through a configured agent CLI.").option("--model <model>", "Model identifier override passed to the agent CLI").option("-C, --cwd <path>", "Working directory or workspace locator for the agent CLI").option("--stdin", "Read the prompt from stdin").option("-i, --interactive", "Launch the agent in interactive TUI mode").option("--mode <mode>", "Permission mode: yolo | edit | read (default: yolo)").option(
|
|
27618
|
+
program.command("spawn").alias("s").description("Run a single prompt through a configured agent CLI.").option("--model <model>", "Model identifier override passed to the agent CLI").option("-C, --cwd <path>", "Working directory or workspace locator for the agent CLI").option("--stdin", "Read the prompt from stdin").option("-i, --interactive", "Launch the agent in interactive TUI mode").option("--mode <mode>", "Permission mode: yolo | edit | read (default: yolo)").option(
|
|
27619
|
+
"--mcp-servers <json|@file>",
|
|
27620
|
+
"MCP server config JSON (or @path/to/file.json): {name: {command, args?, env?}}"
|
|
27621
|
+
).addOption(
|
|
27622
|
+
new Option2("--mcp-config <json|@file>", "[deprecated: use --mcp-servers]").hideHelp()
|
|
27623
|
+
).option("--log-dir <path>", "Directory override for ACP JSONL spawn logs").option(
|
|
27567
27624
|
"--activity-timeout-ms <ms>",
|
|
27568
27625
|
"Kill the agent after N ms of inactivity",
|
|
27569
27626
|
(value) => parsePositiveInt(value, "--activity-timeout-ms")
|
|
@@ -27571,7 +27628,9 @@ function registerSpawnCommand(program, container, options = {}) {
|
|
|
27571
27628
|
const flags = resolveCommandFlags(program);
|
|
27572
27629
|
const commandOptions = this.opts();
|
|
27573
27630
|
const shouldEmitUiOutput = resolveOutputFormat() !== "json";
|
|
27574
|
-
const
|
|
27631
|
+
const rawMcpInput = commandOptions.mcpServers ?? commandOptions.mcpConfig;
|
|
27632
|
+
const mcpInput = await resolveMcpSpawnInput(rawMcpInput, container.fs, container.env.cwd);
|
|
27633
|
+
const mcpServers = parseMcpSpawnConfig2(mcpInput);
|
|
27575
27634
|
const wantsStdinFlag = commandOptions.stdin === true;
|
|
27576
27635
|
const shouldReadFromStdin = wantsStdinFlag || promptText === "-" || !promptText && !process.stdin.isTTY;
|
|
27577
27636
|
const forwardedArgs = wantsStdinFlag ? [...promptText ? [promptText] : [], ...agentArgs] : agentArgs;
|
|
@@ -27814,11 +27873,31 @@ async function confirmUnconfiguredService(container, service, label, flags) {
|
|
|
27814
27873
|
const shouldProceed = await confirm2({
|
|
27815
27874
|
message: `${label} is not configured via poe. Do you want to proceed?`
|
|
27816
27875
|
});
|
|
27817
|
-
if (
|
|
27876
|
+
if (q(shouldProceed)) {
|
|
27818
27877
|
throw new OperationCancelledError();
|
|
27819
27878
|
}
|
|
27820
27879
|
return shouldProceed === true;
|
|
27821
27880
|
}
|
|
27881
|
+
async function resolveMcpSpawnInput(input, fs3, baseDir) {
|
|
27882
|
+
if (!input) {
|
|
27883
|
+
return void 0;
|
|
27884
|
+
}
|
|
27885
|
+
if (!input.startsWith("@")) {
|
|
27886
|
+
return input;
|
|
27887
|
+
}
|
|
27888
|
+
const rawPath = input.slice(1);
|
|
27889
|
+
if (rawPath.length === 0) {
|
|
27890
|
+
throw new ValidationError("--mcp-servers @<path> requires a file path after '@'");
|
|
27891
|
+
}
|
|
27892
|
+
const filePath = path43.isAbsolute(rawPath) ? rawPath : path43.join(baseDir, rawPath);
|
|
27893
|
+
try {
|
|
27894
|
+
return await fs3.readFile(filePath, "utf8");
|
|
27895
|
+
} catch (error2) {
|
|
27896
|
+
throw new ValidationError(
|
|
27897
|
+
`--mcp-servers could not read file "${filePath}": ${error2.message}`
|
|
27898
|
+
);
|
|
27899
|
+
}
|
|
27900
|
+
}
|
|
27822
27901
|
function parseMcpSpawnConfig2(input) {
|
|
27823
27902
|
if (!input) {
|
|
27824
27903
|
return void 0;
|
|
@@ -28554,7 +28633,7 @@ function registerUtilsCommand(program, container) {
|
|
|
28554
28633
|
const utils = program.command("utils").description("Utility commands for inspecting and managing poe-code.").addHelpCommand(false);
|
|
28555
28634
|
registerConfigCommand(utils, container);
|
|
28556
28635
|
}
|
|
28557
|
-
var
|
|
28636
|
+
var init_utils4 = __esm({
|
|
28558
28637
|
"src/cli/commands/utils.ts"() {
|
|
28559
28638
|
"use strict";
|
|
28560
28639
|
init_config4();
|
|
@@ -28757,7 +28836,7 @@ var init_media_download = __esm({
|
|
|
28757
28836
|
});
|
|
28758
28837
|
|
|
28759
28838
|
// src/cli/commands/generate.ts
|
|
28760
|
-
import
|
|
28839
|
+
import path44 from "node:path";
|
|
28761
28840
|
function registerGenerateCommand(program, container) {
|
|
28762
28841
|
const generate2 = program.command("generate").alias("g").description("Generate content via Poe API.").option("--model <model>", `Model identifier (default: ${DEFAULT_TEXT_MODEL})`).option(
|
|
28763
28842
|
"--param <key=value>",
|
|
@@ -29030,11 +29109,11 @@ function getDefaultMimeType(type) {
|
|
|
29030
29109
|
return defaults[type];
|
|
29031
29110
|
}
|
|
29032
29111
|
function resolveOutputPath(filename, cwd) {
|
|
29033
|
-
if (
|
|
29112
|
+
if (path44.isAbsolute(filename)) {
|
|
29034
29113
|
return { path: filename, label: filename };
|
|
29035
29114
|
}
|
|
29036
29115
|
return {
|
|
29037
|
-
path:
|
|
29116
|
+
path: path44.join(cwd, filename),
|
|
29038
29117
|
label: `./${filename}`
|
|
29039
29118
|
};
|
|
29040
29119
|
}
|
|
@@ -29082,6 +29161,7 @@ var init_types5 = __esm({
|
|
|
29082
29161
|
this.code = code;
|
|
29083
29162
|
this.name = "ToolError";
|
|
29084
29163
|
}
|
|
29164
|
+
code;
|
|
29085
29165
|
};
|
|
29086
29166
|
}
|
|
29087
29167
|
});
|
|
@@ -29257,6 +29337,8 @@ var init_image = __esm({
|
|
|
29257
29337
|
this.base64Data = base64Data;
|
|
29258
29338
|
this.mimeType = mimeType;
|
|
29259
29339
|
}
|
|
29340
|
+
base64Data;
|
|
29341
|
+
mimeType;
|
|
29260
29342
|
static async fromUrl(url) {
|
|
29261
29343
|
const response = await fetch(url);
|
|
29262
29344
|
if (!response.ok) {
|
|
@@ -29331,6 +29413,8 @@ var init_audio = __esm({
|
|
|
29331
29413
|
this.base64Data = base64Data;
|
|
29332
29414
|
this.mimeType = mimeType;
|
|
29333
29415
|
}
|
|
29416
|
+
base64Data;
|
|
29417
|
+
mimeType;
|
|
29334
29418
|
static async fromUrl(url) {
|
|
29335
29419
|
const response = await fetch(url);
|
|
29336
29420
|
if (!response.ok) {
|
|
@@ -29401,6 +29485,10 @@ var init_file = __esm({
|
|
|
29401
29485
|
this.isText = isText;
|
|
29402
29486
|
this.name = name;
|
|
29403
29487
|
}
|
|
29488
|
+
data;
|
|
29489
|
+
mimeType;
|
|
29490
|
+
isText;
|
|
29491
|
+
name;
|
|
29404
29492
|
static async fromUrl(url) {
|
|
29405
29493
|
const response = await fetch(url);
|
|
29406
29494
|
if (!response.ok) {
|
|
@@ -30411,10 +30499,10 @@ var init_shapes = __esm({
|
|
|
30411
30499
|
});
|
|
30412
30500
|
|
|
30413
30501
|
// packages/agent-mcp-config/src/apply.ts
|
|
30414
|
-
import
|
|
30502
|
+
import path45 from "node:path";
|
|
30415
30503
|
import { parse as parseYaml3, stringify as stringifyYaml2 } from "yaml";
|
|
30416
30504
|
function getConfigDirectory(configPath) {
|
|
30417
|
-
return
|
|
30505
|
+
return path45.dirname(configPath);
|
|
30418
30506
|
}
|
|
30419
30507
|
function isConfigObject6(value) {
|
|
30420
30508
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
@@ -30434,9 +30522,9 @@ function expandHomePath(configPath, homeDir) {
|
|
|
30434
30522
|
return homeDir;
|
|
30435
30523
|
}
|
|
30436
30524
|
if (configPath.startsWith("~/")) {
|
|
30437
|
-
return
|
|
30525
|
+
return path45.join(homeDir, configPath.slice(2));
|
|
30438
30526
|
}
|
|
30439
|
-
return
|
|
30527
|
+
return path45.join(homeDir, configPath.slice(1));
|
|
30440
30528
|
}
|
|
30441
30529
|
function parseYamlDocument2(content) {
|
|
30442
30530
|
if (content.trim() === "") {
|
|
@@ -30469,7 +30557,7 @@ async function writeYamlConfig(configPath, document, options) {
|
|
|
30469
30557
|
return;
|
|
30470
30558
|
}
|
|
30471
30559
|
const absolutePath = expandHomePath(configPath, options.homeDir);
|
|
30472
|
-
const configDir =
|
|
30560
|
+
const configDir = path45.dirname(absolutePath);
|
|
30473
30561
|
await options.fs.mkdir(configDir, { recursive: true });
|
|
30474
30562
|
await options.fs.writeFile(absolutePath, serializeYamlDocument(document), {
|
|
30475
30563
|
encoding: "utf8"
|
|
@@ -30678,7 +30766,7 @@ ${formatMcpToolsDocs()}`).action(async (options) => {
|
|
|
30678
30766
|
message: "Select agent to configure:",
|
|
30679
30767
|
options: supportedAgents.map((a) => ({ value: a, label: a }))
|
|
30680
30768
|
});
|
|
30681
|
-
if (
|
|
30769
|
+
if (q(selected)) {
|
|
30682
30770
|
cancel("Operation cancelled");
|
|
30683
30771
|
return;
|
|
30684
30772
|
}
|
|
@@ -30793,7 +30881,7 @@ var init_mcp2 = __esm({
|
|
|
30793
30881
|
|
|
30794
30882
|
// packages/agent-skill-config/src/configs.ts
|
|
30795
30883
|
import os4 from "node:os";
|
|
30796
|
-
import
|
|
30884
|
+
import path46 from "node:path";
|
|
30797
30885
|
function resolveAgentSupport2(input, registry = agentSkillConfigs) {
|
|
30798
30886
|
const resolvedId = resolveAgentId(input);
|
|
30799
30887
|
if (!resolvedId) {
|
|
@@ -31032,7 +31120,7 @@ function registerSkillCommand(program, container) {
|
|
|
31032
31120
|
message: "Select agent to configure:",
|
|
31033
31121
|
options: supportedAgents2.map((a) => ({ value: a, label: a }))
|
|
31034
31122
|
});
|
|
31035
|
-
if (
|
|
31123
|
+
if (q(selected)) {
|
|
31036
31124
|
cancel("Operation cancelled");
|
|
31037
31125
|
return;
|
|
31038
31126
|
}
|
|
@@ -31065,7 +31153,7 @@ function registerSkillCommand(program, container) {
|
|
|
31065
31153
|
{ value: "local", label: "Local" }
|
|
31066
31154
|
]
|
|
31067
31155
|
});
|
|
31068
|
-
if (
|
|
31156
|
+
if (q(selected)) {
|
|
31069
31157
|
cancel("Operation cancelled");
|
|
31070
31158
|
return;
|
|
31071
31159
|
}
|
|
@@ -31111,7 +31199,7 @@ function registerSkillCommand(program, container) {
|
|
|
31111
31199
|
message: "Select agent to unconfigure:",
|
|
31112
31200
|
options: supportedAgents2.map((a) => ({ value: a, label: a }))
|
|
31113
31201
|
});
|
|
31114
|
-
if (
|
|
31202
|
+
if (q(selected)) {
|
|
31115
31203
|
cancel("Operation cancelled");
|
|
31116
31204
|
return;
|
|
31117
31205
|
}
|
|
@@ -31141,7 +31229,7 @@ function registerSkillCommand(program, container) {
|
|
|
31141
31229
|
{ value: "local", label: "Local" }
|
|
31142
31230
|
]
|
|
31143
31231
|
});
|
|
31144
|
-
if (
|
|
31232
|
+
if (q(selected)) {
|
|
31145
31233
|
cancel("Operation cancelled");
|
|
31146
31234
|
return;
|
|
31147
31235
|
}
|
|
@@ -31504,7 +31592,7 @@ function registerUsageCommand(program, container) {
|
|
|
31504
31592
|
startingAfter = result.data[result.data.length - 1].query_id;
|
|
31505
31593
|
if (maxPages === void 0) {
|
|
31506
31594
|
const shouldContinue = await confirm2({ message: "Load more?" });
|
|
31507
|
-
if (
|
|
31595
|
+
if (q(shouldContinue)) {
|
|
31508
31596
|
throw new OperationCancelledError();
|
|
31509
31597
|
}
|
|
31510
31598
|
if (!shouldContinue) {
|
|
@@ -31880,7 +31968,7 @@ var init_models2 = __esm({
|
|
|
31880
31968
|
});
|
|
31881
31969
|
|
|
31882
31970
|
// src/cli/commands/pipeline.ts
|
|
31883
|
-
import
|
|
31971
|
+
import path47 from "node:path";
|
|
31884
31972
|
import { readFile as readFile13, stat as stat12 } from "node:fs/promises";
|
|
31885
31973
|
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
31886
31974
|
async function resolvePipelinePlanDirectory(container) {
|
|
@@ -31937,11 +32025,11 @@ function formatRunSummary(result) {
|
|
|
31937
32025
|
].join("\n ");
|
|
31938
32026
|
}
|
|
31939
32027
|
function resolvePipelinePaths(scope, cwd, homeDir) {
|
|
31940
|
-
const rootPath = scope === "global" ?
|
|
32028
|
+
const rootPath = scope === "global" ? path47.join(homeDir, ".poe-code", "pipeline") : path47.join(cwd, ".poe-code", "pipeline");
|
|
31941
32029
|
const displayRoot = scope === "global" ? "~/.poe-code/pipeline" : ".poe-code/pipeline";
|
|
31942
32030
|
return {
|
|
31943
|
-
plansPath:
|
|
31944
|
-
stepsPath:
|
|
32031
|
+
plansPath: path47.join(rootPath, "plans"),
|
|
32032
|
+
stepsPath: path47.join(rootPath, "steps.yaml"),
|
|
31945
32033
|
displayPlansPath: `${displayRoot}/plans`,
|
|
31946
32034
|
displayStepsPath: `${displayRoot}/steps.yaml`
|
|
31947
32035
|
};
|
|
@@ -31952,16 +32040,16 @@ async function loadPipelineTemplates() {
|
|
|
31952
32040
|
}
|
|
31953
32041
|
const packageRoot = await findPackageRoot(fileURLToPath7(import.meta.url));
|
|
31954
32042
|
const templateRoots = [
|
|
31955
|
-
|
|
31956
|
-
|
|
32043
|
+
path47.join(packageRoot, "src", "templates", "pipeline"),
|
|
32044
|
+
path47.join(packageRoot, "dist", "templates", "pipeline")
|
|
31957
32045
|
];
|
|
31958
32046
|
for (const templateRoot of templateRoots) {
|
|
31959
32047
|
if (!await pathExistsOnDisk(templateRoot)) {
|
|
31960
32048
|
continue;
|
|
31961
32049
|
}
|
|
31962
32050
|
const [skillPlan, steps] = await Promise.all([
|
|
31963
|
-
readFile13(
|
|
31964
|
-
readFile13(
|
|
32051
|
+
readFile13(path47.join(templateRoot, "SKILL_plan.md"), "utf8"),
|
|
32052
|
+
readFile13(path47.join(templateRoot, "steps.yaml.mustache"), "utf8")
|
|
31965
32053
|
]);
|
|
31966
32054
|
pipelineTemplatesCache = { skillPlan, steps };
|
|
31967
32055
|
return pipelineTemplatesCache;
|
|
@@ -31980,12 +32068,12 @@ async function pathExistsOnDisk(targetPath) {
|
|
|
31980
32068
|
}
|
|
31981
32069
|
}
|
|
31982
32070
|
async function findPackageRoot(entryFilePath) {
|
|
31983
|
-
let currentPath =
|
|
32071
|
+
let currentPath = path47.dirname(entryFilePath);
|
|
31984
32072
|
while (true) {
|
|
31985
|
-
if (await pathExistsOnDisk(
|
|
32073
|
+
if (await pathExistsOnDisk(path47.join(currentPath, "package.json"))) {
|
|
31986
32074
|
return currentPath;
|
|
31987
32075
|
}
|
|
31988
|
-
const parentPath =
|
|
32076
|
+
const parentPath = path47.dirname(currentPath);
|
|
31989
32077
|
if (parentPath === currentPath) {
|
|
31990
32078
|
throw new Error("Unable to locate package root for Pipeline templates.");
|
|
31991
32079
|
}
|
|
@@ -32028,7 +32116,7 @@ function registerPipelineCommand(program, container) {
|
|
|
32028
32116
|
label: value
|
|
32029
32117
|
}))
|
|
32030
32118
|
});
|
|
32031
|
-
if (
|
|
32119
|
+
if (q(selected)) {
|
|
32032
32120
|
cancel("Pipeline run cancelled.");
|
|
32033
32121
|
return;
|
|
32034
32122
|
}
|
|
@@ -32049,7 +32137,7 @@ function registerPipelineCommand(program, container) {
|
|
|
32049
32137
|
fs: container.fs,
|
|
32050
32138
|
selectPlans: async (input) => {
|
|
32051
32139
|
const selected = await multiselect2(input);
|
|
32052
|
-
if (
|
|
32140
|
+
if (q(selected)) {
|
|
32053
32141
|
cancel("Pipeline run cancelled.");
|
|
32054
32142
|
return null;
|
|
32055
32143
|
}
|
|
@@ -32057,7 +32145,7 @@ function registerPipelineCommand(program, container) {
|
|
|
32057
32145
|
},
|
|
32058
32146
|
promptForPath: async (input) => {
|
|
32059
32147
|
const value = await text3(input);
|
|
32060
|
-
if (
|
|
32148
|
+
if (q(value)) {
|
|
32061
32149
|
cancel("Pipeline run cancelled.");
|
|
32062
32150
|
return null;
|
|
32063
32151
|
}
|
|
@@ -32267,7 +32355,7 @@ function registerPipelineCommand(program, container) {
|
|
|
32267
32355
|
label: value
|
|
32268
32356
|
}))
|
|
32269
32357
|
});
|
|
32270
|
-
if (
|
|
32358
|
+
if (q(selected)) {
|
|
32271
32359
|
cancel("Pipeline install cancelled.");
|
|
32272
32360
|
return;
|
|
32273
32361
|
}
|
|
@@ -32293,7 +32381,7 @@ function registerPipelineCommand(program, container) {
|
|
|
32293
32381
|
{ value: "global", label: "Global" }
|
|
32294
32382
|
]
|
|
32295
32383
|
});
|
|
32296
|
-
if (
|
|
32384
|
+
if (q(selected)) {
|
|
32297
32385
|
cancel("Pipeline install cancelled.");
|
|
32298
32386
|
return;
|
|
32299
32387
|
}
|
|
@@ -32343,7 +32431,7 @@ function registerPipelineCommand(program, container) {
|
|
|
32343
32431
|
`Would ${stepsExists ? "overwrite" : "create"}: ${pipelinePaths.displayStepsPath}`
|
|
32344
32432
|
);
|
|
32345
32433
|
} else {
|
|
32346
|
-
await container.fs.mkdir(
|
|
32434
|
+
await container.fs.mkdir(path47.dirname(pipelinePaths.stepsPath), {
|
|
32347
32435
|
recursive: true
|
|
32348
32436
|
});
|
|
32349
32437
|
await container.fs.writeFile(pipelinePaths.stepsPath, templates2.steps, {
|
|
@@ -32382,7 +32470,7 @@ var init_pipeline3 = __esm({
|
|
|
32382
32470
|
});
|
|
32383
32471
|
|
|
32384
32472
|
// packages/plan-browser/src/format.ts
|
|
32385
|
-
import
|
|
32473
|
+
import path48 from "node:path";
|
|
32386
32474
|
function isPipelineTaskDone(task) {
|
|
32387
32475
|
if (typeof task.status === "string") {
|
|
32388
32476
|
return task.status === "done";
|
|
@@ -32472,9 +32560,9 @@ function formatPipelinePlanMarkdown(options) {
|
|
|
32472
32560
|
return lines.join("\n").trimEnd();
|
|
32473
32561
|
}
|
|
32474
32562
|
function resolveExperimentJournalPath(absolutePath) {
|
|
32475
|
-
return
|
|
32476
|
-
|
|
32477
|
-
`${
|
|
32563
|
+
return path48.join(
|
|
32564
|
+
path48.dirname(absolutePath),
|
|
32565
|
+
`${path48.basename(absolutePath, path48.extname(absolutePath))}.journal.jsonl`
|
|
32478
32566
|
);
|
|
32479
32567
|
}
|
|
32480
32568
|
async function readExperimentState(fs3, absolutePath) {
|
|
@@ -32497,7 +32585,7 @@ async function loadPlanPreviewMarkdown(entry, fs3) {
|
|
|
32497
32585
|
}
|
|
32498
32586
|
async function readPlanMetadata(options) {
|
|
32499
32587
|
const content = await options.fs.readFile(options.absolutePath, "utf8");
|
|
32500
|
-
const fallbackName =
|
|
32588
|
+
const fallbackName = path48.basename(options.path);
|
|
32501
32589
|
if (options.source === "pipeline") {
|
|
32502
32590
|
return {
|
|
32503
32591
|
title: fallbackName,
|
|
@@ -32531,7 +32619,7 @@ var init_format = __esm({
|
|
|
32531
32619
|
});
|
|
32532
32620
|
|
|
32533
32621
|
// packages/plan-browser/src/discovery.ts
|
|
32534
|
-
import
|
|
32622
|
+
import path49 from "node:path";
|
|
32535
32623
|
import * as fsPromises11 from "node:fs/promises";
|
|
32536
32624
|
function createDefaultFs9() {
|
|
32537
32625
|
return {
|
|
@@ -32558,15 +32646,15 @@ function isNotFound5(error2) {
|
|
|
32558
32646
|
}
|
|
32559
32647
|
function resolveAbsoluteDirectory2(dir, cwd, homeDir) {
|
|
32560
32648
|
if (dir.startsWith("~/")) {
|
|
32561
|
-
return
|
|
32649
|
+
return path49.join(homeDir, dir.slice(2));
|
|
32562
32650
|
}
|
|
32563
|
-
return
|
|
32651
|
+
return path49.isAbsolute(dir) ? dir : path49.resolve(cwd, dir);
|
|
32564
32652
|
}
|
|
32565
32653
|
function resolveAbsoluteDisplayPath(displayPath, cwd, homeDir) {
|
|
32566
32654
|
if (displayPath.startsWith("~/")) {
|
|
32567
|
-
return
|
|
32655
|
+
return path49.join(homeDir, displayPath.slice(2));
|
|
32568
32656
|
}
|
|
32569
|
-
return
|
|
32657
|
+
return path49.isAbsolute(displayPath) ? displayPath : path49.resolve(cwd, displayPath);
|
|
32570
32658
|
}
|
|
32571
32659
|
function isPipelinePlanFile(name) {
|
|
32572
32660
|
const lower = name.toLowerCase();
|
|
@@ -32603,12 +32691,12 @@ async function scanDirectory(options) {
|
|
|
32603
32691
|
if (!options.include(name)) {
|
|
32604
32692
|
continue;
|
|
32605
32693
|
}
|
|
32606
|
-
const absolutePath =
|
|
32694
|
+
const absolutePath = path49.join(options.absoluteDir, name);
|
|
32607
32695
|
const stat15 = await options.fs.stat(absolutePath);
|
|
32608
32696
|
if (!stat15.isFile()) {
|
|
32609
32697
|
continue;
|
|
32610
32698
|
}
|
|
32611
|
-
const displayPath =
|
|
32699
|
+
const displayPath = path49.join(options.displayDir, name);
|
|
32612
32700
|
const metadata = await readPlanMetadata({
|
|
32613
32701
|
source: options.source,
|
|
32614
32702
|
absolutePath,
|
|
@@ -32641,11 +32729,11 @@ async function discoverPipelinePlans(options) {
|
|
|
32641
32729
|
displayDir: configuredDir
|
|
32642
32730
|
}] : [
|
|
32643
32731
|
{
|
|
32644
|
-
absoluteDir:
|
|
32732
|
+
absoluteDir: path49.join(options.cwd, ".poe-code", "pipeline", "plans"),
|
|
32645
32733
|
displayDir: ".poe-code/pipeline/plans"
|
|
32646
32734
|
},
|
|
32647
32735
|
{
|
|
32648
|
-
absoluteDir:
|
|
32736
|
+
absoluteDir: path49.join(options.homeDir, ".poe-code", "pipeline", "plans"),
|
|
32649
32737
|
displayDir: "~/.poe-code/pipeline/plans"
|
|
32650
32738
|
}
|
|
32651
32739
|
];
|
|
@@ -32677,11 +32765,11 @@ async function discoverExperimentPlans(options) {
|
|
|
32677
32765
|
displayDir: configuredDir
|
|
32678
32766
|
}] : [
|
|
32679
32767
|
{
|
|
32680
|
-
absoluteDir:
|
|
32768
|
+
absoluteDir: path49.join(options.cwd, ".poe-code", "experiments"),
|
|
32681
32769
|
displayDir: ".poe-code/experiments"
|
|
32682
32770
|
},
|
|
32683
32771
|
{
|
|
32684
|
-
absoluteDir:
|
|
32772
|
+
absoluteDir: path49.join(options.homeDir, ".poe-code", "experiments"),
|
|
32685
32773
|
displayDir: "~/.poe-code/experiments"
|
|
32686
32774
|
}
|
|
32687
32775
|
];
|
|
@@ -32779,7 +32867,7 @@ var init_discovery4 = __esm({
|
|
|
32779
32867
|
});
|
|
32780
32868
|
|
|
32781
32869
|
// packages/plan-browser/src/actions.ts
|
|
32782
|
-
import
|
|
32870
|
+
import path50 from "node:path";
|
|
32783
32871
|
import { spawnSync as nodeSpawnSync } from "node:child_process";
|
|
32784
32872
|
function resolveEditor2(env = process.env) {
|
|
32785
32873
|
const editor = env.EDITOR?.trim() || env.VISUAL?.trim() || "vi";
|
|
@@ -32791,8 +32879,8 @@ function editPlan(absolutePath, options = {}) {
|
|
|
32791
32879
|
spawnSync3(editor, [absolutePath], { stdio: "inherit" });
|
|
32792
32880
|
}
|
|
32793
32881
|
async function archivePlan3(entry, fs3) {
|
|
32794
|
-
const archiveDir =
|
|
32795
|
-
const archivedPath =
|
|
32882
|
+
const archiveDir = path50.join(path50.dirname(entry.absolutePath), "archive");
|
|
32883
|
+
const archivedPath = path50.join(archiveDir, path50.basename(entry.absolutePath));
|
|
32796
32884
|
await fs3.mkdir(archiveDir, { recursive: true });
|
|
32797
32885
|
await fs3.rename(entry.absolutePath, archivedPath);
|
|
32798
32886
|
return archivedPath;
|
|
@@ -32807,7 +32895,7 @@ var init_actions = __esm({
|
|
|
32807
32895
|
});
|
|
32808
32896
|
|
|
32809
32897
|
// packages/plan-browser/src/browser.ts
|
|
32810
|
-
import
|
|
32898
|
+
import path51 from "node:path";
|
|
32811
32899
|
async function runPlanBrowser(options) {
|
|
32812
32900
|
const renderPlanPreview = async (entry) => {
|
|
32813
32901
|
const markdown = await loadPlanPreviewMarkdown(entry, options.fs);
|
|
@@ -32836,12 +32924,12 @@ async function runPlanBrowser(options) {
|
|
|
32836
32924
|
const selectedPath = await select2({
|
|
32837
32925
|
message: "Select a plan",
|
|
32838
32926
|
options: plans.map((plan) => ({
|
|
32839
|
-
label: text.selectLabel(
|
|
32927
|
+
label: text.selectLabel(path51.basename(plan.path), plan.status),
|
|
32840
32928
|
hint: plan.source,
|
|
32841
32929
|
value: plan.absolutePath
|
|
32842
32930
|
}))
|
|
32843
32931
|
});
|
|
32844
|
-
if (
|
|
32932
|
+
if (q(selectedPath)) {
|
|
32845
32933
|
return;
|
|
32846
32934
|
}
|
|
32847
32935
|
const selectedPlan = plans.find((plan) => plan.absolutePath === selectedPath);
|
|
@@ -32860,7 +32948,7 @@ async function runPlanBrowser(options) {
|
|
|
32860
32948
|
{ label: "Delete", value: "delete" }
|
|
32861
32949
|
]
|
|
32862
32950
|
});
|
|
32863
|
-
if (
|
|
32951
|
+
if (q(action) || action === "back") {
|
|
32864
32952
|
continue;
|
|
32865
32953
|
}
|
|
32866
32954
|
if (action === "edit") {
|
|
@@ -32872,7 +32960,7 @@ async function runPlanBrowser(options) {
|
|
|
32872
32960
|
if (action === "archive") {
|
|
32873
32961
|
try {
|
|
32874
32962
|
const confirmed = options.assumeYes || await confirmOrCancel({
|
|
32875
|
-
message: `Archive ${
|
|
32963
|
+
message: `Archive ${path51.basename(selectedPlan.path)}?`,
|
|
32876
32964
|
initialValue: true
|
|
32877
32965
|
});
|
|
32878
32966
|
if (confirmed) {
|
|
@@ -32887,7 +32975,7 @@ async function runPlanBrowser(options) {
|
|
|
32887
32975
|
}
|
|
32888
32976
|
try {
|
|
32889
32977
|
const confirmed = options.assumeYes || await confirmOrCancel({
|
|
32890
|
-
message: `Permanently delete ${
|
|
32978
|
+
message: `Permanently delete ${path51.basename(selectedPlan.path)}?`,
|
|
32891
32979
|
initialValue: true
|
|
32892
32980
|
});
|
|
32893
32981
|
if (confirmed) {
|
|
@@ -32923,7 +33011,7 @@ var init_src25 = __esm({
|
|
|
32923
33011
|
});
|
|
32924
33012
|
|
|
32925
33013
|
// src/cli/commands/plan.ts
|
|
32926
|
-
import
|
|
33014
|
+
import path52 from "node:path";
|
|
32927
33015
|
function resolvePlanCommandOptions(command) {
|
|
32928
33016
|
const localOptions = command.opts();
|
|
32929
33017
|
const parentOptions = command.parent?.opts() ?? {};
|
|
@@ -32974,7 +33062,7 @@ async function discoverPlans(container, source) {
|
|
|
32974
33062
|
async function resolveSelectedPlan(options) {
|
|
32975
33063
|
const providedPath = options.providedPath?.trim();
|
|
32976
33064
|
if (providedPath) {
|
|
32977
|
-
const resolvedAbsolute = providedPath.startsWith("~/") ?
|
|
33065
|
+
const resolvedAbsolute = providedPath.startsWith("~/") ? path52.join(options.container.env.homeDir, providedPath.slice(2)) : path52.isAbsolute(providedPath) ? providedPath : path52.resolve(options.container.env.cwd, providedPath);
|
|
32978
33066
|
const matched2 = options.plans.find(
|
|
32979
33067
|
(plan) => plan.path === providedPath || plan.absolutePath === providedPath || plan.absolutePath === resolvedAbsolute
|
|
32980
33068
|
);
|
|
@@ -32992,12 +33080,12 @@ async function resolveSelectedPlan(options) {
|
|
|
32992
33080
|
const selected = await select2({
|
|
32993
33081
|
message: options.promptMessage,
|
|
32994
33082
|
options: options.plans.map((plan) => ({
|
|
32995
|
-
label: text.selectLabel(
|
|
33083
|
+
label: text.selectLabel(path52.basename(plan.path), plan.status),
|
|
32996
33084
|
hint: plan.source,
|
|
32997
33085
|
value: plan.absolutePath
|
|
32998
33086
|
}))
|
|
32999
33087
|
});
|
|
33000
|
-
if (
|
|
33088
|
+
if (q(selected)) {
|
|
33001
33089
|
throw new ValidationError("Plan selection cancelled.");
|
|
33002
33090
|
}
|
|
33003
33091
|
const matched = options.plans.find((plan) => plan.absolutePath === selected);
|
|
@@ -33028,7 +33116,7 @@ async function renderPlanList(container, options) {
|
|
|
33028
33116
|
JSON.stringify(
|
|
33029
33117
|
plans.map((plan) => ({
|
|
33030
33118
|
source: plan.source,
|
|
33031
|
-
name:
|
|
33119
|
+
name: path52.basename(plan.path),
|
|
33032
33120
|
path: plan.path,
|
|
33033
33121
|
detail: plan.status,
|
|
33034
33122
|
updated: formatDate2(plan.updatedAt)
|
|
@@ -33051,7 +33139,7 @@ async function renderPlanList(container, options) {
|
|
|
33051
33139
|
],
|
|
33052
33140
|
rows: plans.map((plan) => ({
|
|
33053
33141
|
source: plan.source,
|
|
33054
|
-
name:
|
|
33142
|
+
name: path52.basename(plan.path),
|
|
33055
33143
|
detail: plan.status,
|
|
33056
33144
|
updated: formatDate2(plan.updatedAt)
|
|
33057
33145
|
}))
|
|
@@ -33083,7 +33171,7 @@ async function executePlanAction(options) {
|
|
|
33083
33171
|
}
|
|
33084
33172
|
if (!flags.assumeYes) {
|
|
33085
33173
|
const confirmed = await confirmOrCancel({
|
|
33086
|
-
message: options.action === "archive" ? `Archive ${
|
|
33174
|
+
message: options.action === "archive" ? `Archive ${path52.basename(plan.path)}?` : `Permanently delete ${path52.basename(plan.path)}?`,
|
|
33087
33175
|
initialValue: true
|
|
33088
33176
|
});
|
|
33089
33177
|
if (!confirmed) {
|
|
@@ -33203,7 +33291,7 @@ var init_plan = __esm({
|
|
|
33203
33291
|
});
|
|
33204
33292
|
|
|
33205
33293
|
// src/cli/commands/ralph.ts
|
|
33206
|
-
import
|
|
33294
|
+
import path53 from "node:path";
|
|
33207
33295
|
function formatDuration2(ms) {
|
|
33208
33296
|
const totalSeconds = Math.round(ms / 1e3);
|
|
33209
33297
|
const minutes = Math.floor(totalSeconds / 60);
|
|
@@ -33239,9 +33327,9 @@ function normalizeConfiguredIterations(value) {
|
|
|
33239
33327
|
}
|
|
33240
33328
|
function resolveAbsoluteDocPath(container, docPath) {
|
|
33241
33329
|
if (docPath.startsWith("~/")) {
|
|
33242
|
-
return
|
|
33330
|
+
return path53.join(container.env.homeDir, docPath.slice(2));
|
|
33243
33331
|
}
|
|
33244
|
-
return
|
|
33332
|
+
return path53.isAbsolute(docPath) ? docPath : path53.resolve(container.env.cwd, docPath);
|
|
33245
33333
|
}
|
|
33246
33334
|
async function resolvePlanDirectory2(container) {
|
|
33247
33335
|
const configDoc = await readMergedDocument(
|
|
@@ -33312,7 +33400,7 @@ async function resolveDocPath(options) {
|
|
|
33312
33400
|
value: doc.path
|
|
33313
33401
|
}))
|
|
33314
33402
|
});
|
|
33315
|
-
if (
|
|
33403
|
+
if (q(selected)) {
|
|
33316
33404
|
cancel("Ralph run cancelled.");
|
|
33317
33405
|
return null;
|
|
33318
33406
|
}
|
|
@@ -33356,7 +33444,7 @@ async function promptForAgent(program) {
|
|
|
33356
33444
|
value: config.agentId
|
|
33357
33445
|
}))
|
|
33358
33446
|
});
|
|
33359
|
-
if (
|
|
33447
|
+
if (q(selected)) {
|
|
33360
33448
|
cancel("Ralph run cancelled.");
|
|
33361
33449
|
return null;
|
|
33362
33450
|
}
|
|
@@ -33393,7 +33481,7 @@ async function resolveRunIterations(options) {
|
|
|
33393
33481
|
const entered = await text3({
|
|
33394
33482
|
message: "How many Ralph iterations should run?"
|
|
33395
33483
|
});
|
|
33396
|
-
if (
|
|
33484
|
+
if (q(entered)) {
|
|
33397
33485
|
cancel("Ralph run cancelled.");
|
|
33398
33486
|
return null;
|
|
33399
33487
|
}
|
|
@@ -33423,7 +33511,7 @@ async function resolveInitIterations(options) {
|
|
|
33423
33511
|
const entered = await text3({
|
|
33424
33512
|
message: "How many Ralph iterations should run?"
|
|
33425
33513
|
});
|
|
33426
|
-
if (
|
|
33514
|
+
if (q(entered)) {
|
|
33427
33515
|
cancel("Ralph init cancelled.");
|
|
33428
33516
|
return null;
|
|
33429
33517
|
}
|
|
@@ -33612,11 +33700,11 @@ var init_ralph3 = __esm({
|
|
|
33612
33700
|
});
|
|
33613
33701
|
|
|
33614
33702
|
// src/cli/commands/experiment.ts
|
|
33615
|
-
import
|
|
33703
|
+
import path54 from "node:path";
|
|
33616
33704
|
import { readFile as readFile15, stat as stat14 } from "node:fs/promises";
|
|
33617
33705
|
import { fileURLToPath as fileURLToPath8 } from "node:url";
|
|
33618
33706
|
function resolveExperimentPaths(scope, cwd, homeDir) {
|
|
33619
|
-
const rootPath = scope === "global" ?
|
|
33707
|
+
const rootPath = scope === "global" ? path54.join(homeDir, ".poe-code", "experiments") : path54.join(cwd, ".poe-code", "experiments");
|
|
33620
33708
|
const displayRoot = scope === "global" ? "~/.poe-code/experiments" : ".poe-code/experiments";
|
|
33621
33709
|
return {
|
|
33622
33710
|
experimentsPath: rootPath,
|
|
@@ -33635,12 +33723,12 @@ async function pathExistsOnDisk2(targetPath) {
|
|
|
33635
33723
|
}
|
|
33636
33724
|
}
|
|
33637
33725
|
async function findPackageRoot2(entryFilePath) {
|
|
33638
|
-
let currentPath =
|
|
33726
|
+
let currentPath = path54.dirname(entryFilePath);
|
|
33639
33727
|
while (true) {
|
|
33640
|
-
if (await pathExistsOnDisk2(
|
|
33728
|
+
if (await pathExistsOnDisk2(path54.join(currentPath, "package.json"))) {
|
|
33641
33729
|
return currentPath;
|
|
33642
33730
|
}
|
|
33643
|
-
const parentPath =
|
|
33731
|
+
const parentPath = path54.dirname(currentPath);
|
|
33644
33732
|
if (parentPath === currentPath) {
|
|
33645
33733
|
throw new Error("Unable to locate package root for Experiment templates.");
|
|
33646
33734
|
}
|
|
@@ -33653,16 +33741,16 @@ async function loadExperimentTemplates() {
|
|
|
33653
33741
|
}
|
|
33654
33742
|
const packageRoot = await findPackageRoot2(fileURLToPath8(import.meta.url));
|
|
33655
33743
|
const templateRoots = [
|
|
33656
|
-
|
|
33657
|
-
|
|
33744
|
+
path54.join(packageRoot, "src", "templates", "experiment"),
|
|
33745
|
+
path54.join(packageRoot, "dist", "templates", "experiment")
|
|
33658
33746
|
];
|
|
33659
33747
|
for (const templateRoot of templateRoots) {
|
|
33660
33748
|
if (!await pathExistsOnDisk2(templateRoot)) {
|
|
33661
33749
|
continue;
|
|
33662
33750
|
}
|
|
33663
33751
|
const [skillPlan, runYaml] = await Promise.all([
|
|
33664
|
-
readFile15(
|
|
33665
|
-
readFile15(
|
|
33752
|
+
readFile15(path54.join(templateRoot, "SKILL_experiment.md"), "utf8"),
|
|
33753
|
+
readFile15(path54.join(templateRoot, "run.yaml.mustache"), "utf8")
|
|
33666
33754
|
]);
|
|
33667
33755
|
experimentTemplatesCache = { skillPlan, runYaml };
|
|
33668
33756
|
return experimentTemplatesCache;
|
|
@@ -33773,7 +33861,7 @@ async function resolveDocPath2(options) {
|
|
|
33773
33861
|
value: doc.path
|
|
33774
33862
|
}))
|
|
33775
33863
|
});
|
|
33776
|
-
if (
|
|
33864
|
+
if (q(selected)) {
|
|
33777
33865
|
cancel(options.cancelMessage);
|
|
33778
33866
|
return null;
|
|
33779
33867
|
}
|
|
@@ -33803,7 +33891,7 @@ async function promptForAgent2(program) {
|
|
|
33803
33891
|
value: config.agentId
|
|
33804
33892
|
}))
|
|
33805
33893
|
});
|
|
33806
|
-
if (
|
|
33894
|
+
if (q(selected)) {
|
|
33807
33895
|
cancel("Experiment run cancelled.");
|
|
33808
33896
|
return null;
|
|
33809
33897
|
}
|
|
@@ -33893,7 +33981,7 @@ function registerExperimentCommand(program, container) {
|
|
|
33893
33981
|
resources.logger.info(` Reset to ${targetHash.slice(0, 7)}`);
|
|
33894
33982
|
},
|
|
33895
33983
|
onExperimentComplete(index, entry) {
|
|
33896
|
-
const scores = entry.scores ? Object.entries(entry.scores).map(([
|
|
33984
|
+
const scores = entry.scores ? Object.entries(entry.scores).map(([k, v]) => `${k}=${v}`).join(", ") : "-";
|
|
33897
33985
|
resources.logger.info(
|
|
33898
33986
|
`Experiment ${index} ${entry.status} in ${formatDuration3(entry.durationMs)} \xB7 scores: ${scores}`
|
|
33899
33987
|
);
|
|
@@ -33953,7 +34041,7 @@ function registerExperimentCommand(program, container) {
|
|
|
33953
34041
|
const rows = entries.map((entry, index) => ({
|
|
33954
34042
|
index: String(index + 1),
|
|
33955
34043
|
status: entry.status,
|
|
33956
|
-
scores: entry.scores ? Object.entries(entry.scores).map(([
|
|
34044
|
+
scores: entry.scores ? Object.entries(entry.scores).map(([k, v]) => `${k}=${v}`).join(", ") : "-",
|
|
33957
34045
|
duration: formatDuration3(entry.durationMs),
|
|
33958
34046
|
timestamp: entry.timestamp,
|
|
33959
34047
|
commit: entry.commit,
|
|
@@ -34092,7 +34180,7 @@ function registerExperimentCommand(program, container) {
|
|
|
34092
34180
|
label: value
|
|
34093
34181
|
}))
|
|
34094
34182
|
});
|
|
34095
|
-
if (
|
|
34183
|
+
if (q(selected)) {
|
|
34096
34184
|
cancel("Experiment install cancelled.");
|
|
34097
34185
|
return;
|
|
34098
34186
|
}
|
|
@@ -34118,7 +34206,7 @@ function registerExperimentCommand(program, container) {
|
|
|
34118
34206
|
{ value: "global", label: "Global" }
|
|
34119
34207
|
]
|
|
34120
34208
|
});
|
|
34121
|
-
if (
|
|
34209
|
+
if (q(selected)) {
|
|
34122
34210
|
cancel("Experiment install cancelled.");
|
|
34123
34211
|
return;
|
|
34124
34212
|
}
|
|
@@ -34164,8 +34252,8 @@ function registerExperimentCommand(program, container) {
|
|
|
34164
34252
|
);
|
|
34165
34253
|
}
|
|
34166
34254
|
}
|
|
34167
|
-
const runYamlPath =
|
|
34168
|
-
const runYamlDisplayPath =
|
|
34255
|
+
const runYamlPath = path54.join(experimentPaths.experimentsPath, "run.yaml");
|
|
34256
|
+
const runYamlDisplayPath = path54.join(experimentPaths.displayExperimentsPath, "run.yaml");
|
|
34169
34257
|
if (!await pathExists4(container.fs, runYamlPath)) {
|
|
34170
34258
|
if (flags.dryRun) {
|
|
34171
34259
|
resources.logger.dryRun(`Would create: ${runYamlDisplayPath}`);
|
|
@@ -34374,7 +34462,7 @@ async function resolveProcessId(value) {
|
|
|
34374
34462
|
const entered = await text3({
|
|
34375
34463
|
message: "Process ID"
|
|
34376
34464
|
});
|
|
34377
|
-
if (
|
|
34465
|
+
if (q(entered)) {
|
|
34378
34466
|
cancel("Launch start cancelled.");
|
|
34379
34467
|
return null;
|
|
34380
34468
|
}
|
|
@@ -34391,7 +34479,7 @@ async function resolveCommandParts(commandArgs) {
|
|
|
34391
34479
|
const entered = await text3({
|
|
34392
34480
|
message: "Command to run"
|
|
34393
34481
|
});
|
|
34394
|
-
if (
|
|
34482
|
+
if (q(entered)) {
|
|
34395
34483
|
cancel("Launch start cancelled.");
|
|
34396
34484
|
return null;
|
|
34397
34485
|
}
|
|
@@ -34415,7 +34503,7 @@ async function resolveRuntime(options) {
|
|
|
34415
34503
|
{ label: "docker", value: "docker" }
|
|
34416
34504
|
]
|
|
34417
34505
|
});
|
|
34418
|
-
if (
|
|
34506
|
+
if (q(selected)) {
|
|
34419
34507
|
cancel("Launch start cancelled.");
|
|
34420
34508
|
return null;
|
|
34421
34509
|
}
|
|
@@ -34428,7 +34516,7 @@ async function resolveDockerImage(value) {
|
|
|
34428
34516
|
const entered = await text3({
|
|
34429
34517
|
message: "Docker image"
|
|
34430
34518
|
});
|
|
34431
|
-
if (
|
|
34519
|
+
if (q(entered)) {
|
|
34432
34520
|
cancel("Launch start cancelled.");
|
|
34433
34521
|
return null;
|
|
34434
34522
|
}
|
|
@@ -34453,7 +34541,7 @@ async function resolveRestart(restart, assumeYes) {
|
|
|
34453
34541
|
{ label: "always", value: "always" }
|
|
34454
34542
|
]
|
|
34455
34543
|
});
|
|
34456
|
-
if (
|
|
34544
|
+
if (q(selected)) {
|
|
34457
34545
|
cancel("Launch start cancelled.");
|
|
34458
34546
|
return null;
|
|
34459
34547
|
}
|
|
@@ -34631,7 +34719,7 @@ var init_package = __esm({
|
|
|
34631
34719
|
"package.json"() {
|
|
34632
34720
|
package_default = {
|
|
34633
34721
|
name: "poe-code",
|
|
34634
|
-
version: "3.0.
|
|
34722
|
+
version: "3.0.176",
|
|
34635
34723
|
description: "CLI tool to configure Poe API for developer workflows.",
|
|
34636
34724
|
type: "module",
|
|
34637
34725
|
main: "./dist/index.js",
|
|
@@ -34831,22 +34919,22 @@ function formatCommandHeader(cmd) {
|
|
|
34831
34919
|
}
|
|
34832
34920
|
return `Poe - ${parts.reverse().join(" ")}`;
|
|
34833
34921
|
}
|
|
34834
|
-
function findCommandByPath(root,
|
|
34922
|
+
function findCommandByPath(root, path55) {
|
|
34835
34923
|
let current = root;
|
|
34836
|
-
for (const segment of
|
|
34924
|
+
for (const segment of path55) {
|
|
34837
34925
|
const next = current.commands.find(
|
|
34838
34926
|
(command) => Reflect.get(command, "_hidden") !== true && command.name() === segment
|
|
34839
34927
|
);
|
|
34840
34928
|
if (!next) {
|
|
34841
|
-
throw new Error(`Root help command is missing: ${
|
|
34929
|
+
throw new Error(`Root help command is missing: ${path55.join(" ")}`);
|
|
34842
34930
|
}
|
|
34843
34931
|
current = next;
|
|
34844
34932
|
}
|
|
34845
34933
|
return current;
|
|
34846
34934
|
}
|
|
34847
|
-
function formatRootHelpCommandName(
|
|
34935
|
+
function formatRootHelpCommandName(path55, command) {
|
|
34848
34936
|
const leaf = [command.name(), ...command.aliases()].join(", ");
|
|
34849
|
-
return
|
|
34937
|
+
return path55.length > 1 ? [...path55.slice(0, -1), leaf].join(" ") : leaf;
|
|
34850
34938
|
}
|
|
34851
34939
|
function splitUsageParts(usage) {
|
|
34852
34940
|
return usage.split(" ").map((part) => part.trim()).filter((part) => part.length > 0);
|
|
@@ -35125,7 +35213,7 @@ var init_program = __esm({
|
|
|
35125
35213
|
init_login();
|
|
35126
35214
|
init_logout();
|
|
35127
35215
|
init_auth();
|
|
35128
|
-
|
|
35216
|
+
init_utils4();
|
|
35129
35217
|
init_install();
|
|
35130
35218
|
init_unconfigure();
|
|
35131
35219
|
init_test();
|
|
@@ -35200,7 +35288,7 @@ function createPromptRunner(adapter = {
|
|
|
35200
35288
|
text: text3,
|
|
35201
35289
|
password: password2,
|
|
35202
35290
|
select: select2,
|
|
35203
|
-
isCancel:
|
|
35291
|
+
isCancel: q,
|
|
35204
35292
|
cancel
|
|
35205
35293
|
}) {
|
|
35206
35294
|
const runPrompt = async (descriptor) => {
|