@neta-art/cohub-cli 10.23.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/README.md +18 -5
- 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 -118
- 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 -64
- 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 -2139
- 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 -6
- package/dist/session-status.js +0 -16
- 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
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { readdir, readFile } from "node:fs/promises";
|
|
2
|
-
import { setTimeout as delay } from "node:timers/promises";
|
|
3
|
-
import { spawn } from "node:child_process";
|
|
4
|
-
export class ProcessCleanupUncertainError extends Error {
|
|
5
|
-
}
|
|
6
|
-
/** A member that can still execute code. Zombies cannot, so they never block cleanup. */
|
|
7
|
-
const executable = (member) => member.state !== "Z" && member.state !== "X";
|
|
8
|
-
/** Linux: /proc/<pid>/stat exposes pgrp and state for every member of the group. */
|
|
9
|
-
async function probeLinux(pid) {
|
|
10
|
-
const members = [];
|
|
11
|
-
for (const entry of await readdir("/proc")) {
|
|
12
|
-
if (!/^\d+$/.test(entry))
|
|
13
|
-
continue;
|
|
14
|
-
try {
|
|
15
|
-
const stat = await readFile(`/proc/${entry}/stat`, "utf8");
|
|
16
|
-
// After removing `pid (comm)`: state, ppid, pgrp, session, ...
|
|
17
|
-
const [state, , processGroupId] = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
18
|
-
if (processGroupId !== undefined && Number(processGroupId) === pid)
|
|
19
|
-
members.push({ pid: Number(entry), state: state ?? "U" });
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
// Exited between readdir and read.
|
|
23
|
-
if (!["ENOENT", "ESRCH"].includes(error.code ?? ""))
|
|
24
|
-
throw error;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return members.some(executable) ? { state: "alive", members } : { state: "quiescent", members };
|
|
28
|
-
}
|
|
29
|
-
/** macOS/BSD: one `ps` snapshot; a zombie's STAT starts with Z. */
|
|
30
|
-
async function probePosixSnapshot(pid) {
|
|
31
|
-
const output = await new Promise((resolve, reject) => {
|
|
32
|
-
const task = spawn("ps", ["-A", "-o", "pid=,pgid=,stat="], { stdio: ["ignore", "pipe", "ignore"] });
|
|
33
|
-
let text = "";
|
|
34
|
-
task.stdout.on("data", (chunk) => { text += chunk.toString(); });
|
|
35
|
-
task.once("error", reject);
|
|
36
|
-
task.once("close", (code) => code === 0 ? resolve(text) : reject(new Error(`ps exited ${code}`)));
|
|
37
|
-
});
|
|
38
|
-
const members = [];
|
|
39
|
-
for (const line of output.split("\n")) {
|
|
40
|
-
const [processId, processGroupId, stat] = line.trim().split(/\s+/);
|
|
41
|
-
if (processGroupId !== undefined && Number(processGroupId) === pid)
|
|
42
|
-
members.push({ pid: Number(processId), state: stat?.[0] ?? "U" });
|
|
43
|
-
}
|
|
44
|
-
return members.some(executable) ? { state: "alive", members } : { state: "quiescent", members };
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* `kill(-pgid)` outcomes that carry no liveness information on their own.
|
|
48
|
-
* ESRCH: the group is gone. EPERM: xnu's killpg1() reports it when no member can be
|
|
49
|
-
* signalled anymore (exited or zombie), so on macOS it is the normal end state; our
|
|
50
|
-
* harnesses run as the same user, so a real permission denial cannot occur here.
|
|
51
|
-
*/
|
|
52
|
-
const signalCode = (error) => error.code;
|
|
53
|
-
const groupUnsignallable = (error) => signalCode(error) === "ESRCH" || signalCode(error) === "EPERM";
|
|
54
|
-
/**
|
|
55
|
-
* Windows has no process groups: cleanup kills the tree with taskkill, so the leader's
|
|
56
|
-
* absence is the practical quiescence signal. A reused PID can only keep a result
|
|
57
|
-
* uncertain, never wrongly confirm it.
|
|
58
|
-
*/
|
|
59
|
-
async function probeWindows(pid) {
|
|
60
|
-
try {
|
|
61
|
-
process.kill(pid, 0);
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
if (signalCode(error) === "ESRCH")
|
|
65
|
-
return { state: "quiescent", members: [] };
|
|
66
|
-
return { state: "unknown", cause: error };
|
|
67
|
-
}
|
|
68
|
-
return { state: "alive", members: [{ pid, state: "R" }] };
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* A group is alive only while a member can still execute. `kill(0)` is only a fast
|
|
72
|
-
* path; the platform snapshot is the source of truth, and only a failing snapshot is
|
|
73
|
-
* uncertain.
|
|
74
|
-
*/
|
|
75
|
-
async function probeProcessGroup(pid) {
|
|
76
|
-
if (process.platform === "win32")
|
|
77
|
-
return probeWindows(pid);
|
|
78
|
-
try {
|
|
79
|
-
process.kill(-pid, 0);
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
if (signalCode(error) === "ESRCH")
|
|
83
|
-
return { state: "quiescent", members: [] };
|
|
84
|
-
if (signalCode(error) !== "EPERM")
|
|
85
|
-
return { state: "unknown", cause: error };
|
|
86
|
-
}
|
|
87
|
-
if (process.platform === "linux") {
|
|
88
|
-
try {
|
|
89
|
-
return await probeLinux(pid);
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
return { state: "unknown", cause: error };
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
try {
|
|
96
|
-
return await probePosixSnapshot(pid);
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
return { state: "unknown", cause: error };
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
const describeMembers = (members) => members.map((member) => `${member.pid}:${member.state}`).join(" ") || "none";
|
|
103
|
-
/** True only when the process group is gone or holds nothing that can execute. */
|
|
104
|
-
export async function confirmQuiescentProcessGroup(pid) {
|
|
105
|
-
const probe = await probeProcessGroup(pid);
|
|
106
|
-
return probe.state === "quiescent";
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Poll until the probe confirms quiescence. The interval backs off from 25ms to 200ms:
|
|
110
|
-
* normal exits confirm on the first probe, while a resistant group stops spawning
|
|
111
|
-
* snapshot subprocesses at full rate.
|
|
112
|
-
*/
|
|
113
|
-
async function awaitQuiescence(pid, probe, escalate) {
|
|
114
|
-
const started = Date.now();
|
|
115
|
-
let escalated = false;
|
|
116
|
-
let pollMs = 25;
|
|
117
|
-
for (;;) {
|
|
118
|
-
const state = await probe(pid);
|
|
119
|
-
if (state.state === "quiescent")
|
|
120
|
-
return;
|
|
121
|
-
if (state.state === "unknown" || Date.now() - started >= 5000) {
|
|
122
|
-
throw new Error(state.state === "unknown" ? `probe failed: ${state.cause instanceof Error ? state.cause.message : String(state.cause)}` : `still running: ${describeMembers(state.members)}`);
|
|
123
|
-
}
|
|
124
|
-
if (escalate && !escalated && Date.now() - started >= 2000) {
|
|
125
|
-
escalate();
|
|
126
|
-
escalated = true;
|
|
127
|
-
}
|
|
128
|
-
await delay(pollMs);
|
|
129
|
-
pollMs = Math.min(pollMs * 2, 200);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
export async function stopProcessGroup(pid) {
|
|
133
|
-
try {
|
|
134
|
-
if (process.platform === "win32") {
|
|
135
|
-
// taskkill's exit code is not authoritative: a PID that already exited is an
|
|
136
|
-
// "error". The request is sent, then liveness decides.
|
|
137
|
-
await new Promise((resolve) => {
|
|
138
|
-
const task = spawn("taskkill", ["/PID", String(pid), "/T", "/F"], { stdio: "ignore", timeout: 5000 });
|
|
139
|
-
task.once("error", () => resolve());
|
|
140
|
-
task.once("exit", () => resolve());
|
|
141
|
-
});
|
|
142
|
-
await awaitQuiescence(pid, probeWindows);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
const signal = (value) => {
|
|
146
|
-
try {
|
|
147
|
-
process.kill(-pid, value);
|
|
148
|
-
}
|
|
149
|
-
catch (error) {
|
|
150
|
-
if (!groupUnsignallable(error))
|
|
151
|
-
throw error;
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
signal("SIGTERM");
|
|
155
|
-
await awaitQuiescence(pid, probeProcessGroup, () => signal("SIGKILL"));
|
|
156
|
-
}
|
|
157
|
-
catch (cause) {
|
|
158
|
-
// Any cleanup failure leaves the outcome unresolved; callers treat it as uncertain.
|
|
159
|
-
throw new ProcessCleanupUncertainError(`Tool process cleanup could not be confirmed; execution remains unresolved (${cause instanceof Error ? cause.message : String(cause)})`, { cause });
|
|
160
|
-
}
|
|
161
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { NativeProjection, ProjectionTarget } from "@neta-art/cohub";
|
|
2
|
-
import { type ProjectionSourceTurn, type SessionTurnProjectionClient } from "./turn-projection.js";
|
|
3
|
-
export type ProjectionStoreInput = {
|
|
4
|
-
spaceId: string;
|
|
5
|
-
sessionId: string;
|
|
6
|
-
turnId: string;
|
|
7
|
-
nativeSessionId: string;
|
|
8
|
-
cwd: string;
|
|
9
|
-
provider?: string | null;
|
|
10
|
-
target: ProjectionTarget;
|
|
11
|
-
throughTurnId: string | null;
|
|
12
|
-
};
|
|
13
|
-
export type ProjectionStoreResult = {
|
|
14
|
-
projection: NativeProjection;
|
|
15
|
-
turns: ProjectionSourceTurn[];
|
|
16
|
-
};
|
|
17
|
-
/** Give the projection's own records (the native header) the identity of the file it becomes. */
|
|
18
|
-
export declare function rebindProjectionNativeSession(result: ProjectionStoreResult, nativeSessionId: string): ProjectionStoreResult;
|
|
19
|
-
/**
|
|
20
|
-
* Materializes a Session's durable Turns into one harness-specific native file. Cohub never appends
|
|
21
|
-
* to a native file it did not just write, so every projection is complete up to the Session head.
|
|
22
|
-
*/
|
|
23
|
-
export declare class ProjectionStore {
|
|
24
|
-
private readonly source;
|
|
25
|
-
constructor(source: SessionTurnProjectionClient);
|
|
26
|
-
project(input: ProjectionStoreInput, signal?: AbortSignal): Promise<ProjectionStoreResult>;
|
|
27
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { harnessAdapter } from "./harnesses/index.js";
|
|
2
|
-
import { listSessionProjectionTurns, projectTurnBatch } from "./turn-projection.js";
|
|
3
|
-
/** Give the projection's own records (the native header) the identity of the file it becomes. */
|
|
4
|
-
export function rebindProjectionNativeSession(result, nativeSessionId) {
|
|
5
|
-
const records = harnessAdapter(result.projection.target).session.rebind(result.projection.records, nativeSessionId);
|
|
6
|
-
return { ...result, projection: { ...result.projection, records } };
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Materializes a Session's durable Turns into one harness-specific native file. Cohub never appends
|
|
10
|
-
* to a native file it did not just write, so every projection is complete up to the Session head.
|
|
11
|
-
*/
|
|
12
|
-
export class ProjectionStore {
|
|
13
|
-
source;
|
|
14
|
-
constructor(source) {
|
|
15
|
-
this.source = source;
|
|
16
|
-
}
|
|
17
|
-
async project(input, signal) {
|
|
18
|
-
const throughSequence = input.throughTurnId ? (await this.source.session(input.sessionId).turns.get(input.throughTurnId, { signal })).turn.sequence : 0;
|
|
19
|
-
const turns = await listSessionProjectionTurns(this.source, input.sessionId, { throughSequence, excludeTurnId: input.turnId, signal });
|
|
20
|
-
const projection = projectTurnBatch({
|
|
21
|
-
spaceId: input.spaceId,
|
|
22
|
-
sessionId: input.sessionId,
|
|
23
|
-
nativeSessionId: input.nativeSessionId,
|
|
24
|
-
cwd: input.cwd,
|
|
25
|
-
provider: input.provider,
|
|
26
|
-
turns,
|
|
27
|
-
}, input.target);
|
|
28
|
-
return { projection, turns };
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
export type RuntimeSpaceBinding = {
|
|
2
|
-
/** Canonical local workspace root. */
|
|
3
|
-
root: string;
|
|
4
|
-
/** Environment + authenticated actor identity. */
|
|
5
|
-
key: string;
|
|
6
|
-
spaceId: string;
|
|
7
|
-
};
|
|
8
|
-
export type RuntimeSpaceBindingsFile = {
|
|
9
|
-
version: 1;
|
|
10
|
-
bindings: RuntimeSpaceBinding[];
|
|
11
|
-
};
|
|
12
|
-
export type RuntimeSpaceBindingResolution = {
|
|
13
|
-
spaceId: string;
|
|
14
|
-
source: "binding" | "created" | "explicit";
|
|
15
|
-
};
|
|
16
|
-
export declare class RuntimeSpaceBindingsError extends Error {
|
|
17
|
-
name: string;
|
|
18
|
-
}
|
|
19
|
-
export declare function runtimeSpaceBindingsPath(): string;
|
|
20
|
-
export declare function normalizeRuntimeRoot(root: string): string;
|
|
21
|
-
export declare function canonicalRuntimeRoot(root: string): Promise<string>;
|
|
22
|
-
export declare function parseRuntimeSpaceBindings(raw: string, path?: string): RuntimeSpaceBindingsFile;
|
|
23
|
-
export declare function readRuntimeSpaceBindings(path?: string): Promise<RuntimeSpaceBindingsFile>;
|
|
24
|
-
export declare function findRuntimeSpaceBinding(bindings: RuntimeSpaceBinding[] | RuntimeSpaceBindingsFile, input: {
|
|
25
|
-
root: string;
|
|
26
|
-
key: string;
|
|
27
|
-
}): RuntimeSpaceBinding | null;
|
|
28
|
-
export declare function withRuntimeSpaceBindingsLock<T>(fn: () => Promise<T>, options?: {
|
|
29
|
-
path?: string;
|
|
30
|
-
lockPath?: string;
|
|
31
|
-
}): Promise<T>;
|
|
32
|
-
export declare function getRuntimeSpaceBinding(root: string, key: string | null | undefined, path?: string): Promise<RuntimeSpaceBinding | null>;
|
|
33
|
-
/**
|
|
34
|
-
* Resolve a local Runtime Space without silently creating duplicates.
|
|
35
|
-
* The per-binding lock covers creation; the shared file is locked only for
|
|
36
|
-
* short read-modify-write commits.
|
|
37
|
-
*/
|
|
38
|
-
export declare function resolveRuntimeSpace(input: {
|
|
39
|
-
root: string;
|
|
40
|
-
identityKey: string | null | undefined;
|
|
41
|
-
explicitSpaceId?: string | null;
|
|
42
|
-
/** Explicit new selection; compare the binding observed before prompting. */
|
|
43
|
-
newSpace?: boolean;
|
|
44
|
-
expectedSpaceId?: string | null;
|
|
45
|
-
createSpace: () => Promise<string>;
|
|
46
|
-
validateSpace?: (spaceId: string) => Promise<void>;
|
|
47
|
-
path?: string;
|
|
48
|
-
}): Promise<RuntimeSpaceBindingResolution>;
|
|
@@ -1,342 +0,0 @@
|
|
|
1
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
-
import { chmod, mkdir, open, readFile, readdir, realpath, rename, rm, rmdir, stat, utimes, writeFile } from "node:fs/promises";
|
|
3
|
-
import { homedir } from "node:os";
|
|
4
|
-
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
5
|
-
import { setTimeout as delay } from "node:timers/promises";
|
|
6
|
-
const CONFIG_DIR_NAME = ".config";
|
|
7
|
-
const CONFIG_FILE_NAME = "runtime-spaces.json";
|
|
8
|
-
const LOCK_STALE_MS = 5 * 60 * 1000;
|
|
9
|
-
const LOCK_HEARTBEAT_MS = 60 * 1000;
|
|
10
|
-
const LOCK_RETRY_MS = 100;
|
|
11
|
-
const LOCK_ATTEMPTS = 600;
|
|
12
|
-
const GLOBAL_LOCK_SUFFIX = ".lock";
|
|
13
|
-
export class RuntimeSpaceBindingsError extends Error {
|
|
14
|
-
name = "RuntimeSpaceBindingsError";
|
|
15
|
-
}
|
|
16
|
-
const missing = (error) => error?.code === "ENOENT";
|
|
17
|
-
const nonEmptyString = (value) => typeof value === "string" && value.trim().length > 0;
|
|
18
|
-
export function runtimeSpaceBindingsPath() {
|
|
19
|
-
return join(homedir(), CONFIG_DIR_NAME, "cohub", CONFIG_FILE_NAME);
|
|
20
|
-
}
|
|
21
|
-
export function normalizeRuntimeRoot(root) {
|
|
22
|
-
return resolve(root);
|
|
23
|
-
}
|
|
24
|
-
export async function canonicalRuntimeRoot(root) {
|
|
25
|
-
return realpath(normalizeRuntimeRoot(root));
|
|
26
|
-
}
|
|
27
|
-
function invalidBindings(path, detail) {
|
|
28
|
-
return new RuntimeSpaceBindingsError(`Runtime Space bindings are invalid${detail ? ` (${detail})` : ""}: ${path}`);
|
|
29
|
-
}
|
|
30
|
-
export function parseRuntimeSpaceBindings(raw, path = CONFIG_FILE_NAME) {
|
|
31
|
-
let value;
|
|
32
|
-
try {
|
|
33
|
-
value = JSON.parse(raw);
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
throw invalidBindings(path, "invalid JSON");
|
|
37
|
-
}
|
|
38
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
39
|
-
throw invalidBindings(path);
|
|
40
|
-
}
|
|
41
|
-
const record = value;
|
|
42
|
-
if (record.version !== 1 || !Array.isArray(record.bindings)) {
|
|
43
|
-
throw invalidBindings(path, "unsupported format");
|
|
44
|
-
}
|
|
45
|
-
const seen = new Set();
|
|
46
|
-
const bindings = [];
|
|
47
|
-
for (const item of record.bindings) {
|
|
48
|
-
if (!item || typeof item !== "object" || Array.isArray(item)) {
|
|
49
|
-
throw invalidBindings(path, "invalid binding");
|
|
50
|
-
}
|
|
51
|
-
const binding = item;
|
|
52
|
-
if (!nonEmptyString(binding.root) || !isAbsolute(binding.root)) {
|
|
53
|
-
throw invalidBindings(path, "binding root must be absolute");
|
|
54
|
-
}
|
|
55
|
-
if (!nonEmptyString(binding.key) || !nonEmptyString(binding.spaceId)) {
|
|
56
|
-
throw invalidBindings(path, "binding identity is incomplete");
|
|
57
|
-
}
|
|
58
|
-
const root = normalizeRuntimeRoot(binding.root);
|
|
59
|
-
const key = binding.key.trim();
|
|
60
|
-
const spaceId = binding.spaceId.trim();
|
|
61
|
-
const identity = `${key}\u0000${root}`;
|
|
62
|
-
if (seen.has(identity))
|
|
63
|
-
throw invalidBindings(path, "duplicate binding");
|
|
64
|
-
seen.add(identity);
|
|
65
|
-
bindings.push({ root, key, spaceId });
|
|
66
|
-
}
|
|
67
|
-
return { version: 1, bindings };
|
|
68
|
-
}
|
|
69
|
-
export async function readRuntimeSpaceBindings(path = runtimeSpaceBindingsPath()) {
|
|
70
|
-
try {
|
|
71
|
-
return parseRuntimeSpaceBindings(await readFile(path, "utf8"), path);
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
if (missing(error))
|
|
75
|
-
return { version: 1, bindings: [] };
|
|
76
|
-
throw error;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
export function findRuntimeSpaceBinding(bindings, input) {
|
|
80
|
-
const entries = Array.isArray(bindings) ? bindings : bindings.bindings;
|
|
81
|
-
const root = normalizeRuntimeRoot(input.root);
|
|
82
|
-
const key = input.key.trim();
|
|
83
|
-
return entries.find((binding) => binding.root === root && binding.key === key) ?? null;
|
|
84
|
-
}
|
|
85
|
-
function upsertRuntimeSpaceBinding(file, binding) {
|
|
86
|
-
const root = normalizeRuntimeRoot(binding.root);
|
|
87
|
-
const key = binding.key.trim();
|
|
88
|
-
const spaceId = binding.spaceId.trim();
|
|
89
|
-
const nextBinding = { root, key, spaceId };
|
|
90
|
-
const index = file.bindings.findIndex((item) => item.root === root && item.key === key);
|
|
91
|
-
if (index < 0) {
|
|
92
|
-
return { file: { version: 1, bindings: [...file.bindings, nextBinding] }, changed: true };
|
|
93
|
-
}
|
|
94
|
-
const current = file.bindings[index];
|
|
95
|
-
if (current?.root === root && current.key === key && current.spaceId === spaceId) {
|
|
96
|
-
return { file, changed: false };
|
|
97
|
-
}
|
|
98
|
-
const bindings = [...file.bindings];
|
|
99
|
-
bindings[index] = nextBinding;
|
|
100
|
-
return { file: { version: 1, bindings }, changed: true };
|
|
101
|
-
}
|
|
102
|
-
async function writeRuntimeJson(path, file) {
|
|
103
|
-
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
104
|
-
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
105
|
-
try {
|
|
106
|
-
const output = await open(temporary, "wx", 0o600);
|
|
107
|
-
try {
|
|
108
|
-
await output.writeFile(`${JSON.stringify(file, null, 2)}\n`, "utf8");
|
|
109
|
-
await output.sync();
|
|
110
|
-
}
|
|
111
|
-
finally {
|
|
112
|
-
await output.close();
|
|
113
|
-
}
|
|
114
|
-
await rename(temporary, path);
|
|
115
|
-
await chmod(path, 0o600);
|
|
116
|
-
if (process.platform !== "win32") {
|
|
117
|
-
const directory = await open(dirname(path), "r");
|
|
118
|
-
try {
|
|
119
|
-
await directory.sync();
|
|
120
|
-
}
|
|
121
|
-
finally {
|
|
122
|
-
await directory.close();
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
finally {
|
|
127
|
-
await rm(temporary, { force: true });
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
const statIfPresent = async (path) => stat(path, { bigint: false }).catch((error) => {
|
|
131
|
-
if (missing(error))
|
|
132
|
-
return null;
|
|
133
|
-
throw error;
|
|
134
|
-
});
|
|
135
|
-
async function lockSnapshot(lockPath) {
|
|
136
|
-
let names;
|
|
137
|
-
try {
|
|
138
|
-
names = await readdir(lockPath);
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
// A malformed non-directory lock is not safe to reclaim automatically.
|
|
142
|
-
if (missing(error) || error.code === "ENOTDIR")
|
|
143
|
-
return null;
|
|
144
|
-
throw error;
|
|
145
|
-
}
|
|
146
|
-
if (names.length !== 1 || !names[0])
|
|
147
|
-
return null;
|
|
148
|
-
const owner = names[0];
|
|
149
|
-
const info = await statIfPresent(join(lockPath, owner));
|
|
150
|
-
return info ? { owner, mtimeMs: info.mtimeMs } : null;
|
|
151
|
-
}
|
|
152
|
-
async function reclaimStaleLock(lockPath, snapshot) {
|
|
153
|
-
const ownerPath = join(lockPath, snapshot.owner);
|
|
154
|
-
const current = await statIfPresent(ownerPath);
|
|
155
|
-
if (!current || Date.now() - current.mtimeMs <= LOCK_STALE_MS)
|
|
156
|
-
return false;
|
|
157
|
-
// Remove only the owner observed during the stale check. If another process
|
|
158
|
-
// replaced the lock, its owner token is different and rmdir stays harmless.
|
|
159
|
-
await rm(ownerPath, { force: true });
|
|
160
|
-
try {
|
|
161
|
-
await rmdir(lockPath);
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
catch (error) {
|
|
165
|
-
const code = error.code;
|
|
166
|
-
if (code === "ENOENT" || code === "ENOTEMPTY" || code === "EEXIST")
|
|
167
|
-
return false;
|
|
168
|
-
throw error;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
async function acquireLock(lockPath) {
|
|
172
|
-
await mkdir(dirname(lockPath), { recursive: true, mode: 0o700 });
|
|
173
|
-
for (let attempt = 0; attempt < LOCK_ATTEMPTS; attempt += 1) {
|
|
174
|
-
try {
|
|
175
|
-
await mkdir(lockPath, { mode: 0o700 });
|
|
176
|
-
const owner = randomUUID();
|
|
177
|
-
try {
|
|
178
|
-
// The owner token is the filename. Removing this exact file before
|
|
179
|
-
// rmdir makes an old process unable to remove a replacement lock.
|
|
180
|
-
await writeFile(join(lockPath, owner), "", { encoding: "utf8", mode: 0o600, flag: "wx" });
|
|
181
|
-
}
|
|
182
|
-
catch (error) {
|
|
183
|
-
await rm(join(lockPath, owner), { force: true });
|
|
184
|
-
await rmdir(lockPath).catch((cleanupError) => {
|
|
185
|
-
const code = cleanupError.code;
|
|
186
|
-
if (code !== "ENOENT" && code !== "ENOTEMPTY" && code !== "EEXIST")
|
|
187
|
-
throw cleanupError;
|
|
188
|
-
});
|
|
189
|
-
throw error;
|
|
190
|
-
}
|
|
191
|
-
return owner;
|
|
192
|
-
}
|
|
193
|
-
catch (error) {
|
|
194
|
-
if (error.code !== "EEXIST")
|
|
195
|
-
throw error;
|
|
196
|
-
const snapshot = await lockSnapshot(lockPath);
|
|
197
|
-
if (snapshot && Date.now() - snapshot.mtimeMs > LOCK_STALE_MS) {
|
|
198
|
-
await reclaimStaleLock(lockPath, snapshot);
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
await delay(LOCK_RETRY_MS);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
throw new RuntimeSpaceBindingsError("Timed out waiting for the Runtime Space bindings lock");
|
|
205
|
-
}
|
|
206
|
-
async function releaseLock(lockPath, owner) {
|
|
207
|
-
await rm(join(lockPath, owner), { force: true });
|
|
208
|
-
await rmdir(lockPath).catch((error) => {
|
|
209
|
-
const code = error.code;
|
|
210
|
-
if (code !== "ENOENT" && code !== "ENOTEMPTY" && code !== "EEXIST")
|
|
211
|
-
throw error;
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
async function refreshLock(lockPath, owner) {
|
|
215
|
-
const ownerPath = join(lockPath, owner);
|
|
216
|
-
const current = await stat(ownerPath).catch((error) => {
|
|
217
|
-
if (missing(error))
|
|
218
|
-
return null;
|
|
219
|
-
throw error;
|
|
220
|
-
});
|
|
221
|
-
if (!current)
|
|
222
|
-
return;
|
|
223
|
-
const now = new Date();
|
|
224
|
-
await utimes(ownerPath, now, now);
|
|
225
|
-
}
|
|
226
|
-
export async function withRuntimeSpaceBindingsLock(fn, options = {}) {
|
|
227
|
-
const path = options.path ?? runtimeSpaceBindingsPath();
|
|
228
|
-
const lockPath = options.lockPath ?? `${path}${GLOBAL_LOCK_SUFFIX}`;
|
|
229
|
-
const owner = await acquireLock(lockPath);
|
|
230
|
-
const heartbeat = setInterval(() => {
|
|
231
|
-
void refreshLock(lockPath, owner).catch(() => undefined);
|
|
232
|
-
}, LOCK_HEARTBEAT_MS);
|
|
233
|
-
heartbeat.unref?.();
|
|
234
|
-
try {
|
|
235
|
-
return await fn();
|
|
236
|
-
}
|
|
237
|
-
finally {
|
|
238
|
-
clearInterval(heartbeat);
|
|
239
|
-
await releaseLock(lockPath, owner);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
function bindingLockPath(path, root, key) {
|
|
243
|
-
const digest = createHash("sha256").update(`${key}\u0000${root}`).digest("hex");
|
|
244
|
-
return `${path}.${digest}.lock`;
|
|
245
|
-
}
|
|
246
|
-
async function persistRuntimeSpaceBinding(path, binding) {
|
|
247
|
-
await withRuntimeSpaceBindingsLock(async () => {
|
|
248
|
-
const file = await readRuntimeSpaceBindings(path);
|
|
249
|
-
const result = upsertRuntimeSpaceBinding(file, binding);
|
|
250
|
-
if (result.changed)
|
|
251
|
-
await writeRuntimeJson(path, result.file);
|
|
252
|
-
}, { path, lockPath: `${path}${GLOBAL_LOCK_SUFFIX}` });
|
|
253
|
-
}
|
|
254
|
-
export async function getRuntimeSpaceBinding(root, key, path = runtimeSpaceBindingsPath()) {
|
|
255
|
-
if (!nonEmptyString(key))
|
|
256
|
-
return null;
|
|
257
|
-
const canonicalRoot = await canonicalRuntimeRoot(root);
|
|
258
|
-
const file = await readRuntimeSpaceBindings(path);
|
|
259
|
-
return findRuntimeSpaceBinding(file, { root: canonicalRoot, key: key.trim() });
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Resolve a local Runtime Space without silently creating duplicates.
|
|
263
|
-
* The per-binding lock covers creation; the shared file is locked only for
|
|
264
|
-
* short read-modify-write commits.
|
|
265
|
-
*/
|
|
266
|
-
export async function resolveRuntimeSpace(input) {
|
|
267
|
-
const root = await canonicalRuntimeRoot(input.root);
|
|
268
|
-
const explicitSpaceId = input.explicitSpaceId?.trim() || null;
|
|
269
|
-
const identityKey = input.identityKey?.trim() || null;
|
|
270
|
-
const path = input.path ?? runtimeSpaceBindingsPath();
|
|
271
|
-
// An explicit target remains usable even in an environment where there is no
|
|
272
|
-
// decodable identity to scope a persisted local binding to.
|
|
273
|
-
if (!identityKey) {
|
|
274
|
-
if (explicitSpaceId) {
|
|
275
|
-
await input.validateSpace?.(explicitSpaceId);
|
|
276
|
-
return { spaceId: explicitSpaceId, source: "explicit" };
|
|
277
|
-
}
|
|
278
|
-
throw new RuntimeSpaceBindingsError("Cannot remember a local Runtime Space without an authenticated identity");
|
|
279
|
-
}
|
|
280
|
-
const bindingKey = identityKey;
|
|
281
|
-
const lockPath = bindingLockPath(path, root, bindingKey);
|
|
282
|
-
return withRuntimeSpaceBindingsLock(async () => {
|
|
283
|
-
const file = await readRuntimeSpaceBindings(path);
|
|
284
|
-
const receiptPath = `${lockPath}.creation.json`;
|
|
285
|
-
if (explicitSpaceId) {
|
|
286
|
-
await input.validateSpace?.(explicitSpaceId);
|
|
287
|
-
await persistRuntimeSpaceBinding(path, { root, key: bindingKey, spaceId: explicitSpaceId });
|
|
288
|
-
// Preserve an ambiguous creation receipt for diagnosis, rather than deleting it.
|
|
289
|
-
if (await statIfPresent(receiptPath))
|
|
290
|
-
await rename(receiptPath, `${receiptPath}.${randomUUID()}.resolved`);
|
|
291
|
-
return { spaceId: explicitSpaceId, source: "explicit" };
|
|
292
|
-
}
|
|
293
|
-
const existing = findRuntimeSpaceBinding(file, { root, key: bindingKey });
|
|
294
|
-
if (input.newSpace && (existing?.spaceId ?? null) !== (input.expectedSpaceId ?? null)) {
|
|
295
|
-
throw new RuntimeSpaceBindingsError("Directory binding changed; run up again");
|
|
296
|
-
}
|
|
297
|
-
if (existing && !input.newSpace) {
|
|
298
|
-
await input.validateSpace?.(existing.spaceId);
|
|
299
|
-
return { spaceId: existing.spaceId, source: "binding" };
|
|
300
|
-
}
|
|
301
|
-
// Fail closed across the remote-create/local-commit crash window. A saved ID
|
|
302
|
-
// resumes binding; an ambiguous request must be resolved with --space, never replayed.
|
|
303
|
-
let receipt = null;
|
|
304
|
-
try {
|
|
305
|
-
receipt = JSON.parse(await readFile(receiptPath, "utf8"));
|
|
306
|
-
if (!receipt || !nonEmptyString(receipt.operationId) || receipt.spaceId !== undefined && !nonEmptyString(receipt.spaceId)) {
|
|
307
|
-
throw new RuntimeSpaceBindingsError(`Invalid creation receipt; original retained: ${receiptPath}`);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
catch (error) {
|
|
311
|
-
if (!missing(error))
|
|
312
|
-
throw error;
|
|
313
|
-
}
|
|
314
|
-
if (receipt && !receipt.spaceId)
|
|
315
|
-
throw new RuntimeSpaceBindingsError(`A previous Space creation has an unknown outcome. Check your Spaces and use --space <id>. ${receiptPath}`);
|
|
316
|
-
if (!receipt) {
|
|
317
|
-
receipt = { operationId: randomUUID() };
|
|
318
|
-
await writeRuntimeJson(receiptPath, receipt);
|
|
319
|
-
}
|
|
320
|
-
let createdSpaceId = receipt.spaceId;
|
|
321
|
-
if (!createdSpaceId) {
|
|
322
|
-
try {
|
|
323
|
-
createdSpaceId = await input.createSpace();
|
|
324
|
-
}
|
|
325
|
-
catch (error) {
|
|
326
|
-
const status = error?.status;
|
|
327
|
-
if (status && status >= 400 && status < 500 && status !== 408)
|
|
328
|
-
await rm(receiptPath);
|
|
329
|
-
throw error;
|
|
330
|
-
}
|
|
331
|
-
await writeRuntimeJson(receiptPath, { ...receipt, spaceId: createdSpaceId });
|
|
332
|
-
}
|
|
333
|
-
if (!nonEmptyString(createdSpaceId)) {
|
|
334
|
-
throw new RuntimeSpaceBindingsError("Local Runtime Space creation returned no Space ID");
|
|
335
|
-
}
|
|
336
|
-
const spaceId = createdSpaceId.trim();
|
|
337
|
-
await input.validateSpace?.(spaceId);
|
|
338
|
-
await persistRuntimeSpaceBinding(path, { root, key: bindingKey, spaceId });
|
|
339
|
-
await rm(receiptPath);
|
|
340
|
-
return { spaceId, source: "created" };
|
|
341
|
-
}, { path, lockPath });
|
|
342
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { type LocalHarness, type RuntimeCapabilities } from "@neta-art/cohub";
|
|
2
|
-
import { type HarnessExecutables } from "./harnesses/index.js";
|
|
3
|
-
import { type RuntimeDiagnostic, type RuntimeDiagnosticLevel } from "./diagnostics.js";
|
|
4
|
-
import { type RuntimeSummary } from "./presentation.js";
|
|
5
|
-
export type RuntimeLaunch = {
|
|
6
|
-
spaceId: string;
|
|
7
|
-
root: string;
|
|
8
|
-
identity: string;
|
|
9
|
-
harnesses: LocalHarness[];
|
|
10
|
-
executables: HarnessExecutables;
|
|
11
|
-
capabilities?: RuntimeCapabilities;
|
|
12
|
-
background: boolean;
|
|
13
|
-
verbose?: boolean;
|
|
14
|
-
/** Start importing earlier conversations as soon as the Runtime is connected. */
|
|
15
|
-
importHistory?: boolean;
|
|
16
|
-
display?: string;
|
|
17
|
-
};
|
|
18
|
-
export declare function sandboxOutputLevel(value: unknown, stream: "stdout" | "stderr"): RuntimeDiagnosticLevel;
|
|
19
|
-
export declare function runRuntime(config: RuntimeLaunch, onState: (status: RuntimeSummary) => void, externalSignal?: AbortSignal, onDiagnostic?: (event: RuntimeDiagnostic) => void): Promise<void>;
|