@jesdi/skills 0.0.52 → 0.0.53

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jesdi/skills",
3
- "version": "0.0.52",
3
+ "version": "0.0.53",
4
4
  "description": "jesdi's agent skills (content package consumed by @jesdi/skills-cli)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -19,7 +19,7 @@ A comment in the code is for a line that looks wrong or removable without it.
19
19
  | `driver_report.py` | Validation of one agent report against its schema, git and the agent's log |
20
20
  | `driver_review.py` | The locked-file check of a ticket's own tests, the routing of findings, mutation proofs |
21
21
  | `driver_merge.py` | Merges by git plumbing, the locked-file check of a landing, the move of the PR ref |
22
- | `driver_gate.py` | One run of the gate command and its record |
22
+ | `driver_gate.py` | One gate of a commit: the command, once more when a signal ended it, and its record |
23
23
  | `driver_slots.py` | The worktrees that tickets run in, and the `git` helper |
24
24
  | `driver_state.py` | `state.json` (the resume contract) and the kernel lock |
25
25
  | `driver_names.py` | The names of one run: its ticket branches, its recovery ref and its lock file |
@@ -83,7 +83,7 @@ Everything is under `.agent/`, which is never committed.
83
83
  | `.agent/implement/decisions.json` | The open questions and their `revision`. Written only after a stop. |
84
84
  | `.agent/implement/<NN>/` | One folder for each ticket. |
85
85
  | `.agent/implement/<NN>/<role>-<K>.json`, `.log`, `.prompt.md` | The report, the log and the prompt of one agent. K is the fix round. |
86
- | `.agent/implement/<NN>/gate-<sha7>.log` | One gate record: start, commit, status, command, output, exit, the state after the command, end. |
86
+ | `.agent/implement/<NN>/gate-<sha7>.log` | One gate record: start, commit, status, command, output, exit, the state after the command, end. A command that a signal ended, with the tree clean and HEAD unmoved, did not judge the commit: the driver runs it once more, that run overwrites the record, and the ledger says the gate was killed by the signal and runs again. A signal ended the command when its exit is negative, or when it is 128+N for N in SIGHUP (1), SIGINT (2), SIGKILL (9) or SIGTERM (15): the gate runs in `/bin/sh -c`, and a shell that does not exec the command, as Ubuntu's dash does not, outlives its killed child and exits with 128+N. Any other exit, 142 (128+SIGALRM) among them, is a red record with no second run. A second signal leaves the record red. |
87
87
  | `.agent/implement/<NN>/findings-<K>.json` | The merged findings of the review after fix round K, or the red gate of round K. |
88
88
  | `.agent/implement/final/` | The same files for the end of run, and `pr-body.md`: the pr-writer's body, then the facts of the run. |
89
89
  | `.agent/implement/pycache/` | Compiled Python of the gate, kept out of the slots. |
@@ -109,6 +109,7 @@ A ticket is ready when each ticket in its **Blocked by** line is merged and no r
109
109
  Rules for each agent:
110
110
 
111
111
  - A call blocks until the agent ends. The driver does not poll.
