@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.
@@ -113,3 +113,22 @@ Losing a response only observes its original command/run identity; it never retr
113
113
  Exit does not stop accepted work, and **Cancel workflow — request stop** remains independent of conversation mode.
114
114
  There is no generic browser shell/PTY, service management/recovery or checkpoint pause/resume feature.
115
115
  Conversation response completion is distinct from workflow completion; read the workflow card for actual delivery/check outcomes.
116
+
117
+ ### Research scope, timing and retained results
118
+
119
+ Each research call accepts one or two questions and optional specific `roots` (default: the selected project directory).
120
+ Provide the actual investigation directory, especially for large mounted/backup trees; do not begin by enumerating `/` or broad parent directories.
121
+ Research tools are readonly and bounded.
122
+ Search limits and omitted coverage are reported explicitly; a partial search does not prove that no other matching file exists.
123
+ The bounded `grep` tool searches literal text, not regular expressions.
124
+ No files are copied to accelerate research.
125
+
126
+ Separate runs in one project wait for the shared checkout gate; questions inside a run can overlap.
127
+ The worker's total process deadline includes model and tool time, is not an inactivity timer, and is not renewed by progress.
128
+ A timeout that confirms direct-child close does not prove all descendants stopped, nor does it prove any survived.
129
+
130
+ Research replies include `runId` and step identities.
131
+ Ask for `cadence_status` with the exact `runId`, `stepId`, and optionally `transcript: true` to inspect an earlier result after another run.
132
+ Selecting a retained run is readonly and does not replace the current run or restart work.
133
+ Native status/history and the browser's **Owner timing and runtime** details show the actual owner build/epoch and recorded queue/worker timestamps; the worker SDK version can differ from the terminal Pi host.
134
+ A parent session may record a whole batch of tool results together, so those timestamps are not the service's completion times.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abelxiaoxing/cadence",
3
- "version": "2.0.23",
3
+ "version": "2.0.24",
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",
@@ -53,6 +53,7 @@
53
53
  "src/worker-public.mjs",
54
54
  "src/worker-redaction.mjs",
55
55
  "src/worker-tools.mjs",
56
+ "src/research-tools.mjs",
56
57
  "web/dist",
57
58
  "docs",
58
59
  "README.md",
@@ -30,11 +30,13 @@ import {
30
30
  type WorkflowRequest,
31
31
  type WorkflowResponse,
32
32
  type WorkflowRun,
33
+ workflowDiagnostics,
33
34
  } from "./service/contracts/workflow.ts";
34
35
  import { ServiceCoordination } from "./service/coordination.ts";
