@adhdev/daemon-standalone 1.0.38-rc.8 → 1.0.38

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/index.js CHANGED
@@ -37916,10 +37916,10 @@ var require_dist3 = __commonJS({
37916
37916
  }
37917
37917
  function getDaemonBuildInfo() {
37918
37918
  if (cached2) return cached2;
37919
- const commit = readInjected(true ? "5896f4ca87363708599a8f645c75de37a4510a78" : void 0) ?? "unknown";
37920
- const commitShort = readInjected(true ? "5896f4ca" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
37921
- const version2 = readInjected(true ? "1.0.38-rc.8" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
37922
- const builtAt = readInjected(true ? "2026-08-06T14:04:20.486Z" : void 0);
37919
+ const commit = readInjected(true ? "619fea3ec937c98d35155c58f4fa542296cc4c01" : void 0) ?? "unknown";
37920
+ const commitShort = readInjected(true ? "619fea3" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
37921
+ const version2 = readInjected(true ? "1.0.38" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
37922
+ const builtAt = readInjected(true ? "2026-08-07T00:36:08.964Z" : void 0);
37923
37923
  cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
37924
37924
  return cached2;
37925
37925
  }
@@ -39177,7 +39177,7 @@ var require_dist3 = __commonJS({
39177
39177
  }
39178
39178
  });
39179
39179
  function resolveBuildTrack(env2 = process.env) {
39180
- const injected = true ? "preview" : void 0;
39180
+ const injected = true ? "" : void 0;
39181
39181
  const stamped = typeof injected === "string" ? injected.trim() : "";
39182
39182
  const raw = (stamped || (env2[BUILD_CHANNEL_ENV_VAR] ?? "").trim()).toLowerCase();
39183
39183
  return raw === "preview" || raw === "next" ? "preview" : "stable";
@@ -91218,312 +91218,6 @@ ${formatManifestValidationIssues2(validation.issues)}`,
91218
91218
  }
91219
91219
  };
91220
91220
  init_config();
91221
- init_snapshot2();
91222
- init_build_info();
91223
- init_coordinator_registry();
91224
- init_types();
91225
- init_deps();
91226
- init_refresh();
91227
- init_kimi();
91228
- init_codex();
91229
- init_claude();
91230
- init_install();
91231
- init_snapshot();
91232
- var statusMetaHandlers = {
91233
- set_user_name: async (_ctx, args) => {
91234
- const name = args?.userName;
91235
- if (!name || typeof name !== "string") throw new Error("userName required");
91236
- updateConfig({ userName: name });
91237
- return { success: true, userName: name };
91238
- },
91239
- get_status_metadata: async (ctx, _args) => {
91240
- const snapshot = buildStatusSnapshot2({
91241
- allStates: ctx.deps.instanceManager.collectAllStates(),
91242
- cdpManagers: ctx.deps.cdpManagers,
91243
- providerLoader: ctx.deps.providerLoader,
91244
- detectedIdes: ctx.deps.detectedIdes.value,
91245
- instanceId: ctx.deps.statusInstanceId || loadConfig2().machineId || "daemon",
91246
- version: ctx.deps.statusVersion || "unknown",
91247
- profile: "metadata"
91248
- });
91249
- return { success: true, status: snapshot, daemonBuild: getDaemonBuildInfo() };
91250
- },
91251
- get_machine_runtime_stats: async (_ctx, _args) => {
91252
- const quota = readQuotaCache();
91253
- return {
91254
- success: true,
91255
- machine: {
91256
- ...buildMachineInfo2("full"),
91257
- // Omit the key entirely rather than shipping `quota: undefined`
91258
- // — same "never reported" vs "reported empty" contract as
91259
- // buildLocalNodeFacts (mesh/node-facts.ts). `'quota' in machine`
91260
- // must stay false until the refresh loop's first tick.
91261
- ...quota ? { quota } : {},
91262
- machineNickname: loadConfig2().machineNickname
91263
- },
91264
- timestamp: Date.now()
91265
- };
91266
- },
91267
- // Session-info popup data. Aggregates whatever the daemon knows
91268
- // about a single live session into one envelope so the dashboard
91269
- // doesn't need to stitch together status + coordinator registry +
91270
- // session registry on the client. Includes the actual system
91271
- // prompt that was injected at launch when the session is a mesh
91272
- // coordinator — that's the "what prompt did the agent see?"
91273
- // question the info-icon dialog is meant to answer.
91274
- get_session_info: async (ctx, args) => {
91275
- const sessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : typeof args?.sessionId === "string" ? args.sessionId.trim() : "";
91276
- if (!sessionId) return { success: false, error: "targetSessionId required" };
91277
- const target = ctx.deps.sessionRegistry.get(sessionId);
91278
- const coord = getCoordinatorForSession(sessionId);
91279
- if (!target && !coord) return { success: false, error: "Session not found", sessionId };
91280
- const adapter = target ? ctx.deps.cliManager.findAdapter(target.providerType, { instanceKey: sessionId })?.adapter : void 0;
91281
- const runtimeMeta = adapter && typeof adapter.getRuntimeMetadata === "function" ? adapter.getRuntimeMetadata() : void 0;
91282
- const launchInfo = adapter && typeof adapter.getLaunchInfo === "function" ? adapter.getLaunchInfo() : void 0;
91283
- const providerType = target?.providerType || coord?.cliType || "";
91284
- const providerMetaForSession = providerType ? ctx.deps.providerLoader.resolve?.(providerType) || ctx.deps.providerLoader.getMeta(providerType) : void 0;
91285
- const quota = readQuotaCache();
91286
- return {
91287
- success: true,
91288
- session: {
91289
- sessionId,
91290
- providerType,
91291
- providerName: providerMetaForSession?.name,
91292
- transport: target?.transport,
91293
- workspace: target?.workspace || coord?.workspace,
91294
- spawnedAtMs: target?.spawnedAtMs || coord?.startedAt,
91295
- // providerSessionId now comes from the live adapter's launch info
91296
- // (the registry target never carried it — it was always undefined).
91297
- providerSessionId: launchInfo?.providerSessionId || target?.providerSessionId,
91298
- runtimeMetadata: runtimeMeta,
91299
- launch: launchInfo
91300
- },
91301
- // Machine-scoped, not session-scoped: this daemon is the one the
91302
- // dialog already talked to (ctx handles the routing), so it can
91303
- // answer for its own machine's quota with no mesh lookup. Cache
91304
- // read only — see the import comment above. Key omitted entirely
91305
- // (not `quota: undefined`) until the refresh loop's first tick —
91306
- // same never-reported-vs-reported-empty contract as node-facts.ts.
91307
- ...quota ? { quota } : {},
91308
- machineNickname: loadConfig2().machineNickname,
91309
- coordinator: coord ? {
91310
- meshId: coord.meshId,
91311
- startedAt: coord.startedAt,
91312
- cliType: coord.cliType,
91313
- systemPrompt: coord.systemPrompt,
91314
- extraSystemPrompt: coord.extraSystemPrompt,
91315
- injection: coord.injection,
91316
- mcpConfigPath: coord.mcpConfigPath
91317
- } : null
91318
- };
91319
- }
91320
- };
91321
- var coordinatorPromptHandlers = {
91322
- /**
91323
- * Render the coordinator system prompt for a mesh + CLI type, so the
91324
- * dashboard can show the operator exactly what a coordinator session
91325
- * receives by default. This resolves the mesh, applies its repo-mesh
91326
- * config, and runs the SAME buildCoordinatorSystemPrompt the launch path
91327
- * uses — minus the runtime-only best-effort sections (mission / recent
91328
- * activity / operating notes), which are launch-scope and not part of the
91329
- * static "default base" an operator is trying to preview here.
91330
- *
91331
- * It respects mesh-level and user-file override/append layering, so the
91332
- * preview reflects the effective prompt: with no overrides configured it
91333
- * shows the pure daemon default; with an override set it shows that.
91334
- */
91335
- coordinator_prompt_preview: async (ctx, args) => {
91336
- const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
91337
- const cliType = typeof args?.cliType === "string" && args.cliType.trim() ? args.cliType.trim() : "claude-cli";
91338
- if (!meshId) return { success: false, error: "meshId required" };
91339
- try {
91340
- let mesh = null;
91341
- if (ctx.getMeshForCommand) {
91342
- const resolved = await ctx.getMeshForCommand(meshId);
91343
- mesh = resolved?.mesh ?? null;
91344
- }
91345
- if (!mesh) {
91346
- const { getMesh: getMesh2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
91347
- mesh = getMesh2(meshId);
91348
- }
91349
- if (!mesh) return { success: false, error: `mesh not found: ${meshId}` };
91350
- let effectiveMesh = mesh;
91351
- try {
91352
- const { loadRepoMeshJsonConfig: loadRepoMeshJsonConfig2, applyRepoMeshConfig: applyRepoMeshConfig2 } = await Promise.resolve().then(() => (init_mesh_json_config(), mesh_json_config_exports));
91353
- const workspace = typeof mesh?.workspace === "string" ? mesh.workspace : void 0;
91354
- if (workspace) {
91355
- const loaded = loadRepoMeshJsonConfig2(workspace);
91356
- if (loaded?.sourceType !== "invalid") {
91357
- effectiveMesh = applyRepoMeshConfig2(mesh, loaded?.config);
91358
- }
91359
- }
91360
- } catch {
91361
- }
91362
- const { buildCoordinatorSystemPrompt: buildCoordinatorSystemPrompt2 } = await Promise.resolve().then(() => (init_coordinator_prompt(), coordinator_prompt_exports));
91363
- const prompt = buildCoordinatorSystemPrompt2({ mesh: effectiveMesh, coordinatorCliType: cliType });
91364
- return { success: true, prompt, cliType, meshId, bytes: Buffer.byteLength(prompt, "utf8") };
91365
- } catch (error48) {
91366
- return { success: false, error: error48?.message || String(error48) };
91367
- }
91368
- },
91369
- list_coordinator_prompts: async (_ctx, _args) => {
91370
- const fs54 = await import("fs");
91371
- const path54 = await import("path");
91372
- const { getConfigDir: getConfigDir22 } = await Promise.resolve().then(() => (init_config(), config_exports));
91373
- const dir = path54.join(getConfigDir22(), "coordinator-prompts");
91374
- const entries = {};
91375
- try {
91376
- if (fs54.existsSync(dir)) {
91377
- for (const name of fs54.readdirSync(dir)) {
91378
- const matchOverride = name.match(/^([a-zA-Z0-9_.-]+)\.md$/);
91379
- const matchAppend = name.match(/^([a-zA-Z0-9_.-]+)\.append\.md$/);
91380
- const m = matchAppend || matchOverride;
91381
- if (!m) continue;
91382
- const isAppend = !!matchAppend;
91383
- const key2 = m[1];
91384
- const full = path54.join(dir, name);
91385
- let content = "";
91386
- try {
91387
- content = fs54.readFileSync(full, "utf8");
91388
- } catch {
91389
- }
91390
- if (!entries[key2]) entries[key2] = { override: "", append: "" };
91391
- if (isAppend) entries[key2].append = content;
91392
- else entries[key2].override = content;
91393
- }
91394
- }
91395
- } catch (error48) {
91396
- return { success: false, error: error48?.message || String(error48) };
91397
- }
91398
- return { success: true, dir, entries };
91399
- },
91400
- write_coordinator_prompt: async (_ctx, args) => {
91401
- const fs54 = await import("fs");
91402
- const path54 = await import("path");
91403
- const { getConfigDir: getConfigDir22 } = await Promise.resolve().then(() => (init_config(), config_exports));
91404
- const key2 = typeof args?.key === "string" ? args.key.trim() : "";
91405
- const kind = args?.kind === "append" ? "append" : "override";
91406
- const content = typeof args?.content === "string" ? args.content : "";
91407
- if (!key2 || !/^[a-zA-Z0-9_.-]+$/.test(key2)) {
91408
- return { success: false, error: "key must match [a-zA-Z0-9_.-]+" };
91409
- }
91410
- const dir = path54.join(getConfigDir22(), "coordinator-prompts");
91411
- const filename = kind === "append" ? `${key2}.append.md` : `${key2}.md`;
91412
- const full = path54.join(dir, filename);
91413
- try {
91414
- fs54.mkdirSync(dir, { recursive: true });
91415
- if (content.trim()) {
91416
- fs54.writeFileSync(full, content, { encoding: "utf8", mode: 384 });
91417
- } else if (fs54.existsSync(full)) {
91418
- fs54.unlinkSync(full);
91419
- }
91420
- return { success: true, path: full, kind, key: key2 };
91421
- } catch (error48) {
91422
- return { success: false, error: error48?.message || String(error48) };
91423
- }
91424
- }
91425
- };
91426
- init_state_store();
91427
- init_recent_activity();
91428
- init_builders();
91429
- init_snapshot2();
91430
- init_logger();
91431
- var READ_DEBUG_ENABLED2 = process.argv.includes("--dev") || process.env.ADHDEV_READ_DEBUG === "1";
91432
- var notificationHandlers = {
91433
- mark_session_seen: async (ctx, args) => {
91434
- const sessionId = args?.sessionId;
91435
- if (!sessionId || typeof sessionId !== "string") {
91436
- return { success: false, error: "sessionId is required" };
91437
- }
91438
- const currentState = loadState();
91439
- const prevSeenAt = currentState.sessionReads?.[sessionId] || 0;
91440
- const sessionEntries = buildSessionEntries(
91441
- ctx.deps.instanceManager.collectAllStates(),
91442
- ctx.deps.cdpManagers
91443
- );
91444
- const targetSession = sessionEntries.find((entry) => entry.id === sessionId);
91445
- const requestedCompletionMarker = typeof args?.completionMarker === "string" ? args.completionMarker.trim() : "";
91446
- const completionMarker = requestedCompletionMarker || (targetSession ? getSessionCompletionMarker(targetSession) : "");
91447
- const requestedProviderSessionId = typeof args?.providerSessionId === "string" ? args.providerSessionId.trim() : "";
91448
- const providerSessionId = requestedProviderSessionId || targetSession?.providerSessionId;
91449
- const next = markSessionSeen(
91450
- currentState,
91451
- sessionId,
91452
- typeof args?.seenAt === "number" ? args.seenAt : Date.now(),
91453
- completionMarker,
91454
- providerSessionId
91455
- );
91456
- if (READ_DEBUG_ENABLED2) {
91457
- LOG2.info("RecentRead", `mark_session_seen sessionId=${sessionId} seenAt=${String(args?.seenAt || "")} prevSeenAt=${String(prevSeenAt)} nextSeenAt=${String(next.sessionReads?.[sessionId] || 0)} marker=${completionMarker || "-"}`);
91458
- }
91459
- saveState(next);
91460
- ctx.deps.onStatusChange?.();
91461
- return {
91462
- success: true,
91463
- sessionId,
91464
- seenAt: next.sessionReads?.[sessionId] || Date.now(),
91465
- completionMarker
91466
- };
91467
- },
91468
- delete_notification: async (ctx, args) => {
91469
- const sessionId = args?.sessionId;
91470
- const notificationId = typeof args?.notificationId === "string" ? args.notificationId.trim() : "";
91471
- if (!sessionId || typeof sessionId !== "string") {
91472
- return { success: false, error: "sessionId is required" };
91473
- }
91474
- if (!notificationId) {
91475
- return { success: false, error: "notificationId is required" };
91476
- }
91477
- const sessionEntries = buildSessionEntries(
91478
- ctx.deps.instanceManager.collectAllStates(),
91479
- ctx.deps.cdpManagers
91480
- );
91481
- const targetSession = sessionEntries.find((entry) => entry.id === sessionId);
91482
- const next = dismissSessionNotification(
91483
- loadState(),
91484
- sessionId,
91485
- notificationId,
91486
- targetSession?.providerSessionId
91487
- );
91488
- saveState(next);
91489
- ctx.deps.onStatusChange?.();
91490
- return {
91491
- success: true,
91492
- sessionId,
91493
- notificationId
91494
- };
91495
- },
91496
- mark_notification_unread: async (ctx, args) => {
91497
- const sessionId = args?.sessionId;
91498
- const notificationId = typeof args?.notificationId === "string" ? args.notificationId.trim() : "";
91499
- if (!sessionId || typeof sessionId !== "string") {
91500
- return { success: false, error: "sessionId is required" };
91501
- }
91502
- if (!notificationId) {
91503
- return { success: false, error: "notificationId is required" };
91504
- }
91505
- const sessionEntries = buildSessionEntries(
91506
- ctx.deps.instanceManager.collectAllStates(),
91507
- ctx.deps.cdpManagers
91508
- );
91509
- const targetSession = sessionEntries.find((entry) => entry.id === sessionId);
91510
- const next = markSessionNotificationUnread(
91511
- loadState(),
91512
- sessionId,
91513
- notificationId,
91514
- targetSession?.providerSessionId
91515
- );
91516
- saveState(next);
91517
- ctx.deps.onStatusChange?.();
91518
- return {
91519
- success: true,
91520
- sessionId,
91521
- notificationId
91522
- };
91523
- }
91524
- };
91525
- init_config();
91526
- init_install();
91527
91221
  var import_child_process8 = require("child_process");
91528
91222
  var import_child_process9 = require("child_process");
91529
91223
  var fs20 = __toESM2(require("fs"));
@@ -92507,6 +92201,17 @@ ${body}
92507
92201
  } catch {
92508
92202
  }
92509
92203
  }
92204
+ function readUpgradeFailureNotice(configDir = getConfigDir2()) {
92205
+ try {
92206
+ const noticePath = getUpgradeFailureNoticePath(configDir);
92207
+ if (!fs20.existsSync(noticePath)) return null;
92208
+ const notice = fs20.readFileSync(noticePath, "utf8").trim();
92209
+ if (!notice) return null;
92210
+ return { noticePath, logPath: getUpgradeLogPath(configDir), notice };
92211
+ } catch {
92212
+ return null;
92213
+ }
92214
+ }
92510
92215
  function isRetriableInstallLockError(error48) {
92511
92216
  const code = error48?.code;
92512
92217
  if (code === "EBUSY" || code === "EPERM") return true;
@@ -92794,6 +92499,312 @@ ${body}
92794
92499
  process.exit(1);
92795
92500
  }
92796
92501
  }
92502
+ init_snapshot2();
92503
+ init_build_info();
92504
+ init_coordinator_registry();
92505
+ init_types();
92506
+ init_deps();
92507
+ init_refresh();
92508
+ init_kimi();
92509
+ init_codex();
92510
+ init_claude();
92511
+ init_install();
92512
+ init_snapshot();
92513
+ var statusMetaHandlers = {
92514
+ set_user_name: async (_ctx, args) => {
92515
+ const name = args?.userName;
92516
+ if (!name || typeof name !== "string") throw new Error("userName required");
92517
+ updateConfig({ userName: name });
92518
+ return { success: true, userName: name };
92519
+ },
92520
+ get_status_metadata: async (ctx, _args) => {
92521
+ const snapshot = buildStatusSnapshot2({
92522
+ allStates: ctx.deps.instanceManager.collectAllStates(),
92523
+ cdpManagers: ctx.deps.cdpManagers,
92524
+ providerLoader: ctx.deps.providerLoader,
92525
+ detectedIdes: ctx.deps.detectedIdes.value,
92526
+ instanceId: ctx.deps.statusInstanceId || loadConfig2().machineId || "daemon",
92527
+ version: ctx.deps.statusVersion || "unknown",
92528
+ profile: "metadata"
92529
+ });
92530
+ return { success: true, status: snapshot, daemonBuild: getDaemonBuildInfo(), upgradeFailure: readUpgradeFailureNotice() };
92531
+ },
92532
+ get_machine_runtime_stats: async (_ctx, _args) => {
92533
+ const quota = readQuotaCache();
92534
+ return {
92535
+ success: true,
92536
+ machine: {
92537
+ ...buildMachineInfo2("full"),
92538
+ // Omit the key entirely rather than shipping `quota: undefined`
92539
+ // — same "never reported" vs "reported empty" contract as
92540
+ // buildLocalNodeFacts (mesh/node-facts.ts). `'quota' in machine`
92541
+ // must stay false until the refresh loop's first tick.
92542
+ ...quota ? { quota } : {},
92543
+ machineNickname: loadConfig2().machineNickname
92544
+ },
92545
+ timestamp: Date.now()
92546
+ };
92547
+ },
92548
+ // Session-info popup data. Aggregates whatever the daemon knows
92549
+ // about a single live session into one envelope so the dashboard
92550
+ // doesn't need to stitch together status + coordinator registry +
92551
+ // session registry on the client. Includes the actual system
92552
+ // prompt that was injected at launch when the session is a mesh
92553
+ // coordinator — that's the "what prompt did the agent see?"
92554
+ // question the info-icon dialog is meant to answer.
92555
+ get_session_info: async (ctx, args) => {
92556
+ const sessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : typeof args?.sessionId === "string" ? args.sessionId.trim() : "";
92557
+ if (!sessionId) return { success: false, error: "targetSessionId required" };
92558
+ const target = ctx.deps.sessionRegistry.get(sessionId);
92559
+ const coord = getCoordinatorForSession(sessionId);
92560
+ if (!target && !coord) return { success: false, error: "Session not found", sessionId };
92561
+ const adapter = target ? ctx.deps.cliManager.findAdapter(target.providerType, { instanceKey: sessionId })?.adapter : void 0;
92562
+ const runtimeMeta = adapter && typeof adapter.getRuntimeMetadata === "function" ? adapter.getRuntimeMetadata() : void 0;
92563
+ const launchInfo = adapter && typeof adapter.getLaunchInfo === "function" ? adapter.getLaunchInfo() : void 0;
92564
+ const providerType = target?.providerType || coord?.cliType || "";
92565
+ const providerMetaForSession = providerType ? ctx.deps.providerLoader.resolve?.(providerType) || ctx.deps.providerLoader.getMeta(providerType) : void 0;
92566
+ const quota = readQuotaCache();
92567
+ return {
92568
+ success: true,
92569
+ session: {
92570
+ sessionId,
92571
+ providerType,
92572
+ providerName: providerMetaForSession?.name,
92573
+ transport: target?.transport,
92574
+ workspace: target?.workspace || coord?.workspace,
92575
+ spawnedAtMs: target?.spawnedAtMs || coord?.startedAt,
92576
+ // providerSessionId now comes from the live adapter's launch info
92577
+ // (the registry target never carried it — it was always undefined).
92578
+ providerSessionId: launchInfo?.providerSessionId || target?.providerSessionId,
92579
+ runtimeMetadata: runtimeMeta,
92580
+ launch: launchInfo
92581
+ },
92582
+ // Machine-scoped, not session-scoped: this daemon is the one the
92583
+ // dialog already talked to (ctx handles the routing), so it can
92584
+ // answer for its own machine's quota with no mesh lookup. Cache
92585
+ // read only — see the import comment above. Key omitted entirely
92586
+ // (not `quota: undefined`) until the refresh loop's first tick —
92587
+ // same never-reported-vs-reported-empty contract as node-facts.ts.
92588
+ ...quota ? { quota } : {},
92589
+ machineNickname: loadConfig2().machineNickname,
92590
+ coordinator: coord ? {
92591
+ meshId: coord.meshId,
92592
+ startedAt: coord.startedAt,
92593
+ cliType: coord.cliType,
92594
+ systemPrompt: coord.systemPrompt,
92595
+ extraSystemPrompt: coord.extraSystemPrompt,
92596
+ injection: coord.injection,
92597
+ mcpConfigPath: coord.mcpConfigPath
92598
+ } : null
92599
+ };
92600
+ }
92601
+ };
92602
+ var coordinatorPromptHandlers = {
92603
+ /**
92604
+ * Render the coordinator system prompt for a mesh + CLI type, so the
92605
+ * dashboard can show the operator exactly what a coordinator session
92606
+ * receives by default. This resolves the mesh, applies its repo-mesh
92607
+ * config, and runs the SAME buildCoordinatorSystemPrompt the launch path
92608
+ * uses — minus the runtime-only best-effort sections (mission / recent
92609
+ * activity / operating notes), which are launch-scope and not part of the
92610
+ * static "default base" an operator is trying to preview here.
92611
+ *
92612
+ * It respects mesh-level and user-file override/append layering, so the
92613
+ * preview reflects the effective prompt: with no overrides configured it
92614
+ * shows the pure daemon default; with an override set it shows that.
92615
+ */
92616
+ coordinator_prompt_preview: async (ctx, args) => {
92617
+ const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
92618
+ const cliType = typeof args?.cliType === "string" && args.cliType.trim() ? args.cliType.trim() : "claude-cli";
92619
+ if (!meshId) return { success: false, error: "meshId required" };
92620
+ try {
92621
+ let mesh = null;
92622
+ if (ctx.getMeshForCommand) {
92623
+ const resolved = await ctx.getMeshForCommand(meshId);
92624
+ mesh = resolved?.mesh ?? null;
92625
+ }
92626
+ if (!mesh) {
92627
+ const { getMesh: getMesh2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
92628
+ mesh = getMesh2(meshId);
92629
+ }
92630
+ if (!mesh) return { success: false, error: `mesh not found: ${meshId}` };
92631
+ let effectiveMesh = mesh;
92632
+ try {
92633
+ const { loadRepoMeshJsonConfig: loadRepoMeshJsonConfig2, applyRepoMeshConfig: applyRepoMeshConfig2 } = await Promise.resolve().then(() => (init_mesh_json_config(), mesh_json_config_exports));
92634
+ const workspace = typeof mesh?.workspace === "string" ? mesh.workspace : void 0;
92635
+ if (workspace) {
92636
+ const loaded = loadRepoMeshJsonConfig2(workspace);
92637
+ if (loaded?.sourceType !== "invalid") {
92638
+ effectiveMesh = applyRepoMeshConfig2(mesh, loaded?.config);
92639
+ }
92640
+ }
92641
+ } catch {
92642
+ }
92643
+ const { buildCoordinatorSystemPrompt: buildCoordinatorSystemPrompt2 } = await Promise.resolve().then(() => (init_coordinator_prompt(), coordinator_prompt_exports));
92644
+ const prompt = buildCoordinatorSystemPrompt2({ mesh: effectiveMesh, coordinatorCliType: cliType });
92645
+ return { success: true, prompt, cliType, meshId, bytes: Buffer.byteLength(prompt, "utf8") };
92646
+ } catch (error48) {
92647
+ return { success: false, error: error48?.message || String(error48) };
92648
+ }
92649
+ },
92650
+ list_coordinator_prompts: async (_ctx, _args) => {
92651
+ const fs54 = await import("fs");
92652
+ const path54 = await import("path");
92653
+ const { getConfigDir: getConfigDir22 } = await Promise.resolve().then(() => (init_config(), config_exports));
92654
+ const dir = path54.join(getConfigDir22(), "coordinator-prompts");
92655
+ const entries = {};
92656
+ try {
92657
+ if (fs54.existsSync(dir)) {
92658
+ for (const name of fs54.readdirSync(dir)) {
92659
+ const matchOverride = name.match(/^([a-zA-Z0-9_.-]+)\.md$/);
92660
+ const matchAppend = name.match(/^([a-zA-Z0-9_.-]+)\.append\.md$/);
92661
+ const m = matchAppend || matchOverride;
92662
+ if (!m) continue;
92663
+ const isAppend = !!matchAppend;
92664
+ const key2 = m[1];
92665
+ const full = path54.join(dir, name);
92666
+ let content = "";
92667
+ try {
92668
+ content = fs54.readFileSync(full, "utf8");
92669
+ } catch {
92670
+ }
92671
+ if (!entries[key2]) entries[key2] = { override: "", append: "" };
92672
+ if (isAppend) entries[key2].append = content;
92673
+ else entries[key2].override = content;
92674
+ }
92675
+ }
92676
+ } catch (error48) {
92677
+ return { success: false, error: error48?.message || String(error48) };
92678
+ }
92679
+ return { success: true, dir, entries };
92680
+ },
92681
+ write_coordinator_prompt: async (_ctx, args) => {
92682
+ const fs54 = await import("fs");
92683
+ const path54 = await import("path");
92684
+ const { getConfigDir: getConfigDir22 } = await Promise.resolve().then(() => (init_config(), config_exports));
92685
+ const key2 = typeof args?.key === "string" ? args.key.trim() : "";
92686
+ const kind = args?.kind === "append" ? "append" : "override";
92687
+ const content = typeof args?.content === "string" ? args.content : "";
92688
+ if (!key2 || !/^[a-zA-Z0-9_.-]+$/.test(key2)) {
92689
+ return { success: false, error: "key must match [a-zA-Z0-9_.-]+" };
92690
+ }
92691
+ const dir = path54.join(getConfigDir22(), "coordinator-prompts");
92692
+ const filename = kind === "append" ? `${key2}.append.md` : `${key2}.md`;
92693
+ const full = path54.join(dir, filename);
92694
+ try {
92695
+ fs54.mkdirSync(dir, { recursive: true });
92696
+ if (content.trim()) {
92697
+ fs54.writeFileSync(full, content, { encoding: "utf8", mode: 384 });
92698
+ } else if (fs54.existsSync(full)) {
92699
+ fs54.unlinkSync(full);
92700
+ }
92701
+ return { success: true, path: full, kind, key: key2 };
92702
+ } catch (error48) {
92703
+ return { success: false, error: error48?.message || String(error48) };
92704
+ }
92705
+ }
92706
+ };
92707
+ init_state_store();
92708
+ init_recent_activity();
92709
+ init_builders();
92710
+ init_snapshot2();
92711
+ init_logger();
92712
+ var READ_DEBUG_ENABLED2 = process.argv.includes("--dev") || process.env.ADHDEV_READ_DEBUG === "1";
92713
+ var notificationHandlers = {
92714
+ mark_session_seen: async (ctx, args) => {
92715
+ const sessionId = args?.sessionId;
92716
+ if (!sessionId || typeof sessionId !== "string") {
92717
+ return { success: false, error: "sessionId is required" };
92718
+ }
92719
+ const currentState = loadState();
92720
+ const prevSeenAt = currentState.sessionReads?.[sessionId] || 0;
92721
+ const sessionEntries = buildSessionEntries(
92722
+ ctx.deps.instanceManager.collectAllStates(),
92723
+ ctx.deps.cdpManagers
92724
+ );
92725
+ const targetSession = sessionEntries.find((entry) => entry.id === sessionId);
92726
+ const requestedCompletionMarker = typeof args?.completionMarker === "string" ? args.completionMarker.trim() : "";
92727
+ const completionMarker = requestedCompletionMarker || (targetSession ? getSessionCompletionMarker(targetSession) : "");
92728
+ const requestedProviderSessionId = typeof args?.providerSessionId === "string" ? args.providerSessionId.trim() : "";
92729
+ const providerSessionId = requestedProviderSessionId || targetSession?.providerSessionId;
92730
+ const next = markSessionSeen(
92731
+ currentState,
92732
+ sessionId,
92733
+ typeof args?.seenAt === "number" ? args.seenAt : Date.now(),
92734
+ completionMarker,
92735
+ providerSessionId
92736
+ );
92737
+ if (READ_DEBUG_ENABLED2) {
92738
+ LOG2.info("RecentRead", `mark_session_seen sessionId=${sessionId} seenAt=${String(args?.seenAt || "")} prevSeenAt=${String(prevSeenAt)} nextSeenAt=${String(next.sessionReads?.[sessionId] || 0)} marker=${completionMarker || "-"}`);
92739
+ }
92740
+ saveState(next);
92741
+ ctx.deps.onStatusChange?.();
92742
+ return {
92743
+ success: true,
92744
+ sessionId,
92745
+ seenAt: next.sessionReads?.[sessionId] || Date.now(),
92746
+ completionMarker
92747
+ };
92748
+ },
92749
+ delete_notification: async (ctx, args) => {
92750
+ const sessionId = args?.sessionId;
92751
+ const notificationId = typeof args?.notificationId === "string" ? args.notificationId.trim() : "";
92752
+ if (!sessionId || typeof sessionId !== "string") {
92753
+ return { success: false, error: "sessionId is required" };
92754
+ }
92755
+ if (!notificationId) {
92756
+ return { success: false, error: "notificationId is required" };
92757
+ }
92758
+ const sessionEntries = buildSessionEntries(
92759
+ ctx.deps.instanceManager.collectAllStates(),
92760
+ ctx.deps.cdpManagers
92761
+ );
92762
+ const targetSession = sessionEntries.find((entry) => entry.id === sessionId);
92763
+ const next = dismissSessionNotification(
92764
+ loadState(),
92765
+ sessionId,
92766
+ notificationId,
92767
+ targetSession?.providerSessionId
92768
+ );
92769
+ saveState(next);
92770
+ ctx.deps.onStatusChange?.();
92771
+ return {
92772
+ success: true,
92773
+ sessionId,
92774
+ notificationId
92775
+ };
92776
+ },
92777
+ mark_notification_unread: async (ctx, args) => {
92778
+ const sessionId = args?.sessionId;
92779
+ const notificationId = typeof args?.notificationId === "string" ? args.notificationId.trim() : "";
92780
+ if (!sessionId || typeof sessionId !== "string") {
92781
+ return { success: false, error: "sessionId is required" };
92782
+ }
92783
+ if (!notificationId) {
92784
+ return { success: false, error: "notificationId is required" };
92785
+ }
92786
+ const sessionEntries = buildSessionEntries(
92787
+ ctx.deps.instanceManager.collectAllStates(),
92788
+ ctx.deps.cdpManagers
92789
+ );
92790
+ const targetSession = sessionEntries.find((entry) => entry.id === sessionId);
92791
+ const next = markSessionNotificationUnread(
92792
+ loadState(),
92793
+ sessionId,
92794
+ notificationId,
92795
+ targetSession?.providerSessionId
92796
+ );
92797
+ saveState(next);
92798
+ ctx.deps.onStatusChange?.();
92799
+ return {
92800
+ success: true,
92801
+ sessionId,
92802
+ notificationId
92803
+ };
92804
+ }
92805
+ };
92806
+ init_config();
92807
+ init_install();
92797
92808
  init_logger();
92798
92809
  init_track_identity();
92799
92810
  var daemonLifecycleHandlers = {
@@ -92823,7 +92834,7 @@ ${body}
92823
92834
  const runningVersion = typeof ctx.deps.statusVersion === "string" ? ctx.deps.statusVersion.trim().replace(/^v/, "") : null;
92824
92835
  if (currentInstalled === latest && runningVersion === latest) {
92825
92836
  LOG2.info("Upgrade", `Already on ${TRACK} track version v${latest}; skipping install`);
92826
- return { success: true, upgraded: false, alreadyLatest: true, version: latest, channel: TRACK, npmTag };
92837
+ return { success: true, upgraded: false, alreadyLatest: true, outcome: "already_latest", version: latest, targetVersion: latest, channel: TRACK, npmTag };
92827
92838
  }
92828
92839
  if (currentInstalled === latest && runningVersion && runningVersion !== latest) {
92829
92840
  LOG2.info("Upgrade", `Installed package is v${latest}, but running daemon is v${runningVersion}; scheduling restart`);
@@ -92841,7 +92852,18 @@ ${body}
92841
92852
  LOG2.info("Upgrade", "Exiting daemon so detached upgrader can continue...");
92842
92853
  process.exit(0);
92843
92854
  }, 3e3);
92844
- return { success: true, upgraded: true, version: latest, restarting: true, channel: TRACK, npmTag };
92855
+ return {
92856
+ success: true,
92857
+ upgraded: true,
92858
+ version: latest,
92859
+ restarting: true,
92860
+ channel: TRACK,
92861
+ npmTag,
92862
+ outcome: "scheduled",
92863
+ targetVersion: latest,
92864
+ upgradeLogPath: getUpgradeLogPath(),
92865
+ clientHint: `Upgrade to v${latest} SCHEDULED, not completed \u2014 the detached helper installs and restarts the daemon after this response, and a failure rolls back to the previous version. Check upgradeLogPath (or get_status_metadata.upgradeFailure after the restart) for the actual outcome.`
92866
+ };
92845
92867
  } catch (e) {
92846
92868
  LOG2.error("Upgrade", `Failed: ${e.message}`);
92847
92869
  return { success: false, error: e.message };
@@ -92876,7 +92898,16 @@ ${body}
92876
92898
  LOG2.info("Restart", "Exiting daemon so detached helper can re-spawn it...");
92877
92899
  process.exit(0);
92878
92900
  }, 3e3);
92879
- return { success: true, restarted: true, restarting: true, mode: "restart", killSessionHost };
92901
+ return {
92902
+ success: true,
92903
+ restarted: true,
92904
+ restarting: true,
92905
+ mode: "restart",
92906
+ killSessionHost,
92907
+ outcome: "scheduled",
92908
+ upgradeLogPath: getUpgradeLogPath(),
92909
+ clientHint: "Restart SCHEDULED, not completed \u2014 the detached helper re-spawns the daemon after this response. Check upgradeLogPath for the actual outcome."
92910
+ };
92880
92911
  } catch (e) {
92881
92912
  LOG2.error("Restart", `Failed: ${e.message}`);
92882
92913
  return { success: false, error: e.message };
@@ -125819,6 +125850,11 @@ data: ${JSON.stringify(msg.data)}
125819
125850
  installProviderProcessShim();
125820
125851
  installGlobalInterceptor();
125821
125852
  loadMeshCoordinatorRegistry();
125853
+ const upgradeFailureNotice = readUpgradeFailureNotice();
125854
+ if (upgradeFailureNotice) {
125855
+ LOG2.warn("Upgrade", `Previous daemon upgrade FAILED and was rolled back \u2014 this daemon is running the previous version. Notice (${upgradeFailureNotice.noticePath}):
125856
+ ${upgradeFailureNotice.notice}`);
125857
+ }
125822
125858
  const appConfig = loadConfig2();
125823
125859
  const providerSourceMode = appConfig.providerSourceMode || "normal";
125824
125860
  const disableUpstream = providerSourceMode === "no-upstream";