@agent-watch-ai/edge 0.7.0 → 0.7.2
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 +92 -0
- package/README.md +4 -1
- package/dist/billing/session-billing.d.ts +5 -2
- package/dist/billing/session-billing.js +27 -6
- package/dist/capture/capture-env.d.ts +3 -3
- package/dist/capture/capture-env.js +5 -5
- package/dist/capture/captured-step.js +24 -0
- package/dist/capture/constants/capture.constants.d.ts +15 -0
- package/dist/capture/constants/capture.constants.js +15 -0
- package/dist/capture/launched-runs.d.ts +27 -0
- package/dist/capture/launched-runs.js +15 -9
- package/dist/capture/python/sitecustomize.py +11 -2
- package/dist/capture/venv-loader.d.ts +68 -0
- package/dist/capture/venv-loader.js +189 -0
- package/dist/cli/constants/cli.constants.d.ts +21 -0
- package/dist/cli/constants/cli.constants.js +22 -1
- package/dist/cli/doctor-run-capture.d.ts +8 -0
- package/dist/cli/doctor-run-capture.js +14 -0
- package/dist/cli/doctor.js +6 -2
- package/dist/cli/hook-check.d.ts +7 -2
- package/dist/cli/hook-check.js +30 -15
- package/dist/cli/hook.js +44 -3
- package/dist/cli/npm-global.d.ts +24 -0
- package/dist/cli/npm-global.js +77 -0
- package/dist/cli/npx-install.js +22 -6
- package/dist/cli/replay.js +42 -7
- package/dist/cli/setup.js +71 -7
- package/dist/cli/types/cli.types.d.ts +2 -0
- package/dist/cli/uninstall.js +34 -1
- package/dist/cli/update.js +3 -2
- package/dist/cli.js +4 -1
- package/dist/config/config-store.d.ts +15 -4
- package/dist/config/config-store.js +31 -7
- package/dist/config/config.d.ts +8 -0
- package/dist/config/config.js +10 -0
- package/dist/config/constants/config.constants.d.ts +13 -1
- package/dist/config/constants/config.constants.js +13 -1
- package/dist/config/repo-config.js +7 -2
- package/dist/config/schemas/config.schema.d.ts +6 -2
- package/dist/config/schemas/config.schema.js +17 -3
- package/dist/credentials/cloud-claim.d.ts +2 -0
- package/dist/credentials/cloud-claim.js +21 -2
- package/dist/credentials/constants/credentials.constants.d.ts +8 -0
- package/dist/credentials/constants/credentials.constants.js +8 -0
- package/dist/credentials/credential-status.js +1 -1
- package/dist/credentials/credentials.d.ts +3 -3
- package/dist/credentials/credentials.js +26 -12
- package/dist/credentials/identity.d.ts +2 -2
- package/dist/credentials/identity.js +2 -2
- package/dist/credentials/install-key.d.ts +31 -0
- package/dist/credentials/install-key.js +58 -0
- package/dist/credentials/migration.d.ts +9 -7
- package/dist/credentials/migration.js +58 -18
- package/dist/credentials/secret-store.d.ts +12 -0
- package/dist/credentials/secret-store.js +18 -1
- package/dist/enforcement/enforcement.js +1 -1
- package/dist/events/enrich.d.ts +14 -0
- package/dist/events/enrich.js +1 -1
- package/dist/git/constants/git.constants.d.ts +2 -0
- package/dist/git/constants/git.constants.js +9 -0
- package/dist/git/repo-snapshot.js +8 -2
- package/dist/git/types/snapshot.types.d.ts +4 -0
- package/dist/pipeline/hook-pipeline.js +5 -2
- package/dist/providers/antigravity/antigravity.adapter.d.ts +14 -0
- package/dist/providers/antigravity/antigravity.adapter.js +86 -18
- package/dist/providers/antigravity/antigravity.provider.js +7 -4
- package/dist/providers/antigravity/constants/antigravity.constants.d.ts +10 -0
- package/dist/providers/antigravity/constants/antigravity.constants.js +10 -0
- package/dist/providers/antigravity/schemas/antigravity.schema.js +7 -13
- package/dist/providers/claude/claude.otel.d.ts +33 -1
- package/dist/providers/claude/claude.otel.js +81 -12
- package/dist/providers/claude/claude.provider.js +12 -6
- package/dist/providers/codex/codex.capture.d.ts +1 -1
- package/dist/providers/codex/codex.capture.js +3 -3
- package/dist/providers/codex/codex.otel.js +2 -2
- package/dist/providers/codex/codex.provider.js +2 -1
- package/dist/providers/gemini/gemini.capture.js +2 -2
- package/dist/providers/gemini/gemini.otel.js +2 -2
- package/dist/providers/gemini/gemini.provider.js +2 -1
- package/dist/providers/shared/terminal-capture.js +3 -3
- package/dist/providers/types/provider.types.d.ts +5 -5
- package/dist/replay/checkout-resolver.d.ts +41 -14
- package/dist/replay/checkout-resolver.js +134 -30
- package/dist/replay/replay-runner.d.ts +3 -1
- package/dist/replay/replay-runner.js +74 -22
- package/dist/replay/replay-scan.d.ts +2 -1
- package/dist/replay/replay-scan.js +14 -2
- package/dist/replay/throttle.d.ts +2 -1
- package/dist/replay/throttle.js +4 -1
- package/dist/replay/transcript-turns.js +29 -3
- package/dist/replay/turn-event.d.ts +4 -2
- package/dist/replay/turn-event.js +22 -11
- package/dist/replay/types/replay.types.d.ts +39 -3
- package/dist/replay/worktree-map.d.ts +42 -0
- package/dist/replay/worktree-map.js +134 -0
- package/dist/snapshot/snapshot-pipeline.js +15 -4
- package/dist/snapshot/types/snapshot.types.d.ts +2 -0
- package/dist/turns/antigravity-transcript.d.ts +40 -0
- package/dist/turns/antigravity-transcript.js +102 -0
- package/dist/turns/claude-transcript.d.ts +35 -1
- package/dist/turns/claude-transcript.js +185 -2
- package/dist/turns/codex-transcript.d.ts +22 -1
- package/dist/turns/codex-transcript.js +161 -2
- package/dist/turns/constants/turns.constants.d.ts +67 -0
- package/dist/turns/constants/turns.constants.js +67 -0
- package/dist/turns/gemini-transcript.d.ts +17 -1
- package/dist/turns/gemini-transcript.js +36 -2
- package/dist/turns/transcript.d.ts +31 -1
- package/dist/turns/transcript.js +74 -0
- package/dist/turns/turn-state.d.ts +51 -1
- package/dist/turns/turn-state.js +124 -10
- package/dist/turns/turn-tracker.js +156 -18
- package/dist/turns/types/transcript.types.d.ts +25 -0
- package/dist/turns/types/turn-provider.types.d.ts +18 -1
- package/dist/turns/types/turn-state.types.d.ts +10 -0
- package/docs/DATA_HANDLING.md +11 -6
- package/docs/ENTERPRISE_DEPLOYMENT.md +2 -2
- package/package.json +1 -1
|
@@ -19,6 +19,18 @@ export type { SecretStore, StoreDeps } from './types/credentials.types.js';
|
|
|
19
19
|
* @returns The store that holds it now.
|
|
20
20
|
*/
|
|
21
21
|
export declare function saveSecret(deps: StoreDeps, id: string, secret: string): Promise<CredentialStoreKind>;
|
|
22
|
+
/**
|
|
23
|
+
* Write a value to one store and read it back, outside a hook's credential
|
|
24
|
+
* deadline (see `saveSecret`). `security -i` exits 0 whatever happened, so only
|
|
25
|
+
* the read proves the write.
|
|
26
|
+
*
|
|
27
|
+
* @param deps - Environment, paths, timeout and runner.
|
|
28
|
+
* @param kind - The store to write to.
|
|
29
|
+
* @param id - The account name.
|
|
30
|
+
* @param value - What to keep.
|
|
31
|
+
* @returns True when the store gives the value back.
|
|
32
|
+
*/
|
|
33
|
+
export declare function storeVerified(deps: StoreDeps, kind: CredentialStoreKind, id: string, value: string): Promise<boolean>;
|
|
22
34
|
/**
|
|
23
35
|
* The OS keychain this machine offers, or the private file when it offers none.
|
|
24
36
|
*
|
|
@@ -28,11 +28,28 @@ import { CREDENTIALS_DIR_NAME, DBUS_SESSION_VAR, DPAPI_FILE_SUFFIX, DPAPI_PROTEC
|
|
|
28
28
|
export async function saveSecret(deps, id, secret) {
|
|
29
29
|
const unhurried = { ...deps, deadline: undefined };
|
|
30
30
|
const preferred = preferredStore(unhurried);
|
|
31
|
-
if (preferred.kind !== 'file' && (await preferred
|
|
31
|
+
if (preferred.kind !== 'file' && (await setVerified(preferred, id, secret)))
|
|
32
32
|
return preferred.kind;
|
|
33
33
|
await fileStore(unhurried).set(id, secret);
|
|
34
34
|
return 'file';
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Write a value to one store and read it back, outside a hook's credential
|
|
38
|
+
* deadline (see `saveSecret`). `security -i` exits 0 whatever happened, so only
|
|
39
|
+
* the read proves the write.
|
|
40
|
+
*
|
|
41
|
+
* @param deps - Environment, paths, timeout and runner.
|
|
42
|
+
* @param kind - The store to write to.
|
|
43
|
+
* @param id - The account name.
|
|
44
|
+
* @param value - What to keep.
|
|
45
|
+
* @returns True when the store gives the value back.
|
|
46
|
+
*/
|
|
47
|
+
export async function storeVerified(deps, kind, id, value) {
|
|
48
|
+
return setVerified(secretStoreFor(kind, { ...deps, deadline: undefined }), id, value);
|
|
49
|
+
}
|
|
50
|
+
async function setVerified(store, id, value) {
|
|
51
|
+
return (await store.set(id, value)) && (await store.get(id)) === value;
|
|
52
|
+
}
|
|
36
53
|
/**
|
|
37
54
|
* The OS keychain this machine offers, or the private file when it offers none.
|
|
38
55
|
*
|
|
@@ -31,7 +31,7 @@ import { requestDecision } from './decision-client.js';
|
|
|
31
31
|
*/
|
|
32
32
|
export async function resolveEnforcement(options) {
|
|
33
33
|
const url = enforcementUrl(options.config);
|
|
34
|
-
//
|
|
34
|
+
// An install key an older edge left beside its device is not sent: this
|
|
35
35
|
// identity sends as the device: only the caller's cached access token will do.
|
|
36
36
|
const token = options.bearer ?? (deviceFor(options.config) ? undefined : options.config.token);
|
|
37
37
|
const developerId = options.developerId;
|
package/dist/events/enrich.d.ts
CHANGED
|
@@ -14,3 +14,17 @@ export type { EnrichOptions, PathRewriter } from './types/enrich.types.js';
|
|
|
14
14
|
* @returns Enriched, sanitized events in the same order.
|
|
15
15
|
*/
|
|
16
16
|
export declare function enrichEvents(events: readonly AgentWatchEvent[], options: EnrichOptions): Promise<AgentWatchEvent[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Where a file outside every checkout lies, without the home directory's name.
|
|
19
|
+
*
|
|
20
|
+
* A spreadsheet in `~/Documents` is the target of a session with no repository,
|
|
21
|
+
* so it is kept — but as `~/Documents/a.xlsx`: the home directory names the
|
|
22
|
+
* person. A path outside home is kept as it is; with no home to compare against
|
|
23
|
+
* nothing is kept, since the path could be the home itself.
|
|
24
|
+
*
|
|
25
|
+
* @param filePath - Path from a tool payload.
|
|
26
|
+
* @param repositoryRoot - The hook's repository root, when inside one.
|
|
27
|
+
* @param home - Developer home directory, when known.
|
|
28
|
+
* @returns The path to send, or undefined when the file is in the repository or unplaceable.
|
|
29
|
+
*/
|
|
30
|
+
export declare function externalPath(filePath: string, repositoryRoot: string | undefined, home: string | undefined): string | undefined;
|
package/dist/events/enrich.js
CHANGED
|
@@ -278,7 +278,7 @@ function relativize(root, target) {
|
|
|
278
278
|
* @param home - Developer home directory, when known.
|
|
279
279
|
* @returns The path to send, or undefined when the file is in the repository or unplaceable.
|
|
280
280
|
*/
|
|
281
|
-
function externalPath(filePath, repositoryRoot, home) {
|
|
281
|
+
export function externalPath(filePath, repositoryRoot, home) {
|
|
282
282
|
if (!home || !path.isAbsolute(filePath) || (repositoryRoot && isInside(repositoryRoot, filePath)))
|
|
283
283
|
return undefined;
|
|
284
284
|
return isInside(home, filePath) ? HOME_PLACEHOLDER_PREFIX + path.relative(home, filePath) : filePath;
|
|
@@ -56,6 +56,8 @@ export declare const GIT_FIELD_SEPARATOR = "\u001F";
|
|
|
56
56
|
* @returns The argument vector.
|
|
57
57
|
*/
|
|
58
58
|
export declare function gitRecentBranchesArgs(count: number): readonly string[];
|
|
59
|
+
/** The same branch record as {@link gitRecentBranchesArgs}, restricted to named local branches. */
|
|
60
|
+
export declare function gitNamedBranchesArgs(branches: readonly string[]): readonly string[];
|
|
59
61
|
/**
|
|
60
62
|
* What `%(upstream:track)` prints for a branch whose upstream was deleted on
|
|
61
63
|
* the remote and pruned here: the usual end of a merged or closed pull request.
|
|
@@ -64,6 +64,15 @@ export function gitRecentBranchesArgs(count) {
|
|
|
64
64
|
`--format=%(refname:short)${GIT_FIELD_SEPARATOR}%(objectname)${GIT_FIELD_SEPARATOR}%(committerdate:iso-strict)${GIT_FIELD_SEPARATOR}%(upstream:track)`
|
|
65
65
|
];
|
|
66
66
|
}
|
|
67
|
+
/** The same branch record as {@link gitRecentBranchesArgs}, restricted to named local branches. */
|
|
68
|
+
export function gitNamedBranchesArgs(branches) {
|
|
69
|
+
return [
|
|
70
|
+
'for-each-ref',
|
|
71
|
+
'--sort=-committerdate',
|
|
72
|
+
`--format=%(refname:short)${GIT_FIELD_SEPARATOR}%(objectname)${GIT_FIELD_SEPARATOR}%(committerdate:iso-strict)${GIT_FIELD_SEPARATOR}%(upstream:track)`,
|
|
73
|
+
...branches.map((branch) => `refs/heads/${branch}`)
|
|
74
|
+
];
|
|
75
|
+
}
|
|
67
76
|
/**
|
|
68
77
|
* What `%(upstream:track)` prints for a branch whose upstream was deleted on
|
|
69
78
|
* the remote and pruned here: the usual end of a merged or closed pull request.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ASSUMED_DEFAULT_BRANCHES, GIT_FIELD_SEPARATOR, GIT_ORIGIN_HEAD_ARGS, GIT_TIMEOUT_MS, GIT_UPSTREAM_GONE, RE_LEADING_NEWLINE, RE_NAME_STATUS, RE_OBJECT_ID, gitBranchDeltaArgs, gitBranchFilesArgs, gitMergeTreeArgs, gitRecentBranchesArgs, gitTreeArgs, gitVerifyRefArgs } from './constants/git.constants.js';
|
|
1
|
+
import { ASSUMED_DEFAULT_BRANCHES, GIT_FIELD_SEPARATOR, GIT_ORIGIN_HEAD_ARGS, GIT_TIMEOUT_MS, GIT_UPSTREAM_GONE, RE_LEADING_NEWLINE, RE_NAME_STATUS, RE_OBJECT_ID, gitBranchDeltaArgs, gitBranchFilesArgs, gitMergeTreeArgs, gitNamedBranchesArgs, gitRecentBranchesArgs, gitTreeArgs, gitVerifyRefArgs } from './constants/git.constants.js';
|
|
2
2
|
/** `origin/HEAD` is reported as `origin/main`; the branch is what comes after. */
|
|
3
3
|
const REMOTE_PREFIX = 'origin/';
|
|
4
4
|
/**
|
|
@@ -16,6 +16,12 @@ export async function collectBranchRefs(options, run) {
|
|
|
16
16
|
const output = await run(gitRecentBranchesArgs(options.branchCount), options.cwd, GIT_TIMEOUT_MS);
|
|
17
17
|
if (!output)
|
|
18
18
|
return [];
|
|
19
|
+
const recent = parseBranchRefs(output);
|
|
20
|
+
const missing = (options.requiredBranches ?? []).filter((name) => !recent.some((ref) => ref.name === name));
|
|
21
|
+
const required = missing.length === 0 ? [] : parseBranchRefs((await run(gitNamedBranchesArgs(missing), options.cwd, GIT_TIMEOUT_MS)) ?? '');
|
|
22
|
+
return [...required, ...recent];
|
|
23
|
+
}
|
|
24
|
+
function parseBranchRefs(output) {
|
|
19
25
|
return output
|
|
20
26
|
.split('\n')
|
|
21
27
|
.map((line) => parseBranchRef(line))
|
|
@@ -82,7 +88,7 @@ export async function collectBranchCommits(branch, options, run) {
|
|
|
82
88
|
.filter((commit) => commit !== undefined);
|
|
83
89
|
if (commits.length === 0)
|
|
84
90
|
return commits;
|
|
85
|
-
if (await alreadyOnTrunk(delta.base, branch, options.cwd, run))
|
|
91
|
+
if (!options.includeMerged && (await alreadyOnTrunk(delta.base, branch, options.cwd, run)))
|
|
86
92
|
return undefined;
|
|
87
93
|
if (options.withFiles === false)
|
|
88
94
|
return commits;
|
|
@@ -26,6 +26,8 @@ export interface SnapshotBranch extends BranchRef {
|
|
|
26
26
|
export interface CollectRefsOptions {
|
|
27
27
|
readonly cwd: string;
|
|
28
28
|
readonly branchCount: number;
|
|
29
|
+
/** Branches that must be returned even when they are older than the recent window. */
|
|
30
|
+
readonly requiredBranches?: readonly string[];
|
|
29
31
|
}
|
|
30
32
|
export interface CollectCommitsOptions {
|
|
31
33
|
readonly cwd: string;
|
|
@@ -33,6 +35,8 @@ export interface CollectCommitsOptions {
|
|
|
33
35
|
readonly withFiles?: boolean;
|
|
34
36
|
readonly defaultBranch?: string;
|
|
35
37
|
readonly commitCount: number;
|
|
38
|
+
/** Historical replay evidence stays useful after a squash/rebase puts the same tree on trunk. */
|
|
39
|
+
readonly includeMerged?: boolean;
|
|
36
40
|
}
|
|
37
41
|
/** One source file of a default-branch tree: its path and its top-level declaration names. */
|
|
38
42
|
export interface TreeFile {
|
|
@@ -507,7 +507,8 @@ async function trackTurnStage(state) {
|
|
|
507
507
|
async function billingFactSafely(state) {
|
|
508
508
|
try {
|
|
509
509
|
const surface = await resolveSurface(state.provider, state.env, state.payload);
|
|
510
|
-
|
|
510
|
+
const rooted = Object.keys(state.globalConfig.config.roots ?? {}).length > 0;
|
|
511
|
+
return await sessionBillingFact(new TurnStateStore(state.paths.turnsDir), state.events, state.provider, state.env, surface, rooted);
|
|
511
512
|
}
|
|
512
513
|
catch (error) {
|
|
513
514
|
debugLog('session billing fact failed:', error);
|
|
@@ -631,7 +632,9 @@ async function snapshot(state) {
|
|
|
631
632
|
// Never for an inherited repository: core may drop it when folder evidence
|
|
632
633
|
// disagrees, and a snapshot of it would mint a work unit for the wrong one.
|
|
633
634
|
const capture = state.workCapture ?? state.config.capture;
|
|
634
|
-
|
|
635
|
+
// A turn re-sent on a subagent's stop (late usage) was snapshotted at its close.
|
|
636
|
+
const closed = state.events.some((event) => event.event.type === 'generation.completed');
|
|
637
|
+
if (!repository || !closed || state.summary?.work_evidence === 'inherited' || !capture.git)
|
|
635
638
|
return stop(state, STOP_NO_SNAPSHOT);
|
|
636
639
|
const input = {
|
|
637
640
|
// The checkout the summary named, which need not be the folder the agent sits in.
|
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
import type { AgentWatchEvent } from '../../events/types/events.types.js';
|
|
2
|
+
import type { Env } from '../../core/types/core.types.js';
|
|
2
3
|
import type { HookContext, ShellCall } from '../types/provider.types.js';
|
|
3
4
|
import type { AntigravityHookEvent } from './types/antigravity.types.js';
|
|
4
5
|
export type { AntigravityHookEvent, AntigravityPayload } from './types/antigravity.types.js';
|
|
6
|
+
/**
|
|
7
|
+
* The transcript a hook's turn usage is read from.
|
|
8
|
+
*
|
|
9
|
+
* `transcriptPath` when the payload names it; otherwise the transcript under
|
|
10
|
+
* the conversation's brain directory, first through `artifactDirectoryPath`
|
|
11
|
+
* (which is that directory), then through `conversationId` in whichever app
|
|
12
|
+
* directory has it.
|
|
13
|
+
*
|
|
14
|
+
* @param rawPayload - Raw JSON from the hook's stdin.
|
|
15
|
+
* @param env - Where the home directory is.
|
|
16
|
+
* @returns The path, or undefined when the payload names no conversation.
|
|
17
|
+
*/
|
|
18
|
+
export declare function antigravityTranscriptPath(rawPayload: unknown, env: Env): string | undefined;
|
|
5
19
|
/**
|
|
6
20
|
* Which hook this payload is.
|
|
7
21
|
*
|
|
@@ -1,10 +1,57 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
1
3
|
import { sha256Hex } from '../../events/event-id.js';
|
|
2
4
|
import { baseEvent, promptPatch, responsePatch, toolPatch, withPatch } from '../shared/event-builder.js';
|
|
3
5
|
import { asRecord } from '../../core/object.js';
|
|
4
6
|
import { classifyTool, extractCommand, parseMcpToolName, shellCallOf, toolCompleteType, toolStartType } from '../shared/tooling.js';
|
|
5
|
-
import { ANTIGRAVITY_CWD_KEY, ANTIGRAVITY_DISPLAY_NAME, ANTIGRAVITY_HOOK_EVENT_BY_ARGS, ANTIGRAVITY_PROVIDER_ID, DOTLESS_MODEL_FAMILY, RE_MODEL_QUALIFIER, RE_MODEL_VERSION_DOT, RE_MODEL_WHITESPACE } from './constants/antigravity.constants.js';
|
|
7
|
+
import { ANTIGRAVITY_APP_DIRS, ANTIGRAVITY_ARGS_KEY_BY_EVENT, ANTIGRAVITY_BRAIN_DIR, ANTIGRAVITY_GEMINI_DIR, ANTIGRAVITY_TRANSCRIPT_SEGMENTS, RE_SAFE_CONVERSATION_ID, ANTIGRAVITY_CWD_KEY, ANTIGRAVITY_DISPLAY_NAME, ANTIGRAVITY_HOOK_EVENT_BY_ARGS, ANTIGRAVITY_PROVIDER_ID, DOTLESS_MODEL_FAMILY, RE_MODEL_QUALIFIER, RE_MODEL_VERSION_DOT, RE_MODEL_WHITESPACE } from './constants/antigravity.constants.js';
|
|
6
8
|
import { antigravityPayloadSchema } from './schemas/antigravity.schema.js';
|
|
7
9
|
const ARGS_KEYS = Object.keys(ANTIGRAVITY_HOOK_EVENT_BY_ARGS);
|
|
10
|
+
/**
|
|
11
|
+
* Parse a hook payload in either shape Antigravity has written.
|
|
12
|
+
*
|
|
13
|
+
* agy 1.5.0 sends a flat object: the common fields at the top level and a
|
|
14
|
+
* `hookEventName`, with no `common` block and no oneof member (captured
|
|
15
|
+
* 2026-11-14). Older builds send the nested `HookArgs` protojson. A flat
|
|
16
|
+
* payload is lifted into the nested shape by placing the whole object in both
|
|
17
|
+
* `common` and the member its event names; the passthrough schemas ignore the
|
|
18
|
+
* extra keys. Any other shape is left alone and yields no hook.
|
|
19
|
+
*
|
|
20
|
+
* @param rawPayload - Raw JSON from the hook's stdin.
|
|
21
|
+
* @returns The schema's parse result.
|
|
22
|
+
*/
|
|
23
|
+
function parsePayload(rawPayload) {
|
|
24
|
+
const record = asRecord(rawPayload);
|
|
25
|
+
const event = record?.['hookEventName'];
|
|
26
|
+
const key = typeof event === 'string' && record?.['common'] === undefined ? ANTIGRAVITY_ARGS_KEY_BY_EVENT.get(event) : undefined;
|
|
27
|
+
return antigravityPayloadSchema.safeParse(key ? { common: record, [key]: record } : rawPayload);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The transcript a hook's turn usage is read from.
|
|
31
|
+
*
|
|
32
|
+
* `transcriptPath` when the payload names it; otherwise the transcript under
|
|
33
|
+
* the conversation's brain directory, first through `artifactDirectoryPath`
|
|
34
|
+
* (which is that directory), then through `conversationId` in whichever app
|
|
35
|
+
* directory has it.
|
|
36
|
+
*
|
|
37
|
+
* @param rawPayload - Raw JSON from the hook's stdin.
|
|
38
|
+
* @param env - Where the home directory is.
|
|
39
|
+
* @returns The path, or undefined when the payload names no conversation.
|
|
40
|
+
*/
|
|
41
|
+
export function antigravityTranscriptPath(rawPayload, env) {
|
|
42
|
+
const parsed = parsePayload(rawPayload);
|
|
43
|
+
const common = parsed.success ? parsed.data.common : undefined;
|
|
44
|
+
if (common?.transcriptPath)
|
|
45
|
+
return common.transcriptPath;
|
|
46
|
+
if (common?.artifactDirectoryPath)
|
|
47
|
+
return path.join(common.artifactDirectoryPath, ...ANTIGRAVITY_TRANSCRIPT_SEGMENTS);
|
|
48
|
+
const conversationId = common?.conversationId;
|
|
49
|
+
// A path segment from the payload: never let it climb out of brain/.
|
|
50
|
+
if (!conversationId || !RE_SAFE_CONVERSATION_ID.test(conversationId))
|
|
51
|
+
return undefined;
|
|
52
|
+
const candidates = ANTIGRAVITY_APP_DIRS.map((app) => path.join(env.home, ANTIGRAVITY_GEMINI_DIR, app, ANTIGRAVITY_BRAIN_DIR, conversationId, ...ANTIGRAVITY_TRANSCRIPT_SEGMENTS));
|
|
53
|
+
return candidates.find((candidate) => existsSync(candidate));
|
|
54
|
+
}
|
|
8
55
|
/**
|
|
9
56
|
* Which hook this payload is.
|
|
10
57
|
*
|
|
@@ -17,7 +64,7 @@ const ARGS_KEYS = Object.keys(ANTIGRAVITY_HOOK_EVENT_BY_ARGS);
|
|
|
17
64
|
* @returns The hook name, or undefined.
|
|
18
65
|
*/
|
|
19
66
|
export function antigravityHookEvent(rawPayload) {
|
|
20
|
-
const parsed =
|
|
67
|
+
const parsed = parsePayload(rawPayload);
|
|
21
68
|
if (!parsed.success)
|
|
22
69
|
return undefined;
|
|
23
70
|
const key = ARGS_KEYS.find((candidate) => parsed.data[candidate] !== undefined);
|
|
@@ -33,7 +80,7 @@ export function antigravityHookEvent(rawPayload) {
|
|
|
33
80
|
* @returns The primary workspace path, or undefined.
|
|
34
81
|
*/
|
|
35
82
|
export function antigravityCwd(rawPayload) {
|
|
36
|
-
const parsed =
|
|
83
|
+
const parsed = parsePayload(rawPayload);
|
|
37
84
|
if (!parsed.success)
|
|
38
85
|
return undefined;
|
|
39
86
|
return parsed.data.common?.workspacePaths?.[0];
|
|
@@ -49,7 +96,7 @@ export function antigravityCwd(rawPayload) {
|
|
|
49
96
|
* @returns The call, or undefined for any other payload.
|
|
50
97
|
*/
|
|
51
98
|
export function antigravityShellCall(rawPayload) {
|
|
52
|
-
const parsed =
|
|
99
|
+
const parsed = parsePayload(rawPayload);
|
|
53
100
|
const toolCall = parsed.success ? (parsed.data.preToolHookArgs ?? parsed.data.postToolHookArgs)?.toolCall : undefined;
|
|
54
101
|
if (classifyTool(toolCall?.name) !== 'shell')
|
|
55
102
|
return undefined;
|
|
@@ -69,7 +116,7 @@ export function antigravityShellCall(rawPayload) {
|
|
|
69
116
|
* @returns The canonical events, or an empty list for an unusable payload.
|
|
70
117
|
*/
|
|
71
118
|
export function parseAntigravityHookEvent(rawPayload, context) {
|
|
72
|
-
const parsed =
|
|
119
|
+
const parsed = parsePayload(rawPayload);
|
|
73
120
|
if (!parsed.success)
|
|
74
121
|
return [];
|
|
75
122
|
const payload = parsed.data;
|
|
@@ -156,7 +203,7 @@ function hookPatch(payload, hook, context) {
|
|
|
156
203
|
// `common.lastUserInput` by every hook of the execution. The first
|
|
157
204
|
// invocation is therefore where the turn's prompt is recorded; later
|
|
158
205
|
// invocations are model calls inside the same turn.
|
|
159
|
-
if (!isFirstInvocation(payload
|
|
206
|
+
if (!isFirstInvocation(payload))
|
|
160
207
|
return {};
|
|
161
208
|
return promptPatch(payload.common?.lastUserInput ?? '', context.config.capture);
|
|
162
209
|
}
|
|
@@ -180,7 +227,7 @@ function hookPatch(payload, hook, context) {
|
|
|
180
227
|
function antigravityToolPatch(payload, hook, context) {
|
|
181
228
|
const toolCall = toolCallOf(payload, hook);
|
|
182
229
|
const kind = classifyTool(toolCall?.name);
|
|
183
|
-
const failed = hook === 'PostToolUse' && payload
|
|
230
|
+
const failed = hook === 'PostToolUse' && toolFailed(payload);
|
|
184
231
|
const mcp = kind === 'mcp' && toolCall?.name ? parseMcpToolName(toolCall.name) : undefined;
|
|
185
232
|
return toolPatch({
|
|
186
233
|
name: toolCall?.name,
|
|
@@ -220,29 +267,50 @@ function canonicalType(payload, hook) {
|
|
|
220
267
|
if (hook === 'Stop')
|
|
221
268
|
return 'generation.completed';
|
|
222
269
|
if (hook === 'PreInvocation') {
|
|
223
|
-
return isFirstInvocation(payload
|
|
270
|
+
return isFirstInvocation(payload) ? 'prompt.submitted' : 'agent.other';
|
|
224
271
|
}
|
|
225
272
|
if (hook === 'PostInvocation')
|
|
226
273
|
return 'agent.other';
|
|
227
274
|
if (hook === 'PreToolUse')
|
|
228
275
|
return toolStartType(classifyTool(payload.preToolHookArgs?.toolCall?.name));
|
|
229
|
-
if (payload
|
|
276
|
+
if (toolFailed(payload))
|
|
230
277
|
return 'tool.failed';
|
|
231
278
|
return toolCompleteType(classifyTool(payload.postToolHookArgs?.toolCall?.name));
|
|
232
279
|
}
|
|
233
280
|
/**
|
|
234
|
-
* Whether
|
|
281
|
+
* Whether a post-tool payload reports a failure.
|
|
282
|
+
*
|
|
283
|
+
* agy 1.5.0 sends `error: ""` on success (an unset proto string), so only a
|
|
284
|
+
* non-empty error is one; older builds omit the field.
|
|
285
|
+
*
|
|
286
|
+
* @param payload - Parsed hook payload.
|
|
287
|
+
* @returns True when the tool call failed.
|
|
288
|
+
*/
|
|
289
|
+
function toolFailed(payload) {
|
|
290
|
+
const error = payload.postToolHookArgs?.error;
|
|
291
|
+
return error !== undefined && error !== '';
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Whether a `PreInvocation` names the execution's first model call.
|
|
235
295
|
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
296
|
+
* agy 1.5.0's flat payload counts from 0 and restarts at 0 on every turn of a
|
|
297
|
+
* conversation (captured 2026-11-14, two turns of one conversation), so there
|
|
298
|
+
* only 0 is first: invocation 1 is the second model call, and with no `executionId` a
|
|
299
|
+
* second prompt record would not dedupe. The nested shape's base is not
|
|
300
|
+
* documented, so both 0 and 1 count as first there; its records carry the
|
|
301
|
+
* execution id, so a repeat is harmless.
|
|
239
302
|
*
|
|
240
|
-
* @param
|
|
303
|
+
* @param payload - Parsed hook payload.
|
|
241
304
|
* @returns True when this is the first invocation.
|
|
242
305
|
*/
|
|
243
|
-
function isFirstInvocation(
|
|
244
|
-
const
|
|
245
|
-
|
|
306
|
+
function isFirstInvocation(payload) {
|
|
307
|
+
const args = payload.preInvocationHookArgs;
|
|
308
|
+
const value = numeric(args?.invocationNum);
|
|
309
|
+
if (value === undefined)
|
|
310
|
+
return true;
|
|
311
|
+
if (args?.['hookEventName'] !== undefined)
|
|
312
|
+
return value === 0;
|
|
313
|
+
return value <= 1;
|
|
246
314
|
}
|
|
247
315
|
/**
|
|
248
316
|
* The tool call one of the tool hooks carries.
|
|
@@ -297,7 +365,7 @@ function rawStepIdx(payload, hook) {
|
|
|
297
365
|
* @returns The parts to hash.
|
|
298
366
|
*/
|
|
299
367
|
function fingerprintParts(payload, hook) {
|
|
300
|
-
if (hook === 'PreInvocation' && isFirstInvocation(payload
|
|
368
|
+
if (hook === 'PreInvocation' && isFirstInvocation(payload)) {
|
|
301
369
|
return ['prompt', payload.common?.lastUserInput ?? ''];
|
|
302
370
|
}
|
|
303
371
|
return [payload.common?.modelName, toolCallOf(payload, hook)?.name, invocationOf(payload, hook)];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { googleAccountBillingMode } from '../../billing/billing-mode.js';
|
|
2
|
+
import { readAntigravityTurnUsage } from '../../turns/antigravity-transcript.js';
|
|
2
3
|
import { IDE_SURFACE } from '../../turns/constants/turns.constants.js';
|
|
3
|
-
import { antigravityCwd, antigravityHookEvent, antigravityShellCall, parseAntigravityHookEvent } from './antigravity.adapter.js';
|
|
4
|
+
import { antigravityCwd, antigravityHookEvent, antigravityShellCall, antigravityTranscriptPath, parseAntigravityHookEvent } from './antigravity.adapter.js';
|
|
4
5
|
import { antigravityCapture } from './antigravity.capture.js';
|
|
5
6
|
import { detectAntigravity } from './antigravity.detect.js';
|
|
6
7
|
import { installAntigravityHooks, uninstallAntigravityHooks } from './antigravity.hooks.js';
|
|
@@ -20,11 +21,13 @@ export const antigravityProvider = {
|
|
|
20
21
|
},
|
|
21
22
|
resolveCwd: antigravityCwd,
|
|
22
23
|
shellCall: antigravityShellCall,
|
|
24
|
+
readTurnUsage: readAntigravityTurnUsage,
|
|
25
|
+
transcriptPath: antigravityTranscriptPath,
|
|
23
26
|
surface: async () => IDE_SURFACE,
|
|
24
27
|
/** Signed in through the shared `~/.gemini` Google account, as Gemini CLI is. */
|
|
25
28
|
billingMode: googleAccountBillingMode
|
|
26
29
|
// No nativeTelemetry: Antigravity exposes no OTLP exporter configuration, so
|
|
27
|
-
// there is no llm.call ledger source
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
+
// there is no llm.call ledger source; the transcript's step counts are the
|
|
31
|
+
// only usage. Adding a configurator would claim a capability the agent does
|
|
32
|
+
// not have.
|
|
30
33
|
};
|
|
@@ -73,3 +73,13 @@ export declare const ANTIGRAVITY_HOOK_EVENT_BY_ARGS: {
|
|
|
73
73
|
readonly stopHookArgs: "Stop";
|
|
74
74
|
readonly sessionStartHookArgs: "SessionStart";
|
|
75
75
|
};
|
|
76
|
+
/** hooks.json event name -> the `HookArgs` oneof member carrying it, for flat payloads. */
|
|
77
|
+
export declare const ANTIGRAVITY_ARGS_KEY_BY_EVENT: ReadonlyMap<string, keyof typeof ANTIGRAVITY_HOOK_EVENT_BY_ARGS>;
|
|
78
|
+
/** The transcript under a conversation's brain directory (`artifactDirectoryPath`). */
|
|
79
|
+
export declare const ANTIGRAVITY_TRANSCRIPT_SEGMENTS: readonly [".system_generated", "logs", "transcript_full.jsonl"];
|
|
80
|
+
/** App directories under `~/.gemini` that hold `brain/`: CLI, Antigravity 2.0, IDE. */
|
|
81
|
+
export declare const ANTIGRAVITY_APP_DIRS: readonly ["antigravity-cli", "antigravity", "antigravity-ide"];
|
|
82
|
+
export declare const ANTIGRAVITY_GEMINI_DIR = ".gemini";
|
|
83
|
+
export declare const ANTIGRAVITY_BRAIN_DIR = "brain";
|
|
84
|
+
/** A conversation id safe to use as one path segment. */
|
|
85
|
+
export declare const RE_SAFE_CONVERSATION_ID: RegExp;
|
|
@@ -76,3 +76,13 @@ export const ANTIGRAVITY_HOOK_EVENT_BY_ARGS = {
|
|
|
76
76
|
stopHookArgs: 'Stop',
|
|
77
77
|
sessionStartHookArgs: 'SessionStart'
|
|
78
78
|
};
|
|
79
|
+
/** hooks.json event name -> the `HookArgs` oneof member carrying it, for flat payloads. */
|
|
80
|
+
export const ANTIGRAVITY_ARGS_KEY_BY_EVENT = new Map(Object.entries(ANTIGRAVITY_HOOK_EVENT_BY_ARGS).map(([key, event]) => [event, key]));
|
|
81
|
+
/** The transcript under a conversation's brain directory (`artifactDirectoryPath`). */
|
|
82
|
+
export const ANTIGRAVITY_TRANSCRIPT_SEGMENTS = ['.system_generated', 'logs', 'transcript_full.jsonl'];
|
|
83
|
+
/** App directories under `~/.gemini` that hold `brain/`: CLI, Antigravity 2.0, IDE. */
|
|
84
|
+
export const ANTIGRAVITY_APP_DIRS = ['antigravity-cli', 'antigravity', 'antigravity-ide'];
|
|
85
|
+
export const ANTIGRAVITY_GEMINI_DIR = '.gemini';
|
|
86
|
+
export const ANTIGRAVITY_BRAIN_DIR = 'brain';
|
|
87
|
+
/** A conversation id safe to use as one path segment. */
|
|
88
|
+
export const RE_SAFE_CONVERSATION_ID = /^[A-Za-z0-9_-]+$/;
|
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
/**
|
|
3
|
-
* Antigravity hook payloads.
|
|
3
|
+
* Antigravity hook payloads, in the nested shape.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* (`third_party/jetski/hooks_pb/hooks.proto`, read off the `agy` binary)
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* and the event is whichever member of that oneof is set. Reading a
|
|
12
|
-
* `hookEventName` — a field that exists in no version of this schema — is how
|
|
13
|
-
* this provider previously produced `agent.other` with no session id for every
|
|
14
|
-
* hook, which the turn tracker then discarded.
|
|
15
|
-
* - Identity is nested in `common`, and tool arguments are PascalCase
|
|
16
|
-
* (`TargetFile`, `CommandLine`) rather than the snake_case used elsewhere.
|
|
5
|
+
* Older builds send protojson of `exa.hooks_pb.HookArgs`
|
|
6
|
+
* (`third_party/jetski/hooks_pb/hooks.proto`, read off the `agy` binary): a
|
|
7
|
+
* `common` block plus a oneof, the event being whichever member is set, with no
|
|
8
|
+
* event-name field. agy 1.5.0 sends a flat object with `hookEventName` instead;
|
|
9
|
+
* the adapter lifts that into this shape before parsing, so one schema serves
|
|
10
|
+
* both. Tool arguments are PascalCase (`TargetFile`, `CommandLine`) in both.
|
|
17
11
|
*/
|
|
18
12
|
/** proto3 JSON encodes int32 as a number and int64 as a string. */
|
|
19
13
|
const protoInt = z.union([z.number(), z.string()]).optional();
|
|
@@ -48,7 +48,7 @@ export declare class ClaudeOtelConfigurator implements NativeTelemetryConfigurat
|
|
|
48
48
|
node: string;
|
|
49
49
|
python: string;
|
|
50
50
|
});
|
|
51
|
-
/** Run capture rides in the same env block,
|
|
51
|
+
/** Run capture rides in the same env block, on its own switch (`capture.runs`), not the exporters'. */
|
|
52
52
|
readonly runCapture: {
|
|
53
53
|
configPath: typeof claudeSettingsPath;
|
|
54
54
|
inspect: (context: SetupContext) => Promise<import("../types/provider.types.js").RunCaptureStatus>;
|
|
@@ -94,6 +94,14 @@ export declare class ClaudeOtelConfigurator implements NativeTelemetryConfigurat
|
|
|
94
94
|
* install state.
|
|
95
95
|
*/
|
|
96
96
|
uninstall(context: SetupContext): Promise<SetupOutcome>;
|
|
97
|
+
/**
|
|
98
|
+
* Uninstall's work, optionally leaving run capture's part of the env block.
|
|
99
|
+
*
|
|
100
|
+
* @param context - Environment, paths, config and install state.
|
|
101
|
+
* @param keepCapture - Leave run capture in: `otel: none` with `capture.runs` on.
|
|
102
|
+
* @returns As `uninstall`.
|
|
103
|
+
*/
|
|
104
|
+
private removeTelemetry;
|
|
97
105
|
/**
|
|
98
106
|
* Where the exporter setup recorded as AgentWatch's sends. Nothing without
|
|
99
107
|
* that record: the endpoint may then be the developer's own.
|
|
@@ -109,6 +117,30 @@ export declare class ClaudeOtelConfigurator implements NativeTelemetryConfigurat
|
|
|
109
117
|
* @returns The outcome.
|
|
110
118
|
*/
|
|
111
119
|
private configureDisabled;
|
|
120
|
+
/**
|
|
121
|
+
* The env block with run capture in or out, as `capture.runs` says.
|
|
122
|
+
*
|
|
123
|
+
* @param envBlock - The env block as it stands.
|
|
124
|
+
* @param context - Environment, paths and config.
|
|
125
|
+
* @returns The next env block.
|
|
126
|
+
*/
|
|
127
|
+
private capturedEnv;
|
|
128
|
+
/**
|
|
129
|
+
* Run capture alone, as a step that says rather than throws when it cannot write: an
|
|
130
|
+
* optional key must never fail setup or `agentwatch on` (`withCaptureOutcome`).
|
|
131
|
+
*
|
|
132
|
+
* @param context - Environment, paths and config.
|
|
133
|
+
* @returns Whether the file changed, and what to tell the user.
|
|
134
|
+
*/
|
|
135
|
+
private captureOnly;
|
|
136
|
+
/**
|
|
137
|
+
* Write run capture alone, in or out as `capture.runs` says, when the exporters are
|
|
138
|
+
* off or skipped over a conflict.
|
|
139
|
+
*
|
|
140
|
+
* @param context - Environment, paths and config.
|
|
141
|
+
* @returns Whether the file changed; an unreadable or non-object file is left alone.
|
|
142
|
+
*/
|
|
143
|
+
private writeCaptureOnly;
|
|
112
144
|
/**
|
|
113
145
|
* Add the header-helper command when a token needs one.
|
|
114
146
|
*
|