@agent-watch-ai/edge 0.6.0 → 0.7.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 (309) hide show
  1. package/CHANGELOG.md +288 -9
  2. package/README.md +307 -5
  3. package/dist/billing/billing-mode.d.ts +37 -5
  4. package/dist/billing/billing-mode.js +28 -19
  5. package/dist/billing/constants/billing.constants.d.ts +0 -2
  6. package/dist/billing/constants/billing.constants.js +0 -2
  7. package/dist/billing/index.d.ts +2 -1
  8. package/dist/billing/index.js +1 -1
  9. package/dist/billing/session-billing.d.ts +7 -3
  10. package/dist/billing/session-billing.js +34 -13
  11. package/dist/billing/types/billing.types.d.ts +7 -0
  12. package/dist/capture/capture-env.d.ts +147 -0
  13. package/dist/capture/capture-env.js +301 -0
  14. package/dist/capture/captured-step.d.ts +88 -0
  15. package/dist/capture/captured-step.js +503 -0
  16. package/dist/capture/constants/capture.constants.d.ts +85 -0
  17. package/dist/capture/constants/capture.constants.js +87 -0
  18. package/dist/capture/launched-runs.d.ts +43 -0
  19. package/dist/capture/launched-runs.js +157 -0
  20. package/dist/capture/node.cjs +697 -0
  21. package/dist/capture/node.d.cts +32 -0
  22. package/dist/capture/python/sitecustomize.py +832 -0
  23. package/dist/capture/schemas/capture.schema.d.ts +35 -0
  24. package/dist/capture/schemas/capture.schema.js +31 -0
  25. package/dist/capture/types/capture.types.d.ts +20 -0
  26. package/dist/capture/venv-loader.d.ts +68 -0
  27. package/dist/capture/venv-loader.js +189 -0
  28. package/dist/cli/constants/cli.constants.d.ts +23 -6
  29. package/dist/cli/constants/cli.constants.js +24 -7
  30. package/dist/cli/context.d.ts +19 -22
  31. package/dist/cli/context.js +23 -54
  32. package/dist/cli/doctor-run-capture.d.ts +21 -0
  33. package/dist/cli/doctor-run-capture.js +33 -0
  34. package/dist/cli/doctor.js +21 -68
  35. package/dist/cli/hook-check.d.ts +7 -2
  36. package/dist/cli/hook-check.js +30 -15
  37. package/dist/cli/hook.d.ts +14 -0
  38. package/dist/cli/hook.js +82 -1
  39. package/dist/cli/index.d.ts +1 -1
  40. package/dist/cli/index.js +1 -1
  41. package/dist/cli/misc.js +10 -2
  42. package/dist/cli/npm-global.d.ts +24 -0
  43. package/dist/cli/npm-global.js +77 -0
  44. package/dist/cli/npx-install.js +22 -6
  45. package/dist/cli/replay.d.ts +33 -0
  46. package/dist/cli/replay.js +228 -0
  47. package/dist/cli/setup.d.ts +10 -2
  48. package/dist/cli/setup.js +200 -31
  49. package/dist/cli/status.js +45 -5
  50. package/dist/cli/toggle.js +10 -0
  51. package/dist/cli/types/cli.types.d.ts +15 -1
  52. package/dist/cli/uninstall.js +42 -23
  53. package/dist/cli/update.js +3 -2
  54. package/dist/cli.js +104 -17
  55. package/dist/config/config-store.d.ts +15 -4
  56. package/dist/config/config-store.js +31 -7
  57. package/dist/config/config.d.ts +0 -2
  58. package/dist/config/config.js +0 -1
  59. package/dist/config/constants/config.constants.d.ts +8 -1
  60. package/dist/config/constants/config.constants.js +10 -1
  61. package/dist/config/events-transport.d.ts +15 -0
  62. package/dist/config/events-transport.js +29 -0
  63. package/dist/config/index.d.ts +2 -1
  64. package/dist/config/index.js +1 -0
  65. package/dist/config/root-config.d.ts +12 -0
  66. package/dist/config/root-config.js +24 -0
  67. package/dist/config/schemas/config.schema.d.ts +15 -2
  68. package/dist/config/schemas/config.schema.js +52 -8
  69. package/dist/config/types/config.types.d.ts +7 -0
  70. package/dist/core/index.d.ts +1 -1
  71. package/dist/core/index.js +1 -1
  72. package/dist/core/version.d.ts +9 -0
  73. package/dist/core/version.js +14 -0
  74. package/dist/core/which.d.ts +11 -0
  75. package/dist/core/which.js +18 -0
  76. package/dist/credentials/cloud-claim.d.ts +34 -0
  77. package/dist/credentials/cloud-claim.js +61 -0
  78. package/dist/credentials/constants/credentials.constants.d.ts +16 -1
  79. package/dist/credentials/constants/credentials.constants.js +17 -2
  80. package/dist/credentials/credential-status.js +1 -1
  81. package/dist/credentials/credentials.d.ts +3 -3
  82. package/dist/credentials/credentials.js +26 -12
  83. package/dist/credentials/device-api.d.ts +15 -1
  84. package/dist/credentials/device-api.js +12 -1
  85. package/dist/credentials/identity.d.ts +2 -2
  86. package/dist/credentials/identity.js +2 -2
  87. package/dist/credentials/install-key.d.ts +31 -0
  88. package/dist/credentials/install-key.js +58 -0
  89. package/dist/credentials/migration.d.ts +9 -7
  90. package/dist/credentials/migration.js +58 -18
  91. package/dist/credentials/secret-store.d.ts +12 -0
  92. package/dist/credentials/secret-store.js +18 -1
  93. package/dist/credentials/sign-in.d.ts +27 -0
  94. package/dist/credentials/sign-in.js +31 -1
  95. package/dist/credentials/token-refresher.d.ts +5 -1
  96. package/dist/credentials/token-refresher.js +10 -2
  97. package/dist/enforcement/enforcement.js +1 -1
  98. package/dist/events/constants/events.constants.d.ts +5 -2
  99. package/dist/events/constants/events.constants.js +4 -1
  100. package/dist/events/enrich.d.ts +14 -0
  101. package/dist/events/enrich.js +1 -1
  102. package/dist/events/index.d.ts +1 -0
  103. package/dist/events/product-event.d.ts +6 -3
  104. package/dist/events/types/events.types.d.ts +6 -0
  105. package/dist/events/types/replay-progress.types.d.ts +26 -0
  106. package/dist/events/types/replay-progress.types.js +1 -0
  107. package/dist/events/types/repo-tree.types.d.ts +2 -1
  108. package/dist/feature/ticket-candidates.d.ts +1 -1
  109. package/dist/git/checkout-root.d.ts +15 -0
  110. package/dist/git/checkout-root.js +18 -0
  111. package/dist/git/code-state.d.ts +2 -16
  112. package/dist/git/code-state.js +11 -12
  113. package/dist/git/constants/git.constants.d.ts +33 -11
  114. package/dist/git/constants/git.constants.js +45 -12
  115. package/dist/git/fingerprint.d.ts +3 -6
  116. package/dist/git/fingerprint.js +5 -8
  117. package/dist/git/git-context.js +5 -1
  118. package/dist/git/index.d.ts +1 -2
  119. package/dist/git/index.js +1 -1
  120. package/dist/git/repo-snapshot.d.ts +13 -4
  121. package/dist/git/repo-snapshot.js +53 -9
  122. package/dist/git/types/snapshot.types.d.ts +6 -0
  123. package/dist/pipeline/constants/pipeline.constants.d.ts +3 -0
  124. package/dist/pipeline/constants/pipeline.constants.js +3 -0
  125. package/dist/pipeline/hook-pipeline.js +82 -57
  126. package/dist/privacy/product-capture.js +2 -0
  127. package/dist/providers/antigravity/antigravity.capture.d.ts +2 -0
  128. package/dist/providers/antigravity/antigravity.capture.js +5 -0
  129. package/dist/providers/antigravity/antigravity.detect.js +8 -22
  130. package/dist/providers/antigravity/antigravity.provider.js +10 -3
  131. package/dist/providers/antigravity/constants/antigravity.constants.d.ts +1 -0
  132. package/dist/providers/antigravity/constants/antigravity.constants.js +1 -0
  133. package/dist/providers/claude/claude.adapter.js +9 -6
  134. package/dist/providers/claude/claude.detect.js +2 -17
  135. package/dist/providers/claude/claude.otel.d.ts +21 -3
  136. package/dist/providers/claude/claude.otel.js +216 -61
  137. package/dist/providers/claude/claude.provider.js +21 -1
  138. package/dist/providers/claude/claude.version.d.ts +9 -0
  139. package/dist/providers/claude/claude.version.js +28 -0
  140. package/dist/providers/claude/constants/claude.constants.d.ts +27 -0
  141. package/dist/providers/claude/constants/claude.constants.js +27 -0
  142. package/dist/providers/claude/constants/claude.otel.constants.d.ts +27 -0
  143. package/dist/providers/claude/constants/claude.otel.constants.js +45 -5
  144. package/dist/providers/claude/types/claude.types.d.ts +13 -0
  145. package/dist/providers/codex/codex.capture.d.ts +76 -0
  146. package/dist/providers/codex/codex.capture.js +454 -0
  147. package/dist/providers/codex/codex.detect.js +2 -4
  148. package/dist/providers/codex/codex.otel.d.ts +38 -2
  149. package/dist/providers/codex/codex.otel.js +50 -6
  150. package/dist/providers/codex/codex.provider.js +8 -0
  151. package/dist/providers/codex/codex.surface.d.ts +9 -0
  152. package/dist/{turns/codex-originator.js → providers/codex/codex.surface.js} +17 -3
  153. package/dist/providers/codex/codex.titles.d.ts +14 -0
  154. package/dist/providers/codex/codex.titles.js +35 -0
  155. package/dist/providers/codex/constants/codex.constants.d.ts +4 -0
  156. package/dist/providers/codex/constants/codex.constants.js +4 -0
  157. package/dist/providers/cursor/constants/cursor.constants.d.ts +17 -4
  158. package/dist/providers/cursor/constants/cursor.constants.js +25 -5
  159. package/dist/providers/cursor/cursor-mcp-memo.d.ts +34 -0
  160. package/dist/providers/cursor/cursor-mcp-memo.js +94 -0
  161. package/dist/providers/cursor/cursor.adapter.js +20 -82
  162. package/dist/providers/cursor/cursor.capture.d.ts +1 -0
  163. package/dist/providers/cursor/cursor.capture.js +4 -0
  164. package/dist/providers/cursor/cursor.detect.d.ts +5 -1
  165. package/dist/providers/cursor/cursor.detect.js +11 -26
  166. package/dist/providers/cursor/cursor.hooks.js +2 -2
  167. package/dist/providers/cursor/cursor.provider.js +16 -7
  168. package/dist/providers/cursor/cursor.titles.d.ts +14 -0
  169. package/dist/providers/cursor/cursor.titles.js +20 -0
  170. package/dist/providers/cursor/schemas/cursor.schema.d.ts +3 -3
  171. package/dist/providers/cursor/schemas/cursor.schema.js +5 -3
  172. package/dist/providers/gemini/constants/gemini.constants.d.ts +16 -0
  173. package/dist/providers/gemini/constants/gemini.constants.js +17 -0
  174. package/dist/providers/gemini/gemini.capture.d.ts +81 -0
  175. package/dist/providers/gemini/gemini.capture.js +210 -0
  176. package/dist/providers/gemini/gemini.detect.js +57 -24
  177. package/dist/providers/gemini/gemini.otel.d.ts +38 -2
  178. package/dist/providers/gemini/gemini.otel.js +56 -125
  179. package/dist/providers/gemini/gemini.provider.js +5 -0
  180. package/dist/providers/index.d.ts +1 -0
  181. package/dist/providers/index.js +1 -0
  182. package/dist/providers/provider.d.ts +8 -0
  183. package/dist/providers/provider.js +9 -0
  184. package/dist/providers/registry.d.ts +14 -0
  185. package/dist/providers/registry.js +14 -0
  186. package/dist/providers/shared/constants/hook-config.constants.d.ts +2 -0
  187. package/dist/providers/shared/constants/hook-config.constants.js +2 -0
  188. package/dist/providers/shared/constants/terminal-capture.constants.d.ts +6 -0
  189. package/dist/providers/shared/constants/terminal-capture.constants.js +6 -0
  190. package/dist/providers/shared/editor-paths.d.ts +8 -0
  191. package/dist/providers/shared/editor-paths.js +18 -0
  192. package/dist/providers/shared/hook-config.d.ts +5 -0
  193. package/dist/providers/shared/hook-config.js +39 -1
  194. package/dist/providers/shared/hooks-marker.d.ts +14 -0
  195. package/dist/providers/shared/hooks-marker.js +23 -0
  196. package/dist/providers/shared/install-record.d.ts +29 -0
  197. package/dist/providers/shared/install-record.js +52 -0
  198. package/dist/providers/shared/session-title-store.d.ts +23 -0
  199. package/dist/providers/shared/session-title-store.js +50 -0
  200. package/dist/providers/shared/terminal-capture.d.ts +41 -0
  201. package/dist/providers/shared/terminal-capture.js +109 -0
  202. package/dist/providers/shared/tooling.d.ts +21 -0
  203. package/dist/providers/shared/tooling.js +36 -1
  204. package/dist/providers/types/provider.types.d.ts +57 -4
  205. package/dist/replay/checkout-resolver.d.ts +56 -0
  206. package/dist/replay/checkout-resolver.js +173 -0
  207. package/dist/replay/codex-turns.d.ts +24 -0
  208. package/dist/replay/codex-turns.js +221 -0
  209. package/dist/replay/constants/replay.constants.d.ts +99 -0
  210. package/dist/replay/constants/replay.constants.js +102 -0
  211. package/dist/replay/describe.d.ts +10 -0
  212. package/dist/replay/describe.js +31 -0
  213. package/dist/replay/gemini-turns.d.ts +36 -0
  214. package/dist/replay/gemini-turns.js +192 -0
  215. package/dist/replay/machine.d.ts +34 -0
  216. package/dist/replay/machine.js +68 -0
  217. package/dist/replay/progress-event.d.ts +21 -0
  218. package/dist/replay/progress-event.js +45 -0
  219. package/dist/replay/replay-runner.d.ts +60 -0
  220. package/dist/replay/replay-runner.js +581 -0
  221. package/dist/replay/replay-scan.d.ts +84 -0
  222. package/dist/replay/replay-scan.js +182 -0
  223. package/dist/replay/replay-state.d.ts +108 -0
  224. package/dist/replay/replay-state.js +199 -0
  225. package/dist/replay/resume.d.ts +18 -0
  226. package/dist/replay/resume.js +34 -0
  227. package/dist/replay/start.d.ts +23 -0
  228. package/dist/replay/start.js +39 -0
  229. package/dist/replay/throttle.d.ts +36 -0
  230. package/dist/replay/throttle.js +44 -0
  231. package/dist/replay/transcript-turns.d.ts +35 -0
  232. package/dist/replay/transcript-turns.js +241 -0
  233. package/dist/replay/turn-event.d.ts +40 -0
  234. package/dist/replay/turn-event.js +127 -0
  235. package/dist/replay/types/replay.types.d.ts +198 -0
  236. package/dist/replay/types/replay.types.js +1 -0
  237. package/dist/replay/window.d.ts +28 -0
  238. package/dist/replay/window.js +41 -0
  239. package/dist/replay/worktree-map.d.ts +42 -0
  240. package/dist/replay/worktree-map.js +134 -0
  241. package/dist/snapshot/branch-selection.d.ts +40 -23
  242. package/dist/snapshot/branch-selection.js +71 -41
  243. package/dist/snapshot/constants/snapshot-stages.constants.d.ts +3 -1
  244. package/dist/snapshot/constants/snapshot-stages.constants.js +3 -1
  245. package/dist/snapshot/constants/snapshot.constants.d.ts +34 -7
  246. package/dist/snapshot/constants/snapshot.constants.js +34 -7
  247. package/dist/snapshot/index.d.ts +2 -2
  248. package/dist/snapshot/index.js +1 -1
  249. package/dist/snapshot/snapshot-pipeline.js +100 -26
  250. package/dist/snapshot/snapshot-state.js +6 -2
  251. package/dist/snapshot/tree-pipeline.d.ts +1 -1
  252. package/dist/snapshot/tree-pipeline.js +34 -15
  253. package/dist/snapshot/types/snapshot.types.d.ts +22 -3
  254. package/dist/storage/schemas/storage.schema.d.ts +2 -0
  255. package/dist/storage/schemas/storage.schema.js +6 -0
  256. package/dist/transport/delivery-stats.d.ts +13 -1
  257. package/dist/transport/delivery-stats.js +18 -2
  258. package/dist/transport/delivery.d.ts +4 -3
  259. package/dist/transport/delivery.js +21 -7
  260. package/dist/transport/identity-delivery.d.ts +20 -0
  261. package/dist/transport/identity-delivery.js +41 -0
  262. package/dist/transport/index.d.ts +2 -0
  263. package/dist/transport/index.js +1 -0
  264. package/dist/transport/types/delivery-flow.types.d.ts +7 -0
  265. package/dist/turns/claude-transcript.js +4 -12
  266. package/dist/turns/codex-transcript.d.ts +9 -0
  267. package/dist/turns/codex-transcript.js +27 -19
  268. package/dist/turns/constants/turns.constants.d.ts +29 -12
  269. package/dist/turns/constants/turns.constants.js +31 -19
  270. package/dist/turns/gemini-transcript.d.ts +19 -1
  271. package/dist/turns/gemini-transcript.js +29 -18
  272. package/dist/turns/index.d.ts +3 -4
  273. package/dist/turns/index.js +2 -3
  274. package/dist/turns/run-state.d.ts +71 -0
  275. package/dist/turns/run-state.js +114 -0
  276. package/dist/turns/tool-events.d.ts +11 -1
  277. package/dist/turns/tool-events.js +32 -9
  278. package/dist/turns/transcript.d.ts +15 -14
  279. package/dist/turns/transcript.js +23 -4
  280. package/dist/turns/turn-state.d.ts +82 -7
  281. package/dist/turns/turn-state.js +157 -10
  282. package/dist/turns/turn-summary.js +7 -2
  283. package/dist/turns/turn-tracker.d.ts +9 -16
  284. package/dist/turns/turn-tracker.js +163 -87
  285. package/dist/turns/types/transcript.types.d.ts +11 -1
  286. package/dist/turns/types/turn-provider.types.d.ts +33 -0
  287. package/dist/turns/types/turn-provider.types.js +1 -0
  288. package/dist/turns/types/turn-state.types.d.ts +9 -0
  289. package/dist/turns/types/turn-summary.types.d.ts +17 -1
  290. package/dist/turns/types/turn-tracker.types.d.ts +3 -1
  291. package/dist/turns/work-checkout.js +1 -2
  292. package/docs/AUDIT_PROMPT.md +10 -0
  293. package/docs/DATA_HANDLING.md +201 -13
  294. package/docs/ENTERPRISE_DEPLOYMENT.md +3 -3
  295. package/docs/PERFORMANCE.md +10 -0
  296. package/package.json +3 -2
  297. package/dist/events/canonical-event.d.ts +0 -10
  298. package/dist/events/canonical-event.js +0 -9
  299. package/dist/git/repository-root.d.ts +0 -39
  300. package/dist/git/repository-root.js +0 -131
  301. package/dist/git/types/repository-root.types.d.ts +0 -11
  302. package/dist/transport/transport.d.ts +0 -6
  303. package/dist/turns/codex-originator.d.ts +0 -11
  304. package/dist/turns/cursor-transcript.d.ts +0 -21
  305. package/dist/turns/cursor-transcript.js +0 -66
  306. package/dist/turns/native-session-titles.d.ts +0 -26
  307. package/dist/turns/native-session-titles.js +0 -102
  308. /package/dist/{git/types/repository-root.types.js → billing/types/billing.types.js} +0 -0
  309. /package/dist/{transport/transport.js → capture/types/capture.types.js} +0 -0
