marmonitor 0.1.6 ā 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ko.md +248 -0
- package/README.md +41 -5
- package/bin/daemon.js +2 -0
- package/bin/postinstall.cjs +75 -0
- package/bin/preuninstall.cjs +14 -0
- package/dist/banner/index.js +15 -7
- package/dist/cli.js +297 -110
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +5 -3
- package/dist/output/badge-themes.d.ts +19 -0
- package/dist/output/badge-themes.js +52 -0
- package/dist/output/index.d.ts +5 -2
- package/dist/output/index.js +69 -22
- package/dist/output/utils.d.ts +23 -9
- package/dist/output/utils.js +85 -48
- package/dist/scanner/claude.d.ts +8 -1
- package/dist/scanner/claude.js +156 -19
- package/dist/scanner/codex-sqlite.d.ts +11 -0
- package/dist/scanner/codex-sqlite.js +50 -0
- package/dist/scanner/codex.d.ts +1 -1
- package/dist/scanner/codex.js +42 -2
- package/dist/scanner/concurrency.d.ts +5 -0
- package/dist/scanner/concurrency.js +22 -0
- package/dist/scanner/daemon-entry.d.ts +5 -0
- package/dist/scanner/daemon-entry.js +27 -0
- package/dist/scanner/daemon-loop.d.ts +13 -0
- package/dist/scanner/daemon-loop.js +77 -0
- package/dist/scanner/daemon-utils.d.ts +9 -0
- package/dist/scanner/daemon-utils.js +56 -0
- package/dist/scanner/gemini.js +3 -1
- package/dist/scanner/index.js +51 -10
- package/dist/scanner/perf.d.ts +8 -0
- package/dist/scanner/perf.js +26 -0
- package/dist/scanner/session-registry.d.ts +31 -0
- package/dist/scanner/session-registry.js +99 -0
- package/dist/scanner/session-tier.d.ts +6 -0
- package/dist/scanner/session-tier.js +22 -0
- package/dist/tmux/index.js +11 -0
- package/dist/tmux/jump-anchor.d.ts +25 -0
- package/dist/tmux/jump-anchor.js +100 -0
- package/dist/tmux/setup.d.ts +4 -0
- package/dist/tmux/setup.js +41 -1
- package/dist/tmux/status-click.d.ts +9 -0
- package/dist/tmux/status-click.js +19 -0
- package/package.json +2 -2
- package/bin/postinstall.js +0 -20
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));
|
|
@@ -97,6 +100,25 @@ function buildHelpAppendix() {
|
|
|
97
100
|
" performance Snapshot/cache TTL tuning",
|
|
98
101
|
" intervention Guard and policy rules (advanced / optional)",
|
|
99
102
|
"",
|
|
103
|
+
"Phase icons:",
|
|
104
|
+
" ā³ permission Waiting for tool approval (user input needed)",
|
|
105
|
+
" š¤ thinking AI generating response",
|
|
106
|
+
" š§ tool Approved tool executing",
|
|
107
|
+
" ā
done Response complete",
|
|
108
|
+
"",
|
|
109
|
+
"Status labels:",
|
|
110
|
+
" [Active] CPU activity detected",
|
|
111
|
+
" [Idle] Process alive, no recent activity",
|
|
112
|
+
" [Stalled] No activity for extended period",
|
|
113
|
+
" [Dead] Session file exists but process gone",
|
|
114
|
+
" [Unmatched] AI process without matching session",
|
|
115
|
+
"",
|
|
116
|
+
"Common settings:",
|
|
117
|
+
" display.attentionLimit / display.statuslineAttentionLimit",
|
|
118
|
+
" integration.tmux.badgeStyle",
|
|
119
|
+
" integration.tmux.keys.*",
|
|
120
|
+
" paths.* (runtime data path overrides)",
|
|
121
|
+
"",
|
|
100
122
|
"Default tmux shortcuts:",
|
|
101
123
|
" Prefix+a Attention popup",
|
|
102
124
|
" Prefix+j Jump popup",
|
|
@@ -118,12 +140,16 @@ function clearScreen() {
|
|
|
118
140
|
process.stdout.write("\x1Bc");
|
|
119
141
|
}
|
|
120
142
|
}
|
|
121
|
-
async function
|
|
143
|
+
async function promptSelectionAction(maxChoice, currentPage = 1, totalPages = 1) {
|
|
122
144
|
if (!process.stdin.isTTY || maxChoice < 1)
|
|
123
145
|
return undefined;
|
|
124
|
-
const prompt =
|
|
125
|
-
?
|
|
126
|
-
|
|
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: `;
|
|
127
153
|
process.stdout.write(prompt);
|
|
128
154
|
return await new Promise((resolve) => {
|
|
129
155
|
const stdin = process.stdin;
|
|
@@ -141,23 +167,10 @@ async function promptSelectionKey(maxChoice) {
|
|
|
141
167
|
cleanup();
|
|
142
168
|
exitWithCleanup(130);
|
|
143
169
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
resolve(undefined);
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
const trimmed = input.trim();
|
|
150
|
-
if (/^[1-9]$/.test(trimmed)) {
|
|
151
|
-
const selection = Number.parseInt(trimmed, 10);
|
|
152
|
-
if (selection <= maxChoice) {
|
|
153
|
-
cleanup();
|
|
154
|
-
resolve(selection);
|
|
155
|
-
}
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
if (trimmed === "0" && maxChoice >= 10) {
|
|
170
|
+
const action = parseSelectionInput(input, maxChoice, currentPage, totalPages);
|
|
171
|
+
if (action) {
|
|
159
172
|
cleanup();
|
|
160
|
-
resolve(
|
|
173
|
+
resolve(action);
|
|
161
174
|
}
|
|
162
175
|
};
|
|
163
176
|
if (restoreRawMode)
|
|
@@ -228,6 +241,7 @@ function buildMinimalConfigSample() {
|
|
|
228
241
|
},
|
|
229
242
|
integration: {
|
|
230
243
|
tmux: {
|
|
244
|
+
badgeStyle: "basic",
|
|
231
245
|
keys: {
|
|
232
246
|
attentionPopup: "a",
|
|
233
247
|
jumpPopup: "j",
|
|
@@ -259,6 +273,7 @@ function buildAdvancedConfigSample() {
|
|
|
259
273
|
},
|
|
260
274
|
integration: {
|
|
261
275
|
tmux: {
|
|
276
|
+
badgeStyle: "basic",
|
|
262
277
|
keys: {
|
|
263
278
|
attentionPopup: "a",
|
|
264
279
|
jumpPopup: "j",
|
|
@@ -375,9 +390,6 @@ function statuslineCacheFile(format, attentionLimit, width) {
|
|
|
375
390
|
const widthKey = width && width > 0 ? String(width) : "auto";
|
|
376
391
|
return join(tmpdir(), "marmonitor", `statusline-${format}-${attentionLimit}-${widthKey}.txt`);
|
|
377
392
|
}
|
|
378
|
-
function snapshotCacheFile(enrichmentMode, showDead) {
|
|
379
|
-
return join(tmpdir(), "marmonitor", `snapshot-${enrichmentMode}-${showDead ? "dead" : "alive"}.json`);
|
|
380
|
-
}
|
|
381
393
|
async function readCachedStatusline(format, attentionLimit, width, ttlMs) {
|
|
382
394
|
const path = statuslineCacheFile(format, attentionLimit, width);
|
|
383
395
|
try {
|
|
@@ -400,40 +412,18 @@ async function writeCachedStatusline(format, attentionLimit, width, value) {
|
|
|
400
412
|
// cache failures must never break statusline rendering
|
|
401
413
|
}
|
|
402
414
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
return JSON.parse(await readFile(path, "utf-8"));
|
|
410
|
-
}
|
|
411
|
-
catch {
|
|
412
|
-
return undefined;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
async function writeCachedSnapshot(enrichmentMode, showDead, agents) {
|
|
416
|
-
const path = snapshotCacheFile(enrichmentMode, showDead);
|
|
417
|
-
try {
|
|
418
|
-
await mkdir(join(tmpdir(), "marmonitor"), { recursive: true });
|
|
419
|
-
await writeFile(path, JSON.stringify(agents), "utf-8");
|
|
420
|
-
}
|
|
421
|
-
catch {
|
|
422
|
-
// snapshot cache failures must never break command execution
|
|
423
|
-
}
|
|
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));
|
|
424
421
|
}
|
|
425
|
-
async function
|
|
426
|
-
const
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
const cached = await readCachedSnapshot(enrichmentMode, config.display.showDead, ttlMs);
|
|
431
|
-
if (cached)
|
|
432
|
-
return cached;
|
|
433
|
-
}
|
|
434
|
-
const agents = await scanAgents(config, { enrichmentMode });
|
|
435
|
-
if (useCache) {
|
|
436
|
-
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);
|
|
437
427
|
}
|
|
438
428
|
return agents;
|
|
439
429
|
}
|
|
@@ -462,8 +452,23 @@ program
|
|
|
462
452
|
console.log(cached);
|
|
463
453
|
return;
|
|
464
454
|
}
|
|
465
|
-
const agents = await getAgentsSnapshot(
|
|
466
|
-
|
|
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);
|
|
467
472
|
await writeCachedStatusline(opts.statuslineFormat, attentionLimit, width, rendered);
|
|
468
473
|
console.log(rendered);
|
|
469
474
|
return;
|
|
@@ -480,17 +485,29 @@ program
|
|
|
480
485
|
.description("Show current AI agent status")
|
|
481
486
|
.option("--json", "Output as JSON")
|
|
482
487
|
.option("--config <path>", "Path to settings.json")
|
|
483
|
-
.option("--show-dead", "Include dead sessions")
|
|
484
488
|
.action(async (opts) => {
|
|
489
|
+
const agents = await requireDaemonSnapshot();
|
|
485
490
|
const config = await loadConfig(resolveConfigPath(opts));
|
|
486
|
-
|
|
487
|
-
config.display.showDead = true;
|
|
488
|
-
const agents = await getAgentsSnapshot(config, { enrichmentMode: "full" });
|
|
491
|
+
applyTerminalStyle(config.integration.tmux.badgeStyle);
|
|
489
492
|
if (opts.json) {
|
|
490
493
|
await printStatusJson(agents);
|
|
491
494
|
}
|
|
492
495
|
else {
|
|
493
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
|
+
}
|
|
494
511
|
}
|
|
495
512
|
});
|
|
496
513
|
program
|
|
@@ -501,8 +518,9 @@ program
|
|
|
501
518
|
.option("--limit <n>", "Max items to show", "12")
|
|
502
519
|
.option("--config <path>", "Path to settings.json")
|
|
503
520
|
.action(async (opts) => {
|
|
521
|
+
const agents = await requireDaemonSnapshot();
|
|
504
522
|
const config = await loadConfig(resolveConfigPath(opts));
|
|
505
|
-
|
|
523
|
+
applyTerminalStyle(config.integration.tmux.badgeStyle);
|
|
506
524
|
const limit = resolveAttentionLimit(opts, config.display.attentionLimit);
|
|
507
525
|
const interactiveLimit = resolveAttentionLimit(opts, config.display.attentionLimit, true);
|
|
508
526
|
if (opts.interactive && opts.json) {
|
|
@@ -514,13 +532,30 @@ program
|
|
|
514
532
|
console.error("--interactive requires an interactive terminal.");
|
|
515
533
|
process.exit(1);
|
|
516
534
|
}
|
|
517
|
-
|
|
518
|
-
const
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
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
|
+
}
|
|
522
557
|
if (!item) {
|
|
523
|
-
console.error(
|
|
558
|
+
console.error("Invalid selection.");
|
|
524
559
|
process.exit(1);
|
|
525
560
|
}
|
|
526
561
|
const agent = agents.find((candidate) => candidate.pid === item.pid);
|
|
@@ -680,8 +715,8 @@ program
|
|
|
680
715
|
.option("--json", "Output as JSON")
|
|
681
716
|
.option("--config <path>", "Path to settings.json")
|
|
682
717
|
.action(async (opts) => {
|
|
718
|
+
const agents = await requireDaemonSnapshot();
|
|
683
719
|
const config = await loadConfig(resolveConfigPath(opts));
|
|
684
|
-
const agents = await getAgentsSnapshot(config, { enrichmentMode: "full" });
|
|
685
720
|
const useAttention = Boolean(opts.attention);
|
|
686
721
|
const useAttentionIndex = typeof opts.attentionIndex === "string";
|
|
687
722
|
const usePid = typeof opts.pid === "string";
|
|
@@ -697,13 +732,30 @@ program
|
|
|
697
732
|
process.exit(1);
|
|
698
733
|
}
|
|
699
734
|
const limit = resolveAttentionLimit({ limit: undefined }, config.display.attentionLimit, true);
|
|
700
|
-
|
|
701
|
-
const
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
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
|
+
}
|
|
705
757
|
if (!item) {
|
|
706
|
-
console.error(
|
|
758
|
+
console.error("Invalid selection.");
|
|
707
759
|
process.exit(1);
|
|
708
760
|
}
|
|
709
761
|
pid = item.pid;
|
|
@@ -755,59 +807,89 @@ program
|
|
|
755
807
|
if (!result.found)
|
|
756
808
|
process.exit(1);
|
|
757
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
|
+
});
|
|
758
859
|
program
|
|
759
860
|
.command("dock")
|
|
760
861
|
.description("Compact persistent monitor for tmux pane")
|
|
761
|
-
.option("--interval <sec>", "Refresh interval in seconds", "
|
|
762
|
-
.option("--detail-interval <sec>", "Heavy enrichment interval", "30")
|
|
862
|
+
.option("--interval <sec>", "Refresh interval in seconds", "2")
|
|
763
863
|
.option("--lines <n>", "Max display lines", "12")
|
|
764
864
|
.option("--config <path>", "Path to settings.json")
|
|
765
865
|
.action(async (opts) => {
|
|
766
|
-
const intervalMs = Math.max(Number(opts.interval) || 5, 2) * 1000;
|
|
767
|
-
const detailMs = Math.max(Number(opts.detailInterval) || 30, 5) * 1000;
|
|
768
|
-
const maxLines = Number(opts.lines) || 12;
|
|
769
866
|
const config = await loadConfig(resolveConfigPath(opts));
|
|
770
|
-
|
|
867
|
+
applyTerminalStyle(config.integration.tmux.badgeStyle);
|
|
868
|
+
const intervalMs = Math.max(Number(opts.interval) || 2, 2) * 1000;
|
|
869
|
+
const maxLines = Number(opts.lines) || 12;
|
|
870
|
+
let agents = await requireDaemonSnapshot();
|
|
771
871
|
while (true) {
|
|
772
|
-
const now = Date.now();
|
|
773
|
-
const needsHeavy = lastHeavyAt === 0 || now - lastHeavyAt >= detailMs;
|
|
774
|
-
const agents = await scanAgents(config, {
|
|
775
|
-
enrichmentMode: needsHeavy ? "full" : "light",
|
|
776
|
-
});
|
|
777
|
-
if (needsHeavy)
|
|
778
|
-
lastHeavyAt = now;
|
|
779
872
|
clearScreen();
|
|
780
873
|
await printDock(agents, maxLines);
|
|
781
874
|
await sleep(intervalMs);
|
|
875
|
+
agents = await getAgentsSnapshot();
|
|
876
|
+
if (agents.length === 0)
|
|
877
|
+
agents = []; // daemon stopped mid-loop
|
|
782
878
|
}
|
|
783
879
|
});
|
|
784
880
|
program
|
|
785
881
|
.command("watch")
|
|
786
882
|
.description("Refresh agent status in a long-lived loop")
|
|
787
|
-
.option("--interval <sec>", "Refresh interval in seconds", "
|
|
788
|
-
.option("--detail-interval <sec>", "Heavy enrichment refresh interval in seconds", "30")
|
|
883
|
+
.option("--interval <sec>", "Refresh interval in seconds", "2")
|
|
789
884
|
.option("--json", "Output as JSON")
|
|
790
885
|
.option("--config <path>", "Path to settings.json")
|
|
791
|
-
.option("--show-dead", "Include dead sessions")
|
|
792
886
|
.action(async (opts) => {
|
|
793
|
-
const intervalSec = Number(opts.interval);
|
|
794
|
-
const detailIntervalSec = Number(opts.detailInterval);
|
|
795
|
-
const intervalMs = Number.isFinite(intervalSec) && intervalSec > 0 ? intervalSec * 1000 : 10_000;
|
|
796
|
-
const detailIntervalMs = Number.isFinite(detailIntervalSec) && detailIntervalSec > 0
|
|
797
|
-
? detailIntervalSec * 1000
|
|
798
|
-
: 30_000;
|
|
799
887
|
const config = await loadConfig(resolveConfigPath(opts));
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
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();
|
|
803
892
|
while (true) {
|
|
804
|
-
const now = Date.now();
|
|
805
|
-
const needsHeavy = lastHeavyAt === 0 || now - lastHeavyAt >= detailIntervalMs;
|
|
806
|
-
const agents = await scanAgents(config, {
|
|
807
|
-
enrichmentMode: needsHeavy ? "full" : "light",
|
|
808
|
-
});
|
|
809
|
-
if (needsHeavy)
|
|
810
|
-
lastHeavyAt = now;
|
|
811
893
|
clearScreen();
|
|
812
894
|
if (opts.json) {
|
|
813
895
|
await printStatusJson(agents);
|
|
@@ -816,6 +898,9 @@ program
|
|
|
816
898
|
await printStatus(agents);
|
|
817
899
|
}
|
|
818
900
|
await sleep(intervalMs);
|
|
901
|
+
agents = await getAgentsSnapshot();
|
|
902
|
+
if (agents.length === 0)
|
|
903
|
+
agents = []; // daemon stopped mid-loop
|
|
819
904
|
}
|
|
820
905
|
});
|
|
821
906
|
program
|
|
@@ -871,6 +956,54 @@ program
|
|
|
871
956
|
await addMarmonitorPlugin(confPath);
|
|
872
957
|
console.log("ā Added marmonitor-tmux plugin to ~/.tmux.conf");
|
|
873
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. Reload tmux if keybindings or popup sizing changed");
|
|
1006
|
+
}
|
|
874
1007
|
});
|
|
875
1008
|
program
|
|
876
1009
|
.command("uninstall-integration")
|
|
@@ -887,6 +1020,8 @@ program
|
|
|
887
1020
|
else {
|
|
888
1021
|
console.log("No marmonitor settings found in ~/.tmux.conf");
|
|
889
1022
|
}
|
|
1023
|
+
// Stop daemon
|
|
1024
|
+
await stopDaemon();
|
|
890
1025
|
// Restore tmux memory state (status bar ā 1 line, remove status-format[1])
|
|
891
1026
|
try {
|
|
892
1027
|
const { execFile: ef } = await import("node:child_process");
|
|
@@ -899,6 +1034,58 @@ program
|
|
|
899
1034
|
catch {
|
|
900
1035
|
console.log(" tmux not running ā restart tmux to apply changes");
|
|
901
1036
|
}
|
|
1037
|
+
console.log("\nTo complete removal:");
|
|
1038
|
+
console.log(" $ npm uninstall -g marmonitor");
|
|
1039
|
+
console.log("\nOptional cleanup:");
|
|
1040
|
+
console.log(" $ rm -rf ~/.config/marmonitor # settings & session history");
|
|
1041
|
+
console.log(" $ rm -rf ~/.tmux/plugins/marmonitor-tmux # tpm plugin");
|
|
1042
|
+
});
|
|
1043
|
+
async function startDaemon() {
|
|
1044
|
+
if (await isDaemonRunning(DAEMON_PID_PATH)) {
|
|
1045
|
+
const pid = await readDaemonPid(DAEMON_PID_PATH);
|
|
1046
|
+
console.log(`Daemon already running (PID: ${pid})`);
|
|
1047
|
+
return undefined;
|
|
1048
|
+
}
|
|
1049
|
+
const { fork } = await import("node:child_process");
|
|
1050
|
+
const { fileURLToPath } = await import("node:url");
|
|
1051
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
1052
|
+
const child = fork(join(here, "..", "bin", "daemon.js"), [], { detached: true, stdio: "ignore" });
|
|
1053
|
+
child.unref();
|
|
1054
|
+
console.log(`ā Daemon started (PID: ${child.pid})`);
|
|
1055
|
+
return child.pid ?? undefined;
|
|
1056
|
+
}
|
|
1057
|
+
async function stopDaemon() {
|
|
1058
|
+
const pid = await readDaemonPid(DAEMON_PID_PATH);
|
|
1059
|
+
if (!pid || !(await isDaemonRunning(DAEMON_PID_PATH))) {
|
|
1060
|
+
console.log("Daemon is not running.");
|
|
1061
|
+
return false;
|
|
1062
|
+
}
|
|
1063
|
+
process.kill(pid, "SIGTERM");
|
|
1064
|
+
console.log(`ā Daemon stopped (PID: ${pid})`);
|
|
1065
|
+
return true;
|
|
1066
|
+
}
|
|
1067
|
+
program
|
|
1068
|
+
.command("start")
|
|
1069
|
+
.description("Start background scan daemon")
|
|
1070
|
+
.action(async () => {
|
|
1071
|
+
await startDaemon();
|
|
1072
|
+
process.exit(0);
|
|
1073
|
+
});
|
|
1074
|
+
program
|
|
1075
|
+
.command("stop")
|
|
1076
|
+
.description("Stop background scan daemon")
|
|
1077
|
+
.action(async () => {
|
|
1078
|
+
await stopDaemon();
|
|
1079
|
+
process.exit(0);
|
|
1080
|
+
});
|
|
1081
|
+
program
|
|
1082
|
+
.command("restart")
|
|
1083
|
+
.description("Restart background scan daemon")
|
|
1084
|
+
.action(async () => {
|
|
1085
|
+
await stopDaemon();
|
|
1086
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
1087
|
+
await startDaemon();
|
|
1088
|
+
process.exit(0);
|
|
902
1089
|
});
|
|
903
1090
|
installProcessSafetyHandlers();
|
|
904
1091
|
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,
|
|
@@ -85,9 +86,10 @@ const DEFAULTS = {
|
|
|
85
86
|
extraRoots: [],
|
|
86
87
|
},
|
|
87
88
|
performance: {
|
|
88
|
-
snapshotTtlMs:
|
|
89
|
-
statuslineTtlMs:
|
|
90
|
-
stdoutHeuristicTtlMs:
|
|
89
|
+
snapshotTtlMs: 2000,
|
|
90
|
+
statuslineTtlMs: 2000,
|
|
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;
|