@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
|
@@ -30,52 +30,4 @@ export declare const geminiPayloadSchema: z.ZodObject<{
|
|
|
30
30
|
last_assistant_message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
31
31
|
stop_hook_active: z.ZodOptional<z.ZodBoolean>;
|
|
32
32
|
denialReason: z.ZodOptional<z.ZodString>;
|
|
33
|
-
},
|
|
34
|
-
hook_event_name: z.ZodOptional<z.ZodString>;
|
|
35
|
-
session_id: z.ZodOptional<z.ZodString>;
|
|
36
|
-
thread_id: z.ZodOptional<z.ZodString>;
|
|
37
|
-
turn_id: z.ZodOptional<z.ZodString>;
|
|
38
|
-
prompt_id: z.ZodOptional<z.ZodString>;
|
|
39
|
-
transcript_path: z.ZodOptional<z.ZodString>;
|
|
40
|
-
cwd: z.ZodOptional<z.ZodString>;
|
|
41
|
-
permission_mode: z.ZodOptional<z.ZodString>;
|
|
42
|
-
agent_id: z.ZodOptional<z.ZodString>;
|
|
43
|
-
agent_type: z.ZodOptional<z.ZodString>;
|
|
44
|
-
tool_name: z.ZodOptional<z.ZodString>;
|
|
45
|
-
tool_use_id: z.ZodOptional<z.ZodString>;
|
|
46
|
-
tool_input: z.ZodOptional<z.ZodUnknown>;
|
|
47
|
-
tool_response: z.ZodOptional<z.ZodUnknown>;
|
|
48
|
-
tool_error: z.ZodOptional<z.ZodUnknown>;
|
|
49
|
-
prompt: z.ZodOptional<z.ZodString>;
|
|
50
|
-
prompt_response: z.ZodOptional<z.ZodString>;
|
|
51
|
-
source: z.ZodOptional<z.ZodString>;
|
|
52
|
-
model: z.ZodOptional<z.ZodString>;
|
|
53
|
-
reason: z.ZodOptional<z.ZodString>;
|
|
54
|
-
last_assistant_message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
55
|
-
stop_hook_active: z.ZodOptional<z.ZodBoolean>;
|
|
56
|
-
denialReason: z.ZodOptional<z.ZodString>;
|
|
57
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
58
|
-
hook_event_name: z.ZodOptional<z.ZodString>;
|
|
59
|
-
session_id: z.ZodOptional<z.ZodString>;
|
|
60
|
-
thread_id: z.ZodOptional<z.ZodString>;
|
|
61
|
-
turn_id: z.ZodOptional<z.ZodString>;
|
|
62
|
-
prompt_id: z.ZodOptional<z.ZodString>;
|
|
63
|
-
transcript_path: z.ZodOptional<z.ZodString>;
|
|
64
|
-
cwd: z.ZodOptional<z.ZodString>;
|
|
65
|
-
permission_mode: z.ZodOptional<z.ZodString>;
|
|
66
|
-
agent_id: z.ZodOptional<z.ZodString>;
|
|
67
|
-
agent_type: z.ZodOptional<z.ZodString>;
|
|
68
|
-
tool_name: z.ZodOptional<z.ZodString>;
|
|
69
|
-
tool_use_id: z.ZodOptional<z.ZodString>;
|
|
70
|
-
tool_input: z.ZodOptional<z.ZodUnknown>;
|
|
71
|
-
tool_response: z.ZodOptional<z.ZodUnknown>;
|
|
72
|
-
tool_error: z.ZodOptional<z.ZodUnknown>;
|
|
73
|
-
prompt: z.ZodOptional<z.ZodString>;
|
|
74
|
-
prompt_response: z.ZodOptional<z.ZodString>;
|
|
75
|
-
source: z.ZodOptional<z.ZodString>;
|
|
76
|
-
model: z.ZodOptional<z.ZodString>;
|
|
77
|
-
reason: z.ZodOptional<z.ZodString>;
|
|
78
|
-
last_assistant_message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
79
|
-
stop_hook_active: z.ZodOptional<z.ZodBoolean>;
|
|
80
|
-
denialReason: z.ZodOptional<z.ZodString>;
|
|
81
|
-
}, z.ZodTypeAny, "passthrough">>;
|
|
33
|
+
}, z.core.$loose>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AgentWatchPaths } from '../../storage/types/storage.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Put the machine's current access token into every agent config that holds
|
|
4
|
+
* a literal OTLP bearer (Codex, Gemini).
|
|
5
|
+
*
|
|
6
|
+
* They read that header once, when a session starts
|
|
7
|
+
* (docs/NATIVE_OTLP_TOKENS.md), so the hook keeps the file on the live token
|
|
8
|
+
* for the next session. An agent is loaded only when its file holds a bearer
|
|
9
|
+
* that is not this one, so the usual hook pays one small read per agent and no
|
|
10
|
+
* import. Each agent changes nothing but its own bearer.
|
|
11
|
+
*
|
|
12
|
+
* Never throws: a file that cannot be read or written is left as it is, and
|
|
13
|
+
* the next hook tries again.
|
|
14
|
+
*
|
|
15
|
+
* @param paths - Resolved AgentWatch paths, for the install state.
|
|
16
|
+
* @param bearer - The machine's current access token.
|
|
17
|
+
* @returns How many files were rewritten.
|
|
18
|
+
*/
|
|
19
|
+
export declare function rewriteNativeBearers(paths: AgentWatchPaths, bearer: string): Promise<number>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { debugLog } from '../../core/logger.js';
|
|
3
|
+
import { loadInstallState } from '../../storage/install-state.js';
|
|
4
|
+
import { BEARER_PREFIX } from '../constants/provider.constants.js';
|
|
5
|
+
import { loadProvider } from '../loaders.js';
|
|
6
|
+
/**
|
|
7
|
+
* Put the machine's current access token into every agent config that holds
|
|
8
|
+
* a literal OTLP bearer (Codex, Gemini).
|
|
9
|
+
*
|
|
10
|
+
* They read that header once, when a session starts
|
|
11
|
+
* (docs/NATIVE_OTLP_TOKENS.md), so the hook keeps the file on the live token
|
|
12
|
+
* for the next session. An agent is loaded only when its file holds a bearer
|
|
13
|
+
* that is not this one, so the usual hook pays one small read per agent and no
|
|
14
|
+
* import. Each agent changes nothing but its own bearer.
|
|
15
|
+
*
|
|
16
|
+
* Never throws: a file that cannot be read or written is left as it is, and
|
|
17
|
+
* the next hook tries again.
|
|
18
|
+
*
|
|
19
|
+
* @param paths - Resolved AgentWatch paths, for the install state.
|
|
20
|
+
* @param bearer - The machine's current access token.
|
|
21
|
+
* @returns How many files were rewritten.
|
|
22
|
+
*/
|
|
23
|
+
export async function rewriteNativeBearers(paths, bearer) {
|
|
24
|
+
let rewritten = 0;
|
|
25
|
+
try {
|
|
26
|
+
const installState = await loadInstallState(paths);
|
|
27
|
+
for (const [id, agent] of Object.entries(installState.agents)) {
|
|
28
|
+
const configPath = agent.otelConfigPath;
|
|
29
|
+
const raw = configPath ? await fs.readFile(configPath, 'utf8').catch(() => '') : '';
|
|
30
|
+
if (!configPath || !raw.includes(BEARER_PREFIX) || raw.includes(BEARER_PREFIX + bearer))
|
|
31
|
+
continue;
|
|
32
|
+
try {
|
|
33
|
+
const configurator = (await loadProvider(id))?.nativeTelemetry;
|
|
34
|
+
if (await configurator?.rewriteBearer?.({ configPath, installState, bearer, raw }))
|
|
35
|
+
rewritten++;
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
debugLog(`${id}: rewriting the native exporter bearer failed:`, error);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
debugLog('rewriting native exporter bearers failed:', error);
|
|
44
|
+
}
|
|
45
|
+
return rewritten;
|
|
46
|
+
}
|
|
@@ -14,6 +14,10 @@ export declare const FILE_EDIT_TOOLS: ReadonlySet<string>;
|
|
|
14
14
|
/** Prefix and separator of an MCP tool name. */
|
|
15
15
|
export declare const MCP_TOOL_PREFIX = "mcp__";
|
|
16
16
|
export declare const MCP_TOOL_SEPARATOR = "__";
|
|
17
|
+
/** Key a turn's MCP calls fold into under `capture.mcpNames: false`. */
|
|
18
|
+
export declare const MCP_FOLDED_KEY = "mcp";
|
|
19
|
+
/** The bridge's bound on a `tools_used` key. */
|
|
20
|
+
export declare const MAX_TOOL_KEY_LENGTH = 200;
|
|
17
21
|
/**
|
|
18
22
|
* Keys a file path may arrive under, in priority order.
|
|
19
23
|
*
|
|
@@ -39,3 +43,5 @@ export declare const SHELL_COMMAND_KEY = "command";
|
|
|
39
43
|
* stuffed with them; the agent bounds the prompt before the hook sees it.
|
|
40
44
|
*/
|
|
41
45
|
export declare const RE_HARNESS_BLOCK: RegExp;
|
|
46
|
+
/** The executable of a command line: a double-quoted, single-quoted or bare first word. */
|
|
47
|
+
export declare const COMMAND_HEAD: RegExp;
|
|
@@ -14,6 +14,10 @@ export const FILE_EDIT_TOOLS = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookE
|
|
|
14
14
|
/** Prefix and separator of an MCP tool name. */
|
|
15
15
|
export const MCP_TOOL_PREFIX = 'mcp__';
|
|
16
16
|
export const MCP_TOOL_SEPARATOR = '__';
|
|
17
|
+
/** Key a turn's MCP calls fold into under `capture.mcpNames: false`. */
|
|
18
|
+
export const MCP_FOLDED_KEY = 'mcp';
|
|
19
|
+
/** The bridge's bound on a `tools_used` key. */
|
|
20
|
+
export const MAX_TOOL_KEY_LENGTH = 200;
|
|
17
21
|
/**
|
|
18
22
|
* Keys a file path may arrive under, in priority order.
|
|
19
23
|
*
|
|
@@ -39,3 +43,5 @@ export const SHELL_COMMAND_KEY = 'command';
|
|
|
39
43
|
* stuffed with them; the agent bounds the prompt before the hook sees it.
|
|
40
44
|
*/
|
|
41
45
|
export const RE_HARNESS_BLOCK = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
|
|
46
|
+
/** The executable of a command line: a double-quoted, single-quoted or bare first word. */
|
|
47
|
+
export const COMMAND_HEAD = /^\s*(?:"([^"]*)"|'([^']*)'|(\S+))/;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { UnknownRecord } from '../../core/types/core.types.js';
|
|
2
2
|
import type { AgentWatchEvent, EventPatch } from '../../events/types/events.types.js';
|
|
3
|
-
import type { BaseEventInput, CapturePolicy, ToolCallInput } from './types/adapter.types.js';
|
|
4
|
-
export type { BaseEventInput, CapturePolicy, ToolCallInput } from './types/adapter.types.js';
|
|
3
|
+
import type { BaseEventInput, CapturePolicy, ToolCallEvidenceInput, ToolCallInput } from './types/adapter.types.js';
|
|
4
|
+
export type { BaseEventInput, CapturePolicy, ToolCallEvidenceInput, ToolCallInput } from './types/adapter.types.js';
|
|
5
5
|
/**
|
|
6
6
|
* The part of a canonical event every provider fills in the same way.
|
|
7
7
|
*
|
|
@@ -70,6 +70,21 @@ export declare function responsePatch(response: string): EventPatch;
|
|
|
70
70
|
* @returns The patch.
|
|
71
71
|
*/
|
|
72
72
|
export declare function toolPatch(call: ToolCallInput, capture: CapturePolicy): EventPatch;
|
|
73
|
+
/**
|
|
74
|
+
* The content-free facts the turn keeps about one tool call (AWT-675): its
|
|
75
|
+
* ids, exit code, and a digest of its input. Not gated on `capture.toolInput`:
|
|
76
|
+
* the command or connector call is read here, in memory, hashed and dropped,
|
|
77
|
+
* so nothing in this block can quote it. Whether the facts leave the machine
|
|
78
|
+
* is `capture.git`'s, decided at the summary.
|
|
79
|
+
*
|
|
80
|
+
* A shell call is digested with core's command scheme, so the edge's record
|
|
81
|
+
* and the agent's own OTLP record of one call agree; a connector call is the
|
|
82
|
+
* sha256 of its arguments as JSON. Any other tool carries no digest.
|
|
83
|
+
*
|
|
84
|
+
* @param call - The call, as the adapter read it.
|
|
85
|
+
* @returns The block, or undefined when there is nothing to keep.
|
|
86
|
+
*/
|
|
87
|
+
export declare function toolCallEvidence(call: ToolCallEvidenceInput): UnknownRecord | undefined;
|
|
73
88
|
/**
|
|
74
89
|
* Patch carrying a file path, when one is known and permitted.
|
|
75
90
|
*
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { compact } from '../../core/object.js';
|
|
1
|
+
import { asRecord, compact } from '../../core/object.js';
|
|
2
2
|
import { EVENT_SCHEMA_VERSION } from '../../events/constants/events.constants.js';
|
|
3
|
-
import { deriveEventId } from '../../events/event-id.js';
|
|
3
|
+
import { deriveEventId, sha256Hex } from '../../events/event-id.js';
|
|
4
4
|
import { ticketKeysInText } from '../../feature/ticket-candidates.js';
|
|
5
|
-
import {
|
|
5
|
+
import { commandFingerprint, commandText } from '../../privacy/command-fingerprint.js';
|
|
6
|
+
import { RE_HARNESS_BLOCK, SHELL_COMMAND_KEY } from './constants/tooling.constants.js';
|
|
6
7
|
import { contentEvidence, extractCommand, extractFilePath } from './tooling.js';
|
|
7
8
|
/** Metadata key holding the provider's own, non-canonical fields. */
|
|
8
9
|
const PROVIDER_METADATA_KEY = 'provider';
|
|
@@ -151,10 +152,49 @@ export function toolPatch(call, capture) {
|
|
|
151
152
|
toolInput: capture.toolInput && call.input !== undefined ? call.input : undefined,
|
|
152
153
|
toolOutput: capture.toolOutput && call.output !== undefined ? call.output : undefined,
|
|
153
154
|
error: call.error !== undefined ? contentEvidence(JSON.stringify(call.error)) : undefined,
|
|
155
|
+
toolCall: toolCallEvidence(call),
|
|
154
156
|
[PROVIDER_METADATA_KEY]: compact({ toolUseId: call.toolUseId, ...call.providerFields })
|
|
155
157
|
})
|
|
156
158
|
};
|
|
157
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* The content-free facts the turn keeps about one tool call (AWT-675): its
|
|
162
|
+
* ids, exit code, and a digest of its input. Not gated on `capture.toolInput`:
|
|
163
|
+
* the command or connector call is read here, in memory, hashed and dropped,
|
|
164
|
+
* so nothing in this block can quote it. Whether the facts leave the machine
|
|
165
|
+
* is `capture.git`'s, decided at the summary.
|
|
166
|
+
*
|
|
167
|
+
* A shell call is digested with core's command scheme, so the edge's record
|
|
168
|
+
* and the agent's own OTLP record of one call agree; a connector call is the
|
|
169
|
+
* sha256 of its arguments as JSON. Any other tool carries no digest.
|
|
170
|
+
*
|
|
171
|
+
* @param call - The call, as the adapter read it.
|
|
172
|
+
* @returns The block, or undefined when there is nothing to keep.
|
|
173
|
+
*/
|
|
174
|
+
export function toolCallEvidence(call) {
|
|
175
|
+
const digest = inputDigest(call);
|
|
176
|
+
const block = compact({
|
|
177
|
+
callId: call.toolUseId,
|
|
178
|
+
pairingKey: call.pairingKey,
|
|
179
|
+
inputFp: digest?.digest ?? undefined,
|
|
180
|
+
matchesCheck: digest?.matchesCheck === true ? true : undefined,
|
|
181
|
+
exitCode: call.exitCode
|
|
182
|
+
});
|
|
183
|
+
return Object.keys(block).length > 0 ? block : undefined;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* The input digest for a shell or connector call.
|
|
187
|
+
*
|
|
188
|
+
* @param call - The call.
|
|
189
|
+
* @returns The digest and check match, or undefined for any other tool.
|
|
190
|
+
*/
|
|
191
|
+
function inputDigest(call) {
|
|
192
|
+
if (call.kind === 'shell')
|
|
193
|
+
return commandFingerprint(call.command ?? extractCommand(call.input) ?? commandText(asRecord(call.input)?.[SHELL_COMMAND_KEY]));
|
|
194
|
+
if (call.kind !== 'mcp' || call.input === undefined)
|
|
195
|
+
return undefined;
|
|
196
|
+
return { digest: sha256Hex(JSON.stringify(call.input)), matchesCheck: false };
|
|
197
|
+
}
|
|
158
198
|
/**
|
|
159
199
|
* Patch carrying a file path, when one is known and permitted.
|
|
160
200
|
*
|
|
@@ -60,6 +60,8 @@ interface OtelInstallRecord {
|
|
|
60
60
|
* the old bits is what makes the change reversible.
|
|
61
61
|
*/
|
|
62
62
|
readonly priorMode?: number;
|
|
63
|
+
/** What owned keys held before this tool set them; replaces the previous map. */
|
|
64
|
+
readonly priorValues?: Readonly<Record<string, string>>;
|
|
63
65
|
}
|
|
64
66
|
/**
|
|
65
67
|
* Install state with one agent's native-telemetry configuration recorded.
|
|
@@ -90,7 +90,8 @@ export function withOtelInstall(state, agentId, record) {
|
|
|
90
90
|
otelOwnedKeys: [...new Set(record.ownedKeys)],
|
|
91
91
|
// First tightening wins: a second configure must not record the 0600 we
|
|
92
92
|
// ourselves left behind as the file's original mode.
|
|
93
|
-
...(record.priorMode !== undefined && previous?.otelPriorMode === undefined ? { otelPriorMode: record.priorMode } : {})
|
|
93
|
+
...(record.priorMode !== undefined && previous?.otelPriorMode === undefined ? { otelPriorMode: record.priorMode } : {}),
|
|
94
|
+
...(record.priorValues ? { otelPriorValues: { ...record.priorValues } } : {})
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
};
|
|
@@ -110,7 +111,7 @@ export function withoutOtelInstall(state, agentId) {
|
|
|
110
111
|
...state,
|
|
111
112
|
agents: {
|
|
112
113
|
...state.agents,
|
|
113
|
-
[agentId]: { ...omitKeys(previous, new Set(['otelConfiguredAt', 'otelPriorMode'])), otelOwnedKeys: [] }
|
|
114
|
+
[agentId]: { ...omitKeys(previous, new Set(['otelConfiguredAt', 'otelPriorMode', 'otelPriorValues'])), otelOwnedKeys: [] }
|
|
114
115
|
}
|
|
115
116
|
};
|
|
116
117
|
}
|
|
@@ -32,6 +32,41 @@ export declare function toolCompleteType(kind: ToolKind): CanonicalEventType;
|
|
|
32
32
|
* @returns The server and tool, or an empty object for a non-MCP name.
|
|
33
33
|
*/
|
|
34
34
|
export declare function parseMcpToolName(toolName: string): McpToolName;
|
|
35
|
+
/**
|
|
36
|
+
* The `tools_used` key of an MCP call: `mcp__<server>__<tool>`, no arguments.
|
|
37
|
+
*
|
|
38
|
+
* One builder for every provider so the backend can split the key back apart.
|
|
39
|
+
* Scrubbed and cut at the bridge's bound, because a server can come from a
|
|
40
|
+
* URL host or a command and must never carry a credential into a key.
|
|
41
|
+
*
|
|
42
|
+
* @param server - Server's logical name, host or command base name.
|
|
43
|
+
* @param tool - Tool name on that server.
|
|
44
|
+
* @returns The key.
|
|
45
|
+
*/
|
|
46
|
+
export declare function mcpToolKey(server: string, tool: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* One tool name with its MCP server and tool withheld: `mcp__*` becomes `mcp`.
|
|
49
|
+
*
|
|
50
|
+
* @param name - A tool name as `tools_used` and `tool_events` carry it.
|
|
51
|
+
* @returns The name, folded when it is an MCP one.
|
|
52
|
+
*/
|
|
53
|
+
export declare function foldMcpName(name: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Fold every `mcp__*` key of a `tools_used` map into `mcp`, keeping the count.
|
|
56
|
+
*
|
|
57
|
+
* @param toolsUsed - Per-tool call counts.
|
|
58
|
+
* @returns The counts with MCP server and tool names withheld.
|
|
59
|
+
*/
|
|
60
|
+
export declare function foldMcpNames(toolsUsed: Readonly<Record<string, number>>): Record<string, number>;
|
|
61
|
+
/**
|
|
62
|
+
* Server name of a Cursor MCP hook that carries no `mcp__` name: the host of a
|
|
63
|
+
* remote endpoint, else the base name of a stdio command (first word, quote-aware).
|
|
64
|
+
*
|
|
65
|
+
* @param url - The remote endpoint, if any.
|
|
66
|
+
* @param command - The stdio command line, if any.
|
|
67
|
+
* @returns The server, or undefined when neither yields one.
|
|
68
|
+
*/
|
|
69
|
+
export declare function mcpServerFromEndpoint(url: string | undefined, command: string | undefined): string | undefined;
|
|
35
70
|
/**
|
|
36
71
|
* Length and hash of text, as evidence for content we may not transmit.
|
|
37
72
|
*
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { asRecord, firstString } from '../../core/object.js';
|
|
3
|
+
import { sanitizeText } from '../../privacy/sanitizer.js';
|
|
3
4
|
import { sha256Hex } from '../../events/event-id.js';
|
|
4
|
-
import { COMMAND_KEYS, FILE_EDIT_TOOLS, FILE_PATH_KEYS, FILE_READ_TOOLS, MCP_TOOL_PREFIX, MCP_TOOL_SEPARATOR, SHELL_TOOLS } from './constants/tooling.constants.js';
|
|
5
|
+
import { COMMAND_KEYS, FILE_EDIT_TOOLS, FILE_PATH_KEYS, FILE_READ_TOOLS, COMMAND_HEAD, MAX_TOOL_KEY_LENGTH, MCP_FOLDED_KEY, MCP_TOOL_PREFIX, MCP_TOOL_SEPARATOR, SHELL_TOOLS } from './constants/tooling.constants.js';
|
|
5
6
|
/**
|
|
6
7
|
* What kind of thing a tool call is, whatever the agent calls it.
|
|
7
8
|
*
|
|
@@ -66,6 +67,65 @@ export function parseMcpToolName(toolName) {
|
|
|
66
67
|
const parts = toolName.split(MCP_TOOL_SEPARATOR);
|
|
67
68
|
return { server: parts[1], tool: parts.slice(2).join(MCP_TOOL_SEPARATOR) || undefined };
|
|
68
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* The `tools_used` key of an MCP call: `mcp__<server>__<tool>`, no arguments.
|
|
72
|
+
*
|
|
73
|
+
* One builder for every provider so the backend can split the key back apart.
|
|
74
|
+
* Scrubbed and cut at the bridge's bound, because a server can come from a
|
|
75
|
+
* URL host or a command and must never carry a credential into a key.
|
|
76
|
+
*
|
|
77
|
+
* @param server - Server's logical name, host or command base name.
|
|
78
|
+
* @param tool - Tool name on that server.
|
|
79
|
+
* @returns The key.
|
|
80
|
+
*/
|
|
81
|
+
export function mcpToolKey(server, tool) {
|
|
82
|
+
return sanitizeText(`${MCP_TOOL_PREFIX}${server}${MCP_TOOL_SEPARATOR}${tool}`).slice(0, MAX_TOOL_KEY_LENGTH);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* One tool name with its MCP server and tool withheld: `mcp__*` becomes `mcp`.
|
|
86
|
+
*
|
|
87
|
+
* @param name - A tool name as `tools_used` and `tool_events` carry it.
|
|
88
|
+
* @returns The name, folded when it is an MCP one.
|
|
89
|
+
*/
|
|
90
|
+
export function foldMcpName(name) {
|
|
91
|
+
return name.startsWith(MCP_TOOL_PREFIX) ? MCP_FOLDED_KEY : name;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Fold every `mcp__*` key of a `tools_used` map into `mcp`, keeping the count.
|
|
95
|
+
*
|
|
96
|
+
* @param toolsUsed - Per-tool call counts.
|
|
97
|
+
* @returns The counts with MCP server and tool names withheld.
|
|
98
|
+
*/
|
|
99
|
+
export function foldMcpNames(toolsUsed) {
|
|
100
|
+
const folded = {};
|
|
101
|
+
for (const [name, count] of Object.entries(toolsUsed)) {
|
|
102
|
+
const key = foldMcpName(name);
|
|
103
|
+
folded[key] = (folded[key] ?? 0) + count;
|
|
104
|
+
}
|
|
105
|
+
return folded;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Server name of a Cursor MCP hook that carries no `mcp__` name: the host of a
|
|
109
|
+
* remote endpoint, else the base name of a stdio command (first word, quote-aware).
|
|
110
|
+
*
|
|
111
|
+
* @param url - The remote endpoint, if any.
|
|
112
|
+
* @param command - The stdio command line, if any.
|
|
113
|
+
* @returns The server, or undefined when neither yields one.
|
|
114
|
+
*/
|
|
115
|
+
export function mcpServerFromEndpoint(url, command) {
|
|
116
|
+
if (url) {
|
|
117
|
+
try {
|
|
118
|
+
return new URL(url).host || undefined;
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const executable = command ? COMMAND_HEAD.exec(command) : null;
|
|
125
|
+
const head = executable?.[1] ?? executable?.[2] ?? executable?.[3];
|
|
126
|
+
// ponytail: an unquoted path with spaces is ambiguous and splits at the first space; npx/uvx/docker name the launcher, not the server.
|
|
127
|
+
return head ? head.split(/[\\/]/).pop() || undefined : undefined;
|
|
128
|
+
}
|
|
69
129
|
/**
|
|
70
130
|
* Length and hash of text, as evidence for content we may not transmit.
|
|
71
131
|
*
|
|
@@ -41,6 +41,24 @@ export interface ToolCallInput {
|
|
|
41
41
|
readonly error?: unknown;
|
|
42
42
|
/** Extra provider-specific fields for `metadata.provider`, e.g. MCP routing. */
|
|
43
43
|
readonly providerFields?: UnknownRecord;
|
|
44
|
+
/** The shell's exit code, where the provider states one. */
|
|
45
|
+
readonly exitCode?: number;
|
|
46
|
+
/**
|
|
47
|
+
* Pairs a start with its completion when the agent names no call id
|
|
48
|
+
* (Antigravity's step index). Local turn state only; never sent as an id.
|
|
49
|
+
*/
|
|
50
|
+
readonly pairingKey?: string;
|
|
51
|
+
}
|
|
52
|
+
/** What {@link toolCallEvidence} reads from one tool call. */
|
|
53
|
+
export interface ToolCallEvidenceInput {
|
|
54
|
+
readonly kind: ToolKind;
|
|
55
|
+
/** Raw arguments, whatever shape the provider used. */
|
|
56
|
+
readonly input?: unknown;
|
|
57
|
+
/** The command, for a provider that reports it beside the input (Cursor's shell hooks). */
|
|
58
|
+
readonly command?: string;
|
|
59
|
+
readonly toolUseId?: string;
|
|
60
|
+
readonly pairingKey?: string;
|
|
61
|
+
readonly exitCode?: number;
|
|
44
62
|
}
|
|
45
63
|
/** What the effective config allows to be captured. */
|
|
46
64
|
export interface CapturePolicy {
|
|
@@ -20,6 +20,23 @@ export interface SetupContext {
|
|
|
20
20
|
readonly hookCommand: string;
|
|
21
21
|
/** What setup has recorded so far; an operation returns the next version. */
|
|
22
22
|
readonly installState: InstallState;
|
|
23
|
+
/**
|
|
24
|
+
* The bearer an agent's own config may hold (Codex, Gemini): the machine's
|
|
25
|
+
* device access token, which the hook path rewrites as it rotates. Never the
|
|
26
|
+
* install key or the device secret (SPEC R8). Absent writes no header.
|
|
27
|
+
*/
|
|
28
|
+
readonly bearer?: string;
|
|
29
|
+
}
|
|
30
|
+
/** What a hook needs to swap the bearer in an agent's config for a newer one. */
|
|
31
|
+
export interface BearerRewriteContext {
|
|
32
|
+
/** The file setup recorded, which a hook's environment may not point at. */
|
|
33
|
+
readonly configPath: string;
|
|
34
|
+
/** Which entries are AgentWatch's to touch. */
|
|
35
|
+
readonly installState: InstallState;
|
|
36
|
+
/** The machine's current access token. */
|
|
37
|
+
readonly bearer: string;
|
|
38
|
+
/** The agent's config file as the caller just read it. */
|
|
39
|
+
readonly raw: string;
|
|
23
40
|
}
|
|
24
41
|
export interface SetupOutcome {
|
|
25
42
|
readonly ok: boolean;
|
|
@@ -74,6 +91,13 @@ export interface NativeTelemetryConfigurator {
|
|
|
74
91
|
* this and is never reported as held back.
|
|
75
92
|
*/
|
|
76
93
|
withheldSignals?(config: AgentWatchConfig): readonly OtelSignalName[];
|
|
94
|
+
/**
|
|
95
|
+
* Swap the bearer an earlier `configure` wrote for the current one, touching
|
|
96
|
+
* nothing else, atomically at 0600. For agents that read a literal header
|
|
97
|
+
* once at session start (Codex, Gemini): the hook keeps their file on the
|
|
98
|
+
* live access token so the next session starts with one.
|
|
99
|
+
*/
|
|
100
|
+
rewriteBearer?(context: BearerRewriteContext): Promise<boolean>;
|
|
77
101
|
}
|
|
78
102
|
export interface AgentProvider {
|
|
79
103
|
readonly id: string;
|
|
@@ -14,6 +14,20 @@
|
|
|
14
14
|
* target's.
|
|
15
15
|
*/
|
|
16
16
|
export declare function writeFileAtomic(filePath: string, contents: string, mode?: number): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Replace another tool's file only if it still holds what we read.
|
|
19
|
+
*
|
|
20
|
+
* For a write the edge makes while that tool may be running and rewriting the
|
|
21
|
+
* file itself (Codex re-serializes its config.toml): a change since our read is
|
|
22
|
+
* the tool's, and it wins. The window left is the re-read to the rename.
|
|
23
|
+
*
|
|
24
|
+
* @param filePath - The file.
|
|
25
|
+
* @param read - Its contents when the change was computed.
|
|
26
|
+
* @param contents - The new contents.
|
|
27
|
+
* @param mode - Permission bits to force.
|
|
28
|
+
* @returns True when the file was written.
|
|
29
|
+
*/
|
|
30
|
+
export declare function writeIfUnchanged(filePath: string, read: string, contents: string, mode: number): Promise<boolean>;
|
|
17
31
|
/**
|
|
18
32
|
* Copy a file into the backups directory before we mutate it.
|
|
19
33
|
*
|
|
@@ -38,6 +38,25 @@ export async function writeFileAtomic(filePath, contents, mode) {
|
|
|
38
38
|
throw error;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Replace another tool's file only if it still holds what we read.
|
|
43
|
+
*
|
|
44
|
+
* For a write the edge makes while that tool may be running and rewriting the
|
|
45
|
+
* file itself (Codex re-serializes its config.toml): a change since our read is
|
|
46
|
+
* the tool's, and it wins. The window left is the re-read to the rename.
|
|
47
|
+
*
|
|
48
|
+
* @param filePath - The file.
|
|
49
|
+
* @param read - Its contents when the change was computed.
|
|
50
|
+
* @param contents - The new contents.
|
|
51
|
+
* @param mode - Permission bits to force.
|
|
52
|
+
* @returns True when the file was written.
|
|
53
|
+
*/
|
|
54
|
+
export async function writeIfUnchanged(filePath, read, contents, mode) {
|
|
55
|
+
if ((await fs.readFile(filePath, 'utf8').catch(() => undefined)) !== read)
|
|
56
|
+
return false;
|
|
57
|
+
await writeFileAtomic(filePath, contents, mode);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
41
60
|
/**
|
|
42
61
|
* Copy a file into the backups directory before we mutate it.
|
|
43
62
|
*
|
|
@@ -13,6 +13,8 @@ export declare const DATA_DIR_VAR = "AGENTWATCH_DATA_DIR";
|
|
|
13
13
|
* wins, so an interactive run is unaffected.
|
|
14
14
|
*/
|
|
15
15
|
export declare const TOKEN_VAR = "AGENTWATCH_TOKEN";
|
|
16
|
+
/** An admin-issued enrollment code for an unattended setup: never argv, where `ps` reads it (SPEC R4). */
|
|
17
|
+
export declare const ENROLLMENT_CODE_VAR = "AGENTWATCH_ENROLLMENT_CODE";
|
|
16
18
|
export declare const CONFIG_FILE_NAME = "config.json";
|
|
17
19
|
export declare const INSTALL_STATE_FILE_NAME = "install-state.json";
|
|
18
20
|
/** Sub-directories of the data root. */
|
|
@@ -14,6 +14,8 @@ export const DATA_DIR_VAR = 'AGENTWATCH_DATA_DIR';
|
|
|
14
14
|
* wins, so an interactive run is unaffected.
|
|
15
15
|
*/
|
|
16
16
|
export const TOKEN_VAR = 'AGENTWATCH_TOKEN';
|
|
17
|
+
/** An admin-issued enrollment code for an unattended setup: never argv, where `ps` reads it (SPEC R4). */
|
|
18
|
+
export const ENROLLMENT_CODE_VAR = 'AGENTWATCH_ENROLLMENT_CODE';
|
|
17
19
|
export const CONFIG_FILE_NAME = 'config.json';
|
|
18
20
|
export const INSTALL_STATE_FILE_NAME = 'install-state.json';
|
|
19
21
|
/** Sub-directories of the data root. */
|