@agent-watch-ai/edge 0.2.5 → 0.4.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 +558 -0
- package/README.md +222 -97
- package/SECURITY.md +72 -0
- package/dist/billing/session-billing.d.ts +19 -0
- package/dist/billing/session-billing.js +52 -0
- package/dist/cli/args.d.ts +10 -0
- package/dist/cli/args.js +20 -0
- package/dist/cli/constants/cli.constants.d.ts +52 -4
- package/dist/cli/constants/cli.constants.js +56 -5
- package/dist/cli/context.d.ts +33 -2
- package/dist/cli/context.js +84 -14
- package/dist/cli/doctor.js +321 -33
- package/dist/cli/hook-check.d.ts +23 -0
- package/dist/cli/hook-check.js +114 -0
- package/dist/cli/hook.js +118 -7
- package/dist/cli/index.d.ts +3 -1
- package/dist/cli/index.js +3 -1
- package/dist/cli/misc.d.ts +11 -0
- package/dist/cli/misc.js +80 -4
- package/dist/cli/npx-install.d.ts +37 -0
- package/dist/cli/npx-install.js +79 -0
- package/dist/cli/open-browser.d.ts +39 -0
- package/dist/cli/open-browser.js +62 -0
- package/dist/cli/setup.d.ts +17 -8
- package/dist/cli/setup.js +553 -103
- package/dist/cli/status.js +82 -13
- package/dist/cli/toggle.d.ts +9 -0
- package/dist/cli/toggle.js +117 -0
- package/dist/cli/types/cli.types.d.ts +43 -3
- package/dist/cli/ui.d.ts +7 -0
- package/dist/cli/ui.js +10 -1
- package/dist/cli/uninstall.js +39 -2
- package/dist/cli/update.d.ts +17 -0
- package/dist/cli/update.js +76 -0
- package/dist/cli.js +110 -12
- package/dist/config/config-store.d.ts +57 -0
- package/dist/config/config-store.js +250 -12
- package/dist/config/config.d.ts +53 -6
- package/dist/config/config.js +66 -6
- package/dist/config/constants/config.constants.d.ts +116 -6
- package/dist/config/constants/config.constants.js +131 -8
- package/dist/config/destination.d.ts +24 -0
- package/dist/config/destination.js +33 -0
- package/dist/config/index.d.ts +7 -4
- package/dist/config/index.js +5 -3
- package/dist/config/repo-config.d.ts +11 -7
- package/dist/config/repo-config.js +64 -15
- package/dist/config/root-config.d.ts +72 -0
- package/dist/config/root-config.js +170 -0
- package/dist/config/schemas/config.schema.d.ts +831 -84
- package/dist/config/schemas/config.schema.js +398 -16
- package/dist/config/types/config.types.d.ts +15 -1
- package/dist/config/types/destination.types.d.ts +8 -0
- package/dist/core/async.d.ts +36 -0
- package/dist/core/async.js +68 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/object.d.ts +5 -0
- package/dist/core/object.js +9 -4
- package/dist/core/pipe.d.ts +0 -13
- package/dist/core/pipe.js +1 -9
- package/dist/core/types/core.types.d.ts +9 -0
- package/dist/core/types/core.types.js +0 -3
- package/dist/core/which.d.ts +14 -0
- package/dist/core/which.js +43 -3
- package/dist/credentials/budget.d.ts +9 -0
- package/dist/credentials/budget.js +16 -0
- package/dist/credentials/command-runner.d.ts +16 -0
- package/dist/credentials/command-runner.js +37 -0
- package/dist/credentials/constants/credentials.constants.d.ts +119 -0
- package/dist/credentials/constants/credentials.constants.js +120 -0
- package/dist/credentials/credential-status.d.ts +14 -0
- package/dist/credentials/credential-status.js +38 -0
- package/dist/credentials/credentials.d.ts +86 -0
- package/dist/credentials/credentials.js +278 -0
- package/dist/credentials/device-api.d.ts +73 -0
- package/dist/credentials/device-api.js +161 -0
- package/dist/credentials/device-state.d.ts +31 -0
- package/dist/credentials/device-state.js +51 -0
- package/dist/credentials/identity.d.ts +73 -0
- package/dist/credentials/identity.js +101 -0
- package/dist/credentials/index.d.ts +7 -0
- package/dist/credentials/index.js +5 -0
- package/dist/credentials/migration.d.ts +46 -0
- package/dist/credentials/migration.js +164 -0
- package/dist/credentials/schemas/device-api.schema.d.ts +77 -0
- package/dist/credentials/schemas/device-api.schema.js +33 -0
- package/dist/credentials/schemas/device-state.schema.d.ts +51 -0
- package/dist/credentials/schemas/device-state.schema.js +20 -0
- package/dist/credentials/secret-store.d.ts +54 -0
- package/dist/credentials/secret-store.js +217 -0
- package/dist/credentials/sign-in.d.ts +31 -0
- package/dist/credentials/sign-in.js +105 -0
- package/dist/credentials/token-refresher.d.ts +39 -0
- package/dist/credentials/token-refresher.js +185 -0
- package/dist/credentials/types/credentials.types.d.ts +206 -0
- package/dist/credentials/types/credentials.types.js +1 -0
- package/dist/enforcement/constants/enforcement.constants.d.ts +47 -1
- package/dist/enforcement/constants/enforcement.constants.js +56 -0
- package/dist/enforcement/decision-cache.d.ts +20 -1
- package/dist/enforcement/decision-cache.js +65 -2
- package/dist/enforcement/decision-client.d.ts +9 -8
- package/dist/enforcement/decision-client.js +64 -17
- package/dist/enforcement/enforcement.d.ts +23 -2
- package/dist/enforcement/enforcement.js +107 -17
- package/dist/enforcement/index.d.ts +4 -3
- package/dist/enforcement/index.js +3 -2
- package/dist/enforcement/types/enforcement.types.d.ts +66 -2
- package/dist/enrollment/constants/enrollment.constants.d.ts +2 -6
- package/dist/enrollment/constants/enrollment.constants.js +2 -6
- package/dist/enrollment/enrollment.d.ts +16 -0
- package/dist/enrollment/enrollment.js +54 -0
- package/dist/enrollment/index.d.ts +3 -7
- package/dist/enrollment/index.js +1 -1
- package/dist/enrollment/types/enrollment.types.d.ts +9 -13
- package/dist/events/constants/enrich.constants.d.ts +15 -0
- package/dist/events/constants/enrich.constants.js +15 -0
- package/dist/events/constants/events.constants.d.ts +6 -2
- package/dist/events/constants/events.constants.js +5 -1
- package/dist/events/enrich.js +92 -10
- package/dist/events/event-id.d.ts +0 -8
- package/dist/events/event-id.js +0 -10
- package/dist/events/index.d.ts +2 -2
- package/dist/events/index.js +1 -1
- package/dist/events/product-event.d.ts +9 -6
- package/dist/events/types/repo-snapshot.types.d.ts +7 -0
- package/dist/events/types/session-billing.types.d.ts +16 -0
- package/dist/events/types/session-billing.types.js +1 -0
- package/dist/feature/constants/feature.constants.d.ts +7 -0
- package/dist/feature/constants/feature.constants.js +7 -0
- package/dist/feature/index.d.ts +1 -1
- package/dist/feature/index.js +1 -1
- package/dist/feature/ticket-candidates.d.ts +14 -0
- package/dist/feature/ticket-candidates.js +26 -8
- package/dist/git/blob-hash.d.ts +21 -0
- package/dist/git/blob-hash.js +69 -0
- package/dist/git/checkout-root.d.ts +27 -0
- package/dist/git/checkout-root.js +75 -0
- package/dist/git/constants/git.constants.d.ts +160 -0
- package/dist/git/constants/git.constants.js +181 -0
- package/dist/git/fingerprint.d.ts +74 -0
- package/dist/git/fingerprint.js +219 -0
- package/dist/git/gate-checkout.d.ts +44 -0
- package/dist/git/gate-checkout.js +201 -0
- package/dist/git/git-context.d.ts +45 -0
- package/dist/git/git-context.js +61 -3
- package/dist/git/index.d.ts +4 -2
- package/dist/git/index.js +2 -1
- package/dist/git/manifest-repository.d.ts +13 -0
- package/dist/git/manifest-repository.js +92 -0
- package/dist/git/repo-snapshot.d.ts +29 -3
- package/dist/git/repo-snapshot.js +110 -7
- package/dist/git/repository-root.d.ts +39 -0
- package/dist/git/repository-root.js +131 -0
- package/dist/git/types/git.types.d.ts +55 -0
- package/dist/git/types/repository-root.types.d.ts +11 -0
- package/dist/git/types/repository-root.types.js +1 -0
- package/dist/git/types/snapshot.types.d.ts +9 -0
- package/dist/pipeline/constants/pipeline.constants.d.ts +10 -0
- package/dist/pipeline/constants/pipeline.constants.js +10 -0
- package/dist/pipeline/hook-pipeline.js +410 -33
- package/dist/pipeline/types/pipeline.types.d.ts +39 -4
- package/dist/privacy/constants/privacy.constants.js +15 -1
- package/dist/privacy/index.d.ts +1 -0
- package/dist/privacy/index.js +1 -0
- package/dist/privacy/product-capture.d.ts +12 -0
- package/dist/privacy/product-capture.js +75 -0
- package/dist/privacy/sanitizer.d.ts +21 -3
- package/dist/privacy/sanitizer.js +52 -8
- package/dist/process/ancestors.d.ts +39 -0
- package/dist/process/ancestors.js +121 -0
- package/dist/process/constants/process.constants.d.ts +34 -0
- package/dist/process/constants/process.constants.js +34 -0
- package/dist/process/index.d.ts +7 -0
- package/dist/process/index.js +2 -0
- package/dist/process/types/process.types.d.ts +23 -0
- package/dist/process/types/process.types.js +1 -0
- package/dist/providers/antigravity/antigravity.adapter.d.ts +12 -1
- package/dist/providers/antigravity/antigravity.adapter.js +21 -3
- package/dist/providers/antigravity/antigravity.detect.d.ts +0 -9
- package/dist/providers/antigravity/antigravity.detect.js +1 -1
- package/dist/providers/antigravity/antigravity.provider.js +3 -2
- package/dist/providers/antigravity/constants/antigravity.constants.d.ts +2 -0
- package/dist/providers/antigravity/constants/antigravity.constants.js +2 -0
- package/dist/providers/claude/claude.adapter.d.ts +11 -1
- package/dist/providers/claude/claude.adapter.js +26 -5
- package/dist/providers/claude/claude.otel.d.ts +32 -18
- package/dist/providers/claude/claude.otel.js +81 -6
- package/dist/providers/claude/claude.provider.js +5 -2
- package/dist/providers/claude/constants/claude.constants.d.ts +2 -0
- package/dist/providers/claude/constants/claude.constants.js +2 -0
- package/dist/providers/claude/constants/claude.otel.constants.d.ts +4 -0
- package/dist/providers/claude/constants/claude.otel.constants.js +8 -0
- package/dist/providers/codex/codex.adapter.d.ts +15 -1
- package/dist/providers/codex/codex.adapter.js +29 -5
- package/dist/providers/codex/codex.otel.d.ts +36 -3
- package/dist/providers/codex/codex.otel.js +199 -32
- package/dist/providers/codex/codex.provider.js +5 -2
- package/dist/providers/codex/constants/codex.constants.d.ts +2 -0
- package/dist/providers/codex/constants/codex.constants.js +16 -0
- package/dist/providers/codex/constants/codex.otel.constants.d.ts +10 -0
- package/dist/providers/codex/constants/codex.otel.constants.js +10 -0
- package/dist/providers/constants/provider.constants.d.ts +8 -3
- package/dist/providers/constants/provider.constants.js +8 -3
- package/dist/providers/cursor/constants/cursor.constants.d.ts +9 -0
- package/dist/providers/cursor/constants/cursor.constants.js +9 -0
- package/dist/providers/cursor/cursor.adapter.d.ts +33 -1
- package/dist/providers/cursor/cursor.adapter.js +129 -4
- package/dist/providers/cursor/cursor.detect.d.ts +0 -7
- package/dist/providers/cursor/cursor.detect.js +1 -1
- package/dist/providers/cursor/cursor.provider.js +5 -2
- package/dist/providers/gemini/constants/gemini.constants.d.ts +9 -0
- package/dist/providers/gemini/constants/gemini.constants.js +9 -0
- package/dist/providers/gemini/constants/gemini.otel.constants.d.ts +9 -1
- package/dist/providers/gemini/constants/gemini.otel.constants.js +9 -0
- package/dist/providers/gemini/gemini.adapter.d.ts +14 -1
- package/dist/providers/gemini/gemini.adapter.js +25 -5
- package/dist/providers/gemini/gemini.detect.d.ts +0 -7
- package/dist/providers/gemini/gemini.detect.js +1 -1
- package/dist/providers/gemini/gemini.otel.d.ts +30 -21
- package/dist/providers/gemini/gemini.otel.js +166 -22
- package/dist/providers/gemini/gemini.provider.js +2 -1
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +1 -1
- package/dist/providers/loaders.d.ts +10 -0
- package/dist/providers/loaders.js +40 -0
- package/dist/providers/provider.d.ts +11 -0
- package/dist/providers/provider.js +1 -1
- package/dist/providers/registry.d.ts +11 -8
- package/dist/providers/registry.js +11 -15
- package/dist/providers/shared/bearer-rewrite.d.ts +19 -0
- package/dist/providers/shared/bearer-rewrite.js +46 -0
- package/dist/providers/shared/constants/hook-refusal.constants.d.ts +7 -0
- package/dist/providers/shared/constants/hook-refusal.constants.js +7 -0
- package/dist/providers/shared/constants/shell-directories.constants.d.ts +30 -0
- package/dist/providers/shared/constants/shell-directories.constants.js +39 -0
- package/dist/providers/shared/constants/tooling.constants.d.ts +24 -2
- package/dist/providers/shared/constants/tooling.constants.js +25 -3
- package/dist/providers/shared/event-builder.d.ts +12 -14
- package/dist/providers/shared/event-builder.js +20 -14
- package/dist/providers/shared/exporter-allowlist.d.ts +20 -0
- package/dist/providers/shared/exporter-allowlist.js +49 -0
- package/dist/providers/shared/hook-config.d.ts +2 -21
- package/dist/providers/shared/hook-config.js +5 -4
- package/dist/providers/shared/hook-refusal.d.ts +12 -0
- package/dist/providers/shared/hook-refusal.js +17 -1
- package/dist/providers/shared/install-record.d.ts +12 -2
- package/dist/providers/shared/install-record.js +5 -2
- package/dist/providers/shared/shell-directories.d.ts +24 -0
- package/dist/providers/shared/shell-directories.js +90 -0
- package/dist/providers/shared/tooling.d.ts +40 -1
- package/dist/providers/shared/tooling.js +70 -1
- package/dist/providers/shared/types/adapter.types.d.ts +1 -2
- package/dist/providers/types/provider.types.d.ts +81 -1
- package/dist/snapshot/constants/snapshot.constants.d.ts +32 -0
- package/dist/snapshot/constants/snapshot.constants.js +33 -0
- package/dist/snapshot/snapshot-event.js +52 -11
- package/dist/snapshot/snapshot-pipeline.js +1 -1
- package/dist/snapshot/types/snapshot.types.d.ts +2 -0
- package/dist/storage/atomic-file.d.ts +21 -0
- package/dist/storage/atomic-file.js +20 -1
- package/dist/storage/constants/storage.constants.d.ts +19 -0
- package/dist/storage/constants/storage.constants.js +19 -0
- package/dist/storage/disabled.d.ts +13 -0
- package/dist/storage/disabled.js +24 -0
- package/dist/storage/index.d.ts +2 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/paths.js +3 -2
- package/dist/storage/schemas/storage.schema.d.ts +72 -0
- package/dist/storage/schemas/storage.schema.js +6 -0
- package/dist/storage/sweep-marker.d.ts +19 -0
- package/dist/storage/sweep-marker.js +55 -0
- package/dist/storage/types/storage.types.d.ts +2 -0
- package/dist/storage/uninstalled.d.ts +58 -0
- package/dist/storage/uninstalled.js +107 -0
- package/dist/transport/auth-block.d.ts +66 -0
- package/dist/transport/auth-block.js +129 -0
- package/dist/transport/constants/transport.constants.d.ts +82 -3
- package/dist/transport/constants/transport.constants.js +83 -4
- package/dist/transport/cooldown.js +8 -1
- package/dist/transport/delivery.d.ts +14 -6
- package/dist/transport/delivery.js +80 -55
- package/dist/transport/http-transport.d.ts +1 -0
- package/dist/transport/http-transport.js +52 -10
- package/dist/transport/index.d.ts +6 -3
- package/dist/transport/index.js +3 -0
- package/dist/transport/queue-partition.d.ts +91 -0
- package/dist/transport/queue-partition.js +143 -0
- package/dist/transport/queue.d.ts +99 -20
- package/dist/transport/queue.js +210 -69
- package/dist/transport/response-body.d.ts +25 -0
- package/dist/transport/response-body.js +64 -0
- package/dist/transport/send.d.ts +11 -0
- package/dist/transport/send.js +17 -0
- package/dist/transport/types/delivery-flow.types.d.ts +19 -0
- package/dist/transport/types/delivery-flow.types.js +1 -0
- package/dist/transport/types/transport.types.d.ts +45 -0
- package/dist/turns/claude-transcript.d.ts +19 -1
- package/dist/turns/claude-transcript.js +46 -1
- package/dist/turns/codex-originator.d.ts +11 -0
- package/dist/turns/codex-originator.js +31 -0
- package/dist/turns/codex-transcript.d.ts +30 -0
- package/dist/turns/codex-transcript.js +88 -0
- package/dist/turns/constants/turns.constants.d.ts +141 -5
- package/dist/turns/constants/turns.constants.js +155 -5
- package/dist/turns/file-identity.d.ts +27 -0
- package/dist/turns/file-identity.js +48 -0
- package/dist/turns/gemini-transcript.d.ts +30 -0
- package/dist/turns/gemini-transcript.js +96 -0
- package/dist/turns/index.d.ts +3 -3
- package/dist/turns/index.js +1 -1
- package/dist/turns/inherited-checkout.d.ts +54 -0
- package/dist/turns/inherited-checkout.js +155 -0
- package/dist/turns/native-session-titles.d.ts +26 -0
- package/dist/turns/native-session-titles.js +102 -0
- package/dist/turns/transcript.d.ts +3 -2
- package/dist/turns/transcript.js +5 -1
- package/dist/turns/turn-state.d.ts +224 -3
- package/dist/turns/turn-state.js +456 -21
- package/dist/turns/turn-summary.d.ts +1 -14
- package/dist/turns/turn-summary.js +87 -51
- package/dist/turns/turn-tracker.d.ts +21 -2
- package/dist/turns/turn-tracker.js +379 -56
- package/dist/turns/types/transcript.types.d.ts +5 -0
- package/dist/turns/types/turn-state.types.d.ts +116 -5
- package/dist/turns/types/turn-summary.types.d.ts +64 -14
- package/dist/turns/types/turn-tracker.types.d.ts +27 -1
- package/dist/turns/work-checkout.d.ts +67 -0
- package/dist/turns/work-checkout.js +700 -0
- package/dist/untraced/constants/untraced.constants.d.ts +31 -0
- package/dist/untraced/constants/untraced.constants.js +63 -0
- package/dist/untraced/untraced.d.ts +35 -0
- package/dist/untraced/untraced.js +105 -0
- package/dist/update/constants/update.constants.d.ts +18 -0
- package/dist/update/constants/update.constants.js +20 -0
- package/dist/update/update-check.d.ts +52 -0
- package/dist/update/update-check.js +113 -0
- package/docs/AUDIT_PROMPT.md +129 -0
- package/docs/DATA_HANDLING.md +655 -0
- package/docs/ENTERPRISE_DEPLOYMENT.md +194 -0
- package/docs/PERFORMANCE.md +81 -0
- package/package.json +14 -4
- package/dist/enrollment/enrollment-provider.d.ts +0 -5
- package/dist/enrollment/manual-enrollment.d.ts +0 -32
- package/dist/enrollment/manual-enrollment.js +0 -72
- package/example/README.md +0 -43
- package/example/server.mjs +0 -240
- /package/dist/{enrollment/enrollment-provider.js → config/types/destination.types.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReadTurnUsageRetry, TurnUsage } from './types/transcript.types.js';
|
|
1
|
+
import type { ReadTurnUsageRetry, SessionTitles, TurnUsage } from './types/transcript.types.js';
|
|
2
2
|
export type { ReadTurnUsageRetry, TranscriptUsageEntry, TurnUsage } from './types/transcript.types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Authoritative per-turn token usage from Claude Code's transcript JSONL.
|
|
@@ -16,3 +16,21 @@ export type { ReadTurnUsageRetry, TranscriptUsageEntry, TurnUsage } from './type
|
|
|
16
16
|
* @returns The turn's usage, or undefined when the transcript reports none.
|
|
17
17
|
*/
|
|
18
18
|
export declare function readTurnUsage(transcriptPath: string, sinceIso: string, retry?: ReadTurnUsageRetry, untilIso?: string, excludeMessageIds?: ReadonlySet<string>): Promise<TurnUsage | undefined>;
|
|
19
|
+
/**
|
|
20
|
+
* The session's titles, from the tail of Claude Code's transcript.
|
|
21
|
+
*
|
|
22
|
+
* Titles change mid-session and Claude Code appends each new one, so the last
|
|
23
|
+
* entry of each kind is the current one. One tail read, no settle loop: a title
|
|
24
|
+
* is not part of the turn's flush, and a late one is simply the next turn's.
|
|
25
|
+
*
|
|
26
|
+
* @param transcriptPath - Path Claude Code reported in the hook payload.
|
|
27
|
+
* @returns The titles found; empty when the tail holds none or cannot be read.
|
|
28
|
+
*/
|
|
29
|
+
export declare function readClaudeSessionTitles(transcriptPath: string): Promise<SessionTitles>;
|
|
30
|
+
/**
|
|
31
|
+
* The latest title of each kind in a run of transcript lines.
|
|
32
|
+
*
|
|
33
|
+
* @param raw - Transcript text.
|
|
34
|
+
* @returns The latest custom title and the latest generated one.
|
|
35
|
+
*/
|
|
36
|
+
export declare function sessionTitlesFrom(raw: string): SessionTitles;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { asRecord } from '../core/object.js';
|
|
1
|
+
import { asRecord, compact } from '../core/object.js';
|
|
2
|
+
import { CLAUDE_CUSTOM_TITLE_FIELDS, CLAUDE_GENERATED_TITLE_FIELDS, RE_CLAUDE_TITLE_LINE } from './constants/turns.constants.js';
|
|
2
3
|
import { accumulateUsage, messageIdFor, parseJsonLine, readTranscriptTail, readUntilSettled } from './transcript.js';
|
|
3
4
|
/**
|
|
4
5
|
* Authoritative per-turn token usage from Claude Code's transcript JSONL.
|
|
@@ -78,3 +79,47 @@ function assistantUsageEntry(line, since, until, excludeMessageIds) {
|
|
|
78
79
|
const model = typeof message?.['model'] === 'string' ? message['model'] : undefined;
|
|
79
80
|
return { id, value: { model, usage } };
|
|
80
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* The session's titles, from the tail of Claude Code's transcript.
|
|
84
|
+
*
|
|
85
|
+
* Titles change mid-session and Claude Code appends each new one, so the last
|
|
86
|
+
* entry of each kind is the current one. One tail read, no settle loop: a title
|
|
87
|
+
* is not part of the turn's flush, and a late one is simply the next turn's.
|
|
88
|
+
*
|
|
89
|
+
* @param transcriptPath - Path Claude Code reported in the hook payload.
|
|
90
|
+
* @returns The titles found; empty when the tail holds none or cannot be read.
|
|
91
|
+
*/
|
|
92
|
+
export async function readClaudeSessionTitles(transcriptPath) {
|
|
93
|
+
const raw = await readTranscriptTail(transcriptPath);
|
|
94
|
+
if (raw === undefined)
|
|
95
|
+
return {};
|
|
96
|
+
return sessionTitlesFrom(raw);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The latest title of each kind in a run of transcript lines.
|
|
100
|
+
*
|
|
101
|
+
* @param raw - Transcript text.
|
|
102
|
+
* @returns The latest custom title and the latest generated one.
|
|
103
|
+
*/
|
|
104
|
+
export function sessionTitlesFrom(raw) {
|
|
105
|
+
let custom;
|
|
106
|
+
let generated;
|
|
107
|
+
for (const line of raw.split('\n')) {
|
|
108
|
+
if (!RE_CLAUDE_TITLE_LINE.test(line))
|
|
109
|
+
continue;
|
|
110
|
+
const entry = parseJsonLine(line);
|
|
111
|
+
const type = typeof entry?.['type'] === 'string' ? entry['type'] : '';
|
|
112
|
+
const customField = CLAUDE_CUSTOM_TITLE_FIELDS[type];
|
|
113
|
+
const generatedField = CLAUDE_GENERATED_TITLE_FIELDS[type];
|
|
114
|
+
if (customField)
|
|
115
|
+
custom = titleText(entry?.[customField]) ?? custom;
|
|
116
|
+
if (generatedField)
|
|
117
|
+
generated = titleText(entry?.[generatedField]) ?? generated;
|
|
118
|
+
}
|
|
119
|
+
return compact({ custom, generated });
|
|
120
|
+
}
|
|
121
|
+
function titleText(value) {
|
|
122
|
+
if (typeof value !== 'string')
|
|
123
|
+
return undefined;
|
|
124
|
+
return value.trim() || undefined;
|
|
125
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a Codex transcript belongs to a headless `codex exec` run.
|
|
3
|
+
*
|
|
4
|
+
* The hook payload does not say how Codex was started; the transcript's first
|
|
5
|
+
* line (`session_meta`) does. Any failure answers false, so an unreadable
|
|
6
|
+
* transcript reports the default surface rather than failing the hook.
|
|
7
|
+
*
|
|
8
|
+
* @param transcriptPath - Path Codex reported in the hook payload.
|
|
9
|
+
* @returns True only when the originator is `codex_exec`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isCodexExecTranscript(transcriptPath: string): Promise<boolean>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { asRecord } from '../core/object.js';
|
|
3
|
+
import { CODEX_EXEC_ORIGINATOR, CODEX_META_HEAD_BYTES } from './constants/turns.constants.js';
|
|
4
|
+
/**
|
|
5
|
+
* Whether a Codex transcript belongs to a headless `codex exec` run.
|
|
6
|
+
*
|
|
7
|
+
* The hook payload does not say how Codex was started; the transcript's first
|
|
8
|
+
* line (`session_meta`) does. Any failure answers false, so an unreadable
|
|
9
|
+
* transcript reports the default surface rather than failing the hook.
|
|
10
|
+
*
|
|
11
|
+
* @param transcriptPath - Path Codex reported in the hook payload.
|
|
12
|
+
* @returns True only when the originator is `codex_exec`.
|
|
13
|
+
*/
|
|
14
|
+
export async function isCodexExecTranscript(transcriptPath) {
|
|
15
|
+
try {
|
|
16
|
+
const handle = await fs.open(transcriptPath, 'r');
|
|
17
|
+
try {
|
|
18
|
+
const buffer = Buffer.alloc(CODEX_META_HEAD_BYTES);
|
|
19
|
+
const { bytesRead } = await handle.read(buffer, 0, CODEX_META_HEAD_BYTES, 0);
|
|
20
|
+
const head = buffer.toString('utf8', 0, bytesRead);
|
|
21
|
+
const meta = asRecord(JSON.parse(head.split('\n', 1)[0] ?? ''));
|
|
22
|
+
return asRecord(meta?.['payload'])?.['originator'] === CODEX_EXEC_ORIGINATOR;
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
await handle.close();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ReadTurnUsageRetry, TurnUsage } from './types/transcript.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Per-turn token usage from a Codex rollout (`~/.codex/sessions/…/rollout-*.jsonl`).
|
|
4
|
+
*
|
|
5
|
+
* Codex writes one `event_msg` / `token_count` row per model request, whose
|
|
6
|
+
* `info.last_token_usage` is that request's counts (verified on codex-cli
|
|
7
|
+
* 0.150.0: across 294 rows, every `last_token_usage` equals the step in
|
|
8
|
+
* `total_token_usage`). Only those numbers and the model named by the latest
|
|
9
|
+
* `turn_context` row are read; message, reasoning and tool rows are skipped
|
|
10
|
+
* unparsed, so nothing a developer wrote leaves this function.
|
|
11
|
+
*
|
|
12
|
+
* This is how Codex usage reaches the platform on a metadata-only install,
|
|
13
|
+
* where its native OTel stays off because those logs carry tool content.
|
|
14
|
+
*
|
|
15
|
+
* ponytail: reads the same 4 MiB tail as the Claude reader. A single turn whose
|
|
16
|
+
* tool output pushes its own early rows past that undercounts, and loses the
|
|
17
|
+
* rollout's model name (the Stop payload's `model` then names it). Upgrade
|
|
18
|
+
* path: remember the byte offset each Stop read to and read from there.
|
|
19
|
+
*
|
|
20
|
+
* Counts keep OpenAI's meaning: `inputTokens` includes the cached part, which
|
|
21
|
+
* `cachedInputTokens` repeats. The backend prices Codex that way.
|
|
22
|
+
*
|
|
23
|
+
* @param transcriptPath - Path Codex reported in the hook payload.
|
|
24
|
+
* @param sinceIso - When the turn started; earlier rows are another turn's.
|
|
25
|
+
* @param retry - How long to wait for the rollout flush to settle.
|
|
26
|
+
* @param untilIso - Upper bound, keeping a racing next prompt's rows out.
|
|
27
|
+
* @param excludeMessageIds - Rows another turn already claimed.
|
|
28
|
+
* @returns The turn's usage, or undefined when the rollout reports none.
|
|
29
|
+
*/
|
|
30
|
+
export declare function readCodexTurnUsage(transcriptPath: string, sinceIso: string, retry?: ReadTurnUsageRetry, untilIso?: string, excludeMessageIds?: ReadonlySet<string>): Promise<TurnUsage | undefined>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { asRecord, firstStringOf } from '../core/object.js';
|
|
2
|
+
import { accumulateUsage, messageIdFor, parseJsonLine, readTranscriptTail, readUntilSettled } from './transcript.js';
|
|
3
|
+
import { CODEX_CACHED_INPUT_TOKENS, CODEX_LAST_TOKEN_USAGE, CODEX_TOKEN_COUNT, CODEX_TURN_CONTEXT, TRANSCRIPT_CACHE_READ_TOKENS, TRANSCRIPT_INPUT_TOKENS, TRANSCRIPT_OUTPUT_TOKENS } from './constants/turns.constants.js';
|
|
4
|
+
/**
|
|
5
|
+
* Per-turn token usage from a Codex rollout (`~/.codex/sessions/…/rollout-*.jsonl`).
|
|
6
|
+
*
|
|
7
|
+
* Codex writes one `event_msg` / `token_count` row per model request, whose
|
|
8
|
+
* `info.last_token_usage` is that request's counts (verified on codex-cli
|
|
9
|
+
* 0.150.0: across 294 rows, every `last_token_usage` equals the step in
|
|
10
|
+
* `total_token_usage`). Only those numbers and the model named by the latest
|
|
11
|
+
* `turn_context` row are read; message, reasoning and tool rows are skipped
|
|
12
|
+
* unparsed, so nothing a developer wrote leaves this function.
|
|
13
|
+
*
|
|
14
|
+
* This is how Codex usage reaches the platform on a metadata-only install,
|
|
15
|
+
* where its native OTel stays off because those logs carry tool content.
|
|
16
|
+
*
|
|
17
|
+
* ponytail: reads the same 4 MiB tail as the Claude reader. A single turn whose
|
|
18
|
+
* tool output pushes its own early rows past that undercounts, and loses the
|
|
19
|
+
* rollout's model name (the Stop payload's `model` then names it). Upgrade
|
|
20
|
+
* path: remember the byte offset each Stop read to and read from there.
|
|
21
|
+
*
|
|
22
|
+
* Counts keep OpenAI's meaning: `inputTokens` includes the cached part, which
|
|
23
|
+
* `cachedInputTokens` repeats. The backend prices Codex that way.
|
|
24
|
+
*
|
|
25
|
+
* @param transcriptPath - Path Codex reported in the hook payload.
|
|
26
|
+
* @param sinceIso - When the turn started; earlier rows are another turn's.
|
|
27
|
+
* @param retry - How long to wait for the rollout flush to settle.
|
|
28
|
+
* @param untilIso - Upper bound, keeping a racing next prompt's rows out.
|
|
29
|
+
* @param excludeMessageIds - Rows another turn already claimed.
|
|
30
|
+
* @returns The turn's usage, or undefined when the rollout reports none.
|
|
31
|
+
*/
|
|
32
|
+
export async function readCodexTurnUsage(transcriptPath, sinceIso, retry, untilIso, excludeMessageIds) {
|
|
33
|
+
return readUntilSettled(() => readOnce(transcriptPath, sinceIso, untilIso, excludeMessageIds), retry);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* One pass over the rollout tail.
|
|
37
|
+
*
|
|
38
|
+
* @param transcriptPath - Rollout file.
|
|
39
|
+
* @param sinceIso - Lower bound of the turn's window.
|
|
40
|
+
* @param untilIso - Upper bound, or undefined for "no upper bound".
|
|
41
|
+
* @param excludeMessageIds - Rows another turn already claimed.
|
|
42
|
+
* @returns The usage found in this pass.
|
|
43
|
+
*/
|
|
44
|
+
async function readOnce(transcriptPath, sinceIso, untilIso, excludeMessageIds) {
|
|
45
|
+
const since = Date.parse(sinceIso);
|
|
46
|
+
const until = untilIso === undefined ? Number.POSITIVE_INFINITY : Date.parse(untilIso);
|
|
47
|
+
if (Number.isNaN(since) || Number.isNaN(until))
|
|
48
|
+
return undefined;
|
|
49
|
+
const raw = await readTranscriptTail(transcriptPath);
|
|
50
|
+
if (raw === undefined)
|
|
51
|
+
return undefined;
|
|
52
|
+
const byRowId = new Map();
|
|
53
|
+
let model;
|
|
54
|
+
for (const line of raw.split('\n')) {
|
|
55
|
+
// Cheap prefilter: content rows are most of the file and never matter here.
|
|
56
|
+
if (!line.includes(CODEX_TOKEN_COUNT) && !line.includes(CODEX_TURN_CONTEXT))
|
|
57
|
+
continue;
|
|
58
|
+
const row = parseJsonLine(line);
|
|
59
|
+
const payload = asRecord(row?.['payload']);
|
|
60
|
+
if (!row || !payload)
|
|
61
|
+
continue;
|
|
62
|
+
if (row['type'] === CODEX_TURN_CONTEXT) {
|
|
63
|
+
model = firstStringOf(payload['model']) ?? model;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (payload['type'] !== CODEX_TOKEN_COUNT)
|
|
67
|
+
continue;
|
|
68
|
+
const last = asRecord(asRecord(payload['info'])?.[CODEX_LAST_TOKEN_USAGE]);
|
|
69
|
+
const timestamp = typeof row['timestamp'] === 'string' ? Date.parse(row['timestamp']) : NaN;
|
|
70
|
+
if (!last || Number.isNaN(timestamp) || timestamp < since || timestamp > until)
|
|
71
|
+
continue;
|
|
72
|
+
// No row id in the format; the line hash carries the row's millisecond
|
|
73
|
+
// timestamp (and `ordinal`, which 0.150 writes), so it is unique per request
|
|
74
|
+
// and stable across re-reads.
|
|
75
|
+
const id = messageIdFor(undefined, line);
|
|
76
|
+
if (excludeMessageIds?.has(id))
|
|
77
|
+
continue;
|
|
78
|
+
byRowId.set(id, {
|
|
79
|
+
model,
|
|
80
|
+
usage: {
|
|
81
|
+
[TRANSCRIPT_INPUT_TOKENS]: last[TRANSCRIPT_INPUT_TOKENS],
|
|
82
|
+
[TRANSCRIPT_OUTPUT_TOKENS]: last[TRANSCRIPT_OUTPUT_TOKENS],
|
|
83
|
+
[TRANSCRIPT_CACHE_READ_TOKENS]: last[CODEX_CACHED_INPUT_TOKENS]
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return accumulateUsage(byRowId);
|
|
88
|
+
}
|
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
import type { ReadTurnUsageRetry } from '../types/transcript.types.js';
|
|
2
2
|
/** Canonical event types that mean "a tool finished doing something". */
|
|
3
3
|
export declare const TOOL_COMPLETION_TYPES: ReadonlySet<string>;
|
|
4
|
+
/** Canonical event types that mean "a tool is about to run": where a turn names its checkouts. */
|
|
5
|
+
export declare const TOOL_START_TYPES: ReadonlySet<string>;
|
|
6
|
+
/**
|
|
7
|
+
* Completions whose shell command is read again for a checkout it created. A
|
|
8
|
+
* failed call is `tool.failed` whatever the tool; the provider's `shellCall`
|
|
9
|
+
* answers only for a shell.
|
|
10
|
+
*/
|
|
11
|
+
export declare const SHELL_REREAD_TYPES: ReadonlySet<string>;
|
|
4
12
|
/** Orphaned turn state (a crash without Stop/SessionEnd) is deleted after this. */
|
|
5
13
|
export declare const TURN_STATE_TTL_MS: number;
|
|
14
|
+
/**
|
|
15
|
+
* How often the expiry sweep may actually walk the state root.
|
|
16
|
+
*
|
|
17
|
+
* It used to run after every closing turn and every session end — a `readdir`
|
|
18
|
+
* plus a `stat` per file of every recent session, on the hook path, almost
|
|
19
|
+
* always to find that nothing was 24 h old yet. Hourly keeps removal well
|
|
20
|
+
* inside the TTL's own tolerance and costs one `stat` on the common path.
|
|
21
|
+
*/
|
|
22
|
+
export declare const TURN_STATE_SWEEP_INTERVAL_MS: number;
|
|
6
23
|
/** Overlapping Stop hooks serialize only transcript usage allocation. */
|
|
7
24
|
export declare const USAGE_LOCK_WAIT_MS = 5000;
|
|
8
25
|
export declare const USAGE_LOCK_POLL_MS = 25;
|
|
@@ -22,16 +39,85 @@ export declare const TRANSCRIPT_TAIL_BYTES: number;
|
|
|
22
39
|
export declare const TRANSCRIPT_PATH_KEY = "transcript_path";
|
|
23
40
|
/** Prefix distinguishing usage-claim files from turn records in a session dir. */
|
|
24
41
|
export declare const USAGE_CLAIM_PREFIX = "usage-claim--";
|
|
42
|
+
/**
|
|
43
|
+
* The one file in a session dir that is not a turn record: what model the
|
|
44
|
+
* session is on, so a later hook's gate can state it.
|
|
45
|
+
*/
|
|
46
|
+
export declare const SESSION_MODEL_FILE = "session.json";
|
|
47
|
+
/** The folder the session started in, written once by its first hook: `{ cwd }`. */
|
|
48
|
+
export declare const SESSION_START_FILE = "session-start.json";
|
|
49
|
+
/**
|
|
50
|
+
* The checkout the session's last changing turn worked in: `{ root, repository, at }`.
|
|
51
|
+
* Carried by a turn that changes nothing, and read by the prompt gate (AWT-128).
|
|
52
|
+
*/
|
|
53
|
+
export declare const WORK_CHECKOUT_FILE = "work-checkout.json";
|
|
54
|
+
/**
|
|
55
|
+
* The agent process this session runs in: `{ pid, started }`. Written by the
|
|
56
|
+
* first hook, so a session started later can recognise it among its ancestors.
|
|
57
|
+
*/
|
|
58
|
+
export declare const AGENT_PROCESS_FILE = "agent-process.json";
|
|
59
|
+
/**
|
|
60
|
+
* What the session inherited from the process that started it (AWT-228):
|
|
61
|
+
* `{ parent?, root? }`. Written once, by the first hook of a session whose
|
|
62
|
+
* folder is no checkout, so that no later hook walks the process tree again.
|
|
63
|
+
*/
|
|
64
|
+
export declare const INHERITED_CHECKOUT_FILE = "inherited-checkout.json";
|
|
65
|
+
/**
|
|
66
|
+
* The ticket keys the session's opening prompt named: `{ keys }` (AWT-326).
|
|
67
|
+
* Written once, by the first prompt, even when it names none, so that a later
|
|
68
|
+
* prompt can never move the session. Local only; the keys ride the summary.
|
|
69
|
+
*/
|
|
70
|
+
export declare const PROMPT_TICKETS_FILE = "prompt-tickets.json";
|
|
71
|
+
/**
|
|
72
|
+
* Files that say nothing about whether a session is still running. The prompt
|
|
73
|
+
* memo outlives SessionEnd on purpose, so it must not keep the session live.
|
|
74
|
+
*/
|
|
75
|
+
export declare const LIVENESS_IGNORED_FILES: ReadonlySet<string>;
|
|
76
|
+
/** Directory of the state root indexing live agent pids to their session: `<pid>.json`. Not a session. */
|
|
77
|
+
export declare const AGENT_PIDS_DIR = "agent-pids";
|
|
78
|
+
/** Prefix of the once-per-session notice marker a checkout takes: `untraced-<root hash>.json`. Not a turn record. */
|
|
79
|
+
export declare const UNTRACED_MARKER_PREFIX = "untraced-";
|
|
80
|
+
/**
|
|
81
|
+
* The session's last known titles: `{ custom?, generated? }`, each kept on its
|
|
82
|
+
* own. A turn whose transcript tail no longer reaches a title entry still sends
|
|
83
|
+
* the ones seen before.
|
|
84
|
+
*/
|
|
85
|
+
export declare const SESSION_TITLE_FILE = "session-title.json";
|
|
86
|
+
/**
|
|
87
|
+
* Marker that the session's billing fact (`session.billing`) was handed to
|
|
88
|
+
* delivery, written once (AWT-476). Created only after a mode was classified, so
|
|
89
|
+
* a session that could not tell yet asks again on its next prompt.
|
|
90
|
+
*/
|
|
91
|
+
export declare const BILLING_SENT_FILE = "billing-sent.json";
|
|
92
|
+
/** Session-wide files beside the records; none of them is a turn record. */
|
|
93
|
+
export declare const SESSION_FILES: ReadonlySet<string>;
|
|
94
|
+
/** Prefix of a checkout record's filename: `checkout--<turn>-<root>-<call>.json`. */
|
|
95
|
+
export declare const CHECKOUT_RECORD_PREFIX = "checkout--";
|
|
96
|
+
/** Hash length of each part of a checkout record's filename. */
|
|
97
|
+
export declare const CHECKOUT_KEY_HASH_LENGTH = 16;
|
|
98
|
+
/** Checkouts one turn may name; past it, new ones are ignored (seven days of real turns peak at five). */
|
|
99
|
+
export declare const MAX_TURN_CHECKOUTS = 8;
|
|
25
100
|
/** Public provider labels; the internal id is an implementation detail. */
|
|
26
101
|
export declare const PROVIDER_LABELS: Readonly<Record<string, string>>;
|
|
27
102
|
/** Providers whose sessions run inside an editor rather than a terminal. */
|
|
28
103
|
export declare const IDE_SURFACE_PROVIDERS: ReadonlySet<string>;
|
|
104
|
+
/**
|
|
105
|
+
* The session id of the agent session that launched this one, set by the
|
|
106
|
+
* launcher (a spinoff in a new terminal tab, a review bot). Hooks inherit the
|
|
107
|
+
* agent's environment, so every hook of the child can read it (AWT-319).
|
|
108
|
+
*/
|
|
109
|
+
export declare const PARENT_SESSION_VAR = "AGENTWATCH_PARENT_SESSION";
|
|
110
|
+
/** What a declared parent session id may look like: a provider session id, never free text. */
|
|
111
|
+
export declare const RE_PARENT_SESSION_ID: RegExp;
|
|
29
112
|
/** Claude Code reports its own surface here. */
|
|
30
113
|
export declare const CLAUDE_ENTRYPOINT_VAR = "CLAUDE_CODE_ENTRYPOINT";
|
|
31
114
|
export declare const DEFAULT_SURFACE = "cli";
|
|
115
|
+
export declare const EXEC_SURFACE = "exec";
|
|
116
|
+
/** `session_meta.originator` Codex writes for a headless `codex exec` run. */
|
|
117
|
+
export declare const CODEX_EXEC_ORIGINATOR = "codex_exec";
|
|
118
|
+
/** How much of a Codex transcript to read for its `session_meta` line (about 20 KB in practice). */
|
|
119
|
+
export declare const CODEX_META_HEAD_BYTES: number;
|
|
32
120
|
export declare const IDE_SURFACE = "ide";
|
|
33
|
-
/** Separator between several prompts collapsed into one turn. */
|
|
34
|
-
export declare const PROMPT_JOIN_SEPARATOR = "\n---\n";
|
|
35
121
|
/**
|
|
36
122
|
* Cap on `files_touched` and `files_read`, matching the platform's own limit on
|
|
37
123
|
* either list.
|
|
@@ -44,14 +130,43 @@ export declare const PROMPT_JOIN_SEPARATOR = "\n---\n";
|
|
|
44
130
|
* truncated instead; that is a truncated list, not a lost turn.
|
|
45
131
|
*/
|
|
46
132
|
export declare const MAX_TURN_FILES = 500;
|
|
133
|
+
/**
|
|
134
|
+
* Bounds on the content a summary carries under the content flags. Applied after
|
|
135
|
+
* the text was scrubbed whole, never before: a cut through a credential leaves
|
|
136
|
+
* a prefix no pattern matches.
|
|
137
|
+
*
|
|
138
|
+
* ponytail: fixed character cuts, sized so a request plus a pasted link or a
|
|
139
|
+
* sheet id fits. A turn of 200 shell calls sends its first 50; per-tenant
|
|
140
|
+
* bounds would come from the backend.
|
|
141
|
+
*/
|
|
142
|
+
export declare const MAX_PROMPT_TEXT_LENGTH = 4000;
|
|
143
|
+
export declare const MAX_TOOL_INPUT_LENGTH = 2000;
|
|
144
|
+
export declare const MAX_TURN_TOOL_INPUTS = 50;
|
|
145
|
+
/**
|
|
146
|
+
* The longest session title sent, in UTF-16 units — what core cuts at — and
|
|
147
|
+
* never through a code point. Scrubbed whole first, like prompt text.
|
|
148
|
+
*/
|
|
149
|
+
export declare const MAX_SESSION_TITLE_LENGTH = 200;
|
|
150
|
+
/**
|
|
151
|
+
* Claude Code's title entries, by type, and the field holding the text: the
|
|
152
|
+
* session name (`--name`, `/rename`, a hook) is sent as `session_name`, the one
|
|
153
|
+
* Claude Code generates as `session_title`. Not
|
|
154
|
+
* `summary`: that type also holds compaction summaries and, in older releases,
|
|
155
|
+
* another conversation's title by `leafUuid`, so its text is not this session's name.
|
|
156
|
+
*/
|
|
157
|
+
export declare const CLAUDE_CUSTOM_TITLE_FIELDS: Readonly<Record<string, string>>;
|
|
158
|
+
export declare const CLAUDE_GENERATED_TITLE_FIELDS: Readonly<Record<string, string>>;
|
|
159
|
+
/** A transcript line that may be a title entry; the rest of the tail is never parsed for one. */
|
|
160
|
+
export declare const RE_CLAUDE_TITLE_LINE: RegExp;
|
|
47
161
|
/** Fallback tool name for a call the provider did not name. */
|
|
48
162
|
export declare const UNKNOWN_TOOL_NAME = "unknown";
|
|
49
|
-
/** Metadata keys the tracker reads off canonical events. */
|
|
50
|
-
export declare const PROMPT_TEXT_KEY = "promptText";
|
|
163
|
+
/** Metadata keys the tracker reads off canonical events. Evidence only: no text key exists. */
|
|
51
164
|
export declare const PROMPT_EVIDENCE_KEY = "prompt";
|
|
52
|
-
export declare const RESPONSE_TEXT_KEY = "responseText";
|
|
53
165
|
export declare const RESPONSE_EVIDENCE_KEY = "response";
|
|
54
166
|
export declare const FILE_PATH_KEY = "filePath";
|
|
167
|
+
export declare const EXTERNAL_PATH_KEY = "externalPath";
|
|
168
|
+
export declare const PROMPT_TEXT_KEY = "promptText";
|
|
169
|
+
export declare const PROMPT_JIRA_IDS_KEY = "promptJiraIds";
|
|
55
170
|
/** Length of the hashed session directory name. */
|
|
56
171
|
export declare const SESSION_DIR_HASH_LENGTH = 32;
|
|
57
172
|
/** Length of the hashed lock names, which must be filesystem-safe. */
|
|
@@ -63,7 +178,28 @@ export declare const TRANSCRIPT_INPUT_TOKENS = "input_tokens";
|
|
|
63
178
|
export declare const TRANSCRIPT_OUTPUT_TOKENS = "output_tokens";
|
|
64
179
|
export declare const TRANSCRIPT_CACHE_READ_TOKENS = "cache_read_input_tokens";
|
|
65
180
|
export declare const TRANSCRIPT_CACHE_CREATION_TOKENS = "cache_creation_input_tokens";
|
|
181
|
+
/** Codex rollout rows the usage reader needs; every other row is skipped unparsed. */
|
|
182
|
+
export declare const CODEX_TOKEN_COUNT = "token_count";
|
|
183
|
+
export declare const CODEX_TURN_CONTEXT = "turn_context";
|
|
184
|
+
export declare const CODEX_LAST_TOKEN_USAGE = "last_token_usage";
|
|
185
|
+
export declare const CODEX_CACHED_INPUT_TOKENS = "cached_input_tokens";
|
|
186
|
+
/** Gemini CLI chat-file row type that carries a model reply, and its usage block. */
|
|
187
|
+
export declare const GEMINI_REPLY_TYPE = "gemini";
|
|
188
|
+
export declare const GEMINI_TOKENS = "tokens";
|
|
66
189
|
/** Every transcript token field, for weighting which model dominated a turn. */
|
|
67
190
|
export declare const TRANSCRIPT_TOKEN_FIELDS: readonly ["input_tokens", "output_tokens", "cache_read_input_tokens", "cache_creation_input_tokens"];
|
|
68
191
|
/** Prefix for the content-hash id given to a transcript entry without one. */
|
|
69
192
|
export declare const ANONYMOUS_MESSAGE_ID_PREFIX = "anon-";
|
|
193
|
+
/**
|
|
194
|
+
* Counts the commits between two oids that no remote-tracking ref reaches: the
|
|
195
|
+
* turn's own, as opposed to a pull, a reset or another branch's tip (SPEC §3a).
|
|
196
|
+
*
|
|
197
|
+
* @param from - The oid the turn started on.
|
|
198
|
+
* @param to - The oid or ref it ended on.
|
|
199
|
+
* @param since - Only commits made since then (ISO time): after a switch, the
|
|
200
|
+
* new branch's older commits are not the turn's.
|
|
201
|
+
* @returns The argument vector.
|
|
202
|
+
*/
|
|
203
|
+
export declare function gitOwnCommitCountArgs(from: string | undefined, to: string, since?: string): readonly string[];
|
|
204
|
+
/** Commit times are whole seconds; a commit in the second the turn first named its checkout is still the turn's. */
|
|
205
|
+
export declare const OWN_COMMIT_SINCE_SLACK_MS = 2000;
|
|
@@ -7,8 +7,25 @@ export const TOOL_COMPLETION_TYPES = new Set([
|
|
|
7
7
|
'file.read',
|
|
8
8
|
'file.edited'
|
|
9
9
|
]);
|
|
10
|
+
/** Canonical event types that mean "a tool is about to run": where a turn names its checkouts. */
|
|
11
|
+
export const TOOL_START_TYPES = new Set(['tool.started', 'shell.started', 'mcp.started']);
|
|
12
|
+
/**
|
|
13
|
+
* Completions whose shell command is read again for a checkout it created. A
|
|
14
|
+
* failed call is `tool.failed` whatever the tool; the provider's `shellCall`
|
|
15
|
+
* answers only for a shell.
|
|
16
|
+
*/
|
|
17
|
+
export const SHELL_REREAD_TYPES = new Set(['shell.completed', 'tool.failed']);
|
|
10
18
|
/** Orphaned turn state (a crash without Stop/SessionEnd) is deleted after this. */
|
|
11
19
|
export const TURN_STATE_TTL_MS = 24 * 60 * 60 * 1000;
|
|
20
|
+
/**
|
|
21
|
+
* How often the expiry sweep may actually walk the state root.
|
|
22
|
+
*
|
|
23
|
+
* It used to run after every closing turn and every session end — a `readdir`
|
|
24
|
+
* plus a `stat` per file of every recent session, on the hook path, almost
|
|
25
|
+
* always to find that nothing was 24 h old yet. Hourly keeps removal well
|
|
26
|
+
* inside the TTL's own tolerance and costs one `stat` on the common path.
|
|
27
|
+
*/
|
|
28
|
+
export const TURN_STATE_SWEEP_INTERVAL_MS = 60 * 60 * 1000;
|
|
12
29
|
/** Overlapping Stop hooks serialize only transcript usage allocation. */
|
|
13
30
|
export const USAGE_LOCK_WAIT_MS = 5_000;
|
|
14
31
|
export const USAGE_LOCK_POLL_MS = 25;
|
|
@@ -28,6 +45,73 @@ export const TRANSCRIPT_TAIL_BYTES = 4 * 1024 * 1024;
|
|
|
28
45
|
export const TRANSCRIPT_PATH_KEY = 'transcript_path';
|
|
29
46
|
/** Prefix distinguishing usage-claim files from turn records in a session dir. */
|
|
30
47
|
export const USAGE_CLAIM_PREFIX = 'usage-claim--';
|
|
48
|
+
/**
|
|
49
|
+
* The one file in a session dir that is not a turn record: what model the
|
|
50
|
+
* session is on, so a later hook's gate can state it.
|
|
51
|
+
*/
|
|
52
|
+
export const SESSION_MODEL_FILE = 'session.json';
|
|
53
|
+
/** The folder the session started in, written once by its first hook: `{ cwd }`. */
|
|
54
|
+
export const SESSION_START_FILE = 'session-start.json';
|
|
55
|
+
/**
|
|
56
|
+
* The checkout the session's last changing turn worked in: `{ root, repository, at }`.
|
|
57
|
+
* Carried by a turn that changes nothing, and read by the prompt gate (AWT-128).
|
|
58
|
+
*/
|
|
59
|
+
export const WORK_CHECKOUT_FILE = 'work-checkout.json';
|
|
60
|
+
/**
|
|
61
|
+
* The agent process this session runs in: `{ pid, started }`. Written by the
|
|
62
|
+
* first hook, so a session started later can recognise it among its ancestors.
|
|
63
|
+
*/
|
|
64
|
+
export const AGENT_PROCESS_FILE = 'agent-process.json';
|
|
65
|
+
/**
|
|
66
|
+
* What the session inherited from the process that started it (AWT-228):
|
|
67
|
+
* `{ parent?, root? }`. Written once, by the first hook of a session whose
|
|
68
|
+
* folder is no checkout, so that no later hook walks the process tree again.
|
|
69
|
+
*/
|
|
70
|
+
export const INHERITED_CHECKOUT_FILE = 'inherited-checkout.json';
|
|
71
|
+
/**
|
|
72
|
+
* The ticket keys the session's opening prompt named: `{ keys }` (AWT-326).
|
|
73
|
+
* Written once, by the first prompt, even when it names none, so that a later
|
|
74
|
+
* prompt can never move the session. Local only; the keys ride the summary.
|
|
75
|
+
*/
|
|
76
|
+
export const PROMPT_TICKETS_FILE = 'prompt-tickets.json';
|
|
77
|
+
/**
|
|
78
|
+
* Files that say nothing about whether a session is still running. The prompt
|
|
79
|
+
* memo outlives SessionEnd on purpose, so it must not keep the session live.
|
|
80
|
+
*/
|
|
81
|
+
export const LIVENESS_IGNORED_FILES = new Set([PROMPT_TICKETS_FILE]);
|
|
82
|
+
/** Directory of the state root indexing live agent pids to their session: `<pid>.json`. Not a session. */
|
|
83
|
+
export const AGENT_PIDS_DIR = 'agent-pids';
|
|
84
|
+
/** Prefix of the once-per-session notice marker a checkout takes: `untraced-<root hash>.json`. Not a turn record. */
|
|
85
|
+
export const UNTRACED_MARKER_PREFIX = 'untraced-';
|
|
86
|
+
/**
|
|
87
|
+
* The session's last known titles: `{ custom?, generated? }`, each kept on its
|
|
88
|
+
* own. A turn whose transcript tail no longer reaches a title entry still sends
|
|
89
|
+
* the ones seen before.
|
|
90
|
+
*/
|
|
91
|
+
export const SESSION_TITLE_FILE = 'session-title.json';
|
|
92
|
+
/**
|
|
93
|
+
* Marker that the session's billing fact (`session.billing`) was handed to
|
|
94
|
+
* delivery, written once (AWT-476). Created only after a mode was classified, so
|
|
95
|
+
* a session that could not tell yet asks again on its next prompt.
|
|
96
|
+
*/
|
|
97
|
+
export const BILLING_SENT_FILE = 'billing-sent.json';
|
|
98
|
+
/** Session-wide files beside the records; none of them is a turn record. */
|
|
99
|
+
export const SESSION_FILES = new Set([
|
|
100
|
+
BILLING_SENT_FILE,
|
|
101
|
+
SESSION_MODEL_FILE,
|
|
102
|
+
SESSION_TITLE_FILE,
|
|
103
|
+
SESSION_START_FILE,
|
|
104
|
+
WORK_CHECKOUT_FILE,
|
|
105
|
+
AGENT_PROCESS_FILE,
|
|
106
|
+
INHERITED_CHECKOUT_FILE,
|
|
107
|
+
PROMPT_TICKETS_FILE
|
|
108
|
+
]);
|
|
109
|
+
/** Prefix of a checkout record's filename: `checkout--<turn>-<root>-<call>.json`. */
|
|
110
|
+
export const CHECKOUT_RECORD_PREFIX = 'checkout--';
|
|
111
|
+
/** Hash length of each part of a checkout record's filename. */
|
|
112
|
+
export const CHECKOUT_KEY_HASH_LENGTH = 16;
|
|
113
|
+
/** Checkouts one turn may name; past it, new ones are ignored (seven days of real turns peak at five). */
|
|
114
|
+
export const MAX_TURN_CHECKOUTS = 8;
|
|
31
115
|
/** Public provider labels; the internal id is an implementation detail. */
|
|
32
116
|
export const PROVIDER_LABELS = {
|
|
33
117
|
claude: 'claude-code',
|
|
@@ -38,12 +122,23 @@ export const PROVIDER_LABELS = {
|
|
|
38
122
|
};
|
|
39
123
|
/** Providers whose sessions run inside an editor rather than a terminal. */
|
|
40
124
|
export const IDE_SURFACE_PROVIDERS = new Set(['cursor', 'antigravity']);
|
|
125
|
+
/**
|
|
126
|
+
* The session id of the agent session that launched this one, set by the
|
|
127
|
+
* launcher (a spinoff in a new terminal tab, a review bot). Hooks inherit the
|
|
128
|
+
* agent's environment, so every hook of the child can read it (AWT-319).
|
|
129
|
+
*/
|
|
130
|
+
export const PARENT_SESSION_VAR = 'AGENTWATCH_PARENT_SESSION';
|
|
131
|
+
/** What a declared parent session id may look like: a provider session id, never free text. */
|
|
132
|
+
export const RE_PARENT_SESSION_ID = /^[\w.:-]{1,200}$/;
|
|
41
133
|
/** Claude Code reports its own surface here. */
|
|
42
134
|
export const CLAUDE_ENTRYPOINT_VAR = 'CLAUDE_CODE_ENTRYPOINT';
|
|
43
135
|
export const DEFAULT_SURFACE = 'cli';
|
|
136
|
+
export const EXEC_SURFACE = 'exec';
|
|
137
|
+
/** `session_meta.originator` Codex writes for a headless `codex exec` run. */
|
|
138
|
+
export const CODEX_EXEC_ORIGINATOR = 'codex_exec';
|
|
139
|
+
/** How much of a Codex transcript to read for its `session_meta` line (about 20 KB in practice). */
|
|
140
|
+
export const CODEX_META_HEAD_BYTES = 256 * 1024;
|
|
44
141
|
export const IDE_SURFACE = 'ide';
|
|
45
|
-
/** Separator between several prompts collapsed into one turn. */
|
|
46
|
-
export const PROMPT_JOIN_SEPARATOR = '\n---\n';
|
|
47
142
|
/**
|
|
48
143
|
* Cap on `files_touched` and `files_read`, matching the platform's own limit on
|
|
49
144
|
* either list.
|
|
@@ -56,14 +151,43 @@ export const PROMPT_JOIN_SEPARATOR = '\n---\n';
|
|
|
56
151
|
* truncated instead; that is a truncated list, not a lost turn.
|
|
57
152
|
*/
|
|
58
153
|
export const MAX_TURN_FILES = 500;
|
|
154
|
+
/**
|
|
155
|
+
* Bounds on the content a summary carries under the content flags. Applied after
|
|
156
|
+
* the text was scrubbed whole, never before: a cut through a credential leaves
|
|
157
|
+
* a prefix no pattern matches.
|
|
158
|
+
*
|
|
159
|
+
* ponytail: fixed character cuts, sized so a request plus a pasted link or a
|
|
160
|
+
* sheet id fits. A turn of 200 shell calls sends its first 50; per-tenant
|
|
161
|
+
* bounds would come from the backend.
|
|
162
|
+
*/
|
|
163
|
+
export const MAX_PROMPT_TEXT_LENGTH = 4000;
|
|
164
|
+
export const MAX_TOOL_INPUT_LENGTH = 2000;
|
|
165
|
+
export const MAX_TURN_TOOL_INPUTS = 50;
|
|
166
|
+
/**
|
|
167
|
+
* The longest session title sent, in UTF-16 units — what core cuts at — and
|
|
168
|
+
* never through a code point. Scrubbed whole first, like prompt text.
|
|
169
|
+
*/
|
|
170
|
+
export const MAX_SESSION_TITLE_LENGTH = 200;
|
|
171
|
+
/**
|
|
172
|
+
* Claude Code's title entries, by type, and the field holding the text: the
|
|
173
|
+
* session name (`--name`, `/rename`, a hook) is sent as `session_name`, the one
|
|
174
|
+
* Claude Code generates as `session_title`. Not
|
|
175
|
+
* `summary`: that type also holds compaction summaries and, in older releases,
|
|
176
|
+
* another conversation's title by `leafUuid`, so its text is not this session's name.
|
|
177
|
+
*/
|
|
178
|
+
export const CLAUDE_CUSTOM_TITLE_FIELDS = { 'custom-title': 'customTitle' };
|
|
179
|
+
export const CLAUDE_GENERATED_TITLE_FIELDS = { 'ai-title': 'aiTitle' };
|
|
180
|
+
/** A transcript line that may be a title entry; the rest of the tail is never parsed for one. */
|
|
181
|
+
export const RE_CLAUDE_TITLE_LINE = /"type"\s*:\s*"(?:custom-title|ai-title)"/;
|
|
59
182
|
/** Fallback tool name for a call the provider did not name. */
|
|
60
183
|
export const UNKNOWN_TOOL_NAME = 'unknown';
|
|
61
|
-
/** Metadata keys the tracker reads off canonical events. */
|
|
62
|
-
export const PROMPT_TEXT_KEY = 'promptText';
|
|
184
|
+
/** Metadata keys the tracker reads off canonical events. Evidence only: no text key exists. */
|
|
63
185
|
export const PROMPT_EVIDENCE_KEY = 'prompt';
|
|
64
|
-
export const RESPONSE_TEXT_KEY = 'responseText';
|
|
65
186
|
export const RESPONSE_EVIDENCE_KEY = 'response';
|
|
66
187
|
export const FILE_PATH_KEY = 'filePath';
|
|
188
|
+
export const EXTERNAL_PATH_KEY = 'externalPath';
|
|
189
|
+
export const PROMPT_TEXT_KEY = 'promptText';
|
|
190
|
+
export const PROMPT_JIRA_IDS_KEY = 'promptJiraIds';
|
|
67
191
|
/** Length of the hashed session directory name. */
|
|
68
192
|
export const SESSION_DIR_HASH_LENGTH = 32;
|
|
69
193
|
/** Length of the hashed lock names, which must be filesystem-safe. */
|
|
@@ -75,6 +199,14 @@ export const TRANSCRIPT_INPUT_TOKENS = 'input_tokens';
|
|
|
75
199
|
export const TRANSCRIPT_OUTPUT_TOKENS = 'output_tokens';
|
|
76
200
|
export const TRANSCRIPT_CACHE_READ_TOKENS = 'cache_read_input_tokens';
|
|
77
201
|
export const TRANSCRIPT_CACHE_CREATION_TOKENS = 'cache_creation_input_tokens';
|
|
202
|
+
/** Codex rollout rows the usage reader needs; every other row is skipped unparsed. */
|
|
203
|
+
export const CODEX_TOKEN_COUNT = 'token_count';
|
|
204
|
+
export const CODEX_TURN_CONTEXT = 'turn_context';
|
|
205
|
+
export const CODEX_LAST_TOKEN_USAGE = 'last_token_usage';
|
|
206
|
+
export const CODEX_CACHED_INPUT_TOKENS = 'cached_input_tokens';
|
|
207
|
+
/** Gemini CLI chat-file row type that carries a model reply, and its usage block. */
|
|
208
|
+
export const GEMINI_REPLY_TYPE = 'gemini';
|
|
209
|
+
export const GEMINI_TOKENS = 'tokens';
|
|
78
210
|
/** Every transcript token field, for weighting which model dominated a turn. */
|
|
79
211
|
export const TRANSCRIPT_TOKEN_FIELDS = [
|
|
80
212
|
TRANSCRIPT_INPUT_TOKENS,
|
|
@@ -84,3 +216,21 @@ export const TRANSCRIPT_TOKEN_FIELDS = [
|
|
|
84
216
|
];
|
|
85
217
|
/** Prefix for the content-hash id given to a transcript entry without one. */
|
|
86
218
|
export const ANONYMOUS_MESSAGE_ID_PREFIX = 'anon-';
|
|
219
|
+
/**
|
|
220
|
+
* Counts the commits between two oids that no remote-tracking ref reaches: the
|
|
221
|
+
* turn's own, as opposed to a pull, a reset or another branch's tip (SPEC §3a).
|
|
222
|
+
*
|
|
223
|
+
* @param from - The oid the turn started on.
|
|
224
|
+
* @param to - The oid or ref it ended on.
|
|
225
|
+
* @param since - Only commits made since then (ISO time): after a switch, the
|
|
226
|
+
* new branch's older commits are not the turn's.
|
|
227
|
+
* @returns The argument vector.
|
|
228
|
+
*/
|
|
229
|
+
export function gitOwnCommitCountArgs(from, to, since) {
|
|
230
|
+
// --ancestry-path: only commits descending from where the turn started, so a
|
|
231
|
+
// reset onto another local-only commit counts none.
|
|
232
|
+
const range = from === undefined ? [to] : ['--ancestry-path', `${from}..${to}`];
|
|
233
|
+
return ['rev-list', '--count', ...(since === undefined ? [] : [`--since=${since}`]), ...range, '--not', '--remotes', '--'];
|
|
234
|
+
}
|
|
235
|
+
/** Commit times are whole seconds; a commit in the second the turn first named its checkout is still the turn's. */
|
|
236
|
+
export const OWN_COMMIT_SINCE_SLACK_MS = 2000;
|