@humain/humain-code 0.5.0 → 0.5.3
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 +37 -1
- package/README.md +3 -1
- package/dist/agent-monitor/client.d.ts +2 -2
- package/dist/agent-monitor/client.d.ts.map +1 -1
- package/dist/agent-monitor/client.js +3 -2
- package/dist/agent-monitor/client.js.map +1 -1
- package/dist/bundle/chunks/anthropic.js +10 -9
- package/dist/bundle/chunks/{chunk-DR37WKFZ.js → chunk-AO6FF5JL.js} +1 -1
- package/dist/bundle/chunks/{chunk-Q3SFYT2X.js → chunk-EY3LZOUP.js} +1356 -1358
- package/dist/bundle/chunks/{chunk-T3HXWZG4.js → chunk-L2VKM23Q.js} +76 -2
- package/dist/bundle/chunks/{chunk-5C4VL2AR.js → chunk-ODJUBJK2.js} +2 -2
- package/dist/bundle/chunks/{chunk-A6YBWW4T.js → chunk-UJLCKIMZ.js} +646 -495
- package/dist/bundle/chunks/{chunk-476XBL3W.js → chunk-Y3OPKKDR.js} +3 -77
- package/dist/bundle/chunks/{cli-VXU7OWFU.js → cli-ENEFJH2B.js} +1 -1
- package/dist/bundle/chunks/{compat-S2IBVV6V.js → compat-CJBWWYHE.js} +1 -1
- package/dist/bundle/chunks/{dist-645GFIWH.js → dist-RKNCFFGM.js} +2 -2
- package/dist/bundle/chunks/github-copilot.js +28 -26
- package/dist/bundle/chunks/openai-chatgpt.js +2 -2
- package/dist/bundle/chunks/openai-codex.js +10 -9
- package/dist/bundle/chunks/openrouter.js +10 -9
- package/dist/bundle/chunks/radius.js +9 -8
- package/dist/bundle/chunks/{runtime-5VFZTMWL.js → runtime-K3F2QDQP.js} +1 -1
- package/dist/bundle/chunks/{virtual-modules-GU6AW5ZK.js → virtual-modules-5D6QIJPN.js} +2 -2
- package/dist/bundle/cli-runtime.js +1 -1
- package/dist/bundle/index.js +4 -4
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +19 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +24 -2
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/safe-credential-error.d.ts +11 -0
- package/dist/core/safe-credential-error.d.ts.map +1 -0
- package/dist/core/safe-credential-error.js +14 -0
- package/dist/core/safe-credential-error.js.map +1 -0
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +4 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-schema.d.ts +3 -0
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +6 -0
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/humain/gateway/catalog.d.ts +36 -0
- package/dist/humain/gateway/catalog.d.ts.map +1 -0
- package/dist/humain/gateway/catalog.js +74 -0
- package/dist/humain/gateway/catalog.js.map +1 -0
- package/dist/humain/gateway/client.d.ts +58 -0
- package/dist/humain/gateway/client.d.ts.map +1 -0
- package/dist/humain/gateway/client.js +212 -0
- package/dist/humain/gateway/client.js.map +1 -0
- package/dist/humain/gateway/constants.d.ts +23 -0
- package/dist/humain/gateway/constants.d.ts.map +1 -0
- package/dist/humain/gateway/constants.js +32 -0
- package/dist/humain/gateway/constants.js.map +1 -0
- package/dist/humain/gateway/http.d.ts +18 -0
- package/dist/humain/gateway/http.d.ts.map +1 -0
- package/dist/humain/gateway/http.js +274 -0
- package/dist/humain/gateway/http.js.map +1 -0
- package/dist/humain/gateway/login.d.ts +13 -0
- package/dist/humain/gateway/login.d.ts.map +1 -0
- package/dist/humain/gateway/login.js +121 -0
- package/dist/humain/gateway/login.js.map +1 -0
- package/dist/humain/gateway/provider.d.ts +34 -0
- package/dist/humain/gateway/provider.d.ts.map +1 -0
- package/dist/humain/gateway/provider.js +253 -0
- package/dist/humain/gateway/provider.js.map +1 -0
- package/dist/humain/gateway/secret-store.d.ts +19 -0
- package/dist/humain/gateway/secret-store.d.ts.map +1 -0
- package/dist/humain/gateway/secret-store.js +252 -0
- package/dist/humain/gateway/secret-store.js.map +1 -0
- package/dist/humain/gateway/session-store.d.ts +42 -0
- package/dist/humain/gateway/session-store.d.ts.map +1 -0
- package/dist/humain/gateway/session-store.js +175 -0
- package/dist/humain/gateway/session-store.js.map +1 -0
- package/dist/humain/index.d.ts.map +1 -1
- package/dist/humain/index.js +2 -0
- package/dist/humain/index.js.map +1 -1
- package/dist/humain/login-menu.d.ts +14 -0
- package/dist/humain/login-menu.d.ts.map +1 -0
- package/dist/humain/login-menu.js +21 -0
- package/dist/humain/login-menu.js.map +1 -0
- package/dist/humain/node-http.d.ts.map +1 -1
- package/dist/humain/node-http.js +6 -31
- package/dist/humain/node-http.js.map +1 -1
- package/dist/humain/redact-assistant-message.d.ts +4 -0
- package/dist/humain/redact-assistant-message.d.ts.map +1 -0
- package/dist/humain/redact-assistant-message.js +34 -0
- package/dist/humain/redact-assistant-message.js.map +1 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +17 -4
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +3 -2
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +11 -0
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +16 -3
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/radius-login-selector.d.ts +5 -4
- package/dist/modes/interactive/components/radius-login-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/radius-login-selector.js +11 -9
- package/dist/modes/interactive/components/radius-login-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +2 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +53 -36
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/utils/sleep.d.ts +1 -1
- package/dist/utils/sleep.d.ts.map +1 -1
- package/dist/utils/sleep.js +10 -6
- package/dist/utils/sleep.js.map +1 -1
- package/docs/humain-code.md +13 -1
- package/docs/index.md +1 -1
- package/docs/models.md +3 -1
- package/docs/providers.md +58 -2
- package/docs/quickstart.md +8 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/schemas/settings.schema.json +19 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## [
|
|
3
|
+
## [0.5.3] - 2026-11-02
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- 0.5.2 was also tagged but not published: the tag pipeline ran the tests as the `node` user with root's unreadable `/root/.cargo/bin` on `PATH`, which turns a missing command's `ENOENT` into `EACCES` and failed tests that expect "not found" (`mcp-command`, Flow `verification-checks`). The tag pipeline now drops that directory from `PATH` for the test run. 0.5.3 ships the 0.5.1 and 0.5.2 changes with this fix.
|
|
8
|
+
|
|
9
|
+
## [0.5.2] - 2026-11-02
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- 0.5.1 was tagged but never published to npm: the tag pipeline's `scripts/check-biome.test.mjs` treated a missing `bun` as installed when `PATH` held an unreadable directory (root-installed Rust run as the `node` user), so the publish job was skipped. The test now skips unless the package manager actually runs. 0.5.2 ships the 0.5.1 changes below with this fix; the owner-authorized CI test evidence and waivers recorded for 0.5.1 apply to it as well.
|
|
14
|
+
|
|
15
|
+
## [0.5.1] - 2026-11-02
|
|
16
|
+
|
|
17
|
+
### New Features
|
|
18
|
+
|
|
19
|
+
- **HUMAIN Gateway:** sign in with your Microsoft account and use the models, budget, and limits of your [HUMAIN Gateway](https://gateway.humain.services) account, with no API key and no separate Gateway CLI. The session key stays in the OS keychain. See [HUMAIN Gateway](docs/providers.md#humain-gateway).
|
|
20
|
+
- **Sign in with HUMAIN:** `/login` now starts with one entry for HUMAIN Gateway and HUMAIN Node. See [Quickstart](docs/quickstart.md#3-choose-a-model).
|
|
21
|
+
- **Clearer default model choice:** `/model` explains that Enter is for this session and Ctrl+S saves the default for new sessions. See [Choose a model](docs/models.md#select-a-model).
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- Added the HUMAIN Gateway provider (`humain-gateway`): Microsoft sign-in through the browser or a masked paste-back code, session keys stored only in the OS keychain (macOS Keychain, Linux Secret Service, Windows Credential Manager), account-scoped discovery of entitled chat models, HUMAIN Code harness-label blocking with reasons, budget and setup-state handling, and inference through the Responses API with Gateway-owned retries that never resend a request that may have been billed. Sign-in errors show their real reason. See [HUMAIN Gateway](docs/providers.md#humain-gateway).
|
|
26
|
+
- Added the `humainGateway.environment` setting (`production` by default, or `staging`), read from global settings only.
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
- The owner authorized GitLab CI test evidence for HUMAIN Code CLI 0.5.1 (2026-11-02): the local full suite was not reliable on the release host (different timing-sensitive tests failed on each run under host load, each passing alone), so the release uses the `verify-main` full-suite job of the GitLab pipeline for the exact release commit. The release script accepts `HUMAIN_RELEASE_CI_PIPELINE=<id>` and refuses a pipeline that did not succeed on that commit; all other release checks and the Node/Bun smoke tests still run.
|
|
31
|
+
- The owner waived the blocking pi-web-access upstream release check for HUMAIN Code CLI 0.5.1 (2026-11-02): 0.5.1 ships the vendored pi-web-access 0.44.0 while 0.46.0 is available; the update is left to the upstream refresh. The release script accepts `HUMAIN_RELEASE_ALLOW_STALE_WEB_ACCESS=1` for such an explicit waiver.
|
|
32
|
+
- The owner granted a one-time paid Flow eval release-gate waiver for HUMAIN Code CLI 0.5.1 (2026-11-02). No passing Flow gate is claimed. All other checks, tests, Node/Bun smoke tests and post-publication public-registry install and real-prompt checks remain required.
|
|
33
|
+
- `/login` now starts with **Sign in with HUMAIN**, which lists HUMAIN Gateway and HUMAIN Node. The top-level Radius entry is removed; `/login radius` still works.
|
|
34
|
+
- `/model` now explains at the top that Enter uses a model for this session and Ctrl+S saves it as the default for new sessions, and choosing a model reports which of the two happened, with a one-time save tip.
|
|
35
|
+
|
|
36
|
+
### Fixed
|
|
37
|
+
|
|
38
|
+
- OAuth sign-in pages show the HUMAIN Code logo at the CLI icon's proportions with accent-colored bars, instead of a vertically squished mark.
|
|
39
|
+
- The OAuth loopback callback server rejects callbacks that repeat `code` or `state` and compares `state` in constant time.
|
|
4
40
|
|
|
5
41
|
## [0.5.0] - 2026-10-25
|
|
6
42
|
|
package/README.md
CHANGED
|
@@ -41,6 +41,8 @@ humain-code
|
|
|
41
41
|
|
|
42
42
|
The `humain-code` CLI is also available through the `humain-code-cli`, `hc`, `hcc`, `ht`, and `humain` aliases. The old `humain-terminal` command still works but is deprecated. The npm package is `@humain/humain-code` (formerly `@humain/terminal`). The `.humain-terminal` config directory and `HUMAIN_TERMINAL_*` environment variables are unchanged.
|
|
43
43
|
|
|
44
|
+
To use HUMAIN models, run `/login`, choose **Sign in with HUMAIN**, and pick **HUMAIN Gateway** (Microsoft sign-in, no API key) or **HUMAIN Node** (API key). Then choose a model with `/model`. See [HUMAIN Gateway](docs/providers.md#humain-gateway) and [HUMAIN Node](docs/providers.md#humain-node).
|
|
45
|
+
|
|
44
46
|
See the [documentation](docs/index.md) for full setup and usage instructions.
|
|
45
47
|
|
|
46
48
|
## Development
|
|
@@ -65,7 +67,7 @@ npm run check
|
|
|
65
67
|
|
|
66
68
|
For HUMAIN Code CLI contribution instructions, see [CONTRIBUTING.md](../../CONTRIBUTING.md) and [Development](docs/development.md). Upstream Pi contributions follow the linked upstream [CONTRIBUTING.md](https://github.com/earendil-works/pi/blob/main/CONTRIBUTING.md) and [AGENTS.md](https://github.com/earendil-works/pi/blob/main/AGENTS.md).
|
|
67
69
|
|
|
68
|
-
HUMAIN Code CLI also bundles web access, has built-in MCP support (see [MCP](docs/mcp.md)), and supports HUMAIN Node and Forge/DeployNow integrations. See [HUMAIN Code CLI](docs/humain-code.md) for those fork-specific workflows.
|
|
70
|
+
HUMAIN Code CLI also bundles web access, has built-in MCP support (see [MCP](docs/mcp.md)), and supports [HUMAIN Gateway](https://gateway.humain.services), HUMAIN Node, and Forge/DeployNow integrations. See [HUMAIN Code CLI](docs/humain-code.md) for those fork-specific workflows.
|
|
69
71
|
|
|
70
72
|
## License
|
|
71
73
|
|
|
@@ -23,6 +23,6 @@ export interface MonitorConnection {
|
|
|
23
23
|
createClient(options?: AgentMonitorClientOptions): AgentMonitorClient;
|
|
24
24
|
}
|
|
25
25
|
export declare function monitorLaunchSpec(runtime?: LaunchRuntime): BrokerLaunchSpec;
|
|
26
|
-
/** Throws when the agent directory cannot be used safely. */
|
|
27
|
-
export declare function defaultMonitorConnection(agentDir?: string): MonitorConnection;
|
|
26
|
+
/** Throws when the agent directory cannot be used safely. `startupTimeoutMs` defaults to ensureBroker's. */
|
|
27
|
+
export declare function defaultMonitorConnection(agentDir?: string, startupTimeoutMs?: number): MonitorConnection;
|
|
28
28
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/agent-monitor/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAK3C,OAAO,EACN,KAAK,gBAAgB,EAGrB,KAAK,aAAa,EAClB,MAAM,kCAAkC,CAAC;AAI1C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EAON,KAAK,aAAa,EAClB,MAAM,eAAe,CAAC;AAIvB,MAAM,WAAW,yBAAyB;IACzC,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,gFAAgF;AAChF,qBAAa,kBAAmB,SAAQ,YAAY;IACnD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,MAAM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,MAAM,EAAE,OAAO,GAAE,yBAA8B,EAItE;IAED,WAAW,IAAI,OAAO,CAErB;IAED,OAAO,CAAC,YAAY,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqD5E;IAED,2FAA2F;IAC3F,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAElC;IAEK,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAGhC;CACD;AAED,MAAM,WAAW,iBAAiB;IACjC,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,YAAY,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,kBAAkB,CAAC;CACtE;AAED,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,aAAqC,GAAG,gBAAgB,CAKlG;AAED,4GAA4G;AAC5G,wBAAgB,wBAAwB,CACvC,QAAQ,GAAE,MAAsB,EAChC,gBAAgB,CAAC,EAAE,MAAM,GACvB,iBAAiB,CAcnB"}
|
|
@@ -92,8 +92,8 @@ export function monitorLaunchSpec(runtime = detectLaunchRuntime()) {
|
|
|
92
92
|
}
|
|
93
93
|
return getInternalCommandLaunchSpec(runtime, [AGENT_MONITOR_COMMAND]);
|
|
94
94
|
}
|
|
95
|
-
/** Throws when the agent directory cannot be used safely. */
|
|
96
|
-
export function defaultMonitorConnection(agentDir = getAgentDir()) {
|
|
95
|
+
/** Throws when the agent directory cannot be used safely. `startupTimeoutMs` defaults to ensureBroker's. */
|
|
96
|
+
export function defaultMonitorConnection(agentDir = getAgentDir(), startupTimeoutMs) {
|
|
97
97
|
const paths = resolveAgentMonitorPaths(agentDir);
|
|
98
98
|
return {
|
|
99
99
|
ensureMonitor: () => ensureBroker({
|
|
@@ -102,6 +102,7 @@ export function defaultMonitorConnection(agentDir = getAgentDir()) {
|
|
|
102
102
|
launch: monitorLaunchSpec(),
|
|
103
103
|
role: AGENT_MONITOR_ROLE,
|
|
104
104
|
protocol: AGENT_MONITOR_PROTOCOL,
|
|
105
|
+
startupTimeoutMs,
|
|
105
106
|
}),
|
|
106
107
|
createClient: (options) => new AgentMonitorClient(paths.socketPath, options),
|
|
107
108
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/agent-monitor/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAEN,mBAAmB,EACnB,4BAA4B,GAE5B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EACN,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,EAClB,wBAAwB,EACxB,aAAa,EACb,wBAAwB,GAExB,MAAM,eAAe,CAAC;AAEvB,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAMhC,gFAAgF;AAChF,MAAM,OAAO,kBAAmB,SAAQ,YAAY;IAClC,UAAU,CAAS;IAC5B,MAAM,CAAyB;IAC/B,SAAS,GAAG,KAAK,CAAC;IACT,KAAK,CAAU;IAEhC,YAAY,UAAkB,EAAE,OAAO,GAA8B,EAAE;QACtE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC;IACrC,CAAC;IAED,WAAW;QACV,OAAO,IAAI,CAAC,SAAS,CAAC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,EAAE,sBAAsB;YAChC,gBAAgB;SAChB,CAAC;QACH,YAAY,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,kBAAkB,CAAC,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC;KAC5E,CAAC;AACH,CAAC","sourcesContent":["import { EventEmitter } from \"node:events\";\nimport { realpathSync } from \"node:fs\";\nimport net from \"node:net\";\nimport { join } from \"node:path\";\nimport { getAgentDir, getPackageDir } from \"../config.ts\";\nimport {\n\ttype BrokerLaunchSpec,\n\tdetectLaunchRuntime,\n\tgetInternalCommandLaunchSpec,\n\ttype LaunchRuntime,\n} from \"../coordination/client/launch.ts\";\nimport { ensureBroker } from \"../coordination/client/spawn.ts\";\nimport { createMessageReader, writeMessage } from \"../coordination/transport/framing.ts\";\nimport { assertPrivateSocket } from \"../coordination/transport/paths.ts\";\nimport type { SessionRegistration } from \"../coordination/transport/types.ts\";\nimport {\n\tAGENT_MONITOR_COMMAND,\n\tAGENT_MONITOR_PROTOCOL,\n\tAGENT_MONITOR_ROLE,\n\tMAX_SNAPSHOT_FRAME_BYTES,\n\tparseSnapshot,\n\tresolveAgentMonitorPaths,\n\ttype SessionReport,\n} from \"./protocol.ts\";\n\nconst CONNECT_TIMEOUT_MS = 2000;\n\nexport interface AgentMonitorClientOptions {\n\tunref?: boolean;\n}\n\n/** One monitor connection. Fits ConnectionSupervisor, which owns reconnects. */\nexport class AgentMonitorClient extends EventEmitter {\n\tprivate readonly socketPath: string;\n\tprivate socket: net.Socket | undefined;\n\tprivate connected = false;\n\tprivate readonly unref: boolean;\n\n\tconstructor(socketPath: string, options: AgentMonitorClientOptions = {}) {\n\t\tsuper();\n\t\tthis.socketPath = socketPath;\n\t\tthis.unref = options.unref ?? false;\n\t}\n\n\tisConnected(): boolean {\n\t\treturn this.connected;\n\t}\n\n\tconnect(registration: SessionRegistration, _sessionId: string): Promise<void> {\n\t\tassertPrivateSocket(this.socketPath);\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst socket = net.connect(this.socketPath);\n\t\t\tif (this.unref) socket.unref();\n\t\t\tthis.socket = socket;\n\t\t\tlet settled = false;\n\t\t\tconst fail = (error: Error) => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tsocket.destroy();\n\t\t\t\treject(error);\n\t\t\t};\n\t\t\tconst timer = setTimeout(() => fail(new Error(\"Agent monitor did not answer\")), CONNECT_TIMEOUT_MS);\n\t\t\tif (this.unref) timer.unref();\n\t\t\tsocket.on(\n\t\t\t\t\"data\",\n\t\t\t\tcreateMessageReader(\n\t\t\t\t\t(message) => {\n\t\t\t\t\t\tconst type = (message as { type?: unknown } | null)?.type;\n\t\t\t\t\t\tif (type === \"welcome\" && !settled) {\n\t\t\t\t\t\t\tsettled = true;\n\t\t\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\t\t\tthis.connected = true;\n\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t} else if (type === \"incompatible\") {\n\t\t\t\t\t\t\tfail(new Error(\"Agent monitor runs a different HUMAIN version\"));\n\t\t\t\t\t\t} else if (type === \"snapshot\") {\n\t\t\t\t\t\t\tconst snapshot = parseSnapshot(message);\n\t\t\t\t\t\t\tif (snapshot) this.emit(\"snapshot\", snapshot);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t(error) => socket.destroy(error),\n\t\t\t\t\tMAX_SNAPSHOT_FRAME_BYTES,\n\t\t\t\t),\n\t\t\t);\n\t\t\tsocket.on(\"connect\", () =>\n\t\t\t\twriteMessage(socket, {\n\t\t\t\t\ttype: \"hello\",\n\t\t\t\t\tprotocol: AGENT_MONITOR_PROTOCOL.name,\n\t\t\t\t\tversion: AGENT_MONITOR_PROTOCOL.version,\n\t\t\t\t\tpid: registration.pid,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tsocket.on(\"error\", (error) => fail(error));\n\t\t\tsocket.on(\"close\", () => {\n\t\t\t\tconst wasConnected = this.connected;\n\t\t\t\tthis.connected = false;\n\t\t\t\tif (!settled) fail(new Error(\"Agent monitor closed the connection\"));\n\t\t\t\telse if (wasConnected) this.emit(\"disconnected\");\n\t\t\t});\n\t\t});\n\t}\n\n\t/** Never blocks: writeMessage queues, and destroys a socket whose peer stopped reading. */\n\treport(report: SessionReport): void {\n\t\tif (this.connected && this.socket) writeMessage(this.socket, report);\n\t}\n\n\tasync disconnect(): Promise<void> {\n\t\tthis.socket?.destroy();\n\t\tthis.socket = undefined;\n\t}\n}\n\nexport interface MonitorConnection {\n\tensureMonitor(): Promise<void>;\n\tcreateClient(options?: AgentMonitorClientOptions): AgentMonitorClient;\n}\n\nexport function monitorLaunchSpec(runtime: LaunchRuntime = detectLaunchRuntime()): BrokerLaunchSpec {\n\tif (runtime === \"bundled-node\") {\n\t\treturn { command: process.execPath, args: [join(getPackageDir(), \"dist\", \"bundle\", \"agent-monitor.js\")] };\n\t}\n\treturn getInternalCommandLaunchSpec(runtime, [AGENT_MONITOR_COMMAND]);\n}\n\n/** Throws when the agent directory cannot be used safely. `startupTimeoutMs` defaults to ensureBroker's. */\nexport function defaultMonitorConnection(\n\tagentDir: string = getAgentDir(),\n\tstartupTimeoutMs?: number,\n): MonitorConnection {\n\tconst paths = resolveAgentMonitorPaths(agentDir);\n\treturn {\n\t\tensureMonitor: () =>\n\t\t\tensureBroker({\n\t\t\t\tpaths,\n\t\t\t\tagentDir: realpathSync(agentDir),\n\t\t\t\tlaunch: monitorLaunchSpec(),\n\t\t\t\trole: AGENT_MONITOR_ROLE,\n\t\t\t\tprotocol: AGENT_MONITOR_PROTOCOL,\n\t\t\t\tstartupTimeoutMs,\n\t\t\t}),\n\t\tcreateClient: (options) => new AgentMonitorClient(paths.socketPath, options),\n\t};\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url);
|
|
2
2
|
var __require=(x=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(x,{get:(a,b)=>(typeof require<"u"?require:a)[b]}):x)(function(x){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+x+'" is not supported')});var procEnvCache=null;function getBunSandboxEnvValue(name){if(!(typeof process>"u"||!process.versions?.bun||Object.keys(process.env).length>0)){if(procEnvCache===null){procEnvCache=new Map;try{let{readFileSync}=__require("node:fs"),data=readFileSync("/proc/self/environ","utf-8");for(let entry of data.split("\0")){let idx=entry.indexOf("=");idx>0&&procEnvCache.set(entry.slice(0,idx),entry.slice(idx+1))}}catch{}}return procEnvCache.get(name)}}function getProviderEnvValue(name,env){return env?.[name]||
|
|
3
|
-
(typeof process<"u"?process.env[name]:void 0)||getBunSandboxEnvValue(name)||void 0}import{createServer}from"node:http";var LOGO_SVG='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0
|
|
4
|
-
details?escapeHtml(options.details):void 0;return`<!doctype html>
|
|
3
|
+
(typeof process<"u"?process.env[name]:void 0)||getBunSandboxEnvValue(name)||void 0}import{timingSafeEqual}from"node:crypto";import{createServer}from"node:http";var LOGO_SVG='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 15 14" role="img" aria-label="HUMAIN Code"><path fill="#f5f7f7" d="M0 0h6v2H2v10h4v2H0Zm9 0h6v14H9v-2h4V2H9Z"/><path fill="#00b89c" d="M3 4h9v2H3Zm0 4h9v2H3Z"/></svg>';function escapeHtml(value){return value.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'")}function renderPage(options){let title=escapeHtml(options.title),heading=escapeHtml(options.heading),message=escapeHtml(
|
|
4
|
+
options.message),details=options.details?escapeHtml(options.details):void 0;return`<!doctype html>
|
|
5
5
|
<html lang="en">
|
|
6
6
|
<head>
|
|
7
7
|
<meta charset="utf-8" />
|
|
@@ -75,13 +75,14 @@ details?escapeHtml(options.details):void 0;return`<!doctype html>
|
|
|
75
75
|
</main>
|
|
76
76
|
</body>
|
|
77
77
|
</html>`}function oauthSuccessHtml(message){return renderPage({title:"Authentication successful",heading:"Authentication successful",message})}function oauthErrorHtml(message,details){return renderPage({title:"Authentication failed",heading:"Authentication failed",message,details})}var ALLOWED_ERROR_CODES=new Set(["invalid_request","invalid_client","invalid_grant","unauthorized_client","unsupported_grant_type","invalid_scope","access_denied","unsupported_response_type","server_error","temporarily_unavailable","invalid_token","insufficient_scope","authorization_pending","slow_down","expired_token","invalid_redirect_uri","invalid_client_metadata","invalid_software_statement","unapproved_software_statement","deviceauth_authorization_pending","invalid_request_error","rate_limi\
|
|
78
|
-
t_exceeded","usage_limit_reached","previous_response_not_found","websocket_connection_limit_reached"]);function safeOAuthErrorCode(body){let json;try{json=JSON.parse(body)}catch{return}if(typeof json!="object"||json===null)return;let error=json.error,candidate=typeof error=="object"&&error!==null?error.code??error.type:error;return typeof candidate=="string"&&ALLOWED_ERROR_CODES.has(candidate)?candidate:void 0}function sendPage(response,status,html){response.writeHead(status,{"content-type":"text/html; charset=utf-8","cache-control":"no-store"}),response.end(html)}async function startOAuthCallbackServer(options){let{providerName,signal}=options;if(signal?.aborted)throw new Error("Login cancelled");let resolveWait=()=>{},rejectWait=()=>{},
|
|
79
|
-
"Login cancelled")}),finish=result=>{settled||(settled=!0,timer&&clearTimeout(timer),signal?.removeEventListener("abort",onAbort),"error"in result?rejectWait(result.error):resolveWait(result.value))},server=createServer((request,response)=>{(async()=>{let url=new URL(request.url??"/","http://localhost");if(request.method!==
|
|
80
|
-
|
|
81
|
-
searchParams.get("
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
t_exceeded","usage_limit_reached","previous_response_not_found","websocket_connection_limit_reached"]);function safeOAuthErrorCode(body){let json;try{json=JSON.parse(body)}catch{return}if(typeof json!="object"||json===null)return;let error=json.error,candidate=typeof error=="object"&&error!==null?error.code??error.type:error;return typeof candidate=="string"&&ALLOWED_ERROR_CODES.has(candidate)?candidate:void 0}function stateMatches(received,expected){if(received===null)return!1;let a=Buffer.from(received),b=Buffer.from(expected);return a.length===b.length&&timingSafeEqual(a,b)}function sendPage(response,status,html){response.writeHead(status,{"content-type":"text/html; charset=utf-8","cache-control":"no-store"}),response.end(html)}async function startOAuthCallbackServer(options){let{providerName,signal}=options;if(signal?.aborted)throw new Error("Login cancelled");let resolveWait=()=>{},rejectWait=()=>{},
|
|
79
|
+
waitPromise=new Promise((resolve,reject)=>{resolveWait=resolve,rejectWait=reject});waitPromise.catch(()=>{});let claimed=!1,settled=!1,timer,onAbort=()=>finish({error:new Error("Login cancelled")}),finish=result=>{settled||(settled=!0,timer&&clearTimeout(timer),signal?.removeEventListener("abort",onAbort),"error"in result?rejectWait(result.error):resolveWait(result.value))},server=createServer((request,response)=>{(async()=>{let url=new URL(request.url??"/","http://localhost");if(request.method!==
|
|
80
|
+
"GET"||url.pathname!==options.path){sendPage(response,404,oauthErrorHtml("Callback route not found."));return}if(url.searchParams.getAll("state").length>1||url.searchParams.getAll("code").length>1){sendPage(response,400,oauthErrorHtml("Repeated callback parameters."));return}if(options.state!==void 0&&!stateMatches(url.searchParams.get("state"),options.state)){sendPage(response,400,oauthErrorHtml("State mismatch."));return}if(claimed||settled){sendPage(response,409,oauthErrorHtml("This sign-in h\
|
|
81
|
+
as already been handled."));return}let error=url.searchParams.get("error");if(error){let safeErrorCode=safeOAuthErrorCode(JSON.stringify({error}));sendPage(response,400,oauthErrorHtml(`${providerName} authorization failed.`,safeErrorCode)),finish({error:new Error(`${providerName} authorization failed${safeErrorCode?`: ${safeErrorCode}`:""}`)});return}let code=url.searchParams.get("code");if(!code){sendPage(response,400,oauthErrorHtml("Missing authorization code."));return}claimed=!0;try{let value=await options.
|
|
82
|
+
complete(code);sendPage(response,200,oauthSuccessHtml(`Signed in to ${providerName}. You may now close this page.`)),finish({value})}catch(error2){let failure=error2 instanceof Error?error2:new Error(String(error2));sendPage(response,502,oauthErrorHtml(`${providerName} sign-in failed.`,"Return to the terminal for details.")),finish({error:failure})}})()});await new Promise((resolve,reject)=>{server.once("error",reject),server.listen(options.port,options.host,()=>{server.off("error",reject),resolve()})});
|
|
83
|
+
let address=server.address();if(!address||typeof address=="string")throw server.close(),new Error("OAuth callback server did not bind to TCP");server.on("error",error=>finish({error})),signal?.addEventListener("abort",onAbort,{once:!0}),options.timeoutMs!==void 0&&(timer=setTimeout(()=>finish({error:new Error(`${providerName} sign-in timed out`)}),options.timeoutMs));let redirectHost=options.redirectHost??options.host;return{redirectUri:`http://${redirectHost.includes(":")?`[${redirectHost}]`:redirectHost}\
|
|
84
|
+
:${address.port}${options.path}`,wait:()=>waitPromise,cancel:()=>{claimed||finish({value:void 0})},close:()=>{finish({error:new Error("OAuth callback server closed")}),server.close()}}}async function waitForCallbackOrManualInput(interaction,callback,prompt){let manualAbort=new AbortController,manualError,manual=interaction.prompt({type:"manual_code",...prompt,signal:manualAbort.signal}).then(input=>(callback?.cancel(),input)).catch(error=>{manualError=error instanceof Error?error:new Error(String(
|
|
85
|
+
error)),callback?.cancel()});try{let value=await callback?.wait();if(manualError)throw manualError;if(value!==void 0)return{type:"callback",value};let input=await manual;if(manualError)throw manualError;return{type:"manual",input:input??""}}finally{manualAbort.abort()}}function base64urlEncode(bytes){let binary="";for(let byte of bytes)binary+=String.fromCharCode(byte);return btoa(binary).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}async function generatePKCE(){let verifierBytes=new Uint8Array(32);crypto.getRandomValues(verifierBytes);let verifier=base64urlEncode(verifierBytes),data=new TextEncoder().encode(verifier),hashBuffer=await crypto.subtle.digest("SHA-256",data),challenge=base64urlEncode(new Uint8Array(hashBuffer));return{verifier,challenge}}var decode=s=>atob(s),CLIENT_ID=decode("OWQxYzI1MGEtZTYxYi00NGQ5LTg4ZWQtNTk0NGQxOTYyZjVl"),AUTHORIZE_URL="https://claude.ai/oauth/authorize",TOKEN_URL="https://platform.claude.com/v1/oauth/token",CALLBACK_HOST=getProviderEnvValue("PI_OAUTH_CALLBACK_HOST")||"127.0.0.1",CALLBACK_PORT=53692,CALLBACK_PATH="/callback",REDIRECT_URI=`http://localhost:${CALLBACK_PORT}${CALLBACK_PATH}`,COPY_CODE_REDIRECT_URI="https://platform.claude.com/oauth/code/callback",ANTHROPIC_BROWSER_LOGIN_METHOD="browser",ANTHROPIC_COPY_CODE_LOGIN_METHOD="\
|
|
85
86
|
copy_code",SCOPES="org:create_api_key user:profile user:inference user:sessions:claude_code user:mcp_servers user:file_upload";function parseAuthorizationInput(input){let value=input.trim();if(!value)return{};try{let url=new URL(value);return{code:url.searchParams.get("code")??void 0,state:url.searchParams.get("state")??void 0}}catch{}if(value.includes("#")){let[code,state]=value.split("#",2);return{code,state}}if(value.includes("code=")){let params=new URLSearchParams(value);return{code:params.
|
|
86
87
|
get("code")??void 0,state:params.get("state")??void 0}}return{code:value}}function formatErrorDetails(error){if(error instanceof Error){let details=[`${error.name}: ${error.message}`],errorWithCode=error;return errorWithCode.code&&details.push(`code=${errorWithCode.code}`),typeof errorWithCode.errno<"u"&&details.push(`errno=${String(errorWithCode.errno)}`),typeof error.cause<"u"&&details.push(`cause=${formatErrorDetails(error.cause)}`),error.stack&&details.push(`stack=${error.stack}`),details.join(
|
|
87
88
|
"; ")}return String(error)}async function postJson(url,body,signal){let response=await fetch(url,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(body),signal:AbortSignal.any([signal,AbortSignal.timeout(3e4)])}),responseBody=await response.text();if(!response.ok){let code=safeOAuthErrorCode(responseBody);throw new Error(`HTTP request failed. status=${response.status}; url=${url}${code?`; error=${code}`:""}`)}return responseBody}function parseTokenResponse(responseBody,requestName){
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url);
|
|
2
|
-
import{mcpNamespace,require_proper_lockfile,validateMcpServerConfig}from"./chunk-
|
|
2
|
+
import{mcpNamespace,require_proper_lockfile,validateMcpServerConfig}from"./chunk-L2VKM23Q.js";import{CONFIG_DIR_NAME,canonicalizePath,resolvePath,stripBom}from"./chunk-ZI7TK7HM.js";import{__toESM}from"./chunk-JXWJOIH4.js";import{spawn}from"node:child_process";function openBrowser(target){let[cmd,args]=process.platform==="darwin"?["open",[target]]:process.platform==="win32"?["rundll32",["url.dll,FileProtocolHandler",target]]:["xdg-open",[target]];spawn(cmd,args,{stdio:"ignore",detached:!0}).on("error",()=>{}).unref()}var import_proper_lockfile=__toESM(require_proper_lockfile(),1);import{existsSync,mkdirSync,readFileSync,writeFileSync}from"node:fs";import{homedir}from"node:os";import{dirname,join}from"node:path";var TRUST_REQUIRING_PROJECT_CONFIG_RESOURCES=["settings.json","mcp.json","extensions","skills","prompts","themes","SYSTEM.md","APPEND_SYSTEM.md"];function normalizeCwd(cwd){return canonicalizePath(resolvePath(cwd))}function findNearestTrustEntry(data,cwd){let currentDir=normalizeCwd(cwd);for(;;){let value=data[currentDir];if(value===!0||value===!1)return{path:currentDir,decision:value};let parentDir=dirname(currentDir);if(parentDir===currentDir)return null;currentDir=parentDir}}function getProjectTrustParentPath(cwd){
|
|
3
3
|
let trustPath=normalizeCwd(cwd),parentDir=dirname(trustPath);return parentDir===trustPath?void 0:parentDir}function getProjectTrustOptions(cwd,options){let trustPath=normalizeCwd(cwd),trustOptions=[{label:"Trust",trusted:!0,updates:[{path:trustPath,decision:!0}],savedPath:trustPath}],parentPath=getProjectTrustParentPath(cwd);return parentPath!==void 0&&trustOptions.push({label:`Trust parent folder (${parentPath})`,trusted:!0,updates:[{path:parentPath,decision:!0},{path:trustPath,decision:null}],
|
|
4
4
|
savedPath:parentPath}),options?.includeSessionOnly&&trustOptions.push({label:"Trust (this session only)",trusted:!0,updates:[]}),trustOptions.push({label:"Do not trust",trusted:!1,updates:[{path:trustPath,decision:!1}],savedPath:trustPath}),options?.includeSessionOnly&&trustOptions.push({label:"Do not trust (this session only)",trusted:!1,updates:[]}),trustOptions}function readTrustFile(path){if(!existsSync(path))return{};let parsed;try{parsed=JSON.parse(stripBom(readFileSync(path,"utf-8")))}catch(error){
|
|
5
5
|
let message=error instanceof Error?error.message:String(error);throw new Error(`Failed to read trust store ${path}: ${message}`)}if(typeof parsed!="object"||parsed===null||Array.isArray(parsed))throw new Error(`Invalid trust store ${path}: expected an object`);let data={};for(let[key,value]of Object.entries(parsed)){if(value!==!0&&value!==!1&&value!==null)throw new Error(`Invalid trust store ${path}: value for ${JSON.stringify(key)} must be true, false, or null`);data[key]=value}return data}function writeTrustFile(path,data){
|