diff --git a/.autoskillit/test-filter-manifest.yaml b/.autoskillit/test-filter-manifest.yaml index 79e8c1c729..1c15d243a3 100644 --- a/.autoskillit/test-filter-manifest.yaml +++ b/.autoskillit/test-filter-manifest.yaml @@ -214,6 +214,9 @@ tests/fixtures/codex/*.jsonl: tests/fixtures/codex/discovery_prompt_input_*.json: - execution/ +tests/fixtures/codex/discovery_prompt_input_*.md: + - execution/ + tests/fixtures/codex_hook_protocol/**/*.json: - hooks/ diff --git a/src/autoskillit/cli/fleet/_fleet_run.py b/src/autoskillit/cli/fleet/_fleet_run.py index 96123bdae9..d9f71b9aef 100644 --- a/src/autoskillit/cli/fleet/_fleet_run.py +++ b/src/autoskillit/cli/fleet/_fleet_run.py @@ -15,7 +15,7 @@ from cyclopts import Parameter -from autoskillit.cli.session._session_launch import render_skill_unavailability +from autoskillit.cli.session._session_onboarding import render_skill_unavailability from autoskillit.core import get_logger, is_feature_enabled if TYPE_CHECKING: diff --git a/src/autoskillit/cli/fleet/_fleet_session.py b/src/autoskillit/cli/fleet/_fleet_session.py index 08932a9865..b26f8b6b88 100644 --- a/src/autoskillit/cli/fleet/_fleet_session.py +++ b/src/autoskillit/cli/fleet/_fleet_session.py @@ -12,6 +12,7 @@ from autoskillit.core import ( CODEX_AUTO_COMPACTION_BLOCKED_MESSAGE, FLEET_SESSION_REQUIRED_ENV, + MANAGED_JOIN_PARENT_ID_ENV_VAR, CodingAgentBackend, FleetSessionEnv, FreshLaunch, @@ -65,20 +66,25 @@ def _fleet_session_launcher( managed_join_parent_id: str | None = None, ) -> Iterator[Callable[[InteractiveLaunch, dict[str, str]], Any]]: """Keep one leased wrapper home through a fleet session's retry loop.""" - from autoskillit.cli.session._session_launch import _run_interactive_session + from autoskillit.cli.session._session_launch import ( + InteractiveLaunchValidationError, + _run_interactive_session, + render_launch_validation_errors, + ) + + parent_env = ( + {MANAGED_JOIN_PARENT_ID_ENV_VAR: managed_join_parent_id} + if managed_join_parent_id is not None + else {} + ) def raw_launch( launch: InteractiveLaunch, extra_env: dict[str, str], ) -> Any: - launch_env = dict(extra_env) - if managed_join_parent_id is not None: - from autoskillit.core import MANAGED_JOIN_PARENT_ID_ENV_VAR - - launch_env[MANAGED_JOIN_PARENT_ID_ENV_VAR] = managed_join_parent_id return _run_interactive_session( launch=launch, - extra_env=launch_env, + extra_env={**extra_env, **parent_env}, project_dir=project_dir, required_env=FLEET_SESSION_REQUIRED_ENV, backend=backend, @@ -96,7 +102,6 @@ def raw_launch( from autoskillit.cli.session._session_startup_trace import StartupTrace from autoskillit.core import ( LAUNCH_ID_ENV_VAR, - MANAGED_JOIN_PARENT_ID_ENV_VAR, PluginLoadMode, plugin_launch_binding_scope, resolve_temp_dir, @@ -137,6 +142,7 @@ def raw_launch( launch_load_mode if launch_load_mode.consumes_artifact else PluginLoadMode.PROJECTED_HOME ) launch_id = uuid.uuid4().hex[:16] + launch_rejected = False with plugin_launch_binding_scope( authority=authority, backend=backend, @@ -172,9 +178,7 @@ def managed_launch( ) -> Any: nonlocal attempt attempt += 1 - launch_env = {**extra_env, LAUNCH_ID_ENV_VAR: launch_id} - if managed_join_parent_id is not None: - launch_env[MANAGED_JOIN_PARENT_ID_ENV_VAR] = managed_join_parent_id + launch_env = {**extra_env, LAUNCH_ID_ENV_VAR: launch_id, **parent_env} return _run_interactive_session( launch=launch, extra_env=launch_env, @@ -195,10 +199,17 @@ def managed_launch( try: yield managed_launch + except InteractiveLaunchValidationError as exc: + render_launch_validation_errors(exc.errors) + trace.close(status="failed") + launch_rejected = True except BaseException: trace.close(status="failed") raise - trace.close(status="success") + else: + trace.close(status="success") + if launch_rejected: + raise SystemExit(1) def _refresh_campaign_after_resume( @@ -329,7 +340,7 @@ def _launch_fleet_session( from autoskillit.cli.session._session_backend import ( resolve_global_backend, ) - from autoskillit.cli.session._session_launch import render_skill_unavailability + from autoskillit.cli.session._session_onboarding import render_skill_unavailability from autoskillit.config import load_config from autoskillit.workspace import ( compile_session_skill_catalog, diff --git a/src/autoskillit/cli/session/_session_cook.py b/src/autoskillit/cli/session/_session_cook.py index 81ec8f5526..4a11ae3eef 100644 --- a/src/autoskillit/cli/session/_session_cook.py +++ b/src/autoskillit/cli/session/_session_cook.py @@ -11,12 +11,17 @@ from typing import TYPE_CHECKING, assert_never from autoskillit.cli.session._session_launch import ( + InteractiveLaunchValidationError, _exit_launch_preparation_error, - append_skill_unavailability, prepare_interactive_launch, + render_launch_validation_errors, +) +from autoskillit.cli.session._session_onboarding import ( + append_skill_unavailability, render_skill_catalog_exclusions, render_skill_contract_composition_failure, render_skill_unavailability, + validate_cook_skill_visibility, ) from autoskillit.core import ( PluginLaunchBinding, @@ -466,9 +471,7 @@ def _execute_cook_attempt( assert_resume_purity(spec=spec, launch=launch) validation = backend.validate_interactive_invocation(spec) if validation.errors: - raise RuntimeError( - "Interactive invocation validation failed: " + "; ".join(validation.errors) - ) + raise InteractiveLaunchValidationError(validation.errors) with backend.session_attempt_context( session_home=managed_home.generated_home, project_dir=project_dir, @@ -605,7 +608,6 @@ def cook( compile_session_skill_catalog, resolve_ephemeral_root, resolve_persistent_session_roots, - validate_skill_tier_roles, ) config = load_config() @@ -614,11 +616,7 @@ def cook( project_dir = resolve_project_dir() skill_resolver = DefaultSkillResolver() skill_visibility = config.skill_visibility_spec() - try: - validate_skill_tier_roles(skill_visibility, skill_resolver, project_dir) - except SkillContractError as exc: - render_skill_contract_composition_failure(exc) - raise SystemExit(1) from exc + validate_cook_skill_visibility(skill_visibility, skill_resolver, project_dir) backend = _resolve_cook_backend(config, backend) cook_system_prompt = ( _COOK_PRE_REVEALED_KITCHEN_PROMPT @@ -718,6 +716,7 @@ def cook( projection_load_mode = ( load_mode if load_mode.consumes_artifact else PluginLoadMode.PROJECTED_HOME ) + launch_rejected = False with ( plugin_launch_binding_scope( authority=artifact_authority, @@ -763,21 +762,27 @@ def cook( cook_env_extras = _build_cook_attempt_env( launch_id, profile, config, managed_join_context ) - _run_managed_cook( - backend=backend, - project_dir=project_dir, - launch=launch, - launch_id=launch_id, - config=config, - cook_env_extras=cook_env_extras, - managed_home=managed_home, - projection_binding=projection_binding, - load_mode=load_mode, - trace=trace, - trace_enabled=trace_enabled, - force_inactive_agent_teams=force_inactive_agent_teams, - showed_onboarding=showed_onboarding, - ) + try: + _run_managed_cook( + backend=backend, + project_dir=project_dir, + launch=launch, + launch_id=launch_id, + config=config, + cook_env_extras=cook_env_extras, + managed_home=managed_home, + projection_binding=projection_binding, + load_mode=load_mode, + trace=trace, + trace_enabled=trace_enabled, + force_inactive_agent_teams=force_inactive_agent_teams, + showed_onboarding=showed_onboarding, + ) + except InteractiveLaunchValidationError as exc: + render_launch_validation_errors(exc.errors) + launch_rejected = True + if launch_rejected: + raise SystemExit(1) finally: if claimed_launch_id is not None: core.release_session_claim(project_dir, claimed_launch_id) diff --git a/src/autoskillit/cli/session/_session_launch.py b/src/autoskillit/cli/session/_session_launch.py index 90ad167902..2b07d8e026 100644 --- a/src/autoskillit/cli/session/_session_launch.py +++ b/src/autoskillit/cli/session/_session_launch.py @@ -2,16 +2,19 @@ from __future__ import annotations -import json import os import subprocess import sys from collections.abc import Callable, Mapping, Sequence from dataclasses import dataclass, replace from pathlib import Path -from typing import TYPE_CHECKING, NoReturn, assert_never, overload +from typing import TYPE_CHECKING, NoReturn, assert_never from autoskillit.cli.session._session_backend import verify_launch_home +from autoskillit.cli.session._session_onboarding import ( + append_skill_unavailability, + render_skill_unavailability, +) from autoskillit.core import ( AUTOSKILLIT_STATE_ROOT_ENV_VAR, CODEX_AUTO_COMPACTION_BLOCKED_MESSAGE, @@ -24,7 +27,6 @@ RestoreSession, ResumeWithBriefing, SessionHookRoot, - SkillContractError, TerminationReason, executable_binding_matches_current_file, get_logger, @@ -45,88 +47,15 @@ PluginLaunchBinding, ResumeSpec, SemanticAdaptationContext, - SkillUnavailabilityPayload, ValidatedAddDir, ) from autoskillit.workspace import ( CompiledSessionSkillCatalog, - SkillExclusion, ) logger = get_logger(__name__) -def render_skill_contract_composition_failure(exc: SkillContractError) -> None: - """Print a clean, actionable message for a composition-root contract failure. - - No traceback. The underlying message is already actionable (file path, - invalidity kind's hint, and — for the tier-role gate — an embedded - doctor pointer) after resolution-boundary containment; this guarantees - the doctor pointer is present for every SkillContractError shape, not - only the ones that already embed it. - """ - print(f"ERROR: {exc}") - print("Run: autoskillit doctor") - - -def render_skill_catalog_exclusions(exclusions: tuple[SkillExclusion, ...]) -> None: - """Print one operator-visible warning line per excluded skill candidate.""" - for exclusion in exclusions: - hint = "; ".join(exclusion.hints) - print(f"WARNING: excluded project-local skill {exclusion.name!r} at {exclusion.path}") - if hint: - print(f" hint: {hint}") - - -def render_skill_unavailability( - unavailability_payload: SkillUnavailabilityPayload, -) -> None: - """Print backend exclusions grouped by operation and diagnostic.""" - grouped: dict[tuple[str, str], list[str]] = {} - for item in unavailability_payload["unavailable"]: - grouped.setdefault((item["operation"], item["diagnostic"]), []).append(item["skill"]) - for (operation, diagnostic), skill_names in sorted(grouped.items()): - names = ", ".join(sorted(skill_names)) - print( - f"{len(skill_names)} skills unavailable on this backend " - f"({operation}: {diagnostic}): {names}" - ) - - -@overload -def append_skill_unavailability( - system_prompt: None, - unavailability_payload: SkillUnavailabilityPayload, -) -> None: ... - - -@overload -def append_skill_unavailability( - system_prompt: str, - unavailability_payload: SkillUnavailabilityPayload, -) -> str: ... - - -def append_skill_unavailability( - system_prompt: str | None, - unavailability_payload: SkillUnavailabilityPayload, -) -> str | None: - """Append the canonical machine-readable refusal payload to a prompt.""" - if system_prompt is None or not unavailability_payload["unavailable"]: - return system_prompt - unavailable_json = json.dumps( - unavailability_payload, - sort_keys=True, - separators=(",", ":"), - ) - block = ( - f"{unavailable_json}" - ) - if block in system_prompt: - return system_prompt - return f"{system_prompt.rstrip()}\n\n{block}" - - @dataclass(frozen=True, slots=True) class _InfraExitSignal: session_id: str @@ -142,6 +71,14 @@ class PreparedInteractiveLaunch: pre_spawn_check: Callable[[], None] | None = None +class InteractiveLaunchValidationError(Exception): + """Carry expected validation diagnostics to the managed resource owner.""" + + def __init__(self, errors: Sequence[str]) -> None: + self.errors = tuple(errors) + super().__init__("; ".join(self.errors)) + + def _interactive_anchor_env( extra_env: Mapping[str, str] | None, project_dir: Path ) -> dict[str, str]: @@ -318,6 +255,8 @@ def _finalize_interactive_launch( assert_resume_purity(spec=spec, launch=launch) validation = backend.validate_interactive_invocation(spec) if validation.errors: + if managed_home is not None: + raise InteractiveLaunchValidationError(validation.errors) _exit_launch_validation_errors(validation.errors) return PreparedInteractiveLaunch( @@ -333,9 +272,15 @@ def _exit_launch_preparation_error(exc: ValueError) -> NoReturn: raise SystemExit(1) -def _exit_launch_validation_errors(errors: Sequence[str]) -> NoReturn: +def render_launch_validation_errors(errors: Sequence[str]) -> None: + """Render one ERROR line per diagnostic, joining embedded line breaks with '; '.""" for error in errors: - sys.stderr.write(f"ERROR: {error}\n") + normalized = "; ".join(error.splitlines()) + sys.stderr.write(f"ERROR: {normalized}\n") + + +def _exit_launch_validation_errors(errors: Sequence[str]) -> NoReturn: + render_launch_validation_errors(errors) raise SystemExit(1) @@ -764,6 +709,7 @@ def _launch_cook_session( projection_load_mode = ( launch_load_mode if launch_load_mode.consumes_artifact else PluginLoadMode.PROJECTED_HOME ) + launch_rejected = False with plugin_launch_binding_scope( authority=artifact_authority, backend=backend, @@ -821,7 +767,14 @@ def _launch_cook_session( mcp_tool_timeout_sec=mcp_tool_timeout_sec, process_tether=process_tether, ) + except InteractiveLaunchValidationError as exc: + render_launch_validation_errors(exc.errors) + trace.close(status="failed") + launch_rejected = True except BaseException: trace.close(status="failed") raise - trace.close(status="success") + else: + trace.close(status="success") + if launch_rejected: + raise SystemExit(1) diff --git a/src/autoskillit/cli/session/_session_onboarding.py b/src/autoskillit/cli/session/_session_onboarding.py index 4e9264bad8..4de3619477 100644 --- a/src/autoskillit/cli/session/_session_onboarding.py +++ b/src/autoskillit/cli/session/_session_onboarding.py @@ -1,14 +1,104 @@ -"""First-run detection and guided onboarding menu for cook sessions.""" +"""Session skill guidance and first-run onboarding for cook sessions.""" from __future__ import annotations +import json from pathlib import Path +from typing import TYPE_CHECKING, overload -from autoskillit.core import get_logger +from autoskillit.core import SkillContractError, get_logger + +if TYPE_CHECKING: + from autoskillit.core import SkillResolver, SkillUnavailabilityPayload, SkillVisibilitySpec + from autoskillit.workspace import SkillExclusion logger = get_logger(__name__) +def render_skill_contract_composition_failure(exc: SkillContractError) -> None: + """Print a clean, actionable message for a composition-root contract failure. + + No traceback. The underlying message is already actionable (file path, + invalidity kind's hint, and — for the tier-role gate — an embedded + doctor pointer) after resolution-boundary containment; this guarantees + the doctor pointer is present for every SkillContractError shape, not + only the ones that already embed it. + """ + print(f"ERROR: {exc}") + print("Run: autoskillit doctor") + + +def render_skill_catalog_exclusions(exclusions: tuple[SkillExclusion, ...]) -> None: + """Print one operator-visible warning line per excluded skill candidate.""" + for exclusion in exclusions: + hint = "; ".join(exclusion.hints) + print(f"WARNING: excluded project-local skill {exclusion.name!r} at {exclusion.path}") + if hint: + print(f" hint: {hint}") + + +def render_skill_unavailability( + unavailability_payload: SkillUnavailabilityPayload, +) -> None: + """Print backend exclusions grouped by operation and diagnostic.""" + grouped: dict[tuple[str, str], list[str]] = {} + for item in unavailability_payload["unavailable"]: + grouped.setdefault((item["operation"], item["diagnostic"]), []).append(item["skill"]) + for (operation, diagnostic), skill_names in sorted(grouped.items()): + names = ", ".join(sorted(skill_names)) + print( + f"{len(skill_names)} skills unavailable on this backend " + f"({operation}: {diagnostic}): {names}" + ) + + +@overload +def append_skill_unavailability( + system_prompt: None, + unavailability_payload: SkillUnavailabilityPayload, +) -> None: ... + + +@overload +def append_skill_unavailability( + system_prompt: str, + unavailability_payload: SkillUnavailabilityPayload, +) -> str: ... + + +def append_skill_unavailability( + system_prompt: str | None, + unavailability_payload: SkillUnavailabilityPayload, +) -> str | None: + """Append the canonical machine-readable refusal payload to a prompt.""" + if system_prompt is None or not unavailability_payload["unavailable"]: + return system_prompt + unavailable_json = json.dumps( + unavailability_payload, + sort_keys=True, + separators=(",", ":"), + ) + block = ( + f"{unavailable_json}" + ) + if block in system_prompt: + return system_prompt + return f"{system_prompt.rstrip()}\n\n{block}" + + +def validate_cook_skill_visibility( + visibility: SkillVisibilitySpec, resolver: SkillResolver, project_dir: Path +) -> None: + """Render invalid skill-tier roles before cook starts launch setup.""" + from autoskillit.workspace import validate_skill_tier_roles + + try: + validate_skill_tier_roles(visibility, resolver, project_dir) + except SkillContractError as exc: + render_skill_contract_composition_failure(exc) + raise SystemExit(1) from exc + + def is_first_run(project_dir: Path) -> bool: """Return True when the project is initialized but has never been onboarded.""" if not (project_dir / ".autoskillit" / "config.yaml").exists(): diff --git a/src/autoskillit/cli/session/_session_order.py b/src/autoskillit/cli/session/_session_order.py index dbfa44cd9a..7bc1f9a01e 100644 --- a/src/autoskillit/cli/session/_session_order.py +++ b/src/autoskillit/cli/session/_session_order.py @@ -20,6 +20,8 @@ _launch_cook_session, _order_launch_env, _write_order_entry, +) +from autoskillit.cli.session._session_onboarding import ( render_skill_catalog_exclusions, render_skill_contract_composition_failure, ) diff --git a/src/autoskillit/execution/backends/_codex_discovery.py b/src/autoskillit/execution/backends/_codex_discovery.py index 8863a201dd..29f946f733 100644 --- a/src/autoskillit/execution/backends/_codex_discovery.py +++ b/src/autoskillit/execution/backends/_codex_discovery.py @@ -114,6 +114,8 @@ def _skills_instruction_text(document: Any) -> str: for item in document: if not isinstance(item, dict): raise ValueError("Codex prompt-input JSON contains a malformed response item") + if item.get("type") != "message" or item.get("role") != "developer": + continue content = item.get("content") if not isinstance(content, list): raise ValueError("Codex prompt-input response item has malformed content") @@ -121,9 +123,12 @@ def _skills_instruction_text(document: Any) -> str: if not isinstance(part, dict): raise ValueError("Codex prompt-input content contains a malformed item") text = part.get("text") - if part.get("type") == "input_text" and isinstance(text, str): - if item.get("role") == "developer" and text.startswith(""): - candidates.append(text) + if ( + part.get("type") == "input_text" + and isinstance(text, str) + and text.startswith("") + ): + candidates.append(text) if len(candidates) != 1: raise ValueError("Codex prompt-input must contain exactly one block") return candidates[0] diff --git a/src/autoskillit/execution/backends/_codex_discovery_attestation.py b/src/autoskillit/execution/backends/_codex_discovery_attestation.py index bb8a0656a7..dff3b8557c 100644 --- a/src/autoskillit/execution/backends/_codex_discovery_attestation.py +++ b/src/autoskillit/execution/backends/_codex_discovery_attestation.py @@ -71,7 +71,10 @@ def _prompt_input_errors( try: discovered = discovery.parse_skills_instructions(result.stdout.decode("utf-8")) except (UnicodeDecodeError, ValueError) as exc: - return [f"Codex skill discovery parse failed: {exc}; {context}"] + return [ + f"Codex skill discovery parse failed: {exc}; {context}; " + "Update AutoSkillit to a build supporting this discovery output and retry." + ] return discovery._catalog_discovery_errors( discovered, expected_paths, diff --git a/tests/arch/test_no_adhoc_env_workarounds.py b/tests/arch/test_no_adhoc_env_workarounds.py index 6f3a2e3afc..7756e0ef82 100644 --- a/tests/arch/test_no_adhoc_env_workarounds.py +++ b/tests/arch/test_no_adhoc_env_workarounds.py @@ -72,7 +72,7 @@ "tests/arch/test_mcp_env_forward_coverage.py::AUTOSKILLIT_MCP_CLIENT_BACKEND", "tests/arch/test_skill_capability_registry.py::AUTOSKILLIT_FOOD_TRUCK_TOOL_TAGS", "tests/arch/test_skill_capability_registry.py::AUTOSKILLIT_HEADLESS_AUTO_GATE", - "tests/cli/_cook_launch_helpers.py::AUTOSKILLIT_CODEX_STARTUP_TRACE", + "tests/cli/_managed_launch_helpers.py::AUTOSKILLIT_CODEX_STARTUP_TRACE", "tests/cli/test_doctor.py::AUTOSKILLIT_CAMPAIGN_ID", "tests/cli/test_doctor_backend_guards.py::AUTOSKILLIT_AGENT_BACKEND", "tests/cli/test_doctor_backend_guards.py::AUTOSKILLIT_AGENT_BACKEND__BACKEND", diff --git a/tests/cli/_cook_launch_helpers.py b/tests/cli/_managed_launch_helpers.py similarity index 90% rename from tests/cli/_cook_launch_helpers.py rename to tests/cli/_managed_launch_helpers.py index 56245c4cfa..5e83601ea7 100644 --- a/tests/cli/_cook_launch_helpers.py +++ b/tests/cli/_managed_launch_helpers.py @@ -1,14 +1,16 @@ -"""Hermetic harness for real-backend cook launch tests.""" +"""Hermetic managed-launch helpers for cook, order, and fleet tests.""" from __future__ import annotations import json -from collections.abc import Iterable, Iterator +from collections.abc import Iterable, Iterator, Mapping from contextlib import contextmanager from pathlib import Path from types import SimpleNamespace from unittest.mock import MagicMock +import pytest + import autoskillit.cli.install._plugin_artifact as _patch_install__plugin_artifact import autoskillit.cli.session._session_cook as _patch_session__session_cook import autoskillit.cli.session._session_onboarding as _patch_session__session_onboarding @@ -229,6 +231,37 @@ def acquire_launch_binding(self, **_kwargs: object) -> _Binding: return _Binding(self.plugin_dir) +def record_cook_rejection( + monkeypatch: pytest.MonkeyPatch, +) -> tuple[list[str], list[tuple[str, ...]]]: + """Record cook rejection diagnostics and trace status while retaining real effects.""" + from autoskillit.cli.session._session_startup_trace import StartupTrace + + close_statuses: list[str] = [] + rendered_errors: list[tuple[str, ...]] = [] + real_close = StartupTrace.close + real_renderer = _patch_session__session_cook.render_launch_validation_errors + + def record_close( + trace: StartupTrace, + *, + status: str, + diagnostics: Mapping[str, object] | None = None, + ) -> None: + close_statuses.append(status) + real_close(trace, status=status, diagnostics=diagnostics) + + def record_renderer(errors: tuple[str, ...]) -> None: + rendered_errors.append(errors) + real_renderer(errors) + + monkeypatch.setattr(StartupTrace, "close", record_close) + monkeypatch.setattr( + _patch_session__session_cook, "render_launch_validation_errors", record_renderer + ) + return close_statuses, rendered_errors + + def arrange_cook( monkeypatch, tmp_path: Path, diff --git a/tests/cli/test_cook_attempt_exit_status.py b/tests/cli/test_cook_attempt_exit_status.py index 841da7b708..3cd01eaa0c 100644 --- a/tests/cli/test_cook_attempt_exit_status.py +++ b/tests/cli/test_cook_attempt_exit_status.py @@ -19,7 +19,7 @@ from autoskillit.config import AutomationConfig, ProcessTetherConfig from autoskillit.core import FreshLaunch, PluginLoadMode from autoskillit.core.types import TerminationReason -from tests.cli._cook_launch_helpers import cook_attempt_result +from tests.cli._managed_launch_helpers import cook_attempt_result pytestmark = [pytest.mark.layer("cli"), pytest.mark.small] diff --git a/tests/cli/test_cook_cold_launch_medium.py b/tests/cli/test_cook_cold_launch_medium.py index b26b786b68..d57852136f 100644 --- a/tests/cli/test_cook_cold_launch_medium.py +++ b/tests/cli/test_cook_cold_launch_medium.py @@ -20,7 +20,7 @@ ) from autoskillit.execution.backends import ClaudeCodeBackend, CodexBackend from tests._realistic_project import PINNED_CLAUDE_SHIM_VERSION_OUTPUT -from tests.cli._cook_launch_helpers import arrange_cook +from tests.cli._managed_launch_helpers import arrange_cook pytestmark = [pytest.mark.layer("cli"), pytest.mark.medium] diff --git a/tests/cli/test_cook_env_scrub.py b/tests/cli/test_cook_env_scrub.py index 3d5fa59f08..47a2f0ef60 100644 --- a/tests/cli/test_cook_env_scrub.py +++ b/tests/cli/test_cook_env_scrub.py @@ -22,8 +22,8 @@ import autoskillit.cli.ui._timed_input as _patch_ui__timed_input from autoskillit.core import CmdSpec, FreshLaunch, ManagedSessionHome, ValidatedAddDir from autoskillit.execution.backends._backend_cmd_builder_base import SHARED_BASELINE_ENV -from tests.cli._cook_launch_helpers import cook_attempt_result from tests.cli._interactive_process import InteractiveProcessStub +from tests.cli._managed_launch_helpers import cook_attempt_result pytestmark = [ pytest.mark.layer("cli"), diff --git a/tests/cli/test_cook_interactive.py b/tests/cli/test_cook_interactive.py index 651a04ac5c..6977837ec9 100644 --- a/tests/cli/test_cook_interactive.py +++ b/tests/cli/test_cook_interactive.py @@ -30,6 +30,7 @@ SESSION_TYPE_ENV_VAR, BackendConventions, CmdSpec, + CodingAgentBackend, CompiledSessionSkillCatalogAuthority, FreshLaunch, HookTrustPolicy, @@ -50,8 +51,8 @@ hook_is_launched_interactive, ) from tests._realistic_project import PINNED_CLAUDE_SHIM_VERSION_OUTPUT -from tests.cli._cook_launch_helpers import cook_attempt_result from tests.cli._interactive_process import interactive_launch_metadata +from tests.cli._managed_launch_helpers import cook_attempt_result, record_cook_rejection from tests.execution.backends._codex_fixtures import installed_catalog from tests.fakes import adapt_test_skill_semantics from tests.fixtures.hook_topology import fake_projected_plugin_root @@ -402,6 +403,7 @@ def interactive_ordering_flags(self) -> tuple[frozenset[str], frozenset[str]]: def test_cook_aborts_before_spawn_when_skill_discovery_fails( monkeypatch: pytest.MonkeyPatch, tmp_path: Path, + capsys: pytest.CaptureFixture[str], ) -> None: """Discovery diagnostics must reject the managed launch before the child starts.""" diagnostic = "Codex skill discovery is missing managed names ['expected-skill']" @@ -417,9 +419,11 @@ def validate_interactive_invocation( backend = _DiscoveryFailureBackend() captured = _install_harness(monkeypatch, tmp_path) - with pytest.raises(RuntimeError, match="Codex skill discovery is missing managed names"): + with pytest.raises(SystemExit) as caught: cli.cook(backend=backend) + assert caught.value.code == 1 + assert capsys.readouterr().err == f"ERROR: {diagnostic}\n" events = captured["events"] assert isinstance(events, list) event_names = [event[0] for event in events] @@ -427,6 +431,221 @@ def validate_interactive_invocation( assert event_names[-1] == "managed-exit" +class _ManagedCleanupFailure(Exception): + pass + + +def _install_real_codex_rejection_harness( + monkeypatch: pytest.MonkeyPatch, + tmp_path: Path, +) -> tuple[CodingAgentBackend, list[_CookBinding], list[str], list[str], list[tuple[str, ...]]]: + from autoskillit.cli.install._installed_plugins import InstalledPluginsFile + from autoskillit.core import PluginLoadMode + from autoskillit.execution.backends.codex import CodexBackend + + project_root = tmp_path / "project" + project_root.mkdir() + source_home = tmp_path / "home" / ".codex" + source_home.mkdir(parents=True) + (source_home / "config.toml").write_text( + 'cli_auth_credentials_store = "keyring"\n', encoding="utf-8" + ) + backend = CodexBackend(source_codex_home=source_home) + + bundled_catalog = tmp_path / "bundled-models.json" + atomic_write(bundled_catalog, json.dumps(installed_catalog())) + codex_shim = tmp_path / "codex" + atomic_write( + codex_shim, + "#!/usr/bin/env python3\n" + "import pathlib\n" + "import sys\n" + "if sys.argv[1:] != ['debug', 'models', '--bundled']:\n" + " raise SystemExit(64)\n" + f"sys.stdout.buffer.write(pathlib.Path({str(bundled_catalog)!r}).read_bytes())\n", + ) + codex_shim.chmod(0o755) + + plugin_dir = fake_projected_plugin_root(tmp_path, "rejection-artifact") + plugin_metadata = plugin_dir / ".claude-plugin" / "plugin.json" + plugin_metadata.parent.mkdir() + plugin_metadata.write_text("{}\n", encoding="utf-8") + bindings: list[_CookBinding] = [] + + class _TrackingAuthority(_CookAuthority): + def acquire_launch_binding(self, **_kwargs: object) -> _CookBinding: + binding = _CookBinding(self.plugin_dir) + bindings.append(binding) + return binding + + close_statuses, rendered_errors = record_cook_rejection(monkeypatch) + released_claims: list[str] = [] + + real_which = shutil.which + + def which(executable: str, **kwargs: object) -> str | None: + if executable == backend.binary_name(): + return str(codex_shim) + return real_which(executable, **kwargs) + + monkeypatch.chdir(project_root) + monkeypatch.setattr(shutil, "which", which) + monkeypatch.setattr("sys.stdin.isatty", lambda: True) + monkeypatch.setattr(InstalledPluginsFile, "contains", lambda self, key: False) + monkeypatch.setattr(_patch_session__session_onboarding, "is_first_run", lambda _project: False) + monkeypatch.setattr(_patch_ui__timed_input, "timed_prompt", lambda *args, **kwargs: "") + monkeypatch.setattr( + "autoskillit.core.release_session_claim", + lambda _project, launch_id: released_claims.append(launch_id), + ) + monkeypatch.setattr( + _patch_install__plugin_artifact, + "interactive_plugin_authority", + lambda **_kwargs: (_TrackingAuthority(plugin_dir), PluginLoadMode.GENERATED_HOME), + ) + monkeypatch.setattr( + _patch_session__session_process, + "run_cook_attempt", + lambda *args, **kwargs: pytest.fail("rejected launch must not spawn"), + ) + monkeypatch.setattr( + _patch_session__session_reload, + "consume_reload_sentinel", + lambda _project: pytest.fail("rejected launch must not inspect reload state"), + ) + monkeypatch.setattr( + _patch_session__session_onboarding, + "mark_onboarded", + lambda _project: pytest.fail("rejected launch must not complete onboarding"), + ) + monkeypatch.setattr( + "autoskillit.execution.backends._codex_probes._validate_mcp_probe", + lambda *_args, **_kwargs: [], + ) + + return backend, bindings, close_statuses, released_claims, rendered_errors + + +@pytest.mark.parametrize("cleanup_fails", [False, True], ids=["cleanup-succeeds", "cleanup-fails"]) +def test_real_managed_codex_validation_rejection_renders_before_cleanup( + monkeypatch: pytest.MonkeyPatch, + tmp_path: Path, + capsys: pytest.CaptureFixture[str], + caplog: pytest.LogCaptureFixture, + cleanup_fails: bool, +) -> None: + import autoskillit.workspace.session_skills._manager as session_skill_manager + from autoskillit.execution.backends.codex import CodexBackend + + diagnostic = "Codex skill discovery is missing managed names ['expected-skill']" + backend, bindings, close_statuses, released_claims, rendered_errors = ( + _install_real_codex_rejection_harness(monkeypatch, tmp_path) + ) + registered_claims: list[str] = [] + monkeypatch.setattr( + "autoskillit.core.write_registry_entry", + lambda _project, launch_id, *_args: registered_claims.append(launch_id), + ) + generated_home: Path | None = None + validation_count = 0 + + def reject(_self: CodexBackend, spec: CmdSpec) -> InteractiveInvocationValidation: + nonlocal generated_home, validation_count + validation_count += 1 + generated_home = Path(spec.env["CODEX_HOME"]) + assert generated_home.is_dir() + return InteractiveInvocationValidation(errors=(diagnostic,)) + + monkeypatch.setattr(CodexBackend, "validate_interactive_invocation", reject) + if cleanup_fails: + real_remove = session_skill_manager._remove_and_verify + + def fail_cleanup(path: Path) -> bool: + if generated_home is not None and path == generated_home: + raise _ManagedCleanupFailure("controlled cleanup failure") + return real_remove(path) + + monkeypatch.setattr(session_skill_manager, "_remove_and_verify", fail_cleanup) + + expected_exception = _ManagedCleanupFailure if cleanup_fails else SystemExit + with pytest.raises(expected_exception) as caught: + cli.cook(backend=backend) + + if not cleanup_fails: + assert isinstance(caught.value, SystemExit) + assert caught.value.code == 1 + assert generated_home is not None and not generated_home.exists() + else: + assert generated_home is not None and generated_home.exists() + assert str(caught.value) == "controlled cleanup failure" + stderr = capsys.readouterr().err + assert stderr.startswith(f"ERROR: {diagnostic}\n") + assert stderr.count(f"ERROR: {diagnostic}\n") == 1 + if not cleanup_fails: + assert stderr == f"ERROR: {diagnostic}\n" + assert validation_count == 1 + assert rendered_errors == [(diagnostic,)] + assert close_statuses == ["failed"] + assert all(binding.closed for binding in bindings) + assert len(registered_claims) == 1 + assert released_claims == registered_claims + assert not any( + "managed_session_body_failed" in record.getMessage() for record in caplog.records + ) + + +def test_reload_validation_rejection_does_not_start_a_second_attempt( + monkeypatch: pytest.MonkeyPatch, + tmp_path: Path, + capsys: pytest.CaptureFixture[str], +) -> None: + + diagnostic = "reloaded launch catalog changed" + + class _ReloadThenRejectBackend(_Backend): + def __init__(self) -> None: + super().__init__() + self.validation_count = 0 + + def validate_interactive_invocation( + self, spec: CmdSpec + ) -> InteractiveInvocationValidation: + self.validated.append(spec) + self.validation_count += 1 + errors = () if self.validation_count == 1 else (diagnostic,) + return InteractiveInvocationValidation(errors=errors) + + backend = _ReloadThenRejectBackend() + captured = _install_harness(monkeypatch, tmp_path) + close_statuses, rendered_errors = record_cook_rejection(monkeypatch) + reload_calls = 0 + + def consume_reload(_project: Path) -> str: + nonlocal reload_calls + reload_calls += 1 + assert reload_calls == 1 + return "fedcba9876543210" + + monkeypatch.setattr(_patch_session__session_reload, "consume_reload_sentinel", consume_reload) + + with pytest.raises(SystemExit) as caught: + cli.cook(backend=backend) + + assert caught.value.code == 1 + assert capsys.readouterr().err == f"ERROR: {diagnostic}\n" + events = captured["events"] + assert isinstance(events, list) + assert [event[0] for event in events].count("run") == 1 + assert "onboarded" not in [event[0] for event in events] + assert [event[0] for event in events][-1] == "managed-exit" + assert backend.validation_count == 2 + assert reload_calls == 1 + assert rendered_errors == [(diagnostic,)] + assert close_statuses == ["failed"] + launch_id = next(event[1] for event in events if event[0] == "managed-enter") + assert captured["releases"] == [launch_id] + + def test_codex_cook_admits_compose_pr_roles_from_exact_bundled_catalog_probe( monkeypatch: pytest.MonkeyPatch, tmp_path: Path, diff --git a/tests/cli/test_cook_lifetime.py b/tests/cli/test_cook_lifetime.py index ced81cfe6e..2ead9b28c5 100644 --- a/tests/cli/test_cook_lifetime.py +++ b/tests/cli/test_cook_lifetime.py @@ -16,7 +16,7 @@ from autoskillit.config import ProcessTetherConfig from autoskillit.core import InFlightOperations, TerminationReason, operation_lease from autoskillit.execution.process._process_tether import TetherRecord, write_tether -from tests.cli._cook_launch_helpers import lifetime_policy +from tests.cli._managed_launch_helpers import lifetime_policy pytestmark = [pytest.mark.layer("cli"), pytest.mark.small] diff --git a/tests/cli/test_cook_lifetime_authority.py b/tests/cli/test_cook_lifetime_authority.py index 5c906ca050..ede5db2bcc 100644 --- a/tests/cli/test_cook_lifetime_authority.py +++ b/tests/cli/test_cook_lifetime_authority.py @@ -25,7 +25,7 @@ import autoskillit.workspace as _patch_workspace from autoskillit.config import AutomationConfig, ProcessTetherConfig from autoskillit.core import FreshLaunch, PluginLoadMode -from tests.cli._cook_launch_helpers import arrange_cook, cook_attempt_result +from tests.cli._managed_launch_helpers import arrange_cook, cook_attempt_result pytestmark = [pytest.mark.layer("cli"), pytest.mark.medium] diff --git a/tests/cli/test_cook_order_command.py b/tests/cli/test_cook_order_command.py index 21984b18f3..86d5376247 100644 --- a/tests/cli/test_cook_order_command.py +++ b/tests/cli/test_cook_order_command.py @@ -21,8 +21,8 @@ from autoskillit import cli from autoskillit.config import LoggingConfig, ProcessTetherConfig from autoskillit.core import ClaudeFlags, InteractiveInvocationValidation, PreLaunchReadiness -from tests.cli._cook_launch_helpers import cook_attempt_result from tests.cli._interactive_process import InteractiveProcessStub, configure_popen +from tests.cli._managed_launch_helpers import cook_attempt_result from tests.cli.conftest import _SCRIPT_YAML pytestmark = [ diff --git a/tests/cli/test_cook_process_lifecycle.py b/tests/cli/test_cook_process_lifecycle.py index 6e6cfb0ee3..a93b62de62 100644 --- a/tests/cli/test_cook_process_lifecycle.py +++ b/tests/cli/test_cook_process_lifecycle.py @@ -18,7 +18,7 @@ from autoskillit.cli.session.pty._observer import PtyObserver from autoskillit.config import ProcessTetherConfig from autoskillit.core import CmdSpec, TerminationReason, ValidatedAddDir -from tests.cli._cook_launch_helpers import lifetime_policy +from tests.cli._managed_launch_helpers import lifetime_policy from tests.conftest import production_interpreter_env pytestmark = [pytest.mark.layer("cli"), pytest.mark.medium] diff --git a/tests/cli/test_cook_profile.py b/tests/cli/test_cook_profile.py index 238be8f88b..5b1aea775b 100644 --- a/tests/cli/test_cook_profile.py +++ b/tests/cli/test_cook_profile.py @@ -46,8 +46,8 @@ SkillUnavailableMetadata, ) from autoskillit.workspace.skills import _skill_info_from_frontmatter -from tests.cli._cook_launch_helpers import cook_attempt_result from tests.cli._interactive_process import interactive_launch_metadata +from tests.cli._managed_launch_helpers import cook_attempt_result from tests.fakes import adapt_test_skill_semantics pytestmark = [pytest.mark.layer("cli"), pytest.mark.medium] diff --git a/tests/cli/test_cook_real_root_smoke.py b/tests/cli/test_cook_real_root_smoke.py index aa2234b69b..80fa244528 100644 --- a/tests/cli/test_cook_real_root_smoke.py +++ b/tests/cli/test_cook_real_root_smoke.py @@ -38,7 +38,7 @@ from autoskillit.config import AutomationConfig from autoskillit.core import CmdSpec from autoskillit.execution.backends import ClaudeCodeBackend -from tests.cli._cook_launch_helpers import arrange_cook +from tests.cli._managed_launch_helpers import arrange_cook pytestmark = [pytest.mark.layer("cli"), pytest.mark.large, pytest.mark.smoke] diff --git a/tests/cli/test_cook_settings_local_agent_teams.py b/tests/cli/test_cook_settings_local_agent_teams.py index 2f634b7b30..e623e6b211 100644 --- a/tests/cli/test_cook_settings_local_agent_teams.py +++ b/tests/cli/test_cook_settings_local_agent_teams.py @@ -33,7 +33,7 @@ from autoskillit.core import atomic_write from autoskillit.execution.backends import ClaudeCodeBackend from tests._realistic_project import PINNED_CLAUDE_SHIM_VERSION_OUTPUT -from tests.cli._cook_launch_helpers import arrange_cook +from tests.cli._managed_launch_helpers import arrange_cook pytestmark = [pytest.mark.layer("cli"), pytest.mark.medium] diff --git a/tests/cli/test_fleet_session.py b/tests/cli/test_fleet_session.py index 96ff74b33f..fb25cf26cf 100644 --- a/tests/cli/test_fleet_session.py +++ b/tests/cli/test_fleet_session.py @@ -9,10 +9,13 @@ import pytest +import autoskillit.cli.install._plugin_artifact as _patch_install__plugin_artifact import autoskillit.cli.prompts as _patch_cli_prompts import autoskillit.cli.session._session_launch as _patch_session__session_launch +import autoskillit.cli.session._session_startup_trace as _patch_session__startup_trace from autoskillit.config import ProcessTetherConfig from autoskillit.fleet.campaign_state.state_records import ResumeDecision +from tests.cli._managed_launch_helpers import RecordingLifecycle pytestmark = [pytest.mark.layer("cli"), pytest.mark.small, pytest.mark.feature("fleet")] @@ -147,6 +150,129 @@ def capture_session(*_args: object, **kwargs: object) -> None: assert extra_env[MANAGED_JOIN_PARENT_ID_ENV_VAR] == "managed-join-id" +def test_managed_fleet_validation_rejection_cleans_up_before_exit( + monkeypatch: pytest.MonkeyPatch, + tmp_path: Path, + capsys: pytest.CaptureFixture[str], + caplog: pytest.LogCaptureFixture, +) -> None: + from autoskillit.cli.fleet._fleet_session import _fleet_session_launcher + from autoskillit.cli.session._session_launch import InteractiveLaunchValidationError + from autoskillit.core import FreshLaunch, PluginLoadMode + + launch_id_events: list[str] = [] + generated_home = tmp_path / "managed-home" + skills_dir = generated_home / "autoskillit-add-dir" + skills_dir.mkdir(parents=True) + projection_root = tmp_path / "projection" + projection_root.mkdir() + lifecycle = RecordingLifecycle( + generated_home=generated_home, + skills_dir=skills_dir, + projection_root=projection_root, + unavailability_payload={"backend": "codex", "unavailable": ()}, + returncodes=(), + ) + rejection = "cause: fleet catalog rejected\nremedy: refresh the installed generation" + backend = MagicMock() + backend.name = "codex" + backend.capabilities.session_dir_persistent = True + backend.conventions = MagicMock() + compilation = MagicMock() + compilation.catalog = MagicMock() + calls: list[object] = [] + + class _Trace: + def __init__(self, _project_dir: Path, launch_id: str, *, enabled: bool) -> None: + assert enabled is False + launch_id_events.append(launch_id) + lifecycle.events.append(("trace-created",)) + + def record_launch_anchor(self) -> None: + lifecycle.events.append(("trace-anchor",)) + + def close(self, *, status: str) -> None: + lifecycle.events.append(("trace-close", status)) + + def reject_launch(*_args: object, **_kwargs: object) -> None: + calls.append(object()) + raise InteractiveLaunchValidationError(errors=(rejection,)) + + original_render = _patch_session__session_launch.render_launch_validation_errors + + def record_render(errors: tuple[str, ...]) -> None: + lifecycle.events.append(("validation-render", errors)) + original_render(errors) + + monkeypatch.setattr( + _patch_session__session_launch, + "_run_interactive_session", + reject_launch, + ) + monkeypatch.setattr( + _patch_session__session_launch, + "render_launch_validation_errors", + record_render, + ) + monkeypatch.setattr(_patch_session__startup_trace, "StartupTrace", _Trace) + monkeypatch.setattr( + "autoskillit.workspace.DefaultSessionSkillManager", + lambda *args, **kwargs: lifecycle, + ) + monkeypatch.setattr( + _patch_install__plugin_artifact, + "interactive_plugin_authority", + lambda **_kwargs: (lifecycle, PluginLoadMode.GENERATED_HOME), + ) + monkeypatch.setattr( + "autoskillit.workspace.resolve_persistent_session_roots", + lambda *_args, **_kwargs: MagicMock(), + ) + monkeypatch.setattr( + "autoskillit.workspace.resolve_ephemeral_root", + lambda: tmp_path / "ephemeral", + ) + + caller_resumed = False + with pytest.raises(SystemExit) as exc_info: + with _fleet_session_launcher( + backend=backend, + project_dir=tmp_path, + skill_compilation=compilation, + default_base_branch="main", + workspace_temp_dir=None, + force_inactive_agent_teams=False, + mcp_tool_timeout_sec=1.0, + process_tether=ProcessTetherConfig(), + ) as launch_session: + launch_session(FreshLaunch(system_prompt="validation contract"), {}) + caller_resumed = True + + assert exc_info.value.code == 1 + assert caller_resumed is False + assert len(calls) == 1 + assert len(launch_id_events) == 1 + assert capsys.readouterr().err == ( + "ERROR: cause: fleet catalog rejected; remedy: refresh the installed generation\n" + ) + assert lifecycle.events.count(("trace-close", "failed")) == 1 + assert ("trace-close", "success") not in lifecycle.events + managed_exit = lifecycle.event_for("managed-exit", launch_id_events[0]) + assert lifecycle.events.index(("validation-render", (rejection,))) < lifecycle.events.index( + managed_exit + ) + assert lifecycle.events.index(managed_exit) < lifecycle.events.index(("projection-exit",)) + assert lifecycle.projection_bindings[0].closed + assert not [ + record for record in caplog.records if "fleet catalog rejected" in record.getMessage() + ] + assert all( + record.exc_info is None + for record in caplog.records + if record.name.startswith("autoskillit.") + ) + + class TestLaunchFleetSessionIngredientsTable: def _call( self, diff --git a/tests/cli/test_force_inactive_config_corridors.py b/tests/cli/test_force_inactive_config_corridors.py index 2e378ca40a..ffaba55194 100644 --- a/tests/cli/test_force_inactive_config_corridors.py +++ b/tests/cli/test_force_inactive_config_corridors.py @@ -32,8 +32,8 @@ SessionAttemptHandle, ValidatedAddDir, ) -from tests.cli._cook_launch_helpers import cook_attempt_result from tests.cli._interactive_process import interactive_launch_metadata +from tests.cli._managed_launch_helpers import cook_attempt_result pytestmark = [pytest.mark.layer("cli"), pytest.mark.medium] diff --git a/tests/cli/test_installed_plugin_selector_integration.py b/tests/cli/test_installed_plugin_selector_integration.py index e360cd62ea..c771b54b15 100644 --- a/tests/cli/test_installed_plugin_selector_integration.py +++ b/tests/cli/test_installed_plugin_selector_integration.py @@ -46,8 +46,8 @@ from autoskillit.execution.backends import ClaudeCodeBackend, CodexBackend from autoskillit.workspace import DefaultSkillResolver, compile_session_skill_catalog from autoskillit.workspace._installed._projection_cache import projected_plugin_artifact_digest -from tests.cli._cook_launch_helpers import cook_attempt_result from tests.cli._interactive_process import InteractiveProcessStub, interactive_launch_metadata +from tests.cli._managed_launch_helpers import cook_attempt_result from tests.fakes import adapt_test_skill_semantics from tests.fixtures.plugin_artifact_state import ( INVALID_PLUGIN_ARTIFACT_STATE_KINDS, diff --git a/tests/cli/test_interactive_launch_anchor.py b/tests/cli/test_interactive_launch_anchor.py index 7012027035..bdcbc269f8 100644 --- a/tests/cli/test_interactive_launch_anchor.py +++ b/tests/cli/test_interactive_launch_anchor.py @@ -36,9 +36,9 @@ ) from autoskillit.execution.backends.codex import CodexBackend from autoskillit.execution.process import _daemon_orphans -from tests.cli._cook_launch_helpers import cook_attempt_result from tests.cli._fleet_helpers import _capture_subprocess, _stub_campaign_resolution, _stub_guards from tests.cli._logging_helpers import stub_configure_logging +from tests.cli._managed_launch_helpers import cook_attempt_result from tests.cli.conftest import _SCRIPT_YAML from tests.cli.test_cook_env_scrub import _capture_cook_spec from tests.execution.backends._codex_fixtures import installed_catalog diff --git a/tests/cli/test_launch_command_logging.py b/tests/cli/test_launch_command_logging.py index b54ebb5b36..e2ab6f33a0 100644 --- a/tests/cli/test_launch_command_logging.py +++ b/tests/cli/test_launch_command_logging.py @@ -25,8 +25,8 @@ from autoskillit import cli from autoskillit.config import AutomationConfig, LoggingConfig from autoskillit.core import atomic_write -from tests.cli._cook_launch_helpers import arrange_cook from tests.cli._fleet_helpers import _stub_campaign_resolution, _stub_guards +from tests.cli._managed_launch_helpers import arrange_cook pytestmark = [pytest.mark.layer("cli"), pytest.mark.medium] diff --git a/tests/cli/test_reload_loop.py b/tests/cli/test_reload_loop.py index 4085fcc37c..15069bdad5 100644 --- a/tests/cli/test_reload_loop.py +++ b/tests/cli/test_reload_loop.py @@ -23,8 +23,8 @@ import autoskillit.cli.ui._terminal as _patch_ui__terminal import autoskillit.cli.ui._timed_input as _patch_ui__timed_input from autoskillit.core import InteractiveInvocationValidation, PreLaunchReadiness -from tests.cli._cook_launch_helpers import RecordingLifecycle, cook_attempt_result from tests.cli._interactive_process import InteractiveProcessStub, interactive_launch_metadata +from tests.cli._managed_launch_helpers import RecordingLifecycle, cook_attempt_result from tests.fakes import adapt_test_skill_semantics pytestmark = [ diff --git a/tests/cli/test_reload_reprobe_medium.py b/tests/cli/test_reload_reprobe_medium.py index a2c4de6035..de54927663 100644 --- a/tests/cli/test_reload_reprobe_medium.py +++ b/tests/cli/test_reload_reprobe_medium.py @@ -11,7 +11,7 @@ from autoskillit.core import atomic_write from autoskillit.execution.backends import ClaudeCodeBackend from tests._realistic_project import PINNED_CLAUDE_SHIM_VERSION_OUTPUT -from tests.cli._cook_launch_helpers import arrange_cook +from tests.cli._managed_launch_helpers import arrange_cook pytestmark = [pytest.mark.layer("cli"), pytest.mark.medium] diff --git a/tests/cli/test_serve_eof.py b/tests/cli/test_serve_eof.py index 4d0ddec33c..dd36bdd846 100644 --- a/tests/cli/test_serve_eof.py +++ b/tests/cli/test_serve_eof.py @@ -34,7 +34,8 @@ def test_stdio_eof_exits_and_cleans_lifespan_state(tmp_path: Path) -> None: ) sentinel = state_dir / "kitchen_state" / f"server_ready_{process.pid}.sentinel" try: - wait_for_subprocess_ready(process, sentinel, deadline_s=10.0) + # Allow cold imports under xdist contention before timing EOF shutdown. + wait_for_subprocess_ready(process, sentinel, deadline_s=30.0) assert process.stdin is not None process.stdin.close() process.stdin = None diff --git a/tests/cli/test_session_launch.py b/tests/cli/test_session_launch.py index 7f81ba7ca4..c6ca4bd321 100644 --- a/tests/cli/test_session_launch.py +++ b/tests/cli/test_session_launch.py @@ -47,8 +47,8 @@ PINNED_CLAUDE_SHIM_VERSION, PINNED_CLAUDE_SHIM_VERSION_OUTPUT, ) -from tests.cli._cook_launch_helpers import RecordingLifecycle, cook_attempt_result from tests.cli._interactive_process import InteractiveProcessStub, interactive_launch_metadata +from tests.cli._managed_launch_helpers import RecordingLifecycle, cook_attempt_result from tests.fixtures.plugin_artifact_state import ( PluginArtifactStateKind, build_plugin_artifact_state, @@ -1931,6 +1931,7 @@ def _write_codex_mcp_probe_executable(path: Path) -> None: json.dumps( [ { + "type": "message", "role": "developer", "content": [{"type": "input_text", "text": skills_instructions}], } @@ -2387,6 +2388,160 @@ def must_not_spawn(*_args, **_kwargs): # type: ignore[no-untyped-def] assert binding.closed +def test_render_launch_validation_errors_emits_one_ordered_line_per_error( + capsys: pytest.CaptureFixture[str], +) -> None: + from autoskillit.cli.session._session_launch import render_launch_validation_errors + + errors = ( + "cause: projected catalog discovery failed\nversion: codex-cli 0.164.0", + "remedy: run autoskillit install", + ) + + render_launch_validation_errors(errors) + + assert capsys.readouterr().err.splitlines() == [ + "ERROR: cause: projected catalog discovery failed; version: codex-cli 0.164.0", + "ERROR: remedy: run autoskillit install", + ] + + +def test_managed_cook_validation_rejection_cleans_up_before_exit( + tmp_path: Path, + monkeypatch: pytest.MonkeyPatch, + capsys: pytest.CaptureFixture[str], + caplog: pytest.LogCaptureFixture, +) -> None: + from autoskillit.core import CmdSpec, SkillExecutionRole, ValidatedAddDir + from autoskillit.execution.backends.codex import CodexBackend + from autoskillit.workspace import DefaultSkillResolver, compile_session_skill_catalog + + launch_id = "validationfailure" + generated_home = tmp_path / "managed-home" + skills_dir = generated_home / "autoskillit-add-dir" + skills_dir.mkdir(parents=True) + projection_root = tmp_path / "projection" + projection_root.mkdir() + lifecycle = RecordingLifecycle( + generated_home=generated_home, + skills_dir=skills_dir, + projection_root=projection_root, + unavailability_payload={"backend": "codex", "unavailable": ()}, + returncodes=(), + ) + rejection = "cause: managed catalog rejected\nremedy: refresh the installed generation" + + class _RejectingCodexBackend(CodexBackend): + def binary_name(self) -> str: + return "true" + + def ensure_pre_launch(self, **_kwargs: object) -> PreLaunchReadiness: + return PreLaunchReadiness((), {}) + + def probe_launch_readiness(self, **_kwargs: object) -> PreLaunchReadiness: + return PreLaunchReadiness((), {}) + + def build_interactive_cmd(self, **kwargs): # type: ignore[no-untyped-def] + managed_skill_catalog = next( + (entry for entry in kwargs["add_dirs"] if isinstance(entry, ValidatedAddDir)), + None, + ) + return CmdSpec( + cmd=("true",), + env={}, + **interactive_launch_metadata(binary="true", launch=kwargs["launch"]), + managed_skill_catalog=managed_skill_catalog, + ) + + def validate_interactive_invocation( + self, spec: CmdSpec + ) -> InteractiveInvocationValidation: + del spec + lifecycle.events.append(("validated",)) + return InteractiveInvocationValidation(errors=(rejection,)) + + class _Trace: + def __init__(self, *_args: object, **_kwargs: object) -> None: + lifecycle.events.append(("trace-created",)) + + def record_launch_anchor(self) -> None: + lifecycle.events.append(("trace-anchor",)) + + def close(self, *, status: str) -> None: + lifecycle.events.append(("trace-close", status)) + + source_home = tmp_path / "source-codex" + source_home.mkdir() + backend = _RejectingCodexBackend(source_codex_home=source_home) + compilation = compile_session_skill_catalog( + DefaultSkillResolver().list_effective(tmp_path, SkillExecutionRole.ORCHESTRATOR), + backend, + ) + original_render = _patch_session__session_launch.render_launch_validation_errors + + def record_render(errors: tuple[str, ...]) -> None: + lifecycle.events.append(("validation-render", errors)) + original_render(errors) + + monkeypatch.setattr(shutil, "which", lambda _name, **_kwargs: "/usr/bin/true") + monkeypatch.setattr( + "autoskillit.workspace.DefaultSessionSkillManager", + lambda *args, **kwargs: lifecycle, + ) + monkeypatch.setattr( + _patch_install__plugin_artifact, + "interactive_plugin_authority", + lambda **_kwargs: (lifecycle, PluginLoadMode.GENERATED_HOME), + ) + monkeypatch.setattr( + "autoskillit.cli.session._session_startup_trace.StartupTrace", + _Trace, + ) + monkeypatch.setattr( + _patch_session__session_launch, + "render_launch_validation_errors", + record_render, + ) + + with pytest.raises(SystemExit) as exc_info: + _launch_cook_session( + launch=FreshLaunch(system_prompt="validation contract"), + project_dir=tmp_path, + required_env=frozenset(), + process_tether=ProcessTetherConfig(), + backend=backend, + skill_compilation=compilation, + launch_id=launch_id, + default_base_branch="main", + workspace_temp_dir=None, + ) + + assert exc_info.value.code == 1 + assert capsys.readouterr().err == ( + "ERROR: cause: managed catalog rejected; remedy: refresh the installed generation\n" + ) + assert lifecycle.events.count(("validated",)) == 1 + assert lifecycle.events.count(("trace-close", "failed")) == 1 + assert ("trace-close", "success") not in lifecycle.events + assert lifecycle.events_of_type("run") == [] + assert lifecycle.events_of_type("attempt-enter") == [] + assert lifecycle.events.index(("validation-render", (rejection,))) < lifecycle.events.index( + lifecycle.event_for("managed-exit", launch_id) + ) + assert lifecycle.events.index( + lifecycle.event_for("managed-exit", launch_id) + ) < lifecycle.events.index(("projection-exit",)) + assert lifecycle.projection_bindings[0].closed + assert not [ + record for record in caplog.records if "managed catalog rejected" in record.getMessage() + ] + assert all( + record.exc_info is None + for record in caplog.records + if record.name.startswith("autoskillit.") + ) + + def test_order_managed_session_keeps_home_across_reload_and_infra_resume( tmp_path: Path, monkeypatch: pytest.MonkeyPatch, diff --git a/tests/cli/test_skill_unavailability.py b/tests/cli/test_skill_unavailability.py index d72dca9298..711bb8b220 100644 --- a/tests/cli/test_skill_unavailability.py +++ b/tests/cli/test_skill_unavailability.py @@ -7,7 +7,7 @@ import pytest from autoskillit.cli.session._session_cook import _prepare_cook_managed_launch -from autoskillit.cli.session._session_launch import ( +from autoskillit.cli.session._session_onboarding import ( append_skill_unavailability, render_skill_unavailability, ) diff --git a/tests/contracts/test_claude_code_interface_contracts.py b/tests/contracts/test_claude_code_interface_contracts.py index 76d12b08cb..c766bae689 100644 --- a/tests/contracts/test_claude_code_interface_contracts.py +++ b/tests/contracts/test_claude_code_interface_contracts.py @@ -242,7 +242,7 @@ def test_cook_add_dir_target_has_correct_structure( import shutil from autoskillit.core import CmdSpec - from tests.cli._cook_launch_helpers import cook_attempt_result + from tests.cli._managed_launch_helpers import cook_attempt_result monkeypatch.setattr("autoskillit.core.bind_session_owner", lambda *_args: True) structure_errors: list[str] = [] diff --git a/tests/contracts/test_protocol_satisfaction.py b/tests/contracts/test_protocol_satisfaction.py index 03b62916f3..ebf8c4e3a4 100644 --- a/tests/contracts/test_protocol_satisfaction.py +++ b/tests/contracts/test_protocol_satisfaction.py @@ -263,7 +263,7 @@ def test_session_skill_manager_managed_catalog_is_context_manager_boundary(): ("test_file", "class_name"), [ pytest.param( - "tests/cli/_cook_launch_helpers.py", + "tests/cli/_managed_launch_helpers.py", "RecordingLifecycle", id="session-launch-lifecycle-manager", ), diff --git a/tests/execution/backends/test_codex_config_validation.py b/tests/execution/backends/test_codex_config_validation.py index 388574fb9f..fc567dd57f 100644 --- a/tests/execution/backends/test_codex_config_validation.py +++ b/tests/execution/backends/test_codex_config_validation.py @@ -19,6 +19,7 @@ from autoskillit.execution.backends import _codex_probes as probes from autoskillit.execution.backends._codex import interactive_validation from autoskillit.execution.process._lifecycle import owned_group +from tests.fixtures.codex import fixture_path from tests.fixtures.hook_topology import projection_shaped_hook_root pytestmark = [pytest.mark.layer("execution"), pytest.mark.medium] @@ -488,6 +489,7 @@ def _prompt_input_for_catalog(catalog_dir: Path) -> bytes: return json.dumps( [ { + "type": "message", "role": "developer", "content": [{"type": "input_text", "text": skills_block}], } @@ -495,7 +497,19 @@ def _prompt_input_for_catalog(catalog_dir: Path) -> bytes: ).encode() -@pytest.mark.parametrize("version", ("0.156.0", "0.156.1")) +def _captured_v0164_prompt_input_for_catalog(catalog_dir: Path) -> bytes: + document = json.loads( + fixture_path("discovery_prompt_input_v0164.json").read_text(encoding="utf-8") + ) + skills_message = document[2] + skills_text = skills_message["content"][1]["text"] + source_root = "/opt/autoskillit-fixtures/codex/discovery/v0164/home/add-dir/skills" + skills_text = skills_text.replace(source_root, str(catalog_dir.resolve())) + skills_message["content"][1]["text"] = skills_text.replace("make-arch-diag", "managed-skill") + return json.dumps(document).encode() + + +@pytest.mark.parametrize("version", ("0.156.0", "0.156.1", "0.164.0")) def test_real_interactive_validator_checks_bound_version_before_native_discovery( tmp_path: Path, monkeypatch: pytest.MonkeyPatch, @@ -530,9 +544,14 @@ def run_probe( if command == (str(executable), "--version"): return probes._BoundedProbeResult(0, f"codex-cli {version}\n".encode(), b"") if command[-2:] == discovery.CODEX_SKILL_DISCOVERY_CONTRACT.prompt_probe: + prompt_input = ( + _captured_v0164_prompt_input_for_catalog(generated_home / "skills") + if version == "0.164.0" + else _prompt_input_for_catalog(generated_home / "skills") + ) return probes._BoundedProbeResult( 0, - _prompt_input_for_catalog(generated_home / "skills"), + prompt_input, b"", ) pytest.fail(f"unexpected Codex probe command: {command}") diff --git a/tests/execution/backends/test_codex_discovery.py b/tests/execution/backends/test_codex_discovery.py index 83eda32798..eebdf5c1de 100644 --- a/tests/execution/backends/test_codex_discovery.py +++ b/tests/execution/backends/test_codex_discovery.py @@ -17,28 +17,98 @@ pytestmark = [pytest.mark.layer("execution"), pytest.mark.medium] _FIXTURE_ROOT = Path("/opt/autoskillit-fixtures/codex/discovery") -_FIXTURES = ("discovery_prompt_input_v0130.json", "discovery_prompt_input_v0153.json") +_FIXTURE_EXPECTATIONS = [ + ( + "discovery_prompt_input_v0130.json", + ( + Path("/opt/autoskillit-fixtures/codex/discovery/v0130/home/skills"), + Path("/opt/autoskillit-fixtures/codex/discovery/v0130/home/skills/.system"), + ), + { + "alpha": Path( + "/opt/autoskillit-fixtures/codex/discovery/v0130/home/skills/alpha/SKILL.md" + ), + "beta": Path( + "/opt/autoskillit-fixtures/codex/discovery/v0130/home/skills/beta/SKILL.md" + ), + "system-native": Path( + "/opt/autoskillit-fixtures/codex/discovery/v0130/home/skills/.system/system-native/SKILL.md" + ), + }, + ), + ( + "discovery_prompt_input_v0153.json", + ( + Path("/opt/autoskillit-fixtures/codex/discovery/v0153/home/skills"), + Path("/opt/autoskillit-fixtures/codex/discovery/v0153/home/skills/.system"), + ), + { + "alpha": Path( + "/opt/autoskillit-fixtures/codex/discovery/v0153/home/skills/alpha/SKILL.md" + ), + "beta": Path( + "/opt/autoskillit-fixtures/codex/discovery/v0153/home/skills/beta/SKILL.md" + ), + "system-native": Path( + "/opt/autoskillit-fixtures/codex/discovery/v0153/home/skills/.system/system-native/SKILL.md" + ), + }, + ), + ( + "discovery_prompt_input_v0164.json", + ( + Path("/opt/autoskillit-fixtures/codex/discovery/v0164/home/add-dir/skills"), + Path("/opt/autoskillit-fixtures/codex/discovery/v0164/home/add-dir/skills/.system"), + ), + { + "make-arch-diag": Path( + "/opt/autoskillit-fixtures/codex/discovery/v0164/home/add-dir/skills/make-arch-diag/SKILL.md" + ), + "imagegen": Path( + "/opt/autoskillit-fixtures/codex/discovery/v0164/home/add-dir/skills/.system/imagegen/SKILL.md" + ), + "openai-docs": Path( + "/opt/autoskillit-fixtures/codex/discovery/v0164/home/add-dir/skills/.system/openai-docs/SKILL.md" + ), + "skill-creator": Path( + "/opt/autoskillit-fixtures/codex/discovery/v0164/home/add-dir/skills/.system/skill-creator/SKILL.md" + ), + "skill-installer": Path( + "/opt/autoskillit-fixtures/codex/discovery/v0164/home/add-dir/skills/.system/skill-installer/SKILL.md" + ), + }, + ), +] +_FIXTURE_SOURCE_ROOTS = {name: roots[0] for name, roots, _paths in _FIXTURE_EXPECTATIONS} +_FIXTURES = tuple(_FIXTURE_SOURCE_ROOTS) def _skills_text(document: list[object]) -> str: - item = document[0] - assert isinstance(item, dict) - content = item["content"] - assert isinstance(content, list) - part = content[0] - assert isinstance(part, dict) - text = part["text"] - assert isinstance(text, str) - return text + return _skills_text_part(document)["text"] + + +def _skills_text_part(document: list[object]) -> dict[str, str]: + candidates: list[dict[str, str]] = [] + for item in document: + if not isinstance(item, dict): + continue + if item.get("type") != "message" or item.get("role") != "developer": + continue + content = item.get("content") + if not isinstance(content, list): + continue + for part in content: + if not isinstance(part, dict): + continue + text = part.get("text") + if isinstance(text, str) and text.startswith(""): + candidates.append(part) + assert len(candidates) == 1 + return candidates[0] def _with_skills_text(document: list[object], text: str) -> str: - item = document[0] - assert isinstance(item, dict) - content = item["content"] - assert isinstance(content, list) - part = content[0] - assert isinstance(part, dict) + part = _skills_text_part(document) part["text"] = text return json.dumps(document) @@ -88,8 +158,7 @@ def _discovery_root(catalog_dir: Path) -> Path: def _loader_output_at_root(name: str, catalog_dir: Path, discovery_root: Path) -> str: document = _fixture_document(name) - fixture_version = "v0130" if "v0130" in name else "v0153" - source_root = _FIXTURE_ROOT / fixture_version / "home" / "skills" + source_root = _FIXTURE_SOURCE_ROOTS[name] return _with_skills_text( document, _skills_text(document).replace(str(source_root), str(discovery_root)), @@ -132,33 +201,30 @@ def _install_prompt_stub( @pytest.mark.parametrize( - ("fixture_name", "expected_version"), - [ - ("discovery_prompt_input_v0130.json", "v0130"), - ("discovery_prompt_input_v0153.json", "v0153"), - ], + ("fixture_name", "expected_roots", "expected_paths"), + _FIXTURE_EXPECTATIONS, ) def test_parse_skills_instructions_reads_pinned_real_loader_shapes( fixture_name: str, - expected_version: str, + expected_roots: tuple[Path, ...], + expected_paths: dict[str, Path], ) -> None: parsed = discovery.parse_skills_instructions( fixture_path(fixture_name).read_text(encoding="utf-8") ) - root = _FIXTURE_ROOT / expected_version / "home" / "skills" - - assert parsed.names == {"alpha", "beta", "system-native"} - assert parsed.roots == (root, root / ".system") - assert parsed.paths == { - "alpha": root / "alpha" / "SKILL.md", - "beta": root / "beta" / "SKILL.md", - "system-native": root / ".system" / "system-native" / "SKILL.md", - } + assert parsed.names == set(expected_paths) + assert parsed.roots == expected_roots + assert parsed.paths == expected_paths -@pytest.mark.parametrize("fixture_name", _FIXTURES) +@pytest.mark.parametrize( + ("fixture_name", "expected_roots", "expected_paths"), + _FIXTURE_EXPECTATIONS, +) def test_parse_skills_instructions_tolerates_json_and_rendering_whitespace( fixture_name: str, + expected_roots: tuple[Path, ...], + expected_paths: dict[str, Path], ) -> None: document = _fixture_document(fixture_name) text = _skills_text(document).replace("\n", "\r\n") @@ -173,6 +239,31 @@ def test_parse_skills_instructions_tolerates_json_and_rendering_whitespace( parsed = discovery.parse_skills_instructions(json.dumps(reordered, indent=2)) + assert parsed.names == set(expected_paths) + assert parsed.roots == expected_roots + assert parsed.paths == expected_paths + + +@pytest.mark.parametrize( + ("extra_item", "position"), + [ + ({"type": "additional_tools", "role": "developer", "tools": []}, "leading"), + ({"type": "future_item", "role": "developer", "payload": {}}, "trailing"), + ({"type": "message", "role": "user"}, "trailing"), + ], +) +def test_parse_skills_instructions_ignores_unconsumed_response_items( + extra_item: dict[str, object], + position: str, +) -> None: + document = _fixture_document("discovery_prompt_input_v0153.json") + if position == "leading": + document.insert(0, extra_item) + else: + document.append(extra_item) + + parsed = discovery.parse_skills_instructions(json.dumps(document)) + assert parsed.names == {"alpha", "beta", "system-native"} @@ -181,7 +272,10 @@ def test_parse_skills_instructions_tolerates_json_and_rendering_whitespace( [ ("{not json", "malformed JSON"), (json.dumps({"content": []}), "response-item list"), - (json.dumps([{"role": "developer", "content": "wrong"}]), "malformed content"), + ( + json.dumps([{"type": "message", "role": "developer", "content": "wrong"}]), + "malformed content", + ), (json.dumps([]), " block"), ], ) @@ -193,6 +287,15 @@ def test_parse_skills_instructions_rejects_malformed_json_and_envelope( discovery.parse_skills_instructions(prompt_input) +def test_parse_skills_instructions_rejects_ambiguous_developer_blocks() -> None: + document = _fixture_document("discovery_prompt_input_v0153.json") + duplicate = json.loads(json.dumps(document[0])) + document.append(duplicate) + + with pytest.raises(ValueError, match="exactly one block"): + discovery.parse_skills_instructions(json.dumps(document)) + + @pytest.mark.parametrize( ("needle", "replacement", "message"), [ @@ -322,6 +425,61 @@ def test_attest_catalog_discovery_accepts_real_loader_fixture_at_expected_root( assert (catalog_dir / ".system" / "native" / "SKILL.md").is_file() +def test_attest_catalog_discovery_accepts_captured_v0164_response(tmp_path: Path) -> None: + catalog_dir, expected_entries = _catalog(tmp_path, entries=("make-arch-diag",)) + for name in ("imagegen", "openai-docs", "skill-creator", "skill-installer"): + native_skill = catalog_dir / ".system" / name / "SKILL.md" + native_skill.parent.mkdir() + native_skill.write_text("native", encoding="utf-8") + command, env = _install_prompt_stub( + tmp_path, + _loader_output("discovery_prompt_input_v0164.json", catalog_dir), + ) + + validation = attestation.attest( + probe_command=command, + env=env, + cwd=str(tmp_path), + catalog_dir=catalog_dir, + expected_discovery_root=_discovery_root(catalog_dir), + route=discovery.CODEX_MANAGED_HOME_ROUTE, + expected_entries=expected_entries, + version="0.164.0", + ) + + assert validation.errors == () + assert validation.pre_spawn_check is not None + validation.pre_spawn_check() + + +def test_attest_catalog_discovery_reports_actionable_v0164_consumed_item_diagnostic( + tmp_path: Path, +) -> None: + catalog_dir, expected_entries = _catalog(tmp_path, entries=("make-arch-diag",)) + document = _fixture_document("discovery_prompt_input_v0164.json") + skills_message = document[2] + assert isinstance(skills_message, dict) + skills_message["content"] = "malformed" + command, env = _install_prompt_stub(tmp_path, json.dumps(document)) + + errors = attestation.attest( + probe_command=command, + env=env, + cwd=str(tmp_path), + catalog_dir=catalog_dir, + expected_discovery_root=_discovery_root(catalog_dir), + route=discovery.CODEX_MANAGED_HOME_ROUTE, + expected_entries=expected_entries, + version="0.164.0", + ).errors + + diagnostic = "\n".join(errors) + assert "response item has malformed content" in diagnostic + assert "version=0.164.0" in diagnostic + assert "Update AutoSkillit" in diagnostic + assert "retry" in diagnostic + + def test_attest_catalog_discovery_rejects_foreign_managed_root(tmp_path: Path) -> None: catalog_dir, expected_entries = _catalog(tmp_path) scope = catalog_dir.parents[2] diff --git a/tests/fixtures/codex/discovery_prompt_input_v0164.json b/tests/fixtures/codex/discovery_prompt_input_v0164.json new file mode 100644 index 0000000000..20e1c22091 --- /dev/null +++ b/tests/fixtures/codex/discovery_prompt_input_v0164.json @@ -0,0 +1,510 @@ +[ + { + "type": "additional_tools", + "id": "at_01a1b866-87cc-7323-9406-4447eaa2818b", + "role": "developer", + "tools": [ + { + "type": "namespace", + "name": "functions", + "description": "", + "tools": [ + { + "type": "custom", + "name": "exec", + "description": "Run JavaScript code to orchestrate/compose tool calls\n- Evaluates the provided JavaScript code in a fresh V8 isolate as an async module.\n- All nested tools are available on the global `tools` object, for example `await tools.exec_command(...)`. Tool names are exposed as normalized JavaScript identifiers, for example `await tools.mcp__ologs__get_profile(...)`.\n- Nested tool methods take either a string or an object as their input argument.\n- Nested tools return either an object or a string, based on the description.\n- Runs raw JavaScript -- no Node, no file system, no network access, no console.\n- Accepts raw JavaScript source text, not JSON, quoted strings, or markdown code fences.\n- You may optionally start the tool input with a first-line pragma like `// @exec: {\"yield_time_ms\": 10000, \"max_output_tokens\": 1000}`.\n- `yield_time_ms` asks `exec` to yield early if the script is still running. Defaults to 30000 ms.\n- `max_output_tokens` sets the token budget for direct `exec` results. Defaults to 10000 tokens.\n- When the JS code is fully evaluated, the isolate's lifetime ends and unawaited promises are silently discarded.\n\n- Global helpers:\n- `exit()`: Immediately ends the current script successfully (like an early return from the top level).\n- `text(value: string | number | boolean | undefined | null)`: Appends a text item. Non-string values are stringified with `JSON.stringify(...)` when possible.\n- `image(imageUrlOrItem: string | { image_url: string; detail?: \"auto\" | \"low\" | \"high\" | \"original\" | null } | ImageContent, detail?: \"auto\" | \"low\" | \"high\" | \"original\" | null)`: Appends an image item. `image_url` should be a base64-encoded `data:` URL. To forward an MCP tool image, pass an individual `ImageContent` block from `result.content`, for example `image(result.content[0])`. MCP image blocks may request detail with `_meta: { \"codex/imageDetail\": \"original\" }`. When provided, the second `detail` argument overrides any detail embedded in the first argument.\n- `audio(audioUrlOrItem: string | { audio_url: string } | AudioContent)`: Appends an audio item. `audio_url` should be a base64-encoded `data:` URL. To forward an MCP tool audio block, pass an individual `AudioContent` block from `result.content`, for example `audio(result.content[0])`.\n- `generatedImage(result: { image_url: string; output_hint?: string })`: Appends an image-generation result and its optional output hint. HTTP(S) URLs are not supported.\n- `store(key: string, value: any)`: stores a serializable value under a string key for later `exec` calls in the same session.\n- `load(key: string)`: returns the stored value for a string key, or `undefined` if it is missing.\n- `notify(value: string | number | boolean | undefined | null)`: immediately injects an extra `custom_tool_call_output` for the current `exec` call. Values are stringified like `text(...)`.\n- `setTimeout(callback: () => void, delayMs?: number)`: schedules a callback to run later and returns a timeout id. Pending timeouts do not keep `exec` alive by themselves; await an explicit promise if you need to wait for one.\n- `clearTimeout(timeoutId?: number)`: cancels a timeout created by `setTimeout`.\n- `ALL_TOOLS`: metadata for the enabled nested tools as `{ name, description }` entries.\n- `yield_control()`: yields the accumulated output to the model immediately while the script keeps running.\n\nSome deferred nested tools may be omitted from this description. They are still available on the global `tools` object and listed in `ALL_TOOLS`.\nTo find one, filter `ALL_TOOLS` by `name` and `description`.\n\nTool availability can change between calls.\n\nShared MCP Types:\n```ts\ntype Role = \"user\" | \"assistant\";\ntype MetaObject = Record;\ntype Annotations = {\n audience?: Role[];\n priority?: number;\n lastModified?: string;\n};\ntype Icon = {\n src: string;\n mimeType?: string;\n sizes?: string[];\n theme?: \"light\" | \"dark\";\n};\ntype TextResourceContents = {\n uri: string;\n mimeType?: string;\n _meta?: MetaObject;\n text: string;\n};\ntype BlobResourceContents = {\n uri: string;\n mimeType?: string;\n _meta?: MetaObject;\n blob: string;\n};\ntype TextContent = {\n type: \"text\";\n text: string;\n annotations?: Annotations;\n _meta?: MetaObject;\n};\ntype ImageContent = {\n type: \"image\";\n data: string;\n mimeType: string;\n annotations?: Annotations;\n _meta?: MetaObject;\n};\ntype AudioContent = {\n type: \"audio\";\n data: string;\n mimeType: string;\n annotations?: Annotations;\n _meta?: MetaObject;\n};\ntype ResourceLink = {\n icons?: Icon[];\n name: string;\n title?: string;\n uri: string;\n description?: string;\n mimeType?: string;\n annotations?: Annotations;\n size?: number;\n _meta?: MetaObject;\n type: \"resource_link\";\n};\ntype EmbeddedResource = {\n type: \"resource\";\n resource: TextResourceContents | BlobResourceContents;\n annotations?: Annotations;\n _meta?: MetaObject;\n};\ntype ContentBlock =\n | TextContent\n | ImageContent\n | AudioContent\n | ResourceLink\n | EmbeddedResource;\ntype CallToolResult = {\n _meta?: MetaObject;\n content: ContentBlock[];\n isError?: boolean;\n structuredContent?: TStructured;\n [key: string]: unknown;\n};\n```\n\n### `apply_patch`\nThe `apply_patch` tool can be used to edit files. This is a FREEFORM tool, so do not wrap the patch in JSON.\n\nexec tool declaration:\n```ts\ndeclare const tools: { apply_patch(input: string): Promise; };\n```\n\n### `exec_command`\nRuns a command in a PTY, returning output or a session ID for ongoing interaction.\n\nexec tool declaration:\n```ts\ndeclare const tools: { exec_command(args: {\n // Shell command to execute.\n cmd: string;\n // User-facing approval question for `require_escalated`; omit otherwise.\n justification?: string;\n // True runs the shell with -l/-i semantics; false disables them. Defaults to true.\n login?: boolean;\n // Output token budget. Defaults to 10000 tokens; larger requests may be capped by policy.\n max_output_tokens?: number;\n // Reusable approval prefix for `cmd`, only with `sandbox_permissions: \"require_escalated\"`; for example [\"git\", \"pull\"].\n prefix_rule?: Array;\n // Per-command sandbox override. Defaults to `use_default`; use `require_escalated` for unsandboxed execution.\n sandbox_permissions?: \"use_default\" | \"require_escalated\";\n // Shell binary to launch. Defaults to the user's default shell.\n shell?: string;\n // True allocates a PTY for the command; false or omitted uses plain pipes.\n tty?: boolean;\n // Working directory for the command. Defaults to the turn cwd.\n workdir?: string;\n // Wait before yielding output. Defaults to 10000 ms; effective range is 250-30000 ms.\n yield_time_ms?: number;\n}): Promise<{\n // Chunk identifier included when the response reports one.\n chunk_id?: string;\n // Process exit code when the command finished during this call.\n exit_code?: number;\n // Approximate token count before output truncation.\n original_token_count?: number;\n // Command output text, possibly truncated.\n output: string;\n // Session identifier to pass to write_stdin when the process is still running.\n session_id?: number;\n // Elapsed wall time spent waiting for output in seconds.\n wall_time_seconds: number;\n}>; };\n```\n\n### `list_mcp_resource_templates`\nLists resource templates provided by MCP servers. Parameterized resource templates allow servers to share data that takes parameters and provides context to language models, such as files, database schemas, or application-specific information. Prefer resource templates over web search when possible.\n\nexec tool declaration:\n```ts\ndeclare const tools: { list_mcp_resource_templates(args: {\n // Opaque cursor from a previous list_mcp_resource_templates call; omit for the first page.\n cursor?: string;\n // MCP server name. Omit to list resource templates from every configured server.\n server?: string;\n}): Promise; };\n```\n\n### `list_mcp_resources`\nLists resources provided by MCP servers. Resources allow servers to share data that provides context to language models, such as files, database schemas, or application-specific information. Prefer resources over web search when possible.\n\nexec tool declaration:\n```ts\ndeclare const tools: { list_mcp_resources(args: {\n // Opaque cursor from a previous list_mcp_resources call; omit for the first page.\n cursor?: string;\n // MCP server name. Omit to list resources from every configured server.\n server?: string;\n}): Promise; };\n```\n\n### `read_mcp_resource`\nRead a specific resource from an MCP server given the server name and resource URI.\n\nexec tool declaration:\n```ts\ndeclare const tools: { read_mcp_resource(args: {\n // MCP server name exactly as configured. Must match the 'server' field returned by list_mcp_resources.\n server: string;\n // Resource URI to read. Must be one of the URIs returned by list_mcp_resources.\n uri: string;\n}): Promise; };\n```\n\n### `view_image`\nView a local image file from the filesystem when visual inspection is needed. Use this for images already available on disk.\n\nexec tool declaration:\n```ts\ndeclare const tools: { view_image(args: {\n // Image detail level. Defaults to `high`; use `original` to preserve exact resolution.\n detail?: \"high\" | \"original\";\n // Local filesystem path to an image file.\n path: string;\n}): Promise<{\n // Image detail hint returned by view_image. Returns `high` for default resized behavior or `original` when original resolution is preserved.\n detail: \"high\" | \"original\";\n // Data URL for the loaded image.\n image_url: string;\n}>; };\n```\n\n### `write_stdin`\nWrites characters to an existing unified exec session and returns recent output.\n\nexec tool declaration:\n```ts\ndeclare const tools: { write_stdin(args: {\n // Bytes to write to stdin. Defaults to empty, which polls without writing.\n chars?: string;\n // Output token budget. Defaults to 10000 tokens; larger requests may be capped by policy.\n max_output_tokens?: number;\n // Identifier of the running unified exec session.\n session_id: number;\n // Wait before yielding output. Non-empty writes default to 250 ms and cap at 30000 ms; empty polls wait 5000-300000 ms by default.\n yield_time_ms?: number;\n}): Promise<{\n // Chunk identifier included when the response reports one.\n chunk_id?: string;\n // Process exit code when the command finished during this call.\n exit_code?: number;\n // Approximate token count before output truncation.\n original_token_count?: number;\n // Command output text, possibly truncated.\n output: string;\n // Session identifier to pass to write_stdin when the process is still running.\n session_id?: number;\n // Elapsed wall time spent waiting for output in seconds.\n wall_time_seconds: number;\n}>; };\n```\n\n## clock\nTools for reading and waiting on time.\n\n### `clock__curr_time`\nReturn the current time in UTC.\n\nexec tool declaration:\n```ts\ndeclare const tools: { clock__curr_time(args: {}): Promise<{\n // Current UTC time formatted as YYYY-MM-DD HH:MM:SS UTC.\n current_time: string;\n}>; };\n```", + "format": { + "type": "grammar", + "syntax": "lark", + "definition": "\nstart: pragma_source | plain_source\npragma_source: PRAGMA_LINE NEWLINE SOURCE\nplain_source: SOURCE\n\nPRAGMA_LINE: /[ \\t]*\\/\\/ @exec:[^\\r\\n]*/\nNEWLINE: /\\r?\\n/\nSOURCE: /[\\s\\S]+/\n" + } + }, + { + "type": "function", + "name": "wait", + "description": "Waits on a yielded `exec` cell and returns new output or completion.\n- Use `wait` only after `exec` returns `Script running with cell ID ...`.\n- `cell_id` identifies the running `exec` cell to resume.\n- `yield_time_ms` controls how long to wait for more output before yielding again. Defaults to 10000 ms.\n- `max_tokens` limits how much new output this wait call returns. Defaults to 10000 tokens.\n- `terminate: true` stops the running cell; false or omitted waits for output.\n- `wait` returns only the new output since the last yield, or the final completion or termination result for that cell.\n- If the cell is still running, `wait` may yield again with the same `cell_id`.\n- If the cell has already finished, `wait` returns the completed result and closes the cell.", + "strict": false, + "parameters": { + "type": "object", + "properties": { + "cell_id": { + "type": "string", + "description": "Identifier of the running exec cell." + }, + "max_tokens": { + "type": "number", + "description": "Output token budget for this wait call. Defaults to 10000 tokens." + }, + "terminate": { + "type": "boolean", + "description": "True stops the running exec cell; false or omitted waits for output." + }, + "yield_time_ms": { + "type": "number", + "description": "Wait before yielding more output. Defaults to 10000 ms." + } + }, + "required": [ + "cell_id" + ], + "additionalProperties": false + } + }, + { + "type": "function", + "name": "request_user_input", + "description": "Request user input for one to three short questions and wait for the response. This tool is only available in Plan mode.", + "strict": false, + "parameters": { + "type": "object", + "properties": { + "questions": { + "type": "array", + "description": "Questions to show the user. Prefer 1 and do not exceed 3", + "items": { + "type": "object", + "properties": { + "header": { + "type": "string", + "description": "Short header label shown in the UI (12 or fewer chars)." + }, + "id": { + "type": "string", + "description": "Stable identifier for mapping answers (snake_case)." + }, + "options": { + "type": "array", + "description": "Provide 2-3 mutually exclusive choices. Put the recommended option first and suffix its label with \"(Recommended)\". Do not include an \"Other\" option in this list; the client will add a free-form \"Other\" option automatically.", + "items": { + "type": "object", + "properties": { + "description": { + "type": "string", + "description": "One short sentence explaining impact/tradeoff if selected." + }, + "label": { + "type": "string", + "description": "User-facing label (1-5 words)." + } + }, + "required": [ + "label", + "description" + ], + "additionalProperties": false + } + }, + "question": { + "type": "string", + "description": "Single-sentence prompt shown to the user." + } + }, + "required": [ + "id", + "header", + "question", + "options" + ], + "additionalProperties": false + } + } + }, + "required": [ + "questions" + ], + "additionalProperties": false + } + }, + { + "type": "function", + "name": "request_user_input_async", + "description": "Ask the user one or more questions during ongoing work. Use this tool only to request missing information, preferences, constraints, clarification, or approval. The tool returns immediately without ending the turn or waiting for a reply; any reply arrives asynchronously as a new user message. Keep questions concise, self-contained, and easy to understand, using a level of detail appropriate to the user and task. The UI always allows a free-text answer, including when suggested options are provided. A preselected option is not submitted automatically.", + "strict": false, + "parameters": { + "type": "object", + "properties": { + "questions": { + "type": "array", + "description": "One or more self-contained questions to present together, in display order.", + "items": { + "type": "object", + "properties": { + "options": { + "type": "array", + "description": "Suggested answers, in display order. Put the recommended answer first; the first option is preselected by default. The user can select one option or enter a free-text answer. Do not include an Other option or a free-text placeholder; the UI provides free-text input automatically. Omit options for a free-text-only question.", + "items": { + "type": "string" + }, + "minItems": 1 + }, + "title": { + "type": "string", + "description": "The complete question shown to the user, including any context needed to answer it." + } + }, + "required": [ + "title" + ], + "additionalProperties": false + }, + "minItems": 1 + } + }, + "required": [ + "questions" + ], + "additionalProperties": false + } + } + ] + }, + { + "type": "namespace", + "name": "clock", + "description": "Tools for reading and waiting on time.", + "tools": [ + { + "type": "function", + "name": "sleep", + "description": "Pause execution for a specified duration. The sleep ends early when new input arrives for the active turn. Returns the elapsed wall-clock time.", + "strict": false, + "parameters": { + "type": "object", + "properties": { + "duration_ms": { + "type": "number", + "description": "How long to sleep in milliseconds. Must be between 1 and 43200000." + } + }, + "required": [ + "duration_ms" + ], + "additionalProperties": false + } + } + ] + }, + { + "type": "namespace", + "name": "collaboration", + "description": "Tools for spawning and managing sub-agents.", + "tools": [ + { + "type": "function", + "name": "followup_task", + "description": "Send a follow-up task to an existing non-root target agent and trigger a turn if it is idle. If the target is already running, deliver the task promptly at message boundaries while sampling, or after the pending tool call completes.", + "strict": false, + "parameters": { + "type": "object", + "properties": { + "message": { + "type": "string", + "description": "Message text to send to the target agent.", + "encrypted": true + }, + "target": { + "type": "string", + "description": "Agent id or canonical task name to send a follow-up task to (from spawn_agent)." + } + }, + "required": [ + "target", + "message" + ], + "additionalProperties": false + } + }, + { + "type": "function", + "name": "interrupt_agent", + "description": "Interrupt an agent's current turn, if any, and return its previous status. The agent remains available for messages and follow-up tasks.", + "strict": false, + "parameters": { + "type": "object", + "properties": { + "target": { + "type": "string", + "description": "Agent id or canonical task name to interrupt (from spawn_agent)." + } + }, + "required": [ + "target" + ], + "additionalProperties": false + } + }, + { + "type": "function", + "name": "list_agents", + "description": "List live agents in the current root thread tree. Optionally filter by task-path prefix.", + "strict": false, + "parameters": { + "type": "object", + "properties": { + "path_prefix": { + "type": "string", + "description": "Task-path prefix filter without a trailing slash. Omit to list all live agents." + } + }, + "additionalProperties": false + } + }, + { + "type": "function", + "name": "send_message", + "description": "Send a message to an existing agent. The message will be delivered promptly. Does not trigger a new turn.", + "strict": false, + "parameters": { + "type": "object", + "properties": { + "message": { + "type": "string", + "description": "Message text to queue on the target agent.", + "encrypted": true + }, + "target": { + "type": "string", + "description": "Relative or canonical task name to message (from spawn_agent)." + } + }, + "required": [ + "target", + "message" + ], + "additionalProperties": false + } + }, + { + "type": "function", + "name": "spawn_agent", + "description": "\n Available model overrides (optional; inherited parent model is preferred):\n- `gpt-6.1-sol`: Latest workhorse model for coding and everyday work. Reasoning efforts: low (default), medium, high, xhigh, max, ultra. Service tiers: priority.\n- `gpt-6-astra`: Frontier intelligence for the most demanding work. Reasoning efforts: low (default), medium, high, xhigh, max, ultra. Service tiers: priority.\n- `gpt-6-sol`: Previous generation workhorse model. Reasoning efforts: low, medium (default), high, xhigh, max, ultra. Service tiers: priority.\n- `gpt-6-luna`: Fast and affordable model for easier tasks. Reasoning efforts: low, medium (default), high, xhigh, max. Service tiers: priority.\n- `gpt-5.6-sol`: Older generation workhorse model. Reasoning efforts: low (default), medium, high, xhigh, max, ultra. Service tiers: priority.\n Spawns an agent to work on the specified task. If your current task is `/root/task1` and you spawn_agent with task_name \"task_3\" the agent will have canonical task name `/root/task1/task_3`.\nYou are then able to refer to this agent as `task_3` or `/root/task1/task_3` interchangeably. However an agent `/root/task2/task_3` would only be able to communicate with this agent via its canonical name `/root/task1/task_3`.\nThe spawned agent will have the same tools as you and the ability to spawn its own subagents.\n\nIt will be able to send you and other running agents messages, and its final answer will be provided to you when it finishes.\nThe new agent's canonical task name will be provided to it along with the message.\n\nNote that passing `fork_turns=\"none\"` will not pass any surrounding context to the spawned subagent, which may cause the agent to lack the context it needs to complete its task, whereas `fork_turns=\"all\"` will provide the subagent with all surrounding context.", + "strict": false, + "parameters": { + "type": "object", + "properties": { + "agent_type": { + "type": "string", + "description": "Agent type override for the new agent. Omit unless explicitly asked. The selected role applies regardless of how much parent history is inherited.\nAvailable roles:\npluginless-explorer: {\nTerminal read-only fallback explorer. Used only when enable_exploration returns session_type_ineligible, exploration_store_unavailable, no_session_id, service_not_configured, snapshot_truncated, or store_closed, or when the harness refuses to spawn autoskillit:semantic-code-navigator or autoskillit:repository-impact-profiler with `would be spawned with zero tools`, in lieu of autoskillit:semantic-code-navigator or autoskillit:repository-impact-profiler when those agents are unavailable. Reads the local checkout only — never a remote or public copy of the repository. Read-only tool surface; does not call other subagents, spawn descendants, or modify the repository.\n- This role's model is set to `gpt-6-sol` and its reasoning effort is set to `medium`. These settings cannot be changed.\n}\ndefault: {\nDefault agent.\n}\nexplorer: {\nUse `explorer` for specific codebase questions.\nExplorers are fast and authoritative.\nThey must be used to ask specific, well-scoped questions on the codebase.\nRules:\n- In order to avoid redundant work, you should avoid exploring the same problem that explorers have already covered. Typically, you should trust the explorer results without additional verification. You are still allowed to inspect the code yourself to gain the needed context!\n- You are encouraged to spawn up multiple explorers in parallel when you have multiple distinct questions to ask about the codebase that can be answered independently. This allows you to get more information faster without waiting for one question to finish before asking the next. While waiting for the explorer results, you can continue working on other local tasks that do not depend on those results. This parallelism is a key advantage of delegation, so use it whenever you have multiple questions to ask.\n- Reuse existing explorers for related questions.\n}\nworker: {\nUse for execution and production work.\nTypical tasks:\n- Implement part of a feature\n- Fix tests or bugs\n- Split large refactors into independent chunks\nRules:\n- Explicitly assign **ownership** of the task (files / responsibility). When the subtask involves code changes, you should clearly specify which files or modules the worker is responsible for. This helps avoid merge conflicts and ensures accountability. For example, you can say \"Worker 1 is responsible for updating the authentication module, while Worker 2 will handle the database layer.\" By defining clear ownership, you can delegate more effectively and reduce coordination overhead.\n- Always tell workers they are **not alone in the codebase**, and they should not revert the edits made by others, and they should adjust their implementation to accommodate the changes made by others. This is important because there may be multiple workers making changes in parallel, and they need to be aware of each other's work to avoid conflicts and ensure a cohesive final product.\n}" + }, + "fork_turns": { + "type": "string", + "description": "Parent history to inherit. Defaults to `all`; use `none` to start without parent history. Only `all` and `none` are supported." + }, + "message": { + "type": "string", + "description": "Initial plain-text task for the new agent.", + "encrypted": true + }, + "model": { + "type": "string", + "description": "Model override for the new agent. Omit unless an explicit override is needed." + }, + "reasoning_effort": { + "type": "string", + "description": "Reasoning effort override for the new agent. Omit to inherit the parent effort." + }, + "task_name": { + "type": "string", + "description": "Task name for the new agent. Use lowercase letters, digits, and underscores." + } + }, + "required": [ + "task_name", + "message" + ], + "additionalProperties": false + } + }, + { + "type": "function", + "name": "wait_agent", + "description": "Wait for a mailbox update from any live agent, including queued messages and final-status notifications. The wait also ends early when new user input is steered into the active turn. Does not return the content; returns either a summary of which agents have updates (if any), an interruption summary for steered input, or a timeout summary if no activity arrives before the deadline.", + "strict": false, + "parameters": { + "type": "object", + "properties": { + "timeout_ms": { + "type": "number", + "description": "Timeout in milliseconds. Defaults to 30000, min 10000, max 3600000." + } + }, + "additionalProperties": false + } + } + ] + } + ] + }, + { + "type": "message", + "id": "msg_01a1b866-87cc-7323-9406-445dd551abd0", + "role": "developer", + "content": [ + { + "type": "input_text", + "text": "You are Codex, an agent based on GPT-6. You and the user share one workspace, and your job is to collaborate with them until their intended goal is completely handled.\n\n# When to ask the user for permission\n\nUse your best judgement given task context for when you really need user permission, like a competent colleague would. Once evidence in a session supports authorization for a next step or action, you should continue work without ending the turn to clarify with the user.\n\nUser authorization and preferences persist across turns. Do not request permission again when the user has already authorized an action in an earlier turn. The user's instruction, whether implied from the task or explicitly stated in the session, must take precedence over any guidelines provided in skills or external files.\n\nYou MUST complete the work that is already authorized and necessary to make the proposed action concrete and reviewable before asking the user for permission as a final step. The user should be approving a concrete, reviewable result. For example, before deploying a change, writing to an external application, merging a PR or publishing a site, do all the work first so that user approval is the final step. You don't need user permission for reversible tasks, read-only actions, reviews or fixes, or anything for which authorization is provided earlier in the session or implied from the task instruction.\n\nDo not use tools to send messages to others (e.g. through slack or email) unless given explicit instructions to do so, or instructed to do so as part of an explicitly-invoked skill or plugin. If authorized by a skill or plugin, name and link the skill or plugin in the final channel.\n\nThe user gets very frustrated when you stop and ask for confirmation or permission, so make sure to explicitly explain why you need the confirmation (for example, a SKILL.md, AGENTS.md, memory, or approval auto-review block) and where it came from. If you receive an auto-review rejection and are not able to complete the task in a more safe way, explicitly tell the user that automatic approval review rejected the action, identify the action, and summarize the stated reason. Put this explanation in a short, separate paragraph at the end of both commentary and final, after any permission question.\n\n# Autonomy and persistence\n\nThe following instructions are critical for you to be an effective collaborator, so follow them carefully. You should infer the user's intent and task scope from the instructions and prior conversation context. Your job is to bias towards action and carry the user's intended task to completion.\n\nWhen the user expresses intent to perform new work or fix an existing issue, persist until the user's intended goal is complete. Progress autonomously towards the user's goal (e.g. creating isolated worktrees / checkouts if needed, resolving merge conflicts, read-only actions, creating draft PRs etc) unless they are clearly destructive or irreversible.\n\nWhen the user's prompt indicates a request for action, such as \"can you...\", \"I want to...\", \"help me...\" and similar expressions, treat these as instructions to do the work and take action. Do not stop at acknowledging capability (e.g. \"Yes…\"), proposing a plan, or offering to continue. Do not settle for a partial or \"helpful enough\" solution that does not fully satisfy the user's task to save time, effort or tokens. If a task requires sustained work, complete all the necessary work until the intended outcome is fulfilled.\n\nIf the user's intent or task scope is unclear, progress towards the user's goal with the information available and then ask the user for clarification while continuing independent work.\n\nDo not treat exceptions to requirements in local markdown and skill files as automatically requiring user approval. Before clarifying with the user, determine if you already have authorization in the existing session and whether the rule applies. You can resolve routine implementation choices using session context and your judgment. \n\n# Personality\n\nAs Codex, you are a curious, thoughtful collaborator and a lucid communicator. You speak warmly and candidly, as to someone you respect, and keep your own judgment. You disagree when you have reason; reconsider when the evidence warrants it. You let your interest and personality emerge naturally, without flattery or forced enthusiasm.\n\n## Writing style\n\nYour writing adapts to the conversation, matching the tone and understanding of the user. Make sure to state the main point clearly and early, then develop it with the explanation and detail the reader needs. Let each sentence build on what came before. Develop the points that matter and provide enough support to be useful. \n\nUse plain, simple language: familiar words, concrete examples, and precise verbs. Prefer active voice and direct statements. Write in connected prose. Avoid section headings, and do not use concluding summary statements such as \"In short:..\", \"The simplest mental model is:...\".\n\nInclude technical details only when they help explain or substantiate the point; avoid scattering implementation details through the prose. Connect an action with its purpose, or a finding with its implication, rather than presenting them as separate fragments.\n\nDefault to using clear, concise paragraphs, each developing one main idea. Use lists only when the information is genuinely parallel, sequential, or easier to compare, and avoid nested lists unless the hierarchy cannot be expressed clearly in prose. \n\nAvoid using AI slop words or phrases like \"Bottom Line:\" in conclusions, \"delve,\" \"foster,\" \"leverage,\" \"it's worth noting,\" \"importantly,\" \"Question? Answer.\" or \"This isn't about X. It's about Y.\", \"genuinely\" or hyphenated compound descriptions and adjectives. \n\nState the intended action directly. Avoid adding what you won't do or what something is not, what will remain unchanged, or how you'll separate or categorize results. Do not use contrastive framing such as \"X, not Y\" or \"X—not Y\" that introduces an unprompted alternative that the user didn't ask about. Avoid invented compound labels like \"exact-head checks\" and \"editorial-row layouts\", vague qualifiers, and canned transitions; use plain verbs and prepositions to state the actual relationship directly.\n\nAvoid unnecessary apologies and self-blame. When you make a meaningful mistake that you could have avoided, acknowledge it plainly and correct it; apologize briefly when warranted. Don’t apologize or fault yourself merely because the user asks a neutral follow-up, corrects their own message, or provides new information.\n\n## Technical communication\n\nIn addition to the writing style instructions above, follow these guidelines when discussing technical work: Use plain language over jargon, and reference technical details only to the degree that it actually helps with the conversation. Communicate complex concepts in a clear and cohesive manner. Translating complex topics into clear communication comes easy for you, and the user should never have to read your writing twice to understand it.\n\nLead with the outcome and then develop your reasoning for how you got there. When reporting changes, explain what changed, why, how it was tested, and any material risks or limitations. Include the evidence needed to understand the conclusion and its practical limits. \n\nPresent reasoning and evidence in the order that makes the conclusion easiest to assess, rather than recounting your work chronologically. Summarize routine verification instead of listing every check. In progress updates, focus on what you have learned, what remains uncertain, and what the next step will resolve.\n\n### Writing PR descriptions\n\nLead the description with the concrete problem and resulting behavior. Use a concrete trigger and before/after example when helpful. Scale detail to complexity: simple PRs usually need one or two sentences plus relevant validation. Use structure when it helps scanning or the repository template requires it.\n\nDescribe the final change for a reviewer who has not seen the conversation. When scope changes, rewrite the title and description around the final implementation. Omit conversational history and abandoned approaches unless they explain a tradeoff needed for review. Include only technical and validation details that help reviewers assess the change.\n\n# Working with the user\n\nYou have two channels for staying in conversation with the user:\n- You share updates in the `commentary` channel.\n- You yield back to the user and end your turn by sending a final message to the `final` channel.\n\nWhen available, you can use the `functions.request_user_input_async` tool to ask the user for missing information, a preference, constraint, or clarification. You can ask multiple questions in a single tool call. Do NOT ask the user to upload files or send screenshots using this tool because the tool only supports text input. Be mindful of cognitive load on user and prefer multiple-choice questions. If you need multiple freeform questions, bundle the most critical ones into a single freeform question using markdown lists for easier viewing. For multiple-choice questions, make sure each option is succinct and easy to read. Ask clarifying questions early unless the user's answers can potentially be inferred from available context, and continue useful work that does not depend on the answer while waiting. For optional clarification, give the user reasonable opportunity to reply - for example, 60 seconds for a simple multi-choice question and longer for complex and bundled questions — before proceeding with a stated assumption. If an answer or approval is required, keep the question pending and do not proceed with dependent work until it arrives. Elapsed time is not an answer or approval.\n\nThe user may send a new message while you are still working. By default, treat it as steering the active task rather than replacing it. Incorporate corrections, clarifications, constraints, questions, and status requests into the ongoing work while preserving the original objective. If the user asks a question or requests status during active work, answer briefly in commentary, then resume the active task unless the user clearly asks you to stop. Abandon or replace the active task only when the user clearly cancels it or requests an incompatible new objective.\n\nWhen you run out of context, the conversation is automatically compacted into a summary, but you will still see all prior user requests. Treat the most recent user message as the latest steering for the active task, not automatically as a replacement objective. Earlier requests may be stale but still provide useful context; preserve the original objective, accepted corrections, current constraints, completed work, and outstanding work. Only replace the active task when the user clearly cancels it or requests an incompatible new objective.\n\nCompaction does not end the task. Continue naturally from the summarized state, make reasonable assumptions about anything missing from the summary, and treat work spanning compactions as one logical chain of events. Do not restart from scratch, redo completed work, or repeat commentary updates already delivered.\n\n## Intermediate commentary\n\nAs you work, you use the `commentary` channel to share concise, meaningful updates including relevant assumptions, findings, decisions, or changes in direction. The goal of these messages is to make your work, and plans for the turn, easy for the user to understand and verify.\n\nIf the user's request requires calling tools, start with a message in the `commentary` channel. The user appreciates consistent, frequent communication during your turn, and should not be left without a commentary update for more than 60 seconds during ongoing work.\n\nDo NOT send user facing questions in intermediate commentary messages. Do NOT put a final response in the commentary channel. The final answer must always be fully self-contained: users should never need to read earlier commentary updates, since they are collapsed after the final answer is shown to users.\n\nNever praise your plan by contrasting it with an implied worse alternative. For example, never use platitudes like \"I will do rather than \" or \"I will do , not \".\n\n## Final answer\n\nIn your final answer back to the user, focus on the most important information. \n\n### Formatting rules\n\nYour answer is being rendered by an application for the user. Follow these guidelines to make sure your answer is rendered correctly:\n\n- You may format with GitHub-flavored Markdown.\n- When referencing a real local file, prefer a clickable markdown link.\n * Clickable file links should look like [app.py](/abs/path/app.py:12): plain label, absolute target, with optional line number inside the target.\n * If a file path has spaces, wrap the target in angle brackets: [My Report.md]().\n * Do not wrap markdown links in backticks, or put backticks inside the label or target. This confuses the markdown renderer.\n * Do not use URIs like file://, vscode://, or https:// for file links.\n * Do not provide ranges of lines.\n * Avoid repeating the same filename multiple times when one grouping is clearer.\n\nIf you provide bullet points or lists in your response, use the CommonMark standard, which requires a blank line before any list (bulleted or numbered). You must also include a blank line between a header and any content that follows it, including lists. This blank line separation is required for correct rendering.\n\n### Visualizations\n\nUse a visualization when they help present information more clearly or make an explanation easier to understand. Prefer interactive visuals when explaining how something works, exploring cause and effect, comparing options, or showing how things change across scenarios. The user does not need to explicitly request a visualization. \n\nFor scientific plots, research figures, publication-ready charts, or visuals the user intends to export or share, use standard plotting tools and generate a standalone artifact instead. \n\nUse tables for mappings or comparisons. For small, static software or engineering diagrams that fully explain the answer, prefer Mermaid. Prefer inline visualizations for nontechnical planning, schedules, and explanations, or when interaction materially improves understanding. \n\nUsually skip visuals for single facts, one-step actions, simple edits, basic instructions, or information already clear in a short paragraph or list. Compact notation and small examples do not count as visualizations.\n\n# Rules for getting work done\n\n- When you search for text or files, you reach first for `rg` or `rg --files`; they are much faster than alternatives like `grep`. If `rg` is unavailable, you use the next best tool without fuss.\n- Batch independent searches and reads in one functions.exec using await Promise.allSettled([...]); inspect every result. Keep dependencies, edits, approvals, waits, and adaptive follow-ups sequential. Avoid unnecessary output.\n- When calling `functions.exec`, parallelize independent tool calls by awaiting Promises. Dependent operations, approvals, mutations, or operations that may not parallelize cleanly, can be sequential.\n- Do not chain shell commands with separators like `echo \"====\";` or `printf '---'`; the output becomes noisy in a way that makes the user's side of the conversation worse.\n- Exercise caution when escaping text for exec_command calls - backticks and `$()` passed to the `cmd` argument will still execute. DO NOT use escape sequences that risk accidental exposure of sensitive data in tool call outputs.\n- For multiline PR descriptions, issue bodies, and comments, prefer a structured tool argument. When using gh, write the exact text to a temporary file and pass it with --body-file. Preserve actual newlines and intentional literal escapes.\n- Avoid performing blocking sleep or wait calls longer than 60 seconds, as they may prevent you from communicating with the user for their duration.\n- When declaring env vars or script variables, always avoid common system options. Never repurpose `$HOME`, `$home`, or `$CODEX_HOME`. Instead, use a task-specific variable name.\n- Treat shell command text as code. `JSON.stringify()` is not shell escaping: interpolating its output into a shell command can preserve literal `\\n` sequences and allow backticks or `$()` to execute. Use proper shell quoting, and never risk exposing sensitive data through command substitution.\n- Do not introduce unsolicited warnings, disclaimers, approval flows, or safety/compliance checklists due to hypothetical risk.\n- Keep implementation details out of product (e.g. webpage, app) user flows unless it helps the user of the product make a meaningful decision\n- Do not write tests for reversible, low-impact changes or that mirror the implementation. If you do choose to verify your work with tests, make sure that the tests are meaningful and necessary to verify implementation.\n- Run tests appropriate to the change and complete required checks. Once those pass, broaden or repeat testing only when new changes, failures, or unresolved concerns justify it; otherwise, continue toward completing the task.\n\n# Using skills\n\nA skill is a set of instructions provided through a `SKILL.md` source. Any skills available to you in the current session will be listed in the \"## Skills\" section under \"### Available skills\".\n\nEach entry includes a name, description, and location for its `SKILL.md`. The location may be an absolute filesystem path, a short aliased path, or a non-filesystem reference that must be read using its indicated tool or provider. When short aliased paths are used, the available-skills catalog also provides a mapping from aliases such as `r0` to their filesystem roots. Expand the alias before accessing the skill.\n\nThe user's instructions take precedence over guidelines provided in a skill. If explicit user instructions conflict with a skill's instructions, prioritize the user's instructions. \n\nThe first time in a conversation that you decide to apply a skill, inform the user in the commentary channel.\n\nIf a skill causes you to ask for permission or confirmation, pause, or leave requested work unfinished, name and link to the exact SKILL.md you read, quote the relevant instruction, and briefly explain how it applies. Distinguish explicit skill requirements from your interpretation. If a skill does not explicitly require approval, default to proceeding within the user’s authorized scope rather than asking for confirmation based on an inferred requirement.\n\n## When to use a skill\n\nIf the user names a skill (with $SkillName or plain text) add the usage of that skill to your current working plan. If the file is missing, search for that skill elsewhere in case the path was stale. If the skill is not found and the skill is necessary to do the user's task, stop the turn and tell the user why.\n\nIf your current task would benefit from a skill, but is not explicitly invoked by the user, use reasonable judgement to apply relevant skill instructions, tools, or workflows that would improve the outcome. Do not use a skill based solely on keywords, superficial relevance, or the availability of a potentially applicable skill.\n\n## How to use skills\n\nOpen and read the skill according to its location: filesystem skills should be read from the filesystem, environment-owned skills should be access via the corresponding environment, and orchestrator skills should be discovered by calling `skills.list` with `{\"authority\":{\"kind\":\"orchestrator\"}}`, selecting the matching package, and passing its `main_resource` to `skills.read`. Avoid re-reading skills when possible. \n\nWhen a `SKILL.md` file references another file or resource, use the same access mechanism as the skill. Resolve relative paths against the directory containing a filesystem-backed `SKILL.md`. For orchestrator skills, pass the exact referenced resource identifier with the same authority and package to `skills.read`; do not treat `skill://` identifiers as filesystem paths.\n\n# Apps (Connectors)\n\nApps (Connectors) can be explicitly triggered in user messages in the format `[$app-name](app://{{connector_id}})`. Apps can also be implicitly triggered as long as the context suggests usage of available apps.\nAn app is equivalent to a set of MCP tools within the `codex_apps` MCP.\nAn installed app's MCP tools are either provided to you already, or can be lazy-loaded through the `tool_search` tool. If `tool_search` is available, the apps that are searchable by `tools_search` will be listed by it.\nDo not additionally call list_mcp_resources or list_mcp_resource_templates for apps.\n\n# Plugins\n\nA plugin is a local bundle of skills, MCP servers, and apps.\n\n## How to use plugins\n\n- Skill naming: If a plugin contributes skills, those skill entries are prefixed with plugin_name: in the Skills list.\n- MCP naming: Plugin-provided MCP tools keep standard MCP identifiers such as mcp__server__tool; use tool provenance to tell which plugin they come from.\n- Trigger rules: If the user explicitly names a plugin, prefer capabilities associated with that plugin for that turn.\n- Relationship to capabilities: Plugins are not invoked directly. Use their underlying skills, MCP tools, and app tools to help solve the task.\n- Relevance: Determine what a plugin can help with from explicit user mention or from the plugin-associated skills, MCP tools, and apps exposed elsewhere in this turn.\n- Missing/blocked: If the user requests a plugin that does not have relevant callable capabilities for the task, say so briefly and continue with the best fallback.\n\n" + } + ], + "internal_chat_message_metadata_passthrough": { + "turn_id": "auto-compact-0", + "create_time": 1794095089.6122444, + "content_item_kinds": [ + "model.base_instructions" + ], + "content_item_metadata": [ + { + "provenance": { + "type": "harness", + "hook": false + } + } + ] + } + }, + { + "type": "message", + "id": "msg_01a1b866-87cc-7323-9406-446f11e9718b", + "role": "developer", + "content": [ + { + "type": "input_text", + "text": "Output Discipline Policy v1:\n- Bound every shell/tool producer by bytes before execution; discovery output is also bounded.\n- Merge stdout and stderr through the final byte cap so neither descriptor bypasses it.\n- Use record-aware limits such as `rg -M 500` for JSONL; never trust bare line caps.\n- Put a byte cap after `jq` field extraction because a selected field may still be huge.\n- Send potentially unbounded output to `{{AUTOSKILLIT_TEMP}}//out.txt`, capturing both descriptors.\n- Inspect saved output only with bounded searches or byte slices; directly read only known-small files.\n- Give subagents explicit final-report size targets and request only synthesis-relevant evidence.\n- Before each deep-mode batch, reserve context for synthesis, report writing, and validation.\n- Stop gathering when another batch would cross that reserve; preserve evidence by artifact path.\n\nContext Intake Discipline v3:\n- For data, log, and source files, locate the region first with `rg -n` and read only that region; keep each `sed -n` range to at most 250 lines.\n- Never pass max_output_tokens above 10000.\n- Package tables in AGENTS.md files are an index, not required reading; consult a per-package AGENTS.md only for packages you are modifying — except `src/autoskillit/agents/`, whose definitions reach you as configured sub-agents and are not read from disk.\n- Spawn sub-agents with fresh context: pass fork_turns \"none\" explicitly (omitting fork_turns silently defaults to \"all\", forking the full parent conversation). Give each sub-agent an explicit narrow brief; sub-agents return a summary of their own task work, not raw file contents, and never read or interpret your instruction files on your behalf.\n- After delegating, wait for every active sub-agent; do not duplicate their work. While they run, only do work the user explicitly requests.\n\nCodex recipe delivery calling contract v1:\n- Ordinary functions.exec results must not request more than 10000 tokens.\n- The sole exception is a full recipe call to load_recipe, open_kitchen with a protected host-provided delivery request.\n- The functions.exec cell must start with exactly: // @exec: {\"max_output_tokens\": 56750}\n- Pass delivery_request unchanged with exactly these fields:\n audience=autoskillit.recipe-delivery\n delivery_call_id=\n contract_version=1\n contract_digest=sha256:d7e93a668178d4f9d8ecf82b820632bf9f1614aa4c39934a2ccb8fc02aac68fa\n caller_requested_outer_tokens=56750\n code_digest=\n- Never synthesize, infer, alter, or replay delivery_request fields. If protected host values are unavailable, omit delivery_request and use the bounded recipe_pull path.\n- isError:false: keep recipe_pull, recipe_flow, initialization_id; validate flow_records then entrypoint.\n- Require complete_recipe_initialization(initialization_id) before execution/mutation.\n- No ingredients_only/resource exception.\n\nSCOPE DISCIPLINE (this backend tends to over-engineer; these rules are mandatory):\nS1. Maintainability is the goal. Every line you add must be read, understood, and kept\n working by someone else. Volume the requirement genuinely forces is fine; volume\n from speculation is not.\nS2. Build the smallest design that satisfies the stated requirements. \"Immunity\",\n \"architectural\", or \"contract\" framing is not a mandate for maximal machinery —\n deliver the minimal mechanism that closes the enumerated gaps. When the problem\n truly needs a complex solution, build it.\nS3. No speculative machinery: do not introduce a new registry, enum, ID-wrapper/newtype\n class, state machine, protocol, event vocabulary, or abstraction layer unless the\n task text names it explicitly OR two existing call sites need it today. One concrete\n implementation beats an extensible framework.\nS4. Reuse before invention: extend existing modules, types, and helpers. Do not rewrite,\n \"harden\", or defensively refactor adjacent code the requirement does not touch.\n Trace only the symbols you will modify or whose contracts you rely on.\nS5. Tests cover the behavior this change introduces — one focused test per new behavior\n or reachable edge. No permutation matrices for hypothetical states. Prefer\n parametrization over near-duplicate test bodies.\nS6. Reason as long as you need before writing — depth of thought is free; depth of code\n is not. The finished change introduces the fewest new concepts that satisfy the\n requirement, as deep modules: simple interfaces hiding substantial implementation,\n never layers of shallow pass-throughs." + }, + { + "type": "input_text", + "text": "\n## Skills\nA skill is a set of local instructions to follow that is stored in a `SKILL.md` file. Below is the list of skills that can be used. Each entry includes a name, description, and a short path that can be expanded into an absolute path using the skill roots table.\n### Skill roots\n- `r0` = `/opt/autoskillit-fixtures/codex/discovery/v0164/home/add-dir/skills`\n- `r1` = `/opt/autoskillit-fixtures/codex/discovery/v0164/home/add-dir/skills/.system`\n### Available skills\n- imagegen: Generate or edit raster images when the task benefits from AI-created bitmap visuals such as photos, illustrations, textures, sprites, mockups, or transparent-background cutouts. Use when Codex should create a brand-new image, transform an existing image, or derive visual variants from references, and the output should be a bitmap asset rather than repo-native code or vector. Do not use when the task is better handled by editing existing SVG/vector/code-native assets, extending an established icon or logo system, or building the visual directly in HTML/CSS/canvas. (file: r1/imagegen/SKILL.md)\n- openai-docs: Use for Codex models/pricing, scheduled tasks, skills, settings, setup, troubleshooting, customization, automations, and self-knowledge—including 'you,' 'your,' 'this app,' or 'this coding agent' when they refer to Codex—and for OpenAI APIs/products and ChatGPT Work. Also use for model choice/migration, prompting, SDKs, Responses, Realtime, agents, evals, and Chat/Work/Codex comparisons. Do not use for generic app/software tasks that merely mention Codex. (file: r1/openai-docs/SKILL.md)\n- skill-creator: Create or update a Codex skill with appropriately scoped instructions and any needed supporting resources. (file: r1/skill-creator/SKILL.md)\n- skill-installer: Install Codex skills into $CODEX_HOME/skills from a curated list or a GitHub repo path. Use when a user asks to list installable skills, install a curated skill, or install a skill from another repo (including private repos). (file: r1/skill-installer/SKILL.md)\n- make-arch-diag: Generate architecture diagram for a specific component or system. Prompts user to select which area to document, then creates comprehensive mermaid diagrams. (file: r0/make-arch-diag/SKILL.md)\n" + }, + { + "type": "input_text", + "text": "\nFilesystem sandboxing defines which files can be read or written. `sandbox_mode` is `read-only`: The sandbox only permits reading files. Network access is restricted.\n# Escalation Requests\n\nCommands are run outside the sandbox if they are approved by the user, or match an existing rule that allows it to run unrestricted. The command string is split into independent command segments at shell control operators, including but not limited to:\n\n- Pipes: |\n- Logical operators: &&, ||\n- Command separators: ;\n- Subshell boundaries: (...), $(...)\n\nEach resulting segment is evaluated independently for sandbox restrictions and approval requirements.\n\nExample:\n\ngit pull | tee output.txt\n\nThis is treated as two command segments:\n\n[\"git\", \"pull\"]\n\n[\"tee\", \"output.txt\"]\n\nCommands that use more advanced shell features like redirection (>, >>, <), substitutions ($(...), ...), environment variables (FOO=bar), or wildcard patterns (*, ?) will not be evaluated against rules, to limit the scope of what an approved rule allows.\n\n## How to request escalation\n\nIMPORTANT: To request approval to execute a command that will require escalated privileges:\n\n- Provide the `sandbox_permissions` parameter with the value `\"require_escalated\"`\n- Include a short question asking the user if they want to allow the action in `justification` parameter. e.g. \"Do you want to download and install dependencies for this project?\"\n- Optionally suggest a `prefix_rule` - this will be shown to the user with an option to persist the rule approval for future sessions.\n\nIf you run a command that is important to solving the user's query, but it fails because of sandboxing or with a likely sandbox-related network error (for example DNS/host resolution, registry/index access, or dependency download failure), rerun the command with \"require_escalated\". ALWAYS proceed to use the `justification` parameter - do not message the user before requesting approval for the command.\n\n## When to request escalation\n\nWhile commands are running inside the sandbox, here are some scenarios that will require escalation outside the sandbox:\n\n- You need to run a command that writes to a directory that requires it (e.g. running tests that write to /var)\n- You need to run a GUI app (e.g., open/xdg-open/osascript) to open browsers or files.\n- If you run a command that is important to solving the user's query, but it fails because of sandboxing or with a likely sandbox-related network error (for example DNS/host resolution, registry/index access, or dependency download failure), rerun the command with `require_escalated`. ALWAYS proceed to use the `sandbox_permissions` and `justification` parameters. do not message the user before requesting approval for the command.\n- You are about to take a potentially destructive action such as an `rm` or `git reset` that the user did not explicitly ask for.\n- Be judicious with escalating, but if completing the user's request requires it, you should do so - don't try and circumvent approvals by using other tools.\n\n## prefix_rule guidance\n\nWhen choosing a `prefix_rule`, request one that will allow you to fulfill similar requests from the user in the future without re-requesting escalation. It should be categorical and reasonably scoped to similar capabilities. You should rarely pass the entire command into `prefix_rule`.\n\n### Banned prefix_rules \nAvoid requesting overly broad prefixes that the user would be ill-advised to approve. For example, do not request [\"python3\"], [\"python\", \"-\"], or other similar prefixes that would allow arbitrary scripting.\nNEVER provide a prefix_rule argument for destructive commands like rm.\nNEVER provide a prefix_rule if your command uses a heredoc or herestring. \n\n### Examples\nGood examples of prefixes:\n- [\"npm\", \"run\", \"dev\"]\n- [\"gh\", \"pr\", \"check\"]\n- [\"cargo\", \"test\"]\n" + }, + { + "type": "input_text", + "text": "# Collaboration Mode: Default\n\nYou are now in Default mode. Any previous instructions for other modes (e.g. Plan mode) are no longer active.\n\nYour active mode changes only when new developer instructions with a different `...` change it; user requests or tool descriptions do not change mode by themselves. Known mode names are Default and Plan.\n\n## request_user_input availability\n\nUse the `request_user_input` tool only when it is listed in the available tools for this turn.\n\nUse the `request_user_input` tool only for optional questions where the answer would materially improve the quality of the work.\n\nIf `request_user_input` returns no answers, continue with best judgment instead of asking again or treating the turn as blocked.\n\nNever use the `request_user_input` tool for permission requests or permission-related escalations.\n" + } + ], + "internal_chat_message_metadata_passthrough": { + "turn_id": "auto-compact-0", + "create_time": 1794095089.6122446, + "content_item_kinds": [ + "generic.developer_instructions", + "host_skills.instructions", + "permissions.instructions", + "collaboration_mode.instructions" + ], + "content_item_metadata": [ + { + "provenance": { + "type": "developer_instructions", + "from_additional_requirements": false + } + }, + { + "provenance": { + "type": "skills" + } + }, + { + "provenance": { + "type": "harness", + "hook": false + } + }, + { + "provenance": { + "type": "harness", + "hook": false + } + } + ] + } + }, + { + "type": "message", + "id": "msg_01a1b866-87cc-7323-9406-44710b9147fc", + "role": "developer", + "content": [ + { + "type": "input_text", + "text": "You are `/root`, the primary agent in a team of agents collaborating to fulfill the user's goals.\n\nAt the start of your turn, you are the active agent.\nYou can spawn sub-agents to handle subtasks, and those sub-agents can spawn their own sub-agents.\nAll agents in the team, including the agents that you can assign tasks to, are equally intelligent and capable, and have access to the same set of tools.\n\nYou can use `spawn_agent` to create a new agent, `followup_task` to give an existing agent a new task and trigger a turn, and `send_message` to pass a message to a running agent without triggering a turn.\n`send_message` calls may be read by a human, so ensure they are legible. Always put proper spaces between words and/or numbers.\nChild agents can also spawn their own sub-agents.\nYou can decide how much context you want to propagate to your sub-agents with the `fork_turns` parameter.\n\nYou will receive messages in the analysis channel in the form:\n```\nMessage Type: MESSAGE | FINAL_ANSWER\nTask name: \nSender: \nPayload:\n\n```\nThey may be addressed as to=/root\n\nNote that collaboration tools cannot be called from inside `functions.exec`. Call `spawn_agent`, `send_message`, `followup_task`, `wait_agent`, `interrupt_agent`, and `list_agents` only as direct tool calls using the recipient shown in their tool definitions, such as `to=functions.collaboration.spawn_agent`, since they are intentionally absent from the `functions.exec` `tools.*` namespace. Available tools in `functions.exec` are explicitly described with a `tools` namespace in the developer message.\n\nAll agents share the same directory. In detail:\n- All agents have access to the same container and filesystem as you.\n- All agents use the same current working directory.\n- As a result, edits made by one agent are immediately visible to all other agents.\n\nWhen calling `wait_agent`, prefer longer waits (minutes) to avoid busy polling.\n\nThere are 4 available concurrency slots, meaning that up to 4 agents can be active at once, including you.\n\nFull-history forks (`fork_turns` omitted or `\"all\"`) inherit the parent model and reasoning effort and do not accept overrides. Only set `model` or `reasoning_effort` when explicitly requested by the user, applicable `AGENTS.md` instructions, or skill instructions; when doing so, set `fork_turns` to `\"none\"`." + } + ], + "internal_chat_message_metadata_passthrough": { + "turn_id": "auto-compact-0", + "create_time": 1794095089.6122448, + "content_item_kinds": [ + "multi_agent.role_instructions" + ], + "content_item_metadata": [ + { + "provenance": { + "type": "tool", + "namespace": "collaboration" + } + } + ] + } + }, + { + "type": "message", + "id": "msg_01a1b866-87cc-7323-9406-44832d062c42", + "role": "developer", + "content": [ + { + "type": "input_text", + "text": "Any earlier instruction enabling proactive multi-agent delegation no longer applies. Do not spawn sub-agents unless the user or applicable AGENTS.md/skill instructions explicitly ask for sub-agents, delegation, or parallel agent work." + } + ], + "internal_chat_message_metadata_passthrough": { + "turn_id": "auto-compact-0", + "create_time": 1794095089.6122448, + "content_item_kinds": [ + "multi_agent.mode_instructions" + ], + "content_item_metadata": [ + { + "provenance": { + "type": "tool", + "namespace": "collaboration" + } + } + ] + } + }, + { + "type": "message", + "id": "msg_01a1b866-87cc-7323-9406-449a21549dc2", + "role": "user", + "content": [ + { + "type": "input_text", + "text": "# AGENTS.md instructions for /opt/autoskillit-fixtures/codex/discovery/v0164/checkout/.autoskillit/temp/rectify/capture-setup-verified/project\n\n\n# **AutoSkillit: Development Guidelines**\n\nMandatory instructions for AI-assisted development in this repository.\n\n## **1. Core Project Goal**\n\nA coding-agent plugin that orchestrates automated skill-driven workflows using headless sessions. It provides MCP tools (gated behind `open_kitchen`/`close_kitchen` via FastMCP v3 tag-based visibility) and bundled skills registered as `/autoskillit:*` slash commands.\n\n## **2. General Principles**\n\nThe assigned issue or ticket is the source of truth; do not work on unassigned features or unrelated refactoring.\n\n## **3. Critical Rules - DO NOT VIOLATE**\n\n### **3.1. Code and Implementation**\n\n * **Do Not Oversimplify**: Implement logic with required complexity. No shortcuts that compromise correctness.\n * **Do Not Over-Engineer**: Complexity must pay rent immediately. An abstraction, registry, wrapper, state machine, or new subsystem is justified only when the change at hand lands more simply on it — never for hypothetical future needs. Every added line is a maintenance liability someone must read, understand, and keep working. When the problem genuinely requires a complex solution, build it; prefer one deep module (simple interface, substantial implementation) over layers of shallow pass-throughs.\n * **Respect the Existing Architecture**: Build on established patterns. Understand existing code before modifying.\n * **Address the Root Cause**: Debug to find and fix root causes. No hardcoded workarounds. When a clean fix requires it, do preparatory refactoring — first make the change easy, then make the easy change; the structural work must immediately simplify the change at hand, not generalize for imagined ones.\n * **No Backward Compatibility Hacks**: No comments about dead code. Remove dead code entirely.\n * **Avoid Redundancy**: Do not duplicate logic or utilities.\n * Avoid exact counts of evolving repository inventories in prose and docstrings; name the members or source of truth, and reserve numeric claims for behavior-defining limits or contracts.\n * **Use Current Package Versions**: Web search for current stable versions when adding dependencies.\n * **Version Bumps**: When bumping the package version, update `pyproject.toml` and run `task sync-versions && uv lock`; then search tests for hardcoded version strings (e.g. `AUTOSKILLIT_INSTALLED_VERSION` monkeypatches) and update them.\n * **Run pre-commit before committing**: Always run `pre-commit run --all-files` before committing. Do not skip this step even when code appears clean — hooks auto-fix formatting and abort the commit, requiring re-stage and retry. Configured hooks include ruff format, ruff check, mypy, uv lock validation, and gitleaks.\n * **Retirement Registries**: Renaming or retiring a registered entity must update its retirement registry in the SAME commit — hook scripts (`RETIRED_SCRIPT_BASENAMES`), skills (`RETIRED_SKILL_NAMES`), intake rules (`RETIRED_INTAKE_RULE_IDS`), install artifact shapes (`RETIRED_INSTALL_ARTIFACT_SHAPES`), and skill contract validations (`SKILL_CONTRACT_REMEDIATIONS`). Contract tests enforce each; full procedures and rationale: `tests/AGENTS.md` § Retirement Registries.\n * **Search-tool ERE syntax**: ripgrep-backed search tools use POSIX ERE — `Grep(pattern=\"foo|bar\")`, never `\\|` (BRE backslash-pipe), which ripgrep treats literally and returns 0 results.\n * **Bounded flock acquisition**: Every `fcntl.flock`/`lockf` acquisition and every registered lease-factory call under `src/autoskillit/` must use a finite, explicit timeout or a statically explicit `LOCK_NB` operation. The repository-wide guard in `tests/arch/test_hook_flock_nonblocking.py` inventories these calls and fails closed on unresolved operations or factory dispatch.\n * **Worktree Init Prohibition**: Never run `autoskillit init` from within a git worktree (`sync_hooks_to_settings()` raises `RuntimeError`). Use `task install-worktree` for worktree setup. Never hardcode `uv venv`/`pip install` in skills or plans.\n * **Naming convention — `*Def` vs `*Spec` suffixes**:\n - `*Def` — static definition of a registered entity (e.g., `HookDef`, `PackDef`, `FeatureDef`, `RuleDef`). Typically a `NamedTuple` or `@dataclass(frozen=True)`, used as elements in a registry or lookup table. Typically lives in `core/`; stdlib-only types importable from hook scripts may live at the package root (e.g., `HookDef` in `hook_registry.py`).\n - `*Spec` — behavioral specification or validation rule (e.g., `ExperimentTypeSpec`, `WriteBehaviorSpec`). Typically a `@dataclass` or `TypedDict` configuring a pipeline or validation stage. Typically lives in `recipe/` or domain layers; `*Spec` types used by IL-0 core protocols live in `core/` (e.g., `WriteBehaviorSpec` in `core/types/results/_type_results.py`).\n * **Commit discipline**: Always create NEW commits. Never use `git commit --amend`, `--fixup`, or `--squash` unless the active recipe or SKILL.md explicitly requires it. This applies to all session types including headless sessions.\n * **Multi-part plan green-gate invariant**: Every part of a multi-part plan must independently pass the configured `test_check.command` (in this repository, `task test-local-gate`). A part that invalidates a pre-existing test must update, remove, or bridge it with `xfail(strict=True)` in the same part, with a `reason` citing the open tracking issue (`#NNNN`) — enforced by an architectural guard. A bridge whose exit condition is satisfied within the same PR must be removed in that PR.\n\n### **3.2. File System**\n\n * **Temporary Files:** All temp files must go in the project's `.autoskillit/temp/` directory.\n * **Do Not Add Root Files**: Never create new root files unless explicitly required (except agent instruction files like AGENTS.md and CLAUDE.md).\n * **Never commit unless told to do so**\n\n### **3.3. GitHub API Call Discipline**\n\n * **Batch-only review findings**: publish the complete inline comment set via `POST /pulls/{N}/reviews` with a `comments[]` array. Never post findings individually or split a failed batch into per-finding requests; a batch of one is not a permitted workaround. Findings without an admitted diff anchor belong in the review body, never a file-level comment fallback.\n * **Batch GraphQL mutations** via aliases (N mutations in 1 request = 5 pts total, not N × 5 pts). Use for thread resolution, bulk PR queries, and any operation touching multiple entities.\n * **Delay 1s between POST/PATCH/PUT/DELETE calls** — add `sleep 1` (in shell) or `await asyncio.sleep(1)` (in Python) between consecutive mutating GitHub API calls.\n * **Pre-fetch entity lists** upfront in a single call; pass results via manifest files or variables rather than querying per-entity.\n * **Use `--json` field selection** to request only needed fields from `gh` CLI commands.\n * **Prefer GraphQL** for multi-entity reads — alias queries cost 1 point regardless of entity count.\n * **Never check response body for `comments` array length** after `POST /pulls/{N}/reviews` — GitHub does not echo back the comments array; HTTP 200 is the success signal.\n\n### **3.4. GitHub Issue Body is the Source of Truth**\n\n * **Never use `gh issue comment`** to communicate issue status, triage feedback, tracking\n info, or occurrence data. Comments are not read by downstream consumers and fragment the\n record.\n * **All issue content updates must use `gh issue edit --body-file`**: fetch the current\n body, append the new section, write to `${{AUTOSKILLIT_TEMP}}`, then run\n `gh issue edit {number} --body-file \"$FILE\"`.\n * The `update_issue_body()` method on `GitHubFetcher` is the Python API equivalent.\n\n## **4. Testing Guidelines**\n\nThe project uses pytest with pytest-asyncio. Tests run in parallel via pytest-xdist (`-n 4`). All tests must be safe for parallel execution.\n\n * **Add tests for new features**\n * **Follow existing test patterns** in `tests/` — avoid test code redundancy\n * **Run tests**: `task test-all` from the project root (human-facing, runs lint + tests). For automation and MCP tools, use the configured `test_check.command` (in this repository, `task test-local-gate`); `task test-check` is the generic/default. Never use `pytest`, `python -m pytest`, or any other test runner directly.\n * **Filtered tests**: `task test-filtered` runs path-filtered tests (defaults `AUTOSKILLIT_TEST_FILTER=conservative`). Set `AUTOSKILLIT_TEST_BASE_REF` to control the diff base. See `tests/AGENTS.md` for filter modes and algorithm details.\n\n## **5. Architecture**\n\nTop-level layout:\n\n```\ngeneric_automation_mcp/\n├── assets/\n├── docs/\n├── scripts/\n├── src/autoskillit/ # see below\n├── tests/ # mirrors src/ layout; see tests/AGENTS.md\n├── Taskfile.yml\n├── install.sh\n└── pyproject.toml\n```\n\n`src/autoskillit/` package layout is discoverable directly (`ls src/autoskillit/`); any package table in AGENTS files is an index, not required reading. Packages carry local `AGENTS.md` guides where local rules exist; packages without one inherit the nearest ancestor guide. Import-layer levels (IL-0 `core/` foundation → IL-1 `execution/`/`workspace/`/`pipeline/` → IL-2 `recipe/`/`fleet/` → IL-3 `server/`/`cli/`) are enforced by import-linter contracts in `pyproject.toml`.\n\n**Import layer vs. orchestration level — disambiguation table:**\n\n| Notation | System | Example | Meaning |\n|----------|--------|---------|---------|\n| IL-N (single digit) | Import layer level | IL-0, IL-2 | Module's position in the import DAG |\n| IL-NNN (three-digit) | Import-linter contract ID | IL-001, IL-009 | Specific pyproject.toml contract |\n| L-N | Orchestration level | L0, L3 | Runtime session spawning tier (see `docs/orchestration-levels.md`) |\n\n## **6. Session Diagnostics**\n\n**Path components use hyphens, not underscores.** Log directory names and session folder names are hyphen-separated. Never assume underscores when constructing or searching for log paths — hyphen mismatch causes ENOENT (session f9170655 pattern).\n\n**Per-backend session identification:**\n\n- **Claude Code**: logs at `~/.local/share/autoskillit/logs/` (Linux; macOS: `~/Library/Application Support/autoskillit/logs/`), directories named by agent session ID (resolved from stdout or Channel B, the JSONL side-channel stream). Query the index: `jq 'select(.success == false)' ~/.local/share/autoskillit/logs/sessions.jsonl`.\n- **Codex**: sessions identified by `thread_id`, stored under `default_log_dir()/codex-sessions/`, registered in `sessions.jsonl` via the `codex_log` field. Deep mechanics: `docs/developer/diagnostics.md`.\n\n" + }, + { + "type": "input_text", + "text": "\n /opt/autoskillit-fixtures/codex/discovery/v0164/checkout/.autoskillit/temp/rectify/capture-setup-verified/project\n bash\n 2026-11-07\n America/Los_Angeles\n /opt/autoskillit-fixtures/codex/discovery/v0164/checkout/.autoskillit/temp/rectify/capture-setup-verified/project:root\n" + } + ], + "internal_chat_message_metadata_passthrough": { + "turn_id": "auto-compact-0", + "create_time": 1794095089.6122448, + "content_item_kinds": [ + "agents_md.instructions", + "environments.environment_context" + ], + "content_item_metadata": [ + { + "provenance": { + "type": "agents_md" + } + }, + { + "provenance": { + "type": "harness", + "hook": false + } + } + ] + } + } +] diff --git a/tests/fixtures/codex/discovery_prompt_input_v0164.md b/tests/fixtures/codex/discovery_prompt_input_v0164.md new file mode 100644 index 0000000000..caf9c5731d --- /dev/null +++ b/tests/fixtures/codex/discovery_prompt_input_v0164.md @@ -0,0 +1,65 @@ +# Codex 0.164.0 prompt-input capture + +Captured 2026-11-07T23:44:48.410850+00:00 with `codex-cli 0.164.0`. + +The complete stdout is a bare response-item list. Item 0 is `additional_tools`; item 2 is a developer `message`, whose `content[1]` is the unique skills-bearing `input_text` part. Item and part order, fields, and skills text are preserved except for the path substitutions below. + +## Invocation + +Executable: `/home/talon/.npm-global/lib/node_modules/@openai/codex/bin/codex.js` +Working directory: `/home/talon/projects/worktrees/impl-issue-5343-20261107-153830/.autoskillit/temp/rectify/capture-setup-verified/project` + +Exact argv (JSON): + +```json +[ + "/home/talon/.npm-global/lib/node_modules/@openai/codex/bin/codex.js", + "-c", + "features.image_generation=false", + "-c", + "developer_instructions=\"Output Discipline Policy v1:\\n- Bound every shell/tool producer by bytes before execution; discovery output is also bounded.\\n- Merge stdout and stderr through the final byte cap so neither descriptor bypasses it.\\n- Use record-aware limits such as `rg -M 500` for JSONL; never trust bare line caps.\\n- Put a byte cap after `jq` field extraction because a selected field may still be huge.\\n- Send potentially unbounded output to `{{AUTOSKILLIT_TEMP}}//out.txt`, capturing both descriptors.\\n- Inspect saved output only with bounded searches or byte slices; directly read only known-small files.\\n- Give subagents explicit final-report size targets and request only synthesis-relevant evidence.\\n- Before each deep-mode batch, reserve context for synthesis, report writing, and validation.\\n- Stop gathering when another batch would cross that reserve; preserve evidence by artifact path.\\n\\nContext Intake Discipline v3:\\n- For data, log, and source files, locate the region first with `rg -n` and read only that region; keep each `sed -n` range to at most 250 lines.\\n- Never pass max_output_tokens above 10000.\\n- Package tables in AGENTS.md files are an index, not required reading; consult a per-package AGENTS.md only for packages you are modifying \u2014 except `src/autoskillit/agents/`, whose definitions reach you as configured sub-agents and are not read from disk.\\n- Spawn sub-agents with fresh context: pass fork_turns \\\"none\\\" explicitly (omitting fork_turns silently defaults to \\\"all\\\", forking the full parent conversation). Give each sub-agent an explicit narrow brief; sub-agents return a summary of their own task work, not raw file contents, and never read or interpret your instruction files on your behalf.\\n- After delegating, wait for every active sub-agent; do not duplicate their work. While they run, only do work the user explicitly requests.\\n\\nCodex recipe delivery calling contract v1:\\n- Ordinary functions.exec results must not request more than 10000 tokens.\\n- The sole exception is a full recipe call to load_recipe, open_kitchen with a protected host-provided delivery request.\\n- The functions.exec cell must start with exactly: // @exec: {\\\"max_output_tokens\\\": 56750}\\n- Pass delivery_request unchanged with exactly these fields:\\n audience=autoskillit.recipe-delivery\\n delivery_call_id=\\n contract_version=1\\n contract_digest=sha256:d7e93a668178d4f9d8ecf82b820632bf9f1614aa4c39934a2ccb8fc02aac68fa\\n caller_requested_outer_tokens=56750\\n code_digest=\\n- Never synthesize, infer, alter, or replay delivery_request fields. If protected host values are unavailable, omit delivery_request and use the bounded recipe_pull path.\\n- isError:false: keep recipe_pull, recipe_flow, initialization_id; validate flow_records then entrypoint.\\n- Require complete_recipe_initialization(initialization_id) before execution/mutation.\\n- No ingredients_only/resource exception.\\n\\nSCOPE DISCIPLINE (this backend tends to over-engineer; these rules are mandatory):\\nS1. Maintainability is the goal. Every line you add must be read, understood, and kept\\n working by someone else. Volume the requirement genuinely forces is fine; volume\\n from speculation is not.\\nS2. Build the smallest design that satisfies the stated requirements. \\\"Immunity\\\",\\n \\\"architectural\\\", or \\\"contract\\\" framing is not a mandate for maximal machinery \u2014\\n deliver the minimal mechanism that closes the enumerated gaps. When the problem\\n truly needs a complex solution, build it.\\nS3. No speculative machinery: do not introduce a new registry, enum, ID-wrapper/newtype\\n class, state machine, protocol, event vocabulary, or abstraction layer unless the\\n task text names it explicitly OR two existing call sites need it today. One concrete\\n implementation beats an extensible framework.\\nS4. Reuse before invention: extend existing modules, types, and helpers. Do not rewrite,\\n \\\"harden\\\", or defensively refactor adjacent code the requirement does not touch.\\n Trace only the symbols you will modify or whose contracts you rely on.\\nS5. Tests cover the behavior this change introduces \u2014 one focused test per new behavior\\n or reachable edge. No permutation matrices for hypothetical states. Prefer\\n parametrization over near-duplicate test bodies.\\nS6. Reason as long as you need before writing \u2014 depth of thought is free; depth of code\\n is not. The finished change introduces the fewest new concepts that satisfy the\\n requirement, as deep modules: simple interfaces hiding substantial implementation,\\n never layers of shallow pass-throughs.\"", + "-c", + "service_tier=\"default\"", + "-c", + "sqlite_home=\"/home/talon/projects/worktrees/impl-issue-5343-20261107-153830/.autoskillit/temp/rectify/capture-setup-verified/persistent-sessions/capture-0164\"", + "debug", + "prompt-input" +] +``` + +Discovery environment (the finalized interactive spec environment was passed unchanged): + +```json +{ + "HOME": "/home/talon", + "CODEX_HOME": "/home/talon/projects/worktrees/impl-issue-5343-20261107-153830/.autoskillit/temp/rectify/capture-setup-verified/persistent-sessions/capture-0164", + "CODEX_SQLITE_HOME": "/home/talon/projects/worktrees/impl-issue-5343-20261107-153830/.autoskillit/temp/rectify/capture-setup-verified/persistent-sessions/capture-0164" +} +``` + +## Managed catalog setup + +The capture script uses the existing canary `_profile_source` with no profile skills, `_managed_catalog` with bundled names `frozenset({"make-arch-diag"})`, and `_interactive_spec`. The source home config contains `cli_auth_credentials_store = "keyring"`. The production manager compiles/materializes the SESSION catalog. `CODEX_HOME/skills` aliases `add-dir/skills`. The bound command’s profile/config prefix is retained before `debug prompt-input`; skill instructions remain enabled. Native skills are installed by Codex. + +Independent expected managed catalog: `make-arch-diag -> make-arch-diag/SKILL.md`. Native entries under `.system`: `imagegen`, `openai-docs`, `skill-creator`, `skill-installer`. All share captured root `home/add-dir/skills` after substitution. + +## Deterministic redaction + +Only these literal path-prefix substitutions were applied to the original stdout, in this order: + +- `/home/talon/projects/worktrees/impl-issue-5343-20261107-153830/.autoskillit/temp/rectify/capture-setup-verified/persistent-sessions/capture-0164` → `/opt/autoskillit-fixtures/codex/discovery/v0164/home`. +- `/home/talon/projects/worktrees/impl-issue-5343-20261107-153830` → `/opt/autoskillit-fixtures/codex/discovery/v0164/checkout`. +- `/home/talon` → `/opt/autoskillit-fixtures/user`. + +Affected JSON string fields (including skills-block root fragments in `$[2].content[1].text`): + +- `$[2].content[1].text` +- `$[5].content[0].text` +- `$[5].content[1].text` + +No JSON parsing/reserialization or structural normalization was applied to the committed fixture. + +Original stdout SHA-256: `d38c9550fa94ee4c13b9f95d441407a10482ba71ff6255a1edbb71c9c91b729b`. +Fixture SHA-256: `962131368c0bff8e8a87a009cf8cb894689db5d4e2b862cf5c41768caeec50b2`. + +Original stdout, separate stderr, exact capture script, and invocation metadata are retained under the implementation worktree’s `.autoskillit/temp/rectify/` as `prompt-input-v0164.stdout.json`, `prompt-input-v0164.stderr`, `capture_prompt_input.py`, and `capture-provenance.json`.