@yolo-labs/yolo-cli 1.0.0 → 1.1.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 +17 -2
- package/dist/api-env.js +99 -0
- package/dist/api-url.js +16 -0
- package/dist/auth-context.js +95 -7
- package/dist/cli.js +20 -5
- package/dist/context.js +3 -4
- package/dist/deploy-cli.js +22 -3
- package/dist/deploy-client.js +31 -13
- package/dist/deploy-config.js +15 -1
- package/dist/deploy-detect.js +97 -0
- package/dist/deploy-ship.js +28 -1
- package/dist/mcp-scopes.js +2 -2
- package/dist/pod-owner-approval.js +47 -0
- package/dist/tileapp-developer.js +5 -2
- package/dist/tileapp-personal.js +181 -47
- package/dist/tileapp-publisher.js +20 -9
- package/dist/tileapp-validator.js +55 -3
- package/dist/tileapp-workspace.js +7 -7
- package/dist/work-client.js +8 -1
- package/package.json +1 -1
|
@@ -13,15 +13,15 @@
|
|
|
13
13
|
* Both use the user JWT directly (the publisher endpoints are user-authed), so
|
|
14
14
|
* no MCP delegation. The HTTP transport is injectable for unit tests.
|
|
15
15
|
*/
|
|
16
|
+
import { missingUserTokenMessage } from './api-env.js';
|
|
16
17
|
import fs from 'node:fs';
|
|
17
|
-
import { resolveUserToken } from './auth-context.js';
|
|
18
|
+
import { podSessionTelemetryHeaders, resolveUserToken } from './auth-context.js';
|
|
19
|
+
import { resolveCommonApiUrl } from './api-url.js';
|
|
18
20
|
function resolvePublisherAuth(env) {
|
|
19
|
-
const commonApiUrl = env
|
|
20
|
-
if (!commonApiUrl)
|
|
21
|
-
return { ok: false, message: 'YOLO_COMMON_API_URL (or YOLO_API_URL) env var is required' };
|
|
21
|
+
const commonApiUrl = resolveCommonApiUrl(env);
|
|
22
22
|
const userToken = resolveUserToken(env);
|
|
23
23
|
if (!userToken) {
|
|
24
|
-
return { ok: false, message:
|
|
24
|
+
return { ok: false, message: missingUserTokenMessage(env) };
|
|
25
25
|
}
|
|
26
26
|
return { ok: true, commonApiUrl, userToken };
|
|
27
27
|
}
|
|
@@ -68,7 +68,7 @@ export async function runTileAppSign(opts) {
|
|
|
68
68
|
try {
|
|
69
69
|
res = await fetchImpl(`${apiBase(auth.commonApiUrl)}/publisher/sign`, {
|
|
70
70
|
method: 'POST',
|
|
71
|
-
headers: { 'content-type': 'application/json', authorization: `Bearer ${auth.userToken}
|
|
71
|
+
headers: { 'content-type': 'application/json', authorization: `Bearer ${auth.userToken}`, ...podSessionTelemetryHeaders() },
|
|
72
72
|
body: JSON.stringify({ publisherId: opts.publisherId, keyId: opts.keyId, manifest: read.manifest }),
|
|
73
73
|
});
|
|
74
74
|
}
|
|
@@ -76,7 +76,7 @@ export async function runTileAppSign(opts) {
|
|
|
76
76
|
return { ok: false, kind: 'http', message: `sign request failed: ${e.message}` };
|
|
77
77
|
}
|
|
78
78
|
if (!res.ok)
|
|
79
|
-
return { ok: false, kind: 'http', message:
|
|
79
|
+
return { ok: false, kind: 'http', message: podRefusalMessage('sign', res.status, await safeText(res)) };
|
|
80
80
|
const json = (await res.json());
|
|
81
81
|
if (!json.signature || !json.publisherKeyId)
|
|
82
82
|
return { ok: false, kind: 'http', message: 'sign response missing signature/publisherKeyId' };
|
|
@@ -115,7 +115,7 @@ export async function runTileAppPublish(opts) {
|
|
|
115
115
|
body.imageDigest = opts.imageDigest;
|
|
116
116
|
res = await fetchImpl(`${apiBase(auth.commonApiUrl)}/publisher/publish`, {
|
|
117
117
|
method: 'POST',
|
|
118
|
-
headers: { 'content-type': 'application/json', authorization: `Bearer ${auth.userToken}
|
|
118
|
+
headers: { 'content-type': 'application/json', authorization: `Bearer ${auth.userToken}`, ...podSessionTelemetryHeaders() },
|
|
119
119
|
body: JSON.stringify(body),
|
|
120
120
|
});
|
|
121
121
|
}
|
|
@@ -123,12 +123,23 @@ export async function runTileAppPublish(opts) {
|
|
|
123
123
|
return { ok: false, kind: 'http', message: `publish request failed: ${e.message}` };
|
|
124
124
|
}
|
|
125
125
|
if (!res.ok)
|
|
126
|
-
return { ok: false, kind: 'http', message:
|
|
126
|
+
return { ok: false, kind: 'http', message: podRefusalMessage('publish', res.status, await safeText(res)) };
|
|
127
127
|
const json = (await res.json());
|
|
128
128
|
if (!json.releaseId)
|
|
129
129
|
return { ok: false, kind: 'http', message: 'publish response missing releaseId' };
|
|
130
130
|
return { ok: true, output: `Submitted ${json.releaseId} (status: ${json.status ?? 'submitted'}) — awaiting review` };
|
|
131
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* MOGUL-D040 P2 / OD-5: marketplace sign/publish is a human act and is refused
|
|
134
|
+
* to a workspace pod's credential (403 POD_TOKEN_FORBIDDEN). Say so plainly
|
|
135
|
+
* instead of dumping the JSON body.
|
|
136
|
+
*/
|
|
137
|
+
function podRefusalMessage(step, status, body) {
|
|
138
|
+
if (status === 403 && body.includes('POD_TOKEN_FORBIDDEN')) {
|
|
139
|
+
return `${step} refused: marketplace publishing cannot be done from a workspace pod. The owner publishes from Studio (or a signed-in terminal outside the workspace); use \`yolo tileapp publish --personal\` for a personal app.`;
|
|
140
|
+
}
|
|
141
|
+
return `${step} failed: HTTP ${status} — ${body}`;
|
|
142
|
+
}
|
|
132
143
|
export function exitCodeForFailure(kind) {
|
|
133
144
|
return kind === 'http' ? 1 : 64;
|
|
134
145
|
}
|
|
@@ -192,6 +192,9 @@ export function validateManifest(raw, opts = {}) {
|
|
|
192
192
|
errors.push('runtime.port must be a positive number');
|
|
193
193
|
if (raw.runtime.exec !== undefined && !isStr(raw.runtime.exec))
|
|
194
194
|
errors.push('runtime.exec must be a non-empty string when present');
|
|
195
|
+
if (raw.runtime.kind !== undefined && raw.runtime.kind !== 'process' && raw.runtime.kind !== 'worker') {
|
|
196
|
+
errors.push("runtime.kind must be 'process' | 'worker' when present");
|
|
197
|
+
}
|
|
195
198
|
}
|
|
196
199
|
}
|
|
197
200
|
if (raw.image !== undefined) {
|
|
@@ -210,9 +213,21 @@ export function validateManifest(raw, opts = {}) {
|
|
|
210
213
|
}
|
|
211
214
|
}
|
|
212
215
|
}
|
|
213
|
-
|
|
216
|
+
// A worker has neither: it is an edge backend uploaded from the bundle's `_worker/`.
|
|
217
|
+
if (isObj(raw.runtime) && raw.image === undefined && !isStr(raw.runtime.exec) && !isWorkerRuntimeManifest(raw)) {
|
|
214
218
|
errors.push('runtime requires either `image` (OCI image, recommended) or `runtime.exec` (bare-process override)');
|
|
215
219
|
}
|
|
220
|
+
// Publish-time rule (`validateManifestForPublish`): an image or exec on a
|
|
221
|
+
// worker would be silently ignored, so refuse it.
|
|
222
|
+
if (isWorkerRuntimeManifest(raw)) {
|
|
223
|
+
if (raw.image !== undefined)
|
|
224
|
+
errors.push("runtime.kind 'worker' runs from the bundle's _worker/ modules — remove `image`, it would be ignored");
|
|
225
|
+
if (raw.runtime.exec !== undefined)
|
|
226
|
+
errors.push("runtime.kind 'worker' runs from the bundle's _worker/ modules — remove `runtime.exec`, it would be ignored");
|
|
227
|
+
}
|
|
228
|
+
if (raw.isolation !== undefined && raw.isolation !== 'shared' && raw.isolation !== 'dedicated' && raw.isolation !== 'edge') {
|
|
229
|
+
errors.push("isolation must be 'shared' | 'dedicated' | 'edge' when present");
|
|
230
|
+
}
|
|
216
231
|
const allPerms = [];
|
|
217
232
|
if (!isObj(raw.permissions)) {
|
|
218
233
|
errors.push('permissions is required');
|
|
@@ -302,7 +317,44 @@ export function publishGateErrors(manifest) {
|
|
|
302
317
|
return errors;
|
|
303
318
|
}
|
|
304
319
|
/**
|
|
305
|
-
* True
|
|
320
|
+
* True for a `runtime.kind: 'worker'` manifest: a Cloudflare edge tile whose
|
|
321
|
+
* backend ships IN the bundle under `_worker/` — no image, no podman build.
|
|
322
|
+
* The server additionally requires its worker placement (`TILEAPP_CF_PLACEMENTS`)
|
|
323
|
+
* to be on, which the CLI cannot see; with it off the server rejects the
|
|
324
|
+
* manifest at register and says why.
|
|
325
|
+
*/
|
|
326
|
+
export function isWorkerRuntimeManifest(manifest) {
|
|
327
|
+
return isObj(manifest) && isObj(manifest.runtime) && manifest.runtime.kind === 'worker';
|
|
328
|
+
}
|
|
329
|
+
/** Directory (in the bundle) holding a worker tile's backend; never served as a static asset. */
|
|
330
|
+
export const TILE_WORKER_BUNDLE_DIR = '_worker/';
|
|
331
|
+
/** The worker backend's main module, relative to the bundle root. */
|
|
332
|
+
export const TILE_WORKER_BUNDLE_ENTRY = `${TILE_WORKER_BUNDLE_DIR}index.js`;
|
|
333
|
+
/**
|
|
334
|
+
* What a worker bundle needs, from its file paths alone. Mirrors the server's
|
|
335
|
+
* `workerBundleErrors` (`common-api/src/types/tileapp.ts`), which refuses the
|
|
336
|
+
* upload with `INVALID_WORKER_BUNDLE` — checked here first so a bad bundle
|
|
337
|
+
* fails before the manifest is registered.
|
|
338
|
+
*/
|
|
339
|
+
export function workerBundleErrors(paths) {
|
|
340
|
+
const errors = [];
|
|
341
|
+
const backend = paths.filter((p) => p.startsWith(TILE_WORKER_BUNDLE_DIR));
|
|
342
|
+
if (!backend.includes(TILE_WORKER_BUNDLE_ENTRY)) {
|
|
343
|
+
errors.push(`a worker tile needs a backend entry module at ${TILE_WORKER_BUNDLE_ENTRY}`);
|
|
344
|
+
}
|
|
345
|
+
for (const p of backend) {
|
|
346
|
+
if (!/\.m?js$/.test(p))
|
|
347
|
+
errors.push(`backend files must be .js or .mjs modules: ${JSON.stringify(p)}`);
|
|
348
|
+
}
|
|
349
|
+
if (paths.length === backend.length)
|
|
350
|
+
errors.push(`a worker tile needs UI files outside ${TILE_WORKER_BUNDLE_DIR}`);
|
|
351
|
+
return errors;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* True if the manifest declares a server-side runtime built as a container
|
|
355
|
+
* image. A worker runtime (`isWorkerRuntimeManifest`) is NOT one: it ships as a
|
|
356
|
+
* bundle with its backend under `_worker/`, so it needs `surface.entry` on disk
|
|
357
|
+
* like a pure-UI app. Otherwise keyed on `runtime` ONLY
|
|
306
358
|
* — matching the launcher, which serves a static surface bundle for any manifest
|
|
307
359
|
* WITHOUT `runtime` (`common-api/src/services/tileapp/launcher.ts`: `if
|
|
308
360
|
* (!manifest.runtime) → staticSurfaceUrl`). An `image`-only manifest (no
|
|
@@ -311,5 +363,5 @@ export function publishGateErrors(manifest) {
|
|
|
311
363
|
* skip the bundle check on an app that fails to render in prod).
|
|
312
364
|
*/
|
|
313
365
|
export function isRuntimeManifest(manifest) {
|
|
314
|
-
return isObj(manifest) && isObj(manifest.runtime);
|
|
366
|
+
return isObj(manifest) && isObj(manifest.runtime) && !isWorkerRuntimeManifest(manifest);
|
|
315
367
|
}
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
* Auth: user JWT (no SESSION_ID needed — these are user-authed /v1 routes),
|
|
22
22
|
* same resolution as `tileapp publish --personal`.
|
|
23
23
|
*/
|
|
24
|
-
import {
|
|
24
|
+
import { missingUserTokenMessage } from './api-env.js';
|
|
25
|
+
import { podSessionTelemetryHeaders, resolveUserToken } from './auth-context.js';
|
|
26
|
+
import { resolveCommonApiUrl } from './api-url.js';
|
|
25
27
|
export function exitCodeForFailure(kind) {
|
|
26
28
|
return kind === 'http' ? 1 : 64; // EX_USAGE for usage/auth (tileapp-personal precedent)
|
|
27
29
|
}
|
|
@@ -30,12 +32,10 @@ function apiBase(commonApiUrl) {
|
|
|
30
32
|
return base.endsWith('/v1') ? base : `${base}/v1`;
|
|
31
33
|
}
|
|
32
34
|
function resolveAuth(env) {
|
|
33
|
-
const commonApiUrl = env
|
|
34
|
-
if (!commonApiUrl)
|
|
35
|
-
return { ok: false, message: 'YOLO_COMMON_API_URL (or YOLO_API_URL) env var is required' };
|
|
35
|
+
const commonApiUrl = resolveCommonApiUrl(env);
|
|
36
36
|
const userToken = resolveUserToken(env);
|
|
37
37
|
if (!userToken)
|
|
38
|
-
return { ok: false, message:
|
|
38
|
+
return { ok: false, message: missingUserTokenMessage(env) };
|
|
39
39
|
return { ok: true, commonApiUrl, userToken };
|
|
40
40
|
}
|
|
41
41
|
async function safeText(res) {
|
|
@@ -60,7 +60,7 @@ export async function runTileAppInstall(opts) {
|
|
|
60
60
|
try {
|
|
61
61
|
const res = await fetchImpl(`${base}/tileapps/${encodeURIComponent(opts.appId)}/install`, {
|
|
62
62
|
method: 'POST',
|
|
63
|
-
headers: { 'content-type': 'application/json', authorization: `Bearer ${auth.userToken}
|
|
63
|
+
headers: { 'content-type': 'application/json', authorization: `Bearer ${auth.userToken}`, ...podSessionTelemetryHeaders() },
|
|
64
64
|
body: JSON.stringify(body),
|
|
65
65
|
});
|
|
66
66
|
if (!res.ok)
|
|
@@ -97,7 +97,7 @@ export async function runTileAppAddTile(opts) {
|
|
|
97
97
|
return { ok: false, kind: 'auth', message: auth.message };
|
|
98
98
|
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
99
99
|
const base = apiBase(auth.commonApiUrl);
|
|
100
|
-
const headers = { 'content-type': 'application/json', authorization: `Bearer ${auth.userToken}
|
|
100
|
+
const headers = { 'content-type': 'application/json', authorization: `Bearer ${auth.userToken}`, ...podSessionTelemetryHeaders() };
|
|
101
101
|
// Preflight 1 — the app must EXIST. Always performed (even with explicit
|
|
102
102
|
// --version/--name): the tiles route validates only the tile shape, so
|
|
103
103
|
// skipping this would persist a tile for a nonexistent appId that can never
|
package/dist/work-client.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** Session-bound delegated authentication and workspace artifact transport. */
|
|
2
|
+
import { inRestrictedExecution, podSessionTelemetryHeaders, RESTRICTED_EXECUTION_MESSAGE } from './auth-context.js';
|
|
2
3
|
export const SUBSTRATE_CLI_AGENT_ID = 'substrate-cli';
|
|
3
4
|
export const SUBSTRATE_CLI_ARTIFACT_SCOPES = [
|
|
4
5
|
'work.get_artifact',
|
|
@@ -27,6 +28,11 @@ export async function mintSubstrateToken(options) {
|
|
|
27
28
|
if (!fetchImpl) {
|
|
28
29
|
throw new WorkClientError('fetch is not available; substrate CLI requires Node 20+', 0, 'INTERNAL');
|
|
29
30
|
}
|
|
31
|
+
// A restricted execution mints nothing here, whatever token the caller came by: this route answers with
|
|
32
|
+
// the workspace owner's authority, which is not the execution's. Checked before any request is made.
|
|
33
|
+
if ((options.restrictedExecution ?? (() => inRestrictedExecution(process.env)))()) {
|
|
34
|
+
throw new WorkClientError(RESTRICTED_EXECUTION_MESSAGE, 0, 'EXECUTION_RESTRICTED');
|
|
35
|
+
}
|
|
30
36
|
if (!options.userToken) {
|
|
31
37
|
throw new WorkClientError('no user token available to mint a substrate token', 0, 'INTERNAL');
|
|
32
38
|
}
|
|
@@ -36,6 +42,7 @@ export async function mintSubstrateToken(options) {
|
|
|
36
42
|
headers: {
|
|
37
43
|
'Content-Type': 'application/json',
|
|
38
44
|
Authorization: `Bearer ${options.userToken}`,
|
|
45
|
+
...podSessionTelemetryHeaders(),
|
|
39
46
|
},
|
|
40
47
|
body: JSON.stringify({
|
|
41
48
|
sessionId: options.sessionId,
|
|
@@ -118,7 +125,7 @@ export async function userRouteRequest(options, routePath, init = {}) {
|
|
|
118
125
|
if (!options.userToken) {
|
|
119
126
|
throw new WorkClientError('no user token available for user-route request', 0, 'INTERNAL');
|
|
120
127
|
}
|
|
121
|
-
const authHeaders = { Authorization: `Bearer ${options.userToken}
|
|
128
|
+
const authHeaders = { Authorization: `Bearer ${options.userToken}`, ...podSessionTelemetryHeaders() };
|
|
122
129
|
const url = `${stripTrailingSlash(options.commonApiUrl)}/v1${routePath}`;
|
|
123
130
|
const headers = {
|
|
124
131
|
...(init.headers ?? {}),
|