@agent-watch-ai/edge 0.3.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/CHANGELOG.md +75 -0
  2. package/README.md +10 -6
  3. package/SECURITY.md +7 -4
  4. package/dist/cli/constants/cli.constants.d.ts +2 -0
  5. package/dist/cli/constants/cli.constants.js +3 -1
  6. package/dist/cli/doctor.js +13 -2
  7. package/dist/cli/setup.js +138 -29
  8. package/dist/cli/toggle.js +5 -1
  9. package/dist/cli/types/cli.types.d.ts +6 -0
  10. package/dist/cli/uninstall.js +1 -1
  11. package/dist/cli.js +14 -3
  12. package/dist/config/config-store.d.ts +1 -1
  13. package/dist/config/config-store.js +2 -2
  14. package/dist/config/constants/config.constants.d.ts +4 -1
  15. package/dist/config/constants/config.constants.js +7 -2
  16. package/dist/config/repo-config.js +1 -1
  17. package/dist/config/schemas/config.schema.d.ts +113 -767
  18. package/dist/config/schemas/config.schema.js +17 -8
  19. package/dist/credentials/constants/credentials.constants.d.ts +8 -0
  20. package/dist/credentials/constants/credentials.constants.js +9 -1
  21. package/dist/credentials/credential-status.js +8 -4
  22. package/dist/credentials/credentials.d.ts +16 -2
  23. package/dist/credentials/credentials.js +30 -5
  24. package/dist/credentials/device-api.d.ts +10 -1
  25. package/dist/credentials/device-api.js +12 -1
  26. package/dist/credentials/identity.d.ts +12 -1
  27. package/dist/credentials/identity.js +12 -1
  28. package/dist/credentials/migration.d.ts +1 -1
  29. package/dist/credentials/migration.js +1 -1
  30. package/dist/credentials/schemas/device-api.schema.d.ts +4 -51
  31. package/dist/credentials/schemas/device-state.schema.d.ts +3 -38
  32. package/dist/credentials/sign-in.d.ts +14 -1
  33. package/dist/credentials/sign-in.js +24 -5
  34. package/dist/credentials/types/credentials.types.d.ts +12 -1
  35. package/dist/enforcement/decision-client.js +2 -1
  36. package/dist/enforcement/enforcement.js +7 -5
  37. package/dist/enforcement/types/enforcement.types.d.ts +2 -2
  38. package/dist/git/code-state.d.ts +33 -0
  39. package/dist/git/code-state.js +44 -0
  40. package/dist/git/constants/git.constants.d.ts +6 -0
  41. package/dist/git/constants/git.constants.js +6 -0
  42. package/dist/git/index.d.ts +2 -1
  43. package/dist/git/index.js +1 -0
  44. package/dist/git/types/git.types.d.ts +6 -0
  45. package/dist/pipeline/constants/pipeline.constants.d.ts +3 -0
  46. package/dist/pipeline/constants/pipeline.constants.js +3 -0
  47. package/dist/pipeline/hook-pipeline.js +56 -7
  48. package/dist/privacy/command-fingerprint.d.ts +42 -0
  49. package/dist/privacy/command-fingerprint.js +249 -0
  50. package/dist/privacy/constants/command-fingerprint.constants.d.ts +34 -0
  51. package/dist/privacy/constants/command-fingerprint.constants.js +38 -0
  52. package/dist/privacy/index.d.ts +3 -1
  53. package/dist/privacy/index.js +2 -0
  54. package/dist/privacy/product-capture.js +20 -0
  55. package/dist/privacy/types/privacy.types.d.ts +7 -0
  56. package/dist/providers/antigravity/antigravity.adapter.js +3 -0
  57. package/dist/providers/antigravity/schemas/antigravity.schema.d.ts +18 -492
  58. package/dist/providers/claude/claude.adapter.js +12 -1
  59. package/dist/providers/claude/constants/claude.constants.d.ts +6 -0
  60. package/dist/providers/claude/constants/claude.constants.js +6 -0
  61. package/dist/providers/claude/schemas/claude.schema.d.ts +1 -43
  62. package/dist/providers/codex/codex.adapter.js +14 -0
  63. package/dist/providers/codex/codex.otel.d.ts +12 -1
  64. package/dist/providers/codex/codex.otel.js +61 -11
  65. package/dist/providers/codex/constants/codex.otel.constants.d.ts +5 -0
  66. package/dist/providers/codex/constants/codex.otel.constants.js +5 -0
  67. package/dist/providers/codex/schemas/codex.schema.d.ts +1 -41
  68. package/dist/providers/constants/provider.constants.d.ts +8 -0
  69. package/dist/providers/constants/provider.constants.js +8 -0
  70. package/dist/providers/cursor/constants/cursor.constants.d.ts +2 -0
  71. package/dist/providers/cursor/constants/cursor.constants.js +2 -0
  72. package/dist/providers/cursor/cursor.adapter.js +84 -5
  73. package/dist/providers/cursor/schemas/cursor.schema.d.ts +5 -85
  74. package/dist/providers/gemini/constants/gemini.constants.d.ts +2 -0
  75. package/dist/providers/gemini/constants/gemini.constants.js +2 -0
  76. package/dist/providers/gemini/constants/gemini.otel.constants.d.ts +16 -1
  77. package/dist/providers/gemini/constants/gemini.otel.constants.js +16 -1
  78. package/dist/providers/gemini/gemini.detect.d.ts +11 -0
  79. package/dist/providers/gemini/gemini.detect.js +14 -1
  80. package/dist/providers/gemini/gemini.hooks.d.ts +3 -3
  81. package/dist/providers/gemini/gemini.hooks.js +5 -5
  82. package/dist/providers/gemini/gemini.otel.d.ts +14 -4
  83. package/dist/providers/gemini/gemini.otel.js +418 -107
  84. package/dist/providers/gemini/schemas/gemini.schema.d.ts +1 -49
  85. package/dist/providers/shared/bearer-rewrite.d.ts +19 -0
  86. package/dist/providers/shared/bearer-rewrite.js +46 -0
  87. package/dist/providers/shared/constants/tooling.constants.d.ts +6 -0
  88. package/dist/providers/shared/constants/tooling.constants.js +6 -0
  89. package/dist/providers/shared/event-builder.d.ts +17 -2
  90. package/dist/providers/shared/event-builder.js +43 -3
  91. package/dist/providers/shared/install-record.d.ts +2 -0
  92. package/dist/providers/shared/install-record.js +3 -2
  93. package/dist/providers/shared/tooling.d.ts +35 -0
  94. package/dist/providers/shared/tooling.js +61 -1
  95. package/dist/providers/shared/types/adapter.types.d.ts +18 -0
  96. package/dist/providers/types/provider.types.d.ts +24 -0
  97. package/dist/storage/atomic-file.d.ts +14 -0
  98. package/dist/storage/atomic-file.js +19 -0
  99. package/dist/storage/constants/storage.constants.d.ts +2 -0
  100. package/dist/storage/constants/storage.constants.js +2 -0
  101. package/dist/storage/schemas/storage.schema.d.ts +11 -175
  102. package/dist/storage/schemas/storage.schema.js +7 -1
  103. package/dist/transport/schemas/queue.schema.d.ts +1 -16
  104. package/dist/transport/schemas/queue.schema.js +1 -1
  105. package/dist/turns/constants/turns.constants.d.ts +17 -0
  106. package/dist/turns/constants/turns.constants.js +17 -0
  107. package/dist/turns/index.d.ts +3 -2
  108. package/dist/turns/index.js +1 -0
  109. package/dist/turns/tool-events.d.ts +15 -0
  110. package/dist/turns/tool-events.js +59 -0
  111. package/dist/turns/turn-state.js +2 -2
  112. package/dist/turns/turn-summary.d.ts +1 -1
  113. package/dist/turns/turn-summary.js +1 -0
  114. package/dist/turns/turn-tracker.js +138 -7
  115. package/dist/turns/types/turn-state.types.d.ts +28 -1
  116. package/dist/turns/types/turn-summary.types.d.ts +30 -0
  117. package/dist/turns/types/turn-tracker.types.d.ts +10 -0
  118. package/dist/turns/work-checkout.d.ts +5 -3
  119. package/dist/turns/work-checkout.js +46 -12
  120. package/docs/AUDIT_PROMPT.md +11 -0
  121. package/docs/DATA_HANDLING.md +69 -14
  122. package/docs/ENTERPRISE_DEPLOYMENT.md +21 -5
  123. package/package.json +9 -8
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Names the rules in `tests/fixtures/command-vectors.json`, a byte copy of
3
+ * core's `packages/fingerprint/test/command-vectors.json`. Command digests
4
+ * from different schemes never compare.
5
+ */
6
+ export declare const COMMAND_SCHEME = "agent-watch-command/1";
7
+ /**
8
+ * A check is an allowlisted command that ran this long (workflow SPEC §12.1).
9
+ * The edge decides the flag, since only it holds the duration and the command
10
+ * together; core sees the flag alone.
11
+ */
12
+ export declare const CHECK_MIN_DURATION_MS = 60000;
13
+ /** Bounds the lexer's work on hostile input; core cuts at the same code point. */
14
+ export declare const MAX_COMMAND_CODE_POINTS = 16384;
15
+ /** `npm`, `pnpm` and `yarn` scripts that are checks, alone or as `name:variant` (`test:unit`). */
16
+ export declare const CHECK_SCRIPTS: ReadonlySet<string>;
17
+ export declare const CHECK_PROGRAMS: ReadonlySet<string>;
18
+ export declare const SCRIPT_RUNNERS: ReadonlySet<string>;
19
+ /** `go test`, `cargo test`, `make test`, `make check`: the first argument decides. */
20
+ export declare const SUBCOMMAND_CHECKS: ReadonlyMap<string, ReadonlySet<string>>;
21
+ /** The `npm run` words that name a script as their next argument. */
22
+ export declare const RUN_SCRIPT_WORDS: ReadonlySet<string>;
23
+ /** Inside `"…"`, a backslash escapes only these. */
24
+ export declare const DOUBLE_QUOTE_ESCAPES: ReadonlySet<string>;
25
+ /** Shells whose `-c` / `-lc` script is the command an argv runs. */
26
+ export declare const SHELL_WRAPPERS: ReadonlySet<string>;
27
+ export declare const SHELL_SCRIPT_FLAGS: ReadonlySet<string>;
28
+ export declare const RE_ASSIGNMENT: RegExp;
29
+ export declare const RE_FD_PREFIX: RegExp;
30
+ export declare const RE_PYTHON: RegExp;
31
+ /** What may follow `>&` in a duplication (`2>&1`, `>&-`). */
32
+ export declare const RE_DUPLICATION_CHAR: RegExp;
33
+ /** A script's `:variant` suffix (`test:unit`). */
34
+ export declare const RE_SCRIPT_VARIANT: RegExp;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Names the rules in `tests/fixtures/command-vectors.json`, a byte copy of
3
+ * core's `packages/fingerprint/test/command-vectors.json`. Command digests
4
+ * from different schemes never compare.
5
+ */
6
+ export const COMMAND_SCHEME = 'agent-watch-command/1';
7
+ /**
8
+ * A check is an allowlisted command that ran this long (workflow SPEC §12.1).
9
+ * The edge decides the flag, since only it holds the duration and the command
10
+ * together; core sees the flag alone.
11
+ */
12
+ export const CHECK_MIN_DURATION_MS = 60_000;
13
+ /** Bounds the lexer's work on hostile input; core cuts at the same code point. */
14
+ export const MAX_COMMAND_CODE_POINTS = 16_384;
15
+ /** `npm`, `pnpm` and `yarn` scripts that are checks, alone or as `name:variant` (`test:unit`). */
16
+ export const CHECK_SCRIPTS = new Set(['test', 'verify', 'lint', 'typecheck', 'check', 'build']);
17
+ export const CHECK_PROGRAMS = new Set(['vitest', 'jest', 'tsc', 'pytest', 'pr-tests.sh']);
18
+ export const SCRIPT_RUNNERS = new Set(['npm', 'pnpm', 'yarn']);
19
+ /** `go test`, `cargo test`, `make test`, `make check`: the first argument decides. */
20
+ export const SUBCOMMAND_CHECKS = new Map([
21
+ ['go', new Set(['test'])],
22
+ ['cargo', new Set(['test'])],
23
+ ['make', new Set(['test', 'check'])]
24
+ ]);
25
+ /** The `npm run` words that name a script as their next argument. */
26
+ export const RUN_SCRIPT_WORDS = new Set(['run', 'run-script']);
27
+ /** Inside `"…"`, a backslash escapes only these. */
28
+ export const DOUBLE_QUOTE_ESCAPES = new Set(['"', '\\', '$', '`']);
29
+ /** Shells whose `-c` / `-lc` script is the command an argv runs. */
30
+ export const SHELL_WRAPPERS = new Set(['bash', 'sh', 'zsh']);
31
+ export const SHELL_SCRIPT_FLAGS = new Set(['-c', '-lc']);
32
+ export const RE_ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/;
33
+ export const RE_FD_PREFIX = /^\d+$/;
34
+ export const RE_PYTHON = /^python[0-9.]*$/;
35
+ /** What may follow `>&` in a duplication (`2>&1`, `>&-`). */
36
+ export const RE_DUPLICATION_CHAR = /[0-9-]/;
37
+ /** A script's `:variant` suffix (`test:unit`). */
38
+ export const RE_SCRIPT_VARIANT = /:.*/s;
@@ -2,7 +2,9 @@
2
2
  * The last gate before anything leaves the machine: known credential shapes
