@aiden-ade/sandbox-agent 0.1.0 → 0.1.2
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/dist/index.cjs +126 -14
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -900,9 +900,9 @@ var require_browser = __commonJS({
|
|
|
900
900
|
}
|
|
901
901
|
});
|
|
902
902
|
|
|
903
|
-
// ../../node_modules
|
|
903
|
+
// ../../node_modules/has-flag/index.js
|
|
904
904
|
var require_has_flag = __commonJS({
|
|
905
|
-
"../../node_modules
|
|
905
|
+
"../../node_modules/has-flag/index.js"(exports2, module2) {
|
|
906
906
|
"use strict";
|
|
907
907
|
module2.exports = (flag, argv = process.argv) => {
|
|
908
908
|
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
@@ -913,9 +913,9 @@ var require_has_flag = __commonJS({
|
|
|
913
913
|
}
|
|
914
914
|
});
|
|
915
915
|
|
|
916
|
-
// ../../node_modules
|
|
916
|
+
// ../../node_modules/supports-color/index.js
|
|
917
917
|
var require_supports_color = __commonJS({
|
|
918
|
-
"../../node_modules
|
|
918
|
+
"../../node_modules/supports-color/index.js"(exports2, module2) {
|
|
919
919
|
"use strict";
|
|
920
920
|
var os = require("os");
|
|
921
921
|
var tty = require("tty");
|
|
@@ -5264,7 +5264,7 @@ function parseCodexStructuredLine(line, context, state) {
|
|
|
5264
5264
|
break;
|
|
5265
5265
|
}
|
|
5266
5266
|
case "error": {
|
|
5267
|
-
const message = extractCodexErrorMessage(parsed.message);
|
|
5267
|
+
const message = extractCodexErrorMessage(parsed.message) || extractCodexErrorMessage(parsed.error) || typeof parsed.detail === "string" && parsed.detail.trim() || "";
|
|
5268
5268
|
if (message) {
|
|
5269
5269
|
state.error = message;
|
|
5270
5270
|
}
|
|
@@ -5272,7 +5272,7 @@ function parseCodexStructuredLine(line, context, state) {
|
|
|
5272
5272
|
}
|
|
5273
5273
|
case "turn.failed": {
|
|
5274
5274
|
const error = typeof parsed.error === "object" && parsed.error !== null ? parsed.error : {};
|
|
5275
|
-
const message = extractCodexErrorMessage(error.message);
|
|
5275
|
+
const message = extractCodexErrorMessage(error.message) || extractCodexErrorMessage(error.detail) || typeof parsed.message === "string" && parsed.message.trim() || "";
|
|
5276
5276
|
if (message) {
|
|
5277
5277
|
state.error = message;
|
|
5278
5278
|
}
|
|
@@ -5355,7 +5355,8 @@ function parseGeminiStructuredLine(line, context, state) {
|
|
|
5355
5355
|
break;
|
|
5356
5356
|
}
|
|
5357
5357
|
case "error": {
|
|
5358
|
-
const
|
|
5358
|
+
const errObj = typeof parsed.error === "object" && parsed.error !== null ? parsed.error : null;
|
|
5359
|
+
const message = typeof parsed.message === "string" && parsed.message.trim() || errObj && typeof errObj.message === "string" && errObj.message.trim() || typeof parsed.error === "string" && parsed.error.trim() || typeof parsed.error_message === "string" && parsed.error_message.trim() || "";
|
|
5359
5360
|
const severity = typeof parsed.severity === "string" ? parsed.severity : "error";
|
|
5360
5361
|
if (message) {
|
|
5361
5362
|
void presenter.onLog(`[gemini_cli/${severity}] ${message}`);
|
|
@@ -5386,7 +5387,15 @@ function parseGeminiStructuredLine(line, context, state) {
|
|
|
5386
5387
|
cacheCreationTokens: state.usage.cacheCreationTokens
|
|
5387
5388
|
});
|
|
5388
5389
|
if (typeof parsed.status === "string" && parsed.status !== "success" && !state.error) {
|
|
5389
|
-
|
|
5390
|
+
const errObj = typeof parsed.error === "object" && parsed.error !== null ? parsed.error : null;
|
|
5391
|
+
const errMsg = typeof parsed.error === "string" && parsed.error.trim() || errObj && typeof errObj.message === "string" && errObj.message.trim() || typeof parsed.error_message === "string" && parsed.error_message.trim() || typeof parsed.message === "string" && parsed.message.trim() || typeof parsed.result === "string" && parsed.result.trim() || parsed.status;
|
|
5392
|
+
state.error = errMsg;
|
|
5393
|
+
console.error("[gemini_cli] result status=", parsed.status, "error fields:", JSON.stringify({
|
|
5394
|
+
error: parsed.error,
|
|
5395
|
+
error_message: parsed.error_message,
|
|
5396
|
+
message: parsed.message,
|
|
5397
|
+
result: typeof parsed.result === "string" ? parsed.result.slice(0, 200) : parsed.result
|
|
5398
|
+
}));
|
|
5390
5399
|
}
|
|
5391
5400
|
break;
|
|
5392
5401
|
}
|
|
@@ -5472,6 +5481,100 @@ function createGeminiCliBackend(command = "gemini", defaultArgs = []) {
|
|
|
5472
5481
|
parseStructuredLine: parseGeminiStructuredLine
|
|
5473
5482
|
});
|
|
5474
5483
|
}
|
|
5484
|
+
function parseOpencodeStructuredLine(line, context, state) {
|
|
5485
|
+
const presenter = context.presenter;
|
|
5486
|
+
let parsed = null;
|
|
5487
|
+
try {
|
|
5488
|
+
parsed = JSON.parse(line);
|
|
5489
|
+
} catch {
|
|
5490
|
+
if (line.trim().length > 0) {
|
|
5491
|
+
state.summary += `${line}
|
|
5492
|
+
`;
|
|
5493
|
+
void presenter.onAssistantText(`${line}
|
|
5494
|
+
`);
|
|
5495
|
+
}
|
|
5496
|
+
return;
|
|
5497
|
+
}
|
|
5498
|
+
const type = typeof parsed.type === "string" ? parsed.type : "";
|
|
5499
|
+
if (!type) return;
|
|
5500
|
+
const sessionID = typeof parsed.sessionID === "string" ? parsed.sessionID : void 0;
|
|
5501
|
+
if (sessionID) {
|
|
5502
|
+
state.runtimeSessionId = sessionID;
|
|
5503
|
+
}
|
|
5504
|
+
const part = typeof parsed.part === "object" && parsed.part !== null ? parsed.part : null;
|
|
5505
|
+
switch (type) {
|
|
5506
|
+
case "step_start": {
|
|
5507
|
+
state.iterations += 1;
|
|
5508
|
+
void presenter.onLog(`[opencode] Step ${state.iterations} started`);
|
|
5509
|
+
break;
|
|
5510
|
+
}
|
|
5511
|
+
case "text": {
|
|
5512
|
+
const text = part && typeof part.text === "string" ? part.text : "";
|
|
5513
|
+
if (text) {
|
|
5514
|
+
state.summary += text;
|
|
5515
|
+
void presenter.onAssistantText(text);
|
|
5516
|
+
}
|
|
5517
|
+
break;
|
|
5518
|
+
}
|
|
5519
|
+
case "tool_use":
|
|
5520
|
+
case "tool.execute": {
|
|
5521
|
+
const toolName = part && typeof part.name === "string" ? part.name : "OpenCode Tool";
|
|
5522
|
+
const toolId = part && typeof part.id === "string" ? part.id : `opencode-tool-${Date.now()}`;
|
|
5523
|
+
void presenter.onToolUse(toolName, part ?? {}, toolId);
|
|
5524
|
+
break;
|
|
5525
|
+
}
|
|
5526
|
+
case "tool_result":
|
|
5527
|
+
case "tool.result": {
|
|
5528
|
+
const toolId = part && typeof part.id === "string" ? part.id : `opencode-tool-${Date.now()}`;
|
|
5529
|
+
const output = part && typeof part.output === "string" ? part.output : JSON.stringify(part);
|
|
5530
|
+
void presenter.onToolResult?.(toolId, output);
|
|
5531
|
+
break;
|
|
5532
|
+
}
|
|
5533
|
+
case "step_finish": {
|
|
5534
|
+
if (part && typeof part.tokens === "object" && part.tokens !== null) {
|
|
5535
|
+
const tokens = part.tokens;
|
|
5536
|
+
state.usage = {
|
|
5537
|
+
inputTokens: tokens.input ?? 0,
|
|
5538
|
+
outputTokens: tokens.output ?? 0
|
|
5539
|
+
};
|
|
5540
|
+
}
|
|
5541
|
+
break;
|
|
5542
|
+
}
|
|
5543
|
+
case "session.error":
|
|
5544
|
+
case "error": {
|
|
5545
|
+
const errObj = typeof parsed.error === "object" && parsed.error !== null ? parsed.error : null;
|
|
5546
|
+
const message = typeof parsed.message === "string" && parsed.message.trim() || part && typeof part.message === "string" && part.message.trim() || typeof parsed.error === "string" && parsed.error.trim() || errObj && typeof errObj.message === "string" && errObj.message.trim() || part && typeof part.error === "string" && part.error.trim() || "";
|
|
5547
|
+
if (message) {
|
|
5548
|
+
void presenter.onLog(`[opencode/error] ${message}`);
|
|
5549
|
+
state.error = message;
|
|
5550
|
+
}
|
|
5551
|
+
break;
|
|
5552
|
+
}
|
|
5553
|
+
default:
|
|
5554
|
+
break;
|
|
5555
|
+
}
|
|
5556
|
+
}
|
|
5557
|
+
function createOpencodeCliBackend(command = "opencode", defaultArgs = []) {
|
|
5558
|
+
return createGenericCliBackend({
|
|
5559
|
+
kind: "opencode_cli",
|
|
5560
|
+
supportTier: "structured",
|
|
5561
|
+
command,
|
|
5562
|
+
args: [],
|
|
5563
|
+
buildArgs: (context, prompt) => {
|
|
5564
|
+
const args = ["run", "--format", "json"];
|
|
5565
|
+
const resumeId = context.config.runtimeSessionId?.trim() || context.config.providerSessionId?.trim();
|
|
5566
|
+
if (resumeId) args.push("--session", resumeId);
|
|
5567
|
+
const model2 = context.config.selectedModel?.trim();
|
|
5568
|
+
if (model2 && model2.includes("/")) args.push("--model", model2);
|
|
5569
|
+
return [...args, ...defaultArgs, prompt];
|
|
5570
|
+
},
|
|
5571
|
+
augmentPrompt: (context) => {
|
|
5572
|
+
const base = buildPromptWithSystem(context.config, context.promptText);
|
|
5573
|
+
return context.config.mode === "plan" ? buildPlanModePrefix(base) : base;
|
|
5574
|
+
},
|
|
5575
|
+
parseStructuredLine: parseOpencodeStructuredLine
|
|
5576
|
+
});
|
|
5577
|
+
}
|
|
5475
5578
|
function createGenericCliPassthroughBackend(command, defaultArgs = []) {
|
|
5476
5579
|
return createGenericCliBackend({
|
|
5477
5580
|
kind: "generic_cli",
|
|
@@ -5582,6 +5685,7 @@ var CoreAgent = class {
|
|
|
5582
5685
|
case "claude_cli":
|
|
5583
5686
|
case "codex_app_server":
|
|
5584
5687
|
case "gemini_cli":
|
|
5688
|
+
case "opencode_cli":
|
|
5585
5689
|
return "structured";
|
|
5586
5690
|
case "generic_cli":
|
|
5587
5691
|
default:
|
|
@@ -5642,7 +5746,7 @@ var CoreAgent = class {
|
|
|
5642
5746
|
const env = this.buildCliEnvironment();
|
|
5643
5747
|
const runtimeCommand = runtimeConfig.runtimeCommand || this.runtime.runtimeCommand;
|
|
5644
5748
|
const runtimeArgs = runtimeConfig.runtimeArgs || this.runtime.runtimeArgs || [];
|
|
5645
|
-
const backend = backendKind2 === "claude_cli" ? createClaudeCliBackend(runtimeCommand || "claude", runtimeArgs) : backendKind2 === "codex_app_server" ? createCodexRuntimeBackend(runtimeCommand || "codex", runtimeArgs) : backendKind2 === "gemini_cli" ? createGeminiCliBackend(runtimeCommand || "gemini", runtimeArgs) : createGenericCliPassthroughBackend(runtimeCommand || "generic-cli", runtimeArgs);
|
|
5749
|
+
const backend = backendKind2 === "claude_cli" ? createClaudeCliBackend(runtimeCommand || "claude", runtimeArgs) : backendKind2 === "codex_app_server" ? createCodexRuntimeBackend(runtimeCommand || "codex", runtimeArgs) : backendKind2 === "gemini_cli" ? createGeminiCliBackend(runtimeCommand || "gemini", runtimeArgs) : backendKind2 === "opencode_cli" ? createOpencodeCliBackend(runtimeCommand || "opencode", runtimeArgs) : createGenericCliPassthroughBackend(runtimeCommand || "generic-cli", runtimeArgs);
|
|
5646
5750
|
const result = await backend.run({
|
|
5647
5751
|
presenter: this.presenter,
|
|
5648
5752
|
config: runtimeConfig,
|
|
@@ -9398,7 +9502,7 @@ var WSClient = class {
|
|
|
9398
9502
|
console.warn(`[WSClient] Connection error: ${error.message}`);
|
|
9399
9503
|
});
|
|
9400
9504
|
this.socket.on("user_message", (data) => {
|
|
9401
|
-
callbacks.onUserMessage({ text: data.text, providerSessionId: data.providerSessionId });
|
|
9505
|
+
callbacks.onUserMessage({ text: data.text, providerSessionId: data.providerSessionId, backendKind: data.backendKind, selectedModel: data.selectedModel });
|
|
9402
9506
|
});
|
|
9403
9507
|
this.socket.on("stop", () => {
|
|
9404
9508
|
callbacks.onStop();
|
|
@@ -9414,7 +9518,7 @@ var WSClient = class {
|
|
|
9414
9518
|
};
|
|
9415
9519
|
|
|
9416
9520
|
// src/version.ts
|
|
9417
|
-
var AGENT_VERSION = "0.1.
|
|
9521
|
+
var AGENT_VERSION = "0.1.2";
|
|
9418
9522
|
|
|
9419
9523
|
// src/updater.ts
|
|
9420
9524
|
var import_node_child_process2 = require("child_process");
|
|
@@ -9503,6 +9607,8 @@ async function runSandbox(config) {
|
|
|
9503
9607
|
const presenter = new WebPresenter(wsClient, config.sessionId);
|
|
9504
9608
|
presenter.setSuppressSessionLifecycle(true);
|
|
9505
9609
|
let lastProviderSessionId = config.providerSessionId;
|
|
9610
|
+
let activeBackendKind = config.backendKind || "claude_cli";
|
|
9611
|
+
let activeModel = config.model;
|
|
9506
9612
|
while (!stopped) {
|
|
9507
9613
|
if (pendingUpdate) {
|
|
9508
9614
|
await performUpdate(wsClient, pendingUpdate, lastProviderSessionId);
|
|
@@ -9510,7 +9616,7 @@ async function runSandbox(config) {
|
|
|
9510
9616
|
}
|
|
9511
9617
|
if (currentTask?.trim()) {
|
|
9512
9618
|
const agent = new CoreAgent(presenter, {
|
|
9513
|
-
backendKind:
|
|
9619
|
+
backendKind: activeBackendKind
|
|
9514
9620
|
});
|
|
9515
9621
|
currentAgent = agent;
|
|
9516
9622
|
let result;
|
|
@@ -9520,8 +9626,8 @@ async function runSandbox(config) {
|
|
|
9520
9626
|
maxIterations: config.maxIterations || 50,
|
|
9521
9627
|
projectPath: config.projectPath,
|
|
9522
9628
|
cwd: config.projectPath,
|
|
9523
|
-
backendKind:
|
|
9524
|
-
selectedModel:
|
|
9629
|
+
backendKind: activeBackendKind,
|
|
9630
|
+
selectedModel: activeModel,
|
|
9525
9631
|
providerSessionId: lastProviderSessionId ?? void 0
|
|
9526
9632
|
});
|
|
9527
9633
|
} catch (error) {
|
|
@@ -9553,6 +9659,12 @@ async function runSandbox(config) {
|
|
|
9553
9659
|
if (nextPayload.providerSessionId) {
|
|
9554
9660
|
lastProviderSessionId = nextPayload.providerSessionId;
|
|
9555
9661
|
}
|
|
9662
|
+
if (nextPayload.backendKind) {
|
|
9663
|
+
activeBackendKind = nextPayload.backendKind;
|
|
9664
|
+
}
|
|
9665
|
+
if (nextPayload.selectedModel) {
|
|
9666
|
+
activeModel = nextPayload.selectedModel;
|
|
9667
|
+
}
|
|
9556
9668
|
}
|
|
9557
9669
|
presenter.setSuppressSessionLifecycle(false);
|
|
9558
9670
|
wsClient.close();
|