@ainecto/mcp 0.14.0-next.6 → 0.14.0-next.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/dist/bin/ainecto.js +548 -142
- package/dist/bin/ainecto.js.map +1 -1
- package/dist/bin/mcp.js +10 -1
- package/dist/bin/mcp.js.map +1 -1
- package/package.json +3 -2
package/dist/bin/ainecto.js
CHANGED
|
@@ -5585,8 +5585,8 @@ function assertLoopbackRedirectUrl(value) {
|
|
|
5585
5585
|
}
|
|
5586
5586
|
throw new Error("OAuth redirect URI must be an http localhost loopback URL.");
|
|
5587
5587
|
}
|
|
5588
|
-
function isLoopbackHostname(
|
|
5589
|
-
return
|
|
5588
|
+
function isLoopbackHostname(hostname3) {
|
|
5589
|
+
return hostname3 === "localhost" || hostname3 === "127.0.0.1" || hostname3 === "::1" || hostname3 === "[::1]";
|
|
5590
5590
|
}
|
|
5591
5591
|
function assertEnv(value) {
|
|
5592
5592
|
if (value === void 0) {
|
|
@@ -5678,7 +5678,16 @@ function legacyRoleInput(flag, envVars = process.env) {
|
|
|
5678
5678
|
|
|
5679
5679
|
// src/core/version.ts
|
|
5680
5680
|
var UNBUNDLED_VERSION = "dev";
|
|
5681
|
-
var CLI_VERSION = true ? "0.14.0-next.
|
|
5681
|
+
var CLI_VERSION = true ? "0.14.0-next.8" : UNBUNDLED_VERSION;
|
|
5682
|
+
var CLI_BUILD = true ? "b8df977" : void 0;
|
|
5683
|
+
function cliVersionLabel(version, build, release) {
|
|
5684
|
+
return release || build === void 0 ? version : `${version}-dev+${build}`;
|
|
5685
|
+
}
|
|
5686
|
+
var CLI_VERSION_LABEL = cliVersionLabel(
|
|
5687
|
+
CLI_VERSION,
|
|
5688
|
+
CLI_BUILD,
|
|
5689
|
+
true
|
|
5690
|
+
);
|
|
5682
5691
|
var PACKAGE_NAME = "@ainecto/mcp";
|
|
5683
5692
|
var CLI_USER_AGENT = `${PACKAGE_NAME} ${CLI_VERSION}`;
|
|
5684
5693
|
function bridgePackageSpec(version = CLI_VERSION) {
|
|
@@ -10472,6 +10481,7 @@ function assertNoArgs(command, argv) {
|
|
|
10472
10481
|
|
|
10473
10482
|
// src/adapters/cli/termCommand.ts
|
|
10474
10483
|
import { closeSync as closeSync2, writeSync } from "fs";
|
|
10484
|
+
import { hostname } from "os";
|
|
10475
10485
|
import { resolve as resolve3 } from "path";
|
|
10476
10486
|
|
|
10477
10487
|
// src/core/term/client.ts
|
|
@@ -10493,6 +10503,9 @@ var TermError = class extends Error {
|
|
|
10493
10503
|
}
|
|
10494
10504
|
code;
|
|
10495
10505
|
};
|
|
10506
|
+
function noSession(name) {
|
|
10507
|
+
return new TermError("TERM_NO_SESSION", `No session named "${name}" (no term sessions are running).`);
|
|
10508
|
+
}
|
|
10496
10509
|
|
|
10497
10510
|
// src/core/term/daemonLock.ts
|
|
10498
10511
|
var LINUX_ABSTRACT_SOCKET_NODE = [20, 8, 0];
|
|
@@ -10674,6 +10687,25 @@ function parseDaemonMessage(line) {
|
|
|
10674
10687
|
const error = asRecord(record2.error);
|
|
10675
10688
|
return { id, ok: false, error: { code: stringField(error, "code"), message: stringField(error, "message") } };
|
|
10676
10689
|
}
|
|
10690
|
+
function listedSessions(data) {
|
|
10691
|
+
if (data && typeof data === "object" && "sessions" in data && Array.isArray(data.sessions)) {
|
|
10692
|
+
return data.sessions.filter(isListedSession);
|
|
10693
|
+
}
|
|
10694
|
+
return [];
|
|
10695
|
+
}
|
|
10696
|
+
function isListedSession(value) {
|
|
10697
|
+
if (!value || typeof value !== "object") {
|
|
10698
|
+
return false;
|
|
10699
|
+
}
|
|
10700
|
+
const session = value;
|
|
10701
|
+
return typeof session.name === "string" && typeof session.pid === "number" && typeof session.cwd === "string" && typeof session.cols === "number" && typeof session.rows === "number";
|
|
10702
|
+
}
|
|
10703
|
+
function readLines(data) {
|
|
10704
|
+
if (data && typeof data === "object" && "lines" in data && Array.isArray(data.lines)) {
|
|
10705
|
+
return data.lines.filter((line) => typeof line === "string");
|
|
10706
|
+
}
|
|
10707
|
+
throw new TermError("TERM_BAD_RESPONSE", "The term daemon answered read without lines.");
|
|
10708
|
+
}
|
|
10677
10709
|
function asRecord(value) {
|
|
10678
10710
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
10679
10711
|
throw new TermProtocolError("Expected a JSON object.");
|
|
@@ -12149,7 +12181,9 @@ function termPaths(home = homedir2()) {
|
|
|
12149
12181
|
daemonInfo: join6(dir, "daemon.json"),
|
|
12150
12182
|
manifest: join6(dir, "sessions.json"),
|
|
12151
12183
|
log: join6(dir, "daemon.log"),
|
|
12152
|
-
previousLog: join6(dir, "daemon.log.1")
|
|
12184
|
+
previousLog: join6(dir, "daemon.log.1"),
|
|
12185
|
+
remoteLog: join6(dir, "remote.log"),
|
|
12186
|
+
previousRemoteLog: join6(dir, "remote.log.1")
|
|
12153
12187
|
};
|
|
12154
12188
|
}
|
|
12155
12189
|
|
|
@@ -12157,7 +12191,7 @@ function termPaths(home = homedir2()) {
|
|
|
12157
12191
|
async function waitForMatch(paths, name, pattern, range, timeoutMs) {
|
|
12158
12192
|
const client = await openTermClient(paths, { start: false });
|
|
12159
12193
|
if (!client) {
|
|
12160
|
-
throw
|
|
12194
|
+
throw noSession(name);
|
|
12161
12195
|
}
|
|
12162
12196
|
let dirty = false;
|
|
12163
12197
|
let ended;
|
|
@@ -12194,7 +12228,7 @@ async function waitForMatch(paths, name, pattern, range, timeoutMs) {
|
|
|
12194
12228
|
}
|
|
12195
12229
|
throw error;
|
|
12196
12230
|
}
|
|
12197
|
-
const lines =
|
|
12231
|
+
const lines = readLines(data);
|
|
12198
12232
|
for (const line of lines) {
|
|
12199
12233
|
const found = pattern.exec(line);
|
|
12200
12234
|
if (found) {
|
|
@@ -12221,11 +12255,427 @@ async function waitForMatch(paths, name, pattern, range, timeoutMs) {
|
|
|
12221
12255
|
client.close();
|
|
12222
12256
|
}
|
|
12223
12257
|
}
|
|
12224
|
-
|
|
12225
|
-
|
|
12226
|
-
|
|
12258
|
+
|
|
12259
|
+
// src/core/term/remote.ts
|
|
12260
|
+
import { StringDecoder } from "string_decoder";
|
|
12261
|
+
|
|
12262
|
+
// src/core/async/sleep.ts
|
|
12263
|
+
function sleep(ms, signal) {
|
|
12264
|
+
return new Promise((resolve4) => {
|
|
12265
|
+
if (signal.aborted) {
|
|
12266
|
+
resolve4();
|
|
12267
|
+
return;
|
|
12268
|
+
}
|
|
12269
|
+
const timer = setTimeout(done, ms);
|
|
12270
|
+
signal.addEventListener("abort", done, { once: true });
|
|
12271
|
+
function done() {
|
|
12272
|
+
clearTimeout(timer);
|
|
12273
|
+
signal.removeEventListener("abort", done);
|
|
12274
|
+
resolve4();
|
|
12275
|
+
}
|
|
12276
|
+
});
|
|
12277
|
+
}
|
|
12278
|
+
|
|
12279
|
+
// src/core/http/pcHttp.ts
|
|
12280
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
12281
|
+
var PcCallError = class extends Error {
|
|
12282
|
+
constructor(message, op, status, code) {
|
|
12283
|
+
super(message);
|
|
12284
|
+
this.op = op;
|
|
12285
|
+
this.status = status;
|
|
12286
|
+
this.code = code;
|
|
12287
|
+
this.name = "PcCallError";
|
|
12227
12288
|
}
|
|
12228
|
-
|
|
12289
|
+
op;
|
|
12290
|
+
status;
|
|
12291
|
+
code;
|
|
12292
|
+
/** 다시 해 볼 만한가 — 네트워크·기한·5xx·429. */
|
|
12293
|
+
get retryable() {
|
|
12294
|
+
return this.status === void 0 || this.status >= 500 || this.status === 429;
|
|
12295
|
+
}
|
|
12296
|
+
};
|
|
12297
|
+
function createPcHttp(input) {
|
|
12298
|
+
const fetchImpl = input.fetchImpl ?? fetch;
|
|
12299
|
+
const base = `${input.endpoint.replace(/\/+$/, "")}/${input.path}/`;
|
|
12300
|
+
const fail = input.error ?? ((message, op, status, code) => new PcCallError(message, op, status, code));
|
|
12301
|
+
const { log } = input.logging;
|
|
12302
|
+
let sessionToken;
|
|
12303
|
+
async function send(op, payload, token, options = {}) {
|
|
12304
|
+
const controller = new AbortController();
|
|
12305
|
+
const timer = setTimeout(
|
|
12306
|
+
() => controller.abort(new DOMException("timed out", "TimeoutError")),
|
|
12307
|
+
(options.holdMs ?? 0) + input.timeoutMs
|
|
12308
|
+
);
|
|
12309
|
+
const onStop = () => controller.abort(new DOMException("stopped", "AbortError"));
|
|
12310
|
+
options.signal?.addEventListener("abort", onStop, { once: true });
|
|
12311
|
+
const headers = { "Content-Type": "application/json", Accept: "application/json" };
|
|
12312
|
+
if (token) headers.Authorization = `Bearer ${token}`;
|
|
12313
|
+
if (sessionToken && op !== "open") headers[input.sessionHeader] = sessionToken;
|
|
12314
|
+
try {
|
|
12315
|
+
const response = await fetchImpl(base + op, { method: "POST", headers, body: payload, signal: controller.signal });
|
|
12316
|
+
await response.clone().arrayBuffer();
|
|
12317
|
+
return response;
|
|
12318
|
+
} catch (error) {
|
|
12319
|
+
throw controller.signal.aborted && controller.signal.reason instanceof Error ? controller.signal.reason : error;
|
|
12320
|
+
} finally {
|
|
12321
|
+
clearTimeout(timer);
|
|
12322
|
+
options.signal?.removeEventListener("abort", onStop);
|
|
12323
|
+
}
|
|
12324
|
+
}
|
|
12325
|
+
return {
|
|
12326
|
+
useSessionToken(token) {
|
|
12327
|
+
sessionToken = token;
|
|
12328
|
+
},
|
|
12329
|
+
async call(op, body, options) {
|
|
12330
|
+
const callId = randomUUID2();
|
|
12331
|
+
const payload = JSON.stringify(body);
|
|
12332
|
+
const started = Date.now();
|
|
12333
|
+
log.write(input.logging.request({ callId, op, bytes: Buffer.byteLength(payload, "utf8") }, options));
|
|
12334
|
+
let outcome = { ok: false, error: "no response" };
|
|
12335
|
+
try {
|
|
12336
|
+
let response = await send(op, payload, await input.tokenProvider.getAccessToken(), options);
|
|
12337
|
+
if (response.status === 401) {
|
|
12338
|
+
response = await send(op, payload, await input.tokenProvider.refreshAfterUnauthorized(), options);
|
|
12339
|
+
}
|
|
12340
|
+
const text = await response.text();
|
|
12341
|
+
const parsed = parseJson2(text);
|
|
12342
|
+
if (!response.ok) {
|
|
12343
|
+
const code = typeof parsed?.code === "string" ? parsed.code : void 0;
|
|
12344
|
+
outcome = { ok: false, status: response.status, code };
|
|
12345
|
+
throw fail(typeof parsed?.message === "string" ? parsed.message : `HTTP ${response.status}`, op, response.status, code);
|
|
12346
|
+
}
|
|
12347
|
+
outcome = { ok: true, status: response.status, body: parsed ?? {} };
|
|
12348
|
+
return parsed ?? {};
|
|
12349
|
+
} catch (error) {
|
|
12350
|
+
if (error instanceof PcCallError) throw error;
|
|
12351
|
+
const timedOut = error instanceof Error && (error.name === "TimeoutError" || error.name === "AbortError");
|
|
12352
|
+
const reason = timedOut ? error.name : error instanceof Error ? error.message : String(error);
|
|
12353
|
+
outcome = { ok: false, error: reason };
|
|
12354
|
+
throw fail(timedOut ? `${op} timed out` : `${op} failed: ${reason}`, op);
|
|
12355
|
+
} finally {
|
|
12356
|
+
log.write(input.logging.response({ callId, op, ms: Date.now() - started }, outcome));
|
|
12357
|
+
}
|
|
12358
|
+
}
|
|
12359
|
+
};
|
|
12360
|
+
}
|
|
12361
|
+
function parseJson2(text) {
|
|
12362
|
+
if (!text) return void 0;
|
|
12363
|
+
try {
|
|
12364
|
+
const value = JSON.parse(text);
|
|
12365
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
12366
|
+
} catch {
|
|
12367
|
+
return void 0;
|
|
12368
|
+
}
|
|
12369
|
+
}
|
|
12370
|
+
|
|
12371
|
+
// src/core/term/remoteFrame.ts
|
|
12372
|
+
import { createHash as createHash6 } from "crypto";
|
|
12373
|
+
function screenFrame(lines, maxD) {
|
|
12374
|
+
const sizes = lines.map((line) => Buffer.byteLength(line, "utf8"));
|
|
12375
|
+
let start = 0;
|
|
12376
|
+
let bytes = sizes.reduce((sum, size) => sum + size, 0) + Math.max(0, lines.length - 1) * 2;
|
|
12377
|
+
while (start < lines.length && base64Length(bytes) > maxD) {
|
|
12378
|
+
bytes -= (sizes[start] ?? 0) + (start < lines.length - 1 ? 2 : 0);
|
|
12379
|
+
start += 1;
|
|
12380
|
+
}
|
|
12381
|
+
const text = lines.slice(start).join("\r\n");
|
|
12382
|
+
return {
|
|
12383
|
+
d: Buffer.from(text, "utf8").toString("base64"),
|
|
12384
|
+
hash: createHash6("sha256").update(text, "utf8").digest("hex"),
|
|
12385
|
+
dropped: start
|
|
12386
|
+
};
|
|
12387
|
+
}
|
|
12388
|
+
function frameBudget(frameMaxBytes, body) {
|
|
12389
|
+
return frameMaxBytes - Buffer.byteLength(JSON.stringify({ ...body, d: "" }), "utf8");
|
|
12390
|
+
}
|
|
12391
|
+
function base64Length(bytes) {
|
|
12392
|
+
return 4 * Math.ceil(bytes / 3);
|
|
12393
|
+
}
|
|
12394
|
+
|
|
12395
|
+
// src/core/term/remoteLimits.ts
|
|
12396
|
+
var CALL_TIMEOUT_MS = 1e4;
|
|
12397
|
+
var FRAME_MIN_INTERVAL_MS = 150;
|
|
12398
|
+
var FRAME_SCROLLBACK_LINES = 200;
|
|
12399
|
+
var RETRY_MIN_MS = 500;
|
|
12400
|
+
var RETRY_MAX_MS = 1e4;
|
|
12401
|
+
function retryWait(attempt, random) {
|
|
12402
|
+
return Math.min(RETRY_MIN_MS * 2 ** attempt, RETRY_MAX_MS) + Math.floor(random * RETRY_MIN_MS);
|
|
12403
|
+
}
|
|
12404
|
+
|
|
12405
|
+
// src/core/term/remote.ts
|
|
12406
|
+
var REMOTE_NOT_FOUND = "REMOTE_NOT_FOUND";
|
|
12407
|
+
function openRemoteLog(paths) {
|
|
12408
|
+
const log = new DaemonLog(paths.remoteLog, paths.previousRemoteLog);
|
|
12409
|
+
log.enableRotation();
|
|
12410
|
+
return log;
|
|
12411
|
+
}
|
|
12412
|
+
function createRemoteHttp(input) {
|
|
12413
|
+
return createPcHttp({
|
|
12414
|
+
endpoint: input.endpoint,
|
|
12415
|
+
path: "term/pc",
|
|
12416
|
+
tokenProvider: input.tokenProvider,
|
|
12417
|
+
timeoutMs: CALL_TIMEOUT_MS,
|
|
12418
|
+
sessionHeader: "X-Remote-Token",
|
|
12419
|
+
fetchImpl: input.fetchImpl,
|
|
12420
|
+
logging: {
|
|
12421
|
+
log: input.log,
|
|
12422
|
+
request: ({ callId, op, bytes }) => ({ event: "remote_call", callId, op, bytes }),
|
|
12423
|
+
response: ({ callId, op, ms }, outcome) => ({
|
|
12424
|
+
event: "remote_call_response",
|
|
12425
|
+
callId,
|
|
12426
|
+
op,
|
|
12427
|
+
...outcome.ok ? { ok: true, status: outcome.status, ...answerSummary(outcome.body) } : outcome,
|
|
12428
|
+
ms
|
|
12429
|
+
})
|
|
12430
|
+
}
|
|
12431
|
+
});
|
|
12432
|
+
}
|
|
12433
|
+
async function runRemote(deps) {
|
|
12434
|
+
const name = deps.session;
|
|
12435
|
+
const client = await openTermClient(deps.paths, { start: false });
|
|
12436
|
+
if (!client) {
|
|
12437
|
+
throw noSession(name);
|
|
12438
|
+
}
|
|
12439
|
+
let ending;
|
|
12440
|
+
const stopper = new AbortController();
|
|
12441
|
+
let dirty = true;
|
|
12442
|
+
let wakeFrame;
|
|
12443
|
+
const nudge = () => {
|
|
12444
|
+
const wake = wakeFrame;
|
|
12445
|
+
wakeFrame = void 0;
|
|
12446
|
+
wake?.();
|
|
12447
|
+
};
|
|
12448
|
+
const end = (outcome) => {
|
|
12449
|
+
if (ending) return;
|
|
12450
|
+
ending = outcome;
|
|
12451
|
+
stopper.abort();
|
|
12452
|
+
nudge();
|
|
12453
|
+
};
|
|
12454
|
+
const daemonFailed = (op, error) => {
|
|
12455
|
+
const code = error instanceof TermError ? error.code : "UNKNOWN";
|
|
12456
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
12457
|
+
deps.log.write({ event: "remote_daemon_error", op, code, message });
|
|
12458
|
+
end(code === "TERM_NO_SESSION" ? { exitCode: 0, reason: `Session ${name} ended.`, close: true } : { exitCode: 1, reason: `The term daemon failed ${op} (${code}): ${message}`, close: true });
|
|
12459
|
+
};
|
|
12460
|
+
const onUserStop = () => end({ exitCode: 0, reason: "Stopped.", close: true });
|
|
12461
|
+
if (deps.signal.aborted) onUserStop();
|
|
12462
|
+
deps.signal.addEventListener("abort", onUserStop, { once: true });
|
|
12463
|
+
client.onEvent((event) => {
|
|
12464
|
+
if (event.event === "changed") {
|
|
12465
|
+
dirty = true;
|
|
12466
|
+
nudge();
|
|
12467
|
+
} else if (event.event === "exit") {
|
|
12468
|
+
end({ exitCode: 0, reason: `Session ${name} exited (${event.signal ? `signal ${event.signal}` : `code ${event.exitCode}`}).`, close: true });
|
|
12469
|
+
}
|
|
12470
|
+
});
|
|
12471
|
+
client.onClose(() => end({ exitCode: 1, reason: "Lost the connection to the term daemon.", close: true }));
|
|
12472
|
+
let opened = false;
|
|
12473
|
+
try {
|
|
12474
|
+
await client.request({ op: "watch", name });
|
|
12475
|
+
const listed = listedSessions(await client.request({ op: "ls" })).find((session) => session.name === name);
|
|
12476
|
+
if (!listed) {
|
|
12477
|
+
throw noSession(name);
|
|
12478
|
+
}
|
|
12479
|
+
const { cols, rows } = listed;
|
|
12480
|
+
if (ending) {
|
|
12481
|
+
return { exitCode: ending.exitCode, reason: ending.reason };
|
|
12482
|
+
}
|
|
12483
|
+
const openLink2 = async (generation, signal) => {
|
|
12484
|
+
const opened2 = await deps.http.call(
|
|
12485
|
+
"open",
|
|
12486
|
+
{ session: name, hostName: deps.hostName, cliVersion: deps.cliVersion, cols, rows },
|
|
12487
|
+
signal ? { signal } : void 0
|
|
12488
|
+
);
|
|
12489
|
+
const limits = serverLimits(opened2.limits);
|
|
12490
|
+
if (typeof opened2.remoteId !== "string" || typeof opened2.remoteToken !== "string" || !limits) {
|
|
12491
|
+
throw new TermError("TERM_REMOTE_BAD_RESPONSE", "AiNecto answered open without remoteId, remoteToken or limits.");
|
|
12492
|
+
}
|
|
12493
|
+
deps.http.useSessionToken(opened2.remoteToken);
|
|
12494
|
+
return { remoteId: opened2.remoteId, generation, ...limits };
|
|
12495
|
+
};
|
|
12496
|
+
let current = await openLink2(1);
|
|
12497
|
+
opened = true;
|
|
12498
|
+
deps.log.write({
|
|
12499
|
+
event: "remote_opened",
|
|
12500
|
+
remoteId: current.remoteId,
|
|
12501
|
+
cols,
|
|
12502
|
+
rows,
|
|
12503
|
+
pollHoldSeconds: current.pollHoldSeconds,
|
|
12504
|
+
frameMaxBytes: current.frameMaxBytes
|
|
12505
|
+
});
|
|
12506
|
+
deps.print(`Sharing ${name} (${cols}x${rows}) on AiNecto from ${deps.hostName}. Open the remote terminal in AiNecto to watch and type. Press Ctrl+C to stop.`);
|
|
12507
|
+
const refused = (error) => {
|
|
12508
|
+
if (error instanceof PcCallError && error.status === 404) {
|
|
12509
|
+
return { exitCode: 0, reason: `AiNecto no longer has this remote terminal open (${error.code ?? "404"}).`, close: false };
|
|
12510
|
+
}
|
|
12511
|
+
const what = error instanceof PcCallError ? `${error.op}: ${error.status ?? "-"} ${error.code ?? ""} ${error.message}`.replace(/\s+/g, " ") : error instanceof Error ? error.message : String(error);
|
|
12512
|
+
return { exitCode: 1, reason: `AiNecto refused the remote terminal (${what}).`, close: true };
|
|
12513
|
+
};
|
|
12514
|
+
const forgotten = (error) => error instanceof PcCallError && error.status === 404 && error.code === REMOTE_NOT_FOUND;
|
|
12515
|
+
let gone = false;
|
|
12516
|
+
let reopens = 0;
|
|
12517
|
+
const reopen = async () => {
|
|
12518
|
+
const previous = current;
|
|
12519
|
+
while (!ending) {
|
|
12520
|
+
if (reopens > 0) {
|
|
12521
|
+
await sleep(retryWait(reopens - 1, Math.random()), stopper.signal);
|
|
12522
|
+
if (ending) return;
|
|
12523
|
+
}
|
|
12524
|
+
reopens += 1;
|
|
12525
|
+
try {
|
|
12526
|
+
current = await openLink2(previous.generation + 1, stopper.signal);
|
|
12527
|
+
} catch (error) {
|
|
12528
|
+
if (ending) return;
|
|
12529
|
+
if (error instanceof PcCallError && error.retryable) continue;
|
|
12530
|
+
end(refused(error));
|
|
12531
|
+
return;
|
|
12532
|
+
}
|
|
12533
|
+
gone = false;
|
|
12534
|
+
deps.log.write({ event: "remote_reopened", reason: REMOTE_NOT_FOUND, previousRemoteId: previous.remoteId, remoteId: current.remoteId });
|
|
12535
|
+
deps.print("AiNecto lost this remote terminal (it may have restarted); opened it again.");
|
|
12536
|
+
dirty = true;
|
|
12537
|
+
nudge();
|
|
12538
|
+
return;
|
|
12539
|
+
}
|
|
12540
|
+
};
|
|
12541
|
+
const decoder = new StringDecoder("utf8");
|
|
12542
|
+
const pollLoop = async () => {
|
|
12543
|
+
let attempt = 0;
|
|
12544
|
+
while (!ending) {
|
|
12545
|
+
let answer;
|
|
12546
|
+
try {
|
|
12547
|
+
answer = await deps.http.call(
|
|
12548
|
+
"poll",
|
|
12549
|
+
{ remoteId: current.remoteId },
|
|
12550
|
+
{ holdMs: current.pollHoldSeconds * 1e3, signal: stopper.signal }
|
|
12551
|
+
);
|
|
12552
|
+
} catch (error) {
|
|
12553
|
+
if (ending) return;
|
|
12554
|
+
if (forgotten(error)) {
|
|
12555
|
+
gone = true;
|
|
12556
|
+
attempt = 0;
|
|
12557
|
+
await reopen();
|
|
12558
|
+
continue;
|
|
12559
|
+
}
|
|
12560
|
+
if (!(error instanceof PcCallError) || !error.retryable) {
|
|
12561
|
+
end(refused(error));
|
|
12562
|
+
return;
|
|
12563
|
+
}
|
|
12564
|
+
await sleep(retryWait(attempt, Math.random()), stopper.signal);
|
|
12565
|
+
attempt += 1;
|
|
12566
|
+
continue;
|
|
12567
|
+
}
|
|
12568
|
+
attempt = 0;
|
|
12569
|
+
reopens = 0;
|
|
12570
|
+
if (answer.state === "CLOSED") {
|
|
12571
|
+
end({ exitCode: 0, reason: `AiNecto closed this remote terminal (${typeof answer.reason === "string" ? answer.reason : "CLOSED"}).`, close: false });
|
|
12572
|
+
return;
|
|
12573
|
+
}
|
|
12574
|
+
for (const d of inputsIn(answer)) {
|
|
12575
|
+
const text = decoder.write(Buffer.from(d, "base64"));
|
|
12576
|
+
if (text === "") continue;
|
|
12577
|
+
try {
|
|
12578
|
+
await client.request({ op: "send", name, text, paste: false });
|
|
12579
|
+
} catch (error) {
|
|
12580
|
+
daemonFailed("send", error);
|
|
12581
|
+
return;
|
|
12582
|
+
}
|
|
12583
|
+
}
|
|
12584
|
+
}
|
|
12585
|
+
};
|
|
12586
|
+
const frameLoop = async () => {
|
|
12587
|
+
let sentHash;
|
|
12588
|
+
let sentGeneration = 0;
|
|
12589
|
+
let parkedGeneration = 0;
|
|
12590
|
+
let lastRead = 0;
|
|
12591
|
+
let dropped = 0;
|
|
12592
|
+
let attempt = 0;
|
|
12593
|
+
while (!ending) {
|
|
12594
|
+
const target = current;
|
|
12595
|
+
if (!dirty || parkedGeneration === target.generation) {
|
|
12596
|
+
await new Promise((resolve4) => {
|
|
12597
|
+
wakeFrame = resolve4;
|
|
12598
|
+
});
|
|
12599
|
+
continue;
|
|
12600
|
+
}
|
|
12601
|
+
if (sentGeneration !== target.generation) {
|
|
12602
|
+
sentGeneration = target.generation;
|
|
12603
|
+
sentHash = void 0;
|
|
12604
|
+
}
|
|
12605
|
+
const gap = lastRead + FRAME_MIN_INTERVAL_MS - Date.now();
|
|
12606
|
+
if (gap > 0) {
|
|
12607
|
+
await sleep(gap, stopper.signal);
|
|
12608
|
+
continue;
|
|
12609
|
+
}
|
|
12610
|
+
dirty = false;
|
|
12611
|
+
lastRead = Date.now();
|
|
12612
|
+
let lines;
|
|
12613
|
+
try {
|
|
12614
|
+
lines = readLines(await client.request({ op: "read", name, scrollback: true, lines: FRAME_SCROLLBACK_LINES + rows }));
|
|
12615
|
+
} catch (error) {
|
|
12616
|
+
daemonFailed("read", error);
|
|
12617
|
+
return;
|
|
12618
|
+
}
|
|
12619
|
+
const frame = screenFrame(lines, frameBudget(target.frameMaxBytes, { remoteId: target.remoteId, cols, rows }));
|
|
12620
|
+
if (frame.dropped !== dropped) {
|
|
12621
|
+
dropped = frame.dropped;
|
|
12622
|
+
deps.log.write({ event: "remote_frame_trimmed", dropped });
|
|
12623
|
+
}
|
|
12624
|
+
if (frame.hash === sentHash) continue;
|
|
12625
|
+
try {
|
|
12626
|
+
await deps.http.call("frame", { remoteId: target.remoteId, cols, rows, d: frame.d }, { signal: stopper.signal });
|
|
12627
|
+
sentHash = frame.hash;
|
|
12628
|
+
attempt = 0;
|
|
12629
|
+
} catch (error) {
|
|
12630
|
+
if (ending) return;
|
|
12631
|
+
if (forgotten(error)) {
|
|
12632
|
+
parkedGeneration = target.generation;
|
|
12633
|
+
dirty = true;
|
|
12634
|
+
continue;
|
|
12635
|
+
}
|
|
12636
|
+
if (!(error instanceof PcCallError) || !error.retryable) {
|
|
12637
|
+
end(refused(error));
|
|
12638
|
+
return;
|
|
12639
|
+
}
|
|
12640
|
+
await sleep(retryWait(attempt, Math.random()), stopper.signal);
|
|
12641
|
+
attempt += 1;
|
|
12642
|
+
dirty = true;
|
|
12643
|
+
}
|
|
12644
|
+
}
|
|
12645
|
+
};
|
|
12646
|
+
await Promise.all([pollLoop(), frameLoop()]);
|
|
12647
|
+
const outcome = ending ?? { exitCode: 1, reason: "The remote terminal stopped.", close: true };
|
|
12648
|
+
if (outcome.close && !gone) {
|
|
12649
|
+
try {
|
|
12650
|
+
await deps.http.call("close", { remoteId: current.remoteId });
|
|
12651
|
+
} catch (error) {
|
|
12652
|
+
deps.print(`Could not tell AiNecto that sharing stopped: ${error instanceof Error ? error.message : String(error)}`);
|
|
12653
|
+
}
|
|
12654
|
+
}
|
|
12655
|
+
return { exitCode: outcome.exitCode, reason: outcome.reason };
|
|
12656
|
+
} finally {
|
|
12657
|
+
if (!opened) stopper.abort();
|
|
12658
|
+
deps.signal.removeEventListener("abort", onUserStop);
|
|
12659
|
+
client.close();
|
|
12660
|
+
}
|
|
12661
|
+
}
|
|
12662
|
+
function answerSummary(body) {
|
|
12663
|
+
return {
|
|
12664
|
+
...typeof body.state === "string" ? { state: body.state } : {},
|
|
12665
|
+
...typeof body.reason === "string" ? { reason: body.reason } : {},
|
|
12666
|
+
...Array.isArray(body.commands) ? { commands: body.commands.length } : {},
|
|
12667
|
+
...typeof body.version === "number" ? { version: body.version } : {}
|
|
12668
|
+
};
|
|
12669
|
+
}
|
|
12670
|
+
function serverLimits(value) {
|
|
12671
|
+
if (!value || typeof value !== "object") return void 0;
|
|
12672
|
+
const pollHoldSeconds = "pollHoldSeconds" in value ? value.pollHoldSeconds : void 0;
|
|
12673
|
+
const frameMaxBytes = "frameMaxBytes" in value ? value.frameMaxBytes : void 0;
|
|
12674
|
+
return typeof pollHoldSeconds === "number" && pollHoldSeconds >= 0 && typeof frameMaxBytes === "number" && frameMaxBytes > 0 ? { pollHoldSeconds, frameMaxBytes } : void 0;
|
|
12675
|
+
}
|
|
12676
|
+
function inputsIn(answer) {
|
|
12677
|
+
if (!Array.isArray(answer.commands)) return [];
|
|
12678
|
+
return answer.commands.flatMap((command) => command && typeof command === "object" && "type" in command && command.type === "input" && "d" in command && typeof command.d === "string" ? [command.d] : []);
|
|
12229
12679
|
}
|
|
12230
12680
|
|
|
12231
12681
|
// src/adapters/cli/termCommand.ts
|
|
@@ -12238,7 +12688,8 @@ var TERM_HELP_LINES = [
|
|
|
12238
12688
|
" ainecto term wait <name> --match REGEX [--timeout SECONDS] [--lines N] [--scrollback] until a screen line matches",
|
|
12239
12689
|
` ainecto term attach <name> watch and type in your terminal; detach with ${DETACH_HINT}`,
|
|
12240
12690
|
" ainecto term kill <name> \xB7 ainecto term kill-server",
|
|
12241
|
-
" ainecto term restore [--json] start again the sessions that were running when the daemon or the machine stopped"
|
|
12691
|
+
" ainecto term restore [--json] start again the sessions that were running when the daemon or the machine stopped",
|
|
12692
|
+
" ainecto term remote <name> show the session in AiNecto on the web (plain text) and type there (signed in; Ctrl+C to stop; log: ~/.ainecto/term/remote.log)"
|
|
12242
12693
|
];
|
|
12243
12694
|
async function executeTermCommand(input) {
|
|
12244
12695
|
const [action, ...rest] = input.argv;
|
|
@@ -12294,8 +12745,45 @@ async function executeTermCommand(input) {
|
|
|
12294
12745
|
case "daemon":
|
|
12295
12746
|
return await daemonCommand(paths, rest);
|
|
12296
12747
|
default:
|
|
12297
|
-
throw usage(`term new|ls|send|key|read|wait|attach|kill|kill-server|restore \u2014 see ainecto --help`);
|
|
12748
|
+
throw usage(`term new|ls|send|key|read|wait|attach|kill|kill-server|restore|remote \u2014 see ainecto --help`);
|
|
12749
|
+
}
|
|
12750
|
+
}
|
|
12751
|
+
async function executeTermRemote(input) {
|
|
12752
|
+
const name = singleName(parseArgs(input.argv, {}).positionals, "term remote <name>");
|
|
12753
|
+
const paths = termPaths();
|
|
12754
|
+
await ensurePrivateDir(paths.dir);
|
|
12755
|
+
const log = openRemoteLog(paths);
|
|
12756
|
+
const host = hostname();
|
|
12757
|
+
log.write({ event: "remote_start", pid: process.pid, version: CLI_VERSION_LABEL, endpoint: input.endpoint, host, session: name });
|
|
12758
|
+
const controller = new AbortController();
|
|
12759
|
+
const onSignal = () => controller.abort();
|
|
12760
|
+
process.once("SIGINT", onSignal);
|
|
12761
|
+
process.once("SIGTERM", onSignal);
|
|
12762
|
+
let result;
|
|
12763
|
+
try {
|
|
12764
|
+
result = await runRemote({
|
|
12765
|
+
paths,
|
|
12766
|
+
session: name,
|
|
12767
|
+
http: createRemoteHttp({ endpoint: input.endpoint, tokenProvider: input.auth, log }),
|
|
12768
|
+
log,
|
|
12769
|
+
hostName: host,
|
|
12770
|
+
cliVersion: CLI_VERSION_LABEL,
|
|
12771
|
+
signal: controller.signal,
|
|
12772
|
+
print: (line) => input.io.stderr.write(`${line}
|
|
12773
|
+
`)
|
|
12774
|
+
});
|
|
12775
|
+
} catch (error) {
|
|
12776
|
+
log.write({ event: "remote_stop", pid: process.pid, reason: `error: ${error instanceof Error ? error.message : String(error)}` });
|
|
12777
|
+
throw error;
|
|
12778
|
+
} finally {
|
|
12779
|
+
process.off("SIGINT", onSignal);
|
|
12780
|
+
process.off("SIGTERM", onSignal);
|
|
12298
12781
|
}
|
|
12782
|
+
log.write({ event: "remote_stop", pid: process.pid, reason: result.reason, exitCode: result.exitCode });
|
|
12783
|
+
if (result.exitCode !== 0) {
|
|
12784
|
+
throw new TermError("TERM_REMOTE_FAILED", result.reason);
|
|
12785
|
+
}
|
|
12786
|
+
return print(input, result, result.reason);
|
|
12299
12787
|
}
|
|
12300
12788
|
async function newSession(paths, argv, input) {
|
|
12301
12789
|
const args = parseArgs(argv, { cwd: "string" });
|
|
@@ -12316,7 +12804,7 @@ async function listSessions(paths, argv, input) {
|
|
|
12316
12804
|
parseArgs(argv, {});
|
|
12317
12805
|
const result = await termRequest(paths, { op: "ls" }, { start: false });
|
|
12318
12806
|
const data = result.daemon ? result.data : { sessions: [] };
|
|
12319
|
-
const sessions =
|
|
12807
|
+
const sessions = listedSessions(data);
|
|
12320
12808
|
const human = sessions.length === 0 ? "No term sessions." : renderTable(sessions.map((session) => ({
|
|
12321
12809
|
name: session.name,
|
|
12322
12810
|
pid: session.pid,
|
|
@@ -12463,9 +12951,6 @@ function print(input, data, human) {
|
|
|
12463
12951
|
`);
|
|
12464
12952
|
return 0;
|
|
12465
12953
|
}
|
|
12466
|
-
function noSession(name) {
|
|
12467
|
-
return new TermError("TERM_NO_SESSION", `No session named "${name}" (no term sessions are running).`);
|
|
12468
|
-
}
|
|
12469
12954
|
function usage(text) {
|
|
12470
12955
|
return new TermError("TERM_USAGE", `Usage: ainecto ${text}`);
|
|
12471
12956
|
}
|
|
@@ -12525,19 +13010,6 @@ function singleName(positionals, usageText) {
|
|
|
12525
13010
|
function countFlag(value) {
|
|
12526
13011
|
return typeof value === "number" ? value : void 0;
|
|
12527
13012
|
}
|
|
12528
|
-
function sessionsField(data) {
|
|
12529
|
-
if (data && typeof data === "object" && "sessions" in data && Array.isArray(data.sessions)) {
|
|
12530
|
-
return data.sessions.filter(isListedSession);
|
|
12531
|
-
}
|
|
12532
|
-
return [];
|
|
12533
|
-
}
|
|
12534
|
-
function isListedSession(value) {
|
|
12535
|
-
if (!value || typeof value !== "object") {
|
|
12536
|
-
return false;
|
|
12537
|
-
}
|
|
12538
|
-
const session = value;
|
|
12539
|
-
return typeof session.name === "string" && typeof session.pid === "number" && typeof session.cwd === "string";
|
|
12540
|
-
}
|
|
12541
13013
|
function linesField(data) {
|
|
12542
13014
|
if (data && typeof data === "object" && "lines" in data && Array.isArray(data.lines)) {
|
|
12543
13015
|
return data.lines.filter((line) => typeof line === "string");
|
|
@@ -12563,7 +13035,7 @@ function restoreSummary(data) {
|
|
|
12563
13035
|
}
|
|
12564
13036
|
|
|
12565
13037
|
// src/adapters/cli/agentCommand.ts
|
|
12566
|
-
import { hostname } from "os";
|
|
13038
|
+
import { hostname as hostname2 } from "os";
|
|
12567
13039
|
|
|
12568
13040
|
// src/core/agent/agents.ts
|
|
12569
13041
|
var AGENT_IDS = ["claude-code", "codex"];
|
|
@@ -13386,101 +13858,34 @@ function toError(error) {
|
|
|
13386
13858
|
}
|
|
13387
13859
|
|
|
13388
13860
|
// src/core/agent/http.ts
|
|
13389
|
-
|
|
13390
|
-
var AgentCallError = class extends Error {
|
|
13861
|
+
var AgentCallError = class extends PcCallError {
|
|
13391
13862
|
constructor(message, op, status, code) {
|
|
13392
|
-
super(message);
|
|
13393
|
-
this.op = op;
|
|
13394
|
-
this.status = status;
|
|
13395
|
-
this.code = code;
|
|
13863
|
+
super(message, op, status, code);
|
|
13396
13864
|
this.name = "AgentCallError";
|
|
13397
13865
|
}
|
|
13398
|
-
op;
|
|
13399
|
-
status;
|
|
13400
|
-
code;
|
|
13401
|
-
/** 다시 해 볼 만한가 — 네트워크·기한·5xx·429. */
|
|
13402
|
-
get retryable() {
|
|
13403
|
-
return this.status === void 0 || this.status >= 500 || this.status === 429;
|
|
13404
|
-
}
|
|
13405
13866
|
};
|
|
13406
13867
|
function createAgentHttp(input) {
|
|
13407
|
-
const
|
|
13408
|
-
|
|
13409
|
-
|
|
13410
|
-
|
|
13411
|
-
|
|
13412
|
-
|
|
13413
|
-
|
|
13414
|
-
|
|
13415
|
-
|
|
13416
|
-
|
|
13417
|
-
|
|
13418
|
-
|
|
13419
|
-
|
|
13420
|
-
|
|
13421
|
-
|
|
13422
|
-
|
|
13423
|
-
|
|
13424
|
-
|
|
13425
|
-
} catch (error) {
|
|
13426
|
-
throw controller.signal.aborted && controller.signal.reason instanceof Error ? controller.signal.reason : error;
|
|
13427
|
-
} finally {
|
|
13428
|
-
clearTimeout(timer);
|
|
13429
|
-
options.signal?.removeEventListener("abort", onStop);
|
|
13430
|
-
}
|
|
13431
|
-
}
|
|
13432
|
-
return {
|
|
13433
|
-
useLinkToken(token) {
|
|
13434
|
-
linkToken = token;
|
|
13435
|
-
},
|
|
13436
|
-
async call(op, body, options = {}) {
|
|
13437
|
-
const callId = randomUUID2();
|
|
13438
|
-
const payload = JSON.stringify(body);
|
|
13439
|
-
const started = Date.now();
|
|
13440
|
-
input.log.write({ event: "agent_call", callId, op, turnUuid: options.turnUuid, bytes: Buffer.byteLength(payload, "utf8") });
|
|
13441
|
-
let outcome = {
|
|
13442
|
-
ok: false,
|
|
13443
|
-
error: "no response"
|
|
13444
|
-
};
|
|
13445
|
-
try {
|
|
13446
|
-
let response = await send(op, payload, await input.tokenProvider.getAccessToken(), options);
|
|
13447
|
-
if (response.status === 401) {
|
|
13448
|
-
response = await send(op, payload, await input.tokenProvider.refreshAfterUnauthorized(), options);
|
|
13449
|
-
}
|
|
13450
|
-
const text = await response.text();
|
|
13451
|
-
const parsed = parseJson2(text);
|
|
13452
|
-
if (!response.ok) {
|
|
13453
|
-
const code = typeof parsed?.code === "string" ? parsed.code : void 0;
|
|
13454
|
-
outcome = { ok: false, status: response.status, code };
|
|
13455
|
-
throw new AgentCallError(
|
|
13456
|
-
typeof parsed?.detail === "string" ? parsed.detail : `HTTP ${response.status}`,
|
|
13457
|
-
op,
|
|
13458
|
-
response.status,
|
|
13459
|
-
code
|
|
13460
|
-
);
|
|
13461
|
-
}
|
|
13462
|
-
const offers = Array.isArray(parsed?.offers) ? parsed.offers.length : void 0;
|
|
13463
|
-
outcome = { ok: true, status: response.status, offers };
|
|
13464
|
-
return parsed ?? {};
|
|
13465
|
-
} catch (error) {
|
|
13466
|
-
if (error instanceof AgentCallError) throw error;
|
|
13467
|
-
const timedOut = error instanceof Error && (error.name === "TimeoutError" || error.name === "AbortError");
|
|
13468
|
-
outcome = { ok: false, error: timedOut ? error.name : error instanceof Error ? error.message : String(error) };
|
|
13469
|
-
throw new AgentCallError(timedOut ? `${op} timed out` : `${op} failed: ${outcome.error}`, op);
|
|
13470
|
-
} finally {
|
|
13471
|
-
input.log.write({ event: "agent_call_response", callId, op, ...outcome, ms: Date.now() - started });
|
|
13472
|
-
}
|
|
13868
|
+
const http = createPcHttp({
|
|
13869
|
+
endpoint: input.endpoint,
|
|
13870
|
+
path: "agent/pc",
|
|
13871
|
+
tokenProvider: input.tokenProvider,
|
|
13872
|
+
timeoutMs: AGENT_CALL_TIMEOUT_MS,
|
|
13873
|
+
sessionHeader: "X-Link-Token",
|
|
13874
|
+
error: (message, op, status, code) => new AgentCallError(message, op, status, code),
|
|
13875
|
+
fetchImpl: input.fetchImpl,
|
|
13876
|
+
logging: {
|
|
13877
|
+
log: input.log,
|
|
13878
|
+
request: ({ callId, op, bytes }, options) => ({ event: "agent_call", callId, op, turnUuid: options?.turnUuid, bytes }),
|
|
13879
|
+
response: ({ callId, op, ms }, outcome) => ({
|
|
13880
|
+
event: "agent_call_response",
|
|
13881
|
+
callId,
|
|
13882
|
+
op,
|
|
13883
|
+
...outcome.ok ? { ok: true, status: outcome.status, offers: Array.isArray(outcome.body.offers) ? outcome.body.offers.length : void 0 } : outcome,
|
|
13884
|
+
ms
|
|
13885
|
+
})
|
|
13473
13886
|
}
|
|
13474
|
-
};
|
|
13475
|
-
}
|
|
13476
|
-
function parseJson2(text) {
|
|
13477
|
-
if (!text) return void 0;
|
|
13478
|
-
try {
|
|
13479
|
-
const value = JSON.parse(text);
|
|
13480
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
13481
|
-
} catch {
|
|
13482
|
-
return void 0;
|
|
13483
|
-
}
|
|
13887
|
+
});
|
|
13888
|
+
return { call: http.call, useLinkToken: http.useSessionToken };
|
|
13484
13889
|
}
|
|
13485
13890
|
|
|
13486
13891
|
// src/core/agent/tools.ts
|
|
@@ -13840,6 +14245,7 @@ function cardFactsOf(detail) {
|
|
|
13840
14245
|
status: card.status,
|
|
13841
14246
|
...typeof card.assignmentState === "string" ? { assignmentState: card.assignmentState } : {},
|
|
13842
14247
|
blocked: card.blocked === true,
|
|
14248
|
+
archived: card.archived === true,
|
|
13843
14249
|
...typeof d.description === "string" && d.description.trim() ? { description: d.description } : {},
|
|
13844
14250
|
criteria: (Array.isArray(d.criteria) ? d.criteria : []).flatMap((c) => {
|
|
13845
14251
|
const v = record(c);
|
|
@@ -13914,6 +14320,7 @@ async function runTodo(deps, todo) {
|
|
|
13914
14320
|
let conversationUuid;
|
|
13915
14321
|
let failure2;
|
|
13916
14322
|
let warning;
|
|
14323
|
+
let runDropped = false;
|
|
13917
14324
|
try {
|
|
13918
14325
|
const ends = async (value) => {
|
|
13919
14326
|
outcome = value;
|
|
@@ -13954,6 +14361,14 @@ async function runTodo(deps, todo) {
|
|
|
13954
14361
|
return await ends("review_requested");
|
|
13955
14362
|
} catch (error) {
|
|
13956
14363
|
failure2 = error instanceof Error ? error : new Error(String(error));
|
|
14364
|
+
if (todo.kind !== "DECISION_ANSWERED" && error instanceof AgentToolError && !error.retryable) {
|
|
14365
|
+
try {
|
|
14366
|
+
await deps.runs?.finished(todo.cardUuid);
|
|
14367
|
+
runDropped = true;
|
|
14368
|
+
} catch (saveError) {
|
|
14369
|
+
warning = `runs.json not updated: ${saveError instanceof Error ? saveError.message : String(saveError)}`;
|
|
14370
|
+
}
|
|
14371
|
+
}
|
|
13957
14372
|
throw error;
|
|
13958
14373
|
} finally {
|
|
13959
14374
|
deps.log.write({
|
|
@@ -13963,6 +14378,7 @@ async function runTodo(deps, todo) {
|
|
|
13963
14378
|
cardUuid: todo.cardUuid,
|
|
13964
14379
|
outcome: outcome ?? `error: ${failure2?.message ?? "unknown"}`,
|
|
13965
14380
|
...warning ? { warning } : {},
|
|
14381
|
+
...runDropped ? { runDropped } : {},
|
|
13966
14382
|
...failure2 instanceof AgentToolError ? { tool: failure2.tool, ...failure2.code ? { code: failure2.code } : {} } : {},
|
|
13967
14383
|
...workId ? { workId } : {},
|
|
13968
14384
|
...conversationUuid ? { conversationUuid } : {},
|
|
@@ -13976,7 +14392,7 @@ var OPENINGS = {
|
|
|
13976
14392
|
RESUME: (title) => `\uC774 PC \uAC00 \uB2E4\uC2DC \uCF1C\uC838 \xAB${title}\xBB \uC791\uC5C5\uC744 \uC774\uC5B4 \uAC00\uC694.`
|
|
13977
14393
|
};
|
|
13978
14394
|
function resumable(card, workId) {
|
|
13979
|
-
if (card.assignmentState !== "ACCEPTED" || card.blocked) return false;
|
|
14395
|
+
if (card.archived || card.assignmentState !== "ACCEPTED" || card.blocked) return false;
|
|
13980
14396
|
if (card.status !== "TODO" && card.status !== "IN_PROGRESS") return false;
|
|
13981
14397
|
return !workId || !card.workId || card.workId === workId;
|
|
13982
14398
|
}
|
|
@@ -14139,7 +14555,7 @@ async function runAgentServe(deps) {
|
|
|
14139
14555
|
}
|
|
14140
14556
|
const linkId = String(opened.linkId);
|
|
14141
14557
|
deps.http.useLinkToken(String(opened.linkToken));
|
|
14142
|
-
const limits =
|
|
14558
|
+
const limits = serverLimits2(opened.limits);
|
|
14143
14559
|
const displayName = (id) => deps.adapters.get(id)?.displayName ?? id;
|
|
14144
14560
|
const names = deps.agents.map((a) => displayName(a.id)).join(" / ");
|
|
14145
14561
|
deps.print(`Connected to AiNecto as ${deps.hostName}. Requests to \xABMy agent\xBB in AiNecto Chat now run in ${names} on this machine. Press Ctrl+C to stop.`);
|
|
@@ -14469,7 +14885,7 @@ async function runAgentServe(deps) {
|
|
|
14469
14885
|
function jobKey(job) {
|
|
14470
14886
|
return job.kind === "chat" ? job.offer.turnUuid : todoKey(job.todo.todoId);
|
|
14471
14887
|
}
|
|
14472
|
-
function
|
|
14888
|
+
function serverLimits2(value) {
|
|
14473
14889
|
const v = value ?? {};
|
|
14474
14890
|
const num = (key) => {
|
|
14475
14891
|
const n = v[key];
|
|
@@ -14487,7 +14903,8 @@ async function openLink(deps, agents) {
|
|
|
14487
14903
|
const features = pcFeatures(deps.todos !== void 0);
|
|
14488
14904
|
const older = features.filter((f) => f !== "todos");
|
|
14489
14905
|
const attempts = [
|
|
14490
|
-
{ body: { ...base, agents, features } },
|
|
14906
|
+
...deps.cliBuild ? [{ body: { ...base, cliBuild: deps.cliBuild, agents, features } }] : [],
|
|
14907
|
+
{ body: { ...base, agents, features }, ...deps.cliBuild ? { dropped: "cliBuild" } : {} },
|
|
14491
14908
|
...older.length < features.length ? [{ body: { ...base, agents, features: older }, dropped: "features.todos" }] : [],
|
|
14492
14909
|
...named ? [{ body: { ...base, agents: unnamed, features: older }, dropped: "agents.name" }] : [],
|
|
14493
14910
|
{ body: { ...base, agents: unnamed }, dropped: "features" }
|
|
@@ -14540,21 +14957,6 @@ function offersIn(res) {
|
|
|
14540
14957
|
}] : [];
|
|
14541
14958
|
});
|
|
14542
14959
|
}
|
|
14543
|
-
function sleep(ms, signal) {
|
|
14544
|
-
return new Promise((resolve4) => {
|
|
14545
|
-
if (signal.aborted) {
|
|
14546
|
-
resolve4();
|
|
14547
|
-
return;
|
|
14548
|
-
}
|
|
14549
|
-
const timer = setTimeout(done, ms);
|
|
14550
|
-
signal.addEventListener("abort", done, { once: true });
|
|
14551
|
-
function done() {
|
|
14552
|
-
clearTimeout(timer);
|
|
14553
|
-
signal.removeEventListener("abort", done);
|
|
14554
|
-
resolve4();
|
|
14555
|
-
}
|
|
14556
|
-
});
|
|
14557
|
-
}
|
|
14558
14960
|
|
|
14559
14961
|
// src/core/agent/sessions.ts
|
|
14560
14962
|
import { readFile as readFile10, rename as rename7, writeFile as writeFile7 } from "fs/promises";
|
|
@@ -14630,7 +15032,7 @@ async function executeAgentServe(input) {
|
|
|
14630
15032
|
await ensurePrivateDir(paths.dir);
|
|
14631
15033
|
await ensurePrivateDir(paths.work);
|
|
14632
15034
|
const log = openAgentLog(paths);
|
|
14633
|
-
const host =
|
|
15035
|
+
const host = hostname2();
|
|
14634
15036
|
const client = (agentName) => new McpRpcClient({ endpoint: input.endpoint, tokenProvider: input.auth, channel: "cli", ...agentName ? { agentName } : {} });
|
|
14635
15037
|
const tools = createAgentTools({
|
|
14636
15038
|
client: client(),
|
|
@@ -14654,7 +15056,7 @@ async function executeAgentServe(input) {
|
|
|
14654
15056
|
log.write({
|
|
14655
15057
|
event: "serve_start",
|
|
14656
15058
|
pid: process.pid,
|
|
14657
|
-
version:
|
|
15059
|
+
version: CLI_VERSION_LABEL,
|
|
14658
15060
|
endpoint: input.endpoint,
|
|
14659
15061
|
host,
|
|
14660
15062
|
agents: checks.map(({ id, installed, ready, auth, version }) => ({ id, installed, ready, ...auth ? { auth } : {}, ...version ? { version } : {} }))
|
|
@@ -14690,7 +15092,8 @@ async function executeAgentServe(input) {
|
|
|
14690
15092
|
adapters,
|
|
14691
15093
|
agents,
|
|
14692
15094
|
hostName: host,
|
|
14693
|
-
cliVersion:
|
|
15095
|
+
cliVersion: CLI_VERSION_LABEL,
|
|
15096
|
+
...CLI_BUILD ? { cliBuild: CLI_BUILD } : {},
|
|
14694
15097
|
print: (line) => input.io.stderr.write(`${line}
|
|
14695
15098
|
`),
|
|
14696
15099
|
signal: controller.signal,
|
|
@@ -14721,7 +15124,7 @@ async function runAinectoCli(argv, io) {
|
|
|
14721
15124
|
io.stdout.write(helpText());
|
|
14722
15125
|
return 0;
|
|
14723
15126
|
}
|
|
14724
|
-
if (parsed.positionals[0] === "term") {
|
|
15127
|
+
if (parsed.positionals[0] === "term" && parsed.positionals[1] !== "remote") {
|
|
14725
15128
|
return await executeTermCommand({ argv: parsed.positionals.slice(1), json: parsed.json, io });
|
|
14726
15129
|
}
|
|
14727
15130
|
const resolved = resolveEndpoint({ env: parsed.env, endpoint: parsed.endpoint });
|
|
@@ -14823,6 +15226,9 @@ async function runAinectoCli(argv, io) {
|
|
|
14823
15226
|
io
|
|
14824
15227
|
});
|
|
14825
15228
|
}
|
|
15229
|
+
if (domain === "term") {
|
|
15230
|
+
return await executeTermRemote({ argv: rest, json: parsed.json, io, endpoint: resolved.endpoint, auth: connect2().auth });
|
|
15231
|
+
}
|
|
14826
15232
|
if (isAgentCommand(domain, action)) {
|
|
14827
15233
|
return await executeAgentServe({ endpoint: resolved.endpoint, env: resolved.env, auth: connect2().auth, io, agentName });
|
|
14828
15234
|
}
|