@neta-art/cohub-cli 10.24.0 → 10.25.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/bin/cohub.js +4 -1
- package/dist/board-gpu/page.js +1566 -71230
- package/dist/bootstrap.js +67 -27
- package/dist/build.json +1 -1
- package/dist/{board-kernel/FilterPipe.js → chunks/Geometry.js} +10447 -10469
- package/dist/chunks/about.js +102 -0
- package/dist/chunks/app-realtime.js +2216 -0
- package/dist/chunks/app-realtime2.js +2 -0
- package/dist/chunks/app-ref.js +88 -0
- package/dist/chunks/apps.js +1423 -0
- package/dist/chunks/auth.js +175 -0
- package/dist/chunks/avatar.js +146 -0
- package/dist/chunks/board-export-resources.js +232 -0
- package/dist/chunks/board-export.js +874 -0
- package/dist/chunks/board-export2.js +2 -0
- package/dist/{board-kernel.js → chunks/board-kernel.js} +18032 -28512
- package/dist/chunks/board-kernel2.js +4 -0
- package/dist/chunks/board-profile.js +69 -0
- package/dist/chunks/board-simulate.js +315 -0
- package/dist/chunks/board-time.js +34 -0
- package/dist/chunks/boards.js +1943 -0
- package/dist/{board-kernel → chunks}/browserAll.js +9 -8
- package/dist/chunks/channels.js +64 -0
- package/dist/chunks/client.js +12606 -0
- package/dist/chunks/command-input.js +17 -0
- package/dist/chunks/commander.js +2962 -0
- package/dist/chunks/cron-jobs.js +163 -0
- package/dist/chunks/daemon.js +545 -0
- package/dist/chunks/daemon2.js +2 -0
- package/dist/chunks/desktop.js +172 -0
- package/dist/chunks/endpoint-options.js +26 -0
- package/dist/chunks/env-proxy.js +35 -0
- package/dist/chunks/environment.js +154 -0
- package/dist/chunks/feedback.js +120 -0
- package/dist/chunks/generations.js +379 -0
- package/dist/chunks/host.js +9 -0
- package/dist/chunks/http-put.js +131 -0
- package/dist/chunks/id.js +2416 -0
- package/dist/{board-kernel → chunks}/init.js +1 -1
- package/dist/chunks/install.js +11959 -0
- package/dist/chunks/launch.js +374 -0
- package/dist/chunks/local-media.js +47 -0
- package/dist/chunks/me.js +134 -0
- package/dist/chunks/media.js +315 -0
- package/dist/chunks/models.js +242 -0
- package/dist/chunks/operands.js +46 -0
- package/dist/chunks/package-paths.js +13 -0
- package/dist/chunks/policy.js +221 -0
- package/dist/chunks/preferences.js +29 -0
- package/dist/chunks/profile.js +64 -0
- package/dist/chunks/prompts.js +41 -0
- package/dist/chunks/public.js +2 -0
- package/dist/chunks/public2.js +244 -0
- package/dist/chunks/references.js +197 -0
- package/dist/chunks/referrals.js +90 -0
- package/dist/chunks/rolldown-runtime.js +26 -0
- package/dist/chunks/rooms-connect.js +2 -0
- package/dist/chunks/rooms-connect2.js +151 -0
- package/dist/chunks/rooms-rtc.js +309 -0
- package/dist/chunks/rooms.js +211 -0
- package/dist/chunks/run.js +220 -0
- package/dist/chunks/runtime.js +638 -0
- package/dist/chunks/runtime2.js +286 -0
- package/dist/chunks/runtimes.js +48 -0
- package/dist/chunks/safe-remote-image.js +198 -0
- package/dist/chunks/schemas.js +6017 -0
- package/dist/chunks/search.js +113 -0
- package/dist/chunks/self-update.js +238 -0
- package/dist/chunks/serve.js +1246 -0
- package/dist/chunks/session-status.js +24 -0
- package/dist/chunks/skills.js +35 -0
- package/dist/chunks/spaces.js +5080 -0
- package/dist/chunks/src.js +405 -0
- package/dist/chunks/supervisor.js +2511 -0
- package/dist/chunks/supervisor2.js +2 -0
- package/dist/chunks/tasks.js +82 -0
- package/dist/chunks/themes.js +2898 -0
- package/dist/chunks/version.js +2 -0
- package/dist/chunks/version2.js +22 -0
- package/dist/chunks/version3.js +18 -0
- package/dist/chunks/web.js +7 -0
- package/dist/{board-kernel → chunks}/webworkerAll.js +1 -1
- package/dist/runtime/native/pi-extension.js +174 -166
- package/dist/runtime/worker.js +27 -16
- package/package.json +8 -9
- package/dist/about.d.ts +0 -2
- package/dist/about.js +0 -71
- package/dist/app-download.d.ts +0 -11
- package/dist/app-download.js +0 -252
- package/dist/app-ref.d.ts +0 -5
- package/dist/app-ref.js +0 -8
- package/dist/app-target.d.ts +0 -26
- package/dist/app-target.js +0 -55
- package/dist/auth.d.ts +0 -45
- package/dist/auth.js +0 -307
- package/dist/avatar.d.ts +0 -55
- package/dist/avatar.js +0 -104
- package/dist/board-command-support.d.ts +0 -6
- package/dist/board-command-support.js +0 -88
- package/dist/board-export-resources.d.ts +0 -12
- package/dist/board-export-resources.js +0 -51
- package/dist/board-export.d.ts +0 -110
- package/dist/board-export.js +0 -592
- package/dist/board-fonts.d.ts +0 -11
- package/dist/board-fonts.js +0 -10
- package/dist/board-gpu/daemon.d.ts +0 -11
- package/dist/board-gpu/daemon.js +0 -295
- package/dist/board-gpu/index.d.ts +0 -33
- package/dist/board-gpu/index.js +0 -189
- package/dist/board-gpu/protocol.d.ts +0 -77
- package/dist/board-gpu/protocol.js +0 -1
- package/dist/board-kernel.d.ts +0 -5
- package/dist/board-media-export.d.ts +0 -17
- package/dist/board-media-export.js +0 -164
- package/dist/board-media.d.ts +0 -5
- package/dist/board-media.js +0 -66
- package/dist/board-profile.d.ts +0 -21
- package/dist/board-profile.js +0 -67
- package/dist/board-simulate.d.ts +0 -67
- package/dist/board-simulate.js +0 -259
- package/dist/board-time.d.ts +0 -3
- package/dist/board-time.js +0 -34
- package/dist/bootstrap.d.ts +0 -2
- package/dist/client.d.ts +0 -5
- package/dist/client.js +0 -24
- package/dist/command-input.d.ts +0 -4
- package/dist/command-input.js +0 -16
- package/dist/commands/app-commerce.d.ts +0 -2
- package/dist/commands/app-commerce.js +0 -228
- package/dist/commands/app-domains.d.ts +0 -2
- package/dist/commands/app-domains.js +0 -133
- package/dist/commands/apps.d.ts +0 -4
- package/dist/commands/apps.js +0 -827
- package/dist/commands/auth.d.ts +0 -2
- package/dist/commands/auth.js +0 -186
- package/dist/commands/boards/authoring.d.ts +0 -2
- package/dist/commands/boards/authoring.js +0 -166
- package/dist/commands/boards/examples.d.ts +0 -10
- package/dist/commands/boards/examples.js +0 -118
- package/dist/commands/boards.d.ts +0 -13
- package/dist/commands/boards.js +0 -836
- package/dist/commands/channels.d.ts +0 -2
- package/dist/commands/channels.js +0 -74
- package/dist/commands/cron-jobs.d.ts +0 -2
- package/dist/commands/cron-jobs.js +0 -155
- package/dist/commands/decision.d.ts +0 -4
- package/dist/commands/decision.js +0 -113
- package/dist/commands/desktop.d.ts +0 -10
- package/dist/commands/desktop.js +0 -233
- package/dist/commands/feedback.d.ts +0 -2
- package/dist/commands/feedback.js +0 -131
- package/dist/commands/generations.d.ts +0 -2
- package/dist/commands/generations.js +0 -427
- package/dist/commands/host.d.ts +0 -2
- package/dist/commands/host.js +0 -11
- package/dist/commands/me.d.ts +0 -2
- package/dist/commands/me.js +0 -121
- package/dist/commands/models.d.ts +0 -28
- package/dist/commands/models.js +0 -271
- package/dist/commands/profile.d.ts +0 -2
- package/dist/commands/profile.js +0 -81
- package/dist/commands/prompts.d.ts +0 -2
- package/dist/commands/prompts.js +0 -37
- package/dist/commands/public.d.ts +0 -20
- package/dist/commands/public.js +0 -291
- package/dist/commands/references.d.ts +0 -2
- package/dist/commands/references.js +0 -193
- package/dist/commands/referrals.d.ts +0 -2
- package/dist/commands/referrals.js +0 -88
- package/dist/commands/rooms-connect.d.ts +0 -17
- package/dist/commands/rooms-connect.js +0 -140
- package/dist/commands/rooms-rtc-binary.d.ts +0 -2
- package/dist/commands/rooms-rtc-binary.js +0 -107
- package/dist/commands/rooms-rtc.d.ts +0 -21
- package/dist/commands/rooms-rtc.js +0 -171
- package/dist/commands/rooms.d.ts +0 -3
- package/dist/commands/rooms.js +0 -277
- package/dist/commands/run.d.ts +0 -13
- package/dist/commands/run.js +0 -246
- package/dist/commands/runtime.d.ts +0 -3
- package/dist/commands/runtime.js +0 -320
- package/dist/commands/sandboxd-binary.d.ts +0 -11
- package/dist/commands/sandboxd-binary.js +0 -238
- package/dist/commands/search.d.ts +0 -2
- package/dist/commands/search.js +0 -114
- package/dist/commands/session-access.d.ts +0 -2
- package/dist/commands/session-access.js +0 -70
- package/dist/commands/skills.d.ts +0 -2
- package/dist/commands/skills.js +0 -34
- package/dist/commands/space-activity.d.ts +0 -26
- package/dist/commands/space-activity.js +0 -147
- package/dist/commands/space-commerce.d.ts +0 -2
- package/dist/commands/space-commerce.js +0 -514
- package/dist/commands/space-displays.d.ts +0 -2
- package/dist/commands/space-displays.js +0 -620
- package/dist/commands/space-files.d.ts +0 -5
- package/dist/commands/space-files.js +0 -215
- package/dist/commands/space-invitations.d.ts +0 -29
- package/dist/commands/space-invitations.js +0 -189
- package/dist/commands/space-turns.d.ts +0 -49
- package/dist/commands/space-turns.js +0 -205
- package/dist/commands/space-wallet.d.ts +0 -2
- package/dist/commands/space-wallet.js +0 -141
- package/dist/commands/space-webhooks.d.ts +0 -7
- package/dist/commands/space-webhooks.js +0 -73
- package/dist/commands/spaces.d.ts +0 -25
- package/dist/commands/spaces.js +0 -2170
- package/dist/commands/tasks.d.ts +0 -8
- package/dist/commands/tasks.js +0 -80
- package/dist/commands/version.d.ts +0 -2
- package/dist/commands/version.js +0 -21
- package/dist/endpoint-options.d.ts +0 -4
- package/dist/endpoint-options.js +0 -26
- package/dist/env-proxy.d.ts +0 -5
- package/dist/env-proxy.js +0 -20
- package/dist/help-path.d.ts +0 -18
- package/dist/help-path.js +0 -223
- package/dist/host/auth.d.ts +0 -20
- package/dist/host/auth.js +0 -119
- package/dist/host/login-env.d.ts +0 -1
- package/dist/host/login-env.js +0 -31
- package/dist/host/runtime.d.ts +0 -35
- package/dist/host/runtime.js +0 -395
- package/dist/host/runtimes.d.ts +0 -9
- package/dist/host/runtimes.js +0 -42
- package/dist/host/serve.d.ts +0 -2
- package/dist/host/serve.js +0 -117
- package/dist/host/workspaces.d.ts +0 -2
- package/dist/host/workspaces.js +0 -18
- package/dist/http-put.d.ts +0 -25
- package/dist/http-put.js +0 -132
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -129
- package/dist/launcher.d.ts +0 -4
- package/dist/launcher.js +0 -38
- package/dist/local-media.d.ts +0 -2
- package/dist/local-media.js +0 -30
- package/dist/network-error.d.ts +0 -3
- package/dist/network-error.js +0 -22
- package/dist/output.d.ts +0 -46
- package/dist/output.js +0 -244
- package/dist/runtime/archive-store.d.ts +0 -54
- package/dist/runtime/archive-store.js +0 -379
- package/dist/runtime/cli-path.d.ts +0 -5
- package/dist/runtime/cli-path.js +0 -27
- package/dist/runtime/codex-usage.d.ts +0 -7
- package/dist/runtime/codex-usage.js +0 -11
- package/dist/runtime/connection.d.ts +0 -42
- package/dist/runtime/connection.js +0 -789
- package/dist/runtime/diagnostics.d.ts +0 -107
- package/dist/runtime/diagnostics.js +0 -392
- package/dist/runtime/harnesses/chained-projection.d.ts +0 -40
- package/dist/runtime/harnesses/chained-projection.js +0 -95
- package/dist/runtime/harnesses/chained-transcript.d.ts +0 -24
- package/dist/runtime/harnesses/chained-transcript.js +0 -62
- package/dist/runtime/harnesses/claude-approval.d.ts +0 -34
- package/dist/runtime/harnesses/claude-approval.js +0 -124
- package/dist/runtime/harnesses/claude-transcript.d.ts +0 -8
- package/dist/runtime/harnesses/claude-transcript.js +0 -138
- package/dist/runtime/harnesses/claude.d.ts +0 -8
- package/dist/runtime/harnesses/claude.js +0 -225
- package/dist/runtime/harnesses/codex-approval.d.ts +0 -25
- package/dist/runtime/harnesses/codex-approval.js +0 -69
- package/dist/runtime/harnesses/codex.d.ts +0 -4
- package/dist/runtime/harnesses/codex.js +0 -269
- package/dist/runtime/harnesses/cursor-transcript.d.ts +0 -37
- package/dist/runtime/harnesses/cursor-transcript.js +0 -183
- package/dist/runtime/harnesses/cursor.d.ts +0 -24
- package/dist/runtime/harnesses/cursor.js +0 -620
- package/dist/runtime/harnesses/index.d.ts +0 -16
- package/dist/runtime/harnesses/index.js +0 -73
- package/dist/runtime/harnesses/pi.d.ts +0 -4
- package/dist/runtime/harnesses/pi.js +0 -247
- package/dist/runtime/harnesses/process.d.ts +0 -31
- package/dist/runtime/harnesses/process.js +0 -75
- package/dist/runtime/harnesses/stream-json.d.ts +0 -48
- package/dist/runtime/harnesses/stream-json.js +0 -336
- package/dist/runtime/harnesses/types.d.ts +0 -117
- package/dist/runtime/harnesses/types.js +0 -1
- package/dist/runtime/harnesses/workbuddy-transcript.d.ts +0 -8
- package/dist/runtime/harnesses/workbuddy-transcript.js +0 -127
- package/dist/runtime/harnesses/workbuddy.d.ts +0 -21
- package/dist/runtime/harnesses/workbuddy.js +0 -123
- package/dist/runtime/instance.d.ts +0 -20
- package/dist/runtime/instance.js +0 -247
- package/dist/runtime/json-rpc.d.ts +0 -53
- package/dist/runtime/json-rpc.js +0 -212
- package/dist/runtime/launch.d.ts +0 -25
- package/dist/runtime/launch.js +0 -247
- package/dist/runtime/local-workspace.d.ts +0 -15
- package/dist/runtime/local-workspace.js +0 -52
- package/dist/runtime/model-catalog.d.ts +0 -12
- package/dist/runtime/model-catalog.js +0 -84
- package/dist/runtime/native/adapters.d.ts +0 -15
- package/dist/runtime/native/adapters.js +0 -11
- package/dist/runtime/native/approvals.d.ts +0 -18
- package/dist/runtime/native/approvals.js +0 -54
- package/dist/runtime/native/archive.d.ts +0 -19
- package/dist/runtime/native/archive.js +0 -142
- package/dist/runtime/native/attach.d.ts +0 -36
- package/dist/runtime/native/attach.js +0 -128
- package/dist/runtime/native/codex-link.d.ts +0 -60
- package/dist/runtime/native/codex-link.js +0 -322
- package/dist/runtime/native/config.d.ts +0 -16
- package/dist/runtime/native/config.js +0 -24
- package/dist/runtime/native/daemon.d.ts +0 -92
- package/dist/runtime/native/daemon.js +0 -380
- package/dist/runtime/native/execution.d.ts +0 -26
- package/dist/runtime/native/execution.js +0 -34
- package/dist/runtime/native/identity.d.ts +0 -9
- package/dist/runtime/native/identity.js +0 -15
- package/dist/runtime/native/ingest.d.ts +0 -263
- package/dist/runtime/native/ingest.js +0 -884
- package/dist/runtime/native/install.d.ts +0 -9
- package/dist/runtime/native/install.js +0 -113
- package/dist/runtime/native/paths.d.ts +0 -2
- package/dist/runtime/native/paths.js +0 -7
- package/dist/runtime/native/pi-extension.d.ts +0 -36
- package/dist/runtime/native/pi-link.d.ts +0 -69
- package/dist/runtime/native/pi-link.js +0 -269
- package/dist/runtime/native/results.d.ts +0 -41
- package/dist/runtime/native/results.js +0 -128
- package/dist/runtime/native/sessions.d.ts +0 -45
- package/dist/runtime/native/sessions.js +0 -87
- package/dist/runtime/native/transcript.d.ts +0 -89
- package/dist/runtime/native/transcript.js +0 -656
- package/dist/runtime/native/translate.d.ts +0 -46
- package/dist/runtime/native/translate.js +0 -299
- package/dist/runtime/native/transport.d.ts +0 -7
- package/dist/runtime/native/transport.js +0 -16
- package/dist/runtime/native/version.d.ts +0 -5
- package/dist/runtime/native/version.js +0 -21
- package/dist/runtime/preferences.d.ts +0 -7
- package/dist/runtime/preferences.js +0 -22
- package/dist/runtime/presentation.d.ts +0 -32
- package/dist/runtime/presentation.js +0 -124
- package/dist/runtime/process-group.d.ts +0 -5
- package/dist/runtime/process-group.js +0 -161
- package/dist/runtime/projection-store.d.ts +0 -27
- package/dist/runtime/projection-store.js +0 -30
- package/dist/runtime/space-binding.d.ts +0 -48
- package/dist/runtime/space-binding.js +0 -342
- package/dist/runtime/supervisor.d.ts +0 -19
- package/dist/runtime/supervisor.js +0 -441
- package/dist/runtime/turn-projection.d.ts +0 -41
- package/dist/runtime/turn-projection.js +0 -120
- package/dist/runtime/worker.d.ts +0 -1
- package/dist/safe-remote-image.d.ts +0 -36
- package/dist/safe-remote-image.js +0 -191
- package/dist/self-update.d.ts +0 -7
- package/dist/self-update.js +0 -202
- package/dist/session-status.d.ts +0 -10
- package/dist/session-status.js +0 -25
- package/dist/space-files/limit.d.ts +0 -2
- package/dist/space-files/limit.js +0 -16
- package/dist/space-files/operands.d.ts +0 -17
- package/dist/space-files/operands.js +0 -33
- package/dist/space-files/transfer.d.ts +0 -53
- package/dist/space-files/transfer.js +0 -297
- package/dist/space-files/upload.d.ts +0 -17
- package/dist/space-files/upload.js +0 -76
- package/dist/space.d.ts +0 -44
- package/dist/space.js +0 -192
- package/dist/version.d.ts +0 -2
- package/dist/version.js +0 -17
- package/dist/web.d.ts +0 -1
- package/dist/web.js +0 -4
- /package/dist/{board-kernel → chunks}/lexer.js +0 -0
package/dist/commands/runtime.js
DELETED
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
import { setTimeout as delay } from "node:timers/promises";
|
|
2
|
-
import { LOCAL_HARNESS_SPECS, LOCAL_HARNESSES } from "@neta-art/cohub";
|
|
3
|
-
import { createClient } from "../client.js";
|
|
4
|
-
import { json as outJson, jsonRequested } from "../output.js";
|
|
5
|
-
import { currentIdentityKey } from "../space.js";
|
|
6
|
-
import { resolveRuntimeTarget, runtimeUp, parseRuntimeHarnesses } from "../runtime/launch.js";
|
|
7
|
-
import { canonicalRuntimeRoot, getRuntimeSpaceBinding } from "../runtime/space-binding.js";
|
|
8
|
-
import { join } from "node:path";
|
|
9
|
-
import { RuntimeArchiveStore } from "../runtime/archive-store.js";
|
|
10
|
-
import { readNativeConfig, runtimeStateRoot, writeNativeConfig } from "../runtime/native/config.js";
|
|
11
|
-
import { MAX_IMPORT_CONCURRENCY, DEFAULT_IMPORT_CONCURRENCY } from "../runtime/native/ingest.js";
|
|
12
|
-
import { installPiExtension, piExtensionState } from "../runtime/native/install.js";
|
|
13
|
-
import { controlRuntimeInstance, requestRuntimeInstance, runtimeInstanceDirectory, stopRuntimeInstance } from "../runtime/instance.js";
|
|
14
|
-
import { forgetHostRuntime } from "../host/runtimes.js";
|
|
15
|
-
import { atLeastLevel, diagnosticLevels, formatDiagnostic, formatImportProgress, formatNativeSync, printRuntimeSummary } from "../runtime/presentation.js";
|
|
16
|
-
import { readRuntimeDiagnosticEvents, RuntimeDiagnosticReader, runtimeDiagnosticsDirectory, serializeDiagnosticError } from "../runtime/diagnostics.js";
|
|
17
|
-
export { resolveLocalSpaceName, parseRuntimeDisplay, parseRuntimeHarnesses } from "../runtime/launch.js";
|
|
18
|
-
const reportFailure = (cause) => {
|
|
19
|
-
process.stderr.write(`Runtime failed: ${serializeDiagnosticError(cause).message}\n`);
|
|
20
|
-
process.exitCode = 1;
|
|
21
|
-
};
|
|
22
|
-
const megabytes = (bytes) => `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
23
|
-
/** The bound Space of a directory, with its running Runtime; import and attach act through it. */
|
|
24
|
-
async function boundRuntime(program, dir, space) {
|
|
25
|
-
const identity = currentIdentityKey();
|
|
26
|
-
if (!identity)
|
|
27
|
-
throw new Error("Sign in first");
|
|
28
|
-
const root = await canonicalRuntimeRoot(dir ?? process.cwd());
|
|
29
|
-
const spaceId = await resolveRuntimeTarget(program, space);
|
|
30
|
-
const binding = await getRuntimeSpaceBinding(root, identity);
|
|
31
|
-
if (!binding || binding.spaceId !== spaceId)
|
|
32
|
-
throw new Error("Bind this directory with runtime up first");
|
|
33
|
-
return { identity, root, spaceId, directory: runtimeInstanceDirectory(identity, spaceId) };
|
|
34
|
-
}
|
|
35
|
-
export function registerRuntime(program) {
|
|
36
|
-
const runtime = program.command("runtime").description("Connect a local workspace");
|
|
37
|
-
const up = runtime.command("up [dir]")
|
|
38
|
-
.description("Connect local Harnesses and files")
|
|
39
|
-
.option("-s, --space <space>", "Target Space: ID, slug, or username/slug")
|
|
40
|
-
.option("-n, --new", "Create a new Space")
|
|
41
|
-
.option("--name <name>", "New Space name")
|
|
42
|
-
.option("-d, --detach", "Run in the background")
|
|
43
|
-
.option("--harness <name>", `${LOCAL_HARNESSES.join(", ")}; repeatable`, (value, previous) => [...previous, value], []);
|
|
44
|
-
for (const harness of LOCAL_HARNESSES)
|
|
45
|
-
up.option(`--${harness} <path>`, `${LOCAL_HARNESS_SPECS[harness].label} executable`);
|
|
46
|
-
up
|
|
47
|
-
.option("--display [screen]", "Share a screen (default: auto when available), or xvfb[:WIDTHxHEIGHT] for a virtual one")
|
|
48
|
-
.option("--no-display", "Disable screen sharing and skip its confirmation")
|
|
49
|
-
.option("-y, --yes", "Accept defaults and authorize local execution, native sync, and screen sharing")
|
|
50
|
-
.option("--verbose", "Show diagnostic details")
|
|
51
|
-
.option("--json", "JSON output")
|
|
52
|
-
.action(async (dir, options) => {
|
|
53
|
-
try {
|
|
54
|
-
await runtimeUp(program, dir, { ...options, json: jsonRequested(options) });
|
|
55
|
-
}
|
|
56
|
-
catch (cause) {
|
|
57
|
-
reportFailure(cause);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
runtime.command("attach")
|
|
61
|
-
.description("Connect native harnesses to Cohub: install the Pi extension")
|
|
62
|
-
.option("-s, --space <space>", "Target Space: ID, slug, or username/slug")
|
|
63
|
-
.option("--harness <name>", "Pi; repeatable", (value, previous) => [...previous, value], [])
|
|
64
|
-
.option("--json", "JSON output")
|
|
65
|
-
.action(async (options) => {
|
|
66
|
-
try {
|
|
67
|
-
const harnesses = parseRuntimeHarnesses(options.harness.length ? options.harness : ["pi"]);
|
|
68
|
-
if (!harnesses.includes("pi"))
|
|
69
|
-
throw new Error("Only Pi uses an extension; Codex syncs through runtime up's shared app-server");
|
|
70
|
-
const before = await piExtensionState();
|
|
71
|
-
if (before === "foreign")
|
|
72
|
-
throw new Error("A Pi extension named cohub exists and is not managed by Cohub; move it aside, then retry");
|
|
73
|
-
await installPiExtension();
|
|
74
|
-
const spaceId = await resolveRuntimeTarget(program, options.space).catch(() => null);
|
|
75
|
-
const identity = currentIdentityKey();
|
|
76
|
-
if (spaceId && identity)
|
|
77
|
-
await controlRuntimeInstance(runtimeInstanceDirectory(identity, spaceId), "reload").catch(() => undefined);
|
|
78
|
-
if (jsonRequested(options))
|
|
79
|
-
outJson({ harness: "pi", extension: "installed", updated: before !== "installed" });
|
|
80
|
-
else
|
|
81
|
-
process.stdout.write(before === "installed" ? "Pi extension is up to date\n" : "Pi extension installed. Run /reload in open Pi sessions to connect them\n");
|
|
82
|
-
}
|
|
83
|
-
catch (cause) {
|
|
84
|
-
reportFailure(cause);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
runtime.command("detach")
|
|
88
|
-
.description("Pause native sync; keep all data")
|
|
89
|
-
.option("-s, --space <space>", "Target Space: ID, slug, or username/slug")
|
|
90
|
-
.option("--harness <name>", `${LOCAL_HARNESSES.join(", ")}; repeatable`, (value, previous) => [...previous, value], [])
|
|
91
|
-
.option("--json", "JSON output")
|
|
92
|
-
.action(async (options) => {
|
|
93
|
-
try {
|
|
94
|
-
const { identity, spaceId, directory } = await boundRuntime(program, undefined, options.space);
|
|
95
|
-
const stateRoot = runtimeStateRoot(spaceId);
|
|
96
|
-
const config = await readNativeConfig(stateRoot, identity);
|
|
97
|
-
const paused = options.harness.length ? parseRuntimeHarnesses(options.harness) : config?.harnesses ?? [...LOCAL_HARNESSES];
|
|
98
|
-
const harnesses = (config?.harnesses ?? []).filter((harness) => !paused.includes(harness));
|
|
99
|
-
if (config)
|
|
100
|
-
await writeNativeConfig(stateRoot, { ...config, harnesses, codexShared: harnesses.includes("codex") && config.codexShared });
|
|
101
|
-
await controlRuntimeInstance(directory, "reload").catch(() => undefined);
|
|
102
|
-
const codexWasShared = Boolean(config?.codexShared) && paused.includes("codex");
|
|
103
|
-
if (jsonRequested(options))
|
|
104
|
-
outJson({ spaceId, harnesses, paused, enabled: harnesses.length > 0 });
|
|
105
|
-
else {
|
|
106
|
-
process.stdout.write(harnesses.length ? `Native sync paused for ${paused.join(", ")}; still syncing ${harnesses.join(", ")}\n` : "Native sync paused; all data retained\n");
|
|
107
|
-
// Cohub never stops a server that terminal clients may be attached to.
|
|
108
|
-
if (codexWasShared)
|
|
109
|
-
process.stdout.write("Codex's shared app-server keeps running; stop it with codex app-server daemon stop\n");
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
catch (cause) {
|
|
113
|
-
reportFailure(cause);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
runtime.command("import [dir]")
|
|
117
|
-
.description("Import earlier local conversations, newest first")
|
|
118
|
-
.option("-s, --space <space>", "Target Space: ID, slug, or username/slug")
|
|
119
|
-
.option("--harness <name>", "Filter by harness; repeatable", (value, previous) => [...previous, value], [])
|
|
120
|
-
.option("--session <id>", "Filter by native session ID")
|
|
121
|
-
.option("--concurrency <count>", `Conversations read in parallel, 1 to ${MAX_IMPORT_CONCURRENCY}`, String(DEFAULT_IMPORT_CONCURRENCY))
|
|
122
|
-
.option("--dry-run", "Preview without importing")
|
|
123
|
-
.option("-y, --yes", "Skip confirmation")
|
|
124
|
-
.option("--json", "Output as JSON")
|
|
125
|
-
.action(async (dir, options) => {
|
|
126
|
-
const controller = new AbortController();
|
|
127
|
-
const stop = () => controller.abort();
|
|
128
|
-
process.once("SIGINT", stop);
|
|
129
|
-
process.once("SIGTERM", stop);
|
|
130
|
-
const asJson = jsonRequested(options);
|
|
131
|
-
try {
|
|
132
|
-
const concurrency = Number(options.concurrency);
|
|
133
|
-
if (!Number.isSafeInteger(concurrency) || concurrency < 1 || concurrency > MAX_IMPORT_CONCURRENCY)
|
|
134
|
-
throw new Error(`Use a concurrency from 1 to ${MAX_IMPORT_CONCURRENCY}`);
|
|
135
|
-
const { spaceId, root, directory } = await boundRuntime(program, dir, options.space);
|
|
136
|
-
// The Runtime does the work, so an import survives this command: Ctrl-C only pauses it.
|
|
137
|
-
const filter = { harnesses: options.harness.length ? parseRuntimeHarnesses(options.harness) : [], ...(options.session ? { nativeSessionId: options.session } : {}) };
|
|
138
|
-
const control = async (command, timeoutMs = 60_000) => {
|
|
139
|
-
const response = await controlRuntimeInstance(directory, "import", { ...filter, command, concurrency }, timeoutMs);
|
|
140
|
-
if (!response)
|
|
141
|
-
throw new Error("Local Runtime is not running; start it with cohub runtime up");
|
|
142
|
-
return response.result;
|
|
143
|
-
};
|
|
144
|
-
const plan = await control("plan");
|
|
145
|
-
const summary = { spaceId, root, ...plan, dryRun: Boolean(options.dryRun) };
|
|
146
|
-
if (options.dryRun || !plan.files) {
|
|
147
|
-
if (asJson)
|
|
148
|
-
outJson(summary);
|
|
149
|
-
else if (!plan.files)
|
|
150
|
-
process.stdout.write("No earlier conversations left to import\n");
|
|
151
|
-
else {
|
|
152
|
-
process.stdout.write(`Found ${plan.files} conversation${plan.files === 1 ? "" : "s"} · ${megabytes(plan.bytes)}\n`);
|
|
153
|
-
for (const item of plan.sample)
|
|
154
|
-
process.stdout.write(` ${item.harness.padEnd(5)} ${new Date(item.mtimeMs).toISOString().slice(0, 16).replace("T", " ")} ${item.nativeSessionId ?? ""} ${item.path}\n`);
|
|
155
|
-
if (plan.files > plan.sample.length)
|
|
156
|
-
process.stdout.write(` … and ${plan.files - plan.sample.length} more\n`);
|
|
157
|
-
}
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
if (!options.yes) {
|
|
161
|
-
if (!process.stdin.isTTY)
|
|
162
|
-
throw new Error("Use --yes in non-interactive mode");
|
|
163
|
-
const { createInterface } = await import("node:readline/promises");
|
|
164
|
-
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
165
|
-
try {
|
|
166
|
-
const answer = await rl.question(`Import ${plan.files} conversation${plan.files === 1 ? "" : "s"} (${megabytes(plan.bytes)}) to Space ${spaceId}? [Y/n] `);
|
|
167
|
-
if (!/^(|y(es)?)$/i.test(answer.trim())) {
|
|
168
|
-
if (asJson)
|
|
169
|
-
outJson({ ...summary, cancelled: true });
|
|
170
|
-
else
|
|
171
|
-
process.stdout.write("Import cancelled\n");
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
finally {
|
|
176
|
-
rl.close();
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
let job = await control("start");
|
|
180
|
-
while (!controller.signal.aborted && job.state === "running") {
|
|
181
|
-
if (!asJson && process.stderr.isTTY)
|
|
182
|
-
process.stderr.write(`\r\x1b[2KImporting ${formatImportProgress(job)}`);
|
|
183
|
-
await delay(500, undefined, { signal: controller.signal }).catch(() => undefined);
|
|
184
|
-
const status = await requestRuntimeInstance(directory);
|
|
185
|
-
if (!status?.native)
|
|
186
|
-
throw new Error("Local Runtime stopped; the import resumes when it starts again");
|
|
187
|
-
job = status.native.import;
|
|
188
|
-
}
|
|
189
|
-
if (controller.signal.aborted)
|
|
190
|
-
job = await control("pause", 5_000);
|
|
191
|
-
const paused = job.state === "paused";
|
|
192
|
-
if (asJson)
|
|
193
|
-
outJson({ ...summary, ...job, paused });
|
|
194
|
-
else {
|
|
195
|
-
if (process.stderr.isTTY)
|
|
196
|
-
process.stderr.write("\r\x1b[2K");
|
|
197
|
-
process.stdout.write(`${paused ? "Paused" : "Imported"} ${formatImportProgress(job)}\n`);
|
|
198
|
-
for (const failure of job.failed)
|
|
199
|
-
process.stdout.write(`Skipped ${failure.path}: ${failure.message}\n`);
|
|
200
|
-
if (paused)
|
|
201
|
-
process.stdout.write("Run cohub runtime import again to continue\n");
|
|
202
|
-
}
|
|
203
|
-
if (job.failed.length)
|
|
204
|
-
process.exitCode = 1;
|
|
205
|
-
}
|
|
206
|
-
catch (cause) {
|
|
207
|
-
reportFailure(cause);
|
|
208
|
-
}
|
|
209
|
-
finally {
|
|
210
|
-
process.removeListener("SIGINT", stop);
|
|
211
|
-
process.removeListener("SIGTERM", stop);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
runtime.command("status").description("Local and server status")
|
|
215
|
-
.option("-s, --space <space>", "Target Space: ID, slug, or username/slug")
|
|
216
|
-
.option("--json", "JSON output")
|
|
217
|
-
.action(async (options) => {
|
|
218
|
-
try {
|
|
219
|
-
const spaceId = await resolveRuntimeTarget(program, options.space);
|
|
220
|
-
const identity = currentIdentityKey();
|
|
221
|
-
const local = identity ? await requestRuntimeInstance(runtimeInstanceDirectory(identity, spaceId)) : null;
|
|
222
|
-
const space = createClient().space(spaceId);
|
|
223
|
-
const stateRoot = runtimeStateRoot(spaceId);
|
|
224
|
-
const archives = new RuntimeArchiveStore(join(stateRoot, "archives"));
|
|
225
|
-
const [remote, pendingLocalArchives, failedLocalArchives] = await Promise.all([
|
|
226
|
-
space.getRuntime(undefined, { signal: AbortSignal.timeout(5000) }).then((value) => ({ value, error: null })).catch((error) => ({ value: null, error: serializeDiagnosticError(error).message })),
|
|
227
|
-
archives.pendingCount(), archives.failedCaptureCount(),
|
|
228
|
-
]);
|
|
229
|
-
// A corrupt native sync config must never take down the whole status report.
|
|
230
|
-
const nativeSync = identity ? await readNativeConfig(stateRoot, identity).then((config) => ({ config, error: null }), (error) => ({ config: null, error: serializeDiagnosticError(error).message })) : { config: null, error: null };
|
|
231
|
-
const result = { ...remote.value, spaceId, local, remote: remote.value, remoteError: remote.error, diagnosticsPath: runtimeDiagnosticsDirectory(stateRoot), pendingLocalArchives, failedLocalArchives, nativeSync: nativeSync.config, nativeSyncError: nativeSync.error, native: local?.native ?? null };
|
|
232
|
-
if (jsonRequested(options))
|
|
233
|
-
outJson(result);
|
|
234
|
-
else {
|
|
235
|
-
if (local)
|
|
236
|
-
printRuntimeSummary(local);
|
|
237
|
-
else
|
|
238
|
-
process.stdout.write(`Local process Not running\nSpace ${spaceId}\nLogs ${result.diagnosticsPath}\n`);
|
|
239
|
-
process.stdout.write(`Server ${remote.error ? `Unknown — ${remote.error}` : remote.value?.online ? "Harness connected" : "Offline"}\nArchives ${pendingLocalArchives} pending · ${failedLocalArchives} failed\n`);
|
|
240
|
-
const displays = remote.value?.displays ?? [];
|
|
241
|
-
if (displays.length)
|
|
242
|
-
process.stdout.write(`Displays ${displays.map((display) => `${display.name || display.id} ${display.width}x${display.height}${display.needs?.length ? ` (needs ${display.needs.join(", ")})` : display.input ? "" : " (view only)"}`).join(" · ")}\n`);
|
|
243
|
-
process.stdout.write(formatNativeSync(nativeSync.config, local?.native, nativeSync.error));
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
catch (cause) {
|
|
247
|
-
reportFailure(cause);
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
runtime.command("down").description("Stop this local Runtime; retain all data")
|
|
251
|
-
.option("-s, --space <space>", "Target Space: ID, slug, or username/slug")
|
|
252
|
-
.option("-y, --yes", "Stop even with unconfirmed executions")
|
|
253
|
-
.option("--json", "JSON output")
|
|
254
|
-
.action(async (options) => {
|
|
255
|
-
try {
|
|
256
|
-
const spaceId = await resolveRuntimeTarget(program, options.space);
|
|
257
|
-
const identity = currentIdentityKey();
|
|
258
|
-
if (!identity)
|
|
259
|
-
throw new Error("Sign in to the Runtime account");
|
|
260
|
-
const local = await stopRuntimeInstance(runtimeInstanceDirectory(identity, spaceId), Boolean(options.yes));
|
|
261
|
-
await forgetHostRuntime(identity, spaceId).catch((cause) => process.stderr.write(`Desktop app may reconnect this folder: ${serializeDiagnosticError(cause).message}\n`));
|
|
262
|
-
if (jsonRequested(options))
|
|
263
|
-
outJson({ spaceId, stopped: true });
|
|
264
|
-
else {
|
|
265
|
-
process.stdout.write("Runtime stopped; data retained\n");
|
|
266
|
-
// Terminal clients may still be attached to it, so it is never stopped for them.
|
|
267
|
-
if (local?.native?.codex?.control === "shared")
|
|
268
|
-
process.stdout.write("Codex's shared app-server keeps running; stop it with codex app-server daemon stop\n");
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
catch (cause) {
|
|
272
|
-
reportFailure(cause);
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
runtime.command("logs").description("Read local Runtime diagnostics")
|
|
276
|
-
.option("-s, --space <space>", "Target Space: ID, slug, or username/slug")
|
|
277
|
-
.option("-l, --limit <count>", "Number of events", "100")
|
|
278
|
-
.option("--level <level>", "Minimum level: debug, info, warn, error", "info")
|
|
279
|
-
.option("-f, --follow", "Keep watching")
|
|
280
|
-
.option("--json", "Raw diagnostic events")
|
|
281
|
-
.action(async (options) => {
|
|
282
|
-
const controller = new AbortController();
|
|
283
|
-
const stop = () => controller.abort();
|
|
284
|
-
try {
|
|
285
|
-
const spaceId = await resolveRuntimeTarget(program, options.space);
|
|
286
|
-
const stateRoot = runtimeStateRoot(spaceId);
|
|
287
|
-
const limit = Number(options.limit);
|
|
288
|
-
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 10_000)
|
|
289
|
-
throw new Error("Use a limit from 1 to 10000");
|
|
290
|
-
if (!diagnosticLevels.includes(options.level))
|
|
291
|
-
throw new Error("Use debug, info, warn or error");
|
|
292
|
-
const asJson = jsonRequested(options);
|
|
293
|
-
const reader = new RuntimeDiagnosticReader(stateRoot);
|
|
294
|
-
process.once("SIGINT", stop);
|
|
295
|
-
process.once("SIGTERM", stop);
|
|
296
|
-
do {
|
|
297
|
-
const events = (options.follow ? await reader.read({ limit }) : await readRuntimeDiagnosticEvents(stateRoot, { limit }))
|
|
298
|
-
.filter((event) => atLeastLevel(event.level, options.level));
|
|
299
|
-
if (asJson && !options.follow)
|
|
300
|
-
outJson(events);
|
|
301
|
-
else
|
|
302
|
-
for (const event of events)
|
|
303
|
-
process.stdout.write(asJson ? `${JSON.stringify(event)}\n` : formatDiagnostic(event, true));
|
|
304
|
-
if (!options.follow) {
|
|
305
|
-
if (!asJson && !events.length)
|
|
306
|
-
process.stdout.write("No matching diagnostics\n");
|
|
307
|
-
break;
|
|
308
|
-
}
|
|
309
|
-
await delay(1000, undefined, { signal: controller.signal }).catch(() => undefined);
|
|
310
|
-
} while (!controller.signal.aborted);
|
|
311
|
-
}
|
|
312
|
-
catch (cause) {
|
|
313
|
-
reportFailure(cause);
|
|
314
|
-
}
|
|
315
|
-
finally {
|
|
316
|
-
process.removeListener("SIGINT", stop);
|
|
317
|
-
process.removeListener("SIGTERM", stop);
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare const SANDBOXD_VERSION = "v2.68.0";
|
|
2
|
-
export declare class SandboxdDownloadError extends Error {
|
|
3
|
-
name: string;
|
|
4
|
-
}
|
|
5
|
-
export declare function validSandboxdArchiveEntries(entries: string[], goos: string): boolean;
|
|
6
|
-
export declare function validateSandboxdArchive(archivePath: string, goos: string): Promise<string[]>;
|
|
7
|
-
export type EnsureSandboxdOptions = {
|
|
8
|
-
version?: string;
|
|
9
|
-
onStatus?: (message: string) => void;
|
|
10
|
-
};
|
|
11
|
-
export declare const ensureSandboxdBinary: (options?: EnsureSandboxdOptions) => Promise<string>;
|
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
3
|
-
import { createReadStream, createWriteStream } from "node:fs";
|
|
4
|
-
import { chmod, copyFile, mkdir, mkdtemp, rename, rm, stat, lstat } from "node:fs/promises";
|
|
5
|
-
import { homedir, tmpdir } from "node:os";
|
|
6
|
-
import { dirname, join } from "node:path";
|
|
7
|
-
import { pipeline } from "node:stream/promises";
|
|
8
|
-
import { Readable } from "node:stream";
|
|
9
|
-
// Pin only after all platform artifacts are published to the public CDN.
|
|
10
|
-
export const SANDBOXD_VERSION = "v2.68.0";
|
|
11
|
-
const BINARY_NAME = "cohub-sandboxd";
|
|
12
|
-
const binaryName = (goos) => goos === "windows" ? `${BINARY_NAME}.exe` : BINARY_NAME;
|
|
13
|
-
// Public CDN prefix hosting the release archives (the repo is private, so the
|
|
14
|
-
// GitHub Release assets are not publicly downloadable). Overridable for staging
|
|
15
|
-
// or self-hosting.
|
|
16
|
-
const cdnBaseUrl = () => (process.env.COHUB_SANDBOXD_CDN_BASE_URL?.trim() || "https://public.cohub.live/sandboxd").replace(/\/+$/, "");
|
|
17
|
-
const DOWNLOAD_TIMEOUT_MS = 120_000;
|
|
18
|
-
const LOCK_STALE_MS = 5 * 60 * 1000;
|
|
19
|
-
// Map Node's platform/arch to the Go GOOS/GOARCH used in release asset names.
|
|
20
|
-
const GOOS_BY_PLATFORM = { darwin: "darwin", linux: "linux", win32: "windows" };
|
|
21
|
-
const GOARCH_BY_ARCH = { x64: "amd64", arm64: "arm64" };
|
|
22
|
-
export class SandboxdDownloadError extends Error {
|
|
23
|
-
name = "SandboxdDownloadError";
|
|
24
|
-
}
|
|
25
|
-
const resolveTarget = () => {
|
|
26
|
-
const goos = GOOS_BY_PLATFORM[process.platform];
|
|
27
|
-
const goarch = GOARCH_BY_ARCH[process.arch];
|
|
28
|
-
if (!goos || !goarch) {
|
|
29
|
-
throw new SandboxdDownloadError(`Unsupported platform ${process.platform}/${process.arch}. Set COHUB_SANDBOXD_BIN to a locally built binary.`);
|
|
30
|
-
}
|
|
31
|
-
return { goos, goarch };
|
|
32
|
-
};
|
|
33
|
-
const cacheDir = (version) => join(homedir(), ".cache", "cohub", "sandboxd", version);
|
|
34
|
-
const cachedBinaryPath = (version, target) => join(cacheDir(version), binaryName(target.goos));
|
|
35
|
-
const archiveName = (version, target) => `${BINARY_NAME}_${version}_${target.goos}_${target.goarch}.tar.gz`;
|
|
36
|
-
const isExecutableFile = async (path) => {
|
|
37
|
-
const info = await lstat(path).catch(() => null);
|
|
38
|
-
return Boolean(info?.isFile());
|
|
39
|
-
};
|
|
40
|
-
const isSafeArchiveFile = async (path) => {
|
|
41
|
-
const info = await lstat(path).catch(() => null);
|
|
42
|
-
return Boolean(info?.isFile() && info.nlink === 1);
|
|
43
|
-
};
|
|
44
|
-
const sha256File = async (path) => {
|
|
45
|
-
const hash = createHash("sha256");
|
|
46
|
-
await pipeline(createReadStream(path), hash);
|
|
47
|
-
return hash.digest("hex");
|
|
48
|
-
};
|
|
49
|
-
// Run `fn` under a single AbortController whose timeout spans the entire body
|
|
50
|
-
// read (not just the response headers), and normalize any network / timeout
|
|
51
|
-
// failure into a user-readable SandboxdDownloadError.
|
|
52
|
-
const withTimeout = async (what, fn) => {
|
|
53
|
-
const controller = new AbortController();
|
|
54
|
-
const timer = setTimeout(() => controller.abort(), DOWNLOAD_TIMEOUT_MS);
|
|
55
|
-
try {
|
|
56
|
-
return await fn(controller.signal);
|
|
57
|
-
}
|
|
58
|
-
catch (err) {
|
|
59
|
-
if (err instanceof SandboxdDownloadError)
|
|
60
|
-
throw err;
|
|
61
|
-
if (controller.signal.aborted) {
|
|
62
|
-
throw new SandboxdDownloadError(`${what} timed out after ${DOWNLOAD_TIMEOUT_MS / 1000}s`);
|
|
63
|
-
}
|
|
64
|
-
throw new SandboxdDownloadError(`${what} failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
65
|
-
}
|
|
66
|
-
finally {
|
|
67
|
-
clearTimeout(timer);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
// Download a URL straight to disk. The timeout covers the full stream, so a
|
|
71
|
-
// stalled body can never hang indefinitely.
|
|
72
|
-
const downloadToFile = (url, accept, destPath) => withTimeout(`Download of ${url}`, async (signal) => {
|
|
73
|
-
const response = await fetch(url, { signal, headers: { accept } });
|
|
74
|
-
if (!response.ok)
|
|
75
|
-
throw new SandboxdDownloadError(`Download failed (${response.status}) for ${url}`);
|
|
76
|
-
if (!response.body)
|
|
77
|
-
throw new SandboxdDownloadError(`Empty response body for ${url}`);
|
|
78
|
-
// Cast: Node's web-stream typings diverge from the DOM lib bundled by tsc.
|
|
79
|
-
await pipeline(Readable.fromWeb(response.body), createWriteStream(destPath));
|
|
80
|
-
});
|
|
81
|
-
// Fetch a small text resource (the checksum manifest) under the same timeout.
|
|
82
|
-
const fetchText = (url, accept) => withTimeout(`Download of ${url}`, async (signal) => {
|
|
83
|
-
const response = await fetch(url, { signal, headers: { accept } });
|
|
84
|
-
if (!response.ok)
|
|
85
|
-
throw new SandboxdDownloadError(`Download failed (${response.status}) for ${url}`);
|
|
86
|
-
return (await response.text()).trim();
|
|
87
|
-
});
|
|
88
|
-
// Every published release ships the binary alongside its LICENSE and NOTICE.
|
|
89
|
-
export function validSandboxdArchiveEntries(entries, goos) {
|
|
90
|
-
const expected = [binaryName(goos), "LICENSE", "NOTICE"];
|
|
91
|
-
return (entries.length === expected.length &&
|
|
92
|
-
expected.every((entry) => entries.includes(entry)));
|
|
93
|
-
}
|
|
94
|
-
// Git for Windows puts GNU tar on PATH, which treats `C:\...` as a remote host.
|
|
95
|
-
// Use the system bsdtar (Windows 10+) instead.
|
|
96
|
-
const tarCommand = () => {
|
|
97
|
-
if (process.platform !== "win32")
|
|
98
|
-
return "tar";
|
|
99
|
-
if (!process.env.SystemRoot)
|
|
100
|
-
throw new SandboxdDownloadError("SystemRoot is not set; cannot locate tar.exe");
|
|
101
|
-
return join(process.env.SystemRoot, "System32", "tar.exe");
|
|
102
|
-
};
|
|
103
|
-
// Reject unexpected paths before extracting the checksum-verified release.
|
|
104
|
-
const listTarGz = (archivePath, verbose = false) => new Promise((res, rej) => {
|
|
105
|
-
const child = spawn(tarCommand(), [verbose ? "-tvzf" : "-tzf", archivePath], { stdio: ["ignore", "pipe", "pipe"] });
|
|
106
|
-
let stdout = "";
|
|
107
|
-
let stderr = "";
|
|
108
|
-
child.stdout.on("data", (chunk) => {
|
|
109
|
-
stdout += chunk.toString();
|
|
110
|
-
});
|
|
111
|
-
child.stderr.on("data", (chunk) => {
|
|
112
|
-
stderr += chunk.toString();
|
|
113
|
-
});
|
|
114
|
-
child.on("error", rej);
|
|
115
|
-
child.on("close", (code) => code === 0
|
|
116
|
-
? res(stdout.split("\n").map((line) => line.trim()).filter(Boolean))
|
|
117
|
-
: rej(new SandboxdDownloadError(`tar listing failed: ${stderr.trim() || `exit ${code}`}`)));
|
|
118
|
-
});
|
|
119
|
-
export async function validateSandboxdArchive(archivePath, goos) {
|
|
120
|
-
const entries = await listTarGz(archivePath);
|
|
121
|
-
if (!validSandboxdArchiveEntries(entries, goos)) {
|
|
122
|
-
throw new SandboxdDownloadError(`Unexpected sandbox archive contents: ${entries.join(", ") || "(empty)"}`);
|
|
123
|
-
}
|
|
124
|
-
const details = await listTarGz(archivePath, true);
|
|
125
|
-
if (details.length !== entries.length || details.some((line) => !line.startsWith("-") || /(?: link to | -> | == )/.test(line))) {
|
|
126
|
-
throw new SandboxdDownloadError("Sandbox archive must contain only regular files");
|
|
127
|
-
}
|
|
128
|
-
return entries;
|
|
129
|
-
}
|
|
130
|
-
// Extract the verified `.tar.gz` using the system tar (universally present on
|
|
131
|
-
// macOS and Linux), keeping the CLI free of native archive dependencies.
|
|
132
|
-
const extractTarGz = (archivePath, cwd) => new Promise((res, rej) => {
|
|
133
|
-
const child = spawn(tarCommand(), ["-xzf", archivePath, "-C", cwd], { stdio: ["ignore", "ignore", "pipe"] });
|
|
134
|
-
let stderr = "";
|
|
135
|
-
child.stderr.on("data", (chunk) => {
|
|
136
|
-
stderr += chunk.toString();
|
|
137
|
-
});
|
|
138
|
-
child.on("error", rej);
|
|
139
|
-
child.on("close", (code) => code === 0 ? res() : rej(new SandboxdDownloadError(`tar extraction failed: ${stderr.trim() || `exit ${code}`}`)));
|
|
140
|
-
});
|
|
141
|
-
// Cross-process lock via atomic mkdir, mirroring the CLI self-update lock so two
|
|
142
|
-
// concurrent `runtime up` invocations don't download the same archive twice.
|
|
143
|
-
const withLock = async (version, fn) => {
|
|
144
|
-
const lockPath = join(cacheDir(version), ".download.lock");
|
|
145
|
-
await mkdir(dirname(lockPath), { recursive: true });
|
|
146
|
-
for (let attempt = 0; attempt < 600; attempt += 1) {
|
|
147
|
-
try {
|
|
148
|
-
await mkdir(lockPath);
|
|
149
|
-
try {
|
|
150
|
-
return await fn();
|
|
151
|
-
}
|
|
152
|
-
finally {
|
|
153
|
-
await rm(lockPath, { recursive: true, force: true });
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
catch (err) {
|
|
157
|
-
if (err.code !== "EEXIST")
|
|
158
|
-
throw err;
|
|
159
|
-
const info = await stat(lockPath).catch(() => null);
|
|
160
|
-
if (info && Date.now() - info.mtimeMs > LOCK_STALE_MS) {
|
|
161
|
-
await rm(lockPath, { recursive: true, force: true }).catch(() => undefined);
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
await new Promise((r) => setTimeout(r, 500));
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
throw new SandboxdDownloadError("Timed out waiting for the sandboxd download lock");
|
|
168
|
-
};
|
|
169
|
-
const downloadAndVerify = async (version, target) => {
|
|
170
|
-
const name = archiveName(version, target);
|
|
171
|
-
const archiveUrl = `${cdnBaseUrl()}/${version}/${name}`;
|
|
172
|
-
const checksumUrl = `${archiveUrl}.sha256`;
|
|
173
|
-
const tempDir = await mkdtemp(join(tmpdir(), "cohub-sandboxd-"));
|
|
174
|
-
try {
|
|
175
|
-
const archivePath = join(tempDir, name);
|
|
176
|
-
// Fetch archive to disk (timeout covers the full body stream).
|
|
177
|
-
await downloadToFile(archiveUrl, "application/gzip", archivePath);
|
|
178
|
-
// Fetch and verify checksum. The .sha256 file is `<hash> <filename>`.
|
|
179
|
-
const checksumText = await fetchText(checksumUrl, "text/plain");
|
|
180
|
-
const expected = checksumText.split(/\s+/)[0]?.toLowerCase();
|
|
181
|
-
if (!expected || !/^[0-9a-f]{64}$/.test(expected)) {
|
|
182
|
-
throw new SandboxdDownloadError(`Invalid checksum manifest for ${name}`);
|
|
183
|
-
}
|
|
184
|
-
const actual = (await sha256File(archivePath)).toLowerCase();
|
|
185
|
-
if (actual !== expected) {
|
|
186
|
-
throw new SandboxdDownloadError(`Checksum mismatch for ${name} (expected ${expected}, got ${actual})`);
|
|
187
|
-
}
|
|
188
|
-
const entries = await validateSandboxdArchive(archivePath, target.goos);
|
|
189
|
-
await extractTarGz(archivePath, tempDir);
|
|
190
|
-
for (const entry of entries) {
|
|
191
|
-
if (!(await isSafeArchiveFile(join(tempDir, entry)))) {
|
|
192
|
-
throw new SandboxdDownloadError(`Unsafe sandbox archive entry: ${entry}`);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
const extractedBinary = join(tempDir, binaryName(target.goos));
|
|
196
|
-
if (!(await isSafeArchiveFile(extractedBinary))) {
|
|
197
|
-
throw new SandboxdDownloadError(`Archive ${name} did not contain ${binaryName(target.goos)}`);
|
|
198
|
-
}
|
|
199
|
-
// Atomically move into the version cache (fall back to copy across devices).
|
|
200
|
-
const dest = cachedBinaryPath(version, target);
|
|
201
|
-
await mkdir(dirname(dest), { recursive: true });
|
|
202
|
-
await rename(extractedBinary, dest).catch(async (err) => {
|
|
203
|
-
if (err.code !== "EXDEV")
|
|
204
|
-
throw err;
|
|
205
|
-
await copyFile(extractedBinary, dest);
|
|
206
|
-
});
|
|
207
|
-
await chmod(dest, 0o755);
|
|
208
|
-
return dest;
|
|
209
|
-
}
|
|
210
|
-
finally {
|
|
211
|
-
await rm(tempDir, { recursive: true, force: true }).catch(() => undefined);
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
// Resolve a runnable sandboxd binary path, downloading (once, cached) if needed.
|
|
215
|
-
// COHUB_SANDBOXD_BIN always takes precedence for local development and offline use.
|
|
216
|
-
export const ensureSandboxdBinary = async (options = {}) => {
|
|
217
|
-
const override = process.env.COHUB_SANDBOXD_BIN?.trim();
|
|
218
|
-
if (override) {
|
|
219
|
-
if (!(await isExecutableFile(override))) {
|
|
220
|
-
throw new SandboxdDownloadError(`COHUB_SANDBOXD_BIN=${override} is not a file`);
|
|
221
|
-
}
|
|
222
|
-
return override;
|
|
223
|
-
}
|
|
224
|
-
const version = options.version?.trim() || SANDBOXD_VERSION;
|
|
225
|
-
const target = resolveTarget();
|
|
226
|
-
const cached = cachedBinaryPath(version, target);
|
|
227
|
-
if (await isExecutableFile(cached))
|
|
228
|
-
return cached;
|
|
229
|
-
return withLock(version, async () => {
|
|
230
|
-
// Re-check inside the lock: another process may have finished downloading.
|
|
231
|
-
if (await isExecutableFile(cached))
|
|
232
|
-
return cached;
|
|
233
|
-
options.onStatus?.(`Downloading sandbox runtime ${version} (${target.goos}/${target.goarch})`);
|
|
234
|
-
const path = await downloadAndVerify(version, target);
|
|
235
|
-
options.onStatus?.("Sandbox runtime ready");
|
|
236
|
-
return path;
|
|
237
|
-
});
|
|
238
|
-
};
|