Skip to content

Commit 34e9f03

Browse files
feat: stabilize runtime and add stack-neutral quality gates
1 parent 0ea0fc6 commit 34e9f03

19 files changed

Lines changed: 899 additions & 491 deletions
Lines changed: 81 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# DocGen 2 contracts
22

3-
DocGen 2 treats provider output as untrusted and prevents providers from becoming repository scanners. Deterministic code owns source access, indexing, retrieval, validation, budgets, rendering of low-risk references, and most auditing.
3+
DocGen 2 is a language-, framework-, and architecture-neutral documentation pipeline. It treats provider output as untrusted. Deterministic code owns source eligibility, indexing, retrieval, budgets, checkpoints, artifact validation, low-risk rendering, quality gates, and publishing. Providers receive bounded context packs rather than unrestricted repository access.
44

55
## Boundary matrix
66

@@ -9,53 +9,84 @@ DocGen 2 treats provider output as untrusted and prevents providers from becomin
99
| source eligibility | `.docgen/index/inventory.json` | deterministic inventory |
1010
| searchable knowledge | `.docgen/index/semantic.db` | deterministic indexer |
1111
| provider input | `.docgen/context/<stage>/*.json` | bounded context compiler |
12-
| core synthesis | `.docgen/model/{system,business,flows,catalogs}.json` | one bounded provider call + orchestrator validation |
13-
| enterprise synthesis | `.docgen/model/{security,operations,testing,data-governance,decisions,configuration,change-impact,ownership}.json` | one bounded provider call + orchestrator validation |
12+
| core synthesis | `.docgen/model/{system,business,flows,catalogs}.json` | bounded provider call + orchestrator validation |
13+
| enterprise synthesis | `.docgen/model/{security,operations,testing,data-governance,decisions,configuration,change-impact,ownership}.json` | bounded provider call + orchestrator validation |
1414
| page plan | `.docgen/plan/manifest.json` | bounded planner + deterministic canonicalization |
15-
| reference pages | selected `docs/**/*.md` | deterministic renderer |
16-
| narrative pages | selected `docs/**/*.md` | bounded writer |
17-
| page claims | `.docgen/traceability/pages/<page-id>.json` | same generation call or deterministic item mapping |
18-
| structural/grounding audit | `.docgen/audit/deterministic.json` | deterministic auditor |
19-
| semantic risk audit | `.docgen/audit/llm-risk.json` | selective, hash-cached provider call |
15+
| generated pages | `docs/**/*.md` | deterministic renderer or bounded writer |
16+
| page claims | `.docgen/traceability/pages/<page-id>.json` | page generation + deterministic normalization |
17+
| runtime checkpoints | `.docgen/state/state.json` | orchestrator |
18+
| structural and grounding audit | `.docgen/audit/deterministic.json` | deterministic auditor |
19+
| selective semantic-risk audit | `.docgen/audit/llm-risk.json` | hash-cached bounded provider call |
2020
| quality summary | `.docgen/audit/quality-summary.json` | deterministic aggregator |
2121
| publishing | `.docgen/publish/*.json`, `docs/llms*.txt` | deterministic publisher |
2222
| provider usage | `.docgen/telemetry/provider-runs.jsonl`, `.docgen/budget/report.json` | orchestrator |
23+
| provider diagnostics | `.docgen/runs/*.stdout.log`, `.docgen/runs/*.stderr.log` | orchestrator |
2324

2425
## Hard invariants
2526

