@clagentic/console 1.5.0 → 1.6.0-beta.2

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 (66) hide show
  1. package/README.md +23 -4
  2. package/bin/cli.js +15 -82
  3. package/lib/agents-favorites.js +21 -6
  4. package/lib/config.js +1 -1
  5. package/lib/daemon.js +153 -22
  6. package/lib/drain.js +213 -0
  7. package/lib/lite-detect.js +6 -5
  8. package/lib/loop-handoff.js +282 -0
  9. package/lib/mcp-local.js +18 -2
  10. package/lib/memory-limits.js +436 -0
  11. package/lib/model-context-windows.js +65 -0
  12. package/lib/project-loop.js +31 -3
  13. package/lib/project-sessions.js +26 -0
  14. package/lib/project-team.js +4 -1
  15. package/lib/project.js +8 -0
  16. package/lib/public/app.js +4 -0
  17. package/lib/public/css/base.css +18 -0
  18. package/lib/public/css/diagnostics.css +279 -0
  19. package/lib/public/css/icon-strip.css +201 -0
  20. package/lib/public/css/menus.css +2 -2
  21. package/lib/public/css/mobile-nav.css +24 -0
  22. package/lib/public/css/server-settings.css +100 -0
  23. package/lib/public/index.html +26 -0
  24. package/lib/public/modules/app-header.js +4 -7
  25. package/lib/public/modules/app-home-hub.js +31 -7
  26. package/lib/public/modules/app-messages.js +13 -0
  27. package/lib/public/modules/app-notifications.js +5 -1
  28. package/lib/public/modules/app-panels.js +11 -21
  29. package/lib/public/modules/app-projects.js +10 -5
  30. package/lib/public/modules/command-palette.js +16 -5
  31. package/lib/public/modules/custom-icons-settings.js +399 -0
  32. package/lib/public/modules/custom-icons.js +114 -0
  33. package/lib/public/modules/diagnostic-format.js +34 -0
  34. package/lib/public/modules/diagnostics.js +297 -0
  35. package/lib/public/modules/emoji-picker.js +253 -6
  36. package/lib/public/modules/model-context-windows.js +62 -0
  37. package/lib/public/modules/popover-position.js +192 -0
  38. package/lib/public/modules/project-icon.js +113 -0
  39. package/lib/public/modules/project-settings.js +2 -2
  40. package/lib/public/modules/project-switcher.js +2 -1
  41. package/lib/public/modules/scheduler-config.js +5 -8
  42. package/lib/public/modules/scheduler.js +5 -6
  43. package/lib/public/modules/server-settings.js +6 -0
  44. package/lib/public/modules/sidebar-mobile.js +4 -6
  45. package/lib/public/modules/sidebar-projects.js +35 -90
  46. package/lib/public/modules/sidebar-sessions.js +6 -20
  47. package/lib/public/modules/sticky-notes.js +4 -4
  48. package/lib/public/modules/terminal.js +5 -12
  49. package/lib/public/style.css +1 -0
  50. package/lib/sdk-bridge.js +75 -10
  51. package/lib/sdk-message-processor.js +12 -0
  52. package/lib/sdk-worker.js +4 -1
  53. package/lib/server-settings.js +221 -1
  54. package/lib/server.js +30 -1
  55. package/lib/sessions.js +27 -11
  56. package/lib/settings-preflight.js +212 -0
  57. package/lib/ws-schema.js +2 -0
  58. package/lib/yoke/adapters/claude-worker.js +14 -2
  59. package/lib/yoke/adapters/claude.js +16 -0
  60. package/lib/yoke/adapters/diagnostic-patterns.js +120 -0
  61. package/lib/yoke/index.js +4 -0
  62. package/lib/yoke/interface.js +99 -0
  63. package/package.json +2 -1
  64. package/scripts/postinstall.js +41 -0
  65. package/lib/certs/fullchain.pem +0 -47
  66. package/lib/certs/privkey.pem +0 -5
