@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/dist/commands/docs.js
CHANGED
|
@@ -61,12 +61,15 @@ export async function listedPages(ctx, pages) {
|
|
|
61
61
|
return [];
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
const
|
|
65
|
-
"that the their them then there these this those to use using was we what when where which who why will with would you your " +
|
|
66
|
-
"aber alle als am an auch auf aus bei bin bis da damit dann das dass dem den der des die dies diese diesem diesen dieser " +
|
|
64
|
+
const GERMAN_STOP_WORDS = new Set(("aber alle als am an auch auf aus bei bin bis da damit dann das dass dem den der des die dies diese diesem diesen dieser " +
|
|
67
65
|
"doch du ein eine einem einen einer eines er es für geht gibt hat habe haben ich ihr im in ist ja kann kannst können man " +
|
|
68
66
|
"mein meine meinem meinen meiner mich mir mit muss müssen nach nicht noch nur ob oder sich sie sind so soll um und uns " +
|
|
69
67
|
"unser unsere vom von vor war was welche welcher welches wenn wer werden wie wird wo zu zum zur").split(" "));
|
|
68
|
+
const STOP_WORDS = new Set([
|
|
69
|
+
...("a an and are as at be by can could do does for from get got have how i in into is it its me my of on or our should so " +
|
|
70
|
+
"that the their them then there these this those to use using was we what when where which who why will with would you your").split(" "),
|
|
71
|
+
...GERMAN_STOP_WORDS,
|
|
72
|
+
]);
|
|
70
73
|
const CONCEPT_TERMS = {
|
|
71
74
|
bot: "solution",
|
|
72
75
|
bots: "solution",
|
|
@@ -137,10 +140,65 @@ const CONCEPT_TERMS = {
|
|
|
137
140
|
schleife: "loop",
|
|
138
141
|
kosten: "cost",
|
|
139
142
|
kapazität: "capacity",
|
|
143
|
+
begrüßung: "greeting",
|
|
144
|
+
begrüssung: "greeting",
|
|
145
|
+
begrüßungen: "greeting",
|
|
146
|
+
begrüßungsnachricht: "greeting",
|
|
147
|
+
begrüßungstext: "greeting",
|
|
148
|
+
willkommensnachricht: "greeting",
|
|
149
|
+
webseite: "website",
|
|
150
|
+
homepage: "website",
|
|
151
|
+
einbinden: "embed",
|
|
152
|
+
binde: "embed",
|
|
153
|
+
einbetten: "embed",
|
|
154
|
+
bette: "embed",
|
|
155
|
+
speichern: "store",
|
|
156
|
+
speichere: "store",
|
|
157
|
+
hinterlegen: "store",
|
|
158
|
+
hinterlege: "store",
|
|
159
|
+
schlüssel: "key",
|
|
160
|
+
passwort: "password",
|
|
161
|
+
zugangsdaten: "credential",
|
|
162
|
+
falsch: "wrong",
|
|
163
|
+
falsche: "wrong",
|
|
164
|
+
falschen: "wrong",
|
|
165
|
+
geantwortet: "answer",
|
|
166
|
+
antwortet: "answer",
|
|
167
|
+
fehler: "error",
|
|
168
|
+
ändern: "change",
|
|
169
|
+
ändere: "change",
|
|
140
170
|
};
|
|
171
|
+
const RELATED_TERMS = {
|
|
172
|
+
greet: ["persona"],
|
|
173
|
+
greeting: ["persona"],
|
|
174
|
+
welcome: ["greeting", "persona"],
|
|
175
|
+
website: ["widget", "embed"],
|
|
176
|
+
site: ["widget", "embed"],
|
|
177
|
+
embed: ["widget"],
|
|
178
|
+
key: ["secret", "credential"],
|
|
179
|
+
password: ["secret", "credential"],
|
|
180
|
+
credential: ["secret"],
|
|
181
|
+
wrong: ["debug", "trace"],
|
|
182
|
+
incorrect: ["debug", "trace"],
|
|
183
|
+
error: ["debug", "trace"],
|
|
184
|
+
debug: ["trace", "playground"],
|
|
185
|
+
handoff: ["agent", "graph"],
|
|
186
|
+
consult: ["agent", "graph"],
|
|
187
|
+
};
|
|
188
|
+
const ENGLISH_CONCEPT_WORDS = new Set(["bot", "bots", "chatbot", "agent", "tests", "standard", "persona", "homepage"]);
|
|
189
|
+
function soundsGerman(query) {
|
|
190
|
+
return words(query).some((w) => GERMAN_STOP_WORDS.has(w) || /[äöüß]/.test(w) || (Object.hasOwn(CONCEPT_TERMS, w) && !ENGLISH_CONCEPT_WORDS.has(w)));
|
|
191
|
+
}
|
|
192
|
+
const GENERIC_TERMS = new Set(["agent", "cavelon"]);
|
|
193
|
+
const GENERIC_WEIGHT = 0.3;
|
|
194
|
+
const IN_CONTEXT = [
|
|
195
|
+
{ all: ["key"], any: ["tool", "webhook", "integration", "mcp"], add: ["secret"], damp: ["api", "key"] },
|
|
196
|
+
];
|
|
141
197
|
function stem(word) {
|
|
142
|
-
if (word.length > 5 && word.endsWith("ing"))
|
|
143
|
-
|
|
198
|
+
if (word.length > 5 && word.endsWith("ing")) {
|
|
199
|
+
const base = word.slice(0, -3);
|
|
200
|
+
return base.length > 3 && base[base.length - 1] === base[base.length - 2] && !/[aeiouls]/.test(base[base.length - 1]) ? base.slice(0, -1) : base;
|
|
201
|
+
}
|
|
144
202
|
if (word.length > 3 && word.endsWith("s") && !word.endsWith("ss"))
|
|
145
203
|
return word.slice(0, -1);
|
|
146
204
|
return word;
|
|
@@ -166,7 +224,15 @@ export function queryTerms(query) {
|
|
|
166
224
|
}
|
|
167
225
|
for (let i = 0; i + 1 < terms.length; i++)
|
|
168
226
|
phrases.push([terms[i], terms[i + 1]]);
|
|
169
|
-
|
|
227
|
+
const related = terms.flatMap((t) => RELATED_TERMS[t] ?? []).map(stem);
|
|
228
|
+
const damped = [];
|
|
229
|
+
for (const rule of IN_CONTEXT) {
|
|
230
|
+
if (!rule.all.every((t) => terms.includes(t)) || !rule.any.some((t) => terms.includes(t)))
|
|
231
|
+
continue;
|
|
232
|
+
related.push(...rule.add.map(stem));
|
|
233
|
+
damped.push(...rule.damp);
|
|
234
|
+
}
|
|
235
|
+
return { terms: [...new Set([...terms, ...related])], phrases, damped };
|
|
170
236
|
}
|
|
171
237
|
function fieldWords(text) {
|
|
172
238
|
return words(text).map(stem);
|
|
@@ -181,7 +247,7 @@ function hasPhrase(field, phrase) {
|
|
|
181
247
|
const MIN_EVIDENCE = 2;
|
|
182
248
|
const MIN_SHARE_OF_BEST = 0.35;
|
|
183
249
|
export function searchIndex(entries, query) {
|
|
184
|
-
const { terms, phrases } = queryTerms(query);
|
|
250
|
+
const { terms, phrases, damped } = queryTerms(query);
|
|
185
251
|
if (!terms.length)
|
|
186
252
|
return [];
|
|
187
253
|
const fields = entries.map((entry) => ({
|
|
@@ -194,7 +260,7 @@ export function searchIndex(entries, query) {
|
|
|
194
260
|
const weight = new Map();
|
|
195
261
|
for (const term of terms) {
|
|
196
262
|
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)));
|
|
263
|
+
weight.set(term, Math.log(1 + entries.length / (1 + pages)) * (GENERIC_TERMS.has(term) || damped.includes(term) ? GENERIC_WEIGHT : 1));
|
|
198
264
|
}
|
|
199
265
|
const scored = fields
|
|
200
266
|
.map(({ entry, title, page, description, section }) => {
|
|
@@ -248,7 +314,9 @@ export const docsSearch = {
|
|
|
248
314
|
const { terms } = queryTerms(query);
|
|
249
315
|
const items = hits.slice(0, limit).map(({ page, title, description, section }) => ({ page, title, section, description }));
|
|
250
316
|
const none = `No page matches "${query}"${terms.length ? ` (looked for: ${terms.join(", ")})` : " (it has only stop words)"}. ` +
|
|
251
|
-
|
|
317
|
+
(soundsGerman(query)
|
|
318
|
+
? `The docs are in English: try English words for the concept (knowledge base, test, trigger, default), `
|
|
319
|
+
: `No page's title or summary uses them: try another word for the concept, or a broader one, `) +
|
|
252
320
|
`or read the list of all ${entries.length} pages with: ${cavelonCommand("docs", "get", INDEX_REF)}`;
|
|
253
321
|
return {
|
|
254
322
|
data: { query, terms, items, total: hits.length, ...(items.length ? {} : { hint: none }) },
|
package/dist/commands/fmt.js
CHANGED
|
@@ -1,20 +1,45 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { Lexer } from "yaml";
|
|
2
3
|
import { boolOption } from "../command.js";
|
|
3
4
|
import { CavelonError, ExitCode } from "../errors.js";
|
|
4
5
|
import { readTextFile, writeFileAtomic } from "../fsutil.js";
|
|
6
|
+
import { uncommitted } from "../git.js";
|
|
5
7
|
import { fileDigest, fileDigests, readPulledFiles, rememberAppliedFiles } from "../local-state.js";
|
|
6
8
|
import { packageVersionOf } from "../package-check.js";
|
|
7
9
|
import { canonical, contentPath, readPackage } from "../package-files.js";
|
|
8
10
|
import { exportForm, sectionContent, toYaml } from "../package-format.js";
|
|
9
11
|
import { requireInstance } from "../session.js";
|
|
10
12
|
import { requireSolution, schemaFor } from "./solution.js";
|
|
13
|
+
function comments(text) {
|
|
14
|
+
const found = [];
|
|
15
|
+
for (const token of new Lexer().lex(text))
|
|
16
|
+
if (token.startsWith("#"))
|
|
17
|
+
found.push(token.trim());
|
|
18
|
+
return found;
|
|
19
|
+
}
|
|
20
|
+
function droppedComments(before, after) {
|
|
21
|
+
const left = comments(after);
|
|
22
|
+
let dropped = 0;
|
|
23
|
+
for (const comment of comments(before)) {
|
|
24
|
+
const at = left.indexOf(comment);
|
|
25
|
+
if (at >= 0)
|
|
26
|
+
left.splice(at, 1);
|
|
27
|
+
else
|
|
28
|
+
dropped++;
|
|
29
|
+
}
|
|
30
|
+
return dropped;
|
|
31
|
+
}
|
|
11
32
|
export const fmt = {
|
|
12
33
|
name: "fmt",
|
|
13
34
|
summary: "Bring the package files into the export's form (field order and defaults from the package schema), offline.",
|
|
14
35
|
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
|
-
"
|
|
17
|
-
"
|
|
36
|
+
"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" +
|
|
37
|
+
"a list or object field without one. The instance applies the same values, so nothing changes in what apply sends but the\n" +
|
|
38
|
+
"spelling, with one exception: an entry of a list that leaves out an `..._order` field (sort_order, display_order,\n" +
|
|
39
|
+
"step_order) gets its position, so the instance keeps the written order instead of ordering entries that all carry the\n" +
|
|
40
|
+
"default its own way (test cases by name). Lists become block lists; the persona file shows every field, the unset\n" +
|
|
41
|
+
"ones as comments. Comments in a rewritten file are not kept, as pull does not keep them: fmt names each file whose\n" +
|
|
42
|
+
"comments it drops (with --check, would drop), so keep notes you need elsewhere first. A file already in that form\n" +
|
|
18
43
|
"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
44
|
"and before `apply`, so the next `pull` shows only what changed on the instance. --check writes nothing and exits 3 when a\n" +
|
|
20
45
|
"file would change. Uses the cached package schema (as validate does); --offline never contacts the instance.",
|
|
@@ -75,6 +100,18 @@ export const fmt = {
|
|
|
75
100
|
else
|
|
76
101
|
changes.push({ file: source.file, content: sectionContent(section, formed, schema, /\.json$/i.test(source.file)) });
|
|
77
102
|
}
|
|
103
|
+
const dropped = [];
|
|
104
|
+
for (const change of changes) {
|
|
105
|
+
if (/\.json$/i.test(change.file))
|
|
106
|
+
continue;
|
|
107
|
+
const target = await contentPath(project.root, path.join(project.root, change.file));
|
|
108
|
+
const before = target === undefined ? undefined : await readTextFile(target);
|
|
109
|
+
const count = before === undefined ? 0 : droppedComments(before, change.content);
|
|
110
|
+
if (count)
|
|
111
|
+
dropped.push({ file: change.file, comments: count });
|
|
112
|
+
}
|
|
113
|
+
const dirty = !check && changes.length ? await uncommitted(project.root, changes.map((c) => c.file)) : undefined;
|
|
114
|
+
const restorable = (file) => dirty !== undefined && !dirty.includes(file);
|
|
78
115
|
const written = [];
|
|
79
116
|
if (!check && changes.length) {
|
|
80
117
|
const known = await readPulledFiles(project.root);
|
|
@@ -95,22 +132,40 @@ export const fmt = {
|
|
|
95
132
|
await rememberAppliedFiles(project.root, await fileDigests(project.root, wasKnown));
|
|
96
133
|
}
|
|
97
134
|
const files = changes.map((c) => c.file).sort((a, b) => a.localeCompare(b, "en"));
|
|
98
|
-
const
|
|
135
|
+
const lost = check ? dropped : dropped.filter((d) => written.includes(d.file));
|
|
136
|
+
const data = { check, changed: files, written: written.sort((a, b) => a.localeCompare(b, "en")), unchanged, comments_dropped: lost };
|
|
137
|
+
const commentList = lost.map((d) => `${d.file} (${d.comments})`).join(", ");
|
|
99
138
|
if (check) {
|
|
100
139
|
return {
|
|
101
140
|
data,
|
|
102
141
|
text: files.length
|
|
103
|
-
? [
|
|
142
|
+
? [
|
|
143
|
+
...files.map((f) => `would format ${f}`),
|
|
144
|
+
`${files.length} file${files.length === 1 ? "" : "s"} not in the export's form; run \`cavelon fmt\`.`,
|
|
145
|
+
...(lost.length ? [`fmt would drop the comments of ${commentList}; keep notes you need elsewhere first.`] : []),
|
|
146
|
+
].join("\n")
|
|
104
147
|
: `All ${unchanged} package files are in the export's form.`,
|
|
105
148
|
exitCode: files.length ? ExitCode.validation : ExitCode.ok,
|
|
106
149
|
};
|
|
107
150
|
}
|
|
151
|
+
if (lost.length) {
|
|
152
|
+
const back = lost.filter((d) => restorable(d.file)).map((d) => d.file);
|
|
153
|
+
ctx.warn(`fmt dropped the comments of ${commentList}; the export's form has none, as pull keeps none. ` +
|
|
154
|
+
(back.length === lost.length
|
|
155
|
+
? "They were committed: git diff shows them, and git restore brings a file back."
|
|
156
|
+
: back.length
|
|
157
|
+
? `git restore brings back ${back.join(", ")}; the others were not committed.`
|
|
158
|
+
: dirty === undefined
|
|
159
|
+
? "The folder is not in a git repository, so nothing brings them back."
|
|
160
|
+
: "The files were not committed, so git cannot bring the comments back."));
|
|
161
|
+
}
|
|
162
|
+
const diffable = written.some(restorable);
|
|
108
163
|
return {
|
|
109
164
|
data,
|
|
110
165
|
text: [
|
|
111
166
|
...written.map((f) => `formatted ${f}`),
|
|
112
167
|
`${written.length} file${written.length === 1 ? "" : "s"} formatted, ${unchanged} already in the export's form.`,
|
|
113
|
-
...(written.length ? ["Check it: cavelon validate; then git diff shows
|
|
168
|
+
...(written.length ? [diffable ? "Check it: cavelon validate; then git diff shows what changed." : "Check it: cavelon validate."] : []),
|
|
114
169
|
].join("\n"),
|
|
115
170
|
};
|
|
116
171
|
},
|
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,
|
package/dist/commands/init.js
CHANGED
|
@@ -16,8 +16,8 @@ import { readPrincipal, readTenantless } from "../principal.js";
|
|
|
16
16
|
import { ENV_DIR, parseProject, PROJECT_FILE } from "../project.js";
|
|
17
17
|
import { canAsk, readLine } from "../prompt.js";
|
|
18
18
|
import { pick } from "../choose.js";
|
|
19
|
-
import { harnessNotFoundError, listHarnesses, lookupHarness } from "../harness-ref.js";
|
|
20
|
-
import { lookupTenantId, requireInstance, requireToken, tenantRequiredError } from "../session.js";
|
|
19
|
+
import { harnessNotFoundError, listHarnesses, lookupHarness, SLUG, slugFromName } from "../harness-ref.js";
|
|
20
|
+
import { contextFlags, isUuid, lookupTenantId, requireInstance, requireToken, tenantRequiredError } from "../session.js";
|
|
21
21
|
import { cavelonCommand } from "../shell.js";
|
|
22
22
|
import { chooseTenant, listsTenants, noTenantError, tenantOpenError, tenantRef, tenantTitle } from "../tenant-choice.js";
|
|
23
23
|
import { createHarness } from "./tenants.js";
|
|
@@ -242,19 +242,6 @@ function solutionYaml(values, tenantNote) {
|
|
|
242
242
|
function commentText(text) {
|
|
243
243
|
return [...text].map((c) => (c < " " || c === "\u007f" ? " " : c)).join("").trim();
|
|
244
244
|
}
|
|
245
|
-
export function slugFromName(name) {
|
|
246
|
-
const plain = name.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
|
|
247
|
-
let slug = plain.replace(/[^a-z0-9]+/g, "-");
|
|
248
|
-
while (slug.startsWith("-"))
|
|
249
|
-
slug = slug.slice(1);
|
|
250
|
-
while (slug.endsWith("-"))
|
|
251
|
-
slug = slug.slice(0, -1);
|
|
252
|
-
slug = slug.slice(0, 60);
|
|
253
|
-
while (slug.endsWith("-"))
|
|
254
|
-
slug = slug.slice(0, -1);
|
|
255
|
-
return slug;
|
|
256
|
-
}
|
|
257
|
-
const SLUG = /^[a-z0-9][a-z0-9-]*$/;
|
|
258
245
|
async function initTenant(ctx, session) {
|
|
259
246
|
if (session.tokenKind === "api_key")
|
|
260
247
|
return session.tenant ? { ref: session.tenant } : undefined;
|
|
@@ -292,7 +279,8 @@ async function initTenant(ctx, session) {
|
|
|
292
279
|
const listed = reach?.tenants.find((t) => t.id === placed);
|
|
293
280
|
return { ref: listed?.slug ?? placed, id: placed, name: listed?.name ?? undefined, slug: listed?.slug ?? undefined };
|
|
294
281
|
}
|
|
295
|
-
async function initHarness(ctx, given) {
|
|
282
|
+
async function initHarness(ctx, given, displayName = given, choice = { flags: "" }) {
|
|
283
|
+
const { flags } = choice;
|
|
296
284
|
if (given) {
|
|
297
285
|
let lookup;
|
|
298
286
|
try {
|
|
@@ -302,11 +290,38 @@ async function initHarness(ctx, given) {
|
|
|
302
290
|
ctx.warn(`Could not check solution "${given}" on the instance: ${error instanceof Error ? error.message : String(error)}`);
|
|
303
291
|
return { slug: given };
|
|
304
292
|
}
|
|
293
|
+
if (lookup.harness && choice.create) {
|
|
294
|
+
const found = lookup.harness;
|
|
295
|
+
throw new CavelonError(ExitCode.failure, {
|
|
296
|
+
code: "solution_exists",
|
|
297
|
+
message: `Solution ${found.name} (${found.slug}) is already in this tenant; --new creates only a solution it does not have.`,
|
|
298
|
+
hint: `For this folder to hold that solution: ${cavelonCommand("init", "--harness", found.slug)}${flags}. For a new one, give --new another name.`,
|
|
299
|
+
details: { harness: { id: found.id, slug: found.slug, name: found.name } },
|
|
300
|
+
});
|
|
301
|
+
}
|
|
305
302
|
if (lookup.harness)
|
|
306
303
|
return { slug: lookup.harness.slug };
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
304
|
+
const slug = SLUG.test(given) ? given : slugFromName(given);
|
|
305
|
+
const title = (displayName ?? given).trim().slice(0, 255) || slug;
|
|
306
|
+
const create = cavelonCommand("harness", "new", slug, ...(title !== slug ? ["--name", title] : []));
|
|
307
|
+
const notFound = () => harnessNotFoundError(given, lookup.candidates, undefined, (s) => cavelonCommand("init", "--harness", s) + flags, flags);
|
|
308
|
+
if (!slug || isUuid(given))
|
|
309
|
+
throw notFound();
|
|
310
|
+
if (lookup.candidates.length && !choice.create) {
|
|
311
|
+
const error = notFound();
|
|
312
|
+
const createNew = cavelonCommand("init", "--harness", title, "--new") + flags;
|
|
313
|
+
throw new CavelonError(error.exitCode, {
|
|
314
|
+
code: error.code,
|
|
315
|
+
message: error.message,
|
|
316
|
+
hint: `${error.hint} For a new solution of that name: ${createNew}.`,
|
|
317
|
+
details: { ...error.details, create: createNew },
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
if (ctx.mode === "mcp")
|
|
321
|
+
return { slug, missing: true, create };
|
|
322
|
+
const created = await createHarness(ctx, { slug, name: title });
|
|
323
|
+
ctx.io.stderr.write(`Created the draft solution ${created.name} (${created.slug}).\n`);
|
|
324
|
+
return { slug: created.slug, created: true };
|
|
310
325
|
}
|
|
311
326
|
let all;
|
|
312
327
|
try {
|
|
@@ -322,7 +337,7 @@ async function initHarness(ctx, given) {
|
|
|
322
337
|
let name;
|
|
323
338
|
if (all.length) {
|
|
324
339
|
const picked = await pick(ctx, {
|
|
325
|
-
intro: `This tenant has ${all.length
|
|
340
|
+
intro: `This tenant has ${all.length === 1 ? "1 solution; choose it" : `${all.length} solutions; choose one`}, or start a new one:`,
|
|
326
341
|
question: "Which solution does this folder hold?",
|
|
327
342
|
items: all,
|
|
328
343
|
extra: (h) => h.status,
|
|
@@ -355,7 +370,7 @@ function envYaml(name, harness) {
|
|
|
355
370
|
return [
|
|
356
371
|
`# Where \`cavelon apply --env ${name}\` goes. Never a token or a secret value.`,
|
|
357
372
|
"# tenant: <name, slug or id> # default: the tenant in cavelon.yaml",
|
|
358
|
-
harness ? `harness: ${harness}` : "# harness: <slug> #
|
|
373
|
+
harness ? `harness: ${harness}` : "# harness: <slug> # must exist: init or `cavelon harness new` creates it",
|
|
359
374
|
"# mode: overwrite # or replace",
|
|
360
375
|
"# runtime_bindings: # the package's runtime requirement key -> this tenant's resource id",
|
|
361
376
|
"# <key>: <id>",
|
|
@@ -410,6 +425,11 @@ async function readImportFile(ctx, from) {
|
|
|
410
425
|
throw importFileError(from, "its top level is not a mapping of sections");
|
|
411
426
|
return value;
|
|
412
427
|
}
|
|
428
|
+
function onlyHarnessName(pkg) {
|
|
429
|
+
const harnesses = Array.isArray(pkg.harnesses) ? pkg.harnesses : [];
|
|
430
|
+
const name = harnesses.length === 1 ? harnesses[0]?.name : undefined;
|
|
431
|
+
return typeof name === "string" && name.trim() ? name.trim() : undefined;
|
|
432
|
+
}
|
|
413
433
|
function onlyHarnessSlug(pkg) {
|
|
414
434
|
const harnesses = Array.isArray(pkg.harnesses) ? pkg.harnesses : [];
|
|
415
435
|
if (harnesses.length !== 1)
|
|
@@ -464,6 +484,9 @@ async function runInit(ctx, input) {
|
|
|
464
484
|
throw usageError("--from and --update do not go together.", "Run `cavelon init --from <file>` and `cavelon init --update` one after the other.");
|
|
465
485
|
if (boolOption(input, "force") && !from)
|
|
466
486
|
throw usageError("--force only applies to --from.");
|
|
487
|
+
if (boolOption(input, "new") && (update || (!stringOption(input, "harness") && !from))) {
|
|
488
|
+
throw usageError("--new needs the new solution's name: --harness <name>.", "`cavelon init --harness <name> --new` creates it as a draft, even when an existing solution has a similar name.");
|
|
489
|
+
}
|
|
467
490
|
const imported = from ? await readImportFile(ctx, from) : undefined;
|
|
468
491
|
if (update) {
|
|
469
492
|
if (!session.project)
|
|
@@ -491,6 +514,8 @@ async function runInit(ctx, input) {
|
|
|
491
514
|
const existing = await readTextFile(path.join(root, PROJECT_FILE));
|
|
492
515
|
if (existing !== undefined) {
|
|
493
516
|
actions.push({ file: PROJECT_FILE, action: "unchanged" });
|
|
517
|
+
if (boolOption(input, "new"))
|
|
518
|
+
ctx.warn(`${PROJECT_FILE} already names this folder's solution; --new created none.`);
|
|
494
519
|
}
|
|
495
520
|
else {
|
|
496
521
|
const url = requireInstance(session);
|
|
@@ -511,11 +536,16 @@ async function runInit(ctx, input) {
|
|
|
511
536
|
await contracts.errorCatalog().catch(() => null);
|
|
512
537
|
if (!schema)
|
|
513
538
|
ctx.warn("The instance does not publish its package schema; `validate` will have nothing to check against.");
|
|
514
|
-
const
|
|
539
|
+
const choice = { create: boolOption(input, "new"), flags: contextFlags({ ...session, tenant: tenant?.ref ?? session.tenant }) };
|
|
540
|
+
const decided = stringOption(input, "harness")
|
|
541
|
+
? await initHarness(ctx, stringOption(input, "harness"), undefined, choice)
|
|
542
|
+
: packageHarness
|
|
543
|
+
? await initHarness(ctx, packageHarness, (imported && onlyHarnessName(imported)) ?? packageHarness, choice)
|
|
544
|
+
: await initHarness(ctx, undefined, undefined, choice);
|
|
515
545
|
chosenHarness = decided;
|
|
516
546
|
const harness = decided.slug;
|
|
517
547
|
if (decided.missing)
|
|
518
|
-
next.push(`Solution ${harness} is not on the instance yet:
|
|
548
|
+
next.push(`Solution ${harness} is not on the instance yet: create it as a draft with ${decided.create}, then cavelon apply --env test.`);
|
|
519
549
|
const values = { instance: url };
|
|
520
550
|
if (tenant)
|
|
521
551
|
values.tenant = tenant.ref;
|
|
@@ -534,7 +564,7 @@ async function runInit(ctx, input) {
|
|
|
534
564
|
actions.push(...(await folder(root, dir)));
|
|
535
565
|
}
|
|
536
566
|
actions.push(...(await folder(root, "seeds")));
|
|
537
|
-
const harness = stringOption(input, "harness") ??
|
|
567
|
+
const harness = chosenHarness?.slug ?? project.harness ?? stringOption(input, "harness") ?? packageHarness;
|
|
538
568
|
actions.push(await ownFile(root, `${ENV_DIR}/test.yaml`, envYaml("test", harness)));
|
|
539
569
|
actions.push(await ownFile(root, `${ENV_DIR}/prod.yaml`, envYaml("prod", undefined)));
|
|
540
570
|
if (await ensureStateDir(root))
|
|
@@ -589,7 +619,7 @@ export const init = {
|
|
|
589
619
|
"file that holds something else unless --force, and names the sections the instance's schema does not know.",
|
|
590
620
|
readOnly: false,
|
|
591
621
|
destructive: true,
|
|
592
|
-
mcpEffect: "Changes nothing on the instance (as a tool it never creates a solution). Writes files in the solution folder; never overwrites a " +
|
|
622
|
+
mcpEffect: "Changes nothing on the instance (as a tool it never creates a solution; it names the `harness_new` call for one that is missing). Writes files in the solution folder; never overwrites a " +
|
|
593
623
|
"file it did not create, and changes only the blocks between its markers in AGENTS.md, CLAUDE.md and .gitignore.",
|
|
594
624
|
idempotent: true,
|
|
595
625
|
mcpTool: "init",
|
|
@@ -597,7 +627,11 @@ export const init = {
|
|
|
597
627
|
harness: {
|
|
598
628
|
type: "string",
|
|
599
629
|
value: "<harness>",
|
|
600
|
-
description: "The solution (harness) this folder holds, by name, slug or id; its slug goes into cavelon.yaml. Without it, init asks on a terminal.",
|
|
630
|
+
description: "The solution (harness) this folder holds, by name, slug or id; its slug goes into cavelon.yaml. One that is not on the instance yet is created as a draft with that name, unless an existing solution's name is close to it: then init refuses, naming that one, and --new creates the new one. Without it, init asks on a terminal.",
|
|
631
|
+
},
|
|
632
|
+
new: {
|
|
633
|
+
type: "boolean",
|
|
634
|
+
description: "Create the solution --harness names as a new draft, even when an existing solution has a similar name (refused when one has that very name or slug).",
|
|
601
635
|
},
|
|
602
636
|
agents: {
|
|
603
637
|
type: "string",
|
|
@@ -613,6 +647,7 @@ export const init = {
|
|
|
613
647
|
examples: [
|
|
614
648
|
"cavelon init",
|
|
615
649
|
"cavelon init --instance https://cavelon.example.com --tenant \"Acme Support\" --harness \"Support FAQ\"",
|
|
650
|
+
"cavelon init --tenant acme --harness \"Support FAQ v2\" --new",
|
|
616
651
|
"cavelon init --agents codex,cursor --hook",
|
|
617
652
|
"cavelon init --update",
|
|
618
653
|
"cavelon init --instance https://cavelon.example.com --tenant acme --from ./blueprint.json",
|
|
@@ -24,6 +24,27 @@ export async function refreshInventory(root, kind, names, now) {
|
|
|
24
24
|
inventory.refreshed_at = { ...inventory.refreshed_at, [kind]: now.toISOString() };
|
|
25
25
|
await writeState(root, INVENTORY_JSON, `${JSON.stringify(inventory, null, 2)}\n`);
|
|
26
26
|
}
|
|
27
|
+
export async function readInventoryKinds(ctx, root, kinds, now) {
|
|
28
|
+
const failed = [];
|
|
29
|
+
for (const kind of kinds) {
|
|
30
|
+
const listing = LISTINGS.find((l) => l.kind === kind);
|
|
31
|
+
if (!listing) {
|
|
32
|
+
failed.push(kind);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const data = await callStable(ctx, "GET", listing.path, `listing ${listing.label}`, { query: listing.query });
|
|
37
|
+
const names = itemsOf(data)
|
|
38
|
+
.map((i) => i[listing.field])
|
|
39
|
+
.filter((v) => typeof v === "string");
|
|
40
|
+
await refreshInventory(root, kind, names, now);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
failed.push(kind);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return failed;
|
|
47
|
+
}
|
|
27
48
|
const MAX_ROWS = 100;
|
|
28
49
|
const COLUMNS = ["slug", "name", "status", "id"];
|
|
29
50
|
function itemsOf(data) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { originText } from "../capacity.js";
|
|
2
|
-
import {
|
|
2
|
+
import { positional } from "../command.js";
|
|
3
3
|
import { CavelonError, ExitCode, usageError } from "../errors.js";
|
|
4
|
+
import { confirmation } from "../confirm-token.js";
|
|
4
5
|
import { callOperation, openapiOrWarn, workflowOperation } from "../invoke.js";
|
|
5
6
|
import { changedBy, docsPage, formatValue, isOperatorChange, LIMIT_ABOVE_CEILING, limitRef, quotaSetting, readLimits, } from "../limits.js";
|
|
6
7
|
import { deref, jsonBodySchema, operationForPath, validateBody } from "../openapi.js";
|
|
@@ -484,12 +485,13 @@ export const limitsSet = {
|
|
|
484
485
|
},
|
|
485
486
|
],
|
|
486
487
|
options: {
|
|
487
|
-
confirm: { type: "boolean", description: "Change it; without this nothing is changed." },
|
|
488
|
+
confirm: { type: "boolean", mcpToken: true, description: "Change it; without this nothing is changed." },
|
|
488
489
|
env: ENV_OPTION,
|
|
489
490
|
},
|
|
490
491
|
examples: [
|
|
491
492
|
"cavelon limits set kb_upload_max_file_size_mb 50",
|
|
492
493
|
"cavelon limits set kb_upload_max_file_size_mb 50 --confirm",
|
|
494
|
+
"cavelon limits set kb_upload_max_file_size_mb 50 --confirm <token>",
|
|
493
495
|
"cavelon limits set rate_limit_chat_rpm none --confirm",
|
|
494
496
|
"cavelon limits set monthly_inference_token_budget 2000000",
|
|
495
497
|
"cavelon limits set monthly_processing_step_cap none --confirm",
|
|
@@ -573,8 +575,9 @@ export const limitsSet = {
|
|
|
573
575
|
const allowed = operator
|
|
574
576
|
? `a personal access token in Platform mode of a ${anyOf(change.requires_role ?? [], "platform role")}`
|
|
575
577
|
: `a credential with ${anyOf(change.permissions)} (a session, a personal access token, or an admin API key of the tenant)`;
|
|
576
|
-
|
|
577
|
-
|
|
578
|
+
const gate = await confirmation(ctx, input, "limits_set", { key, value, previous: previous ?? null, operation });
|
|
579
|
+
if (!gate.confirmed) {
|
|
580
|
+
const confirm = gate.confirm(`cavelon limits set ${shellWord(key)} ${shellWord(argText(value))}${flags} --confirm`);
|
|
578
581
|
const source = target.limit && target.kind === "limit" ? ` (source now: ${target.limit.source}${target.limit.origin ? `, origin: ${target.limit.origin}` : ""})` : "";
|
|
579
582
|
const what = target.scope === "platform" && target.limit?.tenant_change
|
|
580
583
|
? [`This changes the platform's cap for every tenant without its own; --tenant <id|slug> sets one tenant's own cap.`]
|
|
@@ -582,8 +585,9 @@ export const limitsSet = {
|
|
|
582
585
|
? [`For tenant ${params.tenant_id[0]} only.`]
|
|
583
586
|
: [];
|
|
584
587
|
return {
|
|
585
|
-
data: { ...base, changed: false, sent: false, confirm },
|
|
586
|
-
text: [`${key}: ${from} → ${to}${source}.`, ...what, `Sends: ${sends}`, `Allowed: ${allowed}.`, `Nothing was changed. Change it with: ${confirm}`].join("\n"),
|
|
588
|
+
data: { ...base, changed: false, sent: false, confirm, ...gate.fields },
|
|
589
|
+
text: [`${key}: ${from} → ${to}${source}.`, ...what, `Sends: ${sends}`, `Allowed: ${allowed}.`, ...(gate.mismatch ? [gate.mismatch] : []), `Nothing was changed. Change it with: ${confirm}`].join("\n"),
|
|
590
|
+
...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
|
|
587
591
|
};
|
|
588
592
|
}
|
|
589
593
|
let result;
|
package/dist/commands/loops.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { noteLines, runCapacityNote } from "../capacity.js";
|
|
2
2
|
import { boolOption, CURSOR_OPTION, intOption, LIMIT_OPTION, positional, stringOption, } from "../command.js";
|
|
3
3
|
import { CavelonError, ExitCode, usageError } from "../errors.js";
|
|
4
|
+
import { confirmation } from "../confirm-token.js";
|
|
4
5
|
import { idempotencyKey, requireFeature, UUID_KEY_OPTION, withRetryKey } from "../features.js";
|
|
5
6
|
import { clip, keyValues, moreHint, table } from "../format.js";
|
|
6
7
|
import { callStable } from "../invoke.js";
|
|
@@ -232,9 +233,9 @@ export const loopCancel = {
|
|
|
232
233
|
mcpTool: "loop_cancel",
|
|
233
234
|
positionals: [{ name: "run", description: "The trigger run id (from `loop start`).", required: true }],
|
|
234
235
|
options: {
|
|
235
|
-
confirm: { type: "boolean", description: "Stop the run; without it nothing is stopped." },
|
|
236
|
+
confirm: { type: "boolean", mcpToken: true, description: "Stop the run; without it nothing is stopped." },
|
|
236
237
|
},
|
|
237
|
-
examples: ["cavelon loop cancel <run>", "cavelon loop cancel <run> --confirm"],
|
|
238
|
+
examples: ["cavelon loop cancel <run>", "cavelon loop cancel <run> --confirm", "cavelon loop cancel <run> --confirm <token>"],
|
|
238
239
|
async run(ctx, input) {
|
|
239
240
|
const runId = positional(input, "run");
|
|
240
241
|
const run = await getRun(ctx, runId);
|
|
@@ -243,14 +244,17 @@ export const loopCancel = {
|
|
|
243
244
|
return { data: { cancelled: false, run: runSummary(run, note) }, text: `Run ${run.id} is already ${run.status}; nothing to stop.${noteLines(note)}` };
|
|
244
245
|
}
|
|
245
246
|
const loops = (await loopsOf(ctx, run.id)).map(loopSummary);
|
|
246
|
-
|
|
247
|
-
|
|
247
|
+
const gate = await confirmation(ctx, input, "loop_cancel", { run: run.id });
|
|
248
|
+
if (!gate.confirmed) {
|
|
249
|
+
const confirm = gate.confirm(`cavelon loop cancel ${run.id} --confirm`);
|
|
248
250
|
return {
|
|
249
|
-
data: { cancelled: false, run: runSummary(run, note), loops, confirm },
|
|
251
|
+
data: { cancelled: false, run: runSummary(run, note), loops, confirm, ...gate.fields },
|
|
250
252
|
text: `Run ${run.id} (${run.workflow_name}) is ${run.status}` +
|
|
251
253
|
(loops.length ? `, with loops:\n${table(loops, ["loop_id", "node", "state", "iteration"])}\n` : ".\n") +
|
|
252
254
|
(note ? `${noteLines(note).slice(1)}\n` : "") +
|
|
255
|
+
(gate.mismatch ? `${gate.mismatch}\n` : "") +
|
|
253
256
|
`Nothing was stopped. Stop it with: ${confirm}`,
|
|
257
|
+
...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
|
|
254
258
|
};
|
|
255
259
|
}
|
|
256
260
|
const cancelled = await callStable(ctx, "POST", "/api/v1/triggers/runs/{run_id}/cancel", "cancelling runs", { params: { run_id: [run.id] } });
|
|
@@ -756,9 +760,14 @@ export const triggerIdentity = {
|
|
|
756
760
|
],
|
|
757
761
|
options: {
|
|
758
762
|
clear: { type: "boolean", description: "Remove the binding; scheduled and webhook runs then cannot start." },
|
|
759
|
-
confirm: { type: "boolean", description: "Make the change; without it nothing changes." },
|
|
763
|
+
confirm: { type: "boolean", mcpToken: true, description: "Make the change; without it nothing changes." },
|
|
760
764
|
},
|
|
761
|
-
examples: [
|
|
765
|
+
examples: [
|
|
766
|
+
"cavelon trigger identity orders",
|
|
767
|
+
"cavelon trigger identity orders loop-runner --confirm",
|
|
768
|
+
"cavelon trigger identity orders loop-runner --confirm <token>",
|
|
769
|
+
"cavelon trigger identity orders --clear --confirm",
|
|
770
|
+
],
|
|
762
771
|
async run(ctx, input) {
|
|
763
772
|
const keyRef = positional(input, "key");
|
|
764
773
|
const clear = boolOption(input, "clear");
|
|
@@ -777,11 +786,13 @@ export const triggerIdentity = {
|
|
|
777
786
|
}
|
|
778
787
|
const keyName = key && "name" in key ? key.name : wanted;
|
|
779
788
|
const change = wanted ? `bind API key "${keyName}"` : "clear the binding";
|
|
780
|
-
|
|
781
|
-
|
|
789
|
+
const gate = await confirmation(ctx, input, "trigger_identity", { trigger: trigger.id, from: current.api_key_id ?? null, to: wanted });
|
|
790
|
+
if (!gate.confirmed) {
|
|
791
|
+
const confirm = gate.confirm(cavelonCommand("trigger", "identity", trigger.slug, keyRef ?? "--clear", "--confirm"));
|
|
782
792
|
return {
|
|
783
|
-
data: { trigger: trigger.slug, changed: false, would: change, current: view, confirm },
|
|
784
|
-
text: `${identityText(trigger, view)}\n\
|
|
793
|
+
data: { trigger: trigger.slug, changed: false, would: change, current: view, confirm, ...gate.fields },
|
|
794
|
+
text: `${identityText(trigger, view)}\n\n${gate.mismatch ? `${gate.mismatch}\n` : ""}Nothing changed. To ${change}: ${confirm}`,
|
|
795
|
+
...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
|
|
785
796
|
};
|
|
786
797
|
}
|
|
787
798
|
const updated = await callStable(ctx, "PUT", route, "execution identities", {
|