marmonitor 0.1.6 → 0.2.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.
- package/README.ko.md +248 -0
- package/README.md +41 -5
- package/bin/daemon.js +2 -0
- package/bin/postinstall.cjs +75 -0
- package/bin/preuninstall.cjs +14 -0
- package/dist/banner/index.js +15 -7
- package/dist/cli.js +297 -110
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +5 -3
- 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 +23 -9
- package/dist/output/utils.js +85 -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/gemini.js +3 -1
- 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 +2 -2
- package/bin/postinstall.js +0 -20
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Badge theme definitions for tmux statusline rendering.
|
|
3
|
+
* Each theme defines template strings with placeholders:
|
|
4
|
+
* {label}, {fg}, {bg} for badges
|
|
5
|
+
* {index}, {label}, {bg} for attention segments
|
|
6
|
+
* {text} for focus text
|
|
7
|
+
*/
|
|
8
|
+
export const BADGE_THEMES = {
|
|
9
|
+
basic: {
|
|
10
|
+
badge: "#[fg={bg},bg=#1e1e2e]#[bold,fg={fg},bg={bg}] {label} #[fg={bg},bg=#1e1e2e]#[default]",
|
|
11
|
+
attention: "#[fg={bg},bg=#1e1e2e]#[bold,fg=#11111b,bg={bg}] {index} #[fg=#313244,bg={bg}]#[fg=#cdd6f4,bg=#313244] {label} #[fg=#313244,bg=#1e1e2e]#[default]",
|
|
12
|
+
focus: "#[fg=#bac2de,bg=#181825] {text} #[default]",
|
|
13
|
+
empty: "#[fg=#cdd6f4,bg=#313244] no active #[fg=#313244,bg=#1e1e2e]#[default]",
|
|
14
|
+
jumpBack: "#[fg=#45475a,bg=#1e1e2e]#[fg=#bac2de,bg=#45475a] ↩ #[fg=#45475a,bg=#1e1e2e]#[default]",
|
|
15
|
+
},
|
|
16
|
+
"basic-mono": {
|
|
17
|
+
badge: "#[fg=#313244,bg=#1e1e2e]#[bold,fg=#cdd6f4,bg=#313244] {label} #[fg=#313244,bg=#1e1e2e]#[default]",
|
|
18
|
+
attention: "#[fg=#313244,bg=#1e1e2e]#[bold,fg=#cdd6f4,bg=#313244] {index} #[fg=#1e1e2e,bg=#313244]#[fg=#6c7086,bg=#1e1e2e] {label} #[fg=#1e1e2e]#[default]",
|
|
19
|
+
focus: "#[fg=#6c7086,bg=#181825] {text} #[default]",
|
|
20
|
+
empty: "#[fg=#313244,bg=#1e1e2e]#[fg=#6c7086,bg=#313244] no active #[fg=#313244,bg=#1e1e2e]#[default]",
|
|
21
|
+
jumpBack: "#[fg=#313244,bg=#1e1e2e]#[fg=#6c7086,bg=#313244] ↩ #[fg=#313244,bg=#1e1e2e]#[default]",
|
|
22
|
+
},
|
|
23
|
+
text: {
|
|
24
|
+
badge: "#[fg={bg}]{label}#[default]",
|
|
25
|
+
attention: "#[fg={bg}]{index} {label}#[default]",
|
|
26
|
+
focus: "{text}",
|
|
27
|
+
empty: "no active",
|
|
28
|
+
jumpBack: "#[fg=#89b4fa]↩#[default]",
|
|
29
|
+
},
|
|
30
|
+
"text-mono": {
|
|
31
|
+
badge: "#[fg=#cdd6f4]{label}#[default]",
|
|
32
|
+
attention: "#[bold,fg=#cdd6f4]{index}#[default] #[fg=#6c7086]{label}#[default]",
|
|
33
|
+
focus: "#[fg=#6c7086]{text}#[default]",
|
|
34
|
+
empty: "#[fg=#6c7086]no active#[default]",
|
|
35
|
+
jumpBack: "#[fg=#6c7086]↩#[default]",
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
export function renderBadge(theme, label, fg, bg) {
|
|
39
|
+
return theme.badge.replaceAll("{label}", label).replaceAll("{fg}", fg).replaceAll("{bg}", bg);
|
|
40
|
+
}
|
|
41
|
+
export function renderAttention(theme, index, label, bg) {
|
|
42
|
+
return theme.attention
|
|
43
|
+
.replaceAll("{index}", String(index))
|
|
44
|
+
.replaceAll("{label}", label)
|
|
45
|
+
.replaceAll("{bg}", bg);
|
|
46
|
+
}
|
|
47
|
+
export function renderFocus(theme, text) {
|
|
48
|
+
return theme.focus.replaceAll("{text}", text);
|
|
49
|
+
}
|
|
50
|
+
export function resolveTheme(style) {
|
|
51
|
+
return BADGE_THEMES[style] ?? BADGE_THEMES.basic;
|
|
52
|
+
}
|
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.
|
|
@@ -108,7 +109,7 @@ export interface SessionFileCandidate {
|
|
|
108
109
|
}
|
|
109
110
|
export declare function resolvePhaseWithDecay(currentPhase: SessionPhase, cachedPhase: SessionPhase, cachedDetectedAtMs: number | undefined, decay: PhaseDecayConfig, nowMs?: number): SessionPhase;
|
|
110
111
|
export declare function advanceJsonlCursor(previous: JsonlCursorState, chunk: string, maxLines: number): JsonlCursorState;
|
|
111
|
-
export declare function detectApprovalPromptPhase(output:
|
|
112
|
+
export declare function detectApprovalPromptPhase(output: unknown, patterns?: string[], clearPatterns?: string[]): SessionPhase;
|
|
112
113
|
export declare function updatePhaseHistory(previousPhase: SessionPhase, previousHistory: PhaseHistoryEntry[], nextPhase: SessionPhase, at: number, maxEntries?: number): {
|
|
113
114
|
previousPhase?: SessionPhase;
|
|
114
115
|
history: PhaseHistoryEntry[];
|
|
@@ -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("/");
|
|
@@ -186,6 +192,8 @@ export function detectApprovalPromptPhase(output, patterns = [
|
|
|
186
192
|
"edited",
|
|
187
193
|
"changes applied",
|
|
188
194
|
]) {
|
|
195
|
+
if (!output || typeof output !== "string")
|
|
196
|
+
return undefined;
|
|
189
197
|
const recentLines = output
|
|
190
198
|
.split("\n")
|
|
191
199
|
.map((line) => line.trim())
|
|
@@ -267,13 +275,6 @@ function agentShortName(agentName) {
|
|
|
267
275
|
return "Gm";
|
|
268
276
|
return agentName;
|
|
269
277
|
}
|
|
270
|
-
function attentionPriority(agent) {
|
|
271
|
-
if (agent.phase === "permission")
|
|
272
|
-
return 0;
|
|
273
|
-
if (agent.phase === "thinking")
|
|
274
|
-
return 1;
|
|
275
|
-
return undefined;
|
|
276
|
-
}
|
|
277
278
|
function attentionKind(agent) {
|
|
278
279
|
if (agent.phase === "permission")
|
|
279
280
|
return "permission";
|
|
@@ -289,29 +290,32 @@ function attentionKind(agent) {
|
|
|
289
290
|
function attentionActivityTime(agent) {
|
|
290
291
|
return agent.lastActivityAt ?? agent.lastResponseAt ?? agent.startedAt ?? 0;
|
|
291
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
|
+
}
|
|
292
308
|
function orderedAttentionItems(items) {
|
|
293
|
-
const tier1Order = {
|
|
294
|
-
permission: 0,
|
|
295
|
-
thinking: 1,
|
|
296
|
-
};
|
|
297
309
|
return [...items].sort((a, b) => {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
if (aTier1 !== undefined || bTier1 !== undefined) {
|
|
301
|
-
if (aTier1 === undefined)
|
|
302
|
-
return 1;
|
|
303
|
-
if (bTier1 === undefined)
|
|
304
|
-
return -1;
|
|
305
|
-
if (aTier1 !== bTier1)
|
|
306
|
-
return aTier1 - bTier1;
|
|
307
|
-
return attentionActivityTime(b) - attentionActivityTime(a);
|
|
310
|
+
if (a.priority !== b.priority) {
|
|
311
|
+
return a.priority - b.priority;
|
|
308
312
|
}
|
|
309
313
|
return attentionActivityTime(b) - attentionActivityTime(a);
|
|
310
314
|
});
|
|
311
315
|
}
|
|
312
316
|
/** Build prioritized attention list for popup/jump UX.
|
|
313
|
-
* Order: permission -> thinking ->
|
|
314
|
-
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) {
|
|
315
319
|
const alive = agents.filter((agent) => agent.status !== "Dead" && agent.status !== "Unmatched" && agent.status !== "Stalled");
|
|
316
320
|
const toAttentionItem = (agent, priority, kind) => ({
|
|
317
321
|
kind,
|
|
@@ -329,20 +333,20 @@ export function buildAttentionItems(agents) {
|
|
|
329
333
|
lastActivityAt: agent.lastActivityAt,
|
|
330
334
|
});
|
|
331
335
|
const tier1 = alive
|
|
332
|
-
.filter((agent) => attentionPriority(agent) !== undefined)
|
|
336
|
+
.filter((agent) => attentionPriority(agent, nowSec) !== undefined)
|
|
333
337
|
.sort((a, b) => {
|
|
334
|
-
const aPriority = attentionPriority(a) ?? Number.MAX_SAFE_INTEGER;
|
|
335
|
-
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;
|
|
336
340
|
if (aPriority !== bPriority)
|
|
337
341
|
return aPriority - bPriority;
|
|
338
342
|
return attentionActivityTime(b) - attentionActivityTime(a);
|
|
339
343
|
})
|
|
340
|
-
.map((agent) => toAttentionItem(agent, attentionPriority(agent) ?? 0, attentionKind(agent) ?? "active"));
|
|
344
|
+
.map((agent) => toAttentionItem(agent, attentionPriority(agent, nowSec) ?? 0, attentionKind(agent) ?? "active"));
|
|
341
345
|
const tier1Pids = new Set(tier1.map((item) => item.pid));
|
|
342
346
|
const tier2 = alive
|
|
343
347
|
.filter((agent) => !tier1Pids.has(agent.pid))
|
|
344
348
|
.sort((a, b) => attentionActivityTime(b) - attentionActivityTime(a))
|
|
345
|
-
.map((agent) => toAttentionItem(agent,
|
|
349
|
+
.map((agent) => toAttentionItem(agent, 3, attentionKind(agent) ?? "active"));
|
|
346
350
|
return [...tier1, ...tier2];
|
|
347
351
|
}
|
|
348
352
|
export function selectAttentionItem(agents, selection) {
|
|
@@ -352,14 +356,47 @@ export function selectAttentionItem(agents, selection) {
|
|
|
352
356
|
}
|
|
353
357
|
/** Build jumpable attention items for interactive navigation.
|
|
354
358
|
* Statusline/jump share the same top-of-mind ordering. */
|
|
355
|
-
export function buildJumpAttentionItems(agents) {
|
|
356
|
-
return orderedAttentionItems(buildAttentionItems(agents));
|
|
359
|
+
export function buildJumpAttentionItems(agents, nowSec = Date.now() / 1000) {
|
|
360
|
+
return orderedAttentionItems(buildAttentionItems(agents, nowSec));
|
|
357
361
|
}
|
|
358
362
|
export function selectJumpAttentionItem(agents, selection) {
|
|
359
363
|
if (!Number.isInteger(selection) || selection < 1)
|
|
360
364
|
return undefined;
|
|
361
365
|
return buildJumpAttentionItems(agents)[selection - 1];
|
|
362
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
|
+
}
|
|
363
400
|
export function buildAttentionFocusText(items, maxCount = 3, width) {
|
|
364
401
|
if (maxCount <= 0 || items.length === 0)
|
|
365
402
|
return undefined;
|
|
@@ -507,12 +544,6 @@ export function buildStatuslineSummary(snapshot, format = "compact") {
|
|
|
507
544
|
standardParts.push(...metrics);
|
|
508
545
|
return standardParts.join(" | ");
|
|
509
546
|
}
|
|
510
|
-
function tmuxPill(label, fg, bg) {
|
|
511
|
-
return `#[fg=${bg},bg=#1e1e2e]#[bold,fg=${fg},bg=${bg}] ${label} #[fg=${bg},bg=#1e1e2e]#[default]`;
|
|
512
|
-
}
|
|
513
|
-
function tmuxDetailBlock(label) {
|
|
514
|
-
return `#[fg=#cdd6f4,bg=#313244] ${label} #[fg=#313244,bg=#1e1e2e]#[default]`;
|
|
515
|
-
}
|
|
516
547
|
function attentionBg(kind) {
|
|
517
548
|
if (kind === "permission")
|
|
518
549
|
return "#f38ba8";
|
|
@@ -528,22 +559,28 @@ function tmuxAttentionSegment(index, kind, label) {
|
|
|
528
559
|
const bg = attentionBg(kind);
|
|
529
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]`;
|
|
530
561
|
}
|
|
531
|
-
|
|
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);
|
|
532
567
|
const { agents, alerts } = buildStatusPills(snapshot);
|
|
533
|
-
const agentPills = agents.map((pill) =>
|
|
534
|
-
const alertPills = alerts.map((pill) =>
|
|
535
|
-
const
|
|
536
|
-
|
|
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(" ");
|
|
537
573
|
}
|
|
538
|
-
export function buildTmuxAttentionPills(items, maxCount = 5, width) {
|
|
574
|
+
export function buildTmuxAttentionPills(items, maxCount = 5, width, badgeStyle = "basic") {
|
|
539
575
|
if (maxCount <= 0)
|
|
540
576
|
return undefined;
|
|
541
577
|
const layout = resolveStatuslineDetailLayout(width, maxCount);
|
|
542
578
|
const jumpItems = orderedAttentionItems(items)
|
|
543
579
|
.filter((item) => item.kind !== "unmatched" && item.kind !== "stalled")
|
|
544
580
|
.slice(0, layout.itemCount);
|
|
581
|
+
const theme = resolveTheme(badgeStyle);
|
|
545
582
|
if (jumpItems.length === 0) {
|
|
546
|
-
return
|
|
583
|
+
return theme.empty;
|
|
547
584
|
}
|
|
548
585
|
const segments = jumpItems.map((item, index) => {
|
|
549
586
|
const agent = agentShortName(item.agentName);
|
|
@@ -566,7 +603,7 @@ export function buildTmuxAttentionPills(items, maxCount = 5, width) {
|
|
|
566
603
|
: time
|
|
567
604
|
? `⚠${agent} ${path} ${time}`
|
|
568
605
|
: `⚠${agent} ${path}`;
|
|
569
|
-
return
|
|
606
|
+
return tmuxUserRange(`pid:${item.pid}`, renderAttention(theme, index + 1, label, attentionBg(item.kind)));
|
|
570
607
|
});
|
|
571
608
|
return segments.join(" ");
|
|
572
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>>;
|