@agent-watch-ai/edge 0.4.0 → 0.5.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 (74) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +3 -3
  3. package/SECURITY.md +1 -1
  4. package/dist/config/config-store.js +1 -1
  5. package/dist/config/repo-config.js +1 -1
  6. package/dist/config/schemas/config.schema.d.ts +93 -857
  7. package/dist/config/schemas/config.schema.js +5 -5
  8. package/dist/credentials/credentials.js +2 -2
  9. package/dist/credentials/schemas/device-api.schema.d.ts +4 -51
  10. package/dist/credentials/schemas/device-state.schema.d.ts +3 -38
  11. package/dist/git/code-state.d.ts +33 -0
  12. package/dist/git/code-state.js +44 -0
  13. package/dist/git/constants/git.constants.d.ts +6 -0
  14. package/dist/git/constants/git.constants.js +6 -0
  15. package/dist/git/index.d.ts +2 -1
  16. package/dist/git/index.js +1 -0
  17. package/dist/git/types/git.types.d.ts +6 -0
  18. package/dist/privacy/command-fingerprint.d.ts +42 -0
  19. package/dist/privacy/command-fingerprint.js +249 -0
  20. package/dist/privacy/constants/command-fingerprint.constants.d.ts +34 -0
  21. package/dist/privacy/constants/command-fingerprint.constants.js +38 -0
  22. package/dist/privacy/index.d.ts +3 -1
  23. package/dist/privacy/index.js +2 -0
  24. package/dist/privacy/product-capture.js +19 -1
  25. package/dist/privacy/types/privacy.types.d.ts +7 -0
  26. package/dist/providers/antigravity/antigravity.adapter.js +3 -0
  27. package/dist/providers/antigravity/schemas/antigravity.schema.d.ts +18 -492
  28. package/dist/providers/claude/claude.adapter.js +12 -1
  29. package/dist/providers/claude/constants/claude.constants.d.ts +6 -0
  30. package/dist/providers/claude/constants/claude.constants.js +6 -0
  31. package/dist/providers/claude/schemas/claude.schema.d.ts +1 -43
  32. package/dist/providers/codex/codex.adapter.js +14 -0
  33. package/dist/providers/codex/schemas/codex.schema.d.ts +1 -41
  34. package/dist/providers/cursor/cursor.adapter.js +5 -2
  35. package/dist/providers/cursor/schemas/cursor.schema.d.ts +5 -85
  36. package/dist/providers/gemini/constants/gemini.constants.d.ts +2 -0
  37. package/dist/providers/gemini/constants/gemini.constants.js +2 -0
  38. package/dist/providers/gemini/constants/gemini.otel.constants.d.ts +10 -1
  39. package/dist/providers/gemini/constants/gemini.otel.constants.js +11 -2
  40. package/dist/providers/gemini/gemini.detect.d.ts +11 -0
  41. package/dist/providers/gemini/gemini.detect.js +14 -1
  42. package/dist/providers/gemini/gemini.hooks.d.ts +3 -3
  43. package/dist/providers/gemini/gemini.hooks.js +5 -5
  44. package/dist/providers/gemini/gemini.otel.d.ts +6 -6
  45. package/dist/providers/gemini/gemini.otel.js +392 -121
  46. package/dist/providers/gemini/schemas/gemini.schema.d.ts +1 -49
  47. package/dist/providers/shared/event-builder.d.ts +17 -2
  48. package/dist/providers/shared/event-builder.js +43 -3
  49. package/dist/providers/shared/install-record.d.ts +2 -0
  50. package/dist/providers/shared/install-record.js +3 -2
  51. package/dist/providers/shared/tooling.d.ts +7 -0
  52. package/dist/providers/shared/tooling.js +10 -1
  53. package/dist/providers/shared/types/adapter.types.d.ts +18 -0
  54. package/dist/storage/schemas/storage.schema.d.ts +11 -175
  55. package/dist/storage/schemas/storage.schema.js +7 -1
  56. package/dist/transport/schemas/queue.schema.d.ts +1 -16
  57. package/dist/transport/schemas/queue.schema.js +1 -1
  58. package/dist/turns/constants/turns.constants.d.ts +17 -0
  59. package/dist/turns/constants/turns.constants.js +17 -0
  60. package/dist/turns/index.d.ts +3 -2
  61. package/dist/turns/index.js +1 -0
  62. package/dist/turns/tool-events.d.ts +15 -0
  63. package/dist/turns/tool-events.js +59 -0
  64. package/dist/turns/turn-state.js +2 -2
  65. package/dist/turns/turn-summary.d.ts +1 -1
  66. package/dist/turns/turn-summary.js +1 -0
  67. package/dist/turns/turn-tracker.js +138 -7
  68. package/dist/turns/types/turn-state.types.d.ts +28 -1
  69. package/dist/turns/types/turn-summary.types.d.ts +30 -0
  70. package/dist/turns/types/turn-tracker.types.d.ts +10 -0
  71. package/docs/AUDIT_PROMPT.md +11 -0
  72. package/docs/DATA_HANDLING.md +58 -10
  73. package/docs/ENTERPRISE_DEPLOYMENT.md +2 -1
  74. package/package.json +9 -8
