Harness Docs Pipeline
Orchestrator composing 4 documentation skills into a sequential pipeline with convergence-based remediation, producing a qualitative documentation health report.
When to Use
- When you want a single-command documentation health check across drift, coverage, links, and freshness
- After major refactoring that may have caused widespread documentation drift
- As a periodic hygiene check (weekly or per-sprint)
- When onboarding a new project that has no AGENTS.md (bootstrap mode)
- When
on_doc_check triggers fire
- NOT for fixing a single known drift issue (use align-documentation directly)
- NOT for generating AGENTS.md from scratch when you know you have a graph (use harness-knowledge-mapper directly)
- NOT for validating a single file's context (use validate-context-engineering directly)
Relationship to Sub-Skills
| Skill |
Pipeline Phase |
Role |
| detect-doc-drift |
DETECT |
Find drift between code and docs |
| align-documentation |
FIX |
Apply fixes for drift findings |
| validate-context-engineering |
AUDIT |
Find gaps in documentation coverage |
| harness-knowledge-mapper |
FILL |
Generate/regenerate AGENTS.md and fill gaps |
This orchestrator delegates to sub-skills — it never reimplements their logic. Each sub-skill retains full standalone functionality.
Iron Law
The pipeline delegates, never reimplements. If you find yourself writing drift detection logic, fix application logic, or gap analysis logic inside the pipeline, STOP. Delegate to the dedicated sub-skill.
Safe fixes are silent, unsafe fixes surface. Never apply a fix classified as unsafe without explicit user approval. Never prompt the user for a fix classified as safe.
Flags
| Flag |
Effect |
--fix |
Enable convergence-based auto-fix (default: detect + report only) |
--no-freshen |
Skip graph staleness check |
--bootstrap |
Force AGENTS.md regeneration even if one exists |
--ci |
Non-interactive: apply safe fixes only, report everything else |
Shared Context Object
All phases read from and write to a shared DocPipelineContext:
interface DocPipelineContext {
// Pipeline state
graphAvailable: boolean;
agentsMdExists: boolean;
bootstrapped: boolean; // true if AGENTS.md was created this run
// Phase outputs
driftFindings: DriftFinding[];
fixesApplied: DocFix[];
gapFindings: GapFinding[];
fillsApplied: DocFix[];
exclusions: Set<string>; // finding IDs already addressed
// Health verdict
verdict: 'pass' | 'warn' | 'fail';
summary: string;
}
interface DriftFinding {
id: string;
file: string;
line?: number;
driftType: 'renamed' | 'new-code' | 'deleted-code' | 'changed-behavior' | 'moved-code';
priority: 'critical' | 'high' | 'medium' | 'low';
staleText: string;
codeChange: string;
suggestedFix: string;
fixSafety: 'safe' | 'probably-safe' | 'unsafe';
}
interface GapFinding {
id: string;
file?: string;
gapType: 'undocumented' | 'broken-link' | 'stale-section' | 'missing-context';
priority: 'critical' | 'high' | 'medium' | 'low';
description: string;
suggestedFix: string;
fixSafety: 'safe' | 'probably-safe' | 'unsafe';
}
interface DocFix {
findingId: string;
file: string;
oldText: string;
newText: string;
safety: 'safe' | 'probably-safe';
verified: boolean; // harness check-docs passed after applying
}
The context is passed to sub-skills via handoff.json with a pipeline field. Sub-skills check for this field; if absent, they run in standalone mode.
Process
Phase 1: FRESHEN — Graph Freshness and AGENTS.md Bootstrap
Skip this phase if --no-freshen flag is set.
Check graph existence. Look for .harness/graph/ directory.
- If exists: set
context.graphAvailable = true
- If not: set
context.graphAvailable = false, log notice: "No knowledge graph available. Pipeline will use static analysis fallbacks. Run harness scan for richer results."
Check graph staleness (only if graph exists).
- Count commits since last graph update:
git rev-list --count HEAD ^$(cat .harness/graph/.last-scan-commit 2>/dev/null || echo HEAD)
- If >10 commits behind: run
harness scan to refresh
- If <=10 commits: proceed with current graph
Check AGENTS.md existence.
- If exists and
--bootstrap not set: set context.agentsMdExists = true, proceed to DETECT
- If exists and
--bootstrap set: proceed to step 4 (regenerate)
- If not exists: proceed to step 4
Bootstrap AGENTS.md.
If graph available:
- Invoke
harness-knowledge-mapper to generate AGENTS.md
- Set
context.bootstrapped = true
- Set
context.agentsMdExists = true
If no graph (directory structure fallback):
Glob source directories: src/*/, packages/*/, lib/*/
Read package.json for project name and description
Identify entry points: files matching src/index.*, main field in package.json
List top-level modules: each immediate subdirectory of src/ (or packages/) with its directory name as the module name
Generate minimal AGENTS.md:
# AGENTS.md
> Generated from directory structure. Run `harness scan` for richer output.
## Project
<name from package.json> — <description from package.json>
## Entry Points
- <each identified entry point>
## Modules
- **<dir-name>/** — <inferred from directory name>
Set context.bootstrapped = true
Set context.agentsMdExists = true
Proceed to DETECT phase.
Phase 2: DETECT — Find Documentation Drift
Write pipeline context to handoff.json. Set the pipeline field in .harness/handoff.json with the current DocPipelineContext so detect-doc-drift can read it.
Invoke detect-doc-drift. Run the skill's full process:
- Phase 1 (Scan):
harness check-docs and harness cleanup --type drift
- Phase 2 (Identify): Classify each finding into drift types
- Phase 3 (Prioritize): Rank by impact (Critical > High > Medium > Low)
- Phase 4 (Report): Structured output
Populate context with DriftFinding objects. For each finding from detect-doc-drift, create a DriftFinding with:
id: deterministic hash of file + line + driftType (for dedup tracking)
driftType: map to one of renamed, new-code, deleted-code, changed-behavior, moved-code
priority: map to critical, high, medium, low
fixSafety: classify using the safety table below
Store findings. Set context.driftFindings = <all DriftFinding objects>.
If --fix flag is not set: Skip to AUDIT phase (Phase 4).
Fix Safety Classification
| Category |
Safe (apply silently) |
Probably safe (present diff) |
Unsafe (surface to user) |
| Drift fixes |
Update file path where rename is unambiguous; fix import reference |
Rewrite description for simple rename/parameter change; update code examples |
Rewrite behavioral explanations; remove sections for deleted code |
| Gap fills |
Add entry for new file with obvious single-purpose name |
Add entry for new file requiring description; update AGENTS.md section ordering |
Write documentation for complex modules; create new doc pages |
| Link fixes |
Redirect broken link where target is unambiguous |
Redirect when multiple candidates exist (present options) |
Remove link when target no longer exists |
Phase 3: FIX — Convergence-Based Drift Remediation
This phase runs only when --fix flag is set.
Convergence Loop
previousCount = context.driftFindings.length
maxIterations = 5
while iteration < maxIterations:
1. Partition findings by safety
2. Apply safe fixes → verify → record
3. Present probably-safe fixes → apply approved → verify → record
4. Surface unsafe fixes to user (no auto-apply)
5. Re-run detect-doc-drift
6. newCount = remaining findings
7. if newCount >= previousCount: STOP (converged)
8. previousCount = newCount
9. iteration++
Step-by-step
Partition findings by fixSafety.
safeFixes: findings where fixSafety === 'safe'
probablySafeFixes: findings where fixSafety === 'probably-safe'
unsafeFixes: findings where fixSafety === 'unsafe'
Apply safe fixes silently.
- Write pipeline context to handoff.json with
pipeline.fixBatch = safeFixes
- Invoke align-documentation to apply the fixes
- Run
harness check-docs after the batch
- If check passes: record each fix as a
DocFix with verified: true in context.fixesApplied
- If check fails: revert the batch (
git checkout -- <files>), record fixes as verified: false
- Add fixed finding IDs to
context.exclusions
Present probably-safe fixes (skip in --ci mode).
- For each fix, show the diff (oldText vs newText) to the user
- Apply user-approved fixes
- Run
harness check-docs after the batch
- Same verify/revert logic as safe fixes
- Add fixed finding IDs to
context.exclusions
Surface unsafe fixes.
- List each unsafe finding with its
suggestedFix text
- Do not apply — user must handle manually
- In
--ci mode: log to report, do not prompt
Re-run detect-doc-drift to check for cascading issues revealed by fixes.
- If new finding count < previous count: loop back to step 1
- If new finding count >= previous count: stop (converged or no progress)
- If max iterations reached: stop
Record remaining unfixed findings for the REPORT phase.
Phase 4: AUDIT — Find Documentation Gaps
Write pipeline context to handoff.json. Update the pipeline field with the current DocPipelineContext (including exclusions from FIX phase).
Invoke validate-context-engineering. Run the skill's full process:
- Phase 1 (Audit):
harness validate and harness check-docs
- Phase 2 (Detect Gaps): Classify into undocumented, broken-link, stale-section, missing-context
- Phase 3 (Suggest Updates): Generate specific suggestions
- Phase 4 (Apply): Deferred to FILL phase
Populate context with GapFinding objects. For each finding, create a GapFinding with:
id: deterministic hash of file + gapType + description
gapType: map to undocumented, broken-link, stale-section, missing-context
priority: map to critical, high, medium, low
fixSafety: classify using the safety table from DETECT phase
Dedup against FIX phase. Remove any GapFinding whose id appears in context.exclusions. This prevents double-counting items already fixed in the FIX phase.
Store findings. Set context.gapFindings = <deduplicated GapFinding objects>.
If --fix flag is not set: Skip to REPORT phase (Phase 6).
Phase 5: FILL — Convergence-Based Gap Remediation
This phase runs only when --fix flag is set.
Check if AGENTS.md needs regeneration. If context.bootstrapped === true and gap findings include AGENTS.md coverage issues, invoke harness-knowledge-mapper (if graph available) or the directory-structure fallback to improve AGENTS.md quality.
Run convergence loop (same pattern as FIX phase):
previousCount = context.gapFindings.length
maxIterations = 5
while iteration < maxIterations:
1. Partition findings by safety
2. Apply safe fills → verify → record
3. Present probably-safe fills → apply approved → verify → record
4. Surface unsafe fills to user
5. Re-run validate-context-engineering
6. newCount = remaining gaps (after dedup against exclusions)
7. if newCount >= previousCount: STOP (converged)
8. previousCount = newCount
9. iteration++
Apply safe fills silently.
- For
broken-link with unambiguous target: redirect the link
- For
undocumented with obvious single-purpose name: add minimal entry
- Run
harness check-docs after each batch
- Record in
context.fillsApplied
- Add filled finding IDs to
context.exclusions
Present probably-safe fills (skip in --ci mode).
- Show diff for: new file entries requiring description, AGENTS.md section reordering
- Apply approved fills, verify, record
Surface unsafe fills.
- Documentation for complex modules, new doc pages
- Log for report, do not apply
Record remaining unfilled gaps for the REPORT phase.
Phase 6: REPORT — Synthesize Health Verdict
Run final harness check-docs to establish the post-pipeline state.
Compute verdict.
FAIL if any of:
- Any critical drift findings remain unfixed
harness check-docs fails after all fix attempts
- AGENTS.md does not exist and bootstrap failed
WARN if any of:
- High-priority drift or gap findings remain (user-deferred)
30% of source modules are undocumented
- Graph not available (reduced accuracy notice)
PASS if:
- No critical or high findings remaining
harness check-docs passes
- AGENTS.md exists and covers >70% of modules
Generate per-category breakdown:
| Category |
Metric |
| Accuracy |
Drift findings remaining (by priority) |
| Coverage |
Undocumented modules remaining |
| Links |
Broken references remaining |
| Freshness |
Graph staleness status |
List actions taken:
- Auto-fixes applied (safe): count and file list
- User-approved fixes (probably-safe): count and file list
- Findings deferred to user (unsafe): count and details
- AGENTS.md bootstrapped: yes/no and method (graph or directory structure)
Set context verdict and summary. Write context.verdict and context.summary.
Output report to console. Format:
=== Documentation Health Report ===
Verdict: PASS | WARN | FAIL
Accuracy: N drift findings remaining (0 critical, 0 high, N medium, N low)
Coverage: N/M modules documented (N%)
Links: N broken references remaining
Freshness: Graph current | Graph stale (N commits behind) | No graph
Actions:
- N safe fixes applied silently
- N probably-safe fixes applied (user-approved)
- N unsafe findings deferred to user
- AGENTS.md bootstrapped from <graph|directory structure>
Remaining findings:
[list of unfixed findings with priority and suggested action]
Harness Integration
harness check-docs — Run in DETECT, after each fix batch in FIX/FILL, and in REPORT for final state
harness cleanup --type drift — Used by detect-doc-drift during DETECT phase
harness scan — Used in FRESHEN to refresh stale graph
harness validate — Run as final step in each task to verify project health
Success Criteria
harness-docs-pipeline runs all 4 sub-skills in the right order with shared context
- FIX and FILL phases iterate until converged; cascading fixes are caught
- Safe fixes are applied silently; unsafe changes surface to user
harness check-docs runs after every fix batch; failed fixes are reverted
- Bootstrap handles cold start (no AGENTS.md) with graph path and directory structure fallback
- Standalone skills work independently exactly as today when invoked without pipeline context
- Entire pipeline runs without graph using static analysis fallbacks
- PASS/WARN/FAIL report includes per-category breakdown and specific remaining findings
- Drift fixes in FIX phase are excluded from AUDIT findings (no double-counting)
Rationalizations to Reject
These are common rationalizations that sound reasonable but lead to incorrect results. When you catch yourself thinking any of these, stop and follow the documented process instead.
| Rationalization |
Why It Is Wrong |
| "The drift finding is marked unsafe but the fix is obvious, so I will apply it silently" |
Never apply a fix classified as unsafe without explicit user approval. The Iron Law: safe fixes are silent, unsafe fixes surface. |
| "The convergence loop reduced findings from 8 to 6, but the remaining ones are hard -- I will keep iterating" |
If a convergence iteration does not reduce the finding count, stop immediately. Continuing without progress wastes iterations. |
| "I can write the drift detection logic directly instead of delegating to detect-doc-drift" |
The pipeline delegates, never reimplements. Each sub-skill retains full standalone functionality. |
| "The graph is not available so the pipeline results will be unreliable" |
The entire pipeline runs without a graph using static analysis fallbacks. Reduced accuracy is noted in the report, not used as an excuse to skip. |
Examples
Example: Full pipeline run with fixes
Input: --fix flag set, graph available, AGENTS.md exists
1. FRESHEN — Graph exists, 3 commits behind (< 10, skip refresh)
AGENTS.md exists, no bootstrap needed
2. DETECT — detect-doc-drift found 8 findings:
2 critical (deleted file still referenced)
3 high (renamed functions)
2 medium (stale descriptions)
1 low (formatting)
3. FIX — Iteration 1:
3 safe fixes applied (renamed file paths)
2 probably-safe presented, 2 approved
2 unsafe surfaced to user
harness check-docs: pass
Re-detect: 1 new finding (cascading rename)
Iteration 2:
1 safe fix applied
Re-detect: 0 new findings — converged
4. AUDIT — validate-context-engineering found 5 gaps
2 already in exclusions (fixed in FIX) → 3 remaining
5. FILL — 1 safe fill (broken link redirect)
1 probably-safe (new module entry) → approved
1 unsafe (complex module docs) → deferred
Re-audit: converged
6. REPORT — Verdict: WARN
Accuracy: 2 drift findings remaining (0 critical, 0 high, 1 medium, 1 low)
Coverage: 12/14 modules documented (86%)
Links: 0 broken references
Freshness: Graph current
Example: CI mode (non-interactive)
Input: --fix --ci flags set, no graph
1. FRESHEN — No graph (notice logged), AGENTS.md exists
2. DETECT — 4 findings (1 critical, 2 high, 1 medium)
3. FIX — 2 safe fixes applied silently
probably-safe and unsafe: logged to report (no prompts)
4. AUDIT — 2 gaps (1 deduped) → 1 remaining
5. FILL — 0 safe fills, 1 probably-safe logged to report
6. REPORT — Verdict: FAIL (1 critical finding remains)
Example: Bootstrap from directory structure
Input: --bootstrap flag set, no graph, no AGENTS.md
1. FRESHEN — No graph, no AGENTS.md
Fallback bootstrap: glob src/*, read package.json
Generated minimal AGENTS.md (32 lines)
context.bootstrapped = true
2. DETECT — 0 drift findings (fresh AGENTS.md, no stale refs)
3. AUDIT — 6 gaps (4 undocumented modules, 2 missing context)
4. REPORT — Verdict: WARN (>30% modules undocumented, no graph)
Gates
- No fix without verification. Every fix batch must be followed by
harness check-docs. If check fails, revert the batch.
- No unsafe auto-apply. Fixes classified as
unsafe are never applied without explicit user approval. In --ci mode, they are logged but never applied.
- No reimplementation of sub-skill logic. The pipeline delegates to sub-skills. If the DETECT phase is writing drift detection code, the plan is wrong.
- No convergence without progress. If a convergence loop iteration does not reduce the finding count, stop immediately. Do not retry.
- Max 5 iterations per convergence loop. Hard cap to prevent runaway loops.
Escalation
- When findings exceed 50: Focus on critical and high priority only. Defer medium and low to a follow-up run.
- When bootstrap produces low-quality AGENTS.md: This is expected without a graph. Log a notice recommending
harness scan and accept the reduced quality for the current run.
- When convergence loop does not converge within 5 iterations: Stop the loop, log remaining findings, and proceed to the next phase. The report will reflect the unconverged state.
- When a sub-skill fails: Log the failure, skip the phase, and continue the pipeline. The report will note the skipped phase with a WARN or FAIL verdict.
- When
harness check-docs is unavailable: Fall back to file existence checks and link validation via grep. Log a notice about reduced verification accuracy.
1---2name: harness-docs-pipeline3description: Harness Docs Pipeline4metadata:5 source: https://skillmd.com/skills/intense-visions/harness-docs-pipeline6---7# Harness Docs Pipeline89> Orchestrator composing 4 documentation skills into a sequential pipeline with convergence-based remediation, producing a qualitative documentation health report.1011## When to Use1213- When you want a single-command documentation health check across drift, coverage, links, and freshness14- After major refactoring that may have caused widespread documentation drift15- As a periodic hygiene check (weekly or per-sprint)16- When onboarding a new project that has no AGENTS.md (bootstrap mode)17- When `on_doc_check` triggers fire18- NOT for fixing a single known drift issue (use align-documentation directly)19- NOT for generating AGENTS.md from scratch when you know you have a graph (use harness-knowledge-mapper directly)20- NOT for validating a single file's context (use validate-context-engineering directly)2122## Relationship to Sub-Skills2324| Skill | Pipeline Phase | Role |25| ---------------------------- | -------------- | ------------------------------------------- |26| detect-doc-drift | DETECT | Find drift between code and docs |27| align-documentation | FIX | Apply fixes for drift findings |28| validate-context-engineering | AUDIT | Find gaps in documentation coverage |29| harness-knowledge-mapper | FILL | Generate/regenerate AGENTS.md and fill gaps |3031This orchestrator delegates to sub-skills — it never reimplements their logic. Each sub-skill retains full standalone functionality.3233## Iron Law3435**The pipeline delegates, never reimplements.** If you find yourself writing drift detection logic, fix application logic, or gap analysis logic inside the pipeline, STOP. Delegate to the dedicated sub-skill.3637**Safe fixes are silent, unsafe fixes surface.** Never apply a fix classified as `unsafe` without explicit user approval. Never prompt the user for a fix classified as `safe`.3839## Flags4041| Flag | Effect |42| -------------- | ----------------------------------------------------------------- |43| `--fix` | Enable convergence-based auto-fix (default: detect + report only) |44| `--no-freshen` | Skip graph staleness check |45| `--bootstrap` | Force AGENTS.md regeneration even if one exists |46| `--ci` | Non-interactive: apply safe fixes only, report everything else |4748## Shared Context Object4950All phases read from and write to a shared `DocPipelineContext`:5152```typescript53interface DocPipelineContext {54 // Pipeline state55 graphAvailable: boolean;56 agentsMdExists: boolean;57 bootstrapped: boolean; // true if AGENTS.md was created this run5859 // Phase outputs60 driftFindings: DriftFinding[];61 fixesApplied: DocFix[];62 gapFindings: GapFinding[];63 fillsApplied: DocFix[];64 exclusions: Set<string>; // finding IDs already addressed6566 // Health verdict67 verdict: 'pass' | 'warn' | 'fail';68 summary: string;69}7071interface DriftFinding {72 id: string;73 file: string;74 line?: number;75 driftType: 'renamed' | 'new-code' | 'deleted-code' | 'changed-behavior' | 'moved-code';76 priority: 'critical' | 'high' | 'medium' | 'low';77 staleText: string;78 codeChange: string;79 suggestedFix: string;80 fixSafety: 'safe' | 'probably-safe' | 'unsafe';81}8283interface GapFinding {84 id: string;85 file?: string;86 gapType: 'undocumented' | 'broken-link' | 'stale-section' | 'missing-context';87 priority: 'critical' | 'high' | 'medium' | 'low';88 description: string;89 suggestedFix: string;90 fixSafety: 'safe' | 'probably-safe' | 'unsafe';91}9293interface DocFix {94 findingId: string;95 file: string;96 oldText: string;97 newText: string;98 safety: 'safe' | 'probably-safe';99 verified: boolean; // harness check-docs passed after applying100}101```102103The context is passed to sub-skills via `handoff.json` with a `pipeline` field. Sub-skills check for this field; if absent, they run in standalone mode.104105## Process106107### Phase 1: FRESHEN — Graph Freshness and AGENTS.md Bootstrap108109**Skip this phase if `--no-freshen` flag is set.**1101111. **Check graph existence.** Look for `.harness/graph/` directory.112 - If exists: set `context.graphAvailable = true`113 - If not: set `context.graphAvailable = false`, log notice: "No knowledge graph available. Pipeline will use static analysis fallbacks. Run `harness scan` for richer results."1141152. **Check graph staleness** (only if graph exists).116 - Count commits since last graph update: `git rev-list --count HEAD ^$(cat .harness/graph/.last-scan-commit 2>/dev/null || echo HEAD)`117 - If >10 commits behind: run `harness scan` to refresh118 - If <=10 commits: proceed with current graph1191203. **Check AGENTS.md existence.**121 - If exists and `--bootstrap` not set: set `context.agentsMdExists = true`, proceed to DETECT122 - If exists and `--bootstrap` set: proceed to step 4 (regenerate)123 - If not exists: proceed to step 41241254. **Bootstrap AGENTS.md.**126127 **If graph available:**128 - Invoke `harness-knowledge-mapper` to generate AGENTS.md129 - Set `context.bootstrapped = true`130 - Set `context.agentsMdExists = true`131132 **If no graph (directory structure fallback):**133 - Glob source directories: `src/*/`, `packages/*/`, `lib/*/`134 - Read `package.json` for project name and description135 - Identify entry points: files matching `src/index.*`, `main` field in package.json136 - List top-level modules: each immediate subdirectory of `src/` (or `packages/`) with its directory name as the module name137 - Generate minimal AGENTS.md:138139 ```markdown140 # AGENTS.md141142 > Generated from directory structure. Run `harness scan` for richer output.143144 ## Project145146 <name from package.json> — <description from package.json>147148 ## Entry Points149150 - <each identified entry point>151152 ## Modules153154 - **<dir-name>/** — <inferred from directory name>155 ```156157 - Set `context.bootstrapped = true`158 - Set `context.agentsMdExists = true`1591605. Proceed to DETECT phase.161162### Phase 2: DETECT — Find Documentation Drift1631641. **Write pipeline context to handoff.json.** Set the `pipeline` field in `.harness/handoff.json` with the current `DocPipelineContext` so detect-doc-drift can read it.1651662. **Invoke detect-doc-drift.** Run the skill's full process:167 - Phase 1 (Scan): `harness check-docs` and `harness cleanup --type drift`168 - Phase 2 (Identify): Classify each finding into drift types169 - Phase 3 (Prioritize): Rank by impact (Critical > High > Medium > Low)170 - Phase 4 (Report): Structured output1711723. **Populate context with DriftFinding objects.** For each finding from detect-doc-drift, create a `DriftFinding` with:173 - `id`: deterministic hash of `file + line + driftType` (for dedup tracking)174 - `driftType`: map to one of `renamed`, `new-code`, `deleted-code`, `changed-behavior`, `moved-code`175 - `priority`: map to `critical`, `high`, `medium`, `low`176 - `fixSafety`: classify using the safety table below1771784. **Store findings.** Set `context.driftFindings = <all DriftFinding objects>`.1791805. **If `--fix` flag is not set:** Skip to AUDIT phase (Phase 4).181182### Fix Safety Classification183184| Category | Safe (apply silently) | Probably safe (present diff) | Unsafe (surface to user) |185| --------------- | ------------------------------------------------------------------ | ------------------------------------------------------------------------------- | ----------------------------------------------------------------- |186| **Drift fixes** | Update file path where rename is unambiguous; fix import reference | Rewrite description for simple rename/parameter change; update code examples | Rewrite behavioral explanations; remove sections for deleted code |187| **Gap fills** | Add entry for new file with obvious single-purpose name | Add entry for new file requiring description; update AGENTS.md section ordering | Write documentation for complex modules; create new doc pages |188| **Link fixes** | Redirect broken link where target is unambiguous | Redirect when multiple candidates exist (present options) | Remove link when target no longer exists |189190### Phase 3: FIX — Convergence-Based Drift Remediation191192**This phase runs only when `--fix` flag is set.**193194#### Convergence Loop195196```197previousCount = context.driftFindings.length198maxIterations = 5199200while iteration < maxIterations:201 1. Partition findings by safety202 2. Apply safe fixes → verify → record203 3. Present probably-safe fixes → apply approved → verify → record204 4. Surface unsafe fixes to user (no auto-apply)205 5. Re-run detect-doc-drift206 6. newCount = remaining findings207 7. if newCount >= previousCount: STOP (converged)208 8. previousCount = newCount209 9. iteration++210```211212#### Step-by-step2132141. **Partition findings by fixSafety.**215 - `safeFixes`: findings where `fixSafety === 'safe'`216 - `probablySafeFixes`: findings where `fixSafety === 'probably-safe'`217 - `unsafeFixes`: findings where `fixSafety === 'unsafe'`2182192. **Apply safe fixes silently.**220 - Write pipeline context to handoff.json with `pipeline.fixBatch = safeFixes`221 - Invoke align-documentation to apply the fixes222 - Run `harness check-docs` after the batch223 - If check passes: record each fix as a `DocFix` with `verified: true` in `context.fixesApplied`224 - If check fails: revert the batch (`git checkout -- <files>`), record fixes as `verified: false`225 - Add fixed finding IDs to `context.exclusions`2262273. **Present probably-safe fixes** (skip in `--ci` mode).228 - For each fix, show the diff (oldText vs newText) to the user229 - Apply user-approved fixes230 - Run `harness check-docs` after the batch231 - Same verify/revert logic as safe fixes232 - Add fixed finding IDs to `context.exclusions`2332344. **Surface unsafe fixes.**235 - List each unsafe finding with its `suggestedFix` text236 - Do not apply — user must handle manually237 - In `--ci` mode: log to report, do not prompt2382395. **Re-run detect-doc-drift** to check for cascading issues revealed by fixes.240 - If new finding count < previous count: loop back to step 1241 - If new finding count >= previous count: stop (converged or no progress)242 - If max iterations reached: stop2432446. **Record remaining unfixed findings** for the REPORT phase.245246### Phase 4: AUDIT — Find Documentation Gaps2472481. **Write pipeline context to handoff.json.** Update the `pipeline` field with the current `DocPipelineContext` (including `exclusions` from FIX phase).2492502. **Invoke validate-context-engineering.** Run the skill's full process:251 - Phase 1 (Audit): `harness validate` and `harness check-docs`252 - Phase 2 (Detect Gaps): Classify into undocumented, broken-link, stale-section, missing-context253 - Phase 3 (Suggest Updates): Generate specific suggestions254 - Phase 4 (Apply): Deferred to FILL phase2552563. **Populate context with GapFinding objects.** For each finding, create a `GapFinding` with:257 - `id`: deterministic hash of `file + gapType + description`258 - `gapType`: map to `undocumented`, `broken-link`, `stale-section`, `missing-context`259 - `priority`: map to `critical`, `high`, `medium`, `low`260 - `fixSafety`: classify using the safety table from DETECT phase2612624. **Dedup against FIX phase.** Remove any `GapFinding` whose `id` appears in `context.exclusions`. This prevents double-counting items already fixed in the FIX phase.2632645. **Store findings.** Set `context.gapFindings = <deduplicated GapFinding objects>`.2652666. **If `--fix` flag is not set:** Skip to REPORT phase (Phase 6).267268### Phase 5: FILL — Convergence-Based Gap Remediation269270**This phase runs only when `--fix` flag is set.**2712721. **Check if AGENTS.md needs regeneration.** If `context.bootstrapped === true` and gap findings include AGENTS.md coverage issues, invoke harness-knowledge-mapper (if graph available) or the directory-structure fallback to improve AGENTS.md quality.2732742. **Run convergence loop** (same pattern as FIX phase):275276 ```277 previousCount = context.gapFindings.length278 maxIterations = 5279280 while iteration < maxIterations:281 1. Partition findings by safety282 2. Apply safe fills → verify → record283 3. Present probably-safe fills → apply approved → verify → record284 4. Surface unsafe fills to user285 5. Re-run validate-context-engineering286 6. newCount = remaining gaps (after dedup against exclusions)287 7. if newCount >= previousCount: STOP (converged)288 8. previousCount = newCount289 9. iteration++290 ```2912923. **Apply safe fills silently.**293 - For `broken-link` with unambiguous target: redirect the link294 - For `undocumented` with obvious single-purpose name: add minimal entry295 - Run `harness check-docs` after each batch296 - Record in `context.fillsApplied`297 - Add filled finding IDs to `context.exclusions`2982994. **Present probably-safe fills** (skip in `--ci` mode).300 - Show diff for: new file entries requiring description, AGENTS.md section reordering301 - Apply approved fills, verify, record3023035. **Surface unsafe fills.**304 - Documentation for complex modules, new doc pages305 - Log for report, do not apply3063076. **Record remaining unfilled gaps** for the REPORT phase.308309### Phase 6: REPORT — Synthesize Health Verdict3103111. **Run final `harness check-docs`** to establish the post-pipeline state.3123132. **Compute verdict.**314315 **FAIL if any of:**316 - Any critical drift findings remain unfixed317 - `harness check-docs` fails after all fix attempts318 - AGENTS.md does not exist and bootstrap failed319320 **WARN if any of:**321 - High-priority drift or gap findings remain (user-deferred)322 - > 30% of source modules are undocumented323 - Graph not available (reduced accuracy notice)324325 **PASS if:**326 - No critical or high findings remaining327 - `harness check-docs` passes328 - AGENTS.md exists and covers >70% of modules3293303. **Generate per-category breakdown:**331332 | Category | Metric |333 | --------- | -------------------------------------- |334 | Accuracy | Drift findings remaining (by priority) |335 | Coverage | Undocumented modules remaining |336 | Links | Broken references remaining |337 | Freshness | Graph staleness status |3383394. **List actions taken:**340 - Auto-fixes applied (safe): count and file list341 - User-approved fixes (probably-safe): count and file list342 - Findings deferred to user (unsafe): count and details343 - AGENTS.md bootstrapped: yes/no and method (graph or directory structure)3443455. **Set context verdict and summary.** Write `context.verdict` and `context.summary`.3463476. **Output report** to console. Format:348349 ```350 === Documentation Health Report ===351352 Verdict: PASS | WARN | FAIL353354 Accuracy: N drift findings remaining (0 critical, 0 high, N medium, N low)355 Coverage: N/M modules documented (N%)356 Links: N broken references remaining357 Freshness: Graph current | Graph stale (N commits behind) | No graph358359 Actions:360 - N safe fixes applied silently361 - N probably-safe fixes applied (user-approved)362 - N unsafe findings deferred to user363 - AGENTS.md bootstrapped from <graph|directory structure>364365 Remaining findings:366 [list of unfixed findings with priority and suggested action]367 ```368369## Harness Integration370371- **`harness check-docs`** — Run in DETECT, after each fix batch in FIX/FILL, and in REPORT for final state372- **`harness cleanup --type drift`** — Used by detect-doc-drift during DETECT phase373- **`harness scan`** — Used in FRESHEN to refresh stale graph374- **`harness validate`** — Run as final step in each task to verify project health375376## Success Criteria377378- `harness-docs-pipeline` runs all 4 sub-skills in the right order with shared context379- FIX and FILL phases iterate until converged; cascading fixes are caught380- Safe fixes are applied silently; unsafe changes surface to user381- `harness check-docs` runs after every fix batch; failed fixes are reverted382- Bootstrap handles cold start (no AGENTS.md) with graph path and directory structure fallback383- Standalone skills work independently exactly as today when invoked without pipeline context384- Entire pipeline runs without graph using static analysis fallbacks385- PASS/WARN/FAIL report includes per-category breakdown and specific remaining findings386- Drift fixes in FIX phase are excluded from AUDIT findings (no double-counting)387388## Rationalizations to Reject389390These are common rationalizations that sound reasonable but lead to incorrect results. When you catch yourself thinking any of these, stop and follow the documented process instead.391392| Rationalization | Why It Is Wrong |393| ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |394| "The drift finding is marked unsafe but the fix is obvious, so I will apply it silently" | Never apply a fix classified as unsafe without explicit user approval. The Iron Law: safe fixes are silent, unsafe fixes surface. |395| "The convergence loop reduced findings from 8 to 6, but the remaining ones are hard -- I will keep iterating" | If a convergence iteration does not reduce the finding count, stop immediately. Continuing without progress wastes iterations. |396| "I can write the drift detection logic directly instead of delegating to detect-doc-drift" | The pipeline delegates, never reimplements. Each sub-skill retains full standalone functionality. |397| "The graph is not available so the pipeline results will be unreliable" | The entire pipeline runs without a graph using static analysis fallbacks. Reduced accuracy is noted in the report, not used as an excuse to skip. |398399## Examples400401### Example: Full pipeline run with fixes402403```404Input: --fix flag set, graph available, AGENTS.md exists4054061. FRESHEN — Graph exists, 3 commits behind (< 10, skip refresh)407 AGENTS.md exists, no bootstrap needed4082. DETECT — detect-doc-drift found 8 findings:409 2 critical (deleted file still referenced)410 3 high (renamed functions)411 2 medium (stale descriptions)412 1 low (formatting)4133. FIX — Iteration 1:414 3 safe fixes applied (renamed file paths)415 2 probably-safe presented, 2 approved416 2 unsafe surfaced to user417 harness check-docs: pass418 Re-detect: 1 new finding (cascading rename)419 Iteration 2:420 1 safe fix applied421 Re-detect: 0 new findings — converged4224. AUDIT — validate-context-engineering found 5 gaps423 2 already in exclusions (fixed in FIX) → 3 remaining4245. FILL — 1 safe fill (broken link redirect)425 1 probably-safe (new module entry) → approved426 1 unsafe (complex module docs) → deferred427 Re-audit: converged4286. REPORT — Verdict: WARN429 Accuracy: 2 drift findings remaining (0 critical, 0 high, 1 medium, 1 low)430 Coverage: 12/14 modules documented (86%)431 Links: 0 broken references432 Freshness: Graph current433```434435### Example: CI mode (non-interactive)436437```438Input: --fix --ci flags set, no graph4394401. FRESHEN — No graph (notice logged), AGENTS.md exists4412. DETECT — 4 findings (1 critical, 2 high, 1 medium)4423. FIX — 2 safe fixes applied silently443 probably-safe and unsafe: logged to report (no prompts)4444. AUDIT — 2 gaps (1 deduped) → 1 remaining4455. FILL — 0 safe fills, 1 probably-safe logged to report4466. REPORT — Verdict: FAIL (1 critical finding remains)447```448449### Example: Bootstrap from directory structure450451```452Input: --bootstrap flag set, no graph, no AGENTS.md4534541. FRESHEN — No graph, no AGENTS.md455 Fallback bootstrap: glob src/*, read package.json456 Generated minimal AGENTS.md (32 lines)457 context.bootstrapped = true4582. DETECT — 0 drift findings (fresh AGENTS.md, no stale refs)4593. AUDIT — 6 gaps (4 undocumented modules, 2 missing context)4604. REPORT — Verdict: WARN (>30% modules undocumented, no graph)461```462463## Gates464465- **No fix without verification.** Every fix batch must be followed by `harness check-docs`. If check fails, revert the batch.466- **No unsafe auto-apply.** Fixes classified as `unsafe` are never applied without explicit user approval. In `--ci` mode, they are logged but never applied.467- **No reimplementation of sub-skill logic.** The pipeline delegates to sub-skills. If the DETECT phase is writing drift detection code, the plan is wrong.468- **No convergence without progress.** If a convergence loop iteration does not reduce the finding count, stop immediately. Do not retry.469- **Max 5 iterations per convergence loop.** Hard cap to prevent runaway loops.470471## Escalation472473- **When findings exceed 50:** Focus on critical and high priority only. Defer medium and low to a follow-up run.474- **When bootstrap produces low-quality AGENTS.md:** This is expected without a graph. Log a notice recommending `harness scan` and accept the reduced quality for the current run.475- **When convergence loop does not converge within 5 iterations:** Stop the loop, log remaining findings, and proceed to the next phase. The report will reflect the unconverged state.476- **When a sub-skill fails:** Log the failure, skip the phase, and continue the pipeline. The report will note the skipped phase with a WARN or FAIL verdict.477- **When `harness check-docs` is unavailable:** Fall back to file existence checks and link validation via grep. Log a notice about reduced verification accuracy.