@humain/humain-code 0.8.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/dist/bundle/chunks/{anthropic-messages-UZB5HJE3.js → anthropic-messages-XFCDMGD6.js} +4 -4
- package/dist/bundle/chunks/{azure-openai-responses-J3LCMWPQ.js → azure-openai-responses-F4KQM3NK.js} +3 -3
- package/dist/bundle/chunks/{chunk-7EONJCBE.js → chunk-2JNJJ6SZ.js} +1 -1
- package/dist/bundle/chunks/{chunk-3CGMVKHA.js → chunk-3E37CJCE.js} +1 -1
- package/dist/bundle/chunks/{chunk-SQ7NTRLJ.js → chunk-3PJ7NPWN.js} +20 -17
- package/dist/bundle/chunks/{chunk-WRYGY5XG.js → chunk-4MKATHT2.js} +1 -1
- package/dist/bundle/chunks/{chunk-ATFZAFMS.js → chunk-65FLSKDA.js} +1 -1
- package/dist/bundle/chunks/{chunk-P2Y2H7SD.js → chunk-6JTCRCNF.js} +2 -2
- package/dist/bundle/chunks/{chunk-CET2MXXN.js → chunk-6P6MMQUH.js} +1 -1
- package/dist/bundle/chunks/{chunk-APNPBT7Y.js → chunk-BRSLXHED.js} +1 -1
- package/dist/bundle/chunks/{chunk-KONLZKPL.js → chunk-E4VUW4RI.js} +1 -1
- package/dist/bundle/chunks/{chunk-R3VDXQW2.js → chunk-EFY2QPVP.js} +6 -6
- package/dist/bundle/chunks/{chunk-4EV7CK26.js → chunk-F2H47FRF.js} +1 -1
- package/dist/bundle/chunks/{chunk-KQXXBQ57.js → chunk-G2QMON4O.js} +382 -331
- package/dist/bundle/chunks/{chunk-TYN46EVI.js → chunk-GPLWWO5Q.js} +1 -1
- package/dist/bundle/chunks/{chunk-JV7VHOAY.js → chunk-H2B3WLIM.js} +2 -2
- package/dist/bundle/chunks/chunk-H7UPU2SH.js +2093 -0
- package/dist/bundle/chunks/{chunk-NNWNIBLG.js → chunk-JKX5EGOT.js} +1 -1
- package/dist/bundle/chunks/{chunk-4SFWYKL5.js → chunk-JQBZUFH7.js} +467 -440
- package/dist/bundle/chunks/{chunk-D3KYOSQY.js → chunk-JSHKS7VH.js} +1 -1
- package/dist/bundle/chunks/{chunk-C4DHVDYT.js → chunk-JX6YIPNK.js} +1 -1
- package/dist/bundle/chunks/{chunk-Z5UFSRO4.js → chunk-KI7CHPWC.js} +1 -1
- package/dist/bundle/chunks/{chunk-VKQNYZUA.js → chunk-KRBELWQH.js} +1 -1
- package/dist/bundle/chunks/{chunk-AI7EHDAX.js → chunk-LSRXA7OS.js} +1 -1
- package/dist/bundle/chunks/{chunk-WBSGWISD.js → chunk-M5TVWJ5T.js} +5 -4
- package/dist/bundle/chunks/{chunk-XVIQYONJ.js → chunk-MIAXMK5F.js} +1 -1
- package/dist/bundle/chunks/{chunk-WGXMYMPE.js → chunk-PFBAIRCY.js} +2 -2
- package/dist/bundle/chunks/{chunk-CU6KU7JK.js → chunk-PJXBU6CR.js} +47 -44
- package/dist/bundle/chunks/{chunk-OVDMYBIT.js → chunk-PWFM6AQQ.js} +1 -1
- package/dist/bundle/chunks/{chunk-PGVDL4KB.js → chunk-QFDZEUFU.js} +2 -2
- package/dist/bundle/chunks/{chunk-DD5UT56Y.js → chunk-R2KD2HFT.js} +67 -66
- package/dist/bundle/chunks/{chunk-EMBIUIQ2.js → chunk-T2ZGMEMV.js} +46 -45
- package/dist/bundle/chunks/{chunk-IOLLZXQN.js → chunk-U4EAJPMO.js} +138 -126
- package/dist/bundle/chunks/chunk-UZOIHLNU.js +23 -0
- package/dist/bundle/chunks/{chunk-QRYDGY5I.js → chunk-ZSWU5KKA.js} +1 -1
- package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-ETKC6B2S.js → cloudflare-workers-ai-system-one-JEZVYITT.js} +1 -1
- package/dist/bundle/chunks/{compat-HS4ARZK3.js → compat-ELBUCH6U.js} +6 -6
- package/dist/bundle/chunks/{curator-server-TC7RVVN2.js → curator-server-QB4GITGS.js} +1 -1
- package/dist/bundle/chunks/{dist-NMEXYUP3.js → dist-CBODG4CA.js} +5 -5
- package/dist/bundle/chunks/{dist-5AQPJ2TI.js → dist-NERIS6SW.js} +1 -1
- package/dist/bundle/chunks/{dist-DYB3AR7C.js → dist-QSYDYE3Y.js} +7 -7
- package/dist/bundle/chunks/{easter-egg-3d-VVUF3C3X.js → easter-egg-3d-VZC5WOYV.js} +1 -1
- package/dist/bundle/chunks/{execute-I3WGGPWL.js → execute-6MEJJF2T.js} +2 -2
- package/dist/bundle/chunks/{extract-QHZTEVJP.js → extract-L373D6O7.js} +2 -2
- package/dist/bundle/chunks/{flow-implementer-QMN3HKE2.js → flow-implementer-3P3BHQ7E.js} +4 -4
- package/dist/bundle/chunks/github-copilot.js +53 -56
- package/dist/bundle/chunks/{google-generative-ai-ZND73WDQ.js → google-generative-ai-WIASMWS3.js} +2 -2
- package/dist/bundle/chunks/{google-vertex-YAH62YRM.js → google-vertex-WSPHRZIZ.js} +3 -3
- package/dist/bundle/chunks/{host-Q565BCXB.js → host-WOLZCWQQ.js} +1 -1
- package/dist/bundle/chunks/{inprocess-453SLFL5.js → inprocess-3PDJKE5F.js} +5 -5
- package/dist/bundle/chunks/interactive-mode-SDUO5OLD.js +5 -0
- package/dist/bundle/chunks/{llama-cpp-classify-Z4GZY4GC.js → llama-cpp-classify-KYZT532X.js} +1 -1
- package/dist/bundle/chunks/{mistral-conversations-7I5JURDP.js → mistral-conversations-7JYDDRUT.js} +2 -2
- package/dist/bundle/chunks/{node-IMSYVRPL.js → node-N7TPBUJB.js} +1 -1
- package/dist/bundle/chunks/{openai-codex-responses-LTHOMN37.js → openai-codex-responses-7PAML4NF.js} +3 -3
- package/dist/bundle/chunks/{openai-completions-W2X635EE.js → openai-completions-UJDAIGTK.js} +3 -3
- package/dist/bundle/chunks/{openai-decisions-TN2GNOYI.js → openai-decisions-JMSDGR7K.js} +1 -1
- package/dist/bundle/chunks/{openai-responses-DVY4QXOG.js → openai-responses-2WNCE6AY.js} +3 -3
- package/dist/bundle/chunks/{openrouter-images-SE2JMS44.js → openrouter-images-V3UCCO6X.js} +1 -1
- package/dist/bundle/chunks/{pi-messages-WAS6Z5L5.js → pi-messages-TQ7LJUNQ.js} +2 -2
- package/dist/bundle/chunks/{session-picker-XNVLSJ22.js → session-picker-EYKCMFQR.js} +1 -1
- package/dist/bundle/chunks/{startup-ui-3TCT465D.js → startup-ui-7ODOR34R.js} +2 -2
- package/dist/bundle/chunks/{trace-command-7ORDQ3JS.js → trace-command-VM7FBWPE.js} +4 -4
- package/dist/bundle/chunks/{typesafe-system-one-AAZH6S3I.js → typesafe-system-one-YP7GGN4C.js} +1 -1
- package/dist/bundle/chunks/{virtual-modules-CIVXCEAN.js → virtual-modules-IU5KWB2C.js} +10 -10
- package/dist/bundle/cli-runtime.js +5 -5
- package/dist/bundle/index.js +8 -8
- package/dist/bundle/rpc-entry.js +4 -4
- package/dist/cli/args.js +1 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +16 -1
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/setup.d.ts +1 -1
- package/dist/cli/setup.d.ts.map +1 -1
- package/dist/cli/setup.js +3 -2
- package/dist/cli/setup.js.map +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +3 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +11 -2
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/keybindings.d.ts +24 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +3 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +12 -1
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +13 -9
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +11 -2
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +23 -6
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/oauth-account-pool.d.ts +4 -0
- package/dist/core/oauth-account-pool.d.ts.map +1 -1
- package/dist/core/oauth-account-pool.js +104 -20
- package/dist/core/oauth-account-pool.js.map +1 -1
- package/dist/core/sdk.js +2 -2
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts +4 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +17 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-schema.d.ts +2 -0
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +10 -0
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/extensions/usage/confirmation.d.ts.map +1 -1
- package/dist/extensions/usage/confirmation.js +1 -1
- package/dist/extensions/usage/confirmation.js.map +1 -1
- package/dist/extensions/usage/index.js +6 -6
- package/dist/extensions/usage/index.js.map +1 -1
- package/dist/extensions/usage/panes.d.ts +5 -0
- package/dist/extensions/usage/panes.d.ts.map +1 -0
- package/dist/extensions/usage/panes.js +10 -0
- package/dist/extensions/usage/panes.js.map +1 -0
- package/dist/extensions/usage/popup.d.ts.map +1 -1
- package/dist/extensions/usage/popup.js +9 -18
- package/dist/extensions/usage/popup.js.map +1 -1
- package/dist/humain/gateway/client.d.ts.map +1 -1
- package/dist/humain/gateway/client.js +36 -9
- package/dist/humain/gateway/client.js.map +1 -1
- package/dist/humain/gateway/http.d.ts.map +1 -1
- package/dist/humain/gateway/http.js +26 -6
- package/dist/humain/gateway/http.js.map +1 -1
- package/dist/humain/gateway/provider.d.ts.map +1 -1
- package/dist/humain/gateway/provider.js +9 -2
- package/dist/humain/gateway/provider.js.map +1 -1
- package/dist/humain/hcode/contracts.d.ts +15 -0
- package/dist/humain/hcode/contracts.d.ts.map +1 -1
- package/dist/humain/hcode/contracts.js +85 -10
- package/dist/humain/hcode/contracts.js.map +1 -1
- package/dist/humain/hcode/environment.d.ts.map +1 -1
- package/dist/humain/hcode/environment.js +4 -2
- package/dist/humain/hcode/environment.js.map +1 -1
- package/dist/humain/hcode/facade.d.ts +12 -1
- package/dist/humain/hcode/facade.d.ts.map +1 -1
- package/dist/humain/hcode/facade.js +35 -8
- package/dist/humain/hcode/facade.js.map +1 -1
- package/dist/humain/hcode/images.d.ts.map +1 -1
- package/dist/humain/hcode/images.js +4 -2
- package/dist/humain/hcode/images.js.map +1 -1
- package/dist/humain/hcode/login-copy.d.ts.map +1 -1
- package/dist/humain/hcode/login-copy.js +11 -1
- package/dist/humain/hcode/login-copy.js.map +1 -1
- package/dist/humain/hcode/notices.d.ts +22 -1
- package/dist/humain/hcode/notices.d.ts.map +1 -1
- package/dist/humain/hcode/notices.js +34 -3
- package/dist/humain/hcode/notices.js.map +1 -1
- package/dist/humain/hcode/provider.d.ts +3 -1
- package/dist/humain/hcode/provider.d.ts.map +1 -1
- package/dist/humain/hcode/provider.js +126 -46
- package/dist/humain/hcode/provider.js.map +1 -1
- package/dist/humain/hcode/run-credential.d.ts +21 -0
- package/dist/humain/hcode/run-credential.d.ts.map +1 -0
- package/dist/humain/hcode/run-credential.js +140 -0
- package/dist/humain/hcode/run-credential.js.map +1 -0
- package/dist/humain/hcode/sandbox.d.ts +6 -0
- package/dist/humain/hcode/sandbox.d.ts.map +1 -0
- package/dist/humain/hcode/sandbox.js +139 -0
- package/dist/humain/hcode/sandbox.js.map +1 -0
- package/dist/humain/hcode/selection.d.ts +7 -2
- package/dist/humain/hcode/selection.d.ts.map +1 -1
- package/dist/humain/hcode/selection.js +29 -5
- package/dist/humain/hcode/selection.js.map +1 -1
- package/dist/humain/hcode/transport.d.ts +3 -2
- package/dist/humain/hcode/transport.d.ts.map +1 -1
- package/dist/humain/hcode/transport.js +22 -7
- package/dist/humain/hcode/transport.js.map +1 -1
- package/dist/humain/remote/broker.d.ts +84 -0
- package/dist/humain/remote/broker.d.ts.map +1 -0
- package/dist/humain/remote/broker.js +427 -0
- package/dist/humain/remote/broker.js.map +1 -0
- package/dist/humain/remote/deny-store.d.ts +12 -0
- package/dist/humain/remote/deny-store.d.ts.map +1 -0
- package/dist/humain/remote/deny-store.js +164 -0
- package/dist/humain/remote/deny-store.js.map +1 -0
- package/dist/humain/remote/enablement.d.ts +5 -0
- package/dist/humain/remote/enablement.d.ts.map +1 -0
- package/dist/humain/remote/enablement.js +8 -0
- package/dist/humain/remote/enablement.js.map +1 -0
- package/dist/humain/remote/environment.d.ts +11 -0
- package/dist/humain/remote/environment.d.ts.map +1 -0
- package/dist/humain/remote/environment.js +19 -0
- package/dist/humain/remote/environment.js.map +1 -0
- package/dist/humain/remote/host-watch.d.ts +21 -0
- package/dist/humain/remote/host-watch.d.ts.map +1 -0
- package/dist/humain/remote/host-watch.js +186 -0
- package/dist/humain/remote/host-watch.js.map +1 -0
- package/dist/humain/remote/ipc-posix.d.ts +5 -0
- package/dist/humain/remote/ipc-posix.d.ts.map +1 -0
- package/dist/humain/remote/ipc-posix.js +29 -0
- package/dist/humain/remote/ipc-posix.js.map +1 -0
- package/dist/humain/remote/ipc-windows.d.ts +3 -0
- package/dist/humain/remote/ipc-windows.d.ts.map +1 -0
- package/dist/humain/remote/ipc-windows.js +5 -0
- package/dist/humain/remote/ipc-windows.js.map +1 -0
- package/dist/humain/remote/ipc.d.ts +10 -0
- package/dist/humain/remote/ipc.d.ts.map +1 -0
- package/dist/humain/remote/ipc.js +19 -0
- package/dist/humain/remote/ipc.js.map +1 -0
- package/dist/humain/remote/protocol.d.ts +43 -0
- package/dist/humain/remote/protocol.d.ts.map +1 -0
- package/dist/humain/remote/protocol.js +76 -0
- package/dist/humain/remote/protocol.js.map +1 -0
- package/dist/humain/remote/relay-socket.d.ts +30 -0
- package/dist/humain/remote/relay-socket.d.ts.map +1 -0
- package/dist/humain/remote/relay-socket.js +137 -0
- package/dist/humain/remote/relay-socket.js.map +1 -0
- package/dist/humain/remote/secure-channel.d.ts +10 -0
- package/dist/humain/remote/secure-channel.d.ts.map +1 -0
- package/dist/humain/remote/secure-channel.js +5 -0
- package/dist/humain/remote/secure-channel.js.map +1 -0
- package/dist/humain/remote/terminal.d.ts +48 -0
- package/dist/humain/remote/terminal.d.ts.map +1 -0
- package/dist/humain/remote/terminal.js +119 -0
- package/dist/humain/remote/terminal.js.map +1 -0
- package/dist/humain/remote/tickets.d.ts +35 -0
- package/dist/humain/remote/tickets.d.ts.map +1 -0
- package/dist/humain/remote/tickets.js +132 -0
- package/dist/humain/remote/tickets.js.map +1 -0
- package/dist/main.d.ts +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +13 -1
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/account-picker.d.ts +31 -0
- package/dist/modes/interactive/components/account-picker.d.ts.map +1 -0
- package/dist/modes/interactive/components/account-picker.js +150 -0
- package/dist/modes/interactive/components/account-picker.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +6 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +26 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts +35 -1
- package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
- package/dist/modes/interactive/components/status-indicator.js +179 -3
- package/dist/modes/interactive/components/status-indicator.js.map +1 -1
- package/dist/modes/interactive/components/working-indicator-engine.d.ts +32 -0
- package/dist/modes/interactive/components/working-indicator-engine.d.ts.map +1 -0
- package/dist/modes/interactive/components/working-indicator-engine.js +112 -0
- package/dist/modes/interactive/components/working-indicator-engine.js.map +1 -0
- package/dist/modes/interactive/fullscreen.d.ts +13 -0
- package/dist/modes/interactive/fullscreen.d.ts.map +1 -0
- package/dist/modes/interactive/fullscreen.js +25 -0
- package/dist/modes/interactive/fullscreen.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +19 -3
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +341 -54
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/oauth-account-format.d.ts +9 -0
- package/dist/modes/interactive/oauth-account-format.d.ts.map +1 -1
- package/dist/modes/interactive/oauth-account-format.js +31 -22
- package/dist/modes/interactive/oauth-account-format.js.map +1 -1
- package/dist/modes/interactive/theme/humain-dark.json +5 -4
- package/dist/modes/interactive/theme/humain-light.json +6 -5
- package/docs/cli.md +1 -1
- package/docs/development.md +7 -0
- package/docs/forge-run-bootstrap.md +46 -0
- package/docs/humain-code.md +2 -2
- package/docs/index.md +2 -1
- package/docs/keybindings.md +10 -0
- package/docs/providers.md +16 -6
- package/docs/quickstart.md +16 -2
- package/docs/settings.md +20 -0
- package/docs/slash-commands.md +4 -2
- package/docs/usage.md +2 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/schemas/keybindings.schema.json +12 -0
- package/schemas/settings.schema.json +29 -0
- package/dist/bundle/chunks/chunk-IXQYPQRQ.js +0 -2079
- package/dist/bundle/chunks/chunk-J5TSAJGC.js +0 -22
- package/dist/bundle/chunks/chunk-YPZPCHNV.js +0 -3
- package/dist/bundle/chunks/interactive-mode-MVZOJ5OU.js +0 -5
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { constants } from "node:fs";
|
|
2
|
+
import { mkdir, open, rename, unlink } from "node:fs/promises";
|
|
3
|
+
import { dirname, isAbsolute, join } from "node:path";
|
|
4
|
+
import { MAX_WATCH_DENIES, opaqueId } from "./broker.js";
|
|
5
|
+
const STATE = "denies.json";
|
|
6
|
+
const NEXT = "denies.next";
|
|
7
|
+
const GUARD = "broker-active";
|
|
8
|
+
const MAX_BYTES = 1024 * 1024;
|
|
9
|
+
/** Local deny metadata only. Use a dedicated directory under a trusted, owner-private install root. */
|
|
10
|
+
export class PosixWatchDenyStore {
|
|
11
|
+
#directory;
|
|
12
|
+
#scope;
|
|
13
|
+
#started = false;
|
|
14
|
+
#failed = false;
|
|
15
|
+
constructor(directory) {
|
|
16
|
+
this.#directory = directory;
|
|
17
|
+
}
|
|
18
|
+
/** For a fresh authoritative installation only. Never use this to repair an existing install. */
|
|
19
|
+
static async provision(directory, scope) {
|
|
20
|
+
const binding = scopeKey(scope);
|
|
21
|
+
checkLocation(directory);
|
|
22
|
+
const parent = await openPrivateDirectory(dirname(directory));
|
|
23
|
+
try {
|
|
24
|
+
await mkdir(directory, { mode: 0o700 });
|
|
25
|
+
const root = await openPrivateDirectory(directory);
|
|
26
|
+
try {
|
|
27
|
+
await createFile(join(directory, STATE), encode(binding, []));
|
|
28
|
+
await root.sync();
|
|
29
|
+
await parent.sync();
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
await root.close();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
await parent.close();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async read(scope) {
|
|
40
|
+
if (this.#started)
|
|
41
|
+
throw new Error("Remote deny store already used");
|
|
42
|
+
this.#started = true;
|
|
43
|
+
checkLocation(this.#directory);
|
|
44
|
+
const binding = scopeKey(scope);
|
|
45
|
+
const dir = await this.#openInstallDirectory();
|
|
46
|
+
try {
|
|
47
|
+
// A crash, ambiguous write, or failed read leaves the guard in place. Never reclaim automatically.
|
|
48
|
+
await createFile(join(this.#directory, GUARD), "");
|
|
49
|
+
await dir.sync();
|
|
50
|
+
const state = await open(join(this.#directory, STATE), constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
51
|
+
try {
|
|
52
|
+
const stat = await state.stat();
|
|
53
|
+
if (!stat.isFile() ||
|
|
54
|
+
stat.nlink !== 1 ||
|
|
55
|
+
stat.uid !== process.getuid?.() ||
|
|
56
|
+
(stat.mode & 0o777) !== 0o600 ||
|
|
57
|
+
stat.size > MAX_BYTES) {
|
|
58
|
+
throw new Error("Remote deny file is not trusted");
|
|
59
|
+
}
|
|
60
|
+
const buffer = Buffer.alloc(stat.size + 1);
|
|
61
|
+
const { bytesRead } = await state.read(buffer, 0, buffer.length, 0);
|
|
62
|
+
if (bytesRead !== stat.size)
|
|
63
|
+
throw new Error("Remote deny file changed during read");
|
|
64
|
+
const data = JSON.parse(buffer.toString("utf8", 0, bytesRead));
|
|
65
|
+
if (!Array.isArray(data) || data.length !== 2 || data[0] !== binding || !validDenies(data[1])) {
|
|
66
|
+
throw new Error("Remote deny file is invalid");
|
|
67
|
+
}
|
|
68
|
+
this.#scope = binding;
|
|
69
|
+
return data[1];
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
await state.close();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
await dir.close();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async save(ids) {
|
|
80
|
+
if (!this.#scope || this.#failed)
|
|
81
|
+
throw new Error("Remote deny store unavailable");
|
|
82
|
+
try {
|
|
83
|
+
const contents = encode(this.#scope, ids);
|
|
84
|
+
const dir = await this.#openInstallDirectory();
|
|
85
|
+
try {
|
|
86
|
+
await createFile(join(this.#directory, NEXT), contents);
|
|
87
|
+
await rename(join(this.#directory, NEXT), join(this.#directory, STATE));
|
|
88
|
+
await dir.sync();
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
await dir.close();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
this.#failed = true;
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async release() {
|
|
100
|
+
if (!this.#scope || this.#failed)
|
|
101
|
+
throw new Error("Remote deny store cannot release restart guard");
|
|
102
|
+
this.#scope = undefined;
|
|
103
|
+
const dir = await this.#openInstallDirectory();
|
|
104
|
+
try {
|
|
105
|
+
await unlink(join(this.#directory, GUARD));
|
|
106
|
+
await dir.sync();
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
await dir.close();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async #openInstallDirectory() {
|
|
113
|
+
const parent = await openPrivateDirectory(dirname(this.#directory));
|
|
114
|
+
await parent.close();
|
|
115
|
+
return openPrivateDirectory(this.#directory);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function checkLocation(directory) {
|
|
119
|
+
if ((process.platform !== "darwin" && process.platform !== "linux") || !isAbsolute(directory)) {
|
|
120
|
+
throw new Error("Remote deny store requires a qualified POSIX location");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function scopeKey({ installId, principal }) {
|
|
124
|
+
if (!opaqueId(installId))
|
|
125
|
+
throw new Error("Remote deny store requires an install binding");
|
|
126
|
+
const { issuer, subject, accountId, tenantId, environment } = principal;
|
|
127
|
+
return JSON.stringify([installId, issuer, subject, accountId, tenantId, environment]);
|
|
128
|
+
}
|
|
129
|
+
async function openPrivateDirectory(path) {
|
|
130
|
+
const dir = await open(path, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
|
|
131
|
+
try {
|
|
132
|
+
const stat = await dir.stat();
|
|
133
|
+
if (!stat.isDirectory() || stat.uid !== process.getuid?.() || (stat.mode & 0o777) !== 0o700) {
|
|
134
|
+
throw new Error("Remote deny directory is not owner-private");
|
|
135
|
+
}
|
|
136
|
+
return dir;
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
await dir.close();
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async function createFile(path, contents) {
|
|
144
|
+
const file = await open(path, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);
|
|
145
|
+
try {
|
|
146
|
+
await file.writeFile(contents, "utf8");
|
|
147
|
+
await file.sync();
|
|
148
|
+
}
|
|
149
|
+
finally {
|
|
150
|
+
await file.close();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function validDenies(ids) {
|
|
154
|
+
return Array.isArray(ids) && ids.length <= MAX_WATCH_DENIES && ids.every(opaqueId);
|
|
155
|
+
}
|
|
156
|
+
function encode(binding, ids) {
|
|
157
|
+
if (!validDenies(ids))
|
|
158
|
+
throw new Error("Remote deny set is invalid");
|
|
159
|
+
const contents = JSON.stringify([binding, ids]);
|
|
160
|
+
if (Buffer.byteLength(contents) > MAX_BYTES)
|
|
161
|
+
throw new Error("Remote deny file exceeds its bound");
|
|
162
|
+
return contents;
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=deny-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deny-store.js","sourceRoot":"","sources":["../../../src/humain/remote/deny-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAA4C,MAAM,aAAa,CAAC;AAEnG,MAAM,KAAK,GAAG,aAAa,CAAC;AAC5B,MAAM,IAAI,GAAG,aAAa,CAAC;AAC3B,MAAM,KAAK,GAAG,eAAe,CAAC;AAC9B,MAAM,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;AAE9B,uGAAuG;AACvG,MAAM,OAAO,mBAAmB;IACtB,UAAU,CAAS;IAC5B,MAAM,CAAU;IAChB,QAAQ,GAAG,KAAK,CAAC;IACjB,OAAO,GAAG,KAAK,CAAC;IAEhB,YAAY,SAAiB;QAC5B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,iGAAiG;IACjG,MAAM,CAAC,KAAK,CA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C,KAAK,CAAC,QAAQ,CAAC,CAAC;AACpF,CAAC;AAED,SAAS,MAAM,CAAC,OAAe,EAAE,GAAsB;IACtD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IACrE,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IAChD,IAAI,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACnG,OAAO,QAAQ,CAAC;AACjB,CAAC","sourcesContent":["import { constants } from \"node:fs\";\nimport { mkdir, open, rename, unlink } from \"node:fs/promises\";\nimport { dirname, isAbsolute, join } from \"node:path\";\nimport { MAX_WATCH_DENIES, opaqueId, type WatchDenyScope, type WatchDenyStore } from \"./broker.ts\";\n\nconst STATE = \"denies.json\";\nconst NEXT = \"denies.next\";\nconst GUARD = \"broker-active\";\nconst MAX_BYTES = 1024 * 1024;\n\n/** Local deny metadata only. Use a dedicated directory under a trusted, owner-private install root. */\nexport class PosixWatchDenyStore implements WatchDenyStore {\n\treadonly #directory: string;\n\t#scope?: string;\n\t#started = false;\n\t#failed = false;\n\n\tconstructor(directory: string) {\n\t\tthis.#directory = directory;\n\t}\n\n\t/** For a fresh authoritative installation only. Never use this to repair an existing install. */\n\tstatic async provision(directory: string, scope: WatchDenyScope): Promise<void> {\n\t\tconst binding = scopeKey(scope);\n\t\tcheckLocation(directory);\n\t\tconst parent = await openPrivateDirectory(dirname(directory));\n\t\ttry {\n\t\t\tawait mkdir(directory, { mode: 0o700 });\n\t\t\tconst root = await openPrivateDirectory(directory);\n\t\t\ttry {\n\t\t\t\tawait createFile(join(directory, STATE), encode(binding, []));\n\t\t\t\tawait root.sync();\n\t\t\t\tawait parent.sync();\n\t\t\t} finally {\n\t\t\t\tawait root.close();\n\t\t\t}\n\t\t} finally {\n\t\t\tawait parent.close();\n\t\t}\n\t}\n\n\tasync read(scope: WatchDenyScope): Promise<readonly string[]> {\n\t\tif (this.#started) throw new Error(\"Remote deny store already used\");\n\t\tthis.#started = true;\n\t\tcheckLocation(this.#directory);\n\t\tconst binding = scopeKey(scope);\n\t\tconst dir = await this.#openInstallDirectory();\n\t\ttry {\n\t\t\t// A crash, ambiguous write, or failed read leaves the guard in place. Never reclaim automatically.\n\t\t\tawait createFile(join(this.#directory, GUARD), \"\");\n\t\t\tawait dir.sync();\n\t\t\tconst state = await open(\n\t\t\t\tjoin(this.#directory, STATE),\n\t\t\t\tconstants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK,\n\t\t\t);\n\t\t\ttry {\n\t\t\t\tconst stat = await state.stat();\n\t\t\t\tif (\n\t\t\t\t\t!stat.isFile() ||\n\t\t\t\t\tstat.nlink !== 1 ||\n\t\t\t\t\tstat.uid !== process.getuid?.() ||\n\t\t\t\t\t(stat.mode & 0o777) !== 0o600 ||\n\t\t\t\t\tstat.size > MAX_BYTES\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error(\"Remote deny file is not trusted\");\n\t\t\t\t}\n\t\t\t\tconst buffer = Buffer.alloc(stat.size + 1);\n\t\t\t\tconst { bytesRead } = await state.read(buffer, 0, buffer.length, 0);\n\t\t\t\tif (bytesRead !== stat.size) throw new Error(\"Remote deny file changed during read\");\n\t\t\t\tconst data: unknown = JSON.parse(buffer.toString(\"utf8\", 0, bytesRead));\n\t\t\t\tif (!Array.isArray(data) || data.length !== 2 || data[0] !== binding || !validDenies(data[1])) {\n\t\t\t\t\tthrow new Error(\"Remote deny file is invalid\");\n\t\t\t\t}\n\t\t\t\tthis.#scope = binding;\n\t\t\t\treturn data[1];\n\t\t\t} finally {\n\t\t\t\tawait state.close();\n\t\t\t}\n\t\t} finally {\n\t\t\tawait dir.close();\n\t\t}\n\t}\n\n\tasync save(ids: readonly string[]): Promise<void> {\n\t\tif (!this.#scope || this.#failed) throw new Error(\"Remote deny store unavailable\");\n\t\ttry {\n\t\t\tconst contents = encode(this.#scope, ids);\n\t\t\tconst dir = await this.#openInstallDirectory();\n\t\t\ttry {\n\t\t\t\tawait createFile(join(this.#directory, NEXT), contents);\n\t\t\t\tawait rename(join(this.#directory, NEXT), join(this.#directory, STATE));\n\t\t\t\tawait dir.sync();\n\t\t\t} finally {\n\t\t\t\tawait dir.close();\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthis.#failed = true;\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync release(): Promise<void> {\n\t\tif (!this.#scope || this.#failed) throw new Error(\"Remote deny store cannot release restart guard\");\n\t\tthis.#scope = undefined;\n\t\tconst dir = await this.#openInstallDirectory();\n\t\ttry {\n\t\t\tawait unlink(join(this.#directory, GUARD));\n\t\t\tawait dir.sync();\n\t\t} finally {\n\t\t\tawait dir.close();\n\t\t}\n\t}\n\n\tasync #openInstallDirectory() {\n\t\tconst parent = await openPrivateDirectory(dirname(this.#directory));\n\t\tawait parent.close();\n\t\treturn openPrivateDirectory(this.#directory);\n\t}\n}\n\nfunction checkLocation(directory: string): void {\n\tif ((process.platform !== \"darwin\" && process.platform !== \"linux\") || !isAbsolute(directory)) {\n\t\tthrow new Error(\"Remote deny store requires a qualified POSIX location\");\n\t}\n}\n\nfunction scopeKey({ installId, principal }: WatchDenyScope): string {\n\tif (!opaqueId(installId)) throw new Error(\"Remote deny store requires an install binding\");\n\tconst { issuer, subject, accountId, tenantId, environment } = principal;\n\treturn JSON.stringify([installId, issuer, subject, accountId, tenantId, environment]);\n}\n\nasync function openPrivateDirectory(path: string) {\n\tconst dir = await open(path, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);\n\ttry {\n\t\tconst stat = await dir.stat();\n\t\tif (!stat.isDirectory() || stat.uid !== process.getuid?.() || (stat.mode & 0o777) !== 0o700) {\n\t\t\tthrow new Error(\"Remote deny directory is not owner-private\");\n\t\t}\n\t\treturn dir;\n\t} catch (error) {\n\t\tawait dir.close();\n\t\tthrow error;\n\t}\n}\n\nasync function createFile(path: string, contents: string): Promise<void> {\n\tconst file = await open(\n\t\tpath,\n\t\tconstants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW,\n\t\t0o600,\n\t);\n\ttry {\n\t\tawait file.writeFile(contents, \"utf8\");\n\t\tawait file.sync();\n\t} finally {\n\t\tawait file.close();\n\t}\n}\n\nfunction validDenies(ids: unknown): ids is readonly string[] {\n\treturn Array.isArray(ids) && ids.length <= MAX_WATCH_DENIES && ids.every(opaqueId);\n}\n\nfunction encode(binding: string, ids: readonly string[]): string {\n\tif (!validDenies(ids)) throw new Error(\"Remote deny set is invalid\");\n\tconst contents = JSON.stringify([binding, ids]);\n\tif (Buffer.byteLength(contents) > MAX_BYTES) throw new Error(\"Remote deny file exceeds its bound\");\n\treturn contents;\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Forge admin Feature flag id; an absent flag defaults to available. */
|
|
2
|
+
export declare const REMOTE_WATCH_FEATURE_FLAG = "remote_watch";
|
|
3
|
+
/** Remote is available unless Forge explicitly disables it; sharing still requires a local command. */
|
|
4
|
+
export declare function isRemoteHostEnabled(featureFlags: Readonly<Record<string, boolean>> | undefined): boolean;
|
|
5
|
+
//# sourceMappingURL=enablement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enablement.d.ts","sourceRoot":"","sources":["../../../src/humain/remote/enablement.ts"],"names":[],"mappings":"AAEA,yEAAyE;AACzE,eAAO,MAAM,yBAAyB,iBAAiB,CAAC;AAExD,uGAAuG;AACvG,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,GAAG,OAAO,CAExG"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Decides Remote availability without starting a host or sharing a session.
|
|
2
|
+
/** Forge admin Feature flag id; an absent flag defaults to available. */
|
|
3
|
+
export const REMOTE_WATCH_FEATURE_FLAG = "remote_watch";
|
|
4
|
+
/** Remote is available unless Forge explicitly disables it; sharing still requires a local command. */
|
|
5
|
+
export function isRemoteHostEnabled(featureFlags) {
|
|
6
|
+
return featureFlags?.[REMOTE_WATCH_FEATURE_FLAG] !== false;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=enablement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enablement.js","sourceRoot":"","sources":["../../../src/humain/remote/enablement.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAE5E,yEAAyE;AACzE,MAAM,CAAC,MAAM,yBAAyB,GAAG,cAAc,CAAC;AAExD,uGAAuG;AACvG,MAAM,UAAU,mBAAmB,CAAC,YAA2D;IAC9F,OAAO,YAAY,EAAE,CAAC,yBAAyB,CAAC,KAAK,KAAK,CAAC;AAC5D,CAAC","sourcesContent":["// Decides Remote availability without starting a host or sharing a session.\n\n/** Forge admin Feature flag id; an absent flag defaults to available. */\nexport const REMOTE_WATCH_FEATURE_FLAG = \"remote_watch\";\n\n/** Remote is available unless Forge explicitly disables it; sharing still requires a local command. */\nexport function isRemoteHostEnabled(featureFlags: Readonly<Record<string, boolean>> | undefined): boolean {\n\treturn featureFlags?.[REMOTE_WATCH_FEATURE_FLAG] !== false;\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type HcodeEnvironment } from "../hcode/environment.ts";
|
|
2
|
+
/** Resolves Remote routes without an independent origin override. */
|
|
3
|
+
export declare function remoteDestinations(environment?: HcodeEnvironment): {
|
|
4
|
+
origin: string;
|
|
5
|
+
watch: string;
|
|
6
|
+
pairings: string;
|
|
7
|
+
tickets: string;
|
|
8
|
+
installChallenges: string;
|
|
9
|
+
relay: string;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=environment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../../src/humain/remote/environment.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,gBAAgB,EAA2B,MAAM,yBAAyB,CAAC;AAEzF,qEAAqE;AACrE,wBAAgB,kBAAkB,CAAC,WAAW,GAAE,gBAA4C;;;;;;;EAa3F"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Derives Remote destinations from the selected built-in HUMAIN Code environment.
|
|
2
|
+
import { resolveHcodeEnvironment } from "../hcode/environment.js";
|
|
3
|
+
/** Resolves Remote routes without an independent origin override. */
|
|
4
|
+
export function remoteDestinations(environment = resolveHcodeEnvironment()) {
|
|
5
|
+
const selected = resolveHcodeEnvironment(environment.id);
|
|
6
|
+
// Trusted composition inputs must still name a built-in destination before Remote credentials can be used.
|
|
7
|
+
if (environment.origin !== selected.origin)
|
|
8
|
+
throw new Error("Remote environment unavailable");
|
|
9
|
+
const { origin } = selected;
|
|
10
|
+
return {
|
|
11
|
+
origin,
|
|
12
|
+
watch: `${origin}/remote`,
|
|
13
|
+
pairings: `${origin}/api/remote/pairings`,
|
|
14
|
+
tickets: `${origin}/api/remote/tickets`,
|
|
15
|
+
installChallenges: `${origin}/api/remote/install-challenges`,
|
|
16
|
+
relay: `wss://${new URL(origin).host}/api/remote/socket`,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../../../src/humain/remote/environment.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,OAAO,EAAyB,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAEzF,qEAAqE;AACrE,MAAM,UAAU,kBAAkB,CAAC,WAAW,GAAqB,uBAAuB,EAAE;IAC3F,MAAM,QAAQ,GAAG,uBAAuB,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IACzD,2GAA2G;IAC3G,IAAI,WAAW,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAC9F,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC;IAC5B,OAAO;QACN,MAAM;QACN,KAAK,EAAE,GAAG,MAAM,SAAS;QACzB,QAAQ,EAAE,GAAG,MAAM,sBAAsB;QACzC,OAAO,EAAE,GAAG,MAAM,qBAAqB;QACvC,iBAAiB,EAAE,GAAG,MAAM,gCAAgC;QAC5D,KAAK,EAAE,SAAS,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,oBAAoB;KACxD,CAAC;AACH,CAAC","sourcesContent":["// Derives Remote destinations from the selected built-in HUMAIN Code environment.\nimport { type HcodeEnvironment, resolveHcodeEnvironment } from \"../hcode/environment.ts\";\n\n/** Resolves Remote routes without an independent origin override. */\nexport function remoteDestinations(environment: HcodeEnvironment = resolveHcodeEnvironment()) {\n\tconst selected = resolveHcodeEnvironment(environment.id);\n\t// Trusted composition inputs must still name a built-in destination before Remote credentials can be used.\n\tif (environment.origin !== selected.origin) throw new Error(\"Remote environment unavailable\");\n\tconst { origin } = selected;\n\treturn {\n\t\torigin,\n\t\twatch: `${origin}/remote`,\n\t\tpairings: `${origin}/api/remote/pairings`,\n\t\ttickets: `${origin}/api/remote/tickets`,\n\t\tinstallChallenges: `${origin}/api/remote/install-challenges`,\n\t\trelay: `wss://${new URL(origin).host}/api/remote/socket`,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AgentSession } from "../../core/agent-session.ts";
|
|
2
|
+
import type { WatchFrame } from "./protocol.ts";
|
|
3
|
+
import type { SecureChannel } from "./secure-channel.ts";
|
|
4
|
+
type Snapshot = Extract<WatchFrame, {
|
|
5
|
+
type: "snapshot";
|
|
6
|
+
}>;
|
|
7
|
+
type Message = Snapshot["messages"][number];
|
|
8
|
+
/** A safe, read-only view. It has no reference to terminal input or the agent dispatcher. */
|
|
9
|
+
export interface WatchProjection {
|
|
10
|
+
snapshot(): Pick<Snapshot, "messages" | "historyTruncated">;
|
|
11
|
+
subscribe(listener: (message: Message) => void): () => void;
|
|
12
|
+
}
|
|
13
|
+
/** Adapt only the current branch and completed message events; never serialize raw session objects. */
|
|
14
|
+
export declare function watchCurrentBranch(session: Pick<AgentSession, "sessionManager" | "subscribe">, env?: NodeJS.ProcessEnv): WatchProjection;
|
|
15
|
+
export interface WatchAttachment {
|
|
16
|
+
close(): void;
|
|
17
|
+
}
|
|
18
|
+
/** Snapshot and ordered events on a qualified secure channel only. Never awaits on the agent path. */
|
|
19
|
+
export declare function streamWatch(source: WatchProjection, canSend: () => boolean, channel: SecureChannel, onClose?: () => void): WatchAttachment;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=host-watch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-watch.d.ts","sourceRoot":"","sources":["../../../src/humain/remote/host-watch.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAGhE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,KAAK,QAAQ,GAAG,OAAO,CAAC,UAAU,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,CAAC;AAC1D,KAAK,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5C,6FAA6F;AAC7F,MAAM,WAAW,eAAe;IAC/B,QAAQ,IAAI,IAAI,CAAC,QAAQ,EAAE,UAAU,GAAG,kBAAkB,CAAC,CAAC;IAC5D,SAAS,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CAC5D;AAED,uGAAuG;AACvG,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,gBAAgB,GAAG,WAAW,CAAC,EAC3D,GAAG,GAAE,MAAM,CAAC,UAAwB,GAClC,eAAe,CA2BjB;AA0BD,MAAM,WAAW,eAAe;IAC/B,KAAK,IAAI,IAAI,CAAC;CACd;AAKD,sGAAsG;AACtG,wBAAgB,WAAW,CAC1B,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,MAAM,OAAO,EACtB,OAAO,EAAE,aAAa,EACtB,OAAO,CAAC,EAAE,MAAM,IAAI,GAClB,eAAe,CA2GjB"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { addAbortListener } from "node:events";
|
|
2
|
+
import { createTraceRedactor, getTraceEnvSecrets } from "../../core/trace/redaction.js";
|
|
3
|
+
/** Adapt only the current branch and completed message events; never serialize raw session objects. */
|
|
4
|
+
export function watchCurrentBranch(session, env = process.env) {
|
|
5
|
+
// Literal env credentials plus the shared pattern rules; values under 8 characters would disable the literal table.
|
|
6
|
+
const redactor = createTraceRedactor({ extraSecrets: getTraceEnvSecrets(env).filter((value) => value.length >= 8) });
|
|
7
|
+
return {
|
|
8
|
+
snapshot() {
|
|
9
|
+
const manager = session.sessionManager;
|
|
10
|
+
const messages = [];
|
|
11
|
+
let id = manager.getLeafId();
|
|
12
|
+
let visited = 0;
|
|
13
|
+
while (id && messages.length < 200 && visited++ < 800) {
|
|
14
|
+
const entry = manager.getEntry(id);
|
|
15
|
+
if (!entry)
|
|
16
|
+
break;
|
|
17
|
+
id = entry.parentId;
|
|
18
|
+
if (entry.type !== "message" || entry.controlDenied)
|
|
19
|
+
continue;
|
|
20
|
+
const projected = projectMessage(entry.message, redactor);
|
|
21
|
+
if (projected)
|
|
22
|
+
messages.push(projected);
|
|
23
|
+
}
|
|
24
|
+
return { messages: messages.reverse(), historyTruncated: !!id };
|
|
25
|
+
},
|
|
26
|
+
subscribe(listener) {
|
|
27
|
+
return session.subscribe((event) => {
|
|
28
|
+
if (event.type !== "message_end")
|
|
29
|
+
return;
|
|
30
|
+
const message = projectMessage(event.message, redactor);
|
|
31
|
+
if (message)
|
|
32
|
+
listener(message);
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const WITHHELD = "[withheld: redaction unavailable]";
|
|
38
|
+
function projectMessage(message, redactor) {
|
|
39
|
+
if (message.role !== "user" && message.role !== "assistant" && message.role !== "toolResult")
|
|
40
|
+
return undefined;
|
|
41
|
+
const chunks = typeof message.content === "string"
|
|
42
|
+
? [message.content]
|
|
43
|
+
: message.content.slice(0, 128).flatMap((part) => (part.type === "text" ? [part.text] : []));
|
|
44
|
+
const cap = message.role === "toolResult" ? 16 * 1024 : 32 * 1024;
|
|
45
|
+
// Redact a larger window than the cap, then cut: a secret straddling the cap must not leave a partial prefix.
|
|
46
|
+
const window = cap * 4;
|
|
47
|
+
const text = chunks.join("\n").slice(0, window);
|
|
48
|
+
let redacted;
|
|
49
|
+
// Fail closed: text that cannot be redacted never leaves the host.
|
|
50
|
+
try {
|
|
51
|
+
redacted = redactor.redactText(text).text;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return { role: message.role, text: WITHHELD };
|
|
55
|
+
}
|
|
56
|
+
const output = new Uint8Array(cap);
|
|
57
|
+
const { written } = encoder.encodeInto(redacted, output);
|
|
58
|
+
return { role: message.role, text: new TextDecoder().decode(output.subarray(0, written)) };
|
|
59
|
+
}
|
|
60
|
+
const FRAME_BUDGET = 1024 * 1024 - 4096; // Leave room for the unqualified profile's framing overhead.
|
|
61
|
+
const encoder = new TextEncoder();
|
|
62
|
+
/** Snapshot and ordered events on a qualified secure channel only. Never awaits on the agent path. */
|
|
63
|
+
export function streamWatch(source, canSend, channel, onClose) {
|
|
64
|
+
let closed = false;
|
|
65
|
+
let starting = true;
|
|
66
|
+
let unsubscribe;
|
|
67
|
+
let stopDisconnect;
|
|
68
|
+
let cursor = 0;
|
|
69
|
+
let queuedBytes = 0;
|
|
70
|
+
let pumping = false;
|
|
71
|
+
const queue = [];
|
|
72
|
+
// Abort is observable before the disconnect listener runs. Consent checks can also trigger teardown.
|
|
73
|
+
const isOpen = () => !closed && !channel.signal.aborted;
|
|
74
|
+
const canDeliver = () => isOpen() && canSend() && isOpen();
|
|
75
|
+
const close = () => {
|
|
76
|
+
if (closed)
|
|
77
|
+
return;
|
|
78
|
+
closed = true;
|
|
79
|
+
queue.length = 0;
|
|
80
|
+
stopDisconnect?.[Symbol.dispose]();
|
|
81
|
+
cleanup(unsubscribe);
|
|
82
|
+
cleanup(() => channel.close());
|
|
83
|
+
cleanup(onClose);
|
|
84
|
+
};
|
|
85
|
+
const pump = async () => {
|
|
86
|
+
if (pumping || starting || closed)
|
|
87
|
+
return;
|
|
88
|
+
pumping = true;
|
|
89
|
+
try {
|
|
90
|
+
while (!closed && queue.length) {
|
|
91
|
+
if (!canDeliver()) {
|
|
92
|
+
close();
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const bytes = queue.shift();
|
|
96
|
+
if (!bytes)
|
|
97
|
+
break;
|
|
98
|
+
await channel.send(bytes);
|
|
99
|
+
queuedBytes -= bytes.byteLength;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
close();
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
pumping = false;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const enqueue = (frame, first = false) => {
|
|
110
|
+
if (!canDeliver()) {
|
|
111
|
+
close();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const bytes = encoder.encode(JSON.stringify(frame));
|
|
115
|
+
queuedBytes += bytes.byteLength;
|
|
116
|
+
if (queuedBytes > FRAME_BUDGET || queue.length >= 256) {
|
|
117
|
+
close();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (first)
|
|
121
|
+
queue.unshift(bytes);
|
|
122
|
+
else
|
|
123
|
+
queue.push(bytes);
|
|
124
|
+
void pump();
|
|
125
|
+
};
|
|
126
|
+
try {
|
|
127
|
+
if (!canDeliver()) {
|
|
128
|
+
close();
|
|
129
|
+
return { close };
|
|
130
|
+
}
|
|
131
|
+
stopDisconnect = addAbortListener(channel.signal, close);
|
|
132
|
+
unsubscribe = source.subscribe((message) => {
|
|
133
|
+
try {
|
|
134
|
+
enqueue({ type: "delta", cursor: ++cursor, message });
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
// A live consent or encoding failure must not reach the local session's error path.
|
|
138
|
+
close();
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
if (closed) {
|
|
142
|
+
cleanup(unsubscribe);
|
|
143
|
+
return { close };
|
|
144
|
+
}
|
|
145
|
+
// Subscription can synchronously invalidate the attachment without emitting a message.
|
|
146
|
+
if (!canDeliver()) {
|
|
147
|
+
close();
|
|
148
|
+
return { close };
|
|
149
|
+
}
|
|
150
|
+
const snapshot = source.snapshot();
|
|
151
|
+
if (!canDeliver()) {
|
|
152
|
+
close();
|
|
153
|
+
return { close };
|
|
154
|
+
}
|
|
155
|
+
const messages = [];
|
|
156
|
+
let bytes = 512;
|
|
157
|
+
for (let i = snapshot.messages.length - 1; i >= Math.max(0, snapshot.messages.length - 200); i--) {
|
|
158
|
+
const message = snapshot.messages[i];
|
|
159
|
+
bytes += encoder.encode(JSON.stringify(message)).byteLength + 1;
|
|
160
|
+
if (bytes > FRAME_BUDGET)
|
|
161
|
+
break;
|
|
162
|
+
messages.push(message);
|
|
163
|
+
}
|
|
164
|
+
enqueue({
|
|
165
|
+
type: "snapshot",
|
|
166
|
+
cursor: 0,
|
|
167
|
+
messages: messages.reverse(),
|
|
168
|
+
historyTruncated: snapshot.historyTruncated || messages.length < snapshot.messages.length,
|
|
169
|
+
}, true);
|
|
170
|
+
starting = false;
|
|
171
|
+
void pump();
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
close();
|
|
175
|
+
}
|
|
176
|
+
return { close };
|
|
177
|
+
}
|
|
178
|
+
function cleanup(callback) {
|
|
179
|
+
try {
|
|
180
|
+
callback?.();
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
// Delivery is already fenced. Do not surface private adapter errors on the agent path.
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=host-watch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-watch.js","sourceRoot":"","sources":["../../../src/humain/remote/host-watch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAsB,MAAM,+BAA+B,CAAC;AAa5G,uGAAuG;AACvG,MAAM,UAAU,kBAAkB,CACjC,OAA2D,EAC3D,GAAG,GAAsB,OAAO,CAAC,GAAG;IAEpC,oHAAoH;IACpH,MAAM,QAAQ,GAAG,mBAAmB,CAAC,EAAE,YAAY,EAAE,kBAAkB,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;IACrH,OAAO;QACN,QAAQ;YACP,MAAM,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC;YACvC,MAAM,QAAQ,GAAc,EAAE,CAAC;YAC/B,IAAI,EAAE,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;YAC7B,IAAI,OAAO,GAAG,CAAC,CAAC;YAChB,OAAO,EAAE,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG,IAAI,OAAO,EAAE,GAAG,GAAG,EAAE,CAAC;gBACvD,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;gBACnC,IAAI,CAAC,KAAK;oBAAE,MAAM;gBAClB,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC;gBACpB,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,a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,IAAI,EAAE,CAAC;IACb,CAAC;IAAC,MAAM,CAAC;QACR,KAAK,EAAE,CAAC;IACT,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,CAAC;AAClB,CAAC;AAED,SAAS,OAAO,CAAC,QAAkC;IAClD,IAAI,CAAC;QACJ,QAAQ,EAAE,EAAE,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACR,uFAAuF;IACxF,CAAC;AACF,CAAC","sourcesContent":["import { addAbortListener } from \"node:events\";\nimport type { AgentSession } from \"../../core/agent-session.ts\";\nimport type { SessionMessageEntry } from \"../../core/session-manager.ts\";\nimport { createTraceRedactor, getTraceEnvSecrets, type TraceRedactor } from \"../../core/trace/redaction.ts\";\nimport type { WatchFrame } from \"./protocol.ts\";\nimport type { SecureChannel } from \"./secure-channel.ts\";\n\ntype Snapshot = Extract<WatchFrame, { type: \"snapshot\" }>;\ntype Message = Snapshot[\"messages\"][number];\n\n/** A safe, read-only view. It has no reference to terminal input or the agent dispatcher. */\nexport interface WatchProjection {\n\tsnapshot(): Pick<Snapshot, \"messages\" | \"historyTruncated\">;\n\tsubscribe(listener: (message: Message) => void): () => void;\n}\n\n/** Adapt only the current branch and completed message events; never serialize raw session objects. */\nexport function watchCurrentBranch(\n\tsession: Pick<AgentSession, \"sessionManager\" | \"subscribe\">,\n\tenv: NodeJS.ProcessEnv = process.env,\n): WatchProjection {\n\t// Literal env credentials plus the shared pattern rules; values under 8 characters would disable the literal table.\n\tconst redactor = createTraceRedactor({ extraSecrets: getTraceEnvSecrets(env).filter((value) => value.length >= 8) });\n\treturn {\n\t\tsnapshot() {\n\t\t\tconst manager = session.sessionManager;\n\t\t\tconst messages: Message[] = [];\n\t\t\tlet id = manager.getLeafId();\n\t\t\tlet visited = 0;\n\t\t\twhile (id && messages.length < 200 && visited++ < 800) {\n\t\t\t\tconst entry = manager.getEntry(id);\n\t\t\t\tif (!entry) break;\n\t\t\t\tid = entry.parentId;\n\t\t\t\tif (entry.type !== \"message\" || entry.controlDenied) continue;\n\t\t\t\tconst projected = projectMessage(entry.message, redactor);\n\t\t\t\tif (projected) messages.push(projected);\n\t\t\t}\n\t\t\treturn { messages: messages.reverse(), historyTruncated: !!id };\n\t\t},\n\t\tsubscribe(listener) {\n\t\t\treturn session.subscribe((event) => {\n\t\t\t\tif (event.type !== \"message_end\") return;\n\t\t\t\tconst message = projectMessage(event.message, redactor);\n\t\t\t\tif (message) listener(message);\n\t\t\t});\n\t\t},\n\t};\n}\n\nconst WITHHELD = \"[withheld: redaction unavailable]\";\n\nfunction projectMessage(message: SessionMessageEntry[\"message\"], redactor: TraceRedactor): Message | undefined {\n\tif (message.role !== \"user\" && message.role !== \"assistant\" && message.role !== \"toolResult\") return undefined;\n\tconst chunks =\n\t\ttypeof message.content === \"string\"\n\t\t\t? [message.content]\n\t\t\t: message.content.slice(0, 128).flatMap((part) => (part.type === \"text\" ? [part.text] : []));\n\tconst cap = message.role === \"toolResult\" ? 16 * 1024 : 32 * 1024;\n\t// Redact a larger window than the cap, then cut: a secret straddling the cap must not leave a partial prefix.\n\tconst window = cap * 4;\n\tconst text = chunks.join(\"\\n\").slice(0, window);\n\tlet redacted: string;\n\t// Fail closed: text that cannot be redacted never leaves the host.\n\ttry {\n\t\tredacted = redactor.redactText(text).text;\n\t} catch {\n\t\treturn { role: message.role, text: WITHHELD };\n\t}\n\tconst output = new Uint8Array(cap);\n\tconst { written } = encoder.encodeInto(redacted, output);\n\treturn { role: message.role, text: new TextDecoder().decode(output.subarray(0, written)) };\n}\n\nexport interface WatchAttachment {\n\tclose(): void;\n}\n\nconst FRAME_BUDGET = 1024 * 1024 - 4096; // Leave room for the unqualified profile's framing overhead.\nconst encoder = new TextEncoder();\n\n/** Snapshot and ordered events on a qualified secure channel only. Never awaits on the agent path. */\nexport function streamWatch(\n\tsource: WatchProjection,\n\tcanSend: () => boolean,\n\tchannel: SecureChannel,\n\tonClose?: () => void,\n): WatchAttachment {\n\tlet closed = false;\n\tlet starting = true;\n\tlet unsubscribe: (() => void) | undefined;\n\tlet stopDisconnect: ReturnType<typeof addAbortListener> | undefined;\n\tlet cursor = 0;\n\tlet queuedBytes = 0;\n\tlet pumping = false;\n\tconst queue: Uint8Array[] = [];\n\t// Abort is observable before the disconnect listener runs. Consent checks can also trigger teardown.\n\tconst isOpen = () => !closed && !channel.signal.aborted;\n\tconst canDeliver = () => isOpen() && canSend() && isOpen();\n\tconst close = () => {\n\t\tif (closed) return;\n\t\tclosed = true;\n\t\tqueue.length = 0;\n\t\tstopDisconnect?.[Symbol.dispose]();\n\t\tcleanup(unsubscribe);\n\t\tcleanup(() => channel.close());\n\t\tcleanup(onClose);\n\t};\n\tconst pump = async () => {\n\t\tif (pumping || starting || closed) return;\n\t\tpumping = true;\n\t\ttry {\n\t\t\twhile (!closed && queue.length) {\n\t\t\t\tif (!canDeliver()) {\n\t\t\t\t\tclose();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst bytes = queue.shift();\n\t\t\t\tif (!bytes) break;\n\t\t\t\tawait channel.send(bytes);\n\t\t\t\tqueuedBytes -= bytes.byteLength;\n\t\t\t}\n\t\t} catch {\n\t\t\tclose();\n\t\t} finally {\n\t\t\tpumping = false;\n\t\t}\n\t};\n\tconst enqueue = (frame: WatchFrame, first = false) => {\n\t\tif (!canDeliver()) {\n\t\t\tclose();\n\t\t\treturn;\n\t\t}\n\t\tconst bytes = encoder.encode(JSON.stringify(frame));\n\t\tqueuedBytes += bytes.byteLength;\n\t\tif (queuedBytes > FRAME_BUDGET || queue.length >= 256) {\n\t\t\tclose();\n\t\t\treturn;\n\t\t}\n\t\tif (first) queue.unshift(bytes);\n\t\telse queue.push(bytes);\n\t\tvoid pump();\n\t};\n\ttry {\n\t\tif (!canDeliver()) {\n\t\t\tclose();\n\t\t\treturn { close };\n\t\t}\n\t\tstopDisconnect = addAbortListener(channel.signal, close);\n\t\tunsubscribe = source.subscribe((message) => {\n\t\t\ttry {\n\t\t\t\tenqueue({ type: \"delta\", cursor: ++cursor, message });\n\t\t\t} catch {\n\t\t\t\t// A live consent or encoding failure must not reach the local session's error path.\n\t\t\t\tclose();\n\t\t\t}\n\t\t});\n\t\tif (closed) {\n\t\t\tcleanup(unsubscribe);\n\t\t\treturn { close };\n\t\t}\n\t\t// Subscription can synchronously invalidate the attachment without emitting a message.\n\t\tif (!canDeliver()) {\n\t\t\tclose();\n\t\t\treturn { close };\n\t\t}\n\t\tconst snapshot = source.snapshot();\n\t\tif (!canDeliver()) {\n\t\t\tclose();\n\t\t\treturn { close };\n\t\t}\n\t\tconst messages: Message[] = [];\n\t\tlet bytes = 512;\n\t\tfor (let i = snapshot.messages.length - 1; i >= Math.max(0, snapshot.messages.length - 200); i--) {\n\t\t\tconst message = snapshot.messages[i]!;\n\t\t\tbytes += encoder.encode(JSON.stringify(message)).byteLength + 1;\n\t\t\tif (bytes > FRAME_BUDGET) break;\n\t\t\tmessages.push(message);\n\t\t}\n\t\tenqueue(\n\t\t\t{\n\t\t\t\ttype: \"snapshot\",\n\t\t\t\tcursor: 0,\n\t\t\t\tmessages: messages.reverse(),\n\t\t\t\thistoryTruncated: snapshot.historyTruncated || messages.length < snapshot.messages.length,\n\t\t\t},\n\t\t\ttrue,\n\t\t);\n\t\tstarting = false;\n\t\tvoid pump();\n\t} catch {\n\t\tclose();\n\t}\n\treturn { close };\n}\n\nfunction cleanup(callback: (() => void) | undefined): void {\n\ttry {\n\t\tcallback?.();\n\t} catch {\n\t\t// Delivery is already fenced. Do not surface private adapter errors on the agent path.\n\t}\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Inspect a pre-created private directory. The native adapter must pin it through bind/connect. */
|
|
2
|
+
export declare function requirePrivateRuntimeDirectory(path: string): void;
|
|
3
|
+
/** Do not connect to a socket that is public, substituted, or not under the private directory. */
|
|
4
|
+
export declare function requirePrivateSocket(path: string): void;
|
|
5
|
+
//# sourceMappingURL=ipc-posix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipc-posix.d.ts","sourceRoot":"","sources":["../../../src/humain/remote/ipc-posix.ts"],"names":[],"mappings":"AAGA,oGAAoG;AACpG,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEjE;AAED,kGAAkG;AAClG,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAGvD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { lstatSync, realpathSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
/** Inspect a pre-created private directory. The native adapter must pin it through bind/connect. */
|
|
4
|
+
export function requirePrivateRuntimeDirectory(path) {
|
|
5
|
+
requireOwnerPath(path, "directory");
|
|
6
|
+
}
|
|
7
|
+
/** Do not connect to a socket that is public, substituted, or not under the private directory. */
|
|
8
|
+
export function requirePrivateSocket(path) {
|
|
9
|
+
requirePrivateRuntimeDirectory(resolve(path, ".."));
|
|
10
|
+
requireOwnerPath(path, "socket");
|
|
11
|
+
}
|
|
12
|
+
function requireOwnerPath(path, kind) {
|
|
13
|
+
try {
|
|
14
|
+
const info = lstatSync(path);
|
|
15
|
+
const uid = process.getuid?.();
|
|
16
|
+
if (uid !== undefined &&
|
|
17
|
+
info.uid === uid &&
|
|
18
|
+
realpathSync(path) === resolve(path) &&
|
|
19
|
+
(kind === "directory"
|
|
20
|
+
? info.isDirectory() && (info.mode & 0o7777) === 0o700
|
|
21
|
+
: info.isSocket() && (info.mode & 0o7777) === 0o600))
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// Fixed failure; paths and native exception details are not Remote diagnostics.
|
|
26
|
+
}
|
|
27
|
+
throw new Error("Remote IPC requires an owner-private POSIX endpoint");
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=ipc-posix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipc-posix.js","sourceRoot":"","sources":["../../../src/humain/remote/ipc-posix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,oGAAoG;AACpG,MAAM,UAAU,8BAA8B,CAAC,IAAY;IAC1D,gBAAgB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AACrC,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAChD,8BAA8B,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IACpD,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAY,EAAE,IAA4B;IACnE,IAAI,CAAC;QACJ,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;QAC7B,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;QAC/B,IACC,GAAG,KAAK,SAAS;YACjB,IAAI,CAAC,GAAG,KAAK,GAAG;YAChB,YAAY,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC;YACpC,CAAC,IAAI,KAAK,WAAW;gBACpB,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,KAAK,KAAK;gBACtD,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,KAAK,KAAK,CAAC;YAErD,OAAO;IACT,CAAC;IAAC,MAAM,CAAC;QACR,gFAAgF;IACjF,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;AACxE,CAAC","sourcesContent":["import { lstatSync, realpathSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\n\n/** Inspect a pre-created private directory. The native adapter must pin it through bind/connect. */\nexport function requirePrivateRuntimeDirectory(path: string): void {\n\trequireOwnerPath(path, \"directory\");\n}\n\n/** Do not connect to a socket that is public, substituted, or not under the private directory. */\nexport function requirePrivateSocket(path: string): void {\n\trequirePrivateRuntimeDirectory(resolve(path, \"..\"));\n\trequireOwnerPath(path, \"socket\");\n}\n\nfunction requireOwnerPath(path: string, kind: \"directory\" | \"socket\"): void {\n\ttry {\n\t\tconst info = lstatSync(path);\n\t\tconst uid = process.getuid?.();\n\t\tif (\n\t\t\tuid !== undefined &&\n\t\t\tinfo.uid === uid &&\n\t\t\trealpathSync(path) === resolve(path) &&\n\t\t\t(kind === \"directory\"\n\t\t\t\t? info.isDirectory() && (info.mode & 0o7777) === 0o700\n\t\t\t\t: info.isSocket() && (info.mode & 0o7777) === 0o600)\n\t\t)\n\t\t\treturn;\n\t} catch {\n\t\t// Fixed failure; paths and native exception details are not Remote diagnostics.\n\t}\n\tthrow new Error(\"Remote IPC requires an owner-private POSIX endpoint\");\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipc-windows.d.ts","sourceRoot":"","sources":["../../../src/humain/remote/ipc-windows.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,wBAAgB,uBAAuB,IAAI,KAAK,CAE/C"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Fail closed until a native owner-only ACL and peer identity adapter is available. */
|
|
2
|
+
export function requireWindowsRemoteIpc() {
|
|
3
|
+
throw new Error("Remote IPC unavailable: native Windows owner-only ACLs are not qualified");
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=ipc-windows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipc-windows.js","sourceRoot":"","sources":["../../../src/humain/remote/ipc-windows.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,MAAM,UAAU,uBAAuB;IACtC,MAAM,IAAI,KAAK,CAAC,0EAA0E,CAAC,CAAC;AAC7F,CAAC","sourcesContent":["/** Fail closed until a native owner-only ACL and peer identity adapter is available. */\nexport function requireWindowsRemoteIpc(): never {\n\tthrow new Error(\"Remote IPC unavailable: native Windows owner-only ACLs are not qualified\");\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type HostWatchControl } from "./protocol.ts";
|
|
2
|
+
interface AuthenticatedWatchIpc {
|
|
3
|
+
/** Native owner check and install-bound authentication must hold for this connection. */
|
|
4
|
+
isCurrent(): boolean;
|
|
5
|
+
close(): void;
|
|
6
|
+
}
|
|
7
|
+
/** Accept only complete, bounded host-watch controls on an authenticated local connection. */
|
|
8
|
+
export declare function createWatchIpcIngress(connection: AuthenticatedWatchIpc, receive: (control: HostWatchControl) => boolean): (payload: Uint8Array) => void;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=ipc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipc.d.ts","sourceRoot":"","sources":["../../../src/humain/remote/ipc.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE9E,UAAU,qBAAqB;IAC9B,yFAAyF;IACzF,SAAS,IAAI,OAAO,CAAC;IACrB,KAAK,IAAI,IAAI,CAAC;CACd;AAED,8FAA8F;AAC9F,wBAAgB,qBAAqB,CACpC,UAAU,EAAE,qBAAqB,EACjC,OAAO,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,OAAO,GAC7C,CAAC,OAAO,EAAE,UAAU,KAAK,IAAI,CAa/B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { decodeHostWatchControl } from "./protocol.js";
|
|
2
|
+
/** Accept only complete, bounded host-watch controls on an authenticated local connection. */
|
|
3
|
+
export function createWatchIpcIngress(connection, receive) {
|
|
4
|
+
let closed = false;
|
|
5
|
+
return (payload) => {
|
|
6
|
+
if (closed)
|
|
7
|
+
return;
|
|
8
|
+
try {
|
|
9
|
+
if (connection.isCurrent() && payload.byteLength <= 64 * 1024 && receive(decodeHostWatchControl(payload)))
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
// Invalid controls, unexpected state and lost authority all close without further dispatch.
|
|
14
|
+
}
|
|
15
|
+
closed = true;
|
|
16
|
+
connection.close();
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=ipc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipc.js","sourceRoot":"","sources":["../../../src/humain/remote/ipc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAyB,MAAM,eAAe,CAAC;AAQ9E,8FAA8F;AAC9F,MAAM,UAAU,qBAAqB,CACpC,UAAiC,EACjC,OAA+C;IAE/C,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,OAAO,CAAC,OAAO,EAAE,EAAE;QAClB,IAAI,MAAM;YAAE,OAAO;QACnB,IAAI,CAAC;YACJ,IAAI,UAAU,CAAC,SAAS,EAAE,IAAI,OAAO,CAAC,UAAU,IAAI,EAAE,GAAG,IAAI,IAAI,OAAO,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;gBACxG,OAAO;QACT,CAAC;QAAC,MAAM,CAAC;YACR,4FAA4F;QAC7F,CAAC;QACD,MAAM,GAAG,IAAI,CAAC;QACd,UAAU,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC,CAAC;AACH,CAAC","sourcesContent":["import { decodeHostWatchControl, type HostWatchControl } from \"./protocol.ts\";\n\ninterface AuthenticatedWatchIpc {\n\t/** Native owner check and install-bound authentication must hold for this connection. */\n\tisCurrent(): boolean;\n\tclose(): void;\n}\n\n/** Accept only complete, bounded host-watch controls on an authenticated local connection. */\nexport function createWatchIpcIngress(\n\tconnection: AuthenticatedWatchIpc,\n\treceive: (control: HostWatchControl) => boolean,\n): (payload: Uint8Array) => void {\n\tlet closed = false;\n\treturn (payload) => {\n\t\tif (closed) return;\n\t\ttry {\n\t\t\tif (connection.isCurrent() && payload.byteLength <= 64 * 1024 && receive(decodeHostWatchControl(payload)))\n\t\t\t\treturn;\n\t\t} catch {\n\t\t\t// Invalid controls, unexpected state and lost authority all close without further dispatch.\n\t\t}\n\t\tclosed = true;\n\t\tconnection.close();\n\t};\n}\n"]}
|