marmonitor 0.1.7 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ko.md +262 -0
- package/README.md +49 -5
- package/bin/daemon.js +2 -0
- package/bin/postinstall.cjs +47 -1
- package/bin/preuninstall.cjs +14 -0
- package/dist/banner/index.js +15 -7
- package/dist/cli.js +282 -107
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +2 -0
- package/dist/output/badge-themes.d.ts +19 -0
- package/dist/output/badge-themes.js +52 -0
- package/dist/output/index.d.ts +5 -2
- package/dist/output/index.js +69 -22
- package/dist/output/utils.d.ts +22 -8
- package/dist/output/utils.js +83 -48
- package/dist/scanner/claude.d.ts +8 -1
- package/dist/scanner/claude.js +156 -19
- package/dist/scanner/codex-sqlite.d.ts +11 -0
- package/dist/scanner/codex-sqlite.js +50 -0
- package/dist/scanner/codex.d.ts +1 -1
- package/dist/scanner/codex.js +42 -2
- package/dist/scanner/concurrency.d.ts +5 -0
- package/dist/scanner/concurrency.js +22 -0
- package/dist/scanner/daemon-entry.d.ts +5 -0
- package/dist/scanner/daemon-entry.js +27 -0
- package/dist/scanner/daemon-loop.d.ts +13 -0
- package/dist/scanner/daemon-loop.js +77 -0
- package/dist/scanner/daemon-utils.d.ts +9 -0
- package/dist/scanner/daemon-utils.js +56 -0
- package/dist/scanner/index.js +51 -10
- package/dist/scanner/perf.d.ts +8 -0
- package/dist/scanner/perf.js +26 -0
- package/dist/scanner/session-registry.d.ts +31 -0
- package/dist/scanner/session-registry.js +99 -0
- package/dist/scanner/session-tier.d.ts +6 -0
- package/dist/scanner/session-tier.js +22 -0
- package/dist/tmux/index.js +11 -0
- package/dist/tmux/jump-anchor.d.ts +25 -0
- package/dist/tmux/jump-anchor.js +100 -0
- package/dist/tmux/setup.d.ts +4 -0
- package/dist/tmux/setup.js +41 -1
- package/dist/tmux/status-click.d.ts +9 -0
- package/dist/tmux/status-click.js +19 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -5,15 +5,18 @@ 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
7
|
import { evaluateGuard, formatGuardOutput, parseHookEvent, readStdin } from "./guard/index.js";
|
|
8
|
-
import { printAttention, printAttentionJson, printCleanJson, printCleanPlan, printDock,
|
|
9
|
-
import { selectJumpAttentionItem, selectUnmatchedTargets } from "./output/utils.js";
|
|
8
|
+
import { applyTerminalStyle, printAttention, printAttentionJson, printCleanJson, printCleanPlan, printDock, printJumpJson, printJumpResult, printStatus, printStatusJson, renderJumpAttentionChooser, renderStatusline, renderUnavailableStatusline, } from "./output/index.js";
|
|
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 { isDaemonRunning, readDaemonPid, readDaemonSnapshot } from "./scanner/daemon-utils.js";
|
|
13
14
|
import { parseGeminiSession } from "./scanner/gemini.js";
|
|
14
15
|
import { scanAgents } from "./scanner/index.js";
|
|
15
16
|
import { detectCliStdoutPhase } from "./scanner/status.js";
|
|
16
17
|
import { captureTmuxPaneOutput, jumpToAgent, resolveTmuxJumpTarget } from "./tmux/index.js";
|
|
18
|
+
import { getClientTty, jumpBack } from "./tmux/jump-anchor.js";
|
|
19
|
+
import { findClickedAgent, parseStatusClickToken } from "./tmux/status-click.js";
|
|
17
20
|
import { VERSION } from "./version.js";
|
|
18
21
|
function sleep(ms) {
|
|
19
22
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -110,6 +113,12 @@ function buildHelpAppendix() {
|
|
|
110
113
|
" [Dead] Session file exists but process gone",
|
|
111
114
|
" [Unmatched] AI process without matching session",
|
|
112
115
|
"",
|
|
116
|
+
"Common settings:",
|
|
117
|
+
" display.attentionLimit / display.statuslineAttentionLimit",
|
|
118
|
+
" integration.tmux.badgeStyle",
|
|
119
|
+
" integration.tmux.keys.*",
|
|
120
|
+
" paths.* (runtime data path overrides)",
|
|
121
|
+
"",
|
|
113
122
|
"Default tmux shortcuts:",
|
|
114
123
|
" Prefix+a Attention popup",
|
|
115
124
|
" Prefix+j Jump popup",
|
|
@@ -131,12 +140,16 @@ function clearScreen() {
|
|
|
131
140
|
process.stdout.write("\x1Bc");
|
|
132
141
|
}
|
|
133
142
|
}
|
|
134
|
-
async function
|
|
143
|
+
async function promptSelectionAction(maxChoice, currentPage = 1, totalPages = 1) {
|
|
135
144
|
if (!process.stdin.isTTY || maxChoice < 1)
|
|
136
145
|
return undefined;
|
|
137
|
-
const prompt =
|
|
138
|
-
?
|
|
139
|
-
|
|
146
|
+
const prompt = totalPages > 1
|
|
147
|
+
? maxChoice >= 10
|
|
148
|
+
? "\n←/→ page, 1-9 to jump, 0 for 10, q to cancel: "
|
|
149
|
+
: `\n←/→ page, 1-${maxChoice} to jump, q to cancel: `
|
|
150
|
+
: maxChoice >= 10
|
|
151
|
+
? "\n1-9 to jump, 0 for 10, q to cancel: "
|
|
152
|
+
: `\n1-${maxChoice} to jump, q to cancel: `;
|
|
140
153
|
process.stdout.write(prompt);
|
|
141
154
|
return await new Promise((resolve) => {
|
|
142
155
|
const stdin = process.stdin;
|
|
@@ -154,23 +167,10 @@ async function promptSelectionKey(maxChoice) {
|
|
|
154
167
|
cleanup();
|
|
155
168
|
exitWithCleanup(130);
|
|
156
169
|
}
|
|
157
|
-
|
|
170
|
+
const action = parseSelectionInput(input, maxChoice, currentPage, totalPages);
|
|
171
|
+
if (action) {
|
|
158
172
|
cleanup();
|
|
159
|
-
resolve(
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
const trimmed = input.trim();
|
|
163
|
-
if (/^[1-9]$/.test(trimmed)) {
|
|
164
|
-
const selection = Number.parseInt(trimmed, 10);
|
|
165
|
-
if (selection <= maxChoice) {
|
|
166
|
-
cleanup();
|
|
167
|
-
resolve(selection);
|
|
168
|
-
}
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
if (trimmed === "0" && maxChoice >= 10) {
|
|
172
|
-
cleanup();
|
|
173
|
-
resolve(10);
|
|
173
|
+
resolve(action);
|
|
174
174
|
}
|
|
175
175
|
};
|
|
176
176
|
if (restoreRawMode)
|
|
@@ -241,6 +241,7 @@ function buildMinimalConfigSample() {
|
|
|
241
241
|
},
|
|
242
242
|
integration: {
|
|
243
243
|
tmux: {
|
|
244
|
+
badgeStyle: "basic",
|
|
244
245
|
keys: {
|
|
245
246
|
attentionPopup: "a",
|
|
246
247
|
jumpPopup: "j",
|
|
@@ -272,6 +273,7 @@ function buildAdvancedConfigSample() {
|
|
|
272
273
|
},
|
|
273
274
|
integration: {
|
|
274
275
|
tmux: {
|
|
276
|
+
badgeStyle: "basic",
|
|
275
277
|
keys: {
|
|
276
278
|
attentionPopup: "a",
|
|
277
279
|
jumpPopup: "j",
|
|
@@ -388,9 +390,6 @@ function statuslineCacheFile(format, attentionLimit, width) {
|
|
|
388
390
|
const widthKey = width && width > 0 ? String(width) : "auto";
|
|
389
391
|
return join(tmpdir(), "marmonitor", `statusline-${format}-${attentionLimit}-${widthKey}.txt`);
|
|
390
392
|
}
|
|
391
|
-
function snapshotCacheFile(enrichmentMode, showDead) {
|
|
392
|
-
return join(tmpdir(), "marmonitor", `snapshot-${enrichmentMode}-${showDead ? "dead" : "alive"}.json`);
|
|
393
|
-
}
|
|
394
393
|
async function readCachedStatusline(format, attentionLimit, width, ttlMs) {
|
|
395
394
|
const path = statuslineCacheFile(format, attentionLimit, width);
|
|
396
395
|
try {
|
|
@@ -413,40 +412,18 @@ async function writeCachedStatusline(format, attentionLimit, width, value) {
|
|
|
413
412
|
// cache failures must never break statusline rendering
|
|
414
413
|
}
|
|
415
414
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
return JSON.parse(await readFile(path, "utf-8"));
|
|
423
|
-
}
|
|
424
|
-
catch {
|
|
425
|
-
return undefined;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
async function writeCachedSnapshot(enrichmentMode, showDead, agents) {
|
|
429
|
-
const path = snapshotCacheFile(enrichmentMode, showDead);
|
|
430
|
-
try {
|
|
431
|
-
await mkdir(join(tmpdir(), "marmonitor"), { recursive: true });
|
|
432
|
-
await writeFile(path, JSON.stringify(agents), "utf-8");
|
|
433
|
-
}
|
|
434
|
-
catch {
|
|
435
|
-
// snapshot cache failures must never break command execution
|
|
436
|
-
}
|
|
415
|
+
const DAEMON_DIR = join(tmpdir(), "marmonitor");
|
|
416
|
+
const DAEMON_PID_PATH = join(DAEMON_DIR, "daemon.pid");
|
|
417
|
+
const DAEMON_SNAPSHOT_PATH = join(DAEMON_DIR, "daemon-snapshot.json");
|
|
418
|
+
const DAEMON_NOT_RUNNING = "Daemon not running. Run: marmonitor start";
|
|
419
|
+
async function getAgentsSnapshot() {
|
|
420
|
+
return (await readDaemonSnapshot(DAEMON_SNAPSHOT_PATH, 5_000));
|
|
437
421
|
}
|
|
438
|
-
async function
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
const cached = await readCachedSnapshot(enrichmentMode, config.display.showDead, ttlMs);
|
|
444
|
-
if (cached)
|
|
445
|
-
return cached;
|
|
446
|
-
}
|
|
447
|
-
const agents = await scanAgents(config, { enrichmentMode });
|
|
448
|
-
if (useCache) {
|
|
449
|
-
await writeCachedSnapshot(enrichmentMode, config.display.showDead, agents);
|
|
422
|
+
async function requireDaemonSnapshot() {
|
|
423
|
+
const agents = await getAgentsSnapshot();
|
|
424
|
+
if (agents.length === 0) {
|
|
425
|
+
console.error(DAEMON_NOT_RUNNING);
|
|
426
|
+
process.exit(1);
|
|
450
427
|
}
|
|
451
428
|
return agents;
|
|
452
429
|
}
|
|
@@ -475,8 +452,23 @@ program
|
|
|
475
452
|
console.log(cached);
|
|
476
453
|
return;
|
|
477
454
|
}
|
|
478
|
-
const agents = await getAgentsSnapshot(
|
|
479
|
-
|
|
455
|
+
const agents = await getAgentsSnapshot();
|
|
456
|
+
if (agents.length === 0) {
|
|
457
|
+
console.log(renderUnavailableStatusline(opts.statuslineFormat));
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
// Check jump-back anchor for indicator
|
|
461
|
+
let hasJumpAnchor = false;
|
|
462
|
+
if (opts.statuslineFormat === "tmux-badges") {
|
|
463
|
+
const { tmpdir: td } = await import("node:os");
|
|
464
|
+
const { join: pj } = await import("node:path");
|
|
465
|
+
const { loadJumpAnchor } = await import("./tmux/jump-anchor.js");
|
|
466
|
+
const tty = await getClientTty();
|
|
467
|
+
if (tty) {
|
|
468
|
+
hasJumpAnchor = Boolean(await loadJumpAnchor(pj(td(), "marmonitor", "jump-anchors.json"), tty));
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
const rendered = await renderStatusline(agents, opts.statuslineFormat, attentionLimit, width, config.integration.tmux.badgeStyle, hasJumpAnchor);
|
|
480
472
|
await writeCachedStatusline(opts.statuslineFormat, attentionLimit, width, rendered);
|
|
481
473
|
console.log(rendered);
|
|
482
474
|
return;
|
|
@@ -493,17 +485,29 @@ program
|
|
|
493
485
|
.description("Show current AI agent status")
|
|
494
486
|
.option("--json", "Output as JSON")
|
|
495
487
|
.option("--config <path>", "Path to settings.json")
|
|
496
|
-
.option("--show-dead", "Include dead sessions")
|
|
497
488
|
.action(async (opts) => {
|
|
489
|
+
const agents = await requireDaemonSnapshot();
|
|
498
490
|
const config = await loadConfig(resolveConfigPath(opts));
|
|
499
|
-
|
|
500
|
-
config.display.showDead = true;
|
|
501
|
-
const agents = await getAgentsSnapshot(config, { enrichmentMode: "full" });
|
|
491
|
+
applyTerminalStyle(config.integration.tmux.badgeStyle);
|
|
502
492
|
if (opts.json) {
|
|
503
493
|
await printStatusJson(agents);
|
|
504
494
|
}
|
|
505
495
|
else {
|
|
506
496
|
await printStatus(agents);
|
|
497
|
+
// Show setup hint if tmux plugin not configured
|
|
498
|
+
try {
|
|
499
|
+
const { hasMarmonitorPlugin } = await import("./tmux/setup.js");
|
|
500
|
+
const { homedir } = await import("node:os");
|
|
501
|
+
const { join } = await import("node:path");
|
|
502
|
+
const confPath = join(homedir(), ".tmux.conf");
|
|
503
|
+
if (!(await hasMarmonitorPlugin(confPath))) {
|
|
504
|
+
console.log("\ntmux integration not configured.");
|
|
505
|
+
console.log(" Run: marmonitor setup tmux\n");
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
catch {
|
|
509
|
+
// silent — setup check must never break status
|
|
510
|
+
}
|
|
507
511
|
}
|
|
508
512
|
});
|
|
509
513
|
program
|
|
@@ -514,8 +518,9 @@ program
|
|
|
514
518
|
.option("--limit <n>", "Max items to show", "12")
|
|
515
519
|
.option("--config <path>", "Path to settings.json")
|
|
516
520
|
.action(async (opts) => {
|
|
521
|
+
const agents = await requireDaemonSnapshot();
|
|
517
522
|
const config = await loadConfig(resolveConfigPath(opts));
|
|
518
|
-
|
|
523
|
+
applyTerminalStyle(config.integration.tmux.badgeStyle);
|
|
519
524
|
const limit = resolveAttentionLimit(opts, config.display.attentionLimit);
|
|
520
525
|
const interactiveLimit = resolveAttentionLimit(opts, config.display.attentionLimit, true);
|
|
521
526
|
if (opts.interactive && opts.json) {
|
|
@@ -527,13 +532,30 @@ program
|
|
|
527
532
|
console.error("--interactive requires an interactive terminal.");
|
|
528
533
|
process.exit(1);
|
|
529
534
|
}
|
|
530
|
-
|
|
531
|
-
const
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
+
const totalItems = buildJumpAttentionItems(agents).length;
|
|
536
|
+
const totalPages = Math.max(1, Math.ceil(totalItems / interactiveLimit));
|
|
537
|
+
let currentPage = 1;
|
|
538
|
+
let item;
|
|
539
|
+
while (true) {
|
|
540
|
+
clearScreen();
|
|
541
|
+
console.log(renderJumpAttentionChooser(agents, currentPage, interactiveLimit));
|
|
542
|
+
const pageItemCount = Math.min(interactiveLimit, Math.max(totalItems - (currentPage - 1) * interactiveLimit, 0));
|
|
543
|
+
const action = await promptSelectionAction(pageItemCount, currentPage, totalPages);
|
|
544
|
+
if (!action || action.kind === "cancel")
|
|
545
|
+
return;
|
|
546
|
+
if (action.kind === "next") {
|
|
547
|
+
currentPage = Math.min(currentPage + 1, totalPages);
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
if (action.kind === "prev") {
|
|
551
|
+
currentPage = Math.max(currentPage - 1, 1);
|
|
552
|
+
continue;
|
|
553
|
+
}
|
|
554
|
+
item = selectJumpAttentionItemOnPage(agents, currentPage, action.selection, interactiveLimit);
|
|
555
|
+
break;
|
|
556
|
+
}
|
|
535
557
|
if (!item) {
|
|
536
|
-
console.error(
|
|
558
|
+
console.error("Invalid selection.");
|
|
537
559
|
process.exit(1);
|
|
538
560
|
}
|
|
539
561
|
const agent = agents.find((candidate) => candidate.pid === item.pid);
|
|
@@ -693,8 +715,8 @@ program
|
|
|
693
715
|
.option("--json", "Output as JSON")
|
|
694
716
|
.option("--config <path>", "Path to settings.json")
|
|
695
717
|
.action(async (opts) => {
|
|
718
|
+
const agents = await requireDaemonSnapshot();
|
|
696
719
|
const config = await loadConfig(resolveConfigPath(opts));
|
|
697
|
-
const agents = await getAgentsSnapshot(config, { enrichmentMode: "full" });
|
|
698
720
|
const useAttention = Boolean(opts.attention);
|
|
699
721
|
const useAttentionIndex = typeof opts.attentionIndex === "string";
|
|
700
722
|
const usePid = typeof opts.pid === "string";
|
|
@@ -710,13 +732,30 @@ program
|
|
|
710
732
|
process.exit(1);
|
|
711
733
|
}
|
|
712
734
|
const limit = resolveAttentionLimit({ limit: undefined }, config.display.attentionLimit, true);
|
|
713
|
-
|
|
714
|
-
const
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
735
|
+
const totalItems = buildJumpAttentionItems(agents).length;
|
|
736
|
+
const totalPages = Math.max(1, Math.ceil(totalItems / limit));
|
|
737
|
+
let currentPage = 1;
|
|
738
|
+
let item;
|
|
739
|
+
while (true) {
|
|
740
|
+
clearScreen();
|
|
741
|
+
console.log(renderJumpAttentionChooser(agents, currentPage, limit));
|
|
742
|
+
const pageItemCount = Math.min(limit, Math.max(totalItems - (currentPage - 1) * limit, 0));
|
|
743
|
+
const action = await promptSelectionAction(pageItemCount, currentPage, totalPages);
|
|
744
|
+
if (!action || action.kind === "cancel")
|
|
745
|
+
return;
|
|
746
|
+
if (action.kind === "next") {
|
|
747
|
+
currentPage = Math.min(currentPage + 1, totalPages);
|
|
748
|
+
continue;
|
|
749
|
+
}
|
|
750
|
+
if (action.kind === "prev") {
|
|
751
|
+
currentPage = Math.max(currentPage - 1, 1);
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
754
|
+
item = selectJumpAttentionItemOnPage(agents, currentPage, action.selection, limit);
|
|
755
|
+
break;
|
|
756
|
+
}
|
|
718
757
|
if (!item) {
|
|
719
|
-
console.error(
|
|
758
|
+
console.error("Invalid selection.");
|
|
720
759
|
process.exit(1);
|
|
721
760
|
}
|
|
722
761
|
pid = item.pid;
|
|
@@ -768,59 +807,89 @@ program
|
|
|
768
807
|
if (!result.found)
|
|
769
808
|
process.exit(1);
|
|
770
809
|
});
|
|
810
|
+
program
|
|
811
|
+
.command("jump-back")
|
|
812
|
+
.description("Return to the tmux pane you were in before the last jump")
|
|
813
|
+
.option("--client-tty <tty>", "Override client tty (auto-detected if omitted)")
|
|
814
|
+
.action(async (opts) => {
|
|
815
|
+
const { tmpdir: td } = await import("node:os");
|
|
816
|
+
const { join: pjoin } = await import("node:path");
|
|
817
|
+
const anchorPath = pjoin(td(), "marmonitor", "jump-anchors.json");
|
|
818
|
+
const tty = opts.clientTty ?? (await getClientTty());
|
|
819
|
+
if (!tty) {
|
|
820
|
+
console.error("Cannot detect tmux client. Are you inside tmux?");
|
|
821
|
+
process.exit(1);
|
|
822
|
+
}
|
|
823
|
+
const result = await jumpBack(anchorPath, tty);
|
|
824
|
+
console.log(result.message);
|
|
825
|
+
if (!result.success)
|
|
826
|
+
process.exit(1);
|
|
827
|
+
});
|
|
828
|
+
program
|
|
829
|
+
.command("status-click")
|
|
830
|
+
.description("Internal tmux statusline click handler")
|
|
831
|
+
.argument("[token]", "tmux mouse status range token")
|
|
832
|
+
.option("--client-tty <tty>", "Override client tty (auto-detected if omitted)")
|
|
833
|
+
.action(async (token, opts) => {
|
|
834
|
+
const action = parseStatusClickToken(token);
|
|
835
|
+
if (!action)
|
|
836
|
+
return;
|
|
837
|
+
if (action.kind === "jump-back") {
|
|
838
|
+
const { tmpdir: td } = await import("node:os");
|
|
839
|
+
const { join: pjoin } = await import("node:path");
|
|
840
|
+
const anchorPath = pjoin(td(), "marmonitor", "jump-anchors.json");
|
|
841
|
+
const tty = opts.clientTty ?? (await getClientTty());
|
|
842
|
+
if (!tty)
|
|
843
|
+
process.exit(1);
|
|
844
|
+
const result = await jumpBack(anchorPath, tty);
|
|
845
|
+
if (!result.success)
|
|
846
|
+
process.exit(1);
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
const agents = await getAgentsSnapshot();
|
|
850
|
+
if (agents.length === 0)
|
|
851
|
+
process.exit(1);
|
|
852
|
+
const agent = findClickedAgent(agents, action);
|
|
853
|
+
if (!agent)
|
|
854
|
+
process.exit(1);
|
|
855
|
+
const result = await jumpToAgent(agent);
|
|
856
|
+
if (!result.executed)
|
|
857
|
+
process.exit(1);
|
|
858
|
+
});
|
|
771
859
|
program
|
|
772
860
|
.command("dock")
|
|
773
861
|
.description("Compact persistent monitor for tmux pane")
|
|
774
862
|
.option("--interval <sec>", "Refresh interval in seconds", "2")
|
|
775
|
-
.option("--detail-interval <sec>", "Heavy enrichment interval", "30")
|
|
776
863
|
.option("--lines <n>", "Max display lines", "12")
|
|
777
864
|
.option("--config <path>", "Path to settings.json")
|
|
778
865
|
.action(async (opts) => {
|
|
866
|
+
const config = await loadConfig(resolveConfigPath(opts));
|
|
867
|
+
applyTerminalStyle(config.integration.tmux.badgeStyle);
|
|
779
868
|
const intervalMs = Math.max(Number(opts.interval) || 2, 2) * 1000;
|
|
780
|
-
const detailMs = Math.max(Number(opts.detailInterval) || 30, 5) * 1000;
|
|
781
869
|
const maxLines = Number(opts.lines) || 12;
|
|
782
|
-
|
|
783
|
-
let lastHeavyAt = 0;
|
|
870
|
+
let agents = await requireDaemonSnapshot();
|
|
784
871
|
while (true) {
|
|
785
|
-
const now = Date.now();
|
|
786
|
-
const needsHeavy = lastHeavyAt === 0 || now - lastHeavyAt >= detailMs;
|
|
787
|
-
const agents = await scanAgents(config, {
|
|
788
|
-
enrichmentMode: needsHeavy ? "full" : "light",
|
|
789
|
-
});
|
|
790
|
-
if (needsHeavy)
|
|
791
|
-
lastHeavyAt = now;
|
|
792
872
|
clearScreen();
|
|
793
873
|
await printDock(agents, maxLines);
|
|
794
874
|
await sleep(intervalMs);
|
|
875
|
+
agents = await getAgentsSnapshot();
|
|
876
|
+
if (agents.length === 0)
|
|
877
|
+
agents = []; // daemon stopped mid-loop
|
|
795
878
|
}
|
|
796
879
|
});
|
|
797
880
|
program
|
|
798
881
|
.command("watch")
|
|
799
882
|
.description("Refresh agent status in a long-lived loop")
|
|
800
883
|
.option("--interval <sec>", "Refresh interval in seconds", "2")
|
|
801
|
-
.option("--detail-interval <sec>", "Heavy enrichment refresh interval in seconds", "30")
|
|
802
884
|
.option("--json", "Output as JSON")
|
|
803
885
|
.option("--config <path>", "Path to settings.json")
|
|
804
|
-
.option("--show-dead", "Include dead sessions")
|
|
805
886
|
.action(async (opts) => {
|
|
806
|
-
const intervalSec = Number(opts.interval);
|
|
807
|
-
const detailIntervalSec = Number(opts.detailInterval);
|
|
808
|
-
const intervalMs = Number.isFinite(intervalSec) && intervalSec > 0 ? intervalSec * 1000 : 10_000;
|
|
809
|
-
const detailIntervalMs = Number.isFinite(detailIntervalSec) && detailIntervalSec > 0
|
|
810
|
-
? detailIntervalSec * 1000
|
|
811
|
-
: 30_000;
|
|
812
887
|
const config = await loadConfig(resolveConfigPath(opts));
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
888
|
+
applyTerminalStyle(config.integration.tmux.badgeStyle);
|
|
889
|
+
const intervalSec = Number(opts.interval);
|
|
890
|
+
const intervalMs = Number.isFinite(intervalSec) && intervalSec > 0 ? intervalSec * 1000 : 2_000;
|
|
891
|
+
let agents = await requireDaemonSnapshot();
|
|
816
892
|
while (true) {
|
|
817
|
-
const now = Date.now();
|
|
818
|
-
const needsHeavy = lastHeavyAt === 0 || now - lastHeavyAt >= detailIntervalMs;
|
|
819
|
-
const agents = await scanAgents(config, {
|
|
820
|
-
enrichmentMode: needsHeavy ? "full" : "light",
|
|
821
|
-
});
|
|
822
|
-
if (needsHeavy)
|
|
823
|
-
lastHeavyAt = now;
|
|
824
893
|
clearScreen();
|
|
825
894
|
if (opts.json) {
|
|
826
895
|
await printStatusJson(agents);
|
|
@@ -829,6 +898,9 @@ program
|
|
|
829
898
|
await printStatus(agents);
|
|
830
899
|
}
|
|
831
900
|
await sleep(intervalMs);
|
|
901
|
+
agents = await getAgentsSnapshot();
|
|
902
|
+
if (agents.length === 0)
|
|
903
|
+
agents = []; // daemon stopped mid-loop
|
|
832
904
|
}
|
|
833
905
|
});
|
|
834
906
|
program
|
|
@@ -884,6 +956,55 @@ program
|
|
|
884
956
|
await addMarmonitorPlugin(confPath);
|
|
885
957
|
console.log("✓ Added marmonitor-tmux plugin to ~/.tmux.conf");
|
|
886
958
|
console.log("Press prefix+I inside tmux to activate.");
|
|
959
|
+
// Start daemon if not already running
|
|
960
|
+
await startDaemon();
|
|
961
|
+
});
|
|
962
|
+
program
|
|
963
|
+
.command("update-integration")
|
|
964
|
+
.description("Check how to sync the installed tmux integration")
|
|
965
|
+
.option("--quiet", "Suppress non-essential output")
|
|
966
|
+
.action(async (opts) => {
|
|
967
|
+
const { detectTmuxIntegrationMode, getMarmonitorPluginDir } = await import("./tmux/setup.js");
|
|
968
|
+
const { homedir } = await import("node:os");
|
|
969
|
+
const { join } = await import("node:path");
|
|
970
|
+
const confPath = join(homedir(), ".tmux.conf");
|
|
971
|
+
const pluginDir = getMarmonitorPluginDir();
|
|
972
|
+
const mode = await detectTmuxIntegrationMode(confPath, pluginDir);
|
|
973
|
+
if (mode === "local") {
|
|
974
|
+
if (!opts.quiet) {
|
|
975
|
+
console.log("Local marmonitor-tmux run-shell detected.");
|
|
976
|
+
console.log("Your local repo changes are already active after tmux reload.");
|
|
977
|
+
}
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
if (!mode) {
|
|
981
|
+
if (!opts.quiet) {
|
|
982
|
+
console.log("tmux integration is not configured. Run: marmonitor setup tmux");
|
|
983
|
+
}
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
if (mode === "missing") {
|
|
987
|
+
if (!opts.quiet) {
|
|
988
|
+
console.log("tmux integration is configured, but marmonitor-tmux is not installed yet.");
|
|
989
|
+
console.log("Press prefix+I in tmux to install the plugin.");
|
|
990
|
+
}
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
if (mode === "not_git") {
|
|
994
|
+
if (!opts.quiet) {
|
|
995
|
+
console.log("marmonitor-tmux exists but is not a git checkout.");
|
|
996
|
+
console.log(`Reinstall the plugin or update it manually: ${pluginDir}`);
|
|
997
|
+
}
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
if (!opts.quiet) {
|
|
1001
|
+
console.log("marmonitor-tmux TPM plugin detected.");
|
|
1002
|
+
console.log("Update path:");
|
|
1003
|
+
console.log(" 1. Press prefix+U in tmux");
|
|
1004
|
+
console.log(` 2. Or run: git -C ${pluginDir} pull --ff-only`);
|
|
1005
|
+
console.log(` 3. Re-apply the plugin in the running tmux server: tmux run-shell ${join(pluginDir, "marmonitor.tmux")}`);
|
|
1006
|
+
console.log(" 4. If the status bar still looks stale, reload tmux.conf or restart tmux");
|
|
1007
|
+
}
|
|
887
1008
|
});
|
|
888
1009
|
program
|
|
889
1010
|
.command("uninstall-integration")
|
|
@@ -900,6 +1021,8 @@ program
|
|
|
900
1021
|
else {
|
|
901
1022
|
console.log("No marmonitor settings found in ~/.tmux.conf");
|
|
902
1023
|
}
|
|
1024
|
+
// Stop daemon
|
|
1025
|
+
await stopDaemon();
|
|
903
1026
|
// Restore tmux memory state (status bar → 1 line, remove status-format[1])
|
|
904
1027
|
try {
|
|
905
1028
|
const { execFile: ef } = await import("node:child_process");
|
|
@@ -912,6 +1035,58 @@ program
|
|
|
912
1035
|
catch {
|
|
913
1036
|
console.log(" tmux not running — restart tmux to apply changes");
|
|
914
1037
|
}
|
|
1038
|
+
console.log("\nTo complete removal:");
|
|
1039
|
+
console.log(" $ npm uninstall -g marmonitor");
|
|
1040
|
+
console.log("\nOptional cleanup:");
|
|
1041
|
+
console.log(" $ rm -rf ~/.config/marmonitor # settings & session history");
|
|
1042
|
+
console.log(" $ rm -rf ~/.tmux/plugins/marmonitor-tmux # tpm plugin");
|
|
1043
|
+
});
|
|
1044
|
+
async function startDaemon() {
|
|
1045
|
+
if (await isDaemonRunning(DAEMON_PID_PATH)) {
|
|
1046
|
+
const pid = await readDaemonPid(DAEMON_PID_PATH);
|
|
1047
|
+
console.log(`Daemon already running (PID: ${pid})`);
|
|
1048
|
+
return undefined;
|
|
1049
|
+
}
|
|
1050
|
+
const { fork } = await import("node:child_process");
|
|
1051
|
+
const { fileURLToPath } = await import("node:url");
|
|
1052
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
1053
|
+
const child = fork(join(here, "..", "bin", "daemon.js"), [], { detached: true, stdio: "ignore" });
|
|
1054
|
+
child.unref();
|
|
1055
|
+
console.log(`✓ Daemon started (PID: ${child.pid})`);
|
|
1056
|
+
return child.pid ?? undefined;
|
|
1057
|
+
}
|
|
1058
|
+
async function stopDaemon() {
|
|
1059
|
+
const pid = await readDaemonPid(DAEMON_PID_PATH);
|
|
1060
|
+
if (!pid || !(await isDaemonRunning(DAEMON_PID_PATH))) {
|
|
1061
|
+
console.log("Daemon is not running.");
|
|
1062
|
+
return false;
|
|
1063
|
+
}
|
|
1064
|
+
process.kill(pid, "SIGTERM");
|
|
1065
|
+
console.log(`✓ Daemon stopped (PID: ${pid})`);
|
|
1066
|
+
return true;
|
|
1067
|
+
}
|
|
1068
|
+
program
|
|
1069
|
+
.command("start")
|
|
1070
|
+
.description("Start background scan daemon")
|
|
1071
|
+
.action(async () => {
|
|
1072
|
+
await startDaemon();
|
|
1073
|
+
process.exit(0);
|
|
1074
|
+
});
|
|
1075
|
+
program
|
|
1076
|
+
.command("stop")
|
|
1077
|
+
.description("Stop background scan daemon")
|
|
1078
|
+
.action(async () => {
|
|
1079
|
+
await stopDaemon();
|
|
1080
|
+
process.exit(0);
|
|
1081
|
+
});
|
|
1082
|
+
program
|
|
1083
|
+
.command("restart")
|
|
1084
|
+
.description("Restart background scan daemon")
|
|
1085
|
+
.action(async () => {
|
|
1086
|
+
await stopDaemon();
|
|
1087
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
1088
|
+
await startDaemon();
|
|
1089
|
+
process.exit(0);
|
|
915
1090
|
});
|
|
916
1091
|
installProcessSafetyHandlers();
|
|
917
1092
|
program.parse();
|
package/dist/config/index.d.ts
CHANGED
|
@@ -62,6 +62,7 @@ export interface MarmonitorConfig {
|
|
|
62
62
|
dockToggle: string;
|
|
63
63
|
directJump: string[];
|
|
64
64
|
};
|
|
65
|
+
badgeStyle: "basic" | "basic-mono" | "text" | "text-mono";
|
|
65
66
|
};
|
|
66
67
|
wezterm: {
|
|
67
68
|
enabled: boolean;
|
|
@@ -82,6 +83,7 @@ export interface MarmonitorConfig {
|
|
|
82
83
|
snapshotTtlMs: number;
|
|
83
84
|
statuslineTtlMs: number;
|
|
84
85
|
stdoutHeuristicTtlMs: number;
|
|
86
|
+
daemonIntervalSec: number;
|
|
85
87
|
};
|
|
86
88
|
}
|
|
87
89
|
/** Get config search paths in priority order */
|
package/dist/config/index.js
CHANGED
|
@@ -68,6 +68,7 @@ const DEFAULTS = {
|
|
|
68
68
|
dockToggle: "m",
|
|
69
69
|
directJump: ["M-1", "M-2", "M-3", "M-4", "M-5"],
|
|
70
70
|
},
|
|
71
|
+
badgeStyle: "basic",
|
|
71
72
|
},
|
|
72
73
|
wezterm: {
|
|
73
74
|
enabled: false,
|
|
@@ -88,6 +89,7 @@ const DEFAULTS = {
|
|
|
88
89
|
snapshotTtlMs: 2000,
|
|
89
90
|
statuslineTtlMs: 2000,
|
|
90
91
|
stdoutHeuristicTtlMs: 2000,
|
|
92
|
+
daemonIntervalSec: 2,
|
|
91
93
|
},
|
|
92
94
|
};
|
|
93
95
|
function cloneDefaults() {
|
|
@@ -0,0 +1,19 @@
|
|
|
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 interface BadgeTheme {
|
|
9
|
+
badge: string;
|
|
10
|
+
attention: string;
|
|
11
|
+
focus: string;
|
|
12
|
+
empty: string;
|
|
13
|
+
jumpBack: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const BADGE_THEMES: Record<string, BadgeTheme>;
|
|
16
|
+
export declare function renderBadge(theme: BadgeTheme, label: string, fg: string, bg: string): string;
|
|
17
|
+
export declare function renderAttention(theme: BadgeTheme, index: number, label: string, bg: string): string;
|
|
18
|
+
export declare function renderFocus(theme: BadgeTheme, text: string): string;
|
|
19
|
+
export declare function resolveTheme(style: string): BadgeTheme;
|
|
@@ -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
|
+
}
|