agent-bios 0.19.4 → 0.20.1

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 (162) hide show
  1. package/DEPENDENCIES.md +20 -5
  2. package/README.md +14 -19
  3. package/claude/agents/frontier.md +1 -1
  4. package/claude/guides/claude-prompting.md +475 -234
  5. package/claude/guides/cli-multi-model-workflow.md +8 -7
  6. package/claude/guides/gpt-prompting.md +319 -144
  7. package/claude/guides/session-distill-workflow.md +93 -43
  8. package/claude/guides/tooling-gotchas.md +3 -1
  9. package/codex/agents/frontier.toml +1 -1
  10. package/codex/agents/reviewer.toml +1 -1
  11. package/codex/agents/workhorse.toml +1 -1
  12. package/codex/guides/claude-prompting.md +475 -234
  13. package/codex/guides/cli-multi-model-workflow.md +8 -7
  14. package/codex/guides/gpt-prompting.md +319 -144
  15. package/codex/guides/session-distill-workflow.md +93 -43
  16. package/codex/guides/tooling-gotchas.md +3 -1
  17. package/compose/assemble.py +4 -1
  18. package/compose/canary.sh +8 -6
  19. package/compose/host_platform.py +158 -15
  20. package/compose/instructions-state.py +183 -41
  21. package/compose/instructions_install.py +222 -27
  22. package/compose/instructions_session.py +250 -75
  23. package/compose/instructions_setup_cli.py +2 -36
  24. package/compose/instructions_store.py +160 -3
  25. package/compose/instructions_transaction.py +29 -5
  26. package/docs/advanced-launch.md +5 -1
  27. package/docs/releases/0.20.0.md +102 -0
  28. package/docs/releases/0.20.1.md +76 -0
  29. package/install.sh +42 -14
  30. package/launch/agent-launch.py +152 -18
  31. package/launch/agent-launch.toml +28 -16
  32. package/launch/agent-launch.zsh +104 -13
  33. package/launch/claude_subcommands.py +179 -0
  34. package/launch/shell_integration.py +7 -1
  35. package/learn/collect-learning.py +60 -9
  36. package/learn/migrate-learnings.py +70 -4
  37. package/learn/redact.py +2 -1
  38. package/package.json +36 -3
  39. package/provenance.json +1 -1
  40. package/session-cost.py +80 -9
  41. package/session-distill/coverage.json +6 -0
  42. package/session-distill/distill.py +2575 -0
  43. package/session-distill/grammar/__init__.py +0 -0
  44. package/session-distill/grammar/owner_lines.py +874 -0
  45. package/session-distill/originators.json +9 -0
  46. package/session-distill/packets/cross_review.md +31 -0
  47. package/session-distill/packets/form.md +86 -0
  48. package/session-distill/packets/judge.md +81 -0
  49. package/session-distill/packets/placement_contract.md +90 -0
  50. package/session-distill/packets/propose.md +124 -0
  51. package/session-distill/packets/read.md +57 -0
  52. package/session-distill/packets/reconsider.md +53 -0
  53. package/session-distill/packets/s7b.md +65 -0
  54. package/session-distill/packets/s9b.md +39 -0
  55. package/session-distill/packets/stitch.md +35 -0
  56. package/session-distill/packets/sweep.md +33 -0
  57. package/session-distill/runlib/__init__.py +0 -0
  58. package/session-distill/runlib/bound.py +1102 -0
  59. package/session-distill/runlib/breaker.py +467 -0
  60. package/session-distill/runlib/census.py +2347 -0
  61. package/session-distill/runlib/claims.py +420 -0
  62. package/session-distill/runlib/controls.py +902 -0
  63. package/session-distill/runlib/coverage.py +881 -0
  64. package/session-distill/runlib/declare.py +888 -0
  65. package/session-distill/runlib/delivery_evidence.py +1145 -0
  66. package/session-distill/runlib/derive.py +812 -0
  67. package/session-distill/runlib/destinations.py +3072 -0
  68. package/session-distill/runlib/dispatch.py +7940 -0
  69. package/session-distill/runlib/drift.py +1077 -0
  70. package/session-distill/runlib/entry.py +401 -0
  71. package/session-distill/runlib/evidence.py +890 -0
  72. package/session-distill/runlib/exposure.py +1162 -0
  73. package/session-distill/runlib/gate.py +2727 -0
  74. package/session-distill/runlib/gitread.py +79 -0
  75. package/session-distill/runlib/inventory.py +19624 -0
  76. package/session-distill/runlib/journal.py +1919 -0
  77. package/session-distill/runlib/ledger.py +3210 -0
  78. package/session-distill/runlib/ledger_compat.py +101 -0
  79. package/session-distill/runlib/ledger_migration.py +190 -0
  80. package/session-distill/runlib/lifecycle_intake.py +693 -0
  81. package/session-distill/runlib/lineage.py +454 -0
  82. package/session-distill/runlib/measures.py +249 -0
  83. package/session-distill/runlib/monitor.py +1180 -0
  84. package/session-distill/runlib/operations.py +522 -0
  85. package/session-distill/runlib/packet.py +838 -0
  86. package/session-distill/runlib/placement.py +1769 -0
  87. package/session-distill/runlib/projection.py +4090 -0
  88. package/session-distill/runlib/ranking.py +740 -0
  89. package/session-distill/runlib/receipts.py +200 -0
  90. package/session-distill/runlib/records.py +1965 -0
  91. package/session-distill/runlib/search.py +249 -0
  92. package/session-distill/runlib/sequencing.py +829 -0
  93. package/session-distill/runlib/sources.py +641 -0
  94. package/session-distill/runlib/stage_adjudicate.py +845 -0
  95. package/session-distill/runlib/stage_apply.py +1378 -0
  96. package/session-distill/runlib/stage_approvals.py +758 -0
  97. package/session-distill/runlib/stage_close.py +1220 -0
  98. package/session-distill/runlib/stage_confirm.py +929 -0
  99. package/session-distill/runlib/stage_delivery.py +3080 -0
  100. package/session-distill/runlib/stage_form.py +2576 -0
  101. package/session-distill/runlib/stage_judge.py +4248 -0
  102. package/session-distill/runlib/stage_propose.py +3307 -0
  103. package/session-distill/runlib/stage_read.py +5179 -0
  104. package/session-distill/runlib/stage_render.py +2739 -0
  105. package/session-distill/runlib/stage_retrieve.py +924 -0
  106. package/session-distill/runlib/stage_review_korean.py +1002 -0
  107. package/session-distill/runlib/stage_review_proposals.py +1292 -0
  108. package/session-distill/runlib/stagelock.py +412 -0
  109. package/session-distill/runlib/stop.py +1061 -0
  110. package/session-distill/runlib/targets.py +809 -0
  111. package/session-distill/runlib/usage.py +280 -0
  112. package/session-distill/runlib/validate.py +319 -0
  113. package/session-distill/runlib/views.py +4327 -0
  114. package/session-distill/schemas/adjudication.schema.json +35 -0
  115. package/session-distill/schemas/approval.schema.json +35 -0
  116. package/session-distill/schemas/census.schema.json +128 -0
  117. package/session-distill/schemas/checks.schema.json +207 -0
  118. package/session-distill/schemas/claim.schema.json +16 -0
  119. package/session-distill/schemas/confirmation.schema.json +24 -0
  120. package/session-distill/schemas/coverage.schema.json +66 -0
  121. package/session-distill/schemas/cross_review.schema.json +24 -0
  122. package/session-distill/schemas/event.schema.json +20 -0
  123. package/session-distill/schemas/evidence.schema.json +20 -0
  124. package/session-distill/schemas/expected_observation.schema.json +18 -0
  125. package/session-distill/schemas/form.schema.json +103 -0
  126. package/session-distill/schemas/intake.schema.json +71 -0
  127. package/session-distill/schemas/inventory.schema.json +872 -0
  128. package/session-distill/schemas/judge.schema.json +77 -0
  129. package/session-distill/schemas/ledger.schema.json +313 -0
  130. package/session-distill/schemas/observation.schema.json +16 -0
  131. package/session-distill/schemas/propose.schema.json +555 -0
  132. package/session-distill/schemas/read.schema.json +76 -0
  133. package/session-distill/schemas/reconsider.schema.json +122 -0
  134. package/session-distill/schemas/run.schema.json +150 -0
  135. package/session-distill/schemas/s7b.schema.json +200 -0
  136. package/session-distill/schemas/s9b.schema.json +28 -0
  137. package/session-distill/schemas/stitch.schema.json +25 -0
  138. package/session-distill/schemas/sweep.schema.json +25 -0
  139. package/session-distill/seats.json +149 -0
  140. package/session-distill/tables/allowed_pairs.json +257 -0
  141. package/session-distill/tables/controls.json +30 -0
  142. package/session-distill/tables/delivery_evidence.json +36 -0
  143. package/session-distill/tables/delivery_evidence_fixtures.json +731 -0
  144. package/session-distill/tables/destinations.json +684 -0
  145. package/session-distill/tables/drift_layers.json +68 -0
  146. package/session-distill/tables/exposure_rules.json +192 -0
  147. package/session-distill/tables/placement_rules.json +148 -0
  148. package/session-distill/tables/propose_fixtures.json +154 -0
  149. package/session-distill/tables/ranking.json +194 -0
  150. package/session-distill/tables/redundancy.json +10 -0
  151. package/session-distill/tables/structural_rules.json +44 -0
  152. package/session-distill/tables/transition_fixtures.json +398 -0
  153. package/session-distill/tables/transitions.json +69 -0
  154. package/session-distill/tables/unit_outcome.json +67 -0
  155. package/session-distill/tables/unit_outcome_fixtures.json +2364 -0
  156. package/wrappers/claude-run.sh +481 -33
  157. package/wrappers/claude_hermetic_evidence.py +1423 -0
  158. package/wrappers/codex-helm.sh +46 -15
  159. package/wrappers/codex-run.sh +183 -20
  160. package/wrappers/codex_frame_filter.py +1199 -0
  161. package/wrappers/codex_protocol.py +737 -0
  162. package/wrappers/jsonl_lines.py +65 -0
