@staix/agent-hub 0.44.0 → 0.45.0

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.
Files changed (100) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +3 -8
  3. package/docs/agent-notes/adapters.md +2 -2
  4. package/docs/agent-notes/daemon.md +1 -1
  5. package/docs/agent-notes/local-worker.md +1 -1
  6. package/docs/agent-notes/security-review.md +1 -1
  7. package/docs/agent-notes/tasks.md +3 -1
  8. package/docs/agent-notes/tests.md +3 -2
  9. package/docs/design/adapters.md +4 -2
  10. package/docs/design/agent-hub.md +1 -1
  11. package/docs/design/roadmap.md +75 -2
  12. package/docs/design/supervision.md +21 -1
  13. package/docs/design/task-board.md +30 -2
  14. package/docs/dogfood.md +13 -4
  15. package/docs/events.md +5 -1
  16. package/docs/influences.md +7 -0
  17. package/docs/memory.md +4 -4
  18. package/docs/operations.md +51 -18
  19. package/docs/quickstart.md +8 -2
  20. package/docs/research.md +16 -0
  21. package/docs/roadmap.json +4 -0
  22. package/docs/roadmap.md +9 -0
  23. package/docs/sdlc.md +15 -3
  24. package/docs/security.md +3 -3
  25. package/docs/verification/2026-11-19-claude-implementer-2.1.328.md +49 -0
  26. package/docs/verification/2026-11-20-claude-implementer-2.1.329.md +49 -0
  27. package/docs/verification/2026-11-20-sdlc-metrics-diagnosis.md +7 -0
  28. package/docs/verification/2026-11-21-0.45.0.md +69 -0
  29. package/docs/verification/2026-11-22-codex-0171-reviewer-isolation.md +47 -0
  30. package/docs/verified.json +32 -26
  31. package/package.json +2 -2
  32. package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
  33. package/plugins/agent-hub/kimi-hook.js +472 -229
  34. package/plugins/agent-hub/kimi-review-policy-worker.js +5 -5
  35. package/plugins/agent-hub/server.js +513 -258
  36. package/scripts/check-docs.mjs +9 -1
  37. package/src/adapters/acp.ts +11 -1
  38. package/src/adapters/compat.ts +3 -3
  39. package/src/adapters/definitions/builtin-metadata.ts +2 -2
  40. package/src/adapters/definitions/native-context.ts +10 -0
  41. package/src/adapters/jcode.ts +10 -0
  42. package/src/adapters/local-worker.ts +3 -2
  43. package/src/adapters/pi.ts +15 -4
  44. package/src/cli/console-state.ts +3 -1
  45. package/src/cli/help.ts +3 -1
  46. package/src/cli/identity.ts +2 -1
  47. package/src/cli/main.ts +11 -5
  48. package/src/cli/recovery-package.ts +16 -3
  49. package/src/cli/roadmap-write.ts +59 -0
  50. package/src/cli/roadmap.ts +81 -4
  51. package/src/cli/sdlc-output.ts +4 -0
  52. package/src/cli/upgrade-runtime.ts +10 -6
  53. package/src/hub/agent-mem-range.ts +43 -0
  54. package/src/hub/board.ts +102 -1
  55. package/src/hub/check-runner.ts +25 -1
  56. package/src/hub/config-apply.ts +4 -2
  57. package/src/hub/config-trust.ts +1 -1
  58. package/src/hub/context-window.ts +1 -1
  59. package/src/hub/cost-governance.ts +11 -7
  60. package/src/hub/daemon.ts +253 -30
  61. package/src/hub/dogfood-read.ts +4 -2
  62. package/src/hub/edit-guard.ts +100 -0
  63. package/src/hub/events.ts +79 -8
  64. package/src/hub/facts.ts +57 -4
  65. package/src/hub/hub-tools.ts +2 -0
  66. package/src/hub/lifecycle.ts +6 -1
  67. package/src/hub/log-rotation.ts +130 -0
  68. package/src/hub/memory-profile.ts +137 -21
  69. package/src/hub/no-writes.ts +1 -0
  70. package/src/hub/operational-authority.ts +3 -2
  71. package/src/hub/operational-settings.ts +2 -2
  72. package/src/hub/recovery-store.ts +49 -21
  73. package/src/hub/research-experiments.ts +132 -0
  74. package/src/hub/research-quality.ts +8 -2
  75. package/src/hub/research-record.ts +35 -0
  76. package/src/hub/research.ts +128 -28
  77. package/src/hub/roadmap-check.ts +65 -0
  78. package/src/hub/roadmap-decompose.ts +80 -0
  79. package/src/hub/roadmap-export.ts +27 -0
  80. package/src/hub/roadmap-sync.ts +97 -0
  81. package/src/hub/roadmap.ts +40 -0
  82. package/src/hub/sdlc-branch-ci.ts +128 -0
  83. package/src/hub/sdlc-merge.ts +6 -3
  84. package/src/hub/sdlc-metrics.ts +19 -5
  85. package/src/hub/sdlc.ts +73 -5
  86. package/src/hub/settings.ts +1 -0
  87. package/src/hub/snapshots.ts +13 -1
  88. package/src/hub/startup-event-seeds.ts +21 -15
  89. package/src/hub/startup-timing.ts +3 -1
  90. package/src/hub/supervision-proposals.ts +10 -2
  91. package/src/hub/supervision-rules.ts +26 -3
  92. package/src/hub/supervision.ts +7 -0
  93. package/src/hub/task-pr.ts +47 -0
  94. package/src/hub/task-worktree.ts +18 -11
  95. package/src/hub/tasks.ts +502 -34
  96. package/src/hub/usage-rollup.ts +35 -20
  97. package/src/local/tools.ts +13 -1
  98. package/src/memory/client.ts +3 -2
  99. package/src/pi/extension.ts +15 -3
  100. package/src/pi/tool-receipts.ts +26 -0
@@ -112,7 +112,7 @@ var init_envelope = __esm(() => {
112
112
  });
113
113
 
114
114
  // node_modules/@staix/agent-mem/src/memory/platform.ts
115
- import { realpathSync } from "fs";
115
+ import { lstatSync, realpathSync } from "fs";
116
116
  import { basename, dirname, join, resolve, sep } from "path";
117
117
  import { createRequire } from "module";
118
118
  import { createHash } from "crypto";
@@ -216,7 +216,7 @@ var init_git = __esm(() => {
216
216
  });
217
217
 
218
218
  // src/hub/project.ts
219
- import { existsSync, lstatSync, readFileSync } from "fs";
219
+ import { existsSync, lstatSync as lstatSync2, readFileSync } from "fs";
220
220
  import { homedir } from "os";
221
221
  import { dirname as dirname2, isAbsolute, join as join2, resolve as resolve2 } from "path";
