@nestos/kanban 0.5.1 → 0.5.2

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 (147) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +73 -29
  3. package/dist/{activity-C6xDM-cg.d.cts → activity-BbC4sgKL.d.cts} +28 -2
  4. package/dist/{activity-Dw8DOw0L.d.ts → activity-Czlan5xW.d.ts} +28 -2
  5. package/dist/activity-module-DaO1Rry0.d.cts +22 -0
  6. package/dist/activity-module-T22wliZu.d.ts +22 -0
  7. package/dist/activity-ports-Dqxa86zT.d.cts +12 -0
  8. package/dist/activity-ports-cxfrelaL.d.ts +12 -0
  9. package/dist/activity.cjs +10 -282
  10. package/dist/activity.cjs.map +1 -1
  11. package/dist/activity.d.cts +8 -30
  12. package/dist/activity.d.ts +8 -30
  13. package/dist/activity.js +9 -281
  14. package/dist/activity.js.map +1 -1
  15. package/dist/{chunk-O4OGAAV4.js → chunk-3JYLJPE5.js} +29 -5
  16. package/dist/chunk-3JYLJPE5.js.map +1 -0
  17. package/dist/{chunk-ATUFFNLV.js → chunk-3LEIHB7Y.js} +5 -5
  18. package/dist/chunk-4XF6LQSU.cjs.map +1 -1
  19. package/dist/chunk-5Q7WB63A.cjs +282 -0
  20. package/dist/chunk-5Q7WB63A.cjs.map +1 -0
  21. package/dist/{chunk-PSKQAFDF.cjs → chunk-7KDOTBRX.cjs} +1 -1
  22. package/dist/chunk-7KDOTBRX.cjs.map +1 -0
  23. package/dist/{chunk-5DLZWW5Y.js → chunk-AHHEGTUA.js} +3 -3
  24. package/dist/chunk-AOHQCX7K.cjs +95 -0
  25. package/dist/chunk-AOHQCX7K.cjs.map +1 -0
  26. package/dist/{chunk-IUI5CI2S.cjs → chunk-DINLR6E6.cjs} +96 -92
  27. package/dist/chunk-DINLR6E6.cjs.map +1 -0
  28. package/dist/{chunk-L44TM4EE.cjs → chunk-EYTVC2H5.cjs} +568 -454
  29. package/dist/chunk-EYTVC2H5.cjs.map +1 -0
  30. package/dist/chunk-FEE2YBZ7.js +1972 -0
  31. package/dist/chunk-FEE2YBZ7.js.map +1 -0
  32. package/dist/chunk-FNO5K3A7.js +282 -0
  33. package/dist/chunk-FNO5K3A7.js.map +1 -0
  34. package/dist/chunk-IHHDXZPZ.js +382 -0
  35. package/dist/chunk-IHHDXZPZ.js.map +1 -0
  36. package/dist/chunk-J3EAIVA3.js +280 -0
  37. package/dist/chunk-J3EAIVA3.js.map +1 -0
  38. package/dist/{chunk-DFTOTBGF.js → chunk-KH3WF3K4.js} +20 -16
  39. package/dist/chunk-KH3WF3K4.js.map +1 -0
  40. package/dist/{chunk-TB2RZGDV.js → chunk-M35X5PHO.js} +14 -1
  41. package/dist/chunk-M35X5PHO.js.map +1 -0
  42. package/dist/chunk-QRGZD2JU.cjs +1972 -0
  43. package/dist/chunk-QRGZD2JU.cjs.map +1 -0
  44. package/dist/{chunk-4KF7KUAI.cjs → chunk-RBOER6EW.cjs} +6 -6
  45. package/dist/chunk-RBOER6EW.cjs.map +1 -0
  46. package/dist/{chunk-6MN3H3YF.cjs → chunk-RSH6QSEC.cjs} +16 -3
  47. package/dist/chunk-RSH6QSEC.cjs.map +1 -0
  48. package/dist/{chunk-T7P5EIC4.cjs → chunk-VMRDXOLX.cjs} +33 -33
  49. package/dist/chunk-VMRDXOLX.cjs.map +1 -0
  50. package/dist/{chunk-5XKOCKY2.js → chunk-X4UHZX6F.js} +1 -1
  51. package/dist/chunk-XBSGUVCY.cjs +382 -0
  52. package/dist/chunk-XBSGUVCY.cjs.map +1 -0
  53. package/dist/{chunk-OHQTKGQN.js → chunk-XKDZHAUE.js} +242 -128
  54. package/dist/chunk-XKDZHAUE.js.map +1 -0
  55. package/dist/chunk-ZUZGAO6G.cjs +280 -0
  56. package/dist/chunk-ZUZGAO6G.cjs.map +1 -0
  57. package/dist/{content-CAIp1njn.d.cts → content-C5aJZFlw.d.cts} +1 -1
  58. package/dist/{content-CGMJdyH_.d.ts → content-hLH5BNud.d.ts} +1 -1
  59. package/dist/contracts/index.cjs +13 -3
  60. package/dist/contracts/index.cjs.map +1 -1
  61. package/dist/contracts/index.d.cts +5 -4
  62. package/dist/contracts/index.d.ts +5 -4
  63. package/dist/contracts/index.js +14 -4
  64. package/dist/{discovery-DxpirOz3.d.cts → discovery-9E-LfwIw.d.cts} +1 -1
  65. package/dist/{discovery-gSqWpuRm.d.ts → discovery-D60yrjej.d.ts} +1 -1
  66. package/dist/discovery.cjs +63 -65
  67. package/dist/discovery.cjs.map +1 -1
  68. package/dist/discovery.d.cts +4 -4
  69. package/dist/discovery.d.ts +4 -4
  70. package/dist/discovery.js +5 -7
  71. package/dist/discovery.js.map +1 -1
  72. package/dist/execution-bridge-fpCnH6z5.d.cts +52 -0
  73. package/dist/execution-bridge-rk0uVy_n.d.ts +52 -0
  74. package/dist/execution.cjs +6 -356
  75. package/dist/execution.cjs.map +1 -1
  76. package/dist/execution.d.cts +4 -51
  77. package/dist/execution.d.ts +4 -51
  78. package/dist/execution.js +9 -359
  79. package/dist/execution.js.map +1 -1
  80. package/dist/index.cjs +10 -12
  81. package/dist/index.cjs.map +1 -1
  82. package/dist/index.d.cts +9 -16
  83. package/dist/index.d.ts +9 -16
  84. package/dist/index.js +10 -12
  85. package/dist/index.js.map +1 -1
  86. package/dist/{module-CWNK2BMj.d.ts → module-CYfE7YhM.d.ts} +2 -2
  87. package/dist/{module-BbvwdCDF.d.cts → module-Ca9L3qCn.d.cts} +2 -2
  88. package/dist/{planning-CcFZYdIL.d.cts → planning-CHrOqQ6b.d.cts} +45 -10
  89. package/dist/{planning-CcFZYdIL.d.ts → planning-CHrOqQ6b.d.ts} +45 -10
  90. package/dist/{ports-Bn6ro2FB.d.ts → ports-B0McVg7B.d.ts} +4 -3
  91. package/dist/ports-BeGO1VRI.d.cts +49 -0
  92. package/dist/{ports-CaL6geqR.d.cts → ports-GQy0x-RI.d.cts} +4 -3
  93. package/dist/ports-ykGiNUSx.d.ts +49 -0
  94. package/dist/runtime/index.cjs +205 -0
  95. package/dist/runtime/index.cjs.map +1 -0
  96. package/dist/runtime/index.d.cts +75 -0
  97. package/dist/runtime/index.d.ts +75 -0
  98. package/dist/runtime/index.js +205 -0
  99. package/dist/runtime/index.js.map +1 -0
  100. package/dist/runtime/integration.cjs +423 -0
  101. package/dist/runtime/integration.cjs.map +1 -0
  102. package/dist/runtime/integration.d.cts +658 -0
  103. package/dist/runtime/integration.d.ts +658 -0
  104. package/dist/runtime/integration.js +423 -0
  105. package/dist/runtime/integration.js.map +1 -0
  106. package/dist/storage.cjs +9 -277
  107. package/dist/storage.cjs.map +1 -1
  108. package/dist/storage.d.cts +6 -6
  109. package/dist/storage.d.ts +6 -6
  110. package/dist/storage.js +11 -279
  111. package/dist/storage.js.map +1 -1
  112. package/dist/{store-q63eSMoT.d.cts → store-DPwHzGiz.d.cts} +2 -2
  113. package/dist/{store-Ct0gOAAg.d.ts → store-DgdrPCV9.d.ts} +2 -2
  114. package/dist/task-projection-CSorlMws.d.ts +11 -0
  115. package/dist/task-projection-DKKB_ueb.d.cts +11 -0
  116. package/examples/standalone.ts +22 -0
  117. package/package.json +117 -87
  118. package/dist/chunk-2YFPV5GF.cjs +0 -16
  119. package/dist/chunk-2YFPV5GF.cjs.map +0 -1
  120. package/dist/chunk-4KF7KUAI.cjs.map +0 -1
  121. package/dist/chunk-6MN3H3YF.cjs.map +0 -1
  122. package/dist/chunk-DFTOTBGF.js.map +0 -1
  123. package/dist/chunk-G6FCDLDF.js +0 -16
  124. package/dist/chunk-G6FCDLDF.js.map +0 -1
  125. package/dist/chunk-IUI5CI2S.cjs.map +0 -1
  126. package/dist/chunk-KYNYPKKH.cjs +0 -71
  127. package/dist/chunk-KYNYPKKH.cjs.map +0 -1
  128. package/dist/chunk-L44TM4EE.cjs.map +0 -1
  129. package/dist/chunk-LSE6JG5I.cjs +0 -20
  130. package/dist/chunk-LSE6JG5I.cjs.map +0 -1
  131. package/dist/chunk-O4OGAAV4.js.map +0 -1
  132. package/dist/chunk-OHQTKGQN.js.map +0 -1
  133. package/dist/chunk-PSKQAFDF.cjs.map +0 -1
  134. package/dist/chunk-QTMTBEBA.js +0 -20
  135. package/dist/chunk-QTMTBEBA.js.map +0 -1
  136. package/dist/chunk-T7P5EIC4.cjs.map +0 -1
  137. package/dist/chunk-TB2RZGDV.js.map +0 -1
  138. package/dist/ui/index.cjs +0 -1961
  139. package/dist/ui/index.cjs.map +0 -1
  140. package/dist/ui/index.d.cts +0 -209
  141. package/dist/ui/index.d.ts +0 -209
  142. package/dist/ui/index.js +0 -1961
  143. package/dist/ui/index.js.map +0 -1
  144. package/dist/ui/kanban.css +0 -194
  145. /package/dist/{chunk-ATUFFNLV.js.map → chunk-3LEIHB7Y.js.map} +0 -0
  146. /package/dist/{chunk-5DLZWW5Y.js.map → chunk-AHHEGTUA.js.map} +0 -0
  147. /package/dist/{chunk-5XKOCKY2.js.map → chunk-X4UHZX6F.js.map} +0 -0
@@ -19,27 +19,23 @@ var _chunk4XF6LQSUcjs = require('./chunk-4XF6LQSU.cjs');
19
19
 
20
20
 
21
21
 
22
- var _chunk4KF7KUAIcjs = require('./chunk-4KF7KUAI.cjs');
22
+ var _chunkRBOER6EWcjs = require('./chunk-RBOER6EW.cjs');
23
23
 
24
24
 
25
- var _chunk2YFPV5GFcjs = require('./chunk-2YFPV5GF.cjs');
26
25
 
26
+ var _chunk7KDOTBRXcjs = require('./chunk-7KDOTBRX.cjs');
27
27
 
28
28
 
29
29
 
30
30
 
31
- var _chunkKYNYPKKHcjs = require('./chunk-KYNYPKKH.cjs');
31
+ var _chunkRSH6QSECcjs = require('./chunk-RSH6QSEC.cjs');
32
32
 
33
33
 
34
34
 
35
- var _chunkPSKQAFDFcjs = require('./chunk-PSKQAFDF.cjs');
36
35
 
37
36
 
38
37
 
39
- var _chunk6MN3H3YFcjs = require('./chunk-6MN3H3YF.cjs');
40
-
41
-
42
- var _chunkLSE6JG5Icjs = require('./chunk-LSE6JG5I.cjs');
38
+ var _chunkAOHQCX7Kcjs = require('./chunk-AOHQCX7K.cjs');
43
39
 
44
40
  // src/planning.ts
45
41
  function plan(item) {
@@ -47,6 +43,7 @@ function plan(item) {
47
43
  }
48
44
  function summary(item) {
49
45
  return {
46
+ deletedAt: item.deletedAt,
50
47
  launch: item.launch,
51
48
  analysis: item.analysis,
52
49
  control: item.control,
@@ -78,45 +75,48 @@ function limits(state) {
78
75
  return { ready: _nullishCoalesce(p.maxReady, () => ( 20)), inProgress: _nullishCoalesce(p.maxInProgress, () => ( 3)), perAgent: _nullishCoalesce(_nullishCoalesce(p.maxInProgressPerAssignee, () => ( p.maxInProgressPerAgent)), () => ( 1)), perAssignee: _nullishCoalesce(_nullishCoalesce(p.maxInProgressPerAssignee, () => ( p.maxInProgressPerAgent)), () => ( 1)) };
79
76
  }
80
77
  function validatePlan(state, item, value) {
81
- _chunk4KF7KUAIcjs.requireValue.call(void 0, typeof value.kind === "string" && Number.isInteger(value.priority) && value.priority >= 0 && value.priority <= 4, "INVALID_PLANNING");
82
- _chunk4KF7KUAIcjs.requireValue.call(void 0, Array.isArray(value.dependencies) && value.dependencies.length <= 100 && Array.isArray(value.references) && value.references.length <= 100, "PLANNING_LIMIT");
83
- value.dependencies.forEach(_chunk4KF7KUAIcjs.identity);
84
- value.references.forEach(_chunk4KF7KUAIcjs.text);
85
- if (value.area !== void 0) _chunk4KF7KUAIcjs.identity.call(void 0, value.area);
86
- if (value.milestone !== void 0) _chunk4KF7KUAIcjs.identity.call(void 0, value.milestone);
87
- _chunk4KF7KUAIcjs.requireValue.call(void 0, value.execution === void 0 || ["direct", "children"].includes(value.execution), "INVALID_EXECUTION_MODE");
88
- const type = _chunk4KF7KUAIcjs.workType.call(void 0, state.board, value.kind);
89
- if (value.dueAt !== void 0) _chunk4KF7KUAIcjs.requireValue.call(void 0, Number.isFinite(value.dueAt) && value.dueAt >= 0, "INVALID_DUE_DATE");
78
+ _chunkRBOER6EWcjs.requireValue.call(void 0, typeof value.kind === "string" && Number.isInteger(value.priority) && value.priority >= 0 && value.priority <= 4, "INVALID_PLANNING");
79
+ _chunkRBOER6EWcjs.requireValue.call(void 0, Array.isArray(value.dependencies) && value.dependencies.length <= 100 && Array.isArray(value.references) && value.references.length <= 100, "PLANNING_LIMIT");
80
+ value.dependencies.forEach(_chunkRBOER6EWcjs.identity);
81
+ value.references.forEach(_chunkRBOER6EWcjs.text);
82
+ if (value.area !== void 0) _chunkRBOER6EWcjs.identity.call(void 0, value.area);
83
+ if (value.milestone !== void 0) _chunkRBOER6EWcjs.identity.call(void 0, value.milestone);
84
+ _chunkRBOER6EWcjs.requireValue.call(void 0, value.execution === void 0 || ["direct", "children"].includes(value.execution), "INVALID_EXECUTION_MODE");
85
+ const type = _chunkRBOER6EWcjs.workType.call(void 0, state.board, value.kind);
86
+ if (value.dueAt !== void 0) _chunkRBOER6EWcjs.requireValue.call(void 0, Number.isFinite(value.dueAt) && value.dueAt >= 0, "INVALID_DUE_DATE");
90
87
  const all = catalog(state), parent = all.find((i) => i.id === value.parentId);
91
88
  if (value.parentId) {
92
- _chunk4KF7KUAIcjs.identity.call(void 0, value.parentId);
93
- _chunk4KF7KUAIcjs.requireValue.call(void 0, parent && !parent.archivedAt && !terminal(parent) && !["claimed", "review"].includes(parent.status), "PARENT_UNAVAILABLE");
94
- _chunk4KF7KUAIcjs.requireValue.call(void 0, parent.id !== item.id && _chunk4KF7KUAIcjs.workType.call(void 0, state.board, parent.planning.kind).rank < type.rank, "INVALID_PARENT_KIND");
89
+ _chunkRBOER6EWcjs.identity.call(void 0, value.parentId);
90
+ _chunkRBOER6EWcjs.requireValue.call(void 0, parent && !parent.archivedAt && !parent.deletedAt && !terminal(parent) && _optionalChain([parent, 'access', _7 => _7.control, 'optionalAccess', _8 => _8.action]) !== "cancel" && !["claimed", "review"].includes(parent.status), "PARENT_UNAVAILABLE");
91
+ _chunkRBOER6EWcjs.requireValue.call(void 0, parent.id !== item.id && _chunkRBOER6EWcjs.workType.call(void 0, state.board, parent.planning.kind).rank < type.rank, "INVALID_PARENT_KIND");
95
92
  }
96
- _chunk4KF7KUAIcjs.requireValue.call(void 0, value.execution === "children" || !all.some((child) => child.planning.parentId === item.id), "CHILDREN_REQUIRE_AGGREGATION");
97
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !all.some((child) => child.planning.parentId === item.id && _chunk4KF7KUAIcjs.workType.call(void 0, state.board, child.planning.kind).rank <= type.rank), "INVALID_CHILD_KIND");
98
- for (const id of value.dependencies) _chunk4KF7KUAIcjs.requireValue.call(void 0, id !== item.id && all.some((i) => i.id === id), "INVALID_DEPENDENCY");
93
+ _chunkRBOER6EWcjs.requireValue.call(void 0, value.execution === "children" || !all.some((child) => child.planning.parentId === item.id), "CHILDREN_REQUIRE_AGGREGATION");
94
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !all.some((child) => child.planning.parentId === item.id && _chunkRBOER6EWcjs.workType.call(void 0, state.board, child.planning.kind).rank <= type.rank), "INVALID_CHILD_KIND");
95
+ for (const id of value.dependencies) _chunkRBOER6EWcjs.requireValue.call(void 0, id !== item.id && all.some((i) => i.id === id), "INVALID_DEPENDENCY");
99
96
  const visited = /* @__PURE__ */ new Set(), pending = [...value.dependencies];
100
97
  while (pending.length) {
101
98
  const id = pending.pop();
102
- _chunk4KF7KUAIcjs.requireValue.call(void 0, id !== item.id, "DEPENDENCY_CYCLE");
99
+ _chunkRBOER6EWcjs.requireValue.call(void 0, id !== item.id, "DEPENDENCY_CYCLE");
103
100
  if (visited.has(id)) continue;
104
101
  visited.add(id);
105
- pending.push(..._nullishCoalesce(_optionalChain([all, 'access', _7 => _7.find, 'call', _8 => _8((i) => i.id === id), 'optionalAccess', _9 => _9.planning, 'access', _10 => _10.dependencies]), () => ( [])));
102
+ pending.push(..._nullishCoalesce(_optionalChain([all, 'access', _9 => _9.find, 'call', _10 => _10((i) => i.id === id), 'optionalAccess', _11 => _11.planning, 'access', _12 => _12.dependencies]), () => ( [])));
106
103
  }
107
104
  }
108
105
  function assertReady(state, item) {
109
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _chunk4KF7KUAIcjs.executable.call(void 0, state.board, item), "PLAN_NOT_EXECUTABLE");
110
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !item.blocked, "ITEM_BLOCKED");
106
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !state.board.lifecycle, "BOARD_STOPPING");
107
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !_optionalChain([state, 'access', _13 => _13.board, 'access', _14 => _14.executionControl, 'optionalAccess', _15 => _15.paused]), "BOARD_EXECUTION_PAUSED");
108
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _chunkRBOER6EWcjs.executable.call(void 0, state.board, item), "PLAN_NOT_EXECUTABLE");
109
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !item.blocked, "ITEM_BLOCKED");
110
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !item.control || item.control.action === "resume" && item.control.state === "resumed", "TASK_CONTROL_PENDING");
111
111
  const all = catalog(state);
112
- _chunk4KF7KUAIcjs.requireValue.call(void 0, plan(item).dependencies.every((id) => _optionalChain([all, 'access', _11 => _11.find, 'call', _12 => _12((i) => i.id === id), 'optionalAccess', _13 => _13.status]) === "completed"), "DEPENDENCIES_UNFINISHED");
112
+ _chunkRBOER6EWcjs.requireValue.call(void 0, plan(item).dependencies.every((id) => _optionalChain([all, 'access', _16 => _16.find, 'call', _17 => _17((i) => i.id === id), 'optionalAccess', _18 => _18.status]) === "completed"), "DEPENDENCIES_UNFINISHED");
113
113
  }
114
114
  function setStage(state, item, stage, now) {
115
- _chunk4KF7KUAIcjs.requireValue.call(void 0, ["proposed", "backlog", "open"].includes(item.status), "ITEM_NOT_PLANNABLE");
116
- _chunk4KF7KUAIcjs.requireValue.call(void 0, stage === "backlog" || stage === "open", "INVALID_STAGE");
115
+ _chunkRBOER6EWcjs.requireValue.call(void 0, ["proposed", "backlog", "open"].includes(item.status), "ITEM_NOT_PLANNABLE");
116
+ _chunkRBOER6EWcjs.requireValue.call(void 0, stage === "backlog" || stage === "open", "INVALID_STAGE");
117
117
  if (stage === "open") {
118
118
  assertReady(state, item);
119
- _chunk4KF7KUAIcjs.requireValue.call(void 0, item.status === "open" || state.board.items.filter((i) => i.status === "open").length < limits(state).ready, "READY_LIMIT");
119
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item.status === "open" || state.board.items.filter((i) => i.status === "open").length < limits(state).ready, "READY_LIMIT");
120
120
  }
121
121
  item.status = stage;
122
122
  item.readyAt = now;
@@ -125,16 +125,16 @@ function setStage(state, item, stage, now) {
125
125
  }
126
126
  function automaticStage(state, item) {
127
127
  const all = catalog(state);
128
- const dependenciesComplete = plan(item).dependencies.every((id) => _optionalChain([all, 'access', _14 => _14.find, 'call', _15 => _15((i) => i.id === id), 'optionalAccess', _16 => _16.status]) === "completed");
129
- return _chunk4KF7KUAIcjs.executable.call(void 0, state.board, item) && !item.blocked && dependenciesComplete && state.board.items.filter((i) => i.status === "open").length < limits(state).ready ? "open" : "backlog";
128
+ const dependenciesComplete = plan(item).dependencies.every((id) => _optionalChain([all, 'access', _19 => _19.find, 'call', _20 => _20((i) => i.id === id), 'optionalAccess', _21 => _21.status]) === "completed");
129
+ return _chunkRBOER6EWcjs.executable.call(void 0, state.board, item) && !item.blocked && dependenciesComplete && state.board.items.filter((i) => i.status === "open").length < limits(state).ready ? "open" : "backlog";
130
130
  }
131
131
 
132
132
  // src/amendments.ts
133
133
  var textOf = (item) => ({ title: item.title, responsibility: item.responsibility, acceptance: item.acceptance });
