@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
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/commands/api.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { promises as fs } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { AGENT_VARIABLES, drivenByAgent } from "../agent-env.js";
|
|
4
|
-
import { CURSOR_OPTION, intOption, listOption, pageOf, positional, stringOption, } from "../command.js";
|
|
4
|
+
import { boolOption, CURSOR_OPTION, intOption, listOption, pageOf, positional, stringOption, } from "../command.js";
|
|
5
5
|
import { CavelonError, ExitCode, usageError, validationError } from "../errors.js";
|
|
6
6
|
import { clip, moreHint, table } from "../format.js";
|
|
7
7
|
import { readAll } from "../io.js";
|
|
@@ -10,6 +10,8 @@ import { confinedPath } from "../paths.js";
|
|
|
10
10
|
import { describeSchema, findOperation, jsonBodySchema, matchedLoosely, operations, schemaTypes, secretFields, secretPaths } from "../openapi.js";
|
|
11
11
|
import { harnessNotFoundError, lookupHarness } from "../harness-ref.js";
|
|
12
12
|
import { CONFIRM_TOKEN, confirmToken, confirmTokenRequired, confirmWith } from "../confirm-token.js";
|
|
13
|
+
import { actingTarget, targetLine } from "../acting.js";
|
|
14
|
+
import { accessFor, operationAccess } from "../access.js";
|
|
13
15
|
import { cavelonCommand, fill } from "../printed.js";
|
|
14
16
|
export const JSON_BODY_DEPRECATED = "`--json <body>` as the request body is deprecated and will be removed in a later release; pass the body with --body. " +
|
|
15
17
|
"--json alone prints JSON, as on every command.";
|
|
@@ -96,7 +98,7 @@ function parseParams(input) {
|
|
|
96
98
|
const FOR_A_PERSON = [
|
|
97
99
|
{
|
|
98
100
|
does: "changes a secret",
|
|
99
|
-
hint: "A person sets a secret in their terminal with `cavelon secrets set <name>` (or deletes it with `cavelon secrets delete <name>`).",
|
|
101
|
+
hint: "A person sets a secret in their own terminal with `cavelon secrets set <name>` (or deletes it with `cavelon secrets delete <name>`).",
|
|
100
102
|
match: (word) => word.includes("secret"),
|
|
101
103
|
},
|
|
102
104
|
{
|
|
@@ -118,7 +120,7 @@ export function keptForPerson(op, all) {
|
|
|
118
120
|
if (all.some((o) => o.personOnly)) {
|
|
119
121
|
if (!op.personOnly?.marked)
|
|
120
122
|
return undefined;
|
|
121
|
-
const hint = byPathWords(op)?.hint ?? `A person runs it: in Cavelon, or in their terminal with \`cavelon api ${op.alias}\`.`;
|
|
123
|
+
const hint = byPathWords(op)?.hint ?? `A person runs it: in Cavelon, or in their own terminal with \`cavelon api ${op.alias}\`.`;
|
|
122
124
|
return { source: "instance", ...(op.personOnly.reason ? { reason: op.personOnly.reason } : {}), hint };
|
|
123
125
|
}
|
|
124
126
|
if (op.readOnly)
|
|
@@ -127,12 +129,7 @@ export function keptForPerson(op, all) {
|
|
|
127
129
|
return rule ? { source: "kit", reason: rule.does, hint: rule.hint } : undefined;
|
|
128
130
|
}
|
|
129
131
|
function notSentBy(driven) {
|
|
130
|
-
return driven.by === "mcp"
|
|
131
|
-
? "no tool sends it, with or without confirm."
|
|
132
|
-
: `cavelon api does not send it when a coding agent runs it (${driven.variable} is set), with or without --confirm.`;
|
|
133
|
-
}
|
|
134
|
-
function personHint(hint, driven) {
|
|
135
|
-
return driven.by === "mcp" ? hint : `${hint} A person's own terminal is not guarded: it does not set ${driven.variable}.`;
|
|
132
|
+
return driven.by === "mcp" ? "no tool sends it, with or without confirm." : "cavelon api does not send it when a coding agent runs it, with or without --confirm.";
|
|
136
133
|
}
|
|
137
134
|
function refusal(op, kept, driven) {
|
|
138
135
|
const named = `${op.alias} (${op.method} ${op.path})`;
|
|
@@ -160,7 +157,7 @@ function secretRefusal(op, fields, driven) {
|
|
|
160
157
|
code: "secret_field_for_a_person",
|
|
161
158
|
message: `The request to ${op.alias} sets ${named}, which the instance marks as a secret value (x-cavelon-secret); ` +
|
|
162
159
|
`a person enters secret values, so ${notSentBy(driven)}`,
|
|
163
|
-
hint:
|
|
160
|
+
hint: `A person sets a secret value in their own terminal with \`${cavelonCommand("secrets", "set", fill("name"))}\`, or enters it in the Admin. Leave the field out to send the rest.`,
|
|
164
161
|
details: { fields },
|
|
165
162
|
});
|
|
166
163
|
}
|
|
@@ -202,7 +199,7 @@ export const api = {
|
|
|
202
199
|
"--json <body> still works for now but is deprecated: --json alone prints JSON, as on every command.\n" +
|
|
203
200
|
"The body is checked against the operation's schema before it is sent.\n" +
|
|
204
201
|
"As an MCP tool, or run by a coding agent (" +
|
|
205
|
-
AGENT_VARIABLES.filter((v) => v.variable !== "CAVELON_AGENT").map((v) => v.variable).join(", ") +
|
|
202
|
+
AGENT_VARIABLES.filter((v) => v.variable !== "CAVELON_AGENT").map((v) => (v.value ? `${v.variable}=${v.value}` : v.variable)).join(", ") +
|
|
206
203
|
"\nor CAVELON_AGENT=1 is set), an operation that changes something returns what it would send and a confirm token,\n" +
|
|
207
204
|
"and sends it only with that token: --confirm <token>, or confirm: \"<token>\" as an MCP tool. A changed request\n" +
|
|
208
205
|
"needs a new preview; confirm: true is refused.\n" +
|
|
@@ -267,8 +264,8 @@ export const api = {
|
|
|
267
264
|
throw new CavelonError(ExitCode.needsAction, {
|
|
268
265
|
code: "operation_for_a_person",
|
|
269
266
|
message: refusal(op, kept, driven),
|
|
270
|
-
hint:
|
|
271
|
-
details: { source: kept.source, ...(kept.reason ? { reason: kept.reason } : {})
|
|
267
|
+
hint: kept.hint,
|
|
268
|
+
details: { source: kept.source, ...(kept.reason ? { reason: kept.reason } : {}) },
|
|
272
269
|
});
|
|
273
270
|
}
|
|
274
271
|
const secrets = secretsIn(doc, op, args);
|
|
@@ -314,12 +311,13 @@ async function previewUnlessConfirmed(ctx, input, doc, op, args, driven) {
|
|
|
314
311
|
const confirm = driven.by === "mcp"
|
|
315
312
|
? confirmWith("api", token)
|
|
316
313
|
: `Show the person this request, then run the same command again with --confirm ${token} to send exactly it.`;
|
|
317
|
-
const
|
|
318
|
-
const
|
|
314
|
+
const target = await actingTarget(ctx);
|
|
315
|
+
const shown = { operation: op.alias, ...request, ...(files.length ? { files } : {}), target, sent: false };
|
|
316
|
+
const lines = [`Would send ${request.method} ${request.path}. Nothing was sent.`, targetLine(target)];
|
|
319
317
|
if (stale)
|
|
320
318
|
lines.push("The confirm token is not this request's: the request changed since its preview, or the token is another one's.");
|
|
321
319
|
if (bare && driven.by === "agent")
|
|
322
|
-
lines.push(
|
|
320
|
+
lines.push("--confirm alone does not send it when a coding agent runs cavelon.");
|
|
323
321
|
if (Object.keys(request.query).length)
|
|
324
322
|
lines.push(`Query: ${JSON.stringify(request.query)}`);
|
|
325
323
|
if (Object.keys(request.headers).length)
|
|
@@ -347,11 +345,13 @@ export const apiList = {
|
|
|
347
345
|
method: { type: "string", value: "<method>", description: "Only this HTTP method (GET, POST, …)." },
|
|
348
346
|
tags: { type: "boolean", description: "List the tags with their operation counts instead." },
|
|
349
347
|
limit: { type: "string", value: "<n>", description: "Return at most n operations (default 50, 0 for all)." },
|
|
348
|
+
usable: { type: "boolean", description: "Leave out the operations the instance says this credential may not send." },
|
|
350
349
|
cursor: CURSOR_OPTION,
|
|
351
350
|
},
|
|
352
351
|
async run(ctx, input) {
|
|
353
352
|
const doc = await (await ctx.contracts()).openapi();
|
|
354
353
|
let ops = operations(doc);
|
|
354
|
+
const access = await listAccess(ctx);
|
|
355
355
|
if (input.options.tags === true) {
|
|
356
356
|
const counts = new Map();
|
|
357
357
|
for (const op of ops)
|
|
@@ -373,6 +373,10 @@ export const apiList = {
|
|
|
373
373
|
if (search) {
|
|
374
374
|
ops = ops.filter((o) => [o.operationId, o.path, o.summary ?? ""].some((s) => s.toLowerCase().includes(search)));
|
|
375
375
|
}
|
|
376
|
+
const usableOnly = boolOption(input, "usable");
|
|
377
|
+
const marks = new Map(ops.map((o) => [o, operationAccess(access, `${o.method} ${o.path}`)]));
|
|
378
|
+
if (usableOnly)
|
|
379
|
+
ops = ops.filter((o) => marks.get(o).allowed !== false);
|
|
376
380
|
const wanted = intOption(input, "limit", { min: 0, max: 1000, fallback: 50 });
|
|
377
381
|
const limit = wanted === 0 ? Math.max(ops.length, 1) : wanted;
|
|
378
382
|
const page = pageOf(ops.map((o) => ({
|
|
@@ -383,16 +387,31 @@ export const apiList = {
|
|
|
383
387
|
summary: o.summary ?? null,
|
|
384
388
|
tags: o.tags,
|
|
385
389
|
read_only: o.readOnly,
|
|
390
|
+
...accessFields(marks.get(o)),
|
|
386
391
|
})), limit, stringOption(input, "cursor"));
|
|
387
|
-
const flags = [tag ? ["--tag", tag] : [], method ? ["--method", method] : [], search ? ["--search", search] : []].flat();
|
|
392
|
+
const flags = [tag ? ["--tag", tag] : [], method ? ["--method", method] : [], search ? ["--search", search] : [], usableOnly ? ["--usable"] : []].flat();
|
|
393
|
+
const marked = page.items.some((i) => i.may_send === false);
|
|
388
394
|
return {
|
|
389
|
-
data: page,
|
|
390
|
-
text: table(page.items, ["operation", "method", "path", "summary"]) +
|
|
395
|
+
data: { ...page, credential_published: Boolean(access) },
|
|
396
|
+
text: table(page.items.map((i) => ({ ...i, access: i.needs_a_person ? "a person" : i.needs?.length ? `needs ${i.needs.join(" and ")}` : "" })), marked ? ["operation", "method", "path", "access", "summary"] : ["operation", "method", "path", "summary"]) +
|
|
391
397
|
`\n${page.items.length} of ${page.total}` +
|
|
398
|
+
(marked ? `\nOperations with an access entry are ones this credential may not send, as the instance says; --usable leaves them out.` : "") +
|
|
392
399
|
moreHint(page.next_cursor, cavelonCommand("api", "list", ...flags)),
|
|
393
400
|
};
|
|
394
401
|
},
|
|
395
402
|
};
|
|
403
|
+
async function listAccess(ctx) {
|
|
404
|
+
try {
|
|
405
|
+
const session = await ctx.session();
|
|
406
|
+
return session.token ? await accessFor(await ctx.client()) : undefined;
|
|
407
|
+
}
|
|
408
|
+
catch {
|
|
409
|
+
return undefined;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
function accessFields(mark) {
|
|
413
|
+
return { may_send: mark.allowed, needs_a_person: mark.person ?? null, needs: mark.missing ?? null };
|
|
414
|
+
}
|
|
396
415
|
export const apiDescribe = {
|
|
397
416
|
name: "api describe",
|
|
398
417
|
summary: "Show one operation's parameters, body and responses.",
|