@cavelon/cli 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +58 -22
  2. package/dist/choose.js +8 -4
  3. package/dist/code-hints.js +74 -0
  4. package/dist/commands/api.js +83 -44
  5. package/dist/commands/async.js +26 -5
  6. package/dist/commands/chat.js +177 -0
  7. package/dist/commands/docs.js +240 -37
  8. package/dist/commands/fmt.js +120 -0
  9. package/dist/commands/index.js +9 -1
  10. package/dist/commands/init.js +64 -30
  11. package/dist/commands/inventory.js +48 -5
  12. package/dist/commands/limits-set.js +9 -6
  13. package/dist/commands/loops.js +15 -9
  14. package/dist/commands/models.js +16 -7
  15. package/dist/commands/sandboxes.js +8 -4
  16. package/dist/commands/schema.js +361 -0
  17. package/dist/commands/session.js +148 -24
  18. package/dist/commands/setup.js +22 -6
  19. package/dist/commands/solution.js +537 -76
  20. package/dist/commands/tenants.js +156 -15
  21. package/dist/commands/values.js +18 -9
  22. package/dist/commands/work.js +343 -35
  23. package/dist/confirm-token.js +72 -0
  24. package/dist/contracts.js +3 -0
  25. package/dist/default-route.js +21 -0
  26. package/dist/errors.js +4 -0
  27. package/dist/git.js +14 -5
  28. package/dist/harness-ref.js +14 -1
  29. package/dist/http.js +27 -4
  30. package/dist/invoke.js +8 -4
  31. package/dist/kit-codes.js +91 -0
  32. package/dist/limits.js +12 -1
  33. package/dist/local-state.js +32 -7
  34. package/dist/main.js +52 -4
  35. package/dist/mcp.js +72 -15
  36. package/dist/openapi.js +77 -21
  37. package/dist/operations.js +4 -3
  38. package/dist/package-check.js +361 -12
  39. package/dist/package-files.js +92 -45
  40. package/dist/package-format.js +222 -0
  41. package/dist/package-references.js +298 -0
  42. package/dist/preview-report.js +152 -0
  43. package/dist/results.js +21 -1
  44. package/dist/skills/cavelon-authoring/SKILL.md +98 -13
  45. package/dist/skills/cavelon-long-running/SKILL.md +3 -1
  46. package/dist/skills/cavelon-loop/SKILL.md +129 -21
  47. package/dist/skills/cavelon-testing/SKILL.md +130 -10
  48. package/dist/tenant-choice.js +31 -5
  49. package/dist/trace-view.js +172 -0
  50. package/package.json +1 -1
@@ -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
@@ -40,10 +42,16 @@ use it when you parse the result.
40
42
  - No `cavelon.yaml` here or above: for a new solution run
41
43
  `cavelon init --instance <url> --tenant <tenant> --harness <solution>`, where
42
44
  the tenant and the solution are each a name, slug or id; for an existing one
43
- add `cavelon pull` after it. To start from a package file (a blueprint, an
45
+ add `cavelon pull` after it. From your shell, `init --harness "<name>"`
46
+ creates a solution that does not exist yet as a draft; the MCP tool `init`
47
+ never creates one and names the `cavelon harness new <slug> --name "<name>"`
48
+ that does. `apply` never creates a solution: when the one an env file names
49
+ is missing it stops with `solution_not_found` and names that command. To start from a package file (a blueprint, an
44
50
  export from another instance), run
45
51
  `cavelon init --instance <url> --tenant <tenant> --from <file>` instead of
46
- splitting it by hand or importing it in the Admin. Never guess a tenant or a
52
+ splitting it by hand or importing it in the Admin; from your shell it creates
53
+ the package's only solution as a draft when the tenant lacks it (the MCP tool
54
+ names the `cavelon harness new` command instead). Never guess a tenant or a
47
55
  solution, and never ask the person for an id they would have to look up:
48
56
  `cavelon tenant list --json` and `cavelon harness list --json` list the
49
57
  names, slugs and ids to choose from, and the person names one by its name.
@@ -54,29 +62,70 @@ use it when you parse the result.
54
62
 
55
63
  1. **Pull** what is live: `cavelon pull`. It refuses when `package/` has
56
64
  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.
