@yolo-labs/yolo-cli 0.44.0 → 0.45.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yolo Labs, LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -64,3 +64,11 @@ stopping the service discards them. All commands accept `--json`.
64
64
  `yolo preview --help` lists polling, timeout, port and health-check options. New CLI,
65
65
  API, agent-registry scopes and container-api versions must be deployed together;
66
66
  older deployments return an error rather than run a different preview mode.
67
+
68
+ ## Source & contributing
69
+
70
+ [github.com/yolo-labs-hq/yolo-cli](https://github.com/yolo-labs-hq/yolo-cli) is a public mirror of `packages/yolo-cli` in YOLO Labs' private monorepo, which stays the source of truth. The mirror is synced automatically on every change. Issues are welcome. Pull requests are welcome too: we apply them in the monorepo, keeping you as the author, and the change then syncs back here.
71
+
72
+ ## License
73
+
74
+ MIT. See [LICENSE](./LICENSE).
package/dist/cli.js CHANGED
@@ -62,6 +62,11 @@ function printHelp() {
62
62
  ' [--workspace <wsId>] Sanity-check the workspace bound to this session.',
63
63
  ' kanban import <boardId> <file> Rebuild a board from a seed document (additive; never overwrites).',
64
64
  ' [--workspace <wsId>] Sanity-check the workspace bound to this session.',
65
+ ' kanban models List the model ids a card can be pinned to, and whether each can run now.',
66
+ ' [--json] [--workspace <wsId>] Raw JSON instead of the table; sanity-check the workspace.',
67
+ ' git doctor [opts] Diagnose why git (not gh) can\'t authenticate to github.com.',
68
+ ' [--fix] Repair what is safe to (store file, helpers, remote URL), then re-check.',
69
+ ' [--offline] [--remote <name>] [--json] Skip network checks; remote to probe (default: origin); JSON output.',
65
70
  ' tileapp init <name> Scaffold a personal app (./<name>/tileapp.json + index.html).',
66
71
  ' tileapp validate <manifest> [opts] Offline lint: manifest schema + bundle layout (no auth).',
67
72
  ' tileapp media push <manifest> [--dir d] Upload store screenshots (additive — leaves the rest of the bundle alone).',
@@ -737,6 +742,10 @@ async function main(argv) {
737
742
  process.stderr.write('Subcommands: init, validate, dev, sign, publish, media, install, add-tile\n');
738
743
  return 64;
739
744
  }
745
+ if (cmd === 'git') {
746
+ const { runGitCmd } = await import('./git-doctor.js');
747
+ return runGitCmd(args.slice(1));
748
+ }
740
749
  if (cmd === 'kanban') {
741
750
  const { runKanbanCmd } = await import('./kanban-cli.js');
742
751
  return runKanbanCmd(args.slice(1));
@@ -0,0 +1,458 @@
1
+ /**
2
+ * `yolo git doctor [--fix]` — diagnose, and optionally repair, how git in this
3
+ * workspace authenticates to github.com over HTTPS.
4
+ *
5
+ * git and `gh` resolve credentials differently. `gh` (the /usr/local/bin
6
+ * wrapper) re-reads ~/.yolo-env on every call, so it always holds the current
7
+ * token. git asks its credential helpers: `store` (~/.git-credentials), then
8
+ * the github.com-scoped `gh auth git-credential` fallback from setup-git.sh.
9
+ * When the two disagree, `gh` works and `git push` fails with "could not read
10
+ * Username" — which is what a root exec leaving ~/.git-credentials root-owned
11
+ * 0600 looked like (the lane-gc probe, until #1181). This command looks at
12
+ * every link in git's chain and says which one is broken.
13
+ *
14
+ * Checks: the token (and, online, whether GitHub accepts it), the store file
15
+ * (present, readable, owned by the HOME owner, 0600, holding the current
16
+ * token), the helper config, the push URL of the remote, and — online, in a
17
+ * repository — a real `git ls-remote`.
18
+ *
19
+ * --fix repairs what it safely can, then re-runs every check:
20
+ * - rewrites ~/.git-credentials from the current token by temp file + rename
21
+ * (a rename replaces a file we cannot write through; we own the directory),
22
+ * keeping readable non-github lines, or the forge line from the pod env
23
+ * - sets `credential.helper store` / the github.com gh fallback if missing
24
+ * - strips credentials embedded in a github.com remote URL
25
+ * It only writes a token GitHub accepted in this run, and never while the
26
+ * Auth V2 purge fence is up: that fence means GitHub access was withdrawn, and
27
+ * reinstalling the token would undo the revocation.
28
+ *
29
+ * Tokens are never printed; they are masked to prefix…last4.
30
+ *
31
+ * Exit codes: 0 = no failing check; 1 = a check still fails; 64 = usage.
32
+ */
33
+ import * as fs from 'node:fs';
34
+ import * as path from 'node:path';
35
+ import { spawnSync } from 'node:child_process';
36
+ export const GIT_DOCTOR_HELP = `Usage: yolo git doctor [--fix] [--offline] [--remote <name>] [--json]
37
+
38
+ Diagnose why git (not gh) can't authenticate to github.com over HTTPS.
39
+
40
+ --fix Repair what can be repaired safely, then re-check.
41
+ --offline Skip the GitHub API token check and git ls-remote.
42
+ (--fix won't rewrite ~/.git-credentials without the token check.)
43
+ --remote <name> Remote to inspect and probe (default: origin).
44
+ --json Print {checks, fixed} as JSON.
45
+ `;
46
+ const GH_FALLBACK_KEY = 'credential.https://github.com.helper';
47
+ const GH_FALLBACK_VALUE = '!gh auth git-credential';
48
+ const GITHUB_LINE = /^https:\/\/[^:@/\s]+:([^@\s]+)@github\.com\/?$/;
49
+ /** prefix…last4, so two tokens can be told apart without either being shown. */
50
+ export function maskToken(token) {
51
+ if (token.length <= 12)
52
+ return '****';
53
+ const prefix = /^(github_pat_|gh[pousr]_)/.exec(token)?.[1] ?? token.slice(0, 4);
54
+ return `${prefix}…${token.slice(-4)}`;
55
+ }
56
+ /** Mask anything token-shaped in free text (git stderr, URLs). */
57
+ export function redact(text) {
58
+ return text
59
+ .replace(/(github_pat_|gh[pousr]_)[A-Za-z0-9_]+/g, (t) => maskToken(t))
60
+ .replace(/(\/\/[^:@/\s]+:)[^@\s]+@/g, '$1****@');
61
+ }
62
+ /**
63
+ * The token `gh` would use: the wrapper sources ~/.yolo-env over the process
64
+ * env, then falls back from GH_TOKEN to GITHUB_TOKEN.
65
+ */
66
+ export function resolveToken(env, home) {
67
+ const file = env.YOLO_ENV_FILE || path.join(home, '.yolo-env');
68
+ const fromFile = {};
69
+ try {
70
+ for (const line of fs.readFileSync(file, 'utf8').split('\n')) {
71
+ const m = /^export (GH_TOKEN|GITHUB_TOKEN)='([^']*)'$/.exec(line.trim());
72
+ if (m && m[2])
73
+ fromFile[m[1]] = m[2];
74
+ }
75
+ }
76
+ catch { /* no ~/.yolo-env */ }
77
+ const candidates = [
78
+ [fromFile.GH_TOKEN, 'GH_TOKEN (~/.yolo-env)'],
79
+ [env.GH_TOKEN, 'GH_TOKEN (env)'],
80
+ [fromFile.GITHUB_TOKEN, 'GITHUB_TOKEN (~/.yolo-env)'],
81
+ [env.GITHUB_TOKEN, 'GITHUB_TOKEN (env)'],
82
+ ];
83
+ for (const [token, source] of candidates)
84
+ if (token)
85
+ return { token, source };
86
+ return { source: 'none' };
87
+ }
88
+ function defaultGit(cwd, env) {
89
+ return (args, opts = {}) => {
90
+ const r = spawnSync('git', args, {
91
+ cwd,
92
+ env: { ...env, GIT_TERMINAL_PROMPT: '0' },
93
+ encoding: 'utf8',
94
+ timeout: opts.timeoutMs ?? 10_000,
95
+ });
96
+ return { status: r.status, stdout: r.stdout ?? '', stderr: r.stderr ?? (r.error ? String(r.error.message) : '') };
97
+ };
98
+ }
99
+ function defaultHasCommand(env) {
100
+ return (name) => (env.PATH ?? '').split(':').some((dir) => {
101
+ try {
102
+ fs.accessSync(path.join(dir, name), fs.constants.X_OK);
103
+ return true;
104
+ }
105
+ catch {
106
+ return false;
107
+ }
108
+ });
109
+ }
110
+ function getAll(git, args) {
111
+ const r = git(['config', ...args]);
112
+ // One value per line; an empty value (the anonymous-mode reset) is a blank line.
113
+ return r.status === 0 ? r.stdout.replace(/\n$/, '').split('\n') : [];
114
+ }
115
+ async function checkToken(ctx, d) {
116
+ const { token, source } = resolveToken(ctx.env, ctx.home);
117
+ if (!token) {
118
+ d.checks.push({ id: 'token', status: 'fail', detail: 'no GitHub token (GH_TOKEN / GITHUB_TOKEN, env or ~/.yolo-env)' });
119
+ return undefined;
120
+ }
121
+ const label = `${maskToken(token)} from ${source}`;
122
+ if (ctx.opts.offline) {
123
+ d.checks.push({ id: 'token', status: 'skip', detail: `${label}; not verified (--offline)` });
124
+ return token;
125
+ }
126
+ try {
127
+ const res = await ctx.fetchImpl('https://api.github.com/user', {
128
+ headers: { Authorization: `token ${token}`, 'User-Agent': 'yolo-git-doctor', Accept: 'application/vnd.github+json' },
129
+ });
130
+ if (res.status === 200) {
131
+ const login = (await res.json())?.login ?? '?';
132
+ const scopes = res.headers.get('x-oauth-scopes');
133
+ const expires = res.headers.get('github-authentication-token-expiration');
134
+ d.acceptedToken = token;
135
+ d.checks.push({ id: 'token', status: 'ok', detail: `${label}: ${login}` +
136
+ (scopes !== null ? `, scopes: ${scopes || '(none)'}` : '') + (expires ? `, expires ${expires}` : '') });
137
+ }
138
+ else if (res.status === 401) {
139
+ d.checks.push({ id: 'token', status: 'fail', detail: `${label}: GitHub rejected it (401: revoked or expired)` });
140
+ }
141
+ else {
142
+ d.checks.push({ id: 'token', status: 'warn', detail: `${label}: GitHub API answered ${res.status}` });
143
+ }
144
+ }
145
+ catch (err) {
146
+ d.checks.push({ id: 'token', status: 'warn', detail: `${label}: could not reach the GitHub API (${err.message})` });
147
+ }
148
+ return token;
149
+ }
150
+ function describeOwner(st) {
151
+ return `uid ${st.uid}:${st.gid}, mode ${(st.mode & 0o777).toString(8)}`;
152
+ }
153
+ function checkCredentialsFile(ctx, d, token) {
154
+ const file = path.join(ctx.home, '.git-credentials');
155
+ let st;
156
+ try {
157
+ st = fs.statSync(file);
158
+ }
159
+ catch {
160
+ d.checks.push({ id: 'credentials-file', status: 'fail', detail: '~/.git-credentials does not exist' });
161
+ d.credsNeedRewrite = true;
162
+ return;
163
+ }
164
+ let content;
165
+ try {
166
+ content = fs.readFileSync(file, 'utf8');
167
+ }
168
+ catch (err) {
169
+ d.checks.push({ id: 'credentials-file', status: 'fail', detail: `~/.git-credentials is not readable by uid ${ctx.getuid()} (${describeOwner(st)}): git's store helper finds nothing` });
170
+ d.credsNeedRewrite = true;
171
+ return;
172
+ }
173
+ const problems = [];
174
+ let status = 'ok';
175
+ let homeUid;
176
+ try {
177
+ homeUid = fs.statSync(ctx.home).uid;
178
+ }
179
+ catch { /* leave undefined */ }
180
+ if (homeUid !== undefined && st.uid !== homeUid) {
181
+ problems.push(`owned by uid ${st.uid}, not the HOME owner (uid ${homeUid})`);
182
+ status = 'warn';
183
+ d.credsNeedRewrite = true;
184
+ }
185
+ if ((st.mode & 0o077) !== 0) {
186
+ problems.push(`mode ${(st.mode & 0o777).toString(8)} is readable by others (want 600)`);
187
+ status = 'warn';
188
+ d.credsNeedRewrite = true;
189
+ }
190
+ const stored = content.split('\n').map((l) => GITHUB_LINE.exec(l.trim())?.[1]).filter(Boolean);
191
+ if (stored.length === 0) {
192
+ problems.push('has no github.com line');
193
+ status = 'fail';
194
+ d.credsNeedRewrite = true;
195
+ }
196
+ else if (token && !stored.includes(token)) {
197
+ problems.push(`github.com token ${maskToken(stored[0])} is not the current token ${maskToken(token)}`);
198
+ if (status === 'ok')
199
+ status = 'warn';
200
+ d.credsNeedRewrite = true;
201
+ }
202
+ d.checks.push({ id: 'credentials-file', status, detail: problems.length
203
+ ? `~/.git-credentials ${problems.join('; ')}`
204
+ : `~/.git-credentials readable, 0600, holds the current github.com token` });
205
+ }
206
+ function checkHelpers(ctx, d) {
207
+ const helpers = getAll(ctx.git, ['--global', '--get-all', 'credential.helper']);
208
+ const fallback = getAll(ctx.git, ['--global', '--get-all', GH_FALLBACK_KEY]);
209
+ const problems = [];
210
+ let status = 'ok';
211
+ if (!helpers.includes('store')) {
212
+ problems.push(`global credential.helper is ${helpers.length ? helpers.map((h) => `'${h}'`).join(', ') : 'unset'}, not 'store'`);
213
+ status = 'fail';
214
+ d.needStoreHelper = true;
215
+ }
216
+ if (helpers.length > 1) {
217
+ problems.push(`credential.helper has ${helpers.length} values; the setup scripts' \`git config --global credential.helper store\` exits 5 on that`);
218
+ if (status === 'ok')
219
+ status = 'warn';
220
+ }
221
+ if (!fallback.includes(GH_FALLBACK_VALUE)) {
222
+ if (ctx.hasCommand('gh')) {
223
+ problems.push(`no github.com gh fallback (${GH_FALLBACK_KEY})`);
224
+ d.needFallback = true;
225
+ }
226
+ else {
227
+ problems.push('no github.com gh fallback, and gh is not on PATH');
228
+ }
229
+ if (status === 'ok')
230
+ status = 'warn';
231
+ }
232
+ if (d.inRepo) {
233
+ const local = getAll(ctx.git, ['--local', '--get-all', 'credential.helper']);
234
+ if (local.includes('')) {
235
+ problems.push("this repository resets credential.helper to '' (anonymous mode): git sends no credentials here");
236
+ if (status === 'ok')
237
+ status = 'warn';
238
+ }
239
+ }
240
+ d.checks.push({ id: 'helper', status, detail: problems.length ? problems.join('; ')
241
+ : `store, then ${GH_FALLBACK_VALUE} for github.com` });
242
+ }
243
+ function checkRemote(ctx, d) {
244
+ if (!d.inRepo) {
245
+ d.checks.push({ id: 'remote', status: 'skip', detail: 'not inside a git repository' });
246
+ return;
247
+ }
248
+ const name = ctx.opts.remote;
249
+ const url = ctx.git(['remote', 'get-url', '--push', name]);
250
+ if (url.status !== 0) {
251
+ d.checks.push({ id: 'remote', status: 'skip', detail: `no remote named '${name}'` });
252
+ return;
253
+ }
254
+ const pushUrl = url.stdout.trim();
255
+ const m = /^https:\/\/([^@/]+)@(github\.com\/.*)$/.exec(pushUrl);
256
+ if (m) {
257
+ const hasPushUrl = getAll(ctx.git, ['--get-all', `remote.${name}.pushurl`]).length > 0;
258
+ d.embeddedUrl = { key: hasPushUrl ? 'pushurl' : 'url', clean: `https://${m[2]}` };
259
+ d.checks.push({ id: 'remote', status: 'warn', detail: `${name} push URL embeds credentials (${redact(pushUrl)}); they override the credential helpers and go stale` });
260
+ }
261
+ else if (/^(git@|ssh:\/\/)/.test(pushUrl)) {
262
+ d.checks.push({ id: 'remote', status: 'ok', detail: `${name} pushes over SSH (${pushUrl}); HTTPS credentials aren't used for it` });
263
+ }
264
+ else {
265
+ d.checks.push({ id: 'remote', status: 'ok', detail: `${name} → ${redact(pushUrl)}` });
266
+ }
267
+ }
268
+ function checkLsRemote(ctx, d) {
269
+ if (ctx.opts.offline) {
270
+ d.checks.push({ id: 'ls-remote', status: 'skip', detail: 'skipped (--offline)' });
271
+ return;
272
+ }
273
+ if (!d.inRepo || d.checks.find((c) => c.id === 'remote')?.status === 'skip') {
274
+ d.checks.push({ id: 'ls-remote', status: 'skip', detail: 'no remote to probe' });
275
+ return;
276
+ }
277
+ // ls-remote authenticates like a fetch; a push additionally needs push rights,
278
+ // which the token check's repo scope covers.
279
+ const r = ctx.git(['ls-remote', '--exit-code', ctx.opts.remote, 'HEAD'], { timeoutMs: 20_000 });
280
+ if (r.status === 0) {
281
+ d.checks.push({ id: 'ls-remote', status: 'ok', detail: `git ls-remote ${ctx.opts.remote} authenticated` });
282
+ }
283
+ else {
284
+ const last = redact(r.stderr.trim().split('\n').filter(Boolean).pop() ?? `exit ${r.status}`);
285
+ d.checks.push({ id: 'ls-remote', status: 'fail', detail: `git ls-remote ${ctx.opts.remote} failed: ${last}` });
286
+ }
287
+ }
288
+ async function diagnose(ctx) {
289
+ const inRepo = ctx.git(['rev-parse', '--is-inside-work-tree']).stdout.trim() === 'true';
290
+ const d = { checks: [], inRepo, credsNeedRewrite: false, needStoreHelper: false, needFallback: false };
291
+ const token = await checkToken(ctx, d);
292
+ checkCredentialsFile(ctx, d, token);
293
+ checkHelpers(ctx, d);
294
+ checkRemote(ctx, d);
295
+ checkLsRemote(ctx, d);
296
+ return d;
297
+ }
298
+ /** Temp file + rename: replaces a file we can't write through, as long as we own the directory. */
299
+ function writeCredentialsFile(ctx, token) {
300
+ const file = path.join(ctx.home, '.git-credentials');
301
+ let others;
302
+ try {
303
+ others = fs.readFileSync(file, 'utf8').split('\n').filter((l) => l.trim() && !/@github\.com\/?$/.test(l.trim()));
304
+ }
305
+ catch {
306
+ const { FORGEJO_TOKEN, FORGEJO_HOST } = ctx.env;
307
+ others = FORGEJO_TOKEN && FORGEJO_HOST ? [`https://oauth2:${FORGEJO_TOKEN}@${FORGEJO_HOST}`] : [];
308
+ }
309
+ const content = [`https://oauth2:${token}@github.com`, ...others].join('\n') + '\n';
310
+ const tmp = `${file}.${process.pid}.${Date.now()}.tmp`;
311
+ try {
312
+ fs.writeFileSync(tmp, content, { mode: 0o600, flag: 'wx' });
313
+ if (ctx.getuid() === 0) {
314
+ const owner = fs.statSync(ctx.home);
315
+ fs.chownSync(tmp, owner.uid, owner.gid);
316
+ }
317
+ fs.renameSync(tmp, file);
318
+ }
319
+ finally {
320
+ try {
321
+ fs.unlinkSync(tmp);
322
+ }
323
+ catch { /* renamed */ }
324
+ }
325
+ }
326
+ function fencePath(home) {
327
+ return path.join(home, '.yolo', 'auth-v2-github-purge-fence.json');
328
+ }
329
+ function applyFixes(ctx, d) {
330
+ const fixed = [];
331
+ const refused = [];
332
+ if (d.credsNeedRewrite) {
333
+ if (fs.existsSync(fencePath(ctx.home))) {
334
+ refused.push('~/.git-credentials: GitHub access was withdrawn (Auth V2 purge fence is up); not reinstalling the token');
335
+ }
336
+ else if (!d.acceptedToken) {
337
+ refused.push(ctx.opts.offline
338
+ ? '~/.git-credentials: not rewritten under --offline (the token must be verified first)'
339
+ : '~/.git-credentials: not rewritten, because GitHub did not accept the current token');
340
+ }
341
+ else {
342
+ try {
343
+ writeCredentialsFile(ctx, d.acceptedToken);
344
+ fixed.push(`rewrote ~/.git-credentials with ${maskToken(d.acceptedToken)}, 0600, owned by the HOME owner`);
345
+ }
346
+ catch (err) {
347
+ refused.push(`~/.git-credentials: rewrite failed (${err.message})`);
348
+ }
349
+ }
350
+ }
351
+ if (d.needStoreHelper) {
352
+ // --add keeps any other helper the user configured; a single value becomes 'store'.
353
+ const hasAny = getAll(ctx.git, ['--global', '--get-all', 'credential.helper']).length > 0;
354
+ const r = ctx.git(['config', '--global', ...(hasAny ? ['--add'] : []), 'credential.helper', 'store']);
355
+ (r.status === 0 ? fixed : refused).push(r.status === 0 ? "set global credential.helper 'store'"
356
+ : `credential.helper: git config failed (${r.stderr.trim()})`);
357
+ }
358
+ if (d.needFallback) {
359
+ const r = ctx.git(['config', '--global', GH_FALLBACK_KEY, GH_FALLBACK_VALUE]);
360
+ (r.status === 0 ? fixed : refused).push(r.status === 0 ? `set ${GH_FALLBACK_KEY} '${GH_FALLBACK_VALUE}'`
361
+ : `${GH_FALLBACK_KEY}: git config failed (${r.stderr.trim()})`);
362
+ }
363
+ if (d.embeddedUrl) {
364
+ const { key, clean } = d.embeddedUrl;
365
+ const args = key === 'url' ? ['remote', 'set-url', ctx.opts.remote, clean] : ['remote', 'set-url', '--push', ctx.opts.remote, clean];
366
+ const r = ctx.git(args);
367
+ (r.status === 0 ? fixed : refused).push(r.status === 0 ? `removed credentials from ${ctx.opts.remote} ${key} (${clean})`
368
+ : `remote ${key}: git remote set-url failed (${redact(r.stderr.trim())})`);
369
+ }
370
+ return { fixed, refused };
371
+ }
372
+ const ICON = { ok: '✓', warn: '!', fail: '✗', skip: '-' };
373
+ export function parseGitDoctorArgs(args) {
374
+ const opts = { fix: false, json: false, offline: false, remote: 'origin' };
375
+ for (let i = 0; i < args.length; i++) {
376
+ const a = args[i];
377
+ if (a === '--fix')
378
+ opts.fix = true;
379
+ else if (a === '--json')
380
+ opts.json = true;
381
+ else if (a === '--offline')
382
+ opts.offline = true;
383
+ else if (a === '--remote') {
384
+ const v = args[++i];
385
+ if (!v || v.startsWith('-'))
386
+ return { error: '--remote needs a value' };
387
+ opts.remote = v;
388
+ }
389
+ else
390
+ return { error: `unknown option '${a}'` };
391
+ }
392
+ return opts;
393
+ }
394
+ export async function runGitDoctor(opts, deps = {}) {
395
+ const env = deps.env ?? process.env;
396
+ const home = deps.home ?? env.HOME ?? '/home/yolo';
397
+ const cwd = deps.cwd ?? process.cwd();
398
+ const out = deps.stdout ?? ((t) => process.stdout.write(t));
399
+ const ctx = {
400
+ env,
401
+ home,
402
+ git: deps.git ?? defaultGit(cwd, { ...env, HOME: home }),
403
+ fetchImpl: deps.fetchImpl ?? globalThis.fetch,
404
+ getuid: deps.getuid ?? (() => process.getuid?.() ?? -1),
405
+ hasCommand: deps.hasCommand ?? defaultHasCommand(env),
406
+ opts,
407
+ };
408
+ let d = await diagnose(ctx);
409
+ let fixed = [];
410
+ let refused = [];
411
+ if (opts.fix) {
412
+ ({ fixed, refused } = applyFixes(ctx, d));
413
+ if (fixed.length)
414
+ d = await diagnose(ctx);
415
+ }
416
+ const failing = d.checks.filter((c) => c.status === 'fail').length;
417
+ if (opts.json) {
418
+ out(JSON.stringify({ checks: d.checks, fixed, refused }, null, 2) + '\n');
419
+ return failing ? 1 : 0;
420
+ }
421
+ const width = Math.max(...d.checks.map((c) => c.id.length));
422
+ const lines = ['yolo git doctor', ...d.checks.map((c) => ` ${ICON[c.status]} ${c.id.padEnd(width)} ${c.detail}`)];
423
+ if (fixed.length)
424
+ lines.push('', 'Fixed:', ...fixed.map((f) => ` - ${f}`));
425
+ if (refused.length)
426
+ lines.push('', 'Not fixed:', ...refused.map((f) => ` - ${f}`));
427
+ const warns = d.checks.filter((c) => c.status === 'warn').length;
428
+ lines.push('');
429
+ if (failing) {
430
+ lines.push(`${failing} failing check${failing > 1 ? 's' : ''}.` + (opts.fix ? '' : ' Run `yolo git doctor --fix` to repair.'));
431
+ }
432
+ else if (warns) {
433
+ lines.push(`No failures; ${warns} warning${warns > 1 ? 's' : ''}.` + (opts.fix ? '' : ' `yolo git doctor --fix` repairs the fixable ones.'));
434
+ }
435
+ else {
436
+ lines.push('git can authenticate to github.com.');
437
+ }
438
+ out(lines.join('\n') + '\n');
439
+ return failing ? 1 : 0;
440
+ }
441
+ export async function runGitCmd(args, deps = {}) {
442
+ const err = deps.stderr ?? ((t) => process.stderr.write(t));
443
+ const out = deps.stdout ?? ((t) => process.stdout.write(t));
444
+ if (args[0] !== 'doctor') {
445
+ err(args[0] ? `yolo git: unknown subcommand '${args[0]}'\n${GIT_DOCTOR_HELP}` : `yolo git: requires a subcommand (doctor)\n${GIT_DOCTOR_HELP}`);
446
+ return 64;
447
+ }
448
+ if (args.includes('--help') || args.includes('-h')) {
449
+ out(GIT_DOCTOR_HELP);
450
+ return 0;
451
+ }
452
+ const opts = parseGitDoctorArgs(args.slice(1));
453
+ if ('error' in opts) {
454
+ err(`yolo git doctor: ${opts.error}\n${GIT_DOCTOR_HELP}`);
455
+ return 64;
456
+ }
457
+ return runGitDoctor(opts, deps);
458
+ }
@@ -1,6 +1,8 @@
1
1
  /**
2
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.
3
+ * between a workspace and a file, with no model in the loop. Plus
4
+ * `yolo kanban models`, the pinnable model ids (`studio.kanban_list_models`
5
+ * from a shell, on the same user-token surface).
4
6
  *
5
7
  * A board lives in Mongo, scoped to a workspace that can wedge. The seed
6
8
  * document (`common-api/src/services/kanban-board-seed.ts`) is the only copy
@@ -144,6 +146,44 @@ export async function runKanbanImport(options) {
144
146
  workspaceId,
145
147
  };
146
148
  }
149
+ export async function runKanbanModels(options = {}) {
150
+ const env = options.env ?? process.env;
151
+ const resolved = resolveContext(env, options.workspaceFlag);
152
+ if (!resolved.ok)
153
+ return resolved.failure;
154
+ const { commonApiUrl, userToken, workspaceId } = resolved;
155
+ let response;
156
+ try {
157
+ response = await userRouteRequest({ commonApiUrl, userToken, fetchImpl: options.fetchImpl }, `/workspaces/${encodeURIComponent(workspaceId)}/kanban/models`, { method: 'GET' });
158
+ }
159
+ catch (err) {
160
+ return fail('http', `kanban.models.list failed: ${describeError(err)}`);
161
+ }
162
+ const body = await safeReadText(response);
163
+ if (!response.ok) {
164
+ return fail('http', `kanban.models.list failed: HTTP ${response.status} — ${body}`, { status: response.status });
165
+ }
166
+ if (options.json)
167
+ return { ok: true, output: body, raw: true, workspaceId };
168
+ return { ok: true, output: formatModels(body), raw: false, workspaceId };
169
+ }
170
+ /** One id per line — the value `model` takes — then whether it can run now and why not. */
171
+ export function formatModels(body) {
172
+ let models;
173
+ try {
174
+ models = JSON.parse(body).models ?? [];
175
+ }
176
+ catch {
177
+ return body;
178
+ }
179
+ if (models.length === 0)
180
+ return 'No models are discovered for this workspace right now.';
181
+ const idCol = Math.max(...models.map((m) => m.id.length));
182
+ return models.map((m) => {
183
+ const state = m.available ? 'available' : `unavailable${m.unavailableReason ? ` — ${m.unavailableReason}` : ''}`;
184
+ return `${m.id.padEnd(idCol)} ${m.isDefault ? 'default ' : ' '}${state}`;
185
+ }).join('\n');
186
+ }
147
187
  /**
148
188
  * `key → cardId`, one per line, under a count. That map is what a caller
149
189
  * needs to say anything at all about the board it just rebuilt, and it is
@@ -197,6 +237,48 @@ function resolveContext(env, workspaceFlag) {
197
237
  // ─── CLI surface ──────────────────────────────────────────────────────────
198
238
  const EXPORT_USAGE = 'Usage: yolo kanban export <tileId> [-o <file>] [--workspace <wsId>]\n';
199
239
  const IMPORT_USAGE = 'Usage: yolo kanban import <boardId> <file> [--workspace <wsId>]\n';
240
+ const MODELS_USAGE = 'Usage: yolo kanban models [--json] [--workspace <wsId>]\n';
241
+ const KANBAN_USAGE = [
242
+ 'Usage: yolo kanban <subcommand>',
243
+ '',
244
+ 'Subcommands:',
245
+ ' export <tileId> [-o <file>] Write a board\'s seed document to a file or stdout',
246
+ ' import <boardId> <file> Create cards on a board from a seed document',
247
+ ' models [--json] List the model ids a card can be pinned to',
248
+ '',
249
+ 'Every subcommand takes --workspace <wsId> (defaults to this session\'s workspace).',
250
+ '',
251
+ ].join('\n');
252
+ const isHelp = (a) => a === '--help' || a === '-h' || a === 'help';
253
+ export function parseKanbanModelsArgs(args) {
254
+ let json = false;
255
+ let workspaceFlag;
256
+ for (let i = 0; i < args.length; i++) {
257
+ const a = args[i];
258
+ if (a === '--json') {
259
+ json = true;
260
+ }
261
+ else if (a === '--workspace') {
262
+ const v = args[++i];
263
+ if (!v || v.startsWith('--'))
264
+ return { ok: false, message: '--workspace requires a value' };
265
+ workspaceFlag = v;
266
+ }
267
+ else if (a.startsWith('--workspace=')) {
268
+ const v = a.slice('--workspace='.length);
269
+ if (!v)
270
+ return { ok: false, message: '--workspace requires a value' };
271
+ workspaceFlag = v;
272
+ }
273
+ else if (a.startsWith('-')) {
274
+ return { ok: false, message: `unknown option: ${a}` };
275
+ }
276
+ else {
277
+ return { ok: false, message: `unexpected positional argument: ${a}` };
278
+ }
279
+ }
280
+ return { ok: true, json, workspaceFlag };
281
+ }
200
282
  export function parseKanbanExportArgs(args) {
201
283
  let tileId;
202
284
  let outFile;
@@ -271,6 +353,25 @@ export function parseKanbanImportArgs(args) {
271
353
  /** `args` is everything after `kanban`. */
272
354
  export async function runKanbanCmd(args) {
273
355
  const sub = args[0];
356
+ if (isHelp(sub)) {
357
+ process.stdout.write(KANBAN_USAGE);
358
+ return 0;
359
+ }
360
+ // `yolo kanban <sub> --help` prints that subcommand's usage rather than failing its parse.
361
+ const subUsage = sub === 'export' ? EXPORT_USAGE : sub === 'import' ? IMPORT_USAGE : sub === 'models' ? MODELS_USAGE : null;
362
+ if (subUsage && args.slice(1).some((a) => a === '--help' || a === '-h')) {
363
+ process.stdout.write(subUsage);
364
+ return 0;
365
+ }
366
+ if (sub === 'models') {
367
+ const parsed = parseKanbanModelsArgs(args.slice(1));
368
+ if (!parsed.ok) {
369
+ process.stderr.write(`yolo: kanban models: ${parsed.message}\n`);
370
+ process.stderr.write(MODELS_USAGE);
371
+ return 64;
372
+ }
373
+ return report(await runKanbanModels({ json: parsed.json, workspaceFlag: parsed.workspaceFlag }));
374
+ }
274
375
  if (sub === 'export') {
275
376
  const parsed = parseKanbanExportArgs(args.slice(1));
276
377
  if (!parsed.ok) {
@@ -297,12 +398,8 @@ export async function runKanbanCmd(args) {
297
398
  workspaceFlag: parsed.workspaceFlag,
298
399
  }));
299
400
  }
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');
401
+ process.stderr.write(sub ? `yolo: unknown kanban subcommand '${sub}'\n` : 'yolo: kanban requires a subcommand\n');
402
+ process.stderr.write(KANBAN_USAGE);
306
403
  return 64;
307
404
  }
