@cavelon/cli 0.1.4 → 0.1.6
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 +58 -22
- package/dist/choose.js +8 -4
- package/dist/code-hints.js +74 -0
- package/dist/commands/api.js +83 -44
- package/dist/commands/async.js +26 -5
- package/dist/commands/chat.js +177 -0
- package/dist/commands/docs.js +240 -37
- package/dist/commands/fmt.js +120 -0
- package/dist/commands/index.js +9 -1
- package/dist/commands/init.js +64 -30
- package/dist/commands/inventory.js +48 -5
- package/dist/commands/limits-set.js +9 -6
- package/dist/commands/loops.js +15 -9
- package/dist/commands/models.js +16 -7
- package/dist/commands/sandboxes.js +8 -4
- package/dist/commands/schema.js +361 -0
- package/dist/commands/session.js +148 -24
- package/dist/commands/setup.js +22 -6
- package/dist/commands/solution.js +537 -76
- package/dist/commands/tenants.js +156 -15
- package/dist/commands/values.js +18 -9
- package/dist/commands/work.js +343 -35
- package/dist/confirm-token.js +72 -0
- package/dist/contracts.js +3 -0
- package/dist/default-route.js +21 -0
- package/dist/errors.js +4 -0
- package/dist/git.js +14 -5
- package/dist/harness-ref.js +14 -1
- package/dist/http.js +27 -4
- package/dist/invoke.js +8 -4
- package/dist/kit-codes.js +91 -0
- package/dist/limits.js +12 -1
- package/dist/local-state.js +32 -7
- package/dist/main.js +52 -4
- package/dist/mcp.js +72 -15
- package/dist/openapi.js +77 -21
- package/dist/operations.js +4 -3
- package/dist/package-check.js +361 -12
- package/dist/package-files.js +92 -45
- package/dist/package-format.js +222 -0
- package/dist/package-references.js +298 -0
- package/dist/preview-report.js +152 -0
- package/dist/results.js +21 -1
- package/dist/skills/cavelon-authoring/SKILL.md +98 -13
- package/dist/skills/cavelon-long-running/SKILL.md +3 -1
- package/dist/skills/cavelon-loop/SKILL.md +129 -21
- package/dist/skills/cavelon-testing/SKILL.md +130 -10
- package/dist/tenant-choice.js +31 -5
- package/dist/trace-view.js +172 -0
- package/package.json +1 -1
package/dist/commands/session.js
CHANGED
|
@@ -4,15 +4,17 @@ import { compareContracts, Contracts } from "../contracts.js";
|
|
|
4
4
|
import { deleteToken, saveToken } from "../credentials.js";
|
|
5
5
|
import { CavelonError, ExitCode, usageError } from "../errors.js";
|
|
6
6
|
import { keyValues } from "../format.js";
|
|
7
|
+
import { callStable } from "../invoke.js";
|
|
7
8
|
import { formatQuota, formatValue, limitRef, readLimits, readQuotas } from "../limits.js";
|
|
8
9
|
import { ApiClient, tokensDisabledError } from "../http.js";
|
|
9
10
|
import { readAll } from "../io.js";
|
|
10
11
|
import { listPreviews, readPull } from "../local-state.js";
|
|
12
|
+
import { solutionState, solutionStateLines } from "./solution.js";
|
|
11
13
|
import { expiryOf, readPrincipal, readTenantless } from "../principal.js";
|
|
12
14
|
import { readHidden } from "../prompt.js";
|
|
13
15
|
import { isUuid, lookupTenantId, requireInstance, requireToken, tenantRequiredError } from "../session.js";
|
|
14
16
|
import { cavelonCommand } from "../shell.js";
|
|
15
|
-
import { choicesOf, chooseTenant, commandLines, listsTenants, noTenantError, tenantOpenError, tenantRef, tenantTitle } from "../tenant-choice.js";
|
|
17
|
+
import { choicesOf, chooseTenant, commandLines, describeTenant, listsTenants, noTenantError, tenantOpenError, tenantRef, tenantTitle } from "../tenant-choice.js";
|
|
16
18
|
import { loadUserConfig, saveUserConfig, tokenKind, updateInstance } from "../user-config.js";
|
|
17
19
|
async function readCapabilities(contracts, refresh) {
|
|
18
20
|
const caps = await contracts.capabilities({ refresh });
|
|
@@ -73,7 +75,7 @@ export const login = {
|
|
|
73
75
|
"The token is kept in the operating system's credential store, or in a file only you can read.\n" +
|
|
74
76
|
"Without --tenant, login finds the tenants the token reaches: one is used; from several, a person chooses on a terminal by number or name; " +
|
|
75
77
|
"without a terminal the token is stored and login prints one `cavelon use` line per tenant (exit 2). " +
|
|
76
|
-
"An operator's token that reaches every tenant asks for part of the tenant's name. " +
|
|
78
|
+
"An operator's token that reaches every tenant asks for part of the tenant's name to start in; Enter leaves the choice for later (`cavelon use`). " +
|
|
77
79
|
"--tenant takes the tenant's name, slug or id. An older instance that lists no tenants places the token itself, or needs --tenant <tenant-id>.",
|
|
78
80
|
readOnly: false,
|
|
79
81
|
mcpTool: false,
|
|
@@ -116,8 +118,9 @@ export const login = {
|
|
|
116
118
|
throw tenantRequiredError(url, tenantless.said, "No tenant was given");
|
|
117
119
|
const reach = listsTenants(tenantless) && !tenantless.platform ? tenantless : undefined;
|
|
118
120
|
let open = false;
|
|
121
|
+
let later = false;
|
|
119
122
|
if (reach) {
|
|
120
|
-
const choice = await chooseTenant(ctx, client, reach);
|
|
123
|
+
const choice = await chooseTenant(ctx, client, reach, { later: true });
|
|
121
124
|
if (choice.kind === "none")
|
|
122
125
|
throw noTenantError(url);
|
|
123
126
|
if (choice.kind === "chosen") {
|
|
@@ -126,8 +129,10 @@ export const login = {
|
|
|
126
129
|
chosen = choice.how;
|
|
127
130
|
client.target.tenantId = t.id;
|
|
128
131
|
}
|
|
129
|
-
else if (!reach.tenantId)
|
|
132
|
+
else if (!reach.tenantId) {
|
|
130
133
|
open = true;
|
|
134
|
+
later = choice.kind === "later";
|
|
135
|
+
}
|
|
131
136
|
}
|
|
132
137
|
const me = open ? undefined : await readMe(client);
|
|
133
138
|
const { caps, needsTenant } = open ? { caps: null, needsTenant: false } : await readCapabilities(contracts, true);
|
|
@@ -163,8 +168,15 @@ export const login = {
|
|
|
163
168
|
ctx.warn("CAVELON_TOKEN is set and takes precedence over this login.");
|
|
164
169
|
if (store.kind === "file")
|
|
165
170
|
ctx.warn("No operating-system credential store; the token is in a file only you can read (0600).");
|
|
166
|
-
if (open)
|
|
171
|
+
if (open && !later)
|
|
167
172
|
throw tenantOpenError(url, reach, `The token is stored for ${url}, but no tenant is chosen yet. `);
|
|
173
|
+
if (later) {
|
|
174
|
+
return {
|
|
175
|
+
data: { instance: url, credential: { kind, store: store.kind }, owner: null, tenant: null, instance_version: null, contracts: null },
|
|
176
|
+
text: `Logged in to ${url}. Token stored in the ${store.kind === "keyring" ? "credential store" : "user-only file"}. ` +
|
|
177
|
+
"No tenant is chosen yet: `cavelon use <name or slug>` chooses one; `cavelon tenant list --search <part of the name>` finds its slug.",
|
|
178
|
+
};
|
|
179
|
+
}
|
|
168
180
|
if (needsTenant) {
|
|
169
181
|
ctx.warn("This token works in Platform mode; choose a tenant with `cavelon use <tenant>` before tenant commands.");
|
|
170
182
|
}
|
|
@@ -262,6 +274,19 @@ function credentialSource(session) {
|
|
|
262
274
|
return "CAVELON_TOKEN";
|
|
263
275
|
return session.tokenStore === "file" ? "login (user-only file)" : "login (credential store)";
|
|
264
276
|
}
|
|
277
|
+
function platformModeText(token) {
|
|
278
|
+
const ceiling = token.ceiling_role ? ` (ceiling ${token.ceiling_role})` : "";
|
|
279
|
+
return token.platform_mode_allowed
|
|
280
|
+
? `allowed${ceiling}`
|
|
281
|
+
: `not allowed${ceiling}; creating tenants and other platform routes need a token that allows it`;
|
|
282
|
+
}
|
|
283
|
+
function reachText(reach) {
|
|
284
|
+
if (reach.reachesAll) {
|
|
285
|
+
const own = reach.tenants.length;
|
|
286
|
+
return `every tenant (as operator; ${own ? `${own} membership${own === 1 ? "" : "s"} of your own` : "no memberships of your own"})`;
|
|
287
|
+
}
|
|
288
|
+
return `${reach.tenants.length} tenant${reach.tenants.length === 1 ? "" : "s"} (\`cavelon tenant list\`)`;
|
|
289
|
+
}
|
|
265
290
|
export const whoami = {
|
|
266
291
|
name: "whoami",
|
|
267
292
|
summary: "Show who the token acts as, in which tenant, and where the token came from.",
|
|
@@ -283,7 +308,9 @@ export const whoami = {
|
|
|
283
308
|
}
|
|
284
309
|
const nowhere = Boolean(reach && !reach.tenantId && !reach.platform);
|
|
285
310
|
const me = nowhere ? undefined : await readMe(client);
|
|
286
|
-
const
|
|
311
|
+
const contracts = await ctx.contracts();
|
|
312
|
+
const { caps, needsTenant } = nowhere ? { caps: null, needsTenant: false } : await readCapabilities(contracts, false);
|
|
313
|
+
const versionCachedAt = caps ? contracts.cachedAt : undefined;
|
|
287
314
|
const principal = needsTenant ? undefined : await readPrincipal(client);
|
|
288
315
|
const contextTenant = me?.context?.tenant_id ?? principal?.tenant_id ?? client.target.tenantId ?? null;
|
|
289
316
|
const tenants = [...(me?.memberships ?? []), ...(me?.accessible_tenants ?? [])];
|
|
@@ -293,10 +320,20 @@ export const whoami = {
|
|
|
293
320
|
if (listsTenants(tenantless))
|
|
294
321
|
reach = tenantless;
|
|
295
322
|
}
|
|
323
|
+
if (pat && !reach) {
|
|
324
|
+
const tenantless = await readTenantless(client).catch(() => undefined);
|
|
325
|
+
if (listsTenants(tenantless))
|
|
326
|
+
reach = tenantless;
|
|
327
|
+
}
|
|
296
328
|
const listed = reach?.tenants.find((t) => t.id === contextTenant);
|
|
297
329
|
const stored = session.settings.tenant_id === contextTenant ? session.settings : undefined;
|
|
298
|
-
|
|
299
|
-
|
|
330
|
+
let tenantName = listed?.name ?? membership?.tenant_name ?? stored?.tenant_name ?? null;
|
|
331
|
+
let tenantSlug = listed?.slug ?? membership?.tenant_slug ?? stored?.tenant_slug ?? null;
|
|
332
|
+
if (contextTenant && (!tenantName || !tenantSlug)) {
|
|
333
|
+
const described = await describeTenant(client, contextTenant);
|
|
334
|
+
tenantName ??= described.name ?? null;
|
|
335
|
+
tenantSlug ??= described.slug ?? null;
|
|
336
|
+
}
|
|
300
337
|
if (nowhere && reach) {
|
|
301
338
|
ctx.warn(reach.tenants.length
|
|
302
339
|
? `No tenant is chosen. Choose one with \`cavelon use\`, or run the line for the tenant you want:\n${commandLines(reach.tenants, (r) => cavelonCommand("use", r))}`
|
|
@@ -306,7 +343,12 @@ export const whoami = {
|
|
|
306
343
|
if (expiry.warning)
|
|
307
344
|
ctx.warn(expiry.warning);
|
|
308
345
|
const data = {
|
|
309
|
-
instance: {
|
|
346
|
+
instance: {
|
|
347
|
+
url: session.url,
|
|
348
|
+
source: session.urlSource,
|
|
349
|
+
version: caps?.instance.version ?? null,
|
|
350
|
+
...(versionCachedAt ? { version_cached_at: versionCachedAt } : {}),
|
|
351
|
+
},
|
|
310
352
|
credential: {
|
|
311
353
|
kind: principal?.kind ?? session.tokenKind,
|
|
312
354
|
source: session.tokenSource,
|
|
@@ -317,6 +359,7 @@ export const whoami = {
|
|
|
317
359
|
expires_in_days: expiry.days_left,
|
|
318
360
|
may_activate: principal?.token ? principal.token.may_activate : null,
|
|
319
361
|
ceiling_role: principal?.token?.ceiling_role ?? null,
|
|
362
|
+
platform_mode_allowed: principal?.token?.platform_mode_allowed ?? null,
|
|
320
363
|
scopes: principal?.api_key?.scopes ?? null,
|
|
321
364
|
published: Boolean(principal),
|
|
322
365
|
},
|
|
@@ -362,7 +405,9 @@ export const whoami = {
|
|
|
362
405
|
["credential", `${session.tokenKind === "api_key" ? "tenant API key" : session.tokenKind === "personal_access_token" ? "personal access token" : "token"}${tokenName} from ${credentialSource(session)}`],
|
|
363
406
|
["expires", expires],
|
|
364
407
|
["may activate", principal?.token ? (principal.token.may_activate ? "yes" : "no (a person activates in the Admin)") : undefined],
|
|
365
|
-
["
|
|
408
|
+
["platform mode", typeof principal?.token?.platform_mode_allowed === "boolean" ? platformModeText(principal.token) : undefined],
|
|
409
|
+
["reaches", reach ? reachText(reach) : undefined],
|
|
410
|
+
["version", data.instance.version ? `${data.instance.version}${versionCachedAt ? ` (cached at ${versionCachedAt})` : ""}` : undefined],
|
|
366
411
|
]),
|
|
367
412
|
};
|
|
368
413
|
},
|
|
@@ -414,7 +459,7 @@ export const use = {
|
|
|
414
459
|
const choice = await chooseTenant(ctx, client, tenantless);
|
|
415
460
|
if (choice.kind === "none")
|
|
416
461
|
throw noTenantError(url, false);
|
|
417
|
-
if (choice.kind
|
|
462
|
+
if (choice.kind !== "chosen")
|
|
418
463
|
throw tenantOpenError(url, tenantless, "");
|
|
419
464
|
const t = choice.tenant;
|
|
420
465
|
ref = tenantRef(t);
|
|
@@ -474,9 +519,10 @@ function limitsLine(state, near) {
|
|
|
474
519
|
return `not readable: ${state.unavailable}`;
|
|
475
520
|
if (!state.published)
|
|
476
521
|
return "not published by this instance";
|
|
522
|
+
const quotas = state.quotas_unavailable ? `\n quotas not readable: ${state.quotas_unavailable}` : "";
|
|
477
523
|
if (!near.length)
|
|
478
|
-
return "none close to a quota (
|
|
479
|
-
return `close to a quota: ${near.map((q) => `${q.key} ${formatQuota(q)}`).join("; ")}`;
|
|
524
|
+
return `${state.quotas_unavailable ? "quotas unknown" : "none close to a quota"} (\`cavelon limits\` lists them)${quotas}`;
|
|
525
|
+
return `close to a quota: ${near.map((q) => `${q.key} ${formatQuota(q)}`).join("; ")}${quotas}`;
|
|
480
526
|
}
|
|
481
527
|
export const status = {
|
|
482
528
|
name: "status",
|
|
@@ -500,7 +546,7 @@ export const status = {
|
|
|
500
546
|
root: session.project.root,
|
|
501
547
|
harness: session.project.harness ?? null,
|
|
502
548
|
last_pull: (await readPull(session.project.root)) ?? null,
|
|
503
|
-
open_previews: await listPreviews(session.project.root),
|
|
549
|
+
open_previews: await listPreviews(session.project.root, ctx.io.now()),
|
|
504
550
|
}
|
|
505
551
|
: null,
|
|
506
552
|
logged_in_at: session.settings.logged_in_at ?? null,
|
|
@@ -511,13 +557,29 @@ export const status = {
|
|
|
511
557
|
let published;
|
|
512
558
|
let reachError;
|
|
513
559
|
let client;
|
|
560
|
+
if (offline && session.url) {
|
|
561
|
+
const cached = await new Contracts(new ApiClient({ url: session.url }, ctx.io.env), ctx.io.env, ctx.io.now)
|
|
562
|
+
.cachedOnly("capabilities.json")
|
|
563
|
+
.catch(() => undefined);
|
|
564
|
+
if (cached?.value?.instance?.version) {
|
|
565
|
+
data.instance_version = cached.value.instance.version;
|
|
566
|
+
data.instance_version_cached_at = cached.fetched_at;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
514
569
|
if (!offline && session.url && session.token) {
|
|
515
570
|
try {
|
|
516
571
|
client = await ctx.client();
|
|
517
|
-
|
|
518
|
-
|
|
572
|
+
const tenantId = client.target.tenantId;
|
|
573
|
+
if (tenantId) {
|
|
574
|
+
const shown = data.tenant;
|
|
575
|
+
shown.id = tenantId;
|
|
576
|
+
const stored = session.settings.tenant_id === tenantId ? session.settings : undefined;
|
|
577
|
+
const described = stored?.tenant_name && stored.tenant_slug ? {} : await describeTenant(client, tenantId);
|
|
578
|
+
shown.name = stored?.tenant_name ?? described.name ?? null;
|
|
579
|
+
shown.slug = stored?.tenant_slug ?? described.slug ?? null;
|
|
580
|
+
}
|
|
519
581
|
const contracts = await ctx.contracts();
|
|
520
|
-
const caps = await contracts.
|
|
582
|
+
const caps = await contracts.liveCapabilities();
|
|
521
583
|
data.instance_version = caps?.instance.version ?? null;
|
|
522
584
|
if (contracts.needsTenant) {
|
|
523
585
|
data.operations = { unavailable: "No tenant chosen; operations belong to a tenant." };
|
|
@@ -529,7 +591,7 @@ export const status = {
|
|
|
529
591
|
});
|
|
530
592
|
operations = page.status === 200 ? page.data.items : undefined;
|
|
531
593
|
data.operations = operations
|
|
532
|
-
? { items: operations, more: Boolean(page.data.next_cursor) }
|
|
594
|
+
? { items: operations, more: Boolean(page.data.next_cursor), scope: "tenant" }
|
|
533
595
|
: { unavailable: "This instance does not offer /api/v1/operations." };
|
|
534
596
|
}
|
|
535
597
|
else {
|
|
@@ -541,6 +603,20 @@ export const status = {
|
|
|
541
603
|
capacity = limits.capacity;
|
|
542
604
|
published = limits.published;
|
|
543
605
|
data.limits = limits.data;
|
|
606
|
+
const ref = session.envFile?.harness ?? session.project?.harness;
|
|
607
|
+
if (session.project && ref) {
|
|
608
|
+
const state = await solutionState(ctx, ref);
|
|
609
|
+
data.solution.state = state;
|
|
610
|
+
if (operations && state.harness) {
|
|
611
|
+
const owners = await operationSolutions(ctx, operations);
|
|
612
|
+
const others = operations.filter((o) => owners.get(o.id) && owners.get(o.id) !== state.harness.id);
|
|
613
|
+
if (others.length) {
|
|
614
|
+
operations = operations.filter((o) => !others.includes(o));
|
|
615
|
+
data.operations = { ...data.operations, items: operations, other_solutions: others.length };
|
|
616
|
+
}
|
|
617
|
+
data.operations = { ...data.operations, scope: "solution", harness: state.harness.slug };
|
|
618
|
+
}
|
|
619
|
+
}
|
|
544
620
|
}
|
|
545
621
|
}
|
|
546
622
|
catch (error) {
|
|
@@ -548,8 +624,9 @@ export const status = {
|
|
|
548
624
|
data.error = error instanceof CavelonError ? error.toJSON() : { message: reachError };
|
|
549
625
|
}
|
|
550
626
|
}
|
|
627
|
+
const shownTenant = data.tenant;
|
|
551
628
|
const tenantText = session.tenant
|
|
552
|
-
? `${session.tenant} (${session.tenantSource})`
|
|
629
|
+
? `${shownTenant?.id && (shownTenant.name || shownTenant.slug) ? tenantTitle({ id: shownTenant.id, name: shownTenant.name, slug: shownTenant.slug }) : session.tenant} (${session.tenantSource})`
|
|
553
630
|
: session.tokenKind === "api_key"
|
|
554
631
|
? "the API key's tenant"
|
|
555
632
|
: "not chosen (`cavelon use` lists your tenants to choose from)";
|
|
@@ -563,16 +640,22 @@ export const status = {
|
|
|
563
640
|
const solution = data.solution;
|
|
564
641
|
if (session.project.harness)
|
|
565
642
|
lines.push(["harness", session.project.harness]);
|
|
643
|
+
if (solution.state)
|
|
644
|
+
lines.push(...solutionStateLines(solution.state));
|
|
566
645
|
lines.push(["last pull", solution.last_pull ? `${solution.last_pull.at}${solution.last_pull.harness ? ` (${solution.last_pull.harness.slug})` : ""}` : "never"]);
|
|
567
646
|
lines.push([
|
|
568
647
|
"open previews",
|
|
569
648
|
solution.open_previews.length
|
|
570
|
-
? solution.open_previews
|
|
649
|
+
? solution.open_previews
|
|
650
|
+
.map((p) => `\n ${p.preview_id}${p.env ? ` env ${p.env}` : ""} ${p.created_at} ${p.expired ? "expired (`cavelon apply --discard all` removes it)" : `expires ${p.expires_at}`}`)
|
|
651
|
+
.join("")
|
|
571
652
|
: "none",
|
|
572
653
|
]);
|
|
573
654
|
}
|
|
574
|
-
if (data.instance_version)
|
|
575
|
-
|
|
655
|
+
if (data.instance_version) {
|
|
656
|
+
const cachedAt = data.instance_version_cached_at;
|
|
657
|
+
lines.push(["version", `${data.instance_version}${cachedAt !== undefined ? ` (cached at ${cachedAt ?? "an unknown time"}; not read now)` : ""}`]);
|
|
658
|
+
}
|
|
576
659
|
if (data.limits)
|
|
577
660
|
lines.push(["limits", limitsLine(data.limits, near ?? [])]);
|
|
578
661
|
if (capacity.length)
|
|
@@ -586,18 +669,59 @@ export const status = {
|
|
|
586
669
|
const waiting = waits.flatMap((wait, i) => (wait ? [{ operation_id: operations[i].id, ...wait }] : []));
|
|
587
670
|
if (waiting.length)
|
|
588
671
|
data.capacity_waits = waiting;
|
|
672
|
+
const ops = data.operations;
|
|
673
|
+
const others = ops.other_solutions ? ` (${ops.other_solutions} of other solutions not shown; \`cavelon api list_operations_route\` lists all)` : "";
|
|
674
|
+
const heading = ops.scope === "solution" ? `Running operations of ${ops.harness} and the tenant's shared work${others}` : "Running operations in the tenant";
|
|
589
675
|
text += operations.length
|
|
590
|
-
? `\n\
|
|
676
|
+
? `\n\n${heading}:\n${operations
|
|
591
677
|
.map((o, i) => {
|
|
592
678
|
const wait = waits[i];
|
|
593
679
|
return ` ${o.id} ${o.kind} ${o.status}${o.progress?.phase ? ` (${o.progress.phase})` : ""}${wait ? ` ${wait.note}` : ""}`;
|
|
594
680
|
})
|
|
595
681
|
.join("\n")}`
|
|
596
|
-
:
|
|
682
|
+
: `\n\nNo running operations${ops.scope === "solution" ? ` of ${ops.harness}${others}` : " in the tenant"}.`;
|
|
597
683
|
}
|
|
598
684
|
return { data, text };
|
|
599
685
|
},
|
|
600
686
|
};
|
|
687
|
+
async function operationSolutions(ctx, operations) {
|
|
688
|
+
const owners = new Map();
|
|
689
|
+
const triggers = new Map();
|
|
690
|
+
const triggerSolution = (id) => {
|
|
691
|
+
if (!triggers.has(id)) {
|
|
692
|
+
triggers.set(id, callStable(ctx, "GET", "/api/v1/triggers/{trigger_id}", "reading triggers", { params: { trigger_id: [id] } }).then((t) => t.harness_id ?? undefined, () => undefined));
|
|
693
|
+
}
|
|
694
|
+
return triggers.get(id);
|
|
695
|
+
};
|
|
696
|
+
for (const op of operations) {
|
|
697
|
+
const harnessId = op.harness_id;
|
|
698
|
+
if (typeof harnessId === "string" && harnessId) {
|
|
699
|
+
owners.set(op.id, harnessId);
|
|
700
|
+
continue;
|
|
701
|
+
}
|
|
702
|
+
const ref = op.result_ref;
|
|
703
|
+
if (!ref?.id)
|
|
704
|
+
continue;
|
|
705
|
+
try {
|
|
706
|
+
if (ref.type === "test_run") {
|
|
707
|
+
const run = await callStable(ctx, "GET", "/api/v1/test-runs/{run_id}", "test runs", { params: { run_id: [ref.id] } });
|
|
708
|
+
if (run.harness_id)
|
|
709
|
+
owners.set(op.id, run.harness_id);
|
|
710
|
+
}
|
|
711
|
+
else if (ref.type === "agent_run") {
|
|
712
|
+
const run = await callStable(ctx, "GET", "/api/v1/triggers/runs/{run_id}", "reading runs", {
|
|
713
|
+
params: { run_id: [ref.id] },
|
|
714
|
+
});
|
|
715
|
+
const owner = run.harness_id ?? (run.trigger_definition_id ? await triggerSolution(run.trigger_definition_id) : undefined);
|
|
716
|
+
if (owner)
|
|
717
|
+
owners.set(op.id, owner);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
catch {
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
return owners;
|
|
724
|
+
}
|
|
601
725
|
export async function rememberTenant(ctx, url, tenant) {
|
|
602
726
|
await updateInstance(ctx.io.env, url, (c) => ({
|
|
603
727
|
...c,
|
package/dist/commands/setup.js
CHANGED
|
@@ -266,14 +266,19 @@ async function runCheck(ctx, input) {
|
|
|
266
266
|
const agents = setupAgents(env);
|
|
267
267
|
const named = namedAgents(input, agents);
|
|
268
268
|
const state = await loadState(env);
|
|
269
|
+
const strict = boolOption(input, "strict");
|
|
269
270
|
const checks = [];
|
|
270
271
|
for (const agent of named.length ? named : agents) {
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
272
|
+
const record = state.agents[agent.name];
|
|
273
|
+
const check = await checkAgent(agent, env, record);
|
|
274
|
+
if (!named.length && !check.found && !record)
|
|
275
|
+
continue;
|
|
276
|
+
const skipped = !named.length && !strict && !record && !check.ok;
|
|
277
|
+
checks.push(skipped ? { ...check, skipped: true } : check);
|
|
274
278
|
}
|
|
279
|
+
const counted = checks.filter((c) => !c.skipped);
|
|
275
280
|
const servers = [];
|
|
276
|
-
for (const server of
|
|
281
|
+
for (const server of counted.flatMap((c) => c.servers)) {
|
|
277
282
|
if (!servers.some((s) => JSON.stringify(s) === JSON.stringify(server)))
|
|
278
283
|
servers.push(server);
|
|
279
284
|
}
|
|
@@ -300,12 +305,18 @@ async function runCheck(ctx, input) {
|
|
|
300
305
|
loginCheck = { ok: false, instance: session.url, problem: `${err.message}${err.hint ? ` ${err.hint}` : ""}` };
|
|
301
306
|
}
|
|
302
307
|
}
|
|
303
|
-
const ok =
|
|
308
|
+
const ok = counted.length > 0 && counted.every((c) => c.ok) && probes.every((p) => p.ok) && loginCheck.ok;
|
|
304
309
|
const mark = (good) => (good ? ctx.style.green("ok ") : ctx.style.red("no "));
|
|
305
310
|
const lines = [];
|
|
306
311
|
if (!checks.length)
|
|
307
312
|
lines.push(`${mark(false)}No coding agent found, and setup has set up none.`);
|
|
313
|
+
else if (!counted.length)
|
|
314
|
+
lines.push(`${mark(false)}No coding agent is set up for Cavelon.`);
|
|
308
315
|
for (const check of checks) {
|
|
316
|
+
if (check.skipped) {
|
|
317
|
+
lines.push(`skip ${check.label}: found, not set up for Cavelon (${cavelonCommand("setup", "--agents", check.name)} sets it up)`);
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
309
320
|
lines.push(`${mark(check.ok)}${check.label}${check.found ? "" : " (not found on this computer)"}`);
|
|
310
321
|
for (const detail of check.details)
|
|
311
322
|
lines.push(` ${detail}`);
|
|
@@ -392,7 +403,9 @@ export const setup = {
|
|
|
392
403
|
"server in their user MCP configuration and the skills in their user skills folder. It touches nothing else in those files and\n" +
|
|
393
404
|
"records what it did, so --remove undoes exactly that. Then it logs in if needed, choosing the tenant by name as `login` does.\n" +
|
|
394
405
|
"The server starts as `cavelon mcp` when cavelon is installed, otherwise through npx. --check reports what is set up and\n" +
|
|
395
|
-
"working: each agent's entry, the MCP server starting, and the login.
|
|
406
|
+
"working: each agent's entry, the MCP server starting, and the login. An agent found but never set up for Cavelon is\n" +
|
|
407
|
+
"reported and skipped (exit 0 when the rest works); --strict, or naming it with --agents, counts it.\n" +
|
|
408
|
+
"Without a terminal it changes nothing unless --yes.",
|
|
396
409
|
readOnly: false,
|
|
397
410
|
destructive: true,
|
|
398
411
|
idempotent: true,
|
|
@@ -406,6 +419,7 @@ export const setup = {
|
|
|
406
419
|
},
|
|
407
420
|
yes: { type: "boolean", short: "y", description: "Make the changes without asking." },
|
|
408
421
|
check: { type: "boolean", description: "Report what is set up and working; change nothing." },
|
|
422
|
+
strict: { type: "boolean", description: "With --check: fail for every agent found that is not set up, not only the ones setup set up." },
|
|
409
423
|
remove: { type: "boolean", description: "Undo what setup did (your login stays)." },
|
|
410
424
|
},
|
|
411
425
|
examples: [
|
|
@@ -417,6 +431,8 @@ export const setup = {
|
|
|
417
431
|
async run(ctx, input) {
|
|
418
432
|
if (boolOption(input, "check") && boolOption(input, "remove"))
|
|
419
433
|
throw usageError("--check and --remove do not go together.");
|
|
434
|
+
if (boolOption(input, "strict") && !boolOption(input, "check"))
|
|
435
|
+
throw usageError("--strict goes with --check.");
|
|
420
436
|
if (boolOption(input, "check"))
|
|
421
437
|
return runCheck(ctx, input);
|
|
422
438
|
if (boolOption(input, "remove"))
|