@abelxiaoxing/cadence 2.0.36 → 2.0.38

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 (55) hide show
  1. package/README.de.md +4 -4
  2. package/README.es.md +4 -4
  3. package/README.fr.md +4 -4
  4. package/README.ja.md +4 -4
  5. package/README.ko.md +4 -4
  6. package/README.md +11 -9
  7. package/README.pt-BR.md +4 -4
  8. package/README.ru.md +4 -4
  9. package/README.zh-CN.md +12 -10
  10. package/THIRD_PARTY_NOTICES.md +9 -1
  11. package/agents/design-explorer.md +4 -2
  12. package/agents/diagnosis-worker.md +5 -2
  13. package/agents/implementation-worker.md +19 -12
  14. package/docs/conversation-mode.md +46 -18
  15. package/docs/reuse-and-distribution.md +1 -1
  16. package/docs/service-management.md +35 -9
  17. package/package.json +16 -8
  18. package/src/agent-browser/labeled-rule.ts +74 -0
  19. package/src/agent-browser/session-navigator.ts +214 -0
  20. package/src/agent-browser/source.ts +174 -0
  21. package/src/agent-browser/transcript-content.ts +442 -0
  22. package/src/agent-browser/transcript-pane.ts +324 -0
  23. package/src/agent-panel-cadence.ts +147 -628
  24. package/src/agent-panel-model.ts +34 -267
  25. package/src/agent-panel.ts +139 -437
  26. package/src/cadence-instructions.ts +8 -7
  27. package/src/cadence-mode.ts +30 -9
  28. package/src/change-tools.mjs +268 -0
  29. package/src/coordinator-tools.mjs +44 -16
  30. package/src/git-environment.d.mts +2 -0
  31. package/src/git-environment.mjs +24 -0
  32. package/src/image-content.mjs +7 -28
  33. package/src/index.ts +1 -1
  34. package/src/native-build.ts +1 -1
  35. package/src/native-workflow-history.ts +20 -3
  36. package/src/operator-cli.mjs +18 -11
  37. package/src/research-scan.mjs +393 -0
  38. package/src/research-tools.mjs +406 -342
  39. package/src/sdk-worker.mjs +42 -55
  40. package/src/service/contracts/core.ts +0 -1
  41. package/src/service/contracts/workbench.ts +21 -19
  42. package/src/service/contracts/workflow.ts +283 -16
  43. package/src/service/coordination.ts +7 -0
  44. package/src/service-cli.mjs +652 -149
  45. package/src/service-host.mjs +2745 -1137
  46. package/src/worker-capture.mjs +24 -1
  47. package/src/worker-public.mjs +19 -2
  48. package/src/worker-redaction.mjs +11 -0
  49. package/src/worker-toolkit.mjs +157 -0
  50. package/src/worker-workspace.d.mts +13 -0
  51. package/src/worker-workspace.mjs +48 -0
  52. package/src/workspace.ts +4 -24
  53. package/web/dist/assets/cadence.css +1 -1
  54. package/web/dist/assets/cadence.js +18 -17
  55. package/web/dist/manifest.json +7 -7
@@ -18,7 +18,12 @@ export const SUBAGENT_VIEW = "subagent:view";
18
18
  * of the model's context. */
19
19
  export const CARD_ENTRY = "cadence-agent-batch";
20
20
 
21
- export type SubagentStatus = "running" | "done" | "error" | "cancelled";
21
+ export type SubagentStatus =
22
+ | "running"
23
+ | "done"
24
+ | "rejected"
25
+ | "error"
26
+ | "cancelled";
22
27
  type Ended = Exclude<SubagentStatus, "running">;
23
28
 