package/lib/drain.js ADDED
@@ -0,0 +1,213 @@
1
+ // drain.js — graceful drain state for the daemon (lr-6b30).
2
+ //
3
+ // Drain is entered when either:
4
+ // A. The lr-de07 MemoryHigh watermark watcher fires an onCrossing callback.
5
+ // B. An operator sends SIGUSR1 or SIGUSR2 (manual drain/restart signal).
6
+ //
7
+ // While draining:
8
+ // - New WebSocket session connections are rejected with a structured error.
9
+ // - In-flight sessions are allowed to complete. The drain controller checks
10
+ // the live query count via opts.getActiveCount() and exits once it hits zero.
11
+ // - A configurable drain timeout (default 60 s) forces exit if sessions do
12
+ // not complete in time.
13
+ //
14
+ // The module exports createDrain(opts), which returns a controller object used
15
+ // by daemon.js and the WebSocket gate in server.js.
16
+ //
17
+ // Design constraints:
18
+ // - No second memory poller; consume startMemoryHighWatcher's signal only.
19
+ // - Reuse gracefulShutdown() from daemon.js; do not invent a parallel path.
20
+ // - One drain state machine; both trigger paths set the same state.
21
+
22
+ 'use strict';
23
+
24
+ // Default drain timeout in milliseconds.
25
+ var DEFAULT_DRAIN_TIMEOUT_MS = 60 * 1000;
26
+
27
+ // How often to check the live-query count after entering drain state.
28
+ var DRAIN_POLL_INTERVAL_MS = 1000;
29
+
30
+ /**
31
+ * Create a drain controller.
32
+ *
33
+ * @param {object} opts
34
+ * @param {function(): void} opts.gracefulShutdown
35
+ * Called when all in-flight sessions complete (or timeout expires).
36
+ * @param {function(): number} opts.getActiveCount
37
+ * Returns the current number of in-flight queries. Provided by daemon.js
38
+ * from sdk-bridge's getActiveLiveCount(). Queried on a 1-second interval
39
+ * after drain is entered.
40
+ * @param {number} [opts.drainTimeoutMs]
41
+ * Maximum ms to wait for in-flight sessions before forcing exit.
42
+ * Reads from config.drainTimeoutMs if provided; defaults to 60000.
43
+ * @param {function(object): void} [opts.log]
44
+ * Structured log emitter. Receives a plain object; default emits JSON to
45
+ * stderr so journald captures it alongside other daemon output.
46
+ *
47
+ * @returns {DrainController}
48
+ */
49
+ function createDrain(opts) {
50
+ if (!opts || typeof opts.gracefulShutdown !== 'function') {
51
+ throw new Error('drain.createDrain: opts.gracefulShutdown must be a function');
52
+ }
53
+ if (typeof opts.getActiveCount !== 'function') {
54
+ throw new Error('drain.createDrain: opts.getActiveCount must be a function');
55
+ }
56
+
57
+ var gracefulShutdown = opts.gracefulShutdown;
58
+ var getActiveCount = opts.getActiveCount;
59
+ var drainTimeoutMs = (opts.drainTimeoutMs != null && opts.drainTimeoutMs > 0)
60
+ ? opts.drainTimeoutMs
61
+ : DEFAULT_DRAIN_TIMEOUT_MS;
62
+
63
+ var _log = opts.log || function (event) {
64
+ try {
65
+ process.stderr.write('[drain] ' + JSON.stringify(event) + '\n');
66
+ } catch (_) {}
67
+ };
68
+
69
+ // --- State ---
70
+ var _isDraining = false;
71
+ var _drainReason = null;
72
+ var _drainTimeout = null;
73
+ var _drainPollHandle = null;
74
+ var _signalsRegistered = false;
75
+ var _exitCalled = false;
76
+
77
+ // --- Internal helpers ---
78
+
79
+ function _emitLog(event) {
80
+ try { _log(event); } catch (_) {}
81
+ }
82
+
83
+ function _callExit(reason) {
84
+ if (_exitCalled) return;
85
+ _exitCalled = true;
86
+ _clearTimers();
87
+ _emitLog({
88
+ event: 'drain_exit',
89
+ reason: reason,
90
+ activeCount: getActiveCount(),
91
+ timestamp: new Date().toISOString(),
92
+ });
93
+ gracefulShutdown();
94
+ }
95
+
96
+ function _clearTimers() {
97
+ if (_drainTimeout) {
98
+ clearTimeout(_drainTimeout);
99
+ _drainTimeout = null;
100
+ }
101
+ if (_drainPollHandle) {
102
+ clearInterval(_drainPollHandle);
103
+ _drainPollHandle = null;
104
+ }
105
+ }
106
+
107
+ function _checkActiveCount() {
108
+ if (!_isDraining || _exitCalled) return;
109
+ var count = getActiveCount();
110
+ if (count <= 0) {
111
+ _callExit('active_count_zero');
112
+ }
113
+ }
114
+
115
+ function _forceExit() {
116
+ _callExit('timeout_forced');
117
+ }
118
+
119
+ // --- Public API ---
120
+
121
+ /**
122
+ * Enter drain state. Idempotent: subsequent calls from either trigger path
123
+ * are no-ops — only the first crossing matters.
124
+ *
125
+ * @param {string} reason — 'memory_high_watermark' | 'signal_usr1' | 'signal_usr2'
126
+ * @param {object} [detail] — optional extra fields for the log event
127
+ */
128
+ function enterDrain(reason, detail) {
129
+ if (_isDraining) return; // already draining — idempotent
130
+ _isDraining = true;
131
+ _drainReason = reason;
132
+
133
+ var activeCount = getActiveCount();
134
+ var logEvent = Object.assign({
135
+ event: 'drain_enter',
136
+ reason: reason,
137
+ activeCount: activeCount,
138
+ drainTimeoutMs: drainTimeoutMs,
139
+ timestamp: new Date().toISOString(),
140
+ }, detail || {});
141
+ _emitLog(logEvent);
142
+
143
+ // If no sessions are currently active, exit immediately.
144
+ if (activeCount <= 0) {
145
+ _callExit('active_count_zero');
146
+ return;
147
+ }
148
+
149
+ // Arm the timeout guard so a stuck session cannot hold the daemon up forever.
150
+ _drainTimeout = setTimeout(_forceExit, drainTimeoutMs);
151
+ // Unref so the timeout alone does not prevent other exit paths.
152
+ if (_drainTimeout && typeof _drainTimeout.unref === 'function') {
153
+ _drainTimeout.unref();
154
+ }
155
+
156
+ // Poll the live-query count every second so we exit as soon as sessions finish.
157
+ _drainPollHandle = setInterval(_checkActiveCount, DRAIN_POLL_INTERVAL_MS);
158
+ if (_drainPollHandle && typeof _drainPollHandle.unref === 'function') {
159
+ _drainPollHandle.unref();
160
+ }
161
+ }
162
+
163
+ /**
164
+ * Returns true when the daemon is in drain state.
165
+ *
166
+ * @returns {boolean}
167
+ */
168
+ function isDraining() {
169
+ return _isDraining;
170
+ }
171
+
172
+ /**
173
+ * Register SIGUSR1 and SIGUSR2 as manual drain triggers.
174
+ *
175
+ * Idempotent: safe to call multiple times.
176
+ */
177
+ function registerSignals() {
178
+ if (_signalsRegistered) return;
179
+ _signalsRegistered = true;
180
+
181
+ // SIGUSR1 is used by Node.js built-in debugger on some platforms — we still
182
+ // register it because this daemon does not use the built-in debugger in
183
+ // production, and operator-initiated drain is the intended use case here.
184
+ process.on('SIGUSR1', function () {
185
+ enterDrain('signal_usr1');
186
+ });
187
+ process.on('SIGUSR2', function () {
188
+ enterDrain('signal_usr2');
189
+ });
190
+ }
191
+
192
+ /**
193
+ * Called by the MemoryHigh watcher's onCrossing callback.
194
+ * Enters drain state with the watermark event detail attached to the log.
195
+ *
196
+ * @param {object} [detail] — fields from the watermark event (source, currentBytes, etc.)
197
+ */
198
+ function onMemoryHighCrossing(detail) {
199
+ enterDrain('memory_high_watermark', detail || {});
200
+ }
201
+
202
+ return {
203
+ isDraining: isDraining,
204
+ enterDrain: enterDrain,
205
+ registerSignals: registerSignals,
206
+ onMemoryHighCrossing: onMemoryHighCrossing,
207
+ // Exposed for testing only.
208
+ _DEFAULT_DRAIN_TIMEOUT_MS: DEFAULT_DRAIN_TIMEOUT_MS,
209
+ _DRAIN_POLL_INTERVAL_MS: DRAIN_POLL_INTERVAL_MS,
210
+ };
211
+ }
212
+
213
+ module.exports = { createDrain: createDrain, DEFAULT_DRAIN_TIMEOUT_MS: DEFAULT_DRAIN_TIMEOUT_MS };
@@ -7,13 +7,14 @@
7
7
  var fs = require("fs");
