@clagentic/console 1.10.0-beta.1 → 1.10.0-beta.3

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.
Files changed (94) hide show
  1. package/README.md +1 -1
  2. package/bin/cli.js +10 -0
  3. package/lib/activity-clock.js +23 -0
  4. package/lib/agent-dispatch-tool.js +20 -0
  5. package/lib/build-changes.js +79 -0
  6. package/lib/build-identity.js +192 -0
  7. package/lib/build-monitor.js +125 -0
  8. package/lib/build-sha.json +2 -2
  9. package/lib/build-update-offer.js +141 -0
  10. package/lib/build-update-restart.js +142 -0
  11. package/lib/build-update-standing.js +184 -0
  12. package/lib/cli/daemon-launch.js +8 -5
  13. package/lib/cli/ipc-subcommands.js +6 -0
  14. package/lib/cli/session-subcommands.js +122 -0
  15. package/lib/cli-sessions.js +8 -1
  16. package/lib/cli-transcript-title.js +131 -0
  17. package/lib/codex-defaults.js +8 -2
  18. package/lib/daemon-projects.js +19 -0
  19. package/lib/daemon.js +166 -127
  20. package/lib/debug-log.js +17 -0
  21. package/lib/exit-flush.js +44 -0
  22. package/lib/grant-keys.js +179 -0
  23. package/lib/log-field.js +34 -0
  24. package/lib/memory-shed.js +13 -32
  25. package/lib/project-connection.js +14 -0
  26. package/lib/project-external-trigger.js +91 -123
  27. package/lib/project-http.js +2 -0
  28. package/lib/project-loop.js +5 -4
  29. package/lib/project-notifications.js +4 -0
  30. package/lib/project-prompt-responses.js +7 -5
  31. package/lib/project-session-grants.js +73 -0
  32. package/lib/project-sessions.js +55 -68
  33. package/lib/project-user-message.js +13 -25
  34. package/lib/project.js +25 -5
  35. package/lib/prompt-kinds/permission.js +18 -0
  36. package/lib/prompt-label.js +60 -0
  37. package/lib/prompt-registry.js +123 -13
  38. package/lib/prompt-source.js +65 -0
  39. package/lib/public/css/diagnostics.css +30 -0
  40. package/lib/public/css/notifications-center.css +15 -0
  41. package/lib/public/css/overlays.css +18 -0
  42. package/lib/public/css/rewind.css +8 -0
  43. package/lib/public/modules/agent-dispatch-tool.js +9 -0
  44. package/lib/public/modules/app-messages.js +10 -2
  45. package/lib/public/modules/app-notifications.js +9 -1
  46. package/lib/public/modules/app-panels.js +0 -1
  47. package/lib/public/modules/build-update-detail.js +54 -0
  48. package/lib/public/modules/diagnostics.js +126 -20
  49. package/lib/public/modules/prompt-banner.js +12 -0
  50. package/lib/public/modules/prompt-kinds/permission-choices.js +6 -1
  51. package/lib/public/modules/prompt-kinds/permission.js +15 -0
  52. package/lib/public/modules/prompt-label.js +44 -0
  53. package/lib/public/modules/prompts.js +9 -0
  54. package/lib/public/modules/session-grants.js +131 -0
  55. package/lib/public/modules/sidebar-sessions.js +11 -0
  56. package/lib/public/modules/tools.js +14 -2
  57. package/lib/public/modules/vendor-picker.js +2 -2
  58. package/lib/public/modules/vendor-registry.js +11 -2
  59. package/lib/runtime-env.js +1 -1
  60. package/lib/sdk-bridge.js +114 -115
  61. package/lib/sdk-message-processor.js +25 -87
  62. package/lib/sdk-skill-discovery.js +65 -60
  63. package/lib/server.js +15 -2
  64. package/lib/session-ai-title.js +80 -0
  65. package/lib/session-id.js +33 -0
  66. package/lib/session-input-ipc.js +32 -0
  67. package/lib/session-input.js +409 -0
  68. package/lib/session-reclaim.js +284 -0
  69. package/lib/session-resume.js +172 -0
  70. package/lib/sessions.js +31 -21
  71. package/lib/supervisor.js +39 -0
  72. package/lib/turn-initiator.js +108 -0
  73. package/lib/utils.js +9 -47
  74. package/lib/vendor-registry-message.js +1 -0
  75. package/lib/ws-schema.js +9 -4
  76. package/lib/yoke/adapters/claude-vendor.js +0 -1
  77. package/lib/yoke/adapters/claude-worker.js +6 -4
  78. package/lib/yoke/adapters/claude.js +29 -86
  79. package/lib/yoke/adapters/codex-capabilities.js +9 -6
  80. package/lib/yoke/adapters/codex-vendor.js +15 -15
  81. package/lib/yoke/adapters/codex.js +125 -136
  82. package/lib/yoke/auth-checks.js +8 -21
  83. package/lib/yoke/codex-app-server.js +27 -71
  84. package/lib/yoke/codex-binary.js +254 -0
  85. package/lib/yoke/codex-command.js +122 -0
  86. package/lib/yoke/codex-protocol.js +96 -0
  87. package/lib/yoke/codex-version.js +135 -0
  88. package/lib/yoke/index.js +20 -4
  89. package/lib/yoke/install-probe.js +21 -6
  90. package/lib/yoke/interface.js +14 -12
  91. package/lib/yoke/registry.js +41 -4
  92. package/package.json +1 -2
  93. package/scripts/verify-installed-build.js +59 -17
  94. package/lib/lore-attestation.js +0 -73
