@agent-watch-ai/edge 0.5.0 → 0.7.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 (298) hide show
  1. package/CHANGELOG.md +238 -7
  2. package/README.md +308 -8
  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 +3 -2
  10. package/dist/billing/session-billing.js +8 -8
  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 +479 -0
  16. package/dist/capture/constants/capture.constants.d.ts +70 -0
  17. package/dist/capture/constants/capture.constants.js +72 -0
  18. package/dist/capture/launched-runs.d.ts +16 -0
  19. package/dist/capture/launched-runs.js +151 -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 +823 -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/cli/constants/cli.constants.d.ts +2 -6
  27. package/dist/cli/constants/cli.constants.js +3 -7
  28. package/dist/cli/context.d.ts +19 -22
  29. package/dist/cli/context.js +23 -54
  30. package/dist/cli/doctor-run-capture.d.ts +13 -0
  31. package/dist/cli/doctor-run-capture.js +19 -0
  32. package/dist/cli/doctor.js +16 -67
  33. package/dist/cli/hook.d.ts +14 -0
  34. package/dist/cli/hook.js +40 -0
  35. package/dist/cli/index.d.ts +1 -1
  36. package/dist/cli/index.js +1 -1
  37. package/dist/cli/misc.js +10 -2
  38. package/dist/cli/replay.d.ts +33 -0
  39. package/dist/cli/replay.js +193 -0
  40. package/dist/cli/setup.d.ts +10 -2
  41. package/dist/cli/setup.js +154 -26
  42. package/dist/cli/status.js +45 -5
  43. package/dist/cli/toggle.js +10 -0
  44. package/dist/cli/types/cli.types.d.ts +15 -1
  45. package/dist/cli/uninstall.js +8 -22
  46. package/dist/cli.js +104 -17
  47. package/dist/config/config.d.ts +0 -2
  48. package/dist/config/config.js +0 -1
  49. package/dist/config/constants/config.constants.js +2 -0
  50. package/dist/config/events-transport.d.ts +15 -0
  51. package/dist/config/events-transport.js +29 -0
  52. package/dist/config/index.d.ts +2 -1
  53. package/dist/config/index.js +1 -0
  54. package/dist/config/root-config.d.ts +12 -0
  55. package/dist/config/root-config.js +24 -0
  56. package/dist/config/schemas/config.schema.d.ts +13 -0
  57. package/dist/config/schemas/config.schema.js +42 -6
  58. package/dist/config/types/config.types.d.ts +7 -0
  59. package/dist/core/index.d.ts +1 -1
  60. package/dist/core/index.js +1 -1
  61. package/dist/core/version.d.ts +9 -0
  62. package/dist/core/version.js +14 -0
  63. package/dist/core/which.d.ts +11 -0
  64. package/dist/core/which.js +18 -0
  65. package/dist/credentials/cloud-claim.d.ts +32 -0
  66. package/dist/credentials/cloud-claim.js +42 -0
  67. package/dist/credentials/constants/credentials.constants.d.ts +8 -1
  68. package/dist/credentials/constants/credentials.constants.js +9 -2
  69. package/dist/credentials/device-api.d.ts +15 -1
  70. package/dist/credentials/device-api.js +12 -1
  71. package/dist/credentials/sign-in.d.ts +27 -0
  72. package/dist/credentials/sign-in.js +31 -1
  73. package/dist/credentials/token-refresher.d.ts +5 -1
  74. package/dist/credentials/token-refresher.js +10 -2
  75. package/dist/events/constants/events.constants.d.ts +8 -2
  76. package/dist/events/constants/events.constants.js +7 -1
  77. package/dist/events/index.d.ts +2 -0
  78. package/dist/events/product-event.d.ts +10 -4
  79. package/dist/events/types/events.types.d.ts +6 -0
  80. package/dist/events/types/replay-progress.types.d.ts +26 -0
  81. package/dist/events/types/replay-progress.types.js +1 -0
  82. package/dist/events/types/repo-snapshot.types.d.ts +1 -4
  83. package/dist/events/types/repo-tree.types.d.ts +25 -0
  84. package/dist/events/types/repo-tree.types.js +1 -0
  85. package/dist/feature/ticket-candidates.d.ts +1 -1
  86. package/dist/git/checkout-root.d.ts +15 -0
  87. package/dist/git/checkout-root.js +18 -0
  88. package/dist/git/code-state.d.ts +2 -16
  89. package/dist/git/code-state.js +11 -12
  90. package/dist/git/constants/git.constants.d.ts +31 -11
  91. package/dist/git/constants/git.constants.js +36 -12
  92. package/dist/git/constants/tree.constants.d.ts +71 -0
  93. package/dist/git/constants/tree.constants.js +92 -0
  94. package/dist/git/fingerprint.d.ts +3 -6
  95. package/dist/git/fingerprint.js +5 -8
  96. package/dist/git/git-context.d.ts +1 -0
  97. package/dist/git/git-context.js +8 -3
  98. package/dist/git/index.d.ts +1 -2
  99. package/dist/git/index.js +1 -1
  100. package/dist/git/repo-snapshot.d.ts +13 -4
  101. package/dist/git/repo-snapshot.js +47 -9
  102. package/dist/git/repo-tree.d.ts +69 -0
  103. package/dist/git/repo-tree.js +130 -0
  104. package/dist/git/types/git.types.d.ts +5 -2
  105. package/dist/git/types/snapshot.types.d.ts +14 -0
  106. package/dist/pipeline/constants/pipeline.constants.d.ts +3 -0
  107. package/dist/pipeline/constants/pipeline.constants.js +3 -0
  108. package/dist/pipeline/hook-pipeline.js +112 -72
  109. package/dist/privacy/product-capture.js +36 -5
  110. package/dist/providers/antigravity/antigravity.capture.d.ts +2 -0
  111. package/dist/providers/antigravity/antigravity.capture.js +5 -0
  112. package/dist/providers/antigravity/antigravity.detect.js +8 -22
  113. package/dist/providers/antigravity/antigravity.provider.js +10 -3
  114. package/dist/providers/antigravity/constants/antigravity.constants.d.ts +1 -0
  115. package/dist/providers/antigravity/constants/antigravity.constants.js +1 -0
  116. package/dist/providers/claude/claude.adapter.js +9 -6
  117. package/dist/providers/claude/claude.detect.js +2 -17
  118. package/dist/providers/claude/claude.otel.d.ts +21 -3
  119. package/dist/providers/claude/claude.otel.js +216 -61
  120. package/dist/providers/claude/claude.provider.js +17 -1
  121. package/dist/providers/claude/claude.version.d.ts +9 -0
  122. package/dist/providers/claude/claude.version.js +28 -0
  123. package/dist/providers/claude/constants/claude.constants.d.ts +27 -0
  124. package/dist/providers/claude/constants/claude.constants.js +27 -0
  125. package/dist/providers/claude/constants/claude.otel.constants.d.ts +27 -0
  126. package/dist/providers/claude/constants/claude.otel.constants.js +45 -5
  127. package/dist/providers/claude/types/claude.types.d.ts +13 -0
  128. package/dist/providers/codex/codex.capture.d.ts +76 -0
  129. package/dist/providers/codex/codex.capture.js +454 -0
  130. package/dist/providers/codex/codex.detect.js +2 -4
  131. package/dist/providers/codex/codex.otel.d.ts +38 -2
  132. package/dist/providers/codex/codex.otel.js +50 -6
  133. package/dist/providers/codex/codex.provider.js +8 -0
  134. package/dist/providers/codex/codex.surface.d.ts +9 -0
  135. package/dist/{turns/codex-originator.js → providers/codex/codex.surface.js} +17 -3
  136. package/dist/providers/codex/codex.titles.d.ts +14 -0
  137. package/dist/providers/codex/codex.titles.js +35 -0
  138. package/dist/providers/codex/constants/codex.constants.d.ts +4 -0
  139. package/dist/providers/codex/constants/codex.constants.js +4 -0
  140. package/dist/providers/cursor/constants/cursor.constants.d.ts +17 -4
  141. package/dist/providers/cursor/constants/cursor.constants.js +25 -5
  142. package/dist/providers/cursor/cursor-mcp-memo.d.ts +34 -0
  143. package/dist/providers/cursor/cursor-mcp-memo.js +94 -0
  144. package/dist/providers/cursor/cursor.adapter.js +20 -82
  145. package/dist/providers/cursor/cursor.capture.d.ts +1 -0
  146. package/dist/providers/cursor/cursor.capture.js +4 -0
  147. package/dist/providers/cursor/cursor.detect.d.ts +5 -1
  148. package/dist/providers/cursor/cursor.detect.js +11 -26
  149. package/dist/providers/cursor/cursor.hooks.js +2 -2
  150. package/dist/providers/cursor/cursor.provider.js +16 -7
  151. package/dist/providers/cursor/cursor.titles.d.ts +14 -0
  152. package/dist/providers/cursor/cursor.titles.js +20 -0
  153. package/dist/providers/cursor/schemas/cursor.schema.d.ts +3 -3
  154. package/dist/providers/cursor/schemas/cursor.schema.js +5 -3
  155. package/dist/providers/gemini/constants/gemini.constants.d.ts +16 -0
  156. package/dist/providers/gemini/constants/gemini.constants.js +17 -0
  157. package/dist/providers/gemini/gemini.capture.d.ts +81 -0
  158. package/dist/providers/gemini/gemini.capture.js +210 -0
  159. package/dist/providers/gemini/gemini.detect.js +57 -24
  160. package/dist/providers/gemini/gemini.otel.d.ts +38 -2
  161. package/dist/providers/gemini/gemini.otel.js +56 -125
  162. package/dist/providers/gemini/gemini.provider.js +5 -0
  163. package/dist/providers/index.d.ts +1 -0
  164. package/dist/providers/index.js +1 -0
  165. package/dist/providers/provider.d.ts +8 -0
  166. package/dist/providers/provider.js +9 -0
  167. package/dist/providers/registry.d.ts +14 -0
  168. package/dist/providers/registry.js +14 -0
  169. package/dist/providers/shared/constants/hook-config.constants.d.ts +2 -0
  170. package/dist/providers/shared/constants/hook-config.constants.js +2 -0
  171. package/dist/providers/shared/constants/terminal-capture.constants.d.ts +6 -0
  172. package/dist/providers/shared/constants/terminal-capture.constants.js +6 -0
  173. package/dist/providers/shared/editor-paths.d.ts +8 -0
  174. package/dist/providers/shared/editor-paths.js +18 -0
  175. package/dist/providers/shared/hook-config.d.ts +5 -0
  176. package/dist/providers/shared/hook-config.js +39 -1
  177. package/dist/providers/shared/hooks-marker.d.ts +14 -0
  178. package/dist/providers/shared/hooks-marker.js +23 -0
  179. package/dist/providers/shared/install-record.d.ts +29 -0
  180. package/dist/providers/shared/install-record.js +52 -0
  181. package/dist/providers/shared/session-title-store.d.ts +23 -0
  182. package/dist/providers/shared/session-title-store.js +50 -0
  183. package/dist/providers/shared/terminal-capture.d.ts +41 -0
  184. package/dist/providers/shared/terminal-capture.js +109 -0
  185. package/dist/providers/shared/tooling.d.ts +21 -0
  186. package/dist/providers/shared/tooling.js +36 -1
  187. package/dist/providers/types/provider.types.d.ts +57 -4
  188. package/dist/replay/checkout-resolver.d.ts +29 -0
  189. package/dist/replay/checkout-resolver.js +69 -0
  190. package/dist/replay/codex-turns.d.ts +24 -0
  191. package/dist/replay/codex-turns.js +221 -0
  192. package/dist/replay/constants/replay.constants.d.ts +99 -0
  193. package/dist/replay/constants/replay.constants.js +102 -0
  194. package/dist/replay/describe.d.ts +10 -0
  195. package/dist/replay/describe.js +31 -0
  196. package/dist/replay/gemini-turns.d.ts +36 -0
  197. package/dist/replay/gemini-turns.js +192 -0
  198. package/dist/replay/machine.d.ts +34 -0
  199. package/dist/replay/machine.js +68 -0
  200. package/dist/replay/progress-event.d.ts +21 -0
  201. package/dist/replay/progress-event.js +45 -0
  202. package/dist/replay/replay-runner.d.ts +58 -0
  203. package/dist/replay/replay-runner.js +529 -0
  204. package/dist/replay/replay-scan.d.ts +83 -0
  205. package/dist/replay/replay-scan.js +170 -0
  206. package/dist/replay/replay-state.d.ts +108 -0
  207. package/dist/replay/replay-state.js +199 -0
  208. package/dist/replay/resume.d.ts +18 -0
  209. package/dist/replay/resume.js +34 -0
  210. package/dist/replay/start.d.ts +23 -0
  211. package/dist/replay/start.js +39 -0
  212. package/dist/replay/throttle.d.ts +35 -0
  213. package/dist/replay/throttle.js +41 -0
  214. package/dist/replay/transcript-turns.d.ts +35 -0
  215. package/dist/replay/transcript-turns.js +215 -0
  216. package/dist/replay/turn-event.d.ts +38 -0
  217. package/dist/replay/turn-event.js +116 -0
  218. package/dist/replay/types/replay.types.d.ts +162 -0
  219. package/dist/replay/types/replay.types.js +1 -0
  220. package/dist/replay/window.d.ts +28 -0
  221. package/dist/replay/window.js +41 -0
  222. package/dist/snapshot/branch-selection.d.ts +40 -23
  223. package/dist/snapshot/branch-selection.js +74 -42
  224. package/dist/snapshot/budget.js +2 -2
  225. package/dist/snapshot/constants/snapshot-stages.constants.d.ts +10 -0
  226. package/dist/snapshot/constants/snapshot-stages.constants.js +10 -0
  227. package/dist/snapshot/constants/snapshot.constants.d.ts +37 -4
  228. package/dist/snapshot/constants/snapshot.constants.js +37 -4
  229. package/dist/snapshot/index.d.ts +6 -1
  230. package/dist/snapshot/index.js +3 -1
  231. package/dist/snapshot/snapshot-event.d.ts +7 -0
  232. package/dist/snapshot/snapshot-event.js +8 -5
  233. package/dist/snapshot/snapshot-pipeline.js +89 -26
  234. package/dist/snapshot/snapshot-state.js +24 -2
  235. package/dist/snapshot/tree-event.d.ts +14 -0
  236. package/dist/snapshot/tree-event.js +91 -0
  237. package/dist/snapshot/tree-pipeline.d.ts +12 -0
  238. package/dist/snapshot/tree-pipeline.js +172 -0
  239. package/dist/snapshot/types/snapshot.types.d.ts +62 -2
  240. package/dist/storage/schemas/storage.schema.d.ts +2 -0
  241. package/dist/storage/schemas/storage.schema.js +6 -0
  242. package/dist/transport/constants/transport.constants.d.ts +5 -0
  243. package/dist/transport/constants/transport.constants.js +5 -0
  244. package/dist/transport/delivery-stats.d.ts +13 -1
  245. package/dist/transport/delivery-stats.js +18 -2
  246. package/dist/transport/delivery.d.ts +4 -3
  247. package/dist/transport/delivery.js +21 -7
  248. package/dist/transport/identity-delivery.d.ts +20 -0
  249. package/dist/transport/identity-delivery.js +41 -0
  250. package/dist/transport/index.d.ts +2 -0
  251. package/dist/transport/index.js +1 -0
  252. package/dist/transport/queue.js +40 -6
  253. package/dist/transport/types/delivery-flow.types.d.ts +7 -0
  254. package/dist/turns/claude-transcript.js +4 -12
  255. package/dist/turns/codex-transcript.d.ts +9 -0
  256. package/dist/turns/codex-transcript.js +27 -19
  257. package/dist/turns/constants/turns.constants.d.ts +13 -12
  258. package/dist/turns/constants/turns.constants.js +15 -19
  259. package/dist/turns/gemini-transcript.d.ts +19 -1
  260. package/dist/turns/gemini-transcript.js +29 -18
  261. package/dist/turns/index.d.ts +3 -4
  262. package/dist/turns/index.js +2 -3
  263. package/dist/turns/run-state.d.ts +71 -0
  264. package/dist/turns/run-state.js +114 -0
  265. package/dist/turns/tool-events.d.ts +11 -1
  266. package/dist/turns/tool-events.js +32 -9
  267. package/dist/turns/transcript.d.ts +15 -14
  268. package/dist/turns/transcript.js +23 -4
  269. package/dist/turns/turn-state.d.ts +49 -7
  270. package/dist/turns/turn-state.js +78 -10
  271. package/dist/turns/turn-summary.js +10 -6
  272. package/dist/turns/turn-tracker.d.ts +9 -16
  273. package/dist/turns/turn-tracker.js +162 -86
  274. package/dist/turns/types/transcript.types.d.ts +11 -1
  275. package/dist/turns/types/turn-provider.types.d.ts +33 -0
  276. package/dist/turns/types/turn-provider.types.js +1 -0
  277. package/dist/turns/types/turn-state.types.d.ts +9 -0
  278. package/dist/turns/types/turn-summary.types.d.ts +20 -6
  279. package/dist/turns/types/turn-tracker.types.d.ts +3 -1
  280. package/dist/turns/work-checkout.js +1 -2
  281. package/docs/AUDIT_PROMPT.md +10 -0
  282. package/docs/DATA_HANDLING.md +269 -32
  283. package/docs/ENTERPRISE_DEPLOYMENT.md +1 -1
  284. package/docs/PERFORMANCE.md +27 -0
  285. package/package.json +3 -2
  286. package/dist/events/canonical-event.d.ts +0 -10
  287. package/dist/events/canonical-event.js +0 -9
  288. package/dist/git/repository-root.d.ts +0 -39
  289. package/dist/git/repository-root.js +0 -131
  290. package/dist/git/types/repository-root.types.d.ts +0 -11
  291. package/dist/transport/transport.d.ts +0 -6
  292. package/dist/turns/codex-originator.d.ts +0 -11
  293. package/dist/turns/cursor-transcript.d.ts +0 -21
  294. package/dist/turns/cursor-transcript.js +0 -66
  295. package/dist/turns/native-session-titles.d.ts +0 -26
  296. package/dist/turns/native-session-titles.js +0 -102
  297. /package/dist/{git/types/repository-root.types.js → billing/types/billing.types.js} +0 -0
  298. /package/dist/{transport/transport.js → capture/types/capture.types.js} +0 -0