@@ -34,3 +34,9 @@ export declare const CLAUDE_SHELL_REREAD_EVENTS: ReadonlySet<string>;
34
34
  */
35
35
  export declare const CLAUDE_PROMPT_SUBMIT_EVENTS: ReadonlySet<string>;
36
36
  export declare const CLAUDE_UNKNOWN_EVENT = "unknown";
37
+ /**
38
+ * Where a failed Bash call's error text states its exit code ("Exit code 2",
39
+ * "Command failed with exit code 2"). Claude's hooks carry no exit code field;
40
+ * the error is read for the number in memory, never kept.
41
+ */
42
+ export declare const RE_CLAUDE_EXIT_CODE: RegExp;
@@ -54,3 +54,9 @@ export const CLAUDE_SHELL_REREAD_EVENTS = new Set(['PostToolUse', 'PostToolUseFa
54
54
  */
55
55
  export const CLAUDE_PROMPT_SUBMIT_EVENTS = new Set(['UserPromptSubmit']);
56
56
  export const CLAUDE_UNKNOWN_EVENT = 'unknown';
57
+ /**
58
+ * Where a failed Bash call's error text states its exit code ("Exit code 2",
59
+ * "Command failed with exit code 2"). Claude's hooks carry no exit code field;
60
+ * the error is read for the number in memory, never kept.
61
+ */
62
+ export const RE_CLAUDE_EXIT_CODE = /\bexit code (-?\d+)\b/i;
@@ -27,46 +27,4 @@ export declare const claudePayloadSchema: z.ZodObject<{
27
27
  last_assistant_message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
28
28
  stop_hook_active: z.ZodOptional<z.ZodBoolean>;
29
29
  denialReason: z.ZodOptional<z.ZodString>;
30
- }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
31
- hook_event_name: z.ZodOptional<z.ZodString>;
32
- session_id: z.ZodOptional<z.ZodString>;
33
- prompt_id: z.ZodOptional<z.ZodString>;
34
- transcript_path: z.ZodOptional<z.ZodString>;
35
- cwd: z.ZodOptional<z.ZodString>;
36
- permission_mode: z.ZodOptional<z.ZodString>;
37
- agent_id: z.ZodOptional<z.ZodString>;
38
- agent_type: z.ZodOptional<z.ZodString>;
39
- tool_name: z.ZodOptional<z.ZodString>;
40
- tool_use_id: z.ZodOptional<z.ZodString>;
41
- tool_input: z.ZodOptional<z.ZodUnknown>;
42
- tool_response: z.ZodOptional<z.ZodUnknown>;
43
- tool_error: z.ZodOptional<z.ZodUnknown>;
44
- prompt: z.ZodOptional<z.ZodString>;
45
- source: z.ZodOptional<z.ZodString>;
46
- model: z.ZodOptional<z.ZodString>;
47
- reason: z.ZodOptional<z.ZodString>;
48
- last_assistant_message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
49
- stop_hook_active: z.ZodOptional<z.ZodBoolean>;
50
- denialReason: z.ZodOptional<z.ZodString>;
51
- }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
52
- hook_event_name: z.ZodOptional<z.ZodString>;
53
- session_id: z.ZodOptional<z.ZodString>;
54
- prompt_id: z.ZodOptional<z.ZodString>;
55
- transcript_path: z.ZodOptional<z.ZodString>;
56
- cwd: z.ZodOptional<z.ZodString>;
57
- permission_mode: z.ZodOptional<z.ZodString>;
58
- agent_id: z.ZodOptional<z.ZodString>;
59
- agent_type: z.ZodOptional<z.ZodString>;
60
- tool_name: z.ZodOptional<z.ZodString>;
61
- tool_use_id: z.ZodOptional<z.ZodString>;
62
- tool_input: z.ZodOptional<z.ZodUnknown>;
63
- tool_response: z.ZodOptional<z.ZodUnknown>;
64
- tool_error: z.ZodOptional<z.ZodUnknown>;
65
- prompt: z.ZodOptional<z.ZodString>;
66
- source: z.ZodOptional<z.ZodString>;
67
- model: z.ZodOptional<z.ZodString>;
68
- reason: z.ZodOptional<z.ZodString>;
69
- last_assistant_message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
70
- stop_hook_active: z.ZodOptional<z.ZodBoolean>;
71
- denialReason: z.ZodOptional<z.ZodString>;
72
- }, z.ZodTypeAny, "passthrough">>;
30
+ }, z.core.$loose>;
@@ -95,6 +95,7 @@ function hookPatch(payload, providerEventType, context) {
95
95
  toolUseId: payload.tool_use_id,
96
96
  input: payload.tool_input,
97
97
  output: payload.tool_response,
98
+ exitCode: kind === 'shell' ? exitCodeOf(payload.tool_response) : undefined,
98
99
  providerFields: mcp ? { mcpServer: mcp.server, mcpTool: mcp.tool } : undefined
99
100
  }, capture);