112
+ - An agent stops only the processes it started and their child processes, by PID, and never kills a process it did not start, nor uses `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. A process it did not start that blocks it goes into its concerns.
112
113
  - An agent gets one rerun: after a rejected report, after a timeout, or after it left the ticket branch. The rerun prompt is the first prompt plus the reason.
113
114
  - A report with status `BLOCKED` or `NEEDS_CONTEXT` blocks the ticket.
114
115
  - A BLOCKED ticket stops the tickets that it blocks. All other tickets run on.
@@ -1,11 +1,15 @@
1
1
  """The gate: the repo's one check command, run by the driver on the commit it is about to trust.
2
2
 
3
3
  A gate record is `<folder>/gate-<first 7 hex of the commit>.log`. It is green only for exit 0 on a tree that is
4
- clean before the command and after it, with HEAD still on the commit.
4
+ clean before the command and after it, with HEAD still on the commit. A command that a signal ended, on a clean tree
5
+ with HEAD unmoved, did not judge the commit: it runs once more, and that run overwrites the record. A signal ended the
6
+ command when its exit is negative, or when it is 128+N for N in SIGHUP, SIGINT, SIGKILL or SIGTERM: a shell that does
7
+ not exec its last command, as dash does not, outlives the killed child and exits with 128+N.
5
8
  """
6
9
  from __future__ import annotations
7
10
 
8
11
  import os
12
+ import signal
9
13
  import subprocess
10
14
  from datetime import datetime, timezone
11
15
  from pathlib import Path
@@ -25,18 +29,25 @@ def _after(slot: str, commit: str) -> str:
25
29
  return "not clean\n" + "".join(f" {line}\n" for line in status.splitlines()).rstrip("\n") if status else "clean"
26
30
 
27
31
 
32
+ _KILLS = {signal.SIGHUP, signal.SIGINT, signal.SIGKILL, signal.SIGTERM}
33
+
34
+
35
+ def _signal(code: int | str) -> int | None:
36
+ """The signal that ended the command: from a negative exit, or from 128+N as a shell reports its killed child."""
37
+ if not isinstance(code, int):
38
+ return None
39
+ if code < 0:
40
+ return -code
41
+ return code - 128 if code - 128 in _KILLS else None
42
+
43
+
28
44
  def record_path(folder: Path, commit: str) -> Path:
29
45
  return folder / f"gate-{commit[:7]}.log"
30
46
 
31
47
 
32
- def run(command: str, slot: str, folder: Path, pr_branch: str) -> tuple[bool, Path]:
33
- """Gate the HEAD of `slot`. Returns (green, the record)."""
34
- commit = head(slot)
48
+ def _attempt(command: str, slot: str, commit: str, record: Path, env: dict) -> tuple[int | str, str]:
49
+ """Run the command once into `record`. Returns (the exit code or "not run", the state after it)."""
35
50
  status = git(slot, "status", "--short").stdout
36
- folder.mkdir(parents=True, exist_ok=True)
37
- record = record_path(folder, commit)
38
- # The cache of compiled Python stays out of the slot, so the gate leaves the tree clean.
39
- env = dict(os.environ, IMPLEMENT_SPEC_BASE=pr_branch, PYTHONPYCACHEPREFIX=str(folder.parent.resolve() / "pycache"))
40
51
  with record.open("w") as out:
41
52
  out.write(f"start: {_now()}\ncommit: {commit}\nstatus: {'not clean' if status else 'clean'}\n")
42
53
  out.writelines(f" {line}\n" for line in status.splitlines())
@@ -48,4 +59,21 @@ def run(command: str, slot: str, folder: Path, pr_branch: str) -> tuple[bool, Pa
48
59
  ).returncode
49
60
  after = "not run" if status else _after(slot, commit)
50
61
  out.write(f"\nexit: {code}\nafter: {after}\nend: {_now()}\n")
51
- return code == 0 and after == "clean", record
62
+ return code, after
63
+
64
+
65
+ def run(command: str, slot: str, folder: Path, pr_branch: str) -> tuple[bool, Path, list[str]]:
66
+ """Gate the HEAD of `slot`. Returns (green, the record, a ledger sentence per gate that a signal ended)."""
67
+ commit = head(slot)
68
+ folder.mkdir(parents=True, exist_ok=True)
69
+ record = record_path(folder, commit)
70
+ # The cache of compiled Python stays out of the slot, so the gate leaves the tree clean.
71
+ env = dict(os.environ, IMPLEMENT_SPEC_BASE=pr_branch, PYTHONPYCACHEPREFIX=str(folder.parent.resolve() / "pycache"))
72
+ code, after = _attempt(command, slot, commit, record, env)
73
+ killed = []
74
+ # A process outside the gate can kill it, as a `pkill -f` of another slot does: that run judged nothing.
75
+ number = _signal(code)
76
+ if number and after == "clean":
77
+ killed.append(f"the gate of {commit[:7]} was killed by signal {number} and runs again")
78
+ code, after = _attempt(command, slot, commit, record, env)
79
+ return code == 0 and after == "clean", record, killed
@@ -150,7 +150,9 @@ class Run:
150
150
  at = driver_slots.head(slot)
151
151
  if at != commit:
152
152
  raise Blocked(f"the slot is at {at[:7]}, not at {commit[:7]}: the gate did not run")
153
- green, record = driver_gate.run(self.args.gate, slot, OUT / number, self.pr)
153
+ green, record, killed = driver_gate.run(self.args.gate, slot, OUT / number, self.pr)
154
+ for sentence in killed:
155
+ ledger(f"{_owner(number)}: {sentence}.")
154
156
 
155
157
  def count(state: dict) -> None:
156
158
  state["run"]["gates"] += 1
@@ -29,4 +29,5 @@ Write one JSON report at {report} that matches this schema:
29
29
  }
30
30
  ```
31
31
 