@@ -3,9 +3,12 @@ var { discoverWorkflows } = require("./sdk-workflow-discovery");
3
3
  var { buildEnrichedSlashCommands } = require("./sdk-slash-enrichment");
4
4
  var { promptsFor } = require("./prompt-registry");
5
5
  var sessionActivity = require("./session-activity");
6
- var loreAttestation = require("./lore-attestation");
7
6
  var yokeRegistry = require("./yoke").registry;
8
7
  var { authRequiredFacts } = require("./vendor-auth");
8
+ var sessionReclaim = require("./session-reclaim");
9
+ var { withPromptLabel } = require("./prompt-label");
10
+ var { isAgentDispatchTool } = require("./agent-dispatch-tool");
11
+ var { bumpLastActivity } = require("./activity-clock");
9
12
 
10
13
  // Source names of the activity tokens an agent with the activityTokens
11
14
  // trait holds for its own tool and thinking blocks.
@@ -30,7 +33,7 @@ function attachMessageProcessor(ctx) {
30
33
  var cwd = ctx.cwd;
31
34
  var onProcessingChanged = ctx.onProcessingChanged;
32
35
  var onTurnDone = ctx.onTurnDone;
33
- var onAutoTitle = ctx.onAutoTitle;
36
+ var refreshAiTitle = ctx.refreshAiTitle || null;
34
37
  var onTeamCreate = ctx.onTeamCreate || null;
35
38
  var onTeamDelete = ctx.onTeamDelete || null;
36
39
  var opts = ctx.opts;
@@ -44,8 +47,6 @@ function attachMessageProcessor(ctx) {
44
47
  // Allows callers (and tests) to inject a mock; falls back to the real implementation.
45
48
  var discoverWorkflowsFn = ctx.discoverWorkflows || discoverWorkflows;
46
49
 
47
- var AUTO_TITLE_TURN_THRESHOLD = 2;
48
-
49
50
  function sendAndRecord(session, obj) {
50
51
  sm.sendAndRecord(session, obj);
51
52
  }
@@ -155,7 +156,7 @@ function attachMessageProcessor(ctx) {
155
156
  if (name === "Glob" && input && input.pattern) return "Finding " + input.pattern;
156
157
  if (name === "WebSearch" && input && input.query) return "Searching: " + input.query;
157
158
  if (name === "WebFetch") return "Fetching URL...";
158
- if (name === "Task" && input && input.description) return input.description;
159
+ if (isAgentDispatchTool(name) && input && input.description) return input.description;
159
160
  return "Running " + name + "...";
160
161
  }
161
162
 
@@ -197,7 +198,7 @@ function attachMessageProcessor(ctx) {
197
198
  // producing output; a dead/silent child stops bumping and the session
198
199
  // still times out and is reaped normally (no blanket "never reap if a
199
200
  // child is registered" rule — see startIdleReaper in sdk-bridge.js).
200
- session.lastActivityAt = Date.now();
201
+ bumpLastActivity(session, "subagent-stream", slug);
201
202
 
202
203
  if (parsed.messageRole === "assistant") {
203
204
  // Extract tool_use blocks from sub-agent assistant messages
@@ -264,22 +265,6 @@ function attachMessageProcessor(ctx) {
264
265
  sm.saveSessionFile(session);
265
266
  if (_isNewSessionId) {
266
267
  sendAndRecord(session, { type: "session_id", cliSessionId: session.cliSessionId });
267
- // Declare human presence to LORE for a session of an agent with the
268
- // attestsHumanSessions trait (Codex) that the operator is driving
269
- // through the console, keyed on the rollout/thread id captured just
270
- // above (parsed.sessionId is that id — see
271
- // lib/yoke/adapters/codex.js's thread/start-and-resume handling).
272
- // Claude console sessions are already covered by LORE's own pulse hook
273
- // and are deliberately not duplicated here (see lib/lore-attestation.js
274
- // header). Gated on session.humanOriginated, set ONLY by the WS
275
- // "message"/"send_scheduled_now" handlers in project-user-message.js —
276
- // never true for a headless session (Ralph Loop, external trigger,
277
- // scheduler), so a scheduled/autonomous dispatch is never attested.
278
- // Fire-and-forget and fail-open by construction — see
279
- // attestHumanSession's own contract.
280
- if (sessionHasTrait(session, "attestsHumanSessions") && session.humanOriginated) {
281
- loreAttestation.attestHumanSession(session.cliSessionId);
282
- }
283
268
  }
284
269
  }
285
270
 
@@ -504,8 +489,10 @@ function attachMessageProcessor(ctx) {
504
489
 
505
490
  // Track active Task tools (activeTaskToolIds, written by the prompt
506
491
  // registry) for sub-agent done detection and prompt ownership.
507
- if (block.name === "Task") {
492
+ if (isAgentDispatchTool(block.name)) {
508
493
  promptsFor(sm).taskStarted(session, block.id);
494
+ // Names the agent in any notice about it (reap, shed, its prompts).
495
+ sessionReclaim.noteTaskLabel(session, block.id, input);
509
496
  }
510
497
 
511
498
  if (pushModule && block.name === "AskUserQuestion" && input.questions) {
@@ -514,7 +501,7 @@ function attachMessageProcessor(ctx) {
514
501
  type: "ask_user",
515
502
  slug: slug,
516
503
  title: "Claude has a question",
517
- body: q ? q.question : "Waiting for your response",
504
+ body: withPromptLabel(promptsFor(sm).labelFor(session, block.id), q ? q.question : "Waiting for your response"),
518
505
  tag: "claude-ask",
519
506
  };
520
507
  // Route to session owner only — content carries prompt text.
@@ -584,6 +571,7 @@ function attachMessageProcessor(ctx) {
584
571
  });
585
572
  }
586
573
  resultPrompts.taskEnded(session, block.tool_use_id);
574
+ sessionReclaim.pruneTaskLabels(session);
587
575
  // lr-9bcd7b (widened lr-6e20f7): release the activity token
588
576
  // acquired at block_stop for this tool id, unconditionally --
589
577
  // NOT gated on activeTaskToolIds still containing the entry.
@@ -654,7 +642,7 @@ function attachMessageProcessor(ctx) {
654
642
  if (parsed.cost && parsed.cost > 0) {
655
643
  session.rateLimitResetsAt = null;
656
644
  }
657
- console.log("[sdk-bridge] result handler: session " + session.localId + " cost=" + parsed.cost + " rateLimitResetsAt=" + session.rateLimitResetsAt);
645
+ console.log("[sdk-bridge] result handler: project " + slug + " session " + session.localId + " cost=" + parsed.cost + " rateLimitResetsAt=" + session.rateLimitResetsAt);
658
646
 
659
647
  // Handle SDK execution errors: show the error to the user instead of
660
648
  // silently swallowing it. These have subtype "error_during_execution".
@@ -773,69 +761,16 @@ function attachMessageProcessor(ctx) {
773
761
  });
774
762
  }
775
763
  // Reset for next turn in the same query
776
- session.lastActivityAt = Date.now();
764
+ bumpLastActivity(session, "turn-result", slug);
777
765
  session.turnCount = (session.turnCount || 0) + 1;
778
766
  var donePreview = session.responsePreview || "";
779
767
  session.responsePreview = "";
780
768
  session.streamedText = false;
781
769
  sm.broadcastSessionList();
782
770
 
783
- // Auto-generate title after N turns (skip if loop or already auto-generated).
784
- // lr-62157d: '===' -> '>=' so a session that skips past the exact
785
- // threshold turn (early return, error path, non-result terminal event,
786
- // or a turnCount that was never persisted before this fix) still gets
787
- // titled on a later turn instead of being permanently disqualified.
788
- // Idempotence comes from !session.titleAutoGenerated, which is now
789
- // durable (see sessions.js buildMetaLine/loadSessions).
790
- if (session.turnCount >= AUTO_TITLE_TURN_THRESHOLD
791
- && !session.titleAutoGenerated
792
- && !session.titleManuallySet
793
- && !session.loop
794
- && onAutoTitle) {
795
- try { onAutoTitle(session); } catch (e) {
796
- console.error("[auto-title] onAutoTitle threw:", e.message || e);
797
- }
798
- } else {
799
- // lr-efdab6 (DRUMMER decision, comment #1): the taken branch above
800
- // already logs on every path (sdk-bridge.js [auto-title] sites) — but
801
- // logging existed on NOTHING that recorded the gate NOT firing, so
802
- // silence read identically for "ran fine and logged nothing notable",
803
- // "never invoked", and "invoked and died before the first log". That
804
- // ambiguity is exactly what let lr-62157d's dead auto-title feature
805
- // survive ~3 months / ~160 sessions undetected. This branch makes the
806
- // negative case unambiguous: every turn where the gate evaluates
807
- // false gets exactly one line naming why.
808
- //
809
- // already_auto_generated is the expected steady-state reason for the
810
- // overwhelming majority of turns in a mature session (fires every
811
- // turn after the session's title is set) and is logged at a lower
812
- // level (console.debug) so a normal journald view isn't dominated by
813
- // it; every other reason is diagnostic of a gate that should be
814
- // firing but isn't, and stays at console.log so it is visible by
815
- // default. Nothing here transmits session content — only flags/counts.
816
- var _autoTitleReason;
817
- if (!onAutoTitle) {
818
- _autoTitleReason = "no_callback";
819
- } else if (session.loop) {
820
- _autoTitleReason = "loop_running";
821
- } else if (session.titleManuallySet) {
822
- _autoTitleReason = "manually_set";
823
- } else if (session.titleAutoGenerated) {
824
- _autoTitleReason = "already_auto_generated";
825
- } else if (session.turnCount < AUTO_TITLE_TURN_THRESHOLD) {
826
- _autoTitleReason = "turn_threshold_not_met";
827
- } else {
828
- _autoTitleReason = "unknown";
829
- }
830
- var _autoTitleLogFn = (_autoTitleReason === "already_auto_generated") ? console.debug : console.log;
831
- _autoTitleLogFn(
832
- "[auto-title] gate did not fire: reason=" + _autoTitleReason
833
- + " turnCount=" + session.turnCount
834
- + " titleAutoGenerated=" + !!session.titleAutoGenerated
835
- + " titleManuallySet=" + !!session.titleManuallySet
836
- + " loop=" + !!session.loop
837
- );
838
- }
771
+ // The CLI may have written a newer title into the transcript during
772
+ // this turn; every turn picks up the latest. Never rejects.
773
+ if (refreshAiTitle) refreshAiTitle(session);
839
774
 
840
775
  if (onTurnDone) {
841
776
  try { onTurnDone(session, donePreview); } catch (e) {}
@@ -870,7 +805,7 @@ function attachMessageProcessor(ctx) {
870
805
  // matching comment on processSubagentMessage's bump above and on
871
806
  // startIdleReaper in sdk-bridge.js for why this keeps a WAITING
872
807
  // parent session non-idle for as long as its child keeps reporting in.
873
- session.lastActivityAt = Date.now();
808
+ bumpLastActivity(session, "task_started", slug);
874
809
  if (!session.taskIdMap) session.taskIdMap = {};
875
810
  session.taskIdMap[parentId] = parsed.taskId;
876
811
  sendAndRecord(session, {
@@ -884,7 +819,7 @@ function attachMessageProcessor(ctx) {
884
819
  } else if (parsed.yokeType === "task_progress") {
885
820
  var parentId = parsed.parentToolId;
886
821
  if (parentId) {
887
- session.lastActivityAt = Date.now(); // lr-f36626 — see task_started above
822
+ bumpLastActivity(session, "task_progress", slug); // see task_started above
888
823
  sendAndRecord(session, {
889
824
  type: "task_progress",
890
825
  parentToolId: parentId,
@@ -907,7 +842,7 @@ function attachMessageProcessor(ctx) {
907
842
  }
908
843
  }
909
844
  if (parentId) {
910
- session.lastActivityAt = Date.now(); // lr-f36626 — see task_started above
845
+ bumpLastActivity(session, "task_updated", slug); // see task_started above
911
846
  sendAndRecord(session, {
912
847
  type: "task_updated",
913
848
  parentToolId: parentId,
@@ -920,7 +855,7 @@ function attachMessageProcessor(ctx) {
920
855
  // Sub-agent tool_progress: forward as activity update
921
856
  var parentId = parsed.parentToolId;
922
857
  if (parentId) {
923
- session.lastActivityAt = Date.now(); // lr-f36626 — see task_started above
858
+ bumpLastActivity(session, "tool_progress", slug); // see task_started above
924
859
  sendAndRecord(session, {
925
860
  type: "subagent_activity",
926
861
  parentToolId: parentId,
@@ -962,7 +897,10 @@ function attachMessageProcessor(ctx) {
962
897
  // The sub-agent is done. Its tracking and ownership records are
963
898
  // released, except for a prompt still awaiting the operator, which
964
899
  // keeps the Task in scope until it settles.
965
- if (parentId) notifiedPrompts.taskEnded(session, parentId);
900
+ if (parentId) {
901
+ notifiedPrompts.taskEnded(session, parentId);
902
+ sessionReclaim.pruneTaskLabels(session);
903
+ }
966
904
 
967
905
  } else if (parsed.yokeType === "rate_limit") {
968
906
  var info = parsed.rateLimitInfo;
@@ -203,6 +203,66 @@ function extractDescriptionFromContent(content) {
203
203
  return "";
204
204
  }
205
205
 
206
+ // Where skills live, lowest precedence first: each agent reads its own native
207
+ // location (Claude .claude/skills, Codex .agents/skills), and the console
208
+ // presents one list from all of them. A project's skill beats the user's of the
209
+ // same name, and within a level the directory of the agent the list is for beats
210
+ // the other's: .claude by default, .agents when preferAgentsDir is set (the list
211
+ // for a session of the agent that reads .agents/skills natively).
212
+ function skillRoots(cwd, globalHome, preferAgentsDir) {
213
+ var first = preferAgentsDir ? ".claude" : ".agents";
214
+ var second = preferAgentsDir ? ".agents" : ".claude";
215
+ var roots = [];
216
+ if (globalHome) {
217
+ roots.push(path.join(globalHome, first, "skills"));
218
+ roots.push(path.join(globalHome, second, "skills"));
219
+ }
220
+ if (cwd) {
221
+ roots.push(path.join(cwd, first, "skills"));
222
+ roots.push(path.join(cwd, second, "skills"));
223
+ }
224
+ return roots;
225
+ }
226
+
227
+ // A directory or file that is simply not there is the ordinary case (a user
228
+ // without a .agents directory) and stays quiet. Anything else (permissions, an
229
+ // I/O fault) hides skills the user has, so it is named in the log.
230
+ function warnUnlessAbsent(what, target, err) {
231
+ if (err && (err.code === "ENOENT" || err.code === "ENOTDIR")) return;
232
+ console.warn("[skills] could not read " + what + " " + target + ": " + (err && err.code ? err.code : (err && err.message) || err));
233
+ }
234
+
235
+ // name -> the skill's real directory, for every skill in every root. A name
236
+ // from a directory listing never indexes an ordinary object.
237
+ function collectSkillDirs(cwd, globalHome, preferAgentsDir) {
238
+ var byName = Object.create(null);
239
+ var roots = skillRoots(cwd, globalHome, preferAgentsDir);
240
+ for (var d = 0; d < roots.length; d++) {
241
+ var base = roots[d];
242
+ var entries;
243
+ try {
244
+ entries = fs.readdirSync(base, { withFileTypes: true });
245
+ } catch (e) {
246
+ warnUnlessAbsent("skills directory", base, e);
247
+ continue;
248
+ }
249
+ for (var i = 0; i < entries.length; i++) {
250
+ var entry = entries[i];
251
+ if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
252
+ var skillDir = resolveContainedSkillDir(base, entry.name);
253
+ if (!skillDir) continue;
254
+ var skillMd = path.join(skillDir, "SKILL.md");
255
+ try {
256
+ fs.accessSync(skillMd, fs.constants.R_OK);
257
+ byName[entry.name] = skillDir;
258
+ } catch (e) {
259
+ warnUnlessAbsent("skill file", skillMd, e);
260
+ }
261
+ }
262
+ }
263
+ return byName;
264
+ }
265
+
206
266
  // Read SKILL.md for a skill directory and extract a short description string.
207
267
  // Delegates to extractDescriptionFromContent for the actual parsing logic.
208
268
  function extractSkillDescription(skillDir) {
@@ -226,36 +286,8 @@ function extractSkillDescription(skillDir) {
226
286
  // it here so the global skills dir is the invoking user's own ~/.claude/skills,
227
287
  // not the daemon process's REAL_HOME (lr-3ccc78). Falls back to REAL_HOME when
228
288
  // absent — the single-user / no-OS-isolation case, unchanged behavior.
229
- function discoverSkillsWithMeta(cwd, homeOverride) {
230
- var globalHome = homeOverride || require("./config").REAL_HOME;
231
- var dirs = [
232
- path.join(globalHome, ".claude", "skills"),
233
- path.join(cwd, ".claude", "skills"),
234
- ];
235
- // Ordered map so project skills override global skills
236
- var byName = {};
237
- for (var d = 0; d < dirs.length; d++) {
238
- var base = dirs[d];
239
- var entries;
240
- try {
241
- entries = fs.readdirSync(base, { withFileTypes: true });
242
- } catch (e) {
243
- continue;
244
- }
245
- for (var i = 0; i < entries.length; i++) {
246
- var entry = entries[i];
247
- if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
248
- var skillDir = resolveContainedSkillDir(base, entry.name);
249
- if (!skillDir) continue;
250
- var skillMdPath = path.join(skillDir, "SKILL.md");
251
- try {
252
- fs.accessSync(skillMdPath, fs.constants.R_OK);
253
- byName[entry.name] = skillDir;
254
- } catch (e) {
255
- // no SKILL.md, skip
256
- }
257
- }
258
- }
289
+ function discoverSkillsWithMeta(cwd, homeOverride, preferAgentsDir) {
290
+ var byName = collectSkillDirs(cwd, homeOverride || require("./config").REAL_HOME, preferAgentsDir);
259
291
  var result = [];
260
292
  var names = Object.keys(byName);
261
293
  for (var j = 0; j < names.length; j++) {
@@ -306,36 +338,7 @@ function attachSkillDiscovery(ctx) {
306
338
  // above) so a caller can resolve the session owner's home instead of the
307
339
  // daemon's REAL_HOME on a shared multi-user daemon (lr-3ccc78).
308
340
  function discoverSkillDirs(homeOverride) {
309
- var skills = {};
310
- var globalHome = homeOverride || require("./config").REAL_HOME;
311
- var dirs = [
312
- path.join(globalHome, ".claude", "skills"),
313
- path.join(cwd, ".claude", "skills"),
314
- ];
315
- for (var d = 0; d < dirs.length; d++) {
316
- var base = dirs[d];
317
- var entries;
318
- try {
319
- entries = fs.readdirSync(base, { withFileTypes: true });
320
- } catch (e) {
321
- continue; // directory doesn't exist
322
- }
323
- for (var i = 0; i < entries.length; i++) {
324
- var entry = entries[i];
325
- if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
326
- var skillDir = resolveContainedSkillDir(base, entry.name);
327
- if (!skillDir) continue;
328
- var skillMd = path.join(skillDir, "SKILL.md");
329
- try {
330
- fs.accessSync(skillMd, fs.constants.R_OK);
331
- // project skills override global skills with same name
332
- skills[entry.name] = skillDir;
333
- } catch (e) {
334
- // no SKILL.md, skip
335
- }
336
- }
337
- }
338
- return skills;
341
+ return collectSkillDirs(cwd, homeOverride || require("./config").REAL_HOME);
339
342
  }
340
343
 
341
344
  function mergeSkills(sdkSkills, fsSkills) {
@@ -366,4 +369,6 @@ module.exports = {
366
369
  // reuse the same two-stage (lexical + realpath) containment check instead
367
370
  // of approximating it — see the function's own doc comment.
368
371
  resolveContainedSkillDir: resolveContainedSkillDir,
372
+ collectSkillDirs: collectSkillDirs,
373
+ skillRoots: skillRoots,
369
374
  };
package/lib/server.js CHANGED
@@ -22,6 +22,7 @@ var { computeAllProjectSessions } = require("./server-hub-sessions");
22
22
  var { resolveEffectiveProtocol } = require("./effective-protocol");
23
23
  var { createProjectAccess } = require("./project-access");
24
24
  var { checkWsOrigin } = require("./ws-origin");
25
+ var sessionReclaim = require("./session-reclaim");
25
26
 
26
27
  var https = require("https");
27
28
  var pkg = require("../package.json");
@@ -289,6 +290,7 @@ function createServer(opts) {
289
290
  var onShutdown = opts.onShutdown || null;
290
291
  var onRestart = opts.onRestart || null;
291
292
  var onRestartForBuildUpdate = opts.onRestartForBuildUpdate || null;
293
+ var onGetBuildUpdateDiagnostic = opts.onGetBuildUpdateDiagnostic || null;
292
294
  var onSetUpdateChannel = opts.onSetUpdateChannel || null;
293
295
  var onSetProjectVisibility = opts.onSetProjectVisibility || null;
294
296
  var onSetProjectAllowedUsers = opts.onSetProjectAllowedUsers || null;
@@ -395,9 +397,15 @@ function createServer(opts) {
395
397
  // emitted — the trigger carries its own notification channel (e.g. ntfy).
396
398
  var { attachExternalTrigger } = require("./project-external-trigger");
397
399
  var { EXTERNAL_TRIGGERS_DIR } = require("./config");
400
+ // One implementation for the file drop and the daemon IPC verbs (open-session,
401
+ // send-input).
402
+ var _sessionInput = require("./session-input").createSessionInput({
403
+ getProject: function (slug) { return projects.get(slug) || null; },
404
+ });
398
405
  var _externalTrigger = attachExternalTrigger({
399
406
  triggersDir: EXTERNAL_TRIGGERS_DIR,
400
407
  getProject: function (slug) { return projects.get(slug) || null; },
408
+ sessionInput: _sessionInput,
401
409
  });
402
410
  _externalTrigger.startWatcher();
403
411
 
@@ -1483,6 +1491,7 @@ function createServer(opts) {
1483
1491
  onShutdown: onShutdown,
1484
1492
  onRestart: onRestart,
1485
1493
  onRestartForBuildUpdate: onRestartForBuildUpdate,
1494
+ onGetBuildUpdateDiagnostic: onGetBuildUpdateDiagnostic,
1486
1495
  onDmMessage: handleDmMessage,
1487
1496
  broadcastAll: broadcastAll,
1488
1497
  notificationsModule: _globalNotifications,
@@ -1518,7 +1527,8 @@ function createServer(opts) {
1518
1527
  function removeProject(slug) {
1519
1528
  var ctx = projects.get(slug);
1520
1529
  if (!ctx) return false;
1521
- var shutdownResult = ctx.destroy();
1530
+ // A deliberate removal: its sessions are not recorded as resumable.
1531
+ var shutdownResult = ctx.destroy({ reason: "project_removed" });
1522
1532
  projects.delete(slug);
1523
1533
  if (shutdownResult && typeof shutdownResult.catch === "function") {
1524
1534
  shutdownResult.catch(function(err) {
@@ -1742,9 +1752,10 @@ function createServer(opts) {
1742
1752
  function destroyAll() {
1743
1753
  _externalTrigger.stopWatcher();
1744
1754
  var shutdowns = [];
1755
+ var tally = sessionReclaim.createShutdownTally();
1745
1756
  projects.forEach(function (ctx, slug) {
1746
1757
  console.log("[server] Destroying project:", slug);
1747
- var result = ctx.destroy();
1758
+ var result = ctx.destroy({ reason: sessionReclaim.RESTART_REASON, tally: tally });
1748
1759
  if (result && typeof result.then === "function") {
1749
1760
  shutdowns.push(result.catch(function(err) {
1750
1761
  console.error("[server] Project destroy failed for " + slug + ":", err && err.message ? err.message : err);
@@ -1753,6 +1764,7 @@ function createServer(opts) {
1753
1764
  }
1754
1765
  });
1755
1766
  projects.clear();
1767
+ sessionReclaim.logShutdownSummary(tally);
1756
1768
  return Promise.all(shutdowns);
1757
1769
  }
1758
1770
 
@@ -1822,6 +1834,7 @@ function createServer(opts) {
1822
1834
  clearRecovery: auth.clearRecovery,
1823
1835
  broadcastAll: broadcastAll,
1824
1836
  forEachProject: forEachProject,
1837
+ sessionInput: _sessionInput,
1825
1838
  destroyProject: removeProject,
1826
1839
  destroyAll: destroyAll,
1827
1840
  // Drain controller injection (lr-6b30).
@@ -0,0 +1,80 @@
1
+ // session-ai-title.js - gives a session the title its vendor CLI wrote for it.
2
+ //
3
+ // The console never asks a model for a title. The Claude Code CLI titles each
4
+ // session itself and records it in the session's transcript
5
+ // (cli-transcript-title.js); this module copies the latest such title onto the
6
+ // console session, which is the one place every surface (the picker, prompt
7
+ // cards, banners and push, the restart interrupt list, CLI listings) reads a
8
+ // title from.
9
+ //
10
+ // Precedence: a title the operator set by rename always wins; otherwise the
11
+ // CLI's title replaces whatever the first-line fallback put there; a session
12
+ // whose transcript holds no title keeps the first-line title.
13
+
14
+ var path = require("path");
15
+ var transcriptTitle = require("./cli-transcript-title");
16
+ var runtimeEnv = require("./runtime-env");
17
+
18
+ // Vendors whose sessions have a Claude Code transcript. Another vendor's
19
+ // thread id names no transcript here, so it is never looked up.
20
+ function hasCliTranscript(session) {
21
+ return !session.vendor || session.vendor === "claude";
22
+ }
23
+
24
+ // deps: {
25
+ // sm session manager (saveSessionFile, broadcastSessionList)
26
+ // cwd the project directory
27
+ // resolveHome(session) the session owner's home, or null for the daemon's own
28
+ // daemonHome the daemon user's home
29
+ // getRuntimeEnvOverlay?(session) the Settings variables the session's Claude
30
+ // process was started with, or null
31
+ // claudeDir? overrides the transcript root (tests)
32
+ // }
33
+ // Returns refresh(session): Promise<boolean>, true when the title changed.
34
+ function createAiTitleRefresher(deps) {
35
+ var sm = deps.sm;
36
+
37
+ // The CLAUDE_CONFIG_DIR the session's process was given by Settings. Read
38
+ // through composeRuntimeEnv so a name the runtime drops is dropped here too.
39
+ function overlayConfigDir(session) {
40
+ var overlay = deps.getRuntimeEnvOverlay ? deps.getRuntimeEnvOverlay(session) : null;
41
+ if (!overlay) return null;
42
+ var dir = runtimeEnv.composeRuntimeEnv({}, overlay).CLAUDE_CONFIG_DIR;
43
+ return dir || null;
44
+ }
45
+
46
+ // Same order the session's process resolves its config: Settings overlay,
47
+ // then the owner's home, then the daemon's own variable and home.
48
+ function claudeDirFor(session) {
49
+ if (deps.claudeDir) return deps.claudeDir;
50
+ var overlayDir = overlayConfigDir(session);
51
+ if (overlayDir) return overlayDir;
52
+ var ownerHome = deps.resolveHome ? deps.resolveHome(session) : null;
53
+ if (ownerHome) return path.join(ownerHome, ".claude");
54
+ return process.env.CLAUDE_CONFIG_DIR || path.join(deps.daemonHome, ".claude");
55
+ }
56
+
57
+ return function refresh(session) {
58
+ if (!session || !session.cliSessionId || session.titleManuallySet) return Promise.resolve(false);
59
+ if (!hasCliTranscript(session)) return Promise.resolve(false);
60
+ var sessionId = session.cliSessionId;
61
+ return transcriptTitle.findTranscript(claudeDirFor(session), [session.cwd, deps.cwd], sessionId)
62
+ .then(function (file) { return file ? transcriptTitle.readLatestAiTitle(file, sessionId) : null; })
63
+ .then(function (title) {
64
+ // Re-checked after the read: a rename can land while the file is read.
65
+ if (!title || session.titleManuallySet || session.title === title) return false;
66
+ session.title = title;
67
+ session.titleAutoGenerated = true;
68
+ session.titleProvisional = false;
69
+ sm.saveSessionFile(session);
70
+ sm.broadcastSessionList();
71
+ return true;
72
+ })
73
+ .catch(function (e) {
74
+ console.error("[ai-title] could not read the session title:", e && e.message ? e.message : e);
75
+ return false;
76
+ });
77
+ };
78
+ }
79
+
80
+ module.exports = { createAiTitleRefresher: createAiTitleRefresher };
@@ -0,0 +1,33 @@
1
+ // session-id.js - the one place a session id is checked before it becomes part
2
+ // of a file path. An id arrives from outside (a browser message, an injected
3
+ // input), so it is validated before any filesystem use and every path built from
4
+ // it is checked to stay inside the directory it is meant for.
5
+
6
+ var path = require("path");
7
+
8
+ // Letters, digits, "_" and "-", not starting with a separator-like character.
9
+ var SAFE_SESSION_ID = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
10
+
11
+ function isSafeSessionId(id) {
12
+ return typeof id === "string" && SAFE_SESSION_ID.test(id);
13
+ }
14
+
15
+ // Returns <dir>/<id><ext>, throwing when the id is unsafe or the resolved path
16
+ // is not inside dir. The containment check is separate from the allowlist so a
17
+ // later loosening of the allowlist cannot reopen traversal.
18
+ function sessionPathWithin(dir, id, ext) {
19
+ if (!isSafeSessionId(id)) {
20
+ throw new Error("unsafe session id " + JSON.stringify(String(id).slice(0, 64)));
21
+ }
22
+ var root = path.resolve(dir);
23
+ var full = path.resolve(root, id + ext);
24
+ if (full.indexOf(root + path.sep) !== 0) {
25
+ throw new Error("session path escapes its directory: " + JSON.stringify(String(id).slice(0, 64)));
26
+ }
27
+ return full;
28
+ }
29
+
30
+ module.exports = {
31
+ isSafeSessionId: isSafeSessionId,
32
+ sessionPathWithin: sessionPathWithin,
33
+ };
@@ -0,0 +1,32 @@
1
+ // session-input-ipc.js - the daemon IPC side of open-session and send-input:
2
+ // which fields of an IPC message reach lib/session-input.js. Kept out of
3
+ // daemon.js so the handler a CLI call reaches can be exercised without booting
4
+ // the daemon.
5
+
6
+ // Handles one IPC message with a session-input instance. Returns the result
7
+ // (or a Promise of it), or undefined when msg.cmd is not a session command.
8
+ function handleSessionCommand(sessionInput, msg) {
9
+ if (msg.cmd === "open_session") {
10
+ return sessionInput.openSession({
11
+ projectSlug: msg.projectSlug,
12
+ prompt: msg.prompt,
13
+ contextNote: msg.contextNote,
14
+ vendor: msg.vendor,
15
+ agentName: msg.agentName,
16
+ sessionVisibility: msg.sessionVisibility,
17
+ initiator: msg.initiator,
18
+ });
19
+ }
20
+ if (msg.cmd === "send_session_input") {
21
+ return sessionInput.sendInput({
22
+ projectSlug: msg.projectSlug,
23
+ sessionId: msg.sessionId,
24
+ prompt: msg.prompt,
25
+ contextNote: msg.contextNote,
26
+ initiator: msg.initiator,
27
+ });
28
+ }
29
+ return undefined;
30
+ }
31
+
32
+ module.exports = { handleSessionCommand: handleSessionCommand };