@cavelon/cli 0.1.10 → 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/commands/api.js +38 -19
- package/dist/commands/chat.js +10 -5
- package/dist/commands/db.js +367 -0
- package/dist/commands/docs.js +83 -7
- package/dist/commands/index.js +6 -0
- package/dist/commands/limits-set.js +4 -2
- package/dist/commands/loops.js +60 -5
- package/dist/commands/models.js +2 -1
- package/dist/commands/sandboxes.js +7 -2
- package/dist/commands/session.js +107 -22
- package/dist/commands/solution.js +144 -32
- package/dist/commands/tenants.js +44 -8
- package/dist/commands/values.js +50 -9
- package/dist/commands/work.js +13 -5
- package/dist/confirm-token.js +12 -4
- package/dist/context.js +3 -1
- package/dist/contracts.js +37 -12
- package/dist/database-queries.js +301 -0
- package/dist/fsutil.js +14 -0
- package/dist/http.js +36 -2
- package/dist/invoke.js +4 -0
- package/dist/kit-codes.js +5 -0
- package/dist/mcp.js +69 -10
- package/dist/package-check.js +19 -0
- package/dist/preview-report.js +2 -2
- package/dist/principal.js +24 -2
- package/dist/secret-access.js +16 -4
- package/dist/session.js +36 -8
- package/dist/skills/cavelon-authoring/SKILL.md +79 -2
- package/dist/skills/cavelon-long-running/SKILL.md +8 -2
- package/dist/skills/cavelon-loop/SKILL.md +71 -16
- package/dist/skills/cavelon-testing/SKILL.md +28 -1
- package/dist/trace-view.js +10 -0
- package/dist/update-check.js +2 -2
- package/dist/user-config.js +24 -0
- package/package.json +1 -1
|
@@ -5,7 +5,8 @@ import { boolOption, intOption, positional, stringOption } from "../command.js";
|
|
|
5
5
|
import { Contracts } from "../contracts.js";
|
|
6
6
|
import { CavelonError, ExitCode, usageError } from "../errors.js";
|
|
7
7
|
import { drivenByAgent } from "../agent-env.js";
|
|
8
|
-
import { confirmation,
|
|
8
|
+
import { confirmation, confirmTokenRequired, shellTokenRequired } from "../confirm-token.js";
|
|
9
|
+
import { actingTarget, targetLine, targetText } from "../acting.js";
|
|
9
10
|
import { clip, keyValues } from "../format.js";
|
|
10
11
|
import { readTextFile, writeFileAtomic } from "../fsutil.js";
|
|
11
12
|
import { uncommitted } from "../git.js";
|
|
@@ -16,6 +17,7 @@ import { defaultChangeLine, defaultCommands, named, readDefaultRoute, setDefault
|
|
|
16
17
|
import { ceilingHint, LIMIT_ABOVE_CEILING, parseLimits, readLimits } from "../limits.js";
|
|
17
18
|
import { digest, fileDigest, fileDigests, listPreviews, loadPreview, previewExpiry, readItemFiles, readPulledFiles, rememberAppliedFiles, retiredPreview, retirePreviews, savePreview, writePulledFiles, writeState, } from "../local-state.js";
|
|
18
19
|
import { catalogEntry, checkPackage, KIT_CODES, packageVersionOf } from "../package-check.js";
|
|
20
|
+
import { applyQueryNotes, connectorOffer, NEEDS_SUPERADMIN_CODE, queryBlockedHint, queryChanges, readQueryBaseline, rememberQueries } from "../database-queries.js";
|
|
19
21
|
import { cliFix, similarCodes } from "../code-hints.js";
|
|
20
22
|
import { KIT_ERROR_CODES } from "../kit-codes.js";
|
|
21
23
|
import { pairOrderHint, pairOrderPointer } from "../pair-order.js";
|
|
@@ -30,7 +32,8 @@ import { readInventory, readInventoryKinds, writeInventory } from "./inventory.j
|
|
|
30
32
|
import { checkedBy, MODEL_UNKNOWN_CODE, missingInventory, REFERENCE_UNKNOWN_CODE } from "../package-references.js";
|
|
31
33
|
import { cavelonCommand, printedCommand, spoken } from "../printed.js";
|
|
32
34
|
import { secretSetCommand, variableSetCommand } from "./values.js";
|
|
33
|
-
import { maySetSecrets, SECRET_SETTER } from "../secret-access.js";
|
|
35
|
+
import { maySetSecrets, SECRET_SETTER, VARIABLE_SETTER } from "../secret-access.js";
|
|
36
|
+
import { ACTIVATOR, accessFor, accessOf, mayActivate, operationAccess, principalOf } from "../access.js";
|
|
34
37
|
const HARNESS_OPTION = { type: "string", value: "<harness>", description: "The solution (harness): its name, slug or id; default: env file, then cavelon.yaml." };
|
|
35
38
|
const ENV_OPTION = { type: "string", value: "<name>", description: "Use env/<name>.yaml: its tenant, solution and runtime bindings." };
|
|
36
39
|
export function requireSolution(session, harness) {
|
|
@@ -252,6 +255,7 @@ export const pull = {
|
|
|
252
255
|
}
|
|
253
256
|
const report = await writePackage(project.root, project.layout, exported, schema, options);
|
|
254
257
|
await writePulledFiles(project.root, [...report.written, ...report.unchanged], placed);
|
|
258
|
+
await rememberQueries(project.root, exported, schema, "pull", ctx.io.now());
|
|
255
259
|
if (harness && !project.harness)
|
|
256
260
|
await setProjectKey(project, "harness", harness.slug);
|
|
257
261
|
if (version && project.packageVersion !== version)
|
|
@@ -345,6 +349,7 @@ async function validatePackage(ctx, project, offline) {
|
|
|
345
349
|
limits: await limitsFor(ctx, offline),
|
|
346
350
|
inventory,
|
|
347
351
|
solution: project.harness,
|
|
352
|
+
queryBaseline: await readQueryBaseline(project.root),
|
|
348
353
|
});
|
|
349
354
|
return { disk, findings, schema, schemaVersion: schema["x-package-version"] ?? version ?? null, used, skipped };
|
|
350
355
|
}
|
|
@@ -368,7 +373,7 @@ export const validate = {
|
|
|
368
373
|
"changes, so its copy is read again after a minute (CAVELON_CONTRACT_TTL_SECONDS), or checked with the ETag the instance\n" +
|
|
369
374
|
"sent with it; --verbose says which copy was used.\n" +
|
|
370
375
|
"Warns (never fails) when a fan-out or Map loop's max_concurrency is above the instance's branch width, and when the\n" +
|
|
371
|
-
"tenant runs fan-outs and Map loops in sequence, from the limits the instance last published.\n" +
|
|
376
|
+
"tenant runs fan-outs and Map loops in sequence, from the limits the instance last published for the tenant.\n" +
|
|
372
377
|
"References to skills, tools, knowledge bases, solutions and models outside the package are checked against the tenant's\n" +
|
|
373
378
|
"lists in .cavelon/inventory.json (pull, models list); a list no command has read yet is read now, unless --offline, and a\n" +
|
|
374
379
|
"check that cannot be made is named (`skipped` in --json). A reference that is in neither is a warning, as it may be created\n" +
|
|
@@ -468,7 +473,7 @@ function counts(map) {
|
|
|
468
473
|
function list(items, max = 10) {
|
|
469
474
|
return items.length > max ? `${items.slice(0, max).join(", ")} and ${items.length - max} more` : items.join(", ");
|
|
470
475
|
}
|
|
471
|
-
function needsLines(needs) {
|
|
476
|
+
function needsLines(needs, access) {
|
|
472
477
|
const lines = [];
|
|
473
478
|
const secrets = valueNeeds(needs.secrets);
|
|
474
479
|
if (secrets.length) {
|
|
@@ -476,8 +481,11 @@ function needsLines(needs) {
|
|
|
476
481
|
lines.push(["needs secrets", `${each}\n (a person runs these in a terminal, or sets them in the Admin; never the agent)`]);
|
|
477
482
|
}
|
|
478
483
|
const variables = valueNeeds(needs.variables);
|
|
479
|
-
if (variables.length)
|
|
480
|
-
|
|
484
|
+
if (variables.length) {
|
|
485
|
+
const each = needLines(variables, (name) => variableSetCommand(name), cavelonCommand("variables", "list"));
|
|
486
|
+
const who = operationAccess(access, "PUT /api/v1/variables/{name}").allowed === false ? `\n (this credential may not set variables. ${VARIABLE_SETTER})` : "";
|
|
487
|
+
lines.push(["needs variables", each + who]);
|
|
488
|
+
}
|
|
481
489
|
const grants = (needs.oauth_grants ?? []).map((g) => [g.kind, g.tool_slug, g.capability].filter(Boolean).join(" "));
|
|
482
490
|
if (grants.length)
|
|
483
491
|
lines.push(["needs grants", `${list(grants)} (a person connects them in the Admin)`]);
|
|
@@ -534,7 +542,7 @@ export function previewText(p, context = {}) {
|
|
|
534
542
|
const ignored = [...(p.ignored?.sections ?? []), ...(p.ignored?.fields ?? [])];
|
|
535
543
|
if (ignored.length)
|
|
536
544
|
lines.push(["ignored", list(ignored)]);
|
|
537
|
-
const skipped = notApplied(p.ignored?.not_applied, context.disk?.package, context.harness);
|
|
545
|
+
const skipped = notApplied(p.ignored?.not_applied, context.disk?.package, context.harness, mayActivate(context.access));
|
|
538
546
|
if (skipped.length)
|
|
539
547
|
lines.push(["not applied", notAppliedLines(skipped)]);
|
|
540
548
|
const impact = p.impact ?? {};
|
|
@@ -550,7 +558,7 @@ export function previewText(p, context = {}) {
|
|
|
550
558
|
const limits = Object.entries(budget.limits ?? {}).map(([k, v]) => `${k} ${v}`).join(", ");
|
|
551
559
|
lines.push([`loop ${budget.node_slug}`, `${limits}${budget.worst_case_cost != null ? `; worst case ${JSON.stringify(budget.worst_case_cost)}` : ""}`]);
|
|
552
560
|
}
|
|
553
|
-
lines.push(...needsLines(p.target_needs ?? {}));
|
|
561
|
+
lines.push(...needsLines(p.target_needs ?? {}, context.access));
|
|
554
562
|
return keyValues(lines);
|
|
555
563
|
}
|
|
556
564
|
function previewReport(p, context) {
|
|
@@ -561,7 +569,7 @@ function previewReport(p, context) {
|
|
|
561
569
|
const changes = fieldChanges(p.changes);
|
|
562
570
|
if (changes.length)
|
|
563
571
|
out.field_changes = changes;
|
|
564
|
-
const skipped = notApplied(p.ignored?.not_applied, context.disk?.package, context.harness);
|
|
572
|
+
const skipped = notApplied(p.ignored?.not_applied, context.disk?.package, context.harness, mayActivate(context.access));
|
|
565
573
|
if (skipped.length)
|
|
566
574
|
out.not_applied = skipped;
|
|
567
575
|
return out;
|
|
@@ -714,15 +722,18 @@ async function confirmPreview(ctx, project, previewId, allowStale) {
|
|
|
714
722
|
});
|
|
715
723
|
}
|
|
716
724
|
const client = await ctx.client();
|
|
717
|
-
|
|
725
|
+
const keyTenant = session.tokenKind === "api_key" ? (await actingTarget(ctx)).tenant?.id : undefined;
|
|
726
|
+
const actsIn = client.target.tenantId ?? keyTenant;
|
|
727
|
+
if (stored.tenant_id && actsIn && actsIn !== stored.tenant_id) {
|
|
718
728
|
throw new CavelonError(ExitCode.conflict, {
|
|
719
729
|
code: "preview_other_tenant",
|
|
720
|
-
message: `Preview ${previewId} was made for tenant ${stored.tenant_id}, but this command acts in ${
|
|
730
|
+
message: `Preview ${previewId} was made for tenant ${stored.tenant_id}, but this command acts in ${actsIn}.`,
|
|
721
731
|
hint: "Run the confirm command the preview printed; it names the preview's --env and --tenant. Or preview again here.",
|
|
722
732
|
});
|
|
723
733
|
}
|
|
724
734
|
if (stored.tenant_id && session.tokenKind !== "api_key")
|
|
725
735
|
client.target.tenantId = stored.tenant_id;
|
|
736
|
+
const acting = await actingTarget(ctx);
|
|
726
737
|
const disk = await readPackage(project.root, project.layout);
|
|
727
738
|
const changed = await filesChangedSince(project, stored, disk);
|
|
728
739
|
if (digest(disk.package) !== stored.package_digest) {
|
|
@@ -749,6 +760,7 @@ async function confirmPreview(ctx, project, previewId, allowStale) {
|
|
|
749
760
|
...others.map((p) => ({ preview_id: p.preview_id, reason: "superseded", at: now, by: stored.preview_id })),
|
|
750
761
|
]);
|
|
751
762
|
await rememberImported(ctx, project, stored, disk, changed);
|
|
763
|
+
await rememberQueries(project.root, stored.request.package, (await schemaFor(ctx, packageVersionOf(stored.request.package), false)).schema, "apply", ctx.io.now());
|
|
752
764
|
const summary = (result.summary ?? {});
|
|
753
765
|
const still = setCommands(stored.preview, stored.env ?? undefined);
|
|
754
766
|
const sharedSent = stored.request[INCLUDE_TENANT_WIDE] === true;
|
|
@@ -763,6 +775,7 @@ async function confirmPreview(ctx, project, previewId, allowStale) {
|
|
|
763
775
|
: undefined;
|
|
764
776
|
const text = keyValues([
|
|
765
777
|
["applied", `preview ${stored.preview_id}${stored.harness ? ` to ${stored.harness.slug}` : ""}${stored.env ? ` (env ${stored.env})` : ""}`],
|
|
778
|
+
["acted on", targetText(acting)],
|
|
766
779
|
["tenant-wide", sharedText],
|
|
767
780
|
["created", counts(summary?.creates) || undefined],
|
|
768
781
|
["updated", counts(summary?.updates) || undefined],
|
|
@@ -771,7 +784,7 @@ async function confirmPreview(ctx, project, previewId, allowStale) {
|
|
|
771
784
|
["set secrets", still.secrets.length ? indented(still.secrets) + "\n (a person runs these; never the agent)" : undefined],
|
|
772
785
|
["set variables", still.variables.length ? indented(still.variables) : undefined],
|
|
773
786
|
]);
|
|
774
|
-
const data = { applied: true, preview_id: stored.preview_id, env: stored.env, harness: stored.harness, result };
|
|
787
|
+
const data = { applied: true, preview_id: stored.preview_id, env: stored.env, harness: stored.harness, target: acting, result };
|
|
775
788
|
if (sharedSent || sharedImported.length) {
|
|
776
789
|
data.tenant_wide = {
|
|
777
790
|
applied: resultReport ? resultReport.applied : true,
|
|
@@ -819,6 +832,8 @@ function requirementsChanged(error, stored, session, catalog, disk) {
|
|
|
819
832
|
if (pair && !known.has(pair.code))
|
|
820
833
|
known.set(pair.code, pair.hint);
|
|
821
834
|
}
|
|
835
|
+
if (details.some((b) => b.code === NEEDS_SUPERADMIN_CODE))
|
|
836
|
+
known.set(NEEDS_SUPERADMIN_CODE, queryBlockedHint(sectionFiles(disk, ["tools"])));
|
|
822
837
|
return new CavelonError(ExitCode.conflict, {
|
|
823
838
|
code: error.code,
|
|
824
839
|
status: error.status,
|
|
@@ -905,6 +920,7 @@ export const apply = {
|
|
|
905
920
|
readOnly: false,
|
|
906
921
|
destructive: true,
|
|
907
922
|
mcpTool: "apply",
|
|
923
|
+
operations: ["POST /api/v1/agent-graph/import"],
|
|
908
924
|
options: {
|
|
909
925
|
env: ENV_OPTION,
|
|
910
926
|
harness: HARNESS_OPTION,
|
|
@@ -983,13 +999,20 @@ export const apply = {
|
|
|
983
999
|
request[INCLUDE_TENANT_WIDE] = true;
|
|
984
1000
|
if (tenantWide && solutionImport && !shared.length)
|
|
985
1001
|
ctx.warn("--include-tenant-wide: the package holds no tenant-wide section, so this import changes nothing the whole tenant shares.");
|
|
1002
|
+
const baseline = await readQueryBaseline(project.root);
|
|
1003
|
+
const queries = applyQueryNotes(disk.package, baseline ? queryChanges(disk.package, schema, baseline) : [], connectorOffer((await (await ctx.contracts()).capabilities())));
|
|
1004
|
+
for (const warning of queries.warnings)
|
|
1005
|
+
ctx.warn(warning);
|
|
986
1006
|
const client = await ctx.client();
|
|
987
1007
|
const preview = await callStable(ctx, "POST", "/api/v1/agent-graph/import/preview", "previewing imports", {
|
|
988
1008
|
body: request,
|
|
989
1009
|
timeoutMs: 120_000,
|
|
990
1010
|
});
|
|
991
1011
|
const target = harness ? { id: harness.id, slug: harness.slug } : null;
|
|
992
|
-
const
|
|
1012
|
+
const acting = await actingTarget(ctx);
|
|
1013
|
+
const data = { previewed: true, ...preview, env: envFile?.name ?? null, harness: target, target: acting };
|
|
1014
|
+
if (queries.data)
|
|
1015
|
+
data.database_queries = queries.data;
|
|
993
1016
|
const reported = solutionImport ? tenantWideReport(preview.tenant_wide) : undefined;
|
|
994
1017
|
const sections = reported?.sections ?? shared;
|
|
995
1018
|
const applied = reported ? reported.applied : tenantWide || !takes;
|
|
@@ -1028,7 +1051,7 @@ export const apply = {
|
|
|
1028
1051
|
const commands = setCommands(preview);
|
|
1029
1052
|
if (commands.secrets.length || commands.variables.length)
|
|
1030
1053
|
data.set_commands = commands;
|
|
1031
|
-
const context = { disk, harness: harness?.slug };
|
|
1054
|
+
const context = { disk, harness: harness?.slug, access: await accessFor(await ctx.client()) };
|
|
1032
1055
|
Object.assign(data, previewReport(preview, context));
|
|
1033
1056
|
if (!preview.ready) {
|
|
1034
1057
|
const pair = pairOrderHint(await catalogFor(ctx, false), [
|
|
@@ -1043,6 +1066,10 @@ export const apply = {
|
|
|
1043
1066
|
: undefined;
|
|
1044
1067
|
if (sharedHint)
|
|
1045
1068
|
data.tenant_wide_hint = sharedHint;
|
|
1069
|
+
const queryBlocked = blockerDetails(preview.blocker_details).some((b) => b.code === NEEDS_SUPERADMIN_CODE);
|
|
1070
|
+
const queryHint = queryBlocked ? queryBlockedHint(sectionFiles(disk, ["tools"])) : undefined;
|
|
1071
|
+
if (queryHint)
|
|
1072
|
+
data.database_query_hint = queryHint;
|
|
1046
1073
|
return {
|
|
1047
1074
|
data,
|
|
1048
1075
|
text: [
|
|
@@ -1051,6 +1078,7 @@ export const apply = {
|
|
|
1051
1078
|
"",
|
|
1052
1079
|
...(pair ? [`hint: ${pair.hint}`] : []),
|
|
1053
1080
|
...(sharedHint ? [`hint: ${sharedHint}`] : []),
|
|
1081
|
+
...(queryHint ? [`hint: ${queryHint}`] : []),
|
|
1054
1082
|
`The preview has blockers; fix them and run \`${cavelonCommand("apply")}\` again.`,
|
|
1055
1083
|
].join("\n"),
|
|
1056
1084
|
exitCode: ExitCode.validation,
|
|
@@ -1078,7 +1106,7 @@ export const apply = {
|
|
|
1078
1106
|
preview_id: preview.preview_id,
|
|
1079
1107
|
created_at: ctx.io.now().toISOString(),
|
|
1080
1108
|
instance: url,
|
|
1081
|
-
tenant_id: client.target.tenantId ?? null,
|
|
1109
|
+
tenant_id: client.target.tenantId ?? acting.tenant?.id ?? null,
|
|
1082
1110
|
env: envFile?.name ?? null,
|
|
1083
1111
|
harness: target,
|
|
1084
1112
|
package_digest: digest(disk.package),
|
|
@@ -1099,6 +1127,7 @@ export const apply = {
|
|
|
1099
1127
|
previewText(preview, context),
|
|
1100
1128
|
...(sharedLine ? [sharedLine] : []),
|
|
1101
1129
|
"",
|
|
1130
|
+
targetLine(acting),
|
|
1102
1131
|
...(preview.preview_id ? [`preview id: ${preview.preview_id}`] : []),
|
|
1103
1132
|
...(reason ? [`This ${reason}: show this preview to a person before confirming.`] : []),
|
|
1104
1133
|
...(confirmLine ? [`Import exactly this: ${confirmLine}`] : []),
|
|
@@ -1331,10 +1360,11 @@ export async function solutionState(ctx, ref) {
|
|
|
1331
1360
|
state.ready_to_activate = typeof readiness.ready_to_activate === "boolean" ? readiness.ready_to_activate : null;
|
|
1332
1361
|
state.blockers = (readiness.blockers ?? []).map((b) => clip(String(b.label ?? b.key ?? b.detail ?? "?"), 80));
|
|
1333
1362
|
const secrets = missingSecrets(readiness.blockers ?? []);
|
|
1334
|
-
|
|
1335
|
-
|
|
1363
|
+
const principal = await principalOf(await ctx.client());
|
|
1364
|
+
if (secrets.length)
|
|
1336
1365
|
state.missing_secrets = { names: secrets, may_set: maySetSecrets(principal) };
|
|
1337
|
-
|
|
1366
|
+
if (harness.status !== "active")
|
|
1367
|
+
state.may_activate = mayActivate(accessOf(principal));
|
|
1338
1368
|
if ("latest_test_run" in readiness) {
|
|
1339
1369
|
const run = readiness.latest_test_run;
|
|
1340
1370
|
const summary = run?.summary ?? {};
|
|
@@ -1371,7 +1401,7 @@ export function solutionStateLines(state) {
|
|
|
1371
1401
|
lines.push(["secrets", missingSecretsLine(state.missing_secrets.names, state.missing_secrets.may_set)]);
|
|
1372
1402
|
const route = state.default_route;
|
|
1373
1403
|
if (route)
|
|
1374
|
-
lines.push(["default route", defaultRouteText(state.harness, route)]);
|
|
1404
|
+
lines.push(["default route", defaultRouteText(state.harness, route, state.may_activate ?? null)]);
|
|
1375
1405
|
const run = state.latest_test_run;
|
|
1376
1406
|
if (run === null)
|
|
1377
1407
|
lines.push(["last test run", "none yet (`cavelon test run`)"]);
|
|
@@ -1385,12 +1415,14 @@ export function solutionStateLines(state) {
|
|
|
1385
1415
|
lines.push(["state error", state.unavailable]);
|
|
1386
1416
|
return lines;
|
|
1387
1417
|
}
|
|
1388
|
-
function defaultRouteText(harness, route) {
|
|
1418
|
+
function defaultRouteText(harness, route, may) {
|
|
1389
1419
|
if (route.is_default === null)
|
|
1390
1420
|
return "unknown (this instance does not say which solution is the default)";
|
|
1391
1421
|
if (route.is_default)
|
|
1392
1422
|
return "yes: the tenant's chat and widget answer with it where a conversation names no solution";
|
|
1393
1423
|
const now = route.current ? named(route.current) : "no solution";
|
|
1424
|
+
if (harness.status !== "active" && may === false)
|
|
1425
|
+
return `no: ${now} answers the tenant's chat and widget; only an active solution can be the default, and to activate it ${ACTIVATOR}`;
|
|
1394
1426
|
const how = harness.status === "active" ? cavelonCommand("harness", "default", harness.slug) : cavelonCommand("activate", "--harness", harness.slug, "--make-default");
|
|
1395
1427
|
return `no: ${now} answers the tenant's chat and widget; preview a change with ${how}`;
|
|
1396
1428
|
}
|
|
@@ -1416,7 +1448,7 @@ function readinessText(checks, warnings) {
|
|
|
1416
1448
|
...(warnings.length ? ["Warnings:", ...warnings.map((w) => ` - ${w}`)] : []),
|
|
1417
1449
|
];
|
|
1418
1450
|
}
|
|
1419
|
-
async function defaultRouteAfterActivation(ctx, harness, input) {
|
|
1451
|
+
async function defaultRouteAfterActivation(ctx, harness, input, defaultConfirmed = false) {
|
|
1420
1452
|
const make = boolOption(input, "make-default");
|
|
1421
1453
|
let route;
|
|
1422
1454
|
try {
|
|
@@ -1430,8 +1462,8 @@ async function defaultRouteAfterActivation(ctx, harness, input) {
|
|
|
1430
1462
|
if (route.current?.id === harness.id)
|
|
1431
1463
|
return { data: { default_route: { is_default: true, current } }, lines: [`${named(harness)} is the tenant's default route.`] };
|
|
1432
1464
|
const commands = defaultCommands(harness.slug);
|
|
1433
|
-
const gate = make ? await confirmation(ctx, input, "activate", { harness: harness.id, from: current?.id ?? null }) : undefined;
|
|
1434
|
-
if (gate?.confirmed) {
|
|
1465
|
+
const gate = make && !defaultConfirmed ? await confirmation(ctx, input, "activate", { harness: harness.id, from: current?.id ?? null }) : undefined;
|
|
1466
|
+
if (gate?.confirmed || (make && defaultConfirmed)) {
|
|
1435
1467
|
try {
|
|
1436
1468
|
await setDefaultRoute(ctx, harness.id);
|
|
1437
1469
|
}
|
|
@@ -1456,7 +1488,7 @@ async function defaultRouteAfterActivation(ctx, harness, input) {
|
|
|
1456
1488
|
const confirm = cavelonCommand("activate", "--harness", harness.slug, "--make-default", "--confirm");
|
|
1457
1489
|
return {
|
|
1458
1490
|
data: { default_route: { is_default: false, known: route.known, current, preview: commands.preview, confirm: gate.confirm(confirm), ...gate.fields } },
|
|
1459
|
-
lines: [defaultChangeLine(harness, route), ...(gate.mismatch ? [gate.mismatch] : []), `Show this to a person; with their yes: ${gate.confirm(confirm)}`],
|
|
1491
|
+
lines: [defaultChangeLine(harness, route), gate.where, ...(gate.mismatch ? [gate.mismatch] : []), `Show this to a person; with their yes: ${gate.confirm(confirm)}`],
|
|
1460
1492
|
...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
|
|
1461
1493
|
};
|
|
1462
1494
|
}
|
|
@@ -1466,11 +1498,40 @@ async function defaultRouteAfterActivation(ctx, harness, input) {
|
|
|
1466
1498
|
];
|
|
1467
1499
|
return { data: { default_route: { is_default: false, known: route.known, current, preview: commands.preview, confirm: commands.confirm } }, lines };
|
|
1468
1500
|
}
|
|
1501
|
+
async function reachOf(ctx, harness) {
|
|
1502
|
+
const channels = typeof harness.channel_count === "number" ? harness.channel_count : null;
|
|
1503
|
+
const triggers = await callStable(ctx, "GET", "/api/v1/triggers", "listing triggers", { params: { harness_id: [harness.id] } })
|
|
1504
|
+
.then((list) => list.filter((t) => t.harness_id === harness.id && t.is_active).map((t) => ({ id: t.id, slug: t.slug, name: t.name, type: t.trigger_type })))
|
|
1505
|
+
.catch(() => null);
|
|
1506
|
+
return { channels, triggers };
|
|
1507
|
+
}
|
|
1508
|
+
function reachText(harness, reach) {
|
|
1509
|
+
const parts = [];
|
|
1510
|
+
if (reach.channels)
|
|
1511
|
+
parts.push(`${reach.channels} channel${reach.channels === 1 ? "" : "s"}`);
|
|
1512
|
+
if (reach.triggers?.length)
|
|
1513
|
+
parts.push(`the active trigger${reach.triggers.length === 1 ? "" : "s"} ${reach.triggers.map((t) => `${t.slug} (${t.type})`).join(", ")}`);
|
|
1514
|
+
const unknown = [
|
|
1515
|
+
...(reach.channels === null ? ["whether a channel reaches it (no channel_count)"] : []),
|
|
1516
|
+
...(reach.triggers === null ? ["which triggers start its runs (the trigger list could not be read)"] : []),
|
|
1517
|
+
];
|
|
1518
|
+
const lines = [
|
|
1519
|
+
parts.length
|
|
1520
|
+
? `Activating ${named(harness)} puts it live for what reaches it: ${parts.join("; ")}. From then on it answers them.`
|
|
1521
|
+
: `Activating ${named(harness)} puts it live.`,
|
|
1522
|
+
];
|
|
1523
|
+
if (unknown.length)
|
|
1524
|
+
lines.push(`This instance does not say ${unknown.join(", or ")}, so the activation waits for a confirm.`);
|
|
1525
|
+
return lines.join("\n");
|
|
1526
|
+
}
|
|
1469
1527
|
export const activate = {
|
|
1470
1528
|
name: "activate",
|
|
1471
1529
|
summary: "Activate a solution through the readiness gate (never by force); says whether it is the tenant's default route.",
|
|
1472
1530
|
description: "Only when every readiness check passes, and with a personal access token only when it was created with \"may activate\".\n" +
|
|
1473
1531
|
"Activating without the evidence stays a person's decision in the Admin.\n" +
|
|
1532
|
+
"A solution that a channel or an active trigger reaches goes live for them at once, so its activation previews first\n" +
|
|
1533
|
+
"and only --confirm activates it; so does one on an instance that does not say what reaches it. Show the preview to a\n" +
|
|
1534
|
+
"person and confirm only with their yes. A draft that nothing reaches activates without --confirm.\n" +
|
|
1474
1535
|
"Afterwards it says whether the solution is the tenant's default route (the one the tenant's chat and widget answer with\n" +
|
|
1475
1536
|
"where no solution is named). --make-default previews making it the default; with --confirm as well, it changes it. That\n" +
|
|
1476
1537
|
"changes live traffic: show the preview to a person and confirm only with their yes. `cavelon harness default` does the\n" +
|
|
@@ -1478,26 +1539,35 @@ export const activate = {
|
|
|
1478
1539
|
readOnly: false,
|
|
1479
1540
|
idempotent: true,
|
|
1480
1541
|
mcpTool: "activate",
|
|
1542
|
+
operations: ["POST /api/v1/harnesses/{harness_id}/activate"],
|
|
1481
1543
|
options: {
|
|
1482
1544
|
harness: HARNESS_OPTION,
|
|
1483
1545
|
env: ENV_OPTION,
|
|
1484
1546
|
"make-default": { type: "boolean", description: "Also make it the tenant's default route: previews the change; with --confirm, makes it." },
|
|
1485
|
-
confirm: {
|
|
1547
|
+
confirm: {
|
|
1548
|
+
type: "boolean",
|
|
1549
|
+
mcpToken: true,
|
|
1550
|
+
description: "With --make-default: change the default route; for a solution a channel or trigger reaches: activate it (after a person saw the preview).",
|
|
1551
|
+
},
|
|
1486
1552
|
},
|
|
1487
|
-
examples: [
|
|
1553
|
+
examples: [
|
|
1554
|
+
"cavelon activate",
|
|
1555
|
+
"cavelon activate --confirm",
|
|
1556
|
+
"cavelon activate --make-default",
|
|
1557
|
+
"cavelon activate --make-default --confirm",
|
|
1558
|
+
"cavelon activate --make-default --confirm <token>",
|
|
1559
|
+
],
|
|
1488
1560
|
async run(ctx, input) {
|
|
1489
1561
|
const session = await ctx.session();
|
|
1490
1562
|
const { ref, source } = harnessRef(session, input);
|
|
1491
1563
|
if (!ref)
|
|
1492
1564
|
throw usageError("Which solution?", "Pass --harness <name or slug> (`cavelon harness list` shows them), or set harness in cavelon.yaml or the env file.");
|
|
1493
|
-
|
|
1494
|
-
throw usageError("--confirm only applies to --make-default.", "Activation itself needs no confirmation; the default route does.");
|
|
1495
|
-
}
|
|
1565
|
+
const make = boolOption(input, "make-default");
|
|
1496
1566
|
if (ctx.mode === "mcp" && input.options.confirm === true)
|
|
1497
1567
|
throw confirmTokenRequired("activate");
|
|
1498
1568
|
const driven = drivenByAgent(ctx);
|
|
1499
1569
|
if (driven?.by === "agent" && input.options.confirm === true) {
|
|
1500
|
-
throw shellTokenRequired(cavelonCommand("activate", "--harness", ref, "--make-default"
|
|
1570
|
+
throw shellTokenRequired(cavelonCommand("activate", "--harness", ref, ...(make ? ["--make-default"] : [])));
|
|
1501
1571
|
}
|
|
1502
1572
|
const client = await ctx.client();
|
|
1503
1573
|
const principal = await readPrincipal(client);
|
|
@@ -1549,13 +1619,55 @@ export const activate = {
|
|
|
1549
1619
|
exitCode: ExitCode.validation,
|
|
1550
1620
|
};
|
|
1551
1621
|
}
|
|
1622
|
+
const reach = await reachOf(ctx, harness);
|
|
1623
|
+
const live = Boolean(reach.channels) || Boolean(reach.triggers?.length) || reach.channels === null || reach.triggers === null;
|
|
1624
|
+
let defaultConfirmed = false;
|
|
1625
|
+
if (live) {
|
|
1626
|
+
const route = make ? await readDefaultRoute(ctx).catch(() => undefined) : undefined;
|
|
1627
|
+
const change = {
|
|
1628
|
+
harness: harness.id,
|
|
1629
|
+
activate: true,
|
|
1630
|
+
channels: reach.channels,
|
|
1631
|
+
triggers: reach.triggers?.map((t) => t.id) ?? null,
|
|
1632
|
+
...(make ? { make_default: true, from: route?.current?.id ?? null } : {}),
|
|
1633
|
+
};
|
|
1634
|
+
const gate = await confirmation(ctx, input, "activate", change);
|
|
1635
|
+
if (!gate.confirmed) {
|
|
1636
|
+
const confirm = gate.confirm(cavelonCommand("activate", "--harness", harness.slug, ...(make ? ["--make-default"] : []), "--confirm"));
|
|
1637
|
+
const routeLine = make && route && route.current?.id !== harness.id ? [defaultChangeLine(harness, route)] : [];
|
|
1638
|
+
return {
|
|
1639
|
+
data: {
|
|
1640
|
+
activated: false,
|
|
1641
|
+
would: "activate",
|
|
1642
|
+
harness,
|
|
1643
|
+
reach: { channels: reach.channels, triggers: reach.triggers },
|
|
1644
|
+
checks,
|
|
1645
|
+
warnings,
|
|
1646
|
+
readiness,
|
|
1647
|
+
...(make ? { default_route: { current: route?.current ? { id: route.current.id, slug: route.current.slug, name: route.current.name } : null, known: route?.known ?? false } } : {}),
|
|
1648
|
+
confirm,
|
|
1649
|
+
...gate.fields,
|
|
1650
|
+
},
|
|
1651
|
+
text: [
|
|
1652
|
+
reachText(harness, reach),
|
|
1653
|
+
...routeLine,
|
|
1654
|
+
...readinessText(checks, warnings),
|
|
1655
|
+
gate.where,
|
|
1656
|
+
...(gate.mismatch ? [gate.mismatch] : []),
|
|
1657
|
+
`Nothing was activated. Show this to a person; with their yes: ${confirm}`,
|
|
1658
|
+
].join("\n"),
|
|
1659
|
+
...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
|
|
1660
|
+
};
|
|
1661
|
+
}
|
|
1662
|
+
defaultConfirmed = make;
|
|
1663
|
+
}
|
|
1552
1664
|
const activated = await callStable(ctx, "POST", "/api/v1/harnesses/{harness_id}/activate", "activating solutions", {
|
|
1553
1665
|
params: { harness_id: [harness.id] },
|
|
1554
1666
|
body: { force: false },
|
|
1555
1667
|
});
|
|
1556
|
-
const route = await defaultRouteAfterActivation(ctx, activated, input);
|
|
1668
|
+
const route = await defaultRouteAfterActivation(ctx, activated, input, defaultConfirmed);
|
|
1557
1669
|
return {
|
|
1558
|
-
data: { activated: true, harness: activated, checks, warnings, readiness, ...route.data },
|
|
1670
|
+
data: { activated: true, harness: activated, ...(live ? { reach } : {}), checks, warnings, readiness, ...route.data },
|
|
1559
1671
|
text: [`Activated ${activated.name} (${activated.slug}); status ${activated.status}.`, ...readinessText(checks, warnings), ...route.lines].join("\n"),
|
|
1560
1672
|
...(route.failed ? { exitCode: ExitCode.failure } : route.exitCode ? { exitCode: route.exitCode } : {}),
|
|
1561
1673
|
};
|
package/dist/commands/tenants.js
CHANGED
|
@@ -6,6 +6,7 @@ import { callStable } from "../invoke.js";
|
|
|
6
6
|
import { formatQuota, limitError, limitsOrWarn, readQuotas } from "../limits.js";
|
|
7
7
|
import { containing } from "../choose.js";
|
|
8
8
|
import { readPrincipal, readTenantless } from "../principal.js";
|
|
9
|
+
import { ACTIVATOR, accessFor, mayActivate } from "../access.js";
|
|
9
10
|
import { requireInstance } from "../session.js";
|
|
10
11
|
import { listsTenants, searchTenants } from "../tenant-choice.js";
|
|
11
12
|
import { harnessNotFoundError, lookupHarness, resolveHarnessId } from "../harness-ref.js";
|
|
@@ -76,21 +77,31 @@ async function entersTenant(client, tenantId) {
|
|
|
76
77
|
export const tenantCreate = {
|
|
77
78
|
name: "tenant create",
|
|
78
79
|
tenantless: true,
|
|
79
|
-
summary: "Create a tenant (personal access token in Platform mode with tenants.manage).",
|
|
80
|
+
summary: "Create a tenant (personal access token in Platform mode with tenants.manage); previews first, --confirm creates it.",
|
|
80
81
|
description: "A tenant API key never can. Before sending, the token is checked: one that may not enter Platform mode, or enters it\n" +
|
|
81
|
-
"without tenants.manage, is refused with exit 7 and nothing is sent.
|
|
82
|
-
"
|
|
82
|
+
"without tenants.manage, is refused with exit 7 and nothing is sent. Without --confirm nothing is created: the preview\n" +
|
|
83
|
+
"names the tenant, its plan and the instance it would be created on. A tenant is a platform change, so show the preview\n" +
|
|
84
|
+
"to a person and confirm only with their yes. With --use, the new tenant is chosen only once the instance confirms the\n" +
|
|
85
|
+
"token acts in it. Inviting people and assigning roles stay in the Admin.",
|
|
83
86
|
readOnly: false,
|
|
84
87
|
mcpTool: "tenant_create",
|
|
85
88
|
positionals: [{ name: "slug", description: "Lower-case letters, digits and dashes.", required: true }],
|
|
86
89
|
options: {
|
|
87
90
|
name: { type: "string", value: "<name>", description: "Display name (default: the slug)." },
|
|
88
91
|
plan: { type: "string", value: "<plan>", description: "Licence plan, when the instance knows several." },
|
|
89
|
-
use: {
|
|
92
|
+
use: {
|
|
93
|
+
type: "boolean",
|
|
94
|
+
description: "Switch to the new tenant afterwards (`cavelon use`), once the token is known to act in it.",
|
|
95
|
+
mcpDescription: "Switch to the new tenant afterwards for this MCP session only (as use_tenant does), once the token is known to act in it.",
|
|
96
|
+
},
|
|
90
97
|
"idempotency-key": IDEMPOTENCY_OPTION,
|
|
98
|
+
confirm: { type: "boolean", mcpToken: true, description: "Create the tenant (after a person saw the preview)." },
|
|
91
99
|
},
|
|
100
|
+
examples: ["cavelon tenant create newco --name NewCo", "cavelon tenant create newco --name NewCo --confirm", "cavelon tenant create newco --name NewCo --confirm <token>"],
|
|
92
101
|
async run(ctx, input) {
|
|
93
102
|
const session = await ctx.session();
|
|
103
|
+
if (ctx.mode === "mcp" && input.options.confirm === true)
|
|
104
|
+
throw confirmTokenRequired("tenant_create");
|
|
94
105
|
if (session.tokenKind === "api_key") {
|
|
95
106
|
throw new CavelonError(ExitCode.unauthorized, {
|
|
96
107
|
code: "api_key_cannot_create_tenants",
|
|
@@ -105,6 +116,23 @@ export const tenantCreate = {
|
|
|
105
116
|
const plan = stringOption(input, "plan");
|
|
106
117
|
if (plan)
|
|
107
118
|
body.plan = plan;
|
|
119
|
+
const gate = await confirmation(ctx, input, "tenant_create", body, { platform: "outside" });
|
|
120
|
+
if (!gate.confirmed) {
|
|
121
|
+
const words = ["tenant", "create", slug, "--name", body.name, ...(plan ? ["--plan", plan] : []), ...(boolOption(input, "use") ? ["--use"] : [])];
|
|
122
|
+
const key = stringOption(input, "idempotency-key");
|
|
123
|
+
if (key)
|
|
124
|
+
words.push("--idempotency-key", key);
|
|
125
|
+
const confirm = gate.confirm(cavelonCommand(...words, "--confirm"));
|
|
126
|
+
return {
|
|
127
|
+
data: { created: false, would: "create_tenant", tenant: { slug, name: body.name, plan: plan ?? null }, confirm, ...gate.fields },
|
|
128
|
+
text: [
|
|
129
|
+
`Creating tenant ${body.name} (${slug})${plan ? ` on plan ${plan}` : ""} adds a tenant to the platform: it holds its own solutions, people, limits and budget.`,
|
|
130
|
+
gate.where, ...(gate.mismatch ? [gate.mismatch] : []),
|
|
131
|
+
`Nothing was created. Show this to a person; with their yes: ${confirm}`,
|
|
132
|
+
].join("\n"),
|
|
133
|
+
...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
108
136
|
const tenant = await callStable(ctx, "POST", "/api/v1/tenants", "creating tenants", {
|
|
109
137
|
body,
|
|
110
138
|
sendTenant: false,
|
|
@@ -120,8 +148,11 @@ export const tenantCreate = {
|
|
|
120
148
|
`\`${cavelonCommand("use", tenant.slug)}\`.`);
|
|
121
149
|
return { data: { ...tenant, used: false }, text: `${created} Not switched: this token does not act in it.` };
|
|
122
150
|
}
|
|
123
|
-
await rememberTenant(ctx, requireInstance(session), { ref: tenant.slug, id: tenant.id, name: tenant.name });
|
|
124
|
-
return {
|
|
151
|
+
const scope = await rememberTenant(ctx, requireInstance(session), { ref: tenant.slug, id: tenant.id, name: tenant.name, slug: tenant.slug });
|
|
152
|
+
return {
|
|
153
|
+
data: { ...tenant, used: true, ...(scope === "session" ? { used_in: "session" } : {}) },
|
|
154
|
+
text: scope === "session" ? `${created} Now using it in this MCP session; the tenant stored for your user is unchanged.` : `${created} Now using it.`,
|
|
155
|
+
};
|
|
125
156
|
},
|
|
126
157
|
};
|
|
127
158
|
export const tenantList = {
|
|
@@ -242,6 +273,7 @@ export const harnessDefault = {
|
|
|
242
273
|
readOnly: false,
|
|
243
274
|
idempotent: true,
|
|
244
275
|
mcpTool: "harness_default",
|
|
276
|
+
operations: ["POST /api/v1/harnesses/{harness_id}/default"],
|
|
245
277
|
positionals: [{ name: "solution", description: "Name, slug or id of the solution; default: cavelon.yaml's harness." }],
|
|
246
278
|
options: {
|
|
247
279
|
confirm: { type: "boolean", mcpToken: true, description: "Change the default route (after a person saw the preview)." },
|
|
@@ -268,7 +300,9 @@ export const harnessDefault = {
|
|
|
268
300
|
throw new CavelonError(ExitCode.conflict, {
|
|
269
301
|
code: "solution_not_active",
|
|
270
302
|
message: `${named(harness)} is ${harness.status}, and only an active solution can be the tenant's default route; nothing was changed.`,
|
|
271
|
-
hint:
|
|
303
|
+
hint: (mayActivate(await accessFor(await ctx.client())) === false
|
|
304
|
+
? `Only an active solution can be the default, and to activate it ${ACTIVATOR}. `
|
|
305
|
+
: `Activate it through the readiness gate and preview the default route in one step: ${cavelonCommand("activate", "--harness", harness.slug, "--make-default")}. `) +
|
|
272
306
|
`The default route stays ${current ? named(current) : "as it is"} until then.`,
|
|
273
307
|
details: { harness: target, default_route: current },
|
|
274
308
|
});
|
|
@@ -286,7 +320,7 @@ export const harnessDefault = {
|
|
|
286
320
|
},
|
|
287
321
|
text: [
|
|
288
322
|
defaultChangeLine(harness, route),
|
|
289
|
-
...(gate.mismatch ? [gate.mismatch] : []),
|
|
323
|
+
gate.where, ...(gate.mismatch ? [gate.mismatch] : []),
|
|
290
324
|
`Show this to a person; with their yes: ${gate.confirm(commands.confirm)}`,
|
|
291
325
|
].join("\n"),
|
|
292
326
|
...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
|
|
@@ -347,6 +381,7 @@ export const harnessNew = {
|
|
|
347
381
|
summary: "Create an empty draft solution (harness).",
|
|
348
382
|
readOnly: false,
|
|
349
383
|
mcpTool: "harness_new",
|
|
384
|
+
operations: ["POST /api/v1/harnesses"],
|
|
350
385
|
positionals: [{ name: "slug", description: "The new solution's slug.", required: true }],
|
|
351
386
|
options: {
|
|
352
387
|
name: { type: "string", value: "<name>", description: "Display name (default: the slug)." },
|
|
@@ -375,6 +410,7 @@ export const harnessClone = {
|
|
|
375
410
|
summary: "Copy a solution into a new draft solution.",
|
|
376
411
|
readOnly: false,
|
|
377
412
|
mcpTool: "harness_clone",
|
|
413
|
+
operations: ["POST /api/v1/harnesses/{harness_id}/clone"],
|
|
378
414
|
positionals: [{ name: "source", description: "Name, slug or id of the solution to copy.", required: true }],
|
|
379
415
|
options: {
|
|
380
416
|
slug: { type: "string", value: "<slug>", description: "The copy's slug." },
|