26-
1. **Source is indexed once** — provider sessions do not broadly scan repository source.
27-
2. **Canonical inventory**`.gitignore`, nested non-Git fallback, `.docgenignore`, binary signatures, UTF-8 checks, and size limits are applied before indexing.
28-
3. **Context-only provider** — hooks restrict provider reads to declared `.docgen/context/**` packs and stage outputs.
29-
4. **Bounded context** — each pack has an explicit token budget and reports omitted facts/model items.
30-
5. **Content addressing** — contexts, stages, pages, and risk audits are reusable only while selected item hashes remain unchanged.
31-
6. **Hard provider budget** — a call is refused before execution when it would exceed configured call, input-token, output-token, or per-call limits.
32-
7. **Typed models** — semantic items preserve stable identity, kind, classification, confidence, evidence, and unknowns.
33-
8. **Direct evidence for FACT** — deterministic audit rejects FACT page claims without evidence or with evidence outside the canonical inventory.
34-
9. **Qualified model identity** — SQLite item IDs are model-qualified to prevent cross-model collisions.
35-
10. **Deterministic references** — exhaustive low-risk catalogs are rendered without provider calls.
36-
11. **Selective audit** — LLM audit runs only for risk-scored pages and only when page/context hashes change.
37-
12. **No repair loop** — there is no automatic enrich, fix, or full re-audit cycle.
38-
13. **No parent delegation** — provider prompts complete their bounded task directly and do not load agent/skill trees.
39-
14. **Mermaid only** — published diagrams may not use PlantUML, Graphviz, or image-only diagrams.
40-
15. **Breaking migration** — v1 workflow artifacts are archived, not interpreted as v2 checkpoints.
41-
42-
## Core model surfaces
43-
44-
- `system.json`: components, relationships, workflows, unknowns;
45-
- `business.json`: actors, capabilities, concepts, rules, decisions, branches, lifecycles, invariants, use cases, unknowns;
46-
- `flows.json`: business, control, request, traffic, data, and event flows;
47-
- `catalogs.json`: endpoints, message handlers, dependencies, data stores, scheduled jobs.
48-
49-
## Enterprise model surfaces
50-
51-
- `security.json`
52-
- `operations.json`
53-
- `testing.json`
54-
- `data-governance.json`
55-
- `decisions.json`
56-
- `configuration.json`
57-
- `change-impact.json`
58-
- `ownership.json`
27+
1. **Technology neutrality** — no language, framework, protocol, datastore, messaging system, deployment model, or repository shape is assumed. Applications, libraries, CLIs, jobs, plugins, infrastructure, data pipelines, embedded systems, monoliths, services, and mixed workspaces are all valid inputs.
28+
2. **Canonical source boundary** — Git-aware discovery or filesystem fallback, `.gitignore`, `.docgenignore`, binary signatures, UTF-8 checks, and size limits are applied before indexing.
29+
3. **One index phase per full run**`docgen all` indexes once, then all later phases consume that inventory and semantic database.
30+
4. **Context-only provider** — provider work is bounded by declared context packs and explicit output contracts; prompts must not perform broad repository scans.
31+
5. **Bounded context** — every pack has a token budget and records omitted facts and model items.
32+
6. **Content addressing** — contexts, stages, pages, traces, audits, and publishing are reusable only while their source, model, input, and artifact hashes remain current.
33+
7. **Crash-safe page checkpoints** — page state records running, completed, and failed work. A failed generation batch preserves valid pages and retries only missing or invalid pages.
34+
8. **Fresh-artifact recovery** — a provider non-zero exit may be recovered only when the current invocation produced artifacts that pass the complete output contract. Pre-existing stale artifacts are never accepted as recovery proof.
35+
9. **Effective provider configuration** — every call records and prints the executable, model, effective `maxTurns`, timeout, context size, and log files. The supported minimum conversation-turn budget is 30.
36+
10. **Hard provider budget** — a call is refused before execution when configured call, token, or per-call limits would be exceeded.
37+
11. **Typed semantic claims** — model items and page claims use `FACT`, `INFERENCE`, `ASSUMPTION`, or `UNKNOWN`, with confidence, evidence, and stable qualified identity.
38+
12. **Grounded facts** — a `FACT` requires repository-relative evidence inside the canonical inventory. By default it also requires valid line evidence whose source hash still matches the index.
39+
13. **Context-bound generation** — generated claim evidence and model references must come from the page's supplied context unless explicitly disabled.
40+
14. **Qualified model identity** — references use `<model>:<semantic-id>` to prevent collisions and permit deterministic validation.
41+
15. **Deterministic references where possible** — generic components, interfaces, dependencies, data assets, automation, configuration, ownership, and change-impact catalogs can be rendered without provider calls.
42+
16. **Quality before publishing** — publishing requires a current passing audit and revalidates source, model, page, trace, links, evidence, and audit hashes to reject stale output.
43+
17. **Selective semantic-risk audit** — provider audit is limited to risk-scored pages after deterministic validation and is reused only while its inputs remain unchanged.
44+
18. **No hidden repair loop** — there is no unbounded enrich/fix/re-audit cycle. Recovery is bounded and checkpointed.
45+
19. **Mermaid only** — generated diagrams may not depend on PlantUML, Graphviz, or image-only formats.
46+
20. **Breaking migration boundary** — legacy workflow artifacts are archived rather than interpreted as current checkpoints.
47+
48+
## Framework-neutral semantic surfaces
49+
50+
The shape is extensible. Technology-specific arrays are optional signals, not requirements.
51+
52+
- `system.json`: components, modules, packages, runtimes, deployment units, relationships, workflows, and unknowns.
53+
- `business.json`: actors, capabilities, concepts, rules, decisions, branches, lifecycles, invariants, use cases, and unknowns.
54+
- `flows.json`: execution, control, request, traffic, data, event, batch, and other evidenced flows.
55+
- `catalogs.json`: interfaces, contracts, dependencies, data assets, automations, build artifacts, configuration surfaces, plus optional protocol-specific catalogs when present.
56+
- enterprise models: security, operations, testing, data governance, decisions, configuration, change impact, and ownership.
57+
58+
The deterministic index always provides generic file artifacts and source chunks. It may additionally recognize common symbols, functions, imports/modules, manifests, configuration keys, runtime declarations, infrastructure resources, interfaces, data entities, scheduled automation, or security boundaries. Absence of a recognizer never makes a technology unsupported because bounded source chunks remain the fallback evidence surface.
59+
60+
## Runtime and resume contract
61+
62+
A full run is:
63+
64+
```text
65+
index -> modelCore -> modelEnterprise -> plan -> generate -> audit -> publish
66+
```
67+
68+
`docgen resume` runs the same state-aware pipeline. Completed stages and pages are reused only when their input hashes and required outputs remain valid. During generation:
69+
70+
1. each page is marked `running` with batch, context, and input identity;
71+
2. provider output is validated page-by-page;
72+
3. valid pages are checkpointed immediately;
73+
4. failed or missing pages are marked with their error;
74+
5. bounded recovery retries only the unresolved subset;
75+
6. a page becomes `completed` only after Markdown and traceability validation succeeds.
76+
77+
## Correctness gate
78+
79+
The deterministic audit validates, at minimum:
80+
81+
- source inventory membership, live-source hash, and evidence line ranges;
82+
- model JSON validity, qualified identities, classifications, confidence, and FACT evidence;
83+
- page frontmatter, H1, required sections, Mermaid policy, and local links;
84+
- page/trace identity, page hash, input hash, and generation context identity;
85+
- claim classification, confidence, evidence, context-bound grounding, and model references;
86+
- missing, duplicate, conflicting, stale, orphaned, or substantially duplicated artifacts;
87+
- model-reference coverage and configurable warning/failure policy.
88+
89+
The detailed report is `.docgen/audit/deterministic.json`. `.docgen/audit/quality-summary.json` is the publish gate and contains aggregate claim, evidence, model-reference, failure, warning, and selective-risk metrics.
5990

