meksus 0.4.0 → 0.5.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.md +13 -0
- package/bin/meksus.mjs +7 -0
- package/package.json +1 -1
- package/src/hooks.mjs +11 -2
- package/src/spool.mjs +1 -0
- package/src/statusline.mjs +135 -0
- package/src/turns.mjs +41 -0
package/README.md
CHANGED
|
@@ -35,6 +35,14 @@ meksus watch --label "build" -- npm run build # any command; a failure opens an
|
|
|
35
35
|
|
|
36
36
|
Start a new Claude Code session after installing the hooks. It then appears on the dashboard's **Agents** page: working, waiting for you, finished, or stuck.
|
|
37
37
|
|
|
38
|
+
## Claude plan limits on the dashboard
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
meksus statusline install --global # once per computer (use --replace if you already have a status line)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Claude Code's status line then shows how much of your plan's 5-hour and weekly limits you've used and when each resets, and the dashboard's **Agents** page shows the same with a live countdown. A Discord DM tells you when a limit resets (turn it off on the Agents page). Claude Code provides these numbers for claude.ai Pro and Max plans, after the first reply in a session.
|
|
45
|
+
|
|
38
46
|
## Check
|
|
39
47
|
|
|
40
48
|
```sh
|
|
@@ -53,6 +61,10 @@ With `meksus task-lines` turned on (it's off by default), two more things are se
|
|
|
53
61
|
|
|
54
62
|
The server scrubs anything that looks like a secret.
|
|
55
63
|
|
|
64
|
+
When a Claude turn finishes, three numbers describe its size: how long it took, how many tool calls it made and how many files it changed (counted locally; file names never leave). Discord channels can then ask for big or small finished tasks only.
|
|
65
|
+
|
|
66
|
+
With `meksus statusline` installed, your Claude plan limits are sent too: the used percentage and reset time of the 5-hour and weekly windows, at most once a minute. Nothing else from the status line is sent.
|
|
67
|
+
|
|
56
68
|
## Commands
|
|
57
69
|
|
|
58
70
|
| Command | What it does |
|
|
@@ -65,6 +77,7 @@ The server scrubs anything that looks like a secret.
|
|
|
65
77
|
| `meksus project use <owner/project>` | Write this repo's `.meksus` |
|
|
66
78
|
| `meksus hooks install` / `uninstall` | Watch Claude Code in this repo |
|
|
67
79
|
| `meksus task-lines off \| steps \| prompt` | Opt-in one-line "working on" |
|
|
80
|
+
| `meksus statusline install [--global]` / `uninstall` | Claude plan limits in the status line and on the dashboard |
|
|
68
81
|
| `meksus watch [--label <name>] -- <cmd>` | Run a command and report how it ends |
|
|
69
82
|
|
|
70
83
|
© Lore Inc. All rights reserved.
|
package/bin/meksus.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import { apiBase, dir, readConfig } from "../src/config.mjs";
|
|
|
7
7
|
import { projectCommand, readProjectFile } from "../src/project.mjs";
|
|
8
8
|
import { incidentCommand, printCards } from "../src/cards.mjs";
|
|
9
9
|
import { flush } from "../src/spool.mjs";
|
|
10
|
+
import { limitsFlush, runStatusline, statuslineCommand } from "../src/statusline.mjs";
|
|
10
11
|
import { taskLinesCommand } from "../src/tasks.mjs";
|
|
11
12
|
import { VERSION } from "../src/version.mjs";
|
|
12
13
|
import { watch } from "../src/watch.mjs";
|
|
@@ -22,6 +23,8 @@ const HELP = `M.E.K.S.U.S. CLI ${VERSION}
|
|
|
22
23
|
meksus project use <owner/project> Write this repo's .meksus file (commit it)
|
|
23
24
|
meksus hooks install | uninstall Watch Claude Code in the current repository
|
|
24
25
|
meksus task-lines [off | steps | prompt] Show what Claude is working on, in one line (opt-in)
|
|
26
|
+
meksus statusline install [--global] Claude's plan limits (5-hour and weekly) in Claude Code's
|
|
27
|
+
status line and on your M.E.K.S.U.S. dashboard
|
|
25
28
|
meksus watch [--label <name>] -- <cmd> … Run a command and report its status; a failure opens an incident
|
|
26
29
|
|
|
27
30
|
Status only: code, prompts and command output never leave your machine. With task-lines on, the title
|
|
@@ -48,6 +51,10 @@ switch (command) {
|
|
|
48
51
|
break;
|
|
49
52
|
case "hook": code = await runHook(); break; // called by Claude Code, silent
|
|
50
53
|
case "task-lines": code = taskLinesCommand(rest); break;
|
|
54
|
+
case "statusline":
|
|
55
|
+
code = rest.length ? ((rest[0] === "install" && !(await requireAccess())) ? 1 : statuslineCommand(rest)) : await runStatusline();
|
|
56
|
+
break;
|
|
57
|
+
case "limits-flush": await limitsFlush(); break; // internal, detached
|
|
51
58
|
case "flush": await flush(); break; // internal, detached
|
|
52
59
|
case "watch": code = await watch(rest); break;
|
|
53
60
|
case "--version": case "-v": case "version": console.log(VERSION); break;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meksus",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "M.E.K.S.U.S. CLI: see what your AI coding agents (Claude Code) and builds are doing, live, and get Discord alerts when they fail or need you. Status only: code, prompts and output never leave your machine.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"meksus",
|
package/src/hooks.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import { basename, dirname, isAbsolute, join, relative, resolve } from "node:pat
|
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
10
|
import { readProjectFile } from "./project.mjs";
|
|
11
11
|
import { record } from "./spool.mjs";
|
|
12
|
+
import { trackTurn } from "./turns.mjs";
|
|
12
13
|
import { taskFrom, taskMode } from "./tasks.mjs";
|
|
13
14
|
|
|
14
15
|
const EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse", "Notification", "Stop", "SessionEnd"];
|
|
@@ -114,6 +115,8 @@ export async function runHook() {
|
|
|
114
115
|
if (task) Object.assign(status, task);
|
|
115
116
|
const file = fileFrom(input, mode);
|
|
116
117
|
if (file) Object.assign(status, file);
|
|
118
|
+
const turn = trackTurn(input, status.session);
|
|
119
|
+
if (turn) status.turn = turn; // the finished turn's size: three numbers
|
|
117
120
|
record(status);
|
|
118
121
|
}
|
|
119
122
|
} catch { /* a monitoring hook must never break the agent */ }
|
|
@@ -121,7 +124,7 @@ export async function runHook() {
|
|
|
121
124
|
}
|
|
122
125
|
|
|
123
126
|
// ── install / uninstall ─────────────────────────────────────────
|
|
124
|
-
function settingsPath(cwd) {
|
|
127
|
+
export function settingsPath(cwd) {
|
|
125
128
|
let d = resolve(cwd);
|
|
126
129
|
for (let i = 0; i < 20; i++) {
|
|
127
130
|
if (existsSync(join(d, ".git"))) break;
|
|
@@ -134,7 +137,7 @@ function settingsPath(cwd) {
|
|
|
134
137
|
|
|
135
138
|
// Reads the settings file, or explains (and changes nothing) when it isn't valid JSON — often two
|
|
136
139
|
// { … } blocks pasted one after the other, which Claude Code can't read either.
|
|
137
|
-
function readSettings(file) {
|
|
140
|
+
export function readSettings(file) {
|
|
138
141
|
if (!existsSync(file)) return {};
|
|
139
142
|
const text = readFileSync(file, "utf8");
|
|
140
143
|
try {
|
|
@@ -151,6 +154,12 @@ function readSettings(file) {
|
|
|
151
154
|
return null;
|
|
152
155
|
}
|
|
153
156
|
|
|
157
|
+
export function writeSettings(file, settings) {
|
|
158
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
159
|
+
writeFileSync(file, `${JSON.stringify(settings, null, 2)}
|
|
160
|
+
`);
|
|
161
|
+
}
|
|
162
|
+
|
|
154
163
|
export function install(cwd = process.cwd()) {
|
|
155
164
|
const file = settingsPath(cwd);
|
|
156
165
|
const settings = readSettings(file);
|
package/src/spool.mjs
CHANGED
|
@@ -72,6 +72,7 @@ export function aggregate(events) {
|
|
|
72
72
|
if (e.exit_code !== undefined && e.exit_code !== null) cur.exit_code = e.exit_code;
|
|
73
73
|
if (e.ended) cur.ended = true;
|
|
74
74
|
if (e.transcript) cur.transcript = e.transcript;
|
|
75
|
+
if (e.turn) cur.turn = e.turn;
|
|
75
76
|
if (e.started_at && e.started_at < cur.started_at) cur.started_at = e.started_at;
|
|
76
77
|
if (typeof e.task === "string") {
|
|
77
78
|
Object.assign(cur, { task: e.task, task_source: e.task_source, task_done: e.task_done ?? 0, task_total: e.task_total ?? 0, task_at: e.at });
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Claude plan limits on the M.E.K.S.U.S. dashboard (Rik, 2026-09-26).
|
|
2
|
+
// `meksus statusline` Claude Code's status line command. Reads the status line JSON on stdin and
|
|
3
|
+
// prints one short line ("5h 23% · resets in 2h 14m │ week 41% · Tue 09:00").
|
|
4
|
+
// Keeps ONLY rate_limits (percentages + reset times) in ~/.meksus/limits.json and,
|
|
5
|
+
// when they changed (or every 5 minutes), starts a detached `meksus limits-flush`,
|
|
6
|
+
// at most once a minute (G-1). Never blocks, never breaks the status line.
|
|
7
|
+
// `meksus statusline install [--global] [--replace]` / `uninstall [--global]`
|
|
8
|
+
// <repo>/.claude/settings.local.json, or ~/.claude/settings.json with --global.
|
|
9
|
+
// `meksus limits-flush` internal, detached: one POST /v1/claude-limits as the signed-in user.
|
|
10
|
+
import { spawn } from "node:child_process";
|
|
11
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { homedir } from "node:os";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { fileURLToPath } from "node:url";
|
|
15
|
+
import { getAccessToken } from "./auth.mjs";
|
|
16
|
+
import { apiBase, dir, ensureDir, readConfig } from "./config.mjs";
|
|
17
|
+
import { readSettings, settingsPath, writeSettings } from "./hooks.mjs";
|
|
18
|
+
import { VERSION } from "./version.mjs";
|
|
19
|
+
|
|
20
|
+
const CLI = fileURLToPath(new URL("../bin/meksus.mjs", import.meta.url));
|
|
21
|
+
const MARK = "meksus.mjs\" statusline";
|
|
22
|
+
const WINDOWS = ["five_hour", "seven_day", "spend_limit"];
|
|
23
|
+
export const SEND_MIN_MS = 60_000;
|
|
24
|
+
export const SEND_EVERY_MS = 5 * 60_000;
|
|
25
|
+
const limitsFile = () => join(dir(), "limits.json");
|
|
26
|
+
|
|
27
|
+
/** Only the numbers: { five_hour: { used_percentage, resets_at }, … }, or null. */
|
|
28
|
+
export function pickLimits(input) {
|
|
29
|
+
const src = input?.rate_limits;
|
|
30
|
+
if (!src || typeof src !== "object") return null;
|
|
31
|
+
const out = {};
|
|
32
|
+
for (const w of WINDOWS) {
|
|
33
|
+
const v = src[w];
|
|
34
|
+
const pct = Number(v?.used_percentage);
|
|
35
|
+
const at = Number(v?.resets_at);
|
|
36
|
+
if (Number.isFinite(pct) && Number.isFinite(at)) out[w] = { used_percentage: Math.round(pct * 100) / 100, resets_at: Math.round(at) };
|
|
37
|
+
}
|
|
38
|
+
return Object.keys(out).length ? out : null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function until(resetsAtS, nowMs = Date.now()) {
|
|
42
|
+
const s = Math.max(0, Math.round(resetsAtS - nowMs / 1000));
|
|
43
|
+
const d = Math.floor(s / 86400), hh = Math.floor((s % 86400) / 3600), mm = Math.floor((s % 3600) / 60);
|
|
44
|
+
return d ? `${d}d ${hh}h` : hh ? `${hh}h ${String(mm).padStart(2, "0")}m` : `${mm}m`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function renderLine(limits, nowMs = Date.now()) {
|
|
48
|
+
if (!limits) return "Claude limits: after the first reply";
|
|
49
|
+
const part = (label, w) => (w ? `${label} ${Math.round(w.used_percentage)}% · resets in ${until(w.resets_at, nowMs)}` : null);
|
|
50
|
+
return [part("5h", limits.five_hour), part("week", limits.seven_day), part("spend", limits.spend_limit)].filter(Boolean).join(" │ ");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const signature = (l) => JSON.stringify(WINDOWS.map((w) => (l?.[w] ? [Math.round(l[w].used_percentage), l[w].resets_at] : null)));
|
|
54
|
+
|
|
55
|
+
/** Should this run start a send? (changed and a minute since the last one, or 5 minutes regardless) */
|
|
56
|
+
export function sendDue(state, limits, nowMs = Date.now()) {
|
|
57
|
+
if (!limits) return false;
|
|
58
|
+
const since = nowMs - (state?.sent_at ?? 0);
|
|
59
|
+
return (signature(limits) !== state?.sent_sig && since >= SEND_MIN_MS) || since >= SEND_EVERY_MS;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function readState() { try { return JSON.parse(readFileSync(limitsFile(), "utf8")); } catch { return null; } }
|
|
63
|
+
function writeState(s) { try { ensureDir(); writeFileSync(limitsFile(), JSON.stringify(s)); } catch { /* read-only home: just don't send */ } }
|
|
64
|
+
|
|
65
|
+
export async function runStatusline() {
|
|
66
|
+
let limits = null;
|
|
67
|
+
try {
|
|
68
|
+
const chunks = [];
|
|
69
|
+
for await (const c of process.stdin) chunks.push(c);
|
|
70
|
+
limits = pickLimits(JSON.parse(Buffer.concat(chunks).toString("utf8") || "{}"));
|
|
71
|
+
} catch { /* bad input: still print something */ }
|
|
72
|
+
const state = readState();
|
|
73
|
+
const shown = limits ?? state?.limits ?? null;
|
|
74
|
+
process.stdout.write(`${renderLine(shown)}\n`);
|
|
75
|
+
if (limits && sendDue(state, limits) && readConfig()?.session) {
|
|
76
|
+
writeState({ limits, at: Date.now(), sent_at: Date.now(), sent_sig: signature(limits) }); // claim before spawning
|
|
77
|
+
try { spawn(process.execPath, [CLI, "limits-flush"], { detached: true, stdio: "ignore", windowsHide: true, env: process.env }).unref(); } catch { /* next run */ }
|
|
78
|
+
} else if (limits) {
|
|
79
|
+
writeState({ ...(state ?? {}), limits, at: Date.now() });
|
|
80
|
+
}
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function limitsFlush() {
|
|
85
|
+
const state = readState();
|
|
86
|
+
const config = readConfig();
|
|
87
|
+
if (!state?.limits || !config?.session) return 0;
|
|
88
|
+
const token = await getAccessToken(config);
|
|
89
|
+
if (!token) return 0;
|
|
90
|
+
try {
|
|
91
|
+
const res = await fetch(`${apiBase(config)}/v1/claude-limits`, {
|
|
92
|
+
method: "POST",
|
|
93
|
+
headers: { "Content-Type": "application/json", "User-Agent": `meksus-cli/${VERSION}`, Authorization: `Bearer ${token}` },
|
|
94
|
+
body: JSON.stringify({ rate_limits: state.limits }),
|
|
95
|
+
signal: AbortSignal.timeout(8000),
|
|
96
|
+
});
|
|
97
|
+
await res.body?.cancel();
|
|
98
|
+
return res.status;
|
|
99
|
+
} catch { return 0; } // dropped; the next status line run sends again (G-11)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ── install / uninstall ─────────────────────────────────────────
|
|
103
|
+
const globalSettings = () => join(homedir(), ".claude", "settings.json");
|
|
104
|
+
|
|
105
|
+
export function statuslineCommand(args) {
|
|
106
|
+
const global = args.includes("--global");
|
|
107
|
+
const file = global ? globalSettings() : settingsPath(process.cwd());
|
|
108
|
+
if (args[0] === "install") {
|
|
109
|
+
const settings = readSettings(file);
|
|
110
|
+
if (!settings) return 1;
|
|
111
|
+
const current = settings.statusLine?.command ?? "";
|
|
112
|
+
if (current && !current.includes(MARK) && !args.includes("--replace")) {
|
|
113
|
+
console.error(`✖ ${file} already has a status line: ${current}`);
|
|
114
|
+
console.error(" Run again with --replace to use the M.E.K.S.U.S. one instead (it shows your Claude plan limits).");
|
|
115
|
+
return 1;
|
|
116
|
+
}
|
|
117
|
+
settings.statusLine = { type: "command", command: `node "${CLI}" statusline`, padding: 0, refreshInterval: 30 };
|
|
118
|
+
writeSettings(file, settings);
|
|
119
|
+
console.log(`✔ Status line installed in ${file}`);
|
|
120
|
+
console.log(" It shows your Claude plan limits (5-hour and weekly) and sends only those numbers to your M.E.K.S.U.S. dashboard, at most once a minute.");
|
|
121
|
+
console.log(" Claude Code provides them for claude.ai Pro and Max plans, after the first reply in a session.");
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
if (args[0] === "uninstall") {
|
|
125
|
+
const settings = readSettings(file);
|
|
126
|
+
if (!settings) return 1;
|
|
127
|
+
if (!String(settings.statusLine?.command ?? "").includes(MARK)) { console.log(`No M.E.K.S.U.S. status line in ${file}.`); return 0; }
|
|
128
|
+
delete settings.statusLine;
|
|
129
|
+
writeSettings(file, settings);
|
|
130
|
+
console.log(`✔ Status line removed from ${file}`);
|
|
131
|
+
return 0;
|
|
132
|
+
}
|
|
133
|
+
console.error("Usage: meksus statusline install [--global] [--replace] | uninstall [--global]");
|
|
134
|
+
return 2;
|
|
135
|
+
}
|
package/src/turns.mjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// How big was the turn Claude just finished? Measured here, on this machine, from the hooks themselves:
|
|
2
|
+
// the time from the prompt (UserPromptSubmit) to Stop, the tool calls in between, and how many distinct
|
|
3
|
+
// files it changed (Edit / Write / MultiEdit / NotebookEdit). Only those three numbers are sent, with the
|
|
4
|
+
// Stop event; file names are kept locally as hashes, only to count them once, and dropped with the turn.
|
|
5
|
+
// The server scores big vs small (packages/shared/src/notices.ts taskSize) for the AI-coder notices.
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { dir, ensureDir } from "./config.mjs";
|
|
10
|
+
|
|
11
|
+
const EDITS = new Set(["Edit", "MultiEdit", "Write", "NotebookEdit"]);
|
|
12
|
+
const KEEP = 50; // sessions remembered at most
|
|
13
|
+
const file = () => join(dir(), "turns.json");
|
|
14
|
+
|
|
15
|
+
function load() { try { return JSON.parse(readFileSync(file(), "utf8")); } catch { return {}; } }
|
|
16
|
+
function save(turns) {
|
|
17
|
+
const entries = Object.entries(turns).sort((a, b) => (b[1].at ?? 0) - (a[1].at ?? 0)).slice(0, KEEP);
|
|
18
|
+
try { ensureDir(); writeFileSync(file(), JSON.stringify(Object.fromEntries(entries))); } catch { /* not measured, not fatal */ }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Updates the session's running turn; on Stop returns { seconds, tool_calls, files }, else null. */
|
|
22
|
+
export function trackTurn(input, session, now = Date.now()) {
|
|
23
|
+
const name = input?.hook_event_name;
|
|
24
|
+
if (!session || !["UserPromptSubmit", "PreToolUse", "Stop"].includes(name)) return null;
|
|
25
|
+
const turns = load();
|
|
26
|
+
let t = turns[session];
|
|
27
|
+
if (name === "UserPromptSubmit" || !t) t = { start: now, tools: 0, files: [], at: now };
|
|
28
|
+
if (name === "PreToolUse") {
|
|
29
|
+
t.tools += 1;
|
|
30
|
+
const target = input.tool_input?.file_path ?? input.tool_input?.notebook_path;
|
|
31
|
+
if (EDITS.has(input.tool_name) && typeof target === "string") {
|
|
32
|
+
const h = createHash("sha256").update(target).digest("hex").slice(0, 16);
|
|
33
|
+
if (!t.files.includes(h) && t.files.length < 500) t.files.push(h);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
t.at = now;
|
|
37
|
+
turns[session] = t;
|
|
38
|
+
save(turns);
|
|
39
|
+
if (name !== "Stop") return null;
|
|
40
|
+
return { seconds: Math.max(0, Math.round((now - t.start) / 1000)), tool_calls: t.tools, files: t.files.length };
|
|
41
|
+
}
|