agent-bios 0.19.1 → 0.19.3

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 (106) hide show
  1. package/DEPENDENCIES.md +58 -30
  2. package/INSTALL.md +4 -4
  3. package/README.md +105 -28
  4. package/claude/CLAUDE.md +1 -1
  5. package/claude/guides/claude-prompting.md +1 -1
  6. package/claude/guides/cli-multi-model-workflow.md +4 -4
  7. package/claude/guides/coding-staged-workflow.md +17 -0
  8. package/claude/guides/documentation-hygiene.md +3 -0
  9. package/claude/guides/gpt-prompting.md +1 -1
  10. package/claude/guides/korean-writing.md +153 -0
  11. package/claude/guides/learning-flow.md +4 -4
  12. package/claude/guides/llm-capability-boundary.md +7 -1
  13. package/claude/guides/session-distill-workflow.md +8 -8
  14. package/claude/guides/slide-writing/RUNBOOK.md +5 -5
  15. package/claude/guides/tooling-gotchas.md +20 -1
  16. package/claude/guides/ui-design/visual-direction.md +88 -0
  17. package/claude/guides/ui-design.md +90 -0
  18. package/claude/guides/verification-discipline.md +10 -1
  19. package/claude/hooks/tooling-gotchas-hook.py +41 -0
  20. package/claude/skills/repo-charter/SKILL.md +3 -3
  21. package/claude/skills/understand/SKILL.md +5 -5
  22. package/codex/AGENTS.md +1 -1
  23. package/codex/guides/claude-prompting.md +1 -1
  24. package/codex/guides/cli-multi-model-workflow.md +4 -4
  25. package/codex/guides/coding-staged-workflow.md +17 -0
  26. package/codex/guides/documentation-hygiene.md +3 -0
  27. package/codex/guides/gpt-prompting.md +1 -1
  28. package/codex/guides/korean-writing.md +153 -0
  29. package/codex/guides/learning-flow.md +4 -4
  30. package/codex/guides/llm-capability-boundary.md +7 -1
  31. package/codex/guides/session-distill-workflow.md +8 -8
  32. package/codex/guides/slide-writing/RUNBOOK.md +5 -5
  33. package/codex/guides/tooling-gotchas.md +20 -1
  34. package/codex/guides/ui-design/visual-direction.md +88 -0
  35. package/codex/guides/ui-design.md +90 -0
  36. package/codex/guides/verification-discipline.md +10 -1
  37. package/compose/app_bridge/SKILL.md +12 -12
  38. package/compose/app_bridge/scripts/bridge.py +35 -10
  39. package/compose/app_desktop/server.py +250 -0
  40. package/compose/assemble.py +5 -5
  41. package/compose/bootstrap/SKILL.md +18 -18
  42. package/compose/canary.sh +4 -4
  43. package/compose/check-domains.py +6 -6
  44. package/compose/corpus-state.py +16 -1168
  45. package/compose/corpus.py +13 -402
  46. package/compose/corpus_app.py +14 -450
  47. package/compose/corpus_catalog.py +15 -926
  48. package/compose/corpus_import.py +14 -523
  49. package/compose/corpus_install.py +14 -1847
  50. package/compose/corpus_session.py +16 -848
  51. package/compose/corpus_setup.py +16 -672
  52. package/compose/corpus_setup_cli.py +15 -580
  53. package/compose/corpus_setup_i18n.py +20 -324
  54. package/compose/corpus_setup_ui.py +18 -645
  55. package/compose/corpus_store.py +16 -1664
  56. package/compose/corpus_transaction.py +15 -284
  57. package/compose/corpus_ui.py +17 -972
  58. package/compose/corpus_ui_runtime.py +16 -274
  59. package/compose/corpus_understand.py +13 -671
  60. package/compose/domains.json +3 -1
  61. package/compose/host_platform.py +121 -0
  62. package/compose/instructions-state.py +1178 -0
  63. package/compose/instructions.py +409 -0
  64. package/compose/instructions_app.py +697 -0
  65. package/compose/instructions_catalog.py +931 -0
  66. package/compose/instructions_import.py +537 -0
  67. package/compose/instructions_install.py +1932 -0
  68. package/compose/instructions_session.py +852 -0
  69. package/compose/instructions_setup.py +713 -0
  70. package/compose/instructions_setup_cli.py +607 -0
  71. package/compose/instructions_setup_i18n.py +327 -0
  72. package/compose/instructions_setup_ui.py +647 -0
  73. package/compose/instructions_store.py +1668 -0
  74. package/compose/instructions_transaction.py +308 -0
  75. package/compose/instructions_ui.py +975 -0
  76. package/compose/instructions_ui_runtime.py +279 -0
  77. package/compose/instructions_understand.py +678 -0
  78. package/compose/native_cli.py +52 -0
  79. package/compose/register-hooks.py +1 -1
  80. package/compose/runtime_entry.py +58 -0
  81. package/compose/setup/START.md +11 -11
  82. package/compose/windows_deploy.py +719 -0
  83. package/docs/advanced-launch.md +11 -11
  84. package/docs/instructions-compatibility.md +86 -0
  85. package/docs/{corpus.md → instructions.md} +36 -8
  86. package/docs/recovery.md +10 -10
  87. package/docs/releases/0.19.2.md +38 -0
  88. package/docs/releases/0.19.3.md +107 -0
  89. package/docs/session-model.md +31 -20
  90. package/docs/setup.md +63 -26
  91. package/docs/understand.md +6 -6
  92. package/docs/windows.md +99 -0
  93. package/install.sh +71 -69
  94. package/launch/agent-launch.py +309 -293
  95. package/launch/agent-launch.toml +2 -2
  96. package/launch/agent-launch.zsh +11 -1
  97. package/launch/i18n/en.toml +55 -55
  98. package/launch/i18n/ja.toml +56 -56
  99. package/launch/i18n/ko.toml +56 -56
  100. package/launch/shell_integration.py +4 -4
  101. package/learn/collect-learning.py +10 -10
  102. package/learn/learning.schema.json +1 -1
  103. package/learn/migrate-learnings.py +51 -51
  104. package/package.json +33 -12
  105. package/provenance.json +1 -1
  106. /package/docs/assets/{corpus-studio.svg → instructions-studio.svg} +0 -0