@@ -0,0 +1,179 @@
1
+ """The subcommands the installed `claude --help` lists, for the zsh wrapper (launch/agent-launch.zsh).
2
+
3
+ python3 -I claude_subcommands.py CLAUDE
4
+
5
+ Runs `CLAUDE --help` in a process group of its own and waits at most LIMIT_S seconds. Prints each
6
+ spelling the help lists under `Commands:` (`stop|kill` is two), one per line, and exits 0 only when the
7
+ help exited 0 and listed at least one; otherwise it exits 1 with one line on stderr saying why, and the
8
+ wrapper leaves the permission flag off. LIMIT_S is not a measurement: it is meant to sit well above a
9
+ first `--help` from a slow disk.
10
+
11
+ However the wait ends - the help ending, the limit passing, or SIGINT, SIGTERM or SIGHUP reaching the
12
+ lister - the help's whole group is ended before the help is reaped: SIGKILL when the help had ended by
13
+ itself, which reaches whatever it left in the group, and otherwise SIGTERM, half a second, then SIGKILL.
14
+ Until the help is reaped its number, which is the group's, cannot belong to another process, so the
15
+ help's end is watched without reaping it: kqueue where the platform has it, since the Pythons macOS
16
+ ships lack os.waitid, and waitid elsewhere. Those three signals are only noted, so a second one cannot
17
+ cut the cleanup short; afterwards the lister says so in one line and ends by the signal it received.
18
+ A descendant that made a session of its own has left the group and is beyond this reach: when it
19
+ still holds the help's output after the group has been ended, the output is closed on this side half
20
+ a second later, and the one line that says the help did not end within the limit says so too.
21
+
22
+ The same lifecycle is wrappers/codex_protocol.py's Owned. This file cannot load it: it runs alone under
23
+ -I, and the compatibility install deploys it to a directory of its own. Standard library only, and
24
+ Python 3.9 syntax: the wrapper runs whichever python3 is on the user's PATH.
25
+ """
26
+ import os
27
+ import re
28
+ import select
29
+ import signal
30
+ import subprocess
31
+ import sys
32
+ import time
33
+
34
+ LIMIT_S = 5
35
+ GRACE_S = 0.5
36
+ DRAIN_S = 0.5
37
+ TICK_S = 0.05
38
+ CANCELS = (signal.SIGINT, signal.SIGTERM, signal.SIGHUP)
39
+ LISTED = re.compile(r"^ ([a-z][a-z0-9-]*(?:\|[a-z][a-z0-9-]*)*)(?: |$)")
40
+
41
+
42
+ def spellings(text):
43
+ """The spellings under the help's `Commands:` heading, up to the next unindented line."""
44
+ words, inside = [], False
45
+ for line in text.splitlines():
46
+ if line.startswith("Commands:"):
47
+ inside = True
48
+ elif inside:
49
+ listed = LISTED.match(line)
50
+ if listed:
51
+ words.extend(listed.group(1).split("|"))
52
+ elif line and not line.startswith(" "):
53
+ break
54
+ return words
55
+
56
+
57
+ class Owned:
58
+ """The help, started in a session of its own, ended with its process group (see the module text)."""
59
+
60
+ def __init__(self, proc):
61
+ self.proc, self._ended, self._watch = proc, False, None
62
+ if hasattr(select, "kqueue"):
63
+ self._watch = select.kqueue()
64
+ try:
65
+ self._watch.control([select.kevent(proc.pid, select.KQ_FILTER_PROC,
66
+ select.KQ_EV_ADD | select.KQ_EV_ONESHOT, select.KQ_NOTE_EXIT)], 0, 0)
67
+ except ProcessLookupError: # it ended before the watch began: an unreaped child cannot be watched
68
+ self._ended = True
69
+
70
+ def ended(self, wait_s=0.0):
71
+ """Whether the help has ended, waiting at most `wait_s`. It is never reaped here."""
72
+ if self._ended or self.proc.returncode is not None:
73
+ return True
74
+ if self._watch is not None:
75
+ self._ended = bool(self._watch.control(None, 1, max(wait_s, 0)))
76
+ return self._ended
77
+ deadline = time.monotonic() + wait_s
78
+ while os.waitid(os.P_PID, self.proc.pid, os.WEXITED | os.WNOHANG | os.WNOWAIT) is None:
79
+ if time.monotonic() >= deadline:
80
+ return False
81
+ time.sleep(TICK_S)
82
+ self._ended = True
83
+ return True
84
+
85
+ def end(self, grace_s):
86
+ """End the help's group, then reap the help. Nothing is signalled once the help is reaped."""
87
+ if self.proc.returncode is not None:
88
+ return
89
+ try:
90
+ if not self.ended():
91
+ # ESRCH, or EPERM on macOS when the unreaped help is all the group holds: nothing to signal
92
+ try:
93
+ os.killpg(self.proc.pid, signal.SIGTERM)
94
+ self.ended(grace_s)
95
+ except (ProcessLookupError, PermissionError):
96
+ pass
97
+ finally:
98
+ try:
99
+ os.killpg(self.proc.pid, signal.SIGKILL)
100
+ except (ProcessLookupError, PermissionError):
101
+ pass
102
+ self.proc.wait()
103
+ if self._watch is not None:
104
+ self._watch.close()
105
+
106
+ def collect(self, limit_s, grace_s, drain_s, stopped):
107
+ """(output, timed_out, held): the help's output, read until it has closed and the help has
108
+ ended, for at most `limit_s` or until `stopped()` answers true; then its group is ended and
109
+ the output read for at most `drain_s` more and closed. `held` is true when it was still open
110
+ then. A help's output closing is not its end, and a help that ended while something it started
111
+ still holds its output has not finished either."""
112
+ fd, read, open_ = self.proc.stdout.fileno(), [], [True]
113
+
114
+ def take(wait_s):
115
+ # a wait computed from a deadline that passed meanwhile is a poll, never a refusal
116
+ if select.select([fd], [], [], max(wait_s, 0))[0]:
117
+ chunk = os.read(fd, 65536)
118
+ if chunk:
119
+ read.append(chunk)
120
+ else:
121
+ open_[0] = False
122
+ deadline, timed_out = time.monotonic() + limit_s, False
123
+ try:
124
+ while not stopped() and (open_[0] or not self.ended()):
125
+ left = deadline - time.monotonic()
126
+ if left <= 0:
127
+ timed_out = True
128
+ break
129
+ if open_[0]:
130
+ take(min(left, TICK_S))
131
+ else:
132
+ self.ended(min(left, TICK_S))
133
+ finally:
134
+ self.end(grace_s)
135
+ deadline = time.monotonic() + drain_s
136
+ while open_[0] and time.monotonic() < deadline:
137
+ take(min(deadline - time.monotonic(), TICK_S))
138
+ self.proc.stdout.close()
139
+ return b"".join(read), timed_out, open_[0]
140
+
141
+
142
+ def main(argv):
143
+ if len(argv) != 2:
144
+ sys.stderr.write("usage: claude_subcommands.py CLAUDE\n")
145
+ return 2
146
+ received = []
147
+ for signo in CANCELS:
148
+ signal.signal(signo, lambda signo, _frame: received.append(signo))
149
+ try:
150
+ proc = subprocess.Popen([argv[1], "--help"], stdin=subprocess.DEVNULL, stdout=subprocess.PIPE,
151
+ stderr=subprocess.DEVNULL, start_new_session=True)
152
+ except OSError as exc:
153
+ return fail(f"`claude --help` did not start ({exc.__class__.__name__})")
154
+ out, timed_out, held = Owned(proc).collect(LIMIT_S, GRACE_S, DRAIN_S, lambda: bool(received))
155
+ if received:
156
+ fail(f"`claude --help` was interrupted by {signal.Signals(received[0]).name}")
157
+ sys.stderr.flush()
158
+ signal.signal(received[0], signal.SIG_DFL)
159
+ os.kill(os.getpid(), received[0])
160
+ return 1
161
+ if timed_out:
162
+ return fail(f"`claude --help` did not end within {LIMIT_S} s"
163
+ + (", and a process that left its process group still held its output" if held else ""))
164
+ if proc.returncode != 0:
165
+ return fail(f"`claude --help` exited {proc.returncode}")
166
+ words = spellings(out.decode("utf-8", "replace"))
167
+ if not words:
168
+ return fail("`claude --help` listed no subcommands")
169
+ sys.stdout.write("".join(word + "\n" for word in words))
170
+ return 0
171
+
172
+
173
+ def fail(why):
174
+ sys.stderr.write(f"agent-bios: {why}; claude starts without --dangerously-skip-permissions\n")
175
+ return 1
176
+
177
+
178
+ if __name__ == "__main__":
179
+ sys.exit(main(sys.argv))
@@ -89,8 +89,14 @@ class ShellIntegration:
89
89
  body = self._read(source)
