@bitkyc08/opencodex 2.99.0 → 2.100.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS_INSTALL.md +19 -1
- package/README.md +37 -33
- package/SPONSORS.md +5 -1
- package/bin/ocx.mjs +1 -1
- package/gui/dist/assets/{App-C1hGwaN1.css → App-COo8Yopd.css} +1 -1
- package/gui/dist/assets/App-CitvEefy.js +59 -0
- package/gui/dist/assets/Tray-CeKVWQyB.js +1 -0
- package/gui/dist/assets/{brand-mark-wzPe3R-J.js → brand-mark-M92UnxX2.js} +1 -1
- package/gui/dist/assets/index-BP47do6-.js +94 -0
- package/gui/dist/assets/index-DmDooSAG.css +2 -0
- package/gui/dist/assets/{segment-thumb-features-fYEMxBaW.js → segment-thumb-features-CcxZBnxv.js} +1 -1
- package/gui/dist/classic/assets/App-aYgIQMxI.js +58 -0
- package/gui/dist/classic/assets/{Tray-BqZueZOx.js → Tray-D8jfUXpQ.js} +1 -1
- package/gui/dist/classic/assets/index-CfGqHooN.js +94 -0
- package/gui/dist/classic/assets/quota-summary-R-ih7OlS.js +1 -0
- package/gui/dist/classic/index.html +1 -1
- package/gui/dist/index.html +2 -2
- package/native/ocx-child/Cargo.lock +215 -0
- package/native/ocx-child/Cargo.toml +31 -0
- package/native/ocx-child/src/cli.rs +1901 -0
- package/native/ocx-child/src/codex_home.rs +429 -0
- package/native/ocx-child/src/codex_settings.rs +231 -0
- package/native/ocx-child/src/daemon.rs +363 -0
- package/native/ocx-child/src/http_wire.rs +619 -0
- package/native/ocx-child/src/journal.rs +977 -0
- package/native/ocx-child/src/lib.rs +22 -0
- package/native/ocx-child/src/main.rs +9 -0
- package/native/ocx-child/src/parity.rs +102 -0
- package/native/ocx-child/src/platform.rs +1487 -0
- package/native/ocx-child/src/relay.rs +1288 -0
- package/native/ocx-child/src/relay_auth.rs +166 -0
- package/native/ocx-child/src/routes.rs +236 -0
- package/native/ocx-child/src/state.rs +190 -0
- package/native/ocx-child/src/test_hooks.rs +58 -0
- package/native/ocx-child/src/toml_surgeon.rs +1156 -0
- package/package.json +8 -2
- package/src/adapters/anthropic.ts +28 -2
- package/src/adapters/claude-cli/adapter.ts +5 -25
- package/src/adapters/claude-cli/instruction-images.ts +31 -0
- package/src/adapters/claude-cli/stable-replay.ts +42 -14
- package/src/adapters/claude-cli/usage-admission.ts +53 -64
- package/src/adapters/coding-agent/protocol.ts +1 -1
- package/src/adapters/devin/live-models.ts +3 -0
- package/src/adapters/google-http.ts +3 -0
- package/src/adapters/google-vertex-key-project.ts +10 -2
- package/src/adapters/google.ts +40 -8
- package/src/adapters/kiro/usage.ts +3 -13
- package/src/adapters/openai-responses/passthrough.ts +5 -2
- package/src/adapters/openai-responses/request-strips.ts +32 -0
- package/src/adapters/openai-responses/tool-schema.ts +9 -4
- package/src/chat/inbound.ts +1 -1
- package/src/claude/auth-detect.ts +26 -8
- package/src/claude/inbound-content-options.ts +18 -3
- package/src/claude/inbound.ts +5 -2
- package/src/cli/bundled-bun-diagnostic.ts +91 -0
- package/src/cli/capabilities-agents-routing.ts +2 -2
- package/src/cli/capabilities-observe-system.ts +60 -0
- package/src/cli/combo-input.ts +6 -0
- package/src/cli/combo-result.ts +1 -1
- package/src/cli/combo.ts +4 -0
- package/src/cli/config-command.ts +16 -2
- package/src/cli/connect.ts +12 -10
- package/src/cli/dispatch.ts +4 -0
- package/src/cli/doctor.ts +11 -0
- package/src/cli/help.ts +1 -0
- package/src/cli/init.ts +4 -0
- package/src/cli/link-enrollment.ts +152 -25
- package/src/cli/link-local-control.ts +49 -0
- package/src/cli/link.ts +37 -10
- package/src/cli/provider-lifecycle-runtime.ts +4 -2
- package/src/cli/registry.ts +13 -0
- package/src/cli/star-prompt.ts +2 -0
- package/src/cli/status.ts +1 -1
- package/src/cli/telemetry-profile.ts +206 -0
- package/src/cli/telemetry.ts +260 -0
- package/src/client/hub-relay.ts +26 -0
- package/src/client/machine-api.ts +3 -0
- package/src/clients/config-export/t3code.ts +44 -5
- package/src/clients/omo-role-models.ts +1 -1
- package/src/codex/catalog/bundled.ts +44 -2
- package/src/codex/runtime.ts +12 -0
- package/src/codex/shim-restore-lock.ts +67 -30
- package/src/combos/types.ts +21 -1
- package/src/config/atomic-write.ts +24 -1
- package/src/config/diagnostics.ts +15 -0
- package/src/config/live-reconcile.ts +17 -0
- package/src/config/load-degrade.ts +16 -0
- package/src/config/provider-validation.ts +29 -0
- package/src/config/schema/config-schema.ts +24 -0
- package/src/config/schema/leaf-validators.ts +17 -0
- package/src/config/telemetry-carry.ts +30 -0
- package/src/config.ts +13 -1
- package/src/generated/compatibility-version.json +405 -153
- package/src/generated/model-metadata.ts +3 -3
- package/src/integrations/aside-profiles.ts +7 -1
- package/src/integrations/owned-refresh.ts +9 -2
- package/src/lab/artifacts/secure-fs.ts +12 -11
- package/src/lab/fabric/scratch.ts +11 -9
- package/src/lab/public/community.ts +2 -3
- package/src/lab/public/file-safety.ts +18 -20
- package/src/lab/public/mutation-lock.ts +109 -337
- package/src/lab/public/private-file.ts +4 -3
- package/src/lib/bun-runtime-preflight.ts +1 -1
- package/src/lib/codex-catalog-read-only.ts +122 -0
- package/src/lib/config-ownership.ts +49 -18
- package/src/lib/errors.ts +11 -0
- package/src/lib/gcp-adc.ts +167 -48
- package/src/lib/jsonc.ts +4 -2
- package/src/lib/local-control-socket.ts +88 -0
- package/src/lib/privacy.ts +15 -0
- package/src/lib/provider-client-headers.ts +3 -0
- package/src/lib/token-estimate.ts +13 -2
- package/src/link/child-binary-source.ts +228 -0
- package/src/link/ephemeral-child.ts +45 -0
- package/src/link/remote-plant.ts +306 -0
- package/src/link/remote-windows.ts +59 -5
- package/src/link/ssh-argv.ts +71 -8
- package/src/link/status-projection.ts +2 -0
- package/src/link/store.ts +5 -1
- package/src/oauth/claude-keychain-read.ts +165 -0
- package/src/oauth/local-token-detect.ts +14 -17
- package/src/protocols/envelope.ts +20 -2
- package/src/providers/api-key-selection.ts +8 -2
- package/src/providers/claude-cli-usage-state.ts +93 -0
- package/src/providers/github-copilot-auto.ts +25 -5
- package/src/providers/meta-muse-plan-refusal.ts +94 -0
- package/src/providers/model-rename-fields.ts +3 -0
- package/src/providers/quota/vendor-probes-key.ts +23 -4
- package/src/providers/quota/vendor-probes-oauth.ts +59 -0
- package/src/providers/quota/workbuddy.ts +2 -2
- package/src/providers/quota.ts +25 -18
- package/src/providers/registry/entries-core.ts +7 -4
- package/src/providers/registry/entries-extended.ts +39 -7
- package/src/providers/registry/model-seeds.ts +10 -2
- package/src/providers/resolved-model-policy.ts +4 -0
- package/src/providers/routed-config.ts +30 -3
- package/src/providers/stale-no-vision-seed-migration.ts +7 -0
- package/src/providers/vertex-environment-authority.ts +50 -0
- package/src/providers/workbuddy-credit-balance.ts +38 -6
- package/src/quota-pool/assemble.ts +14 -6
- package/src/router.ts +1 -0
- package/src/server/adapter-resolve.ts +11 -6
- package/src/server/audio-dictation.ts +21 -7
- package/src/server/auth-cors.ts +19 -0
- package/src/server/background-lifecycle.ts +71 -0
- package/src/server/chat-completions.ts +2 -0
- package/src/server/claude-messages.ts +30 -3
- package/src/server/index/live-sideband.ts +15 -1
- package/src/server/index/local-control-listener.ts +515 -0
- package/src/server/index/optional-listeners.ts +21 -1
- package/src/server/index/serve-options.ts +4 -3
- package/src/server/index/websocket-handler.ts +2 -0
- package/src/server/index.ts +3 -0
- package/src/server/management/combo-routes.ts +6 -1
- package/src/server/management/context.ts +1 -0
- package/src/server/management/link-child-preflight.ts +74 -0
- package/src/server/management/link-enrollment.ts +190 -25
- package/src/server/management/link-route-state.ts +6 -1
- package/src/server/management/link-routes.ts +27 -9
- package/src/server/management/model-rows.ts +4 -0
- package/src/server/management/oauth-account-routes.ts +9 -4
- package/src/server/management/provider-overwrite-carry.ts +9 -2
- package/src/server/management/provider-routes.ts +14 -0
- package/src/server/management/provider-thinking-display-patch.ts +54 -0
- package/src/server/management/route-registry.ts +7 -0
- package/src/server/management/session-routes.ts +4 -1
- package/src/server/management/telemetry-routes.ts +37 -0
- package/src/server/management/usage-aggregate-cache.ts +290 -67
- package/src/server/management-api.ts +11 -2
- package/src/server/messages-native-preflight.ts +166 -0
- package/src/server/messages-native.ts +143 -43
- package/src/server/messages-shared.ts +14 -0
- package/src/server/proxy-liveness.ts +99 -6
- package/src/server/request-log-conversation.ts +18 -2
- package/src/server/request-log.ts +7 -2
- package/src/server/responses/adapter-continuation.ts +1 -0
- package/src/server/responses/adapter-dispatch.ts +11 -28
- package/src/server/responses/adapter-failure-message.ts +68 -0
- package/src/server/responses/combo-stream-preflight.ts +14 -2
- package/src/server/responses/core-auth.ts +26 -5
- package/src/server/responses/core-codex-account.ts +8 -1
- package/src/server/responses/core-combo-failure.ts +6 -1
- package/src/server/responses/core-combo-native.ts +150 -37
- package/src/server/responses/core-combo.ts +15 -9
- package/src/server/responses/core-normalize.ts +1 -0
- package/src/server/responses/core-options.ts +7 -1
- package/src/server/responses/core-pipeline.ts +21 -1
- package/src/server/responses/fetch-helpers.ts +5 -0
- package/src/server/responses/opengateway-completion-guard.ts +7 -3
- package/src/server/responses/passthrough-delivery.ts +8 -1
- package/src/server/responses/passthrough-error.ts +22 -0
- package/src/server/responses/request-prepare.ts +7 -1
- package/src/server/responses/request-transport.ts +28 -5
- package/src/server/responses/run-turn-execution.ts +13 -0
- package/src/server/sse-frame-buffer.ts +5 -0
- package/src/server/ws-bridge.ts +10 -0
- package/src/service/launchd.ts +78 -4
- package/src/telemetry/aggregate.ts +348 -0
- package/src/telemetry/consent.ts +128 -0
- package/src/telemetry/contract.ts +403 -0
- package/src/telemetry/disclosure.ts +19 -0
- package/src/telemetry/install-id.ts +226 -0
- package/src/telemetry/payload.ts +129 -0
- package/src/telemetry/profile/client.ts +150 -0
- package/src/telemetry/profile/contract.ts +288 -0
- package/src/telemetry/profile/disclosure.ts +14 -0
- package/src/telemetry/profile/paths.ts +13 -0
- package/src/telemetry/profile/routes.ts +99 -0
- package/src/telemetry/profile/service.ts +234 -0
- package/src/telemetry/profile/state.ts +189 -0
- package/src/telemetry/profile/sync.ts +276 -0
- package/src/telemetry/routes.ts +183 -0
- package/src/telemetry/scheduler.ts +386 -0
- package/src/telemetry/sender.ts +97 -0
- package/src/telemetry/state.ts +334 -0
- package/src/types/combo-jev-effort-mode.ts +11 -0
- package/src/types/config.ts +3 -0
- package/src/types/provider.ts +11 -1
- package/src/types/request.ts +2 -0
- package/src/types/telemetry.ts +15 -0
- package/src/types/wire.ts +10 -0
- package/src/types.ts +5 -0
- package/src/update/index.ts +7 -1
- package/src/update/minisign.d.mts +17 -0
- package/src/update/minisign.mjs +88 -0
- package/src/update/signed-supply.d.mts +59 -0
- package/src/update/signed-supply.mjs +289 -0
- package/src/update/trust-root.json +38 -0
- package/src/update/update-bounded-json.d.mts +4 -0
- package/src/update/update-bounded-json.mjs +113 -0
- package/src/update/update-bytes.d.mts +2 -0
- package/src/update/update-bytes.mjs +23 -0
- package/src/update/update-candidate-id.d.mts +2 -0
- package/src/update/update-candidate-id.mjs +23 -0
- package/src/update/update-checkpoint-codec.d.mts +33 -0
- package/src/update/update-checkpoint-codec.mjs +217 -0
- package/src/update/update-contracts.d.mts +24 -0
- package/src/update/update-contracts.mjs +207 -0
- package/src/update/update-signature-threshold.d.mts +12 -0
- package/src/update/update-signature-threshold.mjs +47 -0
- package/src/update/update-signed-version.d.mts +5 -0
- package/src/update/update-signed-version.mjs +25 -0
- package/src/update/update-trust-anchor.d.mts +2 -0
- package/src/update/update-trust-anchor.mjs +2 -0
- package/src/usage/cache-diagnostic.ts +195 -50
- package/src/usage/expected-prices.ts +20 -2
- package/src/usage/filter-index.ts +1469 -0
- package/src/usage/ledger-scanner.ts +245 -4
- package/src/usage/source-filter.ts +10 -2
- package/src/usage/summary.ts +16 -0
- package/src/web-search/parse.ts +244 -38
- package/gui/dist/assets/App-BepstgEN.js +0 -59
- package/gui/dist/assets/Tray-BinxbEZo.js +0 -1
- package/gui/dist/assets/index-C-9X2yaI.js +0 -94
- package/gui/dist/assets/index-bnUWypyz.css +0 -2
- package/gui/dist/classic/assets/App-DX88_GCW.js +0 -58
- package/gui/dist/classic/assets/index-fSP71pLB.js +0 -94
- package/gui/dist/classic/assets/quota-summary-y2fl0WBv.js +0 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { lstatSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { getConfigDir } from "../config/paths";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The local control socket (#8184): a Unix-domain socket in a private directory under the
|
|
7
|
+
* OpenCodex home. Only a process running as this user can open it, and nothing that relays TCP
|
|
8
|
+
* (Tailscale Serve on the hub management listener, a reverse proxy) can deliver a request to it,
|
|
9
|
+
* so a request that arrives on it came from this machine through the filesystem. That is the
|
|
10
|
+
* property the TCP loopback listeners cannot offer once a relay targets them.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** sun_path is 104 bytes on macOS and 108 on Linux, both including the terminating NUL. */
|
|
14
|
+
export const LOCAL_CONTROL_SOCKET_PATH_MAX = 103;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Whether the kernel can bind this path. sun_path counts the BYTES of the encoded path, not
|
|
18
|
+
* JavaScript's UTF-16 code units, so a home directory with non-ASCII characters needs a shorter
|
|
19
|
+
* name than path.length suggests.
|
|
20
|
+
*/
|
|
21
|
+
export function localControlSocketPathFits(path: string): boolean {
|
|
22
|
+
return Buffer.byteLength(path, "utf8") <= LOCAL_CONTROL_SOCKET_PATH_MAX;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function localControlSocketSupported(): boolean {
|
|
26
|
+
return process.platform !== "win32" && typeof process.getuid === "function";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function localControlSocketDir(configDir: string = getConfigDir()): string {
|
|
30
|
+
return join(configDir, "run");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** One socket per public port, so two runtimes sharing a home never take each other's. */
|
|
34
|
+
export function localControlSocketPath(port: number, configDir?: string): string {
|
|
35
|
+
return join(localControlSocketDir(configDir), `control-${port}.sock`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* How much of the instance token the socket name keeps. The name only has to differ from the
|
|
40
|
+
* instance it replaces, and the lease already serializes instances, so 32 bits is plenty;
|
|
41
|
+
* keeping it short keeps the private path no longer than the public one (`.c65535.abcdef12` is
|
|
42
|
+
* 16 bytes, `control-65535.sock` is 18), so a home that fits the public path fits this one too.
|
|
43
|
+
*/
|
|
44
|
+
const PRIVATE_SOCKET_TOKEN_CHARS = 8;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The address Bun itself binds for one runtime. It is instance-specific, so a shutdown can only
|
|
48
|
+
* ever unlink its own listener and a restart in the same process cannot collide with the instance
|
|
49
|
+
* it is replacing; the public path above is a hard link to this socket.
|
|
50
|
+
*/
|
|
51
|
+
export function localControlPrivateSocketPath(port: number, token: string, configDir?: string): string {
|
|
52
|
+
return join(localControlSocketDir(configDir), `.c${port}.${token.slice(0, PRIVATE_SOCKET_TOKEN_CHARS)}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The ownership record for one port's public socket. A runtime holds it for as long as it serves
|
|
57
|
+
* the socket, so a second runtime can tell a live incumbent from a crashed predecessor.
|
|
58
|
+
*/
|
|
59
|
+
export function localControlLeasePath(port: number, configDir?: string): string {
|
|
60
|
+
return join(localControlSocketDir(configDir), `.c${port}.lease`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** A real directory, owned by this user, that no other user can enter or list. */
|
|
64
|
+
export function isPrivateSocketDir(dir: string): boolean {
|
|
65
|
+
try {
|
|
66
|
+
const stat = lstatSync(dir);
|
|
67
|
+
return stat.isDirectory() && !stat.isSymbolicLink()
|
|
68
|
+
&& stat.uid === process.getuid!() && (stat.mode & 0o077) === 0;
|
|
69
|
+
} catch {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The socket path a client may send the admin token to, or null. The directory must still be
|
|
76
|
+
* private and the socket must be a socket owned by this user: anything else is not ours.
|
|
77
|
+
*/
|
|
78
|
+
export function usableLocalControlSocket(port: number, configDir?: string): string | null {
|
|
79
|
+
if (!localControlSocketSupported() || !Number.isInteger(port) || port <= 0 || port > 65535) return null;
|
|
80
|
+
const path = localControlSocketPath(port, configDir);
|
|
81
|
+
if (!localControlSocketPathFits(path) || !isPrivateSocketDir(localControlSocketDir(configDir))) return null;
|
|
82
|
+
try {
|
|
83
|
+
const stat = lstatSync(path);
|
|
84
|
+
return stat.isSocket() && stat.uid === process.getuid!() ? path : null;
|
|
85
|
+
} catch {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|
package/src/lib/privacy.ts
CHANGED
|
@@ -16,6 +16,21 @@ export function maskedAccountLabel(value: string | null | undefined): string | u
|
|
|
16
16
|
return maskEmail(value) ?? undefined;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Dashboard account label that follows `privacy.maskEmails` (#8286).
|
|
21
|
+
*
|
|
22
|
+
* Masked mode is exactly {@link maskedAccountLabel}. Unmasked mode is the operator's explicit
|
|
23
|
+
* disclosure choice, so it returns the stored address as-is (trimmed) — the same value the
|
|
24
|
+
* unmasked `email` field already carries — and omits only empty, oversized, or control- or
|
|
25
|
+
* format-character values (bidi overrides, zero-width marks) that could not render as one honest label.
|
|
26
|
+
*/
|
|
27
|
+
export function accountDisplayLabel(value: string | null | undefined, mask: boolean): string | undefined {
|
|
28
|
+
if (mask) return maskedAccountLabel(value);
|
|
29
|
+
const label = value?.trim();
|
|
30
|
+
if (!label || label.length > 254 || /[\p{Cc}\p{Cf}]/u.test(label)) return undefined;
|
|
31
|
+
return label;
|
|
32
|
+
}
|
|
33
|
+
|
|
19
34
|
/**
|
|
20
35
|
* Whether stored account emails are masked in management and CLI projections (#3859).
|
|
21
36
|
*
|
|
@@ -26,6 +26,9 @@ const BLOCKED_FORWARDED_CLIENT_HEADERS = new Set([
|
|
|
26
26
|
|
|
27
27
|
const ALLOWED_FORWARDED_CLIENT_HEADERS = new Set([
|
|
28
28
|
"originator", "x-client-request-id", "x-codex-app-version", "user-agent",
|
|
29
|
+
// Preserve caller-supplied identifiers only when the provider explicitly opts in.
|
|
30
|
+
// Do not admit arbitrary x-codex-* fields or authentication evidence.
|
|
31
|
+
"x-codex-window-id", "x-codex-installation-id",
|
|
29
32
|
]);
|
|
30
33
|
const MAX_FORWARDED_CLIENT_HEADERS = 64;
|
|
31
34
|
|
|
@@ -94,17 +94,28 @@ export function charsPerToken(modelId?: string): number {
|
|
|
94
94
|
*/
|
|
95
95
|
const CJK_CHARS_PER_TOKEN = 1.5;
|
|
96
96
|
|
|
97
|
+
// Reuse a sticky Unicode matcher so astral Han needs no substring or per-character regex.
|
|
98
|
+
const SUPPLEMENTARY_HAN = /\p{Script=Han}/uy;
|
|
99
|
+
|
|
97
100
|
/**
|
|
98
101
|
* Count CJK characters exactly, in one pass, with no allocation and no regex object per char.
|
|
99
102
|
*
|
|
100
|
-
* Ranges: Hangul syllables and jamo, CJK
|
|
103
|
+
* Ranges: Hangul syllables and jamo, BMP CJK ideographs, hiragana/katakana, and astral Han.
|
|
101
104
|
* Surrogate pairs (rare CJK extensions beyond the BMP) are counted as their two code units,
|
|
102
105
|
* which slightly over-counts them — again the safe direction.
|
|
103
106
|
*/
|
|
104
|
-
function countCjk(text: string): number {
|
|
107
|
+
export function countCjk(text: string): number {
|
|
105
108
|
let cjk = 0;
|
|
106
109
|
for (let i = 0; i < text.length; i++) {
|
|
107
110
|
const c = text.charCodeAt(i);
|
|
111
|
+
if (c >= 0xd800 && c <= 0xdbff) {
|
|
112
|
+
SUPPLEMENTARY_HAN.lastIndex = i;
|
|
113
|
+
if (SUPPLEMENTARY_HAN.test(text)) {
|
|
114
|
+
cjk += 2;
|
|
115
|
+
i++;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
108
119
|
if (
|
|
109
120
|
(c >= 0xac00 && c <= 0xd7a3)
|
|
110
121
|
|| (c >= 0x1100 && c <= 0x11ff)
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, lstatSync, readFileSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
5
|
+
import { packageVersion } from "../lib/package-version";
|
|
6
|
+
|
|
7
|
+
export const CHILD_TARGET_TRIPLES = [
|
|
8
|
+
"darwin-arm64",
|
|
9
|
+
"darwin-x64",
|
|
10
|
+
"linux-x64",
|
|
11
|
+
"linux-arm64",
|
|
12
|
+
"windows-x64",
|
|
13
|
+
] as const;
|
|
14
|
+
|
|
15
|
+
export type ChildTargetTriple = typeof CHILD_TARGET_TRIPLES[number];
|
|
16
|
+
export type ChildBinarySourceKind = "env" | "sidecar" | "local-release" | "cache";
|
|
17
|
+
export type PlantUnavailableReason = "unsupported_target" | "artifact_not_found" | "checksum_mismatch";
|
|
18
|
+
|
|
19
|
+
export interface VerifiedChildBinaryArtifact {
|
|
20
|
+
readonly targetTriple: ChildTargetTriple;
|
|
21
|
+
readonly bytes: Uint8Array;
|
|
22
|
+
readonly sizeBytes: number;
|
|
23
|
+
readonly sha256: string;
|
|
24
|
+
readonly source: ChildBinarySourceKind;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type ChildBinaryResolution =
|
|
28
|
+
| { readonly ok: true; readonly artifact: VerifiedChildBinaryArtifact }
|
|
29
|
+
| { readonly ok: false; readonly reason: PlantUnavailableReason };
|
|
30
|
+
|
|
31
|
+
export interface ResolveChildBinaryOptions {
|
|
32
|
+
readonly env?: Record<string, string | undefined>;
|
|
33
|
+
readonly hostPlatform?: NodeJS.Platform;
|
|
34
|
+
readonly hostArch?: string;
|
|
35
|
+
readonly opencodexHome?: string;
|
|
36
|
+
readonly version?: string;
|
|
37
|
+
readonly execPath?: string;
|
|
38
|
+
readonly repoRoot?: string;
|
|
39
|
+
readonly allowLocalRelease?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const MAX_CHILD_BINARY_BYTES = 32 * 1024 * 1024;
|
|
43
|
+
const MAX_SHA256SUMS_BYTES = 256 * 1024;
|
|
44
|
+
const SHA256_HEX = /^[0-9a-f]{64}$/;
|
|
45
|
+
|
|
46
|
+
export function isChildTargetTriple(value: unknown): value is ChildTargetTriple {
|
|
47
|
+
return typeof value === "string" && (CHILD_TARGET_TRIPLES as readonly string[]).includes(value);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function hostChildTargetTriple(
|
|
51
|
+
platform: NodeJS.Platform = process.platform,
|
|
52
|
+
architecture: string = process.arch,
|
|
53
|
+
): ChildTargetTriple | null {
|
|
54
|
+
if (platform === "darwin" && architecture === "arm64") return "darwin-arm64";
|
|
55
|
+
if (platform === "darwin" && architecture === "x64") return "darwin-x64";
|
|
56
|
+
if (platform === "linux" && architecture === "x64") return "linux-x64";
|
|
57
|
+
if (platform === "linux" && architecture === "arm64") return "linux-arm64";
|
|
58
|
+
if (platform === "win32" && architecture === "x64") return "windows-x64";
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function childArtifactFilename(targetTriple: ChildTargetTriple): string {
|
|
63
|
+
return targetTriple.startsWith("windows-") ? `ocx-child-${targetTriple}.exe` : `ocx-child-${targetTriple}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function childPlainExecutableName(targetTriple: ChildTargetTriple): string {
|
|
67
|
+
return targetTriple.startsWith("windows-") ? "ocx-child.exe" : "ocx-child";
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function isSafeDirectory(dirPath: string): boolean {
|
|
71
|
+
try {
|
|
72
|
+
const st = lstatSync(dirPath);
|
|
73
|
+
return st.isDirectory() && !st.isSymbolicLink();
|
|
74
|
+
} catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function readSafeRegularFile(filePath: string, maxBytes: number, hostPlatform: NodeJS.Platform): Uint8Array | null {
|
|
80
|
+
let st;
|
|
81
|
+
try {
|
|
82
|
+
st = lstatSync(filePath);
|
|
83
|
+
} catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
if (!st.isFile() || st.isSymbolicLink()) return null;
|
|
87
|
+
if (st.size <= 0 || st.size > maxBytes) return null;
|
|
88
|
+
if (hostPlatform !== "win32" && (st.mode & 0o022) !== 0) return null;
|
|
89
|
+
let buf: Buffer;
|
|
90
|
+
try {
|
|
91
|
+
buf = readFileSync(filePath);
|
|
92
|
+
} catch {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
if (buf.byteLength <= 0 || buf.byteLength > maxBytes) return null;
|
|
96
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function parseSha256Sums(text: string): Map<string, string> {
|
|
100
|
+
const entries = new Map<string, string>();
|
|
101
|
+
for (const rawLine of text.split(/\r?\n/)) {
|
|
102
|
+
const line = rawLine.trim();
|
|
103
|
+
if (!line || line.startsWith("#")) continue;
|
|
104
|
+
const match = /^([0-9A-Fa-f]{64})\s+\*?([^\s/\\]+)$/.exec(line);
|
|
105
|
+
if (!match) continue;
|
|
106
|
+
entries.set(match[2]!, match[1]!.toLowerCase());
|
|
107
|
+
}
|
|
108
|
+
return entries;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function sha256Hex(bytes: Uint8Array): string {
|
|
112
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function verifyManifestCandidate(
|
|
116
|
+
candidatePath: string,
|
|
117
|
+
targetTriple: ChildTargetTriple,
|
|
118
|
+
source: ChildBinarySourceKind,
|
|
119
|
+
hostPlatform: NodeJS.Platform,
|
|
120
|
+
): ChildBinaryResolution | null {
|
|
121
|
+
let rawStat;
|
|
122
|
+
try {
|
|
123
|
+
rawStat = lstatSync(candidatePath);
|
|
124
|
+
} catch {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const dir = dirname(candidatePath);
|
|
128
|
+
if (!isSafeDirectory(dir) || !rawStat.isFile() || rawStat.isSymbolicLink()) {
|
|
129
|
+
return { ok: false, reason: "checksum_mismatch" };
|
|
130
|
+
}
|
|
131
|
+
const sumsBytes = readSafeRegularFile(join(dir, "SHA256SUMS"), MAX_SHA256SUMS_BYTES, hostPlatform);
|
|
132
|
+
if (!sumsBytes) return { ok: false, reason: "checksum_mismatch" };
|
|
133
|
+
const sums = parseSha256Sums(new TextDecoder("utf-8").decode(sumsBytes));
|
|
134
|
+
const expected = sums.get(basename(candidatePath));
|
|
135
|
+
if (!expected || !SHA256_HEX.test(expected)) return { ok: false, reason: "checksum_mismatch" };
|
|
136
|
+
const bytes = readSafeRegularFile(candidatePath, MAX_CHILD_BINARY_BYTES, hostPlatform);
|
|
137
|
+
if (!bytes) return { ok: false, reason: "checksum_mismatch" };
|
|
138
|
+
const actual = sha256Hex(bytes);
|
|
139
|
+
if (actual !== expected) return { ok: false, reason: "checksum_mismatch" };
|
|
140
|
+
return {
|
|
141
|
+
ok: true,
|
|
142
|
+
artifact: { targetTriple, bytes, sizeBytes: bytes.byteLength, sha256: actual, source },
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** What an operator must do when Home cannot plant ocx-child, for the CLI and the API message. */
|
|
147
|
+
export function plantUnavailableGuidance(reason: string | undefined, targetTriple: string | null, version: string = packageVersion("0.0.0")): string {
|
|
148
|
+
if (reason === "artifact_not_found" && targetTriple && isChildTargetTriple(targetTriple)) {
|
|
149
|
+
const file = childArtifactFilename(targetTriple);
|
|
150
|
+
return "No verified ocx-child build for " + targetTriple + " is available on this Home. Put " + file + " and a SHA256SUMS file that lists it in the directory named by OPENCODEX_CHILD_BIN_DIR, or in $OPENCODEX_HOME/cache/ocx-child/" + version + "/, then try again.";
|
|
151
|
+
}
|
|
152
|
+
if (reason === "checksum_mismatch") {
|
|
153
|
+
return "An ocx-child build for " + (targetTriple ?? "this target") + " was found on this Home but failed verification: it needs a matching SHA256SUMS entry, must not be a symlink, and must not be group- or world-writable.";
|
|
154
|
+
}
|
|
155
|
+
return "ocx-child has no build for this Child's platform (" + (targetTriple ?? "unknown target") + ").";
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function resolveChildBinarySource(
|
|
159
|
+
targetTriple: ChildTargetTriple | null,
|
|
160
|
+
options: ResolveChildBinaryOptions = {},
|
|
161
|
+
): ChildBinaryResolution {
|
|
162
|
+
if (!targetTriple || !isChildTargetTriple(targetTriple)) return { ok: false, reason: "unsupported_target" };
|
|
163
|
+
const env = options.env ?? process.env;
|
|
164
|
+
const hostPlatform = options.hostPlatform ?? process.platform;
|
|
165
|
+
const hostArch = options.hostArch ?? process.arch;
|
|
166
|
+
const hostTriple = hostChildTargetTriple(hostPlatform, hostArch);
|
|
167
|
+
const artifactFile = childArtifactFilename(targetTriple);
|
|
168
|
+
const plainExe = childPlainExecutableName(targetTriple);
|
|
169
|
+
const repoRoot = options.repoRoot ?? resolve(import.meta.dir, "..", "..");
|
|
170
|
+
|
|
171
|
+
const envDir = env.OPENCODEX_CHILD_BIN_DIR?.trim();
|
|
172
|
+
if (envDir) {
|
|
173
|
+
if (!isSafeDirectory(envDir)) {
|
|
174
|
+
try { lstatSync(envDir); return { ok: false, reason: "checksum_mismatch" }; } catch { /* absent */ }
|
|
175
|
+
} else {
|
|
176
|
+
const envCandidates = [
|
|
177
|
+
join(envDir, artifactFile),
|
|
178
|
+
join(envDir, targetTriple, plainExe),
|
|
179
|
+
...(targetTriple === hostTriple ? [join(envDir, plainExe)] : []),
|
|
180
|
+
];
|
|
181
|
+
for (const candidate of envCandidates) {
|
|
182
|
+
const res = verifyManifestCandidate(candidate, targetTriple, "env", hostPlatform);
|
|
183
|
+
if (res) return res;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const execDir = dirname(options.execPath ?? process.execPath);
|
|
189
|
+
const sidecarCandidates = [
|
|
190
|
+
join(repoRoot, "native-bin", targetTriple, plainExe),
|
|
191
|
+
join(repoRoot, "native-bin", artifactFile),
|
|
192
|
+
join(execDir, artifactFile),
|
|
193
|
+
join(execDir, "native-bin", targetTriple, plainExe),
|
|
194
|
+
];
|
|
195
|
+
for (const candidate of sidecarCandidates) {
|
|
196
|
+
const res = verifyManifestCandidate(candidate, targetTriple, "sidecar", hostPlatform);
|
|
197
|
+
if (res) return res;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (options.allowLocalRelease !== false && targetTriple === hostTriple) {
|
|
201
|
+
const localRelease = join(repoRoot, "native", "ocx-child", "target", "release", plainExe);
|
|
202
|
+
if (existsSync(localRelease)) {
|
|
203
|
+
const relDir = dirname(localRelease);
|
|
204
|
+
const bytes = isSafeDirectory(relDir) ? readSafeRegularFile(localRelease, MAX_CHILD_BINARY_BYTES, hostPlatform) : null;
|
|
205
|
+
if (!bytes) return { ok: false, reason: "checksum_mismatch" };
|
|
206
|
+
return {
|
|
207
|
+
ok: true,
|
|
208
|
+
artifact: {
|
|
209
|
+
targetTriple,
|
|
210
|
+
bytes,
|
|
211
|
+
sizeBytes: bytes.byteLength,
|
|
212
|
+
sha256: sha256Hex(bytes),
|
|
213
|
+
source: "local-release",
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// An empty OPENCODEX_HOME counts as unset, as in ocx-child; joining "" would search the cwd.
|
|
220
|
+
const ocxHome = options.opencodexHome || env.OPENCODEX_HOME?.trim() || join(env.HOME || homedir(), ".opencodex");
|
|
221
|
+
const version = options.version ?? packageVersion("0.0.0");
|
|
222
|
+
const cachedCandidate = join(ocxHome, "cache", "ocx-child", version, artifactFile);
|
|
223
|
+
const cacheRes = verifyManifestCandidate(cachedCandidate, targetTriple, "cache", hostPlatform);
|
|
224
|
+
if (cacheRes) return cacheRes;
|
|
225
|
+
|
|
226
|
+
return { ok: false, reason: "artifact_not_found" };
|
|
227
|
+
}
|
|
228
|
+
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract predicates for the lightweight `ocx-child` ephemeral Remote Link Child runtime.
|
|
3
|
+
*
|
|
4
|
+
* Pure and free of import-time side effects inside `src/link/` so Home enrollment and
|
|
5
|
+
* diagnostics can distinguish a clean detached `ocx-child` host from a full standalone
|
|
6
|
+
* `ocx` daemon without changing persisted `LinkStore` records on disk.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export interface EphemeralChildConfigProjection {
|
|
10
|
+
readonly port: number;
|
|
11
|
+
readonly runtimeRole?: "standalone" | null | undefined;
|
|
12
|
+
readonly ephemeralChild: true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function isValidChildPort(value: unknown): value is number {
|
|
16
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 1024 && value <= 65535;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* True when `config show --json` came from a clean, detached `ocx-child` binary ready for
|
|
21
|
+
* Home-initiated enrollment (`runtimeRole: "standalone"`, `ephemeralChild: true`, valid port).
|
|
22
|
+
* An already-attached `ocx-child` reports `runtimeRole: "client"` and returns `false`.
|
|
23
|
+
*/
|
|
24
|
+
export function isDetachedEphemeralChildConfig(value: unknown): value is EphemeralChildConfigProjection {
|
|
25
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
26
|
+
const record = value as Record<string, unknown>;
|
|
27
|
+
return record.ephemeralChild === true
|
|
28
|
+
&& (record.runtimeRole ?? "standalone") === "standalone"
|
|
29
|
+
&& isValidChildPort(record.port);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** True when a `/healthz` payload identifies a live `ocx-child` client relay on `expectedPort`. */
|
|
33
|
+
export function isEphemeralChildHealth(value: unknown, expectedPort: number): boolean {
|
|
34
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
35
|
+
const record = value as Record<string, unknown>;
|
|
36
|
+
return record.service === "opencodex"
|
|
37
|
+
&& record.role === "client"
|
|
38
|
+
&& record.ephemeralChild === true
|
|
39
|
+
&& record.port === expectedPort
|
|
40
|
+
&& typeof record.pid === "number"
|
|
41
|
+
&& Number.isInteger(record.pid)
|
|
42
|
+
&& record.pid > 0
|
|
43
|
+
&& typeof record.startedAt === "string"
|
|
44
|
+
&& Number.isFinite(Date.parse(record.startedAt));
|
|
45
|
+
}
|