3
3
  * are removed from every outgoing value, whatever the capture settings.
4
4
  */
5
- export type { SecretPattern } from './types/privacy.types.js';
5
+ export type { CommandFingerprint, SecretPattern } from './types/privacy.types.js';
6
6
  export { REDACTED, SECRET_PATTERNS, SENSITIVE_KEY_PATTERN } from './constants/privacy.constants.js';
7
7
  export { sanitizeText, sanitizeValue } from './sanitizer.js';
8
8
  export { applyProductCapture } from './product-capture.js';
9
+ export { CHECK_MIN_DURATION_MS, COMMAND_SCHEME } from './constants/command-fingerprint.constants.js';
10
+ export { checkSegment, commandFingerprint, commandText, normaliseCommand } from './command-fingerprint.js';
@@ -1,3 +1,5 @@
1
1
  export { REDACTED, SECRET_PATTERNS, SENSITIVE_KEY_PATTERN } from './constants/privacy.constants.js';
2
2
  export { sanitizeText, sanitizeValue } from './sanitizer.js';
3
3
  export { applyProductCapture } from './product-capture.js';
4
+ export { CHECK_MIN_DURATION_MS, COMMAND_SCHEME } from './constants/command-fingerprint.constants.js';
5
+ export { checkSegment, commandFingerprint, commandText, normaliseCommand } from './command-fingerprint.js';
@@ -1,3 +1,4 @@
1
+ import { foldMcpName, foldMcpNames } from '../providers/shared/tooling.js';
1
2
  import { sanitizeValue } from './sanitizer.js';
