@cavelon/cli 0.1.9 → 0.1.10
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/branches.js +4 -3
- package/dist/capacity.js +3 -2
- package/dist/code-hints.js +5 -4
- package/dist/command.js +6 -0
- package/dist/commands/api.js +3 -3
- package/dist/commands/async.js +7 -4
- package/dist/commands/chat.js +10 -12
- package/dist/commands/docs.js +5 -3
- package/dist/commands/fmt.js +6 -4
- package/dist/commands/index.js +2 -0
- package/dist/commands/init.js +106 -28
- package/dist/commands/limits-set.js +8 -9
- package/dist/commands/limits.js +4 -3
- package/dist/commands/loops.js +15 -14
- package/dist/commands/models.js +10 -12
- package/dist/commands/sandboxes.js +15 -14
- package/dist/commands/schema.js +6 -5
- package/dist/commands/session.js +27 -15
- package/dist/commands/setup.js +4 -2
- package/dist/commands/solution.js +152 -68
- package/dist/commands/tenants.js +14 -14
- package/dist/commands/values.js +62 -38
- package/dist/commands/work.js +18 -12
- package/dist/confirm-token.js +3 -1
- package/dist/contracts.js +2 -1
- package/dist/default-route.js +1 -1
- package/dist/features.js +2 -1
- package/dist/harness-ref.js +6 -4
- package/dist/http.js +4 -3
- package/dist/invoke.js +3 -2
- package/dist/kit-codes.js +9 -2
- package/dist/limits.js +1 -1
- package/dist/main.js +13 -1
- package/dist/mcp.js +41 -21
- package/dist/openapi.js +5 -2
- package/dist/operations.js +3 -2
- package/dist/package-check.js +10 -4
- package/dist/package-files.js +5 -1
- package/dist/package-format.js +10 -0
- package/dist/preview-report.js +44 -5
- package/dist/printed.js +182 -0
- package/dist/project.js +2 -1
- package/dist/results.js +1 -1
- package/dist/secret-access.js +30 -0
- package/dist/session.js +3 -11
- package/dist/shell.js +0 -3
- package/dist/skills/cavelon-authoring/SKILL.md +9 -2
- package/dist/skills/cavelon-long-running/SKILL.md +1 -1
- package/dist/skills/cavelon-loop/SKILL.md +11 -4
- package/dist/tenant-choice.js +7 -7
- package/dist/trace-view.js +1 -1
- package/package.json +1 -1
package/dist/commands/init.js
CHANGED
|
@@ -10,15 +10,15 @@ import { git } from "../git.js";
|
|
|
10
10
|
import { ensureStateDir, fileDigests, rememberAppliedFiles, STATE_DIR } from "../local-state.js";
|
|
11
11
|
import { isGenerated, upsertBlock, upsertJsonEntry } from "../markers.js";
|
|
12
12
|
import { packageVersionOf } from "../package-check.js";
|
|
13
|
-
import { PERSONA_SECTION, personaYaml, sectionFields } from "../package-format.js";
|
|
13
|
+
import { MANIFEST_SECTION, PERSONA_SECTION, personaYaml, requiredFields, sectionFields } from "../package-format.js";
|
|
14
14
|
import { defaultLayoutFor, placeholdersOnly, safeSectionName, schemaSections, toYaml, writePackage } from "../package-files.js";
|
|
15
15
|
import { readPrincipal, readTenantless } from "../principal.js";
|
|
16
16
|
import { ENV_DIR, parseProject, PROJECT_FILE } from "../project.js";
|
|
17
17
|
import { canAsk, readLine } from "../prompt.js";
|
|
18
18
|
import { pick } from "../choose.js";
|
|
19
19
|
import { harnessNotFoundError, listHarnesses, lookupHarness, SLUG, slugFromName } from "../harness-ref.js";
|
|
20
|
-
import {
|
|
21
|
-
import { cavelonCommand } from "../
|
|
20
|
+
import { isUuid, lookupTenantId, requireInstance, requireToken, tenantRequiredError } from "../session.js";
|
|
21
|
+
import { cavelonCommand, fill, folderCommand } from "../printed.js";
|
|
22
22
|
import { chooseTenant, listsTenants, noTenantError, tenantOpenError, tenantRef, tenantTitle } from "../tenant-choice.js";
|
|
23
23
|
import { createHarness } from "./tenants.js";
|
|
24
24
|
import { schemaFor, setProjectKey } from "./solution.js";
|
|
@@ -88,6 +88,65 @@ async function personaPlaceholders(ctx, project) {
|
|
|
88
88
|
await rememberAppliedFiles(project.root, await fileDigests(project.root, [relative]));
|
|
89
89
|
return action;
|
|
90
90
|
}
|
|
91
|
+
async function manifestTenant(ctx, session, chosen) {
|
|
92
|
+
if (chosen?.id && chosen.slug)
|
|
93
|
+
return { id: chosen.id, slug: chosen.slug };
|
|
94
|
+
const ref = chosen?.ref ?? session.tenant;
|
|
95
|
+
if (!ref)
|
|
96
|
+
return undefined;
|
|
97
|
+
try {
|
|
98
|
+
const found = await lookupTenantId(await ctx.client({ tenant: false }), ref, session.tenantSource);
|
|
99
|
+
const slug = found.slug ?? (!isUuid(ref) && SLUG.test(ref) ? ref : undefined);
|
|
100
|
+
return slug ? { id: found.id, slug } : undefined;
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function manifestFor(schema, known) {
|
|
107
|
+
const required = requiredFields(schema, MANIFEST_SECTION);
|
|
108
|
+
const fields = sectionFields(schema, MANIFEST_SECTION);
|
|
109
|
+
if (!required || !fields)
|
|
110
|
+
return undefined;
|
|
111
|
+
const manifest = {};
|
|
112
|
+
for (const name of Object.keys(fields).filter((f) => required.includes(f))) {
|
|
113
|
+
const field = fields[name];
|
|
114
|
+
const value = field.const !== undefined ? field.const : known[name] !== undefined ? known[name] : field.default ?? undefined;
|
|
115
|
+
if (value === undefined || value === null)
|
|
116
|
+
return undefined;
|
|
117
|
+
manifest[name] = value;
|
|
118
|
+
}
|
|
119
|
+
return required.every((name) => name in manifest) ? manifest : undefined;
|
|
120
|
+
}
|
|
121
|
+
async function hasManifest(root, dir) {
|
|
122
|
+
const names = await fs.readdir(path.join(root, dir)).catch(() => []);
|
|
123
|
+
return names.some((n) => n.replace(/\.(ya?ml|json)$/i, "") === MANIFEST_SECTION);
|
|
124
|
+
}
|
|
125
|
+
async function manifestFile(ctx, session, project, chosen) {
|
|
126
|
+
if (await hasManifest(project.root, project.layout.package))
|
|
127
|
+
return undefined;
|
|
128
|
+
const { schema } = await schemaFor(ctx, project.packageVersion, false).catch(() => ({ schema: null }));
|
|
129
|
+
if (!requiredFields(schema, MANIFEST_SECTION))
|
|
130
|
+
return undefined;
|
|
131
|
+
const tenant = await manifestTenant(ctx, session, chosen);
|
|
132
|
+
if (!tenant)
|
|
133
|
+
return undefined;
|
|
134
|
+
const version = project.packageVersion ?? (typeof schema?.["x-package-version"] === "string" ? schema["x-package-version"] : undefined);
|
|
135
|
+
const manifest = manifestFor(schema, {
|
|
136
|
+
package_version: version,
|
|
137
|
+
source_tenant_id: tenant.id,
|
|
138
|
+
source_tenant_slug: tenant.slug,
|
|
139
|
+
exported_at: ctx.io.now().toISOString(),
|
|
140
|
+
});
|
|
141
|
+
if (!manifest)
|
|
142
|
+
return undefined;
|
|
143
|
+
const relative = `${project.layout.package}/${MANIFEST_SECTION}.yaml`;
|
|
144
|
+
const content = ["# The package format and the tenant this package is for, written by `cavelon init`; `cavelon pull` replaces it.", toYaml(manifest).trimEnd(), ""].join("\n");
|
|
145
|
+
const action = await ownFile(project.root, relative, content);
|
|
146
|
+
if (action.action === "created")
|
|
147
|
+
await rememberAppliedFiles(project.root, await fileDigests(project.root, [relative]));
|
|
148
|
+
return action;
|
|
149
|
+
}
|
|
91
150
|
async function generatedFile(root, relative, content) {
|
|
92
151
|
const file = path.join(root, relative);
|
|
93
152
|
const existing = await readTextFile(file);
|
|
@@ -265,7 +324,7 @@ async function initTenant(ctx, session) {
|
|
|
265
324
|
if (choice.kind !== "chosen") {
|
|
266
325
|
throw tenantOpenError(client.url, reach, "A solution belongs to one tenant. ", {
|
|
267
326
|
line: (ref) => cavelonCommand("init", "--tenant", ref),
|
|
268
|
-
template: "
|
|
327
|
+
template: cavelonCommand("init", "--tenant", fill("name or slug")),
|
|
269
328
|
});
|
|
270
329
|
}
|
|
271
330
|
const t = choice.tenant;
|
|
@@ -279,8 +338,8 @@ async function initTenant(ctx, session) {
|
|
|
279
338
|
const listed = reach?.tenants.find((t) => t.id === placed);
|
|
280
339
|
return { ref: listed?.slug ?? placed, id: placed, name: listed?.name ?? undefined, slug: listed?.slug ?? undefined };
|
|
281
340
|
}
|
|
282
|
-
async function initHarness(ctx, given, displayName = given, choice = {
|
|
283
|
-
const {
|
|
341
|
+
async function initHarness(ctx, given, displayName = given, choice = { target: [] }) {
|
|
342
|
+
const { target } = choice;
|
|
284
343
|
if (given) {
|
|
285
344
|
let lookup;
|
|
286
345
|
try {
|
|
@@ -295,7 +354,7 @@ async function initHarness(ctx, given, displayName = given, choice = { flags: ""
|
|
|
295
354
|
throw new CavelonError(ExitCode.failure, {
|
|
296
355
|
code: "solution_exists",
|
|
297
356
|
message: `Solution ${found.name} (${found.slug}) is already in this tenant; --new creates only a solution it does not have.`,
|
|
298
|
-
hint: `For this folder to hold that solution: ${cavelonCommand("init", "--harness", found.slug)}
|
|
357
|
+
hint: `For this folder to hold that solution: ${cavelonCommand("init", "--harness", found.slug, ...target)}. For a new one, give --new another name.`,
|
|
299
358
|
details: { harness: { id: found.id, slug: found.slug, name: found.name } },
|
|
300
359
|
});
|
|
301
360
|
}
|
|
@@ -303,13 +362,13 @@ async function initHarness(ctx, given, displayName = given, choice = { flags: ""
|
|
|
303
362
|
return { slug: lookup.harness.slug };
|
|
304
363
|
const slug = SLUG.test(given) ? given : slugFromName(given);
|
|
305
364
|
const title = (displayName ?? given).trim().slice(0, 255) || slug;
|
|
306
|
-
const create =
|
|
307
|
-
const notFound = () => harnessNotFoundError(given, lookup.candidates, undefined, (s) => cavelonCommand("init", "--harness", s
|
|
365
|
+
const create = folderCommand("harness", "new", slug, "--name", title);
|
|
366
|
+
const notFound = () => harnessNotFoundError(given, lookup.candidates, undefined, (s) => cavelonCommand("init", "--harness", s, ...target));
|
|
308
367
|
if (!slug || isUuid(given))
|
|
309
368
|
throw notFound();
|
|
310
369
|
if (lookup.candidates.length && !choice.create) {
|
|
311
370
|
const error = notFound();
|
|
312
|
-
const createNew = cavelonCommand("init", "--harness", title, "--new")
|
|
371
|
+
const createNew = cavelonCommand("init", "--harness", title, "--new", ...target);
|
|
313
372
|
throw new CavelonError(error.exitCode, {
|
|
314
373
|
code: error.code,
|
|
315
374
|
message: error.message,
|
|
@@ -385,9 +444,12 @@ async function hasPackageFiles(root, dir) {
|
|
|
385
444
|
catch {
|
|
386
445
|
return false;
|
|
387
446
|
}
|
|
388
|
-
for (const name of names)
|
|
447
|
+
for (const name of names) {
|
|
448
|
+
if (name.replace(/\.(ya?ml|json)$/i, "") === MANIFEST_SECTION)
|
|
449
|
+
continue;
|
|
389
450
|
if (!(await placeholdersOnly(root, `${dir}/${name}`)))
|
|
390
451
|
return true;
|
|
452
|
+
}
|
|
391
453
|
return false;
|
|
392
454
|
}
|
|
393
455
|
const MAX_PACKAGE_FILE_BYTES = 50 * 1024 * 1024;
|
|
@@ -481,16 +543,16 @@ async function runInit(ctx, input) {
|
|
|
481
543
|
if (from !== undefined && !from.trim())
|
|
482
544
|
throw usageError("--from needs the path of a package file.");
|
|
483
545
|
if (from && update)
|
|
484
|
-
throw usageError("--from and --update do not go together.",
|
|
546
|
+
throw usageError("--from and --update do not go together.", `Run \`${cavelonCommand("init", "--from", fill("file"))}\` and \`${cavelonCommand("init", "--update")}\` one after the other.`);
|
|
485
547
|
if (boolOption(input, "force") && !from)
|
|
486
548
|
throw usageError("--force only applies to --from.");
|
|
487
549
|
if (boolOption(input, "new") && (update || (!stringOption(input, "harness") && !from))) {
|
|
488
|
-
throw usageError("--new needs the new solution's name: --harness <name>.", "
|
|
550
|
+
throw usageError("--new needs the new solution's name: --harness <name>.", `\`${cavelonCommand("init", "--harness", fill("name"), "--new")}\` creates it as a draft, even when an existing solution has a similar name.`);
|
|
489
551
|
}
|
|
490
552
|
const imported = from ? await readImportFile(ctx, from) : undefined;
|
|
491
553
|
if (update) {
|
|
492
554
|
if (!session.project)
|
|
493
|
-
throw usageError("No cavelon.yaml here or above.",
|
|
555
|
+
throw usageError("No cavelon.yaml here or above.", `Run \`${cavelonCommand("init")}\` first.`);
|
|
494
556
|
const root = session.project.root;
|
|
495
557
|
actions.push(await block(root, "AGENTS.md", AGENTS_BLOCK, "html", { onlyExisting: true }));
|
|
496
558
|
const claude = await claudeImport(root, true);
|
|
@@ -510,6 +572,7 @@ async function runInit(ctx, input) {
|
|
|
510
572
|
}
|
|
511
573
|
const packageHarness = imported ? onlyHarnessSlug(imported) : undefined;
|
|
512
574
|
let chosenHarness;
|
|
575
|
+
let chosenTenant;
|
|
513
576
|
const root = ctx.io.cwd;
|
|
514
577
|
const existing = await readTextFile(path.join(root, PROJECT_FILE));
|
|
515
578
|
if (existing !== undefined) {
|
|
@@ -521,6 +584,7 @@ async function runInit(ctx, input) {
|
|
|
521
584
|
const url = requireInstance(session);
|
|
522
585
|
requireToken(session);
|
|
523
586
|
const tenant = await initTenant(ctx, session);
|
|
587
|
+
chosenTenant = tenant;
|
|
524
588
|
if (tenant?.id)
|
|
525
589
|
[session.tenant, session.tenantSource] = [tenant.id, session.tenantSource ?? "option"];
|
|
526
590
|
const contracts = await ctx.contracts();
|
|
@@ -529,14 +593,18 @@ async function runInit(ctx, input) {
|
|
|
529
593
|
throw new CavelonError(ExitCode.usage, {
|
|
530
594
|
code: "tenant_required",
|
|
531
595
|
message: "A solution belongs to one tenant, and none is chosen.",
|
|
532
|
-
hint:
|
|
596
|
+
hint: `Pass --tenant <name or slug>, or run \`${cavelonCommand("use")}\` first to choose one.`,
|
|
533
597
|
});
|
|
534
598
|
}
|
|
535
599
|
const schema = await contracts.packageSchema();
|
|
536
600
|
await contracts.errorCatalog().catch(() => null);
|
|
537
601
|
if (!schema)
|
|
538
602
|
ctx.warn("The instance does not publish its package schema; `validate` will have nothing to check against.");
|
|
539
|
-
const
|
|
603
|
+
const target = [
|
|
604
|
+
...(session.urlSource === "option" && session.url ? ["--instance", session.url] : []),
|
|
605
|
+
...(session.tenantSource === "option" && (tenant?.ref ?? session.tenant) ? ["--tenant", (tenant?.ref ?? session.tenant)] : []),
|
|
606
|
+
];
|
|
607
|
+
const choice = { create: boolOption(input, "new"), target };
|
|
540
608
|
const decided = stringOption(input, "harness")
|
|
541
609
|
? await initHarness(ctx, stringOption(input, "harness"), undefined, choice)
|
|
542
610
|
: packageHarness
|
|
@@ -544,8 +612,6 @@ async function runInit(ctx, input) {
|
|
|
544
612
|
: await initHarness(ctx, undefined, undefined, choice);
|
|
545
613
|
chosenHarness = decided;
|
|
546
614
|
const harness = decided.slug;
|
|
547
|
-
if (decided.missing)
|
|
548
|
-
next.push(`Solution ${harness} is not on the instance yet: create it as a draft with ${decided.create}, then cavelon apply --env test.`);
|
|
549
615
|
const values = { instance: url };
|
|
550
616
|
if (tenant)
|
|
551
617
|
values.tenant = tenant.ref;
|
|
@@ -583,29 +649,38 @@ async function runInit(ctx, input) {
|
|
|
583
649
|
if (boolOption(input, "hook"))
|
|
584
650
|
actions.push(await installHook(root, false));
|
|
585
651
|
else
|
|
586
|
-
next.push(
|
|
652
|
+
next.push(`Catch an invalid package before each commit: ${folderCommand("init", "--hook")}`);
|
|
587
653
|
let result;
|
|
588
654
|
if (imported && from) {
|
|
589
655
|
result = await importPackage(ctx, project, from, imported, boolOption(input, "force"));
|
|
590
656
|
if (packageHarness && !project.harness && !stringOption(input, "harness"))
|
|
591
657
|
await setProjectKey(project, "harness", packageHarness);
|
|
592
|
-
next.unshift(
|
|
658
|
+
next.unshift(`Check it offline: ${folderCommand("validate")}`, `Preview it on the instance: ${harness ? folderCommand("apply", "--env", "test") : folderCommand("apply", "--harness", fill("name or slug"))}`);
|
|
593
659
|
}
|
|
594
660
|
else if (!(await hasPackageFiles(root, project.layout.package))) {
|
|
595
661
|
const choices = chosenHarness?.choices ?? [];
|
|
596
|
-
if (chosenHarness?.created || chosenHarness?.missing)
|
|
597
|
-
next.unshift("Write the package files in package/, then:
|
|
662
|
+
if (chosenHarness?.created || chosenHarness?.missing) {
|
|
663
|
+
next.unshift(`Bring the draft into package/ (its manifest): ${folderCommand("pull")}`, `Write the package files in package/, then: ${folderCommand("validate")}`, `Preview it on the instance: ${folderCommand("apply", "--env", "test")}`);
|
|
664
|
+
}
|
|
598
665
|
else if (harness)
|
|
599
|
-
next.unshift(`Bring the solution into package/:
|
|
666
|
+
next.unshift(`Bring the solution into package/: ${folderCommand("pull")}`);
|
|
600
667
|
else if (choices.length) {
|
|
601
|
-
next.unshift(
|
|
668
|
+
next.unshift(`Bring one of this tenant's solutions into package/ (or write package files, then ${folderCommand("validate")}):`, ...choices.slice(0, 10).map((h) => ` ${folderCommand("pull", "--harness", h.slug)}${h.name !== h.slug ? ` ${h.name}` : ""}`), ...(choices.length > 10 ? [` … and ${choices.length - 10} more (\`${folderCommand("harness", "list")}\`)`] : []));
|
|
669
|
+
}
|
|
670
|
+
else {
|
|
671
|
+
next.unshift(`Bring an existing solution into package/: ${folderCommand("pull", "--harness", fill("name or slug"))} (or write package files, then ${folderCommand("validate")})`);
|
|
602
672
|
}
|
|
603
|
-
else
|
|
604
|
-
next.unshift("Bring an existing solution into package/: cavelon pull --harness <name or slug> (or write package files, then cavelon validate)");
|
|
605
673
|
const persona = await personaPlaceholders(ctx, project);
|
|
606
674
|
if (persona)
|
|
607
675
|
actions.push(persona);
|
|
608
676
|
}
|
|
677
|
+
if (chosenHarness?.missing)
|
|
678
|
+
next.unshift(`Solution ${harness} is not on the instance yet: create it as a draft with ${chosenHarness.create}.`);
|
|
679
|
+
if (!result) {
|
|
680
|
+
const manifest = await manifestFile(ctx, session, project, chosenTenant);
|
|
681
|
+
if (manifest)
|
|
682
|
+
actions.push(manifest);
|
|
683
|
+
}
|
|
609
684
|
return { root, actions, next, imported: result, harness: chosenHarness };
|
|
610
685
|
}
|
|
611
686
|
export const init = {
|
|
@@ -616,10 +691,11 @@ export const init = {
|
|
|
616
691
|
"named agent's `cavelon mcp` entry, for agents without the Cavelon plugin. --update changes only those marked blocks and\n" +
|
|
617
692
|
"the fallback files a previous init wrote. --from writes an existing package file (JSON or YAML export) into package/ and\n" +
|
|
618
693
|
"tests/ as `pull` writes an export, so validate and apply take it from there; it refuses to change or remove a package\n" +
|
|
619
|
-
"file that holds something else unless --force, and names the sections the instance's schema does not know."
|
|
694
|
+
"file that holds something else unless --force, and names the sections the instance's schema does not know. Without\n" +
|
|
695
|
+
"--from, a folder without package/manifest.yaml gets a minimal one (package format and tenant), which the first pull replaces.",
|
|
620
696
|
readOnly: false,
|
|
621
697
|
destructive: true,
|
|
622
|
-
mcpEffect: "Changes nothing on the instance (as a tool it never creates a solution; it names the `harness_new` call for one that is missing). Writes files in the solution folder; never overwrites a " +
|
|
698
|
+
mcpEffect: "Changes nothing on the instance (as a tool it never creates a solution; it names the `harness_new` call for one that is missing, and `pull` after it). Writes files in the solution folder; never overwrites a " +
|
|
623
699
|
"file it did not create, and changes only the blocks between its markers in AGENTS.md, CLAUDE.md and .gitignore.",
|
|
624
700
|
idempotent: true,
|
|
625
701
|
mcpTool: "init",
|
|
@@ -628,10 +704,12 @@ export const init = {
|
|
|
628
704
|
type: "string",
|
|
629
705
|
value: "<harness>",
|
|
630
706
|
description: "The solution (harness) this folder holds, by name, slug or id; its slug goes into cavelon.yaml. One that is not on the instance yet is created as a draft with that name, unless an existing solution's name is close to it: then init refuses, naming that one, and --new creates the new one. Without it, init asks on a terminal.",
|
|
707
|
+
mcpDescription: "The solution (harness) this folder holds, by name, slug or id; its slug goes into cavelon.yaml. One that is not on the instance yet is not created: init names the harness_new call that creates it as a draft, and pull after it. A name close to an existing solution's is refused, naming that one, unless new is set.",
|
|
631
708
|
},
|
|
632
709
|
new: {
|
|
633
710
|
type: "boolean",
|
|
634
711
|
description: "Create the solution --harness names as a new draft, even when an existing solution has a similar name (refused when one has that very name or slug).",
|
|
712
|
+
mcpDescription: "The solution harness names is a new one, even when an existing solution has a similar name (refused when one has that very name or slug); init names the harness_new call that creates it.",
|
|
635
713
|
},
|
|
636
714
|
agents: {
|
|
637
715
|
type: "string",
|
|
@@ -6,8 +6,8 @@ import { callOperation, openapiOrWarn, workflowOperation } from "../invoke.js";
|
|
|
6
6
|
import { changedBy, docsPage, formatValue, isOperatorChange, LIMIT_ABOVE_CEILING, limitRef, quotaSetting, readLimits, } from "../limits.js";
|
|
7
7
|
import { deref, jsonBodySchema, operationForPath, validateBody } from "../openapi.js";
|
|
8
8
|
import { readGlobalRole, readPrincipal } from "../principal.js";
|
|
9
|
-
import { cavelonCommand
|
|
10
|
-
import { ENV_OPTION
|
|
9
|
+
import { cavelonCommand } from "../printed.js";
|
|
10
|
+
import { ENV_OPTION } from "./values.js";
|
|
11
11
|
const UNIT_WORDS = {
|
|
12
12
|
megabytes: ["mb", "megabytes"],
|
|
13
13
|
bytes: ["b", "bytes"],
|
|
@@ -103,8 +103,8 @@ function findTarget(published, key, explicitTenant) {
|
|
|
103
103
|
code: "limit_not_found",
|
|
104
104
|
message: `This instance lists no limit ${key}.`,
|
|
105
105
|
hint: lines.length
|
|
106
|
-
? `${lines.join(" ")}
|
|
107
|
-
: "
|
|
106
|
+
? `${lines.join(" ")} \`${cavelonCommand("limits")}\` lists every limit.`
|
|
107
|
+
: `\`${cavelonCommand("limits")}\` lists every limit; this instance names none that changes through the API.`,
|
|
108
108
|
details: { key, changeable: [...tenant, ...operator], sent: false },
|
|
109
109
|
});
|
|
110
110
|
}
|
|
@@ -346,11 +346,11 @@ async function pathParams(ctx, change, principal) {
|
|
|
346
346
|
for (const match of change.path.matchAll(/\{([^}]+)\}/g)) {
|
|
347
347
|
const name = match[1];
|
|
348
348
|
if (name !== "tenant_id") {
|
|
349
|
-
throw notPublished(`${change.method} ${change.path} needs ${name}, which the kit cannot fill, so nothing was sent.`,
|
|
349
|
+
throw notPublished(`${change.method} ${change.path} needs ${name}, which the kit cannot fill, so nothing was sent.`, `The instance names an operation this kit does not know how to call; \`${cavelonCommand("api", "describe")}\` shows it.`);
|
|
350
350
|
}
|
|
351
351
|
const tenantId = (await ctx.client()).target.tenantId ?? principal?.tenant_id ?? undefined;
|
|
352
352
|
if (!tenantId)
|
|
353
|
-
throw usageError(
|
|
353
|
+
throw usageError(`Which tenant? Choose one with \`${cavelonCommand("use")}\` (it lists your tenants) or --tenant.`);
|
|
354
354
|
params[name] = [tenantId];
|
|
355
355
|
}
|
|
356
356
|
return params;
|
|
@@ -507,7 +507,7 @@ export const limitsSet = {
|
|
|
507
507
|
throw new CavelonError(ExitCode.usage, {
|
|
508
508
|
code: "tenant_required",
|
|
509
509
|
message: "Limits belong to a tenant, and none is chosen.",
|
|
510
|
-
hint:
|
|
510
|
+
hint: `Choose one with \`${cavelonCommand("use")}\` (it lists your tenants) or pass --tenant; an operator's change reads the limits of any tenant and sends in Platform mode.`,
|
|
511
511
|
});
|
|
512
512
|
}
|
|
513
513
|
if (!published.published) {
|
|
@@ -543,7 +543,6 @@ export const limitsSet = {
|
|
|
543
543
|
if (refused)
|
|
544
544
|
throw refused;
|
|
545
545
|
const params = { ...fixed, ...(await pathParams(ctx, change, operator ? undefined : principal)) };
|
|
546
|
-
const flags = targetFlags(session);
|
|
547
546
|
const previous = await previousValue(ctx, published, target);
|
|
548
547
|
const operation = {
|
|
549
548
|
operation: change.operation,
|
|
@@ -577,7 +576,7 @@ export const limitsSet = {
|
|
|
577
576
|
: `a credential with ${anyOf(change.permissions)} (a session, a personal access token, or an admin API key of the tenant)`;
|
|
578
577
|
const gate = await confirmation(ctx, input, "limits_set", { key, value, previous: previous ?? null, operation });
|
|
579
578
|
if (!gate.confirmed) {
|
|
580
|
-
const confirm = gate.confirm(
|
|
579
|
+
const confirm = gate.confirm(cavelonCommand("limits", "set", key, argText(value), "--confirm"));
|
|
581
580
|
const source = target.limit && target.kind === "limit" ? ` (source now: ${target.limit.source}${target.limit.origin ? `, origin: ${target.limit.origin}` : ""})` : "";
|
|
582
581
|
const what = target.scope === "platform" && target.limit?.tenant_change
|
|
583
582
|
? [`This changes the platform's cap for every tenant without its own; --tenant <id|slug> sets one tenant's own cap.`]
|
package/dist/commands/limits.js
CHANGED
|
@@ -4,6 +4,7 @@ import { CavelonError, ExitCode } from "../errors.js";
|
|
|
4
4
|
import { table } from "../format.js";
|
|
5
5
|
import { branchConcurrency, branchConcurrencyText } from "../branches.js";
|
|
6
6
|
import { bindsNow, bindsWhenText, changedBy, docsPage, formatQuota, formatQuotaValue, formatValue, isOperatorChange, readLimits, readQuotas, } from "../limits.js";
|
|
7
|
+
import { cavelonCommand, fill } from "../printed.js";
|
|
7
8
|
const SOURCE_ORDER = ["tenant", "platform", "licence"];
|
|
8
9
|
const SOURCE_TITLE = {
|
|
9
10
|
tenant: "Set by this tenant (its own settings)",
|
|
@@ -56,7 +57,7 @@ export const limits = {
|
|
|
56
57
|
throw new CavelonError(ExitCode.usage, {
|
|
57
58
|
code: "tenant_required",
|
|
58
59
|
message: "Limits belong to a tenant, and none is chosen.",
|
|
59
|
-
hint:
|
|
60
|
+
hint: `Choose one with \`${cavelonCommand("use")}\` (it lists your tenants) or pass --tenant <name or slug>.`,
|
|
60
61
|
});
|
|
61
62
|
}
|
|
62
63
|
if (!published.published) {
|
|
@@ -126,7 +127,7 @@ export const limits = {
|
|
|
126
127
|
const operatorChangeable = values.filter((v) => [v.change, v.tenant_change].some((c) => c && isOperatorChange(c))).map((v) => v.key);
|
|
127
128
|
if (tenantChangeable.length) {
|
|
128
129
|
const owner = quotaValues.filter((q) => q.changeable_by === "tenant_owner" && tenantChangeable.includes(q.key)).map((q) => q.key);
|
|
129
|
-
text += `\n\nA tenant admin changes ${tenantChangeable.length === 1 ? "it" : "these"} with:
|
|
130
|
+
text += `\n\nA tenant admin changes ${tenantChangeable.length === 1 ? "it" : "these"} with: ${cavelonCommand("limits", "set", fill("key"), fill("value"))} (shows the change; --confirm sends it)`;
|
|
130
131
|
if (owner.length)
|
|
131
132
|
text += `; ${owner.join(", ")} only a Tenant Owner (settings.manage)`;
|
|
132
133
|
}
|
|
@@ -135,7 +136,7 @@ export const limits = {
|
|
|
135
136
|
}
|
|
136
137
|
const pages = [...new Set(values.map((v) => docsPage(v.docs)).filter(Boolean))];
|
|
137
138
|
if (pages.length)
|
|
138
|
-
text += `\n\nHow to change one:
|
|
139
|
+
text += `\n\nHow to change one: ${cavelonCommand("docs", "get", fill("page"))} (${pages.join(", ")})`;
|
|
139
140
|
return {
|
|
140
141
|
data: {
|
|
141
142
|
published: true,
|
package/dist/commands/loops.js
CHANGED
|
@@ -8,7 +8,7 @@ import { callStable } from "../invoke.js";
|
|
|
8
8
|
import { catalogEntry } from "../package-check.js";
|
|
9
9
|
import { readPrincipal } from "../principal.js";
|
|
10
10
|
import { isUuid } from "../session.js";
|
|
11
|
-
import { cavelonCommand } from "../
|
|
11
|
+
import { cavelonCommand, fill } from "../printed.js";
|
|
12
12
|
import { readBody } from "./api.js";
|
|
13
13
|
import { TIMEOUT_OPTION, timeoutMs, waitAndReport } from "./async.js";
|
|
14
14
|
import { catalogFor } from "./solution.js";
|
|
@@ -31,12 +31,12 @@ export async function resolveTrigger(ctx, ref) {
|
|
|
31
31
|
throw new CavelonError(ExitCode.failure, {
|
|
32
32
|
code: hits.length ? "trigger_ambiguous" : "trigger_not_found",
|
|
33
33
|
message: hits.length ? `${hits.length} triggers are named "${ref}"; pass its id.` : `No trigger "${ref}" in this tenant.`,
|
|
34
|
-
hint: "
|
|
34
|
+
hint: `\`${cavelonCommand("api", "list_triggers")}\` lists them with their ids and slugs.`,
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
async function getRun(ctx, runId) {
|
|
38
38
|
if (!isUuid(runId))
|
|
39
|
-
throw usageError(`"${runId}" is not a run id.`, "
|
|
39
|
+
throw usageError(`"${runId}" is not a run id.`, `\`${cavelonCommand("loop", "start")}\` prints the run id.`);
|
|
40
40
|
return callStable(ctx, "GET", "/api/v1/triggers/runs/{run_id}", "trigger runs", { params: { run_id: [runId] } });
|
|
41
41
|
}
|
|
42
42
|
const MAX_LOOP_PAGES = 5;
|
|
@@ -71,7 +71,7 @@ async function pickLoop(ctx, runId, loopId, fits, what) {
|
|
|
71
71
|
throw new CavelonError(ExitCode.failure, {
|
|
72
72
|
code: "loop_not_found",
|
|
73
73
|
message: `Run ${runId} has no loop (yet).`,
|
|
74
|
-
hint: `A loop starts when the run reaches its Masterloop node;
|
|
74
|
+
hint: `A loop starts when the run reaches its Masterloop node; \`${cavelonCommand("loop", "watch", runId)}\` waits for it.`,
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
const candidates = loops.filter(fits);
|
|
@@ -217,9 +217,9 @@ export const loopStart = {
|
|
|
217
217
|
return {
|
|
218
218
|
data: started,
|
|
219
219
|
text: `Started run ${run.id} of ${trigger.slug} (${run.status}).\n` +
|
|
220
|
-
`Follow:
|
|
221
|
-
(run.operation_id ? `Wait:
|
|
222
|
-
`Stop:
|
|
220
|
+
`Follow: ${cavelonCommand("loop", "watch", run.id)}\n` +
|
|
221
|
+
(run.operation_id ? `Wait: ${cavelonCommand("wait", run.operation_id)}\n` : "") +
|
|
222
|
+
`Stop: ${cavelonCommand("loop", "cancel", run.id, "--confirm")}`,
|
|
223
223
|
};
|
|
224
224
|
},
|
|
225
225
|
};
|
|
@@ -246,7 +246,7 @@ export const loopCancel = {
|
|
|
246
246
|
const loops = (await loopsOf(ctx, run.id)).map(loopSummary);
|
|
247
247
|
const gate = await confirmation(ctx, input, "loop_cancel", { run: run.id });
|
|
248
248
|
if (!gate.confirmed) {
|
|
249
|
-
const confirm = gate.confirm(
|
|
249
|
+
const confirm = gate.confirm(cavelonCommand("loop", "cancel", run.id, "--confirm"));
|
|
250
250
|
return {
|
|
251
251
|
data: { cancelled: false, run: runSummary(run, note), loops, confirm, ...gate.fields },
|
|
252
252
|
text: `Run ${run.id} (${run.workflow_name}) is ${run.status}` +
|
|
@@ -260,7 +260,7 @@ export const loopCancel = {
|
|
|
260
260
|
const cancelled = await callStable(ctx, "POST", "/api/v1/triggers/runs/{run_id}/cancel", "cancelling runs", { params: { run_id: [run.id] } });
|
|
261
261
|
return {
|
|
262
262
|
data: { cancelled: true, run: runSummary(cancelled), loops },
|
|
263
|
-
text: `Run ${cancelled.id} is ${cancelled.status}; its loops stop at their next safe point.` + (cancelled.operation_id ? `\nWait:
|
|
263
|
+
text: `Run ${cancelled.id} is ${cancelled.status}; its loops stop at their next safe point.` + (cancelled.operation_id ? `\nWait: ${cavelonCommand("wait", cancelled.operation_id)}` : ""),
|
|
264
264
|
};
|
|
265
265
|
},
|
|
266
266
|
};
|
|
@@ -298,7 +298,7 @@ export const loopIterations = {
|
|
|
298
298
|
(table(items, ["iteration", "child_status", "verdict", "outcome", "duration_ms", "child_run_id"]) || "No iterations yet.") +
|
|
299
299
|
moreHint(next, cavelonCommand("loop", "iterations", loop.owner_run_id, "--loop", loop.id)) +
|
|
300
300
|
(page.content_visible ? "" : "\nIteration results are hidden from this credential.") +
|
|
301
|
-
(items.length ? `\nOne iteration's run: ${cavelonCommand("trace")}
|
|
301
|
+
(items.length ? `\nOne iteration's run: ${cavelonCommand("trace", fill("child_run_id"))}` : ""),
|
|
302
302
|
};
|
|
303
303
|
},
|
|
304
304
|
};
|
|
@@ -318,6 +318,7 @@ function envelopeIn(it, loop, newest) {
|
|
|
318
318
|
}
|
|
319
319
|
export const loopWatch = {
|
|
320
320
|
name: "loop watch",
|
|
321
|
+
mcpInstead: "loop iterations",
|
|
321
322
|
summary: "Follow a loop: one line per decided iteration and per state change, then the loop's outcome.",
|
|
322
323
|
description: "Prints each iteration once the loop accepted it, rejected it or its child failed, with its outcome and usage\n" +
|
|
323
324
|
"(one JSON object per line with --json), and the loop's outcome when it ends or pauses. Exit 0 when the loop\n" +
|
|
@@ -525,7 +526,7 @@ function resumeCommand(loop, reason) {
|
|
|
525
526
|
return cavelonCommand("loop", "resume", loop.owner_run_id, "--loop", loop.id, ...(reason ? ["--reason", reason] : []));
|
|
526
527
|
}
|
|
527
528
|
async function startAgain(ctx, loop) {
|
|
528
|
-
let start = "
|
|
529
|
+
let start = cavelonCommand("loop", "start", fill("trigger"));
|
|
529
530
|
try {
|
|
530
531
|
const run = await getRun(ctx, loop.owner_run_id);
|
|
531
532
|
if (run.trigger_definition_id)
|
|
@@ -623,7 +624,7 @@ function controlCommand(action) {
|
|
|
623
624
|
const text = pausing
|
|
624
625
|
? `Pause requested for loop ${receipt.loop_id} (${receipt.state}); it pauses after the current iteration.`
|
|
625
626
|
: `Loop ${receipt.loop_id} resumes (${receipt.state}).`;
|
|
626
|
-
return { data: { ...receipt, run_id: loop.owner_run_id, operation_id: loop.operation_id }, text: `${text}\nFollow:
|
|
627
|
+
return { data: { ...receipt, run_id: loop.owner_run_id, operation_id: loop.operation_id }, text: `${text}\nFollow: ${cavelonCommand("loop", "watch", loop.owner_run_id)}` };
|
|
627
628
|
},
|
|
628
629
|
};
|
|
629
630
|
}
|
|
@@ -633,11 +634,11 @@ const REVIEWED_REASON_OPTION = {
|
|
|
633
634
|
description: "The pause reason a person reviewed, exactly as the loop names it (task_blocked, not free text); only a verdict on the task needs it.",
|
|
634
635
|
};
|
|
635
636
|
function reviewRequired(loop, message, hint) {
|
|
636
|
-
const check = `${cavelonCommand("loop", "iterations", loop.owner_run_id, "--loop", loop.id)} and ${cavelonCommand("trace")}
|
|
637
|
+
const check = `${cavelonCommand("loop", "iterations", loop.owner_run_id, "--loop", loop.id)} and ${cavelonCommand("trace", fill("child_run_id"))}`;
|
|
637
638
|
return new CavelonError(ExitCode.needsAction, {
|
|
638
639
|
code: "loop_resume_review_required",
|
|
639
640
|
message,
|
|
640
|
-
hint: [hint, `A person checks the cause (${check}) and fixes it, then: ${resumeCommand(loop, loop.reason ?? "
|
|
641
|
+
hint: [hint, `A person checks the cause (${check}) and fixes it, then: ${resumeCommand(loop, loop.reason ?? fill("pause_reason"))}`].filter(Boolean).join(" "),
|
|
641
642
|
});
|
|
642
643
|
}
|
|
643
644
|
async function checkResume(ctx, loop, reason) {
|
package/dist/commands/models.js
CHANGED
|
@@ -5,11 +5,11 @@ import { confirmation } from "../confirm-token.js";
|
|
|
5
5
|
import { moreHint, table } from "../format.js";
|
|
6
6
|
import { callStable, workflowOperation } from "../invoke.js";
|
|
7
7
|
import { deref, jsonBodySchema, validateBody } from "../openapi.js";
|
|
8
|
-
import { cavelonCommand,
|
|
8
|
+
import { cavelonCommand, fill } from "../printed.js";
|
|
9
9
|
import { STATE_DIR } from "../local-state.js";
|
|
10
10
|
import { listedPages } from "./docs.js";
|
|
11
11
|
import { refreshInventory } from "./inventory.js";
|
|
12
|
-
import { ENV_OPTION
|
|
12
|
+
import { ENV_OPTION } from "./values.js";
|
|
13
13
|
const LIST_ROUTE = "/api/v1/model-registry";
|
|
14
14
|
const ROW_ROUTE = "/api/v1/model-registry/{model_registry_id}";
|
|
15
15
|
const LIMIT_FIELD = "max_concurrent_requests";
|
|
@@ -55,7 +55,7 @@ async function readRows(ctx) {
|
|
|
55
55
|
const rows = await callStable(ctx, "GET", LIST_ROUTE, "the Model Registry");
|
|
56
56
|
return Array.isArray(rows) ? rows : [];
|
|
57
57
|
}
|
|
58
|
-
function findRow(rows, ref
|
|
58
|
+
function findRow(rows, ref) {
|
|
59
59
|
const byId = rows.find((r) => r.id === ref) ?? rows.find((r) => r.model_id === ref);
|
|
60
60
|
if (byId)
|
|
61
61
|
return byId;
|
|
@@ -63,13 +63,13 @@ function findRow(rows, ref, flags) {
|
|
|
63
63
|
if (byName.length === 1)
|
|
64
64
|
return byName[0];
|
|
65
65
|
if (byName.length > 1) {
|
|
66
|
-
throw usageError(`Several Model Registry rows are called "${ref}": ${byName.map((r) => r.model_id).join(", ")}.`,
|
|
66
|
+
throw usageError(`Several Model Registry rows are called "${ref}": ${byName.map((r) => r.model_id).join(", ")}.`, `Name the row by its model_id or id; \`${cavelonCommand("models", "list")}\` shows them.`);
|
|
67
67
|
}
|
|
68
68
|
throw new CavelonError(ExitCode.failure, {
|
|
69
69
|
code: "model_not_found",
|
|
70
70
|
status: 404,
|
|
71
71
|
message: `This tenant's Model Registry has no row "${ref}".`,
|
|
72
|
-
hint:
|
|
72
|
+
hint: `\`${cavelonCommand("models", "list")}\` shows its rows by model_id and id.`,
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
function parseLimit(raw) {
|
|
@@ -90,7 +90,7 @@ function requireLimitField(doc, op) {
|
|
|
90
90
|
throw new CavelonError(ExitCode.failure, {
|
|
91
91
|
code: "operation_unavailable",
|
|
92
92
|
message: `This instance's Model Registry rows have no ${LIMIT_FIELD} (PATCH ${ROW_ROUTE} does not take it), so nothing was sent.`,
|
|
93
|
-
hint:
|
|
93
|
+
hint: `The instance is older than endpoint limits; \`${cavelonCommand("status")}\` shows its version.`,
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
export const modelsList = {
|
|
@@ -107,7 +107,6 @@ export const modelsList = {
|
|
|
107
107
|
async run(ctx, input) {
|
|
108
108
|
const limit = intOption(input, "limit", { min: 1, max: 500, fallback: 50 });
|
|
109
109
|
const session = await ctx.session();
|
|
110
|
-
const flags = targetFlags(session);
|
|
111
110
|
const rows = await readRows(ctx);
|
|
112
111
|
if (session.project) {
|
|
113
112
|
await refreshInventory(session.project.root, "models", rows.map((r) => r.model_id), ctx.io.now()).catch((error) => ctx.warn(`Could not keep the model list for validate in ${STATE_DIR}/ (${error instanceof Error ? error.message : String(error)}).`));
|
|
@@ -128,9 +127,9 @@ export const modelsList = {
|
|
|
128
127
|
}));
|
|
129
128
|
const pages = await listedPages(ctx, [CAPACITY_TUTORIAL_PAGE]);
|
|
130
129
|
const lines = [
|
|
131
|
-
table(shown, ["model_id", "provider", "endpoint", "max_concurrent_requests", "active"], 60) + moreHint(page.next_cursor,
|
|
130
|
+
table(shown, ["model_id", "provider", "endpoint", "max_concurrent_requests", "active"], 60) + moreHint(page.next_cursor, cavelonCommand("models", "list")),
|
|
132
131
|
"",
|
|
133
|
-
`Rows with the same endpoint share one max_concurrent_requests count. Change it with:
|
|
132
|
+
`Rows with the same endpoint share one max_concurrent_requests count. Change it with: ${cavelonCommand("models", "set-limit", fill("model_id"), fill("n|none"))}`,
|
|
134
133
|
...pages.map((p) => `Plan it for a self-hosted endpoint: ${cavelonCommand("docs", "get", p)}`),
|
|
135
134
|
];
|
|
136
135
|
return { data: { items, next_cursor: page.next_cursor, total: page.total }, text: lines.join("\n") };
|
|
@@ -160,13 +159,12 @@ export const modelsSetLimit = {
|
|
|
160
159
|
async run(ctx, input) {
|
|
161
160
|
const ref = positional(input, "model");
|
|
162
161
|
const limit = parseLimit(positional(input, "limit"));
|
|
163
|
-
const flags = targetFlags(await ctx.session());
|
|
164
162
|
const { doc, op } = await workflowOperation(ctx, "PATCH", ROW_ROUTE, "changing Model Registry rows");
|
|
165
163
|
requireLimitField(doc, op);
|
|
166
164
|
if (doc)
|
|
167
165
|
validateBody(doc, op, { [LIMIT_FIELD]: limit });
|
|
168
166
|
const rows = await readRows(ctx);
|
|
169
|
-
const row = findRow(rows, ref
|
|
167
|
+
const row = findRow(rows, ref);
|
|
170
168
|
const model = rowView(row, rows);
|
|
171
169
|
const previous = model.max_concurrent_requests;
|
|
172
170
|
if (limit !== null && !model.endpoint) {
|
|
@@ -187,7 +185,7 @@ export const modelsSetLimit = {
|
|
|
187
185
|
const sharing = model.shares_endpoint_with?.length ? ` It shares the count with ${model.shares_endpoint_with.join(", ")} (same endpoint).` : "";
|
|
188
186
|
const gate = await confirmation(ctx, input, "models_set_limit", { row: row.id, previous, limit });
|
|
189
187
|
if (!gate.confirmed) {
|
|
190
|
-
const confirm = gate.confirm(
|
|
188
|
+
const confirm = gate.confirm(cavelonCommand("models", "set-limit", row.model_id, limitText(limit), "--confirm"));
|
|
191
189
|
return {
|
|
192
190
|
data: { ...base, changed: false, sent: false, confirm, ...gate.fields },
|
|
193
191
|
text: `${label}: max_concurrent_requests ${limitText(previous)} → ${limitText(limit)}.${sharing}\n${gate.mismatch ? `${gate.mismatch}\n` : ""}Nothing was changed. Change it with: ${confirm}`,
|