@cavelon/cli 0.1.3 → 0.1.5

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.
Files changed (43) hide show
  1. package/README.md +43 -17
  2. package/dist/agent-env.js +24 -0
  3. package/dist/choose.js +8 -4
  4. package/dist/code-hints.js +74 -0
  5. package/dist/commands/api.js +174 -33
  6. package/dist/commands/async.js +26 -5
  7. package/dist/commands/docs.js +183 -37
  8. package/dist/commands/fmt.js +117 -0
  9. package/dist/commands/index.js +6 -1
  10. package/dist/commands/init.js +28 -6
  11. package/dist/commands/inventory.js +27 -5
  12. package/dist/commands/models.js +7 -1
  13. package/dist/commands/schema.js +193 -0
  14. package/dist/commands/session.js +69 -13
  15. package/dist/commands/solution.js +275 -36
  16. package/dist/commands/tenants.js +125 -15
  17. package/dist/commands/work.js +245 -24
  18. package/dist/contracts.js +3 -0
  19. package/dist/default-route.js +21 -0
  20. package/dist/errors.js +4 -0
  21. package/dist/git.js +14 -5
  22. package/dist/http.js +27 -4
  23. package/dist/invoke.js +8 -4
  24. package/dist/kit-codes.js +85 -0
  25. package/dist/limits.js +12 -1
  26. package/dist/local-state.js +9 -2
  27. package/dist/main.js +16 -3
  28. package/dist/mcp.js +19 -8
  29. package/dist/openapi.js +91 -21
  30. package/dist/operations.js +4 -3
  31. package/dist/package-check.js +193 -4
  32. package/dist/package-files.js +21 -10
  33. package/dist/package-format.js +149 -0
  34. package/dist/package-references.js +231 -0
  35. package/dist/paths.js +4 -3
  36. package/dist/preview-report.js +152 -0
  37. package/dist/results.js +65 -5
  38. package/dist/skills/cavelon-authoring/SKILL.md +67 -8
  39. package/dist/skills/cavelon-long-running/SKILL.md +3 -1
  40. package/dist/skills/cavelon-loop/SKILL.md +75 -13
  41. package/dist/skills/cavelon-testing/SKILL.md +85 -4
  42. package/dist/tenant-choice.js +12 -5
  43. package/package.json +3 -3
@@ -14,8 +14,10 @@ use it when you parse the result.
14
14
  ## Before anything
15
15
 
16
16
  - `cavelon status` says which instance, tenant and solution this folder is
17
- bound to, the last pull and the open previews. `cavelon whoami` says who the
18
- token acts as and when it expires.
17
+ bound to, the solution's state (draft or active, whether it is ready to
18
+ activate, its latest test run), the last pull and the open previews.
19
+ `cavelon whoami` says who the token acts as, when it expires, whether it may
20
+ enter Platform mode and which tenants it reaches.
19
21
  - **Never handle a token.** If a command exits 7 (not authorised) or says no
20
22
  token, ask the person to run `cavelon login --instance <url>` themselves (in a
21
23
  terminal, or with a `!` prefix where your client offers one). Never ask them
@@ -54,17 +56,29 @@ use it when you parse the result.
54
56
 
55
57
  1. **Pull** what is live: `cavelon pull`. It refuses when `package/` has
56
58
  uncommitted changes (outside git: files changed since the last pull);
57
- commit or apply them first. `git diff` then shows what someone changed
58
- in the Admin.
59
+ commit or apply them first. A file as the last pull or confirmed apply left
60
+ it counts as unchanged, so a pull right after an apply goes ahead without a
61
+ commit. `git diff` then shows what someone changed in the Admin.
59
62
  2. **Edit** the files in `package/` (one file per schema section) and `tests/`
60
63
  (one file per test suite). See the cavelon-authoring skill.
