@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,132 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { raceWithAbortSignal } from "../../utils/abort.js";
|
|
3
|
+
import { resolveHcodeEnvironment } from "../hcode/environment.js";
|
|
4
|
+
import { readHcodeJson } from "../hcode/http.js";
|
|
5
|
+
import { opaqueId } from "./broker.js";
|
|
6
|
+
import { remoteDestinations } from "./environment.js";
|
|
7
|
+
const routeKeys = ["installId", "brokerEpoch", "sessionId", "attachmentId", "channelEpoch"];
|
|
8
|
+
const tokenPattern = /^[A-Za-z0-9_-]{43}$/;
|
|
9
|
+
/** Issue a scoped, short-lived host ticket without exposing credentials or retrying an ambiguous write. */
|
|
10
|
+
export function createRemoteTicketClient({ environment = resolveHcodeEnvironment(), account, fetchRemote, signInstallProof, now = Date.now, }) {
|
|
11
|
+
const unavailable = () => new Error("Remote ticket unavailable");
|
|
12
|
+
let destinations;
|
|
13
|
+
try {
|
|
14
|
+
destinations = remoteDestinations(environment);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
throw unavailable();
|
|
18
|
+
}
|
|
19
|
+
return async (reference, request, parent) => {
|
|
20
|
+
let unsubscribe;
|
|
21
|
+
try {
|
|
22
|
+
if (reference.environmentId !== environment.id)
|
|
23
|
+
throw unavailable();
|
|
24
|
+
const expected = Object.freeze({ ...reference });
|
|
25
|
+
const matches = (current) => current?.environmentId === expected.environmentId &&
|
|
26
|
+
current.accountId === expected.accountId &&
|
|
27
|
+
current.generation === expected.generation;
|
|
28
|
+
const assertCurrent = () => {
|
|
29
|
+
if (!matches(account.status(expected.environmentId)))
|
|
30
|
+
throw unavailable();
|
|
31
|
+
};
|
|
32
|
+
const { kind, id } = request;
|
|
33
|
+
const { installId, brokerEpoch, sessionId, attachmentId, channelEpoch } = request.route;
|
|
34
|
+
const route = Object.freeze({ installId, brokerEpoch, sessionId, attachmentId, channelEpoch });
|
|
35
|
+
if ((kind !== "offer" && kind !== "pairing") ||
|
|
36
|
+
!opaqueId(id) ||
|
|
37
|
+
!routeKeys.every((key) => opaqueId(route[key])))
|
|
38
|
+
throw unavailable();
|
|
39
|
+
const identity = new AbortController();
|
|
40
|
+
const signals = [identity.signal, AbortSignal.timeout(5_000)];
|
|
41
|
+
if (parent)
|
|
42
|
+
signals.push(parent);
|
|
43
|
+
const signal = AbortSignal.any(signals);
|
|
44
|
+
signal.throwIfAborted();
|
|
45
|
+
unsubscribe = account.subscribe((current) => {
|
|
46
|
+
if (!matches(current))
|
|
47
|
+
identity.abort();
|
|
48
|
+
});
|
|
49
|
+
const post = async (path, body) => {
|
|
50
|
+
assertCurrent();
|
|
51
|
+
signal.throwIfAborted();
|
|
52
|
+
const endpoint = path === "tickets" ? destinations.tickets : destinations.installChallenges;
|
|
53
|
+
const pending = fetchRemote(expected, endpoint, {
|
|
54
|
+
method: "POST",
|
|
55
|
+
headers: { "content-type": "application/json", accept: "application/json" },
|
|
56
|
+
body: JSON.stringify(body),
|
|
57
|
+
signal,
|
|
58
|
+
redirect: "error",
|
|
59
|
+
credentials: "omit",
|
|
60
|
+
cache: "no-store",
|
|
61
|
+
});
|
|
62
|
+
const response = await raceWithAbortSignal(pending, signal).catch((error) => {
|
|
63
|
+
if (signal.aborted)
|
|
64
|
+
void pending.then((late) => late.body?.cancel()).catch(() => { });
|
|
65
|
+
throw error;
|
|
66
|
+
});
|
|
67
|
+
if (signal.aborted ||
|
|
68
|
+
response.status !== 200 ||
|
|
69
|
+
response.redirected ||
|
|
70
|
+
(response.url && response.url !== endpoint)) {
|
|
71
|
+
void response.body?.cancel().catch(() => { });
|
|
72
|
+
throw unavailable();
|
|
73
|
+
}
|
|
74
|
+
const data = await raceWithAbortSignal(readHcodeJson(response, 4096, signal), signal);
|
|
75
|
+
signal.throwIfAborted();
|
|
76
|
+
assertCurrent();
|
|
77
|
+
return data;
|
|
78
|
+
};
|
|
79
|
+
const input = { route, kind, id };
|
|
80
|
+
// Match Forge's host ticket operation binding; this digest is not the install signature.
|
|
81
|
+
const target = createHash("sha256")
|
|
82
|
+
.update(JSON.stringify(["tickets", input]))
|
|
83
|
+
.digest("hex");
|
|
84
|
+
const offered = await post("install-challenges", { installId, target });
|
|
85
|
+
if (!record(offered) ||
|
|
86
|
+
Object.keys(offered).length !== 2 ||
|
|
87
|
+
typeof offered.challenge !== "string" ||
|
|
88
|
+
!tokenPattern.test(offered.challenge) ||
|
|
89
|
+
!validExpiry(offered.expiresAt, now()))
|
|
90
|
+
throw unavailable();
|
|
91
|
+
const { challenge, expiresAt: challengeExpiry } = offered;
|
|
92
|
+
assertCurrent();
|
|
93
|
+
signal.throwIfAborted();
|
|
94
|
+
const proof = await raceWithAbortSignal(signInstallProof(expected, Object.freeze({ installId, target, challenge }), signal), signal);
|
|
95
|
+
if (typeof proof !== "string" || !proof || proof.length > 2048 || challengeExpiry <= now())
|
|
96
|
+
throw unavailable();
|
|
97
|
+
const received = await post("tickets", { ...input, challenge, proof });
|
|
98
|
+
if (!record(received) || Object.keys(received).length !== 3)
|
|
99
|
+
throw unavailable();
|
|
100
|
+
const { token, expiresAt, route: returnedRoute } = received;
|
|
101
|
+
signal.throwIfAborted();
|
|
102
|
+
assertCurrent();
|
|
103
|
+
if (typeof token !== "string" ||
|
|
104
|
+
!tokenPattern.test(token) ||
|
|
105
|
+
!validExpiry(expiresAt, now()) ||
|
|
106
|
+
!record(returnedRoute) ||
|
|
107
|
+
Object.keys(returnedRoute).length !== routeKeys.length ||
|
|
108
|
+
!routeKeys.every((key) => returnedRoute[key] === route[key]))
|
|
109
|
+
throw unavailable();
|
|
110
|
+
return Object.freeze({ token, expiresAt, route });
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
// Do not reflect transport errors, response bodies, bearer credentials or ticket material.
|
|
114
|
+
throw unavailable();
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
try {
|
|
118
|
+
unsubscribe?.();
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// Never reflect private adapter cleanup errors.
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function validExpiry(value, at) {
|
|
127
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > at && value <= at + 60_000;
|
|
128
|
+
}
|
|
129
|
+
function record(value) {
|
|
130
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=tickets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tickets.js","sourceRoot":"","sources":["../../../src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QAAC,MAAM,CAAC;YACR,2FAA2F;YAC3F,MAAM,WAAW,EAAE,CAAC;QACrB,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC;gBACJ,WAAW,EAAE,EAAE,CAAC;YACjB,CAAC;YAAC,MAAM,CAAC;gBACR,gDAAgD;YACjD,CAAC;QACF,CAAC;IACF,CAAC,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,KAAc,EAAE,EAAU;IAC9C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,EAAE,IAAI,KAAK,IAAI,EAAE,GAAG,MAAM,CAAC;AACvG,CAAC;AAED,SAAS,MAAM,CAAC,KAAc;IAC7B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { raceWithAbortSignal } from \"../../utils/abort.ts\";\nimport { type HcodeEnvironment, resolveHcodeEnvironment } from \"../hcode/environment.ts\";\nimport { readHcodeJson } from \"../hcode/http.ts\";\nimport type { HcodeAccountPort, HcodeAccountRef } from \"../hcode/ports.ts\";\nimport { opaqueId } from \"./broker.ts\";\nimport { remoteDestinations } from \"./environment.ts\";\nimport type { LiveRoute } from \"./protocol.ts\";\n\ninterface TicketRequest {\n\troute: LiveRoute;\n\tkind: \"offer\" | \"pairing\";\n\tid: string;\n}\n\ninterface TicketClientOptions {\n\tenvironment?: HcodeEnvironment;\n\taccount: Pick<HcodeAccountPort, \"status\" | \"subscribe\">;\n\t/** Identity-owner transport for the Remote audience only. Must fence the exact account before I/O. */\n\tfetchRemote(expected: Readonly<HcodeAccountRef>, url: string, init: RequestInit): Promise<Response>;\n\t/** Trusted install-key adapter. The private key never enters the ticket client. */\n\tsignInstallProof(\n\t\texpected: Readonly<HcodeAccountRef>,\n\t\tbinding: Readonly<{ installId: string; target: string; challenge: string }>,\n\t\tsignal: AbortSignal,\n\t): Promise<string>;\n\tnow?: () => number;\n}\n\nconst routeKeys = [\"installId\", \"brokerEpoch\", \"sessionId\", \"attachmentId\", \"channelEpoch\"] as const;\nconst tokenPattern = /^[A-Za-z0-9_-]{43}$/;\n\n/** Issue a scoped, short-lived host ticket without exposing credentials or retrying an ambiguous write. */\nexport function createRemoteTicketClient({\n\tenvironment = resolveHcodeEnvironment(),\n\taccount,\n\tfetchRemote,\n\tsignInstallProof,\n\tnow = Date.now,\n}: TicketClientOptions) {\n\tconst unavailable = () => new Error(\"Remote ticket unavailable\");\n\tlet destinations: ReturnType<typeof remoteDestinations>;\n\ttry {\n\t\tdestinations = remoteDestinations(environment);\n\t} catch {\n\t\tthrow unavailable();\n\t}\n\treturn async (reference: HcodeAccountRef, request: TicketRequest, parent?: AbortSignal) => {\n\t\tlet unsubscribe: (() => void) | undefined;\n\t\ttry {\n\t\t\tif (reference.environmentId !== environment.id) throw unavailable();\n\t\t\tconst expected = Object.freeze({ ...reference });\n\t\t\tconst matches = (current: HcodeAccountRef | null) =>\n\t\t\t\tcurrent?.environmentId === expected.environmentId &&\n\t\t\t\tcurrent.accountId === expected.accountId &&\n\t\t\t\tcurrent.generation === expected.generation;\n\t\t\tconst assertCurrent = () => {\n\t\t\t\tif (!matches(account.status(expected.environmentId))) throw unavailable();\n\t\t\t};\n\t\t\tconst { kind, id } = request;\n\t\t\tconst { installId, brokerEpoch, sessionId, attachmentId, channelEpoch } = request.route;\n\t\t\tconst route = Object.freeze({ installId, brokerEpoch, sessionId, attachmentId, channelEpoch });\n\t\t\tif (\n\t\t\t\t(kind !== \"offer\" && kind !== \"pairing\") ||\n\t\t\t\t!opaqueId(id) ||\n\t\t\t\t!routeKeys.every((key) => opaqueId(route[key]))\n\t\t\t)\n\t\t\t\tthrow unavailable();\n\t\t\tconst identity = new AbortController();\n\t\t\tconst signals = [identity.signal, AbortSignal.timeout(5_000)];\n\t\t\tif (parent) signals.push(parent);\n\t\t\tconst signal = AbortSignal.any(signals);\n\t\t\tsignal.throwIfAborted();\n\t\t\tunsubscribe = account.subscribe((current) => {\n\t\t\t\tif (!matches(current)) identity.abort();\n\t\t\t});\n\t\t\tconst post = async (path: \"install-challenges\" | \"tickets\", body: object) => {\n\t\t\t\tassertCurrent();\n\t\t\t\tsignal.throwIfAborted();\n\t\t\t\tconst endpoint = path === \"tickets\" ? destinations.tickets : destinations.installChallenges;\n\t\t\t\tconst pending = fetchRemote(expected, endpoint, {\n\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\theaders: { \"content-type\": \"application/json\", accept: \"application/json\" },\n\t\t\t\t\tbody: JSON.stringify(body),\n\t\t\t\t\tsignal,\n\t\t\t\t\tredirect: \"error\",\n\t\t\t\t\tcredentials: \"omit\",\n\t\t\t\t\tcache: \"no-store\",\n\t\t\t\t});\n\t\t\t\tconst response = await raceWithAbortSignal(pending, signal).catch((error: unknown) => {\n\t\t\t\t\tif (signal.aborted) void pending.then((late) => late.body?.cancel()).catch(() => {});\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\t\t\t\tif (\n\t\t\t\t\tsignal.aborted ||\n\t\t\t\t\tresponse.status !== 200 ||\n\t\t\t\t\tresponse.redirected ||\n\t\t\t\t\t(response.url && response.url !== endpoint)\n\t\t\t\t) {\n\t\t\t\t\tvoid response.body?.cancel().catch(() => {});\n\t\t\t\t\tthrow unavailable();\n\t\t\t\t}\n\t\t\t\tconst data = await raceWithAbortSignal(readHcodeJson(response, 4096, signal), signal);\n\t\t\t\tsignal.throwIfAborted();\n\t\t\t\tassertCurrent();\n\t\t\t\treturn data;\n\t\t\t};\n\t\t\tconst input = { route, kind, id };\n\t\t\t// Match Forge's host ticket operation binding; this digest is not the install signature.\n\t\t\tconst target = createHash(\"sha256\")\n\t\t\t\t.update(JSON.stringify([\"tickets\", input]))\n\t\t\t\t.digest(\"hex\");\n\t\t\tconst offered = await post(\"install-challenges\", { installId, target });\n\t\t\tif (\n\t\t\t\t!record(offered) ||\n\t\t\t\tObject.keys(offered).length !== 2 ||\n\t\t\t\ttypeof offered.challenge !== \"string\" ||\n\t\t\t\t!tokenPattern.test(offered.challenge) ||\n\t\t\t\t!validExpiry(offered.expiresAt, now())\n\t\t\t)\n\t\t\t\tthrow unavailable();\n\t\t\tconst { challenge, expiresAt: challengeExpiry } = offered;\n\t\t\tassertCurrent();\n\t\t\tsignal.throwIfAborted();\n\t\t\tconst proof = await raceWithAbortSignal(\n\t\t\t\tsignInstallProof(expected, Object.freeze({ installId, target, challenge }), signal),\n\t\t\t\tsignal,\n\t\t\t);\n\t\t\tif (typeof proof !== \"string\" || !proof || proof.length > 2048 || challengeExpiry <= now())\n\t\t\t\tthrow unavailable();\n\t\t\tconst received = await post(\"tickets\", { ...input, challenge, proof });\n\t\t\tif (!record(received) || Object.keys(received).length !== 3) throw unavailable();\n\t\t\tconst { token, expiresAt, route: returnedRoute } = received;\n\t\t\tsignal.throwIfAborted();\n\t\t\tassertCurrent();\n\t\t\tif (\n\t\t\t\ttypeof token !== \"string\" ||\n\t\t\t\t!tokenPattern.test(token) ||\n\t\t\t\t!validExpiry(expiresAt, now()) ||\n\t\t\t\t!record(returnedRoute) ||\n\t\t\t\tObject.keys(returnedRoute).length !== routeKeys.length ||\n\t\t\t\t!routeKeys.every((key) => returnedRoute[key] === route[key])\n\t\t\t)\n\t\t\t\tthrow unavailable();\n\t\t\treturn Object.freeze({ token, expiresAt, route });\n\t\t} catch {\n\t\t\t// Do not reflect transport errors, response bodies, bearer credentials or ticket material.\n\t\t\tthrow unavailable();\n\t\t} finally {\n\t\t\ttry {\n\t\t\t\tunsubscribe?.();\n\t\t\t} catch {\n\t\t\t\t// Never reflect private adapter cleanup errors.\n\t\t\t}\n\t\t}\n\t};\n}\n\nfunction validExpiry(value: unknown, at: number): value is number {\n\treturn typeof value === \"number\" && Number.isSafeInteger(value) && value > at && value <= at + 60_000;\n}\n\nfunction record(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"]}
|
package/dist/main.d.ts
CHANGED
|
@@ -15,5 +15,5 @@ export interface MainOptions {
|
|
|
15
15
|
}
|
|
16
16
|
export declare function stripStartupCwdArgs(args: string[]): string[];
|
|
17
17
|
export declare function resolveStartupCwd(parsed: Pick<Args, "cwd">, env: NodeJS.ProcessEnv, currentCwd: string): string;
|
|
18
|
-
export declare function main(args: string[], options?: MainOptions): Promise<void>;
|
|
18
|
+
export declare function main(args: string[], options?: MainOptions, run?: import("./humain/hcode/run-credential.ts").HcodeRunBootstrap): Promise<void>;
|
|
19
19
|
//# sourceMappingURL=main.d.ts.map
|
package/dist/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AASH,OAAO,EAAE,KAAK,IAAI,EAA+E,MAAM,eAAe,CAAC;AAiDvH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAuBlE,OAAO,EAAwB,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEjF,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AASH,OAAO,EAAE,KAAK,IAAI,EAA+E,MAAM,eAAe,CAAC;AAiDvH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAuBlE,OAAO,EAAwB,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEjF,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AA2C7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAuSpD,wBAAsB,oBAAoB,CACzC,MAAM,EAAE,IAAI,EACZ,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,eAAe,EAAE,eAAe,GAC9B,OAAO,CAAC,cAAc,CAAC,CAuFzB;AAiID,MAAM,WAAW,WAAW;IAC3B,kBAAkB,CAAC,EAAE,eAAe,EAAE,CAAC;CACvC;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAE5D;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAM/G;AAED,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,GAAG,+DAAqC,iBA4xBzG"}
|
package/dist/main.js
CHANGED
|
@@ -56,6 +56,8 @@ import { revokeGatewayOrphans, shouldReconcileGatewayOnStartup } from "./humain/
|
|
|
56
56
|
import { resolveHcodeEnvironment } from "./humain/hcode/environment.js";
|
|
57
57
|
import { HCODE_PROVIDER } from "./humain/hcode/http.js";
|
|
58
58
|
import { hcodeLoginAvailability } from "./humain/hcode/login-copy.js";
|
|
59
|
+
import { takeHcodeRunBootstrap } from "./humain/hcode/run-credential.js";
|
|
60
|
+
import { runHcodeSandbox } from "./humain/hcode/sandbox.js";
|
|
59
61
|
import { isHcodeSelectionMessage } from "./humain/hcode/selection.js";
|
|
60
62
|
import { getHumainBundledExtensionFactories, getHumainDefaultPackageSources, HUMAIN_FORGE_CWD_ENV, } from "./humain/index.js";
|
|
61
63
|
import { HUMAIN_NODE_PROVIDER } from "./humain/node-provider.js";
|
|
@@ -506,7 +508,17 @@ export function resolveStartupCwd(parsed, env, currentCwd) {
|
|
|
506
508
|
throw new Error(`Invalid --cwd "${rawCwd}": not a directory`);
|
|
507
509
|
return resolvedCwd;
|
|
508
510
|
}
|
|
509
|
-
export async function main(args, options) {
|
|
511
|
+
export async function main(args, options, run = takeHcodeRunBootstrap(process.env)) {
|
|
512
|
+
if (run.kind !== "desktop") {
|
|
513
|
+
if (run.kind === "invalid") {
|
|
514
|
+
console.error("Invalid Forge run configuration: use the approved origin and a paired run token.");
|
|
515
|
+
process.exitCode = 1;
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
process.exitCode = await runHcodeSandbox(args, run, resolveStartupCwd);
|
|
519
|
+
}
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
510
522
|
const parsed = parseArgs(args);
|
|
511
523
|
const rawIntent = parsed.model || parsed.provider
|
|
512
524
|
? { kind: "chosen", source: "cli" }
|