65
+ commit or apply them first. A file as the last pull or confirmed apply left
66
+ it counts as unchanged, so a pull right after an apply goes ahead without a
67
+ commit. `git diff` then shows what someone changed in the Admin. A test
68
+ suite goes back to the file it came from, whatever its name. A solution's
69
+ pull leaves the tenant-wide sections (the tenant's settings, its model
70
+ list) out of the folder; `--tenant-wide` writes them, and `apply` then
71
+ sends them for the whole tenant, so only with the person's say-so.
59
72
  2. **Edit** the files in `package/` (one file per schema section) and `tests/`
60
73
  (one file per test suite). See the cavelon-authoring skill.
61
74
  3. **Validate** offline: `cavelon validate`. Fix every error; `cavelon explain
62
- <code>` says what a code means and how to fix it.
75
+ <code>` says what a code means and how to fix it. Besides the schema it
76
+ finds duplicate slugs, handoffs and test assertions naming an agent the
77
+ package lacks, fields the schema does not have (with "did you mean"), and
78
+ skills, tools, knowledge bases, solutions and models the tenant does not
79
+ hold (warnings: `cavelon pull` or `cavelon models list` refreshes that
80
+ list; validate reads a list no command has read yet). The preview blocks
81
+ those names, so validate does not say "Valid" while one is left;
82
+ `cavelon validate --strict` fails on every warning. A line `Not checked:`
83
+ names a check it could not make (offline, no list). After writing files by
84
+ hand, run `cavelon fmt`: it fills in the defaults the export writes and
85
+ numbers test cases in their written order, so the first `pull` after the
86
+ apply rewrites only what changed on the instance.
63
87
  4. **Preview**: `cavelon apply --env test` (or `--harness <name or slug>`). Nothing is
64
88
  imported yet. Read the preview: what is created, updated or deleted, which
65
89
  active solutions it reaches, what the target still needs (variables and
66
90
  secrets with the command that sets each, OAuth grants, runtime bindings,
67
- trigger identities), loop budgets, and what the instance ignores.
91
+ trigger identities), loop budgets, and what the instance ignores. A recent
92
+ instance also lists each field it changes (`field changes`, `object.field:
93
+ old → new`) and the fields it does not apply ("not applied", with the
94
+ command that sets each). A blocked preview names each blocker with its
95
+ code, package file and path, and hint; `cavelon explain <code>` says more.
68
96
  5. **Confirm** exactly that preview: `cavelon apply --confirm <preview-id>`
69
- (the line `apply` printed, with the same `--env` and `--tenant`). Exit 4 means the target changed since the preview:
70
- preview again and confirm the new id. When the error lists `blockers`, the
71
- import's own check found them as it applied: fix what each names (the hint
72
- says how for a code the kit knows), then preview again.
97
+ (the line `apply` printed, with the same `--env` and `--tenant`). Exit 4
98
+ means the preview is stale and nothing was imported: the target changed on
99
+ the instance (`import_preview_stale`), the package files changed since
100
+ (`preview_files_changed`, naming them), or the preview is more than a day
101
+ old (`preview_expired`). Preview again, show the new preview when the rules
102
+ below say so, and confirm the new id. Use `--allow-stale` only when the
103
+ person wants exactly the old preview imported. When the error lists
104
+ `blockers`, the import's own check found them as it applied: fix what each
105
+ names (the hint says how for a code the kit knows), then preview again.
106
+ Discard a preview you will not confirm (`cavelon apply --discard <id>`, or
107
+ `--discard all`), so no later agent confirms it; `cavelon status` lists the
108
+ open ones with when each expires.
73
109
  6. **Seed** knowledge when needed: `cavelon kb upload <dir> --kb <kb>`. It
74
110
  refuses before sending when a file is larger than the instance allows or of
75
111
  a type it does not accept, and a `.zip` unless the tenant has archive
76
112
  uploads on (`kb_upload_archive_enabled`) and it stays within their file
77
113
  count, unpacked size and compression ratio (exit 3, naming the limit and who
78
- changes it). A test
79
- Sandbox gets its files with `cavelon sandbox seed <sandbox> <folder>`
114
+ changes it).
115
+ **Updating a document**: upload the new version under the same file name.
116
+ `kb upload` names each file that matches an active document of the
117
+ knowledge base, and what happens to it depends on the instance (try it with
118
+ `--dry-run` first):
119
+ - An instance that replaces same-named documents does so on every upload:
120
+ "faq.md exists (0f3c…) and is replaced by the upload (--keep-both keeps
121
+ it)". `--keep-both` keeps both.
122
+ - On an older instance the old version stays active next to the new one,
123
+ and both answer: "faq.md exists (0f3c…) and stays active". Upload with
124
+ `--replace`: where the instance's upload can replace by id, the old
125
+ document is replaced once the new file is verified; where it cannot,
126
+ `--replace` shows the documents it would deactivate after the upload and
127
+ needs `--confirm`: show the person that first.
128
+ A test Sandbox gets its files with `cavelon sandbox seed <sandbox> <folder>`
80
129
  (isolated container) or `cavelon sandbox refresh <sandbox>` after the files
81
130
  were put on the VM (customer VM).
82
131
  7. **Test**: `cavelon test run --suite <suite>`, then `cavelon wait <operation>`.
@@ -86,6 +135,34 @@ use it when you parse the result.
86
135
  8. **Fix** what the results and traces show, and go back to step 2. Commit
87
136
  when a step works.
88
137
 
138
+ ## The default route
139
+
140
+ A tenant answers its chat and widget, where a conversation names no solution,
141
+ with one solution: its **default route**. A fresh tenant's default is an empty
142
+ `default` solution, so a new solution built beside it answers nobody there.
143
+ `cavelon harness list` marks the default (DEFAULT), and `cavelon activate`
144
+ says when the solution it activated is not the default.
145
+
146
+ - **Ask the person** whether the new solution should become the default. It
147
+ changes live traffic; never decide it yourself.
148
+ - With their yes: `cavelon activate --make-default` (or `cavelon harness
149
+ default <solution>`) shows the change, naming the current default; show it,
150
+ then run the confirm command it printed (from your shell it carries the
151
+ change's token: `--confirm <token>`). `harness default` refuses a draft
152
+ (`solution_not_active`, exit 4): only an active solution can be the
153
+ default, so use `cavelon activate --make-default`.
154
+ - `is_default` in `harnesses.yaml` is not applied by `apply`; the preview
155
+ lists it under "not applied".
156
+ - To try an active solution that is not the default, talk to it by name:
157
+ `cavelon chat "<message>" --harness <solution>` (the `chat` tool over MCP)
158
+ prints its answer, the session to continue with `--session`, and the
159
+ conversation to trace. A draft answers only a person's token, as a
160
+ Playground run.
161
+ - `cavelon deactivate --harness <solution>` takes an active solution out of
162
+ live traffic: it previews, and only `--confirm` deactivates. It is the
163
+ person's decision, like the default route; the default route itself is
164
+ refused until another solution is the default.
165
+
89
166
  ## Show the person before confirming
90
167
 
91
168
  Confirm on your own only for a draft solution in a test environment. Stop and
@@ -100,10 +177,35 @@ show the preview to the person, and confirm only after they agree, when:
100
177
 
101
178
  The same holds for the other commands that take `--confirm`: without it they
102
179
  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
180
+ identity <trigger> <key> --confirm` (it gives a trigger standing authority),
181
+ before `cavelon harness default … --confirm`, `cavelon activate
182
+ --make-default --confirm` or `cavelon deactivate --confirm` (they move live
183
+ traffic), and
104
184
  before `cavelon sandbox seed … --confirm` or `cavelon loop cancel … --confirm` on
