@agent-watch-ai/edge 0.7.1 → 0.7.3

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 (56) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +2 -1
  3. package/dist/capture/capture-env.d.ts +3 -3
  4. package/dist/capture/capture-env.js +5 -5
  5. package/dist/capture/captured-step.js +1 -1
  6. package/dist/cli/constants/cli.constants.js +1 -1
  7. package/dist/cli/setup.js +26 -3
  8. package/dist/cli/types/cli.types.d.ts +2 -0
  9. package/dist/cli/uninstall.js +1 -1
  10. package/dist/cli.js +7 -4
  11. package/dist/config/config.d.ts +8 -0
  12. package/dist/config/config.js +10 -0
  13. package/dist/config/constants/config.constants.d.ts +5 -0
  14. package/dist/config/constants/config.constants.js +5 -0
  15. package/dist/config/repo-config.js +7 -2
  16. package/dist/config/schemas/config.schema.d.ts +4 -0
  17. package/dist/config/schemas/config.schema.js +7 -1
  18. package/dist/enrollment/enrollment.js +7 -4
  19. package/dist/pipeline/hook-pipeline.js +3 -1
  20. package/dist/providers/antigravity/antigravity.adapter.d.ts +14 -0
  21. package/dist/providers/antigravity/antigravity.adapter.js +86 -18
  22. package/dist/providers/antigravity/antigravity.provider.js +7 -4
  23. package/dist/providers/antigravity/constants/antigravity.constants.d.ts +10 -0
  24. package/dist/providers/antigravity/constants/antigravity.constants.js +10 -0
  25. package/dist/providers/antigravity/schemas/antigravity.schema.js +7 -13
  26. package/dist/providers/claude/claude.otel.d.ts +33 -1
  27. package/dist/providers/claude/claude.otel.js +81 -12
  28. package/dist/providers/claude/claude.provider.js +3 -1
  29. package/dist/providers/codex/codex.capture.d.ts +1 -1
  30. package/dist/providers/codex/codex.capture.js +3 -3
  31. package/dist/providers/codex/codex.otel.js +2 -2
  32. package/dist/providers/codex/codex.provider.js +2 -1
  33. package/dist/providers/gemini/gemini.capture.js +2 -2
  34. package/dist/providers/gemini/gemini.otel.js +2 -2
  35. package/dist/providers/gemini/gemini.provider.js +2 -1
  36. package/dist/providers/shared/terminal-capture.js +3 -3
  37. package/dist/turns/antigravity-transcript.d.ts +40 -0
  38. package/dist/turns/antigravity-transcript.js +102 -0
  39. package/dist/turns/claude-transcript.d.ts +35 -1
  40. package/dist/turns/claude-transcript.js +185 -2
  41. package/dist/turns/codex-transcript.d.ts +22 -1
  42. package/dist/turns/codex-transcript.js +161 -2
  43. package/dist/turns/constants/turns.constants.d.ts +51 -0
  44. package/dist/turns/constants/turns.constants.js +51 -0
  45. package/dist/turns/gemini-transcript.d.ts +17 -1
  46. package/dist/turns/gemini-transcript.js +36 -2
  47. package/dist/turns/transcript.d.ts +31 -1
  48. package/dist/turns/transcript.js +74 -0
  49. package/dist/turns/turn-state.d.ts +18 -1
  50. package/dist/turns/turn-state.js +45 -10
  51. package/dist/turns/turn-tracker.js +154 -16
  52. package/dist/turns/types/transcript.types.d.ts +25 -0
  53. package/dist/turns/types/turn-provider.types.d.ts +18 -1
  54. package/dist/turns/types/turn-state.types.d.ts +10 -0
  55. package/docs/DATA_HANDLING.md +3 -0
  56. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,35 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.7.3
