@cavelon/cli 0.1.9 → 0.1.11
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 +23 -10
- package/dist/access.js +194 -0
- package/dist/acting.js +123 -0
- package/dist/agent-env.js +20 -2
- 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 +40 -21
- package/dist/commands/async.js +7 -4
- package/dist/commands/chat.js +18 -15
- package/dist/commands/db.js +367 -0
- package/dist/commands/docs.js +87 -9
- package/dist/commands/fmt.js +6 -4
- package/dist/commands/index.js +8 -0
- package/dist/commands/init.js +106 -28
- package/dist/commands/limits-set.js +12 -11
- package/dist/commands/limits.js +4 -3
- package/dist/commands/loops.js +75 -19
- package/dist/commands/models.js +12 -13
- package/dist/commands/sandboxes.js +22 -16
- package/dist/commands/schema.js +6 -5
- package/dist/commands/session.js +134 -37
- package/dist/commands/setup.js +4 -2
- package/dist/commands/solution.js +289 -93
- package/dist/commands/tenants.js +58 -22
- package/dist/commands/values.js +110 -45
- package/dist/commands/work.js +31 -17
- package/dist/confirm-token.js +15 -5
- package/dist/context.js +3 -1
- package/dist/contracts.js +39 -13
- package/dist/database-queries.js +301 -0
- package/dist/default-route.js +1 -1
- package/dist/features.js +2 -1
- package/dist/fsutil.js +14 -0
- package/dist/harness-ref.js +6 -4
- package/dist/http.js +39 -4
- package/dist/invoke.js +7 -2
- package/dist/kit-codes.js +14 -2
- package/dist/limits.js +1 -1
- package/dist/main.js +13 -1
- package/dist/mcp.js +105 -26
- package/dist/openapi.js +5 -2
- package/dist/operations.js +3 -2
- package/dist/package-check.js +29 -4
- package/dist/package-files.js +5 -1
- package/dist/package-format.js +10 -0
- package/dist/preview-report.js +46 -7
- package/dist/principal.js +24 -2
- package/dist/printed.js +182 -0
- package/dist/project.js +2 -1
- package/dist/results.js +1 -1
- package/dist/secret-access.js +42 -0
- package/dist/session.js +39 -19
- package/dist/shell.js +0 -3
- package/dist/skills/cavelon-authoring/SKILL.md +88 -4
- package/dist/skills/cavelon-long-running/SKILL.md +9 -3
- package/dist/skills/cavelon-loop/SKILL.md +81 -19
- package/dist/skills/cavelon-testing/SKILL.md +28 -1
- package/dist/tenant-choice.js +7 -7
- package/dist/trace-view.js +11 -1
- package/dist/update-check.js +2 -2
- package/dist/user-config.js +24 -0
- 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,
|
|
@@ -575,9 +574,11 @@ export const limitsSet = {
|
|
|
575
574
|
const allowed = operator
|
|
576
575
|
? `a personal access token in Platform mode of a ${anyOf(change.requires_role ?? [], "platform role")}`
|
|
577
576
|
: `a credential with ${anyOf(change.permissions)} (a session, a personal access token, or an admin API key of the tenant)`;
|
|
578
|
-
const gate = await confirmation(ctx, input, "limits_set", { key, value, previous: previous ?? null, operation }
|
|
577
|
+
const gate = await confirmation(ctx, input, "limits_set", { key, value, previous: previous ?? null, operation }, {
|
|
578
|
+
platform: operator ? (target.scope === "one_tenant" ? "tenant" : "outside") : undefined,
|
|
579
|
+
});
|
|
579
580
|
if (!gate.confirmed) {
|
|
580
|
-
const confirm = gate.confirm(
|
|
581
|
+
const confirm = gate.confirm(cavelonCommand("limits", "set", key, argText(value), "--confirm"));
|
|
581
582
|
const source = target.limit && target.kind === "limit" ? ` (source now: ${target.limit.source}${target.limit.origin ? `, origin: ${target.limit.origin}` : ""})` : "";
|
|
582
583
|
const what = target.scope === "platform" && target.limit?.tenant_change
|
|
583
584
|
? [`This changes the platform's cap for every tenant without its own; --tenant <id|slug> sets one tenant's own cap.`]
|
|
@@ -586,7 +587,7 @@ export const limitsSet = {
|
|
|
586
587
|
: [];
|
|
587
588
|
return {
|
|
588
589
|
data: { ...base, changed: false, sent: false, confirm, ...gate.fields },
|
|
589
|
-
text: [`${key}: ${from} → ${to}${source}.`, ...what, `Sends: ${sends}`, `Allowed: ${allowed}.`, ...(gate.mismatch ? [gate.mismatch] : []), `Nothing was changed. Change it with: ${confirm}`].join("\n"),
|
|
590
|
+
text: [`${key}: ${from} → ${to}${source}.`, ...what, `Sends: ${sends}`, `Allowed: ${allowed}.`, gate.where, ...(gate.mismatch ? [gate.mismatch] : []), `Nothing was changed. Change it with: ${confirm}`].join("\n"),
|
|
590
591
|
...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
|
|
591
592
|
};
|
|
592
593
|
}
|
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,
|