90
90
  if body is None:
91
91
  raise ShellIntegrationError(f"shell connection source missing: {source}")
92
+ # The wrapper's subcommand lister stays in the package this connection was made from. Only values
93
+ # every process derives alike go here: a script that is no longer these bytes, and has lost its
94
+ # receipt, is not recognised as ours (the python that made it differs between the installer and
95
+ # the launcher, so it is not one of them).
92
96
  return SCRIPT_HEADER + (
93
- f"typeset -g _agent_launch_private_connection={shlex.quote(str(self.script))}\n").encode() + body
97
+ f"typeset -g _agent_launch_private_connection={shlex.quote(str(self.script))}\n"
98
+ f"typeset -g _agent_launch_claude_lister="
99
+ f"{shlex.quote(str(self.source / 'launch' / 'claude_subcommands.py'))}\n").encode() + body
94
100
 
95
101
  def has_connection(self):
96
102
  """Discover interrupted opt-ins without inspecting an ordinary user's rc.
@@ -639,17 +639,40 @@ def print_upload_summary(s):
639
639
  f"pending={s['pending']}{tail}")
640
640
 
641
641
 
642
+ def drain_under_lock(destination, drain):
643
+ """Run `drain` holding the host's upload lock, so two captures never drain one queue at once. The
644
+ wait is bounded (host_platform.lock_within): past it the drain is not run and the lock is named;
645
+ the learning is already captured, and the next drain sends it."""
646
+ if str(REPO / "compose") not in sys.path:
647
+ sys.path.insert(0, str(REPO / "compose"))
648
+ from host_platform import LockWaitExpired, lock_within
649
+ lock = destination / 'upload.lock'
650
+ fd = os.open(lock, os.O_CREAT | os.O_RDWR | os.O_NOFOLLOW, 0o600)
651
+ with os.fdopen(fd, 'a') as handle:
652
+ try:
653
+ lock_within(handle, f"the learning upload lock ({lock})")
654
+ except LockWaitExpired as exc:
655
+ print(f" upload -> NOT RUN: {exc}; the record is captured and stays queued for the next "
656
+ f"learn!", file=sys.stderr)
657
+ return None
658
+ return drain()
659
+
660
+
642
661
  def _self_test():
643
662
  """Socket-free verification of the drain: status classification, watermark
