@ethlete/agent-rules 0.1.0-next.60 → 0.1.0-next.61

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ethlete/agent-rules
2
2
 
3
+ ## 0.1.0-next.61
4
+
5
+ ### Patch Changes
6
+
7
+ - Count live Codex wrappers alongside Claude subagents and keep away mode active on agent messages.
8
+
3
9
  ## 0.1.0-next.60
4
10
 
5
11
  ### Patch Changes
@@ -40,6 +40,8 @@ CONFIG_FILE = "ethlete-agents.config.json"
40
40
  LOCAL_CONFIG_FILE = "ethlete-agents.config.local.json"
41
41
  DEFAULT_THRESHOLD_MINUTES = 15
42
42
  AGENT_SESSIONS_SUFFIX = "[typed by agent-sessions]"
43
+ MAILBOX_PROMPT = re.compile(r"(?:<pasted_content\b[^>]*>\s*)?Mailbox message from ")
44
+ AGENT_MESSAGE = re.compile(r"(?:Another Claude session sent a message:\s*)?<agent-message(?:\s|>)")
43
45
 
44
46
  BACK_MESSAGE = (
45
47
  "The user is back (typed input after {minutes} min away). Leave away mode: put every question you "
@@ -224,7 +226,8 @@ def is_human_typed(prompt, transcript_path=None, cron_prompts=()):
224
226
  if stripped in cron_prompts or fired_by_schedule(prompt, transcript_path):
225
227
  return False
226
228
  return not (
227
- stripped.startswith("Mailbox message from ")
229
+ MAILBOX_PROMPT.match(stripped)
230
+ or AGENT_MESSAGE.match(stripped)
228
231
  or "<cross-session-message" in stripped
229
232
  or stripped.endswith(AGENT_SESSIONS_SUFFIX)
230
233
  or stripped.startswith("<task-notification")
@@ -26,6 +26,7 @@ else are skipped. A session counts as a builder when it ran the `builder-agent`
26
26
 
27
27
  A tmux agent session with a live Codex pane in this checkout counts as one slot, including
28
28
  while Codex waits at its prompt. A builder starts these sessions outside the transcript.
29
+ Live codex-agent.mjs runs in the checkout count through their run indexes, which survive /clear.
29
30
  While the newest Codex rate-limit sample (as `codex-limit` reads it from `$CODEX_HOME/sessions`) shows
30
31
  20% or less of the 5h window left, or an exhausted week, the builder builds one slice at a time: the
31
32
  slot limit is 1. A row counts as taken when a running task's description or command names its ID.
@@ -50,6 +51,7 @@ import time
50
51
  import re
51
52
  import subprocess
52
53
  import sys
54
+ import tempfile
53
55
  from datetime import datetime
54
56
 
55
57
  HOOK_NAME = "builder-idle-check"
@@ -85,6 +87,7 @@ SERVER_COMMAND = re.compile(
85
87
  r"|\bstorybook\s+dev\b"
86
88
  )
87
89
  CI_POLL = re.compile(r"\b(?:gh\s+run\s+(?:view|list)|glab\s+ci\s+(?:status|list|get))\b")
90
+ CODEX_WRAPPER = re.compile(r"""^\s*(?:\S+/)?node\s+["']?(?:[^\s"']*/)?codex-agent\.mjs["']?(?:\s|$)""")
88
91
  LOOP = re.compile(r"\b(?:while|until|for)\b")
89
92
  NOTIFICATION = re.compile(r"<task-notification>(.*?)</task-notification>", re.S)
90
93
  WAITING_SUMMARY = re.compile(r"<summary>[^<]*is waiting on its own background work")
@@ -415,6 +418,31 @@ def codex_runs(root):
415
418
  return list(sessions)
416
419
 
417
420
 
421
+ def codex_wrapper_runs(root):
422
+ checkout = os.path.realpath(root)
423
+ labels = {}
424
+ for path in sorted(glob.glob(os.path.join(tempfile.gettempdir(), "codex-agent", "*.run.json"))):
425
+ try:
426
+ with open(path, encoding="utf-8") as file:
427
+ run = json.load(file)
428
+ if not isinstance(run, dict) or run.get("endedAt") is not None:
429
+ continue
430
+ pid, cwd = run.get("pid"), run.get("cwd")
431
+ if type(pid) is not int or pid <= 0 or pid in labels or not isinstance(cwd, str) or not cwd:
432
+ continue
433
+ if os.path.commonpath((checkout, os.path.realpath(cwd))) != checkout:
434
+ continue
435
+ command = subprocess.run(
436
+ ["ps", "-p", str(pid), "-o", "args="], capture_output=True, text=True, timeout=1, check=True,
437
+ ).stdout
438
+ if CODEX_WRAPPER.match(command):
439
+ prompt = run.get("prompt")
440
+ labels[pid] = prompt if isinstance(prompt, str) and prompt else f"Codex (pid {pid})"
441
+ except (OSError, ValueError, subprocess.SubprocessError):
442
+ continue
443
+ return list(labels.values())
444
+
445
+
418
446
  def waits(text, patterns):
419
447
  lowered = text.lower()
420
448
  return any(pattern.lower() in lowered for pattern in patterns)
@@ -478,12 +506,13 @@ def not_taken(rows, labels, commands):
478
506
  ]
479
507
 
480
508
 
481
- def reason_for(rows, watchers, working, slots, sources, patterns):
509
+ def reason_for(rows, watchers, workers, slots, sources, patterns):
482
510
  watching = f" (still watching: {', '.join(watchers)})" if watchers else ""
511
+ working = f" (working: {', '.join(workers)})" if workers else ""
483
512
  queues = ", ".join(source["path"] for source in sources)
484
513
  waiting = " or ".join(f'"{pattern}"' for pattern in patterns)
485
514
  return (
486
- f"[{HOOK_NAME} hook] This turn ends with {working} of {slots} slots in use, not counting CI watchers and dev servers{watching}, "
515
+ f"[{HOOK_NAME} hook] This turn ends with {len(workers)} of {slots} slots in use{working}, not counting CI watchers and dev servers{watching}, "
487
516
  f"while {queues} has open rows without a wait reason: {', '.join(rows)}. "
488
517
  "Do not leave slots idle: take the first of them now, or start a subagent on it. "
489
518
  f"A row waits when it contains {waiting}; if a row really waits, "
@@ -508,19 +537,23 @@ def main():
508
537
  return
509
538
  read_earlier_agents(state, transcript_path)
510
539
  running = running_tasks(state)
511
- codex = codex_runs(root)
512
- working = sum(1 for task in running if not task["watcher"]) + len(codex)
540
+ codex = codex_runs(root) + codex_wrapper_runs(root)
541
+ workers = [
542
+ task["label"] for task in running
543
+ if not task["watcher"] and not CODEX_WRAPPER.match(task.get("command", ""))
544
+ ] + codex
513
545
  slots = 1 if codex_low(time.time()) else slot_limit(config)
514
- if working >= slots:
546
+ if len(workers) >= slots:
515
547
  return
516
548
  sources = queue_sources(settings)
517
549
  patterns = string_list(settings.get("waitPatterns"), DEFAULT_WAIT_PATTERNS)
518
- watchers = [task["label"] for task in running] + codex
550
+ watchers = [task["label"] for task in running if task["watcher"]]
551
+ labels = [task["label"] for task in running] + codex
519
552
  commands = [task.get("command", "") for task in running]
520
- rows = not_taken(open_builder_rows(root, sources, patterns), watchers, commands)
553
+ rows = not_taken(open_builder_rows(root, sources, patterns), labels, commands)
521
554
  if not rows:
522
555
  return
523
- print(json.dumps({"decision": "block", "reason": reason_for(rows, watchers, working, slots, sources, patterns)}))
556
+ print(json.dumps({"decision": "block", "reason": reason_for(rows, watchers, workers, slots, sources, patterns)}))
524
557
  except Exception:
525
558
  return
526
559
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-runs",
3
- "version": "0.1.0-next.60",
3
+ "version": "0.1.0-next.61",
4
4
  "description": "Codex sessions in tmux with their state, duration, and recent output",
5
5
  "types": "./types/index.d.ts"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "e2e-progress",
3
- "version": "0.1.0-next.60",
3
+ "version": "0.1.0-next.61",
4
4
  "description": "Live Playwright e2e progress from a run log, as a status line entry and a pane",
5
5
  "types": "./types/index.d.ts"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "status-line",
3
- "version": "0.1.0-next.60",
3
+ "version": "0.1.0-next.61",
4
4
  "description": "Always-visible band with the running task, its duration, the open queue, open questions and a CI blocked mark",
5
5
  "types": "./types/index.d.ts"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "usage-line",
3
- "version": "0.1.0-next.60",
3
+ "version": "0.1.0-next.61",
4
4
  "description": "Status line entry with the 5 hour and weekly usage, the reset time of the 5 hour window and the Codex limit",
5
5
  "types": "./types/index.d.ts"
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethlete/agent-rules",
3
- "version": "0.1.0-next.60",
3
+ "version": "0.1.0-next.61",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/ethlete-io/ethdk",