6091
## Page traceability
6192

@@ -64,26 +95,26 @@ Each page sidecar contains:
6495
```json
6596
{
6697
"schemaVersion": "2.0",
67-
"pageId": "quote-lifecycle",
68-
"pagePath": "docs/business/quote-lifecycle.md",
98+
"pageId": "component-lifecycle",
99+
"pagePath": "docs/architecture/component-lifecycle.md",
69100
"pageHash": "...",
70101
"inputHash": "...",
71102
"contextId": "...",
72103
"claims": [
73104
{
74-
"id": "quote-lifecycle:draft-submit",
75-
"statement": "A draft quote can be submitted.",
105+
"id": "component-lifecycle:transition",
106+
"statement": "The component transitions from pending to active.",
76107
"classification": "FACT",
77108
"confidence": 1,
78-
"evidence": [{"path": "src/QuoteService.java", "startLine": 120, "endLine": 146}],
79-
"sourceModelRefs": ["business:rule-submit-draft"]
109+
"evidence": [{"path": "src/component.ext", "startLine": 120, "endLine": 146}],
110+
"sourceModelRefs": ["business:transition-pending-active"]
80111
}
81112
]
82113
}
83114
```
84115

85-
The orchestrator fills page/input/context hashes after generation.
116+
The orchestrator normalizes and verifies page, input, and context hashes after generation.
86117

87-
## Workspace contracts
118+
## Workspace boundary
88119

89-
P3 remains deterministic and consumes current repository models plus commit/source/model hashes. Cross-repository edges require explicit repository identity, dependency targets, shared evidenced producer/consumer channels, or model references. Ambiguous relationships remain unresolved.
120+
Cross-repository synthesis remains deterministic and requires explicit repository identity plus evidenced relationships, declared dependencies, shared producer/consumer contracts, or qualified model references. Ambiguous relationships remain unresolved instead of being inferred from a preferred stack.

global-template/docgen/lib/context.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { estimateTokens, loadConfig, now, projectPaths, sha256, stableHash, writ
44
import { openDatabase } from './indexer.mjs';
55

66
const STAGE_QUERIES = {
7-
modelCore: 'architecture component workflow endpoint message business rule lifecycle request data event dependency persistence',
8-
modelEnterprise: 'security authorization operation observability failure recovery testing configuration ownership decision transaction consistency change impact',
9-
plan: 'architecture business rule lifecycle flow endpoint message security operation testing configuration ownership decision change impact',
10-
audit: 'fact evidence rule branch failure security transaction contract'
7+
modelCore: 'repository structure architecture component module package symbol interface contract dependency behavior domain rule state lifecycle control flow data flow event automation runtime build deployment',
8+
modelEnterprise: 'security trust identity permission secret operation observability failure recovery testing configuration ownership decision governance consistency concurrency idempotency compatibility change impact',
9+
plan: 'architecture behavior domain interface dependency data security operation testing configuration ownership decision onboarding reference tutorial runbook change impact',
10+
audit: 'fact evidence inference assumption unknown claim contradiction branch failure security consistency compatibility contract'
1111
};
1212
const CORE_MODELS = ['system', 'business', 'flows', 'catalogs'];
1313

0 commit comments

Comments
 (0)