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.
Files changed (44) hide show
  1. package/README.ko.md +262 -0
  2. package/README.md +49 -5
  3. package/bin/daemon.js +2 -0
  4. package/bin/postinstall.cjs +47 -1
  5. package/bin/preuninstall.cjs +14 -0
  6. package/dist/banner/index.js +15 -7
  7. package/dist/cli.js +282 -107
  8. package/dist/config/index.d.ts +2 -0
  9. package/dist/config/index.js +2 -0
  10. package/dist/output/badge-themes.d.ts +19 -0
  11. package/dist/output/badge-themes.js +52 -0
  12. package/dist/output/index.d.ts +5 -2
  13. package/dist/output/index.js +69 -22
  14. package/dist/output/utils.d.ts +22 -8
  15. package/dist/output/utils.js +83 -48
  16. package/dist/scanner/claude.d.ts +8 -1
  17. package/dist/scanner/claude.js +156 -19
  18. package/dist/scanner/codex-sqlite.d.ts +11 -0
  19. package/dist/scanner/codex-sqlite.js +50 -0
  20. package/dist/scanner/codex.d.ts +1 -1
  21. package/dist/scanner/codex.js +42 -2
  22. package/dist/scanner/concurrency.d.ts +5 -0
  23. package/dist/scanner/concurrency.js +22 -0
  24. package/dist/scanner/daemon-entry.d.ts +5 -0
  25. package/dist/scanner/daemon-entry.js +27 -0
  26. package/dist/scanner/daemon-loop.d.ts +13 -0
  27. package/dist/scanner/daemon-loop.js +77 -0
  28. package/dist/scanner/daemon-utils.d.ts +9 -0
  29. package/dist/scanner/daemon-utils.js +56 -0
  30. package/dist/scanner/index.js +51 -10
  31. package/dist/scanner/perf.d.ts +8 -0
  32. package/dist/scanner/perf.js +26 -0
  33. package/dist/scanner/session-registry.d.ts +31 -0
  34. package/dist/scanner/session-registry.js +99 -0
  35. package/dist/scanner/session-tier.d.ts +6 -0
  36. package/dist/scanner/session-tier.js +22 -0
  37. package/dist/tmux/index.js +11 -0
  38. package/dist/tmux/jump-anchor.d.ts +25 -0
  39. package/dist/tmux/jump-anchor.js +100 -0
  40. package/dist/tmux/setup.d.ts +4 -0
  41. package/dist/tmux/setup.js +41 -1
  42. package/dist/tmux/status-click.d.ts +9 -0
  43. package/dist/tmux/status-click.js +19 -0
  44. package/package.json +1 -1
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Session activity tier classification.
3
+ * Determines enrichment frequency based on how recently a session was active.
4
+ */
5
+ const HOT_THRESHOLD_SEC = 120; // 2 minutes
6
+ const WARM_THRESHOLD_SEC = 600; // 10 minutes
7
+ const CPU_HOT_THRESHOLD = 1.0; // CPU% above this = always hot
8
+ const HOT_PHASES = new Set(["permission", "thinking", "tool"]);
9
+ export function classifySessionTier(lastActivityAt, nowSec, cpuPercent = 0, phase) {
10
+ if (cpuPercent >= CPU_HOT_THRESHOLD)
11
+ return "hot";
12
+ if (phase && HOT_PHASES.has(phase))
13
+ return "hot";
14
+ if (lastActivityAt === undefined)
15
+ return "cold";
16
+ const elapsed = nowSec - lastActivityAt;
17
+ if (elapsed <= HOT_THRESHOLD_SEC)
18
+ return "hot";
19
+ if (elapsed <= WARM_THRESHOLD_SEC)
20
+ return "warm";
21
+ return "cold";
22
+ }
@@ -1,5 +1,8 @@
1
1
  import { execFile } from "node:child_process";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
2
4
  import { promisify } from "node:util";
5
+ import { getClientTty, getCurrentTmuxLocation, saveJumpAnchorIfMissing } from "./jump-anchor.js";
3
6
  const execFileAsync = promisify(execFile);
4
7
  export function parseTmuxPanes(raw) {
5
8
  return raw
@@ -137,7 +140,15 @@ export async function jumpToTmuxPane(target) {
137
140
  return false;
138
141
  }
139
142
  }
