@cavelon/cli 0.2.8 → 0.2.9

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.
@@ -5,6 +5,7 @@ import { CavelonError, ExitCode, usageError } from "../errors.js";
5
5
  import { clip, keyValues, table } from "../format.js";
6
6
  import { harnessNotFoundError, lookupHarness } from "../harness-ref.js";
7
7
  import { callOperation, workflowOperation } from "../invoke.js";
8
+ import { canonical } from "../package-files.js";
8
9
  import { cavelonCommand } from "../printed.js";
9
10
  const BASE = "/api/v1/harnesses/{harness_id}";
10
11
  const READ = `${BASE}/publication`;
@@ -31,18 +32,47 @@ async function read(ctx, id, snapshot) {
31
32
  const { doc, op } = await operation(ctx, READ);
32
33
  const result = await callOperation(ctx, await ctx.client(), doc, op, { params: { harness_id: [id], ...(snapshot ? { snapshot_id: [snapshot] } : {}) } });
33
34
  const p = result.data;
34
- if (!p || !Number.isSafeInteger(p.published_version) || p.published_version < 0 || !Number.isSafeInteger(p.draft_revision) || p.draft_revision < 0 || typeof p.has_draft !== "boolean" || !Array.isArray(p.changes) || !Array.isArray(p.readiness?.blockers) || !Number.isSafeInteger(p.waiting_runs_affected) || p.waiting_runs_affected < 0 || !Array.isArray(p.review_run_ids) || p.review_run_ids.some(id => typeof id !== "string") || !Array.isArray(p.waiting_runs) || !Array.isArray(p.published_snapshots) || typeof p.can_rollback !== "boolean") {
35
+ if (!p || !Number.isSafeInteger(p.published_version) || p.published_version < 0 || !Number.isSafeInteger(p.draft_revision) || p.draft_revision < 0 || typeof p.has_draft !== "boolean" || !Array.isArray(p.changes) || !Array.isArray(p.readiness?.blockers) || [p.readiness.warnings, p.readiness.checks].some(value => value !== undefined && !Array.isArray(value)) || !Number.isSafeInteger(p.waiting_runs_affected) || p.waiting_runs_affected < 0 || !Array.isArray(p.review_run_ids) || p.review_run_ids.some(id => typeof id !== "string") || !Array.isArray(p.waiting_runs) || !Array.isArray(p.published_snapshots) || typeof p.can_rollback !== "boolean") {
35
36
  throw new CavelonError(ExitCode.failure, { code: "publication_state_unknown", message: "The instance did not describe a complete publication state; nothing was changed.", hint: "Read the solution's publication state in the Admin or update the instance." });
36
37
  }
37
38
  return p;
38
39
  }
40
+ function findingsText(label, findings) {
41
+ if (!findings?.length)
42
+ return "";
43
+ const lines = findings.slice(0, 20).map(finding => {
44
+ if (finding && typeof finding === "object") {
45
+ const f = finding;
46
+ if (typeof f.label === "string" && typeof f.state === "string" && typeof f.detail === "string") {
47
+ return clip(`${f.label} (${f.state}): ${f.detail}${Array.isArray(f.items) && f.items.length ? ` ${JSON.stringify(f.items)}` : ""}`, 500);
48
+ }
49
+ }
50
+ return clip(JSON.stringify(finding), 500);
51
+ });
52
+ if (findings.length > 20)
53
+ lines.push(`${findings.length - 20} more findings; read --json for the full review before approving.`);
54
+ return `\n\n${label}:\n${lines.join("\n")}`;
55
+ }
39
56
  function stateText(p) {
40
57
  return keyValues([
41
58
  ["published", `v${p.published_version}`],
42
59
  ["draft", p.has_draft ? `${p.draft_change_count} unpublished changes (revision ${p.draft_revision})` : "none"],
43
60
  ["readiness blockers", p.readiness.blockers.length],
61
+ ["readiness warnings", p.readiness.warnings?.length ?? "not reported"],
44
62
  ["waiting runs affected", p.waiting_runs_affected],
45
- ]) + (p.waiting_runs.length ? `\n\nWaiting runs:\n${table(p.waiting_runs.slice(0, 20), ["id", "node_name"])}` : "") + (p.readiness.blockers.length ? `\n\nBlockers:\n${p.readiness.blockers.slice(0, 20).map(b => clip(JSON.stringify(b), 500)).join("\n")}` : "") + (p.changes.length ? `\n\n${table(p.changes.slice(0, 50), ["entity", "name", "action", "id"])}` : "") + (p.changes.length > 50 ? `\n${p.changes.length - 50} more changes; --json includes all.` : "");
63
+ ]) + findingsText("Blockers", p.readiness.blockers) + findingsText("Warnings", p.readiness.warnings) + findingsText("Readiness checks", p.readiness.checks) + (p.waiting_runs.length ? `\n\nWaiting runs:\n${table(p.waiting_runs.slice(0, 20), ["id", "node_name"])}` : "") + (p.changes.length ? `\n\n${table(p.changes.slice(0, 50), ["entity", "name", "action", "id"])}` : "") + (p.changes.length > 50 ? `\n${p.changes.length - 50} more changes; --json includes all.` : "");
64
+ }
65
+ function readinessReview(p) {
66
+ const sorted = (values) => values ? [...values].sort((a, b) => canonical(a).localeCompare(canonical(b))) : null;
67
+ return { ready_to_activate: p.readiness.ready_to_activate ?? null, blockers: sorted(p.readiness.blockers), warnings: sorted(p.readiness.warnings), checks: sorted(p.readiness.checks) };
68
+ }
69
+ function publishRisks(p) {
70
+ return [
71
+ "Publishing risks:",
72
+ "New live requests will use the reviewed draft; this is not a test run.",
73
+ ...(p.waiting_runs_affected ? [`The instance reports ${p.waiting_runs_affected} affected waiting runs; review the listed runs.`] : []),
74
+ ...(p.readiness.warnings?.length ? ["Readiness warnings remain. Publish only if you accept the warnings shown above."] : []),
75
+ ].join("\n");
46
76
  }
