@xtrom-ai/sdk 0.0.0-stage → 0.7.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 (53) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +185 -2
  3. package/dist/allowances.js +74 -0
  4. package/dist/cli.js +268 -0
  5. package/dist/credentials.js +37 -0
  6. package/dist/directive.js +57 -0
  7. package/dist/enforce.js +972 -0
  8. package/dist/index.js +31 -0
  9. package/dist/inspect.js +135 -0
  10. package/dist/local/agents.js +378 -0
  11. package/dist/local/appliers.js +61 -0
  12. package/dist/local/browser.js +135 -0
  13. package/dist/local/discover.js +154 -0
  14. package/dist/local/hook.js +778 -0
  15. package/dist/local/install.js +238 -0
  16. package/dist/local/inventory.js +219 -0
  17. package/dist/local/reasonText.js +29 -0
  18. package/dist/local/shipper.js +251 -0
  19. package/dist/local/spool.js +178 -0
  20. package/dist/local/updateKeys.js +3 -0
  21. package/dist/local/updater.js +224 -0
  22. package/dist/local/view.js +110 -0
  23. package/dist/memory.js +172 -0
  24. package/dist/reporter.js +336 -0
  25. package/dist/session.js +439 -0
  26. package/dist/version.js +2 -0
  27. package/dist/workspace.js +72 -0
  28. package/package.json +23 -4
  29. package/src/allowances.ts +74 -0
  30. package/src/cli.ts +268 -0
  31. package/src/credentials.ts +37 -0
  32. package/src/directive.ts +57 -0
  33. package/src/enforce.ts +972 -0
  34. package/src/index.ts +31 -0
  35. package/src/inspect.ts +135 -0
  36. package/src/local/agents.ts +378 -0
  37. package/src/local/appliers.ts +61 -0
  38. package/src/local/browser.ts +135 -0
  39. package/src/local/discover.ts +154 -0
  40. package/src/local/hook.ts +778 -0
  41. package/src/local/install.ts +238 -0
  42. package/src/local/inventory.ts +219 -0
  43. package/src/local/reasonText.ts +29 -0
  44. package/src/local/shipper.ts +251 -0
  45. package/src/local/spool.ts +178 -0
  46. package/src/local/updateKeys.ts +3 -0
  47. package/src/local/updater.ts +224 -0
  48. package/src/local/view.ts +110 -0
  49. package/src/memory.ts +172 -0
  50. package/src/reporter.ts +336 -0
  51. package/src/session.ts +439 -0
  52. package/src/version.ts +2 -0
  53. package/src/workspace.ts +72 -0
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works.
111
+
112
+ You may add Your own copyright statement to Your modifications and
113
+ may provide additional or different license terms and conditions
114
+ for use, reproduction, or distribution of Your modifications, or
115
+ for any such Derivative Works as a whole, provided Your use,
116
+ reproduction, and distribution of the Work otherwise complies with
117
+ the conditions stated in this License.
118
+
119
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
120
+ any Contribution intentionally submitted for inclusion in the Work
121
+ by You to the Licensor shall be under the terms and conditions of
122
+ this License, without any additional terms or conditions.
123
+ Notwithstanding the above, nothing herein shall supersede or modify
124
+ the terms of any separate license agreement you may have executed
125
+ with Licensor regarding such Contributions.
126
+
127
+ 6. Trademarks. This License does not grant permission to use the trade
128
+ names, trademarks, service marks, or product names of the Licensor,
129
+ except as required for reasonable and customary use in describing the
130
+ origin of the Work and reproducing the content of the NOTICE file.
131
+
132
+ 7. Disclaimer of Warranty. Unless required by applicable law or
133
+ agreed to in writing, Licensor provides the Work (and each
134
+ Contributor provides its Contributions) on an "AS IS" BASIS,
135
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
136
+ implied, including, without limitation, any warranties or conditions
137
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
138
+ PARTICULAR PURPOSE. You are solely responsible for determining the
139
+ appropriateness of using or redistributing the Work and assume any
140
+ risks associated with Your exercise of permissions under this License.
141
+
142
+ 8. Limitation of Liability. In no event and under no legal theory,
143
+ whether in tort (including negligence), contract, or otherwise,
144
+ unless required by applicable law (such as deliberate and grossly
145
+ negligent acts) or agreed to in writing, shall any Contributor be
146
+ liable to You for damages, including any direct, indirect, special,
147
+ incidental, or consequential damages of any character arising as a
148
+ result of this License or out of the use or inability to use the
149
+ Work (including but not limited to damages for loss of goodwill,
150
+ work stoppage, computer failure or malfunction, or any and all
151
+ other commercial damages or losses), even if such Contributor
152
+ has been advised of the possibility of such damages.
153
+
154
+ 9. Accepting Warranty or Additional Liability. While redistributing
155
+ the Work or Derivative Works thereof, You may choose to offer,
156
+ and charge a fee for, acceptance of support, warranty, indemnity,
157
+ or other liability obligations and/or rights consistent with this
158
+ License. However, in accepting such obligations, You may act only
159
+ on Your own behalf and on Your sole responsibility, not on behalf
160
+ of any other Contributor, and only if You agree to indemnify,
161
+ defend, and hold each Contributor harmless for any liability
162
+ incurred by, or claims asserted against, such Contributor by reason
163
+ of your accepting any such warranty or additional liability.
164
+
165
+ END OF TERMS AND CONDITIONS
166
+
167
+ APPENDIX: How to apply the Apache License to your work.
168
+
169
+ To apply the Apache License to your work, attach the following
170
+ boilerplate notice, with the fields enclosed by brackets "[]"
171
+ replaced with your own identifying information. (Don't include
172
+ the brackets!) The text should be enclosed in the appropriate
173
+ comment syntax for the file format. We also recommend that a
174
+ file or class name and description of purpose be included on the
175
+ same "printed page" as the copyright notice for easier
176
+ identification within third-party archives.
177
+
178
+ Copyright 2026 Xtrom
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,186 @@
1
- # Temporary Holding Version
1
+ # @xtrom-ai/sdk (TypeScript)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Deterministic runtime enforcement for **JS/TS and MCP** AI agents, plus a one-command
4
+ hook for **coding agents**: Claude Code, GitHub Copilot CLI, Cursor, OpenAI Codex CLI, Gemini CLI
5
+ and Windsurf. The SDK implements the scoped TypeScript enforcement surface documented in docs/reference/GUARANTEES.md, including known parity limits.
6
+ Every guarded tool call is adjudicated by taint/IFC and policy, with optional fused detection
7
+ risk, and fails closed. Zero runtime dependencies.
8
+
9
+ ## Protect your local coding agent
10
+
11
+ No account needed: decisions are made on this machine and nothing is sent anywhere.
12
+
13
+ ```bash
14
+ npx xtrom install # every coding agent found on this machine, user scope
15
+ npx xtrom install --agent cursor,codex # or pick: claude (claude-code), copilot, cursor, codex, gemini, windsurf, all
16
+ npx xtrom install --project # this repo only
17
+ npx xtrom install --monitor # observe first: audit only, never prompt
18
+ npx xtrom log # what Xtrom stopped (--all for everything, --since 2h, --json)
19
+ npx xtrom status # what's protected (--json for scripts)
20
+ npx xtrom connect --url https://api.xtrom.ai --token-stdin # optional: report to your team's console (--off stops)
21
+ npx xtrom discover | uninstall
22
+ ```
23
+
24
+ `xtrom` is the short name for `@xtrom-ai/sdk` at the same version. Air-gapped or pinned installs use the tarball
25
+ your console serves (**Govern › Connect**, `/pkgs/npm/`, verified with `SHA256SUMS`; see `SUPPLY-CHAIN.md`).
26
+
27
+ | Agent | `--agent` | Hook config (user · `--project`) | "ask" verdict |
28
+ |---|---|---|---|
29
+ | Claude Code | `claude` | `~/.claude/settings.json` · `.claude/settings.json` | asks you |
30
+ | GitHub Copilot CLI | `copilot` | `~/.copilot/hooks/xtrom.json` · `.github/hooks/xtrom.json` | asks you |
31
+ | Cursor | `cursor` | `~/.cursor/hooks.json` · `.cursor/hooks.json` | blocked¹ |
32
+ | OpenAI Codex CLI | `codex` | `~/.codex/hooks.json` · `.codex/hooks.json` | blocked¹ |
33
+ | Gemini CLI | `gemini` | `~/.gemini/settings.json` · `.gemini/settings.json` | blocked¹ |
34
+ | Windsurf | `windsurf` | `~/.codeium/windsurf/hooks.json` · `.devin/hooks.json` | blocked¹ |
35
+
36
+ ¹ These agents' hooks can't pause for a human, so Xtrom fails closed: the call is blocked and the
37
+ reason tells you to run it yourself in a terminal if you meant it. Codex asks you to trust new
38
+ hooks once: open Codex and approve Xtrom in `/hooks`. Windsurf has no web-fetch hook, so its
39
+ untrusted-input signal comes from MCP tools and `curl`/`gh` output.
40
+
41
+ `install` copies the runtime to `~/.xtrom/local/runtime/` and checks that it starts before
42
+ touching any agent's config. A hook that can't start would make most agents fail open, so a broken
43
+ copy is never installed. Each agent points at a small `/bin/sh` launcher. If node later
44
+ disappears (for example after an nvm upgrade) or the hook crashes, the launcher exits 2, which
45
+ every supported agent treats as a block: the call is stopped with the reason, never run unchecked.
46
+ To fix it, re-run `install` from a terminal, or run `uninstall`. `status` says "broken" (`status --json`: `runtime_ok`) per
47
+ agent.
48
+
49
+ | Situation | Verdict |
50
+ |---|---|
51
+ | Sending `~/.ssh/id_rsa`, `~/.aws/credentials` or an API key off the machine | **deny** |
52
+ | Writing to `~/.xtrom` (Xtrom's own config, state, runtime) | **deny** |
53
+ | Changing any coding agent's hook or permission settings | **ask** |
54
+ | After untrusted input (WebFetch, WebSearch, any MCP tool, `curl`/`gh` output): `git push`, `rm -rf`, MCP writes, and any shell command that isn't recognised local dev work (`python -c`, `aws`, `npm publish`, `/usr/bin/curl`, `$(…)`) | **ask** |
55
+ | Edits, tests, builds, `git status`/`diff`/`commit`, `ls`, reads | allowed silently |
56
+
57
+ How it behaves:
58
+ - **Fails safe.** Unreadable state or a hook crash on a sink tool → ask.
59
+ - **Audit stays local.** The log is `~/.xtrom/local/audit.jsonl` (mode 0600). It records the
60
+ verdict, reason code and owner, never tool input.
61
+ - **Optional reporting.** `install --url … --token …` stores the credentials in
62
+ `~/.xtrom/local/config.json` (mode 0600). The agent is denied access to that directory. Don't
63
+ export the token in your shell profile: every command the agent runs can read it there. Only
64
+ `https://` is accepted, except for `localhost`. The events sent to your console are
65
+ metadata only.
66
+ - **Delivery is decoupled from the short-lived hook.** Each event is written to a local spool, and a
67
+ single **detached background shipper** process delivers it with retry/backoff — so a tool call is
68
+ never slowed or blocked by the network, and an undelivered event survives the hook exiting (durable
69
+ spool, redelivered on the next run). The shipper also emits a liveness **heartbeat**, so the
70
+ console's Enforcement-health view shows the agent as live rather than silent. Windows-safe: the
71
+ shipper is spawned detached (no console window) and outlives the agent that started it.
72
+ - **Updating (one-time refresh, then self-updating).** An already-installed agent keeps its current
73
+ version until refreshed **once** — `npx -y <console>/pkgs/npm/xtrom-sdk-<ver>.tgz install`. After
74
+ that, signed updates self-apply per your console policy (approve/auto), no manual command. (The
75
+ first update can't self-deliver: an old agent lacks the background shipper that applies updates.)
76
+ - **Shared format with the Python hook** (`xtrom install` from the Python wheel). State, config
77
+ and audit are the same, so either one honours taint the other recorded. Install only one of them.
78
+ - **Survives npx cache cleanup.** The runtime is copied to `~/.xtrom/local/runtime/`.
79
+ - **Clean uninstall.** Hook entries carry a `--managed-by` marker, so `uninstall` removes only
80
+ Xtrom's entries. Shared config files are backed up each time; Copilot's `xtrom.json` is Xtrom's
81
+ alone and is deleted when empty.
82
+
83
+ **Browser agents.** Browser automation runs through the Playwright, Puppeteer, Chrome DevTools,
84
+ Browserbase/Stagehand and Claude in Chrome MCP servers, and Anthropic's `computer` tool. Every page
85
+ the agent reads, including screenshots, marks the session untrusted. Xtrom then gates the moments
86
+ that have consequences, not every click:
87
+
88
+ | Browser action | Clean session | After untrusted content |
89
+ |---|---|---|
90
+ | Snapshot, screenshot, scroll, hover, typing into a field, ordinary clicks | allowed | allowed |
91
+ | Submit: `submit`/Enter, accepting a dialog, clicking Send/Pay/Delete/Sign in…, the first click after typing | allowed | **ask** |
92
+ | Navigate to a URL | allowed | **ask** |
93
+ | Run script in the page (`evaluate`, `run_code`), install extensions, mock routes; upload files | allowed | **ask** |
94
+ | Read or change cookies, localStorage or sessionStorage (including via script) | **ask** | **ask** |
95
+ | Type a secret (API key, token) into a page | **ask** | **deny** |
96
+ | Navigate to a URL carrying a secret; upload a credential file (`~/.ssh/id_rsa`, `.env`) | **deny** | **deny** |
97
+
98
+ The click-after-typing rule exists because a button's label is whatever the page or the model calls
99
+ it. Once data has been entered, the next click may be the one that sends it.
100
+
101
+ **What it is, and isn't.** This is a guardrail inside your coding agent, not a sandbox. It sees each
102
+ tool call the agent reports to its hooks and judges it from the command text. Known limits:
103
+ - In a session that hasn't read untrusted content, ordinary shell commands run without a prompt.
104
+ The hook assumes the agent's own instructions came from you.
105
+ - `npm test`, `make` and `npm run` stay silent after untrusted input, but they run code the agent
106
+ may have edited.
107
+ - A command's text isn't its behaviour. After untrusted input, anything not on the local-dev
108
+ allowlist asks you; a cleverly disguised command can still look harmless to you.
109
+
110
+ For real isolation, pair it with your agent's sandboxing and permission rules.
111
+
112
+ ## Wrap your agent's tools
113
+
114
+ ```bash
115
+ npm install @xtrom-ai/sdk # Node ≥ 20. Air-gapped: https://console.xtrom.ai/pkgs/npm/xtrom-sdk-latest.tgz
116
+ ```
117
+
118
+ ```ts
119
+ import { Session } from "@xtrom-ai/sdk";
120
+
121
+ const s = new Session("svc-support-agent", {
122
+ mode: "enforce", // or "monitor" to observe first
123
+ onStepUp: async (d) => askHuman(d), // approve/deny STEP_UP decisions
124
+ owner: "alice@corp.example", // or XTROM_OWNER; never guessed from the OS
125
+ controlPlaneUrl: process.env.XTROM_CONTROL_PLANE_URL, token: process.env.XTROM_TOKEN,
126
+ });
127
+
128
+ const readPage = s.guard("http_fetch", async ({ url }) => (await fetch(url)).text(),
129
+ { source: true, origin: "web" }); // output is UNTRUSTED
130
+ const sendEmail = s.guard("send_email", async ({ to, body }) => mailer.send(to, body));
131
+
132
+ await readPage({ url }); // ingests untrusted content
133
+ await sendEmail({ to, body: pageText }); // → BlockedError (L3:taint/IFC)
134
+ await sendEmail({ to, body: "summary…" }); // → StepUpRequired (session/context taint)
135
+ new Session("svc"); // a genuinely fresh conversation: a new Session (newTask() keeps taint)
136
+ ```
137
+
138
+ **Signed workspace mode.** By default the SDK takes the workspace's monitor switch from the control plane's
139
+ response over TLS. Set `XTROM_POLICY_VERIFY_KEY` (the PEM from `GET /v1/signing-keys`, or a path to it) and
140
+ `XTROM_TENANT` to honour monitor only from a directive signed with that key, for that workspace, and no
141
+ older than the last one accepted; anything else means enforce.
142
+
143
+ ## What the engine guarantees
144
+ - **Untrusted data can't drive a sink.** Any non-read-only action counts as a sink. Unlabeled
145
+ args count as untrusted.
146
+ - **Secrets can't leave.** Egress to a non-allowlisted host is blocked. Other durable sinks
147
+ (git, transfers, KMS) ask for approval.
148
+ - **Session (context) taint.** After untrusted ingress, sink calls need approval even when the
149
+ model paraphrased the content. Tool results that carry `instruction`, `hidden_unicode`, `secret`
150
+ or `truncated` flags taint the session; `truncated` means the output exceeded the 256 KiB scan
151
+ budget, so the next sink asks instead of treating padding as safe.
152
+ - **Encoding-resistant registered-secret matching.** Registered/fingerprinted secrets are matched
153
+ in common one-step forms — base64 and URL-safe base64 (with or without padding), hex,
154
+ percent-encoding and reversed strings. Split/chunked secrets are still not caught.
155
+ - **Least-privilege scope.** Destructive actions in prod and high-value transfers step up.
156
+ - **Fusion.** A detector's risk score can only escalate a decision, never relax one.
157
+ - **Fail-closed.** Any adjudication error BLOCKs (`L0:fail-closed`).
158
+ - **Signals v2.** Each decision carries a sink class, coarse taint origins and latency, plus what it
159
+ targeted as categories: `dest_class`, `dest_fp` / `dest_root_fp` (a truncated sha256 of the
160
+ destination host and its root, so the control plane can match known exfiltration services),
161
+ `dest_count`, `path_class` and `arg_bytes`. It is metadata only: argument values, destinations and
162
+ paths never leave the process. Pinned against the Python engine by `xtrom-engine/target_golden.json`.
163
+
164
+ ## Parity and tests
165
+ ```bash
166
+ npm test # node --test test/*.test.ts (native TS, zero deps)
167
+ npm run build
168
+ ```
169
+ `test/parity.test.ts` replays the shared golden vectors, the same ones the Python, Go and Rust
170
+ engines are gated on. It then runs a seeded differential fuzz against the Python engine,
171
+ comparing verdict, reason code, layer and signals and covering every reason code. Raise the volume
172
+ with `XTROM_FUZZ_N=20000 XTROM_FUZZ_SEED=7 npm test`. `test/local.test.ts` checks the hook's
173
+ decisions against the Python hook, and `test/agents.test.ts` checks every agent adapter's payload
174
+ mapping and output protocol against the Python adapters.
175
+
176
+ ## Version handshake
177
+ `xtromHeaders()` returns `X-Xtrom-API-Version`, `X-Xtrom-SDK-Version` and `X-Xtrom-SDK-Lang`.
178
+ An unknown API version gets a 400 before auth, so misconfigured clients fail loudly.
179
+
180
+ ## Not yet
181
+ The Python engine's local WORM audit file is not ported; in TS the hook's local audit and the reporter
182
+ cover that role.
183
+
184
+ Strict-ingress anti-laundering is available on `Ingress` (the counterpart of Python `Engine.trusted()`):
185
+ `new Ingress().trusted(x, origin)` returns an UNTRUSTED value when `x` is a verbatim copy of something
186
+ the same `Ingress` labeled untrusted. The plain `trusted()` / `untrusted()` functions stay stateless.
@@ -0,0 +1,74 @@
1
+ // Allowances: a human approval for a held call (STEP_UP), scoped so the same kind of call isn't held
2
+ // again (design/APPROVAL-ALLOWANCES.md). Parity with xtrom-engine/xtrom/allowances.py, gated on
3
+ // ../xtrom-engine/allowance_golden.json.
4
+ //
5
+ // Consulted only after the engine returns STEP_UP, never for a BLOCK. Covers the same tool, the same
6
+ // destination and the same or cleaner data, and always expires.
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+ export const COVERABLE = Object.freeze({
35
+ "ifc.untrusted_content_stepup": ["call", "session", "window"],
36
+ "ifc.context_tainted_stepup": ["call", "session", "window"],
37
+ "policy.destructive_prod_stepup": ["call", "session", "window"],
38
+ "policy.transfer_threshold_stepup": ["call"],
39
+ "egress.secret_to_durable_sink": ["call"],
40
+ });
41
+ const DATA_RANK = { clean: 0, context: 1, untrusted: 2 };
42
+ const SCOPE_ORDER = { call: 0, session: 1, window: 2 };
43
+ export const APPROVAL_REASON_CODE = "approval.allowance";
44
+ export const APPROVAL_LAYER = "L4:approval";
45
+
46
+ export function dataCondition(h ) {
47
+ if (h.tainted) return "untrusted";
48
+ if (h.context_tainted) return "context";
49
+ return "clean";
50
+ }
51
+
52
+ /** The live allowance covering `hold`, narrowest scope first, or null. `spent`: call allowances
53
+ * already used locally. `now` is epoch seconds. */
54
+ export function matchAllowance(allowances , hold , now ,
55
+ spent = new Set()) {
56
+ const scopes = COVERABLE[hold.reason_code ?? ""];
57
+ if (!scopes) return null;
58
+ const cond = DATA_RANK[dataCondition(hold)];
59
+ const sorted = [...allowances].sort((a, b) =>
60
+ (SCOPE_ORDER[a.scope] ?? 9) - (SCOPE_ORDER[b.scope] ?? 9) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
61
+ for (const a of sorted) {
62
+ if (a.revoked_at || !(Number(a.expires_at) > now)) continue;
63
+ if (a.action !== hold.action || !scopes.includes(a.scope)) continue;
64
+ if (!(a.data in DATA_RANK) || DATA_RANK[a.data] < cond) continue; // same or cleaner data only
65
+ if (a.scope === "call") {
66
+ if (hold.call_fp && a.call_fp === hold.call_fp && !spent.has(a.id) && (a.uses_left ?? 1) > 0) return a;
67
+ continue;
68
+ }
69
+ if (!a.dest_fp || a.dest_fp !== hold.dest_fp) continue; // a wider scope names a destination
70
+ if (a.scope === "session" && (!a.session_id || a.session_id !== hold.session_id)) continue;
71
+ return a;
72
+ }
73
+ return null;
74
+ }