@yolo-labs/yolo-cli 0.25.0 → 0.31.1
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/dist/cli.js +179 -2
- package/dist/deploy-bundle.js +249 -12
- package/dist/deploy-cli.js +229 -1
- package/dist/deploy-client.js +6 -1
- package/dist/deploy-dev.js +215 -0
- package/dist/deploy-ship.js +10 -4
- package/dist/mcp-scopes.js +86 -0
- package/dist/tileapp-workspace.js +164 -0
- package/package.json +3 -2
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `yolo tileapp install` + `yolo tileapp add-tile` — workspace-side app
|
|
3
|
+
* management (field-retro follow-up: agents had to hand-roll curl for both).
|
|
4
|
+
*
|
|
5
|
+
* yolo tileapp install <appId> --workspace <wsId> [--accept-optional <perm>]…
|
|
6
|
+
* → POST /v1/tileapps/<appId>/install { workspaceId, acceptedOptional? }.
|
|
7
|
+
* Records the grant; prints the granted permissions.
|
|
8
|
+
*
|
|
9
|
+
* yolo tileapp add-tile <appId> --workspace <wsId> [--name <n>] [--version <v>]
|
|
10
|
+
* → POST /v1/workspaces/<wsId>/tiles { id, type: 'app', name, app }.
|
|
11
|
+
* The tiles route REQUIRES a client-generated tile id ("Tile id, type,
|
|
12
|
+
* and name are required"), so we mint one: app-<appId-slug>-<suffix>.
|
|
13
|
+
* Preflights BEFORE creating the tile (codex gpt-5.6-sol P2, 2026-07-18
|
|
14
|
+
* — the tiles route itself validates neither, so a bare POST happily
|
|
15
|
+
* persists a tile that 409s "app-not-installed" at launch):
|
|
16
|
+
* 1. GET /v1/tileapps/<appId> — the app must exist (404 → clear
|
|
17
|
+
* error). Also supplies the --version/--name defaults.
|
|
18
|
+
* 2. GET /v1/tileapps/installed?workspaceId=… — the app must have a
|
|
19
|
+
* grant in the target workspace (else: run `tileapp install`).
|
|
20
|
+
*
|
|
21
|
+
* Auth: user JWT (no SESSION_ID needed — these are user-authed /v1 routes),
|
|
22
|
+
* same resolution as `tileapp publish --personal`.
|
|
23
|
+
*/
|
|
24
|
+
import { resolveUserToken } from './auth-context.js';
|
|
25
|
+
export function exitCodeForFailure(kind) {
|
|
26
|
+
return kind === 'http' ? 1 : 64; // EX_USAGE for usage/auth (tileapp-personal precedent)
|
|
27
|
+
}
|
|
28
|
+
function apiBase(commonApiUrl) {
|
|
29
|
+
const base = commonApiUrl.replace(/\/$/, '');
|
|
30
|
+
return base.endsWith('/v1') ? base : `${base}/v1`;
|
|
31
|
+
}
|
|
32
|
+
function resolveAuth(env) {
|
|
33
|
+
const commonApiUrl = env.YOLO_COMMON_API_URL || env.YOLO_API_URL;
|
|
34
|
+
if (!commonApiUrl)
|
|
35
|
+
return { ok: false, message: 'YOLO_COMMON_API_URL (or YOLO_API_URL) env var is required' };
|
|
36
|
+
const userToken = resolveUserToken(env);
|
|
37
|
+
if (!userToken)
|
|
38
|
+
return { ok: false, message: 'no user token: set YOLO_API_TOKEN or sign in (~/.config/yolo/token)' };
|
|
39
|
+
return { ok: true, commonApiUrl, userToken };
|
|
40
|
+
}
|
|
41
|
+
async function safeText(res) {
|
|
42
|
+
try {
|
|
43
|
+
return await res.text();
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return '<no body>';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export async function runTileAppInstall(opts) {
|
|
50
|
+
const env = opts.env ?? process.env;
|
|
51
|
+
const auth = resolveAuth(env);
|
|
52
|
+
if (!auth.ok)
|
|
53
|
+
return { ok: false, kind: 'auth', message: auth.message };
|
|
54
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
55
|
+
const base = apiBase(auth.commonApiUrl);
|
|
56
|
+
const body = { workspaceId: opts.workspaceId };
|
|
57
|
+
if (opts.acceptOptional && opts.acceptOptional.length > 0)
|
|
58
|
+
body.acceptedOptional = opts.acceptOptional;
|
|
59
|
+
let json;
|
|
60
|
+
try {
|
|
61
|
+
const res = await fetchImpl(`${base}/tileapps/${encodeURIComponent(opts.appId)}/install`, {
|
|
62
|
+
method: 'POST',
|
|
63
|
+
headers: { 'content-type': 'application/json', authorization: `Bearer ${auth.userToken}` },
|
|
64
|
+
body: JSON.stringify(body),
|
|
65
|
+
});
|
|
66
|
+
if (!res.ok)
|
|
67
|
+
return { ok: false, kind: 'http', message: `install failed: HTTP ${res.status} — ${await safeText(res)}` };
|
|
68
|
+
json = (await res.json());
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
return { ok: false, kind: 'http', message: `install request failed: ${e.message}` };
|
|
72
|
+
}
|
|
73
|
+
if (!json.installed || !json.grant) {
|
|
74
|
+
return { ok: false, kind: 'http', message: 'install response missing grant' };
|
|
75
|
+
}
|
|
76
|
+
const granted = Array.isArray(json.grant.grantedPermissions) ? json.grant.grantedPermissions : [];
|
|
77
|
+
const lines = [
|
|
78
|
+
`Installed ${json.grant.appId ?? opts.appId}@${json.grant.version ?? '?'} into workspace ${opts.workspaceId}`,
|
|
79
|
+
`Granted permissions (${granted.length}):`,
|
|
80
|
+
...(granted.length > 0 ? granted.map((p) => ` - ${p}`) : [' (none)']),
|
|
81
|
+
];
|
|
82
|
+
return { ok: true, output: lines.join('\n') };
|
|
83
|
+
}
|
|
84
|
+
/** `app-<appId-slug>-<random>` — the client-generated id the tiles route requires. */
|
|
85
|
+
export function generateTileId(appId, suffixImpl) {
|
|
86
|
+
const slug = appId.toLowerCase().replace(/[^a-z0-9-]+/g, '-').replace(/^-+|-+$/g, '');
|
|
87
|
+
const suffix = (suffixImpl ?? defaultSuffix)();
|
|
88
|
+
return `app-${slug}-${suffix}`;
|
|
89
|
+
}
|
|
90
|
+
function defaultSuffix() {
|
|
91
|
+
return Math.random().toString(36).slice(2, 8);
|
|
92
|
+
}
|
|
93
|
+
export async function runTileAppAddTile(opts) {
|
|
94
|
+
const env = opts.env ?? process.env;
|
|
95
|
+
const auth = resolveAuth(env);
|
|
96
|
+
if (!auth.ok)
|
|
97
|
+
return { ok: false, kind: 'auth', message: auth.message };
|
|
98
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
99
|
+
const base = apiBase(auth.commonApiUrl);
|
|
100
|
+
const headers = { 'content-type': 'application/json', authorization: `Bearer ${auth.userToken}` };
|
|
101
|
+
// Preflight 1 — the app must EXIST. Always performed (even with explicit
|
|
102
|
+
// --version/--name): the tiles route validates only the tile shape, so
|
|
103
|
+
// skipping this would persist a tile for a nonexistent appId that can never
|
|
104
|
+
// launch. Doubles as the --version/--name default source.
|
|
105
|
+
let version = opts.version;
|
|
106
|
+
let name = opts.name;
|
|
107
|
+
try {
|
|
108
|
+
const res = await fetchImpl(`${base}/tileapps/${encodeURIComponent(opts.appId)}`, { headers });
|
|
109
|
+
if (res.status === 404) {
|
|
110
|
+
return { ok: false, kind: 'http', message: `app '${opts.appId}' not found — check the appId (GET /v1/tileapps/${opts.appId} → 404)` };
|
|
111
|
+
}
|
|
112
|
+
if (!res.ok)
|
|
113
|
+
return { ok: false, kind: 'http', message: `resolve app failed: HTTP ${res.status} — ${await safeText(res)}` };
|
|
114
|
+
const json = (await res.json());
|
|
115
|
+
if (!version) {
|
|
116
|
+
if (typeof json.app?.version !== 'string' || !json.app.version) {
|
|
117
|
+
return { ok: false, kind: 'http', message: 'resolve app response missing app.version — pass --version explicitly' };
|
|
118
|
+
}
|
|
119
|
+
version = json.app.version;
|
|
120
|
+
}
|
|
121
|
+
if (!name)
|
|
122
|
+
name = json.app?.displayName || opts.appId;
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
return { ok: false, kind: 'http', message: `resolve app request failed: ${e.message}` };
|
|
126
|
+
}
|
|
127
|
+
// Preflight 2 — the app must be INSTALLED (granted) in the target workspace,
|
|
128
|
+
// or the created tile would 409 app-not-installed at launch. Read via the
|
|
129
|
+
// existing grants listing (GET /tileapps/installed?workspaceId=…) — user-JWT
|
|
130
|
+
// readable + workspace-ownership-checked server-side.
|
|
131
|
+
try {
|
|
132
|
+
const res = await fetchImpl(`${base}/tileapps/installed?workspaceId=${encodeURIComponent(opts.workspaceId)}`, { headers });
|
|
133
|
+
if (!res.ok)
|
|
134
|
+
return { ok: false, kind: 'http', message: `installed-apps check failed: HTTP ${res.status} — ${await safeText(res)}` };
|
|
135
|
+
const json = (await res.json());
|
|
136
|
+
if (!Array.isArray(json.installed)) {
|
|
137
|
+
return { ok: false, kind: 'http', message: 'installed-apps response missing `installed` array' };
|
|
138
|
+
}
|
|
139
|
+
if (!json.installed.some((g) => g.appId === opts.appId)) {
|
|
140
|
+
return {
|
|
141
|
+
ok: false,
|
|
142
|
+
kind: 'http',
|
|
143
|
+
message: `app '${opts.appId}' is not installed in this workspace — run: yolo tileapp install ${opts.appId} --workspace ${opts.workspaceId}`,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
catch (e) {
|
|
148
|
+
return { ok: false, kind: 'http', message: `installed-apps check request failed: ${e.message}` };
|
|
149
|
+
}
|
|
150
|
+
const tileId = generateTileId(opts.appId, opts.idSuffixImpl);
|
|
151
|
+
try {
|
|
152
|
+
const res = await fetchImpl(`${base}/workspaces/${encodeURIComponent(opts.workspaceId)}/tiles`, {
|
|
153
|
+
method: 'POST',
|
|
154
|
+
headers,
|
|
155
|
+
body: JSON.stringify({ id: tileId, type: 'app', name, app: { appId: opts.appId, version } }),
|
|
156
|
+
});
|
|
157
|
+
if (!res.ok)
|
|
158
|
+
return { ok: false, kind: 'http', message: `add-tile failed: HTTP ${res.status} — ${await safeText(res)}` };
|
|
159
|
+
}
|
|
160
|
+
catch (e) {
|
|
161
|
+
return { ok: false, kind: 'http', message: `add-tile request failed: ${e.message}` };
|
|
162
|
+
}
|
|
163
|
+
return { ok: true, output: `Added app tile ${tileId} (${opts.appId}@${version}, "${name}") to workspace ${opts.workspaceId}` };
|
|
164
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yolo-labs/yolo-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.1",
|
|
4
4
|
"description": "YOLO Studio substrate CLI — owns yolo plan/workspace/artifact substrate-tooling commands. Distinct from yolo-code (the agent CLI) and yolo-router (the LLM gateway client).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"ajv": "^6.12.6",
|
|
31
31
|
"esbuild": "^0.24.0",
|
|
32
|
-
"js-yaml": "^4.1.0"
|
|
32
|
+
"js-yaml": "^4.1.0",
|
|
33
|
+
"miniflare": "^3.20250718.3"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"typescript": "^5.4.0",
|