@adhdev/daemon-core 0.9.82-rc.481 → 0.9.82-rc.482
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/config/mesh-config.d.ts +5 -28
- package/dist/index.d.ts +2 -2
- package/dist/index.js +243 -246
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +243 -241
- package/dist/index.mjs.map +1 -1
- package/dist/mesh/contracts.d.ts +8 -5
- package/dist/mesh/mesh-reconcile-loop.d.ts +4 -0
- package/dist/mesh/mesh-runtime-store.d.ts +47 -2
- package/dist/mesh/mesh-unresolved-forward-outbox.d.ts +4 -0
- package/dist/repo-mesh-types.d.ts +7 -13
- package/dist/types.d.ts +15 -6
- package/package.json +3 -3
- package/src/commands/chat-commands-read.ts +81 -60
- package/src/commands/med-family/mesh-crud.ts +8 -62
- package/src/config/mesh-config.ts +9 -140
- package/src/index.ts +1 -2
- package/src/mesh/contracts.ts +17 -11
- package/src/mesh/coordinator-prompt.ts +3 -6
- package/src/mesh/mesh-event-forwarding.ts +38 -102
- package/src/mesh/mesh-reconcile-loop.ts +157 -2
- package/src/mesh/mesh-runtime-store.ts +118 -3
- package/src/mesh/mesh-unresolved-forward-outbox.ts +30 -0
- package/src/repo-mesh-types.ts +7 -13
- package/src/types.ts +21 -6
package/dist/index.mjs
CHANGED
|
@@ -404,10 +404,10 @@ function readInjected(value) {
|
|
|
404
404
|
}
|
|
405
405
|
function getDaemonBuildInfo() {
|
|
406
406
|
if (cached) return cached;
|
|
407
|
-
const commit = readInjected(true ? "
|
|
408
|
-
const commitShort = readInjected(true ? "
|
|
409
|
-
const version = readInjected(true ? "0.9.82-rc.
|
|
410
|
-
const builtAt = readInjected(true ? "2026-07-
|
|
407
|
+
const commit = readInjected(true ? "5c311ee659d4fe9b1638a1bb325b681ef6ecc24e" : void 0) ?? "unknown";
|
|
408
|
+
const commitShort = readInjected(true ? "5c311ee6" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
|
|
409
|
+
const version = readInjected(true ? "0.9.82-rc.482" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
|
|
410
|
+
const builtAt = readInjected(true ? "2026-07-08T00:15:56.441Z" : void 0);
|
|
411
411
|
cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
|
|
412
412
|
return cached;
|
|
413
413
|
}
|
|
@@ -2813,8 +2813,6 @@ var init_dist = __esm({
|
|
|
2813
2813
|
"mesh_review_inbox",
|
|
2814
2814
|
"mesh_magi_review",
|
|
2815
2815
|
"mesh_magi_collect",
|
|
2816
|
-
"mesh_magi_panel_set",
|
|
2817
|
-
"mesh_magi_panel_list",
|
|
2818
2816
|
"mesh_magi_kind_panel_set",
|
|
2819
2817
|
"mesh_magi_kind_panel_list"
|
|
2820
2818
|
];
|
|
@@ -2914,24 +2912,19 @@ __export(mesh_config_exports, {
|
|
|
2914
2912
|
createMeshHostPairingToken: () => createMeshHostPairingToken,
|
|
2915
2913
|
deleteMesh: () => deleteMesh,
|
|
2916
2914
|
getMagiKindPanel: () => getMagiKindPanel,
|
|
2917
|
-
getMagiPanel: () => getMagiPanel,
|
|
2918
2915
|
getMesh: () => getMesh,
|
|
2919
2916
|
getMeshByRepo: () => getMeshByRepo,
|
|
2920
2917
|
listMagiKindPanels: () => listMagiKindPanels,
|
|
2921
|
-
listMagiPanels: () => listMagiPanels,
|
|
2922
2918
|
listMeshes: () => listMeshes,
|
|
2923
2919
|
markMeshHostPairingJoined: () => markMeshHostPairingJoined,
|
|
2924
|
-
normalizeMagiPanel: () => normalizeMagiPanel,
|
|
2925
2920
|
normalizeMagiSlots: () => normalizeMagiSlots,
|
|
2926
2921
|
normalizeRepoIdentity: () => normalizeRepoIdentity,
|
|
2927
2922
|
removeMagiKindPanel: () => removeMagiKindPanel,
|
|
2928
|
-
removeMagiPanel: () => removeMagiPanel,
|
|
2929
2923
|
removeNode: () => removeNode,
|
|
2930
2924
|
setMagiKindPanel: () => setMagiKindPanel,
|
|
2931
2925
|
tokenIdForManualPairing: () => tokenIdForManualPairing,
|
|
2932
2926
|
updateMesh: () => updateMesh,
|
|
2933
|
-
updateNode: () => updateNode
|
|
2934
|
-
upsertMagiPanel: () => upsertMagiPanel
|
|
2927
|
+
updateNode: () => updateNode
|
|
2935
2928
|
});
|
|
2936
2929
|
import { existsSync as existsSync5, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
|
|
2937
2930
|
import { join as join5 } from "path";
|
|
@@ -3330,99 +3323,6 @@ function normalizeReplicaCount(value) {
|
|
|
3330
3323
|
const n = Math.floor(value);
|
|
3331
3324
|
return n >= 1 ? n : void 0;
|
|
3332
3325
|
}
|
|
3333
|
-
function normalizeMagiPanelDefaultKind(raw) {
|
|
3334
|
-
if (raw == null) return void 0;
|
|
3335
|
-
const s2 = typeof raw === "string" ? raw.trim().toLowerCase() : "";
|
|
3336
|
-
if (s2 === "claim_audit" || s2 === "rca" || s2 === "design") return s2;
|
|
3337
|
-
if (s2 === "freeform") {
|
|
3338
|
-
console.warn(
|
|
3339
|
-
"[magi] panel defaultKind='freeform' rejected \u2014 freeform contributes no structured claims to cross-verification; dropping (use claim_audit / rca / design, or omit)."
|
|
3340
|
-
);
|
|
3341
|
-
return void 0;
|
|
3342
|
-
}
|
|
3343
|
-
return void 0;
|
|
3344
|
-
}
|
|
3345
|
-
function normalizeMagiPanel(config) {
|
|
3346
|
-
if (!config || typeof config !== "object" || Array.isArray(config)) {
|
|
3347
|
-
throw new Error("invalid_magi_panel: config must be an object");
|
|
3348
|
-
}
|
|
3349
|
-
const raw = config;
|
|
3350
|
-
const rawMembers = raw.members;
|
|
3351
|
-
if (!Array.isArray(rawMembers) || rawMembers.length === 0) {
|
|
3352
|
-
throw new Error("invalid_magi_panel: members must be a non-empty array");
|
|
3353
|
-
}
|
|
3354
|
-
if (rawMembers.length > MAX_MAGI_PANEL_MEMBERS) {
|
|
3355
|
-
throw new Error(`invalid_magi_panel: too many members (max ${MAX_MAGI_PANEL_MEMBERS})`);
|
|
3356
|
-
}
|
|
3357
|
-
const members = rawMembers.map((entry, idx) => {
|
|
3358
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
3359
|
-
throw new Error(`invalid_magi_panel: member[${idx}] must be an object`);
|
|
3360
|
-
}
|
|
3361
|
-
const m = entry;
|
|
3362
|
-
const provider = typeof m.provider === "string" ? m.provider.trim() : "";
|
|
3363
|
-
if (!provider) {
|
|
3364
|
-
throw new Error(`invalid_magi_panel: member[${idx}].provider is required`);
|
|
3365
|
-
}
|
|
3366
|
-
const nodeId = typeof m.nodeId === "string" && m.nodeId.trim() ? m.nodeId.trim() : void 0;
|
|
3367
|
-
const model = typeof m.model === "string" && m.model.trim() ? m.model.trim() : void 0;
|
|
3368
|
-
const capabilityTags = normalizeCapabilityTags(m.capabilityTags);
|
|
3369
|
-
const n = normalizeReplicaCount(m.n);
|
|
3370
|
-
return {
|
|
3371
|
-
provider,
|
|
3372
|
-
...nodeId ? { nodeId } : {},
|
|
3373
|
-
...model ? { model } : {},
|
|
3374
|
-
...capabilityTags ? { capabilityTags } : {},
|
|
3375
|
-
...n !== void 0 ? { n } : {}
|
|
3376
|
-
};
|
|
3377
|
-
});
|
|
3378
|
-
const description = typeof raw.description === "string" && raw.description.trim() ? raw.description.trim().slice(0, 200) : void 0;
|
|
3379
|
-
const defaultN = normalizeReplicaCount(raw.defaultN);
|
|
3380
|
-
const defaultKind = normalizeMagiPanelDefaultKind(raw.defaultKind);
|
|
3381
|
-
return {
|
|
3382
|
-
...description ? { description } : {},
|
|
3383
|
-
members,
|
|
3384
|
-
...defaultN !== void 0 ? { defaultN } : {},
|
|
3385
|
-
...defaultKind !== void 0 ? { defaultKind } : {},
|
|
3386
|
-
// dedupExempt is always meaningful for a MAGI panel (intentional same-prompt
|
|
3387
|
-
// fan-out). Persist it true unless the caller explicitly disables it.
|
|
3388
|
-
dedupExempt: raw.dedupExempt === false ? false : true
|
|
3389
|
-
};
|
|
3390
|
-
}
|
|
3391
|
-
function normalizePanelName(name) {
|
|
3392
|
-
const trimmed = typeof name === "string" ? name.trim() : "";
|
|
3393
|
-
if (!trimmed) throw new Error("invalid_magi_panel: panel name is required");
|
|
3394
|
-
return trimmed.slice(0, 100);
|
|
3395
|
-
}
|
|
3396
|
-
function listMagiPanels() {
|
|
3397
|
-
return loadMeshConfig().magiPanels ?? {};
|
|
3398
|
-
}
|
|
3399
|
-
function getMagiPanel(name) {
|
|
3400
|
-
const key2 = typeof name === "string" ? name.trim() : "";
|
|
3401
|
-
if (!key2) return void 0;
|
|
3402
|
-
return loadMeshConfig().magiPanels?.[key2];
|
|
3403
|
-
}
|
|
3404
|
-
function upsertMagiPanel(name, config, opts = {}) {
|
|
3405
|
-
const key2 = normalizePanelName(name);
|
|
3406
|
-
const panel = normalizeMagiPanel(config);
|
|
3407
|
-
const stored = loadMeshConfig();
|
|
3408
|
-
const panels = stored.magiPanels ?? {};
|
|
3409
|
-
if (panels[key2] && opts.overwrite !== true) {
|
|
3410
|
-
throw new Error(`magi_panel_exists: panel '${key2}' already exists \u2014 pass overwrite=true to replace it`);
|
|
3411
|
-
}
|
|
3412
|
-
panels[key2] = panel;
|
|
3413
|
-
stored.magiPanels = panels;
|
|
3414
|
-
saveMeshConfig(stored);
|
|
3415
|
-
return panel;
|
|
3416
|
-
}
|
|
3417
|
-
function removeMagiPanel(name) {
|
|
3418
|
-
const key2 = typeof name === "string" ? name.trim() : "";
|
|
3419
|
-
if (!key2) return false;
|
|
3420
|
-
const stored = loadMeshConfig();
|
|
3421
|
-
if (!stored.magiPanels || !stored.magiPanels[key2]) return false;
|
|
3422
|
-
delete stored.magiPanels[key2];
|
|
3423
|
-
saveMeshConfig(stored);
|
|
3424
|
-
return true;
|
|
3425
|
-
}
|
|
3426
3326
|
function normalizeMagiTaskKindKey(raw) {
|
|
3427
3327
|
const s2 = typeof raw === "string" ? raw.trim().toLowerCase() : "";
|
|
3428
3328
|
if (!MAGI_KIND_PANEL_KINDS.includes(s2)) {
|
|
@@ -3494,7 +3394,7 @@ function removeMagiKindPanel(kind) {
|
|
|
3494
3394
|
saveMeshConfig(stored);
|
|
3495
3395
|
return true;
|
|
3496
3396
|
}
|
|
3497
|
-
var mergeMeshPolicy,
|
|
3397
|
+
var mergeMeshPolicy, MAGI_KIND_PANEL_KINDS, MAX_MAGI_KIND_SLOTS;
|
|
3498
3398
|
var init_mesh_config = __esm({
|
|
3499
3399
|
"src/config/mesh-config.ts"() {
|
|
3500
3400
|
"use strict";
|
|
@@ -3503,7 +3403,6 @@ var init_mesh_config = __esm({
|
|
|
3503
3403
|
init_repo_mesh_types();
|
|
3504
3404
|
init_mesh_host_ownership();
|
|
3505
3405
|
mergeMeshPolicy = mergeAndNormalizePolicy;
|
|
3506
|
-
MAX_MAGI_PANEL_MEMBERS = 24;
|
|
3507
3406
|
MAGI_KIND_PANEL_KINDS = ["claim_audit", "rca", "design", "freeform"];
|
|
3508
3407
|
MAX_MAGI_KIND_SLOTS = 24;
|
|
3509
3408
|
}
|
|
@@ -3874,9 +3773,7 @@ var init_coordinator_prompt = __esm({
|
|
|
3874
3773
|
| \`mesh_write_mesh_json_config\` | Gated write of \`.adhdev/mesh.json\` (repo coordinator-prompt config) from the mesh entry \u2014 dry-run/overwrite like mesh_init |
|
|
3875
3774
|
| \`mesh_magi_review\` | Cross-verify a read-only investigation across a standing panel of independent mesh agents (different machines/providers) instead of a single worker |
|
|
3876
3775
|
| \`mesh_magi_collect\` | Collect + synthesize a previously dispatched MAGI fan-out by its consensus group id (async companion to mesh_magi_review wait:false) |
|
|
3877
|
-
| \`
|
|
3878
|
-
| \`mesh_magi_panel_list\` | List configured MAGI panels and resolve each member's availability against the current mesh (read-only) |
|
|
3879
|
-
| \`mesh_magi_kind_panel_set\` | Bind a task_kind \u2192 MAGI kind-panel slots (machine-local, wholesale replacement \u2014 approve current-vs-new first) |
|
|
3776
|
+
| \`mesh_magi_kind_panel_set\` | Bind a task_kind \u2192 MAGI kind-panel slots (the SOLE MAGI panel-resolution surface; machine-local, wholesale replacement \u2014 approve current-vs-new first) |
|
|
3880
3777
|
| \`mesh_magi_kind_panel_list\` | List configured task_kind \u2192 MAGI kind-panel slot bindings (machine-local, read-only) |`;
|
|
3881
3778
|
TOOL_EXPOSURE_PREFLIGHT_SECTION = `## Tool Exposure Preflight
|
|
3882
3779
|
|
|
@@ -3916,7 +3813,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
3916
3813
|
|
|
3917
3814
|
**Save scopes \u2014 label every draft with its scope before asking for approval:**
|
|
3918
3815
|
- **repo-file (commit target)** \u2014 \`.adhdev/refine.json\`, \`.adhdev/worktree_bootstrap.json\`, \`.adhdev/change-impact.json\`, \`.adhdev/mesh.json\`. These are committed to the repository and shared with every machine/contributor.
|
|
3919
|
-
- **machine-local** \u2014 MAGI kind\u2192panel bindings
|
|
3816
|
+
- **machine-local** \u2014 MAGI kind\u2192panel bindings, node providerPriority (\`~/.adhdev/meshes.json\`). These stay on this machine and are NOT committed.
|
|
3920
3817
|
|
|
3921
3818
|
**Guided sequence:**
|
|
3922
3819
|
1. **Scan (dry-run)** \u2014 Call \`mesh_init\` (write=false, the default). It returns per-domain suggested configs for refine / worktree_bootstrap / change-impact, a recommended providerPriority, AND \`currentConfig\` \u2014 the currently-saved config per domain (repo files + machine-local \`magiKindPanels\`). Nothing is written.
|
|
@@ -3924,8 +3821,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
|
|
|
3924
3821
|
3. **Approve \u2192 gated write** \u2014 Only after the user approves, call the matching gated-write tool:
|
|
3925
3822
|
- repo \`.adhdev/*\` config files \u2192 \`mesh_init\` with \`write=true\` (and \`overwrite=true\` ONLY for domains the user approved replacing).
|
|
3926
3823
|
- \`.adhdev/mesh.json\` (coordinator prompt / operating notes) \u2192 \`mesh_write_mesh_json_config\` (write=true, overwrite only if approved).
|
|
3927
|
-
- machine-local MAGI kind\u2192panel slots \u2192 \`mesh_magi_kind_panel_set\` (write=true). NOTE: a kind binding is a **wholesale replacement** of that kind's slot list \u2014 present the current-vs-new slots first.
|
|
3928
|
-
- machine-local named MAGI panels \u2192 \`mesh_magi_panel_set\`. providerPriority \u2192 apply via node policy update.
|
|
3824
|
+
- machine-local MAGI kind\u2192panel slots \u2192 \`mesh_magi_kind_panel_set\` (write=true). NOTE: a kind binding is a **wholesale replacement** of that kind's slot list \u2014 present the current-vs-new slots first. providerPriority \u2192 apply via node policy update.
|
|
3929
3825
|
|
|
3930
3826
|
**init vs reinit:**
|
|
3931
3827
|
- **\`mesh_init\`** \u2014 for a fresh, never-onboarded repo. Existing config files are kept (existing-wins) unless the user explicitly approves overwrite. Use for first-time setup.
|
|
@@ -4339,8 +4235,7 @@ function shouldDeliverPendingEventToCoordinator(event, drainer) {
|
|
|
4339
4235
|
return coordinatorIdentityEquals(event.intendedFor, drainer);
|
|
4340
4236
|
}
|
|
4341
4237
|
function defaultScopeForEvent(eventName) {
|
|
4342
|
-
if (
|
|
4343
|
-
if (TERMINAL_TASK_EVENTS.has(eventName)) return "unicast";
|
|
4238
|
+
if (TERMINAL_TASK_EVENTS.has(eventName) || COORDINATOR_ALERT_EVENTS.has(eventName)) return "unicast";
|
|
4344
4239
|
return "broadcast";
|
|
4345
4240
|
}
|
|
4346
4241
|
function coordinatorIdentityFromEmitFields(fields) {
|
|
@@ -4366,7 +4261,7 @@ function buildPendingEventEmitStamp(opts) {
|
|
|
4366
4261
|
...intendedFor ? { intendedFor } : {}
|
|
4367
4262
|
};
|
|
4368
4263
|
}
|
|
4369
|
-
var MESH_PROTOCOL_VERSION_V1, MESH_PROTOCOL_VERSION_V2, SUPPORTED_MESH_PROTOCOL_VERSIONS, MESH_EVENT_SCOPES, MeshContractViolationError, TERMINAL_TASK_EVENTS,
|
|
4264
|
+
var MESH_PROTOCOL_VERSION_V1, MESH_PROTOCOL_VERSION_V2, SUPPORTED_MESH_PROTOCOL_VERSIONS, MESH_EVENT_SCOPES, MeshContractViolationError, TERMINAL_TASK_EVENTS, COORDINATOR_ALERT_EVENTS;
|
|
4370
4265
|
var init_contracts = __esm({
|
|
4371
4266
|
"src/mesh/contracts.ts"() {
|
|
4372
4267
|
"use strict";
|
|
@@ -4395,7 +4290,7 @@ var init_contracts = __esm({
|
|
|
4395
4290
|
"refine:failed",
|
|
4396
4291
|
"refine:accepted"
|
|
4397
4292
|
]);
|
|
4398
|
-
|
|
4293
|
+
COORDINATOR_ALERT_EVENTS = /* @__PURE__ */ new Set([
|
|
4399
4294
|
"mesh:dispatch_blocked"
|
|
4400
4295
|
]);
|
|
4401
4296
|
}
|
|
@@ -6349,7 +6244,22 @@ function meshRuntimeStorePath() {
|
|
|
6349
6244
|
}
|
|
6350
6245
|
return nextPath;
|
|
6351
6246
|
}
|
|
6352
|
-
|
|
6247
|
+
function pruneMeshRuntimeRetention() {
|
|
6248
|
+
try {
|
|
6249
|
+
const store = MeshRuntimeStore.getInstance();
|
|
6250
|
+
const ledger = store.pruneEventLedger(MESH_EVENT_LEDGER_RETENTION_MS);
|
|
6251
|
+
const toolCalls = store.pruneToolCallLog(MESH_TOOL_CALL_LOG_RETENTION_MS);
|
|
6252
|
+
const terminalQueue = store.pruneTerminalQueueEntries(MESH_TERMINAL_QUEUE_RETENTION_MS);
|
|
6253
|
+
if (ledger + toolCalls + terminalQueue > 0) {
|
|
6254
|
+
LOG.info("MeshRuntimeStore", `Retention prune removed ${ledger} ledger / ${toolCalls} tool-call / ${terminalQueue} terminal-queue row(s)`);
|
|
6255
|
+
}
|
|
6256
|
+
return { ledger, toolCalls, terminalQueue };
|
|
6257
|
+
} catch (e) {
|
|
6258
|
+
LOG.warn("MeshRuntimeStore", `Runtime retention prune failed: ${e?.message || e}`);
|
|
6259
|
+
return { ledger: 0, toolCalls: 0, terminalQueue: 0 };
|
|
6260
|
+
}
|
|
6261
|
+
}
|
|
6262
|
+
var DatabaseCtor, loggedMigrationFailure, loggedStrayCleanup, MeshRuntimeStore, MESH_EVENT_LEDGER_RETENTION_MS, MESH_TOOL_CALL_LOG_RETENTION_MS, MESH_TERMINAL_QUEUE_RETENTION_MS;
|
|
6353
6263
|
var init_mesh_runtime_store = __esm({
|
|
6354
6264
|
"src/mesh/mesh-runtime-store.ts"() {
|
|
6355
6265
|
"use strict";
|
|
@@ -7459,10 +7369,79 @@ var init_mesh_runtime_store = __esm({
|
|
|
7459
7369
|
}
|
|
7460
7370
|
/**
|
|
7461
7371
|
* Prune tool call log entries older than the given age in ms.
|
|
7462
|
-
*
|
|
7372
|
+
* Returns the number of rows deleted. Also used by the periodic retention
|
|
7373
|
+
* sweep (pruneMeshRuntimeRetention) — the in-write sweep in recordMeshToolCall
|
|
7374
|
+
* only fires every 200 calls and only covers the rate-limit window, so a
|
|
7375
|
+
* quiet mesh otherwise accumulates rows indefinitely.
|
|
7463
7376
|
*/
|
|
7464
7377
|
pruneToolCallLog(olderThanMs) {
|
|
7465
|
-
this.db.prepare("DELETE FROM mesh_tool_call_log WHERE called_at < ?").run(Date.now() - olderThanMs);
|
|
7378
|
+
return this.db.prepare("DELETE FROM mesh_tool_call_log WHERE called_at < ?").run(Date.now() - olderThanMs).changes;
|
|
7379
|
+
}
|
|
7380
|
+
/**
|
|
7381
|
+
* Retention prune for mesh_event_ledger (SoT 1-11 (b)). The ledger is append-only
|
|
7382
|
+
* with NO lifecycle GC of its own, so lifecycle events accumulate without bound
|
|
7383
|
+
* (the dominant mesh-runtime.db growth). Every production reader is bounded to a
|
|
7384
|
+
* recent window (readLedgerEntries tail/limit ≤ a few hundred; task-stats /
|
|
7385
|
+
* terminal-evidence scans look at recent tasks), so rows past a generous age only
|
|
7386
|
+
* cost space. Excluded from deletion — retained forever:
|
|
7387
|
+
* - coordinator_operating_note / _tombstone: runtime-accumulated lessons whose
|
|
7388
|
+
* whole point is surviving restarts; a tombstone must also outlive the notes
|
|
7389
|
+
* it retracts.
|
|
7390
|
+
* Timestamps are ISO-8601 TEXT, so the lexicographic `<` cutoff is a correct time
|
|
7391
|
+
* comparison; a malformed timestamp compares greater than any ISO date and is
|
|
7392
|
+
* conservatively retained. Returns rows deleted.
|
|
7393
|
+
*/
|
|
7394
|
+
pruneEventLedger(olderThanMs) {
|
|
7395
|
+
const cutoffIso = new Date(Date.now() - Math.max(0, olderThanMs)).toISOString();
|
|
7396
|
+
return this.db.prepare(
|
|
7397
|
+
`DELETE FROM mesh_event_ledger
|
|
7398
|
+
WHERE timestamp < ?
|
|
7399
|
+
AND kind NOT IN ('coordinator_operating_note', 'coordinator_operating_note_tombstone')`
|
|
7400
|
+
).run(cutoffIso).changes;
|
|
7401
|
+
}
|
|
7402
|
+
/**
|
|
7403
|
+
* Retention prune for TERMINAL (completed/cancelled/failed) mesh_queue rows
|
|
7404
|
+
* (SoT 1-11 (b)). Terminal rows are kept as recent history (mesh_task_history,
|
|
7405
|
+
* completion-dedup taskId lookups) but nothing ever deletes them, so the queue
|
|
7406
|
+
* table grows monotonically. Rows past the retention window serve no reader —
|
|
7407
|
+
* every dedup/attribution path operates on recent tasks — EXCEPT as a dependency
|
|
7408
|
+
* anchor: taskDependenciesSatisfied resolves dependsOn by id and treats a MISSING
|
|
7409
|
+
* row as not-completed, so deleting a completed row that a still-live
|
|
7410
|
+
* (pending/assigned) row depends on would permanently strand the dependent.
|
|
7411
|
+
* Those ids are collected first and excluded. Returns rows deleted.
|
|
7412
|
+
*/
|
|
7413
|
+
pruneTerminalQueueEntries(olderThanMs) {
|
|
7414
|
+
const cutoffIso = new Date(Date.now() - Math.max(0, olderThanMs)).toISOString();
|
|
7415
|
+
return this.transaction(() => {
|
|
7416
|
+
const liveRows = this.db.prepare(
|
|
7417
|
+
`SELECT payload FROM mesh_queue WHERE status IN ('pending', 'assigned')`
|
|
7418
|
+
).all();
|
|
7419
|
+
const protectedIds = /* @__PURE__ */ new Set();
|
|
7420
|
+
for (const row of liveRows) {
|
|
7421
|
+
try {
|
|
7422
|
+
const entry = JSON.parse(row.payload);
|
|
7423
|
+
if (Array.isArray(entry.dependsOn)) {
|
|
7424
|
+
for (const dep of entry.dependsOn) {
|
|
7425
|
+
if (typeof dep === "string" && dep) protectedIds.add(dep);
|
|
7426
|
+
}
|
|
7427
|
+
}
|
|
7428
|
+
} catch {
|
|
7429
|
+
}
|
|
7430
|
+
}
|
|
7431
|
+
const candidates = this.db.prepare(
|
|
7432
|
+
`SELECT id FROM mesh_queue
|
|
7433
|
+
WHERE status IN ('completed', 'cancelled', 'failed') AND updated_at < ?`
|
|
7434
|
+
).all(cutoffIso);
|
|
7435
|
+
const deletable = candidates.map((r) => r.id).filter((id) => !protectedIds.has(id));
|
|
7436
|
+
let removed = 0;
|
|
7437
|
+
for (let i = 0; i < deletable.length; i += 500) {
|
|
7438
|
+
const chunk = deletable.slice(i, i + 500);
|
|
7439
|
+
removed += this.db.prepare(
|
|
7440
|
+
`DELETE FROM mesh_queue WHERE id IN (${chunk.map(() => "?").join(",")})`
|
|
7441
|
+
).run(...chunk).changes;
|
|
7442
|
+
}
|
|
7443
|
+
return removed;
|
|
7444
|
+
});
|
|
7466
7445
|
}
|
|
7467
7446
|
// ── G2: Event Ledger ────────────────────────────────────────────────────
|
|
7468
7447
|
appendLedgerEntry(entry) {
|
|
@@ -7948,6 +7927,9 @@ var init_mesh_runtime_store = __esm({
|
|
|
7948
7927
|
return removed;
|
|
7949
7928
|
}
|
|
7950
7929
|
};
|
|
7930
|
+
MESH_EVENT_LEDGER_RETENTION_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
7931
|
+
MESH_TOOL_CALL_LOG_RETENTION_MS = 14 * 24 * 60 * 60 * 1e3;
|
|
7932
|
+
MESH_TERMINAL_QUEUE_RETENTION_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
7951
7933
|
}
|
|
7952
7934
|
});
|
|
7953
7935
|
|
|
@@ -16570,6 +16552,15 @@ function getStore() {
|
|
|
16570
16552
|
return void 0;
|
|
16571
16553
|
}
|
|
16572
16554
|
}
|
|
16555
|
+
function registerUnresolvedForwardRetryNudge(handler) {
|
|
16556
|
+
retryNudgeHandler = handler;
|
|
16557
|
+
}
|
|
16558
|
+
function nudgeUnresolvedForwardRetry() {
|
|
16559
|
+
try {
|
|
16560
|
+
retryNudgeHandler?.();
|
|
16561
|
+
} catch {
|
|
16562
|
+
}
|
|
16563
|
+
}
|
|
16573
16564
|
function enqueueUnresolvedDelegateForward(coordinatorDaemonId, eventName, forwardPayload) {
|
|
16574
16565
|
const target = readNonEmptyString2(coordinatorDaemonId);
|
|
16575
16566
|
const event = readNonEmptyString2(eventName);
|
|
@@ -16653,7 +16644,7 @@ function expireStaleUnresolvedDelegateForwards(nowMs = Date.now()) {
|
|
|
16653
16644
|
return 0;
|
|
16654
16645
|
}
|
|
16655
16646
|
}
|
|
16656
|
-
var UNRESOLVED_FORWARD_OUTBOX_MESH_ID, UNRESOLVED_FORWARD_MAX_AGE_MS;
|
|
16647
|
+
var UNRESOLVED_FORWARD_OUTBOX_MESH_ID, UNRESOLVED_FORWARD_MAX_AGE_MS, retryNudgeHandler;
|
|
16657
16648
|
var init_mesh_unresolved_forward_outbox = __esm({
|
|
16658
16649
|
"src/mesh/mesh-unresolved-forward-outbox.ts"() {
|
|
16659
16650
|
"use strict";
|
|
@@ -19044,6 +19035,7 @@ function sweepExpiredRemoteIdleSessions() {
|
|
|
19044
19035
|
if (now - lastPendingEventsPruneAt >= PENDING_EVENTS_PRUNE_INTERVAL_MS) {
|
|
19045
19036
|
lastPendingEventsPruneAt = now;
|
|
19046
19037
|
prunePendingMeshCoordinatorEventsRetention();
|
|
19038
|
+
pruneMeshRuntimeRetention();
|
|
19047
19039
|
}
|
|
19048
19040
|
}
|
|
19049
19041
|
function isIntentionalCleanupStopMetadata(event) {
|
|
@@ -19900,25 +19892,6 @@ function handleMeshForwardEvent(components, payload) {
|
|
|
19900
19892
|
v2Envelope: readV2EnvelopeFromWire(payload)
|
|
19901
19893
|
});
|
|
19902
19894
|
}
|
|
19903
|
-
function enqueueCoordinatorForwardPush(coordinatorDaemonId, run) {
|
|
19904
|
-
let lane = coordinatorForwardLanes.get(coordinatorDaemonId);
|
|
19905
|
-
if (!lane) {
|
|
19906
|
-
lane = { tail: Promise.resolve(), depth: 0 };
|
|
19907
|
-
coordinatorForwardLanes.set(coordinatorDaemonId, lane);
|
|
19908
|
-
}
|
|
19909
|
-
const wasIdle = lane.depth === 0;
|
|
19910
|
-
lane.depth += 1;
|
|
19911
|
-
const dec = () => {
|
|
19912
|
-
lane.depth -= 1;
|
|
19913
|
-
};
|
|
19914
|
-
if (wasIdle) {
|
|
19915
|
-
lane.tail = Promise.resolve(run()).catch(() => {
|
|
19916
|
-
}).then(dec, dec);
|
|
19917
|
-
} else {
|
|
19918
|
-
lane.tail = lane.tail.then(() => run()).catch(() => {
|
|
19919
|
-
}).then(dec, dec);
|
|
19920
|
-
}
|
|
19921
|
-
}
|
|
19922
19895
|
function forwardUnresolvedDelegateEvent(components, routing, event) {
|
|
19923
19896
|
const coordinatorDaemonId = readNonEmptyString2(routing.coordinatorDaemonId);
|
|
19924
19897
|
if (!coordinatorDaemonId) return false;
|
|
@@ -19955,28 +19928,15 @@ function forwardUnresolvedDelegateEvent(components, routing, event) {
|
|
|
19955
19928
|
nodeId: readNonEmptyString2(routing.nodeId) || readNonEmptyString2(event.meshNodeId),
|
|
19956
19929
|
event: eventName
|
|
19957
19930
|
};
|
|
19958
|
-
|
|
19959
|
-
|
|
19960
|
-
|
|
19961
|
-
|
|
19962
|
-
|
|
19963
|
-
|
|
19964
|
-
|
|
19965
|
-
return;
|
|
19966
|
-
}
|
|
19967
|
-
if (persisted) ackUnresolvedDelegateForwardByFingerprint(coordinatorDaemonId, eventName, payload);
|
|
19968
|
-
}).catch((e) => {
|
|
19969
|
-
LOG.warn("MeshEvents", `Immediate forward of ${eventName} to coordinator ${coordinatorDaemonId} failed: ${e?.message || e} \u2014 left queued for retry`);
|
|
19970
|
-
}));
|
|
19971
|
-
LOG.info("MeshEvents", `Durably forwarded ${eventName} for unresolved-mesh worker at ${routing.workspace || "(no workspace)"} to coordinator daemon ${coordinatorDaemonId}`);
|
|
19931
|
+
if (!persisted) {
|
|
19932
|
+
traceMeshEventDrop("outbox_enqueue_failed", fwdTraceCtx, `coordinatorDaemon=${coordinatorDaemonId}`);
|
|
19933
|
+
return false;
|
|
19934
|
+
}
|
|
19935
|
+
traceMeshEventStage("outbox_enqueue", fwdTraceCtx, `coordinatorDaemon=${coordinatorDaemonId} meshId=${readNonEmptyString2(payload.meshId) || "absent"}`);
|
|
19936
|
+
nudgeUnresolvedForwardRetry();
|
|
19937
|
+
LOG.info("MeshEvents", `Durably queued ${eventName} for unresolved-mesh worker at ${routing.workspace || "(no workspace)"} to coordinator daemon ${coordinatorDaemonId} (reconcile PHASE 0 delivers)`);
|
|
19972
19938
|
return true;
|
|
19973
19939
|
}
|
|
19974
|
-
function ackUnresolvedDelegateForwardByFingerprint(coordinatorDaemonId, eventName, payload) {
|
|
19975
|
-
const match = peekUnresolvedDelegateForwards().find(
|
|
19976
|
-
(entry) => daemonIdsEquivalent(entry.coordinatorDaemonId, coordinatorDaemonId) && readNonEmptyString2(entry.payload.event) === eventName && readNonEmptyString2(entry.payload.targetSessionId || entry.payload.sessionId || entry.payload.instanceId) === readNonEmptyString2(payload.targetSessionId || payload.sessionId || payload.instanceId) && readNonEmptyString2(entry.payload.workspace) === readNonEmptyString2(payload.workspace)
|
|
19977
|
-
);
|
|
19978
|
-
if (match) ackUnresolvedDelegateForward(match.id);
|
|
19979
|
-
}
|
|
19980
19940
|
function flushPendingForMeshIdleCoordinators(components, meshId) {
|
|
19981
19941
|
try {
|
|
19982
19942
|
const store = MeshRuntimeStore.getInstance();
|
|
@@ -20109,7 +20069,7 @@ function setupMeshEventForwarding(components) {
|
|
|
20109
20069
|
flushPendingForMeshIdleCoordinators(components, routing.meshId);
|
|
20110
20070
|
});
|
|
20111
20071
|
}
|
|
20112
|
-
var REMOTE_IDLE_SESSION_TTL_MS, meshByWorkspaceCache, MESH_WORKSPACE_CACHE_TTL_MS, lastPendingEventsPruneAt, PENDING_EVENTS_PRUNE_INTERVAL_MS, INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS, RECENT_COMPLETION_FINGERPRINT_TTL_MS, RECONCILED_COMPLETION_SOURCES
|
|
20072
|
+
var REMOTE_IDLE_SESSION_TTL_MS, meshByWorkspaceCache, MESH_WORKSPACE_CACHE_TTL_MS, lastPendingEventsPruneAt, PENDING_EVENTS_PRUNE_INTERVAL_MS, INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS, RECENT_COMPLETION_FINGERPRINT_TTL_MS, RECONCILED_COMPLETION_SOURCES;
|
|
20113
20073
|
var init_mesh_event_forwarding = __esm({
|
|
20114
20074
|
"src/mesh/mesh-event-forwarding.ts"() {
|
|
20115
20075
|
"use strict";
|
|
@@ -20146,7 +20106,6 @@ var init_mesh_event_forwarding = __esm({
|
|
|
20146
20106
|
"mcp_mesh_status_transcript_reconciliation",
|
|
20147
20107
|
"no_progress_reconciliation"
|
|
20148
20108
|
]);
|
|
20149
|
-
coordinatorForwardLanes = /* @__PURE__ */ new Map();
|
|
20150
20109
|
}
|
|
20151
20110
|
});
|
|
20152
20111
|
|
|
@@ -21125,6 +21084,65 @@ function recoverStrandedAssignedDispatches(components, meshId, store) {
|
|
|
21125
21084
|
}
|
|
21126
21085
|
}
|
|
21127
21086
|
}
|
|
21087
|
+
function reconcileZombieAssignedTasks(components, mesh, selfIds) {
|
|
21088
|
+
const meshId = mesh.id;
|
|
21089
|
+
const assigned = getQueue(meshId, { status: ["assigned"] });
|
|
21090
|
+
if (!assigned.length) return;
|
|
21091
|
+
const nowMs = Date.now();
|
|
21092
|
+
const assignedNodeIsLocal = (assignedNodeId) => {
|
|
21093
|
+
if (!assignedNodeId) return true;
|
|
21094
|
+
if (selfIds.some((id) => daemonIdsEquivalent(id, assignedNodeId))) return true;
|
|
21095
|
+
const nodes = Array.isArray(mesh.nodes) ? mesh.nodes : [];
|
|
21096
|
+
const node = nodes.find((n) => meshNodeIdMatches(n, assignedNodeId));
|
|
21097
|
+
const nodeDaemonId = readNonEmptyString2(node?.daemonId);
|
|
21098
|
+
return !!nodeDaemonId && selfIds.some((id) => daemonIdsEquivalent(id, nodeDaemonId));
|
|
21099
|
+
};
|
|
21100
|
+
for (const row of assigned) {
|
|
21101
|
+
if (Number.isFinite(Date.parse(row.dispatchTimestamp ?? ""))) continue;
|
|
21102
|
+
const updatedMs = Date.parse(row.updatedAt ?? "");
|
|
21103
|
+
const createdMs = Date.parse(row.createdAt ?? "");
|
|
21104
|
+
const anchorMs = Number.isFinite(updatedMs) ? updatedMs : createdMs;
|
|
21105
|
+
if (!Number.isFinite(anchorMs)) continue;
|
|
21106
|
+
if (nowMs - anchorMs < ZOMBIE_ASSIGNED_MIN_AGE_MS) continue;
|
|
21107
|
+
const terminal = findTerminalLedgerEvidenceForTask({ meshId, taskId: row.id });
|
|
21108
|
+
if (terminal) {
|
|
21109
|
+
const status = terminal.kind === "task_completed" ? "completed" : "failed";
|
|
21110
|
+
updateTaskStatus(meshId, row.id, status);
|
|
21111
|
+
LOG.warn("MeshReconcile", `Zombie assigned task ${row.id} on mesh ${meshId} had ${terminal.kind} ledger evidence \u2014 flipped to ${status}`);
|
|
21112
|
+
continue;
|
|
21113
|
+
}
|
|
21114
|
+
if (!assignedNodeIsLocal(row.assignedNodeId)) continue;
|
|
21115
|
+
if (row.assignedSessionId) {
|
|
21116
|
+
const verdict = resolveSessionBusyVerdict(components, row.assignedSessionId);
|
|
21117
|
+
if (verdict !== "UNKNOWN") continue;
|
|
21118
|
+
}
|
|
21119
|
+
const reason = row.assignedSessionId ? "assigned_zombie_session_missing" : "assigned_zombie_no_session_bound";
|
|
21120
|
+
const failed = updateTaskStatus(meshId, row.id, "failed");
|
|
21121
|
+
if (!failed) continue;
|
|
21122
|
+
try {
|
|
21123
|
+
appendLedgerEntry(meshId, {
|
|
21124
|
+
kind: "task_failed",
|
|
21125
|
+
nodeId: row.assignedNodeId,
|
|
21126
|
+
sessionId: row.assignedSessionId,
|
|
21127
|
+
payload: {
|
|
21128
|
+
taskId: row.id,
|
|
21129
|
+
reason,
|
|
21130
|
+
source: "reconcile_zombie_assigned_sweep",
|
|
21131
|
+
ageMs: nowMs - anchorMs
|
|
21132
|
+
}
|
|
21133
|
+
});
|
|
21134
|
+
} catch {
|
|
21135
|
+
}
|
|
21136
|
+
LOG.warn("MeshReconcile", `Failed zombie assigned task ${row.id} on mesh ${meshId} (node=${row.assignedNodeId ?? "?"} session=${row.assignedSessionId ?? "?"}, no dispatchTimestamp, stale ${Math.round((nowMs - anchorMs) / 6e4)}m, ${reason})`);
|
|
21137
|
+
traceMeshEventDrop("assigned_zombie_failed", {
|
|
21138
|
+
taskId: row.id,
|
|
21139
|
+
sessionId: row.assignedSessionId,
|
|
21140
|
+
nodeId: row.assignedNodeId,
|
|
21141
|
+
meshId,
|
|
21142
|
+
event: "agent:generating_completed"
|
|
21143
|
+
}, `${reason} stale=${Math.round((nowMs - anchorMs) / 6e4)}m`);
|
|
21144
|
+
}
|
|
21145
|
+
}
|
|
21128
21146
|
async function runMeshReconcileTick(components) {
|
|
21129
21147
|
const localDaemonId = readNonEmptyString2(loadConfig().machineId) || void 0;
|
|
21130
21148
|
const drainDaemonIds = resolveCoordinatorDaemonIds(components);
|
|
@@ -21163,6 +21181,11 @@ async function runMeshReconcileTick(components) {
|
|
|
21163
21181
|
} catch (e) {
|
|
21164
21182
|
LOG.warn("MeshReconcile", `Assigned-stranded watchdog failed for mesh ${mesh.id}: ${e?.message || e}`);
|
|
21165
21183
|
}
|
|
21184
|
+
try {
|
|
21185
|
+
reconcileZombieAssignedTasks(components, mesh, selfIds);
|
|
21186
|
+
} catch (e) {
|
|
21187
|
+
LOG.warn("MeshReconcile", `Assigned-zombie sweep failed for mesh ${mesh.id}: ${e?.message || e}`);
|
|
21188
|
+
}
|
|
21166
21189
|
}
|
|
21167
21190
|
}
|
|
21168
21191
|
for (const mesh of listMeshes()) {
|
|
@@ -21384,6 +21407,25 @@ function holdOrExpireStrictUnmatchedEvent(pending, wantSession, meshId) {
|
|
|
21384
21407
|
LOG.warn("MeshReconcile", `Failed to ledger-expire strict-unmatched ${pending.event} for mesh ${meshId}: ${e?.message || e}`);
|
|
21385
21408
|
}
|
|
21386
21409
|
}
|
|
21410
|
+
function scheduleUnresolvedForwardNudge(components) {
|
|
21411
|
+
if (!components.dispatchMeshCommand) return;
|
|
21412
|
+
if (unresolvedForwardNudgeTimer) return;
|
|
21413
|
+
unresolvedForwardNudgeTimer = setTimeout(() => {
|
|
21414
|
+
unresolvedForwardNudgeTimer = void 0;
|
|
21415
|
+
if (unresolvedForwardNudgeRunning) return;
|
|
21416
|
+
unresolvedForwardNudgeRunning = true;
|
|
21417
|
+
void retryUnresolvedDelegateForwards(components).catch((e) => LOG.warn("MeshReconcile", `Nudged unresolved-forward retry failed: ${e?.message || e}`)).finally(() => {
|
|
21418
|
+
unresolvedForwardNudgeRunning = false;
|
|
21419
|
+
});
|
|
21420
|
+
}, UNRESOLVED_FORWARD_NUDGE_DELAY_MS);
|
|
21421
|
+
if (typeof unresolvedForwardNudgeTimer.unref === "function") unresolvedForwardNudgeTimer.unref();
|
|
21422
|
+
}
|
|
21423
|
+
function clearUnresolvedForwardNudge() {
|
|
21424
|
+
if (unresolvedForwardNudgeTimer) {
|
|
21425
|
+
clearTimeout(unresolvedForwardNudgeTimer);
|
|
21426
|
+
unresolvedForwardNudgeTimer = void 0;
|
|
21427
|
+
}
|
|
21428
|
+
}
|
|
21387
21429
|
async function retryUnresolvedDelegateForwards(components) {
|
|
21388
21430
|
const dispatchMeshCommand = components.dispatchMeshCommand;
|
|
21389
21431
|
if (!dispatchMeshCommand) return;
|
|
@@ -21468,15 +21510,18 @@ function setupMeshReconcileLoop(components) {
|
|
|
21468
21510
|
});
|
|
21469
21511
|
}, intervalMs);
|
|
21470
21512
|
if (typeof timer.unref === "function") timer.unref();
|
|
21513
|
+
registerUnresolvedForwardRetryNudge(() => scheduleUnresolvedForwardNudge(components));
|
|
21471
21514
|
LOG.info("MeshReconcile", `Mesh reconcile loop started (interval ${intervalMs}ms)`);
|
|
21472
21515
|
return {
|
|
21473
21516
|
stop() {
|
|
21474
21517
|
clearInterval(timer);
|
|
21518
|
+
registerUnresolvedForwardRetryNudge(void 0);
|
|
21519
|
+
clearUnresolvedForwardNudge();
|
|
21475
21520
|
LOG.info("MeshReconcile", "Mesh reconcile loop stopped");
|
|
21476
21521
|
}
|
|
21477
21522
|
};
|
|
21478
21523
|
}
|
|
21479
|
-
var coordinatorModalParkState, heldEventLedgerRecorded, ASSIGNED_STRANDED_DEADLINE_MS, DELIVERED_NO_TURN_DEADLINE_MS, RECLAIM_UNKNOWN_GRACE_TICKS, deliveredNoTurnUnknownStreak, STRICT_SESSION_MATCH_TTL_MS, unresolvedForwardRejectionCounts, MAX_FORWARD_REJECTIONS;
|
|
21524
|
+
var coordinatorModalParkState, heldEventLedgerRecorded, ASSIGNED_STRANDED_DEADLINE_MS, DELIVERED_NO_TURN_DEADLINE_MS, RECLAIM_UNKNOWN_GRACE_TICKS, deliveredNoTurnUnknownStreak, ZOMBIE_ASSIGNED_MIN_AGE_MS, STRICT_SESSION_MATCH_TTL_MS, unresolvedForwardRejectionCounts, MAX_FORWARD_REJECTIONS, UNRESOLVED_FORWARD_NUDGE_DELAY_MS, unresolvedForwardNudgeTimer, unresolvedForwardNudgeRunning;
|
|
21480
21525
|
var init_mesh_reconcile_loop = __esm({
|
|
21481
21526
|
"src/mesh/mesh-reconcile-loop.ts"() {
|
|
21482
21527
|
"use strict";
|
|
@@ -21508,9 +21553,12 @@ var init_mesh_reconcile_loop = __esm({
|
|
|
21508
21553
|
DELIVERED_NO_TURN_DEADLINE_MS = 15 * 6e4;
|
|
21509
21554
|
RECLAIM_UNKNOWN_GRACE_TICKS = 3;
|
|
21510
21555
|
deliveredNoTurnUnknownStreak = /* @__PURE__ */ new Map();
|
|
21556
|
+
ZOMBIE_ASSIGNED_MIN_AGE_MS = 30 * 60 * 1e3;
|
|
21511
21557
|
STRICT_SESSION_MATCH_TTL_MS = 6e4;
|
|
21512
21558
|
unresolvedForwardRejectionCounts = /* @__PURE__ */ new Map();
|
|
21513
21559
|
MAX_FORWARD_REJECTIONS = 5;
|
|
21560
|
+
UNRESOLVED_FORWARD_NUDGE_DELAY_MS = 250;
|
|
21561
|
+
unresolvedForwardNudgeRunning = false;
|
|
21514
21562
|
}
|
|
21515
21563
|
});
|
|
21516
21564
|
|
|
@@ -34195,6 +34243,16 @@ function isRuntimeFallbackHistorySessionId(candidateHistorySessionId, targetSess
|
|
|
34195
34243
|
const candidate = typeof candidateHistorySessionId === "string" ? candidateHistorySessionId.trim() : "";
|
|
34196
34244
|
return candidate === target;
|
|
34197
34245
|
}
|
|
34246
|
+
function resolveNativeHistoryReadSession(args, candidateHistorySessionId) {
|
|
34247
|
+
const targetSid = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
|
|
34248
|
+
const explicitHistorySessionId = getExplicitHistorySessionId(args);
|
|
34249
|
+
const isRuntimeFallback = Boolean(
|
|
34250
|
+
targetSid && isRuntimeFallbackHistorySessionId(candidateHistorySessionId, targetSid) && (!explicitHistorySessionId || isRuntimeFallbackHistorySessionId(explicitHistorySessionId, targetSid))
|
|
34251
|
+
);
|
|
34252
|
+
const pinnedProviderSessionId = getBoundProviderSessionIdPin(args?.targetSessionId);
|
|
34253
|
+
const effectiveHistorySessionId = isRuntimeFallback ? pinnedProviderSessionId || void 0 : candidateHistorySessionId;
|
|
34254
|
+
return { isRuntimeFallback, pinnedProviderSessionId, effectiveHistorySessionId };
|
|
34255
|
+
}
|
|
34198
34256
|
function getHistorySessionId(h, args) {
|
|
34199
34257
|
const explicit = getExplicitHistorySessionId(args);
|
|
34200
34258
|
if (explicit) return explicit;
|
|
@@ -35029,13 +35087,11 @@ async function handleChatHistory(h, args) {
|
|
|
35029
35087
|
if (visibleCount > excludeRecentCount) excludeRecentCount = visibleCount;
|
|
35030
35088
|
}
|
|
35031
35089
|
const workspace = typeof args?.workspace === "string" ? args.workspace : typeof h.currentSession?.workspace === "string" ? h.currentSession.workspace : void 0;
|
|
35032
|
-
const
|
|
35033
|
-
|
|
35034
|
-
|
|
35035
|
-
|
|
35036
|
-
);
|
|
35037
|
-
const pinnedProviderSessionIdForHistory = getBoundProviderSessionIdPin(args?.targetSessionId);
|
|
35038
|
-
const effectiveHistorySessionId = historySessionIdIsRuntimeFallback ? pinnedProviderSessionIdForHistory || void 0 : historySessionId;
|
|
35090
|
+
const {
|
|
35091
|
+
isRuntimeFallback: historySessionIdIsRuntimeFallback,
|
|
35092
|
+
pinnedProviderSessionId: pinnedProviderSessionIdForHistory,
|
|
35093
|
+
effectiveHistorySessionId
|
|
35094
|
+
} = resolveNativeHistoryReadSession(args, historySessionId);
|
|
35039
35095
|
const exactNativeHistoryScope = Boolean(
|
|
35040
35096
|
typeof args?.targetSessionId === "string" && args.targetSessionId.trim() || typeof args?.historySessionId === "string" && args.historySessionId.trim() && !historySessionIdIsRuntimeFallback || typeof args?.providerSessionId === "string" && args.providerSessionId.trim()
|
|
35041
35097
|
);
|
|
@@ -35196,12 +35252,10 @@ async function handleReadChat(h, args) {
|
|
|
35196
35252
|
let nativeHistory = null;
|
|
35197
35253
|
let nativeHistoryError;
|
|
35198
35254
|
if (supportsNative) {
|
|
35199
|
-
const
|
|
35200
|
-
|
|
35201
|
-
|
|
35202
|
-
|
|
35203
|
-
);
|
|
35204
|
-
const effectiveNativeReadSessionId = nativeReadSessionIdIsRuntimeFallback ? pinnedProviderSessionIdForRead || void 0 : nativeHistoryReadSessionId;
|
|
35255
|
+
const {
|
|
35256
|
+
pinnedProviderSessionId: pinnedProviderSessionIdForRead,
|
|
35257
|
+
effectiveHistorySessionId: effectiveNativeReadSessionId
|
|
35258
|
+
} = resolveNativeHistoryReadSession(args, nativeHistoryReadSessionId);
|
|
35205
35259
|
try {
|
|
35206
35260
|
nativeHistory = readCliProviderNativeHistory(agentStr, {
|
|
35207
35261
|
canonicalHistory: provider?.nativeHistory,
|
|
@@ -35478,12 +35532,11 @@ async function handleReadChat(h, args) {
|
|
|
35478
35532
|
const workspace = targetSid ? typeof registrySessionWorkspace === "string" ? registrySessionWorkspace : argsWorkspace ?? currentSessionWorkspace : typeof currentSessionWorkspace === "string" ? currentSessionWorkspace : void 0;
|
|
35479
35533
|
const intendedWorkspace = argsWorkspace;
|
|
35480
35534
|
const supportsNative = supportsCliNativeTranscript(agentStr, provider) && isNativeSourceCanonicalHistory(provider?.nativeHistory);
|
|
35481
|
-
const
|
|
35482
|
-
|
|
35483
|
-
|
|
35484
|
-
|
|
35485
|
-
);
|
|
35486
|
-
const effectiveHistorySessionIdForRead = historySessionIdIsRuntimeFallback ? pinnedProviderSessionIdForHistory || void 0 : historySessionId;
|
|
35535
|
+
const {
|
|
35536
|
+
isRuntimeFallback: historySessionIdIsRuntimeFallback,
|
|
35537
|
+
pinnedProviderSessionId: pinnedProviderSessionIdForHistory,
|
|
35538
|
+
effectiveHistorySessionId: effectiveHistorySessionIdForRead
|
|
35539
|
+
} = resolveNativeHistoryReadSession(args, historySessionId);
|
|
35487
35540
|
const history = supportsNative ? readCliProviderNativeHistory(agentStr, {
|
|
35488
35541
|
canonicalHistory: provider?.nativeHistory,
|
|
35489
35542
|
historySessionId: effectiveHistorySessionIdForRead,
|
|
@@ -54288,61 +54341,15 @@ var meshCrudHandlers = {
|
|
|
54288
54341
|
return { success: false, error: e.message };
|
|
54289
54342
|
}
|
|
54290
54343
|
},
|
|
54291
|
-
// ─── MAGI panels (machine-local config, sibling to meshes) ───────────────
|
|
54292
|
-
// Panels live in ~/.adhdev/meshes.json `magiPanels` and are pure local config
|
|
54293
|
-
// (no mesh ownership). These three handlers mirror list_meshes/create_mesh/
|
|
54294
|
-
// update_mesh: dynamic-import the already-exported mesh-config accessors and
|
|
54295
|
-
// surface normalizeMagiPanel's structured error codes (invalid_magi_panel,
|
|
54296
|
-
// magi_panel_exists) verbatim so the dashboard can render them.
|
|
54297
|
-
//
|
|
54298
|
-
// Permission: magi_panel_set / magi_panel_remove are WRITE commands. They are
|
|
54299
|
-
// intentionally NOT listed in canPeerUsePrivilegedShareCommand (daemon-cloud
|
|
54300
|
-
// data-channel-router), so a peer holding ANY share permission hits its
|
|
54301
|
-
// `default → false` branch — identical owner-only gating to create_mesh /
|
|
54302
|
-
// update_mesh / list_meshes (none of which are listed there either). A trusted
|
|
54303
|
-
// peer (no permission = the owner) passes the top `!permission → true` guard.
|
|
54304
|
-
// Mirror, don't invent: do not add a new policy tier here.
|
|
54305
|
-
//
|
|
54306
|
-
// Resolvability (coupling / stale / available) is deliberately NOT computed
|
|
54307
|
-
// here: buildMagiFanoutPlan lives in mcp-server, unreachable from daemon-core.
|
|
54308
|
-
// magi_panel_list returns the raw definitions only; the dashboard derives
|
|
54309
|
-
// member resolvability client-side (web-core MagiPanelManager, reusing the
|
|
54310
|
-
// MagiGroupRow coupling logic) against live mesh_status.
|
|
54311
|
-
magi_panel_list: async (_ctx, _args) => {
|
|
54312
|
-
try {
|
|
54313
|
-
const { listMagiPanels: listMagiPanels2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
54314
|
-
return { success: true, panels: listMagiPanels2() };
|
|
54315
|
-
} catch (e) {
|
|
54316
|
-
return { success: false, error: e.message };
|
|
54317
|
-
}
|
|
54318
|
-
},
|
|
54319
|
-
magi_panel_set: async (_ctx, args) => {
|
|
54320
|
-
const name = typeof args?.name === "string" ? args.name.trim() : "";
|
|
54321
|
-
if (!name) return { success: false, error: "invalid_magi_panel: panel name is required" };
|
|
54322
|
-
try {
|
|
54323
|
-
const { upsertMagiPanel: upsertMagiPanel2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
54324
|
-
const panel = upsertMagiPanel2(name, args?.panel, { overwrite: args?.overwrite === true });
|
|
54325
|
-
return { success: true, name, panel };
|
|
54326
|
-
} catch (e) {
|
|
54327
|
-
return { success: false, error: e.message };
|
|
54328
|
-
}
|
|
54329
|
-
},
|
|
54330
|
-
magi_panel_remove: async (_ctx, args) => {
|
|
54331
|
-
const name = typeof args?.name === "string" ? args.name.trim() : "";
|
|
54332
|
-
if (!name) return { success: false, error: "invalid_magi_panel: panel name is required" };
|
|
54333
|
-
try {
|
|
54334
|
-
const { removeMagiPanel: removeMagiPanel2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
54335
|
-
const removed = removeMagiPanel2(name);
|
|
54336
|
-
return { success: true, removed };
|
|
54337
|
-
} catch (e) {
|
|
54338
|
-
return { success: false, error: e.message };
|
|
54339
|
-
}
|
|
54340
|
-
},
|
|
54341
54344
|
// ─── MAGI kind → panel bindings (MAGI-KIND-PANEL, machine-local config) ───
|
|
54342
|
-
// Per-task_kind slot lists in ~/.adhdev/meshes.json `magiKindPanels
|
|
54343
|
-
//
|
|
54344
|
-
//
|
|
54345
|
-
//
|
|
54345
|
+
// Per-task_kind slot lists in ~/.adhdev/meshes.json `magiKindPanels` — the SOLE
|
|
54346
|
+
// MAGI panel-resolution surface (the former named-panel magi_panel_* handlers were
|
|
54347
|
+
// removed). Owner-only gating: intentionally NOT listed in
|
|
54348
|
+
// canPeerUsePrivilegedShareCommand (daemon-cloud data-channel-router), so a peer
|
|
54349
|
+
// holding ANY share permission hits its `default → false` branch — identical
|
|
54350
|
+
// owner-only gating to create_mesh / update_mesh / list_meshes. A trusted peer (no
|
|
54351
|
+
// permission = the owner) passes the top `!permission → true` guard. set/remove are
|
|
54352
|
+
// WRITE commands; list is read-only. normalizeMagiSlots (inside setMagiKindPanel)
|
|
54346
54353
|
// surfaces invalid_magi_kind_panel: … messages verbatim for the editor.
|
|
54347
54354
|
magi_kind_panel_list: async (_ctx, _args) => {
|
|
54348
54355
|
try {
|
|
@@ -69481,7 +69488,6 @@ export {
|
|
|
69481
69488
|
getLedgerSummary,
|
|
69482
69489
|
getLogLevel,
|
|
69483
69490
|
getMagiKindPanel,
|
|
69484
|
-
getMagiPanel,
|
|
69485
69491
|
getMesh,
|
|
69486
69492
|
getMeshByRepo,
|
|
69487
69493
|
getMeshMagiActivityByGroup,
|
|
@@ -69539,7 +69545,6 @@ export {
|
|
|
69539
69545
|
listCoordinatorsForWorkspace,
|
|
69540
69546
|
listHostedCliRuntimes,
|
|
69541
69547
|
listMagiKindPanels,
|
|
69542
|
-
listMagiPanels,
|
|
69543
69548
|
listMeshMissionSummaries,
|
|
69544
69549
|
listMeshMissionsForTool,
|
|
69545
69550
|
listMeshes,
|
|
@@ -69576,7 +69581,6 @@ export {
|
|
|
69576
69581
|
normalizeInputEnvelope,
|
|
69577
69582
|
normalizeInteractivePrompt,
|
|
69578
69583
|
normalizeInteractivePromptResponse,
|
|
69579
|
-
normalizeMagiPanel,
|
|
69580
69584
|
normalizeMagiSlots,
|
|
69581
69585
|
normalizeManagedStatus,
|
|
69582
69586
|
normalizeMeshCapabilityTags,
|
|
@@ -69619,7 +69623,6 @@ export {
|
|
|
69619
69623
|
registerExtensionProviders,
|
|
69620
69624
|
registerMeshCoordinator,
|
|
69621
69625
|
removeMagiKindPanel,
|
|
69622
|
-
removeMagiPanel,
|
|
69623
69626
|
removeNode,
|
|
69624
69627
|
removeWorktree,
|
|
69625
69628
|
requeueHeldMeshCoordinatorEvents,
|
|
@@ -69682,7 +69685,6 @@ export {
|
|
|
69682
69685
|
updateSessionDeliveryStatus,
|
|
69683
69686
|
updateSessionTaskStatus,
|
|
69684
69687
|
updateTaskStatus,
|
|
69685
|
-
upsertMagiPanel,
|
|
69686
69688
|
upsertMeshMission,
|
|
69687
69689
|
upsertSavedProviderSession,
|
|
69688
69690
|
validateChangeImpactConfig,
|