@lifeaitools/clauth 1.5.42 → 1.5.44

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 (2) hide show
  1. package/cli/commands/serve.js +111 -20
  2. package/package.json +1 -1
@@ -3382,6 +3382,81 @@ function createServer(initPassword, whitelist, port, tunnelHostnameInit = null,
3382
3382
  });
3383
3383
  }
3384
3384
 
3385
+ // GET /debug/sessions — live view of all terminal/chitchat sessions
3386
+ if (method === "GET" && reqPath === "/debug/sessions") {
3387
+ const now = Date.now();
3388
+ const sessions = [];
3389
+ for (const [, s] of terminalSessions) {
3390
+ const startedMs = new Date(s.started_at).getTime();
3391
+ sessions.push({
3392
+ session_id: s.session_id,
3393
+ name: s.name,
3394
+ type: s.is_chitchat ? "chitchat" : "terminal",
3395
+ status: s.status,
3396
+ turn: s.turn || 0,
3397
+ cwd: s.cwd || null,
3398
+ knowledge_tier: s.knowledge_tier,
3399
+ started_at: s.started_at,
3400
+ age_seconds: Math.round((now - startedMs) / 1000),
3401
+ last_response_at: s.lastResponseAt || null,
3402
+ last_response_preview: s.lastResponse
3403
+ ? s.lastResponse.slice(0, 300) + (s.lastResponse.length > 300 ? "…" : "")
3404
+ : null,
3405
+ context_chars: s.context ? s.context.length : 0,
3406
+ active_pid: s.activeProc ? s.activeProc.pid : null,
3407
+ });
3408
+ }
3409
+ const html = `<!DOCTYPE html>
3410
+ <html>
3411
+ <head>
3412
+ <meta charset="utf-8">
3413
+ <meta http-equiv="refresh" content="3">
3414
+ <title>clauth sessions</title>
3415
+ <style>
3416
+ body { font-family: monospace; background: #0d1117; color: #c9d1d9; padding: 20px; }
3417
+ h1 { color: #58a6ff; font-size: 16px; margin-bottom: 4px; }
3418
+ .meta { color: #6e7681; font-size: 12px; margin-bottom: 20px; }
3419
+ .empty { color: #6e7681; }
3420
+ .session { border: 1px solid #30363d; border-radius: 6px; padding: 16px; margin-bottom: 16px; }
3421
+ .session.busy { border-color: #f0883e; }
3422
+ .session.ready { border-color: #3fb950; }
3423
+ .session.stopped { border-color: #6e7681; opacity: 0.6; }
3424
+ .label { color: #6e7681; font-size: 11px; text-transform: uppercase; }
3425
+ .value { color: #e6edf3; font-size: 13px; margin-bottom: 8px; }
3426
+ .badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: bold; }
3427
+ .badge.chitchat { background: #1f4068; color: #58a6ff; }
3428
+ .badge.terminal { background: #2d1f3d; color: #bc8cff; }
3429
+ .badge.busy { background: #3d2400; color: #f0883e; }
3430
+ .badge.ready { background: #0f2a0f; color: #3fb950; }
3431
+ .preview { background: #161b22; border-radius: 4px; padding: 10px; font-size: 12px; color: #8b949e; white-space: pre-wrap; word-break: break-word; max-height: 120px; overflow: auto; }
3432
+ </style>
3433
+ </head>
3434
+ <body>
3435
+ <h1>clauth · live sessions</h1>
3436
+ <div class="meta">v${VERSION} · ${sessions.length} session${sessions.length !== 1 ? "s" : ""} · auto-refresh 3s · ${new Date().toISOString()}</div>
3437
+ ${sessions.length === 0
3438
+ ? '<div class="empty">No active sessions.</div>'
3439
+ : sessions.map(s => `
3440
+ <div class="session ${s.status}">
3441
+ <span class="badge ${s.type}">${s.type}</span>
3442
+ <span class="badge ${s.status}" style="margin-left:6px">${s.status}${s.status === "busy" ? " ⟳" : ""}</span>
3443
+ <div style="margin-top:10px">
3444
+ <div class="label">name</div><div class="value">${s.name}</div>
3445
+ <div class="label">session_id</div><div class="value" style="color:#6e7681;font-size:11px">${s.session_id}</div>
3446
+ <div class="label">turn / age / context</div>
3447
+ <div class="value">turn ${s.turn} · ${s.age_seconds}s old · ${s.context_chars} chars context${s.active_pid ? ` · pid ${s.active_pid}` : ""}</div>
3448
+ <div class="label">cwd</div><div class="value" style="color:#6e7681">${s.cwd || "(not set)"}</div>
3449
+ ${s.last_response_preview ? `
3450
+ <div class="label">last response ${s.last_response_at ? "· " + s.last_response_at : ""}</div>
3451
+ <div class="preview">${s.last_response_preview.replace(/</g, "&lt;").replace(/>/g, "&gt;")}</div>` : ""}
3452
+ </div>
3453
+ </div>`).join("")}
3454
+ </body>
3455
+ </html>`;
3456
+ res.writeHead(200, { "Content-Type": "text/html", ...CORS });
3457
+ return res.end(html);
3458
+ }
3459
+
3385
3460
  // GET /builds — CI build status (no auth required, same as /ping)