35
36
  import {
36
37
  ContractError,
37
38
  canonicalJson,
39
+ decodeId,
38
40
  decodeModelSelector,
39
41
  type ErrorCode,
40
42
  type ModelSelector,
@@ -280,6 +282,34 @@ export function registerCadenceMode(pi: ExtensionAPI): void {
280
282
  let state = idle(),
281
283
  context: ExtensionContext | undefined,
282
284
  generation = 0;
285
+ // One native conversation has one current run/proposal. Claim synchronously,
286
+ // before any attachment/model await; status and explicit Cancel remain usable.
287
+ type Mutation = { generation: number; assertCurrent(): void };
288
+ let mutation: Mutation | undefined;
289
+ const changing = async <T>(
290
+ ctx: ExtensionContext,
291
+ body: (claim: Mutation) => Promise<T>,
292
+ ) => {
293
+ active(ctx);
294
+ if (mutation?.generation === generation)
295
+ throw new Error(
296
+ "A Cadence request is already in progress. Use cadence_status; no additional work was sent.",
297
+ );
298
+ const claim: Mutation = {
299
+ generation,
300
+ assertCurrent() {
301
+ if (claim.generation !== generation || mutation !== claim)
302
+ throw new ContractError("stale");
303
+ active(ctx);
304
+ },
305
+ };
306
+ mutation = claim;
307
+ try {
308
+ return await body(claim);
309
+ } finally {
310
+ if (mutation === claim) mutation = undefined;
311
+ }
312
+ };
283
313
  let permission: { id: string; digest: string; at: number } | undefined;
284
314
  let allowStart = false,
285
315
  reattach = false;
@@ -353,7 +383,7 @@ export function registerCadenceMode(pi: ExtensionAPI): void {
353
383
  context = ctx;
354
384
  };
355
385
  const summarize = (run: WorkflowRun) =>
356
- `Cadence ${run.status} • ${run.goal}\n${run.steps.map((s) => `${s.kind} ${s.id}: ${s.status}${s.exitCode === null ? "" : ` (exit ${s.exitCode})`}\n${s.text}${s.truncated ? "\n[Preview truncated; full result retained by owner.]" : ""}`).join("\n")}\n${run.notice}${run.mergedCommit ? `\nLocal merge: ${run.mergedCommit}` : ""}${run.status === "unknown" ? "\nOutcome unknown: neither completed nor failed. Its actual effects are not inferred, and the owner keeps any fences." : ""}\nAutomatic review is not human review. Cadence mode remains enabled.`;
386
+ `Cadence ${run.status} • ${run.goal}\nRun: ${run.id}\n${workflowDiagnostics(run)}\n${run.steps.map((s) => `${s.kind} ${s.id}: ${s.status}${s.exitCode === null ? "" : ` (exit ${s.exitCode})`}\n${s.text}${s.truncated ? "\n[Preview truncated; full result retained by owner.]" : ""}`).join("\n")}\n${run.notice}${run.mergedCommit ? `\nLocal merge: ${run.mergedCommit}` : ""}${run.status === "unknown" ? "\nOutcome unknown: neither completed nor failed. Its actual effects are not inferred, and the owner keeps any fences." : ""}\nAutomatic review is not human review. Cadence mode remains enabled.`;
357
387
  const agentDir = () => getAgentDir();
358
388
  const launchOwner = async (ctx: ExtensionContext) => {
359
389
  if (process.env.CADENCE_AUTOSTART === "0")
@@ -501,8 +531,10 @@ export function registerCadenceMode(pi: ExtensionAPI): void {
501
531
  });
502
532
  };
503
533
  const connect = async (ctx: ExtensionContext, selectModel = true) => {
534
+ const expected = generation;
504
535
  active(ctx);
505
536
  await ensureAttached(ctx);
537
+ if (generation !== expected) throw new ContractError("stale");
506
538
  if (!connection.client || !connection.compatible()) {
507
539
  reattach = true;
508
540
  let stop = "its explicit stop command";
@@ -516,13 +548,17 @@ export function registerCadenceMode(pi: ExtensionAPI): void {
516
548
  );
517
549
  }
518
550
  if (selectModel) await ensureModel(ctx);
551
+ if (generation !== expected) throw new ContractError("stale");
519
552
  };
520
553
  const request = async (
521
554
  ctx: ExtensionContext,
522
555
  input: WorkflowRequest,
523
556
  commandId = randomUUID(),
524
557
  sending?: () => void,
558
+ claim?: Mutation,
525
559
  ): Promise<WorkflowResponse> => {
560
+ claim?.assertCurrent();
561
+ const expected = generation;
526
562
  await connect(
527
563
  ctx,
528
564
  input.action === "research" || input.action === "propose",
@@ -535,9 +571,14 @@ export function registerCadenceMode(pi: ExtensionAPI): void {
535
571
  epoch: connection.session.epoch,
536
572
  request: input,
537
573
  };
574
+ if (expected !== generation) throw new ContractError("stale");
575
+ claim?.assertCurrent();
576
+ active(ctx);
538
577
  // Everything before this point had no owner effect.
539
578
  sending?.();
540
579
  const r = value(await connection.client.workbenchCommand(command));
580
+ if (generation !== expected) throw new ContractError("stale");
581
+ claim?.assertCurrent();
541
582
  if (r.kind !== "workflow") throw new ContractError("invalid");
542
583
  const response = r.response;
543
584
  if (
@@ -590,10 +631,13 @@ export function registerCadenceMode(pi: ExtensionAPI): void {
590
631
  return `Attempted run ${id} is not known to the owner and is not active, so it was never accepted. Cadence forgot it; nothing was replayed.\n`;
591
632
  };
592
633
  /** Returns a notice when an attempted run was proven absent and forgotten. */
593
- const requireSettledRun = async (ctx: ExtensionContext) => {
594
- if (!state.runId) return "";
595
- const seen = await observe(ctx, state.runId);
596
- if ("absent" in seen) return forget(state.runId);
634
+ const requireSettledRun = async (ctx: ExtensionContext, claim: Mutation) => {
635
+ claim.assertCurrent();
636
+ const id = state.runId;
637
+ if (!id) return "";
638
+ const seen = await observe(ctx, id);
639
+ claim.assertCurrent();
640
+ if ("absent" in seen) return forget(id);
597
641
  const previous = seen.run;
598
642
  if (["running", "queued"].includes(previous.status))
599
643
  throw new Error(
@@ -905,53 +949,88 @@ export function registerCadenceMode(pi: ExtensionAPI): void {
905
949
  parameters: Type.Object({
906
950
  goal: Type.String(),
907
951
  questions: Type.Array(Type.String(), { minItems: 1, maxItems: 2 }),
952
+ roots: Type.Optional(
953
+ Type.Array(
954
+ Type.String({
955
+ description:
956
+ "Specific investigation directories; defaults to project cwd. Avoid filesystem roots and broad parent trees.",
957
+ }),
958
+ { minItems: 1, maxItems: 8 },
959
+ ),
960
+ ),
908
961
  }),
909
962
  async execute(_id, input, signal, update, ctx) {
910
- active(ctx);
911
- await connect(ctx);
912
- const notice = await requireSettledRun(ctx);
913
- const model = value(await client().models()).version;
914
- const commandId = randomUUID(),
915
- before = state.runId;
916
- let sent = false,
917
- response: WorkflowResponse;
918
- try {
919
- response = await request(
920
- ctx,
921
- { action: "research", ...input, model },
922
- commandId,
923
- () => {
924
- // Retain the attempted identity before transport: a lost reply is
925
- // observed, never replaced with another research request.
926
- state.runId = commandId;
963
+ return changing(ctx, async (claim) => {
964
+ active(ctx);
965
+ await connect(ctx);
966
+ claim.assertCurrent();
967
+ const notice = await requireSettledRun(ctx, claim);
968
+ const model = value(await client().models()).version;
969
+ const commandId = randomUUID(),
970
+ before = state.runId;
971
+ let sent = false,
972
+ response: WorkflowResponse;
973
+ try {
974
+ response = await request(
975
+ ctx,
976
+ { action: "research", ...input, model },
977
+ commandId,
978
+ () => {
979
+ // Retain the attempted identity before transport: a lost reply is
980
+ // observed, never replaced with another research request.
981
+ state.runId = commandId;
982
+ persist();
983
+ sent = true;
984
+ },
985
+ claim,
986
+ );
987
+ } catch (error) {
988
+ if (
989
+ generation === claim.generation &&
990
+ (!sent || definite(error)) &&
991
+ state.runId === commandId
992
+ ) {
993
+ state.runId = before;
927
994
  persist();
928
- sent = true;
929
- },
930
- );
931
- } catch (error) {
932
- if ((!sent || definite(error)) && state.runId === commandId) {
933
- state.runId = before;
934
- persist();
995
+ }
996
+ throw error;
935
997
  }
936
- throw error;
937
- }
938
- if (response.type !== "run") throw new ContractError("invalid");
939
- status("research");
940
- let run = response.run;
941
- while (["queued", "running"].includes(run.status) && !signal?.aborted) {
942
- update?.(
943
- result(
944
- `Investigating: ${run.goal}\n${run.steps.map((s) => `${s.kind} ${s.id}: ${s.status}`).join("\n")}\nSubagents are listed in Pi's agent panel.`,
945
- ),
946
- );
947
- await new Promise((resolve) => setTimeout(resolve, 1000));
948
- const seen = await observe(ctx, run.id);
949
- if ("absent" in seen) throw new ContractError("unavailable");
950
- run = seen.run;
951
- }
952
- status("ready");
953
- if (signal?.aborted) watch(ctx, run.id);
954
- return result(`${notice}${summarize(run)}`);
998
+ if (response.type !== "run") throw new ContractError("invalid");
999
+ status("research");
1000
+ const expected = generation;
1001
+ let run = response.run;
1002
+ while (
1003
+ ["queued", "running"].includes(run.status) &&
1004
+ !signal?.aborted &&
1005
+ generation === expected
1006
+ ) {
1007
+ update?.(
1008
+ result(
1009
+ `Investigating: ${run.goal}\n${run.steps.map((s) => `${s.kind} ${s.id}: ${s.status}`).join("\n")}\nSubagents are listed in Pi's agent panel.`,
1010
+ ),
1011
+ );
1012
+ await new Promise((resolve) => setTimeout(resolve, 1000));
1013
+ if (generation !== expected) break;
1014
+ const seen = await observe(ctx, run.id);
1015
+ if (generation !== expected) break;
1016
+ if ("absent" in seen) throw new ContractError("unavailable");
1017
+ run = seen.run;
1018
+ }
1019
+ if (generation === expected) {
1020
+ status("ready");
1021
+ if (signal?.aborted) watch(ctx, run.id);
1022
+ }
1023
+ return {
1024
+ ...result(`${notice}${summarize(run)}`),
1025
+ details: {
1026
+ runId: run.id,
1027
+ steps: run.steps.map(({ id, childRunId }) => ({
1028
+ stepId: id,
1029
+ childRunId,
1030
+ })),
1031
+ },
1032
+ };
1033
+ });
955
1034
  },
956
1035
  });
957
1036
  pi.registerTool({
@@ -961,38 +1040,47 @@ export function registerCadenceMode(pi: ExtensionAPI): void {
961
1040
  "After interactive clarification, publish the exact readable plan, dependency graph, checks, setup commands, repair budget and delivery policy for user approval. Does not execute.",
962
1041
  parameters: PLAN,
963
1042
  async execute(_id, input, _signal, _update, ctx) {
964
- active(ctx);
965
- await connect(ctx);
966
- permission = undefined;
967
- const notice = await requireSettledRun(ctx);
968
- const plan = decodeWorkflowPlan(input);
969
- const response = await request(ctx, {
970
- action: "propose",
971
- plan,
972
- model: value(await client().models()).version,
973
- });
974
- if (response.type !== "proposal") throw new ContractError("invalid");
975
- state.proposal = response.proposal;
976
- persist();
977
- status("awaiting plan approval");
978
- const shown = readableWorkflowPlan(response.proposal.plan);
979
- const redacted =
980
- canonicalJson(response.proposal.plan) !== canonicalJson(plan);
981
- // The plan is displayed by this tool's own result: a message sent now
982
- // would land between this tool call and its result.
983
- return {
984
- content: [
1043
+ return changing(ctx, async (claim) => {
1044
+ active(ctx);
1045
+ await connect(ctx);
1046
+ claim.assertCurrent();
1047
+ permission = undefined;
1048
+ const notice = await requireSettledRun(ctx, claim);
1049
+ const plan = decodeWorkflowPlan(input);
1050
+ const response = await request(
1051
+ ctx,
985
1052
  {
986
- type: "text" as const,
987
- text: `${notice}${shown}\nPlan identity: ${response.proposal.digest}\n${redacted ? "The owner redacted credential-like text; the plan above is exactly what would run.\n" : ""}The user sees this complete plan. They can type 按计划实施 to approve these exact bytes; vague agreement is not execution consent. Existing unrelated working-copy changes are not imported into isolated candidates.`,
1053
+ action: "propose",
1054
+ plan,
1055
+ model: value(await client().models()).version,
988
1056
  },
989
- ],
990
- details: {
991
- plan: shown,
992
- digest: response.proposal.digest,
993
- redacted,
994
- },
995
- };
1057
+ undefined,
1058
+ undefined,
1059
+ claim,
1060
+ );
1061
+ if (response.type !== "proposal") throw new ContractError("invalid");
1062
+ state.proposal = response.proposal;
1063
+ persist();
1064
+ status("awaiting plan approval");
1065
+ const shown = readableWorkflowPlan(response.proposal.plan);
1066
+ const redacted =
1067
+ canonicalJson(response.proposal.plan) !== canonicalJson(plan);
1068
+ // The plan is displayed by this tool's own result: a message sent now
1069
+ // would land between this tool call and its result.
1070
+ return {
1071
+ content: [
1072
+ {
1073
+ type: "text" as const,
1074
+ text: `${notice}${shown}\nPlan identity: ${response.proposal.digest}\n${redacted ? "The owner redacted credential-like text; the plan above is exactly what would run.\n" : ""}The user sees this complete plan. They can type 按计划实施 to approve these exact bytes; vague agreement is not execution consent. Existing unrelated working-copy changes are not imported into isolated candidates.`,
1075
+ },
1076
+ ],
1077
+ details: {
1078
+ plan: shown,
1079
+ digest: response.proposal.digest,
1080
+ redacted,
1081
+ },
1082
+ };
1083
+ });
996
1084
  },
997
1085
  renderResult(output) {
998
1086
  const d = output.details as
@@ -1021,110 +1109,133 @@ export function registerCadenceMode(pi: ExtensionAPI): void {
1021
1109
  "Start the current exact plan after fresh user approval. The service automatically implements, reviews, verifies, performs bounded repairs and delivers; client departure only detaches.",
1022
1110
  parameters: Type.Object({}),
1023
1111
  async execute(_id, _input, signal, _update, ctx) {
1024
- active(ctx);
1025
- const proposal = state.proposal;
1026
- if (!proposal)
1027
- throw new Error("No current plan. Clarify and propose it first.");
1028
- const expected = generation;
1029
- const fromInput =
1030
- permission?.id === proposal.id &&
1031
- permission.digest === proposal.digest &&
1032
- Date.now() >= permission.at &&
1033
- Date.now() - permission.at < 120000;
1034
- permission = undefined;
1035
- if (
1036
- !fromInput &&
1037
- !(await confirm(
1038
- ctx,
1039
- "Implement this plan automatically?",
1040
- `${readableWorkflowPlan(proposal.plan)}\nProject: ${proposal.cwd}\nNo push or deployment. Keeping the discussion changes nothing.`,
1041
- "Keep discussing (do not start)",
1042
- "Start this exact plan",
1043
- ))
1044
- )
1045
- return result(
1046
- "Not started. Cadence remains enabled for further discussion.",
1047
- );
1048
- if (
1049
- signal?.aborted ||
1050
- expected !== generation ||
1051
- state.proposal?.digest !== proposal.digest
1052
- )
1053
- throw new ContractError("stale");
1054
- // The grant is fresh after consent, so reading the plan never expires it.
1055
- const prepared = await request(ctx, {
1056
- action: "prepare",
1057
- proposalId: proposal.id,
1058
- digest: proposal.digest,
1059
- });
1060
- if (
1061
- prepared.type !== "grant" ||
1062
- canonicalJson(prepared.proposal.plan) !==
1063
- canonicalJson(proposal.plan) ||
1064
- prepared.proposal.cwd !== proposal.cwd
1065
- )
1066
- throw new ContractError("stale");
1067
- const commandId = randomUUID(),
1068
- before = { runId: state.runId, proposal };
1069
- let sent = false,
1070
- started: WorkflowResponse;
1071
- try {
1072
- started = await request(
1112
+ return changing(ctx, async (claim) => {
1113
+ active(ctx);
1114
+ const proposal = state.proposal;
1115
+ if (!proposal)
1116
+ throw new Error("No current plan. Clarify and propose it first.");
1117
+ const expected = generation;
1118
+ const fromInput =
1119
+ permission?.id === proposal.id &&
1120
+ permission.digest === proposal.digest &&
1121
+ Date.now() >= permission.at &&
1122
+ Date.now() - permission.at < 120000;
1123
+ permission = undefined;
1124
+ if (
1125
+ !fromInput &&
1126
+ !(await confirm(
1127
+ ctx,
1128
+ "Implement this plan automatically?",
1129
+ `${readableWorkflowPlan(proposal.plan)}\nProject: ${proposal.cwd}\nNo push or deployment. Keeping the discussion changes nothing.`,
1130
+ "Keep discussing (do not start)",
1131
+ "Start this exact plan",
1132
+ ))
1133
+ )
1134
+ return result(
1135
+ "Not started. Cadence remains enabled for further discussion.",
1136
+ );
1137
+ if (
1138
+ signal?.aborted ||
1139
+ expected !== generation ||
1140
+ state.proposal?.digest !== proposal.digest
1141
+ )
1142
+ throw new ContractError("stale");
1143
+ // The grant is fresh after consent, so reading the plan never expires it.
1144
+ const prepared = await request(
1073
1145
  ctx,
1074
1146
  {
1075
- action: "execute",
1147
+ action: "prepare",
1076
1148
  proposalId: proposal.id,
1077
1149
  digest: proposal.digest,
1078
- grant: prepared.grant,
1079
- },
1080
- commandId,
1081
- () => {
1082
- // Retain the exact attempted identity before transport; a lost
1083
- // reply is observed, never replaced with another Start or a
1084
- // revived approval.
1085
- state.runId = commandId;
1086
- state.proposal = null;
1087
- persist();
1088
- sent = true;
1089
1150
  },
1151
+ undefined,
1152
+ undefined,
1153
+ claim,
1090
1154
  );
1091
- } catch (error) {
1092
- // A proven refusal had no effect: keep the plan for a fresh approval.
1093
- if ((!sent || definite(error)) && state.runId === commandId) {
1094
- state.runId = before.runId;
1095
- state.proposal = before.proposal;
1096
- persist();
1155
+ if (
1156
+ prepared.type !== "grant" ||
1157
+ canonicalJson(prepared.proposal.plan) !==
1158
+ canonicalJson(proposal.plan) ||
1159
+ prepared.proposal.cwd !== proposal.cwd
1160
+ )
1161
+ throw new ContractError("stale");
1162
+ const commandId = randomUUID(),
1163
+ before = { runId: state.runId, proposal };
1164
+ let sent = false,
1165
+ started: WorkflowResponse;
1166
+ try {
1167
+ started = await request(
1168
+ ctx,
1169
+ {
1170
+ action: "execute",
1171
+ proposalId: proposal.id,
1172
+ digest: proposal.digest,
1173
+ grant: prepared.grant,
1174
+ },
1175
+ commandId,
1176
+ () => {
1177
+ // Retain the exact attempted identity before transport; a lost
1178
+ // reply is observed, never replaced with another Start or a
1179
+ // revived approval.
1180
+ state.runId = commandId;
1181
+ state.proposal = null;
1182
+ persist();
1183
+ sent = true;
1184
+ },
1185
+ claim,
1186
+ );
1187
+ } catch (error) {
1188
+ // A proven refusal had no effect: keep the plan for a fresh approval.
1189
+ if (
1190
+ generation === claim.generation &&
1191
+ (!sent || definite(error)) &&
1192
+ state.runId === commandId
1193
+ ) {
1194
+ state.runId = before.runId;
1195
+ state.proposal = before.proposal;
1196
+ persist();
1197
+ }
1198
+ throw error;
1097
1199
  }
1098
- throw error;
1099
- }
1100
- if (started.type !== "run") throw new ContractError("invalid");
1101
- state.runId = started.run.id;
1102
- state.proposal = null;
1103
- persist();
1104
- status("executing");
1105
- watch(ctx, started.run.id);
1106
- return result(
1107
- `Accepted. Implementation, verification and agreed delivery now run under the persistent owner. No further routine approval is needed. ${started.run.id}\nCadence remains enabled. Closing/switching the conversation does not cancel this work.`,
1108
- );
1200
+ if (started.type !== "run") throw new ContractError("invalid");
1201
+ state.runId = started.run.id;
1202
+ state.proposal = null;
1203
+ persist();
1204
+ status("executing");
1205
+ watch(ctx, started.run.id);
1206
+ return result(
1207
+ `Accepted. Implementation, verification and agreed delivery now run under the persistent owner. No further routine approval is needed. ${started.run.id}\nCadence remains enabled. Closing/switching the conversation does not cancel this work.`,
1208
+ );
1209
+ });
1109
1210
  },
1110
1211
  });
1111
1212
  pi.registerTool({
1112
1213
  name: "cadence_status",
1113
1214
  label: "Observe workflow",
1114
1215
  description:
1115
- "Read the current retained workflow outcome without replaying any action. With stepId, read that step's retained result, or its subagent transcript with transcript: true.",
1216
+ "Read a retained workflow without replaying any action. Specify runId for earlier runs; otherwise selects the current run. With stepId read its result, or transcript: true for its transcript.",
1116
1217
  parameters: Type.Object({
1218
+ runId: Type.Optional(Type.String()),
1117
1219
  stepId: Type.Optional(Type.String()),
1118
1220
  transcript: Type.Optional(Type.Boolean()),
1119
1221
  }),
1120
1222
  async execute(_id, input, _signal, _update, ctx) {
1121
1223
  active(ctx);
1122
- if (!state.runId)
1224
+ const id =
1225
+ input.runId === undefined ? state.runId : decodeId(input.runId);
1226
+ if (!id)
1123
1227
  return result(
1124
1228
  "Cadence is enabled; no run yet. Continue clarifying the goal.",
1125
1229
  );
1126
- const id = state.runId;
1127
1230
  if (input.stepId) {
1231
+ const seen = await observe(ctx, id);
1232
+ if (
1233
+ "absent" in seen ||
1234
+ !seen.run.steps.some((s) => s.id === input.stepId)
1235
+ )
1236
+ throw new Error(
1237
+ `Step ${input.stepId} does not belong to selected run ${id}. Supply the exact runId and stepId from the research result; no other run was searched.`,
1238
+ );
1128
1239
  await connect(ctx, false);
1129
1240
  if (input.transcript) {
1130
1241
  const t = value(
@@ -1158,14 +1269,20 @@ export function registerCadenceMode(pi: ExtensionAPI): void {
1158
1269
  }
1159
1270
  const seen = await observe(ctx, id);
1160
1271
  if ("absent" in seen) {
1272
+ if (id !== state.runId)
1273
+ return result(
1274
+ `Run ${id} is not known to this owner. Current selection was not changed.`,
1275
+ );
1161
1276
  status("ready");
1162
1277
  return result(`${forget(id)}Continue normally.`);
1163
1278
  }
1164
1279
  const run = seen.run;
1165
- if (["running", "queued"].includes(run.status)) watch(ctx, run.id);
1166
- if (run.status === "unknown") acknowledgedUnknown = run.id;
1280
+ if (id === state.runId && ["running", "queued"].includes(run.status))
1281
+ watch(ctx, run.id);
1282
+ if (id === state.runId && run.status === "unknown")
1283
+ acknowledgedUnknown = run.id;
1167
1284
  return result(
1168
- `${summarize(run)}${run.status === "unknown" ? "\nThis explicit observation is recorded: research or a new plan may now continue. A new plan observes the current files; nothing about this run is assumed." : ""}`,
1285
+ `${summarize(run)}${run.status === "unknown" && id === state.runId ? "\nThis explicit observation is recorded: research or a new plan may now continue. A new plan observes the current files; nothing about this run is assumed." : ""}`,
1169
1286
  );
1170
1287
  },
1171
1288
  });
@@ -1177,18 +1294,19 @@ export function registerCadenceMode(pi: ExtensionAPI): void {
1177
1294
  parameters: Type.Object({}),
1178
1295
  async execute(_id, _input, _signal, _update, ctx) {
1179
1296
  active(ctx);
1180
- if (!state.runId) return result("No active workflow.");
1297
+ const runId = state.runId;
1298
+ if (!runId) return result("No active workflow.");
1181
1299
  if (
1182
1300
  !(await confirm(
1183
1301
  ctx,
1184
1302
  "Cancel current workflow?",
1185
- "Request Stop and retain actual files/results. This does not reset or undo edits. Cadence mode remains enabled.",
1303
+ `Request Stop for ${runId} and retain actual files/results. This does not reset or undo edits. Cadence mode remains enabled.`,
1186
1304
  "Keep running",
1187
1305
  "Request cancellation",
1188
1306
  ))
1189
1307
  )
1190
1308
  return result("Cancellation not requested.");
1191
- const r = await request(ctx, { action: "cancel", runId: state.runId });
1309
+ const r = await request(ctx, { action: "cancel", runId });
1192
1310
  if (r.type !== "run") throw new ContractError("invalid");
1193
1311
  watch(ctx, r.run.id);
1194
1312
  return result(
@@ -67,6 +67,15 @@ export function coordinatorTools() {
67
67
  parameters: Type.Object({
68
68
  goal: Type.String(),
69
69
  questions: Type.Array(Type.String(), { minItems: 1, maxItems: 2 }),
70
+ roots: Type.Optional(
71
+ Type.Array(
72
+ Type.String({
73
+ description:
74
+ "Specific investigation directories; defaults to project cwd. Avoid filesystem roots and broad parent trees.",
75
+ }),
76
+ { minItems: 1, maxItems: 8 },
77
+ ),
78
+ ),
70
79
  }),
71
80
  },
72
81
  {
@@ -2,5 +2,5 @@
2
2
  export const nativeBuild = {
3
3
  kind: "native",
4
4
  contractHash:
5
- "f0ff0c9d0481dab9fd21cdbc7c0d72b427bee60033a9af4c789f859c4c83fe75",
5
+ "b855efce6a9694452dd77fcdad0b5dbecce617643cc81ac7c55dafb0f2ca7848",
6
6
  } as const;