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
|
@@ -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
|
+
}
|
|
@@ -180,3 +180,344 @@ export async function mountTemplateMcpTools(template, opts = {}) {
|
|
|
180
180
|
cleanup,
|
|
181
181
|
};
|
|
182
182
|
}
|
|
183
|
+
|
|
184
|
+
// =====================================================================
|
|
185
|
+
// cowork-mcp-tools V2 governance overlay (iter27)
|
|
186
|
+
// =====================================================================
|
|
187
|
+
export const CMCPGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
188
|
+
PENDING: "pending",
|
|
189
|
+
ACTIVE: "active",
|
|
190
|
+
STALE: "stale",
|
|
191
|
+
ARCHIVED: "archived",
|
|
192
|
+
});
|
|
193
|
+
export const CMCPGOV_EXEC_LIFECYCLE_V2 = Object.freeze({
|
|
194
|
+
QUEUED: "queued",
|
|
195
|
+
RUNNING: "running",
|
|
196
|
+
COMPLETED: "completed",
|
|
197
|
+
FAILED: "failed",
|
|
198
|
+
CANCELLED: "cancelled",
|
|
199
|
+
});
|
|
200
|
+
const _cmcpgovPTrans = new Map([
|
|
201
|
+
[
|
|
202
|
+
CMCPGOV_PROFILE_MATURITY_V2.PENDING,
|
|
203
|
+
new Set([
|
|
204
|
+
CMCPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
205
|
+
CMCPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
206
|
+
]),
|
|
207
|
+
],
|
|
208
|
+
[
|
|
209
|
+
CMCPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
210
|
+
new Set([
|
|
211
|
+
CMCPGOV_PROFILE_MATURITY_V2.STALE,
|
|
212
|
+
CMCPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
213
|
+
]),
|
|
214
|
+
],
|
|
215
|
+
[
|
|
216
|
+
CMCPGOV_PROFILE_MATURITY_V2.STALE,
|
|
217
|
+
new Set([
|
|
218
|
+
CMCPGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
219
|
+
CMCPGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
220
|
+
]),
|
|
221
|
+
],
|
|
222
|
+
[CMCPGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
223
|
+
]);
|
|
224
|
+
const _cmcpgovPTerminal = new Set([CMCPGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
225
|
+
const _cmcpgovJTrans = new Map([
|
|
226
|
+
[
|
|
227
|
+
CMCPGOV_EXEC_LIFECYCLE_V2.QUEUED,
|
|
228
|
+
new Set([
|
|
229
|
+
CMCPGOV_EXEC_LIFECYCLE_V2.RUNNING,
|
|
230
|
+
CMCPGOV_EXEC_LIFECYCLE_V2.CANCELLED,
|
|
231
|
+
]),
|
|
232
|
+
],
|
|
233
|
+
[
|
|
234
|
+
CMCPGOV_EXEC_LIFECYCLE_V2.RUNNING,
|
|
235
|
+
new Set([
|
|
236
|
+
CMCPGOV_EXEC_LIFECYCLE_V2.COMPLETED,
|
|
237
|
+
CMCPGOV_EXEC_LIFECYCLE_V2.FAILED,
|
|
238
|
+
CMCPGOV_EXEC_LIFECYCLE_V2.CANCELLED,
|
|
239
|
+
]),
|
|
240
|
+
],
|
|
241
|
+
[CMCPGOV_EXEC_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
242
|
+
[CMCPGOV_EXEC_LIFECYCLE_V2.FAILED, new Set()],
|
|
243
|
+
[CMCPGOV_EXEC_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
244
|
+
]);
|
|
245
|
+
const _cmcpgovPsV2 = new Map();
|
|
246
|
+
const _cmcpgovJsV2 = new Map();
|
|
247
|
+
let _cmcpgovMaxActive = 8,
|
|
248
|
+
_cmcpgovMaxPending = 20,
|
|
249
|
+
_cmcpgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
250
|
+
_cmcpgovStuckMs = 60 * 1000;
|
|
251
|
+
function _cmcpgovPos(n, label) {
|
|
252
|
+
const v = Math.floor(Number(n));
|
|
253
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
254
|
+
throw new Error(`${label} must be positive integer`);
|
|
255
|
+
return v;
|
|
256
|
+
}
|
|
257
|
+
function _cmcpgovCheckP(from, to) {
|
|
258
|
+
const a = _cmcpgovPTrans.get(from);
|
|
259
|
+
if (!a || !a.has(to))
|
|
260
|
+
throw new Error(`invalid cmcpgov profile transition ${from} → ${to}`);
|
|
261
|
+
}
|
|
262
|
+
function _cmcpgovCheckJ(from, to) {
|
|
263
|
+
const a = _cmcpgovJTrans.get(from);
|
|
264
|
+
if (!a || !a.has(to))
|
|
265
|
+
throw new Error(`invalid cmcpgov exec transition ${from} → ${to}`);
|
|
266
|
+
}
|
|
267
|
+
function _cmcpgovCountActive(owner) {
|
|
268
|
+
let c = 0;
|
|
269
|
+
for (const p of _cmcpgovPsV2.values())
|
|
270
|
+
if (p.owner === owner && p.status === CMCPGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
271
|
+
c++;
|
|
272
|
+
return c;
|
|
273
|
+
}
|
|
274
|
+
function _cmcpgovCountPending(profileId) {
|
|
275
|
+
let c = 0;
|
|
276
|
+
for (const j of _cmcpgovJsV2.values())
|
|
277
|
+
if (
|
|
278
|
+
j.profileId === profileId &&
|
|
279
|
+
(j.status === CMCPGOV_EXEC_LIFECYCLE_V2.QUEUED ||
|
|
280
|
+
j.status === CMCPGOV_EXEC_LIFECYCLE_V2.RUNNING)
|
|
281
|
+
)
|
|
282
|
+
c++;
|
|
283
|
+
return c;
|
|
284
|
+
}
|
|
285
|
+
export function setMaxActiveCmcpgovProfilesPerOwnerV2(n) {
|
|
286
|
+
_cmcpgovMaxActive = _cmcpgovPos(n, "maxActiveCmcpgovProfilesPerOwner");
|
|
287
|
+
}
|
|
288
|
+
export function getMaxActiveCmcpgovProfilesPerOwnerV2() {
|
|
289
|
+
return _cmcpgovMaxActive;
|
|
290
|
+
}
|
|
291
|
+
export function setMaxPendingCmcpgovExecsPerProfileV2(n) {
|
|
292
|
+
_cmcpgovMaxPending = _cmcpgovPos(n, "maxPendingCmcpgovExecsPerProfile");
|
|
293
|
+
}
|
|
294
|
+
export function getMaxPendingCmcpgovExecsPerProfileV2() {
|
|
295
|
+
return _cmcpgovMaxPending;
|
|
296
|
+
}
|
|
297
|
+
export function setCmcpgovProfileIdleMsV2(n) {
|
|
298
|
+
_cmcpgovIdleMs = _cmcpgovPos(n, "cmcpgovProfileIdleMs");
|
|
299
|
+
}
|
|
300
|
+
export function getCmcpgovProfileIdleMsV2() {
|
|
301
|
+
return _cmcpgovIdleMs;
|
|
302
|
+
}
|
|
303
|
+
export function setCmcpgovExecStuckMsV2(n) {
|
|
304
|
+
_cmcpgovStuckMs = _cmcpgovPos(n, "cmcpgovExecStuckMs");
|
|
305
|
+
}
|
|
306
|
+
export function getCmcpgovExecStuckMsV2() {
|
|
307
|
+
return _cmcpgovStuckMs;
|
|
308
|
+
}
|
|
309
|
+
export function _resetStateCoworkMcpToolsGovV2() {
|
|
310
|
+
_cmcpgovPsV2.clear();
|
|
311
|
+
_cmcpgovJsV2.clear();
|
|
312
|
+
_cmcpgovMaxActive = 8;
|
|
313
|
+
_cmcpgovMaxPending = 20;
|
|
314
|
+
_cmcpgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
315
|
+
_cmcpgovStuckMs = 60 * 1000;
|
|
316
|
+
}
|
|
317
|
+
export function registerCmcpgovProfileV2({
|
|
318
|
+
id,
|
|
319
|
+
owner,
|
|
320
|
+
toolset,
|
|
321
|
+
metadata,
|
|
322
|
+
} = {}) {
|
|
323
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
324
|
+
if (_cmcpgovPsV2.has(id))
|
|
325
|
+
throw new Error(`cmcpgov profile ${id} already exists`);
|
|
326
|
+
const now = Date.now();
|
|
327
|
+
const p = {
|
|
328
|
+
id,
|
|
329
|
+
owner,
|
|
330
|
+
toolset: toolset || "default",
|
|
331
|
+
status: CMCPGOV_PROFILE_MATURITY_V2.PENDING,
|
|
332
|
+
createdAt: now,
|
|
333
|
+
updatedAt: now,
|
|
334
|
+
lastTouchedAt: now,
|
|
335
|
+
activatedAt: null,
|
|
336
|
+
archivedAt: null,
|
|
337
|
+
metadata: { ...(metadata || {}) },
|
|
338
|
+
};
|
|
339
|
+
_cmcpgovPsV2.set(id, p);
|
|
340
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
341
|
+
}
|
|
342
|
+
export function activateCmcpgovProfileV2(id) {
|
|
343
|
+
const p = _cmcpgovPsV2.get(id);
|
|
344
|
+
if (!p) throw new Error(`cmcpgov profile ${id} not found`);
|
|
345
|
+
const isInitial = p.status === CMCPGOV_PROFILE_MATURITY_V2.PENDING;
|
|
346
|
+
_cmcpgovCheckP(p.status, CMCPGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
347
|
+
if (isInitial && _cmcpgovCountActive(p.owner) >= _cmcpgovMaxActive)
|
|
348
|
+
throw new Error(`max active cmcpgov profiles for owner ${p.owner} reached`);
|
|
349
|
+
const now = Date.now();
|
|
350
|
+
p.status = CMCPGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
351
|
+
p.updatedAt = now;
|
|
352
|
+
p.lastTouchedAt = now;
|
|
353
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
354
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
355
|
+
}
|
|
356
|
+
export function staleCmcpgovProfileV2(id) {
|
|
357
|
+
const p = _cmcpgovPsV2.get(id);
|
|
358
|
+
if (!p) throw new Error(`cmcpgov profile ${id} not found`);
|
|
359
|
+
_cmcpgovCheckP(p.status, CMCPGOV_PROFILE_MATURITY_V2.STALE);
|
|
360
|
+
p.status = CMCPGOV_PROFILE_MATURITY_V2.STALE;
|
|
361
|
+
p.updatedAt = Date.now();
|
|
362
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
363
|
+
}
|
|
364
|
+
export function archiveCmcpgovProfileV2(id) {
|
|
365
|
+
const p = _cmcpgovPsV2.get(id);
|
|
366
|
+
if (!p) throw new Error(`cmcpgov profile ${id} not found`);
|
|
367
|
+
_cmcpgovCheckP(p.status, CMCPGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
368
|
+
const now = Date.now();
|
|
369
|
+
p.status = CMCPGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
370
|
+
p.updatedAt = now;
|
|
371
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
372
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
373
|
+
}
|
|
374
|
+
export function touchCmcpgovProfileV2(id) {
|
|
375
|
+
const p = _cmcpgovPsV2.get(id);
|
|
376
|
+
if (!p) throw new Error(`cmcpgov profile ${id} not found`);
|
|
377
|
+
if (_cmcpgovPTerminal.has(p.status))
|
|
378
|
+
throw new Error(`cannot touch terminal cmcpgov profile ${id}`);
|
|
379
|
+
const now = Date.now();
|
|
380
|
+
p.lastTouchedAt = now;
|
|
381
|
+
p.updatedAt = now;
|
|
382
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
383
|
+
}
|
|
384
|
+
export function getCmcpgovProfileV2(id) {
|
|
385
|
+
const p = _cmcpgovPsV2.get(id);
|
|
386
|
+
if (!p) return null;
|
|
387
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
388
|
+
}
|
|
389
|
+
export function listCmcpgovProfilesV2() {
|
|
390
|
+
return [..._cmcpgovPsV2.values()].map((p) => ({
|
|
391
|
+
...p,
|
|
392
|
+
metadata: { ...p.metadata },
|
|
393
|
+
}));
|
|
394
|
+
}
|
|
395
|
+
export function createCmcpgovExecV2({ id, profileId, tool, metadata } = {}) {
|
|
396
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
397
|
+
if (_cmcpgovJsV2.has(id))
|
|
398
|
+
throw new Error(`cmcpgov exec ${id} already exists`);
|
|
399
|
+
if (!_cmcpgovPsV2.has(profileId))
|
|
400
|
+
throw new Error(`cmcpgov profile ${profileId} not found`);
|
|
401
|
+
if (_cmcpgovCountPending(profileId) >= _cmcpgovMaxPending)
|
|
402
|
+
throw new Error(
|
|
403
|
+
`max pending cmcpgov execs for profile ${profileId} reached`,
|
|
404
|
+
);
|
|
405
|
+
const now = Date.now();
|
|
406
|
+
const j = {
|
|
407
|
+
id,
|
|
408
|
+
profileId,
|
|
409
|
+
tool: tool || "",
|
|
410
|
+
status: CMCPGOV_EXEC_LIFECYCLE_V2.QUEUED,
|
|
411
|
+
createdAt: now,
|
|
412
|
+
updatedAt: now,
|
|
413
|
+
startedAt: null,
|
|
414
|
+
settledAt: null,
|
|
415
|
+
metadata: { ...(metadata || {}) },
|
|
416
|
+
};
|
|
417
|
+
_cmcpgovJsV2.set(id, j);
|
|
418
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
419
|
+
}
|
|
420
|
+
export function runningCmcpgovExecV2(id) {
|
|
421
|
+
const j = _cmcpgovJsV2.get(id);
|
|
422
|
+
if (!j) throw new Error(`cmcpgov exec ${id} not found`);
|
|
423
|
+
_cmcpgovCheckJ(j.status, CMCPGOV_EXEC_LIFECYCLE_V2.RUNNING);
|
|
424
|
+
const now = Date.now();
|
|
425
|
+
j.status = CMCPGOV_EXEC_LIFECYCLE_V2.RUNNING;
|
|
426
|
+
j.updatedAt = now;
|
|
427
|
+
if (!j.startedAt) j.startedAt = now;
|
|
428
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
429
|
+
}
|
|
430
|
+
export function completeExecCmcpgovV2(id) {
|
|
431
|
+
const j = _cmcpgovJsV2.get(id);
|
|
432
|
+
if (!j) throw new Error(`cmcpgov exec ${id} not found`);
|
|
433
|
+
_cmcpgovCheckJ(j.status, CMCPGOV_EXEC_LIFECYCLE_V2.COMPLETED);
|
|
434
|
+
const now = Date.now();
|
|
435
|
+
j.status = CMCPGOV_EXEC_LIFECYCLE_V2.COMPLETED;
|
|
436
|
+
j.updatedAt = now;
|
|
437
|
+
if (!j.settledAt) j.settledAt = now;
|
|
438
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
439
|
+
}
|
|
440
|
+
export function failCmcpgovExecV2(id, reason) {
|
|
441
|
+
const j = _cmcpgovJsV2.get(id);
|
|
442
|
+
if (!j) throw new Error(`cmcpgov exec ${id} not found`);
|
|
443
|
+
_cmcpgovCheckJ(j.status, CMCPGOV_EXEC_LIFECYCLE_V2.FAILED);
|
|
444
|
+
const now = Date.now();
|
|
445
|
+
j.status = CMCPGOV_EXEC_LIFECYCLE_V2.FAILED;
|
|
446
|
+
j.updatedAt = now;
|
|
447
|
+
if (!j.settledAt) j.settledAt = now;
|
|
448
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
449
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
450
|
+
}
|
|
451
|
+
export function cancelCmcpgovExecV2(id, reason) {
|
|
452
|
+
const j = _cmcpgovJsV2.get(id);
|
|
453
|
+
if (!j) throw new Error(`cmcpgov exec ${id} not found`);
|
|
454
|
+
_cmcpgovCheckJ(j.status, CMCPGOV_EXEC_LIFECYCLE_V2.CANCELLED);
|
|
455
|
+
const now = Date.now();
|
|
456
|
+
j.status = CMCPGOV_EXEC_LIFECYCLE_V2.CANCELLED;
|
|
457
|
+
j.updatedAt = now;
|
|
458
|
+
if (!j.settledAt) j.settledAt = now;
|
|
459
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
460
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
461
|
+
}
|
|
462
|
+
export function getCmcpgovExecV2(id) {
|
|
463
|
+
const j = _cmcpgovJsV2.get(id);
|
|
464
|
+
if (!j) return null;
|
|
465
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
466
|
+
}
|
|
467
|
+
export function listCmcpgovExecsV2() {
|
|
468
|
+
return [..._cmcpgovJsV2.values()].map((j) => ({
|
|
469
|
+
...j,
|
|
470
|
+
metadata: { ...j.metadata },
|
|
471
|
+
}));
|
|
472
|
+
}
|
|
473
|
+
export function autoStaleIdleCmcpgovProfilesV2({ now } = {}) {
|
|
474
|
+
const t = now ?? Date.now();
|
|
475
|
+
const flipped = [];
|
|
476
|
+
for (const p of _cmcpgovPsV2.values())
|
|
477
|
+
if (
|
|
478
|
+
p.status === CMCPGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
479
|
+
t - p.lastTouchedAt >= _cmcpgovIdleMs
|
|
480
|
+
) {
|
|
481
|
+
p.status = CMCPGOV_PROFILE_MATURITY_V2.STALE;
|
|
482
|
+
p.updatedAt = t;
|
|
483
|
+
flipped.push(p.id);
|
|
484
|
+
}
|
|
485
|
+
return { flipped, count: flipped.length };
|
|
486
|
+
}
|
|
487
|
+
export function autoFailStuckCmcpgovExecsV2({ now } = {}) {
|
|
488
|
+
const t = now ?? Date.now();
|
|
489
|
+
const flipped = [];
|
|
490
|
+
for (const j of _cmcpgovJsV2.values())
|
|
491
|
+
if (
|
|
492
|
+
j.status === CMCPGOV_EXEC_LIFECYCLE_V2.RUNNING &&
|
|
493
|
+
j.startedAt != null &&
|
|
494
|
+
t - j.startedAt >= _cmcpgovStuckMs
|
|
495
|
+
) {
|
|
496
|
+
j.status = CMCPGOV_EXEC_LIFECYCLE_V2.FAILED;
|
|
497
|
+
j.updatedAt = t;
|
|
498
|
+
if (!j.settledAt) j.settledAt = t;
|
|
499
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
500
|
+
flipped.push(j.id);
|
|
501
|
+
}
|
|
502
|
+
return { flipped, count: flipped.length };
|
|
503
|
+
}
|
|
504
|
+
export function getCoworkMcpToolsGovStatsV2() {
|
|
505
|
+
const profilesByStatus = {};
|
|
506
|
+
for (const v of Object.values(CMCPGOV_PROFILE_MATURITY_V2))
|
|
507
|
+
profilesByStatus[v] = 0;
|
|
508
|
+
for (const p of _cmcpgovPsV2.values()) profilesByStatus[p.status]++;
|
|
509
|
+
const execsByStatus = {};
|
|
510
|
+
for (const v of Object.values(CMCPGOV_EXEC_LIFECYCLE_V2))
|
|
511
|
+
execsByStatus[v] = 0;
|
|
512
|
+
for (const j of _cmcpgovJsV2.values()) execsByStatus[j.status]++;
|
|
513
|
+
return {
|
|
514
|
+
totalCmcpgovProfilesV2: _cmcpgovPsV2.size,
|
|
515
|
+
totalCmcpgovExecsV2: _cmcpgovJsV2.size,
|
|
516
|
+
maxActiveCmcpgovProfilesPerOwner: _cmcpgovMaxActive,
|
|
517
|
+
maxPendingCmcpgovExecsPerProfile: _cmcpgovMaxPending,
|
|
518
|
+
cmcpgovProfileIdleMs: _cmcpgovIdleMs,
|
|
519
|
+
cmcpgovExecStuckMs: _cmcpgovStuckMs,
|
|
520
|
+
profilesByStatus,
|
|
521
|
+
execsByStatus,
|
|
522
|
+
};
|
|
523
|
+
}
|