@abelxiaoxing/cadence 2.0.23 → 2.0.24
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/docs/conversation-mode.md +19 -0
- package/package.json +2 -1
- package/src/cadence-mode.ts +283 -165
- package/src/coordinator-tools.mjs +9 -0
- package/src/native-build.ts +1 -1
- package/src/native-workflow-history.ts +3 -1
- package/src/research-tools.mjs +365 -0
- package/src/sdk-worker.mjs +59 -9
- package/src/service/contracts/workflow.ts +132 -1
- package/src/service-cli.mjs +15 -2
- package/src/service-host.mjs +217 -29
- package/src/worker-public.mjs +16 -1
- package/web/dist/assets/cadence.js +15 -14
- package/web/dist/manifest.json +5 -5
package/src/service-cli.mjs
CHANGED
|
@@ -1073,10 +1073,23 @@ function decodeCaptureEvent(v) {
|
|
|
1073
1073
|
const kind = tag(v);
|
|
1074
1074
|
switch (kind) {
|
|
1075
1075
|
case "ready": {
|
|
1076
|
-
const o = closed(v, [
|
|
1076
|
+
const o = closed(v, [
|
|
1077
|
+
"kind",
|
|
1078
|
+
"requestProtocol",
|
|
1079
|
+
...Object.hasOwn(v ?? {}, "runtime") ? ["runtime"] : []
|
|
1080
|
+
]);
|
|
1077
1081
|
return {
|
|
1078
1082
|
kind,
|
|
1079
|
-
requestProtocol: literal(o.requestProtocol, WORKER_PROTOCOL)
|
|
1083
|
+
requestProtocol: literal(o.requestProtocol, WORKER_PROTOCOL),
|
|
1084
|
+
...o.runtime === undefined ? {} : {
|
|
1085
|
+
runtime: (() => {
|
|
1086
|
+
const r = closed(o.runtime, ["sdkVersion", "workerHash"]);
|
|
1087
|
+
return {
|
|
1088
|
+
sdkVersion: text(r.sdkVersion, 128, true),
|
|
1089
|
+
workerHash: decodeHash(r.workerHash)
|
|
1090
|
+
};
|
|
1091
|
+
})()
|
|
1092
|
+
}
|
|
1080
1093
|
};
|
|
1081
1094
|
}
|
|
1082
1095
|
case "message-start": {
|
package/src/service-host.mjs
CHANGED
|
@@ -1117,10 +1117,23 @@ function decodeCaptureEvent(v) {
|
|
|
1117
1117
|
const kind = tag(v);
|
|
1118
1118
|
switch (kind) {
|
|
1119
1119
|
case "ready": {
|
|
1120
|
-
const o = closed(v, [
|
|
1120
|
+
const o = closed(v, [
|
|
1121
|
+
"kind",
|
|
1122
|
+
"requestProtocol",
|
|
1123
|
+
...Object.hasOwn(v ?? {}, "runtime") ? ["runtime"] : []
|
|
1124
|
+
]);
|
|
1121
1125
|
return {
|
|
1122
1126
|
kind,
|
|
1123
|
-
requestProtocol: literal(o.requestProtocol, WORKER_PROTOCOL)
|
|
1127
|
+
requestProtocol: literal(o.requestProtocol, WORKER_PROTOCOL),
|
|
1128
|
+
...o.runtime === undefined ? {} : {
|
|
1129
|
+
runtime: (() => {
|
|
1130
|
+
const r = closed(o.runtime, ["sdkVersion", "workerHash"]);
|
|
1131
|
+
return {
|
|
1132
|
+
sdkVersion: text(r.sdkVersion, 128, true),
|
|
1133
|
+
workerHash: decodeHash(r.workerHash)
|
|
1134
|
+
};
|
|
1135
|
+
})()
|
|
1136
|
+
}
|
|
1124
1137
|
};
|
|
1125
1138
|
}
|
|
1126
1139
|
case "message-start": {
|
|
@@ -3801,14 +3814,24 @@ function decodeWorkflowProposal(v) {
|
|
|
3801
3814
|
function decodeWorkflowRequest(v) {
|
|
3802
3815
|
const action = Object.getOwnPropertyDescriptor(v ?? {}, "action")?.value;
|
|
3803
3816
|
if (action === "research") {
|
|
3804
|
-
const o2 = closed(v, [
|
|
3817
|
+
const o2 = closed(v, [
|
|
3818
|
+
"action",
|
|
3819
|
+
"goal",
|
|
3820
|
+
"questions",
|
|
3821
|
+
"model",
|
|
3822
|
+
...Object.hasOwn(v ?? {}, "roots") ? ["roots"] : []
|
|
3823
|
+
]);
|
|
3805
3824
|
const questions = list(o2.questions, WORKFLOW_LIMITS.parallel, (q) => text(q, 8192, true));
|
|
3806
3825
|
if (!questions.length)
|
|
3807
3826
|
throw new Error("Research needs a question");
|
|
3827
|
+
const roots = o2.roots === undefined ? undefined : list(o2.roots, 8, (p) => text(p, 4096, true));
|
|
3828
|
+
if (roots && !roots.length)
|
|
3829
|
+
throw new Error("Research needs a specific root");
|
|
3808
3830
|
return {
|
|
3809
3831
|
action,
|
|
3810
3832
|
goal: text(o2.goal, 8192, true),
|
|
3811
3833
|
questions,
|
|
3834
|
+
...roots ? { roots } : {},
|
|
3812
3835
|
model: decodeChoiceVersion(o2.model)
|
|
3813
3836
|
};
|
|
3814
3837
|
}
|
|
@@ -3841,7 +3864,8 @@ function decodeWorkflowRun(v) {
|
|
|
3841
3864
|
"steps",
|
|
3842
3865
|
"notice",
|
|
3843
3866
|
"mergedCommit",
|
|
3844
|
-
"humanReviewed"
|
|
3867
|
+
"humanReviewed",
|
|
3868
|
+
...Object.hasOwn(v ?? {}, "diagnostics") ? ["diagnostics"] : []
|
|
3845
3869
|
]);
|
|
3846
3870
|
const status = (x) => oneOf(x, [
|
|
3847
3871
|
"running",
|
|
@@ -3854,6 +3878,7 @@ function decodeWorkflowRun(v) {
|
|
|
3854
3878
|
if (o.humanReviewed !== false)
|
|
3855
3879
|
throw new Error("Automatic execution is not human review");
|
|
3856
3880
|
return {
|
|
3881
|
+
...o.diagnostics === undefined ? {} : { diagnostics: decodeWorkflowDiagnostics(o.diagnostics) },
|
|
3857
3882
|
id: decodeId(o.id),
|
|
3858
3883
|
epoch: decodeId(o.epoch),
|
|
3859
3884
|
goal: text(o.goal, 8192),
|
|
@@ -3878,9 +3903,21 @@ function decodeWorkflowRun(v) {
|
|
|
3878
3903
|
"text",
|
|
3879
3904
|
"exitCode",
|
|
3880
3905
|
"truncated",
|
|
3906
|
+
...Object.hasOwn(v2 ?? {}, "timing") ? ["timing"] : [],
|
|
3907
|
+
...Object.hasOwn(v2 ?? {}, "runtime") ? ["runtime"] : [],
|
|
3881
3908
|
...linked ? ["childRunId"] : []
|
|
3882
3909
|
]);
|
|
3883
3910
|
return {
|
|
3911
|
+
...s.timing === undefined ? {} : { timing: decodeWorkflowTiming(s.timing) },
|
|
3912
|
+
...s.runtime === undefined ? {} : {
|
|
3913
|
+
runtime: (() => {
|
|
3914
|
+
const r = closed(s.runtime, ["sdkVersion", "workerHash"]);
|
|
3915
|
+
return {
|
|
3916
|
+
sdkVersion: text(r.sdkVersion, 128, true),
|
|
3917
|
+
workerHash: decodeHash(r.workerHash)
|
|
3918
|
+
};
|
|
3919
|
+
})()
|
|
3920
|
+
},
|
|
3884
3921
|
id: text(s.id, 160, true),
|
|
3885
3922
|
...linked ? { childRunId: decodeId(s.childRunId) } : {},
|
|
3886
3923
|
kind: oneOf(s.kind, [
|
|
@@ -3955,6 +3992,55 @@ At most ${p.repairAttempts} repair rounds. ${p.delivery === "local-merge" ? "Aut
|
|
|
3955
3992
|
${p.projectContext}
|
|
3956
3993
|
`;
|
|
3957
3994
|
}
|
|
3995
|
+
var timestamp = (v) => integer(v, 0, 8640000000000000);
|
|
3996
|
+
function decodeWorkflowTiming(v) {
|
|
3997
|
+
const o = closed(v, [
|
|
3998
|
+
"createdAt",
|
|
3999
|
+
"preparedAt",
|
|
4000
|
+
"startedAt",
|
|
4001
|
+
"stopRequestedAt",
|
|
4002
|
+
"closedAt",
|
|
4003
|
+
"settledAt",
|
|
4004
|
+
"timeoutMs",
|
|
4005
|
+
"stopReason"
|
|
4006
|
+
]);
|
|
4007
|
+
return {
|
|
4008
|
+
createdAt: timestamp(o.createdAt),
|
|
4009
|
+
preparedAt: nullable(o.preparedAt, timestamp),
|
|
4010
|
+
startedAt: nullable(o.startedAt, timestamp),
|
|
4011
|
+
stopRequestedAt: nullable(o.stopRequestedAt, timestamp),
|
|
4012
|
+
closedAt: nullable(o.closedAt, timestamp),
|
|
4013
|
+
settledAt: nullable(o.settledAt, timestamp),
|
|
4014
|
+
timeoutMs: integer(o.timeoutMs, 100, 1200000),
|
|
4015
|
+
stopReason: nullable(o.stopReason, (v2) => text(v2, 32, true))
|
|
4016
|
+
};
|
|
4017
|
+
}
|
|
4018
|
+
function decodeWorkflowDiagnostics(v) {
|
|
4019
|
+
const o = closed(v, ["acceptedAt", "acquiredAt", "settledAt", "owner"]);
|
|
4020
|
+
const r = closed(o.owner, [
|
|
4021
|
+
"version",
|
|
4022
|
+
"build",
|
|
4023
|
+
"entry",
|
|
4024
|
+
"pid",
|
|
4025
|
+
"node",
|
|
4026
|
+
"platform",
|
|
4027
|
+
"startedAt"
|
|
4028
|
+
]);
|
|
4029
|
+
return {
|
|
4030
|
+
acceptedAt: timestamp(o.acceptedAt),
|
|
4031
|
+
acquiredAt: nullable(o.acquiredAt, timestamp),
|
|
4032
|
+
settledAt: nullable(o.settledAt, timestamp),
|
|
4033
|
+
owner: {
|
|
4034
|
+
version: text(r.version, 128, true),
|
|
4035
|
+
build: text(r.build, 64, true),
|
|
4036
|
+
entry: text(r.entry, 4096, true),
|
|
4037
|
+
pid: integer(r.pid, 1),
|
|
4038
|
+
node: text(r.node, 128, true),
|
|
4039
|
+
platform: text(r.platform, 32, true),
|
|
4040
|
+
startedAt: timestamp(r.startedAt)
|
|
4041
|
+
}
|
|
4042
|
+
};
|
|
4043
|
+
}
|
|
3958
4044
|
|
|
3959
4045
|
// src/service/contracts/workbench.ts
|
|
3960
4046
|
function decodeCadenceConversation(v) {
|
|
@@ -10746,7 +10832,7 @@ async function createGateway(value, hostUrl, source) {
|
|
|
10746
10832
|
const input = decodeGatewayInput(value), store = new GatewayStore(input.serverConfig, input.stateHome);
|
|
10747
10833
|
const web = loadWebAssets(source?.webDirectory);
|
|
10748
10834
|
const build2 = {
|
|
10749
|
-
contractHash: "
|
|
10835
|
+
contractHash: "b855efce6a9694452dd77fcdad0b5dbecce617643cc81ac7c55dafb0f2ca7848",
|
|
10750
10836
|
assets: {
|
|
10751
10837
|
sourceHash: web.manifest.sourceHash,
|
|
10752
10838
|
contractHash: web.manifest.contractHash,
|
|
@@ -21904,7 +21990,7 @@ function conversationMessages(messages, secrets = []) {
|
|
|
21904
21990
|
if (!message || typeof message !== "object")
|
|
21905
21991
|
throw new Error("Invalid context");
|
|
21906
21992
|
const role2 = oneOf(message.role, ["user", "assistant", "toolResult"]);
|
|
21907
|
-
const
|
|
21993
|
+
const timestamp2 = integer(message.timestamp, 0);
|
|
21908
21994
|
const content = typeof message.content === "string" ? [{ type: "text", text: clean(message.content, secrets) }] : list(message.content, 256, (block) => {
|
|
21909
21995
|
if (block.type === "text")
|
|
21910
21996
|
return { type: "text", text: clean(block.text, secrets) };
|
|
@@ -21918,11 +22004,11 @@ function conversationMessages(messages, secrets = []) {
|
|
|
21918
22004
|
return null;
|
|
21919
22005
|
}).filter(Boolean);
|
|
21920
22006
|
if (role2 === "user")
|
|
21921
|
-
return { role: role2, timestamp, content };
|
|
22007
|
+
return { role: role2, timestamp: timestamp2, content };
|
|
21922
22008
|
if (role2 === "toolResult")
|
|
21923
22009
|
return {
|
|
21924
22010
|
role: role2,
|
|
21925
|
-
timestamp,
|
|
22011
|
+
timestamp: timestamp2,
|
|
21926
22012
|
content,
|
|
21927
22013
|
toolCallId: clean(message.toolCallId, secrets, 512),
|
|
21928
22014
|
toolName: clean(message.toolName, secrets, 128),
|
|
@@ -21944,7 +22030,7 @@ function conversationMessages(messages, secrets = []) {
|
|
|
21944
22030
|
]);
|
|
21945
22031
|
return {
|
|
21946
22032
|
role: role2,
|
|
21947
|
-
timestamp,
|
|
22033
|
+
timestamp: timestamp2,
|
|
21948
22034
|
content,
|
|
21949
22035
|
api: clean(message.api, secrets, 128),
|
|
21950
22036
|
provider: clean(message.provider, secrets, 128),
|
|
@@ -22603,8 +22689,18 @@ function runProcess(spec) {
|
|
|
22603
22689
|
let settled = false;
|
|
22604
22690
|
let nativeClosed = false;
|
|
22605
22691
|
let launched = false;
|
|
22692
|
+
const observeLifecycle = (event) => {
|
|
22693
|
+
if (settled)
|
|
22694
|
+
return;
|
|
22695
|
+
try {
|
|
22696
|
+
spec.onLifecycle?.(event);
|
|
22697
|
+
} catch {
|
|
22698
|
+
stop("failed");
|
|
22699
|
+
}
|
|
22700
|
+
};
|
|
22606
22701
|
child.once("spawn", () => {
|
|
22607
22702
|
launched = true;
|
|
22703
|
+
observeLifecycle({ kind: "spawned", at: Date.now() });
|
|
22608
22704
|
});
|
|
22609
22705
|
const ingressStop = new AbortController;
|
|
22610
22706
|
let stopping;
|
|
@@ -22664,7 +22760,7 @@ function runProcess(spec) {
|
|
|
22664
22760
|
exitCode,
|
|
22665
22761
|
signal,
|
|
22666
22762
|
durationMs: Date.now() - started,
|
|
22667
|
-
text: clean2(outcome === "completed" && spec.protocol ? final ?? "" : `${outcome}${closed2 ? "
|
|
22763
|
+
text: clean2(outcome === "completed" && spec.protocol ? final ?? "" : `${outcome === "timeout" ? `timeout: total process deadline ${spec.timeoutMs}ms reached (activity does not extend it)` : outcome}${closed2 ? "; direct child closed; descendant closure was not verified (not evidence of a surviving process)" : "; stop unconfirmed; coordination lock retained"}`, 16384),
|
|
22668
22764
|
output: clean2(output),
|
|
22669
22765
|
truncated
|
|
22670
22766
|
});
|
|
@@ -22694,12 +22790,18 @@ function runProcess(spec) {
|
|
|
22694
22790
|
if (settled || stopping || spec.uninterruptible)
|
|
22695
22791
|
return;
|
|
22696
22792
|
stopping = outcome;
|
|
22793
|
+
const requestedAt = Date.now();
|
|
22794
|
+
if (!nativeClosed) {
|
|
22795
|
+
signalChild("SIGTERM");
|
|
22796
|
+
killTimer = setTimeout(() => signalChild("SIGKILL"), 1000);
|
|
22797
|
+
unknownTimer = setTimeout(() => finish(false, null, null), 3000);
|
|
22798
|
+
}
|
|
22799
|
+
observeLifecycle({
|
|
22800
|
+
kind: "stop-requested",
|
|
22801
|
+
at: requestedAt,
|
|
22802
|
+
reason: outcome
|
|
22803
|
+
});
|
|
22697
22804
|
ingressStop.abort();
|
|
22698
|
-
if (nativeClosed)
|
|
22699
|
-
return;
|
|
22700
|
-
signalChild("SIGTERM");
|
|
22701
|
-
killTimer = setTimeout(() => signalChild("SIGKILL"), 1000);
|
|
22702
|
-
unknownTimer = setTimeout(() => finish(false, null, null), 3000);
|
|
22703
22805
|
};
|
|
22704
22806
|
let bridgeCalls = 0;
|
|
22705
22807
|
let bridgeBusy = false;
|
|
@@ -22896,6 +22998,8 @@ function runProcess(spec) {
|
|
|
22896
22998
|
});
|
|
22897
22999
|
child.on("close", (code2, signal) => {
|
|
22898
23000
|
nativeClosed = true;
|
|
23001
|
+
if (launched)
|
|
23002
|
+
observeLifecycle({ kind: "closed", at: Date.now() });
|
|
22899
23003
|
clearTimeout(timeout);
|
|
22900
23004
|
clearTimeout(killTimer);
|
|
22901
23005
|
clearTimeout(unknownTimer);
|
|
@@ -22952,7 +23056,7 @@ function runProcess(spec) {
|
|
|
22952
23056
|
}
|
|
22953
23057
|
class AmbientFileAuth extends Error {
|
|
22954
23058
|
}
|
|
22955
|
-
function encodeEnvelope(material, captured) {
|
|
23059
|
+
function encodeEnvelope(material, timeoutMs, captured, roots = [material.cwd]) {
|
|
22956
23060
|
const ambient = captured?.ambient ?? networkSnapshot(process.env);
|
|
22957
23061
|
const scoped = captured?.scoped ?? scopedNetwork(material);
|
|
22958
23062
|
if (Object.keys(material.auth.env ?? {}).some((name) => /(?:_FILE|_PATH|_CREDENTIALS)$/.test(name)))
|
|
@@ -22965,10 +23069,15 @@ function encodeEnvelope(material, captured) {
|
|
|
22965
23069
|
...literals(material.auth.env ?? {}),
|
|
22966
23070
|
...selected2.redactionLiterals
|
|
22967
23071
|
];
|
|
22968
|
-
const
|
|
23072
|
+
const investigation = {
|
|
23073
|
+
roots,
|
|
23074
|
+
timeoutMs,
|
|
23075
|
+
deadlineMs: Number(process.hrtime.bigint() / 1000000n) + timeoutMs
|
|
23076
|
+
};
|
|
23077
|
+
const input = JSON.stringify({ ...material, investigation });
|
|
22969
23078
|
if (!sameNetwork(scoped, scopedNetwork(JSON.parse(input)), false))
|
|
22970
23079
|
throw new Error("network");
|
|
22971
|
-
return { material, ambient, scoped, selected: selected2, secrets, input };
|
|
23080
|
+
return { material, investigation, ambient, scoped, selected: selected2, secrets, input };
|
|
22972
23081
|
}
|
|
22973
23082
|
function launchEncoded(encoded2, signal, timeoutMs, extra = {}) {
|
|
22974
23083
|
if (!sameNetwork(encoded2.ambient, networkSnapshot(process.env)) || !sameNetwork(encoded2.scoped, scopedNetwork(encoded2.material)))
|
|
@@ -22991,8 +23100,12 @@ function launchEncoded(encoded2, signal, timeoutMs, extra = {}) {
|
|
|
22991
23100
|
function launchConversation(prepared, conversation, signal, options) {
|
|
22992
23101
|
let encoded2;
|
|
22993
23102
|
return prepared.consume((material) => {
|
|
22994
|
-
encoded2 = encodeEnvelope({ ...material, model: { ...material.model } });
|
|
22995
|
-
encoded2.input = JSON.stringify({
|
|
23103
|
+
encoded2 = encodeEnvelope({ ...material, model: { ...material.model } }, options.timeoutMs);
|
|
23104
|
+
encoded2.input = JSON.stringify({
|
|
23105
|
+
...encoded2.material,
|
|
23106
|
+
investigation: encoded2.investigation,
|
|
23107
|
+
conversation
|
|
23108
|
+
});
|
|
22996
23109
|
return encoded2.input;
|
|
22997
23110
|
}, (input) => {
|
|
22998
23111
|
if (!encoded2 || encoded2.input !== input)
|
|
@@ -23025,7 +23138,7 @@ function launchWorkflowWorker(prepared, cwd, signal, options) {
|
|
|
23025
23138
|
...material,
|
|
23026
23139
|
cwd,
|
|
23027
23140
|
model: { ...material.model }
|
|
23028
|
-
});
|
|
23141
|
+
}, options.timeoutMs, undefined, options.roots ?? [cwd]);
|
|
23029
23142
|
return encoded2.input;
|
|
23030
23143
|
}, (input) => {
|
|
23031
23144
|
if (!encoded2 || encoded2.input !== input)
|
|
@@ -23034,6 +23147,7 @@ function launchWorkflowWorker(prepared, cwd, signal, options) {
|
|
|
23034
23147
|
return launchEncoded(encoded2, signal, options.timeoutMs, {
|
|
23035
23148
|
secrets,
|
|
23036
23149
|
maySignal: options.maySignal,
|
|
23150
|
+
onLifecycle: options.onLifecycle,
|
|
23037
23151
|
onNative: (native, capture) => options.onNative(native, capture?.selected?.messageId),
|
|
23038
23152
|
onFrame: (frame) => options.onFrame(frame, secrets)
|
|
23039
23153
|
});
|
|
@@ -24080,10 +24194,15 @@ BROWSER COORDINATOR: You have only cadence_research, cadence_plan and cadence_st
|
|
|
24080
24194
|
};
|
|
24081
24195
|
}
|
|
24082
24196
|
async research(current2, args, epoch, model, signal) {
|
|
24083
|
-
let goal, questions;
|
|
24197
|
+
let goal, questions, roots;
|
|
24084
24198
|
try {
|
|
24085
|
-
const a = closed(args, [
|
|
24199
|
+
const a = closed(args, [
|
|
24200
|
+
"goal",
|
|
24201
|
+
"questions",
|
|
24202
|
+
...Object.hasOwn(args ?? {}, "roots") ? ["roots"] : []
|
|
24203
|
+
]);
|
|
24086
24204
|
goal = text(a.goal, 8192, true);
|
|
24205
|
+
roots = a.roots === undefined ? undefined : list(a.roots, 8, (p) => text(p, 4096, true));
|
|
24087
24206
|
questions = list(a.questions, 2, (q) => text(q, 8192, true));
|
|
24088
24207
|
if (!questions.length)
|
|
24089
24208
|
throw new ContractError("invalid");
|
|
@@ -24101,6 +24220,7 @@ BROWSER COORDINATOR: You have only cadence_research, cadence_plan and cadence_st
|
|
|
24101
24220
|
action: "research",
|
|
24102
24221
|
goal,
|
|
24103
24222
|
questions,
|
|
24223
|
+
...roots ? { roots } : {},
|
|
24104
24224
|
model
|
|
24105
24225
|
});
|
|
24106
24226
|
} catch (error) {
|
|
@@ -24272,7 +24392,8 @@ import {
|
|
|
24272
24392
|
statfsSync as statfsSync3,
|
|
24273
24393
|
writeFileSync as writeFileSync4
|
|
24274
24394
|
} from "node:fs";
|
|
24275
|
-
import { basename as basename2, dirname as dirname19, join as join27 } from "node:path";
|
|
24395
|
+
import { basename as basename2, dirname as dirname19, join as join27, resolve as resolve10 } from "node:path";
|
|
24396
|
+
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
24276
24397
|
|
|
24277
24398
|
// src/task-diff.ts
|
|
24278
24399
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
@@ -25073,6 +25194,15 @@ class WorkflowHistoryScanner {
|
|
|
25073
25194
|
}
|
|
25074
25195
|
|
|
25075
25196
|
// src/service/workflows.ts
|
|
25197
|
+
var OWNER_RUNTIME = Object.freeze({
|
|
25198
|
+
version: "2.0.24",
|
|
25199
|
+
build: "0c1c6b8c3f8f8909dc00545075370c04090965f643c7e2d38106889d3c9a2879",
|
|
25200
|
+
entry: fileURLToPath5(import.meta.url),
|
|
25201
|
+
pid: process.pid,
|
|
25202
|
+
node: process.versions.node,
|
|
25203
|
+
platform: process.platform,
|
|
25204
|
+
startedAt: Math.round(Date.now() - process.uptime() * 1000)
|
|
25205
|
+
});
|
|
25076
25206
|
var RECORD_BYTES2 = 384 * 1024;
|
|
25077
25207
|
var MAX_STEPS = 256;
|
|
25078
25208
|
var STEP_UNITS = 80;
|
|
@@ -25615,6 +25745,8 @@ class Workflows {
|
|
|
25615
25745
|
response: { type: "grant", proposal: p, grant, expiresAt }
|
|
25616
25746
|
};
|
|
25617
25747
|
}
|
|
25748
|
+
if (r.action === "research" && r.roots?.some((p) => sanitizeText(p, secrets) !== p))
|
|
25749
|
+
throw new ContractError("forbidden");
|
|
25618
25750
|
const request3 = r.action === "research" ? {
|
|
25619
25751
|
...r,
|
|
25620
25752
|
goal: clipBytes(sanitizeText(r.goal, secrets), 8192),
|
|
@@ -25659,6 +25791,15 @@ class Workflows {
|
|
|
25659
25791
|
id: commandId,
|
|
25660
25792
|
epoch,
|
|
25661
25793
|
goal: proposal?.plan.goal ?? (request3.action === "research" ? request3.goal : ""),
|
|
25794
|
+
diagnostics: {
|
|
25795
|
+
acceptedAt: Date.now(),
|
|
25796
|
+
acquiredAt: null,
|
|
25797
|
+
settledAt: null,
|
|
25798
|
+
owner: {
|
|
25799
|
+
...OWNER_RUNTIME,
|
|
25800
|
+
entry: diagnosticText(OWNER_RUNTIME.entry, 4096, secrets)
|
|
25801
|
+
}
|
|
25802
|
+
},
|
|
25662
25803
|
status: "queued",
|
|
25663
25804
|
phase: request3.action === "research" ? "research" : "implementing",
|
|
25664
25805
|
steps: [],
|
|
@@ -25668,8 +25809,8 @@ class Workflows {
|
|
|
25668
25809
|
};
|
|
25669
25810
|
const abort = new AbortController;
|
|
25670
25811
|
let begin;
|
|
25671
|
-
const ready2 = new Promise((
|
|
25672
|
-
begin =
|
|
25812
|
+
const ready2 = new Promise((resolve11) => {
|
|
25813
|
+
begin = resolve11;
|
|
25673
25814
|
});
|
|
25674
25815
|
const live = {
|
|
25675
25816
|
run,
|
|
@@ -25735,6 +25876,18 @@ class Workflows {
|
|
|
25735
25876
|
id: `${clipUnits(id, STEP_UNITS)}-${randomUUID20()}`,
|
|
25736
25877
|
...childRunId ? { childRunId } : {},
|
|
25737
25878
|
kind,
|
|
25879
|
+
...childRunId ? {
|
|
25880
|
+
timing: {
|
|
25881
|
+
createdAt: Date.now(),
|
|
25882
|
+
preparedAt: null,
|
|
25883
|
+
startedAt: null,
|
|
25884
|
+
stopRequestedAt: null,
|
|
25885
|
+
closedAt: null,
|
|
25886
|
+
settledAt: null,
|
|
25887
|
+
timeoutMs: this.o.timeoutMs ?? LIMITS.workerMs,
|
|
25888
|
+
stopReason: null
|
|
25889
|
+
}
|
|
25890
|
+
} : {},
|
|
25738
25891
|
status: "running",
|
|
25739
25892
|
text: "",
|
|
25740
25893
|
exitCode: null,
|
|
@@ -25781,7 +25934,7 @@ class Workflows {
|
|
|
25781
25934
|
this.o.owner.quarantine();
|
|
25782
25935
|
this.save(live);
|
|
25783
25936
|
}
|
|
25784
|
-
async worker(live, cwd, id, prompt, readonly, version) {
|
|
25937
|
+
async worker(live, cwd, id, prompt, readonly, version, roots) {
|
|
25785
25938
|
this.assertRunning(live);
|
|
25786
25939
|
const model = this.model(version, true);
|
|
25787
25940
|
const role2 = loadAgentDefinitions().find((r) => r.role === (readonly ? "design-explorer" : "implementation-worker"));
|
|
@@ -25838,6 +25991,10 @@ Read applicable AGENTS.md, existing project conventions and relevant tests befor
|
|
|
25838
25991
|
const prepared = await auth.result;
|
|
25839
25992
|
if (prepared.status !== "prepared" || !current2())
|
|
25840
25993
|
throw new ContractError("auth-unavailable");
|
|
25994
|
+
if (step.timing) {
|
|
25995
|
+
step.timing.preparedAt = Date.now();
|
|
25996
|
+
this.save(live);
|
|
25997
|
+
}
|
|
25841
25998
|
this.write(this.path(live.run.id, `launches/${childRunId}.json`), {
|
|
25842
25999
|
cwd,
|
|
25843
26000
|
request: request3
|
|
@@ -25862,6 +26019,19 @@ Read applicable AGENTS.md, existing project conventions and relevant tests befor
|
|
|
25862
26019
|
const running = Promise.resolve().then(() => launchWorkflowWorker(prepared.prepared, cwd, live.abort.signal, {
|
|
25863
26020
|
timeoutMs: this.o.timeoutMs ?? LIMITS.workerMs,
|
|
25864
26021
|
ownerSecrets: this.o.secrets(),
|
|
26022
|
+
roots: roots?.length ? roots.map((p) => resolve10(cwd, p)) : [cwd],
|
|
26023
|
+
onLifecycle: (event) => {
|
|
26024
|
+
if (!step.timing)
|
|
26025
|
+
return;
|
|
26026
|
+
if (event.kind === "spawned")
|
|
26027
|
+
step.timing.startedAt = event.at;
|
|
26028
|
+
else if (event.kind === "closed")
|
|
26029
|
+
step.timing.closedAt = event.at;
|
|
26030
|
+
else {
|
|
26031
|
+
step.timing.stopRequestedAt = event.at;
|
|
26032
|
+
step.timing.stopReason = event.reason ?? null;
|
|
26033
|
+
}
|
|
26034
|
+
},
|
|
25865
26035
|
maySignal: () => {
|
|
25866
26036
|
try {
|
|
25867
26037
|
this.o.owner.lease.assert();
|
|
@@ -25876,6 +26046,16 @@ Read applicable AGENTS.md, existing project conventions and relevant tests befor
|
|
|
25876
26046
|
},
|
|
25877
26047
|
onFrame: (frame, secrets) => {
|
|
25878
26048
|
credentials = secrets;
|
|
26049
|
+
if (frame.event.kind === "ready" && frame.event.runtime) {
|
|
26050
|
+
step.runtime = {
|
|
26051
|
+
...frame.event.runtime,
|
|
26052
|
+
sdkVersion: sanitizeText(frame.event.runtime.sdkVersion, [
|
|
26053
|
+
...this.o.secrets(),
|
|
26054
|
+
...secrets
|
|
26055
|
+
])
|
|
26056
|
+
};
|
|
26057
|
+
this.save(live);
|
|
26058
|
+
}
|
|
25879
26059
|
if (recorder.accept(frame))
|
|
25880
26060
|
saveTranscript();
|
|
25881
26061
|
}
|
|
@@ -25908,6 +26088,10 @@ Read applicable AGENTS.md, existing project conventions and relevant tests befor
|
|
|
25908
26088
|
return { result: completed, step };
|
|
25909
26089
|
} finally {
|
|
25910
26090
|
await auth.settled;
|
|
26091
|
+
if (step.timing) {
|
|
26092
|
+
step.timing.settledAt = Date.now();
|
|
26093
|
+
this.save(live);
|
|
26094
|
+
}
|
|
25911
26095
|
this.closeStep(live, step, "Worker did not produce a completed native/recorded result.");
|
|
25912
26096
|
}
|
|
25913
26097
|
}
|
|
@@ -26416,6 +26600,8 @@ Write only these exact files: ${task.writes.join(", ")} (a declared directory in
|
|
|
26416
26600
|
this.assertRunning(live);
|
|
26417
26601
|
barrier = await this.o.gate.acquire(live.run.id, live.abort.signal);
|
|
26418
26602
|
barrier.assertHeld();
|
|
26603
|
+
if (live.run.diagnostics)
|
|
26604
|
+
live.run.diagnostics.acquiredAt = Date.now();
|
|
26419
26605
|
timer = setTimeout(() => {
|
|
26420
26606
|
budgetExpired = true;
|
|
26421
26607
|
live.abort.abort();
|
|
@@ -26427,7 +26613,7 @@ Write only these exact files: ${task.writes.join(", ")} (a declared directory in
|
|
|
26427
26613
|
if (request3.action === "research") {
|
|
26428
26614
|
const answers = await Promise.allSettled(request3.questions.map((q, i) => this.worker(live, this.cwd, `research-${i + 1}`, `Goal: ${request3.goal}
|
|
26429
26615
|
Investigation: ${q}
|
|
26430
|
-
Read only. Cite paths and distinguish evidence, assumptions, user decisions and environment prerequisites.`, true, request3.model)));
|
|
26616
|
+
Read only. Cite paths and distinguish evidence, assumptions, user decisions and environment prerequisites.`, true, request3.model, request3.roots)));
|
|
26431
26617
|
for (const a of answers) {
|
|
26432
26618
|
if (a.status === "rejected")
|
|
26433
26619
|
throw a.reason;
|
|
@@ -26444,6 +26630,8 @@ Read only. Cite paths and distinguish evidence, assumptions, user decisions and
|
|
|
26444
26630
|
} finally {
|
|
26445
26631
|
clearTimeout(timer);
|
|
26446
26632
|
live.run.phase = "finished";
|
|
26633
|
+
if (live.run.diagnostics)
|
|
26634
|
+
live.run.diagnostics.settledAt = Date.now();
|
|
26447
26635
|
const delivered = [...live.delivered].sort();
|
|
26448
26636
|
live.run.notice = this.notice(failure2, delivered.length ? `${live.run.status === "completed" ? "Changed files" : "Changed files so far"}: ${delivered.join(", ")}` : "", ...live.notes);
|
|
26449
26637
|
try {
|
|
@@ -26727,7 +26915,7 @@ function refuseAt(stage, step) {
|
|
|
26727
26915
|
}
|
|
26728
26916
|
}
|
|
26729
26917
|
async function createServiceHost(value, sourceBuild) {
|
|
26730
|
-
const embedded = "
|
|
26918
|
+
const embedded = "b855efce6a9694452dd77fcdad0b5dbecce617643cc81ac7c55dafb0f2ca7848";
|
|
26731
26919
|
if (embedded && sourceBuild)
|
|
26732
26920
|
throw new ContractError("unsupported-context");
|
|
26733
26921
|
const contractHash = decodeHash(embedded ?? sourceBuild?.contractHash);
|
package/src/worker-public.mjs
CHANGED
|
@@ -1203,10 +1203,25 @@ export function decodeCaptureEvent(v) {
|
|
|
1203
1203
|
const kind = tag(v);
|
|
1204
1204
|
switch (kind) {
|
|
1205
1205
|
case "ready": {
|
|
1206
|
-
const o = closed(v, [
|
|
1206
|
+
const o = closed(v, [
|
|
1207
|
+
"kind",
|
|
1208
|
+
"requestProtocol",
|
|
1209
|
+
...(Object.hasOwn(v ?? {}, "runtime") ? ["runtime"] : []),
|
|
1210
|
+
]);
|
|
1207
1211
|
return {
|
|
1208
1212
|
kind,
|
|
1209
1213
|
requestProtocol: literal(o.requestProtocol, WORKER_PROTOCOL),
|
|
1214
|
+
...(o.runtime === undefined
|
|
1215
|
+
? {}
|
|
1216
|
+
: {
|
|
1217
|
+
runtime: (() => {
|
|
1218
|
+
const r = closed(o.runtime, ["sdkVersion", "workerHash"]);
|
|
1219
|
+
return {
|
|
1220
|
+
sdkVersion: text(r.sdkVersion, 128, true),
|
|
1221
|
+
workerHash: decodeHash(r.workerHash),
|
|
1222
|
+
};
|
|
1223
|
+
})(),
|
|
1224
|
+
}),
|
|
1210
1225
|
};
|
|
1211
1226
|
}
|
|
1212
1227
|
case "message-start": {
|