chainlesschain 0.145.0 → 0.156.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/README.md +52 -3
- package/package.json +1 -1
- package/src/commands/a2a.js +201 -0
- package/src/commands/activitypub.js +207 -0
- package/src/commands/agent-network.js +217 -0
- package/src/commands/agent.js +1250 -0
- package/src/commands/automation.js +201 -0
- package/src/commands/bi.js +203 -0
- package/src/commands/browse.js +213 -0
- package/src/commands/chat.js +605 -0
- package/src/commands/cli-anything.js +426 -0
- package/src/commands/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +822 -0
- package/src/commands/config.js +213 -0
- package/src/commands/cowork.js +1666 -0
- package/src/commands/crosschain.js +203 -0
- package/src/commands/dao.js +203 -0
- 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 +213 -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 +830 -0
- package/src/commands/export.js +213 -0
- package/src/commands/federation.js +209 -0
- package/src/commands/fusion.js +205 -0
- package/src/commands/governance.js +209 -0
- package/src/commands/hmemory.js +203 -0
- package/src/commands/hook.js +209 -0
- package/src/commands/import.js +209 -0
- package/src/commands/inference.js +207 -0
- package/src/commands/infra.js +203 -0
- package/src/commands/instinct.js +209 -0
- package/src/commands/ipfs.js +207 -0
- package/src/commands/kg.js +195 -0
- package/src/commands/llm.js +426 -0
- package/src/commands/matrix.js +207 -0
- package/src/commands/mcp.js +217 -0
- package/src/commands/memory.js +412 -0
- package/src/commands/multimodal.js +203 -0
- package/src/commands/nlprog.js +225 -0
- package/src/commands/nostr.js +209 -0
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -0
- package/src/commands/orchestrate.js +406 -0
- package/src/commands/org.js +209 -0
- package/src/commands/p2p.js +209 -0
- package/src/commands/perception.js +209 -0
- package/src/commands/permmem.js +203 -0
- package/src/commands/pipeline.js +199 -0
- package/src/commands/planmode.js +426 -0
- package/src/commands/plugin-ecosystem.js +209 -0
- package/src/commands/plugin.js +209 -0
- package/src/commands/pqc.js +213 -0
- package/src/commands/quantization.js +207 -0
- package/src/commands/rcache.js +205 -0
- package/src/commands/recommend.js +233 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/scim.js +209 -0
- package/src/commands/services.js +207 -0
- package/src/commands/session.js +209 -0
- package/src/commands/setup.js +205 -0
- package/src/commands/skill.js +414 -0
- package/src/commands/social.js +201 -0
- package/src/commands/sso.js +209 -0
- package/src/commands/start.js +209 -0
- package/src/commands/stream.js +213 -0
- package/src/commands/sync.js +209 -0
- package/src/commands/tech.js +209 -0
- package/src/commands/tenant.js +217 -0
- package/src/commands/tokens.js +209 -0
- package/src/commands/trust.js +217 -0
- package/src/commands/ui.js +225 -0
- package/src/commands/wallet.js +209 -0
- package/src/commands/workflow.js +412 -0
- package/src/index.js +252 -0
- package/src/lib/a2a-protocol.js +332 -0
- package/src/lib/activitypub-bridge.js +334 -0
- package/src/lib/agent-coordinator.js +334 -0
- package/src/lib/agent-economy.js +334 -0
- package/src/lib/agent-network.js +341 -0
- package/src/lib/agent-router.js +333 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/automation-engine.js +335 -0
- package/src/lib/autonomous-agent.js +332 -0
- package/src/lib/autonomous-developer.js +332 -0
- package/src/lib/bi-engine.js +333 -0
- package/src/lib/browser-automation.js +334 -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/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-manager.js +334 -0
- package/src/lib/content-recommendation.js +351 -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-share.js +338 -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/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 +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-governance.js +334 -0
- package/src/lib/evomap-manager.js +330 -0
- package/src/lib/execution-backend.js +330 -0
- package/src/lib/federation-hardening.js +340 -0
- package/src/lib/hashline.js +338 -0
- package/src/lib/hierarchical-memory.js +334 -0
- package/src/lib/hook-manager.js +341 -0
- package/src/lib/inference-network.js +341 -0
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/interaction-adapter.js +330 -0
- package/src/lib/interactive-planner.js +354 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/knowledge-exporter.js +341 -0
- package/src/lib/knowledge-graph.js +331 -0
- package/src/lib/knowledge-importer.js +341 -0
- package/src/lib/llm-providers.js +346 -0
- package/src/lib/matrix-bridge.js +339 -0
- package/src/lib/mcp-registry.js +346 -0
- 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 +336 -0
- package/src/lib/note-versioning.js +339 -0
- package/src/lib/org-manager.js +336 -0
- package/src/lib/p2p-manager.js +341 -0
- package/src/lib/perception.js +346 -0
- package/src/lib/permanent-memory.js +327 -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/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/process-manager.js +336 -0
- package/src/lib/protocol-fusion.js +338 -0
- package/src/lib/provider-options.js +346 -0
- package/src/lib/provider-stream.js +348 -0
- package/src/lib/quantization.js +337 -0
- package/src/lib/response-cache.js +333 -0
- package/src/lib/scim-manager.js +346 -0
- package/src/lib/service-manager.js +337 -0
- package/src/lib/session-core-singletons.js +341 -0
- package/src/lib/session-manager.js +334 -0
- package/src/lib/skill-loader.js +334 -0
- package/src/lib/skill-mcp.js +336 -0
- package/src/lib/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -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/sync-manager.js +336 -0
- package/src/lib/tech-learning-engine.js +341 -0
- package/src/lib/tenant-saas.js +341 -0
- package/src/lib/threat-intel.js +330 -0
- package/src/lib/todo-manager.js +336 -0
- package/src/lib/token-tracker.js +336 -0
- 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/wallet-manager.js +336 -0
- package/src/lib/web-ui-server.js +348 -0
- package/src/lib/workflow-engine.js +330 -0
- package/src/lib/workflow-expr.js +346 -0
- package/src/lib/ws-chat-handler.js +337 -0
package/src/lib/cowork-share.js
CHANGED
|
@@ -320,3 +320,341 @@ export function importResultPacket(cwd, packet) {
|
|
|
320
320
|
_deps.writeFileSync(file, JSON.stringify(packet, null, 2), "utf-8");
|
|
321
321
|
return { file, taskId: packet.payload.taskId };
|
|
322
322
|
}
|
|
323
|
+
|
|
324
|
+
// =====================================================================
|
|
325
|
+
// cowork-share V2 governance overlay (iter22)
|
|
326
|
+
// =====================================================================
|
|
327
|
+
export const SHGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
328
|
+
PENDING: "pending",
|
|
329
|
+
ACTIVE: "active",
|
|
330
|
+
PAUSED: "paused",
|
|
331
|
+
ARCHIVED: "archived",
|
|
332
|
+
});
|
|
333
|
+
export const SHGOV_SHARE_LIFECYCLE_V2 = Object.freeze({
|
|
334
|
+
QUEUED: "queued",
|
|
335
|
+
SHARING: "sharing",
|
|
336
|
+
SHARED: "shared",
|
|
337
|
+
FAILED: "failed",
|
|
338
|
+
CANCELLED: "cancelled",
|
|
339
|
+
});
|
|
340
|
+
const _shgovPTrans = new Map([
|
|
341
|
+
[
|
|
342
|
+
SHGOV_PROFILE_MATURITY_V2.PENDING,
|
|
343
|
+
new Set([
|
|
344
|
+
SHGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
345
|
+
SHGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
346
|
+
]),
|
|
347
|
+
],
|
|
348
|
+
[
|
|
349
|
+
SHGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
350
|
+
new Set([
|
|
351
|
+
SHGOV_PROFILE_MATURITY_V2.PAUSED,
|
|
352
|
+
SHGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
353
|
+
]),
|
|
354
|
+
],
|
|
355
|
+
[
|
|
356
|
+
SHGOV_PROFILE_MATURITY_V2.PAUSED,
|
|
357
|
+
new Set([
|
|
358
|
+
SHGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
359
|
+
SHGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
360
|
+
]),
|
|
361
|
+
],
|
|
362
|
+
[SHGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
363
|
+
]);
|
|
364
|
+
const _shgovPTerminal = new Set([SHGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
365
|
+
const _shgovJTrans = new Map([
|
|
366
|
+
[
|
|
367
|
+
SHGOV_SHARE_LIFECYCLE_V2.QUEUED,
|
|
368
|
+
new Set([
|
|
369
|
+
SHGOV_SHARE_LIFECYCLE_V2.SHARING,
|
|
370
|
+
SHGOV_SHARE_LIFECYCLE_V2.CANCELLED,
|
|
371
|
+
]),
|
|
372
|
+
],
|
|
373
|
+
[
|
|
374
|
+
SHGOV_SHARE_LIFECYCLE_V2.SHARING,
|
|
375
|
+
new Set([
|
|
376
|
+
SHGOV_SHARE_LIFECYCLE_V2.SHARED,
|
|
377
|
+
SHGOV_SHARE_LIFECYCLE_V2.FAILED,
|
|
378
|
+
SHGOV_SHARE_LIFECYCLE_V2.CANCELLED,
|
|
379
|
+
]),
|
|
380
|
+
],
|
|
381
|
+
[SHGOV_SHARE_LIFECYCLE_V2.SHARED, new Set()],
|
|
382
|
+
[SHGOV_SHARE_LIFECYCLE_V2.FAILED, new Set()],
|
|
383
|
+
[SHGOV_SHARE_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
384
|
+
]);
|
|
385
|
+
const _shgovPsV2 = new Map();
|
|
386
|
+
const _shgovJsV2 = new Map();
|
|
387
|
+
let _shgovMaxActive = 8,
|
|
388
|
+
_shgovMaxPending = 20,
|
|
389
|
+
_shgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
390
|
+
_shgovStuckMs = 60 * 1000;
|
|
391
|
+
function _shgovPos(n, label) {
|
|
392
|
+
const v = Math.floor(Number(n));
|
|
393
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
394
|
+
throw new Error(`${label} must be positive integer`);
|
|
395
|
+
return v;
|
|
396
|
+
}
|
|
397
|
+
function _shgovCheckP(from, to) {
|
|
398
|
+
const a = _shgovPTrans.get(from);
|
|
399
|
+
if (!a || !a.has(to))
|
|
400
|
+
throw new Error(`invalid shgov profile transition ${from} → ${to}`);
|
|
401
|
+
}
|
|
402
|
+
function _shgovCheckJ(from, to) {
|
|
403
|
+
const a = _shgovJTrans.get(from);
|
|
404
|
+
if (!a || !a.has(to))
|
|
405
|
+
throw new Error(`invalid shgov share transition ${from} → ${to}`);
|
|
406
|
+
}
|
|
407
|
+
function _shgovCountActive(owner) {
|
|
408
|
+
let c = 0;
|
|
409
|
+
for (const p of _shgovPsV2.values())
|
|
410
|
+
if (p.owner === owner && p.status === SHGOV_PROFILE_MATURITY_V2.ACTIVE) c++;
|
|
411
|
+
return c;
|
|
412
|
+
}
|
|
413
|
+
function _shgovCountPending(profileId) {
|
|
414
|
+
let c = 0;
|
|
415
|
+
for (const j of _shgovJsV2.values())
|
|
416
|
+
if (
|
|
417
|
+
j.profileId === profileId &&
|
|
418
|
+
(j.status === SHGOV_SHARE_LIFECYCLE_V2.QUEUED ||
|
|
419
|
+
j.status === SHGOV_SHARE_LIFECYCLE_V2.SHARING)
|
|
420
|
+
)
|
|
421
|
+
c++;
|
|
422
|
+
return c;
|
|
423
|
+
}
|
|
424
|
+
export function setMaxActiveShgovProfilesPerOwnerV2(n) {
|
|
425
|
+
_shgovMaxActive = _shgovPos(n, "maxActiveShgovProfilesPerOwner");
|
|
426
|
+
}
|
|
427
|
+
export function getMaxActiveShgovProfilesPerOwnerV2() {
|
|
428
|
+
return _shgovMaxActive;
|
|
429
|
+
}
|
|
430
|
+
export function setMaxPendingShgovSharesPerProfileV2(n) {
|
|
431
|
+
_shgovMaxPending = _shgovPos(n, "maxPendingShgovSharesPerProfile");
|
|
432
|
+
}
|
|
433
|
+
export function getMaxPendingShgovSharesPerProfileV2() {
|
|
434
|
+
return _shgovMaxPending;
|
|
435
|
+
}
|
|
436
|
+
export function setShgovProfileIdleMsV2(n) {
|
|
437
|
+
_shgovIdleMs = _shgovPos(n, "shgovProfileIdleMs");
|
|
438
|
+
}
|
|
439
|
+
export function getShgovProfileIdleMsV2() {
|
|
440
|
+
return _shgovIdleMs;
|
|
441
|
+
}
|
|
442
|
+
export function setShgovShareStuckMsV2(n) {
|
|
443
|
+
_shgovStuckMs = _shgovPos(n, "shgovShareStuckMs");
|
|
444
|
+
}
|
|
445
|
+
export function getShgovShareStuckMsV2() {
|
|
446
|
+
return _shgovStuckMs;
|
|
447
|
+
}
|
|
448
|
+
export function _resetStateCoworkShareGovV2() {
|
|
449
|
+
_shgovPsV2.clear();
|
|
450
|
+
_shgovJsV2.clear();
|
|
451
|
+
_shgovMaxActive = 8;
|
|
452
|
+
_shgovMaxPending = 20;
|
|
453
|
+
_shgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
454
|
+
_shgovStuckMs = 60 * 1000;
|
|
455
|
+
}
|
|
456
|
+
export function registerShgovProfileV2({
|
|
457
|
+
id,
|
|
458
|
+
owner,
|
|
459
|
+
visibility,
|
|
460
|
+
metadata,
|
|
461
|
+
} = {}) {
|
|
462
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
463
|
+
if (_shgovPsV2.has(id)) throw new Error(`shgov profile ${id} already exists`);
|
|
464
|
+
const now = Date.now();
|
|
465
|
+
const p = {
|
|
466
|
+
id,
|
|
467
|
+
owner,
|
|
468
|
+
visibility: visibility || "private",
|
|
469
|
+
status: SHGOV_PROFILE_MATURITY_V2.PENDING,
|
|
470
|
+
createdAt: now,
|
|
471
|
+
updatedAt: now,
|
|
472
|
+
lastTouchedAt: now,
|
|
473
|
+
activatedAt: null,
|
|
474
|
+
archivedAt: null,
|
|
475
|
+
metadata: { ...(metadata || {}) },
|
|
476
|
+
};
|
|
477
|
+
_shgovPsV2.set(id, p);
|
|
478
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
479
|
+
}
|
|
480
|
+
export function activateShgovProfileV2(id) {
|
|
481
|
+
const p = _shgovPsV2.get(id);
|
|
482
|
+
if (!p) throw new Error(`shgov profile ${id} not found`);
|
|
483
|
+
const isInitial = p.status === SHGOV_PROFILE_MATURITY_V2.PENDING;
|
|
484
|
+
_shgovCheckP(p.status, SHGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
485
|
+
if (isInitial && _shgovCountActive(p.owner) >= _shgovMaxActive)
|
|
486
|
+
throw new Error(`max active shgov profiles for owner ${p.owner} reached`);
|
|
487
|
+
const now = Date.now();
|
|
488
|
+
p.status = SHGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
489
|
+
p.updatedAt = now;
|
|
490
|
+
p.lastTouchedAt = now;
|
|
491
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
492
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
493
|
+
}
|
|
494
|
+
export function pauseShgovProfileV2(id) {
|
|
495
|
+
const p = _shgovPsV2.get(id);
|
|
496
|
+
if (!p) throw new Error(`shgov profile ${id} not found`);
|
|
497
|
+
_shgovCheckP(p.status, SHGOV_PROFILE_MATURITY_V2.PAUSED);
|
|
498
|
+
p.status = SHGOV_PROFILE_MATURITY_V2.PAUSED;
|
|
499
|
+
p.updatedAt = Date.now();
|
|
500
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
501
|
+
}
|
|
502
|
+
export function archiveShgovProfileV2(id) {
|
|
503
|
+
const p = _shgovPsV2.get(id);
|
|
504
|
+
if (!p) throw new Error(`shgov profile ${id} not found`);
|
|
505
|
+
_shgovCheckP(p.status, SHGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
506
|
+
const now = Date.now();
|
|
507
|
+
p.status = SHGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
508
|
+
p.updatedAt = now;
|
|
509
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
510
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
511
|
+
}
|
|
512
|
+
export function touchShgovProfileV2(id) {
|
|
513
|
+
const p = _shgovPsV2.get(id);
|
|
514
|
+
if (!p) throw new Error(`shgov profile ${id} not found`);
|
|
515
|
+
if (_shgovPTerminal.has(p.status))
|
|
516
|
+
throw new Error(`cannot touch terminal shgov profile ${id}`);
|
|
517
|
+
const now = Date.now();
|
|
518
|
+
p.lastTouchedAt = now;
|
|
519
|
+
p.updatedAt = now;
|
|
520
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
521
|
+
}
|
|
522
|
+
export function getShgovProfileV2(id) {
|
|
523
|
+
const p = _shgovPsV2.get(id);
|
|
524
|
+
if (!p) return null;
|
|
525
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
526
|
+
}
|
|
527
|
+
export function listShgovProfilesV2() {
|
|
528
|
+
return [..._shgovPsV2.values()].map((p) => ({
|
|
529
|
+
...p,
|
|
530
|
+
metadata: { ...p.metadata },
|
|
531
|
+
}));
|
|
532
|
+
}
|
|
533
|
+
export function createShgovShareV2({ id, profileId, target, metadata } = {}) {
|
|
534
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
535
|
+
if (_shgovJsV2.has(id)) throw new Error(`shgov share ${id} already exists`);
|
|
536
|
+
if (!_shgovPsV2.has(profileId))
|
|
537
|
+
throw new Error(`shgov profile ${profileId} not found`);
|
|
538
|
+
if (_shgovCountPending(profileId) >= _shgovMaxPending)
|
|
539
|
+
throw new Error(
|
|
540
|
+
`max pending shgov shares for profile ${profileId} reached`,
|
|
541
|
+
);
|
|
542
|
+
const now = Date.now();
|
|
543
|
+
const j = {
|
|
544
|
+
id,
|
|
545
|
+
profileId,
|
|
546
|
+
target: target || "",
|
|
547
|
+
status: SHGOV_SHARE_LIFECYCLE_V2.QUEUED,
|
|
548
|
+
createdAt: now,
|
|
549
|
+
updatedAt: now,
|
|
550
|
+
startedAt: null,
|
|
551
|
+
settledAt: null,
|
|
552
|
+
metadata: { ...(metadata || {}) },
|
|
553
|
+
};
|
|
554
|
+
_shgovJsV2.set(id, j);
|
|
555
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
556
|
+
}
|
|
557
|
+
export function sharingShgovShareV2(id) {
|
|
558
|
+
const j = _shgovJsV2.get(id);
|
|
559
|
+
if (!j) throw new Error(`shgov share ${id} not found`);
|
|
560
|
+
_shgovCheckJ(j.status, SHGOV_SHARE_LIFECYCLE_V2.SHARING);
|
|
561
|
+
const now = Date.now();
|
|
562
|
+
j.status = SHGOV_SHARE_LIFECYCLE_V2.SHARING;
|
|
563
|
+
j.updatedAt = now;
|
|
564
|
+
if (!j.startedAt) j.startedAt = now;
|
|
565
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
566
|
+
}
|
|
567
|
+
export function completeShareShgovV2(id) {
|
|
568
|
+
const j = _shgovJsV2.get(id);
|
|
569
|
+
if (!j) throw new Error(`shgov share ${id} not found`);
|
|
570
|
+
_shgovCheckJ(j.status, SHGOV_SHARE_LIFECYCLE_V2.SHARED);
|
|
571
|
+
const now = Date.now();
|
|
572
|
+
j.status = SHGOV_SHARE_LIFECYCLE_V2.SHARED;
|
|
573
|
+
j.updatedAt = now;
|
|
574
|
+
if (!j.settledAt) j.settledAt = now;
|
|
575
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
576
|
+
}
|
|
577
|
+
export function failShgovShareV2(id, reason) {
|
|
578
|
+
const j = _shgovJsV2.get(id);
|
|
579
|
+
if (!j) throw new Error(`shgov share ${id} not found`);
|
|
580
|
+
_shgovCheckJ(j.status, SHGOV_SHARE_LIFECYCLE_V2.FAILED);
|
|
581
|
+
const now = Date.now();
|
|
582
|
+
j.status = SHGOV_SHARE_LIFECYCLE_V2.FAILED;
|
|
583
|
+
j.updatedAt = now;
|
|
584
|
+
if (!j.settledAt) j.settledAt = now;
|
|
585
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
586
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
587
|
+
}
|
|
588
|
+
export function cancelShgovShareV2(id, reason) {
|
|
589
|
+
const j = _shgovJsV2.get(id);
|
|
590
|
+
if (!j) throw new Error(`shgov share ${id} not found`);
|
|
591
|
+
_shgovCheckJ(j.status, SHGOV_SHARE_LIFECYCLE_V2.CANCELLED);
|
|
592
|
+
const now = Date.now();
|
|
593
|
+
j.status = SHGOV_SHARE_LIFECYCLE_V2.CANCELLED;
|
|
594
|
+
j.updatedAt = now;
|
|
595
|
+
if (!j.settledAt) j.settledAt = now;
|
|
596
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
597
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
598
|
+
}
|
|
599
|
+
export function getShgovShareV2(id) {
|
|
600
|
+
const j = _shgovJsV2.get(id);
|
|
601
|
+
if (!j) return null;
|
|
602
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
603
|
+
}
|
|
604
|
+
export function listShgovSharesV2() {
|
|
605
|
+
return [..._shgovJsV2.values()].map((j) => ({
|
|
606
|
+
...j,
|
|
607
|
+
metadata: { ...j.metadata },
|
|
608
|
+
}));
|
|
609
|
+
}
|
|
610
|
+
export function autoPauseIdleShgovProfilesV2({ now } = {}) {
|
|
611
|
+
const t = now ?? Date.now();
|
|
612
|
+
const flipped = [];
|
|
613
|
+
for (const p of _shgovPsV2.values())
|
|
614
|
+
if (
|
|
615
|
+
p.status === SHGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
616
|
+
t - p.lastTouchedAt >= _shgovIdleMs
|
|
617
|
+
) {
|
|
618
|
+
p.status = SHGOV_PROFILE_MATURITY_V2.PAUSED;
|
|
619
|
+
p.updatedAt = t;
|
|
620
|
+
flipped.push(p.id);
|
|
621
|
+
}
|
|
622
|
+
return { flipped, count: flipped.length };
|
|
623
|
+
}
|
|
624
|
+
export function autoFailStuckShgovSharesV2({ now } = {}) {
|
|
625
|
+
const t = now ?? Date.now();
|
|
626
|
+
const flipped = [];
|
|
627
|
+
for (const j of _shgovJsV2.values())
|
|
628
|
+
if (
|
|
629
|
+
j.status === SHGOV_SHARE_LIFECYCLE_V2.SHARING &&
|
|
630
|
+
j.startedAt != null &&
|
|
631
|
+
t - j.startedAt >= _shgovStuckMs
|
|
632
|
+
) {
|
|
633
|
+
j.status = SHGOV_SHARE_LIFECYCLE_V2.FAILED;
|
|
634
|
+
j.updatedAt = t;
|
|
635
|
+
if (!j.settledAt) j.settledAt = t;
|
|
636
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
637
|
+
flipped.push(j.id);
|
|
638
|
+
}
|
|
639
|
+
return { flipped, count: flipped.length };
|
|
640
|
+
}
|
|
641
|
+
export function getCoworkShareGovStatsV2() {
|
|
642
|
+
const profilesByStatus = {};
|
|
643
|
+
for (const v of Object.values(SHGOV_PROFILE_MATURITY_V2))
|
|
644
|
+
profilesByStatus[v] = 0;
|
|
645
|
+
for (const p of _shgovPsV2.values()) profilesByStatus[p.status]++;
|
|
646
|
+
const sharesByStatus = {};
|
|
647
|
+
for (const v of Object.values(SHGOV_SHARE_LIFECYCLE_V2))
|
|
648
|
+
sharesByStatus[v] = 0;
|
|
649
|
+
for (const j of _shgovJsV2.values()) sharesByStatus[j.status]++;
|
|
650
|
+
return {
|
|
651
|
+
totalShgovProfilesV2: _shgovPsV2.size,
|
|
652
|
+
totalShgovSharesV2: _shgovJsV2.size,
|
|
653
|
+
maxActiveShgovProfilesPerOwner: _shgovMaxActive,
|
|
654
|
+
maxPendingShgovSharesPerProfile: _shgovMaxPending,
|
|
655
|
+
shgovProfileIdleMs: _shgovIdleMs,
|
|
656
|
+
shgovShareStuckMs: _shgovStuckMs,
|
|
657
|
+
profilesByStatus,
|
|
658
|
+
sharesByStatus,
|
|
659
|
+
};
|
|
660
|
+
}
|
|
@@ -651,7 +651,11 @@ export function getTemplatesForUI() {
|
|
|
651
651
|
const userInstalled = Object.values(_userTemplates).map((tpl) => ({
|
|
652
652
|
tpl,
|
|
653
653
|
// User templates carry their own ui metadata inline
|
|
654
|
-
ui: {
|
|
654
|
+
ui: {
|
|
655
|
+
icon: tpl.icon,
|
|
656
|
+
description: tpl.description,
|
|
657
|
+
examples: tpl.examples,
|
|
658
|
+
},
|
|
655
659
|
source: "user",
|
|
656
660
|
}));
|
|
657
661
|
return [...builtIn, ...userInstalled].map(({ tpl, ui, source }) => {
|
|
@@ -684,3 +688,340 @@ export function getTemplatesForUI() {
|
|
|
684
688
|
};
|
|
685
689
|
});
|
|
686
690
|
}
|
|
691
|
+
|
|
692
|
+
// =====================================================================
|
|
693
|
+
// cowork-task-templates V2 governance overlay (iter25)
|
|
694
|
+
// =====================================================================
|
|
695
|
+
export const CTTGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
696
|
+
PENDING: "pending",
|
|
697
|
+
ACTIVE: "active",
|
|
698
|
+
STALE: "stale",
|
|
699
|
+
ARCHIVED: "archived",
|
|
700
|
+
});
|
|
701
|
+
export const CTTGOV_USE_LIFECYCLE_V2 = Object.freeze({
|
|
702
|
+
QUEUED: "queued",
|
|
703
|
+
APPLYING: "applying",
|
|
704
|
+
APPLIED: "applied",
|
|
705
|
+
FAILED: "failed",
|
|
706
|
+
CANCELLED: "cancelled",
|
|
707
|
+
});
|
|
708
|
+
const _cttgovPTrans = new Map([
|
|
709
|
+
[
|
|
710
|
+
CTTGOV_PROFILE_MATURITY_V2.PENDING,
|
|
711
|
+
new Set([
|
|
712
|
+
CTTGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
713
|
+
CTTGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
714
|
+
]),
|
|
715
|
+
],
|
|
716
|
+
[
|
|
717
|
+
CTTGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
718
|
+
new Set([
|
|
719
|
+
CTTGOV_PROFILE_MATURITY_V2.STALE,
|
|
720
|
+
CTTGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
721
|
+
]),
|
|
722
|
+
],
|
|
723
|
+
[
|
|
724
|
+
CTTGOV_PROFILE_MATURITY_V2.STALE,
|
|
725
|
+
new Set([
|
|
726
|
+
CTTGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
727
|
+
CTTGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
728
|
+
]),
|
|
729
|
+
],
|
|
730
|
+
[CTTGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
731
|
+
]);
|
|
732
|
+
const _cttgovPTerminal = new Set([CTTGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
733
|
+
const _cttgovJTrans = new Map([
|
|
734
|
+
[
|
|
735
|
+
CTTGOV_USE_LIFECYCLE_V2.QUEUED,
|
|
736
|
+
new Set([
|
|
737
|
+
CTTGOV_USE_LIFECYCLE_V2.APPLYING,
|
|
738
|
+
CTTGOV_USE_LIFECYCLE_V2.CANCELLED,
|
|
739
|
+
]),
|
|
740
|
+
],
|
|
741
|
+
[
|
|
742
|
+
CTTGOV_USE_LIFECYCLE_V2.APPLYING,
|
|
743
|
+
new Set([
|
|
744
|
+
CTTGOV_USE_LIFECYCLE_V2.APPLIED,
|
|
745
|
+
CTTGOV_USE_LIFECYCLE_V2.FAILED,
|
|
746
|
+
CTTGOV_USE_LIFECYCLE_V2.CANCELLED,
|
|
747
|
+
]),
|
|
748
|
+
],
|
|
749
|
+
[CTTGOV_USE_LIFECYCLE_V2.APPLIED, new Set()],
|
|
750
|
+
[CTTGOV_USE_LIFECYCLE_V2.FAILED, new Set()],
|
|
751
|
+
[CTTGOV_USE_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
752
|
+
]);
|
|
753
|
+
const _cttgovPsV2 = new Map();
|
|
754
|
+
const _cttgovJsV2 = new Map();
|
|
755
|
+
let _cttgovMaxActive = 8,
|
|
756
|
+
_cttgovMaxPending = 20,
|
|
757
|
+
_cttgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
758
|
+
_cttgovStuckMs = 60 * 1000;
|
|
759
|
+
function _cttgovPos(n, label) {
|
|
760
|
+
const v = Math.floor(Number(n));
|
|
761
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
762
|
+
throw new Error(`${label} must be positive integer`);
|
|
763
|
+
return v;
|
|
764
|
+
}
|
|
765
|
+
function _cttgovCheckP(from, to) {
|
|
766
|
+
const a = _cttgovPTrans.get(from);
|
|
767
|
+
if (!a || !a.has(to))
|
|
768
|
+
throw new Error(`invalid cttgov profile transition ${from} → ${to}`);
|
|
769
|
+
}
|
|
770
|
+
function _cttgovCheckJ(from, to) {
|
|
771
|
+
const a = _cttgovJTrans.get(from);
|
|
772
|
+
if (!a || !a.has(to))
|
|
773
|
+
throw new Error(`invalid cttgov use transition ${from} → ${to}`);
|
|
774
|
+
}
|
|
775
|
+
function _cttgovCountActive(owner) {
|
|
776
|
+
let c = 0;
|
|
777
|
+
for (const p of _cttgovPsV2.values())
|
|
778
|
+
if (p.owner === owner && p.status === CTTGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
779
|
+
c++;
|
|
780
|
+
return c;
|
|
781
|
+
}
|
|
782
|
+
function _cttgovCountPending(profileId) {
|
|
783
|
+
let c = 0;
|
|
784
|
+
for (const j of _cttgovJsV2.values())
|
|
785
|
+
if (
|
|
786
|
+
j.profileId === profileId &&
|
|
787
|
+
(j.status === CTTGOV_USE_LIFECYCLE_V2.QUEUED ||
|
|
788
|
+
j.status === CTTGOV_USE_LIFECYCLE_V2.APPLYING)
|
|
789
|
+
)
|
|
790
|
+
c++;
|
|
791
|
+
return c;
|
|
792
|
+
}
|
|
793
|
+
export function setMaxActiveCttgovProfilesPerOwnerV2(n) {
|
|
794
|
+
_cttgovMaxActive = _cttgovPos(n, "maxActiveCttgovProfilesPerOwner");
|
|
795
|
+
}
|
|
796
|
+
export function getMaxActiveCttgovProfilesPerOwnerV2() {
|
|
797
|
+
return _cttgovMaxActive;
|
|
798
|
+
}
|
|
799
|
+
export function setMaxPendingCttgovUsesPerProfileV2(n) {
|
|
800
|
+
_cttgovMaxPending = _cttgovPos(n, "maxPendingCttgovUsesPerProfile");
|
|
801
|
+
}
|
|
802
|
+
export function getMaxPendingCttgovUsesPerProfileV2() {
|
|
803
|
+
return _cttgovMaxPending;
|
|
804
|
+
}
|
|
805
|
+
export function setCttgovProfileIdleMsV2(n) {
|
|
806
|
+
_cttgovIdleMs = _cttgovPos(n, "cttgovProfileIdleMs");
|
|
807
|
+
}
|
|
808
|
+
export function getCttgovProfileIdleMsV2() {
|
|
809
|
+
return _cttgovIdleMs;
|
|
810
|
+
}
|
|
811
|
+
export function setCttgovUseStuckMsV2(n) {
|
|
812
|
+
_cttgovStuckMs = _cttgovPos(n, "cttgovUseStuckMs");
|
|
813
|
+
}
|
|
814
|
+
export function getCttgovUseStuckMsV2() {
|
|
815
|
+
return _cttgovStuckMs;
|
|
816
|
+
}
|
|
817
|
+
export function _resetStateCoworkTaskTemplatesGovV2() {
|
|
818
|
+
_cttgovPsV2.clear();
|
|
819
|
+
_cttgovJsV2.clear();
|
|
820
|
+
_cttgovMaxActive = 8;
|
|
821
|
+
_cttgovMaxPending = 20;
|
|
822
|
+
_cttgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
823
|
+
_cttgovStuckMs = 60 * 1000;
|
|
824
|
+
}
|
|
825
|
+
export function registerCttgovProfileV2({
|
|
826
|
+
id,
|
|
827
|
+
owner,
|
|
828
|
+
category,
|
|
829
|
+
metadata,
|
|
830
|
+
} = {}) {
|
|
831
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
832
|
+
if (_cttgovPsV2.has(id))
|
|
833
|
+
throw new Error(`cttgov profile ${id} already exists`);
|
|
834
|
+
const now = Date.now();
|
|
835
|
+
const p = {
|
|
836
|
+
id,
|
|
837
|
+
owner,
|
|
838
|
+
category: category || "general",
|
|
839
|
+
status: CTTGOV_PROFILE_MATURITY_V2.PENDING,
|
|
840
|
+
createdAt: now,
|
|
841
|
+
updatedAt: now,
|
|
842
|
+
lastTouchedAt: now,
|
|
843
|
+
activatedAt: null,
|
|
844
|
+
archivedAt: null,
|
|
845
|
+
metadata: { ...(metadata || {}) },
|
|
846
|
+
};
|
|
847
|
+
_cttgovPsV2.set(id, p);
|
|
848
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
849
|
+
}
|
|
850
|
+
export function activateCttgovProfileV2(id) {
|
|
851
|
+
const p = _cttgovPsV2.get(id);
|
|
852
|
+
if (!p) throw new Error(`cttgov profile ${id} not found`);
|
|
853
|
+
const isInitial = p.status === CTTGOV_PROFILE_MATURITY_V2.PENDING;
|
|
854
|
+
_cttgovCheckP(p.status, CTTGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
855
|
+
if (isInitial && _cttgovCountActive(p.owner) >= _cttgovMaxActive)
|
|
856
|
+
throw new Error(`max active cttgov profiles for owner ${p.owner} reached`);
|
|
857
|
+
const now = Date.now();
|
|
858
|
+
p.status = CTTGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
859
|
+
p.updatedAt = now;
|
|
860
|
+
p.lastTouchedAt = now;
|
|
861
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
862
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
863
|
+
}
|
|
864
|
+
export function staleCttgovProfileV2(id) {
|
|
865
|
+
const p = _cttgovPsV2.get(id);
|
|
866
|
+
if (!p) throw new Error(`cttgov profile ${id} not found`);
|
|
867
|
+
_cttgovCheckP(p.status, CTTGOV_PROFILE_MATURITY_V2.STALE);
|
|
868
|
+
p.status = CTTGOV_PROFILE_MATURITY_V2.STALE;
|
|
869
|
+
p.updatedAt = Date.now();
|
|
870
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
871
|
+
}
|
|
872
|
+
export function archiveCttgovProfileV2(id) {
|
|
873
|
+
const p = _cttgovPsV2.get(id);
|
|
874
|
+
if (!p) throw new Error(`cttgov profile ${id} not found`);
|
|
875
|
+
_cttgovCheckP(p.status, CTTGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
876
|
+
const now = Date.now();
|
|
877
|
+
p.status = CTTGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
878
|
+
p.updatedAt = now;
|
|
879
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
880
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
881
|
+
}
|
|
882
|
+
export function touchCttgovProfileV2(id) {
|
|
883
|
+
const p = _cttgovPsV2.get(id);
|
|
884
|
+
if (!p) throw new Error(`cttgov profile ${id} not found`);
|
|
885
|
+
if (_cttgovPTerminal.has(p.status))
|
|
886
|
+
throw new Error(`cannot touch terminal cttgov profile ${id}`);
|
|
887
|
+
const now = Date.now();
|
|
888
|
+
p.lastTouchedAt = now;
|
|
889
|
+
p.updatedAt = now;
|
|
890
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
891
|
+
}
|
|
892
|
+
export function getCttgovProfileV2(id) {
|
|
893
|
+
const p = _cttgovPsV2.get(id);
|
|
894
|
+
if (!p) return null;
|
|
895
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
896
|
+
}
|
|
897
|
+
export function listCttgovProfilesV2() {
|
|
898
|
+
return [..._cttgovPsV2.values()].map((p) => ({
|
|
899
|
+
...p,
|
|
900
|
+
metadata: { ...p.metadata },
|
|
901
|
+
}));
|
|
902
|
+
}
|
|
903
|
+
export function createCttgovUseV2({ id, profileId, context, metadata } = {}) {
|
|
904
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
905
|
+
if (_cttgovJsV2.has(id)) throw new Error(`cttgov use ${id} already exists`);
|
|
906
|
+
if (!_cttgovPsV2.has(profileId))
|
|
907
|
+
throw new Error(`cttgov profile ${profileId} not found`);
|
|
908
|
+
if (_cttgovCountPending(profileId) >= _cttgovMaxPending)
|
|
909
|
+
throw new Error(`max pending cttgov uses for profile ${profileId} reached`);
|
|
910
|
+
const now = Date.now();
|
|
911
|
+
const j = {
|
|
912
|
+
id,
|
|
913
|
+
profileId,
|
|
914
|
+
context: context || "",
|
|
915
|
+
status: CTTGOV_USE_LIFECYCLE_V2.QUEUED,
|
|
916
|
+
createdAt: now,
|
|
917
|
+
updatedAt: now,
|
|
918
|
+
startedAt: null,
|
|
919
|
+
settledAt: null,
|
|
920
|
+
metadata: { ...(metadata || {}) },
|
|
921
|
+
};
|
|
922
|
+
_cttgovJsV2.set(id, j);
|
|
923
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
924
|
+
}
|
|
925
|
+
export function applyingCttgovUseV2(id) {
|
|
926
|
+
const j = _cttgovJsV2.get(id);
|
|
927
|
+
if (!j) throw new Error(`cttgov use ${id} not found`);
|
|
928
|
+
_cttgovCheckJ(j.status, CTTGOV_USE_LIFECYCLE_V2.APPLYING);
|
|
929
|
+
const now = Date.now();
|
|
930
|
+
j.status = CTTGOV_USE_LIFECYCLE_V2.APPLYING;
|
|
931
|
+
j.updatedAt = now;
|
|
932
|
+
if (!j.startedAt) j.startedAt = now;
|
|
933
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
934
|
+
}
|
|
935
|
+
export function completeUseCttgovV2(id) {
|
|
936
|
+
const j = _cttgovJsV2.get(id);
|
|
937
|
+
if (!j) throw new Error(`cttgov use ${id} not found`);
|
|
938
|
+
_cttgovCheckJ(j.status, CTTGOV_USE_LIFECYCLE_V2.APPLIED);
|
|
939
|
+
const now = Date.now();
|
|
940
|
+
j.status = CTTGOV_USE_LIFECYCLE_V2.APPLIED;
|
|
941
|
+
j.updatedAt = now;
|
|
942
|
+
if (!j.settledAt) j.settledAt = now;
|
|
943
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
944
|
+
}
|
|
945
|
+
export function failCttgovUseV2(id, reason) {
|
|
946
|
+
const j = _cttgovJsV2.get(id);
|
|
947
|
+
if (!j) throw new Error(`cttgov use ${id} not found`);
|
|
948
|
+
_cttgovCheckJ(j.status, CTTGOV_USE_LIFECYCLE_V2.FAILED);
|
|
949
|
+
const now = Date.now();
|
|
950
|
+
j.status = CTTGOV_USE_LIFECYCLE_V2.FAILED;
|
|
951
|
+
j.updatedAt = now;
|
|
952
|
+
if (!j.settledAt) j.settledAt = now;
|
|
953
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
954
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
955
|
+
}
|
|
956
|
+
export function cancelCttgovUseV2(id, reason) {
|
|
957
|
+
const j = _cttgovJsV2.get(id);
|
|
958
|
+
if (!j) throw new Error(`cttgov use ${id} not found`);
|
|
959
|
+
_cttgovCheckJ(j.status, CTTGOV_USE_LIFECYCLE_V2.CANCELLED);
|
|
960
|
+
const now = Date.now();
|
|
961
|
+
j.status = CTTGOV_USE_LIFECYCLE_V2.CANCELLED;
|
|
962
|
+
j.updatedAt = now;
|
|
963
|
+
if (!j.settledAt) j.settledAt = now;
|
|
964
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
965
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
966
|
+
}
|
|
967
|
+
export function getCttgovUseV2(id) {
|
|
968
|
+
const j = _cttgovJsV2.get(id);
|
|
969
|
+
if (!j) return null;
|
|
970
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
971
|
+
}
|
|
972
|
+
export function listCttgovUsesV2() {
|
|
973
|
+
return [..._cttgovJsV2.values()].map((j) => ({
|
|
974
|
+
...j,
|
|
975
|
+
metadata: { ...j.metadata },
|
|
976
|
+
}));
|
|
977
|
+
}
|
|
978
|
+
export function autoStaleIdleCttgovProfilesV2({ now } = {}) {
|
|
979
|
+
const t = now ?? Date.now();
|
|
980
|
+
const flipped = [];
|
|
981
|
+
for (const p of _cttgovPsV2.values())
|
|
982
|
+
if (
|
|
983
|
+
p.status === CTTGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
984
|
+
t - p.lastTouchedAt >= _cttgovIdleMs
|
|
985
|
+
) {
|
|
986
|
+
p.status = CTTGOV_PROFILE_MATURITY_V2.STALE;
|
|
987
|
+
p.updatedAt = t;
|
|
988
|
+
flipped.push(p.id);
|
|
989
|
+
}
|
|
990
|
+
return { flipped, count: flipped.length };
|
|
991
|
+
}
|
|
992
|
+
export function autoFailStuckCttgovUsesV2({ now } = {}) {
|
|
993
|
+
const t = now ?? Date.now();
|
|
994
|
+
const flipped = [];
|
|
995
|
+
for (const j of _cttgovJsV2.values())
|
|
996
|
+
if (
|
|
997
|
+
j.status === CTTGOV_USE_LIFECYCLE_V2.APPLYING &&
|
|
998
|
+
j.startedAt != null &&
|
|
999
|
+
t - j.startedAt >= _cttgovStuckMs
|
|
1000
|
+
) {
|
|
1001
|
+
j.status = CTTGOV_USE_LIFECYCLE_V2.FAILED;
|
|
1002
|
+
j.updatedAt = t;
|
|
1003
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1004
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1005
|
+
flipped.push(j.id);
|
|
1006
|
+
}
|
|
1007
|
+
return { flipped, count: flipped.length };
|
|
1008
|
+
}
|
|
1009
|
+
export function getCoworkTaskTemplatesGovStatsV2() {
|
|
1010
|
+
const profilesByStatus = {};
|
|
1011
|
+
for (const v of Object.values(CTTGOV_PROFILE_MATURITY_V2))
|
|
1012
|
+
profilesByStatus[v] = 0;
|
|
1013
|
+
for (const p of _cttgovPsV2.values()) profilesByStatus[p.status]++;
|
|
1014
|
+
const usesByStatus = {};
|
|
1015
|
+
for (const v of Object.values(CTTGOV_USE_LIFECYCLE_V2)) usesByStatus[v] = 0;
|
|
1016
|
+
for (const j of _cttgovJsV2.values()) usesByStatus[j.status]++;
|
|
1017
|
+
return {
|
|
1018
|
+
totalCttgovProfilesV2: _cttgovPsV2.size,
|
|
1019
|
+
totalCttgovUsesV2: _cttgovJsV2.size,
|
|
1020
|
+
maxActiveCttgovProfilesPerOwner: _cttgovMaxActive,
|
|
1021
|
+
maxPendingCttgovUsesPerProfile: _cttgovMaxPending,
|
|
1022
|
+
cttgovProfileIdleMs: _cttgovIdleMs,
|
|
1023
|
+
cttgovUseStuckMs: _cttgovStuckMs,
|
|
1024
|
+
profilesByStatus,
|
|
1025
|
+
usesByStatus,
|
|
1026
|
+
};
|
|
1027
|
+
}
|