100
101
  }
@@ -110,6 +111,19 @@ function hookPatch(payload, providerEventType, context) {
110
111
  }
111
112
  return {};
112
113
  }
114
+ /**
115
+ * The exit code a shell call's `tool_response` states.
116
+ *
117
+ * Codex has no failure hook: a command that exits non-zero is a `PostToolUse`
118
+ * like any other, and this number is the only sign it failed.
119
+ *
120
+ * @param response - `tool_response` as the payload carries it.
121
+ * @returns The code, or undefined when the response names none.
122
+ */
123
+ function exitCodeOf(response) {
124
+ const code = asRecord(response)?.['exit_code'];
125
+ return typeof code === 'number' && Number.isInteger(code) ? code : undefined;
126
+ }
113
127
  /**
114
128
  * Canonical type for a hook, falling back to the tool classification.
115
129
  *
@@ -27,44 +27,4 @@ export declare const codexPayloadSchema: z.ZodObject<{
27
27
  trigger: z.ZodOptional<z.ZodString>;
28
28
  last_assistant_message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
29
29
  stop_hook_active: z.ZodOptional<z.ZodBoolean>;
30
- }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
31
- hook_event_name: z.ZodOptional<z.ZodString>;
32
- session_id: z.ZodOptional<z.ZodString>;
33
- thread_id: z.ZodOptional<z.ZodString>;
34
- turn_id: z.ZodOptional<z.ZodString>;
35
- cwd: z.ZodOptional<z.ZodString>;
36
- model: z.ZodOptional<z.ZodString>;
37
- permission_mode: z.ZodOptional<z.ZodString>;
38
- agent_id: z.ZodOptional<z.ZodString>;
39
- agent_type: z.ZodOptional<z.ZodString>;
40
- tool_name: z.ZodOptional<z.ZodString>;
41
- tool_use_id: z.ZodOptional<z.ZodString>;
42
- tool_input: z.ZodOptional<z.ZodUnknown>;
43
- tool_response: z.ZodOptional<z.ZodUnknown>;
44
- prompt: z.ZodOptional<z.ZodString>;
45
- source: z.ZodOptional<z.ZodString>;
46
- reason: z.ZodOptional<z.ZodString>;
47
- trigger: z.ZodOptional<z.ZodString>;
48
- last_assistant_message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
49
- stop_hook_active: z.ZodOptional<z.ZodBoolean>;
50
- }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
51
- hook_event_name: z.ZodOptional<z.ZodString>;
52
- session_id: z.ZodOptional<z.ZodString>;
53
- thread_id: z.ZodOptional<z.ZodString>;
54
- turn_id: z.ZodOptional<z.ZodString>;
55
- cwd: z.ZodOptional<z.ZodString>;
56
- model: z.ZodOptional<z.ZodString>;
57
- permission_mode: z.ZodOptional<z.ZodString>;
58
- agent_id: z.ZodOptional<z.ZodString>;
59
- agent_type: z.ZodOptional<z.ZodString>;
60
- tool_name: z.ZodOptional<z.ZodString>;
61
- tool_use_id: z.ZodOptional<z.ZodString>;
62
- tool_input: z.ZodOptional<z.ZodUnknown>;
63
- tool_response: z.ZodOptional<z.ZodUnknown>;
64
- prompt: z.ZodOptional<z.ZodString>;
65
- source: z.ZodOptional<z.ZodString>;
66
- reason: z.ZodOptional<z.ZodString>;
67
- trigger: z.ZodOptional<z.ZodString>;
68
- last_assistant_message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
69
- stop_hook_active: z.ZodOptional<z.ZodBoolean>;
70
- }, z.ZodTypeAny, "passthrough">>;
30
+ }, z.core.$loose>;
@@ -3,7 +3,7 @@ import path from 'node:path';
3
3
  import { asRecord, compact } from '../../core/object.js';
4
4
  import { sha256Hex } from '../../events/event-id.js';
5
5
  import { resolvePaths } from '../../storage/paths.js';
6
- import { baseEvent, filePathPatch, promptPatch, responsePatch, toolPatch, withPatch } from '../shared/event-builder.js';
6
+ import { baseEvent, filePathPatch, promptPatch, responsePatch, toolCallEvidence, toolPatch, withPatch } from '../shared/event-builder.js';
7
7
  import { classifyTool, contentEvidence, mcpServerFromEndpoint, mcpToolKey, parseMcpToolName, shellCallOf, toolCompleteType, toolStartType } from '../shared/tooling.js';
8
8
  import { ATTACHMENT_FILE_PATH_KEY, CURSOR_DEDICATED_COMPLETION_KINDS, CURSOR_DISPLAY_NAME, CURSOR_EDIT_TOOL_NAME, CURSOR_EVENT_TYPE_MAP, CURSOR_PROVIDER_ID, CURSOR_READ_TOOL_NAME, CURSOR_GENERIC_TOOL_START_EVENT, CURSOR_SHELL_COMMAND_KEY, CURSOR_SHELL_EVENTS, CURSOR_SHELL_WORKDIR_KEY, CURSOR_SHELL_TOOL_NAME, CURSOR_TOOL_KINDS, CURSOR_UNKNOWN_EVENT, CURSOR_UNKNOWN_MCP_SERVER } from './constants/cursor.constants.js';
9
9
  import { cursorPayloadSchema } from './schemas/cursor.schema.js';
@@ -216,7 +216,9 @@ function shellPatch(payload, providerEventType, context) {
216
216
  tool: { name: CURSOR_SHELL_TOOL_NAME, status: completed ? 'completed' : 'started', durationMs: payload.duration },
217
217
  metadata: compact({
218
218
  command: capture.toolInput && typeof payload.command === 'string' ? payload.command : undefined,
219
- toolOutput: capture.toolOutput && completed && typeof payload.output === 'string' ? payload.output : undefined
219
+ toolOutput: capture.toolOutput && completed && typeof payload.output === 'string' ? payload.output : undefined,
220
+ // The shell hooks carry no call id and no exit code; `duration` dates the start.
221
+ toolCall: toolCallEvidence({ kind: 'shell', command: payload.command })
220
222
  })
221
223
  };
222
224
  }
@@ -250,6 +252,7 @@ function mcpPatch(payload, providerEventType, context) {
250
252
  metadata: compact({
251
253
  toolInput: capture.toolInput && payload.tool_input !== undefined ? payload.tool_input : undefined,
252
254
  toolOutput: capture.toolOutput && payload.result_json !== undefined ? payload.result_json : undefined,
255
+ toolCall: toolCallEvidence({ kind: 'mcp', input: payload.tool_input }),
253
256
  provider: compact({
254
257
  mcpServer: parsed.server ?? payload.url ?? payload.command,
255
258
  mcpTool: parsed.tool ?? payload.tool_name
@@ -13,9 +13,9 @@ export declare const cursorPayloadSchema: z.ZodObject<{
13
13
  generation_id: z.ZodOptional<z.ZodString>;
14
14
  model: z.ZodOptional<z.ZodString>;
15
15
  model_id: z.ZodOptional<z.ZodUnknown>;
16
- model_params: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
16
+ model_params: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
17
17
  cursor_version: z.ZodOptional<z.ZodString>;
18
- workspace_roots: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
18
+ workspace_roots: z.ZodOptional<z.ZodArray<z.ZodString>>;
19
19
  transcript_path: z.ZodOptional<z.ZodNullable<z.ZodString>>;
20
20
  cwd: z.ZodOptional<z.ZodString>;
21
21
  session_id: z.ZodOptional<z.ZodString>;
@@ -23,7 +23,7 @@ export declare const cursorPayloadSchema: z.ZodObject<{
23
23
  composer_mode: z.ZodOptional<z.ZodString>;
24
24
  reason: z.ZodOptional<z.ZodString>;
25
25
  prompt: z.ZodOptional<z.ZodString>;
26
- attachments: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
26
+ attachments: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
27
27
  tool_name: z.ZodOptional<z.ZodString>;
28
28
  tool_use_id: z.ZodOptional<z.ZodString>;
29
29
  tool_input: z.ZodOptional<z.ZodUnknown>;
@@ -37,7 +37,7 @@ export declare const cursorPayloadSchema: z.ZodObject<{
37
37
  url: z.ZodOptional<z.ZodString>;
38
38
  result_json: z.ZodOptional<z.ZodString>;
39
39
  file_path: z.ZodOptional<z.ZodString>;
40
- edits: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
40
+ edits: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
41
41
  subagent_id: z.ZodOptional<z.ZodString>;
42
42
  subagent_type: z.ZodOptional<z.ZodString>;
43
43
  subagent_model: z.ZodOptional<z.ZodString>;
@@ -47,84 +47,4 @@ export declare const cursorPayloadSchema: z.ZodObject<{
47
47
  text: z.ZodOptional<z.ZodString>;
48
48
  trigger: z.ZodOptional<z.ZodString>;
49
49
  context_usage_percent: z.ZodOptional<z.ZodNumber>;
50
- }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
51
- hook_event_name: z.ZodOptional<z.ZodString>;
52
- conversation_id: z.ZodOptional<z.ZodString>;
53
- generation_id: z.ZodOptional<z.ZodString>;
54
- model: z.ZodOptional<z.ZodString>;
55
- model_id: z.ZodOptional<z.ZodUnknown>;
56
- model_params: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
57
- cursor_version: z.ZodOptional<z.ZodString>;
58
- workspace_roots: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
59
- transcript_path: z.ZodOptional<z.ZodNullable<z.ZodString>>;
60
- cwd: z.ZodOptional<z.ZodString>;
61
- session_id: z.ZodOptional<z.ZodString>;
62
- is_background_agent: z.ZodOptional<z.ZodBoolean>;
63
- composer_mode: z.ZodOptional<z.ZodString>;
64
- reason: z.ZodOptional<z.ZodString>;
65
- prompt: z.ZodOptional<z.ZodString>;
66
- attachments: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
67
- tool_name: z.ZodOptional<z.ZodString>;
68
- tool_use_id: z.ZodOptional<z.ZodString>;
69
- tool_input: z.ZodOptional<z.ZodUnknown>;
70
- tool_output: z.ZodOptional<z.ZodUnknown>;
71
- error_message: z.ZodOptional<z.ZodString>;
72
- failure_type: z.ZodOptional<z.ZodString>;
73
- duration: z.ZodOptional<z.ZodNumber>;
74
- duration_ms: z.ZodOptional<z.ZodNumber>;
75
- command: z.ZodOptional<z.ZodString>;
76
- output: z.ZodOptional<z.ZodString>;
77
- url: z.ZodOptional<z.ZodString>;
78
- result_json: z.ZodOptional<z.ZodString>;
79
- file_path: z.ZodOptional<z.ZodString>;
80
- edits: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
81
- subagent_id: z.ZodOptional<z.ZodString>;
82
- subagent_type: z.ZodOptional<z.ZodString>;
83
- subagent_model: z.ZodOptional<z.ZodString>;
84
- parent_conversation_id: z.ZodOptional<z.ZodString>;
85
- task: z.ZodOptional<z.ZodString>;
86
- status: z.ZodOptional<z.ZodString>;
87
- text: z.ZodOptional<z.ZodString>;
88
- trigger: z.ZodOptional<z.ZodString>;
89
- context_usage_percent: z.ZodOptional<z.ZodNumber>;
90
- }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
91
- hook_event_name: z.ZodOptional<z.ZodString>;
92
- conversation_id: z.ZodOptional<z.ZodString>;
93
- generation_id: z.ZodOptional<z.ZodString>;
94
- model: z.ZodOptional<z.ZodString>;
95
- model_id: z.ZodOptional<z.ZodUnknown>;
96
- model_params: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
97
- cursor_version: z.ZodOptional<z.ZodString>;
98
- workspace_roots: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
99
- transcript_path: z.ZodOptional<z.ZodNullable<z.ZodString>>;
100
- cwd: z.ZodOptional<z.ZodString>;
101
- session_id: z.ZodOptional<z.ZodString>;
102
- is_background_agent: z.ZodOptional<z.ZodBoolean>;
103
- composer_mode: z.ZodOptional<z.ZodString>;
104
- reason: z.ZodOptional<z.ZodString>;
105
- prompt: z.ZodOptional<z.ZodString>;
106
- attachments: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
107
- tool_name: z.ZodOptional<z.ZodString>;
108
- tool_use_id: z.ZodOptional<z.ZodString>;
109
- tool_input: z.ZodOptional<z.ZodUnknown>;
110
- tool_output: z.ZodOptional<z.ZodUnknown>;
111
- error_message: z.ZodOptional<z.ZodString>;
112
- failure_type: z.ZodOptional<z.ZodString>;
113
- duration: z.ZodOptional<z.ZodNumber>;
114
- duration_ms: z.ZodOptional<z.ZodNumber>;
115
- command: z.ZodOptional<z.ZodString>;
116
- output: z.ZodOptional<z.ZodString>;
117
- url: z.ZodOptional<z.ZodString>;
118
- result_json: z.ZodOptional<z.ZodString>;
119
- file_path: z.ZodOptional<z.ZodString>;
120
- edits: z.ZodOptional<z.ZodArray<z.ZodUnknown, "many">>;
121
- subagent_id: z.ZodOptional<z.ZodString>;
122
- subagent_type: z.ZodOptional<z.ZodString>;
123
- subagent_model: z.ZodOptional<z.ZodString>;
124
- parent_conversation_id: z.ZodOptional<z.ZodString>;
125
- task: z.ZodOptional<z.ZodString>;
126
- status: z.ZodOptional<z.ZodString>;
127
- text: z.ZodOptional<z.ZodString>;
128
- trigger: z.ZodOptional<z.ZodString>;
129
- context_usage_percent: z.ZodOptional<z.ZodNumber>;
130
- }, z.ZodTypeAny, "passthrough">>;
50
+ }, z.core.$loose>;
@@ -5,6 +5,8 @@ export declare const GEMINI_HOME_VAR = "GEMINI_HOME";
5
5
  export declare const GEMINI_CLI_VAR = "GEMINI_CLI";
6
6
  export declare const GEMINI_HOME_DIR = ".gemini";
7
7
  export declare const GEMINI_SETTINGS_FILE = "settings.json";
8
+ /** Gemini's own env file: it loads this at start, unlike the settings.json `env` block. */
9
+ export declare const GEMINI_ENV_FILE = ".env";
8
10
  export declare const GEMINI_EXECUTABLES: readonly ["gemini", "gemini-cli"];
