@cavelon/cli 0.2.11 → 0.2.12

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.
@@ -6,6 +6,8 @@ import { MANIFEST_SECTION, PERSONA_SECTION, sectionFields } from "./package-form
6
6
  import { kitErrorEntry } from "./kit-codes.js";
7
7
  import { checkWorkflowQueries } from "./workflow-queries.js";
8
8
  import { checkWritePaths } from "./database-write-paths.js";
9
+ import { ATTACHED_DOCUMENTS_CODES, checkAttachedDocuments, inAttachedDocuments } from "./attached-documents.js";
10
+ import { checkManagedFields, MANAGED_KINDS_LEFT_OUT_CODE, MANAGED_KINDS_UNSUPPORTED_CODE, MANAGED_SETTING_UNKNOWN_CODE, UNMANAGED_SET_CODE, } from "./managed-fields.js";
9
11
  import { cavelonCommand, fill, folderCommand } from "./printed.js";
10
12
  import { branches, checkModels, checkReferences, checkUnknownFields, closest, DUPLICATE_CODE, FIELD_UNKNOWN_CODE, MODEL_UNKNOWN_CODE, REFERENCE_MISSING_CODE, REFERENCE_UNKNOWN_CODE, KNOWLEDGE_TOOL_KEYS, } from "./package-references.js";
11
13
  export const SCHEMA_CODE = "package_schema_invalid";
@@ -32,6 +34,7 @@ const SOLUTION_MISMATCH_CODE = "solution_slug_mismatch";
32
34
  const TENANT_WIDE_CODE = "tenant_wide_section";
33
35
  const ASSERTION_UNCHECKED_CODE = "test_assertion_unchecked";
34
36
  const TESTING_DOCS = "/docs/concepts/regression-testing";
37
+ const MANAGED_DOCS = "https://github.com/goodguys-gmbh/cavelon-dev-kit/blob/main/docs/concepts.md#fields-the-folder-does-not-manage";
35
38
  const DATABASE_DOCS = "/docs/administration/database-connectors";
