@neta-art/cohub-cli 10.24.0 → 10.25.1
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/binary-pins.js +5 -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 +311 -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 +2513 -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/rooms.js
DELETED
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
import { getAppByRef } from "../app-ref.js";
|
|
2
|
-
import { createClient } from "../client.js";
|
|
3
|
-
import { error, handleHttp, json as outJson, jsonRequested, ok, table, truncateText } from "../output.js";
|
|
4
|
-
const DURATION_RE = /^(\d+)(ms|s|m|h|d)?$/i;
|
|
5
|
-
const DURATION_UNITS = { ms: 1, s: 1_000, m: 60_000, h: 3_600_000, d: 86_400_000 };
|
|
6
|
-
export function parseDuration(name, value) {
|
|
7
|
-
const match = DURATION_RE.exec(value.trim());
|
|
8
|
-
if (!match)
|
|
9
|
-
return error(`Invalid ${name}`, "Use a duration such as 90s, 10m or 2h.");
|
|
10
|
-
return Number(match[1]) * (DURATION_UNITS[(match[2] ?? "s").toLowerCase()] ?? 1_000);
|
|
11
|
-
}
|
|
12
|
-
function seconds(name, value, range) {
|
|
13
|
-
const result = Math.round(parseDuration(name, value) / 1000);
|
|
14
|
-
if (result < range[0] || result > range[1]) {
|
|
15
|
-
return error(`Invalid ${name}`, `Use a duration from ${formatSeconds(range[0])} to ${formatSeconds(range[1])}.`);
|
|
16
|
-
}
|
|
17
|
-
return result;
|
|
18
|
-
}
|
|
19
|
-
const formatSeconds = (value) => (value % 3600 === 0 ? `${value / 3600}h` : value % 60 === 0 ? `${value / 60}m` : `${value}s`);
|
|
20
|
-
const MINUTE = 60;
|
|
21
|
-
const DAY = 24 * 60 * MINUTE;
|
|
22
|
-
function parseJson(name, value) {
|
|
23
|
-
try {
|
|
24
|
-
return JSON.parse(value);
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
return error(`Invalid ${name}`, `${name} must be JSON, e.g. '{"text":"hi"}'.`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async function readStdin() {
|
|
31
|
-
let input = "";
|
|
32
|
-
for await (const chunk of process.stdin)
|
|
33
|
-
input += chunk;
|
|
34
|
-
return input;
|
|
35
|
-
}
|
|
36
|
-
function parsePresence(value) {
|
|
37
|
-
const presence = parseJson("presence", value);
|
|
38
|
-
if (presence === null || (typeof presence === "object" && !Array.isArray(presence)))
|
|
39
|
-
return presence;
|
|
40
|
-
return error("Invalid presence", "presence must be a JSON object, or null to clear it.");
|
|
41
|
-
}
|
|
42
|
-
const short = (participantId) => participantId.slice(0, 8);
|
|
43
|
-
function printMembers(view) {
|
|
44
|
-
table(view.members.map((member) => ({
|
|
45
|
-
member: `${short(member.participantId)}${member.participantId === view.participantId ? " (you)" : ""}`,
|
|
46
|
-
kind: member.kind ?? "user",
|
|
47
|
-
model: member.model?.id ?? "",
|
|
48
|
-
presence: member.presence ? truncateText(JSON.stringify(member.presence), 60) : "",
|
|
49
|
-
})), [
|
|
50
|
-
{ key: "member", label: "Member" },
|
|
51
|
-
{ key: "kind", label: "Kind" },
|
|
52
|
-
{ key: "model", label: "Model" },
|
|
53
|
-
{ key: "presence", label: "Presence" },
|
|
54
|
-
]);
|
|
55
|
-
}
|
|
56
|
-
function printView(view) {
|
|
57
|
-
console.log(`Room ${view.room.code} · ${view.room.id}`);
|
|
58
|
-
console.log(`You are ${view.participantId} · sequence ${view.sequence} · expires ${view.room.expiresAt}\n`);
|
|
59
|
-
printMembers(view);
|
|
60
|
-
}
|
|
61
|
-
const formatEvent = (event) => `#${event.sequence} ${event.type} from ${event.self ? "you" : short(event.sender.participantId)} ${JSON.stringify(event.data)}`;
|
|
62
|
-
function printEvents(roomId, page, options) {
|
|
63
|
-
if (page.truncated)
|
|
64
|
-
console.log("Some earlier events are no longer in the room history.");
|
|
65
|
-
if (page.events.length === 0)
|
|
66
|
-
console.log("No new events.");
|
|
67
|
-
for (const event of page.events)
|
|
68
|
-
console.log(formatEvent(event));
|
|
69
|
-
const filter = options.types.map((type) => ` --type '${type}'`).join("");
|
|
70
|
-
const wait = options.wait ? ` --wait ${options.wait}` : "";
|
|
71
|
-
console.log(`\nNext: cohub rooms events ${roomId} --after ${page.cursor}${filter}${wait}`);
|
|
72
|
-
}
|
|
73
|
-
const collect = (value, previous = []) => [...previous, value];
|
|
74
|
-
async function withClient(run) {
|
|
75
|
-
try {
|
|
76
|
-
return await run(createClient());
|
|
77
|
-
}
|
|
78
|
-
catch (e) {
|
|
79
|
-
return handleHttp(e);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
export function registerRooms(program) {
|
|
83
|
-
const rooms = program
|
|
84
|
-
.command("rooms")
|
|
85
|
-
.description("Take part in App rooms: join, read and publish events, set presence")
|
|
86
|
-
.addHelpText("after", `
|
|
87
|
-
A room belongs to a published App. Join one with an invite from the App
|
|
88
|
-
(room.invite()), or create one for an App you manage. Your seat stays while
|
|
89
|
-
you use it and lapses after --idle without a call.
|
|
90
|
-
|
|
91
|
-
An Agent waits for the room in a background command and wakes when it returns:
|
|
92
|
-
cohub rooms join <invite> --presence '{"name":"Guide"}'
|
|
93
|
-
cohub rooms events <room> --type 'chat.*' --wait 10m
|
|
94
|
-
cohub rooms publish <room> chat.message '{"text":"Hello"}'
|
|
95
|
-
`);
|
|
96
|
-
rooms
|
|
97
|
-
.command("create")
|
|
98
|
-
.description("Create a room for an App you manage, with an invite and a link to it")
|
|
99
|
-
.requiredOption("--app <app>", "App: ID, URL, or username/space/app")
|
|
100
|
-
.option("--code <code>", "Room code people type or open with ?room=")
|
|
101
|
-
.option("--ttl <duration>", "Room lifetime, 1m to 24h (default 2h)")
|
|
102
|
-
.option("--max <count>", "Most members at once, 2 to 128 (default 16)")
|
|
103
|
-
.option("--seat-per-user", "Give each person one App seat across tabs")
|
|
104
|
-
.option("--json", "Output as JSON")
|
|
105
|
-
.action((opts) => withClient(async (client) => {
|
|
106
|
-
const app = await getAppByRef(client, opts.app);
|
|
107
|
-
const created = await client.rooms.create({
|
|
108
|
-
appId: app.app.id,
|
|
109
|
-
...(opts.code ? { code: opts.code } : {}),
|
|
110
|
-
...(opts.ttl ? { expiresInSeconds: seconds("ttl", opts.ttl, [MINUTE, DAY]) } : {}),
|
|
111
|
-
...(opts.max ? { maxParticipants: Number(opts.max) } : {}),
|
|
112
|
-
...(opts.seatPerUser ? { seatPerUser: true } : {}),
|
|
113
|
-
});
|
|
114
|
-
if (jsonRequested(opts))
|
|
115
|
-
return outJson(created);
|
|
116
|
-
console.log(`Room ${created.room.code} · ${created.room.id}`);
|
|
117
|
-
if (created.url)
|
|
118
|
-
console.log(`Open: ${created.url}`);
|
|
119
|
-
console.log(`Invite (until ${created.expiresAt}):\n${created.invite}\n`);
|
|
120
|
-
console.log(`Join: cohub rooms join <invite>`);
|
|
121
|
-
}));
|
|
122
|
-
rooms
|
|
123
|
-
.command("join <invite>")
|
|
124
|
-
.description("Take a seat in a room with an invite")
|
|
125
|
-
.option("--presence <json>", "What others see about you, e.g. '{\"name\":\"Guide\"}'")
|
|
126
|
-
.option("--idle <duration>", "Leave after this long without a call, 1m to 24h (default 30m)")
|
|
127
|
-
.option("--json", "Output as JSON")
|
|
128
|
-
.action((invite, opts) => withClient(async (client) => {
|
|
129
|
-
const view = await client.rooms.join({
|
|
130
|
-
invite,
|
|
131
|
-
...(opts.presence !== undefined ? { presence: parsePresence(opts.presence) } : {}),
|
|
132
|
-
...(opts.idle ? { idleSeconds: seconds("idle", opts.idle, [MINUTE, DAY]) } : {}),
|
|
133
|
-
});
|
|
134
|
-
if (jsonRequested(opts))
|
|
135
|
-
return outJson(view);
|
|
136
|
-
printView(view);
|
|
137
|
-
console.log(`\nWait for events: cohub rooms events ${view.room.id} --after ${view.sequence} --wait 10m`);
|
|
138
|
-
}));
|
|
139
|
-
rooms
|
|
140
|
-
.command("connect <room>")
|
|
141
|
-
.description("Stream room events and members over realtime; disconnecting keeps your seat")
|
|
142
|
-
.option("--after <sequence>", "Replay retained events after this sequence")
|
|
143
|
-
.option("--input", "Accept NDJSON publish/send/presence commands on stdin")
|
|
144
|
-
.option("--json", "Output newline-delimited JSON")
|
|
145
|
-
.action(async (roomId, opts) => {
|
|
146
|
-
try {
|
|
147
|
-
const { connectToRoom } = await import("./rooms-connect.js");
|
|
148
|
-
await connectToRoom(roomId, { ...opts, json: jsonRequested(opts) });
|
|
149
|
-
}
|
|
150
|
-
catch (cause) {
|
|
151
|
-
handleHttp(cause);
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
rooms
|
|
155
|
-
.command("rtc <room>")
|
|
156
|
-
.description("Stream RTC media and data through the Go/Pion helper")
|
|
157
|
-
.option("--helper <path>", "Use a local cohub-rtc binary")
|
|
158
|
-
.option("--channel <name>", "Open a JSON/binary RTC data channel")
|
|
159
|
-
.option("--delivery <policy>", "Data channel delivery: reliable or latest", "reliable")
|
|
160
|
-
.option("--data-input <path>", "NDJSON channel input file or - for stdin")
|
|
161
|
-
.option("--audio <path>", "Audio input file or - for stdin")
|
|
162
|
-
.option("--audio-format <format>", "Audio input: pcm or opus (Ogg)", "pcm")
|
|
163
|
-
.option("--rate <hz>", "Audio sample rate", "48000")
|
|
164
|
-
.option("--channels <count>", "Audio channels", "1")
|
|
165
|
-
.option("--video <path>", "Video input file or - for stdin")
|
|
166
|
-
.option("--video-format <format>", "Video input: i420 or vp8 (IVF)", "i420")
|
|
167
|
-
.option("--size <widthxheight>", "Video frame dimensions")
|
|
168
|
-
.option("--fps <rate>", "Video frame rate", "30")
|
|
169
|
-
.option("--output <directory|->", "Receive framed media into unique .rtc files or binary stdout")
|
|
170
|
-
.option("--receive-format <format>", "Receive rtp packets or raw decoded frames", "rtp")
|
|
171
|
-
.option("--receive-size <widthxheight>", "Decoded I420 output dimensions", "640x360")
|
|
172
|
-
.option("--max-bytes <bytes>", "Stop after this many received bytes; 0 is unlimited", "1073741824")
|
|
173
|
-
.option("--participant <id>", "Only receive this participant's tracks")
|
|
174
|
-
.option("--json", "Output newline-delimited JSON")
|
|
175
|
-
.action(async (roomId, opts) => {
|
|
176
|
-
try {
|
|
177
|
-
const { runRoomRtc } = await import("./rooms-rtc.js");
|
|
178
|
-
await runRoomRtc(roomId, opts);
|
|
179
|
-
}
|
|
180
|
-
catch (cause) {
|
|
181
|
-
handleHttp(cause);
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
rooms
|
|
185
|
-
.command("get <room>")
|
|
186
|
-
.description("Show the room, its members and your seat")
|
|
187
|
-
.option("--json", "Output as JSON")
|
|
188
|
-
.action((roomId, opts) => withClient(async (client) => {
|
|
189
|
-
const view = await client.rooms.get(roomId);
|
|
190
|
-
if (jsonRequested(opts))
|
|
191
|
-
return outJson(view);
|
|
192
|
-
printView(view);
|
|
193
|
-
}));
|
|
194
|
-
rooms
|
|
195
|
-
.command("events <room>")
|
|
196
|
-
.description("Read published events, oldest first; --wait holds until someone else publishes")
|
|
197
|
-
.option("--after <sequence>", "Only events after this sequence")
|
|
198
|
-
.option("--type <pattern>", "Event type to include, * matches any text; repeatable", collect)
|
|
199
|
-
.option("--wait <duration>", "Wait up to this long for a new event from someone else")
|
|
200
|
-
.option("--follow", "Keep printing events as they arrive")
|
|
201
|
-
.option("--limit <count>", "Most events to return")
|
|
202
|
-
.option("--json", "Output as JSON")
|
|
203
|
-
.action((roomId, opts) => withClient(async (client) => {
|
|
204
|
-
const types = opts.type ?? [];
|
|
205
|
-
const after = opts.after === undefined ? undefined : Number(opts.after);
|
|
206
|
-
if (after !== undefined && (!Number.isInteger(after) || after < 0))
|
|
207
|
-
return error("Invalid --after", "Use a sequence number.");
|
|
208
|
-
const limit = opts.limit === undefined ? undefined : Number(opts.limit);
|
|
209
|
-
if (opts.follow)
|
|
210
|
-
return follow(client, roomId, { after, types, json: jsonRequested(opts) });
|
|
211
|
-
const page = await client.rooms.events(roomId, {
|
|
212
|
-
after,
|
|
213
|
-
types,
|
|
214
|
-
...(limit ? { limit } : {}),
|
|
215
|
-
...(opts.wait ? { waitMs: parseDuration("wait", opts.wait) } : {}),
|
|
216
|
-
});
|
|
217
|
-
if (jsonRequested(opts))
|
|
218
|
-
return outJson(page);
|
|
219
|
-
printEvents(roomId, page, { types, wait: opts.wait });
|
|
220
|
-
}));
|
|
221
|
-
rooms
|
|
222
|
-
.command("publish <room> <type> [data]")
|
|
223
|
-
.description("Publish an event to everyone in the room; data is JSON, or - for stdin")
|
|
224
|
-
.option("--json", "Output as JSON")
|
|
225
|
-
.action((roomId, type, data, opts) => withClient(async (client) => {
|
|
226
|
-
const payload = data === undefined ? null : parseJson("data", data === "-" ? await readStdin() : data);
|
|
227
|
-
const result = await client.rooms.publish(roomId, type, payload);
|
|
228
|
-
if (jsonRequested(opts))
|
|
229
|
-
return outJson(result);
|
|
230
|
-
ok(`Published #${result.sequence} ${type}`);
|
|
231
|
-
}));
|
|
232
|
-
rooms
|
|
233
|
-
.command("presence <room> <json>")
|
|
234
|
-
.description("Set what others see about you; null clears it")
|
|
235
|
-
.option("--json", "Output as JSON")
|
|
236
|
-
.action((roomId, value, opts) => withClient(async (client) => {
|
|
237
|
-
const result = await client.rooms.setPresence(roomId, parsePresence(value));
|
|
238
|
-
if (jsonRequested(opts))
|
|
239
|
-
return outJson(result);
|
|
240
|
-
ok("Presence updated");
|
|
241
|
-
}));
|
|
242
|
-
rooms
|
|
243
|
-
.command("invite <room>")
|
|
244
|
-
.description("Create an invite to a room you are in")
|
|
245
|
-
.option("--ttl <duration>", "How long the invite admits people (default 10m)")
|
|
246
|
-
.option("--json", "Output as JSON")
|
|
247
|
-
.action((roomId, opts) => withClient(async (client) => {
|
|
248
|
-
const invite = await client.rooms.invite(roomId, opts.ttl ? { expiresInSeconds: seconds("ttl", opts.ttl, [MINUTE, DAY]) } : {});
|
|
249
|
-
if (jsonRequested(opts))
|
|
250
|
-
return outJson(invite);
|
|
251
|
-
console.log(`Invite (until ${invite.expiresAt}):\n${invite.invite}`);
|
|
252
|
-
}));
|
|
253
|
-
rooms
|
|
254
|
-
.command("leave <room>")
|
|
255
|
-
.description("Give up your seat")
|
|
256
|
-
.option("--json", "Output as JSON")
|
|
257
|
-
.action((roomId, opts) => withClient(async (client) => {
|
|
258
|
-
const result = await client.rooms.leave(roomId);
|
|
259
|
-
if (jsonRequested(opts))
|
|
260
|
-
return outJson(result);
|
|
261
|
-
ok(result.left ? "Left the room" : "You were not in this room");
|
|
262
|
-
}));
|
|
263
|
-
}
|
|
264
|
-
async function follow(client, roomId, input) {
|
|
265
|
-
const controller = new AbortController();
|
|
266
|
-
process.once("SIGINT", () => controller.abort());
|
|
267
|
-
let after = input.after ?? (await client.rooms.get(roomId)).sequence;
|
|
268
|
-
while (!controller.signal.aborted) {
|
|
269
|
-
const page = await client.rooms.events(roomId, { after, types: input.types, waitMs: 25_000, signal: controller.signal })
|
|
270
|
-
.catch((e) => (controller.signal.aborted ? null : Promise.reject(e)));
|
|
271
|
-
if (!page)
|
|
272
|
-
break;
|
|
273
|
-
for (const event of page.events)
|
|
274
|
-
console.log(input.json ? JSON.stringify(event) : formatEvent(event));
|
|
275
|
-
after = page.cursor;
|
|
276
|
-
}
|
|
277
|
-
}
|
package/dist/commands/run.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
type RunCliOptions = {
|
|
2
|
-
spaceId: string;
|
|
3
|
-
json: boolean;
|
|
4
|
-
async: boolean;
|
|
5
|
-
command: string;
|
|
6
|
-
};
|
|
7
|
-
export declare function parseRunCliOptions(argv: string[], spaceOptions?: {
|
|
8
|
-
cwd?: string;
|
|
9
|
-
bindingsPath?: string;
|
|
10
|
-
}): Promise<RunCliOptions>;
|
|
11
|
-
export declare function printRunHelp(): void;
|
|
12
|
-
export declare function maybeHandleRunCommand(argv: string[]): Promise<boolean>;
|
|
13
|
-
export {};
|
package/dist/commands/run.js
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import { consumeBaseUrlOption } from "../endpoint-options.js";
|
|
2
|
-
import { createClient } from "../client.js";
|
|
3
|
-
import { error, handleHttp, json as outJson, spinner } from "../output.js";
|
|
4
|
-
import { resolveSpaceTarget } from "../space.js";
|
|
5
|
-
const DEFAULT_WAIT_TIMEOUT_MS = (6 * 60 * 60 + 60) * 1000;
|
|
6
|
-
const DEFAULT_POLL_INTERVAL_MS = 1500;
|
|
7
|
-
function shellQuote(value) {
|
|
8
|
-
if (value.length === 0)
|
|
9
|
-
return "''";
|
|
10
|
-
if (/^[A-Za-z0-9_@%+=:,./-]+$/.test(value))
|
|
11
|
-
return value;
|
|
12
|
-
return `'${value.replaceAll("'", `'"'"'`)}'`;
|
|
13
|
-
}
|
|
14
|
-
function shellJoin(values) {
|
|
15
|
-
return values.map((value) => shellQuote(value)).join(" ");
|
|
16
|
-
}
|
|
17
|
-
function topLevelRunIndex(argv) {
|
|
18
|
-
for (let index = 0; index < argv.length; index += 1) {
|
|
19
|
-
const token = argv[index] ?? "";
|
|
20
|
-
if (token === "--")
|
|
21
|
-
return -1;
|
|
22
|
-
if (token === "-s" || token === "--space" || token === "--base-url") {
|
|
23
|
-
index += 1;
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
if (token.startsWith("--space=") || token === "--json")
|
|
27
|
-
continue;
|
|
28
|
-
if (token.startsWith("-"))
|
|
29
|
-
continue;
|
|
30
|
-
return token === "run" ? index : -1;
|
|
31
|
-
}
|
|
32
|
-
return -1;
|
|
33
|
-
}
|
|
34
|
-
function parseSpaceId(tokens) {
|
|
35
|
-
for (let index = 0; index < tokens.length; index += 1) {
|
|
36
|
-
const token = tokens[index] ?? "";
|
|
37
|
-
if (token === "-s" || token === "--space") {
|
|
38
|
-
const value = tokens[index + 1];
|
|
39
|
-
if (!value)
|
|
40
|
-
return error("Missing space", `${token} requires a value`);
|
|
41
|
-
return value.trim() || undefined;
|
|
42
|
-
}
|
|
43
|
-
if (token.startsWith("--space="))
|
|
44
|
-
return token.slice("--space=".length).trim() || undefined;
|
|
45
|
-
}
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
export async function parseRunCliOptions(argv, spaceOptions = {}) {
|
|
49
|
-
const runIndex = topLevelRunIndex(argv);
|
|
50
|
-
if (runIndex < 0)
|
|
51
|
-
return error("Invalid invocation", "Use `cohub run [options] <command>`");
|
|
52
|
-
const beforeRun = argv.slice(0, runIndex);
|
|
53
|
-
const afterRun = argv.slice(runIndex + 1);
|
|
54
|
-
for (let index = 0; index < beforeRun.length; index += 1) {
|
|
55
|
-
index = consumeBaseUrlOption(beforeRun, index) ?? index;
|
|
56
|
-
if (beforeRun[index] === "-s" || beforeRun[index] === "--space")
|
|
57
|
-
index += 1;
|
|
58
|
-
}
|
|
59
|
-
const explicitSpaceId = parseSpaceId(beforeRun) ?? process.env.COHUB_SPACE_ID?.trim() ?? "";
|
|
60
|
-
let json = beforeRun.includes("--json");
|
|
61
|
-
let async = false;
|
|
62
|
-
let commandOption = null;
|
|
63
|
-
let positionalTokens = [];
|
|
64
|
-
for (let index = 0; index < afterRun.length; index += 1) {
|
|
65
|
-
const token = afterRun[index] ?? "";
|
|
66
|
-
const endpointIndex = consumeBaseUrlOption(afterRun, index);
|
|
67
|
-
if (endpointIndex !== null) {
|
|
68
|
-
index = endpointIndex;
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
if (token === "-h" || token === "--help") {
|
|
72
|
-
printRunHelp();
|
|
73
|
-
process.exit(0);
|
|
74
|
-
}
|
|
75
|
-
if (token === "--async") {
|
|
76
|
-
async = true;
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
if (token === "--json") {
|
|
80
|
-
json = true;
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
if (token === "-c" || token === "--command") {
|
|
84
|
-
const value = afterRun[index + 1];
|
|
85
|
-
if (!value)
|
|
86
|
-
return error("Missing command", `${token} requires a value`);
|
|
87
|
-
if (commandOption !== null || positionalTokens.length > 0) {
|
|
88
|
-
return error("Conflicting command input", "Use either --command or positional command tokens, not both.");
|
|
89
|
-
}
|
|
90
|
-
commandOption = value;
|
|
91
|
-
index += 1;
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
if (token.startsWith("--command=")) {
|
|
95
|
-
if (commandOption !== null || positionalTokens.length > 0) {
|
|
96
|
-
return error("Conflicting command input", "Use either --command or positional command tokens, not both.");
|
|
97
|
-
}
|
|
98
|
-
commandOption = token.slice("--command=".length);
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
if (token === "--") {
|
|
102
|
-
if (commandOption !== null) {
|
|
103
|
-
return error("Conflicting command input", "Use either --command or positional command tokens, not both.");
|
|
104
|
-
}
|
|
105
|
-
positionalTokens = afterRun.slice(index + 1);
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
if (commandOption !== null) {
|
|
109
|
-
return error("Conflicting command input", "Use either --command or positional command tokens, not both.");
|
|
110
|
-
}
|
|
111
|
-
positionalTokens = afterRun.slice(index);
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
const command = commandOption?.trim() || shellJoin(positionalTokens).trim();
|
|
115
|
-
if (!command) {
|
|
116
|
-
return error("No command", "Pass --command <shell command>, or use `--` followed by the command.");
|
|
117
|
-
}
|
|
118
|
-
const spaceId = await resolveSpaceTarget(explicitSpaceId, spaceOptions);
|
|
119
|
-
return { spaceId, json, async, command };
|
|
120
|
-
}
|
|
121
|
-
export function printRunHelp() {
|
|
122
|
-
process.stdout.write(`
|
|
123
|
-
Usage:
|
|
124
|
-
cohub [--base-url <url>] [-s <space>] run [options] -- <shell command>
|
|
125
|
-
cohub [-s <space>] run --command <shell command>
|
|
126
|
-
|
|
127
|
-
Options:
|
|
128
|
-
--base-url <url> API base URL (overrides COHUB_BASE_URL)
|
|
129
|
-
-c, --command <command> Shell command to execute in the space workspace
|
|
130
|
-
--async Queue the command and return immediately
|
|
131
|
-
--json Output as JSON
|
|
132
|
-
-h, --help Show this help
|
|
133
|
-
|
|
134
|
-
Examples:
|
|
135
|
-
cohub -s <spaceId> run --command "git status"
|
|
136
|
-
cohub -s <spaceId> run --async --command "pnpm test"
|
|
137
|
-
cohub -s <spaceId> run -- git status -sb
|
|
138
|
-
|
|
139
|
-
Notes:
|
|
140
|
-
- Without -s or COHUB_SPACE_ID, the command uses the current directory Runtime binding; it never falls back to Home.
|
|
141
|
-
- Use --command for commands that contain leading flags, or use -- before the shell command.
|
|
142
|
-
- The command runs in /workspace.
|
|
143
|
-
`);
|
|
144
|
-
}
|
|
145
|
-
function sleep(ms) {
|
|
146
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
147
|
-
}
|
|
148
|
-
function formatElapsed(ms) {
|
|
149
|
-
if (ms < 1000)
|
|
150
|
-
return `${ms}ms`;
|
|
151
|
-
const seconds = Math.floor(ms / 1000);
|
|
152
|
-
if (seconds < 60)
|
|
153
|
-
return `${seconds}s`;
|
|
154
|
-
const minutes = Math.floor(seconds / 60);
|
|
155
|
-
const restSeconds = seconds % 60;
|
|
156
|
-
if (minutes < 60)
|
|
157
|
-
return restSeconds > 0 ? `${minutes}m ${restSeconds}s` : `${minutes}m`;
|
|
158
|
-
const hours = Math.floor(minutes / 60);
|
|
159
|
-
const restMinutes = minutes % 60;
|
|
160
|
-
return restMinutes > 0 ? `${hours}h ${restMinutes}m` : `${hours}h`;
|
|
161
|
-
}
|
|
162
|
-
function asRecord(value) {
|
|
163
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
164
|
-
}
|
|
165
|
-
function parseRunResult(detail) {
|
|
166
|
-
const result = asRecord(detail.run.result);
|
|
167
|
-
const terminationRecord = asRecord(result?.termination);
|
|
168
|
-
return {
|
|
169
|
-
exitCode: typeof result?.exitCode === "number" ? result.exitCode : null,
|
|
170
|
-
termination: terminationRecord && (terminationRecord.reason === "exited" || terminationRecord.reason === "timed_out" || terminationRecord.reason === "aborted")
|
|
171
|
-
? {
|
|
172
|
-
reason: terminationRecord.reason,
|
|
173
|
-
exitCode: typeof terminationRecord.exitCode === "number" ? terminationRecord.exitCode : null,
|
|
174
|
-
...(typeof terminationRecord.timeoutSecs === "number" ? { timeoutSecs: terminationRecord.timeoutSecs } : {}),
|
|
175
|
-
...(typeof terminationRecord.message === "string" ? { message: terminationRecord.message } : {}),
|
|
176
|
-
...(typeof terminationRecord.outputTruncated === "boolean" ? { outputTruncated: terminationRecord.outputTruncated } : {}),
|
|
177
|
-
}
|
|
178
|
-
: undefined,
|
|
179
|
-
durationMs: typeof result?.durationMs === "number" ? result.durationMs : 0,
|
|
180
|
-
output: typeof result?.output === "string" ? result.output : "",
|
|
181
|
-
truncated: Boolean(result?.truncated) || Boolean(result?.outputTruncated) || Boolean(terminationRecord?.outputTruncated),
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
function writeOutput(output) {
|
|
185
|
-
if (!output)
|
|
186
|
-
return;
|
|
187
|
-
process.stdout.write(output.endsWith("\n") ? output : `${output}\n`);
|
|
188
|
-
}
|
|
189
|
-
async function waitForRunCompletion(taskRunId, showSpinner) {
|
|
190
|
-
const client = createClient();
|
|
191
|
-
const startedAt = Date.now();
|
|
192
|
-
const spin = showSpinner ? spinner() : null;
|
|
193
|
-
if (spin)
|
|
194
|
-
spin.start(`Waiting for command task ${taskRunId}`);
|
|
195
|
-
while (true) {
|
|
196
|
-
const detail = await client.tasks.get(taskRunId);
|
|
197
|
-
if (detail.run.status === "completed" || detail.run.status === "failed") {
|
|
198
|
-
if (spin)
|
|
199
|
-
spin.stop(`Finished in ${formatElapsed(Date.now() - startedAt)}`);
|
|
200
|
-
return detail;
|
|
201
|
-
}
|
|
202
|
-
const elapsedMs = Date.now() - startedAt;
|
|
203
|
-
if (elapsedMs > DEFAULT_WAIT_TIMEOUT_MS) {
|
|
204
|
-
if (spin)
|
|
205
|
-
spin.stop(`Timed out after ${formatElapsed(DEFAULT_WAIT_TIMEOUT_MS)}`);
|
|
206
|
-
return error("Timed out waiting for run command", `taskRunId: ${taskRunId}`);
|
|
207
|
-
}
|
|
208
|
-
if (spin)
|
|
209
|
-
spin.update(`Running... ${formatElapsed(elapsedMs)}`);
|
|
210
|
-
await sleep(DEFAULT_POLL_INTERVAL_MS);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
async function handleRunCli(argv) {
|
|
214
|
-
const opts = await parseRunCliOptions(argv);
|
|
215
|
-
const client = createClient();
|
|
216
|
-
try {
|
|
217
|
-
const { taskRunId } = await client.space(opts.spaceId).runCommand({ command: opts.command });
|
|
218
|
-
if (opts.async) {
|
|
219
|
-
if (opts.json)
|
|
220
|
-
return outJson({ taskRunId });
|
|
221
|
-
process.stderr.write(` Command queued — taskRunId: ${taskRunId}\n`);
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
const detail = await waitForRunCompletion(taskRunId, !opts.json);
|
|
225
|
-
if (detail.run.status === "failed") {
|
|
226
|
-
const message = detail.run.errorMessage?.trim() || `Command task failed: ${taskRunId}`;
|
|
227
|
-
return error(message);
|
|
228
|
-
}
|
|
229
|
-
const result = parseRunResult(detail);
|
|
230
|
-
if (opts.json) {
|
|
231
|
-
return outJson({ taskRunId, run: detail.run, progress: detail.progress, ...result });
|
|
232
|
-
}
|
|
233
|
-
writeOutput(result.output);
|
|
234
|
-
process.exitCode = result.exitCode ?? 0;
|
|
235
|
-
process.stderr.write(` Command finished — taskRunId: ${taskRunId}, exitCode: ${result.exitCode ?? "unknown"}, duration: ${formatElapsed(result.durationMs)}${result.truncated ? ", output truncated" : ""}\n`);
|
|
236
|
-
}
|
|
237
|
-
catch (e) {
|
|
238
|
-
handleHttp(e);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
export async function maybeHandleRunCommand(argv) {
|
|
242
|
-
if (topLevelRunIndex(argv) < 0)
|
|
243
|
-
return false;
|
|
244
|
-
await handleRunCli(argv);
|
|
245
|
-
return true;
|
|
246
|
-
}
|