@remnic/core 9.63.3 → 9.63.4
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/dist/access-admin-ops-surface.d.ts +4 -4
- package/dist/access-admin-ops-surface.js +1 -1
- package/dist/access-authorization-probe.d.ts +4 -4
- package/dist/access-authorization-probe.js +2 -2
- package/dist/access-boundary.d.ts +4 -4
- package/dist/access-boundary.js +1 -1
- package/dist/access-cli.js +19 -18
- package/dist/access-cli.js.map +1 -1
- package/dist/access-extraction-force-flush.d.ts +4 -4
- package/dist/access-extraction-force-flush.js +1 -1
- package/dist/access-http-lcm-compaction.d.ts +4 -4
- package/dist/access-http-lifecycle-flush.d.ts +4 -4
- package/dist/access-http-offline-stream.d.ts +4 -4
- package/dist/access-http-query.d.ts +13 -1
- package/dist/access-http-query.js +5 -2
- package/dist/access-http.d.ts +5 -5
- package/dist/access-http.js +12 -11
- package/dist/access-identity-continuity-surface.d.ts +3 -3
- package/dist/access-identity-continuity-surface.js +1 -1
- package/dist/access-lcm-surface.d.ts +4 -4
- package/dist/access-lcm-surface.js +1 -1
- package/dist/access-mcp.d.ts +4 -4
- package/dist/access-mcp.js +6 -6
- package/dist/access-namespace-preflight.js +1 -1
- package/dist/access-observe-write-surface.d.ts +4 -4
- package/dist/access-observe-write-surface.js +1 -1
- package/dist/access-offline-manifest.d.ts +3 -3
- package/dist/access-operations-batch.js +2 -2
- package/dist/access-operations.d.ts +7 -7
- package/dist/access-operations.js +5 -5
- package/dist/access-recall-concurrency.d.ts +4 -4
- package/dist/access-recall-concurrency.js +1 -1
- package/dist/access-recall-response.d.ts +4 -4
- package/dist/access-recall-response.js +1 -1
- package/dist/access-recall-surface.d.ts +4 -4
- package/dist/access-recall-surface.js +1 -1
- package/dist/access-schema.d.ts +88 -88
- package/dist/{access-service-M4LgO141.d.ts → access-service-D-bi3r01.d.ts} +66 -72
- package/dist/access-service-helpers.d.ts +4 -4
- package/dist/access-service.d.ts +4 -4
- package/dist/access-service.js +1 -1
- package/dist/access-surface-catalog.d.ts +4 -4
- package/dist/access-surface-catalog.js +3 -3
- package/dist/bootstrap.d.ts +3 -3
- package/dist/buffer.js +1 -1
- package/dist/{catalog-CyYTf_ok.d.ts → catalog-BYIHQw1l.d.ts} +2 -10
- package/dist/{chunk-JJ7JW62R.js → chunk-2JL7WPXL.js} +1 -11
- package/dist/chunk-2JL7WPXL.js.map +1 -0
- package/dist/{chunk-AJSZ2EK6.js → chunk-3USQWITL.js} +2 -2
- package/dist/{chunk-RYGJGXL6.js → chunk-4EDAHS6D.js} +2 -2
- package/dist/{chunk-5W5N7XJZ.js → chunk-A4HXWNST.js} +19 -752
- package/dist/chunk-A4HXWNST.js.map +1 -0
- package/dist/{chunk-KWN6NOHQ.js → chunk-BXOZALJ6.js} +2 -2
- package/dist/{chunk-6F2UMP4H.js → chunk-CKWOMJDY.js} +2 -2
- package/dist/{chunk-MR5HWQHS.js → chunk-DFEYRCG2.js} +2 -2
- package/dist/{chunk-6UZR7KEK.js → chunk-DQV3LUQL.js} +7 -1
- package/dist/chunk-DQV3LUQL.js.map +1 -0
- package/dist/{chunk-EJQXDKYK.js → chunk-EJCN5ATI.js} +3 -3
- package/dist/{chunk-TRPX6F2G.js → chunk-GNKY5JEP.js} +10 -13
- package/dist/chunk-GNKY5JEP.js.map +1 -0
- package/dist/{chunk-XZPSBGHA.js → chunk-ISFUFLFM.js} +2 -2
- package/dist/{chunk-4NMVX5U7.js → chunk-JSH2TV34.js} +2 -2
- package/dist/{chunk-R74NCKEY.js → chunk-LNFYISZ6.js} +2 -2
- package/dist/{chunk-6ZYQ36IB.js → chunk-MRJ43KSG.js} +15 -2
- package/dist/chunk-MRJ43KSG.js.map +1 -0
- package/dist/{chunk-IM56VPKO.js → chunk-OR7KEGLR.js} +2 -2
- package/dist/{chunk-A73QHOZP.js → chunk-QOMUE4FS.js} +2 -2
- package/dist/chunk-RSLRGRBJ.js +727 -0
- package/dist/chunk-RSLRGRBJ.js.map +1 -0
- package/dist/{chunk-44KHFMCM.js → chunk-VG6DC2GO.js} +32 -17
- package/dist/{chunk-44KHFMCM.js.map → chunk-VG6DC2GO.js.map} +1 -1
- package/dist/{chunk-5UFQCU6M.js → chunk-ZUZD2DRV.js} +5 -5
- package/dist/{cli-Bw9z-KqX.d.ts → cli-DEoABKXH.d.ts} +2 -2
- package/dist/cli.d.ts +5 -5
- package/dist/cli.js +15 -14
- package/dist/explicit-capture.d.ts +3 -3
- package/dist/external-wiki-access.d.ts +4 -4
- package/dist/external-wiki-access.js +2 -2
- package/dist/external-wiki-mcp-tools.d.ts +4 -4
- package/dist/index.d.ts +684 -684
- package/dist/index.js +21 -20
- package/dist/{maintenance-uJb74j64.d.ts → maintenance-N5ur13Al.d.ts} +1 -1
- package/dist/mcp-memory-inspector-app.d.ts +4 -4
- package/dist/namespaces/migrate.d.ts +1 -1
- package/dist/namespaces/storage.d.ts +1 -1
- package/dist/operator-toolkit.js +3 -2
- package/dist/orchestration/maintenance.d.ts +2 -2
- package/dist/orchestration/maintenance.js +3 -2
- package/dist/{orchestrator-CFi-5JSR.d.ts → orchestrator-ByLrpav4.d.ts} +2 -2
- package/dist/orchestrator.d.ts +3 -3
- package/dist/orchestrator.js +19 -18
- package/dist/{public-http-DK-QwaBu.d.ts → public-http-DusietP2.d.ts} +1 -1
- package/dist/schemas.d.ts +108 -108
- package/dist/shared-context/manager.d.ts +8 -8
- package/dist/support-passport/index.d.ts +7 -7
- package/dist/support-passport/index.js +4 -4
- package/dist/transfer/types.d.ts +66 -66
- package/package.json +2 -2
- package/src/access-http-query.ts +12 -0
- package/src/access-http.test.ts +32 -0
- package/src/access-http.ts +3 -7
- package/src/admin/admin-surfaces.test.ts +5 -10
- package/src/admin/admin-surfaces.ts +0 -16
- package/src/binary-lifecycle/pipeline.test.ts +1 -1
- package/src/binary-lifecycle/pipeline.ts +23 -9
- package/src/buffer.ts +6 -0
- package/src/maintenance/namespace-planner.ts +0 -2
- package/src/namespaces/catalog.test.ts +53 -8
- package/src/namespaces/catalog.ts +5 -37
- package/src/orchestration/turn-ingestion-snapshot.test.ts +167 -0
- package/src/orchestration/turn-ingestion.ts +2 -1
- package/dist/chunk-5W5N7XJZ.js.map +0 -1
- package/dist/chunk-6UZR7KEK.js.map +0 -1
- package/dist/chunk-6ZYQ36IB.js.map +0 -1
- package/dist/chunk-JJ7JW62R.js.map +0 -1
- package/dist/chunk-TRPX6F2G.js.map +0 -1
- /package/dist/{chunk-AJSZ2EK6.js.map → chunk-3USQWITL.js.map} +0 -0
- /package/dist/{chunk-RYGJGXL6.js.map → chunk-4EDAHS6D.js.map} +0 -0
- /package/dist/{chunk-KWN6NOHQ.js.map → chunk-BXOZALJ6.js.map} +0 -0
- /package/dist/{chunk-6F2UMP4H.js.map → chunk-CKWOMJDY.js.map} +0 -0
- /package/dist/{chunk-MR5HWQHS.js.map → chunk-DFEYRCG2.js.map} +0 -0
- /package/dist/{chunk-EJQXDKYK.js.map → chunk-EJCN5ATI.js.map} +0 -0
- /package/dist/{chunk-XZPSBGHA.js.map → chunk-ISFUFLFM.js.map} +0 -0
- /package/dist/{chunk-4NMVX5U7.js.map → chunk-JSH2TV34.js.map} +0 -0
- /package/dist/{chunk-R74NCKEY.js.map → chunk-LNFYISZ6.js.map} +0 -0
- /package/dist/{chunk-IM56VPKO.js.map → chunk-OR7KEGLR.js.map} +0 -0
- /package/dist/{chunk-A73QHOZP.js.map → chunk-QOMUE4FS.js.map} +0 -0
- /package/dist/{chunk-5UFQCU6M.js.map → chunk-ZUZD2DRV.js.map} +0 -0
|
@@ -2,12 +2,6 @@ import {
|
|
|
2
2
|
resolveDefaultNamespaceRoot,
|
|
3
3
|
resolveNamespaceStorageRoot
|
|
4
4
|
} from "./chunk-QSIQVC32.js";
|
|
5
|
-
import {
|
|
6
|
-
getConfiguredNamespaces
|
|
7
|
-
} from "./chunk-Q57GOHLF.js";
|
|
8
|
-
import {
|
|
9
|
-
displayErrorDetail
|
|
10
|
-
} from "./chunk-RL6NEVXT.js";
|
|
11
5
|
import {
|
|
12
6
|
MutationSerializer,
|
|
13
7
|
withHeldFileLock
|
|
@@ -22,7 +16,6 @@ import {
|
|
|
22
16
|
normalizeNamespaceIdentity
|
|
23
17
|
} from "./chunk-VUFL7X3H.js";
|
|
24
18
|
import {
|
|
25
|
-
resolveConversationContextCapabilities,
|
|
26
19
|
resolveNamespaceCapabilities
|
|
27
20
|
} from "./chunk-JUOZ62Y7.js";
|
|
28
21
|
import {
|
|
@@ -45,13 +38,11 @@ import {
|
|
|
45
38
|
import { StringDecoder } from "string_decoder";
|
|
46
39
|
var NAMESPACE_KINDS = [
|
|
47
40
|
"default",
|
|
48
|
-
"self",
|
|
49
41
|
"shared",
|
|
50
42
|
"project",
|
|
51
43
|
"branch",
|
|
52
44
|
"team-project",
|
|
53
|
-
"explicit"
|
|
54
|
-
"legacy"
|
|
45
|
+
"explicit"
|
|
55
46
|
];
|
|
56
47
|
var NAMESPACE_DISCOVERY_SOURCES = [
|
|
57
48
|
"config",
|
|
@@ -144,8 +135,7 @@ function coerceRecord(value) {
|
|
|
144
135
|
if (typeof v.storageDir !== "string" || v.storageDir.length === 0) return null;
|
|
145
136
|
if (typeof v.createdAt !== "string" || v.createdAt.length === 0) return null;
|
|
146
137
|
if (!isValidIsoTimestamp(v.createdAt)) return null;
|
|
147
|
-
const kind =
|
|
148
|
-
if (!kind) return null;
|
|
138
|
+
const kind = isNamespaceKind(v.kind) ? v.kind : "explicit";
|
|
149
139
|
const discoveredBy = v.discoveredBy === void 0 ? "scan" : isNamespaceDiscoverySource(v.discoveredBy) ? v.discoveredBy : null;
|
|
150
140
|
if (!discoveredBy) return null;
|
|
151
141
|
const record = {
|
|
@@ -156,10 +146,6 @@ function coerceRecord(value) {
|
|
|
156
146
|
storageDir: v.storageDir,
|
|
157
147
|
discoveredBy
|
|
158
148
|
};
|
|
159
|
-
if (typeof v.principal === "string") record.principal = v.principal;
|
|
160
|
-
if (typeof v.projectId === "string") record.projectId = v.projectId;
|
|
161
|
-
if (typeof v.branch === "string") record.branch = v.branch;
|
|
162
|
-
if (typeof v.parentNamespace === "string") record.parentNamespace = v.parentNamespace;
|
|
163
149
|
if (typeof v.lastReadAt === "string" && isValidIsoTimestamp(v.lastReadAt)) {
|
|
164
150
|
record.lastReadAt = v.lastReadAt;
|
|
165
151
|
}
|
|
@@ -509,12 +495,6 @@ var NamespaceCatalog = class {
|
|
|
509
495
|
if (kind === "read" && cached.lastReadAt === void 0) return true;
|
|
510
496
|
if (!metadata) return false;
|
|
511
497
|
if (metadata.kind !== void 0 && metadata.kind !== cached.kind) return true;
|
|
512
|
-
if (metadata.principal !== void 0 && metadata.principal !== cached.principal) return true;
|
|
513
|
-
if (metadata.projectId !== void 0 && metadata.projectId !== cached.projectId) return true;
|
|
514
|
-
if (metadata.branch !== void 0 && metadata.branch !== cached.branch) return true;
|
|
515
|
-
if (metadata.parentNamespace !== void 0 && metadata.parentNamespace !== cached.parentNamespace) {
|
|
516
|
-
return true;
|
|
517
|
-
}
|
|
518
498
|
if (metadata.storageDir !== void 0 && metadata.storageDir !== cached.storageDir) return true;
|
|
519
499
|
return false;
|
|
520
500
|
}
|
|
@@ -655,9 +635,9 @@ var NamespaceCatalog = class {
|
|
|
655
635
|
}
|
|
656
636
|
if (await this.hasSymlinkedAncestor(candidate)) return false;
|
|
657
637
|
try {
|
|
658
|
-
const
|
|
659
|
-
if (
|
|
660
|
-
if (!
|
|
638
|
+
const stat2 = await lstat(candidate);
|
|
639
|
+
if (stat2.isSymbolicLink()) return false;
|
|
640
|
+
if (!stat2.isDirectory()) return false;
|
|
661
641
|
} catch {
|
|
662
642
|
return this.isNearestExistingAncestorContained(candidate, memoryReal);
|
|
663
643
|
}
|
|
@@ -718,8 +698,8 @@ var NamespaceCatalog = class {
|
|
|
718
698
|
}
|
|
719
699
|
if (!(isPathInside(memoryReal, real) || real === memoryReal)) return false;
|
|
720
700
|
try {
|
|
721
|
-
const
|
|
722
|
-
return
|
|
701
|
+
const stat2 = await lstat(real);
|
|
702
|
+
return stat2.isDirectory();
|
|
723
703
|
} catch {
|
|
724
704
|
return false;
|
|
725
705
|
}
|
|
@@ -883,14 +863,14 @@ var NamespaceCatalog = class {
|
|
|
883
863
|
if (normalizeNamespaceIdentity(namespace) !== this.defaultNamespaceIdentity && path.resolve(root) === path.resolve(this.memoryDir)) {
|
|
884
864
|
return false;
|
|
885
865
|
}
|
|
886
|
-
let
|
|
866
|
+
let stat2;
|
|
887
867
|
try {
|
|
888
|
-
|
|
868
|
+
stat2 = await lstat(root);
|
|
889
869
|
} catch {
|
|
890
870
|
return false;
|
|
891
871
|
}
|
|
892
|
-
if (
|
|
893
|
-
if (!
|
|
872
|
+
if (stat2.isSymbolicLink()) return false;
|
|
873
|
+
if (!stat2.isDirectory()) return false;
|
|
894
874
|
try {
|
|
895
875
|
const real = await realpath(root);
|
|
896
876
|
if (memoryReal && !isPathInside(memoryReal, real)) return false;
|
|
@@ -933,11 +913,6 @@ var NamespaceCatalog = class {
|
|
|
933
913
|
};
|
|
934
914
|
record.storageDir = storageDir;
|
|
935
915
|
if (metadata?.kind) record.kind = metadata.kind;
|
|
936
|
-
if (metadata?.principal !== void 0) record.principal = metadata.principal;
|
|
937
|
-
if (metadata?.projectId !== void 0) record.projectId = metadata.projectId;
|
|
938
|
-
if (metadata?.branch !== void 0) record.branch = metadata.branch;
|
|
939
|
-
if (metadata?.parentNamespace !== void 0)
|
|
940
|
-
record.parentNamespace = metadata.parentNamespace;
|
|
941
916
|
if (kind === "write" && existing && record.discoveredBy === "config") {
|
|
942
917
|
record.discoveredBy = "write";
|
|
943
918
|
}
|
|
@@ -1091,18 +1066,18 @@ var NamespaceCatalog = class {
|
|
|
1091
1066
|
for (const entry of entries) {
|
|
1092
1067
|
const token = entry.name;
|
|
1093
1068
|
const fullPath = path.join(namespacesDir, token);
|
|
1094
|
-
let
|
|
1069
|
+
let stat2;
|
|
1095
1070
|
try {
|
|
1096
|
-
|
|
1071
|
+
stat2 = await lstat(fullPath);
|
|
1097
1072
|
} catch (err) {
|
|
1098
1073
|
skipped.push({ token, reason: "error", detail: err instanceof Error ? err.message : String(err) });
|
|
1099
1074
|
continue;
|
|
1100
1075
|
}
|
|
1101
|
-
if (
|
|
1076
|
+
if (stat2.isSymbolicLink()) {
|
|
1102
1077
|
skipped.push({ token, reason: "symlink", detail: fullPath });
|
|
1103
1078
|
continue;
|
|
1104
1079
|
}
|
|
1105
|
-
if (!
|
|
1080
|
+
if (!stat2.isDirectory()) continue;
|
|
1106
1081
|
try {
|
|
1107
1082
|
const real = await realpath(fullPath);
|
|
1108
1083
|
if (memoryReal && !isPathInside(memoryReal, real)) {
|
|
@@ -1312,10 +1287,6 @@ var NamespaceCatalog = class {
|
|
|
1312
1287
|
if (prior.lastReadAt) merged.lastReadAt = prior.lastReadAt;
|
|
1313
1288
|
if (prior.lastWriteAt) merged.lastWriteAt = prior.lastWriteAt;
|
|
1314
1289
|
if (prior.lastMaintenanceAt) merged.lastMaintenanceAt = { ...prior.lastMaintenanceAt };
|
|
1315
|
-
if (prior.principal !== void 0) merged.principal = prior.principal;
|
|
1316
|
-
if (prior.projectId !== void 0) merged.projectId = prior.projectId;
|
|
1317
|
-
if (prior.branch !== void 0) merged.branch = prior.branch;
|
|
1318
|
-
if (prior.parentNamespace !== void 0) merged.parentNamespace = prior.parentNamespace;
|
|
1319
1290
|
return merged;
|
|
1320
1291
|
}
|
|
1321
1292
|
// ── Persistence ──────────────────────────────────────────────────────────
|
|
@@ -1497,713 +1468,9 @@ function isPathInside(root, child) {
|
|
|
1497
1468
|
return relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
1498
1469
|
}
|
|
1499
1470
|
|
|
1500
|
-
// src/maintenance/namespace-planner.ts
|
|
1501
|
-
import { createHash, randomUUID } from "crypto";
|
|
1502
|
-
import { lstat as lstat2, mkdir as mkdir2, open as open2, readFile, readdir as readdir2, rename as rename2, rm, rmdir, utimes, writeFile as writeFile2 } from "fs/promises";
|
|
1503
|
-
import path2 from "path";
|
|
1504
|
-
var DEFAULT_MAX_NAMESPACES_PER_CYCLE = 20;
|
|
1505
|
-
var DEFAULT_LOCK_STALE_MS = 10 * 6e4;
|
|
1506
|
-
var LOCK_BASE = "maintenance-locks";
|
|
1507
|
-
var STATUS_BASE = "namespace-maintenance-status";
|
|
1508
|
-
var namespaceMaintenanceFs = { open: open2, rm };
|
|
1509
|
-
function inferConfiguredKind(config, namespace) {
|
|
1510
|
-
if (namespace === config.defaultNamespace.trim()) return "default";
|
|
1511
|
-
if (namespace === config.sharedNamespace.trim()) return "shared";
|
|
1512
|
-
return "explicit";
|
|
1513
|
-
}
|
|
1514
|
-
function maxNamespacesPerCycle(config) {
|
|
1515
|
-
return Math.max(
|
|
1516
|
-
1,
|
|
1517
|
-
Math.floor(
|
|
1518
|
-
typeof config.maintenanceMaxNamespacesPerCycle === "number" && Number.isFinite(config.maintenanceMaxNamespacesPerCycle) ? config.maintenanceMaxNamespacesPerCycle : DEFAULT_MAX_NAMESPACES_PER_CYCLE
|
|
1519
|
-
)
|
|
1520
|
-
);
|
|
1521
|
-
}
|
|
1522
|
-
function namespaceKindAllowed(config, kind) {
|
|
1523
|
-
switch (kind) {
|
|
1524
|
-
case "branch":
|
|
1525
|
-
return config.maintenanceIncludeBranchNamespaces === true;
|
|
1526
|
-
case "project":
|
|
1527
|
-
return config.maintenanceIncludeProjectNamespaces !== false;
|
|
1528
|
-
case "team-project":
|
|
1529
|
-
return config.maintenanceIncludeTeamProjectNamespaces !== false;
|
|
1530
|
-
default:
|
|
1531
|
-
return true;
|
|
1532
|
-
}
|
|
1533
|
-
}
|
|
1534
|
-
function disabledReasonForKind(kind) {
|
|
1535
|
-
if (kind === "branch") return "branch_disabled";
|
|
1536
|
-
if (kind === "project") return "project_disabled";
|
|
1537
|
-
if (kind === "team-project") return "team_project_disabled";
|
|
1538
|
-
return "fanout_disabled";
|
|
1539
|
-
}
|
|
1540
|
-
async function catalogRootIsLive(config, record) {
|
|
1541
|
-
if (typeof record.storageDir !== "string" || record.storageDir.length === 0) {
|
|
1542
|
-
return false;
|
|
1543
|
-
}
|
|
1544
|
-
try {
|
|
1545
|
-
const liveRoot = await resolveNamespaceStorageRoot(config, record.namespace);
|
|
1546
|
-
if (path2.resolve(liveRoot) !== path2.resolve(record.storageDir)) return false;
|
|
1547
|
-
return hasMemoryData(liveRoot);
|
|
1548
|
-
} catch {
|
|
1549
|
-
return false;
|
|
1550
|
-
}
|
|
1551
|
-
}
|
|
1552
|
-
function candidateSortKey(candidate) {
|
|
1553
|
-
const write = candidate.lastWriteAt ?? "";
|
|
1554
|
-
return `${write}\0${candidate.namespace}`;
|
|
1555
|
-
}
|
|
1556
|
-
function candidatePriority(candidate) {
|
|
1557
|
-
if (candidate.kind === "default") return 0;
|
|
1558
|
-
if (candidate.kind === "shared") return 1;
|
|
1559
|
-
if (candidate.source === "configured") return 2;
|
|
1560
|
-
if (candidate.kind === "team-project") return 3;
|
|
1561
|
-
if (candidate.kind === "project") return 4;
|
|
1562
|
-
if (candidate.kind === "self") return 5;
|
|
1563
|
-
if (candidate.kind === "legacy") return 6;
|
|
1564
|
-
if (candidate.kind === "branch") return 8;
|
|
1565
|
-
return 7;
|
|
1566
|
-
}
|
|
1567
|
-
function sortCandidates(a, b) {
|
|
1568
|
-
const priority = candidatePriority(a) - candidatePriority(b);
|
|
1569
|
-
if (priority !== 0) return priority;
|
|
1570
|
-
const am = Date.parse(a.lastMaintenanceAt ?? "");
|
|
1571
|
-
const bm = Date.parse(b.lastMaintenanceAt ?? "");
|
|
1572
|
-
const aMaintained = Number.isFinite(am);
|
|
1573
|
-
const bMaintained = Number.isFinite(bm);
|
|
1574
|
-
if (aMaintained && bMaintained && am !== bm) return am - bm;
|
|
1575
|
-
if (aMaintained !== bMaintained) return aMaintained ? 1 : -1;
|
|
1576
|
-
const aw = Date.parse(a.lastWriteAt ?? "");
|
|
1577
|
-
const bw = Date.parse(b.lastWriteAt ?? "");
|
|
1578
|
-
const aValid = Number.isFinite(aw);
|
|
1579
|
-
const bValid = Number.isFinite(bw);
|
|
1580
|
-
if (aValid && bValid && aw !== bw) return bw - aw;
|
|
1581
|
-
if (aValid !== bValid) return aValid ? -1 : 1;
|
|
1582
|
-
const byKey = candidateSortKey(a).localeCompare(candidateSortKey(b));
|
|
1583
|
-
if (byKey !== 0) return byKey;
|
|
1584
|
-
return a.namespace.localeCompare(b.namespace);
|
|
1585
|
-
}
|
|
1586
|
-
async function planNamespaceMaintenance(config, options) {
|
|
1587
|
-
const generatedAt = (options.now ?? /* @__PURE__ */ new Date()).toISOString();
|
|
1588
|
-
const configured = resolveNamespaceCapabilities(config).namespaces ? getConfiguredNamespaces(config) : [config.defaultNamespace.trim()].filter(Boolean);
|
|
1589
|
-
const byNamespace = /* @__PURE__ */ new Map();
|
|
1590
|
-
const skipped = [];
|
|
1591
|
-
for (const namespace of configured) {
|
|
1592
|
-
const kind = inferConfiguredKind(config, namespace);
|
|
1593
|
-
byNamespace.set(namespace, {
|
|
1594
|
-
namespace,
|
|
1595
|
-
kind,
|
|
1596
|
-
source: "configured"
|
|
1597
|
-
});
|
|
1598
|
-
}
|
|
1599
|
-
if (resolveNamespaceCapabilities(config).namespaces && resolveConversationContextCapabilities(config).maintenanceNamespaceFanout !== false) {
|
|
1600
|
-
const configuredSet = new Set(configured);
|
|
1601
|
-
try {
|
|
1602
|
-
const records = options.catalog?.enabled ? await options.catalog.listNamespaces() : [];
|
|
1603
|
-
for (const record of records) {
|
|
1604
|
-
const namespace = record.namespace.trim();
|
|
1605
|
-
if (!namespace) continue;
|
|
1606
|
-
const isConfigured = configuredSet.has(namespace);
|
|
1607
|
-
const kind = isConfigured ? inferConfiguredKind(config, namespace) : record.kind;
|
|
1608
|
-
if (!namespaceKindAllowed(config, kind)) {
|
|
1609
|
-
skipped.push({
|
|
1610
|
-
namespace,
|
|
1611
|
-
kind,
|
|
1612
|
-
reason: disabledReasonForKind(kind)
|
|
1613
|
-
});
|
|
1614
|
-
continue;
|
|
1615
|
-
}
|
|
1616
|
-
if (!isConfigured && !await catalogRootIsLive(config, record)) {
|
|
1617
|
-
skipped.push({
|
|
1618
|
-
namespace,
|
|
1619
|
-
kind,
|
|
1620
|
-
reason: "unsafe_or_stale_root"
|
|
1621
|
-
});
|
|
1622
|
-
continue;
|
|
1623
|
-
}
|
|
1624
|
-
byNamespace.set(namespace, {
|
|
1625
|
-
namespace,
|
|
1626
|
-
kind,
|
|
1627
|
-
storageDir: record.storageDir,
|
|
1628
|
-
source: isConfigured ? "configured" : "catalog",
|
|
1629
|
-
lastWriteAt: record.lastWriteAt,
|
|
1630
|
-
lastMaintenanceAt: record.lastMaintenanceAt?.[options.jobName]
|
|
1631
|
-
});
|
|
1632
|
-
}
|
|
1633
|
-
} catch (error) {
|
|
1634
|
-
skipped.push({
|
|
1635
|
-
namespace: "*",
|
|
1636
|
-
reason: "catalog_read_failed",
|
|
1637
|
-
detail: error instanceof Error ? error.message : String(error)
|
|
1638
|
-
});
|
|
1639
|
-
}
|
|
1640
|
-
} else if (resolveNamespaceCapabilities(config).namespaces) {
|
|
1641
|
-
skipped.push({
|
|
1642
|
-
namespace: "*",
|
|
1643
|
-
reason: "fanout_disabled"
|
|
1644
|
-
});
|
|
1645
|
-
}
|
|
1646
|
-
if (options.budgetMode !== "unbounded") {
|
|
1647
|
-
const latestStatusAtByNamespace = await readLatestStatusAtByNamespace(config, options.jobName);
|
|
1648
|
-
for (const candidate of byNamespace.values()) {
|
|
1649
|
-
if (!candidate.lastMaintenanceAt) {
|
|
1650
|
-
candidate.lastMaintenanceAt = latestStatusAtByNamespace.get(candidate.namespace);
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
const candidates = [...byNamespace.values()].filter((candidate) => namespaceKindAllowed(config, candidate.kind)).sort(sortCandidates);
|
|
1655
|
-
const max = maxNamespacesPerCycle(config);
|
|
1656
|
-
const applyCycleBudget = options.budgetMode !== "unbounded";
|
|
1657
|
-
const selected = applyCycleBudget ? candidates.slice(0, max) : candidates;
|
|
1658
|
-
if (applyCycleBudget) {
|
|
1659
|
-
for (const candidate of candidates.slice(max)) {
|
|
1660
|
-
skipped.push({
|
|
1661
|
-
namespace: candidate.namespace,
|
|
1662
|
-
kind: candidate.kind,
|
|
1663
|
-
reason: "budget_exhausted"
|
|
1664
|
-
});
|
|
1665
|
-
}
|
|
1666
|
-
}
|
|
1667
|
-
return {
|
|
1668
|
-
jobName: options.jobName,
|
|
1669
|
-
generatedAt,
|
|
1670
|
-
namespaces: selected,
|
|
1671
|
-
skipped,
|
|
1672
|
-
budget: {
|
|
1673
|
-
maxNamespacesPerCycle: max,
|
|
1674
|
-
selected: selected.length
|
|
1675
|
-
}
|
|
1676
|
-
};
|
|
1677
|
-
}
|
|
1678
|
-
function stablePathSegment(value) {
|
|
1679
|
-
const sanitized = value.replace(/[^a-zA-Z0-9._-]/g, "_").slice(0, 128) || "unnamed";
|
|
1680
|
-
if (sanitized.length <= 128 && sanitized === value) return sanitized;
|
|
1681
|
-
return `${sanitized.slice(0, 80)}-${createHash("sha256").update(value).digest("hex").slice(0, 16)}`;
|
|
1682
|
-
}
|
|
1683
|
-
function namespacePathSegment(namespace) {
|
|
1684
|
-
const token = namespaceIdentityToken(namespace);
|
|
1685
|
-
if (token.length <= 160) return token;
|
|
1686
|
-
return `ns-${createHash("sha256").update(namespace).digest("hex")}`;
|
|
1687
|
-
}
|
|
1688
|
-
function lockPath(config, jobName, namespace) {
|
|
1689
|
-
return path2.join(
|
|
1690
|
-
config.memoryDir,
|
|
1691
|
-
"state",
|
|
1692
|
-
LOCK_BASE,
|
|
1693
|
-
stablePathSegment(jobName),
|
|
1694
|
-
`${namespacePathSegment(namespace)}.lock`
|
|
1695
|
-
);
|
|
1696
|
-
}
|
|
1697
|
-
function namespaceMaintenanceLockStaleMs(config) {
|
|
1698
|
-
if (typeof config.maintenanceNamespaceLockStaleMs === "number" && Number.isFinite(config.maintenanceNamespaceLockStaleMs) && config.maintenanceNamespaceLockStaleMs > 0) {
|
|
1699
|
-
return Math.floor(config.maintenanceNamespaceLockStaleMs);
|
|
1700
|
-
}
|
|
1701
|
-
return DEFAULT_LOCK_STALE_MS;
|
|
1702
|
-
}
|
|
1703
|
-
function namespaceMaintenanceLockHeartbeatMs(config) {
|
|
1704
|
-
const staleMs = namespaceMaintenanceLockStaleMs(config);
|
|
1705
|
-
return Math.max(1, Math.min(3e4, Math.floor(staleMs / 3) || 1));
|
|
1706
|
-
}
|
|
1707
|
-
function errorCode(error) {
|
|
1708
|
-
return typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
|
|
1709
|
-
}
|
|
1710
|
-
async function withNamespaceMaintenanceLockHeartbeat(config, locks, task) {
|
|
1711
|
-
const activeLocks = Array.isArray(locks) ? locks : [locks];
|
|
1712
|
-
const interval = setInterval(() => {
|
|
1713
|
-
for (const lock of activeLocks) {
|
|
1714
|
-
void lock.touch().catch(() => void 0);
|
|
1715
|
-
}
|
|
1716
|
-
}, namespaceMaintenanceLockHeartbeatMs(config));
|
|
1717
|
-
interval.unref?.();
|
|
1718
|
-
try {
|
|
1719
|
-
return await task();
|
|
1720
|
-
} finally {
|
|
1721
|
-
clearInterval(interval);
|
|
1722
|
-
}
|
|
1723
|
-
}
|
|
1724
|
-
async function removeStaleLockDirectory(filePath) {
|
|
1725
|
-
let entries;
|
|
1726
|
-
try {
|
|
1727
|
-
entries = await readdir2(filePath, { withFileTypes: true });
|
|
1728
|
-
} catch (error) {
|
|
1729
|
-
if (errorCode(error) === "ENOENT") return;
|
|
1730
|
-
throw error;
|
|
1731
|
-
}
|
|
1732
|
-
for (const entry of entries) {
|
|
1733
|
-
if (!entry.isFile()) continue;
|
|
1734
|
-
await namespaceMaintenanceFs.rm(path2.join(filePath, entry.name), { force: true });
|
|
1735
|
-
}
|
|
1736
|
-
try {
|
|
1737
|
-
await rmdir(filePath);
|
|
1738
|
-
} catch (error) {
|
|
1739
|
-
if (errorCode(error) === "ENOENT") return;
|
|
1740
|
-
throw error;
|
|
1741
|
-
}
|
|
1742
|
-
}
|
|
1743
|
-
async function tryAcquireNamespaceMaintenanceLock(config, jobName, namespace) {
|
|
1744
|
-
const filePath = lockPath(config, jobName, namespace);
|
|
1745
|
-
await mkdir2(path2.dirname(filePath), { recursive: true });
|
|
1746
|
-
try {
|
|
1747
|
-
const lockId = randomUUID();
|
|
1748
|
-
await mkdir2(filePath);
|
|
1749
|
-
const ownerPath = path2.join(filePath, `${lockId}.json`);
|
|
1750
|
-
let handle;
|
|
1751
|
-
try {
|
|
1752
|
-
handle = await namespaceMaintenanceFs.open(ownerPath, "wx");
|
|
1753
|
-
await handle.writeFile(
|
|
1754
|
-
`${JSON.stringify({
|
|
1755
|
-
lockId,
|
|
1756
|
-
pid: process.pid,
|
|
1757
|
-
jobName,
|
|
1758
|
-
namespace,
|
|
1759
|
-
acquiredAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1760
|
-
})}
|
|
1761
|
-
`,
|
|
1762
|
-
"utf8"
|
|
1763
|
-
);
|
|
1764
|
-
await handle.close();
|
|
1765
|
-
} catch (setupError) {
|
|
1766
|
-
await handle?.close().catch(() => void 0);
|
|
1767
|
-
await namespaceMaintenanceFs.rm(ownerPath, { force: true }).catch(() => void 0);
|
|
1768
|
-
await rmdir(filePath).catch(() => void 0);
|
|
1769
|
-
throw setupError;
|
|
1770
|
-
}
|
|
1771
|
-
return {
|
|
1772
|
-
path: filePath,
|
|
1773
|
-
async touch() {
|
|
1774
|
-
try {
|
|
1775
|
-
const parsed = JSON.parse(await readFile(ownerPath, "utf8"));
|
|
1776
|
-
if (parsed.lockId === lockId) {
|
|
1777
|
-
const now = /* @__PURE__ */ new Date();
|
|
1778
|
-
await utimes(ownerPath, now, now);
|
|
1779
|
-
await utimes(filePath, now, now);
|
|
1780
|
-
}
|
|
1781
|
-
} catch {
|
|
1782
|
-
}
|
|
1783
|
-
},
|
|
1784
|
-
async release() {
|
|
1785
|
-
try {
|
|
1786
|
-
const parsed = JSON.parse(await readFile(ownerPath, "utf8"));
|
|
1787
|
-
if (parsed.lockId === lockId) {
|
|
1788
|
-
await namespaceMaintenanceFs.rm(ownerPath, { force: true });
|
|
1789
|
-
await rmdir(filePath).catch(() => void 0);
|
|
1790
|
-
}
|
|
1791
|
-
} catch {
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
};
|
|
1795
|
-
} catch (error) {
|
|
1796
|
-
if (errorCode(error) === "EEXIST") {
|
|
1797
|
-
const staleMs = namespaceMaintenanceLockStaleMs(config);
|
|
1798
|
-
try {
|
|
1799
|
-
const s = await lstat2(filePath);
|
|
1800
|
-
if (s.isSymbolicLink()) {
|
|
1801
|
-
return null;
|
|
1802
|
-
}
|
|
1803
|
-
if ((s.isFile() || s.isDirectory()) && Date.now() - s.mtimeMs > staleMs) {
|
|
1804
|
-
try {
|
|
1805
|
-
if (s.isDirectory()) {
|
|
1806
|
-
await removeStaleLockDirectory(filePath);
|
|
1807
|
-
} else {
|
|
1808
|
-
await namespaceMaintenanceFs.rm(filePath, { force: true });
|
|
1809
|
-
}
|
|
1810
|
-
} catch (removeError) {
|
|
1811
|
-
if (errorCode(removeError) === "ENOENT") {
|
|
1812
|
-
return tryAcquireNamespaceMaintenanceLock(config, jobName, namespace);
|
|
1813
|
-
}
|
|
1814
|
-
if (errorCode(removeError) === "ENOTEMPTY") {
|
|
1815
|
-
return null;
|
|
1816
|
-
}
|
|
1817
|
-
throw removeError;
|
|
1818
|
-
}
|
|
1819
|
-
return tryAcquireNamespaceMaintenanceLock(config, jobName, namespace);
|
|
1820
|
-
}
|
|
1821
|
-
} catch (statError) {
|
|
1822
|
-
if (errorCode(statError) === "ENOENT") {
|
|
1823
|
-
return tryAcquireNamespaceMaintenanceLock(config, jobName, namespace);
|
|
1824
|
-
}
|
|
1825
|
-
throw statError;
|
|
1826
|
-
}
|
|
1827
|
-
return null;
|
|
1828
|
-
}
|
|
1829
|
-
throw error;
|
|
1830
|
-
}
|
|
1831
|
-
}
|
|
1832
|
-
function statusBasePath(config) {
|
|
1833
|
-
return path2.join(config.memoryDir, "state", STATUS_BASE);
|
|
1834
|
-
}
|
|
1835
|
-
function statusPath(config, jobName, namespace) {
|
|
1836
|
-
return path2.join(statusBasePath(config), stablePathSegment(jobName), `${namespacePathSegment(namespace)}.json`);
|
|
1837
|
-
}
|
|
1838
|
-
function lastRanStatusPath(config, jobName, namespace) {
|
|
1839
|
-
return path2.join(statusBasePath(config), stablePathSegment(jobName), `${namespacePathSegment(namespace)}.last-ran.json`);
|
|
1840
|
-
}
|
|
1841
|
-
function parseStatus(value) {
|
|
1842
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
1843
|
-
const v = value;
|
|
1844
|
-
if (typeof v.namespace === "string" && typeof v.jobName === "string" && (v.state === "ran" || v.state === "skipped" || v.state === "failed") && typeof v.startedAt === "string" && typeof v.completedAt === "string") {
|
|
1845
|
-
return v;
|
|
1846
|
-
}
|
|
1847
|
-
return null;
|
|
1848
|
-
}
|
|
1849
|
-
async function readLatestStatusAtByNamespace(config, jobName) {
|
|
1850
|
-
const latest = /* @__PURE__ */ new Map();
|
|
1851
|
-
const latestMs = /* @__PURE__ */ new Map();
|
|
1852
|
-
for (const status of [...await readStatusFiles(config), ...await readLastRanStatusFiles(config)]) {
|
|
1853
|
-
if (status.state !== "ran") continue;
|
|
1854
|
-
if (status.jobName !== jobName) continue;
|
|
1855
|
-
const completedAtMs = Date.parse(status.completedAt);
|
|
1856
|
-
if (!Number.isFinite(completedAtMs)) continue;
|
|
1857
|
-
const previousMs = latestMs.get(status.namespace);
|
|
1858
|
-
if (previousMs !== void 0 && previousMs >= completedAtMs) continue;
|
|
1859
|
-
latestMs.set(status.namespace, completedAtMs);
|
|
1860
|
-
latest.set(status.namespace, status.completedAt);
|
|
1861
|
-
}
|
|
1862
|
-
return latest;
|
|
1863
|
-
}
|
|
1864
|
-
async function readStatusFile(filePath) {
|
|
1865
|
-
try {
|
|
1866
|
-
const parsed = JSON.parse(await readFile(filePath, "utf8"));
|
|
1867
|
-
return parseStatus(parsed);
|
|
1868
|
-
} catch {
|
|
1869
|
-
return null;
|
|
1870
|
-
}
|
|
1871
|
-
}
|
|
1872
|
-
async function readStatusFiles(config) {
|
|
1873
|
-
if (typeof config.memoryDir !== "string" || config.memoryDir.length === 0) {
|
|
1874
|
-
return [];
|
|
1875
|
-
}
|
|
1876
|
-
const root = statusBasePath(config);
|
|
1877
|
-
const statuses = [];
|
|
1878
|
-
let jobDirs;
|
|
1879
|
-
try {
|
|
1880
|
-
jobDirs = await readdir2(root, { withFileTypes: true });
|
|
1881
|
-
} catch {
|
|
1882
|
-
return statuses;
|
|
1883
|
-
}
|
|
1884
|
-
for (const jobDir of jobDirs) {
|
|
1885
|
-
if (!jobDir.isDirectory()) continue;
|
|
1886
|
-
let files;
|
|
1887
|
-
try {
|
|
1888
|
-
files = await readdir2(path2.join(root, jobDir.name), { withFileTypes: true });
|
|
1889
|
-
} catch {
|
|
1890
|
-
continue;
|
|
1891
|
-
}
|
|
1892
|
-
for (const file of files) {
|
|
1893
|
-
if (!file.isFile() || !file.name.endsWith(".json")) continue;
|
|
1894
|
-
if (file.name.endsWith(".last-ran.json")) continue;
|
|
1895
|
-
const status = await readStatusFile(path2.join(root, jobDir.name, file.name));
|
|
1896
|
-
if (status) statuses.push(status);
|
|
1897
|
-
}
|
|
1898
|
-
}
|
|
1899
|
-
return statuses;
|
|
1900
|
-
}
|
|
1901
|
-
async function readLastRanStatusFiles(config) {
|
|
1902
|
-
if (typeof config.memoryDir !== "string" || config.memoryDir.length === 0) {
|
|
1903
|
-
return [];
|
|
1904
|
-
}
|
|
1905
|
-
const root = statusBasePath(config);
|
|
1906
|
-
const statuses = [];
|
|
1907
|
-
let jobDirs;
|
|
1908
|
-
try {
|
|
1909
|
-
jobDirs = await readdir2(root, { withFileTypes: true });
|
|
1910
|
-
} catch {
|
|
1911
|
-
return statuses;
|
|
1912
|
-
}
|
|
1913
|
-
for (const jobDir of jobDirs) {
|
|
1914
|
-
if (!jobDir.isDirectory()) continue;
|
|
1915
|
-
let files;
|
|
1916
|
-
try {
|
|
1917
|
-
files = await readdir2(path2.join(root, jobDir.name), { withFileTypes: true });
|
|
1918
|
-
} catch {
|
|
1919
|
-
continue;
|
|
1920
|
-
}
|
|
1921
|
-
for (const file of files) {
|
|
1922
|
-
if (!file.isFile() || !file.name.endsWith(".last-ran.json")) continue;
|
|
1923
|
-
const status = await readStatusFile(path2.join(root, jobDir.name, file.name));
|
|
1924
|
-
if (status) statuses.push(status);
|
|
1925
|
-
}
|
|
1926
|
-
}
|
|
1927
|
-
return statuses;
|
|
1928
|
-
}
|
|
1929
|
-
async function writeStatusPayload(target, status) {
|
|
1930
|
-
const dir = path2.dirname(target);
|
|
1931
|
-
await mkdir2(dir, { recursive: true });
|
|
1932
|
-
const temp = `${target}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
1933
|
-
const payload = {
|
|
1934
|
-
version: 1,
|
|
1935
|
-
...status
|
|
1936
|
-
};
|
|
1937
|
-
await writeFile2(temp, `${JSON.stringify(payload, null, 2)}
|
|
1938
|
-
`, "utf8");
|
|
1939
|
-
await rename2(temp, target);
|
|
1940
|
-
}
|
|
1941
|
-
async function writeStatusFile(config, status) {
|
|
1942
|
-
await writeStatusPayload(statusPath(config, status.jobName, status.namespace), status);
|
|
1943
|
-
if (status.state === "ran") {
|
|
1944
|
-
await writeStatusPayload(lastRanStatusPath(config, status.jobName, status.namespace), status);
|
|
1945
|
-
}
|
|
1946
|
-
}
|
|
1947
|
-
async function recordNamespaceMaintenanceStatusSafely(config, status) {
|
|
1948
|
-
try {
|
|
1949
|
-
await writeStatusFile(config, status);
|
|
1950
|
-
} catch {
|
|
1951
|
-
}
|
|
1952
|
-
}
|
|
1953
|
-
function maintenanceErrorDetail(error) {
|
|
1954
|
-
return displayErrorDetail(error) || "Error";
|
|
1955
|
-
}
|
|
1956
|
-
async function readNamespaceMaintenanceStatuses(config) {
|
|
1957
|
-
return (await readStatusFiles(config)).sort((a, b) => {
|
|
1958
|
-
const byJob = a.jobName.localeCompare(b.jobName);
|
|
1959
|
-
if (byJob !== 0) return byJob;
|
|
1960
|
-
return a.namespace.localeCompare(b.namespace);
|
|
1961
|
-
});
|
|
1962
|
-
}
|
|
1963
|
-
async function readNamespaceMaintenanceLastRanStatuses(config) {
|
|
1964
|
-
return (await readLastRanStatusFiles(config)).sort((a, b) => {
|
|
1965
|
-
const byJob = a.jobName.localeCompare(b.jobName);
|
|
1966
|
-
if (byJob !== 0) return byJob;
|
|
1967
|
-
return a.namespace.localeCompare(b.namespace);
|
|
1968
|
-
});
|
|
1969
|
-
}
|
|
1970
|
-
async function runNamespaceMaintenancePlan(config, plan, runner, catalog) {
|
|
1971
|
-
const statuses = [];
|
|
1972
|
-
for (const skipped of plan.skipped) {
|
|
1973
|
-
if (skipped.namespace === "*") continue;
|
|
1974
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1975
|
-
const status = {
|
|
1976
|
-
namespace: skipped.namespace,
|
|
1977
|
-
jobName: plan.jobName,
|
|
1978
|
-
state: "skipped",
|
|
1979
|
-
reason: skipped.reason,
|
|
1980
|
-
startedAt: now,
|
|
1981
|
-
completedAt: now
|
|
1982
|
-
};
|
|
1983
|
-
statuses.push(status);
|
|
1984
|
-
await recordNamespaceMaintenanceStatusSafely(config, status);
|
|
1985
|
-
}
|
|
1986
|
-
for (const candidate of plan.namespaces) {
|
|
1987
|
-
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1988
|
-
const lock = await tryAcquireNamespaceMaintenanceLock(config, plan.jobName, candidate.namespace);
|
|
1989
|
-
if (!lock) {
|
|
1990
|
-
const completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1991
|
-
const status = {
|
|
1992
|
-
namespace: candidate.namespace,
|
|
1993
|
-
jobName: plan.jobName,
|
|
1994
|
-
state: "skipped",
|
|
1995
|
-
reason: "lock_held",
|
|
1996
|
-
startedAt,
|
|
1997
|
-
completedAt
|
|
1998
|
-
};
|
|
1999
|
-
statuses.push(status);
|
|
2000
|
-
await recordNamespaceMaintenanceStatusSafely(config, status);
|
|
2001
|
-
continue;
|
|
2002
|
-
}
|
|
2003
|
-
try {
|
|
2004
|
-
const result = await withNamespaceMaintenanceLockHeartbeat(config, lock, () => runner(candidate));
|
|
2005
|
-
const completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2006
|
-
if (result?.skipped) {
|
|
2007
|
-
const status = {
|
|
2008
|
-
namespace: candidate.namespace,
|
|
2009
|
-
jobName: plan.jobName,
|
|
2010
|
-
state: "skipped",
|
|
2011
|
-
reason: result.skipReason ?? "throttled",
|
|
2012
|
-
startedAt,
|
|
2013
|
-
completedAt
|
|
2014
|
-
};
|
|
2015
|
-
statuses.push(status);
|
|
2016
|
-
await recordNamespaceMaintenanceStatusSafely(config, status);
|
|
2017
|
-
} else {
|
|
2018
|
-
const status = {
|
|
2019
|
-
namespace: candidate.namespace,
|
|
2020
|
-
jobName: plan.jobName,
|
|
2021
|
-
state: "ran",
|
|
2022
|
-
startedAt,
|
|
2023
|
-
completedAt,
|
|
2024
|
-
itemCount: result?.itemCount
|
|
2025
|
-
};
|
|
2026
|
-
statuses.push(status);
|
|
2027
|
-
await recordNamespaceMaintenanceStatusSafely(config, status);
|
|
2028
|
-
try {
|
|
2029
|
-
await catalog?.markMaintenance(candidate.namespace, plan.jobName, new Date(completedAt));
|
|
2030
|
-
} catch {
|
|
2031
|
-
}
|
|
2032
|
-
}
|
|
2033
|
-
} catch (error) {
|
|
2034
|
-
const completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2035
|
-
const status = {
|
|
2036
|
-
namespace: candidate.namespace,
|
|
2037
|
-
jobName: plan.jobName,
|
|
2038
|
-
state: "failed",
|
|
2039
|
-
reason: "job_failed",
|
|
2040
|
-
startedAt,
|
|
2041
|
-
completedAt,
|
|
2042
|
-
error: maintenanceErrorDetail(error)
|
|
2043
|
-
};
|
|
2044
|
-
statuses.push(status);
|
|
2045
|
-
await recordNamespaceMaintenanceStatusSafely(config, status);
|
|
2046
|
-
} finally {
|
|
2047
|
-
await lock.release().catch(() => void 0);
|
|
2048
|
-
}
|
|
2049
|
-
}
|
|
2050
|
-
return {
|
|
2051
|
-
jobName: plan.jobName,
|
|
2052
|
-
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2053
|
-
ran: statuses.filter((s) => s.state === "ran").length,
|
|
2054
|
-
skipped: statuses.filter((s) => s.state === "skipped").length,
|
|
2055
|
-
failed: statuses.filter((s) => s.state === "failed").length,
|
|
2056
|
-
statuses
|
|
2057
|
-
};
|
|
2058
|
-
}
|
|
2059
|
-
async function runNamespaceMaintenanceBatchPlan(config, plan, runner, catalog, options = {}) {
|
|
2060
|
-
const statuses = [];
|
|
2061
|
-
for (const skipped of plan.skipped) {
|
|
2062
|
-
if (skipped.namespace === "*") continue;
|
|
2063
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2064
|
-
const status = {
|
|
2065
|
-
namespace: skipped.namespace,
|
|
2066
|
-
jobName: plan.jobName,
|
|
2067
|
-
state: "skipped",
|
|
2068
|
-
reason: skipped.reason,
|
|
2069
|
-
startedAt: now,
|
|
2070
|
-
completedAt: now
|
|
2071
|
-
};
|
|
2072
|
-
statuses.push(status);
|
|
2073
|
-
await recordNamespaceMaintenanceStatusSafely(config, status);
|
|
2074
|
-
}
|
|
2075
|
-
const acquired = [];
|
|
2076
|
-
try {
|
|
2077
|
-
for (const candidate of plan.namespaces) {
|
|
2078
|
-
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2079
|
-
const lock = await tryAcquireNamespaceMaintenanceLock(config, plan.jobName, candidate.namespace);
|
|
2080
|
-
if (!lock) {
|
|
2081
|
-
const completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2082
|
-
const status = {
|
|
2083
|
-
namespace: candidate.namespace,
|
|
2084
|
-
jobName: plan.jobName,
|
|
2085
|
-
state: "skipped",
|
|
2086
|
-
reason: "lock_held",
|
|
2087
|
-
startedAt,
|
|
2088
|
-
completedAt
|
|
2089
|
-
};
|
|
2090
|
-
statuses.push(status);
|
|
2091
|
-
await recordNamespaceMaintenanceStatusSafely(config, status);
|
|
2092
|
-
continue;
|
|
2093
|
-
}
|
|
2094
|
-
acquired.push({ candidate, lock, startedAt });
|
|
2095
|
-
}
|
|
2096
|
-
} catch (error) {
|
|
2097
|
-
await Promise.all(acquired.map(({ lock }) => lock.release().catch(() => void 0)));
|
|
2098
|
-
throw error;
|
|
2099
|
-
}
|
|
2100
|
-
if (options.requireAllLocks && acquired.length > 0 && acquired.length < plan.namespaces.length) {
|
|
2101
|
-
for (const { candidate, startedAt } of acquired) {
|
|
2102
|
-
const completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2103
|
-
const status = {
|
|
2104
|
-
namespace: candidate.namespace,
|
|
2105
|
-
jobName: plan.jobName,
|
|
2106
|
-
state: "skipped",
|
|
2107
|
-
reason: "batch_lock_incomplete",
|
|
2108
|
-
startedAt,
|
|
2109
|
-
completedAt
|
|
2110
|
-
};
|
|
2111
|
-
statuses.push(status);
|
|
2112
|
-
await recordNamespaceMaintenanceStatusSafely(config, status);
|
|
2113
|
-
}
|
|
2114
|
-
await Promise.all(acquired.map(({ lock }) => lock.release().catch(() => void 0)));
|
|
2115
|
-
return {
|
|
2116
|
-
jobName: plan.jobName,
|
|
2117
|
-
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2118
|
-
ran: statuses.filter((s) => s.state === "ran").length,
|
|
2119
|
-
skipped: statuses.filter((s) => s.state === "skipped").length,
|
|
2120
|
-
failed: statuses.filter((s) => s.state === "failed").length,
|
|
2121
|
-
statuses
|
|
2122
|
-
};
|
|
2123
|
-
}
|
|
2124
|
-
if (acquired.length === 0) {
|
|
2125
|
-
return {
|
|
2126
|
-
jobName: plan.jobName,
|
|
2127
|
-
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2128
|
-
ran: statuses.filter((s) => s.state === "ran").length,
|
|
2129
|
-
skipped: statuses.filter((s) => s.state === "skipped").length,
|
|
2130
|
-
failed: statuses.filter((s) => s.state === "failed").length,
|
|
2131
|
-
statuses
|
|
2132
|
-
};
|
|
2133
|
-
}
|
|
2134
|
-
try {
|
|
2135
|
-
const result = await withNamespaceMaintenanceLockHeartbeat(
|
|
2136
|
-
config,
|
|
2137
|
-
acquired.map(({ lock }) => lock),
|
|
2138
|
-
() => runner(acquired.map(({ candidate }) => candidate))
|
|
2139
|
-
);
|
|
2140
|
-
for (const { candidate, startedAt } of acquired) {
|
|
2141
|
-
const completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2142
|
-
const status = {
|
|
2143
|
-
namespace: candidate.namespace,
|
|
2144
|
-
jobName: plan.jobName,
|
|
2145
|
-
state: "ran",
|
|
2146
|
-
startedAt,
|
|
2147
|
-
completedAt,
|
|
2148
|
-
itemCount: itemCountForNamespace(result, candidate.namespace)
|
|
2149
|
-
};
|
|
2150
|
-
statuses.push(status);
|
|
2151
|
-
await recordNamespaceMaintenanceStatusSafely(config, status);
|
|
2152
|
-
try {
|
|
2153
|
-
await catalog?.markMaintenance(candidate.namespace, plan.jobName, new Date(completedAt));
|
|
2154
|
-
} catch {
|
|
2155
|
-
}
|
|
2156
|
-
}
|
|
2157
|
-
} catch (error) {
|
|
2158
|
-
const skipReason = options.skipReasonForError?.(error);
|
|
2159
|
-
for (const { candidate, startedAt } of acquired) {
|
|
2160
|
-
const completedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2161
|
-
const status = skipReason ? {
|
|
2162
|
-
namespace: candidate.namespace,
|
|
2163
|
-
jobName: plan.jobName,
|
|
2164
|
-
state: "skipped",
|
|
2165
|
-
reason: skipReason,
|
|
2166
|
-
startedAt,
|
|
2167
|
-
completedAt
|
|
2168
|
-
} : {
|
|
2169
|
-
namespace: candidate.namespace,
|
|
2170
|
-
jobName: plan.jobName,
|
|
2171
|
-
state: "failed",
|
|
2172
|
-
reason: "job_failed",
|
|
2173
|
-
startedAt,
|
|
2174
|
-
completedAt,
|
|
2175
|
-
error: maintenanceErrorDetail(error)
|
|
2176
|
-
};
|
|
2177
|
-
statuses.push(status);
|
|
2178
|
-
await recordNamespaceMaintenanceStatusSafely(config, status);
|
|
2179
|
-
}
|
|
2180
|
-
} finally {
|
|
2181
|
-
await Promise.all(acquired.map(({ lock }) => lock.release().catch(() => void 0)));
|
|
2182
|
-
}
|
|
2183
|
-
return {
|
|
2184
|
-
jobName: plan.jobName,
|
|
2185
|
-
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2186
|
-
ran: statuses.filter((s) => s.state === "ran").length,
|
|
2187
|
-
skipped: statuses.filter((s) => s.state === "skipped").length,
|
|
2188
|
-
failed: statuses.filter((s) => s.state === "failed").length,
|
|
2189
|
-
statuses
|
|
2190
|
-
};
|
|
2191
|
-
}
|
|
2192
|
-
function itemCountForNamespace(result, namespace) {
|
|
2193
|
-
const itemCounts = result?.itemCounts;
|
|
2194
|
-
if (itemCounts instanceof Map) return itemCounts.get(namespace);
|
|
2195
|
-
if (itemCounts && Object.prototype.hasOwnProperty.call(itemCounts, namespace)) {
|
|
2196
|
-
return itemCounts[namespace];
|
|
2197
|
-
}
|
|
2198
|
-
return result?.itemCount;
|
|
2199
|
-
}
|
|
2200
|
-
|
|
2201
1471
|
export {
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
readNamespaceMaintenanceLastRanStatuses,
|
|
2206
|
-
runNamespaceMaintenancePlan,
|
|
2207
|
-
runNamespaceMaintenanceBatchPlan
|
|
1472
|
+
hasMemoryData,
|
|
1473
|
+
isNamespaceKind,
|
|
1474
|
+
NamespaceCatalog
|
|
2208
1475
|
};
|
|
2209
|
-
//# sourceMappingURL=chunk-
|
|
1476
|
+
//# sourceMappingURL=chunk-A4HXWNST.js.map
|