@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.
- package/README.de.md +4 -4
- package/README.es.md +4 -4
- package/README.fr.md +4 -4
- package/README.ja.md +4 -4
- package/README.ko.md +4 -4
- package/README.md +11 -9
- package/README.pt-BR.md +4 -4
- package/README.ru.md +4 -4
- package/README.zh-CN.md +12 -10
- package/THIRD_PARTY_NOTICES.md +9 -1
- package/agents/design-explorer.md +4 -2
- package/agents/diagnosis-worker.md +5 -2
- package/agents/implementation-worker.md +19 -12
- package/docs/conversation-mode.md +46 -18
- package/docs/reuse-and-distribution.md +1 -1
- package/docs/service-management.md +35 -9
- package/package.json +16 -8
- package/src/agent-browser/labeled-rule.ts +74 -0
- package/src/agent-browser/session-navigator.ts +214 -0
- package/src/agent-browser/source.ts +174 -0
- package/src/agent-browser/transcript-content.ts +442 -0
- package/src/agent-browser/transcript-pane.ts +324 -0
- package/src/agent-panel-cadence.ts +147 -628
- package/src/agent-panel-model.ts +34 -267
- package/src/agent-panel.ts +139 -437
- package/src/cadence-instructions.ts +8 -7
- package/src/cadence-mode.ts +30 -9
- package/src/change-tools.mjs +268 -0
- package/src/coordinator-tools.mjs +44 -16
- package/src/git-environment.d.mts +2 -0
- package/src/git-environment.mjs +24 -0
- package/src/image-content.mjs +7 -28
- package/src/index.ts +1 -1
- package/src/native-build.ts +1 -1
- package/src/native-workflow-history.ts +20 -3
- package/src/operator-cli.mjs +18 -11
- package/src/research-scan.mjs +393 -0
- package/src/research-tools.mjs +406 -342
- package/src/sdk-worker.mjs +42 -55
- package/src/service/contracts/core.ts +0 -1
- package/src/service/contracts/workbench.ts +21 -19
- package/src/service/contracts/workflow.ts +283 -16
- package/src/service/coordination.ts +7 -0
- package/src/service-cli.mjs +652 -149
- package/src/service-host.mjs +2745 -1137
- package/src/worker-capture.mjs +24 -1
- package/src/worker-public.mjs +19 -2
- package/src/worker-redaction.mjs +11 -0
- package/src/worker-toolkit.mjs +157 -0
- package/src/worker-workspace.d.mts +13 -0
- package/src/worker-workspace.mjs +48 -0
- package/src/workspace.ts +4 -24
- package/web/dist/assets/cadence.css +1 -1
- package/web/dist/assets/cadence.js +18 -17
- package/web/dist/manifest.json +7 -7
package/src/sdk-worker.mjs
CHANGED
|
@@ -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 {
|
|
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 {
|
|
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"
|
|
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,35 @@ 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
|
-
|
|
465
|
+
? openConversation(target, workspace.cwd, model, requestedThinkingLevel)
|
|
466
|
+
: SessionManager.inMemory(workspace.cwd);
|
|
467
|
+
toolkit = createWorkerToolkit({
|
|
468
|
+
workspace,
|
|
469
|
+
purpose: publicRequest.purpose,
|
|
470
|
+
changes: publicRequest.changes,
|
|
471
|
+
coordinator,
|
|
472
|
+
reporting: !conversation && publicRequest.purpose === "edit",
|
|
473
|
+
secrets,
|
|
474
|
+
fail: captureFailure,
|
|
475
|
+
createLocalBashOperations,
|
|
476
|
+
queue: emitter.queue,
|
|
477
|
+
});
|
|
472
478
|
ownsCoordinatorChannel = coordinator;
|
|
473
479
|
const created = await createAgentSession({
|
|
474
|
-
|
|
475
|
-
agentDir: cwd,
|
|
480
|
+
...toolkit.sessionOptions,
|
|
481
|
+
agentDir: workspace.cwd,
|
|
476
482
|
model,
|
|
477
483
|
modelRuntime: runtime,
|
|
478
484
|
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
485
|
resourceLoader:
|
|
510
486
|
conversation && !coordinator
|
|
511
|
-
? conversationResources(
|
|
487
|
+
? conversationResources(
|
|
488
|
+
resourceLoader,
|
|
489
|
+
workspace.cwd,
|
|
490
|
+
conversation.agentDir,
|
|
491
|
+
)
|
|
512
492
|
: resourceLoader,
|
|
513
493
|
sessionManager: manager,
|
|
514
494
|
settingsManager: SettingsManager.inMemory({
|
|
@@ -570,7 +550,9 @@ try {
|
|
|
570
550
|
session.agent.toolExecution = "sequential";
|
|
571
551
|
if (session.agent.toolExecution !== "sequential")
|
|
572
552
|
refuse("session", "capture-unsupported");
|
|
573
|
-
session.agent.state.tools = ingress.wrap(
|
|
553
|
+
session.agent.state.tools = ingress.wrap(
|
|
554
|
+
toolkit.wrap(session.agent.state.tools),
|
|
555
|
+
);
|
|
574
556
|
const initialLeaf = conversation ? manager.getLeafId() : null;
|
|
575
557
|
let recordedUser = null;
|
|
576
558
|
unsubscribe = session.agent.subscribe(async (event) => {
|
|
@@ -667,7 +649,6 @@ try {
|
|
|
667
649
|
if (
|
|
668
650
|
!Number.isSafeInteger(descriptor.bytes) ||
|
|
669
651
|
descriptor.bytes < 1 ||
|
|
670
|
-
descriptor.bytes > IMAGE_LIMITS.wireBytes ||
|
|
671
652
|
!/^[a-f0-9]{64}$/.test(descriptor.sha256) ||
|
|
672
653
|
!model.input?.includes("image")
|
|
673
654
|
)
|
|
@@ -693,21 +674,18 @@ try {
|
|
|
693
674
|
images.length !== publicRequest.imageCount
|
|
694
675
|
)
|
|
695
676
|
throw new Error("Invalid images");
|
|
696
|
-
let total = 0;
|
|
697
677
|
for (const image of images) {
|
|
698
678
|
closed(image, ["type", "data", "mimeType"]);
|
|
699
679
|
if (image.type !== "image") throw new Error("Invalid image");
|
|
700
680
|
const decoded = decodeImageBase64(image.data);
|
|
701
681
|
validateImageBytes(decoded, image.mimeType);
|
|
702
|
-
total += decoded.length;
|
|
703
682
|
}
|
|
704
|
-
if (total > IMAGE_LIMITS.totalBytes) throw new Error("Images exceed bound");
|
|
705
683
|
}
|
|
706
684
|
const suppliedPrompt = [
|
|
707
685
|
publicRequest.context,
|
|
708
686
|
...(!conversation && kind !== "code"
|
|
709
687
|
? [
|
|
710
|
-
`Investigation roots: ${JSON.stringify(
|
|
688
|
+
`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
689
|
]
|
|
712
690
|
: []),
|
|
713
691
|
...publicRequest.handoff.inputs.map(
|
|
@@ -777,12 +755,21 @@ try {
|
|
|
777
755
|
fail("cleanup", "cleanup-failure");
|
|
778
756
|
}
|
|
779
757
|
})();
|
|
758
|
+
const closingTools = (async () => {
|
|
759
|
+
try {
|
|
760
|
+
await toolkit?.close();
|
|
761
|
+
} catch {
|
|
762
|
+
cleanupFailures |= 4;
|
|
763
|
+
fail("cleanup", "cleanup-failure");
|
|
764
|
+
}
|
|
765
|
+
})();
|
|
780
766
|
await Promise.all([
|
|
781
767
|
closing,
|
|
782
768
|
unsubscribing,
|
|
783
769
|
pendingAbort,
|
|
784
770
|
aborting,
|
|
785
771
|
disposing,
|
|
772
|
+
closingTools,
|
|
786
773
|
emitter?.drain(),
|
|
787
774
|
]);
|
|
788
775
|
// A final snapshot exists only after the actual cleanup attempts settle.
|
|
@@ -107,7 +107,7 @@ export type WorkbenchRead =
|
|
|
107
107
|
| { kind: "workflow-history"; after: string | null; scan?: string }
|
|
108
108
|
| { kind: "workflow-detail"; id: string; stepId: string }
|
|
109
109
|
| { kind: "workflow-transcript"; id: string; stepId: string }
|
|
110
|
-
| { kind: "workflow"; id: string }
|
|
110
|
+
| { kind: "workflow"; id: string; before?: number }
|
|
111
111
|
| { kind: "conversation-active" }
|
|
112
112
|
| { kind: "conversations"; after?: ChatCursor | null }
|
|
113
113
|
| {
|
|
@@ -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
|
|
568
|
+
index: integer(o.index, 0),
|
|
573
569
|
offset,
|
|
574
570
|
};
|
|
575
571
|
}
|
|
@@ -614,8 +610,16 @@ export function decodeWorkbenchRead(v: unknown): WorkbenchRead {
|
|
|
614
610
|
return { kind, id: decodeId(o.id), stepId: text(o.stepId, 160, true) };
|
|
615
611
|
}
|
|
616
612
|
case "workflow": {
|
|
617
|
-
const o = closed(v, [
|
|
618
|
-
|
|
613
|
+
const o = closed(v, [
|
|
614
|
+
"kind",
|
|
615
|
+
"id",
|
|
616
|
+
...(Object.hasOwn(v ?? {}, "before") ? ["before"] : []),
|
|
617
|
+
]);
|
|
618
|
+
return {
|
|
619
|
+
kind,
|
|
620
|
+
id: decodeId(o.id),
|
|
621
|
+
...(o.before === undefined ? {} : { before: integer(o.before, 1) }),
|
|
622
|
+
};
|
|
619
623
|
}
|
|
620
624
|
case "conversations": {
|
|
621
625
|
const after = Object.hasOwn(v as object, "after");
|
|
@@ -759,8 +763,8 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
|
|
|
759
763
|
imageId: decodeId(o.imageId),
|
|
760
764
|
send,
|
|
761
765
|
mimeType: oneOf(o.mimeType, IMAGE_TYPES),
|
|
762
|
-
size: integer(o.size, 1
|
|
763
|
-
offset: integer(o.offset, 0
|
|
766
|
+
size: integer(o.size, 1),
|
|
767
|
+
offset: integer(o.offset, 0),
|
|
764
768
|
data: text(o.data, IMAGE_LIMITS.chunkChars, true),
|
|
765
769
|
};
|
|
766
770
|
}
|
|
@@ -784,7 +788,7 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
|
|
|
784
788
|
text: text(o.text, CONVERSATION_SEND_BYTES),
|
|
785
789
|
...(o.images === undefined
|
|
786
790
|
? {}
|
|
787
|
-
: { images: list(o.images,
|
|
791
|
+
: { images: list(o.images, Number.MAX_SAFE_INTEGER, decodeId) }),
|
|
788
792
|
model: decodeChoiceVersion(o.model),
|
|
789
793
|
revision: integer(o.revision, 0),
|
|
790
794
|
intent: oneOf(o.intent, ["message", "enter", "exit"]),
|
|
@@ -839,7 +843,7 @@ export function decodeWorkbenchCommand(v: unknown): WorkbenchCommand {
|
|
|
839
843
|
text: text(o.text, CONVERSATION_SEND_BYTES),
|
|
840
844
|
...(o.images === undefined
|
|
841
845
|
? {}
|
|
842
|
-
: { images: list(o.images,
|
|
846
|
+
: { images: list(o.images, Number.MAX_SAFE_INTEGER, decodeId) }),
|
|
843
847
|
model: decodeChoiceVersion(o.model),
|
|
844
848
|
};
|
|
845
849
|
}
|
|
@@ -905,7 +909,7 @@ export function decodeChatTurn(v: unknown): ChatTurn {
|
|
|
905
909
|
};
|
|
906
910
|
}
|
|
907
911
|
function decodeChatImages(v: unknown): ChatImage[] {
|
|
908
|
-
return list(v,
|
|
912
|
+
return list(v, Number.MAX_SAFE_INTEGER, (value) => {
|
|
909
913
|
const o = closed(value, [
|
|
910
914
|
"entry",
|
|
911
915
|
"index",
|
|
@@ -917,7 +921,7 @@ function decodeChatImages(v: unknown): ChatImage[] {
|
|
|
917
921
|
return {
|
|
918
922
|
...(o.live === undefined ? {} : { live: true as const }),
|
|
919
923
|
entry: decodeEntryId(o.entry),
|
|
920
|
-
index: integer(o.index, 0
|
|
924
|
+
index: integer(o.index, 0),
|
|
921
925
|
mimeType: oneOf(o.mimeType, IMAGE_TYPES),
|
|
922
926
|
};
|
|
923
927
|
});
|
|
@@ -1062,7 +1066,7 @@ export function decodeWorkbenchResult(v: unknown): WorkbenchResult {
|
|
|
1062
1066
|
kind: k,
|
|
1063
1067
|
commandId: decodeId(o.commandId),
|
|
1064
1068
|
imageId: decodeId(o.imageId),
|
|
1065
|
-
offset: integer(o.offset, 0
|
|
1069
|
+
offset: integer(o.offset, 0),
|
|
1066
1070
|
};
|
|
1067
1071
|
}
|
|
1068
1072
|
if (k === "conversation-image") {
|
|
@@ -1071,9 +1075,7 @@ export function decodeWorkbenchResult(v: unknown): WorkbenchResult {
|
|
|
1071
1075
|
kind: k,
|
|
1072
1076
|
mimeType: oneOf(o.mimeType, IMAGE_TYPES),
|
|
1073
1077
|
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
|
-
),
|
|
1078
|
+
next: nullable(o.next, (n) => integer(n, 0)),
|
|
1077
1079
|
};
|
|
1078
1080
|
}
|
|
1079
1081
|
if (k === "conversation-context") {
|