143
+ const ANCHOR_PATH = join(tmpdir(), "marmonitor", "jump-anchors.json");
140
144
  export async function jumpToAgent(agent) {
145
+ // Save current location as jump-back anchor before jumping
146
+ if (process.env.TMUX) {
147
+ const [tty, location] = await Promise.all([getClientTty(), getCurrentTmuxLocation()]);
148
+ if (tty && location) {
149
+ await saveJumpAnchorIfMissing(ANCHOR_PATH, tty, location).catch(() => { });
150
+ }
151
+ }
141
152
  const target = await resolveTmuxJumpTarget(agent);
142
153
  if (!target) {
143
154
  return {
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Jump-back anchor management.
3
+ * Saves the current tmux pane location before jumping, so the user can return.
4
+ */
5
+ export interface JumpAnchorLocation {
6
+ session: string;
7
+ window: string;
8
+ pane: string;
9
+ }
10
+ export interface JumpAnchor extends JumpAnchorLocation {
11
+ savedAt: number;
12
+ }
13
+ export declare function saveJumpAnchor(anchorPath: string, clientTty: string, location: JumpAnchorLocation): Promise<void>;
14
+ export declare function saveJumpAnchorIfMissing(anchorPath: string, clientTty: string, location: JumpAnchorLocation): Promise<boolean>;
15
+ export declare function loadJumpAnchor(anchorPath: string, clientTty: string): Promise<JumpAnchor | undefined>;
16
+ export declare function clearJumpAnchor(anchorPath: string, clientTty: string): Promise<boolean>;
17
+ /** Get the current tmux pane location for the active client */
18
+ export declare function getCurrentTmuxLocation(): Promise<JumpAnchorLocation | undefined>;
19
+ /** Get the client tty of the current tmux client */
20
+ export declare function getClientTty(): Promise<string | undefined>;
21
+ /** Jump back to a saved anchor location */
22
+ export declare function jumpBack(anchorPath: string, clientTty: string): Promise<{
23
+ success: boolean;
24
+ message: string;
25
+ }>;
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Jump-back anchor management.
3
+ * Saves the current tmux pane location before jumping, so the user can return.
4
+ */
5
+ import { execFile } from "node:child_process";
6
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
7
+ import { dirname } from "node:path";
8
+ import { promisify } from "node:util";
9
+ const execFileAsync = promisify(execFile);
10
+ async function readAnchors(anchorPath) {
11
+ try {
12
+ const raw = await readFile(anchorPath, "utf-8");
13
+ return JSON.parse(raw);
14
+ }
15
+ catch {
16
+ return {};
17
+ }
18
+ }
19
+ async function writeAnchors(anchorPath, anchors) {
20
+ await mkdir(dirname(anchorPath), { recursive: true });
21
+ await writeFile(anchorPath, JSON.stringify(anchors, null, 2), "utf-8");
22
+ }
23
+ export async function saveJumpAnchor(anchorPath, clientTty, location) {
24
+ const anchors = await readAnchors(anchorPath);
25
+ anchors[clientTty] = { ...location, savedAt: Date.now() };
26
+ await writeAnchors(anchorPath, anchors);
27
+ }
28
+ export async function saveJumpAnchorIfMissing(anchorPath, clientTty, location) {
29
+ const anchors = await readAnchors(anchorPath);
30
+ if (anchors[clientTty])
31
+ return false;
32
+ anchors[clientTty] = { ...location, savedAt: Date.now() };
33
+ await writeAnchors(anchorPath, anchors);
34
+ return true;
35
+ }
36
+ export async function loadJumpAnchor(anchorPath, clientTty) {
37
+ try {
38
+ const anchors = await readAnchors(anchorPath);
39
+ return anchors[clientTty] ?? undefined;
40
+ }
41
+ catch {
42
+ return undefined;
43
+ }
44
+ }
45
+ export async function clearJumpAnchor(anchorPath, clientTty) {
46
+ const anchors = await readAnchors(anchorPath);
47
+ if (!anchors[clientTty])
48
+ return false;
49
+ delete anchors[clientTty];
50
+ await writeAnchors(anchorPath, anchors);
51
+ return true;
52
+ }
53
+ /** Get the current tmux pane location for the active client */
54
+ export async function getCurrentTmuxLocation() {
55
+ try {
56
+ const { stdout } = await execFileAsync("tmux", [
57
+ "display-message",
58
+ "-p",
59
+ "#{session_name}\t#{window_index}\t#{session_name}:#{window_index}.#{pane_index}",
60
+ ]);
61
+ const [session, window, pane] = stdout.trim().split("\t");
62
+ if (session && window && pane)
63
+ return { session, window, pane };
64
+ return undefined;
65
+ }
66
+ catch {
67
+ return undefined;
68
+ }
69
+ }
70
+ /** Get the client tty of the current tmux client */
71
+ export async function getClientTty() {
72
+ try {
73
+ const { stdout } = await execFileAsync("tmux", ["display-message", "-p", "#{client_tty}"]);
74
+ const tty = stdout.trim();
75
+ return tty || undefined;
76
+ }
77
+ catch {
78
+ return undefined;
79
+ }
80
+ }
81
+ /** Jump back to a saved anchor location */
82
+ export async function jumpBack(anchorPath, clientTty) {
83
+ const anchor = await loadJumpAnchor(anchorPath, clientTty);
84
+ if (!anchor) {
85
+ return { success: false, message: "No jump-back anchor found." };
86
+ }
87
+ try {
88
+ const windowTarget = `${anchor.session}:${anchor.window}`;
89
+ if (process.env.TMUX) {
90
+ await execFileAsync("tmux", ["switch-client", "-t", windowTarget]);
91
+ }
92
+ await execFileAsync("tmux", ["select-window", "-t", windowTarget]);
93
+ await execFileAsync("tmux", ["select-pane", "-t", anchor.pane]);
94
+ await clearJumpAnchor(anchorPath, clientTty).catch(() => { });
95
+ return { success: true, message: `Jumped back to ${anchor.pane}.` };
96
+ }
97
+ catch {
98
+ return { success: false, message: `Failed to jump back to ${anchor.pane}.` };
99
+ }
100
+ }
@@ -2,6 +2,10 @@
2
2
  * tmux.conf plugin line management.
3
3
  * Adds/removes the marmonitor-tmux tpm plugin line.
4
4
  */
5
+ export type TmuxIntegrationMode = "local" | "tpm" | "missing" | "not_git";
6
+ export declare function getMarmonitorPluginDir(home?: string): string;
7
+ export declare function hasInstalledMarmonitorPlugin(pluginDir: string): Promise<boolean>;
8
+ export declare function detectTmuxIntegrationMode(confPath: string, pluginDir: string): Promise<TmuxIntegrationMode | undefined>;
5
9
  export declare function hasMarmonitorPlugin(confPath: string): Promise<boolean>;
6
10
  export declare function addMarmonitorPlugin(confPath: string): Promise<boolean>;
7
11
  export declare function removeMarmonitorPlugin(confPath: string): Promise<boolean>;
@@ -2,11 +2,51 @@
2
2
  * tmux.conf plugin line management.
3
3
  * Adds/removes the marmonitor-tmux tpm plugin line.
4
4
  */
5
- import { readFile, writeFile } from "node:fs/promises";
5
+ import { constants } from "node:fs";
6
+ import { access, readFile, writeFile } from "node:fs/promises";
7
+ import { homedir } from "node:os";
8
+ import { join } from "node:path";
6
9
  const PLUGIN_LINE = "set -g @plugin 'mjjo16/marmonitor-tmux'";
7
10
  function matchesPluginLine(line) {
8
11
  return line.trim() === PLUGIN_LINE;
9
12
  }
13
+ export function getMarmonitorPluginDir(home = homedir()) {
14
+ return join(home, ".tmux", "plugins", "marmonitor-tmux");
15
+ }
16
+ export async function hasInstalledMarmonitorPlugin(pluginDir) {
17
+ try {
18
+ await access(join(pluginDir, "marmonitor.tmux"), constants.F_OK);
19
+ return true;
20
+ }
21
+ catch {
22
+ return false;
23
+ }
24
+ }
25
+ export async function detectTmuxIntegrationMode(confPath, pluginDir) {
26
+ let content = "";
27
+ if (!(await hasInstalledMarmonitorPlugin(pluginDir))) {
28
+ try {
29
+ content = await readFile(confPath, "utf-8");
30
+ }
31
+ catch {
32
+ return undefined;
33
+ }
34
+ if (content.includes("marmonitor-tmux/marmonitor.tmux")) {
35
+ return "local";
36
+ }
37
+ if (content.split("\n").some(matchesPluginLine)) {
38
+ return "missing";
39
+ }
40
+ return undefined;
41
+ }
42
+ try {
43
+ await access(join(pluginDir, ".git"), constants.F_OK);
44
+ return "tpm";
45
+ }
46
+ catch {
47
+ return "not_git";
48
+ }
49
+ }
10
50
  export async function hasMarmonitorPlugin(confPath) {
11
51
  try {
12
52
  const content = await readFile(confPath, "utf-8");
@@ -0,0 +1,9 @@
1
+ import type { AgentSession } from "../types.js";
2
+ export type StatusClickAction = {
3
+ kind: "jump";
4
+ pid: number;
5
+ } | {
6
+ kind: "jump-back";
7
+ };
8
+ export declare function parseStatusClickToken(token?: string): StatusClickAction | undefined;
9
+ export declare function findClickedAgent(sessions: AgentSession[], action: StatusClickAction): AgentSession | undefined;
@@ -0,0 +1,19 @@
1
+ export function parseStatusClickToken(token) {
2
+ if (!token)
3
+ return undefined;
4
+ const trimmed = token.trim();
5
+ if (trimmed === "jump-back")
6
+ return { kind: "jump-back" };
7
+ const pidMatch = /^pid:(\d+)$/.exec(trimmed);
8
+ if (!pidMatch)
9
+ return undefined;
10
+ const pid = Number.parseInt(pidMatch[1] ?? "", 10);
11
+ if (!Number.isFinite(pid))
12
+ return undefined;
13
+ return { kind: "jump", pid };
14
+ }
15
+ export function findClickedAgent(sessions, action) {
16
+ if (action.kind !== "jump")
17
+ return undefined;
18
+ return sessions.find((session) => session.pid === action.pid);
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marmonitor",
3
- "version": "0.1.7",
3
+ "version": "0.2.2",
4
4
  "author": "MJ JO <mjjo16@gmail.com>",
5
5
  "description": "tmux status bar monitor for AI coding agents — track Claude Code, Codex, Gemini sessions, tokens, and phases in real time",
6
6
  "type": "module",