@aiden-ade/sandbox-agent 0.1.8 → 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 +1299 -207
- 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 +5 -3
- 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)."
|
|
4842
4958
|
|
|
4843
|
-
|
|
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
|
|
4988
|
+
|
|
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.
|
|
4862
5159
|
|
|
4863
|
-
##
|
|
5160
|
+
## Universal teammate principles
|
|
5161
|
+
|
|
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.";
|
|
@@ -5212,8 +5528,8 @@ function parseClaudeStructuredLine(line, context, state) {
|
|
|
5212
5528
|
switch (type) {
|
|
5213
5529
|
case "system": {
|
|
5214
5530
|
if (parsed.subtype === "init") {
|
|
5215
|
-
const
|
|
5216
|
-
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}`);
|
|
5217
5533
|
}
|
|
5218
5534
|
break;
|
|
5219
5535
|
}
|
|
@@ -5534,8 +5850,9 @@ function parseCodexStructuredLine(line, context, state) {
|
|
|
5534
5850
|
case "error": {
|
|
5535
5851
|
const message = extractCodexErrorMessage(parsed.message) || extractCodexErrorMessage(parsed.error) || typeof parsed.detail === "string" && parsed.detail.trim() || "";
|
|
5536
5852
|
if (message) {
|
|
5537
|
-
|
|
5538
|
-
|
|
5853
|
+
const normalizedMessage = normalizeCodexCliErrorMessage(message);
|
|
5854
|
+
void presenter.onError(normalizedMessage);
|
|
5855
|
+
state.error = normalizedMessage;
|
|
5539
5856
|
}
|
|
5540
5857
|
break;
|
|
5541
5858
|
}
|
|
@@ -5543,8 +5860,9 @@ function parseCodexStructuredLine(line, context, state) {
|
|
|
5543
5860
|
const error = typeof parsed.error === "object" && parsed.error !== null ? parsed.error : {};
|
|
5544
5861
|
const message = extractCodexErrorMessage(error.message) || extractCodexErrorMessage(error.detail) || typeof parsed.message === "string" && parsed.message.trim() || "";
|
|
5545
5862
|
if (message) {
|
|
5546
|
-
|
|
5547
|
-
|
|
5863
|
+
const normalizedMessage = normalizeCodexCliErrorMessage(message);
|
|
5864
|
+
void presenter.onError(normalizedMessage);
|
|
5865
|
+
state.error = normalizedMessage;
|
|
5548
5866
|
}
|
|
5549
5867
|
break;
|
|
5550
5868
|
}
|
|
@@ -5798,8 +6116,8 @@ function parseGeminiStructuredLine(line, context, state) {
|
|
|
5798
6116
|
if (typeof parsed.model === "string") state.activeModel = parsed.model;
|
|
5799
6117
|
switch (type) {
|
|
5800
6118
|
case "init": {
|
|
5801
|
-
const
|
|
5802
|
-
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}`);
|
|
5803
6121
|
break;
|
|
5804
6122
|
}
|
|
5805
6123
|
case "message": {
|
|
@@ -5874,8 +6192,19 @@ function parseGeminiStructuredLine(line, context, state) {
|
|
|
5874
6192
|
break;
|
|
5875
6193
|
}
|
|
5876
6194
|
}
|
|
5877
|
-
function
|
|
5878
|
-
|
|
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) {
|
|
5879
6208
|
case "plan":
|
|
5880
6209
|
case "ask":
|
|
5881
6210
|
case "review":
|
|
@@ -5884,11 +6213,12 @@ function getClaudePermissionMode(mode2) {
|
|
|
5884
6213
|
return "bypassPermissions";
|
|
5885
6214
|
}
|
|
5886
6215
|
}
|
|
5887
|
-
function
|
|
5888
|
-
return
|
|
6216
|
+
function getClaudeDisallowedTools(config) {
|
|
6217
|
+
return isReadOnlyAgent(config.agentId) ? ["Edit", "Write", "MultiEdit", "NotebookEdit"] : [];
|
|
5889
6218
|
}
|
|
5890
|
-
function shouldForceCursorAgent(
|
|
5891
|
-
|
|
6219
|
+
function shouldForceCursorAgent(config) {
|
|
6220
|
+
if (shouldUseReadOnlyRuntimePermissions(config)) return false;
|
|
6221
|
+
switch (config.mode) {
|
|
5892
6222
|
case "plan":
|
|
5893
6223
|
case "ask":
|
|
5894
6224
|
case "review":
|
|
@@ -5919,6 +6249,10 @@ function writeImagesToTempFiles(images) {
|
|
|
5919
6249
|
}
|
|
5920
6250
|
};
|
|
5921
6251
|
}
|
|
6252
|
+
function buildClaudeModelArg(baseModel, selectedContextWindow) {
|
|
6253
|
+
if (selectedContextWindow === "1m") return `${baseModel}[1m]`;
|
|
6254
|
+
return baseModel;
|
|
6255
|
+
}
|
|
5922
6256
|
function createClaudeCliBackend(command = "claude", defaultArgs = []) {
|
|
5923
6257
|
return {
|
|
5924
6258
|
kind: "claude_cli",
|
|
@@ -5931,8 +6265,12 @@ function createClaudeCliBackend(command = "claude", defaultArgs = []) {
|
|
|
5931
6265
|
"--input-format",
|
|
5932
6266
|
"stream-json",
|
|
5933
6267
|
"--permission-mode",
|
|
5934
|
-
getClaudePermissionMode(context.config
|
|
6268
|
+
getClaudePermissionMode(context.config)
|
|
5935
6269
|
];
|
|
6270
|
+
const disallowedTools = getClaudeDisallowedTools(context.config);
|
|
6271
|
+
if (disallowedTools.length > 0) {
|
|
6272
|
+
args.push("--disallowedTools", disallowedTools.join(","));
|
|
6273
|
+
}
|
|
5936
6274
|
const resumeId = context.config.runtimeSessionId?.trim() || context.config.providerSessionId?.trim();
|
|
5937
6275
|
if (!resumeId) {
|
|
5938
6276
|
if (context.config.systemPrompt?.trim()) {
|
|
@@ -5942,8 +6280,13 @@ function createClaudeCliBackend(command = "claude", defaultArgs = []) {
|
|
|
5942
6280
|
args.push("--append-system-prompt", context.config.systemPromptAppend.trim());
|
|
5943
6281
|
}
|
|
5944
6282
|
}
|
|
5945
|
-
|
|
5946
|
-
|
|
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);
|
|
5947
6290
|
}
|
|
5948
6291
|
if (resumeId) {
|
|
5949
6292
|
args.push("--resume", resumeId);
|
|
@@ -5997,11 +6340,11 @@ function kimiSessionId(cwd) {
|
|
|
5997
6340
|
}
|
|
5998
6341
|
return (0, import_crypto.createHash)("md5").update(resolved).digest("hex");
|
|
5999
6342
|
}
|
|
6000
|
-
function shouldEnableKimiCliThinking(
|
|
6001
|
-
return
|
|
6343
|
+
function shouldEnableKimiCliThinking(model) {
|
|
6344
|
+
return model?.trim() === "kimi-k2.6-thinking";
|
|
6002
6345
|
}
|
|
6003
|
-
function resolveKimiCliModelArg(
|
|
6004
|
-
const trimmed =
|
|
6346
|
+
function resolveKimiCliModelArg(model) {
|
|
6347
|
+
const trimmed = model?.trim();
|
|
6005
6348
|
if (!trimmed) return void 0;
|
|
6006
6349
|
if (trimmed === "kimi-latest" || trimmed === "kimi-k2.5" || trimmed === "kimi-k2.6" || shouldEnableKimiCliThinking(trimmed)) {
|
|
6007
6350
|
return void 0;
|
|
@@ -6088,8 +6431,8 @@ function createKimiCliBackend(command = "kimi", defaultArgs = []) {
|
|
|
6088
6431
|
if (shouldEnableKimiCliThinking(context.config.selectedModel)) {
|
|
6089
6432
|
args.push("--thinking");
|
|
6090
6433
|
}
|
|
6091
|
-
const
|
|
6092
|
-
if (
|
|
6434
|
+
const model = resolveKimiCliModelArg(context.config.selectedModel);
|
|
6435
|
+
if (model) args.push("--model", model);
|
|
6093
6436
|
return [...args, ...defaultArgs, "--prompt", prompt];
|
|
6094
6437
|
},
|
|
6095
6438
|
augmentPrompt: (context) => {
|
|
@@ -6122,8 +6465,8 @@ function createGeminiCliBackend(command = "gemini", defaultArgs = []) {
|
|
|
6122
6465
|
parseStructuredLine: parseGeminiStructuredLine
|
|
6123
6466
|
});
|
|
6124
6467
|
}
|
|
6125
|
-
function isCursorAgentCliModelId(
|
|
6126
|
-
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);
|
|
6127
6470
|
}
|
|
6128
6471
|
function createCursorAgentCliBackend(command = "cursor-agent", defaultArgs = []) {
|
|
6129
6472
|
return createGenericCliBackend({
|
|
@@ -6134,10 +6477,10 @@ function createCursorAgentCliBackend(command = "cursor-agent", defaultArgs = [])
|
|
|
6134
6477
|
buildArgs: (context, prompt) => {
|
|
6135
6478
|
const args = ["--print", "--output-format", "stream-json"];
|
|
6136
6479
|
const resumeId = context.config.runtimeSessionId?.trim() || context.config.providerSessionId?.trim();
|
|
6137
|
-
if (shouldForceCursorAgent(context.config
|
|
6480
|
+
if (shouldForceCursorAgent(context.config)) args.push("--force");
|
|
6138
6481
|
if (resumeId) args.push("--resume", resumeId);
|
|
6139
|
-
const
|
|
6140
|
-
if (
|
|
6482
|
+
const model = context.config.selectedModel?.trim();
|
|
6483
|
+
if (model && isCursorAgentCliModelId(model)) args.push("--model", model);
|
|
6141
6484
|
return [...args, ...defaultArgs, prompt];
|
|
6142
6485
|
},
|
|
6143
6486
|
augmentPrompt: (context) => {
|
|
@@ -6147,8 +6490,8 @@ function createCursorAgentCliBackend(command = "cursor-agent", defaultArgs = [])
|
|
|
6147
6490
|
parseStructuredLine: parseCursorStructuredLine
|
|
6148
6491
|
});
|
|
6149
6492
|
}
|
|
6150
|
-
function droidExecPermissionArgs(
|
|
6151
|
-
if (
|
|
6493
|
+
function droidExecPermissionArgs(mode) {
|
|
6494
|
+
if (mode === "plan" || mode === "ask" || mode === "review") return [];
|
|
6152
6495
|
return ["--auto", "high"];
|
|
6153
6496
|
}
|
|
6154
6497
|
function parseDroidStructuredLine(line, context, state) {
|
|
@@ -6247,8 +6590,8 @@ function createDroidCliBackend(command = "droid", defaultArgs = []) {
|
|
|
6247
6590
|
];
|
|
6248
6591
|
const resumeId = context.config.runtimeSessionId?.trim() || context.config.providerSessionId?.trim();
|
|
6249
6592
|
if (resumeId) args.push("--session-id", resumeId);
|
|
6250
|
-
const
|
|
6251
|
-
if (
|
|
6593
|
+
const model = context.config.selectedModel?.trim();
|
|
6594
|
+
if (model) args.push("-m", model);
|
|
6252
6595
|
args.push(prompt);
|
|
6253
6596
|
return args;
|
|
6254
6597
|
},
|
|
@@ -6370,8 +6713,8 @@ function createOpencodeCliBackend(command = "opencode", defaultArgs = []) {
|
|
|
6370
6713
|
const args = ["run", "--format", "json"];
|
|
6371
6714
|
const resumeId = ctx.config.runtimeSessionId?.trim() || ctx.config.providerSessionId?.trim();
|
|
6372
6715
|
if (resumeId) args.push("--session", resumeId);
|
|
6373
|
-
const
|
|
6374
|
-
if (
|
|
6716
|
+
const model = ctx.config.selectedModel?.trim();
|
|
6717
|
+
if (model && model.includes("/")) args.push("--model", model);
|
|
6375
6718
|
const fileArgs = imagePaths.flatMap((p) => ["--file", p]);
|
|
6376
6719
|
if (fileArgs.length > 0) {
|
|
6377
6720
|
return [...args, ...fileArgs, ...defaultArgs, "--", prompt];
|
|
@@ -6399,6 +6742,11 @@ function createGenericCliPassthroughBackend(command, defaultArgs = []) {
|
|
|
6399
6742
|
promptViaStdin: true
|
|
6400
6743
|
});
|
|
6401
6744
|
}
|
|
6745
|
+
function buildCodexEffortArgs(selectedEffortLevel) {
|
|
6746
|
+
const level = selectedEffortLevel?.trim();
|
|
6747
|
+
if (!level) return [];
|
|
6748
|
+
return ["-c", `model_reasoning_effort=${level}`];
|
|
6749
|
+
}
|
|
6402
6750
|
function createCodexRuntimeBackend(command = "codex", defaultArgs = []) {
|
|
6403
6751
|
return {
|
|
6404
6752
|
kind: "codex_app_server",
|
|
@@ -6414,9 +6762,10 @@ function createCodexRuntimeBackend(command = "codex", defaultArgs = []) {
|
|
|
6414
6762
|
buildArgs: (ctx) => {
|
|
6415
6763
|
const resumeId = ctx.config.runtimeSessionId?.trim() || ctx.config.providerSessionId?.trim();
|
|
6416
6764
|
const modelArgs = ctx.config.selectedModel?.trim() ? ["--model", ctx.config.selectedModel.trim()] : [];
|
|
6417
|
-
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"];
|
|
6418
6767
|
const imageArgs = imagePaths.flatMap((p) => ["--image", p]);
|
|
6419
|
-
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, "-"];
|
|
6420
6769
|
return [...baseArgs, ...defaultArgs];
|
|
6421
6770
|
},
|
|
6422
6771
|
promptViaStdin: true,
|
|
@@ -6433,10 +6782,86 @@ function createCodexRuntimeBackend(command = "codex", defaultArgs = []) {
|
|
|
6433
6782
|
}
|
|
6434
6783
|
};
|
|
6435
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
|
+
}
|
|
6436
6861
|
function createCopilotCliBackend(command = "copilot", defaultArgs = []) {
|
|
6437
6862
|
return createGenericCliBackend({
|
|
6438
6863
|
kind: "copilot_cli",
|
|
6439
|
-
supportTier: "
|
|
6864
|
+
supportTier: "structured",
|
|
6440
6865
|
command,
|
|
6441
6866
|
args: [],
|
|
6442
6867
|
buildArgs: (context, prompt) => {
|
|
@@ -6446,6 +6871,10 @@ function createCopilotCliBackend(command = "copilot", defaultArgs = []) {
|
|
|
6446
6871
|
"--max-autopilot-continues",
|
|
6447
6872
|
"20",
|
|
6448
6873
|
"-s",
|
|
6874
|
+
"--stream",
|
|
6875
|
+
"on",
|
|
6876
|
+
"--output-format",
|
|
6877
|
+
"json",
|
|
6449
6878
|
"-p",
|
|
6450
6879
|
prompt
|
|
6451
6880
|
];
|
|
@@ -6453,13 +6882,14 @@ function createCopilotCliBackend(command = "copilot", defaultArgs = []) {
|
|
|
6453
6882
|
args.push("--model", context.config.selectedModel.trim());
|
|
6454
6883
|
}
|
|
6455
6884
|
return [...args, ...defaultArgs];
|
|
6456
|
-
}
|
|
6885
|
+
},
|
|
6886
|
+
parseStructuredLine: parseCopilotStructuredLine
|
|
6457
6887
|
});
|
|
6458
6888
|
}
|
|
6459
6889
|
var DEFAULT_MODEL = "claude-sonnet-4-6";
|
|
6460
6890
|
var DROID_DEFAULT_MODEL = "claude-opus-4-7";
|
|
6461
|
-
function defaultSelectedModelForBackend(
|
|
6462
|
-
switch (
|
|
6891
|
+
function defaultSelectedModelForBackend(backendKind) {
|
|
6892
|
+
switch (backendKind) {
|
|
6463
6893
|
case "droid_cli":
|
|
6464
6894
|
return DROID_DEFAULT_MODEL;
|
|
6465
6895
|
case "copilot_cli":
|
|
@@ -6478,10 +6908,10 @@ function canonicalizePath(inputPath) {
|
|
|
6478
6908
|
return null;
|
|
6479
6909
|
}
|
|
6480
6910
|
}
|
|
6481
|
-
function buildPromptWithFiles(
|
|
6482
|
-
if (!files || files.length === 0) return
|
|
6911
|
+
function buildPromptWithFiles(task, files) {
|
|
6912
|
+
if (!files || files.length === 0) return task;
|
|
6483
6913
|
const fileList = files.map((file) => `- ${file.filename} (${file.label}): ${file.tempPath}`).join("\n");
|
|
6484
|
-
return `${
|
|
6914
|
+
return `${task}
|
|
6485
6915
|
|
|
6486
6916
|
The user has attached the following files. You can read them using your available tools:
|
|
6487
6917
|
${fileList}`;
|
|
@@ -6557,16 +6987,16 @@ var BaseMachineAgent = class _BaseMachineAgent {
|
|
|
6557
6987
|
resolveBackendKind(config) {
|
|
6558
6988
|
return this.runtime.backendKind || config.backendKind || "claude_cli";
|
|
6559
6989
|
}
|
|
6560
|
-
getDefaultSupportTier(
|
|
6561
|
-
switch (
|
|
6990
|
+
getDefaultSupportTier(backendKind) {
|
|
6991
|
+
switch (backendKind) {
|
|
6562
6992
|
case "claude_cli":
|
|
6563
6993
|
case "codex_app_server":
|
|
6564
6994
|
case "cursor_agent_cli":
|
|
6565
6995
|
case "droid_cli":
|
|
6566
6996
|
case "gemini_cli":
|
|
6567
6997
|
case "opencode_cli":
|
|
6568
|
-
return "structured";
|
|
6569
6998
|
case "copilot_cli":
|
|
6999
|
+
return "structured";
|
|
6570
7000
|
case "generic_cli":
|
|
6571
7001
|
default:
|
|
6572
7002
|
return "text";
|
|
@@ -6574,13 +7004,15 @@ var BaseMachineAgent = class _BaseMachineAgent {
|
|
|
6574
7004
|
}
|
|
6575
7005
|
// ── Core lifecycle ─────────────────────────────────────────────────────
|
|
6576
7006
|
buildRuntimeConfig(config, safeProjectPath) {
|
|
6577
|
-
const
|
|
6578
|
-
const supportTier = config.supportTier || this.getDefaultSupportTier(
|
|
6579
|
-
const systemPromptParts = [AIDEN_IDENTITY_PROMPT
|
|
6580
|
-
|
|
6581
|
-
);
|
|
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);
|
|
6582
7012
|
const modeHint = getAidenModePrompt(config.mode);
|
|
6583
7013
|
if (modeHint) systemPromptParts.push(modeHint);
|
|
7014
|
+
const operatorSystemPrompt = config.systemPrompt?.trim();
|
|
7015
|
+
if (operatorSystemPrompt) systemPromptParts.push(operatorSystemPrompt);
|
|
6584
7016
|
const workingDir = config.worktreePath || safeProjectPath;
|
|
6585
7017
|
if (workingDir) {
|
|
6586
7018
|
systemPromptParts.push(
|
|
@@ -6592,16 +7024,16 @@ Prefer relative paths and keep your work scoped to this project.`
|
|
|
6592
7024
|
systemPromptParts.push(...extra);
|
|
6593
7025
|
return {
|
|
6594
7026
|
...config,
|
|
6595
|
-
backendKind
|
|
7027
|
+
backendKind,
|
|
6596
7028
|
supportTier,
|
|
6597
7029
|
runtimeCommand: config.runtimeCommand || this.runtime.runtimeCommand,
|
|
6598
7030
|
runtimeArgs: config.runtimeArgs || this.runtime.runtimeArgs,
|
|
6599
|
-
selectedModel: config.selectedModel || defaultSelectedModelForBackend(
|
|
7031
|
+
selectedModel: config.selectedModel || defaultSelectedModelForBackend(backendKind),
|
|
6600
7032
|
systemPrompt: systemPromptParts.join("\n\n") || void 0
|
|
6601
7033
|
};
|
|
6602
7034
|
}
|
|
6603
7035
|
async runCliBackend(config, safeProjectPath) {
|
|
6604
|
-
const
|
|
7036
|
+
const backendKind = this.resolveBackendKind(config);
|
|
6605
7037
|
const defaultCwd = (0, import_path2.join)((0, import_os2.homedir)(), "Documents", "aiden");
|
|
6606
7038
|
if (!(0, import_fs2.existsSync)(defaultCwd)) {
|
|
6607
7039
|
(0, import_fs2.mkdirSync)(defaultCwd, { recursive: true });
|
|
@@ -6612,7 +7044,7 @@ Prefer relative paths and keep your work scoped to this project.`
|
|
|
6612
7044
|
const promptText = this.buildPromptText(runtimeConfig);
|
|
6613
7045
|
const runtimeCommand = runtimeConfig.runtimeCommand || this.runtime.runtimeCommand;
|
|
6614
7046
|
const runtimeArgs = runtimeConfig.runtimeArgs || this.runtime.runtimeArgs || [];
|
|
6615
|
-
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);
|
|
6616
7048
|
let lastResult = null;
|
|
6617
7049
|
for (let attempt = 0; attempt <= _BaseMachineAgent.MAX_RETRIES; attempt++) {
|
|
6618
7050
|
if (this.abortController?.signal.aborted) break;
|
|
@@ -6693,11 +7125,11 @@ Prefer relative paths and keep your work scoped to this project.`
|
|
|
6693
7125
|
}
|
|
6694
7126
|
async run(config) {
|
|
6695
7127
|
this.abortController = new AbortController();
|
|
6696
|
-
const
|
|
6697
|
-
const supportTier = config.supportTier || this.getDefaultSupportTier(
|
|
7128
|
+
const backendKind = this.resolveBackendKind(config);
|
|
7129
|
+
const supportTier = config.supportTier || this.getDefaultSupportTier(backendKind);
|
|
6698
7130
|
const initialConfig = {
|
|
6699
7131
|
...config,
|
|
6700
|
-
backendKind
|
|
7132
|
+
backendKind,
|
|
6701
7133
|
supportTier,
|
|
6702
7134
|
runtimeCommand: config.runtimeCommand || this.runtime.runtimeCommand,
|
|
6703
7135
|
runtimeArgs: config.runtimeArgs || this.runtime.runtimeArgs
|
|
@@ -6718,7 +7150,7 @@ Prefer relative paths and keep your work scoped to this project.`
|
|
|
6718
7150
|
planFilesCreated: [],
|
|
6719
7151
|
iterations: 0,
|
|
6720
7152
|
error: message,
|
|
6721
|
-
backendKind
|
|
7153
|
+
backendKind,
|
|
6722
7154
|
supportTier
|
|
6723
7155
|
};
|
|
6724
7156
|
this.presenter.onComplete(result);
|
|
@@ -6740,7 +7172,7 @@ Prefer relative paths and keep your work scoped to this project.`
|
|
|
6740
7172
|
planFilesCreated: [],
|
|
6741
7173
|
iterations: 0,
|
|
6742
7174
|
error: message,
|
|
6743
|
-
backendKind
|
|
7175
|
+
backendKind,
|
|
6744
7176
|
supportTier
|
|
6745
7177
|
};
|
|
6746
7178
|
this.presenter.onComplete(result);
|
|
@@ -6838,6 +7270,28 @@ var CoreAgent = class _CoreAgent extends BaseMachineAgent {
|
|
|
6838
7270
|
return false;
|
|
6839
7271
|
}
|
|
6840
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
|
+
}
|
|
6841
7295
|
// ── BaseMachineAgent hooks ─────────────────────────────────────────────
|
|
6842
7296
|
getOnProcessSpawned() {
|
|
6843
7297
|
return (child) => {
|
|
@@ -6869,6 +7323,18 @@ var CoreAgent = class _CoreAgent extends BaseMachineAgent {
|
|
|
6869
7323
|
}
|
|
6870
7324
|
buildExtraSystemPromptParts(config) {
|
|
6871
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
|
+
}
|
|
6872
7338
|
if (config.taskMeta) {
|
|
6873
7339
|
const meta = config.taskMeta;
|
|
6874
7340
|
const lines = ["# Task Context"];
|
|
@@ -6891,26 +7357,50 @@ ${meta.description}`);
|
|
|
6891
7357
|
if (meta.descriptionAttachmentIds && meta.descriptionAttachmentIds.length > 0) {
|
|
6892
7358
|
lines.push("");
|
|
6893
7359
|
lines.push("## Task Description Images");
|
|
6894
|
-
lines.push(
|
|
7360
|
+
lines.push('The task description contains images. Use the `attachment` MCP tool with op="get" to view them:');
|
|
6895
7361
|
for (const att of meta.descriptionAttachmentIds) {
|
|
6896
7362
|
lines.push(`- Attachment ID: \`${att.id}\` (${att.filename})`);
|
|
6897
7363
|
}
|
|
6898
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
|
+
}
|
|
6899
7372
|
parts2.push(lines.join("\n"));
|
|
6900
7373
|
}
|
|
6901
|
-
const
|
|
7374
|
+
const taskId = config.taskId ?? process.env.AIDEN_TASK_ID;
|
|
6902
7375
|
const conversationId = config.conversationId ?? process.env.AIDEN_SESSION_ID;
|
|
7376
|
+
const teamId = config.teamId;
|
|
6903
7377
|
const artifactIds = [];
|
|
6904
|
-
if (
|
|
7378
|
+
if (teamId) artifactIds.push(`- teamId: "${teamId}"`);
|
|
7379
|
+
if (taskId) artifactIds.push(`- taskId: "${taskId}"`);
|
|
6905
7380
|
if (conversationId) artifactIds.push(`- conversationId: "${conversationId}"`);
|
|
6906
7381
|
if (artifactIds.length > 0) {
|
|
6907
7382
|
parts2.push(
|
|
6908
7383
|
[
|
|
6909
|
-
"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:",
|
|
6910
7385
|
...artifactIds
|
|
6911
7386
|
].join("\n")
|
|
6912
7387
|
);
|
|
6913
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
|
+
}
|
|
6914
7404
|
return parts2;
|
|
6915
7405
|
}
|
|
6916
7406
|
};
|
|
@@ -7010,10 +7500,10 @@ var WebPresenter = class {
|
|
|
7010
7500
|
}
|
|
7011
7501
|
};
|
|
7012
7502
|
|
|
7013
|
-
// ../../node_modules
|
|
7503
|
+
// ../../node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.node.js
|
|
7014
7504
|
var XMLHttpRequestModule = __toESM(require_XMLHttpRequest(), 1);
|
|
7015
7505
|
|
|
7016
|
-
// ../../node_modules
|
|
7506
|
+
// ../../node_modules/engine.io-parser/build/esm/commons.js
|
|
7017
7507
|
var PACKET_TYPES = /* @__PURE__ */ Object.create(null);
|
|
7018
7508
|
PACKET_TYPES["open"] = "0";
|
|
7019
7509
|
PACKET_TYPES["close"] = "1";
|
|
@@ -7028,7 +7518,7 @@ Object.keys(PACKET_TYPES).forEach((key) => {
|
|
|
7028
7518
|
});
|
|
7029
7519
|
var ERROR_PACKET = { type: "error", data: "parser error" };
|
|
7030
7520
|
|
|
7031
|
-
// ../../node_modules
|
|
7521
|
+
// ../../node_modules/engine.io-parser/build/esm/encodePacket.js
|
|
7032
7522
|
var encodePacket = ({ type, data }, supportsBinary, callback) => {
|
|
7033
7523
|
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
|
|
7034
7524
|
return callback(supportsBinary ? data : "b" + toBuffer(data, true).toString("base64"));
|
|
@@ -7057,7 +7547,7 @@ function encodePacketToBinary(packet, callback) {
|
|
|
7057
7547
|
});
|
|
7058
7548
|
}
|
|
7059
7549
|
|
|
7060
|
-
// ../../node_modules
|
|
7550
|
+
// ../../node_modules/engine.io-parser/build/esm/decodePacket.js
|
|
7061
7551
|
var decodePacket = (encodedPacket, binaryType) => {
|
|
7062
7552
|
if (typeof encodedPacket !== "string") {
|
|
7063
7553
|
return {
|
|
@@ -7103,7 +7593,7 @@ var mapBinary = (data, binaryType) => {
|
|
|
7103
7593
|
}
|
|
7104
7594
|
};
|
|
7105
7595
|
|
|
7106
|
-
// ../../node_modules
|
|
7596
|
+
// ../../node_modules/engine.io-parser/build/esm/index.js
|
|
7107
7597
|
var SEPARATOR = String.fromCharCode(30);
|
|
7108
7598
|
var encodePayload = (packets, callback) => {
|
|
7109
7599
|
const length = packets.length;
|
|
@@ -7245,7 +7735,7 @@ function createPacketDecoderStream(maxPayload, binaryType) {
|
|
|
7245
7735
|
}
|
|
7246
7736
|
var protocol = 4;
|
|
7247
7737
|
|
|
7248
|
-
// ../../node_modules
|
|
7738
|
+
// ../../node_modules/@socket.io/component-emitter/lib/esm/index.js
|
|
7249
7739
|
function Emitter(obj) {
|
|
7250
7740
|
if (obj) return mixin(obj);
|
|
7251
7741
|
}
|
|
@@ -7317,7 +7807,7 @@ Emitter.prototype.hasListeners = function(event) {
|
|
|
7317
7807
|
return !!this.listeners(event).length;
|
|
7318
7808
|
};
|
|
7319
7809
|
|
|
7320
|
-
// ../../node_modules
|
|
7810
|
+
// ../../node_modules/engine.io-client/build/esm-debug/globals.node.js
|
|
7321
7811
|
var nextTick = process.nextTick;
|
|
7322
7812
|
var globalThisShim = global;
|
|
7323
7813
|
var defaultBinaryType = "nodebuffer";
|
|
@@ -7405,7 +7895,7 @@ var CookieJar = class {
|
|
|
7405
7895
|
}
|
|
7406
7896
|
};
|
|
7407
7897
|
|
|
7408
|
-
// ../../node_modules
|
|
7898
|
+
// ../../node_modules/engine.io-client/build/esm-debug/util.js
|
|
7409
7899
|
function pick(obj, ...attr) {
|
|
7410
7900
|
return attr.reduce((acc, k) => {
|
|
7411
7901
|
if (obj.hasOwnProperty(k)) {
|
|
@@ -7453,7 +7943,7 @@ function randomString() {
|
|
|
7453
7943
|
return Date.now().toString(36).substring(3) + Math.random().toString(36).substring(2, 5);
|
|
7454
7944
|
}
|
|
7455
7945
|
|
|
7456
|
-
// ../../node_modules
|
|
7946
|
+
// ../../node_modules/engine.io-client/build/esm-debug/contrib/parseqs.js
|
|
7457
7947
|
function encode(obj) {
|
|
7458
7948
|
let str = "";
|
|
7459
7949
|
for (let i in obj) {
|
|
@@ -7475,7 +7965,7 @@ function decode(qs) {
|
|
|
7475
7965
|
return qry;
|
|
7476
7966
|
}
|
|
7477
7967
|
|
|
7478
|
-
// ../../node_modules
|
|
7968
|
+
// ../../node_modules/engine.io-client/build/esm-debug/transport.js
|
|
7479
7969
|
var import_debug = __toESM(require_src(), 1);
|
|
7480
7970
|
var debug = (0, import_debug.default)("engine.io-client:transport");
|
|
7481
7971
|
var TransportError = class extends Error {
|
|
@@ -7593,8 +8083,8 @@ var Transport = class extends Emitter {
|
|
|
7593
8083
|
return schema + "://" + this._hostname() + this._port() + this.opts.path + this._query(query);
|
|
7594
8084
|
}
|
|
7595
8085
|
_hostname() {
|
|
7596
|
-
const
|
|
7597
|
-
return
|
|
8086
|
+
const hostname2 = this.opts.hostname;
|
|
8087
|
+
return hostname2.indexOf(":") === -1 ? hostname2 : "[" + hostname2 + "]";
|
|
7598
8088
|
}
|
|
7599
8089
|
_port() {
|
|
7600
8090
|
if (this.opts.port && (this.opts.secure && Number(this.opts.port) !== 443 || !this.opts.secure && Number(this.opts.port) !== 80)) {
|
|
@@ -7609,7 +8099,7 @@ var Transport = class extends Emitter {
|
|
|
7609
8099
|
}
|
|
7610
8100
|
};
|
|
7611
8101
|
|
|
7612
|
-
// ../../node_modules
|
|
8102
|
+
// ../../node_modules/engine.io-client/build/esm-debug/transports/polling.js
|
|
7613
8103
|
var import_debug2 = __toESM(require_src(), 1);
|
|
7614
8104
|
var debug2 = (0, import_debug2.default)("engine.io-client:polling");
|
|
7615
8105
|
var Polling = class extends Transport {
|
|
@@ -7754,7 +8244,7 @@ var Polling = class extends Transport {
|
|
|
7754
8244
|
}
|
|
7755
8245
|
};
|
|
7756
8246
|
|
|
7757
|
-
// ../../node_modules
|
|
8247
|
+
// ../../node_modules/engine.io-client/build/esm-debug/contrib/has-cors.js
|
|
7758
8248
|
var value = false;
|
|
7759
8249
|
try {
|
|
7760
8250
|
value = typeof XMLHttpRequest !== "undefined" && "withCredentials" in new XMLHttpRequest();
|
|
@@ -7762,7 +8252,7 @@ try {
|
|
|
7762
8252
|
}
|
|
7763
8253
|
var hasCORS = value;
|
|
7764
8254
|
|
|
7765
|
-
// ../../node_modules
|
|
8255
|
+
// ../../node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.js
|
|
7766
8256
|
var import_debug3 = __toESM(require_src(), 1);
|
|
7767
8257
|
var debug3 = (0, import_debug3.default)("engine.io-client:polling");
|
|
7768
8258
|
function empty() {
|
|
@@ -7997,7 +8487,7 @@ function newRequest(opts) {
|
|
|
7997
8487
|
}
|
|
7998
8488
|
}
|
|
7999
8489
|
|
|
8000
|
-
// ../../node_modules
|
|
8490
|
+
// ../../node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.node.js
|
|
8001
8491
|
var XMLHttpRequest2 = XMLHttpRequestModule.default || XMLHttpRequestModule;
|
|
8002
8492
|
var XHR = class extends BaseXHR {
|
|
8003
8493
|
request(opts = {}) {
|
|
@@ -8007,14 +8497,14 @@ var XHR = class extends BaseXHR {
|
|
|
8007
8497
|
}
|
|
8008
8498
|
};
|
|
8009
8499
|
|
|
8010
|
-
// ../../node_modules
|
|
8500
|
+
// ../../node_modules/engine.io-client/node_modules/ws/wrapper.mjs
|
|
8011
8501
|
var import_stream = __toESM(require_stream(), 1);
|
|
8012
8502
|
var import_receiver = __toESM(require_receiver(), 1);
|
|
8013
8503
|
var import_sender = __toESM(require_sender(), 1);
|
|
8014
8504
|
var import_websocket = __toESM(require_websocket(), 1);
|
|
8015
8505
|
var import_websocket_server = __toESM(require_websocket_server(), 1);
|
|
8016
8506
|
|
|
8017
|
-
// ../../node_modules
|
|
8507
|
+
// ../../node_modules/engine.io-client/build/esm-debug/transports/websocket.js
|
|
8018
8508
|
var import_debug4 = __toESM(require_src(), 1);
|
|
8019
8509
|
var debug4 = (0, import_debug4.default)("engine.io-client:websocket");
|
|
8020
8510
|
var isReactNative = typeof navigator !== "undefined" && typeof navigator.product === "string" && navigator.product.toLowerCase() === "reactnative";
|
|
@@ -8103,7 +8593,7 @@ var BaseWS = class extends Transport {
|
|
|
8103
8593
|
};
|
|
8104
8594
|
var WebSocketCtor = globalThisShim.WebSocket || globalThisShim.MozWebSocket;
|
|
8105
8595
|
|
|
8106
|
-
// ../../node_modules
|
|
8596
|
+
// ../../node_modules/engine.io-client/build/esm-debug/transports/websocket.node.js
|
|
8107
8597
|
var WS = class extends BaseWS {
|
|
8108
8598
|
createSocket(uri, protocols, opts) {
|
|
8109
8599
|
var _a;
|
|
@@ -8134,7 +8624,7 @@ var WS = class extends BaseWS {
|
|
|
8134
8624
|
}
|
|
8135
8625
|
};
|
|
8136
8626
|
|
|
8137
|
-
// ../../node_modules
|
|
8627
|
+
// ../../node_modules/engine.io-client/build/esm-debug/transports/webtransport.js
|
|
8138
8628
|
var import_debug5 = __toESM(require_src(), 1);
|
|
8139
8629
|
var debug5 = (0, import_debug5.default)("engine.io-client:webtransport");
|
|
8140
8630
|
var WT = class extends Transport {
|
|
@@ -8204,14 +8694,14 @@ var WT = class extends Transport {
|
|
|
8204
8694
|
}
|
|
8205
8695
|
};
|
|
8206
8696
|
|
|
8207
|
-
// ../../node_modules
|
|
8697
|
+
// ../../node_modules/engine.io-client/build/esm-debug/transports/index.js
|
|
8208
8698
|
var transports = {
|
|
8209
8699
|
websocket: WS,
|
|
8210
8700
|
webtransport: WT,
|
|
8211
8701
|
polling: XHR
|
|
8212
8702
|
};
|
|
8213
8703
|
|
|
8214
|
-
// ../../node_modules
|
|
8704
|
+
// ../../node_modules/engine.io-client/build/esm-debug/contrib/parseuri.js
|
|
8215
8705
|
var re = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
|
|
8216
8706
|
var parts = [
|
|
8217
8707
|
"source",
|
|
@@ -8271,7 +8761,7 @@ function queryKey(uri, query) {
|
|
|
8271
8761
|
return data;
|
|
8272
8762
|
}
|
|
8273
8763
|
|
|
8274
|
-
// ../../node_modules
|
|
8764
|
+
// ../../node_modules/engine.io-client/build/esm-debug/socket.js
|
|
8275
8765
|
var import_debug6 = __toESM(require_src(), 1);
|
|
8276
8766
|
var debug6 = (0, import_debug6.default)("engine.io-client:socket");
|
|
8277
8767
|
var withEventListeners = typeof addEventListener === "function" && typeof removeEventListener === "function";
|
|
@@ -8867,10 +9357,10 @@ var Socket = class extends SocketWithUpgrade {
|
|
|
8867
9357
|
}
|
|
8868
9358
|
};
|
|
8869
9359
|
|
|
8870
|
-
// ../../node_modules
|
|
9360
|
+
// ../../node_modules/engine.io-client/build/esm-debug/index.js
|
|
8871
9361
|
var protocol2 = Socket.protocol;
|
|
8872
9362
|
|
|
8873
|
-
// ../../node_modules
|
|
9363
|
+
// ../../node_modules/socket.io-client/build/esm-debug/url.js
|
|
8874
9364
|
var import_debug7 = __toESM(require_src(), 1);
|
|
8875
9365
|
var debug7 = (0, import_debug7.default)("socket.io-client:url");
|
|
8876
9366
|
function url(uri, path = "", loc) {
|
|
@@ -8912,7 +9402,7 @@ function url(uri, path = "", loc) {
|
|
|
8912
9402
|
return obj;
|
|
8913
9403
|
}
|
|
8914
9404
|
|
|
8915
|
-
// ../../node_modules
|
|
9405
|
+
// ../../node_modules/socket.io-parser/build/esm-debug/index.js
|
|
8916
9406
|
var esm_debug_exports = {};
|
|
8917
9407
|
__export(esm_debug_exports, {
|
|
8918
9408
|
Decoder: () => Decoder,
|
|
@@ -8922,7 +9412,7 @@ __export(esm_debug_exports, {
|
|
|
8922
9412
|
protocol: () => protocol3
|
|
8923
9413
|
});
|
|
8924
9414
|
|
|
8925
|
-
// ../../node_modules
|
|
9415
|
+
// ../../node_modules/socket.io-parser/build/esm-debug/is-binary.js
|
|
8926
9416
|
var withNativeArrayBuffer = typeof ArrayBuffer === "function";
|
|
8927
9417
|
var isView = (obj) => {
|
|
8928
9418
|
return typeof ArrayBuffer.isView === "function" ? ArrayBuffer.isView(obj) : obj.buffer instanceof ArrayBuffer;
|
|
@@ -8959,7 +9449,7 @@ function hasBinary(obj, toJSON) {
|
|
|
8959
9449
|
return false;
|
|
8960
9450
|
}
|
|
8961
9451
|
|
|
8962
|
-
// ../../node_modules
|
|
9452
|
+
// ../../node_modules/socket.io-parser/build/esm-debug/binary.js
|
|
8963
9453
|
function deconstructPacket(packet) {
|
|
8964
9454
|
const buffers = [];
|
|
8965
9455
|
const packetData = packet.data;
|
|
@@ -9021,7 +9511,7 @@ function _reconstructPacket(data, buffers) {
|
|
|
9021
9511
|
return data;
|
|
9022
9512
|
}
|
|
9023
9513
|
|
|
9024
|
-
// ../../node_modules
|
|
9514
|
+
// ../../node_modules/socket.io-parser/build/esm-debug/index.js
|
|
9025
9515
|
var import_debug8 = __toESM(require_src(), 1);
|
|
9026
9516
|
var debug8 = (0, import_debug8.default)("socket.io-parser");
|
|
9027
9517
|
var RESERVED_EVENTS = [
|
|
@@ -9315,7 +9805,7 @@ function isPacketValid(packet) {
|
|
|
9315
9805
|
return isNamespaceValid(packet.nsp) && isAckIdValid(packet.id) && isDataValid(packet.type, packet.data);
|
|
9316
9806
|
}
|
|
9317
9807
|
|
|
9318
|
-
// ../../node_modules
|
|
9808
|
+
// ../../node_modules/socket.io-client/build/esm-debug/on.js
|
|
9319
9809
|
function on(obj, ev, fn) {
|
|
9320
9810
|
obj.on(ev, fn);
|
|
9321
9811
|
return function subDestroy() {
|
|
@@ -9323,7 +9813,7 @@ function on(obj, ev, fn) {
|
|
|
9323
9813
|
};
|
|
9324
9814
|
}
|
|
9325
9815
|
|
|
9326
|
-
// ../../node_modules
|
|
9816
|
+
// ../../node_modules/socket.io-client/build/esm-debug/socket.js
|
|
9327
9817
|
var import_debug9 = __toESM(require_src(), 1);
|
|
9328
9818
|
var debug9 = (0, import_debug9.default)("socket.io-client:socket");
|
|
9329
9819
|
var RESERVED_EVENTS2 = Object.freeze({
|
|
@@ -10118,7 +10608,7 @@ var Socket2 = class extends Emitter {
|
|
|
10118
10608
|
}
|
|
10119
10609
|
};
|
|
10120
10610
|
|
|
10121
|
-
// ../../node_modules
|
|
10611
|
+
// ../../node_modules/socket.io-client/build/esm-debug/contrib/backo2.js
|
|
10122
10612
|
function Backoff(opts) {
|
|
10123
10613
|
opts = opts || {};
|
|
10124
10614
|
this.ms = opts.min || 100;
|
|
@@ -10149,7 +10639,7 @@ Backoff.prototype.setJitter = function(jitter) {
|
|
|
10149
10639
|
this.jitter = jitter;
|
|
10150
10640
|
};
|
|
10151
10641
|
|
|
10152
|
-
// ../../node_modules
|
|
10642
|
+
// ../../node_modules/socket.io-client/build/esm-debug/manager.js
|
|
10153
10643
|
var import_debug10 = __toESM(require_src(), 1);
|
|
10154
10644
|
var debug10 = (0, import_debug10.default)("socket.io-client:manager");
|
|
10155
10645
|
var Manager = class extends Emitter {
|
|
@@ -10518,7 +11008,7 @@ var Manager = class extends Emitter {
|
|
|
10518
11008
|
}
|
|
10519
11009
|
};
|
|
10520
11010
|
|
|
10521
|
-
// ../../node_modules
|
|
11011
|
+
// ../../node_modules/socket.io-client/build/esm-debug/index.js
|
|
10522
11012
|
var import_debug11 = __toESM(require_src(), 1);
|
|
10523
11013
|
var debug11 = (0, import_debug11.default)("socket.io-client");
|
|
10524
11014
|
var cache = {};
|
|
@@ -10560,9 +11050,9 @@ Object.assign(lookup, {
|
|
|
10560
11050
|
// src/ws-client.ts
|
|
10561
11051
|
var WSClient = class {
|
|
10562
11052
|
socket;
|
|
10563
|
-
constructor(
|
|
10564
|
-
this.socket = lookup(
|
|
10565
|
-
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 ?? "" },
|
|
10566
11056
|
auth: { token },
|
|
10567
11057
|
transports: ["websocket"],
|
|
10568
11058
|
reconnection: true,
|
|
@@ -10620,7 +11110,11 @@ var WSClient = class {
|
|
|
10620
11110
|
images: data.images,
|
|
10621
11111
|
providerSessionId: data.providerSessionId,
|
|
10622
11112
|
backendKind: data.backendKind,
|
|
11113
|
+
agentId: data.agentId,
|
|
11114
|
+
agentPrompt: data.agentPrompt,
|
|
10623
11115
|
selectedModel: data.selectedModel,
|
|
11116
|
+
selectedContextWindow: data.selectedContextWindow,
|
|
11117
|
+
selectedEffortLevel: data.selectedEffortLevel,
|
|
10624
11118
|
mode: data.mode,
|
|
10625
11119
|
taskMeta: data.taskMeta,
|
|
10626
11120
|
workflowTools: data.workflowTools,
|
|
@@ -10628,7 +11122,9 @@ var WSClient = class {
|
|
|
10628
11122
|
messageId: data.messageId,
|
|
10629
11123
|
maxIterations: data.maxIterations,
|
|
10630
11124
|
taskId: data.taskId,
|
|
10631
|
-
conversationId: data.conversationId
|
|
11125
|
+
conversationId: data.conversationId,
|
|
11126
|
+
teamId: data.teamId,
|
|
11127
|
+
currentUser: data.currentUser
|
|
10632
11128
|
});
|
|
10633
11129
|
});
|
|
10634
11130
|
this.socket.on("stop", () => {
|
|
@@ -10646,7 +11142,7 @@ var WSClient = class {
|
|
|
10646
11142
|
};
|
|
10647
11143
|
|
|
10648
11144
|
// src/version.ts
|
|
10649
|
-
var AGENT_VERSION = "0.1.
|
|
11145
|
+
var AGENT_VERSION = "0.1.9";
|
|
10650
11146
|
|
|
10651
11147
|
// src/sandbox.ts
|
|
10652
11148
|
async function runSandbox(config) {
|
|
@@ -10660,6 +11156,8 @@ async function runSandbox(config) {
|
|
|
10660
11156
|
let currentMaxIterations = config.maxIterations ?? 50;
|
|
10661
11157
|
let currentTaskId = config.taskId;
|
|
10662
11158
|
let currentConversationId = config.sessionId;
|
|
11159
|
+
let currentTeamId = config.teamId;
|
|
11160
|
+
let currentUser = config.currentUser;
|
|
10663
11161
|
console.info("[sandbox] Connecting to WS server", { wsUrl: config.wsUrl, sessionId: config.sessionId });
|
|
10664
11162
|
const wsClient = new WSClient(
|
|
10665
11163
|
config.wsUrl,
|
|
@@ -10708,7 +11206,11 @@ async function runSandbox(config) {
|
|
|
10708
11206
|
presenter.setSuppressSessionLifecycle(true);
|
|
10709
11207
|
let lastProviderSessionId = config.providerSessionId;
|
|
10710
11208
|
let activeBackendKind = config.backendKind || "claude_cli";
|
|
11209
|
+
let activeAgentId = config.agentId;
|
|
11210
|
+
let activeAgentPrompt = config.agentPrompt;
|
|
10711
11211
|
let activeModel = config.model;
|
|
11212
|
+
let activeContextWindow = config.contextWindow;
|
|
11213
|
+
let activeEffortLevel = config.effortLevel;
|
|
10712
11214
|
let activeMode = config.mode || "agent";
|
|
10713
11215
|
while (!stopped) {
|
|
10714
11216
|
if (currentTask?.trim()) {
|
|
@@ -10724,12 +11226,18 @@ async function runSandbox(config) {
|
|
|
10724
11226
|
teamPath: config.projectPath,
|
|
10725
11227
|
cwd: config.projectPath,
|
|
10726
11228
|
backendKind: activeBackendKind,
|
|
11229
|
+
agentId: activeAgentId,
|
|
11230
|
+
agentPrompt: activeAgentPrompt,
|
|
10727
11231
|
mode: activeMode,
|
|
10728
11232
|
selectedModel: activeModel,
|
|
11233
|
+
selectedContextWindow: activeContextWindow ?? null,
|
|
11234
|
+
selectedEffortLevel: activeEffortLevel ?? null,
|
|
10729
11235
|
providerSessionId: lastProviderSessionId ?? void 0,
|
|
10730
11236
|
taskMeta: currentTaskMeta,
|
|
10731
11237
|
taskId: currentTaskId,
|
|
10732
11238
|
conversationId: currentConversationId,
|
|
11239
|
+
teamId: currentTeamId,
|
|
11240
|
+
currentUser,
|
|
10733
11241
|
workflowTools: currentWorkflowTools,
|
|
10734
11242
|
images: currentImages.length > 0 ? currentImages.map((img) => ({
|
|
10735
11243
|
id: img.id,
|
|
@@ -10765,9 +11273,21 @@ async function runSandbox(config) {
|
|
|
10765
11273
|
if (nextPayload.backendKind) {
|
|
10766
11274
|
activeBackendKind = nextPayload.backendKind;
|
|
10767
11275
|
}
|
|
11276
|
+
if (nextPayload.agentId !== void 0) {
|
|
11277
|
+
activeAgentId = nextPayload.agentId;
|
|
11278
|
+
}
|
|
11279
|
+
if (nextPayload.agentPrompt !== void 0) {
|
|
11280
|
+
activeAgentPrompt = nextPayload.agentPrompt;
|
|
11281
|
+
}
|
|
10768
11282
|
if (nextPayload.selectedModel) {
|
|
10769
11283
|
activeModel = nextPayload.selectedModel;
|
|
10770
11284
|
}
|
|
11285
|
+
if (nextPayload.selectedContextWindow !== void 0) {
|
|
11286
|
+
activeContextWindow = nextPayload.selectedContextWindow;
|
|
11287
|
+
}
|
|
11288
|
+
if (nextPayload.selectedEffortLevel !== void 0) {
|
|
11289
|
+
activeEffortLevel = nextPayload.selectedEffortLevel;
|
|
11290
|
+
}
|
|
10771
11291
|
if (nextPayload.mode) {
|
|
10772
11292
|
activeMode = nextPayload.mode;
|
|
10773
11293
|
}
|
|
@@ -10786,46 +11306,618 @@ async function runSandbox(config) {
|
|
|
10786
11306
|
if (nextPayload.conversationId !== void 0) {
|
|
10787
11307
|
currentConversationId = nextPayload.conversationId;
|
|
10788
11308
|
}
|
|
11309
|
+
if (nextPayload.currentUser !== void 0) {
|
|
11310
|
+
currentUser = nextPayload.currentUser;
|
|
11311
|
+
}
|
|
11312
|
+
if (nextPayload.teamId !== void 0) {
|
|
11313
|
+
currentTeamId = nextPayload.teamId;
|
|
11314
|
+
}
|
|
10789
11315
|
}
|
|
10790
11316
|
presenter.setSuppressSessionLifecycle(false);
|
|
10791
11317
|
wsClient.close();
|
|
10792
11318
|
}
|
|
10793
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
|
+
|
|
10794
11834
|
// src/index.ts
|
|
10795
|
-
|
|
10796
|
-
process.
|
|
10797
|
-
|
|
10798
|
-
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
|
+
});
|
|
10799
11873
|
}
|
|
10800
|
-
|
|
10801
|
-
|
|
10802
|
-
|
|
10803
|
-
|
|
10804
|
-
|
|
10805
|
-
|
|
10806
|
-
|
|
10807
|
-
|
|
10808
|
-
|
|
10809
|
-
|
|
10810
|
-
|
|
10811
|
-
|
|
10812
|
-
|
|
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}`);
|
|
10813
11918
|
}
|
|
10814
|
-
|
|
10815
|
-
|
|
10816
|
-
wsUrl,
|
|
10817
|
-
sessionId,
|
|
10818
|
-
taskId,
|
|
10819
|
-
sessionToken,
|
|
10820
|
-
task,
|
|
10821
|
-
projectPath,
|
|
10822
|
-
backendKind,
|
|
10823
|
-
mode,
|
|
10824
|
-
model,
|
|
10825
|
-
providerSessionId,
|
|
10826
|
-
maxIterations: 50
|
|
10827
|
-
}).catch((error) => {
|
|
10828
|
-
console.error("[aiden-agent] Fatal error:", error);
|
|
11919
|
+
main().catch((error) => {
|
|
11920
|
+
console.error("[aiden-agent] Fatal error:", error instanceof Error ? error.message : error);
|
|
10829
11921
|
process.exit(1);
|
|
10830
11922
|
});
|
|
10831
11923
|
/*! Bundled license information:
|