@yolo-labs/yolo-cli 0.30.0 → 0.32.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/dist/cli.js +179 -2
- package/dist/deploy-client.js +31 -3
- package/dist/mcp-scopes.js +86 -0
- package/dist/tileapp-workspace.js +164 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -143,6 +143,16 @@ function printHelp() {
|
|
|
143
143
|
' tileapp publish <manifest> [opts] Submit a SIGNED manifest for marketplace review (POST /v1/publisher/publish).',
|
|
144
144
|
' [--channel beta|stable] Target channel (default: stable).',
|
|
145
145
|
' [--image-digest <d>] Consistency check: must equal the signed manifest image.digest.',
|
|
146
|
+
' tileapp install <appId> [opts] Record an app grant for a workspace (POST /v1/tileapps/:appId/install).',
|
|
147
|
+
' --workspace <workspaceId> Target workspace (required).',
|
|
148
|
+
' [--accept-optional <perm>] Accept an optional permission (repeatable).',
|
|
149
|
+
' tileapp add-tile <appId> [opts] Place an app tile in a workspace (POST /v1/workspaces/:id/tiles).',
|
|
150
|
+
' --workspace <workspaceId> Target workspace (required).',
|
|
151
|
+
' [--name <name>] Tile display name (default: the app manifest displayName).',
|
|
152
|
+
' [--version <v>] App version to pin (default: the app\'s current version).',
|
|
153
|
+
' mcp scopes [opts] Show mintable vs not-mintable MCP scopes for this session (pure read).',
|
|
154
|
+
' [--agent <agentId>] Agent identity to inspect (default: substrate-cli).',
|
|
155
|
+
' [--json] Emit {agentId, allowed, denied} as JSON.',
|
|
146
156
|
' serve <dir> [opts] Static file server (decision-preview / Gap 2a).',
|
|
147
157
|
' [--port <n>] Port (default: $PORT, else 3000).',
|
|
148
158
|
' [--host <h>] Bind host (default: 0.0.0.0).',
|
|
@@ -746,10 +756,161 @@ function tileAppUsage(sub, message) {
|
|
|
746
756
|
+ ' or: yolo tileapp publish <manifest.json> [--channel beta|stable] [--image-digest <d>] (marketplace)\n',
|
|
747
757
|
validate: 'Usage: yolo tileapp validate <manifest.json> [--bundle-dir <dir>]\n',
|
|
748
758
|
dev: 'Usage: yolo tileapp dev <manifest.json> [--port N] [--host H] [--bundle-dir <dir>] [--deny]\n',
|
|
759
|
+
install: 'Usage: yolo tileapp install <appId> --workspace <workspaceId> [--accept-optional <perm>]...\n',
|
|
760
|
+
'add-tile': 'Usage: yolo tileapp add-tile <appId> --workspace <workspaceId> [--name <name>] [--version <v>]\n',
|
|
749
761
|
};
|
|
750
762
|
process.stderr.write(usage[sub]);
|
|
751
763
|
return 64;
|
|
752
764
|
}
|
|
765
|
+
async function runTileAppInstallCmd(args) {
|
|
766
|
+
let appId;
|
|
767
|
+
let workspaceId;
|
|
768
|
+
const acceptOptional = [];
|
|
769
|
+
for (let i = 0; i < args.length; i++) {
|
|
770
|
+
const a = args[i];
|
|
771
|
+
// A following flag must never be consumed as a value (`--workspace
|
|
772
|
+
// --accept-optional=x`), so reject empty values and `--`-leading values —
|
|
773
|
+
// same pattern as the run/plan parsers (codex gpt-5.6-sol P3, 2026-07-18).
|
|
774
|
+
if (a === '--workspace') {
|
|
775
|
+
const v = args[++i];
|
|
776
|
+
if (!v || v.startsWith('--'))
|
|
777
|
+
return tileAppUsage('install', '--workspace requires a value');
|
|
778
|
+
workspaceId = v;
|
|
779
|
+
}
|
|
780
|
+
else if (a.startsWith('--workspace=')) {
|
|
781
|
+
const v = a.slice('--workspace='.length);
|
|
782
|
+
if (!v)
|
|
783
|
+
return tileAppUsage('install', '--workspace requires a value');
|
|
784
|
+
workspaceId = v;
|
|
785
|
+
}
|
|
786
|
+
else if (a === '--accept-optional') {
|
|
787
|
+
const v = args[++i];
|
|
788
|
+
if (!v || v.startsWith('--'))
|
|
789
|
+
return tileAppUsage('install', '--accept-optional requires a value');
|
|
790
|
+
acceptOptional.push(v);
|
|
791
|
+
}
|
|
792
|
+
else if (a.startsWith('--accept-optional=')) {
|
|
793
|
+
const v = a.slice('--accept-optional='.length);
|
|
794
|
+
if (!v)
|
|
795
|
+
return tileAppUsage('install', '--accept-optional requires a value');
|
|
796
|
+
acceptOptional.push(v);
|
|
797
|
+
}
|
|
798
|
+
else if (!a.startsWith('-') && !appId)
|
|
799
|
+
appId = a;
|
|
800
|
+
else
|
|
801
|
+
return tileAppUsage('install', `unexpected argument '${a}'`);
|
|
802
|
+
}
|
|
803
|
+
if (!appId || !workspaceId)
|
|
804
|
+
return tileAppUsage('install', 'an appId and --workspace <workspaceId> are required');
|
|
805
|
+
const { runTileAppInstall, exitCodeForFailure } = await import('./tileapp-workspace.js');
|
|
806
|
+
const result = await runTileAppInstall({ appId, workspaceId, acceptOptional });
|
|
807
|
+
if (result.ok) {
|
|
808
|
+
process.stdout.write(`${result.output}\n`);
|
|
809
|
+
return 0;
|
|
810
|
+
}
|
|
811
|
+
process.stderr.write(`FAIL [${result.kind}]: ${result.message}\n`);
|
|
812
|
+
return exitCodeForFailure(result.kind);
|
|
813
|
+
}
|
|
814
|
+
async function runTileAppAddTileCmd(args) {
|
|
815
|
+
let appId;
|
|
816
|
+
let workspaceId;
|
|
817
|
+
let name;
|
|
818
|
+
let version;
|
|
819
|
+
for (let i = 0; i < args.length; i++) {
|
|
820
|
+
const a = args[i];
|
|
821
|
+
// Reject empty/`--`-leading values so a following flag is never consumed
|
|
822
|
+
// as a value (codex gpt-5.6-sol P3, 2026-07-18).
|
|
823
|
+
if (a === '--workspace') {
|
|
824
|
+
const v = args[++i];
|
|
825
|
+
if (!v || v.startsWith('--'))
|
|
826
|
+
return tileAppUsage('add-tile', '--workspace requires a value');
|
|
827
|
+
workspaceId = v;
|
|
828
|
+
}
|
|
829
|
+
else if (a.startsWith('--workspace=')) {
|
|
830
|
+
const v = a.slice('--workspace='.length);
|
|
831
|
+
if (!v)
|
|
832
|
+
return tileAppUsage('add-tile', '--workspace requires a value');
|
|
833
|
+
workspaceId = v;
|
|
834
|
+
}
|
|
835
|
+
else if (a === '--name') {
|
|
836
|
+
const v = args[++i];
|
|
837
|
+
if (!v || v.startsWith('--'))
|
|
838
|
+
return tileAppUsage('add-tile', '--name requires a value');
|
|
839
|
+
name = v;
|
|
840
|
+
}
|
|
841
|
+
else if (a.startsWith('--name=')) {
|
|
842
|
+
const v = a.slice('--name='.length);
|
|
843
|
+
if (!v)
|
|
844
|
+
return tileAppUsage('add-tile', '--name requires a value');
|
|
845
|
+
name = v;
|
|
846
|
+
}
|
|
847
|
+
else if (a === '--version') {
|
|
848
|
+
const v = args[++i];
|
|
849
|
+
if (!v || v.startsWith('--'))
|
|
850
|
+
return tileAppUsage('add-tile', '--version requires a value');
|
|
851
|
+
version = v;
|
|
852
|
+
}
|
|
853
|
+
else if (a.startsWith('--version=')) {
|
|
854
|
+
const v = a.slice('--version='.length);
|
|
855
|
+
if (!v)
|
|
856
|
+
return tileAppUsage('add-tile', '--version requires a value');
|
|
857
|
+
version = v;
|
|
858
|
+
}
|
|
859
|
+
else if (!a.startsWith('-') && !appId)
|
|
860
|
+
appId = a;
|
|
861
|
+
else
|
|
862
|
+
return tileAppUsage('add-tile', `unexpected argument '${a}'`);
|
|
863
|
+
}
|
|
864
|
+
if (!appId || !workspaceId)
|
|
865
|
+
return tileAppUsage('add-tile', 'an appId and --workspace <workspaceId> are required');
|
|
866
|
+
const { runTileAppAddTile, exitCodeForFailure } = await import('./tileapp-workspace.js');
|
|
867
|
+
const result = await runTileAppAddTile({ appId, workspaceId, name, version });
|
|
868
|
+
if (result.ok) {
|
|
869
|
+
process.stdout.write(`${result.output}\n`);
|
|
870
|
+
return 0;
|
|
871
|
+
}
|
|
872
|
+
process.stderr.write(`FAIL [${result.kind}]: ${result.message}\n`);
|
|
873
|
+
return exitCodeForFailure(result.kind);
|
|
874
|
+
}
|
|
875
|
+
async function runMcpScopesCmd(args) {
|
|
876
|
+
let agentId;
|
|
877
|
+
let jsonOutput = false;
|
|
878
|
+
for (let i = 0; i < args.length; i++) {
|
|
879
|
+
const a = args[i];
|
|
880
|
+
// Reject empty/`--`-leading values so a following flag is never consumed
|
|
881
|
+
// as a value (codex gpt-5.6-sol P3, 2026-07-18).
|
|
882
|
+
if (a === '--agent') {
|
|
883
|
+
const v = args[++i];
|
|
884
|
+
if (!v || v.startsWith('--')) {
|
|
885
|
+
process.stderr.write('yolo mcp scopes: --agent requires a value\n');
|
|
886
|
+
return 64;
|
|
887
|
+
}
|
|
888
|
+
agentId = v;
|
|
889
|
+
}
|
|
890
|
+
else if (a.startsWith('--agent=')) {
|
|
891
|
+
const v = a.slice('--agent='.length);
|
|
892
|
+
if (!v) {
|
|
893
|
+
process.stderr.write('yolo mcp scopes: --agent requires a value\n');
|
|
894
|
+
return 64;
|
|
895
|
+
}
|
|
896
|
+
agentId = v;
|
|
897
|
+
}
|
|
898
|
+
else if (a === '--json')
|
|
899
|
+
jsonOutput = true;
|
|
900
|
+
else {
|
|
901
|
+
process.stderr.write(`yolo mcp scopes: unexpected argument '${a}'\nUsage: yolo mcp scopes [--agent <agentId>] [--json]\n`);
|
|
902
|
+
return 64;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
const { runMcpScopes, exitCodeForFailure } = await import('./mcp-scopes.js');
|
|
906
|
+
const result = await runMcpScopes({ agentId, outputFormat: jsonOutput ? 'json' : 'summary' });
|
|
907
|
+
if (result.ok) {
|
|
908
|
+
process.stdout.write(`${result.output}\n`);
|
|
909
|
+
return 0;
|
|
910
|
+
}
|
|
911
|
+
process.stderr.write(`FAIL [${result.kind}]: ${result.message}\n`);
|
|
912
|
+
return exitCodeForFailure(result.kind);
|
|
913
|
+
}
|
|
753
914
|
async function runTileAppSignCmd(args) {
|
|
754
915
|
let manifestPath;
|
|
755
916
|
let publisherId;
|
|
@@ -1375,12 +1536,28 @@ async function main(argv) {
|
|
|
1375
1536
|
return runTileAppValidateCmd(args.slice(2));
|
|
1376
1537
|
if (sub === 'dev')
|
|
1377
1538
|
return runTileAppDevCmd(args.slice(2));
|
|
1539
|
+
if (sub === 'install')
|
|
1540
|
+
return runTileAppInstallCmd(args.slice(2));
|
|
1541
|
+
if (sub === 'add-tile')
|
|
1542
|
+
return runTileAppAddTileCmd(args.slice(2));
|
|
1378
1543
|
if (!sub) {
|
|
1379
|
-
process.stderr.write('yolo: tileapp requires a subcommand (init, validate, dev, sign, publish)\n');
|
|
1544
|
+
process.stderr.write('yolo: tileapp requires a subcommand (init, validate, dev, sign, publish, install, add-tile)\n');
|
|
1380
1545
|
return 64;
|
|
1381
1546
|
}
|
|
1382
1547
|
process.stderr.write(`yolo: unknown tileapp subcommand '${sub}'\n`);
|
|
1383
|
-
process.stderr.write('Subcommands: init, validate, dev, sign, publish\n');
|
|
1548
|
+
process.stderr.write('Subcommands: init, validate, dev, sign, publish, install, add-tile\n');
|
|
1549
|
+
return 64;
|
|
1550
|
+
}
|
|
1551
|
+
if (cmd === 'mcp') {
|
|
1552
|
+
const sub = args[1];
|
|
1553
|
+
if (sub === 'scopes')
|
|
1554
|
+
return runMcpScopesCmd(args.slice(2));
|
|
1555
|
+
if (!sub) {
|
|
1556
|
+
process.stderr.write('yolo: mcp requires a subcommand (scopes)\n');
|
|
1557
|
+
return 64;
|
|
1558
|
+
}
|
|
1559
|
+
process.stderr.write(`yolo: unknown mcp subcommand '${sub}'\n`);
|
|
1560
|
+
process.stderr.write('Subcommands: scopes\n');
|
|
1384
1561
|
return 64;
|
|
1385
1562
|
}
|
|
1386
1563
|
if (cmd === 'serve') {
|
package/dist/deploy-client.js
CHANGED
|
@@ -92,6 +92,26 @@ export async function uploadAssetBucket(ctx, projectId, shipId, files) {
|
|
|
92
92
|
* success | 409 awaiting-approval (T3 prod gate — NOT an error)
|
|
93
93
|
* | 410 upload-expired (ship session lapsed → rerun)
|
|
94
94
|
*/
|
|
95
|
+
/**
|
|
96
|
+
* Best-effort substrate run-context headers for the finalize leg. When `yolo
|
|
97
|
+
* deploy` runs inside a Plan-Run lane the pod env carries the run ids, so we
|
|
98
|
+
* forward them and the server stamps release PROVENANCE — letting an auditor
|
|
99
|
+
* walk a live URL back to the run that shipped it. These are CLIENT-ASSERTED
|
|
100
|
+
* over the user JWT (NOT cryptographically bound like the MCP token path), so
|
|
101
|
+
* the server records them as `source: 'cli-env'`: unverified audit metadata,
|
|
102
|
+
* never authorizing. Omitted entirely for an interactive `yolo deploy` run
|
|
103
|
+
* outside a lane (none of the vars set).
|
|
104
|
+
*/
|
|
105
|
+
export function runContextHeaders(env) {
|
|
106
|
+
const headers = {};
|
|
107
|
+
if (env.YOLO_RUN_PLAN_ID)
|
|
108
|
+
headers['X-Yolo-Run-Plan-Id'] = env.YOLO_RUN_PLAN_ID;
|
|
109
|
+
if (env.YOLO_RUN_STEP_RUN_ID)
|
|
110
|
+
headers['X-Yolo-Run-Step-Run-Id'] = env.YOLO_RUN_STEP_RUN_ID;
|
|
111
|
+
if (env.SESSION_ID)
|
|
112
|
+
headers['X-Yolo-Session-Id'] = env.SESSION_ID;
|
|
113
|
+
return headers;
|
|
114
|
+
}
|
|
95
115
|
export async function finalizeShip(ctx, projectId, shipId, modules = [], sourceMap) {
|
|
96
116
|
// NOT auto-retried (unlike ship/start + assets). finalize is single-shot per
|
|
97
117
|
// ship session: if the first request reached the server and created the
|
|
@@ -107,6 +127,8 @@ export async function finalizeShip(ctx, projectId, shipId, modules = [], sourceM
|
|
|
107
127
|
if (!fetchImpl)
|
|
108
128
|
return noFetchFailure();
|
|
109
129
|
const url = `${stripTrailingSlash(ctx.commonApiUrl)}/v1/deploy/projects/${enc(projectId)}/ship/${enc(shipId)}/finalize`;
|
|
130
|
+
// Substrate run-context provenance headers (best-effort; empty outside a lane).
|
|
131
|
+
const runHeaders = runContextHeaders(ctx.env);
|
|
110
132
|
let response;
|
|
111
133
|
try {
|
|
112
134
|
if (modules.length > 0) {
|
|
@@ -122,14 +144,14 @@ export async function finalizeShip(ctx, projectId, shipId, modules = [], sourceM
|
|
|
122
144
|
// No explicit Content-Type — fetch sets the multipart boundary itself.
|
|
123
145
|
response = await fetchImpl(url, {
|
|
124
146
|
method: 'POST',
|
|
125
|
-
headers: { Authorization: `Bearer ${token}
|
|
147
|
+
headers: { Authorization: `Bearer ${token}`, ...runHeaders },
|
|
126
148
|
body: form,
|
|
127
149
|
});
|
|
128
150
|
}
|
|
129
151
|
else {
|
|
130
152
|
response = await fetchImpl(url, {
|
|
131
153
|
method: 'POST',
|
|
132
|
-
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
|
|
154
|
+
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json', ...runHeaders },
|
|
133
155
|
body: JSON.stringify({}),
|
|
134
156
|
});
|
|
135
157
|
}
|
|
@@ -210,7 +232,13 @@ export async function listProjects(ctx) {
|
|
|
210
232
|
}
|
|
211
233
|
/** POST /v1/deploy/projects/:id/rollback */
|
|
212
234
|
export async function rollbackProject(ctx, projectId, request = {}) {
|
|
213
|
-
|
|
235
|
+
// Rollback is a prod re-activation — forward run-context so the server can
|
|
236
|
+
// stamp `rollback.provenance` (same audit basis as a ship's finalize leg).
|
|
237
|
+
return jsonLeg(ctx, `/deploy/projects/${enc(projectId)}/rollback`, {
|
|
238
|
+
method: 'POST',
|
|
239
|
+
jsonBody: request,
|
|
240
|
+
headers: runContextHeaders(ctx.env),
|
|
241
|
+
});
|
|
214
242
|
}
|
|
215
243
|
/** POST /v1/deploy/projects/:id/unpublish — take a live project offline (reversible). */
|
|
216
244
|
export async function unpublishProject(ctx, projectId) {
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `yolo mcp scopes` — inspect what the current session principal can mint.
|
|
3
|
+
*
|
|
4
|
+
* Calls GET /internal/mcp/scopes (a pure read — nothing is minted) with the
|
|
5
|
+
* user JWT, the same auth contract as the token mint the CLI already uses
|
|
6
|
+
* (`mintSubstrateToken`). The server partitions ALL known MCP scopes by the
|
|
7
|
+
* agent's registry `allowedScopes` and returns
|
|
8
|
+
* `{ agentId, allowed: [...], denied: [...] }`.
|
|
9
|
+
*
|
|
10
|
+
* `--agent <agentId>` inspects another HTTP-mintable agent identity
|
|
11
|
+
* (default: substrate-cli, the CLI's own principal).
|
|
12
|
+
*
|
|
13
|
+
* Exit codes: 0 success · 1 http · 64 usage/auth.
|
|
14
|
+
*/
|
|
15
|
+
import { resolveSubstrateContext } from './auth-context.js';
|
|
16
|
+
import { SUBSTRATE_CLI_AGENT_ID } from './work-client.js';
|
|
17
|
+
export async function runMcpScopes(options) {
|
|
18
|
+
const env = options.env ?? process.env;
|
|
19
|
+
const format = options.outputFormat ?? 'summary';
|
|
20
|
+
const agentId = options.agentId ?? SUBSTRATE_CLI_AGENT_ID;
|
|
21
|
+
const auth = resolveSubstrateContext(env);
|
|
22
|
+
if (!auth.ok)
|
|
23
|
+
return fail('auth', auth.message);
|
|
24
|
+
const { sessionId, commonApiUrl, userToken } = auth.context;
|
|
25
|
+
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
26
|
+
const base = commonApiUrl.replace(/\/$/, '');
|
|
27
|
+
const url = `${base}/internal/mcp/scopes?sessionId=${encodeURIComponent(sessionId)}&agentId=${encodeURIComponent(agentId)}`;
|
|
28
|
+
let json;
|
|
29
|
+
try {
|
|
30
|
+
const response = await fetchImpl(url, {
|
|
31
|
+
method: 'GET',
|
|
32
|
+
headers: { Authorization: `Bearer ${userToken}` },
|
|
33
|
+
});
|
|
34
|
+
if (!response.ok) {
|
|
35
|
+
const text = await safeReadText(response);
|
|
36
|
+
return fail('http', `mcp.scopes failed: HTTP ${response.status} — ${text}`, { status: response.status });
|
|
37
|
+
}
|
|
38
|
+
json = (await response.json());
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
return fail('http', `mcp.scopes request failed: ${describeError(err)}`);
|
|
42
|
+
}
|
|
43
|
+
if (!Array.isArray(json.allowed) || !Array.isArray(json.denied)) {
|
|
44
|
+
return fail('http', 'mcp.scopes response missing `allowed`/`denied` arrays');
|
|
45
|
+
}
|
|
46
|
+
const allowed = json.allowed.filter((s) => typeof s === 'string');
|
|
47
|
+
const denied = json.denied.filter((s) => typeof s === 'string');
|
|
48
|
+
const resolvedAgentId = typeof json.agentId === 'string' && json.agentId ? json.agentId : agentId;
|
|
49
|
+
return {
|
|
50
|
+
ok: true,
|
|
51
|
+
output: format === 'json'
|
|
52
|
+
? JSON.stringify({ agentId: resolvedAgentId, allowed, denied }, null, 2)
|
|
53
|
+
: formatSummary(resolvedAgentId, sessionId, allowed, denied),
|
|
54
|
+
agentId: resolvedAgentId,
|
|
55
|
+
allowed,
|
|
56
|
+
denied,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
// ── Output formatting ─────────────────────────────────────────────────────
|
|
60
|
+
export function formatSummary(agentId, sessionId, allowed, denied) {
|
|
61
|
+
const lines = [];
|
|
62
|
+
lines.push(`Mintable MCP scopes for agent '${agentId}' (session ${sessionId}):`);
|
|
63
|
+
lines.push(`Allowed (${allowed.length}):`);
|
|
64
|
+
lines.push(...(allowed.length > 0 ? allowed.map((s) => ` - ${s}`) : [' (none)']));
|
|
65
|
+
lines.push(`Not mintable (${denied.length}):`);
|
|
66
|
+
lines.push(...(denied.length > 0 ? denied.map((s) => ` - ${s}`) : [' (none)']));
|
|
67
|
+
return lines.join('\n');
|
|
68
|
+
}
|
|
69
|
+
// ── Helpers ───────────────────────────────────────────────────────────────
|
|
70
|
+
function fail(kind, message, detail) {
|
|
71
|
+
return { ok: false, kind, message, detail };
|
|
72
|
+
}
|
|
73
|
+
function describeError(err) {
|
|
74
|
+
return err instanceof Error ? err.message : String(err);
|
|
75
|
+
}
|
|
76
|
+
async function safeReadText(response) {
|
|
77
|
+
try {
|
|
78
|
+
return await response.text();
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return '<no body>';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export function exitCodeForFailure(kind) {
|
|
85
|
+
return kind === 'http' ? 1 : 64;
|
|
86
|
+
}
|
|
@@ -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.32.0",
|
|
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",
|