9
11
  /** Hook events AgentWatch registers in Gemini CLI. */
10
12
  export declare const GEMINI_HOOK_EVENTS: readonly ["SessionStart", "SessionEnd", "BeforeAgent", "AfterAgent", "BeforeTool", "AfterTool", "Notification", "PreCompress"];
@@ -4,6 +4,8 @@ export const GEMINI_HOME_VAR = 'GEMINI_HOME';
4
4
  export const GEMINI_CLI_VAR = 'GEMINI_CLI';
5
5
  export const GEMINI_HOME_DIR = '.gemini';
6
6
  export const GEMINI_SETTINGS_FILE = 'settings.json';
7
+ /** Gemini's own env file: it loads this at start, unlike the settings.json `env` block. */
8
+ export const GEMINI_ENV_FILE = '.env';
7
9
  export const GEMINI_EXECUTABLES = ['gemini', 'gemini-cli'];
8
10
  /** Hook events AgentWatch registers in Gemini CLI. */
9
11
  export const GEMINI_HOOK_EVENTS = ['SessionStart', 'SessionEnd', 'BeforeAgent', 'AfterAgent', 'BeforeTool', 'AfterTool', 'Notification', 'PreCompress'];
@@ -1,5 +1,10 @@
1
- /** Settings key holding the environment block telemetry is configured through. */
1
+ /** The settings.json block older versions wrote telemetry into; Gemini never applied it. */
2
2
  export declare const ENV_BLOCK_KEY = "env";
