@cavelon/cli 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +56 -18
  2. package/dist/command.js +10 -0
  3. package/dist/commands/api.js +40 -36
  4. package/dist/commands/chat.js +183 -0
  5. package/dist/commands/docs.js +77 -9
  6. package/dist/commands/fmt.js +61 -6
  7. package/dist/commands/index.js +3 -0
  8. package/dist/commands/init.js +61 -26
  9. package/dist/commands/inventory.js +21 -0
  10. package/dist/commands/limits-set.js +10 -6
  11. package/dist/commands/loops.js +22 -11
  12. package/dist/commands/models.js +11 -7
  13. package/dist/commands/sandboxes.js +11 -5
  14. package/dist/commands/schema.js +230 -48
  15. package/dist/commands/session.js +100 -14
  16. package/dist/commands/setup.js +22 -6
  17. package/dist/commands/solution.js +493 -86
  18. package/dist/commands/tenants.js +43 -10
  19. package/dist/commands/values.js +20 -11
  20. package/dist/commands/work.js +167 -33
  21. package/dist/confirm-token.js +72 -0
  22. package/dist/format.js +4 -4
  23. package/dist/harness-ref.js +17 -4
  24. package/dist/http.js +6 -0
  25. package/dist/kit-codes.js +11 -1
  26. package/dist/local-state.js +46 -10
  27. package/dist/main.js +38 -6
  28. package/dist/mcp.js +65 -14
  29. package/dist/openapi.js +30 -0
  30. package/dist/package-check.js +206 -18
  31. package/dist/package-files.js +98 -40
  32. package/dist/package-format.js +81 -8
  33. package/dist/package-references.js +77 -10
  34. package/dist/results.js +21 -1
  35. package/dist/session.js +9 -0
  36. package/dist/skills/cavelon-authoring/SKILL.md +54 -21
  37. package/dist/skills/cavelon-long-running/SKILL.md +13 -9
  38. package/dist/skills/cavelon-loop/SKILL.md +124 -28
  39. package/dist/skills/cavelon-testing/SKILL.md +69 -16
  40. package/dist/tenant-choice.js +19 -0
  41. package/dist/trace-view.js +172 -0
  42. package/package.json +1 -1
@@ -14,7 +14,8 @@ 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 solution's state (draft or active, whether it is ready to
17
+ bound to, the solution's state (draft, active, or inactive after a
18
+ deactivate; whether it is ready to
18
19
  activate, its latest test run), the last pull and the open previews.
19
20
  `cavelon whoami` says who the token acts as, when it expires, whether it may
20
21
  enter Platform mode and which tenants it reaches.
@@ -42,10 +43,23 @@ use it when you parse the result.
42
43
  - No `cavelon.yaml` here or above: for a new solution run
43
44
  `cavelon init --instance <url> --tenant <tenant> --harness <solution>`, where
44
45
  the tenant and the solution are each a name, slug or id; for an existing one
45
- add `cavelon pull` after it. To start from a package file (a blueprint, an
46
+ add `cavelon pull` after it. From your shell, `init --harness "<name>"`
47
+ creates a solution that does not exist yet as a draft; the MCP tool `init`
48
+ never creates one and names the `cavelon harness new <slug> --name "<name>"`
49
+ that does. A name close to an existing solution's is refused as a likely
50
+ typo (`solution_not_found`, naming the closest ones, creating nothing): ask
51
+ the person whether they meant that one, and only for a new solution run
52
+ `cavelon init ... --harness "<name>" --new`. Until a `cavelon.yaml` exists,
53
+ pass `--tenant` (and `--instance`) to every command, `harness new` and
54
+ `pull` included: without it a command acts in the tenant `cavelon use`
55
+ chose, which may be another one. The commands `cavelon` prints carry the
56
+ `--tenant` you gave; run them as printed. `apply` never creates a solution: when the one an env file names
57
+ is missing it stops with `solution_not_found` and names that command. To start from a package file (a blueprint, an
46
58
  export from another instance), run
47
59
  `cavelon init --instance <url> --tenant <tenant> --from <file>` instead of
48
- splitting it by hand or importing it in the Admin. Never guess a tenant or a
60
+ splitting it by hand or importing it in the Admin; from your shell it creates
61
+ the package's only solution as a draft when the tenant lacks it (the MCP tool
62
+ names the `cavelon harness new` command instead). Never guess a tenant or a
49
63
  solution, and never ask the person for an id they would have to look up:
50
64
  `cavelon tenant list --json` and `cavelon harness list --json` list the
51
65
  names, slugs and ids to choose from, and the person names one by its name.
@@ -58,18 +72,33 @@ use it when you parse the result.
58
72
  uncommitted changes (outside git: files changed since the last pull);
