@ainecto/cli 0.16.1 → 0.16.3
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 +8 -4
- package/dist/bin/ainecto.js +815 -99
- package/dist/bin/ainecto.js.map +1 -1
- package/dist/bin/mcp.js +2 -2
- package/package.json +2 -2
package/dist/bin/ainecto.js
CHANGED
|
@@ -5699,8 +5699,8 @@ function legacyRoleInput(flag, envVars = process.env) {
|
|
|
5699
5699
|
|
|
5700
5700
|
// src/core/version.ts
|
|
5701
5701
|
var UNBUNDLED_VERSION = "dev";
|
|
5702
|
-
var CLI_VERSION = true ? "0.16.
|
|
5703
|
-
var CLI_BUILD = true ? "
|
|
5702
|
+
var CLI_VERSION = true ? "0.16.3" : UNBUNDLED_VERSION;
|
|
5703
|
+
var CLI_BUILD = true ? "8924808" : void 0;
|
|
5704
5704
|
function cliVersionLabel(version, build, release2) {
|
|
5705
5705
|
return release2 || build === void 0 ? version : `${version}-dev+${build}`;
|
|
5706
5706
|
}
|
|
@@ -11369,7 +11369,14 @@ function parseClientMessage(line) {
|
|
|
11369
11369
|
case "key":
|
|
11370
11370
|
return { id, op, name: stringField(record4, "name"), key: stringField(record4, "key"), ...optionalInstance(record4) };
|
|
11371
11371
|
case "read":
|
|
11372
|
-
return {
|
|
11372
|
+
return {
|
|
11373
|
+
id,
|
|
11374
|
+
op,
|
|
11375
|
+
name: stringField(record4, "name"),
|
|
11376
|
+
scrollback: record4.scrollback === true,
|
|
11377
|
+
lines: optionalSize(record4, "lines"),
|
|
11378
|
+
...record4.styles === true ? { styles: true } : {}
|
|
11379
|
+
};
|
|
11373
11380
|
case "kill":
|
|
11374
11381
|
return { id, op, name: stringField(record4, "name"), ...optionalInstance(record4) };
|
|
11375
11382
|
case "watch":
|
|
@@ -11441,7 +11448,17 @@ function readModes(data) {
|
|
|
11441
11448
|
const altScreen = "altScreen" in modes ? modes.altScreen : void 0;
|
|
11442
11449
|
const appCursor = "appCursor" in modes ? modes.appCursor : void 0;
|
|
11443
11450
|
const bracketedPaste = "bracketedPaste" in modes ? modes.bracketedPaste : void 0;
|
|
11444
|
-
|
|
11451
|
+
const mouse = "mouse" in modes ? modes.mouse : void 0;
|
|
11452
|
+
return typeof altScreen === "boolean" && typeof appCursor === "boolean" && typeof bracketedPaste === "boolean" ? { altScreen, appCursor, bracketedPaste, ...typeof mouse === "boolean" ? { mouse } : {} } : void 0;
|
|
11453
|
+
}
|
|
11454
|
+
function readStyles(data, lineCount) {
|
|
11455
|
+
if (!data || typeof data !== "object" || !("styles" in data) || !("runs" in data)) return void 0;
|
|
11456
|
+
const { styles, runs } = data;
|
|
11457
|
+
if (!Array.isArray(styles) || !styles.every((style) => style && typeof style === "object" && !Array.isArray(style))) return void 0;
|
|
11458
|
+
if (!Array.isArray(runs) || runs.length !== lineCount || !runs.every((row) => Array.isArray(row) && row.length % 3 === 0 && row.every((value) => Number.isInteger(value) && value >= 0))) return void 0;
|
|
11459
|
+
const cursor = "cursor" in data ? data.cursor : void 0;
|
|
11460
|
+
const at = cursor && typeof cursor === "object" && "row" in cursor && "col" in cursor && Number.isInteger(cursor.row) && Number.isInteger(cursor.col) ? { row: cursor.row, col: cursor.col } : void 0;
|
|
11461
|
+
return { styles, runs, ...at ? { cursor: at } : {} };
|
|
11445
11462
|
}
|
|
11446
11463
|
function sessionInstance(data) {
|
|
11447
11464
|
return data && typeof data === "object" && "instance" in data && typeof data.instance === "string" && data.instance !== "" ? data.instance : void 0;
|
|
@@ -11852,8 +11869,24 @@ var KEY_NAMES = [
|
|
|
11852
11869
|
"ctrl-space",
|
|
11853
11870
|
"ctrl-slash",
|
|
11854
11871
|
"alt-<key>",
|
|
11855
|
-
"ctrl-/shift-/alt- + up/down/left/right/home/end/pageup/pagedown/delete"
|
|
11872
|
+
"ctrl-/shift-/alt- + up/down/left/right/home/end/pageup/pagedown/delete",
|
|
11873
|
+
"wheel-up",
|
|
11874
|
+
"wheel-down"
|
|
11856
11875
|
];
|
|
11876
|
+
function wheelBytes(up, context) {
|
|
11877
|
+
const wheel = context.wheel;
|
|
11878
|
+
if (!wheel) return void 0;
|
|
11879
|
+
if (wheel.mouseTracking !== "none") {
|
|
11880
|
+
const button = up ? 64 : 65;
|
|
11881
|
+
const x = Math.max(1, Math.ceil(wheel.cols / 2));
|
|
11882
|
+
const y = Math.max(1, Math.ceil(wheel.rows / 2));
|
|
11883
|
+
return wheel.sgrMouse ? `\x1B[<${button};${x};${y}M` : `\x1B[M${String.fromCharCode(32 + button, 32 + Math.min(x, 223), 32 + Math.min(y, 223))}`;
|
|
11884
|
+
}
|
|
11885
|
+
if (wheel.altScreen) {
|
|
11886
|
+
return `${context.applicationCursorKeys ? "\x1BO" : "\x1B["}${up ? "A" : "B"}`;
|
|
11887
|
+
}
|
|
11888
|
+
return "";
|
|
11889
|
+
}
|
|
11857
11890
|
function normalizeKeyName(raw) {
|
|
11858
11891
|
const lower = raw.trim().toLowerCase().replace(/\+/g, "-");
|
|
11859
11892
|
return ALIASES[lower] ?? lower;
|
|
@@ -11868,6 +11901,9 @@ function keyBytes(raw, context) {
|
|
|
11868
11901
|
if (cursor !== void 0) {
|
|
11869
11902
|
return `${context.applicationCursorKeys ? "\x1BO" : "\x1B["}${cursor}`;
|
|
11870
11903
|
}
|
|
11904
|
+
if (name === "wheel-up" || name === "wheel-down") {
|
|
11905
|
+
return wheelBytes(name === "wheel-up", context);
|
|
11906
|
+
}
|
|
11871
11907
|
return comboBytes(name);
|
|
11872
11908
|
}
|
|
11873
11909
|
function comboBytes(name) {
|
|
@@ -12255,16 +12291,108 @@ function oscWithoutQueries(payload) {
|
|
|
12255
12291
|
|
|
12256
12292
|
// src/core/term/screen.ts
|
|
12257
12293
|
function screenLines(buffer, rows, range) {
|
|
12294
|
+
return styledScreen(buffer, rows, range, false).lines;
|
|
12295
|
+
}
|
|
12296
|
+
function styledScreen(buffer, rows, range, cursorVisible) {
|
|
12258
12297
|
const end = buffer.baseY + rows;
|
|
12259
12298
|
const start = range.scrollback ? 0 : buffer.baseY;
|
|
12260
12299
|
const lines = [];
|
|
12300
|
+
const runs = [];
|
|
12301
|
+
const styles = [];
|
|
12302
|
+
const styleIndex = /* @__PURE__ */ new Map();
|
|
12303
|
+
const cell = buffer.getNullCell();
|
|
12261
12304
|
for (let index = start; index < end; index += 1) {
|
|
12262
|
-
|
|
12263
|
-
|
|
12264
|
-
|
|
12265
|
-
|
|
12305
|
+
const line = buffer.getLine(index);
|
|
12306
|
+
const text2 = line?.translateToString(true) ?? "";
|
|
12307
|
+
lines.push(text2);
|
|
12308
|
+
const row = [];
|
|
12309
|
+
let offset = 0;
|
|
12310
|
+
for (let column = 0; line && column < line.length && offset < text2.length; column += 1) {
|
|
12311
|
+
line.getCell(column, cell);
|
|
12312
|
+
if (cell.getWidth() === 0) continue;
|
|
12313
|
+
const length = (cell.getChars() || " ").length;
|
|
12314
|
+
const style = cellStyle(cell);
|
|
12315
|
+
if (style) {
|
|
12316
|
+
const key = JSON.stringify(style);
|
|
12317
|
+
let at = styleIndex.get(key);
|
|
12318
|
+
if (at === void 0) {
|
|
12319
|
+
at = styles.length;
|
|
12320
|
+
styles.push(style);
|
|
12321
|
+
styleIndex.set(key, at);
|
|
12322
|
+
}
|
|
12323
|
+
const stop = Math.min(offset + length, text2.length);
|
|
12324
|
+
if (row.length > 0 && row[row.length - 1] === at && row[row.length - 2] === offset) {
|
|
12325
|
+
row[row.length - 2] = stop;
|
|
12326
|
+
} else {
|
|
12327
|
+
row.push(offset, stop, at);
|
|
12328
|
+
}
|
|
12329
|
+
}
|
|
12330
|
+
offset += length;
|
|
12331
|
+
}
|
|
12332
|
+
runs.push(row);
|
|
12266
12333
|
}
|
|
12267
|
-
|
|
12334
|
+
let kept = lines.length;
|
|
12335
|
+
while (kept > 0 && lines[kept - 1] === "") kept -= 1;
|
|
12336
|
+
const from = range.lines === void 0 ? 0 : Math.max(0, kept - range.lines);
|
|
12337
|
+
const cursorRow = buffer.baseY + buffer.cursorY - start - from;
|
|
12338
|
+
return {
|
|
12339
|
+
lines: lines.slice(from, kept),
|
|
12340
|
+
styles,
|
|
12341
|
+
runs: runs.slice(from, kept),
|
|
12342
|
+
...cursorVisible && cursorRow >= 0 ? { cursor: { row: cursorRow, col: cursorColumn(buffer, cell) } } : {}
|
|
12343
|
+
};
|
|
12344
|
+
}
|
|
12345
|
+
function cursorColumn(buffer, cell) {
|
|
12346
|
+
const line = buffer.getLine(buffer.baseY + buffer.cursorY);
|
|
12347
|
+
let offset = 0;
|
|
12348
|
+
for (let column = 0; line && column < buffer.cursorX && column < line.length; column += 1) {
|
|
12349
|
+
line.getCell(column, cell);
|
|
12350
|
+
if (cell.getWidth() !== 0) offset += (cell.getChars() || " ").length;
|
|
12351
|
+
}
|
|
12352
|
+
return offset + Math.max(0, buffer.cursorX - (line?.length ?? 0));
|
|
12353
|
+
}
|
|
12354
|
+
function cellStyle(cell) {
|
|
12355
|
+
if (cell.isAttributeDefault()) return void 0;
|
|
12356
|
+
const style = {};
|
|
12357
|
+
const fg = cellColor(cell.isFgDefault(), cell.isFgRGB(), cell.getFgColor());
|
|
12358
|
+
const bg = cellColor(cell.isBgDefault(), cell.isBgRGB(), cell.getBgColor());
|
|
12359
|
+
if (fg !== void 0) style.fg = fg;
|
|
12360
|
+
if (bg !== void 0) style.bg = bg;
|
|
12361
|
+
if (cell.isBold()) style.bold = true;
|
|
12362
|
+
if (cell.isDim()) style.dim = true;
|
|
12363
|
+
if (cell.isItalic()) style.italic = true;
|
|
12364
|
+
if (cell.isUnderline()) style.underline = true;
|
|
12365
|
+
if (cell.isInverse()) style.inverse = true;
|
|
12366
|
+
if (cell.isInvisible()) style.invisible = true;
|
|
12367
|
+
if (cell.isStrikethrough()) style.strike = true;
|
|
12368
|
+
return Object.keys(style).length > 0 ? style : void 0;
|
|
12369
|
+
}
|
|
12370
|
+
function cellColor(isDefault, isRgb, value) {
|
|
12371
|
+
if (isDefault) return void 0;
|
|
12372
|
+
return isRgb ? `#${value.toString(16).padStart(6, "0")}` : value;
|
|
12373
|
+
}
|
|
12374
|
+
function trackScreenFlags(terminal) {
|
|
12375
|
+
const flags = { cursorVisible: true, sgrMouse: false };
|
|
12376
|
+
const privateMode = (on) => (params) => {
|
|
12377
|
+
for (const param of params) {
|
|
12378
|
+
if (param === 25) flags.cursorVisible = on;
|
|
12379
|
+
if (param === 1006) flags.sgrMouse = on;
|
|
12380
|
+
}
|
|
12381
|
+
return false;
|
|
12382
|
+
};
|
|
12383
|
+
terminal.parser.registerCsiHandler({ prefix: "?", final: "h" }, privateMode(true));
|
|
12384
|
+
terminal.parser.registerCsiHandler({ prefix: "?", final: "l" }, privateMode(false));
|
|
12385
|
+
const reset = () => {
|
|
12386
|
+
flags.cursorVisible = true;
|
|
12387
|
+
flags.sgrMouse = false;
|
|
12388
|
+
return false;
|
|
12389
|
+
};
|
|
12390
|
+
terminal.parser.registerEscHandler({ final: "c" }, reset);
|
|
12391
|
+
terminal.parser.registerCsiHandler({ intermediates: "!", final: "p" }, () => {
|
|
12392
|
+
flags.cursorVisible = true;
|
|
12393
|
+
return false;
|
|
12394
|
+
});
|
|
12395
|
+
return flags;
|
|
12268
12396
|
}
|
|
12269
12397
|
function terminalResetSequence(modes, alternateScreen) {
|
|
12270
12398
|
let reset = "\x1B[0m";
|
|
@@ -12296,16 +12424,18 @@ var FULL_TERMINAL_RESET = terminalResetSequence(
|
|
|
12296
12424
|
// src/core/term/session.ts
|
|
12297
12425
|
var SESSION_ENV = "AINECTO_TERM_SESSION";
|
|
12298
12426
|
var TermSession = class _TermSession {
|
|
12299
|
-
constructor(spec, pty, screen, serializer) {
|
|
12427
|
+
constructor(spec, pty, screen, serializer, flags) {
|
|
12300
12428
|
this.spec = spec;
|
|
12301
12429
|
this.pty = pty;
|
|
12302
12430
|
this.screen = screen;
|
|
12303
12431
|
this.serializer = serializer;
|
|
12432
|
+
this.flags = flags;
|
|
12304
12433
|
}
|
|
12305
12434
|
spec;
|
|
12306
12435
|
pty;
|
|
12307
12436
|
screen;
|
|
12308
12437
|
serializer;
|
|
12438
|
+
flags;
|
|
12309
12439
|
attached = /* @__PURE__ */ new Map();
|
|
12310
12440
|
/** watch 중인 쪽 → 다음 «바뀜» 알림을 보낼 차례인가. */
|
|
12311
12441
|
watchers = /* @__PURE__ */ new Map();
|
|
@@ -12339,7 +12469,8 @@ var TermSession = class _TermSession {
|
|
|
12339
12469
|
const screen = new import_headless.default.Terminal({ cols: pty.cols, rows: pty.rows, allowProposedApi: true });
|
|
12340
12470
|
const serializer = new import_addon_serialize.default.SerializeAddon();
|
|
12341
12471
|
screen.loadAddon(serializer);
|
|
12342
|
-
const
|
|
12472
|
+
const flags = trackScreenFlags(screen);
|
|
12473
|
+
const session = new _TermSession(spec, pty, screen, serializer, flags);
|
|
12343
12474
|
session.label = spec.label;
|
|
12344
12475
|
screen.onData((answer) => session.answerQuery(answer));
|
|
12345
12476
|
pty.onData((data) => session.handleOutput(data));
|
|
@@ -12374,7 +12505,8 @@ var TermSession = class _TermSession {
|
|
|
12374
12505
|
return {
|
|
12375
12506
|
altScreen: this.screen.buffer.active.type === "alternate",
|
|
12376
12507
|
appCursor: this.screen.modes.applicationCursorKeysMode,
|
|
12377
|
-
bracketedPaste: this.screen.modes.bracketedPasteMode
|
|
12508
|
+
bracketedPaste: this.screen.modes.bracketedPasteMode,
|
|
12509
|
+
mouse: this.screen.modes.mouseTrackingMode !== "none"
|
|
12378
12510
|
};
|
|
12379
12511
|
}
|
|
12380
12512
|
async send(text2, paste) {
|
|
@@ -12383,7 +12515,16 @@ var TermSession = class _TermSession {
|
|
|
12383
12515
|
}
|
|
12384
12516
|
async key(name) {
|
|
12385
12517
|
await this.settled();
|
|
12386
|
-
const bytes = keyBytes(name, {
|
|
12518
|
+
const bytes = keyBytes(name, {
|
|
12519
|
+
applicationCursorKeys: this.screen.modes.applicationCursorKeysMode,
|
|
12520
|
+
wheel: {
|
|
12521
|
+
mouseTracking: this.screen.modes.mouseTrackingMode,
|
|
12522
|
+
sgrMouse: this.flags.sgrMouse,
|
|
12523
|
+
altScreen: this.screen.buffer.active.type === "alternate",
|
|
12524
|
+
cols: this.screen.cols,
|
|
12525
|
+
rows: this.screen.rows
|
|
12526
|
+
}
|
|
12527
|
+
});
|
|
12387
12528
|
if (bytes === void 0) {
|
|
12388
12529
|
throw new TermError("TERM_UNKNOWN_KEY", `Unknown key "${name}".`);
|
|
12389
12530
|
}
|
|
@@ -12397,6 +12538,14 @@ var TermSession = class _TermSession {
|
|
|
12397
12538
|
await this.settled();
|
|
12398
12539
|
return screenLines(this.screen.buffer.active, this.screen.rows, range);
|
|
12399
12540
|
}
|
|
12541
|
+
/** {@link read} 와 같은 줄에 글자 속성·커서까지(원격 웹 화면 — 색·흐림을 칠한다). */
|
|
12542
|
+
async readStyled(range, reader) {
|
|
12543
|
+
if (reader && this.watchers.has(reader)) {
|
|
12544
|
+
this.watchers.set(reader, true);
|
|
12545
|
+
}
|
|
12546
|
+
await this.settled();
|
|
12547
|
+
return styledScreen(this.screen.buffer.active, this.screen.rows, range, this.flags.cursorVisible);
|
|
12548
|
+
}
|
|
12400
12549
|
/**
|
|
12401
12550
|
* 붙는다 — ★첫 화면(직렬화)과 그 «뒤» 출력의 경계를 맞춘다: 붙는 순간부터 오는 출력은 모아 두고,
|
|
12402
12551
|
* 그 앞까지 그린 화면을 직렬화해 보낸 다음 모은 출력을 흘린다(설계 2-3 «화면 세대 번호»와 같은 일).
|
|
@@ -12783,7 +12932,12 @@ var TermDaemon = class {
|
|
|
12783
12932
|
}
|
|
12784
12933
|
case "read": {
|
|
12785
12934
|
const session = this.session(request.name);
|
|
12786
|
-
const
|
|
12935
|
+
const range = { scrollback: request.scrollback, lines: request.lines };
|
|
12936
|
+
if (request.styles) {
|
|
12937
|
+
const screen = await session.readStyled(range, connection);
|
|
12938
|
+
return { data: { name: request.name, instance: session.instance, ...screen, modes: await session.modes() } };
|
|
12939
|
+
}
|
|
12940
|
+
const lines = await session.read(range, connection);
|
|
12787
12941
|
return { data: { name: request.name, instance: session.instance, lines, modes: await session.modes() } };
|
|
12788
12942
|
}
|
|
12789
12943
|
case "kill": {
|
|
@@ -13522,8 +13676,12 @@ function sleep(ms, signal) {
|
|
|
13522
13676
|
}
|
|
13523
13677
|
|
|
13524
13678
|
// src/core/agent/agents.ts
|
|
13525
|
-
var AGENT_IDS = ["claude-code", "codex"];
|
|
13526
|
-
var AGENT_MCP_CLIENT_NAMES = {
|
|
13679
|
+
var AGENT_IDS = ["claude-code", "codex", "antigravity"];
|
|
13680
|
+
var AGENT_MCP_CLIENT_NAMES = {
|
|
13681
|
+
"claude-code": "claude-code",
|
|
13682
|
+
codex: "codex-mcp-client",
|
|
13683
|
+
antigravity: "antigravity-client"
|
|
13684
|
+
};
|
|
13527
13685
|
var DEFAULT_AGENT = "claude-code";
|
|
13528
13686
|
function isAgentId(value) {
|
|
13529
13687
|
return typeof value === "string" && AGENT_IDS.includes(value);
|
|
@@ -13715,6 +13873,8 @@ function replyForOutcome(outcome, limits, agentName) {
|
|
|
13715
13873
|
case "exited":
|
|
13716
13874
|
return failed("AGENT_EXITED", `${agentName} \uAC00 \uB05D\uB0AC\uC5B4\uC694(code ${outcome.code ?? "-"}${outcome.signal ? `, ${outcome.signal}` : ""}).` + (outcome.stderrTail ? `
|
|
13717
13875
|
${outcome.stderrTail}` : ""));
|
|
13876
|
+
case "refused":
|
|
13877
|
+
return failed(outcome.errorCode, outcome.errorCode === "AGENT_PREVIOUS_RUNNING" ? `${agentName} \uC758 \uC55E \uC694\uCCAD \uD504\uB85C\uC138\uC2A4\uAC00 \uC544\uC9C1 \uB05D\uB098\uC9C0 \uC54A\uC544 \uC774\uBC88 \uC694\uCCAD\uC740 \uC2E4\uD589\uD558\uC9C0 \uC54A\uC558\uC5B4\uC694. \uC7A0\uC2DC \uB4A4 \uB2E4\uC2DC \uBCF4\uB0B4 \uC8FC\uC138\uC694(${outcome.reason}).` : `${agentName} \uC124\uC815\uC744 \uB2E4 \uD655\uC778\uD558\uC9C0 \uBABB\uD574 \uC774 PC \uC5D0\uC11C \uC2E4\uD589\uD558\uC9C0 \uC54A\uC558\uC5B4\uC694(${outcome.reason}).`);
|
|
13718
13878
|
case "result": {
|
|
13719
13879
|
const { result } = outcome;
|
|
13720
13880
|
if (result.isError) {
|
|
@@ -14216,7 +14376,7 @@ var TODO_NOTES = {
|
|
|
14216
14376
|
stopped: "Stopped."
|
|
14217
14377
|
};
|
|
14218
14378
|
var SERVE_CONNECTED_PREFIX = "Connected to AiNecto as ";
|
|
14219
|
-
var AGENT_MISSING_LINE = "Agent: no
|
|
14379
|
+
var AGENT_MISSING_LINE = "Agent: no supported agent CLI on this PC \u2014 install one, then `ainecto` again.";
|
|
14220
14380
|
var SERVE_RECONNECTED_LINE = "AiNecto lost this connection (it may have restarted); connected again.";
|
|
14221
14381
|
async function runAgentServe(deps) {
|
|
14222
14382
|
const folderName = deps.todos?.agentName;
|
|
@@ -14419,10 +14579,10 @@ async function runAgentServe(deps) {
|
|
|
14419
14579
|
await session.interrupt();
|
|
14420
14580
|
await session.close();
|
|
14421
14581
|
}
|
|
14422
|
-
if (outcome.kind
|
|
14582
|
+
if (outcome.kind === "timeout" || outcome.kind === "exited") {
|
|
14423
14583
|
if (live.get(adapter.id) === session) live.delete(adapter.id);
|
|
14424
14584
|
if (session.resumed) await deps.sessions.forget(offer.conversationUuid, adapter.id);
|
|
14425
|
-
} else if (session.sessionRef) {
|
|
14585
|
+
} else if (outcome.kind === "result" && session.sessionRef) {
|
|
14426
14586
|
await deps.sessions.set(offer.conversationUuid, adapter.id, session.sessionRef);
|
|
14427
14587
|
}
|
|
14428
14588
|
reply = stopping.has(offer.key) ? stoppedReply(outcome, limits) : replyForOutcome(outcome, limits, adapter.displayName);
|
|
@@ -14619,15 +14779,19 @@ function serverLimits(value) {
|
|
|
14619
14779
|
};
|
|
14620
14780
|
return { pollHoldSeconds: num("pollHoldSeconds"), textMaxCharacters: num("textMaxCharacters"), documentsMax: num("documentsMax") };
|
|
14621
14781
|
}
|
|
14622
|
-
async function openLink(deps,
|
|
14782
|
+
async function openLink(deps, allAgents) {
|
|
14623
14783
|
const base = { hostName: deps.hostName, cliVersion: deps.cliVersion };
|
|
14784
|
+
const agents = allAgents.filter((a) => !NEWER_AGENT_IDS.includes(a.id));
|
|
14785
|
+
const newer = agents.length < allAgents.length;
|
|
14624
14786
|
const named = agents.some((a) => a.name !== void 0);
|
|
14625
14787
|
const unnamed = agents.map(({ name: _name, ...rest }) => rest);
|
|
14626
14788
|
const features = pcFeatures(deps.todos !== void 0);
|
|
14627
14789
|
const older = features.filter((f) => f !== "todos");
|
|
14790
|
+
const build = deps.cliBuild ? { cliBuild: deps.cliBuild } : {};
|
|
14628
14791
|
const attempts = [
|
|
14629
|
-
...
|
|
14630
|
-
{ body: { ...base, agents, features }, ...
|
|
14792
|
+
...newer ? [{ body: { ...base, ...build, agents: allAgents, features } }] : [],
|
|
14793
|
+
...deps.cliBuild ? [{ body: { ...base, cliBuild: deps.cliBuild, agents, features }, ...newer ? { dropped: "agents.newer" } : {} }] : [],
|
|
14794
|
+
{ body: { ...base, agents, features }, ...deps.cliBuild ? { dropped: "cliBuild" } : newer ? { dropped: "agents.newer" } : {} },
|
|
14631
14795
|
...older.length < features.length ? [{ body: { ...base, agents, features: older }, dropped: "features.todos" }] : [],
|
|
14632
14796
|
...named ? [{ body: { ...base, agents: unnamed, features: older }, dropped: "agents.name" }] : [],
|
|
14633
14797
|
{ body: { ...base, agents: unnamed }, dropped: "features" }
|
|
@@ -14643,6 +14807,7 @@ async function openLink(deps, agents) {
|
|
|
14643
14807
|
}
|
|
14644
14808
|
}
|
|
14645
14809
|
}
|
|
14810
|
+
var NEWER_AGENT_IDS = ["antigravity"];
|
|
14646
14811
|
function folderKind(agents) {
|
|
14647
14812
|
return agents.find((a) => a.ready && a.id === DEFAULT_AGENT)?.id ?? agents.find((a) => a.ready)?.id;
|
|
14648
14813
|
}
|
|
@@ -15669,21 +15834,34 @@ function sessionsKey(sessions) {
|
|
|
15669
15834
|
|
|
15670
15835
|
// src/core/term/remoteFrame.ts
|
|
15671
15836
|
import { createHash as createHash7 } from "crypto";
|
|
15672
|
-
function screenFrame(lines, maxD) {
|
|
15837
|
+
function screenFrame(lines, maxD, attributes) {
|
|
15673
15838
|
const sizes = lines.map((line) => Buffer.byteLength(line, "utf8"));
|
|
15839
|
+
const runs = attributes?.runs.length === lines.length ? attributes.runs : void 0;
|
|
15840
|
+
const runSizes = runs ? runs.map((row) => JSON.stringify(row).length + 1) : [];
|
|
15674
15841
|
let start = 0;
|
|
15675
15842
|
let bytes = sizes.reduce((sum, size) => sum + size, 0) + Math.max(0, lines.length - 1) * 2;
|
|
15676
|
-
|
|
15843
|
+
const fixed = runs ? 10 + CURSOR_BYTES : 0;
|
|
15844
|
+
let runBytes = runSizes.reduce((sum, size) => sum + size, 0);
|
|
15845
|
+
while (start < lines.length && base64Length(bytes) + fixed + runBytes > maxD) {
|
|
15677
15846
|
bytes -= (sizes[start] ?? 0) + (start < lines.length - 1 ? 2 : 0);
|
|
15847
|
+
runBytes -= runSizes[start] ?? 0;
|
|
15678
15848
|
start += 1;
|
|
15679
15849
|
}
|
|
15680
15850
|
const text2 = lines.slice(start).join("\r\n");
|
|
15851
|
+
const kept = runs?.slice(start);
|
|
15852
|
+
const cursorRow = attributes?.cursor ? attributes.cursor.row - start : -1;
|
|
15853
|
+
const cursor = attributes?.cursor && cursorRow >= 0 ? { row: cursorRow, col: attributes.cursor.col } : void 0;
|
|
15854
|
+
const hash = createHash7("sha256").update(text2, "utf8");
|
|
15855
|
+
if (kept) hash.update(JSON.stringify([attributes?.styles, kept, cursor ?? null]), "utf8");
|
|
15681
15856
|
return {
|
|
15682
15857
|
d: Buffer.from(text2, "utf8").toString("base64"),
|
|
15683
|
-
|
|
15858
|
+
...kept ? { runs: kept } : {},
|
|
15859
|
+
...cursor ? { cursor } : {},
|
|
15860
|
+
hash: hash.digest("hex"),
|
|
15684
15861
|
dropped: start
|
|
15685
15862
|
};
|
|
15686
15863
|
}
|
|
15864
|
+
var CURSOR_BYTES = Buffer.byteLength(JSON.stringify({ cursor: { row: 2 ** 32 - 1, col: 2 ** 32 - 1 } }), "utf8");
|
|
15687
15865
|
var GCM_TAG_BYTES = 16;
|
|
15688
15866
|
var MAX_COUNTER = 2 ** 32 - 1;
|
|
15689
15867
|
function frameBudget(frameMaxBytes, outer, sealed) {
|
|
@@ -15796,7 +15974,7 @@ var RemoteViewer = class {
|
|
|
15796
15974
|
}
|
|
15797
15975
|
let data;
|
|
15798
15976
|
try {
|
|
15799
|
-
data = await client.request({ op: "read", name, scrollback: true, lines: FRAME_SCROLLBACK_LINES + rows });
|
|
15977
|
+
data = await client.request({ op: "read", name, scrollback: true, lines: FRAME_SCROLLBACK_LINES + rows, styles: true });
|
|
15800
15978
|
} catch (error) {
|
|
15801
15979
|
this.daemonFailed("read", error);
|
|
15802
15980
|
return;
|
|
@@ -15810,9 +15988,11 @@ var RemoteViewer = class {
|
|
|
15810
15988
|
return;
|
|
15811
15989
|
}
|
|
15812
15990
|
const modes = readModes(data);
|
|
15991
|
+
const lines = readLines(data);
|
|
15992
|
+
const attributes = readStyles(data, lines.length);
|
|
15813
15993
|
const outer = { linkId: target.linkId, channelId: this.deps.channelId, session: name, cols, rows };
|
|
15814
|
-
const sealed = { ...modes ? { modes } : {}, instance };
|
|
15815
|
-
const frame = screenFrame(
|
|
15994
|
+
const sealed = { ...modes ? { modes } : {}, ...attributes ? { styles: attributes.styles } : {}, instance };
|
|
15995
|
+
const frame = screenFrame(lines, frameBudget(target.frameMaxBytes, outer, sealed), attributes);
|
|
15816
15996
|
if (frame.dropped !== dropped) {
|
|
15817
15997
|
dropped = frame.dropped;
|
|
15818
15998
|
this.deps.log.write({ event: "remote_frame_trimmed", channelId: this.deps.channelId, session: name, dropped });
|
|
@@ -15821,7 +16001,13 @@ var RemoteViewer = class {
|
|
|
15821
16001
|
if (key === sentKey) continue;
|
|
15822
16002
|
let box;
|
|
15823
16003
|
try {
|
|
15824
|
-
box = await this.deps.seal({
|
|
16004
|
+
box = await this.deps.seal({
|
|
16005
|
+
d: frame.d,
|
|
16006
|
+
...sealed,
|
|
16007
|
+
...frame.runs ? { runs: frame.runs } : {},
|
|
16008
|
+
...frame.cursor ? { cursor: frame.cursor } : {},
|
|
16009
|
+
executedThrough
|
|
16010
|
+
});
|
|
15825
16011
|
} catch (error) {
|
|
15826
16012
|
this.stop();
|
|
15827
16013
|
this.deps.onChannelEnded(error instanceof ChannelSealError ? error.reason : "CHANNEL_GONE");
|
|
@@ -17464,7 +17650,7 @@ function pcResultText(result) {
|
|
|
17464
17650
|
if (result.kind === "already") {
|
|
17465
17651
|
return `This PC is already connected to AiNecto (folder ${result.folder}, version ${result.version}). ${STOP} Log: ${result.log}`;
|
|
17466
17652
|
}
|
|
17467
|
-
const use = result.agentMissing ? "From AiNecto on the web you can open a terminal on this PC and run commands. No Claude Code or
|
|
17653
|
+
const use = result.agentMissing ? "From AiNecto on the web you can open a terminal on this PC and run commands. No Claude Code, Codex or Antigravity was found, so AiNecto agent work cannot run here yet \u2014 install one, then run `ainecto` again." : "From AiNecto on the web you can open a terminal on this PC and run commands, and your AiNecto agent can run work here (Claude Code, Codex or Antigravity).";
|
|
17468
17654
|
return `This PC is now connected to AiNecto. ${use} It keeps running after you close this window. ${STOP} Log: ${result.log}`;
|
|
17469
17655
|
}
|
|
17470
17656
|
function pcNotApprovedText(hostName, then) {
|
|
@@ -17513,7 +17699,7 @@ async function executePcStart(deps) {
|
|
|
17513
17699
|
}
|
|
17514
17700
|
note("");
|
|
17515
17701
|
note(`This connects this PC to AiNecto as ${status.account?.displayName ?? "your account"} (${deps.endpoint}).`);
|
|
17516
|
-
note(" \xB7 Your AiNecto agent will run work on this PC (Claude Code / Codex).");
|
|
17702
|
+
note(" \xB7 Your AiNecto agent will run work on this PC (Claude Code / Codex / Antigravity).");
|
|
17517
17703
|
note(" \xB7 From AiNecto on the web, you can open terminals on this PC and run commands in them.");
|
|
17518
17704
|
note(" \xB7 It keeps itself up to date \u2014 new AiNecto releases built and signed on AiNecto's GitHub are installed when this PC is idle.");
|
|
17519
17705
|
if (!yes(await promptLine(deps.io, "Connect this PC? [y/N]: "), false)) {
|
|
@@ -18250,7 +18436,7 @@ function swapArgsOf(argv) {
|
|
|
18250
18436
|
|
|
18251
18437
|
// src/adapters/cli/ainectoCli.ts
|
|
18252
18438
|
import { mkdtemp, rm as rm3 } from "fs/promises";
|
|
18253
|
-
import { join as
|
|
18439
|
+
import { join as join14 } from "path";
|
|
18254
18440
|
|
|
18255
18441
|
// src/adapters/cli/pcStatus.ts
|
|
18256
18442
|
import { readFile as readFile14 } from "fs/promises";
|
|
@@ -18264,6 +18450,7 @@ function agentPaths(home = homedir5()) {
|
|
|
18264
18450
|
return {
|
|
18265
18451
|
dir,
|
|
18266
18452
|
work: join10(dir, "work"),
|
|
18453
|
+
antigravity: join10(dir, "antigravity"),
|
|
18267
18454
|
sessions: join10(dir, "sessions.json"),
|
|
18268
18455
|
runs: join10(dir, "runs.json"),
|
|
18269
18456
|
log: join10(dir, "agent.log"),
|
|
@@ -18296,7 +18483,176 @@ async function pcStatus(status, endpoint) {
|
|
|
18296
18483
|
}
|
|
18297
18484
|
|
|
18298
18485
|
// src/adapters/cli/agentCommand.ts
|
|
18299
|
-
import {
|
|
18486
|
+
import { createHash as createHash8 } from "crypto";
|
|
18487
|
+
import { homedir as homedir6, hostname as hostname3 } from "os";
|
|
18488
|
+
import { join as join13 } from "path";
|
|
18489
|
+
|
|
18490
|
+
// src/core/agent/antigravity.ts
|
|
18491
|
+
import { mkdir as mkdir7, readFile as readFile16 } from "fs/promises";
|
|
18492
|
+
import { join as join12 } from "path";
|
|
18493
|
+
|
|
18494
|
+
// src/core/agent/antigravityArgs.ts
|
|
18495
|
+
var AGY = "agy";
|
|
18496
|
+
var VERIFIED_AGY_VERSION = "1.5.15";
|
|
18497
|
+
var ANTIGRAVITY_MCP_SERVER = "ainecto-pc";
|
|
18498
|
+
var AGY_CUSTOMIZATION_DIRS = [".agents", ".agent", "_agents", "_agent"];
|
|
18499
|
+
var BUILTIN_DENY = ["command(*)", "write_file(*)", "read_file(*)", "read_url(*)", "execute_url(*)"];
|
|
18500
|
+
function antigravityToolPreamble(tools) {
|
|
18501
|
+
const definitions = tools.map(({ name, description, inputSchema }) => ({ name, description, inputSchema }));
|
|
18502
|
+
return `[AiNecto tool definitions \u2014 MCP server "${ANTIGRAVITY_MCP_SERVER}" (call these with call_mcp_tool; the definitions are complete, do not look for definition files)]
|
|
18503
|
+
${JSON.stringify(definitions)}
|
|
18504
|
+
|
|
18505
|
+
`;
|
|
18506
|
+
}
|
|
18507
|
+
function antigravityMcpConfig(bridge) {
|
|
18508
|
+
return { mcpServers: { [ANTIGRAVITY_MCP_SERVER]: { command: bridge.command, args: bridge.args } } };
|
|
18509
|
+
}
|
|
18510
|
+
function antigravitySettings(denyServers) {
|
|
18511
|
+
return {
|
|
18512
|
+
toolPermission: "request-review",
|
|
18513
|
+
permissions: {
|
|
18514
|
+
allow: [`mcp(${ANTIGRAVITY_MCP_SERVER}/*)`],
|
|
18515
|
+
deny: [...BUILTIN_DENY, ...denyServers.map((name) => `mcp(${name}/*)`)]
|
|
18516
|
+
}
|
|
18517
|
+
};
|
|
18518
|
+
}
|
|
18519
|
+
function antigravityAgentArgs(input) {
|
|
18520
|
+
const args = [
|
|
18521
|
+
// ★`-p` 는 값을 받는다 — 비우지 않으면 다음 인자를 프롬프트로 먹는다(실측 1.5.14 끝 코드 2). 프롬프트는 stdin(stream-json) 한 줄이라 빈 글.
|
|
18522
|
+
"-p",
|
|
18523
|
+
"",
|
|
18524
|
+
"--input-format",
|
|
18525
|
+
"stream-json",
|
|
18526
|
+
"--output-format",
|
|
18527
|
+
"stream-json",
|
|
18528
|
+
"--json-schema",
|
|
18529
|
+
JSON.stringify(input.schema),
|
|
18530
|
+
"--settings",
|
|
18531
|
+
JSON.stringify(input.settings)
|
|
18532
|
+
];
|
|
18533
|
+
if (input.conversationId) {
|
|
18534
|
+
args.push("--conversation", input.conversationId);
|
|
18535
|
+
}
|
|
18536
|
+
return args;
|
|
18537
|
+
}
|
|
18538
|
+
|
|
18539
|
+
// src/core/agent/antigravityPolicy.ts
|
|
18540
|
+
import { existsSync as existsSync2 } from "fs";
|
|
18541
|
+
import { mkdir as mkdir6, readdir as readdir2, readFile as readFile15, rename as rename7, writeFile as writeFile8 } from "fs/promises";
|
|
18542
|
+
import { dirname as dirname8, join as join11, parse as parsePath } from "path";
|
|
18543
|
+
var SAFE_SERVER_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
18544
|
+
var Refuse = class extends Error {
|
|
18545
|
+
constructor(reason, path) {
|
|
18546
|
+
super(reason);
|
|
18547
|
+
this.reason = reason;
|
|
18548
|
+
this.path = path;
|
|
18549
|
+
}
|
|
18550
|
+
reason;
|
|
18551
|
+
path;
|
|
18552
|
+
};
|
|
18553
|
+
async function antigravityMcpPolicy(input) {
|
|
18554
|
+
try {
|
|
18555
|
+
const names = /* @__PURE__ */ new Set();
|
|
18556
|
+
const add = (found, path) => {
|
|
18557
|
+
for (const name of found) {
|
|
18558
|
+
if (!SAFE_SERVER_NAME.test(name)) throw new Refuse("server name the deny rule cannot carry", path);
|
|
18559
|
+
if (name === ANTIGRAVITY_MCP_SERVER) throw new Refuse(`another config also names ${ANTIGRAVITY_MCP_SERVER}`, path);
|
|
18560
|
+
names.add(name);
|
|
18561
|
+
}
|
|
18562
|
+
};
|
|
18563
|
+
for (const dir of selfAndAncestors(input.cwd)) {
|
|
18564
|
+
if (existsSync2(join11(dir, ".git"))) throw new Refuse("work folder is inside a git repository", join11(dir, ".git"));
|
|
18565
|
+
}
|
|
18566
|
+
await onlyEntry(input.cwd, ".agents");
|
|
18567
|
+
const ours = join11(input.cwd, ".agents");
|
|
18568
|
+
await onlyEntry(ours, "mcp_config.json");
|
|
18569
|
+
const ourNames = await serverNames(join11(ours, "mcp_config.json"));
|
|
18570
|
+
if (ourNames.length !== 1 || ourNames[0] !== ANTIGRAVITY_MCP_SERVER) {
|
|
18571
|
+
throw new Refuse("work folder config is not ours", join11(ours, "mcp_config.json"));
|
|
18572
|
+
}
|
|
18573
|
+
for (const dir of selfAndAncestors(dirname8(input.cwd))) {
|
|
18574
|
+
for (const folder of AGY_CUSTOMIZATION_DIRS) {
|
|
18575
|
+
const file = join11(dir, folder, "mcp_config.json");
|
|
18576
|
+
if (existsSync2(file)) add(await serverNames(file), file);
|
|
18577
|
+
}
|
|
18578
|
+
}
|
|
18579
|
+
const globalRoot = join11(input.home, ".gemini", "config");
|
|
18580
|
+
const globalPlugins = join11(globalRoot, "plugins.json");
|
|
18581
|
+
if (existsSync2(globalPlugins)) throw new Refuse("global plugins.json adds plugins that agy plugin list does not show", globalPlugins);
|
|
18582
|
+
const globalFile = join11(globalRoot, "mcp_config.json");
|
|
18583
|
+
if (existsSync2(globalFile)) add(await serverNames(globalFile), globalFile);
|
|
18584
|
+
const listed3 = await input.pluginList();
|
|
18585
|
+
if (!listed3.ok) throw new Refuse(`agy plugin list failed: ${listed3.detail}`);
|
|
18586
|
+
for (const plugin of pluginEntries(listed3.stdout)) {
|
|
18587
|
+
add(plugin.mcpServers, plugin.path);
|
|
18588
|
+
const file = join11(plugin.path, "mcp_config.json");
|
|
18589
|
+
if (existsSync2(file)) add(await serverNames(file), file);
|
|
18590
|
+
}
|
|
18591
|
+
return { ok: true, deny: [...names].sort() };
|
|
18592
|
+
} catch (error) {
|
|
18593
|
+
if (error instanceof Refuse) return { ok: false, reason: error.reason, ...error.path ? { path: error.path } : {} };
|
|
18594
|
+
return { ok: false, reason: `could not read the Antigravity settings: ${error instanceof Error ? error.message : String(error)}` };
|
|
18595
|
+
}
|
|
18596
|
+
}
|
|
18597
|
+
async function writeWorkspaceMcpConfig(cwd, config) {
|
|
18598
|
+
const target = join11(cwd, ".agents", "mcp_config.json");
|
|
18599
|
+
await mkdir6(dirname8(target), { recursive: true, mode: 448 });
|
|
18600
|
+
const temp = join11(dirname8(cwd), `.${parsePath(cwd).base}.mcp_config.${process.pid}.tmp`);
|
|
18601
|
+
await writeFile8(temp, `${JSON.stringify(config)}
|
|
18602
|
+
`, { mode: 384 });
|
|
18603
|
+
await rename7(temp, target);
|
|
18604
|
+
}
|
|
18605
|
+
function selfAndAncestors(start) {
|
|
18606
|
+
const out = [];
|
|
18607
|
+
let dir = start;
|
|
18608
|
+
for (; ; ) {
|
|
18609
|
+
out.push(dir);
|
|
18610
|
+
const parent = dirname8(dir);
|
|
18611
|
+
if (parent === dir) return out;
|
|
18612
|
+
dir = parent;
|
|
18613
|
+
}
|
|
18614
|
+
}
|
|
18615
|
+
async function onlyEntry(dir, expected) {
|
|
18616
|
+
const entries2 = await readdir2(dir);
|
|
18617
|
+
const others = entries2.filter((name) => name !== expected);
|
|
18618
|
+
if (others.length > 0 || !entries2.includes(expected)) {
|
|
18619
|
+
throw new Refuse("work folder holds something other than our config", join11(dir, others[0] ?? expected));
|
|
18620
|
+
}
|
|
18621
|
+
}
|
|
18622
|
+
async function serverNames(file) {
|
|
18623
|
+
const text2 = await readFile15(file, "utf8");
|
|
18624
|
+
if (text2.trim() === "") return [];
|
|
18625
|
+
let value;
|
|
18626
|
+
try {
|
|
18627
|
+
value = JSON.parse(text2);
|
|
18628
|
+
} catch {
|
|
18629
|
+
throw new Refuse("unreadable mcp_config.json", file);
|
|
18630
|
+
}
|
|
18631
|
+
if (!isObject2(value)) throw new Refuse("unknown mcp_config.json shape", file);
|
|
18632
|
+
if (value.mcpServers === void 0) return [];
|
|
18633
|
+
if (!isObject2(value.mcpServers)) throw new Refuse("unknown mcp_config.json shape", file);
|
|
18634
|
+
return Object.keys(value.mcpServers);
|
|
18635
|
+
}
|
|
18636
|
+
function pluginEntries(stdout) {
|
|
18637
|
+
let value;
|
|
18638
|
+
try {
|
|
18639
|
+
value = JSON.parse(stdout);
|
|
18640
|
+
} catch {
|
|
18641
|
+
throw new Refuse("unreadable agy plugin list");
|
|
18642
|
+
}
|
|
18643
|
+
if (!Array.isArray(value)) throw new Refuse("unknown agy plugin list shape");
|
|
18644
|
+
return value.map((item) => {
|
|
18645
|
+
if (!isObject2(item) || typeof item.path !== "string") throw new Refuse("unknown agy plugin list shape");
|
|
18646
|
+
const servers = item.mcpServers ?? [];
|
|
18647
|
+
if (!Array.isArray(servers) || !servers.every((name) => typeof name === "string")) {
|
|
18648
|
+
throw new Refuse("unknown agy plugin list shape", item.path);
|
|
18649
|
+
}
|
|
18650
|
+
return { path: item.path, mcpServers: servers };
|
|
18651
|
+
});
|
|
18652
|
+
}
|
|
18653
|
+
function isObject2(value) {
|
|
18654
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18655
|
+
}
|
|
18300
18656
|
|
|
18301
18657
|
// src/core/agent/child.ts
|
|
18302
18658
|
import { createInterface as createInterface3 } from "readline";
|
|
@@ -18308,6 +18664,7 @@ var AgentChild = class {
|
|
|
18308
18664
|
stderr = "";
|
|
18309
18665
|
exitInfo;
|
|
18310
18666
|
exited;
|
|
18667
|
+
outputDone;
|
|
18311
18668
|
onKilled;
|
|
18312
18669
|
constructor(spawnImpl, command, args, options, hooks) {
|
|
18313
18670
|
this.onKilled = hooks.killed;
|
|
@@ -18325,14 +18682,16 @@ var AgentChild = class {
|
|
|
18325
18682
|
};
|
|
18326
18683
|
this.child.on("exit", done);
|
|
18327
18684
|
this.child.on("error", (error) => {
|
|
18328
|
-
this.stderr
|
|
18329
|
-
${error.message}
|
|
18330
|
-
done(null, null);
|
|
18685
|
+
this.stderr = `${this.stderr}
|
|
18686
|
+
${error.message}`.slice(-STDERR_KEEP);
|
|
18687
|
+
if (this.child.pid === void 0) done(null, null);
|
|
18331
18688
|
});
|
|
18332
18689
|
});
|
|
18333
18690
|
this.child.stdin.on("error", () => {
|
|
18334
18691
|
});
|
|
18335
|
-
createInterface3({ input: this.child.stdout })
|
|
18692
|
+
const lines = createInterface3({ input: this.child.stdout });
|
|
18693
|
+
lines.on("line", hooks.line);
|
|
18694
|
+
this.outputDone = new Promise((resolve4) => lines.once("close", () => resolve4()));
|
|
18336
18695
|
}
|
|
18337
18696
|
get pid() {
|
|
18338
18697
|
return this.child.pid ?? -1;
|
|
@@ -18354,19 +18713,33 @@ ${error.message}`;
|
|
|
18354
18713
|
`);
|
|
18355
18714
|
return true;
|
|
18356
18715
|
}
|
|
18357
|
-
/** stdin
|
|
18358
|
-
|
|
18716
|
+
/** stdin 만 닫는다(입력 끝 알림) — 프로세스는 그대로 돈다. 한 차례에 프로세스 하나인 Agent(agy -p)가 쓴다. */
|
|
18717
|
+
endInput() {
|
|
18718
|
+
if (this.alive) this.child.stdin.end();
|
|
18719
|
+
}
|
|
18720
|
+
/** 기다리지 않고 바로 끈다(SIGTERM → B6 → SIGKILL · Windows 는 taskkill /T /F). 결과는 hooks.killed 에도. */
|
|
18721
|
+
async forceStop() {
|
|
18359
18722
|
if (!this.alive) return void 0;
|
|
18360
|
-
this.child.stdin.end();
|
|
18361
|
-
if (await this.waitExit(AGENT_STOP_WAIT_MS)) return void 0;
|
|
18362
18723
|
const first = await killTree(this.child, AGENT_STOP_WAIT_MS, "SIGTERM");
|
|
18363
18724
|
const result = first.directExited ? first : await killTree(this.child, AGENT_STOP_WAIT_MS, "SIGKILL");
|
|
18364
18725
|
this.onKilled?.(result);
|
|
18365
18726
|
return result;
|
|
18366
18727
|
}
|
|
18367
|
-
|
|
18728
|
+
/** stdin 을 닫아 스스로 끝나게 하고, 안 끝나면 강제로. 강제로 껐으면 그 결과(직계·트리)를 돌려주고 hooks.killed 에도 알린다. */
|
|
18729
|
+
async stop() {
|
|
18730
|
+
if (!this.alive) return void 0;
|
|
18731
|
+
this.child.stdin.end();
|
|
18732
|
+
if (await this.waitForExit(AGENT_STOP_WAIT_MS)) return void 0;
|
|
18733
|
+
return await this.forceStop();
|
|
18734
|
+
}
|
|
18735
|
+
/** {@code ms} 안에 프로세스가 끝나면 true. */
|
|
18736
|
+
async waitForExit(ms) {
|
|
18368
18737
|
return await withDeadline(this.exited.then(() => true), ms, false);
|
|
18369
18738
|
}
|
|
18739
|
+
/** stdout 이 다 읽혔으면(마지막 줄까지 hooks.line 으로 나갔으면) true — exit 이 마지막 줄보다 먼저 올 수 있다. */
|
|
18740
|
+
async waitForOutput(ms) {
|
|
18741
|
+
return await withDeadline(this.outputDone.then(() => true), ms, false);
|
|
18742
|
+
}
|
|
18370
18743
|
};
|
|
18371
18744
|
async function withDeadline(work, ms, fallback) {
|
|
18372
18745
|
let timer;
|
|
@@ -18444,42 +18817,6 @@ async function detectByVersion(spawnImpl, command, options) {
|
|
|
18444
18817
|
return { installed: true, version: run.stdout.trim().split("\n")[0]?.trim() };
|
|
18445
18818
|
}
|
|
18446
18819
|
|
|
18447
|
-
// src/core/agent/claudeArgs.ts
|
|
18448
|
-
function claudeMcpConfig(bridge) {
|
|
18449
|
-
return { mcpServers: { [AINECTO_MCP_SERVER]: { command: bridge.command, args: bridge.args } } };
|
|
18450
|
-
}
|
|
18451
|
-
function claudeAgentArgs(input) {
|
|
18452
|
-
const args = [
|
|
18453
|
-
"-p",
|
|
18454
|
-
"--input-format",
|
|
18455
|
-
"stream-json",
|
|
18456
|
-
"--output-format",
|
|
18457
|
-
"stream-json",
|
|
18458
|
-
"--verbose",
|
|
18459
|
-
"--json-schema",
|
|
18460
|
-
JSON.stringify(input.schema),
|
|
18461
|
-
"--tools",
|
|
18462
|
-
"",
|
|
18463
|
-
// 내장 도구(Bash·Read·Write·Edit·Agent·Skill·WebFetch…) 전부 끔
|
|
18464
|
-
"--strict-mcp-config",
|
|
18465
|
-
"--mcp-config",
|
|
18466
|
-
JSON.stringify(input.mcpConfig),
|
|
18467
|
-
"--allowedTools",
|
|
18468
|
-
`mcp__${AINECTO_MCP_SERVER}`,
|
|
18469
|
-
"--permission-mode",
|
|
18470
|
-
"dontAsk",
|
|
18471
|
-
// 허용 밖은 묻지 않고 바로 거절(헤드리스에서 묻기 = 2분 대기)
|
|
18472
|
-
"--setting-sources",
|
|
18473
|
-
""
|
|
18474
|
-
// 사용자·프로젝트 설정(플러그인·스킬·훅·권한) 끔
|
|
18475
|
-
];
|
|
18476
|
-
if (input.resumeSessionId) {
|
|
18477
|
-
args.push("--resume", input.resumeSessionId);
|
|
18478
|
-
}
|
|
18479
|
-
return args;
|
|
18480
|
-
}
|
|
18481
|
-
var AINECTO_TOOL_PREFIX = `mcp__${AINECTO_MCP_SERVER}__`;
|
|
18482
|
-
|
|
18483
18820
|
// src/core/agent/documents.ts
|
|
18484
18821
|
var DOCUMENT_LINE = /📄[^\n]*?\/app\/docs\/([0-9a-f]{32})(?![0-9a-f])/gu;
|
|
18485
18822
|
var HEX32 = /^[0-9a-f]{32}$/;
|
|
@@ -18581,6 +18918,369 @@ function appendUnique(target, items) {
|
|
|
18581
18918
|
}
|
|
18582
18919
|
}
|
|
18583
18920
|
|
|
18921
|
+
// src/core/agent/antigravity.ts
|
|
18922
|
+
function antigravityAdapter(deps) {
|
|
18923
|
+
const processes = new AgyProcesses();
|
|
18924
|
+
const tools = { names: new Set(deps.tools.map((tool) => tool.name)), preamble: antigravityToolPreamble(deps.tools) };
|
|
18925
|
+
return {
|
|
18926
|
+
id: "antigravity",
|
|
18927
|
+
displayName: "Antigravity",
|
|
18928
|
+
async detect() {
|
|
18929
|
+
const detected = await detectByVersion(deps.spawnImpl, AGY, { cwd: deps.home, env: deps.env, timeoutMs: AGENT_CALL_TIMEOUT_MS });
|
|
18930
|
+
if (detected.installed && detected.version !== VERIFIED_AGY_VERSION) {
|
|
18931
|
+
deps.log.write({ event: "agent_version_unverified", agent: "antigravity", version: detected.version ?? "-", verified: VERIFIED_AGY_VERSION });
|
|
18932
|
+
}
|
|
18933
|
+
return detected;
|
|
18934
|
+
},
|
|
18935
|
+
async authStatus() {
|
|
18936
|
+
const run = await runToEnd(deps.spawnImpl, AGY, ["models"], { cwd: deps.home, env: deps.env, timeoutMs: AGENT_CALL_TIMEOUT_MS });
|
|
18937
|
+
if (run.spawnError || run.timedOut) return { ready: false, detail: run.spawnError ?? "timed out" };
|
|
18938
|
+
return antigravityAuth(run.code, deps.env, await modelProvider(deps.home));
|
|
18939
|
+
},
|
|
18940
|
+
open: ({ conversationUuid, resumeRef, textMaxCharacters, documentsMax, agentName }) => new AntigravitySession(conversationUuid, resumeRef, agentName, deps.schema(textMaxCharacters, documentsMax), deps, processes, tools)
|
|
18941
|
+
};
|
|
18942
|
+
}
|
|
18943
|
+
function antigravityAuth(code, env, provider) {
|
|
18944
|
+
if (code !== 0) return { ready: false, detail: "sign in \u2014 run `agy` once" };
|
|
18945
|
+
if ((env.GEMINI_API_KEY ?? "") !== "" && provider === "gemini") return { ready: true, mode: "apiKey", method: "gemini-api-key" };
|
|
18946
|
+
if (env.AGY_ADC_AUTH === "true") return { ready: true, mode: "apiKey", method: "google-cloud-adc" };
|
|
18947
|
+
return { ready: true, mode: "subscription", method: "google-account" };
|
|
18948
|
+
}
|
|
18949
|
+
async function modelProvider(home) {
|
|
18950
|
+
try {
|
|
18951
|
+
const value = JSON.parse(await readFile16(join12(home, ".gemini", "antigravity-cli", "settings.json"), "utf8"));
|
|
18952
|
+
const provider = value?.modelProvider;
|
|
18953
|
+
return typeof provider === "string" ? provider : void 0;
|
|
18954
|
+
} catch {
|
|
18955
|
+
return void 0;
|
|
18956
|
+
}
|
|
18957
|
+
}
|
|
18958
|
+
var AgyProcesses = class {
|
|
18959
|
+
children = /* @__PURE__ */ new Set();
|
|
18960
|
+
stuck = /* @__PURE__ */ new Set();
|
|
18961
|
+
add(child) {
|
|
18962
|
+
this.children.add(child);
|
|
18963
|
+
}
|
|
18964
|
+
exited(child) {
|
|
18965
|
+
this.children.delete(child);
|
|
18966
|
+
this.stuck.delete(child);
|
|
18967
|
+
}
|
|
18968
|
+
/** 모두 끝났나 — 안 끝난 것은 B6 기다리고 강제로 끈다(이미 못 끈 것은 기다리지 않는다). 하나라도 살아 있으면 그 pid 들. */
|
|
18969
|
+
async settle() {
|
|
18970
|
+
for (const child of [...this.children]) {
|
|
18971
|
+
if (!child.alive || this.stuck.has(child)) continue;
|
|
18972
|
+
if (await child.waitForExit(AGENT_STOP_WAIT_MS)) continue;
|
|
18973
|
+
await child.forceStop();
|
|
18974
|
+
if (child.alive) this.stuck.add(child);
|
|
18975
|
+
}
|
|
18976
|
+
return [...this.children].filter((child) => child.alive).map((child) => child.pid);
|
|
18977
|
+
}
|
|
18978
|
+
/** close — 아직 못 끈 것으로 표시되지 않은 것만 끈다(못 끈 것은 settle 이 계속 막는다). */
|
|
18979
|
+
async stopAll() {
|
|
18980
|
+
await Promise.all([...this.children].filter((child) => !this.stuck.has(child)).map(async (child) => {
|
|
18981
|
+
await child.forceStop();
|
|
18982
|
+
if (child.alive) this.stuck.add(child);
|
|
18983
|
+
}));
|
|
18984
|
+
}
|
|
18985
|
+
};
|
|
18986
|
+
var AntigravitySession = class {
|
|
18987
|
+
constructor(conversationUuid, resumeRef, agentName, schema, deps, processes, tools) {
|
|
18988
|
+
this.conversationUuid = conversationUuid;
|
|
18989
|
+
this.agentName = agentName;
|
|
18990
|
+
this.schema = schema;
|
|
18991
|
+
this.deps = deps;
|
|
18992
|
+
this.processes = processes;
|
|
18993
|
+
this.tools = tools;
|
|
18994
|
+
this.resumed = resumeRef !== void 0;
|
|
18995
|
+
this.sessionRef = resumeRef;
|
|
18996
|
+
this.cwd = deps.workDir(agentName);
|
|
18997
|
+
}
|
|
18998
|
+
conversationUuid;
|
|
18999
|
+
agentName;
|
|
19000
|
+
schema;
|
|
19001
|
+
deps;
|
|
19002
|
+
processes;
|
|
19003
|
+
tools;
|
|
19004
|
+
agent = "antigravity";
|
|
19005
|
+
resumed;
|
|
19006
|
+
sessionRef;
|
|
19007
|
+
closed = false;
|
|
19008
|
+
generation = 0;
|
|
19009
|
+
lastPid = -1;
|
|
19010
|
+
turn;
|
|
19011
|
+
cwd;
|
|
19012
|
+
get pid() {
|
|
19013
|
+
return this.lastPid;
|
|
19014
|
+
}
|
|
19015
|
+
get alive() {
|
|
19016
|
+
return !this.closed;
|
|
19017
|
+
}
|
|
19018
|
+
async send(text2, timeoutMs) {
|
|
19019
|
+
if (this.closed) return { kind: "exited", code: null, signal: null, stderrTail: "session closed" };
|
|
19020
|
+
let resolve4;
|
|
19021
|
+
const outcome = new Promise((r) => {
|
|
19022
|
+
resolve4 = r;
|
|
19023
|
+
});
|
|
19024
|
+
const turn = {
|
|
19025
|
+
generation: ++this.generation,
|
|
19026
|
+
resolve: resolve4,
|
|
19027
|
+
facts: new TurnFactsCollector(),
|
|
19028
|
+
counted: /* @__PURE__ */ new Set(),
|
|
19029
|
+
foreign: [],
|
|
19030
|
+
interrupted: false,
|
|
19031
|
+
done: false
|
|
19032
|
+
};
|
|
19033
|
+
this.turn = turn;
|
|
19034
|
+
void this.run(turn, text2).catch((error) => this.finish(turn, {
|
|
19035
|
+
kind: "exited",
|
|
19036
|
+
code: null,
|
|
19037
|
+
signal: null,
|
|
19038
|
+
stderrTail: error instanceof Error ? error.message : String(error)
|
|
19039
|
+
}));
|
|
19040
|
+
try {
|
|
19041
|
+
return await withDeadline(outcome, timeoutMs, { kind: "timeout" });
|
|
19042
|
+
} finally {
|
|
19043
|
+
if (!turn.done) {
|
|
19044
|
+
turn.interrupted = true;
|
|
19045
|
+
turn.done = true;
|
|
19046
|
+
}
|
|
19047
|
+
if (this.turn === turn) this.turn = void 0;
|
|
19048
|
+
}
|
|
19049
|
+
}
|
|
19050
|
+
async interrupt() {
|
|
19051
|
+
const turn = this.turn;
|
|
19052
|
+
if (!turn || turn.done) return;
|
|
19053
|
+
turn.interrupted = true;
|
|
19054
|
+
if (turn.child?.alive) {
|
|
19055
|
+
await turn.child.forceStop();
|
|
19056
|
+
} else {
|
|
19057
|
+
this.finishInterrupted(turn);
|
|
19058
|
+
}
|
|
19059
|
+
}
|
|
19060
|
+
async close() {
|
|
19061
|
+
this.closed = true;
|
|
19062
|
+
const turn = this.turn;
|
|
19063
|
+
if (turn) turn.interrupted = true;
|
|
19064
|
+
await this.processes.stopAll();
|
|
19065
|
+
if (turn) this.finishInterrupted(turn);
|
|
19066
|
+
}
|
|
19067
|
+
/** 한 차례 — 앞 프로세스 정리 → 사전 점검 → 띄우기. await 마다 멈춤을 다시 본다. */
|
|
19068
|
+
async run(turn, text2) {
|
|
19069
|
+
const running = await this.processes.settle();
|
|
19070
|
+
if (running.length > 0) {
|
|
19071
|
+
this.deps.log.write({ event: "agent_previous_running", agent: this.agent, conversationUuid: this.conversationUuid, pids: running });
|
|
19072
|
+
this.finish(turn, { kind: "refused", errorCode: "AGENT_PREVIOUS_RUNNING", reason: `the previous Antigravity process did not stop (pid ${running.join(", ")})` });
|
|
19073
|
+
return;
|
|
19074
|
+
}
|
|
19075
|
+
if (this.stopped(turn)) return this.finishInterrupted(turn);
|
|
19076
|
+
let policy;
|
|
19077
|
+
try {
|
|
19078
|
+
await mkdir7(this.cwd, { recursive: true, mode: 448 });
|
|
19079
|
+
await writeWorkspaceMcpConfig(this.cwd, this.deps.mcpConfig(this.agentName));
|
|
19080
|
+
policy = await antigravityMcpPolicy({ cwd: this.cwd, home: this.deps.home, pluginList: () => this.pluginList() });
|
|
19081
|
+
} catch (error) {
|
|
19082
|
+
policy = { ok: false, reason: `could not prepare the work folder: ${error instanceof Error ? error.message : String(error)}` };
|
|
19083
|
+
}
|
|
19084
|
+
if (this.stopped(turn)) return this.finishInterrupted(turn);
|
|
19085
|
+
if (!policy.ok) {
|
|
19086
|
+
this.deps.log.write({
|
|
19087
|
+
event: "agent_policy_unverified",
|
|
19088
|
+
agent: this.agent,
|
|
19089
|
+
conversationUuid: this.conversationUuid,
|
|
19090
|
+
reason: policy.reason,
|
|
19091
|
+
...policy.path ? { path: policy.path } : {}
|
|
19092
|
+
});
|
|
19093
|
+
this.finish(turn, { kind: "refused", errorCode: "AGENT_POLICY_UNVERIFIED", reason: policy.reason });
|
|
19094
|
+
return;
|
|
19095
|
+
}
|
|
19096
|
+
const args = antigravityAgentArgs({ schema: this.schema, settings: antigravitySettings(policy.deny), conversationId: this.sessionRef });
|
|
19097
|
+
const child = new AgentChild(this.deps.spawnImpl, AGY, args, { cwd: this.cwd, env: this.deps.env }, {
|
|
19098
|
+
line: (line) => this.onLine(turn, child, line),
|
|
19099
|
+
exit: (exit) => this.onExit(turn, child, exit),
|
|
19100
|
+
killed: (result) => this.deps.log.write({ event: "process_kill", pid: child.pid, agent: this.agent, ...result })
|
|
19101
|
+
});
|
|
19102
|
+
this.processes.add(child);
|
|
19103
|
+
turn.child = child;
|
|
19104
|
+
this.lastPid = child.pid;
|
|
19105
|
+
this.deps.log.write({
|
|
19106
|
+
event: "process_start",
|
|
19107
|
+
pid: child.pid,
|
|
19108
|
+
agent: this.agent,
|
|
19109
|
+
conversationUuid: this.conversationUuid,
|
|
19110
|
+
resume: this.sessionRef !== void 0
|
|
19111
|
+
});
|
|
19112
|
+
child.writeLine({ event: "user", message: { content: this.tools.preamble + text2 } });
|
|
19113
|
+
child.endInput();
|
|
19114
|
+
}
|
|
19115
|
+
stopped(turn) {
|
|
19116
|
+
return turn.interrupted || turn.done || this.closed;
|
|
19117
|
+
}
|
|
19118
|
+
async pluginList() {
|
|
19119
|
+
const run = await runToEnd(
|
|
19120
|
+
this.deps.spawnImpl,
|
|
19121
|
+
AGY,
|
|
19122
|
+
["plugin", "list", "--json"],
|
|
19123
|
+
{ cwd: this.cwd, env: this.deps.env, timeoutMs: AGENT_CALL_TIMEOUT_MS }
|
|
19124
|
+
);
|
|
19125
|
+
if (run.spawnError || run.timedOut || run.code !== 0) {
|
|
19126
|
+
return { ok: false, detail: run.spawnError ?? (run.timedOut ? "timed out" : `exit ${run.code}`) };
|
|
19127
|
+
}
|
|
19128
|
+
return { ok: true, stdout: run.stdout };
|
|
19129
|
+
}
|
|
19130
|
+
/** 결과는 한 번만 — 그 뒤 줄·exit·멈춤은 이 차례를 바꾸지 않는다. */
|
|
19131
|
+
finish(turn, outcome) {
|
|
19132
|
+
if (turn.done) return;
|
|
19133
|
+
turn.done = true;
|
|
19134
|
+
if (this.turn === turn) this.turn = void 0;
|
|
19135
|
+
turn.resolve(outcome);
|
|
19136
|
+
}
|
|
19137
|
+
finishInterrupted(turn) {
|
|
19138
|
+
this.finish(turn, { kind: "result", facts: turn.facts.snapshot(), result: { isError: true, subtype: "interrupted" } });
|
|
19139
|
+
}
|
|
19140
|
+
/** 프로세스 종료 — 소유를 놓고(로그는 그 세대 pid), 결과가 아직이면 마지막 줄까지 읽힌 뒤에 정한다(exit 이 result 줄보다 먼저 올 수 있다). */
|
|
19141
|
+
onExit(turn, child, exit) {
|
|
19142
|
+
this.processes.exited(child);
|
|
19143
|
+
this.deps.log.write({
|
|
19144
|
+
event: "process_exit",
|
|
19145
|
+
pid: child.pid,
|
|
19146
|
+
agent: this.agent,
|
|
19147
|
+
conversationUuid: this.conversationUuid,
|
|
19148
|
+
code: exit.code,
|
|
19149
|
+
signal: exit.signal
|
|
19150
|
+
});
|
|
19151
|
+
void child.waitForOutput(AGENT_STOP_WAIT_MS).then(() => {
|
|
19152
|
+
if (turn.interrupted) this.finishInterrupted(turn);
|
|
19153
|
+
else this.finish(turn, { kind: "exited", ...exit });
|
|
19154
|
+
});
|
|
19155
|
+
}
|
|
19156
|
+
onLine(turn, child, line) {
|
|
19157
|
+
if (turn.done) return;
|
|
19158
|
+
let event;
|
|
19159
|
+
try {
|
|
19160
|
+
const value = JSON.parse(line);
|
|
19161
|
+
if (!isObject3(value)) throw new Error("not an object");
|
|
19162
|
+
event = value;
|
|
19163
|
+
} catch {
|
|
19164
|
+
this.deps.log.write({ event: "bad_line", pid: child.pid, agent: this.agent, length: line.length });
|
|
19165
|
+
return;
|
|
19166
|
+
}
|
|
19167
|
+
if (event.event === "init") {
|
|
19168
|
+
if (typeof event.conversation_id === "string") this.sessionRef = event.conversation_id;
|
|
19169
|
+
return;
|
|
19170
|
+
}
|
|
19171
|
+
if (event.event === "step_update" && isObject3(event.step_update)) {
|
|
19172
|
+
this.onStep(turn, event.step_update);
|
|
19173
|
+
return;
|
|
19174
|
+
}
|
|
19175
|
+
if (event.event === "result" && isObject3(event.result)) {
|
|
19176
|
+
this.onResult(turn, child, event.result);
|
|
19177
|
+
}
|
|
19178
|
+
}
|
|
19179
|
+
/** TurnFacts(r2 좁힘): tool · DONE · call_mcp_tool · 브리지 · 공개 도구 이름 · 오류 없는 글 결과 · 같은 단계 한 번. */
|
|
19180
|
+
onStep(turn, step) {
|
|
19181
|
+
if (step.step_type !== "tool" || step.state !== "DONE" || !isObject3(step.tool_info)) return;
|
|
19182
|
+
const tool = step.tool_info;
|
|
19183
|
+
if (tool.name !== "call_mcp_tool" || !isObject3(tool.parameters)) return;
|
|
19184
|
+
const server = typeof tool.parameters.ServerName === "string" ? tool.parameters.ServerName : "";
|
|
19185
|
+
const name = typeof tool.parameters.ToolName === "string" ? tool.parameters.ToolName : "";
|
|
19186
|
+
if (server !== ANTIGRAVITY_MCP_SERVER) {
|
|
19187
|
+
turn.foreign.push({ server, tool: name });
|
|
19188
|
+
return;
|
|
19189
|
+
}
|
|
19190
|
+
if (typeof step.step_index !== "number" || turn.counted.has(step.step_index)) return;
|
|
19191
|
+
if (tool.error !== void 0 || typeof tool.output !== "string" || !this.tools.names.has(name)) return;
|
|
19192
|
+
turn.counted.add(step.step_index);
|
|
19193
|
+
turn.facts.add(agyContentParts(tool.output), this.deps.writeTools.has(name));
|
|
19194
|
+
}
|
|
19195
|
+
onResult(turn, child, result) {
|
|
19196
|
+
if (typeof result.conversation_id === "string") this.sessionRef = result.conversation_id;
|
|
19197
|
+
const usage2 = isObject3(result.usage) ? result.usage : void 0;
|
|
19198
|
+
this.deps.log.write({
|
|
19199
|
+
event: "agent_usage",
|
|
19200
|
+
pid: child.pid,
|
|
19201
|
+
agent: this.agent,
|
|
19202
|
+
conversationUuid: this.conversationUuid,
|
|
19203
|
+
...typeof usage2?.input_tokens === "number" ? { inputTokens: usage2.input_tokens } : {},
|
|
19204
|
+
...typeof usage2?.output_tokens === "number" ? { outputTokens: usage2.output_tokens } : {}
|
|
19205
|
+
});
|
|
19206
|
+
if (turn.interrupted) return this.finishInterrupted(turn);
|
|
19207
|
+
const facts = turn.facts.snapshot();
|
|
19208
|
+
if (turn.foreign.length > 0) {
|
|
19209
|
+
for (const { server, tool } of turn.foreign) {
|
|
19210
|
+
this.deps.log.write({
|
|
19211
|
+
event: "agent_policy_violation",
|
|
19212
|
+
pid: child.pid,
|
|
19213
|
+
agent: this.agent,
|
|
19214
|
+
conversationUuid: this.conversationUuid,
|
|
19215
|
+
server,
|
|
19216
|
+
tool
|
|
19217
|
+
});
|
|
19218
|
+
}
|
|
19219
|
+
this.finish(turn, { kind: "result", facts, result: { isError: true, subtype: "policy_violation" } });
|
|
19220
|
+
return;
|
|
19221
|
+
}
|
|
19222
|
+
const status = typeof result.status === "string" ? result.status : void 0;
|
|
19223
|
+
this.finish(turn, {
|
|
19224
|
+
kind: "result",
|
|
19225
|
+
facts,
|
|
19226
|
+
result: {
|
|
19227
|
+
subtype: status,
|
|
19228
|
+
isError: status !== "SUCCESS",
|
|
19229
|
+
structuredOutput: result.structured_output,
|
|
19230
|
+
resultText: typeof result.response === "string" ? result.response : void 0,
|
|
19231
|
+
numTurns: typeof result.num_turns === "number" ? result.num_turns : void 0
|
|
19232
|
+
}
|
|
19233
|
+
});
|
|
19234
|
+
}
|
|
19235
|
+
};
|
|
19236
|
+
function agyContentParts(output) {
|
|
19237
|
+
try {
|
|
19238
|
+
JSON.parse(output);
|
|
19239
|
+
return [{ type: "text", text: output }];
|
|
19240
|
+
} catch {
|
|
19241
|
+
return output.split("\n").map((text2) => ({ type: "text", text: text2 }));
|
|
19242
|
+
}
|
|
19243
|
+
}
|
|
19244
|
+
function isObject3(value) {
|
|
19245
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
19246
|
+
}
|
|
19247
|
+
|
|
19248
|
+
// src/core/agent/claudeArgs.ts
|
|
19249
|
+
function claudeMcpConfig(bridge) {
|
|
19250
|
+
return { mcpServers: { [AINECTO_MCP_SERVER]: { command: bridge.command, args: bridge.args } } };
|
|
19251
|
+
}
|
|
19252
|
+
function claudeAgentArgs(input) {
|
|
19253
|
+
const args = [
|
|
19254
|
+
"-p",
|
|
19255
|
+
"--input-format",
|
|
19256
|
+
"stream-json",
|
|
19257
|
+
"--output-format",
|
|
19258
|
+
"stream-json",
|
|
19259
|
+
"--verbose",
|
|
19260
|
+
"--json-schema",
|
|
19261
|
+
JSON.stringify(input.schema),
|
|
19262
|
+
"--tools",
|
|
19263
|
+
"",
|
|
19264
|
+
// 내장 도구(Bash·Read·Write·Edit·Agent·Skill·WebFetch…) 전부 끔
|
|
19265
|
+
"--strict-mcp-config",
|
|
19266
|
+
"--mcp-config",
|
|
19267
|
+
JSON.stringify(input.mcpConfig),
|
|
19268
|
+
"--allowedTools",
|
|
19269
|
+
`mcp__${AINECTO_MCP_SERVER}`,
|
|
19270
|
+
"--permission-mode",
|
|
19271
|
+
"dontAsk",
|
|
19272
|
+
// 허용 밖은 묻지 않고 바로 거절(헤드리스에서 묻기 = 2분 대기)
|
|
19273
|
+
"--setting-sources",
|
|
19274
|
+
""
|
|
19275
|
+
// 사용자·프로젝트 설정(플러그인·스킬·훅·권한) 끔
|
|
19276
|
+
];
|
|
19277
|
+
if (input.resumeSessionId) {
|
|
19278
|
+
args.push("--resume", input.resumeSessionId);
|
|
19279
|
+
}
|
|
19280
|
+
return args;
|
|
19281
|
+
}
|
|
19282
|
+
var AINECTO_TOOL_PREFIX = `mcp__${AINECTO_MCP_SERVER}__`;
|
|
19283
|
+
|
|
18584
19284
|
// src/core/agent/claudeCode.ts
|
|
18585
19285
|
var CLAUDE = "claude";
|
|
18586
19286
|
function claudeCodeAdapter(deps) {
|
|
@@ -19126,7 +19826,7 @@ function toError(error) {
|
|
|
19126
19826
|
}
|
|
19127
19827
|
|
|
19128
19828
|
// src/core/agent/runs.ts
|
|
19129
|
-
import { readFile as
|
|
19829
|
+
import { readFile as readFile17, rename as rename8, writeFile as writeFile9 } from "fs/promises";
|
|
19130
19830
|
var AgentRunLog = class {
|
|
19131
19831
|
constructor(path, log) {
|
|
19132
19832
|
this.path = path;
|
|
@@ -19140,7 +19840,7 @@ var AgentRunLog = class {
|
|
|
19140
19840
|
let reason;
|
|
19141
19841
|
const runs = /* @__PURE__ */ new Map();
|
|
19142
19842
|
try {
|
|
19143
|
-
const parsed = JSON.parse(await
|
|
19843
|
+
const parsed = JSON.parse(await readFile17(this.path, "utf8"));
|
|
19144
19844
|
for (const value of Array.isArray(parsed.runs) ? parsed.runs : []) {
|
|
19145
19845
|
const e = value ?? {};
|
|
19146
19846
|
if (typeof e.cardUuid === "string" && typeof e.startedAt === "string") {
|
|
@@ -19178,9 +19878,9 @@ var AgentRunLog = class {
|
|
|
19178
19878
|
}
|
|
19179
19879
|
async save() {
|
|
19180
19880
|
const tmp = `${this.path}.tmp`;
|
|
19181
|
-
await
|
|
19881
|
+
await writeFile9(tmp, `${JSON.stringify({ version: 1, runs: [...this.runs.values()] }, null, 2)}
|
|
19182
19882
|
`, { mode: PRIVATE_FILE_MODE });
|
|
19183
|
-
await
|
|
19883
|
+
await rename8(tmp, this.path);
|
|
19184
19884
|
}
|
|
19185
19885
|
};
|
|
19186
19886
|
|
|
@@ -19241,7 +19941,7 @@ async function probe(log, agent, kind, work, summary2) {
|
|
|
19241
19941
|
}
|
|
19242
19942
|
|
|
19243
19943
|
// src/core/agent/sessions.ts
|
|
19244
|
-
import { readFile as
|
|
19944
|
+
import { readFile as readFile18, rename as rename9, writeFile as writeFile10 } from "fs/promises";
|
|
19245
19945
|
var AgentSessionMap = class {
|
|
19246
19946
|
constructor(path) {
|
|
19247
19947
|
this.path = path;
|
|
@@ -19250,7 +19950,7 @@ var AgentSessionMap = class {
|
|
|
19250
19950
|
map = emptyMap();
|
|
19251
19951
|
async load() {
|
|
19252
19952
|
try {
|
|
19253
|
-
const parsed = JSON.parse(await
|
|
19953
|
+
const parsed = JSON.parse(await readFile18(this.path, "utf8"));
|
|
19254
19954
|
const map = emptyMap();
|
|
19255
19955
|
map[DEFAULT_AGENT] = entries(parsed.conversations);
|
|
19256
19956
|
const byAgent = parsed.byAgent && typeof parsed.byAgent === "object" ? parsed.byAgent : {};
|
|
@@ -19277,13 +19977,13 @@ var AgentSessionMap = class {
|
|
|
19277
19977
|
async save() {
|
|
19278
19978
|
const byAgent = Object.fromEntries(AGENT_IDS.filter((id) => id !== DEFAULT_AGENT).map((id) => [id, this.map[id]]));
|
|
19279
19979
|
const tmp = `${this.path}.tmp`;
|
|
19280
|
-
await
|
|
19980
|
+
await writeFile10(
|
|
19281
19981
|
tmp,
|
|
19282
19982
|
`${JSON.stringify({ version: 2, conversations: this.map[DEFAULT_AGENT], byAgent }, null, 2)}
|
|
19283
19983
|
`,
|
|
19284
19984
|
{ mode: PRIVATE_FILE_MODE }
|
|
19285
19985
|
);
|
|
19286
|
-
await
|
|
19986
|
+
await rename9(tmp, this.path);
|
|
19287
19987
|
}
|
|
19288
19988
|
};
|
|
19289
19989
|
function emptyMap() {
|
|
@@ -19428,7 +20128,7 @@ var AGENT_HELP_LINES = [
|
|
|
19428
20128
|
function isPcRunCommand(domain, action) {
|
|
19429
20129
|
return domain === "pc" && action === "run";
|
|
19430
20130
|
}
|
|
19431
|
-
var BILLED_TO = { "claude-code": "Anthropic", codex: "OpenAI" };
|
|
20131
|
+
var BILLED_TO = { "claude-code": "Anthropic", codex: "OpenAI", antigravity: "Google" };
|
|
19432
20132
|
async function executeAgentServe(input) {
|
|
19433
20133
|
const paths = agentPaths();
|
|
19434
20134
|
await ensurePrivateDir(paths.dir);
|
|
@@ -19445,14 +20145,30 @@ async function executeAgentServe(input) {
|
|
|
19445
20145
|
},
|
|
19446
20146
|
log
|
|
19447
20147
|
});
|
|
19448
|
-
const
|
|
20148
|
+
const serverTools = await tools.list();
|
|
20149
|
+
const writeTools = writeToolNames(serverTools);
|
|
19449
20150
|
const cliScript = process.argv[1];
|
|
19450
20151
|
if (!cliScript) throw new Error("Cannot find the path of this CLI to start the AiNecto bridge for the agents.");
|
|
19451
20152
|
const bridge = (agentName) => ainectoBridge(process.execPath, cliScript, input.endpoint, agentName);
|
|
19452
20153
|
const shared = { spawnImpl: spawnAgent, cwd: paths.work, env: agentEnv(process.env), log, writeTools };
|
|
19453
20154
|
const all = [
|
|
19454
20155
|
claudeCodeAdapter({ ...shared, args: ({ textMaxCharacters, documentsMax, resumeSessionId, agentName }) => claudeAgentArgs({ schema: agentReplySchema(textMaxCharacters, documentsMax), mcpConfig: claudeMcpConfig(bridge(agentName)), resumeSessionId }) }),
|
|
19455
|
-
codexAdapter({ ...shared, appServerArgs: (agentName) => codexAppServerArgs(bridge(agentName), writeTools), clientVersion: CLI_VERSION })
|
|
20156
|
+
codexAdapter({ ...shared, appServerArgs: (agentName) => codexAppServerArgs(bridge(agentName), writeTools), clientVersion: CLI_VERSION }),
|
|
20157
|
+
antigravityAdapter({
|
|
20158
|
+
spawnImpl: spawnAgent,
|
|
20159
|
+
env: shared.env,
|
|
20160
|
+
home: homedir6(),
|
|
20161
|
+
log,
|
|
20162
|
+
writeTools,
|
|
20163
|
+
tools: serverTools,
|
|
20164
|
+
// 연결 이름마다 한 폴더 — 이름 글자를 폴더 이름에 쓰지 않는다(해시).
|
|
20165
|
+
workDir: (agentName) => join13(
|
|
20166
|
+
paths.antigravity,
|
|
20167
|
+
agentName ? `agent-${createHash8("sha256").update(agentName).digest("hex").slice(0, 16)}` : "chat"
|
|
20168
|
+
),
|
|
20169
|
+
mcpConfig: (agentName) => antigravityMcpConfig(bridge(agentName)),
|
|
20170
|
+
schema: agentReplySchema
|
|
20171
|
+
})
|
|
19456
20172
|
];
|
|
19457
20173
|
const checks = await checkAgents(all, log);
|
|
19458
20174
|
log.write({
|
|
@@ -19467,7 +20183,7 @@ async function executeAgentServe(input) {
|
|
|
19467
20183
|
const remote = await pcRemoteSetup({ endpoint: input.endpoint, auth: input.auth, account: () => readAccount(client()), io: input.io });
|
|
19468
20184
|
const plan = pcPlan({ agents: agents.length, remoteEnabled: remote.remoteEnabled });
|
|
19469
20185
|
if (plan === "nothing") {
|
|
19470
|
-
throw new Error("
|
|
20186
|
+
throw new Error("None of Claude Code (`claude`), Codex (`codex`) or Antigravity (`agy`) is on PATH, and terminals from the web are off on this PC. Install one and sign in, or allow terminals from the web with `ainecto remote on`, then run `ainecto` again.");
|
|
19471
20187
|
}
|
|
19472
20188
|
let agentBusy = () => false;
|
|
19473
20189
|
const upgrades = upgradeWatch({
|
|
@@ -19532,7 +20248,7 @@ async function executeAgentServe(input) {
|
|
|
19532
20248
|
}
|
|
19533
20249
|
|
|
19534
20250
|
// src/adapters/cli/ainectoCli.ts
|
|
19535
|
-
import { homedir as
|
|
20251
|
+
import { homedir as homedir7, hostname as hostname4, tmpdir } from "os";
|
|
19536
20252
|
async function runAinectoCli(argv, io) {
|
|
19537
20253
|
let parsed = { json: argv.includes("--json"), help: false, version: false, positionals: [] };
|
|
19538
20254
|
try {
|
|
@@ -19621,8 +20337,8 @@ async function runAinectoCli(argv, io) {
|
|
|
19621
20337
|
auth,
|
|
19622
20338
|
client: client2,
|
|
19623
20339
|
// ★외부 CLI 는 홈 폴더에서 돈다 — 지금 저장소의 local·project 범위 항목이 사용자 범위 판정에 끼지 않게.
|
|
19624
|
-
runner: systemCommandRunner({ cwd:
|
|
19625
|
-
home:
|
|
20340
|
+
runner: systemCommandRunner({ cwd: homedir7() }),
|
|
20341
|
+
home: homedir7(),
|
|
19626
20342
|
json: parsed.json,
|
|
19627
20343
|
io
|
|
19628
20344
|
});
|
|
@@ -19636,9 +20352,9 @@ async function runAinectoCli(argv, io) {
|
|
|
19636
20352
|
tokenStore,
|
|
19637
20353
|
auth,
|
|
19638
20354
|
client: client2,
|
|
19639
|
-
runner: systemCommandRunner({ cwd:
|
|
20355
|
+
runner: systemCommandRunner({ cwd: homedir7() }),
|
|
19640
20356
|
hereRunner: systemCommandRunner({ cwd: process.cwd() }),
|
|
19641
|
-
home:
|
|
20357
|
+
home: homedir7(),
|
|
19642
20358
|
cwd: process.cwd(),
|
|
19643
20359
|
envVars: process.env
|
|
19644
20360
|
};
|
|
@@ -19766,9 +20482,9 @@ async function runAinectoCli(argv, io) {
|
|
|
19766
20482
|
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
19767
20483
|
return await response.json();
|
|
19768
20484
|
},
|
|
19769
|
-
makeTempDir: () => mkdtemp(
|
|
20485
|
+
makeTempDir: () => mkdtemp(join14(tmpdir(), "ainecto-upgrade-")),
|
|
19770
20486
|
removeDir: (path) => rm3(path, { recursive: true, force: true }),
|
|
19771
|
-
home:
|
|
20487
|
+
home: homedir7(),
|
|
19772
20488
|
log: openAgentLog(swapPaths)
|
|
19773
20489
|
});
|
|
19774
20490
|
}
|
|
@@ -19992,7 +20708,7 @@ function helpText() {
|
|
|
19992
20708
|
" ainecto init --agent NAME name the agent working in this folder: writes .ainecto/agent.local (do not commit it) and puts the name in .mcp.json, .cursor/mcp.json, .agents/mcp_config.json and .codex/config.toml",
|
|
19993
20709
|
" ainecto init --undo",
|
|
19994
20710
|
"",
|
|
19995
|
-
"This PC (requests from AiNecto Chat and auto-run cards, answered by Claude Code or
|
|
20711
|
+
"This PC (requests from AiNecto Chat and auto-run cards, answered by Claude Code, Codex or Antigravity on this machine):",
|
|
19996
20712
|
...AGENT_HELP_LINES,
|
|
19997
20713
|
"",
|
|
19998
20714
|
"Terminal sessions on this machine (no tmux or cmux needed; macOS, Linux and Windows):",
|