644
663
  advance, transient-stop (no storm), permanent-drop, no-token skip, poison
645
664
  line, plus capture-time redaction wiring. Injects post_fn/now; exits
646
665
  non-zero on any failure."""
666
+ import atexit
647
667
  import tempfile
648
668
 
649
669
  # One scratch tree for the whole run, removed at the end: every mkdtemp here
650
670
  # used to survive the process, and the gate that calls this ran on every
651
- # commit — 10k directories before anyone counted.
671
+ # commit — 10k directories before anyone counted. Removed again when the
672
+ # process ends, however it ends: a run that raises never reaches the last
673
+ # line, and the seam-coverage gate runs this suite on mutated copies.
652
674
  scratch = pathlib.Path(tempfile.mkdtemp(prefix="learn-selftest-"))
675
+ atexit.register(shutil.rmtree, scratch, True)
653
676
  made = {"n": 0}
654
677
 
655
678
  def scratch_dir(tag):
@@ -1135,6 +1158,37 @@ def _self_test():
1135
1158
  checks.append(("post limit is a hard cap",
1136
1159
  capped["n"] == 1 and s["uploaded"] == 1 and s["reason"] == "limit"))
1137
1160
 
1161
+ # 18) a drain behind an upload lock held past the bound is not run, and the lock is named — the
1162
+ # writer used to wait on it with no deadline. The bounds are scaled; the holder is a child
1163
+ # that lets go after 8 s, so a drain that waits without a bound runs late and fails here.
1164
+ import contextlib
1165
+ import io
1166
+ import subprocess
1167
+ if str(REPO / "compose") not in sys.path:
1168
+ sys.path.insert(0, str(REPO / "compose"))
1169
+ import host_platform
1170
+ held_dir = scratch_dir("held-upload")
1171
+ holder = subprocess.Popen([sys.executable, "-c", "import fcntl, sys, time; f = open(sys.argv[1], 'a'); "
1172
+ "fcntl.flock(f, fcntl.LOCK_EX); print('held', flush=True); time.sleep(8)",
1173
+ str(held_dir / "upload.lock")], stdout=subprocess.PIPE, text=True)
1174
+ saved = (host_platform.LOCK_WAIT_S, host_platform.LOCK_NOTICE_S)
1175
+ drained = {"n": 0}
1176
+ said = io.StringIO()
1177
+ try:
1178
+ holder.stdout.readline()
1179
+ host_platform.LOCK_WAIT_S, host_platform.LOCK_NOTICE_S = 0.6, 0.2
1180
+ with contextlib.redirect_stderr(said):
1181
+ outcome = drain_under_lock(held_dir, lambda: drained.update(n=1) or {"status": "ok"})
1182
+ finally:
1183
+ host_platform.LOCK_WAIT_S, host_platform.LOCK_NOTICE_S = saved
1184
+ holder.kill()
1185
+ holder.wait()
1186
+ holder.stdout.close()
1187
+ checks.append(("a drain behind a held upload lock is not run and names the lock",
1188
+ outcome is None and drained["n"] == 0
1189
+ and f"the learning upload lock ({held_dir / 'upload.lock'}) is still held after 0.6 s" in said.getvalue()
1190
+ and "waiting for the learning upload lock" in said.getvalue()))
1191
+
1138
1192
  shutil.rmtree(scratch, ignore_errors=True)
1139
1193
  failed = [name for name, ok in checks if not ok]
1140
1194
  if failed:
@@ -1195,14 +1249,11 @@ def main():
1195
1249
  result = store.capture_learning(host, record)
1196
1250
  print(f"collect-learning: OK host={host} learning_id={result['learning_id']} · private source; future activated sessions")
1197
1251
  if not args.no_upload:
1198
- import fcntl
1199
- lock = destination / 'upload.lock'
1200
- fd = os.open(lock, os.O_CREAT | os.O_RDWR | os.O_NOFOLLOW, 0o600)
1201
- with os.fdopen(fd, 'a') as handle:
1202
- fcntl.flock(handle, fcntl.LOCK_EX)
1203
- print_upload_summary(drain_uploads(
1204
- home, jsonl_path=destination / 'events.jsonl',
1205
- state_path=destination / 'upload-state.json'))
1252
+ summary = drain_under_lock(destination, lambda: drain_uploads(
1253
+ home, jsonl_path=destination / 'events.jsonl',
1254
+ state_path=destination / 'upload-state.json'))
1255
+ if summary is not None:
1256
+ print_upload_summary(summary)
1206
1257
  return
1207
1258
  bullet = prose_bullet(record)
1208
1259
  jsonl = append_record(home, record, dry)
@@ -75,6 +75,18 @@ def _load(name, filename):
75
75
  return module
76
76
 
77
77
 
78
+ def load_jsonl():
79
+ """wrappers/jsonl_lines.py, in this package root: a JSONL record ends at "\n" or "\r\n"
80
+ only, read from the file's bytes (single source)."""
81
+ path = REPO / "wrappers" / "jsonl_lines.py"
82
+ if not path.is_file():
83
+ die(f"the JSONL splitter is missing: {path}")
84
+ spec = importlib.util.spec_from_file_location("jsonl_lines", path)
85
+ module = importlib.util.module_from_spec(spec)
86
+ spec.loader.exec_module(module)
87
+ return module
88
+
89
+
78
90
  def load_collect():