8
8
  var path = require("path");
9
9
  var { execFileSync } = require("child_process");
10
- var { CONFIG_DIR, REAL_HOME } = require("./config");
10
+ var { CLAGENTIC_HOME, REAL_HOME } = require("./config");
11
11
 
12
- // Lite home: <CONFIG_DIR>/lite/ — mirrors the path contract established in lr-dc6c.
13
- // CONFIG_DIR is the canonical clagentic data directory (resolves CLAGENTIC_HOME,
14
- // sudo users, and legacy ~/.clay/ migration the same way as every other daemon path).
12
+ // Lite home: ~/.clagentic/lite/ — Lite is a sibling tool that owns its own product
13
+ // folder under the shared ~/.clagentic/ root (lr-dc6c, lr-6204).
14
+ // Console owns ~/.clagentic/console/; Lite owns ~/.clagentic/lite/.
15
+ // Override: CLAGENTIC_LITE_HOME env var (matches clagentic-lite/bin/clagentic-lite:33).
15
16
  function getLiteHome() {
16
- return path.join(CONFIG_DIR, "lite");
17
+ return process.env.CLAGENTIC_LITE_HOME || path.join(CLAGENTIC_HOME, "lite");
17
18
  }
18
19
 
19
20
  // Return true when the Lite home directory exists.
