@aiden-ade/sandbox-agent 0.1.5 → 0.1.7

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.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Re-exports from the canonical shared system prompt.
3
+ * Single source of truth: packages/shared/src/agent/system-prompt.ts
4
+ */
5
+ export * from "@aiden/shared/agent";
6
+ //# sourceMappingURL=aiden-system-prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aiden-system-prompt.d.ts","sourceRoot":"","sources":["../src/aiden-system-prompt.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Re-exports from the canonical shared system prompt.
3
+ * Single source of truth: packages/shared/src/agent/system-prompt.ts
4
+ */
5
+ export * from "@aiden/shared/agent";
6
+ //# sourceMappingURL=aiden-system-prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aiden-system-prompt.js","sourceRoot":"","sources":["../src/aiden-system-prompt.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Sandbox CoreAgent — E2B-specific subclass of BaseMachineAgent.
3
+ *
4
+ * Platform responsibilities:
5
+ * - buildCliEnvironment: extend process.env + inject E2B node bin path
6
+ * - buildExtraSystemPromptParts: inject artifact IDs from AIDEN_* env vars
7
+ * - submitAnswer / submitPlanApproval: resolve interactive-tool prompts relayed via WS
8
+ *
9
+ * Everything else (retry loop, system-prompt assembly, backend selection) lives
10
+ * in BaseMachineAgent.
11
+ */
12
+ import { BaseMachineAgent, type AgentRuntimeConfig } from "@aiden/agent-core";
13
+ import type { ChildProcessWithoutNullStreams } from "node:child_process";
14
+ import type { AgentConfig } from "./types.js";
15
+ export declare class CoreAgent extends BaseMachineAgent {
16
+ private childProcess;
17
+ constructor(presenter: ConstructorParameters<typeof BaseMachineAgent>[0], runtime: AgentRuntimeConfig);
18
+ /**
19
+ * Send a new user message to the CLI's stdin (stream-json format).
20
+ * Used during continuation mode when the CLI process is still alive after
21
+ * completing a turn — the message is processed as the next conversation turn
22
+ * without spawning a new subprocess.
23
+ */
24
+ sendUserMessage(text: string, images?: Array<{
25
+ data: string;
26
+ mimeType: string;
27
+ }>): boolean;
28
+ /**
29
+ * Send a tool_result to the CLI's stdin (stream-json format).
30
+ * Used for interactive tools like AskUserQuestion.
31
+ */
32
+ sendToolResponse(toolId: string, response: string): boolean;
33
+ protected getOnProcessSpawned(): ((child: ChildProcessWithoutNullStreams) => void) | undefined;
34
+ protected buildCliEnvironment(): Promise<Record<string, string>>;
35
+ protected buildExtraSystemPromptParts(_config: AgentConfig): string[];
36
+ }
37
+ //# sourceMappingURL=core-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-agent.d.ts","sourceRoot":"","sources":["../src/core-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE9E,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,qBAAa,SAAU,SAAQ,gBAAgB;IAC7C,OAAO,CAAC,YAAY,CAA+C;gBAEvD,SAAS,EAAE,qBAAqB,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,kBAAkB;IAMrG;;;;;OAKG;IACI,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,OAAO;IAgCjG;;;OAGG;IACI,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO;IAgClE,SAAS,CAAC,mBAAmB,IAAI,CAAC,CAAC,KAAK,EAAE,8BAA8B,KAAK,IAAI,CAAC,GAAG,SAAS;cAO9E,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IA0CtE,SAAS,CAAC,2BAA2B,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,EAAE;CActE"}
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Sandbox CoreAgent — E2B-specific subclass of BaseMachineAgent.
3
+ *
4
+ * Platform responsibilities:
5
+ * - buildCliEnvironment: extend process.env + inject E2B node bin path
6
+ * - buildExtraSystemPromptParts: inject artifact IDs from AIDEN_* env vars
7
+ * - submitAnswer / submitPlanApproval: resolve interactive-tool prompts relayed via WS
8
+ *
9
+ * Everything else (retry loop, system-prompt assembly, backend selection) lives
10
+ * in BaseMachineAgent.
11
+ */
12
+ import { BaseMachineAgent } from "@aiden/agent-core";
13
+ import { accessSync, chmodSync, constants as fsConstants, statSync } from "node:fs";
14
+ export class CoreAgent extends BaseMachineAgent {
15
+ childProcess = null;
16
+ constructor(presenter, runtime) {
17
+ super(presenter, runtime);
18
+ }
19
+ // ── Interactive tool response / continuation user message (WS relay → stdin) ──
20
+ /**
21
+ * Send a new user message to the CLI's stdin (stream-json format).
22
+ * Used during continuation mode when the CLI process is still alive after
23
+ * completing a turn — the message is processed as the next conversation turn
24
+ * without spawning a new subprocess.
25
+ */
26
+ sendUserMessage(text, images) {
27
+ if (!this.childProcess)
28
+ return false;
29
+ const stdin = this.childProcess.stdin;
30
+ if (!stdin || stdin.destroyed)
31
+ return false;
32
+ try {
33
+ const contentBlocks = [];
34
+ if (images && images.length > 0) {
35
+ for (const img of images) {
36
+ contentBlocks.push({
37
+ type: "image",
38
+ source: { type: "base64", media_type: img.mimeType, data: img.data },
39
+ });
40
+ }
41
+ }
42
+ contentBlocks.push({ type: "text", text });
43
+ const message = JSON.stringify({
44
+ type: "user",
45
+ message: { role: "user", content: contentBlocks },
46
+ session_id: "default",
47
+ parent_tool_use_id: null,
48
+ });
49
+ stdin.write(message + "\n");
50
+ console.info("[CoreAgent] Sent user message to CLI stdin (continuation mode)");
51
+ return true;
52
+ }
53
+ catch (err) {
54
+ console.error("[CoreAgent] Failed to write user message to stdin", err);
55
+ return false;
56
+ }
57
+ }
58
+ /**
59
+ * Send a tool_result to the CLI's stdin (stream-json format).
60
+ * Used for interactive tools like AskUserQuestion.
61
+ */
62
+ sendToolResponse(toolId, response) {
63
+ if (!this.childProcess)
64
+ return false;
65
+ const stdin = this.childProcess.stdin;
66
+ if (!stdin || stdin.destroyed)
67
+ return false;
68
+ try {
69
+ const message = JSON.stringify({
70
+ type: "user",
71
+ message: {
72
+ role: "user",
73
+ content: [
74
+ {
75
+ type: "tool_result",
76
+ tool_use_id: toolId,
77
+ content: response,
78
+ },
79
+ ],
80
+ },
81
+ session_id: "default",
82
+ parent_tool_use_id: null,
83
+ });
84
+ stdin.write(message + "\n");
85
+ console.info(`[CoreAgent] Sent tool_response for tool ${toolId}`);
86
+ return true;
87
+ }
88
+ catch (err) {
89
+ console.error("[CoreAgent] Failed to write tool_response to stdin", err);
90
+ return false;
91
+ }
92
+ }
93
+ // ── BaseMachineAgent hooks ─────────────────────────────────────────────
94
+ getOnProcessSpawned() {
95
+ return (child) => {
96
+ this.childProcess = child;
97
+ child.on("exit", () => { this.childProcess = null; });
98
+ };
99
+ }
100
+ async buildCliEnvironment() {
101
+ const loginEnv = process.env;
102
+ const env = {};
103
+ for (const [key, value] of Object.entries(loginEnv)) {
104
+ if (value !== undefined)
105
+ env[key] = value;
106
+ }
107
+ // Guarantee CLI runtime bin dirs are in PATH regardless of how the agent
108
+ // was launched. Uses HOME from the inherited env so this works for both
109
+ // E2B (/home/user) and Daytona (/home/daytona) without hardcoding.
110
+ const home = env.HOME ?? "/home/user";
111
+ const extraPaths = [`${home}/.local/node/bin`, `${home}/.local/bin`];
112
+ const basePath = env.PATH ?? "";
113
+ const existingSegments = new Set(basePath.split(":").filter(Boolean));
114
+ const missing = extraPaths.filter((p) => !existingSegments.has(p));
115
+ env.PATH = missing.length > 0 ? `${missing.join(":")}:${basePath}` : basePath;
116
+ // Guard: ensure the CLI runtime binary has its execute bit set.
117
+ // On long-lived sandboxes the file can lose +x (e.g. npm overwrote it
118
+ // without preserving permissions, or a stray chmod was run during setup).
119
+ // We attempt to fix it silently so the agent can always start.
120
+ for (const dir of extraPaths) {
121
+ for (const bin of ["claude", "codex", "gemini"]) {
122
+ const binPath = `${dir}/${bin}`;
123
+ try {
124
+ const stat = statSync(binPath);
125
+ // Check owner-execute bit (0o100). If missing, add +x for owner/group/other.
126
+ if (!(stat.mode & 0o100)) {
127
+ chmodSync(binPath, stat.mode | 0o111);
128
+ console.info(`[CoreAgent] Restored execute permission on ${binPath}`);
129
+ }
130
+ // Verify we can actually execute it now
131
+ accessSync(binPath, fsConstants.X_OK);
132
+ }
133
+ catch {
134
+ // File doesn't exist or chmod failed — not a fatal error, let the
135
+ // backend surface a clear message if this binary is actually needed.
136
+ }
137
+ }
138
+ }
139
+ return env;
140
+ }
141
+ buildExtraSystemPromptParts(_config) {
142
+ const artifactIds = [];
143
+ const envTaskId = process.env.AIDEN_TASK_ID;
144
+ const envSessionId = process.env.AIDEN_SESSION_ID;
145
+ if (envTaskId)
146
+ artifactIds.push(`- taskId: "${envTaskId}"`);
147
+ if (envSessionId)
148
+ artifactIds.push(`- conversationId: "${envSessionId}"`);
149
+ if (artifactIds.length === 0)
150
+ return [];
151
+ return [
152
+ [
153
+ "When creating artifacts using MCP tools (create_plan, create_document_artifact, create_test_report), always pass these IDs:",
154
+ ...artifactIds,
155
+ ].join("\n"),
156
+ ];
157
+ }
158
+ }
159
+ //# sourceMappingURL=core-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-agent.js","sourceRoot":"","sources":["../src/core-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAA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