marmonitor 0.2.4 → 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 +49 -0
- package/README.md +71 -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 +189 -21
- package/dist/config/index.d.ts +12 -0
- 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 +12 -0
- package/dist/output/index.d.ts +1 -1
- package/dist/output/index.js +2 -2
- package/dist/output/utils.d.ts +2 -1
- package/dist/output/utils.js +9 -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 +21 -1
- package/dist/tmux/index.d.ts +6 -0
- package/dist/tmux/index.js +28 -0
- package/dist/types.d.ts +2 -0
- package/package.json +3 -1
package/dist/cli.js
CHANGED
|
@@ -4,18 +4,18 @@ import { dirname, join } from "node:path";
|
|
|
4
4
|
import { Command } from "commander";
|
|
5
5
|
import { renderInstallBanner, renderRuntimeBanner } from "./banner/index.js";
|
|
6
6
|
import { getConfigDir, getConfigSearchPaths, getDefaultConfigPath, loadConfig, resolveConfigPath as resolveLoadedConfigPath, } from "./config/index.js";
|
|
7
|
-
import { evaluateGuard, formatGuardOutput, parseHookEvent, readStdin } from "./guard/index.js";
|
|
7
|
+
import { detectGuardTriggers, evaluateGuard, formatGuardOutput, parseHookEvent, readStdin, } from "./guard/index.js";
|
|
8
8
|
import { applyTerminalStyle, printAttention, printAttentionJson, printCleanJson, printCleanPlan, printDock, printJumpJson, printJumpResult, printStatus, printStatusJson, renderJumpAttentionChooser, renderStatusline, renderUnavailableStatusline, } from "./output/index.js";
|
|
9
9
|
import { buildJumpAttentionItems, parseSelectionInput, selectJumpAttentionItem, selectJumpAttentionItemOnPage, selectUnmatchedTargets, } from "./output/utils.js";
|
|
10
10
|
import { TERMINAL_RESTORE_SEQUENCE, formatProcessFailure } from "./process-safety.js";
|
|
11
11
|
import { detectClaudePhase } from "./scanner/claude.js";
|
|
12
12
|
import { detectCodexPhase, indexCodexSessions, matchCodexSession } from "./scanner/codex.js";
|
|
13
|
-
import {
|
|
13
|
+
import { readDaemonSnapshot } from "./scanner/daemon-utils.js";
|
|
14
14
|
import { parseGeminiSession } from "./scanner/gemini.js";
|
|
15
15
|
import { scanAgents } from "./scanner/index.js";
|
|
16
16
|
import { loadRegistryFromFile } from "./scanner/session-registry.js";
|
|
17
17
|
import { detectCliStdoutPhase } from "./scanner/status.js";
|
|
18
|
-
import { captureTmuxPaneOutput, jumpToAgent, resolveTmuxJumpTarget } from "./tmux/index.js";
|
|
18
|
+
import { captureTmuxPaneOutput, findActiveAgentPid, jumpToAgent, resolveTmuxJumpTarget, } from "./tmux/index.js";
|
|
19
19
|
import { getClientTty, jumpBack } from "./tmux/jump-anchor.js";
|
|
20
20
|
import { findClickedAgent, parseStatusClickToken } from "./tmux/status-click.js";
|
|
21
21
|
import { VERSION } from "./version.js";
|
|
@@ -415,23 +415,36 @@ function statuslineCacheFile(format, attentionLimit, width) {
|
|
|
415
415
|
const widthKey = width && width > 0 ? String(width) : "auto";
|
|
416
416
|
return join(tmpdir(), "marmonitor", `statusline-${format}-${attentionLimit}-${widthKey}.txt`);
|
|
417
417
|
}
|
|
418
|
+
/** Read cached statusline. When activePanePid is provided, the cache is
|
|
419
|
+
* only valid if the stored panePid (first line) matches — otherwise the
|
|
420
|
+
* active-window highlight would be stale. Returns {content, panePid}. */
|
|
418
421
|
async function readCachedStatusline(format, attentionLimit, width, ttlMs) {
|
|
419
422
|
const path = statuslineCacheFile(format, attentionLimit, width);
|
|
420
423
|
try {
|
|
421
424
|
const fileStat = await stat(path);
|
|
422
425
|
if (Date.now() - fileStat.mtimeMs > ttlMs)
|
|
423
426
|
return undefined;
|
|
424
|
-
|
|
427
|
+
const raw = (await readFile(path, "utf-8")).trimEnd();
|
|
428
|
+
const newline = raw.indexOf("\n");
|
|
429
|
+
if (newline === -1)
|
|
430
|
+
return { content: raw, panePid: undefined };
|
|
431
|
+
const firstLine = raw.slice(0, newline);
|
|
432
|
+
const pid = Number.parseInt(firstLine, 10);
|
|
433
|
+
if (Number.isFinite(pid)) {
|
|
434
|
+
return { content: raw.slice(newline + 1), panePid: pid };
|
|
435
|
+
}
|
|
436
|
+
return { content: raw, panePid: undefined };
|
|
425
437
|
}
|
|
426
438
|
catch {
|
|
427
439
|
return undefined;
|
|
428
440
|
}
|
|
429
441
|
}
|
|
430
|
-
async function writeCachedStatusline(format, attentionLimit, width, value) {
|
|
442
|
+
async function writeCachedStatusline(format, attentionLimit, width, value, activePanePid) {
|
|
431
443
|
const path = statuslineCacheFile(format, attentionLimit, width);
|
|
444
|
+
const data = activePanePid ? `${activePanePid}\n${value}` : value;
|
|
432
445
|
try {
|
|
433
446
|
await mkdir(join(tmpdir(), "marmonitor"), { recursive: true });
|
|
434
|
-
await writeFile(path,
|
|
447
|
+
await writeFile(path, data, "utf-8");
|
|
435
448
|
}
|
|
436
449
|
catch {
|
|
437
450
|
// cache failures must never break statusline rendering
|
|
@@ -477,29 +490,52 @@ program
|
|
|
477
490
|
}
|
|
478
491
|
const attentionLimit = config.display.statuslineAttentionLimit;
|
|
479
492
|
const width = resolveStatuslineWidth(opts.width);
|
|
493
|
+
const isTmuxBadges = opts.statuslineFormat === "tmux-badges";
|
|
494
|
+
// Try cache first. For tmux-badges the cached panePid is checked
|
|
495
|
+
// against the live pane only on cache hit — the tmux call is
|
|
496
|
+
// deferred so cache-miss paths pay for it just once.
|
|
480
497
|
const cached = await readCachedStatusline(opts.statuslineFormat, attentionLimit, width, config.performance.statuslineTtlMs);
|
|
481
498
|
if (cached) {
|
|
482
|
-
|
|
483
|
-
|
|
499
|
+
if (isTmuxBadges && cached.panePid !== undefined) {
|
|
500
|
+
const { getActiveTmuxPanePid } = await import("./tmux/index.js");
|
|
501
|
+
const currentPanePid = await getActiveTmuxPanePid();
|
|
502
|
+
if (currentPanePid !== cached.panePid) {
|
|
503
|
+
// Active pane changed — fall through to re-render
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
console.log(cached.content);
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
console.log(cached.content);
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
484
514
|
}
|
|
485
515
|
const agents = await getAgentsSnapshot();
|
|
486
516
|
if (agents.length === 0) {
|
|
487
517
|
console.log(renderUnavailableStatusline(opts.statuslineFormat));
|
|
488
518
|
return;
|
|
489
519
|
}
|
|
490
|
-
// Check jump-back anchor for
|
|
520
|
+
// Check jump-back anchor and resolve active agent for tmux-badges
|
|
491
521
|
let hasJumpAnchor = false;
|
|
492
|
-
|
|
522
|
+
let activeAgentPid;
|
|
523
|
+
let activePanePid;
|
|
524
|
+
if (isTmuxBadges) {
|
|
493
525
|
const { tmpdir: td } = await import("node:os");
|
|
494
526
|
const { join: pj } = await import("node:path");
|
|
495
527
|
const { loadJumpAnchor } = await import("./tmux/jump-anchor.js");
|
|
496
|
-
const
|
|
528
|
+
const { getActiveTmuxPanePid } = await import("./tmux/index.js");
|
|
529
|
+
const agentPids = agents.map((a) => a.pid);
|
|
530
|
+
const [tty, panePid] = await Promise.all([getClientTty(), getActiveTmuxPanePid()]);
|
|
531
|
+
activePanePid = panePid;
|
|
532
|
+
activeAgentPid = await findActiveAgentPid(agentPids, activePanePid);
|
|
497
533
|
if (tty) {
|
|
498
534
|
hasJumpAnchor = Boolean(await loadJumpAnchor(pj(td(), "marmonitor", "jump-anchors.json"), tty));
|
|
499
535
|
}
|
|
500
536
|
}
|
|
501
|
-
const rendered = await renderStatusline(agents, opts.statuslineFormat, attentionLimit, width, config.integration.tmux.badgeStyle, hasJumpAnchor);
|
|
502
|
-
await writeCachedStatusline(opts.statuslineFormat, attentionLimit, width, rendered);
|
|
537
|
+
const rendered = await renderStatusline(agents, opts.statuslineFormat, attentionLimit, width, config.integration.tmux.badgeStyle, hasJumpAnchor, activeAgentPid);
|
|
538
|
+
await writeCachedStatusline(opts.statuslineFormat, attentionLimit, width, rendered, activePanePid);
|
|
503
539
|
console.log(rendered);
|
|
504
540
|
return;
|
|
505
541
|
}
|
|
@@ -690,12 +726,105 @@ program
|
|
|
690
726
|
return;
|
|
691
727
|
}
|
|
692
728
|
const result = evaluateGuard(config, event);
|
|
729
|
+
// Security alert: alerts.enabled 확인 후 dangerous_command / secret_access 감지·기록
|
|
730
|
+
const securityTriggers = config.alerts.enabled
|
|
731
|
+
? detectGuardTriggers(event).filter((t) => t === "dangerous_command" || t === "secret_access")
|
|
732
|
+
: [];
|
|
733
|
+
if (securityTriggers.length > 0) {
|
|
734
|
+
const { appendAlertLog } = await import("./alerts/index.js");
|
|
735
|
+
const { getConfigDir } = await import("./config/index.js");
|
|
736
|
+
const { join } = await import("node:path");
|
|
737
|
+
const alertsLogPath = join(getConfigDir(), "alerts.log");
|
|
738
|
+
const { sendDesktopNotification } = await import("./alerts/index.js");
|
|
739
|
+
const agentPid = typeof process.ppid === "number" ? process.ppid : 0;
|
|
740
|
+
for (const trigger of securityTriggers) {
|
|
741
|
+
const message = trigger === "secret_access"
|
|
742
|
+
? `Credential file access: ${event.filePath ?? "(unknown)"}`
|
|
743
|
+
: `Dangerous command detected: ${event.command ?? "(unknown)"}`;
|
|
744
|
+
const alert = {
|
|
745
|
+
id: `security:${agentPid}:${Math.floor(Date.now() / 300_000)}`,
|
|
746
|
+
type: "security",
|
|
747
|
+
severity: "critical",
|
|
748
|
+
agentPid,
|
|
749
|
+
cwd: event.cwd,
|
|
750
|
+
message,
|
|
751
|
+
detail: `tool=${event.toolName ?? "?"} trigger=${trigger}`,
|
|
752
|
+
createdAt: Date.now(),
|
|
753
|
+
};
|
|
754
|
+
if (config.alerts.log)
|
|
755
|
+
await appendAlertLog(alertsLogPath, alert);
|
|
756
|
+
if (config.alerts.desktop)
|
|
757
|
+
void sendDesktopNotification(alert); // fire-and-forget
|
|
758
|
+
}
|
|
759
|
+
}
|
|
693
760
|
console.log(formatGuardOutput(result));
|
|
694
761
|
}
|
|
695
762
|
catch {
|
|
696
763
|
console.log(JSON.stringify({ decision: "allow" }));
|
|
697
764
|
}
|
|
698
765
|
});
|
|
766
|
+
// ── alerts command ──────────────────────────────────────────────────────────
|
|
767
|
+
async function patchAlertsConfig(configPath, patch) {
|
|
768
|
+
await mkdir(dirname(configPath), { recursive: true });
|
|
769
|
+
let current = {};
|
|
770
|
+
try {
|
|
771
|
+
current = JSON.parse(await readFile(configPath, "utf-8"));
|
|
772
|
+
}
|
|
773
|
+
catch {
|
|
774
|
+
// file missing — start fresh
|
|
775
|
+
}
|
|
776
|
+
const alerts = (current.alerts && typeof current.alerts === "object"
|
|
777
|
+
? { ...current.alerts }
|
|
778
|
+
: {});
|
|
779
|
+
Object.assign(alerts, patch);
|
|
780
|
+
current.alerts = alerts;
|
|
781
|
+
await writeFile(configPath, `${JSON.stringify(current, null, 2)}\n`, "utf-8");
|
|
782
|
+
}
|
|
783
|
+
const alertsCmd = program
|
|
784
|
+
.command("alerts")
|
|
785
|
+
.description("Show or toggle alert settings")
|
|
786
|
+
.option("--config <path>", "Path to settings.json")
|
|
787
|
+
.action(async (opts) => {
|
|
788
|
+
const config = await loadConfig(resolveConfigPath(opts));
|
|
789
|
+
const a = config.alerts;
|
|
790
|
+
console.log(`alerts.enabled : ${a.enabled}`);
|
|
791
|
+
console.log(`alerts.desktop : ${a.desktop}`);
|
|
792
|
+
console.log(`alerts.log : ${a.log}`);
|
|
793
|
+
console.log(`alerts.contextCritThreshold: ${a.contextCritThreshold} (${Math.round(a.contextCritThreshold * 100)}%)`);
|
|
794
|
+
console.log(`alerts.contextWarnThreshold: ${a.contextWarnThreshold === 1.0 ? "disabled" : `${a.contextWarnThreshold} (${Math.round(a.contextWarnThreshold * 100)}%)`}`);
|
|
795
|
+
});
|
|
796
|
+
alertsCmd
|
|
797
|
+
.command("on")
|
|
798
|
+
.description("Enable alert system")
|
|
799
|
+
.option("--config <path>", "Path to settings.json")
|
|
800
|
+
.action(async (opts) => {
|
|
801
|
+
const p = resolveConfigPath(opts) ?? getDefaultConfigPath();
|
|
802
|
+
await patchAlertsConfig(p, { enabled: true });
|
|
803
|
+
console.log("Alerts enabled. Restart daemon to apply: marmonitor restart");
|
|
804
|
+
});
|
|
805
|
+
alertsCmd
|
|
806
|
+
.command("off")
|
|
807
|
+
.description("Disable alert system")
|
|
808
|
+
.option("--config <path>", "Path to settings.json")
|
|
809
|
+
.action(async (opts) => {
|
|
810
|
+
const p = resolveConfigPath(opts) ?? getDefaultConfigPath();
|
|
811
|
+
await patchAlertsConfig(p, { enabled: false });
|
|
812
|
+
console.log("Alerts disabled. Restart daemon to apply: marmonitor restart");
|
|
813
|
+
});
|
|
814
|
+
alertsCmd
|
|
815
|
+
.command("notify <on|off>")
|
|
816
|
+
.description("Toggle desktop notifications")
|
|
817
|
+
.option("--config <path>", "Path to settings.json")
|
|
818
|
+
.action(async (toggle, opts) => {
|
|
819
|
+
if (toggle !== "on" && toggle !== "off") {
|
|
820
|
+
console.error("Usage: marmonitor alerts notify on|off");
|
|
821
|
+
process.exit(1);
|
|
822
|
+
}
|
|
823
|
+
const p = resolveConfigPath(opts) ?? getDefaultConfigPath();
|
|
824
|
+
await patchAlertsConfig(p, { desktop: toggle === "on" });
|
|
825
|
+
console.log(`Desktop notifications ${toggle === "on" ? "enabled" : "disabled"}. Restart daemon to apply: marmonitor restart`);
|
|
826
|
+
});
|
|
827
|
+
// ── end alerts command ───────────────────────────────────────────────────────
|
|
699
828
|
program
|
|
700
829
|
.command("debug-phase")
|
|
701
830
|
.description("Inspect phase signals, stdout heuristic, and tmux capture for one AI session")
|
|
@@ -1215,10 +1344,21 @@ program
|
|
|
1215
1344
|
console.log(" $ rm -rf ~/.config/marmonitor # settings & session history");
|
|
1216
1345
|
console.log(" $ rm -rf ~/.tmux/plugins/marmonitor-tmux # tpm plugin");
|
|
1217
1346
|
});
|
|
1347
|
+
/** Find all running marmonitor daemon PIDs (excludes current CLI process) */
|
|
1348
|
+
async function findRunningDaemonPids() {
|
|
1349
|
+
try {
|
|
1350
|
+
const { default: psList } = await import("ps-list");
|
|
1351
|
+
const procs = await psList();
|
|
1352
|
+
return procs.filter((p) => p.name === "marmonitor" && p.pid !== process.pid).map((p) => p.pid);
|
|
1353
|
+
}
|
|
1354
|
+
catch {
|
|
1355
|
+
return [];
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1218
1358
|
async function startDaemon() {
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
console.log(`Daemon already running (PID: ${
|
|
1359
|
+
const running = await findRunningDaemonPids();
|
|
1360
|
+
if (running.length > 0) {
|
|
1361
|
+
console.log(`Daemon already running (PID: ${running[0]})`);
|
|
1222
1362
|
return undefined;
|
|
1223
1363
|
}
|
|
1224
1364
|
const { fork } = await import("node:child_process");
|
|
@@ -1230,13 +1370,42 @@ async function startDaemon() {
|
|
|
1230
1370
|
return child.pid ?? undefined;
|
|
1231
1371
|
}
|
|
1232
1372
|
async function stopDaemon() {
|
|
1233
|
-
const
|
|
1234
|
-
if (
|
|
1373
|
+
const pids = await findRunningDaemonPids();
|
|
1374
|
+
if (pids.length === 0) {
|
|
1235
1375
|
console.log("Daemon is not running.");
|
|
1236
1376
|
return false;
|
|
1237
1377
|
}
|
|
1238
|
-
|
|
1239
|
-
|
|
1378
|
+
// Send SIGTERM to all running daemon processes (handles orphans)
|
|
1379
|
+
for (const pid of pids) {
|
|
1380
|
+
try {
|
|
1381
|
+
process.kill(pid, "SIGTERM");
|
|
1382
|
+
}
|
|
1383
|
+
catch { }
|
|
1384
|
+
}
|
|
1385
|
+
// Poll until all processes die (up to 2s)
|
|
1386
|
+
let remaining = [...pids];
|
|
1387
|
+
for (let i = 0; i < 20; i++) {
|
|
1388
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
1389
|
+
remaining = remaining.filter((pid) => {
|
|
1390
|
+
try {
|
|
1391
|
+
process.kill(pid, 0);
|
|
1392
|
+
return true; // still alive
|
|
1393
|
+
}
|
|
1394
|
+
catch {
|
|
1395
|
+
return false; // dead
|
|
1396
|
+
}
|
|
1397
|
+
});
|
|
1398
|
+
if (remaining.length === 0)
|
|
1399
|
+
break;
|
|
1400
|
+
}
|
|
1401
|
+
// Fallback: SIGKILL any survivors
|
|
1402
|
+
for (const pid of remaining) {
|
|
1403
|
+
try {
|
|
1404
|
+
process.kill(pid, "SIGKILL");
|
|
1405
|
+
}
|
|
1406
|
+
catch { }
|
|
1407
|
+
}
|
|
1408
|
+
console.log(`✓ Daemon stopped (PID: ${pids.join(", ")})`);
|
|
1240
1409
|
return true;
|
|
1241
1410
|
}
|
|
1242
1411
|
program
|
|
@@ -1258,7 +1427,6 @@ program
|
|
|
1258
1427
|
.description("Restart background scan daemon")
|
|
1259
1428
|
.action(async () => {
|
|
1260
1429
|
await stopDaemon();
|
|
1261
|
-
await new Promise((r) => setTimeout(r, 500));
|
|
1262
1430
|
await startDaemon();
|
|
1263
1431
|
process.exit(0);
|
|
1264
1432
|
});
|
package/dist/config/index.d.ts
CHANGED
|
@@ -86,6 +86,18 @@ export interface MarmonitorConfig {
|
|
|
86
86
|
daemonIntervalSec: number;
|
|
87
87
|
activityRetentionDays: number;
|
|
88
88
|
};
|
|
89
|
+
alerts: {
|
|
90
|
+
/** 알림 시스템 마스터 토글 */
|
|
91
|
+
enabled: boolean;
|
|
92
|
+
/** macOS/Linux 데스크탑 알림 */
|
|
93
|
+
desktop: boolean;
|
|
94
|
+
/** alerts.log 파일 기록 */
|
|
95
|
+
log: boolean;
|
|
96
|
+
/** 컨텍스트 경고 임계값 (0~1). 0 = 비활성화. 기본 1.0 (비활성) */
|
|
97
|
+
contextWarnThreshold: number;
|
|
98
|
+
/** 컨텍스트 위험 임계값 (0~1). 기본 0.85 */
|
|
99
|
+
contextCritThreshold: number;
|
|
100
|
+
};
|
|
89
101
|
}
|
|
90
102
|
/** Get config search paths in priority order */
|
|
91
103
|
export declare function getConfigSearchPaths(): string[];
|
package/dist/config/index.js
CHANGED
|
@@ -92,6 +92,13 @@ const DEFAULTS = {
|
|
|
92
92
|
daemonIntervalSec: 2,
|
|
93
93
|
activityRetentionDays: 7,
|
|
94
94
|
},
|
|
95
|
+
alerts: {
|
|
96
|
+
enabled: true,
|
|
97
|
+
desktop: true,
|
|
98
|
+
log: true,
|
|
99
|
+
contextWarnThreshold: 1.0, // 기본 비활성 (0.70으로 설정 시 활성화)
|
|
100
|
+
contextCritThreshold: 0.85,
|
|
101
|
+
},
|
|
95
102
|
};
|
|
96
103
|
function cloneDefaults() {
|
|
97
104
|
return JSON.parse(JSON.stringify(DEFAULTS));
|
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,6 +17,7 @@ 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]",
|
|
@@ -23,6 +25,7 @@ export const BADGE_THEMES = {
|
|
|
23
25
|
block: {
|
|
24
26
|
badge: "#[bold,fg={fg},bg={bg}] {label} #[default]",
|
|
25
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]",
|
|
26
29
|
focus: "#[fg=#bac2de,bg=#181825] {text} #[default]",
|
|
27
30
|
empty: "#[fg=#cdd6f4,bg=#313244] no active #[default]",
|
|
28
31
|
jumpBack: "#[fg=#bac2de,bg=#45475a] ↩ #[default]",
|
|
@@ -30,6 +33,7 @@ export const BADGE_THEMES = {
|
|
|
30
33
|
"block-mono": {
|
|
31
34
|
badge: "#[bold,fg=#cdd6f4,bg=#313244] {label} #[default]",
|
|
32
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]",
|
|
33
37
|
focus: "#[fg=#6c7086,bg=#181825] {text} #[default]",
|
|
34
38
|
empty: "#[fg=#6c7086,bg=#313244] no active #[default]",
|
|
35
39
|
jumpBack: "#[fg=#6c7086,bg=#313244] ↩ #[default]",
|
|
@@ -37,6 +41,7 @@ export const BADGE_THEMES = {
|
|
|
37
41
|
text: {
|
|
38
42
|
badge: "#[fg={bg}]{label}#[default]",
|
|
39
43
|
attention: "#[fg={bg}]{index} {label}#[default]",
|
|
44
|
+
attentionActive: "#[underscore,fg={bg}]{index} {label}#[default]",
|
|
40
45
|
focus: "{text}",
|
|
41
46
|
empty: "no active",
|
|
42
47
|
jumpBack: "#[fg=#89b4fa]↩#[default]",
|
|
@@ -44,6 +49,7 @@ export const BADGE_THEMES = {
|
|
|
44
49
|
"text-mono": {
|
|
45
50
|
badge: "#[fg=#cdd6f4]{label}#[default]",
|
|
46
51
|
attention: "#[bold,fg=#cdd6f4]{index}#[default] #[fg=#6c7086]{label}#[default]",
|
|
52
|
+
attentionActive: "#[bold,underscore,fg=#cdd6f4]{index}#[default] #[underscore,fg=#6c7086]{label}#[default]",
|
|
47
53
|
focus: "#[fg=#6c7086]{text}#[default]",
|
|
48
54
|
empty: "#[fg=#6c7086]no active#[default]",
|
|
49
55
|
jumpBack: "#[fg=#6c7086]↩#[default]",
|
|
@@ -58,6 +64,12 @@ export function renderAttention(theme, index, label, bg) {
|
|
|
58
64
|
.replaceAll("{label}", label)
|
|
59
65
|
.replaceAll("{bg}", bg);
|
|
60
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
|
+
}
|
|
61
73
|
export function renderFocus(theme, text) {
|
|
62
74
|
return theme.focus.replaceAll("{text}", text);
|
|
63
75
|
}
|
package/dist/output/index.d.ts
CHANGED
|
@@ -27,6 +27,6 @@ export declare function printDock(agents: AgentSession[], maxLines?: number): Pr
|
|
|
27
27
|
/** Print one-line summary for tmux/terminal status bar */
|
|
28
28
|
export declare function renderUnavailableStatusline(format?: StatuslineFormat): string;
|
|
29
29
|
/** Print one-line summary for tmux/terminal status bar */
|
|
30
|
-
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>;
|
|
31
31
|
/** Print one-line summary for tmux/terminal status bar */
|
|
32
32
|
export declare function printStatusline(agents: AgentSession[], format?: StatuslineFormat, attentionLimit?: number, width?: number): Promise<void>;
|
package/dist/output/index.js
CHANGED
|
@@ -578,7 +578,7 @@ export function renderUnavailableStatusline(format = "compact") {
|
|
|
578
578
|
return "marmonitor unavailable";
|
|
579
579
|
}
|
|
580
580
|
/** Print one-line summary for tmux/terminal status bar */
|
|
581
|
-
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) {
|
|
582
582
|
const alive = agents.filter((a) => a.status !== "Dead" && a.status !== "Unmatched");
|
|
583
583
|
const unmatched = agents.filter((a) => a.status === "Unmatched");
|
|
584
584
|
if (alive.length === 0) {
|
|
@@ -611,7 +611,7 @@ export async function renderStatusline(agents, format = "compact", attentionLimi
|
|
|
611
611
|
memoryUsedGb: sys.memoryUsedGb,
|
|
612
612
|
};
|
|
613
613
|
if (format === "tmux-badges") {
|
|
614
|
-
const focusText = buildTmuxAttentionPills(buildJumpAttentionItems(agents), attentionLimit, width, badgeStyle);
|
|
614
|
+
const focusText = buildTmuxAttentionPills(buildJumpAttentionItems(agents), attentionLimit, width, badgeStyle, activeAgentPid);
|
|
615
615
|
return buildTmuxBadgeBar(snapshot, focusText, badgeStyle, hasJumpAnchor);
|
|
616
616
|
}
|
|
617
617
|
if (format === "wezterm-pills") {
|
package/dist/output/utils.d.ts
CHANGED
|
@@ -103,6 +103,7 @@ export interface SessionRegistryEntry {
|
|
|
103
103
|
startedAt?: number;
|
|
104
104
|
model?: string;
|
|
105
105
|
source: "claude" | "codex";
|
|
106
|
+
binding: "direct" | "provisional";
|
|
106
107
|
}
|
|
107
108
|
export interface SessionFileCandidate {
|
|
108
109
|
path: string;
|
|
@@ -149,5 +150,5 @@ export declare function buildStatusPills(snapshot: StatuslineSnapshot): {
|
|
|
149
150
|
export declare function buildStatuslineSummary(snapshot: StatuslineSnapshot, format?: StatuslineFormat): string;
|
|
150
151
|
export type BadgeStyle = "basic" | "basic-mono" | "block" | "block-mono" | "text" | "text-mono";
|
|
151
152
|
export declare function buildTmuxBadgeBar(snapshot: StatuslineSnapshot, focusText?: string, badgeStyle?: BadgeStyle, hasJumpAnchor?: boolean): string;
|
|
152
|
-
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;
|
|
153
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)
|
|
@@ -583,7 +586,7 @@ export function buildTmuxBadgeBar(snapshot, focusText, badgeStyle = "basic", has
|
|
|
583
586
|
const focus = focusText ? renderFocus(theme, focusText) : "";
|
|
584
587
|
return [agentPills.join(" "), alertPills.join(" "), jumpBack, focus].filter(Boolean).join(" ");
|
|
585
588
|
}
|
|
586
|
-
export function buildTmuxAttentionPills(items, maxCount = 5, width, badgeStyle = "basic") {
|
|
589
|
+
export function buildTmuxAttentionPills(items, maxCount = 5, width, badgeStyle = "basic", activeAgentPid) {
|
|
587
590
|
if (maxCount <= 0)
|
|
588
591
|
return undefined;
|
|
589
592
|
const layout = resolveStatuslineDetailLayout(width, maxCount);
|
|
@@ -615,7 +618,9 @@ export function buildTmuxAttentionPills(items, maxCount = 5, width, badgeStyle =
|
|
|
615
618
|
: time
|
|
616
619
|
? `⚠${agent} ${path} ${time}`
|
|
617
620
|
: `⚠${agent} ${path}`;
|
|
618
|
-
|
|
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)));
|
|
619
624
|
});
|
|
620
625
|
return segments.join(" ");
|
|
621
626
|
}
|