@@ -1,13 +1,28 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
- import { asRecord, compact } from '../core/object.js';
3
+ import { asRecord, compact, firstStringOf } from '../core/object.js';
4
4
  import { sha256Hex } from '../events/event-id.js';
5
5
  import { MAX_TICKET_KEYS } from '../feature/constants/feature.constants.js';
6
6
  import { writeFileAtomic } from '../storage/atomic-file.js';
7
7
  import { readJsonFile } from '../storage/json-file.js';
8
8
  import { SECRET_FILE_MODE, SWEEP_MARKER_FILE } from '../storage/constants/storage.constants.js';
9
9
  import { claimSweep } from '../storage/sweep-marker.js';
10
- import { AGENT_PIDS_DIR, AGENT_PROCESS_FILE, BILLING_SENT_FILE, INHERITED_CHECKOUT_FILE, LIVENESS_IGNORED_FILES, PROMPT_TICKETS_FILE, RE_UNSAFE_NAME_CHARS, SESSION_DIR_HASH_LENGTH, SESSION_FILES, SESSION_MODEL_FILE, SESSION_START_FILE, SESSION_TITLE_FILE, TURN_RECORD_KINDS, TURN_STATE_SWEEP_INTERVAL_MS, UNTRACED_MARKER_PREFIX, USAGE_CLAIM_PREFIX, WORK_CHECKOUT_FILE } from './constants/turns.constants.js';
10
+ import { AGENT_PIDS_DIR, AGENT_PROCESS_FILE, BILLING_SENT_FILE, CLOSED_TURN_PREFIX, INHERITED_CHECKOUT_FILE, LIVENESS_IGNORED_FILES, PROMPT_TICKETS_FILE, RE_UNSAFE_NAME_CHARS, SESSION_DIR_HASH_LENGTH, SESSION_FILES, SESSION_MODEL_FILE, SESSION_MODE_FILE, SESSION_RESUME_FILES, SESSION_START_FILE, SESSION_TITLE_FILE, TURN_RECORD_KINDS, TURN_STATE_SWEEP_INTERVAL_MS, UNTRACED_MARKER_PREFIX, USAGE_CLAIM_PREFIX, WORK_CHECKOUT_FILE } from './constants/turns.constants.js';
11
+ /**
12
+ * The well-formed part of a session mode, from the start event's session or
13
+ * the memo read back: what is written and what is read pass the same check.
14
+ *
15
+ * @param value - Anything.
16
+ * @returns The mode, without the fields that are missing or malformed.
17
+ */
18
+ export function toSessionMode(value) {
19
+ const record = asRecord(value);
20
+ const isCloudAgent = record?.['isCloudAgent'];
21
+ return compact({
22
+ mode: firstStringOf(record?.['mode']),
23
+ isCloudAgent: typeof isCloudAgent === 'boolean' ? isCloudAgent : undefined
24
+ });
25
+ }
11
26
  /**
12
27
  * Per-session accumulator for turn summaries.
13
28
  *
@@ -68,6 +83,26 @@ export class TurnStateStore {
68
83
  async remove(files) {
69
84
  await Promise.all(files.map((file) => fs.rm(file, { force: true })));
70
85
  }
86
+ /**
87
+ * Mark a turn closed, so a call of it that completes later (a background
88
+ * subagent keeps the prompt id that launched it) is known to be late.
89
+ *
90
+ * @param sessionId - Provider session id.
91
+ * @param turnId - The turn that closed.
92
+ */
93
+ async markTurnClosed(sessionId, turnId) {
94
+ await writeFileAtomic(path.join(this.sessionDir(sessionId), `${CLOSED_TURN_PREFIX}${safeName(turnId)}`), '', SECRET_FILE_MODE);
95
+ }
96
+ /**
97
+ * Which turns of a session have closed.
98
+ *
99
+ * @param sessionId - Provider session id.
100
+ * @returns A test for a turn id; false for every id when nothing has closed.
101
+ */
102
+ async closedTurns(sessionId) {
103
+ const names = new Set(await readSessionDirSafely(this.sessionDir(sessionId)));
104
+ return (turnId) => names.has(`${CLOSED_TURN_PREFIX}${safeName(turnId)}`);
105
+ }
71
106
  /**
72
107
  * Record which transcript messages a closed turn has counted.
73
108
  *
@@ -164,6 +199,33 @@ export class TurnStateStore {
164
199
  return undefined;
165
200
  return model;
166
201
  }
202
+ /**
203
+ * Remember the mode the session started in, or forget a stale one.
204
+ *
205
+ * Written on the session's start only, and forgotten there when the start
206
+ * names none, for the reason `forgetModel` gives: `--resume` reuses the id.
207
+ *
208
+ * @param sessionId - Provider session id.
209
+ * @param mode - What the start named.
210
+ */
211
+ async rememberMode(sessionId, mode) {
212
+ const file = path.join(this.sessionDir(sessionId), SESSION_MODE_FILE);
213
+ if (Object.keys(mode).length === 0) {
214
+ await fs.rm(file, { force: true });
215
+ return;
216
+ }
217
+ await writeFileAtomic(file, JSON.stringify(mode), SECRET_FILE_MODE);
218
+ }
219
+ /**
220
+ * The mode the session started in, keeping only well-formed fields.
221
+ *
222
+ * @param sessionId - Provider session id.
223
+ * @returns The mode; empty when none was usably remembered.
224
+ */
225
+ async readMode(sessionId) {
226
+ const read = await readJsonFile(path.join(this.sessionDir(sessionId), SESSION_MODE_FILE));
227
+ return read.state === 'ok' ? toSessionMode(read.value) : {};
228
+ }
167
229
  /**
168
230
  * The names of a session's files, and nothing read: how a tool hook learns
169
231
  * which checkouts its turn already named, for the price of one `readdir`.
@@ -386,14 +448,16 @@ export class TurnStateStore {
386
448
  return keys.filter((key) => typeof key === 'string').slice(0, MAX_TICKET_KEYS);
387
449
  }
388
450
  /**
389
- * Drop a session's state at SessionEnd, all but its opening prompt's keys.
451
+ * Drop a session's state at SessionEnd, all but what a resume needs: the
452
+ * opening prompt's keys and the session mode (`SESSION_RESUME_FILES`).
390
453
  *
391
454
  * `--resume` reuses the session id, and without the memo the resumed
392
455
  * session's first prompt ("continue") would become its opening prompt and
393
- * claim it with no keys. The memo holds keys only, never prompt text, and the
394
- * expiry sweep removes it with the directory once it ages out — counted from
395
- * SessionEnd, not from the opening prompt, so a session that ran all day can
396
- * still be resumed the next morning.
456
+ * claim it with no keys. Cursor names its mode on sessionStart only, so a
457
+ * conversation continued without a new start still needs it. Neither holds
458
+ * prompt text, and the expiry sweep removes them with the directory once they
459
+ * age out — counted from SessionEnd, not from the opening prompt, so a session
460
+ * that ran all day can still be resumed the next morning.
397
461
  *
398
462
  * @param sessionId - Provider session id.
399
463
  */