@@ -1,289 +1,20 @@
1
- """Shared lock and durable pending-operation visibility for corpus state.
1
+ #!/usr/bin/env python3
2
+ """Compatibility entrypoint for corpus_transaction.py; canonical implementation: instructions_transaction.py.
2
3
 
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.
4
+ Retained for installed bridges, saved commands and third-party imports. Remove
5
+ only after the documented compatibility window and historical consumers close.
7
6
  """
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
7
  from pathlib import Path
17
- import stat
8
+ import importlib
9
+ import runpy
18
10
  import sys
19
- import threading
20
- from typing import Any, Iterator
21
-
22
-
23
- PENDING_STATES = frozenset({"PREPARED", "APPLYING", "NEEDS_RECOVERY"})
24
- _local = threading.local()
25
-
26
-
27
- class TransactionError(RuntimeError):
28
- pass
29
-
30
-
31
- class TransactionPendingError(TransactionError):
32
- pass
33
-
34
-
35
- def reject_symlink_ancestors(path: Path) -> None:
36
- """Refuse redirected user paths, allowing only macOS's fixed system aliases.
37
-
38
- /var, /tmp and /etc are root-owned aliases to /private on macOS. They precede
39
- ordinary temporary HOME/state roots and are not user-controlled redirections.
40
- The exception names their exact destinations and never applies to the leaf,
41
- a same-named link elsewhere, or a user-owned link.
42
- """
43
- for ancestor in (path, *path.parents):
44
- if not ancestor.is_symlink():
45
- continue
46
- system_alias = (sys.platform == "darwin" and ancestor != path
47
- and ancestor in {Path("/var"), Path("/tmp"), Path("/etc")}
48
- and ancestor.lstat().st_uid == 0
49
- and ancestor.parent / os.readlink(ancestor) == Path("/private") / ancestor.name)
50
- if not system_alias:
51
- raise TransactionError(f"refusing symlink transaction target: {ancestor}")
52
-
53
-
54
- def _key(state_root: Path) -> str:
55
- return str(Path(state_root).expanduser().resolve())
56
-
57
-
58
- def _depths(name: str) -> dict[str, int]:
59
- value = getattr(_local, name, None)
60
- if value is None:
61
- value = {}
62
- setattr(_local, name, value)
63
- return value
64
-
65
-
66
- @contextlib.contextmanager
67
- def _transaction_lock(state_root: Path, *, readonly: bool) -> Iterator[bool]:
68
- root = Path(state_root).expanduser()
69
- if root.is_symlink():
70
- raise TransactionError(f"unsafe corpus state root: {root}")
71
- if readonly:
72
- reject_symlink_ancestors(root)
73
- key = _key(root)
74
- depths = _depths("lock_depths")
75
- if depths.get(key, 0):
76
- depths[key] += 1
77
- try:
78
- yield True
79
- finally:
80
- depths[key] -= 1
81
- return
82
- if not readonly:
83
- root.mkdir(parents=True, exist_ok=True, mode=0o700)
84
- lock = root / ".corpus-store.lock"
85
- if lock.is_symlink():
86
- raise TransactionError(f"unsafe corpus transaction lock: {lock}")
87
- flags = (os.O_RDONLY | os.O_NONBLOCK if readonly else os.O_CREAT | os.O_RDWR) | getattr(os, "O_NOFOLLOW", 0)
88
- try:
89
- descriptor = os.open(lock, flags, 0o600)
90
- except FileNotFoundError:
91
- if not readonly:
92
- raise
93
- yield False
94
- return
95
- try:
96
- if readonly and not stat.S_ISREG(os.fstat(descriptor).st_mode):
97
- raise TransactionError(f"unsafe corpus transaction lock: {lock}")
98
- try:
99
- fcntl.flock(descriptor, fcntl.LOCK_EX | (fcntl.LOCK_NB if readonly else 0))
100
- except BlockingIOError:
101
- if not readonly:
102
- raise
103
- yield False
104
- return
105
- depths[key] = 1
106
- try:
107
- yield True
108
- finally:
109
- depths.pop(key, None)
110
- fcntl.flock(descriptor, fcntl.LOCK_UN)
111
- finally:
112
- os.close(descriptor)
113
-
114
-
115
- @contextlib.contextmanager
116
- def transaction_lock(state_root: Path) -> Iterator[None]:
117
- """The single re-entrant cross-process lock for store and installer work."""
118
- with _transaction_lock(state_root, readonly=False):
119
- yield
120
-
121
-
122
- @contextlib.contextmanager
123
- def try_transaction_lock(state_root: Path) -> Iterator[bool]:
124
- """Observe under the existing lock, or defer without blocking or creating state."""
125
- with _transaction_lock(state_root, readonly=True) as acquired:
126
- yield acquired
127
-
128
-
129
- @contextlib.contextmanager
130
- def operation_scope(state_root: Path) -> Iterator[None]:
131
- """Permit the coordinating writer to inspect its own pending journal."""
132
- key = _key(Path(state_root))
133
- depths = _depths("operation_depths")
134
- depths[key] = depths.get(key, 0) + 1
135
- try:
136
- yield
137
- finally:
138
- remaining = depths[key] - 1
139
- if remaining:
140
- depths[key] = remaining
141
- else:
142
- depths.pop(key, None)
143
-
144
-
145
- def operation_scope_active(state_root: Path) -> bool:
146
- return bool(_depths("operation_depths").get(_key(Path(state_root)), 0))
147
-
148
-
149
- def _journal_records(state_root: Path, *, coordinator_only: bool = False) -> list[dict[str, Any]]:
150
- root = Path(state_root).expanduser() / "runtime"
151
- records: list[dict[str, Any]] = []
152
- # ``resets`` predates the unified transaction directory and remains visible
153
- # so an old interrupted reset is never silently treated as complete.
154
- for directory in (root / "transactions", root / "installer-transactions", root / "resets", root / "migrations"):
155
- if not directory.exists():
156
- continue
157
- if directory.is_symlink() or not directory.is_dir():
158
- raise TransactionError(f"unsafe transaction journal root: {directory}")
159
- for journal in sorted(directory.glob("*/journal.json")):
160
- if journal.parent.is_symlink() or journal.is_symlink() or not journal.is_file():
161
- raise TransactionError(f"unsafe transaction journal: {journal}")
162
- try:
163
- value = json.loads(journal.read_text(encoding="utf-8"))
164
- except (OSError, ValueError) as exc:
165
- raise TransactionError(f"unreadable transaction journal: {journal}") from exc
166
- if not isinstance(value, dict):
167
- raise TransactionError(f"invalid transaction journal: {journal}")
168
- # Store owns its source-only install journal. It can safely finish
169
- # its own PREPARED source pair under the same lock; launcher/config
170
- # readers must only block on the wider installer/reset coordinator.
171
- coordinator = directory.name in {"installer-transactions", "resets", "migrations"} or value.get("owner") == "installer"
172
- if value.get("state") in PENDING_STATES and (not coordinator_only or coordinator):
173
- fallback = "migrate" if directory.name == "migrations" else "reset" if coordinator else "source"
174
- records.append({"path": str(journal), "kind": value.get("kind", fallback),
175
- "owner": "installer" if coordinator else "store",
176
- "state": value.get("state"), "phase": value.get("phase")})
177
- return records
178
-
179
-
180
- def pending_status(state_root: Path) -> dict[str, Any]:
181
- records = _journal_records(state_root)
182
- return {"pending": bool(records), "transactions": records}
183
-
184
-
185
- def pending_operations(state_root: Path) -> list[dict[str, Any]]:
186
- """Return pending journals for source readers and management views."""
187
- return pending_status(state_root)["transactions"]
188
-
189
-
190
- def guard_pending(state_root: Path) -> None:
191
- """Fail before a config/source reader consumes an incomplete publication."""
192
- key = _key(Path(state_root))
193
- if _depths("operation_depths").get(key, 0):
194
- return
195
- pending = _journal_records(state_root, coordinator_only=True)
196
- if pending:
197
- first = pending[0]
198
- raise TransactionPendingError(
199
- "corpus install/reset/migration needs recovery before reading current configuration: "
200
- f"{first['path']} ({first['state']})"
201
- )
202
-
203
-
204
- def _valid_release(state_root: Path, record: dict[str, Any]) -> Path:
205
- raw = record.get("package_root")
206
- digest = record.get("release_digest")
207
- if not isinstance(raw, str) or not isinstance(digest, str):
208
- raise TransactionPendingError("private install record has no confirmed immutable release")
209
- root = (Path(state_root).expanduser() / "runtime" / "releases").absolute()
210
- release = Path(raw)
211
- try:
212
- release.absolute().relative_to(root)
213
- except ValueError as exc:
214
- raise TransactionPendingError("private install record points outside immutable releases") from exc
215
- if release.name != digest or release.is_symlink() or not release.is_dir():
216
- raise TransactionPendingError("private install record has an invalid immutable release")
217
- entries = record.get("installed_files")
218
- if not isinstance(entries, list) or not entries:
219
- raise TransactionPendingError("private install record has no release inventory")
220
- # The release digest is the digest of the ordered path+bytes stream. The
221
- # installer computes it before any pointer publication, so this is a cheap
222
- # structural confirmation suitable for a config reader; full verification
223
- # remains CorpusInstaller.verify's responsibility.
224
- actual = hashlib.sha256()
225
- for entry in entries:
226
- if not isinstance(entry, dict) or not isinstance(entry.get("path"), str):
227
- raise TransactionPendingError("private install record has invalid release inventory")
228
- relative = Path(entry["path"])
229
- if relative.is_absolute() or ".." in relative.parts:
230
- raise TransactionPendingError("private install record has unsafe release inventory")
231
- member = release / relative
232
- if member.is_symlink() or not member.is_file():
233
- raise TransactionPendingError("confirmed release member is unavailable")
234
- data = member.read_bytes()
235
- actual.update(entry["path"].encode("utf-8") + b"\0" + data + b"\0")
236
- if actual.hexdigest() != digest:
237
- raise TransactionPendingError("confirmed release digest does not match inventory")
238
- return release
239
-
240
-
241
- def confirmed_release(state_root: Path) -> Path:
242
- """Return the last fully confirmed release while a coordinator is pending.
243
11
 
