@aiden-ade/sandbox-agent 0.1.7 → 0.1.9
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/core-agent.d.ts +7 -11
- package/dist/core-agent.d.ts.map +1 -1
- package/dist/core-agent.js +127 -68
- package/dist/core-agent.js.map +1 -1
- package/dist/index.cjs +1500 -206
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/sandbox.d.ts +10 -0
- package/dist/sandbox.d.ts.map +1 -1
- package/dist/sandbox.js +66 -36
- package/dist/sandbox.js.map +1 -1
- package/dist/updater.d.ts +15 -0
- package/dist/updater.d.ts.map +1 -0
- package/dist/updater.js +54 -0
- package/dist/updater.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/web-presenter.d.ts +0 -9
- package/dist/web-presenter.d.ts.map +1 -1
- package/dist/web-presenter.js +4 -24
- package/dist/web-presenter.js.map +1 -1
- package/dist/ws-client.d.ts +45 -0
- package/dist/ws-client.d.ts.map +1 -1
- package/dist/ws-client.js +13 -0
- package/dist/ws-client.js.map +1 -1
- package/package.json +15 -11
- package/dist/aiden-system-prompt.d.ts +0 -6
- package/dist/aiden-system-prompt.d.ts.map +0 -1
- package/dist/aiden-system-prompt.js +0 -6
- package/dist/aiden-system-prompt.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -30,9 +30,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
mod
|
|
31
31
|
));
|
|
32
32
|
|
|
33
|
-
// ../../node_modules
|
|
33
|
+
// ../../node_modules/xmlhttprequest-ssl/lib/XMLHttpRequest.js
|
|
34
34
|
var require_XMLHttpRequest = __commonJS({
|
|
35
|
-
"../../node_modules
|
|
35
|
+
"../../node_modules/xmlhttprequest-ssl/lib/XMLHttpRequest.js"(exports2, module2) {
|
|
36
36
|
"use strict";
|
|
37
37
|
var fs = require("fs");
|
|
38
38
|
var Url = require("url");
|
|
@@ -43,7 +43,7 @@ var require_XMLHttpRequest = __commonJS({
|
|
|
43
43
|
"use strict";
|
|
44
44
|
opts = opts || {};
|
|
45
45
|
var self = this;
|
|
46
|
-
var
|
|
46
|
+
var http2 = require("http");
|
|
47
47
|
var https = require("https");
|
|
48
48
|
var request;
|
|
49
49
|
var response;
|
|
@@ -260,7 +260,7 @@ var require_XMLHttpRequest = __commonJS({
|
|
|
260
260
|
}
|
|
261
261
|
errorFlag = false;
|
|
262
262
|
if (settings.async) {
|
|
263
|
-
var doRequest = ssl ? https.request :
|
|
263
|
+
var doRequest = ssl ? https.request : http2.request;
|
|
264
264
|
sendFlag = true;
|
|
265
265
|
self.dispatchEvent("readystatechange");
|
|
266
266
|
var responseHandler = function(resp2) {
|
|
@@ -434,9 +434,9 @@ var require_XMLHttpRequest = __commonJS({
|
|
|
434
434
|
}
|
|
435
435
|
});
|
|
436
436
|
|
|
437
|
-
// ../../node_modules
|
|
437
|
+
// ../../node_modules/ms/index.js
|
|
438
438
|
var require_ms = __commonJS({
|
|
439
|
-
"../../node_modules
|
|
439
|
+
"../../node_modules/ms/index.js"(exports2, module2) {
|
|
440
440
|
"use strict";
|
|
441
441
|
var s = 1e3;
|
|
442
442
|
var m = s * 60;
|
|
@@ -551,9 +551,9 @@ var require_ms = __commonJS({
|
|
|
551
551
|
}
|
|
552
552
|
});
|
|
553
553
|
|
|
554
|
-
// ../../node_modules
|
|
554
|
+
// ../../node_modules/debug/src/common.js
|
|
555
555
|
var require_common = __commonJS({
|
|
556
|
-
"../../node_modules
|
|
556
|
+
"../../node_modules/debug/src/common.js"(exports2, module2) {
|
|
557
557
|
"use strict";
|
|
558
558
|
function setup(env) {
|
|
559
559
|
createDebug.debug = createDebug;
|
|
@@ -729,9 +729,9 @@ var require_common = __commonJS({
|
|
|
729
729
|
}
|
|
730
730
|
});
|
|
731
731
|
|
|
732
|
-
// ../../node_modules
|
|
732
|
+
// ../../node_modules/debug/src/browser.js
|
|
733
733
|
var require_browser = __commonJS({
|
|
734
|
-
"../../node_modules
|
|
734
|
+
"../../node_modules/debug/src/browser.js"(exports2, module2) {
|
|
735
735
|
"use strict";
|
|
736
736
|
exports2.formatArgs = formatArgs;
|
|
737
737
|
exports2.save = save;
|
|
@@ -1015,9 +1015,9 @@ var require_supports_color = __commonJS({
|
|
|
1015
1015
|
}
|
|
1016
1016
|
});
|
|
1017
1017
|
|
|
1018
|
-
// ../../node_modules
|
|
1018
|
+
// ../../node_modules/debug/src/node.js
|
|
1019
1019
|
var require_node = __commonJS({
|
|
1020
|
-
"../../node_modules
|
|
1020
|
+
"../../node_modules/debug/src/node.js"(exports2, module2) {
|
|
1021
1021
|
"use strict";
|
|
1022
1022
|
var tty = require("tty");
|
|
1023
1023
|
var util = require("util");
|
|
@@ -1190,9 +1190,9 @@ var require_node = __commonJS({
|
|
|
1190
1190
|
}
|
|
1191
1191
|
});
|
|
1192
1192
|
|
|
1193
|
-
// ../../node_modules
|
|
1193
|
+
// ../../node_modules/debug/src/index.js
|
|
1194
1194
|
var require_src = __commonJS({
|
|
1195
|
-
"../../node_modules
|
|
1195
|
+
"../../node_modules/debug/src/index.js"(exports2, module2) {
|
|
1196
1196
|
"use strict";
|
|
1197
1197
|
if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
|
|
1198
1198
|
module2.exports = require_browser();
|
|
@@ -1202,9 +1202,9 @@ var require_src = __commonJS({
|
|
|
1202
1202
|
}
|
|
1203
1203
|
});
|
|
1204
1204
|
|
|
1205
|
-
// ../../node_modules
|
|
1205
|
+
// ../../node_modules/engine.io-client/node_modules/ws/lib/constants.js
|
|
1206
1206
|
var require_constants = __commonJS({
|
|
1207
|
-
"../../node_modules
|
|
1207
|
+
"../../node_modules/engine.io-client/node_modules/ws/lib/constants.js"(exports2, module2) {
|
|
1208
1208
|
"use strict";
|
|
1209
1209
|
var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
|
|
1210
1210
|
var hasBlob = typeof Blob !== "undefined";
|
|
@@ -1224,9 +1224,9 @@ var require_constants = __commonJS({
|
|
|
1224
1224
|
}
|
|
1225
1225
|
});
|
|
1226
1226
|
|
|
1227
|
-
// ../../node_modules
|
|
1227
|
+
// ../../node_modules/engine.io-client/node_modules/ws/lib/buffer-util.js
|
|
1228
1228
|
var require_buffer_util = __commonJS({
|
|
1229
|
-
"../../node_modules
|
|
1229
|
+
"../../node_modules/engine.io-client/node_modules/ws/lib/buffer-util.js"(exports2, module2) {
|
|
1230
1230
|
"use strict";
|
|
1231
1231
|
var { EMPTY_BUFFER } = require_constants();
|
|
1232
1232
|
var FastBuffer = Buffer[Symbol.species];
|
|
@@ -1299,9 +1299,9 @@ var require_buffer_util = __commonJS({
|
|
|
1299
1299
|
}
|
|
1300
1300
|
});
|
|
1301
1301
|
|
|
1302
|
-
// ../../node_modules
|
|
1302
|
+
// ../../node_modules/engine.io-client/node_modules/ws/lib/limiter.js
|
|
1303
1303
|
var require_limiter = __commonJS({
|
|
1304
|
-
"../../node_modules
|
|
1304
|
+
"../../node_modules/engine.io-client/node_modules/ws/lib/limiter.js"(exports2, module2) {
|
|
1305
1305
|
"use strict";
|
|
1306
1306
|
var kDone = /* @__PURE__ */ Symbol("kDone");
|
|
1307
1307
|
var kRun = /* @__PURE__ */ Symbol("kRun");
|
|
@@ -1349,9 +1349,9 @@ var require_limiter = __commonJS({
|
|
|
1349
1349
|
}
|
|
1350
1350
|
});
|
|
1351
1351
|
|
|
1352
|
-
// ../../node_modules
|
|
1352
|
+
// ../../node_modules/engine.io-client/node_modules/ws/lib/permessage-deflate.js
|
|
1353
1353
|
var require_permessage_deflate = __commonJS({
|
|
1354
|
-
"../../node_modules
|
|
1354
|
+
"../../node_modules/engine.io-client/node_modules/ws/lib/permessage-deflate.js"(exports2, module2) {
|
|
1355
1355
|
"use strict";
|
|
1356
1356
|
var zlib = require("zlib");
|
|
1357
1357
|
var bufferUtil = require_buffer_util();
|
|
@@ -1732,9 +1732,9 @@ var require_permessage_deflate = __commonJS({
|
|
|
1732
1732
|
}
|
|
1733
1733
|
});
|
|
1734
1734
|
|
|
1735
|
-
// ../../node_modules
|
|
1735
|
+
// ../../node_modules/engine.io-client/node_modules/ws/lib/validation.js
|
|
1736
1736
|
var require_validation = __commonJS({
|
|
1737
|
-
"../../node_modules
|
|
1737
|
+
"../../node_modules/engine.io-client/node_modules/ws/lib/validation.js"(exports2, module2) {
|
|
1738
1738
|
"use strict";
|
|
1739
1739
|
var { isUtf8 } = require("buffer");
|
|
1740
1740
|
var { hasBlob } = require_constants();
|
|
@@ -1933,9 +1933,9 @@ var require_validation = __commonJS({
|
|
|
1933
1933
|
}
|
|
1934
1934
|
});
|
|
1935
1935
|
|
|
1936
|
-
// ../../node_modules
|
|
1936
|
+
// ../../node_modules/engine.io-client/node_modules/ws/lib/receiver.js
|
|
1937
1937
|
var require_receiver = __commonJS({
|
|
1938
|
-
"../../node_modules
|
|
1938
|
+
"../../node_modules/engine.io-client/node_modules/ws/lib/receiver.js"(exports2, module2) {
|
|
1939
1939
|
"use strict";
|
|
1940
1940
|
var { Writable } = require("stream");
|
|
1941
1941
|
var PerMessageDeflate = require_permessage_deflate();
|
|
@@ -2525,9 +2525,9 @@ var require_receiver = __commonJS({
|
|
|
2525
2525
|
}
|
|
2526
2526
|
});
|
|
2527
2527
|
|
|
2528
|
-
// ../../node_modules
|
|
2528
|
+
// ../../node_modules/engine.io-client/node_modules/ws/lib/sender.js
|
|
2529
2529
|
var require_sender = __commonJS({
|
|
2530
|
-
"../../node_modules
|
|
2530
|
+
"../../node_modules/engine.io-client/node_modules/ws/lib/sender.js"(exports2, module2) {
|
|
2531
2531
|
"use strict";
|
|
2532
2532
|
var { Duplex } = require("stream");
|
|
2533
2533
|
var { randomFillSync } = require("crypto");
|
|
@@ -3013,9 +3013,9 @@ var require_sender = __commonJS({
|
|
|
3013
3013
|
}
|
|
3014
3014
|
});
|
|
3015
3015
|
|
|
3016
|
-
// ../../node_modules
|
|
3016
|
+
// ../../node_modules/engine.io-client/node_modules/ws/lib/event-target.js
|
|
3017
3017
|
var require_event_target = __commonJS({
|
|
3018
|
-
"../../node_modules
|
|
3018
|
+
"../../node_modules/engine.io-client/node_modules/ws/lib/event-target.js"(exports2, module2) {
|
|
3019
3019
|
"use strict";
|
|
3020
3020
|
var { kForOnEventAttribute, kListener } = require_constants();
|
|
3021
3021
|
var kCode = /* @__PURE__ */ Symbol("kCode");
|
|
@@ -3242,9 +3242,9 @@ var require_event_target = __commonJS({
|
|
|
3242
3242
|
}
|
|
3243
3243
|
});
|
|
3244
3244
|
|
|
3245
|
-
// ../../node_modules
|
|
3245
|
+
// ../../node_modules/engine.io-client/node_modules/ws/lib/extension.js
|
|
3246
3246
|
var require_extension = __commonJS({
|
|
3247
|
-
"../../node_modules
|
|
3247
|
+
"../../node_modules/engine.io-client/node_modules/ws/lib/extension.js"(exports2, module2) {
|
|
3248
3248
|
"use strict";
|
|
3249
3249
|
var { tokenChars } = require_validation();
|
|
3250
3250
|
function push(dest, name, elem) {
|
|
@@ -3395,16 +3395,16 @@ var require_extension = __commonJS({
|
|
|
3395
3395
|
}
|
|
3396
3396
|
});
|
|
3397
3397
|
|
|
3398
|
-
// ../../node_modules
|
|
3398
|
+
// ../../node_modules/engine.io-client/node_modules/ws/lib/websocket.js
|
|
3399
3399
|
var require_websocket = __commonJS({
|
|
3400
|
-
"../../node_modules
|
|
3400
|
+
"../../node_modules/engine.io-client/node_modules/ws/lib/websocket.js"(exports2, module2) {
|
|
3401
3401
|
"use strict";
|
|
3402
3402
|
var EventEmitter = require("events");
|
|
3403
3403
|
var https = require("https");
|
|
3404
|
-
var
|
|
3404
|
+
var http2 = require("http");
|
|
3405
3405
|
var net = require("net");
|
|
3406
3406
|
var tls = require("tls");
|
|
3407
|
-
var { randomBytes, createHash: createHash2 } = require("crypto");
|
|
3407
|
+
var { randomBytes: randomBytes2, createHash: createHash2 } = require("crypto");
|
|
3408
3408
|
var { Duplex, Readable } = require("stream");
|
|
3409
3409
|
var { URL } = require("url");
|
|
3410
3410
|
var PerMessageDeflate = require_permessage_deflate();
|
|
@@ -3931,8 +3931,8 @@ var require_websocket = __commonJS({
|
|
|
3931
3931
|
}
|
|
3932
3932
|
}
|
|
3933
3933
|
const defaultPort = isSecure ? 443 : 80;
|
|
3934
|
-
const key =
|
|
3935
|
-
const request = isSecure ? https.request :
|
|
3934
|
+
const key = randomBytes2(16).toString("base64");
|
|
3935
|
+
const request = isSecure ? https.request : http2.request;
|
|
3936
3936
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
3937
3937
|
let perMessageDeflate;
|
|
3938
3938
|
opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
|
|
@@ -4278,9 +4278,9 @@ var require_websocket = __commonJS({
|
|
|
4278
4278
|
}
|
|
4279
4279
|
});
|
|
4280
4280
|
|
|
4281
|
-
// ../../node_modules
|
|
4281
|
+
// ../../node_modules/engine.io-client/node_modules/ws/lib/stream.js
|
|
4282
4282
|
var require_stream = __commonJS({
|
|
4283
|
-
"../../node_modules
|
|
4283
|
+
"../../node_modules/engine.io-client/node_modules/ws/lib/stream.js"(exports2, module2) {
|
|
4284
4284
|
"use strict";
|
|
4285
4285
|
var WebSocket2 = require_websocket();
|
|
4286
4286
|
var { Duplex } = require("stream");
|
|
@@ -4376,9 +4376,9 @@ var require_stream = __commonJS({
|
|
|
4376
4376
|
}
|
|
4377
4377
|
});
|
|
4378
4378
|
|
|
4379
|
-
// ../../node_modules
|
|
4379
|
+
// ../../node_modules/engine.io-client/node_modules/ws/lib/subprotocol.js
|
|
4380
4380
|
var require_subprotocol = __commonJS({
|
|
4381
|
-
"../../node_modules
|
|
4381
|
+
"../../node_modules/engine.io-client/node_modules/ws/lib/subprotocol.js"(exports2, module2) {
|
|
4382
4382
|
"use strict";
|
|
4383
4383
|
var { tokenChars } = require_validation();
|
|
4384
4384
|
function parse3(header) {
|
|
@@ -4421,12 +4421,12 @@ var require_subprotocol = __commonJS({
|
|
|
4421
4421
|
}
|
|
4422
4422
|
});
|
|
4423
4423
|
|
|
4424
|
-
// ../../node_modules
|
|
4424
|
+
// ../../node_modules/engine.io-client/node_modules/ws/lib/websocket-server.js
|
|
4425
4425
|
var require_websocket_server = __commonJS({
|
|
4426
|
-
"../../node_modules
|
|
4426
|
+
"../../node_modules/engine.io-client/node_modules/ws/lib/websocket-server.js"(exports2, module2) {
|
|
4427
4427
|
"use strict";
|
|
4428
4428
|
var EventEmitter = require("events");
|
|
4429
|
-
var
|
|
4429
|
+
var http2 = require("http");
|
|
4430
4430
|
var { Duplex } = require("stream");
|
|
4431
4431
|
var { createHash: createHash2 } = require("crypto");
|
|
4432
4432
|
var extension = require_extension();
|
|
@@ -4497,8 +4497,8 @@ var require_websocket_server = __commonJS({
|
|
|
4497
4497
|
);
|
|
4498
4498
|
}
|
|
4499
4499
|
if (options.port != null) {
|
|
4500
|
-
this._server =
|
|
4501
|
-
const body =
|
|
4500
|
+
this._server = http2.createServer((req, res) => {
|
|
4501
|
+
const body = http2.STATUS_CODES[426];
|
|
4502
4502
|
res.writeHead(426, {
|
|
4503
4503
|
"Content-Length": body.length,
|
|
4504
4504
|
"Content-Type": "text/plain"
|
|
@@ -4785,7 +4785,7 @@ var require_websocket_server = __commonJS({
|
|
|
4785
4785
|
this.destroy();
|
|
4786
4786
|
}
|
|
4787
4787
|
function abortHandshake(socket, code, message, headers) {
|
|
4788
|
-
message = message ||
|
|
4788
|
+
message = message || http2.STATUS_CODES[code];
|
|
4789
4789
|
headers = {
|
|
4790
4790
|
Connection: "close",
|
|
4791
4791
|
"Content-Type": "text/html",
|
|
@@ -4794,7 +4794,7 @@ var require_websocket_server = __commonJS({
|
|
|
4794
4794
|
};
|
|
4795
4795
|
socket.once("finish", socket.destroy);
|
|
4796
4796
|
socket.end(
|
|
4797
|
-
`HTTP/1.1 ${code} ${
|
|
4797
|
+
`HTTP/1.1 ${code} ${http2.STATUS_CODES[code]}\r
|
|
4798
4798
|
` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join("\r\n") + "\r\n\r\n" + message
|
|
4799
4799
|
);
|
|
4800
4800
|
}
|
|
@@ -4818,29 +4818,326 @@ var import_os = require("os");
|
|
|
4818
4818
|
var import_path = require("path");
|
|
4819
4819
|
var import_readline = require("readline");
|
|
4820
4820
|
|
|
4821
|
-
// ../shared/dist/agent/
|
|
4822
|
-
var
|
|
4821
|
+
// ../shared/dist/agent/agent-definitions.js
|
|
4822
|
+
var COORDINATOR_PROMPT = `## You are the Coordinator
|
|
4823
4823
|
|
|
4824
|
-
|
|
4824
|
+
You are the **Coordinator** for this task. When asked "who are you?", "what agent are you?", "are you the coordinator?", or anything similar \u2014 identify yourself plainly as the Coordinator for this task. Do not say "I'm Aiden" alone; say "I'm the Coordinator (an Aiden agent profile) for this task."
|
|
4825
4825
|
|
|
4826
|
-
|
|
4826
|
+
Your primary job is orchestration. Your primary job is **NOT** implementation. **Do not write code**, edit files, run builds or tests, or create implementation artifacts yourself.
|
|
4827
4827
|
|
|
4828
|
-
|
|
4828
|
+
## What you do NOT do
|
|
4829
4829
|
|
|
4830
|
-
|
|
4830
|
+
You MUST NOT call these tools:
|
|
4831
|
+
- \`Edit\`, \`Write\`, \`MultiEdit\`, \`NotebookEdit\` \u2014 any file modification
|
|
4832
|
+
- \`Bash\` for state-mutating commands (git commits, builds, installs, tests, file writes, deploys)
|
|
4831
4833
|
|
|
4832
|
-
|
|
4834
|
+
If the user asks for a code change, a build, a test run, a deploy, or anything that mutates state \u2014 STOP. **Delegate it** via \`start_task_session\` to the right specialist agent.
|
|
4833
4835
|
|
|
4834
|
-
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4836
|
+
Read-only inspection is fine: \`Read\`, \`Glob\`, \`Grep\`, and \`Bash\` for read commands like \`ls\`, \`git status\`, \`git log\`, \`cat\`, \`pwd\`.
|
|
4837
|
+
|
|
4838
|
+
## Your primary tools
|
|
4839
|
+
|
|
4840
|
+
Use these tools, in roughly this order of frequency:
|
|
4841
|
+
1. \`start_task_session\` \u2014 delegate work to a specialist
|
|
4842
|
+
2. \`get_task_memory\` / \`update_task_memory\` \u2014 keep the task-level working memory current
|
|
4843
|
+
3. \`list_subtasks\` / \`create_subtask\` / \`update_subtask\` \u2014 keep task breakdown current
|
|
4844
|
+
4. \`get_session_context\` \u2014 check what a worker accomplished
|
|
4845
|
+
5. \`update_task\` \u2014 keep status, priority, labels current
|
|
4846
|
+
6. \`list_sessions\` / \`search\` / \`Read\` / \`Glob\` / \`Grep\` \u2014 situational awareness (read-only)
|
|
4847
|
+
7. \`add_task_comment\` / \`create_plan\` \u2014 document decisions and plans
|
|
4848
|
+
|
|
4849
|
+
## How to scale work
|
|
4850
|
+
|
|
4851
|
+
Match session count to actual complexity \u2014 do not over-delegate:
|
|
4852
|
+
- **Single session** (1 agent, focused scope): most tasks \u2014 a bug fix, a single feature, a review
|
|
4853
|
+
- **2\u20133 sessions** (parallel or sequential): a feature that touches API + UI independently, or implementation followed by verification
|
|
4854
|
+
- **4+ sessions**: only when subtasks are clearly independent and coordination value exceeds overhead
|
|
4855
|
+
|
|
4856
|
+
A two-line change does not need its own session. A well-scoped subtask can often be one session.
|
|
4857
|
+
|
|
4858
|
+
## How to choose an agent when delegating
|
|
4859
|
+
|
|
4860
|
+
- **Implementor** \u2014 any implementation task, broad or narrow: features, fixes, data, API, UI, tests
|
|
4861
|
+
- **Designer** \u2014 interaction, layout, accessibility, visual clarity
|
|
4862
|
+
- **PM Agent** \u2014 product questions, requirements, scope definition, PRD creation
|
|
4863
|
+
- **General Agent** \u2014 only when no specialist fits
|
|
4864
|
+
|
|
4865
|
+
## How to write a kickoff message
|
|
4866
|
+
|
|
4867
|
+
Every \`start_task_session\` message must include all four of these:
|
|
4868
|
+
1. **Objective** \u2014 what to do, in one clear sentence
|
|
4869
|
+
2. **Relevant context** \u2014 which files, APIs, or prior session results matter
|
|
4870
|
+
3. **Constraints** \u2014 what not to change, patterns to match, things already tried
|
|
4871
|
+
4. **Definition of done** \u2014 what the output should look like when finished
|
|
4872
|
+
|
|
4873
|
+
Write it like a senior engineer's handoff note, not a vague request.
|
|
4874
|
+
|
|
4875
|
+
## Your workflow
|
|
4876
|
+
|
|
4877
|
+
1. Read the task, current subtasks, recent sessions \u2014 understand state before acting.
|
|
4878
|
+
2. Decide the next concrete unit of work. Break it down when scope is wide; keep subtasks current.
|
|
4879
|
+
3. **Either** delegate via \`start_task_session\`, **or** create/update a subtask, **or** ask the user a single targeted question if scope is ambiguous.
|
|
4880
|
+
4. After delegation, stay out of the implementation path. Track results via \`get_session_context\`, persist summaries/outcomes via \`update_task_memory\`, integrate status, decide the next move.
|
|
4881
|
+
|
|
4882
|
+
You are read-only by design. The build happens in spawned sessions. Hold that line.`;
|
|
4883
|
+
var PM_PROMPT = `## You are the PM Agent
|
|
4884
|
+
|
|
4885
|
+
You are the **PM Agent** (Product Manager) for this task. When identifying yourself, say "I'm the PM Agent (an Aiden agent profile)."
|
|
4886
|
+
|
|
4887
|
+
Your job is product thinking, not implementation. You own requirements, scope, and prioritization. You do not write code or edit files.
|
|
4888
|
+
|
|
4889
|
+
## What you do NOT do
|
|
4890
|
+
|
|
4891
|
+
You MUST NOT call these tools:
|
|
4892
|
+
- \`Edit\`, \`Write\`, \`MultiEdit\`, \`NotebookEdit\` \u2014 any file modification
|
|
4893
|
+
- \`Bash\` for state-mutating commands
|
|
4894
|
+
|
|
4895
|
+
You MUST NOT call \`start_task_session\` before you have written a plan or requirements document. Delegate only after scope is defined.
|
|
4896
|
+
|
|
4897
|
+
Read-only inspection is fine when you need to understand what exists.
|
|
4898
|
+
|
|
4899
|
+
## Your primary tools
|
|
4900
|
+
|
|
4901
|
+
Use these tools, in roughly this order of frequency:
|
|
4902
|
+
1. \`create_plan\` / \`create_document_artifact\` \u2014 write requirements, PRDs, or specs first
|
|
4903
|
+
2. \`create_subtask\` / \`update_subtask\` / \`list_subtasks\` \u2014 break work into ordered, dependency-aware units
|
|
4904
|
+
3. \`start_task_session\` \u2014 delegate to a specialist once scope is defined
|
|
4905
|
+
4. \`get_session_context\` / \`list_sessions\` \u2014 track progress
|
|
4906
|
+
5. \`update_task\` \u2014 keep status and priority current
|
|
4907
|
+
6. \`add_task_comment\` \u2014 surface decisions and risks to the user
|
|
4908
|
+
|
|
4909
|
+
## How to think like a PM
|
|
4910
|
+
|
|
4911
|
+
- **Challenge scope creep** \u2014 if a request expands beyond the task objective, name it and decide explicitly
|
|
4912
|
+
- **One question at a time** \u2014 never ask a list of questions; identify the single most ambiguity-reducing question
|
|
4913
|
+
- **Prioritize by dependency** \u2014 order subtasks so nothing blocks unnecessarily
|
|
4914
|
+
- **Define done clearly** \u2014 every subtask must have an unambiguous completion criterion
|
|
4915
|
+
- **Surface risk early** \u2014 flag unknowns before delegating, not after a session fails
|
|
4916
|
+
|
|
4917
|
+
## How to choose an agent when delegating
|
|
4918
|
+
|
|
4919
|
+
- **Implementor** \u2014 any code change: features, fixes, data, API, UI, tests
|
|
4920
|
+
- **Designer** \u2014 interaction, layout, accessibility, visual design
|
|
4921
|
+
- **Coordinator** \u2014 multi-agent orchestration where the work is complex enough to need coordination
|
|
4922
|
+
- **General Agent** \u2014 research, investigation, or work that doesn't fit a specialist
|
|
4923
|
+
|
|
4924
|
+
## How to write a kickoff message
|
|
4925
|
+
|
|
4926
|
+
Every \`start_task_session\` message must include all four of these:
|
|
4927
|
+
1. **Objective** \u2014 what to do, in one clear sentence
|
|
4928
|
+
2. **Relevant context** \u2014 which files, APIs, or prior session results matter
|
|
4929
|
+
3. **Constraints** \u2014 what not to change, patterns to match, things already tried
|
|
4930
|
+
4. **Definition of done** \u2014 what the output should look like when finished
|
|
4931
|
+
|
|
4932
|
+
## Your workflow
|
|
4933
|
+
|
|
4934
|
+
1. Read the task description and existing subtasks/sessions \u2014 understand what's already known before asking anything.
|
|
4935
|
+
2. If scope is ambiguous, ask the one question that resolves the most uncertainty.
|
|
4936
|
+
3. Write requirements or a plan artifact before any delegation.
|
|
4937
|
+
4. Break work into subtasks ordered by dependency. Delegate one at a time unless subtasks are truly independent.
|
|
4938
|
+
5. Track results and update task status as work completes.`;
|
|
4939
|
+
var GENERAL_PROMPT = `## You are the General Agent
|
|
4940
|
+
|
|
4941
|
+
You are a flexible general-purpose agent (an Aiden agent profile) for work that does not need a specialist profile. Wear whatever hat the moment demands \u2014 product thinker, planner, programmer, debugger, tester. Read the room and pick the hat.
|
|
4942
|
+
|
|
4943
|
+
When identifying yourself, say "I'm the General Agent (an Aiden agent profile)."
|
|
4944
|
+
|
|
4945
|
+
Clarify the goal only when required, inspect the relevant context first, then complete the requested work directly. Keep changes focused, avoid unrelated refactors, and validate the result before reporting back.
|
|
4946
|
+
|
|
4947
|
+
Non-trivial implementations include tests. Break and plan before building when scope is wide.
|
|
4948
|
+
|
|
4949
|
+
## When done, report
|
|
4950
|
+
|
|
4951
|
+
- What you did (1\u20132 sentences)
|
|
4952
|
+
- Files changed, if any
|
|
4953
|
+
- How you validated the result
|
|
4954
|
+
- Any residual risk or open question`;
|
|
4955
|
+
var IMPLEMENTOR_PROMPT = `## You are the Implementor Agent
|
|
4956
|
+
|
|
4957
|
+
You are a senior implementation agent responsible for end-to-end code delivery. When identifying yourself, say "I'm the Implementor Agent (an Aiden agent profile)."
|
|
4958
|
+
|
|
4959
|
+
Workflow: Listen \u2192 Understand \u2192 Break down \u2192 Plan \u2192 Build \u2192 Test \u2192 Ship.
|
|
4960
|
+
|
|
4961
|
+
## How to approach the work
|
|
4962
|
+
|
|
4963
|
+
1. Read the kickoff message fully. Identify the exact scope \u2014 do not expand it.
|
|
4964
|
+
2. Read the relevant code before writing any. Find the existing pattern and match it.
|
|
4965
|
+
3. Implement the smallest coherent path that satisfies the objective. Tests ship with code when the change is non-trivial.
|
|
4966
|
+
4. Validate the specific behavior you changed before reporting back.
|
|
4967
|
+
|
|
4968
|
+
## Primary tools
|
|
4969
|
+
|
|
4970
|
+
- \`Read\`, \`Glob\`, \`Grep\` \u2014 understand the codebase before touching it
|
|
4971
|
+
- \`Edit\`, \`Write\` \u2014 make changes; prefer \`Edit\` over \`Write\` for existing files
|
|
4972
|
+
- \`Bash\` \u2014 run type-checks, tests, and read-only commands; never skip validation
|
|
4973
|
+
- \`get_session_context\` \u2014 check what prior sessions already did before redoing work
|
|
4974
|
+
|
|
4975
|
+
## Rules
|
|
4976
|
+
|
|
4977
|
+
- Match existing patterns. Do not introduce new abstractions unless the current implementation cannot work.
|
|
4978
|
+
- Keep the write set narrow. A bug fix does not need surrounding cleanup.
|
|
4979
|
+
- Never skip the type-check or test run after changes.
|
|
4980
|
+
- Do not redesign scope. If the task is ambiguous, ask one targeted question before implementing.
|
|
4981
|
+
|
|
4982
|
+
## When done, report
|
|
4983
|
+
|
|
4984
|
+
- **Changed files**: list every file touched
|
|
4985
|
+
- **Validation**: what you ran (type-check, tests, manual check) and the result
|
|
4986
|
+
- **Residual risk**: anything that could break or needs follow-up`;
|
|
4987
|
+
var DESIGNER_PROMPT = `## You are the Designer Agent
|
|
4842
4988
|
|
|
4843
|
-
|
|
4989
|
+
You are a product UI designer and frontend interaction specialist. When identifying yourself, say "I'm the Designer Agent (an Aiden agent profile)."
|
|
4990
|
+
|
|
4991
|
+
## How to approach the work
|
|
4992
|
+
|
|
4993
|
+
1. Think from the user's task flow before touching layout. What is the user trying to do?
|
|
4994
|
+
2. Read the existing component patterns before writing new ones. Match what's already there.
|
|
4995
|
+
3. Improve clarity, hierarchy, and consistency \u2014 not decoration.
|
|
4996
|
+
4. If implementation is required, keep it tightly scoped to the UI change and validate screen state.
|
|
4997
|
+
|
|
4998
|
+
## Design principles
|
|
4999
|
+
|
|
5000
|
+
- **Useful over decorative** \u2014 every element should serve a user goal
|
|
5001
|
+
- **Consistent** \u2014 match the existing design system tokens; never hardcode colors, spacing, or font sizes
|
|
5002
|
+
- **Accessible** \u2014 keyboard-navigable, sufficient contrast, meaningful labels
|
|
5003
|
+
- **Responsive** \u2014 consider different screen sizes; use layout primitives, not fixed pixel values
|
|
5004
|
+
|
|
5005
|
+
## Primary tools
|
|
5006
|
+
|
|
5007
|
+
- \`Read\`, \`Glob\`, \`Grep\` \u2014 read existing components and design tokens before making changes
|
|
5008
|
+
- \`Edit\` \u2014 make focused UI changes; avoid touching non-UI logic unless it blocks the design
|
|
5009
|
+
- \`Bash\` \u2014 run type-checks after changes; inspect the browser console if needed
|
|
5010
|
+
- \`get_session_context\` \u2014 check what prior sessions already built before duplicating work
|
|
5011
|
+
|
|
5012
|
+
## Rules
|
|
5013
|
+
|
|
5014
|
+
- Never hardcode colors, spacing, or font sizes \u2014 use design system tokens only
|
|
5015
|
+
- Never write raw \`<button>\`, \`<input>\`, \`<select>\` \u2014 use UI primitives
|
|
5016
|
+
- Keep changes focused on the UI layer; do not refactor business logic as a side effect
|
|
5017
|
+
- Validate the specific screen state you changed before reporting back
|
|
5018
|
+
|
|
5019
|
+
## When done, report
|
|
5020
|
+
|
|
5021
|
+
- **Changed files**: list every file touched
|
|
5022
|
+
- **What changed visually**: describe the before/after in one sentence
|
|
5023
|
+
- **Validation**: how you confirmed it renders correctly (type-check, browser check)
|
|
5024
|
+
- **Residual risk**: anything fragile or worth a human eye`;
|
|
5025
|
+
var BUILTIN_AGENT_DEFINITIONS = [
|
|
5026
|
+
{
|
|
5027
|
+
id: "coordinator",
|
|
5028
|
+
name: "Coordinator",
|
|
5029
|
+
description: "Plans work, breaks down tasks, coordinates agents",
|
|
5030
|
+
iconKey: "command",
|
|
5031
|
+
defaultMode: "agent",
|
|
5032
|
+
capabilities: {
|
|
5033
|
+
canEditFiles: false,
|
|
5034
|
+
canRunCommands: false,
|
|
5035
|
+
canCreateArtifacts: false,
|
|
5036
|
+
canStartSessions: true,
|
|
5037
|
+
canManageSubtasks: true
|
|
5038
|
+
},
|
|
5039
|
+
systemPrompt: COORDINATOR_PROMPT
|
|
5040
|
+
},
|
|
5041
|
+
{
|
|
5042
|
+
id: "general",
|
|
5043
|
+
name: "General Agent",
|
|
5044
|
+
description: "Flexible agent with no specialist prompt",
|
|
5045
|
+
iconKey: "bot",
|
|
5046
|
+
defaultMode: "agent",
|
|
5047
|
+
capabilities: {
|
|
5048
|
+
canEditFiles: true,
|
|
5049
|
+
canRunCommands: true,
|
|
5050
|
+
canCreateArtifacts: true,
|
|
5051
|
+
canStartSessions: false,
|
|
5052
|
+
canManageSubtasks: false
|
|
5053
|
+
},
|
|
5054
|
+
systemPrompt: GENERAL_PROMPT
|
|
5055
|
+
},
|
|
5056
|
+
{
|
|
5057
|
+
id: "pm",
|
|
5058
|
+
name: "PM Agent",
|
|
5059
|
+
description: "Product management: requirements, scope, PRDs, task breakdown",
|
|
5060
|
+
iconKey: "clipboard-list",
|
|
5061
|
+
defaultMode: "agent",
|
|
5062
|
+
capabilities: {
|
|
5063
|
+
canEditFiles: false,
|
|
5064
|
+
canRunCommands: false,
|
|
5065
|
+
canCreateArtifacts: true,
|
|
5066
|
+
canStartSessions: true,
|
|
5067
|
+
canManageSubtasks: true
|
|
5068
|
+
},
|
|
5069
|
+
systemPrompt: PM_PROMPT
|
|
5070
|
+
},
|
|
5071
|
+
{
|
|
5072
|
+
id: "implementor",
|
|
5073
|
+
name: "Implementor",
|
|
5074
|
+
description: "Implements features and fixes end to end",
|
|
5075
|
+
iconKey: "code",
|
|
5076
|
+
defaultMode: "agent",
|
|
5077
|
+
capabilities: {
|
|
5078
|
+
canEditFiles: true,
|
|
5079
|
+
canRunCommands: true,
|
|
5080
|
+
canCreateArtifacts: true,
|
|
5081
|
+
canStartSessions: false,
|
|
5082
|
+
canManageSubtasks: false
|
|
5083
|
+
},
|
|
5084
|
+
systemPrompt: IMPLEMENTOR_PROMPT
|
|
5085
|
+
},
|
|
5086
|
+
{
|
|
5087
|
+
id: "designer",
|
|
5088
|
+
name: "Designer",
|
|
5089
|
+
description: "Improves interaction, layout, and visual clarity",
|
|
5090
|
+
iconKey: "palette",
|
|
5091
|
+
defaultMode: "agent",
|
|
5092
|
+
capabilities: {
|
|
5093
|
+
canEditFiles: true,
|
|
5094
|
+
canRunCommands: true,
|
|
5095
|
+
canCreateArtifacts: true,
|
|
5096
|
+
canStartSessions: false,
|
|
5097
|
+
canManageSubtasks: false
|
|
5098
|
+
},
|
|
5099
|
+
systemPrompt: DESIGNER_PROMPT
|
|
5100
|
+
}
|
|
5101
|
+
];
|
|
5102
|
+
var BUILTIN_AGENT_BY_ID = new Map(BUILTIN_AGENT_DEFINITIONS.map((agent) => [agent.id, agent]));
|
|
5103
|
+
var LEGACY_AGENT_ID_ALIASES = {
|
|
5104
|
+
blank: "general",
|
|
5105
|
+
developer: "implementor",
|
|
5106
|
+
implementer: "implementor",
|
|
5107
|
+
"ui-designer": "designer",
|
|
5108
|
+
"pr-reviewer": "general",
|
|
5109
|
+
verifier: "general"
|
|
5110
|
+
};
|
|
5111
|
+
function normalizeBuiltinAgentId(agentId) {
|
|
5112
|
+
if (!agentId)
|
|
5113
|
+
return void 0;
|
|
5114
|
+
if (BUILTIN_AGENT_BY_ID.has(agentId))
|
|
5115
|
+
return agentId;
|
|
5116
|
+
return LEGACY_AGENT_ID_ALIASES[agentId];
|
|
5117
|
+
}
|
|
5118
|
+
function getBuiltinAgentDefinition(agentId) {
|
|
5119
|
+
const normalizedAgentId = normalizeBuiltinAgentId(agentId) ?? "general";
|
|
5120
|
+
return BUILTIN_AGENT_BY_ID.get(normalizedAgentId);
|
|
5121
|
+
}
|
|
5122
|
+
function getAgentSystemPrompt(agentId) {
|
|
5123
|
+
const prompt = getBuiltinAgentDefinition(agentId).systemPrompt.trim();
|
|
5124
|
+
return prompt.length > 0 ? prompt : void 0;
|
|
5125
|
+
}
|
|
5126
|
+
function isReadOnlyAgent(agentId) {
|
|
5127
|
+
const agent = getBuiltinAgentDefinition(agentId);
|
|
5128
|
+
return !agent.capabilities.canEditFiles;
|
|
5129
|
+
}
|
|
5130
|
+
|
|
5131
|
+
// ../shared/dist/agent/system-prompt.js
|
|
5132
|
+
var AIDEN_IDENTITY_PROMPT = `You are Aiden, the software factory agent built by Supatest in Bangalore. Aiden ships software end to end \u2014 plan, write, review, test, deploy.
|
|
5133
|
+
|
|
5134
|
+
Do not present yourself as Claude, Claude Code, Codex, Gemini, Anthropic, or OpenAI as your primary identity \u2014 those are runtime details. Mention them only if the user explicitly asks about the underlying model or backend. If the user asks who you are, answer in Aiden terms first, and identify by your current agent role (described after this block).
|
|
5135
|
+
|
|
5136
|
+
## Voice
|
|
5137
|
+
|
|
5138
|
+
Direct. Structured. Concise. No hype, no "Great question!", no tool-brand roleplay. Speak like a teammate, not a data dump. Precise and decisive when working a task; listen, think, then act.
|
|
5139
|
+
|
|
5140
|
+
## How Aiden is structured
|
|
4844
5141
|
|
|
4845
5142
|
\`\`\`
|
|
4846
5143
|
Team
|
|
@@ -4853,16 +5150,23 @@ Team
|
|
|
4853
5150
|
\u2514\u2500\u2500 Whiteboard (beta)
|
|
4854
5151
|
\`\`\`
|
|
4855
5152
|
|
|
4856
|
-
- Document vs Artifact
|
|
4857
|
-
- IDs are not interchangeable
|
|
5153
|
+
- **Document vs Artifact**: Document = standalone page in a team. Artifact = output from work on a task + conversation, tied to that context. Belongs to a task \u2192 artifact. Doesn't \u2192 document.
|
|
5154
|
+
- **IDs are not interchangeable**: teamId, taskId, conversationId identify different things. Substituting one for another orphans records. Use the IDs the system provides; never invent or guess.
|
|
4858
5155
|
|
|
4859
5156
|
## Structure over chat
|
|
4860
5157
|
|
|
4861
|
-
Deliverables persist as Aiden artifacts and documents
|
|
5158
|
+
Deliverables persist as Aiden artifacts and documents \u2014 not as chat. Plans, PRDs, specs, test reports, and reviews live as structured outputs tied to team, task, and conversation. If a skill exists for the workflow you're in, use it instead of improvising in chat.
|
|
5159
|
+
|
|
5160
|
+
## Universal teammate principles
|
|
4862
5161
|
|
|
4863
|
-
|
|
5162
|
+
- Listen first. Don't jump to solutions. One question at a time, not a list.
|
|
5163
|
+
- Scan available context (task, subtasks, code, history) before asking questions you can answer yourself.
|
|
5164
|
+
- Challenge when off \u2014 never silently implement the wrong thing.
|
|
5165
|
+
- Human leads, you propose. Proactive on reversible actions. Consequential decisions \u2192 propose first, execute after confirmation.
|
|
5166
|
+
- Own mistakes. Wrong ID, jumped too fast \u2014 say so and fix it.
|
|
5167
|
+
- Think visually. Mermaid over paragraphs for architecture, flows, state, and schema.
|
|
4864
5168
|
|
|
4865
|
-
|
|
5169
|
+
The specific work you do \u2014 implementation, planning, review, coordination, verification \u2014 is determined by your agent role, described next.`;
|
|
4866
5170
|
var PLAN_MODE_PROMPT = [
|
|
4867
5171
|
"You are in Aiden plan mode.",
|
|
4868
5172
|
"Analyze the task, inspect the relevant code and context, and produce a concrete implementation plan.",
|
|
@@ -4881,8 +5185,8 @@ var TEST_MODE_PROMPT = [
|
|
|
4881
5185
|
].join("\n");
|
|
4882
5186
|
var ASK_MODE_PROMPT = "You are in ask mode. Stay read-only and explain the code, architecture, or behavior clearly without changing files.";
|
|
4883
5187
|
var REVIEW_MODE_PROMPT = "You are in review mode. Inspect the relevant changes, find real issues, and summarize risks and regressions precisely.";
|
|
4884
|
-
function getAidenModePrompt(
|
|
4885
|
-
switch (
|
|
5188
|
+
function getAidenModePrompt(mode) {
|
|
5189
|
+
switch (mode) {
|
|
4886
5190
|
case "plan":
|
|
4887
5191
|
return PLAN_MODE_PROMPT;
|
|
4888
5192
|
case "test":
|
|
@@ -4895,6 +5199,9 @@ function getAidenModePrompt(mode2) {
|
|
|
4895
5199
|
return void 0;
|
|
4896
5200
|
}
|
|
4897
5201
|
}
|
|
5202
|
+
function getAidenAgentPrompt(agentId) {
|
|
5203
|
+
return getAgentSystemPrompt(agentId);
|
|
5204
|
+
}
|
|
4898
5205
|
|
|
4899
5206
|
// ../shared/dist/agent/session-result.js
|
|
4900
5207
|
var SESSION_RESUME_FAILED_MESSAGE = "Session resume failed. The previous session may have expired or is no longer available. Please start a new session.";
|
|
@@ -4940,7 +5247,16 @@ function isLikelyProviderAuthError(stderr) {
|
|
|
4940
5247
|
const lower = stderr.toLowerCase();
|
|
4941
5248
|
return lower.includes("api key") || lower.includes("api_key") || lower.includes("invalid api key") || lower.includes("api key invalid") || lower.includes("unauthorized") || lower.includes("authentication failed") || lower.includes("authentication error") || lower.includes("provider settings") || lower.includes("invalid token") || lower.includes("token expired");
|
|
4942
5249
|
}
|
|
5250
|
+
function normalizeCodexCliErrorMessage(message) {
|
|
5251
|
+
const lower = message.toLowerCase();
|
|
5252
|
+
if (lower.includes("access token could not be refreshed") || lower.includes("refresh_token_invalidated") || lower.includes("refresh token has been invalidated")) {
|
|
5253
|
+
return "Codex CLI connection expired. Reconnect OpenAI Codex CLI in Cloud settings, then restart or recreate the machine.";
|
|
5254
|
+
}
|
|
5255
|
+
return message;
|
|
5256
|
+
}
|
|
4943
5257
|
function classifyCliError(stderr, exitCode) {
|
|
5258
|
+
const normalizedCodexError = normalizeCodexCliErrorMessage(stderr);
|
|
5259
|
+
if (normalizedCodexError !== stderr) return normalizedCodexError;
|
|
4944
5260
|
const lower = stderr.toLowerCase();
|
|
4945
5261
|
if (lower.includes("rate_limit") || lower.includes("rate limit") || lower.includes("429"))
|
|
4946
5262
|
return "Rate limited by API. Try again shortly.";
|
|
@@ -5160,6 +5476,7 @@ function createGenericCliBackend(options) {
|
|
|
5160
5476
|
runtimeSessionId: state.runtimeSessionId
|
|
5161
5477
|
});
|
|
5162
5478
|
}
|
|
5479
|
+
await options.afterExit?.(context, state);
|
|
5163
5480
|
const hasRenderableTurn = state.summary.trim().length > 0 || state.iterations > 0;
|
|
5164
5481
|
if (hasRenderableTurn) {
|
|
5165
5482
|
await presenter.onTurnComplete([]);
|
|
@@ -5211,8 +5528,8 @@ function parseClaudeStructuredLine(line, context, state) {
|
|
|
5211
5528
|
switch (type) {
|
|
5212
5529
|
case "system": {
|
|
5213
5530
|
if (parsed.subtype === "init") {
|
|
5214
|
-
const
|
|
5215
|
-
void presenter.onLog(`[claude_cli] Session initialized with ${
|
|
5531
|
+
const model = typeof parsed.model === "string" ? parsed.model : "claude";
|
|
5532
|
+
void presenter.onLog(`[claude_cli] Session initialized with ${model}`);
|
|
5216
5533
|
}
|
|
5217
5534
|
break;
|
|
5218
5535
|
}
|
|
@@ -5533,8 +5850,9 @@ function parseCodexStructuredLine(line, context, state) {
|
|
|
5533
5850
|
case "error": {
|
|
5534
5851
|
const message = extractCodexErrorMessage(parsed.message) || extractCodexErrorMessage(parsed.error) || typeof parsed.detail === "string" && parsed.detail.trim() || "";
|
|
5535
5852
|
if (message) {
|
|
5536
|
-
|
|
5537
|
-
|
|
5853
|
+
const normalizedMessage = normalizeCodexCliErrorMessage(message);
|
|
5854
|
+
void presenter.onError(normalizedMessage);
|
|
5855
|
+
state.error = normalizedMessage;
|
|
5538
5856
|
}
|
|
5539
5857
|
break;
|
|
5540
5858
|
}
|
|
@@ -5542,8 +5860,9 @@ function parseCodexStructuredLine(line, context, state) {
|
|
|
5542
5860
|
const error = typeof parsed.error === "object" && parsed.error !== null ? parsed.error : {};
|
|
5543
5861
|
const message = extractCodexErrorMessage(error.message) || extractCodexErrorMessage(error.detail) || typeof parsed.message === "string" && parsed.message.trim() || "";
|
|
5544
5862
|
if (message) {
|
|
5545
|
-
|
|
5546
|
-
|
|
5863
|
+
const normalizedMessage = normalizeCodexCliErrorMessage(message);
|
|
5864
|
+
void presenter.onError(normalizedMessage);
|
|
5865
|
+
state.error = normalizedMessage;
|
|
5547
5866
|
}
|
|
5548
5867
|
break;
|
|
5549
5868
|
}
|
|
@@ -5551,6 +5870,110 @@ function parseCodexStructuredLine(line, context, state) {
|
|
|
5551
5870
|
break;
|
|
5552
5871
|
}
|
|
5553
5872
|
}
|
|
5873
|
+
function parseJsonObject(value2) {
|
|
5874
|
+
try {
|
|
5875
|
+
const parsed = JSON.parse(value2);
|
|
5876
|
+
return typeof parsed === "object" && parsed !== null ? parsed : null;
|
|
5877
|
+
} catch {
|
|
5878
|
+
return null;
|
|
5879
|
+
}
|
|
5880
|
+
}
|
|
5881
|
+
function parseMaybeJson(value2) {
|
|
5882
|
+
if (typeof value2 !== "string") return value2;
|
|
5883
|
+
return parseJsonObject(value2) ?? value2;
|
|
5884
|
+
}
|
|
5885
|
+
function normalizeCodexMcpToolResult(output) {
|
|
5886
|
+
if (typeof output !== "string") return JSON.stringify(output ?? {}, null, 2);
|
|
5887
|
+
const outputMarker = "\nOutput:\n";
|
|
5888
|
+
const raw = output.includes(outputMarker) ? output.slice(output.indexOf(outputMarker) + outputMarker.length).trim() : output.trim();
|
|
5889
|
+
let parsed;
|
|
5890
|
+
try {
|
|
5891
|
+
parsed = JSON.parse(raw);
|
|
5892
|
+
} catch {
|
|
5893
|
+
return raw;
|
|
5894
|
+
}
|
|
5895
|
+
if (Array.isArray(parsed)) {
|
|
5896
|
+
const textBlocks = parsed.filter(
|
|
5897
|
+
(entry) => typeof entry === "object" && entry !== null && "text" in entry
|
|
5898
|
+
).map((entry) => typeof entry.text === "string" ? entry.text : "").filter(Boolean);
|
|
5899
|
+
if (textBlocks.length > 0) return textBlocks.join("\n");
|
|
5900
|
+
}
|
|
5901
|
+
return raw;
|
|
5902
|
+
}
|
|
5903
|
+
function findCodexSessionLog(runtimeSessionId, codexHome) {
|
|
5904
|
+
if (!runtimeSessionId || !(0, import_fs.existsSync)(codexHome)) return null;
|
|
5905
|
+
const root = (0, import_path.join)(codexHome, "sessions");
|
|
5906
|
+
if (!(0, import_fs.existsSync)(root)) return null;
|
|
5907
|
+
const matches = [];
|
|
5908
|
+
const stack = [root];
|
|
5909
|
+
while (stack.length > 0) {
|
|
5910
|
+
const dir = stack.pop();
|
|
5911
|
+
let entries;
|
|
5912
|
+
try {
|
|
5913
|
+
entries = (0, import_fs.readdirSync)(dir, { withFileTypes: true });
|
|
5914
|
+
} catch {
|
|
5915
|
+
continue;
|
|
5916
|
+
}
|
|
5917
|
+
for (const entry of entries) {
|
|
5918
|
+
const path = (0, import_path.join)(dir, entry.name);
|
|
5919
|
+
if (entry.isDirectory()) {
|
|
5920
|
+
stack.push(path);
|
|
5921
|
+
} else if (entry.isFile() && entry.name.includes(runtimeSessionId) && entry.name.endsWith(".jsonl")) {
|
|
5922
|
+
try {
|
|
5923
|
+
matches.push({ path, mtimeMs: (0, import_fs.statSync)(path).mtimeMs });
|
|
5924
|
+
} catch {
|
|
5925
|
+
matches.push({ path, mtimeMs: 0 });
|
|
5926
|
+
}
|
|
5927
|
+
}
|
|
5928
|
+
}
|
|
5929
|
+
}
|
|
5930
|
+
matches.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
5931
|
+
return matches[0]?.path ?? null;
|
|
5932
|
+
}
|
|
5933
|
+
async function replayCodexMcpToolEventsFromSessionLog(context, state) {
|
|
5934
|
+
const runtimeSessionId = state.runtimeSessionId;
|
|
5935
|
+
if (!runtimeSessionId) return;
|
|
5936
|
+
const codexHome = context.env.CODEX_HOME || process.env.CODEX_HOME || (0, import_path.join)((0, import_os.homedir)(), ".codex");
|
|
5937
|
+
const logPath = findCodexSessionLog(runtimeSessionId, codexHome);
|
|
5938
|
+
if (!logPath) return;
|
|
5939
|
+
const emittedToolIds = /* @__PURE__ */ new Set();
|
|
5940
|
+
const lines = (0, import_fs.readFileSync)(logPath, "utf8").split(/\r?\n/).filter(Boolean);
|
|
5941
|
+
for (const line of lines) {
|
|
5942
|
+
const entry = parseJsonObject(line);
|
|
5943
|
+
const payload = entry && typeof entry.payload === "object" && entry.payload !== null ? entry.payload : null;
|
|
5944
|
+
if (!payload) continue;
|
|
5945
|
+
if (payload.type === "function_call") {
|
|
5946
|
+
const callId = typeof payload.call_id === "string" ? payload.call_id : "";
|
|
5947
|
+
const name = typeof payload.name === "string" ? payload.name : "";
|
|
5948
|
+
const namespace = typeof payload.namespace === "string" ? payload.namespace : "";
|
|
5949
|
+
if (!callId || !name || !namespace.startsWith("mcp__")) continue;
|
|
5950
|
+
const toolName = `${namespace}${name}`;
|
|
5951
|
+
context.presenter.onToolUse(toolName, parseMaybeJson(payload.arguments), callId);
|
|
5952
|
+
emittedToolIds.add(callId);
|
|
5953
|
+
continue;
|
|
5954
|
+
}
|
|
5955
|
+
if (payload.type === "tool_search_call") {
|
|
5956
|
+
const callId = typeof payload.call_id === "string" ? payload.call_id : "";
|
|
5957
|
+
if (!callId) continue;
|
|
5958
|
+
context.presenter.onToolUse("tool_search", payload.arguments ?? {}, callId);
|
|
5959
|
+
emittedToolIds.add(callId);
|
|
5960
|
+
}
|
|
5961
|
+
}
|
|
5962
|
+
if (emittedToolIds.size === 0) return;
|
|
5963
|
+
for (const line of lines) {
|
|
5964
|
+
const entry = parseJsonObject(line);
|
|
5965
|
+
const payload = entry && typeof entry.payload === "object" && entry.payload !== null ? entry.payload : null;
|
|
5966
|
+
if (!payload || payload.type !== "function_call_output" && payload.type !== "tool_search_output") continue;
|
|
5967
|
+
const callId = typeof payload.call_id === "string" ? payload.call_id : "";
|
|
5968
|
+
if (!emittedToolIds.has(callId)) continue;
|
|
5969
|
+
try {
|
|
5970
|
+
const result = payload.type === "tool_search_output" ? JSON.stringify(payload.tools ?? [], null, 2) : normalizeCodexMcpToolResult(payload.output);
|
|
5971
|
+
context.presenter.onToolResult?.(callId, result);
|
|
5972
|
+
} catch {
|
|
5973
|
+
context.presenter.onToolResult?.(callId, String(payload.output ?? ""));
|
|
5974
|
+
}
|
|
5975
|
+
}
|
|
5976
|
+
}
|
|
5554
5977
|
function extractCursorToolEntry(toolCall) {
|
|
5555
5978
|
const [rawName, rawPayload] = Object.entries(toolCall)[0] ?? [];
|
|
5556
5979
|
if (!rawName || typeof rawPayload !== "object" || rawPayload === null) return null;
|
|
@@ -5693,8 +6116,8 @@ function parseGeminiStructuredLine(line, context, state) {
|
|
|
5693
6116
|
if (typeof parsed.model === "string") state.activeModel = parsed.model;
|
|
5694
6117
|
switch (type) {
|
|
5695
6118
|
case "init": {
|
|
5696
|
-
const
|
|
5697
|
-
void presenter.onLog(`[gemini_cli] Session initialized with ${
|
|
6119
|
+
const model = state.activeModel || context.config.selectedModel || "gemini";
|
|
6120
|
+
void presenter.onLog(`[gemini_cli] Session initialized with ${model}`);
|
|
5698
6121
|
break;
|
|
5699
6122
|
}
|
|
5700
6123
|
case "message": {
|
|
@@ -5769,8 +6192,19 @@ function parseGeminiStructuredLine(line, context, state) {
|
|
|
5769
6192
|
break;
|
|
5770
6193
|
}
|
|
5771
6194
|
}
|
|
5772
|
-
function
|
|
5773
|
-
|
|
6195
|
+
function shouldUseReadOnlyRuntimePermissions(config) {
|
|
6196
|
+
if (isReadOnlyAgent(config.agentId)) return true;
|
|
6197
|
+
switch (config.mode) {
|
|
6198
|
+
case "plan":
|
|
6199
|
+
case "ask":
|
|
6200
|
+
case "review":
|
|
6201
|
+
return true;
|
|
6202
|
+
default:
|
|
6203
|
+
return false;
|
|
6204
|
+
}
|
|
6205
|
+
}
|
|
6206
|
+
function getClaudePermissionMode(config) {
|
|
6207
|
+
switch (config.mode) {
|
|
5774
6208
|
case "plan":
|
|
5775
6209
|
case "ask":
|
|
5776
6210
|
case "review":
|
|
@@ -5779,11 +6213,12 @@ function getClaudePermissionMode(mode2) {
|
|
|
5779
6213
|
return "bypassPermissions";
|
|
5780
6214
|
}
|
|
5781
6215
|
}
|
|
5782
|
-
function
|
|
5783
|
-
return
|
|
6216
|
+
function getClaudeDisallowedTools(config) {
|
|
6217
|
+
return isReadOnlyAgent(config.agentId) ? ["Edit", "Write", "MultiEdit", "NotebookEdit"] : [];
|
|
5784
6218
|
}
|
|
5785
|
-
function shouldForceCursorAgent(
|
|
5786
|
-
|
|
6219
|
+
function shouldForceCursorAgent(config) {
|
|
6220
|
+
if (shouldUseReadOnlyRuntimePermissions(config)) return false;
|
|
6221
|
+
switch (config.mode) {
|
|
5787
6222
|
case "plan":
|
|
5788
6223
|
case "ask":
|
|
5789
6224
|
case "review":
|
|
@@ -5814,6 +6249,10 @@ function writeImagesToTempFiles(images) {
|
|
|
5814
6249
|
}
|
|
5815
6250
|
};
|
|
5816
6251
|
}
|
|
6252
|
+
function buildClaudeModelArg(baseModel, selectedContextWindow) {
|
|
6253
|
+
if (selectedContextWindow === "1m") return `${baseModel}[1m]`;
|
|
6254
|
+
return baseModel;
|
|
6255
|
+
}
|
|
5817
6256
|
function createClaudeCliBackend(command = "claude", defaultArgs = []) {
|
|
5818
6257
|
return {
|
|
5819
6258
|
kind: "claude_cli",
|
|
@@ -5826,8 +6265,12 @@ function createClaudeCliBackend(command = "claude", defaultArgs = []) {
|
|
|
5826
6265
|
"--input-format",
|
|
5827
6266
|
"stream-json",
|
|
5828
6267
|
"--permission-mode",
|
|
5829
|
-
getClaudePermissionMode(context.config
|
|
6268
|
+
getClaudePermissionMode(context.config)
|
|
5830
6269
|
];
|
|
6270
|
+
const disallowedTools = getClaudeDisallowedTools(context.config);
|
|
6271
|
+
if (disallowedTools.length > 0) {
|
|
6272
|
+
args.push("--disallowedTools", disallowedTools.join(","));
|
|
6273
|
+
}
|
|
5831
6274
|
const resumeId = context.config.runtimeSessionId?.trim() || context.config.providerSessionId?.trim();
|
|
5832
6275
|
if (!resumeId) {
|
|
5833
6276
|
if (context.config.systemPrompt?.trim()) {
|
|
@@ -5837,8 +6280,13 @@ function createClaudeCliBackend(command = "claude", defaultArgs = []) {
|
|
|
5837
6280
|
args.push("--append-system-prompt", context.config.systemPromptAppend.trim());
|
|
5838
6281
|
}
|
|
5839
6282
|
}
|
|
5840
|
-
|
|
5841
|
-
|
|
6283
|
+
const baseModel = context.config.selectedModel?.trim();
|
|
6284
|
+
if (baseModel) {
|
|
6285
|
+
args.push("--model", buildClaudeModelArg(baseModel, context.config.selectedContextWindow));
|
|
6286
|
+
}
|
|
6287
|
+
const claudeEffort = context.config.selectedEffortLevel?.trim();
|
|
6288
|
+
if (claudeEffort) {
|
|
6289
|
+
args.push("--effort", claudeEffort);
|
|
5842
6290
|
}
|
|
5843
6291
|
if (resumeId) {
|
|
5844
6292
|
args.push("--resume", resumeId);
|
|
@@ -5892,10 +6340,13 @@ function kimiSessionId(cwd) {
|
|
|
5892
6340
|
}
|
|
5893
6341
|
return (0, import_crypto.createHash)("md5").update(resolved).digest("hex");
|
|
5894
6342
|
}
|
|
5895
|
-
function
|
|
5896
|
-
|
|
6343
|
+
function shouldEnableKimiCliThinking(model) {
|
|
6344
|
+
return model?.trim() === "kimi-k2.6-thinking";
|
|
6345
|
+
}
|
|
6346
|
+
function resolveKimiCliModelArg(model) {
|
|
6347
|
+
const trimmed = model?.trim();
|
|
5897
6348
|
if (!trimmed) return void 0;
|
|
5898
|
-
if (trimmed === "kimi-latest" || trimmed === "kimi-k2.5" || trimmed === "kimi-k2.6") {
|
|
6349
|
+
if (trimmed === "kimi-latest" || trimmed === "kimi-k2.5" || trimmed === "kimi-k2.6" || shouldEnableKimiCliThinking(trimmed)) {
|
|
5899
6350
|
return void 0;
|
|
5900
6351
|
}
|
|
5901
6352
|
if (trimmed.startsWith("claude-")) return void 0;
|
|
@@ -5921,6 +6372,11 @@ function parseKimiStructuredLine(line, context, state) {
|
|
|
5921
6372
|
const contentBlocks = Array.isArray(parsed.content) ? parsed.content : [];
|
|
5922
6373
|
const toolCalls = Array.isArray(parsed.tool_calls) ? parsed.tool_calls : [];
|
|
5923
6374
|
if (role === "assistant") {
|
|
6375
|
+
const thinking = contentBlocks.filter((b) => b.type === "think" && typeof b.think === "string").map((b) => b.think).join("");
|
|
6376
|
+
if (thinking) {
|
|
6377
|
+
state.iterations = Math.max(state.iterations, 1);
|
|
6378
|
+
void presenter.onThinking(thinking);
|
|
6379
|
+
}
|
|
5924
6380
|
if (toolCalls.length > 0) {
|
|
5925
6381
|
state.iterations = Math.max(state.iterations, 1);
|
|
5926
6382
|
for (const tc of toolCalls) {
|
|
@@ -5972,8 +6428,11 @@ function createKimiCliBackend(command = "kimi", defaultArgs = []) {
|
|
|
5972
6428
|
];
|
|
5973
6429
|
const resumeId = context.config.runtimeSessionId?.trim() || context.config.providerSessionId?.trim();
|
|
5974
6430
|
if (resumeId) args.push("--session", resumeId);
|
|
5975
|
-
|
|
5976
|
-
|
|
6431
|
+
if (shouldEnableKimiCliThinking(context.config.selectedModel)) {
|
|
6432
|
+
args.push("--thinking");
|
|
6433
|
+
}
|
|
6434
|
+
const model = resolveKimiCliModelArg(context.config.selectedModel);
|
|
6435
|
+
if (model) args.push("--model", model);
|
|
5977
6436
|
return [...args, ...defaultArgs, "--prompt", prompt];
|
|
5978
6437
|
},
|
|
5979
6438
|
augmentPrompt: (context) => {
|
|
@@ -6006,8 +6465,8 @@ function createGeminiCliBackend(command = "gemini", defaultArgs = []) {
|
|
|
6006
6465
|
parseStructuredLine: parseGeminiStructuredLine
|
|
6007
6466
|
});
|
|
6008
6467
|
}
|
|
6009
|
-
function isCursorAgentCliModelId(
|
|
6010
|
-
return
|
|
6468
|
+
function isCursorAgentCliModelId(model) {
|
|
6469
|
+
return model === "auto" || /^composer-/.test(model) || /^gpt-\d/.test(model) || /^claude-\d/.test(model) || /^gemini-\d/.test(model) || /^grok-\d/.test(model) || /^kimi-/.test(model);
|
|
6011
6470
|
}
|
|
6012
6471
|
function createCursorAgentCliBackend(command = "cursor-agent", defaultArgs = []) {
|
|
6013
6472
|
return createGenericCliBackend({
|
|
@@ -6018,10 +6477,10 @@ function createCursorAgentCliBackend(command = "cursor-agent", defaultArgs = [])
|
|
|
6018
6477
|
buildArgs: (context, prompt) => {
|
|
6019
6478
|
const args = ["--print", "--output-format", "stream-json"];
|
|
6020
6479
|
const resumeId = context.config.runtimeSessionId?.trim() || context.config.providerSessionId?.trim();
|
|
6021
|
-
if (shouldForceCursorAgent(context.config
|
|
6480
|
+
if (shouldForceCursorAgent(context.config)) args.push("--force");
|
|
6022
6481
|
if (resumeId) args.push("--resume", resumeId);
|
|
6023
|
-
const
|
|
6024
|
-
if (
|
|
6482
|
+
const model = context.config.selectedModel?.trim();
|
|
6483
|
+
if (model && isCursorAgentCliModelId(model)) args.push("--model", model);
|
|
6025
6484
|
return [...args, ...defaultArgs, prompt];
|
|
6026
6485
|
},
|
|
6027
6486
|
augmentPrompt: (context) => {
|
|
@@ -6031,8 +6490,8 @@ function createCursorAgentCliBackend(command = "cursor-agent", defaultArgs = [])
|
|
|
6031
6490
|
parseStructuredLine: parseCursorStructuredLine
|
|
6032
6491
|
});
|
|
6033
6492
|
}
|
|
6034
|
-
function droidExecPermissionArgs(
|
|
6035
|
-
if (
|
|
6493
|
+
function droidExecPermissionArgs(mode) {
|
|
6494
|
+
if (mode === "plan" || mode === "ask" || mode === "review") return [];
|
|
6036
6495
|
return ["--auto", "high"];
|
|
6037
6496
|
}
|
|
6038
6497
|
function parseDroidStructuredLine(line, context, state) {
|
|
@@ -6131,8 +6590,8 @@ function createDroidCliBackend(command = "droid", defaultArgs = []) {
|
|
|
6131
6590
|
];
|
|
6132
6591
|
const resumeId = context.config.runtimeSessionId?.trim() || context.config.providerSessionId?.trim();
|
|
6133
6592
|
if (resumeId) args.push("--session-id", resumeId);
|
|
6134
|
-
const
|
|
6135
|
-
if (
|
|
6593
|
+
const model = context.config.selectedModel?.trim();
|
|
6594
|
+
if (model) args.push("-m", model);
|
|
6136
6595
|
args.push(prompt);
|
|
6137
6596
|
return args;
|
|
6138
6597
|
},
|
|
@@ -6254,8 +6713,8 @@ function createOpencodeCliBackend(command = "opencode", defaultArgs = []) {
|
|
|
6254
6713
|
const args = ["run", "--format", "json"];
|
|
6255
6714
|
const resumeId = ctx.config.runtimeSessionId?.trim() || ctx.config.providerSessionId?.trim();
|
|
6256
6715
|
if (resumeId) args.push("--session", resumeId);
|
|
6257
|
-
const
|
|
6258
|
-
if (
|
|
6716
|
+
const model = ctx.config.selectedModel?.trim();
|
|
6717
|
+
if (model && model.includes("/")) args.push("--model", model);
|
|
6259
6718
|
const fileArgs = imagePaths.flatMap((p) => ["--file", p]);
|
|
6260
6719
|
if (fileArgs.length > 0) {
|
|
6261
6720
|
return [...args, ...fileArgs, ...defaultArgs, "--", prompt];
|
|
@@ -6283,6 +6742,11 @@ function createGenericCliPassthroughBackend(command, defaultArgs = []) {
|
|
|
6283
6742
|
promptViaStdin: true
|
|
6284
6743
|
});
|
|
6285
6744
|
}
|
|
6745
|
+
function buildCodexEffortArgs(selectedEffortLevel) {
|
|
6746
|
+
const level = selectedEffortLevel?.trim();
|
|
6747
|
+
if (!level) return [];
|
|
6748
|
+
return ["-c", `model_reasoning_effort=${level}`];
|
|
6749
|
+
}
|
|
6286
6750
|
function createCodexRuntimeBackend(command = "codex", defaultArgs = []) {
|
|
6287
6751
|
return {
|
|
6288
6752
|
kind: "codex_app_server",
|
|
@@ -6298,9 +6762,10 @@ function createCodexRuntimeBackend(command = "codex", defaultArgs = []) {
|
|
|
6298
6762
|
buildArgs: (ctx) => {
|
|
6299
6763
|
const resumeId = ctx.config.runtimeSessionId?.trim() || ctx.config.providerSessionId?.trim();
|
|
6300
6764
|
const modelArgs = ctx.config.selectedModel?.trim() ? ["--model", ctx.config.selectedModel.trim()] : [];
|
|
6301
|
-
const
|
|
6765
|
+
const effortArgs = buildCodexEffortArgs(ctx.config.selectedEffortLevel);
|
|
6766
|
+
const permissionArgs = shouldUseReadOnlyRuntimePermissions(ctx.config) ? ["--ask-for-approval", "never", "--sandbox", "read-only"] : ["--dangerously-bypass-approvals-and-sandbox"];
|
|
6302
6767
|
const imageArgs = imagePaths.flatMap((p) => ["--image", p]);
|
|
6303
|
-
const baseArgs = resumeId ? [...permissionArgs, "exec", "resume", "--json", "--skip-git-repo-check", ...modelArgs, ...imageArgs, resumeId, "-"] : [...permissionArgs, "exec", "--json", "--skip-git-repo-check", ...modelArgs, ...imageArgs, "-"];
|
|
6768
|
+
const baseArgs = resumeId ? [...permissionArgs, "exec", "resume", "--json", "--skip-git-repo-check", ...modelArgs, ...effortArgs, ...imageArgs, resumeId, "-"] : [...permissionArgs, "exec", "--json", "--skip-git-repo-check", ...modelArgs, ...effortArgs, ...imageArgs, "-"];
|
|
6304
6769
|
return [...baseArgs, ...defaultArgs];
|
|
6305
6770
|
},
|
|
6306
6771
|
promptViaStdin: true,
|
|
@@ -6308,7 +6773,8 @@ function createCodexRuntimeBackend(command = "codex", defaultArgs = []) {
|
|
|
6308
6773
|
const basePrompt = buildPromptWithSystem(ctx.config, ctx.promptText);
|
|
6309
6774
|
return ctx.config.mode === "plan" ? buildPlanModePrefix(basePrompt) : basePrompt;
|
|
6310
6775
|
},
|
|
6311
|
-
parseStructuredLine: parseCodexStructuredLine
|
|
6776
|
+
parseStructuredLine: parseCodexStructuredLine,
|
|
6777
|
+
afterExit: replayCodexMcpToolEventsFromSessionLog
|
|
6312
6778
|
}).run(context);
|
|
6313
6779
|
} finally {
|
|
6314
6780
|
cleanup();
|
|
@@ -6316,12 +6782,118 @@ function createCodexRuntimeBackend(command = "codex", defaultArgs = []) {
|
|
|
6316
6782
|
}
|
|
6317
6783
|
};
|
|
6318
6784
|
}
|
|
6785
|
+
function parseCopilotStructuredLine(line, context, state) {
|
|
6786
|
+
const presenter = context.presenter;
|
|
6787
|
+
let parsed = null;
|
|
6788
|
+
try {
|
|
6789
|
+
parsed = JSON.parse(line);
|
|
6790
|
+
} catch {
|
|
6791
|
+
void presenter.onLog(`[copilot_cli] ${line}`);
|
|
6792
|
+
return;
|
|
6793
|
+
}
|
|
6794
|
+
const type = typeof parsed.type === "string" ? parsed.type : "";
|
|
6795
|
+
if (!type) return;
|
|
6796
|
+
if (typeof parsed.sessionId === "string") state.runtimeSessionId = parsed.sessionId;
|
|
6797
|
+
const data = typeof parsed.data === "object" && parsed.data !== null ? parsed.data : {};
|
|
6798
|
+
switch (type) {
|
|
6799
|
+
case "assistant.turn_start": {
|
|
6800
|
+
state.iterations += 1;
|
|
6801
|
+
break;
|
|
6802
|
+
}
|
|
6803
|
+
case "assistant.message_delta": {
|
|
6804
|
+
const delta = typeof data.deltaContent === "string" ? data.deltaContent : "";
|
|
6805
|
+
if (!delta) break;
|
|
6806
|
+
const messageId = typeof data.messageId === "string" ? data.messageId : null;
|
|
6807
|
+
if (messageId) {
|
|
6808
|
+
if (!state.copilotStreamedMessageIds) state.copilotStreamedMessageIds = /* @__PURE__ */ new Set();
|
|
6809
|
+
state.copilotStreamedMessageIds.add(messageId);
|
|
6810
|
+
}
|
|
6811
|
+
state.summary += delta;
|
|
6812
|
+
void presenter.onAssistantText(delta);
|
|
6813
|
+
break;
|
|
6814
|
+
}
|
|
6815
|
+
case "assistant.message": {
|
|
6816
|
+
const messageId = typeof data.messageId === "string" ? data.messageId : null;
|
|
6817
|
+
const content = typeof data.content === "string" ? data.content : "";
|
|
6818
|
+
const alreadyStreamed = !!messageId && state.copilotStreamedMessageIds?.has(messageId);
|
|
6819
|
+
if (content && !alreadyStreamed) {
|
|
6820
|
+
state.summary += content;
|
|
6821
|
+
void presenter.onAssistantText(content);
|
|
6822
|
+
}
|
|
6823
|
+
const reasoningText = typeof data.reasoningText === "string" ? data.reasoningText.trim() : "";
|
|
6824
|
+
if (reasoningText) {
|
|
6825
|
+
void presenter.onThinking(reasoningText);
|
|
6826
|
+
}
|
|
6827
|
+
break;
|
|
6828
|
+
}
|
|
6829
|
+
case "tool.execution_start": {
|
|
6830
|
+
const toolId = typeof data.toolCallId === "string" ? data.toolCallId : `copilot-tool-${Date.now()}`;
|
|
6831
|
+
const toolName = typeof data.toolName === "string" ? data.toolName : "Copilot Tool";
|
|
6832
|
+
void presenter.onToolUse(toolName, data.arguments ?? {}, toolId);
|
|
6833
|
+
break;
|
|
6834
|
+
}
|
|
6835
|
+
case "tool.execution_complete": {
|
|
6836
|
+
const toolId = typeof data.toolCallId === "string" ? data.toolCallId : `copilot-tool-${Date.now()}`;
|
|
6837
|
+
const result = typeof data.result === "object" && data.result !== null ? data.result : {};
|
|
6838
|
+
const content = typeof result.content === "string" ? result.content : typeof result.detailedContent === "string" ? result.detailedContent : typeof data.error === "string" ? data.error : "";
|
|
6839
|
+
const success = typeof data.success === "boolean" ? data.success : true;
|
|
6840
|
+
void presenter.onToolResult?.(toolId, content, !success);
|
|
6841
|
+
break;
|
|
6842
|
+
}
|
|
6843
|
+
case "session.error": {
|
|
6844
|
+
const message = typeof data.message === "string" ? data.message : typeof data.error === "string" ? data.error : "GitHub Copilot CLI session error";
|
|
6845
|
+
state.error = message;
|
|
6846
|
+
void presenter.onError(message);
|
|
6847
|
+
break;
|
|
6848
|
+
}
|
|
6849
|
+
case "result": {
|
|
6850
|
+
if (typeof parsed.sessionId === "string") state.runtimeSessionId = parsed.sessionId;
|
|
6851
|
+
const exitCode = typeof parsed.exitCode === "number" ? parsed.exitCode : 0;
|
|
6852
|
+
if (exitCode !== 0 && !state.error) {
|
|
6853
|
+
state.error = `GitHub Copilot CLI exited with code ${exitCode}`;
|
|
6854
|
+
}
|
|
6855
|
+
break;
|
|
6856
|
+
}
|
|
6857
|
+
default:
|
|
6858
|
+
break;
|
|
6859
|
+
}
|
|
6860
|
+
}
|
|
6861
|
+
function createCopilotCliBackend(command = "copilot", defaultArgs = []) {
|
|
6862
|
+
return createGenericCliBackend({
|
|
6863
|
+
kind: "copilot_cli",
|
|
6864
|
+
supportTier: "structured",
|
|
6865
|
+
command,
|
|
6866
|
+
args: [],
|
|
6867
|
+
buildArgs: (context, prompt) => {
|
|
6868
|
+
const args = [
|
|
6869
|
+
"--autopilot",
|
|
6870
|
+
"--yolo",
|
|
6871
|
+
"--max-autopilot-continues",
|
|
6872
|
+
"20",
|
|
6873
|
+
"-s",
|
|
6874
|
+
"--stream",
|
|
6875
|
+
"on",
|
|
6876
|
+
"--output-format",
|
|
6877
|
+
"json",
|
|
6878
|
+
"-p",
|
|
6879
|
+
prompt
|
|
6880
|
+
];
|
|
6881
|
+
if (context.config.selectedModel?.trim()) {
|
|
6882
|
+
args.push("--model", context.config.selectedModel.trim());
|
|
6883
|
+
}
|
|
6884
|
+
return [...args, ...defaultArgs];
|
|
6885
|
+
},
|
|
6886
|
+
parseStructuredLine: parseCopilotStructuredLine
|
|
6887
|
+
});
|
|
6888
|
+
}
|
|
6319
6889
|
var DEFAULT_MODEL = "claude-sonnet-4-6";
|
|
6320
6890
|
var DROID_DEFAULT_MODEL = "claude-opus-4-7";
|
|
6321
|
-
function defaultSelectedModelForBackend(
|
|
6322
|
-
switch (
|
|
6891
|
+
function defaultSelectedModelForBackend(backendKind) {
|
|
6892
|
+
switch (backendKind) {
|
|
6323
6893
|
case "droid_cli":
|
|
6324
6894
|
return DROID_DEFAULT_MODEL;
|
|
6895
|
+
case "copilot_cli":
|
|
6896
|
+
return "claude-sonnet-4.5";
|
|
6325
6897
|
case "kimi_cli":
|
|
6326
6898
|
return void 0;
|
|
6327
6899
|
default:
|
|
@@ -6336,10 +6908,10 @@ function canonicalizePath(inputPath) {
|
|
|
6336
6908
|
return null;
|
|
6337
6909
|
}
|
|
6338
6910
|
}
|
|
6339
|
-
function buildPromptWithFiles(
|
|
6340
|
-
if (!files || files.length === 0) return
|
|
6911
|
+
function buildPromptWithFiles(task, files) {
|
|
6912
|
+
if (!files || files.length === 0) return task;
|
|
6341
6913
|
const fileList = files.map((file) => `- ${file.filename} (${file.label}): ${file.tempPath}`).join("\n");
|
|
6342
|
-
return `${
|
|
6914
|
+
return `${task}
|
|
6343
6915
|
|
|
6344
6916
|
The user has attached the following files. You can read them using your available tools:
|
|
6345
6917
|
${fileList}`;
|
|
@@ -6415,14 +6987,15 @@ var BaseMachineAgent = class _BaseMachineAgent {
|
|
|
6415
6987
|
resolveBackendKind(config) {
|
|
6416
6988
|
return this.runtime.backendKind || config.backendKind || "claude_cli";
|
|
6417
6989
|
}
|
|
6418
|
-
getDefaultSupportTier(
|
|
6419
|
-
switch (
|
|
6990
|
+
getDefaultSupportTier(backendKind) {
|
|
6991
|
+
switch (backendKind) {
|
|
6420
6992
|
case "claude_cli":
|
|
6421
6993
|
case "codex_app_server":
|
|
6422
6994
|
case "cursor_agent_cli":
|
|
6423
6995
|
case "droid_cli":
|
|
6424
6996
|
case "gemini_cli":
|
|
6425
6997
|
case "opencode_cli":
|
|
6998
|
+
case "copilot_cli":
|
|
6426
6999
|
return "structured";
|
|
6427
7000
|
case "generic_cli":
|
|
6428
7001
|
default:
|
|
@@ -6431,13 +7004,15 @@ var BaseMachineAgent = class _BaseMachineAgent {
|
|
|
6431
7004
|
}
|
|
6432
7005
|
// ── Core lifecycle ─────────────────────────────────────────────────────
|
|
6433
7006
|
buildRuntimeConfig(config, safeProjectPath) {
|
|
6434
|
-
const
|
|
6435
|
-
const supportTier = config.supportTier || this.getDefaultSupportTier(
|
|
6436
|
-
const systemPromptParts = [AIDEN_IDENTITY_PROMPT
|
|
6437
|
-
|
|
6438
|
-
);
|
|
7007
|
+
const backendKind = this.resolveBackendKind(config);
|
|
7008
|
+
const supportTier = config.supportTier || this.getDefaultSupportTier(backendKind);
|
|
7009
|
+
const systemPromptParts = [AIDEN_IDENTITY_PROMPT];
|
|
7010
|
+
const agentPrompt = config.agentPrompt?.trim() || getAidenAgentPrompt(config.agentId);
|
|
7011
|
+
if (agentPrompt) systemPromptParts.push(agentPrompt);
|
|
6439
7012
|
const modeHint = getAidenModePrompt(config.mode);
|
|
6440
7013
|
if (modeHint) systemPromptParts.push(modeHint);
|
|
7014
|
+
const operatorSystemPrompt = config.systemPrompt?.trim();
|
|
7015
|
+
if (operatorSystemPrompt) systemPromptParts.push(operatorSystemPrompt);
|
|
6441
7016
|
const workingDir = config.worktreePath || safeProjectPath;
|
|
6442
7017
|
if (workingDir) {
|
|
6443
7018
|
systemPromptParts.push(
|
|
@@ -6449,16 +7024,16 @@ Prefer relative paths and keep your work scoped to this project.`
|
|
|
6449
7024
|
systemPromptParts.push(...extra);
|
|
6450
7025
|
return {
|
|
6451
7026
|
...config,
|
|
6452
|
-
backendKind
|
|
7027
|
+
backendKind,
|
|
6453
7028
|
supportTier,
|
|
6454
7029
|
runtimeCommand: config.runtimeCommand || this.runtime.runtimeCommand,
|
|
6455
7030
|
runtimeArgs: config.runtimeArgs || this.runtime.runtimeArgs,
|
|
6456
|
-
selectedModel: config.selectedModel || defaultSelectedModelForBackend(
|
|
7031
|
+
selectedModel: config.selectedModel || defaultSelectedModelForBackend(backendKind),
|
|
6457
7032
|
systemPrompt: systemPromptParts.join("\n\n") || void 0
|
|
6458
7033
|
};
|
|
6459
7034
|
}
|
|
6460
7035
|
async runCliBackend(config, safeProjectPath) {
|
|
6461
|
-
const
|
|
7036
|
+
const backendKind = this.resolveBackendKind(config);
|
|
6462
7037
|
const defaultCwd = (0, import_path2.join)((0, import_os2.homedir)(), "Documents", "aiden");
|
|
6463
7038
|
if (!(0, import_fs2.existsSync)(defaultCwd)) {
|
|
6464
7039
|
(0, import_fs2.mkdirSync)(defaultCwd, { recursive: true });
|
|
@@ -6469,7 +7044,7 @@ Prefer relative paths and keep your work scoped to this project.`
|
|
|
6469
7044
|
const promptText = this.buildPromptText(runtimeConfig);
|
|
6470
7045
|
const runtimeCommand = runtimeConfig.runtimeCommand || this.runtime.runtimeCommand;
|
|
6471
7046
|
const runtimeArgs = runtimeConfig.runtimeArgs || this.runtime.runtimeArgs || [];
|
|
6472
|
-
const backend =
|
|
7047
|
+
const backend = backendKind === "claude_cli" ? createClaudeCliBackend(runtimeCommand || "claude", runtimeArgs) : backendKind === "codex_app_server" ? createCodexRuntimeBackend(runtimeCommand || "codex", runtimeArgs) : backendKind === "copilot_cli" ? createCopilotCliBackend(runtimeCommand || "copilot", runtimeArgs) : backendKind === "cursor_agent_cli" ? createCursorAgentCliBackend(runtimeCommand || "cursor-agent", runtimeArgs) : backendKind === "gemini_cli" ? createGeminiCliBackend(runtimeCommand || "gemini", runtimeArgs) : backendKind === "droid_cli" ? createDroidCliBackend(runtimeCommand || "droid", runtimeArgs) : backendKind === "opencode_cli" ? createOpencodeCliBackend(runtimeCommand || "opencode", runtimeArgs) : backendKind === "kimi_cli" ? createKimiCliBackend(runtimeCommand || "kimi", runtimeArgs) : createGenericCliPassthroughBackend(runtimeCommand || "generic-cli", runtimeArgs);
|
|
6473
7048
|
let lastResult = null;
|
|
6474
7049
|
for (let attempt = 0; attempt <= _BaseMachineAgent.MAX_RETRIES; attempt++) {
|
|
6475
7050
|
if (this.abortController?.signal.aborted) break;
|
|
@@ -6550,11 +7125,11 @@ Prefer relative paths and keep your work scoped to this project.`
|
|
|
6550
7125
|
}
|
|
6551
7126
|
async run(config) {
|
|
6552
7127
|
this.abortController = new AbortController();
|
|
6553
|
-
const
|
|
6554
|
-
const supportTier = config.supportTier || this.getDefaultSupportTier(
|
|
7128
|
+
const backendKind = this.resolveBackendKind(config);
|
|
7129
|
+
const supportTier = config.supportTier || this.getDefaultSupportTier(backendKind);
|
|
6555
7130
|
const initialConfig = {
|
|
6556
7131
|
...config,
|
|
6557
|
-
backendKind
|
|
7132
|
+
backendKind,
|
|
6558
7133
|
supportTier,
|
|
6559
7134
|
runtimeCommand: config.runtimeCommand || this.runtime.runtimeCommand,
|
|
6560
7135
|
runtimeArgs: config.runtimeArgs || this.runtime.runtimeArgs
|
|
@@ -6575,7 +7150,7 @@ Prefer relative paths and keep your work scoped to this project.`
|
|
|
6575
7150
|
planFilesCreated: [],
|
|
6576
7151
|
iterations: 0,
|
|
6577
7152
|
error: message,
|
|
6578
|
-
backendKind
|
|
7153
|
+
backendKind,
|
|
6579
7154
|
supportTier
|
|
6580
7155
|
};
|
|
6581
7156
|
this.presenter.onComplete(result);
|
|
@@ -6597,7 +7172,7 @@ Prefer relative paths and keep your work scoped to this project.`
|
|
|
6597
7172
|
planFilesCreated: [],
|
|
6598
7173
|
iterations: 0,
|
|
6599
7174
|
error: message,
|
|
6600
|
-
backendKind
|
|
7175
|
+
backendKind,
|
|
6601
7176
|
supportTier
|
|
6602
7177
|
};
|
|
6603
7178
|
this.presenter.onComplete(result);
|
|
@@ -6607,11 +7182,61 @@ Prefer relative paths and keep your work scoped to this project.`
|
|
|
6607
7182
|
};
|
|
6608
7183
|
|
|
6609
7184
|
// src/core-agent.ts
|
|
6610
|
-
var CoreAgent = class extends BaseMachineAgent {
|
|
7185
|
+
var CoreAgent = class _CoreAgent extends BaseMachineAgent {
|
|
6611
7186
|
childProcess = null;
|
|
7187
|
+
_aborted = false;
|
|
7188
|
+
/** How long to wait after SIGTERM before escalating to SIGKILL. */
|
|
7189
|
+
static SIGKILL_DELAY_MS = 3e3;
|
|
6612
7190
|
constructor(presenter, runtime) {
|
|
6613
7191
|
super(presenter, runtime);
|
|
6614
7192
|
}
|
|
7193
|
+
abort() {
|
|
7194
|
+
this._aborted = true;
|
|
7195
|
+
super.abort();
|
|
7196
|
+
}
|
|
7197
|
+
kill() {
|
|
7198
|
+
this._aborted = true;
|
|
7199
|
+
super.abort();
|
|
7200
|
+
const child = this.childProcess;
|
|
7201
|
+
if (!child || child.killed || child.exitCode !== null) return false;
|
|
7202
|
+
return this.killChildProcess(child);
|
|
7203
|
+
}
|
|
7204
|
+
killChildProcess(child) {
|
|
7205
|
+
const pid = child.pid;
|
|
7206
|
+
if (!pid) return false;
|
|
7207
|
+
console.info("[CoreAgent] Killing agent process", { pid });
|
|
7208
|
+
try {
|
|
7209
|
+
if (process.platform === "win32") {
|
|
7210
|
+
child.kill("SIGTERM");
|
|
7211
|
+
} else {
|
|
7212
|
+
process.kill(-pid, "SIGTERM");
|
|
7213
|
+
}
|
|
7214
|
+
} catch (err) {
|
|
7215
|
+
if (err.code !== "ESRCH") {
|
|
7216
|
+
console.warn("[CoreAgent] SIGTERM failed", { pid, err });
|
|
7217
|
+
}
|
|
7218
|
+
try {
|
|
7219
|
+
child.kill("SIGTERM");
|
|
7220
|
+
} catch {
|
|
7221
|
+
}
|
|
7222
|
+
}
|
|
7223
|
+
setTimeout(() => {
|
|
7224
|
+
if (child.killed || child.exitCode !== null) return;
|
|
7225
|
+
console.warn("[CoreAgent] Escalating to SIGKILL", { pid });
|
|
7226
|
+
try {
|
|
7227
|
+
if (process.platform === "win32") {
|
|
7228
|
+
child.kill("SIGKILL");
|
|
7229
|
+
} else {
|
|
7230
|
+
process.kill(-pid, "SIGKILL");
|
|
7231
|
+
}
|
|
7232
|
+
} catch (err) {
|
|
7233
|
+
if (err.code !== "ESRCH") {
|
|
7234
|
+
console.warn("[CoreAgent] SIGKILL failed", { pid, err });
|
|
7235
|
+
}
|
|
7236
|
+
}
|
|
7237
|
+
}, _CoreAgent.SIGKILL_DELAY_MS);
|
|
7238
|
+
return true;
|
|
7239
|
+
}
|
|
6615
7240
|
// ── Interactive tool response (WS relay → stdin) ───────────────────────
|
|
6616
7241
|
/**
|
|
6617
7242
|
* Send a tool_result to the CLI's stdin (stream-json format).
|
|
@@ -6645,6 +7270,28 @@ var CoreAgent = class extends BaseMachineAgent {
|
|
|
6645
7270
|
return false;
|
|
6646
7271
|
}
|
|
6647
7272
|
}
|
|
7273
|
+
sendUserMessage(text) {
|
|
7274
|
+
if (!this.childProcess || this._aborted) return false;
|
|
7275
|
+
const stdin = this.childProcess.stdin;
|
|
7276
|
+
if (!stdin || stdin.destroyed) return false;
|
|
7277
|
+
try {
|
|
7278
|
+
const message = JSON.stringify({
|
|
7279
|
+
type: "user",
|
|
7280
|
+
message: {
|
|
7281
|
+
role: "user",
|
|
7282
|
+
content: [{ type: "text", text }]
|
|
7283
|
+
},
|
|
7284
|
+
session_id: "default",
|
|
7285
|
+
parent_tool_use_id: null
|
|
7286
|
+
});
|
|
7287
|
+
stdin.write(message + "\n");
|
|
7288
|
+
console.info(`[CoreAgent] Appended user message to live CLI stdin (${text.length} chars)`);
|
|
7289
|
+
return true;
|
|
7290
|
+
} catch (err) {
|
|
7291
|
+
console.error("[CoreAgent] Failed to append user message to stdin", err);
|
|
7292
|
+
return false;
|
|
7293
|
+
}
|
|
7294
|
+
}
|
|
6648
7295
|
// ── BaseMachineAgent hooks ─────────────────────────────────────────────
|
|
6649
7296
|
getOnProcessSpawned() {
|
|
6650
7297
|
return (child) => {
|
|
@@ -6652,6 +7299,12 @@ var CoreAgent = class extends BaseMachineAgent {
|
|
|
6652
7299
|
child.on("exit", () => {
|
|
6653
7300
|
this.childProcess = null;
|
|
6654
7301
|
});
|
|
7302
|
+
child.on("error", () => {
|
|
7303
|
+
this.childProcess = null;
|
|
7304
|
+
});
|
|
7305
|
+
if (this._aborted) {
|
|
7306
|
+
this.killChildProcess(child);
|
|
7307
|
+
}
|
|
6655
7308
|
};
|
|
6656
7309
|
}
|
|
6657
7310
|
async buildCliEnvironment() {
|
|
@@ -6670,6 +7323,18 @@ var CoreAgent = class extends BaseMachineAgent {
|
|
|
6670
7323
|
}
|
|
6671
7324
|
buildExtraSystemPromptParts(config) {
|
|
6672
7325
|
const parts2 = [];
|
|
7326
|
+
if (config.currentUser) {
|
|
7327
|
+
const u = config.currentUser;
|
|
7328
|
+
const lines = ["# Current User"];
|
|
7329
|
+
if (u.name) lines.push(`- **Name**: ${u.name}`);
|
|
7330
|
+
lines.push(`- **Email**: ${u.email}`);
|
|
7331
|
+
lines.push(`- **User ID**: ${u.id}`);
|
|
7332
|
+
lines.push("");
|
|
7333
|
+
lines.push(
|
|
7334
|
+
"This is the person who initiated this conversation. When creating tasks or assigning work, default to assigning to this user unless explicitly instructed otherwise."
|
|
7335
|
+
);
|
|
7336
|
+
parts2.push(lines.join("\n"));
|
|
7337
|
+
}
|
|
6673
7338
|
if (config.taskMeta) {
|
|
6674
7339
|
const meta = config.taskMeta;
|
|
6675
7340
|
const lines = ["# Task Context"];
|
|
@@ -6692,26 +7357,50 @@ ${meta.description}`);
|
|
|
6692
7357
|
if (meta.descriptionAttachmentIds && meta.descriptionAttachmentIds.length > 0) {
|
|
6693
7358
|
lines.push("");
|
|
6694
7359
|
lines.push("## Task Description Images");
|
|
6695
|
-
lines.push(
|
|
7360
|
+
lines.push('The task description contains images. Use the `attachment` MCP tool with op="get" to view them:');
|
|
6696
7361
|
for (const att of meta.descriptionAttachmentIds) {
|
|
6697
7362
|
lines.push(`- Attachment ID: \`${att.id}\` (${att.filename})`);
|
|
6698
7363
|
}
|
|
6699
7364
|
}
|
|
7365
|
+
if (meta.linkedResources && meta.linkedResources.length > 0) {
|
|
7366
|
+
lines.push("");
|
|
7367
|
+
lines.push("## Linked Task Resources");
|
|
7368
|
+
for (const resource of meta.linkedResources) {
|
|
7369
|
+
lines.push(`- ${resource.type}: "${resource.title}" (${resource.url ?? resource.id})`);
|
|
7370
|
+
}
|
|
7371
|
+
}
|
|
6700
7372
|
parts2.push(lines.join("\n"));
|
|
6701
7373
|
}
|
|
6702
|
-
const
|
|
7374
|
+
const taskId = config.taskId ?? process.env.AIDEN_TASK_ID;
|
|
6703
7375
|
const conversationId = config.conversationId ?? process.env.AIDEN_SESSION_ID;
|
|
7376
|
+
const teamId = config.teamId;
|
|
6704
7377
|
const artifactIds = [];
|
|
6705
|
-
if (
|
|
7378
|
+
if (teamId) artifactIds.push(`- teamId: "${teamId}"`);
|
|
7379
|
+
if (taskId) artifactIds.push(`- taskId: "${taskId}"`);
|
|
6706
7380
|
if (conversationId) artifactIds.push(`- conversationId: "${conversationId}"`);
|
|
6707
7381
|
if (artifactIds.length > 0) {
|
|
6708
7382
|
parts2.push(
|
|
6709
7383
|
[
|
|
6710
|
-
"When creating artifacts using MCP tools (create_plan, create_document_artifact, create_test_report), always pass these IDs:",
|
|
7384
|
+
"When creating artifacts using MCP tools (create_plan, create_document_artifact, create_test_report, upsert_prototype_version), always pass these IDs:",
|
|
6711
7385
|
...artifactIds
|
|
6712
7386
|
].join("\n")
|
|
6713
7387
|
);
|
|
6714
7388
|
}
|
|
7389
|
+
if (taskId && conversationId && teamId) {
|
|
7390
|
+
parts2.push(
|
|
7391
|
+
[
|
|
7392
|
+
"## Prototype Artifacts",
|
|
7393
|
+
"When the user asks to create, build, modify, or iterate on a prototype, do not create local prototype files such as prototype/index.html.",
|
|
7394
|
+
"Instead, generate a Vite React TypeScript source snapshot and call the Aiden MCP tool upsert_prototype_version with teamId, taskId, conversationId, title, sourceSnapshot, and packageJson.",
|
|
7395
|
+
"For follow-up changes to the same prototype, call list_prototypes or get_prototype if needed, then call upsert_prototype_version again with the existing prototypeId and parentVersionId so the task Prototypes panel renders the new version."
|
|
7396
|
+
].join("\n")
|
|
7397
|
+
);
|
|
7398
|
+
}
|
|
7399
|
+
if (teamId) {
|
|
7400
|
+
parts2.push(
|
|
7401
|
+
`You are operating within team \`${teamId}\`. Always use this as the \`teamId\` for all MCP tool calls that accept it (list_tasks, search, start_task_session, etc.). Do not call list_teams.`
|
|
7402
|
+
);
|
|
7403
|
+
}
|
|
6715
7404
|
return parts2;
|
|
6716
7405
|
}
|
|
6717
7406
|
};
|
|
@@ -6811,10 +7500,10 @@ var WebPresenter = class {
|
|
|
6811
7500
|
}
|
|
6812
7501
|
};
|
|
6813
7502
|
|
|
6814
|
-
// ../../node_modules
|
|
7503
|
+
// ../../node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.node.js
|
|
6815
7504
|
var XMLHttpRequestModule = __toESM(require_XMLHttpRequest(), 1);
|
|
6816
7505
|
|
|
6817
|
-
// ../../node_modules
|
|
7506
|
+
// ../../node_modules/engine.io-parser/build/esm/commons.js
|
|
6818
7507
|
var PACKET_TYPES = /* @__PURE__ */ Object.create(null);
|
|
6819
7508
|
PACKET_TYPES["open"] = "0";
|
|
6820
7509
|
PACKET_TYPES["close"] = "1";
|
|
@@ -6829,7 +7518,7 @@ Object.keys(PACKET_TYPES).forEach((key) => {
|
|
|
6829
7518
|
});
|
|
6830
7519
|
var ERROR_PACKET = { type: "error", data: "parser error" };
|
|
6831
7520
|
|
|
6832
|
-
// ../../node_modules
|
|
7521
|
+
// ../../node_modules/engine.io-parser/build/esm/encodePacket.js
|
|
6833
7522
|
var encodePacket = ({ type, data }, supportsBinary, callback) => {
|
|
6834
7523
|
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
|
|
6835
7524
|
return callback(supportsBinary ? data : "b" + toBuffer(data, true).toString("base64"));
|
|
@@ -6858,7 +7547,7 @@ function encodePacketToBinary(packet, callback) {
|
|
|
6858
7547
|
});
|
|
6859
7548
|
}
|
|
6860
7549
|
|
|
6861
|
-
// ../../node_modules
|
|
7550
|
+
// ../../node_modules/engine.io-parser/build/esm/decodePacket.js
|
|
6862
7551
|
var decodePacket = (encodedPacket, binaryType) => {
|
|
6863
7552
|
if (typeof encodedPacket !== "string") {
|
|
6864
7553
|
return {
|
|
@@ -6904,7 +7593,7 @@ var mapBinary = (data, binaryType) => {
|
|
|
6904
7593
|
}
|
|
6905
7594
|
};
|
|
6906
7595
|
|
|
6907
|
-
// ../../node_modules
|
|
7596
|
+
// ../../node_modules/engine.io-parser/build/esm/index.js
|
|
6908
7597
|
var SEPARATOR = String.fromCharCode(30);
|
|
6909
7598
|
var encodePayload = (packets, callback) => {
|
|
6910
7599
|
const length = packets.length;
|
|
@@ -7046,7 +7735,7 @@ function createPacketDecoderStream(maxPayload, binaryType) {
|
|
|
7046
7735
|
}
|
|
7047
7736
|
var protocol = 4;
|
|
7048
7737
|
|
|
7049
|
-
// ../../node_modules
|
|
7738
|
+
// ../../node_modules/@socket.io/component-emitter/lib/esm/index.js
|
|
7050
7739
|
function Emitter(obj) {
|
|
7051
7740
|
if (obj) return mixin(obj);
|
|
7052
7741
|
}
|
|
@@ -7118,7 +7807,7 @@ Emitter.prototype.hasListeners = function(event) {
|
|
|
7118
7807
|
return !!this.listeners(event).length;
|
|
7119
7808
|
};
|
|
7120
7809
|
|
|
7121
|
-
// ../../node_modules
|
|
7810
|
+
// ../../node_modules/engine.io-client/build/esm-debug/globals.node.js
|
|
7122
7811
|
var nextTick = process.nextTick;
|
|
7123
7812
|
var globalThisShim = global;
|
|
7124
7813
|
var defaultBinaryType = "nodebuffer";
|
|
@@ -7206,7 +7895,7 @@ var CookieJar = class {
|
|
|
7206
7895
|
}
|
|
7207
7896
|
};
|
|
7208
7897
|
|
|
7209
|
-
// ../../node_modules
|
|
7898
|
+
// ../../node_modules/engine.io-client/build/esm-debug/util.js
|
|
7210
7899
|
function pick(obj, ...attr) {
|
|
7211
7900
|
return attr.reduce((acc, k) => {
|
|
7212
7901
|
if (obj.hasOwnProperty(k)) {
|
|
@@ -7254,7 +7943,7 @@ function randomString() {
|
|
|
7254
7943
|
return Date.now().toString(36).substring(3) + Math.random().toString(36).substring(2, 5);
|
|
7255
7944
|
}
|
|
7256
7945
|
|
|
7257
|
-
// ../../node_modules
|
|
7946
|
+
// ../../node_modules/engine.io-client/build/esm-debug/contrib/parseqs.js
|
|
7258
7947
|
function encode(obj) {
|
|
7259
7948
|
let str = "";
|
|
7260
7949
|
for (let i in obj) {
|
|
@@ -7276,7 +7965,7 @@ function decode(qs) {
|
|
|
7276
7965
|
return qry;
|
|
7277
7966
|
}
|
|
7278
7967
|
|
|
7279
|
-
// ../../node_modules
|
|
7968
|
+
// ../../node_modules/engine.io-client/build/esm-debug/transport.js
|
|
7280
7969
|
var import_debug = __toESM(require_src(), 1);
|
|
7281
7970
|
var debug = (0, import_debug.default)("engine.io-client:transport");
|
|
7282
7971
|
var TransportError = class extends Error {
|
|
@@ -7394,8 +8083,8 @@ var Transport = class extends Emitter {
|
|
|
7394
8083
|
return schema + "://" + this._hostname() + this._port() + this.opts.path + this._query(query);
|
|
7395
8084
|
}
|
|
7396
8085
|
_hostname() {
|
|
7397
|
-
const
|
|
7398
|
-
return
|
|
8086
|
+
const hostname2 = this.opts.hostname;
|
|
8087
|
+
return hostname2.indexOf(":") === -1 ? hostname2 : "[" + hostname2 + "]";
|
|
7399
8088
|
}
|
|
7400
8089
|
_port() {
|
|
7401
8090
|
if (this.opts.port && (this.opts.secure && Number(this.opts.port) !== 443 || !this.opts.secure && Number(this.opts.port) !== 80)) {
|
|
@@ -7410,7 +8099,7 @@ var Transport = class extends Emitter {
|
|
|
7410
8099
|
}
|
|
7411
8100
|
};
|
|
7412
8101
|
|
|
7413
|
-
// ../../node_modules
|
|
8102
|
+
// ../../node_modules/engine.io-client/build/esm-debug/transports/polling.js
|
|
7414
8103
|
var import_debug2 = __toESM(require_src(), 1);
|
|
7415
8104
|
var debug2 = (0, import_debug2.default)("engine.io-client:polling");
|
|
7416
8105
|
var Polling = class extends Transport {
|
|
@@ -7555,7 +8244,7 @@ var Polling = class extends Transport {
|
|
|
7555
8244
|
}
|
|
7556
8245
|
};
|
|
7557
8246
|
|
|
7558
|
-
// ../../node_modules
|
|
8247
|
+
// ../../node_modules/engine.io-client/build/esm-debug/contrib/has-cors.js
|
|
7559
8248
|
var value = false;
|
|
7560
8249
|
try {
|
|
7561
8250
|
value = typeof XMLHttpRequest !== "undefined" && "withCredentials" in new XMLHttpRequest();
|
|
@@ -7563,7 +8252,7 @@ try {
|
|
|
7563
8252
|
}
|
|
7564
8253
|
var hasCORS = value;
|
|
7565
8254
|
|
|
7566
|
-
// ../../node_modules
|
|
8255
|
+
// ../../node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.js
|
|
7567
8256
|
var import_debug3 = __toESM(require_src(), 1);
|
|
7568
8257
|
var debug3 = (0, import_debug3.default)("engine.io-client:polling");
|
|
7569
8258
|
function empty() {
|
|
@@ -7798,7 +8487,7 @@ function newRequest(opts) {
|
|
|
7798
8487
|
}
|
|
7799
8488
|
}
|
|
7800
8489
|
|
|
7801
|
-
// ../../node_modules
|
|
8490
|
+
// ../../node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.node.js
|
|
7802
8491
|
var XMLHttpRequest2 = XMLHttpRequestModule.default || XMLHttpRequestModule;
|
|
7803
8492
|
var XHR = class extends BaseXHR {
|
|
7804
8493
|
request(opts = {}) {
|
|
@@ -7808,14 +8497,14 @@ var XHR = class extends BaseXHR {
|
|
|
7808
8497
|
}
|
|
7809
8498
|
};
|
|
7810
8499
|
|
|
7811
|
-
// ../../node_modules
|
|
8500
|
+
// ../../node_modules/engine.io-client/node_modules/ws/wrapper.mjs
|
|
7812
8501
|
var import_stream = __toESM(require_stream(), 1);
|
|
7813
8502
|
var import_receiver = __toESM(require_receiver(), 1);
|
|
7814
8503
|
var import_sender = __toESM(require_sender(), 1);
|
|
7815
8504
|
var import_websocket = __toESM(require_websocket(), 1);
|
|
7816
8505
|
var import_websocket_server = __toESM(require_websocket_server(), 1);
|
|
7817
8506
|
|
|
7818
|
-
// ../../node_modules
|
|
8507
|
+
// ../../node_modules/engine.io-client/build/esm-debug/transports/websocket.js
|
|
7819
8508
|
var import_debug4 = __toESM(require_src(), 1);
|
|
7820
8509
|
var debug4 = (0, import_debug4.default)("engine.io-client:websocket");
|
|
7821
8510
|
var isReactNative = typeof navigator !== "undefined" && typeof navigator.product === "string" && navigator.product.toLowerCase() === "reactnative";
|
|
@@ -7904,7 +8593,7 @@ var BaseWS = class extends Transport {
|
|
|
7904
8593
|
};
|
|
7905
8594
|
var WebSocketCtor = globalThisShim.WebSocket || globalThisShim.MozWebSocket;
|
|
7906
8595
|
|
|
7907
|
-
// ../../node_modules
|
|
8596
|
+
// ../../node_modules/engine.io-client/build/esm-debug/transports/websocket.node.js
|
|
7908
8597
|
var WS = class extends BaseWS {
|
|
7909
8598
|
createSocket(uri, protocols, opts) {
|
|
7910
8599
|
var _a;
|
|
@@ -7935,7 +8624,7 @@ var WS = class extends BaseWS {
|
|
|
7935
8624
|
}
|
|
7936
8625
|
};
|
|
7937
8626
|
|
|
7938
|
-
// ../../node_modules
|
|
8627
|
+
// ../../node_modules/engine.io-client/build/esm-debug/transports/webtransport.js
|
|
7939
8628
|
var import_debug5 = __toESM(require_src(), 1);
|
|
7940
8629
|
var debug5 = (0, import_debug5.default)("engine.io-client:webtransport");
|
|
7941
8630
|
var WT = class extends Transport {
|
|
@@ -8005,14 +8694,14 @@ var WT = class extends Transport {
|
|
|
8005
8694
|
}
|
|
8006
8695
|
};
|
|
8007
8696
|
|
|
8008
|
-
// ../../node_modules
|
|
8697
|
+
// ../../node_modules/engine.io-client/build/esm-debug/transports/index.js
|
|
8009
8698
|
var transports = {
|
|
8010
8699
|
websocket: WS,
|
|
8011
8700
|
webtransport: WT,
|
|
8012
8701
|
polling: XHR
|
|
8013
8702
|
};
|
|
8014
8703
|
|
|
8015
|
-
// ../../node_modules
|
|
8704
|
+
// ../../node_modules/engine.io-client/build/esm-debug/contrib/parseuri.js
|
|
8016
8705
|
var re = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
|
|
8017
8706
|
var parts = [
|
|
8018
8707
|
"source",
|
|
@@ -8072,7 +8761,7 @@ function queryKey(uri, query) {
|
|
|
8072
8761
|
return data;
|
|
8073
8762
|
}
|
|
8074
8763
|
|
|
8075
|
-
// ../../node_modules
|
|
8764
|
+
// ../../node_modules/engine.io-client/build/esm-debug/socket.js
|
|
8076
8765
|
var import_debug6 = __toESM(require_src(), 1);
|
|
8077
8766
|
var debug6 = (0, import_debug6.default)("engine.io-client:socket");
|
|
8078
8767
|
var withEventListeners = typeof addEventListener === "function" && typeof removeEventListener === "function";
|
|
@@ -8668,10 +9357,10 @@ var Socket = class extends SocketWithUpgrade {
|
|
|
8668
9357
|
}
|
|
8669
9358
|
};
|
|
8670
9359
|
|
|
8671
|
-
// ../../node_modules
|
|
9360
|
+
// ../../node_modules/engine.io-client/build/esm-debug/index.js
|
|
8672
9361
|
var protocol2 = Socket.protocol;
|
|
8673
9362
|
|
|
8674
|
-
// ../../node_modules
|
|
9363
|
+
// ../../node_modules/socket.io-client/build/esm-debug/url.js
|
|
8675
9364
|
var import_debug7 = __toESM(require_src(), 1);
|
|
8676
9365
|
var debug7 = (0, import_debug7.default)("socket.io-client:url");
|
|
8677
9366
|
function url(uri, path = "", loc) {
|
|
@@ -8713,7 +9402,7 @@ function url(uri, path = "", loc) {
|
|
|
8713
9402
|
return obj;
|
|
8714
9403
|
}
|
|
8715
9404
|
|
|
8716
|
-
// ../../node_modules
|
|
9405
|
+
// ../../node_modules/socket.io-parser/build/esm-debug/index.js
|
|
8717
9406
|
var esm_debug_exports = {};
|
|
8718
9407
|
__export(esm_debug_exports, {
|
|
8719
9408
|
Decoder: () => Decoder,
|
|
@@ -8723,7 +9412,7 @@ __export(esm_debug_exports, {
|
|
|
8723
9412
|
protocol: () => protocol3
|
|
8724
9413
|
});
|
|
8725
9414
|
|
|
8726
|
-
// ../../node_modules
|
|
9415
|
+
// ../../node_modules/socket.io-parser/build/esm-debug/is-binary.js
|
|
8727
9416
|
var withNativeArrayBuffer = typeof ArrayBuffer === "function";
|
|
8728
9417
|
var isView = (obj) => {
|
|
8729
9418
|
return typeof ArrayBuffer.isView === "function" ? ArrayBuffer.isView(obj) : obj.buffer instanceof ArrayBuffer;
|
|
@@ -8760,7 +9449,7 @@ function hasBinary(obj, toJSON) {
|
|
|
8760
9449
|
return false;
|
|
8761
9450
|
}
|
|
8762
9451
|
|
|
8763
|
-
// ../../node_modules
|
|
9452
|
+
// ../../node_modules/socket.io-parser/build/esm-debug/binary.js
|
|
8764
9453
|
function deconstructPacket(packet) {
|
|
8765
9454
|
const buffers = [];
|
|
8766
9455
|
const packetData = packet.data;
|
|
@@ -8822,7 +9511,7 @@ function _reconstructPacket(data, buffers) {
|
|
|
8822
9511
|
return data;
|
|
8823
9512
|
}
|
|
8824
9513
|
|
|
8825
|
-
// ../../node_modules
|
|
9514
|
+
// ../../node_modules/socket.io-parser/build/esm-debug/index.js
|
|
8826
9515
|
var import_debug8 = __toESM(require_src(), 1);
|
|
8827
9516
|
var debug8 = (0, import_debug8.default)("socket.io-parser");
|
|
8828
9517
|
var RESERVED_EVENTS = [
|
|
@@ -9116,7 +9805,7 @@ function isPacketValid(packet) {
|
|
|
9116
9805
|
return isNamespaceValid(packet.nsp) && isAckIdValid(packet.id) && isDataValid(packet.type, packet.data);
|
|
9117
9806
|
}
|
|
9118
9807
|
|
|
9119
|
-
// ../../node_modules
|
|
9808
|
+
// ../../node_modules/socket.io-client/build/esm-debug/on.js
|
|
9120
9809
|
function on(obj, ev, fn) {
|
|
9121
9810
|
obj.on(ev, fn);
|
|
9122
9811
|
return function subDestroy() {
|
|
@@ -9124,7 +9813,7 @@ function on(obj, ev, fn) {
|
|
|
9124
9813
|
};
|
|
9125
9814
|
}
|
|
9126
9815
|
|
|
9127
|
-
// ../../node_modules
|
|
9816
|
+
// ../../node_modules/socket.io-client/build/esm-debug/socket.js
|
|
9128
9817
|
var import_debug9 = __toESM(require_src(), 1);
|
|
9129
9818
|
var debug9 = (0, import_debug9.default)("socket.io-client:socket");
|
|
9130
9819
|
var RESERVED_EVENTS2 = Object.freeze({
|
|
@@ -9919,7 +10608,7 @@ var Socket2 = class extends Emitter {
|
|
|
9919
10608
|
}
|
|
9920
10609
|
};
|
|
9921
10610
|
|
|
9922
|
-
// ../../node_modules
|
|
10611
|
+
// ../../node_modules/socket.io-client/build/esm-debug/contrib/backo2.js
|
|
9923
10612
|
function Backoff(opts) {
|
|
9924
10613
|
opts = opts || {};
|
|
9925
10614
|
this.ms = opts.min || 100;
|
|
@@ -9950,7 +10639,7 @@ Backoff.prototype.setJitter = function(jitter) {
|
|
|
9950
10639
|
this.jitter = jitter;
|
|
9951
10640
|
};
|
|
9952
10641
|
|
|
9953
|
-
// ../../node_modules
|
|
10642
|
+
// ../../node_modules/socket.io-client/build/esm-debug/manager.js
|
|
9954
10643
|
var import_debug10 = __toESM(require_src(), 1);
|
|
9955
10644
|
var debug10 = (0, import_debug10.default)("socket.io-client:manager");
|
|
9956
10645
|
var Manager = class extends Emitter {
|
|
@@ -10319,7 +11008,7 @@ var Manager = class extends Emitter {
|
|
|
10319
11008
|
}
|
|
10320
11009
|
};
|
|
10321
11010
|
|
|
10322
|
-
// ../../node_modules
|
|
11011
|
+
// ../../node_modules/socket.io-client/build/esm-debug/index.js
|
|
10323
11012
|
var import_debug11 = __toESM(require_src(), 1);
|
|
10324
11013
|
var debug11 = (0, import_debug11.default)("socket.io-client");
|
|
10325
11014
|
var cache = {};
|
|
@@ -10361,9 +11050,9 @@ Object.assign(lookup, {
|
|
|
10361
11050
|
// src/ws-client.ts
|
|
10362
11051
|
var WSClient = class {
|
|
10363
11052
|
socket;
|
|
10364
|
-
constructor(
|
|
10365
|
-
this.socket = lookup(
|
|
10366
|
-
query: { type: "agent", sessionId
|
|
11053
|
+
constructor(wsUrl, sessionId, taskId, token, callbacks, agentVersion) {
|
|
11054
|
+
this.socket = lookup(wsUrl, {
|
|
11055
|
+
query: { type: "agent", sessionId, taskId, agentVersion: agentVersion ?? "" },
|
|
10367
11056
|
auth: { token },
|
|
10368
11057
|
transports: ["websocket"],
|
|
10369
11058
|
reconnection: true,
|
|
@@ -10421,7 +11110,11 @@ var WSClient = class {
|
|
|
10421
11110
|
images: data.images,
|
|
10422
11111
|
providerSessionId: data.providerSessionId,
|
|
10423
11112
|
backendKind: data.backendKind,
|
|
11113
|
+
agentId: data.agentId,
|
|
11114
|
+
agentPrompt: data.agentPrompt,
|
|
10424
11115
|
selectedModel: data.selectedModel,
|
|
11116
|
+
selectedContextWindow: data.selectedContextWindow,
|
|
11117
|
+
selectedEffortLevel: data.selectedEffortLevel,
|
|
10425
11118
|
mode: data.mode,
|
|
10426
11119
|
taskMeta: data.taskMeta,
|
|
10427
11120
|
workflowTools: data.workflowTools,
|
|
@@ -10429,7 +11122,9 @@ var WSClient = class {
|
|
|
10429
11122
|
messageId: data.messageId,
|
|
10430
11123
|
maxIterations: data.maxIterations,
|
|
10431
11124
|
taskId: data.taskId,
|
|
10432
|
-
conversationId: data.conversationId
|
|
11125
|
+
conversationId: data.conversationId,
|
|
11126
|
+
teamId: data.teamId,
|
|
11127
|
+
currentUser: data.currentUser
|
|
10433
11128
|
});
|
|
10434
11129
|
});
|
|
10435
11130
|
this.socket.on("stop", () => {
|
|
@@ -10447,7 +11142,7 @@ var WSClient = class {
|
|
|
10447
11142
|
};
|
|
10448
11143
|
|
|
10449
11144
|
// src/version.ts
|
|
10450
|
-
var AGENT_VERSION = "0.1.
|
|
11145
|
+
var AGENT_VERSION = "0.1.9";
|
|
10451
11146
|
|
|
10452
11147
|
// src/sandbox.ts
|
|
10453
11148
|
async function runSandbox(config) {
|
|
@@ -10461,6 +11156,8 @@ async function runSandbox(config) {
|
|
|
10461
11156
|
let currentMaxIterations = config.maxIterations ?? 50;
|
|
10462
11157
|
let currentTaskId = config.taskId;
|
|
10463
11158
|
let currentConversationId = config.sessionId;
|
|
11159
|
+
let currentTeamId = config.teamId;
|
|
11160
|
+
let currentUser = config.currentUser;
|
|
10464
11161
|
console.info("[sandbox] Connecting to WS server", { wsUrl: config.wsUrl, sessionId: config.sessionId });
|
|
10465
11162
|
const wsClient = new WSClient(
|
|
10466
11163
|
config.wsUrl,
|
|
@@ -10479,7 +11176,10 @@ async function runSandbox(config) {
|
|
|
10479
11176
|
},
|
|
10480
11177
|
onStop: () => {
|
|
10481
11178
|
console.info("[sandbox] Stop signal received");
|
|
10482
|
-
if (currentAgent)
|
|
11179
|
+
if (currentAgent) {
|
|
11180
|
+
const killed = currentAgent.kill();
|
|
11181
|
+
if (!killed) currentAgent.abort();
|
|
11182
|
+
}
|
|
10483
11183
|
},
|
|
10484
11184
|
onToolResponse: (toolId, response) => {
|
|
10485
11185
|
if (currentAgent) {
|
|
@@ -10506,7 +11206,11 @@ async function runSandbox(config) {
|
|
|
10506
11206
|
presenter.setSuppressSessionLifecycle(true);
|
|
10507
11207
|
let lastProviderSessionId = config.providerSessionId;
|
|
10508
11208
|
let activeBackendKind = config.backendKind || "claude_cli";
|
|
11209
|
+
let activeAgentId = config.agentId;
|
|
11210
|
+
let activeAgentPrompt = config.agentPrompt;
|
|
10509
11211
|
let activeModel = config.model;
|
|
11212
|
+
let activeContextWindow = config.contextWindow;
|
|
11213
|
+
let activeEffortLevel = config.effortLevel;
|
|
10510
11214
|
let activeMode = config.mode || "agent";
|
|
10511
11215
|
while (!stopped) {
|
|
10512
11216
|
if (currentTask?.trim()) {
|
|
@@ -10522,12 +11226,18 @@ async function runSandbox(config) {
|
|
|
10522
11226
|
teamPath: config.projectPath,
|
|
10523
11227
|
cwd: config.projectPath,
|
|
10524
11228
|
backendKind: activeBackendKind,
|
|
11229
|
+
agentId: activeAgentId,
|
|
11230
|
+
agentPrompt: activeAgentPrompt,
|
|
10525
11231
|
mode: activeMode,
|
|
10526
11232
|
selectedModel: activeModel,
|
|
11233
|
+
selectedContextWindow: activeContextWindow ?? null,
|
|
11234
|
+
selectedEffortLevel: activeEffortLevel ?? null,
|
|
10527
11235
|
providerSessionId: lastProviderSessionId ?? void 0,
|
|
10528
11236
|
taskMeta: currentTaskMeta,
|
|
10529
11237
|
taskId: currentTaskId,
|
|
10530
11238
|
conversationId: currentConversationId,
|
|
11239
|
+
teamId: currentTeamId,
|
|
11240
|
+
currentUser,
|
|
10531
11241
|
workflowTools: currentWorkflowTools,
|
|
10532
11242
|
images: currentImages.length > 0 ? currentImages.map((img) => ({
|
|
10533
11243
|
id: img.id,
|
|
@@ -10563,9 +11273,21 @@ async function runSandbox(config) {
|
|
|
10563
11273
|
if (nextPayload.backendKind) {
|
|
10564
11274
|
activeBackendKind = nextPayload.backendKind;
|
|
10565
11275
|
}
|
|
11276
|
+
if (nextPayload.agentId !== void 0) {
|
|
11277
|
+
activeAgentId = nextPayload.agentId;
|
|
11278
|
+
}
|
|
11279
|
+
if (nextPayload.agentPrompt !== void 0) {
|
|
11280
|
+
activeAgentPrompt = nextPayload.agentPrompt;
|
|
11281
|
+
}
|
|
10566
11282
|
if (nextPayload.selectedModel) {
|
|
10567
11283
|
activeModel = nextPayload.selectedModel;
|
|
10568
11284
|
}
|
|
11285
|
+
if (nextPayload.selectedContextWindow !== void 0) {
|
|
11286
|
+
activeContextWindow = nextPayload.selectedContextWindow;
|
|
11287
|
+
}
|
|
11288
|
+
if (nextPayload.selectedEffortLevel !== void 0) {
|
|
11289
|
+
activeEffortLevel = nextPayload.selectedEffortLevel;
|
|
11290
|
+
}
|
|
10569
11291
|
if (nextPayload.mode) {
|
|
10570
11292
|
activeMode = nextPayload.mode;
|
|
10571
11293
|
}
|
|
@@ -10584,46 +11306,618 @@ async function runSandbox(config) {
|
|
|
10584
11306
|
if (nextPayload.conversationId !== void 0) {
|
|
10585
11307
|
currentConversationId = nextPayload.conversationId;
|
|
10586
11308
|
}
|
|
11309
|
+
if (nextPayload.currentUser !== void 0) {
|
|
11310
|
+
currentUser = nextPayload.currentUser;
|
|
11311
|
+
}
|
|
11312
|
+
if (nextPayload.teamId !== void 0) {
|
|
11313
|
+
currentTeamId = nextPayload.teamId;
|
|
11314
|
+
}
|
|
10587
11315
|
}
|
|
10588
11316
|
presenter.setSuppressSessionLifecycle(false);
|
|
10589
11317
|
wsClient.close();
|
|
10590
11318
|
}
|
|
10591
11319
|
|
|
11320
|
+
// src/daemon.ts
|
|
11321
|
+
var import_node_fs = require("fs");
|
|
11322
|
+
var import_node_http = __toESM(require("http"), 1);
|
|
11323
|
+
var import_node_crypto = require("crypto");
|
|
11324
|
+
var import_node_os = require("os");
|
|
11325
|
+
var import_node_path = require("path");
|
|
11326
|
+
var import_node_child_process = require("child_process");
|
|
11327
|
+
var CONFIG_PATH = process.env.AIDEN_AGENT_CONFIG_PATH ?? (0, import_node_path.join)((0, import_node_os.homedir)(), ".aiden", "agent", "config.json");
|
|
11328
|
+
function readConfig() {
|
|
11329
|
+
if (!(0, import_node_fs.existsSync)(CONFIG_PATH)) return {};
|
|
11330
|
+
return JSON.parse((0, import_node_fs.readFileSync)(CONFIG_PATH, "utf8"));
|
|
11331
|
+
}
|
|
11332
|
+
function writeConfig(config) {
|
|
11333
|
+
(0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(CONFIG_PATH), { recursive: true, mode: 448 });
|
|
11334
|
+
(0, import_node_fs.writeFileSync)(CONFIG_PATH, JSON.stringify(config, null, 2), { mode: 384 });
|
|
11335
|
+
}
|
|
11336
|
+
function removeConfig() {
|
|
11337
|
+
if ((0, import_node_fs.existsSync)(CONFIG_PATH)) (0, import_node_fs.rmSync)(CONFIG_PATH, { force: true });
|
|
11338
|
+
}
|
|
11339
|
+
function argValue(args, name) {
|
|
11340
|
+
const index = args.indexOf(name);
|
|
11341
|
+
if (index === -1) return void 0;
|
|
11342
|
+
return args[index + 1];
|
|
11343
|
+
}
|
|
11344
|
+
function getLocalApiPort(args, stored) {
|
|
11345
|
+
const raw = argValue(args, "--local-api-port") ?? process.env.AIDEN_AGENT_LOCAL_API_PORT;
|
|
11346
|
+
if (raw) return Number.parseInt(raw, 10);
|
|
11347
|
+
return stored.localApiPort ?? 47831;
|
|
11348
|
+
}
|
|
11349
|
+
function sleep(ms) {
|
|
11350
|
+
if (ms <= 0) return Promise.resolve();
|
|
11351
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
11352
|
+
}
|
|
11353
|
+
function commandVersion(command, args = ["--version"]) {
|
|
11354
|
+
const result = (0, import_node_child_process.spawnSync)(command, args, { encoding: "utf8", timeout: 3e3 });
|
|
11355
|
+
if (result.error || result.status !== 0) return void 0;
|
|
11356
|
+
return (result.stdout || result.stderr).split("\n")[0]?.trim() || void 0;
|
|
11357
|
+
}
|
|
11358
|
+
function discoverCapabilities() {
|
|
11359
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
11360
|
+
const providers = [
|
|
11361
|
+
{ provider: "claude_cli", command: process.env.AIDEN_CLAUDE_PATH ?? "claude" },
|
|
11362
|
+
{ provider: "codex", command: process.env.AIDEN_CODEX_PATH ?? "codex" },
|
|
11363
|
+
{ provider: "gemini", command: process.env.AIDEN_GEMINI_PATH ?? "gemini" }
|
|
11364
|
+
];
|
|
11365
|
+
return {
|
|
11366
|
+
agents: providers.map(({ provider, command }) => {
|
|
11367
|
+
const version = commandVersion(command);
|
|
11368
|
+
return {
|
|
11369
|
+
provider,
|
|
11370
|
+
available: Boolean(version),
|
|
11371
|
+
...version ? { version } : {},
|
|
11372
|
+
models: [],
|
|
11373
|
+
lastCheckedAt: now
|
|
11374
|
+
};
|
|
11375
|
+
}),
|
|
11376
|
+
hasGit: Boolean(commandVersion("git")),
|
|
11377
|
+
hasTerminal: true,
|
|
11378
|
+
supportsFilesystem: true
|
|
11379
|
+
};
|
|
11380
|
+
}
|
|
11381
|
+
var RuntimePresenter = class {
|
|
11382
|
+
constructor(socket, conversationId, runId) {
|
|
11383
|
+
this.socket = socket;
|
|
11384
|
+
this.conversationId = conversationId;
|
|
11385
|
+
this.runId = runId;
|
|
11386
|
+
}
|
|
11387
|
+
emitEvent(event) {
|
|
11388
|
+
this.socket.emit("agent.event", {
|
|
11389
|
+
conversationId: this.conversationId,
|
|
11390
|
+
runId: this.runId,
|
|
11391
|
+
event
|
|
11392
|
+
});
|
|
11393
|
+
}
|
|
11394
|
+
onStart(config) {
|
|
11395
|
+
this.emitEvent({ type: "start", task: config.task, ts: Date.now() });
|
|
11396
|
+
}
|
|
11397
|
+
onLog(message) {
|
|
11398
|
+
console.error(message);
|
|
11399
|
+
}
|
|
11400
|
+
onAssistantText(text) {
|
|
11401
|
+
this.emitEvent({ type: "text", text, ts: Date.now() });
|
|
11402
|
+
}
|
|
11403
|
+
onThinking(text) {
|
|
11404
|
+
this.emitEvent({ type: "thinking", text, ts: Date.now() });
|
|
11405
|
+
}
|
|
11406
|
+
onToolUse(tool, input, toolId) {
|
|
11407
|
+
this.emitEvent({ type: "tool_use", id: toolId, name: tool, input, ts: Date.now() });
|
|
11408
|
+
}
|
|
11409
|
+
onToolResult(toolId, content, isError) {
|
|
11410
|
+
this.emitEvent({
|
|
11411
|
+
type: "tool_result",
|
|
11412
|
+
id: toolId,
|
|
11413
|
+
content,
|
|
11414
|
+
ts: Date.now(),
|
|
11415
|
+
...isError ? { is_error: true } : {}
|
|
11416
|
+
});
|
|
11417
|
+
}
|
|
11418
|
+
onTurnComplete(content) {
|
|
11419
|
+
this.emitEvent({ type: "turn_complete", content, ts: Date.now() });
|
|
11420
|
+
}
|
|
11421
|
+
onUsageUpdate(usage) {
|
|
11422
|
+
this.emitEvent({ type: "usage", usage });
|
|
11423
|
+
}
|
|
11424
|
+
onAskUser(id, questions) {
|
|
11425
|
+
this.emitEvent({ type: "ask_user", id, questions });
|
|
11426
|
+
}
|
|
11427
|
+
onTodoWrite(todos) {
|
|
11428
|
+
this.emitEvent({ type: "todo_write", todos });
|
|
11429
|
+
}
|
|
11430
|
+
onExitPlanMode(id, input, planFilePath) {
|
|
11431
|
+
this.emitEvent({ type: "exit_plan_mode", id, input, ...planFilePath ? { planFilePath } : {} });
|
|
11432
|
+
}
|
|
11433
|
+
onCheckpoint(id) {
|
|
11434
|
+
this.emitEvent({ type: "checkpoint", id });
|
|
11435
|
+
}
|
|
11436
|
+
onActivity(status) {
|
|
11437
|
+
this.emitEvent({ type: "activity", status, ts: Date.now() });
|
|
11438
|
+
}
|
|
11439
|
+
onOpenBrowserTab(browserId, url2) {
|
|
11440
|
+
this.emitEvent({ type: "open_browser_tab", browserId, ...url2 ? { url: url2 } : {} });
|
|
11441
|
+
}
|
|
11442
|
+
recordRawTranscript() {
|
|
11443
|
+
}
|
|
11444
|
+
onError(message) {
|
|
11445
|
+
this.emitEvent({ type: "session_error", error: message });
|
|
11446
|
+
}
|
|
11447
|
+
onComplete(result) {
|
|
11448
|
+
this.emitEvent({ type: "query_complete", result, ts: Date.now() });
|
|
11449
|
+
}
|
|
11450
|
+
};
|
|
11451
|
+
async function setupDaemon(args) {
|
|
11452
|
+
const apiUrl = argValue(args, "--api-url") ?? process.env.AIDEN_API_URL ?? "http://localhost:8400";
|
|
11453
|
+
const wsUrl = argValue(args, "--ws-url") ?? process.env.AIDEN_WS_URL ?? "ws://localhost:8401";
|
|
11454
|
+
const teamId = argValue(args, "--team") ?? process.env.AIDEN_TEAM_ID;
|
|
11455
|
+
const setupToken = argValue(args, "--setup-token") ?? process.env.AIDEN_RUNTIME_SETUP_TOKEN;
|
|
11456
|
+
const token = argValue(args, "--token") ?? process.env.AIDEN_SETUP_TOKEN;
|
|
11457
|
+
const displayName = argValue(args, "--name") ?? (0, import_node_os.hostname)();
|
|
11458
|
+
const legacyLocalMachineId = argValue(args, "--legacy-local-machine-id") ?? process.env.AIDEN_LEGACY_LOCAL_MACHINE_ID;
|
|
11459
|
+
if (!setupToken && (!teamId || !token)) {
|
|
11460
|
+
throw new Error("setup requires --setup-token <token> or --team <team-id> and --token <aiden PAT>");
|
|
11461
|
+
}
|
|
11462
|
+
const response = await fetch(`${apiUrl}/public/runtimes${setupToken ? "/register-with-setup-token" : ""}`, {
|
|
11463
|
+
method: "POST",
|
|
11464
|
+
headers: {
|
|
11465
|
+
"content-type": "application/json",
|
|
11466
|
+
...setupToken ? {} : { authorization: `Bearer ${token}` }
|
|
11467
|
+
},
|
|
11468
|
+
body: JSON.stringify({
|
|
11469
|
+
...teamId ? { teamId } : {},
|
|
11470
|
+
...setupToken ? { setupToken } : {},
|
|
11471
|
+
displayName,
|
|
11472
|
+
hostname: (0, import_node_os.hostname)(),
|
|
11473
|
+
...legacyLocalMachineId ? { legacyLocalMachineId } : {},
|
|
11474
|
+
runtimeKind: "machine",
|
|
11475
|
+
managementKind: "user_managed",
|
|
11476
|
+
hostKind: "daemon",
|
|
11477
|
+
lifecycle: "durable",
|
|
11478
|
+
ownerType: "team",
|
|
11479
|
+
visibility: "team",
|
|
11480
|
+
capabilities: discoverCapabilities(),
|
|
11481
|
+
metadata: {
|
|
11482
|
+
platform: (0, import_node_os.platform)(),
|
|
11483
|
+
arch: (0, import_node_os.arch)(),
|
|
11484
|
+
agentVersion: AGENT_VERSION
|
|
11485
|
+
}
|
|
11486
|
+
})
|
|
11487
|
+
});
|
|
11488
|
+
if (!response.ok) {
|
|
11489
|
+
throw new Error(`runtime registration failed: ${response.status} ${await response.text()}`);
|
|
11490
|
+
}
|
|
11491
|
+
const body = await response.json();
|
|
11492
|
+
writeConfig({
|
|
11493
|
+
apiUrl,
|
|
11494
|
+
wsUrl,
|
|
11495
|
+
teamId,
|
|
11496
|
+
runtimeId: body.runtime.id,
|
|
11497
|
+
runtimeToken: body.runtimeToken,
|
|
11498
|
+
localApiPort: getLocalApiPort(args, {}),
|
|
11499
|
+
localApiToken: (0, import_node_crypto.randomBytes)(24).toString("hex"),
|
|
11500
|
+
displayName: body.runtime.displayName ?? displayName
|
|
11501
|
+
});
|
|
11502
|
+
console.info("[aiden-agent] Runtime registered", { runtimeId: body.runtime.id, configPath: CONFIG_PATH });
|
|
11503
|
+
}
|
|
11504
|
+
async function loginWithDeviceCode(args) {
|
|
11505
|
+
const apiUrl = argValue(args, "--api-url") ?? process.env.AIDEN_API_URL ?? "http://localhost:8400";
|
|
11506
|
+
const wsUrl = argValue(args, "--ws-url") ?? process.env.AIDEN_WS_URL ?? "ws://localhost:8401";
|
|
11507
|
+
const displayName = argValue(args, "--name") ?? (0, import_node_os.hostname)();
|
|
11508
|
+
const maxPolls = Number.parseInt(argValue(args, "--max-polls") ?? "300", 10);
|
|
11509
|
+
const start = await fetch(`${apiUrl}/public/runtimes/device-authorizations`, {
|
|
11510
|
+
method: "POST",
|
|
11511
|
+
headers: { "content-type": "application/json" },
|
|
11512
|
+
body: JSON.stringify({
|
|
11513
|
+
displayName,
|
|
11514
|
+
hostname: (0, import_node_os.hostname)(),
|
|
11515
|
+
capabilities: discoverCapabilities(),
|
|
11516
|
+
metadata: {
|
|
11517
|
+
platform: (0, import_node_os.platform)(),
|
|
11518
|
+
arch: (0, import_node_os.arch)(),
|
|
11519
|
+
agentVersion: AGENT_VERSION
|
|
11520
|
+
}
|
|
11521
|
+
})
|
|
11522
|
+
});
|
|
11523
|
+
if (!start.ok) {
|
|
11524
|
+
throw new Error(`device authorization failed: ${start.status} ${await start.text()}`);
|
|
11525
|
+
}
|
|
11526
|
+
const authorization = await start.json();
|
|
11527
|
+
const intervalMs = Math.max(0, (authorization.intervalSeconds ?? 2) * 1e3);
|
|
11528
|
+
console.info(`[aiden-agent] Open ${authorization.verificationUri}`);
|
|
11529
|
+
console.info(`[aiden-agent] Enter code ${authorization.userCode}`);
|
|
11530
|
+
for (let attempt = 0; attempt < maxPolls; attempt += 1) {
|
|
11531
|
+
if (attempt > 0) await sleep(intervalMs);
|
|
11532
|
+
const token = await fetch(`${apiUrl}/public/runtimes/device-authorizations/token`, {
|
|
11533
|
+
method: "POST",
|
|
11534
|
+
headers: { "content-type": "application/json" },
|
|
11535
|
+
body: JSON.stringify({ deviceCode: authorization.deviceCode })
|
|
11536
|
+
});
|
|
11537
|
+
if (token.status === 428) continue;
|
|
11538
|
+
if (!token.ok) {
|
|
11539
|
+
throw new Error(`device authorization token exchange failed: ${token.status} ${await token.text()}`);
|
|
11540
|
+
}
|
|
11541
|
+
const body = await token.json();
|
|
11542
|
+
writeConfig({
|
|
11543
|
+
apiUrl,
|
|
11544
|
+
wsUrl,
|
|
11545
|
+
teamId: body.runtime.teamId ?? void 0,
|
|
11546
|
+
runtimeId: body.runtime.id,
|
|
11547
|
+
runtimeToken: body.runtimeToken,
|
|
11548
|
+
localApiPort: getLocalApiPort(args, {}),
|
|
11549
|
+
localApiToken: (0, import_node_crypto.randomBytes)(24).toString("hex"),
|
|
11550
|
+
displayName: body.runtime.displayName ?? displayName
|
|
11551
|
+
});
|
|
11552
|
+
console.info("[aiden-agent] Runtime registered", { runtimeId: body.runtime.id, configPath: CONFIG_PATH });
|
|
11553
|
+
return;
|
|
11554
|
+
}
|
|
11555
|
+
throw new Error("device authorization timed out before approval");
|
|
11556
|
+
}
|
|
11557
|
+
async function startDaemon(args) {
|
|
11558
|
+
const stored = readConfig();
|
|
11559
|
+
const runtimeId = argValue(args, "--runtime-id") ?? process.env.AIDEN_RUNTIME_ID ?? stored.runtimeId;
|
|
11560
|
+
const runtimeToken = argValue(args, "--token") ?? process.env.AIDEN_RUNTIME_TOKEN ?? stored.runtimeToken;
|
|
11561
|
+
const wsUrl = argValue(args, "--ws-url") ?? process.env.AIDEN_WS_URL ?? stored.wsUrl;
|
|
11562
|
+
let localApiPort = getLocalApiPort(args, stored);
|
|
11563
|
+
const localApiToken = stored.localApiToken ?? (0, import_node_crypto.randomBytes)(24).toString("hex");
|
|
11564
|
+
if (!runtimeId || !runtimeToken || !wsUrl) {
|
|
11565
|
+
throw new Error("daemon requires runtimeId, runtime token, and wsUrl. Run setup first or pass --runtime-id/--token/--ws-url.");
|
|
11566
|
+
}
|
|
11567
|
+
const capabilities = discoverCapabilities();
|
|
11568
|
+
const activeAgents = /* @__PURE__ */ new Map();
|
|
11569
|
+
const recentLogs = [];
|
|
11570
|
+
const pushLog = (message) => {
|
|
11571
|
+
recentLogs.push(`${(/* @__PURE__ */ new Date()).toISOString()} ${message}`);
|
|
11572
|
+
if (recentLogs.length > 200) recentLogs.splice(0, recentLogs.length - 200);
|
|
11573
|
+
};
|
|
11574
|
+
if (stored.localApiPort !== localApiPort || stored.localApiToken !== localApiToken) {
|
|
11575
|
+
writeConfig({ ...stored, runtimeId, runtimeToken, wsUrl, localApiPort, localApiToken });
|
|
11576
|
+
}
|
|
11577
|
+
const socket = lookup(wsUrl, {
|
|
11578
|
+
query: { type: "runtime", runtimeId, hostKind: "daemon", agentVersion: AGENT_VERSION },
|
|
11579
|
+
auth: { token: runtimeToken },
|
|
11580
|
+
transports: ["websocket"],
|
|
11581
|
+
reconnection: true,
|
|
11582
|
+
reconnectionAttempts: Infinity,
|
|
11583
|
+
reconnectionDelay: 1e3,
|
|
11584
|
+
reconnectionDelayMax: 5e3,
|
|
11585
|
+
timeout: 2e4,
|
|
11586
|
+
upgrade: false,
|
|
11587
|
+
extraHeaders: { "ngrok-skip-browser-warning": "1" }
|
|
11588
|
+
});
|
|
11589
|
+
const heartbeat = setInterval(() => {
|
|
11590
|
+
if (socket.connected) socket.emit("runtime.heartbeat", { capabilities });
|
|
11591
|
+
}, 15e3);
|
|
11592
|
+
socket.on("connect", () => {
|
|
11593
|
+
pushLog(`connected runtime=${runtimeId}`);
|
|
11594
|
+
console.info("[aiden-agent] Daemon connected", { runtimeId, wsUrl, version: AGENT_VERSION });
|
|
11595
|
+
socket.emit("runtime.hello", { capabilities });
|
|
11596
|
+
});
|
|
11597
|
+
socket.on("connect_error", (error) => {
|
|
11598
|
+
pushLog(`connect_error ${error.message}`);
|
|
11599
|
+
console.warn("[aiden-agent] Daemon connection error:", error.message);
|
|
11600
|
+
});
|
|
11601
|
+
socket.on("disconnect", (reason) => {
|
|
11602
|
+
pushLog(`disconnected ${reason}`);
|
|
11603
|
+
console.info("[aiden-agent] Daemon disconnected:", reason);
|
|
11604
|
+
});
|
|
11605
|
+
socket.on("agent.execute", (payload) => {
|
|
11606
|
+
if (!payload?.runId || !payload.conversationId || typeof payload.content !== "string") {
|
|
11607
|
+
return;
|
|
11608
|
+
}
|
|
11609
|
+
if (activeAgents.has(payload.runId)) {
|
|
11610
|
+
socket.emit("agent.rejected", { runId: payload.runId, message: "Run is already active" });
|
|
11611
|
+
return;
|
|
11612
|
+
}
|
|
11613
|
+
socket.emit("agent.accepted", { runId: payload.runId });
|
|
11614
|
+
pushLog(`accepted run=${payload.runId}`);
|
|
11615
|
+
const presenter = new RuntimePresenter(socket, payload.conversationId, payload.runId);
|
|
11616
|
+
const agent = new CoreAgent(presenter, {
|
|
11617
|
+
backendKind: payload.backendKind
|
|
11618
|
+
});
|
|
11619
|
+
activeAgents.set(payload.runId, agent);
|
|
11620
|
+
const cwd = payload.projectPath ?? process.cwd();
|
|
11621
|
+
void agent.run({
|
|
11622
|
+
task: payload.content,
|
|
11623
|
+
maxIterations: payload.maxIterations ?? 50,
|
|
11624
|
+
teamPath: cwd,
|
|
11625
|
+
cwd,
|
|
11626
|
+
backendKind: payload.backendKind,
|
|
11627
|
+
agentId: payload.agentId,
|
|
11628
|
+
agentPrompt: payload.agentPrompt,
|
|
11629
|
+
mode: payload.mode ?? "agent",
|
|
11630
|
+
selectedModel: payload.model,
|
|
11631
|
+
selectedContextWindow: payload.selectedContextWindow ?? null,
|
|
11632
|
+
selectedEffortLevel: payload.selectedEffortLevel ?? null,
|
|
11633
|
+
providerSessionId: payload.providerSessionId,
|
|
11634
|
+
taskMeta: payload.taskMeta,
|
|
11635
|
+
conversationId: payload.conversationId,
|
|
11636
|
+
taskId: payload.taskMeta?.id,
|
|
11637
|
+
teamId: payload.teamId,
|
|
11638
|
+
currentUser: payload.currentUser,
|
|
11639
|
+
workflowTools: payload.workflowTools,
|
|
11640
|
+
images: payload.images
|
|
11641
|
+
}).catch((error) => {
|
|
11642
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
11643
|
+
pushLog(`failed run=${payload.runId} ${message}`);
|
|
11644
|
+
socket.emit("agent.event", {
|
|
11645
|
+
conversationId: payload.conversationId,
|
|
11646
|
+
runId: payload.runId,
|
|
11647
|
+
event: { type: "session_error", error: message }
|
|
11648
|
+
});
|
|
11649
|
+
}).finally(() => {
|
|
11650
|
+
activeAgents.delete(payload.runId);
|
|
11651
|
+
});
|
|
11652
|
+
});
|
|
11653
|
+
socket.on("agent.abort", (payload) => {
|
|
11654
|
+
if (!payload?.runId) return;
|
|
11655
|
+
const agent = activeAgents.get(payload.runId);
|
|
11656
|
+
if (!agent) return;
|
|
11657
|
+
agent.kill();
|
|
11658
|
+
activeAgents.delete(payload.runId);
|
|
11659
|
+
pushLog(`aborted run=${payload.runId}`);
|
|
11660
|
+
});
|
|
11661
|
+
socket.on("agent.tool_response", (payload) => {
|
|
11662
|
+
if (!payload?.toolId || typeof payload.response !== "string") return;
|
|
11663
|
+
const agents = payload.runId ? [activeAgents.get(payload.runId)] : [...activeAgents.values()];
|
|
11664
|
+
const delivered = agents.some((agent) => agent?.sendToolResponse(payload.toolId, payload.response) === true);
|
|
11665
|
+
if (!delivered) pushLog(`tool_response missed tool=${payload.toolId}`);
|
|
11666
|
+
});
|
|
11667
|
+
socket.on("agent.append_message", (payload) => {
|
|
11668
|
+
if (!payload?.runId || typeof payload.text !== "string") return;
|
|
11669
|
+
const agent = activeAgents.get(payload.runId);
|
|
11670
|
+
const delivered = agent?.sendUserMessage(payload.text) === true;
|
|
11671
|
+
socket.emit(delivered ? "agent.accepted" : "agent.rejected", {
|
|
11672
|
+
runId: payload.runId,
|
|
11673
|
+
...delivered ? {} : { message: "No active agent for appended message" }
|
|
11674
|
+
});
|
|
11675
|
+
});
|
|
11676
|
+
const localServer = import_node_http.default.createServer((req, res) => {
|
|
11677
|
+
const auth = req.headers.authorization;
|
|
11678
|
+
if (auth !== `Bearer ${localApiToken}`) {
|
|
11679
|
+
res.writeHead(401, { "content-type": "application/json" }).end(JSON.stringify({ error: "Unauthorized" }));
|
|
11680
|
+
return;
|
|
11681
|
+
}
|
|
11682
|
+
if (req.method === "GET" && req.url === "/status") {
|
|
11683
|
+
res.writeHead(200, { "content-type": "application/json" }).end(JSON.stringify({
|
|
11684
|
+
configured: true,
|
|
11685
|
+
runtimeId,
|
|
11686
|
+
wsUrl,
|
|
11687
|
+
connected: socket.connected,
|
|
11688
|
+
activeRunIds: [...activeAgents.keys()],
|
|
11689
|
+
localApiPort,
|
|
11690
|
+
version: AGENT_VERSION
|
|
11691
|
+
}));
|
|
11692
|
+
return;
|
|
11693
|
+
}
|
|
11694
|
+
if (req.method === "GET" && req.url === "/capabilities") {
|
|
11695
|
+
res.writeHead(200, { "content-type": "application/json" }).end(JSON.stringify(discoverCapabilities()));
|
|
11696
|
+
return;
|
|
11697
|
+
}
|
|
11698
|
+
if (req.method === "GET" && req.url === "/logs") {
|
|
11699
|
+
res.writeHead(200, { "content-type": "application/json" }).end(JSON.stringify({ lines: recentLogs }));
|
|
11700
|
+
return;
|
|
11701
|
+
}
|
|
11702
|
+
if (req.method === "POST" && req.url === "/stop") {
|
|
11703
|
+
for (const agent of activeAgents.values()) agent.kill();
|
|
11704
|
+
activeAgents.clear();
|
|
11705
|
+
res.writeHead(200, { "content-type": "application/json" }).end(JSON.stringify({ ok: true }));
|
|
11706
|
+
return;
|
|
11707
|
+
}
|
|
11708
|
+
res.writeHead(404, { "content-type": "application/json" }).end(JSON.stringify({ error: "Not found" }));
|
|
11709
|
+
});
|
|
11710
|
+
await new Promise((resolve2, reject) => {
|
|
11711
|
+
localServer.once("error", reject);
|
|
11712
|
+
localServer.listen(localApiPort, "127.0.0.1", () => {
|
|
11713
|
+
localServer.off("error", reject);
|
|
11714
|
+
const address = localServer.address();
|
|
11715
|
+
if (address && typeof address === "object") localApiPort = address.port;
|
|
11716
|
+
pushLog(`local_api listening port=${localApiPort}`);
|
|
11717
|
+
console.info("[aiden-agent] Local daemon API listening", { port: localApiPort });
|
|
11718
|
+
resolve2();
|
|
11719
|
+
});
|
|
11720
|
+
});
|
|
11721
|
+
let stopped = false;
|
|
11722
|
+
const stop = async () => {
|
|
11723
|
+
if (stopped) return;
|
|
11724
|
+
stopped = true;
|
|
11725
|
+
clearInterval(heartbeat);
|
|
11726
|
+
for (const agent of activeAgents.values()) {
|
|
11727
|
+
agent.kill();
|
|
11728
|
+
}
|
|
11729
|
+
activeAgents.clear();
|
|
11730
|
+
socket.disconnect();
|
|
11731
|
+
await new Promise((resolve2) => {
|
|
11732
|
+
localServer.close(() => resolve2());
|
|
11733
|
+
});
|
|
11734
|
+
};
|
|
11735
|
+
return { runtimeId, wsUrl, localApiPort, localApiToken, stop };
|
|
11736
|
+
}
|
|
11737
|
+
async function runDaemon(args) {
|
|
11738
|
+
const controller = await startDaemon(args);
|
|
11739
|
+
const shutdown = () => {
|
|
11740
|
+
void controller.stop().finally(() => process.exit(0));
|
|
11741
|
+
};
|
|
11742
|
+
process.once("SIGINT", shutdown);
|
|
11743
|
+
process.once("SIGTERM", shutdown);
|
|
11744
|
+
await new Promise(() => {
|
|
11745
|
+
});
|
|
11746
|
+
}
|
|
11747
|
+
async function rotateRuntimeToken(args) {
|
|
11748
|
+
const stored = readConfig();
|
|
11749
|
+
const apiUrl = argValue(args, "--api-url") ?? process.env.AIDEN_API_URL ?? stored.apiUrl;
|
|
11750
|
+
const runtimeId = argValue(args, "--runtime-id") ?? process.env.AIDEN_RUNTIME_ID ?? stored.runtimeId;
|
|
11751
|
+
const token = argValue(args, "--token") ?? process.env.AIDEN_SETUP_TOKEN;
|
|
11752
|
+
if (!apiUrl || !runtimeId || !token) {
|
|
11753
|
+
throw new Error("token rotate requires configured api/runtime plus --token <aiden PAT>");
|
|
11754
|
+
}
|
|
11755
|
+
const response = await fetch(`${apiUrl}/public/runtimes/${runtimeId}/tokens/rotate`, {
|
|
11756
|
+
method: "POST",
|
|
11757
|
+
headers: { authorization: `Bearer ${token}` }
|
|
11758
|
+
});
|
|
11759
|
+
if (!response.ok) {
|
|
11760
|
+
throw new Error(`runtime token rotation failed: ${response.status} ${await response.text()}`);
|
|
11761
|
+
}
|
|
11762
|
+
const body = await response.json();
|
|
11763
|
+
writeConfig({ ...stored, apiUrl, runtimeId, runtimeToken: body.runtimeToken });
|
|
11764
|
+
console.info("[aiden-agent] Runtime token rotated", { runtimeId });
|
|
11765
|
+
}
|
|
11766
|
+
async function revokeRuntimeToken(args) {
|
|
11767
|
+
const stored = readConfig();
|
|
11768
|
+
const apiUrl = argValue(args, "--api-url") ?? process.env.AIDEN_API_URL ?? stored.apiUrl;
|
|
11769
|
+
const runtimeId = argValue(args, "--runtime-id") ?? process.env.AIDEN_RUNTIME_ID ?? stored.runtimeId;
|
|
11770
|
+
const token = argValue(args, "--token") ?? process.env.AIDEN_SETUP_TOKEN;
|
|
11771
|
+
if (!apiUrl || !runtimeId || !token) {
|
|
11772
|
+
throw new Error("token revoke requires configured api/runtime plus --token <aiden PAT>");
|
|
11773
|
+
}
|
|
11774
|
+
const response = await fetch(`${apiUrl}/public/runtimes/${runtimeId}/tokens/revoke`, {
|
|
11775
|
+
method: "POST",
|
|
11776
|
+
headers: { authorization: `Bearer ${token}` }
|
|
11777
|
+
});
|
|
11778
|
+
if (!response.ok) {
|
|
11779
|
+
throw new Error(`runtime token revoke failed: ${response.status} ${await response.text()}`);
|
|
11780
|
+
}
|
|
11781
|
+
removeConfig();
|
|
11782
|
+
console.info("[aiden-agent] Runtime token revoked", { runtimeId });
|
|
11783
|
+
}
|
|
11784
|
+
function logoutDaemon() {
|
|
11785
|
+
removeConfig();
|
|
11786
|
+
console.info("[aiden-agent] Runtime config removed", { configPath: CONFIG_PATH });
|
|
11787
|
+
}
|
|
11788
|
+
function printStatus() {
|
|
11789
|
+
const config = readConfig();
|
|
11790
|
+
console.info(JSON.stringify({
|
|
11791
|
+
configured: Boolean(config.runtimeId && config.runtimeToken && config.wsUrl),
|
|
11792
|
+
runtimeId: config.runtimeId ?? null,
|
|
11793
|
+
wsUrl: config.wsUrl ?? null,
|
|
11794
|
+
localApiPort: config.localApiPort ?? null,
|
|
11795
|
+
hasLocalApiToken: Boolean(config.localApiToken),
|
|
11796
|
+
configPath: CONFIG_PATH
|
|
11797
|
+
}, null, 2));
|
|
11798
|
+
}
|
|
11799
|
+
async function printDoctor(args = []) {
|
|
11800
|
+
const config = readConfig();
|
|
11801
|
+
const capabilities = discoverCapabilities();
|
|
11802
|
+
let synced = false;
|
|
11803
|
+
let syncError = null;
|
|
11804
|
+
if (args.includes("--sync")) {
|
|
11805
|
+
if (!config.apiUrl || !config.runtimeId || !config.runtimeToken) {
|
|
11806
|
+
throw new Error("doctor --sync requires configured apiUrl, runtimeId, and runtimeToken. Run setup first.");
|
|
11807
|
+
}
|
|
11808
|
+
const response = await fetch(`${config.apiUrl}/public/runtimes/${config.runtimeId}/capabilities/self`, {
|
|
11809
|
+
method: "PATCH",
|
|
11810
|
+
headers: {
|
|
11811
|
+
authorization: `Bearer ${config.runtimeToken}`,
|
|
11812
|
+
"content-type": "application/json"
|
|
11813
|
+
},
|
|
11814
|
+
body: JSON.stringify({ capabilities })
|
|
11815
|
+
});
|
|
11816
|
+
if (!response.ok) {
|
|
11817
|
+
syncError = `${response.status} ${await response.text()}`;
|
|
11818
|
+
throw new Error(`doctor sync failed: ${syncError}`);
|
|
11819
|
+
}
|
|
11820
|
+
synced = true;
|
|
11821
|
+
}
|
|
11822
|
+
console.info(JSON.stringify({
|
|
11823
|
+
version: AGENT_VERSION,
|
|
11824
|
+
configPath: CONFIG_PATH,
|
|
11825
|
+
configured: Boolean(config.runtimeId && config.runtimeToken && config.wsUrl),
|
|
11826
|
+
runtimeId: config.runtimeId ?? null,
|
|
11827
|
+
wsUrl: config.wsUrl ?? null,
|
|
11828
|
+
synced,
|
|
11829
|
+
syncError,
|
|
11830
|
+
capabilities
|
|
11831
|
+
}, null, 2));
|
|
11832
|
+
}
|
|
11833
|
+
|
|
10592
11834
|
// src/index.ts
|
|
10593
|
-
|
|
10594
|
-
process.
|
|
10595
|
-
|
|
10596
|
-
process.
|
|
11835
|
+
async function runSessionFromEnv() {
|
|
11836
|
+
const wsUrl = process.env.AIDEN_WS_URL;
|
|
11837
|
+
const sessionId = process.env.AIDEN_SESSION_ID;
|
|
11838
|
+
const taskId = process.env.AIDEN_TASK_ID;
|
|
11839
|
+
const sessionToken = process.env.AIDEN_SESSION_TOKEN;
|
|
11840
|
+
const task = process.env.AIDEN_TASK;
|
|
11841
|
+
const teamId = process.env.AIDEN_TEAM_ID || void 0;
|
|
11842
|
+
const projectPath = process.env.AIDEN_PROJECT_PATH || "/home/user/workspace";
|
|
11843
|
+
const backendKind = process.env.AIDEN_BACKEND_KIND || "claude_cli";
|
|
11844
|
+
const agentId = process.env.AIDEN_AGENT_ID || void 0;
|
|
11845
|
+
const agentPrompt = process.env.AIDEN_AGENT_PROMPT || void 0;
|
|
11846
|
+
const mode = process.env.AIDEN_MODE || "agent";
|
|
11847
|
+
const model = process.env.AIDEN_MODEL;
|
|
11848
|
+
const contextWindow = process.env.AIDEN_CONTEXT_WINDOW || void 0;
|
|
11849
|
+
const effortLevel = process.env.AIDEN_EFFORT_LEVEL || void 0;
|
|
11850
|
+
const providerSessionId = process.env.AIDEN_PROVIDER_SESSION_ID || void 0;
|
|
11851
|
+
if (!wsUrl || !sessionId || !taskId || !sessionToken || task == null) {
|
|
11852
|
+
throw new Error("Missing required env vars: AIDEN_WS_URL, AIDEN_SESSION_ID, AIDEN_TASK_ID, AIDEN_SESSION_TOKEN, AIDEN_TASK");
|
|
11853
|
+
}
|
|
11854
|
+
console.info("[aiden-agent] Starting", { sessionId, taskId, projectPath, backendKind, agentId, mode, model, version: AGENT_VERSION });
|
|
11855
|
+
await runSandbox({
|
|
11856
|
+
wsUrl,
|
|
11857
|
+
sessionId,
|
|
11858
|
+
taskId,
|
|
11859
|
+
sessionToken,
|
|
11860
|
+
task,
|
|
11861
|
+
teamId,
|
|
11862
|
+
projectPath,
|
|
11863
|
+
backendKind,
|
|
11864
|
+
agentId,
|
|
11865
|
+
agentPrompt,
|
|
11866
|
+
mode,
|
|
11867
|
+
model,
|
|
11868
|
+
contextWindow,
|
|
11869
|
+
effortLevel,
|
|
11870
|
+
providerSessionId,
|
|
11871
|
+
maxIterations: 50
|
|
11872
|
+
});
|
|
10597
11873
|
}
|
|
10598
|
-
|
|
10599
|
-
|
|
10600
|
-
|
|
10601
|
-
|
|
10602
|
-
|
|
10603
|
-
|
|
10604
|
-
|
|
10605
|
-
|
|
10606
|
-
|
|
10607
|
-
|
|
10608
|
-
|
|
10609
|
-
|
|
10610
|
-
|
|
11874
|
+
async function main() {
|
|
11875
|
+
if (process.argv.includes("--version")) {
|
|
11876
|
+
process.stdout.write(`${AGENT_VERSION}
|
|
11877
|
+
`);
|
|
11878
|
+
return;
|
|
11879
|
+
}
|
|
11880
|
+
const [command = "run-session", ...commandArgs] = process.argv.slice(2);
|
|
11881
|
+
if (command === "setup") {
|
|
11882
|
+
await setupDaemon(commandArgs);
|
|
11883
|
+
return;
|
|
11884
|
+
}
|
|
11885
|
+
if (command === "login") {
|
|
11886
|
+
await loginWithDeviceCode(commandArgs);
|
|
11887
|
+
return;
|
|
11888
|
+
}
|
|
11889
|
+
if (command === "daemon") {
|
|
11890
|
+
await runDaemon(commandArgs);
|
|
11891
|
+
return;
|
|
11892
|
+
}
|
|
11893
|
+
if (command === "status") {
|
|
11894
|
+
printStatus();
|
|
11895
|
+
return;
|
|
11896
|
+
}
|
|
11897
|
+
if (command === "doctor") {
|
|
11898
|
+
await printDoctor(commandArgs);
|
|
11899
|
+
return;
|
|
11900
|
+
}
|
|
11901
|
+
if (command === "token" && commandArgs[0] === "rotate") {
|
|
11902
|
+
await rotateRuntimeToken(commandArgs.slice(1));
|
|
11903
|
+
return;
|
|
11904
|
+
}
|
|
11905
|
+
if (command === "token" && commandArgs[0] === "revoke") {
|
|
11906
|
+
await revokeRuntimeToken(commandArgs.slice(1));
|
|
11907
|
+
return;
|
|
11908
|
+
}
|
|
11909
|
+
if (command === "logout") {
|
|
11910
|
+
logoutDaemon();
|
|
11911
|
+
return;
|
|
11912
|
+
}
|
|
11913
|
+
if (command === "run-session") {
|
|
11914
|
+
await runSessionFromEnv();
|
|
11915
|
+
return;
|
|
11916
|
+
}
|
|
11917
|
+
throw new Error(`Unknown command: ${command}`);
|
|
10611
11918
|
}
|
|
10612
|
-
|
|
10613
|
-
|
|
10614
|
-
wsUrl,
|
|
10615
|
-
sessionId,
|
|
10616
|
-
taskId,
|
|
10617
|
-
sessionToken,
|
|
10618
|
-
task,
|
|
10619
|
-
projectPath,
|
|
10620
|
-
backendKind,
|
|
10621
|
-
mode,
|
|
10622
|
-
model,
|
|
10623
|
-
providerSessionId,
|
|
10624
|
-
maxIterations: 50
|
|
10625
|
-
}).catch((error) => {
|
|
10626
|
-
console.error("[aiden-agent] Fatal error:", error);
|
|
11919
|
+
main().catch((error) => {
|
|
11920
|
+
console.error("[aiden-agent] Fatal error:", error instanceof Error ? error.message : error);
|
|
10627
11921
|
process.exit(1);
|
|
10628
11922
|
});
|
|
10629
11923
|
/*! Bundled license information:
|