dkitchen 0.6.1__tar.gz → 0.6.2__tar.gz

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.
Files changed (25) hide show
  1. {dkitchen-0.6.1/src/dkitchen.egg-info → dkitchen-0.6.2}/PKG-INFO +3 -3
  2. {dkitchen-0.6.1 → dkitchen-0.6.2}/README.md +1 -1
  3. {dkitchen-0.6.1 → dkitchen-0.6.2}/pyproject.toml +2 -2
  4. {dkitchen-0.6.1 → dkitchen-0.6.2}/src/dkitchen/config.py +5 -0
  5. {dkitchen-0.6.1 → dkitchen-0.6.2}/src/dkitchen/ding.py +48 -4
  6. {dkitchen-0.6.1 → dkitchen-0.6.2/src/dkitchen.egg-info}/PKG-INFO +3 -3
  7. {dkitchen-0.6.1 → dkitchen-0.6.2}/tests/test_codex_session.py +84 -3
  8. {dkitchen-0.6.1 → dkitchen-0.6.2}/tests/test_kitchen.py +6 -0
  9. {dkitchen-0.6.1 → dkitchen-0.6.2}/LICENSE +0 -0
  10. {dkitchen-0.6.1 → dkitchen-0.6.2}/setup.cfg +0 -0
  11. {dkitchen-0.6.1 → dkitchen-0.6.2}/src/dkitchen/__init__.py +0 -0
  12. {dkitchen-0.6.1 → dkitchen-0.6.2}/src/dkitchen/check.py +0 -0
  13. {dkitchen-0.6.1 → dkitchen-0.6.2}/src/dkitchen/night.py +0 -0
  14. {dkitchen-0.6.1 → dkitchen-0.6.2}/src/dkitchen/orchestrate.py +0 -0
  15. {dkitchen-0.6.1 → dkitchen-0.6.2}/src/dkitchen/refs.py +0 -0
  16. {dkitchen-0.6.1 → dkitchen-0.6.2}/src/dkitchen/rule.py +0 -0
  17. {dkitchen-0.6.1 → dkitchen-0.6.2}/src/dkitchen/watch.py +0 -0
  18. {dkitchen-0.6.1 → dkitchen-0.6.2}/src/dkitchen.egg-info/SOURCES.txt +0 -0
  19. {dkitchen-0.6.1 → dkitchen-0.6.2}/src/dkitchen.egg-info/dependency_links.txt +0 -0
  20. {dkitchen-0.6.1 → dkitchen-0.6.2}/src/dkitchen.egg-info/entry_points.txt +0 -0
  21. {dkitchen-0.6.1 → dkitchen-0.6.2}/src/dkitchen.egg-info/requires.txt +0 -0
  22. {dkitchen-0.6.1 → dkitchen-0.6.2}/src/dkitchen.egg-info/top_level.txt +0 -0
  23. {dkitchen-0.6.1 → dkitchen-0.6.2}/tests/test_check.py +0 -0
  24. {dkitchen-0.6.1 → dkitchen-0.6.2}/tests/test_records.py +0 -0
  25. {dkitchen-0.6.1 → dkitchen-0.6.2}/tests/test_reference_scripts.py +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dkitchen
3
- Version: 0.6.1
4
- Summary: A multi-agent workflow for research repos, with the ding CLI for messaging and waking agent sessions
3
+ Version: 0.6.2
4
+ Summary: DIY your own multi-agent workflow with Claude Code and Codex; includes the ding CLI for messaging and waking agent sessions
5
5
  Author: 917Dhj
6
6
  License-Expression: MIT
7
7
  Project-URL: Homepage, https://github.com/917Dhj/dkitchen
@@ -69,7 +69,7 @@ dkitchen sets up your agents the same way. You are the head chef.
69
69
  ## 🧑‍🍳 The kitchen
70
70
 
71
71
  <p align="center">