308
405
  function report(result) {
@@ -148,8 +148,9 @@ export function runTileAppInit(opts) {
148
148
  // calculator/grapher), write a real parser here (tokenizer → shunting-yard →
149
149
  // RPN eval) rather than reaching for eval. Keep everything self-contained.
150
150
  //
151
- // To call HOST capabilities (LLM, MCP tools, files), vendor @yololabs/app-sdk's
152
- // browser build into ./vendor/app-sdk/ and request matching permissions in
151
+ // To call HOST capabilities (LLM, MCP tools, files), vendor @yolo-labs/app-sdk's
152
+ // browser build (npm i @yolo-labs/app-sdk, then copy its dist/) into
153
+ // ./vendor/app-sdk/ and request matching permissions in
153
154
  // tileapp.json (permissions.required / optional):
154
155
  // import { createTileApp } from './vendor/app-sdk/index.js';
155
156
  // const app = createTileApp();
package/package.json CHANGED
@@ -1,8 +1,16 @@
1
1
  {
2
2
  "name": "@yolo-labs/yolo-cli",
3
- "version": "0.44.0",
3
+ "version": "0.45.0",
4
4
  "description": "YOLO Studio CLI for workspace context, artifacts, personal apps and hosting.",
5
5
  "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/yolo-labs-hq/yolo-cli.git"
9
+ },
10
+ "homepage": "https://github.com/yolo-labs-hq/yolo-cli#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/yolo-labs-hq/yolo-cli/issues"
13
+ },
6
14
  "type": "module",
7
15
  "bin": {
8
16
  "yolo": "dist/cli.js"
@@ -32,6 +40,7 @@
32
40
  },
33
41
  "devDependencies": {
34
42
  "@types/node": "^20.0.0",
43
+ "@yolo-labs/flexdb": "^0.1.2",
35
44
  "typescript": "^5.4.0"
36
45
  }
37
46
  }