marmonitor 0.1.5 → 0.1.7

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.
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * postinstall script — show install guide.
5
+ * Runs after `npm install -g marmonitor`.
6
+ *
7
+ * npm suppresses stdout from postinstall scripts by default.
8
+ * Using stderr to ensure the message is always visible.
9
+ */
10
+
11
+ const msg = `
12
+ ✓ marmonitor v${require("../package.json").version} installed
13
+ Monitor Claude Code, Codex & Gemini sessions from your tmux status bar.
14
+
15
+ Setup:
16
+ $ marmonitor setup tmux Add tmux plugin to ~/.tmux.conf
17
+ Then press prefix+I in tmux to activate.
18
+
19
+ Commands:
20
+ $ marmonitor status Show all AI sessions
21
+ $ marmonitor attention Sessions needing your input
22
+ $ marmonitor help All commands and shortcuts
23
+
24
+ Uninstall:
25
+ $ marmonitor uninstall-integration
26
+ $ npm uninstall -g marmonitor
27
+ `;
28
+
29
+ process.stderr.write(msg + "\n");
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * preuninstall script — remove marmonitor plugin line from tmux.conf.
5
+ * Runs before `npm uninstall -g marmonitor`.
6
+ *
7
+ * Uses only CommonJS-compatible built-ins (no ESM import).
8
+ * Must never fail — errors are silently ignored.
9
+ */
10
+
11
+ try {
12
+ const fs = require("fs");
13
+ const path = require("path");
14
+ const os = require("os");
15
+
16
+ const PLUGIN_LINE = "set -g @plugin 'mjjo16/marmonitor-tmux'";
17
+ const confPath = path.join(os.homedir(), ".tmux.conf");
18
+
19
+ const content = fs.readFileSync(confPath, "utf-8");
20
+ const lines = content.split("\n");
21
+ const filtered = lines.filter((line) => line.trim() !== PLUGIN_LINE);
22
+
23
+ if (filtered.length < lines.length) {
24
+ fs.writeFileSync(confPath, filtered.join("\n"), "utf-8");
25
+ console.log(" marmonitor: removed tmux plugin line from ~/.tmux.conf");
26
+ }
27
+ } catch {
28
+ // silent — preuninstall must never block npm uninstall
29
+ }
package/dist/cli.js CHANGED
@@ -97,6 +97,19 @@ function buildHelpAppendix() {
97
97
  " performance Snapshot/cache TTL tuning",
98
98
  " intervention Guard and policy rules (advanced / optional)",
99
99
  "",
100
+ "Phase icons:",
101
+ " ⏳ permission Waiting for tool approval (user input needed)",
102
+ " 🤔 thinking AI generating response",
103
+ " 🔧 tool Approved tool executing",
104
+ " ✅ done Response complete",
105
+ "",
106
+ "Status labels:",
107
+ " [Active] CPU activity detected",
108
+ " [Idle] Process alive, no recent activity",
109
+ " [Stalled] No activity for extended period",
110
+ " [Dead] Session file exists but process gone",
111
+ " [Unmatched] AI process without matching session",
112
+ "",
100
113
  "Default tmux shortcuts:",
101
114
  " Prefix+a Attention popup",
102
115
  " Prefix+j Jump popup",
@@ -758,12 +771,12 @@ program
758
771
  program
759
772
  .command("dock")
760
773
  .description("Compact persistent monitor for tmux pane")
761
- .option("--interval <sec>", "Refresh interval in seconds", "5")
774
+ .option("--interval <sec>", "Refresh interval in seconds", "2")
762
775
  .option("--detail-interval <sec>", "Heavy enrichment interval", "30")
763
776
  .option("--lines <n>", "Max display lines", "12")
764
777
  .option("--config <path>", "Path to settings.json")
765
778
  .action(async (opts) => {
766
- const intervalMs = Math.max(Number(opts.interval) || 5, 2) * 1000;
779
+ const intervalMs = Math.max(Number(opts.interval) || 2, 2) * 1000;
767
780
  const detailMs = Math.max(Number(opts.detailInterval) || 30, 5) * 1000;
768
781
  const maxLines = Number(opts.lines) || 12;
769
782
  const config = await loadConfig(resolveConfigPath(opts));
@@ -784,7 +797,7 @@ program
784
797
  program
785
798
  .command("watch")
786
799
  .description("Refresh agent status in a long-lived loop")
787
- .option("--interval <sec>", "Refresh interval in seconds", "10")
800
+ .option("--interval <sec>", "Refresh interval in seconds", "2")
788
801
  .option("--detail-interval <sec>", "Heavy enrichment refresh interval in seconds", "30")
789
802
  .option("--json", "Output as JSON")
790
803
  .option("--config <path>", "Path to settings.json")
@@ -887,6 +900,18 @@ program
887
900
  else {
888
901
  console.log("No marmonitor settings found in ~/.tmux.conf");
889
902
  }
903
+ // Restore tmux memory state (status bar → 1 line, remove status-format[1])
904
+ try {
905
+ const { execFile: ef } = await import("node:child_process");
906
+ const { promisify: p } = await import("node:util");
907
+ const exec = p(ef);
908
+ await exec("tmux", ["set", "-g", "status", "on"]);
909
+ await exec("tmux", ["set", "-gu", "status-format[1]"]);
910
+ console.log("✓ Restored tmux status bar to single line");
911
+ }
912
+ catch {
913
+ console.log(" tmux not running — restart tmux to apply changes");
914
+ }
890
915
  });
891
916
  installProcessSafetyHandlers();
892
917
  program.parse();
@@ -85,9 +85,9 @@ const DEFAULTS = {
85
85
  extraRoots: [],
86
86
  },
87
87
  performance: {
88
- snapshotTtlMs: 5000,
89
- statuslineTtlMs: 5000,
90
- stdoutHeuristicTtlMs: 5000,
88
+ snapshotTtlMs: 2000,
89
+ statuslineTtlMs: 2000,
90
+ stdoutHeuristicTtlMs: 2000,
91
91
  },
92
92
  };
