@abelxiaoxing/cadence 2.2.3 → 2.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -152,7 +152,8 @@ The job checks the same list again when it requests Stop, including after downlo
152
152
 
153
153
  The request runs outside the service, in a transient unit `cadence.maintenance.service` (`cadence-NAME.maintenance.service` for a named service), so closing or reloading the page does not interrupt it and one job runs at a time.
154
154
  It runs the same `cadence server restart` or `cadence server upgrade`, then records its outcome.
155
- After a successful upgrade, the requesting page reloads automatically when the target version is serving.
155
+ Leave the requesting tab open: it waits through temporary disconnections or proxy error pages and reloads the same address automatically once its upgrade is recorded as successful and the target version answers.
156
+ No second click is needed.
156
157
  A restart still offers a reload; a failed, rolled-back or unconfirmed upgrade leaves the result on screen.
157
158
  If it reports nothing, see `journalctl --user -u cadence.maintenance.service` (without `--user` for a system service) and `cadence server status`.
158
159
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abelxiaoxing/cadence",
3
- "version": "2.2.3",
3
+ "version": "2.2.5",
4
4
  "description": "Conversation-driven Pi workspace: persistent native and WebUI workflows, explicit plan approval, checks and local delivery.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,12 @@
1
1
  /** Serialized private child/owner bridge. Never a browser API or shell executor. */
2
+ import { createHash } from "node:crypto";
2
3
  import { Type } from "typebox";
3
- import { closed, knowledgeFields, LIMITS } from "./worker-public.mjs";
4
+ import {
5
+ canonicalJson,
6
+ closed,
7
+ knowledgeFields,
8
+ LIMITS,
9
+ } from "./worker-public.mjs";
4
10
 
5
11
  /** The parameters of the two tools a coordinator calls, declared once for the
6
12
  * native extension and the browser coordinator. They state shape only: counts,
@@ -278,6 +284,9 @@ export function createCoordinatorTools() {
278
284
  const pending = new Map();
279
285
  let counter = 0;
280
286
  let chain = Promise.resolve();
287
+ // Design validation refusals describe the arguments, not mutable project
288
+ // state. Remember only the last one for this coordinator's lifetime.
289
+ let invalidDesign;
281
290
  let disconnected = false;
282
291
  let retiring = false;
283
292
  let retirement;
@@ -301,13 +310,28 @@ export function createCoordinatorTools() {
301
310
  const p = pending.get(reply.id);
302
311
  if (!p) return;
303
312
  pending.delete(reply.id);
304
- if (reply.ok === true && typeof reply.text === "string")
313
+ if (reply.ok === true && typeof reply.text === "string") {
314
+ if (p.design || p.plan) {
315
+ let value;
316
+ try {
317
+ value = JSON.parse(reply.text);
318
+ } catch {
319
+ /* Not a structured refusal. */
320
+ }
321
+ if (
322
+ (value?.refused === "invalid" || value?.refused === "invalid-plan") &&
323
+ typeof value.notice === "string"
324
+ ) {
325
+ if (p.design) invalidDesign = { key: p.design, notice: value.notice };
326
+ return p.reject(new Error(value.notice));
327
+ }
328
+ if (p.design) invalidDesign = undefined;
329
+ }
305
330
  p.resolve({
306
331
  content: [{ type: "text", text: reply.text }],
307
332
  details: undefined,
308
333
  });
309
- // The service did nothing; its fixed code says why it could not.
310
- else
334
+ } else
311
335
  p.reject(
312
336
  new Error(
313
337
  typeof reply.code === "string" && /^[a-z-]{1,40}$/.test(reply.code)
@@ -360,7 +384,12 @@ export function createCoordinatorTools() {
360
384
  execute: async (_callId, args, signal) => {
361
385
  if (retiring) throw new Error("Coordinator closed");
362
386
  if (signal?.aborted) throw new Error("Coordinator canceled");
363
- const request = { id: ++counter, name: tool.name, args };
387
+ const request = {
388
+ id: ++counter,
389
+ name: tool.name,
390
+ args:
391
+ tool.name === "cadence_knowledge" ? knowledgeToolInput(args) : args,
392
+ };
364
393
  if (Buffer.byteLength(JSON.stringify(request)) > LIMITS.coordinatorBytes)
365
394
  throw new Error(
366
395
  `This call is larger than ${LIMITS.coordinatorBytes} bytes and was not sent; nothing happened.`,
@@ -371,7 +400,24 @@ export function createCoordinatorTools() {
371
400
  if (signal?.aborted) throw new Error("Coordinator canceled");
372
401
  if (disconnected) throw new Error("Coordinator disconnected");
373
402
  if (retiring) throw new Error("Coordinator closed");
374
- pending.set(request.id, { resolve, reject });
403
+ const design =
404
+ tool.name === "cadence_design"
405
+ ? createHash("sha256")
406
+ .update(canonicalJson(args, LIMITS.coordinatorBytes))
407
+ .digest("hex")
408
+ : undefined;
409
+ if (design && invalidDesign?.key === design)
410
+ return reject(
411
+ new Error(
412
+ `Unchanged invalid design was not sent. ${invalidDesign.notice}`,
413
+ ),
414
+ );
415
+ pending.set(request.id, {
416
+ resolve,
417
+ reject,
418
+ design,
419
+ plan: tool.name === "cadence_plan",
420
+ });
375
421
  const unavailable = () => {
376
422
  pending.delete(request.id);
377
423
  reject(new Error("Coordinator request unavailable"));