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
package/src/lib/session-tail.js
CHANGED
|
@@ -129,81 +129,320 @@ export async function* followSession(sessionId, options = {}) {
|
|
|
129
129
|
|
|
130
130
|
// ===== V2 Surface: Session Tail governance overlay (CLI v0.142.0) =====
|
|
131
131
|
export const STAIL_SUB_MATURITY_V2 = Object.freeze({
|
|
132
|
-
PENDING: "pending",
|
|
132
|
+
PENDING: "pending",
|
|
133
|
+
ACTIVE: "active",
|
|
134
|
+
PAUSED: "paused",
|
|
135
|
+
CLOSED: "closed",
|
|
133
136
|
});
|
|
134
137
|
export const STAIL_EVENT_LIFECYCLE_V2 = Object.freeze({
|
|
135
|
-
QUEUED: "queued",
|
|
138
|
+
QUEUED: "queued",
|
|
139
|
+
TAILING: "tailing",
|
|
140
|
+
COMPLETED: "completed",
|
|
141
|
+
FAILED: "failed",
|
|
142
|
+
CANCELLED: "cancelled",
|
|
136
143
|
});
|
|
137
144
|
const _stailSTrans = new Map([
|
|
138
|
-
[
|
|
139
|
-
|
|
140
|
-
|
|
145
|
+
[
|
|
146
|
+
STAIL_SUB_MATURITY_V2.PENDING,
|
|
147
|
+
new Set([STAIL_SUB_MATURITY_V2.ACTIVE, STAIL_SUB_MATURITY_V2.CLOSED]),
|
|
148
|
+
],
|
|
149
|
+
[
|
|
150
|
+
STAIL_SUB_MATURITY_V2.ACTIVE,
|
|
151
|
+
new Set([STAIL_SUB_MATURITY_V2.PAUSED, STAIL_SUB_MATURITY_V2.CLOSED]),
|
|
152
|
+
],
|
|
153
|
+
[
|
|
154
|
+
STAIL_SUB_MATURITY_V2.PAUSED,
|
|
155
|
+
new Set([STAIL_SUB_MATURITY_V2.ACTIVE, STAIL_SUB_MATURITY_V2.CLOSED]),
|
|
156
|
+
],
|
|
141
157
|
[STAIL_SUB_MATURITY_V2.CLOSED, new Set()],
|
|
142
158
|
]);
|
|
143
159
|
const _stailSTerminal = new Set([STAIL_SUB_MATURITY_V2.CLOSED]);
|
|
144
160
|
const _stailETrans = new Map([
|
|
145
|
-
[
|
|
146
|
-
|
|
161
|
+
[
|
|
162
|
+
STAIL_EVENT_LIFECYCLE_V2.QUEUED,
|
|
163
|
+
new Set([
|
|
164
|
+
STAIL_EVENT_LIFECYCLE_V2.TAILING,
|
|
165
|
+
STAIL_EVENT_LIFECYCLE_V2.CANCELLED,
|
|
166
|
+
]),
|
|
167
|
+
],
|
|
168
|
+
[
|
|
169
|
+
STAIL_EVENT_LIFECYCLE_V2.TAILING,
|
|
170
|
+
new Set([
|
|
171
|
+
STAIL_EVENT_LIFECYCLE_V2.COMPLETED,
|
|
172
|
+
STAIL_EVENT_LIFECYCLE_V2.FAILED,
|
|
173
|
+
STAIL_EVENT_LIFECYCLE_V2.CANCELLED,
|
|
174
|
+
]),
|
|
175
|
+
],
|
|
147
176
|
[STAIL_EVENT_LIFECYCLE_V2.COMPLETED, new Set()],
|
|
148
177
|
[STAIL_EVENT_LIFECYCLE_V2.FAILED, new Set()],
|
|
149
178
|
[STAIL_EVENT_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
150
179
|
]);
|
|
151
180
|
const _stailSsV2 = new Map();
|
|
152
181
|
const _stailEsV2 = new Map();
|
|
153
|
-
let _stailMaxActive = 10,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
182
|
+
let _stailMaxActive = 10,
|
|
183
|
+
_stailMaxPending = 30,
|
|
184
|
+
_stailIdleMs = 24 * 60 * 60 * 1000,
|
|
185
|
+
_stailStuckMs = 60 * 1000;
|
|
186
|
+
function _stailPos(n, label) {
|
|
187
|
+
const v = Math.floor(Number(n));
|
|
188
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
189
|
+
throw new Error(`${label} must be positive integer`);
|
|
190
|
+
return v;
|
|
191
|
+
}
|
|
192
|
+
function _stailCheckS(from, to) {
|
|
193
|
+
const a = _stailSTrans.get(from);
|
|
194
|
+
if (!a || !a.has(to))
|
|
195
|
+
throw new Error(`invalid stail subscription transition ${from} → ${to}`);
|
|
196
|
+
}
|
|
197
|
+
function _stailCheckE(from, to) {
|
|
198
|
+
const a = _stailETrans.get(from);
|
|
199
|
+
if (!a || !a.has(to))
|
|
200
|
+
throw new Error(`invalid stail event transition ${from} → ${to}`);
|
|
201
|
+
}
|
|
202
|
+
export function setMaxActiveStailSubsPerOwnerV2(n) {
|
|
203
|
+
_stailMaxActive = _stailPos(n, "maxActiveStailSubsPerOwner");
|
|
204
|
+
}
|
|
205
|
+
export function getMaxActiveStailSubsPerOwnerV2() {
|
|
206
|
+
return _stailMaxActive;
|
|
207
|
+
}
|
|
208
|
+
export function setMaxPendingStailEventsPerSubV2(n) {
|
|
209
|
+
_stailMaxPending = _stailPos(n, "maxPendingStailEventsPerSub");
|
|
210
|
+
}
|
|
211
|
+
export function getMaxPendingStailEventsPerSubV2() {
|
|
212
|
+
return _stailMaxPending;
|
|
213
|
+
}
|
|
214
|
+
export function setStailSubIdleMsV2(n) {
|
|
215
|
+
_stailIdleMs = _stailPos(n, "stailSubIdleMs");
|
|
216
|
+
}
|
|
217
|
+
export function getStailSubIdleMsV2() {
|
|
218
|
+
return _stailIdleMs;
|
|
219
|
+
}
|
|
220
|
+
export function setStailEventStuckMsV2(n) {
|
|
221
|
+
_stailStuckMs = _stailPos(n, "stailEventStuckMs");
|
|
222
|
+
}
|
|
223
|
+
export function getStailEventStuckMsV2() {
|
|
224
|
+
return _stailStuckMs;
|
|
225
|
+
}
|
|
226
|
+
export function _resetStateSessionTailV2() {
|
|
227
|
+
_stailSsV2.clear();
|
|
228
|
+
_stailEsV2.clear();
|
|
229
|
+
_stailMaxActive = 10;
|
|
230
|
+
_stailMaxPending = 30;
|
|
231
|
+
_stailIdleMs = 24 * 60 * 60 * 1000;
|
|
232
|
+
_stailStuckMs = 60 * 1000;
|
|
233
|
+
}
|
|
166
234
|
export function registerStailSubV2({ id, owner, sessionId, metadata } = {}) {
|
|
167
|
-
if (!id) throw new Error("stail sub id required");
|
|
235
|
+
if (!id) throw new Error("stail sub id required");
|
|
236
|
+
if (!owner) throw new Error("stail sub owner required");
|
|
168
237
|
if (_stailSsV2.has(id)) throw new Error(`stail sub ${id} already registered`);
|
|
169
238
|
const now = Date.now();
|
|
170
|
-
const s = {
|
|
171
|
-
|
|
239
|
+
const s = {
|
|
240
|
+
id,
|
|
241
|
+
owner,
|
|
242
|
+
sessionId: sessionId || "*",
|
|
243
|
+
status: STAIL_SUB_MATURITY_V2.PENDING,
|
|
244
|
+
createdAt: now,
|
|
245
|
+
updatedAt: now,
|
|
246
|
+
activatedAt: null,
|
|
247
|
+
closedAt: null,
|
|
248
|
+
lastTouchedAt: now,
|
|
249
|
+
metadata: { ...(metadata || {}) },
|
|
250
|
+
};
|
|
251
|
+
_stailSsV2.set(id, s);
|
|
252
|
+
return { ...s, metadata: { ...s.metadata } };
|
|
253
|
+
}
|
|
254
|
+
function _stailCountActive(owner) {
|
|
255
|
+
let n = 0;
|
|
256
|
+
for (const s of _stailSsV2.values())
|
|
257
|
+
if (s.owner === owner && s.status === STAIL_SUB_MATURITY_V2.ACTIVE) n++;
|
|
258
|
+
return n;
|
|
172
259
|
}
|
|
173
|
-
function _stailCountActive(owner) { let n = 0; for (const s of _stailSsV2.values()) if (s.owner === owner && s.status === STAIL_SUB_MATURITY_V2.ACTIVE) n++; return n; }
|
|
174
260
|
export function activateStailSubV2(id) {
|
|
175
|
-
const s = _stailSsV2.get(id);
|
|
261
|
+
const s = _stailSsV2.get(id);
|
|
262
|
+
if (!s) throw new Error(`stail sub ${id} not found`);
|
|
176
263
|
_stailCheckS(s.status, STAIL_SUB_MATURITY_V2.ACTIVE);
|
|
177
264
|
const recovery = s.status === STAIL_SUB_MATURITY_V2.PAUSED;
|
|
178
|
-
if (!recovery && _stailCountActive(s.owner) >= _stailMaxActive)
|
|
179
|
-
|
|
265
|
+
if (!recovery && _stailCountActive(s.owner) >= _stailMaxActive)
|
|
266
|
+
throw new Error(`max active stail subs for owner ${s.owner} reached`);
|
|
267
|
+
const now = Date.now();
|
|
268
|
+
s.status = STAIL_SUB_MATURITY_V2.ACTIVE;
|
|
269
|
+
s.updatedAt = now;
|
|
270
|
+
s.lastTouchedAt = now;
|
|
271
|
+
if (!s.activatedAt) s.activatedAt = now;
|
|
272
|
+
return { ...s, metadata: { ...s.metadata } };
|
|
273
|
+
}
|
|
274
|
+
export function pauseStailSubV2(id) {
|
|
275
|
+
const s = _stailSsV2.get(id);
|
|
276
|
+
if (!s) throw new Error(`stail sub ${id} not found`);
|
|
277
|
+
_stailCheckS(s.status, STAIL_SUB_MATURITY_V2.PAUSED);
|
|
278
|
+
s.status = STAIL_SUB_MATURITY_V2.PAUSED;
|
|
279
|
+
s.updatedAt = Date.now();
|
|
280
|
+
return { ...s, metadata: { ...s.metadata } };
|
|
281
|
+
}
|
|
282
|
+
export function closeStailSubV2(id) {
|
|
283
|
+
const s = _stailSsV2.get(id);
|
|
284
|
+
if (!s) throw new Error(`stail sub ${id} not found`);
|
|
285
|
+
_stailCheckS(s.status, STAIL_SUB_MATURITY_V2.CLOSED);
|
|
286
|
+
const now = Date.now();
|
|
287
|
+
s.status = STAIL_SUB_MATURITY_V2.CLOSED;
|
|
288
|
+
s.updatedAt = now;
|
|
289
|
+
if (!s.closedAt) s.closedAt = now;
|
|
290
|
+
return { ...s, metadata: { ...s.metadata } };
|
|
291
|
+
}
|
|
292
|
+
export function touchStailSubV2(id) {
|
|
293
|
+
const s = _stailSsV2.get(id);
|
|
294
|
+
if (!s) throw new Error(`stail sub ${id} not found`);
|
|
295
|
+
if (_stailSTerminal.has(s.status))
|
|
296
|
+
throw new Error(`cannot touch terminal stail sub ${id}`);
|
|
297
|
+
const now = Date.now();
|
|
298
|
+
s.lastTouchedAt = now;
|
|
299
|
+
s.updatedAt = now;
|
|
300
|
+
return { ...s, metadata: { ...s.metadata } };
|
|
301
|
+
}
|
|
302
|
+
export function getStailSubV2(id) {
|
|
303
|
+
const s = _stailSsV2.get(id);
|
|
304
|
+
if (!s) return null;
|
|
180
305
|
return { ...s, metadata: { ...s.metadata } };
|
|
181
306
|
}
|
|
182
|
-
export function
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
307
|
+
export function listStailSubsV2() {
|
|
308
|
+
return [..._stailSsV2.values()].map((s) => ({
|
|
309
|
+
...s,
|
|
310
|
+
metadata: { ...s.metadata },
|
|
311
|
+
}));
|
|
312
|
+
}
|
|
313
|
+
function _stailCountPending(subId) {
|
|
314
|
+
let n = 0;
|
|
315
|
+
for (const e of _stailEsV2.values())
|
|
316
|
+
if (
|
|
317
|
+
e.subId === subId &&
|
|
318
|
+
(e.status === STAIL_EVENT_LIFECYCLE_V2.QUEUED ||
|
|
319
|
+
e.status === STAIL_EVENT_LIFECYCLE_V2.TAILING)
|
|
320
|
+
)
|
|
321
|
+
n++;
|
|
322
|
+
return n;
|
|
323
|
+
}
|
|
188
324
|
export function createStailEventV2({ id, subId, cursor, metadata } = {}) {
|
|
189
|
-
if (!id) throw new Error("stail event id required");
|
|
325
|
+
if (!id) throw new Error("stail event id required");
|
|
326
|
+
if (!subId) throw new Error("stail event subId required");
|
|
190
327
|
if (_stailEsV2.has(id)) throw new Error(`stail event ${id} already exists`);
|
|
191
328
|
if (!_stailSsV2.has(subId)) throw new Error(`stail sub ${subId} not found`);
|
|
192
|
-
if (_stailCountPending(subId) >= _stailMaxPending)
|
|
329
|
+
if (_stailCountPending(subId) >= _stailMaxPending)
|
|
330
|
+
throw new Error(`max pending stail events for sub ${subId} reached`);
|
|
193
331
|
const now = Date.now();
|
|
194
|
-
const e = {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
332
|
+
const e = {
|
|
333
|
+
id,
|
|
334
|
+
subId,
|
|
335
|
+
cursor: cursor || "0",
|
|
336
|
+
status: STAIL_EVENT_LIFECYCLE_V2.QUEUED,
|
|
337
|
+
createdAt: now,
|
|
338
|
+
updatedAt: now,
|
|
339
|
+
startedAt: null,
|
|
340
|
+
settledAt: null,
|
|
341
|
+
metadata: { ...(metadata || {}) },
|
|
342
|
+
};
|
|
343
|
+
_stailEsV2.set(id, e);
|
|
344
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
345
|
+
}
|
|
346
|
+
export function tailingStailEventV2(id) {
|
|
347
|
+
const e = _stailEsV2.get(id);
|
|
348
|
+
if (!e) throw new Error(`stail event ${id} not found`);
|
|
349
|
+
_stailCheckE(e.status, STAIL_EVENT_LIFECYCLE_V2.TAILING);
|
|
350
|
+
const now = Date.now();
|
|
351
|
+
e.status = STAIL_EVENT_LIFECYCLE_V2.TAILING;
|
|
352
|
+
e.updatedAt = now;
|
|
353
|
+
if (!e.startedAt) e.startedAt = now;
|
|
354
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
355
|
+
}
|
|
356
|
+
export function completeStailEventV2(id) {
|
|
357
|
+
const e = _stailEsV2.get(id);
|
|
358
|
+
if (!e) throw new Error(`stail event ${id} not found`);
|
|
359
|
+
_stailCheckE(e.status, STAIL_EVENT_LIFECYCLE_V2.COMPLETED);
|
|
360
|
+
const now = Date.now();
|
|
361
|
+
e.status = STAIL_EVENT_LIFECYCLE_V2.COMPLETED;
|
|
362
|
+
e.updatedAt = now;
|
|
363
|
+
if (!e.settledAt) e.settledAt = now;
|
|
364
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
365
|
+
}
|
|
366
|
+
export function failStailEventV2(id, reason) {
|
|
367
|
+
const e = _stailEsV2.get(id);
|
|
368
|
+
if (!e) throw new Error(`stail event ${id} not found`);
|
|
369
|
+
_stailCheckE(e.status, STAIL_EVENT_LIFECYCLE_V2.FAILED);
|
|
370
|
+
const now = Date.now();
|
|
371
|
+
e.status = STAIL_EVENT_LIFECYCLE_V2.FAILED;
|
|
372
|
+
e.updatedAt = now;
|
|
373
|
+
if (!e.settledAt) e.settledAt = now;
|
|
374
|
+
if (reason) e.metadata.failReason = String(reason);
|
|
375
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
376
|
+
}
|
|
377
|
+
export function cancelStailEventV2(id, reason) {
|
|
378
|
+
const e = _stailEsV2.get(id);
|
|
379
|
+
if (!e) throw new Error(`stail event ${id} not found`);
|
|
380
|
+
_stailCheckE(e.status, STAIL_EVENT_LIFECYCLE_V2.CANCELLED);
|
|
381
|
+
const now = Date.now();
|
|
382
|
+
e.status = STAIL_EVENT_LIFECYCLE_V2.CANCELLED;
|
|
383
|
+
e.updatedAt = now;
|
|
384
|
+
if (!e.settledAt) e.settledAt = now;
|
|
385
|
+
if (reason) e.metadata.cancelReason = String(reason);
|
|
386
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
387
|
+
}
|
|
388
|
+
export function getStailEventV2(id) {
|
|
389
|
+
const e = _stailEsV2.get(id);
|
|
390
|
+
if (!e) return null;
|
|
391
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
392
|
+
}
|
|
393
|
+
export function listStailEventsV2() {
|
|
394
|
+
return [..._stailEsV2.values()].map((e) => ({
|
|
395
|
+
...e,
|
|
396
|
+
metadata: { ...e.metadata },
|
|
397
|
+
}));
|
|
398
|
+
}
|
|
399
|
+
export function autoPauseIdleStailSubsV2({ now } = {}) {
|
|
400
|
+
const t = now ?? Date.now();
|
|
401
|
+
const flipped = [];
|
|
402
|
+
for (const s of _stailSsV2.values())
|
|
403
|
+
if (
|
|
404
|
+
s.status === STAIL_SUB_MATURITY_V2.ACTIVE &&
|
|
405
|
+
t - s.lastTouchedAt >= _stailIdleMs
|
|
406
|
+
) {
|
|
407
|
+
s.status = STAIL_SUB_MATURITY_V2.PAUSED;
|
|
408
|
+
s.updatedAt = t;
|
|
409
|
+
flipped.push(s.id);
|
|
410
|
+
}
|
|
411
|
+
return { flipped, count: flipped.length };
|
|
412
|
+
}
|
|
413
|
+
export function autoFailStuckStailEventsV2({ now } = {}) {
|
|
414
|
+
const t = now ?? Date.now();
|
|
415
|
+
const flipped = [];
|
|
416
|
+
for (const e of _stailEsV2.values())
|
|
417
|
+
if (
|
|
418
|
+
e.status === STAIL_EVENT_LIFECYCLE_V2.TAILING &&
|
|
419
|
+
e.startedAt != null &&
|
|
420
|
+
t - e.startedAt >= _stailStuckMs
|
|
421
|
+
) {
|
|
422
|
+
e.status = STAIL_EVENT_LIFECYCLE_V2.FAILED;
|
|
423
|
+
e.updatedAt = t;
|
|
424
|
+
if (!e.settledAt) e.settledAt = t;
|
|
425
|
+
e.metadata.failReason = "auto-fail-stuck";
|
|
426
|
+
flipped.push(e.id);
|
|
427
|
+
}
|
|
428
|
+
return { flipped, count: flipped.length };
|
|
429
|
+
}
|
|
205
430
|
export function getSessionTailGovStatsV2() {
|
|
206
|
-
const subsByStatus = {};
|
|
207
|
-
|
|
208
|
-
|
|
431
|
+
const subsByStatus = {};
|
|
432
|
+
for (const v of Object.values(STAIL_SUB_MATURITY_V2)) subsByStatus[v] = 0;
|
|
433
|
+
for (const s of _stailSsV2.values()) subsByStatus[s.status]++;
|
|
434
|
+
const eventsByStatus = {};
|
|
435
|
+
for (const v of Object.values(STAIL_EVENT_LIFECYCLE_V2))
|
|
436
|
+
eventsByStatus[v] = 0;
|
|
437
|
+
for (const e of _stailEsV2.values()) eventsByStatus[e.status]++;
|
|
438
|
+
return {
|
|
439
|
+
totalStailSubsV2: _stailSsV2.size,
|
|
440
|
+
totalStailEventsV2: _stailEsV2.size,
|
|
441
|
+
maxActiveStailSubsPerOwner: _stailMaxActive,
|
|
442
|
+
maxPendingStailEventsPerSub: _stailMaxPending,
|
|
443
|
+
stailSubIdleMs: _stailIdleMs,
|
|
444
|
+
stailEventStuckMs: _stailStuckMs,
|
|
445
|
+
subsByStatus,
|
|
446
|
+
eventsByStatus,
|
|
447
|
+
};
|
|
209
448
|
}
|