@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,215 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { once } from "node:events";
|
|
3
|
-
import { dirname, posix } from "node:path";
|
|
4
|
-
import { Option } from "commander";
|
|
5
|
-
import { createClient } from "../client.js";
|
|
6
|
-
import { error, json as outJson, jsonRequested, ok } from "../output.js";
|
|
7
|
-
import { explicitSpace, failSpaceTarget, resolveSpace, resolveSpaceRef } from "../space.js";
|
|
8
|
-
import { InvalidFileOperandError, parseCopyOperand, parseSpaceFileOperand, } from "../space-files/operands.js";
|
|
9
|
-
import { checkDestination, copyLocal, CopyAbortError, downloadFromSpace, localNodeType, mergeCopyResults, spaceNodeType, uploadToSpace, } from "../space-files/transfer.js";
|
|
10
|
-
function fail(e) {
|
|
11
|
-
if (e instanceof InvalidFileOperandError || e instanceof CopyAbortError)
|
|
12
|
-
return error(e.message);
|
|
13
|
-
return failSpaceTarget(e);
|
|
14
|
-
}
|
|
15
|
-
const operandSpaceResolver = (spacesCmd) => (space) => space ? resolveSpaceRef(space) : resolveSpace(spacesCmd);
|
|
16
|
-
export function formatBytes(bytes) {
|
|
17
|
-
const units = ["B", "KB", "MB", "GB", "TB"];
|
|
18
|
-
let value = bytes;
|
|
19
|
-
let unit = 0;
|
|
20
|
-
while (value >= 1024 && unit < units.length - 1) {
|
|
21
|
-
value /= 1024;
|
|
22
|
-
unit += 1;
|
|
23
|
-
}
|
|
24
|
-
return unit === 0 ? `${value} B` : `${value.toFixed(value < 10 ? 1 : 0)} ${units[unit]}`;
|
|
25
|
-
}
|
|
26
|
-
const count = (value, singular, plural = `${singular}s`) => `${value} ${value === 1 ? singular : plural}`;
|
|
27
|
-
export function formatCopySummary(result) {
|
|
28
|
-
const parts = [count(result.files, "file")];
|
|
29
|
-
if (result.dirs)
|
|
30
|
-
parts.push(count(result.dirs, "directory", "directories"));
|
|
31
|
-
if (result.symlinks)
|
|
32
|
-
parts.push(count(result.symlinks, "symlink"));
|
|
33
|
-
let summary = `${parts.join(", ")} (${formatBytes(result.bytes)})`;
|
|
34
|
-
if (result.overwritten)
|
|
35
|
-
summary += `, ${result.overwritten} overwritten`;
|
|
36
|
-
if (result.skipped)
|
|
37
|
-
summary += `, ${result.skipped} skipped`;
|
|
38
|
-
return summary;
|
|
39
|
-
}
|
|
40
|
-
function createProgressLine() {
|
|
41
|
-
if (!process.stderr.isTTY)
|
|
42
|
-
return { update: () => undefined, clear: () => undefined };
|
|
43
|
-
let shown = false;
|
|
44
|
-
return {
|
|
45
|
-
update: (progress) => {
|
|
46
|
-
shown = true;
|
|
47
|
-
process.stderr.write(`\r\x1b[2K Copying… ${count(progress.files, "file")} (${formatBytes(progress.bytes)})`);
|
|
48
|
-
},
|
|
49
|
-
clear: () => {
|
|
50
|
-
if (shown)
|
|
51
|
-
process.stderr.write("\r\x1b[2K");
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
const spaceParent = (path) => (posix.dirname(path) === "." ? "" : posix.dirname(path));
|
|
56
|
-
async function copyFiles(spacesCmd, raw, opts) {
|
|
57
|
-
if (raw.length < 2)
|
|
58
|
-
return error("missing destination operand", "Usage: cohub spaces files cp [-r] <source>... <destination>");
|
|
59
|
-
const client = createClient();
|
|
60
|
-
const resolveSpaceId = operandSpaceResolver(spacesCmd);
|
|
61
|
-
const progress = createProgressLine();
|
|
62
|
-
const options = {
|
|
63
|
-
recursive: Boolean(opts.recursive || opts.R),
|
|
64
|
-
noClobber: opts.clobber === false,
|
|
65
|
-
preserveTimestamps: Boolean(opts.preserve),
|
|
66
|
-
};
|
|
67
|
-
try {
|
|
68
|
-
const declared = explicitSpace(spacesCmd) !== null;
|
|
69
|
-
const operands = raw.map((value) => parseCopyOperand(value, declared));
|
|
70
|
-
const destination = operands.pop();
|
|
71
|
-
const display = raw.at(-1);
|
|
72
|
-
const spaceSources = operands.filter((operand) => operand.kind === "space");
|
|
73
|
-
const localSources = operands.filter((operand) => operand.kind === "local").map((operand) => operand.path);
|
|
74
|
-
const results = [];
|
|
75
|
-
if (destination.kind === "space") {
|
|
76
|
-
const files = client.space(await resolveSpaceId(destination.space)).files;
|
|
77
|
-
const intoDirectory = await checkDestination({
|
|
78
|
-
sourceCount: operands.length,
|
|
79
|
-
display,
|
|
80
|
-
path: destination.path,
|
|
81
|
-
parent: spaceParent(destination.path),
|
|
82
|
-
stat: (path) => spaceNodeType(files, path),
|
|
83
|
-
});
|
|
84
|
-
if (spaceSources.length > 0) {
|
|
85
|
-
const started = await files.copy({
|
|
86
|
-
sources: await Promise.all(spaceSources.map(async (source) => ({ spaceId: await resolveSpaceId(source.space), path: source.path }))),
|
|
87
|
-
destination: destination.path,
|
|
88
|
-
...options,
|
|
89
|
-
mutationId: randomUUID(),
|
|
90
|
-
});
|
|
91
|
-
results.push(await files.waitForCopy(started, { pollMs: process.stderr.isTTY ? 2_000 : 10_000, onProgress: progress.update }));
|
|
92
|
-
}
|
|
93
|
-
if (localSources.length > 0) {
|
|
94
|
-
results.push(await uploadToSpace({ files, sources: localSources, destination: destination.path, intoDirectory, options, onProgress: progress.update }));
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
const intoDirectory = await checkDestination({
|
|
99
|
-
sourceCount: operands.length,
|
|
100
|
-
display,
|
|
101
|
-
path: destination.path,
|
|
102
|
-
parent: dirname(destination.path),
|
|
103
|
-
stat: localNodeType,
|
|
104
|
-
});
|
|
105
|
-
if (spaceSources.length > 0) {
|
|
106
|
-
const sources = await Promise.all(spaceSources.map(async (source) => ({
|
|
107
|
-
files: client.space(await resolveSpaceId(source.space)).files,
|
|
108
|
-
path: source.path,
|
|
109
|
-
})));
|
|
110
|
-
results.push(await downloadFromSpace({ sources, destination: destination.path, intoDirectory, options, onProgress: progress.update }));
|
|
111
|
-
}
|
|
112
|
-
if (localSources.length > 0) {
|
|
113
|
-
results.push(await copyLocal({ sources: localSources, destination: destination.path, intoDirectory, options }));
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
progress.clear();
|
|
117
|
-
const result = mergeCopyResults(results);
|
|
118
|
-
if (jsonRequested(opts)) {
|
|
119
|
-
outJson(result);
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
for (const failure of result.errors)
|
|
123
|
-
process.stderr.write(`cp: ${failure.message}\n`);
|
|
124
|
-
if (result.errors.length === 0 || result.files + result.dirs + result.symlinks > 0)
|
|
125
|
-
ok(`Copied ${formatCopySummary(result)}`);
|
|
126
|
-
}
|
|
127
|
-
if (result.errors.length > 0)
|
|
128
|
-
process.exit(1);
|
|
129
|
-
}
|
|
130
|
-
catch (e) {
|
|
131
|
-
progress.clear();
|
|
132
|
-
fail(e);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
async function writeFileBody(response, path) {
|
|
136
|
-
const reader = response.body?.getReader();
|
|
137
|
-
if (!reader)
|
|
138
|
-
return;
|
|
139
|
-
let first = true;
|
|
140
|
-
while (true) {
|
|
141
|
-
const { done, value } = await reader.read();
|
|
142
|
-
if (done)
|
|
143
|
-
return;
|
|
144
|
-
if (first && process.stdout.isTTY && value.includes(0)) {
|
|
145
|
-
await reader.cancel();
|
|
146
|
-
return error(`'${path}' is a binary file`, `Redirect it to a file: cohub spaces files cat ${path} > <file>`);
|
|
147
|
-
}
|
|
148
|
-
first = false;
|
|
149
|
-
if (!process.stdout.write(value))
|
|
150
|
-
await once(process.stdout, "drain");
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
async function catFiles(spacesCmd, paths, opts) {
|
|
154
|
-
process.stdout.on("error", (e) => {
|
|
155
|
-
if (e.code === "EPIPE")
|
|
156
|
-
process.exit(0);
|
|
157
|
-
error(e.message);
|
|
158
|
-
});
|
|
159
|
-
const client = createClient();
|
|
160
|
-
const resolveSpaceId = operandSpaceResolver(spacesCmd);
|
|
161
|
-
try {
|
|
162
|
-
const operands = paths.map(parseSpaceFileOperand);
|
|
163
|
-
if (jsonRequested(opts)) {
|
|
164
|
-
const files = await Promise.all(operands.map(async (operand) => client.space(await resolveSpaceId(operand.space)).files.read(operand.path)));
|
|
165
|
-
return outJson(files.length === 1 ? files[0] : files);
|
|
166
|
-
}
|
|
167
|
-
for (const operand of operands) {
|
|
168
|
-
const file = await client.space(await resolveSpaceId(operand.space)).files.open(operand.path);
|
|
169
|
-
await writeFileBody(file.response, operand.path);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
catch (e) {
|
|
173
|
-
fail(e);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
export function registerSpaceFileTransfer(filesCmd, spacesCmd) {
|
|
177
|
-
filesCmd
|
|
178
|
-
.command("cat <paths...>")
|
|
179
|
-
.description("Print file contents; binary-safe when redirected")
|
|
180
|
-
.option("--json", "Output file metadata and content as JSON")
|
|
181
|
-
.addHelpText("after", `
|
|
182
|
-
Paths may name another Space as <space>:<path>, where <space> is an id,
|
|
183
|
-
username/slug, or the slug of a Space you own.
|
|
184
|
-
|
|
185
|
-
Examples:
|
|
186
|
-
cohub spaces files cat README.md
|
|
187
|
-
cohub spaces files cat assets/logo.png > logo.png
|
|
188
|
-
cohub spaces files cat alice/notes:todo.md`)
|
|
189
|
-
.action((paths, opts) => catFiles(spacesCmd, paths, opts));
|
|
190
|
-
filesCmd
|
|
191
|
-
.command("cp <paths...>")
|
|
192
|
-
.description("Copy files between Spaces and the local filesystem, like scp")
|
|
193
|
-
.option("-r, --recursive", "Copy directories recursively")
|
|
194
|
-
.addOption(new Option("-R", "Same as --recursive").hideHelp())
|
|
195
|
-
.option("-n, --no-clobber", "Do not overwrite existing files")
|
|
196
|
-
.option("-p, --preserve", "Preserve modification times (not kept by uploads)")
|
|
197
|
-
.option("--json", "Output the copy result as JSON")
|
|
198
|
-
.addHelpText("after", `
|
|
199
|
-
Works like scp and cp: the last path is the destination, existing files are
|
|
200
|
-
overwritten and directories merged. <space>:<path> addresses a Space, where
|
|
201
|
-
<space> is an id, username/slug, or the slug of a Space you own; write
|
|
202
|
-
./name for a path that contains a colon.
|
|
203
|
-
|
|
204
|
-
Bare paths address the current Space when one is declared with -s or
|
|
205
|
-
COHUB_SPACE_ID, as inside a Cohub sandbox; otherwise they are local files.
|
|
206
|
-
Absolute paths outside /workspace are always local. Copies between Spaces
|
|
207
|
-
run server-side; local files are uploaded or downloaded.
|
|
208
|
-
|
|
209
|
-
Examples:
|
|
210
|
-
cohub spaces files cp -r alice/templates:starter ./starter
|
|
211
|
-
cohub spaces files cp report.pdf notes:inbox/
|
|
212
|
-
cohub -s <spaceId> spaces files cp -r other:docs docs
|
|
213
|
-
cohub spaces files cp /tmp/chart.png <spaceId>:assets/`)
|
|
214
|
-
.action((paths, opts) => copyFiles(spacesCmd, paths, opts));
|
|
215
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { type CreateInvitationInput, type CreateInvitationResponse, type SpaceInvitationListOptions, type SpaceInvitationListResponse } from "@neta-art/cohub";
|
|
2
|
-
import type { Command } from "commander";
|
|
3
|
-
export type SpaceInvitationCreateCliOptions = {
|
|
4
|
-
role?: string;
|
|
5
|
-
days?: string;
|
|
6
|
-
neverExpires?: boolean;
|
|
7
|
-
maxUses?: string;
|
|
8
|
-
json?: boolean;
|
|
9
|
-
};
|
|
10
|
-
type SpaceInvitationCommandClient = {
|
|
11
|
-
space(spaceId: string): {
|
|
12
|
-
invitations: {
|
|
13
|
-
list(options?: SpaceInvitationListOptions): Promise<SpaceInvitationListResponse>;
|
|
14
|
-
create(input: CreateInvitationInput): Promise<CreateInvitationResponse>;
|
|
15
|
-
revoke(token: string): Promise<{
|
|
16
|
-
ok: true;
|
|
17
|
-
}>;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
export declare class InvalidSpaceInvitationCliOptionsError extends Error {
|
|
22
|
-
readonly detail: string;
|
|
23
|
-
constructor(message: string, detail: string);
|
|
24
|
-
}
|
|
25
|
-
export declare function parseSpaceInvitationCreateOptions(options: SpaceInvitationCreateCliOptions): Required<Pick<CreateInvitationInput, "role" | "ttlSeconds" | "maxUses">>;
|
|
26
|
-
export declare function registerSpaceInvitations(spacesCommand: Command, dependencies?: {
|
|
27
|
-
createClient: () => SpaceInvitationCommandClient;
|
|
28
|
-
}): Command;
|
|
29
|
-
export {};
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { buildSpaceInvitePath, } from "@neta-art/cohub";
|
|
2
|
-
import { createClient } from "../client.js";
|
|
3
|
-
import { webUrl } from "../web.js";
|
|
4
|
-
import { error, handleHttp, json as outJson, jsonRequested, ok, table, } from "../output.js";
|
|
5
|
-
import { resolveSpace } from "../space.js";
|
|
6
|
-
const SPACE_ROLES = ["host", "builder", "guest"];
|
|
7
|
-
const DEFAULT_DAYS = 7;
|
|
8
|
-
const MAX_DAYS = 30;
|
|
9
|
-
const MAX_USES = 10_000;
|
|
10
|
-
export class InvalidSpaceInvitationCliOptionsError extends Error {
|
|
11
|
-
detail;
|
|
12
|
-
constructor(message, detail) {
|
|
13
|
-
super(message);
|
|
14
|
-
this.detail = detail;
|
|
15
|
-
this.name = "InvalidSpaceInvitationCliOptionsError";
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function parseInteger(value, label, min, max) {
|
|
19
|
-
if (!/^\d+$/.test(value.trim())) {
|
|
20
|
-
throw new InvalidSpaceInvitationCliOptionsError(`Invalid ${label}`, `${label} must be an integer from ${min} to ${max}`);
|
|
21
|
-
}
|
|
22
|
-
const parsed = Number.parseInt(value, 10);
|
|
23
|
-
if (!Number.isSafeInteger(parsed) || parsed < min || parsed > max) {
|
|
24
|
-
throw new InvalidSpaceInvitationCliOptionsError(`Invalid ${label}`, `${label} must be an integer from ${min} to ${max}`);
|
|
25
|
-
}
|
|
26
|
-
return parsed;
|
|
27
|
-
}
|
|
28
|
-
export function parseSpaceInvitationCreateOptions(options) {
|
|
29
|
-
const role = (options.role ?? "builder");
|
|
30
|
-
if (!SPACE_ROLES.includes(role)) {
|
|
31
|
-
throw new InvalidSpaceInvitationCliOptionsError("Invalid role", `Use one of: ${SPACE_ROLES.join(", ")}`);
|
|
32
|
-
}
|
|
33
|
-
const maxUses = parseInteger(options.maxUses ?? "0", "max uses", 0, MAX_USES);
|
|
34
|
-
if (options.neverExpires) {
|
|
35
|
-
if (options.days !== undefined) {
|
|
36
|
-
throw new InvalidSpaceInvitationCliOptionsError("Conflicting options", "Use either --days or --never-expires");
|
|
37
|
-
}
|
|
38
|
-
if (role === "host") {
|
|
39
|
-
throw new InvalidSpaceInvitationCliOptionsError("Invalid expiry", `Host invite links expire within ${MAX_DAYS} days`);
|
|
40
|
-
}
|
|
41
|
-
return { role, ttlSeconds: null, maxUses };
|
|
42
|
-
}
|
|
43
|
-
const days = parseInteger(options.days ?? String(DEFAULT_DAYS), "days", 1, MAX_DAYS);
|
|
44
|
-
return { role, ttlSeconds: days * 24 * 60 * 60, maxUses };
|
|
45
|
-
}
|
|
46
|
-
const PAGE_SIZE = 100;
|
|
47
|
-
async function listAllInvitations(invitations, status) {
|
|
48
|
-
const items = [];
|
|
49
|
-
let cursor = null;
|
|
50
|
-
let page;
|
|
51
|
-
do {
|
|
52
|
-
page = await invitations.list({ status, limit: PAGE_SIZE, cursor });
|
|
53
|
-
items.push(...page.items);
|
|
54
|
-
cursor = page.pageInfo?.nextCursor ?? null;
|
|
55
|
-
} while (cursor);
|
|
56
|
-
return { ...page, items };
|
|
57
|
-
}
|
|
58
|
-
function invitationUrl(invitation) {
|
|
59
|
-
return webUrl(buildSpaceInvitePath({
|
|
60
|
-
spaceId: invitation.spaceId,
|
|
61
|
-
ownerUsername: invitation.ownerUsername,
|
|
62
|
-
spaceSlug: invitation.spaceSlug,
|
|
63
|
-
inviteCode: invitation.token,
|
|
64
|
-
}));
|
|
65
|
-
}
|
|
66
|
-
async function confirmRevoke(options) {
|
|
67
|
-
if (options.yes)
|
|
68
|
-
return;
|
|
69
|
-
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
70
|
-
return error("Confirmation required", "Pass --yes to revoke the invite link.");
|
|
71
|
-
}
|
|
72
|
-
process.stdout.write("This invite link will stop working. Continue? [y/N] ");
|
|
73
|
-
const chunks = [];
|
|
74
|
-
for await (const chunk of process.stdin) {
|
|
75
|
-
chunks.push(chunk);
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
const answer = Buffer.concat(chunks).toString().trim().toLowerCase();
|
|
79
|
-
if (answer !== "y" && answer !== "yes")
|
|
80
|
-
return error("Cancelled");
|
|
81
|
-
}
|
|
82
|
-
export function registerSpaceInvitations(spacesCommand, dependencies = {
|
|
83
|
-
createClient,
|
|
84
|
-
}) {
|
|
85
|
-
const invitations = spacesCommand
|
|
86
|
-
.command("invites")
|
|
87
|
-
.description("Create and manage space invite links");
|
|
88
|
-
invitations
|
|
89
|
-
.command("create")
|
|
90
|
-
.description("Create an invite link")
|
|
91
|
-
.option("--role <role>", "Member role: host, builder, or guest", "builder")
|
|
92
|
-
.option("--days <days>", `Validity in days, from 1 to ${MAX_DAYS} (default ${DEFAULT_DAYS})`)
|
|
93
|
-
.option("--never-expires", "Keep the link valid until revoked (not for hosts)")
|
|
94
|
-
.option("--max-uses <count>", "Usage limit, or 0 for unlimited", "0")
|
|
95
|
-
.option("--json", "Output as JSON")
|
|
96
|
-
.action(async (options) => {
|
|
97
|
-
const spaceId = await resolveSpace(spacesCommand);
|
|
98
|
-
let input;
|
|
99
|
-
try {
|
|
100
|
-
input = parseSpaceInvitationCreateOptions(options);
|
|
101
|
-
}
|
|
102
|
-
catch (cause) {
|
|
103
|
-
if (cause instanceof InvalidSpaceInvitationCliOptionsError) {
|
|
104
|
-
return error(cause.message, cause.detail);
|
|
105
|
-
}
|
|
106
|
-
throw cause;
|
|
107
|
-
}
|
|
108
|
-
try {
|
|
109
|
-
const created = await dependencies
|
|
110
|
-
.createClient()
|
|
111
|
-
.space(spaceId)
|
|
112
|
-
.invitations.create(input);
|
|
113
|
-
const output = {
|
|
114
|
-
...created,
|
|
115
|
-
url: invitationUrl({
|
|
116
|
-
...created,
|
|
117
|
-
spaceId: created.spaceId || spaceId,
|
|
118
|
-
ownerUsername: created.ownerUsername ?? null,
|
|
119
|
-
spaceSlug: created.spaceSlug ?? null,
|
|
120
|
-
}),
|
|
121
|
-
};
|
|
122
|
-
if (jsonRequested(options))
|
|
123
|
-
return outJson(output);
|
|
124
|
-
ok(`Invite link created: ${output.url}`);
|
|
125
|
-
}
|
|
126
|
-
catch (cause) {
|
|
127
|
-
handleHttp(cause);
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
invitations
|
|
131
|
-
.command("ls")
|
|
132
|
-
.alias("list")
|
|
133
|
-
.description("List active invite links")
|
|
134
|
-
.option("--all", "Include revoked, exhausted, and expired links")
|
|
135
|
-
.option("--json", "Output as JSON")
|
|
136
|
-
.action(async (options) => {
|
|
137
|
-
const spaceId = await resolveSpace(spacesCommand);
|
|
138
|
-
try {
|
|
139
|
-
const result = await listAllInvitations(dependencies.createClient().space(spaceId).invitations, options.all ? "all" : "active");
|
|
140
|
-
const items = result.items.map((item) => ({
|
|
141
|
-
...item,
|
|
142
|
-
url: invitationUrl({
|
|
143
|
-
...result,
|
|
144
|
-
token: item.token,
|
|
145
|
-
spaceId: result.spaceId || spaceId,
|
|
146
|
-
ownerUsername: result.ownerUsername ?? null,
|
|
147
|
-
spaceSlug: result.spaceSlug ?? null,
|
|
148
|
-
}),
|
|
149
|
-
uses: item.maxUses ? `${item.useCount}/${item.maxUses}` : String(item.useCount),
|
|
150
|
-
expires: item.expiresAt ?? "never",
|
|
151
|
-
}));
|
|
152
|
-
if (jsonRequested(options))
|
|
153
|
-
return outJson({ ...result, items });
|
|
154
|
-
table(items, [
|
|
155
|
-
{ key: "token", label: "Code" },
|
|
156
|
-
{ key: "role", label: "Role" },
|
|
157
|
-
{ key: "status", label: "Status" },
|
|
158
|
-
{ key: "uses", label: "Uses" },
|
|
159
|
-
{ key: "expires", label: "Expires" },
|
|
160
|
-
{ key: "url", label: "URL" },
|
|
161
|
-
]);
|
|
162
|
-
}
|
|
163
|
-
catch (cause) {
|
|
164
|
-
handleHttp(cause);
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
invitations
|
|
168
|
-
.command("revoke <code>")
|
|
169
|
-
.description("Revoke an invite link")
|
|
170
|
-
.option("-y, --yes", "Confirm revocation")
|
|
171
|
-
.option("--json", "Output as JSON")
|
|
172
|
-
.action(async (code, options) => {
|
|
173
|
-
await confirmRevoke(options);
|
|
174
|
-
const spaceId = await resolveSpace(spacesCommand);
|
|
175
|
-
try {
|
|
176
|
-
const result = await dependencies
|
|
177
|
-
.createClient()
|
|
178
|
-
.space(spaceId)
|
|
179
|
-
.invitations.revoke(code);
|
|
180
|
-
if (jsonRequested(options))
|
|
181
|
-
return outJson(result);
|
|
182
|
-
ok("Invite link revoked");
|
|
183
|
-
}
|
|
184
|
-
catch (cause) {
|
|
185
|
-
handleHttp(cause);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
return invitations;
|
|
189
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { SpaceTurnListItem, SpaceTurnListOptions, SpaceTurnsResponse, SessionTurnRecord, TurnIntermediateMessagesFile } from "@neta-art/cohub";
|
|
2
|
-
import type { Command } from "commander";
|
|
3
|
-
import { type Row } from "../output.js";
|
|
4
|
-
export type SpaceTurnListCliOptions = {
|
|
5
|
-
author?: string;
|
|
6
|
-
after?: string;
|
|
7
|
-
before?: string;
|
|
8
|
-
cursor?: string;
|
|
9
|
-
limit?: string;
|
|
10
|
-
session?: string;
|
|
11
|
-
json?: boolean;
|
|
12
|
-
direction?: "older" | "newer";
|
|
13
|
-
};
|
|
14
|
-
type SpaceTurnsCommandClient = {
|
|
15
|
-
space(spaceId: string): {
|
|
16
|
-
turns: {
|
|
17
|
-
list(options: SpaceTurnListOptions): Promise<SpaceTurnsResponse>;
|
|
18
|
-
};
|
|
19
|
-
session(sessionId: string): {
|
|
20
|
-
turns: {
|
|
21
|
-
listPaginated(options?: {
|
|
22
|
-
cursor?: number;
|
|
23
|
-
limit?: number;
|
|
24
|
-
direction?: "older" | "newer";
|
|
25
|
-
}): Promise<{
|
|
26
|
-
session: unknown;
|
|
27
|
-
turns: SessionTurnRecord[];
|
|
28
|
-
hasMore: boolean;
|
|
29
|
-
nextCursor: number | undefined;
|
|
30
|
-
}>;
|
|
31
|
-
intermediate: {
|
|
32
|
-
get(turnId: string): Promise<TurnIntermediateMessagesFile | null>;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
export declare class InvalidSpaceTurnCliOptionsError extends Error {
|
|
39
|
-
readonly detail: string;
|
|
40
|
-
constructor(message: string, detail: string);
|
|
41
|
-
}
|
|
42
|
-
export declare function parseSpaceTurnListOptions(options: SpaceTurnListCliOptions): SpaceTurnListOptions;
|
|
43
|
-
export declare function parseSessionTurnCursor(value: string | undefined): number | undefined;
|
|
44
|
-
export declare function validateSpaceTurnListMode(options: SpaceTurnListCliOptions): void;
|
|
45
|
-
export declare function toSpaceTurnRows(turns: SpaceTurnListItem[]): Row[];
|
|
46
|
-
export declare function registerSpaceTurns(spacesCmd: Command, dependencies?: {
|
|
47
|
-
createClient?: () => SpaceTurnsCommandClient;
|
|
48
|
-
}): Command;
|
|
49
|
-
export {};
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import { createClient } from "../client.js";
|
|
2
|
-
import { error, handleHttp, json as outJson, jsonRequested, table, } from "../output.js";
|
|
3
|
-
import { resolveSpace } from "../space.js";
|
|
4
|
-
const SPACE_TURN_AUTHORS = ["any", "self", "others"];
|
|
5
|
-
export class InvalidSpaceTurnCliOptionsError extends Error {
|
|
6
|
-
detail;
|
|
7
|
-
constructor(message, detail) {
|
|
8
|
-
super(message);
|
|
9
|
-
this.detail = detail;
|
|
10
|
-
this.name = "InvalidSpaceTurnCliOptionsError";
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
function parseAuthor(value) {
|
|
14
|
-
if (value === undefined)
|
|
15
|
-
return undefined;
|
|
16
|
-
if (SPACE_TURN_AUTHORS.includes(value)) {
|
|
17
|
-
return value;
|
|
18
|
-
}
|
|
19
|
-
throw new InvalidSpaceTurnCliOptionsError("Invalid author", `Use one of: ${SPACE_TURN_AUTHORS.join(", ")}`);
|
|
20
|
-
}
|
|
21
|
-
function parseLimit(value) {
|
|
22
|
-
if (value === undefined)
|
|
23
|
-
return undefined;
|
|
24
|
-
if (!/^\d+$/.test(value.trim())) {
|
|
25
|
-
throw new InvalidSpaceTurnCliOptionsError("Invalid limit", "limit must be an integer from 1 to 100");
|
|
26
|
-
}
|
|
27
|
-
const limit = Number.parseInt(value, 10);
|
|
28
|
-
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100) {
|
|
29
|
-
throw new InvalidSpaceTurnCliOptionsError("Invalid limit", "limit must be an integer from 1 to 100");
|
|
30
|
-
}
|
|
31
|
-
return limit;
|
|
32
|
-
}
|
|
33
|
-
function parseBefore(value) {
|
|
34
|
-
if (value === undefined)
|
|
35
|
-
return undefined;
|
|
36
|
-
if (!value.trim() || Number.isNaN(new Date(value).getTime())) {
|
|
37
|
-
throw new InvalidSpaceTurnCliOptionsError("Invalid before", "before must be an ISO 8601 timestamp");
|
|
38
|
-
}
|
|
39
|
-
return value;
|
|
40
|
-
}
|
|
41
|
-
export function parseSpaceTurnListOptions(options) {
|
|
42
|
-
return {
|
|
43
|
-
author: parseAuthor(options.author),
|
|
44
|
-
after: options.after,
|
|
45
|
-
before: parseBefore(options.before),
|
|
46
|
-
cursor: options.cursor,
|
|
47
|
-
limit: parseLimit(options.limit),
|
|
48
|
-
sessionId: options.session,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
export function parseSessionTurnCursor(value) {
|
|
52
|
-
if (value === undefined)
|
|
53
|
-
return undefined;
|
|
54
|
-
const cursor = Number(value);
|
|
55
|
-
if (!Number.isSafeInteger(cursor) || cursor < 1) {
|
|
56
|
-
throw new InvalidSpaceTurnCliOptionsError("Invalid cursor", "Session cursor must be a positive turn sequence");
|
|
57
|
-
}
|
|
58
|
-
return cursor;
|
|
59
|
-
}
|
|
60
|
-
export function validateSpaceTurnListMode(options) {
|
|
61
|
-
if (!options.session && options.direction !== undefined) {
|
|
62
|
-
throw new InvalidSpaceTurnCliOptionsError("Invalid direction", "--direction only applies with --session");
|
|
63
|
-
}
|
|
64
|
-
if (options.session && (options.author || options.after || options.before)) {
|
|
65
|
-
throw new InvalidSpaceTurnCliOptionsError("Invalid session turn options", "--session uses the Session turns API; omit --author, --after, and --before");
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
export function toSpaceTurnRows(turns) {
|
|
69
|
-
return turns.map((turn) => ({
|
|
70
|
-
createdAt: turn.createdAt,
|
|
71
|
-
author: turn.authorProfile?.displayName ?? turn.userUuid ?? "system",
|
|
72
|
-
sessionTitle: turn.session.title ?? "",
|
|
73
|
-
sessionId: turn.session.id,
|
|
74
|
-
sequence: turn.sequence,
|
|
75
|
-
id: turn.id,
|
|
76
|
-
status: turn.status,
|
|
77
|
-
userPreview: turn.userPreview ?? "",
|
|
78
|
-
assistantPreview: turn.assistantPreview ?? "",
|
|
79
|
-
}));
|
|
80
|
-
}
|
|
81
|
-
export function registerSpaceTurns(spacesCmd, dependencies = {}) {
|
|
82
|
-
const turnsCmd = spacesCmd
|
|
83
|
-
.command("turns")
|
|
84
|
-
.description("Browse turns across the space")
|
|
85
|
-
.hook("preAction", async () => {
|
|
86
|
-
await resolveSpace(spacesCmd);
|
|
87
|
-
});
|
|
88
|
-
turnsCmd
|
|
89
|
-
.command("ls")
|
|
90
|
-
.alias("list")
|
|
91
|
-
.description("List turns in the space, or full turns from one session")
|
|
92
|
-
.option("--author <any|self|others>", "Filter space turns by author")
|
|
93
|
-
.option("--after <cursor>", "Start after a previous snapshot cursor")
|
|
94
|
-
.option("--before <timestamp>", "End at an ISO 8601 timestamp")
|
|
95
|
-
.option("--cursor <cursor>", "Page cursor; with --session, use a turn sequence")
|
|
96
|
-
.option("--limit <n>", "Maximum turns per page, 1-100")
|
|
97
|
-
.option("--session <id>", "Use the full turn list for this session")
|
|
98
|
-
.option("--direction <older|newer>", "Session page direction; use with --session")
|
|
99
|
-
.option("--json", "Output as JSON")
|
|
100
|
-
.action(async (options) => {
|
|
101
|
-
let query;
|
|
102
|
-
try {
|
|
103
|
-
query = parseSpaceTurnListOptions(options);
|
|
104
|
-
}
|
|
105
|
-
catch (cause) {
|
|
106
|
-
if (cause instanceof InvalidSpaceTurnCliOptionsError) {
|
|
107
|
-
return error(cause.message, cause.detail);
|
|
108
|
-
}
|
|
109
|
-
throw cause;
|
|
110
|
-
}
|
|
111
|
-
const spaceId = await resolveSpace(spacesCmd);
|
|
112
|
-
const client = dependencies.createClient?.() ?? createClient();
|
|
113
|
-
try {
|
|
114
|
-
try {
|
|
115
|
-
validateSpaceTurnListMode(options);
|
|
116
|
-
}
|
|
117
|
-
catch (cause) {
|
|
118
|
-
if (cause instanceof InvalidSpaceTurnCliOptionsError)
|
|
119
|
-
return error(cause.message, cause.detail);
|
|
120
|
-
throw cause;
|
|
121
|
-
}
|
|
122
|
-
if (options.session) {
|
|
123
|
-
let sessionCursor;
|
|
124
|
-
try {
|
|
125
|
-
sessionCursor = parseSessionTurnCursor(options.cursor);
|
|
126
|
-
}
|
|
127
|
-
catch (cause) {
|
|
128
|
-
if (cause instanceof InvalidSpaceTurnCliOptionsError)
|
|
129
|
-
return error(cause.message, cause.detail);
|
|
130
|
-
throw cause;
|
|
131
|
-
}
|
|
132
|
-
const result = await client.space(spaceId).session(options.session).turns.listPaginated({
|
|
133
|
-
cursor: sessionCursor,
|
|
134
|
-
limit: query.limit,
|
|
135
|
-
direction: options.direction,
|
|
136
|
-
});
|
|
137
|
-
if (jsonRequested(options))
|
|
138
|
-
return outJson(result);
|
|
139
|
-
if (result.turns.length === 0)
|
|
140
|
-
return console.log(" No turns found");
|
|
141
|
-
table(result.turns, [
|
|
142
|
-
{ key: "sequence", label: "Seq" },
|
|
143
|
-
{ key: "id", label: "Turn ID" },
|
|
144
|
-
{ key: "status", label: "Status" },
|
|
145
|
-
{ key: "userText", label: "User" },
|
|
146
|
-
{ key: "assistantText", label: "Assistant" },
|
|
147
|
-
{ key: "updatedAt", label: "Updated" },
|
|
148
|
-
]);
|
|
149
|
-
if (result.hasMore)
|
|
150
|
-
console.log(`\n More turns available - next cursor: ${result.nextCursor}`);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
const result = await client.space(spaceId).turns.list(query);
|
|
154
|
-
if (jsonRequested(options))
|
|
155
|
-
return outJson(result);
|
|
156
|
-
if (result.turns.length === 0)
|
|
157
|
-
return console.log(" No turns found");
|
|
158
|
-
table(toSpaceTurnRows(result.turns), [
|
|
159
|
-
{ key: "createdAt", label: "Created" },
|
|
160
|
-
{ key: "author", label: "Author" },
|
|
161
|
-
{ key: "sessionTitle", label: "Session" },
|
|
162
|
-
{ key: "sessionId", label: "Session ID" },
|
|
163
|
-
{ key: "sequence", label: "Seq" },
|
|
164
|
-
{ key: "id", label: "Turn ID" },
|
|
165
|
-
{ key: "status", label: "Status" },
|
|
166
|
-
{ key: "userPreview", label: "User" },
|
|
167
|
-
{ key: "assistantPreview", label: "Assistant" },
|
|
168
|
-
]);
|
|
169
|
-
if (result.pageInfo.hasMore && result.pageInfo.nextCursor) {
|
|
170
|
-
console.log(`\n More turns available - next cursor: ${result.pageInfo.nextCursor}`);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
catch (cause) {
|
|
174
|
-
handleHttp(cause);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
turnsCmd
|
|
178
|
-
.command("intermediate <sessionId> <turnId>")
|
|
179
|
-
.description("Read persisted intermediate messages from the CDN archive")
|
|
180
|
-
.option("--json", "Output as JSON")
|
|
181
|
-
.action(async (sessionId, turnId, options) => {
|
|
182
|
-
const spaceId = await resolveSpace(spacesCmd);
|
|
183
|
-
const client = dependencies.createClient?.() ?? createClient();
|
|
184
|
-
try {
|
|
185
|
-
const archive = await client.space(spaceId).session(sessionId).turns.intermediate.get(turnId);
|
|
186
|
-
if (jsonRequested(options))
|
|
187
|
-
return outJson(archive);
|
|
188
|
-
if (!archive)
|
|
189
|
-
return console.log(" No intermediate messages found");
|
|
190
|
-
console.log(`Turn ${archive.turnId}`);
|
|
191
|
-
console.log(` ${archive.summary.messageCount} intermediate messages · ${archive.summary.toolCallCount} tool calls`);
|
|
192
|
-
for (const [index, message] of archive.messages.entries()) {
|
|
193
|
-
console.log(`\n${index + 1}. ${message.role}${message.provider ? ` · ${message.provider}/${message.model ?? ""}` : ""}`);
|
|
194
|
-
if (message.text)
|
|
195
|
-
console.log(message.text);
|
|
196
|
-
if (message.toolCallsObjectKey)
|
|
197
|
-
console.log(" Tool calls: available");
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
catch (cause) {
|
|
201
|
-
handleHttp(cause);
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
return turnsCmd;
|
|
205
|
-
}
|