134
- var textDigest = (item) => _chunk6MN3H3YFcjs.sha256HexSync.call(void 0, JSON.stringify(textOf(item)));
134
+ var textDigest = (item) => _chunkRSH6QSECcjs.sha256HexSync.call(void 0, JSON.stringify(textOf(item)));
135
135
  function workFingerprint(item) {
136
136
  const planning = plan(item);
137
- return _chunk6MN3H3YFcjs.sha256HexSync.call(void 0, JSON.stringify({
137
+ return _chunkRSH6QSECcjs.sha256HexSync.call(void 0, JSON.stringify({
138
138
  text: textOf(item),
139
139
  kind: planning.kind,
140
140
  parentId: _nullishCoalesce(planning.parentId, () => ( null)),
@@ -146,62 +146,62 @@ function workFingerprint(item) {
146
146
  }));
147
147
  }
148
148
  function validateSources(sources) {
149
- _chunk4KF7KUAIcjs.requireValue.call(void 0, Array.isArray(sources) && sources.length <= 100, "SOURCE_LIMIT");
149
+ _chunkRBOER6EWcjs.requireValue.call(void 0, Array.isArray(sources) && sources.length <= 100, "SOURCE_LIMIT");
150
150
  for (const source of sources) {
151
- _chunk4KF7KUAIcjs.identity.call(void 0, source.sessionId);
152
- _chunk4KF7KUAIcjs.identity.call(void 0, source.messageId);
153
- _chunk4KF7KUAIcjs.identity.call(void 0, source.revision);
154
- _chunk4KF7KUAIcjs.requireValue.call(void 0, source.role === "user" || source.role === "assistant", "INVALID_SOURCE");
151
+ _chunkRBOER6EWcjs.identity.call(void 0, source.sessionId);
152
+ _chunkRBOER6EWcjs.identity.call(void 0, source.messageId);
153
+ _chunkRBOER6EWcjs.identity.call(void 0, source.revision);
154
+ _chunkRBOER6EWcjs.requireValue.call(void 0, source.role === "user" || source.role === "assistant", "INVALID_SOURCE");
155
155
  }
156
156
  }
157
157
  function proposeAmendment(item, change, actor, now, runId) {
158
- _chunk4KF7KUAIcjs.text.call(void 0, change.title);
159
- _chunk4KF7KUAIcjs.text.call(void 0, change.responsibility);
160
- _chunk4KF7KUAIcjs.text.call(void 0, change.acceptance);
158
+ _chunkRBOER6EWcjs.text.call(void 0, change.title);
159
+ _chunkRBOER6EWcjs.text.call(void 0, change.responsibility);
160
+ _chunkRBOER6EWcjs.text.call(void 0, change.acceptance);
161
161
  validateSources(change.sources);
162
162
  const proposed = textOf(change), fingerprint = textDigest(proposed);
163
- if (textDigest(item) === fingerprint || _optionalChain([item, 'access', _17 => _17.amendments, 'optionalAccess', _18 => _18.some, 'call', _19 => _19((p) => p.fingerprint === fingerprint)])) return;
164
- _chunk4KF7KUAIcjs.requireValue.call(void 0, (_nullishCoalesce(_optionalChain([item, 'access', _20 => _20.amendments, 'optionalAccess', _21 => _21.length]), () => ( 0))) < 20, "AMENDMENT_LIMIT");
163
+ if (textDigest(item) === fingerprint || _optionalChain([item, 'access', _22 => _22.amendments, 'optionalAccess', _23 => _23.some, 'call', _24 => _24((p) => p.fingerprint === fingerprint)])) return;
164
+ _chunkRBOER6EWcjs.requireValue.call(void 0, (_nullishCoalesce(_optionalChain([item, 'access', _25 => _25.amendments, 'optionalAccess', _26 => _26.length]), () => ( 0))) < 20, "AMENDMENT_LIMIT");
165
165
  (item.amendments ??= []).push({
166
166
  runId,
167
- id: `amendment-${_chunk6MN3H3YFcjs.sha256HexSync.call(void 0, JSON.stringify([runId, item.id, fingerprint]))}`,
167
+ id: `amendment-${_chunkRSH6QSECcjs.sha256HexSync.call(void 0, JSON.stringify([runId, item.id, fingerprint]))}`,
168
168
  fingerprint,
169
169
  baseRevision: item.revision,
170
170
  baseDigest: textDigest(item),
171
171
  proposed,
172
- proposedBy: _chunk4KF7KUAIcjs.principal.call(void 0, actor),
172
+ proposedBy: _chunkRBOER6EWcjs.principal.call(void 0, actor),
173
173
  sources: structuredClone(change.sources),
174
174
  createdAt: now,
175
175
  status: "pending"
176
176
  });
177
177
  }
178
178
  function requireReviewer(board, actor) {
179
- const key = _chunk4KF7KUAIcjs.principalKey.call(void 0, _chunk4KF7KUAIcjs.principal.call(void 0, actor));
180
- _chunk4KF7KUAIcjs.requireValue.call(void 0,
181
- _optionalChain([board, 'access', _22 => _22.members, 'optionalAccess', _23 => _23.some, 'call', _24 => _24((m) => _chunk4KF7KUAIcjs.principalKey.call(void 0, m) === key && _optionalChain([m, 'access', _25 => _25.roles, 'optionalAccess', _26 => _26.some, 'call', _27 => _27((role) => role === "coordinator" || role === "reviewer")]))]),
179
+ const key = _chunkRBOER6EWcjs.principalKey.call(void 0, _chunkRBOER6EWcjs.principal.call(void 0, actor));
180
+ _chunkRBOER6EWcjs.requireValue.call(void 0,
181
+ _optionalChain([board, 'access', _27 => _27.members, 'optionalAccess', _28 => _28.some, 'call', _29 => _29((m) => _chunkRBOER6EWcjs.principalKey.call(void 0, m) === key && _optionalChain([m, 'access', _30 => _30.roles, 'optionalAccess', _31 => _31.some, 'call', _32 => _32((role) => role === "coordinator" || role === "reviewer")]))]),
182
182
  "REVIEWER_REQUIRED"
183
183
  );
184
184
  }
185
185
  function reviewAmendment(board, command, actor, now) {
186
186
  requireReviewer(board, actor);
187
- const item = board.items.find((i) => i.id === command.itemId), proposal = _optionalChain([item, 'optionalAccess', _28 => _28.amendments, 'optionalAccess', _29 => _29.find, 'call', _30 => _30((p) => p.id === command.amendmentId)]);
188
- _chunk4KF7KUAIcjs.requireValue.call(void 0, item && _optionalChain([proposal, 'optionalAccess', _31 => _31.status]) === "pending", "AMENDMENT_NOT_PENDING");
187
+ const item = board.items.find((i) => i.id === command.itemId), proposal = _optionalChain([item, 'optionalAccess', _33 => _33.amendments, 'optionalAccess', _34 => _34.find, 'call', _35 => _35((p) => p.id === command.amendmentId)]);
188
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item && _optionalChain([proposal, 'optionalAccess', _36 => _36.status]) === "pending", "AMENDMENT_NOT_PENDING");
189
189
  if (command.accept) {
190
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _chunk4KF7KUAIcjs.principal.call(void 0, actor).kind === "human" || _chunk4KF7KUAIcjs.principalKey.call(void 0, proposal.proposedBy) !== _chunk4KF7KUAIcjs.principalKey.call(void 0, _chunk4KF7KUAIcjs.principal.call(void 0, actor)), "INDEPENDENT_REVIEW_REQUIRED");
191
- _chunk4KF7KUAIcjs.requireValue.call(void 0, ["proposed", "backlog", "open"].includes(item.status), "ITEM_NOT_PLANNABLE");
192
- _chunk4KF7KUAIcjs.requireValue.call(void 0, textDigest(item) === proposal.baseDigest, "AMENDMENT_STALE");
190
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _chunkRBOER6EWcjs.principal.call(void 0, actor).kind === "human" || _chunkRBOER6EWcjs.principalKey.call(void 0, proposal.proposedBy) !== _chunkRBOER6EWcjs.principalKey.call(void 0, _chunkRBOER6EWcjs.principal.call(void 0, actor)), "INDEPENDENT_REVIEW_REQUIRED");
191
+ _chunkRBOER6EWcjs.requireValue.call(void 0, ["proposed", "backlog", "open"].includes(item.status), "ITEM_NOT_PLANNABLE");
192
+ _chunkRBOER6EWcjs.requireValue.call(void 0, textDigest(item) === proposal.baseDigest, "AMENDMENT_STALE");
193
193
  Object.assign(item, proposal.proposed);
194
194
  if (item.status === "open") {
195
195
  item.status = "backlog";
196
196
  item.readyAt = now;
197
197
  }
198
198
  } else {
199
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !!_optionalChain([command, 'access', _32 => _32.reason, 'optionalAccess', _33 => _33.trim, 'call', _34 => _34()]), "AMENDMENT_REASON_REQUIRED");
200
- _chunk4KF7KUAIcjs.text.call(void 0, command.reason);
199
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !!_optionalChain([command, 'access', _37 => _37.reason, 'optionalAccess', _38 => _38.trim, 'call', _39 => _39()]), "AMENDMENT_REASON_REQUIRED");
200
+ _chunkRBOER6EWcjs.text.call(void 0, command.reason);
201
201
  }
202
202
  proposal.status = command.accept ? "accepted" : "rejected";
203
203
  proposal.reviewedAt = now;
204
- proposal.reviewedBy = _chunk4KF7KUAIcjs.principal.call(void 0, actor);
204
+ proposal.reviewedBy = _chunkRBOER6EWcjs.principal.call(void 0, actor);
205
205
  proposal.reason = command.reason;
206
206
  item.updatedAt = now;
207
207
  item.revision++;
@@ -209,30 +209,46 @@ function reviewAmendment(board, command, actor, now) {
209
209
 
210
210
  // src/project-records.ts
211
211
  function isRecordCommand(command) {
212
- return ["append-record", "review-record", "link-record"].includes(command.type);
212
+ return ["append-record", "review-record", "link-record", "request-record-cancellation", "cancel-record", "delete-record"].includes(command.type);
213
213
  }
214
214
  function applyRecord(state, command, actor, now, forceDraft = false) {
215
215
  if (command.type === "append-record") {
216
216
  append(state, command, actor, now, forceDraft);
217
217
  return;
218
218
  }
219
- const record = _optionalChain([state, 'access', _35 => _35.records, 'optionalAccess', _36 => _36.find, 'call', _37 => _37((record2) => record2.id === command.recordId)]);
220
- _chunk4KF7KUAIcjs.requireValue.call(void 0, record, "RECORD_NOT_FOUND");
221
- if (command.type === "link-record") {
219
+ const record = _optionalChain([state, 'access', _40 => _40.records, 'optionalAccess', _41 => _41.find, 'call', _42 => _42((record2) => record2.id === command.recordId)]);
220
+ _chunkRBOER6EWcjs.requireValue.call(void 0, record, "RECORD_NOT_FOUND");
221
+ _chunkRBOER6EWcjs.requireValue.call(void 0, record.deletedAt === void 0, "RECORD_DELETED");
222
+ if (command.type === "request-record-cancellation" || command.type === "cancel-record" || command.type === "delete-record") {
223
+ requireReviewer(state.board, actor);
224
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _chunkRBOER6EWcjs.principal.call(void 0, actor).kind === "human", "FORBIDDEN");
225
+ _chunkRBOER6EWcjs.requireValue.call(void 0, record.kind === "decision", "DECISION_REQUIRED");
226
+ if (command.type !== "request-record-cancellation") _chunkRBOER6EWcjs.requireValue.call(void 0, record.itemIds.every((id) => {
227
+ const item = _nullishCoalesce(state.board.items.find((i) => i.id === id), () => ( _optionalChain([state, 'access', _43 => _43.archiveIndex, 'optionalAccess', _44 => _44.find, 'call', _45 => _45((i) => i.id === id)])));
228
+ return item && ["completed", "cancelled"].includes(item.status);
229
+ }), "RECORD_EXECUTION_UNSETTLED");
230
+ if (command.type === "request-record-cancellation") record.status = record.status === "cancelled" ? "cancelled" : "cancelling";
231
+ else if (command.type === "cancel-record") record.status = "cancelled";
232
+ else {
233
+ _chunkRBOER6EWcjs.requireValue.call(void 0, ["cancelled", "rejected", "superseded"].includes(record.status), "RECORD_CANCEL_REQUIRED");
234
+ record.deletedAt = now;
235
+ }
236
+ } else if (command.type === "link-record") {
237
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !["cancelling", "cancelled"].includes(record.status), "RECORD_CANCELLING");
222
238
  validateItems(state, [command.itemId]);
223
239
  if (!record.itemIds.includes(command.itemId)) {
224
- _chunk4KF7KUAIcjs.requireValue.call(void 0, record.itemIds.length < 100, "RECORD_LINK_LIMIT");
240
+ _chunkRBOER6EWcjs.requireValue.call(void 0, record.itemIds.length < 100, "RECORD_LINK_LIMIT");
225
241
  record.itemIds.push(command.itemId);
226
242
  }
227
243
  } else {
228
244
  requireReviewer(state.board, actor);
229
- _chunk4KF7KUAIcjs.requireValue.call(void 0, record.status === "draft", "RECORD_NOT_DRAFT");
245
+ _chunkRBOER6EWcjs.requireValue.call(void 0, record.status === "draft", "RECORD_NOT_DRAFT");
230
246
  if (command.accept) {
231
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _chunk4KF7KUAIcjs.principal.call(void 0, actor).kind === "human" || _chunk4KF7KUAIcjs.principalKey.call(void 0, record.author) !== _chunk4KF7KUAIcjs.principalKey.call(void 0, _chunk4KF7KUAIcjs.principal.call(void 0, actor)), "INDEPENDENT_REVIEW_REQUIRED");
247
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _chunkRBOER6EWcjs.principal.call(void 0, actor).kind === "human" || _chunkRBOER6EWcjs.principalKey.call(void 0, record.author) !== _chunkRBOER6EWcjs.principalKey.call(void 0, _chunkRBOER6EWcjs.principal.call(void 0, actor)), "INDEPENDENT_REVIEW_REQUIRED");
232
248
  supersede(state, record, now);
233
249
  record.status = "confirmed";
234
250
  } else record.status = "rejected";
235
- record.reviewedBy = _chunk4KF7KUAIcjs.principal.call(void 0, actor);
251
+ record.reviewedBy = _chunkRBOER6EWcjs.principal.call(void 0, actor);
236
252
  }
237
253
  record.updatedAt = now;
238
254
  record.revision++;
@@ -241,23 +257,23 @@ function append(state, command, actor, now, forceDraft) {
241
257
  validateSources(command.record.sources);
242
258
  const { id, kind, title, content, rationale, itemIds, sources, supersedes, coordination, externalRefs } = command.record;
243
259
  const input = structuredClone({ id, kind, title, content, rationale, itemIds, sources: sources.map((source) => ({ sessionId: source.sessionId, messageId: source.messageId, revision: source.revision, role: source.role })), supersedes, ...coordination ? { coordination } : {}, ...externalRefs ? { externalRefs } : {} });
244
- _chunk4KF7KUAIcjs.identity.call(void 0, input.id);
245
- _chunk4KF7KUAIcjs.text.call(void 0, input.title);
246
- _chunk4KF7KUAIcjs.text.call(void 0, input.content);
260
+ _chunkRBOER6EWcjs.identity.call(void 0, input.id);
261
+ _chunkRBOER6EWcjs.text.call(void 0, input.title);
262
+ _chunkRBOER6EWcjs.text.call(void 0, input.content);
247
263
  validateRecordReferences(externalRefs);
248
- _chunk4KF7KUAIcjs.requireValue.call(void 0, input.kind === "log" || input.kind === "decision", "INVALID_RECORD_KIND");
249
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !_optionalChain([state, 'access', _38 => _38.records, 'optionalAccess', _39 => _39.some, 'call', _40 => _40((record) => record.id === input.id)]), "RECORD_EXISTS");
250
- _chunk4KF7KUAIcjs.requireValue.call(void 0, (_nullishCoalesce(_optionalChain([state, 'access', _41 => _41.records, 'optionalAccess', _42 => _42.length]), () => ( 0))) < 200, "RECORD_LIMIT");
264
+ _chunkRBOER6EWcjs.requireValue.call(void 0, input.kind === "log" || input.kind === "decision", "INVALID_RECORD_KIND");
265
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !_optionalChain([state, 'access', _46 => _46.records, 'optionalAccess', _47 => _47.some, 'call', _48 => _48((record) => record.id === input.id)]), "RECORD_EXISTS");
266
+ _chunkRBOER6EWcjs.requireValue.call(void 0, (_nullishCoalesce(_optionalChain([state, 'access', _49 => _49.records, 'optionalAccess', _50 => _50.length]), () => ( 0))) < 200, "RECORD_LIMIT");
251
267
  validateItems(state, input.itemIds);
252
268
  validateSources(input.sources);
253
- if (input.rationale !== void 0) _chunk4KF7KUAIcjs.text.call(void 0, input.rationale);
254
- if (input.kind === "decision") _chunk4KF7KUAIcjs.text.call(void 0, _nullishCoalesce(input.rationale, () => ( "")));
269
+ if (input.rationale !== void 0) _chunkRBOER6EWcjs.text.call(void 0, input.rationale);
270
+ if (input.kind === "decision") _chunkRBOER6EWcjs.text.call(void 0, _nullishCoalesce(input.rationale, () => ( "")));
255
271
  if (coordination) validateCoordination(state, input);
256
272
  if (input.supersedes) {
257
- _chunk4KF7KUAIcjs.identity.call(void 0, input.supersedes);
258
- _chunk4KF7KUAIcjs.requireValue.call(void 0, input.kind === "decision" && input.supersedes !== input.id && _optionalChain([state, 'access', _43 => _43.records, 'optionalAccess', _44 => _44.some, 'call', _45 => _45((record) => record.id === input.supersedes && record.kind === "decision" && record.status === "confirmed")]), "INVALID_SUPERSEDED_RECORD");
273
+ _chunkRBOER6EWcjs.identity.call(void 0, input.supersedes);
274
+ _chunkRBOER6EWcjs.requireValue.call(void 0, input.kind === "decision" && input.supersedes !== input.id && _optionalChain([state, 'access', _51 => _51.records, 'optionalAccess', _52 => _52.some, 'call', _53 => _53((record) => record.id === input.supersedes && record.kind === "decision" && record.status === "confirmed")]), "INVALID_SUPERSEDED_RECORD");
259
275
  }
260
- const author = _chunk4KF7KUAIcjs.principal.call(void 0, actor), manual = author.kind === "human" && !forceDraft;
276
+ const author = _chunkRBOER6EWcjs.principal.call(void 0, actor), manual = author.kind === "human" && !forceDraft;
261
277
  (state.records ??= []).push({
262
278
  ...input,
263
279
  author,
@@ -269,26 +285,26 @@ function append(state, command, actor, now, forceDraft) {
269
285
  });
270
286
  }
271
287
  function validateCoordination(state, input) {
272
- _chunk4KF7KUAIcjs.requireValue.call(void 0, input.kind === "decision", "DECISION_COORDINATION_ONLY");
288
+ _chunkRBOER6EWcjs.requireValue.call(void 0, input.kind === "decision", "DECISION_COORDINATION_ONLY");
273
289
  for (const owner of [input.coordination.manager, input.coordination.executor].filter(Boolean)) {
274
- _chunk4KF7KUAIcjs.requireValue.call(void 0, owner && ["agent", "human", "service"].includes(owner.kind), "INVALID_PRINCIPAL");
275
- _chunk4KF7KUAIcjs.identity.call(void 0, owner.id);
276
- const member = _optionalChain([state, 'access', _46 => _46.board, 'access', _47 => _47.members, 'optionalAccess', _48 => _48.find, 'call', _49 => _49((member2) => _chunk4KF7KUAIcjs.principalKey.call(void 0, member2) === _chunk4KF7KUAIcjs.principalKey.call(void 0, owner))]);
277
- _chunk4KF7KUAIcjs.requireValue.call(void 0, member, "ASSIGNEE_NOT_REGISTERED");
278
- if (owner === input.coordination.manager) _chunk4KF7KUAIcjs.requireValue.call(void 0, _optionalChain([member, 'access', _50 => _50.roles, 'optionalAccess', _51 => _51.includes, 'call', _52 => _52("coordinator")]), "COORDINATOR_REQUIRED");
290
+ _chunkRBOER6EWcjs.requireValue.call(void 0, owner && ["agent", "human", "service"].includes(owner.kind), "INVALID_PRINCIPAL");
291
+ _chunkRBOER6EWcjs.identity.call(void 0, owner.id);
292
+ const member = _optionalChain([state, 'access', _54 => _54.board, 'access', _55 => _55.members, 'optionalAccess', _56 => _56.find, 'call', _57 => _57((member2) => _chunkRBOER6EWcjs.principalKey.call(void 0, member2) === _chunkRBOER6EWcjs.principalKey.call(void 0, owner))]);
293
+ _chunkRBOER6EWcjs.requireValue.call(void 0, member, "ASSIGNEE_NOT_REGISTERED");
294
+ if (owner === input.coordination.manager) _chunkRBOER6EWcjs.requireValue.call(void 0, _optionalChain([member, 'access', _58 => _58.roles, 'optionalAccess', _59 => _59.includes, 'call', _60 => _60("coordinator")]), "COORDINATOR_REQUIRED");
279
295
  }
280
296
  }
281
297
  function validateItems(state, ids) {
282
- _chunk4KF7KUAIcjs.requireValue.call(void 0, Array.isArray(ids) && ids.length <= 100 && new Set(ids).size === ids.length, "RECORD_LINK_LIMIT");
298
+ _chunkRBOER6EWcjs.requireValue.call(void 0, Array.isArray(ids) && ids.length <= 100 && new Set(ids).size === ids.length, "RECORD_LINK_LIMIT");
283
299
  for (const id of ids) {
284
- _chunk4KF7KUAIcjs.identity.call(void 0, id);
285
- _chunk4KF7KUAIcjs.requireValue.call(void 0, state.board.items.some((item) => item.id === id) || _optionalChain([state, 'access', _53 => _53.archiveIndex, 'optionalAccess', _54 => _54.some, 'call', _55 => _55((item) => item.id === id)]), "ITEM_NOT_FOUND");
300
+ _chunkRBOER6EWcjs.identity.call(void 0, id);
301
+ _chunkRBOER6EWcjs.requireValue.call(void 0, state.board.items.some((item) => item.id === id) || _optionalChain([state, 'access', _61 => _61.archiveIndex, 'optionalAccess', _62 => _62.some, 'call', _63 => _63((item) => item.id === id)]), "ITEM_NOT_FOUND");
286
302
  }
287
303
  }
288
304
  function supersede(state, record, now) {
289
305
  if (!record.supersedes) return;
290
- const previous = _optionalChain([state, 'access', _56 => _56.records, 'optionalAccess', _57 => _57.find, 'call', _58 => _58((entry) => entry.id === record.supersedes)]);
291
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _optionalChain([previous, 'optionalAccess', _59 => _59.kind]) === "decision" && previous.status === "confirmed", "SUPERSEDED_RECORD_CHANGED");
306
+ const previous = _optionalChain([state, 'access', _64 => _64.records, 'optionalAccess', _65 => _65.find, 'call', _66 => _66((entry) => entry.id === record.supersedes)]);
307
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _optionalChain([previous, 'optionalAccess', _67 => _67.kind]) === "decision" && previous.status === "confirmed", "SUPERSEDED_RECORD_CHANGED");
292
308
  previous.status = "superseded";
293
309
  previous.supersededBy = record.id;
294
310
  previous.revision++;
@@ -296,30 +312,30 @@ function supersede(state, record, now) {
296
312
  }
297
313
  function queryRecords(state, query = {}, summaries = (_nullishCoalesce(state.records, () => ( []))).map(recordSummary)) {
298
314
  const { cursor, ...filter } = query, limit = _nullishCoalesce(query.limit, () => ( 50));
299
- _chunk4KF7KUAIcjs.requireValue.call(void 0, Number.isSafeInteger(limit) && limit > 0 && limit <= 200, "INVALID_LIMIT");
300
- if (query.kind) _chunk4KF7KUAIcjs.requireValue.call(void 0, ["log", "decision"].includes(query.kind), "INVALID_RECORD_KIND");
301
- if (query.itemId !== void 0) _chunk4KF7KUAIcjs.identity.call(void 0, query.itemId);
302
- if (query.status) _chunk4KF7KUAIcjs.requireValue.call(void 0, ["draft", "confirmed", "rejected", "superseded"].includes(query.status), "INVALID_RECORD_STATUS");
303
- const digest = _chunk6MN3H3YFcjs.sha256HexSync.call(void 0, JSON.stringify(filter));
315
+ _chunkRBOER6EWcjs.requireValue.call(void 0, Number.isSafeInteger(limit) && limit > 0 && limit <= 200, "INVALID_LIMIT");
316
+ if (query.kind) _chunkRBOER6EWcjs.requireValue.call(void 0, ["log", "decision"].includes(query.kind), "INVALID_RECORD_KIND");
317
+ if (query.itemId !== void 0) _chunkRBOER6EWcjs.identity.call(void 0, query.itemId);
318
+ if (query.status) _chunkRBOER6EWcjs.requireValue.call(void 0, ["draft", "confirmed", "rejected", "superseded", "cancelling", "cancelled"].includes(query.status), "INVALID_RECORD_STATUS");
319
+ const digest = _chunkRSH6QSECcjs.sha256HexSync.call(void 0, JSON.stringify(filter));
304
320
  let offset = 0;
305
321
  if (cursor) {
306
322
  let decoded;
307
323
  try {
308
324
  decoded = JSON.parse(decodeURIComponent(cursor));
309
325
  } catch (e) {
310
- _chunk4KF7KUAIcjs.requireValue.call(void 0, false, "INVALID_CURSOR");
326
+ _chunkRBOER6EWcjs.requireValue.call(void 0, false, "INVALID_CURSOR");
311
327
  }
312
- _chunk4KF7KUAIcjs.requireValue.call(void 0, decoded && typeof decoded === "object" && !Array.isArray(decoded) && typeof decoded.filter === "string" && typeof decoded.revision === "number", "INVALID_CURSOR");
313
- _chunk4KF7KUAIcjs.requireValue.call(void 0, decoded.revision === state.board.revision && decoded.filter === digest, "CURSOR_STALE");
328
+ _chunkRBOER6EWcjs.requireValue.call(void 0, decoded && typeof decoded === "object" && !Array.isArray(decoded) && typeof decoded.filter === "string" && typeof decoded.revision === "number", "INVALID_CURSOR");
329
+ _chunkRBOER6EWcjs.requireValue.call(void 0, decoded.revision === state.board.revision && decoded.filter === digest, "CURSOR_STALE");
314
330
  offset = decoded.offset;
315
- _chunk4KF7KUAIcjs.requireValue.call(void 0, Number.isSafeInteger(offset) && offset >= 0, "INVALID_CURSOR");
331
+ _chunkRBOER6EWcjs.requireValue.call(void 0, Number.isSafeInteger(offset) && offset >= 0, "INVALID_CURSOR");
316
332
  }
317
- const matched = summaries.filter((record) => (!query.kind || query.kind === record.kind) && (!query.itemId || record.itemIds.includes(query.itemId)) && (!query.status || query.status === record.status)).sort((a, b) => b.createdAt - a.createdAt || a.id.localeCompare(b.id));
333
+ const matched = summaries.filter((record) => (query.includeDeleted || record.deletedAt === void 0) && (!query.kind || query.kind === record.kind) && (!query.itemId || record.itemIds.includes(query.itemId)) && (!query.status || query.status === record.status)).sort((a, b) => b.createdAt - a.createdAt || a.id.localeCompare(b.id));
318
334
  const items = matched.slice(offset, offset + limit);
319
335
  return { revision: state.board.revision, total: matched.length, items, ...offset + limit < matched.length ? { nextCursor: encodeURIComponent(JSON.stringify({ revision: state.board.revision, filter: digest, offset: offset + limit })) } : {} };
320
336
  }
