@agent-watch-ai/edge 0.2.5 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (348) hide show
  1. package/CHANGELOG.md +558 -0
  2. package/README.md +222 -97
  3. package/SECURITY.md +72 -0
  4. package/dist/billing/session-billing.d.ts +19 -0
  5. package/dist/billing/session-billing.js +52 -0
  6. package/dist/cli/args.d.ts +10 -0
  7. package/dist/cli/args.js +20 -0
  8. package/dist/cli/constants/cli.constants.d.ts +52 -4
  9. package/dist/cli/constants/cli.constants.js +56 -5
  10. package/dist/cli/context.d.ts +33 -2
  11. package/dist/cli/context.js +84 -14
  12. package/dist/cli/doctor.js +321 -33
  13. package/dist/cli/hook-check.d.ts +23 -0
  14. package/dist/cli/hook-check.js +114 -0
  15. package/dist/cli/hook.js +118 -7
  16. package/dist/cli/index.d.ts +3 -1
  17. package/dist/cli/index.js +3 -1
  18. package/dist/cli/misc.d.ts +11 -0
  19. package/dist/cli/misc.js +80 -4
  20. package/dist/cli/npx-install.d.ts +37 -0
  21. package/dist/cli/npx-install.js +79 -0
  22. package/dist/cli/open-browser.d.ts +39 -0
  23. package/dist/cli/open-browser.js +62 -0
  24. package/dist/cli/setup.d.ts +17 -8
  25. package/dist/cli/setup.js +553 -103
  26. package/dist/cli/status.js +82 -13
  27. package/dist/cli/toggle.d.ts +9 -0
  28. package/dist/cli/toggle.js +117 -0
  29. package/dist/cli/types/cli.types.d.ts +43 -3
  30. package/dist/cli/ui.d.ts +7 -0
  31. package/dist/cli/ui.js +10 -1
  32. package/dist/cli/uninstall.js +39 -2
  33. package/dist/cli/update.d.ts +17 -0
  34. package/dist/cli/update.js +76 -0
  35. package/dist/cli.js +110 -12
  36. package/dist/config/config-store.d.ts +57 -0
  37. package/dist/config/config-store.js +250 -12
  38. package/dist/config/config.d.ts +53 -6
  39. package/dist/config/config.js +66 -6
  40. package/dist/config/constants/config.constants.d.ts +116 -6
  41. package/dist/config/constants/config.constants.js +131 -8
  42. package/dist/config/destination.d.ts +24 -0
  43. package/dist/config/destination.js +33 -0
  44. package/dist/config/index.d.ts +7 -4
  45. package/dist/config/index.js +5 -3
  46. package/dist/config/repo-config.d.ts +11 -7
  47. package/dist/config/repo-config.js +64 -15
  48. package/dist/config/root-config.d.ts +72 -0
  49. package/dist/config/root-config.js +170 -0
  50. package/dist/config/schemas/config.schema.d.ts +831 -84
  51. package/dist/config/schemas/config.schema.js +398 -16
  52. package/dist/config/types/config.types.d.ts +15 -1
  53. package/dist/config/types/destination.types.d.ts +8 -0
  54. package/dist/core/async.d.ts +36 -0
  55. package/dist/core/async.js +68 -0
  56. package/dist/core/index.d.ts +1 -1
  57. package/dist/core/index.js +1 -1
  58. package/dist/core/object.d.ts +5 -0
  59. package/dist/core/object.js +9 -4
  60. package/dist/core/pipe.d.ts +0 -13
  61. package/dist/core/pipe.js +1 -9
  62. package/dist/core/types/core.types.d.ts +9 -0
  63. package/dist/core/types/core.types.js +0 -3
  64. package/dist/core/which.d.ts +14 -0
  65. package/dist/core/which.js +43 -3
  66. package/dist/credentials/budget.d.ts +9 -0
  67. package/dist/credentials/budget.js +16 -0
  68. package/dist/credentials/command-runner.d.ts +16 -0
  69. package/dist/credentials/command-runner.js +37 -0
  70. package/dist/credentials/constants/credentials.constants.d.ts +119 -0
  71. package/dist/credentials/constants/credentials.constants.js +120 -0
  72. package/dist/credentials/credential-status.d.ts +14 -0
  73. package/dist/credentials/credential-status.js +38 -0
  74. package/dist/credentials/credentials.d.ts +86 -0
  75. package/dist/credentials/credentials.js +278 -0
  76. package/dist/credentials/device-api.d.ts +73 -0
  77. package/dist/credentials/device-api.js +161 -0
  78. package/dist/credentials/device-state.d.ts +31 -0
  79. package/dist/credentials/device-state.js +51 -0
  80. package/dist/credentials/identity.d.ts +73 -0
  81. package/dist/credentials/identity.js +101 -0
  82. package/dist/credentials/index.d.ts +7 -0
  83. package/dist/credentials/index.js +5 -0
  84. package/dist/credentials/migration.d.ts +46 -0
  85. package/dist/credentials/migration.js +164 -0
  86. package/dist/credentials/schemas/device-api.schema.d.ts +77 -0
  87. package/dist/credentials/schemas/device-api.schema.js +33 -0
  88. package/dist/credentials/schemas/device-state.schema.d.ts +51 -0
  89. package/dist/credentials/schemas/device-state.schema.js +20 -0
  90. package/dist/credentials/secret-store.d.ts +54 -0
  91. package/dist/credentials/secret-store.js +217 -0
  92. package/dist/credentials/sign-in.d.ts +31 -0
  93. package/dist/credentials/sign-in.js +105 -0
  94. package/dist/credentials/token-refresher.d.ts +39 -0
  95. package/dist/credentials/token-refresher.js +185 -0
  96. package/dist/credentials/types/credentials.types.d.ts +206 -0
  97. package/dist/credentials/types/credentials.types.js +1 -0
  98. package/dist/enforcement/constants/enforcement.constants.d.ts +47 -1
  99. package/dist/enforcement/constants/enforcement.constants.js +56 -0
  100. package/dist/enforcement/decision-cache.d.ts +20 -1
  101. package/dist/enforcement/decision-cache.js +65 -2
  102. package/dist/enforcement/decision-client.d.ts +9 -8
  103. package/dist/enforcement/decision-client.js +64 -17
  104. package/dist/enforcement/enforcement.d.ts +23 -2
  105. package/dist/enforcement/enforcement.js +107 -17
  106. package/dist/enforcement/index.d.ts +4 -3
  107. package/dist/enforcement/index.js +3 -2
  108. package/dist/enforcement/types/enforcement.types.d.ts +66 -2
  109. package/dist/enrollment/constants/enrollment.constants.d.ts +2 -6
  110. package/dist/enrollment/constants/enrollment.constants.js +2 -6
  111. package/dist/enrollment/enrollment.d.ts +16 -0
  112. package/dist/enrollment/enrollment.js +54 -0
  113. package/dist/enrollment/index.d.ts +3 -7
  114. package/dist/enrollment/index.js +1 -1
  115. package/dist/enrollment/types/enrollment.types.d.ts +9 -13
  116. package/dist/events/constants/enrich.constants.d.ts +15 -0
  117. package/dist/events/constants/enrich.constants.js +15 -0
  118. package/dist/events/constants/events.constants.d.ts +6 -2
  119. package/dist/events/constants/events.constants.js +5 -1
  120. package/dist/events/enrich.js +92 -10
  121. package/dist/events/event-id.d.ts +0 -8
  122. package/dist/events/event-id.js +0 -10
  123. package/dist/events/index.d.ts +2 -2
  124. package/dist/events/index.js +1 -1
  125. package/dist/events/product-event.d.ts +9 -6
  126. package/dist/events/types/repo-snapshot.types.d.ts +7 -0
  127. package/dist/events/types/session-billing.types.d.ts +16 -0
  128. package/dist/events/types/session-billing.types.js +1 -0
  129. package/dist/feature/constants/feature.constants.d.ts +7 -0
  130. package/dist/feature/constants/feature.constants.js +7 -0
  131. package/dist/feature/index.d.ts +1 -1
  132. package/dist/feature/index.js +1 -1
  133. package/dist/feature/ticket-candidates.d.ts +14 -0
  134. package/dist/feature/ticket-candidates.js +26 -8
  135. package/dist/git/blob-hash.d.ts +21 -0
  136. package/dist/git/blob-hash.js +69 -0
  137. package/dist/git/checkout-root.d.ts +27 -0
  138. package/dist/git/checkout-root.js +75 -0
  139. package/dist/git/constants/git.constants.d.ts +160 -0
  140. package/dist/git/constants/git.constants.js +181 -0
  141. package/dist/git/fingerprint.d.ts +74 -0
  142. package/dist/git/fingerprint.js +219 -0
  143. package/dist/git/gate-checkout.d.ts +44 -0
  144. package/dist/git/gate-checkout.js +201 -0
  145. package/dist/git/git-context.d.ts +45 -0
  146. package/dist/git/git-context.js +61 -3
  147. package/dist/git/index.d.ts +4 -2
  148. package/dist/git/index.js +2 -1
  149. package/dist/git/manifest-repository.d.ts +13 -0
  150. package/dist/git/manifest-repository.js +92 -0
  151. package/dist/git/repo-snapshot.d.ts +29 -3
  152. package/dist/git/repo-snapshot.js +110 -7
  153. package/dist/git/repository-root.d.ts +39 -0
  154. package/dist/git/repository-root.js +131 -0
  155. package/dist/git/types/git.types.d.ts +55 -0
  156. package/dist/git/types/repository-root.types.d.ts +11 -0
  157. package/dist/git/types/repository-root.types.js +1 -0
  158. package/dist/git/types/snapshot.types.d.ts +9 -0
  159. package/dist/pipeline/constants/pipeline.constants.d.ts +10 -0
  160. package/dist/pipeline/constants/pipeline.constants.js +10 -0
  161. package/dist/pipeline/hook-pipeline.js +410 -33
  162. package/dist/pipeline/types/pipeline.types.d.ts +39 -4
  163. package/dist/privacy/constants/privacy.constants.js +15 -1
  164. package/dist/privacy/index.d.ts +1 -0
  165. package/dist/privacy/index.js +1 -0
  166. package/dist/privacy/product-capture.d.ts +12 -0
  167. package/dist/privacy/product-capture.js +75 -0
  168. package/dist/privacy/sanitizer.d.ts +21 -3
  169. package/dist/privacy/sanitizer.js +52 -8
  170. package/dist/process/ancestors.d.ts +39 -0
  171. package/dist/process/ancestors.js +121 -0
  172. package/dist/process/constants/process.constants.d.ts +34 -0
  173. package/dist/process/constants/process.constants.js +34 -0
  174. package/dist/process/index.d.ts +7 -0
  175. package/dist/process/index.js +2 -0
  176. package/dist/process/types/process.types.d.ts +23 -0
  177. package/dist/process/types/process.types.js +1 -0
  178. package/dist/providers/antigravity/antigravity.adapter.d.ts +12 -1
  179. package/dist/providers/antigravity/antigravity.adapter.js +21 -3
  180. package/dist/providers/antigravity/antigravity.detect.d.ts +0 -9
  181. package/dist/providers/antigravity/antigravity.detect.js +1 -1
  182. package/dist/providers/antigravity/antigravity.provider.js +3 -2
  183. package/dist/providers/antigravity/constants/antigravity.constants.d.ts +2 -0
  184. package/dist/providers/antigravity/constants/antigravity.constants.js +2 -0
  185. package/dist/providers/claude/claude.adapter.d.ts +11 -1
  186. package/dist/providers/claude/claude.adapter.js +26 -5
  187. package/dist/providers/claude/claude.otel.d.ts +32 -18
  188. package/dist/providers/claude/claude.otel.js +81 -6
  189. package/dist/providers/claude/claude.provider.js +5 -2
  190. package/dist/providers/claude/constants/claude.constants.d.ts +2 -0
  191. package/dist/providers/claude/constants/claude.constants.js +2 -0
  192. package/dist/providers/claude/constants/claude.otel.constants.d.ts +4 -0
  193. package/dist/providers/claude/constants/claude.otel.constants.js +8 -0
  194. package/dist/providers/codex/codex.adapter.d.ts +15 -1
  195. package/dist/providers/codex/codex.adapter.js +29 -5
  196. package/dist/providers/codex/codex.otel.d.ts +36 -3
  197. package/dist/providers/codex/codex.otel.js +199 -32
  198. package/dist/providers/codex/codex.provider.js +5 -2
  199. package/dist/providers/codex/constants/codex.constants.d.ts +2 -0
  200. package/dist/providers/codex/constants/codex.constants.js +16 -0
  201. package/dist/providers/codex/constants/codex.otel.constants.d.ts +10 -0
  202. package/dist/providers/codex/constants/codex.otel.constants.js +10 -0
  203. package/dist/providers/constants/provider.constants.d.ts +8 -3
  204. package/dist/providers/constants/provider.constants.js +8 -3
  205. package/dist/providers/cursor/constants/cursor.constants.d.ts +9 -0
  206. package/dist/providers/cursor/constants/cursor.constants.js +9 -0
  207. package/dist/providers/cursor/cursor.adapter.d.ts +33 -1
  208. package/dist/providers/cursor/cursor.adapter.js +129 -4
  209. package/dist/providers/cursor/cursor.detect.d.ts +0 -7
  210. package/dist/providers/cursor/cursor.detect.js +1 -1
  211. package/dist/providers/cursor/cursor.provider.js +5 -2
  212. package/dist/providers/gemini/constants/gemini.constants.d.ts +9 -0
  213. package/dist/providers/gemini/constants/gemini.constants.js +9 -0
  214. package/dist/providers/gemini/constants/gemini.otel.constants.d.ts +9 -1
  215. package/dist/providers/gemini/constants/gemini.otel.constants.js +9 -0
  216. package/dist/providers/gemini/gemini.adapter.d.ts +14 -1
  217. package/dist/providers/gemini/gemini.adapter.js +25 -5
  218. package/dist/providers/gemini/gemini.detect.d.ts +0 -7
  219. package/dist/providers/gemini/gemini.detect.js +1 -1
  220. package/dist/providers/gemini/gemini.otel.d.ts +30 -21
  221. package/dist/providers/gemini/gemini.otel.js +166 -22
  222. package/dist/providers/gemini/gemini.provider.js +2 -1
  223. package/dist/providers/index.d.ts +1 -1
  224. package/dist/providers/index.js +1 -1
  225. package/dist/providers/loaders.d.ts +10 -0
  226. package/dist/providers/loaders.js +40 -0
  227. package/dist/providers/provider.d.ts +11 -0
  228. package/dist/providers/provider.js +1 -1
  229. package/dist/providers/registry.d.ts +11 -8
  230. package/dist/providers/registry.js +11 -15
  231. package/dist/providers/shared/bearer-rewrite.d.ts +19 -0
  232. package/dist/providers/shared/bearer-rewrite.js +46 -0
  233. package/dist/providers/shared/constants/hook-refusal.constants.d.ts +7 -0
  234. package/dist/providers/shared/constants/hook-refusal.constants.js +7 -0
  235. package/dist/providers/shared/constants/shell-directories.constants.d.ts +30 -0
  236. package/dist/providers/shared/constants/shell-directories.constants.js +39 -0
  237. package/dist/providers/shared/constants/tooling.constants.d.ts +24 -2
  238. package/dist/providers/shared/constants/tooling.constants.js +25 -3
  239. package/dist/providers/shared/event-builder.d.ts +12 -14
  240. package/dist/providers/shared/event-builder.js +20 -14
  241. package/dist/providers/shared/exporter-allowlist.d.ts +20 -0
  242. package/dist/providers/shared/exporter-allowlist.js +49 -0
  243. package/dist/providers/shared/hook-config.d.ts +2 -21
  244. package/dist/providers/shared/hook-config.js +5 -4
  245. package/dist/providers/shared/hook-refusal.d.ts +12 -0
  246. package/dist/providers/shared/hook-refusal.js +17 -1
  247. package/dist/providers/shared/install-record.d.ts +12 -2
  248. package/dist/providers/shared/install-record.js +5 -2
  249. package/dist/providers/shared/shell-directories.d.ts +24 -0
  250. package/dist/providers/shared/shell-directories.js +90 -0
  251. package/dist/providers/shared/tooling.d.ts +40 -1
  252. package/dist/providers/shared/tooling.js +70 -1
  253. package/dist/providers/shared/types/adapter.types.d.ts +1 -2
  254. package/dist/providers/types/provider.types.d.ts +81 -1
  255. package/dist/snapshot/constants/snapshot.constants.d.ts +32 -0
  256. package/dist/snapshot/constants/snapshot.constants.js +33 -0
  257. package/dist/snapshot/snapshot-event.js +52 -11
  258. package/dist/snapshot/snapshot-pipeline.js +1 -1
  259. package/dist/snapshot/types/snapshot.types.d.ts +2 -0
  260. package/dist/storage/atomic-file.d.ts +21 -0
  261. package/dist/storage/atomic-file.js +20 -1
  262. package/dist/storage/constants/storage.constants.d.ts +19 -0
  263. package/dist/storage/constants/storage.constants.js +19 -0
  264. package/dist/storage/disabled.d.ts +13 -0
  265. package/dist/storage/disabled.js +24 -0
  266. package/dist/storage/index.d.ts +2 -0
  267. package/dist/storage/index.js +2 -0
  268. package/dist/storage/paths.js +3 -2
  269. package/dist/storage/schemas/storage.schema.d.ts +72 -0
  270. package/dist/storage/schemas/storage.schema.js +6 -0
  271. package/dist/storage/sweep-marker.d.ts +19 -0
  272. package/dist/storage/sweep-marker.js +55 -0
  273. package/dist/storage/types/storage.types.d.ts +2 -0
  274. package/dist/storage/uninstalled.d.ts +58 -0
  275. package/dist/storage/uninstalled.js +107 -0
  276. package/dist/transport/auth-block.d.ts +66 -0
  277. package/dist/transport/auth-block.js +129 -0
  278. package/dist/transport/constants/transport.constants.d.ts +82 -3
  279. package/dist/transport/constants/transport.constants.js +83 -4
  280. package/dist/transport/cooldown.js +8 -1
  281. package/dist/transport/delivery.d.ts +14 -6
  282. package/dist/transport/delivery.js +80 -55
  283. package/dist/transport/http-transport.d.ts +1 -0
  284. package/dist/transport/http-transport.js +52 -10
  285. package/dist/transport/index.d.ts +6 -3
  286. package/dist/transport/index.js +3 -0
  287. package/dist/transport/queue-partition.d.ts +91 -0
  288. package/dist/transport/queue-partition.js +143 -0
  289. package/dist/transport/queue.d.ts +99 -20
  290. package/dist/transport/queue.js +210 -69
  291. package/dist/transport/response-body.d.ts +25 -0
  292. package/dist/transport/response-body.js +64 -0
  293. package/dist/transport/send.d.ts +11 -0
  294. package/dist/transport/send.js +17 -0
  295. package/dist/transport/types/delivery-flow.types.d.ts +19 -0
  296. package/dist/transport/types/delivery-flow.types.js +1 -0
  297. package/dist/transport/types/transport.types.d.ts +45 -0
  298. package/dist/turns/claude-transcript.d.ts +19 -1
  299. package/dist/turns/claude-transcript.js +46 -1
  300. package/dist/turns/codex-originator.d.ts +11 -0
  301. package/dist/turns/codex-originator.js +31 -0
  302. package/dist/turns/codex-transcript.d.ts +30 -0
  303. package/dist/turns/codex-transcript.js +88 -0
  304. package/dist/turns/constants/turns.constants.d.ts +141 -5
  305. package/dist/turns/constants/turns.constants.js +155 -5
  306. package/dist/turns/file-identity.d.ts +27 -0
  307. package/dist/turns/file-identity.js +48 -0
  308. package/dist/turns/gemini-transcript.d.ts +30 -0
  309. package/dist/turns/gemini-transcript.js +96 -0
  310. package/dist/turns/index.d.ts +3 -3
  311. package/dist/turns/index.js +1 -1
  312. package/dist/turns/inherited-checkout.d.ts +54 -0
  313. package/dist/turns/inherited-checkout.js +155 -0
  314. package/dist/turns/native-session-titles.d.ts +26 -0
  315. package/dist/turns/native-session-titles.js +102 -0
  316. package/dist/turns/transcript.d.ts +3 -2
  317. package/dist/turns/transcript.js +5 -1
  318. package/dist/turns/turn-state.d.ts +224 -3
  319. package/dist/turns/turn-state.js +456 -21
  320. package/dist/turns/turn-summary.d.ts +1 -14
  321. package/dist/turns/turn-summary.js +87 -51
  322. package/dist/turns/turn-tracker.d.ts +21 -2
  323. package/dist/turns/turn-tracker.js +379 -56
  324. package/dist/turns/types/transcript.types.d.ts +5 -0
  325. package/dist/turns/types/turn-state.types.d.ts +116 -5
  326. package/dist/turns/types/turn-summary.types.d.ts +64 -14
  327. package/dist/turns/types/turn-tracker.types.d.ts +27 -1
  328. package/dist/turns/work-checkout.d.ts +67 -0
  329. package/dist/turns/work-checkout.js +700 -0
  330. package/dist/untraced/constants/untraced.constants.d.ts +31 -0
  331. package/dist/untraced/constants/untraced.constants.js +63 -0
  332. package/dist/untraced/untraced.d.ts +35 -0
  333. package/dist/untraced/untraced.js +105 -0
  334. package/dist/update/constants/update.constants.d.ts +18 -0
  335. package/dist/update/constants/update.constants.js +20 -0
  336. package/dist/update/update-check.d.ts +52 -0
  337. package/dist/update/update-check.js +113 -0
  338. package/docs/AUDIT_PROMPT.md +129 -0
  339. package/docs/DATA_HANDLING.md +655 -0
  340. package/docs/ENTERPRISE_DEPLOYMENT.md +194 -0
  341. package/docs/PERFORMANCE.md +81 -0
  342. package/package.json +14 -4
  343. package/dist/enrollment/enrollment-provider.d.ts +0 -5
  344. package/dist/enrollment/manual-enrollment.d.ts +0 -32
  345. package/dist/enrollment/manual-enrollment.js +0 -72
  346. package/example/README.md +0 -43
  347. package/example/server.mjs +0 -240
  348. /package/dist/{enrollment/enrollment-provider.js → config/types/destination.types.js} +0 -0
