ainecto 0.16.1 → 0.16.2
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 -3
- package/dist/bin/ainecto.js +620 -79
- 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.2" : UNBUNDLED_VERSION;
|
|
5703
|
+
var CLI_BUILD = true ? "3033982" : void 0;
|
|
5704
5704
|
function cliVersionLabel(version, build, release2) {
|
|
5705
5705
|
return release2 || build === void 0 ? version : `${version}-dev+${build}`;
|
|
5706
5706
|
}
|
|
@@ -13522,8 +13522,12 @@ function sleep(ms, signal) {
|
|
|
13522
13522
|
}
|
|
13523
13523
|
|
|
13524
13524
|
// src/core/agent/agents.ts
|
|
13525
|
-
var AGENT_IDS = ["claude-code", "codex"];
|
|
13526
|
-
var AGENT_MCP_CLIENT_NAMES = {
|
|
13525
|
+
var AGENT_IDS = ["claude-code", "codex", "antigravity"];
|
|
13526
|
+
var AGENT_MCP_CLIENT_NAMES = {
|
|
13527
|
+
"claude-code": "claude-code",
|
|
13528
|
+
codex: "codex-mcp-client",
|
|
13529
|
+
antigravity: "antigravity-client"
|
|
13530
|
+
};
|
|
13527
13531
|
var DEFAULT_AGENT = "claude-code";
|
|
13528
13532
|
function isAgentId(value) {
|
|
13529
13533
|
return typeof value === "string" && AGENT_IDS.includes(value);
|
|
@@ -13715,6 +13719,8 @@ function replyForOutcome(outcome, limits, agentName) {
|
|
|
13715
13719
|
case "exited":
|
|
13716
13720
|
return failed("AGENT_EXITED", `${agentName} \uAC00 \uB05D\uB0AC\uC5B4\uC694(code ${outcome.code ?? "-"}${outcome.signal ? `, ${outcome.signal}` : ""}).` + (outcome.stderrTail ? `
|
|
13717
13721
|
${outcome.stderrTail}` : ""));
|
|
13722
|
+
case "refused":
|
|
13723
|
+
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
13724
|
case "result": {
|
|
13719
13725
|
const { result } = outcome;
|
|
13720
13726
|
if (result.isError) {
|
|
@@ -14216,7 +14222,7 @@ var TODO_NOTES = {
|
|
|
14216
14222
|
stopped: "Stopped."
|
|
14217
14223
|
};
|
|
14218
14224
|
var SERVE_CONNECTED_PREFIX = "Connected to AiNecto as ";
|
|
14219
|
-
var AGENT_MISSING_LINE = "Agent: no
|
|
14225
|
+
var AGENT_MISSING_LINE = "Agent: no supported agent CLI on this PC \u2014 install one, then `ainecto` again.";
|
|
14220
14226
|
var SERVE_RECONNECTED_LINE = "AiNecto lost this connection (it may have restarted); connected again.";
|
|
14221
14227
|
async function runAgentServe(deps) {
|
|
14222
14228
|
const folderName = deps.todos?.agentName;
|
|
@@ -14419,10 +14425,10 @@ async function runAgentServe(deps) {
|
|
|
14419
14425
|
await session.interrupt();
|
|
14420
14426
|
await session.close();
|
|
14421
14427
|
}
|
|
14422
|
-
if (outcome.kind
|
|
14428
|
+
if (outcome.kind === "timeout" || outcome.kind === "exited") {
|
|
14423
14429
|
if (live.get(adapter.id) === session) live.delete(adapter.id);
|
|
14424
14430
|
if (session.resumed) await deps.sessions.forget(offer.conversationUuid, adapter.id);
|
|
14425
|
-
} else if (session.sessionRef) {
|
|
14431
|
+
} else if (outcome.kind === "result" && session.sessionRef) {
|
|
14426
14432
|
await deps.sessions.set(offer.conversationUuid, adapter.id, session.sessionRef);
|
|
14427
14433
|
}
|
|
14428
14434
|
reply = stopping.has(offer.key) ? stoppedReply(outcome, limits) : replyForOutcome(outcome, limits, adapter.displayName);
|
|
@@ -14619,15 +14625,19 @@ function serverLimits(value) {
|
|
|
14619
14625
|
};
|
|
14620
14626
|
return { pollHoldSeconds: num("pollHoldSeconds"), textMaxCharacters: num("textMaxCharacters"), documentsMax: num("documentsMax") };
|
|
14621
14627
|
}
|
|
14622
|
-
async function openLink(deps,
|
|
14628
|
+
async function openLink(deps, allAgents) {
|
|
14623
14629
|
const base = { hostName: deps.hostName, cliVersion: deps.cliVersion };
|
|
14630
|
+
const agents = allAgents.filter((a) => !NEWER_AGENT_IDS.includes(a.id));
|
|
14631
|
+
const newer = agents.length < allAgents.length;
|
|
14624
14632
|
const named = agents.some((a) => a.name !== void 0);
|
|
14625
14633
|
const unnamed = agents.map(({ name: _name, ...rest }) => rest);
|
|
14626
14634
|
const features = pcFeatures(deps.todos !== void 0);
|
|
14627
14635
|
const older = features.filter((f) => f !== "todos");
|
|
14636
|
+
const build = deps.cliBuild ? { cliBuild: deps.cliBuild } : {};
|
|
14628
14637
|
const attempts = [
|
|
14629
|
-
...
|
|
14630
|
-
{ body: { ...base, agents, features }, ...
|
|
14638
|
+
...newer ? [{ body: { ...base, ...build, agents: allAgents, features } }] : [],
|
|
14639
|
+
...deps.cliBuild ? [{ body: { ...base, cliBuild: deps.cliBuild, agents, features }, ...newer ? { dropped: "agents.newer" } : {} }] : [],
|
|
14640
|
+
{ body: { ...base, agents, features }, ...deps.cliBuild ? { dropped: "cliBuild" } : newer ? { dropped: "agents.newer" } : {} },
|
|
14631
14641
|
...older.length < features.length ? [{ body: { ...base, agents, features: older }, dropped: "features.todos" }] : [],
|
|
14632
14642
|
...named ? [{ body: { ...base, agents: unnamed, features: older }, dropped: "agents.name" }] : [],
|
|
14633
14643
|
{ body: { ...base, agents: unnamed }, dropped: "features" }
|
|
@@ -14643,6 +14653,7 @@ async function openLink(deps, agents) {
|
|
|
14643
14653
|
}
|
|
14644
14654
|
}
|
|
14645
14655
|
}
|
|
14656
|
+
var NEWER_AGENT_IDS = ["antigravity"];
|
|
14646
14657
|
function folderKind(agents) {
|
|
14647
14658
|
return agents.find((a) => a.ready && a.id === DEFAULT_AGENT)?.id ?? agents.find((a) => a.ready)?.id;
|
|
14648
14659
|
}
|
|
@@ -17464,7 +17475,7 @@ function pcResultText(result) {
|
|
|
17464
17475
|
if (result.kind === "already") {
|
|
17465
17476
|
return `This PC is already connected to AiNecto (folder ${result.folder}, version ${result.version}). ${STOP} Log: ${result.log}`;
|
|
17466
17477
|
}
|
|
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
|
|
17478
|
+
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
17479
|
return `This PC is now connected to AiNecto. ${use} It keeps running after you close this window. ${STOP} Log: ${result.log}`;
|
|
17469
17480
|
}
|
|
17470
17481
|
function pcNotApprovedText(hostName, then) {
|
|
@@ -17513,7 +17524,7 @@ async function executePcStart(deps) {
|
|
|
17513
17524
|
}
|
|
17514
17525
|
note("");
|
|
17515
17526
|
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).");
|
|
17527
|
+
note(" \xB7 Your AiNecto agent will run work on this PC (Claude Code / Codex / Antigravity).");
|
|
17517
17528
|
note(" \xB7 From AiNecto on the web, you can open terminals on this PC and run commands in them.");
|
|
17518
17529
|
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
17530
|
if (!yes(await promptLine(deps.io, "Connect this PC? [y/N]: "), false)) {
|
|
@@ -18250,7 +18261,7 @@ function swapArgsOf(argv) {
|
|
|
18250
18261
|
|
|
18251
18262
|
// src/adapters/cli/ainectoCli.ts
|
|
18252
18263
|
import { mkdtemp, rm as rm3 } from "fs/promises";
|
|
18253
|
-
import { join as
|
|
18264
|
+
import { join as join14 } from "path";
|
|
18254
18265
|
|
|
18255
18266
|
// src/adapters/cli/pcStatus.ts
|
|
18256
18267
|
import { readFile as readFile14 } from "fs/promises";
|
|
@@ -18264,6 +18275,7 @@ function agentPaths(home = homedir5()) {
|
|
|
18264
18275
|
return {
|
|
18265
18276
|
dir,
|
|
18266
18277
|
work: join10(dir, "work"),
|
|
18278
|
+
antigravity: join10(dir, "antigravity"),
|
|
18267
18279
|
sessions: join10(dir, "sessions.json"),
|
|
18268
18280
|
runs: join10(dir, "runs.json"),
|
|
18269
18281
|
log: join10(dir, "agent.log"),
|
|
@@ -18296,7 +18308,176 @@ async function pcStatus(status, endpoint) {
|
|
|
18296
18308
|
}
|
|
18297
18309
|
|
|
18298
18310
|
// src/adapters/cli/agentCommand.ts
|
|
18299
|
-
import {
|
|
18311
|
+
import { createHash as createHash8 } from "crypto";
|
|
18312
|
+
import { homedir as homedir6, hostname as hostname3 } from "os";
|
|
18313
|
+
import { join as join13 } from "path";
|
|
18314
|
+
|
|
18315
|
+
// src/core/agent/antigravity.ts
|
|
18316
|
+
import { mkdir as mkdir7, readFile as readFile16 } from "fs/promises";
|
|
18317
|
+
import { join as join12 } from "path";
|
|
18318
|
+
|
|
18319
|
+
// src/core/agent/antigravityArgs.ts
|
|
18320
|
+
var AGY = "agy";
|
|
18321
|
+
var VERIFIED_AGY_VERSION = "1.5.15";
|
|
18322
|
+
var ANTIGRAVITY_MCP_SERVER = "ainecto-pc";
|
|
18323
|
+
var AGY_CUSTOMIZATION_DIRS = [".agents", ".agent", "_agents", "_agent"];
|
|
18324
|
+
var BUILTIN_DENY = ["command(*)", "write_file(*)", "read_file(*)", "read_url(*)", "execute_url(*)"];
|
|
18325
|
+
function antigravityToolPreamble(tools) {
|
|
18326
|
+
const definitions = tools.map(({ name, description, inputSchema }) => ({ name, description, inputSchema }));
|
|
18327
|
+
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)]
|
|
18328
|
+
${JSON.stringify(definitions)}
|
|
18329
|
+
|
|
18330
|
+
`;
|
|
18331
|
+
}
|
|
18332
|
+
function antigravityMcpConfig(bridge) {
|
|
18333
|
+
return { mcpServers: { [ANTIGRAVITY_MCP_SERVER]: { command: bridge.command, args: bridge.args } } };
|
|
18334
|
+
}
|
|
18335
|
+
function antigravitySettings(denyServers) {
|
|
18336
|
+
return {
|
|
18337
|
+
toolPermission: "request-review",
|
|
18338
|
+
permissions: {
|
|
18339
|
+
allow: [`mcp(${ANTIGRAVITY_MCP_SERVER}/*)`],
|
|
18340
|
+
deny: [...BUILTIN_DENY, ...denyServers.map((name) => `mcp(${name}/*)`)]
|
|
18341
|
+
}
|
|
18342
|
+
};
|
|
18343
|
+
}
|
|
18344
|
+
function antigravityAgentArgs(input) {
|
|
18345
|
+
const args = [
|
|
18346
|
+
// ★`-p` 는 값을 받는다 — 비우지 않으면 다음 인자를 프롬프트로 먹는다(실측 1.5.14 끝 코드 2). 프롬프트는 stdin(stream-json) 한 줄이라 빈 글.
|
|
18347
|
+
"-p",
|
|
18348
|
+
"",
|
|
18349
|
+
"--input-format",
|
|
18350
|
+
"stream-json",
|
|
18351
|
+
"--output-format",
|
|
18352
|
+
"stream-json",
|
|
18353
|
+
"--json-schema",
|
|
18354
|
+
JSON.stringify(input.schema),
|
|
18355
|
+
"--settings",
|
|
18356
|
+
JSON.stringify(input.settings)
|
|
18357
|
+
];
|
|
18358
|
+
if (input.conversationId) {
|
|
18359
|
+
args.push("--conversation", input.conversationId);
|
|
18360
|
+
}
|
|
18361
|
+
return args;
|
|
18362
|
+
}
|
|
18363
|
+
|
|
18364
|
+
// src/core/agent/antigravityPolicy.ts
|
|
18365
|
+
import { existsSync as existsSync2 } from "fs";
|
|
18366
|
+
import { mkdir as mkdir6, readdir as readdir2, readFile as readFile15, rename as rename7, writeFile as writeFile8 } from "fs/promises";
|
|
18367
|
+
import { dirname as dirname8, join as join11, parse as parsePath } from "path";
|
|
18368
|
+
var SAFE_SERVER_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
18369
|
+
var Refuse = class extends Error {
|
|
18370
|
+
constructor(reason, path) {
|
|
18371
|
+
super(reason);
|
|
18372
|
+
this.reason = reason;
|
|
18373
|
+
this.path = path;
|
|
18374
|
+
}
|
|
18375
|
+
reason;
|
|
18376
|
+
path;
|
|
18377
|
+
};
|
|
18378
|
+
async function antigravityMcpPolicy(input) {
|
|
18379
|
+
try {
|
|
18380
|
+
const names = /* @__PURE__ */ new Set();
|
|
18381
|
+
const add = (found, path) => {
|
|
18382
|
+
for (const name of found) {
|
|
18383
|
+
if (!SAFE_SERVER_NAME.test(name)) throw new Refuse("server name the deny rule cannot carry", path);
|
|
18384
|
+
if (name === ANTIGRAVITY_MCP_SERVER) throw new Refuse(`another config also names ${ANTIGRAVITY_MCP_SERVER}`, path);
|
|
18385
|
+
names.add(name);
|
|
18386
|
+
}
|
|
18387
|
+
};
|
|
18388
|
+
for (const dir of selfAndAncestors(input.cwd)) {
|
|
18389
|
+
if (existsSync2(join11(dir, ".git"))) throw new Refuse("work folder is inside a git repository", join11(dir, ".git"));
|
|
18390
|
+
}
|
|
18391
|
+
await onlyEntry(input.cwd, ".agents");
|
|
18392
|
+
const ours = join11(input.cwd, ".agents");
|
|
18393
|
+
await onlyEntry(ours, "mcp_config.json");
|
|
18394
|
+
const ourNames = await serverNames(join11(ours, "mcp_config.json"));
|
|
18395
|
+
if (ourNames.length !== 1 || ourNames[0] !== ANTIGRAVITY_MCP_SERVER) {
|
|
18396
|
+
throw new Refuse("work folder config is not ours", join11(ours, "mcp_config.json"));
|
|
18397
|
+
}
|
|
18398
|
+
for (const dir of selfAndAncestors(dirname8(input.cwd))) {
|
|
18399
|
+
for (const folder of AGY_CUSTOMIZATION_DIRS) {
|
|
18400
|
+
const file = join11(dir, folder, "mcp_config.json");
|
|
18401
|
+
if (existsSync2(file)) add(await serverNames(file), file);
|
|
18402
|
+
}
|
|
18403
|
+
}
|
|
18404
|
+
const globalRoot = join11(input.home, ".gemini", "config");
|
|
18405
|
+
const globalPlugins = join11(globalRoot, "plugins.json");
|
|
18406
|
+
if (existsSync2(globalPlugins)) throw new Refuse("global plugins.json adds plugins that agy plugin list does not show", globalPlugins);
|
|
18407
|
+
const globalFile = join11(globalRoot, "mcp_config.json");
|
|
18408
|
+
if (existsSync2(globalFile)) add(await serverNames(globalFile), globalFile);
|
|
18409
|
+
const listed3 = await input.pluginList();
|
|
18410
|
+
if (!listed3.ok) throw new Refuse(`agy plugin list failed: ${listed3.detail}`);
|
|
18411
|
+
for (const plugin of pluginEntries(listed3.stdout)) {
|
|
18412
|
+
add(plugin.mcpServers, plugin.path);
|
|
18413
|
+
const file = join11(plugin.path, "mcp_config.json");
|
|
18414
|
+
if (existsSync2(file)) add(await serverNames(file), file);
|
|
18415
|
+
}
|
|
18416
|
+
return { ok: true, deny: [...names].sort() };
|
|
18417
|
+
} catch (error) {
|
|
18418
|
+
if (error instanceof Refuse) return { ok: false, reason: error.reason, ...error.path ? { path: error.path } : {} };
|
|
18419
|
+
return { ok: false, reason: `could not read the Antigravity settings: ${error instanceof Error ? error.message : String(error)}` };
|
|
18420
|
+
}
|
|
18421
|
+
}
|
|
18422
|
+
async function writeWorkspaceMcpConfig(cwd, config) {
|
|
18423
|
+
const target = join11(cwd, ".agents", "mcp_config.json");
|
|
18424
|
+
await mkdir6(dirname8(target), { recursive: true, mode: 448 });
|
|
18425
|
+
const temp = join11(dirname8(cwd), `.${parsePath(cwd).base}.mcp_config.${process.pid}.tmp`);
|
|
18426
|
+
await writeFile8(temp, `${JSON.stringify(config)}
|
|
18427
|
+
`, { mode: 384 });
|
|
18428
|
+
await rename7(temp, target);
|
|
18429
|
+
}
|
|
18430
|
+
function selfAndAncestors(start) {
|
|
18431
|
+
const out = [];
|
|
18432
|
+
let dir = start;
|
|
18433
|
+
for (; ; ) {
|
|
18434
|
+
out.push(dir);
|
|
18435
|
+
const parent = dirname8(dir);
|
|
18436
|
+
if (parent === dir) return out;
|
|
18437
|
+
dir = parent;
|
|
18438
|
+
}
|
|
18439
|
+
}
|
|
18440
|
+
async function onlyEntry(dir, expected) {
|
|
18441
|
+
const entries2 = await readdir2(dir);
|
|
18442
|
+
const others = entries2.filter((name) => name !== expected);
|
|
18443
|
+
if (others.length > 0 || !entries2.includes(expected)) {
|
|
18444
|
+
throw new Refuse("work folder holds something other than our config", join11(dir, others[0] ?? expected));
|
|
18445
|
+
}
|
|
18446
|
+
}
|
|
18447
|
+
async function serverNames(file) {
|
|
18448
|
+
const text2 = await readFile15(file, "utf8");
|
|
18449
|
+
if (text2.trim() === "") return [];
|
|
18450
|
+
let value;
|
|
18451
|
+
try {
|
|
18452
|
+
value = JSON.parse(text2);
|
|
18453
|
+
} catch {
|
|
18454
|
+
throw new Refuse("unreadable mcp_config.json", file);
|
|
18455
|
+
}
|
|
18456
|
+
if (!isObject2(value)) throw new Refuse("unknown mcp_config.json shape", file);
|
|
18457
|
+
if (value.mcpServers === void 0) return [];
|
|
18458
|
+
if (!isObject2(value.mcpServers)) throw new Refuse("unknown mcp_config.json shape", file);
|
|
18459
|
+
return Object.keys(value.mcpServers);
|
|
18460
|
+
}
|
|
18461
|
+
function pluginEntries(stdout) {
|
|
18462
|
+
let value;
|
|
18463
|
+
try {
|
|
18464
|
+
value = JSON.parse(stdout);
|
|
18465
|
+
} catch {
|
|
18466
|
+
throw new Refuse("unreadable agy plugin list");
|
|
18467
|
+
}
|
|
18468
|
+
if (!Array.isArray(value)) throw new Refuse("unknown agy plugin list shape");
|
|
18469
|
+
return value.map((item) => {
|
|
18470
|
+
if (!isObject2(item) || typeof item.path !== "string") throw new Refuse("unknown agy plugin list shape");
|
|
18471
|
+
const servers = item.mcpServers ?? [];
|
|
18472
|
+
if (!Array.isArray(servers) || !servers.every((name) => typeof name === "string")) {
|
|
18473
|
+
throw new Refuse("unknown agy plugin list shape", item.path);
|
|
18474
|
+
}
|
|
18475
|
+
return { path: item.path, mcpServers: servers };
|
|
18476
|
+
});
|
|
18477
|
+
}
|
|
18478
|
+
function isObject2(value) {
|
|
18479
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18480
|
+
}
|
|
18300
18481
|
|
|
18301
18482
|
// src/core/agent/child.ts
|
|
18302
18483
|
import { createInterface as createInterface3 } from "readline";
|
|
@@ -18308,6 +18489,7 @@ var AgentChild = class {
|
|
|
18308
18489
|
stderr = "";
|
|
18309
18490
|
exitInfo;
|
|
18310
18491
|
exited;
|
|
18492
|
+
outputDone;
|
|
18311
18493
|
onKilled;
|
|
18312
18494
|
constructor(spawnImpl, command, args, options, hooks) {
|
|
18313
18495
|
this.onKilled = hooks.killed;
|
|
@@ -18325,14 +18507,16 @@ var AgentChild = class {
|
|
|
18325
18507
|
};
|
|
18326
18508
|
this.child.on("exit", done);
|
|
18327
18509
|
this.child.on("error", (error) => {
|
|
18328
|
-
this.stderr
|
|
18329
|
-
${error.message}
|
|
18330
|
-
done(null, null);
|
|
18510
|
+
this.stderr = `${this.stderr}
|
|
18511
|
+
${error.message}`.slice(-STDERR_KEEP);
|
|
18512
|
+
if (this.child.pid === void 0) done(null, null);
|
|
18331
18513
|
});
|
|
18332
18514
|
});
|
|
18333
18515
|
this.child.stdin.on("error", () => {
|
|
18334
18516
|
});
|
|
18335
|
-
createInterface3({ input: this.child.stdout })
|
|
18517
|
+
const lines = createInterface3({ input: this.child.stdout });
|
|
18518
|
+
lines.on("line", hooks.line);
|
|
18519
|
+
this.outputDone = new Promise((resolve4) => lines.once("close", () => resolve4()));
|
|
18336
18520
|
}
|
|
18337
18521
|
get pid() {
|
|
18338
18522
|
return this.child.pid ?? -1;
|
|
@@ -18354,19 +18538,33 @@ ${error.message}`;
|
|
|
18354
18538
|
`);
|
|
18355
18539
|
return true;
|
|
18356
18540
|
}
|
|
18357
|
-
/** stdin
|
|
18358
|
-
|
|
18541
|
+
/** stdin 만 닫는다(입력 끝 알림) — 프로세스는 그대로 돈다. 한 차례에 프로세스 하나인 Agent(agy -p)가 쓴다. */
|
|
18542
|
+
endInput() {
|
|
18543
|
+
if (this.alive) this.child.stdin.end();
|
|
18544
|
+
}
|
|
18545
|
+
/** 기다리지 않고 바로 끈다(SIGTERM → B6 → SIGKILL · Windows 는 taskkill /T /F). 결과는 hooks.killed 에도. */
|
|
18546
|
+
async forceStop() {
|
|
18359
18547
|
if (!this.alive) return void 0;
|
|
18360
|
-
this.child.stdin.end();
|
|
18361
|
-
if (await this.waitExit(AGENT_STOP_WAIT_MS)) return void 0;
|
|
18362
18548
|
const first = await killTree(this.child, AGENT_STOP_WAIT_MS, "SIGTERM");
|
|
18363
18549
|
const result = first.directExited ? first : await killTree(this.child, AGENT_STOP_WAIT_MS, "SIGKILL");
|
|
18364
18550
|
this.onKilled?.(result);
|
|
18365
18551
|
return result;
|
|
18366
18552
|
}
|
|
18367
|
-
|
|
18553
|
+
/** stdin 을 닫아 스스로 끝나게 하고, 안 끝나면 강제로. 강제로 껐으면 그 결과(직계·트리)를 돌려주고 hooks.killed 에도 알린다. */
|
|
18554
|
+
async stop() {
|
|
18555
|
+
if (!this.alive) return void 0;
|
|
18556
|
+
this.child.stdin.end();
|
|
18557
|
+
if (await this.waitForExit(AGENT_STOP_WAIT_MS)) return void 0;
|
|
18558
|
+
return await this.forceStop();
|
|
18559
|
+
}
|
|
18560
|
+
/** {@code ms} 안에 프로세스가 끝나면 true. */
|
|
18561
|
+
async waitForExit(ms) {
|
|
18368
18562
|
return await withDeadline(this.exited.then(() => true), ms, false);
|
|
18369
18563
|
}
|
|
18564
|
+
/** stdout 이 다 읽혔으면(마지막 줄까지 hooks.line 으로 나갔으면) true — exit 이 마지막 줄보다 먼저 올 수 있다. */
|
|
18565
|
+
async waitForOutput(ms) {
|
|
18566
|
+
return await withDeadline(this.outputDone.then(() => true), ms, false);
|
|
18567
|
+
}
|
|
18370
18568
|
};
|
|
18371
18569
|
async function withDeadline(work, ms, fallback) {
|
|
18372
18570
|
let timer;
|
|
@@ -18444,42 +18642,6 @@ async function detectByVersion(spawnImpl, command, options) {
|
|
|
18444
18642
|
return { installed: true, version: run.stdout.trim().split("\n")[0]?.trim() };
|
|
18445
18643
|
}
|
|
18446
18644
|
|
|
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
18645
|
// src/core/agent/documents.ts
|
|
18484
18646
|
var DOCUMENT_LINE = /📄[^\n]*?\/app\/docs\/([0-9a-f]{32})(?![0-9a-f])/gu;
|
|
18485
18647
|
var HEX32 = /^[0-9a-f]{32}$/;
|
|
@@ -18581,6 +18743,369 @@ function appendUnique(target, items) {
|
|
|
18581
18743
|
}
|
|
18582
18744
|
}
|
|
18583
18745
|
|
|
18746
|
+
// src/core/agent/antigravity.ts
|
|
18747
|
+
function antigravityAdapter(deps) {
|
|
18748
|
+
const processes = new AgyProcesses();
|
|
18749
|
+
const tools = { names: new Set(deps.tools.map((tool) => tool.name)), preamble: antigravityToolPreamble(deps.tools) };
|
|
18750
|
+
return {
|
|
18751
|
+
id: "antigravity",
|
|
18752
|
+
displayName: "Antigravity",
|
|
18753
|
+
async detect() {
|
|
18754
|
+
const detected = await detectByVersion(deps.spawnImpl, AGY, { cwd: deps.home, env: deps.env, timeoutMs: AGENT_CALL_TIMEOUT_MS });
|
|
18755
|
+
if (detected.installed && detected.version !== VERIFIED_AGY_VERSION) {
|
|
18756
|
+
deps.log.write({ event: "agent_version_unverified", agent: "antigravity", version: detected.version ?? "-", verified: VERIFIED_AGY_VERSION });
|
|
18757
|
+
}
|
|
18758
|
+
return detected;
|
|
18759
|
+
},
|
|
18760
|
+
async authStatus() {
|
|
18761
|
+
const run = await runToEnd(deps.spawnImpl, AGY, ["models"], { cwd: deps.home, env: deps.env, timeoutMs: AGENT_CALL_TIMEOUT_MS });
|
|
18762
|
+
if (run.spawnError || run.timedOut) return { ready: false, detail: run.spawnError ?? "timed out" };
|
|
18763
|
+
return antigravityAuth(run.code, deps.env, await modelProvider(deps.home));
|
|
18764
|
+
},
|
|
18765
|
+
open: ({ conversationUuid, resumeRef, textMaxCharacters, documentsMax, agentName }) => new AntigravitySession(conversationUuid, resumeRef, agentName, deps.schema(textMaxCharacters, documentsMax), deps, processes, tools)
|
|
18766
|
+
};
|
|
18767
|
+
}
|
|
18768
|
+
function antigravityAuth(code, env, provider) {
|
|
18769
|
+
if (code !== 0) return { ready: false, detail: "sign in \u2014 run `agy` once" };
|
|
18770
|
+
if ((env.GEMINI_API_KEY ?? "") !== "" && provider === "gemini") return { ready: true, mode: "apiKey", method: "gemini-api-key" };
|
|
18771
|
+
if (env.AGY_ADC_AUTH === "true") return { ready: true, mode: "apiKey", method: "google-cloud-adc" };
|
|
18772
|
+
return { ready: true, mode: "subscription", method: "google-account" };
|
|
18773
|
+
}
|
|
18774
|
+
async function modelProvider(home) {
|
|
18775
|
+
try {
|
|
18776
|
+
const value = JSON.parse(await readFile16(join12(home, ".gemini", "antigravity-cli", "settings.json"), "utf8"));
|
|
18777
|
+
const provider = value?.modelProvider;
|
|
18778
|
+
return typeof provider === "string" ? provider : void 0;
|
|
18779
|
+
} catch {
|
|
18780
|
+
return void 0;
|
|
18781
|
+
}
|
|
18782
|
+
}
|
|
18783
|
+
var AgyProcesses = class {
|
|
18784
|
+
children = /* @__PURE__ */ new Set();
|
|
18785
|
+
stuck = /* @__PURE__ */ new Set();
|
|
18786
|
+
add(child) {
|
|
18787
|
+
this.children.add(child);
|
|
18788
|
+
}
|
|
18789
|
+
exited(child) {
|
|
18790
|
+
this.children.delete(child);
|
|
18791
|
+
this.stuck.delete(child);
|
|
18792
|
+
}
|
|
18793
|
+
/** 모두 끝났나 — 안 끝난 것은 B6 기다리고 강제로 끈다(이미 못 끈 것은 기다리지 않는다). 하나라도 살아 있으면 그 pid 들. */
|
|
18794
|
+
async settle() {
|
|
18795
|
+
for (const child of [...this.children]) {
|
|
18796
|
+
if (!child.alive || this.stuck.has(child)) continue;
|
|
18797
|
+
if (await child.waitForExit(AGENT_STOP_WAIT_MS)) continue;
|
|
18798
|
+
await child.forceStop();
|
|
18799
|
+
if (child.alive) this.stuck.add(child);
|
|
18800
|
+
}
|
|
18801
|
+
return [...this.children].filter((child) => child.alive).map((child) => child.pid);
|
|
18802
|
+
}
|
|
18803
|
+
/** close — 아직 못 끈 것으로 표시되지 않은 것만 끈다(못 끈 것은 settle 이 계속 막는다). */
|
|
18804
|
+
async stopAll() {
|
|
18805
|
+
await Promise.all([...this.children].filter((child) => !this.stuck.has(child)).map(async (child) => {
|
|
18806
|
+
await child.forceStop();
|
|
18807
|
+
if (child.alive) this.stuck.add(child);
|
|
18808
|
+
}));
|
|
18809
|
+
}
|
|
18810
|
+
};
|
|
18811
|
+
var AntigravitySession = class {
|
|
18812
|
+
constructor(conversationUuid, resumeRef, agentName, schema, deps, processes, tools) {
|
|
18813
|
+
this.conversationUuid = conversationUuid;
|
|
18814
|
+
this.agentName = agentName;
|
|
18815
|
+
this.schema = schema;
|
|
18816
|
+
this.deps = deps;
|
|
18817
|
+
this.processes = processes;
|
|
18818
|
+
this.tools = tools;
|
|
18819
|
+
this.resumed = resumeRef !== void 0;
|
|
18820
|
+
this.sessionRef = resumeRef;
|
|
18821
|
+
this.cwd = deps.workDir(agentName);
|
|
18822
|
+
}
|
|
18823
|
+
conversationUuid;
|
|
18824
|
+
agentName;
|
|
18825
|
+
schema;
|
|
18826
|
+
deps;
|
|
18827
|
+
processes;
|
|
18828
|
+
tools;
|
|
18829
|
+
agent = "antigravity";
|
|
18830
|
+
resumed;
|
|
18831
|
+
sessionRef;
|
|
18832
|
+
closed = false;
|
|
18833
|
+
generation = 0;
|
|
18834
|
+
lastPid = -1;
|
|
18835
|
+
turn;
|
|
18836
|
+
cwd;
|
|
18837
|
+
get pid() {
|
|
18838
|
+
return this.lastPid;
|
|
18839
|
+
}
|
|
18840
|
+
get alive() {
|
|
18841
|
+
return !this.closed;
|
|
18842
|
+
}
|
|
18843
|
+
async send(text2, timeoutMs) {
|
|
18844
|
+
if (this.closed) return { kind: "exited", code: null, signal: null, stderrTail: "session closed" };
|
|
18845
|
+
let resolve4;
|
|
18846
|
+
const outcome = new Promise((r) => {
|
|
18847
|
+
resolve4 = r;
|
|
18848
|
+
});
|
|
18849
|
+
const turn = {
|
|
18850
|
+
generation: ++this.generation,
|
|
18851
|
+
resolve: resolve4,
|
|
18852
|
+
facts: new TurnFactsCollector(),
|
|
18853
|
+
counted: /* @__PURE__ */ new Set(),
|
|
18854
|
+
foreign: [],
|
|
18855
|
+
interrupted: false,
|
|
18856
|
+
done: false
|
|
18857
|
+
};
|
|
18858
|
+
this.turn = turn;
|
|
18859
|
+
void this.run(turn, text2).catch((error) => this.finish(turn, {
|
|
18860
|
+
kind: "exited",
|
|
18861
|
+
code: null,
|
|
18862
|
+
signal: null,
|
|
18863
|
+
stderrTail: error instanceof Error ? error.message : String(error)
|
|
18864
|
+
}));
|
|
18865
|
+
try {
|
|
18866
|
+
return await withDeadline(outcome, timeoutMs, { kind: "timeout" });
|
|
18867
|
+
} finally {
|
|
18868
|
+
if (!turn.done) {
|
|
18869
|
+
turn.interrupted = true;
|
|
18870
|
+
turn.done = true;
|
|
18871
|
+
}
|
|
18872
|
+
if (this.turn === turn) this.turn = void 0;
|
|
18873
|
+
}
|
|
18874
|
+
}
|
|
18875
|
+
async interrupt() {
|
|
18876
|
+
const turn = this.turn;
|
|
18877
|
+
if (!turn || turn.done) return;
|
|
18878
|
+
turn.interrupted = true;
|
|
18879
|
+
if (turn.child?.alive) {
|
|
18880
|
+
await turn.child.forceStop();
|
|
18881
|
+
} else {
|
|
18882
|
+
this.finishInterrupted(turn);
|
|
18883
|
+
}
|
|
18884
|
+
}
|
|
18885
|
+
async close() {
|
|
18886
|
+
this.closed = true;
|
|
18887
|
+
const turn = this.turn;
|
|
18888
|
+
if (turn) turn.interrupted = true;
|
|
18889
|
+
await this.processes.stopAll();
|
|
18890
|
+
if (turn) this.finishInterrupted(turn);
|
|
18891
|
+
}
|
|
18892
|
+
/** 한 차례 — 앞 프로세스 정리 → 사전 점검 → 띄우기. await 마다 멈춤을 다시 본다. */
|
|
18893
|
+
async run(turn, text2) {
|
|
18894
|
+
const running = await this.processes.settle();
|
|
18895
|
+
if (running.length > 0) {
|
|
18896
|
+
this.deps.log.write({ event: "agent_previous_running", agent: this.agent, conversationUuid: this.conversationUuid, pids: running });
|
|
18897
|
+
this.finish(turn, { kind: "refused", errorCode: "AGENT_PREVIOUS_RUNNING", reason: `the previous Antigravity process did not stop (pid ${running.join(", ")})` });
|
|
18898
|
+
return;
|
|
18899
|
+
}
|
|
18900
|
+
if (this.stopped(turn)) return this.finishInterrupted(turn);
|
|
18901
|
+
let policy;
|
|
18902
|
+
try {
|
|
18903
|
+
await mkdir7(this.cwd, { recursive: true, mode: 448 });
|
|
18904
|
+
await writeWorkspaceMcpConfig(this.cwd, this.deps.mcpConfig(this.agentName));
|
|
18905
|
+
policy = await antigravityMcpPolicy({ cwd: this.cwd, home: this.deps.home, pluginList: () => this.pluginList() });
|
|
18906
|
+
} catch (error) {
|
|
18907
|
+
policy = { ok: false, reason: `could not prepare the work folder: ${error instanceof Error ? error.message : String(error)}` };
|
|
18908
|
+
}
|
|
18909
|
+
if (this.stopped(turn)) return this.finishInterrupted(turn);
|
|
18910
|
+
if (!policy.ok) {
|
|
18911
|
+
this.deps.log.write({
|
|
18912
|
+
event: "agent_policy_unverified",
|
|
18913
|
+
agent: this.agent,
|
|
18914
|
+
conversationUuid: this.conversationUuid,
|
|
18915
|
+
reason: policy.reason,
|
|
18916
|
+
...policy.path ? { path: policy.path } : {}
|
|
18917
|
+
});
|
|
18918
|
+
this.finish(turn, { kind: "refused", errorCode: "AGENT_POLICY_UNVERIFIED", reason: policy.reason });
|
|
18919
|
+
return;
|
|
18920
|
+
}
|
|
18921
|
+
const args = antigravityAgentArgs({ schema: this.schema, settings: antigravitySettings(policy.deny), conversationId: this.sessionRef });
|
|
18922
|
+
const child = new AgentChild(this.deps.spawnImpl, AGY, args, { cwd: this.cwd, env: this.deps.env }, {
|
|
18923
|
+
line: (line) => this.onLine(turn, child, line),
|
|
18924
|
+
exit: (exit) => this.onExit(turn, child, exit),
|
|
18925
|
+
killed: (result) => this.deps.log.write({ event: "process_kill", pid: child.pid, agent: this.agent, ...result })
|
|
18926
|
+
});
|
|
18927
|
+
this.processes.add(child);
|
|
18928
|
+
turn.child = child;
|
|
18929
|
+
this.lastPid = child.pid;
|
|
18930
|
+
this.deps.log.write({
|
|
18931
|
+
event: "process_start",
|
|
18932
|
+
pid: child.pid,
|
|
18933
|
+
agent: this.agent,
|
|
18934
|
+
conversationUuid: this.conversationUuid,
|
|
18935
|
+
resume: this.sessionRef !== void 0
|
|
18936
|
+
});
|
|
18937
|
+
child.writeLine({ event: "user", message: { content: this.tools.preamble + text2 } });
|
|
18938
|
+
child.endInput();
|
|
18939
|
+
}
|
|
18940
|
+
stopped(turn) {
|
|
18941
|
+
return turn.interrupted || turn.done || this.closed;
|
|
18942
|
+
}
|
|
18943
|
+
async pluginList() {
|
|
18944
|
+
const run = await runToEnd(
|
|
18945
|
+
this.deps.spawnImpl,
|
|
18946
|
+
AGY,
|
|
18947
|
+
["plugin", "list", "--json"],
|
|
18948
|
+
{ cwd: this.cwd, env: this.deps.env, timeoutMs: AGENT_CALL_TIMEOUT_MS }
|
|
18949
|
+
);
|
|
18950
|
+
if (run.spawnError || run.timedOut || run.code !== 0) {
|
|
18951
|
+
return { ok: false, detail: run.spawnError ?? (run.timedOut ? "timed out" : `exit ${run.code}`) };
|
|
18952
|
+
}
|
|
18953
|
+
return { ok: true, stdout: run.stdout };
|
|
18954
|
+
}
|
|
18955
|
+
/** 결과는 한 번만 — 그 뒤 줄·exit·멈춤은 이 차례를 바꾸지 않는다. */
|
|
18956
|
+
finish(turn, outcome) {
|
|
18957
|
+
if (turn.done) return;
|
|
18958
|
+
turn.done = true;
|
|
18959
|
+
if (this.turn === turn) this.turn = void 0;
|
|
18960
|
+
turn.resolve(outcome);
|
|
18961
|
+
}
|
|
18962
|
+
finishInterrupted(turn) {
|
|
18963
|
+
this.finish(turn, { kind: "result", facts: turn.facts.snapshot(), result: { isError: true, subtype: "interrupted" } });
|
|
18964
|
+
}
|
|
18965
|
+
/** 프로세스 종료 — 소유를 놓고(로그는 그 세대 pid), 결과가 아직이면 마지막 줄까지 읽힌 뒤에 정한다(exit 이 result 줄보다 먼저 올 수 있다). */
|
|
18966
|
+
onExit(turn, child, exit) {
|
|
18967
|
+
this.processes.exited(child);
|
|
18968
|
+
this.deps.log.write({
|
|
18969
|
+
event: "process_exit",
|
|
18970
|
+
pid: child.pid,
|
|
18971
|
+
agent: this.agent,
|
|
18972
|
+
conversationUuid: this.conversationUuid,
|
|
18973
|
+
code: exit.code,
|
|
18974
|
+
signal: exit.signal
|
|
18975
|
+
});
|
|
18976
|
+
void child.waitForOutput(AGENT_STOP_WAIT_MS).then(() => {
|
|
18977
|
+
if (turn.interrupted) this.finishInterrupted(turn);
|
|
18978
|
+
else this.finish(turn, { kind: "exited", ...exit });
|
|
18979
|
+
});
|
|
18980
|
+
}
|
|
18981
|
+
onLine(turn, child, line) {
|
|
18982
|
+
if (turn.done) return;
|
|
18983
|
+
let event;
|
|
18984
|
+
try {
|
|
18985
|
+
const value = JSON.parse(line);
|
|
18986
|
+
if (!isObject3(value)) throw new Error("not an object");
|
|
18987
|
+
event = value;
|
|
18988
|
+
} catch {
|
|
18989
|
+
this.deps.log.write({ event: "bad_line", pid: child.pid, agent: this.agent, length: line.length });
|
|
18990
|
+
return;
|
|
18991
|
+
}
|
|
18992
|
+
if (event.event === "init") {
|
|
18993
|
+
if (typeof event.conversation_id === "string") this.sessionRef = event.conversation_id;
|
|
18994
|
+
return;
|
|
18995
|
+
}
|
|
18996
|
+
if (event.event === "step_update" && isObject3(event.step_update)) {
|
|
18997
|
+
this.onStep(turn, event.step_update);
|
|
18998
|
+
return;
|
|
18999
|
+
}
|
|
19000
|
+
if (event.event === "result" && isObject3(event.result)) {
|
|
19001
|
+
this.onResult(turn, child, event.result);
|
|
19002
|
+
}
|
|
19003
|
+
}
|
|
19004
|
+
/** TurnFacts(r2 좁힘): tool · DONE · call_mcp_tool · 브리지 · 공개 도구 이름 · 오류 없는 글 결과 · 같은 단계 한 번. */
|
|
19005
|
+
onStep(turn, step) {
|
|
19006
|
+
if (step.step_type !== "tool" || step.state !== "DONE" || !isObject3(step.tool_info)) return;
|
|
19007
|
+
const tool = step.tool_info;
|
|
19008
|
+
if (tool.name !== "call_mcp_tool" || !isObject3(tool.parameters)) return;
|
|
19009
|
+
const server = typeof tool.parameters.ServerName === "string" ? tool.parameters.ServerName : "";
|
|
19010
|
+
const name = typeof tool.parameters.ToolName === "string" ? tool.parameters.ToolName : "";
|
|
19011
|
+
if (server !== ANTIGRAVITY_MCP_SERVER) {
|
|
19012
|
+
turn.foreign.push({ server, tool: name });
|
|
19013
|
+
return;
|
|
19014
|
+
}
|
|
19015
|
+
if (typeof step.step_index !== "number" || turn.counted.has(step.step_index)) return;
|
|
19016
|
+
if (tool.error !== void 0 || typeof tool.output !== "string" || !this.tools.names.has(name)) return;
|
|
19017
|
+
turn.counted.add(step.step_index);
|
|
19018
|
+
turn.facts.add(agyContentParts(tool.output), this.deps.writeTools.has(name));
|
|
19019
|
+
}
|
|
19020
|
+
onResult(turn, child, result) {
|
|
19021
|
+
if (typeof result.conversation_id === "string") this.sessionRef = result.conversation_id;
|
|
19022
|
+
const usage2 = isObject3(result.usage) ? result.usage : void 0;
|
|
19023
|
+
this.deps.log.write({
|
|
19024
|
+
event: "agent_usage",
|
|
19025
|
+
pid: child.pid,
|
|
19026
|
+
agent: this.agent,
|
|
19027
|
+
conversationUuid: this.conversationUuid,
|
|
19028
|
+
...typeof usage2?.input_tokens === "number" ? { inputTokens: usage2.input_tokens } : {},
|
|
19029
|
+
...typeof usage2?.output_tokens === "number" ? { outputTokens: usage2.output_tokens } : {}
|
|
19030
|
+
});
|
|
19031
|
+
if (turn.interrupted) return this.finishInterrupted(turn);
|
|
19032
|
+
const facts = turn.facts.snapshot();
|
|
19033
|
+
if (turn.foreign.length > 0) {
|
|
19034
|
+
for (const { server, tool } of turn.foreign) {
|
|
19035
|
+
this.deps.log.write({
|
|
19036
|
+
event: "agent_policy_violation",
|
|
19037
|
+
pid: child.pid,
|
|
19038
|
+
agent: this.agent,
|
|
19039
|
+
conversationUuid: this.conversationUuid,
|
|
19040
|
+
server,
|
|
19041
|
+
tool
|
|
19042
|
+
});
|
|
19043
|
+
}
|
|
19044
|
+
this.finish(turn, { kind: "result", facts, result: { isError: true, subtype: "policy_violation" } });
|
|
19045
|
+
return;
|
|
19046
|
+
}
|
|
19047
|
+
const status = typeof result.status === "string" ? result.status : void 0;
|
|
19048
|
+
this.finish(turn, {
|
|
19049
|
+
kind: "result",
|
|
19050
|
+
facts,
|
|
19051
|
+
result: {
|
|
19052
|
+
subtype: status,
|
|
19053
|
+
isError: status !== "SUCCESS",
|
|
19054
|
+
structuredOutput: result.structured_output,
|
|
19055
|
+
resultText: typeof result.response === "string" ? result.response : void 0,
|
|
19056
|
+
numTurns: typeof result.num_turns === "number" ? result.num_turns : void 0
|
|
19057
|
+
}
|
|
19058
|
+
});
|
|
19059
|
+
}
|
|
19060
|
+
};
|
|
19061
|
+
function agyContentParts(output) {
|
|
19062
|
+
try {
|
|
19063
|
+
JSON.parse(output);
|
|
19064
|
+
return [{ type: "text", text: output }];
|
|
19065
|
+
} catch {
|
|
19066
|
+
return output.split("\n").map((text2) => ({ type: "text", text: text2 }));
|
|
19067
|
+
}
|
|
19068
|
+
}
|
|
19069
|
+
function isObject3(value) {
|
|
19070
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
19071
|
+
}
|
|
19072
|
+
|
|
19073
|
+
// src/core/agent/claudeArgs.ts
|
|
19074
|
+
function claudeMcpConfig(bridge) {
|
|
19075
|
+
return { mcpServers: { [AINECTO_MCP_SERVER]: { command: bridge.command, args: bridge.args } } };
|
|
19076
|
+
}
|
|
19077
|
+
function claudeAgentArgs(input) {
|
|
19078
|
+
const args = [
|
|
19079
|
+
"-p",
|
|
19080
|
+
"--input-format",
|
|
19081
|
+
"stream-json",
|
|
19082
|
+
"--output-format",
|
|
19083
|
+
"stream-json",
|
|
19084
|
+
"--verbose",
|
|
19085
|
+
"--json-schema",
|
|
19086
|
+
JSON.stringify(input.schema),
|
|
19087
|
+
"--tools",
|
|
19088
|
+
"",
|
|
19089
|
+
// 내장 도구(Bash·Read·Write·Edit·Agent·Skill·WebFetch…) 전부 끔
|
|
19090
|
+
"--strict-mcp-config",
|
|
19091
|
+
"--mcp-config",
|
|
19092
|
+
JSON.stringify(input.mcpConfig),
|
|
19093
|
+
"--allowedTools",
|
|
19094
|
+
`mcp__${AINECTO_MCP_SERVER}`,
|
|
19095
|
+
"--permission-mode",
|
|
19096
|
+
"dontAsk",
|
|
19097
|
+
// 허용 밖은 묻지 않고 바로 거절(헤드리스에서 묻기 = 2분 대기)
|
|
19098
|
+
"--setting-sources",
|
|
19099
|
+
""
|
|
19100
|
+
// 사용자·프로젝트 설정(플러그인·스킬·훅·권한) 끔
|
|
19101
|
+
];
|
|
19102
|
+
if (input.resumeSessionId) {
|
|
19103
|
+
args.push("--resume", input.resumeSessionId);
|
|
19104
|
+
}
|
|
19105
|
+
return args;
|
|
19106
|
+
}
|
|
19107
|
+
var AINECTO_TOOL_PREFIX = `mcp__${AINECTO_MCP_SERVER}__`;
|
|
19108
|
+
|
|
18584
19109
|
// src/core/agent/claudeCode.ts
|
|
18585
19110
|
var CLAUDE = "claude";
|
|
18586
19111
|
function claudeCodeAdapter(deps) {
|
|
@@ -19126,7 +19651,7 @@ function toError(error) {
|
|
|
19126
19651
|
}
|
|
19127
19652
|
|
|
19128
19653
|
// src/core/agent/runs.ts
|
|
19129
|
-
import { readFile as
|
|
19654
|
+
import { readFile as readFile17, rename as rename8, writeFile as writeFile9 } from "fs/promises";
|
|
19130
19655
|
var AgentRunLog = class {
|
|
19131
19656
|
constructor(path, log) {
|
|
19132
19657
|
this.path = path;
|
|
@@ -19140,7 +19665,7 @@ var AgentRunLog = class {
|
|
|
19140
19665
|
let reason;
|
|
19141
19666
|
const runs = /* @__PURE__ */ new Map();
|
|
19142
19667
|
try {
|
|
19143
|
-
const parsed = JSON.parse(await
|
|
19668
|
+
const parsed = JSON.parse(await readFile17(this.path, "utf8"));
|
|
19144
19669
|
for (const value of Array.isArray(parsed.runs) ? parsed.runs : []) {
|
|
19145
19670
|
const e = value ?? {};
|
|
19146
19671
|
if (typeof e.cardUuid === "string" && typeof e.startedAt === "string") {
|
|
@@ -19178,9 +19703,9 @@ var AgentRunLog = class {
|
|
|
19178
19703
|
}
|
|
19179
19704
|
async save() {
|
|
19180
19705
|
const tmp = `${this.path}.tmp`;
|
|
19181
|
-
await
|
|
19706
|
+
await writeFile9(tmp, `${JSON.stringify({ version: 1, runs: [...this.runs.values()] }, null, 2)}
|
|
19182
19707
|
`, { mode: PRIVATE_FILE_MODE });
|
|
19183
|
-
await
|
|
19708
|
+
await rename8(tmp, this.path);
|
|
19184
19709
|
}
|
|
19185
19710
|
};
|
|
19186
19711
|
|
|
@@ -19241,7 +19766,7 @@ async function probe(log, agent, kind, work, summary2) {
|
|
|
19241
19766
|
}
|
|
19242
19767
|
|
|
19243
19768
|
// src/core/agent/sessions.ts
|
|
19244
|
-
import { readFile as
|
|
19769
|
+
import { readFile as readFile18, rename as rename9, writeFile as writeFile10 } from "fs/promises";
|
|
19245
19770
|
var AgentSessionMap = class {
|
|
19246
19771
|
constructor(path) {
|
|
19247
19772
|
this.path = path;
|
|
@@ -19250,7 +19775,7 @@ var AgentSessionMap = class {
|
|
|
19250
19775
|
map = emptyMap();
|
|
19251
19776
|
async load() {
|
|
19252
19777
|
try {
|
|
19253
|
-
const parsed = JSON.parse(await
|
|
19778
|
+
const parsed = JSON.parse(await readFile18(this.path, "utf8"));
|
|
19254
19779
|
const map = emptyMap();
|
|
19255
19780
|
map[DEFAULT_AGENT] = entries(parsed.conversations);
|
|
19256
19781
|
const byAgent = parsed.byAgent && typeof parsed.byAgent === "object" ? parsed.byAgent : {};
|
|
@@ -19277,13 +19802,13 @@ var AgentSessionMap = class {
|
|
|
19277
19802
|
async save() {
|
|
19278
19803
|
const byAgent = Object.fromEntries(AGENT_IDS.filter((id) => id !== DEFAULT_AGENT).map((id) => [id, this.map[id]]));
|
|
19279
19804
|
const tmp = `${this.path}.tmp`;
|
|
19280
|
-
await
|
|
19805
|
+
await writeFile10(
|
|
19281
19806
|
tmp,
|
|
19282
19807
|
`${JSON.stringify({ version: 2, conversations: this.map[DEFAULT_AGENT], byAgent }, null, 2)}
|
|
19283
19808
|
`,
|
|
19284
19809
|
{ mode: PRIVATE_FILE_MODE }
|
|
19285
19810
|
);
|
|
19286
|
-
await
|
|
19811
|
+
await rename9(tmp, this.path);
|
|
19287
19812
|
}
|
|
19288
19813
|
};
|
|
19289
19814
|
function emptyMap() {
|
|
@@ -19428,7 +19953,7 @@ var AGENT_HELP_LINES = [
|
|
|
19428
19953
|
function isPcRunCommand(domain, action) {
|
|
19429
19954
|
return domain === "pc" && action === "run";
|
|
19430
19955
|
}
|
|
19431
|
-
var BILLED_TO = { "claude-code": "Anthropic", codex: "OpenAI" };
|
|
19956
|
+
var BILLED_TO = { "claude-code": "Anthropic", codex: "OpenAI", antigravity: "Google" };
|
|
19432
19957
|
async function executeAgentServe(input) {
|
|
19433
19958
|
const paths = agentPaths();
|
|
19434
19959
|
await ensurePrivateDir(paths.dir);
|
|
@@ -19445,14 +19970,30 @@ async function executeAgentServe(input) {
|
|
|
19445
19970
|
},
|
|
19446
19971
|
log
|
|
19447
19972
|
});
|
|
19448
|
-
const
|
|
19973
|
+
const serverTools = await tools.list();
|
|
19974
|
+
const writeTools = writeToolNames(serverTools);
|
|
19449
19975
|
const cliScript = process.argv[1];
|
|
19450
19976
|
if (!cliScript) throw new Error("Cannot find the path of this CLI to start the AiNecto bridge for the agents.");
|
|
19451
19977
|
const bridge = (agentName) => ainectoBridge(process.execPath, cliScript, input.endpoint, agentName);
|
|
19452
19978
|
const shared = { spawnImpl: spawnAgent, cwd: paths.work, env: agentEnv(process.env), log, writeTools };
|
|
19453
19979
|
const all = [
|
|
19454
19980
|
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 })
|
|
19981
|
+
codexAdapter({ ...shared, appServerArgs: (agentName) => codexAppServerArgs(bridge(agentName), writeTools), clientVersion: CLI_VERSION }),
|
|
19982
|
+
antigravityAdapter({
|
|
19983
|
+
spawnImpl: spawnAgent,
|
|
19984
|
+
env: shared.env,
|
|
19985
|
+
home: homedir6(),
|
|
19986
|
+
log,
|
|
19987
|
+
writeTools,
|
|
19988
|
+
tools: serverTools,
|
|
19989
|
+
// 연결 이름마다 한 폴더 — 이름 글자를 폴더 이름에 쓰지 않는다(해시).
|
|
19990
|
+
workDir: (agentName) => join13(
|
|
19991
|
+
paths.antigravity,
|
|
19992
|
+
agentName ? `agent-${createHash8("sha256").update(agentName).digest("hex").slice(0, 16)}` : "chat"
|
|
19993
|
+
),
|
|
19994
|
+
mcpConfig: (agentName) => antigravityMcpConfig(bridge(agentName)),
|
|
19995
|
+
schema: agentReplySchema
|
|
19996
|
+
})
|
|
19456
19997
|
];
|
|
19457
19998
|
const checks = await checkAgents(all, log);
|
|
19458
19999
|
log.write({
|
|
@@ -19467,7 +20008,7 @@ async function executeAgentServe(input) {
|
|
|
19467
20008
|
const remote = await pcRemoteSetup({ endpoint: input.endpoint, auth: input.auth, account: () => readAccount(client()), io: input.io });
|
|
19468
20009
|
const plan = pcPlan({ agents: agents.length, remoteEnabled: remote.remoteEnabled });
|
|
19469
20010
|
if (plan === "nothing") {
|
|
19470
|
-
throw new Error("
|
|
20011
|
+
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
20012
|
}
|
|
19472
20013
|
let agentBusy = () => false;
|
|
19473
20014
|
const upgrades = upgradeWatch({
|
|
@@ -19532,7 +20073,7 @@ async function executeAgentServe(input) {
|
|
|
19532
20073
|
}
|
|
19533
20074
|
|
|
19534
20075
|
// src/adapters/cli/ainectoCli.ts
|
|
19535
|
-
import { homedir as
|
|
20076
|
+
import { homedir as homedir7, hostname as hostname4, tmpdir } from "os";
|
|
19536
20077
|
async function runAinectoCli(argv, io) {
|
|
19537
20078
|
let parsed = { json: argv.includes("--json"), help: false, version: false, positionals: [] };
|
|
19538
20079
|
try {
|
|
@@ -19621,8 +20162,8 @@ async function runAinectoCli(argv, io) {
|
|
|
19621
20162
|
auth,
|
|
19622
20163
|
client: client2,
|
|
19623
20164
|
// ★외부 CLI 는 홈 폴더에서 돈다 — 지금 저장소의 local·project 범위 항목이 사용자 범위 판정에 끼지 않게.
|
|
19624
|
-
runner: systemCommandRunner({ cwd:
|
|
19625
|
-
home:
|
|
20165
|
+
runner: systemCommandRunner({ cwd: homedir7() }),
|
|
20166
|
+
home: homedir7(),
|
|
19626
20167
|
json: parsed.json,
|
|
19627
20168
|
io
|
|
19628
20169
|
});
|
|
@@ -19636,9 +20177,9 @@ async function runAinectoCli(argv, io) {
|
|
|
19636
20177
|
tokenStore,
|
|
19637
20178
|
auth,
|
|
19638
20179
|
client: client2,
|
|
19639
|
-
runner: systemCommandRunner({ cwd:
|
|
20180
|
+
runner: systemCommandRunner({ cwd: homedir7() }),
|
|
19640
20181
|
hereRunner: systemCommandRunner({ cwd: process.cwd() }),
|
|
19641
|
-
home:
|
|
20182
|
+
home: homedir7(),
|
|
19642
20183
|
cwd: process.cwd(),
|
|
19643
20184
|
envVars: process.env
|
|
19644
20185
|
};
|
|
@@ -19766,9 +20307,9 @@ async function runAinectoCli(argv, io) {
|
|
|
19766
20307
|
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
19767
20308
|
return await response.json();
|
|
19768
20309
|
},
|
|
19769
|
-
makeTempDir: () => mkdtemp(
|
|
20310
|
+
makeTempDir: () => mkdtemp(join14(tmpdir(), "ainecto-upgrade-")),
|
|
19770
20311
|
removeDir: (path) => rm3(path, { recursive: true, force: true }),
|
|
19771
|
-
home:
|
|
20312
|
+
home: homedir7(),
|
|
19772
20313
|
log: openAgentLog(swapPaths)
|
|
19773
20314
|
});
|
|
19774
20315
|
}
|
|
@@ -19992,7 +20533,7 @@ function helpText() {
|
|
|
19992
20533
|
" 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
20534
|
" ainecto init --undo",
|
|
19994
20535
|
"",
|
|
19995
|
-
"This PC (requests from AiNecto Chat and auto-run cards, answered by Claude Code or
|
|
20536
|
+
"This PC (requests from AiNecto Chat and auto-run cards, answered by Claude Code, Codex or Antigravity on this machine):",
|
|
19996
20537
|
...AGENT_HELP_LINES,
|
|
19997
20538
|
"",
|
|
19998
20539
|
"Terminal sessions on this machine (no tmux or cmux needed; macOS, Linux and Windows):",
|