61
64
  3. **Validate** offline: `cavelon validate`. Fix every error; `cavelon explain
62
- <code>` says what a code means and how to fix it.
65
+ <code>` says what a code means and how to fix it. Besides the schema it
66
+ finds duplicate slugs, handoffs to an agent the package lacks, fields the
67
+ schema does not have (with "did you mean"), and skills, tools, knowledge
68
+ bases, solutions and models the tenant did not hold at the last pull
69
+ (warnings: `cavelon pull` or `cavelon models list` refreshes that list).
70
+ After writing files by hand, run `cavelon fmt`: it fills in the defaults
71
+ the export writes, so the first `pull` after the apply rewrites only what
72
+ changed on the instance.
63
73
  4. **Preview**: `cavelon apply --env test` (or `--harness <name or slug>`). Nothing is
64
74
  imported yet. Read the preview: what is created, updated or deleted, which
65
75
  active solutions it reaches, what the target still needs (variables and
66
76
  secrets with the command that sets each, OAuth grants, runtime bindings,
67
- trigger identities), loop budgets, and what the instance ignores.
77
+ trigger identities), loop budgets, and what the instance ignores. A recent
78
+ instance also lists each field it changes (`field changes`, `object.field:
79
+ old → new`) and the fields it does not apply ("not applied", with the
80
+ command that sets each). A blocked preview names each blocker with its
81
+ code, package file and path, and hint; `cavelon explain <code>` says more.
68
82
  5. **Confirm** exactly that preview: `cavelon apply --confirm <preview-id>`
69
83
  (the line `apply` printed, with the same `--env` and `--tenant`). Exit 4 means the target changed since the preview:
70
84
  preview again and confirm the new id. When the error lists `blockers`, the
@@ -75,7 +89,15 @@ use it when you parse the result.
75
89
  a type it does not accept, and a `.zip` unless the tenant has archive
76
90
  uploads on (`kb_upload_archive_enabled`) and it stays within their file
77
91
  count, unpacked size and compression ratio (exit 3, naming the limit and who
78
- changes it). A test
92
+ changes it).
93
+ **Updating a document**: upload the new version under the same file name
94
+ with `--replace` (try it with `--dry-run` first). Without it the old version
95
+ may stay active next to the new one, and both answer: `kb upload` names each
96
+ file that matches an active document ("bergbahn-faq.md exists (094e95e9…)
97
+ and stays active"). An instance that replaces same-named documents itself
98
+ does so on every upload (`--keep-both` keeps both); where the instance's
99
+ upload cannot replace, `--replace` shows the documents it would deactivate
100
+ after the upload and needs `--confirm`: show the person that first. A test
79
101
  Sandbox gets its files with `cavelon sandbox seed <sandbox> <folder>`
80
102
  (isolated container) or `cavelon sandbox refresh <sandbox>` after the files
81
103
  were put on the VM (customer VM).
@@ -86,6 +108,22 @@ use it when you parse the result.
86
108
  8. **Fix** what the results and traces show, and go back to step 2. Commit
87
109
  when a step works.
88
110
 
111
+ ## The default route
112
+
113
+ A tenant answers its chat and widget, where a conversation names no solution,
114
+ with one solution: its **default route**. A fresh tenant's default is an empty
115
+ `default` solution, so a new solution built beside it answers nobody there.
116
+ `cavelon harness list` marks the default (DEFAULT), and `cavelon activate`
117
+ says when the solution it activated is not the default.
118
+
119
+ - **Ask the person** whether the new solution should become the default. It
120
+ changes live traffic; never decide it yourself.
121
+ - With their yes: `cavelon activate --make-default` (or `cavelon harness
122
+ default <solution>`) shows the change, naming the current default; show it,
123
+ then run the same command with `--confirm`.
124
+ - `is_default` in `harnesses.yaml` is not applied by `apply`; the preview
125
+ lists it under "not applied".
126
+
89
127
  ## Show the person before confirming
90
128
 
91
129
  Confirm on your own only for a draft solution in a test environment. Stop and
@@ -100,10 +138,30 @@ show the preview to the person, and confirm only after they agree, when:
100
138
 
101
139
  The same holds for the other commands that take `--confirm`: without it they
102
140
  only show what would happen. Show it to the person before `cavelon trigger
103
- identity <trigger> <key> --confirm` (it gives a trigger standing authority), and
141
+ identity <trigger> <key> --confirm` (it gives a trigger standing authority),
142
+ before `cavelon harness default … --confirm` or `cavelon activate
143
+ --make-default --confirm` (it moves live traffic), and
104
144
  before `cavelon sandbox seed … --confirm` or `cavelon loop cancel … --confirm` on
105
145
  anything but a test Sandbox or a run you started yourself.
106
146
 