244
- A pending update's ``after`` record is deliberately not trusted. The
245
- journal's exact ``before`` private-install bytes identify the previous
246
- generation; a first installation has none and therefore fails closed.
247
- """
248
- root = Path(state_root).expanduser()
249
- pending = _journal_records(root, coordinator_only=True)
250
- migration = next((item for item in pending if item["kind"] == "migrate"), None)
251
- if migration is not None:
252
- try:
253
- value = json.loads(Path(migration["path"]).read_text(encoding="utf-8"))
254
- before = value["prior_install"]
255
- encoded = before.get("bytes_b64") if isinstance(before, dict) else None
256
- if not isinstance(encoded, str):
257
- raise ValueError("no prior private install")
258
- record = json.loads(base64.b64decode(encoded.encode("ascii"), validate=True))
259
- except (KeyError, OSError, ValueError, TypeError) as exc:
260
- raise TransactionPendingError("pending migration has no confirmed prior private install") from exc
261
- if not isinstance(record, dict):
262
- raise TransactionPendingError("prior migration install record is invalid")
263
- return _valid_release(root, record)
264
- install = next((item for item in pending if item["kind"] == "install"), None)
265
- if install is not None:
266
- journal = Path(install["path"])
267
- try:
268
- value = json.loads(journal.read_text(encoding="utf-8"))
269
- record_entry = next(entry for entry in value.get("paths", [])
270
- if isinstance(entry, dict) and str(entry.get("path", "")).endswith(
271
- "/runtime/private-install.json"))
272
- before = record_entry.get("before", {})
273
- encoded = before.get("bytes_b64") if isinstance(before, dict) else None
274
- if not isinstance(encoded, str):
275
- raise ValueError("no prior private-install record")
276
- record = json.loads(base64.b64decode(encoded.encode("ascii"), validate=True))
277
- except (StopIteration, ValueError, TypeError, json.JSONDecodeError) as exc:
278
- raise TransactionPendingError("first or incomplete install has no confirmed prior release") from exc
279
- if not isinstance(record, dict):
280
- raise TransactionPendingError("prior private-install record is invalid")
281
- return _valid_release(root, record)
282
- path = root / "runtime" / "private-install.json"
283
- try:
284
- record = json.loads(path.read_text(encoding="utf-8"))
285
- except (OSError, ValueError) as exc:
286
- raise TransactionPendingError("pending reset has no confirmed private install") from exc
287
- if not isinstance(record, dict):
288
- raise TransactionPendingError("confirmed private install is invalid")
289
- return _valid_release(root, record)
12
+ if __name__ == "__main__":
13
+ runpy.run_path(str(Path(__file__).with_name('instructions_transaction.py')), run_name="__main__")
14
+ else:
15
+ _name = 'instructions_transaction'
16
+ _module = importlib.import_module("." + _name, __package__) if __package__ else importlib.import_module(_name)
17
+ for _symbol in tuple(vars(_module)):
18
+ if "Instructions" in _symbol:
19
+ setattr(_module, _symbol.replace("Instructions", "Corpus"), getattr(_module, _symbol))
20
+ sys.modules[__name__] = _module