chainlesschain 0.143.0 → 0.145.0

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 (133) hide show
  1. package/package.json +1 -1
  2. package/src/commands/a2a.js +196 -28
  3. package/src/commands/activitypub.js +157 -27
  4. package/src/commands/agent.js +587 -103
  5. package/src/commands/audit.js +206 -0
  6. package/src/commands/bi.js +152 -27
  7. package/src/commands/bm25.js +111 -27
  8. package/src/commands/browse.js +190 -29
  9. package/src/commands/ccron.js +128 -28
  10. package/src/commands/chat.js +207 -0
  11. package/src/commands/compliance.js +414 -34
  12. package/src/commands/compt.js +127 -29
  13. package/src/commands/consol.js +8 -2
  14. package/src/commands/cowork.js +580 -34
  15. package/src/commands/crosschain.js +182 -28
  16. package/src/commands/dao.js +182 -28
  17. package/src/commands/dlp.js +172 -27
  18. package/src/commands/economy.js +205 -50
  19. package/src/commands/evolution.js +203 -50
  20. package/src/commands/evomap.js +182 -27
  21. package/src/commands/fflag.js +74 -22
  22. package/src/commands/git.js +177 -37
  23. package/src/commands/hardening.js +209 -0
  24. package/src/commands/hmemory.js +204 -50
  25. package/src/commands/incentive.js +209 -0
  26. package/src/commands/inference.js +170 -34
  27. package/src/commands/itbudget.js +149 -33
  28. package/src/commands/kg.js +206 -0
  29. package/src/commands/lowcode.js +195 -38
  30. package/src/commands/marketplace.js +206 -0
  31. package/src/commands/matrix.js +179 -27
  32. package/src/commands/mcpscaf.js +145 -33
  33. package/src/commands/meminj.js +145 -33
  34. package/src/commands/nostr.js +178 -27
  35. package/src/commands/orchestrate.js +217 -0
  36. package/src/commands/orchgov.js +144 -33
  37. package/src/commands/pdfp.js +109 -27
  38. package/src/commands/perf.js +169 -32
  39. package/src/commands/perm.js +144 -33
  40. package/src/commands/pipeline.js +207 -52
  41. package/src/commands/planmode.js +141 -32
  42. package/src/commands/privacy.js +203 -0
  43. package/src/commands/promcomp.js +111 -27
  44. package/src/commands/recommend.js +177 -34
  45. package/src/commands/reputation.js +208 -0
  46. package/src/commands/sandbox.js +206 -0
  47. package/src/commands/seshhook.js +145 -33
  48. package/src/commands/seshsearch.js +141 -33
  49. package/src/commands/seshtail.js +144 -33
  50. package/src/commands/seshu.js +152 -33
  51. package/src/commands/sganal.js +123 -29
  52. package/src/commands/siem.js +201 -34
  53. package/src/commands/sla.js +212 -0
  54. package/src/commands/slotfill.js +146 -33
  55. package/src/commands/social.js +157 -32
  56. package/src/commands/stress.js +206 -0
  57. package/src/commands/svccont.js +145 -33
  58. package/src/commands/terraform.js +206 -0
  59. package/src/commands/tms.js +171 -33
  60. package/src/commands/topiccls.js +146 -33
  61. package/src/commands/uprof.js +141 -32
  62. package/src/commands/vcheck.js +122 -28
  63. package/src/commands/webfetch.js +141 -32
  64. package/src/commands/zkp.js +184 -28
  65. package/src/index.js +40 -0
  66. package/src/lib/a2a-protocol.js +319 -51
  67. package/src/lib/activitypub-bridge.js +288 -50
  68. package/src/lib/agent-economy.js +304 -51
  69. package/src/lib/app-builder.js +279 -46
  70. package/src/lib/audit-logger.js +321 -0
  71. package/src/lib/autonomous-agent.js +284 -48
  72. package/src/lib/bi-engine.js +283 -49
  73. package/src/lib/bm25-search.js +301 -49
  74. package/src/lib/browser-automation.js +296 -49
  75. package/src/lib/chat-core.js +336 -0
  76. package/src/lib/claude-code-bridge.js +341 -0
  77. package/src/lib/compliance-framework-reporter.js +305 -51
  78. package/src/lib/compliance-manager.js +330 -0
  79. package/src/lib/compression-telemetry.js +301 -49
  80. package/src/lib/content-recommender.js +317 -52
  81. package/src/lib/cowork-cron.js +298 -49
  82. package/src/lib/cowork-learning.js +333 -0
  83. package/src/lib/cowork-task-runner.js +308 -51
  84. package/src/lib/cowork-workflow.js +327 -0
  85. package/src/lib/cross-chain.js +311 -51
  86. package/src/lib/dao-governance.js +280 -46
  87. package/src/lib/dlp-engine.js +287 -49
  88. package/src/lib/evolution-system.js +278 -47
  89. package/src/lib/evomap-manager.js +280 -46
  90. package/src/lib/execution-backend.js +294 -48
  91. package/src/lib/feature-flags.js +294 -49
  92. package/src/lib/git-integration.js +285 -47
  93. package/src/lib/hardening-manager.js +341 -0
  94. package/src/lib/hierarchical-memory.js +284 -48
  95. package/src/lib/inference-network.js +308 -51
  96. package/src/lib/iteration-budget.js +302 -50
  97. package/src/lib/knowledge-graph.js +333 -0
  98. package/src/lib/matrix-bridge.js +281 -47
  99. package/src/lib/mcp-scaffold.js +318 -54
  100. package/src/lib/memory-injection.js +288 -49
  101. package/src/lib/nostr-bridge.js +286 -49
  102. package/src/lib/orchestrator.js +293 -48
  103. package/src/lib/pdf-parser.js +298 -49
  104. package/src/lib/perf-tuning.js +309 -50
  105. package/src/lib/permission-engine.js +287 -49
  106. package/src/lib/pipeline-orchestrator.js +289 -49
  107. package/src/lib/plan-mode.js +298 -51
  108. package/src/lib/privacy-computing.js +335 -0
  109. package/src/lib/reputation-optimizer.js +340 -0
  110. package/src/lib/sandbox-v2.js +327 -0
  111. package/src/lib/service-container.js +313 -52
  112. package/src/lib/session-consolidator.js +296 -49
  113. package/src/lib/session-hooks.js +312 -53
  114. package/src/lib/session-search.js +304 -51
  115. package/src/lib/session-tail.js +288 -49
  116. package/src/lib/session-usage.js +298 -52
  117. package/src/lib/siem-exporter.js +298 -51
  118. package/src/lib/skill-marketplace.js +345 -0
  119. package/src/lib/sla-manager.js +341 -0
  120. package/src/lib/slot-filler.js +303 -51
  121. package/src/lib/social-graph-analytics.js +295 -49
  122. package/src/lib/social-graph.js +272 -49
  123. package/src/lib/stress-tester.js +342 -0
  124. package/src/lib/sub-agent-registry.js +302 -53
  125. package/src/lib/task-model-selector.js +302 -50
  126. package/src/lib/terraform-manager.js +333 -0
  127. package/src/lib/todo-manager.js +281 -47
  128. package/src/lib/token-incentive.js +341 -0
  129. package/src/lib/topic-classifier.js +297 -49
  130. package/src/lib/user-profile.js +294 -50
  131. package/src/lib/version-checker.js +304 -50
  132. package/src/lib/web-fetch.js +292 -51
  133. package/src/lib/zkp-engine.js +286 -49
