@yolo-labs/yolo-cli 0.43.0 → 0.44.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 +51 -42
- package/dist/artifact-get.js +2 -9
- package/dist/cli.js +24 -126
- package/dist/deploy-client.js +10 -20
- package/dist/deploy-config.js +2 -3
- package/dist/exit.js +34 -0
- package/dist/kanban-cli.js +352 -0
- package/dist/preview.js +145 -0
- package/dist/tileapp-oci-assembler.js +2 -2
- package/dist/tileapp-validator.js +6 -0
- package/dist/work-client.js +11 -60
- package/package.json +4 -7
- package/dist/canonicalizer.js +0 -208
- package/dist/lockfile.js +0 -203
- package/dist/plan-frontmatter.schema.json +0 -191
- package/dist/plan-validate.js +0 -270
- package/dist/revision.js +0 -43
- package/dist/run-list.js +0 -148
- package/dist/webapp-url.js +0 -61
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `yolo kanban export` / `yolo kanban import` — move a board seed document
|
|
3
|
+
* between a workspace and a file, with no model in the loop.
|
|
4
|
+
*
|
|
5
|
+
* A board lives in Mongo, scoped to a workspace that can wedge. The seed
|
|
6
|
+
* document (`common-api/src/services/kanban-board-seed.ts`) is the only copy
|
|
7
|
+
* of a card graph that survives the workspace it was built in, and the card
|
|
8
|
+
* descriptions it carries are verbatim dispatch contracts — thousands of
|
|
9
|
+
* bytes of them. Re-emitting those by hand through a chat transcript is how a
|
|
10
|
+
* recovery silently loses a paragraph. These two verbs make the path
|
|
11
|
+
* mechanical: bytes off the wire onto disk, bytes off disk onto the wire.
|
|
12
|
+
*
|
|
13
|
+
* Two properties this module deliberately does NOT have:
|
|
14
|
+
*
|
|
15
|
+
* - **It does not know the seed format.** The format has exactly one owner,
|
|
16
|
+
* server-side. `export` writes the response body unmodified; `import`
|
|
17
|
+
* sends the file unparsed apart from a `JSON.parse` that catches a
|
|
18
|
+
* truncated file before it becomes an HTTP 400. A serializer here and a
|
|
19
|
+
* parser there would drift, and the drift would only surface during a
|
|
20
|
+
* recovery — the worst possible moment.
|
|
21
|
+
* - **It has no MCP surface and needs no new scope.** These are the
|
|
22
|
+
* user-token REST routes in `common-api/src/routes/kanban.ts`, which is
|
|
23
|
+
* what makes them operator-only — the same policy board create/delete
|
|
24
|
+
* already follow (`vibe-mcp-client.ts`). So this goes through
|
|
25
|
+
* `userRouteRequest` (the USER-token helper), not `authenticatedRequest`,
|
|
26
|
+
* and never mints a delegated token.
|
|
27
|
+
*
|
|
28
|
+
* Exit codes (as `artifact-list.ts` documents them):
|
|
29
|
+
* - 0 = success
|
|
30
|
+
* - 1 = http (server error, including a 409 key collision)
|
|
31
|
+
* - 64 = usage (missing env, unreadable file, refusing to overwrite,
|
|
32
|
+
* `--workspace` mismatch)
|
|
33
|
+
*/
|
|
34
|
+
import * as fs from 'node:fs';
|
|
35
|
+
import { userRouteRequest } from './work-client.js';
|
|
36
|
+
import { resolveSubstrateContext } from './auth-context.js';
|
|
37
|
+
// ─── export ───────────────────────────────────────────────────────────────
|
|
38
|
+
export async function runKanbanExport(options) {
|
|
39
|
+
const env = options.env ?? process.env;
|
|
40
|
+
if (!options.tileId)
|
|
41
|
+
return fail('usage', 'a tileId is required');
|
|
42
|
+
const resolved = resolveContext(env, options.workspaceFlag);
|
|
43
|
+
if (!resolved.ok)
|
|
44
|
+
return resolved.failure;
|
|
45
|
+
const { commonApiUrl, userToken, workspaceId } = resolved;
|
|
46
|
+
// Refuse an occupied destination BEFORE the request, not after. An export
|
|
47
|
+
// is reached for when a workspace is already in trouble; spending the round
|
|
48
|
+
// trip only to discard the one readable copy of the board would be the
|
|
49
|
+
// wrong half of the operation to get right.
|
|
50
|
+
if (options.outFile && fs.existsSync(options.outFile)) {
|
|
51
|
+
return fail('usage', `refusing to overwrite existing file '${options.outFile}'; pick another path or remove it first`);
|
|
52
|
+
}
|
|
53
|
+
const path = `/workspaces/${encodeURIComponent(workspaceId)}/kanban/boards/${encodeURIComponent(options.tileId)}/seed`;
|
|
54
|
+
let response;
|
|
55
|
+
try {
|
|
56
|
+
response = await userRouteRequest({ commonApiUrl, userToken, fetchImpl: options.fetchImpl }, path, {
|
|
57
|
+
method: 'GET',
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
return fail('http', `kanban.board.seed.export failed: ${describeError(err)}`);
|
|
62
|
+
}
|
|
63
|
+
const body = await safeReadText(response);
|
|
64
|
+
if (!response.ok) {
|
|
65
|
+
return fail('http', `kanban.board.seed.export failed: HTTP ${response.status} — ${body}`, {
|
|
66
|
+
status: response.status,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (!options.outFile) {
|
|
70
|
+
return { ok: true, output: body, raw: true, workspaceId };
|
|
71
|
+
}
|
|
72
|
+
const write = options.writeFileImpl ?? defaultWriteFileExclusive;
|
|
73
|
+
try {
|
|
74
|
+
write(options.outFile, body);
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
if (isEexist(err)) {
|
|
78
|
+
return fail('usage', `refusing to overwrite existing file '${options.outFile}'; pick another path or remove it first`);
|
|
79
|
+
}
|
|
80
|
+
return fail('usage', `could not write '${options.outFile}': ${describeError(err)}`);
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
ok: true,
|
|
84
|
+
output: `Wrote ${Buffer.byteLength(body, 'utf-8')} bytes to ${options.outFile}`,
|
|
85
|
+
raw: false,
|
|
86
|
+
workspaceId,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
// ─── import ───────────────────────────────────────────────────────────────
|
|
90
|
+
export async function runKanbanImport(options) {
|
|
91
|
+
const env = options.env ?? process.env;
|
|
92
|
+
if (!options.boardId)
|
|
93
|
+
return fail('usage', 'a boardId is required');
|
|
94
|
+
if (!options.file)
|
|
95
|
+
return fail('usage', 'a seed document path is required');
|
|
96
|
+
const resolved = resolveContext(env, options.workspaceFlag);
|
|
97
|
+
if (!resolved.ok)
|
|
98
|
+
return resolved.failure;
|
|
99
|
+
const { commonApiUrl, userToken, workspaceId } = resolved;
|
|
100
|
+
const read = options.readFileImpl ?? defaultReadFile;
|
|
101
|
+
let contents;
|
|
102
|
+
try {
|
|
103
|
+
contents = read(options.file);
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
return fail('usage', `could not read '${options.file}': ${describeError(err)}`);
|
|
107
|
+
}
|
|
108
|
+
// The ONLY inspection of the document on this side. It catches a truncated
|
|
109
|
+
// or half-pasted file locally, where the message can name the file. Every
|
|
110
|
+
// other rule about what a seed means — keys, dependsOn, columns, cycles —
|
|
111
|
+
// belongs to the server, which reports all of them at once.
|
|
112
|
+
try {
|
|
113
|
+
JSON.parse(contents);
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
return fail('usage', `'${options.file}' is not valid JSON: ${describeError(err)}`);
|
|
117
|
+
}
|
|
118
|
+
const path = `/workspaces/${encodeURIComponent(workspaceId)}/kanban/boards/${encodeURIComponent(options.boardId)}/seed`;
|
|
119
|
+
let response;
|
|
120
|
+
try {
|
|
121
|
+
response = await userRouteRequest({ commonApiUrl, userToken, fetchImpl: options.fetchImpl }, path, {
|
|
122
|
+
method: 'POST',
|
|
123
|
+
// Verbatim: what the server validates is the file on disk, not a
|
|
124
|
+
// re-serialization of it.
|
|
125
|
+
rawBody: contents,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
return fail('http', `kanban.board.seed.import failed: ${describeError(err)}`);
|
|
130
|
+
}
|
|
131
|
+
const body = await safeReadText(response);
|
|
132
|
+
if (!response.ok) {
|
|
133
|
+
// A 409 names every colliding key. Pass the server's words through
|
|
134
|
+
// unedited — an operator paraphrased at this point has to bisect the
|
|
135
|
+
// document by hand to find out which card is already there.
|
|
136
|
+
return fail('http', `kanban.board.seed.import failed: HTTP ${response.status} — ${body}`, {
|
|
137
|
+
status: response.status,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
ok: true,
|
|
142
|
+
output: formatImportSummary(body, options.boardId),
|
|
143
|
+
raw: false,
|
|
144
|
+
workspaceId,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* `key → cardId`, one per line, under a count. That map is what a caller
|
|
149
|
+
* needs to say anything at all about the board it just rebuilt, and it is
|
|
150
|
+
* the only part of the response worth reading by eye.
|
|
151
|
+
*/
|
|
152
|
+
export function formatImportSummary(body, boardId) {
|
|
153
|
+
let parsed;
|
|
154
|
+
try {
|
|
155
|
+
parsed = JSON.parse(body);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return `Imported seed into board ${boardId}`;
|
|
159
|
+
}
|
|
160
|
+
const keyToCardId = parsed?.keyToCardId ?? {};
|
|
161
|
+
const keys = Object.keys(keyToCardId);
|
|
162
|
+
const count = Array.isArray(parsed?.cards) ? parsed.cards.length : keys.length;
|
|
163
|
+
const lines = [`Imported ${count} card${count === 1 ? '' : 's'} into board ${boardId}`];
|
|
164
|
+
if (keys.length > 0) {
|
|
165
|
+
const keyCol = Math.max(...keys.map((k) => k.length));
|
|
166
|
+
for (const key of keys)
|
|
167
|
+
lines.push(` ${key.padEnd(keyCol)} ${keyToCardId[key]}`);
|
|
168
|
+
}
|
|
169
|
+
return lines.join('\n');
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Auth first, so a missing token reports the message `resolveSubstrateContext`
|
|
173
|
+
* already writes (which names both places a token can live) rather than a
|
|
174
|
+
* workspace complaint that would send an operator looking in the wrong place.
|
|
175
|
+
*/
|
|
176
|
+
function resolveContext(env, workspaceFlag) {
|
|
177
|
+
const auth = resolveSubstrateContext(env);
|
|
178
|
+
if (!auth.ok)
|
|
179
|
+
return { ok: false, failure: fail('auth', auth.message) };
|
|
180
|
+
const { commonApiUrl, userToken } = auth.context;
|
|
181
|
+
const sessionWorkspace = env.WORKSPACE_ID?.trim() || undefined;
|
|
182
|
+
if (workspaceFlag && sessionWorkspace && workspaceFlag !== sessionWorkspace) {
|
|
183
|
+
return {
|
|
184
|
+
ok: false,
|
|
185
|
+
failure: fail('workspace_mismatch', `--workspace ${workspaceFlag} does not match the workspace bound to this session (${sessionWorkspace}).`),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
const workspaceId = workspaceFlag ?? sessionWorkspace;
|
|
189
|
+
if (!workspaceId) {
|
|
190
|
+
return {
|
|
191
|
+
ok: false,
|
|
192
|
+
failure: fail('usage', 'no workspace: WORKSPACE_ID is unset in this session — pass --workspace <workspaceId>'),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
return { ok: true, commonApiUrl, userToken, workspaceId };
|
|
196
|
+
}
|
|
197
|
+
// ─── CLI surface ──────────────────────────────────────────────────────────
|
|
198
|
+
const EXPORT_USAGE = 'Usage: yolo kanban export <tileId> [-o <file>] [--workspace <wsId>]\n';
|
|
199
|
+
const IMPORT_USAGE = 'Usage: yolo kanban import <boardId> <file> [--workspace <wsId>]\n';
|
|
200
|
+
export function parseKanbanExportArgs(args) {
|
|
201
|
+
let tileId;
|
|
202
|
+
let outFile;
|
|
203
|
+
let workspaceFlag;
|
|
204
|
+
for (let i = 0; i < args.length; i++) {
|
|
205
|
+
const a = args[i];
|
|
206
|
+
if (a === '--workspace' || a === '-o' || a === '--out') {
|
|
207
|
+
const v = args[++i];
|
|
208
|
+
if (!v || v.startsWith('--'))
|
|
209
|
+
return { ok: false, message: `${a} requires a value` };
|
|
210
|
+
if (a === '--workspace')
|
|
211
|
+
workspaceFlag = v;
|
|
212
|
+
else
|
|
213
|
+
outFile = v;
|
|
214
|
+
}
|
|
215
|
+
else if (a.startsWith('--workspace=')) {
|
|
216
|
+
const v = a.slice('--workspace='.length);
|
|
217
|
+
if (!v)
|
|
218
|
+
return { ok: false, message: '--workspace requires a value' };
|
|
219
|
+
workspaceFlag = v;
|
|
220
|
+
}
|
|
221
|
+
else if (a.startsWith('--out=')) {
|
|
222
|
+
const v = a.slice('--out='.length);
|
|
223
|
+
if (!v)
|
|
224
|
+
return { ok: false, message: '--out requires a value' };
|
|
225
|
+
outFile = v;
|
|
226
|
+
}
|
|
227
|
+
else if (a.startsWith('-')) {
|
|
228
|
+
return { ok: false, message: `unknown option: ${a}` };
|
|
229
|
+
}
|
|
230
|
+
else if (tileId === undefined) {
|
|
231
|
+
tileId = a;
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
return { ok: false, message: `unexpected positional argument: ${a}` };
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (!tileId)
|
|
238
|
+
return { ok: false, message: 'a <tileId> is required' };
|
|
239
|
+
return { ok: true, tileId, outFile, workspaceFlag };
|
|
240
|
+
}
|
|
241
|
+
export function parseKanbanImportArgs(args) {
|
|
242
|
+
const positional = [];
|
|
243
|
+
let workspaceFlag;
|
|
244
|
+
for (let i = 0; i < args.length; i++) {
|
|
245
|
+
const a = args[i];
|
|
246
|
+
if (a === '--workspace') {
|
|
247
|
+
const v = args[++i];
|
|
248
|
+
if (!v || v.startsWith('--'))
|
|
249
|
+
return { ok: false, message: '--workspace requires a value' };
|
|
250
|
+
workspaceFlag = v;
|
|
251
|
+
}
|
|
252
|
+
else if (a.startsWith('--workspace=')) {
|
|
253
|
+
const v = a.slice('--workspace='.length);
|
|
254
|
+
if (!v)
|
|
255
|
+
return { ok: false, message: '--workspace requires a value' };
|
|
256
|
+
workspaceFlag = v;
|
|
257
|
+
}
|
|
258
|
+
else if (a.startsWith('-')) {
|
|
259
|
+
return { ok: false, message: `unknown option: ${a}` };
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
positional.push(a);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (positional.length < 2)
|
|
266
|
+
return { ok: false, message: 'a <boardId> and a <file> are required' };
|
|
267
|
+
if (positional.length > 2)
|
|
268
|
+
return { ok: false, message: `unexpected positional argument: ${positional[2]}` };
|
|
269
|
+
return { ok: true, boardId: positional[0], file: positional[1], workspaceFlag };
|
|
270
|
+
}
|
|
271
|
+
/** `args` is everything after `kanban`. */
|
|
272
|
+
export async function runKanbanCmd(args) {
|
|
273
|
+
const sub = args[0];
|
|
274
|
+
if (sub === 'export') {
|
|
275
|
+
const parsed = parseKanbanExportArgs(args.slice(1));
|
|
276
|
+
if (!parsed.ok) {
|
|
277
|
+
process.stderr.write(`yolo: kanban export: ${parsed.message}\n`);
|
|
278
|
+
process.stderr.write(EXPORT_USAGE);
|
|
279
|
+
return 64;
|
|
280
|
+
}
|
|
281
|
+
return report(await runKanbanExport({
|
|
282
|
+
tileId: parsed.tileId,
|
|
283
|
+
outFile: parsed.outFile,
|
|
284
|
+
workspaceFlag: parsed.workspaceFlag,
|
|
285
|
+
}));
|
|
286
|
+
}
|
|
287
|
+
if (sub === 'import') {
|
|
288
|
+
const parsed = parseKanbanImportArgs(args.slice(1));
|
|
289
|
+
if (!parsed.ok) {
|
|
290
|
+
process.stderr.write(`yolo: kanban import: ${parsed.message}\n`);
|
|
291
|
+
process.stderr.write(IMPORT_USAGE);
|
|
292
|
+
return 64;
|
|
293
|
+
}
|
|
294
|
+
return report(await runKanbanImport({
|
|
295
|
+
boardId: parsed.boardId,
|
|
296
|
+
file: parsed.file,
|
|
297
|
+
workspaceFlag: parsed.workspaceFlag,
|
|
298
|
+
}));
|
|
299
|
+
}
|
|
300
|
+
if (!sub) {
|
|
301
|
+
process.stderr.write('yolo: kanban requires a subcommand (export, import)\n');
|
|
302
|
+
return 64;
|
|
303
|
+
}
|
|
304
|
+
process.stderr.write(`yolo: unknown kanban subcommand '${sub}'\n`);
|
|
305
|
+
process.stderr.write('Subcommands: export, import\n');
|
|
306
|
+
return 64;
|
|
307
|
+
}
|
|
308
|
+
function report(result) {
|
|
309
|
+
if (result.ok) {
|
|
310
|
+
// `raw` output is the document: no trailing newline, so a redirect or a
|
|
311
|
+
// pipe gets the same bytes `-o` would have written.
|
|
312
|
+
process.stdout.write(result.raw ? result.output : `${result.output}\n`);
|
|
313
|
+
return 0;
|
|
314
|
+
}
|
|
315
|
+
process.stderr.write(`FAIL [${result.kind}]: ${result.message}\n`);
|
|
316
|
+
return exitCodeForFailure(result.kind);
|
|
317
|
+
}
|
|
318
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────
|
|
319
|
+
function fail(kind, message, detail) {
|
|
320
|
+
return { ok: false, kind, message, detail };
|
|
321
|
+
}
|
|
322
|
+
function describeError(err) {
|
|
323
|
+
return err instanceof Error ? err.message : String(err);
|
|
324
|
+
}
|
|
325
|
+
async function safeReadText(response) {
|
|
326
|
+
try {
|
|
327
|
+
return await response.text();
|
|
328
|
+
}
|
|
329
|
+
catch {
|
|
330
|
+
return '<no body>';
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
function isEexist(err) {
|
|
334
|
+
return typeof err === 'object' && err !== null && err.code === 'EEXIST';
|
|
335
|
+
}
|
|
336
|
+
/** `wx` so the refusal is the filesystem's, not a check racing the write. */
|
|
337
|
+
function defaultWriteFileExclusive(filePath, contents) {
|
|
338
|
+
fs.writeFileSync(filePath, contents, { encoding: 'utf-8', flag: 'wx' });
|
|
339
|
+
}
|
|
340
|
+
function defaultReadFile(filePath) {
|
|
341
|
+
return fs.readFileSync(filePath, 'utf-8');
|
|
342
|
+
}
|
|
343
|
+
export function exitCodeForFailure(kind) {
|
|
344
|
+
switch (kind) {
|
|
345
|
+
case 'usage':
|
|
346
|
+
case 'auth':
|
|
347
|
+
case 'workspace_mismatch':
|
|
348
|
+
return 64;
|
|
349
|
+
case 'http':
|
|
350
|
+
return 1;
|
|
351
|
+
}
|
|
352
|
+
}
|
package/dist/preview.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/** Session-bound CLI for the workspace-owned branch preview service. */
|
|
2
|
+
import { resolveSubstrateContext } from './auth-context.js';
|
|
3
|
+
import { mintSubstrateToken } from './work-client.js';
|
|
4
|
+
export const PREVIEW_HELP = `Usage:
|
|
5
|
+
yolo preview create --name <name> --branch <branch> --command <command> [options]
|
|
6
|
+
yolo preview status [tile-id] [--json]
|
|
7
|
+
yolo preview logs <tile-id> [--tail 50] [--json]
|
|
8
|
+
yolo preview stop <tile-id> [--json]
|
|
9
|
+
|
|
10
|
+
Create options:
|
|
11
|
+
--cwd <dir> Repository-relative app directory (default: .)
|
|
12
|
+
--setup <command> Install dependencies in each candidate checkout
|
|
13
|
+
--build <command> Build each candidate
|
|
14
|
+
--health-path <path> Readiness endpoint (default: /)
|
|
15
|
+
--port <auto|number> Public preview port (default: auto)
|
|
16
|
+
--poll-seconds <n> Branch polling interval, 5..3600 (default: 30)
|
|
17
|
+
--timeout-seconds <n> Setup/build timeout, 1..1800 (default: 300)
|
|
18
|
+
--ready-seconds <n> Server readiness timeout, 1..300 (default: 60)
|
|
19
|
+
--wait-for <path> Repository-relative file to wait for on the branch
|
|
20
|
+
before checkout/build (e.g. app/package.json)
|
|
21
|
+
--request-id <id> Reuse for retrying the same create request
|
|
22
|
+
--desktop <id> Destination desktop
|
|
23
|
+
--json Print structured output
|
|
24
|
+
|
|
25
|
+
Run inside a Studio workspace. Quote commands so $PORT and $HOST reach the
|
|
26
|
+
managed server unchanged. Stop keeps the tile and prevents automatic restart.
|
|
27
|
+
`;
|
|
28
|
+
function parse(args) {
|
|
29
|
+
const action = args[0];
|
|
30
|
+
if (!['create', 'status', 'logs', 'stop'].includes(action || ''))
|
|
31
|
+
throw new Error('Choose create, status, logs, or stop');
|
|
32
|
+
const values = {};
|
|
33
|
+
let id, json = false;
|
|
34
|
+
const allowed = action === 'create' ? ['name', 'branch', 'command', 'cwd', 'setup', 'build', 'health-path', 'port', 'poll-seconds', 'timeout-seconds', 'ready-seconds', 'wait-for', 'request-id', 'desktop'] : action === 'logs' ? ['tail'] : [];
|
|
35
|
+
for (let i = 1; i < args.length; i++) {
|
|
36
|
+
const arg = args[i];
|
|
37
|
+
if (arg === '--json') {
|
|
38
|
+
json = true;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (!arg.startsWith('-')) {
|
|
42
|
+
if (action === 'create' || id)
|
|
43
|
+
throw new Error(`Unexpected argument: ${arg}`);
|
|
44
|
+
id = arg;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const match = /^--([^=]+)(?:=(.*))?$/.exec(arg);
|
|
48
|
+
if (!match || !allowed.includes(match[1]))
|
|
49
|
+
throw new Error(`Unknown option: ${arg}`);
|
|
50
|
+
const key = match[1];
|
|
51
|
+
if (values[key] !== undefined)
|
|
52
|
+
throw new Error(`Repeated option: --${key}`);
|
|
53
|
+
const value = match[2] ?? args[++i];
|
|
54
|
+
if (!value || (match[2] === undefined && value.startsWith('--')))
|
|
55
|
+
throw new Error(`--${key} requires a value`);
|
|
56
|
+
values[key] = value;
|
|
57
|
+
}
|
|
58
|
+
if (id && !/^[a-zA-Z0-9_-]{1,128}$/.test(id))
|
|
59
|
+
throw new Error('Invalid preview tile ID');
|
|
60
|
+
if ((action === 'logs' || action === 'stop') && !id)
|
|
61
|
+
throw new Error(`${action} requires a preview tile ID`);
|
|
62
|
+
const number = (key, min, max, fallback) => {
|
|
63
|
+
const raw = values[key];
|
|
64
|
+
if (raw === undefined)
|
|
65
|
+
return fallback;
|
|
66
|
+
const n = Number(raw);
|
|
67
|
+
if (!/^\d+$/.test(raw) || !Number.isInteger(n) || n < min || n > max)
|
|
68
|
+
throw new Error(`--${key} must be an integer in ${min}..${max}`);
|
|
69
|
+
return n;
|
|
70
|
+
};
|
|
71
|
+
const result = { action: action, id, json, tail: number('tail', 1, 200, 50) };
|
|
72
|
+
if (action === 'create') {
|
|
73
|
+
for (const key of ['name', 'branch', 'command'])
|
|
74
|
+
if (!values[key]?.trim())
|
|
75
|
+
throw new Error(`--${key} is required`);
|
|
76
|
+
const cwd = values.cwd || '.';
|
|
77
|
+
if (cwd.startsWith('/') || cwd.split(/[\\/]/).includes('..'))
|
|
78
|
+
throw new Error('--cwd must stay inside the repository');
|
|
79
|
+
const waitFor = values['wait-for'];
|
|
80
|
+
if (waitFor !== undefined && (waitFor.length > 1024 || waitFor.startsWith('/') || waitFor.split(/[\\/]/).includes('..') || /[\r\n]/.test(waitFor)))
|
|
81
|
+
throw new Error('--wait-for must be a repository-relative path');
|
|
82
|
+
result.body = { name: values.name, command: values.command, cwd,
|
|
83
|
+
port: !values.port || values.port === 'auto' ? 'auto' : number('port', 1024, 65535, 3100),
|
|
84
|
+
...(values['request-id'] && { requestId: values['request-id'] }), ...(values.desktop && { desktopId: values.desktop }),
|
|
85
|
+
followBranch: { branch: values.branch, ...(values.setup && { setup: values.setup }), ...(values.build && { build: values.build }),
|
|
86
|
+
healthPath: values['health-path'] || '/', pollSeconds: number('poll-seconds', 5, 3600, 30),
|
|
87
|
+
timeoutSeconds: number('timeout-seconds', 1, 1800, 300), readySeconds: number('ready-seconds', 1, 300, 60),
|
|
88
|
+
...(waitFor && { waitFor }) } };
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
export async function runPreviewCmd(args, deps = {}) {
|
|
93
|
+
const out = deps.stdout ?? (text => process.stdout.write(text));
|
|
94
|
+
const err = deps.stderr ?? (text => process.stderr.write(text));
|
|
95
|
+
if (args[0] === '--help' || args[0] === '-h' || args.slice(1).includes('--help')) {
|
|
96
|
+
out(PREVIEW_HELP);
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
let input;
|
|
100
|
+
try {
|
|
101
|
+
input = parse(args);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
err(`yolo preview: ${error.message}\n${PREVIEW_HELP}`);
|
|
105
|
+
return 64;
|
|
106
|
+
}
|
|
107
|
+
const auth = resolveSubstrateContext(deps.env ?? process.env);
|
|
108
|
+
if (!auth.ok) {
|
|
109
|
+
err(`yolo preview: ${auth.message}\n`);
|
|
110
|
+
return 78;
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
const scope = input.action === 'create' ? 'studio.create_preview' : input.action === 'stop' ? 'studio.stop_preview' : 'studio.read_preview';
|
|
114
|
+
const token = await mintSubstrateToken({ ...auth.context, scopes: [scope], fetchImpl: deps.fetchImpl });
|
|
115
|
+
const base = `${auth.context.commonApiUrl.replace(/\/+$/, '')}/internal/mcp/workspaces/${encodeURIComponent(token.workspaceId)}`;
|
|
116
|
+
const route = input.action === 'create' ? '/tiles/preview' : input.action === 'status'
|
|
117
|
+
? `/previews${input.id ? `/${encodeURIComponent(input.id)}` : ''}`
|
|
118
|
+
: `/previews/${encodeURIComponent(input.id)}/${input.action}${input.action === 'logs' ? `?tail=${input.tail}` : ''}`;
|
|
119
|
+
const response = await (deps.fetchImpl ?? globalThis.fetch)(base + route, {
|
|
120
|
+
method: input.action === 'create' || input.action === 'stop' ? 'POST' : 'GET',
|
|
121
|
+
headers: { Authorization: `Bearer ${token.token}`, 'Content-Type': 'application/json' },
|
|
122
|
+
...(input.body && { body: JSON.stringify(input.body) }),
|
|
123
|
+
});
|
|
124
|
+
const body = await response.json();
|
|
125
|
+
if (!response.ok)
|
|
126
|
+
throw new Error(`${body.code || response.status}: ${body.error || 'Preview request failed'}`);
|
|
127
|
+
if (input.json)
|
|
128
|
+
out(JSON.stringify(body, null, 2) + '\n');
|
|
129
|
+
else if (input.action === 'create')
|
|
130
|
+
out(`Preview ${body.tile?.id || body.previewId} follows ${input.body.followBranch && input.body.followBranch.branch} on port ${body.preview?.port}.\nUse yolo preview status to check build progress.\n`);
|
|
131
|
+
else if (input.action === 'stop')
|
|
132
|
+
out(`Stopped preview ${input.id}. The tile is retained.\n`);
|
|
133
|
+
else if (input.action === 'logs')
|
|
134
|
+
out((body.lines?.map((line) => line.text).join('') || '(no logs)') + '\n');
|
|
135
|
+
else {
|
|
136
|
+
const previews = body.previews || [body.preview];
|
|
137
|
+
out(previews.length ? previews.map((p) => `${p.tileId}\t${p.name}\t${p.status}\t${p.branchStatus?.phase || '-'}\t${p.branch}\t:${p.port}\t${p.branchStatus?.servedCommit?.slice(0, 12) || '-'}${p.branchStatus?.error ? `\n ${p.branchStatus.error}` : ''}`).join('\n') + '\n' : 'No managed branch previews.\n');
|
|
138
|
+
}
|
|
139
|
+
return 0;
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
err(`yolo preview: ${error.message}\n`);
|
|
143
|
+
return 1;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -360,11 +360,11 @@ function loadDockerignore(contextDir) {
|
|
|
360
360
|
if (/[*?]/.test(line)) {
|
|
361
361
|
const re = new RegExp('^' + line.split('').map((ch) => {
|
|
362
362
|
if (ch === '*')
|
|
363
|
-
return '
|
|
363
|
+
return '\x00STAR\x00';
|
|
364
364
|
if (ch === '?')
|
|
365
365
|
return '[^/]';
|
|
366
366
|
return ch.replace(/[.+^${}()|[\]\\]/g, '\\$&');
|
|
367
|
-
}).join('').replace(
|
|
367
|
+
}).join('').replace(/\x00STAR\x00\x00STAR\x00/g, '.*').replace(/\x00STAR\x00/g, '[^/]*') + '$');
|
|
368
368
|
// Slash-less glob (`*.log`) matches by BASENAME at any depth; a glob with
|
|
369
369
|
// `/` matches the full path.
|
|
370
370
|
rules.push({ negate, test: (rel) => hasSlash ? re.test(rel) : re.test(rel.split('/').pop() ?? rel) });
|
|
@@ -134,6 +134,10 @@ export function parsePermissionShape(raw) {
|
|
|
134
134
|
if (action || !arg)
|
|
135
135
|
return null; // arg = KEY_NAME (preset membership checked server-side)
|
|
136
136
|
return { raw, namespace: 'secret', action: arg };
|
|
137
|
+
case 'notifications':
|
|
138
|
+
if (head !== 'notifications.send' || (arg !== 'global' && arg !== 'workspace'))
|
|
139
|
+
return null;
|
|
140
|
+
return { raw, namespace: 'notifications', action, arg };
|
|
137
141
|
case 'device':
|
|
138
142
|
if (!action)
|
|
139
143
|
return null;
|
|
@@ -247,6 +251,8 @@ export function validateManifest(raw, opts = {}) {
|
|
|
247
251
|
errors.push('changelog must be a string when present');
|
|
248
252
|
if (raw.featured !== undefined && typeof raw.featured !== 'boolean')
|
|
249
253
|
errors.push('featured must be a boolean when present');
|
|
254
|
+
if (raw.marketplaceListed !== undefined && typeof raw.marketplaceListed !== 'boolean')
|
|
255
|
+
errors.push('marketplaceListed must be a boolean when present');
|
|
250
256
|
if (raw.pricing !== undefined) {
|
|
251
257
|
const p = raw.pricing;
|
|
252
258
|
if (!isObj(p)) {
|
package/dist/work-client.js
CHANGED
|
@@ -1,62 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Substrate-CLI work client (Phase 8c.2).
|
|
3
|
-
*
|
|
4
|
-
* Replaces the 8a Group 9 scaffold stub with the real auth flow:
|
|
5
|
-
*
|
|
6
|
-
* 1. `mintSubstrateToken` POSTs to `/internal/mcp/tokens` with
|
|
7
|
-
* `Authorization: Bearer <user JWT>` and the session-bound payload
|
|
8
|
-
* `{ sessionId, agentId: 'substrate-cli', scopes: [...] }`. The endpoint
|
|
9
|
-
* (`internalOrUserAuth`) verifies the JWT's userId owns the session,
|
|
10
|
-
* derives `workspaceId`, and returns a delegated JWT in `result.token`
|
|
11
|
-
* plus `result.claims.workspaceId`. The substrate CLI's lockfile is
|
|
12
|
-
* keyed by that workspaceId — `--workspace` is optional in containers
|
|
13
|
-
* because the session record IS the source of truth.
|
|
14
|
-
*
|
|
15
|
-
* 2. `authenticatedRequest` is the helper used by `yolo run list` /
|
|
16
|
-
* `yolo artifact get/list` to call `/internal/work/*`. It sends
|
|
17
|
-
* `Authorization: Bearer <delegated>` — the delegated MCP token is the
|
|
18
|
-
* capability (the per-agent allowedScopes check at the work routes is
|
|
19
|
-
* satisfied by the token's claims). The CLI is user-JWT-only; the
|
|
20
|
-
* INTERNAL_API_KEY / X-Internal-Auth path was removed.
|
|
21
|
-
*
|
|
22
|
-
* Both calls take an injectable `fetchImpl` so unit tests can stub
|
|
23
|
-
* the transport without touching real `globalThis.fetch`. In v1 the
|
|
24
|
-
* substrate CLI requires Node 20+, which guarantees `fetch` exists
|
|
25
|
-
* globally — `engines: ">=20"` is pinned in package.json.
|
|
26
|
-
*
|
|
27
|
-
* Substrate-CLI v1 scopes (capped per agents.json `substrate-cli`):
|
|
28
|
-
* - Run lifecycle: work.start_run, work.get_run,
|
|
29
|
-
* work.list_runs, work.pause_run, work.resume_run,
|
|
30
|
-
* work.cancel_run, work.transfer_run_operator
|
|
31
|
-
* - Artifact reads: work.get_artifact, work.list_artifacts, work.transfer_run_operator
|
|
32
|
-
*
|
|
33
|
-
* (The Plan-authoring scopes — work.create_plan/update_plan/get_plan/
|
|
34
|
-
* list_plans — backed `yolo plan import/export/get/list/open/activate/
|
|
35
|
-
* archive`. Those subcommands had no backing `/internal/work` route and
|
|
36
|
-
* were removed as dead CLI surface during the Plan Run substrate
|
|
37
|
-
* tear-down; `SUBSTRATE_CLI_PLAN_SCOPES` was removed with them. `yolo
|
|
38
|
-
* plan validate` is unaffected — it's a pure offline file check with no
|
|
39
|
-
* network call and no scope requirement.)
|
|
40
|
-
*
|
|
41
|
-
* Run-lifecycle implication: `work.start_run` binds the calling agent
|
|
42
|
-
* as the Run's Operator (route handler, Phase 4/6 R4). Historically a Run
|
|
43
|
-
* started via `yolo run start` had `operatorAgentId === 'substrate-cli'`,
|
|
44
|
-
* and only the substrate CLI could pause/resume/cancel it via MCP, with
|
|
45
|
-
* `yolo run transfer <runId> --to claude` as the handoff. `run start`,
|
|
46
|
-
* `run get`, `run pause/resume/cancel`, and `run transfer` were all
|
|
47
|
-
* removed as dead CLI surface (no backing route) in the same tear-down;
|
|
48
|
-
* `yolo run list` is the only survivor.
|
|
49
|
-
*/
|
|
1
|
+
/** Session-bound delegated authentication and workspace artifact transport. */
|
|
50
2
|
export const SUBSTRATE_CLI_AGENT_ID = 'substrate-cli';
|
|
51
|
-
export const SUBSTRATE_CLI_RUN_SCOPES = [
|
|
52
|
-
'work.start_run',
|
|
53
|
-
'work.get_run',
|
|
54
|
-
'work.list_runs',
|
|
55
|
-
'work.pause_run',
|
|
56
|
-
'work.resume_run',
|
|
57
|
-
'work.cancel_run',
|
|
58
|
-
'work.transfer_run_operator',
|
|
59
|
-
];
|
|
60
3
|
export const SUBSTRATE_CLI_ARTIFACT_SCOPES = [
|
|
61
4
|
'work.get_artifact',
|
|
62
5
|
'work.list_artifacts',
|
|
@@ -157,7 +100,11 @@ export async function authenticatedRequest(options, workPath, init = {}) {
|
|
|
157
100
|
method: init.method ?? 'GET',
|
|
158
101
|
headers,
|
|
159
102
|
};
|
|
160
|
-
if (init.
|
|
103
|
+
if (init.rawBody !== undefined) {
|
|
104
|
+
headers['Content-Type'] = 'application/json';
|
|
105
|
+
fetchInit.body = init.rawBody;
|
|
106
|
+
}
|
|
107
|
+
else if (init.jsonBody !== undefined) {
|
|
161
108
|
headers['Content-Type'] = 'application/json';
|
|
162
109
|
fetchInit.body = JSON.stringify(init.jsonBody);
|
|
163
110
|
}
|
|
@@ -181,7 +128,11 @@ export async function userRouteRequest(options, routePath, init = {}) {
|
|
|
181
128
|
method: init.method ?? 'GET',
|
|
182
129
|
headers,
|
|
183
130
|
};
|
|
184
|
-
if (init.
|
|
131
|
+
if (init.rawBody !== undefined) {
|
|
132
|
+
headers['Content-Type'] = 'application/json';
|
|
133
|
+
fetchInit.body = init.rawBody;
|
|
134
|
+
}
|
|
135
|
+
else if (init.jsonBody !== undefined) {
|
|
185
136
|
headers['Content-Type'] = 'application/json';
|
|
186
137
|
fetchInit.body = JSON.stringify(init.jsonBody);
|
|
187
138
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yolo-labs/yolo-cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "YOLO Studio
|
|
3
|
+
"version": "0.44.0",
|
|
4
|
+
"description": "YOLO Studio CLI for workspace context, artifacts, personal apps and hosting.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"README.md"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
|
-
"build": "
|
|
21
|
+
"build": "rm -rf dist && tsc -p tsconfig.json && node scripts/build-vendored-flexdb.mjs",
|
|
22
22
|
"test": "npm run build && node --test --test-reporter=spec dist/*.test.js",
|
|
23
23
|
"clean": "rm -rf dist",
|
|
24
24
|
"prepublishOnly": "npm test"
|
|
@@ -27,14 +27,11 @@
|
|
|
27
27
|
"node": ">=20"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"ajv": "^6.12.6",
|
|
31
30
|
"esbuild": "^0.24.0",
|
|
32
|
-
"js-yaml": "^4.1.0",
|
|
33
31
|
"miniflare": "^3.20250718.3"
|
|
34
32
|
},
|
|
35
33
|
"devDependencies": {
|
|
36
|
-
"typescript": "^5.4.0",
|
|
37
34
|
"@types/node": "^20.0.0",
|
|
38
|
-
"
|
|
35
|
+
"typescript": "^5.4.0"
|
|
39
36
|
}
|
|
40
37
|
}
|