3386
3461
  if (method === "GET" && reqPath === "/builds") {
3387
3462
  return ok(res, buildStatus);
@@ -4919,7 +4994,7 @@ function findClaudeBinary() {
4919
4994
  let activeCliWorkers = 0;
4920
4995
  const MAX_CLI_WORKERS = 2;
4921
4996
 
4922
- function spawnClaudeTask(prompt, jobId) {
4997
+ function spawnClaudeTask(prompt, jobId, cwd) {
4923
4998
  if (activeCliWorkers >= MAX_CLI_WORKERS) {
4924
4999
  return { error: 'concurrency_limit', message: `Max ${MAX_CLI_WORKERS} CLI workers active` };
4925
5000
  }
@@ -4930,7 +5005,7 @@ function spawnClaudeTask(prompt, jobId) {
4930
5005
 
4931
5006
  activeCliWorkers++;
4932
5007
  const proc = spawnProc(binary, ['-p', prompt, '--dangerously-skip-permissions'], {
4933
- cwd: 'C:/Dev/regen-root',
5008
+ cwd: cwd || CHITCHAT_FALLBACK_CWD,
4934
5009
  env: process.env,
4935
5010
  stdio: ['ignore', 'pipe', 'pipe'],
4936
5011
  shell: true,
@@ -4955,7 +5030,7 @@ function generateSessionId() {
4955
5030
  return crypto.randomUUID();
4956
5031
  }
4957
5032
 
4958
- function startTerminalSession(name, knowledge_tier, context_md) {
5033
+ function startTerminalSession(name, knowledge_tier, context_md, cwd) {
4959
5034
  const binary = findClaudeBinary();
4960
5035
  if (!binary) {
4961
5036
  return { error: 'binary_not_found', message: 'claude CLI not found in PATH or AppData/npm' };
@@ -4973,9 +5048,10 @@ function startTerminalSession(name, knowledge_tier, context_md) {
4973
5048
  started_at: new Date().toISOString(),
4974
5049
  context: initialContext,
4975
5050
  activeProc: null,
5051
+ cwd: cwd || CHITCHAT_FALLBACK_CWD,
4976
5052
  };
4977
5053
  terminalSessions.set(session_id, session);
4978
- console.log(`[terminal] started session ${session_id} name=${name}`);
5054
+ console.log(`[terminal] started session ${session_id} name=${name} cwd=${session.cwd}`);
4979
5055
  return { session_id, status: 'ready' };
4980
5056
  }
4981
5057
 
@@ -4992,7 +5068,7 @@ function sendTerminalMessage(session_id, message) {
4992
5068
  const fullPrompt = `${session.context}\n\n---\nUser: ${message}`;
4993
5069
 
4994
5070
  const proc = spawnProc(binary, ['-p', fullPrompt, '--dangerously-skip-permissions'], {
4995
- cwd: 'C:/Dev/regen-root',
5071
+ cwd: session.cwd || CHITCHAT_FALLBACK_CWD,
4996
5072
  env: process.env,
4997
5073
  stdio: ['ignore', 'pipe', 'pipe'],
4998
5074
  shell: true,
@@ -5075,23 +5151,34 @@ function stopTerminalSession(session_id) {
5075
5151
 
5076
5152
  // ── Chitchat helpers ──────────────────────────────────────────────────────
5077
5153
  // Wrappers around terminal session logic, pre-configured for regen-root collab.
5078
- // Auto-injects agent-bootstrap.md as corpus context on every new session.
5154
+ // cwd + bootstrap path are read from the vault's first fileserver mount at
5155
+ // call time — no hardcoded paths. Falls back to C:/Dev/regen-root if vault
5156
+ // is locked or no fileserver mount is configured.
5157
+
5158
+ const CHITCHAT_FALLBACK_CWD = 'C:/Dev/regen-root';
5079
5159
 
5080
- const CHITCHAT_CWD = 'C:/Dev/regen-root';
5081
- const CHITCHAT_BOOTSTRAP_PATH = 'C:/Dev/regen-root/.rdc/guides/agent-bootstrap.md';
5160
+ async function resolveChitchatRoot(vault) {
5161
+ try {
5162
+ const { mounts } = await getFileserverMounts(vault);
5163
+ if (mounts && mounts.length > 0) return mounts[0].path;
5164
+ } catch {}
5165
+ return CHITCHAT_FALLBACK_CWD;
5166
+ }
5082
5167
 
5083
- function readBootstrapContext() {
5168
+ async function readBootstrapContext(rootPath) {
5169
+ const bootstrapPath = path.join(rootPath, '.rdc', 'guides', 'agent-bootstrap.md');
5084
5170
  try {
5085
- return fs.readFileSync(CHITCHAT_BOOTSTRAP_PATH, 'utf-8');
5171
+ return fs.readFileSync(bootstrapPath, 'utf-8');
5086
5172
  } catch {
5087
- return '# agent-bootstrap.md not found — proceeding without corpus context\n';
5173
+ return `# agent-bootstrap.md not found at ${bootstrapPath} — proceeding without corpus context\n`;
5088
5174
  }
5089
5175
  }
5090
5176
 
5091
- function startChitchatSession(name) {
5092
- const corpus = readBootstrapContext();
5177
+ async function startChitchatSession(name, vault) {
5178
+ const rootPath = await resolveChitchatRoot(vault);
5179
+ const corpus = await readBootstrapContext(rootPath);
5093
5180
  const session_id = generateSessionId();
5094
- const preamble = `${corpus}\n\n---\nCollab session: ${name} | cwd: ${CHITCHAT_CWD}\nRead the bootstrap above. Ready to receive tasks from claude.ai.`;
5181
+ const preamble = `${corpus}\n\n---\nCollab session: ${name} | cwd: ${rootPath}\nRead the bootstrap above. Ready to receive tasks from claude.ai.`;
5095
5182
  const session = {
5096
5183
  session_id,
5097
5184
  name,
@@ -5101,10 +5188,11 @@ function startChitchatSession(name) {
5101
5188
  context: preamble,
5102
5189
  activeProc: null,
5103
5190
  is_chitchat: true,
5191
+ cwd: rootPath,
5104
5192
  };
5105
5193
  terminalSessions.set(session_id, session);
5106
- console.log(`[chitchat] started session ${session_id} name=${name}`);
5107
- return { session_id, status: 'ready', name };
5194
+ console.log(`[chitchat] started session ${session_id} name=${name} cwd=${rootPath}`);
5195
+ return { session_id, status: 'ready', name, cwd: rootPath };
5108
5196
  }
5109
5197
 
5110
5198
  function sendChitchatMessage(session_id, message) {
@@ -5121,7 +5209,7 @@ function sendChitchatMessage(session_id, message) {
5121
5209
  const fullPrompt = `${session.context}\n\n---\nFrom claude.ai: ${message}`;
5122
5210
 
5123
5211
  const proc = spawnProc(binary, ['-p', fullPrompt, '--dangerously-skip-permissions'], {
5124
- cwd: CHITCHAT_CWD,
5212
+ cwd: session.cwd,
5125
5213
  env: process.env,
5126
5214
  stdio: ['ignore', 'pipe', 'pipe'],
5127
5215
  shell: true,
@@ -5161,6 +5249,7 @@ function listChitchatSessions() {
5161
5249
  status: s.status,
5162
5250
  started_at: s.started_at,
5163
5251
  turn: s.turn || 0,
5252
+ cwd: s.cwd,
5164
5253
  });
5165
5254
  }
5166
5255
  }
@@ -6172,7 +6261,8 @@ async function handleMcpTool(vault, name, args) {
6172
6261
  case "monkey_dispatch": {
6173
6262
  const { prompt, job_id } = args;
6174
6263
  if (!prompt) return mcpError("prompt required");
6175
- const result = spawnClaudeTask(prompt, job_id || "untracked");
6264
+ const cwd = await resolveChitchatRoot(vault);
6265
+ const result = spawnClaudeTask(prompt, job_id || "untracked", cwd);
6176
6266
  if (result.error) return mcpError(`${result.error}: ${result.message}`);
6177
6267
  return mcpResult(JSON.stringify(result));
6178
6268
  }
@@ -6180,7 +6270,8 @@ async function handleMcpTool(vault, name, args) {
6180
6270
  case "terminal_start": {
6181
6271
  const { name, knowledge_tier, context_md } = args;
6182
6272
  if (!name) return mcpError("name required");
6183
- const result = startTerminalSession(name, knowledge_tier || 'db_only', context_md || null);
6273
+ const cwd = await resolveChitchatRoot(vault);
6274
+ const result = startTerminalSession(name, knowledge_tier || 'db_only', context_md || null, cwd);
6184
6275
  if (result.error) return mcpError(`${result.error}: ${result.message}`);
6185
6276
  return mcpResult(JSON.stringify(result));
6186
6277
  }
@@ -6216,7 +6307,7 @@ async function handleMcpTool(vault, name, args) {
6216
6307
  case "chitchat_start": {
6217
6308
  const { name } = args;
6218
6309
  if (!name) return mcpError("name required");
6219
- const result = startChitchatSession(name);
6310
+ const result = await startChitchatSession(name, vault);
6220
6311
  if (result.error) return mcpError(`${result.error}: ${result.message}`);
6221
6312
  return mcpResult(JSON.stringify(result));
6222
6313
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifeaitools/clauth",
3
- "version": "1.5.42",
3
+ "version": "1.5.44",
4
4
  "description": "Hardware-bound credential vault for the LIFEAI infrastructure stack",
5
5
  "type": "module",
6
6
  "bin": {