47
77
  export const publication = {
48
78
  name: "harness publication",
@@ -78,6 +108,11 @@ function mutationBody(action, p, snapshot) {
78
108
  }
79
109
  return body;
80
110
  }
111
+ function reviewedChange(harnessId, action, p, snapshot) {
112
+ const changes = [...p.changes].sort((a, b) => (a.entity + ":" + a.id).localeCompare(b.entity + ":" + b.id));
113
+ const waiting = [...p.waiting_runs].sort((a, b) => a.id.localeCompare(b.id));
114
+ return { harness: harnessId, body: mutationBody(action, p, snapshot), changes, waiting_runs: waiting, has_draft: p.has_draft, ...(action !== "discard-draft" ? { readiness: readinessReview(p), waiting_runs_affected: p.waiting_runs_affected } : {}) };
115
+ }
81
116
  function commandWords(action, input, harness, snapshot) {
82
117
  const words = [...ACTIONS[action].words, "--harness", harness.slug];
83
118
  const env = stringOption(input, "env");
@@ -107,11 +142,11 @@ async function checkMutationAccess(ctx, action) {
107
142
  if (permission.allowed === false)
108
143
  throw new CavelonError(ExitCode.unauthorized, { code: "permission_missing", message: "This credential cannot perform the publication change; nothing was changed.", hint: whoInstead(access, permission) });
109
144
  }
110
- function previewResult(harness, p, gate, consequence, words, snapshot) {
145
+ function previewResult(harness, p, gate, review, words, snapshot) {
111
146
  const confirm = gate.confirm(cavelonCommand(...words));
112
147
  return {
113
148
  data: { changed: false, harness, publication: p, ...(snapshot ? { rollback_snapshot: snapshot } : {}), confirm, ...gate.fields },
114
- text: [consequence, stateText(p), gate.where, ...(gate.mismatch ? [gate.mismatch] : []), `Show this to a person; with their yes: ${confirm}`].join("\n"),
149
+ text: [review, gate.where, ...(gate.mismatch ? [gate.mismatch] : []), `Show this to a person; with their yes: ${confirm}`].join("\n"),
115
150
  ...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
116
151
  };
117
152
  }
@@ -135,11 +170,17 @@ async function runChange(ctx, input, action) {
135
170
  const body = mutationBody(action, p, snapshot);
136
171
  const words = commandWords(action, input, harness, snapshot);
137
172
  const consequence = consequenceOf(action, harness, p, snapshot);
138
- const changes = [...p.changes].sort((a, b) => (a.entity + ":" + a.id).localeCompare(b.entity + ":" + b.id));
139
- const waiting = [...p.waiting_runs].sort((a, b) => a.id.localeCompare(b.id));
140
- const gate = await confirmation(ctx, input, tool, { harness: harness.id, body, changes, waiting_runs: waiting, has_draft: p.has_draft }, { person: { what: `${consequence}\n${stateText(p)}`, words } });
173
+ const review = `${consequence}\n${stateText(p)}${action === "publish" ? `\n\n${publishRisks(p)}` : ""}`;
174
+ const change = reviewedChange(harness.id, action, p, snapshot);
175
+ const gate = await confirmation(ctx, input, tool, change, { person: { what: review, words, ...(action === "publish" ? { approval: { title: "Publish this solution", description: "I reviewed this draft, accept any remaining warnings and the effects on live traffic and affected waiting runs, and approve this publication." } } : {}) } });
141
176
  if (!gate.confirmed)
142
- return previewResult(harness, p, gate, consequence, words, snapshot);
177
+ return previewResult(harness, p, gate, review, words, snapshot);
178
+ if (action === "publish" && ctx.mode === "mcp") {
179
+ const current = await read(ctx, harness.id);
180
+ if (canonical(change) !== canonical(reviewedChange(harness.id, action, current))) {
181
+ throw new CavelonError(ExitCode.conflict, { code: "publication_review_changed", message: "The publication review changed while awaiting approval; nothing was published.", hint: "Read the updated publication findings and request a fresh preview and personal approval." });
182
+ }
183
+ }
143
184
  const result = await callOperation(ctx, await ctx.client(), doc, op, { params: { harness_id: [harness.id] }, body });
144
185
  const data = result.data;
145
186
  const warnings = Array.isArray(data.warnings) ? data.warnings.map(w => clip(String(w), 500)) : [];
@@ -71,7 +71,7 @@ async function gateOf(ctx, input, tool, change, options) {
71
71
  if (!tokenGiven)
72
72
  return { confirmed: false, fields, confirm };
73
73
  if (given === token) {
74
- await personApproves(ctx, driven, { tool, what: person.what, command }, options);
74
+ await personApproves(ctx, driven, { tool, what: person.what, command, approval: person.approval }, options);
75
75
  return { confirmed: true, fields: {}, confirm };
76
76
  }
77
77
  return {
@@ -113,7 +113,7 @@ export async function personApproves(ctx, driven, change, target = {}) {
113
113
  if (personRoute(ctx, driven) === "terminal")
114
114
  throw needsPerson(change.command);
115
115
  const where = targetLine(await actingTarget(ctx, target));
116
- const answer = await ctx.askPerson([change.what, where, `A coding agent asks to make this change through cavelon (${change.tool}). Approve only this exact change.`].filter(Boolean).join("\n"));
116
+ const answer = await ctx.askPerson([change.approval?.title, change.what, where, change.approval?.description, `A coding agent asks to make this change through cavelon (${change.tool}). Approve only this exact change.`].filter(Boolean).join("\n"), change.approval);
117
117
  if (answer === "approved") {
118
118
  ctx.approved = { guarded: change.guarded ?? true };
119
119
  return;
package/dist/kit-codes.js CHANGED
@@ -2,6 +2,7 @@ import { printMode } from "./printed.js";
2
2
  export const KIT_ERROR_CODES = [
3
3
  { code: "invalid_trace_export", area: "cli", message: "The instance did not return a JSON trace and integrity manifest; no export was kept.", hint: "Retry the export; if it repeats, report the command and instance version without sharing sensitive trace contents." },
4
4
  { code: "publication_state_unknown", area: "cli", message: "The instance did not describe complete version, draft, readiness or affected-run state; nothing was changed.", hint: "Review publication in the Admin or update the instance before publishing from the kit." },
5
+ { code: "publication_review_changed", area: "cli", message: "The publication review changed while awaiting approval; nothing was published.", hint: "Read the updated publication findings and request a fresh preview and personal approval." },
5
6
  { code: "held_for_privacy_review", area: "cli", message: "This document is held for privacy review; it is not indexed or readable.", hint: "A person with knowledge_bases.manage_documents reviews and releases it in the Admin. Tokens and API keys cannot release it; YOLO does not change this." },
6
7
  { code: "document_file_for_a_person", area: "cli", message: "This document file is restricted or not agent-readable.", hint: "A person with knowledge_bases.manage_documents opens it in the Admin. The privacy vault and conversion report are never returned to agents." },
7
8
  { code: "not_logged_in", area: "cli", message: "There is no token for the instance.", hint: "A person runs `cavelon login` (or sets CAVELON_URL and CAVELON_TOKEN); an agent never handles the token." },
package/dist/mcp.js CHANGED
@@ -228,9 +228,10 @@ function clientAsks(server) {
228
228
  const elicitation = server.getClientCapabilities()?.elicitation;
229
229
  return Boolean(elicitation && (elicitation.form || Object.keys(elicitation).length === 0));
230
230
  }
231
- async function askThroughClient(server, message, relatedRequestId) {
231
+ async function askThroughClient(server, message, relatedRequestId, approval) {
232
232
  try {
233
- const result = await server.elicitInput({ mode: "form", message, requestedSchema: APPROVAL_SCHEMA }, { timeout: PERSON_WAIT_MS, relatedRequestId });
233
+ const requestedSchema = approval ? { ...APPROVAL_SCHEMA, properties: { approve: { ...APPROVAL_SCHEMA.properties.approve, ...approval } } } : APPROVAL_SCHEMA;
234
+ const result = await server.elicitInput({ mode: "form", message, requestedSchema }, { timeout: PERSON_WAIT_MS, relatedRequestId });
234
235
  if (result.action === "accept" && result.content?.approve === true)
235
236
  return "approved";
236
237
  if (result.action === "decline" || result.action === "accept" && result.content?.approve === false)
@@ -304,8 +305,8 @@ export function createMcpServer(io, commands, updates = {}, startup = {}) {
304
305
  }
305
306
  const ctx = createContext(mcpIo(folder.io), { ...launch, json: true, tenant: tenant ?? launch.tenant, solutionEnv: solutionEnv ?? launch.solutionEnv, sessionTenants }, "mcp");
306
307
  if (!clientUiUnavailable && clientAsks(server))
307
- ctx.askPerson = async (message) => {
308
- const answer = await askThroughClient(server, message, requestId);
308
+ ctx.askPerson = async (message, approval) => {
309
+ const answer = await askThroughClient(server, message, requestId, approval);
309
310
  if (answer === "unavailable")
310
311
  clientUiUnavailable = true;
311
312
  return answer;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "format": 1,
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "entries": {
5
5
  "omp": [
6
6
  "omp-extension.mjs"
@@ -158,8 +158,15 @@ When the instance advertises solution publication, an active solution's scoped
158
158
  graph apply writes an unpublished draft. Read the explicit `publication`
159
159
  report; older instances keep their previous behavior. Inspect it with
160
160
  `cavelon harness publication <solution> --json`, run tests and fix readiness,
161
- then review `cavelon publish --harness <solution>`. Publication changes live
162
- traffic and always needs the person's fresh MCP/own-terminal confirmation,
161
+ then review `cavelon publish --harness <solution>`. Show the person the pending
162
+ edits, blockers, remaining warnings, readiness checks and affected waiting runs
163
+ before requesting publication. Blockers must be fixed; the person's single
164
+ publish form can accept remaining warnings and live-traffic effects. Call
165
+ `solution_publish` with the preview's token to open that form, without asking
166
+ for an extra chat yes. A client without a usable form returns an own-terminal
167
+ command. Changed findings need a fresh review, including changes while the
168
+ form was open. Publication changes live traffic and always needs the person's
169
+ fresh MCP/own-terminal confirmation,
163
170
  including in YOLO. Never force it from the kit. Conflicting versions, revisions
164
171
  or affected waiting runs require a fresh review. Shared tenant resources keep
165
172
  their existing behavior and are not isolated by the graph draft.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cavelon/cli",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
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",