@@ -0,0 +1,282 @@
1
+ /**
2
+ * Ralph Loop boundary compaction / handoff-to-disk (lr-ed10).
3
+ *
4
+ * At the completion of each loop iteration (the BOUNDARY between iterations),
5
+ * this module optionally writes a structured handoff file to disk and returns
6
+ * a brief summary that the next iteration prepends to its prompt.
7
+ *
8
+ * Design:
9
+ * - Opt-in only. No effect unless loopSettings.compactHandoff === true.
10
+ * - Handoff directory: CONFIG_DIR/handoffs/<loopId>/ — derived from the same
11
+ * config-dir root the rest of Console uses (lr-6204 path contract).
12
+ * - Each handoff file is named handoff-<N>.json (N = iteration number).
13
+ * - The structured frame contains: task, decisions, open_threads, key_files,
14
+ * verdict, iteration, timestamp. All fields are populated from the session
15
+ * history at the iteration boundary; fallback to empty when unavailable.
16
+ * - The summary injected into the next iteration is intentionally brief:
17
+ * a few lines of plain text covering just the fields above. It is
18
+ * prepended to the original PROMPT.md text by the caller.
19
+ * - Clean degradation: if the write fails the loop continues unchanged;
20
+ * if the read fails (no prior handoff exists) the loop continues unchanged.
21
+ *
22
+ * No new dependencies: uses only Node built-ins (fs, path, crypto).
23
+ */
24
+
25
+ "use strict";
26
+
27
+ var fs = require("fs");
28
+ var path = require("path");
29
+ var { CONFIG_DIR } = require("./config");
30
+
31
+ // ---------------------------------------------------------------------------
32
+ // Internal helpers
33
+ // ---------------------------------------------------------------------------
34
+
35
+ /**
36
+ * Build the handoff directory path for a given loopId.
37
+ * Always derived from CONFIG_DIR — never an absolute caller-supplied path.
38
+ * Returns null if loopId is missing or fails the safety regex.
39
+ *
40
+ * @param {string} loopId
41
+ * @returns {string|null}
42
+ */
43
+ function handoffDir(loopId) {
44
+ // Mirror the loop ID allowlist from scheduler.js / project-loop.js.
45
+ if (!loopId || !/^loop_[A-Za-z0-9_-]+$/.test(loopId)) return null;
46
+ return path.join(CONFIG_DIR, "handoffs", loopId);
47
+ }
48
+
49
+ /**
50
+ * Return the path for iteration N's handoff file.
51
+ * @param {string} loopId
52
+ * @param {number} iteration
53
+ * @returns {string|null}
54
+ */
55
+ function handoffFilePath(loopId, iteration) {
56
+ var dir = handoffDir(loopId);
57
+ if (!dir) return null;
58
+ return path.join(dir, "handoff-" + iteration + ".json");
59
+ }
60
+
61
+ /**
62
+ * Extract a brief human-readable summary from a completed session's history.
63
+ * Looks at the last assistant text blocks for decision/thread content.
64
+ * Returns a string up to ~1 000 chars — enough for a continuation frame
65
+ * without re-inflating the context.
66
+ *
67
+ * @param {Array} history session.history array
68
+ * @returns {string}
69
+ */
70
+ function extractSessionSummary(history) {
71
+ if (!Array.isArray(history) || history.length === 0) return "";
72
+
73
+ // Collect assistant text in reverse order until we have ~800 chars.
74
+ var chunks = [];
75
+ var total = 0;
76
+ for (var i = history.length - 1; i >= 0 && total < 800; i--) {
77
+ var entry = history[i];
78
+ var text = "";
79
+ if (entry.type === "delta" && entry.text) text = entry.text;
80
+ else if (entry.type === "text" && entry.text) text = entry.text;
81
+ if (text) {
82
+ chunks.unshift(text);
83
+ total += text.length;
84
+ }
85
+ }
86
+ return chunks.join("").slice(-800).trim();
87
+ }
88
+
89
+ /**
90
+ * Scan assistant text for lines that look like decisions or open items.
91
+ * Very lightweight heuristic — just extracts bullet-style lines.
92
+ *
93
+ * @param {string} text
94
+ * @returns {{ decisions: string[], open_threads: string[] }}
95
+ */
96
+ function parseDecisionsAndThreads(text) {
97
+ var decisions = [];
98
+ var threads = [];
99
+ if (!text) return { decisions: decisions, open_threads: threads };
100
+
101
+ var lines = text.split(/\r?\n/);
102
+ for (var i = 0; i < lines.length; i++) {
103
+ var line = lines[i].trim();
104
+ // Bullet / numbered list items
105
+ var isBullet = /^[-*•]\s+/.test(line) || /^\d+\.\s+/.test(line);
106
+ if (!isBullet || line.length < 5) continue;
107
+
108
+ var lower = line.toLowerCase();
109
+ // Decision-like: keywords that suggest a resolved choice
110
+ if (/\b(decided|chose|using|implemented|added|fixed|completed|done)\b/.test(lower)) {
111
+ decisions.push(line.substring(0, 120));
112
+ }
113
+ // Thread-like: keywords that suggest something still open
114
+ if (/\b(todo|open|still|pending|not yet|need to|should|must|missing|blocked)\b/.test(lower)) {
115
+ threads.push(line.substring(0, 120));
116
+ }
117
+ }
118
+ // Keep only the most recent N items to bound size
119
+ return {
120
+ decisions: decisions.slice(-5),
121
+ open_threads: threads.slice(-5),
122
+ };
123
+ }
124
+
125
+ // ---------------------------------------------------------------------------
126
+ // Public API
127
+ // ---------------------------------------------------------------------------
128
+
129
+ /**
130
+ * Write a structured handoff file at the end of iteration N.
131
+ * Called at the iteration boundary — after the coder session completes
132
+ * and before the next iteration starts.
133
+ *
134
+ * Silently no-ops when:
135
+ * - compactHandoff is not enabled (settings.compactHandoff !== true)
136
+ * - loopId is missing or invalid
137
+ * - any write error occurs (loop must continue regardless)
138
+ *
139
+ * @param {object} opts
140
+ * @param {object} opts.loopState current loopState object
141
+ * @param {object} opts.session completed coder session (with .history)
142
+ * @param {string} [opts.verdict] judge verdict if available ("pass"|"fail"|null)
143
+ * @returns {boolean} true if a handoff file was written, false otherwise
144
+ */
145
+ function writeHandoff(opts) {
146
+ var loopState = opts.loopState;
147
+ var session = opts.session;
148
+ var verdict = opts.verdict || null;
149
+
150
+ // Guard: opt-in only
151
+ var settings = loopState.settings || {};
152
+ if (!settings.compactHandoff) return false;
153
+
154
+ var loopId = loopState.loopId;
155
+ var dir = handoffDir(loopId);
156
+ if (!dir) return false;
157
+
158
+ var filePath = handoffFilePath(loopId, loopState.iteration);
159
+ if (!filePath) return false;
160
+
161
+ try {
162
+ fs.mkdirSync(dir, { recursive: true });
163
+ } catch (e) {
164
+ console.warn("[loop-handoff] Failed to create handoff dir:", e.message);
165
+ return false;
166
+ }
167
+
168
+ var rawSummary = extractSessionSummary(session.history || []);
169
+ var parsed = parseDecisionsAndThreads(rawSummary);
170
+
171
+ var frame = {
172
+ schema_version: 1,
173
+ loop_id: loopId,
174
+ iteration: loopState.iteration,
175
+ task: (loopState.promptText || "").substring(0, 500),
176
+ decisions: parsed.decisions,
177
+ open_threads: parsed.open_threads,
178
+ key_files: [], // reserved for future tool-output parsing
179
+ verdict: verdict,
180
+ written_at: new Date().toISOString(),
181
+ };
182
+
183
+ var tmpPath = filePath + ".tmp";
184
+ try {
185
+ fs.writeFileSync(tmpPath, JSON.stringify(frame, null, 2), "utf8");
186
+ fs.renameSync(tmpPath, filePath);
187
+ console.log("[loop-handoff] Wrote handoff for " + loopId + " iteration " + loopState.iteration);
188
+ return true;
189
+ } catch (e) {
190
+ console.warn("[loop-handoff] Failed to write handoff file:", e.message);
191
+ try { fs.unlinkSync(tmpPath); } catch (_) {}
192
+ return false;
193
+ }
194
+ }
195
+
196
+ /**
197
+ * Read the most recent handoff file for a loop and return a brief
198
+ * structured summary string to prepend to the next iteration's prompt.
199
+ *
200
+ * Returns null when:
201
+ * - compactHandoff is not enabled
202
+ * - no prior handoff file exists (first iteration)
203
+ * - any read/parse error
204
+ *
205
+ * @param {object} opts
206
+ * @param {object} opts.loopState current loopState (iteration already incremented)
207
+ * @returns {string|null}
208
+ */
209
+ function buildHandoffPreamble(opts) {
210
+ var loopState = opts.loopState;
211
+
212
+ // Guard: opt-in only
213
+ var settings = loopState.settings || {};
214
+ if (!settings.compactHandoff) return null;
215
+
216
+ var loopId = loopState.loopId;
217
+ // The handoff was written for the PREVIOUS iteration
218
+ var prevIteration = loopState.iteration - 1;
219
+ if (prevIteration < 1) return null;
220
+
221
+ var filePath = handoffFilePath(loopId, prevIteration);
222
+ if (!filePath) return null;
223
+
224
+ var frame;
225
+ try {
226
+ var raw = fs.readFileSync(filePath, "utf8");
227
+ frame = JSON.parse(raw);
228
+ } catch (e) {
229
+ // No prior handoff — first iteration or file missing (clean degradation)
230
+ return null;
231
+ }
232
+
233
+ // Build a brief continuation frame — intentionally short
234
+ var lines = [
235
+ "## Continuation from iteration " + frame.iteration + " (structured handoff)",
236
+ "",
237
+ ];
238
+
239
+ if (frame.decisions && frame.decisions.length > 0) {
240
+ lines.push("**Decisions made in the previous iteration:**");
241
+ for (var i = 0; i < frame.decisions.length; i++) {
242
+ lines.push(" - " + frame.decisions[i]);
243
+ }
244
+ lines.push("");
245
+ }
246
+
247
+ if (frame.open_threads && frame.open_threads.length > 0) {
248
+ lines.push("**Open items from the previous iteration:**");
249
+ for (var j = 0; j < frame.open_threads.length; j++) {
250
+ lines.push(" - " + frame.open_threads[j]);
251
+ }
252
+ lines.push("");
253
+ }
254
+
255
+ if (frame.verdict) {
256
+ lines.push("**Previous judge verdict:** " + frame.verdict);
257
+ lines.push("");
258
+ }
259
+
260
+ lines.push("---");
261
+ lines.push("");
262
+
263
+ return lines.join("\n");
264
+ }
265
+
266
+ /**
267
+ * Return the handoff directory path for a given loopId.
268
+ * Exported for tests; not part of the runtime hot path.
269
+ */
270
+ function getHandoffDir(loopId) {
271
+ return handoffDir(loopId);
272
+ }
273
+
274
+ module.exports = {
275
+ writeHandoff: writeHandoff,
276
+ buildHandoffPreamble: buildHandoffPreamble,
277
+ getHandoffDir: getHandoffDir,
278
+ // Exported for unit tests only
279
+ _handoffFilePath: handoffFilePath,
280
+ _extractSessionSummary: extractSessionSummary,
281
+ _parseDecisionsAndThreads: parseDecisionsAndThreads,
282
+ };
package/lib/mcp-local.js CHANGED
@@ -6,8 +6,24 @@ var child_process = require("child_process");
6
6
  var fs = require("fs");
