marmonitor 0.1.7 → 0.2.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.
- package/README.ko.md +262 -0
- package/README.md +49 -5
- package/bin/daemon.js +2 -0
- package/bin/postinstall.cjs +47 -1
- package/bin/preuninstall.cjs +14 -0
- package/dist/banner/index.js +15 -7
- package/dist/cli.js +282 -107
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +2 -0
- package/dist/output/badge-themes.d.ts +19 -0
- package/dist/output/badge-themes.js +52 -0
- package/dist/output/index.d.ts +5 -2
- package/dist/output/index.js +69 -22
- package/dist/output/utils.d.ts +22 -8
- package/dist/output/utils.js +83 -48
- package/dist/scanner/claude.d.ts +8 -1
- package/dist/scanner/claude.js +156 -19
- package/dist/scanner/codex-sqlite.d.ts +11 -0
- package/dist/scanner/codex-sqlite.js +50 -0
- package/dist/scanner/codex.d.ts +1 -1
- package/dist/scanner/codex.js +42 -2
- package/dist/scanner/concurrency.d.ts +5 -0
- package/dist/scanner/concurrency.js +22 -0
- package/dist/scanner/daemon-entry.d.ts +5 -0
- package/dist/scanner/daemon-entry.js +27 -0
- package/dist/scanner/daemon-loop.d.ts +13 -0
- package/dist/scanner/daemon-loop.js +77 -0
- package/dist/scanner/daemon-utils.d.ts +9 -0
- package/dist/scanner/daemon-utils.js +56 -0
- package/dist/scanner/index.js +51 -10
- package/dist/scanner/perf.d.ts +8 -0
- package/dist/scanner/perf.js +26 -0
- package/dist/scanner/session-registry.d.ts +31 -0
- package/dist/scanner/session-registry.js +99 -0
- package/dist/scanner/session-tier.d.ts +6 -0
- package/dist/scanner/session-tier.js +22 -0
- package/dist/tmux/index.js +11 -0
- package/dist/tmux/jump-anchor.d.ts +25 -0
- package/dist/tmux/jump-anchor.js +100 -0
- package/dist/tmux/setup.d.ts +4 -0
- package/dist/tmux/setup.js +41 -1
- package/dist/tmux/status-click.d.ts +9 -0
- package/dist/tmux/status-click.js +19 -0
- package/package.json +1 -1
package/dist/output/index.d.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import type { TmuxJumpResult } from "../tmux/index.js";
|
|
2
2
|
import type { AgentSession, SystemInfo } from "../types.js";
|
|
3
|
-
import { type StatuslineFormat } from "./utils.js";
|
|
3
|
+
import { type BadgeStyle, type StatuslineFormat } from "./utils.js";
|
|
4
4
|
/** Collect system resource info */
|
|
5
5
|
export declare function getSystemInfo(): Promise<SystemInfo>;
|
|
6
|
+
/** Apply badge style to terminal chalk output: mono uses bold/dim only */
|
|
7
|
+
export declare function applyTerminalStyle(badgeStyle: BadgeStyle): void;
|
|
6
8
|
/** Print agent status as formatted text */
|
|
7
9
|
export declare function printStatus(agents: AgentSession[]): Promise<void>;
|
|
8
10
|
/** Print agent status as JSON */
|
|
9
11
|
export declare function printStatusJson(agents: AgentSession[]): Promise<void>;
|
|
10
12
|
export declare function printCleanPlan(agents: AgentSession[], kill: boolean): void;
|
|
11
13
|
export declare function printCleanJson(agents: AgentSession[], executed: boolean, signal?: string): void;
|
|
14
|
+
export declare function renderJumpAttentionChooser(agents: AgentSession[], page?: number, pageSize?: number): string;
|
|
12
15
|
export declare function printAttention(agents: AgentSession[], limit?: number): void;
|
|
13
16
|
export declare function printAttentionJson(agents: AgentSession[], limit?: number): void;
|
|
14
17
|
export declare function printAttentionChooser(agents: AgentSession[], limit?: number): void;
|
|
@@ -23,6 +26,6 @@ export declare function printDock(agents: AgentSession[], maxLines?: number): Pr
|
|
|
23
26
|
/** Print one-line summary for tmux/terminal status bar */
|
|
24
27
|
export declare function renderUnavailableStatusline(format?: StatuslineFormat): string;
|
|
25
28
|
/** Print one-line summary for tmux/terminal status bar */
|
|
26
|
-
export declare function renderStatusline(agents: AgentSession[], format?: StatuslineFormat, attentionLimit?: number, width?: number): Promise<string>;
|
|
29
|
+
export declare function renderStatusline(agents: AgentSession[], format?: StatuslineFormat, attentionLimit?: number, width?: number, badgeStyle?: BadgeStyle, hasJumpAnchor?: boolean): Promise<string>;
|
|
27
30
|
/** Print one-line summary for tmux/terminal status bar */
|
|
28
31
|
export declare function printStatusline(agents: AgentSession[], format?: StatuslineFormat, attentionLimit?: number, width?: number): Promise<void>;
|
package/dist/output/index.js
CHANGED
|
@@ -16,8 +16,16 @@ export async function getSystemInfo() {
|
|
|
16
16
|
return info;
|
|
17
17
|
}
|
|
18
18
|
// shortenPath, formatElapsed, formatTokens imported from ./utils.js
|
|
19
|
+
let monoMode = false;
|
|
20
|
+
/** Apply badge style to terminal chalk output: mono uses bold/dim only */
|
|
21
|
+
export function applyTerminalStyle(badgeStyle) {
|
|
22
|
+
monoMode = badgeStyle === "basic-mono" || badgeStyle === "text-mono";
|
|
23
|
+
}
|
|
19
24
|
/** Agent name with distinct color */
|
|
20
25
|
function agentLabel(name) {
|
|
26
|
+
const label = name === "Claude Code" ? "Claude" : name;
|
|
27
|
+
if (monoMode)
|
|
28
|
+
return chalk.bold.white(label);
|
|
21
29
|
switch (name) {
|
|
22
30
|
case "Claude Code":
|
|
23
31
|
return chalk.hex("#D97706")("Claude"); // amber/orange
|
|
@@ -31,6 +39,20 @@ function agentLabel(name) {
|
|
|
31
39
|
}
|
|
32
40
|
/** Status icon/color */
|
|
33
41
|
function statusLabel(status) {
|
|
42
|
+
if (monoMode) {
|
|
43
|
+
switch (status) {
|
|
44
|
+
case "Active":
|
|
45
|
+
return chalk.white("[Active] ");
|
|
46
|
+
case "Idle":
|
|
47
|
+
return chalk.gray("[Idle] ");
|
|
48
|
+
case "Stalled":
|
|
49
|
+
return chalk.dim("[Stalled] ");
|
|
50
|
+
case "Unmatched":
|
|
51
|
+
return chalk.dim("[Unmatched]");
|
|
52
|
+
case "Dead":
|
|
53
|
+
return chalk.dim("[Dead] ");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
34
56
|
switch (status) {
|
|
35
57
|
case "Active":
|
|
36
58
|
return chalk.green("[Active] ");
|
|
@@ -45,6 +67,15 @@ function statusLabel(status) {
|
|
|
45
67
|
}
|
|
46
68
|
}
|
|
47
69
|
function displayStatusLabel(status, phase) {
|
|
70
|
+
if (monoMode) {
|
|
71
|
+
if (phase === "permission")
|
|
72
|
+
return chalk.bold.white("[Allow] ");
|
|
73
|
+
if (phase === "tool")
|
|
74
|
+
return chalk.white("[Tool] ");
|
|
75
|
+
if (phase === "thinking")
|
|
76
|
+
return chalk.white("[Think] ");
|
|
77
|
+
return statusLabel(status);
|
|
78
|
+
}
|
|
48
79
|
if (phase === "permission")
|
|
49
80
|
return chalk.red("[Allow] ");
|
|
50
81
|
if (phase === "tool")
|
|
@@ -272,6 +303,39 @@ function jumpAttentionLine(item) {
|
|
|
272
303
|
}
|
|
273
304
|
return ` ${status} ${agent} ${chalk.dim(path)}${runtime}${icon}\n PID:${item.pid} ${stats}${started}${activity}`;
|
|
274
305
|
}
|
|
306
|
+
function paginateJumpAttentionItems(items, page, pageSize = 10) {
|
|
307
|
+
const normalizedPage = Number.isInteger(page) && page > 0 ? page : 1;
|
|
308
|
+
const normalizedSize = Number.isInteger(pageSize) && pageSize > 0 ? pageSize : 10;
|
|
309
|
+
const start = (normalizedPage - 1) * normalizedSize;
|
|
310
|
+
return items.slice(start, start + normalizedSize);
|
|
311
|
+
}
|
|
312
|
+
export function renderJumpAttentionChooser(agents, page = 1, pageSize = 10) {
|
|
313
|
+
const items = buildJumpAttentionItems(agents);
|
|
314
|
+
if (items.length === 0) {
|
|
315
|
+
return "No jumpable attention items.";
|
|
316
|
+
}
|
|
317
|
+
const shown = paginateJumpAttentionItems(items, page, pageSize);
|
|
318
|
+
if (shown.length === 0) {
|
|
319
|
+
return "No jumpable attention items.";
|
|
320
|
+
}
|
|
321
|
+
const totalPages = Math.max(1, Math.ceil(items.length / pageSize));
|
|
322
|
+
const lines = [
|
|
323
|
+
`Select session to jump to (${items.length}) — ${totalPages > 1 ? `< ${page}/${totalPages} >` : "< 1/1 >"}:`,
|
|
324
|
+
];
|
|
325
|
+
shown.forEach((item, index) => {
|
|
326
|
+
const [firstLine, ...restLines] = jumpAttentionLine(item).split("\n");
|
|
327
|
+
const displayNumber = index + 1;
|
|
328
|
+
const indexLabel = `${displayNumber})`.padStart(displayNumber === 10 ? 4 : 3);
|
|
329
|
+
lines.push(`${indexLabel} ${firstLine.trimStart()}`);
|
|
330
|
+
for (const line of restLines) {
|
|
331
|
+
lines.push(` ${line.trimStart()}`);
|
|
332
|
+
}
|
|
333
|
+
if (index < shown.length - 1) {
|
|
334
|
+
lines.push(chalk.dim(" ───────────────────────────────────────────────────────────"));
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
return lines.join("\n");
|
|
338
|
+
}
|
|
275
339
|
export function printAttention(agents, limit = 12) {
|
|
276
340
|
const items = buildAttentionItems(agents);
|
|
277
341
|
if (items.length === 0) {
|
|
@@ -311,25 +375,8 @@ export function printAttentionChooser(agents, limit = 12) {
|
|
|
311
375
|
console.log(` ${index + 1}) ${attentionLine(item)}`);
|
|
312
376
|
});
|
|
313
377
|
}
|
|
314
|
-
export function printJumpAttentionChooser(agents, limit =
|
|
315
|
-
|
|
316
|
-
if (items.length === 0) {
|
|
317
|
-
console.log("No jumpable attention items.");
|
|
318
|
-
return;
|
|
319
|
-
}
|
|
320
|
-
console.log(`Select session to jump to (${items.length}):`);
|
|
321
|
-
items.forEach((item, index) => {
|
|
322
|
-
const [firstLine, ...restLines] = jumpAttentionLine(item).split("\n");
|
|
323
|
-
const indexLabel = `${index + 1})`.padStart(3);
|
|
324
|
-
console.log(`${indexLabel} ${firstLine.trimStart()}`);
|
|
325
|
-
for (const line of restLines) {
|
|
326
|
-
console.log(` ${line.trimStart()}`);
|
|
327
|
-
}
|
|
328
|
-
if (index < items.length - 1) {
|
|
329
|
-
console.log(chalk.dim(" ───────────────────────────────────────────────────────────"));
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
console.log(chalk.dim("\nPress 1-9 to jump, 0 for item 10, q to cancel."));
|
|
378
|
+
export function printJumpAttentionChooser(agents, limit = 10) {
|
|
379
|
+
console.log(renderJumpAttentionChooser(agents, 1, limit));
|
|
333
380
|
}
|
|
334
381
|
export function printJumpResult(result) {
|
|
335
382
|
if (!result.found) {
|
|
@@ -409,7 +456,7 @@ export function renderUnavailableStatusline(format = "compact") {
|
|
|
409
456
|
return "marmonitor unavailable";
|
|
410
457
|
}
|
|
411
458
|
/** Print one-line summary for tmux/terminal status bar */
|
|
412
|
-
export async function renderStatusline(agents, format = "compact", attentionLimit = 5, width) {
|
|
459
|
+
export async function renderStatusline(agents, format = "compact", attentionLimit = 5, width, badgeStyle = "basic", hasJumpAnchor = false) {
|
|
413
460
|
const alive = agents.filter((a) => a.status !== "Dead" && a.status !== "Unmatched");
|
|
414
461
|
const unmatched = agents.filter((a) => a.status === "Unmatched");
|
|
415
462
|
if (alive.length === 0) {
|
|
@@ -442,8 +489,8 @@ export async function renderStatusline(agents, format = "compact", attentionLimi
|
|
|
442
489
|
memoryUsedGb: sys.memoryUsedGb,
|
|
443
490
|
};
|
|
444
491
|
if (format === "tmux-badges") {
|
|
445
|
-
const focusText = buildTmuxAttentionPills(buildJumpAttentionItems(agents), attentionLimit, width);
|
|
446
|
-
return buildTmuxBadgeBar(snapshot, focusText);
|
|
492
|
+
const focusText = buildTmuxAttentionPills(buildJumpAttentionItems(agents), attentionLimit, width, badgeStyle);
|
|
493
|
+
return buildTmuxBadgeBar(snapshot, focusText, badgeStyle, hasJumpAnchor);
|
|
447
494
|
}
|
|
448
495
|
if (format === "wezterm-pills") {
|
|
449
496
|
const focusText = buildAttentionFocusText(buildAttentionItems(agents), attentionLimit, width);
|
package/dist/output/utils.d.ts
CHANGED
|
@@ -13,9 +13,10 @@ export declare function formatElapsedCompact(epochSec?: number, now?: number): s
|
|
|
13
13
|
/** Format token count (e.g. 1234 -> "1.2K", 1234567 -> "1.2M") */
|
|
14
14
|
export declare function formatTokens(n: number): string;
|
|
15
15
|
/** Compact directory label for dock/focus display.
|
|
16
|
-
*
|
|
17
|
-
* e.g. "/Users/macrent
|
|
18
|
-
* "/Users/macrent/
|
|
16
|
+
* Replaces $HOME with ~ first, then shows last 2 path segments.
|
|
17
|
+
* e.g. "/Users/macrent" → "~"
|
|
18
|
+
* "/Users/macrent/marmonitor" → "~/marmonitor"
|
|
19
|
+
* "/Users/macrent/Documents/vos/vos-data-service" → "vos/vos-data-service"
|
|
19
20
|
* "/Users/macrent/.ai/projects/vos" → "projects/vos" */
|
|
20
21
|
export declare function compactDirLabel(cwd: string): string;
|
|
21
22
|
/** Compact directory label for narrow statusline surfaces.
|
|
@@ -118,13 +119,25 @@ export declare function resolveSessionRegistryPath(registry: Map<string, Session
|
|
|
118
119
|
export declare function upsertSessionRegistryEntry(registry: Map<string, SessionRegistryEntry>, entry: SessionRegistryEntry): void;
|
|
119
120
|
export declare function selectRecentSessionFile(candidates: SessionFileCandidate[], nowMs?: number, maxAgeMs?: number, minLeadMs?: number): string | undefined;
|
|
120
121
|
/** Build prioritized attention list for popup/jump UX.
|
|
121
|
-
* Order: permission -> thinking ->
|
|
122
|
-
export declare function buildAttentionItems(agents: AgentSession[]): AttentionItem[];
|
|
122
|
+
* Order: permission -> fresh thinking/tool -> recent alive sessions -> stale thinking/tool. */
|
|
123
|
+
export declare function buildAttentionItems(agents: AgentSession[], nowSec?: number): AttentionItem[];
|
|
123
124
|
export declare function selectAttentionItem(agents: AgentSession[], selection: number): AttentionItem | undefined;
|
|
124
125
|
/** Build jumpable attention items for interactive navigation.
|
|
125
126
|
* Statusline/jump share the same top-of-mind ordering. */
|
|
126
|
-
export declare function buildJumpAttentionItems(agents: AgentSession[]): AttentionItem[];
|
|
127
|
+
export declare function buildJumpAttentionItems(agents: AgentSession[], nowSec?: number): AttentionItem[];
|
|
127
128
|
export declare function selectJumpAttentionItem(agents: AgentSession[], selection: number): AttentionItem | undefined;
|
|
129
|
+
export declare function selectJumpAttentionItemOnPage(agents: AgentSession[], page: number, selection: number, pageSize?: number): AttentionItem | undefined;
|
|
130
|
+
export type SelectionAction = {
|
|
131
|
+
kind: "cancel";
|
|
132
|
+
} | {
|
|
133
|
+
kind: "next";
|
|
134
|
+
} | {
|
|
135
|
+
kind: "prev";
|
|
136
|
+
} | {
|
|
137
|
+
kind: "select";
|
|
138
|
+
selection: number;
|
|
139
|
+
};
|
|
140
|
+
export declare function parseSelectionInput(input: string, maxChoice: number, currentPage?: number, totalPages?: number): SelectionAction | undefined;
|
|
128
141
|
export declare function buildAttentionFocusText(items: AttentionItem[], maxCount?: number, width?: number): string | undefined;
|
|
129
142
|
export declare function buildTmuxBadgeSummary(snapshot: StatuslineSnapshot): string;
|
|
130
143
|
export declare function buildStatusPills(snapshot: StatuslineSnapshot): {
|
|
@@ -133,6 +146,7 @@ export declare function buildStatusPills(snapshot: StatuslineSnapshot): {
|
|
|
133
146
|
};
|
|
134
147
|
/** Build one-line persistent-bar summary string. */
|
|
135
148
|
export declare function buildStatuslineSummary(snapshot: StatuslineSnapshot, format?: StatuslineFormat): string;
|
|
136
|
-
export
|
|
137
|
-
export declare function
|
|
149
|
+
export type BadgeStyle = "basic" | "basic-mono" | "text" | "text-mono";
|
|
150
|
+
export declare function buildTmuxBadgeBar(snapshot: StatuslineSnapshot, focusText?: string, badgeStyle?: BadgeStyle, hasJumpAnchor?: boolean): string;
|
|
151
|
+
export declare function buildTmuxAttentionPills(items: AttentionItem[], maxCount?: number, width?: number, badgeStyle?: BadgeStyle): string | undefined;
|
|
138
152
|
export declare function serializeWeztermPills(snapshot: StatuslineSnapshot, focusText?: string): string;
|
package/dist/output/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { renderAttention, renderBadge, renderFocus, resolveTheme } from "./badge-themes.js";
|
|
1
2
|
/**
|
|
2
3
|
* Pure utility functions for marmonitor.
|
|
3
4
|
* Extracted for testability — no side effects, no I/O.
|
|
@@ -49,12 +50,17 @@ export function formatTokens(n) {
|
|
|
49
50
|
return String(n);
|
|
50
51
|
}
|
|
51
52
|
/** Compact directory label for dock/focus display.
|
|
52
|
-
*
|
|
53
|
-
* e.g. "/Users/macrent
|
|
54
|
-
* "/Users/macrent/
|
|
53
|
+
* Replaces $HOME with ~ first, then shows last 2 path segments.
|
|
54
|
+
* e.g. "/Users/macrent" → "~"
|
|
55
|
+
* "/Users/macrent/marmonitor" → "~/marmonitor"
|
|
56
|
+
* "/Users/macrent/Documents/vos/vos-data-service" → "vos/vos-data-service"
|
|
55
57
|
* "/Users/macrent/.ai/projects/vos" → "projects/vos" */
|
|
56
58
|
export function compactDirLabel(cwd) {
|
|
57
|
-
const
|
|
59
|
+
const home = process.env.HOME ?? "";
|
|
60
|
+
const shortened = home && cwd.startsWith(home) ? `~${cwd.slice(home.length)}` : cwd;
|
|
61
|
+
if (shortened === "~")
|
|
62
|
+
return "~";
|
|
63
|
+
const parts = shortened.split("/").filter(Boolean);
|
|
58
64
|
if (parts.length <= 1)
|
|
59
65
|
return parts[0] || cwd;
|
|
60
66
|
return parts.slice(-2).join("/");
|
|
@@ -269,13 +275,6 @@ function agentShortName(agentName) {
|
|
|
269
275
|
return "Gm";
|
|
270
276
|
return agentName;
|
|
271
277
|
}
|
|
272
|
-
function attentionPriority(agent) {
|
|
273
|
-
if (agent.phase === "permission")
|
|
274
|
-
return 0;
|
|
275
|
-
if (agent.phase === "thinking")
|
|
276
|
-
return 1;
|
|
277
|
-
return undefined;
|
|
278
|
-
}
|
|
279
278
|
function attentionKind(agent) {
|
|
280
279
|
if (agent.phase === "permission")
|
|
281
280
|
return "permission";
|
|
@@ -291,29 +290,32 @@ function attentionKind(agent) {
|
|
|
291
290
|
function attentionActivityTime(agent) {
|
|
292
291
|
return agent.lastActivityAt ?? agent.lastResponseAt ?? agent.startedAt ?? 0;
|
|
293
292
|
}
|
|
293
|
+
const STALE_ATTENTION_PHASE_SEC = 10 * 60;
|
|
294
|
+
function attentionPriority(agent, nowSec = Date.now() / 1000) {
|
|
295
|
+
if (agent.phase === "permission")
|
|
296
|
+
return 0;
|
|
297
|
+
const activityTime = attentionActivityTime(agent);
|
|
298
|
+
if (activityTime <= 0)
|
|
299
|
+
return undefined;
|
|
300
|
+
const elapsedSec = Math.max(0, nowSec - activityTime);
|
|
301
|
+
const isFresh = elapsedSec <= STALE_ATTENTION_PHASE_SEC;
|
|
302
|
+
if (agent.phase === "thinking" && isFresh)
|
|
303
|
+
return 1;
|
|
304
|
+
if (agent.phase === "tool" && isFresh)
|
|
305
|
+
return 2;
|
|
306
|
+
return undefined;
|
|
307
|
+
}
|
|
294
308
|
function orderedAttentionItems(items) {
|
|
295
|
-
const tier1Order = {
|
|
296
|
-
permission: 0,
|
|
297
|
-
thinking: 1,
|
|
298
|
-
};
|
|
299
309
|
return [...items].sort((a, b) => {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
if (aTier1 !== undefined || bTier1 !== undefined) {
|
|
303
|
-
if (aTier1 === undefined)
|
|
304
|
-
return 1;
|
|
305
|
-
if (bTier1 === undefined)
|
|
306
|
-
return -1;
|
|
307
|
-
if (aTier1 !== bTier1)
|
|
308
|
-
return aTier1 - bTier1;
|
|
309
|
-
return attentionActivityTime(b) - attentionActivityTime(a);
|
|
310
|
+
if (a.priority !== b.priority) {
|
|
311
|
+
return a.priority - b.priority;
|
|
310
312
|
}
|
|
311
313
|
return attentionActivityTime(b) - attentionActivityTime(a);
|
|
312
314
|
});
|
|
313
315
|
}
|
|
314
316
|
/** Build prioritized attention list for popup/jump UX.
|
|
315
|
-
* Order: permission -> thinking ->
|
|
316
|
-
export function buildAttentionItems(agents) {
|
|
317
|
+
* Order: permission -> fresh thinking/tool -> recent alive sessions -> stale thinking/tool. */
|
|
318
|
+
export function buildAttentionItems(agents, nowSec = Date.now() / 1000) {
|
|
317
319
|
const alive = agents.filter((agent) => agent.status !== "Dead" && agent.status !== "Unmatched" && agent.status !== "Stalled");
|
|
318
320
|
const toAttentionItem = (agent, priority, kind) => ({
|
|
319
321
|
kind,
|
|
@@ -331,20 +333,20 @@ export function buildAttentionItems(agents) {
|
|
|
331
333
|
lastActivityAt: agent.lastActivityAt,
|
|
332
334
|
});
|
|
333
335
|
const tier1 = alive
|
|
334
|
-
.filter((agent) => attentionPriority(agent) !== undefined)
|
|
336
|
+
.filter((agent) => attentionPriority(agent, nowSec) !== undefined)
|
|
335
337
|
.sort((a, b) => {
|
|
336
|
-
const aPriority = attentionPriority(a) ?? Number.MAX_SAFE_INTEGER;
|
|
337
|
-
const bPriority = attentionPriority(b) ?? Number.MAX_SAFE_INTEGER;
|
|
338
|
+
const aPriority = attentionPriority(a, nowSec) ?? Number.MAX_SAFE_INTEGER;
|
|
339
|
+
const bPriority = attentionPriority(b, nowSec) ?? Number.MAX_SAFE_INTEGER;
|
|
338
340
|
if (aPriority !== bPriority)
|
|
339
341
|
return aPriority - bPriority;
|
|
340
342
|
return attentionActivityTime(b) - attentionActivityTime(a);
|
|
341
343
|
})
|
|
342
|
-
.map((agent) => toAttentionItem(agent, attentionPriority(agent) ?? 0, attentionKind(agent) ?? "active"));
|
|
344
|
+
.map((agent) => toAttentionItem(agent, attentionPriority(agent, nowSec) ?? 0, attentionKind(agent) ?? "active"));
|
|
343
345
|
const tier1Pids = new Set(tier1.map((item) => item.pid));
|
|
344
346
|
const tier2 = alive
|
|
345
347
|
.filter((agent) => !tier1Pids.has(agent.pid))
|
|
346
348
|
.sort((a, b) => attentionActivityTime(b) - attentionActivityTime(a))
|
|
347
|
-
.map((agent) => toAttentionItem(agent,
|
|
349
|
+
.map((agent) => toAttentionItem(agent, 3, attentionKind(agent) ?? "active"));
|
|
348
350
|
return [...tier1, ...tier2];
|
|
349
351
|
}
|
|
350
352
|
export function selectAttentionItem(agents, selection) {
|
|
@@ -354,14 +356,47 @@ export function selectAttentionItem(agents, selection) {
|
|
|
354
356
|
}
|
|
355
357
|
/** Build jumpable attention items for interactive navigation.
|
|
356
358
|
* Statusline/jump share the same top-of-mind ordering. */
|
|
357
|
-
export function buildJumpAttentionItems(agents) {
|
|
358
|
-
return orderedAttentionItems(buildAttentionItems(agents));
|
|
359
|
+
export function buildJumpAttentionItems(agents, nowSec = Date.now() / 1000) {
|
|
360
|
+
return orderedAttentionItems(buildAttentionItems(agents, nowSec));
|
|
359
361
|
}
|
|
360
362
|
export function selectJumpAttentionItem(agents, selection) {
|
|
361
363
|
if (!Number.isInteger(selection) || selection < 1)
|
|
362
364
|
return undefined;
|
|
363
365
|
return buildJumpAttentionItems(agents)[selection - 1];
|
|
364
366
|
}
|
|
367
|
+
export function selectJumpAttentionItemOnPage(agents, page, selection, pageSize = 10) {
|
|
368
|
+
if (!Number.isInteger(selection) || selection < 1)
|
|
369
|
+
return undefined;
|
|
370
|
+
if (!Number.isInteger(page) || page < 1)
|
|
371
|
+
return undefined;
|
|
372
|
+
if (!Number.isInteger(pageSize) || pageSize < 1)
|
|
373
|
+
return undefined;
|
|
374
|
+
const start = (page - 1) * pageSize;
|
|
375
|
+
return buildJumpAttentionItems(agents)[start + selection - 1];
|
|
376
|
+
}
|
|
377
|
+
export function parseSelectionInput(input, maxChoice, currentPage = 1, totalPages = 1) {
|
|
378
|
+
if (input === "\u001b" || input === "q" || input === "Q") {
|
|
379
|
+
return { kind: "cancel" };
|
|
380
|
+
}
|
|
381
|
+
if (input === "\u001b[C" && currentPage < totalPages) {
|
|
382
|
+
return { kind: "next" };
|
|
383
|
+
}
|
|
384
|
+
if (input === "\u001b[D" && currentPage > 1) {
|
|
385
|
+
return { kind: "prev" };
|
|
386
|
+
}
|
|
387
|
+
const trimmed = input.trim();
|
|
388
|
+
if (/^[1-9]$/.test(trimmed)) {
|
|
389
|
+
const selection = Number.parseInt(trimmed, 10);
|
|
390
|
+
if (selection <= maxChoice) {
|
|
391
|
+
return { kind: "select", selection };
|
|
392
|
+
}
|
|
393
|
+
return undefined;
|
|
394
|
+
}
|
|
395
|
+
if (trimmed === "0" && maxChoice >= 10) {
|
|
396
|
+
return { kind: "select", selection: 10 };
|
|
397
|
+
}
|
|
398
|
+
return undefined;
|
|
399
|
+
}
|
|
365
400
|
export function buildAttentionFocusText(items, maxCount = 3, width) {
|
|
366
401
|
if (maxCount <= 0 || items.length === 0)
|
|
367
402
|
return undefined;
|
|
@@ -509,12 +544,6 @@ export function buildStatuslineSummary(snapshot, format = "compact") {
|
|
|
509
544
|
standardParts.push(...metrics);
|
|
510
545
|
return standardParts.join(" | ");
|
|
511
546
|
}
|
|
512
|
-
function tmuxPill(label, fg, bg) {
|
|
513
|
-
return `#[fg=${bg},bg=#1e1e2e]#[bold,fg=${fg},bg=${bg}] ${label} #[fg=${bg},bg=#1e1e2e]#[default]`;
|
|
514
|
-
}
|
|
515
|
-
function tmuxDetailBlock(label) {
|
|
516
|
-
return `#[fg=#cdd6f4,bg=#313244] ${label} #[fg=#313244,bg=#1e1e2e]#[default]`;
|
|
517
|
-
}
|
|
518
547
|
function attentionBg(kind) {
|
|
519
548
|
if (kind === "permission")
|
|
520
549
|
return "#f38ba8";
|
|
@@ -530,22 +559,28 @@ function tmuxAttentionSegment(index, kind, label) {
|
|
|
530
559
|
const bg = attentionBg(kind);
|
|
531
560
|
return `#[fg=${bg},bg=#1e1e2e]#[bold,fg=#11111b,bg=${bg}] ${index} #[fg=#313244,bg=${bg}]#[fg=#cdd6f4,bg=#313244] ${label} #[fg=#313244,bg=#1e1e2e]#[default]`;
|
|
532
561
|
}
|
|
533
|
-
|
|
562
|
+
function tmuxUserRange(value, content) {
|
|
563
|
+
return `#[range=user|${value}]${content}#[norange]`;
|
|
564
|
+
}
|
|
565
|
+
export function buildTmuxBadgeBar(snapshot, focusText, badgeStyle = "basic", hasJumpAnchor = false) {
|
|
566
|
+
const theme = resolveTheme(badgeStyle);
|
|
534
567
|
const { agents, alerts } = buildStatusPills(snapshot);
|
|
535
|
-
const agentPills = agents.map((pill) =>
|
|
536
|
-
const alertPills = alerts.map((pill) =>
|
|
537
|
-
const
|
|
538
|
-
|
|
568
|
+
const agentPills = agents.map((pill) => renderBadge(theme, pill.label, pill.fg, pill.bg));
|
|
569
|
+
const alertPills = alerts.map((pill) => renderBadge(theme, pill.label, pill.fg, pill.bg));
|
|
570
|
+
const jumpBack = hasJumpAnchor ? tmuxUserRange("jump-back", theme.jumpBack) : "";
|
|
571
|
+
const focus = focusText ? renderFocus(theme, focusText) : "";
|
|
572
|
+
return [agentPills.join(" "), alertPills.join(" "), jumpBack, focus].filter(Boolean).join(" ");
|
|
539
573
|
}
|
|
540
|
-
export function buildTmuxAttentionPills(items, maxCount = 5, width) {
|
|
574
|
+
export function buildTmuxAttentionPills(items, maxCount = 5, width, badgeStyle = "basic") {
|
|
541
575
|
if (maxCount <= 0)
|
|
542
576
|
return undefined;
|
|
543
577
|
const layout = resolveStatuslineDetailLayout(width, maxCount);
|
|
544
578
|
const jumpItems = orderedAttentionItems(items)
|
|
545
579
|
.filter((item) => item.kind !== "unmatched" && item.kind !== "stalled")
|
|
546
580
|
.slice(0, layout.itemCount);
|
|
581
|
+
const theme = resolveTheme(badgeStyle);
|
|
547
582
|
if (jumpItems.length === 0) {
|
|
548
|
-
return
|
|
583
|
+
return theme.empty;
|
|
549
584
|
}
|
|
550
585
|
const segments = jumpItems.map((item, index) => {
|
|
551
586
|
const agent = agentShortName(item.agentName);
|
|
@@ -568,7 +603,7 @@ export function buildTmuxAttentionPills(items, maxCount = 5, width) {
|
|
|
568
603
|
: time
|
|
569
604
|
? `⚠${agent} ${path} ${time}`
|
|
570
605
|
: `⚠${agent} ${path}`;
|
|
571
|
-
return
|
|
606
|
+
return tmuxUserRange(`pid:${item.pid}`, renderAttention(theme, index + 1, label, attentionBg(item.kind)));
|
|
572
607
|
});
|
|
573
608
|
return segments.join(" ");
|
|
574
609
|
}
|
package/dist/scanner/claude.d.ts
CHANGED
|
@@ -21,5 +21,12 @@ export declare function parseClaudeTokens(sessionId: string, cwd: string, starte
|
|
|
21
21
|
* Detect current Claude session phase by reading the last few lines of JSONL.
|
|
22
22
|
*/
|
|
23
23
|
export declare function detectClaudePhase(sessionId: string, cwd: string, startedAt?: number, config?: MarmonitorConfig): Promise<PhaseResult>;
|
|
24
|
+
/**
|
|
25
|
+
* Match a Claude session by scanning JSONL files in the project directory.
|
|
26
|
+
* When processStartedAt is available, matches by JSONL creation timestamp
|
|
27
|
+
* (first-line timestamp) proximity to process start time.
|
|
28
|
+
* Falls back to the most recently modified JSONL when no start time is available.
|
|
29
|
+
*/
|
|
30
|
+
export declare function matchClaudeSessionByMtime(cwd: string, processStartedAt: number | undefined, config?: MarmonitorConfig): Promise<Partial<AgentSession> | undefined>;
|
|
24
31
|
/** Parse Claude Code session file for enriched data */
|
|
25
|
-
export declare function parseClaudeSession(pid: number, config?: MarmonitorConfig): Promise<Partial<AgentSession>>;
|
|
32
|
+
export declare function parseClaudeSession(pid: number, cwd?: string, processStartedAt?: number, config?: MarmonitorConfig): Promise<Partial<AgentSession>>;
|
package/dist/scanner/claude.js
CHANGED
|
@@ -394,32 +394,169 @@ export async function detectClaudePhase(sessionId, cwd, startedAt, config) {
|
|
|
394
394
|
return {};
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
|
-
/**
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
return {};
|
|
397
|
+
/**
|
|
398
|
+
* Read the first line of a JSONL file to extract session metadata.
|
|
399
|
+
* Returns undefined if the file can't be read or parsed.
|
|
400
|
+
*/
|
|
401
|
+
async function readJsonlFirstLine(filePath) {
|
|
402
|
+
let fd;
|
|
404
403
|
try {
|
|
405
|
-
|
|
406
|
-
const
|
|
407
|
-
|
|
404
|
+
fd = await open(filePath, "r");
|
|
405
|
+
const buf = Buffer.alloc(4096);
|
|
406
|
+
await fd.read(buf, 0, 4096, 0);
|
|
407
|
+
const firstLine = buf.toString("utf-8").split("\n")[0];
|
|
408
|
+
if (!firstLine)
|
|
409
|
+
return undefined;
|
|
410
|
+
return JSON.parse(firstLine);
|
|
411
|
+
}
|
|
412
|
+
catch {
|
|
413
|
+
return undefined;
|
|
414
|
+
}
|
|
415
|
+
finally {
|
|
416
|
+
await fd?.close().catch(() => { });
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Match a Claude session by scanning JSONL files in the project directory.
|
|
421
|
+
* When processStartedAt is available, matches by JSONL creation timestamp
|
|
422
|
+
* (first-line timestamp) proximity to process start time.
|
|
423
|
+
* Falls back to the most recently modified JSONL when no start time is available.
|
|
424
|
+
*/
|
|
425
|
+
export async function matchClaudeSessionByMtime(cwd, processStartedAt, config) {
|
|
426
|
+
const projectDirName = await findClaudeProjectDir(cwd, undefined, config);
|
|
427
|
+
if (!projectDirName)
|
|
428
|
+
return undefined;
|
|
429
|
+
const projectRoots = getClaudeProjectRoots(config);
|
|
430
|
+
const candidates = [];
|
|
431
|
+
for (const projectsDir of projectRoots) {
|
|
432
|
+
const projectDir = join(projectsDir, projectDirName);
|
|
433
|
+
if (!existsSync(projectDir))
|
|
434
|
+
continue;
|
|
435
|
+
try {
|
|
436
|
+
const files = await readdir(projectDir);
|
|
437
|
+
for (const file of files) {
|
|
438
|
+
if (!file.endsWith(".jsonl"))
|
|
439
|
+
continue;
|
|
440
|
+
try {
|
|
441
|
+
const filePath = join(projectDir, file);
|
|
442
|
+
const fileStat = await stat(filePath);
|
|
443
|
+
candidates.push({ path: filePath, mtimeMs: fileStat.mtimeMs });
|
|
444
|
+
}
|
|
445
|
+
catch {
|
|
446
|
+
// skip
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
catch {
|
|
451
|
+
// skip
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
if (candidates.length === 0)
|
|
455
|
+
return undefined;
|
|
456
|
+
let bestPath;
|
|
457
|
+
if (processStartedAt) {
|
|
458
|
+
const startMs = processStartedAt * 1000;
|
|
459
|
+
// Pre-filter: only consider JSONL files modified after process start (with tolerance)
|
|
460
|
+
const active = candidates.filter((c) => c.mtimeMs >= startMs - CLAUDE_SESSION_MTIME_MATCH_SEC * 1000);
|
|
461
|
+
const pool = active.length > 0 ? active : candidates;
|
|
462
|
+
// Read first lines to get creation timestamps and match by proximity
|
|
463
|
+
const scored = [];
|
|
464
|
+
for (const c of pool) {
|
|
465
|
+
const firstLine = await readJsonlFirstLine(c.path);
|
|
466
|
+
if (!firstLine?.timestamp)
|
|
467
|
+
continue;
|
|
468
|
+
const createdAt = new Date(firstLine.timestamp).getTime() / 1000;
|
|
469
|
+
scored.push({
|
|
470
|
+
path: c.path,
|
|
471
|
+
deltaSec: Math.abs(createdAt - processStartedAt),
|
|
472
|
+
mtimeMs: c.mtimeMs,
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
if (scored.length > 0) {
|
|
476
|
+
// Pick the JSONL whose creation time is closest to process start
|
|
477
|
+
scored.sort((a, b) => a.deltaSec - b.deltaSec);
|
|
478
|
+
// Only accept if within reasonable tolerance (5 minutes)
|
|
479
|
+
if (scored[0].deltaSec <= 300) {
|
|
480
|
+
bestPath = scored[0].path;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
// Fallback: most recently modified
|
|
484
|
+
if (!bestPath) {
|
|
485
|
+
pool.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
486
|
+
bestPath = pool[0].path;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
else {
|
|
490
|
+
// No process start time — pick most recently modified
|
|
491
|
+
candidates.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
492
|
+
bestPath = candidates[0].path;
|
|
493
|
+
}
|
|
494
|
+
// Read first line for session metadata
|
|
495
|
+
const entry = await readJsonlFirstLine(bestPath);
|
|
496
|
+
if (!entry?.sessionId)
|
|
497
|
+
return undefined;
|
|
498
|
+
try {
|
|
499
|
+
const fileStat = await stat(bestPath);
|
|
500
|
+
const sessionCwd = entry.cwd ?? cwd;
|
|
408
501
|
const result = {
|
|
409
|
-
cwd:
|
|
410
|
-
sessionId:
|
|
411
|
-
startedAt:
|
|
502
|
+
cwd: sessionCwd,
|
|
503
|
+
sessionId: entry.sessionId,
|
|
504
|
+
startedAt: entry.timestamp ? new Date(entry.timestamp).getTime() / 1000 : undefined,
|
|
412
505
|
lastActivityAt: fileStat.mtimeMs / 1000,
|
|
413
506
|
sessionMatched: true,
|
|
414
507
|
};
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
508
|
+
// Register in session registry for subsequent lookups
|
|
509
|
+
upsertSessionRegistryEntry(claudeSessionRegistry, {
|
|
510
|
+
filePath: bestPath,
|
|
511
|
+
sessionId: entry.sessionId,
|
|
512
|
+
cwd: sessionCwd,
|
|
513
|
+
firstSeenOffset: 0,
|
|
514
|
+
startedAt: result.startedAt,
|
|
515
|
+
source: "claude",
|
|
516
|
+
});
|
|
517
|
+
const tokenData = await parseClaudeTokens(entry.sessionId, sessionCwd, result.startedAt, config);
|
|
518
|
+
result.tokenUsage = tokenData.tokenUsage;
|
|
519
|
+
result.model = tokenData.model;
|
|
420
520
|
return result;
|
|
421
521
|
}
|
|
422
522
|
catch {
|
|
423
|
-
return
|
|
523
|
+
return undefined;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
/** Parse Claude Code session file for enriched data */
|
|
527
|
+
export async function parseClaudeSession(pid, cwd, processStartedAt, config) {
|
|
528
|
+
// 1st: try legacy sessions/{pid}.json
|
|
529
|
+
const sessionFile = getClaudeSessionRoots(config)
|
|
530
|
+
.map((root) => join(root, `${pid}.json`))
|
|
531
|
+
.find((candidate) => existsSync(candidate));
|
|
532
|
+
if (sessionFile) {
|
|
533
|
+
try {
|
|
534
|
+
const fileStat = await stat(sessionFile);
|
|
535
|
+
const raw = await readFile(sessionFile, "utf-8");
|
|
536
|
+
const data = JSON.parse(raw);
|
|
537
|
+
const result = {
|
|
538
|
+
cwd: data.cwd,
|
|
539
|
+
sessionId: data.sessionId,
|
|
540
|
+
startedAt: data.startedAt ? data.startedAt / 1000 : undefined,
|
|
541
|
+
lastActivityAt: fileStat.mtimeMs / 1000,
|
|
542
|
+
sessionMatched: true,
|
|
543
|
+
};
|
|
544
|
+
if (data.sessionId && data.cwd) {
|
|
545
|
+
const tokenData = await parseClaudeTokens(data.sessionId, data.cwd, data.startedAt ? data.startedAt / 1000 : undefined, config);
|
|
546
|
+
result.tokenUsage = tokenData.tokenUsage;
|
|
547
|
+
result.model = tokenData.model;
|
|
548
|
+
}
|
|
549
|
+
return result;
|
|
550
|
+
}
|
|
551
|
+
catch {
|
|
552
|
+
// fall through to mtime-based matching
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
// 2nd: match by JSONL mtime in project directory
|
|
556
|
+
if (cwd && cwd !== "unknown") {
|
|
557
|
+
const matched = await matchClaudeSessionByMtime(cwd, processStartedAt, config);
|
|
558
|
+
if (matched)
|
|
559
|
+
return matched;
|
|
424
560
|
}
|
|
561
|
+
return {};
|
|
425
562
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codex session indexing via SQLite threads table.
|
|
3
|
+
* Uses sqlite3 CLI (pre-installed on macOS/Linux) — no npm dependency.
|
|
4
|
+
* Falls back gracefully if sqlite3 is unavailable or DB is missing.
|
|
5
|
+
*/
|
|
6
|
+
import type { CodexSessionMeta } from "./cache.js";
|
|
7
|
+
/**
|
|
8
|
+
* Query Codex state SQLite for active (non-archived) threads.
|
|
9
|
+
* Returns CodexSessionMeta[] compatible with existing matchCodexSession().
|
|
10
|
+
*/
|
|
11
|
+
export declare function indexCodexSessionsFromSqlite(dbPath: string): Promise<CodexSessionMeta[]>;
|