<!-- Written per the the-loop:writing skill. -->
Tasks: give each pull request of a multi-PR work item its own scoped spec
Derived from the approved requirements, design and testing plan. Each task names the requirement(s) it satisfies and the testing-plan row that proves it. TDD throughout: the named test is written first and seen red.
The short version
Fourteen tasks in four layers. The pure functions come first: digest, citations, applicability and path. Then the offline hook, the online verb and its API route, which build on them. The graph wiring, templates and command depend on those. Docs come last. All code lands in this repository, so no repository is declared beyond the origin.
Task list
Layer 1 — pure building blocks (cli/the_loop/graph/prspec.py)
- [x] 1. Chain digest and PR-spec key/path
chain_digest(spec_dir)is a SHA-256 over requirements/bugfix, design, testing-plan and tasks, each with its front matter stripped (viathe_loop.graph.frontmatter) and taken in a fixed order. A missing file contributes a fixed marker, so a latertasks.mdchanges the digest.pr_spec_key(origin_ref, pr_repo, id)gives<id>for the origin and<owner>__<repo>__<id>elsewhere.pr_spec_dir(key, n)givesdocs/specs/<key>/pr-<n>/. Both reuserepo_state_key's part validation: no/, no.., no empty part, no leading dot.- Depends on: none
- Requirements: R2.7, R4.4, R5.1, AC4
- Test: T1 and T8 —
tests/test_pr_spec.py::test_digest_*,::test_key_*,::test_abuse_path_parts_refused(red→green)
- [x] 2. Citation parser and resolver
- Parse every
[wi:…]token in five forms:R2,R2.3,design#slug,TP-T2andtask-4. Resolve each against the chain: requirement headings, EARS list items, the design heading slugs, testing-plan matrix#cells andtasks.mdnumbers. missing_citations(files)returns every required item with no citation: each###in PR requirements, each task line in PR tasks, and each in-scope matrix row in PR testing-plan.- Depends on: none
- Requirements: R3.1, R3.2
- Test: T1 —
tests/test_pr_spec.py::test_citation_*(red→green)
- Parse every
- [x] 3. Applicability and the record model
applicability(outer_state, origin_repo)returnsmulti-prwhen there are ≥2 non-selfrows, or when any row or declared repo lies outside the origin. Otherwise it returnssingle-pr.- The
PrSpecRecorddataclass (version 1) has a strict loader. It rejects apullRequestthat disagrees with its directory, a malformed digest and unknown reasons. - Depends on: none
- Requirements: R1.1–R1.3, R1.6
- Test: T1 and T8 —
tests/test_pr_spec.py::test_applicability_*,::test_forged_record_*(red→green)
- [x] 4. Secret scan
- Use a fixed pattern list:
ghp_,gho_,ghs_,github_pat_,xox[abp]-,AKIA,Authorization:/Bearervalues,Cookie/Set-Cookie, and email addresses (reusingredact._EMAIL_RE). - It reports findings with file and line, and never rewrites.
redact._TOKEN_REis not reused because it would flag SHA digests. - Depends on: none
- Requirements: AC5
- Test: T8 —
tests/test_pr_spec.py::test_abuse_seeded_token_is_finding(red→green)
- Use a fixed pattern list:
Layer 2 — the hook, the verb, the API
- [x] 5. Offline hook
pr-spec-current- Registered with
@hook("pr-spec-current")ingraph/hooks/pr_spec.pyand imported inhooks/__init__.py. - Inner placement (with
prRefin config): re-derive applicability; forsingle-pr, pass with outcomenot-required; otherwise loadpr-spec.jsonfrom the inner-loop dir, validate it and compare the digest. A stale record blocks with "stale: chain changed since<rev>" and names the changed files. - Outer placement: every non-
selfPR row needs a valid, current record. - It writes nothing. Its messages stay in code, because
docs/capabilities/prompts-and-strings.mdexempts graph hook messages. - Depends on: 1, 3
- Requirements: R1.2–R1.4, R4.5, R5.1, R5.2, AC3, NFR offline
- Test: T1 and T8 —
tests/test_pr_spec.py::test_hook_*,::test_forged_required_false_still_blocks,::test_abuse_hook_writes_nothing(red→green)
- Registered with
- [x] 6. GitHub reads for the verb
graph/prspec_github.pyaddsrepository_visibility(client, repo)over the existingGitHubApi.repository, mapping errors, missing values and unknown values tounknown. Comments are found with the existinglist_comments, soghapigains no new read.authorize_comment(url, kind, expected_target, pr_repo)checks four things: that the URL targets the work item (disclosure) or this PR (still-valid); that the author is inrouting.authorizedUsers; that the comment carries no loop-prevention marker; and, for disclosure, that the body containsallow-disclosure <owner>/<repo>.- Depends on: none
- Requirements: R5.2, AC1, AC2
- Test: T8 —
tests/test_pr_spec.py::test_abuse_disclosure_*,::test_abuse_visibility_unknown,::test_abuse_comment_*with a stubbed client (red→green)
- [x] 7. Verb
the-loop graph pr-spec- Lives in
commands/graph_cmd.py. Flags:--pr,--pr-repo,--checkout,--disclosure-approval,--still-valid,--json. Exit codes: 0 recorded, 1 findings, 2 usage. - Runs the eight checks in design order and reports every finding at once.
spec-onlycomes fromgit diff --name-only <merge-base>..HEADin the checkout.- Resolving the checkout path refuses a symlink that escapes it.
- On success it writes exactly one
pr-spec.json, creating the inner dir if absent, and emitsgraph.pr_spec_recorded; a refusal emitsgraph.pr_spec_refused. Both are registered ineventlog.EVENT_TYPESwith their text instrings/en.json: the event names are a closed list, not an opengraph.*namespace. - With
--still-valid, it re-records the current digest without the file checks being re-run against a new derivation. - Depends on: 1, 2, 3, 4, 6
- Requirements: R1.2, R2.7, R3.1–R3.3, R4.2, R4.3, R5.2, AC1–AC5
- Test: T1 and T8 —
tests/test_pr_spec.py::test_verb_*,::test_abuse_symlink_escape,::test_abuse_writes_only_record(red→green)
- Lives in
- [x] 8. API route and OpenAPI contract
- Add
POST /api/v1/graph/pr-spectoapi/routes.pybeside/graph/skip, calling the same function as the verb. - Add the path and request schema (six fields) to
docs/api-specs/openapi/the-loop.v1.yaml. - Depends on: 7
- Requirements: design § API and schema
- Test: T3 —
tests/test_api_contract_parity.py(red→green)
- Add
Layer 3 — graph, templates, command
- [x] 9. Graph wiring
- In
pdlc-pr-loop.yaml, add a new start nodepr-spec: an agent withskippable: true,command: /the-loop:derive-pr-spec, exit hookpr-spec-current, and edges toimplementation(includingon: skipped). - Add
pr-spec-currenttoreviewer-briefing's exit chain. - In
pdlc-work-item-loop.yaml, addpr-spec-currenttoimplementation's exit chain afterawait-inner-loops. - Inner states already at
implementationor later load unchanged. - Update
test_graph_skips.py's "no skippable inner node" tests on purpose, so thatpr-specis the one. - Depends on: 5
- Requirements: R1.5, R4.1, R4.5, R5.1
- Test: T6 and T10 —
tests/test_graph_loops.py,tests/test_graph_skips.py,tests/test_graph_multirepo_integration.py(red→green)
- In
- [x] 10. PR-spec templates
- Create
skills/the-loop/templates/pr-spec/{requirements,design,testing-plan,tasks}.mdwith PR-spec front matter (type,workItem,pullRequest,sourceRevision,chainDigest) and nostatus. - Each starts with a required Context section (work item, source revision, and the sibling PRs with what each delivers).
- The required-section markers are the ones the verb's check 5 reads.
- No manifest entry:
.the-loop/manifest.yaml'stemplatesDiralready covers every template underskills/the-loop/templates/. They jointest_writing_parity.py's human-read list instead. - Depends on: 7 (check 5 reads their markers)
- Requirements: R2.1–R2.6, R3.5
- Test: T6 —
tests/test_manifest_schemas.py,tests/test_writing_parity.py(red→green)
- Create
- [x] 11.
/the-loop:derive-pr-speccommand and assignment text- Create
commands/derive-pr-spec.md. It covers:- choosing this PR's items from the chain;
- citing in every item;
- deriving from the chain only, never from comments, and dropping hostnames;
- the two commands to run;
- asking with
the-loop askwhen disclosure narrows; - feedback routing (R6).
- Any agent-facing text the CLI adds goes in
cli/the_loop/prompts/. - Depends on: 9, 10
- Requirements: R4.1, R6.1–R6.3, AC3
- Test: T6 —
tests/test_graph_loops.pyassignment render names both commands (written after the command, so green on first run)
- Create
Layer 4 — integration, docs, dogfood
- [x] 12. Integration scenarios
- Create
tests/test_pr_spec_integration.pywith the five Gherkin scenarios from design § Testing strategy. Each is driven through the real graph runtime and the CLI, against a temp PR checkout and a stubbed GitHub client. - Depends on: 7, 9, 10
- Requirements: R1.1, R1.2, R1.4, R1.6, R4.1, R4.5, R5.1–R5.3, AC1, AC2
- Test: T2 —
cd cli && uv run python -m pytest -q tests/test_pr_spec_integration.py
- Create
- [x] 13. Docs and decision
- Write
docs/decisions/decision-153.md, which refines decision-065 D2/D4. - Update
docs/capabilities/process-graph.mdandspec-workflow.md. - Update
skills/the-loop/SKILL.mdandreference/workflow.md, including feedback routing. - Change
templates/pr-briefing.mdso it links the PR spec first. - Depends on: 9, 11
- Requirements: R4.6, R6, R7.1, R7.2
- Test: T6 and T12 —
tests/test_writing_parity.py,make lint
- Write
- [x] 14. Dogfood on PR #546
- Ran
the-loop graph pr-spec issue-543 --pr 546 --checkout .in-process. It recordedrequired: false, reason: single-pratpr-loops/pr-546/pr-spec.json, committed here.pr-spec-currentpasses asnot-requiredat the outer and the inner placement. - Rescoped. issue-543 has one delivery PR, so R1.2 says it needs no PR spec, and none was written. A stale report needs a required record, which this work item cannot have, so that half of T11 is shown by T2's second scenario instead. The verification node records T11 on those terms.
- Found while dogfooding, fixed test-first: a ref derived from the checkout's remote can differ in case from the daemon's (
madarauchiha-314againstMadaraUchiha-314), so the record and front-matter refs now compare case-insensitively. The verb also now routes like the harness's GitHub verbs. The running daemon predates the route and still answers it with a bare 404 untilthe-loop restart. - Depends on: 12, 13
- Requirements: R1.2, R4.3, R5.1
- Test: T11 (recorded at verification), T12 —
make check
- Ran
Dependency graph (DAG)
Checkpoints
- After each task: run its named test, commit with the red→green noted, and tick the box.
- After task 9: run the full graph suite (T10).
- After task 14: run
make check(T12), then the verification node executestesting-plan.md.
Review comments
Appended by the-loop's
record-feedbackhook when a human gate approves with comments (issue-109). Append-only and attributed.