72
- <img src="https://raw.githubusercontent.com/917Dhj/dkitchen/main/docs/assets/kitchen.gif" width="100%" alt="A pixel-art kitchen: you talk a design through with the designer, the verifier checks the ticket, the orchestrator rings the bell to start a Codex executor on free GPUs, reviews and merges a PR, and brings you one decision to approve">
72
+ <img src="https://raw.githubusercontent.com/917Dhj/dkitchen/main/docs/assets/kitchen.webp" width="100%" alt="A pixel-art kitchen: you agree a plan with the designer, the orchestrator rings the bell to start a Codex executor on free GPUs, an executor asks the designer directly, the verifier reviews a PR and the orchestrator merges it; then you go to bed, the kitchen keeps cooking on your night orders, and in the morning it brings you one decision">
73
73
  </p>
74
74
 
75
75
  | Role | In a kitchen | What it does | Runs on |
@@ -35,7 +35,7 @@ dkitchen sets up your agents the same way. You are the head chef.
35
35
  ## 🧑‍🍳 The kitchen
36
36
 
37
37
  <p align="center">
38
- <img src="https://raw.githubusercontent.com/917Dhj/dkitchen/main/docs/assets/kitchen.gif" width="100%" alt="A pixel-art kitchen: you talk a design through with the designer, the verifier checks the ticket, the orchestrator rings the bell to start a Codex executor on free GPUs, reviews and merges a PR, and brings you one decision to approve">
38
+ <img src="https://raw.githubusercontent.com/917Dhj/dkitchen/main/docs/assets/kitchen.webp" width="100%" alt="A pixel-art kitchen: you agree a plan with the designer, the orchestrator rings the bell to start a Codex executor on free GPUs, an executor asks the designer directly, the verifier reviews a PR and the orchestrator merges it; then you go to bed, the kitchen keeps cooking on your night orders, and in the morning it brings you one decision">
39
39
  </p>
40
40
 
41
41
  | Role | In a kitchen | What it does | Runs on |
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "dkitchen"
7
- version = "0.6.1"
8
- description = "A multi-agent workflow for research repos, with the ding CLI for messaging and waking agent sessions"
7
+ version = "0.6.2"
8
+ description = "DIY your own multi-agent workflow with Claude Code and Codex; includes the ding CLI for messaging and waking agent sessions"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
11
11
  license = "MIT"
@@ -191,6 +191,7 @@ class Rule:
191
191
  class Launch:
192
192
  preflight: tuple[str, ...] = ()
193
193
  preflight_timeout: float = 300
194
+ keep_days: float = 14
194
195
 
195
196
 
196
197
  @dataclass(frozen=True)
@@ -371,6 +372,10 @@ def section(cls, values: object, name: str):
371
372
  if (isinstance(value, bool) or not isinstance(value, (int, float))
372
373
  or not math.isfinite(value) or value <= 0):
373
374
  raise ValueError(f"{FILE}: [launch] preflight_timeout must be a positive finite number of seconds")
375
+ elif key == "keep_days":
376
+ if (isinstance(value, bool) or not isinstance(value, (int, float))
377
+ or not math.isfinite(value) or value < 0):
378
+ raise ValueError(f"{FILE}: [launch] keep_days must be a nonnegative finite number of days")
374
379
  elif key in {"idle_minutes", "design_answer_minutes", "unrouted_wait_minutes"}:
375
380
  if (isinstance(value, bool) or not isinstance(value, (int, float))
376
381
  or not math.isfinite(value) or value < 0):
