marmonitor 0.2.2 → 0.2.3

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.
@@ -3,29 +3,74 @@
3
3
  */
4
4
  import { detectApprovalPromptPhase } from "../output/utils.js";
5
5
  import { captureTmuxPaneOutput, resolveTmuxJumpTarget } from "../tmux/index.js";
6
- import { RECENT_ACTIVITY_ACTIVE_SEC, stdoutHeuristicCache } from "./cache.js";
6
+ import { RECENT_ACTIVITY_ACTIVE_SEC, STATUS_HYSTERESIS_SEC, stdoutHeuristicCache, } from "./cache.js";
7
+ export function refreshLastActivityAt(lastActivityAt, cpuPercent, phase, activeCpuThreshold, agentName, nowSec = Math.floor(Date.now() / 1000)) {
8
+ if (agentName !== "Codex")
9
+ return lastActivityAt;
10
+ if (cpuPercent > activeCpuThreshold ||
11
+ phase === "permission" ||
12
+ phase === "thinking" ||
13
+ phase === "tool") {
14
+ return Math.max(lastActivityAt ?? 0, nowSec);
15
+ }
16
+ return lastActivityAt;
17
+ }
7
18
  /** Determine agent activity status */
8
- export function determineStatus(cpuPercent, elapsedSec, sessionMatched, phase, config) {
19
+ export function determineStatus(cpuPercent, elapsedSec, sessionMatched, phase, config, agentName) {
9
20
  // Zombie: process exists but no matching session
10
21
  if (!sessionMatched)
11
22
  return "Unmatched";
23
+ const stalledSec = config.status.stalledAfterMin * 60;
12
24
  // Active: CPU above threshold
13
25
  if (cpuPercent > config.status.activeCpuThreshold)
14
26
  return "Active";
15
- // Permission/thinking override: these phases require user attention
16
- // regardless of how long the process has been running
17
- if (phase === "permission" || phase === "thinking")
18
- return "Idle";
19
- if (phase === "tool" && (elapsedSec === undefined || elapsedSec <= RECENT_ACTIVITY_ACTIVE_SEC)) {
27
+ // Recent active phases stay active briefly even after CPU bursts end.
28
+ if ((phase === "permission" || phase === "thinking" || phase === "tool") &&
29
+ (elapsedSec === undefined || elapsedSec <= RECENT_ACTIVITY_ACTIVE_SEC)) {
30
+ return "Active";
31
+ }
32
+ // Codex often drops to ~0% CPU immediately after a burst.
33
+ // Keep it active for a short recent-activity grace window even without a strong phase.
34
+ if (agentName === "Codex" &&
35
+ elapsedSec !== undefined &&
36
+ elapsedSec <= Math.min(60, RECENT_ACTIVITY_ACTIVE_SEC)) {
20
37
  return "Active";
21
38
  }
39
+ // Codex quiet sessions often hold a live rollout while CPU falls to 0%.
40
+ // Treat them as idle for a much longer window before escalating to stalled.
41
+ if (agentName === "Codex" && elapsedSec !== undefined && cpuPercent < 0.1) {
42
+ const codexStalledSec = Math.max(stalledSec, 24 * 60 * 60);
43
+ if (elapsedSec > codexStalledSec)
44
+ return "Stalled";
45
+ return "Idle";
46
+ }
22
47
  // Stalled: idle for longer than configured threshold
23
- const stalledSec = config.status.stalledAfterMin * 60;
24
48
  if (elapsedSec !== undefined && elapsedSec > stalledSec && cpuPercent < 0.1) {
25
49
  return "Stalled";
26
50
  }
27
51
  return "Idle";
28
52
  }
53
+ export function applyStatusHysteresis(nextStatus, previousStatus, elapsedSec, phase, agentName) {
54
+ if (!previousStatus || previousStatus === nextStatus)
55
+ return nextStatus;
56
+ if (nextStatus === "Unmatched" || nextStatus === "Dead")
57
+ return nextStatus;
58
+ if (previousStatus === "Unmatched" || previousStatus === "Dead")
59
+ return nextStatus;
60
+ const hasLivePhase = phase === "permission" || phase === "thinking" || phase === "tool";
61
+ const hysteresisSec = agentName === "Codex" ? Math.max(STATUS_HYSTERESIS_SEC, 60) : STATUS_HYSTERESIS_SEC;
62
+ if (previousStatus === "Active" && (nextStatus === "Idle" || nextStatus === "Stalled")) {
63
+ if (elapsedSec === undefined || elapsedSec <= hysteresisSec || hasLivePhase) {
64
+ return "Active";
65
+ }
66
+ }
67
+ if (previousStatus === "Idle" && nextStatus === "Stalled") {
68
+ if (elapsedSec === undefined || elapsedSec <= hysteresisSec * 2 || hasLivePhase) {
69
+ return "Idle";
70
+ }
71
+ }
72
+ return nextStatus;
73
+ }
29
74
  export async function detectCliStdoutPhase(agent, config) {
30
75
  const cached = stdoutHeuristicCache.get(agent.pid);
31
76
  if (cached && Date.now() - cached.checkedAt < config.performance.stdoutHeuristicTtlMs) {
@@ -1,6 +1,10 @@
1
1
  /**
2
2
  * Public types for the scanner module.
3
3
  */
4
+ import type { CodexBindingRegistry } from "./codex-binding-registry.js";
5
+ import type { SessionRegistryRecord } from "./session-registry.js";
4
6
  export interface ScanOptions {
5
7
  enrichmentMode?: "full" | "light";
8
+ codexBindingRegistry?: CodexBindingRegistry;
9
+ sessionRegistry?: Map<string, SessionRegistryRecord>;
6
10
  }
package/dist/types.d.ts CHANGED
@@ -29,6 +29,7 @@ export interface AgentSession {
29
29
  memoryMb: number;
30
30
  status: SessionStatus;
31
31
  startedAt?: number;
32
+ processStartedAt?: number;
32
33
  sessionId?: string;
33
34
  lastActivity?: string;
34
35
  tokenUsage?: TokenUsage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marmonitor",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
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",