2
3
  /**
3
4
  * Reapply current capture policy to persisted records before queueing or sending.
@@ -35,6 +36,7 @@ export function applyProductCapture(event, capture) {
35
36
  return sanitizeValue({
36
37
  ...event,
37
38
  prompt: undefined,
39
+ tools_used: capture?.mcpNames === false ? foldMcpNames(summary.tools_used) : summary.tools_used,
38
40
  response: undefined,
39
41
  prompt_text: capture?.promptText === true ? summary.prompt_text : undefined,
40
42
  tool_inputs: capture?.toolInput === true ? summary.tool_inputs : undefined,
@@ -47,6 +49,10 @@ export function applyProductCapture(event, capture) {
47
49
  prompt_jira_ids: git ? undefined : summary.prompt_jira_ids,
48
50
  work_evidence: git ? undefined : summary.work_evidence,
49
51
  parent_session_id: git ? undefined : summary.parent_session_id,
52
+ // Content-free (ids, times, outcome, digests), but on by default with git
53
+ // context and withheld whole without it: a digest of a command still says
54
+ // which command ran when.
55
+ tool_events: git ? undefined : withMcpPolicy(summary.tool_events, capture?.mcpNames === false),
50
56
  content_hashes: files ? undefined : summary.content_hashes,
51
57
  manifest_repository: files ? undefined : summary.manifest_repository,
52
58
  files_changed: files ? undefined : summary.files_changed,
@@ -56,6 +62,20 @@ export function applyProductCapture(event, capture) {
56
62
  external_files_read: files ? undefined : summary.external_files_read
57
63
  });
58
64
  }
65
+ /**
66
+ * Tool events with MCP names folded as `tools_used` folds them, when the
67
+ * policy withholds them: one name per call would otherwise say what the
68
+ * counts were folded to hide.
69
+ *
70
+ * @param events - The summary's tool events, if any.
71
+ * @param fold - Whether `capture.mcpNames` is off.
72
+ * @returns The events, folded when asked.
73
+ */
74
+ function withMcpPolicy(events, fold) {
75
+ if (!fold || events === undefined)
76
+ return events;
77
+ return events.map((event) => ({ ...event, tool: foldMcpName(event.tool) }));
78
+ }
59
79
  /**
60
80
  * A snapshot with no commit file names, for a policy that withholds paths.
61
81
  *
@@ -11,3 +11,10 @@ export interface SecretPattern {
11
11
  */
12
12
  readonly replacement?: string;
13
13
  }
14
+ /** What the edge sends for one shell call. Never the command itself. */
15
+ export interface CommandFingerprint {
16
+ /** sha256 hex of the check segment when there is one, else of the whole normalised command; null when nothing is left. */
17
+ readonly digest: string | null;
18
+ /** A segment is on the check allowlist. A check also needs `CHECK_MIN_DURATION_MS`. */
19
+ readonly matchesCheck: boolean;
20
+ }
@@ -187,6 +187,9 @@ function antigravityToolPatch(payload, hook, context) {
187
187
  status: toolStatus(hook, failed),
188
188
  kind,
189
189
  input: toolCall?.args,
190
+ // Unique within an execution, which is the turn: it pairs the two hooks
191
+ // of one call, and is never sent as the call's id.
192
+ pairingKey: stepIdxOf(payload, hook),
190
193
  output: hook === 'PostToolUse' ? payload.postToolHookArgs?.result : undefined,
191
194
  error: failed ? payload.postToolHookArgs?.error : undefined,
192
195
  providerFields: mcp ? { mcpServer: mcp.server, mcpTool: mcp.tool } : undefined