agent-bios 0.14.0 → 0.16.0

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 (60) hide show
  1. package/DEPENDENCIES.md +35 -12
  2. package/README.md +346 -31
  3. package/claude/CLAUDE.md +2 -2
  4. package/claude/agents/frontier.md +1 -1
  5. package/claude/agents/sweep.md +3 -3
  6. package/claude/agents/workhorse.md +2 -2
  7. package/claude/guides/claude-prompting.md +119 -34
  8. package/claude/guides/cli-multi-model-workflow.md +33 -15
  9. package/claude/guides/gpt-prompting.md +148 -28
  10. package/claude/guides/review-request.md +27 -0
  11. package/claude/guides/session-distill-workflow.md +54 -2
  12. package/claude/guides/slide-writing/RUNBOOK.md +137 -0
  13. package/claude/guides/slide-writing/scripts/pair.py +979 -0
  14. package/claude/guides/slide-writing/scripts/render.mjs +82 -0
  15. package/claude/guides/slide-writing.md +195 -0
  16. package/claude/guides/svg-visualization-guide.md +9 -0
  17. package/claude/guides/verification-discipline.md +5 -1
  18. package/claude/hooks/tooling-gotchas-hook.py +7 -5
  19. package/codex/AGENTS.md +2 -2
  20. package/codex/agents/frontier.toml +2 -1
  21. package/codex/agents/reviewer.toml +1 -1
  22. package/codex/agents/sweep.toml +3 -3
  23. package/codex/agents/workhorse.toml +1 -1
  24. package/codex/config-additions.toml +1 -1
  25. package/codex/guides/claude-prompting.md +119 -34
  26. package/codex/guides/cli-multi-model-workflow.md +33 -15
  27. package/codex/guides/gpt-prompting.md +148 -28
  28. package/codex/guides/review-request.md +27 -0
  29. package/codex/guides/session-distill-workflow.md +54 -2
  30. package/codex/guides/slide-writing/RUNBOOK.md +137 -0
  31. package/codex/guides/slide-writing/scripts/pair.py +979 -0
  32. package/codex/guides/slide-writing/scripts/render.mjs +82 -0
  33. package/codex/guides/slide-writing.md +195 -0
  34. package/codex/guides/svg-visualization-guide.md +9 -0
  35. package/codex/guides/verification-discipline.md +5 -1
  36. package/compose/assemble.py +290 -14
  37. package/compose/bootstrap/SKILL.md +119 -0
  38. package/compose/check-domains.py +102 -9
  39. package/compose/corpus-state.py +1174 -0
  40. package/compose/corpus.py +387 -0
  41. package/compose/corpus_catalog.py +882 -0
  42. package/compose/corpus_install.py +1617 -0
  43. package/compose/corpus_session.py +726 -0
  44. package/compose/corpus_store.py +1414 -0
  45. package/compose/corpus_transaction.py +236 -0
  46. package/compose/corpus_ui.py +644 -0
  47. package/compose/domains.json +101 -100
  48. package/compose/write-update-cache.py +53 -0
  49. package/install.sh +174 -24
  50. package/launch/agent-launch.py +1327 -184
  51. package/launch/agent-launch.toml +12 -16
  52. package/launch/i18n/en.toml +113 -7
  53. package/launch/i18n/ja.toml +113 -7
  54. package/launch/i18n/ko.toml +113 -7
  55. package/learn/collect-learning.py +46 -19
  56. package/learn/migrate-learnings.py +10 -1
  57. package/package.json +13 -3
  58. package/provenance.json +1 -1
  59. package/session-cost.py +22 -2
  60. package/wrappers/codex-helm.sh +3 -3