59
73
  commit or apply them first. A file as the last pull or confirmed apply left
60
74
  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.
75
+ commit. `git diff` then shows what someone changed in the Admin. A test
76
+ suite goes back to the file it came from, whatever its name. A solution's
77
+ pull leaves the tenant-wide sections (the tenant's settings, its model
78
+ list) out of the folder, and `apply` leaves them out of the solution's
79
+ import. `pull --tenant-wide` writes them; `apply --tenant-wide` imports
80
+ them, for every solution of the tenant, so only with the person's say-so.
81
+ `validate` warns about a tenant-wide file in the folder
82
+ (`tenant_wide_section`); on an instance that does not publish
83
+ `include_tenant_wide`, `apply` imports such a file anyway and says so:
84
+ remove it unless the person wants it.
62
85
  2. **Edit** the files in `package/` (one file per schema section) and `tests/`
63
86
  (one file per test suite). See the cavelon-authoring skill.
64
87
  3. **Validate** offline: `cavelon validate`. Fix every error; `cavelon explain
65
88
  <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.
89
+ finds duplicate slugs, handoffs and test assertions naming an agent the
90
+ package lacks, fields the schema does not have (with "did you mean"), and
91
+ skills, tools, knowledge bases, solutions and models the tenant does not
92
+ hold (warnings: `cavelon pull` or `cavelon models list` refreshes that
93
+ list; validate reads a list no command has read yet). The preview blocks
94
+ those names, so validate does not say "Valid" while one is left;
95
+ `cavelon validate --strict` fails on every warning. A line `Not checked:`
96
+ names a check it could not make (offline, no list). After writing files by
97
+ hand, run `cavelon fmt`: it fills in the defaults the export writes and
98
+ numbers test cases in their written order, so the first `pull` after the
99
+ apply rewrites only what changed on the instance. It drops comments, as
100
+ pull does, and names each file whose comments it drops (`cavelon fmt
101
+ --check` says so first): keep notes the person needs elsewhere.
73
102
  4. **Preview**: `cavelon apply --env test` (or `--harness <name or slug>`). Nothing is
74
103
  imported yet. Read the preview: what is created, updated or deleted, which
75
104
  active solutions it reaches, what the target still needs (variables and
@@ -79,26 +108,49 @@ use it when you parse the result.
79
108
  old → new`) and the fields it does not apply ("not applied", with the
80
109
  command that sets each). A blocked preview names each blocker with its
81
110
  code, package file and path, and hint; `cavelon explain <code>` says more.
111
+ A preview that changes nothing says "Nothing to import" and stores no
112
+ preview: there is nothing to confirm.
82
113
  5. **Confirm** exactly that preview: `cavelon apply --confirm <preview-id>`
83
- (the line `apply` printed, with the same `--env` and `--tenant`). Exit 4 means the target changed since the preview:
84
- preview again and confirm the new id. When the error lists `blockers`, the
85
- import's own check found them as it applied: fix what each names (the hint
86
- says how for a code the kit knows), then preview again.
114
+ (the line `apply` printed, with the same `--env` and `--tenant`). Exit 4
115
+ means the preview is stale and nothing was imported: the target changed on
116
+ the instance (`import_preview_stale`; a recent instance names what changed), the package files changed since
117
+ (`preview_files_changed`, naming them), the preview is more than a day
118
+ old (`preview_expired`), another preview was imported after it
119
+ (`preview_superseded`), it was imported already (`preview_applied`), or it
120
+ was discarded (`preview_discarded`). Preview again, show the new preview when the rules
121
+ below say so, and confirm the new id. Use `--allow-stale` only when the
122
+ person wants exactly the old preview imported. When the error lists
123
+ `blockers`, the import's own check found them as it applied: fix what each
124
+ names (the hint says how for a code the kit knows), then preview again.
125
+ Discard a preview you will not confirm (`cavelon apply --discard <id>`, or
126
+ `--discard all`), so no later agent confirms it; `cavelon status` lists the
127
+ open ones with when each expires.
87
128
  6. **Seed** knowledge when needed: `cavelon kb upload <dir> --kb <kb>`. It
88
129
  refuses before sending when a file is larger than the instance allows or of
89
130
  a type it does not accept, and a `.zip` unless the tenant has archive
90
131
  uploads on (`kb_upload_archive_enabled`) and it stays within their file
