@cavelon/cli 0.1.9 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -10
- package/dist/access.js +194 -0
- package/dist/acting.js +123 -0
- package/dist/agent-env.js +20 -2
- package/dist/branches.js +4 -3
- package/dist/capacity.js +3 -2
- package/dist/code-hints.js +5 -4
- package/dist/command.js +6 -0
- package/dist/commands/api.js +40 -21
- package/dist/commands/async.js +7 -4
- package/dist/commands/chat.js +18 -15
- package/dist/commands/db.js +367 -0
- package/dist/commands/docs.js +87 -9
- package/dist/commands/fmt.js +6 -4
- package/dist/commands/index.js +8 -0
- package/dist/commands/init.js +106 -28
- package/dist/commands/limits-set.js +12 -11
- package/dist/commands/limits.js +4 -3
- package/dist/commands/loops.js +75 -19
- package/dist/commands/models.js +12 -13
- package/dist/commands/sandboxes.js +22 -16
- package/dist/commands/schema.js +6 -5
- package/dist/commands/session.js +134 -37
- package/dist/commands/setup.js +4 -2
- package/dist/commands/solution.js +289 -93
- package/dist/commands/tenants.js +58 -22
- package/dist/commands/values.js +110 -45
- package/dist/commands/work.js +31 -17
- package/dist/confirm-token.js +15 -5
- package/dist/context.js +3 -1
- package/dist/contracts.js +39 -13
- package/dist/database-queries.js +301 -0
- package/dist/default-route.js +1 -1
- package/dist/features.js +2 -1
- package/dist/fsutil.js +14 -0
- package/dist/harness-ref.js +6 -4
- package/dist/http.js +39 -4
- package/dist/invoke.js +7 -2
- package/dist/kit-codes.js +14 -2
- package/dist/limits.js +1 -1
- package/dist/main.js +13 -1
- package/dist/mcp.js +105 -26
- package/dist/openapi.js +5 -2
- package/dist/operations.js +3 -2
- package/dist/package-check.js +29 -4
- package/dist/package-files.js +5 -1
- package/dist/package-format.js +10 -0
- package/dist/preview-report.js +46 -7
- package/dist/principal.js +24 -2
- package/dist/printed.js +182 -0
- package/dist/project.js +2 -1
- package/dist/results.js +1 -1
- package/dist/secret-access.js +42 -0
- package/dist/session.js +39 -19
- package/dist/shell.js +0 -3
- package/dist/skills/cavelon-authoring/SKILL.md +88 -4
- package/dist/skills/cavelon-long-running/SKILL.md +9 -3
- package/dist/skills/cavelon-loop/SKILL.md +81 -19
- package/dist/skills/cavelon-testing/SKILL.md +28 -1
- package/dist/tenant-choice.js +7 -7
- package/dist/trace-view.js +11 -1
- package/dist/update-check.js +2 -2
- package/dist/user-config.js +24 -0
- package/package.json +1 -1
package/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,7 +10,9 @@ 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 {
|
|
13
|
+
import { actingTarget, targetLine } from "../acting.js";
|
|
14
|
+
import { accessFor, operationAccess } from "../access.js";
|
|
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.";
|
|
16
18
|
export function splitJsonBody(args, warn) {
|
|
@@ -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)
|
|
@@ -364,7 +364,7 @@ export const apiList = {
|
|
|
364
364
|
if (tag) {
|
|
365
365
|
ops = ops.filter((o) => o.tags.includes(tag));
|
|
366
366
|
if (ops.length === 0)
|
|
367
|
-
throw usageError(`No operations tagged "${tag}".`, "
|
|
367
|
+
throw usageError(`No operations tagged "${tag}".`, `\`${cavelonCommand("api", "list", "--tags")}\` shows the tags.`);
|
|
368
368
|
}
|
|
369
369
|
const method = stringOption(input, "method")?.toUpperCase();
|
|
370
370
|
if (method)
|
|
@@ -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.",
|
package/dist/commands/async.js
CHANGED
|
@@ -3,6 +3,7 @@ import { stringOption, parseDuration } from "../command.js";
|
|
|
3
3
|
import { CavelonError, ExitCode, usageError } from "../errors.js";
|
|
4
4
|
import { combinedExitCode, describe, exitCodeFor, getOperation, isSettled, TERMINAL, waitFor } from "../operations.js";
|
|
5
5
|
import { failureLines, resultFailure } from "../results.js";
|
|
6
|
+
import { cavelonCommand } from "../printed.js";
|
|
6
7
|
import { readEvents } from "../sse.js";
|
|
7
8
|
export const DEFAULT_WAIT = "90s";
|
|
8
9
|
const MCP_TIMEOUT_MS = 0;
|
|
@@ -42,6 +43,7 @@ export async function waitAndReport(ctx, ids, timeout) {
|
|
|
42
43
|
onChange: progress ? (op) => ctx.io.stderr.write(`${ctx.style.dim(describe(op).split("\n")[0])}\n`) : undefined,
|
|
43
44
|
});
|
|
44
45
|
const pending = operations.filter((o) => !isSettled(o)).map((o) => o.id);
|
|
46
|
+
const resume = cavelonCommand("wait", ...pending);
|
|
45
47
|
const note = capacityNotes(ctx, client);
|
|
46
48
|
const notes = await Promise.all(operations.map(async (op) => withResult(await note(op), await resultFailure(ctx, op))));
|
|
47
49
|
const exitCode = combinedExitCode(operations, notes);
|
|
@@ -54,7 +56,7 @@ export async function waitAndReport(ctx, ids, timeout) {
|
|
|
54
56
|
timed_out: timedOut,
|
|
55
57
|
timeout_ms: timeout,
|
|
56
58
|
waited_ms: waitedMs,
|
|
57
|
-
...(pending.length ? { resume
|
|
59
|
+
...(pending.length ? { resume } : {}),
|
|
58
60
|
...(waits.length ? { capacity_waits: waits } : {}),
|
|
59
61
|
...(refusals.length ? { capacity_refusals: refusals } : {}),
|
|
60
62
|
...(failedResults.length ? { failed_results: failedResults } : {}),
|
|
@@ -63,7 +65,7 @@ export async function waitAndReport(ctx, ids, timeout) {
|
|
|
63
65
|
const body = lines.join("\n");
|
|
64
66
|
const why = waits.length === pending.length ? "Waiting for run capacity" : "Still running";
|
|
65
67
|
if (pending.length) {
|
|
66
|
-
lines.push(timeout === 0 ? `${why}. Wait with:
|
|
68
|
+
lines.push(timeout === 0 ? `${why}. Wait with: ${resume}` : `${why} after the timeout; resume with: ${resume}`);
|
|
67
69
|
}
|
|
68
70
|
return { data, text: lines.join("\n"), exitCode, body, pending, why };
|
|
69
71
|
}
|
|
@@ -97,6 +99,7 @@ export const wait = {
|
|
|
97
99
|
};
|
|
98
100
|
export const watch = {
|
|
99
101
|
name: "watch",
|
|
102
|
+
mcpInstead: "wait",
|
|
100
103
|
summary: "Stream an operation's changes until it ends (server-sent events).",
|
|
101
104
|
description: "Prints one line per change (one JSON object per line with --json). A needs_action state is shown and the stream goes on.",
|
|
102
105
|
readOnly: true,
|
|
@@ -129,7 +132,7 @@ export const watch = {
|
|
|
129
132
|
throw new CavelonError(ExitCode.server, {
|
|
130
133
|
code: "stream_error",
|
|
131
134
|
message: `The event stream of ${id} kept dropping.`,
|
|
132
|
-
hint:
|
|
135
|
+
hint: `\`${cavelonCommand("wait", id)}\` polls instead.`,
|
|
133
136
|
});
|
|
134
137
|
}
|
|
135
138
|
await ctx.io.sleep(Math.min(1000 * 2 ** (failures - 1), 10_000, Math.max(0, deadline - Date.now())));
|
|
@@ -220,7 +223,7 @@ export const watch = {
|
|
|
220
223
|
}
|
|
221
224
|
if (!settled) {
|
|
222
225
|
const wait = (await note(last))?.capacity_wait;
|
|
223
|
-
ctx.io.stderr.write(`Stopped watching; ${id} is still ${last.status}. Resume:
|
|
226
|
+
ctx.io.stderr.write(`Stopped watching; ${id} is still ${last.status}. Resume: ${cavelonCommand("watch", id)}\n${wait ? ` ${wait.note}\n` : ""}`);
|
|
224
227
|
}
|
|
225
228
|
const unsettled = last.status === "needs_action" ? ExitCode.needsAction : ExitCode.timeout;
|
|
226
229
|
return { data: undefined, text: "", exitCode: settled ? exitCodeFor(last, { result_failure: failure }) : unsettled };
|
package/dist/commands/chat.js
CHANGED
|
@@ -5,9 +5,9 @@ import { CavelonError, ExitCode, usageError } from "../errors.js";
|
|
|
5
5
|
import { clip } from "../format.js";
|
|
6
6
|
import { harnessNotFoundError, lookupHarness } from "../harness-ref.js";
|
|
7
7
|
import { callStable, workflowOperation } from "../invoke.js";
|
|
8
|
-
import {
|
|
9
|
-
import { cavelonCommand } from "../shell.js";
|
|
8
|
+
import { cavelonCommand, fill } from "../printed.js";
|
|
10
9
|
import { MCP_MAX_WAIT_MS } from "./async.js";
|
|
10
|
+
import { accessFor, activationStep, mayActivate } from "../access.js";
|
|
11
11
|
function harnessRef(session, input) {
|
|
12
12
|
const option = stringOption(input, "harness");
|
|
13
13
|
if (option)
|
|
@@ -22,8 +22,7 @@ async function findHarness(ctx, ref, source, command) {
|
|
|
22
22
|
const { harness, candidates } = await lookupHarness(ctx, ref);
|
|
23
23
|
if (harness)
|
|
24
24
|
return harness;
|
|
25
|
-
|
|
26
|
-
throw harnessNotFoundError(ref, candidates, source === "option" ? undefined : source, (slug) => command(slug) + flags, flags);
|
|
25
|
+
throw harnessNotFoundError(ref, candidates, source === "option" ? undefined : source, command);
|
|
27
26
|
}
|
|
28
27
|
const HARNESS_OPTION = {
|
|
29
28
|
type: "string",
|
|
@@ -32,13 +31,13 @@ const HARNESS_OPTION = {
|
|
|
32
31
|
};
|
|
33
32
|
const ENV_OPTION = { type: "string", value: "<name>", description: "Use env/<name>.yaml: its tenant and solution." };
|
|
34
33
|
const DEFAULT_CHAT_TIMEOUT = "2m";
|
|
35
|
-
function chatError(error, harness) {
|
|
34
|
+
function chatError(error, harness, may = null) {
|
|
36
35
|
if (!(error instanceof CavelonError) || error.status !== 409)
|
|
37
36
|
return error;
|
|
38
37
|
const hint = !harness
|
|
39
|
-
?
|
|
38
|
+
? `Nothing answers on the tenant's default route yet: name a solution with --harness, or make an active one the default (\`${cavelonCommand("harness", "default", fill("solution"))}\`).`
|
|
40
39
|
: 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 (
|
|
40
|
+
? `${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 (${activationStep(may, cavelonCommand("activate", "--harness", harness.slug))}).`
|
|
42
41
|
: "A session belongs to the solution it started with: leave out --session to start a new one.";
|
|
43
42
|
return new CavelonError(error.exitCode, { code: error.code, status: error.status, message: error.message, hint, docs: error.docs, details: error.details });
|
|
44
43
|
}
|
|
@@ -53,6 +52,7 @@ export const chat = {
|
|
|
53
52
|
readOnly: false,
|
|
54
53
|
mcpEffect: "Starts or continues a conversation with the solution and runs its agents (model usage, its tools' actions); changes no configuration.",
|
|
55
54
|
mcpTool: "chat",
|
|
55
|
+
operations: ["POST /api/v1/chat"],
|
|
56
56
|
positionals: [{ name: "message", description: "What the user says.", required: true }],
|
|
57
57
|
options: {
|
|
58
58
|
harness: HARNESS_OPTION,
|
|
@@ -69,7 +69,7 @@ export const chat = {
|
|
|
69
69
|
const timeout = Math.min(parseDuration(raw ?? DEFAULT_CHAT_TIMEOUT), ctx.mode === "mcp" ? MCP_MAX_WAIT_MS : Number.MAX_SAFE_INTEGER);
|
|
70
70
|
const session = await ctx.session();
|
|
71
71
|
const { ref, source } = harnessRef(session, input);
|
|
72
|
-
const harness = ref ? await findHarness(ctx, ref, source, (slug) => cavelonCommand("chat", "
|
|
72
|
+
const harness = ref ? await findHarness(ctx, ref, source, (slug) => cavelonCommand("chat", fill("message"), "--harness", slug)) : undefined;
|
|
73
73
|
const body = { message, stream: false };
|
|
74
74
|
if (harness)
|
|
75
75
|
body.harness_id = harness.id;
|
|
@@ -81,13 +81,13 @@ export const chat = {
|
|
|
81
81
|
answer = await callStable(ctx, "POST", "/api/v1/chat", "chatting with a solution", { body, timeoutMs: timeout });
|
|
82
82
|
}
|
|
83
83
|
catch (error) {
|
|
84
|
-
throw chatError(error, harness);
|
|
84
|
+
throw chatError(error, harness, error instanceof CavelonError && error.status === 409 ? mayActivate(await accessFor(await ctx.client())) : null);
|
|
85
85
|
}
|
|
86
86
|
const target = harness ? { id: harness.id, slug: harness.slug, name: harness.name, status: harness.status } : null;
|
|
87
87
|
if (answer.retrieval_warning)
|
|
88
88
|
ctx.warn(answer.retrieval_warning);
|
|
89
89
|
const next = {
|
|
90
|
-
continue: cavelonCommand("chat", "
|
|
90
|
+
continue: cavelonCommand("chat", fill("message"), "--session", answer.session_id),
|
|
91
91
|
trace: cavelonCommand("trace", answer.conversation_id, "--kind", "conversation"),
|
|
92
92
|
};
|
|
93
93
|
const who = harness ? named(harness) : "The default route";
|
|
@@ -119,6 +119,7 @@ export const deactivate = {
|
|
|
119
119
|
destructive: true,
|
|
120
120
|
idempotent: true,
|
|
121
121
|
mcpTool: "deactivate",
|
|
122
|
+
operations: ["POST /api/v1/harnesses/{harness_id}/deactivate"],
|
|
122
123
|
options: {
|
|
123
124
|
harness: HARNESS_OPTION,
|
|
124
125
|
env: ENV_OPTION,
|
|
@@ -131,7 +132,7 @@ export const deactivate = {
|
|
|
131
132
|
const session = await ctx.session();
|
|
132
133
|
const { ref, source } = harnessRef(session, input);
|
|
133
134
|
if (!ref)
|
|
134
|
-
throw usageError("Which solution?",
|
|
135
|
+
throw usageError("Which solution?", `Pass --harness <name or slug> (\`${cavelonCommand("harness", "list")}\` shows them), or set harness in cavelon.yaml or the env file.`);
|
|
135
136
|
if (ctx.mode === "mcp" && input.options.confirm === true)
|
|
136
137
|
throw confirmTokenRequired("deactivate");
|
|
137
138
|
await workflowOperation(ctx, "POST", "/api/v1/harnesses/{harness_id}/deactivate", "deactivating solutions").catch((error) => {
|
|
@@ -139,7 +140,7 @@ export const deactivate = {
|
|
|
139
140
|
throw new CavelonError(ExitCode.failure, {
|
|
140
141
|
code: "operation_unavailable",
|
|
141
142
|
message: "This instance publishes no route to deactivate a solution; nothing was changed.",
|
|
142
|
-
hint:
|
|
143
|
+
hint: `A person deactivates it in the Admin; the instance may be older than the route (\`${cavelonCommand("status")}\` shows its version).`,
|
|
143
144
|
});
|
|
144
145
|
}
|
|
145
146
|
throw error;
|
|
@@ -154,7 +155,7 @@ export const deactivate = {
|
|
|
154
155
|
throw new CavelonError(ExitCode.needsAction, {
|
|
155
156
|
code: "default_route_deactivate",
|
|
156
157
|
message: `${named(harness)} is the tenant's default route: the tenant's chat and widget answer with it. Nothing was changed.`,
|
|
157
|
-
hint:
|
|
158
|
+
hint: `Ask the person which solution should answer there instead, make it the default (\`${cavelonCommand("harness", "default", fill("solution"))}\`, previews first), then deactivate this one.`,
|
|
158
159
|
details: { harness: target },
|
|
159
160
|
});
|
|
160
161
|
}
|
|
@@ -166,7 +167,7 @@ export const deactivate = {
|
|
|
166
167
|
data: { changed: false, harness: target, would: "deactivate", confirm: gate.confirm(confirmCommand), ...gate.fields },
|
|
167
168
|
text: [
|
|
168
169
|
`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
|
+
gate.where, ...(gate.mismatch ? [gate.mismatch] : []),
|
|
170
171
|
`Show this to a person; with their yes: ${gate.confirm(confirmCommand)}`,
|
|
171
172
|
].join("\n"),
|
|
172
173
|
...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
|
|
@@ -177,7 +178,9 @@ export const deactivate = {
|
|
|
177
178
|
});
|
|
178
179
|
return {
|
|
179
180
|
data: { changed: true, harness: { ...target, status: updated?.status ?? target.status } },
|
|
180
|
-
text: `Deactivated ${named(harness)}; status ${updated?.status ?? "unknown"}.
|
|
181
|
+
text: `Deactivated ${named(harness)}; status ${updated?.status ?? "unknown"}. ${mayActivate(await accessFor(await ctx.client())) === false
|
|
182
|
+
? "A person who may activate puts it back through its readiness gate, in the Admin; this credential may not activate."
|
|
183
|
+
: `\`${cavelonCommand("activate", "--harness", harness.slug)}\` puts it back through its readiness gate.`}`,
|
|
181
184
|
};
|
|
182
185
|
},
|
|
183
186
|
};
|