@cavelon/cli 0.1.5 → 0.1.6
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 +17 -7
- package/dist/commands/api.js +40 -36
- package/dist/commands/chat.js +177 -0
- package/dist/commands/docs.js +62 -5
- package/dist/commands/fmt.js +5 -2
- package/dist/commands/index.js +3 -0
- package/dist/commands/init.js +38 -26
- package/dist/commands/inventory.js +21 -0
- package/dist/commands/limits-set.js +9 -6
- package/dist/commands/loops.js +15 -9
- package/dist/commands/models.js +9 -6
- package/dist/commands/sandboxes.js +8 -4
- package/dist/commands/schema.js +216 -48
- package/dist/commands/session.js +81 -13
- package/dist/commands/setup.js +22 -6
- package/dist/commands/solution.js +318 -66
- package/dist/commands/tenants.js +37 -6
- package/dist/commands/values.js +18 -9
- package/dist/commands/work.js +110 -23
- package/dist/confirm-token.js +72 -0
- package/dist/harness-ref.js +14 -1
- package/dist/kit-codes.js +7 -1
- package/dist/local-state.js +28 -10
- package/dist/main.js +36 -1
- package/dist/mcp.js +63 -14
- package/dist/openapi.js +30 -0
- package/dist/package-check.js +177 -17
- package/dist/package-files.js +75 -39
- package/dist/package-format.js +81 -8
- package/dist/package-references.js +77 -10
- package/dist/results.js +21 -1
- package/dist/skills/cavelon-authoring/SKILL.md +47 -18
- package/dist/skills/cavelon-loop/SKILL.md +91 -27
- 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
|
@@ -125,9 +125,9 @@ Every command takes `--json` (one JSON document on stdout, errors included),
|
|
|
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
127
|
| `init [--harness] [--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); `--from` writes a package file into it. |
|
|
128
|
-
| `pull [--harness] [--force]` | changing (files) | Write the instance's package into `package/` and `tests/`, the inventory into `.cavelon/`. |
|
|
129
|
-
| `validate [--offline]` | read-only | Check the package files against the cached package schema, their references, unknown fields and models. |
|
|
130
|
-
| `schema [<section>] [--offline]` | read-only | The package schema's sections, or
|
|
128
|
+
| `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`. |
|
|
129
|
+
| `validate [--offline] [--strict]` | read-only | Check the package files against the cached package schema, their references, unknown fields and models; `--strict` fails on warnings. |
|
|
130
|
+
| `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. |
|
|
131
131
|
| `apply [--env] [--harness] [--mode]` | changing | Preview the files against the instance; prints and stores a preview id. |
|
|
132
132
|
| `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
133
|
| `explain <code>` | read-only | Look a code up in the instance's error catalog. |
|
|
@@ -613,14 +613,24 @@ cavelon activate --harness support
|
|
|
613
613
|
one the tenant's full configuration, and splits it along the top-level sections
|
|
614
614
|
of the instance's published package schema, so no entity type is built into
|
|
615
615
|
the binary. A file whose content did not change keeps its bytes, so `git diff`
|
|
616
|
-
shows what changed on the instance;
|
|
617
|
-
|
|
616
|
+
shows what changed on the instance; a field the export spells out and the file
|
|
617
|
+
leaves out (an empty list or object, `null`, a default) is no change. A test
|
|
618
|
+
suite goes back to the file it came from (`.cavelon/pulled-files.json` records
|
|
619
|
+
which). Files of sections the schema does not know are kept byte for byte. A
|
|
620
|
+
solution's pull leaves the tenant-wide sections out of the folder (those the
|
|
621
|
+
schema marks `x-cavelon-scope: tenant`; on an instance that marks none,
|
|
622
|
+
`tenant_settings` and `model_registry`) unless `--tenant-wide`. It refuses when package files have uncommitted changes
|
|
618
623
|
(exit 4) unless `--force`, and writes the tenant's solutions, knowledge bases,
|
|
619
624
|
tools, test suites and sandboxes to `.cavelon/inventory.md`.
|
|
620
625
|
- **`validate`** checks the files against the package schema that `init`, `pull`
|
|
621
626
|
or `apply` cached, and the package version against those the instance accepts.
|
|
622
|
-
It contacts the instance only when nothing is cached
|
|
623
|
-
|
|
627
|
+
It contacts the instance only when nothing is cached, or to read a tenant's
|
|
628
|
+
list (models, skills, tools, knowledge bases, solutions) the package refers to
|
|
629
|
+
and no command has read yet; never with `--offline`, which names the checks it
|
|
630
|
+
skipped instead. Each finding has a file, line, path and code; exit 3 on
|
|
631
|
+
errors, and with `--strict` on warnings too. A reference the import preview
|
|
632
|
+
will block (`package_reference_unknown`, `package_model_unknown`) keeps the
|
|
633
|
+
summary from saying "Valid". A Model
|
|
624
634
|
Registry row's `max_concurrent_requests` needs a `base_url`
|
|
625
635
|
(`model_endpoint_limit_without_base_url`); where the package schema does not
|
|
626
636
|
carry the field, a warning says the import ignores it.
|
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,177 @@
|
|
|
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 { cavelonCommand } from "../shell.js";
|
|
9
|
+
import { MCP_MAX_WAIT_MS } from "./async.js";
|
|
10
|
+
function harnessRef(session, input) {
|
|
11
|
+
const option = stringOption(input, "harness");
|
|
12
|
+
if (option)
|
|
13
|
+
return { ref: option, source: "option" };
|
|
14
|
+
if (session.envFile?.harness)
|
|
15
|
+
return { ref: session.envFile.harness, source: `env/${session.envFile.name}.yaml` };
|
|
16
|
+
if (session.project?.harness)
|
|
17
|
+
return { ref: session.project.harness, source: "cavelon.yaml" };
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
async function findHarness(ctx, ref, source, command) {
|
|
21
|
+
const { harness, candidates } = await lookupHarness(ctx, ref);
|
|
22
|
+
if (!harness)
|
|
23
|
+
throw harnessNotFoundError(ref, candidates, source === "option" ? undefined : source, command);
|
|
24
|
+
return harness;
|
|
25
|
+
}
|
|
26
|
+
const HARNESS_OPTION = {
|
|
27
|
+
type: "string",
|
|
28
|
+
value: "<harness>",
|
|
29
|
+
description: "The solution (harness): its name, slug or id; default: env file, then cavelon.yaml.",
|
|
30
|
+
};
|
|
31
|
+
const ENV_OPTION = { type: "string", value: "<name>", description: "Use env/<name>.yaml: its tenant and solution." };
|
|
32
|
+
const DEFAULT_CHAT_TIMEOUT = "2m";
|
|
33
|
+
function chatError(error, harness) {
|
|
34
|
+
if (!(error instanceof CavelonError) || error.status !== 409)
|
|
35
|
+
return error;
|
|
36
|
+
const hint = !harness
|
|
37
|
+
? "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>`)."
|
|
38
|
+
: harness.status !== "active"
|
|
39
|
+
? `${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}\`).`
|
|
40
|
+
: "A session belongs to the solution it started with: leave out --session to start a new one.";
|
|
41
|
+
return new CavelonError(error.exitCode, { code: error.code, status: error.status, message: error.message, hint, docs: error.docs, details: error.details });
|
|
42
|
+
}
|
|
43
|
+
export const chat = {
|
|
44
|
+
name: "chat",
|
|
45
|
+
summary: "Send one message to a solution and print its answer, with the session to continue and the conversation to trace.",
|
|
46
|
+
description: "The tenant's chat and widget answer only with the default route; this names the solution, so an active solution that is\n" +
|
|
47
|
+
"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" +
|
|
48
|
+
"(counted as testing), never a tenant API key. Without --harness: the env file's or cavelon.yaml's solution, else the\n" +
|
|
49
|
+
"tenant's default route. Each call is one turn; --session continues a conversation. Not streamed: waits for the whole\n" +
|
|
50
|
+
`answer, at most --timeout (default ${DEFAULT_CHAT_TIMEOUT}; ${MCP_MAX_WAIT_MS / 1000} s as an MCP tool).`,
|
|
51
|
+
readOnly: false,
|
|
52
|
+
mcpEffect: "Starts or continues a conversation with the solution and runs its agents (model usage, its tools' actions); changes no configuration.",
|
|
53
|
+
mcpTool: "chat",
|
|
54
|
+
positionals: [{ name: "message", description: "What the user says.", required: true }],
|
|
55
|
+
options: {
|
|
56
|
+
harness: HARNESS_OPTION,
|
|
57
|
+
env: ENV_OPTION,
|
|
58
|
+
session: { type: "string", value: "<session_id>", description: "Continue this conversation (the session_id a previous chat printed)." },
|
|
59
|
+
timeout: { type: "string", value: "<duration>", description: `Wait at most this long for the answer (90s, 5m; default ${DEFAULT_CHAT_TIMEOUT}).` },
|
|
60
|
+
},
|
|
61
|
+
examples: ['cavelon chat "When are you open?" --harness support-faq', 'cavelon chat "And on Saturdays?" --session <session_id>', 'cavelon chat "Hello" --json'],
|
|
62
|
+
async run(ctx, input) {
|
|
63
|
+
const message = positional(input, "message");
|
|
64
|
+
if (!message.trim())
|
|
65
|
+
throw usageError("The message is empty.");
|
|
66
|
+
const raw = stringOption(input, "timeout");
|
|
67
|
+
const timeout = Math.min(parseDuration(raw ?? DEFAULT_CHAT_TIMEOUT), ctx.mode === "mcp" ? MCP_MAX_WAIT_MS : Number.MAX_SAFE_INTEGER);
|
|
68
|
+
const session = await ctx.session();
|
|
69
|
+
const { ref, source } = harnessRef(session, input);
|
|
70
|
+
const harness = ref ? await findHarness(ctx, ref, source, (slug) => cavelonCommand("chat", "<message>", "--harness", slug)) : undefined;
|
|
71
|
+
const body = { message, stream: false };
|
|
72
|
+
if (harness)
|
|
73
|
+
body.harness_id = harness.id;
|
|
74
|
+
const sessionId = stringOption(input, "session");
|
|
75
|
+
if (sessionId)
|
|
76
|
+
body.session_id = sessionId;
|
|
77
|
+
let answer;
|
|
78
|
+
try {
|
|
79
|
+
answer = await callStable(ctx, "POST", "/api/v1/chat", "chatting with a solution", { body, timeoutMs: timeout });
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
throw chatError(error, harness);
|
|
83
|
+
}
|
|
84
|
+
const target = harness ? { id: harness.id, slug: harness.slug, name: harness.name, status: harness.status } : null;
|
|
85
|
+
if (answer.retrieval_warning)
|
|
86
|
+
ctx.warn(answer.retrieval_warning);
|
|
87
|
+
const next = {
|
|
88
|
+
continue: cavelonCommand("chat", "<message>", "--session", answer.session_id),
|
|
89
|
+
trace: cavelonCommand("trace", answer.conversation_id, "--kind", "conversation"),
|
|
90
|
+
};
|
|
91
|
+
const who = harness ? named(harness) : "The default route";
|
|
92
|
+
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)` : "";
|
|
93
|
+
const limit = answer.limit_error ? `\nlimit: ${clip(JSON.stringify(answer.limit_error), 300)}` : "";
|
|
94
|
+
return {
|
|
95
|
+
data: { harness: target, ...answer, next },
|
|
96
|
+
text: [
|
|
97
|
+
`${who} answered:`,
|
|
98
|
+
`${answer.response || "(no text)"}${directives}${limit}`,
|
|
99
|
+
"",
|
|
100
|
+
`session: ${answer.session_id} continue with: ${next.continue}`,
|
|
101
|
+
`conversation_id: ${answer.conversation_id} its traces: ${next.trace}`,
|
|
102
|
+
].join("\n"),
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
export const deactivate = {
|
|
107
|
+
name: "deactivate",
|
|
108
|
+
summary: "Take an active solution out of service; previews first, --confirm deactivates.",
|
|
109
|
+
description: "An active solution answers live traffic: the conversations, channels and API keys that name it. Deactivating stops that\n" +
|
|
110
|
+
"until it is activated again (`cavelon activate`, through its readiness gate). Without --confirm nothing changes: the\n" +
|
|
111
|
+
"preview says what would stop. Show it to a person and confirm only with their yes. The tenant's default route is refused\n" +
|
|
112
|
+
"before anything is sent: make another solution the default first (`cavelon harness default <solution>`). An instance\n" +
|
|
113
|
+
"that publishes no deactivate route is said so; a person deactivates in the Admin there.",
|
|
114
|
+
readOnly: false,
|
|
115
|
+
destructive: true,
|
|
116
|
+
idempotent: true,
|
|
117
|
+
mcpTool: "deactivate",
|
|
118
|
+
options: {
|
|
119
|
+
harness: HARNESS_OPTION,
|
|
120
|
+
env: ENV_OPTION,
|
|
121
|
+
confirm: { type: "boolean", mcpToken: true, description: "Deactivate it (after a person saw the preview)." },
|
|
122
|
+
},
|
|
123
|
+
examples: ["cavelon deactivate --harness support-faq", "cavelon deactivate --harness support-faq --confirm"],
|
|
124
|
+
async run(ctx, input) {
|
|
125
|
+
const session = await ctx.session();
|
|
126
|
+
const { ref, source } = harnessRef(session, input);
|
|
127
|
+
if (!ref)
|
|
128
|
+
throw usageError("Which solution?", "Pass --harness <name or slug> (`cavelon harness list` shows them), or set harness in cavelon.yaml or the env file.");
|
|
129
|
+
if (ctx.mode === "mcp" && input.options.confirm === true)
|
|
130
|
+
throw confirmTokenRequired("deactivate");
|
|
131
|
+
await workflowOperation(ctx, "POST", "/api/v1/harnesses/{harness_id}/deactivate", "deactivating solutions").catch((error) => {
|
|
132
|
+
if (error instanceof CavelonError && error.code === "operation_unavailable") {
|
|
133
|
+
throw new CavelonError(ExitCode.failure, {
|
|
134
|
+
code: "operation_unavailable",
|
|
135
|
+
message: "This instance publishes no route to deactivate a solution; nothing was changed.",
|
|
136
|
+
hint: "A person deactivates it in the Admin; the instance may be older than the route (`cavelon status` shows its version).",
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
throw error;
|
|
140
|
+
});
|
|
141
|
+
const harness = await findHarness(ctx, ref, source, (slug) => cavelonCommand("deactivate", "--harness", slug));
|
|
142
|
+
const target = { id: harness.id, slug: harness.slug, name: harness.name, status: harness.status };
|
|
143
|
+
if (harness.status !== "active") {
|
|
144
|
+
return { data: { changed: false, harness: target }, text: `${named(harness)} is ${harness.status}, not active; nothing to deactivate.` };
|
|
145
|
+
}
|
|
146
|
+
const route = await readDefaultRoute(ctx).catch(() => undefined);
|
|
147
|
+
if (route?.current?.id === harness.id) {
|
|
148
|
+
throw new CavelonError(ExitCode.needsAction, {
|
|
149
|
+
code: "default_route_deactivate",
|
|
150
|
+
message: `${named(harness)} is the tenant's default route: the tenant's chat and widget answer with it. Nothing was changed.`,
|
|
151
|
+
hint: "Ask the person which solution should answer there instead, make it the default (`cavelon harness default <solution>`, previews first), then deactivate this one.",
|
|
152
|
+
details: { harness: target },
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
const confirmCommand = cavelonCommand("deactivate", "--harness", harness.slug, "--confirm");
|
|
156
|
+
const gate = await confirmation(ctx, input, "deactivate", { harness: harness.id, status: harness.status });
|
|
157
|
+
if (!gate.confirmed) {
|
|
158
|
+
const known = route?.known ? "" : " (this instance does not say which solution is the default route)";
|
|
159
|
+
return {
|
|
160
|
+
data: { changed: false, harness: target, would: "deactivate", confirm: gate.confirm(confirmCommand), ...gate.fields },
|
|
161
|
+
text: [
|
|
162
|
+
`Deactivating ${named(harness)} 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}.`,
|
|
163
|
+
...(gate.mismatch ? [gate.mismatch] : []),
|
|
164
|
+
`Show this to a person; with their yes: ${gate.confirm(confirmCommand)}`,
|
|
165
|
+
].join("\n"),
|
|
166
|
+
...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
const updated = await callStable(ctx, "POST", "/api/v1/harnesses/{harness_id}/deactivate", "deactivating solutions", {
|
|
170
|
+
params: { harness_id: [harness.id] },
|
|
171
|
+
});
|
|
172
|
+
return {
|
|
173
|
+
data: { changed: true, harness: { ...target, status: updated?.status ?? target.status } },
|
|
174
|
+
text: `Deactivated ${named(harness)}; status ${updated?.status ?? "unknown"}. \`cavelon activate --harness ${harness.slug}\` puts it back through its readiness gate.`,
|
|
175
|
+
};
|
|
176
|
+
},
|
|
177
|
+
};
|
package/dist/commands/docs.js
CHANGED
|
@@ -137,10 +137,59 @@ const CONCEPT_TERMS = {
|
|
|
137
137
|
schleife: "loop",
|
|
138
138
|
kosten: "cost",
|
|
139
139
|
kapazität: "capacity",
|
|
140
|
+
begrüßung: "greeting",
|
|
141
|
+
begrüssung: "greeting",
|
|
142
|
+
begrüßungen: "greeting",
|
|
143
|
+
begrüßungsnachricht: "greeting",
|
|
144
|
+
begrüßungstext: "greeting",
|
|
145
|
+
willkommensnachricht: "greeting",
|
|
146
|
+
webseite: "website",
|
|
147
|
+
homepage: "website",
|
|
148
|
+
einbinden: "embed",
|
|
149
|
+
binde: "embed",
|
|
150
|
+
einbetten: "embed",
|
|
151
|
+
bette: "embed",
|
|
152
|
+
speichern: "store",
|
|
153
|
+
speichere: "store",
|
|
154
|
+
hinterlegen: "store",
|
|
155
|
+
hinterlege: "store",
|
|
156
|
+
schlüssel: "key",
|
|
157
|
+
passwort: "password",
|
|
158
|
+
zugangsdaten: "credential",
|
|
159
|
+
falsch: "wrong",
|
|
160
|
+
falsche: "wrong",
|
|
161
|
+
falschen: "wrong",
|
|
162
|
+
geantwortet: "answer",
|
|
163
|
+
antwortet: "answer",
|
|
164
|
+
fehler: "error",
|
|
165
|
+
ändern: "change",
|
|
166
|
+
ändere: "change",
|
|
140
167
|
};
|
|
168
|
+
const RELATED_TERMS = {
|
|
169
|
+
greet: ["persona"],
|
|
170
|
+
greeting: ["persona"],
|
|
171
|
+
welcome: ["greeting", "persona"],
|
|
172
|
+
website: ["widget", "embed"],
|
|
173
|
+
site: ["widget", "embed"],
|
|
174
|
+
embed: ["widget"],
|
|
175
|
+
key: ["secret", "credential"],
|
|
176
|
+
password: ["secret", "credential"],
|
|
177
|
+
credential: ["secret"],
|
|
178
|
+
wrong: ["debug", "trace"],
|
|
179
|
+
incorrect: ["debug", "trace"],
|
|
180
|
+
error: ["debug", "trace"],
|
|
181
|
+
debug: ["trace", "playground"],
|
|
182
|
+
};
|
|
183
|
+
const GENERIC_TERMS = new Set(["agent", "cavelon"]);
|
|
184
|
+
const GENERIC_WEIGHT = 0.3;
|
|
185
|
+
const IN_CONTEXT = [
|
|
186
|
+
{ all: ["key"], any: ["tool", "webhook", "integration", "mcp"], add: ["secret"], damp: ["api", "key"] },
|
|
187
|
+
];
|
|
141
188
|
function stem(word) {
|
|
142
|
-
if (word.length > 5 && word.endsWith("ing"))
|
|
143
|
-
|
|
189
|
+
if (word.length > 5 && word.endsWith("ing")) {
|
|
190
|
+
const base = word.slice(0, -3);
|
|
191
|
+
return base.length > 3 && base[base.length - 1] === base[base.length - 2] && !/[aeiouls]/.test(base[base.length - 1]) ? base.slice(0, -1) : base;
|
|
192
|
+
}
|
|
144
193
|
if (word.length > 3 && word.endsWith("s") && !word.endsWith("ss"))
|
|
145
194
|
return word.slice(0, -1);
|
|
146
195
|
return word;
|
|
@@ -166,7 +215,15 @@ export function queryTerms(query) {
|
|
|
166
215
|
}
|
|
167
216
|
for (let i = 0; i + 1 < terms.length; i++)
|
|
168
217
|
phrases.push([terms[i], terms[i + 1]]);
|
|
169
|
-
|
|
218
|
+
const related = terms.flatMap((t) => RELATED_TERMS[t] ?? []).map(stem);
|
|
219
|
+
const damped = [];
|
|
220
|
+
for (const rule of IN_CONTEXT) {
|
|
221
|
+
if (!rule.all.every((t) => terms.includes(t)) || !rule.any.some((t) => terms.includes(t)))
|
|
222
|
+
continue;
|
|
223
|
+
related.push(...rule.add.map(stem));
|
|
224
|
+
damped.push(...rule.damp);
|
|
225
|
+
}
|
|
226
|
+
return { terms: [...new Set([...terms, ...related])], phrases, damped };
|
|
170
227
|
}
|
|
171
228
|
function fieldWords(text) {
|
|
172
229
|
return words(text).map(stem);
|
|
@@ -181,7 +238,7 @@ function hasPhrase(field, phrase) {
|
|
|
181
238
|
const MIN_EVIDENCE = 2;
|
|
182
239
|
const MIN_SHARE_OF_BEST = 0.35;
|
|
183
240
|
export function searchIndex(entries, query) {
|
|
184
|
-
const { terms, phrases } = queryTerms(query);
|
|
241
|
+
const { terms, phrases, damped } = queryTerms(query);
|
|
185
242
|
if (!terms.length)
|
|
186
243
|
return [];
|
|
187
244
|
const fields = entries.map((entry) => ({
|
|
@@ -194,7 +251,7 @@ export function searchIndex(entries, query) {
|
|
|
194
251
|
const weight = new Map();
|
|
195
252
|
for (const term of terms) {
|
|
196
253
|
const pages = fields.filter((f) => f.title.includes(term) || f.page.includes(term) || f.description.includes(term)).length;
|
|
197
|
-
weight.set(term, Math.log(1 + entries.length / (1 + pages)));
|
|
254
|
+
weight.set(term, Math.log(1 + entries.length / (1 + pages)) * (GENERIC_TERMS.has(term) || damped.includes(term) ? GENERIC_WEIGHT : 1));
|
|
198
255
|
}
|
|
199
256
|
const scored = fields
|
|
200
257
|
.map(({ entry, title, page, description, section }) => {
|
package/dist/commands/fmt.js
CHANGED
|
@@ -12,8 +12,11 @@ export const fmt = {
|
|
|
12
12
|
name: "fmt",
|
|
13
13
|
summary: "Bring the package files into the export's form (field order and defaults from the package schema), offline.",
|
|
14
14
|
description: "A file whose value the export would spell differently is rewritten: each field in the schema's order, and each field it\n" +
|
|
15
|
-
"leaves out set to the
|
|
16
|
-
"
|
|
15
|
+
"leaves out set to what the instance gives it, as the export writes it: the schema's default, an empty list or object for\n" +
|
|
16
|
+
"a list or object field without one. The instance applies the same values, so nothing changes in what apply sends but the\n" +
|
|
17
|
+
"spelling, with one exception: an entry of a list that leaves out an `..._order` field (sort_order, display_order,\n" +
|
|
18
|
+
"step_order) gets its position, so the instance keeps the written order instead of ordering entries that all carry the\n" +
|
|
19
|
+
"default its own way (test cases by name). Lists become block lists; the persona file shows every field, the unset\n" +
|
|
17
20
|
"ones as comments. Comments in a rewritten file are not kept, as pull does not keep them. A file already in that form\n" +
|
|
18
21
|
"keeps its bytes, and so do the files of sections the schema does not know. Run it after writing package files by hand\n" +
|
|
19
22
|
"and before `apply`, so the next `pull` shows only what changed on the instance. --check writes nothing and exits 3 when a\n" +
|
package/dist/commands/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { table } from "../format.js";
|
|
2
2
|
import { api, apiDescribe, apiList } from "./api.js";
|
|
3
3
|
import { wait, watch } from "./async.js";
|
|
4
|
+
import { chat, deactivate } from "./chat.js";
|
|
4
5
|
import { docsGet, docsSearch } from "./docs.js";
|
|
5
6
|
import { login, logout, status, use, whoami } from "./session.js";
|
|
6
7
|
import { init } from "./init.js";
|
|
@@ -73,6 +74,8 @@ export const COMMANDS = [
|
|
|
73
74
|
harnessNew,
|
|
74
75
|
harnessClone,
|
|
75
76
|
activate,
|
|
77
|
+
deactivate,
|
|
78
|
+
chat,
|
|
76
79
|
init,
|
|
77
80
|
pull,
|
|
78
81
|
validate,
|