3
+ /**
4
+ * Gemini's native settings.json telemetry block. Owned fields are recorded as
5
+ * `telemetry.<field>`, beside the `.env` key names.
6
+ */
7
+ export declare const TELEMETRY_BLOCK_KEY = "telemetry";
3
8
  /** Where Gemini reads OTLP auth from; it has no header-helper mechanism. */
4
9
  export declare const OTLP_HEADERS_KEY = "OTEL_EXPORTER_OTLP_HEADERS";
5
10
  /**
@@ -40,3 +45,7 @@ export declare const GEMINI_TELEMETRY_TARGET_LOCAL = "local";
40
45
  * rewrites it alone.
41
46
  */
42
47
  export declare const RE_BEARER_PAIR: RegExp;
48
+ /** One `KEY=value` line of a dotenv file, `export` prefix allowed. */
49
+ export declare const RE_ENV_LINE: RegExp;
50
+ /** A value wrapped in matching quotes, inner part captured. */
51
+ export declare const RE_QUOTED_VALUE: RegExp;
@@ -1,5 +1,10 @@
1
- /** Settings key holding the environment block telemetry is configured through. */
1
+ /** The settings.json block older versions wrote telemetry into; Gemini never applied it. */
2
2
  export const ENV_BLOCK_KEY = 'env';
