@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/README.md
CHANGED
|
@@ -68,7 +68,8 @@ deletes it. The coding agent never sees the token: it calls `cavelon`, and
|
|
|
68
68
|
|
|
69
69
|
`login` reads the instance's capabilities and warns when its contract versions
|
|
70
70
|
are newer than this `cavelon` understands. It also caches the OpenAPI and the
|
|
71
|
-
error catalog under `~/.cache/cavelon/<instance>/<version
|
|
71
|
+
error catalog under `~/.cache/cavelon/<instance>/<version>/`, which only you
|
|
72
|
+
can read.
|
|
72
73
|
|
|
73
74
|
### CI, scripts and cloud agents
|
|
74
75
|
|
|
@@ -118,12 +119,12 @@ Every command takes `--json` (one JSON document on stdout, errors included),
|
|
|
118
119
|
| `limits set <key> <value> [--confirm]` | changing (destructive) | Change a limit through the operation the instance names: a tenant admin's, a quota of the Tenant Owner's (inference budget, Processing Step cap), or an operator's run cap with a Platform-mode token; without `--confirm`, shows the old and new value. |
|
|
119
120
|
| `models list` | read-only | The tenant's Model Registry rows with their endpoint and `max_concurrent_requests`; never a key. |
|
|
120
121
|
| `models set-limit <model> <n\|none> [--confirm]` | changing (destructive) | Set or clear a row's `max_concurrent_requests`; without `--confirm`, shows the old and new value. |
|
|
121
|
-
| `tenant create <slug> [--name] [--use]` | changing | Create a tenant (personal token in Platform mode with `tenants.manage`); refused before sending when the token cannot. |
|
|
122
|
+
| `tenant create <slug> [--name] [--use] [--confirm]` | changing | Create a tenant (personal token in Platform mode with `tenants.manage`); refused before sending when the token cannot; without `--confirm`, shows the tenant it would create. |
|
|
122
123
|
| `tenant list [--search]` | read-only | Tenants the token can see, with name, slug, role and id. |
|
|
123
124
|
| `harness list [--readiness]` | read-only | The tenant's solutions, with slug, name, status and id. |
|
|
124
125
|
| `harness new <slug> [--name] [--description]` | changing | Create an empty draft solution. |
|
|
125
126
|
| `harness clone <source> [--slug] [--name] [--no-tests] [--no-triggers]` | changing | Copy a solution into a new draft. |
|
|
126
|
-
| `activate [--harness] [--env]` | changing | Activate through the readiness gate only, never by force. |
|
|
127
|
+
| `activate [--harness] [--env] [--make-default] [--confirm [<token>]]` | changing | Activate through the readiness gate only, never by force; a solution a channel or trigger reaches previews first. |
|
|
127
128
|
| `chat <message> [--harness] [--env] [--session <id>] [--timeout 90s]` | changing | Send one message to a solution and print its answer, with the session to continue and the conversation to trace; tries a draft or an active solution that is not the default route. |
|
|
128
129
|
| `deactivate [--harness] [--env] [--confirm [<token>]]` | changing (destructive) | Take an active solution out of live traffic: its status becomes `inactive` (not `draft`); previews first. |
|
|
129
130
|
| `init [--harness [--new]] [--agents <list>] [--hook] [--update] [--from <file> [--force]]` | changing (files) | Make this folder a solution: `cavelon.yaml`, `package/`, `tests/`, `env/`, `.cavelon/`; on a terminal it asks for the tenant and the solution (or a new one by name); a name close to an existing solution's is refused unless `--new`; `--from` writes a package file into it. |
|
|
@@ -134,7 +135,7 @@ Every command takes `--json` (one JSON document on stdout, errors included),
|
|
|
134
135
|
| `apply --confirm <preview-id>` | changing | Import exactly that preview; a stale one, or one the import's own check refuses (it names the blockers), exits 4. |
|
|
135
136
|
| `explain <code>` | read-only | Look a code up in the instance's error catalog. |
|
|
136
137
|
| `variables list` / `variables get <name>` | read-only | The tenant's plain-text variables (`{{var:…}}`) with their values. |
|
|
137
|
-
| `variables set <name> <value> [--stdin]` | changing | Create or replace a variable. Never a credential. |
|
|
138
|
+
| `variables set <name> <value> [--stdin] [--confirm]` | changing | Create or replace a variable. Never a credential. Replacing another value needs `--confirm`; without it, shows the old and new value. |
|
|
138
139
|
| `variables delete <name> [--confirm]` | changing (destructive) | Delete a variable; without `--confirm`, shows it. |
|
|
139
140
|
| `secrets list [--missing]` | read-only | The tenant's secret names (`{{secret:…}}`): set or not, declared, changed when. Never a value. |
|
|
140
141
|
| `secrets set <name>` | changing | Set a secret's value from the terminal or stdin. A person runs this. |
|
|
@@ -148,8 +149,11 @@ Every command takes `--json` (one JSON document on stdout, errors included),
|
|
|
148
149
|
| `watch <operation> [--timeout 10m]` | read-only | Stream an operation's changes (server-sent events). |
|
|
149
150
|
| `kb upload <dir> --kb <kb> [-r] [--ext pdf] [--replace] [--dry-run] [--wait]` | changing | Upload documents; returns operation ids. Names files that match an active document; `--replace` replaces those. `--dry-run` also names files identical to an active document. |
|
|
150
151
|
| `test run [--suite <s>] [--harness <h>] [--wait]` | changing | Start test-suite runs; returns operation ids. |
|
|
151
|
-
| `trace <run> [--trace <id>] [--span <id>]` | read-only | Summarise a run's traces (or a test run's results, with why a case did not pass), then one trace's spans, then one span. |
|
|
152
|
-
| `
|
|
152
|
+
| `trace <run> [--trace <id>] [--span <id>]` | read-only | Summarise a run's traces (or a test run's results, with why a case did not pass), then one trace's spans, then one span. A database query call that failed shows its code. |
|
|
153
|
+
| `db connections` / `db queries [<query>] [--connection]` / `db runs <query>` | read-only | The tenant's database connections, saved queries (one in full with its SQL and parameters) and a query's runs (no values, no rows). |
|
|
154
|
+
| `db test <connection>` | changing | The tenant Owner tests a connection step by step; exit 3 when a step fails. |
|
|
155
|
+
| `db test-run <query> [--value name=value…]` | changing | The tenant Owner runs a saved query once, identity parameters included, and sees what the model would; exit 3 when it fails. |
|
|
156
|
+
| `loop start <trigger> [--input <json>] [--wait] [--confirm]` | changing | Start a loop through its trigger, as you; without `--confirm`, shows the trigger, its solution and the payload; with it, returns the run and operation ids. |
|
|
153
157
|
| `loop cancel <run> [--confirm]` | changing (destructive) | Stop a trigger run and its loops; without `--confirm`, shows what would stop. |
|
|
154
158
|
| `loop watch <run> [--loop] [--timeout 10m]` | read-only | One line per decided iteration and per state change, then the loop's outcome; returns when it ends or pauses. |
|
|
155
159
|
| `loop iterations <run> [--loop] [--limit] [--cursor]` | read-only | A loop's state, budget and iterations. |
|
|
@@ -385,6 +389,9 @@ op read op://dev/crm/token | cavelon secrets set crm_api_token
|
|
|
385
389
|
- A **variable** is plain text: anyone who may view the tenant's settings
|
|
386
390
|
reads it, and the agent may set it (MCP: `variables_list`, `variables_get`,
|
|
387
391
|
`variables_set`). `variables set` refuses a value that looks like a token.
|
|
392
|
+
A new variable is set at once; replacing another value shows the old and
|
|
393
|
+
the new one and changes it only with `--confirm`, because every solution of
|
|
394
|
+
the tenant reads it.
|
|
388
395
|
- A **secret's** value is never an argument, never printed, never written to a
|
|
389
396
|
file and never read back. `secrets set` reads it from the terminal without
|
|
390
397
|
echo, or from standard input when that is piped (one trailing line break is
|
|
@@ -491,14 +498,17 @@ cavelon sandbox seed orders-test seeds/orders # shows what it would s
|
|
|
491
498
|
cavelon sandbox seed orders-test seeds/orders --confirm # the archive becomes the workspace
|
|
492
499
|
cavelon trigger identity orders loop-runner # shows the change
|
|
493
500
|
cavelon trigger identity orders loop-runner --confirm # binds the API key
|
|
494
|
-
cavelon loop start orders --input @request.json
|
|
501
|
+
cavelon loop start orders --input @request.json # shows what it would start
|
|
502
|
+
cavelon loop start orders --input @request.json --confirm # starts the run
|
|
495
503
|
cavelon loop watch <run>
|
|
496
504
|
cavelon sandbox cat orders-test output/summary.json
|
|
497
505
|
cavelon artifacts export orders-test --path output --wait --out results.tar
|
|
498
506
|
```
|
|
499
507
|
|
|
500
508
|
- **`loop start`** calls the trigger's run-now route; the run acts as you (with
|
|
501
|
-
a personal access token, the person)
|
|
509
|
+
a personal access token, the person) and spends the tenant's budget, so it
|
|
510
|
+
first shows the trigger, its solution and the payload, and starts only with
|
|
511
|
+
`--confirm`. It returns the run id and the run's
|
|
502
512
|
operation id, so `wait` and `watch` follow it (and `trace <operation>` reads
|
|
503
513
|
the run's traces); a paused loop makes `wait` exit 5. It sends an
|
|
504
514
|
`Idempotency-Key` (`--idempotency-key`, a new UUID by default; `--json`:
|
|
@@ -691,7 +701,10 @@ cavelon activate --harness support
|
|
|
691
701
|
- **`activate`** reads the readiness gate and activates only when it passes,
|
|
692
702
|
never with `force`. A personal access token without "may activate" is refused
|
|
693
703
|
before anything is sent (exit 7); a solution that is not ready exits 3 with its
|
|
694
|
-
blockers.
|
|
704
|
+
blockers. A solution a channel or an active trigger reaches (the solution's
|
|
705
|
+
`channel_count`, the active triggers bound to it) goes live for them at once,
|
|
706
|
+
so there it previews and activates only with `--confirm`; so it does where the
|
|
707
|
+
instance does not say what reaches a solution.
|
|
695
708
|
- **A Masterloop parent and its iteration solution** activate without the
|
|
696
709
|
override in one order: apply the iteration, apply the parent, run the
|
|
697
710
|
parent's loop suite, activate the iteration, activate the parent.
|
|
@@ -779,7 +792,7 @@ an agent only with a new plugin or `init --update`. With `cavelon` installed,
|
|
|
779
792
|
| `~/.config/cavelon/config.json` | the current instance, the tenant chosen with `use`, which store holds the token. Never a token. |
|
|
780
793
|
| `~/.config/cavelon/credentials.json` | the token per instance (0600), only where there is no OS credential store |
|
|
781
794
|
| `~/.config/cavelon/setup.json` | what `cavelon setup` changed in your coding agents, so `setup --remove` undoes exactly that (0600) |
|
|
782
|
-
| `~/.cache/cavelon/<instance>/<version>/` | the instance's
|
|
795
|
+
| `~/.cache/cavelon/<instance>/<version>/` | the instance's OpenAPI, error catalog and package schema, its capabilities once per tenant (they carry the tenant's limits) and its docs index once per token and tenant; files 0600, folders 0700 |
|
|
783
796
|
| `~/.cache/cavelon/update-check.json` | when the latest release was last looked up and announced; `CAVELON_NO_UPDATE_CHECK=1` turns the check off |
|
|
784
797
|
|
|
785
798
|
`CAVELON_CONFIG_DIR` and `CAVELON_CACHE_DIR` move them; `XDG_CONFIG_HOME` and
|
package/dist/access.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { readPrincipal } from "./principal.js";
|
|
2
|
+
import { cavelonCommand } from "./printed.js";
|
|
3
|
+
export const ACTIVATE_PERMISSION = "harnesses.activate";
|
|
4
|
+
const SETTINGS_VALUES = ["settings.secrets.manage", "settings.manage"];
|
|
5
|
+
export const OPERATION_PERMISSIONS = {
|
|
6
|
+
"POST /api/v1/agent-graph/import": ["agents.edit"],
|
|
7
|
+
"POST /api/v1/harnesses": ["harnesses.manage"],
|
|
8
|
+
"POST /api/v1/harnesses/{harness_id}/activate": ["harnesses.manage", ACTIVATE_PERMISSION],
|
|
9
|
+
"POST /api/v1/harnesses/{harness_id}/clone": ["harnesses.manage"],
|
|
10
|
+
"POST /api/v1/harnesses/{harness_id}/deactivate": ["harnesses.manage"],
|
|
11
|
+
"POST /api/v1/harnesses/{harness_id}/default": ["harnesses.manage"],
|
|
12
|
+
"POST /api/v1/knowledge-bases/{kb_id}/documents/upload": ["knowledge_bases.manage_documents"],
|
|
13
|
+
"PATCH /api/v1/knowledge-bases/{kb_id}/documents/active": ["knowledge_bases.manage_documents"],
|
|
14
|
+
"PATCH /api/v1/model-registry/{model_registry_id}": ["agents.manage_llm_config"],
|
|
15
|
+
"POST /api/v1/test-suites/{suite_id}/runs": ["playground.use"],
|
|
16
|
+
"POST /api/v1/triggers/{trigger_id}/run": ["triggers.manage"],
|
|
17
|
+
"PUT /api/v1/triggers/{trigger_id}/execution-identity": ["settings.manage", "triggers.manage"],
|
|
18
|
+
"POST /api/v1/triggers/runs/{run_id}/cancel": ["triggers.manage"],
|
|
19
|
+
"POST /api/v1/triggers/runs/{run_id}/loops/{loop_id}/pause": ["triggers.manage"],
|
|
20
|
+
"POST /api/v1/triggers/runs/{run_id}/loops/{loop_id}/resume": ["triggers.manage"],
|
|
21
|
+
"POST /api/v1/sandboxes/{sandbox_id}/artifact-jobs": ["sandboxes.write"],
|
|
22
|
+
"POST /api/v1/sandboxes/{sandbox_id}/refresh-workspace": ["sandboxes.manage"],
|
|
23
|
+
"POST /api/v1/sandboxes/{sandbox_id}/validate": ["sandboxes.manage"],
|
|
24
|
+
"POST /api/v1/database-connectors/connections/{connection_id}/test": [["database_connectors.test", "database_connectors.manage"]],
|
|
25
|
+
"POST /api/v1/database-connectors/queries/{query_id}/test-run": [["database_connectors.test", "database_connectors.manage"]],
|
|
26
|
+
"PUT /api/v1/variables/{name}": [SETTINGS_VALUES],
|
|
27
|
+
"DELETE /api/v1/variables/{name}": [SETTINGS_VALUES],
|
|
28
|
+
"PUT /api/v1/secrets/{name}": [SETTINGS_VALUES],
|
|
29
|
+
"DELETE /api/v1/secrets/{name}": [SETTINGS_VALUES],
|
|
30
|
+
};
|
|
31
|
+
function needWords(need) {
|
|
32
|
+
return typeof need === "string" ? need : anyOf(need);
|
|
33
|
+
}
|
|
34
|
+
export function accessOf(principal) {
|
|
35
|
+
if (!principal)
|
|
36
|
+
return undefined;
|
|
37
|
+
const complete = Array.isArray(principal.needs_a_person);
|
|
38
|
+
const acting = principal.mode === "tenant" || principal.mode === "platform";
|
|
39
|
+
let permissions = null;
|
|
40
|
+
if (principal.permissions && acting && (complete || principal.kind !== "api_key")) {
|
|
41
|
+
permissions = [...principal.permissions];
|
|
42
|
+
if (!complete && principal.token?.may_activate && permissions.includes("harnesses.manage") && !permissions.includes(ACTIVATE_PERMISSION)) {
|
|
43
|
+
permissions.push(ACTIVATE_PERMISSION);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
kind: principal.kind,
|
|
48
|
+
permissions,
|
|
49
|
+
complete,
|
|
50
|
+
scopes: principal.api_key ? [...principal.api_key.scopes] : null,
|
|
51
|
+
needsAPerson: principal.needs_a_person ?? [],
|
|
52
|
+
principal,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const principals = new WeakMap();
|
|
56
|
+
export function principalOf(client) {
|
|
57
|
+
let read = principals.get(client);
|
|
58
|
+
if (!read) {
|
|
59
|
+
read = readPrincipal(client).catch(() => undefined);
|
|
60
|
+
principals.set(client, read);
|
|
61
|
+
}
|
|
62
|
+
return read;
|
|
63
|
+
}
|
|
64
|
+
export async function accessFor(client) {
|
|
65
|
+
return accessOf(await principalOf(client));
|
|
66
|
+
}
|
|
67
|
+
export function pathMatches(template, path) {
|
|
68
|
+
const want = template.split("/");
|
|
69
|
+
const got = path.split("?")[0].split("/");
|
|
70
|
+
if (want.length !== got.length)
|
|
71
|
+
return false;
|
|
72
|
+
return want.every((part, i) => (part.startsWith("{") && part.endsWith("}") ? got[i] !== "" : part === got[i]));
|
|
73
|
+
}
|
|
74
|
+
export function knownOperation(method, path) {
|
|
75
|
+
const verb = method.toUpperCase();
|
|
76
|
+
return Object.keys(OPERATION_PERMISSIONS).find((key) => {
|
|
77
|
+
const [m, template] = key.split(" ");
|
|
78
|
+
return m === verb && pathMatches(template, path);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
export function operationAccess(access, operation) {
|
|
82
|
+
if (!access)
|
|
83
|
+
return { allowed: null };
|
|
84
|
+
const [method, template] = operation.split(" ");
|
|
85
|
+
const person = access.needsAPerson.find((o) => o.method === method && (o.path === template || pathMatches(o.path, template)));
|
|
86
|
+
if (person)
|
|
87
|
+
return { allowed: false, person: person.reason || "a person runs it" };
|
|
88
|
+
const needs = OPERATION_PERMISSIONS[operation];
|
|
89
|
+
if (!needs || !access.permissions)
|
|
90
|
+
return { allowed: null };
|
|
91
|
+
const held = (need) => (typeof need === "string" ? [need] : need).some((p) => access.permissions.includes(p));
|
|
92
|
+
const missing = needs.filter((need) => !held(need));
|
|
93
|
+
return missing.length ? { allowed: false, missing: missing.map(needWords) } : { allowed: true };
|
|
94
|
+
}
|
|
95
|
+
export function mayActivate(access) {
|
|
96
|
+
if (!access)
|
|
97
|
+
return null;
|
|
98
|
+
const known = operationAccess(access, "POST /api/v1/harnesses/{harness_id}/activate").allowed;
|
|
99
|
+
if (known !== null)
|
|
100
|
+
return known;
|
|
101
|
+
return access.principal.token ? access.principal.token.may_activate : null;
|
|
102
|
+
}
|
|
103
|
+
export function anyOf(permissions) {
|
|
104
|
+
if (permissions.length <= 1)
|
|
105
|
+
return permissions[0] ?? "a permission";
|
|
106
|
+
return `${permissions.slice(0, -1).join(", ")} or ${permissions.at(-1)}`;
|
|
107
|
+
}
|
|
108
|
+
export function allOf(needs) {
|
|
109
|
+
if (needs.length <= 1)
|
|
110
|
+
return needs[0] ?? "a permission";
|
|
111
|
+
return `${needs.slice(0, -1).join(", ")} and ${needs.at(-1)}`;
|
|
112
|
+
}
|
|
113
|
+
export function credentialWords(access) {
|
|
114
|
+
if (!access)
|
|
115
|
+
return "this credential";
|
|
116
|
+
if (access.kind === "api_key")
|
|
117
|
+
return access.principal.api_key ? `the API key "${access.principal.api_key.name}"` : "this API key";
|
|
118
|
+
return access.principal.token ? `the token "${access.principal.token.name}"` : "this session";
|
|
119
|
+
}
|
|
120
|
+
export function whoInstead(access, refused) {
|
|
121
|
+
if (refused.person)
|
|
122
|
+
return `A person does it, in the Admin or with their own token: the instance says ${JSON.stringify(refused.person)}.`;
|
|
123
|
+
const needs = allOf(refused.missing ?? []);
|
|
124
|
+
if (access?.kind === "api_key") {
|
|
125
|
+
return `An API key's scopes grant its permissions, and this one's (${access.scopes?.join(", ") || "none"}) hold no ${needs}: a person with ${needs} does it, or a tenant administrator issues a key that may.`;
|
|
126
|
+
}
|
|
127
|
+
const ceiling = access?.principal.token?.ceiling_role;
|
|
128
|
+
return `A person whose role holds ${needs} does it, in the Admin or with their own token${ceiling ? ` (this token acts at most as ${ceiling})` : ""}.`;
|
|
129
|
+
}
|
|
130
|
+
export function permissionsNamed(message) {
|
|
131
|
+
const at = /permissions?:\s*([\w.]+(?:\s*,\s*[\w.]+)*)/i.exec(message);
|
|
132
|
+
return at ? at[1].split(",").map((p) => p.trim()).filter(Boolean) : [];
|
|
133
|
+
}
|
|
134
|
+
export function scopeNamed(message) {
|
|
135
|
+
return /missing required scope:\s*([\w.]+)/i.exec(message)?.[1];
|
|
136
|
+
}
|
|
137
|
+
export function forbiddenHint(message, refused) {
|
|
138
|
+
const { access } = refused;
|
|
139
|
+
const kind = access?.kind ?? refused.kind;
|
|
140
|
+
const whoami = `\`${cavelonCommand("whoami")}\` shows what it may do.`;
|
|
141
|
+
const person = access?.needsAPerson.find((o) => o.method === refused.method.toUpperCase() && pathMatches(o.path, refused.path));
|
|
142
|
+
if (person) {
|
|
143
|
+
return {
|
|
144
|
+
hint: `A person does this, not a token or an API key${person.reason ? ` (the instance says: ${person.reason})` : ""}: in the Admin, or as a session of their own.`,
|
|
145
|
+
details: { credential: kind ?? null, needs_a_person: true, reason: person.reason || null },
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
const named = permissionsNamed(message);
|
|
149
|
+
const scope = scopeNamed(message);
|
|
150
|
+
let lacks;
|
|
151
|
+
let needs;
|
|
152
|
+
let permissions = named;
|
|
153
|
+
if (named.length)
|
|
154
|
+
lacks = /one of permissions/i.test(message) ? anyOf(named) : allOf(named);
|
|
155
|
+
else if (!scope) {
|
|
156
|
+
const operation = knownOperation(refused.method, refused.path);
|
|
157
|
+
const known = operation ? operationAccess(access, operation) : undefined;
|
|
158
|
+
if (known?.missing)
|
|
159
|
+
lacks = allOf((permissions = known.missing));
|
|
160
|
+
else if (operation && known?.allowed !== true)
|
|
161
|
+
needs = allOf((permissions = OPERATION_PERMISSIONS[operation].map(needWords)));
|
|
162
|
+
else
|
|
163
|
+
permissions = [];
|
|
164
|
+
}
|
|
165
|
+
const details = { credential: kind ?? null, ...(permissions.length ? { permissions } : {}), ...(scope ? { scope } : {}) };
|
|
166
|
+
if (kind === "api_key") {
|
|
167
|
+
const scopes = access?.scopes;
|
|
168
|
+
const held = scopes ? ` Its scopes: ${scopes.join(", ") || "none"}.` : "";
|
|
169
|
+
const what = scope ? `lacks the scope ${scope}` : lacks ? `lacks a scope that grants ${lacks}` : needs ? `may lack a scope that grants ${needs}` : "lacks a scope that allows this, or is limited to other solutions";
|
|
170
|
+
return {
|
|
171
|
+
hint: `An API key acts only with what its scopes grant, and this one ${what}.${held} A tenant administrator issues a key that may (Settings → API keys), or a person does this with their own token. ${whoami}`,
|
|
172
|
+
details,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const token = access?.principal.token;
|
|
176
|
+
if (token && !token.may_activate && (lacks ?? needs)?.includes(ACTIVATE_PERMISSION)) {
|
|
177
|
+
return {
|
|
178
|
+
hint: `The token was created without "may activate". A person activates in the Admin, or creates a token with "may activate" on /account/access-tokens. ${whoami}`,
|
|
179
|
+
details,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
const capped = token?.ceiling_role ? ` A token acts with the lesser of its owner's role and its ceiling (${token.ceiling_role}).` : " A token acts at most with its ceiling role.";
|
|
183
|
+
if (lacks || needs) {
|
|
184
|
+
return {
|
|
185
|
+
hint: `${lacks ? `This token's role in the tenant lacks ${lacks}.` : `This needs ${needs}.`}${capped} A person whose role holds it does this, in the Admin or with their own token. ${whoami}`,
|
|
186
|
+
details,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
return { hint: `The token does not reach this. Check the tenant and the token's role.${capped} ${whoami}`, details };
|
|
190
|
+
}
|
|
191
|
+
export const ACTIVATOR = "a person who may activate does it, in the Admin (this credential may not)";
|
|
192
|
+
export function activationStep(may, command) {
|
|
193
|
+
return may === false ? ACTIVATOR : `\`${command}\``;
|
|
194
|
+
}
|
package/dist/acting.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { CavelonError, ExitCode } from "./errors.js";
|
|
2
|
+
import { readPrincipal, readTenantless } from "./principal.js";
|
|
3
|
+
import { isUuid } from "./session.js";
|
|
4
|
+
import { describeTenant, tenantTitle } from "./tenant-choice.js";
|
|
5
|
+
export function sourceName(source) {
|
|
6
|
+
switch (source) {
|
|
7
|
+
case "option":
|
|
8
|
+
return "--tenant";
|
|
9
|
+
case "use":
|
|
10
|
+
return "`cavelon use`";
|
|
11
|
+
case "session":
|
|
12
|
+
return "use_tenant in this MCP session";
|
|
13
|
+
default:
|
|
14
|
+
return source ?? "nowhere";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const targets = new WeakMap();
|
|
18
|
+
export function actingTarget(ctx, options = {}) {
|
|
19
|
+
const platform = options.platform ?? "";
|
|
20
|
+
let read = targets.get(ctx);
|
|
21
|
+
if (!read)
|
|
22
|
+
targets.set(ctx, (read = new Map()));
|
|
23
|
+
let target = read.get(platform);
|
|
24
|
+
if (!target) {
|
|
25
|
+
target = readTarget(ctx, platform);
|
|
26
|
+
read.set(platform, target);
|
|
27
|
+
}
|
|
28
|
+
return target;
|
|
29
|
+
}
|
|
30
|
+
async function readTarget(ctx, platform) {
|
|
31
|
+
const session = await ctx.session();
|
|
32
|
+
const client = await ctx.client();
|
|
33
|
+
const from = ctx.mode === "mcp" && session.tenantSource === "option" ? "the tenant argument" : sourceName(session.tenantSource);
|
|
34
|
+
const base = { instance: client.url, credential: session.tokenKind ?? null, tenant_from: session.tenant ? from : null };
|
|
35
|
+
const named = async (id) => ({ id, ...(await tenantNames(session, client, id)) });
|
|
36
|
+
if (platform === "outside")
|
|
37
|
+
return { ...base, tenant: null, tenant_from: null, mode: "platform" };
|
|
38
|
+
if (platform === "tenant")
|
|
39
|
+
return { ...base, tenant: client.target.tenantId ? await named(client.target.tenantId) : null, mode: "platform" };
|
|
40
|
+
if (client.target.tenantId)
|
|
41
|
+
return { ...base, tenant: await named(client.target.tenantId), mode: "tenant" };
|
|
42
|
+
if (session.tokenKind === "api_key") {
|
|
43
|
+
const principal = await readPrincipal(client).catch(() => undefined);
|
|
44
|
+
return { ...base, tenant: principal?.tenant_id ? await named(principal.tenant_id) : null, mode: "tenant" };
|
|
45
|
+
}
|
|
46
|
+
const tenantless = await readTenantless(client).catch(() => undefined);
|
|
47
|
+
if (!tenantless)
|
|
48
|
+
return { ...base, tenant: null, mode: "unknown" };
|
|
49
|
+
if (tenantless.refused)
|
|
50
|
+
return { ...base, tenant: null, mode: "none" };
|
|
51
|
+
if (tenantless.platform)
|
|
52
|
+
return { ...base, tenant: null, mode: "platform" };
|
|
53
|
+
if (!tenantless.tenantId)
|
|
54
|
+
return { ...base, tenant: null, mode: "none" };
|
|
55
|
+
const listed = tenantless.tenants?.find((t) => t.id === tenantless.tenantId);
|
|
56
|
+
const tenant = listed ? { id: listed.id, name: listed.name, slug: listed.slug } : await named(tenantless.tenantId);
|
|
57
|
+
return { ...base, tenant, mode: "tenant", tenant_from: "the token's default tenant" };
|
|
58
|
+
}
|
|
59
|
+
async function tenantNames(session, client, id) {
|
|
60
|
+
const chosen = session.sessionTenant?.id === id ? session.sessionTenant : undefined;
|
|
61
|
+
const stored = session.settings.tenant_id === id ? session.settings : undefined;
|
|
62
|
+
let name = chosen?.name ?? stored?.tenant_name ?? null;
|
|
63
|
+
let slug = chosen?.slug ?? stored?.tenant_slug ?? null;
|
|
64
|
+
if (!name || !slug) {
|
|
65
|
+
const described = await describeTenant(client, id);
|
|
66
|
+
name ??= described.name ?? null;
|
|
67
|
+
slug ??= described.slug ?? null;
|
|
68
|
+
}
|
|
69
|
+
return { name, slug };
|
|
70
|
+
}
|
|
71
|
+
export function targetText(target) {
|
|
72
|
+
const where = target.mode === "platform"
|
|
73
|
+
? target.tenant
|
|
74
|
+
? `Platform mode, for tenant ${tenantTitle(target.tenant)}${target.tenant_from ? ` from ${target.tenant_from}` : ""}`
|
|
75
|
+
: "Platform mode, outside any tenant"
|
|
76
|
+
: target.mode === "none"
|
|
77
|
+
? "no tenant (none is chosen, and the instance places this token in none)"
|
|
78
|
+
: target.tenant
|
|
79
|
+
? `tenant ${tenantTitle(target.tenant)}${target.tenant_from ? ` from ${target.tenant_from}` : ""}, tenant mode`
|
|
80
|
+
: target.mode === "tenant"
|
|
81
|
+
? "the API key's own tenant (the instance does not say which), tenant mode"
|
|
82
|
+
: "a tenant the instance does not name (it is too old to say where the token acts)";
|
|
83
|
+
return `${target.instance}, ${where}`;
|
|
84
|
+
}
|
|
85
|
+
export function targetLine(target) {
|
|
86
|
+
return `acts on: ${targetText(target)}`;
|
|
87
|
+
}
|
|
88
|
+
export async function checkKeyTenant(client, session, warn) {
|
|
89
|
+
const ref = session.tenant;
|
|
90
|
+
if (!ref || session.tenantSource === "use" || session.tenantSource === "session")
|
|
91
|
+
return undefined;
|
|
92
|
+
const from = sourceName(session.tenantSource);
|
|
93
|
+
const principal = await readPrincipal(client);
|
|
94
|
+
const own = principal?.tenant_id ?? undefined;
|
|
95
|
+
if (!own) {
|
|
96
|
+
warn(`The tenant API key acts in its own tenant, and this instance does not say which, so the kit cannot check that it is "${ref}" (from ${from}).`);
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
if (isUuid(ref)) {
|
|
100
|
+
if (ref.toLowerCase() !== own.toLowerCase())
|
|
101
|
+
throw keyTenantMismatch(ref, from, { id: own }, principal?.api_key?.name);
|
|
102
|
+
return own;
|
|
103
|
+
}
|
|
104
|
+
const described = await describeTenant(client, own);
|
|
105
|
+
const wanted = ref.toLowerCase();
|
|
106
|
+
if (described.slug?.toLowerCase() === wanted || described.name?.toLowerCase() === wanted)
|
|
107
|
+
return own;
|
|
108
|
+
if (described.slug || described.name)
|
|
109
|
+
throw keyTenantMismatch(ref, from, { id: own, ...described }, principal?.api_key?.name);
|
|
110
|
+
warn(`The tenant API key acts in its own tenant ${own}; the instance does not tell the key that tenant's slug or name, so the kit cannot check that it is "${ref}" (from ${from}). ` +
|
|
111
|
+
"Name the tenant by its id to have it checked.");
|
|
112
|
+
return own;
|
|
113
|
+
}
|
|
114
|
+
function keyTenantMismatch(ref, from, own, keyName) {
|
|
115
|
+
const key = keyName ? `The tenant API key "${keyName}"` : "The tenant API key";
|
|
116
|
+
return new CavelonError(ExitCode.usage, {
|
|
117
|
+
code: "tenant_mismatch",
|
|
118
|
+
message: `${key} acts only in tenant ${tenantTitle(own)}, but ${from} names tenant "${ref}"; nothing was sent there.`,
|
|
119
|
+
hint: "A key is bound to its own tenant and cannot act in another. Use a key of the tenant you name (CAVELON_TOKEN), " +
|
|
120
|
+
`or name the key's tenant, or leave the tenant out where the key is meant.`,
|
|
121
|
+
details: { named: { ref, from }, key_tenant: { id: own.id, name: own.name ?? null, slug: own.slug ?? null } },
|
|
122
|
+
});
|
|
123
|
+
}
|
package/dist/agent-env.js
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
|
+
import { CavelonError, ExitCode } from "./errors.js";
|
|
1
2
|
export const AGENT_VARIABLES = [
|
|
2
3
|
{ variable: "CAVELON_AGENT", agent: "any agent whose shell environment sets it" },
|
|
3
4
|
{ variable: "CLAUDECODE", agent: "Claude Code" },
|
|
4
5
|
{ variable: "CODEX_THREAD_ID", agent: "Codex" },
|
|
6
|
+
{ variable: "CODEX_CI", agent: "Codex" },
|
|
5
7
|
{ variable: "CODEX_SANDBOX", agent: "Codex" },
|
|
6
8
|
{ variable: "CURSOR_AGENT", agent: "Cursor" },
|
|
7
9
|
{ variable: "GEMINI_CLI", agent: "Gemini CLI" },
|
|
8
10
|
{ variable: "COPILOT_CLI", agent: "GitHub Copilot CLI" },
|
|
9
11
|
{ variable: "COPILOT_AGENT", agent: "GitHub Copilot in VS Code" },
|
|
12
|
+
{ variable: "AGENT_CONTEXT_OUT", agent: "Kiro CLI" },
|
|
13
|
+
{ variable: "TERM_PROGRAM", value: "kiro", agent: "Kiro" },
|
|
14
|
+
{ variable: "OPENCODE", agent: "OpenCode" },
|
|
15
|
+
{ variable: "GROK_AGENT", agent: "Grok Build" },
|
|
10
16
|
{ variable: "AI_AGENT", agent: "an agent that follows the AI_AGENT convention" },
|
|
11
17
|
];
|
|
12
|
-
function isSet(value) {
|
|
18
|
+
function isSet(value, expected) {
|
|
13
19
|
const text = value?.trim().toLowerCase();
|
|
20
|
+
if (expected !== undefined)
|
|
21
|
+
return text === expected;
|
|
14
22
|
return Boolean(text) && text !== "0" && text !== "false";
|
|
15
23
|
}
|
|
16
24
|
export function agentVariable(env) {
|
|
17
|
-
return AGENT_VARIABLES.find(({ variable }) => isSet(env[variable]))?.variable;
|
|
25
|
+
return AGENT_VARIABLES.find(({ variable, value }) => isSet(env[variable], value))?.variable;
|
|
18
26
|
}
|
|
19
27
|
export function drivenByAgent(ctx) {
|
|
20
28
|
if (ctx.mode === "mcp")
|
|
@@ -22,3 +30,13 @@ export function drivenByAgent(ctx) {
|
|
|
22
30
|
const variable = agentVariable(ctx.io.env);
|
|
23
31
|
return variable ? { by: "agent", variable } : undefined;
|
|
24
32
|
}
|
|
33
|
+
export function refuseForAgent(ctx, what, command) {
|
|
34
|
+
if (!drivenByAgent(ctx))
|
|
35
|
+
return;
|
|
36
|
+
throw new CavelonError(ExitCode.needsAction, {
|
|
37
|
+
code: "operation_for_a_person",
|
|
38
|
+
message: `${what} stays with a person, so cavelon does not do it when a coding agent runs it; nothing was sent.`,
|
|
39
|
+
hint: `A person runs this in their own terminal: \`${command}\`, or does it in the Admin.`,
|
|
40
|
+
details: { sent: false },
|
|
41
|
+
});
|
|
42
|
+
}
|
package/dist/branches.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isOperatorChange } from "./limits.js";
|
|
2
|
+
import { cavelonCommand, fill } from "./printed.js";
|
|
2
3
|
export const BRANCH_WIDTH_KEY = "orchestration_max_branch_concurrency";
|
|
3
4
|
export const BRANCH_PROCESS_KEY = "orchestration_process_max_branch_inflight";
|
|
4
5
|
export const PARALLEL_BRANCHES_KEY = "orchestration_parallel_branches";
|
|
@@ -30,11 +31,11 @@ export function switchOnText(item, change) {
|
|
|
30
31
|
if (item.source !== "tenant")
|
|
31
32
|
return `the instance operator turns it on with ${item.setting} (a deploy)`;
|
|
32
33
|
if (change && isOperatorChange(change)) {
|
|
33
|
-
return (`an operator turns it on in the Admin (Configure › Feature Flags), or with
|
|
34
|
-
"--tenant
|
|
34
|
+
return (`an operator turns it on in the Admin (Configure › Feature Flags), or with ` +
|
|
35
|
+
`${cavelonCommand("limits", "set", PARALLEL_BRANCHES_KEY, "on", "--tenant", fill("tenant"), "--confirm")} and a Platform-mode token`);
|
|
35
36
|
}
|
|
36
37
|
if (change)
|
|
37
|
-
return `a tenant admin turns it on with
|
|
38
|
+
return `a tenant admin turns it on with ${cavelonCommand("limits", "set", PARALLEL_BRANCHES_KEY, "on", "--confirm")}`;
|
|
38
39
|
return "the instance operator turns it on for this tenant in the Admin (Configure › Feature Flags)";
|
|
39
40
|
}
|
|
40
41
|
export function offText(branches) {
|
package/dist/capacity.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { changedBy, formatValue, readLimits } from "./limits.js";
|
|
2
|
+
import { cavelonCommand, fill } from "./printed.js";
|
|
2
3
|
export const CAPACITY_WAIT_AFTER_MS = 30_000;
|
|
3
4
|
export const RUN_CAPACITY_BUSY = "run_capacity_busy";
|
|
4
5
|
export const MODEL_ENDPOINT_BUSY = "model_endpoint_busy";
|
|
@@ -86,7 +87,7 @@ export function capacityHint(code, limits) {
|
|
|
86
87
|
const caps = runCaps(limits);
|
|
87
88
|
const now = caps.length ? ` Now: ${caps.map(capText).join("; ")}.` : "";
|
|
88
89
|
const kit = caps.some((c) => c.change?.requires_role?.length)
|
|
89
|
-
? ` With a Platform-mode personal access token, the operator runs
|
|
90
|
+
? ` With a Platform-mode personal access token, the operator runs ${cavelonCommand("limits", "set", "max_concurrent_agent_runs_per_tenant", fill("n"), "--tenant", fill("tenant"), "--confirm")}.`
|
|
90
91
|
: "";
|
|
91
92
|
return ("Retrying later is fine; a trigger or channel run waits for a free slot on its own. " +
|
|
92
93
|
"To run more at once, the instance operator raises max_concurrent_agent_runs_per_tenant: for this tenant alone " +
|
|
@@ -97,7 +98,7 @@ export function capacityHint(code, limits) {
|
|
|
97
98
|
const waited = wait ? ` (${ENDPOINT_SLOT_WAIT_KEY} is ${formatValue(wait)}; ${changedBy(wait)} changes it with ${wait.setting})` : "";
|
|
98
99
|
return (`Retrying later is fine. The model endpoint was serving its max_concurrent_requests and no slot freed in time${waited}. ` +
|
|
99
100
|
"If the endpoint can serve more at once, a tenant admin raises max_concurrent_requests on its Model Registry row " +
|
|
100
|
-
"
|
|
101
|
+
`(${cavelonCommand("models", "set-limit", fill("model_id"), fill("n"))}, the Admin's model form, or PATCH /api/v1/model-registry/{model_registry_id}); ` +
|
|
101
102
|
"every row with the same base_url shares that count.");
|
|
102
103
|
}
|
|
103
104
|
function readLinkedRun(client, op) {
|
package/dist/code-hints.js
CHANGED
|
@@ -41,14 +41,15 @@ export function similarCodes(code, known, max = 8) {
|
|
|
41
41
|
}
|
|
42
42
|
return ranked.sort((a, b) => a.rank - b.rank || a.code.localeCompare(b.code, "en")).slice(0, max).map((r) => r.code);
|
|
43
43
|
}
|
|
44
|
-
const BY_CODE = {
|
|
44
|
+
export const BY_CODE = {
|
|
45
45
|
package_schema_invalid: "Run `cavelon validate`: it checks the package files against the package schema offline and names each field that " +
|
|
46
|
-
"does not match, with file, line and path. `cavelon schema <section>` shows a section's fields and a minimal entry."
|
|
46
|
+
"does not match, with file, line and path. `cavelon schema <section>` shows a section's fields and a minimal entry. " +
|
|
47
|
+
"A missing manifest comes from `cavelon pull`, or `cavelon init` in the folder writes a minimal one.",
|
|
47
48
|
package_requirements_changed: "Run `cavelon apply` again for a new preview, show it, and confirm its id with `cavelon apply --confirm <preview-id>`.",
|
|
48
49
|
import_preview_stale: "Run `cavelon apply` again for a new preview, show it, and confirm its id with `cavelon apply --confirm <preview-id>`.",
|
|
49
50
|
};
|
|
50
|
-
const BY_ROUTE = [
|
|
51
|
-
{ route: "/api/v1/meta/package-schema", command: "`cavelon schema
|
|
51
|
+
export const BY_ROUTE = [
|
|
52
|
+
{ route: "/api/v1/meta/package-schema", command: "`cavelon schema` shows the package schema, `cavelon schema <section>` one section; `cavelon validate` checks the files against it." },
|
|
52
53
|
{ route: "/api/v1/meta/error-catalog", command: "`cavelon explain <code>` reads the error catalog." },
|
|
53
54
|
{ route: "/api/v1/meta/capabilities", command: "`cavelon status` and `cavelon limits` read the capabilities." },
|
|
54
55
|
{ route: "/api/v1/agent-graph/import/preview", command: "`cavelon apply` previews the package files." },
|
package/dist/command.js
CHANGED
|
@@ -29,6 +29,12 @@ export function renameFormerOptions(spec, args, warn) {
|
|
|
29
29
|
}
|
|
30
30
|
return out;
|
|
31
31
|
}
|
|
32
|
+
export function propertyName(name) {
|
|
33
|
+
return name.replaceAll("-", "_");
|
|
34
|
+
}
|
|
35
|
+
export function ownsTenant(spec) {
|
|
36
|
+
return Boolean(spec.positionals?.some((p) => p.name === "tenant") || spec.options?.tenant);
|
|
37
|
+
}
|
|
32
38
|
export const GLOBAL_OPTIONS = {
|
|
33
39
|
json: { type: "boolean", description: "Print one JSON document instead of text." },
|
|
34
40
|
instance: { type: "string", value: "<url>", description: "The instance URL (overrides CAVELON_URL and cavelon.yaml)." },
|