@oh-my-pi/pi-coding-agent 17.1.8 → 17.2.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.
Files changed (246) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/dist/{CHANGELOG-vt8ene9g.md → CHANGELOG-dj46zzrm.md} +110 -0
  3. package/dist/cli.js +10009 -9654
  4. package/dist/{template-dys3vk5b.js → template-8vdv6xb4.js} +1 -1
  5. package/dist/types/advisor/runtime.d.ts +8 -2
  6. package/dist/types/advisor/transcript-recorder.d.ts +15 -0
  7. package/dist/types/auto-thinking/classifier.d.ts +9 -2
  8. package/dist/types/cli/args.d.ts +2 -0
  9. package/dist/types/cli/session-picker.d.ts +14 -7
  10. package/dist/types/collab/guest.d.ts +21 -2
  11. package/dist/types/commands/launch.d.ts +6 -0
  12. package/dist/types/config/model-discovery.d.ts +12 -0
  13. package/dist/types/config/settings-schema.d.ts +73 -8
  14. package/dist/types/cursor-bridge-tools.d.ts +54 -0
  15. package/dist/types/cursor.d.ts +193 -8
  16. package/dist/types/edit/edit-clipboard.d.ts +19 -0
  17. package/dist/types/edit/hashline/diff.d.ts +9 -1
  18. package/dist/types/edit/index.d.ts +8 -1
  19. package/dist/types/edit/streaming.d.ts +8 -1
  20. package/dist/types/extensibility/extensions/runner.d.ts +19 -2
  21. package/dist/types/extensibility/extensions/types.d.ts +25 -1
  22. package/dist/types/extensibility/legacy-pi-coding-agent-shim.d.ts +25 -0
  23. package/dist/types/internal-urls/index.d.ts +1 -0
  24. package/dist/types/internal-urls/local-protocol.d.ts +3 -2
  25. package/dist/types/internal-urls/security-protocol.d.ts +15 -0
  26. package/dist/types/internal-urls/types.d.ts +1 -1
  27. package/dist/types/launch/terminal-output-worker-client.d.ts +5 -0
  28. package/dist/types/launch/terminal-output-worker-protocol.d.ts +14 -0
  29. package/dist/types/launch/terminal-output-worker.d.ts +1 -0
  30. package/dist/types/lsp/client.d.ts +2 -0
  31. package/dist/types/main.d.ts +2 -0
  32. package/dist/types/mcp/manager.d.ts +33 -4
  33. package/dist/types/modes/components/codex-reset-fireworks.d.ts +51 -0
  34. package/dist/types/modes/components/read-tool-group.d.ts +12 -0
  35. package/dist/types/modes/components/session-selector.d.ts +6 -0
  36. package/dist/types/modes/components/status-line/component.d.ts +23 -0
  37. package/dist/types/modes/components/tool-execution.d.ts +16 -7
  38. package/dist/types/modes/components/usage-row.d.ts +2 -0
  39. package/dist/types/modes/controllers/mcp-command-controller.d.ts +26 -1
  40. package/dist/types/modes/controllers/selector-controller.d.ts +2 -1
  41. package/dist/types/modes/interactive-mode.d.ts +4 -2
  42. package/dist/types/modes/rpc/rpc-client.d.ts +7 -0
  43. package/dist/types/modes/rpc/rpc-types.d.ts +16 -0
  44. package/dist/types/modes/theme/theme.d.ts +12 -1
  45. package/dist/types/modes/types.d.ts +2 -1
  46. package/dist/types/sdk.d.ts +18 -0
  47. package/dist/types/security/auth.d.ts +30 -0
  48. package/dist/types/security/cloud.d.ts +79 -0
  49. package/dist/types/security/comparison.d.ts +49 -0
  50. package/dist/types/security/contracts/ids.d.ts +15 -0
  51. package/dist/types/security/contracts/index.d.ts +4 -0
  52. package/dist/types/security/contracts/schemas.d.ts +660 -0
  53. package/dist/types/security/contracts/types.d.ts +234 -0
  54. package/dist/types/security/contracts/validation.d.ts +5 -0
  55. package/dist/types/security/coordinator.d.ts +100 -0
  56. package/dist/types/security/importers/codex-security.d.ts +7 -0
  57. package/dist/types/security/importers/index.d.ts +2 -0
  58. package/dist/types/security/importers/sarif.d.ts +9 -0
  59. package/dist/types/security/index.d.ts +13 -0
  60. package/dist/types/security/preflight.d.ts +61 -0
  61. package/dist/types/security/provenance.d.ts +24 -0
  62. package/dist/types/security/publication.d.ts +78 -0
  63. package/dist/types/security/remediation.d.ts +27 -0
  64. package/dist/types/security/resource-output.d.ts +8 -0
  65. package/dist/types/security/sarif.d.ts +2 -0
  66. package/dist/types/security/store.d.ts +40 -0
  67. package/dist/types/session/agent-session-events.d.ts +2 -0
  68. package/dist/types/session/agent-session-types.d.ts +36 -1
  69. package/dist/types/session/agent-session.d.ts +4 -2
  70. package/dist/types/session/claude-session-store.d.ts +13 -0
  71. package/dist/types/session/codex-session-store.d.ts +14 -0
  72. package/dist/types/session/credential-pin.d.ts +58 -0
  73. package/dist/types/session/foreign-session-import.d.ts +15 -0
  74. package/dist/types/session/foreign-session-jsonl.d.ts +9 -0
  75. package/dist/types/session/foreign-session-store.d.ts +23 -0
  76. package/dist/types/session/session-advisors.d.ts +47 -2
  77. package/dist/types/session/session-entries.d.ts +19 -1
  78. package/dist/types/session/session-handoff.d.ts +4 -1
  79. package/dist/types/session/session-loader.d.ts +2 -0
  80. package/dist/types/session/session-maintenance.d.ts +1 -1
  81. package/dist/types/session/session-manager.d.ts +21 -0
  82. package/dist/types/session/session-tools.d.ts +25 -1
  83. package/dist/types/session/turn-recovery.d.ts +10 -4
  84. package/dist/types/slash-commands/helpers/security.d.ts +2 -0
  85. package/dist/types/system-prompt.d.ts +4 -1
  86. package/dist/types/task/executor.d.ts +14 -2
  87. package/dist/types/task/render.d.ts +7 -0
  88. package/dist/types/thinking.d.ts +18 -6
  89. package/dist/types/tools/acp-bridge.d.ts +28 -5
  90. package/dist/types/tools/builtin-names.d.ts +1 -1
  91. package/dist/types/tools/grep.d.ts +17 -1
  92. package/dist/types/tools/hub/launch.d.ts +5 -1
  93. package/dist/types/tools/index.d.ts +10 -2
  94. package/dist/types/tools/path-utils.d.ts +19 -0
  95. package/dist/types/tools/read.d.ts +2 -0
  96. package/dist/types/tools/security-scan.d.ts +96 -0
  97. package/dist/types/tools/xdev.d.ts +2 -1
  98. package/dist/types/utils/changelog.d.ts +19 -0
  99. package/dist/types/utils/git.d.ts +10 -0
  100. package/dist/types/utils/jj.d.ts +11 -4
  101. package/dist/types/web/search/types.d.ts +2 -2
  102. package/package.json +12 -12
  103. package/scripts/security-compare.ts +40 -0
  104. package/src/advisor/runtime.ts +138 -12
  105. package/src/advisor/transcript-recorder.ts +56 -0
  106. package/src/auto-thinking/classifier.ts +48 -10
  107. package/src/cli/args.ts +6 -0
  108. package/src/cli/flag-tables.ts +2 -0
  109. package/src/cli/gallery-fixtures/fs.ts +25 -0
  110. package/src/cli/session-picker.ts +34 -17
  111. package/src/cli/ttsr-cli.ts +19 -1
  112. package/src/cli.ts +9 -0
  113. package/src/collab/guest.ts +37 -4
  114. package/src/collab/host.ts +1 -0
  115. package/src/commands/launch.ts +6 -0
  116. package/src/config/model-discovery.ts +32 -5
  117. package/src/config/model-registry.ts +107 -25
  118. package/src/config/settings-schema.ts +77 -6
  119. package/src/config/settings.ts +25 -0
  120. package/src/cursor-bridge-tools.ts +81 -0
  121. package/src/cursor.ts +463 -12
  122. package/src/edit/edit-clipboard.ts +23 -0
  123. package/src/edit/hashline/diff.ts +49 -10
  124. package/src/edit/hashline/execute.ts +38 -6
  125. package/src/edit/hashline/filesystem.ts +27 -3
  126. package/src/edit/index.ts +12 -2
  127. package/src/edit/renderer.ts +4 -4
  128. package/src/edit/streaming.ts +17 -2
  129. package/src/eval/py/prelude.py +7 -3
  130. package/src/export/html/template.js +1 -1
  131. package/src/extensibility/extensions/runner.ts +70 -0
  132. package/src/extensibility/extensions/types.ts +30 -0
  133. package/src/extensibility/legacy-pi-coding-agent-shim.ts +65 -13
  134. package/src/internal-urls/index.ts +1 -0
  135. package/src/internal-urls/local-protocol.ts +3 -2
  136. package/src/internal-urls/mcp-protocol.ts +4 -1
  137. package/src/internal-urls/router.ts +4 -1
  138. package/src/internal-urls/security-protocol.ts +261 -0
  139. package/src/internal-urls/types.ts +1 -1
  140. package/src/launch/terminal-output-worker-client.ts +53 -0
  141. package/src/launch/terminal-output-worker-protocol.ts +11 -0
  142. package/src/launch/terminal-output-worker.ts +23 -0
  143. package/src/lsp/client.ts +18 -3
  144. package/src/lsp/index.ts +7 -0
  145. package/src/lsp/render.ts +1 -1
  146. package/src/main.ts +127 -56
  147. package/src/mcp/manager.ts +120 -18
  148. package/src/modes/acp/acp-agent.ts +15 -9
  149. package/src/modes/components/chat-transcript-builder.ts +30 -11
  150. package/src/modes/components/codex-reset-fireworks.ts +369 -0
  151. package/src/modes/components/read-tool-group.ts +159 -17
  152. package/src/modes/components/session-selector.ts +19 -3
  153. package/src/modes/components/status-line/component.ts +381 -54
  154. package/src/modes/components/tool-execution.ts +78 -31
  155. package/src/modes/components/usage-row.ts +10 -5
  156. package/src/modes/controllers/event-controller.ts +26 -4
  157. package/src/modes/controllers/mcp-command-controller.ts +68 -3
  158. package/src/modes/controllers/selector-controller.ts +94 -36
  159. package/src/modes/controllers/tan-command-controller.ts +14 -0
  160. package/src/modes/interactive-mode.ts +31 -17
  161. package/src/modes/rpc/host-uris.ts +6 -0
  162. package/src/modes/rpc/rpc-client.ts +18 -0
  163. package/src/modes/rpc/rpc-mode.ts +16 -1
  164. package/src/modes/rpc/rpc-types.ts +11 -0
  165. package/src/modes/theme/theme.ts +151 -6
  166. package/src/modes/types.ts +2 -1
  167. package/src/modes/utils/ui-helpers.ts +38 -21
  168. package/src/prompts/agents/security-reviewer.md +75 -0
  169. package/src/prompts/security/scan-coordinator.md +7 -0
  170. package/src/prompts/security/scan-request.md +21 -0
  171. package/src/prompts/security/validate-request.md +8 -0
  172. package/src/prompts/system/auto-thinking-difficulty.md +4 -2
  173. package/src/prompts/system/plan-mode-active.md +2 -2
  174. package/src/prompts/system/system-prompt.md +6 -0
  175. package/src/prompts/system/xdev-mount-notice.md +1 -1
  176. package/src/prompts/tools/bash.md +15 -17
  177. package/src/prompts/tools/checkpoint.md +1 -1
  178. package/src/prompts/tools/glob.md +7 -6
  179. package/src/prompts/tools/grep.md +7 -6
  180. package/src/prompts/tools/security-publish.md +1 -0
  181. package/src/prompts/tools/security-scan.md +1 -0
  182. package/src/sdk.ts +212 -21
  183. package/src/security/auth.ts +98 -0
  184. package/src/security/cloud.ts +686 -0
  185. package/src/security/comparison.ts +255 -0
  186. package/src/security/contracts/ids.ts +111 -0
  187. package/src/security/contracts/index.ts +4 -0
  188. package/src/security/contracts/schemas.ts +201 -0
  189. package/src/security/contracts/types.ts +254 -0
  190. package/src/security/contracts/validation.ts +65 -0
  191. package/src/security/coordinator.ts +708 -0
  192. package/src/security/importers/codex-security.ts +387 -0
  193. package/src/security/importers/index.ts +2 -0
  194. package/src/security/importers/sarif.ts +357 -0
  195. package/src/security/index.ts +13 -0
  196. package/src/security/preflight.ts +405 -0
  197. package/src/security/provenance.ts +106 -0
  198. package/src/security/publication.ts +326 -0
  199. package/src/security/remediation.ts +93 -0
  200. package/src/security/resource-output.ts +50 -0
  201. package/src/security/sarif.ts +78 -0
  202. package/src/security/store.ts +430 -0
  203. package/src/session/agent-session-events.ts +1 -0
  204. package/src/session/agent-session-types.ts +40 -1
  205. package/src/session/agent-session.ts +302 -175
  206. package/src/session/claude-session-store.ts +426 -0
  207. package/src/session/codex-session-store.ts +673 -0
  208. package/src/session/credential-pin.ts +93 -0
  209. package/src/session/foreign-session-import.ts +52 -0
  210. package/src/session/foreign-session-jsonl.ts +29 -0
  211. package/src/session/foreign-session-store.ts +26 -0
  212. package/src/session/model-controls.ts +11 -3
  213. package/src/session/session-advisors.ts +140 -16
  214. package/src/session/session-entries.ts +21 -1
  215. package/src/session/session-handoff.ts +20 -3
  216. package/src/session/session-loader.ts +25 -9
  217. package/src/session/session-maintenance.ts +59 -11
  218. package/src/session/session-manager.ts +61 -0
  219. package/src/session/session-tools.ts +107 -5
  220. package/src/session/settings-stream-fn.ts +1 -0
  221. package/src/session/turn-recovery.ts +97 -51
  222. package/src/slash-commands/builtin-registry.ts +152 -3
  223. package/src/slash-commands/helpers/security.ts +451 -0
  224. package/src/system-prompt.ts +7 -2
  225. package/src/task/agents.ts +2 -0
  226. package/src/task/executor.ts +20 -4
  227. package/src/task/render.ts +20 -4
  228. package/src/task/structured-subagent.ts +6 -4
  229. package/src/thinking.ts +29 -10
  230. package/src/tools/acp-bridge.ts +52 -8
  231. package/src/tools/browser.ts +5 -0
  232. package/src/tools/builtin-names.ts +1 -0
  233. package/src/tools/checkpoint.ts +0 -13
  234. package/src/tools/grep.ts +64 -8
  235. package/src/tools/hub/launch.ts +10 -15
  236. package/src/tools/index.ts +37 -5
  237. package/src/tools/path-utils.ts +91 -0
  238. package/src/tools/read.ts +3 -0
  239. package/src/tools/security-scan.ts +287 -0
  240. package/src/tools/write.ts +9 -3
  241. package/src/tools/xdev.ts +39 -14
  242. package/src/utils/changelog.ts +144 -4
  243. package/src/utils/git.ts +61 -14
  244. package/src/utils/jj.ts +19 -13
  245. package/src/web/search/providers/codex.ts +34 -0
  246. package/src/web/search/types.ts +1 -1
