@agent-watch-ai/edge 0.3.1 → 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.
- package/CHANGELOG.md +75 -0
- package/README.md +10 -6
- package/SECURITY.md +7 -4
- package/dist/cli/constants/cli.constants.d.ts +2 -0
- package/dist/cli/constants/cli.constants.js +3 -1
- package/dist/cli/doctor.js +13 -2
- package/dist/cli/setup.js +138 -29
- package/dist/cli/toggle.js +5 -1
- package/dist/cli/types/cli.types.d.ts +6 -0
- package/dist/cli/uninstall.js +1 -1
- package/dist/cli.js +14 -3
- package/dist/config/config-store.d.ts +1 -1
- package/dist/config/config-store.js +2 -2
- package/dist/config/constants/config.constants.d.ts +4 -1
- package/dist/config/constants/config.constants.js +7 -2
- package/dist/config/repo-config.js +1 -1
- package/dist/config/schemas/config.schema.d.ts +113 -767
- package/dist/config/schemas/config.schema.js +17 -8
- package/dist/credentials/constants/credentials.constants.d.ts +8 -0
- package/dist/credentials/constants/credentials.constants.js +9 -1
- package/dist/credentials/credential-status.js +8 -4
- package/dist/credentials/credentials.d.ts +16 -2
- package/dist/credentials/credentials.js +30 -5
- package/dist/credentials/device-api.d.ts +10 -1
- package/dist/credentials/device-api.js +12 -1
- package/dist/credentials/identity.d.ts +12 -1
- package/dist/credentials/identity.js +12 -1
- package/dist/credentials/migration.d.ts +1 -1
- package/dist/credentials/migration.js +1 -1
- package/dist/credentials/schemas/device-api.schema.d.ts +4 -51
- package/dist/credentials/schemas/device-state.schema.d.ts +3 -38
- package/dist/credentials/sign-in.d.ts +14 -1
- package/dist/credentials/sign-in.js +24 -5
- package/dist/credentials/types/credentials.types.d.ts +12 -1
- package/dist/enforcement/decision-client.js +2 -1
- package/dist/enforcement/enforcement.js +7 -5
- package/dist/enforcement/types/enforcement.types.d.ts +2 -2
- package/dist/git/code-state.d.ts +33 -0
- package/dist/git/code-state.js +44 -0
- package/dist/git/constants/git.constants.d.ts +6 -0
- package/dist/git/constants/git.constants.js +6 -0
- package/dist/git/index.d.ts +2 -1
- package/dist/git/index.js +1 -0
- package/dist/git/types/git.types.d.ts +6 -0
- package/dist/pipeline/constants/pipeline.constants.d.ts +3 -0
- package/dist/pipeline/constants/pipeline.constants.js +3 -0
- package/dist/pipeline/hook-pipeline.js +56 -7
- package/dist/privacy/command-fingerprint.d.ts +42 -0
- package/dist/privacy/command-fingerprint.js +249 -0
- package/dist/privacy/constants/command-fingerprint.constants.d.ts +34 -0
- package/dist/privacy/constants/command-fingerprint.constants.js +38 -0
- package/dist/privacy/index.d.ts +3 -1
- package/dist/privacy/index.js +2 -0
- package/dist/privacy/product-capture.js +20 -0
- package/dist/privacy/types/privacy.types.d.ts +7 -0
- package/dist/providers/antigravity/antigravity.adapter.js +3 -0
- package/dist/providers/antigravity/schemas/antigravity.schema.d.ts +18 -492
- package/dist/providers/claude/claude.adapter.js +12 -1
- package/dist/providers/claude/constants/claude.constants.d.ts +6 -0
- package/dist/providers/claude/constants/claude.constants.js +6 -0
- package/dist/providers/claude/schemas/claude.schema.d.ts +1 -43
- package/dist/providers/codex/codex.adapter.js +14 -0
- package/dist/providers/codex/codex.otel.d.ts +12 -1
- package/dist/providers/codex/codex.otel.js +61 -11
- package/dist/providers/codex/constants/codex.otel.constants.d.ts +5 -0
- package/dist/providers/codex/constants/codex.otel.constants.js +5 -0
- package/dist/providers/codex/schemas/codex.schema.d.ts +1 -41
- package/dist/providers/constants/provider.constants.d.ts +8 -0
- package/dist/providers/constants/provider.constants.js +8 -0
- package/dist/providers/cursor/constants/cursor.constants.d.ts +2 -0
- package/dist/providers/cursor/constants/cursor.constants.js +2 -0
- package/dist/providers/cursor/cursor.adapter.js +84 -5
- package/dist/providers/cursor/schemas/cursor.schema.d.ts +5 -85
- package/dist/providers/gemini/constants/gemini.constants.d.ts +2 -0
- package/dist/providers/gemini/constants/gemini.constants.js +2 -0
- package/dist/providers/gemini/constants/gemini.otel.constants.d.ts +16 -1
- package/dist/providers/gemini/constants/gemini.otel.constants.js +16 -1
- package/dist/providers/gemini/gemini.detect.d.ts +11 -0
- package/dist/providers/gemini/gemini.detect.js +14 -1
- package/dist/providers/gemini/gemini.hooks.d.ts +3 -3
- package/dist/providers/gemini/gemini.hooks.js +5 -5
- package/dist/providers/gemini/gemini.otel.d.ts +14 -4
- package/dist/providers/gemini/gemini.otel.js +418 -107
- package/dist/providers/gemini/schemas/gemini.schema.d.ts +1 -49
- package/dist/providers/shared/bearer-rewrite.d.ts +19 -0
- package/dist/providers/shared/bearer-rewrite.js +46 -0
- package/dist/providers/shared/constants/tooling.constants.d.ts +6 -0
- package/dist/providers/shared/constants/tooling.constants.js +6 -0
- package/dist/providers/shared/event-builder.d.ts +17 -2
- package/dist/providers/shared/event-builder.js +43 -3
- package/dist/providers/shared/install-record.d.ts +2 -0
- package/dist/providers/shared/install-record.js +3 -2
- package/dist/providers/shared/tooling.d.ts +35 -0
- package/dist/providers/shared/tooling.js +61 -1
- package/dist/providers/shared/types/adapter.types.d.ts +18 -0
- package/dist/providers/types/provider.types.d.ts +24 -0
- package/dist/storage/atomic-file.d.ts +14 -0
- package/dist/storage/atomic-file.js +19 -0
- package/dist/storage/constants/storage.constants.d.ts +2 -0
- package/dist/storage/constants/storage.constants.js +2 -0
- package/dist/storage/schemas/storage.schema.d.ts +11 -175
- package/dist/storage/schemas/storage.schema.js +7 -1
- package/dist/transport/schemas/queue.schema.d.ts +1 -16
- package/dist/transport/schemas/queue.schema.js +1 -1
- package/dist/turns/constants/turns.constants.d.ts +17 -0
- package/dist/turns/constants/turns.constants.js +17 -0
- package/dist/turns/index.d.ts +3 -2
- package/dist/turns/index.js +1 -0
- package/dist/turns/tool-events.d.ts +15 -0
- package/dist/turns/tool-events.js +59 -0
- package/dist/turns/turn-state.js +2 -2
- package/dist/turns/turn-summary.d.ts +1 -1
- package/dist/turns/turn-summary.js +1 -0
- package/dist/turns/turn-tracker.js +138 -7
- package/dist/turns/types/turn-state.types.d.ts +28 -1
- package/dist/turns/types/turn-summary.types.d.ts +30 -0
- package/dist/turns/types/turn-tracker.types.d.ts +10 -0
- package/dist/turns/work-checkout.d.ts +5 -3
- package/dist/turns/work-checkout.js +46 -12
- package/docs/AUDIT_PROMPT.md +11 -0
- package/docs/DATA_HANDLING.md +69 -14
- package/docs/ENTERPRISE_DEPLOYMENT.md +21 -5
- package/package.json +9 -8
|
@@ -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
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Env } from '../../core/types/core.types.js';
|
|
2
2
|
import type { AgentWatchConfig, OtelSignalName } from '../../config/types/config.types.js';
|
|
3
|
-
import type { NativeTelemetryConfigurator, NativeTelemetryStatus, SetupContext, SetupOutcome } from '../types/provider.types.js';
|
|
3
|
+
import type { BearerRewriteContext, NativeTelemetryConfigurator, NativeTelemetryStatus, SetupContext, SetupOutcome } from '../types/provider.types.js';
|
|
4
4
|
/**
|
|
5
5
|
* Configures Codex's own OTLP export.
|
|
6
6
|
*
|
|
@@ -44,6 +44,17 @@ export declare class CodexOtelConfigurator implements NativeTelemetryConfigurato
|
|
|
44
44
|
* install state.
|
|
45
45
|
*/
|
|
46
46
|
uninstall(context: SetupContext): Promise<SetupOutcome>;
|
|
47
|
+
/**
|
|
48
|
+
* Swap the bearer in our exporters for the current one.
|
|
49
|
+
*
|
|
50
|
+
* Only the bearer in our own `[otel]` table changes: an MCP server's
|
|
51
|
+
* `Authorization` that Codex parked inside our markers is not ours. No
|
|
52
|
+
* backup: one per rotation would collect copies of every token.
|
|
53
|
+
*
|
|
54
|
+
* @param context - The recorded file, its contents as read and the current bearer.
|
|
55
|
+
* @returns True when the file was rewritten.
|
|
56
|
+
*/
|
|
57
|
+
rewriteBearer(context: BearerRewriteContext): Promise<boolean>;
|
|
47
58
|
/**
|
|
48
59
|
* Where the managed block's exporters send. The block is AgentWatch's whole,
|
|
49
60
|
* so every endpoint in it is.
|
|
@@ -2,13 +2,15 @@ import fs from 'node:fs/promises';
|
|
|
2
2
|
import { parse as parseToml } from 'smol-toml';
|
|
3
3
|
import { asRecord } from '../../core/object.js';
|
|
4
4
|
import { joinUrl, otlpBaseUrl, toolContentConsented } from '../../config/config.js';
|
|
5
|
-
import { backupFile, currentMode, writeFileAtomic } from '../../storage/atomic-file.js';
|
|
5
|
+
import { backupFile, currentMode, writeFileAtomic, writeIfUnchanged } from '../../storage/atomic-file.js';
|
|
6
6
|
import { SECRET_FILE_MODE } from '../../storage/constants/storage.constants.js';
|
|
7
|
+
import { deviceFor, hasCredential } from '../../credentials/identity.js';
|
|
8
|
+
import { BEARER_PLACEHOLDER } from '../constants/provider.constants.js';
|
|
7
9
|
import { withOtelInstall, withoutOtelInstall } from '../shared/install-record.js';
|
|
8
10
|
import { INSTALLATION_HEADER } from '../../transport/constants/transport.constants.js';
|
|
9
11
|
import { codexConfigTomlPath } from './codex.detect.js';
|
|
10
12
|
import { CODEX_PROVIDER_ID } from './constants/codex.constants.js';
|
|
11
|
-
import { BLOCK_END, BLOCK_START, CODEX_EXPORTER_KEYS, CODEX_OTEL_SIGNALS, LOGS_PATH, OTEL_TABLE_KEY, OTLP_HTTP_KEY, RE_LEADING_NEWLINE, RE_TOML_BACKSLASH, RE_TOML_QUOTE, RE_TOML_TABLE_HEADER, RE_TRAILING_NEWLINES, TRACES_PATH } from './constants/codex.otel.constants.js';
|
|
13
|
+
import { BLOCK_END, BLOCK_START, CODEX_EXPORTER_KEYS, CODEX_OTEL_SIGNALS, LOGS_PATH, OTEL_TABLE_KEY, OTLP_HTTP_KEY, RE_BEARER_HEADER, RE_LEADING_NEWLINE, RE_TOML_BACKSLASH, RE_TOML_QUOTE, RE_TOML_TABLE_HEADER, RE_TRAILING_NEWLINES, TRACES_PATH } from './constants/codex.otel.constants.js';
|
|
12
14
|
/**
|
|
13
15
|
* Configures Codex's own OTLP export.
|
|
14
16
|
*
|
|
@@ -70,7 +72,7 @@ export class CodexOtelConfigurator {
|
|
|
70
72
|
return { ok: false, changed: false, messages: ['no backend endpoint configured'] };
|
|
71
73
|
const configPath = codexConfigTomlPath(context.env);
|
|
72
74
|
const raw = (await readFileOrUndefined(configPath)) ?? '';
|
|
73
|
-
const block = renderBlock(otlpBase, context.
|
|
75
|
+
const block = renderBlock(otlpBase, context.bearer, context.config.otel, context.config.installationId);
|
|
74
76
|
const next = raw.includes(BLOCK_START) ? replaceBlock(raw, block) : appendBlock(raw, block);
|
|
75
77
|
if (typeof next !== 'string')
|
|
76
78
|
return { ok: false, changed: false, messages: [next.error(configPath)] };
|
|
@@ -85,8 +87,8 @@ export class CodexOtelConfigurator {
|
|
|
85
87
|
// The managed block may carry the bearer token, so the file becomes private
|
|
86
88
|
// — but this file is Codex's, not ours, so the mode it had first is
|
|
87
89
|
// recorded and uninstall puts it back.
|
|
88
|
-
const priorMode = context.
|
|
89
|
-
await writeFileAtomic(configPath, next, context.
|
|
90
|
+
const priorMode = context.bearer ? await currentMode(configPath) : undefined;
|
|
91
|
+
await writeFileAtomic(configPath, next, context.bearer ? SECRET_FILE_MODE : undefined);
|
|
90
92
|
return {
|
|
91
93
|
ok: true,
|
|
92
94
|
changed: true,
|
|
@@ -138,6 +140,22 @@ export class CodexOtelConfigurator {
|
|
|
138
140
|
installState: withoutOtelInstall(context.installState, CODEX_PROVIDER_ID)
|
|
139
141
|
};
|
|
140
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Swap the bearer in our exporters for the current one.
|
|
145
|
+
*
|
|
146
|
+
* Only the bearer in our own `[otel]` table changes: an MCP server's
|
|
147
|
+
* `Authorization` that Codex parked inside our markers is not ours. No
|
|
148
|
+
* backup: one per rotation would collect copies of every token.
|
|
149
|
+
*
|
|
150
|
+
* @param context - The recorded file, its contents as read and the current bearer.
|
|
151
|
+
* @returns True when the file was rewritten.
|
|
152
|
+
*/
|
|
153
|
+
async rewriteBearer(context) {
|
|
154
|
+
const next = withBearer(context.raw, context.bearer);
|
|
155
|
+
if (next === undefined || next === context.raw || tryParseToml(next) === undefined)
|
|
156
|
+
return false;
|
|
157
|
+
return writeIfUnchanged(context.configPath, context.raw, next, SECRET_FILE_MODE);
|
|
158
|
+
}
|
|
141
159
|
/**
|
|
142
160
|
* Where the managed block's exporters send. The block is AgentWatch's whole,
|
|
143
161
|
* so every endpoint in it is.
|
|
@@ -243,8 +261,15 @@ function inspectManagedBlock(raw, config) {
|
|
|
243
261
|
const otlpBase = otlpBaseUrl(config);
|
|
244
262
|
if (!otlpBase)
|
|
245
263
|
return { supported: true, configured: false, detail: 'no backend endpoint configured' };
|
|
246
|
-
|
|
247
|
-
|
|
264
|
+
// The bearer's value is not compared: it is the access token, which the hook
|
|
265
|
+
// path rotates. Only whether a header is there, when there is a credential.
|
|
266
|
+
// An install key still in the block once a device exists is stale.
|
|
267
|
+
const block = extractBlock(raw);
|
|
268
|
+
const device = deviceFor(config);
|
|
269
|
+
if (device && config.token && block?.includes(config.token))
|
|
270
|
+
return { supported: true, configured: false, detail: 'AgentWatch [otel] block still holds the install key — run `agentwatch setup`' };
|
|
271
|
+
const actual = block?.replace(RE_BEARER_HEADER, `$1${BEARER_PLACEHOLDER}$3`);
|
|
272
|
+
const expected = renderBlock(otlpBase, hasCredential(config) ? BEARER_PLACEHOLDER : undefined, config.otel, config.installationId).trim();
|
|
248
273
|
if (actual === expected)
|
|
249
274
|
return { supported: true, configured: true };
|
|
250
275
|
return { supported: true, configured: false, detail: 'AgentWatch [otel] block is incomplete or stale — run `agentwatch setup`' };
|
|
@@ -258,13 +283,15 @@ function inspectManagedBlock(raw, config) {
|
|
|
258
283
|
* @param otlpBase - Backend OTLP base URL.
|
|
259
284
|
* @param token - Bearer token, when one is configured.
|
|
260
285
|
* @param signals - The signal selection.
|
|
286
|
+
* @param installationId - This installation's id, when one exists.
|
|
261
287
|
* @returns The block text, newline-terminated.
|
|
262
288
|
*/
|
|
263
289
|
function renderBlock(otlpBase, token, signals, installationId) {
|
|
264
|
-
// Codex has no header helper
|
|
265
|
-
//
|
|
266
|
-
//
|
|
267
|
-
//
|
|
290
|
+
// Codex has no header helper and reads this map once, when a session starts
|
|
291
|
+
// (docs/NATIVE_OTLP_TOKENS.md), so the bearer is the short-lived access token
|
|
292
|
+
// and the hook path rewrites it as it rotates. The installation id is fixed
|
|
293
|
+
// for the life of the config, so that suits it; a developer identity would
|
|
294
|
+
// not, which is why one is never put here.
|
|
268
295
|
const headers = token
|
|
269
296
|
? `, headers = { ${tomlHeaders(token, installationId)} }`
|
|
270
297
|
: '';
|
|
@@ -299,6 +326,29 @@ function tomlHeaders(token, installationId) {
|
|
|
299
326
|
}
|
|
300
327
|
return pairs.join(', ');
|
|
301
328
|
}
|
|
329
|
+
/**
|
|
330
|
+
* The file with our exporters' bearer set to this one.
|
|
331
|
+
*
|
|
332
|
+
* @param raw - The whole config.toml.
|
|
333
|
+
* @param bearer - The bearer to present.
|
|
334
|
+
* @returns The next contents, or undefined when there is no well-formed block.
|
|
335
|
+
*/
|
|
336
|
+
function withBearer(raw, bearer) {
|
|
337
|
+
const span = managedSpan(raw);
|
|
338
|
+
if (!span)
|
|
339
|
+
return undefined;
|
|
340
|
+
// Our table runs from its `[otel]` header to the first foreign table;
|
|
341
|
+
// `managed` re-joins the span without that, so its length up to the end
|
|
342
|
+
// marker is ours in the raw text. A table Codex parked before our header, or
|
|
343
|
+
// a span with no header at all, is never touched.
|
|
344
|
+
const ownedEnd = span.start + span.managed.length - BLOCK_END.length;
|
|
345
|
+
const header = raw.indexOf(`\n[${OTEL_TABLE_KEY}]`, span.start);
|
|
346
|
+
const ownedStart = header + 1;
|
|
347
|
+
if (header === -1 || ownedStart >= ownedEnd)
|
|
348
|
+
return undefined;
|
|
349
|
+
const owned = raw.slice(ownedStart, ownedEnd).replace(RE_BEARER_HEADER, (_match, head, _old, tail) => head + escapeTomlString(bearer) + tail);
|
|
350
|
+
return raw.slice(0, ownedStart) + owned + raw.slice(ownedEnd);
|
|
351
|
+
}
|
|
302
352
|
/**
|
|
303
353
|
* Replace, or remove, the marker-delimited block.
|
|
304
354
|
*
|
|
@@ -25,3 +25,8 @@ export declare const RE_TOML_BACKSLASH: RegExp;
|
|
|
25
25
|
export declare const RE_TOML_QUOTE: RegExp;
|
|
26
26
|
/** Start of any TOML table header, used to find where our block stops being ours. */
|
|
27
27
|
export declare const RE_TOML_TABLE_HEADER: RegExp;
|
|
28
|
+
/**
|
|
29
|
+
* The bearer in our exporters' header maps, value captured. A token rotation
|
|
30
|
+
* changes only this, so drift checks ignore it and the hook rewrites it alone.
|
|
31
|
+
*/
|
|
32
|
+
export declare const RE_BEARER_HEADER: RegExp;
|
|
@@ -25,3 +25,8 @@ export const RE_TOML_BACKSLASH = /\\/g;
|
|
|
25
25
|
export const RE_TOML_QUOTE = /"/g;
|
|
26
26
|
/** Start of any TOML table header, used to find where our block stops being ours. */
|
|
27
27
|
export const RE_TOML_TABLE_HEADER = /^\s*\[/;
|
|
28
|
+
/**
|
|
29
|
+
* The bearer in our exporters' header maps, value captured. A token rotation
|
|
30
|
+
* changes only this, so drift checks ignore it and the hook rewrites it alone.
|
|
31
|
+
*/
|
|
32
|
+
export const RE_BEARER_HEADER = /("Authorization" = "Bearer )((?:[^"\\]|\\.)*)(")/g;
|
|
@@ -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
|
-
},
|
|
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>;
|
|
@@ -28,3 +28,11 @@ export declare const RE_SHELL_CONTROL: RegExp;
|
|
|
28
28
|
/** Characters a double quote still escapes inside a quoted argument. */
|
|
29
29
|
export declare const RE_DOUBLE_QUOTE_ESCAPABLE: RegExp;
|
|
30
30
|
export declare const RE_WHITESPACE: RegExp;
|
|
31
|
+
/**
|
|
32
|
+
* Stands in for the bearer when a drift check compares an agent's config with
|
|
33
|
+
* what setup would write: the access token rotates hourly, and a rotated token
|
|
34
|
+
* is not drift.
|
|
35
|
+
*/
|
|
36
|
+
export declare const BEARER_PLACEHOLDER = "<access token>";
|
|
37
|
+
/** How every literal bearer the edge writes into an agent's config starts. */
|
|
38
|
+
export declare const BEARER_PREFIX = "Bearer ";
|
|
@@ -28,3 +28,11 @@ export const RE_SHELL_CONTROL = /[|&;<>\r\n]/;
|
|
|
28
28
|
/** Characters a double quote still escapes inside a quoted argument. */
|
|
29
29
|
export const RE_DOUBLE_QUOTE_ESCAPABLE = /["\\$`]/;
|
|
30
30
|
export const RE_WHITESPACE = /\s/;
|
|
31
|
+
/**
|
|
32
|
+
* Stands in for the bearer when a drift check compares an agent's config with
|
|
33
|
+
* what setup would write: the access token rotates hourly, and a rotated token
|
|
34
|
+
* is not drift.
|
|
35
|
+
*/
|
|
36
|
+
export const BEARER_PLACEHOLDER = '<access token>';
|
|
37
|
+
/** How every literal bearer the edge writes into an agent's config starts. */
|
|
38
|
+
export const BEARER_PREFIX = 'Bearer ';
|
|
@@ -44,6 +44,8 @@ export declare const CURSOR_TOOL_KINDS: Readonly<Record<string, ToolKind>>;
|
|
|
44
44
|
export declare const CURSOR_READ_TOOL_NAME = "Read";
|
|
45
45
|
export declare const CURSOR_EDIT_TOOL_NAME = "Edit";
|
|
46
46
|
export declare const CURSOR_SHELL_TOOL_NAME = "Shell";
|
|
47
|
+
/** Server segment of an MCP key when a Cursor hook names neither a server, a url nor a command. */
|
|
48
|
+
export declare const CURSOR_UNKNOWN_MCP_SERVER = "unknown";
|
|
47
49
|
/** The dedicated shell hooks, with `command` (and, before the call, `cwd`) at the top level. */
|
|
48
50
|
export declare const CURSOR_SHELL_EVENTS: ReadonlySet<string>;
|
|
49
51
|
/** The generic hook that fires before any tool call, the shell's included. */
|
|
@@ -81,6 +81,8 @@ export const CURSOR_TOOL_KINDS = {
|
|
|
81
81
|
export const CURSOR_READ_TOOL_NAME = 'Read';
|
|
82
82
|
export const CURSOR_EDIT_TOOL_NAME = 'Edit';
|
|
83
83
|
export const CURSOR_SHELL_TOOL_NAME = 'Shell';
|
|
84
|
+
/** Server segment of an MCP key when a Cursor hook names neither a server, a url nor a command. */
|
|
85
|
+
export const CURSOR_UNKNOWN_MCP_SERVER = 'unknown';
|
|
84
86
|
/** The dedicated shell hooks, with `command` (and, before the call, `cwd`) at the top level. */
|
|
85
87
|
export const CURSOR_SHELL_EVENTS = new Set(['beforeShellExecution', 'afterShellExecution']);
|
|
86
88
|
/** The generic hook that fires before any tool call, the shell's included. */
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
1
2
|
import path from 'node:path';
|
|
2
3
|
import { asRecord, compact } from '../../core/object.js';
|
|
3
4
|
import { sha256Hex } from '../../events/event-id.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { resolvePaths } from '../../storage/paths.js';
|
|
6
|
+
import { baseEvent, filePathPatch, promptPatch, responsePatch, toolCallEvidence, toolPatch, withPatch } from '../shared/event-builder.js';
|
|
7
|
+
import { classifyTool, contentEvidence, mcpServerFromEndpoint, mcpToolKey, parseMcpToolName, shellCallOf, toolCompleteType, toolStartType } from '../shared/tooling.js';
|
|
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';
|
|
7
9
|
import { cursorPayloadSchema } from './schemas/cursor.schema.js';
|
|
8
10
|
/**
|
|
9
11
|
* Translate one Cursor hook payload into canonical events.
|
|
@@ -214,7 +216,9 @@ function shellPatch(payload, providerEventType, context) {
|
|
|
214
216
|
tool: { name: CURSOR_SHELL_TOOL_NAME, status: completed ? 'completed' : 'started', durationMs: payload.duration },
|
|
215
217
|
metadata: compact({
|
|
216
218
|
command: capture.toolInput && typeof payload.command === 'string' ? payload.command : undefined,
|
|
217
|
-
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 })
|
|
218
222
|
})
|
|
219
223
|
};
|
|
220
224
|
}
|
|
@@ -233,15 +237,22 @@ function shellPatch(payload, providerEventType, context) {
|
|
|
233
237
|
function mcpPatch(payload, providerEventType, context) {
|
|
234
238
|
const capture = context.config.capture;
|
|
235
239
|
const parsed = payload.tool_name ? parseMcpToolName(payload.tool_name) : {};
|
|
240
|
+
// An endpoint that names no server still gets a parseable key, so mcpNames:false folds it.
|
|
241
|
+
const toolName = parsed.tool ?? payload.tool_name;
|
|
242
|
+
const endpoint = parsed.server ?? mcpServerFromEndpoint(payload.url, payload.command);
|
|
243
|
+
const server = endpoint ?? rememberedMcpServer(payload, toolName, context) ?? CURSOR_UNKNOWN_MCP_SERVER;
|
|
244
|
+
if (endpoint && toolName)
|
|
245
|
+
rememberMcpServer(payload, toolName, endpoint, context);
|
|
236
246
|
return {
|
|
237
247
|
tool: {
|
|
238
|
-
name: payload.tool_name,
|
|
248
|
+
name: toolName ? mcpToolKey(server, toolName) : payload.tool_name,
|
|
239
249
|
status: providerEventType === 'beforeMCPExecution' ? 'started' : 'completed',
|
|
240
250
|
durationMs: payload.duration
|
|
241
251
|
},
|
|
242
252
|
metadata: compact({
|
|
243
253
|
toolInput: capture.toolInput && payload.tool_input !== undefined ? payload.tool_input : undefined,
|
|
244
254
|
toolOutput: capture.toolOutput && payload.result_json !== undefined ? payload.result_json : undefined,
|
|
255
|
+
toolCall: toolCallEvidence({ kind: 'mcp', input: payload.tool_input }),
|
|
245
256
|
provider: compact({
|
|
246
257
|
mcpServer: parsed.server ?? payload.url ?? payload.command,
|
|
247
258
|
mcpTool: parsed.tool ?? payload.tool_name
|
|
@@ -249,6 +260,74 @@ function mcpPatch(payload, providerEventType, context) {
|
|
|
249
260
|
})
|
|
250
261
|
};
|
|
251
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* Where a conversation's MCP servers are remembered between its hooks.
|
|
265
|
+
*
|
|
266
|
+
* `afterMCPExecution` carries neither url nor command, and only completions
|
|
267
|
+
* become turn records, so the server the before-hook saw has to outlive it.
|
|
268
|
+
*
|
|
269
|
+
* @param payload - Parsed hook payload.
|
|
270
|
+
* @param context - Environment.
|
|
271
|
+
* @returns The state file, or undefined without a conversation id.
|
|
272
|
+
*/
|
|
273
|
+
function mcpMemoFile(payload, context) {
|
|
274
|
+
if (!payload.conversation_id)
|
|
275
|
+
return undefined;
|
|
276
|
+
return path.join(resolvePaths(context.env).dataDir, 'cursor-mcp', `${sha256Hex(payload.conversation_id).slice(0, 32)}.json`);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Remembers which server a tool resolved to, for the completion hook.
|
|
280
|
+
*
|
|
281
|
+
* ponytail: one tiny file per conversation, last write wins per tool name, never
|
|
282
|
+
* pruned (the data dir is disposable); two servers exposing the same tool name
|
|
283
|
+
* in one conversation share an entry. Upgrade: key by tool_use_id if Cursor sends it.
|
|
284
|
+
*
|
|
285
|
+
* @param payload - Parsed hook payload.
|
|
286
|
+
* @param tool - Tool name.
|
|
287
|
+
* @param server - Resolved server.
|
|
288
|
+
* @param context - Environment.
|
|
289
|
+
*/
|
|
290
|
+
function rememberMcpServer(payload, tool, server, context) {
|
|
291
|
+
const file = mcpMemoFile(payload, context);
|
|
292
|
+
if (!file)
|
|
293
|
+
return;
|
|
294
|
+
try {
|
|
295
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
296
|
+
fs.writeFileSync(file, JSON.stringify({ ...readMcpMemo(file), [tool]: server }), { mode: 0o600 });
|
|
297
|
+
}
|
|
298
|
+
catch {
|
|
299
|
+
// Hooks never fail the agent; the completion just keys as unknown.
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* The server a tool resolved to in this conversation's before-hook.
|
|
304
|
+
*
|
|
305
|
+
* @param payload - Parsed hook payload.
|
|
306
|
+
* @param tool - Tool name.
|
|
307
|
+
* @param context - Environment.
|
|
308
|
+
* @returns The server, or undefined when none was remembered.
|
|
309
|
+
*/
|
|
310
|
+
function rememberedMcpServer(payload, tool, context) {
|
|
311
|
+
const file = mcpMemoFile(payload, context);
|
|
312
|
+
if (!file || !tool)
|
|
313
|
+
return undefined;
|
|
314
|
+
const server = readMcpMemo(file)[tool];
|
|
315
|
+
return typeof server === 'string' ? server : undefined;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Reads a conversation's MCP memo.
|
|
319
|
+
*
|
|
320
|
+
* @param file - Memo file.
|
|
321
|
+
* @returns Its contents, empty when missing or unreadable.
|
|
322
|
+
*/
|
|
323
|
+
function readMcpMemo(file) {
|
|
324
|
+
try {
|
|
325
|
+
return asRecord(JSON.parse(fs.readFileSync(file, 'utf8'))) ?? {};
|
|
326
|
+
}
|
|
327
|
+
catch {
|
|
328
|
+
return {};
|
|
329
|
+
}
|
|
330
|
+
}
|
|
252
331
|
/**
|
|
253
332
|
* File-edit fields for Cursor's dedicated edit hooks.
|
|
254
333
|
*
|
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
},
|
|
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
|
-
/**
|
|
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
|
/**
|
|
@@ -34,3 +39,13 @@ export declare const STANDARD_OTLP_PROTOCOL = "http/json";
|
|
|
34
39
|
* that is not a default worth inheriting.
|
|
35
40
|
*/
|
|
36
41
|
export declare const GEMINI_TELEMETRY_TARGET_LOCAL = "local";
|
|
42
|
+
/**
|
|
43
|
+
* The bearer inside the `OTEL_EXPORTER_OTLP_HEADERS` list, value captured. A
|
|
44
|
+
* token rotation changes only this, so drift checks ignore it and the hook
|
|
45
|
+
* rewrites it alone.
|
|
46
|
+
*/
|
|
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
|
-
/**
|
|
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
|
/**
|
|
@@ -49,3 +54,13 @@ export const STANDARD_OTLP_PROTOCOL = 'http/json';
|
|
|
49
54
|
* that is not a default worth inheriting.
|
|
50
55
|
*/
|
|
51
56
|
export const GEMINI_TELEMETRY_TARGET_LOCAL = 'local';
|
|
57
|
+
/**
|
|
58
|
+
* The bearer inside the `OTEL_EXPORTER_OTLP_HEADERS` list, value captured. A
|
|
59
|
+
* token rotation changes only this, so drift checks ignore it and the hook
|
|
60
|
+
* rewrites it alone.
|
|
61
|
+
*/
|
|
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
|
*
|