@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,297 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { createWriteStream } from "node:fs";
|
|
3
|
-
import { cp, lstat, mkdir, readdir, rename, rm, stat, utimes } from "node:fs/promises";
|
|
4
|
-
import { dirname, join, posix } from "node:path";
|
|
5
|
-
import { Readable } from "node:stream";
|
|
6
|
-
import { pipeline } from "node:stream/promises";
|
|
7
|
-
import { UPLOAD_MAX_FILE_BYTES } from "@neta-art/cohub";
|
|
8
|
-
import { createLimiter } from "./limit.js";
|
|
9
|
-
import { uploadLocalFiles, uploadsDirectly } from "./upload.js";
|
|
10
|
-
export class CopyAbortError extends Error {
|
|
11
|
-
name = "CopyAbortError";
|
|
12
|
-
}
|
|
13
|
-
export const emptyCopyResult = () => ({
|
|
14
|
-
files: 0, dirs: 0, symlinks: 0, bytes: 0, paths: [], overwritten: 0, skipped: 0, errors: [],
|
|
15
|
-
});
|
|
16
|
-
export function mergeCopyResults(results) {
|
|
17
|
-
const merged = emptyCopyResult();
|
|
18
|
-
for (const result of results) {
|
|
19
|
-
for (const key of ["files", "dirs", "symlinks", "bytes", "overwritten", "skipped"])
|
|
20
|
-
merged[key] += result[key];
|
|
21
|
-
merged.paths.push(...result.paths);
|
|
22
|
-
merged.errors.push(...result.errors);
|
|
23
|
-
}
|
|
24
|
-
return merged;
|
|
25
|
-
}
|
|
26
|
-
const display = (path) => path || ".";
|
|
27
|
-
const targetOf = (source, destination, intoDirectory, join) => {
|
|
28
|
-
const name = posix.basename(source);
|
|
29
|
-
return intoDirectory && name ? join(destination, name) : destination;
|
|
30
|
-
};
|
|
31
|
-
const joinSpacePath = (parent, name) => (parent ? `${parent}/${name}` : name);
|
|
32
|
-
const lstatOrNull = (path) => lstat(path).catch(() => null);
|
|
33
|
-
export async function statSpacePath(files, path) {
|
|
34
|
-
try {
|
|
35
|
-
return { type: "dir", tree: await files.list(path) };
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
const { status, code } = error;
|
|
39
|
-
if (status === 404)
|
|
40
|
-
return null;
|
|
41
|
-
if (code === "not_a_directory")
|
|
42
|
-
return { type: "file" };
|
|
43
|
-
throw error;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
export async function checkDestination(input) {
|
|
47
|
-
const node = await input.stat(input.path);
|
|
48
|
-
if (input.sourceCount > 1 && node !== "dir")
|
|
49
|
-
throw new CopyAbortError(`target '${input.display}' is not a directory`);
|
|
50
|
-
if (!node && input.parent !== input.path && (await input.stat(input.parent)) !== "dir") {
|
|
51
|
-
throw new CopyAbortError(`cannot create '${input.display}': No such file or directory`);
|
|
52
|
-
}
|
|
53
|
-
return node === "dir";
|
|
54
|
-
}
|
|
55
|
-
export const spaceNodeType = async (files, path) => (await statSpacePath(files, path))?.type ?? null;
|
|
56
|
-
export const localNodeType = async (path) => {
|
|
57
|
-
const stats = await lstatOrNull(path);
|
|
58
|
-
return stats ? (stats.isDirectory() ? "dir" : "file") : null;
|
|
59
|
-
};
|
|
60
|
-
const isUploadableName = (name) => name.length > 0 && name.length <= 255 && name !== "." && name !== ".." && name.trim() === name &&
|
|
61
|
-
!/[<>:"/\\|?*]/.test(name) && ![...name].some((char) => char.charCodeAt(0) <= 0x1f);
|
|
62
|
-
export async function uploadToSpace(input) {
|
|
63
|
-
const { files, options } = input;
|
|
64
|
-
const result = emptyCopyResult();
|
|
65
|
-
const fail = (path, code, message) => {
|
|
66
|
-
result.errors.push({ path, code, message });
|
|
67
|
-
};
|
|
68
|
-
const entries = [];
|
|
69
|
-
const walk = async (localPath, target, stats) => {
|
|
70
|
-
if (stats.isFile()) {
|
|
71
|
-
entries.push({ localPath, relativePath: target, size: stats.size });
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (!stats.isDirectory()) {
|
|
75
|
-
result.skipped += 1;
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
const names = await readdir(localPath);
|
|
79
|
-
await Promise.all(names.map(async (name) => {
|
|
80
|
-
const child = join(localPath, name);
|
|
81
|
-
const childStats = await stat(child).catch(() => null);
|
|
82
|
-
if (childStats)
|
|
83
|
-
await walk(child, joinSpacePath(target, name), childStats);
|
|
84
|
-
}));
|
|
85
|
-
};
|
|
86
|
-
for (const source of input.sources) {
|
|
87
|
-
const stats = await stat(source).catch(() => null);
|
|
88
|
-
if (!stats) {
|
|
89
|
-
fail(source, "path_not_found", `cannot stat '${source}': No such file or directory`);
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
if (stats.isDirectory() && !options.recursive) {
|
|
93
|
-
fail(source, "is_a_directory", `-r not specified; omitting directory '${source}'`);
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
const target = targetOf(source, input.destination, input.intoDirectory, joinSpacePath);
|
|
97
|
-
await walk(source, target, stats);
|
|
98
|
-
result.paths.push(target);
|
|
99
|
-
}
|
|
100
|
-
const parents = [...new Set(entries.map((entry) => posix.dirname(entry.relativePath)).map((dir) => (dir === "." ? "" : dir)))];
|
|
101
|
-
const limit = createLimiter(8);
|
|
102
|
-
const existing = new Map();
|
|
103
|
-
await Promise.all(parents.map((dir) => limit(async () => {
|
|
104
|
-
const node = await statSpacePath(files, dir);
|
|
105
|
-
if (node?.type === "dir")
|
|
106
|
-
for (const entry of node.tree.entries)
|
|
107
|
-
existing.set(entry.path, entry.type);
|
|
108
|
-
})));
|
|
109
|
-
const maxFileBytes = await uploadsDirectly(files) ? Number.POSITIVE_INFINITY : UPLOAD_MAX_FILE_BYTES;
|
|
110
|
-
const upload = entries.filter((entry) => {
|
|
111
|
-
const current = existing.get(entry.relativePath);
|
|
112
|
-
if (current === "dir") {
|
|
113
|
-
fail(entry.relativePath, "is_a_directory", `cannot overwrite directory '${entry.relativePath}' with non-directory`);
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
if (current && options.noClobber) {
|
|
117
|
-
result.skipped += 1;
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
if (!entry.relativePath.split("/").every(isUploadableName)) {
|
|
121
|
-
fail(entry.relativePath, "name_invalid", `cannot upload '${entry.localPath}': unsupported file name`);
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
if (entry.size > maxFileBytes) {
|
|
125
|
-
fail(entry.relativePath, "file_too_large", `cannot upload '${entry.localPath}': file exceeds the upload size limit`);
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
if (current)
|
|
129
|
-
result.overwritten += 1;
|
|
130
|
-
return true;
|
|
131
|
-
});
|
|
132
|
-
const progress = { files: 0, dirs: 0, symlinks: 0, bytes: 0 };
|
|
133
|
-
await uploadLocalFiles(files, upload, {
|
|
134
|
-
onUploaded: (entry) => {
|
|
135
|
-
progress.files += 1;
|
|
136
|
-
progress.bytes += entry.size;
|
|
137
|
-
input.onProgress(progress);
|
|
138
|
-
},
|
|
139
|
-
});
|
|
140
|
-
return { ...result, ...progress };
|
|
141
|
-
}
|
|
142
|
-
export async function downloadFromSpace(input) {
|
|
143
|
-
const { options } = input;
|
|
144
|
-
const result = emptyCopyResult();
|
|
145
|
-
const fail = (path, code, message) => {
|
|
146
|
-
result.errors.push({ path, code, message });
|
|
147
|
-
};
|
|
148
|
-
const limit = createLimiter(6);
|
|
149
|
-
const report = () => input.onProgress(result);
|
|
150
|
-
const downloadFile = async (files, path, target, mtimeMs) => {
|
|
151
|
-
const current = await lstatOrNull(target);
|
|
152
|
-
if (current?.isDirectory())
|
|
153
|
-
return fail(target, "is_a_directory", `cannot overwrite directory '${target}' with non-directory`);
|
|
154
|
-
if (current && options.noClobber) {
|
|
155
|
-
result.skipped += 1;
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
const temp = join(dirname(target), `.cohub-download.${randomUUID().slice(0, 8)}`);
|
|
159
|
-
try {
|
|
160
|
-
const bytes = await limit(async () => {
|
|
161
|
-
const { response } = await files.open(path);
|
|
162
|
-
let written = 0;
|
|
163
|
-
if (response.body) {
|
|
164
|
-
const body = Readable.fromWeb(response.body);
|
|
165
|
-
body.on("data", (chunk) => {
|
|
166
|
-
written += chunk.length;
|
|
167
|
-
});
|
|
168
|
-
await pipeline(body, createWriteStream(temp, { flags: "wx" }));
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
await pipeline(Readable.from([]), createWriteStream(temp, { flags: "wx" }));
|
|
172
|
-
}
|
|
173
|
-
return written;
|
|
174
|
-
});
|
|
175
|
-
if (options.preserveTimestamps && mtimeMs !== undefined)
|
|
176
|
-
await utimes(temp, new Date(), new Date(mtimeMs));
|
|
177
|
-
await rename(temp, target);
|
|
178
|
-
result.files += 1;
|
|
179
|
-
result.bytes += bytes;
|
|
180
|
-
if (current)
|
|
181
|
-
result.overwritten += 1;
|
|
182
|
-
report();
|
|
183
|
-
}
|
|
184
|
-
catch (error) {
|
|
185
|
-
await rm(temp, { force: true });
|
|
186
|
-
fail(target, "download_failed", `cannot download '${display(path)}': ${error.message}`);
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
const downloadDir = async (files, tree, target) => {
|
|
190
|
-
const current = await lstatOrNull(target);
|
|
191
|
-
if (current && !current.isDirectory()) {
|
|
192
|
-
return fail(target, "not_a_directory", `cannot overwrite non-directory '${target}' with directory '${display(tree.path)}'`);
|
|
193
|
-
}
|
|
194
|
-
if (!current)
|
|
195
|
-
await mkdir(target);
|
|
196
|
-
result.dirs += 1;
|
|
197
|
-
if (tree.entries.length >= 1000) {
|
|
198
|
-
fail(target, "listing_truncated", `cannot copy all of '${display(tree.path)}': directories with 1000 or more entries are not fully listed`);
|
|
199
|
-
}
|
|
200
|
-
await Promise.all(tree.entries.map(async (entry) => {
|
|
201
|
-
const child = join(target, entry.name);
|
|
202
|
-
if (entry.type === "file")
|
|
203
|
-
return downloadFile(files, entry.path, child, entry.mtimeMs);
|
|
204
|
-
if (entry.type === "symlink") {
|
|
205
|
-
result.skipped += 1;
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
const node = await limit(() => statSpacePath(files, entry.path));
|
|
209
|
-
if (node?.type === "dir")
|
|
210
|
-
await downloadDir(files, node.tree, child);
|
|
211
|
-
}));
|
|
212
|
-
};
|
|
213
|
-
for (const { files, path } of input.sources) {
|
|
214
|
-
const node = await statSpacePath(files, path);
|
|
215
|
-
if (!node) {
|
|
216
|
-
fail(path, "path_not_found", `cannot stat '${display(path)}': No such file or directory`);
|
|
217
|
-
continue;
|
|
218
|
-
}
|
|
219
|
-
if (node.type === "dir" && !options.recursive) {
|
|
220
|
-
fail(path, "is_a_directory", `-r not specified; omitting directory '${display(path)}'`);
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
const target = targetOf(path, input.destination, input.intoDirectory, join);
|
|
224
|
-
if (node.type === "dir") {
|
|
225
|
-
await downloadDir(files, node.tree, target);
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
const parent = options.preserveTimestamps ? await statSpacePath(files, posix.dirname(path) === "." ? "" : posix.dirname(path)) : null;
|
|
229
|
-
const mtimeMs = parent?.type === "dir" ? parent.tree.entries.find((entry) => entry.path === path)?.mtimeMs : undefined;
|
|
230
|
-
await downloadFile(files, path, target, mtimeMs);
|
|
231
|
-
}
|
|
232
|
-
result.paths.push(target);
|
|
233
|
-
}
|
|
234
|
-
return result;
|
|
235
|
-
}
|
|
236
|
-
export async function copyLocal(input) {
|
|
237
|
-
const { options } = input;
|
|
238
|
-
const result = emptyCopyResult();
|
|
239
|
-
const fail = (path, code, message) => {
|
|
240
|
-
result.errors.push({ path, code, message });
|
|
241
|
-
};
|
|
242
|
-
for (const source of input.sources) {
|
|
243
|
-
const stats = await lstatOrNull(source);
|
|
244
|
-
if (!stats) {
|
|
245
|
-
fail(source, "path_not_found", `cannot stat '${source}': No such file or directory`);
|
|
246
|
-
continue;
|
|
247
|
-
}
|
|
248
|
-
if (stats.isDirectory() && !options.recursive) {
|
|
249
|
-
fail(source, "is_a_directory", `-r not specified; omitting directory '${source}'`);
|
|
250
|
-
continue;
|
|
251
|
-
}
|
|
252
|
-
const target = targetOf(source, input.destination, input.intoDirectory, join);
|
|
253
|
-
if (target === source) {
|
|
254
|
-
fail(source, "same_file", `'${source}' and '${target}' are the same file`);
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
if (stats.isDirectory() && target.startsWith(`${source}/`)) {
|
|
258
|
-
fail(source, "copy_into_itself", `cannot copy a directory, '${source}', into itself, '${target}'`);
|
|
259
|
-
continue;
|
|
260
|
-
}
|
|
261
|
-
try {
|
|
262
|
-
await cp(source, target, {
|
|
263
|
-
recursive: true,
|
|
264
|
-
force: !options.noClobber,
|
|
265
|
-
errorOnExist: false,
|
|
266
|
-
preserveTimestamps: options.preserveTimestamps,
|
|
267
|
-
verbatimSymlinks: true,
|
|
268
|
-
filter: async (from, to) => {
|
|
269
|
-
const node = await lstat(from);
|
|
270
|
-
if (node.isDirectory()) {
|
|
271
|
-
result.dirs += 1;
|
|
272
|
-
return true;
|
|
273
|
-
}
|
|
274
|
-
const existing = await lstatOrNull(to);
|
|
275
|
-
if (existing && options.noClobber) {
|
|
276
|
-
result.skipped += 1;
|
|
277
|
-
return false;
|
|
278
|
-
}
|
|
279
|
-
if (existing)
|
|
280
|
-
result.overwritten += 1;
|
|
281
|
-
if (node.isSymbolicLink())
|
|
282
|
-
result.symlinks += 1;
|
|
283
|
-
else {
|
|
284
|
-
result.files += 1;
|
|
285
|
-
result.bytes += node.size;
|
|
286
|
-
}
|
|
287
|
-
return true;
|
|
288
|
-
},
|
|
289
|
-
});
|
|
290
|
-
result.paths.push(target);
|
|
291
|
-
}
|
|
292
|
-
catch (error) {
|
|
293
|
-
fail(target, "copy_failed", `cannot copy '${source}': ${error.message}`);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
return result;
|
|
297
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { type CohubHttpClient, type SpaceFsUploadEntry } from "@neta-art/cohub";
|
|
2
|
-
export type SpaceFiles = ReturnType<CohubHttpClient["space"]>["files"];
|
|
3
|
-
export type LocalUploadEntry = {
|
|
4
|
-
localPath: string;
|
|
5
|
-
relativePath: string;
|
|
6
|
-
size: number;
|
|
7
|
-
};
|
|
8
|
-
type UploadOptions = {
|
|
9
|
-
targetDir?: string;
|
|
10
|
-
onUploaded?: (entry: LocalUploadEntry) => void;
|
|
11
|
-
};
|
|
12
|
-
export declare const uploadsDirectly: (files: SpaceFiles) => Promise<boolean>;
|
|
13
|
-
export declare function uploadLocalFiles(files: SpaceFiles, entries: LocalUploadEntry[], options?: UploadOptions): Promise<{
|
|
14
|
-
uploaded: SpaceFsUploadEntry[];
|
|
15
|
-
uploadIds: string[];
|
|
16
|
-
}>;
|
|
17
|
-
export {};
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { openAsBlob } from "node:fs";
|
|
3
|
-
import { posix } from "node:path";
|
|
4
|
-
import { batchUploadEntries, LocalWorkspaceUnavailableError, localWorkspaceHttpError, mimeTypeForPath, } from "@neta-art/cohub";
|
|
5
|
-
import { putLocalFile } from "../http-put.js";
|
|
6
|
-
import { createLimiter } from "./limit.js";
|
|
7
|
-
const PUT_CONCURRENCY = 4;
|
|
8
|
-
export const uploadsDirectly = async (files) => Boolean((await files.workspace())?.put);
|
|
9
|
-
export async function uploadLocalFiles(files, entries, options = {}) {
|
|
10
|
-
const workspace = await files.workspace();
|
|
11
|
-
if (!workspace?.put)
|
|
12
|
-
return uploadThroughApi(files, entries, options);
|
|
13
|
-
const { uploaded, remaining } = await putLocalFiles(workspace, workspace.put, entries, options);
|
|
14
|
-
if (!remaining.length)
|
|
15
|
-
return { uploaded, uploadIds: [] };
|
|
16
|
-
const rest = await uploadThroughApi(files, remaining, options);
|
|
17
|
-
return { uploaded: [...uploaded, ...rest.uploaded], uploadIds: rest.uploadIds };
|
|
18
|
-
}
|
|
19
|
-
async function putLocalFiles(workspace, put, entries, options) {
|
|
20
|
-
const limit = createLimiter(PUT_CONCURRENCY);
|
|
21
|
-
const uploaded = [];
|
|
22
|
-
const remaining = [];
|
|
23
|
-
const failures = [];
|
|
24
|
-
await Promise.all(entries.map((entry) => limit(async () => {
|
|
25
|
-
const path = options.targetDir ? posix.join(options.targetDir, entry.relativePath) : entry.relativePath;
|
|
26
|
-
try {
|
|
27
|
-
// As the API's uploads do: a file edited meanwhile is a conflict, never overwritten.
|
|
28
|
-
const version = await workspace.fs.statVersion(path);
|
|
29
|
-
const expected = version.exists ? { expected: { size: version.size, mtimeMs: version.mtimeMs } } : { exclusive: true };
|
|
30
|
-
const result = await put(path, await openAsBlob(entry.localPath), expected);
|
|
31
|
-
const name = posix.basename(path);
|
|
32
|
-
uploaded.push({ path, name, size: result.bytesWritten, mimeType: mimeTypeForPath(name), mtimeMs: result.mtimeMs ?? Date.now(), created: result.created });
|
|
33
|
-
options.onUploaded?.(entry);
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
if (error instanceof LocalWorkspaceUnavailableError)
|
|
37
|
-
remaining.push(entry);
|
|
38
|
-
else
|
|
39
|
-
failures.push(error);
|
|
40
|
-
}
|
|
41
|
-
})));
|
|
42
|
-
if (failures.length)
|
|
43
|
-
throw localWorkspaceHttpError(failures[0]);
|
|
44
|
-
return { uploaded, remaining };
|
|
45
|
-
}
|
|
46
|
-
async function uploadThroughApi(files, entries, options) {
|
|
47
|
-
const uploaded = [];
|
|
48
|
-
const uploadIds = [];
|
|
49
|
-
const limit = createLimiter(PUT_CONCURRENCY);
|
|
50
|
-
for (const batch of batchUploadEntries(entries, (entry) => entry.size)) {
|
|
51
|
-
const byId = new Map(batch.map((entry) => [randomUUID(), entry]));
|
|
52
|
-
const plan = await files.createUpload({
|
|
53
|
-
destination: { kind: "workspace", targetDir: options.targetDir },
|
|
54
|
-
entries: [...byId].map(([id, entry]) => ({
|
|
55
|
-
id,
|
|
56
|
-
name: entry.relativePath.split("/").at(-1) ?? entry.relativePath,
|
|
57
|
-
relativePath: entry.relativePath,
|
|
58
|
-
size: entry.size,
|
|
59
|
-
mimeType: null,
|
|
60
|
-
})),
|
|
61
|
-
});
|
|
62
|
-
await Promise.all(plan.entries.map((item) => limit(async () => {
|
|
63
|
-
const entry = byId.get(item.id);
|
|
64
|
-
if (!entry)
|
|
65
|
-
throw new Error(`Missing upload entry: ${item.id}`);
|
|
66
|
-
if (item.uploadUrl) {
|
|
67
|
-
await putLocalFile({ url: item.uploadUrl, filePath: entry.localPath, size: entry.size, headers: item.headers, label: entry.relativePath });
|
|
68
|
-
}
|
|
69
|
-
options.onUploaded?.(entry);
|
|
70
|
-
})));
|
|
71
|
-
const result = await files.completeUpload(plan.uploadId, { entries: plan.entries.map((item) => ({ id: item.id })) });
|
|
72
|
-
uploaded.push(...result.uploaded);
|
|
73
|
-
uploadIds.push(plan.uploadId);
|
|
74
|
-
}
|
|
75
|
-
return { uploaded, uploadIds };
|
|
76
|
-
}
|
package/dist/space.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { Command } from "commander";
|
|
2
|
-
export declare class SpaceTargetError extends Error {
|
|
3
|
-
readonly detail?: string | undefined;
|
|
4
|
-
name: string;
|
|
5
|
-
constructor(message: string, detail?: string | undefined);
|
|
6
|
-
}
|
|
7
|
-
export declare function jwtClaim(token: string | undefined | null, key: string): string | null;
|
|
8
|
-
/**
|
|
9
|
-
* Cache key aligned with auth: execution token is exclusive (same as
|
|
10
|
-
* `resolveAccessToken`) and never falls back to a local Logto session.
|
|
11
|
-
* Execution grants identify the actor as `actorUserId`, not `sub`.
|
|
12
|
-
*/
|
|
13
|
-
export declare function identityKeyFrom(input: {
|
|
14
|
-
env: string;
|
|
15
|
-
baseUrl?: string;
|
|
16
|
-
executionToken?: string | null;
|
|
17
|
-
idToken?: string | null;
|
|
18
|
-
accessToken?: string | null;
|
|
19
|
-
}): string | null;
|
|
20
|
-
export declare function currentIdentityKey(): string | null;
|
|
21
|
-
/** Exported for tests; production always uses `CACHE_PATH`. */
|
|
22
|
-
export declare function readHomeSpaceCache(path: string, key: string, now?: number): string | null;
|
|
23
|
-
export declare function clearHomeSpaceCache(): void;
|
|
24
|
-
/** Explicit target from `-s/--space` (any ancestor) or `COHUB_SPACE_ID`, else null. */
|
|
25
|
-
export declare function explicitSpace(program: Command): string | null;
|
|
26
|
-
/** Cached per identity and memoized per process. */
|
|
27
|
-
export declare function resolveHomeSpace(): Promise<string>;
|
|
28
|
-
export declare function resolveSpaceRef(value: string): Promise<string>;
|
|
29
|
-
export declare function failSpaceTarget(e: unknown): never;
|
|
30
|
-
/** Shared exit for commands that need a space but resolved none. */
|
|
31
|
-
export declare function missingSpaceError(): never;
|
|
32
|
-
export declare function resolveBoundSpace(options?: {
|
|
33
|
-
cwd?: string;
|
|
34
|
-
bindingsPath?: string;
|
|
35
|
-
}): Promise<string | null>;
|
|
36
|
-
export type SpaceTargetOptions = {
|
|
37
|
-
/** Only for commands that start new work. */
|
|
38
|
-
home?: boolean;
|
|
39
|
-
cwd?: string;
|
|
40
|
-
bindingsPath?: string;
|
|
41
|
-
};
|
|
42
|
-
/** Explicit target or `COHUB_SPACE_ID`, then the directory binding, then Home when allowed. */
|
|
43
|
-
export declare function resolveSpaceTarget(target?: string | null, options?: SpaceTargetOptions): Promise<string>;
|
|
44
|
-
export declare function resolveSpace(command: Command, options?: Pick<SpaceTargetOptions, "home">): Promise<string>;
|
package/dist/space.js
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { COHUB_ENVIRONMENTS, HOME_SPACE_SLUG, normalizeBaseUrl, parseSpaceRef, resolveApiBaseUrl, resolveCohubEnvironment } from "@neta-art/cohub";
|
|
5
|
-
import { readAuthSession } from "./auth.js";
|
|
6
|
-
import { createClient } from "./client.js";
|
|
7
|
-
import { getRuntimeSpaceBinding } from "./runtime/space-binding.js";
|
|
8
|
-
import { error, handleHttp } from "./output.js";
|
|
9
|
-
const CONFIG_DIR = join(homedir(), ".config", "cohub");
|
|
10
|
-
const CACHE_PATH = join(CONFIG_DIR, "home-space.json");
|
|
11
|
-
/** Legacy cache that may name another user's Home; never read. */
|
|
12
|
-
const LEGACY_CACHE_PATH = join(CONFIG_DIR, "default-space.json");
|
|
13
|
-
/** Home space is stable; a one-day TTL bounds how long a stale hit survives. */
|
|
14
|
-
const CACHE_TTL_MS = 86_400_000;
|
|
15
|
-
const SPACE_REF_HINT = "Use a Space ID, a slug you own such as home, or username/slug.";
|
|
16
|
-
export class SpaceTargetError extends Error {
|
|
17
|
-
detail;
|
|
18
|
-
name = "SpaceTargetError";
|
|
19
|
-
constructor(message, detail) {
|
|
20
|
-
super(message);
|
|
21
|
-
this.detail = detail;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
export function jwtClaim(token, key) {
|
|
25
|
-
const payload = token?.split(".")[1];
|
|
26
|
-
if (!payload)
|
|
27
|
-
return null;
|
|
28
|
-
try {
|
|
29
|
-
const parsed = JSON.parse(Buffer.from(payload, "base64url").toString("utf-8"));
|
|
30
|
-
const value = parsed[key];
|
|
31
|
-
return typeof value === "string" && value ? value : null;
|
|
32
|
-
}
|
|
33
|
-
catch {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Cache key aligned with auth: execution token is exclusive (same as
|
|
39
|
-
* `resolveAccessToken`) and never falls back to a local Logto session.
|
|
40
|
-
* Execution grants identify the actor as `actorUserId`, not `sub`.
|
|
41
|
-
*/
|
|
42
|
-
export function identityKeyFrom(input) {
|
|
43
|
-
const baseUrl = input.baseUrl ? normalizeBaseUrl(input.baseUrl) : "";
|
|
44
|
-
const defaultBaseUrl = COHUB_ENVIRONMENTS[input.env === "dev" ? "dev" : "prod"].apiBaseUrl;
|
|
45
|
-
const namespace = baseUrl && baseUrl !== defaultBaseUrl ? `${input.env}:${baseUrl}` : input.env;
|
|
46
|
-
if (input.executionToken) {
|
|
47
|
-
const actor = jwtClaim(input.executionToken, "actorUserId") ?? jwtClaim(input.executionToken, "sub");
|
|
48
|
-
return actor ? `${namespace}:${actor}` : null;
|
|
49
|
-
}
|
|
50
|
-
const sub = jwtClaim(input.idToken, "sub") ?? jwtClaim(input.accessToken, "sub");
|
|
51
|
-
return sub ? `${namespace}:${sub}` : null;
|
|
52
|
-
}
|
|
53
|
-
export function currentIdentityKey() {
|
|
54
|
-
const session = readAuthSession();
|
|
55
|
-
return identityKeyFrom({
|
|
56
|
-
env: resolveCohubEnvironment(),
|
|
57
|
-
baseUrl: resolveApiBaseUrl(),
|
|
58
|
-
executionToken: process.env.COHUB_EXECUTION_TOKEN?.trim(),
|
|
59
|
-
idToken: session?.idToken,
|
|
60
|
-
accessToken: session?.accessToken,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
/** Exported for tests; production always uses `CACHE_PATH`. */
|
|
64
|
-
export function readHomeSpaceCache(path, key, now = Date.now()) {
|
|
65
|
-
try {
|
|
66
|
-
const cache = JSON.parse(readFileSync(path, "utf-8"));
|
|
67
|
-
if (cache.key !== key || typeof cache.spaceId !== "string" || typeof cache.cachedAt !== "number")
|
|
68
|
-
return null;
|
|
69
|
-
if (now - cache.cachedAt > CACHE_TTL_MS)
|
|
70
|
-
return null;
|
|
71
|
-
return cache.spaceId;
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
function writeHomeSpaceCache(key, spaceId) {
|
|
78
|
-
try {
|
|
79
|
-
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
80
|
-
const cache = { key, spaceId, cachedAt: Date.now() };
|
|
81
|
-
writeFileSync(CACHE_PATH, `${JSON.stringify(cache, null, 2)}\n`, { encoding: "utf-8", mode: 0o600 });
|
|
82
|
-
rmSync(LEGACY_CACHE_PATH, { force: true });
|
|
83
|
-
}
|
|
84
|
-
catch {
|
|
85
|
-
// Cache is best-effort; never fail the command over it.
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
const homeSpaces = new Map();
|
|
89
|
-
const spaceRefs = new Map();
|
|
90
|
-
export function clearHomeSpaceCache() {
|
|
91
|
-
homeSpaces.clear();
|
|
92
|
-
spaceRefs.clear();
|
|
93
|
-
try {
|
|
94
|
-
rmSync(CACHE_PATH, { force: true });
|
|
95
|
-
rmSync(LEGACY_CACHE_PATH, { force: true });
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
// Best-effort, same as writes.
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
/** Explicit target from `-s/--space` (any ancestor) or `COHUB_SPACE_ID`, else null. */
|
|
102
|
-
export function explicitSpace(program) {
|
|
103
|
-
let current = program;
|
|
104
|
-
while (current) {
|
|
105
|
-
const opts = current.opts();
|
|
106
|
-
if (typeof opts.space === "string" && opts.space.trim())
|
|
107
|
-
return opts.space.trim();
|
|
108
|
-
current = current.parent ?? null;
|
|
109
|
-
}
|
|
110
|
-
return process.env.COHUB_SPACE_ID?.trim() || null;
|
|
111
|
-
}
|
|
112
|
-
/** Cached per identity and memoized per process. */
|
|
113
|
-
export function resolveHomeSpace() {
|
|
114
|
-
const key = currentIdentityKey();
|
|
115
|
-
const memoKey = key ?? resolveApiBaseUrl();
|
|
116
|
-
let resolved = homeSpaces.get(memoKey);
|
|
117
|
-
if (!resolved)
|
|
118
|
-
resolved = (async () => {
|
|
119
|
-
const cached = key ? readHomeSpaceCache(CACHE_PATH, key) : null;
|
|
120
|
-
if (cached)
|
|
121
|
-
return cached;
|
|
122
|
-
const space = await createClient().spaces.ensureHome();
|
|
123
|
-
if (key)
|
|
124
|
-
writeHomeSpaceCache(key, space.id);
|
|
125
|
-
return space.id;
|
|
126
|
-
})();
|
|
127
|
-
homeSpaces.set(memoKey, resolved);
|
|
128
|
-
return resolved;
|
|
129
|
-
}
|
|
130
|
-
async function lookupSpaceRef(value) {
|
|
131
|
-
const ref = parseSpaceRef(value);
|
|
132
|
-
if (!ref)
|
|
133
|
-
throw new SpaceTargetError(`Invalid space '${value}'`, SPACE_REF_HINT);
|
|
134
|
-
if (ref.kind === "id")
|
|
135
|
-
return ref.id;
|
|
136
|
-
if (ref.kind === "owned" && ref.slug === HOME_SPACE_SLUG)
|
|
137
|
-
return resolveHomeSpace();
|
|
138
|
-
const spaces = createClient().spaces;
|
|
139
|
-
try {
|
|
140
|
-
const space = ref.kind === "owned"
|
|
141
|
-
? await spaces.getOwnedBySlug(ref.slug)
|
|
142
|
-
: await spaces.getBySlug(ref.username, ref.slug);
|
|
143
|
-
return space.id;
|
|
144
|
-
}
|
|
145
|
-
catch (e) {
|
|
146
|
-
if (e.status === 404)
|
|
147
|
-
throw new SpaceTargetError(`Space '${value}' not found`, SPACE_REF_HINT);
|
|
148
|
-
throw e;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
export function resolveSpaceRef(value) {
|
|
152
|
-
const key = `${currentIdentityKey() ?? resolveApiBaseUrl()}:${value.trim()}`;
|
|
153
|
-
let resolved = spaceRefs.get(key);
|
|
154
|
-
if (!resolved) {
|
|
155
|
-
resolved = lookupSpaceRef(value.trim());
|
|
156
|
-
spaceRefs.set(key, resolved);
|
|
157
|
-
}
|
|
158
|
-
return resolved;
|
|
159
|
-
}
|
|
160
|
-
export function failSpaceTarget(e) {
|
|
161
|
-
if (e instanceof SpaceTargetError)
|
|
162
|
-
return error(e.message, e.detail);
|
|
163
|
-
return handleHttp(e);
|
|
164
|
-
}
|
|
165
|
-
/** Shared exit for commands that need a space but resolved none. */
|
|
166
|
-
export function missingSpaceError() {
|
|
167
|
-
return error("No target space", "Pass -s <space> (an ID, home, or username/slug), set COHUB_SPACE_ID, or run in a directory bound with `cohub runtime up`.");
|
|
168
|
-
}
|
|
169
|
-
export async function resolveBoundSpace(options = {}) {
|
|
170
|
-
const bound = await getRuntimeSpaceBinding(options.cwd ?? process.cwd(), currentIdentityKey(), options.bindingsPath).catch(handleHttp);
|
|
171
|
-
return bound?.spaceId ?? null;
|
|
172
|
-
}
|
|
173
|
-
/** Explicit target or `COHUB_SPACE_ID`, then the directory binding, then Home when allowed. */
|
|
174
|
-
export async function resolveSpaceTarget(target, options = {}) {
|
|
175
|
-
const explicit = target?.trim() || process.env.COHUB_SPACE_ID?.trim() || null;
|
|
176
|
-
try {
|
|
177
|
-
if (explicit)
|
|
178
|
-
return await resolveSpaceRef(explicit);
|
|
179
|
-
const bound = await resolveBoundSpace(options);
|
|
180
|
-
if (bound)
|
|
181
|
-
return bound;
|
|
182
|
-
if (options.home)
|
|
183
|
-
return await resolveHomeSpace();
|
|
184
|
-
}
|
|
185
|
-
catch (e) {
|
|
186
|
-
return failSpaceTarget(e);
|
|
187
|
-
}
|
|
188
|
-
return missingSpaceError();
|
|
189
|
-
}
|
|
190
|
-
export function resolveSpace(command, options = {}) {
|
|
191
|
-
return resolveSpaceTarget(explicitSpace(command), options);
|
|
192
|
-
}
|
package/dist/version.d.ts
DELETED
package/dist/version.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
export const CLI_VERSION = (() => {
|
|
3
|
-
try {
|
|
4
|
-
return JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
5
|
-
}
|
|
6
|
-
catch {
|
|
7
|
-
return "0.0.0";
|
|
8
|
-
}
|
|
9
|
-
})();
|
|
10
|
-
export function cliCommit() {
|
|
11
|
-
try {
|
|
12
|
-
return JSON.parse(readFileSync(new URL("./build.json", import.meta.url), "utf8")).commit ?? null;
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
}
|
package/dist/web.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function webUrl(path: string): string;
|
package/dist/web.js
DELETED
|
File without changes
|