@quantiya/codevibe-core 2.0.81 → 2.0.82

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.
@@ -951,7 +951,7 @@ function companionPreferenceFilePath() {
951
951
  async function readCompanionPreference() {
952
952
  let filePath = companionPreferenceFilePath(), raw, st;
953
953
  try {
954
- st = await fs64.stat(filePath);
954
+ st = await fs65.stat(filePath);
955
955
  } catch (err) {
956
956
  return err?.code !== "ENOENT" && logger.debug("[companion-preference] stat error \u2014 treating as missing", {
957
957
  filePath,
@@ -964,7 +964,7 @@ async function readCompanionPreference() {
964
964
  `
965
965
  ), null;
966
966
  try {
967
- raw = await fs64.readFile(filePath, "utf8");
967
+ raw = await fs65.readFile(filePath, "utf8");
968
968
  } catch (err) {
969
969
  return logger.debug("[companion-preference] read error \u2014 treating as missing", {
970
970
  filePath,
@@ -982,19 +982,19 @@ async function readCompanionPreference() {
982
982
  }
983
983
  async function persistCompanionPreference(pref) {
984
984
  let filePath = companionPreferenceFilePath(), dir = path85.dirname(filePath);
985
- await fs64.mkdir(dir, { recursive: !0 }), await fs64.writeFile(filePath, JSON.stringify(pref, null, 2), {
985
+ await fs65.mkdir(dir, { recursive: !0 }), await fs65.writeFile(filePath, JSON.stringify(pref, null, 2), {
986
986
  encoding: "utf8",
987
987
  mode: 384
988
988
  });
989
989
  try {
990
- await fs64.chmod(filePath, 384);
990
+ await fs65.chmod(filePath, 384);
991
991
  } catch {
992
992
  }
993
993
  }
994
- var fs64, path85, os52, import_zod16, CompanionPreferenceSchema, init_persist_preference = __esm({
994
+ var fs65, path85, os52, import_zod16, CompanionPreferenceSchema, init_persist_preference = __esm({
995
995
  "src/companion-mode/persist-preference.ts"() {
996
996
  "use strict";
997
- fs64 = __toESM(require("fs/promises")), path85 = __toESM(require("path")), os52 = __toESM(require("os")), import_zod16 = require("zod");
997
+ fs65 = __toESM(require("fs/promises")), path85 = __toESM(require("path")), os52 = __toESM(require("os")), import_zod16 = require("zod");
998
998
  init_logger2();
999
999
  CompanionPreferenceSchema = import_zod16.z.object({
1000
1000
  lastAgent: import_zod16.z.union([
@@ -1059,13 +1059,13 @@ function isContainedPath(parent, candidate) {
1059
1059
  }
1060
1060
  function resolveDeclaredCompanionLauncher(packageJsonPath) {
1061
1061
  try {
1062
- let packageRoot = fs65.realpathSync(path86.dirname(packageJsonPath)), declared = JSON.parse(
1063
- fs65.readFileSync(packageJsonPath, "utf8")
1062
+ let packageRoot = fs66.realpathSync(path86.dirname(packageJsonPath)), declared = JSON.parse(
1063
+ fs66.readFileSync(packageJsonPath, "utf8")
1064
1064
  ).codevibe?.companionLauncher;
1065
1065
  if (typeof declared != "string" || declared.trim().length === 0)
1066
1066
  return null;
1067
- let launcherPath = fs65.realpathSync(path86.resolve(packageRoot, declared));
1068
- return !isContainedPath(packageRoot, launcherPath) || !fs65.statSync(launcherPath).isFile() ? null : (fs65.accessSync(launcherPath, fs65.constants.X_OK), launcherPath);
1067
+ let launcherPath = fs66.realpathSync(path86.resolve(packageRoot, declared));
1068
+ return !isContainedPath(packageRoot, launcherPath) || !fs66.statSync(launcherPath).isFile() ? null : (fs66.accessSync(launcherPath, fs66.constants.X_OK), launcherPath);
1069
1069
  } catch {
1070
1070
  return null;
1071
1071
  }
@@ -1175,10 +1175,10 @@ async function runCompanionMode(args) {
1175
1175
  process.kill(process.pid, signal);
1176
1176
  }))(child.signal), 1) : child.status ?? 1;
1177
1177
  }
1178
- var import_child_process10, import_module, path86, fs65, NoAgentInstalledError, COMPANION_PLUGIN, ACTIVE_COMPANION_AGENTS, ACTIVATION_AGENT, init_companion_mode = __esm({
1178
+ var import_child_process10, import_module, path86, fs66, NoAgentInstalledError, COMPANION_PLUGIN, ACTIVE_COMPANION_AGENTS, ACTIVATION_AGENT, init_companion_mode = __esm({
1179
1179
  "src/companion-mode/index.ts"() {
1180
1180
  "use strict";
1181
- import_child_process10 = require("child_process"), import_module = require("module"), path86 = __toESM(require("path")), fs65 = __toESM(require("fs"));
1181
+ import_child_process10 = require("child_process"), import_module = require("module"), path86 = __toESM(require("path")), fs66 = __toESM(require("fs"));
1182
1182
  init_env_scrub();
1183
1183
  init_logger2();
1184
1184
  init_detect_agents();
@@ -21826,7 +21826,7 @@ async function clearRetiredPlannerCache(userId, cacheRoot = process.env.CODEVIBE
21826
21826
  }
21827
21827
 
21828
21828
  // src/orchestration-shell/index.ts
21829
- var path79 = __toESM(require("path")), os48 = __toESM(require("os")), import_promises = require("node:fs/promises"), import_node_fs37 = require("node:fs"), import_node_child_process10 = require("node:child_process"), import_node_util3 = require("node:util"), import_node_async_hooks = require("node:async_hooks");
21829
+ var path79 = __toESM(require("path")), os48 = __toESM(require("os")), import_promises = require("node:fs/promises"), fs59 = __toESM(require("node:fs")), import_node_fs37 = require("node:fs"), import_node_child_process10 = require("node:child_process"), import_node_util3 = require("node:util"), import_node_async_hooks = require("node:async_hooks");
21830
21830
 
21831
21831
  // src/orchestration-shell/web/sanitize.ts
21832
21832
  function sanitizeForTerminal(input) {
@@ -61160,6 +61160,9 @@ function resolveTeamExecution(_override, _env = process.env) {
61160
61160
  return DEFAULT_TEAM_EXECUTION;
61161
61161
  }
61162
61162
 
61163
+ // src/local-executor/spawn-sweep.ts
61164
+ init_logger2();
61165
+
61163
61166
  // src/orchestration-shell/quorum-loop.ts
61164
61167
  init_env_scrub();
61165
61168
 
@@ -62549,6 +62552,7 @@ var ChildProcessCommandRunner = class {
62549
62552
  let spawnOptions = {
62550
62553
  stdio: opts.stdinTty ? ["pipe", "pipe", "pipe"] : ["ignore", "pipe", "pipe"],
62551
62554
  windowsHide: !0,
62555
+ detached: opts.detached ?? !1,
62552
62556
  signal: opts.signal,
62553
62557
  env: opts.env !== void 0 ? scrubSearchApiKeys({ ...opts.env }) : scrubSearchApiKeys({ ...process.env }),
62554
62558
  ...opts.cwd !== void 0 ? { cwd: opts.cwd } : {}
@@ -63081,7 +63085,17 @@ function buildSeatbeltProfile(workdir, execPath = process.execPath, extraReadDir
63081
63085
  '(allow file-read* (subpath "/Library"))',
63082
63086
  '(allow file-read* (subpath "/private/var/db"))',
63083
63087
  '(allow file-read* (subpath "/private/var/select"))',
63084
- '(allow file-read* (subpath "/dev"))',
63088
+ // PD-MAC-DEV (§6.1): grant only literal reads of the device nodes agents
63089
+ // use, plus `/dev/fd`. Replaces the broad `/dev` subpath read so a confined
63090
+ // agent cannot open another terminal session's tty or its own controlling
63091
+ // terminal (/dev/tty, /dev/ttys*).
63092
+ '(allow file-read* (literal "/dev/null"))',
63093
+ '(allow file-read* (literal "/dev/zero"))',
63094
+ '(allow file-read* (literal "/dev/random"))',
63095
+ '(allow file-read* (literal "/dev/urandom"))',
63096
+ '(allow file-read* (literal "/dev/dtracehelper"))',
63097
+ '(allow file-read* (literal "/dev/autofs_nowait"))',
63098
+ '(allow file-read* (subpath "/dev/fd"))',
63085
63099
  // Ordinary POSIX tooling opens `/dev/null` rw. Grant only that literal
63086
63100
  // device (the `/dev` read above does not cover writes).
63087
63101
  '(allow file-write* (literal "/dev/null"))'
@@ -63124,11 +63138,13 @@ function buildSeatbeltProfile(workdir, execPath = process.execPath, extraReadDir
63124
63138
  );
63125
63139
  }
63126
63140
  return networkPosture === "open" ? lines.push(
63127
- // A1d resolver-confinement row: deny all network, then re-allow ALL
63128
- // OUTBOUND (external inbound stays denied). Loopback bind/inbound is permitted
63141
+ // A1d resolver-confinement row (§6.1, SP-A5, SP-A5b): deny all network,
63142
+ // then allow IP outbound + only mDNSResponder Unix socket for name resolution
63143
+ // (external inbound stays denied). Loopback bind/inbound is permitted
63129
63144
  // for local IPC (e.g. Antigravity local RPC daemon on 127.0.0.1).
63130
63145
  "(deny network*)",
63131
- "(allow network-outbound)",
63146
+ '(allow network-outbound (remote ip "*:*"))',
63147
+ '(allow network-outbound (remote unix-socket (path-literal "/private/var/run/mDNSResponder")))',
63132
63148
  '(allow network-bind (local ip "localhost:*"))',
63133
63149
  '(allow network-inbound (local ip "localhost:*"))',
63134
63150
  ""
@@ -84900,14 +84916,138 @@ function uniqueDetectedAgents(detected) {
84900
84916
  item2 !== "CLAUDE" && item2 !== "CODEX" && item2 !== "ANTIGRAVITY" || out.includes(item2) || out.push(item2);
84901
84917
  return out;
84902
84918
  }
84903
- function agyReadOnlyWorkdirPreamble(workdir) {
84904
- return [
84919
+ var AGY_ADVISORY_LISTING_MAX_ENTRIES = 500, AGY_ADVISORY_LISTING_MAX_BYTES = 16384, AGY_ADVISORY_IGNORED_DIRS = /* @__PURE__ */ new Set([
84920
+ ".git",
84921
+ "node_modules",
84922
+ "dist",
84923
+ "build",
84924
+ "coverage",
84925
+ "target",
84926
+ "venv",
84927
+ ".venv",
84928
+ "__pycache__",
84929
+ "Pods",
84930
+ "DerivedData",
84931
+ ".gradle",
84932
+ ".idea",
84933
+ ".next",
84934
+ ".turbo",
84935
+ ".cache",
84936
+ ".gemini",
84937
+ ".codevibe",
84938
+ ".codevibe-audit",
84939
+ ".codevibe-attachments",
84940
+ ".agent-worktrees",
84941
+ ".review-worktrees",
84942
+ ".hard-gate",
84943
+ ".dev-marketplace",
84944
+ ".dev-marketplace-next"
84945
+ ]), AGY_COMMAND_TOOL_SEATBELT_WARNING = "Your command tool cannot run in this sandbox: do not call it. CodeVibe listed the folder for you below (relative paths with '/' separator; literal backslashes escaped as \\\\, control characters escaped as \\xNN or \\uNNNN; a trailing / marks a folder). Read files with your file-reading tool, using absolute paths under the folder.";
84946
+ function sanitizeListingPath(relPath) {
84947
+ return relPath.replace(/\\/g, "\\\\").replace(/[\x00-\x1f\x7f]/g, (c) => `\\x${c.charCodeAt(0).toString(16).padStart(2, "0")}`).replace(/[\u0080-\u009f\u061c\u200e\u200f\u2028\u2029\u202a-\u202e\u2066-\u2069\ufeff]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
84948
+ }
84949
+ function formatAgyWorkspaceListing(workdir, maxEntries = AGY_ADVISORY_LISTING_MAX_ENTRIES, maxBytes = AGY_ADVISORY_LISTING_MAX_BYTES) {
84950
+ try {
84951
+ if (!fs59.existsSync(workdir))
84952
+ return "Folder listing unavailable (directory does not exist)";
84953
+ if (!fs59.statSync(workdir).isDirectory())
84954
+ return "Folder listing unavailable (not a directory)";
84955
+ if (maxBytes <= 0 || maxEntries <= 0)
84956
+ return "Folder listing (listing omitted \u2014 prompt budget exhausted)";
84957
+ let entries = [], skippedTopLevel = [], totalBytes = 0, truncated = !1, hasUnreadableDirs = !1, queue = [""];
84958
+ for (; queue.length > 0 && !truncated; ) {
84959
+ let relDir = queue.shift(), absDir = relDir === "" ? workdir : path79.join(workdir, relDir), dir;
84960
+ try {
84961
+ dir = fs59.opendirSync(absDir);
84962
+ } catch (err) {
84963
+ if (relDir === "")
84964
+ return `Folder listing unavailable (directory unreadable: ${err?.code || (err instanceof Error ? err.message : String(err))})`;
84965
+ hasUnreadableDirs = !0;
84966
+ continue;
84967
+ }
84968
+ let dirEntries = [], dirScanLimit = maxEntries * 2;
84969
+ try {
84970
+ let entry5;
84971
+ for (; (entry5 = dir.readSync()) !== null; )
84972
+ if (dirEntries.push(entry5), dirEntries.length > dirScanLimit) {
84973
+ truncated = !0;
84974
+ break;
84975
+ }
84976
+ } catch (err) {
84977
+ if (relDir === "" && dirEntries.length === 0)
84978
+ return `Folder listing unavailable (directory unreadable: ${err?.code || (err instanceof Error ? err.message : String(err))})`;
84979
+ hasUnreadableDirs = !0;
84980
+ } finally {
84981
+ try {
84982
+ dir.closeSync();
84983
+ } catch {
84984
+ }
84985
+ }
84986
+ dirEntries.sort((a, b) => a.name.localeCompare(b.name));
84987
+ for (let entry5 of dirEntries) {
84988
+ let isDir = entry5.isDirectory(), isSymlinkToDir = !1;
84989
+ if (!isDir && entry5.isSymbolicLink())
84990
+ try {
84991
+ fs59.statSync(path79.join(absDir, entry5.name)).isDirectory() && (isSymlinkToDir = !0, isDir = !0);
84992
+ } catch {
84993
+ }
84994
+ if (entry5.name === ".git") {
84995
+ relDir === "" && skippedTopLevel.push(isDir ? ".git/" : ".git");
84996
+ continue;
84997
+ }
84998
+ if (isDir && AGY_ADVISORY_IGNORED_DIRS.has(entry5.name)) {
84999
+ relDir === "" && skippedTopLevel.push(`${entry5.name}/`);
85000
+ continue;
85001
+ }
85002
+ let rawRelPath = relDir === "" ? entry5.name : `${relDir}/${entry5.name}`, sanitizedRel = sanitizeListingPath(rawRelPath);
85003
+ if (entry5.isDirectory()) {
85004
+ let entryStr = `${sanitizedRel}/`, entryBytes = Buffer.byteLength(entryStr, "utf8") + 1;
85005
+ if (entries.length >= maxEntries || totalBytes + entryBytes > maxBytes) {
85006
+ truncated = !0;
85007
+ break;
85008
+ }
85009
+ entries.push(entryStr), totalBytes += entryBytes, queue.push(rawRelPath);
85010
+ } else if (isSymlinkToDir) {
85011
+ let entryStr = `${sanitizedRel}/`, entryBytes = Buffer.byteLength(entryStr, "utf8") + 1;
85012
+ if (entries.length >= maxEntries || totalBytes + entryBytes > maxBytes) {
85013
+ truncated = !0;
85014
+ break;
85015
+ }
85016
+ entries.push(entryStr), totalBytes += entryBytes;
85017
+ } else {
85018
+ let entryStr = sanitizedRel, entryBytes = Buffer.byteLength(entryStr, "utf8") + 1;
85019
+ if (entries.length >= maxEntries || totalBytes + entryBytes > maxBytes) {
85020
+ truncated = !0;
85021
+ break;
85022
+ }
85023
+ entries.push(entryStr), totalBytes += entryBytes;
85024
+ }
85025
+ }
85026
+ }
85027
+ if (entries.length === 0)
85028
+ return truncated ? "Folder listing (listing omitted \u2014 prompt budget exhausted)" : hasUnreadableDirs ? "Folder listing unavailable (directory unreadable)" : skippedTopLevel.length > 0 ? `Folder listing (0 entries listed, complete; not listed: ${skippedTopLevel.join(", ")}):
85029
+ (no other files found)` : `Folder listing (0 entries, complete):
85030
+ (no files found)`;
85031
+ let status = truncated ? "truncated" : hasUnreadableDirs ? "partial, some subdirectories unreadable" : "complete", notListedPart = skippedTopLevel.length > 0 ? `; not listed: ${skippedTopLevel.join(", ")}` : "";
85032
+ return `${`Folder listing (${entries.length} entries, ${status}${notListedPart}):`}
85033
+ ${entries.join(`
85034
+ `)}`;
85035
+ } catch (err) {
85036
+ return `Folder listing unavailable (${err?.code || (err instanceof Error ? err.message : String(err))})`;
85037
+ }
85038
+ }
85039
+ function agyReadOnlyWorkdirPreamble(workdir, listing) {
85040
+ let parts = [
84905
85041
  `You are reading the directory \`${workdir}\` (added to your workspace via --add-dir).`,
84906
85042
  `Use absolute paths under \`${workdir}\` when you reference files.`,
84907
85043
  "Do NOT use a relative 'current directory' \u2014 your process cwd is NOT the workspace.",
84908
- "This is read-only advisory work: do not create, edit, delete, or move files.",
84909
- ""
84910
- ].join(`
85044
+ "This is read-only advisory work: do not create, edit, delete, or move files."
85045
+ ];
85046
+ return listing !== void 0 && listing.length > 0 && parts.push(
85047
+ AGY_COMMAND_TOOL_SEATBELT_WARNING,
85048
+ "",
85049
+ listing
85050
+ ), parts.push(""), parts.join(`
84911
85051
  `);
84912
85052
  }
84913
85053
  function readOnlyAgentPrompt(args) {
@@ -84928,8 +85068,17 @@ function readOnlyAgentPrompt(args) {
84928
85068
  args.advisoryBrief || args.intent.promptForPlanning || args.intent.rawMention,
84929
85069
  ""
84930
85070
  ].join(`
84931
- `);
84932
- return args.agent === "ANTIGRAVITY" && args.allowRepositoryTools ? `${agyReadOnlyWorkdirPreamble(args.workingDir)}${body}` : body;
85071
+ `), fullPrompt;
85072
+ if (args.agent === "ANTIGRAVITY" && args.allowRepositoryTools) {
85073
+ let basePreamble = agyReadOnlyWorkdirPreamble(args.workingDir), bodyBytes = Buffer.byteLength(body, "utf8"), basePreambleBytes = Buffer.byteLength(basePreamble, "utf8"), instructionPreambleText = `${AGY_COMMAND_TOOL_SEATBELT_WARNING}
85074
+
85075
+ `, instructionBytes = Buffer.byteLength(instructionPreambleText, "utf8"), totalScaffoldBytes = bodyBytes + basePreambleBytes + instructionBytes + 128 + 512, availableListingBytes = Math.max(0, 122880 - totalScaffoldBytes), maxListingBytes = Math.min(AGY_ADVISORY_LISTING_MAX_BYTES, availableListingBytes), listing;
85076
+ args.folderListing !== void 0 ? (listing = args.folderListing, Buffer.byteLength(listing, "utf8") > availableListingBytes && (listing = "Folder listing (listing omitted \u2014 prompt budget exhausted)")) : maxListingBytes >= 64 ? listing = formatAgyWorkspaceListing(args.workingDir, AGY_ADVISORY_LISTING_MAX_ENTRIES, maxListingBytes) : listing = "Folder listing (listing omitted \u2014 prompt budget exhausted)";
85077
+ let candidatePrompt = `${agyReadOnlyWorkdirPreamble(args.workingDir, listing)}${body}`;
85078
+ Buffer.byteLength(candidatePrompt, "utf8") <= 122880 ? fullPrompt = candidatePrompt : fullPrompt = `${basePreamble}${body}`;
85079
+ } else
85080
+ fullPrompt = body;
85081
+ return fullPrompt;
84933
85082
  }
84934
85083
  function readOnlyAdvisoryAllowsRepositoryTools(_input) {
84935
85084
  return !0;
@@ -89300,14 +89449,14 @@ var OllamaGemmaRunner = class {
89300
89449
  };
89301
89450
 
89302
89451
  // src/orchestration-shell/cli.ts
89303
- var import_uuid18 = require("uuid"), fs66 = __toESM(require("fs"));
89452
+ var import_uuid18 = require("uuid"), fs67 = __toESM(require("fs"));
89304
89453
 
89305
89454
  // src/orchestration-shell/doctor-cli.ts
89306
- var fs60 = __toESM(require("fs")), path80 = __toESM(require("path")), crypto32 = __toESM(require("crypto")), import_child_process7 = require("child_process");
89455
+ var fs61 = __toESM(require("fs")), path80 = __toESM(require("path")), crypto32 = __toESM(require("crypto")), import_child_process7 = require("child_process");
89307
89456
  init_detect_agents();
89308
89457
 
89309
89458
  // src/auth/auth-service.ts
89310
- var crypto31 = __toESM(require("crypto")), fs59 = __toESM(require("fs")), http3 = __toESM(require("http")), import_child_process6 = require("child_process");
89459
+ var crypto31 = __toESM(require("crypto")), fs60 = __toESM(require("fs")), http3 = __toESM(require("http")), import_child_process6 = require("child_process");
89311
89460
  init_env_scrub();
89312
89461
  init_logger2();
89313
89462
  init_auth_telemetry();
@@ -89389,7 +89538,7 @@ var AuthService = class _AuthService {
89389
89538
  isRunningInWSL() {
89390
89539
  if (process.platform !== "linux") return !1;
89391
89540
  try {
89392
- let osRelease = fs59.readFileSync("/proc/sys/kernel/osrelease", "utf8");
89541
+ let osRelease = fs60.readFileSync("/proc/sys/kernel/osrelease", "utf8");
89393
89542
  return /microsoft|wsl/i.test(osRelease);
89394
89543
  } catch {
89395
89544
  return !1;
@@ -89883,9 +90032,9 @@ var colors = {
89883
90032
  function probeAgentClis(env = process.env) {
89884
90033
  return AGENT_SPECS.map(({ agent, command, name }) => {
89885
90034
  let binPath;
89886
- if (agent === "ANTIGRAVITY" && env.AGY_PATH && fs60.existsSync(env.AGY_PATH))
90035
+ if (agent === "ANTIGRAVITY" && env.AGY_PATH && fs61.existsSync(env.AGY_PATH))
89887
90036
  try {
89888
- fs60.statSync(env.AGY_PATH).isFile() && (binPath = env.AGY_PATH);
90037
+ fs61.statSync(env.AGY_PATH).isFile() && (binPath = env.AGY_PATH);
89889
90038
  } catch {
89890
90039
  binPath = void 0;
89891
90040
  }
@@ -90013,19 +90162,19 @@ async function probeBackendConnectivity(appsyncUrl) {
90013
90162
  function readBoundedUtf8File(filePath, maxBytes) {
90014
90163
  let fd;
90015
90164
  try {
90016
- let stat14 = fs60.statSync(filePath);
90165
+ let stat14 = fs61.statSync(filePath);
90017
90166
  if (!stat14.isFile()) return { ok: !1, error: "not a regular file" };
90018
90167
  if (stat14.size > maxBytes) return { ok: !1, error: `file exceeds ${maxBytes} byte limit (${stat14.size} bytes)` };
90019
90168
  if (stat14.size === 0) return { ok: !1, error: "empty file (0 bytes)" };
90020
- fd = fs60.openSync(filePath, "r");
90021
- let buf = Buffer.alloc(stat14.size), bytesRead = fs60.readSync(fd, buf, 0, stat14.size, 0);
90169
+ fd = fs61.openSync(filePath, "r");
90170
+ let buf = Buffer.alloc(stat14.size), bytesRead = fs61.readSync(fd, buf, 0, stat14.size, 0);
90022
90171
  return { ok: !0, content: buf.subarray(0, bytesRead).toString("utf8") };
90023
90172
  } catch (err) {
90024
90173
  return { ok: !1, error: err.message };
90025
90174
  } finally {
90026
90175
  if (fd !== void 0)
90027
90176
  try {
90028
- fs60.closeSync(fd);
90177
+ fs61.closeSync(fd);
90029
90178
  } catch {
90030
90179
  }
90031
90180
  }
@@ -90151,8 +90300,8 @@ async function probeOrphanStatus(stateRoot, ownerRootOverride, shadowRootOverrid
90151
90300
  scanErrors.push(`Exposure retention ${record2.marker.taskId}: ${err.message}`);
90152
90301
  }
90153
90302
  let ownerRoot = ownerRootOverride ?? resolveOwnerRoot({}, stateRoot), deadProcessOwnersCount = 0;
90154
- if (fs60.existsSync(ownerRoot)) {
90155
- let entries = fs60.readdirSync(ownerRoot, { withFileTypes: !0 });
90303
+ if (fs61.existsSync(ownerRoot)) {
90304
+ let entries = fs61.readdirSync(ownerRoot, { withFileTypes: !0 });
90156
90305
  for (let entry5 of entries) {
90157
90306
  if (!entry5.isFile() || !/^owner-[0-9a-f-]{36}\.json$/i.test(entry5.name)) continue;
90158
90307
  let readResult = readBoundedUtf8File(path80.join(ownerRoot, entry5.name), 4096);
@@ -90210,7 +90359,7 @@ function shadowStateRoot() {
90210
90359
  function readRegistry(stateRoot) {
90211
90360
  let file = path80.join(stateRoot, SHADOW_ROOT_REGISTRY_FILE), raw;
90212
90361
  try {
90213
- raw = fs60.readFileSync(file, "utf8");
90362
+ raw = fs61.readFileSync(file, "utf8");
90214
90363
  } catch {
90215
90364
  return null;
90216
90365
  }
@@ -90222,7 +90371,7 @@ function readRegistry(stateRoot) {
90222
90371
  function collectMarkers(stateRoot) {
90223
90372
  let index = /* @__PURE__ */ new Map(), taskDirs;
90224
90373
  try {
90225
- taskDirs = fs60.readdirSync(stateRoot, { withFileTypes: !0 });
90374
+ taskDirs = fs61.readdirSync(stateRoot, { withFileTypes: !0 });
90226
90375
  } catch {
90227
90376
  return index;
90228
90377
  }
@@ -90230,7 +90379,7 @@ function collectMarkers(stateRoot) {
90230
90379
  if (!taskDir.isDirectory() || taskDir.name.startsWith(".")) continue;
90231
90380
  let dir = path80.join(stateRoot, taskDir.name), files;
90232
90381
  try {
90233
- files = fs60.readdirSync(dir);
90382
+ files = fs61.readdirSync(dir);
90234
90383
  } catch {
90235
90384
  continue;
90236
90385
  }
@@ -90238,8 +90387,8 @@ function collectMarkers(stateRoot) {
90238
90387
  if (!SHADOW_STATE_FILE_RE.test(name) && !SHADOW_EXPOSURE_RETENTION_FILE_RE.test(name)) continue;
90239
90388
  let file = path80.join(dir, name), marker;
90240
90389
  try {
90241
- if (fs60.statSync(file).size > MAX_STATE_MARKER_BYTES) continue;
90242
- marker = JSON.parse(fs60.readFileSync(file, "utf8"));
90390
+ if (fs61.statSync(file).size > MAX_STATE_MARKER_BYTES) continue;
90391
+ marker = JSON.parse(fs61.readFileSync(file, "utf8"));
90243
90392
  } catch {
90244
90393
  continue;
90245
90394
  }
@@ -90255,19 +90404,19 @@ function inodeSurvivesInParent(root) {
90255
90404
  if (!root.ino) return;
90256
90405
  let parent = path80.dirname(root.path);
90257
90406
  try {
90258
- fs60.lstatSync(parent);
90407
+ fs61.lstatSync(parent);
90259
90408
  } catch (err) {
90260
90409
  return err.code === "ENOENT" ? !1 : void 0;
90261
90410
  }
90262
90411
  let entries;
90263
90412
  try {
90264
- entries = fs60.readdirSync(parent);
90413
+ entries = fs61.readdirSync(parent);
90265
90414
  } catch {
90266
90415
  return;
90267
90416
  }
90268
90417
  for (let name of entries)
90269
90418
  try {
90270
- if (fs60.lstatSync(path80.join(parent, name), { bigint: !0 }).ino.toString() === root.ino) return !0;
90419
+ if (fs61.lstatSync(path80.join(parent, name), { bigint: !0 }).ino.toString() === root.ino) return !0;
90271
90420
  } catch {
90272
90421
  continue;
90273
90422
  }
@@ -90278,7 +90427,7 @@ function diagnose(stateRoot, roots) {
90278
90427
  return roots.map((root) => {
90279
90428
  let markers = markerIndex.get(root.path) ?? [], present = !1;
90280
90429
  try {
90281
- present = fs60.lstatSync(root.path).isDirectory();
90430
+ present = fs61.lstatSync(root.path).isDirectory();
90282
90431
  } catch {
90283
90432
  present = !1;
90284
90433
  }
@@ -90436,29 +90585,29 @@ ${colors.red}\u2717${colors.reset} ${withheld.length} entr${withheld.length ===
90436
90585
  Nothing was written. Re-run with ${colors.bold}--yes${colors.reset} to apply${withheld.length ? " the entries listed first" : ""}.`), 0;
90437
90586
  let locks = path80.join(stateRoot, SHADOW_QUOTA_LOCK_DIR), held = [];
90438
90587
  try {
90439
- held = fs60.readdirSync(locks);
90588
+ held = fs61.readdirSync(locks);
90440
90589
  } catch {
90441
90590
  held = [];
90442
90591
  }
90443
90592
  if (held.length)
90444
90593
  return console.error(`${colors.red}\u2717${colors.reset} A CodeVibe session is registering a root right now. Try again once it is idle.`), 1;
90445
- let file = path80.join(stateRoot, SHADOW_ROOT_REGISTRY_FILE), current = fs60.readFileSync(file, "utf8");
90594
+ let file = path80.join(stateRoot, SHADOW_ROOT_REGISTRY_FILE), current = fs61.readFileSync(file, "utf8");
90446
90595
  if (crypto32.createHash("sha256").update(current).digest("hex") !== crypto32.createHash("sha256").update(registry.raw).digest("hex"))
90447
90596
  return console.error(`${colors.red}\u2717${colors.reset} The registry changed while this ran. Nothing was written; re-run.`), 1;
90448
90597
  let stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-"), backupDir = path80.join(path80.dirname(stateRoot), "shadow-root-backups", stamp), backup = path80.join(backupDir, "shadow-roots.json");
90449
90598
  try {
90450
- fs60.mkdirSync(backupDir, { recursive: !0, mode: 448 }), fs60.copyFileSync(file, backup);
90599
+ fs61.mkdirSync(backupDir, { recursive: !0, mode: 448 }), fs61.copyFileSync(file, backup);
90451
90600
  } catch (err) {
90452
90601
  return console.error(`${colors.red}\u2717${colors.reset} Could not write the backup at ${backupDir} (${err.code ?? "unknown error"}). Nothing was changed \u2014 this command will not clear an entry it cannot restore.`), 1;
90453
90602
  }
90454
90603
  let removed = new Set(clearable.map((d) => d.root.path)), kept = registry.roots.filter((r) => !removed.has(r.path)), tmp = path80.join(backupDir, `.registry.next.${process.pid}`);
90455
90604
  try {
90456
- fs60.writeFileSync(tmp, JSON.stringify({ version: 2, roots: kept }), { mode: 384 }), fs60.renameSync(tmp, file);
90605
+ fs61.writeFileSync(tmp, JSON.stringify({ version: 2, roots: kept }), { mode: 384 }), fs61.renameSync(tmp, file);
90457
90606
  } catch (err) {
90458
90607
  return console.error(`${colors.red}\u2717${colors.reset} Could not replace the registry (${err.code ?? "unknown error"}). Nothing was changed; a copy of it is at ${backup}.`), 1;
90459
90608
  } finally {
90460
90609
  try {
90461
- fs60.unlinkSync(tmp);
90610
+ fs61.unlinkSync(tmp);
90462
90611
  } catch {
90463
90612
  }
90464
90613
  }
@@ -90467,7 +90616,7 @@ ${colors.red}\u2717${colors.reset} ${withheld.length} entr${withheld.length ===
90467
90616
  for (let marker of d.markers) {
90468
90617
  let copy = path80.join(backupDir, `marker-${savedMarkers.length}-${path80.basename(marker)}`);
90469
90618
  try {
90470
- fs60.copyFileSync(marker, copy), savedMarkers.push({ copy: path80.basename(copy), original: marker });
90619
+ fs61.copyFileSync(marker, copy), savedMarkers.push({ copy: path80.basename(copy), original: marker });
90471
90620
  } catch (err) {
90472
90621
  if (err.code !== "ENOENT") {
90473
90622
  unbackedMarkers.push(marker);
@@ -90475,16 +90624,16 @@ ${colors.red}\u2717${colors.reset} ${withheld.length} entr${withheld.length ===
90475
90624
  }
90476
90625
  }
90477
90626
  try {
90478
- fs60.unlinkSync(marker);
90627
+ fs61.unlinkSync(marker);
90479
90628
  } catch {
90480
90629
  }
90481
90630
  try {
90482
- fs60.rmdirSync(path80.dirname(marker));
90631
+ fs61.rmdirSync(path80.dirname(marker));
90483
90632
  } catch {
90484
90633
  }
90485
90634
  }
90486
90635
  try {
90487
- fs60.writeFileSync(path80.join(backupDir, "manifest.json"), `${JSON.stringify({
90636
+ fs61.writeFileSync(path80.join(backupDir, "manifest.json"), `${JSON.stringify({
90488
90637
  clearedAtUtc: (/* @__PURE__ */ new Date()).toISOString(),
90489
90638
  registry: file,
90490
90639
  registryBackup: path80.basename(backup),
@@ -90504,7 +90653,7 @@ ${colors.green}\u2713${colors.reset} Cleared ${clearable.length} entr${clearable
90504
90653
  }
90505
90654
 
90506
90655
  // src/substrate-launch/engage-substrate.ts
90507
- var import_node_fs38 = require("node:fs"), os49 = __toESM(require("node:os")), path81 = __toESM(require("node:path"));
90656
+ var import_node_fs38 = require("node:fs"), os49 = __toESM(require("node:os")), path81 = __toESM(require("node:path")), crypto33 = __toESM(require("node:crypto"));
90508
90657
 
90509
90658
  // src/credential-broker/types.ts
90510
90659
  var BROKER_ROUTES = [
@@ -92795,8 +92944,7 @@ async function engageSubstrate(input) {
92795
92944
  }
92796
92945
  }
92797
92946
  var RESOLVER_AGENT_STATE_DIR_SEGMENTS = {
92798
- GEMINI: [".gemini"],
92799
- ANTIGRAVITY: [".gemini"]
92947
+ GEMINI: [".gemini"]
92800
92948
  };
92801
92949
  async function engageWriteConfinedResolverSandbox(input) {
92802
92950
  let agentKind = input.agentKind;
@@ -92821,36 +92969,94 @@ async function engageWriteConfinedResolverSandbox(input) {
92821
92969
  teardown: async () => {
92822
92970
  }
92823
92971
  };
92824
- let homedir41 = os49.homedir(), stateDir = path81.join(
92825
- homedir41,
92826
- ...RESOLVER_AGENT_STATE_DIR_SEGMENTS[agentKind]
92827
- );
92828
- await import_node_fs38.promises.mkdir(stateDir, { recursive: !0 }).catch(() => {
92829
- });
92830
- let env = {}, nodeDir = process.execPath.slice(0, process.execPath.lastIndexOf("/"));
92831
- env.PATH = `${SANDBOX_DEFAULT_PATH}:${nodeDir}`, env.HOME = homedir41;
92832
- let safeSource = input.localeSource ?? {};
92833
- for (let key of SAFE_ENV_ALLOWLIST) {
92834
- let v = safeSource[key];
92835
- typeof v == "string" && v.length > 0 && (env[key] = v);
92972
+ let homedir41 = input.homedir ?? os49.homedir(), stateDir, privateHomeDir = null, spawnParentDir = null, spawnParentDirCreated = !1, env = {}, handle, finalEnv;
92973
+ if (agentKind === "ANTIGRAVITY") {
92974
+ let spawnId = input.spawnId ?? crypto33.randomUUID().slice(0, 8), taskSegment = input.taskId || "advisory";
92975
+ if (process.platform === "darwin")
92976
+ input.taskId ? (spawnParentDir = path81.join(homedir41, "Library", "Caches", "CodeVibe", "shadows", taskSegment, "agy-home", spawnId), privateHomeDir = spawnParentDir) : (spawnParentDir = path81.join(homedir41, "Library", "Caches", "CodeVibe", "shadows", `advisory-${spawnId}`), privateHomeDir = path81.join(spawnParentDir, "agy-home"));
92977
+ else {
92978
+ let cacheBase = process.env.XDG_CACHE_HOME || path81.join(homedir41, ".cache");
92979
+ input.taskId ? (spawnParentDir = path81.join(cacheBase, "codevibe", "shadows", taskSegment, "spawn", spawnId), privateHomeDir = path81.join(spawnParentDir, "home")) : (spawnParentDir = path81.join(cacheBase, "codevibe", "shadows", `advisory-${spawnId}`), privateHomeDir = path81.join(spawnParentDir, "home"));
92980
+ }
92981
+ stateDir = privateHomeDir, await import_node_fs38.promises.mkdir(path81.dirname(spawnParentDir), { recursive: !0 }), await import_node_fs38.promises.mkdir(spawnParentDir), spawnParentDirCreated = !0;
92982
+ try {
92983
+ let agyCliDir = path81.join(privateHomeDir, ".gemini", "antigravity-cli");
92984
+ await import_node_fs38.promises.mkdir(agyCliDir, { recursive: !0 });
92985
+ let hostAgyDir = path81.join(homedir41, ".gemini", "antigravity-cli"), tokenFile = path81.join(hostAgyDir, "antigravity-oauth-token"), idFile = path81.join(hostAgyDir, "installation_id");
92986
+ try {
92987
+ await import_node_fs38.promises.copyFile(tokenFile, path81.join(agyCliDir, "antigravity-oauth-token")), await import_node_fs38.promises.chmod(path81.join(agyCliDir, "antigravity-oauth-token"), 384);
92988
+ } catch {
92989
+ }
92990
+ try {
92991
+ await import_node_fs38.promises.copyFile(idFile, path81.join(agyCliDir, "installation_id")), await import_node_fs38.promises.chmod(path81.join(agyCliDir, "installation_id"), 384);
92992
+ } catch {
92993
+ }
92994
+ env.HOME = privateHomeDir;
92995
+ let nodeDir = process.execPath.slice(0, process.execPath.lastIndexOf("/"));
92996
+ env.PATH = `${SANDBOX_DEFAULT_PATH}:${nodeDir}`;
92997
+ let safeSource = input.localeSource ?? {};
92998
+ for (let key of SAFE_ENV_ALLOWLIST) {
92999
+ let v = safeSource[key];
93000
+ typeof v == "string" && v.length > 0 && (env[key] = v);
93001
+ }
93002
+ assertNoAmbientCreds(env), finalEnv = buildSubstrateImplementorEnv(input.role, env, input.processTreeId);
93003
+ let spec = {
93004
+ isolationTech: "sandbox_exec",
93005
+ workdir: input.workdir,
93006
+ ...input.workdirAuthority ? { workdirAuthority: input.workdirAuthority } : {},
93007
+ hostBrokerAddr: "",
93008
+ sandboxBrokerUrl: "",
93009
+ taskId: input.taskId,
93010
+ sanitizedEnv: finalEnv,
93011
+ agentConfig: { hostDir: stateDir, sandboxDir: stateDir },
93012
+ networkPosture: "open",
93013
+ writableWorkdir: input.writableWorkdir !== !1
93014
+ };
93015
+ handle = await selection.substrate.launch(spec);
93016
+ } catch (launchErr) {
93017
+ let rollbackErrors = [];
93018
+ if (spawnParentDirCreated && spawnParentDir !== null)
93019
+ try {
93020
+ await import_node_fs38.promises.rm(spawnParentDir, { recursive: !0, force: !0 });
93021
+ } catch (rmErr) {
93022
+ rollbackErrors.push(rmErr);
93023
+ }
93024
+ if (rollbackErrors.length > 0) {
93025
+ let combinedError = new Error(
93026
+ `engageSubstrate initialization or launch failed and rollback failed: ${launchErr instanceof Error ? launchErr.message : String(launchErr)} (rollback: ${rollbackErrors.map((e) => e instanceof Error ? e.message : String(e)).join("; ")})`
93027
+ );
93028
+ throw combinedError.cause = launchErr, combinedError;
93029
+ }
93030
+ throw launchErr;
93031
+ }
93032
+ } else {
93033
+ stateDir = path81.join(
93034
+ homedir41,
93035
+ ...RESOLVER_AGENT_STATE_DIR_SEGMENTS[agentKind]
93036
+ ), await import_node_fs38.promises.mkdir(stateDir, { recursive: !0 }).catch(() => {
93037
+ }), env.HOME = homedir41;
93038
+ let nodeDir = process.execPath.slice(0, process.execPath.lastIndexOf("/"));
93039
+ env.PATH = `${SANDBOX_DEFAULT_PATH}:${nodeDir}`;
93040
+ let safeSource = input.localeSource ?? {};
93041
+ for (let key of SAFE_ENV_ALLOWLIST) {
93042
+ let v = safeSource[key];
93043
+ typeof v == "string" && v.length > 0 && (env[key] = v);
93044
+ }
93045
+ assertNoAmbientCreds(env), finalEnv = buildSubstrateImplementorEnv(input.role, env, input.processTreeId);
93046
+ let spec = {
93047
+ isolationTech: "sandbox_exec",
93048
+ workdir: input.workdir,
93049
+ ...input.workdirAuthority ? { workdirAuthority: input.workdirAuthority } : {},
93050
+ hostBrokerAddr: "",
93051
+ sandboxBrokerUrl: "",
93052
+ taskId: input.taskId,
93053
+ sanitizedEnv: finalEnv,
93054
+ agentConfig: { hostDir: stateDir, sandboxDir: stateDir },
93055
+ networkPosture: "open",
93056
+ writableWorkdir: input.writableWorkdir !== !1
93057
+ };
93058
+ handle = await selection.substrate.launch(spec);
92836
93059
  }
92837
- assertNoAmbientCreds(env);
92838
- let finalEnv = buildSubstrateImplementorEnv(input.role, env, input.processTreeId), spec = {
92839
- isolationTech: "sandbox_exec",
92840
- workdir: input.workdir,
92841
- ...input.workdirAuthority ? { workdirAuthority: input.workdirAuthority } : {},
92842
- // No broker on this row — the addr/url fields are informational for A5
92843
- // (the profile, not these strings, governs egress) and deliberately empty.
92844
- hostBrokerAddr: "",
92845
- sandboxBrokerUrl: "",
92846
- taskId: input.taskId,
92847
- sanitizedEnv: finalEnv,
92848
- // The agent's own auth/state home — writable, read-granted (A5: sandbox fs
92849
- // == host fs, so sandboxDir == hostDir).
92850
- agentConfig: { hostDir: stateDir, sandboxDir: stateDir },
92851
- networkPosture: "open",
92852
- writableWorkdir: input.writableWorkdir !== !1
92853
- }, handle = await selection.substrate.launch(spec);
92854
93060
  return logger.info(
92855
93061
  `[A1d] Resolver-confinement row engaged (tier=sandbox_exec, egress=open) \u2014 writes fenced to the disposable workspace; ${agentKind} runs on its own file-based auth (no broker)`,
92856
93062
  { taskId: input.taskId, agent: agentKind }
@@ -92868,8 +93074,18 @@ async function engageWriteConfinedResolverSandbox(input) {
92868
93074
  refreshBrokerToken: async () => {
92869
93075
  },
92870
93076
  teardown: async () => {
92871
- await handle.teardown().catch(() => {
92872
- });
93077
+ try {
93078
+ await handle.teardown();
93079
+ } catch (err) {
93080
+ throw logger.warn(
93081
+ "[engageSubstrate] resolver sandbox handle teardown failed, retaining state for recovery",
93082
+ {
93083
+ err,
93084
+ spawnParentDir
93085
+ }
93086
+ ), err;
93087
+ }
93088
+ spawnParentDirCreated && spawnParentDir !== null && await import_node_fs38.promises.rm(spawnParentDir, { recursive: !0, force: !0 });
92873
93089
  }
92874
93090
  };
92875
93091
  }
@@ -94760,7 +94976,7 @@ Note: --export will overwrite any existing file at <path>.
94760
94976
  offset: parsed.offset
94761
94977
  });
94762
94978
  if (result.kind === "ok" && parsed.exportPath) {
94763
- let writeFile4 = deps?.writeFileFn ?? ((p, c) => fs66.writeFileSync(p, c, "utf8"));
94979
+ let writeFile4 = deps?.writeFileFn ?? ((p, c) => fs67.writeFileSync(p, c, "utf8"));
94764
94980
  try {
94765
94981
  let formatted = formatAuditExport(
94766
94982
  result.model,