321
337
  function recordFingerprint(record) {
322
- return _chunk6MN3H3YFcjs.sha256HexSync.call(void 0, JSON.stringify({
338
+ return _chunkRSH6QSECcjs.sha256HexSync.call(void 0, JSON.stringify({
323
339
  kind: record.kind,
324
340
  title: record.title,
325
341
  content: record.content,
@@ -332,15 +348,15 @@ function recordFingerprint(record) {
332
348
  }
333
349
  function validateRecordReferences(refs) {
334
350
  if (refs === void 0) return;
335
- _chunk4KF7KUAIcjs.requireValue.call(void 0, Array.isArray(refs) && refs.length <= 100, "REFERENCE_LIMIT");
351
+ _chunkRBOER6EWcjs.requireValue.call(void 0, Array.isArray(refs) && refs.length <= 100, "REFERENCE_LIMIT");
336
352
  const keys = /* @__PURE__ */ new Set();
337
353
  for (const ref of refs) {
338
- _chunk4KF7KUAIcjs.requireValue.call(void 0, ref && typeof ref === "object", "INVALID_REFERENCE");
339
- _chunk4KF7KUAIcjs.identity.call(void 0, ref.system);
340
- _chunk4KF7KUAIcjs.identity.call(void 0, ref.id);
341
- if (ref.revision !== void 0) _chunk4KF7KUAIcjs.text.call(void 0, ref.revision);
354
+ _chunkRBOER6EWcjs.requireValue.call(void 0, ref && typeof ref === "object", "INVALID_REFERENCE");
355
+ _chunkRBOER6EWcjs.identity.call(void 0, ref.system);
356
+ _chunkRBOER6EWcjs.identity.call(void 0, ref.id);
357
+ if (ref.revision !== void 0) _chunkRBOER6EWcjs.text.call(void 0, ref.revision);
342
358
  const key = JSON.stringify([ref.system, ref.id]);
343
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !keys.has(key), "DUPLICATE_REFERENCE");
359
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !keys.has(key), "DUPLICATE_REFERENCE");
344
360
  keys.add(key);
345
361
  }
346
362
  }
@@ -351,10 +367,10 @@ function recordSummary(record) {
351
367
 
352
368
  // src/board.ts
353
369
  function createBoardState(input, actor, now) {
354
- const board = { ...structuredClone(input), policy: _chunk4KF7KUAIcjs.policy.call(void 0, input.policy), revision: 1, items: [], participants: [] };
355
- _chunk4KF7KUAIcjs.validateBoard.call(void 0, board);
356
- if (actor.sessionId) _chunk4KF7KUAIcjs.participant.call(void 0, board.participants, actor.sessionId, actor.agentId, "creator", true, now);
357
- for (const session of board.policy.escalationSessionIds) _chunk4KF7KUAIcjs.participant.call(void 0, board.participants, session, void 0, "escalation", true, now);
370
+ const board = { ...structuredClone(input), policy: _chunkRBOER6EWcjs.policy.call(void 0, input.policy), revision: 1, items: [], participants: [] };
371
+ _chunkRBOER6EWcjs.validateBoard.call(void 0, board);
372
+ if (actor.sessionId) _chunkRBOER6EWcjs.participant.call(void 0, board.participants, actor.sessionId, actor.agentId, "creator", true, now);
373
+ for (const session of board.policy.escalationSessionIds) _chunkRBOER6EWcjs.participant.call(void 0, board.participants, session, void 0, "escalation", true, now);
358
374
  return { schema: 1, board, sequence: 0, events: [], escalations: [] };
359
375
  }
360
376
 
@@ -366,7 +382,7 @@ function rowKeys(raw) {
366
382
  if (raw === null) return [];
367
383
  const saved = JSON.parse(raw);
368
384
  if (saved.layout !== 2) return [];
369
- _chunk4KF7KUAIcjs.requireValue.call(void 0, Array.isArray(saved.itemIds) && Array.isArray(saved.recordIds) && _optionalChain([saved, 'access', _60 => _60.state, 'optionalAccess', _61 => _61.board]), "INVALID_STORAGE");
385
+ _chunkRBOER6EWcjs.requireValue.call(void 0, Array.isArray(saved.itemIds) && Array.isArray(saved.recordIds) && _optionalChain([saved, 'access', _68 => _68.state, 'optionalAccess', _69 => _69.board]), "INVALID_STORAGE");
370
386
  return [...saved.itemIds.map((id) => rowKey("item", saved.state.board.id, id)), ...saved.recordIds.map((id) => rowKey("record", saved.state.board.id, id))];
371
387
  }
372
388
  async function hydrate(saved, bodies) {
@@ -376,12 +392,12 @@ async function hydrate(saved, bodies) {
376
392
  const state = validateState(parsed.state), id = state.board.id;
377
393
  state.board.items = await Promise.all(parsed.itemIds.map(async (itemId) => {
378
394
  const item = await decodeRow(requiredRow(saved, rowKey("item", id, itemId)), bodies);
379
- _chunk4KF7KUAIcjs.requireValue.call(void 0, item.id === itemId, "INVALID_STORAGE");
395
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item.id === itemId, "INVALID_STORAGE");
380
396
  return item;
381
397
  }));
382
398
  state.records = await Promise.all(parsed.recordIds.map(async (recordId) => {
383
399
  const record = await decodeRow(requiredRow(saved, rowKey("record", id, recordId)), bodies);
384
- _chunk4KF7KUAIcjs.requireValue.call(void 0, record.id === recordId, "INVALID_STORAGE");
400
+ _chunkRBOER6EWcjs.requireValue.call(void 0, record.id === recordId, "INVALID_STORAGE");
385
401
  return record;
386
402
  }));
387
403
  return state;
@@ -394,7 +410,7 @@ async function encodeBoard(state, bodies) {
394
410
  itemIndex: state.board.items.map(summary),
395
411
  recordIndex: (_nullishCoalesce(state.records, () => ( []))).map(recordSummary),
396
412
  layout: 2,
397
- generation: _chunk6MN3H3YFcjs.randomUUID.call(void 0, ),
413
+ generation: _chunkRSH6QSECcjs.randomUUID.call(void 0, ),
398
414
  state: { ...state, board: { ...state.board, items: [] }, records: [] },
399
415
  itemIds: state.board.items.map((item) => item.id),
400
416
  recordIds: (_nullishCoalesce(state.records, () => ( []))).map((record) => record.id)
@@ -407,15 +423,15 @@ function rowChanges(before, after) {
407
423
  return writes;
408
424
  }
409
425
  function receiptDigest(fingerprint) {
410
- return `sha256:v1:${_chunk6MN3H3YFcjs.sha256HexSync.call(void 0, fingerprint)}`;
426
+ return `sha256:v1:${_chunkRSH6QSECcjs.sha256HexSync.call(void 0, fingerprint)}`;
411
427
  }
412
428
  function verifyReceipt(saved, fingerprint) {
413
- _chunk4KF7KUAIcjs.requireValue.call(void 0, saved === fingerprint || saved === receiptDigest(fingerprint), "IDEMPOTENCY_CONFLICT");
429
+ _chunkRBOER6EWcjs.requireValue.call(void 0, saved === fingerprint || saved === receiptDigest(fingerprint), "IDEMPOTENCY_CONFLICT");
414
430
  }
415
431
  async function encodeRow(value, bodies) {
416
432
  const raw = JSON.stringify(value), bytes = new TextEncoder().encode(raw);
417
433
  if (!bodies || bytes.length <= 8192) return raw;
418
- const ref = { body: "kanban-body/v1", sha256: _chunk6MN3H3YFcjs.sha256HexSync.call(void 0, bytes), bytes: bytes.length };
434
+ const ref = { body: "kanban-body/v1", sha256: _chunkRSH6QSECcjs.sha256HexSync.call(void 0, bytes), bytes: bytes.length };
419
435
  const existing = await bodies.read(ref.sha256);
420
436
  if (existing !== null) verifyBody(existing, ref);
421
437
  else {
@@ -426,30 +442,30 @@ async function encodeRow(value, bodies) {
426
442
  failure = error;
427
443
  }
428
444
  const confirmed = await bodies.read(ref.sha256);
429
- if (confirmed === null) throw _nullishCoalesce(failure, () => ( new (0, _chunk2YFPV5GFcjs.KanbanError)("BODY_WRITE_UNCONFIRMED")));
445
+ if (confirmed === null) throw _nullishCoalesce(failure, () => ( new (0, _chunkRSH6QSECcjs.KanbanError)("BODY_WRITE_UNCONFIRMED")));
430
446
  verifyBody(confirmed, ref);
431
447
  }
432
448
  return JSON.stringify(ref);
433
449
  }
434
450
  async function decodeRow(raw, bodies) {
435
451
  const parsed = JSON.parse(raw);
436
- if (_optionalChain([parsed, 'optionalAccess', _62 => _62.body]) !== "kanban-body/v1") return parsed;
437
- _chunk4KF7KUAIcjs.requireValue.call(void 0, /^[a-f0-9]{64}$/.test(parsed.sha256) && Number.isSafeInteger(parsed.bytes) && parsed.bytes > 8192, "INVALID_BODY_REFERENCE");
438
- _chunk4KF7KUAIcjs.requireValue.call(void 0, bodies, "BODY_STORE_REQUIRED");
452
+ if (_optionalChain([parsed, 'optionalAccess', _70 => _70.body]) !== "kanban-body/v1") return parsed;
453
+ _chunkRBOER6EWcjs.requireValue.call(void 0, /^[a-f0-9]{64}$/.test(parsed.sha256) && Number.isSafeInteger(parsed.bytes) && parsed.bytes > 8192, "INVALID_BODY_REFERENCE");
454
+ _chunkRBOER6EWcjs.requireValue.call(void 0, bodies, "BODY_STORE_REQUIRED");
439
455
  const bytes = await bodies.read(parsed.sha256);
440
- _chunk4KF7KUAIcjs.requireValue.call(void 0, bytes !== null, "BODY_MISSING");
456
+ _chunkRBOER6EWcjs.requireValue.call(void 0, bytes !== null, "BODY_MISSING");
441
457
  verifyBody(bytes, parsed);
442
458
  return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
443
459
  }
444
460
  function verifyBody(bytes, ref) {
445
- _chunk4KF7KUAIcjs.requireValue.call(void 0, bytes instanceof ArrayBuffer && bytes.byteLength === ref.bytes && _chunk6MN3H3YFcjs.sha256HexSync.call(void 0, bytes) === ref.sha256, "BODY_INTEGRITY");
461
+ _chunkRBOER6EWcjs.requireValue.call(void 0, bytes instanceof ArrayBuffer && bytes.byteLength === ref.bytes && _chunkRSH6QSECcjs.sha256HexSync.call(void 0, bytes) === ref.sha256, "BODY_INTEGRITY");
446
462
  }
447
463
  function requiredRow(saved, key) {
448
- _chunk4KF7KUAIcjs.requireValue.call(void 0, typeof saved.rows[key] === "string", "MISSING_STORAGE_ROW");
464
+ _chunkRBOER6EWcjs.requireValue.call(void 0, typeof saved.rows[key] === "string", "MISSING_STORAGE_ROW");
449
465
  return saved.rows[key];
450
466
  }
451
467
  function validateState(state) {
452
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _optionalChain([state, 'optionalAccess', _63 => _63.schema]) === 1 && state.board && Array.isArray(state.board.items) && Array.isArray(state.events), "INVALID_STORAGE");
468
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _optionalChain([state, 'optionalAccess', _71 => _71.schema]) === 1 && state.board && Array.isArray(state.board.items) && Array.isArray(state.events), "INVALID_STORAGE");
453
469
  return state;
454
470
  }
455
471
  function indexedView(raw) {
@@ -467,15 +483,15 @@ function viewFromState(state) {
467
483
  var boardCounterKey = "counter/board";
468
484
  var boardNumberKey = (number) => `reference/board/${number}`;
469
485
  function counter(raw) {
470
- _chunk4KF7KUAIcjs.requireValue.call(void 0, raw === null || /^(0|[1-9]\d*)$/.test(raw), "INVALID_NUMBER_COUNTER");
486
+ _chunkRBOER6EWcjs.requireValue.call(void 0, raw === null || /^(0|[1-9]\d*)$/.test(raw), "INVALID_NUMBER_COUNTER");
471
487
  const value = raw === null ? 0 : Number(raw);
472
- _chunk4KF7KUAIcjs.requireValue.call(void 0, Number.isSafeInteger(value) && value >= 0 && value <= Number.MAX_SAFE_INTEGER, "INVALID_NUMBER_COUNTER");
488
+ _chunkRBOER6EWcjs.requireValue.call(void 0, Number.isSafeInteger(value) && value >= 0 && value <= Number.MAX_SAFE_INTEGER, "INVALID_NUMBER_COUNTER");
473
489
  return value;
474
490
  }
475
491
  function storedBoardNumber(raw) {
476
492
  if (raw === null) return void 0;
477
- const parsed = JSON.parse(raw), number = _optionalChain([(parsed.layout === 2 ? _optionalChain([parsed, 'access', _64 => _64.state, 'optionalAccess', _65 => _65.board]) : parsed.board), 'optionalAccess', _66 => _66.number]);
478
- if (number !== void 0) _chunk4KF7KUAIcjs.requireValue.call(void 0, Number.isSafeInteger(number) && number > 0, "INVALID_NUMBERING");
493
+ const parsed = JSON.parse(raw), number = _optionalChain([(parsed.layout === 2 ? _optionalChain([parsed, 'access', _72 => _72.state, 'optionalAccess', _73 => _73.board]) : parsed.board), 'optionalAccess', _74 => _74.number]);
494
+ if (number !== void 0) _chunkRBOER6EWcjs.requireValue.call(void 0, Number.isSafeInteger(number) && number > 0, "INVALID_NUMBERING");
479
495
  return number;
480
496
  }
481
497
  function patchBoardNumber(raw, number) {
@@ -493,14 +509,14 @@ function assign(rows, high) {
493
509
  counter(String(high));
494
510
  const used = /* @__PURE__ */ new Map(), known = /* @__PURE__ */ new Map();
495
511
  for (const row of rows) if (row.number !== void 0) {
496
- _chunk4KF7KUAIcjs.requireValue.call(void 0, Number.isSafeInteger(row.number) && row.number > 0 && (!used.has(row.number) || used.get(row.number) === row.id) && (!known.has(row.id) || known.get(row.id) === row.number), "INVALID_NUMBERING");
512
+ _chunkRBOER6EWcjs.requireValue.call(void 0, Number.isSafeInteger(row.number) && row.number > 0 && (!used.has(row.number) || used.get(row.number) === row.id) && (!known.has(row.id) || known.get(row.id) === row.number), "INVALID_NUMBERING");
497
513
  used.set(row.number, row.id);
498
514
  known.set(row.id, row.number);
499
515
  high = Math.max(high, row.number);
500
516
  }
501
517
  for (const row of rows) if (row.number === void 0) {
502
518
  if (!known.has(row.id)) {
503
- _chunk4KF7KUAIcjs.requireValue.call(void 0, high < Number.MAX_SAFE_INTEGER, "NUMBER_COUNTER_EXHAUSTED");
519
+ _chunkRBOER6EWcjs.requireValue.call(void 0, high < Number.MAX_SAFE_INTEGER, "NUMBER_COUNTER_EXHAUSTED");
504
520
  known.set(row.id, ++high);
505
521
  }
506
522
  row.number = known.get(row.id);
@@ -510,16 +526,103 @@ function assign(rows, high) {
510
526
  function allocateBoardNumber(raw, high) {
511
527
  const known = storedBoardNumber(raw);
512
528
  if (known !== void 0) return known;
513
- _chunk4KF7KUAIcjs.requireValue.call(void 0, high < Number.MAX_SAFE_INTEGER, "NUMBER_COUNTER_EXHAUSTED");
529
+ _chunkRBOER6EWcjs.requireValue.call(void 0, high < Number.MAX_SAFE_INTEGER, "NUMBER_COUNTER_EXHAUSTED");
514
530
  return high + 1;
515
531
  }
516
532
 
533
+ // src/workflow-plans.ts
534
+ function requireCoordinator(state, actor) {
535
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _optionalChain([state, 'access', _75 => _75.board, 'access', _76 => _76.members, 'optionalAccess', _77 => _77.some, 'call', _78 => _78((member) => _chunkRBOER6EWcjs.principalKey.call(void 0, member) === _chunkRBOER6EWcjs.principalKey.call(void 0, _chunkRBOER6EWcjs.principal.call(void 0, actor)) && _optionalChain([member, 'access', _79 => _79.roles, 'optionalAccess', _80 => _80.includes, 'call', _81 => _81("coordinator")]))]), "COORDINATOR_REQUIRED");
536
+ }
537
+ function publishPlan(state, plan2, actor, apply) {
538
+ requireCoordinator(state, actor);
539
+ _chunkRBOER6EWcjs.requireValue.call(void 0, plan2 && typeof plan2 === "object", "INVALID_WORK_PLAN");
540
+ _chunkRBOER6EWcjs.identity.call(void 0, plan2.id);
541
+ _chunkRBOER6EWcjs.requireValue.call(void 0, plan2.schema === "kanban.plan/1" && typeof plan2.sealed === "boolean" && Array.isArray(plan2.items) && plan2.items.length > 0 && plan2.items.length <= 100, "INVALID_WORK_PLAN");
542
+ const workflow = state.workflow, previous = workflow.plans[plan2.id];
543
+ _chunkRBOER6EWcjs.requireValue.call(void 0, Number.isSafeInteger(plan2.revision) && plan2.revision === (_nullishCoalesce(_optionalChain([previous, 'optionalAccess', _82 => _82.revision]), () => ( 0))) + 1, "PLAN_REVISION_CONFLICT");
544
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !Object.values(workflow.dispatches).some((dispatch) => dispatch.planId === plan2.id && ["prepared", "running", "unknown", "succeeded"].includes(dispatch.outcome)), "PLAN_EXECUTION_UNSETTLED");
545
+ if (plan2.decisionId) {
546
+ const decision = _optionalChain([state, 'access', _83 => _83.records, 'optionalAccess', _84 => _84.find, 'call', _85 => _85((record) => record.id === plan2.decisionId && record.kind === "decision" && record.status === "confirmed")]);
547
+ _chunkRBOER6EWcjs.requireValue.call(void 0, decision, "DECISION_NOT_CONFIRMED");
548
+ if (decision.coordination) _chunkRBOER6EWcjs.requireValue.call(void 0, _chunkRBOER6EWcjs.principalKey.call(void 0, decision.coordination.manager) === _chunkRBOER6EWcjs.principalKey.call(void 0, _chunkRBOER6EWcjs.principal.call(void 0, actor)), "DECISION_MANAGER_REQUIRED");
549
+ }
550
+ if (plan2.rootItemId) {
551
+ const root = state.board.items.find((item) => item.id === plan2.rootItemId);
552
+ _chunkRBOER6EWcjs.requireValue.call(void 0, root && !root.owner && ["backlog", "open"].includes(root.status), "PLAN_ROOT_UNAVAILABLE");
553
+ if (_optionalChain([root, 'access', _86 => _86.planning, 'optionalAccess', _87 => _87.execution]) !== "children") apply({ type: "plan-item", itemId: root.id, planning: { ...plan(root), execution: "children" } });
554
+ }
555
+ const ordered = orderWork(plan2.items, state), definitions = {};
556
+ for (const item of ordered) {
557
+ const digest = _chunkRSH6QSECcjs.sha256HexSync.call(void 0, JSON.stringify(item));
558
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !Object.values(workflow.plans).some((other) => other.id !== plan2.id && other.itemIds.includes(item.id)), "ITEM_IN_OTHER_PLAN");
559
+ const exists = state.board.items.some((old) => old.id === item.id) || _optionalChain([state, 'access', _88 => _88.archiveIndex, 'optionalAccess', _89 => _89.some, 'call', _90 => _90((old) => old.id === item.id)]);
560
+ if (exists && _optionalChain([previous, 'optionalAccess', _91 => _91.definitions, 'access', _92 => _92[item.id], 'optionalAccess', _93 => _93.digest]) !== digest) {
561
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !_optionalChain([previous, 'optionalAccess', _94 => _94.definitions, 'access', _95 => _95[item.id]]), "PLAN_ITEM_CHANGED_REQUIRES_NEW_ID");
562
+ adoptItem(state, item, apply);
563
+ }
564
+ if (!exists) apply({
565
+ type: "create-item",
566
+ item: { id: item.id, title: item.title, responsibility: item.responsibility, acceptance: item.acceptance, eligiblePrincipals: [item.assignee], externalRefs: item.externalRefs },
567
+ planning: { kind: _nullishCoalesce(_nullishCoalesce(item.workType, () => ( state.board.defaultWorkType)), () => ( "task")), priority: 2, dependencies: item.dependsOn, references: [], ...plan2.rootItemId ? { parentId: plan2.rootItemId } : {} }
568
+ });
569
+ definitions[item.id] = { digest, inputs: item.inputs, outputs: _nullishCoalesce(item.outputs, () => ( [])) };
570
+ }
571
+ workflow.plans[plan2.id] = { schema: plan2.schema, id: plan2.id, revision: plan2.revision, decisionId: plan2.decisionId, rootItemId: plan2.rootItemId, sealed: plan2.sealed, itemIds: ordered.map((item) => item.id), definitions };
572
+ }
573
+ function adoptItem(state, definition, apply) {
574
+ const item = state.board.items.find((item2) => item2.id === definition.id);
575
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item && definition.expectedRevision === item.revision && ["backlog", "open"].includes(item.status) && !item.owner && !item.blocked && (!item.control || item.control.action === "resume" && item.control.state === "resumed"), "PLAN_ITEM_CHANGED_REQUIRES_NEW_ID");
576
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !definition.workType || definition.workType === _optionalChain([item, 'access', _96 => _96.planning, 'optionalAccess', _97 => _97.kind]), "PLAN_ITEM_CHANGED_REQUIRES_NEW_ID");
577
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !definition.externalRefs || definition.externalRefs.every((ref) => _optionalChain([item, 'access', _98 => _98.externalRefs, 'optionalAccess', _99 => _99.some, 'call', _100 => _100((existing) => JSON.stringify(existing) === JSON.stringify(ref))])), "PLAN_RESOURCE_MISMATCH");
578
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item.title === definition.title && item.responsibility === definition.responsibility && item.acceptance === definition.acceptance, "PLAN_ITEM_CHANGED_REQUIRES_NEW_ID");
579
+ _chunkRBOER6EWcjs.requireValue.call(void 0, plan(item).dependencies.every((id) => definition.dependsOn.includes(id)), "EXISTING_DEPENDENCY_REQUIRED");
580
+ apply({ type: "plan-item", itemId: item.id, planning: { ...plan(item), dependencies: definition.dependsOn } });
581
+ item.eligiblePrincipals = [definition.assignee];
582
+ delete item.eligibleAgentIds;
583
+ _chunkRBOER6EWcjs.validateCandidates.call(void 0, state.board, item, true);
584
+ }
585
+ function orderWork(items, state) {
586
+ for (const item of items) validateDefinition(item);
587
+ const ids = new Set(items.map((item) => item.id));
588
+ _chunkRBOER6EWcjs.requireValue.call(void 0, ids.size === items.length, "DUPLICATE_PLAN_ITEM");
589
+ for (const item of items) {
590
+ _chunkRBOER6EWcjs.identity.call(void 0, item.id);
591
+ _chunkRBOER6EWcjs.requireValue.call(void 0, Array.isArray(item.dependsOn) && item.dependsOn.length <= 100 && new Set(item.dependsOn).size === item.dependsOn.length, "INVALID_DEPENDENCIES");
592
+ _chunkRBOER6EWcjs.requireValue.call(void 0, Object.keys(_nullishCoalesce(item.inputs, () => ( {}))).length <= 100 && Array.isArray(_nullishCoalesce(item.outputs, () => ( []))) && (_nullishCoalesce(item.outputs, () => ( []))).length <= 100 && new Set(_nullishCoalesce(item.outputs, () => ( []))).size === (_nullishCoalesce(item.outputs, () => ( []))).length, "PLAN_BINDING_LIMIT");
593
+ for (const name of [...Object.keys(_nullishCoalesce(item.inputs, () => ( {}))), ..._nullishCoalesce(item.outputs, () => ( []))]) _chunkRBOER6EWcjs.requireValue.call(void 0, /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/.test(name), "INVALID_OUTPUT_NAME");
594
+ for (const binding of Object.values(_nullishCoalesce(item.inputs, () => ( {})))) {
595
+ _chunkRBOER6EWcjs.requireValue.call(void 0, binding && item.dependsOn.includes(binding.fromItemId) && typeof binding.output === "string", "INPUT_DEPENDENCY_REQUIRED");
596
+ const producer = items.find((other) => other.id === binding.fromItemId), existing = Object.values(state.workflow.dispatches).some((dispatch) => dispatch.itemId === binding.fromItemId && dispatch.outcome === "accepted" && _optionalChain([dispatch, 'access', _101 => _101.outputs, 'optionalAccess', _102 => _102.some, 'call', _103 => _103((output) => output.name === binding.output)]));
597
+ _chunkRBOER6EWcjs.requireValue.call(void 0, producer ? _optionalChain([producer, 'access', _104 => _104.outputs, 'optionalAccess', _105 => _105.includes, 'call', _106 => _106(binding.output)]) : existing, "OUTPUT_NOT_DECLARED");
598
+ }
599
+ for (const dependency of item.dependsOn) _chunkRBOER6EWcjs.requireValue.call(void 0, ids.has(dependency) || [...state.board.items, ..._nullishCoalesce(state.archiveIndex, () => ( []))].some((old) => old.id === dependency), "DEPENDENCY_NOT_FOUND");
600
+ }
601
+ const ordered = [], remaining = [...items], done = /* @__PURE__ */ new Set();
602
+ while (remaining.length) {
603
+ const next = remaining.findIndex((item2) => item2.dependsOn.every((id) => !ids.has(id) || done.has(id)));
604
+ _chunkRBOER6EWcjs.requireValue.call(void 0, next >= 0, "DEPENDENCY_CYCLE");
605
+ const [item] = remaining.splice(next, 1);
606
+ ordered.push(item);
607
+ done.add(item.id);
608
+ }
609
+ return ordered;
610
+ }
611
+ function validateDefinition(item) {
612
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item && typeof item === "object" && !Array.isArray(item), "INVALID_WORK_DEFINITION");
613
+ const assignee = item.assignee;
614
+ _chunkRBOER6EWcjs.requireValue.call(void 0, assignee && ["agent", "human", "service"].includes(assignee.kind), "INVALID_PRINCIPAL");
615
+ _chunkRBOER6EWcjs.identity.call(void 0, assignee.id);
616
+ if (item.inputs !== void 0) _chunkRBOER6EWcjs.requireValue.call(void 0, item.inputs && typeof item.inputs === "object" && !Array.isArray(item.inputs), "INVALID_INPUT_BINDINGS");
617
+ if (item.outputs !== void 0) _chunkRBOER6EWcjs.requireValue.call(void 0, Array.isArray(item.outputs) && item.outputs.every((name) => typeof name === "string"), "INVALID_OUTPUT_NAMES");
618
+ }
619
+
517
620
  // src/archives.ts
518
621
  function archiveItems(state, ids, reason, now) {
519
- _chunk4KF7KUAIcjs.text.call(void 0, reason);
520
- _chunk4KF7KUAIcjs.requireValue.call(void 0, ids.length > 0 && ids.length <= 50 && new Set(ids).size === ids.length, "ARCHIVE_BATCH_LIMIT");
622
+ _chunkRBOER6EWcjs.text.call(void 0, reason);
623
+ _chunkRBOER6EWcjs.requireValue.call(void 0, ids.length > 0 && ids.length <= 50 && new Set(ids).size === ids.length, "ARCHIVE_BATCH_LIMIT");
521
624
  const items = ids.map((id) => state.board.items.find((i) => i.id === id));
522
- _chunk4KF7KUAIcjs.requireValue.call(void 0, items.every((item) => item && terminal(item)), "ARCHIVE_REQUIRES_CLOSED_ITEM");
625
+ _chunkRBOER6EWcjs.requireValue.call(void 0, items.every((item) => item && terminal(item)), "ARCHIVE_REQUIRES_CLOSED_ITEM");
523
626
  for (const item of items) {
524
627
  const archived = { item, archivedAt: now, reason };
525
628
  (state.archiveIndex ??= []).push({ ...summary(item), archivedAt: now, archiveReason: reason });
@@ -530,8 +633,8 @@ function archiveItems(state, ids, reason, now) {
530
633
  }
531
634
  function restoreItem(state, id, now) {
532
635
  const record = state.restore;
533
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _optionalChain([record, 'optionalAccess', _67 => _67.item, 'access', _68 => _68.id]) === id && _optionalChain([state, 'access', _69 => _69.archiveIndex, 'optionalAccess', _70 => _70.some, 'call', _71 => _71((i) => i.id === id)]), "ARCHIVED_ITEM_NOT_FOUND");
534
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !state.board.items.some((i) => i.id === id), "ITEM_EXISTS");
636
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _optionalChain([record, 'optionalAccess', _107 => _107.item, 'access', _108 => _108.id]) === id && _optionalChain([state, 'access', _109 => _109.archiveIndex, 'optionalAccess', _110 => _110.some, 'call', _111 => _111((i) => i.id === id)]), "ARCHIVED_ITEM_NOT_FOUND");
637
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !state.board.items.some((i) => i.id === id), "ITEM_EXISTS");
535
638
  record.item.restoredAt = now;
536
639
  record.item.updatedAt = now;
537
640
  record.item.revision++;
@@ -556,7 +659,7 @@ function applyPlanningCommand(state, command, now, actor, internal = false) {
556
659
  if (command.type === "archive-items") return archiveItems(state, command.itemIds, command.reason, now);
557
660
  if (command.type === "restore-item") return restoreItem(state, command.itemId, now);
558
661
  const item = state.board.items.find((i) => i.id === command.itemId);
559
- _chunk4KF7KUAIcjs.requireValue.call(void 0, item, "ITEM_NOT_FOUND");
662
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item, "ITEM_NOT_FOUND");
560
663
  if (isOperational(command)) operate(item, command, now, actor);
561
664
  else {
562
665
  if (!internal && ["edit-item", "plan-item", "review-amendment"].includes(command.type)) assertDefinitionEditable(item, now);
@@ -568,9 +671,9 @@ function isOperational(command) {
568
671
  }
569
672
  function operate(item, command, now, actor) {
570
673
  if (command.type === "release-item") {
571
- _chunk4KF7KUAIcjs.requireValue.call(void 0, ["claimed", "review"].includes(item.status) && _optionalChain([item, 'access', _72 => _72.owner, 'optionalAccess', _73 => _73.token]) === command.token, "OWNER_MISMATCH");
572
- _chunk4KF7KUAIcjs.requireValue.call(void 0, ["backlog", "cancelled"].includes(command.next), "INVALID_STAGE");
573
- _chunk4KF7KUAIcjs.text.call(void 0, command.reason);
674
+ _chunkRBOER6EWcjs.requireValue.call(void 0, ["claimed", "review"].includes(item.status) && _optionalChain([item, 'access', _112 => _112.owner, 'optionalAccess', _113 => _113.token]) === command.token, "OWNER_MISMATCH");
675
+ _chunkRBOER6EWcjs.requireValue.call(void 0, ["backlog", "cancelled"].includes(command.next), "INVALID_STAGE");
676
+ _chunkRBOER6EWcjs.text.call(void 0, command.reason);
574
677
  item.status = command.next;
575
678
  if (command.next === "cancelled") {
576
679
  item.closedAt = now;
@@ -581,10 +684,10 @@ function operate(item, command, now, actor) {
581
684
  delete item.estimate;
582
685
  } else if (command.type === "link-reference") attachReference(item, command.reference);
583
686
  else {
584
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !terminal(item), "ITEM_COMPLETED");
585
- if (item.status === "claimed") _chunk4KF7KUAIcjs.owned.call(void 0, item, actor, _nullishCoalesce(command.token, () => ( "")), now);
687
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !terminal(item), "ITEM_COMPLETED");
688
+ if (item.status === "claimed") _chunkRBOER6EWcjs.owned.call(void 0, item, actor, _nullishCoalesce(command.token, () => ( "")), now);
586
689
  if (command.type === "block-item") {
587
- _chunk4KF7KUAIcjs.text.call(void 0, command.reason);
690
+ _chunkRBOER6EWcjs.text.call(void 0, command.reason);
588
691
  item.blocked = { reason: command.reason, at: now };
589
692
  } else delete item.blocked;
590
693
  }
@@ -592,17 +695,18 @@ function operate(item, command, now, actor) {
592
695
  item.revision++;
593
696
  }
594
697
  function updatePlan(state, item, command, now) {
595
- if (command.type === "cancel-item") _chunk4KF7KUAIcjs.requireValue.call(void 0, _optionalChain([item, 'access', _74 => _74.launch, 'optionalAccess', _75 => _75.admittedAt]) === void 0, "TASK_CONTROL_REQUIRED");
698
+ if (command.type === "close-plan") _chunkRBOER6EWcjs.requireValue.call(void 0, _optionalChain([item, 'access', _114 => _114.control, 'optionalAccess', _115 => _115.action]) !== "cancel", "TASK_CANCELLING");
699
+ if (command.type === "cancel-item") _chunkRBOER6EWcjs.requireValue.call(void 0, _optionalChain([item, 'access', _116 => _116.launch, 'optionalAccess', _117 => _117.admittedAt]) === void 0, "TASK_CONTROL_REQUIRED");
596
700
  if (command.type === "publish-proposal") {
597
- _chunk4KF7KUAIcjs.requireValue.call(void 0, item.status === "proposed", "NOT_PROPOSED");
701
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item.status === "proposed", "NOT_PROPOSED");
598
702
  return setStage(state, item, _nullishCoalesce(command.stage, () => ( "backlog")), now);
599
703
  }
600
704
  if (command.type === "set-stage") return setStage(state, item, command.stage, now);
601
- _chunk4KF7KUAIcjs.requireValue.call(void 0, ["proposed", "backlog", "open"].includes(item.status), "ITEM_NOT_PLANNABLE");
705
+ _chunkRBOER6EWcjs.requireValue.call(void 0, ["proposed", "backlog", "open"].includes(item.status), "ITEM_NOT_PLANNABLE");
602
706
  if (command.type === "edit-item") {
603
- _chunk4KF7KUAIcjs.text.call(void 0, command.title);
604
- _chunk4KF7KUAIcjs.text.call(void 0, command.responsibility);
605
- _chunk4KF7KUAIcjs.text.call(void 0, command.acceptance);
707
+ _chunkRBOER6EWcjs.text.call(void 0, command.title);
708
+ _chunkRBOER6EWcjs.text.call(void 0, command.responsibility);
709
+ _chunkRBOER6EWcjs.text.call(void 0, command.acceptance);
606
710
  item.title = command.title;
607
711
  item.responsibility = command.responsibility;
608
712
  item.acceptance = command.acceptance;
@@ -612,16 +716,16 @@ function updatePlan(state, item, command, now) {
612
716
  item.planning = command.planning;
613
717
  if (item.status === "open") return setStage(state, item, "backlog", now);
614
718
  } else {
615
- _chunk4KF7KUAIcjs.requireValue.call(void 0, catalog(state).filter((i) => i.planning.parentId === item.id).every(terminal), "CHILDREN_UNFINISHED");
719
+ _chunkRBOER6EWcjs.requireValue.call(void 0, catalog(state).filter((i) => i.planning.parentId === item.id).every(terminal), "CHILDREN_UNFINISHED");
616
720
  if (command.type === "close-plan") {
617
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !_chunk4KF7KUAIcjs.executable.call(void 0, state.board, item), "TASK_REQUIRES_REVIEW");
618
- _chunk4KF7KUAIcjs.text.call(void 0, command.resultRef);
721
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !_chunkRBOER6EWcjs.executable.call(void 0, state.board, item), "TASK_REQUIRES_REVIEW");
722
+ _chunkRBOER6EWcjs.text.call(void 0, command.resultRef);
619
723
  const children = catalog(state).filter((child) => child.planning.parentId === item.id);
620
- if (_optionalChain([item, 'access', _76 => _76.planning, 'optionalAccess', _77 => _77.execution]) === "children") _chunk4KF7KUAIcjs.requireValue.call(void 0, children.length > 0 && children.every((child) => child.status === "completed"), "CHILDREN_UNFINISHED");
724
+ if (_optionalChain([item, 'access', _118 => _118.planning, 'optionalAccess', _119 => _119.execution]) === "children") _chunkRBOER6EWcjs.requireValue.call(void 0, children.length > 0 && children.every((child) => child.status === "completed"), "CHILDREN_UNFINISHED");
621
725
  item.status = "completed";
622
726
  item.resultRef = command.resultRef;
623
727
  } else {
624
- _chunk4KF7KUAIcjs.text.call(void 0, command.reason);
728
+ _chunkRBOER6EWcjs.text.call(void 0, command.reason);
625
729
  item.status = "cancelled";
626
730
  item.closureReason = command.reason;
627
731
  }
@@ -631,119 +735,33 @@ function updatePlan(state, item, command, now) {
631
735
  item.revision++;
632
736
  }
633
737
  function attachReference(item, reference) {
634
- _chunk4KF7KUAIcjs.identity.call(void 0, reference.system);
635
- _chunk4KF7KUAIcjs.identity.call(void 0, reference.id);
636
- if (reference.revision !== void 0) _chunk4KF7KUAIcjs.text.call(void 0, reference.revision);
738
+ _chunkRBOER6EWcjs.identity.call(void 0, reference.system);
739
+ _chunkRBOER6EWcjs.identity.call(void 0, reference.id);
740
+ if (reference.revision !== void 0) _chunkRBOER6EWcjs.text.call(void 0, reference.revision);
637
741
  item.externalRefs ??= [];
638
742
  if (item.externalRefs.some((r) => r.system === reference.system && r.id === reference.id && r.revision === reference.revision)) return;
639
- _chunk4KF7KUAIcjs.requireValue.call(void 0, item.externalRefs.length < 100, "REFERENCE_LIMIT");
743
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item.externalRefs.length < 100, "REFERENCE_LIMIT");
640
744
  item.externalRefs.push(reference);
641
745
  }
642
746
 
643
- // src/workflow-plans.ts
644
- function requireCoordinator(state, actor) {
645
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _optionalChain([state, 'access', _78 => _78.board, 'access', _79 => _79.members, 'optionalAccess', _80 => _80.some, 'call', _81 => _81((member) => _chunk4KF7KUAIcjs.principalKey.call(void 0, member) === _chunk4KF7KUAIcjs.principalKey.call(void 0, _chunk4KF7KUAIcjs.principal.call(void 0, actor)) && _optionalChain([member, 'access', _82 => _82.roles, 'optionalAccess', _83 => _83.includes, 'call', _84 => _84("coordinator")]))]), "COORDINATOR_REQUIRED");
646
- }
647
- function publishPlan(state, plan2, actor, apply) {
648
- requireCoordinator(state, actor);
649
- _chunk4KF7KUAIcjs.requireValue.call(void 0, plan2 && typeof plan2 === "object", "INVALID_WORK_PLAN");
650
- _chunk4KF7KUAIcjs.identity.call(void 0, plan2.id);
651
- _chunk4KF7KUAIcjs.requireValue.call(void 0, plan2.schema === "kanban.plan/1" && typeof plan2.sealed === "boolean" && Array.isArray(plan2.items) && plan2.items.length > 0 && plan2.items.length <= 100, "INVALID_WORK_PLAN");
652
- const workflow = state.workflow, previous = workflow.plans[plan2.id];
653
- _chunk4KF7KUAIcjs.requireValue.call(void 0, Number.isSafeInteger(plan2.revision) && plan2.revision === (_nullishCoalesce(_optionalChain([previous, 'optionalAccess', _85 => _85.revision]), () => ( 0))) + 1, "PLAN_REVISION_CONFLICT");
654
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !Object.values(workflow.dispatches).some((dispatch) => dispatch.planId === plan2.id && ["prepared", "running", "unknown", "succeeded"].includes(dispatch.outcome)), "PLAN_EXECUTION_UNSETTLED");
655
- if (plan2.decisionId) {
656
- const decision = _optionalChain([state, 'access', _86 => _86.records, 'optionalAccess', _87 => _87.find, 'call', _88 => _88((record) => record.id === plan2.decisionId && record.kind === "decision" && record.status === "confirmed")]);
657
- _chunk4KF7KUAIcjs.requireValue.call(void 0, decision, "DECISION_NOT_CONFIRMED");
658
- if (decision.coordination) _chunk4KF7KUAIcjs.requireValue.call(void 0, _chunk4KF7KUAIcjs.principalKey.call(void 0, decision.coordination.manager) === _chunk4KF7KUAIcjs.principalKey.call(void 0, _chunk4KF7KUAIcjs.principal.call(void 0, actor)), "DECISION_MANAGER_REQUIRED");
659
- }
660
- if (plan2.rootItemId) {
661
- const root = state.board.items.find((item) => item.id === plan2.rootItemId);
662
- _chunk4KF7KUAIcjs.requireValue.call(void 0, root && !root.owner && ["backlog", "open"].includes(root.status), "PLAN_ROOT_UNAVAILABLE");
663
- if (_optionalChain([root, 'access', _89 => _89.planning, 'optionalAccess', _90 => _90.execution]) !== "children") apply({ type: "plan-item", itemId: root.id, planning: { ...plan(root), execution: "children" } });
664
- }
665
- const ordered = orderWork(plan2.items, state), definitions = {};
666
- for (const item of ordered) {
667
- const digest = _chunk6MN3H3YFcjs.sha256HexSync.call(void 0, JSON.stringify(item));
668
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !Object.values(workflow.plans).some((other) => other.id !== plan2.id && other.itemIds.includes(item.id)), "ITEM_IN_OTHER_PLAN");
669
- const exists = state.board.items.some((old) => old.id === item.id) || _optionalChain([state, 'access', _91 => _91.archiveIndex, 'optionalAccess', _92 => _92.some, 'call', _93 => _93((old) => old.id === item.id)]);
670
- if (exists && _optionalChain([previous, 'optionalAccess', _94 => _94.definitions, 'access', _95 => _95[item.id], 'optionalAccess', _96 => _96.digest]) !== digest) {
671
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !_optionalChain([previous, 'optionalAccess', _97 => _97.definitions, 'access', _98 => _98[item.id]]), "PLAN_ITEM_CHANGED_REQUIRES_NEW_ID");
672
- adoptItem(state, item, apply);
673
- }
674
- if (!exists) apply({
675
- type: "create-item",
676
- item: { id: item.id, title: item.title, responsibility: item.responsibility, acceptance: item.acceptance, eligiblePrincipals: [item.assignee], externalRefs: item.externalRefs },
677
- planning: { kind: _nullishCoalesce(_nullishCoalesce(item.workType, () => ( state.board.defaultWorkType)), () => ( "task")), priority: 2, dependencies: item.dependsOn, references: [], ...plan2.rootItemId ? { parentId: plan2.rootItemId } : {} }
678
- });
679
- definitions[item.id] = { digest, inputs: item.inputs, outputs: _nullishCoalesce(item.outputs, () => ( [])) };
680
- }
681
- workflow.plans[plan2.id] = { schema: plan2.schema, id: plan2.id, revision: plan2.revision, decisionId: plan2.decisionId, rootItemId: plan2.rootItemId, sealed: plan2.sealed, itemIds: ordered.map((item) => item.id), definitions };
682
- }
683
- function adoptItem(state, definition, apply) {
684
- const item = state.board.items.find((item2) => item2.id === definition.id);
685
- _chunk4KF7KUAIcjs.requireValue.call(void 0, item && definition.expectedRevision === item.revision && ["backlog", "open"].includes(item.status) && !item.owner && !item.blocked, "PLAN_ITEM_CHANGED_REQUIRES_NEW_ID");
686
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !definition.workType || definition.workType === _optionalChain([item, 'access', _99 => _99.planning, 'optionalAccess', _100 => _100.kind]), "PLAN_ITEM_CHANGED_REQUIRES_NEW_ID");
687
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !definition.externalRefs || definition.externalRefs.every((ref) => _optionalChain([item, 'access', _101 => _101.externalRefs, 'optionalAccess', _102 => _102.some, 'call', _103 => _103((existing) => JSON.stringify(existing) === JSON.stringify(ref))])), "PLAN_RESOURCE_MISMATCH");
688
- _chunk4KF7KUAIcjs.requireValue.call(void 0, item.title === definition.title && item.responsibility === definition.responsibility && item.acceptance === definition.acceptance, "PLAN_ITEM_CHANGED_REQUIRES_NEW_ID");
689
- _chunk4KF7KUAIcjs.requireValue.call(void 0, plan(item).dependencies.every((id) => definition.dependsOn.includes(id)), "EXISTING_DEPENDENCY_REQUIRED");
690
- apply({ type: "plan-item", itemId: item.id, planning: { ...plan(item), dependencies: definition.dependsOn } });
691
- item.eligiblePrincipals = [definition.assignee];
692
- delete item.eligibleAgentIds;
693
- _chunk4KF7KUAIcjs.validateCandidates.call(void 0, state.board, item, true);
694
- }
695
- function orderWork(items, state) {
696
- for (const item of items) validateDefinition(item);
697
- const ids = new Set(items.map((item) => item.id));
698
- _chunk4KF7KUAIcjs.requireValue.call(void 0, ids.size === items.length, "DUPLICATE_PLAN_ITEM");
699
- for (const item of items) {
700
- _chunk4KF7KUAIcjs.identity.call(void 0, item.id);
701
- _chunk4KF7KUAIcjs.requireValue.call(void 0, Array.isArray(item.dependsOn) && item.dependsOn.length <= 100 && new Set(item.dependsOn).size === item.dependsOn.length, "INVALID_DEPENDENCIES");
702
- _chunk4KF7KUAIcjs.requireValue.call(void 0, Object.keys(_nullishCoalesce(item.inputs, () => ( {}))).length <= 100 && Array.isArray(_nullishCoalesce(item.outputs, () => ( []))) && (_nullishCoalesce(item.outputs, () => ( []))).length <= 100 && new Set(_nullishCoalesce(item.outputs, () => ( []))).size === (_nullishCoalesce(item.outputs, () => ( []))).length, "PLAN_BINDING_LIMIT");
703
- for (const name of [...Object.keys(_nullishCoalesce(item.inputs, () => ( {}))), ..._nullishCoalesce(item.outputs, () => ( []))]) _chunk4KF7KUAIcjs.requireValue.call(void 0, /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/.test(name), "INVALID_OUTPUT_NAME");
704
- for (const binding of Object.values(_nullishCoalesce(item.inputs, () => ( {})))) {
705
- _chunk4KF7KUAIcjs.requireValue.call(void 0, binding && item.dependsOn.includes(binding.fromItemId) && typeof binding.output === "string", "INPUT_DEPENDENCY_REQUIRED");
706
- const producer = items.find((other) => other.id === binding.fromItemId), existing = Object.values(state.workflow.dispatches).some((dispatch) => dispatch.itemId === binding.fromItemId && dispatch.outcome === "accepted" && _optionalChain([dispatch, 'access', _104 => _104.outputs, 'optionalAccess', _105 => _105.some, 'call', _106 => _106((output) => output.name === binding.output)]));
707
- _chunk4KF7KUAIcjs.requireValue.call(void 0, producer ? _optionalChain([producer, 'access', _107 => _107.outputs, 'optionalAccess', _108 => _108.includes, 'call', _109 => _109(binding.output)]) : existing, "OUTPUT_NOT_DECLARED");
708
- }
709
- for (const dependency of item.dependsOn) _chunk4KF7KUAIcjs.requireValue.call(void 0, ids.has(dependency) || [...state.board.items, ..._nullishCoalesce(state.archiveIndex, () => ( []))].some((old) => old.id === dependency), "DEPENDENCY_NOT_FOUND");
710
- }
711
- const ordered = [], remaining = [...items], done = /* @__PURE__ */ new Set();
712
- while (remaining.length) {
713
- const next = remaining.findIndex((item2) => item2.dependsOn.every((id) => !ids.has(id) || done.has(id)));
714
- _chunk4KF7KUAIcjs.requireValue.call(void 0, next >= 0, "DEPENDENCY_CYCLE");
715
- const [item] = remaining.splice(next, 1);
716
- ordered.push(item);
717
- done.add(item.id);
718
- }
719
- return ordered;
720
- }
721
- function validateDefinition(item) {
722
- _chunk4KF7KUAIcjs.requireValue.call(void 0, item && typeof item === "object" && !Array.isArray(item), "INVALID_WORK_DEFINITION");
723
- const assignee = item.assignee;
724
- _chunk4KF7KUAIcjs.requireValue.call(void 0, assignee && ["agent", "human", "service"].includes(assignee.kind), "INVALID_PRINCIPAL");
725
- _chunk4KF7KUAIcjs.identity.call(void 0, assignee.id);
726
- if (item.inputs !== void 0) _chunk4KF7KUAIcjs.requireValue.call(void 0, item.inputs && typeof item.inputs === "object" && !Array.isArray(item.inputs), "INVALID_INPUT_BINDINGS");
727
- if (item.outputs !== void 0) _chunk4KF7KUAIcjs.requireValue.call(void 0, Array.isArray(item.outputs) && item.outputs.every((name) => typeof name === "string"), "INVALID_OUTPUT_NAMES");
728
- }
729
-
730
747
  // src/task-commands.ts