105
185
  anything but a test Sandbox or a run you started yourself.
106
186
 
187
+ **Over MCP, confirm with the preview's token.** `api`, `limits_set`,
188
+ `models_set_limit`, `loop_cancel`, `sandbox_seed`, `trigger_identity`,
189
+ `harness_default`, `deactivate`, `activate` with `make_default`, and
190
+ `kb_upload` where it would deactivate documents return a `confirm_token` with
191
+ their preview. Show
192
+ the preview, then call the tool again with the same arguments and `confirm`
193
+ set to that token; it makes exactly the change shown. `confirm: true` is
194
+ refused (`confirm_token_required`), and a token of another change returns the
195
+ new preview with `token_mismatch` (exit code 4): show that one instead. Tool
196
+ arguments are spelled in snake_case (`make_default`, `keep_both`, `dry_run`);
197
+ an argument a tool does not list is refused (`unknown_argument`) with the
198
+ closest one named.
199
+
200
+ **From your shell, `--confirm` takes the same token.** Run by a coding agent,
201
+ `limits set`, `models set-limit`, `loop cancel`, `sandbox seed`,
202
+ `trigger identity`, `harness default`, `activate --make-default`,
203
+ `kb upload --replace`, `variables delete` and `secrets delete` print their
204
+ preview with a confirm token and the command that confirms it
205
+ (`… --confirm <token>`). Show the preview, then run exactly that command. A
206
+ bare `--confirm` changes nothing and exits 5; a token of another change exits
207
+ 4 with the new preview.
208
+
107
209
  **`cavelon api` from your shell has the guards of the MCP `api` tool**, since