7
7
  var path = require("path");
8
8
  var os = require("os");
9
-
10
- var CLAY_CONFIG_PATH = path.join(os.homedir(), ".clagentic", "mcp.json");
9
+ var { CONFIG_DIR } = require("./config");
10
+
11
+ // mcp.json lives under the Console data dir (CONFIG_DIR = ~/.clagentic/console/).
12
+ // One-time migration: if the old root-level file exists and the new one does not,
13
+ // copy it so existing server configs are preserved on upgrade.
14
+ var CLAY_CONFIG_PATH = path.join(CONFIG_DIR, "mcp.json");
15
+ (function migrateMcpJson() {
16
+ var oldPath = path.join(os.homedir(), ".clagentic", "mcp.json");
17
+ try {
18
+ if (fs.existsSync(oldPath) && !fs.existsSync(CLAY_CONFIG_PATH)) {
19
+ fs.mkdirSync(path.dirname(CLAY_CONFIG_PATH), { recursive: true });
20
+ fs.copyFileSync(oldPath, CLAY_CONFIG_PATH);
21
+ console.log("[mcp-local] Migrated mcp.json → " + CLAY_CONFIG_PATH + " — root copy can be removed when verified");
22
+ }
23
+ } catch (e) {
24
+ // Non-fatal — mcp.json will be created fresh on first use
25
+ }
26
+ }());
11
27
 
12
28
  function createLocalMcp() {
13
29
  var _configCache = {}; // name -> { command, args, env, url }