@@ -1595,6 +1595,45 @@ def launch_preflight(args, command: list[str], record: Path, launch_id: str, set
1595
1595
  return True
1596
1596
 
1597
1597
 
1598
+ LAUNCH_LOG = re.compile(r"(?P<name>[A-Za-z0-9][A-Za-z0-9_-]{0,63})-[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}\.log")
1599
+
1600
+
1601
+ def prune_launch_logs(directory: Path, keep_days: float, tmux: str) -> None:
1602
+ """Delete launch logs untouched for keep_days, except those of a ding-NAME session still open."""
1603
+ if not keep_days:
1604
+ return
1605
+ cutoff = time.time() - keep_days * 86400
1606
+ old = []
1607
+ for path in directory.glob("*.log"):
1608
+ match = LAUNCH_LOG.fullmatch(path.name)
1609
+ try:
1610
+ if match is not None and path.stat().st_mtime < cutoff:
1611
+ old.append((path, match["name"]))
1612
+ except OSError:
1613
+ continue
1614
+ if not old:
1615
+ return
1616
+ try:
1617
+ result = subprocess.run([tmux, "list-sessions", "-F", "#{session_name}"],
1618
+ capture_output=True, text=True, timeout=10, check=False)
1619
+ except (OSError, subprocess.TimeoutExpired) as exc:
1620
+ print(f"ding: launch logs not pruned: {exc}", file=sys.stderr)
1621
+ return
1622
+ if result.returncode and not re.search(r"no server running|error connecting", result.stderr or ""):
1623
+ print(f"ding: launch logs not pruned: {(result.stderr or '').strip() or result.returncode}", file=sys.stderr)
1624
+ return
1625
+ open_names = {line.removeprefix("ding-") for line in (result.stdout or "").splitlines() if line.startswith("ding-")}
1626
+ for path, name in old:
1627
+ if name in open_names:
1628
+ continue
1629
+ try:
1630
+ path.unlink()
1631
+ except FileNotFoundError:
1632
+ pass
1633
+ except OSError as exc:
1634
+ print(f"ding: launch log not pruned ({path}): {exc}", file=sys.stderr)
1635
+
1636
+
1598
1637
  def launch_task(args, command: list[str]) -> int:
1599
1638
  if not re.fullmatch(r"[A-Za-z0-9][A-Za-z0-9_-]{0,63}", args.name):
1600
1639
  raise ValueError("launch name must be 1-64 letters, digits, underscores or hyphens, starting with a letter or digit")
@@ -1610,14 +1649,16 @@ def launch_task(args, command: list[str]) -> int:
1610
1649
  launch_id = str(uuid4())
1611
1650
  launch_records = (run_registry().parent / "launch-records").resolve()
1612
1651
  record = (Path(args.record) if args.record else launch_records / f"{launch_id}.jsonl").resolve()
1652
+ log = launch_records / f"{args.name}-{launch_id}.log"
1613
1653
  message = message_text(args.message if args.message is not None else
1614
- f"Task {args.name} exited; inspect {record}", args.message_file, args.sender)
1654
+ f"Task {args.name} exited; log: {log}; record: {record}", args.message_file, args.sender)
1615
1655
  inner = [os.path.abspath(sys.executable), str(Path(__file__).resolve()), "run", thread_id,
1616
1656
  "--record", str(record)]
1617
1657
  if getattr(args, "progress", None):
1618
1658
  inner += ["--progress", str(Path(args.progress).resolve())]
1619
1659
  launch_records.mkdir(parents=True, exist_ok=True, mode=0o700)
1620
1660
  launch_records.chmod(0o700)
1661
+ prune_launch_logs(launch_records, settings.keep_days, tmux)
1621
1662
  if not launch_preflight(args, command, record, launch_id, settings):
1622
1663
  return 1
1623
1664
  message_path = launch_records / f"{launch_id}.message.txt"
@@ -1626,6 +1667,7 @@ def launch_task(args, command: list[str]) -> int:
1626
1667
  handle.write(message)
1627
1668
  handle.flush()
1628
1669
  os.fsync(handle.fileno())
1670
+ os.close(os.open(log, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o600))
1629
1671
  _fsync_directory(launch_records)
1630
1672
  inner.extend(["--message-file", str(message_path)])
1631
1673
  if args.socket is not None:
@@ -1641,8 +1683,10 @@ def launch_task(args, command: list[str]) -> int:
1641
1683
  "-n", args.name, "-c", str(Path.cwd())]
1642
1684
  for key, value in environment.items():
1643
1685
  arguments.extend(["-e", f"{key}={value}"])
