@abelxiaoxing/cadence 2.0.35 → 2.0.37

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 (40) 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 +3 -4
  5. package/README.ko.md +4 -4
  6. package/README.md +4 -4
  7. package/README.pt-BR.md +4 -4
  8. package/README.ru.md +5 -4
  9. package/README.zh-CN.md +4 -4
  10. package/THIRD_PARTY_NOTICES.md +9 -1
  11. package/docs/conversation-mode.md +21 -2
  12. package/docs/reuse-and-distribution.md +1 -1
  13. package/docs/service-management.md +35 -9
  14. package/package.json +18 -18
  15. package/src/abort-scope.ts +47 -0
  16. package/src/agent-browser/labeled-rule.ts +74 -0
  17. package/src/agent-browser/session-navigator.ts +187 -0
  18. package/src/agent-browser/source.ts +170 -0
  19. package/src/agent-browser/transcript-content.ts +442 -0
  20. package/src/agent-browser/transcript-pane.ts +324 -0
  21. package/src/agent-panel-model.ts +4 -248
  22. package/src/agent-panel.ts +138 -432
  23. package/src/coordinator-tools.mjs +42 -14
  24. package/src/image-content.mjs +7 -28
  25. package/src/native-build.ts +1 -1
  26. package/src/research-scan.mjs +393 -0
  27. package/src/research-tools.mjs +406 -342
  28. package/src/sdk-worker.mjs +40 -55
  29. package/src/service/contracts/core.ts +0 -1
  30. package/src/service/contracts/workbench.ts +10 -16
  31. package/src/service-cli.mjs +328 -106
  32. package/src/service-host.mjs +545 -404
  33. package/src/service-http-client.ts +55 -50
  34. package/src/worker-public.mjs +1 -2
  35. package/src/worker-toolkit.mjs +110 -0
  36. package/src/worker-workspace.d.mts +13 -0
  37. package/src/worker-workspace.mjs +48 -0
  38. package/web/dist/assets/cadence.css +1 -1
  39. package/web/dist/assets/cadence.js +17 -17
  40. package/web/dist/manifest.json +7 -7
@@ -26,13 +26,7 @@ import {
26
26
  VERSION,
27
27
  } from "@earendil-works/pi-coding-agent";
28
28
  import { conversationResources } from "./conversation-resources.mjs";