@@ -0,0 +1,236 @@
1
+ """Shared lock and durable pending-operation visibility for corpus state.
2
+
3
+ The corpus store owns source bytes and the installer owns projections. Neither
4
+ may publish independently while an install, reset or migration is incomplete: a reader
5
+ must see the completed generation or a clear recovery requirement, never a
6
+ mixture. Journals deliberately contain no token bytes.
7
+ """
8
+ from __future__ import annotations
9
+
10
+ import contextlib
11
+ import base64
12
+ import fcntl
13
+ import hashlib
14
+ import json
15
+ import os
16
+ from pathlib import Path
17
+ import threading
18
+ from typing import Any, Iterator
19
+
20
+
21
+ PENDING_STATES = frozenset({"PREPARED", "APPLYING", "NEEDS_RECOVERY"})
22
+ _local = threading.local()
23
+
24
+
25
+ class TransactionError(RuntimeError):
26
+ pass
27
+
28
+
29
+ class TransactionPendingError(TransactionError):
30
+ pass
31
+
32
+
33
+ def _key(state_root: Path) -> str:
34
+ return str(Path(state_root).expanduser().resolve())
35
+
36
+
37
+ def _depths(name: str) -> dict[str, int]:
38
+ value = getattr(_local, name, None)
39
+ if value is None:
40
+ value = {}
41
+ setattr(_local, name, value)
42
+ return value
43
+
44
+
45
+ @contextlib.contextmanager
46
+ def transaction_lock(state_root: Path) -> Iterator[None]:
47
+ """The single re-entrant cross-process lock for store and installer work."""
48
+ root = Path(state_root).expanduser()
49
+ if root.is_symlink():
50
+ raise TransactionError(f"unsafe corpus state root: {root}")
51
+ key = _key(root)
52
+ depths = _depths("lock_depths")
53
+ if depths.get(key, 0):
54
+ depths[key] += 1
55
+ try:
56
+ yield
57
+ finally:
58
+ depths[key] -= 1
59
+ return
60
+ root.mkdir(parents=True, exist_ok=True, mode=0o700)
61
+ lock = root / ".corpus-store.lock"
62
+ if lock.is_symlink():
63
+ raise TransactionError(f"unsafe corpus transaction lock: {lock}")
64
+ flags = os.O_CREAT | os.O_RDWR | getattr(os, "O_NOFOLLOW", 0)
65
+ descriptor = os.open(lock, flags, 0o600)
66
+ with os.fdopen(descriptor, "a+", encoding="utf-8") as handle:
67
+ fcntl.flock(handle, fcntl.LOCK_EX)
68
+ depths[key] = 1
69
+ try:
70
+ yield
71
+ finally:
72
+ depths.pop(key, None)
73
+ fcntl.flock(handle, fcntl.LOCK_UN)
74
+
75
+
76
+ @contextlib.contextmanager
77
+ def operation_scope(state_root: Path) -> Iterator[None]:
78
+ """Permit the coordinating writer to inspect its own pending journal."""
79
+ key = _key(Path(state_root))
80
+ depths = _depths("operation_depths")
81
+ depths[key] = depths.get(key, 0) + 1
82
+ try:
83
+ yield
84
+ finally:
85
+ remaining = depths[key] - 1
86
+ if remaining:
87
+ depths[key] = remaining
88
+ else:
89
+ depths.pop(key, None)
90
+
91
+
92
+ def operation_scope_active(state_root: Path) -> bool:
93
+ return bool(_depths("operation_depths").get(_key(Path(state_root)), 0))
94
+
95
+
96
+ def _journal_records(state_root: Path, *, coordinator_only: bool = False) -> list[dict[str, Any]]:
97
+ root = Path(state_root).expanduser() / "runtime"
98
+ records: list[dict[str, Any]] = []
99
+ # ``resets`` predates the unified transaction directory and remains visible
100
+ # so an old interrupted reset is never silently treated as complete.
101
+ for directory in (root / "transactions", root / "installer-transactions", root / "resets", root / "migrations"):
102
+ if not directory.exists():
103
+ continue
104
+ if directory.is_symlink() or not directory.is_dir():
105
+ raise TransactionError(f"unsafe transaction journal root: {directory}")
106
+ for journal in sorted(directory.glob("*/journal.json")):
107
+ if journal.parent.is_symlink() or journal.is_symlink() or not journal.is_file():
108
+ raise TransactionError(f"unsafe transaction journal: {journal}")
109
+ try:
110
+ value = json.loads(journal.read_text(encoding="utf-8"))
111
+ except (OSError, ValueError) as exc:
112
+ raise TransactionError(f"unreadable transaction journal: {journal}") from exc
113
+ if not isinstance(value, dict):
114
+ raise TransactionError(f"invalid transaction journal: {journal}")
115
+ # Store owns its source-only install journal. It can safely finish
116
+ # its own PREPARED source pair under the same lock; launcher/config
117
+ # readers must only block on the wider installer/reset coordinator.
118
+ coordinator = directory.name in {"installer-transactions", "resets", "migrations"} or value.get("owner") == "installer"
119
+ if value.get("state") in PENDING_STATES and (not coordinator_only or coordinator):
120
+ fallback = "migrate" if directory.name == "migrations" else "reset" if coordinator else "source"
121
+ records.append({"path": str(journal), "kind": value.get("kind", fallback),
122
+ "owner": "installer" if coordinator else "store",
123
+ "state": value.get("state"), "phase": value.get("phase")})
124
+ return records
125
+
126
+
127
+ def pending_status(state_root: Path) -> dict[str, Any]:
128
+ records = _journal_records(state_root)
129
+ return {"pending": bool(records), "transactions": records}
130
+
131
+
132
+ def pending_operations(state_root: Path) -> list[dict[str, Any]]:
133
+ """Return pending journals for source readers and management views."""
134
+ return pending_status(state_root)["transactions"]
135
+
136
+
137
+ def guard_pending(state_root: Path) -> None:
138
+ """Fail before a config/source reader consumes an incomplete publication."""
139
+ key = _key(Path(state_root))
140
+ if _depths("operation_depths").get(key, 0):
141
+ return
142
+ pending = _journal_records(state_root, coordinator_only=True)
143
+ if pending:
144
+ first = pending[0]
145
+ raise TransactionPendingError(
146
+ "corpus install/reset/migration needs recovery before reading current configuration: "
147
+ f"{first['path']} ({first['state']})"
148
+ )
149
+
150
+
151
+ def _valid_release(state_root: Path, record: dict[str, Any]) -> Path:
152
+ raw = record.get("package_root")
153
+ digest = record.get("release_digest")
154
+ if not isinstance(raw, str) or not isinstance(digest, str):
155
+ raise TransactionPendingError("private install record has no confirmed immutable release")
156
+ root = (Path(state_root).expanduser() / "runtime" / "releases").absolute()
157
+ release = Path(raw)
158
+ try:
159
+ release.absolute().relative_to(root)
160
+ except ValueError as exc:
161
+ raise TransactionPendingError("private install record points outside immutable releases") from exc
162
+ if release.name != digest or release.is_symlink() or not release.is_dir():
163
+ raise TransactionPendingError("private install record has an invalid immutable release")
164
+ entries = record.get("installed_files")
165
+ if not isinstance(entries, list) or not entries:
166
+ raise TransactionPendingError("private install record has no release inventory")
167
+ # The release digest is the digest of the ordered path+bytes stream. The
168
+ # installer computes it before any pointer publication, so this is a cheap
169
+ # structural confirmation suitable for a config reader; full verification
170
+ # remains CorpusInstaller.verify's responsibility.
171
+ actual = hashlib.sha256()
172
+ for entry in entries:
173
+ if not isinstance(entry, dict) or not isinstance(entry.get("path"), str):
174
+ raise TransactionPendingError("private install record has invalid release inventory")
175
+ relative = Path(entry["path"])
176
+ if relative.is_absolute() or ".." in relative.parts:
177
+ raise TransactionPendingError("private install record has unsafe release inventory")
178
+ member = release / relative
179
+ if member.is_symlink() or not member.is_file():
180
+ raise TransactionPendingError("confirmed release member is unavailable")
181
+ data = member.read_bytes()
182
+ actual.update(entry["path"].encode("utf-8") + b"\0" + data + b"\0")
183
+ if actual.hexdigest() != digest:
184
+ raise TransactionPendingError("confirmed release digest does not match inventory")
185
+ return release
186
+
187
+
188
+ def confirmed_release(state_root: Path) -> Path:
189
+ """Return the last fully confirmed release while a coordinator is pending.
190
+
191
+ A pending update's ``after`` record is deliberately not trusted. The
192
+ journal's exact ``before`` private-install bytes identify the previous
193
+ generation; a first installation has none and therefore fails closed.
194
+ """
195
+ root = Path(state_root).expanduser()
196
+ pending = _journal_records(root, coordinator_only=True)
197
+ migration = next((item for item in pending if item["kind"] == "migrate"), None)
198
+ if migration is not None:
199
+ try:
200
+ value = json.loads(Path(migration["path"]).read_text(encoding="utf-8"))
201
+ before = value["prior_install"]
202
+ encoded = before.get("bytes_b64") if isinstance(before, dict) else None
203
+ if not isinstance(encoded, str):
204
+ raise ValueError("no prior private install")
205
+ record = json.loads(base64.b64decode(encoded.encode("ascii"), validate=True))
206
+ except (KeyError, OSError, ValueError, TypeError) as exc:
207
+ raise TransactionPendingError("pending migration has no confirmed prior private install") from exc
208
+ if not isinstance(record, dict):
209
+ raise TransactionPendingError("prior migration install record is invalid")
210
+ return _valid_release(root, record)
211
+ install = next((item for item in pending if item["kind"] == "install"), None)
212
+ if install is not None:
213
+ journal = Path(install["path"])
214
+ try:
215
+ value = json.loads(journal.read_text(encoding="utf-8"))
216
+ record_entry = next(entry for entry in value.get("paths", [])
217
+ if isinstance(entry, dict) and str(entry.get("path", "")).endswith(
218
+ "/runtime/private-install.json"))
219
+ before = record_entry.get("before", {})
220
+ encoded = before.get("bytes_b64") if isinstance(before, dict) else None
221
+ if not isinstance(encoded, str):
222
+ raise ValueError("no prior private-install record")
223
+ record = json.loads(base64.b64decode(encoded.encode("ascii"), validate=True))
224
+ except (StopIteration, ValueError, TypeError, json.JSONDecodeError) as exc:
225
+ raise TransactionPendingError("first or incomplete install has no confirmed prior release") from exc
226
+ if not isinstance(record, dict):
227
+ raise TransactionPendingError("prior private-install record is invalid")
228
+ return _valid_release(root, record)
229
+ path = root / "runtime" / "private-install.json"
230
+ try:
231
+ record = json.loads(path.read_text(encoding="utf-8"))
232
+ except (OSError, ValueError) as exc:
233
+ raise TransactionPendingError("pending reset has no confirmed private install") from exc
234
+ if not isinstance(record, dict):
235
+ raise TransactionPendingError("confirmed private install is invalid")
236
+ return _valid_release(root, record)