openwork-server 0.18.66 → 0.18.67

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 (81) hide show
  1. package/dist/opencode-plugin-deps-1.18.33.tgz +0 -0
  2. package/dist/opencode-plugins/managed-policy-next.js +11 -0
  3. package/dist/opencode-plugins/openwork-agent-permissions-v2.js +17 -2
  4. package/dist/opencode-plugins/openwork-agent-questions.js +2 -9
  5. package/dist/opencode-plugins/openwork-auto-route-v2.js +1 -0
  6. package/dist/opencode-plugins/openwork-capabilities-knowledge.js +2 -2
  7. package/dist/opencode-plugins/openwork-computer-use.js +4 -14
  8. package/dist/opencode-plugins/openwork-context-v2.js +11 -63
  9. package/dist/opencode-plugins/openwork-extensions-preview.js +65 -13
  10. package/dist/opencode-plugins/openwork-provider-adapters.js +1 -0
  11. package/dist/opencode-plugins/openwork-provider-sync-v2.js +136 -19
  12. package/dist/openwork-server.mjs +3884 -6606
  13. package/package.json +1 -1
  14. package/web/assets/{abnfDiagram-VCTEODGH-Btnc8K5J.js → abnfDiagram-VCTEODGH-D3rS6DjN.js} +1 -1
  15. package/web/assets/app-BUb4-37_.css +32 -0
  16. package/web/assets/{app-ncfqDSg8.js → app-DnDiUeJ_.js} +490 -462
  17. package/web/assets/{arc-D7Fla6cB.js → arc-1nwR3BuI.js} +1 -1
  18. package/web/assets/{architectureDiagram-5GKGNRK7-CYw8_dHQ.js → architectureDiagram-5GKGNRK7-CGr_AnX8.js} +1 -1
  19. package/web/assets/{artifact-code-view-K_Wjfta2.js → artifact-code-view-op4noM_j.js} +1 -1
  20. package/web/assets/{artifact-spreadsheet-editor-B4DQaEb8.js → artifact-spreadsheet-editor-OOE-8BBB.js} +1 -1
  21. package/web/assets/{artifact-text-editor-DR-26kOP.js → artifact-text-editor-CvG4fImt.js} +1 -1
  22. package/web/assets/{blockDiagram-OSKFZWR5-CRvrZcXA.js → blockDiagram-OSKFZWR5-DcGHjZxr.js} +1 -1
  23. package/web/assets/{c4Diagram-7LVT6UL2-D7W-zIO4.js → c4Diagram-7LVT6UL2-o2lny2Rm.js} +1 -1
  24. package/web/assets/channel-Bw8HKEF7.js +1 -0
  25. package/web/assets/{chunk-2Q5K7J3B-CYj0ZG5R.js → chunk-2Q5K7J3B-Btg11SQH.js} +1 -1
  26. package/web/assets/{chunk-5VM5RSS4-CjLNiZx9.js → chunk-5VM5RSS4-BKmIdwHz.js} +1 -1
  27. package/web/assets/{chunk-F27PBJKO-B3BB5ZTi.js → chunk-F27PBJKO-Da3YRoya.js} +1 -1
  28. package/web/assets/{chunk-HLEWEB6X-DL3Dmhz2.js → chunk-HLEWEB6X-C35q0ph_.js} +1 -1
  29. package/web/assets/{chunk-JWPE2WC7-C8tTzTT2.js → chunk-JWPE2WC7-B5UTV1rv.js} +1 -1
  30. package/web/assets/{chunk-POPQ4Y6H-C69w1cBF.js → chunk-POPQ4Y6H-DxbwOxng.js} +1 -1
  31. package/web/assets/{chunk-SVP7TREG-D6cAgd1S.js → chunk-SVP7TREG-Rcv8F-aG.js} +1 -1
  32. package/web/assets/{chunk-XXDRQBXY-BGySdr7-.js → chunk-XXDRQBXY-DzI8m20a.js} +1 -1
  33. package/web/assets/{chunk-ZLD2IHE6-kFLP4DwD.js → chunk-ZLD2IHE6-I_R2Af3b.js} +1 -1
  34. package/web/assets/classDiagram-CYGNFDIV-Dgehf2qM.js +1 -0
  35. package/web/assets/classDiagram-v2-TLXNO2FR-Dgehf2qM.js +1 -0
  36. package/web/assets/{cose-bilkent-JH36ORCC-CKjDU3Ne.js → cose-bilkent-JH36ORCC-B9pJF5iu.js} +1 -1
  37. package/web/assets/{cynefin-OW5HDTMX-CBbOdI_d.js → cynefin-OW5HDTMX-BbJ34Xko.js} +1 -1
  38. package/web/assets/{cynefinDiagram-5FMLGOSQ-CSUCoNam.js → cynefinDiagram-5FMLGOSQ-BF_NZucr.js} +1 -1
  39. package/web/assets/{dagre-OS7QT2EB-BdB_oIrS.js → dagre-OS7QT2EB-Djr2ERNz.js} +1 -1
  40. package/web/assets/{diagram-S7CK7UJ4-sVtvdZDt.js → diagram-S7CK7UJ4-Br-qbMBh.js} +1 -1
  41. package/web/assets/{diagram-UQ7AKVKN-BdJDe0eW.js → diagram-UQ7AKVKN-DYVDN8PC.js} +1 -1
  42. package/web/assets/{diagram-VSXAHHWV-PbYEI0sA.js → diagram-VSXAHHWV-LxYw5zGG.js} +1 -1
  43. package/web/assets/{diagram-VX7I27RA-Cy5jJ40B.js → diagram-VX7I27RA-C0eoRvBk.js} +1 -1
  44. package/web/assets/{diagram-Z3DM3KII-DDHCm9FS.js → diagram-Z3DM3KII-DWgkcERO.js} +1 -1
  45. package/web/assets/{ebnfDiagram-PWID7BFC-Bjzjo_Zp.js → ebnfDiagram-PWID7BFC-Cez2iaxe.js} +1 -1
  46. package/web/assets/{erDiagram-2YWLMYGG-BD9FvOYK.js → erDiagram-2YWLMYGG-BaPzOQg7.js} +1 -1
  47. package/web/assets/{flowDiagram-T62WH6J4-CZCLczhV.js → flowDiagram-T62WH6J4-BZMN8XWi.js} +1 -1
  48. package/web/assets/{ganttDiagram-EL5Y4UJY-CJFwU23-.js → ganttDiagram-EL5Y4UJY-B71eSBEQ.js} +1 -1
  49. package/web/assets/{gitGraphDiagram-WWUBYQGX-CZUW7MkE.js → gitGraphDiagram-WWUBYQGX-DhuvhkGK.js} +1 -1
  50. package/web/assets/{infoDiagram-FKFFQAWI-Bp03OYtO.js → infoDiagram-FKFFQAWI-Devpgkju.js} +1 -1
  51. package/web/assets/{ishikawaDiagram-5VMMS53U-V13uN-7U.js → ishikawaDiagram-5VMMS53U-B9UrQ14y.js} +1 -1
  52. package/web/assets/{journeyDiagram-EYS64GPL-CZm5FWOH.js → journeyDiagram-EYS64GPL-BFK11Iww.js} +1 -1
  53. package/web/assets/{kanban-definition-UXKFOSKX-BdqJCUgf.js → kanban-definition-UXKFOSKX-PPExTrNG.js} +1 -1
  54. package/web/assets/{layout-B1ORwZSQ.js → layout-kCZSGp9r.js} +1 -1
  55. package/web/assets/{linear-BiQNIfsC.js → linear-BXCvSAaf.js} +1 -1
  56. package/web/assets/{mermaid.core-Do9iiICa.js → mermaid.core-CWPg7y8d.js} +6 -6
  57. package/web/assets/{mindmap-definition-THT77NOG-OW4rnK02.js → mindmap-definition-THT77NOG-uvGv44sD.js} +1 -1
  58. package/web/assets/{pegDiagram-XKGWAZYB-CYa-yK48.js → pegDiagram-XKGWAZYB-DSPBLDwA.js} +1 -1
  59. package/web/assets/{pieDiagram-E7YTZNPT-qU4fj_-b.js → pieDiagram-E7YTZNPT-B5nP9Y1z.js} +1 -1
  60. package/web/assets/{quadrantDiagram-AXDQQJYC-TS_ktNC7.js → quadrantDiagram-AXDQQJYC-BWthwN9w.js} +1 -1
  61. package/web/assets/{railroadDiagram-O6MQD6OU-BX8kuYOp.js → railroadDiagram-O6MQD6OU-DAXwCa18.js} +1 -1
  62. package/web/assets/{requirementDiagram-IS5BZ75X-DywoSPiE.js → requirementDiagram-IS5BZ75X-BmHtbdJS.js} +1 -1
  63. package/web/assets/{sankeyDiagram-P5KCCOFB-CWvFp2l8.js → sankeyDiagram-P5KCCOFB-UR3FQTYa.js} +1 -1
  64. package/web/assets/{sequenceDiagram-WJ2MYXX4-4EIPcp4K.js → sequenceDiagram-WJ2MYXX4-DGCx4UQK.js} +1 -1
  65. package/web/assets/{sizeCapture-INFHLROL-BJPOmFrf.js → sizeCapture-INFHLROL-C2q53DG3.js} +1 -1
  66. package/web/assets/{stateDiagram-XQSTLZYL-CTIIwL_Z.js → stateDiagram-XQSTLZYL-r9Sk3D6F.js} +1 -1
  67. package/web/assets/stateDiagram-v2-IH3M54BS-BoRR34S1.js +1 -0
  68. package/web/assets/{swimlanes-V6O3JKXN-CkM0zLLl.js → swimlanes-V6O3JKXN-C99OzjKu.js} +1 -1
  69. package/web/assets/swimlanesDiagram-JKAHXJPX-Bz7seo8f.js +8 -0
  70. package/web/assets/{timeline-definition-24CTP7MA-CWmfH9h5.js → timeline-definition-24CTP7MA-bX_ZEoDi.js} +1 -1
  71. package/web/assets/{vennDiagram-4TSXK5OY-BBcLi-dV.js → vennDiagram-4TSXK5OY-WWxZXXkY.js} +1 -1
  72. package/web/assets/{wardleyDiagram-VM6X3IG4-BOY_u0xY.js → wardleyDiagram-VM6X3IG4-DWxNbx_H.js} +1 -1
  73. package/web/assets/{workspace-file-tree-BlFl8HTy.js → workspace-file-tree-C3bZb5LL.js} +1 -1
  74. package/web/assets/{xychartDiagram-S5SC5T6Z-DEKEJe3d.js → xychartDiagram-S5SC5T6Z-Cyx8sJUe.js} +1 -1
  75. package/web/index.html +2 -2
  76. package/web/assets/app-DTWR2xcV.css +0 -32
  77. package/web/assets/channel-CMyQLup7.js +0 -1
  78. package/web/assets/classDiagram-CYGNFDIV-CRxvLR9h.js +0 -1
  79. package/web/assets/classDiagram-v2-TLXNO2FR-CRxvLR9h.js +0 -1
  80. package/web/assets/stateDiagram-v2-IH3M54BS-CPpaTRdY.js +0 -1
  81. package/web/assets/swimlanesDiagram-JKAHXJPX-BNdLlLdW.js +0 -8
