chainlesschain 0.143.0 → 0.145.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands/a2a.js +196 -28
- package/src/commands/activitypub.js +157 -27
- package/src/commands/agent.js +587 -103
- package/src/commands/audit.js +206 -0
- package/src/commands/bi.js +152 -27
- package/src/commands/bm25.js +111 -27
- package/src/commands/browse.js +190 -29
- package/src/commands/ccron.js +128 -28
- package/src/commands/chat.js +207 -0
- package/src/commands/compliance.js +414 -34
- package/src/commands/compt.js +127 -29
- package/src/commands/consol.js +8 -2
- package/src/commands/cowork.js +580 -34
- package/src/commands/crosschain.js +182 -28
- package/src/commands/dao.js +182 -28
- package/src/commands/dlp.js +172 -27
- package/src/commands/economy.js +205 -50
- package/src/commands/evolution.js +203 -50
- package/src/commands/evomap.js +182 -27
- package/src/commands/fflag.js +74 -22
- package/src/commands/git.js +177 -37
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +204 -50
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +170 -34
- package/src/commands/itbudget.js +149 -33
- package/src/commands/kg.js +206 -0
- package/src/commands/lowcode.js +195 -38
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +179 -27
- package/src/commands/mcpscaf.js +145 -33
- package/src/commands/meminj.js +145 -33
- package/src/commands/nostr.js +178 -27
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +144 -33
- package/src/commands/pdfp.js +109 -27
- package/src/commands/perf.js +169 -32
- package/src/commands/perm.js +144 -33
- package/src/commands/pipeline.js +207 -52
- package/src/commands/planmode.js +141 -32
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +111 -27
- package/src/commands/recommend.js +177 -34
- package/src/commands/reputation.js +208 -0
- package/src/commands/sandbox.js +206 -0
- package/src/commands/seshhook.js +145 -33
- package/src/commands/seshsearch.js +141 -33
- package/src/commands/seshtail.js +144 -33
- package/src/commands/seshu.js +152 -33
- package/src/commands/sganal.js +123 -29
- package/src/commands/siem.js +201 -34
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +146 -33
- package/src/commands/social.js +157 -32
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +145 -33
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +171 -33
- package/src/commands/topiccls.js +146 -33
- package/src/commands/uprof.js +141 -32
- package/src/commands/vcheck.js +122 -28
- package/src/commands/webfetch.js +141 -32
- package/src/commands/zkp.js +184 -28
- package/src/index.js +40 -0
- package/src/lib/a2a-protocol.js +319 -51
- package/src/lib/activitypub-bridge.js +288 -50
- package/src/lib/agent-economy.js +304 -51
- package/src/lib/app-builder.js +279 -46
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/autonomous-agent.js +284 -48
- package/src/lib/bi-engine.js +283 -49
- package/src/lib/bm25-search.js +301 -49
- package/src/lib/browser-automation.js +296 -49
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -0
- package/src/lib/compliance-framework-reporter.js +305 -51
- package/src/lib/compliance-manager.js +330 -0
- package/src/lib/compression-telemetry.js +301 -49
- package/src/lib/content-recommender.js +317 -52
- package/src/lib/cowork-cron.js +298 -49
- package/src/lib/cowork-learning.js +333 -0
- package/src/lib/cowork-task-runner.js +308 -51
- package/src/lib/cowork-workflow.js +327 -0
- package/src/lib/cross-chain.js +311 -51
- package/src/lib/dao-governance.js +280 -46
- package/src/lib/dlp-engine.js +287 -49
- package/src/lib/evolution-system.js +278 -47
- package/src/lib/evomap-manager.js +280 -46
- package/src/lib/execution-backend.js +294 -48
- package/src/lib/feature-flags.js +294 -49
- package/src/lib/git-integration.js +285 -47
- package/src/lib/hardening-manager.js +341 -0
- package/src/lib/hierarchical-memory.js +284 -48
- package/src/lib/inference-network.js +308 -51
- package/src/lib/iteration-budget.js +302 -50
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/matrix-bridge.js +281 -47
- package/src/lib/mcp-scaffold.js +318 -54
- package/src/lib/memory-injection.js +288 -49
- package/src/lib/nostr-bridge.js +286 -49
- package/src/lib/orchestrator.js +293 -48
- package/src/lib/pdf-parser.js +298 -49
- package/src/lib/perf-tuning.js +309 -50
- package/src/lib/permission-engine.js +287 -49
- package/src/lib/pipeline-orchestrator.js +289 -49
- package/src/lib/plan-mode.js +298 -51
- package/src/lib/privacy-computing.js +335 -0
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/sandbox-v2.js +327 -0
- package/src/lib/service-container.js +313 -52
- package/src/lib/session-consolidator.js +296 -49
- package/src/lib/session-hooks.js +312 -53
- package/src/lib/session-search.js +304 -51
- package/src/lib/session-tail.js +288 -49
- package/src/lib/session-usage.js +298 -52
- package/src/lib/siem-exporter.js +298 -51
- package/src/lib/skill-marketplace.js +345 -0
- package/src/lib/sla-manager.js +341 -0
- package/src/lib/slot-filler.js +303 -51
- package/src/lib/social-graph-analytics.js +295 -49
- package/src/lib/social-graph.js +272 -49
- package/src/lib/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +302 -53
- package/src/lib/task-model-selector.js +302 -50
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/todo-manager.js +281 -47
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/topic-classifier.js +297 -49
- package/src/lib/user-profile.js +294 -50
- package/src/lib/version-checker.js +304 -50
- package/src/lib/web-fetch.js +292 -51
- package/src/lib/zkp-engine.js +286 -49
|
@@ -124,25 +124,62 @@ export async function consolidateJsonlSession(sessionId, options = {}) {
|
|
|
124
124
|
);
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
|
|
128
127
|
// ===== V2 Surface: Session Consolidator governance overlay (CLI v0.134.0) =====
|
|
129
128
|
export const CONSOL_PROFILE_MATURITY_V2 = Object.freeze({
|
|
130
|
-
PENDING: "pending",
|
|
129
|
+
PENDING: "pending",
|
|
130
|
+
ACTIVE: "active",
|
|
131
|
+
PAUSED: "paused",
|
|
132
|
+
ARCHIVED: "archived",
|
|
131
133
|
});
|
|
132
134
|
export const CONSOL_JOB_LIFECYCLE_V2 = Object.freeze({
|
|
133
|
-
QUEUED: "queued",
|
|
135
|
+
QUEUED: "queued",
|
|
136
|
+
RUNNING: "running",
|
|
137
|
+
COMPLETED: "completed",
|
|
138
|
+
FAILED: "failed",
|
|
139
|
+
CANCELLED: "cancelled",
|
|
134
140
|
});
|
|
135
141
|
|
|
136
142
|
const _scProfTrans = new Map([
|
|
137
|
-
[
|
|
138
|
-
|
|
139
|
-
|
|
143
|
+
[
|
|
144
|
+
CONSOL_PROFILE_MATURITY_V2.PENDING,
|
|
145
|
+
new Set([
|
|
146
|
+
CONSOL_PROFILE_MATURITY_V2.ACTIVE,
|
|
147
|
+
CONSOL_PROFILE_MATURITY_V2.ARCHIVED,
|
|
148
|
+
]),
|
|
149
|
+
],
|
|
150
|
+
[
|
|
151
|
+
CONSOL_PROFILE_MATURITY_V2.ACTIVE,
|
|
152
|
+
new Set([
|
|
153
|
+
CONSOL_PROFILE_MATURITY_V2.PAUSED,
|
|
154
|
+
CONSOL_PROFILE_MATURITY_V2.ARCHIVED,
|
|
155
|
+
]),
|
|
156
|
+
],
|
|
157
|
+
[
|
|
158
|
+
CONSOL_PROFILE_MATURITY_V2.PAUSED,
|
|
159
|
+
new Set([
|
|
160
|
+
CONSOL_PROFILE_MATURITY_V2.ACTIVE,
|
|
161
|
+
CONSOL_PROFILE_MATURITY_V2.ARCHIVED,
|
|
162
|
+
]),
|
|
163
|
+
],
|
|
140
164
|
[CONSOL_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
141
165
|
]);
|
|
142
166
|
const _scProfTerminal = new Set([CONSOL_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
143
167
|
const _scJobTrans = new Map([
|
|
144
|
-
[
|
|
145
|
-
|
|
168
|
+
[
|
|
169
|
+
CONSOL_JOB_LIFECYCLE_V2.QUEUED,
|
|
170
|
+
new Set([
|
|
171
|
+
CONSOL_JOB_LIFECYCLE_V2.RUNNING,
|
|
172
|
+
CONSOL_JOB_LIFECYCLE_V2.CANCELLED,
|
|
173
|
+
]),
|
|
174
|
+
],
|
|
175
|
+
[
|
|
176
|
+
CONSOL_JOB_LIFECYCLE_V2.RUNNING,
|
|
177
|
+
new Set([
|
|
178
|
+
CONSOL_JOB_LIFECYCLE_V2.COMPLETED,
|
|
179
|
+
CONSOL_JOB_LIFECYCLE_V2.FAILED,
|
|
180
|
+
CONSOL_JOB_LIFECYCLE_V2.CANCELLED,
|
|
181
|
+
]),
|
|
182
|
+
],
|
|
146
183
|
[CONSOL_JOB_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
147
184
|
[CONSOL_JOB_LIFECYCLE_V2.FAILED, new Set()],
|
|
148
185
|
[CONSOL_JOB_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
@@ -155,76 +192,286 @@ let _scMaxPendingPerProfile = 12;
|
|
|
155
192
|
let _scProfileIdleMs = 7 * 24 * 60 * 60 * 1000;
|
|
156
193
|
let _scJobStuckMs = 10 * 60 * 1000;
|
|
157
194
|
|
|
158
|
-
function _scPos(n, lbl) {
|
|
195
|
+
function _scPos(n, lbl) {
|
|
196
|
+
const v = Math.floor(Number(n));
|
|
197
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
198
|
+
throw new Error(`${lbl} must be positive integer`);
|
|
199
|
+
return v;
|
|
200
|
+
}
|
|
159
201
|
|
|
160
|
-
export function setMaxActiveConsolProfilesPerOwnerV2(n) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
export function
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
export function
|
|
167
|
-
|
|
202
|
+
export function setMaxActiveConsolProfilesPerOwnerV2(n) {
|
|
203
|
+
_scMaxActivePerOwner = _scPos(n, "maxActiveConsolProfilesPerOwner");
|
|
204
|
+
}
|
|
205
|
+
export function getMaxActiveConsolProfilesPerOwnerV2() {
|
|
206
|
+
return _scMaxActivePerOwner;
|
|
207
|
+
}
|
|
208
|
+
export function setMaxPendingConsolJobsPerProfileV2(n) {
|
|
209
|
+
_scMaxPendingPerProfile = _scPos(n, "maxPendingConsolJobsPerProfile");
|
|
210
|
+
}
|
|
211
|
+
export function getMaxPendingConsolJobsPerProfileV2() {
|
|
212
|
+
return _scMaxPendingPerProfile;
|
|
213
|
+
}
|
|
214
|
+
export function setConsolProfileIdleMsV2(n) {
|
|
215
|
+
_scProfileIdleMs = _scPos(n, "consolProfileIdleMs");
|
|
216
|
+
}
|
|
217
|
+
export function getConsolProfileIdleMsV2() {
|
|
218
|
+
return _scProfileIdleMs;
|
|
219
|
+
}
|
|
220
|
+
export function setConsolJobStuckMsV2(n) {
|
|
221
|
+
_scJobStuckMs = _scPos(n, "consolJobStuckMs");
|
|
222
|
+
}
|
|
223
|
+
export function getConsolJobStuckMsV2() {
|
|
224
|
+
return _scJobStuckMs;
|
|
225
|
+
}
|
|
168
226
|
|
|
169
227
|
export function _resetStateSessionConsolidatorV2() {
|
|
170
|
-
_scProfiles.clear();
|
|
171
|
-
|
|
172
|
-
|
|
228
|
+
_scProfiles.clear();
|
|
229
|
+
_scJobs.clear();
|
|
230
|
+
_scMaxActivePerOwner = 8;
|
|
231
|
+
_scMaxPendingPerProfile = 12;
|
|
232
|
+
_scProfileIdleMs = 7 * 24 * 60 * 60 * 1000;
|
|
233
|
+
_scJobStuckMs = 10 * 60 * 1000;
|
|
173
234
|
}
|
|
174
235
|
|
|
175
236
|
export function registerConsolProfileV2({ id, owner, scope, metadata } = {}) {
|
|
176
237
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
177
238
|
if (!owner || typeof owner !== "string") throw new Error("owner is required");
|
|
178
|
-
if (_scProfiles.has(id))
|
|
239
|
+
if (_scProfiles.has(id))
|
|
240
|
+
throw new Error(`consol profile ${id} already registered`);
|
|
179
241
|
const now = Date.now();
|
|
180
|
-
const p = {
|
|
242
|
+
const p = {
|
|
243
|
+
id,
|
|
244
|
+
owner,
|
|
245
|
+
scope: scope || "agent",
|
|
246
|
+
status: CONSOL_PROFILE_MATURITY_V2.PENDING,
|
|
247
|
+
createdAt: now,
|
|
248
|
+
updatedAt: now,
|
|
249
|
+
activatedAt: null,
|
|
250
|
+
archivedAt: null,
|
|
251
|
+
lastTouchedAt: now,
|
|
252
|
+
metadata: { ...(metadata || {}) },
|
|
253
|
+
};
|
|
181
254
|
_scProfiles.set(id, p);
|
|
182
255
|
return { ...p, metadata: { ...p.metadata } };
|
|
183
256
|
}
|
|
184
|
-
function _scCheckP(from, to) {
|
|
185
|
-
|
|
257
|
+
function _scCheckP(from, to) {
|
|
258
|
+
const a = _scProfTrans.get(from);
|
|
259
|
+
if (!a || !a.has(to))
|
|
260
|
+
throw new Error(`invalid consol profile transition ${from} → ${to}`);
|
|
261
|
+
}
|
|
262
|
+
function _scCountActive(owner) {
|
|
263
|
+
let n = 0;
|
|
264
|
+
for (const p of _scProfiles.values())
|
|
265
|
+
if (p.owner === owner && p.status === CONSOL_PROFILE_MATURITY_V2.ACTIVE)
|
|
266
|
+
n++;
|
|
267
|
+
return n;
|
|
268
|
+
}
|
|
186
269
|
|
|
187
270
|
export function activateConsolProfileV2(id) {
|
|
188
|
-
const p = _scProfiles.get(id);
|
|
271
|
+
const p = _scProfiles.get(id);
|
|
272
|
+
if (!p) throw new Error(`consol profile ${id} not found`);
|
|
189
273
|
_scCheckP(p.status, CONSOL_PROFILE_MATURITY_V2.ACTIVE);
|
|
190
274
|
const recovery = p.status === CONSOL_PROFILE_MATURITY_V2.PAUSED;
|
|
191
|
-
if (!recovery) {
|
|
192
|
-
|
|
275
|
+
if (!recovery) {
|
|
276
|
+
const a = _scCountActive(p.owner);
|
|
277
|
+
if (a >= _scMaxActivePerOwner)
|
|
278
|
+
throw new Error(
|
|
279
|
+
`max active consol profiles per owner (${_scMaxActivePerOwner}) reached for ${p.owner}`,
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
const now = Date.now();
|
|
283
|
+
p.status = CONSOL_PROFILE_MATURITY_V2.ACTIVE;
|
|
284
|
+
p.updatedAt = now;
|
|
285
|
+
p.lastTouchedAt = now;
|
|
286
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
287
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
288
|
+
}
|
|
289
|
+
export function pauseConsolProfileV2(id) {
|
|
290
|
+
const p = _scProfiles.get(id);
|
|
291
|
+
if (!p) throw new Error(`consol profile ${id} not found`);
|
|
292
|
+
_scCheckP(p.status, CONSOL_PROFILE_MATURITY_V2.PAUSED);
|
|
293
|
+
p.status = CONSOL_PROFILE_MATURITY_V2.PAUSED;
|
|
294
|
+
p.updatedAt = Date.now();
|
|
295
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
296
|
+
}
|
|
297
|
+
export function archiveConsolProfileV2(id) {
|
|
298
|
+
const p = _scProfiles.get(id);
|
|
299
|
+
if (!p) throw new Error(`consol profile ${id} not found`);
|
|
300
|
+
_scCheckP(p.status, CONSOL_PROFILE_MATURITY_V2.ARCHIVED);
|
|
301
|
+
const now = Date.now();
|
|
302
|
+
p.status = CONSOL_PROFILE_MATURITY_V2.ARCHIVED;
|
|
303
|
+
p.updatedAt = now;
|
|
304
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
305
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
306
|
+
}
|
|
307
|
+
export function touchConsolProfileV2(id) {
|
|
308
|
+
const p = _scProfiles.get(id);
|
|
309
|
+
if (!p) throw new Error(`consol profile ${id} not found`);
|
|
310
|
+
if (_scProfTerminal.has(p.status))
|
|
311
|
+
throw new Error(`cannot touch terminal consol profile ${id}`);
|
|
312
|
+
const now = Date.now();
|
|
313
|
+
p.lastTouchedAt = now;
|
|
314
|
+
p.updatedAt = now;
|
|
315
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
316
|
+
}
|
|
317
|
+
export function getConsolProfileV2(id) {
|
|
318
|
+
const p = _scProfiles.get(id);
|
|
319
|
+
if (!p) return null;
|
|
193
320
|
return { ...p, metadata: { ...p.metadata } };
|
|
194
321
|
}
|
|
195
|
-
export function
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
322
|
+
export function listConsolProfilesV2() {
|
|
323
|
+
return [..._scProfiles.values()].map((p) => ({
|
|
324
|
+
...p,
|
|
325
|
+
metadata: { ...p.metadata },
|
|
326
|
+
}));
|
|
327
|
+
}
|
|
200
328
|
|
|
201
|
-
function _scCountPending(pid) {
|
|
329
|
+
function _scCountPending(pid) {
|
|
330
|
+
let n = 0;
|
|
331
|
+
for (const j of _scJobs.values())
|
|
332
|
+
if (
|
|
333
|
+
j.profileId === pid &&
|
|
334
|
+
(j.status === CONSOL_JOB_LIFECYCLE_V2.QUEUED ||
|
|
335
|
+
j.status === CONSOL_JOB_LIFECYCLE_V2.RUNNING)
|
|
336
|
+
)
|
|
337
|
+
n++;
|
|
338
|
+
return n;
|
|
339
|
+
}
|
|
202
340
|
|
|
203
341
|
export function createConsolJobV2({ id, profileId, sessionId, metadata } = {}) {
|
|
204
342
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
205
|
-
if (!profileId || typeof profileId !== "string")
|
|
343
|
+
if (!profileId || typeof profileId !== "string")
|
|
344
|
+
throw new Error("profileId is required");
|
|
206
345
|
if (_scJobs.has(id)) throw new Error(`consol job ${id} already exists`);
|
|
207
|
-
if (!_scProfiles.has(profileId))
|
|
346
|
+
if (!_scProfiles.has(profileId))
|
|
347
|
+
throw new Error(`consol profile ${profileId} not found`);
|
|
208
348
|
const pending = _scCountPending(profileId);
|
|
209
|
-
if (pending >= _scMaxPendingPerProfile)
|
|
349
|
+
if (pending >= _scMaxPendingPerProfile)
|
|
350
|
+
throw new Error(
|
|
351
|
+
`max pending consol jobs per profile (${_scMaxPendingPerProfile}) reached for ${profileId}`,
|
|
352
|
+
);
|
|
210
353
|
const now = Date.now();
|
|
211
|
-
const j = {
|
|
354
|
+
const j = {
|
|
355
|
+
id,
|
|
356
|
+
profileId,
|
|
357
|
+
sessionId: sessionId || null,
|
|
358
|
+
status: CONSOL_JOB_LIFECYCLE_V2.QUEUED,
|
|
359
|
+
createdAt: now,
|
|
360
|
+
updatedAt: now,
|
|
361
|
+
startedAt: null,
|
|
362
|
+
settledAt: null,
|
|
363
|
+
metadata: { ...(metadata || {}) },
|
|
364
|
+
};
|
|
212
365
|
_scJobs.set(id, j);
|
|
213
366
|
return { ...j, metadata: { ...j.metadata } };
|
|
214
367
|
}
|
|
215
|
-
function _scCheckJ(from, to) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
export function
|
|
221
|
-
|
|
368
|
+
function _scCheckJ(from, to) {
|
|
369
|
+
const a = _scJobTrans.get(from);
|
|
370
|
+
if (!a || !a.has(to))
|
|
371
|
+
throw new Error(`invalid consol job transition ${from} → ${to}`);
|
|
372
|
+
}
|
|
373
|
+
export function startConsolJobV2(id) {
|
|
374
|
+
const j = _scJobs.get(id);
|
|
375
|
+
if (!j) throw new Error(`consol job ${id} not found`);
|
|
376
|
+
_scCheckJ(j.status, CONSOL_JOB_LIFECYCLE_V2.RUNNING);
|
|
377
|
+
const now = Date.now();
|
|
378
|
+
j.status = CONSOL_JOB_LIFECYCLE_V2.RUNNING;
|
|
379
|
+
j.updatedAt = now;
|
|
380
|
+
if (!j.startedAt) j.startedAt = now;
|
|
381
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
382
|
+
}
|
|
383
|
+
export function completeConsolJobV2(id) {
|
|
384
|
+
const j = _scJobs.get(id);
|
|
385
|
+
if (!j) throw new Error(`consol job ${id} not found`);
|
|
386
|
+
_scCheckJ(j.status, CONSOL_JOB_LIFECYCLE_V2.COMPLETED);
|
|
387
|
+
const now = Date.now();
|
|
388
|
+
j.status = CONSOL_JOB_LIFECYCLE_V2.COMPLETED;
|
|
389
|
+
j.updatedAt = now;
|
|
390
|
+
if (!j.settledAt) j.settledAt = now;
|
|
391
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
392
|
+
}
|
|
393
|
+
export function failConsolJobV2(id, reason) {
|
|
394
|
+
const j = _scJobs.get(id);
|
|
395
|
+
if (!j) throw new Error(`consol job ${id} not found`);
|
|
396
|
+
_scCheckJ(j.status, CONSOL_JOB_LIFECYCLE_V2.FAILED);
|
|
397
|
+
const now = Date.now();
|
|
398
|
+
j.status = CONSOL_JOB_LIFECYCLE_V2.FAILED;
|
|
399
|
+
j.updatedAt = now;
|
|
400
|
+
if (!j.settledAt) j.settledAt = now;
|
|
401
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
402
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
403
|
+
}
|
|
404
|
+
export function cancelConsolJobV2(id, reason) {
|
|
405
|
+
const j = _scJobs.get(id);
|
|
406
|
+
if (!j) throw new Error(`consol job ${id} not found`);
|
|
407
|
+
_scCheckJ(j.status, CONSOL_JOB_LIFECYCLE_V2.CANCELLED);
|
|
408
|
+
const now = Date.now();
|
|
409
|
+
j.status = CONSOL_JOB_LIFECYCLE_V2.CANCELLED;
|
|
410
|
+
j.updatedAt = now;
|
|
411
|
+
if (!j.settledAt) j.settledAt = now;
|
|
412
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
413
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
414
|
+
}
|
|
415
|
+
export function getConsolJobV2(id) {
|
|
416
|
+
const j = _scJobs.get(id);
|
|
417
|
+
if (!j) return null;
|
|
418
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
419
|
+
}
|
|
420
|
+
export function listConsolJobsV2() {
|
|
421
|
+
return [..._scJobs.values()].map((j) => ({
|
|
422
|
+
...j,
|
|
423
|
+
metadata: { ...j.metadata },
|
|
424
|
+
}));
|
|
425
|
+
}
|
|
222
426
|
|
|
223
|
-
export function autoPauseIdleConsolProfilesV2({ now } = {}) {
|
|
224
|
-
|
|
427
|
+
export function autoPauseIdleConsolProfilesV2({ now } = {}) {
|
|
428
|
+
const t = now ?? Date.now();
|
|
429
|
+
const flipped = [];
|
|
430
|
+
for (const p of _scProfiles.values())
|
|
431
|
+
if (
|
|
432
|
+
p.status === CONSOL_PROFILE_MATURITY_V2.ACTIVE &&
|
|
433
|
+
t - p.lastTouchedAt >= _scProfileIdleMs
|
|
434
|
+
) {
|
|
435
|
+
p.status = CONSOL_PROFILE_MATURITY_V2.PAUSED;
|
|
436
|
+
p.updatedAt = t;
|
|
437
|
+
flipped.push(p.id);
|
|
438
|
+
}
|
|
439
|
+
return { flipped, count: flipped.length };
|
|
440
|
+
}
|
|
441
|
+
export function autoFailStuckConsolJobsV2({ now } = {}) {
|
|
442
|
+
const t = now ?? Date.now();
|
|
443
|
+
const flipped = [];
|
|
444
|
+
for (const j of _scJobs.values())
|
|
445
|
+
if (
|
|
446
|
+
j.status === CONSOL_JOB_LIFECYCLE_V2.RUNNING &&
|
|
447
|
+
j.startedAt != null &&
|
|
448
|
+
t - j.startedAt >= _scJobStuckMs
|
|
449
|
+
) {
|
|
450
|
+
j.status = CONSOL_JOB_LIFECYCLE_V2.FAILED;
|
|
451
|
+
j.updatedAt = t;
|
|
452
|
+
if (!j.settledAt) j.settledAt = t;
|
|
453
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
454
|
+
flipped.push(j.id);
|
|
455
|
+
}
|
|
456
|
+
return { flipped, count: flipped.length };
|
|
457
|
+
}
|
|
225
458
|
|
|
226
459
|
export function getSessionConsolidatorStatsV2() {
|
|
227
|
-
const profilesByStatus = {};
|
|
228
|
-
|
|
229
|
-
|
|
460
|
+
const profilesByStatus = {};
|
|
461
|
+
for (const s of Object.values(CONSOL_PROFILE_MATURITY_V2))
|
|
462
|
+
profilesByStatus[s] = 0;
|
|
463
|
+
for (const p of _scProfiles.values()) profilesByStatus[p.status]++;
|
|
464
|
+
const jobsByStatus = {};
|
|
465
|
+
for (const s of Object.values(CONSOL_JOB_LIFECYCLE_V2)) jobsByStatus[s] = 0;
|
|
466
|
+
for (const j of _scJobs.values()) jobsByStatus[j.status]++;
|
|
467
|
+
return {
|
|
468
|
+
totalProfilesV2: _scProfiles.size,
|
|
469
|
+
totalJobsV2: _scJobs.size,
|
|
470
|
+
maxActiveConsolProfilesPerOwner: _scMaxActivePerOwner,
|
|
471
|
+
maxPendingConsolJobsPerProfile: _scMaxPendingPerProfile,
|
|
472
|
+
consolProfileIdleMs: _scProfileIdleMs,
|
|
473
|
+
consolJobStuckMs: _scJobStuckMs,
|
|
474
|
+
profilesByStatus,
|
|
475
|
+
jobsByStatus,
|
|
476
|
+
};
|
|
230
477
|
}
|