147
+ **`cavelon api` from your shell has the guards of the MCP `api` tool**, since
148
+ `cavelon` sees that a coding agent runs it (`CLAUDECODE`, `CODEX_THREAD_ID`, `CODEX_SANDBOX`,
149
+ `CURSOR_AGENT`, `GEMINI_CLI`, `COPILOT_CLI`, `COPILOT_AGENT`, `AI_AGENT` or
150
+ `CAVELON_AGENT=1`):
151
+
152
+ - For an operation that is not read-only, it prints the request and a confirm
153
+ token and sends nothing. Show the request to the person when the rules above
154
+ say so, then run the same command again with `--confirm <token>`; it sends
155
+ exactly that request. A changed body or parameter needs a new preview (exit 4).
156
+ - It refuses an operation the instance keeps for a person
157
+ (`operation_for_a_person`) and a body that sets a field the instance marks as
158
+ a secret value (`secret_field_for_a_person`), with or without `--confirm`.
159
+ Tell the person what the error's hint says; for a secret field, send the rest
160
+ without it and let the person enter the value (`cavelon secrets set <name>`
161
+ or the Admin). Never work around a refusal, by unsetting the variable or by
162
+ any other way.
163
+ - Its `@file` body, `--file` and `--output` stay inside the solution folder.
164
+
107
165
  `activate` goes through the readiness gate only, and only with a token that
108
166
  may activate. It never forces: activating without the evidence stays a person's
109
167
  decision in the Admin, so do not ask for it as a shortcut.
@@ -137,8 +195,10 @@ return operation ids at once. `cavelon wait <ids> --timeout 90s` returns the
137
195
  state when the time is up (exit 6 means still running; the same `wait` again
138
196
  resumes). Keep each wait under your shell's command time limit, and run longer
139
197
  waits in the background if your client can. Over MCP, the `operation_status`
140
- tool reads an operation without blocking. Exit 5 means a person must act (an
141
- approval, a paused loop): tell them, with the link `wait` prints.
198
+ tool returns the state at once, or, given a `timeout`, waits up to it (at most
199
+ 50 seconds) and reports `waited_ms`; `timed_out` is true only when it waited
200
+ the whole timeout. Exit 5 means a person must act (an approval, a paused
201
+ loop): tell them, with the link `wait` prints.
142
202
 
143
203
  **Never approve anything.** An approval is decided by a person, or by an API
144
204
  key an owner granted the explicit scope `approvals.decide`; never by you, and
@@ -156,9 +216,11 @@ preview · 5 needs a person · 6 timed out (still running) · 7 not authorised
156
216
  ## Where to read more
157
217
 
158
218
  - `cavelon docs search <query>` and `cavelon docs get <page>`: the instance's
159
- own docs, for its version.
160
- - `.cavelon/inventory.md`: the tenant's solutions, knowledge bases, tools, test
161
- suites and sandboxes from the last pull; `cavelon sandbox list` for their
219
+ own docs, for its version. They are in English; a German question works for
220
+ the core concepts, English words for the rest. `cavelon docs get index`
221
+ lists every page.
222
+ - `.cavelon/inventory.md`: the tenant's solutions, knowledge bases, tools,
223
+ skills, models, test suites and sandboxes from the last pull; `cavelon sandbox list` for their
162
224
  current state and mode.
163
225
  - `cavelon api list --search <word>` and `cavelon api <operation>`: any API
164
226
  operation the workflow commands do not cover.
@@ -22,11 +22,62 @@ Write cases for:
22
22
 
23
23
  - the questions the solution exists for, with the facts a good answer needs;
24
24
  - edge cases: out of scope, ambiguous, a follow-up in the same conversation;
25
- - the tools it must call, and the ones it must not;
26
- - what it must refuse or hand over;
25
+ - the tools it must call, and the ones it must not (`tool_called`,
26
+ `tool_not_called`, below);
27
+ - what it must refuse or hand over, and to which agent (`handoff_to`,
28
+ `answered_by`);
27
29
  - in a pipeline with an approval: the cases that must reach it, and the ones
28
30
  that must not.
29
31
 