222
222
  function gitRoot(dir) {
@@ -234,7 +234,7 @@ function projectRoot(cwd) {
234
234
  let dir;
235
235
  try {
236
236
  dir = canonicalPath(input);
237
- if (!lstatSync(dir).isDirectory())
237
+ if (!lstatSync2(dir).isDirectory())
238
238
  throw new Error(`${cwd} is not a directory`);
239
239
  } catch (error) {
240
240
  throw new Error(`cannot resolve project directory ${cwd}: ${error.message}`);
@@ -325,7 +325,7 @@ function finishPreview(ctx, launch, envNames, unresolved, metadata, settings) {
325
325
  var REDACTED = "[redacted]", UNRESOLVED = "[unresolved]";
326
326
 
327
327
  // src/adapters/compat.ts
328
- import { closeSync, constants, fstatSync, lstatSync as lstatSync2, mkdirSync, openSync, readSync, renameSync, unlinkSync, writeFileSync } from "fs";
328
+ import { closeSync, constants, fstatSync, lstatSync as lstatSync3, mkdirSync, openSync, readSync, renameSync, unlinkSync, writeFileSync } from "fs";
329
329
  import { dirname as dirname3, join as join3 } from "path";
330
330
  function inLine(version, line) {
331
331
  const v = parts(version);
@@ -393,12 +393,12 @@ var init_compat = __esm(() => {
393
393
  },
394
394
  "claude-implementer": {
395
395
  label: "Claude headless implementer",
396
- verified: ["2.1.309", "2.1.310", "2.1.314", "2.1.316", "2.1.318", "2.1.319", "2.1.322", "2.1.323"],
396
+ verified: ["2.1.309", "2.1.310", "2.1.314", "2.1.316", "2.1.318", "2.1.319", "2.1.322", "2.1.323", "2.1.328", "2.1.329"],
397
397
  gate: "contract",
398
398
  probe: ["claude", "--version"],
399
399
  parse: (out) => plain(out.trim().replace(/ \(Claude Code\)$/, "")),
400
400
  trustNote: "The native prompt-tool transport and host-wrapper rewrite, environment isolation and replay contract have isolated receipts. No dontAsk/bypass fallback exists; another version's permission or rewrite behavior is unverified.",
401
- receipt: "docs/verification/2026-11-13-claude-implementer-2.1.323.md"
401
+ receipt: "docs/verification/2026-11-20-claude-implementer-2.1.329.md"
402
402
  },
403
403
  "codex-review": {
404
404
  label: "Codex reviewer (codex-cli)",
@@ -514,7 +514,7 @@ var init_same_directory = __esm(() => {
514
514
 
515
515
  // src/cli/agy-mcp.ts
516
516
  import { randomUUID } from "crypto";
517
- import { closeSync as closeSync2, fstatSync as fstatSync2, lstatSync as lstatSync3, mkdirSync as mkdirSync2, openSync as openSync2, readFileSync as readFileSync2, renameSync as renameSync2, rmdirSync, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "fs";
517
+ import { closeSync as closeSync2, fstatSync as fstatSync2, lstatSync as lstatSync4, mkdirSync as mkdirSync2, openSync as openSync2, readFileSync as readFileSync2, renameSync as renameSync2, rmdirSync, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "fs";
518
518
  import { isAbsolute as isAbsolute2, join as join4, resolve as resolve3 } from "path";
519
519
  import { isDeepStrictEqual } from "util";
520
520
  function object(value) {
@@ -568,13 +568,13 @@ function validateOptions(options) {
568
568
  return { root, peer };
569
569
  }
570
570
  function safeDirectory(path) {
571
- const stat = lstatSync3(path, { throwIfNoEntry: false });
571
+ const stat = lstatSync4(path, { throwIfNoEntry: false });
572
572
  if (stat && (!stat.isDirectory() || stat.isSymbolicLink()))
573
573
  throw new Error(`${path} must be a project directory, not a link`);
574
574
  return stat;
575
575
  }
576
576
  function safeFile(path) {
577
- const stat = lstatSync3(path, { throwIfNoEntry: false });
577
+ const stat = lstatSync4(path, { throwIfNoEntry: false });
578
578
  if (!stat)
579
579
  return;
580
580
  if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink !== 1 || stat.size > MAX_CONFIG_BYTES)
@@ -759,7 +759,7 @@ function internalPlan(options) {
759
759
  return { file: pluginDir, tracked, changed, action: changed ? "create or update the managed agent-hub plugin" : "keep the managed agent-hub plugin", root, pluginDir, canonicalRoot, ...canonicalPluginDir ? { canonicalPluginDir } : {}, ...directories ? { directories } : {}, targets };
760
760
  }
761
761
  function identityMatches(path, before) {
762
- const now = lstatSync3(path, { throwIfNoEntry: false });
762
+ const now = lstatSync4(path, { throwIfNoEntry: false });
763
763
  return before ? !!now && now.dev === before.dev && now.ino === before.ino : !now;
764
764
  }
765
765
  function atomicWrite(path, bytes, expected, plan) {
@@ -778,7 +778,7 @@ function atomicWrite(path, bytes, expected, plan) {
778
778
  if (!identityMatches(path, expected))
779
779
  throw new Error(`${path} changed while the managed plugin was being written`);
780
780
  renameSync2(temporary, path);
781
- const stat = lstatSync3(path);
781
+ const stat = lstatSync4(path);
782
782
  if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink !== 1)
783
783
  throw new Error(`${path} changed while the managed plugin was written`);
784
784
  return { dev: stat.dev, ino: stat.ino };
@@ -786,7 +786,7 @@ function atomicWrite(path, bytes, expected, plan) {
786
786
  if (fd !== undefined)
787
787
  closeSync2(fd);
788
788
  try {
789
- const current = lstatSync3(temporary, { throwIfNoEntry: false });
789
+ const current = lstatSync4(temporary, { throwIfNoEntry: false });
790
790
  if (current && tempIdentity && current.dev === tempIdentity.dev && current.ino === tempIdentity.ino)
791
791
  unlinkSync2(temporary);
792
792
  } catch {}
@@ -795,7 +795,7 @@ function atomicWrite(path, bytes, expected, plan) {
795
795
  function rollback(plan, written, createdDirs) {
796
796
  for (const { target, own } of written.reverse()) {
797
797
  try {
798
- const now = lstatSync3(target.path, { throwIfNoEntry: false });
798
+ const now = lstatSync4(target.path, { throwIfNoEntry: false });
799
799
  if (!now || now.dev !== own.dev || now.ino !== own.ino)
800
800
  continue;
801
801
  if (target.current)
@@ -806,7 +806,7 @@ function rollback(plan, written, createdDirs) {
806
806
  }
807
807
  for (const { path, dev, ino } of createdDirs.reverse()) {
808
808
  try {
809
- const now = lstatSync3(path);
809
+ const now = lstatSync4(path);
810
810
  if (now.isDirectory() && !now.isSymbolicLink() && now.dev === dev && now.ino === ino)
811
811
  rmdirSync(path);
812
812
  } catch {}
@@ -862,7 +862,7 @@ function cleanupAgyMcp(options) {
862
862
  const deleted = [];
863
863
  try {
864
864
  for (const target of plan.targets) {
865
- const stat = lstatSync3(target.path);
865
+ const stat = lstatSync4(target.path);
866
866
  if (!target.stat || stat.dev !== target.stat.dev || stat.ino !== target.stat.ino)
867
867
  throw new Error(`${target.path} changed before agy plugin cleanup`);
868
868
  }
@@ -891,7 +891,7 @@ function cleanupAgyMcp(options) {
891
891
  } catch (error) {
892
892
  for (const item of deleted.reverse()) {
893
893
  try {
894
- const current = lstatSync3(item.path, { throwIfNoEntry: false });
894
+ const current = lstatSync4(item.path, { throwIfNoEntry: false });
895
895
  if (item.own) {
896
896
  if (current?.dev === item.own.dev && current.ino === item.own.ino)
897
897
  atomicWrite(item.path, item.bytes, current, plan);
@@ -2750,7 +2750,7 @@ var init_claude_print = __esm(() => {
2750
2750
  // src/adapters/codex-review-isolation.ts
2751
2751
  import { createHash as createHash2 } from "crypto";
2752
2752
  import { spawn as spawn3 } from "child_process";
2753
- import { existsSync as existsSync3, lstatSync as lstatSync4, mkdirSync as mkdirSync3, mkdtempSync, readFileSync as readFileSync3, rmSync, statSync, symlinkSync, writeFileSync as writeFileSync3 } from "fs";
2753
+ import { existsSync as existsSync3, lstatSync as lstatSync5, mkdirSync as mkdirSync3, mkdtempSync, readFileSync as readFileSync3, rmSync, statSync, symlinkSync, writeFileSync as writeFileSync3 } from "fs";
2754
2754
  import { createRequire as createRequire2 } from "module";
2755
2755
  import { homedir as homedir2, tmpdir } from "os";
2756
2756
  import { basename as basename2, delimiter, dirname as dirname5, isAbsolute as isAbsolute3, join as join5, relative, resolve as resolve5 } from "path";
@@ -2872,7 +2872,7 @@ function toml(value) {
2872
2872
  }
2873
2873
  function metadata(file) {
2874
2874
  try {
2875
- const link = lstatSync4(file), stat = statSync(file);
2875
+ const link = lstatSync5(file), stat = statSync(file);
2876
2876
  return [link.dev, link.ino, link.mtimeMs, stat.dev, stat.ino, stat.size, stat.mtimeMs, stat.ctimeMs].join(":");
2877
2877
  } catch (error) {
2878
2878
  if (error.code === "ENOENT")
@@ -2918,7 +2918,7 @@ function credentialCanonicalPath(lexical) {
2918
2918
  let ancestor = lexical;
2919
2919
  for (;; ) {
2920
2920
  try {
2921
- lstatSync4(ancestor);
2921
+ lstatSync5(ancestor);
2922
2922
  break;
2923
2923
  } catch (error) {
2924
2924
  if (error.code !== "ENOENT" || dirname5(ancestor) === ancestor)
@@ -3279,7 +3279,7 @@ var init_codex_review_isolation = __esm(() => {
3279
3279
  });
3280
3280
 
3281
3281
  // src/adapters/kimi-wire-usage.ts
3282
- import { closeSync as closeSync3, constants as constants2, fstatSync as fstatSync3, lstatSync as lstatSync5, openSync as openSync3, readSync as fsReadSync, readdirSync, statSync as statSync2 } from "fs";
3282
+ import { closeSync as closeSync3, constants as constants2, fstatSync as fstatSync3, lstatSync as lstatSync6, openSync as openSync3, readSync as fsReadSync, readdirSync, statSync as statSync2 } from "fs";
3283
3283
  import { createHash as createHash3 } from "crypto";
3284
3284
  import { join as join6, sep as sep2 } from "path";
3285
3285
  function kimiCountedTokens(row) {
@@ -3483,7 +3483,7 @@ class KimiWireReader {
3483
3483
  for (const name of names) {
3484
3484
  const path = join6(dir, "agents", name, "wire.jsonl");
3485
3485
  try {
3486
- lstatSync5(path);
3486
+ lstatSync6(path);
3487
3487
  } catch (error) {
3488
3488
  if (error.code === "ENOENT")
3489
3489
  continue;
@@ -3982,10 +3982,10 @@ var init_kimi_usage = __esm(() => {
3982
3982
 
3983
3983
  // src/adapters/kimi-review-policy.ts
3984
3984
  import { createHash as createHash4 } from "crypto";
3985
- import { lstatSync as lstatSync6, readFileSync as readFileSync4 } from "fs";
3985
+ import { lstatSync as lstatSync7, readFileSync as readFileSync4 } from "fs";
3986
3986
  import { dirname as dirname6, join as join7, resolve as resolve6 } from "path";
3987
3987
  function readKimiReviewFile(file, limit = 262144) {
3988
- const stat = lstatSync6(file);
3988
+ const stat = lstatSync7(file);
3989
3989
  if (!stat.isFile() || stat.size > limit)
3990
3990
  throw new Error("unsupported reviewer file");
3991
3991
  return readFileSync4(file, "utf8");
@@ -3998,7 +3998,7 @@ function assertCleanCwdAncestors(...candidates) {
3998
3998
  if (!seen.has(ancestor)) {
3999
3999
  seen.add(ancestor);
4000
4000
  for (const marker of [".git", ".kimi-code", "AGENTS.md"]) {
4001
- if (lstatSync6(join7(ancestor, marker), { throwIfNoEntry: false }) !== undefined) {
4001
+ if (lstatSync7(join7(ancestor, marker), { throwIfNoEntry: false }) !== undefined) {
4002
4002
  throw new Error("private cwd ancestor contains ambient configuration");
4003
4003
  }
4004
4004
  }
@@ -4034,7 +4034,7 @@ function projectKimiReviewPolicyBinding(binding) {
4034
4034
  function checkKimiReviewPolicy(binding) {
4035
4035
  try {
4036
4036
  assertCleanCwdAncestors(binding.lexicalCwd, binding.physicalCwd);
4037
- const now = lstatSync6(binding.executable), expected = binding.executableStat;
4037
+ const now = lstatSync7(binding.executable), expected = binding.executableStat;
4038
4038
  return realPath(binding.sourcePath) === binding.source && now.dev === expected.dev && now.ino === expected.ino && now.size === expected.size && now.mtimeMs === expected.mtimeMs && now.ctimeMs === expected.ctimeMs && kimiReviewFingerprint(readKimiReviewFile(binding.sourceConfig)) === binding.sourceConfigHash && binding.privateFiles.length === 3 && binding.privateFiles.every((file) => kimiReviewFingerprint(readKimiReviewFile(file.path, 2097152)) === file.hash) && binding.authTargets.length === 3 && ["credentials", "oauth", "device_id"].every((name, index) => realPath(join7(binding.source, name)) === binding.authTargets[index] && realPath(join7(binding.tool, name)) === binding.authTargets[index]);
4039
4039
  } catch {
4040
4040
  return false;
@@ -4174,7 +4174,7 @@ var init_kimi_review_policy_worker = __esm(() => {
4174
4174
 
4175
4175
  // src/adapters/kimi-review.ts
4176
4176
  import { spawn as spawn4 } from "child_process";
4177
- import { existsSync as existsSync4, lstatSync as lstatSync7, mkdirSync as mkdirSync4, mkdtempSync as mkdtempSync2, rmSync as rmSync2, symlinkSync as symlinkSync2, writeFileSync as writeFileSync4 } from "fs";
4177
+ import { existsSync as existsSync4, lstatSync as lstatSync8, mkdirSync as mkdirSync4, mkdtempSync as mkdtempSync2, rmSync as rmSync2, symlinkSync as symlinkSync2, writeFileSync as writeFileSync4 } from "fs";
4178
4178
  import { homedir as homedir3, tmpdir as tmpdir2 } from "os";
4179
4179
  import { basename as basename3, join as join8, resolve as resolve7 } from "path";
4180
4180
  function managedConfig(raw) {
@@ -4330,7 +4330,7 @@ async function prepareKimiReviewer(context, policyFactory = startKimiReviewPolic
4330
4330
  const sourcePath = process.env.KIMI_CODE_HOME ?? join8(process.env.HOME ?? homedir3(), ".kimi-code"), source = realPath(sourcePath);
4331
4331
  const sourceConfig = join8(source, "config.toml"), original = readKimiReviewFile(sourceConfig), selected = managedConfig(original);
4332
4332
  const sources = ["credentials", "oauth", "device_id"].map((name) => realPath(join8(source, name)));
4333
- if (!sources.every((file, index) => index < 2 ? lstatSync7(file).isDirectory() : lstatSync7(file).isFile()))
4333
+ if (!sources.every((file, index) => index < 2 ? lstatSync8(file).isDirectory() : lstatSync8(file).isFile()))
4334
4334
  throw new Error("native OAuth directories and device identity required");
4335
4335
  const mcp = mcpConfig(context);
4336
4336
  if (Buffer.byteLength(context.input ?? "") > 1048576)
@@ -4364,7 +4364,7 @@ ${context.input ?? "No review is active; startup self-check only."}
4364
4364
  const native = context.command ?? [Bun.which("kimi", { PATH: process.env.PATH }) ?? "kimi"];
4365
4365
  const executable = realPath(Bun.which(native[0], { PATH: process.env.PATH }) ?? resolve7(native[0]));
4366
4366
  const command = [executable, ...native.slice(1)];
4367
- const executableStat = lstatSync7(executable);
4367
+ const executableStat = lstatSync8(executable);
4368
4368
  const verdict = assessVersion("kimi-review", COMPAT["kimi-review"].parse(await version(command, cwd, env, context.signal)));
4369
4369
  if (!verdict.ok)
4370
4370
  throw new Error(verdict.reason);
@@ -4519,6 +4519,14 @@ function jcodeContextValue(value, sessionId, measuredAt) {
4519
4519
  const tokens = okay ? raw.used : null, window = okay ? raw.size : null;
4520
4520
  return { source: "jcode_usage_update", sessionId, measuredAt, tokens, window, used: tokens !== null && window !== null ? Math.min(1, tokens / window) : null };
4521
4521
  }
4522
+ function piContext(value, sessionId, measuredAt) {
4523
+ const raw = object4(value), parts = [raw.input, raw.cacheRead, raw.cacheWrite];
4524
+ const valid = parts.every((n) => Number.isSafeInteger(n) && n >= 0);
4525
+ const sum = valid ? parts.reduce((a, n) => a + n, 0) : null;
4526
+ const tokens = Number.isSafeInteger(sum) ? sum : null;
4527
+ const window = Number.isSafeInteger(raw.contextWindow) && raw.contextWindow > 0 ? raw.contextWindow : null;
4528
+ return { source: "pi_usage", sessionId, measuredAt, tokens, window, used: tokens !== null && window !== null ? Math.min(1, tokens / window) : null };
4529
+ }
4522
4530
  var nonnegative = (n) => typeof n === "number" && Number.isFinite(n) && n >= 0, positive = (n) => nonnegative(n) && n > 0, record2 = (v) => v !== null && typeof v === "object" && !Array.isArray(v), object4 = (v) => record2(v) ? v : {};
4523
4531
 
4524
4532
  // src/hub/context-window.ts
@@ -5026,7 +5034,7 @@ var init_acp = __esm(() => {
5026
5034
  init_model_token();
5027
5035
  init_acp_session_model();
5028
5036
  init_native_capabilities();
5029
- TOOL_CEILING_MS = 30 * 60000;
5037
+ TOOL_CEILING_MS = 60 * 60000;
5030
5038
  managedLaunches = new WeakMap;
5031
5039
  RpcTimeoutError = class RpcTimeoutError extends Error {
5032
5040
  };
@@ -5689,6 +5697,9 @@ ${renderDigest(envs, this.primed)}` : renderDigest(envs, this.primed) }] });
5689
5697
  this.touch(Math.min(this.watchdogMs, remaining));
5690
5698
  return;
5691
5699
  }
5700
+ try {
5701
+ this.opts.onToolCeiling?.({ ceilingMs: ceiling });
5702
+ } catch {}
5692
5703
  try {
5693
5704
  this.activityPrivate ||= this.opts.isPrivateTurn?.() === true;
5694
5705
  } catch {
@@ -7148,7 +7159,7 @@ __export(exports_jcode, {
7148
7159
  });
7149
7160
  import { spawn as spawn7, spawnSync as spawnSync2 } from "child_process";
7150
7161
  import { createConnection } from "net";
7151
- import { closeSync as closeSync4, constants as constants3, existsSync as existsSync5, fstatSync as fstatSync4, lstatSync as lstatSync8, mkdtempSync as mkdtempSync3, openSync as openSync4, readSync as readSync2, rmSync as rmSync3 } from "fs";
7162
+ import { closeSync as closeSync4, constants as constants3, existsSync as existsSync5, fstatSync as fstatSync4, lstatSync as lstatSync9, mkdtempSync as mkdtempSync3, openSync as openSync4, readSync as readSync2, rmSync as rmSync3 } from "fs";
7152
7163
  import { tmpdir as tmpdir3 } from "os";
7153
7164
  import { isAbsolute as isAbsolute4, join as join9 } from "path";
7154
7165
  function jcodeCommand(command, kind, socket, cwd, model, profile, provider, peer = "jcode") {
@@ -7193,12 +7204,12 @@ function jcodeTuiCommand(command, socket, sessionId, model, profile, provider) {
7193
7204
  function savedSession(home, id) {
7194
7205
  if (!/^[A-Za-z0-9_-]{1,128}$/.test(id))
7195
7206
  throw new Error("invalid native session identity");
7196
- const directory = join9(home, "sessions"), info = lstatSync8(directory, { throwIfNoEntry: false });
7207
+ const directory = join9(home, "sessions"), info = lstatSync9(directory, { throwIfNoEntry: false });
7197
7208
  if (!info)
7198
7209
  return false;
7199
7210
  if (!info.isDirectory() || info.isSymbolicLink())
7200
7211
  throw new Error("unsafe native session directory");
7201
- const file = join9(directory, `${id}.json`), entry = lstatSync8(file, { throwIfNoEntry: false });
7212
+ const file = join9(directory, `${id}.json`), entry = lstatSync9(file, { throwIfNoEntry: false });
7202
7213
  if (!entry)
7203
7214
  return false;
7204
7215
  if (!entry.isFile() || entry.isSymbolicLink())
@@ -7397,7 +7408,7 @@ var init_jcode = __esm(() => {
7397
7408
  ready.once("data", () => {
7398
7409
  clearTimeout(timer);
7399
7410
  server.off("exit", fail);
7400
- if (lstatSync8(this.socket, { throwIfNoEntry: false })?.isSocket())
7411
+ if (lstatSync9(this.socket, { throwIfNoEntry: false })?.isSocket())
7401
7412
  resolve();
7402
7413
  else
7403
7414
  reject(new Error("Jcode readiness has no private socket"));
@@ -7407,7 +7418,7 @@ var init_jcode = __esm(() => {
7407
7418
  if (!this.ending && this.server === server)
7408
7419
  this.stop("Jcode owned daemon disconnected").catch(() => {});
7409
7420
  });
7410
- const identity = lstatSync8(this.socket);
7421
+ const identity = lstatSync9(this.socket);
7411
7422
  this.socketIdentity = { dev: identity.dev, ino: identity.ino };
7412
7423
  await super.start();
7413
7424
  } catch (error) {
@@ -7481,7 +7492,7 @@ var init_jcode = __esm(() => {
7481
7492
  throw new Error(reason);
7482
7493
  };
7483
7494
  const sessionId = super.recoveryMetadata().sessionId;
7484
- const socket = lstatSync8(this.socket, { throwIfNoEntry: false });
7495
+ const socket = lstatSync9(this.socket, { throwIfNoEntry: false });
7485
7496
  if (this.state !== "busy")
7486
7497
  refuse(`jcode is ${this.state}`);
7487
7498
  if (this.ending || !this.server || this.server.exitCode !== null || this.server.signalCode !== null || !socket?.isSocket() || socket.dev !== this.socketIdentity?.dev || socket.ino !== this.socketIdentity.ino || typeof sessionId !== "string")
@@ -7494,7 +7505,7 @@ var init_jcode = __esm(() => {
7494
7505
  return "owned Jcode server changed before the steer was sent";
7495
7506
  if (super.recoveryMetadata().sessionId !== sessionId)
7496
7507
  return "jcode's session changed before the steer was sent";
7497
- const now = lstatSync8(this.socket, { throwIfNoEntry: false });
7508
+ const now = lstatSync9(this.socket, { throwIfNoEntry: false });
7498
7509
  if (!now?.isSocket() || now.dev !== identity?.dev || now.ino !== identity.ino)
7499
7510
  return "owned Jcode socket changed before the steer was sent";
7500
7511
  return;
@@ -7519,7 +7530,7 @@ var init_jcode = __esm(() => {
7519
7530
  }
7520
7531
  tuiLaunch(expected, options = {}) {
7521
7532
  const sessionId = super.recoveryMetadata().sessionId;
7522
- const socket = lstatSync8(this.socket, { throwIfNoEntry: false });
7533
+ const socket = lstatSync9(this.socket, { throwIfNoEntry: false });
7523
7534
  if (this.ending || !this.server || this.server.exitCode !== null || this.server.signalCode !== null || this.state === "offline")
7524
7535
  throw new JcodeTuiRefusal("server_not_running");
7525
7536
  if (!socket?.isSocket() || socket.dev !== this.socketIdentity?.dev || socket.ino !== this.socketIdentity.ino)
@@ -7560,7 +7571,7 @@ var exports_qwen_dual = {};
7560
7571
  __export(exports_qwen_dual, {
7561
7572
  QwenDualPeer: () => QwenDualPeer
7562
7573
  });
7563
- import { closeSync as closeSync5, constants as constants4, fstatSync as fstatSync5, lstatSync as lstatSync9, mkdirSync as mkdirSync5, openSync as openSync5, readSync as readSync3, realpathSync as realpathSync2, renameSync as renameSync3, writeFileSync as writeFileSync5, writeSync } from "fs";
7574
+ import { closeSync as closeSync5, constants as constants4, fstatSync as fstatSync5, lstatSync as lstatSync10, mkdirSync as mkdirSync5, openSync as openSync5, readSync as readSync3, realpathSync as realpathSync2, renameSync as renameSync3, writeFileSync as writeFileSync5, writeSync } from "fs";
7564
7575
  import { join as join10 } from "path";
7565
7576
  function qwenDualNamesStateDir(input, stateDir) {
7566
7577
  const needles = new Set([".agenthub/state", ".agenthub\\state", "qwen-dual", "input.jsonl", stateDir]);
@@ -7697,7 +7708,7 @@ var init_qwen_dual = __esm(() => {
7697
7708
  return { ...this.state_.sessionId ? { sessionId: this.state_.sessionId } : {}, launch: { mode: "tui" } };
7698
7709
  }
7699
7710
  ensureFile(path, create) {
7700
- const found = lstatSync9(path, { throwIfNoEntry: false });
7711
+ const found = lstatSync10(path, { throwIfNoEntry: false });
7701
7712
  if (!found) {
7702
7713
  if (!create)
7703
7714
  throw new Error("Qwen dual-output file is missing");
@@ -7762,7 +7773,7 @@ var init_qwen_dual = __esm(() => {
7762
7773
  }
7763
7774
  async start() {
7764
7775
  mkdirSync5(this.dir, { recursive: true, mode: 448 });
7765
- const dir = lstatSync9(this.dir);
7776
+ const dir = lstatSync10(this.dir);
7766
7777
  if (!dir.isDirectory() || dir.isSymbolicLink() || typeof process.getuid === "function" && dir.uid !== process.getuid() || (dir.mode & 63) !== 0)
7767
7778
  throw new Error("Qwen dual-output directory is not private to the person running the hub");
7768
7779
  this._launch = undefined;
@@ -7802,7 +7813,7 @@ var init_qwen_dual = __esm(() => {
7802
7813
  if (fenced && !this.freshBaselineAbsent) {
7803
7814
  this.sessionSeen = this.state_.sessionId !== undefined;
7804
7815
  this.primed = true;
7805
- this.denyCursor = lstatSync9(this.eventFile).size;
7816
+ this.denyCursor = lstatSync10(this.eventFile).size;
7806
7817
  this.setState("offline");
7807
7818
  try {
7808
7819
  this.opts.onNotice?.(`${this.id}: the hub could not verify that the old Qwen terminal is absent; inspect and end that terminal before running ahub qwen --mode tui again`);
@@ -7855,7 +7866,7 @@ var init_qwen_dual = __esm(() => {
7855
7866
  }
7856
7867
  prepareFreshEvents(fenced) {
7857
7868
  if (!fenced) {
7858
- const previous = lstatSync9(this.eventFile);
7869
+ const previous = lstatSync10(this.eventFile);
7859
7870
  if (previous.size > 0) {
7860
7871
  try {
7861
7872
  renameSync3(this.eventFile, join10(this.dir, "events.prev.jsonl"));
@@ -7868,7 +7879,7 @@ var init_qwen_dual = __esm(() => {
7868
7879
  let fd;
7869
7880
  let ready = false;
7870
7881
  try {
7871
- const previous = lstatSync9(this.eventFile);
7882
+ const previous = lstatSync10(this.eventFile);
7872
7883
  if (previous.size > 0)
7873
7884
  renameSync3(this.eventFile, join10(this.dir, "events.prev.jsonl"));
7874
7885
  this.ensureFile(this.eventFile, true);
@@ -8450,7 +8461,7 @@ ${text}`;
8450
8461
  this.discardReadProof();
8451
8462
  return;
8452
8463
  }
8453
- const current = fstatSync5(fd), named = lstatSync9(this.eventFile);
8464
+ const current = fstatSync5(fd), named = lstatSync10(this.eventFile);
8454
8465
  if (!current.isFile() || !named.isFile() || named.isSymbolicLink() || current.dev !== named.dev || current.ino !== named.ino || `${current.dev}:${current.ino}` !== candidate.source || this.freshInputPending && candidate.source !== this.freshRead?.source || current.size !== this.state_.offset || named.size !== current.size) {
8455
8466
  this.discardReadProof();
8456
8467
  return;
@@ -8688,7 +8699,7 @@ var init_recovery_error = __esm(() => {
8688
8699
  });
8689
8700
 
8690
8701
  // src/hub/recovery-store.ts
8691
- import { chmodSync, existsSync as existsSync6, linkSync, lstatSync as lstatSync10, mkdirSync as mkdirSync6, readFileSync as readFileSync5, renameSync as renameSync4, rmSync as rmSync4, writeFileSync as writeFileSync6 } from "fs";
8702
+ import { chmodSync, existsSync as existsSync6, linkSync, lstatSync as lstatSync11, mkdirSync as mkdirSync6, readFileSync as readFileSync5, renameSync as renameSync4, rmSync as rmSync4, writeFileSync as writeFileSync6 } from "fs";
8692
8703
  import { randomUUID as randomUUID4 } from "crypto";
8693
8704
  function atomicPrivateJSON(file, value) {
8694
8705
  const temporary = `${file}.${randomUUID4()}.tmp`;
@@ -8764,10 +8775,10 @@ var init_session = __esm(() => {
8764
8775
  });
8765
8776
 
8766
8777
  // src/hub/permission-mode.ts
8767
- import { lstatSync as lstatSync11 } from "fs";
8778
+ import { lstatSync as lstatSync12 } from "fs";
8768
8779
  function hardLinked(path) {
8769
8780
  try {
8770
- const st = lstatSync11(path);
8781
+ const st = lstatSync12(path);
8771
8782
  return st.isFile() && st.nlink > 1;
8772
8783
  } catch {
8773
8784
  return false;
@@ -8786,11 +8797,11 @@ var init_permission_mode = __esm(() => {
8786
8797
  });
8787
8798
 
8788
8799
  // src/hub/path-policy.ts
8789
- import { accessSync, constants as constants5, lstatSync as lstatSync12, opendirSync, readlinkSync, statSync as statSync3 } from "fs";
8800
+ import { accessSync, constants as constants5, lstatSync as lstatSync13, opendirSync, readlinkSync, statSync as statSync3 } from "fs";
8790
8801
  import { dirname as dirname8, isAbsolute as isAbsolute5, join as join13, relative as relative3, resolve as resolve9, sep as sep3 } from "path";
8791
8802
  function existing(path) {
8792
8803
  try {
8793
- lstatSync12(path);
8804
+ lstatSync13(path);
8794
8805
  return true;
8795
8806
  } catch (error) {
8796
8807
  if (error.code === "ENOENT")
@@ -8839,7 +8850,7 @@ function directAliasTarget(path) {
8839
8850
  return;
8840
8851
  ancestor = parent;
8841
8852
  }
8842
- if (!lstatSync12(ancestor).isSymbolicLink())
8853
+ if (!lstatSync13(ancestor).isSymbolicLink())
8843
8854
  return;
8844
8855
  target = resolve9(dirname8(ancestor), readlinkSync(ancestor), relative3(ancestor, target));
8845
8856
  }
@@ -9131,7 +9142,7 @@ var init_shell_environment = () => {};
9131
9142
 
9132
9143
  // src/local/sandbox.ts
9133
9144
  import { spawn as spawn8, spawnSync as spawnSync3 } from "child_process";
9134
- import { existsSync as existsSync7, lstatSync as lstatSync13, mkdtempSync as mkdtempSync4, readdirSync as readdirSync2, rmdirSync as rmdirSync2, rmSync as rmSync5 } from "fs";
9145
+ import { existsSync as existsSync7, lstatSync as lstatSync14, mkdtempSync as mkdtempSync4, readdirSync as readdirSync2, rmdirSync as rmdirSync2, rmSync as rmSync5 } from "fs";
9135
9146
  import { homedir as homedir4, tmpdir as tmpdir4 } from "os";
9136
9147
  import { dirname as dirname10, join as join15, resolve as resolve10 } from "path";
9137
9148
  function developerDir() {
@@ -9336,13 +9347,13 @@ async function probeCommand(argv, opts) {
9336
9347
  return { code: null, output: "error: probe command authority or environment unavailable", quiescent: true };
9337
9348
  }
9338
9349
  const own = realPath(mkdtempSync4(join15(proof.temporaryRoot, "command-")));
9339
- const created = lstatSync13(own);
9350
+ const created = lstatSync14(own);
9340
9351
  let removed = false;
9341
9352
  const dropOwn = () => {
9342
9353
  if (removed)
9343
9354
  return;
9344
9355
  proof.physical();
9345
- const current = lstatSync13(own);
9356
+ const current = lstatSync14(own);
9346
9357
  if (!current.isDirectory() || current.isSymbolicLink() || current.dev !== created.dev || current.ino !== created.ino || realPath(own) !== own)
9347
9358
  throw new Error("probe command temp ownership changed");
9348
9359
  rmdirSync2(own);
@@ -9455,7 +9466,7 @@ var init_text_projection = __esm(() => {
9455
9466
  });
9456
9467
 
9457
9468
  // src/local/doc-read.ts
9458
- import { lstatSync as lstatSync14 } from "fs";
9469
+ import { lstatSync as lstatSync15 } from "fs";
9459
9470
  import { extname } from "path";
9460
9471
  function docRead(file, shown, args, port, cwd) {
9461
9472
  const projections = port.projections();
@@ -9465,7 +9476,7 @@ function docRead(file, shown, args, port, cwd) {
9465
9476
  }
9466
9477
  let st;
9467
9478
  try {
9468
- st = lstatSync14(file);
9479
+ st = lstatSync15(file);
9469
9480
  } catch {
9470
9481
  return `error: ${shown} cannot be read`;
9471
9482
  }
@@ -9945,13 +9956,13 @@ var init_probe_errors = __esm(() => {
9945
9956
  });
9946
9957
 
9947
9958
  // src/local/probe-workspace.ts
9948
- import { chmodSync as chmodSync2, constants as constants6, closeSync as closeSync7, fstatSync as fstatSync6, lstatSync as lstatSync15, mkdirSync as mkdirSync8, mkdtempSync as mkdtempSync5, openSync as openSync7, opendirSync as opendirSync2, readSync as readSync4, rmSync as rmSync6, rmdirSync as rmdirSync3, unlinkSync as unlinkSync3, writeFileSync as writeFileSync7 } from "fs";
9959
+ import { chmodSync as chmodSync2, constants as constants6, closeSync as closeSync7, fstatSync as fstatSync6, lstatSync as lstatSync16, mkdirSync as mkdirSync8, mkdtempSync as mkdtempSync5, openSync as openSync7, opendirSync as opendirSync2, readSync as readSync4, rmSync as rmSync6, rmdirSync as rmdirSync3, unlinkSync as unlinkSync3, writeFileSync as writeFileSync7 } from "fs";
9949
9960
  import { dirname as dirname11, isAbsolute as isAbsolute6, join as join16 } from "path";
9950
9961
  function refused() {
9951
9962
  throw new Error("probe workspace source, role, path or resource proof is unavailable");
9952
9963
  }
9953
9964
  function directoryIdentity(file) {
9954
- const stat = lstatSync15(file);
9965
+ const stat = lstatSync16(file);
9955
9966
  if (!stat.isDirectory() || stat.isSymbolicLink() || realPath(file) !== file)
9956
9967
  refused();
9957
9968
  return { file, dev: stat.dev, ino: stat.ino };
@@ -9978,7 +9989,7 @@ function probeWorkspaceCurrent(workspace) {
9978
9989
  state.current();
9979
9990
  probeWorkspacePhysical(workspace);
9980
9991
  for (const entry of state.identities) {
9981
- const stat = lstatSync15(entry.file);
9992
+ const stat = lstatSync16(entry.file);
9982
9993
  if (!stat.isFile() || stat.nlink !== 1 || stat.dev !== entry.dev || stat.ino !== entry.ino || stat.size !== entry.size || stat.mtimeMs !== entry.mtimeMs || stat.ctimeMs !== entry.ctimeMs)
9983
9994
  refused();
9984
9995
  }
@@ -10006,7 +10017,7 @@ var init_probe_workspace = __esm(() => {
10006
10017
  });
10007
10018
 
10008
10019
  // src/local/tools.ts
10009
- import { lstatSync as lstatSync16, mkdirSync as mkdirSync9, readFileSync as readFileSync7, statSync as statSync4, writeFileSync as writeFileSync8 } from "fs";
10020
+ import { lstatSync as lstatSync17, mkdirSync as mkdirSync9, readFileSync as readFileSync7, statSync as statSync4, writeFileSync as writeFileSync8 } from "fs";
10010
10021
  import { dirname as dirname12, join as join17, relative as relative4, resolve as resolve11 } from "path";
10011
10022
  function probeCurrent(probe) {
10012
10023
  try {
@@ -10016,7 +10027,7 @@ function probeCurrent(probe) {
10016
10027
  }
10017
10028
  }
10018
10029
  function probeTargetIdentity(target) {
10019
- const stat = lstatSync16(target, { throwIfNoEntry: false });
10030
+ const stat = lstatSync17(target, { throwIfNoEntry: false });
10020
10031
  if (!stat)
10021
10032
  return;
10022
10033
  if (!stat.isFile())
@@ -10039,7 +10050,7 @@ function planProbeTool(name, rawArgs, ctx) {
10039
10050
  if (name === "write")
10040
10051
  maximum = Buffer.byteLength(String(value.content ?? ""), "utf8");
10041
10052
  else {
10042
- const stat = lstatSync16(target, { throwIfNoEntry: false });
10053
+ const stat = lstatSync17(target, { throwIfNoEntry: false });
10043
10054
  if (!stat || !stat.isFile())
10044
10055
  throw new ProbeToolRefusal("nonregular_target");
10045
10056
  maximum = Math.min(PROBE_WORKSPACE_LIMITS.fileBytes, stat.size + Buffer.byteLength(String(value.new ?? ""), "utf8"));
@@ -10116,7 +10127,7 @@ function guardPath(ctx, path, mode) {
10116
10127
  throw new Error(`${path} is on the secrets denylist`);
10117
10128
  }
10118
10129
  if (ctx.probe) {
10119
- const stat = lstatSync16(real, { throwIfNoEntry: false });
10130
+ const stat = lstatSync17(real, { throwIfNoEntry: false });
10120
10131
  if (stat && !stat.isFile() && !(mode === "read" && stat.isDirectory()))
10121
10132
  throw new ProbeToolRefusal("nonregular_target");
10122
10133
  if (stat?.isFile() && stat.nlink !== 1)
@@ -10128,7 +10139,7 @@ function guardPath(ctx, path, mode) {
10128
10139
  }
10129
10140
  if (mode === "write" && (isHubWritePath(rel) || inside && isHubWritePath(typed)))
10130
10141
  throw new Error(`${path} is not writable by the local worker`);
10131
- if (mode === "write" && ctx.readOnly?.length && (lstatSync16(real, { throwIfNoEntry: false })?.nlink ?? 1) > 1)
10142
+ if (mode === "write" && ctx.readOnly?.length && (lstatSync17(real, { throwIfNoEntry: false })?.nlink ?? 1) > 1)
10132
10143
  throw new Error("hardlinked write target cannot be verified with data.readonly");
10133
10144
  if (mode === "write" && matchesPolicy(root, path, ctx.readOnly ?? []))
10134
10145
  throw new Error("target is protected by data.readonly");
@@ -10203,11 +10214,14 @@ async function runTool(name, rawArgs, ctx) {
10203
10214
  const file = guardPath(ctx, String(a.path), "read");
10204
10215
  if (statSync4(file).size > 5000000)
10205
10216
  return "error: file is larger than 5 MB; use bash (head, grep, sed -n) to look at parts of it";
10206
- const lines = readFileSync7(file, "utf8").split(`
10217
+ const bytes = readFileSync7(file);
10218
+ const lines = bytes.toString("utf8").split(`
10207
10219
  `);
10208
10220
  const from = Math.max(1, Number(a.offset) || 1);
10209
10221
  const out = lines.slice(from - 1, from - 1 + (Number(a.limit) || 2000)).map((l, i) => `${from + i} ${l}`).join(`
10210
10222
  `);
10223
+ ctx.editGuard?.read(file, bytes, a.offset === undefined && a.limit === undefined && out.split(`
10224
+ `).length === lines.length && out.length <= OUTPUT_CAP);
10211
10225
  return out.length > OUTPUT_CAP ? `${out.slice(0, OUTPUT_CAP)}
10212
10226
  (truncated: read again with offset/limit)` : out;
10213
10227
  }
@@ -10237,8 +10251,12 @@ ${preview(content)}`, "write", ctx.signal, file, undefined, String(a.path), a),
10237
10251
  if (guardPath(ctx, String(a.path), "write") !== approvedTarget)
10238
10252
  return formatProbeToolRefusal(new ProbeToolRefusal("target_changed"));
10239
10253
  }
10254
+ const unverified = ctx.editGuard?.write(file);
10240
10255
  mkdirSync9(dirname12(file), { recursive: true });
10241
10256
  writeFileSync8(file, content);
10257
+ try {
10258
+ ctx.editGuard?.written(file, unverified);
10259
+ } catch {}
10242
10260
  return `wrote ${a.path}`;
10243
10261
  }
10244
10262
  case "edit": {
@@ -10274,7 +10292,11 @@ ${preview(content)}`, "write", ctx.signal, file, undefined, String(a.path), a),
10274
10292
  if (guardPath(ctx, String(a.path), "write") !== approvedTarget || readFileSync7(file, "utf8") !== text)
10275
10293
  return formatProbeToolRefusal(new ProbeToolRefusal("target_changed"));
10276
10294
  }
10295
+ const unverified = ctx.editGuard?.write(file);
10277
10296
  writeFileSync8(file, replacement);
10297
+ try {
10298
+ ctx.editGuard?.written(file, unverified);
10299
+ } catch {}
10278
10300
  return `edited ${a.path}`;
10279
10301
  }
10280
10302
  case "bash": {
@@ -10303,7 +10325,11 @@ ${preview(content)}`, "write", ctx.signal, file, undefined, String(a.path), a),
10303
10325
  if (attempt)
10304
10326
  return "error: read-only shell proof remained unstable; no command was executed";
10305
10327
  }
10328
+ const observedShell = ctx.editGuard?.shell(command);
10306
10329
  const res = await sandboxedExec(["/bin/bash", "-c", command], { cwd: ctx.cwd, profile: ctx.sandboxProfile, readOnlyData: !!ctx.readOnly?.length, timeoutMs: (Number(a.timeout_s) || 120) * 1000, ...ctx.sandboxEnv ? { env: ctx.sandboxEnv } : {}, ...ctx.signal ? { signal: ctx.signal } : {} });
10330
+ try {
10331
+ observedShell?.();
10332
+ } catch {}
10307
10333
  try {
10308
10334
  ctx.onProcessExit?.(res.code);
10309
10335
  } catch {}
@@ -10356,7 +10382,7 @@ note: the sandbox does not let you move a branch, tag or HEAD, or stage inside a
10356
10382
  }
10357
10383
  var APPROVAL_EXPIRED_TEXT = "error: approval expired: no person answered; do not retry this call; hand the task off or stop", ApprovalWaitStop, approvalError = (picked, denied) => picked === true ? undefined : picked === "expired" ? APPROVAL_EXPIRED_TEXT : picked === "aborted" ? "error: approval withdrawn because the turn ended; no operation was executed" : denied, probeToolPlans, lexists = (p) => {
10358
10384
  try {
10359
- lstatSync16(p);
10385
+ lstatSync17(p);
10360
10386
  return true;
10361
10387
  } catch {
10362
10388
  return false;
@@ -10536,6 +10562,7 @@ var init_pi = __esm(() => {
10536
10562
  PiPeer = class PiPeer extends BasePeer {
10537
10563
  opts;
10538
10564
  preflight;
10565
+ sessionModel;
10539
10566
  hubNative = true;
10540
10567
  hubOwned = true;
10541
10568
  proc;
@@ -10761,6 +10788,9 @@ var init_pi = __esm(() => {
10761
10788
  const session = this.recoveryMetadata().sessionId;
10762
10789
  return typeof session === "string" ? session : undefined;
10763
10790
  }
10791
+ get verifiedRecordSession() {
10792
+ return this.verifiedOwner() ? this.nativeSession : undefined;
10793
+ }
10764
10794
  async captureResume() {
10765
10795
  if (this.state === "offline") {
10766
10796
  if (this.canReuseVerifiedEmptyResume())
@@ -10778,6 +10808,10 @@ var init_pi = __esm(() => {
10778
10808
  const snapshot = this.opts.mode === "headless" ? (await this.waitRpc("get_state", 15000)).data : await this.sendTui({ type: "get_session_state" });
10779
10809
  if (this.state !== "idle" || this.activeTools || snapshot?.sessionId !== this.sessionId || snapshot?.sessionFile !== this.sessionFile)
10780
10810
  throw new Error("Pi source session changed during capture");
10811
+ if (this.opts.mode === "tui" && this.verifiedOwner() && this.sessionId) {
10812
+ this.sessionModel = stateModelId(snapshot);
10813
+ this.opts.onContext?.(snapshot.context, this.sessionId);
10814
+ }
10781
10815
  if (!this.observeSnapshotTitle(snapshot, titleRevisionBefore, titleEpochBefore))
10782
10816
  throw new Error("Pi source session title changed during capture; retry with a fresh native session snapshot");
10783
10817
  const empty = this.opts.mode === "headless" ? snapshot.messageCount === 0 && snapshot.pendingMessageCount === 0 && snapshot.isStreaming === false && snapshot.isCompacting !== true && !snapshot.sessionName : snapshot.empty === true && snapshot.idle === true;
@@ -11260,6 +11294,10 @@ var init_pi = __esm(() => {
11260
11294
  throw new Error("Pi roster return could not verify the current native session");
11261
11295
  if (lifecycle !== this.rosterLifecycleRevision)
11262
11296
  throw new Error("Pi native activity changed during roster return; retry with a fresh session snapshot");
11297
+ if (session) {
11298
+ this.sessionModel = stateModelId(snapshot);
11299
+ this.opts.onContext?.(snapshot.context, session);
11300
+ }
11263
11301
  this.observeSnapshotTitle(snapshot, titleRevisionBefore, titleEpochBefore);
11264
11302
  this.rosterDetached = false;
11265
11303
  this.hubPromptId = undefined;
@@ -11430,7 +11468,7 @@ var init_pi = __esm(() => {
11430
11468
  attempted = true;
11431
11469
  if (deliveryId)
11432
11470
  this.activeDeliveryIds.add(deliveryId);
11433
- const recordPrompt = this.opts.mode === "tui" ? "" : this.turnRecordPrompt("");
11471
+ const recordPrompt = this.turnRecordPrompt("");
11434
11472
  const message = [recordPrompt, envs.some((env) => env.private || remoteEnvelope(env)) ? undefined : this.opts.titlePreface?.(), renderDigest(envs, true)].filter(Boolean).join(`
11435
11473
  `);
11436
11474
  if (this.opts.mode === "tui") {
@@ -11540,6 +11578,11 @@ var init_pi = __esm(() => {
11540
11578
  return;
11541
11579
  }
11542
11580
  } catch {}
11581
+ } else {
11582
+ if (this.verifiedOwner() && this.sessionModel) {
11583
+ this.turnModel = { model: this.sessionModel, evidence: "session" };
11584
+ return;
11585
+ }
11543
11586
  }
11544
11587
  if (requested)
11545
11588
  this.turnModel = { model: requested, evidence: "configured" };
@@ -11565,9 +11608,11 @@ var init_pi = __esm(() => {
11565
11608
  const slash = model.indexOf("/");
11566
11609
  const provider = "agent-hub-local";
11567
11610
  const modelId = model;
11568
- if (this.opts.mode === "tui")
11611
+ if (this.opts.mode === "tui") {
11612
+ if (this.sessionModel !== modelId)
11613
+ this.sessionModel = undefined;
11569
11614
  await this.sendTui({ type: "set_model", provider, modelId });
11570
- else
11615
+ } else
11571
11616
  await this.sendRpc({ type: "set_model", provider, modelId });
11572
11617
  this.requestedModel = model;
11573
11618
  }
@@ -11650,6 +11695,7 @@ var init_pi = __esm(() => {
11650
11695
  this.opts.log?.(`[${this.id}] Pi session identity mismatch`);
11651
11696
  return;
11652
11697
  }
11698
+ this.sessionModel = stateModelId(event);
11653
11699
  this.titleRevision = -1;
11654
11700
  this.titleEpoch++;
11655
11701
  this.nativeTitleEpoch = typeof event.titleEpoch === "string" && event.titleEpoch ? event.titleEpoch : undefined;
@@ -11696,6 +11742,8 @@ var init_pi = __esm(() => {
11696
11742
  const generation = Number.isSafeInteger(event.generation) ? event.generation : this.budgetGeneration + 1;
11697
11743
  if (generation <= this.budgetGeneration)
11698
11744
  return;
11745
+ if (this.opts.mode === "tui" && this.sessionModel && this.verifiedOwner() && (event.sessionId === undefined || event.sessionId === this.sessionId))
11746
+ this.turnModel = { model: this.sessionModel, evidence: "session" };
11699
11747
  this.modelStep = 0;
11700
11748
  this.ceilingUnsafe = false;
11701
11749
  this.turnObserved = false;
@@ -11726,6 +11774,14 @@ var init_pi = __esm(() => {
11726
11774
  }
11727
11775
  if (event.type === "activity" && this.state === "busy")
11728
11776
  this.touch();
11777
+ if (event.type === "pi_model" && event.sessionId === this.sessionId && this.verifiedOwner() && this.sessionId) {
11778
+ this.sessionModel = stateModelId(event);
11779
+ this.opts.onContext?.(undefined, this.sessionId);
11780
+ }
11781
+ if (event.type === "pi_usage" && this.agentRunning && this.state === "busy" && event.sessionId === this.sessionId && event.generation === this.budgetGeneration && this.verifiedOwner() && this.sessionId) {
11782
+ this.sessionModel = stateModelId(event);
11783
+ this.opts.onContext?.(event.context, this.sessionId);
11784
+ }
11729
11785
  if (event.type === "tokens" && this.state === "busy" && typeof event.id === "string" && event.id.length <= 100 && Number.isSafeInteger(event.tokens) && event.tokens >= 0 && !this.usageSeen.has(event.id)) {
11730
11786
  this.usageSeen.add(event.id);
11731
11787
  if (this.usageSeen.size > 1000)
@@ -12644,7 +12700,7 @@ var init_shipped_roles = __esm(() => {
12644
12700
 
12645
12701
  // src/hub/roles.ts
12646
12702
  import { createHash as createHash7 } from "crypto";
12647
- import { constants as constants7, closeSync as closeSync8, fstatSync as fstatSync7, lstatSync as lstatSync17, openSync as openSync8, readSync as readSync5, readdirSync as readdirSync3 } from "fs";
12703
+ import { constants as constants7, closeSync as closeSync8, fstatSync as fstatSync7, lstatSync as lstatSync18, openSync as openSync8, readSync as readSync5, readdirSync as readdirSync3 } from "fs";
12648
12704
  import { join as join19 } from "path";
12649
12705
  function parseRole(text, stem, layer) {
12650
12706
  if (Buffer.byteLength(text) > 8192 || text.includes("\r") || !ID.test(stem))
@@ -12726,7 +12782,7 @@ function loadRoleCatalog(cwd) {
12726
12782
  try {
12727
12783
  const config = join19(cwd, ".agenthub"), dir = join19(config, "roles");
12728
12784
  for (const path of [config, dir]) {
12729
- const stat = lstatSync17(path);
12785
+ const stat = lstatSync18(path);
12730
12786
  if (!stat.isDirectory() || stat.isSymbolicLink())
12731
12787
  throw new Error("unsafe role directory");
12732
12788
  }
@@ -13614,7 +13670,7 @@ var package_default;
13614
13670
  var init_package = __esm(() => {
13615
13671
  package_default = {
13616
13672
  name: "@staix/agent-hub",
13617
- version: "0.44.0",
13673
+ version: "0.45.0",
13618
13674
  description: "Native multi-agent hub: Claude Code, Codex, Kimi Code, Pi and local inference as peers in one project",
13619
13675
  license: "MIT",
13620
13676
  type: "module",
@@ -13631,7 +13687,7 @@ var init_package = __esm(() => {
13631
13687
  bun: ">=1.4.4"
13632
13688
  },
13633
13689
  dependencies: {
13634
- "@staix/agent-mem": "0.30.0"
13690
+ "@staix/agent-mem": ">=0.33.0 <1.0.0"
13635
13691
  },
13636
13692
  devDependencies: {
13637
13693
  "@modelcontextprotocol/sdk": "^1.27.1",
@@ -13748,6 +13804,12 @@ var init_host_executable = __esm(() => {
13748
13804
  init_project();
13749
13805
  });
13750
13806
 
13807
+ // src/hub/sdlc-branch-ci.ts
13808
+ var CAP2;
13809
+ var init_sdlc_branch_ci = __esm(() => {
13810
+ CAP2 = 256 * 1024;
13811
+ });
13812
+
13751
13813
  // src/hub/sdlc.ts
13752
13814
  var SDLC_STAGES, PLAYBOOK_STAGES, BASES2, STAGE_GATES, GATES;
13753
13815
  var init_sdlc = __esm(() => {
@@ -13762,6 +13824,7 @@ var init_sdlc = __esm(() => {
13762
13824
  init_workflow();
13763
13825
  init_child_process();
13764
13826
  init_host_executable();
13827
+ init_sdlc_branch_ci();
13765
13828
  SDLC_STAGES = ["spec", "plan", "implement", "review", "verify", "merge", "release"];
13766
13829
  PLAYBOOK_STAGES = ["intent", "spec", "plan", "build", "test", "review", "merge", "release", "maintain"];
13767
13830
  BASES2 = [...new Set([...SDLC_STAGES, ...PLAYBOOK_STAGES])];
@@ -13813,6 +13876,12 @@ var init_review_comments = __esm(() => {
13813
13876
  init_review_anchor();
13814
13877
  });
13815
13878
 
13879
+ // node_modules/@staix/agent-mem/src/memory/recap-scratch.ts
13880
+ var RECAP_SCRATCH;
13881
+ var init_recap_scratch = __esm(() => {
13882
+ RECAP_SCRATCH = Symbol("recap scratch without search");
13883
+ });
13884
+
13816
13885
  // node_modules/@staix/agent-mem/src/memory/screen.ts
13817
13886
  var SECRETS, looksSecret = (text) => SECRETS.some((re) => re.test(text));
13818
13887
  var init_screen = __esm(() => {
@@ -14505,11 +14574,45 @@ var init_capture = __esm(() => {
14505
14574
  });
14506
14575
 
14507
14576
  // node_modules/@staix/agent-mem/src/memory/style.ts
14508
- function style(color) {
14509
- return { color, ok: wrap(color, 32, 39), attention: wrap(color, 33, 39), error: wrap(color, 31, 39), dim: wrap(color, 2, 22), bold: wrap(color, 1, 22) };
14577
+ function paint(role, text, color) {
14578
+ return color && ROLE_SGR[role] ? `${ROLE_SGR[role]}${text}${SGR_RESET}` : text;
14510
14579
  }
14511
- var wrap = (on, open, close) => (text) => on ? `\x1B[${open}m${text}\x1B[${close}m` : text, PLAIN;
14580
+ function style(color, ascii = true) {
14581
+ return {
14582
+ color,
14583
+ ascii,
14584
+ ok: (text) => paint("success", text, color),
14585
+ attention: (text) => paint("warning", text, color),
14586
+ error: (text) => paint("error", text, color),
14587
+ dim: (text) => paint("hint", text, color),
14588
+ bold: (text) => paint("value", text, color)
14589
+ };
14590
+ }
14591
+ var ESC, SGR_RESET, ROLE_SGR, MARKERS, PLAIN;
14512
14592
  var init_style = __esm(() => {
14593
+ ESC = String.fromCharCode(27);
14594
+ SGR_RESET = `${ESC}[0m`;
14595
+ ROLE_SGR = Object.freeze({
14596
+ header: `${ESC}[1;34m`,
14597
+ section: `${ESC}[1;35m`,
14598
+ key: `${ESC}[34m`,
14599
+ value: "",
14600
+ success: `${ESC}[1;32m`,
14601
+ warning: `${ESC}[1;33m`,
14602
+ error: `${ESC}[1;31m`,
14603
+ hint: `${ESC}[90m`,
14604
+ accent: `${ESC}[36m`
14605
+ });
14606
+ MARKERS = Object.freeze({
14607
+ ok: { glyph: "\u2713", ascii: "ok", role: "success" },
14608
+ fail: { glyph: "\u2717", ascii: "x", role: "error" },
14609
+ warn: { glyph: "\u26A0", ascii: "!", role: "warning" },
14610
+ absent: { glyph: "-", ascii: "-", role: "hint" },
14611
+ unknown: { glyph: "?", ascii: "?", role: "hint" },
14612
+ pending: { glyph: "~", ascii: "~", role: "hint" },
14613
+ active: { glyph: "*", ascii: "*", role: "success" },
14614
+ next: { glyph: "\u2192", ascii: "->", role: "accent" }
14615
+ });
14513
14616
  PLAIN = style(false);
14514
14617
  });
14515
14618
 
@@ -14609,6 +14712,7 @@ var init_reader_lease = __esm(() => {
14609
14712
  // node_modules/@staix/agent-mem/src/memory/store.ts
14610
14713
  var DEFAULT_TTL_MS, UNSETTLED_MS, DEFAULT_LEASE_MS, MIGRATION_BOOTSTRAP, curatedDepth, curatedPending;
14611
14714
  var init_store = __esm(() => {
14715
+ init_recap_scratch();
14612
14716
  init_brief_curated();
14613
14717
  init_curated_cache_state();
14614
14718
  init_sync_placement_guard();
@@ -14688,6 +14792,7 @@ var init_gc = __esm(() => {
14688
14792
 
14689
14793
  // node_modules/@staix/agent-mem/src/memory/curated-read.ts
14690
14794
  var init_curated_read = __esm(() => {
14795
+ init_recap_scratch();
14691
14796
  init_store();
14692
14797
  init_shard();
14693
14798
  });
@@ -14897,6 +15002,9 @@ var init_commands = __esm(() => {
14897
15002
  // node_modules/@staix/agent-mem/src/memory/shard-migration.ts
14898
15003
  var USER2;
14899
15004
  var init_shard_migration = __esm(() => {
15005
+ init_sync_placement_active();
15006
+ init_sync_placement_guard();
15007
+ init_sync_placement_format();
14900
15008
  init_bridge();
14901
15009
  init_generation();
14902
15010
  init_generation_index();
@@ -15140,6 +15248,11 @@ var init_hooks = __esm(() => {
15140
15248
  hookStartedAt = performance.now();
15141
15249
  });
15142
15250
 
15251
+ // node_modules/@staix/agent-mem/src/memory/native-roots.ts
15252
+ var init_native_roots = __esm(() => {
15253
+ init_platform();
15254
+ });
15255
+
15143
15256
  // node_modules/@staix/agent-mem/src/ingest-records.ts
15144
15257
  var init_ingest_records = __esm(() => {
15145
15258
  init_hook_record();
@@ -15150,6 +15263,7 @@ var MAX_BYTES8, DEFAULT_BYTES, MAX_CURSOR_BYTES, utf8, MAX_RECORD;
15150
15263
  var init_ingest = __esm(() => {
15151
15264
  init_capture();
15152
15265
  init_home();
15266
+ init_native_roots();
15153
15267
  init_platform();
15154
15268
  init_policy();
15155
15269
  init_config();
@@ -15208,10 +15322,15 @@ var init_curated_brief_cache = __esm(() => {
15208
15322
  init_store();
15209
15323
  });
15210
15324
 
15325
+ // node_modules/@staix/agent-mem/src/memory/review-targets.ts
15326
+ var init_review_targets = () => {};
15327
+
15211
15328
  // node_modules/@staix/agent-mem/src/memory/decay-review.ts
15212
15329
  var init_decay_review = __esm(() => {
15213
15330
  init_generation();
15214
15331
  init_candidates();
15332
+ init_candidates();
15333
+ init_review_targets();
15215
15334
  });
15216
15335
 
15217
15336
  // node_modules/@staix/agent-mem/src/memory/goal-promotion.ts
@@ -15793,6 +15912,7 @@ var init_sync_placement_writer_context = __esm(() => {
15793
15912
 
15794
15913
  // node_modules/@staix/agent-mem/src/index.ts
15795
15914
  var init_src = __esm(() => {
15915
+ init_platform();
15796
15916
  init_cli_attribution();
15797
15917
  init_search_fts();
15798
15918
  init_platform();
@@ -15843,6 +15963,7 @@ var init_src = __esm(() => {
15843
15963
  init_recall_staleness();
15844
15964
  init_intent_brief();
15845
15965
  init_plan_guard();
15966
+ init_review_targets();
15846
15967
  init_consolidate();
15847
15968
  init_record_candidates();
15848
15969
  init_consolidation_clusters();
@@ -15857,6 +15978,145 @@ var init_src = __esm(() => {
15857
15978
  init_sync_placement_journal();
15858
15979
  });
15859
15980
 
15981
+ // src/hub/log-rotation.ts
15982
+ import { appendFileSync, closeSync as closeSync10, copyFileSync, existsSync as existsSync9, fstatSync as fstatSync9, openSync as openSync10, readdirSync as readdirSync4, readSync as readSync7, renameSync as renameSync5, rmSync as rmSync7, statSync as statSync5, truncateSync } from "fs";
15983
+ import { basename as basename5, dirname as dirname13, join as join20 } from "path";
15984
+ function segmentsOf(file) {
15985
+ const dir = dirname13(file), prefix = `${basename5(file)}.`;
15986
+ let names;
15987
+ try {
15988
+ names = readdirSync4(dir);
15989
+ } catch {
15990
+ names = [];
15991
+ }
15992
+ const rotated = [];
15993
+ for (const name of names) {
15994
+ if (!name.startsWith(prefix))
15995
+ continue;
15996
+ const digits = /^(0|[1-9][0-9]{0,15})$/.exec(name.slice(prefix.length));
15997
+ if (!digits)
15998
+ continue;
15999
+ const path = join20(dir, name);
16000
+ try {
16001
+ const stat = statSync5(path);
16002
+ if (stat.isFile())
16003
+ rotated.push({ path, start: Number(digits[1]), size: stat.size, live: false });
16004
+ } catch {}
16005
+ }
16006
+ rotated.sort((a, b) => a.start - b.start);
16007
+ const last = rotated[rotated.length - 1];
16008
+ const start = last ? last.start + last.size : 0;
16009
+ try {
16010
+ const stat = statSync5(file);
16011
+ if (stat.isFile())
16012
+ rotated.push({ path: file, start, size: stat.size, live: true });
16013
+ } catch {}
16014
+ return rotated;
16015
+ }
16016
+ var EVENTS_SEGMENT_BYTES, HUB_LOG_SEGMENT_BYTES;
16017
+ var init_log_rotation = __esm(() => {
16018
+ EVENTS_SEGMENT_BYTES = 64 * 1024 * 1024;
16019
+ HUB_LOG_SEGMENT_BYTES = 16 * 1024 * 1024;
16020
+ });
16021
+
16022
+ // src/hub/events.ts
16023
+ import { appendFileSync as appendFileSync2, closeSync as closeSync11, existsSync as existsSync10, fstatSync as fstatSync10, openSync as openSync11, readFileSync as readFileSync9, readSync as readSync8 } from "fs";
16024
+ function readEvents(file, since = 0) {
16025
+ for (let attempt = 0;; attempt++) {
16026
+ const segments = segmentsOf(file), out = [];
16027
+ for (const segment of segments) {
16028
+ let text;
16029
+ try {
16030
+ text = readFileSync9(segment.path, "utf8");
16031
+ } catch {
16032
+ continue;
16033
+ }
16034
+ for (const line of text.split(`
16035
+ `)) {
16036
+ const event = parseEventLine(line, since);
16037
+ if (event !== undefined)
16038
+ out.push(event);
16039
+ }
16040
+ }
16041
+ const again = segmentsOf(file);
16042
+ if (attempt >= 3 || again.length === segments.length && again.every((segment, i) => segment.path === segments[i].path && segment.start === segments[i].start))
16043
+ return out;
16044
+ }
16045
+ }
16046
+ function parseEventLine(line, since = 0) {
16047
+ if (!line.trim())
16048
+ return;
16049
+ try {
16050
+ const e = JSON.parse(line);
16051
+ const measuredAt = e.type === "usage" && typeof e.measuredAt === "string" ? e.measuredAt : e.at;
16052
+ return Date.parse(measuredAt) >= since ? e : undefined;
16053
+ } catch {
16054
+ return;
16055
+ }
16056
+ }
16057
+ var init_events = __esm(() => {
16058
+ init_log_rotation();
16059
+ });
16060
+
16061
+ // src/hub/tooling.ts
16062
+ var identities;
16063
+ var init_tooling = __esm(() => {
16064
+ init_registry();
16065
+ init_project();
16066
+ identities = new Map;
16067
+ });
16068
+
16069
+ // src/hub/bench.ts
16070
+ var TASK_FIELDS, CLASSES3, HEAD;
16071
+ var init_bench = __esm(() => {
16072
+ init_project();
16073
+ init_process_signature();
16074
+ TASK_FIELDS = new Set(["id", "title", "detail", "class", "owner", "ref", "setup", "verify", "timeout_s"]);
16075
+ CLASSES3 = new Set(["plan", "implement", "bulk_edit", "test", "review", "summarize", "triage"]);
16076
+ HEAD = `${"".padEnd(28)} ${"attempts".padStart(8)} ${"pass".padStart(5)} ${"p/f/t/e".padStart(11)} ${"first pass".padStart(10)} ${"rework".padStart(6)} ${"tokens p50".padStart(10)} ${"wall p50".padStart(8)}`;
16077
+ });
16078
+
16079
+ // src/hub/research-memory.ts
16080
+ var UNKNOWN_MEMORY_FIGURES;
16081
+ var init_research_memory = __esm(() => {
16082
+ UNKNOWN_MEMORY_FIGURES = Object.freeze({ rendered: null, delivered: null, cited: null, failsExposed: null, failsCited: null, failRetrySignal: null });
16083
+ });
16084
+
16085
+ // src/hub/person-figures.ts
16086
+ var UNKNOWN_PERSON_FIGURES, ALLOW, DENY;
16087
+ var init_person_figures = __esm(() => {
16088
+ UNKNOWN_PERSON_FIGURES = Object.freeze({ permissions: null, questions: null, completions: null, cliRefusals: null, consoleConfirmations: null, latencyMs: null });
16089
+ ALLOW = new Set(["allow_once", "allow_always"]);
16090
+ DENY = new Set(["reject_once", "reject_always"]);
16091
+ });
16092
+
16093
+ // src/hub/cost-governance.ts
16094
+ var init_cost_governance = () => {};
16095
+
16096
+ // src/hub/research-record.ts
16097
+ var NO_EVIDENCE;
16098
+ var init_research_record = __esm(() => {
16099
+ init_cost_governance();
16100
+ init_db_schema();
16101
+ init_sdlc_metrics();
16102
+ NO_EVIDENCE = { tasks: new Map, board: false };
16103
+ });
16104
+
16105
+ // src/hub/research.ts
16106
+ var FAILED, TRACKED2;
16107
+ var init_research2 = __esm(() => {
16108
+ init_log_rotation();
16109
+ init_events();
16110
+ init_project();
16111
+ init_tooling();
16112
+ init_bench();
16113
+ init_research_memory();
16114
+ init_person_figures();
16115
+ init_research_record();
16116
+ FAILED = new Set(["regressed", "reverted", "incomplete", "wrong", "abandoned"]);
16117
+ TRACKED2 = new Set(["hub_start", "state", "tooling", "memory_brief", "task", "usage"]);
16118
+ });
16119
+
15860
16120
  // src/hub/deliverables.ts
15861
16121
  var DELIVERABLE_LIMITS;
15862
16122
  var init_deliverables = __esm(() => {
@@ -15875,6 +16135,8 @@ var BODY2;
15875
16135
  var init_research_experiments = __esm(() => {
15876
16136
  init_src();
15877
16137
  init_packs();
16138
+ init_research2();
16139
+ init_events();
15878
16140
  init_research_runner();
15879
16141
  init_deliverables();
15880
16142
  BODY2 = 64 * 1024;
@@ -15892,12 +16154,13 @@ var init_planning = __esm(() => {
15892
16154
  });
15893
16155
 
15894
16156
  // src/hub/roadmap.ts
15895
- var MILESTONE_STATES, MILESTONE_HORIZONS, MILESTONE_LINK_KINDS, MILESTONE_LIMITS;
16157
+ var MILESTONE_STATES, MILESTONE_HORIZONS, MILESTONE_LINK_KINDS, MILESTONE_LIMITS, DECOMPOSE_LIMITS;
15896
16158
  var init_roadmap = __esm(() => {
15897
16159
  MILESTONE_STATES = ["proposed", "planned", "active", "done", "dropped"];
15898
16160
  MILESTONE_HORIZONS = ["now", "next", "later"];
15899
16161
  MILESTONE_LINK_KINDS = ["spec", "issue", "task", "release"];
15900
16162
  MILESTONE_LIMITS = Object.freeze({ title: 300, outcome: 4000, spec: 160, issue: 300, actor: 64 });
16163
+ DECOMPOSE_LIMITS = Object.freeze({ parts: 8, title: 300, detail: 1200, cites: 16 });
15901
16164
  });
15902
16165
 
15903
16166
  // src/hub/research-campaign.ts
@@ -15922,7 +16185,7 @@ var init_considered_findings = __esm(() => {
15922
16185
  });
15923
16186
 
15924
16187
  // src/hub/board.ts
15925
- var SURVEY_STORE_BYTES, GUIDANCE_VARIANT_SELECT, HOST_MERGE_ADOPTION, HOST_SPEC_ACCEPTANCE_CARRY, EXECUTION_REFERENCE_SELECT, CLASSES2, SPEC_ACCEPTANCE_FIELD_BYTES, SPEC_ACCEPTANCE_TOTAL_BYTES, PLAN_KEYS, ALL_PLAN_KEYS, OUTCOMES_KEPT_MS;
16188
+ var SURVEY_STORE_BYTES, GUIDANCE_VARIANT_SELECT, HOST_MERGE_ADOPTION, HOST_SPEC_ACCEPTANCE_CARRY, HOST_ROADMAP_DRAFT, EXECUTION_REFERENCE_SELECT, CLASSES2, SPEC_ACCEPTANCE_FIELD_BYTES, SPEC_ACCEPTANCE_TOTAL_BYTES, PLAN_KEYS, ALL_PLAN_KEYS, OUTCOMES_KEPT_MS;
15926
16189
  var init_board = __esm(() => {
15927
16190
  init_tool_refusal();
15928
16191
  init_guidance_variants();
@@ -15955,6 +16218,7 @@ var init_board = __esm(() => {
15955
16218
  CASE WHEN withdrawn_by IS NULL OR typeof(withdrawn_by)='text' AND length(CAST(withdrawn_by AS BLOB))<=${EXECUTION_REFERENCE_LIMITS.id} THEN 1 ELSE 0 END AS valid_withdrawn_by`;
15956
16219
  HOST_MERGE_ADOPTION = Symbol("host merge adoption");
15957
16220
  HOST_SPEC_ACCEPTANCE_CARRY = Symbol("host spec acceptance carry");
16221
+ HOST_ROADMAP_DRAFT = Symbol("host roadmap acceptance draft");
15958
16222
  EXECUTION_REFERENCE_SELECT = `SELECT
15959
16223
  CASE WHEN length(CAST(id AS BLOB))=64 THEN id END AS id,
15960
16224
  CASE WHEN length(CAST(project_id AS BLOB)) BETWEEN 1 AND 256 THEN project_id END AS project_id,
@@ -16292,7 +16556,7 @@ var init_config2 = __esm(() => {
16292
16556
  });
16293
16557
 
16294
16558
  // src/hub/routing.ts
16295
- import { join as join20, resolve as resolve13 } from "path";
16559
+ import { join as join21, resolve as resolve13 } from "path";
16296
16560
  function effectiveLocalRoute(defaultRoute, classRoute, classFixedModel) {
16297
16561
  return classRoute ?? (classFixedModel === undefined ? defaultRoute : undefined);
16298
16562
  }
@@ -16306,7 +16570,7 @@ var init_routing = __esm(() => {
16306
16570
  init_spec_read();
16307
16571
  init_config2();
16308
16572
  init_stage_fallback();
16309
- TEMPLATE = join20(import.meta.dir, "..", "..", "templates", "routing.toml");
16573
+ TEMPLATE = join21(import.meta.dir, "..", "..", "templates", "routing.toml");
16310
16574
  cache = new Map;
16311
16575
  });
16312
16576
 
@@ -18839,8 +19103,10 @@ var init_hub_tools = __esm(() => {
18839
19103
  TASK_TOOLS = [
18840
19104
  tool2("hub_roadmap_list", "Read public milestones with computed task/issue/spec/train progress. Private work is a count only; unknown evidence stays unknown. Read only, with no GitHub or model call.", {}),
18841
19105
  tool2("hub_roadmap_show", "Read a milestone's public links, inherited membership and computed progress. Inspect this before editing and copy its current revision. Private tasks are counts only.", { id: { type: "integer", minimum: 1 } }, ["id"]),
19106
+ tool2("hub_roadmap_check", "Read roadmap drift findings and unknown evidence. Private tasks stay withheld; no writes are made.", {}),
18842
19107
  tool2("hub_roadmap_unplaced", "Read the open GitHub issues, open board tasks and active/draft specs that no live milestone places, each with why. Private tasks are a count only. partial: true means the GitHub read stopped early or a list was cut, so the lists are a lower bound; unavailable names evidence that could not be read. Read only: no write, no model call. Optional repo is owner/name.", { repo: { type: "string", maxLength: MILESTONE_LIMITS.issue } }),
18843
19108
  tool2("hub_roadmap_triage", "Ask the hub's model to suggest a milestone (or a new one) for unplaced work. Each suggestion cites the milestone and item words it matched and is saved as a pending model answer; nothing is linked until hub_roadmap_edit accept. Configured planner or unique conductor only. list: true reads the pending public suggestions without a model call and is open to any agent.", { repo: { type: "string", maxLength: MILESTONE_LIMITS.issue }, list: { type: "boolean" } }),
19109
+ tool2("hub_roadmap_decompose", "Ask the hub's model to decompose one milestone into parts, from its outcome, the specs it links and the issues it links. Each part cites linked ids and says whether it needs a spec issue or goes straight to a task; the answer is saved as a pending model answer and nothing is linked, intaken or published. Pass accept with one part's number to hold that part as an intake draft instead: it is linked to the milestone, carries the part's spec-issue or task kind, and is offered to nobody until the person releases it with ahub intake approve. Configured planner or unique conductor only. On refusal inspect hub_roadmap_show and correct the named input.", { id: { type: "integer", minimum: 1 }, accept: { type: "integer", minimum: 1 } }, ["id"]),
18844
19110
  tool2("hub_roadmap_edit", "Create or change a milestone. Configured planner or unique conductor only; done/dropped are person-only. new/edit take fields; edit also needs the current revision. Link kinds are spec/issue/task/release; issue refs are owner/repo#N. accept applies exactly one pending triage suggestion through link (creating its proposed milestone first); reject drops it. No GitHub write, task assignment or model call. On refusal inspect hub_roadmap_show and correct the named input.", {
18845
19111
  op: { type: "string", enum: ["new", "edit", "link", "unlink", "order", "state", "accept", "reject"] },
18846
19112
  id: { type: "integer", minimum: 1 },
@@ -19484,7 +19750,7 @@ var init_local_worker = __esm(() => {
19484
19750
  }
19485
19751
  const taskToolName = name.replace(/^mcp__[^ ]+__/, "");
19486
19752
  const reviewNoteWrite = taskToolName === "hub_remember" || taskToolName === "hub_task_propose";
19487
- const toolRun = () => this.probeConfinement && !["read", "write", "edit"].includes(name) ? Promise.resolve(formatProbeToolRefusal(new ProbeToolRefusal("tool_unavailable"))) : reviewScope.excluded && reviewNoteWrite ? Promise.resolve("error: anchored review in this batch; save notes in a later turn") : (TASK_TOOL_NAMES.has(name) || CONDUCTOR_TOOL_NAMES.has(name)) && this.opts.taskTool ? this.opts.taskTool(name, safeParse(call.function.arguments), { pii: !!policy?.pii, signal: turnSignal }).catch((e) => `error: ${e.message}`) : runTool(name, call.function.arguments, ctx);
19753
+ const toolRun = () => this.probeConfinement && !["read", "write", "edit"].includes(name) ? Promise.resolve(formatProbeToolRefusal(new ProbeToolRefusal("tool_unavailable"))) : reviewScope.excluded && reviewNoteWrite ? Promise.resolve("error: anchored review in this batch; save notes in a later turn") : (TASK_TOOL_NAMES.has(name) || CONDUCTOR_TOOL_NAMES.has(name)) && this.opts.taskTool ? this.opts.taskTool(name, safeParse(call.function.arguments), { pii: !!policy?.pii, signal: turnSignal }).catch((e) => `error: ${e.message}`) : runTool(name, call.function.arguments, this.probeConfinement ? ctx : this.toolContext(envs, turnSignal, !!policy?.pii, reply, policy?.task));
19488
19754
  const probe = this.probeSession;
19489
19755
  const running = probe ? (async () => {
19490
19756
  try {
@@ -19548,6 +19814,7 @@ var init_local_worker = __esm(() => {
19548
19814
  ...this.opts.tools.docRead ? { docRead: { ...this.opts.tools.docRead, pii } } : {},
19549
19815
  ...this.opts.tools.webFetch ? { webFetch: { ...this.opts.tools.webFetch, pii } } : {},
19550
19816
  cwd: this.opts.cwd,
19817
+ ...this.opts.tools.editGuard && !probe ? { editGuard: this.opts.tools.editGuard(task, () => !turnSignal.aborted && executionGeneration === this.turn) } : {},
19551
19818
  deny: this.opts.tools.deny,
19552
19819
  readOnly: this.opts.tools.readOnly,
19553
19820
  ...probe ? { probe: {
@@ -19920,12 +20187,12 @@ var init_launch2 = __esm(() => {
19920
20187
 
19921
20188
  // src/adapters/claude-task-sessions.ts
19922
20189
  import { randomUUID as randomUUID8 } from "crypto";
19923
- import { mkdirSync as mkdirSync11, readFileSync as readFileSync9 } from "fs";
19924
- import { dirname as dirname13 } from "path";
20190
+ import { mkdirSync as mkdirSync11, readFileSync as readFileSync10 } from "fs";
20191
+ import { dirname as dirname14 } from "path";
19925
20192
  function readState(file) {
19926
20193
  let text;
19927
20194
  try {
19928
- text = readFileSync9(file, "utf8");
20195
+ text = readFileSync10(file, "utf8");
19929
20196
  } catch (error) {
19930
20197
  if (error.code === "ENOENT")
19931
20198
  return { version: 1, sessions: {} };
@@ -19958,7 +20225,7 @@ class ClaudeTaskSessions {
19958
20225
  }
19959
20226
  write(sessions) {
19960
20227
  const next = { version: 1, sessions };
19961
- mkdirSync11(dirname13(this.file), { recursive: true, mode: 448 });
20228
+ mkdirSync11(dirname14(this.file), { recursive: true, mode: 448 });
19962
20229
  atomicPrivateJSON(this.file, next);
19963
20230
  this.state = next;
19964
20231
  }
@@ -20052,9 +20319,9 @@ __export(exports_claude_implementer, {
20052
20319
  ClaudeImplementerPeer: () => ClaudeImplementerPeer
20053
20320
  });
20054
20321
  import { randomUUID as randomUUID9 } from "crypto";
20055
- import { lstatSync as lstatSync18, mkdtempSync as mkdtempSync6, rmSync as rmSync7, writeFileSync as writeFileSync9 } from "fs";
20322
+ import { lstatSync as lstatSync19, mkdtempSync as mkdtempSync6, rmSync as rmSync8, writeFileSync as writeFileSync9 } from "fs";
20056
20323
  import { tmpdir as tmpdir5 } from "os";
20057
- import { join as join21 } from "path";
20324
+ import { join as join22 } from "path";
20058
20325
  function provenVersion(binding) {
20059
20326
  return provenVersions.get(binding);
20060
20327
  }
@@ -20110,10 +20377,10 @@ function claudeImplementerArgs(turn, mcp, settings, prompt, model) {
20110
20377
  async function proveClaudeImplementer(peer, command) {
20111
20378
  const binary = Bun.which(command[0], { PATH: process.env.PATH }) ?? command[0];
20112
20379
  const fingerprint = () => {
20113
- const file = realPath(binary), stat = lstatSync18(file);
20380
+ const file = realPath(binary), stat = lstatSync19(file);
20114
20381
  return [file, stat.dev, stat.ino, stat.size, stat.mtimeMs, stat.ctimeMs].join(":");
20115
20382
  };
20116
- const binding = fingerprint(), home = mkdtempSync6(join21(tmpdir5(), "ahub-claude-proof-"));
20383
+ const binding = fingerprint(), home = mkdtempSync6(join22(tmpdir5(), "ahub-claude-proof-"));
20117
20384
  let version = "", timedOut = false;
20118
20385
  const child = new OwnedPrintChild({
20119
20386
  peer,
@@ -20122,7 +20389,7 @@ async function proveClaudeImplementer(peer, command) {
20122
20389
  cwd: home,
20123
20390
  input: "",
20124
20391
  envMode: "replace",
20125
- env: { PATH: process.env.PATH, HOME: home, CLAUDE_CONFIG_DIR: join21(home, ".claude") },
20392
+ env: { PATH: process.env.PATH, HOME: home, CLAUDE_CONFIG_DIR: join22(home, ".claude") },
20126
20393
  maxFrameBytes: 4096,
20127
20394
  maxOutputBytes: 4096,
20128
20395
  onLine: (line) => {
@@ -20158,7 +20425,7 @@ async function proveClaudeImplementer(peer, command) {
20158
20425
  } finally {
20159
20426
  clearTimeout(timer);
20160
20427
  await child.stop();
20161
- rmSync7(home, { recursive: true, force: true });
20428
+ rmSync8(home, { recursive: true, force: true });
20162
20429
  }
20163
20430
  }
20164
20431
  var provenVersions, ClaudeImplementerPeer;
@@ -20209,7 +20476,7 @@ var init_claude_implementer = __esm(() => {
20209
20476
  if (options.mode !== undefined && options.mode !== "ask" && options.mode !== "ask-when-needed")
20210
20477
  throw new Error("Claude implementer refuses unsupported permission mode");
20211
20478
  this.mode = options.mode ?? "ask";
20212
- this.sessions = new ClaudeTaskSessions(join21(options.stateDir, claudeStateFile("claude-task-sessions", id)));
20479
+ this.sessions = new ClaudeTaskSessions(join22(options.stateDir, claudeStateFile("claude-task-sessions", id)));
20213
20480
  }
20214
20481
  get permissionModeState() {
20215
20482
  return this.mode;
@@ -20378,9 +20645,9 @@ var init_claude_implementer = __esm(() => {
20378
20645
  this.observerSessionIdValue = turn.sessionId;
20379
20646
  this.currentInputContext = inputContext;
20380
20647
  this.options.beforeInput?.(inputContext, group.envs);
20381
- const launchId = randomUUID9(), directory = mkdtempSync6(join21(this.options.stateDir, "claude-child-")), settings = join21(directory, "settings.json");
20648
+ const launchId = randomUUID9(), directory = mkdtempSync6(join22(this.options.stateDir, "claude-child-")), settings = join22(directory, "settings.json");
20382
20649
  let launchFailureTrace;
20383
- this.cleanup = () => rmSync7(directory, { recursive: true, force: true });
20650
+ this.cleanup = () => rmSync8(directory, { recursive: true, force: true });
20384
20651
  writeFileSync9(settings, sessionSettings(undefined, { script: this.options.factsHook, stateDir: this.options.stateDir, purpose: "permission" }), { mode: 384, flag: "wx" });
20385
20652
  const env = {
20386
20653
  AGENTHUB_MODE: "tools",
@@ -20723,9 +20990,9 @@ var init_reviewer_variants = __esm(() => {
20723
20990
  });
20724
20991
 
20725
20992
  // src/adapters/agy/hooks.ts
20726
- import { closeSync as closeSync10, constants as constants9, fstatSync as fstatSync9, lstatSync as lstatSync19, openSync as openSync10, readSync as readSync7 } from "fs";
20993
+ import { closeSync as closeSync12, constants as constants9, fstatSync as fstatSync11, lstatSync as lstatSync20, openSync as openSync12, readSync as readSync9 } from "fs";
20727
20994
  import { homedir as homedir5 } from "os";
20728
- import { isAbsolute as isAbsolute7, join as join22, relative as relative5 } from "path";
20995
+ import { isAbsolute as isAbsolute7, join as join23, relative as relative5 } from "path";
20729
20996
  import { createHash as createHash12 } from "crypto";
20730
20997
  function agyModel(value) {
20731
20998
  const model = safeModelLabel(value);
@@ -20780,19 +21047,19 @@ function readAgyTranscript(session, transcript, options) {
20780
21047
  if (!UUID2.test(session))
20781
21048
  return empty;
20782
21049
  const home = process.env.HOME ?? homedir5();
20783
- const candidates = ["antigravity-cli", "antigravity", "antigravity-ide"].map((surface) => join22(home, ".gemini", surface, "brain", session, ".system_generated/logs/transcript_full.jsonl"));
21050
+ const candidates = ["antigravity-cli", "antigravity", "antigravity-ide"].map((surface) => join23(home, ".gemini", surface, "brain", session, ".system_generated/logs/transcript_full.jsonl"));
20784
21051
  if (!candidates.includes(transcript))
20785
21052
  return empty;
20786
21053
  let fd;
20787
21054
  try {
20788
21055
  let cursor = home;
20789
21056
  for (const name of relative5(home, transcript).split("/")) {
20790
- cursor = join22(cursor, name);
20791
- if (lstatSync19(cursor).isSymbolicLink())
21057
+ cursor = join23(cursor, name);
21058
+ if (lstatSync20(cursor).isSymbolicLink())
20792
21059
  return empty;
20793
21060
  }
20794
- fd = openSync10(transcript, constants9.O_RDONLY | constants9.O_NOFOLLOW);
20795
- const stat = fstatSync9(fd);
21061
+ fd = openSync12(transcript, constants9.O_RDONLY | constants9.O_NOFOLLOW);
21062
+ const stat = fstatSync11(fd);
20796
21063
  if (!stat.isFile() || stat.nlink !== 1)
20797
21064
  return empty;
20798
21065
  if (options?.unchanged && stat.size === options.unchanged.size && stat.mtimeMs === options.unchanged.mtimeMs)
@@ -20807,7 +21074,7 @@ function readAgyTranscript(session, transcript, options) {
20807
21074
  const buffer = Buffer.alloc(stat.size - from);
20808
21075
  let bytes = 0;
20809
21076
  while (bytes < buffer.length) {
20810
- const count = readSync7(fd, buffer, bytes, buffer.length - bytes, from + bytes);
21077
+ const count = readSync9(fd, buffer, bytes, buffer.length - bytes, from + bytes);
20811
21078
  if (!count)
20812
21079
  break;
20813
21080
  bytes += count;
@@ -20868,7 +21135,7 @@ function readAgyTranscript(session, transcript, options) {
20868
21135
  return empty;
20869
21136
  } finally {
20870
21137
  if (fd !== undefined)
20871
- closeSync10(fd);
21138
+ closeSync12(fd);
20872
21139
  }
20873
21140
  }
20874
21141
  var EVENTS2, UUID2, record6 = (value) => !!value && typeof value === "object" && !Array.isArray(value), AGY_FACTS_HOOK;
@@ -20946,8 +21213,8 @@ function builtinCliEntries(definitions) {
20946
21213
  return Object.freeze(definitions.flatMap((definition) => definition.cli.entry ? [Object.freeze({ ...definition.cli.entry, command: definition.cli.command })] : []));
20947
21214
  }
20948
21215
  // src/adapters/definitions/native-cli-entry-claude.ts
20949
- import { readFileSync as readFileSync10 } from "fs";
20950
- import { join as join23 } from "path";
21216
+ import { readFileSync as readFileSync11 } from "fs";
21217
+ import { join as join24 } from "path";
20951
21218
  import { randomUUID as randomUUID10 } from "crypto";
20952
21219
  async function runClaudeEntry(ctx) {
20953
21220
  const { args, cwd, stateDir, cliDir, unattendedEnv, projectConfig, fail } = ctx;
@@ -20998,17 +21265,17 @@ async function runClaudeEntry(ctx) {
20998
21265
  }
20999
21266
  }
21000
21267
  let original;
21001
- for (const file of [join23(executionCwd, ".claude", "settings.local.json"), join23(executionCwd, ".claude", "settings.json"), join23(process.env.HOME ?? "", ".claude", "settings.json")]) {
21268
+ for (const file of [join24(executionCwd, ".claude", "settings.local.json"), join24(executionCwd, ".claude", "settings.json"), join24(process.env.HOME ?? "", ".claude", "settings.json")]) {
21002
21269
  try {
21003
- original ??= JSON.parse(readFileSync10(file, "utf8")).statusLine;
21270
+ original ??= JSON.parse(readFileSync11(file, "utf8")).statusLine;
21004
21271
  } catch {}
21005
21272
  }
21006
- const facts = claudeObservationHooks(projectConfig(), { script: join23(cliDir, "facts-hook.ts"), stateDir });
21273
+ const facts = claudeObservationHooks(projectConfig(), { script: join24(cliDir, "facts-hook.ts"), stateDir });
21007
21274
  let previousLaunch;
21008
21275
  try {
21009
- previousLaunch = JSON.parse(readFileSync10(join23(stateDir, claudeStateFile("claude-launch", peer)), "utf8"));
21276
+ previousLaunch = JSON.parse(readFileSync11(join24(stateDir, claudeStateFile("claude-launch", peer)), "utf8"));
21010
21277
  } catch {}
21011
- const launch = buildLaunch("claude", args, { unattended: unattendedEnv, statusLine: { script: join23(cliDir, "statusline-tee.ts"), stateDir, ...original ? { original } : {} }, ...facts ? { facts } : {} });
21278
+ const launch = buildLaunch("claude", args, { unattended: unattendedEnv, statusLine: { script: join24(cliDir, "statusline-tee.ts"), stateDir, ...original ? { original } : {} }, ...facts ? { facts } : {} });
21012
21279
  let result;
21013
21280
  try {
21014
21281
  let launchRecord;
@@ -21102,15 +21369,15 @@ var init_native_cli_entry_codex = () => {};
21102
21369
 
21103
21370
  // src/cli/kimi-plugin.ts
21104
21371
  import { randomUUID as randomUUID11 } from "crypto";
21105
- import { closeSync as closeSync11, lstatSync as lstatSync20, mkdirSync as mkdirSync12, openSync as openSync11, readFileSync as readFileSync11, renameSync as renameSync5, rmdirSync as rmdirSync4, unlinkSync as unlinkSync4, writeFileSync as writeFileSync10 } from "fs";
21106
- import { dirname as dirname14, isAbsolute as isAbsolute8, join as join24 } from "path";
21372
+ import { closeSync as closeSync13, lstatSync as lstatSync21, mkdirSync as mkdirSync12, openSync as openSync13, readFileSync as readFileSync12, renameSync as renameSync6, rmdirSync as rmdirSync4, unlinkSync as unlinkSync4, writeFileSync as writeFileSync10 } from "fs";
21373
+ import { dirname as dirname15, isAbsolute as isAbsolute8, join as join25 } from "path";
21107
21374
  function file(path, cap) {
21108
- const stat = lstatSync20(path, { throwIfNoEntry: false });
21375
+ const stat = lstatSync21(path, { throwIfNoEntry: false });
21109
21376
  if (!stat)
21110
21377
  return;
21111
21378
  if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink !== 1 || stat.size > cap)
21112
21379
  throw new Error(`${path} must be a bounded regular file`);
21113
- return { stat, bytes: readFileSync11(path) };
21380
+ return { stat, bytes: readFileSync12(path) };
21114
21381
  }
21115
21382
  function parse2(value, name) {
21116
21383
  if (!value)
@@ -21125,28 +21392,28 @@ function parse2(value, name) {
21125
21392
  }
21126
21393
  }
21127
21394
  function atomic(path, bytes, before) {
21128
- const current = lstatSync20(path, { throwIfNoEntry: false });
21395
+ const current = lstatSync21(path, { throwIfNoEntry: false });
21129
21396
  if (before ? !current || current.dev !== before.dev || current.ino !== before.ino : current)
21130
21397
  throw new Error(`${path} changed before its managed write`);
21131
21398
  const temporary = `${path}.${randomUUID11()}.tmp`;
21132
21399
  let fd;
21133
21400
  try {
21134
- fd = openSync11(temporary, "wx", 384);
21401
+ fd = openSync13(temporary, "wx", 384);
21135
21402
  writeFileSync10(fd, bytes);
21136
- closeSync11(fd);
21403
+ closeSync13(fd);
21137
21404
  fd = undefined;
21138
- renameSync5(temporary, path);
21405
+ renameSync6(temporary, path);
21139
21406
  } finally {
21140
21407
  if (fd !== undefined)
21141
- closeSync11(fd);
21408
+ closeSync13(fd);
21142
21409
  try {
21143
21410
  unlinkSync4(temporary);
21144
21411
  } catch {}
21145
21412
  }
21146
21413
  }
21147
21414
  function removeFile(path, expected) {
21148
- const current = lstatSync20(path, { throwIfNoEntry: false });
21149
- if (!current || !current.isFile() || current.isSymbolicLink() || current.nlink !== 1 || !readFileSync11(path).equals(expected))
21415
+ const current = lstatSync21(path, { throwIfNoEntry: false });
21416
+ if (!current || !current.isFile() || current.isSymbolicLink() || current.nlink !== 1 || !readFileSync12(path).equals(expected))
21150
21417
  return;
21151
21418
  unlinkSync4(path);
21152
21419
  }
@@ -21176,7 +21443,7 @@ function plan2(options) {
21176
21443
  const hook = file(options.hookScript, MAX_HOOK);
21177
21444
  if (!hook)
21178
21445
  throw new Error("Kimi hook bundle is missing");
21179
- const root = join24(options.home, "plugins"), managed = join24(root, "managed", ID2), installed = join24(root, "installed.json");
21446
+ const root = join25(options.home, "plugins"), managed = join25(root, "managed", ID2), installed = join25(root, "installed.json");
21180
21447
  const installedBefore = file(installed, MAX_INSTALLED), document = parse2(installedBefore, installed);
21181
21448
  if (document && (document.version !== 1 || !Array.isArray(document.plugins)))
21182
21449
  throw new Error(`${installed} has an unsupported shape`);
@@ -21189,11 +21456,11 @@ function plan2(options) {
21189
21456
  if (record && (record.root !== managed || record.source !== "local-path" || record.origin !== "custom" || record.enabled !== true || typeof record.originalSource !== "string" || record.agentHubLaunch !== options.launchId && options.replaceStale !== true)) {
21190
21457
  throw new Error("Kimi's agent-hub plugin belongs to another launch or is disabled; it was not changed");
21191
21458
  }
21192
- const manifestBefore = file(join24(managed, "kimi.plugin.json"), MAX_INSTALLED), hookBefore = file(join24(managed, "kimi-hook.js"), MAX_HOOK);
21459
+ const manifestBefore = file(join25(managed, "kimi.plugin.json"), MAX_INSTALLED), hookBefore = file(join25(managed, "kimi-hook.js"), MAX_HOOK);
21193
21460
  const nextManifest = Buffer.from(`${JSON.stringify(manifest(), null, 2)}
21194
21461
  `);
21195
21462
  const now = new Date(options.now ?? Date.now()).toISOString();
21196
- const changed = !record || record.agentHubLaunch !== options.launchId || !record.agentHubOwner || !manifestBefore?.bytes.equals(nextManifest) || !hookBefore?.bytes.equals(hook.bytes) || record.originalSource !== dirname14(options.hookScript);
21463
+ const changed = !record || record.agentHubLaunch !== options.launchId || !record.agentHubOwner || !manifestBefore?.bytes.equals(nextManifest) || !hookBefore?.bytes.equals(hook.bytes) || record.originalSource !== dirname15(options.hookScript);
21197
21464
  const nextRecord = {
21198
21465
  id: ID2,
21199
21466
  root: managed,
@@ -21202,7 +21469,7 @@ function plan2(options) {
21202
21469
  enabled: true,
21203
21470
  installedAt: typeof record?.installedAt === "string" ? record.installedAt : now,
21204
21471
  updatedAt: changed ? now : typeof record?.updatedAt === "string" ? record.updatedAt : now,
21205
- originalSource: dirname14(options.hookScript),
21472
+ originalSource: dirname15(options.hookScript),
21206
21473
  agentHubLaunch: options.launchId,
21207
21474
  agentHubOwner: record && record.agentHubLaunch === options.launchId && record.agentHubOwner ? record.agentHubOwner : ownerProof(options)
21208
21475
  };
@@ -21214,8 +21481,8 @@ function plan2(options) {
21214
21481
  ...record ? { record } : {},
21215
21482
  changed,
21216
21483
  targets: [
21217
- { path: join24(managed, "kimi.plugin.json"), next: nextManifest, ...manifestBefore ? { before: manifestBefore } : {} },
21218
- { path: join24(managed, "kimi-hook.js"), next: hook.bytes, ...hookBefore ? { before: hookBefore } : {} },
21484
+ { path: join25(managed, "kimi.plugin.json"), next: nextManifest, ...manifestBefore ? { before: manifestBefore } : {} },
21485
+ { path: join25(managed, "kimi-hook.js"), next: hook.bytes, ...hookBefore ? { before: hookBefore } : {} },
21219
21486
  { path: installed, next: Buffer.from(`${JSON.stringify(nextDocument, null, 2)}
21220
21487
  `), ...installedBefore ? { before: installedBefore } : {} }
21221
21488
  ]
@@ -21227,23 +21494,23 @@ function kimiPluginPreview(home, hookScript) {
21227
21494
  directory(home, false);
21228
21495
  if (!file(hookScript, MAX_HOOK))
21229
21496
  throw new Error("Kimi hook bundle is missing");
21230
- return { file: join24(home, "plugins", "managed", ID2), changed: true, action: "only after Kimi 2.5.2 is confirmed, install the launch-scoped completion plugin and remove it on exit; other versions keep the existing TUI with no plugin" };
21497
+ return { file: join25(home, "plugins", "managed", ID2), changed: true, action: "only after Kimi 2.5.2 is confirmed, install the launch-scoped completion plugin and remove it on exit; other versions keep the existing TUI with no plugin" };
21231
21498
  }
21232
21499
  function locked(options, run) {
21233
21500
  if (!isAbsolute8(options.home))
21234
21501
  throw new Error("Kimi home must be an absolute path");
21235
21502
  directory(options.home);
21236
- const path = join24(options.home, "agent-hub-plugin.lock");
21503
+ const path = join25(options.home, "agent-hub-plugin.lock");
21237
21504
  let fd;
21238
21505
  try {
21239
- fd = openSync11(path, "wx", 384);
21506
+ fd = openSync13(path, "wx", 384);
21240
21507
  } catch {
21241
21508
  throw new Error(`Another Kimi plugin replacement is active or left a stale lock; retry after it exits or inspect ${path}`);
21242
21509
  }
21243
21510
  try {
21244
21511
  return run();
21245
21512
  } finally {
21246
- closeSync11(fd);
21513
+ closeSync13(fd);
21247
21514
  unlinkSync4(path);
21248
21515
  }
21249
21516
  }
@@ -21252,7 +21519,7 @@ function ensureKimiPlugin(options) {
21252
21519
  const current = plan2(options);
21253
21520
  if (!current.changed)
21254
21521
  return { changed: false };
21255
- for (const path of [join24(options.home, "plugins"), join24(options.home, "plugins", "managed"), current.managed]) {
21522
+ for (const path of [join25(options.home, "plugins"), join25(options.home, "plugins", "managed"), current.managed]) {
21256
21523
  if (!directory(path, false))
21257
21524
  mkdirSync12(path, { mode: 448 });
21258
21525
  }
@@ -21277,15 +21544,15 @@ function cleanupKimiPlugin(options) {
21277
21544
  atomic(current.installed, Buffer.from(`${JSON.stringify(next, null, 2)}
21278
21545
  `), installedBefore?.stat);
21279
21546
  const [manifestTarget, hookTarget] = current.targets;
21280
- removeFile(join24(current.managed, "kimi.plugin.json"), manifestTarget.next);
21281
- removeFile(join24(current.managed, "kimi-hook.js"), hookTarget.next);
21547
+ removeFile(join25(current.managed, "kimi.plugin.json"), manifestTarget.next);
21548
+ removeFile(join25(current.managed, "kimi-hook.js"), hookTarget.next);
21282
21549
  try {
21283
21550
  rmdirSync4(current.managed);
21284
21551
  } catch {}
21285
21552
  });
21286
21553
  }
21287
21554
  var EVENTS3, ID2 = "agent-hub", MAX_INSTALLED, MAX_HOOK, object8 = (value) => !!value && typeof value === "object" && !Array.isArray(value), directory = (path, required = true) => {
21288
- const stat = lstatSync20(path, { throwIfNoEntry: false });
21555
+ const stat = lstatSync21(path, { throwIfNoEntry: false });
21289
21556
  if (stat && (!stat.isDirectory() || stat.isSymbolicLink()))
21290
21557
  throw new Error(`${path} must be a plain directory`);
21291
21558
  if (!stat && required)
@@ -21300,7 +21567,7 @@ var init_kimi_plugin = __esm(() => {
21300
21567
  });
21301
21568
 
21302
21569
  // src/adapters/definitions/native-cli-entry-kimi.ts
21303
- import { join as join25, resolve as resolve14 } from "path";
21570
+ import { join as join26, resolve as resolve14 } from "path";
21304
21571
  import { homedir as homedir6 } from "os";
21305
21572
  import { spawn as spawn10, spawnSync as spawnSync4 } from "child_process";
21306
21573
  import { mkdirSync as mkdirSync13 } from "fs";
@@ -21422,7 +21689,7 @@ async function runKimiEntry(ctx) {
21422
21689
  if (!gate.ok) {
21423
21690
  result = await runKimiTui(launch.cmd, launch.args, cwd, nativeEnv);
21424
21691
  } else {
21425
- const nativeHome = nativeEnv.KIMI_CODE_HOME ?? join25(nativeEnv.HOME ?? homedir6(), ".kimi-code");
21692
+ const nativeHome = nativeEnv.KIMI_CODE_HOME ?? join26(nativeEnv.HOME ?? homedir6(), ".kimi-code");
21426
21693
  let nativeLaunchId, completionEnv, plugin;
21427
21694
  try {
21428
21695
  mkdirSync13(nativeHome, { recursive: true, mode: 448 });
@@ -21431,7 +21698,7 @@ async function runKimiEntry(ctx) {
21431
21698
  throw new Error(native.error ?? "native hook launch was not admitted");
21432
21699
  nativeLaunchId = native.launchId;
21433
21700
  plugin = { home: nativeHome, hookScript: resolve14(serverBundle, "../kimi-hook.js"), launchId: native.launchId, replaceStale: true };
21434
- console.error(`Kimi TUI completion facts: installing a launch-scoped native plugin under ${join25(nativeHome, "plugins", "managed", "agent-hub")}; it will be removed after this TUI exits`);
21701
+ console.error(`Kimi TUI completion facts: installing a launch-scoped native plugin under ${join26(nativeHome, "plugins", "managed", "agent-hub")}; it will be removed after this TUI exits`);
21435
21702
  ensureKimiPlugin(plugin);
21436
21703
  completionEnv = { ...nativeEnv, AGENTHUB_INSTANCE_ID: native.instanceId, AGENTHUB_LAUNCH_ID: native.launchId, AGENTHUB_HOOK_PURPOSE: "facts" };
21437
21704
  } catch (error) {
@@ -21442,7 +21709,7 @@ async function runKimiEntry(ctx) {
21442
21709
  try {
21443
21710
  cleanupKimiPlugin(plugin);
21444
21711
  } catch {
21445
- console.error(`Managed Kimi plugin cleanup refused: files or ownership changed; inspect ${join25(nativeHome, "plugins", "managed", "agent-hub")} before removing it`);
21712
+ console.error(`Managed Kimi plugin cleanup refused: files or ownership changed; inspect ${join26(nativeHome, "plugins", "managed", "agent-hub")} before removing it`);
21446
21713
  }
21447
21714
  }
21448
21715
  if (completionEnv) {
@@ -21455,7 +21722,7 @@ async function runKimiEntry(ctx) {
21455
21722
  try {
21456
21723
  cleanupKimiPlugin(plugin);
21457
21724
  } catch {
21458
- console.error(`Managed Kimi plugin cleanup refused: files or ownership changed; inspect ${join25(nativeHome, "plugins", "managed", "agent-hub")} before removing it`);
21725
+ console.error(`Managed Kimi plugin cleanup refused: files or ownership changed; inspect ${join26(nativeHome, "plugins", "managed", "agent-hub")} before removing it`);
21459
21726
  }
21460
21727
  }
21461
21728
  } else {
@@ -21823,8 +22090,8 @@ var init_native_cli_entry_jcode = __esm(() => {
21823
22090
  });
21824
22091
 
21825
22092
  // src/adapters/definitions/native-cli-preview-claude.ts
21826
- import { readFileSync as readFileSync12 } from "fs";
21827
- import { join as join26 } from "path";
22093
+ import { readFileSync as readFileSync13 } from "fs";
22094
+ import { join as join27 } from "path";
21828
22095
  function previewClaude(ctx) {
21829
22096
  const { args, cwd, stateDir, cliDir, unattended, config } = ctx;
21830
22097
  const { buildLaunch, claudeObservationHooks } = ctx.helpers;
@@ -21832,13 +22099,13 @@ function previewClaude(ctx) {
21832
22099
  let envNames = state.envNames;
21833
22100
  let launch;
21834
22101
  let original;
21835
- for (const file of [join26(cwd, ".claude/settings.local.json"), join26(cwd, ".claude/settings.json"), join26(process.env.HOME ?? "", ".claude/settings.json")]) {
22102
+ for (const file of [join27(cwd, ".claude/settings.local.json"), join27(cwd, ".claude/settings.json"), join27(process.env.HOME ?? "", ".claude/settings.json")]) {
21836
22103
  try {
21837
- original ??= JSON.parse(readFileSync12(file, "utf8")).statusLine;
22104
+ original ??= JSON.parse(readFileSync13(file, "utf8")).statusLine;
21838
22105
  } catch {}
21839
22106
  }
21840
- const facts = claudeObservationHooks(config, { script: join26(cliDir, "facts-hook.ts"), stateDir });
21841
- launch = buildLaunch("claude", args, { preview: true, unattended, statusLine: { script: join26(cliDir, "statusline-tee.ts"), stateDir, ...original ? { original: { command: original.command ? REDACTED : "", ...typeof original.refreshInterval === "number" && Number.isFinite(original.refreshInterval) ? { refreshInterval: original.refreshInterval } : {}, ...typeof original.padding === "number" && Number.isFinite(original.padding) ? { padding: original.padding } : {} } } : {} }, ...facts ? { facts } : {} });
22107
+ const facts = claudeObservationHooks(config, { script: join27(cliDir, "facts-hook.ts"), stateDir });
22108
+ launch = buildLaunch("claude", args, { preview: true, unattended, statusLine: { script: join27(cliDir, "statusline-tee.ts"), stateDir, ...original ? { original: { command: original.command ? REDACTED : "", ...typeof original.refreshInterval === "number" && Number.isFinite(original.refreshInterval) ? { refreshInterval: original.refreshInterval } : {}, ...typeof original.padding === "number" && Number.isFinite(original.padding) ? { padding: original.padding } : {} } } : {} }, ...facts ? { facts } : {} });
21842
22109
  const safeArgs = args.map((arg, i) => {
21843
22110
  if (args[i - 1] === "--settings")
21844
22111
  return "{}";
@@ -21849,7 +22116,7 @@ function previewClaude(ctx) {
21849
22116
  return publicArg(arg);
21850
22117
  });
21851
22118
  const publicLaunch = buildLaunch("claude", safeArgs, { preview: true, unattended, statusLine: {
21852
- script: join26(cliDir, "statusline-tee.ts"),
22119
+ script: join27(cliDir, "statusline-tee.ts"),
21853
22120
  stateDir,
21854
22121
  ...original ? { original: { command: original.command ? REDACTED : "", ...typeof original.refreshInterval === "number" && Number.isFinite(original.refreshInterval) ? { refreshInterval: original.refreshInterval } : {}, ...typeof original.padding === "number" && Number.isFinite(original.padding) ? { padding: original.padding } : {} } } : {}
21855
22122
  }, facts });
@@ -21882,7 +22149,7 @@ function previewCodex(ctx) {
21882
22149
  var init_native_cli_preview_codex = () => {};
21883
22150
 
21884
22151
  // src/adapters/definitions/native-cli-preview-kimi.ts
21885
- import { join as join27 } from "path";
22152
+ import { join as join28 } from "path";
21886
22153
  import { homedir as homedir7 } from "os";
21887
22154
  function previewKimi(ctx) {
21888
22155
  const { args, cwd, stateDir, cliDir, config } = ctx;
@@ -21908,10 +22175,10 @@ function previewKimi(ctx) {
21908
22175
  const nativeEnv = nativeLaunchEnv("kimi", childEnv());
21909
22176
  envNames = Object.keys(nativeEnv).concat(["AGENTHUB_STATE_DIR", "AGENTHUB_PROJECT_DIR", "AGENTHUB_INSTANCE_ID", "AGENTHUB_LAUNCH_ID", "AGENTHUB_HOOK_PURPOSE"]);
21910
22177
  unresolved.push({ field: "nativeLaunchId", reason: "native completion facts bind to the launch admitted by the running hub" });
21911
- const home = nativeEnv.KIMI_CODE_HOME ?? join27(nativeEnv.HOME ?? homedir7(), ".kimi-code");
21912
- completionPlugin = kimiPluginPreview(home, join27(cliDir, "../../plugins/agent-hub/kimi-hook.js"));
22178
+ const home = nativeEnv.KIMI_CODE_HOME ?? join28(nativeEnv.HOME ?? homedir7(), ".kimi-code");
22179
+ completionPlugin = kimiPluginPreview(home, join28(cliDir, "../../plugins/agent-hub/kimi-hook.js"));
21913
22180
  }
21914
- const { file, action, changed, tracked } = kimiMcpPlan(cwd, stateDir, join27(cliDir, "../../plugins/agent-hub/server.js"), mode);
22181
+ const { file, action, changed, tracked } = kimiMcpPlan(cwd, stateDir, join28(cliDir, "../../plugins/agent-hub/server.js"), mode);
21915
22182
  kimiMetadata = { mode, mcp: { file, action, changed, tracked }, ...completionPlugin ? { completionPlugin } : {} };
21916
22183
  return finishPreview(ctx, launch, envNames, unresolved, kimiMetadata);
21917
22184
  }
@@ -21920,7 +22187,7 @@ var init_native_cli_preview_kimi = __esm(() => {
21920
22187
  });
21921
22188
 
21922
22189
  // src/adapters/definitions/native-cli-preview-pi.ts
21923
- import { join as join28, resolve as resolve16 } from "path";
22190
+ import { join as join29, resolve as resolve16 } from "path";
21924
22191
  function previewPi(ctx) {
21925
22192
  const { args, stateDir, cliDir, config } = ctx;
21926
22193
  const { relayModelIds, buildPiLaunch, startModeOf } = ctx.helpers;
@@ -21955,7 +22222,7 @@ function previewPi(ctx) {
21955
22222
  tools: [],
21956
22223
  preamble: REDACTED,
21957
22224
  maxSteps: config.pi.max_steps
21958
- }, {}, resolve16(join28(cliDir, "../pi/extension.ts")), UNRESOLVED, UNRESOLVED);
22225
+ }, {}, resolve16(join29(cliDir, "../pi/extension.ts")), UNRESOLVED, UNRESOLVED);
21959
22226
  launch = pi;
21960
22227
  envNames = Object.keys(pi.env).concat(["PATH", "HOME", "USER", "SHELL", "TMPDIR", "TERM", "TERM_PROGRAM", "LANG", "LC_ALL", "LC_CTYPE", "NO_COLOR", "CODEX_HOME"].filter((key) => process.env[key] !== undefined));
21961
22228
  if (mode === "tui")
@@ -22045,8 +22312,8 @@ var init_native_config_policy = __esm(() => {
22045
22312
  });
22046
22313
 
22047
22314
  // src/adapters/definitions/native-policy-aux.ts
22048
- import { closeSync as closeSync12, constants as constants10, fstatSync as fstatSync10, openSync as openSync12, readdirSync as readdirSync4, readFileSync as readFileSync13 } from "fs";
22049
- import { isAbsolute as isAbsolute9, join as join29, normalize } from "path";
22315
+ import { closeSync as closeSync14, constants as constants10, fstatSync as fstatSync12, openSync as openSync14, readdirSync as readdirSync5, readFileSync as readFileSync14 } from "fs";
22316
+ import { isAbsolute as isAbsolute9, join as join30, normalize } from "path";
22050
22317
  function claudeCrashPlan(_meta) {
22051
22318
  return { how: "claude: the Claude Code plugin reconnects by itself while that session is still open" };
22052
22319
  }
@@ -22091,13 +22358,13 @@ function localCrashPlan(meta) {
22091
22358
  }
22092
22359
  function claudePlugins(root, cwd) {
22093
22360
  const enabled = new Map;
22094
- for (const file of [join29(root, "settings.json"), ...cwd ? [join29(cwd, ".claude", "settings.json"), join29(cwd, ".claude", "settings.local.json")] : []]) {
22361
+ for (const file of [join30(root, "settings.json"), ...cwd ? [join30(cwd, ".claude", "settings.json"), join30(cwd, ".claude", "settings.local.json")] : []]) {
22095
22362
  const map = json(file)?.enabledPlugins;
22096
22363
  if (map && typeof map === "object")
22097
22364
  for (const [key, on] of Object.entries(map))
22098
22365
  enabled.set(key, on === true);
22099
22366
  }
22100
- const installed = json(join29(root, "plugins", "installed_plugins.json"))?.plugins ?? {};
22367
+ const installed = json(join30(root, "plugins", "installed_plugins.json"))?.plugins ?? {};
22101
22368
  const out = [];
22102
22369
  for (const [key, on] of enabled) {
22103
22370
  if (!on)
@@ -22111,7 +22378,7 @@ function claudePlugins(root, cwd) {
22111
22378
  return out;
22112
22379
  }
22113
22380
  function codexPlugins(root) {
22114
- const config = text2(join29(root, "config.toml"));
22381
+ const config = text2(join30(root, "config.toml"));
22115
22382
  if (config === undefined)
22116
22383
  return [];
22117
22384
  const found = new Map, disabled = new Set;
@@ -22130,7 +22397,7 @@ function codexPlugins(root) {
22130
22397
  continue;
22131
22398
  let versions = [];
22132
22399
  try {
22133
- versions = readdirSync4(join29(root, "plugins", "cache", market, plugin));
22400
+ versions = readdirSync5(join30(root, "plugins", "cache", market, plugin));
22134
22401
  } catch {}
22135
22402
  out.push({ name, version: versions.length === 1 ? version2(versions[0]) : null });
22136
22403
  }
@@ -22150,16 +22417,16 @@ function absoluteContinuityPath(value) {
22150
22417
  var str3 = (value) => typeof value === "string" && value ? value : undefined, PLUGINS, CLAUDE_ONLY, text2 = (file) => {
22151
22418
  let fd;
22152
22419
  try {
22153
- fd = openSync12(file, constants10.O_RDONLY | constants10.O_NONBLOCK);
22154
- const st = fstatSync10(fd);
22420
+ fd = openSync14(file, constants10.O_RDONLY | constants10.O_NONBLOCK);
22421
+ const st = fstatSync12(fd);
22155
22422
  if (!st.isFile() || st.size > 1024 * 1024)
22156
22423
  return;
22157
- return readFileSync13(fd, "utf8");
22424
+ return readFileSync14(fd, "utf8");
22158
22425
  } catch {
22159
22426
  return;
22160
22427
  } finally {
22161
22428
  if (fd !== undefined)
22162
- closeSync12(fd);
22429
+ closeSync14(fd);
22163
22430
  }
22164
22431
  }, json = (file) => {
22165
22432
  try {
@@ -22168,7 +22435,7 @@ var str3 = (value) => typeof value === "string" && value ? value : undefined, PL
22168
22435
  } catch {
22169
22436
  return;
22170
22437
  }
22171
- }, version2 = (v) => typeof v === "string" && /^[0-9A-Za-z.+_-]{1,40}$/.test(v) ? v : null, claudePluginInventory = (ctx) => claudePlugins(ctx.env.CLAUDE_CONFIG_DIR?.trim() || join29(ctx.home, ".claude"), ctx.cwd), codexPluginInventory = (ctx) => codexPlugins(ctx.env.CODEX_HOME?.trim() || join29(ctx.home, ".codex")), codexToolSemantic = (name, _command) => name.toLowerCase() === "filechange" ? "edit" : undefined;
22438
+ }, version2 = (v) => typeof v === "string" && /^[0-9A-Za-z.+_-]{1,40}$/.test(v) ? v : null, claudePluginInventory = (ctx) => claudePlugins(ctx.env.CLAUDE_CONFIG_DIR?.trim() || join30(ctx.home, ".claude"), ctx.cwd), codexPluginInventory = (ctx) => codexPlugins(ctx.env.CODEX_HOME?.trim() || join30(ctx.home, ".codex")), codexToolSemantic = (name, _command) => name.toLowerCase() === "filechange" ? "edit" : undefined;
22172
22439
  var init_native_policy_aux = __esm(() => {
22173
22440
  PLUGINS = new Map([["claude-mem", "claude-mem"], ["ponytail", "ponytail"], ["open-code-review", "open-code-review"]]);
22174
22441
  CLAUDE_ONLY = new Map([["codex@openai-codex", "codex-plugin"]]);
@@ -22211,9 +22478,9 @@ var init_native_cli_launch_common = __esm(() => {
22211
22478
  });
22212
22479
 
22213
22480
  // src/adapters/definitions/native-cli-claude-launch.ts
22214
- import { mkdirSync as mkdirSync14, writeFileSync as writeFileSync11, renameSync as renameSync6, unlinkSync as unlinkSync5, readFileSync as readFileSync14 } from "fs";
22481
+ import { mkdirSync as mkdirSync14, writeFileSync as writeFileSync11, renameSync as renameSync7, unlinkSync as unlinkSync5, readFileSync as readFileSync15 } from "fs";
22215
22482
  import { randomUUID as randomUUID12 } from "crypto";
22216
- import { resolve as resolve17, join as join30 } from "path";
22483
+ import { resolve as resolve17, join as join31 } from "path";
22217
22484
  function claudeChannel(userArgs) {
22218
22485
  const bundle = resolve17(import.meta.dir, "../../../plugins/agent-hub/server.js");
22219
22486
  for (let i = 0;i < userArgs.length; i++) {
@@ -22222,7 +22489,7 @@ function claudeChannel(userArgs) {
22222
22489
  if (!path)
22223
22490
  continue;
22224
22491
  try {
22225
- const server = JSON.parse(readFileSync14(resolve17(path), "utf8")).mcpServers?.["agent-hub"];
22492
+ const server = JSON.parse(readFileSync15(resolve17(path), "utf8")).mcpServers?.["agent-hub"];
22226
22493
  if (server?.command === "bun" && Array.isArray(server.args) && server.args.some((value) => typeof value === "string" && resolve17(value) === bundle))
22227
22494
  return "server:agent-hub";
22228
22495
  } catch {}
@@ -22246,7 +22513,7 @@ function claudeNativeLaunch(ctx) {
22246
22513
  throw new Error("--settings requires a JSON object or readable file so the hub permission hook can be installed");
22247
22514
  let caller;
22248
22515
  try {
22249
- caller = JSON.parse(value.trim().startsWith("{") ? value : readFileSync14(resolve17(value), "utf8"));
22516
+ caller = JSON.parse(value.trim().startsWith("{") ? value : readFileSync15(resolve17(value), "utf8"));
22250
22517
  if (!caller || typeof caller !== "object" || Array.isArray(caller))
22251
22518
  throw new Error("not an object");
22252
22519
  } catch {
@@ -22275,11 +22542,11 @@ function claudeNativeLaunch(ctx) {
22275
22542
  const stateDir = ctx.facts?.stateDir ?? ctx.statusLine?.stateDir;
22276
22543
  if (!stateDir)
22277
22544
  throw new Error("Claude session settings require the hub state directory");
22278
- const file = join30(stateDir, `claude-settings-${randomUUID12()}.json`);
22545
+ const file = join31(stateDir, `claude-settings-${randomUUID12()}.json`);
22279
22546
  try {
22280
22547
  mkdirSync14(stateDir, { recursive: true, mode: 448 });
22281
22548
  writeFileSync11(`${file}.tmp`, settingsArgs[1], { mode: 384, flag: "wx" });
22282
- renameSync6(`${file}.tmp`, file);
22549
+ renameSync7(`${file}.tmp`, file);
22283
22550
  } catch {
22284
22551
  try {
22285
22552
  unlinkSync5(`${file}.tmp`);
@@ -22331,44 +22598,20 @@ var init_native_cli_codex_launch = __esm(() => {
22331
22598
  CODEX_LAUNCH_POLICY = Object.freeze({ hubSwitches: Object.freeze(["--unattended", "--safe", "--new"]), ownedFlags: Object.freeze(["--remote", "--remote-auth-token-env", "--yolo", "--dangerously-bypass-approvals-and-sandbox"]), unattended: true, passthrough: true });
22332
22599
  });
22333
22600
 
22334
- // src/hub/events.ts
22335
- import { appendFileSync, closeSync as closeSync13, existsSync as existsSync9, fstatSync as fstatSync11, openSync as openSync13, readFileSync as readFileSync15, readSync as readSync8 } from "fs";
22336
- function readEvents(file, since = 0) {
22337
- if (!existsSync9(file))
22338
- return [];
22339
- return readFileSync15(file, "utf8").split(`
22340
- `).flatMap((line) => {
22341
- const event = parseEventLine(line, since);
22342
- return event === undefined ? [] : [event];
22343
- });
22344
- }
22345
- function parseEventLine(line, since = 0) {
22346
- if (!line.trim())
22347
- return;
22348
- try {
22349
- const e = JSON.parse(line);
22350
- const measuredAt = e.type === "usage" && typeof e.measuredAt === "string" ? e.measuredAt : e.at;
22351
- return Date.parse(measuredAt) >= since ? e : undefined;
22352
- } catch {
22353
- return;
22354
- }
22355
- }
22356
- var init_events = () => {};
22357
-
22358
22601
  // src/cli/recovery-session-file.ts
22359
- import { statSync as statSync5 } from "fs";
22602
+ import { statSync as statSync6 } from "fs";
22360
22603
  import { homedir as homedir8 } from "os";
22361
- import { join as join31 } from "path";
22604
+ import { join as join32 } from "path";
22362
22605
  function checkedSessionPath(binding, kind) {
22363
22606
  if (kind === "rollout")
22364
- return join31(binding.launch.env.CODEX_HOME ?? join31(homedir8(), ".codex"), "sessions");
22365
- const config = binding.launch.env.CLAUDE_CONFIG_DIR ?? join31(homedir8(), ".claude");
22607
+ return join32(binding.launch.env.CODEX_HOME ?? join32(homedir8(), ".codex"), "sessions");
22608
+ const config = binding.launch.env.CLAUDE_CONFIG_DIR ?? join32(homedir8(), ".claude");
22366
22609
  const slug = binding.projectRoot.replace(/[^a-zA-Z0-9]/g, "-");
22367
- return join31(config, "projects", slug, `${binding.sessionId}.jsonl`);
22610
+ return join32(config, "projects", slug, `${binding.sessionId}.jsonl`);
22368
22611
  }
22369
22612
  function recordedFileState(file) {
22370
22613
  try {
22371
- return statSync5(file).isFile() ? "found" : "unknown";
22614
+ return statSync6(file).isFile() ? "found" : "unknown";
22372
22615
  } catch (error) {
22373
22616
  return error.code === "ENOENT" ? "missing" : "unknown";
22374
22617
  }
@@ -22376,11 +22619,11 @@ function recordedFileState(file) {
22376
22619
  var init_recovery_session_file = () => {};
22377
22620
 
22378
22621
  // src/adapters/definitions/native-recovery.ts
22379
- import { readdirSync as readdirSync5 } from "fs";
22380
- import { basename as basename5, join as join32 } from "path";
22622
+ import { readdirSync as readdirSync6 } from "fs";
22623
+ import { basename as basename6, join as join33 } from "path";
22381
22624
  var rolloutState = (binding) => {
22382
22625
  try {
22383
- return readdirSync5(checkedSessionPath(binding, "rollout"), { recursive: true }).some((name) => String(name).endsWith(".jsonl") && basename5(String(name)).includes(binding.sessionId));
22626
+ return readdirSync6(checkedSessionPath(binding, "rollout"), { recursive: true }).some((name) => String(name).endsWith(".jsonl") && basename6(String(name)).includes(binding.sessionId));
22384
22627
  } catch (error) {
22385
22628
  return error.code === "ENOENT" ? false : "unknown";
22386
22629
  }
@@ -22401,7 +22644,7 @@ var init_native_recovery = __esm(() => {
22401
22644
  if (phase !== "plan")
22402
22645
  return false;
22403
22646
  let current, started = false, turned = false;
22404
- for (const e of readEvents(join32(stateDir, "events.jsonl"))) {
22647
+ for (const e of readEvents(join33(stateDir, "events.jsonl"))) {
22405
22648
  if (e.type === "native_thread" && e.peer === binding.peer) {
22406
22649
  current = e.thread;
22407
22650
  if (e.thread === binding.sessionId && e.fresh)
@@ -22478,9 +22721,9 @@ var init_native_recovery = __esm(() => {
22478
22721
  });
22479
22722
 
22480
22723
  // src/adapters/kimi-tui-facts.ts
22481
- import { closeSync as closeSync14, constants as constants11, fstatSync as fstatSync12, lstatSync as lstatSync21, openSync as openSync14, readSync as readSync9, readdirSync as readdirSync6 } from "fs";
22724
+ import { closeSync as closeSync15, constants as constants11, fstatSync as fstatSync13, lstatSync as lstatSync22, openSync as openSync15, readSync as readSync10, readdirSync as readdirSync7 } from "fs";
22482
22725
  import { createHash as createHash13 } from "crypto";
22483
- import { basename as basename6, dirname as dirname15, isAbsolute as isAbsolute10, join as join33, relative as relative6 } from "path";
22726
+ import { basename as basename7, dirname as dirname16, isAbsolute as isAbsolute10, join as join34, relative as relative6 } from "path";
22484
22727
  import { homedir as homedir9 } from "os";
22485
22728
  function decodeKimiTuiHook(event, value) {
22486
22729
  if (!EVENTS4.includes(event) || !record7(value) || value.hook_event_name !== event || value.client_type !== "kimi_code_cli" || typeof value.session_id !== "string" || !SESSION.test(value.session_id) || typeof value.cwd !== "string" || !isAbsolute10(value.cwd) || value.cwd.length > 4096)
@@ -22489,8 +22732,8 @@ function decodeKimiTuiHook(event, value) {
22489
22732
  return;
22490
22733
  if (event === "TaskStarted" && (typeof value.task_id !== "string" || !TASK.test(value.task_id)))
22491
22734
  return;
22492
- const home = process.env.KIMI_CODE_HOME ?? join33(process.env.HOME ?? homedir9(), ".kimi-code");
22493
- const transcriptPath = value.agentHubTranscriptPath ?? join33(home, "session_index.jsonl");
22735
+ const home = process.env.KIMI_CODE_HOME ?? join34(process.env.HOME ?? homedir9(), ".kimi-code");
22736
+ const transcriptPath = value.agentHubTranscriptPath ?? join34(home, "session_index.jsonl");
22494
22737
  if (typeof transcriptPath !== "string" || !isAbsolute10(transcriptPath) || transcriptPath.length > 4096)
22495
22738
  return;
22496
22739
  const phase = { TurnStarted: "start", Stop: "stop", StopFailure: "stop", Interrupt: "stop", SessionEnd: "session", TaskStarted: "pre", Notification: "post" }[event];
@@ -22500,30 +22743,30 @@ function encodeKimiTuiHook() {
22500
22743
  return;
22501
22744
  }
22502
22745
  function readBytes(path, cap, tail = false) {
22503
- const link = lstatSync21(path);
22746
+ const link = lstatSync22(path);
22504
22747
  if (!link.isFile() || link.isSymbolicLink() || link.nlink !== 1)
22505
22748
  throw new Error("not a regular file");
22506
- const fd = openSync14(path, constants11.O_RDONLY | constants11.O_NOFOLLOW);
22749
+ const fd = openSync15(path, constants11.O_RDONLY | constants11.O_NOFOLLOW);
22507
22750
  try {
22508
- const stat = fstatSync12(fd);
22751
+ const stat = fstatSync13(fd);
22509
22752
  if (!stat.isFile() || stat.nlink !== 1 || !tail && stat.size > cap)
22510
22753
  throw new Error("invalid file");
22511
22754
  const length = Math.min(stat.size, cap), start = tail ? stat.size - length : 0;
22512
22755
  const bytes = Buffer.alloc(length);
22513
22756
  let offset = 0;
22514
22757
  while (offset < length) {
22515
- const count = readSync9(fd, bytes, offset, length - offset, start + offset);
22758
+ const count = readSync10(fd, bytes, offset, length - offset, start + offset);
22516
22759
  if (count <= 0)
22517
22760
  throw new Error("short read");
22518
22761
  offset += count;
22519
22762
  }
22520
22763
  return bytes;
22521
22764
  } finally {
22522
- closeSync14(fd);
22765
+ closeSync15(fd);
22523
22766
  }
22524
22767
  }
22525
22768
  function sessionDirectory(index, session) {
22526
- const home = dirname15(index), sessions = realPath(join33(home, "sessions"));
22769
+ const home = dirname16(index), sessions = realPath(join34(home, "sessions"));
22527
22770
  let listed;
22528
22771
  for (const line of readBytes(index, INDEX_CAP2).toString("utf8").split(`
22529
22772
  `)) {
@@ -22550,7 +22793,7 @@ function sessionDirectory(index, session) {
22550
22793
  }
22551
22794
  function taskInventory(agents) {
22552
22795
  let active = 0;
22553
- const names = readdirSync6(agents, { withFileTypes: true });
22796
+ const names = readdirSync7(agents, { withFileTypes: true });
22554
22797
  if (names.length > MAX_AGENTS2)
22555
22798
  throw new Error("too many agents");
22556
22799
  for (const entry of names) {
@@ -22558,19 +22801,19 @@ function taskInventory(agents) {
22558
22801
  continue;
22559
22802
  if (!entry.isDirectory())
22560
22803
  continue;
22561
- const tasks = join33(agents, entry.name, "tasks");
22562
- const dir = lstatSync21(tasks, { throwIfNoEntry: false });
22804
+ const tasks = join34(agents, entry.name, "tasks");
22805
+ const dir = lstatSync22(tasks, { throwIfNoEntry: false });
22563
22806
  if (!dir)
22564
22807
  continue;
22565
22808
  if (!dir.isDirectory() || dir.isSymbolicLink())
22566
22809
  throw new Error("invalid task directory");
22567
- const files = readdirSync6(tasks).filter((name) => name.endsWith(".json")).sort();
22810
+ const files = readdirSync7(tasks).filter((name) => name.endsWith(".json")).sort();
22568
22811
  if (files.length > MAX_TASKS)
22569
22812
  throw new Error("too many tasks");
22570
22813
  for (const name of files) {
22571
22814
  if (!TASK.test(name.slice(0, -5)))
22572
22815
  throw new Error("invalid task name");
22573
- const row = JSON.parse(readBytes(join33(tasks, name), TASK_CAP).toString("utf8"));
22816
+ const row = JSON.parse(readBytes(join34(tasks, name), TASK_CAP).toString("utf8"));
22574
22817
  if (!record7(row) || row.taskId !== name.slice(0, -5) || typeof row.status !== "string")
22575
22818
  throw new Error("invalid task");
22576
22819
  if (row.status === "running" && row.endedAt === null) {
@@ -22585,11 +22828,11 @@ function taskInventory(agents) {
22585
22828
  return active;
22586
22829
  }
22587
22830
  function readKimiTuiTranscript(session, index) {
22588
- if (!SESSION.test(session) || basename6(index) !== "session_index.jsonl" || !isAbsolute10(index))
22831
+ if (!SESSION.test(session) || basename7(index) !== "session_index.jsonl" || !isAbsolute10(index))
22589
22832
  return empty();
22590
22833
  try {
22591
22834
  const directory = sessionDirectory(index, session);
22592
- const wire = join33(directory, "agents", "main", "wire.jsonl");
22835
+ const wire = join34(directory, "agents", "main", "wire.jsonl");
22593
22836
  if (!inside3(directory, realPath(wire)))
22594
22837
  return empty();
22595
22838
  const bytes = readBytes(wire, WIRE_CAP, true);
@@ -22643,7 +22886,7 @@ function readKimiTuiTranscript(session, index) {
22643
22886
  }
22644
22887
  let background;
22645
22888
  try {
22646
- background = taskInventory(join33(directory, "agents"));
22889
+ background = taskInventory(join34(directory, "agents"));
22647
22890
  } catch {}
22648
22891
  return {
22649
22892
  factIds: [],
@@ -22900,7 +23143,7 @@ var init_builtin_metadata = __esm(() => {
22900
23143
  session: { idField: "sessionId", currentId: sessionId("sessionId"), restoreOnStart: true, launchKind: "pi", launchRecord: true, ...PI_RECOVERY_SESSION, crashPlan: piCrashPlan, unrecordedTerminal: "tui", continuityBookmark: piRecoveryContinuity, continuity: { key: "pi", parse: parsePiContinuity } },
22901
23144
  turnEnd: "adapter",
22902
23145
  settle: { signal: "agent-settled" },
22903
- budget: { account: "pi", instrumented: true, noQuotaReason: "on-prem backends have no provider quota" },
23146
+ budget: { account: "pi", instrumented: true, noQuotaReason: "on-prem backends have no provider quota", context: { source: "pi_usage", read: piContext } },
22904
23147
  reporting: { tokensNotReported: true },
22905
23148
  configuration: { schema: piConfigSchema, routingSchema: piRoutingSchema, settings: PI_SETTINGS, restartReasons: PI_RESTART_REASONS, validateEffective: piEffectiveConfig },
22906
23149
  routing: { localAllowedRefusal: "local_allowed = false also excludes pi for this class", longContext: "backend-limit", preferredTier: true, handoffPriority: 0, trace: "backend", backendLabel: "pi" },
@@ -23032,7 +23275,7 @@ var init_native_cli_entry_qwen = __esm(() => {
23032
23275
  });
23033
23276
 
23034
23277
  // src/adapters/definitions/native-cli-preview-qwen.ts
23035
- import { join as join34 } from "path";
23278
+ import { join as join35 } from "path";
23036
23279
  function previewQwen(ctx) {
23037
23280
  const { tool, args, cwd, stateDir, cliDir, config } = ctx;
23038
23281
  const state = previewState(args, ctx.baseEnvNames), { unresolved, value } = state;
@@ -23062,7 +23305,7 @@ function previewQwen(ctx) {
23062
23305
  form: "headless",
23063
23306
  projectRoot: cwd,
23064
23307
  stateDir,
23065
- entrypoint: join34(cliDir, "main.js"),
23308
+ entrypoint: join35(cliDir, "main.js"),
23066
23309
  userArgs: [],
23067
23310
  unattended: false,
23068
23311
  env: {},
@@ -23159,7 +23402,7 @@ var init_qwen = __esm(() => {
23159
23402
  });
23160
23403
 
23161
23404
  // src/adapters/configured-acp.ts
23162
- import { basename as basename7 } from "path";
23405
+ import { basename as basename8 } from "path";
23163
23406
  import { types as types7 } from "util";
23164
23407
  function fields(raw, at) {
23165
23408
  if (!raw || typeof raw !== "object" || types7.isProxy(raw) || Array.isArray(raw) || ![Object.prototype, null].includes(Object.getPrototypeOf(raw)) || Object.getOwnPropertySymbols(raw).length)
@@ -23227,7 +23470,7 @@ function configuredAcpDefinitions(raw, builtinKinds) {
23227
23470
  return fail(`${at}.identity`, "unknown identity field");
23228
23471
  identity = { name: text4(value.name?.value, `${at}.identity.name`, 256), version: text4(value.version?.value, `${at}.identity.version`, 256) };
23229
23472
  }
23230
- const grokContract = kind === "grok" || /^grok(?:\.exe)?$/i.test(basename7(command)) || identity?.name.toLowerCase() === "grok";
23473
+ const grokContract = kind === "grok" || /^grok(?:\.exe)?$/i.test(basename8(command)) || identity?.name.toLowerCase() === "grok";
23231
23474
  const noLeader = args.indexOf("--no-leader"), endOptions = args.indexOf("--");
23232
23475
  if (grokContract && (noLeader < 0 || endOptions >= 0 && noLeader > endOptions || args.some((arg) => arg.startsWith("--no-leader=")))) {
23233
23476
  return fail(`${at}.args`, "Grok requires explicit --no-leader before argv termination; valued opt-outs are unsupported");
@@ -30735,10 +30978,10 @@ var adapterNumber = (def) => ({ group: "Start", store: "config", risk: "raises",
30735
30978
  var ACP_TOOL_CEILING_SETTING = adapterNumber({
30736
30979
  key: "adapter_timing.acp_tool_ceiling_min",
30737
30980
  path: ["adapter_timing", "acp_tool_ceiling_min"],
30738
- label: "Next ACP launch: open-tool ceiling (minutes, at least the watchdog)",
30981
+ label: "Next ACP launch: open-tool ceiling (minutes, at least the watchdog; 60 covers a documented 50-minute gate wait)",
30739
30982
  min: 1,
30740
- max: 30,
30741
- defaultValue: 30,
30983
+ max: 120,
30984
+ defaultValue: 60,
30742
30985
  unit: "minutes",
30743
30986
  inventory: "src/adapters/acp.ts:TOOL_CEILING_MS"
30744
30987
  });
@@ -30953,7 +31196,7 @@ init_project();
30953
31196
  // src/hub/instance-config.ts
30954
31197
  init_registry();
30955
31198
  import { readFileSync as readFileSync17 } from "fs";
30956
- import { join as join37 } from "path";
31199
+ import { join as join38 } from "path";
30957
31200
 
30958
31201
  // src/adapters/external-metadata.ts
30959
31202
  import { types as types9 } from "util";
@@ -31066,8 +31309,8 @@ init_registry();
31066
31309
  // src/hub/config-trust.ts
31067
31310
  init_child_process();
31068
31311
  init_git();
31069
- import { lstatSync as lstatSync22, statSync as statSync6 } from "fs";
31070
- import { dirname as dirname16, join as join35 } from "path";
31312
+ import { lstatSync as lstatSync23, statSync as statSync7 } from "fs";
31313
+ import { dirname as dirname17, join as join36 } from "path";
31071
31314
  var MACHINE_LOCAL = [
31072
31315
  "kimi_cmd",
31073
31316
  "permission_modes",
@@ -31096,7 +31339,7 @@ var MACHINE_LOCAL = [
31096
31339
  "corpus.paths",
31097
31340
  "invocation"
31098
31341
  ];
31099
- var ALL_MACHINE_LOCAL = [...MACHINE_LOCAL, "research.runners", "rooms", "tasks.queue_backpressure", "context.max_assignment_used", "action_policy", "protect_instruction_files", "qwen_cmd", "jcode_cmd", "jcode_home", "jcode_provider_profile", "start.agents", "adapters", "adapter_modules", "text_projection", "instances"];
31342
+ var ALL_MACHINE_LOCAL = [...MACHINE_LOCAL, "edit_governance.arm", "roadmap.github_mirror", "roadmap.github_write", "research.runners", "rooms", "tasks.queue_backpressure", "context.max_assignment_used", "action_policy", "protect_instruction_files", "qwen_cmd", "jcode_cmd", "jcode_home", "jcode_provider_profile", "start.agents", "adapters", "adapter_modules", "text_projection", "instances"];
31100
31343
  function configRefusal(cwd, name) {
31101
31344
  const tracked = configTracked(cwd, name);
31102
31345
  return tracked === undefined ? `git could not confirm that .agenthub/${name} is untracked` : tracked ? `.agenthub/${name} is committed to git` : undefined;
@@ -31107,7 +31350,7 @@ function configTracked(cwd, name) {
31107
31350
  return;
31108
31351
  let opened;
31109
31352
  try {
31110
- opened = statSync6(join35(cwd, ".agenthub", name));
31353
+ opened = statSync7(join36(cwd, ".agenthub", name));
31111
31354
  } catch {}
31112
31355
  return r.stdout.split("\x00").filter(Boolean).some((row) => {
31113
31356
  const path = row.slice(row.indexOf("\t") + 1);
@@ -31116,7 +31359,7 @@ function configTracked(cwd, name) {
31116
31359
  if (!opened)
31117
31360
  return path === `.agenthub/${name}`;
31118
31361
  try {
31119
- const s = statSync6(join35(cwd, path));
31362
+ const s = statSync7(join36(cwd, path));
31120
31363
  return !!opened && s.dev === opened.dev && s.ino === opened.ino;
31121
31364
  } catch {
31122
31365
  return false;
@@ -31174,7 +31417,7 @@ function readAdapterModuleDeclarations(cwd, layers) {
31174
31417
  // src/hub/control-client.ts
31175
31418
  init_project();
31176
31419
  import { readFileSync as readFileSync16 } from "fs";
31177
- import { join as join36, resolve as resolve18 } from "path";
31420
+ import { join as join37, resolve as resolve18 } from "path";
31178
31421
 
31179
31422
  // src/hub/tool-request.ts
31180
31423
  init_capabilities();
@@ -31278,8 +31521,8 @@ function controlProtocolWindow(descriptor) {
31278
31521
  }
31279
31522
  function readControl(stateDir) {
31280
31523
  try {
31281
- const status = JSON.parse(readFileSync16(join36(stateDir, "status.json"), "utf8"));
31282
- const token = readFileSync16(join36(stateDir, "control-token"), "utf8").trim();
31524
+ const status = JSON.parse(readFileSync16(join37(stateDir, "status.json"), "utf8"));
31525
+ const token = readFileSync16(join37(stateDir, "control-token"), "utf8").trim();
31283
31526
  if (!Number.isInteger(status.controlPort) || status.controlPort < 1 || status.controlPort > 65535 || !token)
31284
31527
  return;
31285
31528
  const startModes = status.startModes && typeof status.startModes === "object" && !Array.isArray(status.startModes) ? Object.fromEntries(Object.entries(status.startModes).filter((entry) => entry[1] === "tui" || entry[1] === "headless")) : undefined;
@@ -31542,15 +31785,25 @@ init_db_schema();
31542
31785
  init_hub_tools();
31543
31786
  init_envelope();
31544
31787
 
31788
+ // src/hub/github-import.ts
31789
+ init_sdlc();
31790
+
31545
31791
  // src/hub/tasks.ts
31546
31792
  init_roadmap();
31547
31793
 
31548
31794
  // src/hub/roadmap-view.ts
31549
31795
  init_envelope();
31550
31796
 
31797
+ // src/hub/roadmap-sync.ts
31798
+ init_roadmap();
31799
+
31551
31800
  // src/hub/roadmap-unplaced.ts
31552
31801
  init_envelope();
31553
31802
 
31803
+ // src/hub/roadmap-decompose.ts
31804
+ init_board();
31805
+ init_roadmap();
31806
+
31554
31807
  // src/hub/tasks.ts
31555
31808
  init_src();
31556
31809
  init_guidance_variants();
@@ -31649,6 +31902,7 @@ import { fileURLToPath } from "url";
31649
31902
  var CHECKER_PATH = fileURLToPath(new URL("../../scripts/check-docs.mjs", import.meta.url));
31650
31903
 
31651
31904
  // src/hub/tasks.ts
31905
+ init_cost_governance();
31652
31906
  init_spec_read();
31653
31907
 
31654
31908
  // src/hub/schedules.ts
@@ -31666,6 +31920,7 @@ var INTAKE_MAX_ANSWER = 64 * 1024;
31666
31920
  // src/hub/tasks.ts
31667
31921
  init_sdlc_metrics();
31668
31922
  init_security_baseline();
31923
+ init_cost_governance();
31669
31924
  init_version();
31670
31925
 
31671
31926
  // src/hub/no-writes.ts
@@ -31673,9 +31928,7 @@ var OWNER_TOOL_EFFECTS = new Set(["hub_task_propose", "hub_task_decline", "hub_t
31673
31928
  OWNER_TOOL_EFFECTS.add("hub_survey_report");
31674
31929
  OWNER_TOOL_EFFECTS.add("hub_roadmap_edit");
31675
31930
  OWNER_TOOL_EFFECTS.add("hub_roadmap_triage");
31676
-
31677
- // src/hub/github-import.ts
31678
- init_sdlc();
31931
+ OWNER_TOOL_EFFECTS.add("hub_roadmap_decompose");
31679
31932
 
31680
31933
  // src/hub/tasks.ts
31681
31934
  init_planning();
@@ -31691,6 +31944,7 @@ init_sdlc();
31691
31944
  // src/hub/sdlc-merge.ts
31692
31945
  init_review_findings();
31693
31946
  init_eval_gate();
31947
+ init_cost_governance();
31694
31948
  init_sdlc();
31695
31949
  var MERGE_READBACK_INTERVAL_MS = 5 * 60000;
31696
31950
 
@@ -31730,7 +31984,7 @@ var LEARNING_DEFAULTS = { windowMs: 30 * 24 * 3600000, threshold: 3, maxGroups:
31730
31984
  init_deliverables();
31731
31985
 
31732
31986
  // src/hub/deliverable-files.ts
31733
- import { constants as constants12, lstatSync as lstatSync23 } from "fs";
31987
+ import { constants as constants12, lstatSync as lstatSync24 } from "fs";
31734
31988
  init_tools();
31735
31989
  init_deny();
31736
31990
  init_permission_mode();
@@ -31799,6 +32053,7 @@ QUIET_EVENTS.add("wait recorded");
31799
32053
  QUIET_EVENTS.add("shell branch bound");
31800
32054
  var OWNERSHIP_EVENTS = new Set(["assigned", "escalated", "reassigned", "unassigned"]);
31801
32055
  var GROOM_FYI_WINDOW_MS = 10 * 60000;
32056
+ var MANAGED_HANDOFF = Symbol("managed worktree handoff");
31802
32057
 
31803
32058
  // src/hub/conductor.ts
31804
32059
  init_tool_refusal();
@@ -31812,7 +32067,7 @@ import { types as types10 } from "util";
31812
32067
  init_project();
31813
32068
  init_registry();
31814
32069
  init_permission_mode();
31815
- import { dirname as dirname17, isAbsolute as isAbsolute11, sep as sep4 } from "path";
32070
+ import { dirname as dirname18, isAbsolute as isAbsolute11, sep as sep4 } from "path";
31816
32071
  init_model_token();
31817
32072
  init_model_token();
31818
32073
  var JCODE_FIELDS = ["jcode_home", "provider", "model", "provider_profile"];
@@ -32047,7 +32302,7 @@ var INSTANCE_CONFIG_FILES = ["config.json", "config.local.json"];
32047
32302
  function readInstanceConfigLayers(cwd) {
32048
32303
  return INSTANCE_CONFIG_FILES.flatMap((name) => {
32049
32304
  try {
32050
- return [{ name, raw: JSON.parse(readFileSync17(join37(cwd, ".agenthub", name), "utf8")) }];
32305
+ return [{ name, raw: JSON.parse(readFileSync17(join38(cwd, ".agenthub", name), "utf8")) }];
32051
32306
  } catch (error) {
32052
32307
  if (error.code === "ENOENT")
32053
32308
  return [];
@@ -40440,7 +40695,7 @@ class StdioServerTransport {
40440
40695
 
40441
40696
  // src/adapters/claude-channel.ts
40442
40697
  import { readFileSync as readFileSync18 } from "fs";
40443
- import { join as join40 } from "path";
40698
+ import { join as join41 } from "path";
40444
40699
 
40445
40700
  // src/hub/channel-project.ts
40446
40701
  init_registry();
@@ -40448,8 +40703,8 @@ init_registry();
40448
40703
  // src/hub/instance-execution.ts
40449
40704
  init_git();
40450
40705
  init_project();
40451
- import { lstatSync as lstatSync24 } from "fs";
40452
- import { join as join38, resolve as resolve20 } from "path";
40706
+ import { lstatSync as lstatSync25 } from "fs";
40707
+ import { join as join39, resolve as resolve20 } from "path";
40453
40708
  var refuse = (reason) => {
40454
40709
  throw new Error(`instance execution workspace refused: ${reason}`);
40455
40710
  };
@@ -40491,12 +40746,12 @@ function resolveInstanceExecutionCwd(projectRoot, id, declarations, roles, adapt
40491
40746
  try {
40492
40747
  root = realPath(projectRoot);
40493
40748
  cwd = realPath(resolve20(root, declaration.worktree));
40494
- if (!lstatSync24(root).isDirectory() || !lstatSync24(cwd).isDirectory())
40749
+ if (!lstatSync25(root).isDirectory() || !lstatSync25(cwd).isDirectory())
40495
40750
  return refuse("workspace is not a directory");
40496
40751
  } catch {
40497
40752
  return refuse("workspace paths are unavailable");
40498
40753
  }
40499
- const expected = join38(root, ".worktrees", id);
40754
+ const expected = join39(root, ".worktrees", id);
40500
40755
  if (cwd !== expected)
40501
40756
  return refuse("worktree must be the exact managed instance directory");
40502
40757
  const inventory = git(root, ["worktree", "list", "--porcelain", "-z"]);
@@ -40525,8 +40780,8 @@ function resolveInstanceExecutionCwd(projectRoot, id, declarations, roles, adapt
40525
40780
 
40526
40781
  // src/hub/channel-project.ts
40527
40782
  init_project();
40528
- import { existsSync as existsSync10 } from "fs";
40529
- import { join as join39 } from "path";
40783
+ import { existsSync as existsSync11 } from "fs";
40784
+ import { join as join40 } from "path";
40530
40785
  function channelProject(cwd, env, policyRoles) {
40531
40786
  const override = env.AGENTHUB_STATE_DIR?.trim(), declared = env.AGENTHUB_PROJECT_DIR?.trim();
40532
40787
  if (env.AGENTHUB_MODE === "tools" && override && declared)
@@ -40556,7 +40811,7 @@ function channelProject(cwd, env, policyRoles) {
40556
40811
  const inherited = inheritedStateDir(own.root, env);
40557
40812
  if (inherited)
40558
40813
  return { root: own.root, stateDir: inherited, inherited: true };
40559
- if (override && !existsSync10(join39(own.root, ".agenthub", "config.json")))
40814
+ if (override && !existsSync11(join40(own.root, ".agenthub", "config.json")))
40560
40815
  return asSession();
40561
40816
  return { root: own.root, stateDir: own.stateDir, inherited: false };
40562
40817
  }
@@ -40692,7 +40947,7 @@ function currentClaudeChannelEvidence() {
40692
40947
  var own5 = channelProject(process.cwd(), process.env, (root) => {
40693
40948
  const read = (name) => {
40694
40949
  try {
40695
- return JSON.parse(readFileSync18(join40(root, ".agenthub", name), "utf8")).roles ?? {};
40950
+ return JSON.parse(readFileSync18(join41(root, ".agenthub", name), "utf8")).roles ?? {};
40696
40951
  } catch {
40697
40952
  return {};
40698
40953
  }
@@ -40718,7 +40973,7 @@ var channel = !toolsMode && channelEvidence === "development-channel-launch";
40718
40973
  function roles2() {
40719
40974
  const read = (name) => {
40720
40975
  try {
40721
- return JSON.parse(readFileSync18(join40(projectRoot2, ".agenthub", name), "utf8")).roles ?? {};
40976
+ return JSON.parse(readFileSync18(join41(projectRoot2, ".agenthub", name), "utf8")).roles ?? {};
40722
40977
  } catch {
40723
40978
  return {};
40724
40979
  }
@@ -40737,7 +40992,7 @@ function sessionProfile() {
40737
40992
  for (const name of ["config.json", "config.local.json"]) {
40738
40993
  let data;
40739
40994
  try {
40740
- data = JSON.parse(readFileSync18(join40(projectRoot2, ".agenthub", name), "utf8"));
40995
+ data = JSON.parse(readFileSync18(join41(projectRoot2, ".agenthub", name), "utf8"));
40741
40996
  } catch (error) {
40742
40997
  if (error.code === "ENOENT")
40743
40998
  continue;
@@ -40764,7 +41019,7 @@ function sessionRoles() {
40764
41019
  const read = (name) => {
40765
41020
  let raw;
40766
41021
  try {
40767
- raw = JSON.parse(readFileSync18(join40(projectRoot2, ".agenthub", name), "utf8")).catalog_roles;
41022
+ raw = JSON.parse(readFileSync18(join41(projectRoot2, ".agenthub", name), "utf8")).catalog_roles;
40768
41023
  } catch {
40769
41024
  return {};
40770
41025
  }
@@ -40795,14 +41050,14 @@ var HELD = `another session is attached to the hub as "${peerId}"; this one is s
40795
41050
  var INBOX_CAP = 200;
40796
41051
  function sessionSupported() {
40797
41052
  try {
40798
- return (JSON.parse(readFileSync18(join40(stateDir, "status.json"), "utf8")).features ?? []).includes("session_identity");
41053
+ return (JSON.parse(readFileSync18(join41(stateDir, "status.json"), "utf8")).features ?? []).includes("session_identity");
40799
41054
  } catch {
40800
41055
  return false;
40801
41056
  }
40802
41057
  }
40803
41058
  function peerHeld() {
40804
41059
  try {
40805
- const status = JSON.parse(readFileSync18(join40(stateDir, "status.json"), "utf8"));
41060
+ const status = JSON.parse(readFileSync18(join41(stateDir, "status.json"), "utf8"));
40806
41061
  const peer = status.peers?.[peerId];
40807
41062
  if (channel && peer?.toolsOnly && !peer.claiming)
40808
41063
  return false;