731
748
  var types = ["set-launch-mode", "retry-analysis", "begin-edit", "end-edit", "save-edit", "request-run", "admit-item", "report-analysis", "request-control", "control-receipt", "report-issue", "resolve-issue"];
732
749
  function taskCommand(command) {
733
750
  return types.includes(command.type);
734
751
  }
735
752
  function assertDefinitionEditable(item, now, editId, actor) {
736
- _chunk4KF7KUAIcjs.requireValue.call(void 0, ["proposed", "backlog", "open"].includes(item.status) && !item.owner && _optionalChain([item, 'access', _110 => _110.launch, 'optionalAccess', _111 => _111.admittedAt]) === void 0, "TASK_DEFINITION_FROZEN");
737
- if (_chunkKYNYPKKHcjs.taskEditing.call(void 0, item, now)) _chunk4KF7KUAIcjs.requireValue.call(void 0, item.launch.editing.id === editId && !!actor && _chunk4KF7KUAIcjs.principalKey.call(void 0, item.launch.editing.principal) === _chunk4KF7KUAIcjs.principalKey.call(void 0, _chunk4KF7KUAIcjs.principal.call(void 0, actor)), "EDIT_LEASE_ACTIVE");
753
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _optionalChain([item, 'access', _120 => _120.control, 'optionalAccess', _121 => _121.action]) !== "cancel", "TASK_CANCELLING");
754
+ _chunkRBOER6EWcjs.requireValue.call(void 0, ["proposed", "backlog", "open"].includes(item.status) && !item.owner && _optionalChain([item, 'access', _122 => _122.launch, 'optionalAccess', _123 => _123.admittedAt]) === void 0, "TASK_DEFINITION_FROZEN");
755
+ if (_chunkAOHQCX7Kcjs.taskEditing.call(void 0, item, now)) _chunkRBOER6EWcjs.requireValue.call(void 0, item.launch.editing.id === editId && !!actor && _chunkRBOER6EWcjs.principalKey.call(void 0, item.launch.editing.principal) === _chunkRBOER6EWcjs.principalKey.call(void 0, _chunkRBOER6EWcjs.principal.call(void 0, actor)), "EDIT_LEASE_ACTIVE");
738
756
  }
739
757
  function applyTaskCommand(state, command, actor, now) {
740
758
  const item = state.board.items.find((i) => i.id === command.itemId);
741
- _chunk4KF7KUAIcjs.requireValue.call(void 0, item, "ITEM_NOT_FOUND");
742
- item.launch ??= { startAt: _chunkKYNYPKKHcjs.taskStartAt.call(void 0, item) };
759
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item, "ITEM_NOT_FOUND");
760
+ item.launch ??= { startAt: _chunkAOHQCX7Kcjs.taskStartAt.call(void 0, item) };
743
761
  if (["begin-edit", "end-edit", "save-edit"].includes(command.type)) edit(state, item, command, actor, now);
744
762
  else if (command.type === "retry-analysis") {
745
- _chunk4KF7KUAIcjs.identity.call(void 0, command.retryId);
746
- _chunk4KF7KUAIcjs.requireValue.call(void 0, ["failed", "clarification"].includes(_nullishCoalesce(_optionalChain([item, 'access', _112 => _112.analysis, 'optionalAccess', _113 => _113.state]), () => ( ""))) && !item.owner, "ANALYSIS_NOT_RETRYABLE");
763
+ _chunkRBOER6EWcjs.identity.call(void 0, command.retryId);
764
+ _chunkRBOER6EWcjs.requireValue.call(void 0, ["failed", "clarification"].includes(_nullishCoalesce(_optionalChain([item, 'access', _124 => _124.analysis, 'optionalAccess', _125 => _125.state]), () => ( ""))) && !item.owner, "ANALYSIS_NOT_RETRYABLE");
747
765
  item.launch.analysisEpoch = command.retryId;
748
766
  delete item.analysis;
749
767
  } else if (command.type === "set-launch-mode") {
@@ -755,42 +773,41 @@ function applyTaskCommand(state, command, actor, now) {
755
773
  } else if (command.type === "admit-item") {
756
774
  requireCoordinator(state, actor);
757
775
  assertDefinitionEditable(item, now);
758
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _chunkLSE6JG5Icjs.boardAllowsStart.call(void 0, state.board, item), "BOARD_EXECUTION_PAUSED");
759
- _chunk4KF7KUAIcjs.requireValue.call(void 0, command.trigger === "manual" ? item.launch.requestedAt !== void 0 : _chunkKYNYPKKHcjs.taskDue.call(void 0, item, now), "START_NOT_DUE");
760
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !item.blocked && _optionalChain([item, 'access', _114 => _114.control, 'optionalAccess', _115 => _115.action]) !== "pause", "ITEM_BLOCKED");
761
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _nullishCoalesce(_optionalChain([item, 'access', _116 => _116.planning, 'optionalAccess', _117 => _117.dependencies, 'access', _118 => _118.every, 'call', _119 => _119((id) => _optionalChain([catalog, 'call', _120 => _120(state), 'access', _121 => _121.find, 'call', _122 => _122((i) => i.id === id), 'optionalAccess', _123 => _123.status]) === "completed")]), () => ( true)), "DEPENDENCIES_UNFINISHED");
776
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _chunkAOHQCX7Kcjs.boardAllowsStart.call(void 0, state.board, item), "BOARD_EXECUTION_PAUSED");
777
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !item.control || item.control.action === "resume" && item.control.state === "resumed", "TASK_CONTROL_PENDING");
778
+ _chunkRBOER6EWcjs.requireValue.call(void 0, command.trigger === "manual" ? item.launch.requestedAt !== void 0 : _chunkAOHQCX7Kcjs.taskDue.call(void 0, item, now), "START_NOT_DUE");
779
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !item.blocked && _optionalChain([item, 'access', _126 => _126.control, 'optionalAccess', _127 => _127.action]) !== "pause", "ITEM_BLOCKED");
780
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _nullishCoalesce(_optionalChain([item, 'access', _128 => _128.planning, 'optionalAccess', _129 => _129.dependencies, 'access', _130 => _130.every, 'call', _131 => _131((id) => _optionalChain([catalog, 'call', _132 => _132(state), 'access', _133 => _133.find, 'call', _134 => _134((i) => i.id === id), 'optionalAccess', _135 => _135.status]) === "completed")]), () => ( true)), "DEPENDENCIES_UNFINISHED");
762
781
  item.launch.admittedAt = now;
763
782
  } else if (command.type === "report-analysis") {
764
783
  requireCoordinator(state, actor);
765
- _chunk4KF7KUAIcjs.identity.call(void 0, command.operationId);
766
- _chunk4KF7KUAIcjs.requireValue.call(void 0, command.status.itemId === item.id, "ANALYSIS_SCOPE_MISMATCH");
784
+ _chunkRBOER6EWcjs.identity.call(void 0, command.operationId);
785
+ _chunkRBOER6EWcjs.requireValue.call(void 0, command.status.itemId === item.id, "ANALYSIS_SCOPE_MISMATCH");
786
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _optionalChain([item, 'access', _136 => _136.control, 'optionalAccess', _137 => _137.action]) !== "cancel" && !["completed", "cancelled"].includes(item.status), "TASK_CANCELLING");
767
787
  item.analysis = structuredClone(command.status);
768
- } else if (command.type === "request-control") requestControl(state, item, command);
769
- else if (command.type === "control-receipt") {
770
- requireCoordinator(state, actor);
771
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _optionalChain([item, 'access', _124 => _124.control, 'optionalAccess', _125 => _125.id]) === command.controlId, "STALE_CONTROL_RECEIPT");
772
- _chunk4KF7KUAIcjs.requireValue.call(void 0, ["accepted", "paused", "resumed", "failed", "unknown"].includes(command.state), "INVALID_CONTROL_STATE");
773
- item.control.state = command.state;
774
- item.control.code = command.code;
775
- } else issues(state, item, command, actor);
788
+ } else if (command.type === "request-control") {
789
+ requestControl(state, item, command);
790
+ if (command.action === "cancel") cancelChildren(state, item, command.controlId);
791
+ } else if (command.type === "control-receipt") applyControlReceipt(state, item, command, actor, now);
792
+ else issues(state, item, command, actor);
776
793
  item.updatedAt = now;
