@neta-art/cohub-cli 10.14.1 → 10.16.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 +3 -1
- package/dist/auth.d.ts +3 -1
- package/dist/auth.js +4 -0
- package/dist/board-export.d.ts +7 -0
- package/dist/board-export.js +3 -3
- package/dist/board-kernel.d.ts +1 -0
- package/dist/board-kernel.js +7605 -277
- package/dist/board-simulate.d.ts +53 -0
- package/dist/board-simulate.js +151 -0
- package/dist/bootstrap.js +5 -0
- package/dist/commands/auth.js +12 -1
- package/dist/commands/boards.js +68 -0
- package/dist/commands/host.d.ts +2 -0
- package/dist/commands/host.js +11 -0
- package/dist/commands/runtime.js +4 -16
- package/dist/commands/space-invitations.d.ts +3 -2
- package/dist/commands/space-invitations.js +29 -8
- package/dist/commands/spaces.js +55 -30
- package/dist/host/auth.d.ts +20 -0
- package/dist/host/auth.js +107 -0
- package/dist/host/login-env.d.ts +1 -0
- package/dist/host/login-env.js +31 -0
- package/dist/host/runtime.d.ts +25 -0
- package/dist/host/runtime.js +250 -0
- package/dist/host/runtimes.d.ts +9 -0
- package/dist/host/runtimes.js +42 -0
- package/dist/host/serve.d.ts +2 -0
- package/dist/host/serve.js +73 -0
- package/dist/index.js +2 -0
- package/dist/runtime/connection.d.ts +3 -0
- package/dist/runtime/connection.js +59 -3
- package/dist/runtime/harnesses/claude.js +8 -2
- package/dist/runtime/harnesses/index.d.ts +2 -0
- package/dist/runtime/harnesses/index.js +13 -0
- package/dist/runtime/harnesses/stream-json.d.ts +2 -2
- package/dist/runtime/harnesses/stream-json.js +5 -3
- package/dist/runtime/harnesses/types.d.ts +4 -2
- package/dist/runtime/harnesses/workbuddy.d.ts +8 -2
- package/dist/runtime/instance.d.ts +8 -1
- package/dist/runtime/instance.js +89 -9
- package/dist/runtime/launch.d.ts +1 -0
- package/dist/runtime/launch.js +6 -0
- package/dist/runtime/model-catalog.d.ts +1 -3
- package/dist/runtime/model-catalog.js +23 -7
- package/dist/runtime/supervisor.js +6 -4
- package/dist/space.d.ts +1 -0
- package/dist/space.js +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { BoardExportRegion, BoardThemeId } from "@neta-art/cohub/board";
|
|
2
|
+
import type { BoardNodeExportFormat } from "@neta-art/cohub/board/export/node";
|
|
3
|
+
import type { BoardScriptHarnessPointer } from "@neta-art/cohub/board/testing";
|
|
4
|
+
declare const TOOLS: readonly ["select", "hand", "text", "shape", "draw", "arrow", "frame"];
|
|
5
|
+
type Point = {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
};
|
|
9
|
+
export type BoardSimulationStep = {
|
|
10
|
+
wait: number;
|
|
11
|
+
} | {
|
|
12
|
+
tool: (typeof TOOLS)[number];
|
|
13
|
+
} | {
|
|
14
|
+
tap: Point;
|
|
15
|
+
input: BoardScriptHarnessPointer;
|
|
16
|
+
} | {
|
|
17
|
+
drag: Point[];
|
|
18
|
+
input: BoardScriptHarnessPointer;
|
|
19
|
+
} | {
|
|
20
|
+
pointer: "down" | "move" | "up";
|
|
21
|
+
at: Point;
|
|
22
|
+
input: BoardScriptHarnessPointer;
|
|
23
|
+
} | {
|
|
24
|
+
key: string;
|
|
25
|
+
} | {
|
|
26
|
+
select: string[];
|
|
27
|
+
};
|
|
28
|
+
export declare function parseBoardSimulationSteps(value: unknown): BoardSimulationStep[];
|
|
29
|
+
export type BoardSimulationResult = {
|
|
30
|
+
time: number;
|
|
31
|
+
commits: number;
|
|
32
|
+
changes: Record<string, unknown>;
|
|
33
|
+
errors: Record<string, string>;
|
|
34
|
+
image?: {
|
|
35
|
+
bytes: Uint8Array;
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export declare function runBoardSimulation(options: {
|
|
41
|
+
spaceId: string;
|
|
42
|
+
target: string;
|
|
43
|
+
steps: readonly BoardSimulationStep[];
|
|
44
|
+
leader: boolean;
|
|
45
|
+
image?: {
|
|
46
|
+
region: BoardExportRegion;
|
|
47
|
+
scale: number;
|
|
48
|
+
theme: BoardThemeId;
|
|
49
|
+
format: BoardNodeExportFormat;
|
|
50
|
+
withImages: boolean;
|
|
51
|
+
};
|
|
52
|
+
}): Promise<BoardSimulationResult>;
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { diffMergePatch } from "@neta-art/cohub/board";
|
|
2
|
+
import { loadBoardDocument, readSpaceFileBytes, resolveBundledFonts, runBoardExport } from "./board-export.js";
|
|
3
|
+
import { createBoardScriptHarness, createNodeBoardRenderer } from "./board-kernel.js";
|
|
4
|
+
import { settleBoardDocument } from "./board-media.js";
|
|
5
|
+
import { parseBoardTime } from "./board-time.js";
|
|
6
|
+
import { createClient } from "./client.js";
|
|
7
|
+
const TOOLS = ["select", "hand", "text", "shape", "draw", "arrow", "frame"];
|
|
8
|
+
const POINTER_TYPES = ["mouse", "pen", "touch"];
|
|
9
|
+
const MAX_STEPS = 10_000;
|
|
10
|
+
const MAX_TIME_MS = 600_000;
|
|
11
|
+
const FRAME_MS = 1000 / 60;
|
|
12
|
+
function point(value, name) {
|
|
13
|
+
if (!Array.isArray(value) || value.length !== 2 || !value.every((n) => typeof n === "number" && Number.isFinite(n)))
|
|
14
|
+
throw new Error(`${name} must be [x, y]`);
|
|
15
|
+
return { x: value[0], y: value[1] };
|
|
16
|
+
}
|
|
17
|
+
function pointerInput(step, name) {
|
|
18
|
+
const pointerType = step.pointerType ?? "mouse";
|
|
19
|
+
if (!POINTER_TYPES.includes(pointerType))
|
|
20
|
+
throw new Error(`${name}.pointerType must be one of ${POINTER_TYPES.join(", ")}`);
|
|
21
|
+
const input = { pointerType: pointerType };
|
|
22
|
+
for (const key of ["shiftKey", "altKey", "ctrlKey", "metaKey"]) {
|
|
23
|
+
if (step[key] === undefined)
|
|
24
|
+
continue;
|
|
25
|
+
if (typeof step[key] !== "boolean")
|
|
26
|
+
throw new Error(`${name}.${key} must be a boolean`);
|
|
27
|
+
input[key] = step[key];
|
|
28
|
+
}
|
|
29
|
+
return input;
|
|
30
|
+
}
|
|
31
|
+
export function parseBoardSimulationSteps(value) {
|
|
32
|
+
if (!Array.isArray(value))
|
|
33
|
+
throw new Error("steps must be an array");
|
|
34
|
+
if (value.length > MAX_STEPS)
|
|
35
|
+
throw new Error(`steps exceed the limit of ${MAX_STEPS}`);
|
|
36
|
+
const steps = value.map(parseStep);
|
|
37
|
+
const elapsed = steps.reduce((total, step) => total + ("wait" in step ? step.wait : "tap" in step ? 2 * FRAME_MS : "drag" in step ? (step.drag.length + 1) * FRAME_MS : "pointer" in step ? FRAME_MS : 0), 0);
|
|
38
|
+
if (elapsed > MAX_TIME_MS)
|
|
39
|
+
throw new Error(`steps exceed ${MAX_TIME_MS / 60_000} minutes of simulated time`);
|
|
40
|
+
return steps;
|
|
41
|
+
}
|
|
42
|
+
function parseStep(entry, index) {
|
|
43
|
+
const name = `steps[${index}]`;
|
|
44
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
45
|
+
throw new Error(`${name} must be an object`);
|
|
46
|
+
const step = entry;
|
|
47
|
+
if ("wait" in step) {
|
|
48
|
+
const wait = typeof step.wait === "number" ? step.wait : parseBoardTime(String(step.wait), `${name}.wait`);
|
|
49
|
+
if (!Number.isFinite(wait) || wait < 0)
|
|
50
|
+
throw new Error(`${name}.wait must not be negative`);
|
|
51
|
+
return { wait };
|
|
52
|
+
}
|
|
53
|
+
if ("tool" in step) {
|
|
54
|
+
if (!TOOLS.includes(step.tool))
|
|
55
|
+
throw new Error(`${name}.tool must be one of ${TOOLS.join(", ")}`);
|
|
56
|
+
return { tool: step.tool };
|
|
57
|
+
}
|
|
58
|
+
if ("tap" in step)
|
|
59
|
+
return { tap: point(step.tap, `${name}.tap`), input: pointerInput(step, name) };
|
|
60
|
+
if ("drag" in step) {
|
|
61
|
+
if (!Array.isArray(step.drag) || step.drag.length < 2)
|
|
62
|
+
throw new Error(`${name}.drag must list at least two points`);
|
|
63
|
+
return { drag: step.drag.map((entry, at) => point(entry, `${name}.drag[${at}]`)), input: pointerInput(step, name) };
|
|
64
|
+
}
|
|
65
|
+
if ("pointer" in step) {
|
|
66
|
+
if (step.pointer !== "down" && step.pointer !== "move" && step.pointer !== "up")
|
|
67
|
+
throw new Error(`${name}.pointer must be down, move or up`);
|
|
68
|
+
return { pointer: step.pointer, at: point(step.at, `${name}.at`), input: pointerInput(step, name) };
|
|
69
|
+
}
|
|
70
|
+
if ("key" in step) {
|
|
71
|
+
if (typeof step.key !== "string" || !step.key)
|
|
72
|
+
throw new Error(`${name}.key must be a key name`);
|
|
73
|
+
return { key: step.key };
|
|
74
|
+
}
|
|
75
|
+
if ("select" in step) {
|
|
76
|
+
if (!Array.isArray(step.select) || !step.select.every((id) => typeof id === "string"))
|
|
77
|
+
throw new Error(`${name}.select must list item ids`);
|
|
78
|
+
return { select: step.select };
|
|
79
|
+
}
|
|
80
|
+
throw new Error(`${name} must be one of wait, tool, tap, drag, pointer, key or select`);
|
|
81
|
+
}
|
|
82
|
+
async function run(harness, steps) {
|
|
83
|
+
for (const step of steps) {
|
|
84
|
+
if ("wait" in step)
|
|
85
|
+
await harness.advance(step.wait);
|
|
86
|
+
else if ("tool" in step)
|
|
87
|
+
harness.tool = step.tool;
|
|
88
|
+
else if ("tap" in step)
|
|
89
|
+
await harness.tap(step.tap, step.input);
|
|
90
|
+
else if ("drag" in step)
|
|
91
|
+
await harness.drag(step.drag, step.input);
|
|
92
|
+
else if ("pointer" in step)
|
|
93
|
+
await harness.pointer(step.pointer, step.at, step.input);
|
|
94
|
+
else if ("key" in step) {
|
|
95
|
+
await harness.key("keydown", step.key);
|
|
96
|
+
await harness.key("keyup", step.key);
|
|
97
|
+
}
|
|
98
|
+
else
|
|
99
|
+
await harness.select(step.select);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export async function runBoardSimulation(options) {
|
|
103
|
+
const client = createClient();
|
|
104
|
+
const document = await settleBoardDocument(options.spaceId, (await loadBoardDocument(options.spaceId, options.target)).document);
|
|
105
|
+
const renderer = await createNodeBoardRenderer({ fonts: resolveBundledFonts() });
|
|
106
|
+
const harness = await createBoardScriptHarness({
|
|
107
|
+
document,
|
|
108
|
+
renderer,
|
|
109
|
+
leader: options.leader,
|
|
110
|
+
readModule: async (path) => new TextDecoder().decode((await readSpaceFileBytes(client, options.spaceId, path)).bytes),
|
|
111
|
+
});
|
|
112
|
+
try {
|
|
113
|
+
await run(harness, options.steps);
|
|
114
|
+
await harness.flush();
|
|
115
|
+
const shown = options.image ? await harness.shown(options.image.scale) : null;
|
|
116
|
+
const errors = {};
|
|
117
|
+
for (const [id, item] of Object.entries(harness.document.items)) {
|
|
118
|
+
const message = item.script?.enabled ? harness.error(id) : null;
|
|
119
|
+
if (message)
|
|
120
|
+
errors[id] = message;
|
|
121
|
+
}
|
|
122
|
+
const result = {
|
|
123
|
+
time: Math.round(harness.time),
|
|
124
|
+
commits: harness.commits.length,
|
|
125
|
+
changes: diffMergePatch(document, harness.document) ?? {},
|
|
126
|
+
errors,
|
|
127
|
+
};
|
|
128
|
+
if (options.image && shown) {
|
|
129
|
+
const exported = await runBoardExport({
|
|
130
|
+
spaceId: options.spaceId,
|
|
131
|
+
target: options.target,
|
|
132
|
+
document: shown.document,
|
|
133
|
+
...(shown.scripts ? { scripts: shown.scripts } : {}),
|
|
134
|
+
region: options.image.region,
|
|
135
|
+
scale: options.image.scale,
|
|
136
|
+
theme: options.image.theme,
|
|
137
|
+
background: "paper",
|
|
138
|
+
format: options.image.format,
|
|
139
|
+
withImages: options.image.withImages,
|
|
140
|
+
});
|
|
141
|
+
const frame = exported?.frames[0];
|
|
142
|
+
if (frame)
|
|
143
|
+
result.image = { bytes: frame.bytes, width: frame.width, height: frame.height };
|
|
144
|
+
}
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
harness.destroy();
|
|
149
|
+
renderer.destroy();
|
|
150
|
+
}
|
|
151
|
+
}
|
package/dist/bootstrap.js
CHANGED
|
@@ -21,6 +21,11 @@ if (!isVersionRequest && shouldRelaunchWithEnvProxy()) {
|
|
|
21
21
|
}));
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
+
if (argv[0] === "host" && argv[1] === "serve" && argv.length === 2) {
|
|
25
|
+
const { serveHost } = await import("./host/serve.js");
|
|
26
|
+
await serveHost();
|
|
27
|
+
process.exit(0);
|
|
28
|
+
}
|
|
24
29
|
if (!isVersionRequest) {
|
|
25
30
|
const entrypoint = process.argv[1];
|
|
26
31
|
if (entrypoint)
|
package/dist/commands/auth.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { authSource, loginWithDeviceFlow, readAuthSession, refreshAccessToken, requestDeviceCode, revokeAndClearAuthSession, verifyDeviceCode } from "../auth.js";
|
|
1
|
+
import { authSource, loginWithDeviceFlow, readAuthSession, refreshAccessToken, requestDeviceCode, requireAccessToken, revokeAndClearAuthSession, verifyDeviceCode } from "../auth.js";
|
|
2
2
|
import { clearHomeSpaceCache } from "../space.js";
|
|
3
3
|
import { createClient } from "../client.js";
|
|
4
4
|
import { table, json as outJson, jsonRequested, ok, error, spinner, handleHttp } from "../output.js";
|
|
@@ -48,6 +48,17 @@ export function registerAuth(program) {
|
|
|
48
48
|
const asJson = jsonRequested(opts);
|
|
49
49
|
return showSignedIn(asJson);
|
|
50
50
|
});
|
|
51
|
+
auth
|
|
52
|
+
.command("token")
|
|
53
|
+
.description("Print a valid access token, refreshing it when needed")
|
|
54
|
+
.action(async () => {
|
|
55
|
+
try {
|
|
56
|
+
process.stdout.write(`${await requireAccessToken()}\n`);
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
handleHttp(e);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
51
62
|
auth
|
|
52
63
|
.command("refresh")
|
|
53
64
|
.description("Refresh the stored Logto access token")
|
package/dist/commands/boards.js
CHANGED
|
@@ -298,6 +298,73 @@ Examples:
|
|
|
298
298
|
}
|
|
299
299
|
});
|
|
300
300
|
}
|
|
301
|
+
function registerSimulateCommand(boards) {
|
|
302
|
+
withJson(boards.command("simulate <board> [steps]")
|
|
303
|
+
.description("Run a Board's scripts locally through input steps; nothing is saved")
|
|
304
|
+
.option("-i, --input <file>", "Steps JSON; - for stdin")
|
|
305
|
+
.option("-o, --out <file>", "Also render the result, screen UI included; the extension picks the format")
|
|
306
|
+
.option("--follower", "Simulate an editor that does not write autonomous commits")
|
|
307
|
+
.option("--frame <item-id>", "Render one frame")
|
|
308
|
+
.option("--items <ids>", "Render comma-separated item ids")
|
|
309
|
+
.option("--rect <rect>", "Render a world rect as x,y,width,height")
|
|
310
|
+
.option("--scale <factor>", "Output pixels per board unit", "2")
|
|
311
|
+
.option("--theme <name>", `Cohub theme: ${BOARD_THEME_IDS.join(", ")}`, "dark")
|
|
312
|
+
.option("--no-images", "Draw placeholders instead of downloading images")
|
|
313
|
+
.option("--force", "Replace an existing output file"))
|
|
314
|
+
.addHelpText("after", `
|
|
315
|
+
Steps are {"steps": [...]}, points in board coordinates, run on a virtual clock:
|
|
316
|
+
{"wait": "500ms"} {"tool": "draw"} {"tap": [x, y]} {"drag": [[x, y], ...], "pointerType": "pen"}
|
|
317
|
+
{"pointer": "down", "at": [x, y]} {"key": "Enter"} {"select": ["id"]}
|
|
318
|
+
|
|
319
|
+
Examples:
|
|
320
|
+
cohub boards simulate farm.board '{"steps":[{"wait":"2s"}]}' -o farm.png
|
|
321
|
+
cohub boards simulate farm.board -i steps.json --json`)
|
|
322
|
+
.action(async (target, inline, options) => {
|
|
323
|
+
try {
|
|
324
|
+
if (inline !== undefined && options.input !== undefined)
|
|
325
|
+
throw new Error("Pass steps inline or with --input, not both.");
|
|
326
|
+
const input = inline !== undefined
|
|
327
|
+
? parseBoardJsonObject(inline, "steps")
|
|
328
|
+
: options.input !== undefined ? await readBoardJsonObject(options.input) : { steps: [] };
|
|
329
|
+
const { parseBoardSimulationSteps, runBoardSimulation } = await import("../board-simulate.js");
|
|
330
|
+
const steps = parseBoardSimulationSteps(input.steps);
|
|
331
|
+
const out = options.out;
|
|
332
|
+
if (out && !options.force && existsSync(out))
|
|
333
|
+
throw new Error(`${out} already exists; use --force to replace it.`);
|
|
334
|
+
const result = await runBoardSimulation({
|
|
335
|
+
spaceId: await resolveSpace(boards),
|
|
336
|
+
target,
|
|
337
|
+
steps,
|
|
338
|
+
leader: !options.follower,
|
|
339
|
+
...(out ? { image: {
|
|
340
|
+
region: parseExportRegion(options),
|
|
341
|
+
scale: parseNumber(options.scale ?? "2", "--scale", { min: 0.01, max: 16 }),
|
|
342
|
+
theme: parseChoice(options.theme, "--theme", BOARD_THEME_IDS),
|
|
343
|
+
format: parseExportFormat(options, out),
|
|
344
|
+
withImages: options.images !== false,
|
|
345
|
+
} } : {}),
|
|
346
|
+
});
|
|
347
|
+
if (out && result.image) {
|
|
348
|
+
await mkdir(dirname(out), { recursive: true });
|
|
349
|
+
await writeBoardOutput(out, result.image.bytes, Boolean(options.force));
|
|
350
|
+
}
|
|
351
|
+
const { image, ...summary } = result;
|
|
352
|
+
if (jsonRequested(options))
|
|
353
|
+
return outJson({ ...summary, ...(out && image ? { file: out, width: image.width, height: image.height } : {}) });
|
|
354
|
+
const changed = Object.keys(result.changes.items ?? {}).length;
|
|
355
|
+
ok(`Simulated ${formatBoardTime(result.time)}: ${result.commits} commit${result.commits === 1 ? "" : "s"}, ${changed} item${changed === 1 ? "" : "s"} changed (not saved)`);
|
|
356
|
+
for (const [id, message] of Object.entries(result.errors))
|
|
357
|
+
console.log(` ! ${id}: ${message.split("\n")[0]}`);
|
|
358
|
+
if (out && image)
|
|
359
|
+
console.log(` Rendered ${image.width}×${image.height} to ${out}`);
|
|
360
|
+
else if (out)
|
|
361
|
+
console.log(" ! Nothing to render: the region contains no items.");
|
|
362
|
+
}
|
|
363
|
+
catch (cause) {
|
|
364
|
+
handleHttp(cause);
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
}
|
|
301
368
|
// ─── Commands ────────────────────────────────────────────────────────────────
|
|
302
369
|
export function registerBoards(program) {
|
|
303
370
|
const boards = program
|
|
@@ -535,6 +602,7 @@ Presets: ${BOARD_PRESET_NAMES.join(", ")}
|
|
|
535
602
|
});
|
|
536
603
|
registerBoardExampleCommands(boards);
|
|
537
604
|
registerExportCommand(boards);
|
|
605
|
+
registerSimulateCommand(boards);
|
|
538
606
|
registerBoardAuthoringCommands(boards);
|
|
539
607
|
registerPlaybackCommands(boards);
|
|
540
608
|
withJson(boards.command("watch <board>")
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function registerHost(program) {
|
|
2
|
+
program
|
|
3
|
+
.command("host", { hidden: true })
|
|
4
|
+
.description("Machine interface for native desktop hosts")
|
|
5
|
+
.command("serve")
|
|
6
|
+
.description("Answer host bridge requests over stdio, one JSON message per line")
|
|
7
|
+
.action(async () => {
|
|
8
|
+
const { serveHost } = await import("../host/serve.js");
|
|
9
|
+
await serveHost();
|
|
10
|
+
});
|
|
11
|
+
}
|
package/dist/commands/runtime.js
CHANGED
|
@@ -10,7 +10,8 @@ import { RuntimeArchiveStore } from "../runtime/archive-store.js";
|
|
|
10
10
|
import { readNativeConfig, runtimeStateRoot, writeNativeConfig } from "../runtime/native/config.js";
|
|
11
11
|
import { MAX_IMPORT_CONCURRENCY, DEFAULT_IMPORT_CONCURRENCY } from "../runtime/native/ingest.js";
|
|
12
12
|
import { installPiExtension, piExtensionState } from "../runtime/native/install.js";
|
|
13
|
-
import { controlRuntimeInstance, requestRuntimeInstance, runtimeInstanceDirectory } from "../runtime/instance.js";
|
|
13
|
+
import { controlRuntimeInstance, requestRuntimeInstance, runtimeInstanceDirectory, stopRuntimeInstance } from "../runtime/instance.js";
|
|
14
|
+
import { forgetHostRuntime } from "../host/runtimes.js";
|
|
14
15
|
import { atLeastLevel, diagnosticLevels, formatDiagnostic, formatImportProgress, formatNativeSync, printRuntimeSummary } from "../runtime/presentation.js";
|
|
15
16
|
import { readRuntimeDiagnosticEvents, RuntimeDiagnosticReader, runtimeDiagnosticsDirectory, serializeDiagnosticError } from "../runtime/diagnostics.js";
|
|
16
17
|
export { resolveLocalSpaceName, parseRuntimeDisplay, parseRuntimeHarnesses } from "../runtime/launch.js";
|
|
@@ -256,21 +257,8 @@ export function registerRuntime(program) {
|
|
|
256
257
|
const identity = currentIdentityKey();
|
|
257
258
|
if (!identity)
|
|
258
259
|
throw new Error("Sign in to the Runtime account");
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
const until = Date.now() + 15_000;
|
|
262
|
-
let running = Boolean(local);
|
|
263
|
-
while (running && Date.now() < until) {
|
|
264
|
-
await delay(250);
|
|
265
|
-
try {
|
|
266
|
-
running = Boolean(await requestRuntimeInstance(directory));
|
|
267
|
-
}
|
|
268
|
-
catch {
|
|
269
|
-
running = true;
|
|
270
|
-
} // An unreachable control socket does not prove the process stopped.
|
|
271
|
-
}
|
|
272
|
-
if (running)
|
|
273
|
-
throw new Error("Runtime is still stopping; inspect logs");
|
|
260
|
+
const local = await stopRuntimeInstance(runtimeInstanceDirectory(identity, spaceId), Boolean(options.yes));
|
|
261
|
+
await forgetHostRuntime(identity, spaceId).catch((cause) => process.stderr.write(`Desktop app may reconnect this folder: ${serializeDiagnosticError(cause).message}\n`));
|
|
274
262
|
if (jsonRequested(options))
|
|
275
263
|
outJson({ spaceId, stopped: true });
|
|
276
264
|
else {
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { type CreateInvitationInput, type CreateInvitationResponse, type SpaceInvitationListResponse } from "@neta-art/cohub";
|
|
1
|
+
import { type CreateInvitationInput, type CreateInvitationResponse, type SpaceInvitationListOptions, type SpaceInvitationListResponse } from "@neta-art/cohub";
|
|
2
2
|
import type { Command } from "commander";
|
|
3
3
|
export type SpaceInvitationCreateCliOptions = {
|
|
4
4
|
role?: string;
|
|
5
5
|
days?: string;
|
|
6
|
+
neverExpires?: boolean;
|
|
6
7
|
maxUses?: string;
|
|
7
8
|
json?: boolean;
|
|
8
9
|
};
|
|
9
10
|
type SpaceInvitationCommandClient = {
|
|
10
11
|
space(spaceId: string): {
|
|
11
12
|
invitations: {
|
|
12
|
-
list(): Promise<SpaceInvitationListResponse>;
|
|
13
|
+
list(options?: SpaceInvitationListOptions): Promise<SpaceInvitationListResponse>;
|
|
13
14
|
create(input: CreateInvitationInput): Promise<CreateInvitationResponse>;
|
|
14
15
|
revoke(token: string): Promise<{
|
|
15
16
|
ok: true;
|
|
@@ -30,10 +30,31 @@ export function parseSpaceInvitationCreateOptions(options) {
|
|
|
30
30
|
if (!SPACE_ROLES.includes(role)) {
|
|
31
31
|
throw new InvalidSpaceInvitationCliOptionsError("Invalid role", `Use one of: ${SPACE_ROLES.join(", ")}`);
|
|
32
32
|
}
|
|
33
|
-
const days = parseInteger(options.days ?? String(DEFAULT_DAYS), "days", 1, MAX_DAYS);
|
|
34
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);
|
|
35
44
|
return { role, ttlSeconds: days * 24 * 60 * 60, maxUses };
|
|
36
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
|
+
}
|
|
37
58
|
function invitationUrl(invitation) {
|
|
38
59
|
return webUrl(buildSpaceInvitePath({
|
|
39
60
|
spaceId: invitation.spaceId,
|
|
@@ -68,7 +89,8 @@ export function registerSpaceInvitations(spacesCommand, dependencies = {
|
|
|
68
89
|
.command("create")
|
|
69
90
|
.description("Create an invite link")
|
|
70
91
|
.option("--role <role>", "Member role: host, builder, or guest", "builder")
|
|
71
|
-
.option("--days <days>",
|
|
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)")
|
|
72
94
|
.option("--max-uses <count>", "Usage limit, or 0 for unlimited", "0")
|
|
73
95
|
.option("--json", "Output as JSON")
|
|
74
96
|
.action(async (options) => {
|
|
@@ -108,15 +130,13 @@ export function registerSpaceInvitations(spacesCommand, dependencies = {
|
|
|
108
130
|
invitations
|
|
109
131
|
.command("ls")
|
|
110
132
|
.alias("list")
|
|
111
|
-
.description("List invite links")
|
|
133
|
+
.description("List active invite links")
|
|
134
|
+
.option("--all", "Include revoked, exhausted, and expired links")
|
|
112
135
|
.option("--json", "Output as JSON")
|
|
113
136
|
.action(async (options) => {
|
|
114
137
|
const spaceId = await resolveSpace(spacesCommand);
|
|
115
138
|
try {
|
|
116
|
-
const result = await dependencies
|
|
117
|
-
.createClient()
|
|
118
|
-
.space(spaceId)
|
|
119
|
-
.invitations.list();
|
|
139
|
+
const result = await listAllInvitations(dependencies.createClient().space(spaceId).invitations, options.all ? "all" : "active");
|
|
120
140
|
const items = result.items.map((item) => ({
|
|
121
141
|
...item,
|
|
122
142
|
url: invitationUrl({
|
|
@@ -127,6 +147,7 @@ export function registerSpaceInvitations(spacesCommand, dependencies = {
|
|
|
127
147
|
spaceSlug: result.spaceSlug ?? null,
|
|
128
148
|
}),
|
|
129
149
|
uses: item.maxUses ? `${item.useCount}/${item.maxUses}` : String(item.useCount),
|
|
150
|
+
expires: item.expiresAt ?? "never",
|
|
130
151
|
}));
|
|
131
152
|
if (jsonRequested(options))
|
|
132
153
|
return outJson({ ...result, items });
|
|
@@ -135,7 +156,7 @@ export function registerSpaceInvitations(spacesCommand, dependencies = {
|
|
|
135
156
|
{ key: "role", label: "Role" },
|
|
136
157
|
{ key: "status", label: "Status" },
|
|
137
158
|
{ key: "uses", label: "Uses" },
|
|
138
|
-
{ key: "
|
|
159
|
+
{ key: "expires", label: "Expires" },
|
|
139
160
|
{ key: "url", label: "URL" },
|
|
140
161
|
]);
|
|
141
162
|
}
|