1644
- prelude = (f'{shlex.quote(str(Path(tmux).absolute()))} set-option -p -t "$TMUX_PANE" '
1645
- f'remain-on-exit on && exec {shlex.join(inner)}')
1686
+ # The pane closes when the job exits, however it exits; its output stays in the log.
1687
+ pipe = shlex.quote(f"cat >> {shlex.quote(str(log))}")
1688
+ prelude = (f'{shlex.quote(str(Path(tmux).absolute()))} pipe-pane -o -t "$TMUX_PANE" {pipe} '
1689
+ f'&& exec {shlex.join(inner)}')
1646
1690
  arguments.extend(["-P", "-F", "#{session_name}\t#{window_name}", "/bin/sh", "-c", prelude])
1647
1691
  # tmux treats a trailing semicolon as a command separator even in argv values.
1648
1692
  arguments = [value[:-1] + r"\;" if value.endswith(";") else value for value in arguments]
@@ -1652,7 +1696,7 @@ def launch_task(args, command: list[str]) -> int:
1652
1696
  raise RuntimeError("tmux launch timed out; task creation is unconfirmed; inspect tmux and run records before retrying") from exc
1653
1697
  if result.returncode:
1654
1698
  raise ValueError(f"tmux launch failed: {result.stderr.strip() or result.returncode}")
1655
- print(f"ding: created ding-{args.name}/{args.name}; record: {record}")
1699
+ print(f"ding: created ding-{args.name}/{args.name}; log: {log}; record: {record}")
1656
1700
  return 0
1657
1701
 
1658
1702
 
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dkitchen
3
- Version: 0.6.1
4
- Summary: A multi-agent workflow for research repos, with the ding CLI for messaging and waking agent sessions
3
+ Version: 0.6.2
4
+ Summary: DIY your own multi-agent workflow with Claude Code and Codex; includes the ding CLI for messaging and waking agent sessions
5
5
  Author: 917Dhj
6
6
  License-Expression: MIT
7
7
  Project-URL: Homepage, https://github.com/917Dhj/dkitchen
@@ -69,7 +69,7 @@ dkitchen sets up your agents the same way. You are the head chef.
69
69
  ## 🧑‍🍳 The kitchen
70
70
 
71
71
  <p align="center">
72
- <img src="https://raw.githubusercontent.com/917Dhj/dkitchen/main/docs/assets/kitchen.gif" width="100%" alt="A pixel-art kitchen: you talk a design through with the designer, the verifier checks the ticket, the orchestrator rings the bell to start a Codex executor on free GPUs, reviews and merges a PR, and brings you one decision to approve">
72
+ <img src="https://raw.githubusercontent.com/917Dhj/dkitchen/main/docs/assets/kitchen.webp" width="100%" alt="A pixel-art kitchen: you agree a plan with the designer, the orchestrator rings the bell to start a Codex executor on free GPUs, an executor asks the designer directly, the verifier reviews a PR and the orchestrator merges it; then you go to bed, the kitchen keeps cooking on your night orders, and in the morning it brings you one decision">
73
73
  </p>
74
74
 
75
75
  | Role | In a kitchen | What it does | Runs on |
@@ -2673,8 +2673,13 @@ def test_launch_captures_caller_session_environment_command_and_paths(tmp_path,
2673
2673
  r"HOME=/caller/home\;", "XDG_STATE_HOME=" + str(cwd / "caller-state") + r"\;",
2674
2674
  "PYTHONPATH="]
2675
2675
  assert argv[-3:-1] == ["/bin/sh", "-c"]
2676
- assert argv[-1].split(" && exec ", 1)[0] == (
2677
- '/fake/bin/tmux set-option -p -t "$TMUX_PANE" remain-on-exit on')
2676
+ assert "remain-on-exit" not in argv[-1]
2677
+ pipe = shlex.split(argv[-1].split(" && exec ", 1)[0])
2678
+ assert pipe[:5] == ["/fake/bin/tmux", "pipe-pane", "-o", "-t", "$TMUX_PANE"]
2679
+ log = cwd / "caller-state;" / "ding/launch-records" / shlex.split(pipe[5])[2].rsplit("/", 1)[1]
2680
+ assert shlex.split(pipe[5]) == ["cat", ">>", str(log)]
2681
+ assert ding.LAUNCH_LOG.fullmatch(log.name)["name"] == "CPU_193"
2682
+ assert log.read_bytes() == b"" and stat.S_IMODE(log.stat().st_mode) == 0o600
2678
2683
  inner = shlex.split(argv[-1].split(" && exec ", 1)[1])