777
794
  item.revision++;
778
795
  }
779
796
  function edit(state, item, command, actor, now) {
780
797
  if (command.type === "begin-edit") {
781
798
  assertDefinitionEditable(item, now, command.editId, actor);
782
- _chunk4KF7KUAIcjs.identity.call(void 0, command.editId);
783
- _chunk4KF7KUAIcjs.requireValue.call(void 0, Number.isSafeInteger(command.leaseMs) && command.leaseMs >= 1e3 && command.leaseMs <= 3e5, "INVALID_EDIT_LEASE");
784
- item.launch.editing = { id: command.editId, principal: _chunk4KF7KUAIcjs.principal.call(void 0, actor), expiresAt: now + command.leaseMs };
799
+ _chunkRBOER6EWcjs.identity.call(void 0, command.editId);
800
+ _chunkRBOER6EWcjs.requireValue.call(void 0, Number.isSafeInteger(command.leaseMs) && command.leaseMs >= 1e3 && command.leaseMs <= 3e5, "INVALID_EDIT_LEASE");
801
+ item.launch.editing = { id: command.editId, principal: _chunkRBOER6EWcjs.principal.call(void 0, actor), expiresAt: now + command.leaseMs };
785
802
  return;
786
803
  }
787
804
  if (command.type !== "save-edit" && command.type !== "end-edit") return;
788
805
  assertDefinitionEditable(item, now, command.editId, actor);
789
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _chunkKYNYPKKHcjs.taskEditing.call(void 0, item, now) && item.launch.editing.id === command.editId, "EDIT_LEASE_EXPIRED");
806
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _chunkAOHQCX7Kcjs.taskEditing.call(void 0, item, now) && item.launch.editing.id === command.editId, "EDIT_LEASE_EXPIRED");
790
807
  if (command.type === "save-edit") {
791
- _chunk4KF7KUAIcjs.text.call(void 0, command.title);
792
- _chunk4KF7KUAIcjs.text.call(void 0, command.responsibility);
793
- _chunk4KF7KUAIcjs.text.call(void 0, command.acceptance);
808
+ _chunkRBOER6EWcjs.text.call(void 0, command.title);
809
+ _chunkRBOER6EWcjs.text.call(void 0, command.responsibility);
810
+ _chunkRBOER6EWcjs.text.call(void 0, command.acceptance);
794
811
  validatePlan(state, item, command.planning);
795
812
  if (command.launchMode !== void 0) setMode(item, command.launchMode);
796
813
  Object.assign(item, { title: command.title, responsibility: command.responsibility, acceptance: command.acceptance, planning: command.planning });
@@ -799,81 +816,160 @@ function edit(state, item, command, actor, now) {
799
816
  for (const ref of command.externalRefs) attachReference(item, ref);
800
817
  }
801
818
  }
802
- if (command.type === "save-edit") for (const plan2 of Object.values(_nullishCoalesce(_optionalChain([state, 'access', _126 => _126.workflow, 'optionalAccess', _127 => _127.plans]), () => ( {})))) {
819
+ if (command.type === "save-edit") for (const plan2 of Object.values(_nullishCoalesce(_optionalChain([state, 'access', _138 => _138.workflow, 'optionalAccess', _139 => _139.plans]), () => ( {})))) {
803
820
  const definition = plan2.definitions[item.id];
804
821
  if (!definition) continue;
805
- _chunk4KF7KUAIcjs.requireValue.call(void 0, Object.values(_nullishCoalesce(definition.inputs, () => ( {}))).every((binding) => _optionalChain([item, 'access', _128 => _128.planning, 'optionalAccess', _129 => _129.dependencies, 'access', _130 => _130.includes, 'call', _131 => _131(binding.fromItemId)])), "EXISTING_DEPENDENCY_REQUIRED");
806
- definition.digest = _chunk6MN3H3YFcjs.sha256HexSync.call(void 0, JSON.stringify([item.title, item.responsibility, item.acceptance, item.planning, item.externalRefs, definition.inputs, definition.outputs]));
822
+ _chunkRBOER6EWcjs.requireValue.call(void 0, Object.values(_nullishCoalesce(definition.inputs, () => ( {}))).every((binding) => _optionalChain([item, 'access', _140 => _140.planning, 'optionalAccess', _141 => _141.dependencies, 'access', _142 => _142.includes, 'call', _143 => _143(binding.fromItemId)])), "EXISTING_DEPENDENCY_REQUIRED");
823
+ definition.digest = _chunkRSH6QSECcjs.sha256HexSync.call(void 0, JSON.stringify([item.title, item.responsibility, item.acceptance, item.planning, item.externalRefs, definition.inputs, definition.outputs]));
807
824
  }
808
825
  delete item.launch.editing;
809
826
  }
810
827
  function requestControl(state, item, command) {
811
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !["completed", "cancelled", "review"].includes(item.status), "ITEM_COMPLETED");
812
- _chunk4KF7KUAIcjs.identity.call(void 0, command.controlId);
813
- _chunk4KF7KUAIcjs.requireValue.call(void 0, ["pause", "resume"].includes(command.action), "INVALID_CONTROL_ACTION");
814
- if (_optionalChain([item, 'access', _132 => _132.control, 'optionalAccess', _133 => _133.id]) === command.controlId) {
815
- _chunk4KF7KUAIcjs.requireValue.call(void 0, item.control.action === command.action, "IDEMPOTENCY_CONFLICT");
828
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !["completed", "cancelled"].includes(item.status), "ITEM_COMPLETED");
829
+ _chunkRBOER6EWcjs.identity.call(void 0, command.controlId);
830
+ _chunkRBOER6EWcjs.requireValue.call(void 0, ["pause", "resume", "cancel"].includes(command.action), "INVALID_CONTROL_ACTION");
831
+ if (_optionalChain([item, 'access', _144 => _144.control, 'optionalAccess', _145 => _145.id]) === command.controlId) {
832
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item.control.action === command.action, "IDEMPOTENCY_CONFLICT");
816
833
  return;
817
834
  }
818
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !item.control || !["requested", "unknown"].includes(item.control.state), "CONTROL_UNSETTLED");
819
- const dispatch = Object.values(_nullishCoalesce(_optionalChain([state, 'access', _134 => _134.workflow, 'optionalAccess', _135 => _135.dispatches]), () => ( {}))).find((d) => d.itemId === item.id && ["prepared", "running", "unknown"].includes(d.outcome));
820
- _chunk4KF7KUAIcjs.requireValue.call(void 0, dispatch || _optionalChain([item, 'access', _136 => _136.launch, 'optionalAccess', _137 => _137.admittedAt]) === void 0, "TASK_CONTROL_UNSUPPORTED");
821
- _chunk4KF7KUAIcjs.requireValue.call(void 0, command.action === "pause" || _optionalChain([item, 'access', _138 => _138.control, 'optionalAccess', _139 => _139.action]) === "pause", "TASK_NOT_PAUSED");
822
- item.control = { id: command.controlId, dispatchId: _optionalChain([dispatch, 'optionalAccess', _140 => _140.id]), action: command.action, state: "requested" };
835
+ if (command.action === "cancel" && _optionalChain([item, 'access', _146 => _146.control, 'optionalAccess', _147 => _147.action]) === "cancel" && item.control.state !== "failed") return;
836
+ _chunkRBOER6EWcjs.requireValue.call(void 0, command.action === "cancel" || !item.control || !["requested", "unknown"].includes(item.control.state), "CONTROL_UNSETTLED");
837
+ const dispatch = Object.values(_nullishCoalesce(_optionalChain([state, 'access', _148 => _148.workflow, 'optionalAccess', _149 => _149.dispatches]), () => ( {}))).filter((d) => d.itemId === item.id).sort((a, b) => b.attempt - a.attempt)[0];
838
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !item.owner || dispatch || command.action === "cancel", "TASK_CONTROL_UNSUPPORTED");
839
+ _chunkRBOER6EWcjs.requireValue.call(void 0, command.action !== "resume" || _optionalChain([item, 'access', _150 => _150.control, 'optionalAccess', _151 => _151.action]) === "pause", "TASK_NOT_PAUSED");
840
+ item.control = { id: command.controlId, dispatchId: _optionalChain([dispatch, 'optionalAccess', _152 => _152.id]), action: command.action, state: "requested" };
823
841
  }
824
842
  function issues(state, item, command, actor) {
825
843
  requireCoordinator(state, actor);
826
844
  if (command.type === "report-issue") {
827
845
  const issue = command.issue;
828
- _chunk4KF7KUAIcjs.identity.call(void 0, issue.id);
829
- _chunk4KF7KUAIcjs.identity.call(void 0, issue.attemptId);
830
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !issue.resolvedBy && ["clarification", "error"].includes(issue.type), "INVALID_ISSUE");
831
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _optionalChain([state, 'access', _141 => _141.workflow, 'optionalAccess', _142 => _142.dispatches, 'access', _143 => _143[issue.attemptId], 'optionalAccess', _144 => _144.itemId]) === item.id && _optionalChain([item, 'access', _145 => _145.owner, 'optionalAccess', _146 => _146.token]) === state.workflow.dispatches[issue.attemptId].fence, "STALE_EXECUTION_RESULT");
846
+ _chunkRBOER6EWcjs.identity.call(void 0, issue.id);
847
+ _chunkRBOER6EWcjs.identity.call(void 0, issue.attemptId);
848
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !issue.resolvedBy && ["clarification", "error"].includes(issue.type), "INVALID_ISSUE");
849
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _optionalChain([state, 'access', _153 => _153.workflow, 'optionalAccess', _154 => _154.dispatches, 'access', _155 => _155[issue.attemptId], 'optionalAccess', _156 => _156.itemId]) === item.id && _optionalChain([item, 'access', _157 => _157.owner, 'optionalAccess', _158 => _158.token]) === state.workflow.dispatches[issue.attemptId].fence, "STALE_EXECUTION_RESULT");
832
850
  item.issues ??= [];
833
851
  const old = item.issues.find((i) => i.id === issue.id && i.attemptId === issue.attemptId);
834
852
  if (!old) {
835
- _chunk4KF7KUAIcjs.requireValue.call(void 0, item.issues.length < 200, "ISSUE_LIMIT");
853
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item.issues.length < 200, "ISSUE_LIMIT");
836
854
  item.issues.push(structuredClone(issue));
837
855
  }
838
856
  } else if (command.type === "resolve-issue") {
839
- const issue = _optionalChain([item, 'access', _147 => _147.issues, 'optionalAccess', _148 => _148.find, 'call', _149 => _149((i) => i.id === command.issueId && i.attemptId === command.attemptId)]);
840
- _chunk4KF7KUAIcjs.requireValue.call(void 0, issue, "ISSUE_NOT_FOUND");
841
- _chunk4KF7KUAIcjs.identity.call(void 0, command.resolvedBy);
842
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !issue.resolvedBy || issue.resolvedBy === command.resolvedBy, "ISSUE_ALREADY_RESOLVED");
857
+ const issue = _optionalChain([item, 'access', _159 => _159.issues, 'optionalAccess', _160 => _160.find, 'call', _161 => _161((i) => i.id === command.issueId && i.attemptId === command.attemptId)]);
858
+ _chunkRBOER6EWcjs.requireValue.call(void 0, issue, "ISSUE_NOT_FOUND");
859
+ _chunkRBOER6EWcjs.identity.call(void 0, command.resolvedBy);
860
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !issue.resolvedBy || issue.resolvedBy === command.resolvedBy, "ISSUE_ALREADY_RESOLVED");
843
861
  issue.resolvedBy = command.resolvedBy;
844
862
  }
845
863
  }
846
864
  function initializeTaskLaunch(state, item) {
847
865
  if (item.launch) return false;
848
- const first = Object.values(_nullishCoalesce(_optionalChain([state, 'access', _150 => _150.workflow, 'optionalAccess', _151 => _151.dispatches]), () => ( {}))).filter((d) => d.itemId === item.id).sort((a, b) => a.attempt - b.attempt)[0];
849
- const admittedAt = _nullishCoalesce(_optionalChain([first, 'optionalAccess', _152 => _152.preparedAt]), () => ( _optionalChain([item, 'access', _153 => _153.owner, 'optionalAccess', _154 => _154.claimedAt])));
850
- item.launch = { startAt: _chunkKYNYPKKHcjs.taskStartAt.call(void 0, item), ...admittedAt === void 0 ? {} : { admittedAt } };
866
+ const first = Object.values(_nullishCoalesce(_optionalChain([state, 'access', _162 => _162.workflow, 'optionalAccess', _163 => _163.dispatches]), () => ( {}))).filter((d) => d.itemId === item.id).sort((a, b) => a.attempt - b.attempt)[0];
867
+ const admittedAt = _nullishCoalesce(_optionalChain([first, 'optionalAccess', _164 => _164.preparedAt]), () => ( _optionalChain([item, 'access', _165 => _165.owner, 'optionalAccess', _166 => _166.claimedAt])));
868
+ item.launch = { startAt: _chunkAOHQCX7Kcjs.taskStartAt.call(void 0, item), ...admittedAt === void 0 ? {} : { admittedAt } };
851
869
  item.revision++;
852
870
  return true;
853
871
  }
854
872
  function setMode(item, mode) {
855
- _chunk4KF7KUAIcjs.requireValue.call(void 0, ["automatic", "manual"].includes(mode), "INVALID_LAUNCH_MODE");
873
+ _chunkRBOER6EWcjs.requireValue.call(void 0, ["automatic", "manual"].includes(mode), "INVALID_LAUNCH_MODE");
856
874
  item.launch.mode = mode;
857
875
  delete item.launch.requestedAt;
858
876
  }
877
+ function cancelChildren(state, parent, controlId) {
878
+ const ids = /* @__PURE__ */ new Set([parent.id]);
879
+ for (let pass = 0; pass < state.board.items.length; pass++) {
880
+ const children = state.board.items.filter((item) => _optionalChain([item, 'access', _167 => _167.planning, 'optionalAccess', _168 => _168.parentId]) && ids.has(item.planning.parentId) && !ids.has(item.id));
881
+ if (!children.length) return;
882
+ for (const child of children) {
883
+ ids.add(child.id);
884
+ if (["completed", "cancelled"].includes(child.status) || _optionalChain([child, 'access', _169 => _169.control, 'optionalAccess', _170 => _170.action]) === "cancel") continue;
885
+ requestControl(state, child, { type: "request-control", itemId: child.id, controlId: _chunkRSH6QSECcjs.sha256HexSync.call(void 0, JSON.stringify([controlId, child.id])), action: "cancel" });
886
+ child.updatedAt = parent.updatedAt;
887
+ child.revision++;
888
+ }
889
+ }
890
+ }
891
+ function applyControlReceipt(state, item, command, actor, now) {
892
+ requireCoordinator(state, actor);
893
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _optionalChain([item, 'access', _171 => _171.control, 'optionalAccess', _172 => _172.id]) === command.controlId, "STALE_CONTROL_RECEIPT");
894
+ _chunkRBOER6EWcjs.requireValue.call(void 0, ["accepted", "paused", "resumed", "cancelled", "failed", "unknown"].includes(command.state), "INVALID_CONTROL_STATE");
895
+ _chunkRBOER6EWcjs.requireValue.call(void 0, command.code === void 0 || /^[A-Z][A-Z0-9_]{0,79}$/.test(command.code), "INVALID_ERROR_CODE");
896
+ if (command.state === "cancelled") {
897
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item.control.action === "cancel", "INVALID_CONTROL_STATE");
898
+ for (const dispatch of Object.values(_nullishCoalesce(_optionalChain([state, 'access', _173 => _173.workflow, 'optionalAccess', _174 => _174.dispatches]), () => ( {}))).filter((d) => d.itemId === item.id && ["prepared", "running", "unknown", "succeeded"].includes(d.outcome))) {
899
+ _chunkRBOER6EWcjs.requireValue.call(void 0, dispatch.id === item.control.dispatchId && _optionalChain([item, 'access', _175 => _175.owner, 'optionalAccess', _176 => _176.token]) === dispatch.fence, "STALE_EXECUTION_RESULT");
900
+ dispatch.outcome = "cancelled";
901
+ dispatch.code = "USER_CANCELLED";
902
+ }
903
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !catalog(state).some((i) => i.planning.parentId === item.id && !["completed", "cancelled"].includes(i.status)), "CHILDREN_UNFINISHED");
904
+ item.status = "cancelled";
905
+ item.closedAt = now;
906
+ item.closureReason = "USER_CANCELLED";
907
+ delete item.owner;
908
+ delete item.transfer;
909
+ delete item.blocked;
910
+ delete item.launch.editing;
911
+ }
912
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item.control.state !== "cancelled" || command.state === "cancelled", "STALE_CONTROL_RECEIPT");
913
+ item.control.state = command.state;
914
+ item.control.code = command.code;
915
+ }
916
+
917
+ // src/board-stop.ts
918
+ function stopBoard(state, command, actor, now) {
919
+ requireCoordinator(state, actor);
920
+ _chunkRBOER6EWcjs.requireValue.call(void 0, actor.kind === "human", "FORBIDDEN");
921
+ _chunkRBOER6EWcjs.identity.call(void 0, command.controlId);
922
+ if (command.type === "observe-board-stop") {
923
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _optionalChain([state, 'access', _177 => _177.board, 'access', _178 => _178.lifecycle, 'optionalAccess', _179 => _179.operationId]) === command.controlId, "STALE_CONTROL_RECEIPT");
924
+ _chunkRBOER6EWcjs.requireValue.call(void 0, ["waiting", "ready", "blocked"].includes(command.phase), "INVALID_CONTROL_STATE");
925
+ _chunkRBOER6EWcjs.requireValue.call(void 0, command.code === void 0 || /^[A-Z][A-Z0-9_]{0,79}$/.test(command.code), "INVALID_ERROR_CODE");
926
+ state.board.lifecycle.phase = command.phase;
927
+ state.board.lifecycle.code = command.code;
928
+ return;
929
+ }
930
+ _chunkRBOER6EWcjs.requireValue.call(void 0, ["cancel", "delete"].includes(command.intent) && ["drain", "cancel"].includes(command.mode), "INVALID_BOARD_CONTROL");
931
+ const old = state.board.lifecycle;
932
+ if (old) {
933
+ _chunkRBOER6EWcjs.requireValue.call(void 0, old.intent === "cancel" && command.intent === "delete" || old.operationId === command.controlId, "BOARD_STOP_PENDING");
934
+ if (old.operationId === command.controlId) return;
935
+ }
936
+ state.board.lifecycle = { operationId: command.controlId, intent: command.intent, mode: command.mode, phase: "waiting" };
937
+ state.board.executionControl = { ...state.board.executionControl, mode: "manual", paused: true, controls: {} };
938
+ if (state.board.automation) state.board.automation.enabled = false;
939
+ if (command.mode !== "cancel") return;
940
+ for (const item of state.board.items) if (!["completed", "cancelled"].includes(item.status)) applyTaskCommand(
941
+ state,
942
+ { type: "request-control", itemId: item.id, controlId: _chunkRSH6QSECcjs.sha256HexSync.call(void 0, JSON.stringify([command.controlId, item.id])), action: "cancel" },
943
+ actor,
944
+ now
945
+ );
946
+ }
947
+ function protectStoppedBoard(state, command) {
948
+ if (!state.board.lifecycle) return;
949
+ if (command.type === "append-record" && command.record.kind === "decision") _chunkRBOER6EWcjs.requireValue.call(void 0, false, "BOARD_STOPPING");
950
+ const fresh = ["create-item", "admit-item", "prepare-dispatch", "continue-execution", "publish-plan", "request-run", "apply-discovery", "begin-edit", "save-edit"];
951
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !fresh.includes(command.type), "BOARD_STOPPING");
952
+ if (command.type === "set-board-control") _chunkRBOER6EWcjs.requireValue.call(void 0, command.paused !== false && command.mode !== "automatic", "BOARD_STOPPING");
953
+ if (command.type === "configure-automation") _chunkRBOER6EWcjs.requireValue.call(void 0, !command.settings.enabled, "BOARD_STOPPING");
954
+ }
859
955
 
860
956
  // src/board-control.ts