91
132
  count, unpacked size and compression ratio (exit 3, naming the limit and who
92
133
  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
101
- Sandbox gets its files with `cavelon sandbox seed <sandbox> <folder>`
134
+ **Updating a document**: upload the new version under the same file name.
135
+ `kb upload` names each file that matches an active document of the
136
+ knowledge base, and what happens to it depends on the instance (try it with
137
+ `--dry-run` first):
138
+ - An instance that replaces same-named documents does so on every upload:
139
+ "faq.md exists (0f3c…) and is replaced by the upload (--keep-both keeps
140
+ it)". `--keep-both` keeps both.
141
+ - On an older instance the old version stays active next to the new one,
142
+ and both answer: "faq.md exists (0f3c…) and stays active". Upload with
143
+ `--replace`: where the instance's upload can replace by id, the old
144
+ document is replaced once the new file is verified; where it cannot,
145
+ `--replace` shows the documents it would deactivate after the upload and
146
+ needs `--confirm`: show the person that first.
147
+ - A file whose content is already an active document is not uploaded
148
+ again: "identical to the active document …; nothing new was created
149
+ (deduplicated)", with nothing to wait for and nothing replaced. Where the
150
+ instance publishes its documents' file hashes, `--dry-run` says it first
151
+ ("nothing new would be created"; `--json`: `identical`, and
152
+ `content_compared` false where it cannot tell).
153
+ A test Sandbox gets its files with `cavelon sandbox seed <sandbox> <folder>`
102
154
  (isolated container) or `cavelon sandbox refresh <sandbox>` after the files
103
155
  were put on the VM (customer VM).
104
156
  7. **Test**: `cavelon test run --suite <suite>`, then `cavelon wait <operation>`.
@@ -120,9 +172,24 @@ says when the solution it activated is not the default.
120
172
  changes live traffic; never decide it yourself.
121
173
  - With their yes: `cavelon activate --make-default` (or `cavelon harness
122
174
  default <solution>`) shows the change, naming the current default; show it,
