chainlesschain 0.143.0 → 0.152.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.
- package/package.json +1 -1
- package/src/commands/a2a.js +196 -28
- package/src/commands/activitypub.js +364 -27
- package/src/commands/agent-network.js +217 -0
- package/src/commands/agent.js +587 -103
- package/src/commands/audit.js +206 -0
- package/src/commands/automation.js +201 -0
- package/src/commands/bi.js +355 -27
- package/src/commands/bm25.js +111 -27
- package/src/commands/browse.js +403 -29
- package/src/commands/ccron.js +128 -28
- package/src/commands/chat.js +207 -0
- package/src/commands/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +824 -34
- package/src/commands/compt.js +127 -29
- package/src/commands/consol.js +8 -2
- package/src/commands/cowork.js +783 -34
- package/src/commands/crosschain.js +182 -28
- package/src/commands/dao.js +182 -28
- package/src/commands/dbevo.js +227 -0
- package/src/commands/dev.js +207 -0
- package/src/commands/did-v2.js +217 -0
- package/src/commands/did.js +221 -0
- package/src/commands/dlp.js +385 -27
- package/src/commands/economy.js +205 -50
- package/src/commands/evolution.js +203 -50
- package/src/commands/evomap.js +387 -27
- package/src/commands/export.js +213 -0
- package/src/commands/federation.js +209 -0
- package/src/commands/fflag.js +74 -22
- package/src/commands/fusion.js +205 -0
- package/src/commands/git.js +177 -37
- package/src/commands/governance.js +209 -0
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +204 -50
- package/src/commands/hook.js +209 -0
- package/src/commands/import.js +209 -0
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +170 -34
- package/src/commands/infra.js +203 -0
- package/src/commands/instinct.js +209 -0
- package/src/commands/ipfs.js +207 -0
- package/src/commands/itbudget.js +149 -33
- package/src/commands/kg.js +206 -0
- package/src/commands/llm.js +217 -0
- package/src/commands/lowcode.js +195 -38
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +386 -27
- package/src/commands/mcp.js +217 -0
- package/src/commands/mcpscaf.js +145 -33
- package/src/commands/meminj.js +145 -33
- package/src/commands/memory.js +209 -0
- package/src/commands/multimodal.js +203 -0
- package/src/commands/nlprog.js +225 -0
- package/src/commands/nostr.js +387 -27
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -0
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +144 -33
- package/src/commands/org.js +209 -0
- package/src/commands/p2p.js +209 -0
- package/src/commands/pdfp.js +109 -27
- package/src/commands/perception.js +209 -0
- package/src/commands/perf.js +169 -32
- package/src/commands/perm.js +144 -33
- package/src/commands/permmem.js +203 -0
- package/src/commands/pipeline.js +207 -52
- package/src/commands/planmode.js +141 -32
- package/src/commands/plugin-ecosystem.js +209 -0
- package/src/commands/pqc.js +213 -0
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +111 -27
- package/src/commands/quantization.js +207 -0
- package/src/commands/rcache.js +205 -0
- package/src/commands/recommend.js +410 -34
- package/src/commands/reputation.js +208 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/sandbox.js +206 -0
- package/src/commands/scim.js +209 -0
- package/src/commands/seshhook.js +145 -33
- package/src/commands/seshsearch.js +141 -33
- package/src/commands/seshtail.js +144 -33
- package/src/commands/seshu.js +152 -33
- package/src/commands/session.js +209 -0
- package/src/commands/sganal.js +123 -29
- package/src/commands/siem.js +201 -34
- package/src/commands/skill.js +207 -0
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +146 -33
- package/src/commands/social.js +358 -32
- package/src/commands/sso.js +209 -0
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +145 -33
- package/src/commands/sync.js +209 -0
- package/src/commands/tech.js +209 -0
- package/src/commands/tenant.js +217 -0
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +171 -33
- package/src/commands/tokens.js +209 -0
- package/src/commands/topiccls.js +146 -33
- package/src/commands/trust.js +217 -0
- package/src/commands/uprof.js +141 -32
- package/src/commands/vcheck.js +122 -28
- package/src/commands/wallet.js +209 -0
- package/src/commands/webfetch.js +141 -32
- package/src/commands/workflow.js +203 -0
- package/src/commands/zkp.js +184 -28
- package/src/index.js +180 -0
- package/src/lib/a2a-protocol.js +319 -51
- package/src/lib/activitypub-bridge.js +622 -50
- package/src/lib/agent-economy.js +304 -51
- package/src/lib/agent-network.js +341 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/app-builder.js +279 -46
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/automation-engine.js +335 -0
- package/src/lib/autonomous-agent.js +284 -48
- package/src/lib/autonomous-developer.js +332 -0
- package/src/lib/bi-engine.js +616 -49
- package/src/lib/bm25-search.js +301 -49
- package/src/lib/browser-automation.js +630 -49
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -0
- package/src/lib/code-agent.js +339 -0
- package/src/lib/collaboration-governance.js +334 -0
- package/src/lib/community-governance.js +346 -0
- package/src/lib/compliance-framework-reporter.js +305 -51
- package/src/lib/compliance-manager.js +330 -0
- package/src/lib/compression-telemetry.js +301 -49
- package/src/lib/content-recommendation.js +351 -0
- package/src/lib/content-recommender.js +317 -52
- package/src/lib/cowork-cron.js +298 -49
- package/src/lib/cowork-learning.js +333 -0
- package/src/lib/cowork-share.js +338 -0
- package/src/lib/cowork-task-runner.js +308 -51
- package/src/lib/cowork-workflow.js +327 -0
- package/src/lib/cross-chain.js +311 -51
- package/src/lib/dao-governance.js +280 -46
- package/src/lib/dbevo.js +351 -0
- package/src/lib/decentral-infra.js +330 -0
- package/src/lib/did-manager.js +341 -0
- package/src/lib/did-v2-manager.js +341 -0
- package/src/lib/dlp-engine.js +626 -49
- package/src/lib/evolution-system.js +278 -47
- package/src/lib/evomap-governance.js +334 -0
- package/src/lib/evomap-manager.js +280 -46
- package/src/lib/execution-backend.js +294 -48
- package/src/lib/feature-flags.js +294 -49
- package/src/lib/federation-hardening.js +340 -0
- package/src/lib/git-integration.js +285 -47
- package/src/lib/hardening-manager.js +341 -0
- package/src/lib/hierarchical-memory.js +284 -48
- package/src/lib/hook-manager.js +341 -0
- package/src/lib/inference-network.js +308 -51
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/iteration-budget.js +302 -50
- package/src/lib/knowledge-exporter.js +341 -0
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/knowledge-importer.js +341 -0
- package/src/lib/llm-providers.js +346 -0
- package/src/lib/matrix-bridge.js +620 -47
- package/src/lib/mcp-registry.js +346 -0
- package/src/lib/mcp-scaffold.js +318 -54
- package/src/lib/memory-injection.js +288 -49
- package/src/lib/memory-manager.js +336 -0
- package/src/lib/multimodal.js +330 -0
- package/src/lib/nl-programming.js +341 -0
- package/src/lib/nostr-bridge.js +622 -49
- package/src/lib/note-versioning.js +339 -0
- package/src/lib/orchestrator.js +293 -48
- package/src/lib/org-manager.js +336 -0
- package/src/lib/p2p-manager.js +341 -0
- package/src/lib/pdf-parser.js +298 -49
- package/src/lib/perception.js +346 -0
- package/src/lib/perf-tuning.js +309 -50
- package/src/lib/permanent-memory.js +327 -0
- package/src/lib/permission-engine.js +287 -49
- package/src/lib/pipeline-orchestrator.js +289 -49
- package/src/lib/plan-mode.js +298 -51
- package/src/lib/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/privacy-computing.js +335 -0
- package/src/lib/protocol-fusion.js +338 -0
- package/src/lib/quantization.js +337 -0
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/response-cache.js +333 -0
- package/src/lib/sandbox-v2.js +327 -0
- package/src/lib/scim-manager.js +346 -0
- package/src/lib/service-container.js +313 -52
- package/src/lib/session-consolidator.js +296 -49
- package/src/lib/session-hooks.js +312 -53
- package/src/lib/session-manager.js +334 -0
- package/src/lib/session-search.js +304 -51
- package/src/lib/session-tail.js +288 -49
- package/src/lib/session-usage.js +298 -52
- package/src/lib/siem-exporter.js +298 -51
- package/src/lib/skill-loader.js +334 -0
- package/src/lib/skill-marketplace.js +345 -0
- package/src/lib/sla-manager.js +341 -0
- package/src/lib/slot-filler.js +303 -51
- package/src/lib/social-graph-analytics.js +295 -49
- package/src/lib/social-graph.js +272 -49
- package/src/lib/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -0
- package/src/lib/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +302 -53
- package/src/lib/sync-manager.js +336 -0
- package/src/lib/task-model-selector.js +302 -50
- package/src/lib/tech-learning-engine.js +341 -0
- package/src/lib/tenant-saas.js +341 -0
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/threat-intel.js +330 -0
- package/src/lib/todo-manager.js +281 -47
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/token-tracker.js +336 -0
- package/src/lib/topic-classifier.js +297 -49
- package/src/lib/trust-security.js +343 -0
- package/src/lib/ueba.js +340 -0
- package/src/lib/universal-runtime.js +330 -0
- package/src/lib/user-profile.js +294 -50
- package/src/lib/version-checker.js +304 -50
- package/src/lib/wallet-manager.js +336 -0
- package/src/lib/web-fetch.js +292 -51
- package/src/lib/workflow-engine.js +330 -0
- package/src/lib/zkp-engine.js +286 -49
package/src/lib/todo-manager.js
CHANGED
|
@@ -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",
|
|
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",
|
|
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
|
-
[
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
[
|
|
128
|
-
|
|
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) {
|
|
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) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
export function
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
export function
|
|
150
|
-
|
|
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();
|
|
154
|
-
|
|
155
|
-
|
|
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 = {
|
|
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) {
|
|
168
|
-
|
|
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);
|
|
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) {
|
|
175
|
-
|
|
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
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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) {
|
|
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")
|
|
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)
|
|
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 = {
|
|
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) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
export function
|
|
204
|
-
|
|
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 } = {}) {
|
|
207
|
-
|
|
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 = {};
|
|
211
|
-
|
|
212
|
-
|
|
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
|
}
|