Plan the core and integration API migration

This commit is contained in:
2026-11-25 13:45:13 +00:00
parent f0ba5cce84
commit a7dd841219
3 changed files with 386 additions and 22 deletions

View File

@@ -14,6 +14,10 @@ another code audit or an implementation plan.
The companion [remediation discussion](discussion.md) collects review
recommendations and open choices in discussion order. Accepted decisions there
qualify proposed remediation; finding statuses here track implementation.
The [Core And Integration API Roadmap](../core-integration-api.md) takes
implementation priority over the remaining catalog work. Reassess affected
findings after that migration rather than assuming their current remediation
remains unchanged.
The **45 original finding entries** reduce to **33 outstanding catalog entries
and one resolved documentation entry**. Repeated responsibility findings are

View File

@@ -194,32 +194,26 @@ broader consolidation.
## 5. Producer State And Shared Reconciliation Lifecycle
**Findings:** CAT-015 and CAT-016; coordinate CAT-007.
**Status:** Open technical design review.
**Status:** Expanded API direction accepted; implementation planned separately.
Make delivered-candidate state, invalidation, assessment, and terminal disposition
explicit. Small private phase results may make the producer clearer than coupled
mutable closure variables. Keep native execution, continuation history, structural
repair, and admission with PromptKit.
The discussion selected a clear core/integration boundary, core ownership of as
much demonstrated shared lifecycle responsibility as practical, and a clean,
flexible API that future integration authors can understand without reading core
execution internals. Improving private producer state alone does not satisfy
that target. Internal integration interfaces may change to achieve it.
For NPC, item, and location normalization, share only the demonstrated common
reconciliation lifecycle. Families retain preprocessing, identity, typed proposal
application, fallback validity, prompts, and diagnostic meaning. Every proposal
continues to apply afresh to fixed originals.
The [Core And Integration API Roadmap](../core-integration-api.md) now owns the
targeted end state, migration work, verification, and meaningful open API choices.
Execute that initiative before the remaining audit remediation, then reassess
which findings remain against the resulting architecture. Items 1–4 remain
accepted; later discussion items are not silently accepted by this change.
Before committing to a helper, show how a representative family caller becomes
easier to follow. Avoid replacing readable procedures with an elaborate callback
framework. Verify final-turn assessment, candidate invalidation, cancellation,
capture errors, cache hits, and strict/permissive outcomes through existing
behavioral boundaries.
CAT-007's native usability/error-detail correction is accepted and included in
that roadmap. Producer disposition and validator unavailability remain distinct;
no new structural repair loop or budget is selected.
CAT-007 is a narrower correction: retain native failed-validation details and
distinguish a completed failed content check from an operational native error.
A small shared usability check should suffice. Preserve producer disposition and
validator unavailability as distinct caller outcomes. Correct the misleading test
oracle without introducing another validation protocol or extending repair budgets.
That fix need not wait for the broader producer refactor.
**Decision:** Pending.
**Decision:** Accepted direction; detailed API choices and implementation status
are maintained in the linked roadmap.
## 6. Finalization, Completed Diagnostics, And Intermediate Lifetimes

View File

