@cavelon/cli 0.1.5 → 0.1.7
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 +56 -18
- package/dist/command.js +10 -0
- package/dist/commands/api.js +40 -36
- package/dist/commands/chat.js +183 -0
- package/dist/commands/docs.js +77 -9
- package/dist/commands/fmt.js +61 -6
- package/dist/commands/index.js +3 -0
- package/dist/commands/init.js +61 -26
- package/dist/commands/inventory.js +21 -0
- package/dist/commands/limits-set.js +10 -6
- package/dist/commands/loops.js +22 -11
- package/dist/commands/models.js +11 -7
- package/dist/commands/sandboxes.js +11 -5
- package/dist/commands/schema.js +230 -48
- package/dist/commands/session.js +100 -14
- package/dist/commands/setup.js +22 -6
- package/dist/commands/solution.js +493 -86
- package/dist/commands/tenants.js +43 -10
- package/dist/commands/values.js +20 -11
- package/dist/commands/work.js +167 -33
- package/dist/confirm-token.js +72 -0
- package/dist/format.js +4 -4
- package/dist/harness-ref.js +17 -4
- package/dist/http.js +6 -0
- package/dist/kit-codes.js +11 -1
- package/dist/local-state.js +46 -10
- package/dist/main.js +38 -6
- package/dist/mcp.js +65 -14
- package/dist/openapi.js +30 -0
- package/dist/package-check.js +206 -18
- package/dist/package-files.js +98 -40
- package/dist/package-format.js +81 -8
- package/dist/package-references.js +77 -10
- package/dist/results.js +21 -1
- package/dist/session.js +9 -0
- package/dist/skills/cavelon-authoring/SKILL.md +54 -21
- package/dist/skills/cavelon-long-running/SKILL.md +13 -9
- package/dist/skills/cavelon-loop/SKILL.md +124 -28
- package/dist/skills/cavelon-testing/SKILL.md +69 -16
- package/dist/tenant-choice.js +19 -0
- package/dist/trace-view.js +172 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -124,11 +124,13 @@ Every command takes `--json` (one JSON document on stdout, errors included),
|
|
|
124
124
|
| `harness new <slug> [--name] [--description]` | changing | Create an empty draft solution. |
|
|
125
125
|
| `harness clone <source> [--slug] [--name] [--no-tests] [--no-triggers]` | changing | Copy a solution into a new draft. |
|
|
126
126
|
| `activate [--harness] [--env]` | changing | Activate through the readiness gate only, never by force. |
|
|
127
|
-
| `
|
|
128
|
-
| `
|
|
129
|
-
| `
|
|
130
|
-
| `
|
|
131
|
-
| `
|
|
127
|
+
| `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
|
+
| `deactivate [--harness] [--env] [--confirm [<token>]]` | changing (destructive) | Take an active solution out of live traffic: its status becomes `inactive` (not `draft`); previews first. |
|
|
129
|
+
| `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. |
|
|
130
|
+
| `pull [--harness] [--force] [--tenant-wide]` | changing (files) | Write the instance's package into `package/` and `tests/`, the inventory into `.cavelon/`. A solution's tenant-wide sections only with `--tenant-wide`, which says when the export carries none. |
|
|
131
|
+
| `validate [--offline] [--strict]` | read-only | Check the package files against the cached package schema, their references, unknown fields and models; `--strict` fails on warnings. |
|
|
132
|
+
| `schema [<section>[.<field>…] \| <type>] [--offline]` | read-only | The package schema's sections, or the fields of a section, a nested field (`agents.handoffs`) or a type, with a minimal example. |
|
|
133
|
+
| `apply [--env] [--harness] [--mode] [--tenant-wide]` | changing | Preview the files against the instance; prints and stores a preview id. A solution's tenant-wide sections go along only with `--tenant-wide`, for the whole tenant. |
|
|
132
134
|
| `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. |
|
|
133
135
|
| `explain <code>` | read-only | Look a code up in the instance's error catalog. |
|
|
134
136
|
| `variables list` / `variables get <name>` | read-only | The tenant's plain-text variables (`{{var:…}}`) with their values. |
|
|
@@ -144,7 +146,7 @@ Every command takes `--json` (one JSON document on stdout, errors included),
|
|
|
144
146
|
| `docs get <page> [--max-chars] [--cursor]` | read-only | One docs page as markdown. |
|
|
145
147
|
| `wait <operation…> [--timeout 90s]` | read-only | Wait for operations; resumable, and reports `waited_ms`. A test run with failed cases is a failure. |
|
|
146
148
|
| `watch <operation> [--timeout 10m]` | read-only | Stream an operation's changes (server-sent events). |
|
|
147
|
-
| `kb upload <dir> --kb <kb> [-r] [--ext pdf] [--replace] [--wait]` | changing | Upload documents; returns operation ids. Names files that match an active document; `--replace` replaces those. |
|
|
149
|
+
| `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. |
|
|
148
150
|
| `test run [--suite <s>] [--harness <h>] [--wait]` | changing | Start test-suite runs; returns operation ids. |
|
|
149
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. |
|
|
150
152
|
| `loop start <trigger> [--input <json>] [--wait]` | changing | Start a loop through its trigger, as you; returns the run and operation ids. |
|
|
@@ -404,6 +406,19 @@ base by file name, with what happens to that document, in `--dry-run` too:
|
|
|
404
406
|
bergbahn-faq.md exists (094e95e9…) and stays active
|
|
405
407
|
```
|
|
406
408
|
|
|
409
|
+
A file whose bytes are those of an active document, under any name, is not
|
|
410
|
+
created again: the instance deduplicates it, and `kb upload` says
|
|
411
|
+
"identical to the active document …; nothing new was created (deduplicated)".
|
|
412
|
+
`--dry-run` says so before the upload ("nothing new would be created") where
|
|
413
|
+
the instance publishes each document's `file_sha256` (the SHA-256 of the
|
|
414
|
+
uploaded bytes, which its deduplication compares): it hashes each local file
|
|
415
|
+
the same way, and `--json` lists those files under `identical` with the
|
|
416
|
+
document each one matches, and sets `content_compared`. A same-named document
|
|
417
|
+
the file is identical to is then neither replaced nor deactivated. On an
|
|
418
|
+
instance that does not publish the hash, `content_compared` is `false` and
|
|
419
|
+
the dry run names no file identical; a document without a hash (not a file,
|
|
420
|
+
or uploaded before the instance published it) matches none.
|
|
421
|
+
|
|
407
422
|
- Without a flag the old document stays active next to the new one, and both
|
|
408
423
|
answer, unless the instance replaces same-named documents itself (its upload
|
|
409
424
|
offers `replace_existing`); there `--keep-both` keeps both.
|
|
@@ -592,8 +607,11 @@ cavelon activate --harness support
|
|
|
592
607
|
Sections the instance's package schema does not know are written, reported as
|
|
593
608
|
`ignored` and warned about, as `validate` does. With no `--harness`,
|
|
594
609
|
a package with one harness names the solution in a new `cavelon.yaml` and
|
|
595
|
-
`env/test.yaml
|
|
596
|
-
|
|
610
|
+
`env/test.yaml`. A solution the tenant does not have yet, `init` creates as a
|
|
611
|
+
draft, named as in the package, so `apply --env test` previews into it; the
|
|
612
|
+
MCP tool `init` creates none and names the `cavelon harness new` command
|
|
613
|
+
instead. The rest of `init` runs as without `--from`: its own files, the
|
|
614
|
+
marked blocks.
|
|
597
615
|
|
|
598
616
|
```bash
|
|
599
617
|
mkdir counter && cd counter
|
|
@@ -613,14 +631,27 @@ cavelon activate --harness support
|
|
|
613
631
|
one the tenant's full configuration, and splits it along the top-level sections
|
|
614
632
|
of the instance's published package schema, so no entity type is built into
|
|
615
633
|
the binary. A file whose content did not change keeps its bytes, so `git diff`
|
|
616
|
-
shows what changed on the instance;
|
|
617
|
-
|
|
634
|
+
shows what changed on the instance; a field the export spells out and the file
|
|
635
|
+
leaves out (an empty list or object, `null`, a default) is no change. A test
|
|
636
|
+
suite goes back to the file it came from (`.cavelon/pulled-files.json` records
|
|
637
|
+
which). Files of sections the schema does not know are kept byte for byte. A
|
|
638
|
+
solution's pull leaves the tenant-wide sections out of the folder (those the
|
|
639
|
+
schema marks `x-cavelon-scope: tenant`; on an instance that marks none,
|
|
640
|
+
`tenant_settings` and `model_registry`) unless `--tenant-wide`, which asks the
|
|
641
|
+
export for them (`include_tenant_wide`) where the instance takes it, and says
|
|
642
|
+
when the export carries none. A file of one already there is kept (listed
|
|
643
|
+
under `kept`). It refuses when package files have uncommitted changes
|
|
618
644
|
(exit 4) unless `--force`, and writes the tenant's solutions, knowledge bases,
|
|
619
645
|
tools, test suites and sandboxes to `.cavelon/inventory.md`.
|
|
620
646
|
- **`validate`** checks the files against the package schema that `init`, `pull`
|
|
621
647
|
or `apply` cached, and the package version against those the instance accepts.
|
|
622
|
-
It contacts the instance only when nothing is cached
|
|
623
|
-
|
|
648
|
+
It contacts the instance only when nothing is cached, or to read a tenant's
|
|
649
|
+
list (models, skills, tools, knowledge bases, solutions) the package refers to
|
|
650
|
+
and no command has read yet; never with `--offline`, which names the checks it
|
|
651
|
+
skipped instead. Each finding has a file, line, path and code; exit 3 on
|
|
652
|
+
errors, and with `--strict` on warnings too. A reference the import preview
|
|
653
|
+
will block (`package_reference_unknown`, `package_model_unknown`) keeps the
|
|
654
|
+
summary from saying "Valid". A Model
|
|
624
655
|
Registry row's `max_concurrent_requests` needs a `base_url`
|
|
625
656
|
(`model_endpoint_limit_without_base_url`); where the package schema does not
|
|
626
657
|
carry the field, a warning says the import ignores it.
|
|
@@ -635,12 +666,19 @@ cavelon activate --harness support
|
|
|
635
666
|
finds what the preview did not answers `409 package_requirements_changed`
|
|
636
667
|
with `blockers`: exit 4, each blocker on its own line (in `--json`, the
|
|
637
668
|
error's `blockers`), "nothing was imported; preview again", and for a code
|
|
638
|
-
the kit knows (such as `runtime_draft_iteration_needs_draft_parent`) its hint.
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
669
|
+
the kit knows (such as `runtime_draft_iteration_needs_draft_parent`) its hint.
|
|
670
|
+
`apply` previews into an existing solution and never creates one: when the
|
|
671
|
+
env file, `cavelon.yaml` or `--harness` names a solution the tenant does not
|
|
672
|
+
have, it stops with `solution_not_found` (exit 1) before anything is sent,
|
|
673
|
+
and names the `cavelon harness new <slug>` command that creates the draft
|
|
674
|
+
(with `--name` as `package/harnesses.yaml` names that harness); preview again
|
|
675
|
+
after it. `runtime_bindings` from the env file
|
|
676
|
+
bind the package's runtime requirements. A solution's import leaves the
|
|
677
|
+
package's tenant-wide sections out; `--tenant-wide` sends them
|
|
678
|
+
(`include_tenant_wide`), for every solution of the tenant. An instance that
|
|
679
|
+
does not publish that flag imports them with every solution's package, and
|
|
680
|
+
`apply` says so. A preview that reaches an active solution, deletes, changes
|
|
681
|
+
tenant-wide sections or goes to `env/prod` says to show it to a person first.
|
|
644
682
|
- **`explain <code>`** looks a rule code or API error code up in the instance's
|
|
645
683
|
error catalog (and the codes `validate` reports itself): meaning, fix and docs
|
|
646
684
|
link. For `run_capacity_busy` and `model_endpoint_busy` it adds which limit to
|
package/dist/command.js
CHANGED
|
@@ -5,6 +5,16 @@ export const GLOBAL_OPTIONS = {
|
|
|
5
5
|
tenant: { type: "string", value: "<tenant>", description: "Tenant slug, name or id (overrides CAVELON_TENANT and cavelon.yaml)." },
|
|
6
6
|
help: { type: "boolean", short: "h", description: "Show help for the command." },
|
|
7
7
|
};
|
|
8
|
+
export function optionFlag(name, o) {
|
|
9
|
+
const value = o.type === "string" ? ` ${o.value ?? "<value>"}` : o.mcpToken ? " [<token>]" : "";
|
|
10
|
+
return `${o.short ? `-${o.short}, ` : ""}--${name}${value}`;
|
|
11
|
+
}
|
|
12
|
+
export function optionDescription(name, o) {
|
|
13
|
+
const token = o.type === "boolean" && o.mcpToken
|
|
14
|
+
? ` In a person's terminal the flag alone confirms; run by a coding agent, \`--${name} <token>\` with the token its preview printed (the bare flag only shows the preview there, exit 5).`
|
|
15
|
+
: "";
|
|
16
|
+
return o.description + token + (o.multiple ? " Repeatable." : "");
|
|
17
|
+
}
|
|
8
18
|
export function stringOption(input, name) {
|
|
9
19
|
const value = input.options[name];
|
|
10
20
|
if (Array.isArray(value))
|
package/dist/commands/api.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
1
|
import { promises as fs } from "node:fs";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
import { AGENT_VARIABLES, drivenByAgent } from "../agent-env.js";
|
|
5
|
-
import {
|
|
4
|
+
import { CURSOR_OPTION, intOption, listOption, pageOf, positional, stringOption, } from "../command.js";
|
|
6
5
|
import { CavelonError, ExitCode, usageError, validationError } from "../errors.js";
|
|
7
6
|
import { clip, moreHint, table } from "../format.js";
|
|
8
7
|
import { readAll } from "../io.js";
|
|
9
8
|
import { callOperation, previewRequest } from "../invoke.js";
|
|
10
9
|
import { confinedPath } from "../paths.js";
|
|
11
|
-
import { describeSchema, findOperation, jsonBodySchema, matchedLoosely, operations, schemaTypes, secretFields } from "../openapi.js";
|
|
12
|
-
import { canonical } from "../package-files.js";
|
|
10
|
+
import { describeSchema, findOperation, jsonBodySchema, matchedLoosely, operations, schemaTypes, secretFields, secretPaths } from "../openapi.js";
|
|
13
11
|
import { harnessNotFoundError, lookupHarness } from "../harness-ref.js";
|
|
12
|
+
import { CONFIRM_TOKEN, confirmToken, confirmTokenRequired, confirmWith } from "../confirm-token.js";
|
|
14
13
|
import { cavelonCommand } from "../shell.js";
|
|
15
14
|
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. " +
|
|
16
15
|
"--json alone prints JSON, as on every command.";
|
|
@@ -37,7 +36,6 @@ export function splitJsonBody(args, warn) {
|
|
|
37
36
|
warn?.(JSON_BODY_DEPRECATED);
|
|
38
37
|
return out;
|
|
39
38
|
}
|
|
40
|
-
const CONFIRM_TOKEN = /^[0-9a-f]{12}$/;
|
|
41
39
|
export function splitConfirm(args) {
|
|
42
40
|
const out = [];
|
|
43
41
|
for (let i = 0; i < args.length; i++) {
|
|
@@ -158,7 +156,7 @@ function secretsIn(doc, op, args) {
|
|
|
158
156
|
}
|
|
159
157
|
function secretRefusal(op, fields, driven) {
|
|
160
158
|
const named = fields.map((f) => `"${f}"`).join(", ");
|
|
161
|
-
return new CavelonError(ExitCode.
|
|
159
|
+
return new CavelonError(ExitCode.needsAction, {
|
|
162
160
|
code: "secret_field_for_a_person",
|
|
163
161
|
message: `The request to ${op.alias} sets ${named}, which the instance marks as a secret value (x-cavelon-secret); ` +
|
|
164
162
|
`a person enters secret values, so ${notSentBy(driven)}`,
|
|
@@ -166,12 +164,6 @@ function secretRefusal(op, fields, driven) {
|
|
|
166
164
|
details: { fields },
|
|
167
165
|
});
|
|
168
166
|
}
|
|
169
|
-
function confirmToken(target, request, files) {
|
|
170
|
-
return createHash("sha256")
|
|
171
|
-
.update(canonical({ instance: target.url ?? null, tenant: target.tenant ?? null, request, files }))
|
|
172
|
-
.digest("hex")
|
|
173
|
-
.slice(0, 12);
|
|
174
|
-
}
|
|
175
167
|
function truncate(data, limit) {
|
|
176
168
|
if (limit <= 0)
|
|
177
169
|
return { data };
|
|
@@ -211,8 +203,9 @@ export const api = {
|
|
|
211
203
|
"The body is checked against the operation's schema before it is sent.\n" +
|
|
212
204
|
"As an MCP tool, or run by a coding agent (" +
|
|
213
205
|
AGENT_VARIABLES.filter((v) => v.variable !== "CAVELON_AGENT").map((v) => v.variable).join(", ") +
|
|
214
|
-
"\nor CAVELON_AGENT=1 is set), an operation that changes something returns what it would send and
|
|
215
|
-
"
|
|
206
|
+
"\nor CAVELON_AGENT=1 is set), an operation that changes something returns what it would send and a confirm token,\n" +
|
|
207
|
+
"and sends it only with that token: --confirm <token>, or confirm: \"<token>\" as an MCP tool. A changed request\n" +
|
|
208
|
+
"needs a new preview; confirm: true is refused.\n" +
|
|
216
209
|
"Run by an agent, one the instance marks for a person only (x-cavelon-person-only) is refused, as is a body that\n" +
|
|
217
210
|
"sets a field the instance marks as a secret value (x-cavelon-secret) and a file outside the solution folder. On an\n" +
|
|
218
211
|
"instance that marks no operation, one that changes a secret, creates or revokes a credential or decides an\n" +
|
|
@@ -234,8 +227,8 @@ export const api = {
|
|
|
234
227
|
confirm: {
|
|
235
228
|
type: "string",
|
|
236
229
|
value: "<token>",
|
|
237
|
-
|
|
238
|
-
description: "Send an operation that changes something: run by a coding agent
|
|
230
|
+
mcpToken: true,
|
|
231
|
+
description: "Send an operation that changes something: run by a coding agent or as an MCP tool, the token its preview returned. " +
|
|
239
232
|
"Without it, nothing is sent. A person's terminal sends at once.",
|
|
240
233
|
},
|
|
241
234
|
limit: { type: "string", value: "<n>", description: "Show at most n items of a list response (default 50, 0 for all)." },
|
|
@@ -271,7 +264,7 @@ export const api = {
|
|
|
271
264
|
if (driven) {
|
|
272
265
|
const kept = keptForPerson(op, operations(doc));
|
|
273
266
|
if (kept) {
|
|
274
|
-
throw new CavelonError(ExitCode.
|
|
267
|
+
throw new CavelonError(ExitCode.needsAction, {
|
|
275
268
|
code: "operation_for_a_person",
|
|
276
269
|
message: refusal(op, kept, driven),
|
|
277
270
|
hint: personHint(kept.hint, driven),
|
|
@@ -307,27 +300,26 @@ export const api = {
|
|
|
307
300
|
},
|
|
308
301
|
};
|
|
309
302
|
async function previewUnlessConfirmed(ctx, input, doc, op, args, driven) {
|
|
310
|
-
|
|
311
|
-
|
|
303
|
+
const given = input.options.confirm;
|
|
304
|
+
if (given === true)
|
|
305
|
+
throw confirmTokenRequired("api");
|
|
312
306
|
const request = previewRequest(doc, op, args);
|
|
313
307
|
const files = (args.files ?? []).map((f) => ({ field: f.field, file: path.relative(ctx.io.cwd, f.path) || f.path }));
|
|
314
|
-
const shown = { operation: op.alias, ...request, ...(files.length ? { files } : {}), sent: false };
|
|
315
|
-
if (driven.by === "mcp") {
|
|
316
|
-
return {
|
|
317
|
-
data: { ...shown, confirm: "Call api again with the same arguments and confirm: true." },
|
|
318
|
-
text: `Would send ${request.method} ${request.path}. Nothing was sent.`,
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
308
|
const session = await ctx.session();
|
|
322
|
-
const token = confirmToken({ url: session.url, tenant: session.tenant }, request, files);
|
|
323
|
-
|
|
324
|
-
if (given === token)
|
|
309
|
+
const token = confirmToken({ url: session.url, tenant: session.tenant }, "api", { request, files });
|
|
310
|
+
if (typeof given === "string" && given === token)
|
|
325
311
|
return undefined;
|
|
326
|
-
const stale =
|
|
327
|
-
const
|
|
312
|
+
const stale = typeof given === "string" && given !== "";
|
|
313
|
+
const bare = given === "" && driven.by === "agent";
|
|
314
|
+
const confirm = driven.by === "mcp"
|
|
315
|
+
? confirmWith("api", token)
|
|
316
|
+
: `Show the person this request, then run the same command again with --confirm ${token} to send exactly it.`;
|
|
317
|
+
const shown = { operation: op.alias, ...request, ...(files.length ? { files } : {}), sent: false };
|
|
328
318
|
const lines = [`Would send ${request.method} ${request.path}. Nothing was sent.`];
|
|
329
319
|
if (stale)
|
|
330
|
-
lines.push("The
|
|
320
|
+
lines.push("The confirm token is not this request's: the request changed since its preview, or the token is another one's.");
|
|
321
|
+
if (bare && driven.by === "agent")
|
|
322
|
+
lines.push(`--confirm alone does not send it when a coding agent runs cavelon (${driven.variable} is set).`);
|
|
331
323
|
if (Object.keys(request.query).length)
|
|
332
324
|
lines.push(`Query: ${JSON.stringify(request.query)}`);
|
|
333
325
|
if (Object.keys(request.headers).length)
|
|
@@ -338,9 +330,9 @@ async function previewUnlessConfirmed(ctx, input, doc, op, args, driven) {
|
|
|
338
330
|
lines.push(`File: ${f.field} = ${f.file}`);
|
|
339
331
|
lines.push(confirm);
|
|
340
332
|
return {
|
|
341
|
-
data: { ...shown, confirm_token: token, confirm, ...(stale ? { token_mismatch: true } : {}) },
|
|
333
|
+
data: { ...shown, confirm_token: token, confirm, ...(stale ? { token_mismatch: true } : {}), ...(bare ? { token_required: true } : {}) },
|
|
342
334
|
text: lines.join("\n"),
|
|
343
|
-
...(stale ? { exitCode: ExitCode.conflict } : {}),
|
|
335
|
+
...(stale ? { exitCode: ExitCode.conflict } : bare ? { exitCode: ExitCode.needsAction } : {}),
|
|
344
336
|
};
|
|
345
337
|
}
|
|
346
338
|
export const apiList = {
|
|
@@ -354,7 +346,7 @@ export const apiList = {
|
|
|
354
346
|
search: { type: "string", value: "<text>", description: "Only operations whose name, path or summary contains the text." },
|
|
355
347
|
method: { type: "string", value: "<method>", description: "Only this HTTP method (GET, POST, …)." },
|
|
356
348
|
tags: { type: "boolean", description: "List the tags with their operation counts instead." },
|
|
357
|
-
limit:
|
|
349
|
+
limit: { type: "string", value: "<n>", description: "Return at most n operations (default 50, 0 for all)." },
|
|
358
350
|
cursor: CURSOR_OPTION,
|
|
359
351
|
},
|
|
360
352
|
async run(ctx, input) {
|
|
@@ -381,7 +373,8 @@ export const apiList = {
|
|
|
381
373
|
if (search) {
|
|
382
374
|
ops = ops.filter((o) => [o.operationId, o.path, o.summary ?? ""].some((s) => s.toLowerCase().includes(search)));
|
|
383
375
|
}
|
|
384
|
-
const
|
|
376
|
+
const wanted = intOption(input, "limit", { min: 0, max: 1000, fallback: 50 });
|
|
377
|
+
const limit = wanted === 0 ? Math.max(ops.length, 1) : wanted;
|
|
385
378
|
const page = pageOf(ops.map((o) => ({
|
|
386
379
|
operation: o.alias,
|
|
387
380
|
operation_id: o.operationId,
|
|
@@ -418,12 +411,16 @@ export const apiDescribe = {
|
|
|
418
411
|
const responses = Object.fromEntries(Object.entries(op.responses)
|
|
419
412
|
.filter(([code]) => code.startsWith("2"))
|
|
420
413
|
.map(([code, r]) => [code, describeSchema(doc, r.content?.["application/json"]?.schema)]));
|
|
414
|
+
const kept = keptForPerson(op, operations(doc));
|
|
415
|
+
const secrets = secretPaths(doc, bodySchema);
|
|
421
416
|
const data = {
|
|
422
417
|
operation: op.alias,
|
|
423
418
|
operation_id: op.operationId,
|
|
424
419
|
method: op.method,
|
|
425
420
|
path: op.path,
|
|
426
421
|
read_only: op.readOnly,
|
|
422
|
+
person_only: kept ? { source: kept.source, reason: kept.reason ?? null, hint: kept.hint } : null,
|
|
423
|
+
secret_fields: secrets,
|
|
427
424
|
tags: op.tags,
|
|
428
425
|
summary: op.summary ?? null,
|
|
429
426
|
description: op.description ? clip(op.description, 1500) : null,
|
|
@@ -440,6 +437,13 @@ export const apiDescribe = {
|
|
|
440
437
|
responses,
|
|
441
438
|
};
|
|
442
439
|
const lines = [`${op.method} ${op.path} (${op.readOnly ? "read-only" : "changing"})`, op.summary ?? ""];
|
|
440
|
+
if (kept) {
|
|
441
|
+
lines.push(kept.source === "instance"
|
|
442
|
+
? `For a person only (x-cavelon-person-only${kept.reason ? `: ${kept.reason}` : ""}): an agent does not send it. ${kept.hint}`
|
|
443
|
+
: `For a person: it ${kept.reason}, and this instance marks no operation, so an agent does not send it. ${kept.hint}`);
|
|
444
|
+
}
|
|
445
|
+
if (secrets.length)
|
|
446
|
+
lines.push(`Secret values (x-cavelon-secret): ${secrets.join(", ")}. A person enters them; an agent leaves them out.`);
|
|
443
447
|
if (data.description && data.description !== op.summary)
|
|
444
448
|
lines.push("", data.description);
|
|
445
449
|
if (data.parameters.length) {
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { parseDuration, positional, stringOption } from "../command.js";
|
|
2
|
+
import { confirmation, confirmTokenRequired } from "../confirm-token.js";
|
|
3
|
+
import { named, readDefaultRoute } from "../default-route.js";
|
|
4
|
+
import { CavelonError, ExitCode, usageError } from "../errors.js";
|
|
5
|
+
import { clip } from "../format.js";
|
|
6
|
+
import { harnessNotFoundError, lookupHarness } from "../harness-ref.js";
|
|
7
|
+
import { callStable, workflowOperation } from "../invoke.js";
|
|
8
|
+
import { contextFlags } from "../session.js";
|
|
9
|
+
import { cavelonCommand } from "../shell.js";
|
|
10
|
+
import { MCP_MAX_WAIT_MS } from "./async.js";
|
|
11
|
+
function harnessRef(session, input) {
|
|
12
|
+
const option = stringOption(input, "harness");
|
|
13
|
+
if (option)
|
|
14
|
+
return { ref: option, source: "option" };
|
|
15
|
+
if (session.envFile?.harness)
|
|
16
|
+
return { ref: session.envFile.harness, source: `env/${session.envFile.name}.yaml` };
|
|
17
|
+
if (session.project?.harness)
|
|
18
|
+
return { ref: session.project.harness, source: "cavelon.yaml" };
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
async function findHarness(ctx, ref, source, command) {
|
|
22
|
+
const { harness, candidates } = await lookupHarness(ctx, ref);
|
|
23
|
+
if (harness)
|
|
24
|
+
return harness;
|
|
25
|
+
const flags = contextFlags(await ctx.session());
|
|
26
|
+
throw harnessNotFoundError(ref, candidates, source === "option" ? undefined : source, (slug) => command(slug) + flags, flags);
|
|
27
|
+
}
|
|
28
|
+
const HARNESS_OPTION = {
|
|
29
|
+
type: "string",
|
|
30
|
+
value: "<harness>",
|
|
31
|
+
description: "The solution (harness): its name, slug or id; default: env file, then cavelon.yaml.",
|
|
32
|
+
};
|
|
33
|
+
const ENV_OPTION = { type: "string", value: "<name>", description: "Use env/<name>.yaml: its tenant and solution." };
|
|
34
|
+
const DEFAULT_CHAT_TIMEOUT = "2m";
|
|
35
|
+
function chatError(error, harness) {
|
|
36
|
+
if (!(error instanceof CavelonError) || error.status !== 409)
|
|
37
|
+
return error;
|
|
38
|
+
const hint = !harness
|
|
39
|
+
? "Nothing answers on the tenant's default route yet: name a solution with --harness, or make an active one the default (`cavelon harness default <solution>`)."
|
|
40
|
+
: harness.status !== "active"
|
|
41
|
+
? `${named(harness)} is ${harness.status}: a draft answers only a person's token (as a Playground run), never a tenant API key. Use a personal access token, or activate it first (\`cavelon activate --harness ${harness.slug}\`).`
|
|
42
|
+
: "A session belongs to the solution it started with: leave out --session to start a new one.";
|
|
43
|
+
return new CavelonError(error.exitCode, { code: error.code, status: error.status, message: error.message, hint, docs: error.docs, details: error.details });
|
|
44
|
+
}
|
|
45
|
+
export const chat = {
|
|
46
|
+
name: "chat",
|
|
47
|
+
summary: "Send one message to a solution and print its answer, with the session to continue and the conversation to trace.",
|
|
48
|
+
description: "The tenant's chat and widget answer only with the default route; this names the solution, so an active solution that is\n" +
|
|
49
|
+
"not the default, or a draft, can be tried before it answers anyone. A draft answers a person's token as a Playground run\n" +
|
|
50
|
+
"(counted as testing), never a tenant API key. Without --harness: the env file's or cavelon.yaml's solution, else the\n" +
|
|
51
|
+
"tenant's default route. Each call is one turn; --session continues a conversation. Not streamed: waits for the whole\n" +
|
|
52
|
+
`answer, at most --timeout (default ${DEFAULT_CHAT_TIMEOUT}; ${MCP_MAX_WAIT_MS / 1000} s as an MCP tool).`,
|
|
53
|
+
readOnly: false,
|
|
54
|
+
mcpEffect: "Starts or continues a conversation with the solution and runs its agents (model usage, its tools' actions); changes no configuration.",
|
|
55
|
+
mcpTool: "chat",
|
|
56
|
+
positionals: [{ name: "message", description: "What the user says.", required: true }],
|
|
57
|
+
options: {
|
|
58
|
+
harness: HARNESS_OPTION,
|
|
59
|
+
env: ENV_OPTION,
|
|
60
|
+
session: { type: "string", value: "<session_id>", description: "Continue this conversation (the session_id a previous chat printed)." },
|
|
61
|
+
timeout: { type: "string", value: "<duration>", description: `Wait at most this long for the answer (90s, 5m; default ${DEFAULT_CHAT_TIMEOUT}).` },
|
|
62
|
+
},
|
|
63
|
+
examples: ['cavelon chat "When are you open?" --harness support-faq', 'cavelon chat "And on Saturdays?" --session <session_id>', 'cavelon chat "Hello" --json'],
|
|
64
|
+
async run(ctx, input) {
|
|
65
|
+
const message = positional(input, "message");
|
|
66
|
+
if (!message.trim())
|
|
67
|
+
throw usageError("The message is empty.");
|
|
68
|
+
const raw = stringOption(input, "timeout");
|
|
69
|
+
const timeout = Math.min(parseDuration(raw ?? DEFAULT_CHAT_TIMEOUT), ctx.mode === "mcp" ? MCP_MAX_WAIT_MS : Number.MAX_SAFE_INTEGER);
|
|
70
|
+
const session = await ctx.session();
|
|
71
|
+
const { ref, source } = harnessRef(session, input);
|
|
72
|
+
const harness = ref ? await findHarness(ctx, ref, source, (slug) => cavelonCommand("chat", "<message>", "--harness", slug)) : undefined;
|
|
73
|
+
const body = { message, stream: false };
|
|
74
|
+
if (harness)
|
|
75
|
+
body.harness_id = harness.id;
|
|
76
|
+
const sessionId = stringOption(input, "session");
|
|
77
|
+
if (sessionId)
|
|
78
|
+
body.session_id = sessionId;
|
|
79
|
+
let answer;
|
|
80
|
+
try {
|
|
81
|
+
answer = await callStable(ctx, "POST", "/api/v1/chat", "chatting with a solution", { body, timeoutMs: timeout });
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
throw chatError(error, harness);
|
|
85
|
+
}
|
|
86
|
+
const target = harness ? { id: harness.id, slug: harness.slug, name: harness.name, status: harness.status } : null;
|
|
87
|
+
if (answer.retrieval_warning)
|
|
88
|
+
ctx.warn(answer.retrieval_warning);
|
|
89
|
+
const next = {
|
|
90
|
+
continue: cavelonCommand("chat", "<message>", "--session", answer.session_id),
|
|
91
|
+
trace: cavelonCommand("trace", answer.conversation_id, "--kind", "conversation"),
|
|
92
|
+
};
|
|
93
|
+
const who = harness ? named(harness) : "The default route";
|
|
94
|
+
const directives = answer.ui_directives?.length ? `\n(${answer.ui_directives.length} UI directive${answer.ui_directives.length === 1 ? "" : "s"}, such as a form; --json shows them)` : "";
|
|
95
|
+
const limit = answer.limit_error ? `\nlimit: ${clip(JSON.stringify(answer.limit_error), 300)}` : "";
|
|
96
|
+
return {
|
|
97
|
+
data: { harness: target, ...answer, next },
|
|
98
|
+
text: [
|
|
99
|
+
`${who} answered:`,
|
|
100
|
+
`${answer.response || "(no text)"}${directives}${limit}`,
|
|
101
|
+
"",
|
|
102
|
+
`session: ${answer.session_id} continue with: ${next.continue}`,
|
|
103
|
+
`conversation_id: ${answer.conversation_id} its traces: ${next.trace}`,
|
|
104
|
+
].join("\n"),
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
export const deactivate = {
|
|
109
|
+
name: "deactivate",
|
|
110
|
+
summary: "Take an active solution out of service (status inactive); previews first, --confirm deactivates.",
|
|
111
|
+
description: "An active solution answers live traffic: the conversations, channels and API keys that name it. Deactivating sets its\n" +
|
|
112
|
+
"status to inactive, not back to draft (a draft has not been activated yet; an inactive solution was taken out of\n" +
|
|
113
|
+
"service). It keeps its configuration and answers no live traffic until it is activated again (`cavelon activate`,\n" +
|
|
114
|
+
"through its readiness gate). Without --confirm nothing changes: the preview says what would stop. Show it to a person\n" +
|
|
115
|
+
"and confirm only with their yes. The tenant's default route is refused before anything is sent: make another solution\n" +
|
|
116
|
+
"the default first (`cavelon harness default <solution>`). An instance that publishes no deactivate route is said so; a\n" +
|
|
117
|
+
"person deactivates in the Admin there.",
|
|
118
|
+
readOnly: false,
|
|
119
|
+
destructive: true,
|
|
120
|
+
idempotent: true,
|
|
121
|
+
mcpTool: "deactivate",
|
|
122
|
+
options: {
|
|
123
|
+
harness: HARNESS_OPTION,
|
|
124
|
+
env: ENV_OPTION,
|
|
125
|
+
confirm: { type: "boolean", mcpToken: true, description: "Deactivate it (after a person saw the preview)." },
|
|
126
|
+
},
|
|
127
|
+
examples: ["cavelon deactivate --harness support-faq", "cavelon deactivate --harness support-faq --confirm",
|
|
128
|
+
"cavelon deactivate --harness support-faq --confirm <token>",
|
|
129
|
+
],
|
|
130
|
+
async run(ctx, input) {
|
|
131
|
+
const session = await ctx.session();
|
|
132
|
+
const { ref, source } = harnessRef(session, input);
|
|
133
|
+
if (!ref)
|
|
134
|
+
throw usageError("Which solution?", "Pass --harness <name or slug> (`cavelon harness list` shows them), or set harness in cavelon.yaml or the env file.");
|
|
135
|
+
if (ctx.mode === "mcp" && input.options.confirm === true)
|
|
136
|
+
throw confirmTokenRequired("deactivate");
|
|
137
|
+
await workflowOperation(ctx, "POST", "/api/v1/harnesses/{harness_id}/deactivate", "deactivating solutions").catch((error) => {
|
|
138
|
+
if (error instanceof CavelonError && error.code === "operation_unavailable") {
|
|
139
|
+
throw new CavelonError(ExitCode.failure, {
|
|
140
|
+
code: "operation_unavailable",
|
|
141
|
+
message: "This instance publishes no route to deactivate a solution; nothing was changed.",
|
|
142
|
+
hint: "A person deactivates it in the Admin; the instance may be older than the route (`cavelon status` shows its version).",
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
throw error;
|
|
146
|
+
});
|
|
147
|
+
const harness = await findHarness(ctx, ref, source, (slug) => cavelonCommand("deactivate", "--harness", slug));
|
|
148
|
+
const target = { id: harness.id, slug: harness.slug, name: harness.name, status: harness.status };
|
|
149
|
+
if (harness.status !== "active") {
|
|
150
|
+
return { data: { changed: false, harness: target }, text: `${named(harness)} is ${harness.status}, not active; nothing to deactivate.` };
|
|
151
|
+
}
|
|
152
|
+
const route = await readDefaultRoute(ctx).catch(() => undefined);
|
|
153
|
+
if (route?.current?.id === harness.id) {
|
|
154
|
+
throw new CavelonError(ExitCode.needsAction, {
|
|
155
|
+
code: "default_route_deactivate",
|
|
156
|
+
message: `${named(harness)} is the tenant's default route: the tenant's chat and widget answer with it. Nothing was changed.`,
|
|
157
|
+
hint: "Ask the person which solution should answer there instead, make it the default (`cavelon harness default <solution>`, previews first), then deactivate this one.",
|
|
158
|
+
details: { harness: target },
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
const confirmCommand = cavelonCommand("deactivate", "--harness", harness.slug, "--confirm");
|
|
162
|
+
const gate = await confirmation(ctx, input, "deactivate", { harness: harness.id, status: harness.status });
|
|
163
|
+
if (!gate.confirmed) {
|
|
164
|
+
const known = route?.known ? "" : " (this instance does not say which solution is the default route)";
|
|
165
|
+
return {
|
|
166
|
+
data: { changed: false, harness: target, would: "deactivate", confirm: gate.confirm(confirmCommand), ...gate.fields },
|
|
167
|
+
text: [
|
|
168
|
+
`Deactivating ${named(harness)} sets it inactive and takes it out of live traffic: the conversations, channels and API keys that name it are no longer answered by it until it is activated again${known}.`,
|
|
169
|
+
...(gate.mismatch ? [gate.mismatch] : []),
|
|
170
|
+
`Show this to a person; with their yes: ${gate.confirm(confirmCommand)}`,
|
|
171
|
+
].join("\n"),
|
|
172
|
+
...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const updated = await callStable(ctx, "POST", "/api/v1/harnesses/{harness_id}/deactivate", "deactivating solutions", {
|
|
176
|
+
params: { harness_id: [harness.id] },
|
|
177
|
+
});
|
|
178
|
+
return {
|
|
179
|
+
data: { changed: true, harness: { ...target, status: updated?.status ?? target.status } },
|
|
180
|
+
text: `Deactivated ${named(harness)}; status ${updated?.status ?? "unknown"}. \`cavelon activate --harness ${harness.slug}\` puts it back through its readiness gate.`,
|
|
181
|
+
};
|
|
182
|
+
},
|
|
183
|
+
};
|