6
+
7
+ - `agentwatch setup <organization-id>` signs in to the Agent Watch backend without a URL:
8
+ the install line no longer needs `https://api.agent-watch.ai?organization=…`. The URL form
9
+ still works, and `--endpoint` points a bare id at another backend.
10
+
11
+ ## 0.7.2
12
+
13
+ - Google Antigravity turns now report token usage, read from the conversation's own
14
+ transcript (`brain/<conversation>/.system_generated/logs/transcript_full.jsonl`): input,
15
+ cache read and output tokens per model, each model step counted once. Only the counts and
16
+ the model name are read, never the conversation. Builds that write no counts still report
17
+ the turn without usage.
18
+ - Antigravity CLI 1.5.0 hooks are now read. That version sends a flat payload (event name
19
+ and conversation at the top level), which the edge did not recognize, so its hooks
20
+ produced no turns.
21
+ - Claude Code turn summaries now include the tokens the turn's subagents used, read from
22
+ their own transcripts. Before, a turn that handed work to subagents reported only the
23
+ main agent's tokens. A background subagent that is still running when the turn ends
24
+ adds its tokens to that turn when it finishes.
25
+ - Codex and Gemini CLI turn summaries now include the tokens their subagents used, read
26
+ from the subagents' own session files.
27
+ - Counting the provider calls of scripts your coding agent starts (run capture) has its
28
+ own switch now: `capture.runs` in `~/.agentwatch/config.json`, set with
29
+ `agentwatch setup --capture-runs on|off`, on by default. `--otel none` used to turn it
30
+ off too, though those calls never travel over OpenTelemetry. Now it turns off only the
31
+ agents' own telemetry export. Run `agentwatch setup` once after updating if you set
32
+ `--otel none`, to start counting those calls again.
33
+
5
34
  ## 0.7.1
6
35
 
7
36
  - The budget check before each turn now waits up to 500 ms for the platform's answer, up
package/README.md CHANGED
@@ -364,7 +364,8 @@ The cloud documentation behind each of these points, and the container runs that
364
364
  ## CLI
365
365
 