79
91
  """Reuse collect-learning.py's host/home/marker constants (single source)."""
80
92
  return _load("collect_learning", "collect-learning.py")
@@ -212,7 +224,7 @@ def prune_jsonl(jsonl, remove_ids, dry):
212
224
  if not jsonl.is_file():
213
225
  return 0
214
226
  kept, removed = [], 0
215
- for line in jsonl.read_text(encoding="utf-8").splitlines():
227
+ for line, terminator in load_jsonl().read_terminated(jsonl):
216
228
  s = line.strip()
217
229
  if s:
218
230
  try:
@@ -222,9 +234,10 @@ def prune_jsonl(jsonl, remove_ids, dry):
222
234
  continue
223
235
  except json.JSONDecodeError:
224
236
  pass # keep malformed lines untouched
225
- kept.append(line)
237
+ kept.append(line + terminator)
226
238
  if removed and not dry:
227
- atomic_write(jsonl, "\n".join(kept) + ("\n" if kept else ""))
239
+ # bytes, so no newline translation (Windows text mode) touches a kept line's own terminator
240
+ atomic_write(jsonl, "".join(kept).encode("utf-8"))
228
241
  return removed
229
242
 
230
243
 
@@ -327,7 +340,7 @@ def migrate(home, host, promotions, in_bundle, collect, dry=False, instructions_
327
340
  jsonl = home / "personal" / "learnings.jsonl"
328
341
  local_ids = set()
329
342
  if jsonl.is_file():
330
- for line in jsonl.read_text(encoding="utf-8").splitlines():
343
+ for line in load_jsonl().read(jsonl):
331
344
  s = line.strip()
332
345
  if not s:
333
346
  continue
@@ -461,8 +474,15 @@ def _self_test():
461
474
  user's bundle), removal of an in-bundle promotion from BOTH prose + jsonl,
462
475
  idempotency, and that the user's own '## Personal' text is untouched. Uses
463
476
  collect-learning's own writers so the seeded format is authoritative."""
477
+ import atexit
478
+ import shutil
464
479
  import tempfile
465
480
 
481
+ # Every scratch home below is made inside one root, removed when the process ends however it ends: the
482
+ # homes used to outlive it, sixteen directories per umbrella run.
483
+ tempfile.tempdir = tempfile.mkdtemp(prefix="migrate-selftest-root-")
484
+ atexit.register(shutil.rmtree, tempfile.tempdir, True)
485
+
466
486
  collect = load_collect()
467
487
 
468
488
  def rec(lid, domain):
@@ -699,6 +719,52 @@ def _self_test():
699
719
  valid.write_text('{"version": 2, "promotions": [{"learning_id": "x"}]}', encoding="utf-8")
700
720
  checks.append(("a real manifest still loads", len(load_manifest(valid)) == 1))
701
721
 
722
+ # a learnings.jsonl record ends at "\n" only; collect-learning writes U+2028 and U+2029 raw
723
+ # (ensure_ascii=False), and str.splitlines() would cut the record there
724
+ sep = "before\u2028between\u2029after"
725
+ sep_dir = pathlib.Path(tempfile.mkdtemp(prefix="migrate-jsonl-"))
726
+ kept_line = json.dumps(dict(rec(L["off"], "office-work"), lesson=sep), ensure_ascii=False)
727
+ (sep_dir / "learnings.jsonl").write_text(kept_line + "\n" + json.dumps(rec(L["core"], "core")) + "\n", encoding="utf-8")
728
+ pruned = prune_jsonl(sep_dir / "learnings.jsonl", {L["core"]}, dry=False)
729
+ checks.append(("jsonl-line-separators-inside-a-string-read-whole (prune_jsonl): the kept record is byte for byte",
730
+ pruned == 1 and (sep_dir / "learnings.jsonl").read_text(encoding="utf-8") == kept_line + "\n"))
731
+ # a bare CR is JSON whitespace, which text-mode reading would turn into a line break; a CRLF record stays CRLF
732
+ cr_line = "{\r" + json.dumps(rec(L["off"], "office-work"))[1:]
733
+ (sep_dir / "learnings.jsonl").write_bytes((cr_line + "\r\n" + json.dumps(rec(L["core"], "core")) + "\n").encode("utf-8"))
734
+ pruned = prune_jsonl(sep_dir / "learnings.jsonl", {L["core"]}, dry=False)
735
+ checks.append(("jsonl-bare-cr-whitespace-and-crlf-read-whole (prune_jsonl): the kept record is byte for byte",
736
+ pruned == 1 and (sep_dir / "learnings.jsonl").read_bytes() == (cr_line + "\r\n").encode("utf-8")))
737
+ # the rewrite keeps each line's own terminator under Windows text-mode writing too, which
738
+ # turns every "\n" written as text into "\r\n"
739
+ from unittest import mock
740
+ real_write_text = pathlib.Path.write_text
741
+
742
+ def windows_write_text(self, data, encoding=None, errors=None, newline=None):
743
+ return real_write_text(self, data.replace("\n", "\r\n") if newline is None else data,
744
+ encoding=encoding, errors=errors, newline=newline)
745
+ lf_line = json.dumps(rec(L["bb"], "builder-base"))
746
+ (sep_dir / "learnings.jsonl").write_bytes((cr_line + "\r\n" + lf_line + "\n" + json.dumps(rec(L["core"], "core")) + "\n")
747
+ .encode("utf-8"))
748
+ with mock.patch.object(pathlib.Path, "write_text", windows_write_text):
749
+ pruned = prune_jsonl(sep_dir / "learnings.jsonl", {L["core"]}, dry=False)
750
+ checks.append(("jsonl-rewrite-keeps-each-terminator-under-windows-newline-translation (prune_jsonl)",
751
+ pruned == 1 and (sep_dir / "learnings.jsonl").read_bytes()
752
+ == (cr_line + "\r\n" + lf_line + "\n").encode("utf-8")))
753
+ home = seed_claude()
754
+ jsonl = home / "personal" / "learnings.jsonl"
755
+ jsonl.write_text("".join(json.dumps(dict(json.loads(line), lesson=sep), ensure_ascii=False) + "\n"
756
+ for line in jsonl.read_text(encoding="utf-8").split("\n") if line), encoding="utf-8")
757
+ s = migrate(home, "claude", promos, make_in_bundle(["builder-base"]), collect)
758
+ checks.append(("jsonl-line-separators-inside-a-string-read-whole (migrate): every record's id is held locally",
759
+ s["removed"] == 2 and s["kept_not_in_bundle"] == 1))
760
+ home = seed_claude()
761
+ jsonl = home / "personal" / "learnings.jsonl"
762
+ jsonl.write_bytes("".join("{\r" + json.dumps(json.loads(line))[1:] + "\r\n"
763
+ for line in jsonl.read_text(encoding="utf-8").split("\n") if line).encode("utf-8"))
764
+ s = migrate(home, "claude", promos, make_in_bundle(["builder-base"]), collect)
765
+ checks.append(("jsonl-bare-cr-whitespace-and-crlf-read-whole (migrate): every record's id is held locally",
766
+ s["removed"] == 2 and s["kept_not_in_bundle"] == 1))
767
+
702
768
  failed = [n for n, ok in checks if not ok]
703
769
  if failed:
704
770
  for n in failed:
package/learn/redact.py CHANGED
@@ -3,7 +3,8 @@
3
3
 
4
4
  Both flows that egress session-derived text redact through here, so the floor
5
5
  is single-sourced (concept economy) rather than duplicated per call site:
6
- * heavy flow — session-distill/digest.py (per-session digests);
6
+ * heavy flow — session-distill/runlib/projection.py (the driver's transcript
7
+ views; it loads this module by path, never a copy of its patterns);
7
8
  * light flow — learn/collect-learning.py (`learn!` prose + upload + the
8
9
  curator export downstream, since the server stores what it receives —
9
10
  redaction that does not happen HERE cannot be undone there).
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "agent-bios",
3
- "version": "0.19.4",
4
- "releaseDate": "2026-11-03",
3
+ "version": "0.20.1",
4
+ "releaseDate": "2026-11-24",
5
5
  "description": "A thin, low-level instruction layer for LLM CLI agents: one set of principles and behavior whichever model you run. Stores private, editable instructions for explicitly activated sessions.",
6
6
  "bin": {
7
7
  "agent-bios": "install.sh"
@@ -23,6 +23,7 @@
23
23
  "learn/learning.schema.json",
24
24
  "learn/promotions.json",
25
25
  "launch/agent-launch.zsh",
26
+ "launch/claude_subcommands.py",
26
27
  "launch/agent-launch.py",
27
28
  "launch/shell_integration.py",
28
29
  "compose/pkgid.py",
@@ -75,11 +76,39 @@
75
76
  "learn/migrate-learnings.py",
76
77
  "learn/redact.py",
77
78
  "wrappers/codex-run.sh",
79
+ "wrappers/codex_frame_filter.py",
80
+ "wrappers/codex_protocol.py",
78
81
  "wrappers/codex-helm.sh",
79
82
  "wrappers/claude-run.sh",
83
+ "wrappers/claude_hermetic_evidence.py",
84
+ "wrappers/jsonl_lines.py",
80
85
  "install.sh",
81
86
  "launch/provision-venv.sh",
82
87
  "session-cost.py",
88
+ "session-distill/distill.py",
89
+ "session-distill/runlib/",
90
+ "session-distill/grammar/",
91
+ "session-distill/schemas/",
92
+ "session-distill/tables/redundancy.json",
93
+ "session-distill/tables/transition_fixtures.json",
94
+ "session-distill/tables/allowed_pairs.json",
95
+ "session-distill/tables/destinations.json",
96
+ "session-distill/tables/drift_layers.json",
97
+ "session-distill/tables/exposure_rules.json",
98
+ "session-distill/tables/structural_rules.json",
99
+ "session-distill/tables/placement_rules.json",
100
+ "session-distill/tables/ranking.json",
101
+ "session-distill/tables/propose_fixtures.json",
102
+ "session-distill/tables/transitions.json",
103
+ "session-distill/tables/controls.json",
104
+ "session-distill/tables/delivery_evidence.json",
105
+ "session-distill/tables/delivery_evidence_fixtures.json",
106
+ "session-distill/tables/unit_outcome.json",
107
+ "session-distill/tables/unit_outcome_fixtures.json",
108
+ "session-distill/packets/",
109
+ "session-distill/seats.json",
110
+ "session-distill/originators.json",
111
+ "session-distill/coverage.json",
83
112
  "docs/",
84
113
  "README.md",
85
114
  "INSTALL.md",
@@ -88,7 +117,11 @@
88
117
  "compose/native_cli.py",
89
118
  "compose/host_platform.py",
90
119
  "compose/runtime_entry.py",
91
- "compose/windows_deploy.py"
120
+ "compose/windows_deploy.py",
121
+ "!**/__pycache__",
122
+ "!**/__pycache__/**",
123
+ "!**/*.pyc",
124
+ "!**/*.pyo"
92
125
  ],
93
126
  "scripts": {
94
127
  "postinstall": "printf '\\n> agent-bios installed. Deploy into this environment with: agent-bios install\\n> Then: agent-bios verify | status | uninstall\\n\\n'",
package/provenance.json CHANGED
@@ -1 +1 @@
1
- {"commit":"cd424da6d7b2ae7f5ba34158bd1ae01383a5be72","committedAt":"2026-11-03T17:09:20+09:00","dirty":false}
1
+ {"commit":"2245338edef2146693e88579cc330f7c12a498e7","committedAt":"2026-11-24T11:32:48+09:00","dirty":false}