@cjhyy/code-shell 0.1.0-alpha.0 → 0.1.0-alpha.1

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.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17; var _class18; var _class19; var _class20; var _class21; var _class22;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17; var _class18; var _class19; var _class20; var _class21; var _class22; var _class23; var _class24;
2
2
 
3
3
  var _chunk3QR52LL5cjs = require('./chunk-3QR52LL5.cjs');
4
4
 
@@ -443,7 +443,7 @@ var FileStateCache = (_class2 = class {constructor() { _class2.prototype.__init3
443
443
  if (s.mtimeMs === entry.mtimeMs) return entry.content;
444
444
  this.cache.delete(filePath);
445
445
  return null;
446
- } catch (e2) {
446
+ } catch (e3) {
447
447
  this.cache.delete(filePath);
448
448
  return null;
449
449
  }
@@ -664,7 +664,7 @@ async function globTool(args) {
664
664
  try {
665
665
  const s = await _promises.stat.call(void 0, filePath);
666
666
  return { path: filePath, size: s.size, mtime: s.mtimeMs };
667
- } catch (e3) {
667
+ } catch (e4) {
668
668
  return { path: filePath, size: 0, mtime: 0 };
669
669
  }
670
670
  })
@@ -814,7 +814,7 @@ var bashToolDef = {
814
814
  command: { type: "string", description: "The shell command to execute" },
815
815
  timeout: {
816
816
  type: "number",
817
- description: "Timeout in milliseconds (default: 120000, max: 600000)"
817
+ description: "Timeout in milliseconds (default: 120000). Outer registry caps at 1h."
818
818
  },
819
819
  description: {
820
820
  type: "string",
@@ -828,7 +828,7 @@ var MAX_OUTPUT = 1e5;
828
828
  async function bashTool(args) {
829
829
  const command = args.command;
830
830
  if (!command) return "Error: command is required";
831
- const timeout = Math.min(args.timeout || 12e4, 6e5);
831
+ const timeout = args.timeout || 12e4;
832
832
  try {
833
833
  const { stdout, stderr } = await execAsync(command, {
834
834
  timeout,
@@ -903,6 +903,63 @@ async function askUserTool(args) {
903
903
  // src/tool-system/builtin/agent.ts
904
904
  _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
905
905
  init_plan();
906
+
907
+ // src/tool-system/builtin/agent-registry.ts
908
+ _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
909
+ var AsyncAgentRegistry = (_class3 = class {constructor() { _class3.prototype.__init4.call(this); }
910
+ __init4() {this.agents = /* @__PURE__ */ new Map()}
911
+ register(entry) {
912
+ this.agents.set(entry.agentId, entry);
913
+ }
914
+ get(agentId) {
915
+ return this.agents.get(agentId);
916
+ }
917
+ list() {
918
+ return [...this.agents.values()];
919
+ }
920
+ markCompleted(agentId, result) {
921
+ const e = this.agents.get(agentId);
922
+ if (!e) return;
923
+ if (e.status !== "running") return;
924
+ e.status = "completed";
925
+ e.result = result;
926
+ e.finishedAt = Date.now();
927
+ }
928
+ markFailed(agentId, error) {
929
+ const e = this.agents.get(agentId);
930
+ if (!e) return;
931
+ if (e.status !== "running") return;
932
+ e.status = "failed";
933
+ e.error = error;
934
+ e.finishedAt = Date.now();
935
+ }
936
+ cancel(agentId) {
937
+ const e = this.agents.get(agentId);
938
+ if (!e) return false;
939
+ if (e.status !== "running") return false;
940
+ try {
941
+ e.abort();
942
+ } catch (e5) {
943
+ }
944
+ e.status = "cancelled";
945
+ e.finishedAt = Date.now();
946
+ return true;
947
+ }
948
+ reset() {
949
+ for (const e of this.agents.values()) {
950
+ if (e.status === "running") {
951
+ try {
952
+ e.abort();
953
+ } catch (e6) {
954
+ }
955
+ }
956
+ }
957
+ this.agents.clear();
958
+ }
959
+ }, _class3);
960
+ var asyncAgentRegistry = new AsyncAgentRegistry();
961
+
962
+ // src/tool-system/builtin/agent.ts
906
963
  var _nanoid = require('nanoid');
907
964
  var agentToolDef = {
908
965
  name: "Agent",
@@ -921,6 +978,10 @@ var agentToolDef = {
921
978
  max_turns: {
922
979
  type: "number",
923
980
  description: "Maximum turns for the sub-agent (default: 15)"
981
+ },
982
+ run_in_background: {
983
+ type: "boolean",
984
+ description: "If true, launch the sub-agent in the background and return an agent_id immediately instead of waiting for it to finish. Use AgentStatus(agent_id) to check progress and AgentCancel(agent_id) to stop it. The agent runs in this process; restarting loses its state. Default: false (synchronous wait)."
924
985
  }
925
986
  },
926
987
  required: ["description", "prompt"]
@@ -930,35 +991,21 @@ var _subAgentConfig;
930
991
  function setSubAgentConfig(config) {
931
992
  _subAgentConfig = config;
932
993
  }
933
- async function agentTool(args) {
934
- const prompt = args.prompt;
935
- const description = args.description || "sub-agent";
936
- if (!prompt) return "Error: prompt is required";
937
- if (!_subAgentConfig) {
938
- return "Error: Agent tool is not configured.";
939
- }
940
- const signal = args.__signal;
941
- if (_optionalChain([signal, 'optionalAccess', _5 => _5.aborted])) {
942
- return "Agent aborted before starting.";
943
- }
944
- const maxTurns = Math.min(args.max_turns || 15, 30);
945
- const agentId = _nanoid.nanoid.call(void 0, 8);
946
- const parentStream = _subAgentConfig.onStream;
947
- _optionalChain([parentStream, 'optionalCall', _6 => _6({ type: "agent_start", agentId, description })]);
994
+ async function runSubAgent(opts) {
995
+ if (!_subAgentConfig) throw new Error("Agent tool is not configured.");
996
+ const { agentId, description, prompt, maxTurns, signal, parentStream } = opts;
997
+ _optionalChain([parentStream, 'optionalCall', _5 => _5({ type: "agent_start", agentId, description })]);
948
998
  const childStream = (event) => {
949
999
  if (!parentStream) return;
950
1000
  const tagged = { ...event, agentId };
951
1001
  parentStream(tagged);
952
1002
  };
1003
+ const parentWasInPlanMode = isInPlanMode();
1004
+ if (parentWasInPlanMode) resetPlanMode();
953
1005
  try {
954
- const parentWasInPlanMode = isInPlanMode();
955
- if (parentWasInPlanMode) {
956
- resetPlanMode();
957
- }
958
1006
  const engine = _subAgentConfig.createEngine({
959
1007
  llm: {
960
1008
  ..._subAgentConfig.llm,
961
- timeout: Math.min(_nullishCoalesce(_subAgentConfig.llm.timeout, () => ( 12e4)), 6e4),
962
1009
  retryMaxAttempts: 2
963
1010
  },
964
1011
  cwd: _subAgentConfig.cwd,
@@ -972,27 +1019,142 @@ async function agentTool(args) {
972
1019
  maxContextTokens: _subAgentConfig.maxContextTokens,
973
1020
  sessionStorageDir: _subAgentConfig.sessionStorageDir
974
1021
  });
975
- let result;
976
- try {
977
- result = await engine.run(prompt, { signal, onStream: childStream });
978
- } finally {
979
- if (parentWasInPlanMode) {
980
- restorePlanMode();
1022
+ const result = await engine.run(prompt, { signal, onStream: childStream });
1023
+ _optionalChain([parentStream, 'optionalCall', _6 => _6({ type: "agent_end", agentId, description })]);
1024
+ return result.text || `Agent completed (${result.reason}) but produced no text output.`;
1025
+ } finally {
1026
+ if (parentWasInPlanMode) restorePlanMode();
1027
+ }
1028
+ }
1029
+ async function agentTool(args) {
1030
+ const prompt = args.prompt;
1031
+ const description = args.description || "sub-agent";
1032
+ if (!prompt) return "Error: prompt is required";
1033
+ if (!_subAgentConfig) {
1034
+ return "Error: Agent tool is not configured.";
1035
+ }
1036
+ const parentSignal = args.__signal;
1037
+ if (_optionalChain([parentSignal, 'optionalAccess', _7 => _7.aborted])) {
1038
+ return "Agent aborted before starting.";
1039
+ }
1040
+ const maxTurns = args.max_turns || 15;
1041
+ const runInBackground = args.run_in_background === true;
1042
+ const agentId = _nanoid.nanoid.call(void 0, 8);
1043
+ const parentStream = _subAgentConfig.onStream;
1044
+ if (runInBackground) {
1045
+ const controller = new AbortController();
1046
+ asyncAgentRegistry.register({
1047
+ agentId,
1048
+ description,
1049
+ status: "running",
1050
+ startedAt: Date.now(),
1051
+ abort: () => controller.abort()
1052
+ });
1053
+ void runSubAgent({
1054
+ agentId,
1055
+ description,
1056
+ prompt,
1057
+ maxTurns,
1058
+ signal: controller.signal,
1059
+ parentStream
1060
+ }).then((text) => asyncAgentRegistry.markCompleted(agentId, text)).catch((err) => {
1061
+ if (controller.signal.aborted) {
1062
+ return;
981
1063
  }
982
- }
983
- _optionalChain([parentStream, 'optionalCall', _7 => _7({ type: "agent_end", agentId, description })]);
984
- if (result.text) {
985
- return result.text;
986
- }
987
- return `Agent completed (${result.reason}) but produced no text output.`;
1064
+ asyncAgentRegistry.markFailed(agentId, err.message);
1065
+ });
1066
+ return [
1067
+ `Agent launched in background.`,
1068
+ `agent_id: ${agentId}`,
1069
+ `description: ${description}`,
1070
+ ``,
1071
+ `Use AgentStatus(agent_id="${agentId}") to check progress or fetch the result.`,
1072
+ `Use AgentCancel(agent_id="${agentId}") to stop it.`
1073
+ ].join("\n");
1074
+ }
1075
+ try {
1076
+ return await runSubAgent({
1077
+ agentId,
1078
+ description,
1079
+ prompt,
1080
+ maxTurns,
1081
+ signal: _nullishCoalesce(parentSignal, () => ( new AbortController().signal)),
1082
+ parentStream
1083
+ });
988
1084
  } catch (err) {
989
1085
  _optionalChain([parentStream, 'optionalCall', _8 => _8({ type: "agent_end", agentId, description, error: err.message })]);
990
- if (_optionalChain([signal, 'optionalAccess', _9 => _9.aborted])) {
1086
+ if (_optionalChain([parentSignal, 'optionalAccess', _9 => _9.aborted])) {
991
1087
  return "Agent was aborted.";
992
1088
  }
993
1089
  return `Agent error: ${err.message}`;
994
1090
  }
995
1091
  }
1092
+ var agentStatusToolDef = {
1093
+ name: "AgentStatus",
1094
+ description: "Check the status of a background agent launched with Agent(run_in_background=true). Returns running / completed / failed / cancelled, plus the result text once finished. Omit agent_id to list all background agents in this process.",
1095
+ inputSchema: {
1096
+ type: "object",
1097
+ properties: {
1098
+ agent_id: {
1099
+ type: "string",
1100
+ description: "The agent_id returned by Agent(run_in_background=true). Omit to list all."
1101
+ }
1102
+ }
1103
+ }
1104
+ };
1105
+ async function agentStatusTool(args) {
1106
+ const agentId = args.agent_id;
1107
+ if (!agentId) {
1108
+ const all = asyncAgentRegistry.list();
1109
+ if (all.length === 0) return "No background agents in this process.";
1110
+ return all.map((e2) => {
1111
+ const dur2 = ((_nullishCoalesce(e2.finishedAt, () => ( Date.now()))) - e2.startedAt) / 1e3;
1112
+ return `${e2.agentId} [${e2.status}] ${e2.description} (${dur2.toFixed(1)}s)`;
1113
+ }).join("\n");
1114
+ }
1115
+ const e = asyncAgentRegistry.get(agentId);
1116
+ if (!e) return `Error: agent_id "${agentId}" not found.`;
1117
+ const dur = ((_nullishCoalesce(e.finishedAt, () => ( Date.now()))) - e.startedAt) / 1e3;
1118
+ const lines = [
1119
+ `agent_id: ${e.agentId}`,
1120
+ `status: ${e.status}`,
1121
+ `description: ${e.description}`,
1122
+ `duration: ${dur.toFixed(1)}s`
1123
+ ];
1124
+ if (e.status === "completed" && e.result) {
1125
+ lines.push("", "\u2500\u2500 result \u2500\u2500", e.result);
1126
+ } else if (e.status === "failed" && e.error) {
1127
+ lines.push("", "\u2500\u2500 error \u2500\u2500", e.error);
1128
+ } else if (e.status === "running") {
1129
+ lines.push("", "(still running \u2014 call AgentStatus again later)");
1130
+ }
1131
+ return lines.join("\n");
1132
+ }
1133
+ var agentCancelToolDef = {
1134
+ name: "AgentCancel",
1135
+ description: "Cancel a background agent launched with Agent(run_in_background=true). The agent's current LLM call and any in-flight tools will be aborted.",
1136
+ inputSchema: {
1137
+ type: "object",
1138
+ properties: {
1139
+ agent_id: {
1140
+ type: "string",
1141
+ description: "The agent_id to cancel."
1142
+ }
1143
+ },
1144
+ required: ["agent_id"]
1145
+ }
1146
+ };
1147
+ async function agentCancelTool(args) {
1148
+ const agentId = args.agent_id;
1149
+ if (!agentId) return "Error: agent_id is required.";
1150
+ const e = asyncAgentRegistry.get(agentId);
1151
+ if (!e) return `Error: agent_id "${agentId}" not found.`;
1152
+ if (e.status !== "running") {
1153
+ return `Agent ${agentId} is already ${e.status}; nothing to cancel.`;
1154
+ }
1155
+ const ok = asyncAgentRegistry.cancel(agentId);
1156
+ return ok ? `Agent ${agentId} cancelled.` : `Failed to cancel agent ${agentId}.`;
1157
+ }
996
1158
 
997
1159
  // src/tool-system/builtin/index.ts
998
1160
  init_plan();
@@ -1102,7 +1264,7 @@ function createWorktree(cwd, slug, sessionId) {
1102
1264
  encoding: "utf-8",
1103
1265
  timeout: 5e3
1104
1266
  }).trim();
1105
- } catch (e4) {
1267
+ } catch (e7) {
1106
1268
  }
1107
1269
  _child_process.execSync.call(void 0, `git worktree add -b "${branchName}" "${worktreePath}"`, {
1108
1270
  cwd: gitRoot,
@@ -1136,10 +1298,10 @@ function removeWorktree(worktreePath, removeBranch = false) {
1136
1298
  if (branch.startsWith("worktree/")) {
1137
1299
  _child_process.execSync.call(void 0, `git branch -D "${branch}"`, { cwd: gitRoot, timeout: 1e4 });
1138
1300
  }
1139
- } catch (e5) {
1301
+ } catch (e8) {
1140
1302
  }
1141
1303
  }
1142
- } catch (e6) {
1304
+ } catch (e9) {
1143
1305
  }
1144
1306
  }
1145
1307
  function symlinkLargeDirectories(sourceRoot, worktreePath) {
@@ -1150,7 +1312,7 @@ function symlinkLargeDirectories(sourceRoot, worktreePath) {
1150
1312
  if (_fs.existsSync.call(void 0, source) && _fs.lstatSync.call(void 0, source).isDirectory() && !_fs.existsSync.call(void 0, target)) {
1151
1313
  try {
1152
1314
  _fs.symlinkSync.call(void 0, source, target, "dir");
1153
- } catch (e7) {
1315
+ } catch (e10) {
1154
1316
  }
1155
1317
  }
1156
1318
  }
@@ -1638,10 +1800,10 @@ _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
1638
1800
 
1639
1801
  // src/cron/scheduler.ts
1640
1802
  _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
1641
- var CronScheduler = (_class3 = class {constructor() { _class3.prototype.__init4.call(this);_class3.prototype.__init5.call(this);_class3.prototype.__init6.call(this); }
1642
- __init4() {this.jobs = /* @__PURE__ */ new Map()}
1643
- __init5() {this.timers = /* @__PURE__ */ new Map()}
1644
- __init6() {this.nextId = 1}
1803
+ var CronScheduler = (_class4 = class {constructor() { _class4.prototype.__init5.call(this);_class4.prototype.__init6.call(this);_class4.prototype.__init7.call(this); }
1804
+ __init5() {this.jobs = /* @__PURE__ */ new Map()}
1805
+ __init6() {this.timers = /* @__PURE__ */ new Map()}
1806
+ __init7() {this.nextId = 1}
1645
1807
 
1646
1808
  setExecutor(fn) {
1647
1809
  this.onExecute = fn;
@@ -1713,12 +1875,12 @@ var CronScheduler = (_class3 = class {constructor() { _class3.prototype.__init4.
1713
1875
  job.nextRun = Date.now() + intervalMs;
1714
1876
  try {
1715
1877
  await _optionalChain([this, 'access', _20 => _20.onExecute, 'optionalCall', _21 => _21(job)]);
1716
- } catch (e8) {
1878
+ } catch (e11) {
1717
1879
  }
1718
1880
  }, intervalMs);
1719
1881
  this.timers.set(job.id, timer);
1720
1882
  }
1721
- }, _class3);
1883
+ }, _class4);
1722
1884
  function parseSchedule(schedule) {
1723
1885
  const match = schedule.match(/^(\d+)(s|m|h|d)$/);
1724
1886
  if (match) {
@@ -2321,7 +2483,9 @@ var BUILTIN_TOOLS = [
2321
2483
  source: "builtin",
2322
2484
  permissionDefault: "ask",
2323
2485
  isReadOnly: false,
2324
- isConcurrencySafe: false
2486
+ isConcurrencySafe: false,
2487
+ timeoutMs: 36e5
2488
+ // 1h — supports long-running shell loops (e.g. `until` polling)
2325
2489
  },
2326
2490
  execute: bashTool
2327
2491
  },
@@ -2361,10 +2525,32 @@ var BUILTIN_TOOLS = [
2361
2525
  source: "builtin",
2362
2526
  permissionDefault: "allow",
2363
2527
  isReadOnly: true,
2364
- isConcurrencySafe: true
2528
+ isConcurrencySafe: true,
2529
+ timeoutMs: 18e5
2530
+ // 30min — sub-agent runs may execute many tool calls
2365
2531
  },
2366
2532
  execute: agentTool
2367
2533
  },
2534
+ {
2535
+ definition: {
2536
+ ...agentStatusToolDef,
2537
+ source: "builtin",
2538
+ permissionDefault: "allow",
2539
+ isReadOnly: true,
2540
+ isConcurrencySafe: true
2541
+ },
2542
+ execute: agentStatusTool
2543
+ },
2544
+ {
2545
+ definition: {
2546
+ ...agentCancelToolDef,
2547
+ source: "builtin",
2548
+ permissionDefault: "allow",
2549
+ isReadOnly: false,
2550
+ isConcurrencySafe: false
2551
+ },
2552
+ execute: agentCancelTool
2553
+ },
2368
2554
  {
2369
2555
  definition: {
2370
2556
  ...enterPlanModeToolDef,
@@ -2647,7 +2833,9 @@ var BUILTIN_TOOLS = [
2647
2833
  source: "builtin",
2648
2834
  permissionDefault: "ask",
2649
2835
  isReadOnly: true,
2650
- isConcurrencySafe: false
2836
+ isConcurrencySafe: false,
2837
+ timeoutMs: 18e5
2838
+ // 30min — multi-model debate rounds take time
2651
2839
  },
2652
2840
  execute: arenaTool
2653
2841
  }
@@ -2655,10 +2843,11 @@ var BUILTIN_TOOLS = [
2655
2843
 
2656
2844
  // src/tool-system/registry.ts
2657
2845
  _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
2658
- var ToolRegistry = (_class4 = class {
2659
- __init7() {this.tools = /* @__PURE__ */ new Map()}
2660
- __init8() {this.builtinExecutors = /* @__PURE__ */ new Map()}
2661
- constructor(options = {}) {;_class4.prototype.__init7.call(this);_class4.prototype.__init8.call(this);
2846
+ var DEFAULT_TOOL_TIMEOUT_MS = 12e4;
2847
+ var ToolRegistry = (_class5 = class {
2848
+ __init8() {this.tools = /* @__PURE__ */ new Map()}
2849
+ __init9() {this.builtinExecutors = /* @__PURE__ */ new Map()}
2850
+ constructor(options = {}) {;_class5.prototype.__init8.call(this);_class5.prototype.__init9.call(this);
2662
2851
  this.registerBuiltins(options.builtinTools);
2663
2852
  }
2664
2853
  registerBuiltins(selectedBuiltinTools) {
@@ -2709,10 +2898,7 @@ var ToolRegistry = (_class4 = class {
2709
2898
  if (!executor) {
2710
2899
  throw new (0, _chunkEL2RL5DGcjs.ToolExecutionError)(name, "No executor registered for this tool");
2711
2900
  }
2712
- const LONG_TIMEOUT_TOOLS = /* @__PURE__ */ new Set(["Agent", "Arena"]);
2713
- const isLongRunning = LONG_TIMEOUT_TOOLS.has(name);
2714
- const defaultTimeout = isLongRunning ? 18e5 : 12e4;
2715
- const timeout = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _46 => _46.timeoutMs]), () => ( defaultTimeout));
2901
+ const timeout = _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _46 => _46.timeoutMs]), () => ( tool.timeoutMs)), () => ( DEFAULT_TOOL_TIMEOUT_MS));
2716
2902
  const parentSignal = _optionalChain([options, 'optionalAccess', _47 => _47.signal]);
2717
2903
  const id = `tool_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
2718
2904
  if (_optionalChain([parentSignal, 'optionalAccess', _48 => _48.aborted])) {
@@ -2762,7 +2948,7 @@ var ToolRegistry = (_class4 = class {
2762
2948
  listToolsDetailed() {
2763
2949
  return [...this.tools.values()];
2764
2950
  }
2765
- }, _class4);
2951
+ }, _class5);
2766
2952
 
2767
2953
  // src/tool-system/executor.ts
2768
2954
  _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
@@ -2796,7 +2982,7 @@ function validateToolArgs(toolName, args, schema) {
2796
2982
  }
2797
2983
  }
2798
2984
  return null;
2799
- } catch (e9) {
2985
+ } catch (e12) {
2800
2986
  return null;
2801
2987
  }
2802
2988
  }
@@ -3115,9 +3301,9 @@ var AutoApprovalBackend = class {
3115
3301
  return false;
3116
3302
  }
3117
3303
  };
3118
- var InteractiveApprovalBackend = (_class5 = class {constructor() { _class5.prototype.__init9.call(this);_class5.prototype.__init10.call(this); }
3119
- __init9() {this.sessionRules = /* @__PURE__ */ new Map()}
3120
- __init10() {this.promptFn = null}
3304
+ var InteractiveApprovalBackend = (_class6 = class {constructor() { _class6.prototype.__init10.call(this);_class6.prototype.__init11.call(this); }
3305
+ __init10() {this.sessionRules = /* @__PURE__ */ new Map()}
3306
+ __init11() {this.promptFn = null}
3121
3307
  setPromptFn(fn) {
3122
3308
  this.promptFn = fn;
3123
3309
  }
@@ -3126,7 +3312,7 @@ var InteractiveApprovalBackend = (_class5 = class {constructor() { _class5.proto
3126
3312
  if (toolRule === "allow") return { approved: true };
3127
3313
  if (toolRule === "deny") return { approved: false };
3128
3314
  if (!this.promptFn) {
3129
- return { approved: true };
3315
+ return { approved: false, reason: "interactive approval backend has no prompt function" };
3130
3316
  }
3131
3317
  const result = await this.promptFn(req);
3132
3318
  if (result.always && result.approved) {
@@ -3141,7 +3327,7 @@ var InteractiveApprovalBackend = (_class5 = class {constructor() { _class5.proto
3141
3327
  if (args.command) return String(args.command).slice(0, 50);
3142
3328
  return "";
3143
3329
  }
3144
- }, _class5);
3330
+ }, _class6);
3145
3331
  var _interactiveBackend = null;
3146
3332
  function getInteractiveApprovalBackend() {
3147
3333
  if (!_interactiveBackend) {
@@ -3212,11 +3398,11 @@ function classifyBashCommand(command) {
3212
3398
  }
3213
3399
  return "unsafe";
3214
3400
  }
3215
- var DenialTracker = (_class6 = class {
3216
- __init11() {this.denials = /* @__PURE__ */ new Map()}
3401
+ var DenialTracker = (_class7 = class {
3402
+ __init12() {this.denials = /* @__PURE__ */ new Map()}
3217
3403
 
3218
3404
 
3219
- constructor(opts) {;_class6.prototype.__init11.call(this);
3405
+ constructor(opts) {;_class7.prototype.__init12.call(this);
3220
3406
  this.periodMs = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _64 => _64.periodMs]), () => ( 60 * 60 * 1e3));
3221
3407
  this.maxDenials = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _65 => _65.maxDenials]), () => ( 5));
3222
3408
  }
@@ -3250,18 +3436,18 @@ var DenialTracker = (_class6 = class {
3250
3436
  clear() {
3251
3437
  this.denials.clear();
3252
3438
  }
3253
- }, _class6);
3439
+ }, _class7);
3254
3440
  var _runtimeBypass = false;
3255
3441
  function setRuntimeBypass(enabled) {
3256
3442
  _runtimeBypass = enabled;
3257
3443
  }
3258
- var PermissionClassifier = (_class7 = class {
3259
- constructor(rules, defaultMode = "default", approvalBackend = new HeadlessApprovalBackend("deny-all")) {;_class7.prototype.__init12.call(this);
3444
+ var PermissionClassifier = (_class8 = class {
3445
+ constructor(rules, defaultMode = "default", approvalBackend = new HeadlessApprovalBackend("deny-all")) {;_class8.prototype.__init13.call(this);
3260
3446
  this.rules = rules;
3261
3447
  this.defaultMode = defaultMode;
3262
3448
  this.approvalBackend = approvalBackend;
3263
3449
  }
3264
- __init12() {this.denialTracker = new DenialTracker()}
3450
+ __init13() {this.denialTracker = new DenialTracker()}
3265
3451
  classify(toolName, args) {
3266
3452
  if (_runtimeBypass) return "allow";
3267
3453
  for (const rule of this.rules) {
@@ -3352,12 +3538,12 @@ var PermissionClassifier = (_class7 = class {
3352
3538
  return `${toolName}(${JSON.stringify(args).slice(0, 100)})`;
3353
3539
  }
3354
3540
  }
3355
- }, _class7);
3541
+ }, _class8);
3356
3542
 
3357
3543
  // src/hooks/registry.ts
3358
3544
  _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
3359
- var HookRegistry = (_class8 = class {constructor() { _class8.prototype.__init13.call(this); }
3360
- __init13() {this.hooks = /* @__PURE__ */ new Map()}
3545
+ var HookRegistry = (_class9 = class {constructor() { _class9.prototype.__init14.call(this); }
3546
+ __init14() {this.hooks = /* @__PURE__ */ new Map()}
3361
3547
  register(eventName, handler, priority = 0, name) {
3362
3548
  if (!this.hooks.has(eventName)) {
3363
3549
  this.hooks.set(eventName, []);
@@ -3419,7 +3605,7 @@ var HookRegistry = (_class8 = class {constructor() { _class8.prototype.__init13.
3419
3605
  countHandlers(eventName) {
3420
3606
  return _nullishCoalesce(_optionalChain([this, 'access', _71 => _71.hooks, 'access', _72 => _72.get, 'call', _73 => _73(eventName), 'optionalAccess', _74 => _74.length]), () => ( 0));
3421
3607
  }
3422
- }, _class8);
3608
+ }, _class9);
3423
3609
 
3424
3610
  // src/context/manager.ts
3425
3611
  _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
@@ -3430,11 +3616,11 @@ var DEFAULT_CONFIG = {
3430
3616
  summarizeAtRatio: 0.8,
3431
3617
  maxToolResultChars: 3e4
3432
3618
  };
3433
- var ContextManager = (_class9 = class {
3619
+ var ContextManager = (_class10 = class {
3434
3620
 
3435
- __init14() {this.toolCallHashes = /* @__PURE__ */ new Map()}
3621
+ __init15() {this.toolCallHashes = /* @__PURE__ */ new Map()}
3436
3622
 
3437
- __init15() {this.consecutiveSummaryFailures = 0}
3623
+ __init16() {this.consecutiveSummaryFailures = 0}
3438
3624
 
3439
3625
  /** Last known actual token count from API usage data. */
3440
3626
 
@@ -3442,7 +3628,7 @@ var ContextManager = (_class9 = class {
3442
3628
 
3443
3629
  /** Path to session transcript — passed to summary compaction for on-demand access. */
3444
3630
 
3445
- constructor(config) {;_class9.prototype.__init14.call(this);_class9.prototype.__init15.call(this);
3631
+ constructor(config) {;_class10.prototype.__init15.call(this);_class10.prototype.__init16.call(this);
3446
3632
  this.config = { ...DEFAULT_CONFIG, ...config };
3447
3633
  }
3448
3634
  /**
@@ -3632,12 +3818,12 @@ var ContextManager = (_class9 = class {
3632
3818
  hashCall(toolName, args) {
3633
3819
  return `${toolName}:${JSON.stringify(args)}`;
3634
3820
  }
3635
- }, _class9);
3821
+ }, _class10);
3636
3822
 
3637
3823
  // src/prompt/section-cache.ts
3638
3824
  _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
3639
- var SectionCache = (_class10 = class {constructor() { _class10.prototype.__init16.call(this); }
3640
- __init16() {this.cache = /* @__PURE__ */ new Map()}
3825
+ var SectionCache = (_class11 = class {constructor() { _class11.prototype.__init17.call(this); }
3826
+ __init17() {this.cache = /* @__PURE__ */ new Map()}
3641
3827
  async resolve(sections) {
3642
3828
  const results = [];
3643
3829
  for (const section of sections) {
@@ -3661,7 +3847,7 @@ var SectionCache = (_class10 = class {constructor() { _class10.prototype.__init1
3661
3847
  has(name) {
3662
3848
  return this.cache.has(name);
3663
3849
  }
3664
- }, _class10);
3850
+ }, _class11);
3665
3851
 
3666
3852
  // src/prompt/instruction-scanner.ts
3667
3853
  _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
@@ -3723,7 +3909,7 @@ function tryAddFile(path, source, depth, entries) {
3723
3909
  if (content) {
3724
3910
  entries.push({ path, content, source, depth });
3725
3911
  }
3726
- } catch (e10) {
3912
+ } catch (e13) {
3727
3913
  }
3728
3914
  }
3729
3915
  function tryAddRulesDir(dir, source, depth, entries) {
@@ -3733,7 +3919,7 @@ function tryAddRulesDir(dir, source, depth, entries) {
3733
3919
  for (const file of files) {
3734
3920
  tryAddFile(_path.join.call(void 0, dir, file), source, depth, entries);
3735
3921
  }
3736
- } catch (e11) {
3922
+ } catch (e14) {
3737
3923
  }
3738
3924
  }
3739
3925
  function findGitRoot2(cwd) {
@@ -3744,7 +3930,7 @@ function findGitRoot2(cwd) {
3744
3930
  timeout: 3e3,
3745
3931
  stdio: ["pipe", "pipe", "pipe"]
3746
3932
  }).trim() || null;
3747
- } catch (e12) {
3933
+ } catch (e15) {
3748
3934
  return null;
3749
3935
  }
3750
3936
  }
@@ -3870,6 +4056,8 @@ var GENERAL_BUILTIN_TOOLS = [
3870
4056
  "WebFetch",
3871
4057
  "AskUserQuestion",
3872
4058
  "Agent",
4059
+ "AgentStatus",
4060
+ "AgentCancel",
3873
4061
  "EnterPlanMode",
3874
4062
  "ExitPlanMode",
3875
4063
  "ToolSearch",
@@ -3909,6 +4097,8 @@ var GENERAL_PERMISSION_RULES = [
3909
4097
  { tool: "WebFetch", decision: "allow" },
3910
4098
  { tool: "AskUserQuestion", decision: "allow" },
3911
4099
  { tool: "Agent", decision: "allow" },
4100
+ { tool: "AgentStatus", decision: "allow" },
4101
+ { tool: "AgentCancel", decision: "allow" },
3912
4102
  { tool: "EnterPlanMode", decision: "allow" },
3913
4103
  { tool: "ExitPlanMode", decision: "allow" },
3914
4104
  { tool: "ToolSearch", decision: "allow" },
@@ -3983,12 +4173,12 @@ function resolveBuiltinToolNames(options) {
3983
4173
 
3984
4174
  // src/prompt/composer.ts
3985
4175
  _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
3986
- var PromptComposer = (_class11 = class {
3987
- constructor(options) {;_class11.prototype.__init17.call(this);_class11.prototype.__init18.call(this);
4176
+ var PromptComposer = (_class12 = class {
4177
+ constructor(options) {;_class12.prototype.__init18.call(this);_class12.prototype.__init19.call(this);
3988
4178
  this.options = options;
3989
4179
  }
3990
- __init17() {this.sectionCache = new SectionCache()}
3991
- __init18() {this.cachedInstructions = null}
4180
+ __init18() {this.sectionCache = new SectionCache()}
4181
+ __init19() {this.cachedInstructions = null}
3992
4182
  /**
3993
4183
  * Build the system prompt from sections.
3994
4184
  */
@@ -4053,7 +4243,7 @@ ${status}`;
4053
4243
  Recent commits:
4054
4244
  ${log}`;
4055
4245
  }
4056
- } catch (e13) {
4246
+ } catch (e16) {
4057
4247
  }
4058
4248
  return gitStatus;
4059
4249
  }
@@ -4130,11 +4320,11 @@ ${toolLines.join("\n\n")}`;
4130
4320
  try {
4131
4321
  const mm = new (0, _chunk3EAEC566cjs.MemoryManager)(this.options.cwd);
4132
4322
  return mm.buildMemoryContext();
4133
- } catch (e14) {
4323
+ } catch (e17) {
4134
4324
  return "";
4135
4325
  }
4136
4326
  }
4137
- }, _class11);
4327
+ }, _class12);
4138
4328
 
4139
4329
  // src/engine/engine.ts
4140
4330
  _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
@@ -4326,13 +4516,13 @@ function checkTokenBudget(turnOutputTokens, budget, tracker) {
4326
4516
 
4327
4517
  // src/engine/streaming-tool-queue.ts
4328
4518
  _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
4329
- var StreamingToolQueue = (_class12 = class {
4519
+ var StreamingToolQueue = (_class13 = class {
4330
4520
 
4331
- __init19() {this.pending = /* @__PURE__ */ new Map()}
4332
- __init20() {this.unsafeQueue = []}
4333
- __init21() {this.callOrder = []}
4334
- __init22() {this.draining = false}
4335
- constructor(executor) {;_class12.prototype.__init19.call(this);_class12.prototype.__init20.call(this);_class12.prototype.__init21.call(this);_class12.prototype.__init22.call(this);
4521
+ __init20() {this.pending = /* @__PURE__ */ new Map()}
4522
+ __init21() {this.unsafeQueue = []}
4523
+ __init22() {this.callOrder = []}
4524
+ __init23() {this.draining = false}
4525
+ constructor(executor) {;_class13.prototype.__init20.call(this);_class13.prototype.__init21.call(this);_class13.prototype.__init22.call(this);_class13.prototype.__init23.call(this);
4336
4526
  this.executor = executor;
4337
4527
  }
4338
4528
  /**
@@ -4368,17 +4558,17 @@ var StreamingToolQueue = (_class12 = class {
4368
4558
  get size() {
4369
4559
  return this.callOrder.length;
4370
4560
  }
4371
- }, _class12);
4561
+ }, _class13);
4372
4562
 
4373
4563
  // src/engine/turn-loop.ts
4374
- var TurnLoop = (_class13 = class {
4375
- constructor(deps, config) {;_class13.prototype.__init23.call(this);_class13.prototype.__init24.call(this);
4564
+ var TurnLoop = (_class14 = class {
4565
+ constructor(deps, config) {;_class14.prototype.__init24.call(this);_class14.prototype.__init25.call(this);
4376
4566
  this.deps = deps;
4377
4567
  this.config = config;
4378
4568
  }
4379
- __init23() {this.turnCount = 0}
4569
+ __init24() {this.turnCount = 0}
4380
4570
  /** Tool IDs already emitted as tool_use_start during streaming (to avoid duplicates). */
4381
- __init24() {this.streamedToolIds = /* @__PURE__ */ new Set()}
4571
+ __init25() {this.streamedToolIds = /* @__PURE__ */ new Set()}
4382
4572
  /**
4383
4573
  * Run the multi-turn agent loop until completion.
4384
4574
  */
@@ -4433,19 +4623,19 @@ var TurnLoop = (_class13 = class {
4433
4623
  } catch (retryErr) {
4434
4624
  if (!(retryErr instanceof _chunkEL2RL5DGcjs.ContextLimitError)) {
4435
4625
  _optionalChain([this, 'access', _85 => _85.config, 'access', _86 => _86.onStream, 'optionalCall', _87 => _87({ type: "error", error: retryErr.message })]);
4436
- return { text: finalText, reason: "model_error" };
4626
+ return { text: finalText, reason: "model_error", messages };
4437
4627
  }
4438
4628
  }
4439
4629
  }
4440
4630
  if (!recovered) {
4441
4631
  this.patchOrphanedToolUses(messages);
4442
4632
  _optionalChain([this, 'access', _88 => _88.config, 'access', _89 => _89.onStream, 'optionalCall', _90 => _90({ type: "error", error: "Context limit exceeded after 3 recovery attempts" })]);
4443
- return { text: finalText, reason: "prompt_too_long" };
4633
+ return { text: finalText, reason: "prompt_too_long", messages };
4444
4634
  }
4445
4635
  } else {
4446
4636
  this.patchOrphanedToolUses(messages);
4447
4637
  _optionalChain([this, 'access', _91 => _91.config, 'access', _92 => _92.onStream, 'optionalCall', _93 => _93({ type: "error", error: err.message })]);
4448
- return { text: finalText, reason: "model_error" };
4638
+ return { text: finalText, reason: "model_error", messages };
4449
4639
  }
4450
4640
  }
4451
4641
  if (_optionalChain([response, 'access', _94 => _94.usage, 'optionalAccess', _95 => _95.promptTokens]) !== void 0) {
@@ -4476,14 +4666,14 @@ var TurnLoop = (_class13 = class {
4476
4666
  response = { ...contResponse, text: combinedText };
4477
4667
  break;
4478
4668
  }
4479
- } catch (e15) {
4669
+ } catch (e18) {
4480
4670
  break;
4481
4671
  }
4482
4672
  }
4483
4673
  response = { ...response, text: combinedText };
4484
4674
  }
4485
4675
  if (_optionalChain([this, 'access', _96 => _96.config, 'access', _97 => _97.signal, 'optionalAccess', _98 => _98.aborted])) {
4486
- return { text: finalText, reason: "aborted_streaming" };
4676
+ return { text: finalText, reason: "aborted_streaming", messages };
4487
4677
  }
4488
4678
  if (response.text) {
4489
4679
  finalText = response.text;
@@ -4502,7 +4692,8 @@ var TurnLoop = (_class13 = class {
4502
4692
  turnNumber: this.turnCount,
4503
4693
  hasToolUse: false
4504
4694
  });
4505
- return { text: finalText, reason: "completed" };
4695
+ messages.push({ role: "assistant", content: finalText });
4696
+ return { text: finalText, reason: "completed", messages };
4506
4697
  }
4507
4698
  _chunkIMMTBZ33cjs.logger.info("turn.tool_use", { turn: this.turnCount, tools: response.toolCalls.map((t) => t.toolName) });
4508
4699
  const toolCalls = response.toolCalls.slice(0, this.config.maxToolCallsPerTurn);
@@ -4566,7 +4757,8 @@ var TurnLoop = (_class13 = class {
4566
4757
  type: "assistant_message",
4567
4758
  message: { role: "assistant", content: finalText }
4568
4759
  })]);
4569
- return { text: finalText, reason: "completed" };
4760
+ messages.push({ role: "assistant", content: finalText });
4761
+ return { text: finalText, reason: "completed", messages };
4570
4762
  }
4571
4763
  if (budgetDecision === "nudge") {
4572
4764
  messages.push({
@@ -4599,7 +4791,7 @@ var TurnLoop = (_class13 = class {
4599
4791
  if (summaryResponse.text) {
4600
4792
  finalText = summaryResponse.text;
4601
4793
  }
4602
- } catch (e16) {
4794
+ } catch (e19) {
4603
4795
  _chunkIMMTBZ33cjs.logger.warn("turn.summary_failed");
4604
4796
  }
4605
4797
  if (finalText) {
@@ -4607,9 +4799,10 @@ var TurnLoop = (_class13 = class {
4607
4799
  type: "assistant_message",
4608
4800
  message: { role: "assistant", content: finalText }
4609
4801
  })]);
4802
+ messages.push({ role: "assistant", content: finalText });
4610
4803
  }
4611
4804
  _optionalChain([this, 'access', _121 => _121.config, 'access', _122 => _122.onStream, 'optionalCall', _123 => _123({ type: "turn_complete", reason: "max_turns" })]);
4612
- return { text: finalText, reason: "max_turns" };
4805
+ return { text: finalText, reason: "max_turns", messages };
4613
4806
  }
4614
4807
  /**
4615
4808
  * Call model with streaming fallback.
@@ -4731,15 +4924,15 @@ var TurnLoop = (_class13 = class {
4731
4924
  return;
4732
4925
  }
4733
4926
  }
4734
- }, _class13);
4927
+ }, _class14);
4735
4928
 
4736
4929
  // src/engine/engine.ts
4737
4930
  init_plan();
4738
4931
  _chunkFGZGCFJXcjs.init_manager.call(void 0, );
4739
4932
 
4740
4933
 
4741
- var Engine = class _Engine {
4742
- constructor(config) {
4934
+ var Engine = (_class15 = class _Engine {
4935
+ constructor(config) {;_class15.prototype.__init26.call(this);
4743
4936
  this.config = config;
4744
4937
  this.preset = resolveAgentPreset(config.preset);
4745
4938
  this.toolRegistry = new ToolRegistry({
@@ -4750,6 +4943,9 @@ var Engine = class _Engine {
4750
4943
  })
4751
4944
  });
4752
4945
  this.hooks = new HookRegistry();
4946
+ for (const hook of _nullishCoalesce(config.hooks, () => ( []))) {
4947
+ this.hooks.register(hook.event, hook.handler, hook.priority, hook.name);
4948
+ }
4753
4949
  this.sessionManager = new (0, _chunkNG73UR3Lcjs.SessionManager)(config.sessionStorageDir);
4754
4950
  this.modelPool = new (0, _chunkUK2SU23Scjs.ModelPool)();
4755
4951
  try {
@@ -4771,7 +4967,7 @@ var Engine = class _Engine {
4771
4967
  const match = settings.models.find((m) => m.model === currentModel);
4772
4968
  if (match) this.modelPool.switch(match.key);
4773
4969
  }
4774
- } catch (e17) {
4970
+ } catch (e20) {
4775
4971
  }
4776
4972
  }
4777
4973
 
@@ -4819,7 +5015,7 @@ var Engine = class _Engine {
4819
5015
  let messages;
4820
5016
  if (_optionalChain([options, 'optionalAccess', _132 => _132.sessionId])) {
4821
5017
  session = this.sessionManager.resume(options.sessionId);
4822
- messages = session.transcript.toMessages();
5018
+ messages = this.compactedMessagesBySession.get(options.sessionId) ? [...this.compactedMessagesBySession.get(options.sessionId)] : session.transcript.toMessages();
4823
5019
  if (session.state.costState && this.config.costStore) {
4824
5020
  this.config.costStore.restore(session.state.costState);
4825
5021
  }
@@ -4851,7 +5047,7 @@ var Engine = class _Engine {
4851
5047
  if (_optionalChain([settings, 'access', _133 => _133.permissions, 'optionalAccess', _134 => _134.rules, 'optionalAccess', _135 => _135.length])) {
4852
5048
  defaultRules.unshift(...settings.permissions.rules);
4853
5049
  }
4854
- } catch (e18) {
5050
+ } catch (e21) {
4855
5051
  }
4856
5052
  let approvalBackend;
4857
5053
  if (this.config.approvalBackend) {
@@ -4860,7 +5056,7 @@ var Engine = class _Engine {
4860
5056
  approvalBackend = new AutoApprovalBackend();
4861
5057
  } else {
4862
5058
  approvalBackend = new HeadlessApprovalBackend(
4863
- mode === "bypassPermissions" ? "approve-all" : mode === "dontAsk" ? "deny-all" : "approve-all"
5059
+ mode === "bypassPermissions" ? "approve-all" : mode === "dontAsk" ? "deny-all" : "deny-all"
4864
5060
  );
4865
5061
  }
4866
5062
  const permission = new PermissionClassifier(defaultRules, mode, approvalBackend);
@@ -4912,6 +5108,8 @@ var Engine = class _Engine {
4912
5108
  if (userContextMsg) {
4913
5109
  messages.unshift(userContextMsg);
4914
5110
  }
5111
+ this.lastSessionId = session.state.sessionId;
5112
+ this.lastMessages = messages;
4915
5113
  contextManager.setTranscriptPath(session.transcript.getFilePath());
4916
5114
  contextManager.setSummarizeFn(async (prompt) => {
4917
5115
  const summaryResponse = await llmClient.createMessage({
@@ -4977,6 +5175,11 @@ var Engine = class _Engine {
4977
5175
  }
4978
5176
  );
4979
5177
  const result = await turnLoop.run(messages);
5178
+ this.lastMessages = result.messages;
5179
+ this.compactedMessagesBySession.set(
5180
+ session.state.sessionId,
5181
+ this.stripUserContextMessage(result.messages, userContextMsg)
5182
+ );
4980
5183
  _chunkIMMTBZ33cjs.logger.info("engine.done", {
4981
5184
  sessionId: session.state.sessionId,
4982
5185
  reason: result.reason,
@@ -5059,19 +5262,29 @@ var Engine = class _Engine {
5059
5262
  * Returns token stats before/after.
5060
5263
  */
5061
5264
  forceCompact() {
5062
- if (!this.lastContextManager || !this.lastMessages) {
5265
+ const sessionId = this.lastSessionId;
5266
+ if (!this.lastContextManager || !sessionId) {
5063
5267
  return { before: 0, after: 0, strategy: "none (no active session)" };
5064
5268
  }
5065
5269
  const { estimateTokens: estimateTokens2 } = (_chunkLRAY5IYCcjs.init_compaction.call(void 0, ), _chunkIJSHQGMPcjs.__toCommonJS.call(void 0, _chunkLRAY5IYCcjs.compaction_exports));
5066
- const before = estimateTokens2(this.lastMessages);
5067
- this.lastMessages = this.lastContextManager.manage(this.lastMessages);
5068
- const after = estimateTokens2(this.lastMessages);
5270
+ const sourceMessages = _nullishCoalesce(this.compactedMessagesBySession.get(sessionId), () => ( this.sessionManager.resume(sessionId).transcript.toMessages()));
5271
+ const before = estimateTokens2(sourceMessages);
5272
+ const compacted = this.lastContextManager.manage(sourceMessages);
5273
+ const after = estimateTokens2(compacted);
5274
+ this.compactedMessagesBySession.set(sessionId, compacted);
5275
+ this.lastMessages = compacted;
5069
5276
  return {
5070
5277
  before,
5071
5278
  after,
5072
5279
  strategy: before === after ? "no compaction needed" : "compacted"
5073
5280
  };
5074
5281
  }
5282
+ stripUserContextMessage(messages, userContextMsg) {
5283
+ if (!userContextMsg || messages[0] !== userContextMsg) {
5284
+ return [...messages];
5285
+ }
5286
+ return messages.slice(1);
5287
+ }
5075
5288
  /**
5076
5289
  * Update a config setting at runtime.
5077
5290
  */
@@ -5090,7 +5303,9 @@ var Engine = class _Engine {
5090
5303
  /** Track last context manager and messages for /compact support. */
5091
5304
 
5092
5305
 
5093
- };
5306
+
5307
+ __init26() {this.compactedMessagesBySession = /* @__PURE__ */ new Map()}
5308
+ }, _class15);
5094
5309
 
5095
5310
  // src/run/types.ts
5096
5311
  _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
@@ -5126,9 +5341,9 @@ _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
5126
5341
 
5127
5342
 
5128
5343
 
5129
- var FileRunStore = (_class14 = class {
5344
+ var FileRunStore = (_class16 = class {
5130
5345
 
5131
- constructor(storageDir) {;_class14.prototype.__init25.call(this);
5346
+ constructor(storageDir) {;_class16.prototype.__init27.call(this);
5132
5347
  this.runsDir = _nullishCoalesce(storageDir, () => ( _path.join.call(void 0, _os.homedir.call(void 0, ), ".code-shell", "runs")));
5133
5348
  _fs.mkdirSync.call(void 0, this.runsDir, { recursive: true });
5134
5349
  }
@@ -5154,7 +5369,7 @@ var FileRunStore = (_class14 = class {
5154
5369
  return JSON.parse(_fs.readFileSync.call(void 0, filePath, "utf-8"));
5155
5370
  }
5156
5371
  /** Serializes concurrent JSONL appends per file path. */
5157
- __init25() {this.appendLocks = /* @__PURE__ */ new Map()}
5372
+ __init27() {this.appendLocks = /* @__PURE__ */ new Map()}
5158
5373
  async appendJsonl(filePath, data) {
5159
5374
  const prev = _nullishCoalesce(this.appendLocks.get(filePath), () => ( Promise.resolve()));
5160
5375
  const current = prev.then(() => {
@@ -5274,17 +5489,17 @@ var FileRunStore = (_class14 = class {
5274
5489
  _path.join.call(void 0, this.runDir(runId), "artifacts", "refs.jsonl")
5275
5490
  );
5276
5491
  }
5277
- }, _class14);
5492
+ }, _class16);
5278
5493
 
5279
5494
  // src/run/RunQueue.ts
5280
5495
  _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
5281
- var RunQueue = (_class15 = class {
5496
+ var RunQueue = (_class17 = class {
5282
5497
 
5283
- __init26() {this.pending = []}
5284
- __init27() {this.active = /* @__PURE__ */ new Set()}
5285
- __init28() {this.executor = null}
5286
- __init29() {this.draining = false}
5287
- constructor(config) {;_class15.prototype.__init26.call(this);_class15.prototype.__init27.call(this);_class15.prototype.__init28.call(this);_class15.prototype.__init29.call(this);
5498
+ __init28() {this.pending = []}
5499
+ __init29() {this.active = /* @__PURE__ */ new Set()}
5500
+ __init30() {this.executor = null}
5501
+ __init31() {this.draining = false}
5502
+ constructor(config) {;_class17.prototype.__init28.call(this);_class17.prototype.__init29.call(this);_class17.prototype.__init30.call(this);_class17.prototype.__init31.call(this);
5288
5503
  this.concurrency = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _151 => _151.concurrency]), () => ( 1));
5289
5504
  }
5290
5505
  setExecutor(fn) {
@@ -5336,18 +5551,18 @@ var RunQueue = (_class15 = class {
5336
5551
  });
5337
5552
  }
5338
5553
  }
5339
- }, _class15);
5554
+ }, _class17);
5340
5555
 
5341
5556
  // src/run/RunApprovalBackend.ts
5342
5557
  _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
5343
- var RunApprovalBackend = (_class16 = class {constructor() { _class16.prototype.__init30.call(this);_class16.prototype.__init31.call(this);_class16.prototype.__init32.call(this); }
5344
- __init30() {this.pendingApproval = null}
5345
- __init31() {this.hooks = null}
5558
+ var RunApprovalBackend = (_class18 = class {constructor() { _class18.prototype.__init32.call(this);_class18.prototype.__init33.call(this);_class18.prototype.__init34.call(this); }
5559
+ __init32() {this.pendingApproval = null}
5560
+ __init33() {this.hooks = null}
5346
5561
  setHooks(hooks) {
5347
5562
  this.hooks = hooks;
5348
5563
  }
5349
5564
  /** Max time (ms) to wait for approval before auto-rejecting. Default: 24h */
5350
- __init32() {this.timeoutMs = 24 * 60 * 60 * 1e3}
5565
+ __init34() {this.timeoutMs = 24 * 60 * 60 * 1e3}
5351
5566
  setTimeout(ms) {
5352
5567
  this.timeoutMs = ms;
5353
5568
  }
@@ -5382,7 +5597,7 @@ var RunApprovalBackend = (_class16 = class {constructor() { _class16.prototype._
5382
5597
  hasPendingApproval() {
5383
5598
  return this.pendingApproval !== null;
5384
5599
  }
5385
- }, _class16);
5600
+ }, _class18);
5386
5601
  function createRunAskUserFn(hooks) {
5387
5602
  let pending = null;
5388
5603
  const askUserFn = async (question) => {
@@ -5415,16 +5630,16 @@ var PHASE_PATTERNS = [
5415
5630
  { pattern: /\breview\b.*\b(complete|done|finished)\b/i, phase: "review_complete" },
5416
5631
  { pattern: /\brefactor\b.*\b(complete|done|finished)\b/i, phase: "refactor_complete" }
5417
5632
  ];
5418
- var CheckpointWriter = (_class17 = class {
5633
+ var CheckpointWriter = (_class19 = class {
5419
5634
 
5420
5635
 
5421
- __init33() {this.currentTurn = 0}
5422
- __init34() {this.lastCheckpointTurn = 0}
5423
- __init35() {this.touchedTools = /* @__PURE__ */ new Set()}
5424
- __init36() {this.lastAssistantText = ""}
5425
- __init37() {this.sessionId = null}
5426
- __init38() {this.detectedPhases = /* @__PURE__ */ new Set()}
5427
- constructor(config) {;_class17.prototype.__init33.call(this);_class17.prototype.__init34.call(this);_class17.prototype.__init35.call(this);_class17.prototype.__init36.call(this);_class17.prototype.__init37.call(this);_class17.prototype.__init38.call(this);
5636
+ __init35() {this.currentTurn = 0}
5637
+ __init36() {this.lastCheckpointTurn = 0}
5638
+ __init37() {this.touchedTools = /* @__PURE__ */ new Set()}
5639
+ __init38() {this.lastAssistantText = ""}
5640
+ __init39() {this.sessionId = null}
5641
+ __init40() {this.detectedPhases = /* @__PURE__ */ new Set()}
5642
+ constructor(config) {;_class19.prototype.__init35.call(this);_class19.prototype.__init36.call(this);_class19.prototype.__init37.call(this);_class19.prototype.__init38.call(this);_class19.prototype.__init39.call(this);_class19.prototype.__init40.call(this);
5428
5643
  this.config = config;
5429
5644
  this.turnInterval = _nullishCoalesce(config.turnInterval, () => ( 10));
5430
5645
  }
@@ -5510,16 +5725,16 @@ var CheckpointWriter = (_class17 = class {
5510
5725
  }
5511
5726
  return truncated.trim() + (text.length > 400 ? "..." : "");
5512
5727
  }
5513
- }, _class17);
5728
+ }, _class19);
5514
5729
 
5515
5730
  // src/run/ArtifactTracker.ts
5516
5731
  _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
5517
5732
 
5518
- var ArtifactTracker = (_class18 = class {
5733
+ var ArtifactTracker = (_class20 = class {
5519
5734
 
5520
- __init39() {this.pendingCalls = /* @__PURE__ */ new Map()}
5521
- __init40() {this.recordedPaths = /* @__PURE__ */ new Set()}
5522
- constructor(config) {;_class18.prototype.__init39.call(this);_class18.prototype.__init40.call(this);
5735
+ __init41() {this.pendingCalls = /* @__PURE__ */ new Map()}
5736
+ __init42() {this.recordedPaths = /* @__PURE__ */ new Set()}
5737
+ constructor(config) {;_class20.prototype.__init41.call(this);_class20.prototype.__init42.call(this);
5523
5738
  this.config = config;
5524
5739
  }
5525
5740
  /**
@@ -5630,7 +5845,7 @@ var ArtifactTracker = (_class18 = class {
5630
5845
  return;
5631
5846
  }
5632
5847
  }
5633
- }, _class18);
5848
+ }, _class20);
5634
5849
  function extractFileName(filePath) {
5635
5850
  const parts = filePath.split("/");
5636
5851
  return parts[parts.length - 1] || filePath;
@@ -5662,11 +5877,11 @@ function check(file, options) {
5662
5877
  }
5663
5878
 
5664
5879
  // src/run/RunLock.ts
5665
- var RunLock = (_class19 = class {
5880
+ var RunLock = (_class21 = class {
5666
5881
 
5667
5882
 
5668
- __init41() {this.releaseFns = /* @__PURE__ */ new Map()}
5669
- constructor(config) {;_class19.prototype.__init41.call(this);
5883
+ __init43() {this.releaseFns = /* @__PURE__ */ new Map()}
5884
+ constructor(config) {;_class21.prototype.__init43.call(this);
5670
5885
  this.runsDir = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _154 => _154.runsDir]), () => ( _path.join.call(void 0, _os.homedir.call(void 0, ), ".code-shell", "runs")));
5671
5886
  this.staleMs = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _155 => _155.staleMs]), () => ( 6e4));
5672
5887
  }
@@ -5684,7 +5899,7 @@ var RunLock = (_class19 = class {
5684
5899
  this.releaseFns.set(runId, release);
5685
5900
  _chunkIMMTBZ33cjs.logger.info("run.lock.acquired", { runId });
5686
5901
  return true;
5687
- } catch (e19) {
5902
+ } catch (e22) {
5688
5903
  return false;
5689
5904
  }
5690
5905
  }
@@ -5696,7 +5911,7 @@ var RunLock = (_class19 = class {
5696
5911
  if (releaseFn) {
5697
5912
  try {
5698
5913
  await releaseFn();
5699
- } catch (e20) {
5914
+ } catch (e23) {
5700
5915
  }
5701
5916
  this.releaseFns.delete(runId);
5702
5917
  _chunkIMMTBZ33cjs.logger.info("run.lock.released", { runId });
@@ -5710,7 +5925,7 @@ var RunLock = (_class19 = class {
5710
5925
  if (!_fs.existsSync.call(void 0, lockTarget)) return false;
5711
5926
  try {
5712
5927
  return await check(lockTarget, { stale: this.staleMs });
5713
- } catch (e21) {
5928
+ } catch (e24) {
5714
5929
  return false;
5715
5930
  }
5716
5931
  }
@@ -5723,7 +5938,7 @@ var RunLock = (_class19 = class {
5723
5938
  try {
5724
5939
  await unlock(lockTarget);
5725
5940
  _chunkIMMTBZ33cjs.logger.info("run.lock.force_unlocked", { runId });
5726
- } catch (e22) {
5941
+ } catch (e25) {
5727
5942
  }
5728
5943
  }
5729
5944
  /**
@@ -5737,18 +5952,18 @@ var RunLock = (_class19 = class {
5737
5952
  lockTarget(runId) {
5738
5953
  return _path.join.call(void 0, this.runsDir, runId, "run.json");
5739
5954
  }
5740
- }, _class19);
5955
+ }, _class21);
5741
5956
 
5742
5957
  // src/run/Heartbeat.ts
5743
5958
  _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
5744
5959
 
5745
5960
 
5746
5961
 
5747
- var Heartbeat = (_class20 = class {
5962
+ var Heartbeat = (_class22 = class {
5748
5963
 
5749
5964
 
5750
- __init42() {this.timers = /* @__PURE__ */ new Map()}
5751
- constructor(config) {;_class20.prototype.__init42.call(this);
5965
+ __init44() {this.timers = /* @__PURE__ */ new Map()}
5966
+ constructor(config) {;_class22.prototype.__init44.call(this);
5752
5967
  this.runsDir = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _156 => _156.runsDir]), () => ( _path.join.call(void 0, _os.homedir.call(void 0, ), ".code-shell", "runs")));
5753
5968
  this.intervalMs = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _157 => _157.intervalMs]), () => ( 5e3));
5754
5969
  }
@@ -5790,7 +6005,7 @@ var Heartbeat = (_class20 = class {
5790
6005
  if (!_fs.existsSync.call(void 0, filePath)) return null;
5791
6006
  try {
5792
6007
  return JSON.parse(_fs.readFileSync.call(void 0, filePath, "utf-8"));
5793
- } catch (e23) {
6008
+ } catch (e26) {
5794
6009
  return null;
5795
6010
  }
5796
6011
  }
@@ -5813,7 +6028,7 @@ var Heartbeat = (_class20 = class {
5813
6028
  try {
5814
6029
  process.kill(data.pid, 0);
5815
6030
  return true;
5816
- } catch (e24) {
6031
+ } catch (e27) {
5817
6032
  return false;
5818
6033
  }
5819
6034
  }
@@ -5825,7 +6040,7 @@ var Heartbeat = (_class20 = class {
5825
6040
  };
5826
6041
  try {
5827
6042
  _fs.writeFileSync.call(void 0, this.filePath(runId), JSON.stringify(data), "utf-8");
5828
- } catch (e25) {
6043
+ } catch (e28) {
5829
6044
  }
5830
6045
  }
5831
6046
  remove(runId) {
@@ -5834,22 +6049,22 @@ var Heartbeat = (_class20 = class {
5834
6049
  if (_fs.existsSync.call(void 0, filePath)) {
5835
6050
  _fs.unlinkSync.call(void 0, filePath);
5836
6051
  }
5837
- } catch (e26) {
6052
+ } catch (e29) {
5838
6053
  }
5839
6054
  }
5840
6055
  filePath(runId) {
5841
6056
  return _path.join.call(void 0, this.runsDir, runId, "heartbeat");
5842
6057
  }
5843
- }, _class20);
6058
+ }, _class22);
5844
6059
 
5845
6060
  // src/run/Evaluator.ts
5846
6061
  _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
5847
- var NoopEvaluator = (_class21 = class {constructor() { _class21.prototype.__init43.call(this); }
5848
- __init43() {this.name = "noop"}
6062
+ var NoopEvaluator = (_class23 = class {constructor() { _class23.prototype.__init45.call(this); }
6063
+ __init45() {this.name = "noop"}
5849
6064
  async evaluate() {
5850
6065
  return { verdict: "passed", findings: [] };
5851
6066
  }
5852
- }, _class21);
6067
+ }, _class23);
5853
6068
  var CompositeEvaluator = class {
5854
6069
 
5855
6070
 
@@ -5921,6 +6136,7 @@ var EngineRunner = class {
5921
6136
  appendSystemPrompt: this.config.appendSystemPrompt,
5922
6137
  sessionStorageDir: this.config.sessionStorageDir,
5923
6138
  mcpServers: this.config.mcpServers,
6139
+ hooks: this.config.hooks,
5924
6140
  approvalBackend,
5925
6141
  askUser: askUserFn,
5926
6142
  ...context.engineConfigOverrides
@@ -5954,18 +6170,20 @@ var EngineRunner = class {
5954
6170
  // src/run/RunManager.ts
5955
6171
  _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
5956
6172
 
5957
- var RunManager = (_class22 = class {
6173
+ var RunManager = (_class24 = class {
6174
+
6175
+
5958
6176
 
5959
6177
 
5960
6178
 
5961
6179
 
5962
6180
 
5963
6181
 
5964
- __init44() {this.subscribers = /* @__PURE__ */ new Map()}
5965
- __init45() {this.abortControllers = /* @__PURE__ */ new Map()}
6182
+ __init46() {this.subscribers = /* @__PURE__ */ new Map()}
6183
+ __init47() {this.abortControllers = /* @__PURE__ */ new Map()}
5966
6184
  /** Active execution handles — used to resolve pending approvals/input while Engine is suspended */
5967
- __init46() {this.executionHandles = /* @__PURE__ */ new Map()}
5968
- constructor(config) {;_class22.prototype.__init44.call(this);_class22.prototype.__init45.call(this);_class22.prototype.__init46.call(this);
6185
+ __init48() {this.executionHandles = /* @__PURE__ */ new Map()}
6186
+ constructor(config) {;_class24.prototype.__init46.call(this);_class24.prototype.__init47.call(this);_class24.prototype.__init48.call(this);
5969
6187
  this.store = config.store;
5970
6188
  this.queue = new RunQueue({ concurrency: _nullishCoalesce(config.concurrency, () => ( 1)) });
5971
6189
  this.runner = isRunExecutor(config.executor) ? config.executor : new EngineRunner(config.executor);
@@ -5978,6 +6196,8 @@ var RunManager = (_class22 = class {
5978
6196
  intervalMs: config.heartbeatIntervalMs
5979
6197
  });
5980
6198
  this.evaluator = _nullishCoalesce(config.evaluator, () => ( new NoopEvaluator()));
6199
+ this.defaultTags = _nullishCoalesce(config.defaultTags, () => ( []));
6200
+ this.defaultMetadata = _nullishCoalesce(config.defaultMetadata, () => ( {}));
5981
6201
  this.queue.setExecutor((runId) => this.executeRun(runId));
5982
6202
  }
5983
6203
  // ─── Submit ────────────────────────────────────────────────────
@@ -6002,8 +6222,8 @@ var RunManager = (_class22 = class {
6002
6222
  latestApprovalId: null,
6003
6223
  summary: null,
6004
6224
  error: null,
6005
- tags: _nullishCoalesce(input.tags, () => ( [])),
6006
- metadata: _nullishCoalesce(input.metadata, () => ( {}))
6225
+ tags: [.../* @__PURE__ */ new Set([...this.defaultTags, ..._nullishCoalesce(input.tags, () => ( []))])],
6226
+ metadata: { ...this.defaultMetadata, ..._nullishCoalesce(input.metadata, () => ( {})) }
6007
6227
  };
6008
6228
  await this.store.create(snapshot);
6009
6229
  await this.emitRunEvent(runId, "run_created", { objective: input.objective });
@@ -6454,7 +6674,7 @@ var RunManager = (_class22 = class {
6454
6674
  if (!run) throw new Error(`Run not found: ${runId}`);
6455
6675
  return run;
6456
6676
  }
6457
- }, _class22);
6677
+ }, _class24);
6458
6678
  function isRunExecutor(obj) {
6459
6679
  return obj != null && typeof obj.execute === "function";
6460
6680
  }
@@ -6508,4 +6728,5 @@ function isRunExecutor(obj) {
6508
6728
 
6509
6729
 
6510
6730
 
6511
- exports.setAskUserFn = setAskUserFn; exports.isInPlanMode = isInPlanMode; exports.setInPlanMode = setInPlanMode; exports.plan_exports = plan_exports; exports.init_plan = init_plan; exports.taskManager = taskManager; exports.BUILTIN_TOOLS = BUILTIN_TOOLS; exports.ToolRegistry = ToolRegistry; exports.ToolExecutor = ToolExecutor; exports.HeadlessApprovalBackend = HeadlessApprovalBackend; exports.AutoApprovalBackend = AutoApprovalBackend; exports.setInteractiveApprovalFn = setInteractiveApprovalFn; exports.setRuntimeBypass = setRuntimeBypass; exports.PermissionClassifier = PermissionClassifier; exports.HookRegistry = HookRegistry; exports.ContextManager = ContextManager; exports.SectionCache = SectionCache; exports.scanInstructions = scanInstructions; exports.combineInstructions = combineInstructions; exports.registerSection = registerSection; exports.loadSection = loadSection; exports.loadSections = loadSections; exports.availableSections = availableSections; exports.BUILTIN_AGENT_PRESETS = BUILTIN_AGENT_PRESETS; exports.DEFAULT_AGENT_PRESET = DEFAULT_AGENT_PRESET; exports.DEFAULT_CLI_PRESET = DEFAULT_CLI_PRESET; exports.registerPreset = registerPreset; exports.listPresetNames = listPresetNames; exports.resolveAgentPreset = resolveAgentPreset; exports.buildPresetSystemPrompt = buildPresetSystemPrompt; exports.resolveBuiltinToolNames = resolveBuiltinToolNames; exports.PromptComposer = PromptComposer; exports.updateLastInteractionTime = updateLastInteractionTime; exports.flushInteractionTime = flushInteractionTime; exports.Engine = Engine; exports.VALID_TRANSITIONS = VALID_TRANSITIONS; exports.FileRunStore = FileRunStore; exports.RunQueue = RunQueue; exports.RunApprovalBackend = RunApprovalBackend; exports.createRunAskUserFn = createRunAskUserFn; exports.CheckpointWriter = CheckpointWriter; exports.ArtifactTracker = ArtifactTracker; exports.RunLock = RunLock; exports.Heartbeat = Heartbeat; exports.NoopEvaluator = NoopEvaluator; exports.CompositeEvaluator = CompositeEvaluator; exports.EngineRunner = EngineRunner; exports.RunManager = RunManager;
6731
+
6732
+ exports.setAskUserFn = setAskUserFn; exports.isInPlanMode = isInPlanMode; exports.setInPlanMode = setInPlanMode; exports.plan_exports = plan_exports; exports.init_plan = init_plan; exports.taskManager = taskManager; exports.BUILTIN_TOOLS = BUILTIN_TOOLS; exports.ToolRegistry = ToolRegistry; exports.ToolExecutor = ToolExecutor; exports.HeadlessApprovalBackend = HeadlessApprovalBackend; exports.AutoApprovalBackend = AutoApprovalBackend; exports.getInteractiveApprovalBackend = getInteractiveApprovalBackend; exports.setInteractiveApprovalFn = setInteractiveApprovalFn; exports.setRuntimeBypass = setRuntimeBypass; exports.PermissionClassifier = PermissionClassifier; exports.HookRegistry = HookRegistry; exports.ContextManager = ContextManager; exports.SectionCache = SectionCache; exports.scanInstructions = scanInstructions; exports.combineInstructions = combineInstructions; exports.registerSection = registerSection; exports.loadSection = loadSection; exports.loadSections = loadSections; exports.availableSections = availableSections; exports.BUILTIN_AGENT_PRESETS = BUILTIN_AGENT_PRESETS; exports.DEFAULT_AGENT_PRESET = DEFAULT_AGENT_PRESET; exports.DEFAULT_CLI_PRESET = DEFAULT_CLI_PRESET; exports.registerPreset = registerPreset; exports.listPresetNames = listPresetNames; exports.resolveAgentPreset = resolveAgentPreset; exports.buildPresetSystemPrompt = buildPresetSystemPrompt; exports.resolveBuiltinToolNames = resolveBuiltinToolNames; exports.PromptComposer = PromptComposer; exports.updateLastInteractionTime = updateLastInteractionTime; exports.flushInteractionTime = flushInteractionTime; exports.Engine = Engine; exports.VALID_TRANSITIONS = VALID_TRANSITIONS; exports.FileRunStore = FileRunStore; exports.RunQueue = RunQueue; exports.RunApprovalBackend = RunApprovalBackend; exports.createRunAskUserFn = createRunAskUserFn; exports.CheckpointWriter = CheckpointWriter; exports.ArtifactTracker = ArtifactTracker; exports.RunLock = RunLock; exports.Heartbeat = Heartbeat; exports.NoopEvaluator = NoopEvaluator; exports.CompositeEvaluator = CompositeEvaluator; exports.EngineRunner = EngineRunner; exports.RunManager = RunManager;