agent-bios 0.19.4 → 0.20.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.
- package/DEPENDENCIES.md +19 -5
- package/README.md +14 -19
- package/claude/agents/frontier.md +1 -1
- package/claude/guides/claude-prompting.md +475 -234
- package/claude/guides/cli-multi-model-workflow.md +4 -3
- package/claude/guides/gpt-prompting.md +235 -136
- package/claude/guides/session-distill-workflow.md +93 -43
- package/claude/guides/tooling-gotchas.md +3 -1
- package/codex/guides/claude-prompting.md +475 -234
- package/codex/guides/cli-multi-model-workflow.md +4 -3
- package/codex/guides/gpt-prompting.md +235 -136
- package/codex/guides/session-distill-workflow.md +93 -43
- package/codex/guides/tooling-gotchas.md +3 -1
- package/compose/assemble.py +4 -1
- package/compose/canary.sh +8 -6
- package/compose/host_platform.py +158 -15
- package/compose/instructions-state.py +183 -41
- package/compose/instructions_install.py +222 -27
- package/compose/instructions_session.py +250 -75
- package/compose/instructions_setup_cli.py +2 -36
- package/compose/instructions_store.py +160 -3
- package/compose/instructions_transaction.py +29 -5
- package/docs/advanced-launch.md +4 -0
- package/docs/releases/0.20.0.md +102 -0
- package/install.sh +42 -14
- package/launch/agent-launch.py +152 -18
- package/launch/agent-launch.toml +17 -7
- package/launch/agent-launch.zsh +104 -13
- package/launch/claude_subcommands.py +179 -0
- package/launch/shell_integration.py +7 -1
- package/learn/collect-learning.py +60 -9
- package/learn/migrate-learnings.py +70 -4
- package/learn/redact.py +2 -1
- package/package.json +36 -3
- package/provenance.json +1 -1
- package/session-cost.py +80 -9
- package/session-distill/coverage.json +6 -0
- package/session-distill/distill.py +2575 -0
- package/session-distill/grammar/__init__.py +0 -0
- package/session-distill/grammar/owner_lines.py +874 -0
- package/session-distill/originators.json +9 -0
- package/session-distill/packets/cross_review.md +31 -0
- package/session-distill/packets/form.md +86 -0
- package/session-distill/packets/judge.md +81 -0
- package/session-distill/packets/placement_contract.md +90 -0
- package/session-distill/packets/propose.md +124 -0
- package/session-distill/packets/read.md +57 -0
- package/session-distill/packets/reconsider.md +53 -0
- package/session-distill/packets/s7b.md +65 -0
- package/session-distill/packets/s9b.md +39 -0
- package/session-distill/packets/stitch.md +35 -0
- package/session-distill/packets/sweep.md +33 -0
- package/session-distill/runlib/__init__.py +0 -0
- package/session-distill/runlib/bound.py +1102 -0
- package/session-distill/runlib/breaker.py +467 -0
- package/session-distill/runlib/census.py +2347 -0
- package/session-distill/runlib/claims.py +420 -0
- package/session-distill/runlib/controls.py +902 -0
- package/session-distill/runlib/coverage.py +881 -0
- package/session-distill/runlib/declare.py +888 -0
- package/session-distill/runlib/delivery_evidence.py +1145 -0
- package/session-distill/runlib/derive.py +812 -0
- package/session-distill/runlib/destinations.py +3072 -0
- package/session-distill/runlib/dispatch.py +7939 -0
- package/session-distill/runlib/drift.py +1077 -0
- package/session-distill/runlib/entry.py +401 -0
- package/session-distill/runlib/evidence.py +890 -0
- package/session-distill/runlib/exposure.py +1162 -0
- package/session-distill/runlib/gate.py +2727 -0
- package/session-distill/runlib/gitread.py +79 -0
- package/session-distill/runlib/inventory.py +19624 -0
- package/session-distill/runlib/journal.py +1919 -0
- package/session-distill/runlib/ledger.py +3210 -0
- package/session-distill/runlib/ledger_compat.py +101 -0
- package/session-distill/runlib/ledger_migration.py +190 -0
- package/session-distill/runlib/lifecycle_intake.py +693 -0
- package/session-distill/runlib/lineage.py +454 -0
- package/session-distill/runlib/measures.py +249 -0
- package/session-distill/runlib/monitor.py +1180 -0
- package/session-distill/runlib/operations.py +522 -0
- package/session-distill/runlib/packet.py +838 -0
- package/session-distill/runlib/placement.py +1769 -0
- package/session-distill/runlib/projection.py +4090 -0
- package/session-distill/runlib/ranking.py +740 -0
- package/session-distill/runlib/receipts.py +200 -0
- package/session-distill/runlib/records.py +1965 -0
- package/session-distill/runlib/search.py +249 -0
- package/session-distill/runlib/sequencing.py +829 -0
- package/session-distill/runlib/sources.py +641 -0
- package/session-distill/runlib/stage_adjudicate.py +845 -0
- package/session-distill/runlib/stage_apply.py +1378 -0
- package/session-distill/runlib/stage_approvals.py +758 -0
- package/session-distill/runlib/stage_close.py +1220 -0
- package/session-distill/runlib/stage_confirm.py +929 -0
- package/session-distill/runlib/stage_delivery.py +3080 -0
- package/session-distill/runlib/stage_form.py +2576 -0
- package/session-distill/runlib/stage_judge.py +4248 -0
- package/session-distill/runlib/stage_propose.py +3307 -0
- package/session-distill/runlib/stage_read.py +5179 -0
- package/session-distill/runlib/stage_render.py +2739 -0
- package/session-distill/runlib/stage_retrieve.py +924 -0
- package/session-distill/runlib/stage_review_korean.py +1002 -0
- package/session-distill/runlib/stage_review_proposals.py +1292 -0
- package/session-distill/runlib/stagelock.py +412 -0
- package/session-distill/runlib/stop.py +1061 -0
- package/session-distill/runlib/targets.py +809 -0
- package/session-distill/runlib/usage.py +280 -0
- package/session-distill/runlib/validate.py +319 -0
- package/session-distill/runlib/views.py +4327 -0
- package/session-distill/schemas/adjudication.schema.json +35 -0
- package/session-distill/schemas/approval.schema.json +35 -0
- package/session-distill/schemas/census.schema.json +128 -0
- package/session-distill/schemas/checks.schema.json +207 -0
- package/session-distill/schemas/claim.schema.json +16 -0
- package/session-distill/schemas/confirmation.schema.json +24 -0
- package/session-distill/schemas/coverage.schema.json +66 -0
- package/session-distill/schemas/cross_review.schema.json +24 -0
- package/session-distill/schemas/event.schema.json +20 -0
- package/session-distill/schemas/evidence.schema.json +20 -0
- package/session-distill/schemas/expected_observation.schema.json +18 -0
- package/session-distill/schemas/form.schema.json +103 -0
- package/session-distill/schemas/intake.schema.json +71 -0
- package/session-distill/schemas/inventory.schema.json +872 -0
- package/session-distill/schemas/judge.schema.json +77 -0
- package/session-distill/schemas/ledger.schema.json +313 -0
- package/session-distill/schemas/observation.schema.json +16 -0
- package/session-distill/schemas/propose.schema.json +555 -0
- package/session-distill/schemas/read.schema.json +76 -0
- package/session-distill/schemas/reconsider.schema.json +122 -0
- package/session-distill/schemas/run.schema.json +150 -0
- package/session-distill/schemas/s7b.schema.json +200 -0
- package/session-distill/schemas/s9b.schema.json +28 -0
- package/session-distill/schemas/stitch.schema.json +25 -0
- package/session-distill/schemas/sweep.schema.json +25 -0
- package/session-distill/seats.json +149 -0
- package/session-distill/tables/allowed_pairs.json +257 -0
- package/session-distill/tables/controls.json +30 -0
- package/session-distill/tables/delivery_evidence.json +36 -0
- package/session-distill/tables/delivery_evidence_fixtures.json +731 -0
- package/session-distill/tables/destinations.json +684 -0
- package/session-distill/tables/drift_layers.json +68 -0
- package/session-distill/tables/exposure_rules.json +192 -0
- package/session-distill/tables/placement_rules.json +148 -0
- package/session-distill/tables/propose_fixtures.json +154 -0
- package/session-distill/tables/ranking.json +194 -0
- package/session-distill/tables/redundancy.json +10 -0
- package/session-distill/tables/structural_rules.json +44 -0
- package/session-distill/tables/transition_fixtures.json +398 -0
- package/session-distill/tables/transitions.json +69 -0
- package/session-distill/tables/unit_outcome.json +67 -0
- package/session-distill/tables/unit_outcome_fixtures.json +2364 -0
- package/wrappers/claude-run.sh +481 -33
- package/wrappers/claude_hermetic_evidence.py +1423 -0
- package/wrappers/codex-helm.sh +38 -7
- package/wrappers/codex-run.sh +183 -20
- package/wrappers/codex_frame_filter.py +1199 -0
- package/wrappers/codex_protocol.py +737 -0
- package/wrappers/jsonl_lines.py +65 -0
package/launch/agent-launch.py
CHANGED
|
@@ -25,9 +25,6 @@ from typing import Any, Callable, NoReturn
|
|
|
25
25
|
|
|
26
26
|
if os.name == "nt":
|
|
27
27
|
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1] / "compose"))
|
|
28
|
-
from host_platform import file_locks as fcntl
|
|
29
|
-
else:
|
|
30
|
-
import fcntl
|
|
31
28
|
|
|
32
29
|
|
|
33
30
|
TIER_ORDER = ("frontier", "helm", "workhorse", "sweep")
|
|
@@ -4108,6 +4105,42 @@ class BackRequested(RuntimeError):
|
|
|
4108
4105
|
pass
|
|
4109
4106
|
|
|
4110
4107
|
|
|
4108
|
+
_LOCK_PLATFORMS: dict[pathlib.Path, Any] = {}
|
|
4109
|
+
|
|
4110
|
+
|
|
4111
|
+
def lock_platform(config_path: pathlib.Path):
|
|
4112
|
+
"""compose/host_platform.py, which owns the shared bounded lock wait (D-20261102-49b466), loaded by
|
|
4113
|
+
path under a private name: from the package this launcher runs in, or, for the compatibility
|
|
4114
|
+
install's standalone copy in ~/.local/bin, from the copy deployed beside the launcher's config.
|
|
4115
|
+
With neither, the launcher refuses naming both rather than waiting on a lock without a bound."""
|
|
4116
|
+
import importlib.util
|
|
4117
|
+
|
|
4118
|
+
candidates = (pathlib.Path(__file__).resolve().parents[1] / "compose" / "host_platform.py",
|
|
4119
|
+
config_path.with_name("host_platform.py"))
|
|
4120
|
+
for path in candidates:
|
|
4121
|
+
if path in _LOCK_PLATFORMS:
|
|
4122
|
+
return _LOCK_PLATFORMS[path]
|
|
4123
|
+
if path.is_file():
|
|
4124
|
+
spec = importlib.util.spec_from_file_location(
|
|
4125
|
+
"agent_launch_host_platform_" + hashlib.sha256(str(path).encode()).hexdigest()[:12], path)
|
|
4126
|
+
module = importlib.util.module_from_spec(spec)
|
|
4127
|
+
spec.loader.exec_module(module)
|
|
4128
|
+
_LOCK_PLATFORMS[path] = module
|
|
4129
|
+
return module
|
|
4130
|
+
raise LaunchError("the launcher's lock helper is missing (looked for "
|
|
4131
|
+
+ " and ".join(str(path) for path in candidates) + "); reinstall agent-bios")
|
|
4132
|
+
|
|
4133
|
+
|
|
4134
|
+
def lock_within(handle, name: str, config_path: pathlib.Path) -> None:
|
|
4135
|
+
"""Hold `handle`'s exclusive lock, waiting at most the shared bound; past it, a LaunchError names
|
|
4136
|
+
the lock. The launcher's writers used to wait on their locks with no deadline."""
|
|
4137
|
+
platform = lock_platform(config_path)
|
|
4138
|
+
try:
|
|
4139
|
+
platform.lock_within(handle, name)
|
|
4140
|
+
except platform.LockWaitExpired as exc:
|
|
4141
|
+
raise LaunchError(str(exc)) from exc
|
|
4142
|
+
|
|
4143
|
+
|
|
4111
4144
|
def resolve_command(value: str) -> str:
|
|
4112
4145
|
# Guarded here rather than at each call site because the callers disagree about what a
|
|
4113
4146
|
# failure means: `resolve_backend` reports it and stops, while `host_dispatch_command`
|
|
@@ -5727,6 +5760,12 @@ def build_plan(config: dict[str, Any], host: str, preset_name: str) -> dict[str,
|
|
|
5727
5760
|
raise LaunchError(f"invalid preset or host binding: {host}/{preset_name}") from exc
|
|
5728
5761
|
if not isinstance(preset, dict) or not isinstance(tiers, dict):
|
|
5729
5762
|
raise LaunchError(f"invalid preset or host binding: {host}/{preset_name}")
|
|
5763
|
+
# The same verdict wherever a preset is named — a flag, a saved mode, a resume. The menu
|
|
5764
|
+
# withholds it; this is what makes the withholding a rule rather than a screen.
|
|
5765
|
+
if preset_withheld(preset):
|
|
5766
|
+
raise LaunchError(
|
|
5767
|
+
f"PRESET_AUTHOR_ONLY {preset_name}: the preset edits the agent-bios instructions "
|
|
5768
|
+
f"themselves and names paths only a checkout has; this tree is a packaged install")
|
|
5730
5769
|
validate_host_tiers(host, tiers)
|
|
5731
5770
|
all_overrides = preset.get("tier_overrides", {})
|
|
5732
5771
|
if not isinstance(all_overrides, dict):
|
|
@@ -6644,7 +6683,12 @@ def register_reviewer_wizard(
|
|
|
6644
6683
|
lock_path, os.O_CREAT | os.O_WRONLY | getattr(os, "O_NOFOLLOW", 0), 0o600
|
|
6645
6684
|
)
|
|
6646
6685
|
with os.fdopen(lock_fd, "w") as lock_handle:
|
|
6647
|
-
|
|
6686
|
+
try:
|
|
6687
|
+
lock_within(lock_handle, f"the launcher methods lock ({lock_path})", config_path)
|
|
6688
|
+
except LaunchError as exc:
|
|
6689
|
+
_instructions_info(ui, t("wizard.title"), [str(exc)],
|
|
6690
|
+
back_hint=t("instructions.back.hint"))
|
|
6691
|
+
return False
|
|
6648
6692
|
# Existence is part of the snapshot: a file created (or removed)
|
|
6649
6693
|
# since the trial must read as a race even when its bytes happen
|
|
6650
6694
|
# to equal the header the wizard would have invented.
|
|
@@ -7692,7 +7736,7 @@ def save_preset(
|
|
|
7692
7736
|
lock_path = target.with_name(target.name + ".lock")
|
|
7693
7737
|
lock_fd = os.open(lock_path, os.O_CREAT | os.O_WRONLY | getattr(os, "O_NOFOLLOW", 0), 0o600)
|
|
7694
7738
|
with os.fdopen(lock_fd, "w") as lock_handle:
|
|
7695
|
-
|
|
7739
|
+
lock_within(lock_handle, f"the launcher presets lock ({lock_path})", config_path)
|
|
7696
7740
|
try:
|
|
7697
7741
|
kept = remove_preset_block(
|
|
7698
7742
|
target.read_text(encoding="utf-8"), name
|
|
@@ -8244,6 +8288,29 @@ def customize(
|
|
|
8244
8288
|
|
|
8245
8289
|
|
|
8246
8290
|
DISTILL_PRESET = "session-distill"
|
|
8291
|
+
# An author-only preset instructs its agent to edit THIS repository's instructions, so its mission
|
|
8292
|
+
# names paths that exist only in a checkout. Offering it on a packaged install offers a route whose
|
|
8293
|
+
# first step fails, which is why `compose/assemble.py` already withholds an author-only GUIDE from a
|
|
8294
|
+
# packaged user; until now the preset's own `audience = "author"` was read by the payload gate and
|
|
8295
|
+
# by nothing else, so the route stayed open.
|
|
8296
|
+
#
|
|
8297
|
+
# The marker is `gates/`, which `gates/check-package.sh` forbids the payload from carrying in both
|
|
8298
|
+
# directions. Its presence therefore IS "this tree is a checkout", and no second declaration exists
|
|
8299
|
+
# to drift from it.
|
|
8300
|
+
AUTHOR_TREE_MARKER = "gates"
|
|
8301
|
+
|
|
8302
|
+
|
|
8303
|
+
def author_tree(root: Any = None) -> bool:
|
|
8304
|
+
"""Whether the tree this launcher runs from is an agent-bios checkout."""
|
|
8305
|
+
base = pathlib.Path(root) if root is not None else pathlib.Path(__file__).resolve().parent.parent
|
|
8306
|
+
return (base / AUTHOR_TREE_MARKER).is_dir()
|
|
8307
|
+
|
|
8308
|
+
|
|
8309
|
+
def preset_withheld(preset: dict[str, Any], root: Any = None) -> bool:
|
|
8310
|
+
"""Whether this preset must not be offered or launched from the tree we run in."""
|
|
8311
|
+
return isinstance(preset, dict) and preset.get("audience") == "author" and not author_tree(root)
|
|
8312
|
+
|
|
8313
|
+
|
|
8247
8314
|
INSTRUCTIONS_STATUS_PATH = pathlib.Path(
|
|
8248
8315
|
_instructions_environment(
|
|
8249
8316
|
"AGENT_BIOS_INSTRUCTIONS_STATUS", "AGENT_BIOS_CORPUS_STATUS",
|
|
@@ -9369,6 +9436,10 @@ def pick_mode_and_preset(
|
|
|
9369
9436
|
t("instructions.private.description") if private_instructions_enabled() else t("instructions.description"),
|
|
9370
9437
|
)
|
|
9371
9438
|
)
|
|
9439
|
+
if preset_withheld(presets.get(DISTILL_PRESET, {})):
|
|
9440
|
+
# Withheld, not greyed out: a route whose first instruction names a path the
|
|
9441
|
+
# reader does not have is worse than an absent route (WP-22a).
|
|
9442
|
+
mode_options = [o for o in mode_options if o.value != DISTILL_MODE]
|
|
9372
9443
|
if private_instructions_enabled():
|
|
9373
9444
|
mode_options.append(MenuOption(UNDERSTAND_OPTION, t("understand.title"), t("understand.description")))
|
|
9374
9445
|
mode_options.append(MenuOption(SHELL_CONNECTION_OPTION, t("shell.title"), t("shell.description")))
|
|
@@ -9446,6 +9517,13 @@ def pick_mode_and_preset(
|
|
|
9446
9517
|
mode = None
|
|
9447
9518
|
continue
|
|
9448
9519
|
if mode == DISTILL_MODE:
|
|
9520
|
+
# Reached by a resume, a flag or a stale saved mode rather than the menu: the same
|
|
9521
|
+
# verdict, by name, instead of a hub whose first instruction cannot be followed.
|
|
9522
|
+
if preset_withheld(presets.get(DISTILL_PRESET, {})):
|
|
9523
|
+
raise LaunchError(
|
|
9524
|
+
f"PRESET_AUTHOR_ONLY {DISTILL_PRESET}: this preset edits the agent-bios "
|
|
9525
|
+
f"instructions themselves and needs a checkout; a packaged install has none, "
|
|
9526
|
+
f"so it is not offered here")
|
|
9449
9527
|
if distill_hub(config, ui) != "start":
|
|
9450
9528
|
mode = None
|
|
9451
9529
|
continue
|
|
@@ -10711,26 +10789,79 @@ def _line_count(path: pathlib.Path) -> int:
|
|
|
10711
10789
|
return 0
|
|
10712
10790
|
|
|
10713
10791
|
|
|
10714
|
-
def
|
|
10715
|
-
"""
|
|
10792
|
+
def _transcript_file_count(home: pathlib.Path) -> int:
|
|
10793
|
+
"""Transcript files under the two hosts' roots: a directory listing, no parsing.
|
|
10716
10794
|
|
|
10717
|
-
|
|
10718
|
-
|
|
10719
|
-
|
|
10720
|
-
"""
|
|
10795
|
+
Claude keeps one file per session directly inside each project directory; Codex keeps
|
|
10796
|
+
rollouts, plain or compressed in place, anywhere below `sessions/` and `archived_sessions/`.
|
|
10797
|
+
The window-close writer (session-distill/update-state.py) counts them the same way, and its
|
|
10798
|
+
self-test holds the two counts to one answer."""
|
|
10799
|
+
total = 0
|
|
10800
|
+
try:
|
|
10801
|
+
with os.scandir(home / ".claude" / "projects") as projects:
|
|
10802
|
+
for project in projects:
|
|
10803
|
+
if project.is_dir(follow_symlinks=False):
|
|
10804
|
+
with os.scandir(project.path) as files:
|
|
10805
|
+
total += sum(1 for f in files if f.name.endswith(".jsonl") and f.is_file(follow_symlinks=False))
|
|
10806
|
+
except OSError:
|
|
10807
|
+
pass
|
|
10808
|
+
pending = [home / ".codex" / "sessions", home / ".codex" / "archived_sessions"]
|
|
10809
|
+
while pending:
|
|
10810
|
+
try:
|
|
10811
|
+
with os.scandir(pending.pop()) as entries:
|
|
10812
|
+
for entry in entries:
|
|
10813
|
+
if entry.is_dir(follow_symlinks=False):
|
|
10814
|
+
pending.append(pathlib.Path(entry.path))
|
|
10815
|
+
elif entry.name.endswith((".jsonl", ".jsonl.zst")) and entry.is_file(follow_symlinks=False):
|
|
10816
|
+
total += 1
|
|
10817
|
+
except OSError:
|
|
10818
|
+
continue
|
|
10819
|
+
return total
|
|
10820
|
+
|
|
10821
|
+
|
|
10822
|
+
def _nudge_setting(settings: Any, key: str, default: int) -> int:
|
|
10823
|
+
"""A positive integer setting of `[session_distill]`, or `default`.
|
|
10824
|
+
|
|
10825
|
+
A hand-edited "250" made the comparison a TypeError before the launcher drew anything — a
|
|
10826
|
+
nudge is a hint, so an unusable value falls back to the default rather than taking the
|
|
10827
|
+
launch down with it. `bool` is excluded because `True` is an int that means nothing here."""
|
|
10828
|
+
value = settings.get(key, default) if isinstance(settings, dict) else default
|
|
10829
|
+
return default if isinstance(value, bool) or not isinstance(value, int) or value < 1 else value
|
|
10830
|
+
|
|
10831
|
+
|
|
10832
|
+
def session_distill_nudge(config: dict[str, Any]) -> str | None:
|
|
10833
|
+
"""Nudge when a mining window is due.
|
|
10834
|
+
|
|
10835
|
+
The baseline is written by session-distill/update-state.py at window close. A state file that
|
|
10836
|
+
carries `transcript_files_total` nudges when `cadence_days` have passed since its `window_end`
|
|
10837
|
+
or the transcript files under the hosts' roots grew by `transcript_growth`; one without it
|
|
10838
|
+
keeps the original rule, provider history line counts as a cheap proxy for new sessions. No
|
|
10839
|
+
state file means no nudge. The launcher reads this file and the hosts' directories, nothing
|
|
10840
|
+
in a checkout."""
|
|
10721
10841
|
try:
|
|
10722
10842
|
state = json.loads(SESSION_DISTILL_STATE.read_text(encoding="utf-8"))
|
|
10723
10843
|
baseline = int(state["history_lines_total"])
|
|
10724
10844
|
except (OSError, ValueError, KeyError, TypeError):
|
|
10725
10845
|
return None
|
|
10726
10846
|
settings = config.get("session_distill", {})
|
|
10727
|
-
|
|
10728
|
-
|
|
10729
|
-
|
|
10730
|
-
|
|
10731
|
-
|
|
10732
|
-
|
|
10733
|
-
|
|
10847
|
+
files_then = state.get("transcript_files_total")
|
|
10848
|
+
if isinstance(files_then, int) and not isinstance(files_then, bool):
|
|
10849
|
+
cadence = _nudge_setting(settings, "cadence_days", 14)
|
|
10850
|
+
growth = _nudge_setting(settings, "transcript_growth", 250)
|
|
10851
|
+
reasons = []
|
|
10852
|
+
try:
|
|
10853
|
+
days = (datetime.date.today() - datetime.date.fromisoformat(state["window_end"])).days
|
|
10854
|
+
except (KeyError, TypeError, ValueError):
|
|
10855
|
+
days = None
|
|
10856
|
+
if days is not None and days >= cadence:
|
|
10857
|
+
reasons.append(f"{days} days since {state['window_end']} (cadence {cadence})")
|
|
10858
|
+
grown = _transcript_file_count(pathlib.Path.home()) - files_then
|
|
10859
|
+
if grown >= growth:
|
|
10860
|
+
reasons.append(f"~{grown} new transcript files since {state.get('window_end', '?')} (threshold {growth})")
|
|
10861
|
+
if not reasons:
|
|
10862
|
+
return None
|
|
10863
|
+
return "session-distill due: " + "; ".join(reasons) + " — launch the Session distill preset to run the next mining window"
|
|
10864
|
+
threshold = _nudge_setting(settings, "nudge_after", 250)
|
|
10734
10865
|
current = _line_count(pathlib.Path.home() / ".claude/history.jsonl") + _line_count(
|
|
10735
10866
|
pathlib.Path.home() / ".codex/history.jsonl"
|
|
10736
10867
|
)
|
|
@@ -11161,6 +11292,7 @@ def main(argv: list[str], *, bundled_ui: bool = False) -> int:
|
|
|
11161
11292
|
raise LaunchError("an instruction-pinned resume requires a private installation")
|
|
11162
11293
|
store = instructions_store()
|
|
11163
11294
|
import instructions_session
|
|
11295
|
+
instructions_session.raise_on_termination()
|
|
11164
11296
|
return instructions_session.launch(command, [], store.state_root, args.host, {},
|
|
11165
11297
|
resume_id=args.resume_session)
|
|
11166
11298
|
nudge = session_distill_nudge(config)
|
|
@@ -11303,6 +11435,7 @@ def main(argv: list[str], *, bundled_ui: bool = False) -> int:
|
|
|
11303
11435
|
projected += [understand_initial_prompt("<pinned-understand-session-prompt>")]
|
|
11304
11436
|
if snapshot is not None and args.dry_run:
|
|
11305
11437
|
import instructions_session
|
|
11438
|
+
instructions_session.raise_on_termination()
|
|
11306
11439
|
projected = instructions_session.compose_argv(
|
|
11307
11440
|
command,
|
|
11308
11441
|
projected,
|
|
@@ -11359,6 +11492,7 @@ def main(argv: list[str], *, bundled_ui: bool = False) -> int:
|
|
|
11359
11492
|
summary_stream.flush()
|
|
11360
11493
|
if snapshot is not None:
|
|
11361
11494
|
import instructions_session
|
|
11495
|
+
instructions_session.raise_on_termination()
|
|
11362
11496
|
return instructions_session.launch(command, projected, store.state_root, args.host,
|
|
11363
11497
|
snapshot, env=env,
|
|
11364
11498
|
include_global_instructions=plan["include_global_instructions"])
|
package/launch/agent-launch.toml
CHANGED
|
@@ -189,7 +189,7 @@ sweep = "${CODEX_HOME}/agents/sweep.toml"
|
|
|
189
189
|
# Every id named anywhere in this file must have a row here, and every row must be named
|
|
190
190
|
# somewhere — both directions are gated, so this table cannot quietly outlive its bindings.
|
|
191
191
|
[models]
|
|
192
|
-
"claude-fable-5-
|
|
192
|
+
"claude-fable-5-2" = { display = "Claude Fable 5.2" }
|
|
193
193
|
"claude-opus-5-5" = { display = "Claude Opus 5.5" }
|
|
194
194
|
"claude-sonnet-5-5" = { display = "Claude Sonnet 5.5" }
|
|
195
195
|
"claude-haiku-5-5" = { display = "Claude Haiku 5.5" }
|
|
@@ -199,10 +199,15 @@ sweep = "${CODEX_HOME}/agents/sweep.toml"
|
|
|
199
199
|
|
|
200
200
|
[hosts.claude]
|
|
201
201
|
provider = "anthropic"
|
|
202
|
-
models = ["claude-fable-5-
|
|
202
|
+
models = ["claude-fable-5-2", "claude-opus-5-5", "claude-sonnet-5-5", "claude-haiku-5-5"]
|
|
203
203
|
|
|
204
|
+
# Rebound from Fable 5.1 on 2026-11-11, and Fable 5.1 is RETIRED rather than kept beside
|
|
205
|
+
# it: `models` is the selectable catalogue, and a listed model no tier binds would be a
|
|
206
|
+
# site the currency check reports superseded forever, answerable only by a `superseded_by`
|
|
207
|
+
# acknowledgement nobody has a reason to make. The codex host lists exactly its distinct
|
|
208
|
+
# tier-bound models for the same reason.
|
|
204
209
|
[hosts.claude.tiers.frontier]
|
|
205
|
-
model = "claude-fable-5-
|
|
210
|
+
model = "claude-fable-5-2"
|
|
206
211
|
effort = "max"
|
|
207
212
|
|
|
208
213
|
# One step below the seats the 5.x generation used. The vendor's Opus 5.5 guidance
|
|
@@ -275,9 +280,9 @@ claude_permission_mode = "standard"
|
|
|
275
280
|
[presets.session-distill]
|
|
276
281
|
# Author-only: the workflow edits the agent-bios instructions and needs a checkout, so
|
|
277
282
|
# its mission names repo paths a packaged user does not have. Declaring it lets
|
|
278
|
-
# gates/check-package.sh judge the mission text
|
|
279
|
-
#
|
|
280
|
-
#
|
|
283
|
+
# gates/check-package.sh judge the mission text, and the launcher reads it too: a tree
|
|
284
|
+
# with no `gates/` directory is not a checkout, and the menu, the mode branch and
|
|
285
|
+
# `build_plan` each refuse the preset by name there (`preset_withheld`, WP-22a).
|
|
281
286
|
audience = "author"
|
|
282
287
|
label = "Session distill"
|
|
283
288
|
description = "Dedicated session-distill run: mine recent sessions, verify, place, and apply per the session-distill workflow. Requires an agent-bios checkout."
|
|
@@ -347,6 +352,11 @@ provider = "anthropic"
|
|
|
347
352
|
tier = "frontier"
|
|
348
353
|
|
|
349
354
|
# Nudge baseline lives in ~/.local/share/agent-bios/session-distill-state.json,
|
|
350
|
-
# written by session-distill/update-state.py at window close.
|
|
355
|
+
# written by session-distill/update-state.py at window close. A state file that records
|
|
356
|
+
# transcript_files_total nudges when cadence_days have passed since its window end or the
|
|
357
|
+
# transcript files grew by transcript_growth; one without it nudges after nudge_after new
|
|
358
|
+
# history lines.
|
|
351
359
|
[session_distill]
|
|
352
360
|
nudge_after = 250
|
|
361
|
+
cadence_days = 14
|
|
362
|
+
transcript_growth = 250
|
package/launch/agent-launch.zsh
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
# Alias expansion is OFF while this file is parsed and restored to what it was at the
|
|
2
2
|
# end: zsh expands aliases at parse time, inside function bodies too, so an alias named
|
|
3
3
|
# `builtin`, `command`, or `claude` that exists when this file is sourced would be baked
|
|
4
|
-
# into the functions below and the real binary never reached.
|
|
4
|
+
# into the functions below and the real binary never reached. A command substitution is
|
|
5
|
+
# the exception: its text is parsed again each time it runs, under the aliases then in
|
|
6
|
+
# force, so a builtin inside `$(...)` is written `\builtin`, which no alias can replace.
|
|
5
7
|
[[ -o aliases ]] && _agent_launch_aliases_were=1 || _agent_launch_aliases_were=0
|
|
6
8
|
setopt no_aliases
|
|
7
9
|
|
|
@@ -17,22 +19,111 @@ _agent_launch_direct() {
|
|
|
17
19
|
# provide is handed to whatever the user's function does. `builtin` cannot be shadowed,
|
|
18
20
|
# so the resolution is the one the comment above already promised.
|
|
19
21
|
if [[ "$host" == "claude" && -z "${_agent_launch_private_connection:-}" ]]; then
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
# The permission default goes in front of a prompt or an option, never in front of a
|
|
23
|
+
# subcommand: some subcommands are dispatched only from the first argument, so with a
|
|
24
|
+
# flag in front `claude attach <id>` is a new session whose prompt is "attach <id>",
|
|
25
|
+
# and which ones is the installed version's to say. The subcommands are what that
|
|
26
|
+
# version's `claude --help` lists (_agent_launch_claude_subcommands); a first argument
|
|
27
|
+
# that starts with `-` is no subcommand and needs no probe. When the list cannot be
|
|
28
|
+
# read, the flag stays off.
|
|
29
|
+
if [[ $# -eq 0 || "$1" == -* ]]; then
|
|
30
|
+
builtin command claude --dangerously-skip-permissions "$@"
|
|
31
|
+
elif _agent_launch_claude_subcommands && ! _agent_launch_claude_lists "$1"; then
|
|
32
|
+
builtin command claude --dangerously-skip-permissions "$@"
|
|
33
|
+
else
|
|
34
|
+
builtin command claude "$@"
|
|
35
|
+
fi
|
|
31
36
|
else
|
|
32
37
|
builtin command "$host" "$@"
|
|
33
38
|
fi
|
|
34
39
|
}
|
|
35
40
|
|
|
41
|
+
# The subcommand spellings (`stop|kill` is two) the installed `claude --help` lists under
|
|
42
|
+
# `Commands:`, in `_agent_launch_claude_verbs`. Read once per installed binary: the key is the
|
|
43
|
+
# binary's resolved path, modification time and size, held in this shell and in
|
|
44
|
+
# ~/.local/share/agent-bios/claude-subcommands (the state dir the shadow log below uses, never
|
|
45
|
+
# created here), so an update, which installs a new versioned path or rewrites the file, is
|
|
46
|
+
# probed again. Returns nonzero when no list can be read, and a failed probe is not cached.
|
|
47
|
+
#
|
|
48
|
+
# The help is run by the lister, launch/claude_subcommands.py: in a process group of its own, for
|
|
49
|
+
# at most 5 s, and answered for only when it exited 0 and listed a subcommand; on any other outcome
|
|
50
|
+
# it says why in one line on stderr. The lister is found where the private shell connection's
|
|
51
|
+
# header names it, else beside this file (the compatibility install deploys the two together, as
|
|
52
|
+
# the checkout holds them). The python3 that runs it is the one on PATH; on macOS /usr/bin/python3
|
|
53
|
+
# without the Command Line Tools would open their installer on every call, so it is not run then.
|
|
54
|
+
# When zsh/stat does not load or cannot read the binary, or there is no python3 or lister, the flag
|
|
55
|
+
# stays off and one line names the check (_agent_launch_claude_unread). A claude missing from PATH
|
|
56
|
+
# is not reported: the call that follows fails by itself, and a line about the flag would only
|
|
57
|
+
# stand in front of that error. The builtins are called as builtins, past any function of the
|
|
58
|
+
# user's that shares their name.
|
|
59
|
+
typeset -ga _agent_launch_claude_verbs
|
|
60
|
+
typeset -g _agent_launch_claude_verbs_key=""
|
|
61
|
+
typeset -g _agent_launch_claude_lister="${_agent_launch_claude_lister:-${${(%):-%x}:a:h}/claude_subcommands.py}"
|
|
62
|
+
_agent_launch_claude_unread() {
|
|
63
|
+
builtin print -ru2 -- "agent-bios: $1, so the subcommands claude lists cannot be read; claude starts" \
|
|
64
|
+
"without --dangerously-skip-permissions"
|
|
65
|
+
return 1
|
|
66
|
+
}
|
|
67
|
+
_agent_launch_claude_subcommands() {
|
|
68
|
+
setopt localoptions noksharrays no_err_return no_err_exit
|
|
69
|
+
local bin real key py listed why cache="$HOME/.local/share/agent-bios/claude-subcommands"
|
|
70
|
+
local -a words cached
|
|
71
|
+
local -A meta
|
|
72
|
+
bin="$(\builtin whence -p claude)" || return 1
|
|
73
|
+
[[ -n "$bin" ]] || return 1
|
|
74
|
+
real="${bin:A}"
|
|
75
|
+
if ! builtin zmodload -F zsh/stat b:zstat 2>/dev/null; then
|
|
76
|
+
_agent_launch_claude_unread "zsh's zsh/stat module did not load"
|
|
77
|
+
return 1
|
|
78
|
+
fi
|
|
79
|
+
if ! { builtin zstat -H meta -- "$real" } 2>/dev/null; then
|
|
80
|
+
_agent_launch_claude_unread "zstat could not read $real"
|
|
81
|
+
return 1
|
|
82
|
+
fi
|
|
83
|
+
key="${real}"$'\t'"${meta[mtime]}"$'\t'"${meta[size]}"
|
|
84
|
+
[[ "$key" == "$_agent_launch_claude_verbs_key" ]] && return 0
|
|
85
|
+
if [[ -f "$cache" && ! -L "$cache" ]]; then
|
|
86
|
+
cached=("${(@f)$(<"$cache")}")
|
|
87
|
+
if [[ "${cached[1]-}" == "$key" && ${#cached} -gt 1 ]]; then
|
|
88
|
+
_agent_launch_claude_verbs=("${(@)cached[2,-1]}")
|
|
89
|
+
_agent_launch_claude_verbs_key="$key"
|
|
90
|
+
return 0
|
|
91
|
+
fi
|
|
92
|
+
fi
|
|
93
|
+
py="$(\builtin whence -p python3)" || py=""
|
|
94
|
+
if [[ -n "$py" && "$OSTYPE" == darwin* && "${py:A}" == /usr/bin/python3 ]] \
|
|
95
|
+
&& ! builtin command xcode-select -p >/dev/null 2>&1; then
|
|
96
|
+
why="python3 is the Command Line Tools stub, which are not installed"
|
|
97
|
+
elif [[ -z "$py" ]]; then
|
|
98
|
+
why="no python3 is on PATH"
|
|
99
|
+
elif [[ ! -f "$_agent_launch_claude_lister" ]]; then
|
|
100
|
+
why="the subcommand lister is missing at $_agent_launch_claude_lister"
|
|
101
|
+
fi
|
|
102
|
+
if [[ -n "$why" ]]; then
|
|
103
|
+
_agent_launch_claude_unread "$why"
|
|
104
|
+
return 1
|
|
105
|
+
fi
|
|
106
|
+
listed="$("$py" -I "$_agent_launch_claude_lister" "$bin" </dev/null)" || return 1
|
|
107
|
+
words=("${(@f)listed}")
|
|
108
|
+
(( ${#words} )) || return 1
|
|
109
|
+
_agent_launch_claude_verbs=("${words[@]}")
|
|
110
|
+
_agent_launch_claude_verbs_key="$key"
|
|
111
|
+
if [[ -d "${cache:h}" && ( ! -e "$cache" || ( -f "$cache" && ! -L "$cache" ) ) ]]; then
|
|
112
|
+
builtin print -rl -- "$key" "${words[@]}" >| "$cache.$$" 2>/dev/null \
|
|
113
|
+
&& builtin command mv -f -- "$cache.$$" "$cache" 2>/dev/null \
|
|
114
|
+
|| builtin command rm -f -- "$cache.$$" 2>/dev/null
|
|
115
|
+
fi
|
|
116
|
+
return 0
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
# Whether $1 is a spelling `_agent_launch_claude_verbs` holds. A function of its own so the
|
|
120
|
+
# subscript is read under zsh's array options, not the user's: with KSH_ARRAYS set, `(Ie)` answers
|
|
121
|
+
# 0 for the first element, the same answer as "absent".
|
|
122
|
+
_agent_launch_claude_lists() {
|
|
123
|
+
setopt localoptions noksharrays no_err_return no_err_exit
|
|
124
|
+
(( ${_agent_launch_claude_verbs[(Ie)$1]} ))
|
|
125
|
+
}
|
|
126
|
+
|
|
36
127
|
_agent_launch_dispatch() {
|
|
37
128
|
local host="$1"
|
|
38
129
|
shift
|
|
@@ -108,7 +199,7 @@ _agent_launch_note_shadow() {
|
|
|
108
199
|
prog="${TERM_PROGRAM:-unknown}"
|
|
109
200
|
prog="${prog//[[:cntrl:]]/ }"
|
|
110
201
|
# `builtin command`: a shell function named `date` must not write this field.
|
|
111
|
-
stamp="$(builtin command date -u +%Y-%m-%dT%H:%M:%SZ 2>/dev/null)"
|
|
202
|
+
stamp="$(\builtin command date -u +%Y-%m-%dT%H:%M:%SZ 2>/dev/null)"
|
|
112
203
|
stamp="${stamp//[[:cntrl:]]/ }"
|
|
113
204
|
# `builtin printf`: a shell function named printf could report success and write nothing.
|
|
114
205
|
if builtin printf '%s\t%s\t%s\t%s\n' "${stamp:-<unknown>}" "$host" "$prog" \
|
|
@@ -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"
|
|
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.
|