Repository navigation
Description
Problem or Motivation
Item #4479 closed on 2026-11-12 without the scope that its comment of 2026-11-12T04:11Z added. That comment asks for one citation module with public functions to parse, verify and re-anchor a citation. The stage gate, the question resolver (#4808), brain add (#4671) and brain repair (#4687) must all use it. Without one module, 4 copies of the same logic drift apart.
PR #5040 (created 2026-11-12T11:17Z, merged 13:12Z) delivered only the stage-gate rule:
_anchored_lineis private insrc/devops_cli/roadmap/stage/stage_change.py:1749. The citation patterns_LINE_CITATIONand_SYMBOL_CITATIONare private atstage_change.py:207-212.git greponsrc/finds nospan_hash, no citation module and no permalink function (origin/main 0d90de5, 2026-11-19).- No code parses the structured citation of ADR 0025 (
docs/adr/0025-generated-documents-stay-in-git-and-the-project-brain-cites-them.md:53-61):{path, commit, lines, span_hash, doc_class, generated_from?, adr_status?, as_of}.
The cause: stage and implement got no item comments until #6182 (for #6167) merged at 2026-11-17T16:26Z. #6182 fixes future runs, but not this delivered item.
Effects:
- The tracker feat(docs): track current content and brain-fed reference docs #4880 lists child 14 as feat(roadmap): re-anchor a stale citation that matches one line #4479, which is closed, so no open item holds the module. Children 16 (feat(ai): give every agent brain tools through MCP, CLI and skill #4671) and 17 (feat(roadmap): run brain repair, consolidate and evaluate daily #4687) depend on child 14.
- The refine design of feat(roadmap): run brain repair, consolidate and evaluate daily #4687 says "feat(roadmap): re-anchor a stale citation that matches one line #4479 is delivered and its re-anchor is reused". It cannot reuse a private function of the stage gate.
- ADR 0025 (line 57) says that feat(roadmap): re-anchor a stale citation that matches one line #4479 moves a stale citation. The delivered code moves only a
path:N:textcitation of a stage plan.
Proposed Solution & Architectural Design
Build the module that the scope comment of #4479 describes:
- Parse a
path:N:textcitation, apath:def namecitation and the structured citation of ADR 0025 into one typed model. - Render a permalink at a commit.
- Verify a citation at a SHA with
git show <sha>:<path>(0 GitHub requests), else with 1 contents GET. - Compute the span hash: SHA-256, the first
CONST_KB_SHA_DIGEST_LENGTH(16) hex characters, assrc/devops_cli/ai/kb.py:614does. - Re-anchor a span that matches exactly one place. Refuse 0 matches and 2 or more matches.
- Move the stage gate to the module:
_line_citation,_anchored_lineand the two patterns ofstage_change.pycall the public functions. The behavior of the gate does not change.
Target Subsystem
SDLC, Git & PR Governance (the stage citation gate in src/devops_cli/roadmap/stage/stage_change.py, and a new shared citation module that the brain items #4671, #4687 and #4808 import).
Existing Tool Considered
git (git show <sha>:<path>) gives the text at a commit, and hashlib gives the span hash. No open tool parses this project's citation forms. The alternatives check of #4479 (2026-11-11) found none. The module is project code on top of git and the standard library. Cost: about 150 lines plus tests, about 60k tokens and 2 h (estimate).
Standards Compliance
- I confirm this proposal aligns with AGENTS.md engineering principles.
- I am willing to submit a pull request implementing this feature with accompanying tests.
Acceptance Criteria
- The module has one public function each to parse, verify and re-anchor a citation, and the stage gate calls them.
- A test re-anchors a moved span with 1 match, and refuses 0 matches and 2 or more matches.
- A test parses a structured citation of ADR 0025 and gets the same span hash for the same text.
- A test verifies a citation at a SHA with no GitHub request.
- The tests of the stage citation gate pass with no change.
- After the merge, a comment on feat(roadmap): the question resolver answers with verified sources #4808, feat(ai): give every agent brain tools through MCP, CLI and skill #4671 and feat(roadmap): run brain repair, consolidate and evaluate daily #4687 names the module. This is a follow-up step, not a file of the pull request.
Dependencies
None. The structured citation form is in ADR 0025 (#4884, closed).
Alternatives check of 2026-11-19: none.
Tool: none found.
Reason: Searches found no maintained tool that parses this project's line, symbol and ADR 0025 structured citation forms, verifies them at a commit or re-anchors a span at a unique match; git and hashlib only give the raw text and hash.
Lacks:
- Parsing of
path:N:textandpath:def namecitations - Typed model of the ADR 0025 structured citation
- Verification at a SHA with git show and one contents fallback
- Span hash of 16 hex characters from the span text
- Re-anchoring only when the span text occurs exactly once
- Permalink rendering with commit, path and line range
Proposed design
Problem statement
PR #5040 delivered only the stage-gate citation rule. The anchor logic and the two citation patterns stay private in src/devops_cli/roadmap/stage/stage_change.py. No code parses the structured citation of ADR 0025. The stage gate, the question resolver (#4808), brain add (#4671) and brain repair (#4687) need one shared module. Without that module, four copies of the same logic drift apart.
Acceptance criteria
Requirement: One parse function for three citation forms
The citation module SHALL give one public function that parses a line citation, a symbol citation and a structured citation into one typed model.
Scenario: Parse each of the three forms
- WHEN A test parses the line citation
src/devops_cli/ai/kb.py:614:sha = hashlib.sha256(...), the symbol citationsrc/devops_cli/ai/kb.py:def load_matched_kb_manualsand the structured citation object of ADR 0025 - THEN The test asserts the path, the line or the symbol, the commit, the line range, the span hash and the document class of each result.
Requirement: Span hash matches the knowledge base hash
The module MUST compute a span hash as the first CONST_KB_SHA_DIGEST_LENGTH hexadecimal characters of the SHA-256 of the span text.
Scenario: The module and the knowledge base give the same hash
- WHEN A test computes the span hash of one text with the module and with
hashlib.sha256(text.encode("utf-8")).hexdigest()[:CONST_KB_SHA_DIGEST_LENGTH] - THEN The test asserts two equal values of 16 hexadecimal characters.
Requirement: Verification at a local commit makes no GitHub request
The module SHALL verify a citation at a commit with git show <sha>:<path> and MUST make no GitHub request when the local repository holds the commit.
Scenario: A local commit verifies with no request
- WHEN A test verifies a citation at a commit of the local repository, with the contents client replaced by a double that raises on any call
- THEN The test asserts the verification result and that the double recorded no call.
Requirement: A commit outside the clone costs one contents GET
The module MUST ask for one contents GET only when the local repository does not hold the cited commit.
Scenario: A commit outside the clone costs one request
- WHEN A test verifies a citation at a commit that the local repository does not hold, with a contents function that returns the file text
- THEN The test asserts the verification result and that the contents function was called exactly once.
Requirement: Re-anchor only a unique span
The module SHALL re-anchor a stale citation to the one place where its span text occurs, and MUST refuse a span text with zero matches or two or more matches.
Scenario: One match moves; zero and two matches refuse
- WHEN A test re-anchors a span whose text occurs once at a new line range, then one whose text occurs zero times, then one whose text occurs twice
- THEN The test asserts the new line range for the one match and a refusal with its reason for the zero-match case and the two-match case.
Requirement: Permalink at a commit
The module SHALL render a permalink that names the cited commit, the path and the first and the last line of the span.
Scenario: The permalink holds the commit and the line range
- WHEN A test renders the permalink of a citation with a commit, a path and a line range
- THEN The test asserts that the URL holds the commit, the path and the first and the last line.
Requirement: The stage gate delegates to the module
src/devops_cli/roadmap/stage/stage_change.py SHALL call the public citation functions and MUST NOT define its own citation patterns or anchor logic.
Scenario: The gate module holds no private citation code
- WHEN A test imports
devops_cli.roadmap.stage.stage_change, replaces the public parse and re-anchor functions of the citation module with doubles, and runs one stage citation check - THEN The test asserts that the gate module has no attribute
_LINE_CITATION,_SYMBOL_CITATION,_anchored_lineor_line_citation, and that the doubles were called.
Requirement: The stage citation gate keeps its results
The stage citation gate MUST give the same result and the same message for each citation case after the move.
Scenario: The existing gate tests pass with no edit
- WHEN The existing test suite of the stage citation gate runs with no edit to its files
- THEN The test run passes and each case gives its earlier result and message.
Existing Tool Considered
The alternatives check of 2026-11-19 gives the verdict none with no tool, as the alternatives block in the issue body records it. The block holds the searches and the list of what no tool covers. No open, maintained tool covers this need, so the change builds project code on git show <sha>:<path> and hashlib. Written cost: about 150 lines of module code plus tests, about 60k tokens and 2 hours to build, keep and fix.
Key questions
- Where does the shared citation module live?: A top-level module
src/devops_cli/citation.py. Bothdevops_cli.roadmap.stageanddevops_cli.aiimport it, with no import fromaitoroadmapor the reverse. (best practice) [sources: src/devops_cli/roadmap/stage/stage_change.py:1749, src/devops_cli/ai/kb.py:614, CONTEXT.md]- Chosen: Top-level module
src/devops_cli/citation.py. About 150 lines fit one module, and bothroadmap.stageandaiimport it with no cycle between them. - Rejected: Package
src/devops_cli/citations/. One module holds the code, and a package adds files that no item needs. - Rejected: Keep it in
src/devops_cli/roadmap/stage/. The brain code would import from the stage job, so brain add and repair would depend onroadmap.stage.
- Chosen: Top-level module
- Which fields does the structured citation of ADR 0025 hold?:
{path, commit, lines, span_hash, doc_class, generated_from?, adr_status?, as_of}.commitis a first-parent commit ofmain,linesis the first and the last line, andspan_hashis a hash of the span text. [sources: docs/adr/0025-generated-documents-stay-in-git-and-the-project-brain-cites-them.md:53-61] - How is the span hash computed?: SHA-256 of the span text in UTF-8, hexadecimal, cut to the first
CONST_KB_SHA_DIGEST_LENGTHcharacters, which is 16.src/devops_cli/ai/kb.py:614computes the knowledge base hash the same way. [sources: src/devops_cli/ai/kb.py:614, src/devops_cli/config/constants.py:5604] - Which Python type holds a parsed citation?: A frozen
dataclassfor each citation form, with the fields of the form and no free-form dictionary. The stage gate already returns a_Citationtype. (best practice) [sources: src/devops_cli/roadmap/stage/stage_change.py:1769]- Chosen: Frozen
dataclass. It gives named fields, an equality check in tests and no dependency. - Rejected: Plain dictionary. A dictionary hides the field names, and no type checker finds a missing key.
- Rejected: Pydantic model. It adds a dependency for a value that no input parses.
- Chosen: Frozen
- How does the module verify a citation at a commit?: It runs
git show <sha>:<path>in the repository and reads the text at that commit, with 0 GitHub requests. It falls back to one contents GET only when the local repository does not hold the commit. (best practice) [sources: docs/adr/0025-generated-documents-stay-in-git-and-the-project-brain-cites-them.md:57, CONTEXT.md]- Chosen:
git showfirst, one contents GET as fallback. The cited commit is a first-parent commit ofmain, which the clone holds, so most checks cost no request. - Rejected: Contents GET only. Each citation costs one request, and the rate limit applies to the brain runs.
- Rejected: Read the working tree. The working tree holds the head text, not the text at the cited commit, so a stale citation would look valid.
- Chosen:
- When does the module re-anchor a stale citation?: Only when the span text occurs exactly once in the file at the head commit. A span text with zero matches or two or more matches is refused with a reason. (best practice) [sources: docs/adr/0025-generated-documents-stay-in-git-and-the-project-brain-cites-them.md:57, src/devops_cli/roadmap/stage/stage_change.py:1749]
- Chosen: Exact span text with exactly one match. ADR 0025 moves a stale citation whose text matches, and a second match makes the move a guess.
- Rejected: First match. The first of two equal spans is arbitrary, so the brain can cite the wrong text.
- Rejected: Nearest span by similarity. A fuzzy move can cite text that does not support the entry, and no test can fix a wrong threshold.
- Does the module validate
doc_classandadr_status?: No. The module carriesdoc_classandadr_statusas strings. The brain sets them from the docs inventory and fromdevops_cli.roadmap.adr, and the module reads neither. (best practice) [sources: docs/adr/0025-generated-documents-stay-in-git-and-the-project-brain-cites-them.md:53-61]- Chosen: Carry
doc_classandadr_statusas strings. The module then has no dependency on the docs inventory or the ADR reader. - Rejected: Validate
doc_classagainst the docs inventory. It couples the stage gate to the docs inventory, which the gate does not read.
- Chosen: Carry
- Does the stage gate keep its behavior after the move to the module?: Yes.
_line_citation,_anchored_line,_LINE_CITATIONand_SYMBOL_CITATIONbecome calls to the public functions. Each result and message of the gate stays the same. (best practice) [sources: src/devops_cli/roadmap/stage/stage_change.py:207, src/devops_cli/roadmap/stage/stage_change.py:210, src/devops_cli/roadmap/stage/stage_change.py:1749, src/devops_cli/roadmap/stage/stage_change.py:1769]- Chosen: Thin delegation with the same results. The gate rule is delivered and tested, and this item must not change it.
- Rejected: Rewrite the gate on the new module. A behavior change in the gate belongs to its own item and would break its tests.
- Does the pull request comment on feat(roadmap): the question resolver answers with verified sources #4808, feat(ai): give every agent brain tools through MCP, CLI and skill #4671 and feat(roadmap): run brain repair, consolidate and evaluate daily #4687?: No. The pull request changes the module and its callers. The module docstring names its readers, and a comment after the merge names the module on the three items. (best practice) [sources: AGENTS.md]
- Chosen: Docstring now, comment after the merge. AGENTS.md rule 8 forbids a change that only updates tracking.
- Rejected: Three comments from the pull request. The pull request would carry a change that only updates tracking.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 19, 2026
Both concern citation re-anchoring, but #4479 delivered a private gate function while the candidate asks for a public shared module used by four consumers.devops-cli-service commentedon Nov 19, 2026
Next step: the alternatives check records a verdict. See the section Proposed design of the body.
devops-cli-service commentedon Nov 19, 2026
The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.
Searches (10)
Searches run:
Sources:
devops-cli-service commentedon Nov 19, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.
devops-cli-service commentedon Nov 25, 2026
Released in v0.216.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.216.0
devops-cli-service commentedon Nov 25, 2026
Live since 2026-11-25 06:00 UTC