@@ -405,13 +469,17 @@ export class TurnStateStore {
405
469
  await fs.rm(this.pidFile(pid), { force: true });
406
470
  const dir = this.sessionDir(sessionId);
407
471
  const names = await readSessionDir(dir);
408
- if (!names?.includes(PROMPT_TICKETS_FILE)) {
472
+ const kept = [];
473
+ const dropped = [];
474
+ for (const name of names ?? [])
475
+ (SESSION_RESUME_FILES.has(name) ? kept : dropped).push(name);
476
+ if (kept.length === 0) {
409
477
  await fs.rm(dir, { recursive: true, force: true });
410
478
  return;
411
479
  }
412
- await Promise.all(names.filter((name) => name !== PROMPT_TICKETS_FILE).map((name) => fs.rm(path.join(dir, name), { recursive: true, force: true })));
480
+ await Promise.all(dropped.map((name) => fs.rm(path.join(dir, name), { recursive: true, force: true })));
413
481
  const now = new Date();
414
- await fs.utimes(path.join(dir, PROMPT_TICKETS_FILE), now, now).catch(() => undefined);
482
+ await Promise.all(kept.map((name) => fs.utimes(path.join(dir, name), now, now).catch(() => undefined)));
415
483
  }
416
484
  /**
417
485
  * Remove sessions whose newest record is older than `maxAgeMs`.
@@ -3,7 +3,8 @@ import { FAIL_OPEN_REASONS } from '../enforcement/constants/enforcement.constant
3
3
  import { deriveEventId, sha256Hex } from '../events/event-id.js';
4
4
  import { EVENT_SCHEMA_VERSION } from '../events/constants/events.constants.js';
5
5
  import { sanitizeText } from '../privacy/sanitizer.js';
6
- import { MAX_SESSION_TITLE_LENGTH, MAX_TURN_FILES, MAX_TURN_TOOL_INPUTS, PROVIDER_LABELS, UNKNOWN_TOOL_NAME } from './constants/turns.constants.js';
6
+ import { CANONICAL_PROVIDER_NAMES } from '../otlp/constants/otlp.constants.js';
7
+ import { MAX_SESSION_TITLE_LENGTH, MAX_TURN_FILES, MAX_TURN_TOOL_INPUTS, UNKNOWN_TOOL_NAME } from './constants/turns.constants.js';
7
8
  /**
8
9
  * Flatten one turn's accumulated state into the single product record the hook
9
10
  * path emits.
@@ -20,7 +21,7 @@ export function buildTurnSummary(input) {
20
21
  const startedAt = input.prompts[0]?.at;
21
22
  const turnId = input.turnId ?? input.prompts.find((prompt) => prompt.turnId)?.turnId;
22
23
  const jiraIds = ticketValues(input.featureCandidates);
23
- const provider = PROVIDER_LABELS[input.provider] ?? input.provider;
24
+ const provider = CANONICAL_PROVIDER_NAMES[input.provider] ?? input.provider;
24
25
  return compact({
25
26
  schemaVersion: EVENT_SCHEMA_VERSION,
26
27
  id: deriveEventId({
@@ -42,29 +43,32 @@ export function buildTurnSummary(input) {
42
43
  turn_id: turnId,
43
44
  developer_id: input.developerId,
44
45
  developer_name: input.developerName,
46
+ account_email: input.accountEmail,
47
+ session_mode: input.sessionMode?.mode,
48
+ is_cloud_agent: input.sessionMode?.isCloudAgent,
45
49
  repository: input.git?.repository,
46
50
  branch: input.git?.branch,
47
51
  commit: input.git?.commit,
48
52
  jira_ids: jiraIds.length > 0 ? jiraIds : undefined,
49
- prompt_jira_ids: input.promptJiraIds?.length ? input.promptJiraIds : undefined,
53
+ // Only the first is read (bridge-live), so only the first is sent.
54
+ prompt_jira_ids: input.promptJiraIds?.length ? input.promptJiraIds.slice(0, 1) : undefined,
50
55
  files_changed: input.git?.changedFiles,
51
56
  work_evidence: input.git?.repository ? input.workEvidence : undefined,
52
57
  parent_session_id: input.parentSessionId,
53
- content_hashes: input.contentHashes?.length ? input.contentHashes : undefined,
58
+ content_hashes: input.contentHashes?.length ? input.contentHashes.map(({ blob_sha }) => ({ blob_sha })) : undefined,
54
59
  manifest_repository: input.manifestRepository,
55
60
  files_touched: files.filesTouched.length > 0 ? files.filesTouched : undefined,
56
61
  files_read: files.filesRead.length > 0 ? files.filesRead : undefined,
57
62
  external_files_touched: files.externalTouched.length > 0 ? files.externalTouched : undefined,
58
63
  external_files_read: files.externalRead.length > 0 ? files.externalRead : undefined,
59
- prompt_evidence: input.prompts[0]?.evidence,
60
64
  prompt_text: input.prompts[0]?.text,
61
65
  session_name: boundSessionTitle(input.sessionTitles?.custom),
62
66
  session_title: boundSessionTitle(input.sessionTitles?.generated),
63
67
  tool_inputs: files.toolInputs.length > 0 ? files.toolInputs : undefined,
64
- response_evidence: input.response,
65
68
  tool_calls: input.tools.length,
66
69
  tools_used: files.toolsUsed,
67
70
  tool_events: input.toolEvents?.length ? input.toolEvents : undefined,
71
+ command: input.command,
68
72
  model: input.usage?.model ?? input.model,
69
73
  // 'unknown' is the absence of a verdict, not a billing mode.
70
74
  billing_mode: input.billingMode && input.billingMode !== 'unknown' ? input.billingMode : undefined,
@@ -1,33 +1,26 @@
1
1
  import type { Env } from '../core/types/core.types.js';
2
- import type { TurnSummaryEvent } from './types/turn-summary.types.js';
2
+ import type { TurnProvider } from './types/turn-provider.types.js';
3
3
  import type { TrackTurnOptions, TurnOutcome } from './types/turn-tracker.types.js';
4
4
  export type { TrackTurnOptions, TurnOutcome } from './types/turn-tracker.types.js';
5
5
  /**
6
6
  * Accumulate turn state across hook invocations and close the turn on
7
- * `generation.completed`, producing one flat summary.
7
+ * `generation.completed`, producing one flat summary, with the local root of
8
+ * the checkout the summary reported beside it: the pipeline takes the
9
+ * repository snapshot there. The root never goes on the summary.
8
10
  *
9
11
  * Best-effort by design: hooks run inside the coding agent, so every failure
10
12
  * path here ends in "no summary" or a degraded one, never in a thrown error.
11
13
  *
12
14
  * @param options - The payload's events, config, paths and clock.
13
- * @returns The turn summary when this payload closed a turn.
14
- */
15
- export declare function trackTurn(options: TrackTurnOptions): Promise<TurnSummaryEvent | undefined>;
16
- /**
17
- * {@link trackTurn}, with the local root of the checkout the summary reported
18
- * beside it: the pipeline takes the repository snapshot there. The root never
19
- * goes on the summary.
20
- *
21
- * @param options - The payload's events, config, paths and clock.
22
15
  * @returns The summary when this payload closed a turn, and its checkout's root.
23
16
  */
24
17
  export declare function trackTurnOutcome(options: TrackTurnOptions): Promise<TurnOutcome>;
25
18
  /**
26
- * Which surface the turn happened on.
19
+ * Which surface the turn happened on, as the agent says, else the default.
27
20
  *
28
- * @param provider - Internal provider id.
29
- * @param env - Environment; Claude Code reports its own entrypoint there.
30
- * @param rawPayload - Hook payload; Codex only names its originator in the transcript it points at.
21
+ * @param provider - The agent the hook came from.
22
+ * @param env - The hook's environment.
23
+ * @param rawPayload - Hook payload.
31
24
  * @returns The surface label.
32
25
  */
33
- export declare function resolveSurface(provider: string, env: Env, rawPayload?: unknown): Promise<string>;
26
+ export declare function resolveSurface(provider: TurnProvider, env: Env, rawPayload: unknown): Promise<string>;