3
+ /**
4
+ * Gemini's native settings.json telemetry block. Owned fields are recorded as
5
+ * `telemetry.<field>`, beside the `.env` key names.
6
+ */
7
+ export const TELEMETRY_BLOCK_KEY = 'telemetry';
3
8
  /** Where Gemini reads OTLP auth from; it has no header-helper mechanism. */
4
9
  export const OTLP_HEADERS_KEY = 'OTEL_EXPORTER_OTLP_HEADERS';
5
10
  /**
@@ -54,4 +59,8 @@ export const GEMINI_TELEMETRY_TARGET_LOCAL = 'local';
54
59
  * token rotation changes only this, so drift checks ignore it and the hook
55
60
  * rewrites it alone.
56
61
  */
57
- export const RE_BEARER_PAIR = /(Authorization=Bearer )([^,]*)/g;
62
+ export const RE_BEARER_PAIR = /(Authorization=Bearer )([^,"'\s]*)/g;
63
+ /** One `KEY=value` line of a dotenv file, `export` prefix allowed. */
64
+ export const RE_ENV_LINE = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$/;
65
+ /** A value wrapped in matching quotes, inner part captured. */
66
+ export const RE_QUOTED_VALUE = /^(['"])(.*)\1$/;
@@ -7,6 +7,17 @@ import type { DetectionResult } from '../types/provider.types.js';
7
7
  * @returns Absolute path of `settings.json`.
8
8
  */
9
9
  export declare function geminiSettingsPath(env: Env): string;
10
+ /**
11
+ * Where native telemetry is configured.
12
+ *
13
+ * Gemini CLI 0.63+ loads `~/.gemini/.env` into its process at start (for a
14
+ * trusted folder) but does not apply the settings.json `env` block, and its
15
+ * `telemetry` settings have no header option for the bearer.
16
+ *
17
+ * @param env - Environment supplying HOME and GEMINI_HOME.
18
+ * @returns Absolute path of the `.env` beside `settings.json`.
19
+ */
20
+ export declare function geminiEnvPath(env: Env): string;
10
21
  /**
11
22
  * Whether Gemini CLI is installed here, and whether our hooks are registered.
12
23
  *
@@ -4,7 +4,7 @@ import { asRecord } from '../../core/object.js';
4
4
  import { findExecutable } from '../../core/which.js';
5
5
  import { readJsonFile } from '../../storage/json-file.js';
6
6
  import { HOOK_COMMAND_MARKER } from '../constants/provider.constants.js';
7
- import { GEMINI_CLI_VAR, GEMINI_EXECUTABLES, GEMINI_HOME_DIR, GEMINI_HOME_VAR, GEMINI_SETTINGS_FILE } from './constants/gemini.constants.js';
7
+ import { GEMINI_CLI_VAR, GEMINI_ENV_FILE, GEMINI_EXECUTABLES, GEMINI_HOME_DIR, GEMINI_HOME_VAR, GEMINI_SETTINGS_FILE } from './constants/gemini.constants.js';
8
8
  /**
9
9
  * Gemini CLI's configuration root.
10
10
  *
@@ -23,6 +23,19 @@ function geminiHome(env) {
23
23
  export function geminiSettingsPath(env) {
24
24
  return path.join(geminiHome(env), GEMINI_SETTINGS_FILE);
25
25
  }
26
+ /**
27
+ * Where native telemetry is configured.
28
+ *
29
+ * Gemini CLI 0.63+ loads `~/.gemini/.env` into its process at start (for a
30
+ * trusted folder) but does not apply the settings.json `env` block, and its
31
+ * `telemetry` settings have no header option for the bearer.
32
+ *
33
+ * @param env - Environment supplying HOME and GEMINI_HOME.
34
+ * @returns Absolute path of the `.env` beside `settings.json`.
35
+ */
36
+ export function geminiEnvPath(env) {
37
+ return path.join(geminiHome(env), GEMINI_ENV_FILE);
38
+ }
26
39
  /**
27
40
  * Whether Gemini CLI is installed here, and whether our hooks are registered.
28
41
  *
@@ -11,9 +11,9 @@ export declare function installGeminiHooks(context: SetupContext): Promise<Setup
11
11
  /**
12
12
  * Remove AgentWatch's hooks from Gemini CLI's `settings.json`.
13
13
  *
14
- * The agent is forgotten entirely rather than just having its hook fields
15
- * cleared: Gemini's hooks and its telemetry live in the same file, so once that
16
- * file has nothing of ours left there is nothing to describe.
14
+ * Only the hook fields are cleared: the telemetry record lives on, since
15
+ * telemetry is in `~/.gemini/.env` and its uninstall needs to know which lines
16
+ * and which file mode are ours.
17
17
  *
18
18
  * @param context - Environment, paths and current install state.
19
19
  * @returns Whether the file changed, what to tell the user, and the next
@@ -2,7 +2,7 @@ import { asRecord } from '../../core/object.js';
2
2
  import { backupFile } from '../../storage/atomic-file.js';
3
3
  import { readJsonFile } from '../../storage/json-file.js';
4
4
  import { registerOurHandlers, stripOurHandlers, sweepUnregisteredEvents, withHooksBlock, writeJsonValidated } from '../shared/hook-config.js';
5
- import { withHookInstall, withoutAgent } from '../shared/install-record.js';
5
+ import { withHookInstall, withoutHookInstall } from '../shared/install-record.js';
6
6
  import { geminiSettingsPath } from './gemini.detect.js';
7
7
  import { GEMINI_HOOK_EVENTS, GEMINI_HOOK_TIMEOUT_MILLISECONDS, GEMINI_MATCHED_EVENTS, GEMINI_PROVIDER_ID } from './constants/gemini.constants.js';
8
8
  export { GEMINI_HOOK_EVENTS } from './constants/gemini.constants.js';
@@ -46,9 +46,9 @@ export async function installGeminiHooks(context) {
46
46
  /**
47
47
  * Remove AgentWatch's hooks from Gemini CLI's `settings.json`.
48
48
  *
49
- * The agent is forgotten entirely rather than just having its hook fields
50
- * cleared: Gemini's hooks and its telemetry live in the same file, so once that
51
- * file has nothing of ours left there is nothing to describe.
49
+ * Only the hook fields are cleared: the telemetry record lives on, since
50
+ * telemetry is in `~/.gemini/.env` and its uninstall needs to know which lines
51
+ * and which file mode are ours.
52
52
  *
53
53
  * @param context - Environment, paths and current install state.
54
54
  * @returns Whether the file changed, what to tell the user, and the next
@@ -57,7 +57,7 @@ export async function installGeminiHooks(context) {
57
57
  export async function uninstallGeminiHooks(context) {
58
58
  const settingsPath = geminiSettingsPath(context.env);
59
59
  const read = await readJsonFile(settingsPath);
60
- const forgotten = withoutAgent(context.installState, GEMINI_PROVIDER_ID);
60
+ const forgotten = withoutHookInstall(context.installState, GEMINI_PROVIDER_ID);
61
61
  if (read.state === 'missing') {
62
62
  return { ok: true, changed: false, messages: ['no Gemini settings file'], installState: forgotten };
63
63
  }
@@ -1,7 +1,7 @@
1
1
  import type { Env } from '../../core/types/core.types.js';
2
2
  import type { AgentWatchConfig, OtelSignalName } from '../../config/types/config.types.js';
3
3
  import type { BearerRewriteContext, NativeTelemetryConfigurator, NativeTelemetryStatus, SetupContext, SetupOutcome } from '../types/provider.types.js';
4
- /** Configures Gemini CLI's own OTLP export. */
4
+ /** Configures Gemini CLI's own OTLP export, through `~/.gemini/.env` and settings.json. */
5
5
  export declare class GeminiOtelConfigurator implements NativeTelemetryConfigurator {
6
6
  /**
7
7
  * Whether this agent can export native telemetry at all.
@@ -18,7 +18,7 @@ export declare class GeminiOtelConfigurator implements NativeTelemetryConfigurat
18
18
  */
19
19
  inspect(context: SetupContext): Promise<NativeTelemetryStatus>;
20
20
  /**
21
- * Write the telemetry configuration into Gemini CLI's settings.
21
+ * Write the telemetry configuration into Gemini CLI's `.env`.
22
22
  *
23
23
  * @param context - Environment, paths, config and install state.
24
24
  * @returns Whether the file changed, what to tell the user, and the next
@@ -29,7 +29,7 @@ export declare class GeminiOtelConfigurator implements NativeTelemetryConfigurat
29
29
  * Remove the telemetry configuration AgentWatch wrote.
30
30
  *
31
31
  * @param context - Environment, paths, config and install state.
32
- * @returns Whether the file changed, what to tell the user, and the next
32
+ * @returns Whether a file changed, what to tell the user, and the next
33
33
  * install state.
34
34
  */
35
35
  uninstall(context: SetupContext): Promise<SetupOutcome>;
@@ -48,10 +48,10 @@ export declare class GeminiOtelConfigurator implements NativeTelemetryConfigurat
48
48
  */
49
49
  private configureDisabled;
50
50
  /**
51
- * Swap the bearer in our `OTEL_EXPORTER_OTLP_HEADERS` for the current one.
51
+ * Swap the bearer in our `OTEL_EXPORTER_OTLP_HEADERS` line for the current one.
52
52
  *
53
- * Only when a setup recorded the key as ours, and only the bearer in it
54
- * changes. No backup: one per rotation would collect copies of every token.
53
+ * Only when a setup recorded the key as ours, and only the bearer in that
54
+ * line changes. No backup: one per rotation would collect copies of every token.
55
55
  *
56
56
  * @param context - The recorded file, its contents as read, install state and the current bearer.
57
57
  * @returns True when the file was rewritten.