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