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
|
@@ -106,3 +106,344 @@ export function buildHtml(data) {
|
|
|
106
106
|
</body>
|
|
107
107
|
</html>`;
|
|
108
108
|
}
|
|
109
|
+
|
|
110
|
+
// =====================================================================
|
|
111
|
+
// cowork-observe-html V2 governance overlay (iter27)
|
|
112
|
+
// =====================================================================
|
|
113
|
+
export const COHTGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
114
|
+
PENDING: "pending",
|
|
115
|
+
ACTIVE: "active",
|
|
116
|
+
STALE: "stale",
|
|
117
|
+
ARCHIVED: "archived",
|
|
118
|
+
});
|
|
119
|
+
export const COHTGOV_RENDER_LIFECYCLE_V2 = Object.freeze({
|
|
120
|
+
QUEUED: "queued",
|
|
121
|
+
RENDERING: "rendering",
|
|
122
|
+
RENDERED: "rendered",
|
|
123
|
+
FAILED: "failed",
|
|
124
|
+
CANCELLED: "cancelled",
|
|
125
|
+
});
|
|
126
|
+
const _cohtgovPTrans = new Map([
|
|
127
|
+
[
|
|
128
|
+
COHTGOV_PROFILE_MATURITY_V2.PENDING,
|
|
129
|
+
new Set([
|
|
130
|
+
COHTGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
131
|
+
COHTGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
132
|
+
]),
|
|
133
|
+
],
|
|
134
|
+
[
|
|
135
|
+
COHTGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
136
|
+
new Set([
|
|
137
|
+
COHTGOV_PROFILE_MATURITY_V2.STALE,
|
|
138
|
+
COHTGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
139
|
+
]),
|
|
140
|
+
],
|
|
141
|
+
[
|
|
142
|
+
COHTGOV_PROFILE_MATURITY_V2.STALE,
|
|
143
|
+
new Set([
|
|
144
|
+
COHTGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
145
|
+
COHTGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
146
|
+
]),
|
|
147
|
+
],
|
|
148
|
+
[COHTGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
149
|
+
]);
|
|
150
|
+
const _cohtgovPTerminal = new Set([COHTGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
151
|
+
const _cohtgovJTrans = new Map([
|
|
152
|
+
[
|
|
153
|
+
COHTGOV_RENDER_LIFECYCLE_V2.QUEUED,
|
|
154
|
+
new Set([
|
|
155
|
+
COHTGOV_RENDER_LIFECYCLE_V2.RENDERING,
|
|
156
|
+
COHTGOV_RENDER_LIFECYCLE_V2.CANCELLED,
|
|
157
|
+
]),
|
|
158
|
+
],
|
|
159
|
+
[
|
|
160
|
+
COHTGOV_RENDER_LIFECYCLE_V2.RENDERING,
|
|
161
|
+
new Set([
|
|
162
|
+
COHTGOV_RENDER_LIFECYCLE_V2.RENDERED,
|
|
163
|
+
COHTGOV_RENDER_LIFECYCLE_V2.FAILED,
|
|
164
|
+
COHTGOV_RENDER_LIFECYCLE_V2.CANCELLED,
|
|
165
|
+
]),
|
|
166
|
+
],
|
|
167
|
+
[COHTGOV_RENDER_LIFECYCLE_V2.RENDERED, new Set()],
|
|
168
|
+
[COHTGOV_RENDER_LIFECYCLE_V2.FAILED, new Set()],
|
|
169
|
+
[COHTGOV_RENDER_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
170
|
+
]);
|
|
171
|
+
const _cohtgovPsV2 = new Map();
|
|
172
|
+
const _cohtgovJsV2 = new Map();
|
|
173
|
+
let _cohtgovMaxActive = 6,
|
|
174
|
+
_cohtgovMaxPending = 15,
|
|
175
|
+
_cohtgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
176
|
+
_cohtgovStuckMs = 60 * 1000;
|
|
177
|
+
function _cohtgovPos(n, label) {
|
|
178
|
+
const v = Math.floor(Number(n));
|
|
179
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
180
|
+
throw new Error(`${label} must be positive integer`);
|
|
181
|
+
return v;
|
|
182
|
+
}
|
|
183
|
+
function _cohtgovCheckP(from, to) {
|
|
184
|
+
const a = _cohtgovPTrans.get(from);
|
|
185
|
+
if (!a || !a.has(to))
|
|
186
|
+
throw new Error(`invalid cohtgov profile transition ${from} → ${to}`);
|
|
187
|
+
}
|
|
188
|
+
function _cohtgovCheckJ(from, to) {
|
|
189
|
+
const a = _cohtgovJTrans.get(from);
|
|
190
|
+
if (!a || !a.has(to))
|
|
191
|
+
throw new Error(`invalid cohtgov render transition ${from} → ${to}`);
|
|
192
|
+
}
|
|
193
|
+
function _cohtgovCountActive(owner) {
|
|
194
|
+
let c = 0;
|
|
195
|
+
for (const p of _cohtgovPsV2.values())
|
|
196
|
+
if (p.owner === owner && p.status === COHTGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
197
|
+
c++;
|
|
198
|
+
return c;
|
|
199
|
+
}
|
|
200
|
+
function _cohtgovCountPending(profileId) {
|
|
201
|
+
let c = 0;
|
|
202
|
+
for (const j of _cohtgovJsV2.values())
|
|
203
|
+
if (
|
|
204
|
+
j.profileId === profileId &&
|
|
205
|
+
(j.status === COHTGOV_RENDER_LIFECYCLE_V2.QUEUED ||
|
|
206
|
+
j.status === COHTGOV_RENDER_LIFECYCLE_V2.RENDERING)
|
|
207
|
+
)
|
|
208
|
+
c++;
|
|
209
|
+
return c;
|
|
210
|
+
}
|
|
211
|
+
export function setMaxActiveCohtgovProfilesPerOwnerV2(n) {
|
|
212
|
+
_cohtgovMaxActive = _cohtgovPos(n, "maxActiveCohtgovProfilesPerOwner");
|
|
213
|
+
}
|
|
214
|
+
export function getMaxActiveCohtgovProfilesPerOwnerV2() {
|
|
215
|
+
return _cohtgovMaxActive;
|
|
216
|
+
}
|
|
217
|
+
export function setMaxPendingCohtgovRendersPerProfileV2(n) {
|
|
218
|
+
_cohtgovMaxPending = _cohtgovPos(n, "maxPendingCohtgovRendersPerProfile");
|
|
219
|
+
}
|
|
220
|
+
export function getMaxPendingCohtgovRendersPerProfileV2() {
|
|
221
|
+
return _cohtgovMaxPending;
|
|
222
|
+
}
|
|
223
|
+
export function setCohtgovProfileIdleMsV2(n) {
|
|
224
|
+
_cohtgovIdleMs = _cohtgovPos(n, "cohtgovProfileIdleMs");
|
|
225
|
+
}
|
|
226
|
+
export function getCohtgovProfileIdleMsV2() {
|
|
227
|
+
return _cohtgovIdleMs;
|
|
228
|
+
}
|
|
229
|
+
export function setCohtgovRenderStuckMsV2(n) {
|
|
230
|
+
_cohtgovStuckMs = _cohtgovPos(n, "cohtgovRenderStuckMs");
|
|
231
|
+
}
|
|
232
|
+
export function getCohtgovRenderStuckMsV2() {
|
|
233
|
+
return _cohtgovStuckMs;
|
|
234
|
+
}
|
|
235
|
+
export function _resetStateCoworkObserveHtmlGovV2() {
|
|
236
|
+
_cohtgovPsV2.clear();
|
|
237
|
+
_cohtgovJsV2.clear();
|
|
238
|
+
_cohtgovMaxActive = 6;
|
|
239
|
+
_cohtgovMaxPending = 15;
|
|
240
|
+
_cohtgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
241
|
+
_cohtgovStuckMs = 60 * 1000;
|
|
242
|
+
}
|
|
243
|
+
export function registerCohtgovProfileV2({
|
|
244
|
+
id,
|
|
245
|
+
owner,
|
|
246
|
+
template,
|
|
247
|
+
metadata,
|
|
248
|
+
} = {}) {
|
|
249
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
250
|
+
if (_cohtgovPsV2.has(id))
|
|
251
|
+
throw new Error(`cohtgov profile ${id} already exists`);
|
|
252
|
+
const now = Date.now();
|
|
253
|
+
const p = {
|
|
254
|
+
id,
|
|
255
|
+
owner,
|
|
256
|
+
template: template || "default",
|
|
257
|
+
status: COHTGOV_PROFILE_MATURITY_V2.PENDING,
|
|
258
|
+
createdAt: now,
|
|
259
|
+
updatedAt: now,
|
|
260
|
+
lastTouchedAt: now,
|
|
261
|
+
activatedAt: null,
|
|
262
|
+
archivedAt: null,
|
|
263
|
+
metadata: { ...(metadata || {}) },
|
|
264
|
+
};
|
|
265
|
+
_cohtgovPsV2.set(id, p);
|
|
266
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
267
|
+
}
|
|
268
|
+
export function activateCohtgovProfileV2(id) {
|
|
269
|
+
const p = _cohtgovPsV2.get(id);
|
|
270
|
+
if (!p) throw new Error(`cohtgov profile ${id} not found`);
|
|
271
|
+
const isInitial = p.status === COHTGOV_PROFILE_MATURITY_V2.PENDING;
|
|
272
|
+
_cohtgovCheckP(p.status, COHTGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
273
|
+
if (isInitial && _cohtgovCountActive(p.owner) >= _cohtgovMaxActive)
|
|
274
|
+
throw new Error(`max active cohtgov profiles for owner ${p.owner} reached`);
|
|
275
|
+
const now = Date.now();
|
|
276
|
+
p.status = COHTGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
277
|
+
p.updatedAt = now;
|
|
278
|
+
p.lastTouchedAt = now;
|
|
279
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
280
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
281
|
+
}
|
|
282
|
+
export function staleCohtgovProfileV2(id) {
|
|
283
|
+
const p = _cohtgovPsV2.get(id);
|
|
284
|
+
if (!p) throw new Error(`cohtgov profile ${id} not found`);
|
|
285
|
+
_cohtgovCheckP(p.status, COHTGOV_PROFILE_MATURITY_V2.STALE);
|
|
286
|
+
p.status = COHTGOV_PROFILE_MATURITY_V2.STALE;
|
|
287
|
+
p.updatedAt = Date.now();
|
|
288
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
289
|
+
}
|
|
290
|
+
export function archiveCohtgovProfileV2(id) {
|
|
291
|
+
const p = _cohtgovPsV2.get(id);
|
|
292
|
+
if (!p) throw new Error(`cohtgov profile ${id} not found`);
|
|
293
|
+
_cohtgovCheckP(p.status, COHTGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
294
|
+
const now = Date.now();
|
|
295
|
+
p.status = COHTGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
296
|
+
p.updatedAt = now;
|
|
297
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
298
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
299
|
+
}
|
|
300
|
+
export function touchCohtgovProfileV2(id) {
|
|
301
|
+
const p = _cohtgovPsV2.get(id);
|
|
302
|
+
if (!p) throw new Error(`cohtgov profile ${id} not found`);
|
|
303
|
+
if (_cohtgovPTerminal.has(p.status))
|
|
304
|
+
throw new Error(`cannot touch terminal cohtgov profile ${id}`);
|
|
305
|
+
const now = Date.now();
|
|
306
|
+
p.lastTouchedAt = now;
|
|
307
|
+
p.updatedAt = now;
|
|
308
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
309
|
+
}
|
|
310
|
+
export function getCohtgovProfileV2(id) {
|
|
311
|
+
const p = _cohtgovPsV2.get(id);
|
|
312
|
+
if (!p) return null;
|
|
313
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
314
|
+
}
|
|
315
|
+
export function listCohtgovProfilesV2() {
|
|
316
|
+
return [..._cohtgovPsV2.values()].map((p) => ({
|
|
317
|
+
...p,
|
|
318
|
+
metadata: { ...p.metadata },
|
|
319
|
+
}));
|
|
320
|
+
}
|
|
321
|
+
export function createCohtgovRenderV2({ id, profileId, page, metadata } = {}) {
|
|
322
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
323
|
+
if (_cohtgovJsV2.has(id))
|
|
324
|
+
throw new Error(`cohtgov render ${id} already exists`);
|
|
325
|
+
if (!_cohtgovPsV2.has(profileId))
|
|
326
|
+
throw new Error(`cohtgov profile ${profileId} not found`);
|
|
327
|
+
if (_cohtgovCountPending(profileId) >= _cohtgovMaxPending)
|
|
328
|
+
throw new Error(
|
|
329
|
+
`max pending cohtgov renders for profile ${profileId} reached`,
|
|
330
|
+
);
|
|
331
|
+
const now = Date.now();
|
|
332
|
+
const j = {
|
|
333
|
+
id,
|
|
334
|
+
profileId,
|
|
335
|
+
page: page || "",
|
|
336
|
+
status: COHTGOV_RENDER_LIFECYCLE_V2.QUEUED,
|
|
337
|
+
createdAt: now,
|
|
338
|
+
updatedAt: now,
|
|
339
|
+
startedAt: null,
|
|
340
|
+
settledAt: null,
|
|
341
|
+
metadata: { ...(metadata || {}) },
|
|
342
|
+
};
|
|
343
|
+
_cohtgovJsV2.set(id, j);
|
|
344
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
345
|
+
}
|
|
346
|
+
export function renderingCohtgovRenderV2(id) {
|
|
347
|
+
const j = _cohtgovJsV2.get(id);
|
|
348
|
+
if (!j) throw new Error(`cohtgov render ${id} not found`);
|
|
349
|
+
_cohtgovCheckJ(j.status, COHTGOV_RENDER_LIFECYCLE_V2.RENDERING);
|
|
350
|
+
const now = Date.now();
|
|
351
|
+
j.status = COHTGOV_RENDER_LIFECYCLE_V2.RENDERING;
|
|
352
|
+
j.updatedAt = now;
|
|
353
|
+
if (!j.startedAt) j.startedAt = now;
|
|
354
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
355
|
+
}
|
|
356
|
+
export function completeRenderCohtgovV2(id) {
|
|
357
|
+
const j = _cohtgovJsV2.get(id);
|
|
358
|
+
if (!j) throw new Error(`cohtgov render ${id} not found`);
|
|
359
|
+
_cohtgovCheckJ(j.status, COHTGOV_RENDER_LIFECYCLE_V2.RENDERED);
|
|
360
|
+
const now = Date.now();
|
|
361
|
+
j.status = COHTGOV_RENDER_LIFECYCLE_V2.RENDERED;
|
|
362
|
+
j.updatedAt = now;
|
|
363
|
+
if (!j.settledAt) j.settledAt = now;
|
|
364
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
365
|
+
}
|
|
366
|
+
export function failCohtgovRenderV2(id, reason) {
|
|
367
|
+
const j = _cohtgovJsV2.get(id);
|
|
368
|
+
if (!j) throw new Error(`cohtgov render ${id} not found`);
|
|
369
|
+
_cohtgovCheckJ(j.status, COHTGOV_RENDER_LIFECYCLE_V2.FAILED);
|
|
370
|
+
const now = Date.now();
|
|
371
|
+
j.status = COHTGOV_RENDER_LIFECYCLE_V2.FAILED;
|
|
372
|
+
j.updatedAt = now;
|
|
373
|
+
if (!j.settledAt) j.settledAt = now;
|
|
374
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
375
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
376
|
+
}
|
|
377
|
+
export function cancelCohtgovRenderV2(id, reason) {
|
|
378
|
+
const j = _cohtgovJsV2.get(id);
|
|
379
|
+
if (!j) throw new Error(`cohtgov render ${id} not found`);
|
|
380
|
+
_cohtgovCheckJ(j.status, COHTGOV_RENDER_LIFECYCLE_V2.CANCELLED);
|
|
381
|
+
const now = Date.now();
|
|
382
|
+
j.status = COHTGOV_RENDER_LIFECYCLE_V2.CANCELLED;
|
|
383
|
+
j.updatedAt = now;
|
|
384
|
+
if (!j.settledAt) j.settledAt = now;
|
|
385
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
386
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
387
|
+
}
|
|
388
|
+
export function getCohtgovRenderV2(id) {
|
|
389
|
+
const j = _cohtgovJsV2.get(id);
|
|
390
|
+
if (!j) return null;
|
|
391
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
392
|
+
}
|
|
393
|
+
export function listCohtgovRendersV2() {
|
|
394
|
+
return [..._cohtgovJsV2.values()].map((j) => ({
|
|
395
|
+
...j,
|
|
396
|
+
metadata: { ...j.metadata },
|
|
397
|
+
}));
|
|
398
|
+
}
|
|
399
|
+
export function autoStaleIdleCohtgovProfilesV2({ now } = {}) {
|
|
400
|
+
const t = now ?? Date.now();
|
|
401
|
+
const flipped = [];
|
|
402
|
+
for (const p of _cohtgovPsV2.values())
|
|
403
|
+
if (
|
|
404
|
+
p.status === COHTGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
405
|
+
t - p.lastTouchedAt >= _cohtgovIdleMs
|
|
406
|
+
) {
|
|
407
|
+
p.status = COHTGOV_PROFILE_MATURITY_V2.STALE;
|
|
408
|
+
p.updatedAt = t;
|
|
409
|
+
flipped.push(p.id);
|
|
410
|
+
}
|
|
411
|
+
return { flipped, count: flipped.length };
|
|
412
|
+
}
|
|
413
|
+
export function autoFailStuckCohtgovRendersV2({ now } = {}) {
|
|
414
|
+
const t = now ?? Date.now();
|
|
415
|
+
const flipped = [];
|
|
416
|
+
for (const j of _cohtgovJsV2.values())
|
|
417
|
+
if (
|
|
418
|
+
j.status === COHTGOV_RENDER_LIFECYCLE_V2.RENDERING &&
|
|
419
|
+
j.startedAt != null &&
|
|
420
|
+
t - j.startedAt >= _cohtgovStuckMs
|
|
421
|
+
) {
|
|
422
|
+
j.status = COHTGOV_RENDER_LIFECYCLE_V2.FAILED;
|
|
423
|
+
j.updatedAt = t;
|
|
424
|
+
if (!j.settledAt) j.settledAt = t;
|
|
425
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
426
|
+
flipped.push(j.id);
|
|
427
|
+
}
|
|
428
|
+
return { flipped, count: flipped.length };
|
|
429
|
+
}
|
|
430
|
+
export function getCoworkObserveHtmlGovStatsV2() {
|
|
431
|
+
const profilesByStatus = {};
|
|
432
|
+
for (const v of Object.values(COHTGOV_PROFILE_MATURITY_V2))
|
|
433
|
+
profilesByStatus[v] = 0;
|
|
434
|
+
for (const p of _cohtgovPsV2.values()) profilesByStatus[p.status]++;
|
|
435
|
+
const rendersByStatus = {};
|
|
436
|
+
for (const v of Object.values(COHTGOV_RENDER_LIFECYCLE_V2))
|
|
437
|
+
rendersByStatus[v] = 0;
|
|
438
|
+
for (const j of _cohtgovJsV2.values()) rendersByStatus[j.status]++;
|
|
439
|
+
return {
|
|
440
|
+
totalCohtgovProfilesV2: _cohtgovPsV2.size,
|
|
441
|
+
totalCohtgovRendersV2: _cohtgovJsV2.size,
|
|
442
|
+
maxActiveCohtgovProfilesPerOwner: _cohtgovMaxActive,
|
|
443
|
+
maxPendingCohtgovRendersPerProfile: _cohtgovMaxPending,
|
|
444
|
+
cohtgovProfileIdleMs: _cohtgovIdleMs,
|
|
445
|
+
cohtgovRenderStuckMs: _cohtgovStuckMs,
|
|
446
|
+
profilesByStatus,
|
|
447
|
+
rendersByStatus,
|
|
448
|
+
};
|
|
449
|
+
}
|
|
@@ -158,3 +158,344 @@ export function aggregate(cwd, { windowDays = 7 } = {}) {
|
|
|
158
158
|
},
|
|
159
159
|
};
|
|
160
160
|
}
|
|
161
|
+
|
|
162
|
+
// =====================================================================
|
|
163
|
+
// cowork-observe V2 governance overlay (iter27)
|
|
164
|
+
// =====================================================================
|
|
165
|
+
export const COBSGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
166
|
+
PENDING: "pending",
|
|
167
|
+
ACTIVE: "active",
|
|
168
|
+
MUTED: "muted",
|
|
169
|
+
ARCHIVED: "archived",
|
|
170
|
+
});
|
|
171
|
+
export const COBSGOV_EVENT_LIFECYCLE_V2 = Object.freeze({
|
|
172
|
+
QUEUED: "queued",
|
|
173
|
+
RECORDING: "recording",
|
|
174
|
+
RECORDED: "recorded",
|
|
175
|
+
FAILED: "failed",
|
|
176
|
+
CANCELLED: "cancelled",
|
|
177
|
+
});
|
|
178
|
+
const _cobsgovPTrans = new Map([
|
|
179
|
+
[
|
|
180
|
+
COBSGOV_PROFILE_MATURITY_V2.PENDING,
|
|
181
|
+
new Set([
|
|
182
|
+
COBSGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
183
|
+
COBSGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
184
|
+
]),
|
|
185
|
+
],
|
|
186
|
+
[
|
|
187
|
+
COBSGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
188
|
+
new Set([
|
|
189
|
+
COBSGOV_PROFILE_MATURITY_V2.MUTED,
|
|
190
|
+
COBSGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
191
|
+
]),
|
|
192
|
+
],
|
|
193
|
+
[
|
|
194
|
+
COBSGOV_PROFILE_MATURITY_V2.MUTED,
|
|
195
|
+
new Set([
|
|
196
|
+
COBSGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
197
|
+
COBSGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
198
|
+
]),
|
|
199
|
+
],
|
|
200
|
+
[COBSGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
201
|
+
]);
|
|
202
|
+
const _cobsgovPTerminal = new Set([COBSGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
203
|
+
const _cobsgovJTrans = new Map([
|
|
204
|
+
[
|
|
205
|
+
COBSGOV_EVENT_LIFECYCLE_V2.QUEUED,
|
|
206
|
+
new Set([
|
|
207
|
+
COBSGOV_EVENT_LIFECYCLE_V2.RECORDING,
|
|
208
|
+
COBSGOV_EVENT_LIFECYCLE_V2.CANCELLED,
|
|
209
|
+
]),
|
|
210
|
+
],
|
|
211
|
+
[
|
|
212
|
+
COBSGOV_EVENT_LIFECYCLE_V2.RECORDING,
|
|
213
|
+
new Set([
|
|
214
|
+
COBSGOV_EVENT_LIFECYCLE_V2.RECORDED,
|
|
215
|
+
COBSGOV_EVENT_LIFECYCLE_V2.FAILED,
|
|
216
|
+
COBSGOV_EVENT_LIFECYCLE_V2.CANCELLED,
|
|
217
|
+
]),
|
|
218
|
+
],
|
|
219
|
+
[COBSGOV_EVENT_LIFECYCLE_V2.RECORDED, new Set()],
|
|
220
|
+
[COBSGOV_EVENT_LIFECYCLE_V2.FAILED, new Set()],
|
|
221
|
+
[COBSGOV_EVENT_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
222
|
+
]);
|
|
223
|
+
const _cobsgovPsV2 = new Map();
|
|
224
|
+
const _cobsgovJsV2 = new Map();
|
|
225
|
+
let _cobsgovMaxActive = 10,
|
|
226
|
+
_cobsgovMaxPending = 25,
|
|
227
|
+
_cobsgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
228
|
+
_cobsgovStuckMs = 60 * 1000;
|
|
229
|
+
function _cobsgovPos(n, label) {
|
|
230
|
+
const v = Math.floor(Number(n));
|
|
231
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
232
|
+
throw new Error(`${label} must be positive integer`);
|
|
233
|
+
return v;
|
|
234
|
+
}
|
|
235
|
+
function _cobsgovCheckP(from, to) {
|
|
236
|
+
const a = _cobsgovPTrans.get(from);
|
|
237
|
+
if (!a || !a.has(to))
|
|
238
|
+
throw new Error(`invalid cobsgov profile transition ${from} → ${to}`);
|
|
239
|
+
}
|
|
240
|
+
function _cobsgovCheckJ(from, to) {
|
|
241
|
+
const a = _cobsgovJTrans.get(from);
|
|
242
|
+
if (!a || !a.has(to))
|
|
243
|
+
throw new Error(`invalid cobsgov event transition ${from} → ${to}`);
|
|
244
|
+
}
|
|
245
|
+
function _cobsgovCountActive(owner) {
|
|
246
|
+
let c = 0;
|
|
247
|
+
for (const p of _cobsgovPsV2.values())
|
|
248
|
+
if (p.owner === owner && p.status === COBSGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
249
|
+
c++;
|
|
250
|
+
return c;
|
|
251
|
+
}
|
|
252
|
+
function _cobsgovCountPending(profileId) {
|
|
253
|
+
let c = 0;
|
|
254
|
+
for (const j of _cobsgovJsV2.values())
|
|
255
|
+
if (
|
|
256
|
+
j.profileId === profileId &&
|
|
257
|
+
(j.status === COBSGOV_EVENT_LIFECYCLE_V2.QUEUED ||
|
|
258
|
+
j.status === COBSGOV_EVENT_LIFECYCLE_V2.RECORDING)
|
|
259
|
+
)
|
|
260
|
+
c++;
|
|
261
|
+
return c;
|
|
262
|
+
}
|
|
263
|
+
export function setMaxActiveCobsgovProfilesPerOwnerV2(n) {
|
|
264
|
+
_cobsgovMaxActive = _cobsgovPos(n, "maxActiveCobsgovProfilesPerOwner");
|
|
265
|
+
}
|
|
266
|
+
export function getMaxActiveCobsgovProfilesPerOwnerV2() {
|
|
267
|
+
return _cobsgovMaxActive;
|
|
268
|
+
}
|
|
269
|
+
export function setMaxPendingCobsgovEventsPerProfileV2(n) {
|
|
270
|
+
_cobsgovMaxPending = _cobsgovPos(n, "maxPendingCobsgovEventsPerProfile");
|
|
271
|
+
}
|
|
272
|
+
export function getMaxPendingCobsgovEventsPerProfileV2() {
|
|
273
|
+
return _cobsgovMaxPending;
|
|
274
|
+
}
|
|
275
|
+
export function setCobsgovProfileIdleMsV2(n) {
|
|
276
|
+
_cobsgovIdleMs = _cobsgovPos(n, "cobsgovProfileIdleMs");
|
|
277
|
+
}
|
|
278
|
+
export function getCobsgovProfileIdleMsV2() {
|
|
279
|
+
return _cobsgovIdleMs;
|
|
280
|
+
}
|
|
281
|
+
export function setCobsgovEventStuckMsV2(n) {
|
|
282
|
+
_cobsgovStuckMs = _cobsgovPos(n, "cobsgovEventStuckMs");
|
|
283
|
+
}
|
|
284
|
+
export function getCobsgovEventStuckMsV2() {
|
|
285
|
+
return _cobsgovStuckMs;
|
|
286
|
+
}
|
|
287
|
+
export function _resetStateCoworkObserveGovV2() {
|
|
288
|
+
_cobsgovPsV2.clear();
|
|
289
|
+
_cobsgovJsV2.clear();
|
|
290
|
+
_cobsgovMaxActive = 10;
|
|
291
|
+
_cobsgovMaxPending = 25;
|
|
292
|
+
_cobsgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
293
|
+
_cobsgovStuckMs = 60 * 1000;
|
|
294
|
+
}
|
|
295
|
+
export function registerCobsgovProfileV2({
|
|
296
|
+
id,
|
|
297
|
+
owner,
|
|
298
|
+
channel,
|
|
299
|
+
metadata,
|
|
300
|
+
} = {}) {
|
|
301
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
302
|
+
if (_cobsgovPsV2.has(id))
|
|
303
|
+
throw new Error(`cobsgov profile ${id} already exists`);
|
|
304
|
+
const now = Date.now();
|
|
305
|
+
const p = {
|
|
306
|
+
id,
|
|
307
|
+
owner,
|
|
308
|
+
channel: channel || "default",
|
|
309
|
+
status: COBSGOV_PROFILE_MATURITY_V2.PENDING,
|
|
310
|
+
createdAt: now,
|
|
311
|
+
updatedAt: now,
|
|
312
|
+
lastTouchedAt: now,
|
|
313
|
+
activatedAt: null,
|
|
314
|
+
archivedAt: null,
|
|
315
|
+
metadata: { ...(metadata || {}) },
|
|
316
|
+
};
|
|
317
|
+
_cobsgovPsV2.set(id, p);
|
|
318
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
319
|
+
}
|
|
320
|
+
export function activateCobsgovProfileV2(id) {
|
|
321
|
+
const p = _cobsgovPsV2.get(id);
|
|
322
|
+
if (!p) throw new Error(`cobsgov profile ${id} not found`);
|
|
323
|
+
const isInitial = p.status === COBSGOV_PROFILE_MATURITY_V2.PENDING;
|
|
324
|
+
_cobsgovCheckP(p.status, COBSGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
325
|
+
if (isInitial && _cobsgovCountActive(p.owner) >= _cobsgovMaxActive)
|
|
326
|
+
throw new Error(`max active cobsgov profiles for owner ${p.owner} reached`);
|
|
327
|
+
const now = Date.now();
|
|
328
|
+
p.status = COBSGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
329
|
+
p.updatedAt = now;
|
|
330
|
+
p.lastTouchedAt = now;
|
|
331
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
332
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
333
|
+
}
|
|
334
|
+
export function muteCobsgovProfileV2(id) {
|
|
335
|
+
const p = _cobsgovPsV2.get(id);
|
|
336
|
+
if (!p) throw new Error(`cobsgov profile ${id} not found`);
|
|
337
|
+
_cobsgovCheckP(p.status, COBSGOV_PROFILE_MATURITY_V2.MUTED);
|
|
338
|
+
p.status = COBSGOV_PROFILE_MATURITY_V2.MUTED;
|
|
339
|
+
p.updatedAt = Date.now();
|
|
340
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
341
|
+
}
|
|
342
|
+
export function archiveCobsgovProfileV2(id) {
|
|
343
|
+
const p = _cobsgovPsV2.get(id);
|
|
344
|
+
if (!p) throw new Error(`cobsgov profile ${id} not found`);
|
|
345
|
+
_cobsgovCheckP(p.status, COBSGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
346
|
+
const now = Date.now();
|
|
347
|
+
p.status = COBSGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
348
|
+
p.updatedAt = now;
|
|
349
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
350
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
351
|
+
}
|
|
352
|
+
export function touchCobsgovProfileV2(id) {
|
|
353
|
+
const p = _cobsgovPsV2.get(id);
|
|
354
|
+
if (!p) throw new Error(`cobsgov profile ${id} not found`);
|
|
355
|
+
if (_cobsgovPTerminal.has(p.status))
|
|
356
|
+
throw new Error(`cannot touch terminal cobsgov profile ${id}`);
|
|
357
|
+
const now = Date.now();
|
|
358
|
+
p.lastTouchedAt = now;
|
|
359
|
+
p.updatedAt = now;
|
|
360
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
361
|
+
}
|
|
362
|
+
export function getCobsgovProfileV2(id) {
|
|
363
|
+
const p = _cobsgovPsV2.get(id);
|
|
364
|
+
if (!p) return null;
|
|
365
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
366
|
+
}
|
|
367
|
+
export function listCobsgovProfilesV2() {
|
|
368
|
+
return [..._cobsgovPsV2.values()].map((p) => ({
|
|
369
|
+
...p,
|
|
370
|
+
metadata: { ...p.metadata },
|
|
371
|
+
}));
|
|
372
|
+
}
|
|
373
|
+
export function createCobsgovEventV2({ id, profileId, kind, metadata } = {}) {
|
|
374
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
375
|
+
if (_cobsgovJsV2.has(id))
|
|
376
|
+
throw new Error(`cobsgov event ${id} already exists`);
|
|
377
|
+
if (!_cobsgovPsV2.has(profileId))
|
|
378
|
+
throw new Error(`cobsgov profile ${profileId} not found`);
|
|
379
|
+
if (_cobsgovCountPending(profileId) >= _cobsgovMaxPending)
|
|
380
|
+
throw new Error(
|
|
381
|
+
`max pending cobsgov events for profile ${profileId} reached`,
|
|
382
|
+
);
|
|
383
|
+
const now = Date.now();
|
|
384
|
+
const j = {
|
|
385
|
+
id,
|
|
386
|
+
profileId,
|
|
387
|
+
kind: kind || "",
|
|
388
|
+
status: COBSGOV_EVENT_LIFECYCLE_V2.QUEUED,
|
|
389
|
+
createdAt: now,
|
|
390
|
+
updatedAt: now,
|
|
391
|
+
startedAt: null,
|
|
392
|
+
settledAt: null,
|
|
393
|
+
metadata: { ...(metadata || {}) },
|
|
394
|
+
};
|
|
395
|
+
_cobsgovJsV2.set(id, j);
|
|
396
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
397
|
+
}
|
|
398
|
+
export function recordingCobsgovEventV2(id) {
|
|
399
|
+
const j = _cobsgovJsV2.get(id);
|
|
400
|
+
if (!j) throw new Error(`cobsgov event ${id} not found`);
|
|
401
|
+
_cobsgovCheckJ(j.status, COBSGOV_EVENT_LIFECYCLE_V2.RECORDING);
|
|
402
|
+
const now = Date.now();
|
|
403
|
+
j.status = COBSGOV_EVENT_LIFECYCLE_V2.RECORDING;
|
|
404
|
+
j.updatedAt = now;
|
|
405
|
+
if (!j.startedAt) j.startedAt = now;
|
|
406
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
407
|
+
}
|
|
408
|
+
export function completeEventCobsgovV2(id) {
|
|
409
|
+
const j = _cobsgovJsV2.get(id);
|
|
410
|
+
if (!j) throw new Error(`cobsgov event ${id} not found`);
|
|
411
|
+
_cobsgovCheckJ(j.status, COBSGOV_EVENT_LIFECYCLE_V2.RECORDED);
|
|
412
|
+
const now = Date.now();
|
|
413
|
+
j.status = COBSGOV_EVENT_LIFECYCLE_V2.RECORDED;
|
|
414
|
+
j.updatedAt = now;
|
|
415
|
+
if (!j.settledAt) j.settledAt = now;
|
|
416
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
417
|
+
}
|
|
418
|
+
export function failCobsgovEventV2(id, reason) {
|
|
419
|
+
const j = _cobsgovJsV2.get(id);
|
|
420
|
+
if (!j) throw new Error(`cobsgov event ${id} not found`);
|
|
421
|
+
_cobsgovCheckJ(j.status, COBSGOV_EVENT_LIFECYCLE_V2.FAILED);
|
|
422
|
+
const now = Date.now();
|
|
423
|
+
j.status = COBSGOV_EVENT_LIFECYCLE_V2.FAILED;
|
|
424
|
+
j.updatedAt = now;
|
|
425
|
+
if (!j.settledAt) j.settledAt = now;
|
|
426
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
427
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
428
|
+
}
|
|
429
|
+
export function cancelCobsgovEventV2(id, reason) {
|
|
430
|
+
const j = _cobsgovJsV2.get(id);
|
|
431
|
+
if (!j) throw new Error(`cobsgov event ${id} not found`);
|
|
432
|
+
_cobsgovCheckJ(j.status, COBSGOV_EVENT_LIFECYCLE_V2.CANCELLED);
|
|
433
|
+
const now = Date.now();
|
|
434
|
+
j.status = COBSGOV_EVENT_LIFECYCLE_V2.CANCELLED;
|
|
435
|
+
j.updatedAt = now;
|
|
436
|
+
if (!j.settledAt) j.settledAt = now;
|
|
437
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
438
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
439
|
+
}
|
|
440
|
+
export function getCobsgovEventV2(id) {
|
|
441
|
+
const j = _cobsgovJsV2.get(id);
|
|
442
|
+
if (!j) return null;
|
|
443
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
444
|
+
}
|
|
445
|
+
export function listCobsgovEventsV2() {
|
|
446
|
+
return [..._cobsgovJsV2.values()].map((j) => ({
|
|
447
|
+
...j,
|
|
448
|
+
metadata: { ...j.metadata },
|
|
449
|
+
}));
|
|
450
|
+
}
|
|
451
|
+
export function autoMuteIdleCobsgovProfilesV2({ now } = {}) {
|
|
452
|
+
const t = now ?? Date.now();
|
|
453
|
+
const flipped = [];
|
|
454
|
+
for (const p of _cobsgovPsV2.values())
|
|
455
|
+
if (
|
|
456
|
+
p.status === COBSGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
457
|
+
t - p.lastTouchedAt >= _cobsgovIdleMs
|
|
458
|
+
) {
|
|
459
|
+
p.status = COBSGOV_PROFILE_MATURITY_V2.MUTED;
|
|
460
|
+
p.updatedAt = t;
|
|
461
|
+
flipped.push(p.id);
|
|
462
|
+
}
|
|
463
|
+
return { flipped, count: flipped.length };
|
|
464
|
+
}
|
|
465
|
+
export function autoFailStuckCobsgovEventsV2({ now } = {}) {
|
|
466
|
+
const t = now ?? Date.now();
|
|
467
|
+
const flipped = [];
|
|
468
|
+
for (const j of _cobsgovJsV2.values())
|
|
469
|
+
if (
|
|
470
|
+
j.status === COBSGOV_EVENT_LIFECYCLE_V2.RECORDING &&
|
|
471
|
+
j.startedAt != null &&
|
|
472
|
+
t - j.startedAt >= _cobsgovStuckMs
|
|
473
|
+
) {
|
|
474
|
+
j.status = COBSGOV_EVENT_LIFECYCLE_V2.FAILED;
|
|
475
|
+
j.updatedAt = t;
|
|
476
|
+
if (!j.settledAt) j.settledAt = t;
|
|
477
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
478
|
+
flipped.push(j.id);
|
|
479
|
+
}
|
|
480
|
+
return { flipped, count: flipped.length };
|
|
481
|
+
}
|
|
482
|
+
export function getCoworkObserveGovStatsV2() {
|
|
483
|
+
const profilesByStatus = {};
|
|
484
|
+
for (const v of Object.values(COBSGOV_PROFILE_MATURITY_V2))
|
|
485
|
+
profilesByStatus[v] = 0;
|
|
486
|
+
for (const p of _cobsgovPsV2.values()) profilesByStatus[p.status]++;
|
|
487
|
+
const eventsByStatus = {};
|
|
488
|
+
for (const v of Object.values(COBSGOV_EVENT_LIFECYCLE_V2))
|
|
489
|
+
eventsByStatus[v] = 0;
|
|
490
|
+
for (const j of _cobsgovJsV2.values()) eventsByStatus[j.status]++;
|
|
491
|
+
return {
|
|
492
|
+
totalCobsgovProfilesV2: _cobsgovPsV2.size,
|
|
493
|
+
totalCobsgovEventsV2: _cobsgovJsV2.size,
|
|
494
|
+
maxActiveCobsgovProfilesPerOwner: _cobsgovMaxActive,
|
|
495
|
+
maxPendingCobsgovEventsPerProfile: _cobsgovMaxPending,
|
|
496
|
+
cobsgovProfileIdleMs: _cobsgovIdleMs,
|
|
497
|
+
cobsgovEventStuckMs: _cobsgovStuckMs,
|
|
498
|
+
profilesByStatus,
|
|
499
|
+
eventsByStatus,
|
|
500
|
+
};
|
|
501
|
+
}
|