366
366
  ```bash
367
- agentwatch setup --token <key> # install hooks and exporters
367
+ agentwatch setup <organization-id> # install hooks and exporters, sign in through the browser
368
+ agentwatch setup --token <key> # same, with an install key
368
369
  agentwatch status # backend, queue and agent health
369
370
  agentwatch doctor # environment checks (--json for CI)
370
371
  agentwatch config # active configuration, secrets redacted
@@ -57,7 +57,7 @@ export declare function installCaptureCopy(dataDir: string, source?: Shims): Pro
57
57
  *
58
58
  * Every agent shares the one copy, and a missing `--require` target stops every Node an
59
59
  * agent starts, so it stays while either holds. Hooks: `agentwatch off`, the exporter sweep
60
- * and `otel: none` take the env keys out and leave the hooks, with sessions still running
60
+ * and `capture.runs: false` take the env keys out and leave the hooks, with sessions still running
61
61
  * that hold the `--require`; a detection that fails counts as installed. A config naming the
62
62
  * copy: a removal that was refused leaves the keys, and a hook file that does not parse
63
63
  * reads as no hooks. A copy left behind costs nothing.
@@ -138,10 +138,10 @@ export declare function withCaptureOutcome(outcome: SetupOutcome, capture: Setup
138
138
  *
139
139
  * @param block - The env block the agent runs with.
140
140
  * @param config - The credential that would deliver what is captured.
141
- * @param telemetryOn - Whether this machine's config allows the agent's telemetry.
141
+ * @param runsOn - Whether this machine's config turns run capture on (`capture.runs`).
142
142
  * @param dataDir - The data dir holding the copy.
143
143
  * @param source - The package's shims, which the copy should match.
144
144
  * @returns On, or off with the reason; on with a warning when the copy is stale.
145
145
  */
146
- export declare function inspectCaptureEnv(block: Record<string, unknown>, config: CredentialFields, telemetryOn: boolean, dataDir: string, source?: Shims): Promise<RunCaptureStatus>;
146
+ export declare function inspectCaptureEnv(block: Record<string, unknown>, config: CredentialFields, runsOn: boolean, dataDir: string, source?: Shims): Promise<RunCaptureStatus>;
147
147
  export {};
@@ -154,7 +154,7 @@ async function configNamesCopy(dataDir, env, agents) {
154
154
  *
155
155
  * Every agent shares the one copy, and a missing `--require` target stops every Node an
156
156
  * agent starts, so it stays while either holds. Hooks: `agentwatch off`, the exporter sweep
157
- * and `otel: none` take the env keys out and leave the hooks, with sessions still running
157
+ * and `capture.runs: false` take the env keys out and leave the hooks, with sessions still running
158
158
  * that hold the `--require`; a detection that fails counts as installed. A config naming the
159
159
  * copy: a removal that was refused leaves the keys, and a hook file that does not parse
160
160
  * reads as no hooks. A copy left behind costs nothing.
@@ -269,19 +269,19 @@ export function withCaptureOutcome(outcome, capture) {
269
269
  *
270
270
  * @param block - The env block the agent runs with.
271
271
  * @param config - The credential that would deliver what is captured.
272
- * @param telemetryOn - Whether this machine's config allows the agent's telemetry.
272
+ * @param runsOn - Whether this machine's config turns run capture on (`capture.runs`).
273
273
  * @param dataDir - The data dir holding the copy.
274
274
  * @param source - The package's shims, which the copy should match.
275
275
  * @returns On, or off with the reason; on with a warning when the copy is stale.
276
276
  */
277
- export async function inspectCaptureEnv(block, config, telemetryOn, dataDir, source = shimPaths()) {
277
+ export async function inspectCaptureEnv(block, config, runsOn, dataDir, source = shimPaths()) {
278
278
  const shims = copiedShims(dataDir);
279
279
  if (path.delimiter === ';')
280
280
  return { on: false, reason: 'not supported on Windows' };
281
281
  if (!hasCredential(config))
282
282
  return { on: false, reason: 'Edge is not signed in, so nothing is captured' };
283
- if (!telemetryOn)
284
- return { on: false, reason: 'telemetry is off in config (otel)' };
283
+ if (!runsOn)
284
+ return { on: false, reason: 'turned off in config (capture.runs)' };
285
285
  const expected = captureEnv(block, {}, shims);
286
286
  if (block[RUN_CAPTURE_ENV_NODE] !== expected[RUN_CAPTURE_ENV_NODE] || block[RUN_CAPTURE_ENV_PYTHON] !== expected[RUN_CAPTURE_ENV_PYTHON]) {
287
287
  return { on: false, reason: 'not configured; run `agentwatch setup` and restart the agent' };
@@ -173,7 +173,7 @@ async function armVenvsOfThisRun(state) {
173
173
  const shimDir = copiedShims(state.paths.dataDir).python;
174
174
  if (pythonInterpreters(call.command, directory).length === 0)
175
175
  return;
176
- // Only while this agent's route loads the copy: `otel: none`, `off`, and a route not
176
+ // Only while this agent's route loads the copy: `capture.runs: false`, `off`, and a route not
177
177
  // yet verified (Cursor, Antigravity) leave its config without it, and the venv alone.
178
178
  const config = runCaptureRoute(state.provider)?.configPath(state.env);
179
179
  if (config === undefined || !(await fs.readFile(config, 'utf8').catch(() => '')).includes(shimDir))
@@ -5,7 +5,7 @@
5
5
  * itself into a boolean — which is how `--otel none` once ignored the selection
6
6
  * entirely.
7
7
  */
8
- export const VALUE_FLAGS = new Set(['agent', 'endpoint', 'token', 'enrollment-code', 'developer-email', 'developer-name', 'otel', 'root', 'replay-days']);
8
+ export const VALUE_FLAGS = new Set(['agent', 'endpoint', 'token', 'enrollment-code', 'developer-email', 'developer-name', 'otel', 'capture-runs', 'root', 'replay-days']);
9
9
  /** The commands that take `--agent`; the help names the same three. Any other command refuses it. */
10
10
  export const AGENT_COMMANDS = new Set(['setup', 'uninstall', 'hook']);
11
11
  export const FLAG_PREFIX = '--';
package/dist/cli/setup.js CHANGED
@@ -123,6 +123,11 @@ async function setup(options, context, cloud) {
123
123
  println(`${symbols.fail} invalid --otel value "${options.otel}" (expected "all", "none" or a comma list of logs,traces,metrics)`);
124
124
  return 1;
125
125
  }
126
+ const runs = resolveCaptureRuns(baseConfig, options.captureRuns);
127
+ if (runs === undefined) {
128
+ println(`${symbols.fail} invalid --capture-runs value "${options.captureRuns}" (expected "on" or "off")`);
129
+ return 1;
130
+ }
126
131
  const replayDays = parseReplayDays(options.replayDays);
127
132
  if (replayDays === undefined) {
128
133
  println(`${symbols.fail} invalid --replay-days "${options.replayDays}" (expected a whole number of days, 1 to 366)`);
@@ -147,7 +152,7 @@ async function setup(options, context, cloud) {
147
152
  const inherited = rootPath === undefined ? baseConfig : { endpoint: existingRoot?.endpoint === undefined ? baseConfig.endpoint : existingRoot.endpoint };
148
153
  const heldDevice = rootPath === undefined ? baseConfig.device : existingRoot?.device;
149
154
  if (options.deferSignIn === true && (options.setupUrl === undefined || rootPath !== undefined)) {
150
- println(`${symbols.fail} --defer-sign-in takes the organization enrollment URL and configures the machine, not a project root; nothing was written`);
155
+ println(`${symbols.fail} --defer-sign-in takes the organization id or enrollment URL and configures the machine, not a project root; nothing was written`);
151
156
  return 1;
152
157
  }
153
158
  const resolvedEnrollment = enroll({ ...options, setupUrl: options.setupUrl ?? pendingSignInUrl(options, baseConfig, rootPath) }, inherited, baseConfig.customEndpoints);
@@ -245,7 +250,7 @@ async function setup(options, context, cloud) {
245
250
  const customEndpoints = nextTrustedOrigins(baseConfig.customEndpoints, previous, enrolled.endpoint, options.allowCustomEndpoint === true, withIdentity);
246
251
  // Set by an enrollment URL and cleared by any other machine setup, so it never outlives the backend it belongs to.
247
252
  const organization = rootPath === undefined ? { organizationId: enrolled.signIn?.organizationId } : {};
248
- const config = ensureInstallationId({ ...withIdentity, ...organization, ...(signedIn ? { installationId } : {}), customEndpoints, otel, emit: { ...baseConfig.emit, llmCalls: true } });
253
+ const config = ensureInstallationId({ ...withIdentity, ...organization, ...(signedIn ? { installationId } : {}), customEndpoints, otel, capture: { ...baseConfig.capture, runs }, emit: { ...baseConfig.emit, llmCalls: true } });
249
254
  await reportContentDowngrade(context, config);
250
255
  // Under the config lock and onto the file as it is now: a hook may have
251
256
  // exchanged this key while setup was running.
@@ -275,6 +280,7 @@ async function setup(options, context, cloud) {
275
280
  if (developerName)
276
281
  println(`${symbols.ok} name: ${developerName}`);
277
282
  println(`${symbols.ok} otel signals: ${enabledSignalNames(otel).join(', ') || 'none'}`);
283
+ println(`${symbols.ok} run capture: ${runs ? 'on' : 'off'}`);
278
284
  println(dim(` config: ${context.paths.configFile}`));
279
285
  println();
280
286
  // Setup is the one way back after an uninstall, for the entry it ran for
@@ -391,7 +397,7 @@ async function readEnrollmentCode(options, withUrl) {
391
397
  return { error: `an enrollment code goes in $${ENROLLMENT_CODE_VAR} or on stdin with --enrollment-code -, never on the command line, where other users can read it; nothing was written. If that was a code, ask your admin for a new one` };
392
398
  }
393
399
  if (flag !== undefined && !withUrl)
394
- return { error: 'an enrollment code is redeemed with the enrollment URL: agentwatch setup <backend>?organization=<id>; nothing was written' };
400
+ return { error: 'an enrollment code is redeemed with the organization id: agentwatch setup <organization-id>; nothing was written' };
395
401
  if (!withUrl)
396
402
  return {};
397
403
  // `||`, as for the token: an exported-but-empty variable is one nobody set.
@@ -528,6 +534,8 @@ async function resolveRoot(options, baseConfig) {
528
534
  return { error: 'set up the machine identity first (agentwatch setup without --root); a project root is an addition to it' };
529
535
  if (options.otel !== undefined)
530
536
  return { error: 'native OTLP signals are machine-wide; run setup without --root to change them' };
537
+ if (options.captureRuns !== undefined)
538
+ return { error: 'run capture is machine-wide; run setup without --root to change it' };
531
539
  try {
532
540
  const root = await fs.realpath(path.resolve(options.env.cwd, options.root));
533
541
  const existing = Object.keys(baseConfig.roots ?? {}).filter((key) => path.isAbsolute(key) && canonicalRoot(key) === root);
@@ -583,6 +591,21 @@ function resolveOtel(baseConfig, flag) {
583
591
  return baseConfig.otel;
584
592
  return parseOtelSignals(flag);
585
593
  }
594
+ /**
595
+ * The run capture switch for this run, validated with the other flags.
596
+ *
597
+ * @param baseConfig - Config the run starts from.
598
+ * @param flag - Raw `--capture-runs` value, when given.
599
+ * @returns On or off, or undefined when the flag is invalid.
600
+ */
601
+ function resolveCaptureRuns(baseConfig, flag) {
602
+ if (flag === undefined)
603
+ return baseConfig.capture.runs;
604
+ const value = flag.trim().toLowerCase();
605
+ if (value === 'on' || value === 'off')
606
+ return value === 'on';
607
+ return undefined;
608
+ }
586
609
  /**
587
610
  * Print the repository context. Informational; never fails the run.
588
611
  *
@@ -75,6 +75,8 @@ export interface SetupOptions {
75
75
  readonly root?: string;
76
76
  /** OTLP signal selection: "all", "none" or a comma list of logs,traces,metrics. */
77
77
  readonly otel?: string;
78
+ /** Run capture (`capture.runs`): "on" or "off". */
79
+ readonly captureRuns?: string;
78
80
  /** The agents `--agent` selected; every registered agent when absent. */
79
81
  readonly agents?: readonly AgentProvider[];
80
82
  readonly hookCommandFor?: (providerId: string) => string;
@@ -115,7 +115,7 @@ function report(outcome, current) {
115
115
  */
116
116
  function revocationLine(revocation) {
117
117
  if (revocation.revoked && revocation.removed)
118
- return `${symbols.ok} device credential revoked on the platform and removed from this machine; your organization's setup command (\`agentwatch setup <enrollment-url>\`) enrolls it again`;
118
+ return `${symbols.ok} device credential revoked on the platform and removed from this machine; your organization's setup command (\`agentwatch setup <organization-id>\`) enrolls it again`;
119
119
  const leftover = revocation.leftover ? `; remove it by hand from ${revocation.leftover}` : '';