@@ -486,7 +486,7 @@ var init_auth = __esm(() => {
486
486
  function emptyJournal() {
487
487
  return { version: 1, commands: [], requests: [] };
488
488
  }
489
- var TRANSCRIPT_PARTS_MAX = 200, TRANSCRIPT_TOOL_FIELD_MAX = 2000, TRANSCRIPT_TEXT_PART_MAX = 20000, TRANSCRIPT_REASONING_PART_MAX = 4000, MAX_COMMAND_ENTRIES = 256, MAX_REQUEST_ENTRIES = 256, REQUEST_RESULT_MAX_BYTES, DEFAULT_OPERATION_TIMEOUT_MS = 15000, SessionRunnerError;
489
+ var TRANSCRIPT_PARTS_MAX = 200, TRANSCRIPT_TOOL_FIELD_MAX = 2000, TRANSCRIPT_TEXT_PART_MAX = 20000, TRANSCRIPT_REASONING_PART_MAX = 4000, PENDING_ITEMS_MAX = 5, MAX_COMMAND_ENTRIES = 256, MAX_REQUEST_ENTRIES = 256, REQUEST_RESULT_MAX_BYTES, DEFAULT_OPERATION_TIMEOUT_MS = 15000, SessionRunnerError;
490
490
  var init_types = __esm(() => {
491
491
  REQUEST_RESULT_MAX_BYTES = 256 * 1024;
492
492
  SessionRunnerError = class SessionRunnerError extends Error {
@@ -636,6 +636,10 @@ function parseAnswerInput(value) {
636
636
  return invalid();
637
637
  return { kind: "question", requestId: text(v.requestId, 240), answers };
638
638
  }
639
+ if (v.kind === "dismiss") {
640
+ keys(v, ["kind", "requestId"]);
641
+ return { kind: "dismiss", requestId: text(v.requestId, 240) };
642
+ }
639
643
  if (v.kind !== "permission")
640
644
  return invalid();
641
645
  keys(v, ["kind", "requestId", "decision"]);
@@ -650,6 +654,21 @@ function parseAnswerResult(value) {
650
654
  }
651
655
  function parseCommand(value) {
652
656
  const v = object(value);
657
+ if (v.kind === "remote_session_attach") {
658
+ keys(v, ["commandId", "kind", "title", "prompt", "model", "expiresAt", "workspaceId", "sessionId"]);
659
+ if (v.prompt !== null || v.model !== null)
660
+ return invalid();
661
+ return {
662
+ commandId: text(v.commandId, 160),
663
+ kind: "remote_session_attach",
664
+ title: text(v.title, 120),
665
+ prompt: null,
666
+ model: null,
667
+ expiresAt: integer(v.expiresAt),
668
+ workspaceId: text(v.workspaceId, 240),
669
+ sessionId: text(v.sessionId, 240)
670
+ };
671
+ }
653
672
  keys(v, ["commandId", "kind", "title", "prompt", "model", "expiresAt", "workspaceId"]);
654
673
  if (v.kind !== "remote_session_create")
655
674
  return invalid();
@@ -808,7 +827,7 @@ function message(value) {
808
827
  }
809
828
  function parseReadResult(value) {
810
829
  const v = object(value);
811
- keys(v, ["title", "status", "waitingFor", "lastError", "messageCount", "from", "messages", "nextCursor", "historyScope", "pending"]);
830
+ keys(v, ["title", "status", "waitingFor", "lastError", "messageCount", "from", "messages", "nextCursor", "historyScope", "pending", "pendingItems"]);
812
831
  if (v.historyScope !== undefined && v.historyScope !== "context" && v.historyScope !== "full")
813
832
  return invalid();
814
833
  return {
@@ -821,7 +840,8 @@ function parseReadResult(value) {
821
840
  messages: array(v.messages, 100, message),
822
841
  nextCursor: nullable(v.nextCursor, (value2) => text(value2, 160, 0)),
823
842
  ...v.historyScope === undefined ? {} : { historyScope: v.historyScope },
824
- ...v.pending === undefined ? {} : { pending: nullable(v.pending, parsePending) }
843
+ ...v.pending === undefined ? {} : { pending: nullable(v.pending, parsePending) },
844
+ ...v.pendingItems === undefined ? {} : { pendingItems: array(v.pendingItems, PENDING_ITEMS_MAX, parsePending) }
825
845
  };
826
846
  }
827
847
  function parseSendResult(value) {
@@ -911,15 +931,17 @@ function parseJournal(value) {
911
931
  if (e.phase !== "prepared" && e.phase !== "created" && e.phase !== "delivered" && e.phase !== "failed")
912
932
  return invalid();
913
933
  const command = parseCommand(e.command);
914
- const legacyCreation = e.creation === undefined && e.intendedSessionId === undefined;
934
+ const attach = command.kind === "remote_session_attach";
935
+ const legacyCreation = !attach && e.creation === undefined && e.intendedSessionId === undefined;
915
936
  if (!legacyCreation && e.creation !== "idempotent" && e.creation !== "at_most_once")
916
937
  return invalid();
917
938
  const creation = e.creation === "idempotent" ? "idempotent" : "at_most_once";
918
939
  if (e.sendReplay !== undefined && e.sendReplay !== "idempotent" && e.sendReplay !== "at_most_once")
919
940
  return invalid();
920
941
  const sendReplay = e.sendReplay === "idempotent" ? "idempotent" : "at_most_once";
921
- const intendedSessionId = legacyCreation ? sessionIdForCommand(command.commandId) : text(e.intendedSessionId, 240);
922
- if (intendedSessionId !== sessionIdForCommand(command.commandId))
942
+ const intended = attach ? command.sessionId : sessionIdForCommand(command.commandId);
943
+ const intendedSessionId = legacyCreation ? intended : text(e.intendedSessionId, 240);
944
+ if (intendedSessionId !== intended)
923
945
  return invalid();
924
946
  const receipt = nullable(e.receipt, parseReceipt);
925
947
  const completion = nullable(e.completion, parseComplete);
@@ -941,6 +963,8 @@ function parseJournal(value) {
941
963
  return invalid();
942
964
  if (receipt && command.workspaceId && receipt.workspaceId !== command.workspaceId)
943
965
  return invalid();
966
+ if (attach && (receipt !== null !== (e.phase === "delivered") || receipt && receipt.sessionId !== command.sessionId))
967
+ return invalid();
944
968
  if (e.phase === "delivered" !== (completion?.status === "delivered") || e.phase === "failed" !== (completion?.status === "failed"))
945
969
  return invalid();
946
970
  if (acknowledged && completion === null)
@@ -1004,10 +1028,10 @@ function parseJournal(value) {
1004
1028
  };
1005
1029
  if (new Set(journal.commands.map((e) => e.command.commandId)).size !== journal.commands.length || new Set(journal.requests.map((e) => e.request.requestId)).size !== journal.requests.length)
1006
1030
  return invalid();
1007
- const receipts = journal.commands.flatMap((e) => e.receipt ? [`${e.receipt.workspaceId}\x00${e.receipt.sessionId}`] : []);
1031
+ const receipts = journal.commands.flatMap((e) => e.receipt && e.phase !== "failed" ? [`${e.receipt.workspaceId}\x00${e.receipt.sessionId}`] : []);
1008
1032
  if (new Set(receipts).size !== receipts.length)
1009
1033
  return invalid();
1010
- const intendedIds = journal.commands.filter((e) => e.creation === "idempotent").map((e) => e.intendedSessionId);
1034
+ const intendedIds = journal.commands.filter((e) => e.creation === "idempotent" && e.command.kind === "remote_session_create").map((e) => e.intendedSessionId);
1011
1035
  if (new Set(intendedIds).size !== intendedIds.length)
1012
1036
  return invalid();
1013
1037
  for (const e of journal.requests) {
@@ -1104,6 +1128,15 @@ function definitive(error) {
1104
1128
  function ambiguousAnswer() {
1105
1129
  return failure("ambiguous_answer", "The answer may already have reached the session. Check it on that computer before answering again; it will not be sent again automatically.");
1106
1130
  }
1131
+ function unknownReceipt() {
1132
+ return failure("unknown_receipt", "Only a session delivered by this account's local journal can be controlled.");
1133
+ }
1134
+ function accessRevoked() {
1135
+ return failure("session_access_denied", "This computer no longer allows sessions that were started on it.");
1136
+ }
1137
+ function tasksOff() {
1138
+ return failure("remote_access_off", "This computer doesn't take tasks from other devices.");
1139
+ }
1107
1140
  function staleRequest(error) {
1108
1141
  return error instanceof SessionRunnerError && error.code === "stale_request";
1109
1142
  }
@@ -1122,10 +1155,18 @@ function createSessionRunner(options) {
1122
1155
  const clock = options.now ?? Date.now;
1123
1156
  const now = () => integer(clock());
1124
1157
  const timeoutMs = integer(options.operationTimeoutMs ?? DEFAULT_OPERATION_TIMEOUT_MS, 1, 120000);
1158
+ const sessionAccess = options.sessionAccess ?? (() => "created");
1159
+ const revoked = (entry) => entry.command.kind === "remote_session_attach" && sessionAccess() !== "all";
1160
+ const closed = (entry) => {
1161
+ const access = sessionAccess();
1162
+ if (access === "off")
1163
+ return failure("remote_access_off", "This computer no longer takes anything from other devices.");
1164
+ return entry?.command.kind === "remote_session_attach" && access !== "all" ? accessRevoked() : null;
1165
+ };
1125
1166
  const creation = adapter.creation ?? "at_most_once";
1126
1167
  if (creation !== "idempotent" && creation !== "at_most_once")
1127
1168
  throw new SessionRunnerError("invalid_data", "Invalid adapter creation capability.");
1128
- const canReplayCreation = (entry) => entry.creation === "idempotent" && creation === "idempotent";
1169
+ const canReplayCreation = (entry) => entry.command.kind === "remote_session_attach" || entry.creation === "idempotent" && creation === "idempotent";
1129
1170
  const sendReplay = adapter.sendReplay ?? "idempotent";
1130
1171
  if (sendReplay !== "idempotent" && sendReplay !== "at_most_once")
1131
1172
  throw new SessionRunnerError("invalid_data", "Invalid adapter send replay capability.");
@@ -1233,10 +1274,65 @@ function createSessionRunner(options) {
1233
1274
  await local(signal, (s) => transport.completeRequest(id, structuredClone(e.completion), s));
1234
1275
  await saveRequest({ ...request(id), completionAcknowledged: true });
1235
1276
  }
1277
+ async function attachPrepared(value, signal) {
1278
+ const id = value.commandId;
1279
+ throwIfAborted(signal);
1280
+ try {
1281
+ if (value.expiresAt <= now())
1282
+ throw new SessionRunnerError("expired", "The command expired before the session could be attached.");
1283
+ const access = sessionAccess();
1284
+ if (access === "off") {
1285
+ const { code, message: message2 } = tasksOff();
1286
+ throw new SessionRunnerError(code, message2);
1287
+ }
1288
+ if (access !== "all")
1289
+ throw new SessionRunnerError("session_access_denied", "This computer only allows sessions that were started remotely.");
1290
+ const attach = adapter.attach;
1291
+ if (!attach)
1292
+ throw new SessionRunnerError("attach_unsupported", "This computer can't attach to a session that was started on it.");
1293
+ const creator = state().commands.find((e) => e.command.kind === "remote_session_create" && e.phase !== "failed" && e.receipt?.sessionId === value.sessionId && e.receipt.workspaceId === value.workspaceId);
1294
+ if (creator) {
1295
+ throw new SessionRunnerError("session_already_attached", creator.phase === "delivered" ? "This session is already reachable through another command." : "Another command on this computer still holds this session.");
1296
+ }
1297
+ const receipt = parseReceipt(await local(signal, (s) => attach.call(adapter, structuredClone(value), s)));
1298
+ if (receipt.sessionId !== value.sessionId || receipt.workspaceId !== value.workspaceId) {
1299
+ throw new SessionRunnerError("invalid_receipt", "The computer answered for a different session than the one to attach.");
1300
+ }
1301
+ const current = state();
1302
+ const superseded = new Set(current.commands.slice(0, current.commands.findIndex((e) => e.command.commandId === id)).filter((e) => e.command.kind === "remote_session_attach" && e.command.sessionId === value.sessionId && e.command.workspaceId === value.workspaceId).map((e) => e.command.commandId));
1303
+ await persist({
1304
+ ...current,
1305
+ commands: current.commands.filter((e) => !superseded.has(e.command.commandId)).map((e) => e.command.commandId !== id ? e : {
1306
+ ...e,
1307
+ phase: "delivered",
1308
+ receipt,
1309
+ completion: { status: "delivered", sessionId: receipt.sessionId, workspaceId: receipt.workspaceId }
1310
+ }),
1311
+ requests: current.requests.flatMap((r) => {
1312
+ if (!superseded.has(r.request.commandId) || r.completion?.status === "failed")
1313
+ return [r];
1314
+ if (r.completion)
1315
+ return [];
1316
+ const error = r.request.action === "send" && r.turn !== null ? ambiguousSend(r.request) : r.request.action === "answer" && r.messageId !== null ? ambiguousAnswer() : unknownReceipt();
1317
+ return [{ ...r, completion: { status: "failed", error } }];
1318
+ })
1319
+ });
1320
+ } catch (error) {
1321
+ if (signal.aborted || poisoned)
1322
+ throw error;
1323
+ const proven = definitive(error);
1324
+ if (!proven)
1325
+ throw error;
1326
+ await saveCommand({ ...command(id), phase: "failed", completion: { status: "failed", error: proven } });
1327
+ }
1328
+ }
1236
1329
  async function createPrepared(id, signal, firstAttempt = false) {
1237
1330
  const entry = command(id);
1238
1331
  if (entry.phase !== "prepared")
1239
1332
  return;
1333
+ if (entry.command.kind === "remote_session_attach")
1334
+ return attachPrepared(entry.command, signal);
1335
+ const value = entry.command;
1240
1336
  if (!firstAttempt && !canReplayCreation(entry)) {
1241
1337
  await saveCommand({ ...entry, phase: "failed", completion: { status: "failed", error: failure("ambiguous_creation", "Creation was interrupted before a receipt was saved. Inspect the native harness; this command will not create another session.") } });
1242
1338
  return;
@@ -1249,8 +1345,12 @@ function createSessionRunner(options) {
1249
1345
  } });
1250
1346
  return;
1251
1347
  }
1348
+ if (sessionAccess() === "off") {
1349
+ await saveCommand({ ...entry, phase: "failed", completion: { status: "failed", error: tasksOff() } });
1350
+ return;
1351
+ }
1252
1352
  try {
1253
- const receipt = parseReceipt(await local(signal, (s) => adapter.create(structuredClone(entry.command), s)));
1353
+ const receipt = parseReceipt(await local(signal, (s) => adapter.create(structuredClone(value), s)));
1254
1354
  if (entry.command.workspaceId && receipt.workspaceId !== entry.command.workspaceId) {
1255
1355
  throw new SessionRunnerError("invalid_data", "The adapter created a session in a different workspace.");
1256
1356
  }
@@ -1281,6 +1381,11 @@ function createSessionRunner(options) {
1281
1381
  await saveCommand({ ...e, phase: "failed", completion: completion2 });
1282
1382
  return completion2;
1283
1383
  }
1384
+ if (sessionAccess() === "off") {
1385
+ const completion2 = { status: "failed", error: e.turn && e.receipt ? ambiguousSend(e.receipt) : tasksOff() };
1386
+ await saveCommand({ ...e, phase: "failed", completion: completion2 });
1387
+ return completion2;
1388
+ }
1284
1389
  if (!e.receipt)
1285
1390
  throw new SessionRunnerError("ambiguous_creation", "A missing creation receipt cannot be replayed.");
1286
1391
  if (e.command.prompt !== null) {
@@ -1297,7 +1402,7 @@ function createSessionRunner(options) {
1297
1402
  }
1298
1403
  try {
1299
1404
  throwIfAborted(signal);
1300
- if (e.command.expiresAt <= now())
1405
+ if (e.command.expiresAt <= now() || sessionAccess() === "off")
1301
1406
  return deliver(id, signal);
1302
1407
  const result = parseSendResult(await local(signal, (s) => adapter.send(structuredClone(e.receipt), {
1303
1408
  prompt: e.command.prompt,
@@ -1340,14 +1445,18 @@ function createSessionRunner(options) {
1340
1445
  let completion;
1341
1446
  let applyTurn = false;
1342
1447
  const c = knownReceipt(e);
1448
+ const refusal = closed(c);
1343
1449
  if (e.request.action === "send" && e.turn && !canReplaySend(e)) {
1344
1450
  completion = { status: "failed", error: ambiguousSend(e.request) };
1345
1451
  applyTurn = true;
1346
1452
  } else if (e.request.expiresAt <= now()) {
1347
1453
  completion = { status: "failed", error: e.request.action === "answer" && e.messageId !== null ? ambiguousAnswer() : failure("expired", "The request expired before its next native effect.") };
1348
1454
  applyTurn = e.turn !== null;
1455
+ } else if (refusal) {
1456
+ completion = { status: "failed", error: e.request.action === "answer" && e.messageId !== null ? ambiguousAnswer() : e.request.action === "send" && e.turn !== null ? ambiguousSend(e.request) : refusal };
1457
+ applyTurn = e.turn !== null;
1349
1458
  } else if (!c?.receipt)
1350
- completion = { status: "failed", error: failure("unknown_receipt", "Only a session delivered by this account's local journal can be controlled.") };
1459
+ completion = { status: "failed", error: unknownReceipt() };
1351
1460
  else {
1352
1461
  const earlier = state().requests.slice(0, state().requests.findIndex((r) => r.request.requestId === id)).some((r) => r.request.commandId === e.request.commandId && r.request.action !== "read" && r.completion === null);
1353
1462
  if (earlier && e.request.action !== "read")
@@ -1370,7 +1479,7 @@ function createSessionRunner(options) {
1370
1479
  e = request(id);
1371
1480
  }
1372
1481
  throwIfAborted(signal);
1373
- if (e.request.expiresAt <= now())
1482
+ if (e.request.expiresAt <= now() || closed(c))
1374
1483
  return performRequest(id, signal);
1375
1484
  const result = parseSendResult(await local(signal, (s) => adapter.send(structuredClone(c.receipt), {
1376
1485
  ...structuredClone(input),
@@ -1392,6 +1501,8 @@ function createSessionRunner(options) {
1392
1501
  e = request(id);
1393
1502
  }
1394
1503
  throwIfAborted(signal);
1504
+ if (closed(c))
1505
+ return performRequest(id, signal);
1395
1506
  try {
1396
1507
  await local(signal, (s) => answer.call(adapter, structuredClone(c.receipt), structuredClone(input), s));
1397
1508
  completion = { status: "done", outcome: { action: "answer", result: { requestId: input.requestId, alreadyAnswered: false } } };
@@ -1444,6 +1555,8 @@ function createSessionRunner(options) {
1444
1555
  return completion;
1445
1556
  }
1446
1557
  async function flushProgress(id, progress, signal) {
1558
+ if (closed(command(id)))
1559
+ return false;
1447
1560
  try {
1448
1561
  await local(signal, (s) => transport.report(id, structuredClone(progress), s));
1449
1562
  } catch (error) {
@@ -1468,6 +1581,8 @@ function createSessionRunner(options) {
1468
1581
  return;
1469
1582
  e = command(id);
1470
1583
  }
1584
+ if (closed(e))
1585
+ return;
1471
1586
  let progress = parseProgress(await local(signal, (s) => adapter.observe(structuredClone(e.receipt), s)));
1472
1587
  let turn = e.turn;
1473
1588
  if (turn) {
@@ -1502,13 +1617,13 @@ function createSessionRunner(options) {
1502
1617
  if (!existing) {
1503
1618
  if (state().commands.length >= MAX_COMMAND_ENTRIES)
1504
1619
  throw new SessionRunnerError("journal_full", "Prune acknowledged commands before accepting more work.");
1505
- const expired = value.expiresAt <= now();
1620
+ const expired = value.kind === "remote_session_create" && value.expiresAt <= now();
1506
1621
  await persist({ ...state(), commands: [...state().commands, {
1507
1622
  command: value,
1508
1623
  creation,
1509
1624
  sendReplay,
1510
- intendedSessionId: sessionIdForCommand(value.commandId),
1511
1625
  lastObservedAt: null,
1626
+ intendedSessionId: value.kind === "remote_session_attach" ? value.sessionId : sessionIdForCommand(value.commandId),
1512
1627
  phase: expired ? "failed" : "prepared",
1513
1628
  receipt: null,
1514
1629
  promptMessageId: value.prompt === null ? null : stableMessageId(value.commandId),
@@ -1538,14 +1653,15 @@ function createSessionRunner(options) {
1538
1653
  if (state().requests.length >= MAX_REQUEST_ENTRIES)
1539
1654
  throw new SessionRunnerError("journal_full", "Prune acknowledged requests before accepting more work.");
1540
1655
  const c = state().commands.find((c2) => c2.command.commandId === value.commandId && c2.phase === "delivered" && c2.receipt?.sessionId === value.sessionId && c2.receipt.workspaceId === value.workspaceId);
1541
- let completion2 = !c ? { status: "failed", error: failure("unknown_receipt", "Only a session delivered by this account's local journal can be controlled.") } : null;
1542
- if (c && value.action === "answer") {
1656
+ const refusal = closed(c) ?? (c ? null : unknownReceipt());
1657
+ let completion2 = refusal ? { status: "failed", error: refusal } : null;
1658
+ if (c && completion2 === null && value.action === "answer") {
1543
1659
  const prior = state().requests.find((r) => r.request.commandId === value.commandId && r.request.action === "answer" && r.request.input.requestId === value.input.requestId && r.completion?.status === "done");
1544
1660
  if (prior)
1545
1661
  completion2 = { status: "done", outcome: { action: "answer", result: { requestId: value.input.requestId, alreadyAnswered: true } } };
1546
1662
  }
1547
1663
  const id = value.action === "send" ? value.input.messageId ?? stableMessageId(value.requestId) : value.action === "stop" ? value.input.messageId ?? c?.lastMessageId ?? null : null;
1548
- if (c && value.action === "send") {
1664
+ if (c && completion2 === null && value.action === "send") {
1549
1665
  const prior = state().requests.find((r) => r.request.commandId === value.commandId && r.messageId === id && r.request.action === "send");
1550
1666
  const original = c.promptMessageId === id ? { prompt: c.command.prompt, model: c.command.model } : null;
1551
1667
  const fingerprint = original ?? (prior?.request.action === "send" ? prior.request.input : null);
@@ -1612,7 +1728,8 @@ function createSessionRunner(options) {
1612
1728
  toRemove = Math.max(0, state().commands.length - retainCommands);
1613
1729
  const commands = state().commands.filter((e) => {
1614
1730
  const terminal = e.phase === "failed" || e.reportedProgress?.status === "idle" || e.reportedProgress?.status === "error";
1615
- if (toRemove > 0 && terminal && e.completionAcknowledged && e.progress === null && e.command.expiresAt <= now() && !retainedRequests.some((r) => r.request.commandId === e.command.commandId)) {
1731
+ const settled = revoked(e) || terminal && e.progress === null;
1732
+ if (toRemove > 0 && settled && e.completionAcknowledged && e.command.expiresAt <= now() && !retainedRequests.some((r) => r.request.commandId === e.command.commandId)) {
1616
1733
  toRemove--;
1617
1734
  return false;
1618
1735
  }