29
- import { coordinatorTools } from "./coordinator-tools.mjs";
30
- import {
31
- decodeImageBase64,
32
- IMAGE_LIMITS,
33
- validateImageBytes,
34
- } from "./image-content.mjs";
35
- import { researchClock, researchTools } from "./research-tools.mjs";
29
+ import { decodeImageBase64, validateImageBytes } from "./image-content.mjs";
36
30
  import {
37
31
  BROWSER_COMMAND_ENTRY,
38
32
  WEBUI_SESSION_ENTRY,
@@ -45,7 +39,9 @@ import {
45
39
  parseWireJson,
46
40
  } from "./worker-public.mjs";
47
41
  import { own } from "./worker-redaction.mjs";
48
- import { captureBash, ToolIngress } from "./worker-tools.mjs";
42
+ import { createWorkerToolkit } from "./worker-toolkit.mjs";
43
+ import { ToolIngress } from "./worker-tools.mjs";
44
+ import { bindWorkerWorkspace } from "./worker-workspace.mjs";
49
45
 
50
46
  const adapters = {
51
47
  "openai-completions": () =>
@@ -64,6 +60,7 @@ const adapters = {
64
60
  import("@earendil-works/pi-ai/api/azure-openai-responses"),
65
61
  };
66
62
  let session;
63
+ let toolkit;
67
64
  let ownsCoordinatorChannel = false;
68
65
  let ownedAgent;
69
66
  let unsubscribe;
@@ -81,7 +78,7 @@ let terminalStopReason = "UNKNOWN";
81
78
  let requestPrepared = false;
82
79
  let actualResponseStatus = "UNKNOWN";
83
80
  let preflight = "UNKNOWN";
84
- let cleanupFailures = 0; // Bit flags: unsubscribe=1, abort=2, dispose=4, owned close=8.
81
+ let cleanupFailures = 0; // Bit flags: unsubscribe=1, abort=2, session/tool dispose=4, owned close=8.
85
82
  let pendingAbort;
86
83
  let cleanupSettled = false;
87
84
  const fail = (where, category) => {
@@ -306,7 +303,7 @@ try {
306
303
  const investigation =
307
304
  envelope.investigation === undefined
308
305
  ? null
309
- : closed(envelope.investigation, ["roots", "timeoutMs", "deadlineMs"]);
306
+ : closed(envelope.investigation, ["roots", "timeoutMs"]);
310
307
  if (
311
308
  investigation &&
312
309
  (!Array.isArray(investigation.roots) ||
@@ -317,9 +314,7 @@ try {
317
314
  ) ||
318
315
  !Number.isSafeInteger(investigation.timeoutMs) ||
319
316
  investigation.timeoutMs < 100 ||
320
- investigation.timeoutMs > LIMITS.workerMs ||
321
- !Number.isSafeInteger(investigation.deadlineMs) ||
322
- investigation.deadlineMs < 0)
317
+ investigation.timeoutMs > LIMITS.workerMs)
323
318
  )
324
319
  refuse("parse", "invalid-investigation");
325
320
  const publicRequest = decodeWorkerPublicRequest(envelope.request);
@@ -465,50 +460,33 @@ try {
465
460
  process.stdout.on("error", stdoutFailureListener);
466
461
  stage = "session";
467
462
  const requestedThinkingLevel = thinkingLevel ?? "off";
463
+ const workspace = bindWorkerWorkspace(cwd, investigation?.roots ?? [cwd]);
468
464
  const manager = conversation
469
- ? openConversation(target, cwd, model, requestedThinkingLevel)
470
- : SessionManager.inMemory(cwd);
471
- const coordinationTools = coordinator ? coordinatorTools() : undefined;
465
+ ? openConversation(target, workspace.cwd, model, requestedThinkingLevel)
466
+ : SessionManager.inMemory(workspace.cwd);
467
+ toolkit = createWorkerToolkit({
468
+ workspace,
469
+ purpose: publicRequest.purpose,
470
+ coordinator,
471
+ secrets,
472
+ fail: captureFailure,
473
+ createLocalBashOperations,
474
+ queue: emitter.queue,
475
+ });
472
476
  ownsCoordinatorChannel = coordinator;
473
477
  const created = await createAgentSession({
474
- cwd,
475
- agentDir: cwd,
478
+ ...toolkit.sessionOptions,
479
+ agentDir: workspace.cwd,
476
480
  model,
477
481
  modelRuntime: runtime,
478
482
  thinkingLevel: requestedThinkingLevel,
479
- tools: coordinator
480
- ? ["cadence_research", "cadence_plan", "cadence_status"]
481
- : kind === "code"
482
- ? ["read", "grep", "find", "ls", "write", "edit", "bash"]
483
- : ["read", "grep", "find", "ls"],
484
- customTools: coordinator
485
- ? coordinationTools
486
- : kind === "code"
487
- ? [
488
- captureBash(
489
- cwd,
490
- secrets,
491
- captureFailure,
492
- createLocalBashOperations,
493
- emitter.queue,
494
- ),
495
- ]
496
- : conversation
497
- ? []
498
- : researchTools(
499
- cwd,
500
- investigation?.roots ?? [cwd],
501
- investigation ?? {
502
- timeoutMs: LIMITS.workerMs,
503
- // Standalone protocol callers without a launcher policy still
504
- // start at process birth, never at tool construction.
505
- deadlineMs:
506
- researchClock() + LIMITS.workerMs - process.uptime() * 1000,
507
- },
508
- ),
509
483
  resourceLoader:
510
484
  conversation && !coordinator
511
- ? conversationResources(resourceLoader, cwd, conversation.agentDir)
485
+ ? conversationResources(
486
+ resourceLoader,
487
+ workspace.cwd,
488
+ conversation.agentDir,
489
+ )
512
490
  : resourceLoader,
513
491
  sessionManager: manager,
514
492
  settingsManager: SettingsManager.inMemory({
@@ -570,7 +548,9 @@ try {
570
548
  session.agent.toolExecution = "sequential";
571
549
  if (session.agent.toolExecution !== "sequential")
572
550
  refuse("session", "capture-unsupported");
573
- session.agent.state.tools = ingress.wrap(session.agent.state.tools);
551
+ session.agent.state.tools = ingress.wrap(
552
+ toolkit.wrap(session.agent.state.tools),
553
+ );
574
554
  const initialLeaf = conversation ? manager.getLeafId() : null;
575
555
  let recordedUser = null;
576
556
  unsubscribe = session.agent.subscribe(async (event) => {
@@ -667,7 +647,6 @@ try {
667
647
  if (
668
648
  !Number.isSafeInteger(descriptor.bytes) ||
669
649
  descriptor.bytes < 1 ||
670
- descriptor.bytes > IMAGE_LIMITS.wireBytes ||
671
650
  !/^[a-f0-9]{64}$/.test(descriptor.sha256) ||
672
651
  !model.input?.includes("image")
673
652
  )
@@ -693,21 +672,18 @@ try {
693
672
  images.length !== publicRequest.imageCount
694
673
  )
695
674
  throw new Error("Invalid images");
696
- let total = 0;
697
675
  for (const image of images) {
698
676
  closed(image, ["type", "data", "mimeType"]);
699
677
  if (image.type !== "image") throw new Error("Invalid image");
700
678
  const decoded = decodeImageBase64(image.data);
701
679
  validateImageBytes(decoded, image.mimeType);
702
- total += decoded.length;
703
680
  }
704
- if (total > IMAGE_LIMITS.totalBytes) throw new Error("Images exceed bound");
705
681
  }
706
682
  const suppliedPrompt = [
707
683
  publicRequest.context,
708
684
  ...(!conversation && kind !== "code"
709
685
  ? [
710
- `Investigation roots: ${JSON.stringify(investigation?.roots ?? [cwd])}. Start at these specific paths, not / or their parents. Tools use bounded cooperative reads; no shell is available. Search filenames and shallow directories before content. Do not repeat broad scans or silently exclude backup trees. Total worker deadline: ${investigation?.timeoutMs ?? LIMITS.workerMs}ms, including model and tool time; activity never extends it. Reserve the last portion for a concise final report. On any budget/coverage limit, summarize partial evidence and unresolved questions; never claim exhaustive absence.`,
686
+ `Investigation roots: ${JSON.stringify(workspace.roots)}. Start at these specific paths, not / or their parents. Observation tools support file/range batches, literal multi-pattern searches and one-use continuation cursors; no shell is available. Read their schemas. Continue a cursor to advance actual I/O, including empty progress pages; do not repeat the initial query to paginate. Close unused cursors. Source-changed/expired cursors require an explicit fresh query, never an assumed continuation. Coverage names omissions and live-filesystem observation, not a snapshot. Search filenames and shallow directories before content; do not silently exclude backup trees. Total worker deadline: ${investigation?.timeoutMs ?? LIMITS.workerMs}ms, including model and tool time; activity never extends it. There is no cumulative tool-call quota or early tool cutoff. Use nextCursor when available; for terminal omissions, narrow the scope as needed. Never claim exhaustive absence from a progress page or incomplete coverage. Report retained evidence and unresolved questions honestly.`,
711
687
  ]
712
688
  : []),
713
689
  ...publicRequest.handoff.inputs.map(
@@ -777,12 +753,21 @@ try {
777
753
  fail("cleanup", "cleanup-failure");
778
754
  }
779
755
  })();
756
+ const closingTools = (async () => {
757
+ try {
758
+ await toolkit?.close();
759
+ } catch {
760
+ cleanupFailures |= 4;
761
+ fail("cleanup", "cleanup-failure");
762
+ }
763
+ })();
780
764
  await Promise.all([
781
765
  closing,
782
766
  unsubscribing,
783
767
  pendingAbort,
784
768
  aborting,
785
769
  disposing,
770
+ closingTools,
786
771
  emitter?.drain(),
787
772
  ]);
788
773
  // A final snapshot exists only after the actual cleanup attempts settle.
@@ -16,7 +16,6 @@ export {
16
16
  errorStatus,
17
17
  GRAPH_SCHEMA,
18
18
  HISTORY_SCHEMA,
19
- IMAGE_COUNT,
20
19
  integer,
21
20
  invalid,
22
21
  LIMITS,
@@ -553,11 +553,7 @@ export function decodeWorkbenchRead(v: unknown): WorkbenchRead {
553
553
  "offset",
554
554
  ...(Object.hasOwn(v ?? {}, "live") ? ["live"] : []),
555
555
  ]);
556
- const offset = integer(
557
- o.offset,
558
- 0,
559
- 4 * Math.ceil(IMAGE_LIMITS.bytes / 3),
560
- );
556
+ const offset = integer(o.offset, 0);
561
557
  if (
562
558
  offset % IMAGE_LIMITS.chunkChars ||
563
559
  (o.live !== undefined && o.live !== true)
@@ -569,7 +565,7 @@ export function decodeWorkbenchRead(v: unknown): WorkbenchRead {
569
565
  leaf: nullable(o.leaf, decodeEntryId),
570
566
  ...(o.live === undefined ? {} : { live: true as const }),
571
567
  entry: decodeEntryId(o.entry),
572
- index: integer(o.index, 0, 1024),
568
+ index: integer(o.index, 0),
573
569
  offset,
574
570
  };
575
571
  }
@@ -759,8 +755,8 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
759
755
  imageId: decodeId(o.imageId),
760
756
  send,
761
757
  mimeType: oneOf(o.mimeType, IMAGE_TYPES),
762
- size: integer(o.size, 1, IMAGE_LIMITS.bytes),
763
- offset: integer(o.offset, 0, 4 * Math.ceil(IMAGE_LIMITS.bytes / 3)),
758
+ size: integer(o.size, 1),
759
+ offset: integer(o.offset, 0),
764
760
  data: text(o.data, IMAGE_LIMITS.chunkChars, true),
765
761
  };
766
762
  }
@@ -784,7 +780,7 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
784
780
  text: text(o.text, CONVERSATION_SEND_BYTES),
785
781
  ...(o.images === undefined
786
782
  ? {}
787
- : { images: list(o.images, IMAGE_LIMITS.count, decodeId) }),
783
+ : { images: list(o.images, Number.MAX_SAFE_INTEGER, decodeId) }),
788
784
  model: decodeChoiceVersion(o.model),
789
785
  revision: integer(o.revision, 0),
790
786
  intent: oneOf(o.intent, ["message", "enter", "exit"]),
@@ -839,7 +835,7 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
839
835
  text: text(o.text, CONVERSATION_SEND_BYTES),
840
836
  ...(o.images === undefined
841
837
  ? {}
842
- : { images: list(o.images, IMAGE_LIMITS.count, decodeId) }),
838
+ : { images: list(o.images, Number.MAX_SAFE_INTEGER, decodeId) }),
843
839
  model: decodeChoiceVersion(o.model),
844
840
  };
845
841
  }
@@ -905,7 +901,7 @@ export function decodeChatTurn(v: unknown): ChatTurn {
905
901
  };
906
902
  }
907
903
  function decodeChatImages(v: unknown): ChatImage[] {
908
- return list(v, IMAGE_LIMITS.count, (value) => {
904
+ return list(v, Number.MAX_SAFE_INTEGER, (value) => {
909
905
  const o = closed(value, [
910
906
  "entry",
911
907
  "index",
@@ -917,7 +913,7 @@ function decodeChatImages(v: unknown): ChatImage[] {
917
913
  return {
918
914
  ...(o.live === undefined ? {} : { live: true as const }),
919
915
  entry: decodeEntryId(o.entry),
920
- index: integer(o.index, 0, 1024),
916
+ index: integer(o.index, 0),
921
917
  mimeType: oneOf(o.mimeType, IMAGE_TYPES),
922
918
  };
923
919
  });
@@ -1062,7 +1058,7 @@ export function decodeWorkbenchResult(v: unknown): WorkbenchResult {
1062
1058
  kind: k,
1063
1059
  commandId: decodeId(o.commandId),
1064
1060
  imageId: decodeId(o.imageId),
1065
- offset: integer(o.offset, 0, 4 * Math.ceil(IMAGE_LIMITS.bytes / 3)),
1061
+ offset: integer(o.offset, 0),
1066
1062
  };
1067
1063
  }
1068
1064
  if (k === "conversation-image") {
@@ -1071,9 +1067,7 @@ export function decodeWorkbenchResult(v: unknown): WorkbenchResult {
1071
1067
  kind: k,
1072
1068
  mimeType: oneOf(o.mimeType, IMAGE_TYPES),
1073
1069
  data: text(o.data, IMAGE_LIMITS.chunkChars, true),
1074
- next: nullable(o.next, (n) =>
1075
- integer(n, 0, 4 * Math.ceil(IMAGE_LIMITS.bytes / 3)),
1076
- ),
1070
+ next: nullable(o.next, (n) => integer(n, 0)),
1077
1071
  };
1078
1072
  }
1079
1073
  if (k === "conversation-context") {