2679
2684
  assert inner[:4] == ["/venv/bin/python", str(Path(ding.__file__).resolve()), "run", THREAD_ID]
2680
2685
  assert inner[inner.index("--record") + 1] == str(cwd / "exit.jsonl")
@@ -2710,7 +2715,9 @@ def test_launch_materializes_message_once_and_defaults_to_unique_records(tmp_pat
2710
2715
  record = Path(inner[inner.index("--record") + 1])
2711
2716
  records_seen.append(record)
2712
2717
  materialized = Path(inner[inner.index("--message-file") + 1])
2713
- assert materialized.read_text() == (f"Task job exited; inspect {record}" if text is None else text)
2718
+ log = record.parent / f"job-{record.stem}.log"
2719
+ assert log.exists()
2720
+ assert materialized.read_text() == (f"Task job exited; log: {log}; record: {record}" if text is None else text)
2714
2721
  assert record.is_absolute()
2715
2722
  assert record.parent == ding.run_registry().parent / "launch-records"
2716
2723
  assert materialized.stem.removesuffix(".message") == record.stem
@@ -2763,6 +2770,80 @@ def test_launch_collision_does_not_retry_or_modify_tmux(monkeypatch, fake_tmux,
2763
2770
  assert "duplicate session" in capsys.readouterr().err
2764
2771
 
2765
2772
 
2773
+ def launch_logs(directory, names, age_days):
2774
+ directory.mkdir(parents=True, exist_ok=True)
2775
+ paths = []
2776
+ for name in names:
2777
+ path = directory / f"{name}-{ding.uuid4()}.log"
2778
+ path.write_text("output")
2779
+ stamp = ding.time.time() - age_days * 86400
2780
+ ding.os.utime(path, (stamp, stamp))
2781
+ paths.append(path)
2782
+ return paths
2783
+
2784
+
2785
+ def test_prune_launch_logs_keeps_fresh_open_and_foreign_files(tmp_path, monkeypatch):
2786
+ directory = tmp_path / "launch-records"
2787
+ old_done, old_open = launch_logs(directory, ["done", "still-open"], 20)
2788
+ (fresh,) = launch_logs(directory, ["fresh"], 1)
2789
+ foreign = directory / "notes.log"
2790
+ foreign.write_text("x")
2791
+ ding.os.utime(foreign, (0, 0))
2792
+ record = directory / f"{ding.uuid4()}.jsonl"
2793
+ record.write_text("{}")
2794
+ ding.os.utime(record, (0, 0))
2795
+ calls = []
2796
+ monkeypatch.setattr(ding.subprocess, "run", lambda argv, **kwargs: calls.append(argv) or SimpleNamespace(
2797
+ returncode=0, stdout="cloudflare_ssh\nding-still-open\n", stderr=""))
2798
+ ding.prune_launch_logs(directory, 14, "/fake/bin/tmux")
2799
+ assert calls == [["/fake/bin/tmux", "list-sessions", "-F", "#{session_name}"]]
2800
+ assert not old_done.exists()
2801
+ assert old_open.exists() and fresh.exists() and foreign.exists() and record.exists()
2802
+
2803
+
2804
+ def test_prune_launch_logs_without_a_tmux_server_deletes_old_logs(tmp_path, monkeypatch):
2805
+ (old,) = launch_logs(tmp_path, ["done"], 20)
2806
+ monkeypatch.setattr(ding.subprocess, "run", lambda argv, **kwargs: SimpleNamespace(
2807
+ returncode=1, stdout="", stderr="no server running on /tmp/tmux-0/default"))
2808
+ ding.prune_launch_logs(tmp_path, 14, "/fake/bin/tmux")
2809
+ assert not old.exists()
2810
+
2811
+
2812
+ @pytest.mark.parametrize("outcome", ["error", "timeout"])
2813
+ def test_prune_launch_logs_keeps_everything_when_tmux_cannot_answer(tmp_path, monkeypatch, capsys, outcome):
2814
+ (old,) = launch_logs(tmp_path, ["done"], 20)
2815
+
2816
+ def run(argv, **kwargs):
2817
+ if outcome == "timeout":
2818
+ raise subprocess.TimeoutExpired(argv, 10)
2819
+ return SimpleNamespace(returncode=1, stdout="", stderr="permission denied")
2820
+
2821
+ monkeypatch.setattr(ding.subprocess, "run", run)
2822
+ ding.prune_launch_logs(tmp_path, 14, "/fake/bin/tmux")
2823
+ assert old.exists()
2824
+ assert "launch logs not pruned" in capsys.readouterr().err
2825
+
2826
+
2827
+ @pytest.mark.parametrize("keep_days,age", [(0, 1000), (14, 1)])
2828
+ def test_prune_launch_logs_asks_tmux_only_when_a_log_is_due(tmp_path, monkeypatch, keep_days, age):
2829
+ (log,) = launch_logs(tmp_path, ["done"], age)
2830
+ monkeypatch.setattr(ding.subprocess, "run", lambda argv, **kwargs: pytest.fail("tmux was asked"))
2831
+ ding.prune_launch_logs(tmp_path, keep_days, "/fake/bin/tmux")
2832
+ assert log.exists()
2833
+
2834
+
2835
+ def test_launch_prunes_old_logs_with_configured_keep_days(tmp_path, monkeypatch, fake_tmux):
2836
+ monkeypatch.setenv("CODEX_THREAD_ID", THREAD_ID)
2837
+ monkeypatch.chdir(tmp_path)
2838
+ (tmp_path / ".dkitchen.toml").write_text("[launch]\nkeep_days = 30\n")
2839
+ directory = ding.run_registry().parent / "launch-records"
2840
+ (recent,) = launch_logs(directory, ["recent"], 20)
2841
+ (old,) = launch_logs(directory, ["old"], 40)
2842
+ assert ding.main(["launch", "job", "--", "task"]) == 0
2843
+ assert [argv[1] for argv, _ in fake_tmux] == ["list-sessions", "new-session"]
2844
+ assert recent.exists() and not old.exists()
2845
+
2846
+
2766
2847
  def audit_process(pid, ppid=1, argv=None, age=1000, cpu=50, uid=None, state="S"):
2767
2848
  return {"pid": pid, "ppid": ppid, "argv": argv or ["python", "train.py"],
2768
2849
  "age": age, "cpu": cpu, "uid": ding.os.geteuid() if uid is None else uid, "state": state}
@@ -1002,6 +1002,8 @@ def test_launch_config_preserves_argv_and_defaults(tmp_path):
1002
1002
  loaded = settings(tmp_path, '[launch]\npreflight = ["python", "", "two words"]')
1003
1003
  assert loaded.launch.preflight == ("python", "", "two words")
1004
1004
  assert loaded.launch.preflight_timeout == 300
1005
+ assert loaded.launch.keep_days == 14
1006
+ assert settings(tmp_path, "[launch]\nkeep_days = 0").launch.keep_days == 0
1005
1007
 
1006
1008
 
1007
1009
  @pytest.mark.parametrize("text, error", [
@@ -1016,6 +1018,10 @@ def test_launch_config_preserves_argv_and_defaults(tmp_path):
1016
1018
  ('preflight_timeout = "300"', "positive finite"),
1017
1019
  ('preflight_timeout = inf', "positive finite"),
1018
1020
  ('preflight_timeout = nan', "positive finite"),
1021
+ ('keep_days = -1', "nonnegative finite"),
1022
+ ('keep_days = true', "nonnegative finite"),
1023
+ ('keep_days = "14"', "nonnegative finite"),
1024
+ ('keep_days = inf', "nonnegative finite"),
1019
1025
  ('prefligth = ["python"]', "unknown keys"),
1020
1026
  ])
1021
1027
  def test_bad_launch_config_is_refused(tmp_path, text, error):
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes