@agent-watch-ai/edge 0.4.0 → 0.6.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 +50 -0
- package/README.md +8 -7
- package/SECURITY.md +1 -1
- package/dist/config/config-store.js +1 -1
- package/dist/config/repo-config.js +1 -1
- package/dist/config/schemas/config.schema.d.ts +93 -857
- package/dist/config/schemas/config.schema.js +5 -5
- package/dist/credentials/credentials.js +2 -2
- package/dist/credentials/schemas/device-api.schema.d.ts +4 -51
- package/dist/credentials/schemas/device-state.schema.d.ts +3 -38
- package/dist/events/constants/events.constants.d.ts +5 -2
- package/dist/events/constants/events.constants.js +4 -1
- package/dist/events/index.d.ts +1 -0
- package/dist/events/product-event.d.ts +7 -4
- package/dist/events/types/repo-snapshot.types.d.ts +1 -4
- package/dist/events/types/repo-tree.types.d.ts +24 -0
- package/dist/events/types/repo-tree.types.js +1 -0
- 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/constants/tree.constants.d.ts +71 -0
- package/dist/git/constants/tree.constants.js +92 -0
- package/dist/git/git-context.d.ts +1 -0
- package/dist/git/git-context.js +3 -2
- package/dist/git/index.d.ts +2 -1
- package/dist/git/index.js +1 -0
- package/dist/git/repo-tree.d.ts +69 -0
- package/dist/git/repo-tree.js +130 -0
- package/dist/git/types/git.types.d.ts +11 -2
- package/dist/git/types/snapshot.types.d.ts +12 -0
- package/dist/pipeline/hook-pipeline.js +40 -24
- 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 +53 -6
- 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/schemas/codex.schema.d.ts +1 -41
- package/dist/providers/cursor/cursor.adapter.js +5 -2
- 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 +10 -1
- package/dist/providers/gemini/constants/gemini.otel.constants.js +11 -2
- 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 +6 -6
- package/dist/providers/gemini/gemini.otel.js +392 -121
- package/dist/providers/gemini/schemas/gemini.schema.d.ts +1 -49
- 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 +7 -0
- package/dist/providers/shared/tooling.js +10 -1
- package/dist/providers/shared/types/adapter.types.d.ts +18 -0
- package/dist/snapshot/branch-selection.js +3 -1
- package/dist/snapshot/budget.js +2 -2
- package/dist/snapshot/constants/snapshot-stages.constants.d.ts +8 -0
- package/dist/snapshot/constants/snapshot-stages.constants.js +8 -0
- package/dist/snapshot/constants/snapshot.constants.d.ts +6 -0
- package/dist/snapshot/constants/snapshot.constants.js +6 -0
- package/dist/snapshot/index.d.ts +5 -0
- package/dist/snapshot/index.js +2 -0
- package/dist/snapshot/snapshot-event.d.ts +7 -0
- package/dist/snapshot/snapshot-event.js +8 -5
- package/dist/snapshot/snapshot-state.js +19 -1
- package/dist/snapshot/tree-event.d.ts +14 -0
- package/dist/snapshot/tree-event.js +91 -0
- package/dist/snapshot/tree-pipeline.d.ts +12 -0
- package/dist/snapshot/tree-pipeline.js +153 -0
- package/dist/snapshot/types/snapshot.types.d.ts +44 -1
- package/dist/storage/schemas/storage.schema.d.ts +11 -175
- package/dist/storage/schemas/storage.schema.js +7 -1
- package/dist/transport/constants/transport.constants.d.ts +5 -0
- package/dist/transport/constants/transport.constants.js +5 -0
- package/dist/transport/queue.js +40 -6
- 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 +4 -4
- 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 +33 -5
- package/dist/turns/types/turn-tracker.types.d.ts +10 -0
- package/docs/AUDIT_PROMPT.md +11 -0
- package/docs/DATA_HANDLING.md +132 -33
- package/docs/ENTERPRISE_DEPLOYMENT.md +2 -1
- package/docs/PERFORMANCE.md +17 -0
- package/package.json +9 -8
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TurnRecord } from './types/turn-state.types.js';
|
|
2
|
+
import type { ToolEvent } from './types/turn-summary.types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The turn's tool calls as `tool_events`: each completion dated by its start,
|
|
5
|
+
* in call order, the first {@link MAX_TURN_TOOL_EVENTS} only.
|
|
6
|
+
*
|
|
7
|
+
* Pure over the turn's records, so a duplicate Stop sends the same list. A
|
|
8
|
+
* completion with no status was written by an older release and sends no
|
|
9
|
+
* event; a start that came after its completion (a clock step) dates nothing.
|
|
10
|
+
* The caller decides whether the list may leave: it rides `capture.git`.
|
|
11
|
+
*
|
|
12
|
+
* @param records - The closing turn's records, oldest first.
|
|
13
|
+
* @returns The events, possibly empty.
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildToolEvents(records: readonly TurnRecord[]): ToolEvent[];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { compact } from '../core/object.js';
|
|
2
|
+
import { MAX_TOOL_EVENT_ID_LENGTH, MAX_TURN_TOOL_EVENTS, UNKNOWN_TOOL_NAME } from './constants/turns.constants.js';
|
|
3
|
+
/**
|
|
4
|
+
* The turn's tool calls as `tool_events`: each completion dated by its start,
|
|
5
|
+
* in call order, the first {@link MAX_TURN_TOOL_EVENTS} only.
|
|
6
|
+
*
|
|
7
|
+
* Pure over the turn's records, so a duplicate Stop sends the same list. A
|
|
8
|
+
* completion with no status was written by an older release and sends no
|
|
9
|
+
* event; a start that came after its completion (a clock step) dates nothing.
|
|
10
|
+
* The caller decides whether the list may leave: it rides `capture.git`.
|
|
11
|
+
*
|
|
12
|
+
* @param records - The closing turn's records, oldest first.
|
|
13
|
+
* @returns The events, possibly empty.
|
|
14
|
+
*/
|
|
15
|
+
export function buildToolEvents(records) {
|
|
16
|
+
const starts = new Map();
|
|
17
|
+
const calls = [];
|
|
18
|
+
for (const record of records) {
|
|
19
|
+
if (record.kind !== 'tool-start' || starts.has(record.pairingKey))
|
|
20
|
+
continue;
|
|
21
|
+
starts.set(record.pairingKey, record.at);
|
|
22
|
+
}
|
|
23
|
+
for (const record of records) {
|
|
24
|
+
if (record.kind !== 'tool' || record.status === undefined)
|
|
25
|
+
continue;
|
|
26
|
+
const start = record.startedAt ?? (record.pairingKey === undefined ? undefined : starts.get(record.pairingKey));
|
|
27
|
+
calls.push({ record, startedAt: start !== undefined && start <= record.at ? start : undefined });
|
|
28
|
+
}
|
|
29
|
+
// Call order is start order; a call with no start sorts by its end. Stable,
|
|
30
|
+
// so calls that tie keep the order their records were written in.
|
|
31
|
+
calls.sort((a, b) => (a.startedAt ?? a.record.at).localeCompare(b.startedAt ?? b.record.at));
|
|
32
|
+
const events = [];
|
|
33
|
+
for (const { record, startedAt } of calls) {
|
|
34
|
+
if (events.length >= MAX_TURN_TOOL_EVENTS)
|
|
35
|
+
break;
|
|
36
|
+
events.push(toolEvent(record, startedAt, events.length));
|
|
37
|
+
}
|
|
38
|
+
return events;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* One record on the wire, by field: never a spread, so nothing a record
|
|
42
|
+
* holds besides these fields (its paths, its input) can ride along.
|
|
43
|
+
*/
|
|
44
|
+
function toolEvent(record, startedAt, seq) {
|
|
45
|
+
return compact({
|
|
46
|
+
seq,
|
|
47
|
+
tool: (record.tool ?? UNKNOWN_TOOL_NAME).slice(0, MAX_TOOL_EVENT_ID_LENGTH),
|
|
48
|
+
tool_call_id: record.callId?.slice(0, MAX_TOOL_EVENT_ID_LENGTH),
|
|
49
|
+
status: record.status ?? 'ok',
|
|
50
|
+
exit_code: record.exitCode,
|
|
51
|
+
started_at: startedAt,
|
|
52
|
+
ended_at: record.at,
|
|
53
|
+
input_fp: record.inputFp,
|
|
54
|
+
// A check needs its start: without one it ran for no known time.
|
|
55
|
+
check: record.check === true && startedAt !== undefined ? true : undefined,
|
|
56
|
+
commit: record.commit,
|
|
57
|
+
diff_fp: record.diffFp
|
|
58
|
+
});
|
|
59
|
+
}
|
package/dist/turns/turn-state.js
CHANGED
|
@@ -7,7 +7,7 @@ import { writeFileAtomic } from '../storage/atomic-file.js';
|
|
|
7
7
|
import { readJsonFile } from '../storage/json-file.js';
|
|
8
8
|
import { SECRET_FILE_MODE, SWEEP_MARKER_FILE } from '../storage/constants/storage.constants.js';
|
|
9
9
|
import { claimSweep } from '../storage/sweep-marker.js';
|
|
10
|
-
import { AGENT_PIDS_DIR, AGENT_PROCESS_FILE, BILLING_SENT_FILE, INHERITED_CHECKOUT_FILE, LIVENESS_IGNORED_FILES, PROMPT_TICKETS_FILE, RE_UNSAFE_NAME_CHARS, SESSION_DIR_HASH_LENGTH, SESSION_FILES, SESSION_MODEL_FILE, SESSION_START_FILE, SESSION_TITLE_FILE, TURN_STATE_SWEEP_INTERVAL_MS, UNTRACED_MARKER_PREFIX, USAGE_CLAIM_PREFIX, WORK_CHECKOUT_FILE } from './constants/turns.constants.js';
|
|
10
|
+
import { AGENT_PIDS_DIR, AGENT_PROCESS_FILE, BILLING_SENT_FILE, INHERITED_CHECKOUT_FILE, LIVENESS_IGNORED_FILES, PROMPT_TICKETS_FILE, RE_UNSAFE_NAME_CHARS, SESSION_DIR_HASH_LENGTH, SESSION_FILES, SESSION_MODEL_FILE, SESSION_START_FILE, SESSION_TITLE_FILE, TURN_RECORD_KINDS, TURN_STATE_SWEEP_INTERVAL_MS, UNTRACED_MARKER_PREFIX, USAGE_CLAIM_PREFIX, WORK_CHECKOUT_FILE } from './constants/turns.constants.js';
|
|
11
11
|
/**
|
|
12
12
|
* Per-session accumulator for turn summaries.
|
|
13
13
|
*
|
|
@@ -665,5 +665,5 @@ function isTurnRecord(value) {
|
|
|
665
665
|
const record = asRecord(value);
|
|
666
666
|
if (!record || typeof record['at'] !== 'string')
|
|
667
667
|
return false;
|
|
668
|
-
return record['kind']
|
|
668
|
+
return TURN_RECORD_KINDS.has(String(record['kind']));
|
|
669
669
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BuildTurnSummaryInput, TurnSummaryEvent } from './types/turn-summary.types.js';
|
|
2
|
-
export type { AgentUsageSummary, BuildTurnSummaryInput, TouchedFiles, TurnSummaryEvent, TurnUsageStatus, WorkEvidence } from './types/turn-summary.types.js';
|
|
2
|
+
export type { AgentUsageSummary, BuildTurnSummaryInput, ToolEvent, TouchedFiles, TurnSummaryEvent, TurnUsageStatus, WorkEvidence } from './types/turn-summary.types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Flatten one turn's accumulated state into the single product record the hook
|
|
5
5
|
* path emits.
|
|
@@ -46,24 +46,24 @@ export function buildTurnSummary(input) {
|
|
|
46
46
|
branch: input.git?.branch,
|
|
47
47
|
commit: input.git?.commit,
|
|
48
48
|
jira_ids: jiraIds.length > 0 ? jiraIds : undefined,
|
|
49
|
-
|
|
49
|
+
// Only the first is read (bridge-live), so only the first is sent.
|
|
50
|
+
prompt_jira_ids: input.promptJiraIds?.length ? input.promptJiraIds.slice(0, 1) : undefined,
|
|
50
51
|
files_changed: input.git?.changedFiles,
|
|
51
52
|
work_evidence: input.git?.repository ? input.workEvidence : undefined,
|
|
52
53
|
parent_session_id: input.parentSessionId,
|
|
53
|
-
content_hashes: input.contentHashes?.length ? input.contentHashes : undefined,
|
|
54
|
+
content_hashes: input.contentHashes?.length ? input.contentHashes.map(({ blob_sha }) => ({ blob_sha })) : undefined,
|
|
54
55
|
manifest_repository: input.manifestRepository,
|
|
55
56
|
files_touched: files.filesTouched.length > 0 ? files.filesTouched : undefined,
|
|
56
57
|
files_read: files.filesRead.length > 0 ? files.filesRead : undefined,
|
|
57
58
|
external_files_touched: files.externalTouched.length > 0 ? files.externalTouched : undefined,
|
|
58
59
|
external_files_read: files.externalRead.length > 0 ? files.externalRead : undefined,
|
|
59
|
-
prompt_evidence: input.prompts[0]?.evidence,
|
|
60
60
|
prompt_text: input.prompts[0]?.text,
|
|
61
61
|
session_name: boundSessionTitle(input.sessionTitles?.custom),
|
|
62
62
|
session_title: boundSessionTitle(input.sessionTitles?.generated),
|
|
63
63
|
tool_inputs: files.toolInputs.length > 0 ? files.toolInputs : undefined,
|
|
64
|
-
response_evidence: input.response,
|
|
65
64
|
tool_calls: input.tools.length,
|
|
66
65
|
tools_used: files.toolsUsed,
|
|
66
|
+
tool_events: input.toolEvents?.length ? input.toolEvents : undefined,
|
|
67
67
|
model: input.usage?.model ?? input.model,
|
|
68
68
|
// 'unknown' is the absence of a verdict, not a billing mode.
|
|
69
69
|
billing_mode: input.billingMode && input.billingMode !== 'unknown' ? input.billingMode : undefined,
|
|
@@ -5,7 +5,9 @@ import { asRecord, compact } from '../core/object.js';
|
|
|
5
5
|
import { detectBillingMode } from '../billing/billing-mode.js';
|
|
6
6
|
import { sha256Hex } from '../events/event-id.js';
|
|
7
7
|
import { REPOSITORY_PATH_METADATA_KEY } from '../events/constants/enrich.constants.js';
|
|
8
|
+
import { codeStateAt } from '../git/code-state.js';
|
|
8
9
|
import { developerDisplayName, developerIdentity } from '../git/git-context.js';
|
|
10
|
+
import { CHECK_MIN_DURATION_MS } from '../privacy/constants/command-fingerprint.constants.js';
|
|
9
11
|
import { sanitizeValue } from '../privacy/sanitizer.js';
|
|
10
12
|
import { acquireLock } from '../storage/lock.js';
|
|
11
13
|
import { inheritedRootConfig } from '../config/root-config.js';
|
|
@@ -16,9 +18,10 @@ import { readCodexTurnUsage } from './codex-transcript.js';
|
|
|
16
18
|
import { readCursorTurnUsage } from './cursor-transcript.js';
|
|
17
19
|
import { readGeminiTurnUsage } from './gemini-transcript.js';
|
|
18
20
|
import { readCodexSessionTitles, readCursorSessionTitles } from './native-session-titles.js';
|
|
19
|
-
import { CLAUDE_ENTRYPOINT_VAR, PARENT_SESSION_VAR, RE_PARENT_SESSION_ID, DEFAULT_SURFACE, EXTERNAL_PATH_KEY, FILE_PATH_KEY, IDE_SURFACE, IDE_SURFACE_PROVIDERS, LOCK_KEY_HASH_LENGTH, MAX_PROMPT_TEXT_LENGTH, MAX_TOOL_INPUT_LENGTH, PROMPT_EVIDENCE_KEY, PROMPT_JIRA_IDS_KEY, PROMPT_TEXT_KEY, RESPONSE_EVIDENCE_KEY, TOOL_COMPLETION_TYPES, EXEC_SURFACE, TRANSCRIPT_PATH_KEY, TURN_STATE_TTL_MS, USAGE_LOCK_POLL_MS, USAGE_LOCK_WAIT_MS, USAGE_RETRY } from './constants/turns.constants.js';
|
|
21
|
+
import { CLAUDE_ENTRYPOINT_VAR, PARENT_SESSION_VAR, RE_PARENT_SESSION_ID, DEFAULT_SURFACE, EXTERNAL_PATH_KEY, FILE_PATH_KEY, IDE_SURFACE, IDE_SURFACE_PROVIDERS, LOCK_KEY_HASH_LENGTH, MAX_PROMPT_TEXT_LENGTH, MAX_TOOL_INPUT_LENGTH, PROMPT_EVIDENCE_KEY, PROMPT_JIRA_IDS_KEY, PROMPT_TEXT_KEY, RESPONSE_EVIDENCE_KEY, INT32_MAX, INT32_MIN, RE_SHA256_HEX, TOOL_CALL_KEY, TOOL_COMPLETION_TYPES, TOOL_START_TYPES, EXEC_SURFACE, TRANSCRIPT_PATH_KEY, TURN_STATE_TTL_MS, USAGE_LOCK_POLL_MS, USAGE_LOCK_WAIT_MS, USAGE_RETRY } from './constants/turns.constants.js';
|
|
20
22
|
import { resolveFileIdentity } from './file-identity.js';
|
|
21
23
|
import { TurnStateStore } from './turn-state.js';
|
|
24
|
+
import { buildToolEvents } from './tool-events.js';
|
|
22
25
|
import { buildTurnSummary } from './turn-summary.js';
|
|
23
26
|
import { rememberInheritance, retryInheritance } from './inherited-checkout.js';
|
|
24
27
|
import { recordCheckouts, resolveWorkCheckout } from './work-checkout.js';
|
|
@@ -118,7 +121,7 @@ async function processEvent(store, sessionId, event, options) {
|
|
|
118
121
|
if (type === 'prompt.submitted')
|
|
119
122
|
await rememberPromptTicketsSafely(store, sessionId, event, options.config.capture.git);
|
|
120
123
|
await recordCheckoutsSafely(store, sessionId, event, options);
|
|
121
|
-
const record = recordFor(event, options.cwd, options.failOpenReason);
|
|
124
|
+
const record = await withCheckState(store, sessionId, event, recordFor(event, options.cwd, options.failOpenReason, options.config.capture.git), options);
|
|
122
125
|
if (record)
|
|
123
126
|
await store.append(sessionId, recordKeyFor(event), record);
|
|
124
127
|
if (type === 'generation.completed') {
|
|
@@ -227,14 +230,19 @@ async function recordCheckoutsSafely(store, sessionId, event, options) {
|
|
|
227
230
|
* @param event - Canonical event.
|
|
228
231
|
* @param cwd - This hook's own working directory.
|
|
229
232
|
* @param failOpenReason - Why this payload's prompt ran unchecked, if it did.
|
|
233
|
+
* @param git - Whether this hook's capture policy allows git context, which `tool_events` ride.
|
|
230
234
|
* @returns The record, or undefined when the event carries no turn state.
|
|
231
235
|
*/
|
|
232
|
-
function recordFor(event, cwd, failOpenReason) {
|
|
236
|
+
function recordFor(event, cwd, failOpenReason, git) {
|
|
233
237
|
const type = event.event.type;
|
|
234
238
|
if (type === 'prompt.submitted')
|
|
235
239
|
return promptRecord(event, failOpenReason);
|
|
236
240
|
if (TOOL_COMPLETION_TYPES.has(type))
|
|
237
|
-
return toolRecord(event, cwd);
|
|
241
|
+
return toolRecord(event, cwd, git);
|
|
242
|
+
// A start is kept only to date its completion in `tool_events`, which ride
|
|
243
|
+
// `capture.git`: with it off the start would be a write for nothing.
|
|
244
|
+
if (git && TOOL_START_TYPES.has(type))
|
|
245
|
+
return toolStartRecord(event);
|
|
238
246
|
// Cursor delivers the response text in its own hook (afterAgentResponse)
|
|
239
247
|
// instead of on Stop; keep it as turn state until the turn closes.
|
|
240
248
|
if (type === 'agent.other' && responseFrom(event) !== undefined)
|
|
@@ -311,7 +319,8 @@ async function closeTurnLocked(store, sessionId, stopEvent, options, readOnly =
|
|
|
311
319
|
// the turn) means no empty duplicate.
|
|
312
320
|
const all = await store.collectEntries(sessionId);
|
|
313
321
|
const firstPass = filterTurn(all, stopTurnId);
|
|
314
|
-
|
|
322
|
+
// A start alone is not a turn: it only dates a completion that never came.
|
|
323
|
+
if (!firstPass.some(({ record }) => record.kind !== 'tool-start'))
|
|
315
324
|
return undefined;
|
|
316
325
|
const window = resolveWindow(all, firstPass, stopEvent.timestamp);
|
|
317
326
|
const usage = await resolveAndClaimUsage(store, sessionId, stopEvent, options, window, readOnly);
|
|
@@ -364,6 +373,8 @@ async function closeTurnLocked(store, sessionId, stopEvent, options, readOnly =
|
|
|
364
373
|
parentSessionId: declaredParent(options.env, sessionId) ?? work.parentSessionId,
|
|
365
374
|
prompts: recordsOfKind(records, 'prompt'),
|
|
366
375
|
tools: work.tools,
|
|
376
|
+
// Withheld whole with `capture.git` off: digests, times, status and the check flag go together.
|
|
377
|
+
toolEvents: (work.capture ?? options.config.capture).git === false ? undefined : buildToolEvents(records),
|
|
367
378
|
response: resolveResponse(stopEvent, records),
|
|
368
379
|
usage,
|
|
369
380
|
model: resolvedStop.ai?.model,
|
|
@@ -697,13 +708,14 @@ function promptRecord(event, failOpenReason) {
|
|
|
697
708
|
*
|
|
698
709
|
* @param event - The tool event.
|
|
699
710
|
* @param cwd - This hook's own working directory, which the event's repository path is relative to.
|
|
711
|
+
* @param git - Whether this hook's capture policy allows git context, which the call's `tool_events` facts ride.
|
|
700
712
|
* @returns The record.
|
|
701
713
|
*/
|
|
702
|
-
function toolRecord(event, cwd) {
|
|
714
|
+
function toolRecord(event, cwd, git) {
|
|
703
715
|
const filePath = event.metadata?.[FILE_PATH_KEY];
|
|
704
716
|
const externalPath = event.metadata?.[EXTERNAL_PATH_KEY];
|
|
705
717
|
const repositoryPath = event.metadata?.[REPOSITORY_PATH_METADATA_KEY];
|
|
706
|
-
|
|
718
|
+
const record = {
|
|
707
719
|
kind: 'tool',
|
|
708
720
|
at: event.timestamp,
|
|
709
721
|
turnId: event.session.turnId,
|
|
@@ -716,6 +728,125 @@ function toolRecord(event, cwd) {
|
|
|
716
728
|
externalPath: typeof externalPath === 'string' && externalPath ? externalPath : undefined,
|
|
717
729
|
input: toolInputOf(event)
|
|
718
730
|
};
|
|
731
|
+
// Decided here by the hook's own policy, as `tool_inputs` is, and again at
|
|
732
|
+
// the close by the reported checkout's: a call seen under `capture.git` off
|
|
733
|
+
// keeps no facts to send, whichever checkout the turn reports.
|
|
734
|
+
if (!git)
|
|
735
|
+
return record;
|
|
736
|
+
const call = toolCallOf(event);
|
|
737
|
+
return {
|
|
738
|
+
...record,
|
|
739
|
+
status: event.event.type === 'tool.failed' || event.tool?.status === 'failed' || (call.exitCode !== undefined && call.exitCode !== 0) ? 'failed' : 'ok',
|
|
740
|
+
callId: call.callId,
|
|
741
|
+
pairingKey: call.pairingKey,
|
|
742
|
+
exitCode: call.exitCode,
|
|
743
|
+
startedAt: startFromDuration(event.timestamp, event.tool?.durationMs),
|
|
744
|
+
inputFp: call.inputFp
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* The start of a tool call, from the agent's own record of it.
|
|
749
|
+
*
|
|
750
|
+
* @param event - The tool-start event.
|
|
751
|
+
* @returns The record, or undefined when the call has nothing to pair its completion on.
|
|
752
|
+
*/
|
|
753
|
+
function toolStartRecord(event) {
|
|
754
|
+
const pairingKey = toolCallOf(event).pairingKey;
|
|
755
|
+
if (pairingKey === undefined)
|
|
756
|
+
return undefined;
|
|
757
|
+
return { kind: 'tool-start', at: event.timestamp, turnId: event.session.turnId, pairingKey };
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* The content-free tool-call block the adapter put on the event, type-checked.
|
|
761
|
+
*
|
|
762
|
+
* @param event - A tool event.
|
|
763
|
+
* @returns Its fields; empty when the adapter wrote none.
|
|
764
|
+
*/
|
|
765
|
+
function toolCallOf(event) {
|
|
766
|
+
const block = asRecord(event.metadata?.[TOOL_CALL_KEY]);
|
|
767
|
+
const callId = nonEmptyString(block?.['callId']);
|
|
768
|
+
const inputFp = block?.['inputFp'];
|
|
769
|
+
const exitCode = block?.['exitCode'];
|
|
770
|
+
return {
|
|
771
|
+
callId,
|
|
772
|
+
pairingKey: nonEmptyString(block?.['pairingKey']) ?? callId,
|
|
773
|
+
inputFp: typeof inputFp === 'string' && RE_SHA256_HEX.test(inputFp) ? inputFp : undefined,
|
|
774
|
+
matchesCheck: block?.['matchesCheck'] === true,
|
|
775
|
+
// Core's int32 range: one value outside it would cost the whole summary a 422.
|
|
776
|
+
exitCode: typeof exitCode === 'number' && Number.isInteger(exitCode) && exitCode >= INT32_MIN && exitCode <= INT32_MAX ? exitCode : undefined
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* A string worth keeping, else nothing.
|
|
781
|
+
*
|
|
782
|
+
* @param value - Any decoded value.
|
|
783
|
+
* @returns The string when it is a non-empty one.
|
|
784
|
+
*/
|
|
785
|
+
function nonEmptyString(value) {
|
|
786
|
+
return typeof value === 'string' && value ? value : undefined;
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* When a call that reports its duration started.
|
|
790
|
+
*
|
|
791
|
+
* @param endedAt - The completion's ISO timestamp.
|
|
792
|
+
* @param durationMs - The duration the agent reported, if any.
|
|
793
|
+
* @returns The ISO start, or undefined without a usable duration.
|
|
794
|
+
*/
|
|
795
|
+
function startFromDuration(endedAt, durationMs) {
|
|
796
|
+
const end = Date.parse(endedAt);
|
|
797
|
+
if (durationMs === undefined || !Number.isFinite(durationMs) || durationMs < 0 || Number.isNaN(end))
|
|
798
|
+
return undefined;
|
|
799
|
+
return new Date(end - durationMs).toISOString();
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* A completion of an allowlisted check that ran for a minute, with the code
|
|
803
|
+
* it ran on (workflow SPEC §11.2) taken now, before the tree moves on.
|
|
804
|
+
*
|
|
805
|
+
* Every other record passes through untouched, and costs nothing: the start
|
|
806
|
+
* is looked up, and git asked, only for a call whose command is on the
|
|
807
|
+
* allowlist, and only under `capture.git`. Never throws: a check whose state
|
|
808
|
+
* cannot be read is sent as a check without it.
|
|
809
|
+
*
|
|
810
|
+
* ponytail: git runs in the hook's cwd, not a directory the command `cd`s
|
|
811
|
+
* into; `cd pkg && npm test` is the same checkout. A command that tests
|
|
812
|
+
* another checkout records this one's state. Upgrade path: the provider's
|
|
813
|
+
* `shellCall` workdir, for the agents that report one.
|
|
814
|
+
*
|
|
815
|
+
* @param store - Per-session state store.
|
|
816
|
+
* @param sessionId - Provider session id.
|
|
817
|
+
* @param event - The event the record came from.
|
|
818
|
+
* @param record - The record about to be persisted.
|
|
819
|
+
* @param options - Tracking options.
|
|
820
|
+
* @returns The record, with the check and its code state when it is one.
|
|
821
|
+
*/
|
|
822
|
+
async function withCheckState(store, sessionId, event, record, options) {
|
|
823
|
+
if (record?.kind !== 'tool' || !options.config.capture.git || !toolCallOf(event).matchesCheck)
|
|
824
|
+
return record;
|
|
825
|
+
try {
|
|
826
|
+
const startedAt = record.startedAt ?? (await startOf(store, sessionId, record));
|
|
827
|
+
if (startedAt === undefined || Date.parse(record.at) - Date.parse(startedAt) < CHECK_MIN_DURATION_MS)
|
|
828
|
+
return record;
|
|
829
|
+
const state = await codeStateAt(options.cwd);
|
|
830
|
+
return compact({ ...record, startedAt, check: true, commit: state?.commit, diffFp: state?.diffFp });
|
|
831
|
+
}
|
|
832
|
+
catch {
|
|
833
|
+
debugLog('could not read the code state a check ran on');
|
|
834
|
+
return record;
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* When the call a completion closes started, from its start record.
|
|
839
|
+
*
|
|
840
|
+
* @param store - Per-session state store.
|
|
841
|
+
* @param sessionId - Provider session id.
|
|
842
|
+
* @param record - The completion.
|
|
843
|
+
* @returns The ISO start, or undefined when no start was recorded.
|
|
844
|
+
*/
|
|
845
|
+
async function startOf(store, sessionId, record) {
|
|
846
|
+
if (record.pairingKey === undefined)
|
|
847
|
+
return undefined;
|
|
848
|
+
const entries = await store.collectEntries(sessionId);
|
|
849
|
+
return entries.find(({ record: start }) => start.kind === 'tool-start' && start.pairingKey === record.pairingKey && start.turnId === record.turnId)?.record.at;
|
|
719
850
|
}
|
|
720
851
|
/**
|
|
721
852
|
* The shell command or connector call a tool event carries, bounded.
|
|
@@ -45,6 +45,33 @@ export interface ToolRecord {
|
|
|
45
45
|
readonly externalPath?: string;
|
|
46
46
|
/** The shell command or connector call, bounded; under `capture.toolInput`. */
|
|
47
47
|
readonly input?: ToolInputSummary;
|
|
48
|
+
readonly status?: 'ok' | 'failed';
|
|
49
|
+
/** The agent's own id for the call; what joins it to the agent's OTLP record. */
|
|
50
|
+
readonly callId?: string;
|
|
51
|
+
/** Matches the call's start record; the call id, or Antigravity's step index. Local only. */
|
|
52
|
+
readonly pairingKey?: string;
|
|
53
|
+
readonly exitCode?: number;
|
|
54
|
+
/** From the provider's duration, or the start record's time for a check. */
|
|
55
|
+
readonly startedAt?: string;
|
|
56
|
+
/** Unkeyed sha256 of the normalised command or connector arguments. */
|
|
57
|
+
readonly inputFp?: string;
|
|
58
|
+
/** On the check allowlist and ran for `CHECK_MIN_DURATION_MS`. */
|
|
59
|
+
readonly check?: boolean;
|
|
60
|
+
/** HEAD at a check's completion. */
|
|
61
|
+
readonly commit?: string;
|
|
62
|
+
/** Digest of the working tree at a check's completion. */
|
|
63
|
+
readonly diffFp?: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A tool call starting, kept only to date its completion: no duration on the
|
|
67
|
+
* completion means no start time without it. Local only; written only when
|
|
68
|
+
* the call has an id to pair on and `capture.git` is on.
|
|
69
|
+
*/
|
|
70
|
+
export interface ToolStartRecord {
|
|
71
|
+
readonly kind: 'tool-start';
|
|
72
|
+
readonly at: string;
|
|
73
|
+
readonly turnId?: string;
|
|
74
|
+
readonly pairingKey: string;
|
|
48
75
|
}
|
|
49
76
|
/** What went into one shell or connector (MCP) call, as the turn summary sends it. */
|
|
50
77
|
export interface ToolInputSummary {
|
|
@@ -100,7 +127,7 @@ export interface SessionModelRecord {
|
|
|
100
127
|
readonly model: string;
|
|
101
128
|
}
|
|
102
129
|
/** Anything the accumulator persists between hook invocations. */
|
|
103
|
-
export type TurnRecord = PromptRecord | ToolRecord | ResponseRecord | CheckoutRecord;
|
|
130
|
+
export type TurnRecord = PromptRecord | ToolRecord | ToolStartRecord | ResponseRecord | CheckoutRecord;
|
|
104
131
|
/** The session's last changed checkout, as `work-checkout.json` holds it. Local only. */
|
|
105
132
|
export interface WorkCheckoutMemo {
|
|
106
133
|
readonly root: string;
|
|
@@ -59,7 +59,7 @@ export interface TurnSummaryEvent extends AgentWatchEvent<'turn.summary'> {
|
|
|
59
59
|
readonly branch?: string;
|
|
60
60
|
readonly commit?: string;
|
|
61
61
|
readonly jira_ids?: readonly string[];
|
|
62
|
-
/**
|
|
62
|
+
/** The first ticket key the session's opening prompt named; the same on every turn of the session. Under `capture.git`. At most one. */
|
|
63
63
|
readonly prompt_jira_ids?: readonly string[];
|
|
64
64
|
/** The files this turn changed in its checkout: its edits, its commits' files, its new dirt. */
|
|
65
65
|
readonly files_changed?: readonly string[];
|
|
@@ -67,8 +67,8 @@ export interface TurnSummaryEvent extends AgentWatchEvent<'turn.summary'> {
|
|
|
67
67
|
readonly work_evidence?: WorkEvidence;
|
|
68
68
|
/** The session id of the agent that started this one: declared by its launcher, or the live parent an `inherited` checkout came from. */
|
|
69
69
|
readonly parent_session_id?: string;
|
|
70
|
-
/** One-way content ids of files the turn's tools named, in a folder with no git; under `capture.files`. */
|
|
71
|
-
readonly content_hashes?: readonly ContentHash[];
|
|
70
|
+
/** One-way content ids (git blob ids) of files the turn's tools named, in a folder with no git, without their paths; under `capture.files`. */
|
|
71
|
+
readonly content_hashes?: readonly Pick<ContentHash, 'blob_sha'>[];
|
|
72
72
|
/** The repository address the nearest project manifest names, cleaned like a git remote; under `capture.files`. */
|
|
73
73
|
readonly manifest_repository?: string;
|
|
74
74
|
/** Files edited by the agent's tools during this turn (repo-relative). */
|
|
@@ -79,7 +79,6 @@ export interface TurnSummaryEvent extends AgentWatchEvent<'turn.summary'> {
|
|
|
79
79
|
readonly external_files_touched?: readonly string[];
|
|
80
80
|
/** Files outside every checkout the turn's tools only read, home-relative. */
|
|
81
81
|
readonly external_files_read?: readonly string[];
|
|
82
|
-
readonly prompt_evidence?: ContentEvidence;
|
|
83
82
|
/** The turn's first prompt, harness blocks removed, scrubbed, bounded; under `capture.promptText`. */
|
|
84
83
|
readonly prompt_text?: string;
|
|
85
84
|
/** The session's latest name, scrubbed then cut to 200; under `capture.sessionTitle`; when the provider exposes one. */
|
|
@@ -88,9 +87,10 @@ export interface TurnSummaryEvent extends AgentWatchEvent<'turn.summary'> {
|
|
|
88
87
|
readonly session_title?: string;
|
|
89
88
|
/** The turn's shell commands and connector calls, bounded; under `capture.toolInput`. */
|
|
90
89
|
readonly tool_inputs?: readonly ToolInputSummary[];
|
|
91
|
-
readonly response_evidence?: ContentEvidence;
|
|
92
90
|
readonly tool_calls: number;
|
|
93
91
|
readonly tools_used: Readonly<Record<string, number>>;
|
|
92
|
+
/** The turn's first 200 tool calls in call order, content-free; under `capture.git` (AWT-675). */
|
|
93
|
+
readonly tool_events?: readonly ToolEvent[];
|
|
94
94
|
readonly model?: string;
|
|
95
95
|
/** subscription (flat plan) vs api (per-token billing); see billing-mode.ts. */
|
|
96
96
|
readonly billing_mode?: UsageBillingMode;
|
|
@@ -117,6 +117,32 @@ export interface TurnSummaryEvent extends AgentWatchEvent<'turn.summary'> {
|
|
|
117
117
|
readonly started_at?: string;
|
|
118
118
|
readonly ended_at: string;
|
|
119
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* One tool call of a turn, as core's `turn.summary.tool_events` takes it
|
|
122
|
+
* (AWT-674). Content-free by construction: there is no field for a command, a
|
|
123
|
+
* path or an output. The digests are unkeyed sha256; core re-keys them per
|
|
124
|
+
* tenant before it stores them.
|
|
125
|
+
*/
|
|
126
|
+
export interface ToolEvent {
|
|
127
|
+
/** Order in the turn, from 0. */
|
|
128
|
+
readonly seq: number;
|
|
129
|
+
readonly tool: string;
|
|
130
|
+
/** The agent's own id for the call, when it names one: what joins this record to its OTLP one. */
|
|
131
|
+
readonly tool_call_id?: string;
|
|
132
|
+
readonly status: 'ok' | 'failed';
|
|
133
|
+
readonly exit_code?: number;
|
|
134
|
+
/** Absent when the provider gives no start; such a call is never a check. */
|
|
135
|
+
readonly started_at?: string;
|
|
136
|
+
readonly ended_at: string;
|
|
137
|
+
/** The normalised command's digest (core's command scheme), or the connector arguments'. */
|
|
138
|
+
readonly input_fp?: string;
|
|
139
|
+
/** On the check allowlist and ran for at least 60 s. */
|
|
140
|
+
readonly check?: boolean;
|
|
141
|
+
/** HEAD when the check finished. */
|
|
142
|
+
readonly commit?: string;
|
|
143
|
+
/** Digest of the working tree when the check finished. */
|
|
144
|
+
readonly diff_fp?: string;
|
|
145
|
+
}
|
|
120
146
|
export interface BuildTurnSummaryInput {
|
|
121
147
|
/** Internal provider id ('claude' | 'codex' | ...); mapped to the public label. */
|
|
122
148
|
readonly provider: string;
|
|
@@ -138,6 +164,8 @@ export interface BuildTurnSummaryInput {
|
|
|
138
164
|
/** The session's latest native name and generated/display title as the agent holds them, unscrubbed. */
|
|
139
165
|
readonly sessionTitles?: SessionTitles;
|
|
140
166
|
readonly tools: readonly ToolRecord[];
|
|
167
|
+
/** Already gated and capped by the tracker; see {@link ToolEvent}. */
|
|
168
|
+
readonly toolEvents?: readonly ToolEvent[];
|
|
141
169
|
/** Evidence of the response the user actually saw, however the provider delivered it. */
|
|
142
170
|
readonly response?: ContentEvidence;
|
|
143
171
|
readonly usage?: TurnUsage;
|
|
@@ -51,3 +51,13 @@ export interface TurnWindow {
|
|
|
51
51
|
*/
|
|
52
52
|
readonly untilIso: string;
|
|
53
53
|
}
|
|
54
|
+
/** The content-free tool-call block an adapter put on a tool event, type-checked. */
|
|
55
|
+
export interface ToolCallFacts {
|
|
56
|
+
readonly callId?: string;
|
|
57
|
+
/** The call id, or the provider's own pairing key when it names no call id. */
|
|
58
|
+
readonly pairingKey?: string;
|
|
59
|
+
readonly inputFp?: string;
|
|
60
|
+
/** A command segment is on the check allowlist; the duration decides the rest. */
|
|
61
|
+
readonly matchesCheck: boolean;
|
|
62
|
+
readonly exitCode?: number;
|
|
63
|
+
}
|
package/docs/AUDIT_PROMPT.md
CHANGED
|
@@ -72,6 +72,17 @@ is there any code path through which prompt text, model response text, tool
|
|
|
72
72
|
input bodies, tool output bodies, or file contents leave the machine? If yes,
|
|
73
73
|
show the path.
|
|
74
74
|
|
|
75
|
+
`turn.summary` carries `tool_events` by default, one record per tool call:
|
|
76
|
+
`seq`, `tool`, `tool_call_id`, `status`, `exit_code`, `started_at`, `ended_at`,
|
|
77
|
+
`input_fp`, `check`, `commit` and `diff_fp`. `input_fp` is a sha256 of the
|
|
78
|
+
normalized shell command or of a connector call's JSON arguments, and `diff_fp`
|
|
79
|
+
a sha256 of the check's uncommitted `git diff HEAD`. Verify that no field of a record can hold a
|
|
80
|
+
command, a path, arguments or an output, that the command is hashed in memory
|
|
81
|
+
and never written to turn state without `toolInput`, that the whole list is
|
|
82
|
+
absent with `capture.git: false` (at build time and again before send), and
|
|
83
|
+
which git processes a check runs on the hook path. Say what a guessed common
|
|
84
|
+
command's hash lets someone confirm.
|
|
85
|
+
|
|
75
86
|
## 5. The consent gate
|
|
76
87
|
Explain how content capture is enabled. Can a repository-level config file,
|
|
77
88
|
an environment variable, a command-line flag, or a corrupt or missing global
|