@@ -107,25 +107,53 @@ export function resetAllStores() {
107
107
 
108
108
  export const _deps = { _stores };
109
109
 
110
-
111
110
  // ===== V2 Surface: Todo Manager governance overlay (CLI v0.133.0) =====
112
111
  export const TODO_LIST_MATURITY_V2 = Object.freeze({
113
- DRAFT: "draft", ACTIVE: "active", PAUSED: "paused", ARCHIVED: "archived",
112
+ DRAFT: "draft",
113
+ ACTIVE: "active",
114
+ PAUSED: "paused",
115
+ ARCHIVED: "archived",
114
116
  });
115
117
  export const TODO_ITEM_LIFECYCLE_V2 = Object.freeze({
116
- PENDING: "pending", IN_PROGRESS: "in_progress", COMPLETED: "completed", FAILED: "failed", CANCELLED: "cancelled",
118
+ PENDING: "pending",
119
+ IN_PROGRESS: "in_progress",
120
+ COMPLETED: "completed",
121
+ FAILED: "failed",
122
+ CANCELLED: "cancelled",
117
123
  });
118
124
 
119
125
  const _tlListTrans = new Map([
120
- [TODO_LIST_MATURITY_V2.DRAFT, new Set([TODO_LIST_MATURITY_V2.ACTIVE, TODO_LIST_MATURITY_V2.ARCHIVED])],
121
- [TODO_LIST_MATURITY_V2.ACTIVE, new Set([TODO_LIST_MATURITY_V2.PAUSED, TODO_LIST_MATURITY_V2.ARCHIVED])],
122
- [TODO_LIST_MATURITY_V2.PAUSED, new Set([TODO_LIST_MATURITY_V2.ACTIVE, TODO_LIST_MATURITY_V2.ARCHIVED])],
126
+ [
127
+ TODO_LIST_MATURITY_V2.DRAFT,
128
+ new Set([TODO_LIST_MATURITY_V2.ACTIVE, TODO_LIST_MATURITY_V2.ARCHIVED]),
129
+ ],
130
+ [
131
+ TODO_LIST_MATURITY_V2.ACTIVE,
132
+ new Set([TODO_LIST_MATURITY_V2.PAUSED, TODO_LIST_MATURITY_V2.ARCHIVED]),
133
+ ],
134
+ [
135
+ TODO_LIST_MATURITY_V2.PAUSED,
136
+ new Set([TODO_LIST_MATURITY_V2.ACTIVE, TODO_LIST_MATURITY_V2.ARCHIVED]),
137
+ ],
123
138
  [TODO_LIST_MATURITY_V2.ARCHIVED, new Set()],
124
139
  ]);
125
140
  const _tlListTerminal = new Set([TODO_LIST_MATURITY_V2.ARCHIVED]);
126
141
  const _tlItemTrans = new Map([
127
- [TODO_ITEM_LIFECYCLE_V2.PENDING, new Set([TODO_ITEM_LIFECYCLE_V2.IN_PROGRESS, TODO_ITEM_LIFECYCLE_V2.CANCELLED])],
128
- [TODO_ITEM_LIFECYCLE_V2.IN_PROGRESS, new Set([TODO_ITEM_LIFECYCLE_V2.COMPLETED, TODO_ITEM_LIFECYCLE_V2.FAILED, TODO_ITEM_LIFECYCLE_V2.CANCELLED])],
142
+ [
143
+ TODO_ITEM_LIFECYCLE_V2.PENDING,
144
+ new Set([
145
+ TODO_ITEM_LIFECYCLE_V2.IN_PROGRESS,
146
+ TODO_ITEM_LIFECYCLE_V2.CANCELLED,
147
+ ]),
148
+ ],
149
+ [
150
+ TODO_ITEM_LIFECYCLE_V2.IN_PROGRESS,
151
+ new Set([
152
+ TODO_ITEM_LIFECYCLE_V2.COMPLETED,
153
+ TODO_ITEM_LIFECYCLE_V2.FAILED,
154
+ TODO_ITEM_LIFECYCLE_V2.CANCELLED,
155
+ ]),
156
+ ],
129
157
  [TODO_ITEM_LIFECYCLE_V2.COMPLETED, new Set()],
130
158
  [TODO_ITEM_LIFECYCLE_V2.FAILED, new Set()],
131
159
  [TODO_ITEM_LIFECYCLE_V2.CANCELLED, new Set()],
@@ -138,21 +166,45 @@ let _tlMaxPendingPerList = 40;
138
166
  let _tlListIdleMs = 7 * 24 * 60 * 60 * 1000;
139
167
  let _tlItemStuckMs = 24 * 60 * 60 * 1000;
140
168
 
141
- function _tlPos(n, lbl) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${lbl} must be positive integer`); return v; }
169
+ function _tlPos(n, lbl) {
170
+ const v = Math.floor(Number(n));
171
+ if (!Number.isFinite(v) || v <= 0)
172
+ throw new Error(`${lbl} must be positive integer`);
173
+ return v;
174
+ }
142
175
 
143
- export function setMaxActiveTodoListsPerOwnerV2(n) { _tlMaxActivePerOwner = _tlPos(n, "maxActiveTodoListsPerOwner"); }
144
- export function getMaxActiveTodoListsPerOwnerV2() { return _tlMaxActivePerOwner; }
145
- export function setMaxPendingItemsPerTodoListV2(n) { _tlMaxPendingPerList = _tlPos(n, "maxPendingItemsPerTodoList"); }
146
- export function getMaxPendingItemsPerTodoListV2() { return _tlMaxPendingPerList; }
147
- export function setTodoListIdleMsV2(n) { _tlListIdleMs = _tlPos(n, "todoListIdleMs"); }
148
- export function getTodoListIdleMsV2() { return _tlListIdleMs; }
149
- export function setTodoItemStuckMsV2(n) { _tlItemStuckMs = _tlPos(n, "todoItemStuckMs"); }
150
- export function getTodoItemStuckMsV2() { return _tlItemStuckMs; }
176
+ export function setMaxActiveTodoListsPerOwnerV2(n) {
177
+ _tlMaxActivePerOwner = _tlPos(n, "maxActiveTodoListsPerOwner");
178
+ }
179
+ export function getMaxActiveTodoListsPerOwnerV2() {
180
+ return _tlMaxActivePerOwner;
181
+ }
182
+ export function setMaxPendingItemsPerTodoListV2(n) {
183
+ _tlMaxPendingPerList = _tlPos(n, "maxPendingItemsPerTodoList");
184
+ }
185
+ export function getMaxPendingItemsPerTodoListV2() {
186
+ return _tlMaxPendingPerList;
187
+ }
188
+ export function setTodoListIdleMsV2(n) {
189
+ _tlListIdleMs = _tlPos(n, "todoListIdleMs");
190
+ }
191
+ export function getTodoListIdleMsV2() {
192
+ return _tlListIdleMs;
193
+ }
194
+ export function setTodoItemStuckMsV2(n) {
195
+ _tlItemStuckMs = _tlPos(n, "todoItemStuckMs");
196
+ }
197
+ export function getTodoItemStuckMsV2() {
198
+ return _tlItemStuckMs;
199
+ }
151
200
 
152
201
  export function _resetStateTodoManagerV2() {
153
- _tlLists.clear(); _tlItems.clear();
154
- _tlMaxActivePerOwner = 10; _tlMaxPendingPerList = 40;
155
- _tlListIdleMs = 7 * 24 * 60 * 60 * 1000; _tlItemStuckMs = 24 * 60 * 60 * 1000;
202
+ _tlLists.clear();
203
+ _tlItems.clear();
204
+ _tlMaxActivePerOwner = 10;
205
+ _tlMaxPendingPerList = 40;
206
+ _tlListIdleMs = 7 * 24 * 60 * 60 * 1000;
207
+ _tlItemStuckMs = 24 * 60 * 60 * 1000;
156
208
  }
157
209
 
158
210
  export function registerTodoListV2({ id, owner, title, metadata } = {}) {
@@ -160,54 +212,236 @@ export function registerTodoListV2({ id, owner, title, metadata } = {}) {
160
212
  if (!owner || typeof owner !== "string") throw new Error("owner is required");
161
213
  if (_tlLists.has(id)) throw new Error(`todo list ${id} already registered`);
162
214
  const now = Date.now();
163
- const l = { id, owner, title: title || id, status: TODO_LIST_MATURITY_V2.DRAFT, createdAt: now, updatedAt: now, activatedAt: null, archivedAt: null, lastTouchedAt: now, metadata: { ...(metadata || {}) } };
215
+ const l = {
216
+ id,
217
+ owner,
218
+ title: title || id,
219
+ status: TODO_LIST_MATURITY_V2.DRAFT,
220
+ createdAt: now,
221
+ updatedAt: now,
222
+ activatedAt: null,
223
+ archivedAt: null,
224
+ lastTouchedAt: now,
225
+ metadata: { ...(metadata || {}) },
226
+ };
164
227
  _tlLists.set(id, l);
165
228
  return { ...l, metadata: { ...l.metadata } };
166
229
  }
167
- function _tlCheckL(from, to) { const allowed = _tlListTrans.get(from); if (!allowed || !allowed.has(to)) throw new Error(`invalid todo list transition ${from} → ${to}`); }
168
- function _tlCountActive(owner) { let n = 0; for (const l of _tlLists.values()) if (l.owner === owner && l.status === TODO_LIST_MATURITY_V2.ACTIVE) n++; return n; }
230
+ function _tlCheckL(from, to) {
231
+ const allowed = _tlListTrans.get(from);
232
+ if (!allowed || !allowed.has(to))
233
+ throw new Error(`invalid todo list transition ${from} → ${to}`);
234
+ }
235
+ function _tlCountActive(owner) {
236
+ let n = 0;
237
+ for (const l of _tlLists.values())
238
+ if (l.owner === owner && l.status === TODO_LIST_MATURITY_V2.ACTIVE) n++;
239
+ return n;
240
+ }
169
241
 
170
242
  export function activateTodoListV2(id) {
171
- const l = _tlLists.get(id); if (!l) throw new Error(`todo list ${id} not found`);
243
+ const l = _tlLists.get(id);
244
+ if (!l) throw new Error(`todo list ${id} not found`);
172
245
  _tlCheckL(l.status, TODO_LIST_MATURITY_V2.ACTIVE);
173
246
  const recovery = l.status === TODO_LIST_MATURITY_V2.PAUSED;
174
- if (!recovery) { const a = _tlCountActive(l.owner); if (a >= _tlMaxActivePerOwner) throw new Error(`max active todo lists per owner (${_tlMaxActivePerOwner}) reached for ${l.owner}`); }
175
- const now = Date.now(); l.status = TODO_LIST_MATURITY_V2.ACTIVE; l.updatedAt = now; l.lastTouchedAt = now; if (!l.activatedAt) l.activatedAt = now;
247
+ if (!recovery) {
248
+ const a = _tlCountActive(l.owner);
249
+ if (a >= _tlMaxActivePerOwner)
250
+ throw new Error(
251
+ `max active todo lists per owner (${_tlMaxActivePerOwner}) reached for ${l.owner}`,
252
+ );
253
+ }
254
+ const now = Date.now();
255
+ l.status = TODO_LIST_MATURITY_V2.ACTIVE;
256
+ l.updatedAt = now;
257
+ l.lastTouchedAt = now;
258
+ if (!l.activatedAt) l.activatedAt = now;
259
+ return { ...l, metadata: { ...l.metadata } };
260
+ }
261
+ export function pauseTodoListV2(id) {
262
+ const l = _tlLists.get(id);
263
+ if (!l) throw new Error(`todo list ${id} not found`);
264
+ _tlCheckL(l.status, TODO_LIST_MATURITY_V2.PAUSED);
265
+ l.status = TODO_LIST_MATURITY_V2.PAUSED;
266
+ l.updatedAt = Date.now();
267
+ return { ...l, metadata: { ...l.metadata } };
268
+ }
269
+ export function archiveTodoListV2(id) {
270
+ const l = _tlLists.get(id);
271
+ if (!l) throw new Error(`todo list ${id} not found`);
272
+ _tlCheckL(l.status, TODO_LIST_MATURITY_V2.ARCHIVED);
273
+ const now = Date.now();
274
+ l.status = TODO_LIST_MATURITY_V2.ARCHIVED;
275
+ l.updatedAt = now;
276
+ if (!l.archivedAt) l.archivedAt = now;
176
277
  return { ...l, metadata: { ...l.metadata } };
177
278
  }
178
- export function pauseTodoListV2(id) { const l = _tlLists.get(id); if (!l) throw new Error(`todo list ${id} not found`); _tlCheckL(l.status, TODO_LIST_MATURITY_V2.PAUSED); l.status = TODO_LIST_MATURITY_V2.PAUSED; l.updatedAt = Date.now(); return { ...l, metadata: { ...l.metadata } }; }
179
- export function archiveTodoListV2(id) { const l = _tlLists.get(id); if (!l) throw new Error(`todo list ${id} not found`); _tlCheckL(l.status, TODO_LIST_MATURITY_V2.ARCHIVED); const now = Date.now(); l.status = TODO_LIST_MATURITY_V2.ARCHIVED; l.updatedAt = now; if (!l.archivedAt) l.archivedAt = now; return { ...l, metadata: { ...l.metadata } }; }
180
- export function touchTodoListV2(id) { const l = _tlLists.get(id); if (!l) throw new Error(`todo list ${id} not found`); if (_tlListTerminal.has(l.status)) throw new Error(`cannot touch terminal todo list ${id}`); const now = Date.now(); l.lastTouchedAt = now; l.updatedAt = now; return { ...l, metadata: { ...l.metadata } }; }
181
- export function getTodoListV2(id) { const l = _tlLists.get(id); if (!l) return null; return { ...l, metadata: { ...l.metadata } }; }
182
- export function listTodoListsV2() { return [..._tlLists.values()].map((l) => ({ ...l, metadata: { ...l.metadata } })); }
279
+ export function touchTodoListV2(id) {
280
+ const l = _tlLists.get(id);
281
+ if (!l) throw new Error(`todo list ${id} not found`);
282
+ if (_tlListTerminal.has(l.status))
283
+ throw new Error(`cannot touch terminal todo list ${id}`);
284
+ const now = Date.now();
285
+ l.lastTouchedAt = now;
286
+ l.updatedAt = now;
287
+ return { ...l, metadata: { ...l.metadata } };
288
+ }
289
+ export function getTodoListV2(id) {
290
+ const l = _tlLists.get(id);
291
+ if (!l) return null;
292
+ return { ...l, metadata: { ...l.metadata } };
293
+ }
294
+ export function listTodoListsV2() {
295
+ return [..._tlLists.values()].map((l) => ({
296
+ ...l,
297
+ metadata: { ...l.metadata },
298
+ }));
299
+ }
183
300
 
184
- function _tlCountPending(lid) { let n = 0; for (const it of _tlItems.values()) if (it.listId === lid && (it.status === TODO_ITEM_LIFECYCLE_V2.PENDING || it.status === TODO_ITEM_LIFECYCLE_V2.IN_PROGRESS)) n++; return n; }
301
+ function _tlCountPending(lid) {
302
+ let n = 0;
303
+ for (const it of _tlItems.values())
304
+ if (
305
+ it.listId === lid &&
306
+ (it.status === TODO_ITEM_LIFECYCLE_V2.PENDING ||
307
+ it.status === TODO_ITEM_LIFECYCLE_V2.IN_PROGRESS)
308
+ )
309
+ n++;
310
+ return n;
311
+ }
185
312
 
186
313
  export function createTodoItemV2({ id, listId, description, metadata } = {}) {
187
314
  if (!id || typeof id !== "string") throw new Error("id is required");
188
- if (!listId || typeof listId !== "string") throw new Error("listId is required");
315
+ if (!listId || typeof listId !== "string")
316
+ throw new Error("listId is required");
189
317
  if (_tlItems.has(id)) throw new Error(`todo item ${id} already exists`);
190
318
  if (!_tlLists.has(listId)) throw new Error(`todo list ${listId} not found`);
191
319
  const pending = _tlCountPending(listId);
192
- if (pending >= _tlMaxPendingPerList) throw new Error(`max pending items per todo list (${_tlMaxPendingPerList}) reached for ${listId}`);
320
+ if (pending >= _tlMaxPendingPerList)
321
+ throw new Error(
322
+ `max pending items per todo list (${_tlMaxPendingPerList}) reached for ${listId}`,
323
+ );
193
324
  const now = Date.now();
194
- const it = { id, listId, description: description || "", status: TODO_ITEM_LIFECYCLE_V2.PENDING, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
325
+ const it = {
326
+ id,
327
+ listId,
328
+ description: description || "",
329
+ status: TODO_ITEM_LIFECYCLE_V2.PENDING,
330
+ createdAt: now,
331
+ updatedAt: now,
332
+ startedAt: null,
333
+ settledAt: null,
334
+ metadata: { ...(metadata || {}) },
335
+ };
195
336
  _tlItems.set(id, it);
196
337
  return { ...it, metadata: { ...it.metadata } };
197
338
  }
198
- function _tlCheckI(from, to) { const allowed = _tlItemTrans.get(from); if (!allowed || !allowed.has(to)) throw new Error(`invalid todo item transition ${from} → ${to}`); }
199
- export function startTodoItemV2(id) { const it = _tlItems.get(id); if (!it) throw new Error(`todo item ${id} not found`); _tlCheckI(it.status, TODO_ITEM_LIFECYCLE_V2.IN_PROGRESS); const now = Date.now(); it.status = TODO_ITEM_LIFECYCLE_V2.IN_PROGRESS; it.updatedAt = now; if (!it.startedAt) it.startedAt = now; return { ...it, metadata: { ...it.metadata } }; }
200
- export function completeTodoItemV2(id) { const it = _tlItems.get(id); if (!it) throw new Error(`todo item ${id} not found`); _tlCheckI(it.status, TODO_ITEM_LIFECYCLE_V2.COMPLETED); const now = Date.now(); it.status = TODO_ITEM_LIFECYCLE_V2.COMPLETED; it.updatedAt = now; if (!it.settledAt) it.settledAt = now; return { ...it, metadata: { ...it.metadata } }; }
201
- export function failTodoItemV2(id, reason) { const it = _tlItems.get(id); if (!it) throw new Error(`todo item ${id} not found`); _tlCheckI(it.status, TODO_ITEM_LIFECYCLE_V2.FAILED); const now = Date.now(); it.status = TODO_ITEM_LIFECYCLE_V2.FAILED; it.updatedAt = now; if (!it.settledAt) it.settledAt = now; if (reason) it.metadata.failReason = String(reason); return { ...it, metadata: { ...it.metadata } }; }
202
- export function cancelTodoItemV2(id, reason) { const it = _tlItems.get(id); if (!it) throw new Error(`todo item ${id} not found`); _tlCheckI(it.status, TODO_ITEM_LIFECYCLE_V2.CANCELLED); const now = Date.now(); it.status = TODO_ITEM_LIFECYCLE_V2.CANCELLED; it.updatedAt = now; if (!it.settledAt) it.settledAt = now; if (reason) it.metadata.cancelReason = String(reason); return { ...it, metadata: { ...it.metadata } }; }
203
- export function getTodoItemV2(id) { const it = _tlItems.get(id); if (!it) return null; return { ...it, metadata: { ...it.metadata } }; }
204
- export function listTodoItemsV2() { return [..._tlItems.values()].map((it) => ({ ...it, metadata: { ...it.metadata } })); }
339
+ function _tlCheckI(from, to) {
340
+ const allowed = _tlItemTrans.get(from);
341
+ if (!allowed || !allowed.has(to))
342
+ throw new Error(`invalid todo item transition ${from} ${to}`);
343
+ }
344
+ export function startTodoItemV2(id) {
345
+ const it = _tlItems.get(id);
346
+ if (!it) throw new Error(`todo item ${id} not found`);
347
+ _tlCheckI(it.status, TODO_ITEM_LIFECYCLE_V2.IN_PROGRESS);
348
+ const now = Date.now();
349
+ it.status = TODO_ITEM_LIFECYCLE_V2.IN_PROGRESS;
350
+ it.updatedAt = now;
351
+ if (!it.startedAt) it.startedAt = now;
352
+ return { ...it, metadata: { ...it.metadata } };
353
+ }
354
+ export function completeTodoItemV2(id) {
355
+ const it = _tlItems.get(id);
356
+ if (!it) throw new Error(`todo item ${id} not found`);
357
+ _tlCheckI(it.status, TODO_ITEM_LIFECYCLE_V2.COMPLETED);
358
+ const now = Date.now();
359
+ it.status = TODO_ITEM_LIFECYCLE_V2.COMPLETED;
360
+ it.updatedAt = now;
361
+ if (!it.settledAt) it.settledAt = now;
362
+ return { ...it, metadata: { ...it.metadata } };
363
+ }
364
+ export function failTodoItemV2(id, reason) {
365
+ const it = _tlItems.get(id);
366
+ if (!it) throw new Error(`todo item ${id} not found`);
367
+ _tlCheckI(it.status, TODO_ITEM_LIFECYCLE_V2.FAILED);
368
+ const now = Date.now();
369
+ it.status = TODO_ITEM_LIFECYCLE_V2.FAILED;
370
+ it.updatedAt = now;
371
+ if (!it.settledAt) it.settledAt = now;
372
+ if (reason) it.metadata.failReason = String(reason);
373
+ return { ...it, metadata: { ...it.metadata } };
374
+ }
375
+ export function cancelTodoItemV2(id, reason) {
376
+ const it = _tlItems.get(id);
377
+ if (!it) throw new Error(`todo item ${id} not found`);
378
+ _tlCheckI(it.status, TODO_ITEM_LIFECYCLE_V2.CANCELLED);
379
+ const now = Date.now();
380
+ it.status = TODO_ITEM_LIFECYCLE_V2.CANCELLED;
381
+ it.updatedAt = now;
382
+ if (!it.settledAt) it.settledAt = now;
383
+ if (reason) it.metadata.cancelReason = String(reason);
384
+ return { ...it, metadata: { ...it.metadata } };
385
+ }
386
+ export function getTodoItemV2(id) {
387
+ const it = _tlItems.get(id);
388
+ if (!it) return null;
389
+ return { ...it, metadata: { ...it.metadata } };
390
+ }
391
+ export function listTodoItemsV2() {
392
+ return [..._tlItems.values()].map((it) => ({
393
+ ...it,
394
+ metadata: { ...it.metadata },
395
+ }));
396
+ }
205
397
 
206
- export function autoPauseIdleTodoListsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const l of _tlLists.values()) if (l.status === TODO_LIST_MATURITY_V2.ACTIVE && (t - l.lastTouchedAt) >= _tlListIdleMs) { l.status = TODO_LIST_MATURITY_V2.PAUSED; l.updatedAt = t; flipped.push(l.id); } return { flipped, count: flipped.length }; }
207
- export function autoFailStuckTodoItemsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const it of _tlItems.values()) if (it.status === TODO_ITEM_LIFECYCLE_V2.IN_PROGRESS && it.startedAt != null && (t - it.startedAt) >= _tlItemStuckMs) { it.status = TODO_ITEM_LIFECYCLE_V2.FAILED; it.updatedAt = t; if (!it.settledAt) it.settledAt = t; it.metadata.failReason = "auto-fail-stuck"; flipped.push(it.id); } return { flipped, count: flipped.length }; }
398
+ export function autoPauseIdleTodoListsV2({ now } = {}) {
399
+ const t = now ?? Date.now();
400
+ const flipped = [];
401
+ for (const l of _tlLists.values())
402
+ if (
403
+ l.status === TODO_LIST_MATURITY_V2.ACTIVE &&
404
+ t - l.lastTouchedAt >= _tlListIdleMs
405
+ ) {
406
+ l.status = TODO_LIST_MATURITY_V2.PAUSED;
407
+ l.updatedAt = t;
408
+ flipped.push(l.id);
409
+ }
410
+ return { flipped, count: flipped.length };
411
+ }
412
+ export function autoFailStuckTodoItemsV2({ now } = {}) {
413
+ const t = now ?? Date.now();
414
+ const flipped = [];
415
+ for (const it of _tlItems.values())
416
+ if (
417
+ it.status === TODO_ITEM_LIFECYCLE_V2.IN_PROGRESS &&
418
+ it.startedAt != null &&
419
+ t - it.startedAt >= _tlItemStuckMs
420
+ ) {
421
+ it.status = TODO_ITEM_LIFECYCLE_V2.FAILED;
422
+ it.updatedAt = t;
423
+ if (!it.settledAt) it.settledAt = t;
424
+ it.metadata.failReason = "auto-fail-stuck";
425
+ flipped.push(it.id);
426
+ }
427
+ return { flipped, count: flipped.length };
428
+ }
208
429
 
209
430
  export function getTodoManagerStatsV2() {
210
- const listsByStatus = {}; for (const s of Object.values(TODO_LIST_MATURITY_V2)) listsByStatus[s] = 0; for (const l of _tlLists.values()) listsByStatus[l.status]++;
211
- const itemsByStatus = {}; for (const s of Object.values(TODO_ITEM_LIFECYCLE_V2)) itemsByStatus[s] = 0; for (const it of _tlItems.values()) itemsByStatus[it.status]++;
212
- return { totalListsV2: _tlLists.size, totalItemsV2: _tlItems.size, maxActiveTodoListsPerOwner: _tlMaxActivePerOwner, maxPendingItemsPerTodoList: _tlMaxPendingPerList, todoListIdleMs: _tlListIdleMs, todoItemStuckMs: _tlItemStuckMs, listsByStatus, itemsByStatus };
431
+ const listsByStatus = {};
432
+ for (const s of Object.values(TODO_LIST_MATURITY_V2)) listsByStatus[s] = 0;
433
+ for (const l of _tlLists.values()) listsByStatus[l.status]++;
434
+ const itemsByStatus = {};
435
+ for (const s of Object.values(TODO_ITEM_LIFECYCLE_V2)) itemsByStatus[s] = 0;
436
+ for (const it of _tlItems.values()) itemsByStatus[it.status]++;
437
+ return {
438
+ totalListsV2: _tlLists.size,
439
+ totalItemsV2: _tlItems.size,
440
+ maxActiveTodoListsPerOwner: _tlMaxActivePerOwner,
441
+ maxPendingItemsPerTodoList: _tlMaxPendingPerList,
442
+ todoListIdleMs: _tlListIdleMs,
443
+ todoItemStuckMs: _tlItemStuckMs,
444
+ listsByStatus,
445
+ itemsByStatus,
446
+ };
213
447
  }