@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
@@ -2,7 +2,7 @@ import path from 'node:path';
2
2
  import { pollUntil } from '../core/async.js';
3
3
  import { debugLog } from '../core/logger.js';
4
4
  import { asRecord, compact } from '../core/object.js';
5
- import { detectBillingMode } from '../billing/billing-mode.js';
5
+ import { billingModeOf } from '../billing/billing-mode.js';
6
6
  import { sha256Hex } from '../events/event-id.js';
7
7
  import { REPOSITORY_PATH_METADATA_KEY } from '../events/constants/enrich.constants.js';
8
8
  import { codeStateAt } from '../git/code-state.js';
@@ -10,53 +10,25 @@ import { developerDisplayName, developerIdentity } from '../git/git-context.js';
10
10
  import { CHECK_MIN_DURATION_MS } from '../privacy/constants/command-fingerprint.constants.js';
11
11
  import { sanitizeValue } from '../privacy/sanitizer.js';
12
12
  import { acquireLock } from '../storage/lock.js';
13
- import { inheritedRootConfig } from '../config/root-config.js';
13
+ import { inheritedRootConfig, servesMultipleIdentities } from '../config/root-config.js';
14
14
  import { MAX_WORK_CHANGED_FILES } from '../git/constants/git.constants.js';
15
- import { readClaudeSessionTitles, readTurnUsage } from './claude-transcript.js';
16
- import { isCodexExecTranscript } from './codex-originator.js';
17
- import { readCodexTurnUsage } from './codex-transcript.js';
18
- import { readCursorTurnUsage } from './cursor-transcript.js';
19
- import { readGeminiTurnUsage } from './gemini-transcript.js';
20
- import { readCodexSessionTitles, readCursorSessionTitles } from './native-session-titles.js';
21
- import { CLAUDE_ENTRYPOINT_VAR, PARENT_SESSION_VAR, RE_PARENT_SESSION_ID, DEFAULT_SURFACE, EXTERNAL_PATH_KEY, FILE_PATH_KEY, IDE_SURFACE, IDE_SURFACE_PROVIDERS, LOCK_KEY_HASH_LENGTH, MAX_PROMPT_TEXT_LENGTH, MAX_TOOL_INPUT_LENGTH, PROMPT_EVIDENCE_KEY, PROMPT_JIRA_IDS_KEY, PROMPT_TEXT_KEY, RESPONSE_EVIDENCE_KEY, INT32_MAX, INT32_MIN, RE_SHA256_HEX, TOOL_CALL_KEY, TOOL_COMPLETION_TYPES, TOOL_START_TYPES, EXEC_SURFACE, TRANSCRIPT_PATH_KEY, TURN_STATE_TTL_MS, USAGE_LOCK_POLL_MS, USAGE_LOCK_WAIT_MS, USAGE_RETRY } from './constants/turns.constants.js';
15
+ import { PARENT_SESSION_VAR, RE_PARENT_SESSION_ID, CLOUD_SURFACE, DEFAULT_SURFACE, EXTERNAL_PATH_KEY, FILE_PATH_KEY, LOCK_KEY_HASH_LENGTH, MAX_PROMPT_TEXT_LENGTH, MAX_TOOL_INPUT_LENGTH, PROMPT_EVIDENCE_KEY, PROMPT_JIRA_IDS_KEY, PROMPT_TEXT_KEY, RESPONSE_EVIDENCE_KEY, INT32_MAX, INT32_MIN, RE_SHA256_HEX, TOOL_CALL_KEY, TOOL_COMPLETION_TYPES, TOOL_START_TYPES, TRANSCRIPT_PATH_KEY, TURN_STATE_TTL_MS, USAGE_LOCK_POLL_MS, USAGE_LOCK_WAIT_MS, USAGE_RETRY } from './constants/turns.constants.js';
22
16
  import { resolveFileIdentity } from './file-identity.js';
23
- import { TurnStateStore } from './turn-state.js';
24
- import { buildToolEvents } from './tool-events.js';
17
+ import { toSessionMode, TurnStateStore } from './turn-state.js';
18
+ import { buildToolEvents, callKey } from './tool-events.js';
25
19
  import { buildTurnSummary } from './turn-summary.js';
26
20
  import { rememberInheritance, retryInheritance } from './inherited-checkout.js';
27
21
  import { recordCheckouts, resolveWorkCheckout } from './work-checkout.js';
