@cavelon/cli 0.1.10 → 0.1.12
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 +34 -15
- package/dist/access.js +194 -0
- package/dist/acting.js +123 -0
- package/dist/agent-env.js +20 -2
- package/dist/change-confirmation.js +93 -0
- package/dist/commands/api.js +77 -30
- package/dist/commands/chat.js +16 -8
- package/dist/commands/db.js +474 -0
- package/dist/commands/docs.js +83 -7
- package/dist/commands/index.js +7 -0
- package/dist/commands/limits-set.js +11 -5
- package/dist/commands/loops.js +72 -9
- package/dist/commands/models.js +12 -6
- package/dist/commands/sandboxes.js +7 -2
- package/dist/commands/session.js +111 -24
- package/dist/commands/setup.js +1 -1
- package/dist/commands/solution.js +211 -54
- package/dist/commands/tenants.js +55 -12
- package/dist/commands/values.js +104 -23
- package/dist/commands/work.js +13 -5
- package/dist/confirm-token.js +90 -7
- package/dist/context.js +5 -1
- package/dist/contracts.js +37 -12
- package/dist/database-queries.js +301 -0
- package/dist/fsutil.js +14 -0
- package/dist/http.js +69 -3
- package/dist/install.js +30 -0
- package/dist/invoke.js +12 -2
- package/dist/kit-codes.js +9 -2
- package/dist/mcp.js +106 -19
- package/dist/openapi.js +7 -0
- package/dist/package-check.js +19 -0
- package/dist/preview-report.js +2 -2
- package/dist/principal.js +24 -2
- package/dist/printed.js +5 -0
- package/dist/secret-access.js +30 -9
- package/dist/session.js +36 -8
- package/dist/skills/cavelon-authoring/SKILL.md +93 -10
- package/dist/skills/cavelon-long-running/SKILL.md +18 -8
- package/dist/skills/cavelon-loop/SKILL.md +126 -41
- package/dist/skills/cavelon-testing/SKILL.md +32 -3
- 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
package/README.md
CHANGED
|
@@ -17,8 +17,9 @@ npm i -g @cavelon/cli
|
|
|
17
17
|
Without Node.js, one line installs a standalone `cavelon` into your user
|
|
18
18
|
folder: `curl -fsSL https://github.com/goodguys-gmbh/cavelon-dev-kit/releases/latest/download/install.sh | sh`
|
|
19
19
|
on macOS and Linux, `irm https://github.com/goodguys-gmbh/cavelon-dev-kit/releases/latest/download/install.ps1 | iex`
|
|
20
|
-
in Windows PowerShell.
|
|
21
|
-
|
|
20
|
+
in Windows PowerShell. With Python, `uvx cavelon` runs the same executable from
|
|
21
|
+
PyPI, and `uv tool install cavelon` or `pipx install cavelon` installs it. Then
|
|
22
|
+
`cavelon setup` sets up your coding agents and logs you in.
|
|
22
23
|
|
|
23
24
|
The full documentation is in the repository's
|
|
24
25
|
[`docs/`](https://github.com/goodguys-gmbh/cavelon-dev-kit/tree/main/docs):
|
|
@@ -68,7 +69,8 @@ deletes it. The coding agent never sees the token: it calls `cavelon`, and
|
|
|
68
69
|
|
|
69
70
|
`login` reads the instance's capabilities and warns when its contract versions
|
|
70
71
|
are newer than this `cavelon` understands. It also caches the OpenAPI and the
|
|
71
|
-
error catalog under `~/.cache/cavelon/<instance>/<version
|
|
72
|
+
error catalog under `~/.cache/cavelon/<instance>/<version>/`, which only you
|
|
73
|
+
can read.
|
|
72
74
|
|
|
73
75
|
### CI, scripts and cloud agents
|
|
74
76
|
|
|
@@ -118,12 +120,12 @@ Every command takes `--json` (one JSON document on stdout, errors included),
|
|
|
118
120
|
| `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
121
|
| `models list` | read-only | The tenant's Model Registry rows with their endpoint and `max_concurrent_requests`; never a key. |
|
|
120
122
|
| `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. |
|
|
123
|
+
| `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
124
|
| `tenant list [--search]` | read-only | Tenants the token can see, with name, slug, role and id. |
|
|
123
125
|
| `harness list [--readiness]` | read-only | The tenant's solutions, with slug, name, status and id. |
|
|
124
126
|
| `harness new <slug> [--name] [--description]` | changing | Create an empty draft solution. |
|
|
125
127
|
| `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. |
|
|
128
|
+
| `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
129
|
| `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
130
|
| `deactivate [--harness] [--env] [--confirm [<token>]]` | changing (destructive) | Take an active solution out of live traffic: its status becomes `inactive` (not `draft`); previews first. |
|
|
129
131
|
| `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 +136,7 @@ Every command takes `--json` (one JSON document on stdout, errors included),
|
|
|
134
136
|
| `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
137
|
| `explain <code>` | read-only | Look a code up in the instance's error catalog. |
|
|
136
138
|
| `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. |
|
|
139
|
+
| `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
140
|
| `variables delete <name> [--confirm]` | changing (destructive) | Delete a variable; without `--confirm`, shows it. |
|
|
139
141
|
| `secrets list [--missing]` | read-only | The tenant's secret names (`{{secret:…}}`): set or not, declared, changed when. Never a value. |
|
|
140
142
|
| `secrets set <name>` | changing | Set a secret's value from the terminal or stdin. A person runs this. |
|
|
@@ -148,8 +150,12 @@ Every command takes `--json` (one JSON document on stdout, errors included),
|
|
|
148
150
|
| `watch <operation> [--timeout 10m]` | read-only | Stream an operation's changes (server-sent events). |
|
|
149
151
|
| `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
152
|
| `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
|
-
| `
|
|
153
|
+
| `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. |
|
|
154
|
+
| `db instance` | read-only | The dialects the instance runs and the addresses it connects to databases from, which a database's firewall lets in. |
|
|
155
|
+
| `db connections` / `db queries [<query>] [--connection]` / `db runs <query>` | read-only | The tenant's database connections (with their CA certificates' expiry), saved queries (one in full with its SQL and parameters) and a query's runs (no values, no rows). |
|
|
156
|
+
| `db test <connection>` | changing | The tenant Owner tests a connection step by step; exit 3 when a step fails. |
|
|
157
|
+
| `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. |
|
|
158
|
+
| `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
159
|
| `loop cancel <run> [--confirm]` | changing (destructive) | Stop a trigger run and its loops; without `--confirm`, shows what would stop. |
|
|
154
160
|
| `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
161
|
| `loop iterations <run> [--loop] [--limit] [--cursor]` | read-only | A loop's state, budget and iterations. |
|
|
@@ -385,15 +391,22 @@ op read op://dev/crm/token | cavelon secrets set crm_api_token
|
|
|
385
391
|
- A **variable** is plain text: anyone who may view the tenant's settings
|
|
386
392
|
reads it, and the agent may set it (MCP: `variables_list`, `variables_get`,
|
|
387
393
|
`variables_set`). `variables set` refuses a value that looks like a token.
|
|
394
|
+
A new variable is set at once; replacing another value shows the old and
|
|
395
|
+
the new one and changes it only with `--confirm`, because every solution of
|
|
396
|
+
the tenant reads it.
|
|
388
397
|
- A **secret's** value is never an argument, never printed, never written to a
|
|
389
398
|
file and never read back. `secrets set` reads it from the terminal without
|
|
390
399
|
echo, or from standard input when that is piped (one trailing line break is
|
|
391
400
|
dropped), and refuses a value given as an argument without repeating it.
|
|
392
401
|
Setting or deleting one needs a person (a session or a personal access
|
|
393
402
|
token): with a tenant API key, `cavelon` refuses before it asks for the value
|
|
394
|
-
or sends anything (
|
|
395
|
-
|
|
396
|
-
`
|
|
403
|
+
or sends anything (`secret_needs_a_person`, as the instance would answer).
|
|
404
|
+
Where the instance lets only a person signed in to the Admin set or delete
|
|
405
|
+
one (`/meta/principal` lists them in `needs_a_person`), every token is
|
|
406
|
+
refused that way (exit 5; a key on an older instance exits 7), and the hints name the Admin's
|
|
407
|
+
Settings › Secrets page. MCP offers only `secrets_list`; an agent tells the
|
|
408
|
+
person the exact `cavelon secrets set <name>` command, or the Admin page,
|
|
409
|
+
instead.
|
|
397
410
|
- `--env <name>` acts in the tenant `env/<name>.yaml` names, like `apply`. A
|
|
398
411
|
name without its env file is refused (exit 2) before anything is sent.
|
|
399
412
|
|
|
@@ -491,14 +504,17 @@ cavelon sandbox seed orders-test seeds/orders # shows what it would s
|
|
|
491
504
|
cavelon sandbox seed orders-test seeds/orders --confirm # the archive becomes the workspace
|
|
492
505
|
cavelon trigger identity orders loop-runner # shows the change
|
|
493
506
|
cavelon trigger identity orders loop-runner --confirm # binds the API key
|
|
494
|
-
cavelon loop start orders --input @request.json
|
|
507
|
+
cavelon loop start orders --input @request.json # shows what it would start
|
|
508
|
+
cavelon loop start orders --input @request.json --confirm # starts the run
|
|
495
509
|
cavelon loop watch <run>
|
|
496
510
|
cavelon sandbox cat orders-test output/summary.json
|
|
497
511
|
cavelon artifacts export orders-test --path output --wait --out results.tar
|
|
498
512
|
```
|
|
499
513
|
|
|
500
514
|
- **`loop start`** calls the trigger's run-now route; the run acts as you (with
|
|
501
|
-
a personal access token, the person)
|
|
515
|
+
a personal access token, the person) and spends the tenant's budget, so it
|
|
516
|
+
first shows the trigger, its solution and the payload, and starts only with
|
|
517
|
+
`--confirm`. It returns the run id and the run's
|
|
502
518
|
operation id, so `wait` and `watch` follow it (and `trace <operation>` reads
|
|
503
519
|
the run's traces); a paused loop makes `wait` exit 5. It sends an
|
|
504
520
|
`Idempotency-Key` (`--idempotency-key`, a new UUID by default; `--json`:
|
|
@@ -691,7 +707,10 @@ cavelon activate --harness support
|
|
|
691
707
|
- **`activate`** reads the readiness gate and activates only when it passes,
|
|
692
708
|
never with `force`. A personal access token without "may activate" is refused
|
|
693
709
|
before anything is sent (exit 7); a solution that is not ready exits 3 with its
|
|
694
|
-
blockers.
|
|
710
|
+
blockers. A solution a channel or an active trigger reaches (the solution's
|
|
711
|
+
`channel_count`, the active triggers bound to it) goes live for them at once,
|
|
712
|
+
so there it previews and activates only with `--confirm`; so it does where the
|
|
713
|
+
instance does not say what reaches a solution.
|
|
695
714
|
- **A Masterloop parent and its iteration solution** activate without the
|
|
696
715
|
override in one order: apply the iteration, apply the parent, run the
|
|
697
716
|
parent's loop suite, activate the iteration, activate the parent.
|
|
@@ -779,7 +798,7 @@ an agent only with a new plugin or `init --update`. With `cavelon` installed,
|
|
|
779
798
|
| `~/.config/cavelon/config.json` | the current instance, the tenant chosen with `use`, which store holds the token. Never a token. |
|
|
780
799
|
| `~/.config/cavelon/credentials.json` | the token per instance (0600), only where there is no OS credential store |
|
|
781
800
|
| `~/.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
|
|
801
|
+
| `~/.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
802
|
| `~/.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
803
|
|
|
785
804
|
`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
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { CavelonError, ExitCode } from "./errors.js";
|
|
2
|
+
import { operationForPath } from "./openapi.js";
|
|
3
|
+
import { cavelonCommand } from "./printed.js";
|
|
4
|
+
const DOCUMENTED = { path: "/api/v1/confirmations", header: "X-Cavelon-Confirmation" };
|
|
5
|
+
const HEADER_NAME = /^[A-Za-z][A-Za-z0-9-]*$/;
|
|
6
|
+
export async function enforcedOffer(ctx) {
|
|
7
|
+
const caps = await (await ctx.contracts()).capabilities().catch(() => null);
|
|
8
|
+
const offer = caps?.confirmations;
|
|
9
|
+
if (!offer || typeof offer !== "object" || offer.enforced !== true)
|
|
10
|
+
return undefined;
|
|
11
|
+
return offerFrom(offer.path, offer.header);
|
|
12
|
+
}
|
|
13
|
+
function offerFrom(path, header) {
|
|
14
|
+
return {
|
|
15
|
+
path: typeof path === "string" && path.startsWith("/") ? path : DOCUMENTED.path,
|
|
16
|
+
header: typeof header === "string" && HEADER_NAME.test(header) ? header : DOCUMENTED.header,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
async function marked(ctx, method, path) {
|
|
20
|
+
const doc = await (await ctx.contracts()).openapi().catch(() => undefined);
|
|
21
|
+
const found = doc ? operationForPath(doc, method, path) : undefined;
|
|
22
|
+
return found?.op.confirmation === true;
|
|
23
|
+
}
|
|
24
|
+
function ownPath(client, path, query) {
|
|
25
|
+
const url = client.resolve(path, query);
|
|
26
|
+
const base = new URL(client.url.endsWith("/") ? client.url : `${client.url}/`).pathname;
|
|
27
|
+
return { pathname: base.length > 1 && url.pathname.startsWith(base) ? url.pathname.slice(base.length - 1) : url.pathname, search: url.search };
|
|
28
|
+
}
|
|
29
|
+
export function confirmedPath(client, path, query) {
|
|
30
|
+
const own = ownPath(client, path, query);
|
|
31
|
+
return `${decodeURIComponent(own.pathname)}${own.search}`;
|
|
32
|
+
}
|
|
33
|
+
async function issue(client, offer, method, path, body) {
|
|
34
|
+
const response = await client.request("POST", offer.path, {
|
|
35
|
+
json: { method, path, body: body ?? null },
|
|
36
|
+
confirmation: false,
|
|
37
|
+
allow: [400, 404, 405, 422],
|
|
38
|
+
});
|
|
39
|
+
const id = response.status === 201 || response.status === 200 ? response.data?.confirmation_id : undefined;
|
|
40
|
+
return typeof id === "string" && id.trim() ? id.trim() : undefined;
|
|
41
|
+
}
|
|
42
|
+
export function changeConfirmer(ctx, client) {
|
|
43
|
+
return async (request, asked) => {
|
|
44
|
+
const approved = ctx.approved;
|
|
45
|
+
if (!approved || !client.target.token?.startsWith("cvpat_"))
|
|
46
|
+
return undefined;
|
|
47
|
+
let offer;
|
|
48
|
+
if (asked)
|
|
49
|
+
offer = offerFrom(asked.confirmations, asked.header);
|
|
50
|
+
else {
|
|
51
|
+
if (!approved.guarded)
|
|
52
|
+
return undefined;
|
|
53
|
+
offer = await enforcedOffer(ctx);
|
|
54
|
+
if (!offer || !(await marked(ctx, request.method, ownPath(client, request.path).pathname)))
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
const path = confirmedPath(client, request.path, request.query);
|
|
58
|
+
const id = await issue(client, offer, request.method, path, request.body);
|
|
59
|
+
return id ? { [offer.header]: id } : undefined;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export const CONFIRMATION_REQUIRED = "confirmation_required";
|
|
63
|
+
export const CONFIRMATION_INVALID = "confirmation_invalid";
|
|
64
|
+
export function confirmationRefused(error, sentId) {
|
|
65
|
+
if (error.status !== 428 || (error.code !== CONFIRMATION_REQUIRED && error.code !== CONFIRMATION_INVALID))
|
|
66
|
+
return error;
|
|
67
|
+
const details = error.details && typeof error.details === "object" && !Array.isArray(error.details) ? error.details : {};
|
|
68
|
+
const hint = error.code === CONFIRMATION_INVALID
|
|
69
|
+
? "Run the command again: it previews the change, and once the person approves it cavelon asks the instance for a new confirmation. " +
|
|
70
|
+
`A confirmation lasts minutes and confirms one change once. \`${cavelonCommand("explain", CONFIRMATION_INVALID)}\` says more.`
|
|
71
|
+
: sentId
|
|
72
|
+
? `The instance asked again for a confirmation cavelon sent. \`${cavelonCommand("explain", CONFIRMATION_REQUIRED)}\` says more.`
|
|
73
|
+
: "The instance wants the person's own yes for this change. The person runs the command in their own terminal with --confirm " +
|
|
74
|
+
"(or approves it in the MCP client's dialog), where cavelon asks the instance for the confirmation; or makes the change in the Admin. " +
|
|
75
|
+
`\`${cavelonCommand("explain", CONFIRMATION_REQUIRED)}\` says more.`;
|
|
76
|
+
return new CavelonError(ExitCode.needsAction, {
|
|
77
|
+
code: error.code,
|
|
78
|
+
message: error.message.includes("Nothing was changed") ? error.message : `${error.message} Nothing was changed.`,
|
|
79
|
+
hint,
|
|
80
|
+
docs: error.docs,
|
|
81
|
+
status: error.status,
|
|
82
|
+
details: { ...details, confirmation_sent: sentId },
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
export function confirmationPointer(code) {
|
|
86
|
+
if (code !== CONFIRMATION_REQUIRED && code !== CONFIRMATION_INVALID)
|
|
87
|
+
return undefined;
|
|
88
|
+
return ("Only after the person approved the change does cavelon ask the instance for this confirmation: in their own terminal with " +
|
|
89
|
+
"--confirm, or in the MCP client's dialog when an agent confirms with the preview's token. An agent's token alone never gets one. " +
|
|
90
|
+
(code === CONFIRMATION_INVALID
|
|
91
|
+
? "An expired, used or other change's confirmation needs a new preview and the person's yes again."
|
|
92
|
+
: "An older cavelon sends none: update it, or make the change in the Admin."));
|
|
93
|
+
}
|