|
| 1 | +# TFD Incremental Skill Binding Implementation Plan |
| 2 | + |
| 3 | +> **For agentic workers:** REQUIRED SUB-SKILL: Use `superpowers:executing-plans` to implement this plan task-by-task. Do not use `subagent-driven-development`; the approved TFD roster and TaskPacket require inline execution by `developer-tooling`. |
| 4 | +
|
| 5 | +**Goal:** Add read-only proposal and atomic apply services that incrementally BIND reviewed installed Skills to existing ACTIVE Agents without broadening permissions or bypassing ordinary runtime preparation. |
| 6 | + |
| 7 | +**Architecture:** A focused `skill_binding.py` service strictly decodes requests, pins every authority-bearing input, revalidates installed package provenance, derives a complete deterministic poststate, and seals it with a full canonical digest. Apply holds the existing re-entrant Workspace transaction across revalidation, publication, ordinary runtime preparation, immutable event recording, generated-view rebuild, final verification, and exact rollback. Existing `AgentSkillGrant`, full Skill Store assembly, runtime, event kind, and Workspace schemas remain unchanged. |
| 8 | + |
| 9 | +**Tech Stack:** Python 3 standard library, frozen dataclasses, existing TFD YAML/schema/Skill Store/runtime/event/view services, `unittest`. |
| 10 | + |
| 11 | +## Global Constraints |
| 12 | + |
| 13 | +- Follow `docs/superpowers/specs/2026-07-26-tfd-incremental-skill-bind-design.md` exactly. |
| 14 | +- Only reviewed installed Skills with `requested_decision == decision == BIND` may be incrementally bound. |
| 15 | +- Preserve default denial, exact Task/Agent/Skill/purpose/expiry/termination checks, and ordinary `prepare_task_packet` strength. |
| 16 | +- Do not expand `AgentSkillGrant` or any Workspace schema. |
| 17 | +- Proposal is byte-for-byte read-only; apply has one outer rollback boundary and no external effect. |
| 18 | +- The durable project `.tfd` is singular and is never copied into this worktree. |
| 19 | +- Do not modify Creave code or Workspace; the Creave-named artifact is a repository-only JSON fixture. |
| 20 | +- No Agent creation/start, permission grant, install, network, paid call, external write, credential, push, PR, tag, release, deploy, reinstall, or local commit. |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +### Task 1: Strict proposal model and read-only vertical slice |
| 25 | + |
| 26 | +**Files:** |
| 27 | +- Create: `plugins/tfd/scripts/tfd_workspace/skill_binding.py` |
| 28 | +- Create: `plugins/tfd/scripts/test_workspace_skill_binding.py` |
| 29 | +- Modify: `plugins/tfd/scripts/tfd_workspace/__init__.py` |
| 30 | + |
| 31 | +**Interfaces:** |
| 32 | +- Consumes: persisted Workspace documents, `SkillReview`, `CapabilityContract`, `SourceTrustPolicy`, `AgentSkillGrant`, `validate_skill_review_snapshot`, `verify_skill_lock`, `prepare_task_packet`. |
| 33 | +- Produces: `SkillBindRequestEntry`, `SkillBindRequest`, `SkillBindProposal`, `SkillBindResult`, `build_skill_bind_proposal(project_root, request, at)`. |
| 34 | + |
| 35 | +- [ ] **Step 1: Write the failing vertical-slice proposal test** |
| 36 | + |
| 37 | + Build a real temporary Workspace from the existing Skill Store fixture conventions, snapshot every file and directory entry, call `build_skill_bind_proposal`, and assert `PASS`, a full `sha256:` seal, canonical root, exact named approver, exact normalized binding, and an unchanged tree inventory/byte snapshot. |
| 38 | + |
| 39 | +- [ ] **Step 2: Run the focused test to verify RED** |
| 40 | + |
| 41 | + Run: `python3 -m unittest plugins.tfd.scripts.test_workspace_skill_binding.SkillBindingTests.test_propose_is_read_only_and_seals_exact_binding -v` |
| 42 | + |
| 43 | + Expected: import failure because `skill_binding` does not exist. |
| 44 | + |
| 45 | +- [ ] **Step 3: Implement strict request validation and proposal derivation** |
| 46 | + |
| 47 | + Add frozen request/proposal/result dataclasses. Validate exact schemas and canonical IDs, timestamps, full digests, one Task scope, one normalized purpose, unique grants/Agent-Skill pairs/purposes, explicit expiry, `task_completion`, named-user identity, ACTIVE roster/source identity, exact non-terminal owned and assigned Task revision/candidate/required Skill, BIND review provenance, complete review risk fields, permission non-expansion, and existing authority conflicts. Seal pinned prestate and installed package identities; derive deterministic approval/lock/review/grant poststate and expected event IDs without writing. |
| 48 | + |
| 49 | +- [ ] **Step 4: Run focused proposal test to verify GREEN** |
| 50 | + |
| 51 | + Run the command from Step 2 and require one passing test with an unchanged tree. |
| 52 | + |
| 53 | +### Task 2: Atomic apply, runtime proof, idempotency, and CLI |
| 54 | + |
| 55 | +**Files:** |
| 56 | +- Modify: `plugins/tfd/scripts/tfd_workspace/skill_binding.py` |
| 57 | +- Modify: `plugins/tfd/scripts/tfd_workspace/cli.py` |
| 58 | +- Modify: `plugins/tfd/scripts/tfd_workspace/__init__.py` |
| 59 | +- Modify: `plugins/tfd/scripts/test_workspace_skill_binding.py` |
| 60 | +- Modify: `plugins/tfd/scripts/test_workspace_cli.py` |
| 61 | + |
| 62 | +**Interfaces:** |
| 63 | +- Produces: `SkillBindApproval`, `apply_skill_bind_proposal(project_root, proposal, approval, at)`, CLI `skill-bind-propose` and `skill-bind-apply`. |
| 64 | +- Apply returns `PASS/applied`, `PASS/already_applied`, or `BLOCKER` with one stable fail-closed issue code. |
| 65 | + |
| 66 | +- [ ] **Step 1: Write failing success/apply/runtime/CLI tests** |
| 67 | + |
| 68 | + Assert that apply adds exactly one grant, updates or creates the exact authority/lock/review fragments, records the deterministic `skill_grant_changed` event, rebuilds projections, passes `verify_skill_lock`, and allows ordinary `prepare_task_packet`. Assert a second exact apply changes no bytes or event count. Assert CLI accepts only a complete digest and emits one JSON object. |
| 69 | + |
| 70 | +- [ ] **Step 2: Run the new tests to verify RED** |
| 71 | + |
| 72 | + Run the individual service and CLI test methods; expect missing apply/CLI behavior failures. |
| 73 | + |
| 74 | +- [ ] **Step 3: Implement one-boundary publication** |
| 75 | + |
| 76 | + Validate the proposal seal and named approval, acquire `workspace_transaction`, check idempotent exact postcondition before prestate staleness, revalidate prestate/package/Agent/Task/Skill/grant/event availability, pin all mutated authority/event/view targets, atomically publish the deterministic merge, run `verify_skill_lock`, call ordinary `prepare_task_packet` for every Agent/Task group, record exact immutable events, rebuild every projection, rerun complete validation, fsync, and release. On any failure restore exact bytes, modes, and existence and return a stable blocker; surface `recovery_required` if exact restoration cannot be proved. |
| 77 | + |
| 78 | +- [ ] **Step 4: Run the service and CLI tests to verify GREEN** |
| 79 | + |
| 80 | + Require success, idempotency, runtime packet, and CLI tests to pass. |
| 81 | + |
| 82 | +### Task 3: Fail-closed matrix and rollback |
| 83 | + |
| 84 | +**Files:** |
| 85 | +- Modify: `plugins/tfd/scripts/test_workspace_skill_binding.py` |
| 86 | +- Modify: `plugins/tfd/scripts/tfd_workspace/skill_binding.py` |
| 87 | + |
| 88 | +**Interfaces:** |
| 89 | +- Consumes: `_SKILL_BIND_FAULT_HOOK` test-only injection boundary. |
| 90 | +- Produces: stable issue codes from the design table and exact rollback behavior. |
| 91 | + |
| 92 | +- [ ] **Step 1: Add failing table-driven rejection tests** |
| 93 | + |
| 94 | + Cover malformed/short/wrong digest, expiry/future issuance/completed Task, approver mismatch, prestate and installed source/catalog/package/review drift, Agent/roster/Task/permission drift, conflicting authority/event, missing/symlinked/ambiguous/unreviewed/non-BIND Skill, wrong owner/scope/required Skill/purpose, and proposed network/external/credential/dependency/permission expansion. |
| 95 | + |
| 96 | +- [ ] **Step 2: Run rejection tests to verify RED** |
| 97 | + |
| 98 | + Run the exact new test methods and confirm each fails on the missing validation branch, not fixture setup. |
| 99 | + |
| 100 | +- [ ] **Step 3: Add minimal fail-closed mappings** |
| 101 | + |
| 102 | + Revalidate each sealed identity at apply time and map secret-safe failures to the stable codes in the design. Never include installed Skill bodies, absolute package paths, full approval digests, credentials, or raw exceptions. |
| 103 | + |
| 104 | +- [ ] **Step 4: Add and verify concurrent/fault rollback tests** |
| 105 | + |
| 106 | + Race two divergent proposals and require one winner. Inject a fault after each authority write, review, lock, Agent grant, runtime gate, event, and generated view; compare complete inventories, bytes, and modes with the exact preimage. |
| 107 | + |
| 108 | +- [ ] **Step 5: Run the complete focused module to GREEN** |
| 109 | + |
| 110 | + Run: `python3 -m unittest plugins.tfd.scripts.test_workspace_skill_binding -v` |
| 111 | + |
| 112 | +### Task 4: Creave consumer fixture, documentation, and regression verification |
| 113 | + |
| 114 | +**Files:** |
| 115 | +- Create: `plugins/tfd/scripts/fixtures/creave-incremental-skill-bind.json` |
| 116 | +- Modify: `plugins/tfd/scripts/test_workspace_skill_binding.py` |
| 117 | +- Modify: `plugins/tfd/references/workspace-protocol.md` |
| 118 | +- Modify: `README.md` |
| 119 | +- Modify: `README-CN.md` |
| 120 | + |
| 121 | +**Interfaces:** |
| 122 | +- Fixture contains exactly the nine approved role/Skill/purpose mappings from the design and no Coordinator or `subagent-driven-development` grant. |
| 123 | + |
| 124 | +- [ ] **Step 1: Add failing fixture consumption test** |
| 125 | + |
| 126 | + Materialize temporary installed packages and an isolated temporary Workspace from the JSON fixture, propose/apply the mappings, and assert exact role mapping, no Coordinator output Skill, and denial of `subagent-driven-development`. |
| 127 | + |
| 128 | +- [ ] **Step 2: Run fixture test to verify RED** |
| 129 | + |
| 130 | + Expect failure because the fixture does not yet exist. |
| 131 | + |
| 132 | +- [ ] **Step 3: Add fixture and protocol/CLI documentation** |
| 133 | + |
| 134 | + Document the proposal/apply commands, full-digest named approval, read-only/atomic/idempotent behavior, runtime re-prepare requirement, project-singleton Workspace/worktree rule, exclusions, and the tested Creave consumer boundary. |
| 135 | + |
| 136 | +- [ ] **Step 4: Run fixture and focused tests to GREEN** |
| 137 | + |
| 138 | + Run the fixture method and complete `test_workspace_skill_binding` module. |
| 139 | + |
| 140 | +- [ ] **Step 5: Run related and full offline verification** |
| 141 | + |
| 142 | + Run focused CLI, Skill Store, runtime/policy, schema, events, views, recovery, initialization, and contract modules; then run the repository's full documented Python suite plus formatting/static/release-preflight commands discovered from the current repository. Record exact pass/fail counts and preserve any host-isolation, real-Creave productivity, model-role advantage, and production execution claims as `UNVERIFIED`. |
| 143 | + |
| 144 | +## Self-review |
| 145 | + |
| 146 | +- Spec coverage: Tasks 1–3 cover proposal, named approval, delta preservation, idempotency, concurrency, source drift, runtime strength, and exact rollback; Task 4 covers the required consumer mapping, protocol/CLI docs, regressions, and explicit UNVERIFIED boundaries. |
| 147 | +- Placeholder scan: no implementation step contains TBD/TODO, “similar to”, or unspecified error handling. |
| 148 | +- Type consistency: the request, proposal, approval, and result symbols named in Tasks 1–3 are the only new service boundary; durable grants continue to use existing `AgentSkillGrant`. |
| 149 | +- Execution selection: the approved TFD TaskPacket already selects inline `superpowers:executing-plans`; no additional user choice or commit step is permitted. |
0 commit comments