861
957
  function setBoardControl(state, command, actor, now, token) {
862
- _chunk4KF7KUAIcjs.requireValue.call(void 0, actor.kind === "human", "FORBIDDEN");
863
- _chunk4KF7KUAIcjs.requireValue.call(void 0, command.mode !== void 0 || command.paused !== void 0, "INVALID_BOARD_CONTROL");
864
- _chunk4KF7KUAIcjs.requireValue.call(void 0, command.mode === void 0 || ["automatic", "manual"].includes(command.mode), "INVALID_LAUNCH_MODE");
865
- _chunk4KF7KUAIcjs.requireValue.call(void 0, command.paused === void 0 || typeof command.paused === "boolean", "INVALID_BOARD_CONTROL");
958
+ _chunkRBOER6EWcjs.requireValue.call(void 0, actor.kind === "human", "FORBIDDEN");
959
+ _chunkRBOER6EWcjs.requireValue.call(void 0, command.mode !== void 0 || command.paused !== void 0, "INVALID_BOARD_CONTROL");
960
+ _chunkRBOER6EWcjs.requireValue.call(void 0, command.mode === void 0 || ["automatic", "manual"].includes(command.mode), "INVALID_LAUNCH_MODE");
961
+ _chunkRBOER6EWcjs.requireValue.call(void 0, command.paused === void 0 || typeof command.paused === "boolean", "INVALID_BOARD_CONTROL");
866
962
  const policy2 = state.board.executionControl ??= { mode: "automatic", paused: false, controls: {} };
867
963
  if (command.mode) policy2.mode = command.mode;
868
964
  if (command.paused === void 0 || command.paused === policy2.paused) return;
869
- if (!command.paused) _chunk4KF7KUAIcjs.requireValue.call(void 0, !state.board.items.some((item) => policy2.controls[item.id] === _optionalChain([item, 'access', _155 => _155.control, 'optionalAccess', _156 => _156.id]) && ["requested", "unknown"].includes(item.control.state)), "CONTROL_UNSETTLED");
965
+ if (!command.paused) _chunkRBOER6EWcjs.requireValue.call(void 0, !state.board.items.some((item) => policy2.controls[item.id] === _optionalChain([item, 'access', _180 => _180.control, 'optionalAccess', _181 => _181.id]) && ["requested", "unknown"].includes(item.control.state)), "CONTROL_UNSETTLED");
870
966
  policy2.paused = command.paused;
871
967
  if (policy2.paused) policy2.controls = {};
872
968
  state.board.items.forEach((item, index) => {
873
969
  if (["completed", "cancelled", "review"].includes(item.status)) return;
874
- const active = Object.values(_nullishCoalesce(_optionalChain([state, 'access', _157 => _157.workflow, 'optionalAccess', _158 => _158.dispatches]), () => ( {}))).some((d) => d.itemId === item.id && ["prepared", "running", "unknown"].includes(d.outcome));
875
- const managed = policy2.controls[item.id] === _optionalChain([item, 'access', _159 => _159.control, 'optionalAccess', _160 => _160.id]);
876
- if (policy2.paused ? !active || _optionalChain([item, 'access', _161 => _161.control, 'optionalAccess', _162 => _162.action]) === "pause" : !managed || _optionalChain([item, 'access', _163 => _163.control, 'optionalAccess', _164 => _164.action]) !== "pause") return;
970
+ const active = _optionalChain([item, 'access', _182 => _182.analysis, 'optionalAccess', _183 => _183.state]) === "analyzing" || _optionalChain([item, 'access', _184 => _184.launch, 'optionalAccess', _185 => _185.admittedAt]) !== void 0 || Object.values(_nullishCoalesce(_optionalChain([state, 'access', _186 => _186.workflow, 'optionalAccess', _187 => _187.dispatches]), () => ( {}))).some((d) => d.itemId === item.id && ["prepared", "running", "unknown"].includes(d.outcome));
971
+ const managed = policy2.controls[item.id] === _optionalChain([item, 'access', _188 => _188.control, 'optionalAccess', _189 => _189.id]);
972
+ if (policy2.paused ? !active || _optionalChain([item, 'access', _190 => _190.control, 'optionalAccess', _191 => _191.action]) === "pause" : !managed || _optionalChain([item, 'access', _192 => _192.control, 'optionalAccess', _193 => _193.action]) !== "pause") return;
877
973
  if (item.control && ["requested", "unknown"].includes(item.control.state)) return;
878
974
  const controlId = token + "-" + index;
879
975
  applyTaskCommand(state, { type: "request-control", itemId: item.id, controlId, action: policy2.paused ? "pause" : "resume" }, actor, now);
@@ -883,21 +979,21 @@ function setBoardControl(state, command, actor, now, token) {
883
979
 
884
980
  // src/scan-commit.ts
885
981
  function applyDiscovery(state, batch, actor, now) {
886
- const discovery = _chunk4KF7KUAIcjs.discoveryState.call(void 0, state), pending = _optionalChain([discovery, 'optionalAccess', _165 => _165.pending]);
887
- _chunk4KF7KUAIcjs.requireValue.call(void 0, pending && pending.runId === batch.runId && pending.token === batch.leaseToken && pending.leaseUntil > now, "SCAN_LEASE_EXPIRED");
888
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _optionalChain([pending, 'access', _166 => _166.request, 'optionalAccess', _167 => _167.command, 'access', _168 => _168.type]) === "apply-discovery" && JSON.stringify(pending.request.command.batch) === JSON.stringify(batch), "SCAN_BATCH_MISMATCH");
889
- _chunk4KF7KUAIcjs.requireValue.call(void 0, batch.changes.length <= 50, "SCAN_CHANGE_LIMIT");
982
+ const discovery = _chunkRBOER6EWcjs.discoveryState.call(void 0, state), pending = _optionalChain([discovery, 'optionalAccess', _194 => _194.pending]);
983
+ _chunkRBOER6EWcjs.requireValue.call(void 0, pending && pending.runId === batch.runId && pending.token === batch.leaseToken && pending.leaseUntil > now, "SCAN_LEASE_EXPIRED");
984
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _optionalChain([pending, 'access', _195 => _195.request, 'optionalAccess', _196 => _196.command, 'access', _197 => _197.type]) === "apply-discovery" && JSON.stringify(pending.request.command.batch) === JSON.stringify(batch), "SCAN_BATCH_MISMATCH");
985
+ _chunkRBOER6EWcjs.requireValue.call(void 0, batch.changes.length <= 50, "SCAN_CHANGE_LIMIT");
890
986
  for (const change of batch.changes) {
891
- _chunk4KF7KUAIcjs.identity.call(void 0, change.itemId);
987
+ _chunkRBOER6EWcjs.identity.call(void 0, change.itemId);
892
988
  validateSources(change.sources);
893
- _chunk4KF7KUAIcjs.requireValue.call(void 0, change.sources.length > 0 && change.sources.some((s) => s.role === "user"), "USER_EVIDENCE_REQUIRED");
989
+ _chunkRBOER6EWcjs.requireValue.call(void 0, change.sources.length > 0 && change.sources.some((s) => s.role === "user"), "USER_EVIDENCE_REQUIRED");
894
990
  const item = change.action === "create" ? createItem(state, change, actor, now, batch.autoCreate, batch.runId) : updateItem(state, change, actor, now, batch.runId);
895
991
  if (item) attachSources(item, change, now);
896
992
  }
897
- _chunk4KF7KUAIcjs.requireValue.call(void 0, (_nullishCoalesce(_optionalChain([batch, 'access', _169 => _169.records, 'optionalAccess', _170 => _170.length]), () => ( 0))) <= 20, "SCAN_RECORD_LIMIT");
993
+ _chunkRBOER6EWcjs.requireValue.call(void 0, (_nullishCoalesce(_optionalChain([batch, 'access', _198 => _198.records, 'optionalAccess', _199 => _199.length]), () => ( 0))) <= 20, "SCAN_RECORD_LIMIT");
898
994
  for (const record of _nullishCoalesce(batch.records, () => ( []))) {
899
- _chunk4KF7KUAIcjs.requireValue.call(void 0, record.sources.some((source) => source.role === "user"), "USER_EVIDENCE_REQUIRED");
900
- const duplicate = _optionalChain([state, 'access', _171 => _171.records, 'optionalAccess', _172 => _172.some, 'call', _173 => _173((old) => recordFingerprint(old) === recordFingerprint(record))]);
995
+ _chunkRBOER6EWcjs.requireValue.call(void 0, record.sources.some((source) => source.role === "user"), "USER_EVIDENCE_REQUIRED");
996
+ const duplicate = _optionalChain([state, 'access', _200 => _200.records, 'optionalAccess', _201 => _201.some, 'call', _202 => _202((old) => recordFingerprint(old) === recordFingerprint(record))]);
901
997
  if (!duplicate) {
902
998
  applyRecord(state, { type: "append-record", record }, actor, now, true);
903
999
  state.records.find((entry) => entry.id === record.id).originRunId = batch.runId;
@@ -908,11 +1004,11 @@ function applyDiscovery(state, batch, actor, now) {
908
1004
  delete discovery.pending;
909
1005
  }
910
1006
  function createItem(state, change, actor, now, autoCreate, runId) {
911
- _chunk4KF7KUAIcjs.text.call(void 0, change.title);
912
- _chunk4KF7KUAIcjs.text.call(void 0, change.responsibility);
913
- _chunk4KF7KUAIcjs.text.call(void 0, change.acceptance);
1007
+ _chunkRBOER6EWcjs.text.call(void 0, change.title);
1008
+ _chunkRBOER6EWcjs.text.call(void 0, change.responsibility);
1009
+ _chunkRBOER6EWcjs.text.call(void 0, change.acceptance);
914
1010
  const item = {
915
- origin: { kind: "discovery", principal: _chunk4KF7KUAIcjs.principal.call(void 0, actor), runId },
1011
+ origin: { kind: "discovery", principal: _chunkRBOER6EWcjs.principal.call(void 0, actor), runId },
916
1012
  id: change.itemId,
917
1013
  title: change.title,
918
1014
  responsibility: change.responsibility,
@@ -928,48 +1024,48 @@ function createItem(state, change, actor, now, autoCreate, runId) {
928
1024
  participants: [],
929
1025
  sources: []
930
1026
  };
931
- item.launch = { startAt: now + _chunkKYNYPKKHcjs.TASK_START_DELAY_MS };
1027
+ item.launch = { startAt: now + _chunkAOHQCX7Kcjs.TASK_START_DELAY_MS };
932
1028
  item.planning = _nullishCoalesce(change.planning, () => ( { ...plan(item), kind: _nullishCoalesce(state.board.defaultWorkType, () => ( "task")) }));
933
1029
  const fingerprint = workFingerprint(item);
934
1030
  item.origin.fingerprint = fingerprint;
935
- _chunk4KF7KUAIcjs.validateCandidates.call(void 0, state.board, item, _chunk4KF7KUAIcjs.executable.call(void 0, state.board, item));
936
- if (_optionalChain([state, 'access', _174 => _174.archiveIndex, 'optionalAccess', _175 => _175.some, 'call', _176 => _176((old) => old.discoveryFingerprint === fingerprint)])) return void 0;
937
- const existing = state.board.items.find((old) => workFingerprint(old) === fingerprint || _optionalChain([old, 'access', _177 => _177.origin, 'optionalAccess', _178 => _178.fingerprint]) === fingerprint);
1031
+ _chunkRBOER6EWcjs.validateCandidates.call(void 0, state.board, item, _chunkRBOER6EWcjs.executable.call(void 0, state.board, item));
1032
+ if (_optionalChain([state, 'access', _203 => _203.archiveIndex, 'optionalAccess', _204 => _204.some, 'call', _205 => _205((old) => old.discoveryFingerprint === fingerprint)])) return void 0;
1033
+ const existing = state.board.items.find((old) => workFingerprint(old) === fingerprint || _optionalChain([old, 'access', _206 => _206.origin, 'optionalAccess', _207 => _207.fingerprint]) === fingerprint);
938
1034
  if (existing) {
939
1035
  existing.revision++;
940
1036
  existing.updatedAt = now;
941
1037
  return existing;
942
1038
  }
943
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !state.board.items.some((old) => old.id === change.itemId) && !_optionalChain([state, 'access', _179 => _179.archiveIndex, 'optionalAccess', _180 => _180.some, 'call', _181 => _181((old) => old.id === change.itemId)]), "ITEM_EXISTS");
1039
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !state.board.items.some((old) => old.id === change.itemId) && !_optionalChain([state, 'access', _208 => _208.archiveIndex, 'optionalAccess', _209 => _209.some, 'call', _210 => _210((old) => old.id === change.itemId)]), "ITEM_EXISTS");
944
1040
  validatePlan(state, item, item.planning);
945
1041
  state.board.items.push(item);
946
1042
  if (autoCreate) setStage(state, item, automaticStage(state, item), now);
947
- if (actor.sessionId) _chunk4KF7KUAIcjs.participant.call(void 0, item.participants, actor.sessionId, actor.agentId, "creator", true, now);
1043
+ if (actor.sessionId) _chunkRBOER6EWcjs.participant.call(void 0, item.participants, actor.sessionId, actor.agentId, "creator", true, now);
948
1044
  return item;
949
1045
  }
950
1046
  function updateItem(state, change, actor, now, runId) {
951
1047
  const item = state.board.items.find((i) => i.id === change.itemId);
952
- _chunk4KF7KUAIcjs.requireValue.call(void 0, item, "ITEM_NOT_FOUND");
1048
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item, "ITEM_NOT_FOUND");
953
1049
  if (change.action === "update") {
954
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !change.planning, "SCAN_PLANNING_REQUIRES_REVIEW");
955
- const ownDraft = item.status === "proposed" && _optionalChain([item, 'access', _182 => _182.origin, 'optionalAccess', _183 => _183.kind]) === "discovery" && _chunk4KF7KUAIcjs.principalKey.call(void 0, item.origin.principal) === _chunk4KF7KUAIcjs.principalKey.call(void 0, _chunk4KF7KUAIcjs.principal.call(void 0, actor));
1050
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !change.planning, "SCAN_PLANNING_REQUIRES_REVIEW");
1051
+ const ownDraft = item.status === "proposed" && _optionalChain([item, 'access', _211 => _211.origin, 'optionalAccess', _212 => _212.kind]) === "discovery" && _chunkRBOER6EWcjs.principalKey.call(void 0, item.origin.principal) === _chunkRBOER6EWcjs.principalKey.call(void 0, _chunkRBOER6EWcjs.principal.call(void 0, actor));
956
1052
  if (ownDraft) {
957
- _chunk4KF7KUAIcjs.text.call(void 0, change.title);
958
- _chunk4KF7KUAIcjs.text.call(void 0, change.responsibility);
959
- _chunk4KF7KUAIcjs.text.call(void 0, change.acceptance);
1053
+ _chunkRBOER6EWcjs.text.call(void 0, change.title);
1054
+ _chunkRBOER6EWcjs.text.call(void 0, change.responsibility);
1055
+ _chunkRBOER6EWcjs.text.call(void 0, change.acceptance);
960
1056
  item.title = change.title;
961
1057
  item.responsibility = change.responsibility;
962
1058
  item.acceptance = change.acceptance;
963
1059
  } else proposeAmendment(item, change, actor, now, runId);
964
- } else _chunk4KF7KUAIcjs.requireValue.call(void 0, change.action === "link", "INVALID_CHANGE");
1060
+ } else _chunkRBOER6EWcjs.requireValue.call(void 0, change.action === "link", "INVALID_CHANGE");
965
1061
  item.revision++;
966
1062
  item.updatedAt = now;
967
1063
  return item;
968
1064
  }
969
1065
  function attachSources(item, change, now) {
970
1066
  for (const source of change.sources) {
971
- const subscribed = _nullishCoalesce(_optionalChain([item, 'access', _184 => _184.participants, 'access', _185 => _185.find, 'call', _186 => _186((p) => p.sessionId === source.sessionId), 'optionalAccess', _187 => _187.subscribed]), () => ( false));
972
- _chunk4KF7KUAIcjs.participant.call(void 0, item.participants, source.sessionId, void 0, source.role === "user" ? "creator" : "consultant", subscribed, now);
1067
+ const subscribed = _nullishCoalesce(_optionalChain([item, 'access', _213 => _213.participants, 'access', _214 => _214.find, 'call', _215 => _215((p) => p.sessionId === source.sessionId), 'optionalAccess', _216 => _216.subscribed]), () => ( false));
1068
+ _chunkRBOER6EWcjs.participant.call(void 0, item.participants, source.sessionId, void 0, source.role === "user" ? "creator" : "consultant", subscribed, now);
973
1069
  item.sources ??= [];
974
1070
  if (!item.sources.some((s) => s.sessionId === source.sessionId && s.messageId === source.messageId && s.revision === source.revision)) item.sources.push(source);
975
1071
  }
@@ -977,19 +1073,19 @@ function attachSources(item, change, now) {
977
1073
 
978
1074
  // src/automation.ts
979
1075
  function configureAutomation(board, settings, actor) {
980
- _chunk4KF7KUAIcjs.requireValue.call(void 0, settings && typeof settings.enabled === "boolean" && typeof settings.autoAccept === "boolean", "INVALID_AUTOMATION");
1076
+ _chunkRBOER6EWcjs.requireValue.call(void 0, settings && typeof settings.enabled === "boolean" && typeof settings.autoAccept === "boolean", "INVALID_AUTOMATION");
981
1077
  for (const ref of [settings.planner, settings.executor, ...settings.preparation ? [settings.preparation] : []]) {
982
- _chunk4KF7KUAIcjs.requireValue.call(void 0, ref && typeof ref === "object", "INVALID_AUTOMATION_TARGET");
983
- _chunk4KF7KUAIcjs.identity.call(void 0, ref.system);
984
- _chunk4KF7KUAIcjs.identity.call(void 0, ref.id);
985
- _chunk4KF7KUAIcjs.identity.call(void 0, _nullishCoalesce(ref.revision, () => ( "")));
1078
+ _chunkRBOER6EWcjs.requireValue.call(void 0, ref && typeof ref === "object", "INVALID_AUTOMATION_TARGET");
1079
+ _chunkRBOER6EWcjs.identity.call(void 0, ref.system);
1080
+ _chunkRBOER6EWcjs.identity.call(void 0, ref.id);
1081
+ _chunkRBOER6EWcjs.identity.call(void 0, _nullishCoalesce(ref.revision, () => ( "")));
986
1082
  }
987
1083
  validateOptions(settings.preparationOptions);
988
- _chunk4KF7KUAIcjs.requireValue.call(void 0, settings.preparation || !Object.keys(_nullishCoalesce(settings.preparationOptions, () => ( {}))).length, "PREPARATION_REQUIRED");
989
- const members = [..._nullishCoalesce(board.members, () => ( [])), ...(_nullishCoalesce(board.agents, () => ( []))).filter((agent) => !_optionalChain([board, 'access', _188 => _188.members, 'optionalAccess', _189 => _189.some, 'call', _190 => _190((member) => member.kind === "agent" && member.id === agent.agentId)])).map((agent) => ({ kind: "agent", id: agent.agentId, responsibility: agent.responsibility }))];
1084
+ _chunkRBOER6EWcjs.requireValue.call(void 0, settings.preparation || !Object.keys(_nullishCoalesce(settings.preparationOptions, () => ( {}))).length, "PREPARATION_REQUIRED");
1085
+ const members = [..._nullishCoalesce(board.members, () => ( [])), ...(_nullishCoalesce(board.agents, () => ( []))).filter((agent) => !_optionalChain([board, 'access', _217 => _217.members, 'optionalAccess', _218 => _218.some, 'call', _219 => _219((member) => member.kind === "agent" && member.id === agent.agentId)])).map((agent) => ({ kind: "agent", id: agent.agentId, responsibility: agent.responsibility }))];
990
1086
  for (const [principal2, role] of [[settings.coordinator, "coordinator"], [settings.worker, "worker"]]) {
991
- _chunk4KF7KUAIcjs.requireValue.call(void 0, principal2 && ["agent", "human", "service"].includes(principal2.kind), "INVALID_PRINCIPAL");
992
- _chunk4KF7KUAIcjs.identity.call(void 0, principal2.id);
1087
+ _chunkRBOER6EWcjs.requireValue.call(void 0, principal2 && ["agent", "human", "service"].includes(principal2.kind), "INVALID_PRINCIPAL");
1088
+ _chunkRBOER6EWcjs.identity.call(void 0, principal2.id);
993
1089
  const existing = members.find((member) => member.kind === principal2.kind && member.id === principal2.id);
994
1090
  if (existing) existing.roles = [.../* @__PURE__ */ new Set([..._nullishCoalesce(existing.roles, () => ( [])), role])];
995
1091
  else members.push({ ...principal2, responsibility: role, roles: [role] });
@@ -999,7 +1095,7 @@ function configureAutomation(board, settings, actor) {
999
1095
  delete board.agents;
1000
1096
  board.automation = structuredClone(settings);
1001
1097
  board.policy.review = settings.autoAccept ? "assignee" : "independent";
1002
- _chunk4KF7KUAIcjs.validateBoard.call(void 0, board);
1098
+ _chunkRBOER6EWcjs.validateBoard.call(void 0, board);
1003
1099
  }
1004
1100
  function addReviewer(members, actor) {
1005
1101
  if (actor.kind !== "human" || !actor.id) return;
@@ -1009,27 +1105,27 @@ function addReviewer(members, actor) {
1009
1105
  }
1010
1106
  function validateOptions(options) {
1011
1107
  if (options === void 0) return;
1012
- _chunk4KF7KUAIcjs.requireValue.call(void 0, options && typeof options === "object" && !Array.isArray(options) && Object.keys(options).length <= 16, "INVALID_PREPARATION_OPTIONS");
1108
+ _chunkRBOER6EWcjs.requireValue.call(void 0, options && typeof options === "object" && !Array.isArray(options) && Object.keys(options).length <= 16, "INVALID_PREPARATION_OPTIONS");
1013
1109
  for (const [key, value] of Object.entries(options)) {
1014
- _chunk4KF7KUAIcjs.requireValue.call(void 0, /^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(key) && typeof value === "string" && value.length <= 4096, "INVALID_PREPARATION_OPTIONS");
1110
+ _chunkRBOER6EWcjs.requireValue.call(void 0, /^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(key) && typeof value === "string" && value.length <= 4096, "INVALID_PREPARATION_OPTIONS");
1015
1111
  }
1016
1112
  }
1017
1113
 
1018
1114
  // src/workflow-continuation.ts
1019
1115
  function continueExecution(state, command, actor, now, apply) {
1020
1116
  requireCoordinator(state, actor);
1021
- _chunk4KF7KUAIcjs.identity.call(void 0, command.dispatchId);
1117
+ _chunkRBOER6EWcjs.identity.call(void 0, command.dispatchId);
1022
1118
  const workflow = state.workflow, previous = workflow.dispatches[command.previousDispatchId];
1023
- _chunk4KF7KUAIcjs.requireValue.call(void 0, previous && ["failed", "cancelled"].includes(previous.outcome), "EXECUTION_NOT_CONTINUABLE");
1024
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !workflow.dispatches[command.dispatchId], "DISPATCH_EXISTS");
1119
+ _chunkRBOER6EWcjs.requireValue.call(void 0, previous && ["failed", "cancelled"].includes(previous.outcome), "EXECUTION_NOT_CONTINUABLE");
1120
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !workflow.dispatches[command.dispatchId], "DISPATCH_EXISTS");
1025
1121
  const item = state.board.items.find((item2) => item2.id === previous.itemId), plan2 = workflow.plans[previous.planId];
1026
- _chunk4KF7KUAIcjs.requireValue.call(void 0, item && ["backlog", "open"].includes(item.status) && !item.owner, "ITEM_NOT_CONTINUABLE");
1122
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item && ["backlog", "open"].includes(item.status) && !item.owner, "ITEM_NOT_CONTINUABLE");
1027
1123
  const attempts = Object.values(workflow.dispatches).filter((row) => row.itemId === item.id);
1028
- _chunk4KF7KUAIcjs.requireValue.call(void 0, attempts.every((row) => row.attempt <= previous.attempt), "STALE_CONTINUATION");
1029
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !attempts.some((row) => ["prepared", "running", "unknown", "succeeded"].includes(row.outcome)), "EXECUTION_UNSETTLED");
1030
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _optionalChain([plan2, 'optionalAccess', _191 => _191.revision]) === previous.planRevision && _optionalChain([plan2, 'access', _192 => _192.definitions, 'access', _193 => _193[item.id], 'optionalAccess', _194 => _194.digest]) === previous.definitionDigest, "PLAN_CHANGED");
1031
- _chunk4KF7KUAIcjs.requireValue.call(void 0, command.instruction === void 0 || typeof command.instruction === "string" && command.instruction.trim().length > 0 && command.instruction.length <= 8e3, "INVALID_CONTINUATION_INSTRUCTION");
1032
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !item.blocked || item.blocked.reason === (_nullishCoalesce(previous.code, () => ( "EXECUTION_FAILED"))), "ITEM_BLOCKED");
1124
+ _chunkRBOER6EWcjs.requireValue.call(void 0, attempts.every((row) => row.attempt <= previous.attempt), "STALE_CONTINUATION");
1125
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !attempts.some((row) => ["prepared", "running", "unknown", "succeeded"].includes(row.outcome)), "EXECUTION_UNSETTLED");
1126
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _optionalChain([plan2, 'optionalAccess', _220 => _220.revision]) === previous.planRevision && _optionalChain([plan2, 'access', _221 => _221.definitions, 'access', _222 => _222[item.id], 'optionalAccess', _223 => _223.digest]) === previous.definitionDigest, "PLAN_CHANGED");
1127
+ _chunkRBOER6EWcjs.requireValue.call(void 0, command.instruction === void 0 || typeof command.instruction === "string" && command.instruction.trim().length > 0 && command.instruction.length <= 8e3, "INVALID_CONTINUATION_INSTRUCTION");
1128
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !item.blocked || item.blocked.reason === (_nullishCoalesce(previous.code, () => ( "EXECUTION_FAILED"))), "ITEM_BLOCKED");
1033
1129
  delete item.blocked;
1034
1130
  if (item.status === "backlog") apply({ type: "set-stage", itemId: item.id, stage: "open" });
1035
1131
  apply({ type: "claim", itemId: item.id, estimate: item.estimate }, previous.principal);
@@ -1055,16 +1151,16 @@ function isWorkflowCommand(command) {
1055
1151
  return ["publish-plan", "prepare-dispatch", "continue-execution", "observe-execution", "accept-execution"].includes(command.type);
1056
1152
  }
1057
1153
  function protectWorkflowItem(state, command) {
1058
- if (command.type === "configure-automation" && Object.values(_nullishCoalesce(_optionalChain([state, 'access', _195 => _195.workflow, 'optionalAccess', _196 => _196.dispatches]), () => ( {}))).some((dispatch) => ["prepared", "running", "unknown", "succeeded"].includes(dispatch.outcome))) {
1059
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _chunkPSKQAFDFcjs.sameAutomationBinding.call(void 0, state.board.automation, command.settings), "PLAN_EXECUTION_UNSETTLED");
1154
+ if (command.type === "configure-automation" && Object.values(_nullishCoalesce(_optionalChain([state, 'access', _224 => _224.workflow, 'optionalAccess', _225 => _225.dispatches]), () => ( {}))).some((dispatch) => ["prepared", "running", "unknown", "succeeded"].includes(dispatch.outcome))) {
1155
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _chunk7KDOTBRXcjs.sameAutomationBinding.call(void 0, state.board.automation, command.settings), "PLAN_EXECUTION_UNSETTLED");
1060
1156
  }
1061
1157
  if (!("itemId" in command) || !command.itemId || !state.workflow) return;
1062
1158
  const plan2 = Object.values(state.workflow.plans).find((plan3) => plan3.itemIds.includes(command.itemId));
1063
1159
  if (!plan2) return;
1064
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !["edit-item", "plan-item", "review-amendment"].includes(command.type), "PLAN_ITEM_CHANGED_REQUIRES_NEW_ID");
1065
- if (plan2.sealed) _chunk4KF7KUAIcjs.requireValue.call(void 0, !["claim", "submit", "review", "close-plan"].includes(command.type), "WORKFLOW_COMMAND_REQUIRED");
1160
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !["edit-item", "plan-item", "review-amendment"].includes(command.type), "PLAN_ITEM_CHANGED_REQUIRES_NEW_ID");
1161
+ if (plan2.sealed) _chunkRBOER6EWcjs.requireValue.call(void 0, !["claim", "submit", "review", "close-plan"].includes(command.type), "WORKFLOW_COMMAND_REQUIRED");
1066
1162
  const live = Object.values(state.workflow.dispatches).some((dispatch) => dispatch.itemId === command.itemId && ["prepared", "running", "unknown", "succeeded"].includes(dispatch.outcome));
1067
- if (live) _chunk4KF7KUAIcjs.requireValue.call(void 0, !["request-transfer", "accept-transfer", "release-item", "cancel-item"].includes(command.type), "EXECUTION_UNSETTLED");
1163
+ if (live) _chunkRBOER6EWcjs.requireValue.call(void 0, !["delete-item", "request-transfer", "accept-transfer", "release-item", "cancel-item"].includes(command.type), "EXECUTION_UNSETTLED");
1068
1164
  }
1069
1165
  function applyWorkflow(state, command, actor, now, apply) {
1070
1166
  state.workflow ??= { plans: {}, dispatches: {}, ready: [], completedPlans: [] };
@@ -1072,7 +1168,7 @@ function applyWorkflow(state, command, actor, now, apply) {
1072
1168
  if (command.type === "publish-plan") publishPlan(state, command.plan, actor, apply);
1073
1169
  else if (command.type === "prepare-dispatch") prepare(state, command, actor, now, apply);
1074
1170
  else if (command.type === "continue-execution") {
1075
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !_optionalChain([state, 'access', _197 => _197.board, 'access', _198 => _198.executionControl, 'optionalAccess', _199 => _199.paused]), "BOARD_EXECUTION_PAUSED");
1171
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !_optionalChain([state, 'access', _226 => _226.board, 'access', _227 => _227.executionControl, 'optionalAccess', _228 => _228.paused]), "BOARD_EXECUTION_PAUSED");
1076
1172
  continueExecution(state, command, actor, now, apply);
1077
1173
  } else if (command.type === "observe-execution") changed = observe(state, command, actor, now);
1078
1174
  else accept(state, command, actor, apply);
@@ -1080,45 +1176,47 @@ function applyWorkflow(state, command, actor, now, apply) {
1080
1176
  return changed;
1081
1177
  }
1082
1178
  function prepare(state, command, actor, now, apply) {
1083
- _chunk4KF7KUAIcjs.identity.call(void 0, command.dispatchId);
1179
+ _chunkRBOER6EWcjs.identity.call(void 0, command.dispatchId);
1084
1180
  const workflow = state.workflow;
1085
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !workflow.dispatches[command.dispatchId], "DISPATCH_EXISTS");
1181
+ const controlled = state.board.items.find((item2) => item2.id === command.itemId);
1182
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !_optionalChain([controlled, 'optionalAccess', _229 => _229.control]) || controlled.control.action === "resume" && controlled.control.state === "resumed", "TASK_CONTROL_PENDING");
1183
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !workflow.dispatches[command.dispatchId], "DISPATCH_EXISTS");
1086
1184
  refreshReady(state);
1087
- _chunk4KF7KUAIcjs.requireValue.call(void 0, workflow.ready.includes(command.itemId), "WORK_NOT_READY");
1185
+ _chunkRBOER6EWcjs.requireValue.call(void 0, workflow.ready.includes(command.itemId), "WORK_NOT_READY");
1088
1186
  const plan2 = Object.values(workflow.plans).find((plan3) => plan3.itemIds.includes(command.itemId));
1089
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !Object.values(workflow.dispatches).some((dispatch) => dispatch.itemId === command.itemId && ["prepared", "running", "unknown", "succeeded"].includes(dispatch.outcome)), "EXECUTION_UNSETTLED");
1187
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !Object.values(workflow.dispatches).some((dispatch) => dispatch.itemId === command.itemId && ["prepared", "running", "unknown", "succeeded"].includes(dispatch.outcome)), "EXECUTION_UNSETTLED");
1090
1188
  const item = state.board.items.find((item2) => item2.id === command.itemId);
1091
1189
  if (item.status === "backlog") apply({ type: "set-stage", itemId: item.id, stage: "open" });
1092
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !_chunkKYNYPKKHcjs.taskEditing.call(void 0, item, now), "EDIT_LEASE_ACTIVE");
1093
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !_optionalChain([state, 'access', _200 => _200.board, 'access', _201 => _201.executionControl, 'optionalAccess', _202 => _202.paused]), "BOARD_EXECUTION_PAUSED");
1094
- if (command.trigger === "automatic") _chunk4KF7KUAIcjs.requireValue.call(void 0, _chunkLSE6JG5Icjs.boardAllowsStart.call(void 0, state.board, item) && _chunkKYNYPKKHcjs.taskDue.call(void 0, item, now), "START_NOT_DUE");
1095
- item.launch ??= { startAt: _chunkKYNYPKKHcjs.taskStartAt.call(void 0, item) };
1190
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !_chunkAOHQCX7Kcjs.taskEditing.call(void 0, item, now), "EDIT_LEASE_ACTIVE");
1191
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !_optionalChain([state, 'access', _230 => _230.board, 'access', _231 => _231.executionControl, 'optionalAccess', _232 => _232.paused]), "BOARD_EXECUTION_PAUSED");
1192
+ if (command.trigger === "automatic") _chunkRBOER6EWcjs.requireValue.call(void 0, _chunkAOHQCX7Kcjs.boardAllowsStart.call(void 0, state.board, item) && _chunkAOHQCX7Kcjs.taskDue.call(void 0, item, now), "START_NOT_DUE");
1193
+ item.launch ??= { startAt: _chunkAOHQCX7Kcjs.taskStartAt.call(void 0, item) };
1096
1194
  item.launch.admittedAt ??= now;