24
29
  export interface SubagentState {
@@ -49,12 +54,9 @@ export interface SubagentState {
49
54
 
50
55
  /** Retained messages per agent; older ones are counted, not kept. */
51
56
  export const MAX_MESSAGES = 2000;
52
- /** Ended agents kept for review outside the open batch; older ones are
53
- * dropped with their messages once a batch collapses into its card. */
54
- export const MAX_ENDED = 24;
55
57
  /** Agents written into one card; more are counted, not listed. */
56
58
  export const MAX_CARD_AGENTS = 64;
57
- const ENDED = new Set(["done", "error", "cancelled"]);
59
+ const ENDED = new Set(["done", "rejected", "error", "cancelled"]);
58
60
 
59
61
  const record = (v: unknown): Record<string, unknown> | undefined =>
60
62
  v && typeof v === "object" && !Array.isArray(v)
@@ -120,16 +122,14 @@ export class SubagentStore {
120
122
  this.batchIds = [];
121
123
  return batch;
122
124
  }
123
- /** Drop ended agents outside the open batch, oldest first, until at most
124
- * `keep` remain; `retain` ids stay. Returns the dropped ids. Listeners are
125
- * not called: the caller is the panel, which redraws itself. */
126
- prune(keep: number, retain: (string | undefined)[] = []): string[] {
125
+ /** Drop ended agents once their batch has become a display card. An open
126
+ * transcript already holds its own state reference; no history list stays.
127
+ * Listeners are not called: the panel owns the redraw. */
128
+ prune(): string[] {
127
129
  const open = new Set(this.batchOpen ? this.batchIds : []);
128
- const ended = [...this.agents.values()].filter(
129
- (a) =>
130
- a.status !== "running" && !open.has(a.id) && !retain.includes(a.id),
130
+ const drop = [...this.agents.values()].filter(
131
+ (a) => a.status !== "running" && !open.has(a.id),
131
132
  );
132
- const drop = ended.slice(0, Math.max(0, ended.length - keep));
133
133
  for (const a of drop) this.agents.delete(a.id);
134
134
  return drop.map((a) => a.id);
135
135
  }
@@ -265,6 +265,7 @@ export const SPINNER = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧",
265
265
  const SYMBOL: Record<Ended, [string, PaintRole]> = {
266
266
  done: ["✔", "success"],
267
267
  error: ["✘", "error"],
268
+ rejected: ["⊘", "accent"],
268
269
  cancelled: ["○", "muted"],
269
270
  };
270
271
  export function statusSymbol(
@@ -301,28 +302,6 @@ export function described(
301
302
  : `${agent.label} · ${text}`;
302
303
  }
303
304
 
304
- /** The `max` most recently active agents plus any pinned ones, shown in
305
- * stable start order, and how many others are hidden. */
306
- export function visibleAgents(
307
- agents: SubagentState[],
308
- max: number,
309
- pinned: (string | undefined)[] = [],
310
- ): { rows: SubagentState[]; hidden: number } {
311
- if (agents.length <= max) return { rows: agents, hidden: 0 };
312
- const recent = [...agents].sort((a, b) => b.activeAt - a.activeAt);
313
- const keep = new Set(recent.slice(0, max).map((a) => a.id));
314
- for (const id of pinned) {
315
- if (!id || keep.has(id) || !agents.some((a) => a.id === id)) continue;
316
- const drop = [...keep]
317
- .reverse()
318
- .find((k) => !pinned.includes(k) && k !== id);
319
- if (drop) keep.delete(drop);
320
- keep.add(id);
321
- }
322
- const rows = agents.filter((a) => keep.has(a.id));
323
- return { rows, hidden: agents.length - rows.length };
324
- }
325
-
326
305
  const s = (n: number) => (n === 1 ? "" : "s");
327
306
  const cut = (text: string, width: number) =>
328
307
  truncateToWidth(text, Math.max(0, width), "…");
@@ -368,16 +347,6 @@ function rowLine(
368
347
  width,
369
348
  );
370
349
  }
371
- const liveRow = (a: SubagentState, now: number, frame: number): Row => {
372
- const used = usage(a);
373
- return {
374
- symbol: statusSymbol(a, frame),
375
- kind: a.kind,
376
- text: described(a),
377
- failed: a.status === "error",
378
- facts: `${elapsedText(a, now).padStart(8)}${used ? ` · ${used}` : ""}`,
379
- };
380
- };
381
350
  const kindColumn = (kinds: string[]) =>
382
351
  Math.min(12, Math.max(7, ...kinds.map((k) => visibleWidth(k))));
383
352
  /** The kind every agent shares, if any; it then names the batch instead of
@@ -463,7 +432,7 @@ export function decodeCard(data: unknown): AgentCard | undefined {
463
432
  }
464
433
 
465
434
  /** A finished batch: `✔ 3 Research agents finished · 2m 14s`, with outcome
466
- * counts when any failed or was cancelled. Collapsed, it lists only those;
435
+ * counts when any failed, rejected or was cancelled. Collapsed, it lists only those;
467
436
  * expanded, every member with its final text and elapsed time. */
468
437
  export function cardLines(
469
438
  card: AgentCard,
@@ -476,13 +445,22 @@ export function cardLines(
476
445
  const tally = (status: Ended) =>
477
446
  card.agents.filter((a) => a.status === status).length;
478
447
  const failed = tally("error"),
448
+ rejected = tally("rejected"),
479
449
  cancelled = tally("cancelled");
480
450
  const [symbol, role] =
481
- SYMBOL[failed ? "error" : cancelled ? "cancelled" : "done"];
451
+ SYMBOL[
452
+ failed
453
+ ? "error"
454
+ : rejected
455
+ ? "rejected"
456
+ : cancelled
457
+ ? "cancelled"
458
+ : "done"
459
+ ];
482
460
  const kind = sharedKind(card.agents);
483
461
  const outcome =
484
- failed || cancelled
485
- ? ` · ${tally("done")} done${failed ? ` · ${failed} failed` : ""}${
462
+ failed || rejected || cancelled
463
+ ? ` · ${tally("done")} done${failed ? ` · ${failed} failed` : ""}${rejected ? ` · ${rejected} rejected` : ""}${
486
464
  cancelled ? ` · ${cancelled} cancelled` : ""
487
465
  }`
488
466
  : "";
@@ -519,243 +497,32 @@ export interface LiveFrame {
519
497
  agents: SubagentState[];
520
498
  now: number;
521
499
  frame: number;
522
- maxRows: number;
523
- /** Show the `↓ to manage` hint: the input box has focus. */
500
+ /** Show the `↓ to view` hint: the input box has focus. */
524
501
  hint: boolean;
525
502
  }
526
- /** Above the input while a batch is open. Running: a spinner header with the
527
- * batch's outcome counts, then its running and failed/cancelled members; a
528
- * member that finished cleanly is only counted. Settled: the card it is about
529
- * to become, so the collapse into the transcript does not change the text. */
503
+ /** One summary line; the adapted session browser owns all agent rows. */
530
504
  export function liveLines(f: LiveFrame, width: number, paint: Paint): string[] {
531
505
  const { agents } = f;
532
506
  if (agents.length === 0) return [];
533
507
  const running = agents.filter((a) => a.status === "running");
534
508
  if (running.length === 0)
535
- return cardLines(cardOf(agents), false, width, paint, false);
509
+ return cardLines(cardOf(agents), false, width, paint, false).slice(0, 1);
536
510
  const kind = sharedKind(agents);
537
511
  const tally = (status: SubagentStatus) =>
538
512
  agents.filter((a) => a.status === status).length;
539
513
  const done = tally("done"),
540
514
  failed = tally("error"),
515
+ rejected = tally("rejected"),
541
516
  cancelled = tally("cancelled");
542
517
  const counts = `${done ? ` · ${done} done` : ""}${
543
518
  failed ? ` · ${failed} failed` : ""
544
- }${cancelled ? ` · ${cancelled} cancelled` : ""}`;
519
+ }${rejected ? ` · ${rejected} rejected` : ""}${cancelled ? ` · ${cancelled} cancelled` : ""}`;
545
520
  const [spin, role] = statusSymbol(running[0], f.frame);
546
521
  const header = hinted(
547
522
  `${paint(role, spin)} ${running.length} ${noun(kind, running.length)} running${counts}`,
548
- f.hint ? " (↓ to manage)" : "",
523
+ f.hint ? " (↓ to view)" : "",
549
524
  width,
550
525
  paint,
551
526
  );
552
- const listed = [
553
- ...running,
554
- ...agents.filter((a) => a.status === "error" || a.status === "cancelled"),
555
- ];
556
- const rows = listed.slice(0, f.maxRows);
557
- const more = listed.length - rows.length;
558
- const kindWidth = kind ? 0 : kindColumn(rows.map((a) => a.kind));
559
- const leads = tree(rows.length, more);
560
- const lines = [
561
- header,
562
- ...rows.map((a, i) =>
563
- rowLine(liveRow(a, f.now, f.frame), leads[i], kindWidth, width, paint),
564
- ),
565
- ];
566
- if (more) lines.push(cut(`${paint("dim", " └ ")}… +${more} more`, width));
567
- return lines;
568
- }
569
-
570
- export interface PanelFrame {
571
- agents: SubagentState[];
572
- focus: "input" | "panel";
573
- /** Selected row: an agent id, or undefined while the input has focus. */
574
- selected: string | undefined;
575
- /** Agent shown in place of the main view, if any. */
576
- view: string | undefined;
577
- now: number;
578
- frame: number;
579
- maxRows: number;
580
- }
581
- /** Below the input only while it is being used (focus moved down to it, or
582
- * an agent view is open): this Pi session's agents, at most `maxRows` of the
583
- * most recently active plus the selection, `+K more`, and a key hint. */
584
- export function panelLines(
585
- f: PanelFrame,
586
- width: number,
587
- paint: Paint,
588
- ): string[] {
589
- if (f.agents.length === 0 || (f.focus !== "panel" && f.view === undefined))
590
- return [];
591
- const { rows, hidden } = visibleAgents(f.agents, f.maxRows, [
592
- f.selected,
593
- f.view,
594
- ]);
595
- const lines = hidden ? [cut(paint("dim", ` +${hidden} more`), width)] : [];
596
- const kindWidth = kindColumn(rows.map((a) => a.kind));
597
- for (const a of rows) {
598
- const selected = f.focus === "panel" && f.selected === a.id;
599
- lines.push(
600
- rowLine(
601
- liveRow(a, f.now, f.frame),
602
- selected ? "▶" : " ",
603
- kindWidth,
604
- width,
605
- paint,
606
- selected,
607
- ),
608
- );
609
- }
610
- if (f.view === undefined)
611
- lines.push(
612
- cut(paint("dim", " ↑↓ select · Enter open · Esc back to input"), width),
613
- );
614
- return lines;
615
- }
616
-
617
- export type PanelKey =
618
- | "down"
619
- | "up"
620
- | "next"
621
- | "previous"
622
- | "enter"
623
- | "escape"
624
- | "interrupt"
625
- | "pageUp"
626
- | "pageDown"
627
- | "halfUp"
628
- | "halfDown"
629
- | "home"
630
- | "end"
631
- | "other";
632
- /** `pass` leaves the key to Pi; `open`/`close` show or leave an agent view. */
633
- export type PanelAction = "pass" | "consume" | "open" | "close";
634
- export interface Scroll {
635
- top: number;
636
- /** Stick to the newest line as the transcript grows. */
637
- follow: boolean;
638
- }
639
-
640
- /** Focus model. F_input (default) passes every key except ↓ on an idle, empty
641
- * editor, which moves focus down to the agent list; F_panel moves its
642
- * selection, and ↑ past the first row or Esc returns to the input. An agent
643
- * view keeps F_panel and replaces the main view until Esc or Ctrl+C. */
644
- export class PanelFocus {
645
- focus: "input" | "panel" = "input";
646
- selected: string | undefined;
647
- view: string | undefined;
648
- /** Rows of the last rendered agent view, for paging. */
649
- page = 10;
650
- private readonly scrolls = new Map<string, Scroll>();
651
- constructor(
652
- private readonly store: SubagentStore,
653
- private readonly maxRows = 6,
654
- ) {}
655
-
656
- key(key: PanelKey, editorIdle: boolean): PanelAction {
657
- if (this.focus === "input" && this.view === undefined) {
658
- if (key !== "down" || !editorIdle || this.store.size === 0) return "pass";
659
- this.focus = "panel";
660
- this.selected = visibleAgents(
661
- this.store.ordered(),
662
- this.maxRows,
663
- ).rows[0]?.id;
664
- return "consume";
665
- }
666
- const rows = this.store.ordered().map((a) => a.id);
667
- // A selection the store dropped falls back to the first row.
668
- const at = Math.max(0, rows.indexOf(this.selected ?? ""));
669
- switch (key) {
670
- case "up":
671
- case "previous":
672
- // ↑ past the first row returns to the input, the inverse of ↓.
673
- if (at === 0 && this.view === undefined) this.toInput();
674
- else this.selected = rows[Math.max(0, at - 1)];
675
- return "consume";
676
- case "down":
677
- case "next":
678
- this.selected = rows[Math.min(rows.length - 1, at + 1)];
679
- return "consume";
680
- case "enter":
681
- this.selected = rows[at];
682
- if (this.selected === undefined) {
683
- this.toInput();
684
- return "consume";
685
- }
686
- if (this.view === undefined) {
687
- this.view = this.selected;
688
- return "open";
689
- }
690
- this.view = this.selected;
691
- return "consume";
692
- case "escape":
693
- case "interrupt":
694
- if (this.view !== undefined) return this.leave();
695
- this.toInput();
696
- // Ctrl+C keeps Pi's own clear/interrupt/exit meaning.
697
- return key === "escape" ? "consume" : "pass";
698
- case "pageUp":
699
- case "pageDown":
700
- case "halfUp":
701
- case "halfDown":
702
- case "home":
703
- case "end":
704
- if (this.view !== undefined) {
705
- this.scroll(this.view, key);
706
- return "consume";
707
- }
708
- // The main transcript scrolls itself; Ctrl+U/D must not edit or exit.
709
- return key === "halfUp" || key === "halfDown" ? "consume" : "pass";
710
- default:
711
- if (this.view !== undefined) return "consume";
712
- this.toInput();
713
- return "pass";
714
- }
715
- }
716
- /** Pi replaced the agent view (another dialog took the editor slot). */
717
- abandon(): void {
718
- this.view = undefined;
719
- this.toInput();
720
- }
721
- /** Top line for this view, remembered per agent across switches. */
722
- settle(id: string, total: number, height: number): number {
723
- const s = this.scrolls.get(id) ?? { top: 0, follow: true };
724
- const max = Math.max(0, total - height);
725
- const top = s.follow ? max : Math.min(Math.max(0, s.top), max);
726
- this.scrolls.set(id, { top, follow: top >= max });
727
- this.page = Math.max(1, height);
728
- return top;
729
- }
730
- scrollOf(id: string): Scroll | undefined {
731
- return this.scrolls.get(id);
732
- }
733
- /** The store dropped these agents: forget their scroll positions. */
734
- forget(ids: string[]): void {
735
- for (const id of ids) this.scrolls.delete(id);
736
- }
737
- private toInput(): void {
738
- this.focus = "input";
739
- this.selected = undefined;
740
- }
741
- private leave(): PanelAction {
742
- this.view = undefined;
743
- return "close";
744
- }
745
- private scroll(id: string, key: PanelKey): void {
746
- const s = this.scrolls.get(id) ?? { top: 0, follow: true };
747
- const step =
748
- key === "pageUp" || key === "pageDown"
749
- ? Math.max(1, this.page - 1)
750
- : Math.max(1, Math.floor(this.page / 2));
751
- const sign = key === "pageUp" || key === "halfUp" ? -1 : 1;
752
- this.scrolls.set(
753
- id,
754
- key === "home"
755
- ? { top: 0, follow: false }
756
- : key === "end"
757
- ? { top: s.top, follow: true }
758
- : { top: s.top + sign * step, follow: false },
759
- );
760
- }
527
+ return [header];
761
528
  }