120
120
  if (revocation.revoked)
121
121
  return `${symbols.warn} device credential revoked on the platform but not removed from this machine (${revocation.reason})${leftover}`;
package/dist/cli.js CHANGED
@@ -11,7 +11,7 @@ import { providerIds } from './providers/loaders.js';
11
11
  const HELP = `agentwatch — telemetry edge for AI coding agents
12
12
 
13
13
  Usage:
14
- agentwatch setup [enrollment-url] [--endpoint <url>] [--allow-custom-endpoint] [--no-browser] [--enrollment-code -] [--token <token>] [--developer-email <email>] [--developer-name <name>] [--root <path>] [--otel <signals>] [--replay-days <n>] [--no-replay] [--agent <id>]
14
+ agentwatch setup [organization-id | enrollment-url] [--endpoint <url>] [--allow-custom-endpoint] [--no-browser] [--enrollment-code -] [--token <token>] [--developer-email <email>] [--developer-name <name>] [--root <path>] [--otel <signals>] [--capture-runs on|off] [--replay-days <n>] [--no-replay] [--agent <id>]
15
15
  agentwatch setup --cloud (a Claude Code cloud session's managed SessionStart hook)
16
16
  agentwatch status
17
17
  agentwatch replay [--machine | --root <path>] [--replay-days <n>] [--resume | --stop] [--dry-run]
@@ -30,9 +30,9 @@ Flags:
30
30
  loopback for local development (default: https://api.agent-watch.ai)
31
31
  --allow-custom-endpoint trust an --endpoint outside the Agent Watch hosts (self-hosted or
32
32
  proxied backend). Stored in the config and shown by status and doctor
33
- --no-browser with an enrollment URL, print the sign-in link without opening a
33
+ --no-browser when signing in, print the sign-in link without opening a
34
34
  browser (never opened anyway under CI, over SSH or without a terminal)
35
- --enrollment-code - with an enrollment URL, enroll an unattended machine with an
35
+ --enrollment-code - with an organization id, enroll an unattended machine with an
36
36
  admin-issued code read from stdin instead of signing in through
37
37
  a browser; $AGENTWATCH_ENROLLMENT_CODE works too. A code is never
38
38
  accepted on the command line
@@ -52,7 +52,9 @@ Flags:
52
52
  --otel <signals> native OTLP signals agents export to the backend: comma list of
53
53
  logs,traces,metrics, or "all"/"none" (default: logs — the
54
54
  per-request usage/cost ledger the backend turns into llm.call)
55
- --defer-sign-in with an enrollment URL, for an MDM run: save the organization and
55
+ --capture-runs on|off count the provider calls of scripts an agent starts (default: on).
56
+ Apart from --otel: --otel none leaves it on
57
+ --defer-sign-in with an organization id, for an MDM run: save the organization and
56
58
  install the hooks with no credential. Nothing is sent until the
57
59
  developer runs \`agentwatch setup\` and signs in as themselves.
58
60
  A machine with no device and an enrollment code redeems the
@@ -167,6 +169,7 @@ async function main() {
167
169
  developerName: stringFlag(parsed, 'developer-name'),
168
170
  root: stringFlag(parsed, 'root'),
169
171
  otel: stringFlag(parsed, 'otel'),
172
+ captureRuns: stringFlag(parsed, 'capture-runs'),
170
173
  agents: selected.agents,
171
174
  deferSignIn: boolFlag(parsed, 'defer-sign-in'),
172
175
  replayDays: stringFlag(parsed, 'replay-days'),
@@ -12,6 +12,14 @@ export declare function defaultConfig(): AgentWatchConfig;
12
12
  * @returns True when at least one signal is on.
13
13
  */
14
14
  export declare function otelEnabled(config: AgentWatchConfig): boolean;
15
+ /**
16
+ * Whether setup writes run capture into each agent's environment. Apart from
17
+ * `otelEnabled` on purpose: captured calls go out as events, not OTLP.
18
+ *
19
+ * @param config - Effective configuration.
20
+ * @returns True when `capture.runs` is on.
21
+ */
22
+ export declare function runCaptureEnabled(config: AgentWatchConfig): boolean;
15
23
  /**
16
24
  * Names of the enabled OTLP signals, for setup and status messages.
17
25
  *
@@ -17,6 +17,16 @@ export function defaultConfig() {
17
17
  export function otelEnabled(config) {
18
18
  return config.otel.logs || config.otel.traces || config.otel.metrics;
19
19
  }
20
+ /**
21
+ * Whether setup writes run capture into each agent's environment. Apart from
22
+ * `otelEnabled` on purpose: captured calls go out as events, not OTLP.
23
+ *
24
+ * @param config - Effective configuration.
25
+ * @returns True when `capture.runs` is on.
26
+ */
27
+ export function runCaptureEnabled(config) {
28
+ return config.capture.runs;
29
+ }
20
30
  /**
21
31
  * Names of the enabled OTLP signals, for setup and status messages.
22
32
  *
@@ -135,6 +135,11 @@ export declare const GLOBAL_ONLY_BLOCKS: readonly ["delivery", "otel", "enforcem
135
135
  * to silence usage telemetry for everyone who clones the repository.
136
136
  */
137
137
  export declare const GLOBAL_ONLY_EMIT_KEYS: ReadonlySet<string>;
138
+ /**
139
+ * Capture flags a repo file may not set. Run capture is written into each agent's
140
+ * machine-wide environment by setup, so a repository has no say in it.
141
+ */
142
+ export declare const GLOBAL_ONLY_CAPTURE_KEYS: ReadonlySet<string>;
138
143
  /**
139
144
  * The capture flags that carry raw content off the machine: the developer's
140
145
  * prompt text, tool arguments and tool results, and the session's title. Response text is not here
@@ -158,6 +158,11 @@ export const GLOBAL_ONLY_BLOCKS = ['delivery', 'otel', 'enforcement'];
158
158
  * to silence usage telemetry for everyone who clones the repository.
159
159
  */
160
160
  export const GLOBAL_ONLY_EMIT_KEYS = new Set(['llmCalls', 'turnSummaries']);
161
+ /**
162
+ * Capture flags a repo file may not set. Run capture is written into each agent's
163
+ * machine-wide environment by setup, so a repository has no say in it.
164
+ */
165
+ export const GLOBAL_ONLY_CAPTURE_KEYS = new Set(['runs']);
161
166
  /**
162
167
  * The capture flags that carry raw content off the machine: the developer's
163
168
  * prompt text, tool arguments and tool results, and the session's title. Response text is not here
@@ -5,7 +5,7 @@ import { debugLog } from '../core/logger.js';
5
5
  import { readJsonFile } from '../storage/json-file.js';
6
6
  import { loadConfig } from './config-store.js';
7
7
  import { applyRootOverride } from './root-config.js';
8
- import { CAPTURE_KEY, GLOBAL_ONLY_BLOCKS, GLOBAL_ONLY_EMIT_KEYS, GLOBAL_ONLY_KEYS, MAX_WALK_DEPTH, MERGE_BLOCKS, REPO_CONFIG_NAME } from './constants/config.constants.js';
8
+ import { CAPTURE_KEY, GLOBAL_ONLY_BLOCKS, GLOBAL_ONLY_CAPTURE_KEYS, GLOBAL_ONLY_EMIT_KEYS, GLOBAL_ONLY_KEYS, MAX_WALK_DEPTH, MERGE_BLOCKS, REPO_CONFIG_NAME } from './constants/config.constants.js';
9
9
  import { configSchema } from './schemas/config.schema.js';
10
10
  export { REPO_CONFIG_NAME } from './constants/config.constants.js';
11
11
  /**
@@ -125,7 +125,12 @@ function withoutGlobalOnly(repo) {
125
125
  warnings.push(`${REPO_CONFIG_NAME}: "${block}" is global-only and was ignored`);
126
126
  refused.add(block);
127
127
  }
128
- const value = omitKeys(repo, refused);
128
+ const stripped = omitKeys(repo, refused);
129
+ const capture = asRecord(stripped[CAPTURE_KEY]);
130
+ const refusedCaptureKeys = new Set(Object.keys(capture ?? {}).filter((key) => GLOBAL_ONLY_CAPTURE_KEYS.has(key)));
131
+ for (const key of refusedCaptureKeys)
132
+ warnings.push(`${REPO_CONFIG_NAME}: "capture.${key}" is global-only and was ignored`);
133
+ const value = capture && refusedCaptureKeys.size > 0 ? { ...stripped, [CAPTURE_KEY]: omitKeys(capture, refusedCaptureKeys) } : stripped;
129
134
  const emit = asRecord(value['emit']);
130
135
  if (!emit)
131
136
  return { value, warnings };
@@ -33,6 +33,7 @@ export declare const captureSchema: z.ZodObject<{
33
33
  git: z.ZodDefault<z.ZodBoolean>;
34
34
  files: z.ZodDefault<z.ZodBoolean>;
35
35
  mcpNames: z.ZodDefault<z.ZodBoolean>;
36
+ runs: z.ZodDefault<z.ZodBoolean>;
36
37
  }, z.core.$strip>;
37
38
  /** Tuning for the in-hook send and the machine-global offline queue. */
38
39
  export declare const deliverySchema: z.ZodObject<{
@@ -239,6 +240,7 @@ export declare const configSchema: z.ZodPipe<z.ZodObject<{
239
240
  git: z.ZodDefault<z.ZodBoolean>;
240
241
  files: z.ZodDefault<z.ZodBoolean>;
241
242
  mcpNames: z.ZodDefault<z.ZodBoolean>;
243
+ runs: z.ZodDefault<z.ZodBoolean>;
242
244
  }, z.core.$strip>>;
243
245
  emit: z.ZodPrefault<z.ZodObject<{
244
246
  turnSummaries: z.ZodDefault<z.ZodBoolean>;
@@ -270,6 +272,7 @@ export declare const configSchema: z.ZodPipe<z.ZodObject<{
270
272
  git: boolean;
271
273
  files: boolean;
272
274
  mcpNames: boolean;
275
+ runs: boolean;
273
276
  };
274
277
  schemaVersion: 1;
275
278
  ignoredRoots: string[];
@@ -347,6 +350,7 @@ export declare const configSchema: z.ZodPipe<z.ZodObject<{
347
350
  git: boolean;
348
351
  files: boolean;
349
352
  mcpNames: boolean;
353
+ runs: boolean;
350
354
  };
351
355
  emit: {
352
356
  turnSummaries: boolean;
@@ -52,7 +52,13 @@ export const captureSchema = z
52
52
  git: z.boolean().default(true),
53
53
  files: z.boolean().default(true),
54
54
  /** MCP server and tool names in `tools_used`; false folds them into `mcp`. Metadata, not content. */
55
- mcpNames: z.boolean().default(true)
55
+ mcpNames: z.boolean().default(true),
56
+ /**
57
+ * Run capture: the shims each agent's environment loads, counting provider calls of the
58
+ * processes it starts. Its own switch, apart from `otel`: the calls travel as events,
59
+ * not OTLP, so turning native telemetry off must not stop them. Machine-wide, global-only.
60
+ */
61
+ runs: z.boolean().default(true)
56
62
  })
57
63
  .strip();
58
64
  /** Tuning for the in-hook send and the machine-global offline queue. */
@@ -17,10 +17,13 @@ import { RE_ORGANIZATION_ID } from './constants/enrollment.constants.js';
17
17
  * @throws When the endpoint is not usable.
18
18
  */
19
19
  export function resolveEnrollment(input) {
20
- const link = input.setupUrl ? parseEnrollmentUrl(input.setupUrl) : undefined;
20
+ // A bare organization id signs in to the production backend, or `--endpoint` when given.
21
+ const bareId = input.setupUrl !== undefined && RE_ORGANIZATION_ID.test(input.setupUrl);
22
+ const parsed = input.setupUrl && !bareId ? parseEnrollmentUrl(input.setupUrl) : undefined;
23
+ const link = bareId ? { endpoint: input.endpoint ?? DEFAULT_ENDPOINT, organizationId: input.setupUrl } : parsed;
21
24
  if (link && input.token)
22
- throw new Error('an enrollment URL signs in through the browser and takes no install key; drop --token / $AGENTWATCH_TOKEN');
23
- if (link && input.endpoint)
25
+ throw new Error('an organization id or enrollment URL signs in through the browser and takes no install key; drop --token / $AGENTWATCH_TOKEN');
26
+ if (link && !bareId && input.endpoint)
24
27
  throw new Error('an enrollment URL names its own backend; drop --endpoint');
25
28
  const endpoint = link?.endpoint ?? input.endpoint ?? DEFAULT_ENDPOINT;
26
29
  const trimmed = normalizeEndpoint(endpoint);
@@ -48,7 +51,7 @@ function parseEnrollmentUrl(link) {
48
51
  const url = URL.canParse(link) ? new URL(link) : undefined;
49
52
  const organizationId = url?.searchParams.get('organization') ?? '';
50
53
  if (!url || !RE_ORGANIZATION_ID.test(organizationId))
51
- throw new Error('enrollment URL must look like https://<backend>?organization=<organization id>');
54
+ throw new Error('setup takes the organization id, or an enrollment URL like https://<backend>?organization=<organization id>');
52
55
  // A backend under a path prefix keeps it, as `--endpoint` does.
53
56
  return { endpoint: url.origin + url.pathname.replace(/\/+$/, ''), organizationId };
54
57
  }
@@ -632,7 +632,9 @@ async function snapshot(state) {
632
632
  // Never for an inherited repository: core may drop it when folder evidence
633
633
  // disagrees, and a snapshot of it would mint a work unit for the wrong one.
634
634
  const capture = state.workCapture ?? state.config.capture;
635
- if (!repository || state.summary?.work_evidence === 'inherited' || !capture.git)
635
+ // A turn re-sent on a subagent's stop (late usage) was snapshotted at its close.
636
+ const closed = state.events.some((event) => event.event.type === 'generation.completed');
637
+ if (!repository || !closed || state.summary?.work_evidence === 'inherited' || !capture.git)
636
638
  return stop(state, STOP_NO_SNAPSHOT);
637
639
  const input = {
638
640
  // The checkout the summary named, which need not be the folder the agent sits in.
@@ -1,7 +1,21 @@
1
1
  import type { AgentWatchEvent } from '../../events/types/events.types.js';
2
+ import type { Env } from '../../core/types/core.types.js';
2
3
  import type { HookContext, ShellCall } from '../types/provider.types.js';
3
4
  import type { AntigravityHookEvent } from './types/antigravity.types.js';
4
5
  export type { AntigravityHookEvent, AntigravityPayload } from './types/antigravity.types.js';
6
+ /**
7
+ * The transcript a hook's turn usage is read from.
8
+ *
9
+ * `transcriptPath` when the payload names it; otherwise the transcript under
10
+ * the conversation's brain directory, first through `artifactDirectoryPath`
11
+ * (which is that directory), then through `conversationId` in whichever app
12
+ * directory has it.
13
+ *
14
+ * @param rawPayload - Raw JSON from the hook's stdin.
15
+ * @param env - Where the home directory is.
16
+ * @returns The path, or undefined when the payload names no conversation.
17
+ */
18
+ export declare function antigravityTranscriptPath(rawPayload: unknown, env: Env): string | undefined;
5
19
  /**
6
20
  * Which hook this payload is.
7
21
  *