28
- /**
29
- * Providers whose transcript can be read for token usage.
30
- *
31
- * Claude, Codex and Gemini window by row timestamps; Cursor rows carry none, so its reader
32
- * relies solely on the exactly-once message-id ledger (today Cursor rows also
33
- * carry no usage — the reader returns undefined and the summary stays pending).
34
- */
35
- const TRANSCRIPT_READERS = {
36
- claude: (transcriptPath, startedAt, untilIso, excludeMessageIds) => readTurnUsage(transcriptPath, startedAt, USAGE_RETRY, untilIso, excludeMessageIds),
37
- codex: (transcriptPath, startedAt, untilIso, excludeMessageIds) => readCodexTurnUsage(transcriptPath, startedAt, USAGE_RETRY, untilIso, excludeMessageIds),
38
- gemini: (transcriptPath, startedAt, untilIso, excludeMessageIds) => readGeminiTurnUsage(transcriptPath, startedAt, USAGE_RETRY, untilIso, excludeMessageIds),
39
- cursor: (transcriptPath, _startedAt, _untilIso, excludeMessageIds) => readCursorTurnUsage(transcriptPath, USAGE_RETRY, excludeMessageIds)
40
- };
41
22
  /**
42
23
  * Accumulate turn state across hook invocations and close the turn on
43
- * `generation.completed`, producing one flat summary.
24
+ * `generation.completed`, producing one flat summary, with the local root of
25
+ * the checkout the summary reported beside it: the pipeline takes the
26
+ * repository snapshot there. The root never goes on the summary.
44
27
  *
45
28
  * Best-effort by design: hooks run inside the coding agent, so every failure
46
29
  * path here ends in "no summary" or a degraded one, never in a thrown error.
47
30
  *
48
31
  * @param options - The payload's events, config, paths and clock.
49
- * @returns The turn summary when this payload closed a turn.
50
- */
51
- export async function trackTurn(options) {
52
- return (await trackTurnOutcome(options)).summary;
53
- }
54
- /**
55
- * {@link trackTurn}, with the local root of the checkout the summary reported
56
- * beside it: the pipeline takes the repository snapshot there. The root never
57
- * goes on the summary.
58
- *
59
- * @param options - The payload's events, config, paths and clock.
60
32
  * @returns The summary when this payload closed a turn, and its checkout's root.
61
33
  */