36
39
  export const KIT_CODES = [
37
40
  {
@@ -185,6 +188,36 @@ export const KIT_CODES = [
185
188
  hint: "Change the query's parameters instead (database_query.parameters), or put the field back as pulled.",
186
189
  docs: DATABASE_DOCS,
187
190
  },
191
+ {
192
+ code: UNMANAGED_SET_CODE,
193
+ area: "package",
194
+ message: "A package file sets a field that cavelon.yaml lists under unmanaged: apply leaves it out, so the instance keeps its own value.",
195
+ hint: "Remove the field from the package file, or take its pointer out of unmanaged in cavelon.yaml when the folder should manage it again. " +
196
+ "`cavelon pull` does not write an unmanaged field.",
197
+ docs: MANAGED_DOCS,
198
+ },
199
+ {
200
+ code: MANAGED_SETTING_UNKNOWN_CODE,
201
+ area: "package",
202
+ message: "cavelon.yaml's unmanaged or managed_kinds names a field or a kind this instance's package schema does not have.",
203
+ hint: "Check the pointer and the kinds for a typo; `cavelon schema persona` lists the persona's fields. A field inside a list cannot be named.",
204
+ docs: MANAGED_DOCS,
205
+ },
206
+ {
207
+ code: MANAGED_KINDS_LEFT_OUT_CODE,
208
+ area: "package",
209
+ message: "A list entry is of a kind that cavelon.yaml's managed_kinds does not list: apply leaves it out, and the instance keeps its own entries of that kind.",
210
+ hint: "Add the kind to managed_kinds in cavelon.yaml when the folder should manage it, or remove the entry from the package file.",
211
+ docs: MANAGED_DOCS,
212
+ },
213
+ {
214
+ code: MANAGED_KINDS_UNSUPPORTED_CODE,
215
+ area: "package",
216
+ message: "This instance cannot import only some kinds of a list, so apply leaves the list out to keep the entries of the kinds the folder does not manage.",
217
+ hint: "The instance keeps the whole list as it is. To send the list anyway, replacing every kind, remove its entry from managed_kinds in cavelon.yaml; " +
218
+ "an instance that publishes <list>_kinds in its package schema imports only the managed kinds.",
219
+ docs: MANAGED_DOCS,
220
+ },
188
221
  {
189
222
  code: "package_file_duplicate",
190
223
  area: "package",
@@ -192,6 +225,7 @@ export const KIT_CODES = [
192
225
  hint: "Keep one of them: package/<section>.yaml, or the section's own folder from cavelon.yaml's layout.",
193
226
  docs: PACKAGE_DOCS,
194
227
  },
228
+ ...ATTACHED_DOCUMENTS_CODES,
195
229
  ];
196
230
  function findingEntry(catalog, code) {
197
231
  return catalog?.rule_codes?.find((e) => e.code === code) ?? KIT_CODES.find((e) => e.code === code) ?? catalog?.api_error_codes?.find((e) => e.code === code);
@@ -216,10 +250,27 @@ export function packageVersionOf(pkg) {
216
250
  const version = manifest.package_version;
217
251
  return typeof version === "string" ? version : undefined;
218
252
  }
253
+ function withPlainDiscriminators(value) {
254
+ if (Array.isArray(value))
255
+ return value.map(withPlainDiscriminators);
256
+ if (!value || typeof value !== "object")
257
+ return value;
258
+ const out = {};
259
+ for (const [key, inner] of Object.entries(value)) {
260
+ const name = key === "discriminator" ? inner?.propertyName : undefined;
261
+ out[key] = typeof name === "string" ? { propertyName: name } : withPlainDiscriminators(inner);
262
+ }
263
+ return out;
264
+ }
219
265
  function compile(schema) {
220
266
  const { $id: _id, $schema: _schema, ...body } = schema;
221
- const ajv = new Ajv2020({ strict: false, allErrors: true, verbose: true, validateSchema: false, validateFormats: false });
222
- return ajv.compile(body);
267
+ const options = { strict: false, allErrors: true, verbose: true, validateSchema: false, validateFormats: false };
268
+ try {
269
+ return new Ajv2020({ ...options, discriminator: true }).compile(withPlainDiscriminators(body));
270
+ }
271
+ catch {
272
+ return new Ajv2020(options).compile(body);
273
+ }
223
274
  }
224
275
  function closestBranchErrors(errors) {
225
276
  const dropped = new Set();
@@ -253,12 +304,17 @@ function closestBranchErrors(errors) {
253
304
  const field = e.instancePath.startsWith(`${here}/`) && !e.instancePath.slice(here.length + 1).includes("/");
254
305
  return sum + ((e.keyword === "const" || e.keyword === "enum") && field ? 100 : 1);
255
306
  }, 0);
256
- const ranked = [...byBranch.values()].map((list) => ({ list, distance: distance(list) })).sort((a, b) => a.distance - b.distance);
307
+ const claimed = new Set([...byBranch.values()].flat());
308
+ const unclaimed = errors.slice(0, index).filter((e) => !dropped.has(e) && !isChoice(e) && !claimed.has(e) && (e.instancePath === here || e.instancePath.startsWith(`${here}/`)));
309
+ if (unclaimed.length)
310
+ byBranch.set(-1, unclaimed);
311
+ const ranked = [...byBranch.entries()].map(([branch, list]) => ({ branch, list, distance: distance(list) })).sort((a, b) => a.distance - b.distance);
257
312
  if (ranked.length < 2 || ranked[0].distance === ranked[1].distance)
258
313
  return;
259
314
  for (const other of ranked.slice(1))
260
- for (const error of other.list)
261
- dropped.add(error);
315
+ if (other.branch !== -1)
316
+ for (const error of other.list)
317
+ dropped.add(error);
262
318
  for (const error of ranked[0].list)
263
319
  countedAt.set(error, pathOf(choice));
264
320
  });
@@ -326,6 +382,8 @@ export function checkPackage(disk, options) {
326
382
  continue;
327
383
  if (misnamed.some((m) => within(error.instancePath, m.pointer)))
328
384
  continue;
385
+ if (inAttachedDocuments(options.schema, error.instancePath))
386
+ continue;
329
387
  if (error.keyword === "required" && error.instancePath === "" && unreadable.has(String(error.params.missingProperty)))
330
388
  continue;
331
389
  const { pointer, message } = describe(error);
@@ -340,6 +398,7 @@ export function checkPackage(disk, options) {
340
398
  findings.push(...checkEndpointLimits(disk, options.schema));
341
399
  findings.push(...checkBranchConcurrency(disk, options.limits));
342
400
  findings.push(...checkKnowledgeSearch(disk));
401
+ findings.push(...checkAttachedDocuments(disk, options.schema));
343
402
  findings.push(...checkUnknownFields(disk, options.schema, findings));
344
403
  findings.push(...checkReferences(disk, options.inventory));
345
404
  findings.push(...checkModels(disk, options.inventory));
@@ -350,6 +409,7 @@ export function checkPackage(disk, options) {
350
409
  findings.push(...checkQueryTools(disk, options.schema, options.queryBaseline, options.queryConnections));
351
410
  findings.push(...checkWorkflowQueries(disk, options.schema, options.inventory, options.queryBaseline));
352
411
  findings.push(...checkWritePaths(disk, options.schema, options.catalog, options.queryBaseline));
412
+ findings.push(...checkManagedFields(disk, options.managed, options.schema));
353
413
  noteTenantWide(findings, options.schema, options.solution);
354
414
  for (const finding of findings) {
355
415
  const entry = findingEntry(options.catalog, finding.code);
@@ -114,11 +114,12 @@ export function exportForm(schema, node, value, depth = 0, position) {
114
114
  if (!props)
115
115
  return value;
116
116
  const required = requiredOf(object);
117
+ const openMap = object.additionalProperties === true;
117
118
  const out = {};
118
119
  for (const [key, sub] of Object.entries(props)) {
119
120
  if (key in value)
120
121
  out[key] = exportForm(schema, sub, value[key], depth + 1);
121
- else {
122
+ else if (!openMap) {
122
123
  const fallback = implicitDefault(schema, key, sub, required, position);
123
124
  if (fallback !== undefined)
124
125
  out[key] = structuredClone(fallback);
@@ -152,6 +153,10 @@ function isEmpty(value) {
152
153
  return value === null || value === undefined || (isObject(value) && Object.keys(value).length === 0);
153
154
  }
154
155
  const isUnset = (value) => isEmpty(value) || (Array.isArray(value) && value.length === 0);
156
+ function emptyListIsAValue(schema, node) {
157
+ const field = resolve(schema, node);
158
+ return Boolean(field) && field.default === null && nullable(schema, field) && arrayBranch(schema, field) !== undefined;
159
+ }
155
160
  export function settledForm(schema, node, value, depth = 0) {
156
161
  const resolved = resolve(schema, node);
157
162
  if (!resolved || depth > 40)
@@ -175,6 +180,10 @@ export function settledForm(schema, node, value, depth = 0) {
175
180
  continue;
176
181
  }
177
182
  const settled = settledForm(schema, props[key], inner, depth + 1);
183
+ if (Array.isArray(inner) && emptyListIsAValue(schema, props[key])) {
184
+ out[key] = settled;
185
+ continue;
186
+ }
178
187
  if (!required.has(key)) {
179
188
  const fallback = implicitDefault(schema, key, props[key], required, undefined);
180
189
  if (isUnset(settled) && (fallback === undefined || isUnset(fallback)))
package/dist/project.js CHANGED
@@ -6,6 +6,7 @@ import { CavelonError, ExitCode, usageError } from "./errors.js";
6
6
  import { layoutFrom } from "./package-files.js";
7
7
  import { cavelonCommand } from "./printed.js";
8
8
  import { solutionPath, solutionPaths } from "./file-boundary.js";
9
+ import { validManagedPointer } from "./managed-fields.js";
9
10
  export const PROJECT_FILE = "cavelon.yaml";
10
11
  function stringField(value, ...keys) {
11
12
  if (typeof value === "string" && value.trim())
@@ -60,9 +61,42 @@ export function parseProject(file, text) {
60
61
  harness: stringField(map.harness, "slug", "id"),
61
62
  packageVersion: stringField(map.package_version),
62
63
  layout: layoutFrom(map),
64
+ managed: managedFrom(file, map),
63
65
  raw: map,
64
66
  };
65
67
  }
68
+ function managedFrom(file, map) {
69
+ const invalid = (message) => new CavelonError(ExitCode.validation, {
70
+ code: "project_file_invalid",
71
+ message: `${file}: ${message}`,
72
+ hint: "Name a field inside a section as a JSON pointer, such as /persona/engagement_rules; `managed_kinds` maps such a pointer to a list of kinds.",
73
+ });
74
+ const pointer = (value, where) => {
75
+ if (typeof value !== "string" || !validManagedPointer(value.trim()))
76
+ throw invalid(`${where} must be a JSON pointer to a field inside a section, got ${JSON.stringify(value)}.`);
77
+ return value.trim();
78
+ };
79
+ const unmanaged = [];
80
+ if (map.unmanaged !== undefined && map.unmanaged !== null) {
81
+ if (!Array.isArray(map.unmanaged))
82
+ throw invalid("unmanaged must be a list of JSON pointers.");
83
+ for (const entry of map.unmanaged)
84
+ unmanaged.push(pointer(entry, "each unmanaged entry"));
85
+ }
86
+ const kinds = {};
87
+ const declared = map.managed_kinds;
88
+ if (declared !== undefined && declared !== null) {
89
+ if (typeof declared !== "object" || Array.isArray(declared))
90
+ throw invalid("managed_kinds must map a JSON pointer to the list of kinds the folder manages.");
91
+ for (const [key, value] of Object.entries(declared)) {
92
+ const at = pointer(key, "each managed_kinds key");
93
+ if (!Array.isArray(value) || !value.every((k) => typeof k === "string" && k.trim()))
94
+ throw invalid(`managed_kinds["${at}"] must be a list of kinds, such as [starters].`);
95
+ kinds[at] = [...new Set(value.map((k) => k.trim()))];
96
+ }
97
+ }
98
+ return { unmanaged: [...new Set(unmanaged)], kinds };
99
+ }
66
100
  function refuseCredentials(file, map) {
67
101
  for (const forbidden of ["token", "api_key", "secret"]) {
68
102
  if (forbidden in map) {
@@ -230,11 +230,51 @@ and fill the field in to set it. A file of comments only sets nothing.
230
230
  (`persona_message_empty`). Write the text, or turn it off.
231
231
  - Leave the persona out (all fields commented) only for a solution nobody
232
232
  talks to directly: a pipeline, a loop, a solution another solution calls.
233
+ - **Engagement rules** (`engagement_rules`) are the page starter questions
234
+ (`kind: starters`) and the campaigns: `calendar`, `banner` and
235
+ `decoration`. Give every rule a stable `id` of lowercase letters, digits and
236
+ hyphens, and never reuse one for something else: the instance counts results
237
+ by `rule_id`. `cavelon schema persona.engagement_rules` shows each kind's
238
+ fields. A minimal campaign:
239
+
240
+ ```yaml
241
+ engagement_rules:
242
+ - id: winter-snow
243
+ kind: decoration
244
+ name: Winter snow
245
+ enabled: true
246
+ window: { timezone: Europe/Vienna, starts_at: "2026-12-01T00:00", ends_at: "2027-01-07T00:00" }
247
+ content: { effect: snow }
248
+ ```
249
+
250
+ Left out, an import keeps the solution's rules; `[]` deletes them all.
251
+ Campaigns are usually edited in the Admin. When people do that, add
252
+ `managed_kinds: {/persona/engagement_rules: [starters]}` to `cavelon.yaml`, so
253
+ `pull` and `apply` touch only the starters. Try a page and a date with
254
+ `cavelon engagement preview --page <url> --at <time>`. On an active solution,
255
+ rules, greeting and teasers reach visitors at once, without a publication,
256
+ so the preview asks for a person. A site with a Content Security Policy must
257
+ allow the widget's `chat-widget-engagement.js` and the image hosts a campaign
258
+ uses: `cavelon docs get channels/widget`.
233
259
  - Without `harness_id`, the persona operations of `cavelon api`
234
260
  (`get_bot_persona`, `upsert_bot_persona`) reach the tenant's default route;
235
261
  in a solution folder, `cavelon api` sends the folder's solution, and says
236
262
  so. Prefer the package file and `apply` over those operations.
237
263
 
264
+ ## A chat turn's wait for attached files
265
+
266
+ A solution sets how long a chat turn waits for a file it carries that is still
267
+ being read in `harnesses.yaml`: `settings.attached_documents` with
268
+ `wait_until_readable` (only `false` turns the wait off) and `wait_seconds`
269
+ (0 to 120, as the package schema publishes). The instance reads it leniently
270
+ and never refuses it, so `cavelon validate` warns instead
271
+ (`attached_documents_value_ignored`, `attached_documents_wait_clamped`). It is
272
+ not the tenant's `attached_documents` context-source limit, which bounds how
273
+ much of the files reaches the model. On an active solution the change goes to
274
+ the draft; try it with `cavelon chat "<message>" --file <path> --draft` (a
275
+ personal access token holding `playground.use` reaches the draft; an API key
276
+ gets the published version).
277
+
238
278
  ## Rules that keep a package portable
239
279
 
240
280
  - **Slugs are identities.** An entry is matched by its slug on import; renaming
@@ -334,7 +334,9 @@ preview too.
334
334
  `cavelon chat "<message>" --harness <solution>` (the `chat` tool over MCP)
335
335
  prints its answer, the session to continue with `--session`, and the
336
336
  conversation to trace. A draft answers only a person's token, as a
337
- Playground run.
337
+ Playground run; `--draft` tries an active solution's unpublished draft. On
338
+ `chat_turn_timeout` the turn goes on and its answer is stored: read the
339
+ conversation the error names instead of sending the message again.
338
340
  - `cavelon deactivate --harness <solution>` takes an active solution out of
339
341
  live traffic: it previews, and only the confirm command it prints
340
342
  deactivates. Its status becomes `inactive`, not `draft`: it keeps its
@@ -171,6 +171,13 @@ no verdict; `cavelon explain <status>` says what it means and what to do next:
171
171
  The case's own reason (which knowledge base, which value) is in the output of
172
172
  `test run --wait`, `wait` and `cavelon trace <run>`.
173
173
 
174
+ Without `--suite`, `test run` runs every suite of the solution except those
175
+ that never vote in readiness: a campaign's question check (tagged `engagement`
176
+ and `rule:<id>`, made by the Admin's Engagement editor, and never part of the
177
+ package). They are listed under `skipped` and never change the exit code; a
178
+ failed question there is a content gap for the campaign's author.
179
+ `--suite <name>` runs one when asked.
180
+
174
181
  ## Database query tools
175
182
 
176
183
  Test edited package SQL before apply with `cavelon db test-run <slug> --draft
@@ -390,7 +397,14 @@ To try a question outside the suite, `cavelon chat "<message>" --harness
390
397
  the answer, the session to continue with `--session`, and the conversation to
391
398
  trace. It reaches an active solution that is not the tenant's default route,
392
399
  which the tenant's chat and widget never answer with; a draft answers only a
393
- person's token, as a Playground run. `cavelon api chat` with `harness_id` in
400
+ person's token, as a Playground run. `--file <path>` attaches a file (the
401
+ solution's wait for a file still being read is `settings.attached_documents`
402
+ in `harnesses.yaml`). With a personal access token holding `playground.use`
403
+ the chat is a Playground run, so an active solution answers with its pending
404
+ draft; `--draft` asks for it explicitly, and an API key gets the published
405
+ version. A `chat_turn_timeout` means the turn goes on and its answer is stored:
406
+ never send the message again (it would run twice); read the conversation the
407
+ error names. A `cancelled` status is a turn stored without an answer. `cavelon api chat` with `harness_id` in
394
408
  the body does the same, but needs the id and a confirm. `cavelon deactivate
395
409
  --harness <solution>` takes an active solution out of live traffic again; it
396
410
  previews first and is the person's decision: show the preview; over MCP the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cavelon/cli",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
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",