marmonitor 0.1.2 → 0.1.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.
@@ -0,0 +1,115 @@
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
+ });
@@ -0,0 +1,43 @@
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
+ }
package/dist/cli.js CHANGED
@@ -851,5 +851,42 @@ program
851
851
  printCleanPlan(targets, Boolean(opts.kill));
852
852
  }
853
853
  });
854
+ program
855
+ .command("setup")
856
+ .description("Set up marmonitor integrations")
857
+ .argument("<target>", "Integration target (tmux)")
858
+ .action(async (target) => {
859
+ if (target !== "tmux") {
860
+ console.error(`Unknown target: ${target}. Supported: tmux`);
861
+ process.exit(1);
862
+ }
863
+ const { addMarmonitorPlugin, hasMarmonitorPlugin } = await import("./tmux/setup.js");
864
+ const { homedir } = await import("node:os");
865
+ const { join } = await import("node:path");
866
+ const confPath = join(homedir(), ".tmux.conf");
867
+ if (await hasMarmonitorPlugin(confPath)) {
868
+ console.log("tmux integration already configured.");
869
+ return;
870
+ }
871
+ await addMarmonitorPlugin(confPath);
872
+ console.log("✓ Added marmonitor-tmux plugin to ~/.tmux.conf");
873
+ console.log("Press prefix+I inside tmux to activate.");
874
+ });
875
+ program
876
+ .command("uninstall-integration")
877
+ .description("Remove marmonitor settings from tmux.conf")
878
+ .action(async () => {
879
+ const { removeMarmonitorPlugin } = await import("./tmux/setup.js");
880
+ const { homedir } = await import("node:os");
881
+ const { join } = await import("node:path");
882
+ const confPath = join(homedir(), ".tmux.conf");
883
+ const removed = await removeMarmonitorPlugin(confPath);
884
+ if (removed) {
885
+ console.log("✓ Removed marmonitor-tmux plugin from ~/.tmux.conf");
886
+ }
887
+ else {
888
+ console.log("No marmonitor settings found in ~/.tmux.conf");
889
+ }
890
+ });
854
891
  installProcessSafetyHandlers();
855
892
  program.parse();
@@ -543,7 +543,7 @@ export function buildTmuxAttentionPills(items, maxCount = 5, width) {
543
543
  .filter((item) => item.kind !== "unmatched" && item.kind !== "stalled")
544
544
  .slice(0, layout.itemCount);
545
545
  if (jumpItems.length === 0) {
546
- return tmuxDetailBlock("✅ all ok");
546
+ return tmuxDetailBlock("no active");
547
547
  }
548
548
  const segments = jumpItems.map((item, index) => {
549
549
  const agent = agentShortName(item.agentName);
@@ -0,0 +1,7 @@
1
+ /**
2
+ * tmux.conf plugin line management.
3
+ * Adds/removes the marmonitor-tmux tpm plugin line.
4
+ */
5
+ export declare function hasMarmonitorPlugin(confPath: string): Promise<boolean>;
6
+ export declare function addMarmonitorPlugin(confPath: string): Promise<boolean>;
7
+ export declare function removeMarmonitorPlugin(confPath: string): Promise<boolean>;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * tmux.conf plugin line management.
3
+ * Adds/removes the marmonitor-tmux tpm plugin line.
4
+ */
5
+ import { readFile, writeFile } from "node:fs/promises";
6
+ const PLUGIN_LINE = "set -g @plugin 'mjjo16/marmonitor-tmux'";
7
+ function matchesPluginLine(line) {
8
+ return line.trim() === PLUGIN_LINE;
9
+ }
10
+ export async function hasMarmonitorPlugin(confPath) {
11
+ try {
12
+ const content = await readFile(confPath, "utf-8");
13
+ return content.split("\n").some(matchesPluginLine);
14
+ }
15
+ catch {
16
+ return false;
17
+ }
18
+ }
19
+ export async function addMarmonitorPlugin(confPath) {
20
+ if (await hasMarmonitorPlugin(confPath))
21
+ return false;
22
+ let existing = "";
23
+ try {
24
+ existing = await readFile(confPath, "utf-8");
25
+ }
26
+ catch {
27
+ // file doesn't exist yet — will create
28
+ }
29
+ const separator = existing.length > 0 && !existing.endsWith("\n") ? "\n" : "";
30
+ await writeFile(confPath, `${existing}${separator}${PLUGIN_LINE}\n`, "utf-8");
31
+ return true;
32
+ }
33
+ export async function removeMarmonitorPlugin(confPath) {
34
+ let content;
35
+ try {
36
+ content = await readFile(confPath, "utf-8");
37
+ }
38
+ catch {
39
+ return false;
40
+ }
41
+ const lines = content.split("\n");
42
+ const filtered = lines.filter((line) => !matchesPluginLine(line));
43
+ if (filtered.length === lines.length)
44
+ return false;
45
+ await writeFile(confPath, filtered.join("\n"), "utf-8");
46
+ return true;
47
+ }
package/dist/version.js CHANGED
@@ -1,5 +1,4 @@
1
- import { readFileSync } from "node:fs";
2
- import { dirname, join } from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- const pkg = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), "..", "package.json"), "utf-8"));
1
+ import { createRequire } from "node:module";
2
+ const require = createRequire(import.meta.url);
3
+ const pkg = require("../package.json");
5
4
  export const VERSION = pkg.version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marmonitor",
3
- "version": "0.1.2",
3
+ "version": "0.1.5",
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,6 +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
53
  "prepublishOnly": "npm run build && npm test"
52
54
  },
53
55
  "dependencies": {