From 2c5cf6042c85bcdc6c116b555cea7a3be9f45fc1 Mon Sep 17 00:00:00 2001 From: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> Date: Wed, 25 Nov 2026 09:11:00 +0800 Subject: [PATCH 1/3] canary(planner): modularize planner into zero-Any submodules Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> --- loopx/canary/catalog_markdown.py | 293 ++++ loopx/canary/core_domain_profiles.py | 487 ++++++ loopx/canary/family_profiles.py | 167 ++ loopx/canary/module_metric_baseline.json | 2 +- loopx/canary/planner.py | 1836 +++------------------ loopx/canary/workflow_domain_profiles.py | 600 +++++++ scripts/semantic_incident_retrodiction.py | 240 ++- 7 files changed, 1966 insertions(+), 1659 deletions(-) create mode 100644 loopx/canary/catalog_markdown.py create mode 100644 loopx/canary/core_domain_profiles.py create mode 100644 loopx/canary/family_profiles.py create mode 100644 loopx/canary/workflow_domain_profiles.py diff --git a/loopx/canary/catalog_markdown.py b/loopx/canary/catalog_markdown.py new file mode 100644 index 0000000000..0b433a7add --- /dev/null +++ b/loopx/canary/catalog_markdown.py @@ -0,0 +1,293 @@ +"""Markdown catalog parsing helpers and canary report renderers.""" + +from __future__ import annotations + +from collections.abc import Mapping, Sequence +import re + + +def mapping_list(payload: Mapping[str, object], key: str) -> list[Mapping[str, object]]: + """Return nested mapping items under ``key``, ignoring malformed entries.""" + + raw = payload.get(key) + if not isinstance(raw, Sequence) or isinstance(raw, (str, bytes, bytearray)): + return [] + return [item for item in raw if isinstance(item, Mapping)] + + +def string_list(payload: Mapping[str, object], key: str) -> list[str]: + """Return stringified sequence elements under ``key``.""" + + raw = payload.get(key) + if not isinstance(raw, Sequence) or isinstance(raw, (str, bytes, bytearray)): + return [] + return [str(item) for item in raw] + + +def slug(value: str) -> str: + """Normalize a human label into a lowercase kebab-case identifier.""" + + return re.sub(r"[^a-z0-9]+", "-", value.lower()).strip("-") + + +def catalog_profile_id(profile: Mapping[str, object]) -> str: + """Resolve the normalized identifier for a catalog or domain profile.""" + + return slug(str(profile.get("id") or profile.get("family") or "")) + + +def _split_table_row(line: str) -> list[str]: + return [cell.strip() for cell in line.strip().strip("|").split("|")] + + +def _parse_markdown_table(lines: list[str]) -> list[dict[str, str]]: + rows = [_split_table_row(line) for line in lines if line.strip().startswith("|")] + if len(rows) < 3: + return [] + headers = rows[0] + parsed: list[dict[str, str]] = [] + for row in rows[2:]: + if len(row) != len(headers): + continue + parsed.append({headers[index]: value for index, value in enumerate(row)}) + return parsed + + +def first_table_after(text: str, marker: str) -> list[dict[str, str]]: + """Parse the first markdown table appearing at or after ``marker``.""" + + index = text.find(marker) + if index < 0: + return [] + table_lines: list[str] = [] + in_table = False + for line in text[index:].splitlines(): + if line.strip().startswith("|"): + table_lines.append(line) + in_table = True + elif in_table: + break + return _parse_markdown_table(table_lines) + + +def pattern_ids(value: str) -> list[str]: + """Extract sorted unique ``IP-NNN`` pattern identifiers from text.""" + + return sorted(set(re.findall(r"\bIP-\d{3}\b", value))) + + +def split_semicolon(value: str) -> list[str]: + """Split semicolon-delimited items and omit blank entries.""" + + return [item.strip() for item in value.split(";") if item.strip()] + + +def catalog_pattern_rows(text: str) -> list[dict[str, str]]: + """Extract interaction-pattern metadata rows from the catalog markdown.""" + + rows: list[dict[str, str]] = [] + for line in text.splitlines(): + if not line.strip().startswith("|"): + continue + cells = _split_table_row(line) + if len(cells) < 3: + continue + if cells[0] not in {"P0", "P1", "P2"} or not re.fullmatch(r"IP-\d{3}", cells[1]): + continue + rows.append( + { + "importance": cells[0], + "pattern_id": cells[1], + "name": cells[2], + } + ) + return rows + + +def coverage_exception_rows(text: str) -> dict[str, dict[str, str]]: + """Parse documented canary coverage exceptions indexed by pattern ID.""" + + table = first_table_after(text, "| Pattern ID | Canary Coverage Status |") + exceptions: dict[str, dict[str, str]] = {} + for row in table: + pattern_id = next(iter(pattern_ids(row.get("Pattern ID", ""))), "") + if not pattern_id: + continue + status = slug(row.get("Canary Coverage Status", "")) + if status not in {"non-applicable", "not-applicable", "deferred"}: + continue + exceptions[pattern_id] = { + "pattern_id": pattern_id, + "status": "non-applicable" if status == "not-applicable" else status, + "rationale": row.get("Rationale", ""), + "owner": row.get("Owner", ""), + } + return exceptions + + +def coverage_exception_is_valid(exception: Mapping[str, str]) -> bool: + """Return whether a coverage exception supplies required rationale/owner fields.""" + + status = exception.get("status") + rationale = bool(str(exception.get("rationale") or "").strip()) + owner = bool(str(exception.get("owner") or "").strip()) + if status == "non-applicable": + return rationale + if status == "deferred": + return rationale and owner + return False + + +def _format_archetypes(profile: Mapping[str, object]) -> str: + return ", ".join( + f"`{item.get('name')}`" + for item in mapping_list(profile, "default_archetypes") + ) + + +def render_catalog_canary_profiles_markdown(payload: dict[str, object]) -> str: + """Render catalog family and domain canary profiles as markdown.""" + + lines = [ + "# Catalog Canary Profiles", + "", + f"- source: `{payload.get('source')}`", + f"- archetypes: `{payload.get('archetype_count')}`", + f"- profiles: `{payload.get('profile_count')}`", + "- dry_run: `true`", + "- executes_checks: `false`", + "", + ] + for profile in mapping_list(payload, "profiles"): + lines.extend( + [ + f"## {profile.get('family')}", + f"- patterns: `{', '.join(string_list(profile, 'pattern_ids'))}`", + "- archetypes: " + _format_archetypes(profile), + f"- trigger surfaces: {profile.get('trigger_surfaces')}", + f"- minimum fixture: {profile.get('minimum_useful_fixture')}", + f"- failure meaning: {profile.get('failure_meaning')}", + "", + ] + ) + domain_profiles = mapping_list(payload, "domain_profiles") + if domain_profiles: + lines.extend(["## Current Repo Profiles", ""]) + for profile in domain_profiles: + checks = mapping_list(profile, "checks") + default_count = sum(1 for check in checks if check.get("tier") != "deep") + deep_count = sum(1 for check in checks if check.get("tier") == "deep") + lines.extend( + [ + f"### {profile.get('title')}", + f"- id: `{profile.get('id')}`", + f"- catalog families: `{', '.join(string_list(profile, 'catalog_families'))}`", + f"- purpose: {profile.get('purpose')}", + f"- default checks: `{default_count}`", + f"- deep checks: `{deep_count}`", + "", + ] + ) + return "\n".join(lines).rstrip() + "\n" + + +def render_catalog_canary_plan_markdown(payload: dict[str, object]) -> str: + """Render a selected catalog canary plan as markdown.""" + + inputs_value = payload.get("selection_inputs") + inputs: Mapping[str, object] = ( + inputs_value if isinstance(inputs_value, Mapping) else {} + ) + lines = [ + "# Catalog Canary Plan", + "", + f"- source: `{payload.get('source')}`", + "- dry_run: `true`", + "- executes_checks: `false`", + f"- selected_profiles: `{payload.get('profile_count')}`", + f"- selected_domain_profiles: `{payload.get('domain_profile_count')}`", + f"- changed_files: `{', '.join(string_list(inputs, 'changed_files'))}`", + f"- surfaces: `{', '.join(string_list(inputs, 'surfaces'))}`", + f"- families: `{', '.join(string_list(inputs, 'families'))}`", + f"- profiles: `{', '.join(string_list(inputs, 'profiles'))}`", + f"- include_deep_checks: `{str(inputs.get('include_deep_checks')).lower()}`", + "", + str(payload.get("note") or ""), + "", + ] + for profile in mapping_list(payload, "profiles"): + lines.extend( + [ + f"## {profile.get('family')}", + f"- patterns: `{', '.join(string_list(profile, 'pattern_ids'))}`", + "- selected because: " + + "; ".join(string_list(profile, "selection_reasons")), + "- archetypes: " + _format_archetypes(profile), + f"- minimum fixture: {profile.get('minimum_useful_fixture')}", + f"- failure meaning: {profile.get('failure_meaning')}", + "- suggested checks:", + ] + ) + for check in mapping_list(profile, "candidate_checks"): + lines.append(f" - `{check.get('command')}` - {check.get('reason')}") + lines.append("") + for profile in mapping_list(payload, "domain_profiles"): + lines.extend( + [ + f"## {profile.get('title')}", + f"- id: `{profile.get('id')}`", + f"- catalog families: `{', '.join(string_list(profile, 'catalog_families'))}`", + "- selected because: " + + "; ".join(string_list(profile, "selection_reasons")), + f"- purpose: {profile.get('purpose')}", + f"- deep checks available: `{str(profile.get('deep_checks_available')).lower()}`", + f"- deep checks included: `{str(profile.get('deep_checks_included')).lower()}`", + "- suggested checks:", + ] + ) + for check in mapping_list(profile, "checks"): + lines.append( + f" - `{check.get('command')}` [{check.get('tier')}] - {check.get('reason')}" + ) + lines.append("") + return "\n".join(lines).rstrip() + "\n" + + +def render_catalog_canary_coverage_audit_markdown(payload: dict[str, object]) -> str: + """Render catalog pattern canary coverage audit results as markdown.""" + + lines = [ + "# Catalog Canary Coverage Audit", + "", + f"- source: `{payload.get('source')}`", + "- dry_run: `true`", + "- executes_checks: `false`", + f"- priorities: `{', '.join(string_list(payload, 'priorities'))}`", + f"- required_patterns: `{payload.get('required_pattern_count')}`", + f"- covered: `{payload.get('covered_count')}`", + f"- excepted: `{payload.get('excepted_count')}`", + f"- missing: `{payload.get('missing_count')}`", + f"- invalid_exceptions: `{payload.get('invalid_exception_count')}`", + f"- drift: `{payload.get('drift_count')}`", + "", + str(payload.get("note") or ""), + "", + ] + missing_patterns = mapping_list(payload, "missing_patterns") + if missing_patterns: + lines.extend(["## Missing Coverage", ""]) + for row in missing_patterns: + lines.append( + f"- `{row.get('pattern_id')}` {row.get('name')} ({row.get('importance')})" + ) + lines.append("") + invalid_exceptions = mapping_list(payload, "invalid_exceptions") + if invalid_exceptions: + lines.extend(["## Invalid Exceptions", ""]) + for row in invalid_exceptions: + lines.append( + f"- `{row.get('pattern_id')}` {row.get('status')}: " + f"rationale={row.get('rationale')!r}; owner={row.get('owner')!r}" + ) + lines.append("") + return "\n".join(lines).rstrip() + "\n" diff --git a/loopx/canary/core_domain_profiles.py b/loopx/canary/core_domain_profiles.py new file mode 100644 index 0000000000..bf03e22d56 --- /dev/null +++ b/loopx/canary/core_domain_profiles.py @@ -0,0 +1,487 @@ +"""Core control-plane, release, status, and CLI canary domain profiles.""" + +from __future__ import annotations + +from collections.abc import Mapping + +from .qualification_profiles import CONTROL_PLANE_QUALIFICATION_PROFILES +from .release_profiles import RELEASE_PROMOTION_PROFILE + + +CORE_DOMAIN_PROFILES: tuple[Mapping[str, object], ...] = ( + { + "id": "pr-review-and-merge", + "title": "PR review and merge workflow", + "purpose": "Check public PR review packets, public-handle evidence, and merge-gate boundaries without approving or merging anything.", + "catalog_families": ["Human Decision", "Evidence Lifecycle", "State And Boundary"], + "trigger_hints": ("pr-review", "pull request", "github pr", "self-merge", "merge policy", "public pr metadata"), + "checks": [ + { + "command": "python3 examples/pr-review-command-smoke.py", + "tier": "default", + "reason": "checks the public-safe /loopx-pr-review packet and review-card contract", + }, + { + "command": "python3 examples/value-connectors-github-public-probe-smoke.py", + "tier": "default", + "reason": "guards public GitHub issue/PR metadata probes without raw body capture", + }, + { + "command": "python3 examples/control_plane/check-public-boundary-smoke.py", + "tier": "deep", + "reason": "runs broader public/private boundary checks when review artifacts are promoted", + }, + ], + }, + RELEASE_PROMOTION_PROFILE, + { + "id": "install-update", + "title": "Install and update safety", + "quality_risk": "high", + "purpose": "Check local install, packaged install, update planning, rollback, and uninstall safety before install/update changes ship.", + "catalog_families": ["State And Boundary", "Work Routing", "Planning Governance"], + "trigger_hints": ( + "install", + "installer", + "packaged install", + "install-local", + "install-from-github", + "loopx update", + "self-update", + "update command", + "upgrade", + "rollback", + "uninstall", + "scripts/install-local.sh", + "scripts/install-from-github.sh", + "loopx/self_update.py", + "loopx/cli_commands/update", + ), + "checks": [ + { + "command": "python3 examples/install-local-smoke.py", + "tier": "default", + "reason": "guards the local installer wrapper, skill installation, and install freshness reporting", + }, + { + "command": "python3 examples/release/local-install-promotion-boundary-smoke.py", + "tier": "deep", + "reason": "guards explicit default promotion while keeping dirty or non-main checkouts canary-only", + }, + { + "command": "python3 examples/codex-cli-packaged-install-smoke.py", + "tier": "default", + "reason": "checks packaged GitHub/archive install behavior in a temporary home", + }, + { + "command": "python3 examples/loopx-update-smoke.py", + "tier": "default", + "reason": "checks update planning, check-only behavior, rollback planning, and rollback execution fixtures", + }, + { + "command": "python3 examples/install-local-overwrite-smoke.py", + "tier": "deep", + "reason": "guards existing loopx executable overwrite and directory-conflict safety", + }, + { + "command": "python3 examples/protocol/rollback-packet-protocol-smoke.py", + "tier": "deep", + "reason": "validates the public rollback packet protocol and fixture boundary", + }, + { + "command": "python3 examples/project/project-uninstall-smoke.py", + "tier": "deep", + "reason": "samples project-local uninstall safety with isolated fixture registries", + }, + { + "command": "python3 examples/cli-worker-bridge-command-modularization-smoke.py", + "tier": "deep", + "reason": "checks generic worker bridge install contracts without exposing private runtime material", + }, + ], + }, + { + "id": "control-plane-refactor", + "title": "Control-plane refactor safety", + "purpose": "Sample hot-path route, policy seam, and interface budget checks for quota/status refactors.", + "catalog_families": ["Work Routing", "State And Boundary", "Planning Governance"], + "trigger_hints": ( + "refactor", + "quota.py", + "status.py", + "control-plane", + "policy seam", + "work-lane policy", + "resume_when", + "resume_ready", + "handoff", + "blocks_agent", + "unblocks_todo_id", + "successor", + "monitor_target", + "monitor_poll_writeback", + "loopx/control_plane/scheduler/monitor_todo.py", + "loopx/control_plane/scheduler/monitor_wait.py", + "loopx/control_plane/scheduler/monitor_poll_writeback.py", + "loopx/control_plane/quota/monitor_poll_commit.ts", + "loopx/control_plane/quota/monitor_poll_codec.ts", + "loopx/control_plane/quota/monitor_poll_admission.ts", + "loopx/control_plane/quota/monitor_poll_provider.ts", + "loopx/control_plane/scheduler/scheduler_hint.py", + "loopx/control_plane/quota/stall_repair.py", + "loopx/control_plane/scheduler/arbitration.py", + "loopx/control_plane/todos/decision_scope.py", + "loopx/control_plane/testing/decision_replay.py", + "loopx/control_plane/work_items/interaction_contract.py", + "loopx/control_plane/todos/handoff_gate.py", + "loopx/control_plane/work_items/execution_obligation.py", + "loopx/control_plane/work_items/goal_route_hint.py", + "loopx/control_plane/work_items/delivery_history.py", + "loopx/control_plane/work_items/delivery_history.ts", + "loopx/control_plane/work_items/work_lane.py", + ), + "checks": [ + { + "command": "python3 examples/control_plane/bounded-context-namespace-smoke.py", + "tier": "default", + "reason": "prevents repo-local code and smokes from depending on legacy projection shims after bounded-context moves", + }, + { + "command": "python3 examples/control_plane/control-plane-risk-characterization-smoke.py", + "tier": "default", + "reason": "characterizes shared control-plane routing, scheduler, and review-packet risks", + }, + { + "command": "python3 examples/control_plane/hot-path-interface-budget-smoke.py", + "tier": "default", + "reason": "keeps hot-path payload and module growth bounded", + }, + { + "command": "python3 examples/control_plane/quota-resume-gated-open-todo-smoke.py", + "tier": "default", + "reason": "guards resume_when-gated open todos from entering executable quota lanes early", + }, + { + "command": "python3 examples/control_plane/quota-cleared-blocker-successor-gate-smoke.py", + "tier": "default", + "reason": "guards cleared handoff gates waking the blocked agent through a concrete successor todo", + }, + { + "command": "python3 examples/control_plane/work-lane-contract-smoke.py", + "tier": "deep", + "reason": "covers broad work-lane policy interactions after larger refactors", + }, + ], + }, + { + "id": "repo-architecture-budget", + "title": "Control-plane maintainability ratchet", + "purpose": ( + "Report control-plane dependency debt, oversized decision functions, and " + "compatibility facades while rejecting unreviewed debt, magnitude growth, or " + "stale exceptions. This intentionally replaces the repository-wide exact Python " + "line budget with semantic control-plane and public-facade checks." + ), + "catalog_families": ["Planning Governance", "State And Boundary"], + "trigger_hints": ( + "architecture", + "architecture budget", + "maintainability", + "dependency debt", + "decision function", + "compatibility facade", + "refactor", + "quota.py", + "status.py", + "benchmark/", + "benchmark_toolkit", + "loopx/", + "examples/", + "scripts/", + ), + "checks": [ + { + "command": "python3 examples/control_plane/control-plane-maintainability-ratchet-smoke.py", + "tier": "default", + "reason": ( + "fails on unreviewed maintainability debt or an exception whose " + "underlying debt has been retired" + ), + }, + { + "command": "python3 examples/semantic-vocabulary-drift-smoke.py", + "tier": "default", + "reason": ( + "fails on an unregistered vocabulary value, a forked owner symbol, " + "unclassified project-registry I/O or stale classifications, " + "or a raised collision or retirement budget" + ), + }, + ], + }, + *CONTROL_PLANE_QUALIFICATION_PROFILES, + { + "id": "status-read-path", + "title": "Status read-path contract", + "purpose": "Check scoped status reads, markdown rendering, and goal-channel status export before status/read-path changes ship.", + "catalog_families": ["Work Routing", "State And Boundary"], + "trigger_hints": ( + "read-path", + "status --goal-id", + "status data", + "goal status", + "runtime handoff", + "handoff_readiness", + "post_handoff_run", + "loopx/status.py", + "loopx/cli_commands/status", + "loopx/control_plane/handoff/project_handoff.py", + ), + "checks": [ + { + "command": "python3 examples/control_plane/status-goal-filter-smoke.py", + "tier": "default", + "reason": "guards scoped status projection and global default status behavior", + }, + { + "command": "python3 examples/control_plane/status-quota-review-packet-parity-smoke.py", + "tier": "default", + "reason": "guards scoped status, agent quota, review-packet handoff, and scheduler_hint parity on one fixture", + }, + { + "command": "python3 examples/control_plane/runtime-handoff-status-read-path-smoke.py", + "tier": "default", + "reason": ( + "guards compact runtime handoff history through status, quota should-run, " + "and review-packet handoff-only read paths" + ), + }, + { + "command": "python3 examples/control_plane/run-history-readmodel-smoke.py", + "tier": "default", + "reason": "guards status run-history parity, compact reward/gate privacy, and bounded history projection", + }, + { + "command": "python3 examples/control_plane/goal-channel-readmodel-smoke.py", + "tier": "default", + "reason": "guards status wrapper parity for goal-channel projection attachment", + }, + { + "command": "python3 examples/control_plane/status-markdown-smoke.py", + "tier": "default", + "reason": "checks operator-facing markdown status rendering", + }, + { + "command": "python3 examples/project/goal-channel-status-export-smoke.py", + "tier": "deep", + "reason": "guards goal-channel status export consumed by non-hot-path readers", + }, + { + "command": "python3 examples/control_plane/status-quota-perf-budget-smoke.py", + "tier": "deep", + "reason": "runs the broader status/quota performance budget sample when explicitly requested", + }, + ], + }, + { + "id": "status-projection-cache", + "title": "Status projection cache contract", + "purpose": ( + "Check opt-in status projection cache freshness, expiration fallback, " + "and quota next-action isolation before cache-path changes ship." + ), + "catalog_families": ["Work Routing", "State And Boundary"], + "trigger_hints": ( + "projection-cache", + "status_projection_cache", + "use-projection-cache", + "write-projection-cache", + "status projection cache", + "loopx/control_plane/runtime/status_projection_cache.py", + "examples/control_plane/status-projection-cache-smoke.py", + ), + "checks": [ + { + "command": "python3 examples/control_plane/status-projection-cache-smoke.py", + "tier": "default", + "reason": ( + "guards opt-in status projection cache freshness, expiration fallback, " + "and quota next-action read-path isolation" + ), + }, + ], + }, + { + "id": "review-packet-read-path", + "title": "Review-packet read-path contract", + "purpose": "Check operator review packets, handoff-only payloads, and task-graph lineage before review-packet/read-path changes ship.", + "catalog_families": ["Work Routing", "Human Decision", "State And Boundary"], + "trigger_hints": ( + "review-packet", + "review packet", + "handoff-only", + "project-agent handoff", + "operator packet", + "loopx/review_packet.py", + "loopx/cli_commands/status", + "docs/status-data-contract.md", + ), + "checks": [ + { + "command": "python3 examples/control_plane/review-packet-cli-smoke.py", + "tier": "default", + "reason": "guards CLI-visible review-packet and handoff-only JSON contracts", + }, + { + "command": "python3 examples/control_plane/review-packet-smoke.py", + "tier": "default", + "reason": "checks dashboard/operator packet copy and public-safe handoff text", + }, + { + "command": "python3 examples/control_plane/task-graph-projection-fixture-smoke.py", + "tier": "default", + "reason": "guards task-graph lineage consumed by review packets without private sources", + }, + { + "command": "python3 examples/control_plane/control-plane-integrated-canary-smoke.py", + "tier": "deep", + "reason": "samples the bounded status -> quota -> review-packet Todo read path", + }, + { + "command": "python3 examples/control_plane/hot-path-interface-budget-smoke.py", + "tier": "deep", + "reason": "checks review-packet handoff interface budgets after hot-path changes", + }, + ], + }, + { + "id": "cli-command-contract", + "title": "CLI command module contract", + "purpose": "Check command-module boundaries, ownership budgets, and compatibility for LoopX CLI refactors.", + "catalog_families": ["State And Boundary", "Planning Governance"], + "trigger_hints": ( + "loopx/cli.py", + "loopx/cli_commands", + "cli command", + "command modularization", + "command-module", + ), + "checks": [ + { + "command": "python3 examples/cli-version-command-modularization-smoke.py", + "tier": "default", + "reason": "guards version output parity and both JSON format option placements", + }, + { + "command": "python3 examples/cli-control-plane-command-modularization-smoke.py", + "tier": "default", + "reason": "samples todo/quota command compatibility after CLI command refactors", + }, + ], + }, + { + "id": "todo-lifecycle", + "title": "Todo lifecycle contract", + "purpose": "Check todo metadata, lifecycle transitions, and event/list projection before todo read/write CLI changes ship.", + "catalog_families": ["State And Boundary", "Human Decision", "Planning Governance"], + "trigger_hints": ( + "todo lifecycle", + "todo claim", + "todo list", + "todo complete", + "todo supersede", + "todo metadata", + "todo detail", + "loopx/todos.py", + "loopx/control_plane/todos/contract.py", + "loopx/control_plane/todos/decision_scope.py", + "loopx/cli_commands/todo", + ), + "checks": [ + { + "command": "python3 examples/control_plane/todo-contract-smoke.py", + "tier": "default", + "reason": "guards the public todo status and metadata helper contract", + }, + { + "command": "python3 examples/control_plane/todo-cli-smoke.py", + "tier": "default", + "reason": "checks agent-facing todo add/update/list behavior on fixture state", + }, + { + "command": "python3 examples/control_plane/todo-lifecycle-cli-smoke.py", + "tier": "default", + "reason": "exercises claim, completion, successor, and handoff lifecycle transitions by todo_id", + }, + { + "command": "python3 examples/control_plane/todo-deferred-capacity-cli-smoke.py", + "tier": "default", + "reason": "guards deferred writes, fail-closed resume kinds, and runtime capacity resume routing", + }, + { + "command": "python3 examples/control_plane/todo-concurrent-write-lock-smoke.py", + "tier": "deep", + "reason": "samples lock behavior for concurrent todo writes", + }, + ], + }, + { + "id": "monitor-scheduler", + "title": "Monitor scheduler routing", + "purpose": "Check monitor due/quiet/replan behavior without polling external targets by default.", + "catalog_families": ["Work Routing", "Planning Governance"], + "trigger_hints": ("monitor", "scheduler", "next_due_at", "monitor-poll", "continuous_monitor"), + "checks": [ + { + "command": "python3 examples/control_plane/monitor-scheduler-contract-smoke.py", + "tier": "default", + "reason": "checks due monitor selection, expiry, and priority behavior", + }, + { + "command": "python3 examples/control_plane/monitor-poll-writeback-smoke.py", + "tier": "default", + "reason": "guards no-spend monitor poll writeback and replan triggers", + }, + { + "command": "python3 examples/control_plane/heartbeat-quota-flow-smoke.py", + "tier": "deep", + "reason": "runs a broader heartbeat/quota control-flow sample", + }, + ], + }, + { + "id": "state-write-correctness", + "title": "State write correctness", + "quality_risk": "high", + "purpose": "Check local state writes, refresh-state, and todo write paths before touching writer internals.", + "catalog_families": ["State And Boundary", "Planning Governance", "Human Decision"], + "trigger_hints": ("state write", "refresh-state", "todo write", "idempotency", "revision", "lease"), + "checks": [ + { + "command": "python3 examples/control_plane/task-lease-runtime-smoke.py", + "tier": "default", + "reason": "guards shipped task_lease_v0 CLI/runtime ownership, TTL, conflict, transfer, and release behavior", + }, + { + "command": "python3 examples/control_plane/local-state-write-correctness-contract-smoke.py", + "tier": "default", + "reason": "checks local state write correctness contract fixtures", + }, + { + "command": "python3 examples/control_plane/refresh-state-write-correctness-smoke.py", + "tier": "default", + "reason": "guards refresh-state update behavior and projection writes", + }, + { + "command": "python3 examples/control_plane/todo-write-correctness-smoke.py", + "tier": "default", + "reason": "guards todo dry-run write correctness and shadow revision/lease validation", + }, + { + "command": "python3 examples/control_plane/todo-concurrent-write-lock-smoke.py", + "tier": "deep", + "reason": "samples lock behavior for concurrent todo writes", + }, + ], + }, +) diff --git a/loopx/canary/family_profiles.py b/loopx/canary/family_profiles.py new file mode 100644 index 0000000000..515e678930 --- /dev/null +++ b/loopx/canary/family_profiles.py @@ -0,0 +1,167 @@ +"""Catalog family canary checks and selector hints.""" + +from __future__ import annotations + + +FAMILY_CHECKS: dict[str, list[dict[str, str]]] = { + "Work Routing": [ + { + "command": "python3 examples/control_plane/quota-plan-smoke.py", + "reason": "exercises quota should-run routing, fallback, and execution obligation projection", + }, + { + "command": "python3 examples/control_plane/quota-work-lane-policy-smoke.py", + "reason": "checks advancement, monitor, and no-work lane policy selection", + }, + { + "command": "python3 examples/control_plane/monitor-scheduler-contract-smoke.py", + "reason": "guards due-monitor routing without requiring real external polling", + }, + { + "command": "python3 examples/control_plane/heartbeat-prompt-smoke.py", + "reason": "checks heartbeat prompt and scheduler guidance for controller loops", + }, + ], + "Human Decision": [ + { + "command": "python3 examples/control_plane/todo-user-gate-scope-smoke.py", + "reason": "checks scoped user-gate projection instead of global prose gates", + }, + { + "command": "python3 examples/project/operator-gate-resume-contract-smoke.py", + "reason": "exercises operator gate preview and resume behavior", + }, + { + "command": "python3 examples/reward-gate-direct-write-contract-smoke.py", + "reason": "guards reward/gate write boundaries before agent continuation", + }, + { + "command": "python3 examples/control_plane/quota-agent-scoped-user-gate-smoke.py", + "reason": "checks that agent-scoped user gates do not block unrelated lanes", + }, + ], + "State And Boundary": [ + { + "command": "python3 examples/control_plane/todo-contract-smoke.py", + "reason": "checks todo metadata shape consumed by status and quota", + }, + { + "command": "python3 examples/control_plane/todo-readmodel-boundary-smoke.py", + "reason": "guards status wrapper parity for todo read-model extraction", + }, + { + "command": "python3 examples/control_plane/active-state-structured-projection-smoke.py", + "reason": "guards active-state structured projection from Markdown drift", + }, + { + "command": "python3 examples/control_plane/task-graph-projection-fixture-smoke.py", + "reason": "checks task graph projection and lineage without private sources", + }, + { + "command": "python3 examples/control_plane/check-public-boundary-smoke.py", + "reason": "guards public/private boundary scanning for touched files", + }, + ], + "Evidence Lifecycle": [ + { + "command": "python3 examples/benchmark-candidate-source-boundary-smoke.py", + "reason": "guards raw/private candidate source exclusion", + }, + { + "command": "python3 examples/benchmark-artifact-path-filter-smoke.py", + "reason": "guards raw/private artifact path exclusion", + }, + { + "command": "python3 examples/content-ops-public-handle-observation-smoke.py", + "reason": "checks public-handle evidence observation without private connector reads", + }, + ], + "Planning Governance": [ + { + "command": "python3 examples/autonomous-replan-obligation-smoke.py", + "reason": "guards stalled-turn autonomous replan obligations", + }, + { + "command": "python3 examples/control_plane/monitor-poll-writeback-smoke.py", + "reason": "checks monitor poll writeback and no-spend replan triggers", + }, + { + "command": "python3 examples/control_plane/refresh-state-write-correctness-smoke.py", + "reason": "checks refresh-state writeback correctness and projection updates", + }, + { + "command": "python3 examples/dreaming-dry-run-proposal-smoke.py", + "reason": "checks planning proposal preview remains dry-run and machine-visible", + }, + ], +} + + +FAMILY_SELECTOR_HINTS: dict[str, tuple[str, ...]] = { + "Work Routing": ( + "quota", + "should-run", + "status", + "review-packet", + "heartbeat", + "scheduler", + "work-lane", + "monitor", + "handoff", + "loopx/quota.py", + "loopx/status.py", + "loopx/review_packet.py", + "loopx/heartbeat_prompt.py", + ), + "Human Decision": ( + "user todo", + "operator-gate", + "reward", + "decision-scope", + "deferred", + "gate", + "loopx/operator_gate.py", + "loopx/control_plane/todos/decision_scope.py", + "loopx/feedback.py", + ), + "State And Boundary": ( + "active state", + "todo", + "task graph", + "authority", + "boundary", + "connector", + "public/private", + "loopx/todos.py", + "loopx/control_plane/todos/contract.py", + "loopx/status.py", + "loopx/state_projection.py", + "loopx/boundary_authority.py", + "loopx/authority.py", + ), + "Evidence Lifecycle": ( + "benchmark", + "evidence", + "ledger", + "artifact", + "public handle", + "ci", + "content-ops", + "worker_bridge", + "loopx/benchmark", + "loopx/worker_bridge.py", + "loopx/capabilities/content_ops", + ), + "Planning Governance": ( + "replan", + "repair", + "cadence", + "dreaming", + "plan-to-todo", + "refresh-state", + "monitor-poll", + "loopx/dreaming.py", + "loopx/state_refresh.py", + "loopx/long_task_cadence.py", + ), +} diff --git a/loopx/canary/module_metric_baseline.json b/loopx/canary/module_metric_baseline.json index 6f6f362a6c..5d03de500c 100644 --- a/loopx/canary/module_metric_baseline.json +++ b/loopx/canary/module_metric_baseline.json @@ -15,7 +15,7 @@ "dict_any_count": 0 }, "loopx/canary/planner.py": { - "any_count": 22, + "any_count": 0, "dict_any_count": 0 }, "loopx/capabilities/benchmark_toolkit/experiment_board.py": { diff --git a/loopx/canary/planner.py b/loopx/canary/planner.py index 447c04d4a4..32e9bbe08c 100644 --- a/loopx/canary/planner.py +++ b/loopx/canary/planner.py @@ -1,15 +1,32 @@ +"""Catalog-driven canary profile planning and coverage auditing.""" + from __future__ import annotations -import re +from collections.abc import Mapping from pathlib import Path -from typing import Any +import re -from .qualification_profiles import CONTROL_PLANE_QUALIFICATION_PROFILES +from .catalog_markdown import ( + catalog_pattern_rows, + catalog_profile_id, + coverage_exception_is_valid, + coverage_exception_rows, + first_table_after, + mapping_list, + pattern_ids, + render_catalog_canary_coverage_audit_markdown, + render_catalog_canary_plan_markdown, + render_catalog_canary_profiles_markdown, + slug, + split_semicolon, + string_list, +) +from .core_domain_profiles import CORE_DOMAIN_PROFILES +from .family_profiles import FAMILY_CHECKS, FAMILY_SELECTOR_HINTS from .quality_surface_catalog import ( build_quality_surface_catalog_audit as _build_quality_surface_catalog_audit, ) -from .package_profiles import PACKAGE_QUALIFICATION_PROFILES -from .release_profiles import RELEASE_PROMOTION_PROFILE +from .workflow_domain_profiles import WORKFLOW_DOMAIN_PROFILES CANARY_PROFILE_SCHEMA_VERSION = "catalog_canary_profile_v0" @@ -21,1238 +38,33 @@ REPO_ROOT = Path(__file__).resolve().parents[2] DEFAULT_CATALOG_PATH = REPO_ROOT / "docs" / "concepts" / "interaction-pattern-catalog.md" - -FAMILY_CHECKS: dict[str, list[dict[str, str]]] = { - "Work Routing": [ - { - "command": "python3 examples/control_plane/quota-plan-smoke.py", - "reason": "exercises quota should-run routing, fallback, and execution obligation projection", - }, - { - "command": "python3 examples/control_plane/quota-work-lane-policy-smoke.py", - "reason": "checks advancement, monitor, and no-work lane policy selection", - }, - { - "command": "python3 examples/control_plane/monitor-scheduler-contract-smoke.py", - "reason": "guards due-monitor routing without requiring real external polling", - }, - { - "command": "python3 examples/control_plane/heartbeat-prompt-smoke.py", - "reason": "checks heartbeat prompt and scheduler guidance for controller loops", - }, - ], - "Human Decision": [ - { - "command": "python3 examples/control_plane/todo-user-gate-scope-smoke.py", - "reason": "checks scoped user-gate projection instead of global prose gates", - }, - { - "command": "python3 examples/project/operator-gate-resume-contract-smoke.py", - "reason": "exercises operator gate preview and resume behavior", - }, - { - "command": "python3 examples/reward-gate-direct-write-contract-smoke.py", - "reason": "guards reward/gate write boundaries before agent continuation", - }, - { - "command": "python3 examples/control_plane/quota-agent-scoped-user-gate-smoke.py", - "reason": "checks that agent-scoped user gates do not block unrelated lanes", - }, - ], - "State And Boundary": [ - { - "command": "python3 examples/control_plane/todo-contract-smoke.py", - "reason": "checks todo metadata shape consumed by status and quota", - }, - { - "command": "python3 examples/control_plane/todo-readmodel-boundary-smoke.py", - "reason": "guards status wrapper parity for todo read-model extraction", - }, - { - "command": "python3 examples/control_plane/active-state-structured-projection-smoke.py", - "reason": "guards active-state structured projection from Markdown drift", - }, - { - "command": "python3 examples/control_plane/task-graph-projection-fixture-smoke.py", - "reason": "checks task graph projection and lineage without private sources", - }, - { - "command": "python3 examples/control_plane/check-public-boundary-smoke.py", - "reason": "guards public/private boundary scanning for touched files", - }, - ], - "Evidence Lifecycle": [ - { - "command": "python3 examples/benchmark-candidate-source-boundary-smoke.py", - "reason": "guards raw/private candidate source exclusion", - }, - { - "command": "python3 examples/benchmark-artifact-path-filter-smoke.py", - "reason": "guards raw/private artifact path exclusion", - }, - { - "command": "python3 examples/content-ops-public-handle-observation-smoke.py", - "reason": "checks public-handle evidence observation without private connector reads", - }, - ], - "Planning Governance": [ - { - "command": "python3 examples/autonomous-replan-obligation-smoke.py", - "reason": "guards stalled-turn autonomous replan obligations", - }, - { - "command": "python3 examples/control_plane/monitor-poll-writeback-smoke.py", - "reason": "checks monitor poll writeback and no-spend replan triggers", - }, - { - "command": "python3 examples/control_plane/refresh-state-write-correctness-smoke.py", - "reason": "checks refresh-state writeback correctness and projection updates", - }, - { - "command": "python3 examples/dreaming-dry-run-proposal-smoke.py", - "reason": "checks planning proposal preview remains dry-run and machine-visible", - }, - ], -} - - -FAMILY_SELECTOR_HINTS: dict[str, tuple[str, ...]] = { - "Work Routing": ( - "quota", - "should-run", - "status", - "review-packet", - "heartbeat", - "scheduler", - "work-lane", - "monitor", - "handoff", - "loopx/quota.py", - "loopx/status.py", - "loopx/review_packet.py", - "loopx/heartbeat_prompt.py", - ), - "Human Decision": ( - "user todo", - "operator-gate", - "reward", - "decision-scope", - "deferred", - "gate", - "loopx/operator_gate.py", - "loopx/control_plane/todos/decision_scope.py", - "loopx/feedback.py", - ), - "State And Boundary": ( - "active state", - "todo", - "task graph", - "authority", - "boundary", - "connector", - "public/private", - "loopx/todos.py", - "loopx/control_plane/todos/contract.py", - "loopx/status.py", - "loopx/state_projection.py", - "loopx/boundary_authority.py", - "loopx/authority.py", - ), - "Evidence Lifecycle": ( - "benchmark", - "evidence", - "ledger", - "artifact", - "public handle", - "ci", - "content-ops", - "worker_bridge", - "loopx/benchmark", - "loopx/worker_bridge.py", - "loopx/capabilities/content_ops", - ), - "Planning Governance": ( - "replan", - "repair", - "cadence", - "dreaming", - "plan-to-todo", - "refresh-state", - "monitor-poll", - "loopx/dreaming.py", - "loopx/state_refresh.py", - "loopx/long_task_cadence.py", - ), -} - - -CURRENT_REPO_PROFILES: tuple[dict[str, Any], ...] = ( - { - "id": "pr-review-and-merge", - "title": "PR review and merge workflow", - "purpose": "Check public PR review packets, public-handle evidence, and merge-gate boundaries without approving or merging anything.", - "catalog_families": ["Human Decision", "Evidence Lifecycle", "State And Boundary"], - "trigger_hints": ("pr-review", "pull request", "github pr", "self-merge", "merge policy", "public pr metadata"), - "checks": [ - { - "command": "python3 examples/pr-review-command-smoke.py", - "tier": "default", - "reason": "checks the public-safe /loopx-pr-review packet and review-card contract", - }, - { - "command": "python3 examples/value-connectors-github-public-probe-smoke.py", - "tier": "default", - "reason": "guards public GitHub issue/PR metadata probes without raw body capture", - }, - { - "command": "python3 examples/control_plane/check-public-boundary-smoke.py", - "tier": "deep", - "reason": "runs broader public/private boundary checks when review artifacts are promoted", - }, - ], - }, - RELEASE_PROMOTION_PROFILE, - { - "id": "install-update", - "title": "Install and update safety", - "quality_risk": "high", - "purpose": "Check local install, packaged install, update planning, rollback, and uninstall safety before install/update changes ship.", - "catalog_families": ["State And Boundary", "Work Routing", "Planning Governance"], - "trigger_hints": ( - "install", - "installer", - "packaged install", - "install-local", - "install-from-github", - "loopx update", - "self-update", - "update command", - "upgrade", - "rollback", - "uninstall", - "scripts/install-local.sh", - "scripts/install-from-github.sh", - "loopx/self_update.py", - "loopx/cli_commands/update", - ), - "checks": [ - { - "command": "python3 examples/install-local-smoke.py", - "tier": "default", - "reason": "guards the local installer wrapper, skill installation, and install freshness reporting", - }, - { - "command": "python3 examples/release/local-install-promotion-boundary-smoke.py", - "tier": "deep", - "reason": "guards explicit default promotion while keeping dirty or non-main checkouts canary-only", - }, - { - "command": "python3 examples/codex-cli-packaged-install-smoke.py", - "tier": "default", - "reason": "checks packaged GitHub/archive install behavior in a temporary home", - }, - { - "command": "python3 examples/loopx-update-smoke.py", - "tier": "default", - "reason": "checks update planning, check-only behavior, rollback planning, and rollback execution fixtures", - }, - { - "command": "python3 examples/install-local-overwrite-smoke.py", - "tier": "deep", - "reason": "guards existing loopx executable overwrite and directory-conflict safety", - }, - { - "command": "python3 examples/protocol/rollback-packet-protocol-smoke.py", - "tier": "deep", - "reason": "validates the public rollback packet protocol and fixture boundary", - }, - { - "command": "python3 examples/project/project-uninstall-smoke.py", - "tier": "deep", - "reason": "samples project-local uninstall safety with isolated fixture registries", - }, - { - "command": "python3 examples/cli-worker-bridge-command-modularization-smoke.py", - "tier": "deep", - "reason": "checks generic worker bridge install contracts without exposing private runtime material", - }, - ], - }, - { - "id": "control-plane-refactor", - "title": "Control-plane refactor safety", - "purpose": "Sample hot-path route, policy seam, and interface budget checks for quota/status refactors.", - "catalog_families": ["Work Routing", "State And Boundary", "Planning Governance"], - "trigger_hints": ( - "refactor", - "quota.py", - "status.py", - "control-plane", - "policy seam", - "work-lane policy", - "resume_when", - "resume_ready", - "handoff", - "blocks_agent", - "unblocks_todo_id", - "successor", - "monitor_target", - "monitor_poll_writeback", - "loopx/control_plane/scheduler/monitor_todo.py", - "loopx/control_plane/scheduler/monitor_wait.py", - "loopx/control_plane/scheduler/monitor_poll_writeback.py", - "loopx/control_plane/quota/monitor_poll_commit.ts", - "loopx/control_plane/quota/monitor_poll_codec.ts", - "loopx/control_plane/quota/monitor_poll_admission.ts", - "loopx/control_plane/quota/monitor_poll_provider.ts", - "loopx/control_plane/scheduler/scheduler_hint.py", - "loopx/control_plane/quota/stall_repair.py", - "loopx/control_plane/scheduler/arbitration.py", - "loopx/control_plane/todos/decision_scope.py", - "loopx/control_plane/testing/decision_replay.py", - "loopx/control_plane/work_items/interaction_contract.py", - "loopx/control_plane/todos/handoff_gate.py", - "loopx/control_plane/work_items/execution_obligation.py", - "loopx/control_plane/work_items/goal_route_hint.py", - "loopx/control_plane/work_items/delivery_history.py", - "loopx/control_plane/work_items/delivery_history.ts", - "loopx/control_plane/work_items/work_lane.py", - ), - "checks": [ - { - "command": "python3 examples/control_plane/bounded-context-namespace-smoke.py", - "tier": "default", - "reason": "prevents repo-local code and smokes from depending on legacy projection shims after bounded-context moves", - }, - { - "command": "python3 examples/control_plane/control-plane-risk-characterization-smoke.py", - "tier": "default", - "reason": "characterizes shared control-plane routing, scheduler, and review-packet risks", - }, - { - "command": "python3 examples/control_plane/hot-path-interface-budget-smoke.py", - "tier": "default", - "reason": "keeps hot-path payload and module growth bounded", - }, - { - "command": "python3 examples/control_plane/quota-resume-gated-open-todo-smoke.py", - "tier": "default", - "reason": "guards resume_when-gated open todos from entering executable quota lanes early", - }, - { - "command": "python3 examples/control_plane/quota-cleared-blocker-successor-gate-smoke.py", - "tier": "default", - "reason": "guards cleared handoff gates waking the blocked agent through a concrete successor todo", - }, - { - "command": "python3 examples/control_plane/work-lane-contract-smoke.py", - "tier": "deep", - "reason": "covers broad work-lane policy interactions after larger refactors", - }, - ], - }, - { - "id": "repo-architecture-budget", - "title": "Control-plane maintainability ratchet", - "purpose": ( - "Report control-plane dependency debt, oversized decision functions, and " - "compatibility facades while rejecting unreviewed debt, magnitude growth, or " - "stale exceptions. This intentionally replaces the repository-wide exact Python " - "line budget with semantic control-plane and public-facade checks." - ), - "catalog_families": ["Planning Governance", "State And Boundary"], - "trigger_hints": ( - "architecture", - "architecture budget", - "maintainability", - "dependency debt", - "decision function", - "compatibility facade", - "refactor", - "quota.py", - "status.py", - "benchmark/", - "benchmark_toolkit", - "loopx/", - "examples/", - "scripts/", - ), - "checks": [ - { - "command": "python3 examples/control_plane/control-plane-maintainability-ratchet-smoke.py", - "tier": "default", - "reason": ( - "fails on unreviewed maintainability debt or an exception whose " - "underlying debt has been retired" - ), - }, - { - "command": "python3 examples/semantic-vocabulary-drift-smoke.py", - "tier": "default", - "reason": ( - "fails on an unregistered vocabulary value, a forked owner symbol, " - "unclassified project-registry I/O or stale classifications, " - "or a raised collision or retirement budget" - ), - }, - ], - }, - *CONTROL_PLANE_QUALIFICATION_PROFILES, - { - "id": "status-read-path", - "title": "Status read-path contract", - "purpose": "Check scoped status reads, markdown rendering, and goal-channel status export before status/read-path changes ship.", - "catalog_families": ["Work Routing", "State And Boundary"], - "trigger_hints": ( - "read-path", - "status --goal-id", - "status data", - "goal status", - "runtime handoff", - "handoff_readiness", - "post_handoff_run", - "loopx/status.py", - "loopx/cli_commands/status", - "loopx/control_plane/handoff/project_handoff.py", - ), - "checks": [ - { - "command": "python3 examples/control_plane/status-goal-filter-smoke.py", - "tier": "default", - "reason": "guards scoped status projection and global default status behavior", - }, - { - "command": "python3 examples/control_plane/status-quota-review-packet-parity-smoke.py", - "tier": "default", - "reason": "guards scoped status, agent quota, review-packet handoff, and scheduler_hint parity on one fixture", - }, - { - "command": "python3 examples/control_plane/runtime-handoff-status-read-path-smoke.py", - "tier": "default", - "reason": ( - "guards compact runtime handoff history through status, quota should-run, " - "and review-packet handoff-only read paths" - ), - }, - { - "command": "python3 examples/control_plane/run-history-readmodel-smoke.py", - "tier": "default", - "reason": "guards status run-history parity, compact reward/gate privacy, and bounded history projection", - }, - { - "command": "python3 examples/control_plane/goal-channel-readmodel-smoke.py", - "tier": "default", - "reason": "guards status wrapper parity for goal-channel projection attachment", - }, - { - "command": "python3 examples/control_plane/status-markdown-smoke.py", - "tier": "default", - "reason": "checks operator-facing markdown status rendering", - }, - { - "command": "python3 examples/project/goal-channel-status-export-smoke.py", - "tier": "deep", - "reason": "guards goal-channel status export consumed by non-hot-path readers", - }, - { - "command": "python3 examples/control_plane/status-quota-perf-budget-smoke.py", - "tier": "deep", - "reason": "runs the broader status/quota performance budget sample when explicitly requested", - }, - ], - }, - { - "id": "status-projection-cache", - "title": "Status projection cache contract", - "purpose": ( - "Check opt-in status projection cache freshness, expiration fallback, " - "and quota next-action isolation before cache-path changes ship." - ), - "catalog_families": ["Work Routing", "State And Boundary"], - "trigger_hints": ( - "projection-cache", - "status_projection_cache", - "use-projection-cache", - "write-projection-cache", - "status projection cache", - "loopx/control_plane/runtime/status_projection_cache.py", - "examples/control_plane/status-projection-cache-smoke.py", - ), - "checks": [ - { - "command": "python3 examples/control_plane/status-projection-cache-smoke.py", - "tier": "default", - "reason": ( - "guards opt-in status projection cache freshness, expiration fallback, " - "and quota next-action read-path isolation" - ), - }, - ], - }, - { - "id": "review-packet-read-path", - "title": "Review-packet read-path contract", - "purpose": "Check operator review packets, handoff-only payloads, and task-graph lineage before review-packet/read-path changes ship.", - "catalog_families": ["Work Routing", "Human Decision", "State And Boundary"], - "trigger_hints": ( - "review-packet", - "review packet", - "handoff-only", - "project-agent handoff", - "operator packet", - "loopx/review_packet.py", - "loopx/cli_commands/status", - "docs/status-data-contract.md", - ), - "checks": [ - { - "command": "python3 examples/control_plane/review-packet-cli-smoke.py", - "tier": "default", - "reason": "guards CLI-visible review-packet and handoff-only JSON contracts", - }, - { - "command": "python3 examples/control_plane/review-packet-smoke.py", - "tier": "default", - "reason": "checks dashboard/operator packet copy and public-safe handoff text", - }, - { - "command": "python3 examples/control_plane/task-graph-projection-fixture-smoke.py", - "tier": "default", - "reason": "guards task-graph lineage consumed by review packets without private sources", - }, - { - "command": "python3 examples/control_plane/control-plane-integrated-canary-smoke.py", - "tier": "deep", - "reason": "samples the bounded status -> quota -> review-packet Todo read path", - }, - { - "command": "python3 examples/control_plane/hot-path-interface-budget-smoke.py", - "tier": "deep", - "reason": "checks review-packet handoff interface budgets after hot-path changes", - }, - ], - }, - { - "id": "cli-command-contract", - "title": "CLI command module contract", - "purpose": "Check command-module boundaries, ownership budgets, and compatibility for LoopX CLI refactors.", - "catalog_families": ["State And Boundary", "Planning Governance"], - "trigger_hints": ( - "loopx/cli.py", - "loopx/cli_commands", - "cli command", - "command modularization", - "command-module", - ), - "checks": [ - { - "command": "python3 examples/cli-version-command-modularization-smoke.py", - "tier": "default", - "reason": "guards version output parity and both JSON format option placements", - }, - { - "command": "python3 examples/cli-control-plane-command-modularization-smoke.py", - "tier": "default", - "reason": "samples todo/quota command compatibility after CLI command refactors", - }, - ], - }, - { - "id": "todo-lifecycle", - "title": "Todo lifecycle contract", - "purpose": "Check todo metadata, lifecycle transitions, and event/list projection before todo read/write CLI changes ship.", - "catalog_families": ["State And Boundary", "Human Decision", "Planning Governance"], - "trigger_hints": ( - "todo lifecycle", - "todo claim", - "todo list", - "todo complete", - "todo supersede", - "todo metadata", - "todo detail", - "loopx/todos.py", - "loopx/control_plane/todos/contract.py", - "loopx/control_plane/todos/decision_scope.py", - "loopx/cli_commands/todo", - ), - "checks": [ - { - "command": "python3 examples/control_plane/todo-contract-smoke.py", - "tier": "default", - "reason": "guards the public todo status and metadata helper contract", - }, - { - "command": "python3 examples/control_plane/todo-cli-smoke.py", - "tier": "default", - "reason": "checks agent-facing todo add/update/list behavior on fixture state", - }, - { - "command": "python3 examples/control_plane/todo-lifecycle-cli-smoke.py", - "tier": "default", - "reason": "exercises claim, completion, successor, and handoff lifecycle transitions by todo_id", - }, - { - "command": "python3 examples/control_plane/todo-deferred-capacity-cli-smoke.py", - "tier": "default", - "reason": "guards deferred writes, fail-closed resume kinds, and runtime capacity resume routing", - }, - { - "command": "python3 examples/control_plane/todo-concurrent-write-lock-smoke.py", - "tier": "deep", - "reason": "samples lock behavior for concurrent todo writes", - }, - ], - }, - { - "id": "monitor-scheduler", - "title": "Monitor scheduler routing", - "purpose": "Check monitor due/quiet/replan behavior without polling external targets by default.", - "catalog_families": ["Work Routing", "Planning Governance"], - "trigger_hints": ("monitor", "scheduler", "next_due_at", "monitor-poll", "continuous_monitor"), - "checks": [ - { - "command": "python3 examples/control_plane/monitor-scheduler-contract-smoke.py", - "tier": "default", - "reason": "checks due monitor selection, expiry, and priority behavior", - }, - { - "command": "python3 examples/control_plane/monitor-poll-writeback-smoke.py", - "tier": "default", - "reason": "guards no-spend monitor poll writeback and replan triggers", - }, - { - "command": "python3 examples/control_plane/heartbeat-quota-flow-smoke.py", - "tier": "deep", - "reason": "runs a broader heartbeat/quota control-flow sample", - }, - ], - }, - { - "id": "state-write-correctness", - "title": "State write correctness", - "quality_risk": "high", - "purpose": "Check local state writes, refresh-state, and todo write paths before touching writer internals.", - "catalog_families": ["State And Boundary", "Planning Governance", "Human Decision"], - "trigger_hints": ("state write", "refresh-state", "todo write", "idempotency", "revision", "lease"), - "checks": [ - { - "command": "python3 examples/control_plane/task-lease-runtime-smoke.py", - "tier": "default", - "reason": "guards shipped task_lease_v0 CLI/runtime ownership, TTL, conflict, transfer, and release behavior", - }, - { - "command": "python3 examples/control_plane/local-state-write-correctness-contract-smoke.py", - "tier": "default", - "reason": "checks local state write correctness contract fixtures", - }, - { - "command": "python3 examples/control_plane/refresh-state-write-correctness-smoke.py", - "tier": "default", - "reason": "guards refresh-state update behavior and projection writes", - }, - { - "command": "python3 examples/control_plane/todo-write-correctness-smoke.py", - "tier": "default", - "reason": "guards todo dry-run write correctness and shadow revision/lease validation", - }, - { - "command": "python3 examples/control_plane/todo-concurrent-write-lock-smoke.py", - "tier": "deep", - "reason": "samples lock behavior for concurrent todo writes", - }, - ], - }, - { - "id": "product-entry-workflows", - "title": "Product entry workflows", - "purpose": ( - "Check user-facing product entry routes for issue-fix, content-ops, " - "update notes, and cross-runtime demo surfaces without reading private sources." - ), - "catalog_families": ["Human Decision", "Evidence Lifecycle", "State And Boundary", "Work Routing"], - "trigger_hints": ( - "product-entry", - "product entry", - "issue-fix", - "issue fix", - "content-ops", - "content ops", - "update-note", - "update note", - "update-notes", - "update notes", - "cross-runtime", - "impl-review", - "claude implements", - "codex reviews", - "README.md", - "docs/product/use-cases/cross-runtime/cross-runtime-impl-review-demo.md", - "loopx/capabilities/issue_fix", - "loopx/capabilities/content_ops", - "docs/update-notes", - "loopx/cli_commands/issue_fix", - "loopx/cli_commands/content_ops", - "scripts/update_notes_release_job.py", - ), - "checks": [ - { - "command": "python3 examples/issue-fix-workflow-contract-smoke.py", - "tier": "default", - "reason": "guards the public issue-fix workflow contract, gated metadata preview, and todo writeback preview", - }, - { - "command": "python3 examples/issue-fix-repository-context-smoke.py", - "tier": "default", - "reason": "guards provenance-aware repository context, advisory experts, and feasibility domain-state integration", - }, - { - "command": "python3 examples/issue-fix-feasibility-smoke.py", - "tier": "default", - "reason": "guards single-route feasibility decisions and compact issue_fix domain-state writeback", - }, - { - "command": "python3 examples/issue-fix-pr-lifecycle-smoke.py", - "tier": "default", - "reason": "guards PR lifecycle transitions, terminal-state precedence, and issue_fix domain-state writeback", - }, - { - "command": "python3 examples/content-ops-issue-fix-intake-smoke.py", - "tier": "default", - "reason": "checks content-ops issue-fix intake from public metadata without external reads or writes", - }, - { - "command": "python3 examples/public_entry/readme-demo-surface-smoke.py", - "tier": "default", - "reason": "guards the README and cross-runtime implement/review demo entry surface", - }, - { - "command": "python3 examples/update-notes-archive-smoke.py", - "tier": "default", - "reason": "checks public update-note archive, automation wiring, and private-boundary exclusions", - }, - { - "command": "python3 examples/issue-fix-workflow-e2e-smoke.py", - "tier": "deep", - "reason": "runs the fuller issue-fix metadata-to-plan-to-review-packet product path", - }, - { - "command": "python3 examples/issue-fix-acceptance-loop-smoke.py", - "tier": "deep", - "reason": "samples the heavier caller-repo branch and acceptance-loop fixture", - }, - { - "command": "python3 examples/content-ops-private-connector-gate-smoke.py", - "tier": "deep", - "reason": "checks private connector owner-gate projection for content operations", - }, - ], - }, - { - "id": "issue-fix-reviewer-routing", - "title": "Issue-fix reviewer routing and bilingual guide", - "purpose": ( - "Check the bilingual issue-fix product entry and explainable local " - "reviewer recommendation plus authority-gated verified notification " - "contract." - ), - "catalog_families": ["Human Decision", "Evidence Lifecycle", "State And Boundary"], - "trigger_hints": ( - "reviewer-plan", - "reviewer recommendation", - "issue_fix_reviewer_recommendation", - "reviewer-request", - "issue_fix_reviewer_request", - "reviewer notification sink", - "issue_fix_reviewer_notification", - "loopx/capabilities/issue_fix/README", - "loopx/capabilities/issue_fix/docs/protocols/issue-fix-reviewer-recommendation", - "examples/issue-fix-capability-guide-smoke.py", - "examples/issue-fix-reviewer-recommendation-smoke.py", - "examples/issue-fix-reviewer-request-smoke.py", - "examples/issue-fix-reviewer-notification-drain-postwrite-smoke.py", - "loopx/capabilities/issue_fix/reviewer_notification_drain.py", - "examples/issue-fix-json-input-boundary-smoke.py", - "examples/issue-fix-reviewer-notification-sink-smoke.py", - "loopx/capabilities/issue_fix/cli.py", - "loopx/capabilities/issue_fix/reviewer_recommendation.py", - "loopx/capabilities/issue_fix/reviewer_request.py", - "loopx/capabilities/issue_fix/reviewer_notification.py", - ), - "checks": [ - { - "command": "python3 examples/issue-fix-json-input-boundary-smoke.py", - "tier": "default", - "reason": "guards bounded inline issue-fix JSON inputs and compact errors that never echo raw payloads", - }, - { - "command": "python3 examples/issue-fix-capability-guide-smoke.py", - "tier": "default", - "reason": "guards the bilingual issue-fix product entry, README links, reviewer protocol, and public-safe roadmap surface", - }, - { - "command": "python3 examples/issue-fix-reviewer-recommendation-smoke.py", - "tier": "default", - "reason": "guards explainable CODEOWNERS and base-revision changed-path/module-history reviewer recommendations", - }, - { - "command": "python3 examples/issue-fix-reviewer-request-smoke.py", - "tier": "default", - "reason": "guards author exclusion, formal-request-first notification, permission-only comment fallback, idempotency, blockers, and post-write verification", - }, - { - "command": "python3 examples/issue-fix-reviewer-notification-drain-postwrite-smoke.py", - "tier": "default", - "reason": "guards restart-safe drain writeback, unverified-send suppression, and semantic notification deduplication", - }, - { - "command": "python3 examples/issue-fix-reviewer-notification-sink-smoke.py", - "tier": "default", - "reason": "guards project-dedicated secondary notification identity, local-private mapping, idempotent send/readback, concrete gates, and public-safety redaction", - }, - ], - }, - { - "id": "issue-fix-outcome-visibility", - "title": "Issue-fix status and output visibility", - "purpose": ( - "Check the derived issue case read model and generic Kanban projection " - "without adding a parallel issue-fix state machine." - ), - "catalog_families": ["Evidence Lifecycle", "State And Boundary", "Work Routing"], - "trigger_hints": ( - "issue-fix outcome", - "issue_fix_outcome", - "outcome_projection", - "examples/issue-fix-outcome-projection-smoke.py", - "examples/issue-fix-validated-memory-writeback-smoke.py", - "loopx/capabilities/issue_fix/outcome_projection.py", - "loopx/capabilities/issue_fix/repository_memory_provider.py", - "loopx/capabilities/context_providers/service_ownership.py", - "loopx/extensions/lark/presentation/projection_rows.py", - "projection_source_reconcile", - ), - "checks": [ - { - "command": "python3 examples/issue-fix-outcome-projection-smoke.py", - "tier": "default", - "reason": "guards derived issue status/output cards, truthful delivery evidence, terminal visibility, and Lark projection reuse", - }, - { - "command": "python3 examples/issue-fix-validated-memory-writeback-smoke.py", - "tier": "default", - "reason": "guards explicit owner gating, validated distilled facts, idempotent provider writes, and unsafe-capture rejection", - }, - {"command": "python3 examples/context-provider-service-ownership-smoke.py", "tier": "default", "reason": "guards persistent ownership, restart detection, append-attempt accounting, and public-safe receipts"}, - {"command": "python3 examples/lark-projection-source-reconcile-smoke.py", - "tier": "default", "reason": "guards preview-first complete-source " - "orphan and stale-mapping reconciliation"}, - ], - }, - { - "id": "cross-runtime-impl-review-demo", - "title": "Cross-runtime implementation/review demo", - "purpose": ( - "Check the Claude Code implementation + Codex review demo packet " - "without writing state or launching either runtime." - ), - "catalog_families": [ - "Human Decision", - "Work Routing", - "Evidence Lifecycle", - "State And Boundary", - ], - "trigger_hints": ( - "cross-runtime", - "impl-review", - "claude implements", - "codex reviews", - "claude-code-impl", - "codex-review", - "loopx demo impl-review", - "cross_runtime_impl_review_demo_packet_v0", - "docs/product/use-cases/cross-runtime/cross-runtime-impl-review-demo.md", - "loopx/control_plane/handoff/cross_runtime_impl_review.py", - "loopx/cli_commands/starter.py", - ), - "checks": [ - { - "command": "python3 examples/cross-runtime-impl-review-demo-smoke.py", - "tier": "default", - "reason": "guards the dry-run packet, CLI route, role split, and no-write boundary", - }, - { - "command": "python3 examples/public_entry/readme-demo-surface-smoke.py", - "tier": "default", - "reason": "guards the public README and product note entry points for the demo", - }, - ], - }, - { - "id": "host-command-entry", - "title": "Host command entry and slash-command discovery", - "purpose": ( - "Check slash-command discovery, Codex App host command routing, " - "and global manager command entry surfaces without mutating project state." - ), - "catalog_families": ["Human Decision", "Work Routing", "State And Boundary"], - "trigger_hints": ( - "slash-command", - "slash command", - "slash-commands", - "/loopx-global-summary", - "/loopx-global-gates", - "/loopx-global-todos", - "/loopx-global-risks", - "global-manager", - "global manager", - "host command", - "host command registry", - "codex app host command", - "docs/reference/protocols/codex-app-host-command-registry-v0.md", - "docs/reference/protocols/global-manager-command-v0.md", - "loopx/cli_commands/slash_commands.py", - "loopx/cli_commands/summary_all.py", - ), - "checks": [ - { - "command": "python3 examples/slash-command-catalog-smoke.py", - "tier": "default", - "reason": "guards public slash-command discovery and legacy alias visibility", - }, - { - "command": "python3 examples/codex-app-host-command-registry-smoke.py", - "tier": "default", - "reason": "guards Codex App host command routing and fail-closed slash-command help", - }, - { - "command": "python3 examples/project/global-manager-command-protocol-smoke.py", - "tier": "default", - "reason": "checks read-only global manager command protocol and aliases", - }, - ], - }, - { - "id": "first-connect-contract", - "title": "First-connect contract", - "quality_risk": "high", - "purpose": ( - "Check fresh connection state, absence of first-connect todos, " - "state-gap detection, and domain-adapter routing ownership." - ), - "catalog_families": ["Work Routing", "State And Boundary"], - "trigger_hints": ( - "new user onboarding", - "first connect", - "first-connect contract", - "state projection gap", - "start-goal", - "loopx/bootstrap.py", - "loopx/bootstrap_command_pack.py", - "loopx/contract.py", - "loopx/state_projection.py", - "loopx/cli_commands/bootstrap_connect.py", - "loopx/cli_commands/starter_bootstrap.py", - "loopx/cli_commands/starter_bootstrap_registration.py", - ), - "checks": [ - { - "command": "python3 examples/project/first-connect-contract-smoke.py", - "tier": "default", - "reason": ( - "guards fresh connection state, first-connect todo absence, " - "state-gap warnings, and domain-adapter routing ownership" - ), - }, - ], - }, - { - "id": "runtime-connector-catalog", - "title": "Runtime connector catalog", - "purpose": ( - "Check Codex App heartbeat, Codex CLI TUI, Claude Code loop, " - "and worker bridge connector contracts from the public runtime catalog." - ), - "catalog_families": ["Work Routing", "State And Boundary", "Planning Governance"], - "trigger_hints": ( - "runtime connector", - "runtime connector catalog", - "runtime-connector-catalog", - "docs/integrations/runtime-connector-catalog.md", - "codex app heartbeat", - "codex_app_heartbeat", - "codex app ssh", - "codex_app_ssh_goal", - "codex cli tui", - "codex_cli_tui", - "claude code loop", - "claude_code_loop", - "shell worker", - "http webhook", - "worker bridge", - "worker_bridge", - "scheduler_hint", - "scoped identity", - "runtime loop", - "host runtime", - "computer use", - "computer_use_runtime", - "computer-use-runtime-v0", - ), - "checks": [ - { - "command": "python3 examples/control_plane/heartbeat-prompt-smoke.py", - "tier": "default", - "reason": "guards Codex App heartbeat identity, scheduler hints, and no-spend cadence behavior", - }, - { - "command": "python3 examples/codex-cli-bootstrap-message-smoke.py", - "tier": "default", - "reason": "checks Codex CLI TUI bootstrap message and scoped LoopX command contract", - }, - { - "command": "python3 examples/claude-goalmode-lifecycle-smoke.py", - "tier": "default", - "reason": "checks the Claude Code goal-mode loop lifecycle without production actions", - }, - { - "command": "python3 examples/cli-worker-bridge-command-modularization-smoke.py", - "tier": "default", - "reason": "checks the worker bridge install and active-user observation contracts without private runtime material", - }, - { - "command": "python3 examples/computer-use-runtime-contract-smoke.py", - "tier": "default", - "reason": "checks the computer_use_runtime_v0 provider boundary: gate-before-write, unknown-modal handling, raw-evidence stripping, and rejection of provider-authored writeback", - }, - { - "command": "python3 examples/host-integration-surface-smoke.py", - "tier": "deep", - "reason": "samples the broader host integration surface when connector catalog changes are promoted", - }, - ], - }, - { - "id": "frontstage-rollout", - "title": "Frontstage rollout projection", - "purpose": "Check public frontstage/showcase projection data before visual browser smokes.", - "catalog_families": ["State And Boundary", "Evidence Lifecycle", "Human Decision"], - "trigger_hints": ("frontstage", "showcase", "rollout", "dashboard", "visual"), - "checks": [ - { - "command": "python3 examples/frontstage-rollout-projections-fixture-smoke.py", - "tier": "default", - "reason": "checks reusable frontstage rollout projection fixtures", - }, - { - "command": "python3 examples/showcase-animation-prototype-smoke.py", - "tier": "default", - "reason": "guards showcase animation projection data without a browser", - }, - { - "command": "node examples/dashboard-frontstage-browser-smoke.mjs", - "tier": "deep", - "reason": "runs browser-level visual route validation when UI is promoted", - }, - ], - }, - { - "id": "explore-harness", - "title": "Explore Harness configuration and runtime", - "purpose": ( - "Check the deny-by-default goal boundary, planner agreement, resumable " - "runtime state, and per-item failure isolation." - ), - "catalog_families": ["Work Routing", "State And Boundary", "Evidence Lifecycle"], - "trigger_hints": ( - "explore harness", - "explore-harness", - "harness_runtime", - "harness_checkpoint", - "explore_harness", - "loopx/capabilities/explore", - "examples/explore-configure-goal-smoke.py", - "examples/explore-harness-runtime-resume-smoke.py", - ), - "checks": [ - { - "command": "python3 examples/explore-configure-goal-smoke.py", - "tier": "default", - "reason": "guards configure-goal opt-in and quota/planner boundary agreement", - }, - { - "command": "python3 examples/explore-harness-runtime-resume-smoke.py", - "tier": "default", - "reason": "guards validated resume state, novelty/variant restoration, and item failure isolation", - }, - { - "command": "python3 examples/explore-worker-plan-gate-smoke.py", - "tier": "default", - "reason": "guards profile pinning, analysis-only planning, and lane-width authority", - }, - { - "command": "python3 examples/explore-result-layer-smoke.py", - "tier": "deep", - "reason": "samples the wider Explore result and presentation contract", - }, - ], - }, - { - "id": "peer-agent-runtime", - "title": "Peer agent runtime and migration", - "quality_risk": "high", - "purpose": ( - "Check equal peer identity, deterministic task assignment, task-policy " - "completion, symmetric workspace isolation, task-scoped coordination, " - "and atomic registry/heartbeat migration." - ), - "catalog_families": ["Work Routing", "State And Boundary", "Evidence Lifecycle"], - "trigger_hints": ( - "peer agent", - "peer-agent", - "peer_v1", - "agent_model", - "excluded_agents", - "task_orchestration_contract", - "agent_workspace_guard", - "loopx/control_plane/quota/slot_accounting.py", - "loopx/control_plane/agents", - "loopx/control_plane/todos/completion_policy.py", - "loopx/control_plane/quota/task_orchestration.py", - "loopx/control_plane/goals/configure_goal_service.py", - "loopx/heartbeat_prompt.py", - "loopx/configure_goal.py", - "examples/project/configure-goal-global-sync-smoke.py", - ), - "checks": [ - { - "command": "python3 examples/project/configure-goal-global-sync-smoke.py", - "tier": "default", - "reason": "guards authoritative split-runtime configure-goal sync, explicit overrides, and exact readback", - }, - { - "command": "python3 examples/control_plane/peer-agent-runtime-v1-smoke.py", - "tier": "default", - "reason": "guards the complete peer identity, routing, completion, workspace, orchestration, migration, and host-loop contract", - }, - { - "command": "python3 examples/control_plane/agent-identity-readmodel-smoke.py", - "tier": "deep", - "reason": "guards rank-free peer identity and deterministic assignment", - }, - { - "command": "python3 examples/control_plane/quota-replan-decision-plane-smoke.py", - "tier": "deep", - "reason": "guards exactly-one peer ownership for unscoped replans", - }, - { - "command": "python3 examples/control_plane/todo-continuation-policy-smoke.py", - "tier": "deep", - "reason": "guards task-policy completion and independent review handoff", - }, - { - "command": "python3 examples/control_plane/peer-agent-migration-smoke.py", - "tier": "deep", - "reason": "guards atomic registry backup/cutover and peer heartbeat prompts", - }, - { - "command": "python3 examples/control_plane/peer-agent-workspace-guard-smoke.py", - "tier": "deep", - "reason": "guards symmetric write-aware worktree isolation in real git worktrees", - }, - { - "command": "python3 examples/control_plane/quota-spend-workspace-causality-smoke.py", - "tier": "deep", - "reason": "binds post-completion quota spend to the accountable delivery repository without weakening cross-repo isolation", - }, - { - "command": "python3 examples/control_plane/task-orchestration-smoke.py", - "tier": "deep", - "reason": "guards deterministic task-scoped coordination without durable leader authority", - }, - { - "command": "python3 examples/control_plane/agent-onboard-host-loop-activation-smoke.py", - "tier": "deep", - "reason": "guards rank-free host-loop identity selection and regeneration", - }, - ], - }, - { - "id": "catalog-canary-contract", - "title": "Catalog canary contract", - "purpose": "Check catalog-to-canary planning, JSON actionability, shell-free no-write execution, and full/module smoke-suite selection.", - "catalog_families": ["Planning Governance", "State And Boundary", "Work Routing"], - "trigger_hints": ( - "catalog canary", "canary planner", "canary runner", "canary plan", "canary run", - "smoke-suite", "run-smokes", "full smoke", "loopx/canary", "loopx/cli_commands/canary.py", - "examples/canary/catalog", "examples/run-smokes.py", - ), - "checks": [ - { - "command": "python3 examples/canary/catalog-planner-smoke.py", - "tier": "default", - "reason": "guards catalog coverage, selector routing, and actionable JSON plan commands", - }, - { - "command": "python3 examples/canary/catalog-run-e2e-smoke.py", - "tier": "default", - "reason": "guards shell-free no-write canary execution from the selected catalog plan", - }, - { - "command": "python3 examples/canary/smoke-suite-runner-smoke.py", - "tier": "default", - "reason": "guards full-public, module-filtered, and catalog-profile smoke-suite selection", - }, - { - "command": "python3 examples/canary/pytest-smoke-suite-facade-smoke.py", - "tier": "deep", - "reason": "guards optional pytest/JUnit reporting while keeping canary smoke-suite as source of truth", - }, - { - "command": "python3 examples/canary/quality-surface-catalog-smoke.py", - "tier": "deep", - "reason": "guards high-risk surface classification, independent semantic oracles, and explicit quality-layer gaps", - }, - ], - }, - *PACKAGE_QUALIFICATION_PROFILES, - { - "id": "benchmark-toolkit-boundary", - "title": "Benchmark toolkit boundary", - "purpose": "Check provider-neutral permission, artifact, candidate-source, and integrity boundaries without launching jobs.", - "catalog_families": ["Evidence Lifecycle", "State And Boundary", "Work Routing"], - "trigger_hints": ( - "benchmark", - "benchmark toolkit", - "benchmark research", - "loopx/capabilities/benchmark_toolkit", - "benchmark/", - "examples/benchmark", - ), - "checks": [ - { - "command": "python3 examples/benchmark-run-permission-policy-smoke.py", - "tier": "default", - "reason": "guards explicit execution and publication permission policy", - }, - { - "command": "python3 examples/benchmark-candidate-source-boundary-smoke.py", - "tier": "default", - "reason": "guards candidate selection against raw and private sources", - }, - { - "command": "python3 examples/benchmark-artifact-path-filter-smoke.py", - "tier": "default", - "reason": "guards raw/private benchmark artifact path exclusion", - }, - { - "command": "python3 -m pytest -q tests/capabilities/test_benchmark_toolkit.py", - "tier": "deep", - "reason": "checks integrity qualification and fail-closed public boundaries", - }, - ], - }, +CURRENT_REPO_PROFILES: tuple[Mapping[str, object], ...] = ( + *CORE_DOMAIN_PROFILES, + *WORKFLOW_DOMAIN_PROFILES, ) +__all__ = [ + "CANARY_PROFILE_SCHEMA_VERSION", + "CANARY_DOMAIN_PROFILE_SCHEMA_VERSION", + "CANARY_PROFILES_SCHEMA_VERSION", + "CANARY_PLAN_SCHEMA_VERSION", + "CANARY_COVERAGE_AUDIT_SCHEMA_VERSION", + "REPO_ROOT", + "DEFAULT_CATALOG_PATH", + "FAMILY_CHECKS", + "FAMILY_SELECTOR_HINTS", + "CURRENT_REPO_PROFILES", + "build_quality_surface_catalog_audit", + "resolve_canary_catalog_path", + "build_catalog_canary_profiles", + "build_catalog_canary_coverage_audit", + "flatten_catalog_canary_checks", + "build_catalog_canary_plan", + "render_catalog_canary_profiles_markdown", + "render_catalog_canary_plan_markdown", + "render_catalog_canary_coverage_audit_markdown", +] + def _quality_audit_source_root(candidate: Path | None) -> Path | None: source_root = (candidate or REPO_ROOT).resolve() @@ -1267,71 +79,34 @@ def _quality_audit_source_root(candidate: Path | None) -> Path | None: def build_quality_surface_catalog_audit( *, repo_root: Path | None = None, -) -> dict[str, Any]: +) -> dict[str, object]: """Audit quality-layer ownership for every high-risk canary profile.""" - return _build_quality_surface_catalog_audit( + raw_audit = _build_quality_surface_catalog_audit( CURRENT_REPO_PROFILES, repo_root=_quality_audit_source_root(repo_root), ) - - -def _slug(value: str) -> str: - return re.sub(r"[^a-z0-9]+", "-", value.lower()).strip("-") - - -def _catalog_profile_id(profile: dict[str, Any]) -> str: - return _slug(str(profile.get("id") or profile.get("family") or "")) - - -def _split_table_row(line: str) -> list[str]: - return [cell.strip() for cell in line.strip().strip("|").split("|")] - - -def _parse_markdown_table(lines: list[str]) -> list[dict[str, str]]: - rows = [_split_table_row(line) for line in lines if line.strip().startswith("|")] - if len(rows) < 3: - return [] - headers = rows[0] - parsed: list[dict[str, str]] = [] - for row in rows[2:]: - if len(row) != len(headers): - continue - parsed.append({headers[index]: value for index, value in enumerate(row)}) - return parsed - - -def _first_table_after(text: str, marker: str) -> list[dict[str, str]]: - index = text.find(marker) - if index < 0: - return [] - table_lines: list[str] = [] - in_table = False - for line in text[index:].splitlines(): - if line.strip().startswith("|"): - table_lines.append(line) - in_table = True - elif in_table: - break - return _parse_markdown_table(table_lines) - - -def _pattern_ids(value: str) -> list[str]: - return sorted(set(re.findall(r"\bIP-\d{3}\b", value))) - - -def _split_semicolon(value: str) -> list[str]: - return [item.strip() for item in value.split(";") if item.strip()] + audit: dict[str, object] = {} + for key, value in raw_audit.items(): + audit[str(key)] = value + return audit def resolve_canary_catalog_path( - catalog_path: Path | None = None, *, repo_root: Path | None = None, + catalog_path: Path | None = None, + *, + repo_root: Path | None = None, ) -> Path: """Resolve development inputs without treating an installed wheel as a checkout.""" - path = (catalog_path or ( - repo_root / "docs/concepts/interaction-pattern-catalog.md" - if repo_root is not None else DEFAULT_CATALOG_PATH - )).expanduser() + + path = ( + catalog_path + or ( + repo_root / "docs/concepts/interaction-pattern-catalog.md" + if repo_root is not None + else DEFAULT_CATALOG_PATH + ) + ).expanduser() if not path.is_file(): raise ValueError( f"canary catalog is missing: {path}; run from a complete LoopX source " @@ -1352,17 +127,19 @@ def _display_path(path: Path) -> str: return str(path) -def build_catalog_canary_profiles(catalog_path: Path | None = None) -> dict[str, Any]: +def build_catalog_canary_profiles(catalog_path: Path | None = None) -> dict[str, object]: + """Load canary family and domain profiles from the interaction pattern catalog.""" + path, text = _read_catalog(catalog_path) - archetype_rows = _first_table_after(text, "| Canary Archetype |") - family_rows = _first_table_after(text, "| Family |") + archetype_rows = first_table_after(text, "| Canary Archetype |") + family_rows = first_table_after(text, "| Family |") - archetypes = [] + archetypes: list[dict[str, str]] = [] for row in archetype_rows: name = row.get("Canary Archetype", "") archetypes.append( { - "id": _slug(name), + "id": slug(name), "name": name, "primary_question": row.get("Primary Question", ""), "trigger_surface": row.get("Typical Trigger Surface", ""), @@ -1372,19 +149,19 @@ def build_catalog_canary_profiles(catalog_path: Path | None = None) -> dict[str, } ) - profiles = [] + profiles: list[dict[str, object]] = [] for row in family_rows: family = row.get("Family", "") - archetype_names = _split_semicolon(row.get("Default Canary Archetypes", "")) + archetype_names = split_semicolon(row.get("Default Canary Archetypes", "")) profiles.append( { "schema_version": CANARY_PROFILE_SCHEMA_VERSION, - "id": _slug(family), + "id": slug(family), "family": family, - "pattern_ids": _pattern_ids(row.get("P0/P1 Pattern Coverage", "")), + "pattern_ids": pattern_ids(row.get("P0/P1 Pattern Coverage", "")), "default_archetypes": [ { - "id": _slug(name), + "id": slug(name), "name": name, } for name in archetype_names @@ -1396,13 +173,13 @@ def build_catalog_canary_profiles(catalog_path: Path | None = None) -> dict[str, } ) - domain_profiles = [] + domain_profiles: list[dict[str, object]] = [] for profile in CURRENT_REPO_PROFILES: domain_profiles.append( { "schema_version": CANARY_DOMAIN_PROFILE_SCHEMA_VERSION, **profile, - "checks": list(profile.get("checks", [])), + "checks": [dict(check) for check in mapping_list(profile, "checks")], } ) @@ -1421,83 +198,32 @@ def build_catalog_canary_profiles(catalog_path: Path | None = None) -> dict[str, } -def _catalog_pattern_rows(text: str) -> list[dict[str, str]]: - rows: list[dict[str, str]] = [] - for line in text.splitlines(): - if not line.strip().startswith("|"): - continue - cells = _split_table_row(line) - if len(cells) < 3: - continue - if cells[0] not in {"P0", "P1", "P2"} or not re.fullmatch(r"IP-\d{3}", cells[1]): - continue - rows.append( - { - "importance": cells[0], - "pattern_id": cells[1], - "name": cells[2], - } - ) - return rows - - -def _coverage_exception_rows(text: str) -> dict[str, dict[str, str]]: - table = _first_table_after(text, "| Pattern ID | Canary Coverage Status |") - exceptions: dict[str, dict[str, str]] = {} - for row in table: - pattern_id = next(iter(_pattern_ids(row.get("Pattern ID", ""))), "") - if not pattern_id: - continue - status = _slug(row.get("Canary Coverage Status", "")) - if status not in {"non-applicable", "not-applicable", "deferred"}: - continue - exceptions[pattern_id] = { - "pattern_id": pattern_id, - "status": "non-applicable" if status == "not-applicable" else status, - "rationale": row.get("Rationale", ""), - "owner": row.get("Owner", ""), - } - return exceptions - - -def _coverage_exception_is_valid(exception: dict[str, str]) -> bool: - status = exception.get("status") - rationale = bool(str(exception.get("rationale") or "").strip()) - owner = bool(str(exception.get("owner") or "").strip()) - if status == "non-applicable": - return rationale - if status == "deferred": - return rationale and owner - return False - - def build_catalog_canary_coverage_audit( *, catalog_path: Path | None = None, priorities: list[str] | None = None, -) -> dict[str, Any]: +) -> dict[str, object]: + """Audit catalog interaction-pattern coverage against canary profiles and exceptions.""" + path, text = _read_catalog(catalog_path) profile_packet = build_catalog_canary_profiles(catalog_path) required_priorities = tuple(priorities or ["P0", "P1"]) pattern_rows = [ row - for row in _catalog_pattern_rows(text) + for row in catalog_pattern_rows(text) if row.get("importance") in required_priorities ] profile_coverage: dict[str, list[str]] = {} - for profile in profile_packet.get("profiles", []): - if not isinstance(profile, dict): - continue + for profile in mapping_list(profile_packet, "profiles"): profile_id = str(profile.get("id") or "") - for pattern_id in profile.get("pattern_ids", []): - if isinstance(pattern_id, str): - profile_coverage.setdefault(pattern_id, []).append(profile_id) - exceptions = _coverage_exception_rows(text) - - covered: list[dict[str, Any]] = [] - excepted: list[dict[str, Any]] = [] - missing: list[dict[str, Any]] = [] - invalid_exceptions: list[dict[str, Any]] = [] + for pattern_id in string_list(profile, "pattern_ids"): + profile_coverage.setdefault(pattern_id, []).append(profile_id) + exceptions = coverage_exception_rows(text) + + covered: list[dict[str, object]] = [] + excepted: list[dict[str, object]] = [] + missing: list[dict[str, object]] = [] + invalid_exceptions: list[dict[str, object]] = [] for row in pattern_rows: pattern_id = row["pattern_id"] profile_ids = profile_coverage.get(pattern_id, []) @@ -1505,13 +231,13 @@ def build_catalog_canary_coverage_audit( covered.append({**row, "profile_ids": profile_ids}) continue exception = exceptions.get(pattern_id) - if exception and _coverage_exception_is_valid(exception): + if exception and coverage_exception_is_valid(exception): excepted.append({**row, **exception}) continue if exception: invalid_exceptions.append({**row, **exception}) else: - missing.append(row) + missing.append(dict(row)) drift_count = len(missing) + len(invalid_exceptions) return { @@ -1544,7 +270,7 @@ def _selector_blob(changed_files: list[str], surfaces: list[str]) -> str: return "\n".join([*changed_files, *surfaces]).lower() -def _selection_reasons(profile: dict[str, Any], selector_blob: str) -> list[str]: +def _selection_reasons(profile: Mapping[str, object], selector_blob: str) -> list[str]: family = str(profile.get("family") or "") family_lc = family.lower() reasons: list[str] = [] @@ -1560,7 +286,9 @@ def _selection_reasons(profile: dict[str, Any], selector_blob: str) -> list[str] return reasons -def _domain_selection_reasons(profile: dict[str, Any], selector_blob: str) -> list[str]: +def _domain_selection_reasons( + profile: Mapping[str, object], selector_blob: str, +) -> list[str]: reasons: list[str] = [] profile_id = str(profile.get("id") or "") title = str(profile.get("title") or "") @@ -1568,125 +296,98 @@ def _domain_selection_reasons(profile: dict[str, Any], selector_blob: str) -> li reasons.append(f"selector names profile `{profile_id}`") if title and title.lower() in selector_blob: reasons.append(f"selector names profile `{title}`") - for hint in profile.get("trigger_hints", []): - hint_text = str(hint or "").lower() + for hint in string_list(profile, "trigger_hints"): + hint_text = hint.lower() if hint_text and hint_text in selector_blob: reasons.append(f"selector matches `{hint}`") - for family in profile.get("catalog_families", []): - family_text = str(family or "").lower() + for family in string_list(profile, "catalog_families"): + family_text = family.lower() if family_text and family_text in selector_blob: reasons.append(f"selector matches family `{family}`") return reasons def _domain_profile_with_checks( - profile: dict[str, Any], + profile: Mapping[str, object], *, include_deep_checks: bool, max_checks: int, -) -> dict[str, Any]: +) -> dict[str, object]: + raw_checks = mapping_list(profile, "checks") checks = [ dict(check) - for check in profile.get("checks", []) + for check in raw_checks if include_deep_checks or check.get("tier") != "deep" ] copied = dict(profile) copied["checks"] = checks[: max(1, max_checks)] copied["deep_checks_available"] = any( - isinstance(check, dict) and check.get("tier") == "deep" - for check in profile.get("checks", []) + check.get("tier") == "deep" for check in raw_checks ) copied["deep_checks_included"] = bool(include_deep_checks) return copied -def flatten_catalog_canary_checks(plan: dict[str, Any]) -> list[dict[str, Any]]: +def flatten_catalog_canary_checks( + plan: Mapping[str, object], +) -> list[dict[str, object]]: """Return selected canary checks in execution order.""" - checks: list[dict[str, Any]] = [] + checks: list[dict[str, object]] = [] seen: set[str] = set() - for profile in plan.get("domain_profiles", []): - if not isinstance(profile, dict): - continue - for check in profile.get("checks", []): - if not isinstance(check, dict): - continue - command = str(check.get("command") or "") - if not command or command in seen: - continue - seen.add(command) - checks.append( - { - "source": "domain_profile", - "profile_id": profile.get("id"), - "profile_title": profile.get("title"), - "tier": check.get("tier") or "default", - **check, - } - ) - for profile in plan.get("profiles", []): - if not isinstance(profile, dict): - continue - for check in profile.get("candidate_checks", []): - if not isinstance(check, dict): - continue - command = str(check.get("command") or "") - if not command or command in seen: - continue - seen.add(command) - checks.append( - { - "source": "catalog_family", - "profile_id": profile.get("id"), - "profile_title": profile.get("family"), - "tier": check.get("tier") or "default", - **check, - } - ) + sources = ( + ("domain_profile", "domain_profiles", "checks", "title"), + ("catalog_family", "profiles", "candidate_checks", "family"), + ) + for source_name, profiles_key, checks_key, title_key in sources: + for profile in mapping_list(plan, profiles_key): + for check in mapping_list(profile, checks_key): + command = str(check.get("command") or "") + if not command or command in seen: + continue + seen.add(command) + checks.append( + { + "source": source_name, + "profile_id": profile.get("id"), + "profile_title": profile.get(title_key), + "tier": check.get("tier") or "default", + **check, + } + ) return checks -def build_catalog_canary_plan( +def _select_catalog_profiles( + profiles: list[Mapping[str, object]], *, - catalog_path: Path | None = None, - changed_files: list[str] | None = None, - surfaces: list[str] | None = None, - families: list[str] | None = None, - profiles: list[str] | None = None, - include_deep_checks: bool = False, - max_checks_per_family: int = 3, - max_checks_per_profile: int = 3, -) -> dict[str, Any]: - packet = build_catalog_canary_profiles(catalog_path) - changed_files = changed_files or [] - surfaces = surfaces or [] - requested_families = {_slug(family) for family in (families or []) if family.strip()} - requested_profiles = {_slug(profile) for profile in (profiles or []) if profile.strip()} - selector_blob = _selector_blob(changed_files, surfaces) - max_checks = max(1, max_checks_per_family) - max_profile_checks = max(1, max_checks_per_profile) - catalog_profile_ids = { - _catalog_profile_id(profile) - for profile in packet["profiles"] - if isinstance(profile, dict) - } - requested_catalog_profiles = requested_profiles & catalog_profile_ids - requested_domain_profiles = requested_profiles - requested_catalog_profiles - - selected_profiles: list[dict[str, Any]] = [] - for profile in packet["profiles"]: - profile_id = _catalog_profile_id(profile) - if requested_domain_profiles and not requested_catalog_profiles and not requested_families and not selector_blob: + selector_blob: str, + requested_families: set[str], + requested_catalog_profiles: set[str], + requested_domain_profiles: set[str], + max_checks: int, +) -> list[dict[str, object]]: + selected: list[dict[str, object]] = [] + for profile in profiles: + profile_id = catalog_profile_id(profile) + if ( + requested_domain_profiles + and not requested_catalog_profiles + and not requested_families + and not selector_blob + ): continue reasons = _selection_reasons(profile, selector_blob) if requested_catalog_profiles and profile_id not in requested_catalog_profiles: continue - if requested_families and _slug(str(profile.get("family") or "")) not in requested_families: + if requested_families and slug(str(profile.get("family") or "")) not in requested_families: continue if not requested_catalog_profiles and not requested_families and selector_blob and not reasons: continue profile_copy = dict(profile) - profile_copy["candidate_checks"] = list(profile_copy.get("candidate_checks", []))[:max_checks] + profile_copy["candidate_checks"] = [ + dict(check) for check in mapping_list(profile_copy, "candidate_checks") + ][:max_checks] if requested_catalog_profiles and profile_id in requested_catalog_profiles: profile_copy["selection_reasons"] = reasons or [ "selected because this catalog profile was explicitly requested", @@ -1695,12 +396,26 @@ def build_catalog_canary_plan( profile_copy["selection_reasons"] = reasons or [ "selected because no narrower selector was provided", ] - selected_profiles.append(profile_copy) + selected.append(profile_copy) + return selected - selected_domain_profiles: list[dict[str, Any]] = [] - for profile in packet["domain_profiles"]: + +def _select_domain_profiles( + profiles: list[Mapping[str, object]], + *, + selector_blob: str, + requested_catalog_profiles: set[str], + requested_domain_profiles: set[str], + include_deep_checks: bool, + max_profile_checks: int, +) -> list[dict[str, object]]: + selected: list[dict[str, object]] = [] + for profile in profiles: reasons = _domain_selection_reasons(profile, selector_blob) - if requested_domain_profiles and _slug(str(profile.get("id") or "")) not in requested_domain_profiles: + if ( + requested_domain_profiles + and slug(str(profile.get("id") or "")) not in requested_domain_profiles + ): continue if requested_catalog_profiles and not requested_domain_profiles: continue @@ -1716,9 +431,54 @@ def build_catalog_canary_plan( profile_copy["selection_reasons"] = reasons or [ "selected because this profile was explicitly requested", ] - selected_domain_profiles.append(profile_copy) + selected.append(profile_copy) + return selected + - payload = { +def build_catalog_canary_plan( + *, + catalog_path: Path | None = None, + changed_files: list[str] | None = None, + surfaces: list[str] | None = None, + families: list[str] | None = None, + profiles: list[str] | None = None, + include_deep_checks: bool = False, + max_checks_per_family: int = 3, + max_checks_per_profile: int = 3, +) -> dict[str, object]: + """Select catalog family and repo domain canary checks for a scope or diff.""" + + packet = build_catalog_canary_profiles(catalog_path) + changed_files = changed_files or [] + surfaces = surfaces or [] + requested_families = {slug(family) for family in (families or []) if family.strip()} + requested_profiles = {slug(profile) for profile in (profiles or []) if profile.strip()} + selector_blob = _selector_blob(changed_files, surfaces) + max_checks = max(1, max_checks_per_family) + max_profile_checks = max(1, max_checks_per_profile) + catalog_profiles = mapping_list(packet, "profiles") + catalog_profile_ids = {catalog_profile_id(profile) for profile in catalog_profiles} + requested_catalog_profiles = requested_profiles & catalog_profile_ids + requested_domain_profiles = requested_profiles - requested_catalog_profiles + + selected_profiles = _select_catalog_profiles( + catalog_profiles, + selector_blob=selector_blob, + requested_families=requested_families, + requested_catalog_profiles=requested_catalog_profiles, + requested_domain_profiles=requested_domain_profiles, + max_checks=max_checks, + ) + selected_domain_profiles = _select_domain_profiles( + mapping_list(packet, "domain_profiles"), + selector_blob=selector_blob, + requested_catalog_profiles=requested_catalog_profiles, + requested_domain_profiles=requested_domain_profiles, + include_deep_checks=include_deep_checks, + max_profile_checks=max_profile_checks, + ) + + payload: dict[str, object] = { "ok": True, "schema_version": CANARY_PLAN_SCHEMA_VERSION, "source": packet["source"], @@ -1750,165 +510,3 @@ def build_catalog_canary_plan( payload["suggested_checks"] = suggested_checks payload["commands"] = [str(check.get("command") or "") for check in suggested_checks] return payload - - -def render_catalog_canary_profiles_markdown(payload: dict[str, Any]) -> str: - lines = [ - "# Catalog Canary Profiles", - "", - f"- source: `{payload.get('source')}`", - f"- archetypes: `{payload.get('archetype_count')}`", - f"- profiles: `{payload.get('profile_count')}`", - "- dry_run: `true`", - "- executes_checks: `false`", - "", - ] - for profile in payload.get("profiles", []): - if not isinstance(profile, dict): - continue - lines.extend( - [ - f"## {profile.get('family')}", - f"- patterns: `{', '.join(profile.get('pattern_ids') or [])}`", - "- archetypes: " - + ", ".join( - f"`{item.get('name')}`" - for item in profile.get("default_archetypes", []) - if isinstance(item, dict) - ), - f"- trigger surfaces: {profile.get('trigger_surfaces')}", - f"- minimum fixture: {profile.get('minimum_useful_fixture')}", - f"- failure meaning: {profile.get('failure_meaning')}", - "", - ] - ) - if payload.get("domain_profiles"): - lines.extend(["## Current Repo Profiles", ""]) - for profile in payload.get("domain_profiles", []): - if not isinstance(profile, dict): - continue - default_count = sum( - 1 for check in profile.get("checks", []) if isinstance(check, dict) and check.get("tier") != "deep" - ) - deep_count = sum( - 1 for check in profile.get("checks", []) if isinstance(check, dict) and check.get("tier") == "deep" - ) - lines.extend( - [ - f"### {profile.get('title')}", - f"- id: `{profile.get('id')}`", - f"- catalog families: `{', '.join(profile.get('catalog_families') or [])}`", - f"- purpose: {profile.get('purpose')}", - f"- default checks: `{default_count}`", - f"- deep checks: `{deep_count}`", - "", - ] - ) - return "\n".join(lines).rstrip() + "\n" - - -def render_catalog_canary_plan_markdown(payload: dict[str, Any]) -> str: - inputs_value = payload.get('selection_inputs') - inputs = inputs_value if isinstance(inputs_value, dict) else {} - lines = [ - "# Catalog Canary Plan", - "", - f"- source: `{payload.get('source')}`", - "- dry_run: `true`", - "- executes_checks: `false`", - f"- selected_profiles: `{payload.get('profile_count')}`", - f"- selected_domain_profiles: `{payload.get('domain_profile_count')}`", - f"- changed_files: `{', '.join(inputs.get('changed_files') or [])}`", - f"- surfaces: `{', '.join(inputs.get('surfaces') or [])}`", - f"- families: `{', '.join(inputs.get('families') or [])}`", - f"- profiles: `{', '.join(inputs.get('profiles') or [])}`", - f"- include_deep_checks: `{str(inputs.get('include_deep_checks')).lower()}`", - "", - str(payload.get("note") or ""), - "", - ] - for profile in payload.get("profiles", []): - if not isinstance(profile, dict): - continue - lines.extend( - [ - f"## {profile.get('family')}", - f"- patterns: `{', '.join(profile.get('pattern_ids') or [])}`", - "- selected because: " - + "; ".join(str(reason) for reason in profile.get("selection_reasons", [])), - "- archetypes: " - + ", ".join( - f"`{item.get('name')}`" - for item in profile.get("default_archetypes", []) - if isinstance(item, dict) - ), - f"- minimum fixture: {profile.get('minimum_useful_fixture')}", - f"- failure meaning: {profile.get('failure_meaning')}", - "- suggested checks:", - ] - ) - for check in profile.get("candidate_checks", []): - if isinstance(check, dict): - lines.append(f" - `{check.get('command')}` - {check.get('reason')}") - lines.append("") - for profile in payload.get("domain_profiles", []): - if not isinstance(profile, dict): - continue - lines.extend( - [ - f"## {profile.get('title')}", - f"- id: `{profile.get('id')}`", - f"- catalog families: `{', '.join(profile.get('catalog_families') or [])}`", - "- selected because: " - + "; ".join(str(reason) for reason in profile.get("selection_reasons", [])), - f"- purpose: {profile.get('purpose')}", - f"- deep checks available: `{str(profile.get('deep_checks_available')).lower()}`", - f"- deep checks included: `{str(profile.get('deep_checks_included')).lower()}`", - "- suggested checks:", - ] - ) - for check in profile.get("checks", []): - if isinstance(check, dict): - lines.append( - f" - `{check.get('command')}` [{check.get('tier')}] - {check.get('reason')}" - ) - lines.append("") - return "\n".join(lines).rstrip() + "\n" - - -def render_catalog_canary_coverage_audit_markdown(payload: dict[str, Any]) -> str: - lines = [ - "# Catalog Canary Coverage Audit", - "", - f"- source: `{payload.get('source')}`", - "- dry_run: `true`", - "- executes_checks: `false`", - f"- priorities: `{', '.join(payload.get('priorities') or [])}`", - f"- required_patterns: `{payload.get('required_pattern_count')}`", - f"- covered: `{payload.get('covered_count')}`", - f"- excepted: `{payload.get('excepted_count')}`", - f"- missing: `{payload.get('missing_count')}`", - f"- invalid_exceptions: `{payload.get('invalid_exception_count')}`", - f"- drift: `{payload.get('drift_count')}`", - "", - str(payload.get("note") or ""), - "", - ] - if payload.get("missing_patterns"): - lines.extend(["## Missing Coverage", ""]) - for row in payload.get("missing_patterns", []): - if isinstance(row, dict): - lines.append( - f"- `{row.get('pattern_id')}` {row.get('name')} ({row.get('importance')})" - ) - lines.append("") - if payload.get("invalid_exceptions"): - lines.extend(["## Invalid Exceptions", ""]) - for row in payload.get("invalid_exceptions", []): - if isinstance(row, dict): - lines.append( - f"- `{row.get('pattern_id')}` {row.get('status')}: " - f"rationale={row.get('rationale')!r}; owner={row.get('owner')!r}" - ) - lines.append("") - return "\n".join(lines).rstrip() + "\n" diff --git a/loopx/canary/workflow_domain_profiles.py b/loopx/canary/workflow_domain_profiles.py new file mode 100644 index 0000000000..7a52e23f20 --- /dev/null +++ b/loopx/canary/workflow_domain_profiles.py @@ -0,0 +1,600 @@ +"""Product-entry, runtime, connector, and package canary domain profiles.""" + +from __future__ import annotations + +from collections.abc import Mapping + +from .package_profiles import PACKAGE_QUALIFICATION_PROFILES + + +WORKFLOW_DOMAIN_PROFILES: tuple[Mapping[str, object], ...] = ( + { + "id": "product-entry-workflows", + "title": "Product entry workflows", + "purpose": ( + "Check user-facing product entry routes for issue-fix, content-ops, " + "update notes, and cross-runtime demo surfaces without reading private sources." + ), + "catalog_families": ["Human Decision", "Evidence Lifecycle", "State And Boundary", "Work Routing"], + "trigger_hints": ( + "product-entry", + "product entry", + "issue-fix", + "issue fix", + "content-ops", + "content ops", + "update-note", + "update note", + "update-notes", + "update notes", + "cross-runtime", + "impl-review", + "claude implements", + "codex reviews", + "README.md", + "docs/product/use-cases/cross-runtime/cross-runtime-impl-review-demo.md", + "loopx/capabilities/issue_fix", + "loopx/capabilities/content_ops", + "docs/update-notes", + "loopx/cli_commands/issue_fix", + "loopx/cli_commands/content_ops", + "scripts/update_notes_release_job.py", + ), + "checks": [ + { + "command": "python3 examples/issue-fix-workflow-contract-smoke.py", + "tier": "default", + "reason": "guards the public issue-fix workflow contract, gated metadata preview, and todo writeback preview", + }, + { + "command": "python3 examples/issue-fix-repository-context-smoke.py", + "tier": "default", + "reason": "guards provenance-aware repository context, advisory experts, and feasibility domain-state integration", + }, + { + "command": "python3 examples/issue-fix-feasibility-smoke.py", + "tier": "default", + "reason": "guards single-route feasibility decisions and compact issue_fix domain-state writeback", + }, + { + "command": "python3 examples/issue-fix-pr-lifecycle-smoke.py", + "tier": "default", + "reason": "guards PR lifecycle transitions, terminal-state precedence, and issue_fix domain-state writeback", + }, + { + "command": "python3 examples/content-ops-issue-fix-intake-smoke.py", + "tier": "default", + "reason": "checks content-ops issue-fix intake from public metadata without external reads or writes", + }, + { + "command": "python3 examples/public_entry/readme-demo-surface-smoke.py", + "tier": "default", + "reason": "guards the README and cross-runtime implement/review demo entry surface", + }, + { + "command": "python3 examples/update-notes-archive-smoke.py", + "tier": "default", + "reason": "checks public update-note archive, automation wiring, and private-boundary exclusions", + }, + { + "command": "python3 examples/issue-fix-workflow-e2e-smoke.py", + "tier": "deep", + "reason": "runs the fuller issue-fix metadata-to-plan-to-review-packet product path", + }, + { + "command": "python3 examples/issue-fix-acceptance-loop-smoke.py", + "tier": "deep", + "reason": "samples the heavier caller-repo branch and acceptance-loop fixture", + }, + { + "command": "python3 examples/content-ops-private-connector-gate-smoke.py", + "tier": "deep", + "reason": "checks private connector owner-gate projection for content operations", + }, + ], + }, + { + "id": "issue-fix-reviewer-routing", + "title": "Issue-fix reviewer routing and bilingual guide", + "purpose": ( + "Check the bilingual issue-fix product entry and explainable local " + "reviewer recommendation plus authority-gated verified notification " + "contract." + ), + "catalog_families": ["Human Decision", "Evidence Lifecycle", "State And Boundary"], + "trigger_hints": ( + "reviewer-plan", + "reviewer recommendation", + "issue_fix_reviewer_recommendation", + "reviewer-request", + "issue_fix_reviewer_request", + "reviewer notification sink", + "issue_fix_reviewer_notification", + "loopx/capabilities/issue_fix/README", + "loopx/capabilities/issue_fix/docs/protocols/issue-fix-reviewer-recommendation", + "examples/issue-fix-capability-guide-smoke.py", + "examples/issue-fix-reviewer-recommendation-smoke.py", + "examples/issue-fix-reviewer-request-smoke.py", + "examples/issue-fix-reviewer-notification-drain-postwrite-smoke.py", + "loopx/capabilities/issue_fix/reviewer_notification_drain.py", + "examples/issue-fix-json-input-boundary-smoke.py", + "examples/issue-fix-reviewer-notification-sink-smoke.py", + "loopx/capabilities/issue_fix/cli.py", + "loopx/capabilities/issue_fix/reviewer_recommendation.py", + "loopx/capabilities/issue_fix/reviewer_request.py", + "loopx/capabilities/issue_fix/reviewer_notification.py", + ), + "checks": [ + { + "command": "python3 examples/issue-fix-json-input-boundary-smoke.py", + "tier": "default", + "reason": "guards bounded inline issue-fix JSON inputs and compact errors that never echo raw payloads", + }, + { + "command": "python3 examples/issue-fix-capability-guide-smoke.py", + "tier": "default", + "reason": "guards the bilingual issue-fix product entry, README links, reviewer protocol, and public-safe roadmap surface", + }, + { + "command": "python3 examples/issue-fix-reviewer-recommendation-smoke.py", + "tier": "default", + "reason": "guards explainable CODEOWNERS and base-revision changed-path/module-history reviewer recommendations", + }, + { + "command": "python3 examples/issue-fix-reviewer-request-smoke.py", + "tier": "default", + "reason": "guards author exclusion, formal-request-first notification, permission-only comment fallback, idempotency, blockers, and post-write verification", + }, + { + "command": "python3 examples/issue-fix-reviewer-notification-drain-postwrite-smoke.py", + "tier": "default", + "reason": "guards restart-safe drain writeback, unverified-send suppression, and semantic notification deduplication", + }, + { + "command": "python3 examples/issue-fix-reviewer-notification-sink-smoke.py", + "tier": "default", + "reason": "guards project-dedicated secondary notification identity, local-private mapping, idempotent send/readback, concrete gates, and public-safety redaction", + }, + ], + }, + { + "id": "issue-fix-outcome-visibility", + "title": "Issue-fix status and output visibility", + "purpose": ( + "Check the derived issue case read model and generic Kanban projection " + "without adding a parallel issue-fix state machine." + ), + "catalog_families": ["Evidence Lifecycle", "State And Boundary", "Work Routing"], + "trigger_hints": ( + "issue-fix outcome", + "issue_fix_outcome", + "outcome_projection", + "examples/issue-fix-outcome-projection-smoke.py", + "examples/issue-fix-validated-memory-writeback-smoke.py", + "loopx/capabilities/issue_fix/outcome_projection.py", + "loopx/capabilities/issue_fix/repository_memory_provider.py", + "loopx/capabilities/context_providers/service_ownership.py", + "loopx/extensions/lark/presentation/projection_rows.py", + "projection_source_reconcile", + ), + "checks": [ + { + "command": "python3 examples/issue-fix-outcome-projection-smoke.py", + "tier": "default", + "reason": "guards derived issue status/output cards, truthful delivery evidence, terminal visibility, and Lark projection reuse", + }, + { + "command": "python3 examples/issue-fix-validated-memory-writeback-smoke.py", + "tier": "default", + "reason": "guards explicit owner gating, validated distilled facts, idempotent provider writes, and unsafe-capture rejection", + }, + {"command": "python3 examples/context-provider-service-ownership-smoke.py", "tier": "default", "reason": "guards persistent ownership, restart detection, append-attempt accounting, and public-safe receipts"}, + {"command": "python3 examples/lark-projection-source-reconcile-smoke.py", + "tier": "default", "reason": "guards preview-first complete-source " + "orphan and stale-mapping reconciliation"}, + ], + }, + { + "id": "cross-runtime-impl-review-demo", + "title": "Cross-runtime implementation/review demo", + "purpose": ( + "Check the Claude Code implementation + Codex review demo packet " + "without writing state or launching either runtime." + ), + "catalog_families": [ + "Human Decision", + "Work Routing", + "Evidence Lifecycle", + "State And Boundary", + ], + "trigger_hints": ( + "cross-runtime", + "impl-review", + "claude implements", + "codex reviews", + "claude-code-impl", + "codex-review", + "loopx demo impl-review", + "cross_runtime_impl_review_demo_packet_v0", + "docs/product/use-cases/cross-runtime/cross-runtime-impl-review-demo.md", + "loopx/control_plane/handoff/cross_runtime_impl_review.py", + "loopx/cli_commands/starter.py", + ), + "checks": [ + { + "command": "python3 examples/cross-runtime-impl-review-demo-smoke.py", + "tier": "default", + "reason": "guards the dry-run packet, CLI route, role split, and no-write boundary", + }, + { + "command": "python3 examples/public_entry/readme-demo-surface-smoke.py", + "tier": "default", + "reason": "guards the public README and product note entry points for the demo", + }, + ], + }, + { + "id": "host-command-entry", + "title": "Host command entry and slash-command discovery", + "purpose": ( + "Check slash-command discovery, Codex App host command routing, " + "and global manager command entry surfaces without mutating project state." + ), + "catalog_families": ["Human Decision", "Work Routing", "State And Boundary"], + "trigger_hints": ( + "slash-command", + "slash command", + "slash-commands", + "/loopx-global-summary", + "/loopx-global-gates", + "/loopx-global-todos", + "/loopx-global-risks", + "global-manager", + "global manager", + "host command", + "host command registry", + "codex app host command", + "docs/reference/protocols/codex-app-host-command-registry-v0.md", + "docs/reference/protocols/global-manager-command-v0.md", + "loopx/cli_commands/slash_commands.py", + "loopx/cli_commands/summary_all.py", + ), + "checks": [ + { + "command": "python3 examples/slash-command-catalog-smoke.py", + "tier": "default", + "reason": "guards public slash-command discovery and legacy alias visibility", + }, + { + "command": "python3 examples/codex-app-host-command-registry-smoke.py", + "tier": "default", + "reason": "guards Codex App host command routing and fail-closed slash-command help", + }, + { + "command": "python3 examples/project/global-manager-command-protocol-smoke.py", + "tier": "default", + "reason": "checks read-only global manager command protocol and aliases", + }, + ], + }, + { + "id": "first-connect-contract", + "title": "First-connect contract", + "quality_risk": "high", + "purpose": ( + "Check fresh connection state, absence of first-connect todos, " + "state-gap detection, and domain-adapter routing ownership." + ), + "catalog_families": ["Work Routing", "State And Boundary"], + "trigger_hints": ( + "new user onboarding", + "first connect", + "first-connect contract", + "state projection gap", + "start-goal", + "loopx/bootstrap.py", + "loopx/bootstrap_command_pack.py", + "loopx/contract.py", + "loopx/state_projection.py", + "loopx/cli_commands/bootstrap_connect.py", + "loopx/cli_commands/starter_bootstrap.py", + "loopx/cli_commands/starter_bootstrap_registration.py", + ), + "checks": [ + { + "command": "python3 examples/project/first-connect-contract-smoke.py", + "tier": "default", + "reason": ( + "guards fresh connection state, first-connect todo absence, " + "state-gap warnings, and domain-adapter routing ownership" + ), + }, + ], + }, + { + "id": "runtime-connector-catalog", + "title": "Runtime connector catalog", + "purpose": ( + "Check Codex App heartbeat, Codex CLI TUI, Claude Code loop, " + "and worker bridge connector contracts from the public runtime catalog." + ), + "catalog_families": ["Work Routing", "State And Boundary", "Planning Governance"], + "trigger_hints": ( + "runtime connector", + "runtime connector catalog", + "runtime-connector-catalog", + "docs/integrations/runtime-connector-catalog.md", + "codex app heartbeat", + "codex_app_heartbeat", + "codex app ssh", + "codex_app_ssh_goal", + "codex cli tui", + "codex_cli_tui", + "claude code loop", + "claude_code_loop", + "shell worker", + "http webhook", + "worker bridge", + "worker_bridge", + "scheduler_hint", + "scoped identity", + "runtime loop", + "host runtime", + "computer use", + "computer_use_runtime", + "computer-use-runtime-v0", + ), + "checks": [ + { + "command": "python3 examples/control_plane/heartbeat-prompt-smoke.py", + "tier": "default", + "reason": "guards Codex App heartbeat identity, scheduler hints, and no-spend cadence behavior", + }, + { + "command": "python3 examples/codex-cli-bootstrap-message-smoke.py", + "tier": "default", + "reason": "checks Codex CLI TUI bootstrap message and scoped LoopX command contract", + }, + { + "command": "python3 examples/claude-goalmode-lifecycle-smoke.py", + "tier": "default", + "reason": "checks the Claude Code goal-mode loop lifecycle without production actions", + }, + { + "command": "python3 examples/cli-worker-bridge-command-modularization-smoke.py", + "tier": "default", + "reason": "checks the worker bridge install and active-user observation contracts without private runtime material", + }, + { + "command": "python3 examples/computer-use-runtime-contract-smoke.py", + "tier": "default", + "reason": "checks the computer_use_runtime_v0 provider boundary: gate-before-write, unknown-modal handling, raw-evidence stripping, and rejection of provider-authored writeback", + }, + { + "command": "python3 examples/host-integration-surface-smoke.py", + "tier": "deep", + "reason": "samples the broader host integration surface when connector catalog changes are promoted", + }, + ], + }, + { + "id": "frontstage-rollout", + "title": "Frontstage rollout projection", + "purpose": "Check public frontstage/showcase projection data before visual browser smokes.", + "catalog_families": ["State And Boundary", "Evidence Lifecycle", "Human Decision"], + "trigger_hints": ("frontstage", "showcase", "rollout", "dashboard", "visual"), + "checks": [ + { + "command": "python3 examples/frontstage-rollout-projections-fixture-smoke.py", + "tier": "default", + "reason": "checks reusable frontstage rollout projection fixtures", + }, + { + "command": "python3 examples/showcase-animation-prototype-smoke.py", + "tier": "default", + "reason": "guards showcase animation projection data without a browser", + }, + { + "command": "node examples/dashboard-frontstage-browser-smoke.mjs", + "tier": "deep", + "reason": "runs browser-level visual route validation when UI is promoted", + }, + ], + }, + { + "id": "explore-harness", + "title": "Explore Harness configuration and runtime", + "purpose": ( + "Check the deny-by-default goal boundary, planner agreement, resumable " + "runtime state, and per-item failure isolation." + ), + "catalog_families": ["Work Routing", "State And Boundary", "Evidence Lifecycle"], + "trigger_hints": ( + "explore harness", + "explore-harness", + "harness_runtime", + "harness_checkpoint", + "explore_harness", + "loopx/capabilities/explore", + "examples/explore-configure-goal-smoke.py", + "examples/explore-harness-runtime-resume-smoke.py", + ), + "checks": [ + { + "command": "python3 examples/explore-configure-goal-smoke.py", + "tier": "default", + "reason": "guards configure-goal opt-in and quota/planner boundary agreement", + }, + { + "command": "python3 examples/explore-harness-runtime-resume-smoke.py", + "tier": "default", + "reason": "guards validated resume state, novelty/variant restoration, and item failure isolation", + }, + { + "command": "python3 examples/explore-worker-plan-gate-smoke.py", + "tier": "default", + "reason": "guards profile pinning, analysis-only planning, and lane-width authority", + }, + { + "command": "python3 examples/explore-result-layer-smoke.py", + "tier": "deep", + "reason": "samples the wider Explore result and presentation contract", + }, + ], + }, + { + "id": "peer-agent-runtime", + "title": "Peer agent runtime and migration", + "quality_risk": "high", + "purpose": ( + "Check equal peer identity, deterministic task assignment, task-policy " + "completion, symmetric workspace isolation, task-scoped coordination, " + "and atomic registry/heartbeat migration." + ), + "catalog_families": ["Work Routing", "State And Boundary", "Evidence Lifecycle"], + "trigger_hints": ( + "peer agent", + "peer-agent", + "peer_v1", + "agent_model", + "excluded_agents", + "task_orchestration_contract", + "agent_workspace_guard", + "loopx/control_plane/quota/slot_accounting.py", + "loopx/control_plane/agents", + "loopx/control_plane/todos/completion_policy.py", + "loopx/control_plane/quota/task_orchestration.py", + "loopx/control_plane/goals/configure_goal_service.py", + "loopx/heartbeat_prompt.py", + "loopx/configure_goal.py", + "examples/project/configure-goal-global-sync-smoke.py", + ), + "checks": [ + { + "command": "python3 examples/project/configure-goal-global-sync-smoke.py", + "tier": "default", + "reason": "guards authoritative split-runtime configure-goal sync, explicit overrides, and exact readback", + }, + { + "command": "python3 examples/control_plane/peer-agent-runtime-v1-smoke.py", + "tier": "default", + "reason": "guards the complete peer identity, routing, completion, workspace, orchestration, migration, and host-loop contract", + }, + { + "command": "python3 examples/control_plane/agent-identity-readmodel-smoke.py", + "tier": "deep", + "reason": "guards rank-free peer identity and deterministic assignment", + }, + { + "command": "python3 examples/control_plane/quota-replan-decision-plane-smoke.py", + "tier": "deep", + "reason": "guards exactly-one peer ownership for unscoped replans", + }, + { + "command": "python3 examples/control_plane/todo-continuation-policy-smoke.py", + "tier": "deep", + "reason": "guards task-policy completion and independent review handoff", + }, + { + "command": "python3 examples/control_plane/peer-agent-migration-smoke.py", + "tier": "deep", + "reason": "guards atomic registry backup/cutover and peer heartbeat prompts", + }, + { + "command": "python3 examples/control_plane/peer-agent-workspace-guard-smoke.py", + "tier": "deep", + "reason": "guards symmetric write-aware worktree isolation in real git worktrees", + }, + { + "command": "python3 examples/control_plane/quota-spend-workspace-causality-smoke.py", + "tier": "deep", + "reason": "binds post-completion quota spend to the accountable delivery repository without weakening cross-repo isolation", + }, + { + "command": "python3 examples/control_plane/task-orchestration-smoke.py", + "tier": "deep", + "reason": "guards deterministic task-scoped coordination without durable leader authority", + }, + { + "command": "python3 examples/control_plane/agent-onboard-host-loop-activation-smoke.py", + "tier": "deep", + "reason": "guards rank-free host-loop identity selection and regeneration", + }, + ], + }, + { + "id": "catalog-canary-contract", + "title": "Catalog canary contract", + "purpose": "Check catalog-to-canary planning, JSON actionability, shell-free no-write execution, and full/module smoke-suite selection.", + "catalog_families": ["Planning Governance", "State And Boundary", "Work Routing"], + "trigger_hints": ( + "catalog canary", "canary planner", "canary runner", "canary plan", "canary run", + "smoke-suite", "run-smokes", "full smoke", "loopx/canary", "loopx/cli_commands/canary.py", + "examples/canary/catalog", "examples/run-smokes.py", + ), + "checks": [ + { + "command": "python3 examples/canary/catalog-planner-smoke.py", + "tier": "default", + "reason": "guards catalog coverage, selector routing, and actionable JSON plan commands", + }, + { + "command": "python3 examples/canary/catalog-run-e2e-smoke.py", + "tier": "default", + "reason": "guards shell-free no-write canary execution from the selected catalog plan", + }, + { + "command": "python3 examples/canary/smoke-suite-runner-smoke.py", + "tier": "default", + "reason": "guards full-public, module-filtered, and catalog-profile smoke-suite selection", + }, + { + "command": "python3 examples/canary/pytest-smoke-suite-facade-smoke.py", + "tier": "deep", + "reason": "guards optional pytest/JUnit reporting while keeping canary smoke-suite as source of truth", + }, + { + "command": "python3 examples/canary/quality-surface-catalog-smoke.py", + "tier": "deep", + "reason": "guards high-risk surface classification, independent semantic oracles, and explicit quality-layer gaps", + }, + ], + }, + *PACKAGE_QUALIFICATION_PROFILES, + { + "id": "benchmark-toolkit-boundary", + "title": "Benchmark toolkit boundary", + "purpose": "Check provider-neutral permission, artifact, candidate-source, and integrity boundaries without launching jobs.", + "catalog_families": ["Evidence Lifecycle", "State And Boundary", "Work Routing"], + "trigger_hints": ( + "benchmark", + "benchmark toolkit", + "benchmark research", + "loopx/capabilities/benchmark_toolkit", + "benchmark/", + "examples/benchmark", + ), + "checks": [ + { + "command": "python3 examples/benchmark-run-permission-policy-smoke.py", + "tier": "default", + "reason": "guards explicit execution and publication permission policy", + }, + { + "command": "python3 examples/benchmark-candidate-source-boundary-smoke.py", + "tier": "default", + "reason": "guards candidate selection against raw and private sources", + }, + { + "command": "python3 examples/benchmark-artifact-path-filter-smoke.py", + "tier": "default", + "reason": "guards raw/private benchmark artifact path exclusion", + }, + { + "command": "python3 -m pytest -q tests/capabilities/test_benchmark_toolkit.py", + "tier": "deep", + "reason": "checks integrity qualification and fail-closed public boundaries", + }, + ], + }, +) diff --git a/scripts/semantic_incident_retrodiction.py b/scripts/semantic_incident_retrodiction.py index e187128465..a86f2d1b29 100644 --- a/scripts/semantic_incident_retrodiction.py +++ b/scripts/semantic_incident_retrodiction.py @@ -18,6 +18,7 @@ from __future__ import annotations +from collections.abc import Callable, Mapping import copy import importlib.util import json @@ -26,7 +27,7 @@ import sys import tempfile from pathlib import Path -from typing import Any +from typing import TypedDict REPO_ROOT = Path(__file__).resolve().parents[1] if str(REPO_ROOT) not in sys.path: @@ -66,28 +67,168 @@ def appendix_e_lessons(rfc_path: Path) -> int: return sum(1 for line in tail.splitlines() if line.startswith("- ")) -def load_ledger() -> dict[str, Any]: - ledger = json.loads(LEDGER_PATH.read_text(encoding="utf-8")) - require(set(ledger) == LEDGER_KEYS, f"ledger keys must be exactly {sorted(LEDGER_KEYS)}") - require(ledger["schema_version"] == LEDGER_SCHEMA_VERSION, "ledger schema_version drift") - require(ledger["meaning"].strip() and ledger["source"].strip(), "ledger needs a meaning and a source") +BaselineDict = TypedDict( + "BaselineDict", + { + "meaning": str, + "would_have_caught": int, + "total": int, + "negative_control_false_positives": int, + }, +) +IncidentDict = TypedDict( + "IncidentDict", + { + "id": str, + "class": str, + "defect": str, + "expected_rule": str, + "probe": str, + "expectation": str, + }, +) +ControlDict = TypedDict( + "ControlDict", + { + "id": str, + "class": str, + "meaning": str, + "probe": str, + }, +) +LedgerDict = TypedDict( + "LedgerDict", + { + "schema_version": str, + "meaning": str, + "source": str, + "measured_at": str, + "incidents": list[IncidentDict], + "negative_controls": list[ControlDict], + "caught_baseline": BaselineDict, + }, +) + + +def _require_mapping(value: object, message: str) -> dict[str, object]: + if not isinstance(value, dict): + raise LedgerError(message) + return {str(key): item for key, item in value.items()} + + +def _require_str_records( + value: object, + *, + label: str, + keys: set[str], + non_empty_keys: set[str], +) -> list[dict[str, str]]: + if not isinstance(value, list): + raise LedgerError(f"{label} must be a list") + records: list[dict[str, str]] = [] + for entry in value: + mapping = _require_mapping(entry, f"{label} entry must be an object") + require(set(mapping) == keys, f"{mapping.get('id')}: {label} keys must be exactly {sorted(keys)}") + record: dict[str, str] = {} + for key in keys: + item = mapping[key] + if not isinstance(item, str): + raise LedgerError(f"{mapping.get('id')}: {key} must be a string") + if key in non_empty_keys: + require(bool(item.strip()), f"{mapping.get('id')}: {key} must be non-empty") + record[key] = item + records.append(record) + ids = [record["id"] for record in records] + require(len(ids) == len(set(ids)), f"{label} ids repeat") + return records + + +def load_ledger() -> LedgerDict: + raw = _require_mapping( + json.loads(LEDGER_PATH.read_text(encoding="utf-8")), + "ledger must be a JSON object", + ) + require(set(raw) == LEDGER_KEYS, f"ledger keys must be exactly {sorted(LEDGER_KEYS)}") + require(raw["schema_version"] == LEDGER_SCHEMA_VERSION, "ledger schema_version drift") + meaning = raw["meaning"] + source = raw["source"] + measured_at = raw["measured_at"] + require( + isinstance(meaning, str) and bool(meaning.strip()) + and isinstance(source, str) and bool(source.strip()) + and isinstance(measured_at, str), + "ledger needs a meaning, measured_at, and source", + ) require(LEDGER_PATH.parent.joinpath("vocabulary_v0.json").is_file(), "ledger must sit beside the vocabulary registry") - ids = [incident["id"] for incident in ledger["incidents"]] - require(len(ids) == len(set(ids)), "incident ids repeat") - for incident in ledger["incidents"]: - require(set(incident) == INCIDENT_KEYS, f"{incident.get('id')}: incident keys must be exactly {sorted(INCIDENT_KEYS)}") - require(incident["expectation"] in VERDICTS, f"{incident['id']}: expectation must be one of {sorted(VERDICTS)}") - for key in ("class", "defect", "expected_rule", "probe"): - require(incident[key].strip(), f"{incident['id']}: {key} must be non-empty") - control_ids = [control["id"] for control in ledger["negative_controls"]] - require(len(control_ids) == len(set(control_ids)), "negative control ids repeat") - for control in ledger["negative_controls"]: - require(set(control) == CONTROL_KEYS, f"{control.get('id')}: control keys must be exactly {sorted(CONTROL_KEYS)}") - baseline = ledger["caught_baseline"] - require(set(baseline) == {"meaning", "would_have_caught", "total", "negative_control_false_positives"}, - "caught_baseline keys must be meaning, would_have_caught, total, and negative_control_false_positives") - require(baseline["total"] == len(ledger["incidents"]), "caught_baseline.total must equal the incident count") - return ledger + + incident_rows = _require_str_records( + raw["incidents"], + label="incident", + keys=INCIDENT_KEYS, + non_empty_keys={"class", "defect", "expected_rule", "probe"}, + ) + incidents: list[IncidentDict] = [] + for row in incident_rows: + require(row["expectation"] in VERDICTS, f"{row['id']}: expectation must be one of {sorted(VERDICTS)}") + incidents.append( + { + "id": row["id"], + "class": row["class"], + "defect": row["defect"], + "expected_rule": row["expected_rule"], + "probe": row["probe"], + "expectation": row["expectation"], + } + ) + + control_rows = _require_str_records( + raw["negative_controls"], + label="negative control", + keys=CONTROL_KEYS, + non_empty_keys=set(), + ) + controls: list[ControlDict] = [ + { + "id": row["id"], + "class": row["class"], + "meaning": row["meaning"], + "probe": row["probe"], + } + for row in control_rows + ] + + raw_baseline = _require_mapping(raw["caught_baseline"], "caught_baseline must be an object") + require( + set(raw_baseline) == {"meaning", "would_have_caught", "total", "negative_control_false_positives"}, + "caught_baseline keys must be meaning, would_have_caught, total, and negative_control_false_positives", + ) + base_meaning = raw_baseline["meaning"] + caught = raw_baseline["would_have_caught"] + total = raw_baseline["total"] + false_pos = raw_baseline["negative_control_false_positives"] + if not ( + isinstance(base_meaning, str) + and isinstance(caught, int) + and isinstance(total, int) + and isinstance(false_pos, int) + ): + raise LedgerError("caught_baseline field types mismatch") + baseline: BaselineDict = { + "meaning": base_meaning, + "would_have_caught": caught, + "total": total, + "negative_control_false_positives": false_pos, + } + require(baseline["total"] == len(incidents), "caught_baseline.total must equal the incident count") + return { + "schema_version": str(raw["schema_version"]), + "meaning": str(meaning), + "source": str(source), + "measured_at": str(measured_at), + "incidents": incidents, + "negative_controls": controls, + "caught_baseline": baseline, + } class Guard: @@ -105,7 +246,8 @@ class Guard: def __init__(self) -> None: spec = importlib.util.spec_from_file_location("_semantic_drift_smoke_probe", SMOKE_PATH) - require(spec is not None and spec.loader is not None, "the guard module could not be loaded") + if spec is None or spec.loader is None: + raise LedgerError("the guard module could not be loaded") self.module = importlib.util.module_from_spec(spec) sys.modules[spec.name] = self.module spec.loader.exec_module(self.module) @@ -114,7 +256,7 @@ def __init__(self) -> None: self.sources = self.ns["load_sources"](self.ns["REPO_ROOT"]) self.inventory = self.ns["build_inventory"](self.ns["REPO_ROOT"], sources=self.sources) - def rejects(self, call: Any) -> tuple[bool, str]: + def rejects(self, call: Callable[[], object]) -> tuple[bool, str]: try: call() except Exception as error: # noqa: BLE001 - any rejection is the signal @@ -122,7 +264,7 @@ def rejects(self, call: Any) -> tuple[bool, str]: return True, f"{type(error).__name__}: {first}" return False, "accepted" - def with_registry_file(self, mutated: dict[str, Any], call: Any) -> tuple[bool, str]: + def with_registry_file(self, mutated: Mapping[str, object], call: Callable[[], object]) -> tuple[bool, str]: """Run a loader-level check against mutated registry content. The patch is proven live before the verdict is used: the committed @@ -143,8 +285,8 @@ def with_registry_file(self, mutated: dict[str, Any], call: Any) -> tuple[bool, self.ns["REGISTRY_PATH"] = original temporary.unlink(missing_ok=True) - def semantic_forks(self, registry: dict[str, Any] | None = None) -> int: - return self.ns["check_scope_declarations"](registry or self.registry, self.inventory) + def semantic_forks(self, registry: Mapping[str, object] | None = None) -> int: + return int(self.ns["check_scope_declarations"](registry or self.registry, self.inventory)) # --- incident probes ----------------------------------------------------------------- @@ -158,14 +300,15 @@ def probe_cross_runtime_value_drift(guard: Guard) -> tuple[bool, str]: if owner and "::" in owner and owner.split("::")[0].endswith(".ts"): target = (name, owner) break - require(target is not None, "no registered cross-runtime pair to mutate; the probe cannot measure anything") + if target is None: + raise LedgerError("no registered cross-runtime pair to mutate; the probe cannot measure anything") name, owner = target module, _symbol = owner.split("::") victim = guard.ns["owner_values"](owner)[-1] original = guard.ns["source"] - applied = [] + applied: list[str] = [] - def drifted(path: str): + def drifted(path: str) -> object: file = original(path) if path != module: return file @@ -180,7 +323,7 @@ def drifted(path: str): rejected, detail = guard.rejects(lambda: guard.ns["check_owned_vocabularies"](guard.registry, guard.inventory)) finally: guard.ns["source"] = original - require(applied and set(applied) == {module}, f"the drifted module was never read (read={sorted(set(applied))})") + require(bool(applied) and set(applied) == {module}, f"the drifted module was never read (read={sorted(set(applied))})") return rejected, f"{name} {owner}: {victim} -> {victim}_drift rejected={rejected} ({detail})" @@ -254,12 +397,22 @@ def probe_definitions_ratcheted(guard: Guard) -> tuple[bool, str]: def probe_commit_time_selection(guard: Guard) -> tuple[bool, str]: """E07: the guard must be selected before merge, not discovered by the fleet.""" + from loopx.canary.planner import CURRENT_REPO_PROFILES from loopx.canary.premerge import build_premerge_validation_gate from loopx.canary.runner import MAINTAINABILITY_RATCHET_SCRIPT - planner = (REPO_ROOT / "loopx" / "canary" / "planner.py").read_text(encoding="utf-8") command = "examples/semantic-vocabulary-drift-smoke.py" - planned = command in planner + matching_profiles: list[Mapping[str, object]] = [] + for profile in CURRENT_REPO_PROFILES: + raw_checks = profile.get("checks") + if not isinstance(raw_checks, list): + continue + if any( + isinstance(check, Mapping) and command in str(check.get("command") or "") + for check in raw_checks + ): + matching_profiles.append(profile) + planned = bool(matching_profiles) gate = build_premerge_validation_gate( changed_files=["loopx/_probe_semantic_guard.py"], execute=False, @@ -272,7 +425,12 @@ def probe_commit_time_selection(guard: Guard) -> tuple[bool, str]: ] selected_by_premerge = any(command in item for item in selected_commands) not_advisory_baseline = command != MAINTAINABILITY_RATCHET_SCRIPT - guarded_roots = [hint for hint in ("loopx/", "scripts/", "examples/") if f'"{hint}"' in planner] + hint_values: set[str] = set() + for profile in matching_profiles: + raw_hints = profile.get("trigger_hints") + if isinstance(raw_hints, (list, tuple)): + hint_values.update(str(hint) for hint in raw_hints) + guarded_roots = [hint for hint in ("loopx/", "scripts/", "examples/") if hint in hint_values] return planned and selected_by_premerge and not_advisory_baseline, ( f"named_in_planner={planned} selected_by_premerge={selected_by_premerge} " f"not_advisory_baseline={not_advisory_baseline} planner_trigger_hints={guarded_roots}" @@ -364,7 +522,7 @@ def probe_scan_reach_disclosed(guard: Guard) -> tuple[bool, str]: require(dropped > 0, f"{dropped_prefix} holds no sources; the probe cannot narrow anything") original = guard.ns["load_sources"] - def narrowed(repo_root: str, root: str | None = None): + def narrowed(repo_root: str, root: str | None = None) -> list[object]: scope = root if root is not None else DEFAULT_ROOT return [source for source in kept if source.path.startswith(scope)] @@ -438,7 +596,10 @@ def probe_roles_table(guard: Guard) -> tuple[bool, str]: def control_single_value_ignored(guard: Guard) -> tuple[bool, str]: """A one-value set must not be reported as a collision candidate.""" - fake = {section: [] for section in ("python_enums", "python_closed_sets", "python_literal_aliases", "typescript_const_arrays")} + fake: dict[str, list[dict[str, object]]] = { + section: [] + for section in ("python_enums", "python_closed_sets", "python_literal_aliases", "typescript_const_arrays") + } fake["python_closed_sets"] = [ {"name": "ONLY_ONE", "module": "loopx/_probe_a.py", "values": ["solo"]}, {"name": "ALSO_ONE", "module": "loopx/_probe_b.py", "values": ["solo"]}, @@ -521,9 +682,10 @@ def main() -> int: f"Appendix E records {lessons} lessons but the ledger probes {len(ledger['incidents'])}; " "every lesson needs a probe and every probe needs a lesson" )) - for ledger_key, probes in (("incidents", INCIDENT_PROBES), ("negative_controls", CONTROL_PROBES)): - for entry in ledger[ledger_key]: - require(entry["probe"] in probes, f"{entry['id']}: unknown probe {entry['probe']!r}") + for incident in ledger["incidents"]: + require(incident["probe"] in INCIDENT_PROBES, f"{incident['id']}: unknown probe {incident['probe']!r}") + for control in ledger["negative_controls"]: + require(control["probe"] in CONTROL_PROBES, f"{control['id']}: unknown probe {control['probe']!r}") caught, mismatches, details = 0, [], [] for incident in ledger["incidents"]: From 45f7c5a03d80cd51b0f18688bd651c059dc27d51 Mon Sep 17 00:00:00 2001 From: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> Date: Thu, 26 Nov 2026 23:06:31 +0800 Subject: [PATCH 2/3] test(canary): retain the newly caught retrodiction lesson Record E12 as caught after the planner refactor makes the dropped extension-source scope visible to an existing check. Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> --- loopx/semantics/incident_v0.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/loopx/semantics/incident_v0.json b/loopx/semantics/incident_v0.json index 213e3564ad..4b993d78d7 100644 --- a/loopx/semantics/incident_v0.json +++ b/loopx/semantics/incident_v0.json @@ -98,7 +98,7 @@ "defect": "When a document widens its scope faster than the code, the two must be reconciled; a scope claim the scanner does not implement is a false invariant.", "expected_rule": "The scan's implemented reach is measured at check time and compared with the declared claim.", "probe": "scan_reach_disclosed", - "expectation": "uncovered" + "expectation": "caught" }, { "id": "E13", @@ -159,7 +159,7 @@ ], "caught_baseline": { "meaning": "Frozen at authoring time so the retrodiction cannot silently regress; it records what the guard caught then, not a target.", - "would_have_caught": 12, + "would_have_caught": 13, "total": 15, "negative_control_false_positives": 0 } From 239d3726553f296e65efae705270744ca04301b3 Mon Sep 17 00:00:00 2001 From: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> Date: Thu, 26 Nov 2026 23:22:38 +0800 Subject: [PATCH 3/3] Revert "test(canary): retain the newly caught retrodiction lesson" This reverts commit 337c51e77aef939848b6fc53b11d7fd4dda56772. Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> --- loopx/semantics/incident_v0.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/loopx/semantics/incident_v0.json b/loopx/semantics/incident_v0.json index 4b993d78d7..213e3564ad 100644 --- a/loopx/semantics/incident_v0.json +++ b/loopx/semantics/incident_v0.json @@ -98,7 +98,7 @@ "defect": "When a document widens its scope faster than the code, the two must be reconciled; a scope claim the scanner does not implement is a false invariant.", "expected_rule": "The scan's implemented reach is measured at check time and compared with the declared claim.", "probe": "scan_reach_disclosed", - "expectation": "caught" + "expectation": "uncovered" }, { "id": "E13", @@ -159,7 +159,7 @@ ], "caught_baseline": { "meaning": "Frozen at authoring time so the retrodiction cannot silently regress; it records what the guard caught then, not a target.", - "would_have_caught": 13, + "would_have_caught": 12, "total": 15, "negative_control_false_positives": 0 }