32
+ ## Assertions: tools and routing
33
+
34
+ A step's `evaluation_criteria` can hold, besides the judge's criteria (plain
35
+ sentences), **assertions**: objects with a `type` and a `value`, checked in
36
+ code before the judge runs. A failed assertion fails the step whatever the
37
+ judge says, so use them for facts with one right answer:
38
+
39
+ | Type | Value | Passes when |
40
+ |---|---|---|
41
+ | `tool_called` | tool slug | the step called the tool |
42
+ | `tool_not_called` | tool slug | the step did not call it |
43
+ | `answered_by` | agent slug | that agent produced the answer (it made the step's last model call) |
44
+ | `handoff_to` | agent slug | the step handed the turn to that agent |
45
+
46
+ The answer text cannot show which agent wrote it, so make routing part of the
47
+ regression wherever a solution has a handoff. For an entry agent that should
48
+ hand price questions to a ticket agent:
49
+
50
+ ```yaml
51
+ test_cases:
52
+ - name: Family ticket price goes to the ticket agent
53
+ steps:
54
+ - user_message: What does a family ticket cost?
55
+ evaluation_criteria:
56
+ - States the price of the family ticket.
57
+ - {type: handoff_to, value: ticket-agent}
58
+ - {type: answered_by, value: ticket-agent}
59
+ - {type: tool_called, value: search_documents}
60
+ - name: Opening hours stay with the front desk
61
+ steps:
62
+ - user_message: When are you open?
63
+ evaluation_criteria:
64
+ - States the opening hours.
65
+ - {type: answered_by, value: front-desk}
66
+ ```
67
+
68
+ `answered_by` with the entry agent's slug checks the opposite: that a question
69
+ stays where it is. A consulted agent is a tool call of the agent that consulted
70
+ it, which still answers, so check a consultation with `tool_called` and the
71
+ consult tool's name, not with `handoff_to`. Use the slugs from
72
+ `package/agents.yaml`.
73
+
74
+ `cavelon validate` checks the assertions against the instance's package
75
+ schema where the schema describes a step's criteria. Where it does not, it
76
+ warns `test_assertion_unchecked`: an instance that does not know a type grades
77
+ it as a judge criterion instead of checking it, so read `cavelon docs get
78
+ concepts/regression-testing` for the types the instance knows before relying on
79
+ `answered_by` or `handoff_to`.
80
+
30
81
  ## Testing an approval
31
82
 
32
83
  A test run never waits for a person and never approves anything. A run that
@@ -61,6 +112,20 @@ errors, no pass rate): it is no evidence the solution works, so do not go on to
61
112
  `activate`; find the cause and run again. Exit 5 means answers wait for a
62
113
  person's verdict or a value a case needs: tell the person.
63
114
 
115
+ Besides `pass`, `fail` and `error`, a case's step can end in a status that is
116
+ no verdict; `cavelon explain <status>` says what it means and what to do next:
117
+
118
+ | Status | Means | Next |
119
+ |---|---|---|
120
+ | `calibration_required` | Not run: a knowledge base it needs had no ready documents, or a `{{var:…}}` value was not set, when the run started (exit 5) | Wait for the documents or set the value, then start a new run |
121
+ | `pending_review` | Ran; the answer waits for a person's verdict, because Auto-Evaluate is off (exit 5) | Tell the person |
122
+ | `not_run` | The step produced no result: the run stopped or was cancelled first (exit 1) | `cavelon trace <run>`, fix the cause, run again |
123
+ | `skip` | A person parked the case with a Skip verdict, or the run was cancelled before it (exit 1) | Run again, or leave it to the person |
124
+ | `not_evaluated` | A preparation step (`evaluate: false`): it ran and is not scored | Nothing |
125
+
126
+ The case's own reason (which knowledge base, which value) is in the output of
127
+ `test run --wait`, `wait` and `cavelon trace <run>`.
128
+
64
129
  ## Reading what happened
65
130
 