62
34
  export async function trackTurnOutcome(options) {
@@ -109,7 +81,7 @@ async function processEvent(store, sessionId, event, options) {
109
81
  // `generation.completed` would degrade the turn to a fallback summary, and one
110
82
  // on `session.ended` would leave a session's raw prompt text undeleted.
111
83
  if (type === 'session.started')
112
- await rememberModelSafely(store, sessionId, event);
84
+ await Promise.all([rememberModelSafely(store, sessionId, event), rememberModeSafely(store, sessionId, event, options.provider)]);
113
85
  // The first hook walks; a later one walks again only when the deadline cut
114
86
  // the last walk, so a busy first hook does not cost the whole session. Not
115
87
  // at the session's end, which clears the answer straight after.
@@ -160,6 +132,54 @@ async function rememberModelSafely(store, sessionId, event) {
160
132
  debugLog('could not record the session model:', error);
161
133
  }
162
134
  }
135
+ /**
136
+ * Remember the mode the session started in, or carry on without it.
137
+ *
138
+ * Cursor names its composer mode and background flag on sessionStart alone;
139
+ * a memo that cannot be written only costs the summaries those two fields.
140
+ *
141
+ * @param store - Per-session state store.
142
+ * @param sessionId - Provider session id.
143
+ * @param event - The session's own event.
144
+ * @param provider - The agent the hook came from.
145
+ */
146
+ async function rememberModeSafely(store, sessionId, event, provider) {
147
+ // A provider that names no mode does not pay for the memo.
148
+ if (provider.namesSessionMode !== true)
149
+ return;
150
+ try {
151
+ await store.rememberMode(sessionId, toSessionMode(event.session));
152
+ }
153
+ catch (error) {
154
+ debugLog('could not record the session mode:', error);
155
+ }
156
+ }
157
+ /**
158
+ * The mode the session started in, for a provider that names one.
159
+ *
160
+ * @param store - Per-session state store.
161
+ * @param sessionId - Provider session id.
162
+ * @param provider - The agent the hook came from.
163
+ * @returns The mode, possibly empty.
164
+ */
165
+ async function readMode(store, sessionId, provider) {
166
+ return provider.namesSessionMode === true ? store.readMode(sessionId) : {};
167
+ }
168
+ /**
169
+ * The agent account's email the closing hook named, unless this machine serves
170
+ * more than one tenant.
171
+ *
172
+ * The address is the agent's login for the whole machine, while `developer_id`
173
+ * is chosen per root: with two identities configured, one tenant's turn could
174
+ * carry the address another tenant knows the developer by, so it is withheld.
175
+ *
176
+ * @param stopEvent - The closing event.
177
+ * @param options - Tracker options, for the machine's global config.
178
+ * @returns The address, or undefined.
179
+ */
180
+ function accountEmailOf(stopEvent, options) {
181
+ return servesMultipleIdentities(options.globalConfig.config) ? undefined : stopEvent.developer?.accountEmail;
182
+ }
163
183
  /**
164
184
  * Remember the folder the session started in, or carry on without it.
165
185
  *
@@ -236,7 +256,7 @@ async function recordCheckoutsSafely(store, sessionId, event, options) {
236
256
  function recordFor(event, cwd, failOpenReason, git) {
237
257
  const type = event.event.type;
238
258
  if (type === 'prompt.submitted')
239
- return promptRecord(event, failOpenReason);
259
+ return promptRecord(event, failOpenReason, git);
240
260
  if (TOOL_COMPLETION_TYPES.has(type))
241
261
  return toolRecord(event, cwd, git);
242
262
  // A start is kept only to date its completion in `tool_events`, which ride
@@ -290,10 +310,14 @@ async function closeTurn(store, sessionId, stopEvent, options) {
290
310
  const release = await acquireLock(options.locksDir, `turn-close-${lockKey}`, options.env.now);
291
311
  if (!release)
292
312
  return undefined;
313
+ // Late tool records (AWT-701) are the session's, not the turn's: one close at
314
+ // a time takes them, and one that finds them taken sends none.
315
+ const releaseLate = await acquireLock(options.locksDir, `turn-late-${sha256Hex(sessionId).slice(0, LOCK_KEY_HASH_LENGTH)}`, options.env.now);
293
316
  try {
294
- return await closeTurnLocked(store, sessionId, stopEvent, options);
317
+ return await closeTurnLocked(store, sessionId, stopEvent, options, false, releaseLate !== undefined);
295
318
  }
296
319
  finally {
320
+ await releaseLate?.();
297
321
  await release();
298
322
  }
299
323
  }
@@ -309,9 +333,10 @@ async function closeTurn(store, sessionId, stopEvent, options) {
309
333
  * @param stopEvent - The closing event.
310
334
  * @param options - Tracking options.
311
335
  * @param readOnly - Preview only: consume and claim nothing.
336
+ * @param takeLate - The caller holds the session's late-records lock.
312
337
  * @returns The summary and its checkout's root, or undefined when there is nothing to summarize.
313
338
  */
314
- async function closeTurnLocked(store, sessionId, stopEvent, options, readOnly = false) {
339
+ async function closeTurnLocked(store, sessionId, stopEvent, options, readOnly = false, takeLate = false) {
315
340
  const stopTurnId = stopEvent.session.turnId;
316
341
  // Consume only this prompt's records: a racing next prompt keeps its state
317
342
  // for its own Stop. Records without a turn id are legacy and belong to any
@@ -324,16 +349,22 @@ async function closeTurnLocked(store, sessionId, stopEvent, options, readOnly =
324
349
  return undefined;
325
350
  const window = resolveWindow(all, firstPass, stopEvent.timestamp);
326
351
  const usage = await resolveAndClaimUsage(store, sessionId, stopEvent, options, window, readOnly);
327
- const billingMode = await detectBillingMode(options.agentId, options.env);
352
+ const billingMode = await billingModeOf(options.provider, options.env);
328
353
  // Re-collect after the settle wait: a tool completion that landed while we
329
354
  // watched the transcript still belongs to this turn.
330
- const mine = filterTurn(await store.collectEntries(sessionId), stopTurnId);
355
+ const collected = await store.collectEntries(sessionId);
356
+ const mine = filterTurn(collected, stopTurnId);
357
+ const late = takeLate ? lateToolEntries(collected, stopTurnId, await store.closedTurns(sessionId)) : [];
331
358
  const records = mine.map((entry) => entry.record);
332
359
  // Which checkout this turn worked in is answerable only here, where every
333
360
  // checkout it named and every tool call it made are in hand — and this is the
334
361
  // one hook that may pay for a batch of git processes.
335
362
  // Alongside the session's opening prompt keys, not this turn's: later prompts never move them.
336
- const [work, promptJiraIds] = await Promise.all([resolveWorkCheckout(store, sessionId, records, stopEvent, options), store.readPromptTickets(sessionId)]);
363
+ const [work, promptJiraIds, sessionMode] = await Promise.all([
364
+ resolveWorkCheckout(store, sessionId, records, stopEvent, options),
365
+ store.readPromptTickets(sessionId),
366
+ readMode(store, sessionId, options.provider)
367
+ ]);
337
368
  // Usage is mirrored onto a *copy* of the Stop event: the summary's model
338
369
  // should come from the transcript when the transcript knows better, and
339
370
  // rewriting an event another stage may still be reading is not an option.
@@ -360,12 +391,14 @@ async function closeTurnLocked(store, sessionId, stopEvent, options, readOnly =
360
391
  ...fileIdentity,
361
392
  sessionTitles,
362
393
  provider: stopEvent.agent.provider,
363
- surface: await resolveSurface(stopEvent.agent.provider, options.env, options.rawPayload),
394
+ surface: await turnSurface(options, sessionMode),
364
395
  sessionId,
365
396
  turnId: stopTurnId,
366
397
  developerId,
367
398
  developerName,
368
399
  installationId: identity.installationId,
400
+ accountEmail: accountEmailOf(stopEvent, options),
401
+ sessionMode,
369
402
  git: work.git,
370
403
  featureCandidates: work.featureCandidates,
371
404
  promptJiraIds,
@@ -374,16 +407,21 @@ async function closeTurnLocked(store, sessionId, stopEvent, options, readOnly =
374
407
  prompts: recordsOfKind(records, 'prompt'),
375
408
  tools: work.tools,
376
409
  // Withheld whole with `capture.git` off: digests, times, status and the check flag go together.
377
- toolEvents: (work.capture ?? options.config.capture).git === false ? undefined : buildToolEvents(records),
410
+ toolEvents: (work.capture ?? options.config.capture).git === false ? undefined : buildToolEvents([...late.map((entry) => entry.record), ...records]),
411
+ // The same gate, for the slash command the turn opened with (AWT-711).
412
+ command: (work.capture ?? options.config.capture).git === false ? undefined : recordsOfKind(records, 'prompt')[0]?.command,
378
413
  response: resolveResponse(stopEvent, records),
379
414
  usage,
380
415
  model: resolvedStop.ai?.model,
381
416
  billingMode,
382
417
  endedAt: stopEvent.timestamp
383
418
  });
384
- // Consume exactly what went into the summary; other prompts' records stay.
419
+ // Consume exactly what went into the summary; other prompts' records stay,
420
+ // and so does a start still waiting for its completion, which dates it.
385
421
  if (!readOnly)
386
- await store.remove(mine.map((entry) => entry.file));
422
+ await store.remove(consumable([...mine, ...late], collected).map((entry) => entry.file));
423
+ if (!readOnly && stopTurnId !== undefined)
424
+ await store.markTurnClosed(sessionId, stopTurnId);
387
425
  // The next turn that changes nothing carries this one; the prompt gate asks it too.
388
426
  if (!readOnly && work.evidence === 'changed' && work.root && work.git?.repository) {
389
427
  // After the records are consumed, so a failure here must not cost the summary.
@@ -431,9 +469,10 @@ async function fallbackSummary(store, sessionId, stopEvent, options) {
431
469
  // The same resolvers the healthy close uses, and resolved together for the
432
470
  // same reason: on a machine that names its developer through git alone,
433
471
  // reading the config verbatim here would ship a turn attributed to nobody.
434
- const [developerId, developerName] = await Promise.all([
472
+ const [developerId, developerName, sessionMode] = await Promise.all([
435
473
  developerIdentity(options.config.developerEmail, options.cwd, { home: options.env.home }),
436
- developerDisplayName(options.config.developerName, options.cwd, { home: options.env.home })
474
+ developerDisplayName(options.config.developerName, options.cwd, { home: options.env.home }),
475
+ readMode(store, sessionId, options.provider)
437
476
  ]);
438
477
  // Caught on its own, as on the healthy close: a throw here must not cost the thin record.
439
478
  const fileIdentity = await resolveFileIdentity(store, sessionId, [], stopEvent, options).catch((error) => {
@@ -443,12 +482,14 @@ async function fallbackSummary(store, sessionId, stopEvent, options) {
443
482
  const summary = buildTurnSummary({
444
483
  ...fileIdentity,
445
484
  provider: stopEvent.agent.provider,
446
- surface: await resolveSurface(stopEvent.agent.provider, options.env, options.rawPayload),
485
+ surface: await turnSurface(options, sessionMode),
447
486
  sessionId,
448
487
  turnId: stopEvent.session.turnId,
449
488
  developerId,
450
489
  developerName,
451
490
  installationId: options.config.installationId,
491
+ accountEmail: accountEmailOf(stopEvent, options),
492
+ sessionMode,
452
493
  git: stopEvent.git,
453
494
  featureCandidates: stopEvent.feature?.candidates,
454
495
  // A memo, not turn state: still readable when the records were not.
@@ -516,7 +557,7 @@ function resolveWindow(all, mine, stopAt) {
516
557
  * @returns The usage, or undefined when none could be claimed.
517
558
  */
518
559
  async function resolveAndClaimUsage(store, sessionId, stopEvent, options, window, readOnly) {
519
- if (!TRANSCRIPT_READERS[options.agentId] || window.startedAt === undefined)
560
+ if (!options.provider.readTurnUsage || window.startedAt === undefined)
520
561
  return undefined;
521
562
  if (readOnly) {
522
563
  return readTranscriptUsage(options, window, await store.claimedMessageIds(sessionId));
@@ -560,20 +601,20 @@ function waitForUsageLock(options, lockName) {
560
601
  * @returns The usage, or undefined when the provider reports none.
561
602
  */
562
603
  async function readTranscriptUsage(options, window, excludeMessageIds) {
563
- const reader = TRANSCRIPT_READERS[options.agentId];
604
+ const reader = options.provider.readTurnUsage;
564
605
  const transcriptPath = asRecord(options.rawPayload)?.[TRANSCRIPT_PATH_KEY];
565
606
  if (!reader || window.startedAt === undefined || typeof transcriptPath !== 'string')
566
607
  return undefined;
567
- return reader(transcriptPath, window.startedAt, window.untilIso, excludeMessageIds);
608
+ return reader(transcriptPath, window.startedAt, USAGE_RETRY, window.untilIso, excludeMessageIds);
568
609
  }
569
610
  /**
570
611
  * The session's name and generated title, when the config lets them leave the machine.
571
612
  *
572
613
  * Read only under `capture.sessionTitle`, so with it off the transcript is not
573
- * even looked at for one. Claude Code alone names its sessions in its
574
- * transcript. Codex and Cursor keep them in local read-model databases. The
575
- * other agents send none, and nothing is derived from the prompt. Claude's
576
- * last title of each kind is remembered, each on its own, for a turn whose
614
+ * even looked at for one. The provider reads them, out of its own local store
615
+ * (`readSessionTitles`) or its transcript tail (`readTranscriptTitles`). The
616
+ * other agents send none, and nothing is derived from the prompt. A transcript
617
+ * title of each kind is remembered, each on its own, for a turn whose
577
618
  * tail no longer reaches one. A failure costs the titles, never the summary.
578
619
  *
579
620
  * ponytail: a second tail read after the usage one, rather than threading the
@@ -589,15 +630,14 @@ async function readTranscriptUsage(options, window, excludeMessageIds) {
589
630
  async function resolveSessionTitles(store, sessionId, options, readOnly) {
590
631
  if (options.config.capture.sessionTitle !== true)
591
632
  return {};
592
- if (options.agentId === 'codex')
593
- return safeNativeTitles(() => readCodexSessionTitles(options.env, sessionId));
594
- if (options.agentId === 'cursor')
595
- return safeNativeTitles(() => readCursorSessionTitles(options.env, sessionId));
633
+ const { readSessionTitles, readTranscriptTitles } = options.provider;
634
+ if (readSessionTitles)
635
+ return safeNativeTitles(() => readSessionTitles(options.env, sessionId));
596
636
  const transcriptPath = asRecord(options.rawPayload)?.[TRANSCRIPT_PATH_KEY];
597
- if (options.agentId !== 'claude' || typeof transcriptPath !== 'string')
637
+ if (!readTranscriptTitles || typeof transcriptPath !== 'string')
598
638
  return {};
599
639
  try {
600
- const [seen, remembered] = await Promise.all([readClaudeSessionTitles(transcriptPath), store.readSessionTitles(sessionId)]);
640
+ const [seen, remembered] = await Promise.all([readTranscriptTitles(transcriptPath), store.readSessionTitles(sessionId)]);
601
641
  const titles = compact({ custom: seen.custom ?? remembered.custom, generated: seen.generated ?? remembered.generated });
602
642
  // Its own catch: a memo that fails to write must not cost this turn's title.
603
643
  if (!readOnly && (titles.custom !== remembered.custom || titles.generated !== remembered.generated)) {
@@ -642,6 +682,34 @@ function recordsOfKind(records, kind) {
642
682
  function filterTurn(entries, stopTurnId) {
643
683
  return entries.filter(({ record }) => stopTurnId === undefined || record.turnId === undefined || record.turnId === stopTurnId);
644
684
  }
685
+ /**
686
+ * Tool records of turns that already closed (AWT-701), for this close's
687
+ * `tool_events` and nothing else of its summary. A background subagent keeps
688
+ * the prompt id of the turn that launched it, so its calls complete after that
689
+ * turn's Stop. The caller holds the session's late-records lock.
690
+ *
691
+ * @param entries - Every entry of the session.
692
+ * @param stopTurnId - Turn id of the closing event, when it has one.
693
+ * @param closed - Whether a turn id has closed.
694
+ * @returns The tool starts and completions of closed turns.
695
+ */
696
+ function lateToolEntries(entries, stopTurnId, closed) {
697
+ if (stopTurnId === undefined)
698
+ return [];
699
+ return entries.filter(({ record }) => (record.kind === 'tool' || record.kind === 'tool-start') && record.turnId !== undefined && record.turnId !== stopTurnId && closed(record.turnId));
700
+ }
701
+ /**
702
+ * The entries a close may delete: all but a start whose completion has not
703
+ * landed, which a later close needs to date that call.
704
+ *
705
+ * @param entries - The entries the close read.
706
+ * @param collected - Every entry of the session.
707
+ * @returns The entries to remove.
708
+ */
709
+ function consumable(entries, collected) {
710
+ const completed = new Set(collected.flatMap(({ record }) => (record.kind === 'tool' && record.pairingKey !== undefined ? [callKey(record.turnId, record.pairingKey)] : [])));
711
+ return entries.filter(({ record }) => record.kind !== 'tool-start' || completed.has(callKey(record.turnId, record.pairingKey)));
712
+ }
645
713
  /**
646
714
  * The response the user saw.
647
715
  *
@@ -689,9 +757,10 @@ function withResolvedUsage(stopEvent, usage, billingMode) {
689
757
  *
690
758
  * @param event - The prompt event.
691
759
  * @param failOpenReason - Why it ran without an enforcement decision, if it did.
760
+ * @param git - Whether this hook's capture policy allows git context, which the command name rides as `tool_events` do.
692
761
  * @returns The record.
693
762
  */
694
- function promptRecord(event, failOpenReason) {
763
+ function promptRecord(event, failOpenReason, git) {
695
764
  const text = event.metadata?.[PROMPT_TEXT_KEY];
696
765
  return {
697
766
  kind: 'prompt',
@@ -700,7 +769,8 @@ function promptRecord(event, failOpenReason) {
700
769
  evidence: asEvidence(event.metadata?.[PROMPT_EVIDENCE_KEY]),
701
770
  // Enrichment already scrubbed the whole string; the bound comes after it.
702
771
  text: typeof text === 'string' && text ? text.slice(0, MAX_PROMPT_TEXT_LENGTH) : undefined,
703
- failOpenReason
772
+ failOpenReason,
773
+ command: git ? nonEmptyString(asRecord(event.metadata?.['provider'])?.['command']) : undefined
704
774
  };
705
775
  }
706
776
  /**
@@ -741,7 +811,8 @@ function toolRecord(event, cwd, git) {
741
811
  pairingKey: call.pairingKey,
742
812
  exitCode: call.exitCode,
743
813
  startedAt: startFromDuration(event.timestamp, event.tool?.durationMs),
744
- inputFp: call.inputFp
814
+ inputFp: call.inputFp,
815
+ skill: nonEmptyString(asRecord(event.metadata?.['provider'])?.['skill'])
745
816
  };
746
817
  }
747
818
  /**
@@ -948,28 +1019,33 @@ function declaredParent(env, sessionId) {
948
1019
  return parent;
949
1020
  }
950
1021
  /**
951
- * Which surface the turn happened on.
1022
+ * The surface a closing turn reports: a session the agent runs in its vendor's
1023
+ * cloud (e.g. a Cursor background agent) says so, whatever the hook process looks like.
952
1024
  *
953
- * @param provider - Internal provider id.
954
- * @param env - Environment; Claude Code reports its own entrypoint there.
955
- * @param rawPayload - Hook payload; Codex only names its originator in the transcript it points at.
1025
+ * @param options - Tracking options carrying the provider, env and payload.
1026
+ * @param sessionMode - The mode memo the session start left.
1027
+ * @returns The surface label.
1028
+ */
1029
+ async function turnSurface(options, sessionMode) {
1030
+ if (sessionMode.isCloudAgent === true)
1031
+ return CLOUD_SURFACE;
1032
+ return resolveSurface(options.provider, options.env, options.rawPayload);
1033
+ }
1034
+ /**
1035
+ * Which surface the turn happened on, as the agent says, else the default.
1036
+ *
1037
+ * @param provider - The agent the hook came from.
1038
+ * @param env - The hook's environment.
1039
+ * @param rawPayload - Hook payload.
956
1040
  * @returns The surface label.
957
1041
  */
958
1042
  export async function resolveSurface(provider, env, rawPayload) {
959
- if (provider === 'claude') {
960
- const entrypoint = env.vars[CLAUDE_ENTRYPOINT_VAR];
961
- if (entrypoint)
962
- return entrypoint;
963
- }
964
- if (provider === 'codex') {
965
- const transcriptPath = asRecord(rawPayload)?.[TRANSCRIPT_PATH_KEY];
966
- if (typeof transcriptPath === 'string' && (await isCodexExecTranscript(transcriptPath)))
967
- return EXEC_SURFACE;
968
- }
969
- // Cursor and Antigravity hooks fire from an editor agent. Cursor's
970
- // is_background_agent is only available on sessionStart, not on Stop, so v1
971
- // reports a single surface for them.
972
- if (IDE_SURFACE_PROVIDERS.has(provider))
973
- return IDE_SURFACE;
974
- return DEFAULT_SURFACE;
1043
+ try {
1044
+ return (await provider.surface?.(env, rawPayload)) ?? DEFAULT_SURFACE;
1045
+ }
1046
+ catch (error) {
1047
+ // A provider's own read failing costs the label, never the summary.
1048
+ debugLog('could not resolve the surface:', error);
1049
+ return DEFAULT_SURFACE;
1050
+ }
975
1051
  }
@@ -35,12 +35,22 @@ export interface ReadTurnUsageRetry {
35
35
  *
36
36
  * @param transcriptPath - Path the provider reported.
37
37
  * @param startedAt - ISO timestamp the turn began at.
38
+ * @param retry - How long to wait for the agent to flush the turn's last entry.
38
39
  * @param untilIso - Upper bound; entries after it belong to another turn.
39
40
  * @param excludeMessageIds - Messages another turn has already claimed.
40
41
  */
41
- export type TranscriptReader = (transcriptPath: string, startedAt: string, untilIso: string, excludeMessageIds: ReadonlySet<string>) => Promise<TurnUsage | undefined>;
42
+ export type TranscriptReader = (transcriptPath: string, startedAt: string, retry: ReadTurnUsageRetry, untilIso: string, excludeMessageIds: ReadonlySet<string>) => Promise<TurnUsage | undefined>;
42
43
  /** One assistant entry's usage, keyed by message id during accumulation. */
43
44
  export interface TranscriptUsageEntry {
44
45
  readonly model?: string;
45
46
  readonly usage: Readonly<Record<string, unknown>>;
46
47
  }
48
+ /** A transcript tail and the turn window to filter its lines by, both bounds in epoch ms. */
49
+ export interface WindowedTail {
50
+ /** The tail text. */
51
+ readonly raw: string;
52
+ /** Window lower bound. */
53
+ readonly since: number;
54
+ /** Window upper bound; positive infinity when there is none. */
55
+ readonly until: number;
56
+ }
@@ -0,0 +1,33 @@
1
+ import type { BillingSource } from '../../billing/types/billing.types.js';
2
+ import type { Env } from '../../core/types/core.types.js';
3
+ import type { SessionTitles, TranscriptReader } from './transcript.types.js';
4
+ /**
5
+ * What the turn tracker asks of the agent a hook came from.
6
+ *
7
+ * The tracker names no agent: each one says here what its turns can carry,
8
+ * and `AgentProvider` extends this, so the dependency runs from the providers
9
+ * to turns and never back. A field an agent leaves out means it has nothing to say.
10
+ */
11
+ export interface TurnProvider extends BillingSource {
12
+ readonly id: string;
13
+ /** Provisional usage out of the transcript the hook payload points at. */
14
+ readonly readTurnUsage?: TranscriptReader;
15
+ /**
16
+ * The session's titles out of the agent's own local store (Codex, Cursor),
17
+ * read only under `capture.sessionTitle`.
18
+ */
19
+ readonly readSessionTitles?: (env: Env, sessionId: string) => Promise<SessionTitles>;
20
+ /**
21
+ * The session's titles out of the transcript tail (Claude Code), read only
22
+ * under `capture.sessionTitle`. The tracker remembers the last of each kind
23
+ * for a turn whose tail no longer reaches one.
24
+ */
25
+ readonly readTranscriptTitles?: (transcriptPath: string) => Promise<SessionTitles>;
26
+ /**
27
+ * Where the turn ran (`cli`, `exec`, `ide`, or the agent's own entrypoint);
28
+ * undefined, or no function, reports `cli`.
29
+ */
30
+ readonly surface?: (env: Env, rawPayload: unknown) => Promise<string | undefined>;
31
+ /** The agent names a mode on session start, so the tracker keeps the session mode memo. */
32
+ readonly namesSessionMode?: boolean;
33
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -18,6 +18,8 @@ export interface PromptRecord {
18
18
  * the turn it happened on.
19
19
  */
20
20
  readonly failOpenReason?: FailOpenReason;
21
+ /** The slash command the prompt opened with, its name only; kept only under `capture.git` (AWT-711). */
22
+ readonly command?: string;
21
23
  }
22
24
  /** One tool call the agent completed. */
23
25
  export interface ToolRecord {
@@ -61,6 +63,8 @@ export interface ToolRecord {
61
63
  readonly commit?: string;
62
64
  /** Digest of the working tree at a check's completion. */
63
65
  readonly diffFp?: string;
66
+ /** The skill a skill call invoked, its name only (AWT-711). */
67
+ readonly skill?: string;
64
68
  }
65
69
  /**
66
70
  * A tool call starting, kept only to date its completion: no duration on the
@@ -126,6 +130,11 @@ export interface ResponseRecord {
126
130
  export interface SessionModelRecord {
127
131
  readonly model: string;
128
132
  }
133
+ /** The mode the agent named at session start; see `SESSION_MODE_FILE`. */
134
+ export interface SessionModeRecord {
135
+ readonly mode?: string;
136
+ readonly isCloudAgent?: boolean;
137
+ }
129
138
  /** Anything the accumulator persists between hook invocations. */
130
139
  export type TurnRecord = PromptRecord | ToolRecord | ToolStartRecord | ResponseRecord | CheckoutRecord;
131
140
  /** The session's last changed checkout, as `work-checkout.json` holds it. Local only. */
@@ -1,7 +1,7 @@
1
1
  import type { FailOpenReason } from '../../enforcement/types/enforcement.types.js';
2
2
  import type { AgentWatchEvent, ContentEvidence, EventGit, FeatureCandidate, UsageBillingMode } from '../../events/types/events.types.js';
3
3
  import type { ContentHash } from '../../git/types/git.types.js';
4
- import type { PromptRecord, ToolInputSummary, ToolRecord } from './turn-state.types.js';
4
+ import type { PromptRecord, SessionModeRecord, ToolInputSummary, ToolRecord } from './turn-state.types.js';
5
5
  import type { SessionTitles, TurnUsage } from './transcript.types.js';
6
6
  /**
7
7
  * Usage attributed to one agent inside a turn — the main agent, or one of the
@@ -55,11 +55,17 @@ export interface TurnSummaryEvent extends AgentWatchEvent<'turn.summary'> {
55
55
  readonly developer_id?: string;
56
56
  /** What to call this developer; the platform keeps its own if this is absent. */
57
57
  readonly developer_name?: string;
58
+ /** The email the agent's own account is signed in as (Cursor `user_email`); beside `developer_id`, never in its place. */
59
+ readonly account_email?: string;
60
+ /** The agent's mode when the session started (Cursor `composer_mode`: `agent`, `ask`, ...); named on the start only, so a later switch is not seen. */
61
+ readonly session_mode?: string;
62
+ /** Whether the agent ran the session in the vendor's cloud (Cursor `is_background_agent`). */
63
+ readonly is_cloud_agent?: boolean;
58
64
  readonly repository?: string;
59
65
  readonly branch?: string;
60
66
  readonly commit?: string;
61
67
  readonly jira_ids?: readonly string[];
62
- /** Ticket keys the session's opening prompt named, in order; the same on every turn of the session. Under `capture.git`. */
68
+ /** The first ticket key the session's opening prompt named; the same on every turn of the session. Under `capture.git`. At most one. */
63
69
  readonly prompt_jira_ids?: readonly string[];
64
70
  /** The files this turn changed in its checkout: its edits, its commits' files, its new dirt. */
65
71
  readonly files_changed?: readonly string[];
@@ -67,8 +73,8 @@ export interface TurnSummaryEvent extends AgentWatchEvent<'turn.summary'> {
67
73
  readonly work_evidence?: WorkEvidence;
68
74
  /** The session id of the agent that started this one: declared by its launcher, or the live parent an `inherited` checkout came from. */
69
75
  readonly parent_session_id?: string;
70
- /** One-way content ids of files the turn's tools named, in a folder with no git; under `capture.files`. */
71
- readonly content_hashes?: readonly ContentHash[];
76
+ /** One-way content ids (git blob ids) of files the turn's tools named, in a folder with no git, without their paths; under `capture.files`. */
77
+ readonly content_hashes?: readonly Pick<ContentHash, 'blob_sha'>[];
72
78
  /** The repository address the nearest project manifest names, cleaned like a git remote; under `capture.files`. */
73
79
  readonly manifest_repository?: string;
74
80
  /** Files edited by the agent's tools during this turn (repo-relative). */
@@ -79,7 +85,6 @@ export interface TurnSummaryEvent extends AgentWatchEvent<'turn.summary'> {
79
85
  readonly external_files_touched?: readonly string[];
80
86
  /** Files outside every checkout the turn's tools only read, home-relative. */
81
87
  readonly external_files_read?: readonly string[];
82
- readonly prompt_evidence?: ContentEvidence;
83
88
  /** The turn's first prompt, harness blocks removed, scrubbed, bounded; under `capture.promptText`. */
84
89
  readonly prompt_text?: string;
85
90
  /** The session's latest name, scrubbed then cut to 200; under `capture.sessionTitle`; when the provider exposes one. */
@@ -88,11 +93,12 @@ export interface TurnSummaryEvent extends AgentWatchEvent<'turn.summary'> {
88
93
  readonly session_title?: string;
89
94
  /** The turn's shell commands and connector calls, bounded; under `capture.toolInput`. */
90
95
  readonly tool_inputs?: readonly ToolInputSummary[];
91
- readonly response_evidence?: ContentEvidence;
92
96
  readonly tool_calls: number;
93
97
  readonly tools_used: Readonly<Record<string, number>>;
94
98
  /** The turn's first 200 tool calls in call order, content-free; under `capture.git` (AWT-675). */
95
99
  readonly tool_events?: readonly ToolEvent[];
100
+ /** The slash command the turn's first prompt opened with, name only, no slash or arguments; under `capture.git` (AWT-711). */
101
+ readonly command?: string;
96
102
  readonly model?: string;
97
103
  /** subscription (flat plan) vs api (per-token billing); see billing-mode.ts. */
98
104
  readonly billing_mode?: UsageBillingMode;
@@ -144,6 +150,8 @@ export interface ToolEvent {
144
150
  readonly commit?: string;
145
151
  /** Digest of the working tree when the check finished. */
146
152
  readonly diff_fp?: string;
153
+ /** The skill a skill call invoked, its name only, never its arguments (AWT-711). */
154
+ readonly skill?: string;
147
155
  }
148
156
  export interface BuildTurnSummaryInput {
149
157
  /** Internal provider id ('claude' | 'codex' | ...); mapped to the public label. */
@@ -154,6 +162,10 @@ export interface BuildTurnSummaryInput {
154
162
  readonly developerId?: string;
155
163
  readonly developerName?: string;
156
164
  readonly installationId?: string;
165
+ /** The agent account's email, as the closing hook named it. */
166
+ readonly accountEmail?: string;
167
+ /** The mode the session started in, from its memo. */
168
+ readonly sessionMode?: SessionModeRecord;
157
169
  readonly git?: EventGit;
158
170
  readonly featureCandidates?: readonly FeatureCandidate[];
159
171
  /** The session's opening prompt keys, as the tracker remembered them. */
@@ -168,6 +180,8 @@ export interface BuildTurnSummaryInput {
168
180
  readonly tools: readonly ToolRecord[];
169
181
  /** Already gated and capped by the tracker; see {@link ToolEvent}. */
170
182
  readonly toolEvents?: readonly ToolEvent[];
183
+ /** Already gated by the tracker, as `toolEvents` are. */
184
+ readonly command?: string;
171
185
  /** Evidence of the response the user actually saw, however the provider delivered it. */
172
186
  readonly response?: ContentEvidence;
173
187
  readonly usage?: TurnUsage;
@@ -3,9 +3,11 @@ import type { FailOpenReason } from '../../enforcement/types/enforcement.types.j
3
3
  import type { Env } from '../../core/types/core.types.js';
4
4
  import type { AgentWatchEvent } from '../../events/types/events.types.js';
5
5
  import type { AgentWatchPaths } from '../../storage/types/storage.types.js';
6
+ import type { TurnProvider } from './turn-provider.types.js';
6
7
  import type { TurnSummaryEvent } from './turn-summary.types.js';
7
8
  export interface TrackTurnOptions {
8
- readonly agentId: string;
9
+ /** The agent the hook came from, already loaded on the hook path. */
10
+ readonly provider: TurnProvider;
9
11
  /** Raw provider payload; source of the transcript path. */
10
12
  readonly rawPayload: unknown;
11
13
  /** Enriched + sanitized canonical events produced from this payload. */
@@ -7,11 +7,10 @@ import { canonicalRoot, selectRoot } from '../config/root-config.js';
7
7
  import { REPOSITORY_PATH_METADATA_KEY } from '../events/constants/enrich.constants.js';
8
8
  import { sha256Hex } from '../events/event-id.js';
9
9
  import { featureCandidatesFromBranch } from '../feature/ticket-candidates.js';
10
- import { checkoutRootOf } from '../git/checkout-root.js';
10
+ import { checkoutRootOf, isBeneath } from '../git/checkout-root.js';
11
11
  import { ASSUMED_DEFAULT_BRANCHES, GIT_FIELD_SEPARATOR, GIT_REMOTE_ARGS, GIT_TIMEOUT_MS, MAX_WORK_CHANGED_FILES, gitRemoteBranchesAtArgs, gitVerifyRefArgs } from '../git/constants/git.constants.js';
12
12
  import { asFingerprint, commitFiles, dirtyDelta, fingerprint } from '../git/fingerprint.js';
13
13
  import { repositoryIdentity, runGit } from '../git/git-context.js';
14
- import { isBeneath } from '../git/repository-root.js';
15
14
  import { CHECKOUT_KEY_HASH_LENGTH, CHECKOUT_RECORD_PREFIX, MAX_TURN_CHECKOUTS, TOOL_COMPLETION_TYPES, TOOL_START_TYPES, OWN_COMMIT_SINCE_SLACK_MS, TURN_STATE_TTL_MS, gitOwnCommitCountArgs } from './constants/turns.constants.js';
16
15
  import { resolveInherited } from './inherited-checkout.js';
17
16
  /**