chainlesschain 0.152.0 → 0.156.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.
- package/README.md +52 -3
- package/package.json +1 -1
- package/src/commands/a2a.js +201 -0
- package/src/commands/agent.js +1250 -0
- package/src/commands/chat.js +605 -0
- package/src/commands/cli-anything.js +426 -0
- package/src/commands/compliance.js +412 -0
- package/src/commands/config.js +213 -0
- package/src/commands/cowork.js +1463 -0
- package/src/commands/crosschain.js +203 -0
- package/src/commands/dao.js +203 -0
- package/src/commands/economy.js +199 -0
- package/src/commands/encrypt.js +201 -0
- package/src/commands/evolution.js +199 -0
- package/src/commands/evomap.js +625 -0
- package/src/commands/hmemory.js +203 -0
- package/src/commands/inference.js +207 -0
- package/src/commands/kg.js +195 -0
- package/src/commands/llm.js +209 -0
- package/src/commands/memory.js +203 -0
- package/src/commands/orchestrate.js +406 -0
- package/src/commands/pipeline.js +199 -0
- package/src/commands/planmode.js +426 -0
- package/src/commands/plugin.js +209 -0
- package/src/commands/services.js +207 -0
- package/src/commands/setup.js +205 -0
- package/src/commands/skill.js +207 -0
- package/src/commands/start.js +209 -0
- package/src/commands/stream.js +213 -0
- package/src/commands/ui.js +225 -0
- package/src/commands/workflow.js +209 -0
- package/src/index.js +112 -0
- package/src/lib/a2a-protocol.js +332 -0
- package/src/lib/agent-coordinator.js +334 -0
- package/src/lib/agent-economy.js +334 -0
- package/src/lib/agent-router.js +333 -0
- package/src/lib/autonomous-agent.js +332 -0
- package/src/lib/chat-core.js +335 -0
- package/src/lib/cli-anything-bridge.js +341 -0
- package/src/lib/cli-context-engineering.js +351 -0
- package/src/lib/compliance-manager.js +334 -0
- package/src/lib/cowork-adapter.js +336 -0
- package/src/lib/cowork-evomap-adapter.js +341 -0
- package/src/lib/cowork-mcp-tools.js +341 -0
- package/src/lib/cowork-observe-html.js +341 -0
- package/src/lib/cowork-observe.js +341 -0
- package/src/lib/cowork-task-templates.js +342 -1
- package/src/lib/cowork-template-marketplace.js +340 -0
- package/src/lib/cross-chain.js +339 -0
- package/src/lib/crypto-manager.js +334 -0
- package/src/lib/dao-governance.js +339 -0
- package/src/lib/downloader.js +334 -0
- package/src/lib/evolution-system.js +334 -0
- package/src/lib/evomap-client.js +342 -0
- package/src/lib/evomap-federation.js +338 -0
- package/src/lib/evomap-manager.js +330 -0
- package/src/lib/execution-backend.js +330 -0
- package/src/lib/hashline.js +338 -0
- package/src/lib/hierarchical-memory.js +334 -0
- package/src/lib/inference-network.js +341 -0
- package/src/lib/interaction-adapter.js +330 -0
- package/src/lib/interactive-planner.js +354 -0
- package/src/lib/knowledge-graph.js +331 -0
- package/src/lib/pipeline-orchestrator.js +332 -0
- package/src/lib/plan-mode.js +336 -0
- package/src/lib/plugin-autodiscovery.js +334 -0
- package/src/lib/process-manager.js +336 -0
- package/src/lib/provider-options.js +346 -0
- package/src/lib/provider-stream.js +348 -0
- package/src/lib/service-manager.js +337 -0
- package/src/lib/session-core-singletons.js +341 -0
- package/src/lib/skill-mcp.js +336 -0
- package/src/lib/stix-parser.js +346 -0
- package/src/lib/sub-agent-context.js +343 -0
- package/src/lib/sub-agent-profiles.js +335 -0
- package/src/lib/sub-agent-registry.js +336 -0
- package/src/lib/todo-manager.js +336 -0
- package/src/lib/web-ui-server.js +348 -0
- package/src/lib/workflow-expr.js +346 -0
- package/src/lib/ws-chat-handler.js +337 -0
|
@@ -104,3 +104,339 @@ export const coworkLogger = {
|
|
|
104
104
|
error: (...args) => console.error("[cowork]", ...args),
|
|
105
105
|
debug: () => {},
|
|
106
106
|
};
|
|
107
|
+
|
|
108
|
+
// =====================================================================
|
|
109
|
+
// cowork-adapter V2 governance overlay (iter27)
|
|
110
|
+
// =====================================================================
|
|
111
|
+
export const CADPGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
112
|
+
PENDING: "pending",
|
|
113
|
+
ACTIVE: "active",
|
|
114
|
+
STALE: "stale",
|
|
115
|
+
ARCHIVED: "archived",
|
|
116
|
+
});
|
|
117
|
+
export const CADPGOV_ADAPT_LIFECYCLE_V2 = Object.freeze({
|
|
118
|
+
QUEUED: "queued",
|
|
119
|
+
ADAPTING: "adapting",
|
|
120
|
+
ADAPTED: "adapted",
|
|
121
|
+
FAILED: "failed",
|
|
122
|
+
CANCELLED: "cancelled",
|
|
123
|
+
});
|
|
124
|
+
const _cadpgovPTrans = new Map([
|
|
125
|
+
[
|
|
126
|
+
CADPGOV_PROFILE_MATURITY_V2.PENDING,
|
|
127
|
+
new Set([
|
|
128
|
+
CADPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
129
|
+
CADPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
130
|
+
]),
|
|
131
|
+
],
|
|
132
|
+
[
|
|
133
|
+
CADPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
134
|
+
new Set([
|
|
135
|
+
CADPGOV_PROFILE_MATURITY_V2.STALE,
|
|
136
|
+
CADPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
137
|
+
]),
|
|
138
|
+
],
|
|
139
|
+
[
|
|
140
|
+
CADPGOV_PROFILE_MATURITY_V2.STALE,
|
|
141
|
+
new Set([
|
|
142
|
+
CADPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
143
|
+
CADPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
144
|
+
]),
|
|
145
|
+
],
|
|
146
|
+
[CADPGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
147
|
+
]);
|
|
148
|
+
const _cadpgovPTerminal = new Set([CADPGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
149
|
+
const _cadpgovJTrans = new Map([
|
|
150
|
+
[
|
|
151
|
+
CADPGOV_ADAPT_LIFECYCLE_V2.QUEUED,
|
|
152
|
+
new Set([
|
|
153
|
+
CADPGOV_ADAPT_LIFECYCLE_V2.ADAPTING,
|
|
154
|
+
CADPGOV_ADAPT_LIFECYCLE_V2.CANCELLED,
|
|
155
|
+
]),
|
|
156
|
+
],
|
|
157
|
+
[
|
|
158
|
+
CADPGOV_ADAPT_LIFECYCLE_V2.ADAPTING,
|
|
159
|
+
new Set([
|
|
160
|
+
CADPGOV_ADAPT_LIFECYCLE_V2.ADAPTED,
|
|
161
|
+
CADPGOV_ADAPT_LIFECYCLE_V2.FAILED,
|
|
162
|
+
CADPGOV_ADAPT_LIFECYCLE_V2.CANCELLED,
|
|
163
|
+
]),
|
|
164
|
+
],
|
|
165
|
+
[CADPGOV_ADAPT_LIFECYCLE_V2.ADAPTED, new Set()],
|
|
166
|
+
[CADPGOV_ADAPT_LIFECYCLE_V2.FAILED, new Set()],
|
|
167
|
+
[CADPGOV_ADAPT_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
168
|
+
]);
|
|
169
|
+
const _cadpgovPsV2 = new Map();
|
|
170
|
+
const _cadpgovJsV2 = new Map();
|
|
171
|
+
let _cadpgovMaxActive = 6,
|
|
172
|
+
_cadpgovMaxPending = 15,
|
|
173
|
+
_cadpgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
174
|
+
_cadpgovStuckMs = 60 * 1000;
|
|
175
|
+
function _cadpgovPos(n, label) {
|
|
176
|
+
const v = Math.floor(Number(n));
|
|
177
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
178
|
+
throw new Error(`${label} must be positive integer`);
|
|
179
|
+
return v;
|
|
180
|
+
}
|
|
181
|
+
function _cadpgovCheckP(from, to) {
|
|
182
|
+
const a = _cadpgovPTrans.get(from);
|
|
183
|
+
if (!a || !a.has(to))
|
|
184
|
+
throw new Error(`invalid cadpgov profile transition ${from} → ${to}`);
|
|
185
|
+
}
|
|
186
|
+
function _cadpgovCheckJ(from, to) {
|
|
187
|
+
const a = _cadpgovJTrans.get(from);
|
|
188
|
+
if (!a || !a.has(to))
|
|
189
|
+
throw new Error(`invalid cadpgov adapt transition ${from} → ${to}`);
|
|
190
|
+
}
|
|
191
|
+
function _cadpgovCountActive(owner) {
|
|
192
|
+
let c = 0;
|
|
193
|
+
for (const p of _cadpgovPsV2.values())
|
|
194
|
+
if (p.owner === owner && p.status === CADPGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
195
|
+
c++;
|
|
196
|
+
return c;
|
|
197
|
+
}
|
|
198
|
+
function _cadpgovCountPending(profileId) {
|
|
199
|
+
let c = 0;
|
|
200
|
+
for (const j of _cadpgovJsV2.values())
|
|
201
|
+
if (
|
|
202
|
+
j.profileId === profileId &&
|
|
203
|
+
(j.status === CADPGOV_ADAPT_LIFECYCLE_V2.QUEUED ||
|
|
204
|
+
j.status === CADPGOV_ADAPT_LIFECYCLE_V2.ADAPTING)
|
|
205
|
+
)
|
|
206
|
+
c++;
|
|
207
|
+
return c;
|
|
208
|
+
}
|
|
209
|
+
export function setMaxActiveCadpgovProfilesPerOwnerV2(n) {
|
|
210
|
+
_cadpgovMaxActive = _cadpgovPos(n, "maxActiveCadpgovProfilesPerOwner");
|
|
211
|
+
}
|
|
212
|
+
export function getMaxActiveCadpgovProfilesPerOwnerV2() {
|
|
213
|
+
return _cadpgovMaxActive;
|
|
214
|
+
}
|
|
215
|
+
export function setMaxPendingCadpgovAdaptsPerProfileV2(n) {
|
|
216
|
+
_cadpgovMaxPending = _cadpgovPos(n, "maxPendingCadpgovAdaptsPerProfile");
|
|
217
|
+
}
|
|
218
|
+
export function getMaxPendingCadpgovAdaptsPerProfileV2() {
|
|
219
|
+
return _cadpgovMaxPending;
|
|
220
|
+
}
|
|
221
|
+
export function setCadpgovProfileIdleMsV2(n) {
|
|
222
|
+
_cadpgovIdleMs = _cadpgovPos(n, "cadpgovProfileIdleMs");
|
|
223
|
+
}
|
|
224
|
+
export function getCadpgovProfileIdleMsV2() {
|
|
225
|
+
return _cadpgovIdleMs;
|
|
226
|
+
}
|
|
227
|
+
export function setCadpgovAdaptStuckMsV2(n) {
|
|
228
|
+
_cadpgovStuckMs = _cadpgovPos(n, "cadpgovAdaptStuckMs");
|
|
229
|
+
}
|
|
230
|
+
export function getCadpgovAdaptStuckMsV2() {
|
|
231
|
+
return _cadpgovStuckMs;
|
|
232
|
+
}
|
|
233
|
+
export function _resetStateCoworkAdapterGovV2() {
|
|
234
|
+
_cadpgovPsV2.clear();
|
|
235
|
+
_cadpgovJsV2.clear();
|
|
236
|
+
_cadpgovMaxActive = 6;
|
|
237
|
+
_cadpgovMaxPending = 15;
|
|
238
|
+
_cadpgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
239
|
+
_cadpgovStuckMs = 60 * 1000;
|
|
240
|
+
}
|
|
241
|
+
export function registerCadpgovProfileV2({ id, owner, target, metadata } = {}) {
|
|
242
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
243
|
+
if (_cadpgovPsV2.has(id))
|
|
244
|
+
throw new Error(`cadpgov profile ${id} already exists`);
|
|
245
|
+
const now = Date.now();
|
|
246
|
+
const p = {
|
|
247
|
+
id,
|
|
248
|
+
owner,
|
|
249
|
+
target: target || "default",
|
|
250
|
+
status: CADPGOV_PROFILE_MATURITY_V2.PENDING,
|
|
251
|
+
createdAt: now,
|
|
252
|
+
updatedAt: now,
|
|
253
|
+
lastTouchedAt: now,
|
|
254
|
+
activatedAt: null,
|
|
255
|
+
archivedAt: null,
|
|
256
|
+
metadata: { ...(metadata || {}) },
|
|
257
|
+
};
|
|
258
|
+
_cadpgovPsV2.set(id, p);
|
|
259
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
260
|
+
}
|
|
261
|
+
export function activateCadpgovProfileV2(id) {
|
|
262
|
+
const p = _cadpgovPsV2.get(id);
|
|
263
|
+
if (!p) throw new Error(`cadpgov profile ${id} not found`);
|
|
264
|
+
const isInitial = p.status === CADPGOV_PROFILE_MATURITY_V2.PENDING;
|
|
265
|
+
_cadpgovCheckP(p.status, CADPGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
266
|
+
if (isInitial && _cadpgovCountActive(p.owner) >= _cadpgovMaxActive)
|
|
267
|
+
throw new Error(`max active cadpgov profiles for owner ${p.owner} reached`);
|
|
268
|
+
const now = Date.now();
|
|
269
|
+
p.status = CADPGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
270
|
+
p.updatedAt = now;
|
|
271
|
+
p.lastTouchedAt = now;
|
|
272
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
273
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
274
|
+
}
|
|
275
|
+
export function staleCadpgovProfileV2(id) {
|
|
276
|
+
const p = _cadpgovPsV2.get(id);
|
|
277
|
+
if (!p) throw new Error(`cadpgov profile ${id} not found`);
|
|
278
|
+
_cadpgovCheckP(p.status, CADPGOV_PROFILE_MATURITY_V2.STALE);
|
|
279
|
+
p.status = CADPGOV_PROFILE_MATURITY_V2.STALE;
|
|
280
|
+
p.updatedAt = Date.now();
|
|
281
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
282
|
+
}
|
|
283
|
+
export function archiveCadpgovProfileV2(id) {
|
|
284
|
+
const p = _cadpgovPsV2.get(id);
|
|
285
|
+
if (!p) throw new Error(`cadpgov profile ${id} not found`);
|
|
286
|
+
_cadpgovCheckP(p.status, CADPGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
287
|
+
const now = Date.now();
|
|
288
|
+
p.status = CADPGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
289
|
+
p.updatedAt = now;
|
|
290
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
291
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
292
|
+
}
|
|
293
|
+
export function touchCadpgovProfileV2(id) {
|
|
294
|
+
const p = _cadpgovPsV2.get(id);
|
|
295
|
+
if (!p) throw new Error(`cadpgov profile ${id} not found`);
|
|
296
|
+
if (_cadpgovPTerminal.has(p.status))
|
|
297
|
+
throw new Error(`cannot touch terminal cadpgov profile ${id}`);
|
|
298
|
+
const now = Date.now();
|
|
299
|
+
p.lastTouchedAt = now;
|
|
300
|
+
p.updatedAt = now;
|
|
301
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
302
|
+
}
|
|
303
|
+
export function getCadpgovProfileV2(id) {
|
|
304
|
+
const p = _cadpgovPsV2.get(id);
|
|
305
|
+
if (!p) return null;
|
|
306
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
307
|
+
}
|
|
308
|
+
export function listCadpgovProfilesV2() {
|
|
309
|
+
return [..._cadpgovPsV2.values()].map((p) => ({
|
|
310
|
+
...p,
|
|
311
|
+
metadata: { ...p.metadata },
|
|
312
|
+
}));
|
|
313
|
+
}
|
|
314
|
+
export function createCadpgovAdaptV2({ id, profileId, source, metadata } = {}) {
|
|
315
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
316
|
+
if (_cadpgovJsV2.has(id))
|
|
317
|
+
throw new Error(`cadpgov adapt ${id} already exists`);
|
|
318
|
+
if (!_cadpgovPsV2.has(profileId))
|
|
319
|
+
throw new Error(`cadpgov profile ${profileId} not found`);
|
|
320
|
+
if (_cadpgovCountPending(profileId) >= _cadpgovMaxPending)
|
|
321
|
+
throw new Error(
|
|
322
|
+
`max pending cadpgov adapts for profile ${profileId} reached`,
|
|
323
|
+
);
|
|
324
|
+
const now = Date.now();
|
|
325
|
+
const j = {
|
|
326
|
+
id,
|
|
327
|
+
profileId,
|
|
328
|
+
source: source || "",
|
|
329
|
+
status: CADPGOV_ADAPT_LIFECYCLE_V2.QUEUED,
|
|
330
|
+
createdAt: now,
|
|
331
|
+
updatedAt: now,
|
|
332
|
+
startedAt: null,
|
|
333
|
+
settledAt: null,
|
|
334
|
+
metadata: { ...(metadata || {}) },
|
|
335
|
+
};
|
|
336
|
+
_cadpgovJsV2.set(id, j);
|
|
337
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
338
|
+
}
|
|
339
|
+
export function adaptingCadpgovAdaptV2(id) {
|
|
340
|
+
const j = _cadpgovJsV2.get(id);
|
|
341
|
+
if (!j) throw new Error(`cadpgov adapt ${id} not found`);
|
|
342
|
+
_cadpgovCheckJ(j.status, CADPGOV_ADAPT_LIFECYCLE_V2.ADAPTING);
|
|
343
|
+
const now = Date.now();
|
|
344
|
+
j.status = CADPGOV_ADAPT_LIFECYCLE_V2.ADAPTING;
|
|
345
|
+
j.updatedAt = now;
|
|
346
|
+
if (!j.startedAt) j.startedAt = now;
|
|
347
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
348
|
+
}
|
|
349
|
+
export function completeAdaptCadpgovV2(id) {
|
|
350
|
+
const j = _cadpgovJsV2.get(id);
|
|
351
|
+
if (!j) throw new Error(`cadpgov adapt ${id} not found`);
|
|
352
|
+
_cadpgovCheckJ(j.status, CADPGOV_ADAPT_LIFECYCLE_V2.ADAPTED);
|
|
353
|
+
const now = Date.now();
|
|
354
|
+
j.status = CADPGOV_ADAPT_LIFECYCLE_V2.ADAPTED;
|
|
355
|
+
j.updatedAt = now;
|
|
356
|
+
if (!j.settledAt) j.settledAt = now;
|
|
357
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
358
|
+
}
|
|
359
|
+
export function failCadpgovAdaptV2(id, reason) {
|
|
360
|
+
const j = _cadpgovJsV2.get(id);
|
|
361
|
+
if (!j) throw new Error(`cadpgov adapt ${id} not found`);
|
|
362
|
+
_cadpgovCheckJ(j.status, CADPGOV_ADAPT_LIFECYCLE_V2.FAILED);
|
|
363
|
+
const now = Date.now();
|
|
364
|
+
j.status = CADPGOV_ADAPT_LIFECYCLE_V2.FAILED;
|
|
365
|
+
j.updatedAt = now;
|
|
366
|
+
if (!j.settledAt) j.settledAt = now;
|
|
367
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
368
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
369
|
+
}
|
|
370
|
+
export function cancelCadpgovAdaptV2(id, reason) {
|
|
371
|
+
const j = _cadpgovJsV2.get(id);
|
|
372
|
+
if (!j) throw new Error(`cadpgov adapt ${id} not found`);
|
|
373
|
+
_cadpgovCheckJ(j.status, CADPGOV_ADAPT_LIFECYCLE_V2.CANCELLED);
|
|
374
|
+
const now = Date.now();
|
|
375
|
+
j.status = CADPGOV_ADAPT_LIFECYCLE_V2.CANCELLED;
|
|
376
|
+
j.updatedAt = now;
|
|
377
|
+
if (!j.settledAt) j.settledAt = now;
|
|
378
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
379
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
380
|
+
}
|
|
381
|
+
export function getCadpgovAdaptV2(id) {
|
|
382
|
+
const j = _cadpgovJsV2.get(id);
|
|
383
|
+
if (!j) return null;
|
|
384
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
385
|
+
}
|
|
386
|
+
export function listCadpgovAdaptsV2() {
|
|
387
|
+
return [..._cadpgovJsV2.values()].map((j) => ({
|
|
388
|
+
...j,
|
|
389
|
+
metadata: { ...j.metadata },
|
|
390
|
+
}));
|
|
391
|
+
}
|
|
392
|
+
export function autoStaleIdleCadpgovProfilesV2({ now } = {}) {
|
|
393
|
+
const t = now ?? Date.now();
|
|
394
|
+
const flipped = [];
|
|
395
|
+
for (const p of _cadpgovPsV2.values())
|
|
396
|
+
if (
|
|
397
|
+
p.status === CADPGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
398
|
+
t - p.lastTouchedAt >= _cadpgovIdleMs
|
|
399
|
+
) {
|
|
400
|
+
p.status = CADPGOV_PROFILE_MATURITY_V2.STALE;
|
|
401
|
+
p.updatedAt = t;
|
|
402
|
+
flipped.push(p.id);
|
|
403
|
+
}
|
|
404
|
+
return { flipped, count: flipped.length };
|
|
405
|
+
}
|
|
406
|
+
export function autoFailStuckCadpgovAdaptsV2({ now } = {}) {
|
|
407
|
+
const t = now ?? Date.now();
|
|
408
|
+
const flipped = [];
|
|
409
|
+
for (const j of _cadpgovJsV2.values())
|
|
410
|
+
if (
|
|
411
|
+
j.status === CADPGOV_ADAPT_LIFECYCLE_V2.ADAPTING &&
|
|
412
|
+
j.startedAt != null &&
|
|
413
|
+
t - j.startedAt >= _cadpgovStuckMs
|
|
414
|
+
) {
|
|
415
|
+
j.status = CADPGOV_ADAPT_LIFECYCLE_V2.FAILED;
|
|
416
|
+
j.updatedAt = t;
|
|
417
|
+
if (!j.settledAt) j.settledAt = t;
|
|
418
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
419
|
+
flipped.push(j.id);
|
|
420
|
+
}
|
|
421
|
+
return { flipped, count: flipped.length };
|
|
422
|
+
}
|
|
423
|
+
export function getCoworkAdapterGovStatsV2() {
|
|
424
|
+
const profilesByStatus = {};
|
|
425
|
+
for (const v of Object.values(CADPGOV_PROFILE_MATURITY_V2))
|
|
426
|
+
profilesByStatus[v] = 0;
|
|
427
|
+
for (const p of _cadpgovPsV2.values()) profilesByStatus[p.status]++;
|
|
428
|
+
const adaptsByStatus = {};
|
|
429
|
+
for (const v of Object.values(CADPGOV_ADAPT_LIFECYCLE_V2))
|
|
430
|
+
adaptsByStatus[v] = 0;
|
|
431
|
+
for (const j of _cadpgovJsV2.values()) adaptsByStatus[j.status]++;
|
|
432
|
+
return {
|
|
433
|
+
totalCadpgovProfilesV2: _cadpgovPsV2.size,
|
|
434
|
+
totalCadpgovAdaptsV2: _cadpgovJsV2.size,
|
|
435
|
+
maxActiveCadpgovProfilesPerOwner: _cadpgovMaxActive,
|
|
436
|
+
maxPendingCadpgovAdaptsPerProfile: _cadpgovMaxPending,
|
|
437
|
+
cadpgovProfileIdleMs: _cadpgovIdleMs,
|
|
438
|
+
cadpgovAdaptStuckMs: _cadpgovStuckMs,
|
|
439
|
+
profilesByStatus,
|
|
440
|
+
adaptsByStatus,
|
|
441
|
+
};
|
|
442
|
+
}
|
|
@@ -119,3 +119,344 @@ export async function installTemplateFromHub(
|
|
|
119
119
|
}
|
|
120
120
|
return saveUserTemplate(cwd, packet.payload);
|
|
121
121
|
}
|
|
122
|
+
|
|
123
|
+
// =====================================================================
|
|
124
|
+
// cowork-evomap-adapter V2 governance overlay (iter27)
|
|
125
|
+
// =====================================================================
|
|
126
|
+
export const CEADGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
127
|
+
PENDING: "pending",
|
|
128
|
+
ACTIVE: "active",
|
|
129
|
+
STALE: "stale",
|
|
130
|
+
ARCHIVED: "archived",
|
|
131
|
+
});
|
|
132
|
+
export const CEADGOV_BIND_LIFECYCLE_V2 = Object.freeze({
|
|
133
|
+
QUEUED: "queued",
|
|
134
|
+
BINDING: "binding",
|
|
135
|
+
BOUND: "bound",
|
|
136
|
+
FAILED: "failed",
|
|
137
|
+
CANCELLED: "cancelled",
|
|
138
|
+
});
|
|
139
|
+
const _ceadgovPTrans = new Map([
|
|
140
|
+
[
|
|
141
|
+
CEADGOV_PROFILE_MATURITY_V2.PENDING,
|
|
142
|
+
new Set([
|
|
143
|
+
CEADGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
144
|
+
CEADGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
145
|
+
]),
|
|
146
|
+
],
|
|
147
|
+
[
|
|
148
|
+
CEADGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
149
|
+
new Set([
|
|
150
|
+
CEADGOV_PROFILE_MATURITY_V2.STALE,
|
|
151
|
+
CEADGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
152
|
+
]),
|
|
153
|
+
],
|
|
154
|
+
[
|
|
155
|
+
CEADGOV_PROFILE_MATURITY_V2.STALE,
|
|
156
|
+
new Set([
|
|
157
|
+
CEADGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
158
|
+
CEADGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
159
|
+
]),
|
|
160
|
+
],
|
|
161
|
+
[CEADGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
162
|
+
]);
|
|
163
|
+
const _ceadgovPTerminal = new Set([CEADGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
164
|
+
const _ceadgovJTrans = new Map([
|
|
165
|
+
[
|
|
166
|
+
CEADGOV_BIND_LIFECYCLE_V2.QUEUED,
|
|
167
|
+
new Set([
|
|
168
|
+
CEADGOV_BIND_LIFECYCLE_V2.BINDING,
|
|
169
|
+
CEADGOV_BIND_LIFECYCLE_V2.CANCELLED,
|
|
170
|
+
]),
|
|
171
|
+
],
|
|
172
|
+
[
|
|
173
|
+
CEADGOV_BIND_LIFECYCLE_V2.BINDING,
|
|
174
|
+
new Set([
|
|
175
|
+
CEADGOV_BIND_LIFECYCLE_V2.BOUND,
|
|
176
|
+
CEADGOV_BIND_LIFECYCLE_V2.FAILED,
|
|
177
|
+
CEADGOV_BIND_LIFECYCLE_V2.CANCELLED,
|
|
178
|
+
]),
|
|
179
|
+
],
|
|
180
|
+
[CEADGOV_BIND_LIFECYCLE_V2.BOUND, new Set()],
|
|
181
|
+
[CEADGOV_BIND_LIFECYCLE_V2.FAILED, new Set()],
|
|
182
|
+
[CEADGOV_BIND_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
183
|
+
]);
|
|
184
|
+
const _ceadgovPsV2 = new Map();
|
|
185
|
+
const _ceadgovJsV2 = new Map();
|
|
186
|
+
let _ceadgovMaxActive = 6,
|
|
187
|
+
_ceadgovMaxPending = 15,
|
|
188
|
+
_ceadgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
189
|
+
_ceadgovStuckMs = 60 * 1000;
|
|
190
|
+
function _ceadgovPos(n, label) {
|
|
191
|
+
const v = Math.floor(Number(n));
|
|
192
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
193
|
+
throw new Error(`${label} must be positive integer`);
|
|
194
|
+
return v;
|
|
195
|
+
}
|
|
196
|
+
function _ceadgovCheckP(from, to) {
|
|
197
|
+
const a = _ceadgovPTrans.get(from);
|
|
198
|
+
if (!a || !a.has(to))
|
|
199
|
+
throw new Error(`invalid ceadgov profile transition ${from} → ${to}`);
|
|
200
|
+
}
|
|
201
|
+
function _ceadgovCheckJ(from, to) {
|
|
202
|
+
const a = _ceadgovJTrans.get(from);
|
|
203
|
+
if (!a || !a.has(to))
|
|
204
|
+
throw new Error(`invalid ceadgov bind transition ${from} → ${to}`);
|
|
205
|
+
}
|
|
206
|
+
function _ceadgovCountActive(owner) {
|
|
207
|
+
let c = 0;
|
|
208
|
+
for (const p of _ceadgovPsV2.values())
|
|
209
|
+
if (p.owner === owner && p.status === CEADGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
210
|
+
c++;
|
|
211
|
+
return c;
|
|
212
|
+
}
|
|
213
|
+
function _ceadgovCountPending(profileId) {
|
|
214
|
+
let c = 0;
|
|
215
|
+
for (const j of _ceadgovJsV2.values())
|
|
216
|
+
if (
|
|
217
|
+
j.profileId === profileId &&
|
|
218
|
+
(j.status === CEADGOV_BIND_LIFECYCLE_V2.QUEUED ||
|
|
219
|
+
j.status === CEADGOV_BIND_LIFECYCLE_V2.BINDING)
|
|
220
|
+
)
|
|
221
|
+
c++;
|
|
222
|
+
return c;
|
|
223
|
+
}
|
|
224
|
+
export function setMaxActiveCeadgovProfilesPerOwnerV2(n) {
|
|
225
|
+
_ceadgovMaxActive = _ceadgovPos(n, "maxActiveCeadgovProfilesPerOwner");
|
|
226
|
+
}
|
|
227
|
+
export function getMaxActiveCeadgovProfilesPerOwnerV2() {
|
|
228
|
+
return _ceadgovMaxActive;
|
|
229
|
+
}
|
|
230
|
+
export function setMaxPendingCeadgovBindsPerProfileV2(n) {
|
|
231
|
+
_ceadgovMaxPending = _ceadgovPos(n, "maxPendingCeadgovBindsPerProfile");
|
|
232
|
+
}
|
|
233
|
+
export function getMaxPendingCeadgovBindsPerProfileV2() {
|
|
234
|
+
return _ceadgovMaxPending;
|
|
235
|
+
}
|
|
236
|
+
export function setCeadgovProfileIdleMsV2(n) {
|
|
237
|
+
_ceadgovIdleMs = _ceadgovPos(n, "ceadgovProfileIdleMs");
|
|
238
|
+
}
|
|
239
|
+
export function getCeadgovProfileIdleMsV2() {
|
|
240
|
+
return _ceadgovIdleMs;
|
|
241
|
+
}
|
|
242
|
+
export function setCeadgovBindStuckMsV2(n) {
|
|
243
|
+
_ceadgovStuckMs = _ceadgovPos(n, "ceadgovBindStuckMs");
|
|
244
|
+
}
|
|
245
|
+
export function getCeadgovBindStuckMsV2() {
|
|
246
|
+
return _ceadgovStuckMs;
|
|
247
|
+
}
|
|
248
|
+
export function _resetStateCoworkEvomapAdapterGovV2() {
|
|
249
|
+
_ceadgovPsV2.clear();
|
|
250
|
+
_ceadgovJsV2.clear();
|
|
251
|
+
_ceadgovMaxActive = 6;
|
|
252
|
+
_ceadgovMaxPending = 15;
|
|
253
|
+
_ceadgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
254
|
+
_ceadgovStuckMs = 60 * 1000;
|
|
255
|
+
}
|
|
256
|
+
export function registerCeadgovProfileV2({
|
|
257
|
+
id,
|
|
258
|
+
owner,
|
|
259
|
+
direction,
|
|
260
|
+
metadata,
|
|
261
|
+
} = {}) {
|
|
262
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
263
|
+
if (_ceadgovPsV2.has(id))
|
|
264
|
+
throw new Error(`ceadgov profile ${id} already exists`);
|
|
265
|
+
const now = Date.now();
|
|
266
|
+
const p = {
|
|
267
|
+
id,
|
|
268
|
+
owner,
|
|
269
|
+
direction: direction || "bidirectional",
|
|
270
|
+
status: CEADGOV_PROFILE_MATURITY_V2.PENDING,
|
|
271
|
+
createdAt: now,
|
|
272
|
+
updatedAt: now,
|
|
273
|
+
lastTouchedAt: now,
|
|
274
|
+
activatedAt: null,
|
|
275
|
+
archivedAt: null,
|
|
276
|
+
metadata: { ...(metadata || {}) },
|
|
277
|
+
};
|
|
278
|
+
_ceadgovPsV2.set(id, p);
|
|
279
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
280
|
+
}
|
|
281
|
+
export function activateCeadgovProfileV2(id) {
|
|
282
|
+
const p = _ceadgovPsV2.get(id);
|
|
283
|
+
if (!p) throw new Error(`ceadgov profile ${id} not found`);
|
|
284
|
+
const isInitial = p.status === CEADGOV_PROFILE_MATURITY_V2.PENDING;
|
|
285
|
+
_ceadgovCheckP(p.status, CEADGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
286
|
+
if (isInitial && _ceadgovCountActive(p.owner) >= _ceadgovMaxActive)
|
|
287
|
+
throw new Error(`max active ceadgov profiles for owner ${p.owner} reached`);
|
|
288
|
+
const now = Date.now();
|
|
289
|
+
p.status = CEADGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
290
|
+
p.updatedAt = now;
|
|
291
|
+
p.lastTouchedAt = now;
|
|
292
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
293
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
294
|
+
}
|
|
295
|
+
export function staleCeadgovProfileV2(id) {
|
|
296
|
+
const p = _ceadgovPsV2.get(id);
|
|
297
|
+
if (!p) throw new Error(`ceadgov profile ${id} not found`);
|
|
298
|
+
_ceadgovCheckP(p.status, CEADGOV_PROFILE_MATURITY_V2.STALE);
|
|
299
|
+
p.status = CEADGOV_PROFILE_MATURITY_V2.STALE;
|
|
300
|
+
p.updatedAt = Date.now();
|
|
301
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
302
|
+
}
|
|
303
|
+
export function archiveCeadgovProfileV2(id) {
|
|
304
|
+
const p = _ceadgovPsV2.get(id);
|
|
305
|
+
if (!p) throw new Error(`ceadgov profile ${id} not found`);
|
|
306
|
+
_ceadgovCheckP(p.status, CEADGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
307
|
+
const now = Date.now();
|
|
308
|
+
p.status = CEADGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
309
|
+
p.updatedAt = now;
|
|
310
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
311
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
312
|
+
}
|
|
313
|
+
export function touchCeadgovProfileV2(id) {
|
|
314
|
+
const p = _ceadgovPsV2.get(id);
|
|
315
|
+
if (!p) throw new Error(`ceadgov profile ${id} not found`);
|
|
316
|
+
if (_ceadgovPTerminal.has(p.status))
|
|
317
|
+
throw new Error(`cannot touch terminal ceadgov profile ${id}`);
|
|
318
|
+
const now = Date.now();
|
|
319
|
+
p.lastTouchedAt = now;
|
|
320
|
+
p.updatedAt = now;
|
|
321
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
322
|
+
}
|
|
323
|
+
export function getCeadgovProfileV2(id) {
|
|
324
|
+
const p = _ceadgovPsV2.get(id);
|
|
325
|
+
if (!p) return null;
|
|
326
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
327
|
+
}
|
|
328
|
+
export function listCeadgovProfilesV2() {
|
|
329
|
+
return [..._ceadgovPsV2.values()].map((p) => ({
|
|
330
|
+
...p,
|
|
331
|
+
metadata: { ...p.metadata },
|
|
332
|
+
}));
|
|
333
|
+
}
|
|
334
|
+
export function createCeadgovBindV2({ id, profileId, geneId, metadata } = {}) {
|
|
335
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
336
|
+
if (_ceadgovJsV2.has(id))
|
|
337
|
+
throw new Error(`ceadgov bind ${id} already exists`);
|
|
338
|
+
if (!_ceadgovPsV2.has(profileId))
|
|
339
|
+
throw new Error(`ceadgov profile ${profileId} not found`);
|
|
340
|
+
if (_ceadgovCountPending(profileId) >= _ceadgovMaxPending)
|
|
341
|
+
throw new Error(
|
|
342
|
+
`max pending ceadgov binds for profile ${profileId} reached`,
|
|
343
|
+
);
|
|
344
|
+
const now = Date.now();
|
|
345
|
+
const j = {
|
|
346
|
+
id,
|
|
347
|
+
profileId,
|
|
348
|
+
geneId: geneId || "",
|
|
349
|
+
status: CEADGOV_BIND_LIFECYCLE_V2.QUEUED,
|
|
350
|
+
createdAt: now,
|
|
351
|
+
updatedAt: now,
|
|
352
|
+
startedAt: null,
|
|
353
|
+
settledAt: null,
|
|
354
|
+
metadata: { ...(metadata || {}) },
|
|
355
|
+
};
|
|
356
|
+
_ceadgovJsV2.set(id, j);
|
|
357
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
358
|
+
}
|
|
359
|
+
export function bindingCeadgovBindV2(id) {
|
|
360
|
+
const j = _ceadgovJsV2.get(id);
|
|
361
|
+
if (!j) throw new Error(`ceadgov bind ${id} not found`);
|
|
362
|
+
_ceadgovCheckJ(j.status, CEADGOV_BIND_LIFECYCLE_V2.BINDING);
|
|
363
|
+
const now = Date.now();
|
|
364
|
+
j.status = CEADGOV_BIND_LIFECYCLE_V2.BINDING;
|
|
365
|
+
j.updatedAt = now;
|
|
366
|
+
if (!j.startedAt) j.startedAt = now;
|
|
367
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
368
|
+
}
|
|
369
|
+
export function completeBindCeadgovV2(id) {
|
|
370
|
+
const j = _ceadgovJsV2.get(id);
|
|
371
|
+
if (!j) throw new Error(`ceadgov bind ${id} not found`);
|
|
372
|
+
_ceadgovCheckJ(j.status, CEADGOV_BIND_LIFECYCLE_V2.BOUND);
|
|
373
|
+
const now = Date.now();
|
|
374
|
+
j.status = CEADGOV_BIND_LIFECYCLE_V2.BOUND;
|
|
375
|
+
j.updatedAt = now;
|
|
376
|
+
if (!j.settledAt) j.settledAt = now;
|
|
377
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
378
|
+
}
|
|
379
|
+
export function failCeadgovBindV2(id, reason) {
|
|
380
|
+
const j = _ceadgovJsV2.get(id);
|
|
381
|
+
if (!j) throw new Error(`ceadgov bind ${id} not found`);
|
|
382
|
+
_ceadgovCheckJ(j.status, CEADGOV_BIND_LIFECYCLE_V2.FAILED);
|
|
383
|
+
const now = Date.now();
|
|
384
|
+
j.status = CEADGOV_BIND_LIFECYCLE_V2.FAILED;
|
|
385
|
+
j.updatedAt = now;
|
|
386
|
+
if (!j.settledAt) j.settledAt = now;
|
|
387
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
388
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
389
|
+
}
|
|
390
|
+
export function cancelCeadgovBindV2(id, reason) {
|
|
391
|
+
const j = _ceadgovJsV2.get(id);
|
|
392
|
+
if (!j) throw new Error(`ceadgov bind ${id} not found`);
|
|
393
|
+
_ceadgovCheckJ(j.status, CEADGOV_BIND_LIFECYCLE_V2.CANCELLED);
|
|
394
|
+
const now = Date.now();
|
|
395
|
+
j.status = CEADGOV_BIND_LIFECYCLE_V2.CANCELLED;
|
|
396
|
+
j.updatedAt = now;
|
|
397
|
+
if (!j.settledAt) j.settledAt = now;
|
|
398
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
399
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
400
|
+
}
|
|
401
|
+
export function getCeadgovBindV2(id) {
|
|
402
|
+
const j = _ceadgovJsV2.get(id);
|
|
403
|
+
if (!j) return null;
|
|
404
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
405
|
+
}
|
|
406
|
+
export function listCeadgovBindsV2() {
|
|
407
|
+
return [..._ceadgovJsV2.values()].map((j) => ({
|
|
408
|
+
...j,
|
|
409
|
+
metadata: { ...j.metadata },
|
|
410
|
+
}));
|
|
411
|
+
}
|
|
412
|
+
export function autoStaleIdleCeadgovProfilesV2({ now } = {}) {
|
|
413
|
+
const t = now ?? Date.now();
|
|
414
|
+
const flipped = [];
|
|
415
|
+
for (const p of _ceadgovPsV2.values())
|
|
416
|
+
if (
|
|
417
|
+
p.status === CEADGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
418
|
+
t - p.lastTouchedAt >= _ceadgovIdleMs
|
|
419
|
+
) {
|
|
420
|
+
p.status = CEADGOV_PROFILE_MATURITY_V2.STALE;
|
|
421
|
+
p.updatedAt = t;
|
|
422
|
+
flipped.push(p.id);
|
|
423
|
+
}
|
|
424
|
+
return { flipped, count: flipped.length };
|
|
425
|
+
}
|
|
426
|
+
export function autoFailStuckCeadgovBindsV2({ now } = {}) {
|
|
427
|
+
const t = now ?? Date.now();
|
|
428
|
+
const flipped = [];
|
|
429
|
+
for (const j of _ceadgovJsV2.values())
|
|
430
|
+
if (
|
|
431
|
+
j.status === CEADGOV_BIND_LIFECYCLE_V2.BINDING &&
|
|
432
|
+
j.startedAt != null &&
|
|
433
|
+
t - j.startedAt >= _ceadgovStuckMs
|
|
434
|
+
) {
|
|
435
|
+
j.status = CEADGOV_BIND_LIFECYCLE_V2.FAILED;
|
|
436
|
+
j.updatedAt = t;
|
|
437
|
+
if (!j.settledAt) j.settledAt = t;
|
|
438
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
439
|
+
flipped.push(j.id);
|
|
440
|
+
}
|
|
441
|
+
return { flipped, count: flipped.length };
|
|
442
|
+
}
|
|
443
|
+
export function getCoworkEvomapAdapterGovStatsV2() {
|
|
444
|
+
const profilesByStatus = {};
|
|
445
|
+
for (const v of Object.values(CEADGOV_PROFILE_MATURITY_V2))
|
|
446
|
+
profilesByStatus[v] = 0;
|
|
447
|
+
for (const p of _ceadgovPsV2.values()) profilesByStatus[p.status]++;
|
|
448
|
+
const bindsByStatus = {};
|
|
449
|
+
for (const v of Object.values(CEADGOV_BIND_LIFECYCLE_V2))
|
|
450
|
+
bindsByStatus[v] = 0;
|
|
451
|
+
for (const j of _ceadgovJsV2.values()) bindsByStatus[j.status]++;
|
|
452
|
+
return {
|
|
453
|
+
totalCeadgovProfilesV2: _ceadgovPsV2.size,
|
|
454
|
+
totalCeadgovBindsV2: _ceadgovJsV2.size,
|
|
455
|
+
maxActiveCeadgovProfilesPerOwner: _ceadgovMaxActive,
|
|
456
|
+
maxPendingCeadgovBindsPerProfile: _ceadgovMaxPending,
|
|
457
|
+
ceadgovProfileIdleMs: _ceadgovIdleMs,
|
|
458
|
+
ceadgovBindStuckMs: _ceadgovStuckMs,
|
|
459
|
+
profilesByStatus,
|
|
460
|
+
bindsByStatus,
|
|
461
|
+
};
|
|
462
|
+
}
|