1097
1195
  apply({ type: "claim", itemId: item.id, estimate: command.estimate });
1098
1196
  const inputs = {};
1099
1197
  for (const [name, binding] of Object.entries(_nullishCoalesce(plan2.definitions[item.id].inputs, () => ( {})))) {
1100
1198
  const producer = Object.values(workflow.dispatches).reverse().find((dispatch) => dispatch.itemId === binding.fromItemId && dispatch.outcome === "accepted");
1101
- const output = _optionalChain([producer, 'optionalAccess', _203 => _203.outputs, 'optionalAccess', _204 => _204.find, 'call', _205 => _205((output2) => output2.name === binding.output)]);
1102
- _chunk4KF7KUAIcjs.requireValue.call(void 0, output, "DEPENDENCY_OUTPUT_MISSING");
1199
+ const output = _optionalChain([producer, 'optionalAccess', _233 => _233.outputs, 'optionalAccess', _234 => _234.find, 'call', _235 => _235((output2) => output2.name === binding.output)]);
1200
+ _chunkRBOER6EWcjs.requireValue.call(void 0, output, "DEPENDENCY_OUTPUT_MISSING");
1103
1201
  inputs[name] = structuredClone(output);
1104
1202
  }
1105
1203
  const attempt = Math.max(0, ...Object.values(workflow.dispatches).filter((dispatch) => dispatch.itemId === item.id).map((dispatch) => dispatch.attempt)) + 1;
1106
- workflow.dispatches[command.dispatchId] = { id: command.dispatchId, itemId: item.id, itemRevision: item.revision, planId: plan2.id, planRevision: plan2.revision, principal: _chunk4KF7KUAIcjs.principal.call(void 0, actor), definitionDigest: plan2.definitions[item.id].digest, attempt, fence: item.owner.token, preparedAt: now, outcome: "prepared", inputs };
1204
+ workflow.dispatches[command.dispatchId] = { id: command.dispatchId, itemId: item.id, itemRevision: item.revision, planId: plan2.id, planRevision: plan2.revision, principal: _chunkRBOER6EWcjs.principal.call(void 0, actor), definitionDigest: plan2.definitions[item.id].digest, attempt, fence: item.owner.token, preparedAt: now, outcome: "prepared", inputs };
1107
1205
  }
1108
1206
  function observe(state, command, actor, now) {
1109
1207
  requireCoordinator(state, actor);
1110
1208
  const dispatch = activeDispatch(state, command.dispatchId);
1111
- _chunk4KF7KUAIcjs.requireValue.call(void 0, command.fence === dispatch.fence && ["prepared", "running", "unknown"].includes(dispatch.outcome), "STALE_EXECUTION_RESULT");
1112
- _chunk4KF7KUAIcjs.requireValue.call(void 0, ["running", "unknown", "succeeded", "failed", "cancelled"].includes(command.outcome), "INVALID_EXECUTION_OUTCOME");
1113
- if (command.code !== void 0) _chunk4KF7KUAIcjs.requireValue.call(void 0, /^[A-Z][A-Z0-9_]{0,79}$/.test(command.code), "INVALID_ERROR_CODE");
1209
+ _chunkRBOER6EWcjs.requireValue.call(void 0, command.fence === dispatch.fence && ["prepared", "running", "unknown"].includes(dispatch.outcome), "STALE_EXECUTION_RESULT");
1210
+ _chunkRBOER6EWcjs.requireValue.call(void 0, ["running", "unknown", "succeeded", "failed", "cancelled"].includes(command.outcome), "INVALID_EXECUTION_OUTCOME");
1211
+ if (command.code !== void 0) _chunkRBOER6EWcjs.requireValue.call(void 0, /^[A-Z][A-Z0-9_]{0,79}$/.test(command.code), "INVALID_ERROR_CODE");
1114
1212
  const item = state.board.items.find((item2) => item2.id === dispatch.itemId);
1115
1213
  if (command.executionSessionId) {
1116
- _chunk4KF7KUAIcjs.identity.call(void 0, command.executionSessionId);
1117
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !dispatch.executionSessionId || dispatch.executionSessionId === command.executionSessionId, "EXECUTION_SESSION_LOCKED");
1214
+ _chunkRBOER6EWcjs.identity.call(void 0, command.executionSessionId);
1215
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !dispatch.executionSessionId || dispatch.executionSessionId === command.executionSessionId, "EXECUTION_SESSION_LOCKED");
1118
1216
  dispatch.executionSessionId = command.executionSessionId;
1119
1217
  }
1120
1218
  if (command.controlCapabilities) {
1121
- _chunk4KF7KUAIcjs.requireValue.call(void 0, ["boundary", "none"].includes(command.controlCapabilities.pause) && typeof command.controlCapabilities.resume === "boolean", "INVALID_CONTROL_CAPABILITIES");
1219
+ _chunkRBOER6EWcjs.requireValue.call(void 0, ["boundary", "none"].includes(command.controlCapabilities.pause) && typeof command.controlCapabilities.resume === "boolean", "INVALID_CONTROL_CAPABILITIES");
1122
1220
  dispatch.controlCapabilities = structuredClone(command.controlCapabilities);
1123
1221
  }
1124
1222
  const outputs = _nullishCoalesce(command.outputs, () => ( []));
@@ -1127,7 +1225,7 @@ function observe(state, command, actor, now) {
1127
1225
  if (!_chunk4XF6LQSUcjs.executionObservationChanged.call(void 0, dispatch, command)) return false;
1128
1226
  if (command.outcome === "succeeded") {
1129
1227
  const required = state.workflow.plans[dispatch.planId].definitions[item.id].outputs;
1130
- _chunk4KF7KUAIcjs.requireValue.call(void 0, required.every((name) => outputs.some((output) => output.name === name)), "REQUIRED_OUTPUT_MISSING");
1228
+ _chunkRBOER6EWcjs.requireValue.call(void 0, required.every((name) => outputs.some((output) => output.name === name)), "REQUIRED_OUTPUT_MISSING");
1131
1229
  item.status = state.board.policy.review === "assignee" ? "completed" : "review";
1132
1230
  if (item.status === "completed") item.closedAt = now;
1133
1231
  item.resultRef = `kanban:dispatch:${dispatch.id}`;
@@ -1147,7 +1245,8 @@ function observe(state, command, actor, now) {
1147
1245
  function accept(state, command, actor, apply) {
1148
1246
  requireCoordinator(state, actor);
1149
1247
  const dispatch = activeDispatch(state, command.dispatchId);
1150
- _chunk4KF7KUAIcjs.requireValue.call(void 0, dispatch.outcome === "succeeded", "EXECUTION_NOT_SUCCEEDED");
1248
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _optionalChain([state, 'access', _236 => _236.board, 'access', _237 => _237.items, 'access', _238 => _238.find, 'call', _239 => _239((item) => item.id === dispatch.itemId), 'optionalAccess', _240 => _240.control, 'optionalAccess', _241 => _241.action]) !== "cancel", "TASK_CANCELLING");
1249
+ _chunkRBOER6EWcjs.requireValue.call(void 0, dispatch.outcome === "succeeded", "EXECUTION_NOT_SUCCEEDED");
1151
1250
  apply({ type: "review", itemId: dispatch.itemId, accept: command.accept }, actor);
1152
1251
  dispatch.outcome = command.accept ? "accepted" : "rejected";
1153
1252
  if (!command.accept) {
@@ -1158,30 +1257,30 @@ function accept(state, command, actor, apply) {
1158
1257
  }
1159
1258
  function activeDispatch(state, id) {
1160
1259
  const dispatch = state.workflow.dispatches[id];
1161
- _chunk4KF7KUAIcjs.requireValue.call(void 0, dispatch, "DISPATCH_NOT_FOUND");
1260
+ _chunkRBOER6EWcjs.requireValue.call(void 0, dispatch, "DISPATCH_NOT_FOUND");
1162
1261
  const item = state.board.items.find((item2) => item2.id === dispatch.itemId), plan2 = state.workflow.plans[dispatch.planId];
1163
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _optionalChain([plan2, 'optionalAccess', _206 => _206.revision]) === dispatch.planRevision && _optionalChain([item, 'optionalAccess', _207 => _207.owner, 'optionalAccess', _208 => _208.token]) === dispatch.fence && _optionalChain([plan2, 'access', _209 => _209.definitions, 'access', _210 => _210[dispatch.itemId], 'optionalAccess', _211 => _211.digest]) === dispatch.definitionDigest, "STALE_EXECUTION_RESULT");
1262
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _optionalChain([plan2, 'optionalAccess', _242 => _242.revision]) === dispatch.planRevision && _optionalChain([item, 'optionalAccess', _243 => _243.owner, 'optionalAccess', _244 => _244.token]) === dispatch.fence && _optionalChain([plan2, 'access', _245 => _245.definitions, 'access', _246 => _246[dispatch.itemId], 'optionalAccess', _247 => _247.digest]) === dispatch.definitionDigest, "STALE_EXECUTION_RESULT");
1164
1263
  return dispatch;
1165
1264
  }
1166
1265
  function validateOutputs(outputs) {
1167
- _chunk4KF7KUAIcjs.requireValue.call(void 0, Array.isArray(outputs) && outputs.length <= 100 && outputs.every((output) => output && typeof output === "object" && typeof output.name === "string") && new Set(outputs.map((output) => output.name)).size === outputs.length, "INVALID_OUTPUTS");
1168
- for (const output of outputs) _chunk4KF7KUAIcjs.requireValue.call(void 0, /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/.test(output.name) && typeof output.ref === "string" && output.ref.length > 0 && output.ref.length <= 2048 && /^[a-f0-9]{64}$/.test(output.sha256) && Number.isSafeInteger(output.bytes) && output.bytes >= 0, "INVALID_OUTPUT_REFERENCE");
1266
+ _chunkRBOER6EWcjs.requireValue.call(void 0, Array.isArray(outputs) && outputs.length <= 100 && outputs.every((output) => output && typeof output === "object" && typeof output.name === "string") && new Set(outputs.map((output) => output.name)).size === outputs.length, "INVALID_OUTPUTS");
1267
+ for (const output of outputs) _chunkRBOER6EWcjs.requireValue.call(void 0, /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/.test(output.name) && typeof output.ref === "string" && output.ref.length > 0 && output.ref.length <= 2048 && /^[a-f0-9]{64}$/.test(output.sha256) && Number.isSafeInteger(output.bytes) && output.bytes >= 0, "INVALID_OUTPUT_REFERENCE");
1169
1268
  }
1170
1269
  function refreshReady(state) {
1171
1270
  if (!state.workflow) return;
1172
1271
  const all = catalog(state), included = new Set(Object.values(state.workflow.plans).filter((plan2) => plan2.sealed).flatMap((plan2) => plan2.itemIds));
1173
- state.workflow.completedPlans = Object.values(state.workflow.plans).filter((plan2) => plan2.sealed && plan2.itemIds.every((id) => _optionalChain([all, 'access', _212 => _212.find, 'call', _213 => _213((item) => item.id === id), 'optionalAccess', _214 => _214.status]) === "completed")).map((plan2) => plan2.id);
1174
- state.workflow.ready = state.board.items.filter((item) => included.has(item.id) && _chunkPSKQAFDFcjs.executableWorkItem.call(void 0, state.board, item) && ["backlog", "open"].includes(item.status) && !item.owner && !item.blocked && _optionalChain([item, 'access', _215 => _215.control, 'optionalAccess', _216 => _216.action]) !== "pause" && (_nullishCoalesce(_optionalChain([item, 'access', _217 => _217.planning, 'optionalAccess', _218 => _218.dependencies]), () => ( []))).every((id) => _optionalChain([all, 'access', _219 => _219.find, 'call', _220 => _220((other) => other.id === id), 'optionalAccess', _221 => _221.status]) === "completed")).map((item) => item.id);
1272
+ state.workflow.completedPlans = Object.values(state.workflow.plans).filter((plan2) => plan2.sealed && plan2.itemIds.every((id) => _optionalChain([all, 'access', _248 => _248.find, 'call', _249 => _249((item) => item.id === id), 'optionalAccess', _250 => _250.status]) === "completed")).map((plan2) => plan2.id);
1273
+ state.workflow.ready = state.board.items.filter((item) => included.has(item.id) && _chunk7KDOTBRXcjs.executableWorkItem.call(void 0, state.board, item) && ["backlog", "open"].includes(item.status) && !item.owner && !item.blocked && (!item.control || item.control.action === "resume" && item.control.state === "resumed") && (_nullishCoalesce(_optionalChain([item, 'access', _251 => _251.planning, 'optionalAccess', _252 => _252.dependencies]), () => ( []))).every((id) => _optionalChain([all, 'access', _253 => _253.find, 'call', _254 => _254((other) => other.id === id), 'optionalAccess', _255 => _255.status]) === "completed")).map((item) => item.id);
1175
1274
  }
1176
1275
 
1177
1276
  // src/transitions.ts
1178
1277
  function transition(state, item, command, actor, now, token) {
1179
- _chunk4KF7KUAIcjs.requireValue.call(void 0, item.status !== "completed" && item.status !== "cancelled", "ITEM_COMPLETED");
1278
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item.status !== "completed" && item.status !== "cancelled", "ITEM_COMPLETED");
1180
1279
  if (command.type === "claim" || command.type === "accept-transfer") claim(state, item, command, actor, now, token);
1181
1280
  else if (command.type === "review") review(state, item, command.accept, actor, now);
1182
1281
  else {
1183
- _chunk4KF7KUAIcjs.owned.call(void 0, item, actor, command.token, now);
1184
- if (command.type === "submit") _chunk4KF7KUAIcjs.requireValue.call(void 0, catalog(state).filter((i) => i.planning.parentId === item.id).every(terminal), "CHILDREN_UNFINISHED");
1282
+ _chunkRBOER6EWcjs.owned.call(void 0, item, actor, command.token, now);
1283
+ if (command.type === "submit") _chunkRBOER6EWcjs.requireValue.call(void 0, catalog(state).filter((i) => i.planning.parentId === item.id).every(terminal), "CHILDREN_UNFINISHED");
1185
1284
  ownerUpdate(state.board, item, command, now, token);
1186
1285
  }
1187
1286
  if (command.type !== "renew") {
@@ -1190,34 +1289,35 @@ function transition(state, item, command, actor, now, token) {
1190
1289
  }
1191
1290
  }
1192
1291
  function claim(state, item, command, actor, now, token) {
1193
- const board = state.board, key = _chunk4KF7KUAIcjs.principalKey.call(void 0, _chunk4KF7KUAIcjs.principal.call(void 0, actor));
1194
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !_chunkKYNYPKKHcjs.taskEditing.call(void 0, item, now), "EDIT_LEASE_ACTIVE");
1195
- _chunk4KF7KUAIcjs.eligible.call(void 0, board, item, actor);
1292
+ const board = state.board, key = _chunkRBOER6EWcjs.principalKey.call(void 0, _chunkRBOER6EWcjs.principal.call(void 0, actor));
1293
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !_chunkAOHQCX7Kcjs.taskEditing.call(void 0, item, now), "EDIT_LEASE_ACTIVE");
1294
+ _chunkRBOER6EWcjs.eligible.call(void 0, board, item, actor);
1196
1295
  assertReady(state, item);
1197
- _chunk4KF7KUAIcjs.requireValue.call(void 0, command.estimate || board.policy.requireEstimate === false, "ESTIMATE_REQUIRED");
1198
- if (command.estimate) _chunk4KF7KUAIcjs.validateEstimate.call(void 0, command.estimate);
1296
+ _chunkRBOER6EWcjs.requireValue.call(void 0, command.estimate || board.policy.requireEstimate === false, "ESTIMATE_REQUIRED");
1297
+ if (command.estimate) _chunkRBOER6EWcjs.validateEstimate.call(void 0, command.estimate);
1199
1298
  const wip = board.items.filter((i) => i.status === "claimed" || i.status === "review");
1200
- if (command.type === "claim") _chunk4KF7KUAIcjs.requireValue.call(void 0, wip.length < limits(state).inProgress, "WIP_LIMIT");
1201
- _chunk4KF7KUAIcjs.requireValue.call(void 0, wip.filter((i) => i.id !== item.id && i.owner && _chunk4KF7KUAIcjs.assigneeKey.call(void 0, i.owner) === key).length < limits(state).perAssignee, _chunk4KF7KUAIcjs.principal.call(void 0, actor).kind === "agent" ? "AGENT_WIP_LIMIT" : "ASSIGNEE_WIP_LIMIT");
1202
- if (command.type === "claim") _chunk4KF7KUAIcjs.requireValue.call(void 0, item.status === "open" && !item.owner, "ALREADY_OWNED");
1299
+ if (command.type === "claim") _chunkRBOER6EWcjs.requireValue.call(void 0, wip.length < limits(state).inProgress, "WIP_LIMIT");
1300
+ _chunkRBOER6EWcjs.requireValue.call(void 0, wip.filter((i) => i.id !== item.id && i.owner && _chunkRBOER6EWcjs.assigneeKey.call(void 0, i.owner) === key).length < limits(state).perAssignee, _chunkRBOER6EWcjs.principal.call(void 0, actor).kind === "agent" ? "AGENT_WIP_LIMIT" : "ASSIGNEE_WIP_LIMIT");
1301
+ if (command.type === "claim") _chunkRBOER6EWcjs.requireValue.call(void 0, item.status === "open" && !item.owner, "ALREADY_OWNED");
1203
1302
  else {
1204
- _chunk4KF7KUAIcjs.requireValue.call(void 0, item.status === "claimed" && item.transfer && _chunk4KF7KUAIcjs.principalKey.call(void 0, transferTarget(item.transfer)) === key, "TRANSFER_NOT_OFFERED");
1205
- _chunk4KF7KUAIcjs.requireValue.call(void 0, item.transfer.expiresAt > now && item.owner && item.owner.leaseUntil > now, "TRANSFER_EXPIRED");
1206
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _chunk4KF7KUAIcjs.assigneeKey.call(void 0, item.owner) !== key, "SELF_TRANSFER");
1303
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item.status === "claimed" && item.transfer && _chunkRBOER6EWcjs.principalKey.call(void 0, transferTarget(item.transfer)) === key, "TRANSFER_NOT_OFFERED");
1304
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item.transfer.expiresAt > now && item.owner && item.owner.leaseUntil > now, "TRANSFER_EXPIRED");
1305
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _chunkRBOER6EWcjs.assigneeKey.call(void 0, item.owner) !== key, "SELF_TRANSFER");
1207
1306
  }
1208
1307
  item.owner = { ...actor, principalId: key, token, claimedAt: now, leaseUntil: now + board.policy.leaseMs };
1209
1308
  item.estimate = command.estimate;
1210
1309
  item.status = "claimed";
1211
1310
  item.progressAt = now;
1212
1311
  delete item.transfer;
1213
- if (actor.sessionId) _chunk4KF7KUAIcjs.participant.call(void 0, item.participants, actor.sessionId, actor.agentId, "owner", true, now);
1312
+ if (actor.sessionId) _chunkRBOER6EWcjs.participant.call(void 0, item.participants, actor.sessionId, actor.agentId, "owner", true, now);
1214
1313
  }
1215
1314
  function review(state, item, accept2, actor, now) {
1216
- _chunk4KF7KUAIcjs.requireValue.call(void 0, item.status === "review", "NOT_IN_REVIEW");
1217
- const key = _chunk4KF7KUAIcjs.principalKey.call(void 0, _chunk4KF7KUAIcjs.principal.call(void 0, actor));
1218
- const registered = actor.sessionId && item.participants.some((p) => p.sessionId === actor.sessionId && p.roles.includes("reviewer")) || _optionalChain([state, 'access', _222 => _222.board, 'access', _223 => _223.members, 'optionalAccess', _224 => _224.some, 'call', _225 => _225((m) => _chunk4KF7KUAIcjs.principalKey.call(void 0, m) === key && _optionalChain([m, 'access', _226 => _226.roles, 'optionalAccess', _227 => _227.includes, 'call', _228 => _228("reviewer")]))]);
1219
- _chunk4KF7KUAIcjs.requireValue.call(void 0, registered, "REVIEWER_REQUIRED");
1220
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !item.owner || _chunk4KF7KUAIcjs.assigneeKey.call(void 0, item.owner) !== key, "INDEPENDENT_REVIEW_REQUIRED");
1315
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _optionalChain([item, 'access', _256 => _256.control, 'optionalAccess', _257 => _257.action]) !== "cancel", "TASK_CANCELLING");
1316
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item.status === "review", "NOT_IN_REVIEW");
1317
+ const key = _chunkRBOER6EWcjs.principalKey.call(void 0, _chunkRBOER6EWcjs.principal.call(void 0, actor));
1318
+ const registered = actor.sessionId && item.participants.some((p) => p.sessionId === actor.sessionId && p.roles.includes("reviewer")) || _optionalChain([state, 'access', _258 => _258.board, 'access', _259 => _259.members, 'optionalAccess', _260 => _260.some, 'call', _261 => _261((m) => _chunkRBOER6EWcjs.principalKey.call(void 0, m) === key && _optionalChain([m, 'access', _262 => _262.roles, 'optionalAccess', _263 => _263.includes, 'call', _264 => _264("reviewer")]))]);
1319
+ _chunkRBOER6EWcjs.requireValue.call(void 0, registered, "REVIEWER_REQUIRED");
1320
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !item.owner || _chunkRBOER6EWcjs.assigneeKey.call(void 0, item.owner) !== key, "INDEPENDENT_REVIEW_REQUIRED");
1221
1321
  item.status = accept2 ? "completed" : state.board.items.filter((i) => i.status === "open").length < limits(state).ready ? "open" : "backlog";
1222
1322
  if (accept2) item.closedAt = now;
1223
1323
  if (!accept2) {
@@ -1233,11 +1333,11 @@ function ownerUpdate(board, item, command, now, token) {
1233
1333
  item.owner.leaseUntil = now + board.policy.leaseMs;
1234
1334
  break;
1235
1335
  case "progress":
1236
- _chunk4KF7KUAIcjs.requireValue.call(void 0, Number.isFinite(command.workUnits) && command.workUnits >= item.workUnits, "INVALID_WORK_UNITS");
1336
+ _chunkRBOER6EWcjs.requireValue.call(void 0, Number.isFinite(command.workUnits) && command.workUnits >= item.workUnits, "INVALID_WORK_UNITS");
1237
1337
  item.workUnits = command.workUnits;
1238
1338
  item.progressAt = now;
1239
1339
  if (command.estimate) {
1240
- _chunk4KF7KUAIcjs.validateEstimate.call(void 0, command.estimate);
1340
+ _chunkRBOER6EWcjs.validateEstimate.call(void 0, command.estimate);
1241
1341
  item.estimate = command.estimate;
1242
1342
  }
1243
1343
  break;
@@ -1245,7 +1345,7 @@ function ownerUpdate(board, item, command, now, token) {
1245
1345
  requestTransfer(board, item, command, now, token);
1246
1346
  break;
1247
1347
  case "submit":
1248
- _chunk4KF7KUAIcjs.text.call(void 0, command.resultRef);
1348
+ _chunkRBOER6EWcjs.text.call(void 0, command.resultRef);
1249
1349
  item.resultRef = command.resultRef;
1250
1350
  item.status = board.policy.review === "assignee" ? "completed" : "review";
1251
1351
  if (item.status === "completed") item.closedAt = now;
@@ -1254,11 +1354,11 @@ function ownerUpdate(board, item, command, now, token) {
1254
1354
  }
1255
1355
  }
1256
1356
  function requestTransfer(board, item, command, now, token) {
1257
- _chunk4KF7KUAIcjs.requireValue.call(void 0, Boolean(command.target) !== Boolean(command.agentId), "TRANSFER_TARGET_REQUIRED");
1258
- const target = _nullishCoalesce(command.target, () => ( { kind: "agent", id: command.agentId })), key = _chunk4KF7KUAIcjs.principalKey.call(void 0, target);
1259
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _chunk4KF7KUAIcjs.candidates.call(void 0, board, item).some((p) => _chunk4KF7KUAIcjs.principalKey.call(void 0, p) === key), "AGENT_NOT_ELIGIBLE");
1260
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _chunk4KF7KUAIcjs.assigneeKey.call(void 0, item.owner) !== key, "SELF_TRANSFER");
1261
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !item.transfer, "TRANSFER_ALREADY_PENDING");
1357
+ _chunkRBOER6EWcjs.requireValue.call(void 0, Boolean(command.target) !== Boolean(command.agentId), "TRANSFER_TARGET_REQUIRED");
1358
+ const target = _nullishCoalesce(command.target, () => ( { kind: "agent", id: command.agentId })), key = _chunkRBOER6EWcjs.principalKey.call(void 0, target);
1359
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _chunkRBOER6EWcjs.candidates.call(void 0, board, item).some((p) => _chunkRBOER6EWcjs.principalKey.call(void 0, p) === key), "AGENT_NOT_ELIGIBLE");
1360
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _chunkRBOER6EWcjs.assigneeKey.call(void 0, item.owner) !== key, "SELF_TRANSFER");
1361
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !item.transfer, "TRANSFER_ALREADY_PENDING");
1262
1362
  item.transfer = { id: token, target, ...target.kind === "agent" ? { agentId: target.id } : {}, requestedAt: now, expiresAt: now + board.policy.transferTimeoutMs };
1263
1363
  }
