@agent-watch-ai/edge 0.2.5 → 0.3.1
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 +512 -0
- package/README.md +217 -96
- package/SECURITY.md +69 -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 +50 -4
- package/dist/cli/constants/cli.constants.js +54 -5
- package/dist/cli/context.d.ts +33 -2
- package/dist/cli/context.js +84 -14
- package/dist/cli/doctor.js +309 -32
- 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 +439 -98
- package/dist/cli/status.js +82 -13
- package/dist/cli/toggle.d.ts +9 -0
- package/dist/cli/toggle.js +113 -0
- package/dist/cli/types/cli.types.d.ts +37 -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 +100 -13
- 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 +113 -6
- package/dist/config/constants/config.constants.js +126 -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 +721 -84
- package/dist/config/schemas/config.schema.js +388 -15
- 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 +111 -0
- package/dist/credentials/constants/credentials.constants.js +112 -0
- package/dist/credentials/credential-status.d.ts +14 -0
- package/dist/credentials/credential-status.js +34 -0
- package/dist/credentials/credentials.d.ts +72 -0
- package/dist/credentials/credentials.js +253 -0
- package/dist/credentials/device-api.d.ts +64 -0
- package/dist/credentials/device-api.js +150 -0
- package/dist/credentials/device-state.d.ts +31 -0
- package/dist/credentials/device-state.js +51 -0
- package/dist/credentials/identity.d.ts +62 -0
- package/dist/credentials/identity.js +90 -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 +18 -0
- package/dist/credentials/sign-in.js +86 -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 +195 -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 +62 -16
- package/dist/enforcement/enforcement.d.ts +23 -2
- package/dist/enforcement/enforcement.js +103 -15
- package/dist/enforcement/index.d.ts +4 -3
- package/dist/enforcement/index.js +3 -2
- package/dist/enforcement/types/enforcement.types.d.ts +64 -0
- 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 +7 -0
- package/dist/pipeline/constants/pipeline.constants.js +7 -0
- package/dist/pipeline/hook-pipeline.js +360 -32
- 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 +73 -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 +24 -2
- package/dist/providers/codex/codex.otel.js +147 -30
- 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 +5 -0
- package/dist/providers/codex/constants/codex.otel.constants.js +5 -0
- package/dist/providers/constants/provider.constants.d.ts +0 -3
- package/dist/providers/constants/provider.constants.js +0 -3
- package/dist/providers/cursor/constants/cursor.constants.d.ts +7 -0
- package/dist/providers/cursor/constants/cursor.constants.js +7 -0
- package/dist/providers/cursor/cursor.adapter.d.ts +33 -1
- package/dist/providers/cursor/cursor.adapter.js +52 -3
- 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 +3 -1
- package/dist/providers/gemini/constants/gemini.otel.constants.js +3 -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 +19 -20
- package/dist/providers/gemini/gemini.otel.js +121 -17
- 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/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 +18 -2
- package/dist/providers/shared/constants/tooling.constants.js +19 -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 +12 -1
- package/dist/providers/shared/tooling.js +18 -0
- package/dist/providers/shared/types/adapter.types.d.ts +1 -2
- package/dist/providers/types/provider.types.d.ts +57 -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 +7 -0
- package/dist/storage/atomic-file.js +1 -1
- package/dist/storage/constants/storage.constants.d.ts +17 -0
- package/dist/storage/constants/storage.constants.js +17 -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 +65 -0
- package/dist/turns/work-checkout.js +666 -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 +648 -0
- package/docs/ENTERPRISE_DEPLOYMENT.md +179 -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
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { sanitizeValue } from './sanitizer.js';
|
|
2
|
+
/**
|
|
3
|
+
* Reapply current capture policy to persisted records before queueing or sending.
|
|
4
|
+
* Old turn state and offline events may predate a flag change — or this release —
|
|
5
|
+
* so the gate runs again here rather than only where the record was built.
|
|
6
|
+
* @param event - Product record, possibly from an older installation.
|
|
7
|
+
* @param capture - Effective, consent-gated capture flags. Metadata follows the
|
|
8
|
+
* schema defaults, so only an explicit `false` drops it.
|
|
9
|
+
* @returns A sanitized copy, or undefined when the whole record is no longer allowed.
|
|
10
|
+
*/
|
|
11
|
+
export function applyProductCapture(event, capture) {
|
|
12
|
+
// A snapshot is git metadata end to end — commit subjects included — so a
|
|
13
|
+
// revoked git flag drops the record instead of emptying it. Its commit files
|
|
14
|
+
// are path lists like any other, and go with `capture.files`.
|
|
15
|
+
if (event.event.type === 'repo.snapshot') {
|
|
16
|
+
if (capture?.git === false)
|
|
17
|
+
return undefined;
|
|
18
|
+
return sanitizeValue(capture?.files === false ? withoutCommitFiles(event) : event);
|
|
19
|
+
}
|
|
20
|
+
if (event.event.type !== 'turn.summary')
|
|
21
|
+
return sanitizeValue(event);
|
|
22
|
+
const summary = event;
|
|
23
|
+
// Response text goes unconditionally: this release never builds it, but a
|
|
24
|
+
// summary queued by an older one can still carry it. `prompt` is that older
|
|
25
|
+
// release's field and goes the same way; prompt text now rides only as
|
|
26
|
+
// `prompt_text`. Evidence (length + sha256) stays: it is what tells the
|
|
27
|
+
// backend a turn had content at all.
|
|
28
|
+
//
|
|
29
|
+
// The content fields need an explicit `true`: they are opt-in, and a
|
|
30
|
+
// missing policy is not consent. The path and repository fields need an
|
|
31
|
+
// explicit `false`: they are on by default. A queued record can outlive
|
|
32
|
+
// any of these flags, which is why they are asked again here.
|
|
33
|
+
const git = capture?.git === false;
|
|
34
|
+
const files = capture?.files === false;
|
|
35
|
+
return sanitizeValue({
|
|
36
|
+
...event,
|
|
37
|
+
prompt: undefined,
|
|
38
|
+
response: undefined,
|
|
39
|
+
prompt_text: capture?.promptText === true ? summary.prompt_text : undefined,
|
|
40
|
+
tool_inputs: capture?.toolInput === true ? summary.tool_inputs : undefined,
|
|
41
|
+
session_name: capture?.sessionTitle === true ? summary.session_name : undefined,
|
|
42
|
+
session_title: capture?.sessionTitle === true ? summary.session_title : undefined,
|
|
43
|
+
repository: git ? undefined : summary.repository,
|
|
44
|
+
branch: git ? undefined : summary.branch,
|
|
45
|
+
commit: git ? undefined : summary.commit,
|
|
46
|
+
jira_ids: git ? undefined : summary.jira_ids,
|
|
47
|
+
prompt_jira_ids: git ? undefined : summary.prompt_jira_ids,
|
|
48
|
+
work_evidence: git ? undefined : summary.work_evidence,
|
|
49
|
+
parent_session_id: git ? undefined : summary.parent_session_id,
|
|
50
|
+
content_hashes: files ? undefined : summary.content_hashes,
|
|
51
|
+
manifest_repository: files ? undefined : summary.manifest_repository,
|
|
52
|
+
files_changed: files ? undefined : summary.files_changed,
|
|
53
|
+
files_touched: files ? undefined : summary.files_touched,
|
|
54
|
+
files_read: files ? undefined : summary.files_read,
|
|
55
|
+
external_files_touched: files ? undefined : summary.external_files_touched,
|
|
56
|
+
external_files_read: files ? undefined : summary.external_files_read
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A snapshot with no commit file names, for a policy that withholds paths.
|
|
61
|
+
*
|
|
62
|
+
* @param event - The snapshot, possibly queued before the flag changed.
|
|
63
|
+
* @returns A copy whose commits carry no `files`.
|
|
64
|
+
*/
|
|
65
|
+
function withoutCommitFiles(event) {
|
|
66
|
+
return {
|
|
67
|
+
...event,
|
|
68
|
+
branches: event.branches.map((branch) => ({
|
|
69
|
+
...branch,
|
|
70
|
+
commits: branch.commits.map(({ files: _files, ...commit }) => commit)
|
|
71
|
+
}))
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Redact known credential shapes inside a string, and cap its length.
|
|
3
3
|
*
|
|
4
|
+
* Redaction runs on the whole string and the cap is applied to the result,
|
|
5
|
+
* never the other way round. Truncating first cuts a credential that straddles
|
|
6
|
+
* the boundary short, so no pattern matches it any more and the surviving
|
|
7
|
+
* prefix ships in the clear: `openai-anthropic-key` needs 16 characters after
|
|
8
|
+
* `sk-`, and `jwt` needs its third dot-separated segment — a JWT cut mid
|
|
9
|
+
* signature would have shipped its header and payload, which base64url-decode
|
|
10
|
+
* to the very claims this exists to keep off the wire.
|
|
11
|
+
*
|
|
12
|
+
* Scrubbing the whole string is affordable because every pattern is linear in
|
|
13
|
+
* its input — see `url-credentials`, which was not. A bounded window instead of
|
|
14
|
+
* the whole string would not do: the margin would have to exceed the longest
|
|
15
|
+
* credential, and a private-key block or a JWT with a fat payload has no such
|
|
16
|
+
* length.
|
|
17
|
+
*
|
|
4
18
|
* @param text - Text about to leave the machine.
|
|
5
19
|
* @returns The scrubbed text.
|
|
6
20
|
*/
|
|
@@ -10,9 +24,13 @@ export declare function sanitizeText(text: string): string;
|
|
|
10
24
|
*
|
|
11
25
|
* Two independent defences, because either alone leaks: a value under a
|
|
12
26
|
* sensitive *key* is dropped whole whatever it looks like, and every string is
|
|
13
|
-
* pattern-scrubbed whatever key it sits under
|
|
14
|
-
*
|
|
15
|
-
*
|
|
27
|
+
* pattern-scrubbed whatever key it sits under — keys included, because captured
|
|
28
|
+
* material contains keyed maps whose keys are the credential. Both run
|
|
29
|
+
* regardless of the user's capture settings — those decide what we collect, not
|
|
30
|
+
* whether secrets are removed from it.
|
|
31
|
+
*
|
|
32
|
+
* The sensitive-key test reads the *raw* key, since scrubbing it first could
|
|
33
|
+
* destroy the very word ("authorization") the test matches on.
|
|
16
34
|
*
|
|
17
35
|
* @param value - Value to sanitize; left untouched.
|
|
18
36
|
* @returns A sanitized copy of the same shape.
|
|
@@ -3,24 +3,42 @@ import { MAX_DEPTH, MAX_STRING_LENGTH, REDACTED, SECRET_PATTERNS, SENSITIVE_KEY_
|
|
|
3
3
|
/**
|
|
4
4
|
* Redact known credential shapes inside a string, and cap its length.
|
|
5
5
|
*
|
|
6
|
+
* Redaction runs on the whole string and the cap is applied to the result,
|
|
7
|
+
* never the other way round. Truncating first cuts a credential that straddles
|
|
8
|
+
* the boundary short, so no pattern matches it any more and the surviving
|
|
9
|
+
* prefix ships in the clear: `openai-anthropic-key` needs 16 characters after
|
|
10
|
+
* `sk-`, and `jwt` needs its third dot-separated segment — a JWT cut mid
|
|
11
|
+
* signature would have shipped its header and payload, which base64url-decode
|
|
12
|
+
* to the very claims this exists to keep off the wire.
|
|
13
|
+
*
|
|
14
|
+
* Scrubbing the whole string is affordable because every pattern is linear in
|
|
15
|
+
* its input — see `url-credentials`, which was not. A bounded window instead of
|
|
16
|
+
* the whole string would not do: the margin would have to exceed the longest
|
|
17
|
+
* credential, and a private-key block or a JWT with a fat payload has no such
|
|
18
|
+
* length.
|
|
19
|
+
*
|
|
6
20
|
* @param text - Text about to leave the machine.
|
|
7
21
|
* @returns The scrubbed text.
|
|
8
22
|
*/
|
|
9
23
|
export function sanitizeText(text) {
|
|
10
|
-
let out = text
|
|
24
|
+
let out = text;
|
|
11
25
|
for (const { pattern, replacement } of SECRET_PATTERNS) {
|
|
12
26
|
out = out.replace(pattern, replacement ?? REDACTED);
|
|
13
27
|
}
|
|
14
|
-
return out;
|
|
28
|
+
return out.length > MAX_STRING_LENGTH ? out.slice(0, MAX_STRING_LENGTH) : out;
|
|
15
29
|
}
|
|
16
30
|
/**
|
|
17
31
|
* Recursively sanitize any value before it leaves the machine.
|
|
18
32
|
*
|
|
19
33
|
* Two independent defences, because either alone leaks: a value under a
|
|
20
34
|
* sensitive *key* is dropped whole whatever it looks like, and every string is
|
|
21
|
-
* pattern-scrubbed whatever key it sits under
|
|
22
|
-
*
|
|
23
|
-
*
|
|
35
|
+
* pattern-scrubbed whatever key it sits under — keys included, because captured
|
|
36
|
+
* material contains keyed maps whose keys are the credential. Both run
|
|
37
|
+
* regardless of the user's capture settings — those decide what we collect, not
|
|
38
|
+
* whether secrets are removed from it.
|
|
39
|
+
*
|
|
40
|
+
* The sensitive-key test reads the *raw* key, since scrubbing it first could
|
|
41
|
+
* destroy the very word ("authorization") the test matches on.
|
|
24
42
|
*
|
|
25
43
|
* @param value - Value to sanitize; left untouched.
|
|
26
44
|
* @returns A sanitized copy of the same shape.
|
|
@@ -42,11 +60,37 @@ function walk(value, depth) {
|
|
|
42
60
|
return sanitizeText(value);
|
|
43
61
|
if (Array.isArray(value))
|
|
44
62
|
return value.map((item) => walk(item, depth + 1));
|
|
63
|
+
// A Date is an object to `isRecord`, so rebuilding it as a record turned it
|
|
64
|
+
// into `{}` — the record on the wire lost a timestamp that `JSON.stringify`
|
|
65
|
+
// would have written as an ISO string. It carries no secret and has nothing
|
|
66
|
+
// to descend into, so it passes through and serializes as it always would.
|
|
67
|
+
if (value instanceof Date)
|
|
68
|
+
return value;
|
|
45
69
|
if (!isRecord(value))
|
|
46
70
|
return value;
|
|
47
|
-
const out =
|
|
71
|
+
const out = Object.create(null);
|
|
48
72
|
for (const [key, entry] of Object.entries(value)) {
|
|
49
|
-
out[key] = SENSITIVE_KEY_PATTERN.test(key) ? REDACTED : walk(entry, depth + 1);
|
|
73
|
+
out[freeKey(out, sanitizeText(key))] = SENSITIVE_KEY_PATTERN.test(key) ? REDACTED : walk(entry, depth + 1);
|
|
50
74
|
}
|
|
51
|
-
return out;
|
|
75
|
+
return { ...out };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* First unused spelling of an already-sanitized key.
|
|
79
|
+
*
|
|
80
|
+
* Two distinct keys can scrub to the same string, and plain assignment would
|
|
81
|
+
* then silently merge two entries into one — data loss in the module whose job
|
|
82
|
+
* is to be trustworthy. Collisions get a `:2`, `:3` suffix instead, so the copy
|
|
83
|
+
* always holds as many entries as the original.
|
|
84
|
+
*
|
|
85
|
+
* @param out - Object being built; only read here.
|
|
86
|
+
* @param key - Sanitized key to place.
|
|
87
|
+
* @returns The key itself, or the first free suffixed spelling of it.
|
|
88
|
+
*/
|
|
89
|
+
function freeKey(out, key) {
|
|
90
|
+
if (!(key in out))
|
|
91
|
+
return key;
|
|
92
|
+
let suffix = 2;
|
|
93
|
+
while (`${key}:${suffix}` in out)
|
|
94
|
+
suffix += 1;
|
|
95
|
+
return `${key}:${suffix}`;
|
|
52
96
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ProcessInfo, ProcessTable } from './types/process.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parse `ps -o pid=,ppid=,lstart=,comm=` output. Lines that do not parse are dropped.
|
|
4
|
+
*
|
|
5
|
+
* @param text - The listing.
|
|
6
|
+
* @returns The processes by pid.
|
|
7
|
+
*/
|
|
8
|
+
export declare function parseProcessList(text: string): Map<number, ProcessInfo>;
|
|
9
|
+
/**
|
|
10
|
+
* The processes above `pid`, nearest first.
|
|
11
|
+
*
|
|
12
|
+
* Stops at the depth cap, at a pid the table does not list, at pid 0/1 and at a
|
|
13
|
+
* cycle: a damaged table must end the walk, never loop it.
|
|
14
|
+
*
|
|
15
|
+
* @param table - The listing.
|
|
16
|
+
* @param pid - The process whose ancestors are wanted; not itself included.
|
|
17
|
+
* @param depth - How many to return at most.
|
|
18
|
+
* @returns The ancestors.
|
|
19
|
+
*/
|
|
20
|
+
export declare function ancestorChain(table: ReadonlyMap<number, ProcessInfo>, pid: number, depth?: number): ProcessInfo[];
|
|
21
|
+
/**
|
|
22
|
+
* The agent process behind a hook: its parent, or that parent's parent when a
|
|
23
|
+
* shell was put between them to run the hook command.
|
|
24
|
+
*
|
|
25
|
+
* Without the hop, an ephemeral `sh -c` would be recorded as the agent and no
|
|
26
|
+
* child's ancestry would ever contain it.
|
|
27
|
+
*
|
|
28
|
+
* @param table - The process table.
|
|
29
|
+
* @returns The agent process with its start time, or undefined when it cannot be read.
|
|
30
|
+
*/
|
|
31
|
+
export declare function agentProcess(table: ProcessTable): Promise<ProcessInfo | undefined>;
|
|
32
|
+
/**
|
|
33
|
+
* The real process table. Fails open: every error is an absent answer.
|
|
34
|
+
*
|
|
35
|
+
* @param signal - Kills every `ps` or `lsof` still running when it aborts, so a
|
|
36
|
+
* walk past its deadline leaves no child behind.
|
|
37
|
+
* @returns A table over `ps`, and `/proc` or `lsof` for working folders.
|
|
38
|
+
*/
|
|
39
|
+
export declare function systemProcessTable(signal?: AbortSignal): ProcessTable;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
import { debugLog } from '../core/logger.js';
|
|
5
|
+
import { LSOF_FAST_ARGS, MAX_ANCESTOR_DEPTH, PROCESS_MAX_BUFFER_BYTES, PROCESS_TIMEOUT_MS, RE_LOGIN_SHELL_DASH, RE_LSOF_PID, RE_PS_LINE, SHELL_NAMES } from './constants/process.constants.js';
|
|
6
|
+
/**
|
|
7
|
+
* Parse `ps -o pid=,ppid=,lstart=,comm=` output. Lines that do not parse are dropped.
|
|
8
|
+
*
|
|
9
|
+
* @param text - The listing.
|
|
10
|
+
* @returns The processes by pid.
|
|
11
|
+
*/
|
|
12
|
+
export function parseProcessList(text) {
|
|
13
|
+
const table = new Map();
|
|
14
|
+
for (const line of text.split('\n')) {
|
|
15
|
+
const match = RE_PS_LINE.exec(line);
|
|
16
|
+
if (match)
|
|
17
|
+
table.set(Number(match[1]), { pid: Number(match[1]), ppid: Number(match[2]), started: match[3], comm: match[4] ?? '' });
|
|
18
|
+
}
|
|
19
|
+
return table;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The processes above `pid`, nearest first.
|
|
23
|
+
*
|
|
24
|
+
* Stops at the depth cap, at a pid the table does not list, at pid 0/1 and at a
|
|
25
|
+
* cycle: a damaged table must end the walk, never loop it.
|
|
26
|
+
*
|
|
27
|
+
* @param table - The listing.
|
|
28
|
+
* @param pid - The process whose ancestors are wanted; not itself included.
|
|
29
|
+
* @param depth - How many to return at most.
|
|
30
|
+
* @returns The ancestors.
|
|
31
|
+
*/
|
|
32
|
+
export function ancestorChain(table, pid, depth = MAX_ANCESTOR_DEPTH) {
|
|
33
|
+
const chain = [];
|
|
34
|
+
const seen = new Set([pid]);
|
|
35
|
+
let next = table.get(pid)?.ppid;
|
|
36
|
+
while (next !== undefined && next > 1 && !seen.has(next) && chain.length < depth) {
|
|
37
|
+
const info = table.get(next);
|
|
38
|
+
if (!info)
|
|
39
|
+
break;
|
|
40
|
+
chain.push(info);
|
|
41
|
+
seen.add(next);
|
|
42
|
+
next = info.ppid;
|
|
43
|
+
}
|
|
44
|
+
return chain;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The agent process behind a hook: its parent, or that parent's parent when a
|
|
48
|
+
* shell was put between them to run the hook command.
|
|
49
|
+
*
|
|
50
|
+
* Without the hop, an ephemeral `sh -c` would be recorded as the agent and no
|
|
51
|
+
* child's ancestry would ever contain it.
|
|
52
|
+
*
|
|
53
|
+
* @param table - The process table.
|
|
54
|
+
* @returns The agent process with its start time, or undefined when it cannot be read.
|
|
55
|
+
*/
|
|
56
|
+
export async function agentProcess(table) {
|
|
57
|
+
const parent = await table.info(table.ppid);
|
|
58
|
+
if (!parent || !isShell(parent))
|
|
59
|
+
return parent;
|
|
60
|
+
return (await table.info(parent.ppid)) ?? parent;
|
|
61
|
+
}
|
|
62
|
+
function isShell(info) {
|
|
63
|
+
return SHELL_NAMES.has(info.comm.split('/').pop().replace(RE_LOGIN_SHELL_DASH, ''));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The real process table. Fails open: every error is an absent answer.
|
|
67
|
+
*
|
|
68
|
+
* @param signal - Kills every `ps` or `lsof` still running when it aborts, so a
|
|
69
|
+
* walk past its deadline leaves no child behind.
|
|
70
|
+
* @returns A table over `ps`, and `/proc` or `lsof` for working folders.
|
|
71
|
+
*/
|
|
72
|
+
export function systemProcessTable(signal) {
|
|
73
|
+
return {
|
|
74
|
+
ppid: process.ppid,
|
|
75
|
+
async info(pid) {
|
|
76
|
+
return parseProcessList((await run('ps', ['-o', 'pid=,ppid=,lstart=,comm=', '-p', String(pid)], signal)) ?? '').get(pid);
|
|
77
|
+
},
|
|
78
|
+
async snapshot() {
|
|
79
|
+
const text = await run('ps', ['-A', '-o', 'pid=,ppid='], signal);
|
|
80
|
+
return text === undefined ? undefined : parseProcessList(text);
|
|
81
|
+
},
|
|
82
|
+
cwds: (pids) => (process.platform === 'linux' ? procCwds(pids) : lsofCwds(pids, signal))
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
async function procCwds(pids) {
|
|
86
|
+
const found = new Map();
|
|
87
|
+
await Promise.all(pids.map(async (pid) => {
|
|
88
|
+
const cwd = await fs.readlink(`/proc/${pid}/cwd`).catch(() => undefined);
|
|
89
|
+
if (cwd)
|
|
90
|
+
found.set(pid, cwd);
|
|
91
|
+
}));
|
|
92
|
+
return found;
|
|
93
|
+
}
|
|
94
|
+
// One lsof for the whole chain: each spawn costs more than the lookup does.
|
|
95
|
+
async function lsofCwds(pids, signal) {
|
|
96
|
+
const found = new Map();
|
|
97
|
+
if (process.platform === 'win32' || pids.length === 0)
|
|
98
|
+
return found;
|
|
99
|
+
let current;
|
|
100
|
+
for (const line of ((await run('lsof', [...LSOF_FAST_ARGS, '-a', '-p', pids.join(','), '-d', 'cwd', '-Fn'], signal)) ?? '').split('\n')) {
|
|
101
|
+
const pid = RE_LSOF_PID.exec(line);
|
|
102
|
+
if (pid)
|
|
103
|
+
current = Number(pid[1]);
|
|
104
|
+
if (line.startsWith('n/') && current !== undefined)
|
|
105
|
+
found.set(current, line.slice(1));
|
|
106
|
+
}
|
|
107
|
+
return found;
|
|
108
|
+
}
|
|
109
|
+
// Killed at PROCESS_TIMEOUT_MS, or at once when `signal` aborts.
|
|
110
|
+
function run(file, args, signal) {
|
|
111
|
+
if (process.platform === 'win32')
|
|
112
|
+
return Promise.resolve(undefined);
|
|
113
|
+
return new Promise((resolve) => {
|
|
114
|
+
execFile(file, args, { timeout: PROCESS_TIMEOUT_MS, signal, maxBuffer: PROCESS_MAX_BUFFER_BYTES, windowsHide: true, env: { ...process.env, LC_ALL: 'C' } }, (error, stdout) => {
|
|
115
|
+
// A fixed sentence: nothing about which processes ran belongs in a log.
|
|
116
|
+
if (error && !stdout)
|
|
117
|
+
debugLog('process table unreadable');
|
|
118
|
+
resolve(error && !stdout ? undefined : stdout);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** How many processes above the agent are looked at. */
|
|
2
|
+
export declare const MAX_ANCESTOR_DEPTH = 8;
|
|
3
|
+
/**
|
|
4
|
+
* Kill budget for each `ps` or `lsof` child, so a stuck one does not outlive
|
|
5
|
+
* the walk's deadline by much. A healthy run is 15-25 ms.
|
|
6
|
+
*/
|
|
7
|
+
export declare const PROCESS_TIMEOUT_MS = 150;
|
|
8
|
+
/** Upper bound on `ps` output: a busy machine lists a few thousand processes. */
|
|
9
|
+
export declare const PROCESS_MAX_BUFFER_BYTES: number;
|
|
10
|
+
/**
|
|
11
|
+
* `<pid> <ppid> [[<lstart>] <comm>]`. lstart is always five fields, `Sat Oct 4
|
|
12
|
+
* 11:42:27 2026`, with the day padded by spaces; the command is the rest of the
|
|
13
|
+
* line. The bulk listing asks for neither: resolving every process's command
|
|
14
|
+
* costs as much as listing them all, and the chain needs only pids.
|
|
15
|
+
*/
|
|
16
|
+
export declare const RE_PS_LINE: RegExp;
|
|
17
|
+
/**
|
|
18
|
+
* The whole walk's deadline: SPEC §8 allows the first hook of a session 100 ms
|
|
19
|
+
* at the 95th percentile. A slow `ps` or `lsof` is abandoned, never waited for.
|
|
20
|
+
*/
|
|
21
|
+
export declare const WALK_DEADLINE_MS = 100;
|
|
22
|
+
/**
|
|
23
|
+
* Walks a session gets when the deadline keeps cutting them: the first hook's
|
|
24
|
+
* and two retries, one per later hook, each under {@link WALK_DEADLINE_MS}.
|
|
25
|
+
*/
|
|
26
|
+
export declare const MAX_WALK_ATTEMPTS = 3;
|
|
27
|
+
/** A login shell's name carries a leading dash: `-zsh`. */
|
|
28
|
+
export declare const RE_LOGIN_SHELL_DASH: RegExp;
|
|
29
|
+
/** `lsof` without name resolution or kernel calls that can block: half the time, same answer for a cwd. */
|
|
30
|
+
export declare const LSOF_FAST_ARGS: readonly string[];
|
|
31
|
+
/** Shells a hook command may be wrapped in; the agent is the shell's parent. */
|
|
32
|
+
export declare const SHELL_NAMES: ReadonlySet<string>;
|
|
33
|
+
/** `lsof -Fn` prints `p<pid>` then `n<path>` for each process. */
|
|
34
|
+
export declare const RE_LSOF_PID: RegExp;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** How many processes above the agent are looked at. */
|
|
2
|
+
export const MAX_ANCESTOR_DEPTH = 8;
|
|
3
|
+
/**
|
|
4
|
+
* Kill budget for each `ps` or `lsof` child, so a stuck one does not outlive
|
|
5
|
+
* the walk's deadline by much. A healthy run is 15-25 ms.
|
|
6
|
+
*/
|
|
7
|
+
export const PROCESS_TIMEOUT_MS = 150;
|
|
8
|
+
/** Upper bound on `ps` output: a busy machine lists a few thousand processes. */
|
|
9
|
+
export const PROCESS_MAX_BUFFER_BYTES = 8 * 1024 * 1024;
|
|
10
|
+
/**
|
|
11
|
+
* `<pid> <ppid> [[<lstart>] <comm>]`. lstart is always five fields, `Sat Oct 4
|
|
12
|
+
* 11:42:27 2026`, with the day padded by spaces; the command is the rest of the
|
|
13
|
+
* line. The bulk listing asks for neither: resolving every process's command
|
|
14
|
+
* costs as much as listing them all, and the chain needs only pids.
|
|
15
|
+
*/
|
|
16
|
+
export const RE_PS_LINE = /^\s*(\d+)\s+(\d+)(?:\s+(?:(\w{3} \w{3}\s+\d+ \d\d:\d\d:\d\d \d{4})\s+)?(.+?))?\s*$/;
|
|
17
|
+
/**
|
|
18
|
+
* The whole walk's deadline: SPEC §8 allows the first hook of a session 100 ms
|
|
19
|
+
* at the 95th percentile. A slow `ps` or `lsof` is abandoned, never waited for.
|
|
20
|
+
*/
|
|
21
|
+
export const WALK_DEADLINE_MS = 100;
|
|
22
|
+
/**
|
|
23
|
+
* Walks a session gets when the deadline keeps cutting them: the first hook's
|
|
24
|
+
* and two retries, one per later hook, each under {@link WALK_DEADLINE_MS}.
|
|
25
|
+
*/
|
|
26
|
+
export const MAX_WALK_ATTEMPTS = 3;
|
|
27
|
+
/** A login shell's name carries a leading dash: `-zsh`. */
|
|
28
|
+
export const RE_LOGIN_SHELL_DASH = /^-/;
|
|
29
|
+
/** `lsof` without name resolution or kernel calls that can block: half the time, same answer for a cwd. */
|
|
30
|
+
export const LSOF_FAST_ARGS = ['-b', '-n', '-P', '-w'];
|
|
31
|
+
/** Shells a hook command may be wrapped in; the agent is the shell's parent. */
|
|
32
|
+
export const SHELL_NAMES = new Set(['sh', 'bash', 'zsh', 'dash', 'fish', 'ksh']);
|
|
33
|
+
/** `lsof -Fn` prints `p<pid>` then `n<path>` for each process. */
|
|
34
|
+
export const RE_LSOF_PID = /^p(\d+)$/;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The machine's process table, read once per session to find what started the
|
|
3
|
+
* agent. Local only, and fail-open: nothing here may fail a hook.
|
|
4
|
+
*/
|
|
5
|
+
export type { ProcessInfo, ProcessTable } from './types/process.types.js';
|
|
6
|
+
export { agentProcess, ancestorChain, parseProcessList, systemProcessTable } from './ancestors.js';
|
|
7
|
+
export { MAX_ANCESTOR_DEPTH, MAX_WALK_ATTEMPTS, WALK_DEADLINE_MS } from './constants/process.constants.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** One process, as `ps` lists it. Local only: none of it is ever sent. */
|
|
2
|
+
export interface ProcessInfo {
|
|
3
|
+
readonly pid: number;
|
|
4
|
+
readonly ppid: number;
|
|
5
|
+
/** Start time as `ps -o lstart` prints it; tells a pid's reuse from the process remembered. */
|
|
6
|
+
readonly started?: string;
|
|
7
|
+
/** Executable name, possibly a full path; empty in the bulk listing, which does not resolve it. */
|
|
8
|
+
readonly comm: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* What the edge may ask of the machine's process table. Injected through `Env`
|
|
12
|
+
* so a test can stand up a process tree no harness could start for real.
|
|
13
|
+
*/
|
|
14
|
+
export interface ProcessTable {
|
|
15
|
+
/** The hook process's own parent: the agent, or the shell the agent ran the hook in. */
|
|
16
|
+
readonly ppid: number;
|
|
17
|
+
/** One process, or undefined when it is gone or the table cannot be read. */
|
|
18
|
+
info(pid: number): Promise<ProcessInfo | undefined>;
|
|
19
|
+
/** Every process, listed once, without start times or names (`info` has them). Undefined when the table cannot be read. */
|
|
20
|
+
snapshot(): Promise<ReadonlyMap<number, ProcessInfo> | undefined>;
|
|
21
|
+
/** The working folders of these processes; a pid whose folder cannot be read is absent. */
|
|
22
|
+
cwds(pids: readonly number[]): Promise<ReadonlyMap<number, string>>;
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AgentWatchEvent } from '../../events/types/events.types.js';
|
|
2
|
-
import type { HookContext } from '../types/provider.types.js';
|
|
2
|
+
import type { HookContext, ShellCall } from '../types/provider.types.js';
|
|
3
3
|
import type { AntigravityHookEvent } from './types/antigravity.types.js';
|
|
4
4
|
export type { AntigravityHookEvent, AntigravityPayload } from './types/antigravity.types.js';
|
|
5
5
|
/**
|
|
@@ -24,6 +24,17 @@ export declare function antigravityHookEvent(rawPayload: unknown): AntigravityHo
|
|
|
24
24
|
* @returns The primary workspace path, or undefined.
|
|
25
25
|
*/
|
|
26
26
|
export declare function antigravityCwd(rawPayload: unknown): string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* The command a `run_command` tool call runs, and its `Cwd`, before and after it
|
|
29
|
+
* ran (a command can create the worktree it works in).
|
|
30
|
+
*
|
|
31
|
+
* Arguments as the fixtures record them, read off the tool schema in the `agy`
|
|
32
|
+
* binary: `CommandLine` and `Cwd`, PascalCase.
|
|
33
|
+
*
|
|
34
|
+
* @param rawPayload - Raw JSON from the hook's stdin.
|
|
35
|
+
* @returns The call, or undefined for any other payload.
|
|
36
|
+
*/
|
|
37
|
+
export declare function antigravityShellCall(rawPayload: unknown): ShellCall | undefined;
|
|
27
38
|
/**
|
|
28
39
|
* Translate one Antigravity hook payload into canonical events.
|
|
29
40
|
*
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { sha256Hex } from '../../events/event-id.js';
|
|
2
2
|
import { baseEvent, promptPatch, responsePatch, toolPatch, withPatch } from '../shared/event-builder.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { asRecord } from '../../core/object.js';
|
|
4
|
+
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';
|
|
5
6
|
import { antigravityPayloadSchema } from './schemas/antigravity.schema.js';
|
|
6
7
|
const ARGS_KEYS = Object.keys(ANTIGRAVITY_HOOK_EVENT_BY_ARGS);
|
|
7
8
|
/**
|
|
@@ -37,6 +38,23 @@ export function antigravityCwd(rawPayload) {
|
|
|
37
38
|
return undefined;
|
|
38
39
|
return parsed.data.common?.workspacePaths?.[0];
|
|
39
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* The command a `run_command` tool call runs, and its `Cwd`, before and after it
|
|
43
|
+
* ran (a command can create the worktree it works in).
|
|
44
|
+
*
|
|
45
|
+
* Arguments as the fixtures record them, read off the tool schema in the `agy`
|
|
46
|
+
* binary: `CommandLine` and `Cwd`, PascalCase.
|
|
47
|
+
*
|
|
48
|
+
* @param rawPayload - Raw JSON from the hook's stdin.
|
|
49
|
+
* @returns The call, or undefined for any other payload.
|
|
50
|
+
*/
|
|
51
|
+
export function antigravityShellCall(rawPayload) {
|
|
52
|
+
const parsed = antigravityPayloadSchema.safeParse(rawPayload);
|
|
53
|
+
const toolCall = parsed.success ? (parsed.data.preToolHookArgs ?? parsed.data.postToolHookArgs)?.toolCall : undefined;
|
|
54
|
+
if (classifyTool(toolCall?.name) !== 'shell')
|
|
55
|
+
return undefined;
|
|
56
|
+
return shellCallOf(extractCommand(toolCall?.args), asRecord(toolCall?.args)?.[ANTIGRAVITY_CWD_KEY]);
|
|
57
|
+
}
|
|
40
58
|
/**
|
|
41
59
|
* Translate one Antigravity hook payload into canonical events.
|
|
42
60
|
*
|
|
@@ -148,7 +166,7 @@ function hookPatch(payload, hook, context) {
|
|
|
148
166
|
if (hook === 'PreToolUse' || hook === 'PostToolUse')
|
|
149
167
|
return antigravityToolPatch(payload, hook, context);
|
|
150
168
|
if (hook === 'Stop')
|
|
151
|
-
return responsePatch(payload.stopHookArgs?.finalModelOutput ?? ''
|
|
169
|
+
return responsePatch(payload.stopHookArgs?.finalModelOutput ?? '');
|
|
152
170
|
return {};
|
|
153
171
|
}
|
|
154
172
|
/**
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import type { Env } from '../../core/types/core.types.js';
|
|
2
2
|
import type { DetectionResult } from '../types/provider.types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Antigravity's configuration root.
|
|
5
|
-
*
|
|
6
|
-
* It shares Gemini's home directory: `~/.gemini/config`.
|
|
7
|
-
*
|
|
8
|
-
* @param env - Environment supplying HOME.
|
|
9
|
-
* @returns Absolute path of the config root.
|
|
10
|
-
*/
|
|
11
|
-
export declare function antigravityRoot(env: Env): string;
|
|
12
3
|
/**
|
|
13
4
|
* Where Antigravity reads named hook groups from.
|
|
14
5
|
*
|
|
@@ -12,7 +12,7 @@ import { ANTIGRAVITY_CLI_DIR_SEGMENTS, ANTIGRAVITY_EXECUTABLES, ANTIGRAVITY_HOOK
|
|
|
12
12
|
* @param env - Environment supplying HOME.
|
|
13
13
|
* @returns Absolute path of the config root.
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
function antigravityRoot(env) {
|
|
16
16
|
return path.join(env.home, ...ANTIGRAVITY_ROOT_SEGMENTS);
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { antigravityCwd, antigravityHookEvent, parseAntigravityHookEvent } from './antigravity.adapter.js';
|
|
1
|
+
import { antigravityCwd, antigravityHookEvent, antigravityShellCall, parseAntigravityHookEvent } from './antigravity.adapter.js';
|
|
2
2
|
import { detectAntigravity } from './antigravity.detect.js';
|
|
3
3
|
import { installAntigravityHooks, uninstallAntigravityHooks } from './antigravity.hooks.js';
|
|
4
4
|
import { ANTIGRAVITY_DISPLAY_NAME, ANTIGRAVITY_FALLBACK_DECISION, ANTIGRAVITY_HOOK_DECISIONS, ANTIGRAVITY_PROVIDER_ID } from './constants/antigravity.constants.js';
|
|
@@ -14,7 +14,8 @@ export const antigravityProvider = {
|
|
|
14
14
|
const decision = hook === undefined ? ANTIGRAVITY_FALLBACK_DECISION : ANTIGRAVITY_HOOK_DECISIONS[hook];
|
|
15
15
|
return { stdout: JSON.stringify(decision ?? {}), exitCode: 0 };
|
|
16
16
|
},
|
|
17
|
-
resolveCwd: antigravityCwd
|
|
17
|
+
resolveCwd: antigravityCwd,
|
|
18
|
+
shellCall: antigravityShellCall
|
|
18
19
|
// No nativeTelemetry: Antigravity exposes no OTLP exporter configuration, so
|
|
19
20
|
// there is no llm.call ledger source and turn summaries stay
|
|
20
21
|
// usage_status=pending. Adding a configurator would claim a capability the
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare const ANTIGRAVITY_PROVIDER_ID = "antigravity";
|
|
2
2
|
export declare const ANTIGRAVITY_DISPLAY_NAME = "Google Antigravity";
|
|
3
|
+
/** `run_command`'s working-directory argument, PascalCase like all of its arguments. */
|
|
4
|
+
export declare const ANTIGRAVITY_CWD_KEY = "Cwd";
|
|
3
5
|
/** Antigravity shares Gemini's home; its own config lives one level down. */
|
|
4
6
|
export declare const ANTIGRAVITY_ROOT_SEGMENTS: readonly [".gemini", "config"];
|
|
5
7
|
export declare const ANTIGRAVITY_CLI_DIR_SEGMENTS: readonly [".gemini", "antigravity-cli"];
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export const ANTIGRAVITY_PROVIDER_ID = 'antigravity';
|
|
2
2
|
export const ANTIGRAVITY_DISPLAY_NAME = 'Google Antigravity';
|
|
3
|
+
/** `run_command`'s working-directory argument, PascalCase like all of its arguments. */
|
|
4
|
+
export const ANTIGRAVITY_CWD_KEY = 'Cwd';
|
|
3
5
|
/** Antigravity shares Gemini's home; its own config lives one level down. */
|
|
4
6
|
export const ANTIGRAVITY_ROOT_SEGMENTS = ['.gemini', 'config'];
|
|
5
7
|
export const ANTIGRAVITY_CLI_DIR_SEGMENTS = ['.gemini', 'antigravity-cli'];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AgentWatchEvent } from '../../events/types/events.types.js';
|
|
2
|
-
import type { HookContext } from '../types/provider.types.js';
|
|
2
|
+
import type { HookContext, ShellCall } from '../types/provider.types.js';
|
|
3
3
|
export type { ClaudePayload } from './types/claude.types.js';
|
|
4
4
|
/**
|
|
5
5
|
* Translate one Claude Code hook payload into canonical events.
|
|
@@ -13,3 +13,13 @@ export type { ClaudePayload } from './types/claude.types.js';
|
|
|
13
13
|
* @returns The canonical events, or an empty list.
|
|
14
14
|
*/
|
|
15
15
|
export declare function parseClaudeHookEvent(rawPayload: unknown, context: HookContext): AgentWatchEvent[];
|
|
16
|
+
/**
|
|
17
|
+
* The command a Bash tool hook is about to run, or has just run.
|
|
18
|
+
*
|
|
19
|
+
* Claude reports no separate working directory for the call: it runs in the
|
|
20
|
+
* payload's `cwd`.
|
|
21
|
+
*
|
|
22
|
+
* @param rawPayload - Raw JSON from the hook's stdin.
|
|
23
|
+
* @returns The command, or undefined for any other payload.
|
|
24
|
+
*/
|
|
25
|
+
export declare function claudeShellCall(rawPayload: unknown): ShellCall | undefined;
|