66
131
  ```bash
@@ -78,13 +143,29 @@ carries the id its route needs. A case's traces are under its
78
143
  under the test run's id; a wrong id answers with a hint naming the right one.
79
144
  A low-scoring pass shows the judge's reasoning too.
80
145
 
146
+ Each step names the agent that answered it (AGENT, `agent` in `--json`), and a
147
+ case that did not pass says `Answered by: <agent>` under its reason: the first
148
+ thing to check when a routing assertion failed. A failed assertion's reason is
149
+ the case's reason, and `--json` carries each assertion's result in
150
+ `judge_breakdown.deterministic_criteria` (expected, observed, reasoning). A
151
+ knowledge search's spans show what the agent recorded the search found
152
+ (`knowledge_outcome`: `usable_evidence`, `content_gap`, `unusable_hits`,
153
+ `retrieval_fault` or `deliberately_unanswerable`) on the search's tool span
154
+ and its retrieval span; a search without one is one the agent did not
155
+ classify. An instance that records none shows no such column.
156
+
81
157
  ## Optimizing
82
158
 
83
159
  Change one thing at a time, then run the same suite again and compare:
84
160
 
85
161
  - **Wrong or missing facts:** check retrieval first (which chunks came back in
86
- the retrieval span). Fix the documents or the knowledge base's settings
87
- before the prompt.
162
+ the retrieval span, and its `knowledge_outcome`: `content_gap` means the
163
+ knowledge base lacks the answer, `unusable_hits` that what came back did not
164
+ answer it, `retrieval_fault` that the search failed). Fix the documents or
165
+ the knowledge base's settings before the prompt.
166
+ - **Wrong agent answered:** the handoff instructions of the entry agent, and
167
+ the target agent's description, decide where a question goes; fix those, and
168
+ keep the `answered_by` and `handoff_to` assertions that caught it.
88
169
  - **Wrong tool, or a tool called with bad arguments:** sharpen the tool's
89
170
  description and parameters, then the agent's instructions about when to use it.
90
171
  - **Right facts, poor answer:** adjust the agent's instructions; keep them short
@@ -17,7 +17,7 @@ export async function searchTenants(client, text) {
17
17
  const found = await readTenantless(client, { search: text });
18
18
  return found && !found.refused ? (found.tenants ?? []) : [];
19
19
  }
20
- export async function chooseTenant(ctx, client, reach) {
20
+ export async function chooseTenant(ctx, client, reach, options = {}) {
21
21
  const { tenants, reachesAll } = reach;
22
22
  if (!reachesAll && tenants.length === 1)
23
23
  return { kind: "chosen", tenant: tenants[0], how: "only" };
@@ -25,17 +25,24 @@ export async function chooseTenant(ctx, client, reach) {
25
25
  return { kind: "none" };
26
26
  if (!canAsk(ctx))
27
27
  return { kind: "open" };
28
- const intro = reachesAll
29
- ? `This token reaches every tenant on ${client.url}.${tenants.length ? " Yours:" : ""}`
30
- : `This token reaches ${tenants.length} tenants on ${client.url}:`;
28
+ const later = reachesAll && options.later;
29
+ const intro = later
30
+ ? `This token works in every tenant on ${client.url}, one at a time: \`cavelon use\` switches, ` +
31
+ `and --tenant or \`tenant:\` in cavelon.yaml choose one per command or per solution folder.${tenants.length ? "\nYours:" : ""}`
32
+ : reachesAll
33
+ ? `This token reaches every tenant on ${client.url}.${tenants.length ? " Yours:" : ""}`
34
+ : `This token reaches ${tenants.length} tenants on ${client.url}:`;
31
35
  const picked = await pick(ctx, {
32
36
  intro,
33
- question: "Which tenant?",
37
+ question: later ? "Which tenant to start in?" : "Which tenant?",
34
38
  items: tenants,
35
39
  extra: (t) => t.role ?? undefined,
36
40
  preferred: tenants.find((t) => t.is_default),
37
41
  search: reachesAll ? (text) => searchTenants(client, text) : undefined,
42
+ ...(later ? { later: "choose later" } : {}),
38
43
  });
44
+ if ("later" in picked)
45
+ return { kind: "later" };
39
46
  if (!("item" in picked))
40
47
  throw new Error("unreachable: the tenant list offers no other entry");
41
48
  return { kind: "chosen", tenant: picked.item, how: "picked" };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cavelon/cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "The cavelon binary: CLI and local MCP server for building Cavelon solutions with a coding agent.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/goodguys-gmbh/cavelon-dev-kit",
@@ -41,9 +41,9 @@
41
41
  "@napi-rs/keyring": "^2.1.0"
42
42
  },
43
43
  "devDependencies": {
44
- "@eslint/js": "^9.39.0",
44
+ "@eslint/js": "^10.0.1",
45
45
  "@types/node": "^20.19.0",
46
- "eslint": "^9.39.0",
46
+ "eslint": "^10.12.0",
47
47
  "typescript": "~5.9.3",
48
48
  "typescript-eslint": "^8.71.0",
49
49
  "vitest": "^4.0.0"