1264
1364
  function transferTarget(value) {
@@ -1267,8 +1367,10 @@ function transferTarget(value) {
1267
1367
 
1268
1368
  // src/reducer.ts
1269
1369
  function reduce(state, command, actor, operationId, now, token, workflowInternal = false) {
1270
- _chunk4KF7KUAIcjs.requireValue.call(void 0, state.board.deletedAt === void 0, "BOARD_DELETED");
1370
+ _chunkRBOER6EWcjs.requireValue.call(void 0, state.board.deletedAt === void 0, "BOARD_DELETED");
1271
1371
  numberEntities(state);
1372
+ protectStoppedBoard(state, command);
1373
+ if ("itemId" in command && command.itemId) _chunkRBOER6EWcjs.requireValue.call(void 0, _optionalChain([state, 'access', _265 => _265.board, 'access', _266 => _266.items, 'access', _267 => _267.find, 'call', _268 => _268((i) => i.id === command.itemId), 'optionalAccess', _269 => _269.deletedAt]) === void 0, "ITEM_DELETED");
1272
1374
  if (!workflowInternal) protectWorkflowItem(state, command);
1273
1375
  const board = state.board;
1274
1376
  if (command.type === "delete-board") return deleteBoard(state, actor, operationId, now);
@@ -1278,8 +1380,18 @@ function reduce(state, command, actor, operationId, now, token, workflowInternal
1278
1380
  return state;
1279
1381
  }
1280
1382
  let recordEvent = command.type !== "renew";
1281
- if (command.type === "set-board-control") setBoardControl(state, command, actor, now, token);
1282
- else if (taskCommand(command)) applyTaskCommand(state, command, actor, now);
1383
+ if (command.type === "request-board-stop" || command.type === "observe-board-stop") stopBoard(state, command, actor, now);
1384
+ else if (command.type === "set-board-control") setBoardControl(state, command, actor, now, token);
1385
+ else if (command.type === "delete-item") {
1386
+ const item = itemFor(board, command.itemId);
1387
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _chunkRBOER6EWcjs.principal.call(void 0, actor).kind === "human", "FORBIDDEN");
1388
+ _chunkRBOER6EWcjs.requireValue.call(void 0, terminal(item), "ITEM_DELETE_REQUIRES_CLOSED");
1389
+ delete item.owner;
1390
+ delete item.transfer;
1391
+ item.deletedAt = now;
1392
+ item.updatedAt = now;
1393
+ item.revision++;
1394
+ } else if (taskCommand(command)) applyTaskCommand(state, command, actor, now);
1283
1395
  else if (isWorkflowCommand(command)) recordEvent = applyWorkflow(state, command, actor, now, (inner, owner = actor) => {
1284
1396
  reduce(state, inner, owner, operationId, now, token, true);
1285
1397
  });
@@ -1294,13 +1406,13 @@ function reduce(state, command, actor, operationId, now, token, workflowInternal
1294
1406
  else if (command.type === "register-session") {
1295
1407
  const item = command.itemId ? itemFor(board, command.itemId) : void 0;
1296
1408
  const list = item ? item.participants : board.participants;
1297
- _chunk4KF7KUAIcjs.participant.call(void 0, list, command.sessionId, command.agentId, command.role, command.subscribed, now);
1409
+ _chunkRBOER6EWcjs.participant.call(void 0, list, command.sessionId, command.agentId, command.role, command.subscribed, now);
1298
1410
  if (item) item.revision++;
1299
1411
  } else if (command.type === "message") {
1300
- _chunk4KF7KUAIcjs.text.call(void 0, command.message);
1301
- command.recipientSessionIds.forEach(_chunk4KF7KUAIcjs.identity);
1412
+ _chunkRBOER6EWcjs.text.call(void 0, command.message);
1413
+ command.recipientSessionIds.forEach(_chunkRBOER6EWcjs.identity);
1302
1414
  if (command.itemId) itemFor(board, command.itemId);
1303
- _chunk4KF7KUAIcjs.requireValue.call(void 0, command.recipientSessionIds.every((id) => related(board).includes(id)), "UNKNOWN_RECIPIENT");
1415
+ _chunkRBOER6EWcjs.requireValue.call(void 0, command.recipientSessionIds.every((id) => related(board).includes(id)), "UNKNOWN_RECIPIENT");
1304
1416
  } else transition(state, itemFor(board, command.itemId), command, actor, now, token);
1305
1417
  numberEntities(state);
1306
1418
  refreshReady(state);
@@ -1311,7 +1423,7 @@ function reduce(state, command, actor, operationId, now, token, workflowInternal
1311
1423
  operationId,
1312
1424
  now,
1313
1425
  command.type,
1314
- "itemId" in command ? command.itemId : command.type === "create-item" ? command.item.id : "dispatchId" in command ? _optionalChain([state, 'access', _229 => _229.workflow, 'optionalAccess', _230 => _230.dispatches, 'access', _231 => _231[command.dispatchId], 'optionalAccess', _232 => _232.itemId]) : void 0,
1426
+ "itemId" in command ? command.itemId : command.type === "create-item" ? command.item.id : "dispatchId" in command ? _optionalChain([state, 'access', _270 => _270.workflow, 'optionalAccess', _271 => _271.dispatches, 'access', _272 => _272[command.dispatchId], 'optionalAccess', _273 => _273.itemId]) : void 0,
1315
1427
  eventData(command, state),
1316
1428
  command.type === "message" ? command.recipientSessionIds : void 0
1317
1429
  );
@@ -1321,45 +1433,45 @@ function reduce(state, command, actor, operationId, now, token, workflowInternal
1321
1433
  function createItem2(state, command, actor, now, token) {
1322
1434
  const { id, title, responsibility, acceptance, eligibleAgentIds, eligiblePrincipals, externalRefs } = command.item;
1323
1435
  const input = { id, title, responsibility, acceptance, eligibleAgentIds, eligiblePrincipals, externalRefs }, board = state.board;
1324
- _chunk4KF7KUAIcjs.identity.call(void 0, input.id);
1325
- _chunk4KF7KUAIcjs.text.call(void 0, input.title);
1326
- _chunk4KF7KUAIcjs.text.call(void 0, input.responsibility);
1327
- _chunk4KF7KUAIcjs.text.call(void 0, input.acceptance);
1328
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !board.items.some((i) => i.id === input.id) && !_optionalChain([state, 'access', _233 => _233.archiveIndex, 'optionalAccess', _234 => _234.some, 'call', _235 => _235((i) => i.id === input.id)]), "ITEM_EXISTS");
1329
- const item = { ...input, origin: { kind: "direct", principal: _chunk4KF7KUAIcjs.principal.call(void 0, actor) }, status: "backlog", revision: 1, createdAt: now, readyAt: now, updatedAt: now, workUnits: 0, participants: [] };
1330
- item.launch = { startAt: now + _chunkKYNYPKKHcjs.TASK_START_DELAY_MS };
1331
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _optionalChain([command, 'access', _236 => _236.launch, 'optionalAccess', _237 => _237.mode]) === void 0 || ["automatic", "manual"].includes(command.launch.mode), "INVALID_LAUNCH_MODE");
1332
- _chunk4KF7KUAIcjs.requireValue.call(void 0, _optionalChain([command, 'access', _238 => _238.launch, 'optionalAccess', _239 => _239.paused]) === void 0 || typeof command.launch.paused === "boolean", "INVALID_TASK_PAUSE");
1333
- if (_optionalChain([command, 'access', _240 => _240.launch, 'optionalAccess', _241 => _241.mode])) item.launch.mode = command.launch.mode;
1334
- if (_optionalChain([command, 'access', _242 => _242.launch, 'optionalAccess', _243 => _243.paused])) item.control = { id: "initial-" + token, action: "pause", state: "paused" };
1436
+ _chunkRBOER6EWcjs.identity.call(void 0, input.id);
1437
+ _chunkRBOER6EWcjs.text.call(void 0, input.title);
1438
+ _chunkRBOER6EWcjs.text.call(void 0, input.responsibility);
1439
+ _chunkRBOER6EWcjs.text.call(void 0, input.acceptance);
1440
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !board.items.some((i) => i.id === input.id) && !_optionalChain([state, 'access', _274 => _274.archiveIndex, 'optionalAccess', _275 => _275.some, 'call', _276 => _276((i) => i.id === input.id)]), "ITEM_EXISTS");
1441
+ const item = { ...input, origin: { kind: "direct", principal: _chunkRBOER6EWcjs.principal.call(void 0, actor) }, status: "backlog", revision: 1, createdAt: now, readyAt: now, updatedAt: now, workUnits: 0, participants: [] };
1442
+ item.launch = { startAt: now + _chunkAOHQCX7Kcjs.TASK_START_DELAY_MS };
1443
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _optionalChain([command, 'access', _277 => _277.launch, 'optionalAccess', _278 => _278.mode]) === void 0 || ["automatic", "manual"].includes(command.launch.mode), "INVALID_LAUNCH_MODE");
1444
+ _chunkRBOER6EWcjs.requireValue.call(void 0, _optionalChain([command, 'access', _279 => _279.launch, 'optionalAccess', _280 => _280.paused]) === void 0 || typeof command.launch.paused === "boolean", "INVALID_TASK_PAUSE");
1445
+ if (_optionalChain([command, 'access', _281 => _281.launch, 'optionalAccess', _282 => _282.mode])) item.launch.mode = command.launch.mode;
1446
+ if (_optionalChain([command, 'access', _283 => _283.launch, 'optionalAccess', _284 => _284.paused])) item.control = { id: "initial-" + token, action: "pause", state: "paused" };
1335
1447
  item.planning = _nullishCoalesce(command.planning, () => ( { ...plan(item), kind: _nullishCoalesce(board.defaultWorkType, () => ( "task")) }));
1336
1448
  const references = _nullishCoalesce(item.externalRefs, () => ( []));
1337
1449
  item.externalRefs = [];
1338
1450
  for (const reference of references) attachReference(item, reference);
1339
- _chunk4KF7KUAIcjs.validateCandidates.call(void 0, board, item, _chunk4KF7KUAIcjs.executable.call(void 0, board, item));
1451
+ _chunkRBOER6EWcjs.validateCandidates.call(void 0, board, item, _chunkRBOER6EWcjs.executable.call(void 0, board, item));
1340
1452
  validatePlan(state, item, item.planning);
1341
1453
  if (item.planning.parentId) {
1342
1454
  const parent = board.items.find((parent2) => parent2.id === item.planning.parentId);
1343
- if (_optionalChain([parent, 'access', _244 => _244.planning, 'optionalAccess', _245 => _245.execution]) !== "children") {
1455
+ if (_optionalChain([parent, 'access', _285 => _285.planning, 'optionalAccess', _286 => _286.execution]) !== "children") {
1344
1456
  parent.planning = { ...plan(parent), execution: "children" };
1345
1457
  parent.updatedAt = now;
1346
1458
  parent.revision++;
1347
1459
  }
1348
1460
  }
1349
- if (actor.sessionId) _chunk4KF7KUAIcjs.participant.call(void 0, item.participants, actor.sessionId, actor.agentId, "creator", true, now);
1461
+ if (actor.sessionId) _chunkRBOER6EWcjs.participant.call(void 0, item.participants, actor.sessionId, actor.agentId, "creator", true, now);
1350
1462
  board.items.push(item);
1351
1463
  if (command.stage === "open") setStage(state, item, "open", now);
1352
1464
  }
1353
1465
  function itemFor(board, id) {
1354
1466
  const item = board.items.find((value) => value.id === id);
1355
- _chunk4KF7KUAIcjs.requireValue.call(void 0, item, "ITEM_NOT_FOUND");
1467
+ _chunkRBOER6EWcjs.requireValue.call(void 0, item, "ITEM_NOT_FOUND");
1356
1468
  return item;
1357
1469
  }
1358
1470
  function related(board) {
1359
1471
  return [...new Set([...board.participants, ...board.items.flatMap((i) => i.participants)].map((p) => p.sessionId))];
1360
1472
  }
1361
1473
  function append2(state, actor, operationId, at, kind, itemId, data = {}, recipients) {
1362
- const archived = _nullishCoalesce(_optionalChain([state, 'access', _246 => _246.archiveWrites, 'optionalAccess', _247 => _247.flatMap, 'call', _248 => _248((write) => _nullishCoalesce(_optionalChain([write, 'access', _249 => _249.value, 'optionalAccess', _250 => _250.item, 'access', _251 => _251.participants]), () => ( [])))]), () => ( []));
1474
+ const archived = _nullishCoalesce(_optionalChain([state, 'access', _287 => _287.archiveWrites, 'optionalAccess', _288 => _288.flatMap, 'call', _289 => _289((write) => _nullishCoalesce(_optionalChain([write, 'access', _290 => _290.value, 'optionalAccess', _291 => _291.item, 'access', _292 => _292.participants]), () => ( [])))]), () => ( []));
1363
1475
  const members = [...archived, ...state.board.participants, ...state.board.items.filter((i) => i.id === itemId).flatMap((i) => i.participants)];
1364
1476
  state.events.push({
1365
1477
  sequence: ++state.sequence,
@@ -1381,7 +1493,7 @@ function scan(state, actor, operationId, now) {
1381
1493
  }
1382
1494
  if (terminal(item)) continue;
1383
1495
  for (const reason of escalationReasons(state.board, item, now)) {
1384
- const epoch = reason === "transfer-timeout" ? _optionalChain([item, 'access', _252 => _252.transfer, 'optionalAccess', _253 => _253.id]) : reason === "backlog-review" ? item.updatedAt : _nullishCoalesce(_optionalChain([item, 'access', _254 => _254.owner, 'optionalAccess', _255 => _255.token]), () => ( item.readyAt));
1496
+ const epoch = reason === "transfer-timeout" ? _optionalChain([item, 'access', _293 => _293.transfer, 'optionalAccess', _294 => _294.id]) : reason === "backlog-review" ? item.updatedAt : _nullishCoalesce(_optionalChain([item, 'access', _295 => _295.owner, 'optionalAccess', _296 => _296.token]), () => ( item.readyAt));
1385
1497
  const key = JSON.stringify([item.id, epoch, reason]);
1386
1498
  if (state.escalations.includes(key)) continue;
1387
1499
  state.escalations.push(key);
@@ -1404,7 +1516,7 @@ function scan(state, actor, operationId, now) {
1404
1516
  function escalationReasons(board, item, now) {
1405
1517
  const p = board.policy, result = [];
1406
1518
  if (item.status === "backlog" && p.backlogReviewMs && now - item.updatedAt >= p.backlogReviewMs) result.push("backlog-review");
1407
- if (_optionalChain([item, 'access', _256 => _256.planning, 'optionalAccess', _257 => _257.dueAt]) !== void 0 && now >= item.planning.dueAt) result.push("due-date");
1519
+ if (_optionalChain([item, 'access', _297 => _297.planning, 'optionalAccess', _298 => _298.dueAt]) !== void 0 && now >= item.planning.dueAt) result.push("due-date");
1408
1520
  if (item.blocked && now - item.blocked.at >= p.progressTimeoutMs) result.push("blocked-age");
1409
1521
  if (!item.blocked && item.status === "open" && now - item.readyAt >= p.claimTimeoutMs) result.push("unclaimed");
1410
1522
  if (item.status === "review" && now - item.updatedAt >= p.progressTimeoutMs) result.push("review-timeout");
@@ -1412,25 +1524,26 @@ function escalationReasons(board, item, now) {
1412
1524
  if (item.status !== "claimed" || !item.owner) return result;
1413
1525
  if (now >= item.owner.leaseUntil) result.push("lease-expired");
1414
1526
  if (now - (_nullishCoalesce(item.progressAt, () => ( item.owner.claimedAt))) >= p.progressTimeoutMs) result.push("no-progress");
1415
- if (now - item.owner.claimedAt >= Math.min(_nullishCoalesce(_optionalChain([item, 'access', _258 => _258.estimate, 'optionalAccess', _259 => _259.durationMs]), () => ( p.maxDurationMs)), p.maxDurationMs)) result.push("execution-timeout");
1416
- if ((_nullishCoalesce(_optionalChain([item, 'access', _260 => _260.estimate, 'optionalAccess', _261 => _261.complexity]), () => ( 0))) >= p.maxComplexity) result.push("complexity-threshold");
1417
- if (Math.max(item.workUnits, _nullishCoalesce(_optionalChain([item, 'access', _262 => _262.estimate, 'optionalAccess', _263 => _263.workUnits]), () => ( 0))) >= p.maxWorkUnits) result.push("work-threshold");
1418
- if ((_nullishCoalesce(_optionalChain([item, 'access', _264 => _264.estimate, 'optionalAccess', _265 => _265.durationMs]), () => ( 0))) >= p.maxDurationMs) result.push("duration-threshold");
1527
+ if (now - item.owner.claimedAt >= Math.min(_nullishCoalesce(_optionalChain([item, 'access', _299 => _299.estimate, 'optionalAccess', _300 => _300.durationMs]), () => ( p.maxDurationMs)), p.maxDurationMs)) result.push("execution-timeout");
1528
+ if ((_nullishCoalesce(_optionalChain([item, 'access', _301 => _301.estimate, 'optionalAccess', _302 => _302.complexity]), () => ( 0))) >= p.maxComplexity) result.push("complexity-threshold");
1529
+ if (Math.max(item.workUnits, _nullishCoalesce(_optionalChain([item, 'access', _303 => _303.estimate, 'optionalAccess', _304 => _304.workUnits]), () => ( 0))) >= p.maxWorkUnits) result.push("work-threshold");
1530
+ if ((_nullishCoalesce(_optionalChain([item, 'access', _305 => _305.estimate, 'optionalAccess', _306 => _306.durationMs]), () => ( 0))) >= p.maxDurationMs) result.push("duration-threshold");
1419
1531
  return result;
1420
1532
  }
1421
1533
  function eventData(command, state) {
1422
- if (command.type === "set-board-control") return { code: "BOARD_" + (_optionalChain([state, 'access', _266 => _266.board, 'access', _267 => _267.executionControl, 'optionalAccess', _268 => _268.paused]) ? "PAUSE_REQUESTED" : _optionalChain([state, 'access', _269 => _269.board, 'access', _270 => _270.executionControl, 'optionalAccess', _271 => _271.mode, 'optionalAccess', _272 => _272.toUpperCase, 'call', _273 => _273()])) };
1534
+ if (command.type === "request-board-stop" || command.type === "observe-board-stop") return { code: _optionalChain([state, 'access', _307 => _307.board, 'access', _308 => _308.lifecycle, 'optionalAccess', _309 => _309.code]), reason: _optionalChain([state, 'access', _310 => _310.board, 'access', _311 => _311.lifecycle, 'optionalAccess', _312 => _312.intent]), itemIds: state.board.items.filter((item) => _optionalChain([item, 'access', _313 => _313.control, 'optionalAccess', _314 => _314.action]) === "cancel").map((item) => item.id) };
1535
+ else if (command.type === "set-board-control") return { code: "BOARD_" + (_optionalChain([state, 'access', _315 => _315.board, 'access', _316 => _316.executionControl, 'optionalAccess', _317 => _317.paused]) ? "PAUSE_REQUESTED" : _optionalChain([state, 'access', _318 => _318.board, 'access', _319 => _319.executionControl, 'optionalAccess', _320 => _320.mode, 'optionalAccess', _321 => _321.toUpperCase, 'call', _322 => _322()])) };
1423
1536
  if (command.type === "apply-discovery") return discoveryEvent(state, command.batch);
1424
1537
  if (command.type === "report-analysis") return { code: command.status.code, reason: "analysis-" + command.status.state };
1425
1538
  if (command.type === "control-receipt") return { code: command.code, reason: "control-" + command.state };
1426
- if (isWorkflowCommand(command)) return { readyItemIds: _optionalChain([state, 'access', _274 => _274.workflow, 'optionalAccess', _275 => _275.ready]), ..."dispatchId" in command ? { dispatchId: command.dispatchId } : { planId: command.plan.id }, ..."outcome" in command ? { reason: `execution-${command.outcome}`, code: command.code, status: _optionalChain([state, 'access', _276 => _276.board, 'access', _277 => _277.items, 'access', _278 => _278.find, 'call', _279 => _279((item) => item.id === _optionalChain([state, 'access', _280 => _280.workflow, 'optionalAccess', _281 => _281.dispatches, 'access', _282 => _282[command.dispatchId], 'optionalAccess', _283 => _283.itemId])), 'optionalAccess', _284 => _284.status]) } : command.type === "accept-execution" ? { reason: command.accept ? "accepted" : "rejected" } : {} };
1539
+ if (isWorkflowCommand(command)) return { readyItemIds: _optionalChain([state, 'access', _323 => _323.workflow, 'optionalAccess', _324 => _324.ready]), ..."dispatchId" in command ? { dispatchId: command.dispatchId } : { planId: command.plan.id }, ..."outcome" in command ? { reason: `execution-${command.outcome}`, code: command.code, status: _optionalChain([state, 'access', _325 => _325.board, 'access', _326 => _326.items, 'access', _327 => _327.find, 'call', _328 => _328((item) => item.id === _optionalChain([state, 'access', _329 => _329.workflow, 'optionalAccess', _330 => _330.dispatches, 'access', _331 => _331[command.dispatchId], 'optionalAccess', _332 => _332.itemId])), 'optionalAccess', _333 => _333.status]) } : command.type === "accept-execution" ? { reason: command.accept ? "accepted" : "rejected" } : {} };
1427
1540
  if (command.type === "create-item") return { itemTitle: command.item.title };
1428
1541
  if (command.type === "link-reference") return { reference: command.reference };
1429
1542
  if (command.type === "block-item") return { reason: command.reason };
1430
1543
  if (command.type === "release-item") return { reason: command.next === "cancelled" ? "cancelled" : "released" };
1431
1544
  if (command.type === "review") return {
1432
1545
  reason: command.accept ? "accepted" : "rejected",
1433
- dispatchId: _optionalChain([Object, 'access', _285 => _285.values, 'call', _286 => _286(_nullishCoalesce(_optionalChain([state, 'access', _287 => _287.workflow, 'optionalAccess', _288 => _288.dispatches]), () => ( {}))), 'access', _289 => _289.find, 'call', _290 => _290((dispatch) => dispatch.itemId === command.itemId && dispatch.outcome === "succeeded"), 'optionalAccess', _291 => _291.id])
1546
+ dispatchId: _optionalChain([Object, 'access', _334 => _334.values, 'call', _335 => _335(_nullishCoalesce(_optionalChain([state, 'access', _336 => _336.workflow, 'optionalAccess', _337 => _337.dispatches]), () => ( {}))), 'access', _338 => _338.find, 'call', _339 => _339((dispatch) => dispatch.itemId === command.itemId && dispatch.outcome === "succeeded"), 'optionalAccess', _340 => _340.id])
1434
1547
  };
1435
1548
  if (command.type === "append-record") return { recordId: command.record.id, reason: command.record.kind === "decision" ? "decision-draft" : "log" };
1436
1549
  if (command.type === "review-record" || command.type === "link-record") return { recordId: command.recordId };
@@ -1446,15 +1559,16 @@ function eventData(command, state) {
1446
1559
  function discoveryEvent(state, batch) {
1447
1560
  return {
1448
1561
  itemIds: batch.changes.map((change) => change.itemId),
1449
- recordIds: _optionalChain([batch, 'access', _292 => _292.records, 'optionalAccess', _293 => _293.filter, 'call', _294 => _294((record) => _optionalChain([state, 'access', _295 => _295.records, 'optionalAccess', _296 => _296.some, 'call', _297 => _297((entry) => entry.id === record.id && entry.originRunId === batch.runId)])), 'access', _298 => _298.map, 'call', _299 => _299((record) => record.id)]),
1450
- ...state.board.items.some((item) => _optionalChain([item, 'access', _300 => _300.amendments, 'optionalAccess', _301 => _301.some, 'call', _302 => _302((proposal) => proposal.runId === batch.runId && proposal.status === "pending")])) ? { reason: "amendment-proposed" } : state.board.items.some((item) => item.status === "proposed" && _optionalChain([item, 'access', _303 => _303.origin, 'optionalAccess', _304 => _304.runId]) === batch.runId) ? { reason: "proposal-created" } : {}
1562
+ recordIds: _optionalChain([batch, 'access', _341 => _341.records, 'optionalAccess', _342 => _342.filter, 'call', _343 => _343((record) => _optionalChain([state, 'access', _344 => _344.records, 'optionalAccess', _345 => _345.some, 'call', _346 => _346((entry) => entry.id === record.id && entry.originRunId === batch.runId)])), 'access', _347 => _347.map, 'call', _348 => _348((record) => record.id)]),
1563
+ ...state.board.items.some((item) => _optionalChain([item, 'access', _349 => _349.amendments, 'optionalAccess', _350 => _350.some, 'call', _351 => _351((proposal) => proposal.runId === batch.runId && proposal.status === "pending")])) ? { reason: "amendment-proposed" } : state.board.items.some((item) => item.status === "proposed" && _optionalChain([item, 'access', _352 => _352.origin, 'optionalAccess', _353 => _353.runId]) === batch.runId) ? { reason: "proposal-created" } : {}
1451
1564
  };
1452
1565
  }
1453
1566
  function deleteBoard(state, actor, operationId, now) {
1454
- const owner = _chunk4KF7KUAIcjs.principal.call(void 0, actor), board = state.board;
1455
- _chunk4KF7KUAIcjs.requireValue.call(void 0, owner.kind === "human" && _optionalChain([board, 'access', _305 => _305.members, 'optionalAccess', _306 => _306.some, 'call', _307 => _307((member) => member.kind === owner.kind && member.id === owner.id && _optionalChain([member, 'access', _308 => _308.roles, 'optionalAccess', _309 => _309.includes, 'call', _310 => _310("coordinator")]))]), "COORDINATOR_REQUIRED");
1456
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !board.items.some((item) => item.owner || item.transfer || item.status === "claimed"), "BOARD_EXECUTION_ACTIVE");
1457
- _chunk4KF7KUAIcjs.requireValue.call(void 0, !Object.values(_nullishCoalesce(_optionalChain([state, 'access', _311 => _311.workflow, 'optionalAccess', _312 => _312.dispatches]), () => ( {}))).some((dispatch) => ["prepared", "running", "unknown", "succeeded"].includes(dispatch.outcome)), "BOARD_EXECUTION_UNSETTLED");
1567
+ const owner = _chunkRBOER6EWcjs.principal.call(void 0, actor), board = state.board;
1568
+ _chunkRBOER6EWcjs.requireValue.call(void 0, owner.kind === "human" && _optionalChain([board, 'access', _354 => _354.members, 'optionalAccess', _355 => _355.some, 'call', _356 => _356((member) => member.kind === owner.kind && member.id === owner.id && _optionalChain([member, 'access', _357 => _357.roles, 'optionalAccess', _358 => _358.includes, 'call', _359 => _359("coordinator")]))]), "COORDINATOR_REQUIRED");
1569
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !board.items.some((item) => !terminal(item) && (item.owner || item.transfer || item.status === "claimed")), "BOARD_EXECUTION_ACTIVE");
1570
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !Object.values(_nullishCoalesce(_optionalChain([state, 'access', _360 => _360.workflow, 'optionalAccess', _361 => _361.dispatches]), () => ( {}))).some((dispatch) => ["prepared", "running", "unknown", "succeeded"].includes(dispatch.outcome)), "BOARD_EXECUTION_UNSETTLED");
1571
+ _chunkRBOER6EWcjs.requireValue.call(void 0, !board.items.some((item) => _optionalChain([item, 'access', _362 => _362.control, 'optionalAccess', _363 => _363.action]) === "cancel" && item.control.state !== "cancelled" && !terminal(item)), "BOARD_CONTROL_UNSETTLED");
1458
1572
  board.deletedAt = now;
1459
1573
  board.revision++;
1460
1574
  if (board.automation) board.automation.enabled = false;
@@ -1495,4 +1609,4 @@ function deleteBoard(state, actor, operationId, now) {
1495
1609
 
1496
1610
 
1497
1611
  exports.summary = summary; exports.terminal = terminal; exports.catalog = catalog; exports.limits = limits; exports.proposeAmendment = proposeAmendment; exports.queryRecords = queryRecords; exports.recordSummary = recordSummary; exports.createBoardState = createBoardState; exports.boardKey = boardKey; exports.archiveKey = archiveKey; exports.rowKeys = rowKeys; exports.hydrate = hydrate; exports.encodeBoard = encodeBoard; exports.rowChanges = rowChanges; exports.receiptDigest = receiptDigest; exports.verifyReceipt = verifyReceipt; exports.encodeRow = encodeRow; exports.decodeRow = decodeRow; exports.indexedView = indexedView; exports.viewFromState = viewFromState; exports.boardCounterKey = boardCounterKey; exports.boardNumberKey = boardNumberKey; exports.counter = counter; exports.storedBoardNumber = storedBoardNumber; exports.patchBoardNumber = patchBoardNumber; exports.numberEntities = numberEntities; exports.allocateBoardNumber = allocateBoardNumber; exports.reduce = reduce; exports.related = related; exports.escalationReasons = escalationReasons;
1498
- //# sourceMappingURL=chunk-L44TM4EE.cjs.map
1612
+ //# sourceMappingURL=chunk-EYTVC2H5.cjs.map