Document thread planning contract and migration audit

This commit is contained in:
Codex 2026-12-05 16:17:49 +00:00
parent aac04e17d1
commit 8c54850647

View File

@ -0,0 +1,112 @@
# Intent and Threads audit and proposed contract
This is a source audit for task 154 at `aac04e17d1d16828a44fe11913a3daf2bb29ce6d`.
The contract below is a proposal for implementation planning. The audit did not
query Development or measure the prevalence of legacy data patterns.
## Current behaviour
| Area | Finding |
| --- | --- |
| Plotline and thread | `Models/CoreModels.cs` gives a plotline an optional book and a thread one parent plotline. A thread has a title, summary, type, status, importance, audit and archive fields, and separate introduction, planned resolution and actual resolution scene references. There is no single chapter-or-scene planning assignment on that model. |
| Explicit links | `Sql/340_SceneThreads.sql` stores a pair of scene and thread IDs. The same thread can appear in multiple scenes. `Services/Context/ContextThreads.cs` combines these links with thread event contributions and introduction and actual resolution milestones. The history display deduplicates by scene and excludes planned resolution by itself. `Sql/348_ContextSceneThreadRemove.sql` removes a direct link. If an event or milestone still exists, the association still appears. |
| Events and dependencies | `ThreadEvent` stores a scene, event role/type, title and description, provenance and target plotlines. `Models/PlotLineWorkspaceModels.cs` carries scene-to-scene dependencies separately from events. The Context Add path writes direct scene links and has no thread prerequisite check. Scene dependency edges and event plotline targets have distinct meanings from proposed thread prerequisite edges. |
| Notes and checklists | The existing thread summary is a single field. `Data/ImportRepository.cs` can combine incoming thread description, status metadata and notes into it, so there is no reliably reversible split. Writer and Scene Inspector have scene-scoped notes and checklist items. The newer Context Intent checklist in `Sql/346_ContextIntentChecklist.sql` has chapter/scene scope. None of these establishes ownership by an individual planned thread. |
| Attachments and entities | `Services/Writer/WriterAuthoringService.cs` loads attachments and characters by scene and resolves the scene's primary location. The current thread model has no separate planned character, location, or asset links. Scene evidence and spatial state have their own lifecycles. |
| Review and editing | `Services/Writer/WriterReviewService.cs` reads the shared Writer authoring context at chapter scope or at a scene verified through accepted paragraph assignments. The Review and Writer editing views reuse `Views/Writer/_AuthoringSection.cshtml` for chapter and scene fields, including scene notes and checklists. The shared authoring model loads scene thread events and attachments, while the Review partial renders the editable sections and editorial observations. The Context direct-link picker uses a separate read/write path. Review observations have chapter, scene or passage anchors and a separate write contract. `Sql/340_SceneThreads.sql`, `348_ContextSceneThreadRemove.sql` and `346_ContextIntentChecklist.sql` gate edits to active Owners and Collaborators. Review and editing surfaces do not themselves confer project access. |
| Portability | `Data/ProjectBackupRepository.cs` exports threads, events and direct links separately. `Sql/340_SceneThreads.sql` remaps direct links on restore and accommodates omission in older backup formats. This separation must survive the new model. |
Application source paths in this table are relative to `PlotLine/`.
## Proposed planning contract
- Keep a discrete thread under one plotline, with a stable identity, title and
description. Store notes, optional checklist items and attachment references
under that thread. Use typed references to existing characters, locations and
assets. Validate project membership and applicable book scope. Preserve the
existing access, attachment download and lifecycle controls. Planned references
do not create appearances, locations, possession or other manuscript evidence.
- An assignment has one target, either a chapter or a scene, or is absent.
Resolve the book from the target and verify it against the plotline's scope.
Store chapter ancestry for a scene through the existing relationship. Scope
assignment to one book even for a project-level plotline. Multiple threads can
share a target. Return a conflict on stale edits and keep explicit move and
unassign commands.
- Represent prerequisites as directed thread-to-thread edges. For the initial
contract, evaluate edges within one book planning scope, including across its
plotlines. Project-level threads entering that scope need explicit book
membership. Cross-book prerequisites need an approved reading-order model.
Reject self-edges, duplicates and cycles, including cycles among unassigned
threads. An archived prerequisite cannot satisfy an edge.
- A prerequisite is satisfied when it has a valid assignment strictly before
the dependent's proposed placement and its own prerequisites are satisfied.
This supports planning ahead in unwritten chapters. Written status, scene
evidence and checklist completion remain separately visible. A missing,
invalid or unordered prerequisite blocks addition and the response names the
prerequisite and reason.
- Use canonical manuscript chapter order, then scene order within a chapter.
Give threads sharing the exact target an explicit author-controlled order.
Two different scenes in the same chapter compare by scene order. A chapter
target spans its scenes, so a chapter target and a scene target within that
chapter have ambiguous relative order. Block that prerequisite arrangement
until the author uses comparable targets. Placement in an earlier chapter
precedes any placement in a later chapter.
- Validate the resulting graph and placements in one transaction, covering
assignment, reordering, unassignment, archival, edge edits, and chapter or
scene moves/deletions. If a change invalidates an assigned dependent, show
the affected threads and reject the change by default. Allow an explicit
atomic repair, such as moving both threads or unassigning the affected
dependents. Validate the final state of a batch so an earlier prerequisite
and its dependent can be planned together. Serialize conflicting changes to
order and dependency data and revalidate at write time.
- Manual planning and future MCP use the same scoped application service and
stored-procedure writes. Pickers and previews give the same eligibility
reasons. Apply existing project access checks to every operation, including
attachment reads. Review and authoring surfaces can read the same plan at
their selected scope using existing access rules. Keep editorial observations,
scene annotations and manuscript history distinct. Publish scoped invalidation
after successful writes so both surfaces can reload.
## Proposed migration and validation
1. Add new storage alongside the existing records. Preserve IDs, provenance,
timestamps, archive state, distinct milestone roles, event targets and
existing relationships. Keep direct links available to historical readers
and decide their editing lifecycle at cutover. Add a versioned backup and
restore contract for assignments, ordering, edges and thread-owned content.
Missing sections in older backups must never act as an instruction to clear
newer data. Update copy, portable import and scoped deletion with the same
ID remapping and access rules.
2. Produce a read-only inventory by thread with each raw association, origin,
book and archival state. Count zero links, single explicit links, recurring
links, cross-book or invalid references, milestone/event-only threads and
mixed-origin threads. Report existing notes/checklists/files by current
owner. Retain both raw records and a distinct-scene count so deduplication
in the display cannot hide conflicts.
3. Propose a candidate only where an active thread has one valid explicit link
and no conflicting legacy placement evidence. Keep threads with zero links
unassigned. Treat event-only and milestone-only threads as history pending
explicit planning choices. Stage recurring, cross-book and conflicting
cases for an owner decision with all source references visible. Supported
decisions should include keeping the thread unassigned, choosing one plan
target while retaining the full history, or explicitly splitting the plan
into related discrete threads with provenance. Never pick the first or last
scene, create copies automatically, parse the summary into separate notes,
move scene-owned content, or derive thread dependencies from scene edges.
4. Before any backfill, obtain owner approval of the mapping rules and the
treatment of ambiguous cases. Record a repeatable mapping keyed by source
identity, approved decision and destination. Qualify forward migrations in
an isolated restore with pre/post counts and per-ID reconciliation. Keep the
legacy path readable through cutover and verify it against the recorded
source before enabling new planning writes.
5. Cover same-target ordering, same-chapter mixed scope, unwritten
prerequisites, transitive blocking, cycles, concurrent edits, atomic repair,
and permission denials. Verify multiple threads per target, read sharing,
history retention, legacy and new backup round trips, and scoped cleanup.
Use fixtures with multiple events in one scene, recurring links across
scenes, conflicting milestones and archived/cross-book records.
Owner decisions for the implementation stage are the prerequisite and
mixed-scope ordering rules, legacy link editing at cutover, and approval of
the backfill mapping after the inventory. This audit proposes those rules
without applying a migration or selecting placements for existing records.