@cryptiklemur/lattice 1.41.2 → 1.42.0

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.
@@ -19,6 +19,7 @@ function getProjectInitials(title: string): string {
19
19
  interface ProjectGroup {
20
20
  slug: string;
21
21
  title: string;
22
+ activeSessions: number;
22
23
  nodes: Array<{ nodeId: string; nodeName: string; online: boolean; path: string }>;
23
24
  }
24
25
 
@@ -36,8 +37,9 @@ function groupProjectsBySlug(projects: ProjectInfo[], nodes: NodeInfo[]): Projec
36
37
  };
37
38
  if (existing) {
38
39
  existing.nodes.push(nodeEntry);
40
+ existing.activeSessions += p.activeSessions ?? 0;
39
41
  } else {
40
- groups.set(p.slug, { slug: p.slug, title: p.title, nodes: [nodeEntry] });
42
+ groups.set(p.slug, { slug: p.slug, title: p.title, activeSessions: p.activeSessions ?? 0, nodes: [nodeEntry] });
41
43
  }
42
44
  }
43
45
  return Array.from(groups.values());
@@ -95,6 +97,12 @@ function ProjectButton(props: ProjectButtonProps) {
95
97
  {initials}
96
98
  </button>
97
99
 
100
+ {props.group.activeSessions > 0 && (
101
+ <div className="absolute -top-1 -right-1 min-w-[16px] h-[16px] rounded-full bg-primary text-primary-content text-[9px] font-bold flex items-center justify-center pointer-events-none px-1">
102
+ {props.group.activeSessions}
103
+ </div>
104
+ )}
105
+
98
106
  <div className="absolute bottom-0 right-0 flex gap-[2px] pointer-events-none">
99
107
  {props.group.nodes.map(function (n) {
100
108
  return (
@@ -137,6 +145,59 @@ function ProjectButton(props: ProjectButtonProps) {
137
145
  );
138
146
  }
139
147
 
148
+ function NodeIndicator({ node }: { node: NodeInfo }) {
149
+ var [hovered, setHovered] = useState(false);
150
+ var [tooltipTop, setTooltipTop] = useState(0);
151
+ var sidebar = useSidebar();
152
+ var initial = node.name.charAt(0).toUpperCase();
153
+
154
+ return (
155
+ <div className="relative flex items-center">
156
+ <button
157
+ onClick={function () { sidebar.openSettings("nodes"); }}
158
+ onMouseEnter={function (e) {
159
+ var rect = e.currentTarget.getBoundingClientRect();
160
+ setTooltipTop(rect.top + rect.height / 2);
161
+ setHovered(true);
162
+ }}
163
+ onMouseLeave={function () { setHovered(false); }}
164
+ className={
165
+ "w-[28px] h-[28px] flex items-center justify-center text-[10px] font-bold rounded-full cursor-pointer transition-all duration-[120ms] flex-shrink-0 border-2 " +
166
+ (node.online
167
+ ? "border-success/50 bg-base-200 text-base-content/50 hover:bg-base-200/80"
168
+ : "border-error/30 bg-base-200/50 text-base-content/25 hover:bg-base-200/60")
169
+ }
170
+ >
171
+ {initial}
172
+ </button>
173
+ {hovered && (
174
+ <div
175
+ className="pointer-events-none z-[9000] bg-base-300 border border-base-content/20 rounded-lg px-2.5 py-1.5 shadow-xl"
176
+ style={{
177
+ position: "fixed",
178
+ left: "calc(64px + 8px)",
179
+ top: tooltipTop + "px",
180
+ transform: "translateY(-50%)",
181
+ }}
182
+ >
183
+ <div className="flex items-center gap-1.5">
184
+ <div className={"w-[6px] h-[6px] rounded-full flex-shrink-0 " + (node.online ? "bg-success" : "bg-error")} />
185
+ <span className="text-[12px] font-bold text-base-content whitespace-nowrap">{node.name}</span>
186
+ </div>
187
+ {node.addresses && node.addresses.length > 0 && (
188
+ <div className="text-[10px] text-base-content/40 mt-0.5 whitespace-nowrap">
189
+ {node.addresses[0]}
190
+ </div>
191
+ )}
192
+ <div className="text-[10px] text-base-content/30 mt-0.5">
193
+ {node.projects.length} project{node.projects.length !== 1 ? "s" : ""}
194
+ </div>
195
+ </div>
196
+ )}
197
+ </div>
198
+ );
199
+ }
200
+
140
201
  interface ProjectRailProps {
141
202
  projects: ProjectInfo[];
142
203
  nodes: NodeInfo[];
@@ -151,6 +212,7 @@ export function ProjectRail(props: ProjectRailProps) {
151
212
  var ws = useWebSocket();
152
213
  var sidebar = useSidebar();
153
214
  var groups = groupProjectsBySlug(props.projects, props.nodes);
215
+ var remoteNodes = props.nodes.filter(function (n) { return !n.isLocal; });
154
216
  var [contextMenu, setContextMenu] = useState<ContextMenuState>({
155
217
  visible: false,
156
218
  x: 0,
@@ -255,10 +317,18 @@ export function ProjectRail(props: ProjectRailProps) {
255
317
  })}
256
318
 
257
319
 
258
- {groups.length > 0 && (
320
+ {groups.length > 0 && remoteNodes.length > 0 && (
259
321
  <div className="w-6 h-px bg-base-300 my-0.5 flex-shrink-0" />
260
322
  )}
261
323
 
324
+ {remoteNodes.map(function (node) {
325
+ return (
326
+ <NodeIndicator key={node.id} node={node} />
327
+ );
328
+ })}
329
+
330
+ <div className="w-6 h-px bg-base-300 my-0.5 flex-shrink-0" />
331
+
262
332
  <button
263
333
  onClick={function () { sidebar.openAddProject(); }}
264
334
  className="w-[42px] h-[42px] flex items-center justify-center rounded-full border-2 border-dashed border-base-content/25 text-base-content/20 hover:border-base-content/40 hover:text-base-content/40 transition-colors duration-[120ms] flex-shrink-0 cursor-pointer"
@@ -15,7 +15,6 @@ import { AddProjectModal } from "./components/sidebar/AddProjectModal";
15
15
  import { useSidebar } from "./hooks/useSidebar";
16
16
  import { useWorkspace } from "./hooks/useWorkspace";
17
17
  import { useWebSocket } from "./hooks/useWebSocket";
18
- import { UpdateBanner } from "./components/ui/UpdateBanner";
19
18
  import { NodeDisconnectedOverlay } from "./components/ui/NodeDisconnectedOverlay";
20
19
  import { useSwipeDrawer } from "./hooks/useSwipeDrawer";
21
20
  import { exitSettings, getSidebarStore, handlePopState, closeDrawer, toggleDrawer } from "./stores/sidebar";
@@ -424,7 +423,6 @@ function RootLayout() {
424
423
  />
425
424
 
426
425
  <main id="main-content" className="drawer-content flex flex-col h-full min-w-0 overflow-hidden relative">
427
- <UpdateBanner />
428
426
  <Outlet />
429
427
  <NodeDisconnectedOverlay />
430
428
  </main>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cryptiklemur/lattice",
3
- "version": "1.41.2",
3
+ "version": "1.42.0",
4
4
  "description": "Multi-machine agentic dashboard for Claude Code. Monitor sessions, manage MCP servers and skills, orchestrate across mesh-networked nodes.",
5
5
  "license": "MIT",
6
6
  "author": "Aaron Scherer <me@aaronscherer.me>",
@@ -18,7 +18,7 @@ import { detectIdeProjectName } from "./handlers/settings";
18
18
  import "./handlers/session";
19
19
  import "./handlers/chat";
20
20
  import "./handlers/attachment";
21
- import { loadInterruptedSessions, unwatchSessionLock, cleanupClientPermissions } from "./project/sdk-bridge";
21
+ import { loadInterruptedSessions, unwatchSessionLock, cleanupClientPermissions, getActiveSessionCountForProject } from "./project/sdk-bridge";
22
22
  import { clearActiveSession, getActiveSession } from "./handlers/chat";
23
23
  import { clearActiveProject } from "./handlers/fs";
24
24
  import { clearClientRemoteNode } from "./ws/router";
@@ -410,7 +410,7 @@ export async function startDaemon(portOverride?: number | null): Promise<void> {
410
410
  var currentIdentity = loadOrCreateIdentity();
411
411
  broadcast({ type: "mesh:nodes", nodes: buildNodesMessage() });
412
412
  var localProjects = currentConfig.projects.map(function (p: typeof currentConfig.projects[number]) {
413
- return { slug: p.slug, path: p.path, title: p.title, nodeId: currentIdentity.id, nodeName: currentConfig.name, isRemote: false, ideProjectName: detectIdeProjectName(p.path) };
413
+ return { slug: p.slug, path: p.path, title: p.title, nodeId: currentIdentity.id, nodeName: currentConfig.name, isRemote: false, ideProjectName: detectIdeProjectName(p.path), activeSessions: getActiveSessionCountForProject(p.path) };
414
414
  });
415
415
  var remoteProjects = getAllRemoteProjects(currentIdentity.id);
416
416
  broadcast({
@@ -4,7 +4,7 @@ import type { SDKMessage, SDKPartialAssistantMessage, SDKResultMessage, SDKUserM
4
4
  import type { CanUseTool, PermissionMode, PermissionResult, PermissionUpdate } from "@anthropic-ai/claude-agent-sdk";
5
5
  type MessageParam = SDKUserMessage["message"];
6
6
  import type { Attachment } from "@lattice/shared";
7
- import { existsSync, readFileSync, writeFileSync, mkdirSync, statSync } from "node:fs";
7
+ import { existsSync, readFileSync, writeFileSync, mkdirSync, statSync, readdirSync, readlinkSync } from "node:fs";
8
8
  import { join, resolve } from "node:path";
9
9
  import { homedir } from "node:os";
10
10
  import { sendTo, broadcast } from "../ws/broadcast";
@@ -212,6 +212,41 @@ export function getActiveStreamCount(): number {
212
212
  return activeStreams.size;
213
213
  }
214
214
 
215
+ export function getActiveSessionCountForProject(projectPath: string): number {
216
+ var count = 0;
217
+ var hash = projectPath.replace(/\//g, "-");
218
+ var dir = join(homedir(), ".claude", "projects", hash);
219
+
220
+ for (var [sessionId] of activeStreams) {
221
+ if (existsSync(join(dir, sessionId + ".jsonl"))) count++;
222
+ }
223
+
224
+ for (var [sessionId2] of streamMetadata) {
225
+ void sessionId2;
226
+ }
227
+
228
+ if (isClaudeCliRunningInProject(projectPath)) count++;
229
+
230
+ return count;
231
+ }
232
+
233
+ function isClaudeCliRunningInProject(projectPath: string): boolean {
234
+ try {
235
+ var result = Bun.spawnSync(["pgrep", "-x", "claude"], { stderr: "ignore" });
236
+ if (result.exitCode !== 0) return false;
237
+ var pids = result.stdout.toString().trim().split("\n");
238
+ for (var i = 0; i < pids.length; i++) {
239
+ var pid = parseInt(pids[i], 10);
240
+ if (isNaN(pid) || pid === process.pid) continue;
241
+ try {
242
+ var cwd = readlinkSync("/proc/" + pid + "/cwd");
243
+ if (cwd === projectPath) return true;
244
+ } catch {}
245
+ }
246
+ } catch {}
247
+ return false;
248
+ }
249
+
215
250
  /**
216
251
  * Check if a session is controlled by an external process (not Lattice).
217
252
  * Lattice's own active streams are handled by isProcessing on the client,
@@ -227,47 +262,116 @@ export function isSessionBusy(sessionId: string): boolean {
227
262
  * The SDK spawns child processes (e.g. claude-agent-sdk/cli.js) that hold
228
263
  * lock files — those are NOT external.
229
264
  */
230
- function isSessionLockedByExternal(sessionId: string): boolean {
231
- if (activeStreams.has(sessionId)) return false;
232
-
265
+ function getProjectPathForSession(sessionId: string): string | null {
233
266
  var config = loadConfig();
234
267
  for (var i = 0; i < config.projects.length; i++) {
235
- var projectPath = config.projects[i].path;
236
- var hash = projectPath.replace(/\//g, "-");
268
+ var hash = config.projects[i].path.replace(/\//g, "-");
237
269
  var jsonlPath = join(homedir(), ".claude", "projects", hash, sessionId + ".jsonl");
238
- if (existsSync(jsonlPath)) {
270
+ if (existsSync(jsonlPath)) return config.projects[i].path;
271
+ }
272
+ return null;
273
+ }
274
+
275
+ function getClaudeCliPids(): Array<{ pid: number; cwd: string; cmdline: string[] }> {
276
+ var results: Array<{ pid: number; cwd: string; cmdline: string[] }> = [];
277
+ try {
278
+ var result = Bun.spawnSync(["pgrep", "-x", "claude"], { stderr: "ignore" });
279
+ if (result.exitCode !== 0) return results;
280
+ var pidStrs = result.stdout.toString().trim().split("\n");
281
+ for (var i = 0; i < pidStrs.length; i++) {
282
+ var pid = parseInt(pidStrs[i], 10);
283
+ if (isNaN(pid) || pid === process.pid) continue;
239
284
  try {
240
- var stat = statSync(jsonlPath);
241
- var mtime = stat.mtimeMs;
242
- if (Date.now() - mtime < 10000) {
243
- return true;
244
- }
285
+ var cwd = readlinkSync("/proc/" + pid + "/cwd");
286
+ var cmdline = readFileSync("/proc/" + pid + "/cmdline", "utf-8").split("\0");
287
+ results.push({ pid, cwd, cmdline });
245
288
  } catch {}
246
289
  }
290
+ } catch {}
291
+ return results;
292
+ }
293
+
294
+ function resolveSessionName(projectPath: string, name: string): string | null {
295
+ var hash = projectPath.replace(/\//g, "-");
296
+ var dir = join(homedir(), ".claude", "projects", hash);
297
+ if (!existsSync(dir)) return null;
298
+
299
+ if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(name)) {
300
+ if (existsSync(join(dir, name + ".jsonl"))) return name;
247
301
  }
248
302
 
249
- return false;
303
+ var entries = readdirSync(dir).filter(function (f) { return f.endsWith(".jsonl"); });
304
+ for (var e = 0; e < entries.length; e++) {
305
+ try {
306
+ var result = Bun.spawnSync(["grep", "-m", "1", "custom-title", join(dir, entries[e])], { stdout: "pipe", stderr: "ignore" });
307
+ if (result.exitCode !== 0) continue;
308
+ var line = result.stdout.toString().trim();
309
+ if (!line) continue;
310
+ var parsed = JSON.parse(line);
311
+ if (parsed.type === "custom-title" && parsed.customTitle === name) {
312
+ return entries[e].replace(".jsonl", "");
313
+ }
314
+ } catch {}
315
+ }
316
+ return null;
250
317
  }
251
318
 
252
- export function stopExternalSession(sessionId: string): boolean {
253
- try {
254
- var config = loadConfig();
255
- for (var i = 0; i < config.projects.length; i++) {
256
- var hash = config.projects[i].path.replace(/\//g, "-");
257
- var jsonlPath = join(homedir(), ".claude", "projects", hash, sessionId + ".jsonl");
258
- if (existsSync(jsonlPath)) {
259
- var result = Bun.spawnSync(["fuser", jsonlPath], { stderr: "ignore" });
260
- if (result.exitCode === 0) {
261
- var output = result.stdout.toString().trim();
262
- var pids = output.split(/\s+/).map(Number).filter(function (p) { return !isNaN(p) && p !== process.pid; });
263
- if (pids.length > 0) {
264
- process.kill(pids[0], "SIGINT");
265
- return true;
266
- }
267
- }
319
+ function findMostRecentSession(projectPath: string): string | null {
320
+ var hash = projectPath.replace(/\//g, "-");
321
+ var dir = join(homedir(), ".claude", "projects", hash);
322
+ if (!existsSync(dir)) return null;
323
+
324
+ var entries = readdirSync(dir).filter(function (f) { return f.endsWith(".jsonl"); });
325
+ var latest: { id: string; mtime: number } | null = null;
326
+ for (var e = 0; e < entries.length; e++) {
327
+ try {
328
+ var s = statSync(join(dir, entries[e]));
329
+ if (!latest || s.mtimeMs > latest.mtime) {
330
+ latest = { id: entries[e].replace(".jsonl", ""), mtime: s.mtimeMs };
268
331
  }
332
+ } catch {}
333
+ }
334
+ if (latest && Date.now() - latest.mtime < 60000) return latest.id;
335
+ return null;
336
+ }
337
+
338
+ function getCliSessionIdForProject(projectPath: string): string | null {
339
+ var cliProcesses = getClaudeCliPids();
340
+ for (var i = 0; i < cliProcesses.length; i++) {
341
+ if (cliProcesses[i].cwd !== projectPath) continue;
342
+
343
+ var cmdline = cliProcesses[i].cmdline;
344
+ var resumeIdx = cmdline.indexOf("--resume");
345
+ if (resumeIdx !== -1 && resumeIdx + 1 < cmdline.length) {
346
+ var sessionName = cmdline[resumeIdx + 1];
347
+ return resolveSessionName(projectPath, sessionName);
269
348
  }
270
- } catch {}
349
+
350
+ return findMostRecentSession(projectPath);
351
+ }
352
+ return null;
353
+ }
354
+
355
+ function isSessionLockedByExternal(sessionId: string): boolean {
356
+ if (activeStreams.has(sessionId)) return false;
357
+ var projectPath = getProjectPathForSession(sessionId);
358
+ if (!projectPath) return false;
359
+ var cliSessionId = getCliSessionIdForProject(projectPath);
360
+ return cliSessionId === sessionId;
361
+ }
362
+
363
+ export function stopExternalSession(sessionId: string): boolean {
364
+ var projectPath = getProjectPathForSession(sessionId);
365
+ if (!projectPath) return false;
366
+ var cliProcesses = getClaudeCliPids();
367
+ for (var i = 0; i < cliProcesses.length; i++) {
368
+ if (cliProcesses[i].cwd === projectPath) {
369
+ try {
370
+ process.kill(cliProcesses[i].pid, "SIGINT");
371
+ return true;
372
+ } catch {}
373
+ }
374
+ }
271
375
  return false;
272
376
  }
273
377
 
@@ -23,6 +23,7 @@ export interface ProjectInfo extends ProjectSummary {
23
23
  isRemote: boolean;
24
24
  online?: boolean;
25
25
  ideProjectName?: string;
26
+ activeSessions?: number;
26
27
  }
27
28
 
28
29
  export interface SessionSummary {