32
+ Stop only processes you started and their child processes, by PID (for example the PID of a job you put in the background, or its process group). Never kill a process you did not start, and never use `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. If a process you did not start blocks you, report it in your concerns and do not kill it.
32
33
  Never run `git stash`, never reset, and never check out another branch: worktrees share one stash and one ref store.
@@ -34,4 +34,5 @@ Write one JSON report at {report} that matches this schema:
34
34
  }
35
35
  ```
36
36
 
37
+ Stop only processes you started and their child processes, by PID (for example the PID of a job you put in the background, or its process group). Never kill a process you did not start, and never use `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. If a process you did not start blocks you, report it in your concerns and do not kill it.
37
38
  Never run `git stash`, never reset, and never check out another branch: worktrees share one stash and one ref store.
@@ -35,4 +35,5 @@ Write one JSON report at {report} that matches this schema:
35
35
 
36
36
  Run git as plain `git` in this worktree, and leave the git config as it is: all worktrees read one shared config, and one key written there, such as a `core.worktree`, breaks git in each of them. So never set GIT_DIR or GIT_WORK_TREE, and never write with `git config`.
37
37
  To run a check off this worktree, read the gate record of the driver, {gate}, or make a copy with `git worktree add --detach <temp dir> {start_sha}`, run the check there, and remove the copy with `git worktree remove --force <temp dir>` before you report.
38
+ Stop only processes you started and their child processes, by PID (for example the PID of a job you put in the background, or its process group). Never kill a process you did not start, and never use `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. If a process you did not start blocks you, report it in your concerns and do not kill it.
38
39
  Never run `git stash`, never reset, and never check out another branch: worktrees share one stash and one ref store.
@@ -35,4 +35,5 @@ Write one JSON report at {report} that matches this schema:
35
35
  }
36
36
  ```
37
37
 
38
+ Stop only processes you started and their child processes, by PID (for example the PID of a job you put in the background, or its process group). Never kill a process you did not start, and never use `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. If a process you did not start blocks you, report it in your concerns and do not kill it.
38
39
  Never run `git stash`, never reset, and never check out another branch: worktrees share one stash and one ref store.
@@ -31,4 +31,5 @@ Write one JSON report at {report} that matches this schema:
31
31
  }
32
32
  ```
33
33
 
34
+ Stop only processes you started and their child processes, by PID (for example the PID of a job you put in the background, or its process group). Never kill a process you did not start, and never use `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. If a process you did not start blocks you, report it in your concerns and do not kill it.
34
35
  Never run `git stash`, never reset, and never check out another branch: worktrees share one stash and one ref store.
@@ -30,4 +30,5 @@ Write one JSON report at {report} that matches this schema:
30
30
  }
31
31
  ```
32
32
 
33
+ Stop only processes you started and their child processes, by PID (for example the PID of a job you put in the background, or its process group). Never kill a process you did not start, and never use `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. If a process you did not start blocks you, report it in your concerns and do not kill it.
33
34
  Never run `git stash`, never reset, and never check out another branch: worktrees share one stash and one ref store.
@@ -33,4 +33,5 @@ Write one JSON report at {report}. When your sandbox is read-only, give the JSON
33
33
 
34
34
  Run git as plain `git` in this worktree, and leave the git config as it is: all worktrees read one shared config, and one key written there, such as a `core.worktree`, breaks git in each of them. So never set GIT_DIR or GIT_WORK_TREE, and never write with `git config`.
35
35
  To run a check off this worktree, read the gate record of the driver, {gate_record}, or make a copy with `git worktree add --detach <temp dir> {start_sha}`, run the check there, and remove the copy with `git worktree remove --force <temp dir>` before you report.
36
+ Stop only processes you started and their child processes, by PID (for example the PID of a job you put in the background, or its process group). Never kill a process you did not start, and never use `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. If a process you did not start blocks you, report it in your concerns and do not kill it.
36
37
  Never run `git stash`, never reset, and never check out another branch: worktrees share one stash and one ref store.
@@ -33,4 +33,5 @@ Write one JSON report at {report} that matches this schema:
33
33
  }
34
34
  ```
35
35
 
36
+ Stop only processes you started and their child processes, by PID (for example the PID of a job you put in the background, or its process group). Never kill a process you did not start, and never use `pkill`, `killall` or a `kill` by name or pattern: other slots and sessions share the machine. If a process you did not start blocks you, report it in your concerns and do not kill it.
36
37
  Never run `git stash`, never reset, and never check out another branch: worktrees share one stash and one ref store.