@@ -1,4 +1,6 @@
1
+ import { googleAccountBillingMode } from '../../billing/billing-mode.js';
1
2
  import { hookRefusal } from '../shared/hook-refusal.js';
3
+ import { readGeminiTurnUsage } from '../../turns/gemini-transcript.js';
2
4
  import { GEMINI_PROMPT_EVENTS } from './constants/gemini.constants.js';
3
5
  import { detectGemini } from './gemini.detect.js';
4
6
  import { installGeminiHooks, uninstallGeminiHooks } from './gemini.hooks.js';
@@ -19,5 +21,8 @@ export const geminiProvider = {
19
21
  */
20
22
  getBlockResponse: (payload, message) => hookRefusal(payload, GEMINI_PROMPT_EVENTS, { decision: 'deny', reason: message }),
21
23
  shellCall: geminiShellCall,
24
+ readTurnUsage: readGeminiTurnUsage,
25
+ /** Signed in through the shared `~/.gemini` Google account, as Antigravity is. */
26
+ billingMode: googleAccountBillingMode,
22
27
  nativeTelemetry: new GeminiOtelConfigurator()
23
28
  };
@@ -11,4 +11,5 @@ export { classifyTool, contentEvidence, extractCommand, extractFilePath, parseMc
11
11
  export { baseEvent, filePathPatch, promptPatch, providerPatch, responsePatch, toolPatch, withPatch } from './shared/event-builder.js';
12
12
  export { registerOurHandlers, stripOurHandlers, sweepUnregisteredEvents, withHooksBlock, writeJsonValidated } from './shared/hook-config.js';
13
13
  export { hookRefusal } from './shared/hook-refusal.js';
14
+ export { hooksMarkerPresent } from './shared/hooks-marker.js';
14
15
  export { withHookInstall, withOtelInstall, withoutAgent, withoutHookInstall, withoutOtelInstall } from './shared/install-record.js';
@@ -5,4 +5,5 @@ export { classifyTool, contentEvidence, extractCommand, extractFilePath, parseMc
5
5
  export { baseEvent, filePathPatch, promptPatch, providerPatch, responsePatch, toolPatch, withPatch } from './shared/event-builder.js';
6
6
  export { registerOurHandlers, stripOurHandlers, sweepUnregisteredEvents, withHooksBlock, writeJsonValidated } from './shared/hook-config.js';
7
7
  export { hookRefusal } from './shared/hook-refusal.js';
8
+ export { hooksMarkerPresent } from './shared/hooks-marker.js';
8
9
  export { withHookInstall, withOtelInstall, withoutAgent, withoutHookInstall, withoutOtelInstall } from './shared/install-record.js';
@@ -1,3 +1,4 @@
1
+ import type { AgentProvider, RunCaptureRoute } from './types/provider.types.js';
1
2
  export { HOOK_COMMAND_MARKER } from './constants/provider.constants.js';
2
3
  export type { AgentProvider, DetectionResult, HookContext, McpToolName, NativeTelemetryConfigurator, NativeTelemetryStatus, ProviderHookResponse, SetupContext, SetupOutcome, ToolKind, ToolStatus } from './types/provider.types.js';
3
4
  /**
@@ -25,3 +26,10 @@ export declare function isAgentWatchHookCommand(command: string): boolean;
25
26
  * @returns Its tokens, or undefined when the command is not one we emit.
26
27
  */
27
28
  export declare function tokenizeHookCommand(command: string): string[] | undefined;
29
+ /**
30
+ * The agent's run-capture route: its own, else the one its telemetry config carries.
31
+ *
32
+ * @param provider - The agent's provider.
33
+ * @returns The route, or undefined for an agent with none.
34
+ */
35
+ export declare function runCaptureRoute(provider: Pick<AgentProvider, 'runCapture' | 'nativeTelemetry'>): RunCaptureRoute | undefined;
@@ -147,3 +147,12 @@ export function tokenizeHookCommand(command) {
147
147
  tokens.push(token);
148
148
  return tokens;
149
149
  }
150
+ /**
151
+ * The agent's run-capture route: its own, else the one its telemetry config carries.
152
+ *
153
+ * @param provider - The agent's provider.
154
+ * @returns The route, or undefined for an agent with none.
155
+ */
156
+ export function runCaptureRoute(provider) {
157
+ return provider.runCapture ?? provider.nativeTelemetry?.runCapture;
158
+ }
@@ -13,3 +13,17 @@ export { loadProvider, providerIds } from './loaders.js';
13
13
  * present here and missing there installs hooks that resolve no provider.
14
14
  */
15
15
  export declare const providers: readonly AgentProvider[];
16
+ /**
17
+ * The providers an `--agent` value selects: the one place an id is checked against the registry.
18
+ *
19
+ * Commands receive the result and never filter the registry themselves, so an
20
+ * id read as absent cannot quietly widen a run to every agent's config.
21
+ *
22
+ * @param agent - Value of `--agent`.
23
+ * @returns That one provider, or the refusal naming every known id.
24
+ */
25
+ export declare function selectProviders(agent: string): {
26
+ readonly providers: readonly AgentProvider[];
27
+ } | {
28
+ readonly error: string;
29
+ };
@@ -3,6 +3,7 @@ import { claudeProvider } from './claude/claude.provider.js';
3
3
  import { codexProvider } from './codex/codex.provider.js';
4
4
  import { cursorProvider } from './cursor/cursor.provider.js';
5
5
  import { geminiProvider } from './gemini/gemini.provider.js';
6
+ import { providerIds } from './loaders.js';
6
7
  export { loadProvider, providerIds } from './loaders.js';
7
8
  /**
8
9
  * Every provider, eagerly.
@@ -17,3 +18,16 @@ export { loadProvider, providerIds } from './loaders.js';
17
18
  * present here and missing there installs hooks that resolve no provider.
18
19
  */
19
20
  export const providers = [claudeProvider, codexProvider, cursorProvider, geminiProvider, antigravityProvider];
21
+ /**
22
+ * The providers an `--agent` value selects: the one place an id is checked against the registry.
23
+ *
24
+ * Commands receive the result and never filter the registry themselves, so an
25
+ * id read as absent cannot quietly widen a run to every agent's config.
26
+ *
27
+ * @param agent - Value of `--agent`.
28
+ * @returns That one provider, or the refusal naming every known id.
29
+ */
30
+ export function selectProviders(agent) {
31
+ const provider = providers.find((candidate) => candidate.id === agent);
32
+ return provider ? { providers: [provider] } : { error: `unknown agent "${agent}" (known: ${providerIds.join(', ')})` };
33
+ }
@@ -0,0 +1,2 @@
1
+ /** Errors that mean a followed link's target may not be written, so the link itself is replaced instead. */
2
+ export declare const READ_ONLY_CODES: ReadonlySet<string>;
@@ -0,0 +1,2 @@
1
+ /** Errors that mean a followed link's target may not be written, so the link itself is replaced instead. */
2
+ export const READ_ONLY_CODES = new Set(['EROFS', 'EACCES', 'EPERM']);
@@ -0,0 +1,6 @@
1
+ /** Why run capture is off for an app whose terminal route nobody has seen work yet. */
2
+ export declare const NO_TERMINAL_ROUTE = "no environment route: not yet verified on the app";
3
+ /** VS Code settings key prefix for the integrated terminal's environment. */
4
+ export declare const TERMINAL_ENV_PREFIX = "terminal.integrated.env.";
5
+ /** The key suffix VS Code uses per platform; anything else reads `linux`. */
6
+ export declare const TERMINAL_ENV_PLATFORMS: Readonly<Partial<Record<NodeJS.Platform, string>>>;
@@ -0,0 +1,6 @@
1
+ /** Why run capture is off for an app whose terminal route nobody has seen work yet. */
2
+ export const NO_TERMINAL_ROUTE = 'no environment route: not yet verified on the app';
3
+ /** VS Code settings key prefix for the integrated terminal's environment. */
4
+ export const TERMINAL_ENV_PREFIX = 'terminal.integrated.env.';
5
+ /** The key suffix VS Code uses per platform; anything else reads `linux`. */
6
+ export const TERMINAL_ENV_PLATFORMS = { darwin: 'osx', win32: 'windows' };
@@ -0,0 +1,8 @@
1
+ import type { Env } from '../../core/types/core.types.js';
2
+ /**
3
+ * Where VS Code based apps (Cursor, Antigravity) keep their per-user folders on this platform.
4
+ *
5
+ * @param env - Environment supplying HOME, APPDATA and XDG_CONFIG_HOME.
6
+ * @returns The root the app's own folder sits in.
7
+ */
8
+ export declare function editorConfigRoot(env: Env): string;
@@ -0,0 +1,18 @@
1
+ import path from 'node:path';
2
+ /**
3
+ * Where VS Code based apps (Cursor, Antigravity) keep their per-user folders on this platform.
4
+ *
5
+ * @param env - Environment supplying HOME, APPDATA and XDG_CONFIG_HOME.
6
+ * @returns The root the app's own folder sits in.
7
+ */
8
+ export function editorConfigRoot(env) {
9
+ if (env.platform === 'darwin')
10
+ return path.join(env.home, 'Library', 'Application Support');
11
+ if (env.platform === 'win32')
12
+ return absoluteOr(env.vars['APPDATA'], path.join(env.home, 'AppData', 'Roaming'));
13
+ return absoluteOr(env.vars['XDG_CONFIG_HOME'], path.join(env.home, '.config'));
14
+ }
15
+ /** The XDG spec ignores an empty or relative value; kept, it would resolve against the hook's cwd. */
16
+ function absoluteOr(value, fallback) {
17
+ return value && path.isAbsolute(value) ? value : fallback;
18
+ }
@@ -54,6 +54,11 @@ export declare function withHooksBlock(config: UnknownRecord, hooks: UnknownReco
54
54
  * every setting in it, not just the hooks — so a serialization bug must fail
55
55
  * before the file is touched, not after.
56
56
  *
57
+ * A symlinked config (kept in a dotfiles repository by stow or chezmoi) is
58
+ * written at its target, so the link survives. Only agent JSON configs do
59
+ * this: they never hold a token, while the Codex and Gemini files that do keep
60
+ * replacing the link, so a bearer never lands in a dotfiles repository.
61
+ *
57
62
  * @param targetPath - File to write.
58
63
  * @param value - The whole config object.
59
64
  * @param mode - Permissions for credential-bearing settings.
@@ -1,6 +1,8 @@
1
+ import fs from 'node:fs/promises';
1
2
  import { isRecord, omitKeys } from '../../core/object.js';
2
3
  import { writeFileAtomic } from '../../storage/atomic-file.js';
3
4
  import { isAgentWatchHookCommand } from '../provider.js';
5
+ import { READ_ONLY_CODES } from './constants/hook-config.constants.js';
4
6
  /**
5
7
  * Whether one handler is an AgentWatch command.
6
8
  *
@@ -144,6 +146,11 @@ export function withHooksBlock(config, hooks, key = 'hooks') {
144
146
  * every setting in it, not just the hooks — so a serialization bug must fail
145
147
  * before the file is touched, not after.
146
148
  *
149
+ * A symlinked config (kept in a dotfiles repository by stow or chezmoi) is
150
+ * written at its target, so the link survives. Only agent JSON configs do
151
+ * this: they never hold a token, while the Codex and Gemini files that do keep
152
+ * replacing the link, so a bearer never lands in a dotfiles repository.
153
+ *
147
154
  * @param targetPath - File to write.
148
155
  * @param value - The whole config object.
149
156
  * @param mode - Permissions for credential-bearing settings.
@@ -151,7 +158,38 @@ export function withHooksBlock(config, hooks, key = 'hooks') {
151
158
  export async function writeJsonValidated(targetPath, value, mode) {
152
159
  const serialized = `${JSON.stringify(value, null, 2)}\n`;
153
160
  JSON.parse(serialized);
154
- await writeFileAtomic(targetPath, serialized, mode);
161
+ const resolved = await writeTargetOf(targetPath);
162
+ if (resolved === targetPath)
163
+ return writeFileAtomic(targetPath, serialized, mode);
164
+ try {
165
+ await writeFileAtomic(resolved, serialized, mode);
166
+ }
167
+ catch (error) {
168
+ // A target we may not write (Nix home-manager links into the read-only
169
+ // store) keeps the behaviour from before links were followed: the link is
170
+ // replaced, so setup still works.
171
+ if (!READ_ONLY_CODES.has(error.code ?? ''))
172
+ throw error;
173
+ await writeFileAtomic(targetPath, serialized, mode);
174
+ }
175
+ }
176
+ /**
177
+ * Where a config write lands: the file a link points at, or the path itself
178
+ * when nothing exists there yet (a new file, or a dangling link).
179
+ *
180
+ * Only a missing file falls back. A link that fails to resolve for any other
181
+ * reason (a loop, a directory we may not read) would otherwise be silently
182
+ * replaced by a regular file, so that error surfaces instead.
183
+ */
184
+ async function writeTargetOf(targetPath) {
185
+ try {
186
+ return await fs.realpath(targetPath);
187
+ }
188
+ catch (error) {
189
+ if (error.code === 'ENOENT')
190
+ return targetPath;
191
+ throw error;
192
+ }
155
193
  }
156
194
  /**
157
195
  * Whether two entry lists are equivalent.
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Whether an agent's hook file already names the agentwatch hook command.
3
+ *
4
+ * Detection only, never ownership (that is `isAgentWatchHookCommand`): a
5
+ * substring is what `detect` reports as "hooks installed", which status and
6
+ * doctor show and `agentwatch on` reads to decide whether to turn telemetry
7
+ * back on.
8
+ *
9
+ * @param file - The agent's JSON hook or settings file.
10
+ * @param key - Top-level block to search, for a settings file that holds more
11
+ * than hooks; omitted, the whole file is searched.
12
+ * @returns True when the marker appears; false when the file is missing or unreadable.
13
+ */
14
+ export declare function hooksMarkerPresent(file: string, key?: string): Promise<boolean>;
@@ -0,0 +1,23 @@
1
+ import { asRecord } from '../../core/object.js';
2
+ import { readJsonFile } from '../../storage/json-file.js';
3
+ import { HOOK_COMMAND_MARKER } from '../constants/provider.constants.js';
4
+ /**
5
+ * Whether an agent's hook file already names the agentwatch hook command.
6
+ *
7
+ * Detection only, never ownership (that is `isAgentWatchHookCommand`): a
8
+ * substring is what `detect` reports as "hooks installed", which status and
9
+ * doctor show and `agentwatch on` reads to decide whether to turn telemetry
10
+ * back on.
11
+ *
12
+ * @param file - The agent's JSON hook or settings file.
13
+ * @param key - Top-level block to search, for a settings file that holds more
14
+ * than hooks; omitted, the whole file is searched.
15
+ * @returns True when the marker appears; false when the file is missing or unreadable.
16
+ */
17
+ export async function hooksMarkerPresent(file, key) {
18
+ const read = await readJsonFile(file);
19
+ if (read.state !== 'ok')
20
+ return false;
21
+ const scope = key === undefined ? read.value : asRecord(read.value)?.[key];
22
+ return JSON.stringify(scope ?? {}).includes(HOOK_COMMAND_MARKER);
23
+ }
@@ -84,4 +84,33 @@ export declare function withOtelInstall(state: InstallState, agentId: string, re
84
84
  * @returns The next install state.
85
85
  */
86
86
  export declare function withoutOtelInstall(state: InstallState, agentId: string): InstallState;
87
+ /**
88
+ * What owned config keys held before this tool first set them.
89
+ *
90
+ * @param state - Install state.
91
+ * @param agentId - Agent whose record to read.
92
+ * @returns Prior text by key; empty when nothing was recorded.
93
+ */
94
+ export declare function otelPriorValuesOf(state: InstallState, agentId: string): Readonly<Record<string, string>>;
95
+ /**
96
+ * The prior values to record for the keys about to be written.
97
+ *
98
+ * A key already owned keeps what was recorded when it was taken, because its
99
+ * current value is our own. Any other key records what it holds now. Every
100
+ * provider folds this the same way, so ownership never drifts between them.
101
+ *
102
+ * @param keys - Keys about to be written.
103
+ * @param ownedKeys - Keys a previous setup recorded as owned.
104
+ * @param previous - Prior values that setup recorded.
105
+ * @param before - What each key holds now, as recorded text.
106
+ * @returns Prior text by key, for keys that had one.
107
+ */
108
+ export declare function foldPriorValues(keys: readonly string[], ownedKeys: readonly string[], previous: Readonly<Record<string, string>>, before: Readonly<Record<string, string>>): Record<string, string>;
109
+ /**
110
+ * A recorded JSON value, as it was before setup.
111
+ *
112
+ * @param prior - Its JSON text, if one was recorded.
113
+ * @returns The value; undefined (remove the key) when absent or unparseable.
114
+ */
115
+ export declare function parsePriorValue(prior: string | undefined): unknown;
87
116
  export {};
@@ -14,6 +14,13 @@ import { omitKeys } from '../../core/object.js';
14
14
  */
15
15
  export function withHookInstall(state, agentId, record) {
16
16
  const previous = state.agents[agentId];
17
+ // Only a first install sets it: an agent with an earlier hook record (`hookConfigPath` survives an
18
+ // uninstall) but no first-install time was hooked before it was recorded, and inventing one now
19
+ // would let replay resend turns the hooks already sent.
20
+ // ponytail: install state is local, so `uninstall --purge` forgets it and the next setup counts as a
21
+ // first install: Gemini turns the hooks sent before the purge, inside the replay window, are sent
22
+ // again under replay ids. Upgrade path: a purge-surviving tombstone, or a backend "last live Gemini turn".
23
+ const firstInstalledAt = previous?.hookConfigPath === undefined && previous?.hooksFirstInstalledAt === undefined ? record.installedAt.toISOString() : previous?.hooksFirstInstalledAt;
17
24
  return {
18
25
  ...state,
19
26
  agents: {
@@ -21,6 +28,7 @@ export function withHookInstall(state, agentId, record) {
21
28
  [agentId]: {
22
29
  ...previous,
23
30
  hooksInstalledAt: record.installedAt.toISOString(),
31
+ ...(firstInstalledAt === undefined ? {} : { hooksFirstInstalledAt: firstInstalledAt }),
24
32
  hookConfigPath: record.hookConfigPath,
25
33
  hookEvents: [...record.hookEvents],
26
34
  hookCommand: record.hookCommand,
@@ -115,3 +123,47 @@ export function withoutOtelInstall(state, agentId) {
115
123
  }
116
124
  };
117
125
  }
126
+ /**
127
+ * What owned config keys held before this tool first set them.
128
+ *
129
+ * @param state - Install state.
130
+ * @param agentId - Agent whose record to read.
131
+ * @returns Prior text by key; empty when nothing was recorded.
132
+ */
133
+ export function otelPriorValuesOf(state, agentId) {
134
+ return state.agents[agentId]?.otelPriorValues ?? {};
135
+ }
136
+ /**
137
+ * The prior values to record for the keys about to be written.
138
+ *
139
+ * A key already owned keeps what was recorded when it was taken, because its
140
+ * current value is our own. Any other key records what it holds now. Every
141
+ * provider folds this the same way, so ownership never drifts between them.
142
+ *
143
+ * @param keys - Keys about to be written.
144
+ * @param ownedKeys - Keys a previous setup recorded as owned.
145
+ * @param previous - Prior values that setup recorded.
146
+ * @param before - What each key holds now, as recorded text.
147
+ * @returns Prior text by key, for keys that had one.
148
+ */
149
+ export function foldPriorValues(keys, ownedKeys, previous, before) {
150
+ const owned = new Set(ownedKeys);
151
+ return Object.fromEntries(keys.flatMap((key) => {
152
+ const prior = owned.has(key) ? previous[key] : before[key];
153
+ return prior === undefined ? [] : [[key, prior]];
154
+ }));
155
+ }
156
+ /**
157
+ * A recorded JSON value, as it was before setup.
158
+ *
159
+ * @param prior - Its JSON text, if one was recorded.
160
+ * @returns The value; undefined (remove the key) when absent or unparseable.
161
+ */
162
+ export function parsePriorValue(prior) {
163
+ try {
164
+ return prior === undefined ? undefined : JSON.parse(prior);
165
+ }
166
+ catch {
167
+ return undefined;
168
+ }
169
+ }
@@ -0,0 +1,23 @@
1
+ import type * as NodeSqlite from 'node:sqlite';
2
+ import type { SessionTitles } from '../../turns/types/transcript.types.js';
3
+ /**
4
+ * Open one agent-owned read model and return only its title fields: `name` as
5
+ * the custom title, `title` as the generated one.
6
+ *
7
+ * ponytail: the synchronous stdlib query can briefly block one Stop hook; it is
8
+ * one indexed local lookup. Move it to a worker if measured hook latency makes
9
+ * that visible.
10
+ *
11
+ * @param sqlite - The stdlib SQLite module, from `sqliteModule`.
12
+ * @param databasePath - The agent's database, opened read-only.
13
+ * @param query - One-row query taking the session id.
14
+ * @param sessionId - The hook's session id.
15
+ * @returns The titles, or neither on any failure.
16
+ */
17
+ export declare function readTitles(sqlite: typeof NodeSqlite, databasePath: string, query: string, sessionId: string): SessionTitles;
18
+ /**
19
+ * The stdlib SQLite module, where it can open a file read-only.
20
+ *
21
+ * @returns The module, or undefined before Node 22.12, which added enforced read-only opens.
22
+ */
23
+ export declare function sqliteModule(): typeof NodeSqlite | undefined;
@@ -0,0 +1,50 @@
1
+ import { createRequire } from 'node:module';
2
+ import { asRecord, compact } from '../../core/object.js';
3
+ const require = createRequire(import.meta.url);
4
+ /**
5
+ * Open one agent-owned read model and return only its title fields: `name` as
6
+ * the custom title, `title` as the generated one.
7
+ *
8
+ * ponytail: the synchronous stdlib query can briefly block one Stop hook; it is
9
+ * one indexed local lookup. Move it to a worker if measured hook latency makes
10
+ * that visible.
11
+ *
12
+ * @param sqlite - The stdlib SQLite module, from `sqliteModule`.
13
+ * @param databasePath - The agent's database, opened read-only.
14
+ * @param query - One-row query taking the session id.
15
+ * @param sessionId - The hook's session id.
16
+ * @returns The titles, or neither on any failure.
17
+ */
18
+ export function readTitles(sqlite, databasePath, query, sessionId) {
19
+ let database;
20
+ try {
21
+ database = new sqlite.DatabaseSync(databasePath, { readOnly: true });
22
+ const row = asRecord(database.prepare(query).get(sessionId));
23
+ return compact({
24
+ custom: typeof row?.['name'] === 'string' ? row['name'] : undefined,
25
+ generated: typeof row?.['title'] === 'string' ? row['title'] : undefined
26
+ });
27
+ }
28
+ catch {
29
+ return {};
30
+ }
31
+ finally {
32
+ database?.close();
33
+ }
34
+ }
35
+ /**
36
+ * The stdlib SQLite module, where it can open a file read-only.
37
+ *
38
+ * @returns The module, or undefined before Node 22.12, which added enforced read-only opens.
39
+ */
40
+ export function sqliteModule() {
41
+ const [major = 0, minor = 0] = process.versions.node.split('.').map(Number);
42
+ if (major < 22 || (major === 22 && minor < 12))
43
+ return undefined;
44
+ try {
45
+ return require('node:sqlite');
46
+ }
47
+ catch {
48
+ return undefined;
49
+ }
50
+ }
@@ -0,0 +1,41 @@
1
+ import type { Env } from '../../core/types/core.types.js';
2
+ import type { RunCaptureRoute, SetupContext, SetupOutcome } from '../types/provider.types.js';
3
+ /** One app built on VS Code's settings, and the hook operations capture rides on. */
4
+ export interface TerminalCapture {
5
+ readonly route: RunCaptureRoute;
6
+ /** The hook install, with the terminal's environment written after it. */
7
+ install(inner: (context: SetupContext) => Promise<SetupOutcome>): (context: SetupContext) => Promise<SetupOutcome>;
8
+ /** The hook uninstall, with the terminal's environment taken out after it. */
9
+ uninstall(inner: (context: SetupContext) => Promise<SetupOutcome>): (context: SetupContext) => Promise<SetupOutcome>;
10
+ }
11
+ /**
12
+ * The app's user `settings.json`. Not under `~/.cursor` or `~/.gemini`: those hold the
13
+ * agents' own config, this one is the editor's.
14
+ *
15
+ * @param env - Environment supplying HOME, APPDATA and XDG_CONFIG_HOME.
16
+ * @param app - The app's folder name.
17
+ * @returns The absolute path.
18
+ */
19
+ export declare function terminalSettingsPath(env: Env, app: string): string;
20
+ /**
21
+ * The run-capture route of an app whose terminal reads `terminal.integrated.env.*`.
22
+ *
23
+ * Off the app's real terminal until `verified`: what the app's agent runs may not inherit
24
+ * that setting, and a setting that does reach it also reaches every terminal the developer
25
+ * types into, so nothing is written until someone has seen it work (PR "Verification for
26
+ * Cursor and Antigravity"). The removal always runs, so flipping back cleans up.
27
+ *
28
+ * ponytail: VS Code settings are JSONC and `readJsonFile` is strict, so a file with
29
+ * comments is refused rather than rewritten. One that holds our keys cannot be cleaned
30
+ * either: uninstall says so, and the shared copy stays while the file names it. The upgrade
31
+ * is a JSONC-aware edit.
32
+ *
33
+ * @param app - The app's folder name under the settings root.
34
+ * @param verified - Whether the route was seen working on the installed app.
35
+ * @param source - The package's shims.
36
+ * @returns The route and the wrappers for the provider's hook operations.
37
+ */
38
+ export declare function terminalCapture(app: string, verified: boolean, source?: {
39
+ node: string;
40
+ python: string;
41
+ }): TerminalCapture;
@@ -0,0 +1,109 @@
1
+ import fs from 'node:fs/promises';
2
+ import { existsSync } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { copiedShims, inspectCaptureEnv, installedCaptureEnv, removeCaptureCopy, shimPaths, skippedOnError, withCaptureOutcome, withoutCaptureEnv } from '../../capture/capture-env.js';
5
+ import { otelEnabled } from '../../config/config.js';
6
+ import { asRecord, omitKeys } from '../../core/object.js';
7
+ import { backupFile } from '../../storage/atomic-file.js';
8
+ import { readJsonFile } from '../../storage/json-file.js';
9
+ import { NO_TERMINAL_ROUTE, TERMINAL_ENV_PLATFORMS, TERMINAL_ENV_PREFIX } from './constants/terminal-capture.constants.js';
10
+ import { editorConfigRoot } from './editor-paths.js';
11
+ import { writeJsonValidated } from './hook-config.js';
12
+ /**
13
+ * The app's user `settings.json`. Not under `~/.cursor` or `~/.gemini`: those hold the
14
+ * agents' own config, this one is the editor's.
15
+ *
16
+ * @param env - Environment supplying HOME, APPDATA and XDG_CONFIG_HOME.
17
+ * @param app - The app's folder name.
18
+ * @returns The absolute path.
19
+ */
20
+ export function terminalSettingsPath(env, app) {
21
+ return path.join(editorConfigRoot(env), app, 'User', 'settings.json');
22
+ }
23
+ /** VS Code's per-platform key for the integrated terminal's environment. */
24
+ function terminalEnvKey(env) {
25
+ return `${TERMINAL_ENV_PREFIX}${TERMINAL_ENV_PLATFORMS[env.platform] ?? 'linux'}`;
26
+ }
27
+ function withBlock(settings, key, block) {
28
+ return Object.keys(block).length > 0 ? { ...settings, [key]: block } : omitKeys(settings, new Set([key]));
29
+ }
30
+ /**
31
+ * The run-capture route of an app whose terminal reads `terminal.integrated.env.*`.
32
+ *
33
+ * Off the app's real terminal until `verified`: what the app's agent runs may not inherit
34
+ * that setting, and a setting that does reach it also reaches every terminal the developer
35
+ * types into, so nothing is written until someone has seen it work (PR "Verification for
36
+ * Cursor and Antigravity"). The removal always runs, so flipping back cleans up.
37
+ *
38
+ * ponytail: VS Code settings are JSONC and `readJsonFile` is strict, so a file with
39
+ * comments is refused rather than rewritten. One that holds our keys cannot be cleaned
40
+ * either: uninstall says so, and the shared copy stays while the file names it. The upgrade
41
+ * is a JSONC-aware edit.
42
+ *
43
+ * @param app - The app's folder name under the settings root.
44
+ * @param verified - Whether the route was seen working on the installed app.
45
+ * @param source - The package's shims.
46
+ * @returns The route and the wrappers for the provider's hook operations.
47
+ */
48
+ export function terminalCapture(app, verified, source = shimPaths()) {
49
+ async function apply(context) {
50
+ const file = terminalSettingsPath(context.env, app);
51
+ const read = await readJsonFile(file);
52
+ const settings = read.state === 'ok' ? asRecord(read.value) : undefined;
53
+ if (read.state === 'invalid' || (read.state === 'ok' && !settings))
54
+ return { ok: true, changed: false, messages: [`run capture skipped: ${file} is not plain JSON`] };
55
+ // No User folder: the app itself is not here (only its CLI), so nothing reads this file.
56
+ if (read.state === 'missing' && !existsSync(path.dirname(file)))
57
+ return { ok: true, changed: false, messages: [] };
58
+ const current = settings ?? {};
59
+ const key = terminalEnvKey(context.env);
60
+ const block = asRecord(current[key]) ?? {};
61
+ const next = await installedCaptureEnv(block, context.env.vars, context.paths.dataDir, source);
62
+ if (JSON.stringify(next) === JSON.stringify(block))
63
+ return { ok: true, changed: false, messages: [] };
64
+ await backupFile(file, context.paths.backupsDir, context.env.now());
65
+ await writeJsonValidated(file, withBlock(current, key, next));
66
+ return { ok: true, changed: true, messages: [`run capture configured; restart ${app} to pick it up`] };
67
+ }
68
+ async function remove(context) {
69
+ const file = terminalSettingsPath(context.env, app);
70
+ const read = await readJsonFile(file);
71
+ const shims = copiedShims(context.paths.dataDir);
72
+ if (read.state === 'invalid') {
73
+ const raw = await fs.readFile(file, 'utf8').catch(() => '');
74
+ if (raw.includes(shims.node) || raw.includes(shims.python))
75
+ return { ok: false, changed: false, messages: [`run capture: ${file} is not plain JSON; take NODE_OPTIONS and PYTHONPATH out of ${terminalEnvKey(context.env)} by hand`] };
76
+ }
77
+ const settings = read.state === 'ok' ? asRecord(read.value) : undefined;
78
+ const key = terminalEnvKey(context.env);
79
+ const block = asRecord(settings?.[key]);
80
+ const next = block && withoutCaptureEnv(block, shims);
81
+ const changed = settings !== undefined && block !== undefined && JSON.stringify(next) !== JSON.stringify(block);
82
+ if (changed) {
83
+ await backupFile(file, context.paths.backupsDir, context.env.now());
84
+ await writeJsonValidated(file, withBlock(settings, key, next));
85
+ }
86
+ await removeCaptureCopy(context.paths.dataDir, context.env);
87
+ return { ok: true, changed, messages: changed ? ['run capture configuration removed'] : [] };
88
+ }
89
+ return {
90
+ route: {
91
+ configPath: (env) => terminalSettingsPath(env, app),
92
+ inspect: async (context) => {
93
+ if (!verified)
94
+ return { on: false, reason: NO_TERMINAL_ROUTE };
95
+ const file = terminalSettingsPath(context.env, app);
96
+ const read = await readJsonFile(file);
97
+ if (read.state === 'invalid')
98
+ return { on: false, reason: `${file} is not plain JSON, so Edge cannot edit it` };
99
+ const block = asRecord(asRecord(read.state === 'ok' ? read.value : undefined)?.[terminalEnvKey(context.env)]) ?? {};
100
+ return inspectCaptureEnv(block, context.config, otelEnabled(context.config), context.paths.dataDir, source);
101
+ }
102
+ },
103
+ install: (inner) => async (context) => {
104
+ const outcome = await inner(context);
105
+ return withCaptureOutcome(outcome, await (verified && otelEnabled(context.config) ? skippedOnError(apply(context)) : remove(context)));
106
+ },
107
+ uninstall: (inner) => async (context) => withCaptureOutcome(await inner(context), await remove(context))
108
+ };
109
+ }
@@ -91,6 +91,27 @@ export declare function extractFilePath(toolInput: unknown): string | undefined;
91
91
  * @returns The command, or undefined when the input names none.
92
92
  */
93
93
  export declare function extractCommand(toolInput: unknown): string | undefined;
94
+ /**
95
+ * The skill a skill call invoked, its name and nothing else.
96
+ *
97
+ * Read in memory from the call's input; its arguments are never looked at.
98
+ * A name core would refuse is dropped here, never the call it rides on.
99
+ *
100
+ * @param input - The skill tool's input as the agent passed it.
101
+ * @param key - The input field naming the skill.
102
+ * @returns The trimmed name, or undefined when there is no valid one.
103
+ */
104
+ export declare function skillName(input: unknown, key: string): string | undefined;
105
+ /**
106
+ * The slash command a prompt starts with, without its slash or arguments.
107
+ *
108
+ * Only the matched token survives: nothing after it, and nothing at all from
109
+ * a prompt that does not open with one.
110
+ *
111
+ * @param prompt - The prompt as the agent reported it.
112
+ * @returns The command name, or undefined.
113
+ */
114
+ export declare function slashCommandName(prompt: string | undefined): string | undefined;
94
115
  /**
95
116
  * A shell call out of untrusted payload fields, type-checked.
96
117
  *