@@ -0,0 +1,366 @@
# Core And Integration API Roadmap
## Status And Purpose
**Status:** Direction accepted; detailed API choices open; implementation pending.
This roadmap is the next implementation priority, before the remaining
[audit catalog](audit/catalog.md) remediation. It develops
[discussion Item 5](audit/discussion.md#5-producer-state-and-shared-reconciliation-lifecycle)
into an integration-author API initiative, rather than a private-helper cleanup.
The document is a plan; this pass changes no application code.
The selected goals are:
1. Make the boundary between Notarius core and integrations clear and well defined.
2. Put as much demonstrated shared responsibility as practical in core, with a
clean, flexible interface for integration-owned behavior.
3. Make the API understandable and usable by future integration authors without
requiring them to reconstruct the execution lifecycle from core internals.
Here, **core** means the framework contracts and orchestration, including shared
producer and reconciliation facilities. **Integrations** means Notarius artifact
families and their stage modules, validators, codecs, and domain behavior. It does
not mean replacing the adopted kits' APIs with another abstraction.
## Current Baseline
Reviewed baseline: `f0ba5cce843182e0f5f3eaa6577110a087cf1422`.
Production code is unchanged from the catalog's audited baseline
`3887d89b763b7040efc866d4a57eb910d8778730`; intervening changes are documentation.
[go.mod](../../go.mod) selects Go 1.27.0, PromptKit v0.25.0, ConfigKit v1.4.0,
CommandKit v0.8.0, ckconfig v0.11.0, and ckprompt v0.12.0. No dependency upgrade is
required by this plan; assess any concrete upstream gap if implementation finds one.
The fixed typed pipeline and native-kit responsibilities are already implemented.
[Module Internals](../internal/modules.md) and
[Pipeline Internals](../internal/pipeline.md) describe current authoring and execution.
| Current surface | Responsibility and friction |
| --- | --- |
| [Typed stage requests](../../internal/framework/contracts/typed_pipeline.go) and [producer contracts](../../internal/framework/contracts/producer.go) | Requests expose `ProducerOperation[T]`, including assessor, controls, cache binding, execution options, and reuse eligibility. Authors carry framework plumbing through their module implementation. |
| [RunProducer](../../internal/framework/pipeline/producer.go) | Shares native execution, assessment, corrections, caching, and disposition, but its closures coordinate candidate, guidance, failure, acceptance, and capture state through mutable outer variables. |
| [Producer outcome helpers](../../internal/framework/pipeline/producer_outcome.go) | Integrations choose between `RunProducer`, `AssessProducer`, and `FinishProducerFailure` for model work, no-model answers, and preparation outcomes. Correct lifecycle composition remains part of the authoring recipe. |
| [Spell extraction](../../internal/modules/dnd/extract/spells/extractor.go) and [scene planning](../../internal/modules/dnd/chunk/scenes/chunker.go) | Modules prepare domain/native inputs, supply interpretation/correction/fallback closures, invoke the producer, and assemble typed outcomes. Scene planning also demonstrates correctable interpretation without a usable candidate. |
| [NPC](../../internal/modules/dnd/normalize/npcregistry/normalizer.go), [item](../../internal/modules/dnd/normalize/itemregistry/normalizer.go), and [location](../../internal/modules/dnd/normalize/locationregistry/normalizer.go) reconciliation | Each repeats fixed-original preparation, proposal/evidence tracking, no-model and limit dispositions, correction construction, fallback bookkeeping, and result assembly around existing shared mechanisms. |
| [Semantic reconciliation](../../internal/framework/semanticreconcile/preparation.go) | Already provides neutral candidate preparation, proposal safety, request construction, and typed application. The missing sharing is primarily the lifecycle connecting those facilities to production. |
| [Combat semantic validation](../../internal/modules/dnd/validate/scenedescriptions/combat_semantics/validator.go) | Executes one native assessment directly. It shares the native-usability classification defect with the producer, but is not a producer correction loop. |
The production migration inventory starts with ten D&D extractors (spells,
combat turns, enemy events, scene descriptions, and NPC/item/location registries
and occurrences), D&D scene planning, and the three registry normalizers.
Combat/enemy extraction and registry reconciliation have no-model paths that must
be exercised. Deterministic stage completion and typed registration/preparation
also participate where they connect to the changed contracts. Confirm the caller
inventory during implementation rather than treating these counts as invariants.
## Targeted End State
### Ownership
| Responsibility | Target owner |
| --- | --- |
| Transport, credentials, native structural validation/repair, transient retries, exchanges, continuation iteration, and backend admission | PromptKit, through its native types and APIs |
| Configuration loading/composition and command parsing/rendering | ConfigKit, CommandKit, and their existing application integrations |
| Operation lifecycle, configured assessment, native continuation coordination, cache use, standard evidence, cancellation, and terminal mode application | Notarius core |
| Domain input preparation, prompt selection/native input construction, result interpretation, deterministic identity, and domain transformations | Integration |
| Validation meaning and actionable repair instructions | Detecting integration validator or interpretation rule; core collects and applies configured assessment |
| When supported fallback is selected and how it affects outcomes/reuse | Core, applying resolved policy |
| What constitutes a valid fallback and how to construct it | Integration, with existing intrinsic/downstream checks |
| Fixed-original and current-proposal reconciliation bookkeeping | Shared core reconciliation facility |
| Entity compatibility, typed proposal application, family diagnostics, and domain-specific reconciliation evidence | Integration, using family-shared helpers where appropriate |
| Physical publication, invocation debug allocation/finalization, and terminal reporting | Existing CLI/recorder boundary |
Core should own the complete shared lifecycle, not merely offer utilities that
authors must arrange correctly. That does not require hiding native PromptKit
requests/results or moving domain rules into the framework.
### Integration Author Experience
An author describes one typed operation: prepare its domain material; provide a
deterministic candidate or the native request/interpretation behavior needed for
model work; supply supported correction and fallback behavior. Core runs the
appropriate lifecycle and assembles the resulting acceptance/fallback outcome.
An ordinary integration no longer selects assessment/cache collaborators, decides
which terminal helper to invoke, tracks native capture finalization, or maintains
framework acceptance state. Required inputs and optional capabilities should be
clear from the author-facing types and documentation. The specific Go API is
selected under Open Decision 1, not prescribed by illustrative terminology here.
Support the existing meaningful preparation outcomes: a deterministic answer,
model work, an existing preparation-limit disposition, or an ordinary failure.
Moving their handling into core must not turn arbitrary preparation errors into
permissive recovery. A model-backed module may legitimately complete without a
model call; deterministic work needs no manufactured prompt or cache key.
Candidate-associated findings, guidance, and applicable proposal information
travel with the evaluation that produced them. Integrations should not need
parallel mutable variables to remember which findings belong to the final
candidate. Private fixed operation data and domain helpers remain legitimate;
this is not a requirement that all integration code be pure or stateless.
Keep direct programmatic use straightforward through the selected core entry
point. Changing internal interfaces is allowed where it improves the target
boundary; retaining the present method signatures or lifecycle plumbing is not
the purpose of the migration. This does not promise a versioned public SDK,
dynamic plugin loading, or universal backwards compatibility.
### Reconciliation As A Focused Facility
Build a typed reconciliation facility on the same producer lifecycle. It owns
fixed preparation, proposal decoding/safety bookkeeping, current-proposal
replacement, standard evidence, and disposition handoff. Families supply records,
candidate projections, prompts, application policies, fallback construction, and
domain diagnostics. Reuse the existing neutral reconciliation mechanisms.
Preserve item currency compatibility, NPC naming/identity rules, and distinctions
between same-named locations. Neutral proposal issues can be translated into
family diagnostics by a D&D-local adapter; generic core need not import D&D.
Ordinary extractors do not acquire reconciliation concepts they do not use.
The useful outcome is that family code reads primarily as domain preparation and
policy. If a proposed common facility instead needs numerous family switches,
revise the boundary rather than hiding three procedures in a configurable engine.
### Native Result Handling
The CAT-007 correction is accepted. Share a small native usability check where
needed by producers and the LLM validator. Distinguish absent results, completed
failed validation, and actual native Go errors; retain useful validation details
without manufacturing `promptkit.ErrValidation` for completed content rejection.
Preserve producer disposition and validator unavailability as separate outcomes.
Correct the test that expects the wrong sentinel and the native fixture that
currently accepts an arbitrary error. This adds no repair loop or budget.
## Behavioral Scope
This is an ownership/API migration. Existing selected behavior is the starting
contract, as recorded in [Architecture](../policy/architecture.md),
[Configuration](../config.md), and the focused internal guides. In particular:
- Preserve complete configured assessment of each delivered usable candidate,
including the last allowed revision; no duplicate outer assessment. An unusable
interpretation may supply domain correction guidance without claiming a candidate.
- Keep native structural work upstream. Preserve growing native exchanges,
explicit execution selections, and release of native admission before nested
validation. A failed/result-less correction does not revive an earlier candidate.
- Apply reconciliation proposals afresh to fixed originals. Preserve final-only
fallback behavior, ordinary deterministic error propagation, and cancellation
precedence. Moving code must not widen fallback eligibility.
- Preserve accepted-result reuse under the original prepared message-content
hash, current-source usability checks, and no semantic reassessment on hits.
Store final accepted domain artifacts/plans, not exchanges or rejected proposals.
- Preserve fallback disclosure and dependency-specific reuse ineligibility,
required-capture failure handling, and independent consumer-owned observation.
- Preserve typed artifact/codec compatibility, module selections, native prompt ownership,
fixed stage boundaries, worker/admission separation, and domain output shapes.
These are references to existing behavior, not an invitation to freeze incidental
callback order, private error prose, debug filenames, or implementation structures.
Keep flexibility for concrete integration requirements. No new correction limits,
input restrictions, shutdown guarantees, resource caps, or model-quality claims
are selected here.
A redesign of input/output adapters, the CLI, registry discovery, or configuration
composition is not needed merely to centralize producer behavior. Adapt their
existing connections where necessary. Native LLM validators retain their one-shot
assessment role; sharing usability/evidence support does not enroll them in the
producer correction lifecycle.
## Work From The Baseline
### 1. Define And Exercise The Author-Facing Contract
- Inventory production and programmatic callers of the current producer/outcome
helpers, typed operation requests/results, registration, and preparation.
- Resolve Open Decisions 1–3 with concrete API sketches for spell extraction,
registry normalization, and a no-model branch. Include scene-plan interpretation
that requests correction before a candidate can be materialized.
- Specify which inputs are operation-owned or borrowed, which implementations
are reused concurrently, and the lifetime of optional evidence hooks. Document
actual behavior without promising arbitrary collaborator thread safety or
prohibiting reasonable per-operation state.
- Show how ordinary use avoids exposed assessor/cache replacement and terminal
helper selection. Identify which existing types can be reused and which should
become private or be replaced. Exact helper names/files are implementation choices.
This is an implementation design step, not a separate approval ceremony or a
requirement to create a large specification before trying representative callers.
### 2. Establish Core-Owned Execution
- Implement the selected cohesive typed operation boundary and wire it through
registration/preparation and runner completion where necessary.
- Make deterministic completion, native execution, correctable interpretation,
assessment, preparation dispositions, and supported fallback explicit paths
owned by core. Separate candidate state from pending native capture state.
- Keep existing cache, assessment, capture, and terminal helpers internally where
they remain useful; replace their author-facing choreography, not merely names.
- Integrate CAT-007's usability/detail correction and focused regressions.
- Migrate one extractor and a no-model path end to end, including registration,
capture, reuse, assessment, and final typed results. Private transitional adapters
may help keep changes reviewable, but are not the completed authoring API.
### 3. Consolidate Reconciliation And Migrate Producers
- Build the shared reconciliation facility on the selected operation boundary.
Move no-model/limit handling, current-proposal state, and common evidence/result
assembly out of the three family procedures.
- Migrate NPC, item, and location normalizers, retaining independent family
expectations for identity, application, omissions, and fallback semantics.
- Migrate all affected extractors and scene planning. Exercise combat-gated
no-model branches and chunk-plan materialization/assessment/cache behavior.
- Adapt deterministic stage completion as needed while preserving its ordinary
one-production/assessment path. Do not force deterministic modules to declare
model requests or reconciliation policies.
- Keep one-shot model validation native, sharing the corrected usability boundary
and any necessary evidence support without a new semantic retry mechanism.
### 4. Remove Superseded Plumbing And Teach The API
- Remove unused author-facing lifecycle fields, wrappers, and duplicate family
state once callers have moved. Do not leave two competing supported authoring
recipes simply to preserve the old internal arrangement.
- Update [Module Internals](../internal/modules.md),
[Pipeline Internals](../internal/pipeline.md), and
[D&D Internals](../internal/dnd.md) alongside implementation. Update architecture
ownership and record significant changed decisions through the existing ADR
process, preserving accepted ADR bodies.
- Supply one minimal working integration example and point to a richer registry
example. Explain required/optional capabilities, no-model completion, domain
guidance versus operational errors, fallback, concurrency, and evidence ownership.
Reuse a production example or small maintained fixture rather than a new demo app.
- Verify that the example can be understood without reading the core producer.
Test actual registration/execution of the example where useful; do not add a
subjective readability gate or a required external-author study.
### 5. Verify And Reassess The Audit
- Finish the relevant behavioral verification below and review remaining callers
for old lifecycle composition that was merely relocated into integrations.
- Reassess overlapping catalog entries against the resulting implementation.
Record resolved, partially addressed, and remaining work with concrete evidence.
- Resume the remaining audit remediation using that revised catalog. Completion
of this roadmap does not require completing unrelated catalog work first.
These are coherent work units, not required release boundaries. Keep each unit
reviewable and preserve working behavior during migration.
## Verification And Completion Evidence
Use existing boundary tests and real native kits with offline provider fakes.
Tests should protect behavior and author-facing contracts, not private callback
sequences or exact struct layouts. Relevant starting points include
[producer](../../internal/framework/pipeline/producer_test.go),
[producer cache](../../internal/framework/pipeline/producer_cache_test.go),
[operation completion](../../internal/framework/pipeline/runner_operation_test.go),
[chunk-plan cache](../../internal/framework/pipeline/chunk_plan_cache_test.go),
and [native capture](../../internal/framework/pipeline/native_capture_test.go) tests.
Cover the distinct risks introduced by moving ownership:
- Registered typed extraction, scene planning, reconciliation, and no-model paths
reach core execution without integration-owned assessment/disposition plumbing.
- Every usable revised candidate receives complete assessment; interpretation-only
guidance can request correction; native failed checks retain details and do not
become semantic approval or an extra structural-repair loop.
- Fixed-original reconciliation retains each family's expected output, fresh
proposal application, and final-only fallback. Failed/undelivered corrections
and caller cancellation retain their established behavior.
- Cache hits, accepted corrected writes, failed refresh, fallback-derived
ineligibility, and cache/capture error distinctions survive the new boundary.
- Native evidence and supplied observers remain attached to actual executions;
cache hits invent no model execution. Disabled evidence does not require
expensive domain-only debug construction in the new API.
- Concurrent operations do not share candidate state; nested validation still
works with limited native capacity. Reuse relevant worker/admission tests.
Place common lifecycle coverage in core and retain representative independent
family tests. Simplify tests coupled to retired plumbing; do not derive expected
domain outputs from the same helper under test. This is a coverage guide, not a
new test for every row or an exhaustive cross-product requirement.
Run focused checks while iterating, then the repository's offline full tests,
vet, and build for the shared-contract migration, with focused race checks for
changed concurrency paths. Follow [Testing Policy](../policy/testing.md) and
[Development](../development.md#validation). No paid inference, benchmark target,
coverage percentage, or new release gate is required. This planning pass has not
run those implementation checks.
The roadmap is complete when affected production integrations use the selected
API, ordinary authors no longer compose the shared lifecycle, obsolete paths are
removed, behavior is verified, author guidance matches the implementation, and
the catalog is reassessed. A clearer private `RunProducer` alone is insufficient.
## Relationship To The Audit
| Findings | Treatment in this roadmap |
| --- | --- |
| CAT-015 / CAT-016 | Central scope: replace coupled author-facing lifecycle responsibilities and duplicated registry reconciliation coordination. |
| CAT-007 | Accepted correction included at both producer and one-shot validator boundaries, including the misleading test oracle. |
| CAT-006 / CAT-008 / CAT-009 / CAT-022 / CAT-023 | Coordinate candidate/evidence/diagnostic lifetime changes where this migration touches them. Runner-wide finalization and CLI lifecycle issues remain outstanding unless separately demonstrated fixed. |
| CAT-003 / CAT-024 / CAT-025 / CAT-032 | Keep new optional evidence inexpensive and document actual concurrency. Apply the accepted whole-source capture direction if touched, but do not assume a package move or the entire capture inventory must be redesigned here. |
| CAT-014 / CAT-017 / CAT-018 | Accepted composition/copying direction remains valid. Make only changes required by the new registration/operation boundary; broader consolidation follows this initiative unless it becomes a concrete prerequisite. |
| Other entries | Reassess after migration; retain independent defects, optional cleanups, and CAT-034's resolved status. |
The accepted diagnostic retention, source-capture, signal, and composition choices
in [discussion Items 1–4](audit/discussion.md) remain selected future work. This
roadmap does not reverse them or silently incorporate all their implementation.
If an overlapping fix is completed during this work, record its actual scope and
tests. Catalog IDs are evidence references, not a mandate to close every entry.
## Open Decisions
### D1. How Integrations Hand An Operation To Core
**Recommendation:** Prefer a small typed operation definition returned by the
integration and consumed by core. Use ordinary Go fields/functions for optional
behavior and keep lifecycle collaborators inside the executor. Preparation can
produce a deterministic candidate or model-backed behavior without the module
choosing execution helpers. This makes the ownership visible in control flow and
offers one understandable recipe; standalone callers can use the same executor.
Its cost is adapting current stage interfaces and representing the legitimate
preparation outcomes without an overly broad bag of optional fields.
**Viable alternative:** Keep stage methods and supply an operation-scoped core
executor that the integration invokes once with its typed behavior. This reduces
registration changes and can fit existing custom preparation naturally. It still
centralizes mechanics, but leaves authors responsible for invoking the executor
on every relevant branch and risks recreating the current no-model/terminal
helper choreography. Select it only if representative callers are comparably
clear. Neither choice mandates a universal plugin interface or exported SDK.
### D2. Carrying Candidate-Associated Domain Information
**Recommendation:** Return candidate-associated guidance and diagnostics explicitly
from interpretation/application, with reconciliation-specific typed issue and
omission information retained by the reconciliation facility. Core replaces that
evaluation as one unit and invalidates the previous candidate when selecting a new
execution, so a subsequent failure cannot revive stale state. Keep domain translation in the
family adapter. This eliminates stale parallel closure state without teaching
generic execution about D&D; some result types and adapter signatures will change.
**Viable alternative:** Permit a small per-operation typed domain session to retain
annotations, exposing explicit evaluate/finalize methods to core. This can handle
rich domain bookkeeping without propagating extra types through registration,
but invalidation and candidate/annotation correspondence are harder to inspect.
It should not become a session shared across concurrent operations. Compare both
shapes with item reconciliation's richer findings before fixing the API.
### D3. The Convenient Correction-Request Authoring Path
**Recommendation:** Offer a small convenience path for the existing common
pattern: a native correction prompt and ordered guidance, with core carrying the
resolved execution selections and PromptKit carrying history. Retain a native
request-builder option for domain-specific correction material. Existing prompt
declarations still own templates and schemas. This removes repeated request glue
while retaining flexibility, at the cost of two authoring forms that need a clear
relationship; the convenience form should reduce to the same native builder path.
**Viable alternative:** Require every integration to provide a native correction
request builder, with one shared helper available for ordinary guidance binding.
This has a smaller formal API and maximum visible control, but repeats more setup
and places selection propagation details closer to authors. It is reasonable if
the helper makes ordinary examples just as direct. Neither choice fixes all
integrations to one prompt schema, guidance variable name, or correction policy.