@@ -927,6 +927,18 @@ export const SETTINGS_SCHEMA = {
927
927
  },
928
928
  },
929
929
 
930
+ "tui.codexResetFireworks": {
931
+ type: "boolean",
932
+ default: false,
933
+ ui: {
934
+ tab: "appearance",
935
+ group: "Display",
936
+ label: "Codex Reset Fireworks",
937
+ description:
938
+ "Celebrate unscheduled Codex weekly usage resets and newly banked saved resets with a top-third fireworks overlay that remains until Escape",
939
+ },
940
+ },
941
+
930
942
  "tui.titleState": {
931
943
  type: "boolean",
932
944
  default: true,
@@ -1811,14 +1823,32 @@ export const SETTINGS_SCHEMA = {
1811
1823
  },
1812
1824
  },
1813
1825
 
1814
- collapseChangelog: {
1815
- type: "boolean",
1816
- default: false,
1826
+ "startup.changelogMode": {
1827
+ type: "enum",
1828
+ values: ["summary", "expanded", "hidden"] as const,
1829
+ default: "summary",
1817
1830
  ui: {
1818
1831
  tab: "interaction",
1819
1832
  group: "Startup & Updates",
1820
- label: "Collapse Changelog",
1821
- description: "Show condensed changelog after updates",
1833
+ label: "Startup Changelog",
1834
+ description: "Choose whether update notes start as a summary, full details, or stay hidden",
1835
+ options: [
1836
+ {
1837
+ value: "summary",
1838
+ label: "Summary",
1839
+ description: "Show release and change counts with a /changelog hint",
1840
+ },
1841
+ {
1842
+ value: "expanded",
1843
+ label: "Expanded",
1844
+ description: "Show the recent release notes in full",
1845
+ },
1846
+ {
1847
+ value: "hidden",
1848
+ label: "Hidden",
1849
+ description: "Do not show release notes on startup",
1850
+ },
1851
+ ],
1822
1852
  },
1823
1853
  },
1824
1854
 
@@ -4032,6 +4062,18 @@ export const SETTINGS_SCHEMA = {
4032
4062
  },
4033
4063
  },