93
93
  function cloneDefaults() {
@@ -108,7 +108,7 @@ export interface SessionFileCandidate {
108
108
  }
109
109
  export declare function resolvePhaseWithDecay(currentPhase: SessionPhase, cachedPhase: SessionPhase, cachedDetectedAtMs: number | undefined, decay: PhaseDecayConfig, nowMs?: number): SessionPhase;
110
110
  export declare function advanceJsonlCursor(previous: JsonlCursorState, chunk: string, maxLines: number): JsonlCursorState;
111
- export declare function detectApprovalPromptPhase(output: string, patterns?: string[], clearPatterns?: string[]): SessionPhase;
111
+ export declare function detectApprovalPromptPhase(output: unknown, patterns?: string[], clearPatterns?: string[]): SessionPhase;
112
112
  export declare function updatePhaseHistory(previousPhase: SessionPhase, previousHistory: PhaseHistoryEntry[], nextPhase: SessionPhase, at: number, maxEntries?: number): {
113
113
  previousPhase?: SessionPhase;
114
114
  history: PhaseHistoryEntry[];
@@ -186,6 +186,8 @@ export function detectApprovalPromptPhase(output, patterns = [
186
186
  "edited",
187
187
  "changes applied",
188
188
  ]) {
189
+ if (!output || typeof output !== "string")
190
+ return undefined;
189
191
  const recentLines = output
190
192
  .split("\n")
191
193
  .map((line) => line.trim())
@@ -14,7 +14,9 @@ export function toEpochSec(value) {
14
14
  export function parseGeminiSessionContent(raw) {
15
15
  try {
16
16
  const data = JSON.parse(raw);
17
- const messages = Array.isArray(data.messages) ? data.messages : [];
17
+ const messages = Array.isArray(data.messages)
18
+ ? data.messages.filter((msg) => msg != null)
19
+ : [];
18
20
  const latestMessage = messages.at(-1);
19
21
  const latestGeminiMessage = [...messages].reverse().find((msg) => msg.type === "gemini");
20
22
  const lastActivityAt = toEpochSec(data.lastUpdated) ??
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marmonitor",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
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",
@@ -48,8 +48,8 @@
48
48
  "start": "node bin/marmonitor.js",
49
49
  "lint": "biome check src tests",
50
50
  "test": "node --test tests/*.test.mjs",
51
- "postinstall": "node bin/postinstall.js",
52
- "preuninstall": "node bin/preuninstall.js",
51
+ "postinstall": "node bin/postinstall.cjs",
52
+ "preuninstall": "node bin/preuninstall.cjs",
53
53
  "prepublishOnly": "npm run build && npm test"
54
54
  },
55
55
  "dependencies": {
@@ -1,115 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * postinstall script — show banner + offer tmux setup.
5
- * Runs after `npm install -g marmonitor`.
6
- *
7
- * - Non-TTY (CI): banner only, no prompt
8
- * - No tmux: banner + CLI-only message
9
- * - Already configured: banner + "already configured"
10
- * - Interactive: banner + y/n prompt → add plugin line to tmux.conf
11
- */
12
-
13
- import { execSync } from "node:child_process";
14
- import { readFileSync, writeFileSync, existsSync } from "node:fs";
15
- import { homedir } from "node:os";
16
- import { join } from "node:path";
17
- import { createInterface } from "node:readline";
18
-
19
- const PLUGIN_LINE = "set -g @plugin 'mjjo16/marmonitor-tmux'";
20
- const CONF_PATH = join(homedir(), ".tmux.conf");
21
-
22
- function hasTmux() {
23
- try {
24
- execSync("which tmux", { stdio: "ignore" });
25
- return true;
26
- } catch {
27
- return false;
28
- }
29
- }
30
-
31
- function hasPlugin() {
32
- try {
33
- const content = readFileSync(CONF_PATH, "utf-8");
34
- return content.split("\n").some((line) => line.trim() === PLUGIN_LINE);
35
- } catch {
36
- return false;
37
- }
38
- }
39
-
40
- function addPlugin() {
41
- let existing = "";
42
- try {
43
- existing = readFileSync(CONF_PATH, "utf-8");
44
- } catch {
45
- // file doesn't exist — will create
46
- }
47
- const sep = existing.length > 0 && !existing.endsWith("\n") ? "\n" : "";
48
- writeFileSync(CONF_PATH, `${existing}${sep}${PLUGIN_LINE}\n`, "utf-8");
49
- }
50
-
51
- function printBanner() {
52
- console.log("");
53
- console.log(" ✓ marmonitor installed");
54
- console.log(" Standing guard over your AI coding sessions");
55
- console.log("");
56
- }
57
-
58
- function ask(question) {
59
- return new Promise((resolve) => {
60
- const rl = createInterface({ input: process.stdin, output: process.stdout });
61
- rl.question(question, (answer) => {
62
- rl.close();
63
- resolve(answer.trim().toLowerCase());
64
- });
65
- });
66
- }
67
-
68
- async function main() {
69
- printBanner();
70
-
71
- // Non-interactive (CI, piped, etc.)
72
- if (!process.stdin.isTTY) {
73
- console.log(" Run 'marmonitor setup tmux' to configure tmux integration.");
74
- console.log("");
75
- return;
76
- }
77
-
78
- // No tmux
79
- if (!hasTmux()) {
80
- console.log(" tmux not found. marmonitor CLI is ready:");
81
- console.log(" $ marmonitor status");
82
- console.log(" $ marmonitor help");
83
- console.log("");
84
- return;
85
- }
86
-
87
- // Already configured
88
- if (hasPlugin()) {
89
- console.log(" tmux integration already configured.");
90
- console.log(" Press prefix+I in tmux to update the plugin.");
91
- console.log("");
92
- return;
93
- }
94
-
95
- // Interactive prompt
96
- const answer = await ask(" Set up tmux integration? (y/n): ");
97
-
98
- if (answer === "y" || answer === "yes") {
99
- addPlugin();
100
- console.log("");
101
- console.log(" ✓ Added to ~/.tmux.conf");
102
- console.log(" Press prefix+I inside tmux to activate.");
103
- console.log("");
104
- } else {
105
- console.log("");
106
- console.log(" Skipped. You can set up later:");
107
- console.log(" $ marmonitor setup tmux");
108
- console.log("");
109
- }
110
- }
111
-
112
- main().catch(() => {
113
- // postinstall must never fail the npm install
114
- process.exit(0);
115
- });
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * preuninstall script — remove marmonitor plugin line from tmux.conf.
5
- * Runs before `npm uninstall -g marmonitor`.
6
- *
7
- * - No prompt — automatic cleanup
8
- * - Only removes the exact plugin line, nothing else
9
- * - Silent if no tmux.conf or no plugin line found
10
- */
11
-
12
- import { readFileSync, writeFileSync } from "node:fs";
13
- import { homedir } from "node:os";
14
- import { join } from "node:path";
15
-
16
- const PLUGIN_LINE = "set -g @plugin 'mjjo16/marmonitor-tmux'";
17
- const CONF_PATH = join(homedir(), ".tmux.conf");
18
-
19
- function removePlugin() {
20
- let content;
21
- try {
22
- content = readFileSync(CONF_PATH, "utf-8");
23
- } catch {
24
- return false;
25
- }
26
-
27
- const lines = content.split("\n");
28
- const filtered = lines.filter((line) => line.trim() !== PLUGIN_LINE);
29
-
30
- if (filtered.length === lines.length) return false;
31
-
32
- writeFileSync(CONF_PATH, filtered.join("\n"), "utf-8");
33
- return true;
34
- }
35
-
36
- try {
37
- const removed = removePlugin();
38
- if (removed) {
39
- console.log(" marmonitor: removed tmux plugin line from ~/.tmux.conf");
40
- }
41
- } catch {
42
- // preuninstall must never fail the npm uninstall
43
- }