marmonitor 0.2.3 → 0.2.5
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 +109 -17
- package/README.md +73 -0
- package/dist/alerts/desktop.d.ts +3 -0
- package/dist/alerts/desktop.js +23 -0
- package/dist/alerts/index.d.ts +7 -0
- package/dist/alerts/index.js +5 -0
- package/dist/alerts/log.d.ts +3 -0
- package/dist/alerts/log.js +14 -0
- package/dist/alerts/snapshot.d.ts +4 -0
- package/dist/alerts/snapshot.js +25 -0
- package/dist/alerts/store.d.ts +23 -0
- package/dist/alerts/store.js +61 -0
- package/dist/alerts/token.d.ts +18 -0
- package/dist/alerts/token.js +65 -0
- package/dist/alerts/types.d.ts +23 -0
- package/dist/alerts/types.js +2 -0
- package/dist/cli.js +318 -124
- package/dist/config/index.d.ts +13 -1
- package/dist/config/index.js +7 -0
- package/dist/guard/index.js +51 -5
- package/dist/output/badge-themes.d.ts +3 -0
- package/dist/output/badge-themes.js +26 -0
- package/dist/output/index.d.ts +2 -1
- package/dist/output/index.js +156 -34
- package/dist/output/utils.d.ts +4 -2
- package/dist/output/utils.js +10 -4
- package/dist/scanner/claude.js +174 -90
- package/dist/scanner/codex.js +2 -0
- package/dist/scanner/daemon-entry.js +2 -0
- package/dist/scanner/daemon-loop.d.ts +2 -0
- package/dist/scanner/daemon-loop.js +25 -27
- package/dist/scanner/index.js +14 -0
- package/dist/scanner/process.js +6 -0
- package/dist/tmux/index.d.ts +6 -0
- package/dist/tmux/index.js +28 -0
- package/dist/types.d.ts +3 -0
- package/package.json +3 -1
package/dist/guard/index.js
CHANGED
|
@@ -1,7 +1,45 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
2
|
+
// 시스템 경로 판단 기준: /, /*, /etc, /usr, /var, /home, /root, /bin, /sbin, /sys, /proc, /dev, /boot, /lib, ~
|
|
3
|
+
const SYSTEM_PATH = String.raw `(?:\/(?:$|\*|etc(?:\/|$)|usr(?:\/|$)|var(?:\/|$)|home(?:\/|$)|root(?:\/|$)|bin(?:\/|$)|sbin(?:\/|$)|sys(?:\/|$)|proc(?:\/|$)|dev(?:\/|$)|boot(?:\/|$)|lib(?:\/|$))|~(?:\/|$))`;
|
|
4
|
+
const DANGEROUS_COMMAND_PATTERNS = [
|
|
5
|
+
// ── destructive delete: 시스템 경로 대상 + 재귀/강제 옵션 조합 ──
|
|
6
|
+
// 단축 옵션: rm -rf /, rm -fr /etc, rm -Rrf ~ (-[옵션]에 r과 f 둘 다 포함)
|
|
7
|
+
new RegExp(String.raw `\brm\b(?=.*\s-[^\s-]*[rf][^\s-]*[rf])(?=.*\s${SYSTEM_PATH})`, "i"),
|
|
8
|
+
// 롱 옵션: rm --recursive --force /var (순서 무관)
|
|
9
|
+
new RegExp(String.raw `\brm\b(?=.*--recursive\b)(?=.*--force\b)(?=.*\s${SYSTEM_PATH})`, "i"),
|
|
10
|
+
// ── filesystem format ──
|
|
11
|
+
/\bmkfs(?:\.[a-z0-9]+)?\b/i,
|
|
12
|
+
// ── raw disk write (sudo 유무 무관) ──
|
|
13
|
+
/\bdd\b.*\bof=\/dev\/(?:sd[a-z]\d*|nvme\d+n\d+(?:p\d+)?|vd[a-z]\d*|zero|null)\b/i,
|
|
14
|
+
/\bsudo\s+dd\b/i,
|
|
15
|
+
// ── 시스템 경로 대상 권한/소유권 대규모 변경 ──
|
|
16
|
+
new RegExp(String.raw `\bchmod\b.*\s-[^\s]*R[^\s]*(?=.*\s${SYSTEM_PATH})`, "i"),
|
|
17
|
+
new RegExp(String.raw `\bchown\b.*\s-[^\s]*R[^\s]*(?=.*\s${SYSTEM_PATH})`, "i"),
|
|
18
|
+
// ── git force push ──
|
|
19
|
+
/\bgit\s+push\b.*(?:--force\b|-f\b)/i,
|
|
20
|
+
// ── 원격 스크립트 직접 실행 ──
|
|
21
|
+
/\bcurl\b.+\|\s*(?:bash|sh)\b/i,
|
|
22
|
+
/\bwget\b.+\|\s*(?:bash|sh)\b/i,
|
|
23
|
+
/\b(?:bash|sh)\b\s*<\(\s*curl\b/i, // bash <(curl ...)
|
|
24
|
+
/\bsudo\s+(?:bash|sh)\b.*-c\b.*(?:curl|wget)\b.*\|\s*(?:bash|sh)\b/i, // sudo sh -c '... | bash'
|
|
25
|
+
// ── critical process kill ──
|
|
26
|
+
/\bkill\s+-9\s+1\b/i,
|
|
27
|
+
/\bpkill\s+-9\s+(?:init|systemd)\b/i,
|
|
28
|
+
];
|
|
29
|
+
// secret_access: 정확한 자격증명 파일 경로에만 반응 (content 키워드 false positive 방지)
|
|
30
|
+
// Write/Edit 툴일 때만 체크 → Read는 별도 함수에서 처리
|
|
31
|
+
const SECRET_WRITE_TOOLS = new Set(["Write", "Edit", "str_replace_editor"]);
|
|
32
|
+
const SECRET_EXACT_SUFFIXES = [
|
|
33
|
+
/(?:^|\/)\.env$/, // .env (not .env.example, .env.local)
|
|
34
|
+
/(?:^|\/)id_rsa$/, // SSH private key
|
|
35
|
+
/(?:^|\/)id_ed25519$/, // ED25519 private key
|
|
36
|
+
/(?:^|\/)id_ecdsa$/, // ECDSA private key
|
|
37
|
+
/(?:^|\/)\.netrc$/, // netrc credential file
|
|
38
|
+
/(?:^|\/)credentials$/, // AWS credentials etc
|
|
39
|
+
];
|
|
40
|
+
// Read 툴에서 실제 private key 파일 경로를 읽는 경우
|
|
41
|
+
const SECRET_READ_TOOLS = new Set(["Read", "cat"]);
|
|
42
|
+
const PROD_PATH_PATTERNS = [/\/prod\b/, /\/production\b/];
|
|
5
43
|
function normalizeAction(action) {
|
|
6
44
|
if (action === "block")
|
|
7
45
|
return "block";
|
|
@@ -37,19 +75,27 @@ export function parseHookEvent(input) {
|
|
|
37
75
|
return undefined;
|
|
38
76
|
}
|
|
39
77
|
}
|
|
78
|
+
function isSecretFilePath(filePath) {
|
|
79
|
+
return SECRET_EXACT_SUFFIXES.some((pattern) => pattern.test(filePath));
|
|
80
|
+
}
|
|
40
81
|
export function detectGuardTriggers(event) {
|
|
41
82
|
const triggers = new Set();
|
|
42
83
|
const command = event.command ?? "";
|
|
43
84
|
const filePath = event.filePath ?? "";
|
|
44
85
|
const cwd = event.cwd ?? "";
|
|
86
|
+
const toolName = event.toolName ?? "";
|
|
45
87
|
if (DANGEROUS_COMMAND_PATTERNS.some((pattern) => pattern.test(command))) {
|
|
46
88
|
triggers.add("dangerous_command");
|
|
47
89
|
}
|
|
48
90
|
if (PROD_PATH_PATTERNS.some((pattern) => pattern.test(command) || pattern.test(filePath))) {
|
|
49
91
|
triggers.add("prod_path_access");
|
|
50
92
|
}
|
|
51
|
-
|
|
52
|
-
|
|
93
|
+
// secret_access: Write/Edit 툴 + 정확한 자격증명 파일 경로
|
|
94
|
+
// Read 툴 + 정확한 private key 파일 경로
|
|
95
|
+
if (filePath && isSecretFilePath(filePath)) {
|
|
96
|
+
if (SECRET_WRITE_TOOLS.has(toolName) || SECRET_READ_TOOLS.has(toolName)) {
|
|
97
|
+
triggers.add("secret_access");
|
|
98
|
+
}
|
|
53
99
|
}
|
|
54
100
|
if (filePath && cwd && !filePath.startsWith(cwd)) {
|
|
55
101
|
triggers.add("out_of_cwd_write");
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
export interface BadgeTheme {
|
|
9
9
|
badge: string;
|
|
10
10
|
attention: string;
|
|
11
|
+
/** Attention segment for the currently active tmux window */
|
|
12
|
+
attentionActive: string;
|
|
11
13
|
focus: string;
|
|
12
14
|
empty: string;
|
|
13
15
|
jumpBack: string;
|
|
@@ -15,5 +17,6 @@ export interface BadgeTheme {
|
|
|
15
17
|
export declare const BADGE_THEMES: Record<string, BadgeTheme>;
|
|
16
18
|
export declare function renderBadge(theme: BadgeTheme, label: string, fg: string, bg: string): string;
|
|
17
19
|
export declare function renderAttention(theme: BadgeTheme, index: number, label: string, bg: string): string;
|
|
20
|
+
export declare function renderAttentionActive(theme: BadgeTheme, index: number, label: string, bg: string): string;
|
|
18
21
|
export declare function renderFocus(theme: BadgeTheme, text: string): string;
|
|
19
22
|
export declare function resolveTheme(style: string): BadgeTheme;
|
|
@@ -9,6 +9,7 @@ export const BADGE_THEMES = {
|
|
|
9
9
|
basic: {
|
|
10
10
|
badge: "#[fg={bg},bg=#1e1e2e]#[bold,fg={fg},bg={bg}] {label} #[fg={bg},bg=#1e1e2e]#[default]",
|
|
11
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
|
+
attentionActive: "#[fg={bg},bg=#1e1e2e]#[bold,underscore,fg=#11111b,bg={bg}] {index} #[fg=#45475a,bg={bg}]#[underscore,fg=#cdd6f4,bg=#45475a] {label} #[fg=#45475a,bg=#1e1e2e]#[default]",
|
|
12
13
|
focus: "#[fg=#bac2de,bg=#181825] {text} #[default]",
|
|
13
14
|
empty: "#[fg=#cdd6f4,bg=#313244] no active #[fg=#313244,bg=#1e1e2e]#[default]",
|
|
14
15
|
jumpBack: "#[fg=#45475a,bg=#1e1e2e]#[fg=#bac2de,bg=#45475a] ↩ #[fg=#45475a,bg=#1e1e2e]#[default]",
|
|
@@ -16,13 +17,31 @@ export const BADGE_THEMES = {
|
|
|
16
17
|
"basic-mono": {
|
|
17
18
|
badge: "#[fg=#313244,bg=#1e1e2e]#[bold,fg=#cdd6f4,bg=#313244] {label} #[fg=#313244,bg=#1e1e2e]#[default]",
|
|
18
19
|
attention: "#[fg=#313244,bg=#1e1e2e]#[bold,fg=#cdd6f4,bg=#313244] {index} #[fg=#1e1e2e,bg=#313244]#[fg=#6c7086,bg=#1e1e2e] {label} #[fg=#1e1e2e]#[default]",
|
|
20
|
+
attentionActive: "#[fg=#45475a,bg=#1e1e2e]#[bold,underscore,fg=#cdd6f4,bg=#45475a] {index} #[fg=#1e1e2e,bg=#45475a]#[underscore,fg=#cdd6f4,bg=#1e1e2e] {label} #[fg=#1e1e2e]#[default]",
|
|
19
21
|
focus: "#[fg=#6c7086,bg=#181825] {text} #[default]",
|
|
20
22
|
empty: "#[fg=#313244,bg=#1e1e2e]#[fg=#6c7086,bg=#313244] no active #[fg=#313244,bg=#1e1e2e]#[default]",
|
|
21
23
|
jumpBack: "#[fg=#313244,bg=#1e1e2e]#[fg=#6c7086,bg=#313244] ↩ #[fg=#313244,bg=#1e1e2e]#[default]",
|
|
22
24
|
},
|
|
25
|
+
block: {
|
|
26
|
+
badge: "#[bold,fg={fg},bg={bg}] {label} #[default]",
|
|
27
|
+
attention: "#[bold,fg=#11111b,bg={bg}] {index} #[fg=#cdd6f4,bg=#313244] {label} #[default]",
|
|
28
|
+
attentionActive: "#[bold,underscore,fg=#11111b,bg={bg}] {index} #[underscore,fg=#cdd6f4,bg=#45475a] {label} #[default]",
|
|
29
|
+
focus: "#[fg=#bac2de,bg=#181825] {text} #[default]",
|
|
30
|
+
empty: "#[fg=#cdd6f4,bg=#313244] no active #[default]",
|
|
31
|
+
jumpBack: "#[fg=#bac2de,bg=#45475a] ↩ #[default]",
|
|
32
|
+
},
|
|
33
|
+
"block-mono": {
|
|
34
|
+
badge: "#[bold,fg=#cdd6f4,bg=#313244] {label} #[default]",
|
|
35
|
+
attention: "#[bold,fg=#cdd6f4,bg=#313244] {index} #[fg=#6c7086,bg=#1e1e2e] {label} #[default]",
|
|
36
|
+
attentionActive: "#[bold,underscore,fg=#cdd6f4,bg=#45475a] {index} #[underscore,fg=#cdd6f4,bg=#1e1e2e] {label} #[default]",
|
|
37
|
+
focus: "#[fg=#6c7086,bg=#181825] {text} #[default]",
|
|
38
|
+
empty: "#[fg=#6c7086,bg=#313244] no active #[default]",
|
|
39
|
+
jumpBack: "#[fg=#6c7086,bg=#313244] ↩ #[default]",
|
|
40
|
+
},
|
|
23
41
|
text: {
|
|
24
42
|
badge: "#[fg={bg}]{label}#[default]",
|
|
25
43
|
attention: "#[fg={bg}]{index} {label}#[default]",
|
|
44
|
+
attentionActive: "#[underscore,fg={bg}]{index} {label}#[default]",
|
|
26
45
|
focus: "{text}",
|
|
27
46
|
empty: "no active",
|
|
28
47
|
jumpBack: "#[fg=#89b4fa]↩#[default]",
|
|
@@ -30,6 +49,7 @@ export const BADGE_THEMES = {
|
|
|
30
49
|
"text-mono": {
|
|
31
50
|
badge: "#[fg=#cdd6f4]{label}#[default]",
|
|
32
51
|
attention: "#[bold,fg=#cdd6f4]{index}#[default] #[fg=#6c7086]{label}#[default]",
|
|
52
|
+
attentionActive: "#[bold,underscore,fg=#cdd6f4]{index}#[default] #[underscore,fg=#6c7086]{label}#[default]",
|
|
33
53
|
focus: "#[fg=#6c7086]{text}#[default]",
|
|
34
54
|
empty: "#[fg=#6c7086]no active#[default]",
|
|
35
55
|
jumpBack: "#[fg=#6c7086]↩#[default]",
|
|
@@ -44,6 +64,12 @@ export function renderAttention(theme, index, label, bg) {
|
|
|
44
64
|
.replaceAll("{label}", label)
|
|
45
65
|
.replaceAll("{bg}", bg);
|
|
46
66
|
}
|
|
67
|
+
export function renderAttentionActive(theme, index, label, bg) {
|
|
68
|
+
return theme.attentionActive
|
|
69
|
+
.replaceAll("{index}", String(index))
|
|
70
|
+
.replaceAll("{label}", label)
|
|
71
|
+
.replaceAll("{bg}", bg);
|
|
72
|
+
}
|
|
47
73
|
export function renderFocus(theme, text) {
|
|
48
74
|
return theme.focus.replaceAll("{text}", text);
|
|
49
75
|
}
|
package/dist/output/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { type BadgeStyle, type StatuslineFormat } from "./utils.js";
|
|
|
5
5
|
export declare function getSystemInfo(): Promise<SystemInfo>;
|
|
6
6
|
/** Apply badge style to terminal chalk output: mono uses bold/dim only */
|
|
7
7
|
export declare function applyTerminalStyle(badgeStyle: BadgeStyle): void;
|
|
8
|
+
export declare function abbreviateModel(model: string | undefined): string;
|
|
8
9
|
/** Print agent status as formatted text */
|
|
9
10
|
export declare function printStatus(agents: AgentSession[]): Promise<void>;
|
|
10
11
|
/** Print agent status as JSON */
|
|
@@ -26,6 +27,6 @@ export declare function printDock(agents: AgentSession[], maxLines?: number): Pr
|
|
|
26
27
|
/** Print one-line summary for tmux/terminal status bar */
|
|
27
28
|
export declare function renderUnavailableStatusline(format?: StatuslineFormat): string;
|
|
28
29
|
/** Print one-line summary for tmux/terminal status bar */
|
|
29
|
-
export declare function renderStatusline(agents: AgentSession[], format?: StatuslineFormat, attentionLimit?: number, width?: number, badgeStyle?: BadgeStyle, hasJumpAnchor?: boolean): Promise<string>;
|
|
30
|
+
export declare function renderStatusline(agents: AgentSession[], format?: StatuslineFormat, attentionLimit?: number, width?: number, badgeStyle?: BadgeStyle, hasJumpAnchor?: boolean, activeAgentPid?: number): Promise<string>;
|
|
30
31
|
/** Print one-line summary for tmux/terminal status bar */
|
|
31
32
|
export declare function printStatusline(agents: AgentSession[], format?: StatuslineFormat, attentionLimit?: number, width?: number): Promise<void>;
|
package/dist/output/index.js
CHANGED
|
@@ -19,7 +19,59 @@ export async function getSystemInfo() {
|
|
|
19
19
|
let monoMode = false;
|
|
20
20
|
/** Apply badge style to terminal chalk output: mono uses bold/dim only */
|
|
21
21
|
export function applyTerminalStyle(badgeStyle) {
|
|
22
|
-
monoMode =
|
|
22
|
+
monoMode =
|
|
23
|
+
badgeStyle === "basic-mono" || badgeStyle === "block-mono" || badgeStyle === "text-mono";
|
|
24
|
+
}
|
|
25
|
+
export function abbreviateModel(model) {
|
|
26
|
+
if (!model)
|
|
27
|
+
return "—";
|
|
28
|
+
if (model.includes("opus"))
|
|
29
|
+
return "opus";
|
|
30
|
+
if (model.includes("sonnet"))
|
|
31
|
+
return "sonnet";
|
|
32
|
+
if (model.includes("haiku"))
|
|
33
|
+
return "haiku";
|
|
34
|
+
if (model.length <= 12)
|
|
35
|
+
return model;
|
|
36
|
+
return model.slice(0, 11);
|
|
37
|
+
}
|
|
38
|
+
function cwdToProjectName(cwd) {
|
|
39
|
+
const home = process.env.HOME ?? "";
|
|
40
|
+
const short = cwd.startsWith(home) ? cwd.slice(home.length + 1) : cwd;
|
|
41
|
+
const parts = short.split("/");
|
|
42
|
+
return parts[parts.length - 1] || short;
|
|
43
|
+
}
|
|
44
|
+
/** Strip ANSI escape codes to get visible character count */
|
|
45
|
+
function visibleLength(str) {
|
|
46
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: ANSI escape stripping
|
|
47
|
+
return str.replace(/\x1b\[\d*(;\d+)*m/g, "").length;
|
|
48
|
+
}
|
|
49
|
+
/** Pad string to fixed visible width (ANSI-aware) */
|
|
50
|
+
function padVisible(str, width) {
|
|
51
|
+
const visible = visibleLength(str);
|
|
52
|
+
return visible >= width ? str : str + " ".repeat(width - visible);
|
|
53
|
+
}
|
|
54
|
+
/** Right-align a string to fixed width (for numbers like CPU, MEM) */
|
|
55
|
+
function padVisibleRight(str, width) {
|
|
56
|
+
const visible = visibleLength(str);
|
|
57
|
+
return visible >= width ? str : " ".repeat(width - visible) + str;
|
|
58
|
+
}
|
|
59
|
+
function formatTokensCompact(n) {
|
|
60
|
+
if (n >= 1_000_000)
|
|
61
|
+
return `${(n / 1_000_000).toFixed(1)}M`;
|
|
62
|
+
if (n >= 1_000)
|
|
63
|
+
return `${(n / 1_000).toFixed(1)}K`;
|
|
64
|
+
return String(n);
|
|
65
|
+
}
|
|
66
|
+
function formatElapsedCompactTable(epochSec) {
|
|
67
|
+
const sec = Math.floor(Date.now() / 1000 - epochSec);
|
|
68
|
+
if (sec < 60)
|
|
69
|
+
return `${sec}s`;
|
|
70
|
+
if (sec < 3600)
|
|
71
|
+
return `${Math.floor(sec / 60)}m`;
|
|
72
|
+
if (sec < 86400)
|
|
73
|
+
return `${Math.floor(sec / 3600)}h`;
|
|
74
|
+
return `${Math.floor(sec / 86400)}d`;
|
|
23
75
|
}
|
|
24
76
|
/** Agent name with distinct color */
|
|
25
77
|
function agentLabel(name) {
|
|
@@ -141,29 +193,95 @@ export async function printStatus(agents) {
|
|
|
141
193
|
return;
|
|
142
194
|
}
|
|
143
195
|
if (alive.length > 0) {
|
|
144
|
-
console.log(`AI Sessions (${alive.length} active)
|
|
196
|
+
console.log(`AI Sessions (${alive.length} active):\n`);
|
|
197
|
+
// Column widths — fixed-width columns first, variable-width last
|
|
198
|
+
const W = {
|
|
199
|
+
status: 10,
|
|
200
|
+
agent: 7,
|
|
201
|
+
model: 12,
|
|
202
|
+
pid: 6,
|
|
203
|
+
cpu: 6,
|
|
204
|
+
mem: 7,
|
|
205
|
+
last: 6,
|
|
206
|
+
tokens: 10,
|
|
207
|
+
project: 22,
|
|
208
|
+
branch: 16,
|
|
209
|
+
};
|
|
210
|
+
// Table header
|
|
211
|
+
const cols = [
|
|
212
|
+
"Status".padEnd(W.status),
|
|
213
|
+
"Agent".padEnd(W.agent),
|
|
214
|
+
"Model".padEnd(W.model),
|
|
215
|
+
"PID".padEnd(W.pid),
|
|
216
|
+
"CPU".padEnd(W.cpu),
|
|
217
|
+
"MEM".padEnd(W.mem),
|
|
218
|
+
"Last".padEnd(W.last),
|
|
219
|
+
"Tokens".padEnd(W.tokens),
|
|
220
|
+
"Project".padEnd(W.project),
|
|
221
|
+
"Branch",
|
|
222
|
+
];
|
|
223
|
+
console.log(` ${chalk.dim(cols.join(" "))}`);
|
|
224
|
+
console.log(chalk.dim(` ${"─".repeat(cols.join(" ").length)}`));
|
|
145
225
|
for (const a of alive) {
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
226
|
+
// Fixed-width status: colorize label only, pad with plain spaces after
|
|
227
|
+
const statusWord = a.phase === "permission"
|
|
228
|
+
? "Allow"
|
|
229
|
+
: a.phase === "thinking"
|
|
230
|
+
? "Think"
|
|
231
|
+
: a.phase === "tool"
|
|
232
|
+
? "Tool"
|
|
233
|
+
: a.status;
|
|
234
|
+
const statusLabel2 = `[${statusWord}]`;
|
|
235
|
+
const coloredLabel = statusWord === "Active"
|
|
236
|
+
? chalk.green(statusLabel2)
|
|
237
|
+
: statusWord === "Idle"
|
|
238
|
+
? chalk.yellow(statusLabel2)
|
|
239
|
+
: statusWord === "Stalled"
|
|
240
|
+
? chalk.red(statusLabel2)
|
|
241
|
+
: statusWord === "Allow"
|
|
242
|
+
? chalk.red(statusLabel2)
|
|
243
|
+
: statusWord === "Think"
|
|
244
|
+
? chalk.magenta(statusLabel2)
|
|
245
|
+
: statusWord === "Tool"
|
|
246
|
+
? chalk.green(statusLabel2)
|
|
247
|
+
: chalk.white(statusLabel2);
|
|
248
|
+
const rawStatus = coloredLabel + " ".repeat(Math.max(0, W.status - statusLabel2.length));
|
|
249
|
+
const agentStr = a.agentName === "Claude Code" ? "Claude" : a.agentName;
|
|
250
|
+
const modelStr = abbreviateModel(a.model);
|
|
251
|
+
const cpu = `${a.cpuPercent}%`;
|
|
252
|
+
const mem = `${a.memoryMb.toFixed(0)}MB`;
|
|
253
|
+
const last = a.lastResponseAt
|
|
254
|
+
? formatElapsedCompactTable(a.lastResponseAt)
|
|
155
255
|
: a.lastActivityAt
|
|
156
|
-
?
|
|
157
|
-
: "";
|
|
158
|
-
|
|
159
|
-
|
|
256
|
+
? formatElapsedCompactTable(a.lastActivityAt)
|
|
257
|
+
: "—";
|
|
258
|
+
const tokens = a.tokenUsage ? `out:${formatTokensCompact(a.tokenUsage.outputTokens)}` : "";
|
|
259
|
+
const project = cwdToProjectName(a.cwd).slice(0, W.project - 1);
|
|
260
|
+
const branchStr = (a.branch ?? "—").slice(0, W.branch - 1);
|
|
261
|
+
const line = [
|
|
262
|
+
rawStatus,
|
|
263
|
+
padVisible(agentStr, W.agent),
|
|
264
|
+
chalk.dim(modelStr.padEnd(W.model)),
|
|
265
|
+
String(a.pid).padEnd(W.pid),
|
|
266
|
+
padVisibleRight(cpu, W.cpu),
|
|
267
|
+
padVisibleRight(mem, W.mem),
|
|
268
|
+
chalk.dim(last.padStart(W.last)),
|
|
269
|
+
chalk.dim(tokens.padEnd(W.tokens)),
|
|
270
|
+
project.padEnd(W.project),
|
|
271
|
+
chalk.dim(branchStr),
|
|
272
|
+
].join(" ");
|
|
273
|
+
console.log(` ${line}`);
|
|
160
274
|
if (a.workers && a.workers.length > 0) {
|
|
161
|
-
for (
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
275
|
+
for (const w of a.workers) {
|
|
276
|
+
const wLine = [
|
|
277
|
+
" ".repeat(W.status),
|
|
278
|
+
"└─".padEnd(W.agent),
|
|
279
|
+
" ".repeat(W.model),
|
|
280
|
+
String(w.pid).padEnd(W.pid),
|
|
281
|
+
padVisibleRight(`${w.cpuPercent}%`, W.cpu),
|
|
282
|
+
padVisibleRight(`${w.memoryMb.toFixed(0)}MB`, W.mem),
|
|
283
|
+
].join(" ");
|
|
284
|
+
console.log(chalk.dim(` ${wLine}`));
|
|
167
285
|
}
|
|
168
286
|
}
|
|
169
287
|
}
|
|
@@ -237,6 +355,8 @@ function attentionKindLabel(kind) {
|
|
|
237
355
|
function attentionLine(item) {
|
|
238
356
|
const name = item.agentName === "Claude Code" ? "Claude" : item.agentName;
|
|
239
357
|
const path = compactDirLabel(item.cwd);
|
|
358
|
+
const branch = item.branch;
|
|
359
|
+
const branchTag = branch ? chalk.dim(` (${branch})`) : "";
|
|
240
360
|
const runtime = runtimeLabel(item.runtimeSource);
|
|
241
361
|
const time = item.lastResponseAt
|
|
242
362
|
? ` ${chalk.dim(formatElapsed(item.lastResponseAt))}`
|
|
@@ -244,21 +364,21 @@ function attentionLine(item) {
|
|
|
244
364
|
? ` ${chalk.dim(formatElapsed(item.lastActivityAt))}`
|
|
245
365
|
: "";
|
|
246
366
|
if (item.kind === "unmatched") {
|
|
247
|
-
return `${name} ${chalk.dim(path)}${runtime} PID:${item.pid}${time}`;
|
|
367
|
+
return `${name} ${chalk.dim(path)}${branchTag}${runtime} PID:${item.pid}${time}`;
|
|
248
368
|
}
|
|
249
369
|
if (item.kind === "permission") {
|
|
250
|
-
return `${name} ${chalk.dim(path)}${runtime} allow pending PID:${item.pid}${time}`;
|
|
370
|
+
return `${name} ${chalk.dim(path)}${branchTag}${runtime} allow pending PID:${item.pid}${time}`;
|
|
251
371
|
}
|
|
252
372
|
if (item.kind === "stalled") {
|
|
253
|
-
return `${name} ${chalk.dim(path)}${runtime} stalled PID:${item.pid}${time}`;
|
|
373
|
+
return `${name} ${chalk.dim(path)}${branchTag}${runtime} stalled PID:${item.pid}${time}`;
|
|
254
374
|
}
|
|
255
375
|
if (item.kind === "thinking") {
|
|
256
|
-
return `${name} ${chalk.dim(path)}${runtime} thinking PID:${item.pid}${time}`;
|
|
376
|
+
return `${name} ${chalk.dim(path)}${branchTag}${runtime} thinking PID:${item.pid}${time}`;
|
|
257
377
|
}
|
|
258
378
|
if (item.kind === "active") {
|
|
259
|
-
return `${name} ${chalk.dim(path)}${runtime}
|
|
379
|
+
return `${name} ${chalk.dim(path)}${branchTag}${runtime} active PID:${item.pid}${time}`;
|
|
260
380
|
}
|
|
261
|
-
return `${name} ${chalk.dim(path)}${runtime} tool PID:${item.pid}${time}`;
|
|
381
|
+
return `${name} ${chalk.dim(path)}${branchTag}${runtime} tool PID:${item.pid}${time}`;
|
|
262
382
|
}
|
|
263
383
|
function jumpAttentionStatusLabel(item) {
|
|
264
384
|
if (item.kind === "permission")
|
|
@@ -267,7 +387,7 @@ function jumpAttentionStatusLabel(item) {
|
|
|
267
387
|
return chalk.green("[Thinking]");
|
|
268
388
|
if (item.kind === "tool")
|
|
269
389
|
return chalk.cyan("[Tool] ");
|
|
270
|
-
return chalk.blue("[
|
|
390
|
+
return chalk.blue("[Active] ");
|
|
271
391
|
}
|
|
272
392
|
function jumpAttentionPhaseIcon(item) {
|
|
273
393
|
if (item.kind === "permission")
|
|
@@ -281,6 +401,8 @@ function jumpAttentionPhaseIcon(item) {
|
|
|
281
401
|
function jumpAttentionLine(item) {
|
|
282
402
|
const name = item.agentName === "Claude Code" ? "Claude" : item.agentName;
|
|
283
403
|
const path = compactDirLabel(item.cwd);
|
|
404
|
+
const branch = item.branch;
|
|
405
|
+
const branchTag = branch ? chalk.dim(` (${branch})`) : "";
|
|
284
406
|
const runtime = runtimeLabel(item.runtimeSource);
|
|
285
407
|
const started = item.startedAt ? chalk.dim(` started ${formatElapsed(item.startedAt)}`) : "";
|
|
286
408
|
const activity = item.lastResponseAt
|
|
@@ -293,15 +415,15 @@ function jumpAttentionLine(item) {
|
|
|
293
415
|
const icon = jumpAttentionPhaseIcon(item);
|
|
294
416
|
const agent = agentLabel(item.agentName).padEnd(8);
|
|
295
417
|
if (item.kind === "permission") {
|
|
296
|
-
return ` ${status} ${agent} ${chalk.dim(path)}${runtime}${icon}\n PID:${item.pid} ${stats}${started}${activity}`;
|
|
418
|
+
return ` ${status} ${agent} ${chalk.dim(path)}${branchTag}${runtime}${icon}\n PID:${item.pid} ${stats}${started}${activity}`;
|
|
297
419
|
}
|
|
298
420
|
if (item.kind === "thinking") {
|
|
299
|
-
return ` ${status} ${agent} ${chalk.dim(path)}${runtime}${icon}\n PID:${item.pid} ${stats}${started}${activity}`;
|
|
421
|
+
return ` ${status} ${agent} ${chalk.dim(path)}${branchTag}${runtime}${icon}\n PID:${item.pid} ${stats}${started}${activity}`;
|
|
300
422
|
}
|
|
301
423
|
if (item.kind === "tool") {
|
|
302
|
-
return ` ${status} ${agent} ${chalk.dim(path)}${runtime}${icon}\n PID:${item.pid} ${stats}${started}${activity}`;
|
|
424
|
+
return ` ${status} ${agent} ${chalk.dim(path)}${branchTag}${runtime}${icon}\n PID:${item.pid} ${stats}${started}${activity}`;
|
|
303
425
|
}
|
|
304
|
-
return ` ${status} ${agent} ${chalk.dim(path)}${runtime}${icon}\n PID:${item.pid} ${stats}${started}${activity}`;
|
|
426
|
+
return ` ${status} ${agent} ${chalk.dim(path)}${branchTag}${runtime}${icon}\n PID:${item.pid} ${stats}${started}${activity}`;
|
|
305
427
|
}
|
|
306
428
|
function paginateJumpAttentionItems(items, page, pageSize = 10) {
|
|
307
429
|
const normalizedPage = Number.isInteger(page) && page > 0 ? page : 1;
|
|
@@ -456,7 +578,7 @@ export function renderUnavailableStatusline(format = "compact") {
|
|
|
456
578
|
return "marmonitor unavailable";
|
|
457
579
|
}
|
|
458
580
|
/** Print one-line summary for tmux/terminal status bar */
|
|
459
|
-
export async function renderStatusline(agents, format = "compact", attentionLimit = 5, width, badgeStyle = "basic", hasJumpAnchor = false) {
|
|
581
|
+
export async function renderStatusline(agents, format = "compact", attentionLimit = 5, width, badgeStyle = "basic", hasJumpAnchor = false, activeAgentPid) {
|
|
460
582
|
const alive = agents.filter((a) => a.status !== "Dead" && a.status !== "Unmatched");
|
|
461
583
|
const unmatched = agents.filter((a) => a.status === "Unmatched");
|
|
462
584
|
if (alive.length === 0) {
|
|
@@ -489,7 +611,7 @@ export async function renderStatusline(agents, format = "compact", attentionLimi
|
|
|
489
611
|
memoryUsedGb: sys.memoryUsedGb,
|
|
490
612
|
};
|
|
491
613
|
if (format === "tmux-badges") {
|
|
492
|
-
const focusText = buildTmuxAttentionPills(buildJumpAttentionItems(agents), attentionLimit, width, badgeStyle);
|
|
614
|
+
const focusText = buildTmuxAttentionPills(buildJumpAttentionItems(agents), attentionLimit, width, badgeStyle, activeAgentPid);
|
|
493
615
|
return buildTmuxBadgeBar(snapshot, focusText, badgeStyle, hasJumpAnchor);
|
|
494
616
|
}
|
|
495
617
|
if (format === "wezterm-pills") {
|
package/dist/output/utils.d.ts
CHANGED
|
@@ -73,6 +73,7 @@ export interface AttentionItem {
|
|
|
73
73
|
phase?: AgentSession["phase"];
|
|
74
74
|
lastResponseAt?: number;
|
|
75
75
|
lastActivityAt?: number;
|
|
76
|
+
branch?: string;
|
|
76
77
|
}
|
|
77
78
|
export interface StatusPill {
|
|
78
79
|
label: string;
|
|
@@ -102,6 +103,7 @@ export interface SessionRegistryEntry {
|
|
|
102
103
|
startedAt?: number;
|
|
103
104
|
model?: string;
|
|
104
105
|
source: "claude" | "codex";
|
|
106
|
+
binding: "direct" | "provisional";
|
|
105
107
|
}
|
|
106
108
|
export interface SessionFileCandidate {
|
|
107
109
|
path: string;
|
|
@@ -146,7 +148,7 @@ export declare function buildStatusPills(snapshot: StatuslineSnapshot): {
|
|
|
146
148
|
};
|
|
147
149
|
/** Build one-line persistent-bar summary string. */
|
|
148
150
|
export declare function buildStatuslineSummary(snapshot: StatuslineSnapshot, format?: StatuslineFormat): string;
|
|
149
|
-
export type BadgeStyle = "basic" | "basic-mono" | "text" | "text-mono";
|
|
151
|
+
export type BadgeStyle = "basic" | "basic-mono" | "block" | "block-mono" | "text" | "text-mono";
|
|
150
152
|
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;
|
|
153
|
+
export declare function buildTmuxAttentionPills(items: AttentionItem[], maxCount?: number, width?: number, badgeStyle?: BadgeStyle, activeAgentPid?: number): string | undefined;
|
|
152
154
|
export declare function serializeWeztermPills(snapshot: StatuslineSnapshot, focusText?: string): string;
|
package/dist/output/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { renderAttention, renderBadge, renderFocus, resolveTheme } from "./badge-themes.js";
|
|
1
|
+
import { renderAttention, renderAttentionActive, renderBadge, renderFocus, resolveTheme, } from "./badge-themes.js";
|
|
2
2
|
/**
|
|
3
3
|
* Pure utility functions for marmonitor.
|
|
4
4
|
* Extracted for testability — no side effects, no I/O.
|
|
@@ -257,7 +257,10 @@ export function resolveSessionRegistryPath(registry, sessionId) {
|
|
|
257
257
|
return registry.get(sessionId)?.filePath;
|
|
258
258
|
}
|
|
259
259
|
export function upsertSessionRegistryEntry(registry, entry) {
|
|
260
|
-
registry.set(entry.sessionId,
|
|
260
|
+
registry.set(entry.sessionId, {
|
|
261
|
+
...entry,
|
|
262
|
+
binding: entry.binding ?? "provisional",
|
|
263
|
+
});
|
|
261
264
|
}
|
|
262
265
|
export function selectRecentSessionFile(candidates, nowMs = Date.now(), maxAgeMs = 72 * 60 * 60 * 1000, minLeadMs = 5 * 60 * 1000) {
|
|
263
266
|
if (candidates.length === 0)
|
|
@@ -342,6 +345,7 @@ export function buildAttentionItems(agents, nowSec = Date.now() / 1000) {
|
|
|
342
345
|
phase: agent.phase,
|
|
343
346
|
lastResponseAt: agent.lastResponseAt,
|
|
344
347
|
lastActivityAt: agent.lastActivityAt,
|
|
348
|
+
branch: agent.branch,
|
|
345
349
|
});
|
|
346
350
|
const tier1 = alive
|
|
347
351
|
.filter((agent) => attentionPriority(agent, nowSec) !== undefined)
|
|
@@ -582,7 +586,7 @@ export function buildTmuxBadgeBar(snapshot, focusText, badgeStyle = "basic", has
|
|
|
582
586
|
const focus = focusText ? renderFocus(theme, focusText) : "";
|
|
583
587
|
return [agentPills.join(" "), alertPills.join(" "), jumpBack, focus].filter(Boolean).join(" ");
|
|
584
588
|
}
|
|
585
|
-
export function buildTmuxAttentionPills(items, maxCount = 5, width, badgeStyle = "basic") {
|
|
589
|
+
export function buildTmuxAttentionPills(items, maxCount = 5, width, badgeStyle = "basic", activeAgentPid) {
|
|
586
590
|
if (maxCount <= 0)
|
|
587
591
|
return undefined;
|
|
588
592
|
const layout = resolveStatuslineDetailLayout(width, maxCount);
|
|
@@ -614,7 +618,9 @@ export function buildTmuxAttentionPills(items, maxCount = 5, width, badgeStyle =
|
|
|
614
618
|
: time
|
|
615
619
|
? `⚠${agent} ${path} ${time}`
|
|
616
620
|
: `⚠${agent} ${path}`;
|
|
617
|
-
|
|
621
|
+
const isActive = activeAgentPid !== undefined && item.pid === activeAgentPid;
|
|
622
|
+
const render = isActive ? renderAttentionActive : renderAttention;
|
|
623
|
+
return tmuxUserRange(`pid:${item.pid}`, render(theme, index + 1, label, attentionBg(item.kind)));
|
|
618
624
|
});
|
|
619
625
|
return segments.join(" ");
|
|
620
626
|
}
|