4034
4064
 
4065
+ "security.enabled": {
4066
+ type: "boolean",
4067
+ default: false,
4068
+ ui: {
4069
+ tab: "tools",
4070
+ group: "Available Tools",
4071
+ label: "Security",
4072
+ description:
4073
+ "Enable OMP-native security scan planning, execution, and the read-only security:// resource namespace",
4074
+ },
4075
+ },
4076
+
4035
4077
  "ask.enabled": {
4036
4078
  type: "boolean",
4037
4079
  default: true,
@@ -4054,6 +4096,18 @@ export const SETTINGS_SCHEMA = {
4054
4096
  },
4055
4097
  },
4056
4098
 
4099
+ "browser.cdpUrl": {
4100
+ type: "string",
4101
+ default: undefined,
4102
+ ui: {
4103
+ tab: "tools",
4104
+ group: "Grep & Browser",
4105
+ label: "Browser CDP URL",
4106
+ description:
4107
+ "Default HTTP CDP discovery endpoint (for example http://127.0.0.1:9222) to attach to instead of launching a browser. Explicit app.cdp_url or app.path on the tool call take precedence.",
4108
+ },
4109
+ },
4110
+
4057
4111
  "browser.headless": {
4058
4112
  type: "boolean",
4059
4113
  default: true,
@@ -4592,7 +4646,7 @@ export const SETTINGS_SCHEMA = {
4592
4646
  group: "Subagents",
4593
4647
  label: "Soft Subagent Request Budget",
4594
4648
  description:
4595
- "Soft per-subagent request budget (assistant requests per run). Crossing it injects a wrap-up steering notice (see task.softRequestBudgetNotice); at 1.5x the budget the run is force-stopped and the agent must yield its partial findings. 0 disables the guard. Bundled scout/sonic agents use a lower built-in budget.",
4649
+ "Soft per-subagent request budget (assistant requests per run). Crossing it injects a wrap-up steering notice (see task.softRequestBudgetNotice); at 1.5x the budget the run is force-stopped and the agent must yield its partial findings. 0 disables the guard. Bundled scout/sonic agents cap out at a lower built-in budget, so a value below that cap still applies to them.",
4596
4650
  options: [
4597
4651
  { value: "0", label: "Disabled" },
4598
4652
  { value: "90", label: "90 requests" },
@@ -5064,6 +5118,23 @@ export const SETTINGS_SCHEMA = {
5064
5118
  options: AUTO_THINKING_MODEL_OPTIONS,
5065
5119
  },
5066
5120
  },
5121
+ "providers.autoThinkingMaxEffort": {
5122
+ type: "enum",
5123
+ values: ["xhigh", "max"] as const,
5124
+ default: "xhigh",
5125
+ ui: {
5126
+ tab: "model",
5127
+ group: "Thinking",
5128
+ label: "Auto Thinking Ceiling",
5129
+ description:
5130
+ "Highest effort the `auto` classifier may resolve. `xhigh` keeps the classifier one tier below the top, so only an explicit `ultrathink` reaches `max`; `max` lets a turn the classifier judges exceptional bill the top tier on models that expose it.",
5131
+ condition: "autoThinkingActive",
5132
+ options: [
5133
+ { value: "xhigh", label: "xhigh", description: "Classifier stops at xhigh (default)" },
5134
+ { value: "max", label: "max", description: "Classifier may resolve max where the model supports it" },
5135
+ ],
5136
+ },
5137
+ },
5067
5138
  "features.unexpectedStopDetection": {
5068
5139
  type: "boolean",
5069
5140
  default: false,
@@ -1346,6 +1346,31 @@ export class Settings {
1346
1346
  }
1347
1347
  delete raw.lastChangelogVersion;
1348
1348
 
1349
+ // collapseChangelog (boolean) -> startup.changelogMode (enum). Preserve
1350
+ // every explicit legacy choice while giving new installs the schema's
1351
+ // "summary" default: true -> summary, false -> expanded. A separately
1352
+ // configured new mode always wins.
1353
+ const startupObj = isRecord(raw.startup) ? (raw.startup as Record<string, unknown>) : undefined;
1354
+ const legacyCollapseChangelog = typeof raw.collapseChangelog === "boolean" ? raw.collapseChangelog : undefined;
1355
+ const flatChangelogMode = raw["startup.changelogMode"];
1356
+ const normalizedFlatChangelogMode =
1357
+ flatChangelogMode === "summary" || flatChangelogMode === "expanded" || flatChangelogMode === "hidden"
1358
+ ? flatChangelogMode
1359
+ : undefined;
1360
+ if (legacyCollapseChangelog !== undefined || normalizedFlatChangelogMode !== undefined) {
1361
+ if (!startupObj) {
1362
+ raw.startup = {};
1363
+ }
1364
+ const target = raw.startup as Record<string, unknown>;
1365
+ if (target.changelogMode === undefined) {
1366
+ target.changelogMode =
1367
+ normalizedFlatChangelogMode ??
1368
+ (legacyCollapseChangelog !== undefined ? (legacyCollapseChangelog ? "summary" : "expanded") : undefined);
1369
+ }
1370
+ }
1371
+ delete raw.collapseChangelog;
1372
+ delete raw["startup.changelogMode"];
1373
+
1349
1374
  // ask.timeout: ms -> seconds (if value > 1000, it's old ms format)
1350
1375
  if (raw.ask && typeof (raw.ask as Record<string, unknown>).timeout === "number") {
1351
1376
  const oldValue = (raw.ask as Record<string, unknown>).timeout as number;
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Per-call tools the Cursor exec bridge needs but the model-facing registry
3
+ * cannot supply.
4
+ *
5
+ * Both bridge callsites — the primary session and the advisor roster — build
6
+ * the same instances, and both must apply the session's approval wrapper. A
7
+ * raw tool here silently escapes the gate every registry call goes through, so
8
+ * the construction lives in one place rather than being repeated per callsite.
9
+ */
10
+
11
+ import type { AgentTool } from "@oh-my-pi/pi-agent-core";
12
+ import { EditTool } from "./edit";
13
+ import type { ExtensionRunner } from "./extensibility/extensions";
14
+ import { ExtensionToolWrapper } from "./extensibility/extensions";
15
+ import type { GrepToolOptions, Tool, ToolSession } from "./tools";
16
+ import { GrepTool } from "./tools";
17
+
18
+ /**
19
+ * Build the bridge's `createGrepTool` factory for one tool session.
20
+ *
21
+ * A `pi_grep` frame carries its own context width and total match cap. Neither
22
+ * is expressible in the model-facing `grep` schema — context comes from
23
+ * `grep.contextBefore`/`grep.contextAfter`, fixed when the shared instance is
24
+ * constructed — so honoring them needs a fresh tool per call.
25
+ *
26
+ * The result is wrapped exactly like a registry tool: the approval gate runs on
27
+ * every call site, and a per-call instance is no exception.
28
+ */
29
+ export function createBridgeGrepFactory(
30
+ session: ToolSession,
31
+ extensionRunner: ExtensionRunner,
32
+ ): (options: GrepToolOptions) => AgentTool {
33
+ return options => {
34
+ const grepTool: Tool = new GrepTool(session, options);
35
+ return new ExtensionToolWrapper(grepTool, extensionRunner);
36
+ };
37
+ }
38
+
39
+ /**
40
+ * Build the `replace`-mode `edit` the bridge answers `pi_edit` with.
41
+ *
42
+ * `PiEditExecArgs` carries `old_text`/`new_text` pairs, which is exactly
43
+ * `replace`'s schema and nothing else's. The session's own instance follows the
44
+ * configured `edit.mode` — `hashline` by default, whose schema is a single
45
+ * `input` string — so a frame handed that instance fails validation instead of
46
+ * editing the file.
47
+ *
48
+ * Callers MUST gate this on the session having actually granted `edit`: the
49
+ * tool is constructed rather than looked up, so building one unconditionally
50
+ * hands a restricted agent a mutating tool it was denied (issue #5680).
51
+ */
52
+ export function createBridgeEditTool(session: ToolSession, extensionRunner: ExtensionRunner): AgentTool {
53
+ const editTool: Tool = new EditTool(session, "replace");
54
+ return new ExtensionToolWrapper(editTool, extensionRunner);
55
+ }
56
+
57
+ /**
58
+ * The tool map the exec bridge should run, given the map a caller granted.
59
+ *
60
+ * `pi_edit` needs a `replace`-mode instance, but only when `edit` was granted:
61
+ * the tool is constructed rather than looked up, so substituting
62
+ * unconditionally would hand a restricted roster a mutating tool it was denied
63
+ * (issue #5680). The granted map is never mutated: an unsubstituted result is a
64
+ * copy, so a caller without an `edit` grant cannot accidentally gain one.
65
+ *
66
+ * The advisor roster passes its granted map here; the primary session keeps its
67
+ * instance out of the registry entirely (Cursor does not advertise `edit`) and
68
+ * serves it through the bridge's `getEditReplaceTool` accessor instead — not
69
+ * the `getTool` fallback, which doubles as the agent loop's resolver for
70
+ * unadvertised calls and must stay device-only.
71
+ */
72
+ export function bridgeToolMap(
73
+ granted: ReadonlyMap<string, AgentTool>,
74
+ createEditTool: (() => AgentTool | undefined) | undefined,
75
+ ): Map<string, AgentTool> {
76
+ const bridged = new Map(granted);
77
+ if (!granted.has("edit") || !createEditTool) return bridged;
78
+ const bridgeEdit = createEditTool();
79
+ if (bridgeEdit) bridged.set("edit", bridgeEdit);
80
+ return bridged;
81
+ }