@@ -1,6 +1,8 @@
1
- import type { AgentWatchConfig } from '../../config/types/config.types.js';
1
+ import type { AgentWatchConfig, CaptureConfig, ConfigLoadResult } from '../../config/types/config.types.js';
2
2
  import type { Env } from '../../core/types/core.types.js';
3
+ import type { FailOpenReason } from '../../enforcement/types/enforcement.types.js';
3
4
  import type { AgentWatchEvent } from '../../events/types/events.types.js';
5
+ import type { ProductEvent } from '../../events/product-event.js';
4
6
  import type { AgentProvider } from '../../providers/types/provider.types.js';
5
7
  import type { AgentWatchPaths } from '../../storage/types/storage.types.js';
6
8
  import type { TurnSummaryEvent } from '../../turns/types/turn-summary.types.js';
@@ -10,8 +12,15 @@ export interface HookPipelineInput {
10
12
  readonly provider: AgentProvider;
11
13
  readonly env: Env;
12
14
  readonly paths: AgentWatchPaths;
13
- /** The machine-global configuration, before the repository overlay. */
14
- readonly globalConfig: AgentWatchConfig;
15
+ /**
16
+ * The machine-global configuration as loaded, before the repository overlay.
17
+ *
18
+ * The load *result*, not just the config: the repository overlay is refused
19
+ * outright when the global file is missing or corrupt, so the stage that
20
+ * applies it needs to know which — and carrying it here is what keeps the
21
+ * hook path down to one read of the file.
22
+ */
23
+ readonly globalConfig: ConfigLoadResult;
15
24
  /** Decoded hook payload. */
16
25
  readonly payload: unknown;
17
26
  /** Preview only: append nothing, consume nothing, send nothing. */
@@ -28,6 +37,8 @@ export interface HookPipelineState extends HookPipelineInput {
28
37
  readonly cwd: string;
29
38
  /** Global config with the repository overlay applied. */
30
39
  readonly config: AgentWatchConfig;
40
+ /** The uninstall-marker scope of `config`'s credential; absent for the machine's. */
41
+ readonly credentialScope?: string;
31
42
  /** Canonical events the provider adapter produced. */
32
43
  readonly events: readonly AgentWatchEvent[];
33
44
  /**
@@ -39,10 +50,34 @@ export interface HookPipelineState extends HookPipelineInput {
39
50
  * a refusal without a message — so its presence *is* the refusal.
40
51
  */
41
52
  readonly blockMessage?: string;
53
+ /**
54
+ * A line for the developer: after a shell run that called an LLM with no
55
+ * tracing (AWT-310, the `untraced` stage), or at session start when a newer
56
+ * release exists (the `update` stage). Never sent anywhere.
57
+ */
58
+ readonly notice?: string;
59
+ /**
60
+ * Why the turn was allowed without a decision, when it was. Set only by the
61
+ * `enforce` stage; carried onto the prompt record so the turn's summary can
62
+ * say it ran unchecked.
63
+ */
64
+ readonly failOpenReason?: FailOpenReason;
65
+ /**
66
+ * The real roots of the checkouts this payload's shell command names. Roots
67
+ * only: the command and the directories in it never leave the `nominate`
68
+ * stage.
69
+ */
70
+ readonly nominations?: readonly string[];
71
+ /** The real roots of the folders the agent has open, when it reports them (Cursor). Roots only. */
72
+ readonly workspaceRoots?: readonly string[];
73
+ /** Local root of the checkout the closed turn reported; where its snapshot is taken. Never sent. */
74
+ readonly workRoot?: string;
75
+ /** That checkout's own capture policy, re-applied to the summary and asked by the snapshot. */
76
+ readonly workCapture?: CaptureConfig;
42
77
  /** The turn summary, when this payload closed a turn. */
43
78
  readonly summary?: TurnSummaryEvent;
44
79
  /** Records this run intends to send; empty on a dry run. */
45
- readonly outbound: readonly TurnSummaryEvent[];
80
+ readonly outbound: readonly ProductEvent[];
46
81
  /** What delivery did, when it ran. */
47
82
  readonly delivery?: DeliveryOutcome;
48
83
  }
@@ -21,7 +21,21 @@ export const SENSITIVE_KEY_PATTERN = /(^|[_.-])(authorization|auth|token|secret|
21
21
  */
22
22
  export const SECRET_PATTERNS = [
23
23
  { name: 'private-key-block', pattern: /-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)/g },
24
- { name: 'url-credentials', pattern: /(\w+:\/\/)([^/\s:@]+)(?::([^/\s@]+))?@/g, replacement: `$1${REDACTED}@` },
24
+ // The scheme is the only part that was quadratic: `\w+` re-consumed the rest of
25
+ // the string at every start index before backtracking to look for `://`, which
26
+ // cost 1.8s on a 64KiB prompt and 17s on a 200_000-character one, on the
27
+ // agent's hook path. `\w{1,32}` ends that, and no real scheme comes near 32 —
28
+ // `\w` never matched `mongodb+srv` in the first place. That bound is what makes
29
+ // scrubbing the *whole* string affordable, which `sanitizeText` needs in order
30
+ // to redact a credential straddling the length cap.
31
+ //
32
+ // The userinfo groups stay unbounded on purpose. A negated class that cannot
33
+ // cross `@` or whitespace cannot backtrack the same way — measured linear, 21ms
34
+ // on a 200_000-character run with no `@` in it — while a ceiling there leaks
35
+ // every credential longer than it: a 300-character URL password went out in the
36
+ // clear under a `{1,256}` bound, and a signed URL, a service-account secret or
37
+ // a JWT used as a password is routinely longer than that.
38
+ { name: 'url-credentials', pattern: /(\w{1,32}:\/\/)([^/\s:@]+)(?::([^/\s@]+))?@/g, replacement: `$1${REDACTED}@` },
25
39
  { name: 'aws-access-key', pattern: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g },
26
40
  { name: 'github-token', pattern: /\b(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{20,}\b/g },
27
41
  { name: 'github-fine-grained', pattern: /\bgithub_pat_[A-Za-z0-9_]{20,}\b/g },
@@ -5,3 +5,4 @@
5
5
  export type { SecretPattern } from './types/privacy.types.js';
6
6
  export { REDACTED, SECRET_PATTERNS, SENSITIVE_KEY_PATTERN } from './constants/privacy.constants.js';
7
7
  export { sanitizeText, sanitizeValue } from './sanitizer.js';
8
+ export { applyProductCapture } from './product-capture.js';
@@ -1,2 +1,3 @@
1
1
  export { REDACTED, SECRET_PATTERNS, SENSITIVE_KEY_PATTERN } from './constants/privacy.constants.js';
2
2
  export { sanitizeText, sanitizeValue } from './sanitizer.js';
3
+ export { applyProductCapture } from './product-capture.js';
@@ -0,0 +1,12 @@
1
+ import type { CaptureConfig } from '../config/types/config.types.js';
2
+ import type { ProductEvent } from '../events/product-event.js';
3
+ /**
4
+ * Reapply current capture policy to persisted records before queueing or sending.
5
+ * Old turn state and offline events may predate a flag change — or this release —
6
+ * so the gate runs again here rather than only where the record was built.
7
+ * @param event - Product record, possibly from an older installation.
8
+ * @param capture - Effective, consent-gated capture flags. Metadata follows the
9
+ * schema defaults, so only an explicit `false` drops it.
10
+ * @returns A sanitized copy, or undefined when the whole record is no longer allowed.
11
+ */
12
+ export declare function applyProductCapture<T extends ProductEvent>(event: T, capture?: CaptureConfig): T | undefined;
@@ -0,0 +1,75 @@
1
+ import { foldMcpNames } from '../providers/shared/tooling.js';
2
+ import { sanitizeValue } from './sanitizer.js';
3
+ /**
4
+ * Reapply current capture policy to persisted records before queueing or sending.
5
+ * Old turn state and offline events may predate a flag change — or this release —
6
+ * so the gate runs again here rather than only where the record was built.
7
+ * @param event - Product record, possibly from an older installation.
8
+ * @param capture - Effective, consent-gated capture flags. Metadata follows the
9
+ * schema defaults, so only an explicit `false` drops it.
10
+ * @returns A sanitized copy, or undefined when the whole record is no longer allowed.
11
+ */
12
+ export function applyProductCapture(event, capture) {
13
+ // A snapshot is git metadata end to end — commit subjects included — so a
14
+ // revoked git flag drops the record instead of emptying it. Its commit files
15
+ // are path lists like any other, and go with `capture.files`.
16
+ if (event.event.type === 'repo.snapshot') {
17
+ if (capture?.git === false)
18
+ return undefined;
19
+ return sanitizeValue(capture?.files === false ? withoutCommitFiles(event) : event);
20
+ }
21
+ if (event.event.type !== 'turn.summary')
22
+ return sanitizeValue(event);
23
+ const summary = event;
24
+ // Response text goes unconditionally: this release never builds it, but a
25
+ // summary queued by an older one can still carry it. `prompt` is that older
26
+ // release's field and goes the same way; prompt text now rides only as
27
+ // `prompt_text`. Evidence (length + sha256) stays: it is what tells the
28
+ // backend a turn had content at all.
29
+ //
30
+ // The content fields need an explicit `true`: they are opt-in, and a
31
+ // missing policy is not consent. The path and repository fields need an
32
+ // explicit `false`: they are on by default. A queued record can outlive
33
+ // any of these flags, which is why they are asked again here.
34
+ const git = capture?.git === false;
35
+ const files = capture?.files === false;
36
+ return sanitizeValue({
37
+ ...event,
38
+ prompt: undefined,
39
+ tools_used: capture?.mcpNames === false ? foldMcpNames(summary.tools_used) : summary.tools_used,
40
+ response: undefined,
41
+ prompt_text: capture?.promptText === true ? summary.prompt_text : undefined,
42
+ tool_inputs: capture?.toolInput === true ? summary.tool_inputs : undefined,
43
+ session_name: capture?.sessionTitle === true ? summary.session_name : undefined,
44
+ session_title: capture?.sessionTitle === true ? summary.session_title : undefined,
45
+ repository: git ? undefined : summary.repository,
46
+ branch: git ? undefined : summary.branch,
47
+ commit: git ? undefined : summary.commit,
48
+ jira_ids: git ? undefined : summary.jira_ids,
49
+ prompt_jira_ids: git ? undefined : summary.prompt_jira_ids,
50
+ work_evidence: git ? undefined : summary.work_evidence,
51
+ parent_session_id: git ? undefined : summary.parent_session_id,
52
+ content_hashes: files ? undefined : summary.content_hashes,
53
+ manifest_repository: files ? undefined : summary.manifest_repository,
54
+ files_changed: files ? undefined : summary.files_changed,
55
+ files_touched: files ? undefined : summary.files_touched,
56
+ files_read: files ? undefined : summary.files_read,
57
+ external_files_touched: files ? undefined : summary.external_files_touched,
58
+ external_files_read: files ? undefined : summary.external_files_read
59
+ });
60
+ }
61
+ /**
62
+ * A snapshot with no commit file names, for a policy that withholds paths.
63
+ *
64
+ * @param event - The snapshot, possibly queued before the flag changed.
65
+ * @returns A copy whose commits carry no `files`.
66
+ */
67
+ function withoutCommitFiles(event) {
68
+ return {
69
+ ...event,
70
+ branches: event.branches.map((branch) => ({
71
+ ...branch,
72
+ commits: branch.commits.map(({ files: _files, ...commit }) => commit)
73
+ }))
74
+ };
75
+ }
@@ -1,6 +1,20 @@
1
1
  /**
2
2
  * Redact known credential shapes inside a string, and cap its length.
3
3
  *
4
+ * Redaction runs on the whole string and the cap is applied to the result,
5
+ * never the other way round. Truncating first cuts a credential that straddles
6
+ * the boundary short, so no pattern matches it any more and the surviving
7
+ * prefix ships in the clear: `openai-anthropic-key` needs 16 characters after
8
+ * `sk-`, and `jwt` needs its third dot-separated segment — a JWT cut mid
9
+ * signature would have shipped its header and payload, which base64url-decode
10
+ * to the very claims this exists to keep off the wire.
11
+ *
12
+ * Scrubbing the whole string is affordable because every pattern is linear in
13
+ * its input — see `url-credentials`, which was not. A bounded window instead of
14
+ * the whole string would not do: the margin would have to exceed the longest
15
+ * credential, and a private-key block or a JWT with a fat payload has no such
16
+ * length.
17
+ *
4
18
  * @param text - Text about to leave the machine.
5
19
  * @returns The scrubbed text.
6
20
  */
@@ -10,9 +24,13 @@ export declare function sanitizeText(text: string): string;
10
24
  *
11
25
  * Two independent defences, because either alone leaks: a value under a
12
26
  * sensitive *key* is dropped whole whatever it looks like, and every string is
13
- * pattern-scrubbed whatever key it sits under. Both run regardless of the
14
- * user's capture settings — those decide what we collect, not whether secrets
15
- * are removed from it.
27
+ * pattern-scrubbed whatever key it sits under — keys included, because captured
28
+ * material contains keyed maps whose keys are the credential. Both run
29
+ * regardless of the user's capture settings — those decide what we collect, not
30
+ * whether secrets are removed from it.
31
+ *
32
+ * The sensitive-key test reads the *raw* key, since scrubbing it first could
33
+ * destroy the very word ("authorization") the test matches on.
16
34
  *
17
35
  * @param value - Value to sanitize; left untouched.
18
36
  * @returns A sanitized copy of the same shape.
@@ -3,24 +3,42 @@ import { MAX_DEPTH, MAX_STRING_LENGTH, REDACTED, SECRET_PATTERNS, SENSITIVE_KEY_
3
3
  /**
4
4
  * Redact known credential shapes inside a string, and cap its length.
5
5
  *
6
+ * Redaction runs on the whole string and the cap is applied to the result,
7
+ * never the other way round. Truncating first cuts a credential that straddles
8
+ * the boundary short, so no pattern matches it any more and the surviving
9
+ * prefix ships in the clear: `openai-anthropic-key` needs 16 characters after
10
+ * `sk-`, and `jwt` needs its third dot-separated segment — a JWT cut mid
11
+ * signature would have shipped its header and payload, which base64url-decode
12
+ * to the very claims this exists to keep off the wire.
13
+ *
14
+ * Scrubbing the whole string is affordable because every pattern is linear in
15
+ * its input — see `url-credentials`, which was not. A bounded window instead of
16
+ * the whole string would not do: the margin would have to exceed the longest
17
+ * credential, and a private-key block or a JWT with a fat payload has no such
18
+ * length.
19
+ *
6
20
  * @param text - Text about to leave the machine.
7
21
  * @returns The scrubbed text.
8
22
  */
9
23
  export function sanitizeText(text) {
10
- let out = text.length > MAX_STRING_LENGTH ? text.slice(0, MAX_STRING_LENGTH) : text;
24
+ let out = text;
11
25
  for (const { pattern, replacement } of SECRET_PATTERNS) {
12
26
  out = out.replace(pattern, replacement ?? REDACTED);
13
27
  }
14
- return out;
28
+ return out.length > MAX_STRING_LENGTH ? out.slice(0, MAX_STRING_LENGTH) : out;
15
29
  }
16
30
  /**
17
31
  * Recursively sanitize any value before it leaves the machine.
18
32
  *
19
33
  * Two independent defences, because either alone leaks: a value under a
20
34
  * sensitive *key* is dropped whole whatever it looks like, and every string is
21
- * pattern-scrubbed whatever key it sits under. Both run regardless of the
22
- * user's capture settings — those decide what we collect, not whether secrets
23
- * are removed from it.
35
+ * pattern-scrubbed whatever key it sits under — keys included, because captured
36
+ * material contains keyed maps whose keys are the credential. Both run
37
+ * regardless of the user's capture settings — those decide what we collect, not
38
+ * whether secrets are removed from it.
39
+ *
40
+ * The sensitive-key test reads the *raw* key, since scrubbing it first could
41
+ * destroy the very word ("authorization") the test matches on.
24
42
  *
25
43
  * @param value - Value to sanitize; left untouched.
26
44
  * @returns A sanitized copy of the same shape.
@@ -42,11 +60,37 @@ function walk(value, depth) {
42
60
  return sanitizeText(value);
43
61
  if (Array.isArray(value))
44
62
  return value.map((item) => walk(item, depth + 1));
63
+ // A Date is an object to `isRecord`, so rebuilding it as a record turned it
64
+ // into `{}` — the record on the wire lost a timestamp that `JSON.stringify`
65
+ // would have written as an ISO string. It carries no secret and has nothing
66
+ // to descend into, so it passes through and serializes as it always would.
67
+ if (value instanceof Date)
68
+ return value;
45
69
  if (!isRecord(value))
46
70
  return value;
47
- const out = {};
71
+ const out = Object.create(null);
48
72
  for (const [key, entry] of Object.entries(value)) {
49
- out[key] = SENSITIVE_KEY_PATTERN.test(key) ? REDACTED : walk(entry, depth + 1);
73
+ out[freeKey(out, sanitizeText(key))] = SENSITIVE_KEY_PATTERN.test(key) ? REDACTED : walk(entry, depth + 1);
50
74
  }
51
- return out;
75
+ return { ...out };
76
+ }
77
+ /**
78
+ * First unused spelling of an already-sanitized key.
79
+ *
80
+ * Two distinct keys can scrub to the same string, and plain assignment would
81
+ * then silently merge two entries into one — data loss in the module whose job
82
+ * is to be trustworthy. Collisions get a `:2`, `:3` suffix instead, so the copy
83
+ * always holds as many entries as the original.
84
+ *
85
+ * @param out - Object being built; only read here.
86
+ * @param key - Sanitized key to place.
87
+ * @returns The key itself, or the first free suffixed spelling of it.
88
+ */
89
+ function freeKey(out, key) {
90
+ if (!(key in out))
91
+ return key;
92
+ let suffix = 2;
93
+ while (`${key}:${suffix}` in out)
94
+ suffix += 1;
95
+ return `${key}:${suffix}`;
52
96
  }
@@ -0,0 +1,39 @@
1
+ import type { ProcessInfo, ProcessTable } from './types/process.types.js';
2
+ /**
3
+ * Parse `ps -o pid=,ppid=,lstart=,comm=` output. Lines that do not parse are dropped.
4
+ *
5
+ * @param text - The listing.
6
+ * @returns The processes by pid.
7
+ */
8
+ export declare function parseProcessList(text: string): Map<number, ProcessInfo>;
9
+ /**
10
+ * The processes above `pid`, nearest first.
11
+ *
12
+ * Stops at the depth cap, at a pid the table does not list, at pid 0/1 and at a
13
+ * cycle: a damaged table must end the walk, never loop it.
14
+ *
15
+ * @param table - The listing.
16
+ * @param pid - The process whose ancestors are wanted; not itself included.
17
+ * @param depth - How many to return at most.
18
+ * @returns The ancestors.
19
+ */
20
+ export declare function ancestorChain(table: ReadonlyMap<number, ProcessInfo>, pid: number, depth?: number): ProcessInfo[];
21
+ /**
22
+ * The agent process behind a hook: its parent, or that parent's parent when a
23
+ * shell was put between them to run the hook command.
24
+ *
25
+ * Without the hop, an ephemeral `sh -c` would be recorded as the agent and no
26
+ * child's ancestry would ever contain it.
27
+ *
28
+ * @param table - The process table.
29
+ * @returns The agent process with its start time, or undefined when it cannot be read.
30
+ */
31
+ export declare function agentProcess(table: ProcessTable): Promise<ProcessInfo | undefined>;
32
+ /**
33
+ * The real process table. Fails open: every error is an absent answer.
34
+ *
35
+ * @param signal - Kills every `ps` or `lsof` still running when it aborts, so a
36
+ * walk past its deadline leaves no child behind.
37
+ * @returns A table over `ps`, and `/proc` or `lsof` for working folders.
38
+ */
39
+ export declare function systemProcessTable(signal?: AbortSignal): ProcessTable;
@@ -0,0 +1,121 @@
1
+ import { execFile } from 'node:child_process';
2
+ import fs from 'node:fs/promises';
3
+ import process from 'node:process';
4
+ import { debugLog } from '../core/logger.js';
5
+ import { LSOF_FAST_ARGS, MAX_ANCESTOR_DEPTH, PROCESS_MAX_BUFFER_BYTES, PROCESS_TIMEOUT_MS, RE_LOGIN_SHELL_DASH, RE_LSOF_PID, RE_PS_LINE, SHELL_NAMES } from './constants/process.constants.js';
6
+ /**
7
+ * Parse `ps -o pid=,ppid=,lstart=,comm=` output. Lines that do not parse are dropped.
8
+ *
9
+ * @param text - The listing.
10
+ * @returns The processes by pid.
11
+ */
12
+ export function parseProcessList(text) {
13
+ const table = new Map();
14
+ for (const line of text.split('\n')) {
15
+ const match = RE_PS_LINE.exec(line);
16
+ if (match)
17
+ table.set(Number(match[1]), { pid: Number(match[1]), ppid: Number(match[2]), started: match[3], comm: match[4] ?? '' });
18
+ }
19
+ return table;
20
+ }
21
+ /**
22
+ * The processes above `pid`, nearest first.
23
+ *
24
+ * Stops at the depth cap, at a pid the table does not list, at pid 0/1 and at a
25
+ * cycle: a damaged table must end the walk, never loop it.
26
+ *
27
+ * @param table - The listing.
28
+ * @param pid - The process whose ancestors are wanted; not itself included.
29
+ * @param depth - How many to return at most.
30
+ * @returns The ancestors.
31
+ */
32
+ export function ancestorChain(table, pid, depth = MAX_ANCESTOR_DEPTH) {
33
+ const chain = [];
34
+ const seen = new Set([pid]);
35
+ let next = table.get(pid)?.ppid;
36
+ while (next !== undefined && next > 1 && !seen.has(next) && chain.length < depth) {
37
+ const info = table.get(next);
38
+ if (!info)
39
+ break;
40
+ chain.push(info);
41
+ seen.add(next);
42
+ next = info.ppid;
43
+ }
44
+ return chain;
45
+ }
46
+ /**
47
+ * The agent process behind a hook: its parent, or that parent's parent when a
48
+ * shell was put between them to run the hook command.
49
+ *
50
+ * Without the hop, an ephemeral `sh -c` would be recorded as the agent and no
51
+ * child's ancestry would ever contain it.
52
+ *
53
+ * @param table - The process table.
54
+ * @returns The agent process with its start time, or undefined when it cannot be read.
55
+ */
56
+ export async function agentProcess(table) {
57
+ const parent = await table.info(table.ppid);
58
+ if (!parent || !isShell(parent))
59
+ return parent;
60
+ return (await table.info(parent.ppid)) ?? parent;
61
+ }
62
+ function isShell(info) {
63
+ return SHELL_NAMES.has(info.comm.split('/').pop().replace(RE_LOGIN_SHELL_DASH, ''));
64
+ }
65
+ /**
66
+ * The real process table. Fails open: every error is an absent answer.
67
+ *
68
+ * @param signal - Kills every `ps` or `lsof` still running when it aborts, so a
69
+ * walk past its deadline leaves no child behind.
70
+ * @returns A table over `ps`, and `/proc` or `lsof` for working folders.
71
+ */
72
+ export function systemProcessTable(signal) {
73
+ return {
74
+ ppid: process.ppid,
75
+ async info(pid) {
76
+ return parseProcessList((await run('ps', ['-o', 'pid=,ppid=,lstart=,comm=', '-p', String(pid)], signal)) ?? '').get(pid);
77
+ },
78
+ async snapshot() {
79
+ const text = await run('ps', ['-A', '-o', 'pid=,ppid='], signal);
80
+ return text === undefined ? undefined : parseProcessList(text);
81
+ },
82
+ cwds: (pids) => (process.platform === 'linux' ? procCwds(pids) : lsofCwds(pids, signal))
83
+ };
84
+ }
85
+ async function procCwds(pids) {
86
+ const found = new Map();
87
+ await Promise.all(pids.map(async (pid) => {
88
+ const cwd = await fs.readlink(`/proc/${pid}/cwd`).catch(() => undefined);
89
+ if (cwd)
90
+ found.set(pid, cwd);
91
+ }));
92
+ return found;
93
+ }
94
+ // One lsof for the whole chain: each spawn costs more than the lookup does.
95
+ async function lsofCwds(pids, signal) {
96
+ const found = new Map();
97
+ if (process.platform === 'win32' || pids.length === 0)
98
+ return found;
99
+ let current;
100
+ for (const line of ((await run('lsof', [...LSOF_FAST_ARGS, '-a', '-p', pids.join(','), '-d', 'cwd', '-Fn'], signal)) ?? '').split('\n')) {
101
+ const pid = RE_LSOF_PID.exec(line);
102
+ if (pid)
103
+ current = Number(pid[1]);
104
+ if (line.startsWith('n/') && current !== undefined)
105
+ found.set(current, line.slice(1));
106
+ }
107
+ return found;
108
+ }
109
+ // Killed at PROCESS_TIMEOUT_MS, or at once when `signal` aborts.
110
+ function run(file, args, signal) {
111
+ if (process.platform === 'win32')
112
+ return Promise.resolve(undefined);
113
+ return new Promise((resolve) => {
114
+ execFile(file, args, { timeout: PROCESS_TIMEOUT_MS, signal, maxBuffer: PROCESS_MAX_BUFFER_BYTES, windowsHide: true, env: { ...process.env, LC_ALL: 'C' } }, (error, stdout) => {
115
+ // A fixed sentence: nothing about which processes ran belongs in a log.
116
+ if (error && !stdout)
117
+ debugLog('process table unreadable');
118
+ resolve(error && !stdout ? undefined : stdout);
119
+ });
120
+ });
121
+ }
@@ -0,0 +1,34 @@
1
+ /** How many processes above the agent are looked at. */
2
+ export declare const MAX_ANCESTOR_DEPTH = 8;
3
+ /**
4
+ * Kill budget for each `ps` or `lsof` child, so a stuck one does not outlive
5
+ * the walk's deadline by much. A healthy run is 15-25 ms.
6
+ */
7
+ export declare const PROCESS_TIMEOUT_MS = 150;
8
+ /** Upper bound on `ps` output: a busy machine lists a few thousand processes. */
9
+ export declare const PROCESS_MAX_BUFFER_BYTES: number;
10
+ /**
11
+ * `<pid> <ppid> [[<lstart>] <comm>]`. lstart is always five fields, `Sat Oct 4
12
+ * 11:42:27 2026`, with the day padded by spaces; the command is the rest of the
13
+ * line. The bulk listing asks for neither: resolving every process's command
14
+ * costs as much as listing them all, and the chain needs only pids.
15
+ */
16
+ export declare const RE_PS_LINE: RegExp;
17
+ /**
18
+ * The whole walk's deadline: SPEC §8 allows the first hook of a session 100 ms
19
+ * at the 95th percentile. A slow `ps` or `lsof` is abandoned, never waited for.
20
+ */
21
+ export declare const WALK_DEADLINE_MS = 100;
22
+ /**
23
+ * Walks a session gets when the deadline keeps cutting them: the first hook's
24
+ * and two retries, one per later hook, each under {@link WALK_DEADLINE_MS}.
25
+ */
26
+ export declare const MAX_WALK_ATTEMPTS = 3;
27
+ /** A login shell's name carries a leading dash: `-zsh`. */
28
+ export declare const RE_LOGIN_SHELL_DASH: RegExp;
29
+ /** `lsof` without name resolution or kernel calls that can block: half the time, same answer for a cwd. */
30
+ export declare const LSOF_FAST_ARGS: readonly string[];
31
+ /** Shells a hook command may be wrapped in; the agent is the shell's parent. */
32
+ export declare const SHELL_NAMES: ReadonlySet<string>;
33
+ /** `lsof -Fn` prints `p<pid>` then `n<path>` for each process. */
34
+ export declare const RE_LSOF_PID: RegExp;
@@ -0,0 +1,34 @@
1
+ /** How many processes above the agent are looked at. */
2
+ export const MAX_ANCESTOR_DEPTH = 8;
3
+ /**
4
+ * Kill budget for each `ps` or `lsof` child, so a stuck one does not outlive
5
+ * the walk's deadline by much. A healthy run is 15-25 ms.
6
+ */
7
+ export const PROCESS_TIMEOUT_MS = 150;
8
+ /** Upper bound on `ps` output: a busy machine lists a few thousand processes. */
9
+ export const PROCESS_MAX_BUFFER_BYTES = 8 * 1024 * 1024;
10
+ /**
11
+ * `<pid> <ppid> [[<lstart>] <comm>]`. lstart is always five fields, `Sat Oct 4
12
+ * 11:42:27 2026`, with the day padded by spaces; the command is the rest of the
13
+ * line. The bulk listing asks for neither: resolving every process's command
14
+ * costs as much as listing them all, and the chain needs only pids.
15
+ */
16
+ export const RE_PS_LINE = /^\s*(\d+)\s+(\d+)(?:\s+(?:(\w{3} \w{3}\s+\d+ \d\d:\d\d:\d\d \d{4})\s+)?(.+?))?\s*$/;
17
+ /**
18
+ * The whole walk's deadline: SPEC §8 allows the first hook of a session 100 ms
19
+ * at the 95th percentile. A slow `ps` or `lsof` is abandoned, never waited for.
20
+ */
21
+ export const WALK_DEADLINE_MS = 100;
22
+ /**
23
+ * Walks a session gets when the deadline keeps cutting them: the first hook's
24
+ * and two retries, one per later hook, each under {@link WALK_DEADLINE_MS}.
25
+ */
26
+ export const MAX_WALK_ATTEMPTS = 3;
27
+ /** A login shell's name carries a leading dash: `-zsh`. */
28
+ export const RE_LOGIN_SHELL_DASH = /^-/;
29
+ /** `lsof` without name resolution or kernel calls that can block: half the time, same answer for a cwd. */
30
+ export const LSOF_FAST_ARGS = ['-b', '-n', '-P', '-w'];
31
+ /** Shells a hook command may be wrapped in; the agent is the shell's parent. */
32
+ export const SHELL_NAMES = new Set(['sh', 'bash', 'zsh', 'dash', 'fish', 'ksh']);
33
+ /** `lsof -Fn` prints `p<pid>` then `n<path>` for each process. */
34
+ export const RE_LSOF_PID = /^p(\d+)$/;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The machine's process table, read once per session to find what started the
3
+ * agent. Local only, and fail-open: nothing here may fail a hook.
4
+ */
5
+ export type { ProcessInfo, ProcessTable } from './types/process.types.js';
6
+ export { agentProcess, ancestorChain, parseProcessList, systemProcessTable } from './ancestors.js';
7
+ export { MAX_ANCESTOR_DEPTH, MAX_WALK_ATTEMPTS, WALK_DEADLINE_MS } from './constants/process.constants.js';
@@ -0,0 +1,2 @@
1
+ export { agentProcess, ancestorChain, parseProcessList, systemProcessTable } from './ancestors.js';
2
+ export { MAX_ANCESTOR_DEPTH, MAX_WALK_ATTEMPTS, WALK_DEADLINE_MS } from './constants/process.constants.js';
@@ -0,0 +1,23 @@
1
+ /** One process, as `ps` lists it. Local only: none of it is ever sent. */
2
+ export interface ProcessInfo {
3
+ readonly pid: number;
4
+ readonly ppid: number;
5
+ /** Start time as `ps -o lstart` prints it; tells a pid's reuse from the process remembered. */
6
+ readonly started?: string;
7
+ /** Executable name, possibly a full path; empty in the bulk listing, which does not resolve it. */
8
+ readonly comm: string;
9
+ }
10
+ /**
11
+ * What the edge may ask of the machine's process table. Injected through `Env`
12
+ * so a test can stand up a process tree no harness could start for real.
13
+ */
14
+ export interface ProcessTable {
15
+ /** The hook process's own parent: the agent, or the shell the agent ran the hook in. */
16
+ readonly ppid: number;
17
+ /** One process, or undefined when it is gone or the table cannot be read. */
18
+ info(pid: number): Promise<ProcessInfo | undefined>;
19
+ /** Every process, listed once, without start times or names (`info` has them). Undefined when the table cannot be read. */
20
+ snapshot(): Promise<ReadonlyMap<number, ProcessInfo> | undefined>;
21
+ /** The working folders of these processes; a pid whose folder cannot be read is absent. */
22
+ cwds(pids: readonly number[]): Promise<ReadonlyMap<number, string>>;
23
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  import type { AgentWatchEvent } from '../../events/types/events.types.js';
2
- import type { HookContext } from '../types/provider.types.js';
2
+ import type { HookContext, ShellCall } from '../types/provider.types.js';
3
3
  import type { AntigravityHookEvent } from './types/antigravity.types.js';
4
4
  export type { AntigravityHookEvent, AntigravityPayload } from './types/antigravity.types.js';
5
5
  /**
@@ -24,6 +24,17 @@ export declare function antigravityHookEvent(rawPayload: unknown): AntigravityHo
24
24
  * @returns The primary workspace path, or undefined.
25
25
  */
26
26
  export declare function antigravityCwd(rawPayload: unknown): string | undefined;
27
+ /**
28
+ * The command a `run_command` tool call runs, and its `Cwd`, before and after it
29
+ * ran (a command can create the worktree it works in).
30
+ *
31
+ * Arguments as the fixtures record them, read off the tool schema in the `agy`
32
+ * binary: `CommandLine` and `Cwd`, PascalCase.
33
+ *
34
+ * @param rawPayload - Raw JSON from the hook's stdin.
35
+ * @returns The call, or undefined for any other payload.
36
+ */
37
+ export declare function antigravityShellCall(rawPayload: unknown): ShellCall | undefined;
27
38
  /**
28
39
  * Translate one Antigravity hook payload into canonical events.
29
40
  *