123
- then run the same command with `--confirm`.
175
+ then run the confirm command it printed (from your shell it carries the
176
+ change's token: `--confirm <token>`). `harness default` refuses a draft
177
+ (`solution_not_active`, exit 4): only an active solution can be the
178
+ default, so use `cavelon activate --make-default`.
124
179
  - `is_default` in `harnesses.yaml` is not applied by `apply`; the preview
125
180
  lists it under "not applied".
181
+ - To try an active solution that is not the default, talk to it by name:
182
+ `cavelon chat "<message>" --harness <solution>` (the `chat` tool over MCP)
183
+ prints its answer, the session to continue with `--session`, and the
184
+ conversation to trace. A draft answers only a person's token, as a
185
+ Playground run.
186
+ - `cavelon deactivate --harness <solution>` takes an active solution out of
187
+ live traffic: it previews, and only the confirm command it prints
188
+ deactivates. Its status becomes `inactive`, not `draft`: it keeps its
189
+ configuration, answers no live traffic, and `cavelon activate` puts it back
190
+ through its readiness gate. It is the person's decision, like the default
191
+ route; the default route itself is refused until another solution is the
192
+ default.
126
193
 
127
194
  ## Show the person before confirming
128
195
 
@@ -133,17 +200,44 @@ show the preview to the person, and confirm only after they agree, when:
133
200
  solution is active;
134
201
  - the environment is `prod` (`--env prod`), or the preview deletes anything
135
202
  (`--mode replace`);
203
+ - the preview changes tenant-wide sections (`tenant-wide: … change for every
204
+ solution of the tenant`, after `--tenant-wide` or on an instance that
205
+ imports them anyway): every solution of the tenant sees the change;
136
206
  - the preview lists target needs (secrets, grants, identities): only a person
137
207
  can provide them, with `cavelon secrets set <name>` or in the Admin.
138
208
 
139
209
  The same holds for the other commands that take `--confirm`: without it they
140
210
  only show what would happen. Show it to the person before `cavelon trigger
141
211
  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
212
+ before `cavelon harness default … --confirm`, `cavelon activate
213
+ --make-default --confirm` or `cavelon deactivate --confirm` (they move live
214
+ traffic), and
144
215
  before `cavelon sandbox seed … --confirm` or `cavelon loop cancel … --confirm` on
145
216
  anything but a test Sandbox or a run you started yourself.
146
217
 
218
+ **Over MCP, confirm with the preview's token.** `api`, `limits_set`,
219
+ `models_set_limit`, `loop_cancel`, `sandbox_seed`, `trigger_identity`,
220
+ `harness_default`, `deactivate`, `activate` with `make_default`, and
221
+ `kb_upload` where it would deactivate documents return a `confirm_token` with
222
+ their preview. Show
223
+ the preview, then call the tool again with the same arguments and `confirm`
224
+ set to that token; it makes exactly the change shown. `confirm: true` is
225
+ refused (`confirm_token_required`), and a token of another change returns the
226
+ new preview with `token_mismatch` (exit code 4): show that one instead. Tool
227
+ arguments are spelled in snake_case (`make_default`, `keep_both`, `dry_run`);
228
+ an argument a tool does not list is refused (`unknown_argument`) with the
229
+ closest one named.
230
+
231
+ **From your shell, `--confirm` takes the same token.** Run by a coding agent,
232
+ `limits set`, `models set-limit`, `loop cancel`, `sandbox seed`,
233
+ `trigger identity`, `harness default`, `activate --make-default`,
234
+ `deactivate`, `kb upload --replace`, `variables delete` and `secrets delete`
235
+ print their preview with a confirm token and the command that confirms it
236
+ (`… --confirm <token>`). Show the preview, then run exactly that command. A
237
+ bare `--confirm`, as the docs show it for a person's terminal, changes nothing
238
+ from your shell and exits 5; a token of another change exits 4 with the new
239
+ preview.
240
+
147
241
  **`cavelon api` from your shell has the guards of the MCP `api` tool**, since
148
242
  `cavelon` sees that a coding agent runs it (`CLAUDECODE`, `CODEX_THREAD_ID`, `CODEX_SANDBOX`,
149
243
  `CURSOR_AGENT`, `GEMINI_CLI`, `COPILOT_CLI`, `COPILOT_AGENT`, `AI_AGENT` or
@@ -155,7 +249,9 @@ anything but a test Sandbox or a run you started yourself.
155
249
  exactly that request. A changed body or parameter needs a new preview (exit 4).
156
250
  - It refuses an operation the instance keeps for a person
157
251
  (`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`.
252
+ a secret value (`secret_field_for_a_person`), with or without `--confirm`,
253
+ with exit code 5 (needs a person). `cavelon api describe <operation>` shows
254
+ both marks up front.
159
255
  Tell the person what the error's hint says; for a secret field, send the rest
160
256
  without it and let the person enter the value (`cavelon secrets set <name>`
161
257
  or the Admin). Never work around a refusal, by unsetting the variable or by
@@ -72,7 +72,14 @@ consult tool's name, not with `handoff_to`. Use the slugs from
72
72
  `package/agents.yaml`.
73
73
 
74
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
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
76
83
  warns `test_assertion_unchecked`: an instance that does not know a type grades
77
84
  it as a judge criterion instead of checking it, so read `cavelon docs get
78
85
  concepts/regression-testing` for the types the instance knows before relying on
@@ -129,7 +136,7 @@ The case's own reason (which knowledge base, which value) is in the output of
129
136
  ## Reading what happened
130
137
 
131
138
  ```bash
132
- 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
133
140
  cavelon trace <conversation-id> --kind conversation # one case's traces
134
141
  cavelon trace <conversation-id> --kind conversation --trace <trace-id> # one trace's spans
135
142
  cavelon trace <conversation-id> --kind conversation --trace <trace-id> --span <span-id>
@@ -141,24 +148,54 @@ retrieval). Output is bounded; run the command each level prints as printed: it
141
148
  carries the id its route needs. A case's traces are under its
142
149
  `conversation_id` (a trigger case's under its `run_id`, `--kind trigger`), not
143
150
  under the test run's id; a wrong id answers with a hint naming the right one.
144
- A low-scoring pass shows the judge's reasoning too.
145
-
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.
146
161
  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.
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 |
182
+
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.
156
186
 
157
187
  ## Optimizing
158
188
 
159
- Change one thing at a time, then run the same suite again and compare:
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.
160
193
 
161
- - **Wrong or missing facts:** check retrieval first (which chunks came back in
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
162
199
  the retrieval span, and its `knowledge_outcome`: `content_gap` means the
163
200
  knowledge base lacks the answer, `unusable_hits` that what came back did not
164
201
  answer it, `retrieval_fault` that the search failed). Fix the documents or
@@ -170,9 +207,25 @@ Change one thing at a time, then run the same suite again and compare:
170
207
  description and parameters, then the agent's instructions about when to use it.
171
208
  - **Right facts, poor answer:** adjust the agent's instructions; keep them short
172
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.
173
215
  - **Too slow or too costly:** read the token counts and durations in the trace;
174
216
  a smaller model or fewer tool rounds often suffice for a step.
175
217
 
176
- 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,
177
230
  `cavelon activate --harness <name or slug>` goes through the readiness gate; if the
178
231
  token may not activate, a person activates in the Admin.
@@ -98,3 +98,22 @@ export function tenantMissError(ref, pool, reachesAll, from) {
98
98
  details: { tenants: listed.map((t) => ({ id: t.id, slug: t.slug, name: t.name })) },
99
99
  });
100
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.5",
3
+ "version": "0.1.7",
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",