@@ -290,6 +290,16 @@ def test_every_prompt_ends_with_report_path_schema_and_the_never_rule(env, role,
290
290
  assert report in prompt
291
291
 
292
292
 
293
+ @pytest.mark.parametrize("role", ["test-writer", "implementer", "fixer", "conflict", "reviewer", "final-reviewer",
294
+ "final-fixer", "rebase-conflict"])
295
+ def test_each_role_that_runs_commands_stops_only_its_own_processes(role):
296
+ """Issue 101: a `pkill -f` of one slot killed the gate of another."""
297
+ text = (SKILL / f"prompts/{role}.md").read_text()
298
+ assert "Stop only processes you started and their child processes, by PID" in text
299
+ assert "Never kill a process you did not start, and never use `pkill`, `killall` or a `kill` by name" in text
300
+ assert "If a process you did not start blocks you, report it in your concerns and do not kill it." in text
301
+
302
+
293
303
  def test_no_report_is_a_violation_with_one_rerun_then_blocked(env):
294
304
  w = World(env, refactor=True)
295
305
  blocked(w.run({"implementer": [{}, {}, impl()]}))
@@ -4,6 +4,7 @@ import json
4
4
  import os
5
5
  import shutil
6
6
  import subprocess
7
+ import sys
7
8
 
8
9
  import jsonschema
9
10
  import pytest
@@ -23,10 +24,13 @@ from test_walk import impl, plan, tw
23
24
  class Inside(test_review.Review):
24
25
  """The rig of test_review with the driver called in this process."""
25
26
 
27
+ command = "{gate}" # the gate command; `{gate}` is the rig's gate script
28
+
26
29
  def run(self, steps, *extra, parallel="2", watch=False):
27
30
  (self.rig / "plan.json").write_text(json.dumps(steps))
28
- args = ["--tickets", ".agent/tickets", "--gate", str(self.rig / "gate"), "--spec", "specs/csv/spec.md",
29
- "--models", str(self.models), "--runner", str(self.rig / "run-agent"), "--parallel", parallel, *extra]
31
+ args = ["--tickets", ".agent/tickets", "--gate", self.command.format(gate=self.rig / "gate"), "--spec",
32
+ "specs/csv/spec.md", "--models", str(self.models), "--runner", str(self.rig / "run-agent"), "--parallel",
33
+ parallel, *extra]
30
34
  here = os.getcwd()
31
35
  os.chdir(self.repo)
32
36
  try:
@@ -530,6 +534,76 @@ def test_a_red_gate_on_the_implementer_commit_starts_fix_round_1_with_the_record
530
534
  assert gate["title"] == f"the gate is red on {tip[:7]}" and record in gate["evidence"]
531
535
  assert "findings-0.json" in rig.prompt("fixer-1") and rig.state()["tickets"]["01"]["phase"] == "merged"
532
536
  assert "The fix is" not in rig.prompt("reviewer-1") # no review saw the implementer commit: a full review
537
+ assert [gate["commit"] for gate in rig.gates()].count(tip) == 1 and not rig.led("killed by signal")
538
+
539
+
540
+ def killed(rig, subject, times, end="os.kill(os.getpid(), signal.SIGTERM)"):
541
+ """The rig's gate, ended by `end` (SIGTERM by default) on its first `times` runs on the commit with `subject`, as a
542
+ `pkill -f` of another slot ends it (issue 101). A killed run logs nothing into `<rig>/gates/`."""
543
+ gate, real = rig.rig / "gate", rig.rig / "real-gate"
544
+ gate.rename(real)
545
+ gate.write_text(f"""#!{sys.executable}
546
+ import os, signal, subprocess, sys
547
+ from pathlib import Path
548
+ kills = Path(__file__).with_name("kills")
549
+ subject = subprocess.run(["git", "log", "-1", "--format=%s"], capture_output=True, text=True).stdout.strip()
550
+ if subject == {subject!r} and len(kills.read_text() if kills.exists() else "") < {times}:
551
+ with kills.open("a") as file:
552
+ file.write("x")
553
+ {end}
554
+ os.execv({str(real)!r}, [{str(real)!r}])
555
+ """)
556
+ gate.chmod(0o755)
557
+ return rig
558
+
559
+
560
+ # How the gate's shell reports a SIGTERM of the command: `exec` replaces the shell, so the exit is -15; a shell that
561
+ # outlives its child, as Ubuntu's dash does even for one simple command, exits 128+15.
562
+ SHAPES = {"exec": ("exec {gate}", -15), "compound": ("{gate}; exit $?", 143)}
563
+
564
+
565
+ def shaped(tmp_path, command):
566
+ rig = Inside(tmp_path)
567
+ rig.command = command
568
+ return rig
569
+
570
+
571
+ @pytest.mark.parametrize("command, code", SHAPES.values(), ids=SHAPES)
572
+ def test_a_gate_killed_by_a_signal_runs_once_more_and_its_green_second_run_counts(tmp_path, command, code):
573
+ rig = killed(shaped(tmp_path, command), "feat: 01 rows", 1).run(plan(**{"01/reviewer": [review("01")]}))
574
+ assert rig.code == 0, rig.ledger()
575
+ tip = rig.sha("01", "implementer")
576
+ assert [call["role"] for call in rig.calls("01")] == ["test-writer", "implementer", "reviewer"]
577
+ assert rig.led("killed by signal") == [f"Ticket 01: the gate of {tip[:7]} was killed by signal 15 and runs again."]
578
+ assert rig.led(f"Ticket 01: the gate is green on {tip[:7]}") and not rig.led("finding of kind")
579
+ assert json.loads((rig.folder() / "findings-0.json").read_text()) == [] # the review's, with no gate finding
580
+ record = (rig.folder() / f"gate-{tip[:7]}.log").read_text()
581
+ assert record.count("exit: ") == 1 and "\nexit: 0\nafter: clean\n" in record # the second run overwrote it
582
+
583
+
584
+ @pytest.mark.parametrize("command, code", SHAPES.values(), ids=SHAPES)
585
+ def test_a_gate_killed_by_a_signal_twice_is_red(tmp_path, command, code):
586
+ rig = killed(shaped(tmp_path, command), "feat: 01 rows", 2)
587
+ rig.run(plan(**{"01/reviewer": [review("01")], "01/fixer": [fix("01", 1)]}))
588
+ assert rig.code == 0, rig.ledger()
589
+ tip = rig.sha("01", "implementer")
590
+ assert [call["role"] for call in rig.calls("01")] == ["test-writer", "implementer", "fixer", "reviewer"]
591
+ assert len(rig.led("killed by signal")) == 1 and tip not in [gate["commit"] for gate in rig.gates()]
592
+ (gate,) = json.loads((rig.folder() / "findings-0.json").read_text())
593
+ assert gate["title"] == f"the gate is red on {tip[:7]}"
594
+ assert f"\nexit: {code}\nafter: clean\n" in (rig.folder() / f"gate-{tip[:7]}.log").read_text()
595
+
596
+
597
+ @pytest.mark.parametrize("exit", [1, 142]) # 142 is 128+SIGALRM: a signal, but not one that kills a gate from outside
598
+ def test_a_gate_that_exits_with_any_other_code_is_red_without_running_again(tmp_path, exit):
599
+ rig = killed(shaped(tmp_path, "{gate}; exit $?"), "feat: 01 rows", 1, end=f"sys.exit({exit})")
600
+ rig.run(plan(**{"01/reviewer": [review("01")], "01/fixer": [fix("01", 1)]}))
601
+ assert rig.code == 0, rig.ledger()
602
+ tip = rig.sha("01", "implementer")
603
+ assert [call["role"] for call in rig.calls("01")] == ["test-writer", "implementer", "fixer", "reviewer"]
604
+ assert not rig.led("killed by signal") and tip not in [gate["commit"] for gate in rig.gates()]
605
+ record = (rig.folder() / f"gate-{tip[:7]}.log").read_text()
606
+ assert record.count("exit: ") == 1 and f"\nexit: {exit}\nafter: clean\n" in record
533
607
 
534
608
 
535
609
  def test_a_red_gate_on_the_fixer_commit_of_round_4_blocks_the_ticket(tmp_path):
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "generatedAt": "2026-10-19T11:13:23.574Z",
3
+ "generatedAt": "2026-10-19T23:09:36.924Z",
4
4
  "skills": [
5
5
  {
6
6
  "name": "backlog",
@@ -46,8 +46,8 @@
46
46
  },
47
47
  {
48
48
  "name": "implement-spec",
49
- "version": "0.1.27",
50
- "hash": "sha256-5cd78074157850b0abb3de812a51a911486bd5da29fe5f553a4838b25e61d30b",
49
+ "version": "0.1.28",
50
+ "hash": "sha256-bcdecd8970590a6678eec2601eccabadc23a7f92c9e9aba1887a67518f71dc2c",
51
51
  "description": "Implement a specification in code."
52
52
  },
53
53
  {