108
210
  `cavelon` sees that a coding agent runs it (`CLAUDECODE`, `CODEX_THREAD_ID`, `CODEX_SANDBOX`,
109
211
  `CURSOR_AGENT`, `GEMINI_CLI`, `COPILOT_CLI`, `COPILOT_AGENT`, `AI_AGENT` or
@@ -115,7 +217,9 @@ anything but a test Sandbox or a run you started yourself.
115
217
  exactly that request. A changed body or parameter needs a new preview (exit 4).
116
218
  - It refuses an operation the instance keeps for a person
117
219
  (`operation_for_a_person`) and a body that sets a field the instance marks as
118
- a secret value (`secret_field_for_a_person`), with or without `--confirm`.
220
+ a secret value (`secret_field_for_a_person`), with or without `--confirm`,
221
+ with exit code 5 (needs a person). `cavelon api describe <operation>` shows
222
+ both marks up front.
119
223
  Tell the person what the error's hint says; for a secret field, send the rest
120
224
  without it and let the person enter the value (`cavelon secrets set <name>`
121
225
  or the Admin). Never work around a refusal, by unsetting the variable or by
@@ -155,8 +259,10 @@ return operation ids at once. `cavelon wait <ids> --timeout 90s` returns the
155
259
  state when the time is up (exit 6 means still running; the same `wait` again
156
260
  resumes). Keep each wait under your shell's command time limit, and run longer
157
261
  waits in the background if your client can. Over MCP, the `operation_status`
158
- tool reads an operation without blocking. Exit 5 means a person must act (an
159
- approval, a paused loop): tell them, with the link `wait` prints.
262
+ tool returns the state at once, or, given a `timeout`, waits up to it (at most
263
+ 50 seconds) and reports `waited_ms`; `timed_out` is true only when it waited
264
+ the whole timeout. Exit 5 means a person must act (an approval, a paused
265
+ loop): tell them, with the link `wait` prints.
160
266
 
161
267
  **Never approve anything.** An approval is decided by a person, or by an API
162
268
  key an owner granted the explicit scope `approvals.decide`; never by you, and
@@ -174,9 +280,11 @@ preview · 5 needs a person · 6 timed out (still running) · 7 not authorised
174
280
  ## Where to read more
175
281
 
176
282
  - `cavelon docs search <query>` and `cavelon docs get <page>`: the instance's
177
- own docs, for its version.
178
- - `.cavelon/inventory.md`: the tenant's solutions, knowledge bases, tools, test
179
- suites and sandboxes from the last pull; `cavelon sandbox list` for their
283
+ own docs, for its version. They are in English; a German question works for
284
+ the core concepts, English words for the rest. `cavelon docs get index`
285
+ lists every page.
286
+ - `.cavelon/inventory.md`: the tenant's solutions, knowledge bases, tools,
287
+ skills, models, test suites and sandboxes from the last pull; `cavelon sandbox list` for their
180
288
  current state and mode.
181
289
  - `cavelon api list --search <word>` and `cavelon api <operation>`: any API
182
290
  operation the workflow commands do not cover.
@@ -22,11 +22,69 @@ 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 (`cavelon schema
76
+ test_suites.test_cases.steps.evaluation_criteria` lists each shape): a
77
+ misspelt `type` is one error with the closest type, an `answered_by` or
78
+ `handoff_to` naming an agent the package lacks is an error, and a
79
+ `tool_called` or `tool_not_called` naming a tool that is nowhere is a warning,
80
+ each with "did you mean". Cases and steps run in their written order once
81
+ `cavelon fmt` has numbered them (`sort_order`, `step_order`); left out, the
82
+ instance orders cases by name. Where the schema does not describe a step's criteria, it
83
+ warns `test_assertion_unchecked`: an instance that does not know a type grades
84
+ it as a judge criterion instead of checking it, so read `cavelon docs get
85
+ concepts/regression-testing` for the types the instance knows before relying on
86
+ `answered_by` or `handoff_to`.
87
+
30
88
  ## Testing an approval
31
89
 
32
90
  A test run never waits for a person and never approves anything. A run that
@@ -78,7 +136,7 @@ The case's own reason (which knowledge base, which value) is in the output of
78
136
  ## Reading what happened
79
137
 
80
138
  ```bash
81
- cavelon trace <test-run-id or operation-id> # cases, scores, judge's reasoning
139
+ cavelon trace <test-run-id or operation-id> # cases, assertions, answers, judge's reasoning
82
140
  cavelon trace <conversation-id> --kind conversation # one case's traces
83
141
  cavelon trace <conversation-id> --kind conversation --trace <trace-id> # one trace's spans
84
142
  cavelon trace <conversation-id> --kind conversation --trace <trace-id> --span <span-id>
@@ -90,22 +148,84 @@ retrieval). Output is bounded; run the command each level prints as printed: it
90
148
  carries the id its route needs. A case's traces are under its
91
149
  `conversation_id` (a trigger case's under its `run_id`, `--kind trigger`), not
92
150
  under the test run's id; a wrong id answers with a hint naming the right one.
93
- A low-scoring pass shows the judge's reasoning too.
151
+ The spans list suggests the span to open first: the one that failed, else the
152
+ last model call, else the knowledge search.
153
+
154
+ Each step lists its assertions with pass or FAIL (`Assertions (1 of 2
155
+ passed)`, then one line each with the expected and observed value of a failed
156
+ one and the reasoning), the judge's criteria with their scores, and the
157
+ answer it judged, shortened (`assertions[]` and `answer` in `--json`; the
158
+ whole answer with `--full`). Read the assertions, not only the judge's
159
+ sentence: "meets the only criterion" can stand above a failed `answered_by`.
160
+ `test run --wait` names a failed case's failed assertions and its answer too.
161
+ Each step names the agent that answered it (AGENT, `agent` in `--json`), and a
162
+ case that did not pass says `Answered by: <agent>`: the first thing to check
163
+ when a routing assertion failed.
164
+
165
+ A knowledge search's retrieval span (`--span <span-id>`) shows the query, its
166
+ `knowledge_outcome` and the hits as a table (rank, title, score, whether it
167
+ may be cited, document id); `retrieval` in `--json`. Its tool span shows the
168
+ outcome too; a search without one is one the agent did not classify, and an
169
+ instance that records none shows no such column. The agent records one of four
170
+ values, and the trace refines `no_usable_evidence` by what the search returned,
171
+ so the trace never shows that value itself (`cavelon explain <value>` says
172
+ more, from the instance's catalog where it lists them):
173
+
174
+ | The agent records | The retrieval span shows | When |
175
+ |---|---|---|
176
+ | `usable_evidence` | `usable_evidence` | The hits support the answer |
177
+ | `no_usable_evidence` | `content_gap` | The search returned no hits at all |
178
+ | `no_usable_evidence` | `unusable_hits` | It returned hits, and none answers the question |
179
+ | `no_usable_evidence` | `retrieval_fault` | The search failed, returned a partial result, or had no knowledge base it may read |
180
+ | `retrieval_fault` | `retrieval_fault` | The agent saw the search report a fault |
181
+ | `deliberately_unanswerable` | `deliberately_unanswerable` | Policy or the request, not missing content, made the agent decline |
94
182
 
95
- ## Optimizing
183
+ A question the knowledge base does not cover usually shows as `unusable_hits`,
184
+ not `content_gap`: a search almost always returns its closest passages. Read
185
+ both as a gap to fill.
96
186
 
97
- Change one thing at a time, then run the same suite again and compare:
187
+ ## Optimizing
98
188
 
99
- - **Wrong or missing facts:** check retrieval first (which chunks came back in
100
- the retrieval span). Fix the documents or the knowledge base's settings
101
- before the prompt.
189
+ Change one thing at a time, then run the whole suite again and compare, not
190
+ only the case that failed: a prompt change that fixes one case can break
191
+ another. In one solution, a line "just answer directly" made the agent answer
192
+ an off-topic question its persona forbade.
193
+
194
+ - **Wrong or missing facts:** check retrieval first. Under a case that did not
195
+ pass, `cavelon trace <run>` shows a `Knowledge:` line with the outcomes of
196
+ its knowledge searches (`knowledge_outcomes` per case in `--json`; `null`
197
+ where the instance or the run recorded none), so a `content_gap` shows
198
+ before you open the case's spans. Then read which chunks came back in
199
+ the retrieval span, and its `knowledge_outcome`: `content_gap` means the
200
+ knowledge base lacks the answer, `unusable_hits` that what came back did not
201
+ answer it, `retrieval_fault` that the search failed). Fix the documents or
202
+ the knowledge base's settings before the prompt.
203
+ - **Wrong agent answered:** the handoff instructions of the entry agent, and
204
+ the target agent's description, decide where a question goes; fix those, and
205
+ keep the `answered_by` and `handoff_to` assertions that caught it.
102
206
  - **Wrong tool, or a tool called with bad arguments:** sharpen the tool's
103
207
  description and parameters, then the agent's instructions about when to use it.
104
208
  - **Right facts, poor answer:** adjust the agent's instructions; keep them short
105
209
  and specific.
210
+ - **A limit that does not hold** (the agent writes the poem it should decline):
211
+ a limit stated only in the persona's `persona_prompt` is weaker than a direct
212
+ instruction in the agent's `system_prompt`, most of all on small models. Put
213
+ the hard limit in the agent's `system_prompt` too, and keep a test case that
214
+ checks it.
106
215
  - **Too slow or too costly:** read the token counts and durations in the trace;
107
216
  a smaller model or fewer tool rounds often suffice for a step.
108
217
 
109
- Record why a change helped in the commit message. When every suite passes,
218
+ Record why a change helped in the commit message.
219
+
220
+ To try a question outside the suite, `cavelon chat "<message>" --harness
221
+ <solution>` (the `chat` tool over MCP) sends it to that solution and prints
222
+ the answer, the session to continue with `--session`, and the conversation to
223
+ trace. It reaches an active solution that is not the tenant's default route,
224
+ which the tenant's chat and widget never answer with; a draft answers only a
225
+ person's token, as a Playground run. `cavelon api chat` with `harness_id` in
226
+ the body does the same, but needs the id and a confirm. `cavelon deactivate
227
+ --harness <solution>` takes an active solution out of live traffic again; it
228
+ previews first and is the person's decision, so show the preview and confirm
229
+ only with their yes. When every suite passes,
110
230
  `cavelon activate --harness <name or slug>` goes through the readiness gate; if the
111
231
  token may not activate, a person activates in the Admin.
@@ -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" };
@@ -91,3 +98,22 @@ export function tenantMissError(ref, pool, reachesAll, from) {
91
98
  details: { tenants: listed.map((t) => ({ id: t.id, slug: t.slug, name: t.name })) },
92
99
  });
93
100
  }
101
+ export async function describeTenant(client, id) {
102
+ try {
103
+ const detail = await client.get(`/api/v1/tenants/${encodeURIComponent(id)}`, {
104
+ sendTenant: false,
105
+ headers: { "X-Tenant-Id": id },
106
+ allow: [400, 401, 403, 404, 405, 422],
107
+ });
108
+ const name = typeof detail.data?.name === "string" && detail.data.name ? detail.data.name : undefined;
109
+ const slug = typeof detail.data?.slug === "string" && detail.data.slug ? detail.data.slug : undefined;
110
+ if (detail.status === 200 && (name || slug))
111
+ return { ...(name ? { name } : {}), ...(slug ? { slug } : {}) };
112
+ const found = await readTenantless(client, { search: id });
113
+ const hit = found && !found.refused ? found.tenants?.find((t) => t.id === id) : undefined;
114
+ return hit ? { ...(hit.name ? { name: hit.name } : {}), ...(hit.slug ? { slug: hit.slug } : {}) } : {};
115
+ }
116
+ catch {
117
+ return {};
118
+ }
119
+ }
@@ -0,0 +1,172 @@
1
+ import { clip } from "./format.js";
2
+ const REASONING_CHARS = 300;
3
+ const VALUE_CHARS = 120;
4
+ const record = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
5
+ const text = (value) => (typeof value === "string" && value.trim() ? value : null);
6
+ const brief = (value, max) => (typeof value === "string" ? clip(value, max) : value);
7
+ export function stepAssertions(breakdown, full = false) {
8
+ const b = record(breakdown);
9
+ if (!b)
10
+ return [];
11
+ const max = full ? Number.MAX_SAFE_INTEGER : REASONING_CHARS;
12
+ const out = [];
13
+ for (const raw of Array.isArray(b.deterministic_criteria) ? b.deterministic_criteria : []) {
14
+ const c = record(raw);
15
+ if (!c)
16
+ continue;
17
+ const type = text(c.type) ?? "assertion";
18
+ out.push({
19
+ type,
20
+ label: text(c.label) ?? type,
21
+ passed: typeof c.passed === "boolean" ? c.passed : null,
22
+ ...("expected" in c ? { expected: brief(c.expected, full ? max : VALUE_CHARS) } : {}),
23
+ ...("observed" in c ? { observed: brief(c.observed, full ? max : VALUE_CHARS) } : {}),
24
+ reasoning: text(c.reasoning) ? clip(text(c.reasoning), max) : null,
25
+ });
26
+ }
27
+ for (const raw of Array.isArray(b.criteria) ? b.criteria : []) {
28
+ const c = record(raw);
29
+ const criterion = c && text(c.criterion);
30
+ if (!c || !criterion)
31
+ continue;
32
+ out.push({
33
+ type: "judge",
34
+ label: clip(criterion, full ? max : VALUE_CHARS),
35
+ passed: null,
36
+ score: typeof c.score === "number" ? c.score : null,
37
+ reasoning: text(c.reasoning) ? clip(text(c.reasoning), max) : null,
38
+ });
39
+ }
40
+ return out;
41
+ }
42
+ export function assertionCount(assertions) {
43
+ const judged = assertions.filter((a) => a.passed !== null);
44
+ if (!judged.length)
45
+ return undefined;
46
+ return `${judged.filter((a) => a.passed).length} of ${judged.length} passed`;
47
+ }
48
+ function assertionName(a) {
49
+ if (a.type === "judge")
50
+ return `criterion "${a.label}"`;
51
+ return a.label === a.type ? a.type : `${a.label} [${a.type}]`;
52
+ }
53
+ export function assertionLine(a) {
54
+ const mark = a.passed === true ? "pass" : a.passed === false ? "FAIL" : a.score !== null && a.score !== undefined ? `score ${a.score}` : "judged";
55
+ const values = a.passed === false && ("expected" in a || "observed" in a)
56
+ ? ` (expected ${JSON.stringify(a.expected ?? null)}, observed ${JSON.stringify(a.observed ?? null)})`
57
+ : "";
58
+ return `${mark} ${assertionName(a)}${values}${a.reasoning ? `: ${a.reasoning}` : ""}`;
59
+ }
60
+ export function failedAssertions(breakdown) {
61
+ return stepAssertions(breakdown)
62
+ .filter((a) => a.passed === false)
63
+ .map(assertionName);
64
+ }
65
+ export function spanAttributes(value) {
66
+ let current = value;
67
+ for (let i = 0; i < 3 && typeof current === "string"; i++) {
68
+ const trimmed = current.trim();
69
+ if (!trimmed.startsWith("{") && !trimmed.startsWith('"'))
70
+ return undefined;
71
+ try {
72
+ current = JSON.parse(trimmed);
73
+ }
74
+ catch {
75
+ return undefined;
76
+ }
77
+ }
78
+ return record(current);
79
+ }
80
+ const num = (value) => (typeof value === "number" && Number.isFinite(value) ? value : null);
81
+ export function retrievalView(attributes) {
82
+ if (!attributes)
83
+ return undefined;
84
+ const sources = Array.isArray(attributes.sources) ? attributes.sources : [];
85
+ const query = text(attributes.query) ?? text(record(attributes.pipeline_metadata)?.query);
86
+ if (!query && !sources.length && !("knowledge_outcome" in attributes) && !("source_count" in attributes))
87
+ return undefined;
88
+ const hits = sources
89
+ .map((raw, index) => {
90
+ const s = record(raw);
91
+ if (!s)
92
+ return undefined;
93
+ return {
94
+ rank: num(s.rank) ?? index + 1,
95
+ title: text(s.title) ?? text(s.filename),
96
+ score: num(s.score),
97
+ citation_state: text(s.citation_state),
98
+ cited: typeof s.cited === "boolean" ? s.cited : null,
99
+ document_id: text(s.document_id),
100
+ knowledge_base_id: text(s.knowledge_base_id),
101
+ };
102
+ })
103
+ .filter((h) => Boolean(h));
104
+ const status = text(attributes.retrieval_status) ?? text(record(attributes.pipeline_metadata)?.retrieval_status);
105
+ return {
106
+ query,
107
+ knowledge_outcome: text(attributes.knowledge_outcome),
108
+ source_count: num(attributes.source_count) ?? (hits.length ? hits.length : null),
109
+ sources: hits,
110
+ sources_total: num(attributes.sources_total),
111
+ retrieval_status: status,
112
+ };
113
+ }
114
+ export function retrievalRows(view) {
115
+ return view.sources.map((h) => ({
116
+ rank: h.rank,
117
+ title: h.title,
118
+ score: h.score === null ? null : Math.round(h.score * 1000) / 1000,
119
+ citable: h.citation_state === null ? null : h.citation_state === "citable" ? "yes" : "no",
120
+ cited: h.cited === false ? "no" : null,
121
+ document_id: h.document_id,
122
+ }));
123
+ }
124
+ export function suggestedSpan(spans) {
125
+ const inOrder = spans.slice().sort((a, b) => (a.sequence ?? 0) - (b.sequence ?? 0));
126
+ const last = (pick) => inOrder.filter(pick).pop();
127
+ return (last((s) => Boolean(s.error_json) || s.status === "error" || s.status === "errored") ??
128
+ last((s) => s.span_type === "llm") ??
129
+ last((s) => s.span_type === "retrieval") ??
130
+ last((s) => Boolean(s.parent_span_id)) ??
131
+ inOrder[0]);
132
+ }
133
+ export const KNOWLEDGE_OUTCOME_AREA = "knowledge_outcome";
134
+ export const KNOWLEDGE_OUTCOME_PAGE = "concepts/regression-testing";
135
+ export const KNOWLEDGE_OUTCOMES = [
136
+ {
137
+ value: "usable_evidence",
138
+ message: "The agent recorded usable_evidence: what this search returned supports the answer.",
139
+ hint: "Nothing to fix. The answer's sources come from this search's hits.",
140
+ },
141
+ {
142
+ value: "content_gap",
143
+ recorded_as: "no_usable_evidence",
144
+ message: "The agent recorded no_usable_evidence and the search returned no hits at all.",
145
+ hint: "Add a document that answers the question, or check that the knowledge base the agent searches holds it.",
146
+ },
147
+ {
148
+ value: "unusable_hits",
149
+ recorded_as: "no_usable_evidence",
150
+ message: "The agent recorded no_usable_evidence although the search returned hits: none of them answers the question. A question the knowledge base does not cover usually shows here, not as content_gap, because a search almost always returns its closest passages.",
151
+ hint: "Read the hits on the retrieval span (`cavelon trace … --span <span_id>`). Add the missing content, or improve the document whose passage should have answered it.",
152
+ },
153
+ {
154
+ value: "retrieval_fault",
155
+ message: "The search failed technically: the agent recorded retrieval_fault, or it recorded no_usable_evidence for a search that reported an error, a partial or unavailable result, or no knowledge base it may read.",
156
+ hint: "Read the retrieval span's status and attributes, fix the knowledge base binding or the service, and ask again.",
157
+ },
158
+ {
159
+ value: "deliberately_unanswerable",
160
+ message: "The agent recorded deliberately_unanswerable: policy or the nature of the request, not missing content, made it decline.",
161
+ hint: "Nothing to add to the knowledge base. Change the agent's instructions if it should answer.",
162
+ },
163
+ {
164
+ value: "no_usable_evidence",
165
+ message: "What the agent records when a search's result cannot support the answer. The trace never shows it: it shows content_gap (no hits), unusable_hits (hits, none usable) or retrieval_fault (the search failed).",
166
+ hint: "Look up the value on the search's retrieval span: `cavelon explain <value>`.",
167
+ },
168
+ ];
169
+ export function knowledgeOutcome(code) {
170
+ const wanted = code.trim().toLowerCase().replaceAll(" ", "_").replaceAll("-", "_");
171
+ return KNOWLEDGE_OUTCOMES.find((o) => o.value === wanted);
172
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cavelon/cli",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
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",