@cavelon/cli 0.1.6 → 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 +41 -13
- package/dist/command.js +10 -0
- package/dist/commands/chat.js +17 -11
- package/dist/commands/docs.js +15 -4
- package/dist/commands/fmt.js +56 -4
- package/dist/commands/init.js +35 -12
- package/dist/commands/limits-set.js +1 -0
- package/dist/commands/loops.js +7 -2
- package/dist/commands/models.js +2 -1
- package/dist/commands/sandboxes.js +3 -1
- package/dist/commands/schema.js +19 -5
- package/dist/commands/session.js +21 -3
- package/dist/commands/solution.js +202 -47
- package/dist/commands/tenants.js +6 -4
- package/dist/commands/values.js +3 -3
- package/dist/commands/work.js +59 -12
- package/dist/format.js +4 -4
- package/dist/harness-ref.js +4 -4
- package/dist/http.js +6 -0
- package/dist/kit-codes.js +6 -2
- package/dist/local-state.js +18 -0
- package/dist/main.js +2 -5
- package/dist/mcp.js +3 -1
- package/dist/package-check.js +33 -5
- package/dist/package-files.js +24 -2
- package/dist/session.js +9 -0
- package/dist/skills/cavelon-authoring/SKILL.md +7 -3
- package/dist/skills/cavelon-long-running/SKILL.md +13 -9
- package/dist/skills/cavelon-loop/SKILL.md +47 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -124,11 +124,13 @@ Every command takes `--json` (one JSON document on stdout, errors included),
|
|
|
124
124
|
| `harness new <slug> [--name] [--description]` | changing | Create an empty draft solution. |
|
|
125
125
|
| `harness clone <source> [--slug] [--name] [--no-tests] [--no-triggers]` | changing | Copy a solution into a new draft. |
|
|
126
126
|
| `activate [--harness] [--env]` | changing | Activate through the readiness gate only, never by force. |
|
|
127
|
-
| `
|
|
128
|
-
| `
|
|
127
|
+
| `chat <message> [--harness] [--env] [--session <id>] [--timeout 90s]` | changing | Send one message to a solution and print its answer, with the session to continue and the conversation to trace; tries a draft or an active solution that is not the default route. |
|
|
128
|
+
| `deactivate [--harness] [--env] [--confirm [<token>]]` | changing (destructive) | Take an active solution out of live traffic: its status becomes `inactive` (not `draft`); previews first. |
|
|
129
|
+
| `init [--harness [--new]] [--agents <list>] [--hook] [--update] [--from <file> [--force]]` | changing (files) | Make this folder a solution: `cavelon.yaml`, `package/`, `tests/`, `env/`, `.cavelon/`; on a terminal it asks for the tenant and the solution (or a new one by name); a name close to an existing solution's is refused unless `--new`; `--from` writes a package file into it. |
|
|
130
|
+
| `pull [--harness] [--force] [--tenant-wide]` | changing (files) | Write the instance's package into `package/` and `tests/`, the inventory into `.cavelon/`. A solution's tenant-wide sections only with `--tenant-wide`, which says when the export carries none. |
|
|
129
131
|
| `validate [--offline] [--strict]` | read-only | Check the package files against the cached package schema, their references, unknown fields and models; `--strict` fails on warnings. |
|
|
130
132
|
| `schema [<section>[.<field>…] \| <type>] [--offline]` | read-only | The package schema's sections, or the fields of a section, a nested field (`agents.handoffs`) or a type, with a minimal example. |
|
|
131
|
-
| `apply [--env] [--harness] [--mode]` | changing | Preview the files against the instance; prints and stores a preview id. |
|
|
133
|
+
| `apply [--env] [--harness] [--mode] [--tenant-wide]` | changing | Preview the files against the instance; prints and stores a preview id. A solution's tenant-wide sections go along only with `--tenant-wide`, for the whole tenant. |
|
|
132
134
|
| `apply --confirm <preview-id>` | changing | Import exactly that preview; a stale one, or one the import's own check refuses (it names the blockers), exits 4. |
|
|
133
135
|
| `explain <code>` | read-only | Look a code up in the instance's error catalog. |
|
|
134
136
|
| `variables list` / `variables get <name>` | read-only | The tenant's plain-text variables (`{{var:…}}`) with their values. |
|
|
@@ -144,7 +146,7 @@ Every command takes `--json` (one JSON document on stdout, errors included),
|
|
|
144
146
|
| `docs get <page> [--max-chars] [--cursor]` | read-only | One docs page as markdown. |
|
|
145
147
|
| `wait <operation…> [--timeout 90s]` | read-only | Wait for operations; resumable, and reports `waited_ms`. A test run with failed cases is a failure. |
|
|
146
148
|
| `watch <operation> [--timeout 10m]` | read-only | Stream an operation's changes (server-sent events). |
|
|
147
|
-
| `kb upload <dir> --kb <kb> [-r] [--ext pdf] [--replace] [--wait]` | changing | Upload documents; returns operation ids. Names files that match an active document; `--replace` replaces those. |
|
|
149
|
+
| `kb upload <dir> --kb <kb> [-r] [--ext pdf] [--replace] [--dry-run] [--wait]` | changing | Upload documents; returns operation ids. Names files that match an active document; `--replace` replaces those. `--dry-run` also names files identical to an active document. |
|
|
148
150
|
| `test run [--suite <s>] [--harness <h>] [--wait]` | changing | Start test-suite runs; returns operation ids. |
|
|
149
151
|
| `trace <run> [--trace <id>] [--span <id>]` | read-only | Summarise a run's traces (or a test run's results, with why a case did not pass), then one trace's spans, then one span. |
|
|
150
152
|
| `loop start <trigger> [--input <json>] [--wait]` | changing | Start a loop through its trigger, as you; returns the run and operation ids. |
|
|
@@ -404,6 +406,19 @@ base by file name, with what happens to that document, in `--dry-run` too:
|
|
|
404
406
|
bergbahn-faq.md exists (094e95e9…) and stays active
|
|
405
407
|
```
|
|
406
408
|
|
|
409
|
+
A file whose bytes are those of an active document, under any name, is not
|
|
410
|
+
created again: the instance deduplicates it, and `kb upload` says
|
|
411
|
+
"identical to the active document …; nothing new was created (deduplicated)".
|
|
412
|
+
`--dry-run` says so before the upload ("nothing new would be created") where
|
|
413
|
+
the instance publishes each document's `file_sha256` (the SHA-256 of the
|
|
414
|
+
uploaded bytes, which its deduplication compares): it hashes each local file
|
|
415
|
+
the same way, and `--json` lists those files under `identical` with the
|
|
416
|
+
document each one matches, and sets `content_compared`. A same-named document
|
|
417
|
+
the file is identical to is then neither replaced nor deactivated. On an
|
|
418
|
+
instance that does not publish the hash, `content_compared` is `false` and
|
|
419
|
+
the dry run names no file identical; a document without a hash (not a file,
|
|
420
|
+
or uploaded before the instance published it) matches none.
|
|
421
|
+
|
|
407
422
|
- Without a flag the old document stays active next to the new one, and both
|
|
408
423
|
answer, unless the instance replaces same-named documents itself (its upload
|
|
409
424
|
offers `replace_existing`); there `--keep-both` keeps both.
|
|
@@ -592,8 +607,11 @@ cavelon activate --harness support
|
|
|
592
607
|
Sections the instance's package schema does not know are written, reported as
|
|
593
608
|
`ignored` and warned about, as `validate` does. With no `--harness`,
|
|
594
609
|
a package with one harness names the solution in a new `cavelon.yaml` and
|
|
595
|
-
`env/test.yaml
|
|
596
|
-
|
|
610
|
+
`env/test.yaml`. A solution the tenant does not have yet, `init` creates as a
|
|
611
|
+
draft, named as in the package, so `apply --env test` previews into it; the
|
|
612
|
+
MCP tool `init` creates none and names the `cavelon harness new` command
|
|
613
|
+
instead. The rest of `init` runs as without `--from`: its own files, the
|
|
614
|
+
marked blocks.
|
|
597
615
|
|
|
598
616
|
```bash
|
|
599
617
|
mkdir counter && cd counter
|
|
@@ -619,7 +637,10 @@ cavelon activate --harness support
|
|
|
619
637
|
which). Files of sections the schema does not know are kept byte for byte. A
|
|
620
638
|
solution's pull leaves the tenant-wide sections out of the folder (those the
|
|
621
639
|
schema marks `x-cavelon-scope: tenant`; on an instance that marks none,
|
|
622
|
-
`tenant_settings` and `model_registry`) unless `--tenant-wide
|
|
640
|
+
`tenant_settings` and `model_registry`) unless `--tenant-wide`, which asks the
|
|
641
|
+
export for them (`include_tenant_wide`) where the instance takes it, and says
|
|
642
|
+
when the export carries none. A file of one already there is kept (listed
|
|
643
|
+
under `kept`). It refuses when package files have uncommitted changes
|
|
623
644
|
(exit 4) unless `--force`, and writes the tenant's solutions, knowledge bases,
|
|
624
645
|
tools, test suites and sandboxes to `.cavelon/inventory.md`.
|
|
625
646
|
- **`validate`** checks the files against the package schema that `init`, `pull`
|
|
@@ -645,12 +666,19 @@ cavelon activate --harness support
|
|
|
645
666
|
finds what the preview did not answers `409 package_requirements_changed`
|
|
646
667
|
with `blockers`: exit 4, each blocker on its own line (in `--json`, the
|
|
647
668
|
error's `blockers`), "nothing was imported; preview again", and for a code
|
|
648
|
-
the kit knows (such as `runtime_draft_iteration_needs_draft_parent`) its hint.
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
669
|
+
the kit knows (such as `runtime_draft_iteration_needs_draft_parent`) its hint.
|
|
670
|
+
`apply` previews into an existing solution and never creates one: when the
|
|
671
|
+
env file, `cavelon.yaml` or `--harness` names a solution the tenant does not
|
|
672
|
+
have, it stops with `solution_not_found` (exit 1) before anything is sent,
|
|
673
|
+
and names the `cavelon harness new <slug>` command that creates the draft
|
|
674
|
+
(with `--name` as `package/harnesses.yaml` names that harness); preview again
|
|
675
|
+
after it. `runtime_bindings` from the env file
|
|
676
|
+
bind the package's runtime requirements. A solution's import leaves the
|
|
677
|
+
package's tenant-wide sections out; `--tenant-wide` sends them
|
|
678
|
+
(`include_tenant_wide`), for every solution of the tenant. An instance that
|
|
679
|
+
does not publish that flag imports them with every solution's package, and
|
|
680
|
+
`apply` says so. A preview that reaches an active solution, deletes, changes
|
|
681
|
+
tenant-wide sections or goes to `env/prod` says to show it to a person first.
|
|
654
682
|
- **`explain <code>`** looks a rule code or API error code up in the instance's
|
|
655
683
|
error catalog (and the codes `validate` reports itself): meaning, fix and docs
|
|
656
684
|
link. For `run_capacity_busy` and `model_endpoint_busy` it adds which limit to
|
package/dist/command.js
CHANGED
|
@@ -5,6 +5,16 @@ export const GLOBAL_OPTIONS = {
|
|
|
5
5
|
tenant: { type: "string", value: "<tenant>", description: "Tenant slug, name or id (overrides CAVELON_TENANT and cavelon.yaml)." },
|
|
6
6
|
help: { type: "boolean", short: "h", description: "Show help for the command." },
|
|
7
7
|
};
|
|
8
|
+
export function optionFlag(name, o) {
|
|
9
|
+
const value = o.type === "string" ? ` ${o.value ?? "<value>"}` : o.mcpToken ? " [<token>]" : "";
|
|
10
|
+
return `${o.short ? `-${o.short}, ` : ""}--${name}${value}`;
|
|
11
|
+
}
|
|
12
|
+
export function optionDescription(name, o) {
|
|
13
|
+
const token = o.type === "boolean" && o.mcpToken
|
|
14
|
+
? ` In a person's terminal the flag alone confirms; run by a coding agent, \`--${name} <token>\` with the token its preview printed (the bare flag only shows the preview there, exit 5).`
|
|
15
|
+
: "";
|
|
16
|
+
return o.description + token + (o.multiple ? " Repeatable." : "");
|
|
17
|
+
}
|
|
8
18
|
export function stringOption(input, name) {
|
|
9
19
|
const value = input.options[name];
|
|
10
20
|
if (Array.isArray(value))
|
package/dist/commands/chat.js
CHANGED
|
@@ -5,6 +5,7 @@ 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 { contextFlags } from "../session.js";
|
|
8
9
|
import { cavelonCommand } from "../shell.js";
|
|
9
10
|
import { MCP_MAX_WAIT_MS } from "./async.js";
|
|
10
11
|
function harnessRef(session, input) {
|
|
@@ -19,9 +20,10 @@ function harnessRef(session, input) {
|
|
|
19
20
|
}
|
|
20
21
|
async function findHarness(ctx, ref, source, command) {
|
|
21
22
|
const { harness, candidates } = await lookupHarness(ctx, ref);
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
if (harness)
|
|
24
|
+
return harness;
|
|
25
|
+
const flags = contextFlags(await ctx.session());
|
|
26
|
+
throw harnessNotFoundError(ref, candidates, source === "option" ? undefined : source, (slug) => command(slug) + flags, flags);
|
|
25
27
|
}
|
|
26
28
|
const HARNESS_OPTION = {
|
|
27
29
|
type: "string",
|
|
@@ -105,12 +107,14 @@ export const chat = {
|
|
|
105
107
|
};
|
|
106
108
|
export const deactivate = {
|
|
107
109
|
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
|
|
110
|
-
"
|
|
111
|
-
"
|
|
112
|
-
"
|
|
113
|
-
"
|
|
110
|
+
summary: "Take an active solution out of service (status inactive); previews first, --confirm deactivates.",
|
|
111
|
+
description: "An active solution answers live traffic: the conversations, channels and API keys that name it. Deactivating sets its\n" +
|
|
112
|
+
"status to inactive, not back to draft (a draft has not been activated yet; an inactive solution was taken out of\n" +
|
|
113
|
+
"service). It keeps its configuration and answers no live traffic until it is activated again (`cavelon activate`,\n" +
|
|
114
|
+
"through its readiness gate). Without --confirm nothing changes: the preview says what would stop. Show it to a person\n" +
|
|
115
|
+
"and confirm only with their yes. The tenant's default route is refused before anything is sent: make another solution\n" +
|
|
116
|
+
"the default first (`cavelon harness default <solution>`). An instance that publishes no deactivate route is said so; a\n" +
|
|
117
|
+
"person deactivates in the Admin there.",
|
|
114
118
|
readOnly: false,
|
|
115
119
|
destructive: true,
|
|
116
120
|
idempotent: true,
|
|
@@ -120,7 +124,9 @@ export const deactivate = {
|
|
|
120
124
|
env: ENV_OPTION,
|
|
121
125
|
confirm: { type: "boolean", mcpToken: true, description: "Deactivate it (after a person saw the preview)." },
|
|
122
126
|
},
|
|
123
|
-
examples: ["cavelon deactivate --harness support-faq", "cavelon deactivate --harness support-faq --confirm"
|
|
127
|
+
examples: ["cavelon deactivate --harness support-faq", "cavelon deactivate --harness support-faq --confirm",
|
|
128
|
+
"cavelon deactivate --harness support-faq --confirm <token>",
|
|
129
|
+
],
|
|
124
130
|
async run(ctx, input) {
|
|
125
131
|
const session = await ctx.session();
|
|
126
132
|
const { ref, source } = harnessRef(session, input);
|
|
@@ -159,7 +165,7 @@ export const deactivate = {
|
|
|
159
165
|
return {
|
|
160
166
|
data: { changed: false, harness: target, would: "deactivate", confirm: gate.confirm(confirmCommand), ...gate.fields },
|
|
161
167
|
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}.`,
|
|
168
|
+
`Deactivating ${named(harness)} sets it inactive and takes it out of live traffic: the conversations, channels and API keys that name it are no longer answered by it until it is activated again${known}.`,
|
|
163
169
|
...(gate.mismatch ? [gate.mismatch] : []),
|
|
164
170
|
`Show this to a person; with their yes: ${gate.confirm(confirmCommand)}`,
|
|
165
171
|
].join("\n"),
|
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",
|
|
@@ -179,7 +182,13 @@ const RELATED_TERMS = {
|
|
|
179
182
|
incorrect: ["debug", "trace"],
|
|
180
183
|
error: ["debug", "trace"],
|
|
181
184
|
debug: ["trace", "playground"],
|
|
185
|
+
handoff: ["agent", "graph"],
|
|
186
|
+
consult: ["agent", "graph"],
|
|
182
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
|
+
}
|
|
183
192
|
const GENERIC_TERMS = new Set(["agent", "cavelon"]);
|
|
184
193
|
const GENERIC_WEIGHT = 0.3;
|
|
185
194
|
const IN_CONTEXT = [
|
|
@@ -305,7 +314,9 @@ export const docsSearch = {
|
|
|
305
314
|
const { terms } = queryTerms(query);
|
|
306
315
|
const items = hits.slice(0, limit).map(({ page, title, description, section }) => ({ page, title, section, description }));
|
|
307
316
|
const none = `No page matches "${query}"${terms.length ? ` (looked for: ${terms.join(", ")})` : " (it has only stop words)"}. ` +
|
|
308
|
-
|
|
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, `) +
|
|
309
320
|
`or read the list of all ${entries.length} pages with: ${cavelonCommand("docs", "get", INDEX_REF)}`;
|
|
310
321
|
return {
|
|
311
322
|
data: { query, terms, items, total: hits.length, ...(items.length ? {} : { hint: none }) },
|
package/dist/commands/fmt.js
CHANGED
|
@@ -1,13 +1,34 @@
|
|
|
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.",
|
|
@@ -17,7 +38,8 @@ export const fmt = {
|
|
|
17
38
|
"spelling, with one exception: an entry of a list that leaves out an `..._order` field (sort_order, display_order,\n" +
|
|
18
39
|
"step_order) gets its position, so the instance keeps the written order instead of ordering entries that all carry the\n" +
|
|
19
40
|
"default its own way (test cases by name). Lists become block lists; the persona file shows every field, the unset\n" +
|
|
20
|
-
"ones as comments. Comments in a rewritten file are not kept, as pull does not keep them
|
|
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" +
|
|
21
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" +
|
|
22
44
|
"and before `apply`, so the next `pull` shows only what changed on the instance. --check writes nothing and exits 3 when a\n" +
|
|
23
45
|
"file would change. Uses the cached package schema (as validate does); --offline never contacts the instance.",
|
|
@@ -78,6 +100,18 @@ export const fmt = {
|
|
|
78
100
|
else
|
|
79
101
|
changes.push({ file: source.file, content: sectionContent(section, formed, schema, /\.json$/i.test(source.file)) });
|
|
80
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);
|
|
81
115
|
const written = [];
|
|
82
116
|
if (!check && changes.length) {
|
|
83
117
|
const known = await readPulledFiles(project.root);
|
|
@@ -98,22 +132,40 @@ export const fmt = {
|
|
|
98
132
|
await rememberAppliedFiles(project.root, await fileDigests(project.root, wasKnown));
|
|
99
133
|
}
|
|
100
134
|
const files = changes.map((c) => c.file).sort((a, b) => a.localeCompare(b, "en"));
|
|
101
|
-
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(", ");
|
|
102
138
|
if (check) {
|
|
103
139
|
return {
|
|
104
140
|
data,
|
|
105
141
|
text: files.length
|
|
106
|
-
? [
|
|
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")
|
|
107
147
|
: `All ${unchanged} package files are in the export's form.`,
|
|
108
148
|
exitCode: files.length ? ExitCode.validation : ExitCode.ok,
|
|
109
149
|
};
|
|
110
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);
|
|
111
163
|
return {
|
|
112
164
|
data,
|
|
113
165
|
text: [
|
|
114
166
|
...written.map((f) => `formatted ${f}`),
|
|
115
167
|
`${written.length} file${written.length === 1 ? "" : "s"} formatted, ${unchanged} already in the export's form.`,
|
|
116
|
-
...(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."] : []),
|
|
117
169
|
].join("\n"),
|
|
118
170
|
};
|
|
119
171
|
},
|
package/dist/commands/init.js
CHANGED
|
@@ -17,7 +17,7 @@ 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
19
|
import { harnessNotFoundError, listHarnesses, lookupHarness, SLUG, slugFromName } from "../harness-ref.js";
|
|
20
|
-
import { isUuid, lookupTenantId, requireInstance, requireToken, tenantRequiredError } from "../session.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";
|
|
@@ -279,7 +279,8 @@ async function initTenant(ctx, session) {
|
|
|
279
279
|
const listed = reach?.tenants.find((t) => t.id === placed);
|
|
280
280
|
return { ref: listed?.slug ?? placed, id: placed, name: listed?.name ?? undefined, slug: listed?.slug ?? undefined };
|
|
281
281
|
}
|
|
282
|
-
async function initHarness(ctx, given, displayName = given) {
|
|
282
|
+
async function initHarness(ctx, given, displayName = given, choice = { flags: "" }) {
|
|
283
|
+
const { flags } = choice;
|
|
283
284
|
if (given) {
|
|
284
285
|
let lookup;
|
|
285
286
|
try {
|
|
@@ -289,20 +290,31 @@ async function initHarness(ctx, given, displayName = given) {
|
|
|
289
290
|
ctx.warn(`Could not check solution "${given}" on the instance: ${error instanceof Error ? error.message : String(error)}`);
|
|
290
291
|
return { slug: given };
|
|
291
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
|
+
}
|
|
292
302
|
if (lookup.harness)
|
|
293
303
|
return { slug: lookup.harness.slug };
|
|
294
304
|
const slug = SLUG.test(given) ? given : slugFromName(given);
|
|
295
305
|
const title = (displayName ?? given).trim().slice(0, 255) || slug;
|
|
296
306
|
const create = cavelonCommand("harness", "new", slug, ...(title !== slug ? ["--name", title] : []));
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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;
|
|
301
313
|
throw new CavelonError(error.exitCode, {
|
|
302
314
|
code: error.code,
|
|
303
315
|
message: error.message,
|
|
304
|
-
hint: `${error.hint} For a new solution of that name: ${
|
|
305
|
-
details: error.details,
|
|
316
|
+
hint: `${error.hint} For a new solution of that name: ${createNew}.`,
|
|
317
|
+
details: { ...error.details, create: createNew },
|
|
306
318
|
});
|
|
307
319
|
}
|
|
308
320
|
if (ctx.mode === "mcp")
|
|
@@ -472,6 +484,9 @@ async function runInit(ctx, input) {
|
|
|
472
484
|
throw usageError("--from and --update do not go together.", "Run `cavelon init --from <file>` and `cavelon init --update` one after the other.");
|
|
473
485
|
if (boolOption(input, "force") && !from)
|
|
474
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
|
+
}
|
|
475
490
|
const imported = from ? await readImportFile(ctx, from) : undefined;
|
|
476
491
|
if (update) {
|
|
477
492
|
if (!session.project)
|
|
@@ -499,6 +514,8 @@ async function runInit(ctx, input) {
|
|
|
499
514
|
const existing = await readTextFile(path.join(root, PROJECT_FILE));
|
|
500
515
|
if (existing !== undefined) {
|
|
501
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.`);
|
|
502
519
|
}
|
|
503
520
|
else {
|
|
504
521
|
const url = requireInstance(session);
|
|
@@ -519,11 +536,12 @@ async function runInit(ctx, input) {
|
|
|
519
536
|
await contracts.errorCatalog().catch(() => null);
|
|
520
537
|
if (!schema)
|
|
521
538
|
ctx.warn("The instance does not publish its package schema; `validate` will have nothing to check against.");
|
|
539
|
+
const choice = { create: boolOption(input, "new"), flags: contextFlags({ ...session, tenant: tenant?.ref ?? session.tenant }) };
|
|
522
540
|
const decided = stringOption(input, "harness")
|
|
523
|
-
? await initHarness(ctx, stringOption(input, "harness"))
|
|
541
|
+
? await initHarness(ctx, stringOption(input, "harness"), undefined, choice)
|
|
524
542
|
: packageHarness
|
|
525
|
-
? await initHarness(ctx, packageHarness, (imported && onlyHarnessName(imported)) ?? packageHarness)
|
|
526
|
-
: await initHarness(ctx, undefined);
|
|
543
|
+
? await initHarness(ctx, packageHarness, (imported && onlyHarnessName(imported)) ?? packageHarness, choice)
|
|
544
|
+
: await initHarness(ctx, undefined, undefined, choice);
|
|
527
545
|
chosenHarness = decided;
|
|
528
546
|
const harness = decided.slug;
|
|
529
547
|
if (decided.missing)
|
|
@@ -609,7 +627,11 @@ export const init = {
|
|
|
609
627
|
harness: {
|
|
610
628
|
type: "string",
|
|
611
629
|
value: "<harness>",
|
|
612
|
-
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. 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).",
|
|
613
635
|
},
|
|
614
636
|
agents: {
|
|
615
637
|
type: "string",
|
|
@@ -625,6 +647,7 @@ export const init = {
|
|
|
625
647
|
examples: [
|
|
626
648
|
"cavelon init",
|
|
627
649
|
"cavelon init --instance https://cavelon.example.com --tenant \"Acme Support\" --harness \"Support FAQ\"",
|
|
650
|
+
"cavelon init --tenant acme --harness \"Support FAQ v2\" --new",
|
|
628
651
|
"cavelon init --agents codex,cursor --hook",
|
|
629
652
|
"cavelon init --update",
|
|
630
653
|
"cavelon init --instance https://cavelon.example.com --tenant acme --from ./blueprint.json",
|
|
@@ -491,6 +491,7 @@ export const limitsSet = {
|
|
|
491
491
|
examples: [
|
|
492
492
|
"cavelon limits set kb_upload_max_file_size_mb 50",
|
|
493
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>",
|
|
494
495
|
"cavelon limits set rate_limit_chat_rpm none --confirm",
|
|
495
496
|
"cavelon limits set monthly_inference_token_budget 2000000",
|
|
496
497
|
"cavelon limits set monthly_processing_step_cap none --confirm",
|
package/dist/commands/loops.js
CHANGED
|
@@ -235,7 +235,7 @@ export const loopCancel = {
|
|
|
235
235
|
options: {
|
|
236
236
|
confirm: { type: "boolean", mcpToken: true, description: "Stop the run; without it nothing is stopped." },
|
|
237
237
|
},
|
|
238
|
-
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>"],
|
|
239
239
|
async run(ctx, input) {
|
|
240
240
|
const runId = positional(input, "run");
|
|
241
241
|
const run = await getRun(ctx, runId);
|
|
@@ -762,7 +762,12 @@ export const triggerIdentity = {
|
|
|
762
762
|
clear: { type: "boolean", description: "Remove the binding; scheduled and webhook runs then cannot start." },
|
|
763
763
|
confirm: { type: "boolean", mcpToken: true, description: "Make the change; without it nothing changes." },
|
|
764
764
|
},
|
|
765
|
-
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
|
+
],
|
|
766
771
|
async run(ctx, input) {
|
|
767
772
|
const keyRef = positional(input, "key");
|
|
768
773
|
const clear = boolOption(input, "clear");
|
package/dist/commands/models.js
CHANGED
|
@@ -155,7 +155,8 @@ export const modelsSetLimit = {
|
|
|
155
155
|
confirm: { type: "boolean", mcpToken: true, description: "Change it; without this nothing is changed." },
|
|
156
156
|
env: ENV_OPTION,
|
|
157
157
|
},
|
|
158
|
-
examples: ["cavelon models set-limit llama-70b 8", "cavelon models set-limit llama-70b 8 --confirm",
|
|
158
|
+
examples: ["cavelon models set-limit llama-70b 8", "cavelon models set-limit llama-70b 8 --confirm",
|
|
159
|
+
"cavelon models set-limit llama-70b 8 --confirm <token>", "cavelon models set-limit llama-70b none --confirm"],
|
|
159
160
|
async run(ctx, input) {
|
|
160
161
|
const ref = positional(input, "model");
|
|
161
162
|
const limit = parseLimit(positional(input, "limit"));
|
|
@@ -476,7 +476,9 @@ export const sandboxSeed = {
|
|
|
476
476
|
timeout: TIMEOUT_OPTION,
|
|
477
477
|
"idempotency-key": UUID_KEY_OPTION,
|
|
478
478
|
},
|
|
479
|
-
examples: ["cavelon sandbox seed orders-test seeds/orders", "cavelon sandbox seed orders-test seeds/orders --confirm --wait"
|
|
479
|
+
examples: ["cavelon sandbox seed orders-test seeds/orders", "cavelon sandbox seed orders-test seeds/orders --confirm --wait",
|
|
480
|
+
"cavelon sandbox seed orders-test seeds/orders --confirm <token> --wait",
|
|
481
|
+
],
|
|
480
482
|
async run(ctx, input) {
|
|
481
483
|
const sandbox = await resolveSandbox(ctx, positional(input, "sandbox"));
|
|
482
484
|
requireOffer(ctx, sandbox, "archive", "sandbox seed");
|
package/dist/commands/schema.js
CHANGED
|
@@ -39,14 +39,24 @@ function namedType(schema, raw) {
|
|
|
39
39
|
}
|
|
40
40
|
return undefined;
|
|
41
41
|
}
|
|
42
|
+
function shapeCount(schema, raw) {
|
|
43
|
+
const all = variants(schema, raw);
|
|
44
|
+
return all.length > 1 && all.some((v) => v.node.properties) ? all.length : undefined;
|
|
45
|
+
}
|
|
42
46
|
function typeOf(schema, raw) {
|
|
43
47
|
const node = nonNull(schema, raw);
|
|
44
48
|
const ref = namedType(schema, raw);
|
|
45
49
|
const types = schemaTypes(node).filter((t) => t !== "null");
|
|
46
50
|
if (types.includes("array") && node.items) {
|
|
47
51
|
const item = node.items;
|
|
52
|
+
const shapes = shapeCount(schema, item);
|
|
53
|
+
if (shapes)
|
|
54
|
+
return `list of ${shapes} shapes`;
|
|
48
55
|
return `list of ${refName(item) ?? (schemaTypes(resolve(schema, item)).join("|") || "any")}`;
|
|
49
56
|
}
|
|
57
|
+
const shapes = ref ? undefined : shapeCount(schema, raw);
|
|
58
|
+
if (shapes)
|
|
59
|
+
return `one of ${shapes} shapes`;
|
|
50
60
|
return ref ?? (types.join("|") || "object");
|
|
51
61
|
}
|
|
52
62
|
function fieldsOf(schema, entry) {
|
|
@@ -253,7 +263,7 @@ function headLines(target, data, used) {
|
|
|
253
263
|
]);
|
|
254
264
|
}
|
|
255
265
|
const what = data.kind === "list" ? "a list of entries" : "one object";
|
|
256
|
-
const each = data.entry ? `, each
|
|
266
|
+
const each = data.entry ? `, each ${withArticle(data.entry)}` : "";
|
|
257
267
|
return keyValues([
|
|
258
268
|
[target.nested ? "field" : "section", `${target.name} (${what}${each})`],
|
|
259
269
|
["file", data.file ?? "(none)"],
|
|
@@ -264,7 +274,7 @@ const FIELD_COLUMNS = ["field", "type", "required", "notes"];
|
|
|
264
274
|
function shapeLines(data) {
|
|
265
275
|
const shapes = data.shapes ?? [];
|
|
266
276
|
const others = data.other_shapes ?? [];
|
|
267
|
-
const besides = others.length ? ` (${others.map(
|
|
277
|
+
const besides = others.length ? ` (${others.map(withArticle).join(", ")}, or an object below)` : "";
|
|
268
278
|
const lines = [`Each entry takes one of ${shapes.length + others.length} shapes${besides}:`, ""];
|
|
269
279
|
for (const shape of shapes) {
|
|
270
280
|
const example = data.kind === "list" ? [shape.example] : shape.example;
|
|
@@ -284,18 +294,22 @@ function fieldLines(data) {
|
|
|
284
294
|
lines.push("", "With one entry of each nested list:", yamlOf(data.nested_example));
|
|
285
295
|
if (data.nested.length) {
|
|
286
296
|
const rows = data.nested.map((n) => ({ command: `cavelon schema ${n.path}`, type: n.type }));
|
|
287
|
-
lines.push("", "Fields with fields of their own:", table(rows, ["command", "type"]));
|
|
297
|
+
lines.push("", "Fields with fields of their own:", table(rows, ["command", "type"], 60, ["command"]));
|
|
288
298
|
}
|
|
289
299
|
return lines;
|
|
290
300
|
}
|
|
301
|
+
function withArticle(type) {
|
|
302
|
+
return `${/^[aeiou]/i.test(type) ? "an" : "a"} ${type}`;
|
|
303
|
+
}
|
|
291
304
|
function targetLines(schema, target, data, used) {
|
|
292
305
|
const head = [headLines(target, data, used), ""];
|
|
293
306
|
if (data.shapes)
|
|
294
307
|
return [...head, ...shapeLines(data)];
|
|
295
308
|
if (data.example !== null)
|
|
296
309
|
return [...head, ...fieldLines(data)];
|
|
297
|
-
const others = objectShapes(schema, target.node)
|
|
298
|
-
|
|
310
|
+
const { list, others } = objectShapes(schema, target.node);
|
|
311
|
+
const type = others.map(withArticle).join(" or ") || withArticle(typeOf(schema, entryOf(schema, target.node).entry));
|
|
312
|
+
return [...head, `${list ? "Each entry is" : "It is"} ${type}; there are no fields to list.`];
|
|
299
313
|
}
|
|
300
314
|
export const schema = {
|
|
301
315
|
name: "schema",
|