229 lines
13 KiB
Markdown
229 lines
13 KiB
Markdown
# PlotDirector Codex Guide
|
|
|
|
PlotDirector is an ASP.NET Core .NET 10 MVC/Razor application using Dapper and Microsoft.Data.SqlClient.
|
|
|
|
This file contains the rules and information needed on most development tasks. Detailed operational procedures are deliberately kept in separate documents. Read those only when the current task requires them.
|
|
|
|
## Repository
|
|
|
|
- Repository: `/srv/repos/PlotDirector`
|
|
- Solution: `PlotLine.slnx`
|
|
- Web application: `PlotLine/PlotLine.csproj`
|
|
- Regression harness: `PlotLine.Tests/PlotLine.Tests.csproj`
|
|
- Word add-in: `PlotDirector.WordCompanion/`
|
|
- Development service: `plotdirector-dev`
|
|
- Development site: `https://dev.plotdirector.com/`
|
|
- Development database: `PlotDirector_Development`
|
|
- Production is a separate host and database. Development work does not authorise production changes.
|
|
- `Tools/` and `tools/`, and `Docs/` and `docs/`, are distinct paths on Linux.
|
|
|
|
## Core Development Rules
|
|
|
|
- Use Dapper and stored procedures for application database access.
|
|
- Do not add inline SQL to application code.
|
|
- Do not introduce Entity Framework or EF migrations.
|
|
- SQL migrations are forward-only. Never modify an existing numbered migration to repair a live schema.
|
|
- PlotDirector must work for arbitrary books and authors. Never add production logic that recognises manuscript-specific names, places, vehicles, objects or relationships.
|
|
- Preserve existing user changes in a dirty worktree. Do not revert unrelated changes.
|
|
- Never expose or commit passwords, connection strings, API keys, SMTP credentials, Stripe secrets or OpenAI keys.
|
|
|
|
## Context And Discovery Discipline
|
|
|
|
Context is a finite resource. Repository discovery must be targeted, incremental and evidence-led.
|
|
|
|
Start from the implementation point most directly related to the requested change and trace dependencies outward only when evidence requires it.
|
|
|
|
Prefer:
|
|
|
|
- narrow `rg` searches within likely directories or files;
|
|
- specific symbols, methods, routes, stored procedures or view names;
|
|
- targeted line ranges instead of reading entire large files;
|
|
- one or a small number of directly relevant files at a time;
|
|
- existing focused documentation when it answers a question more cheaply than rediscovering the architecture from source;
|
|
- inspecting callers or dependencies only when relevant to the requested behaviour.
|
|
|
|
Avoid:
|
|
|
|
- broad repository-wide searches merely to build general context;
|
|
- searching application code, tests and all documentation trees simultaneously unless genuinely necessary;
|
|
- very large result limits such as hundreds or thousands of search matches;
|
|
- reading many large files in parallel;
|
|
- reading entire controllers, services, repositories or SQL files when only a method or section is relevant;
|
|
- speculative investigation of adjacent systems;
|
|
- repeatedly rereading material already available in the current context;
|
|
- loading detailed operational documentation unless the task actually needs it.
|
|
|
|
Do not attempt to understand the whole application before making a local change.
|
|
|
|
For broad tasks, identify the primary implementation path first. Expand discovery in stages and only where the previous stage demonstrates that more context is required.
|
|
|
|
Parallel tool calls are useful for latency but must not be used to load large amounts of speculative context simultaneously.
|
|
|
|
## UI Notifications
|
|
|
|
Use the shared `PlotDirector.toast` service for transient feedback. See `Docs/Codex/Notifications.md` for the API, partial-view usage, and messages that must remain inline. Do not introduce another notification library or page-specific toast host.
|
|
|
|
## Build And Test
|
|
|
|
Normal build gate:
|
|
|
|
dotnet build PlotLine.slnx
|
|
|
|
Full regression harness:
|
|
|
|
dotnet run --project PlotLine.Tests/PlotLine.Tests.csproj
|
|
|
|
`PlotLine.Tests` is an executable regression harness, not a conventional test SDK project. `dotnet test` is not the normal test gate.
|
|
|
|
Run build and tests serially. Parallel execution can cause static web asset cache locking.
|
|
|
|
Use verification proportionate to the change. Do not run unrelated specialist test suites merely for completeness.
|
|
|
|
Detailed specialist testing instructions are in `Docs/Codex/Testing.md`.
|
|
|
|
## Database Work
|
|
|
|
For tasks requiring database inspection, schema changes, migrations or direct development-database access, read `Docs/Codex/Database.md`.
|
|
|
|
Do not load that guide for tasks that do not require database work.
|
|
|
|
Essential rules that always apply:
|
|
|
|
- The development database is `PlotDirector_Development`.
|
|
- Never assume the database named in appsettings is the effective development database.
|
|
- Never restore, reset or overwrite the development database unless explicitly requested and the target has been verified.
|
|
- Do not modify database state during a read-only investigation.
|
|
- Do not apply SQL during a read-only audit.
|
|
|
|
## Deployment
|
|
|
|
For tasks that actually require deployment or detailed development-service operations, read `Docs/Codex/Deployment.md`.
|
|
|
|
Do not load deployment procedures during ordinary implementation or investigation unless deployment is part of the requested task.
|
|
|
|
## Story Intelligence
|
|
|
|
For Story Intelligence work, use the existing authoritative documentation:
|
|
|
|
- `docs/story-intelligence/single-system-runtime.md`
|
|
- `Docs/StoryIntelligence_ExceptionReview.md`
|
|
|
|
Read these only when the task concerns Story Intelligence or behaviour governed by those contracts.
|
|
|
|
Core invariant: manuscript-specific examples may be used in regression fixtures, but production behaviour must remain generic.
|
|
|
|
## Operational Safety
|
|
|
|
- Avoid destructive Git commands such as `git reset --hard` or `git checkout --` unless explicitly requested.
|
|
- Inspect the worktree before editing and preserve unrelated changes.
|
|
- Do not deploy while an import or Story Intelligence analysis is active unless interruption has explicitly been accepted.
|
|
- Production changes require explicit production authorisation.
|
|
- Prefer reversible, narrowly scoped actions.
|
|
|
|
## Public website separation
|
|
|
|
The independent public website source is `/srv/repos/PlotDirector.Website`, repository
|
|
`PlotDirector.Website`. Public editorial pages and the public Problem Solver are
|
|
maintained there. Do not duplicate website content edits in this application.
|
|
Internal PlotLine project/assembly/namespace identities remain unchanged.
|
|
Application Production origin is `https://app.plotdirector.com`; the owner-approved
|
|
cutover completed on 27 November 2026. Further Production changes require approval. Development remains `https://dev.plotdirector.com`.
|
|
See `Docs/Separation/Audit.md`, `Cutover.md` and `Acceptance.md` for measured status.
|
|
|
|
Application help remains authoritative in `PlotLine/Help/Articles`. Public help must
|
|
be explicitly exported via `Tools/PublicContent` using an approved URL allowlist and
|
|
exact source commit. Never publish internal/unreleased documentation by globbing.
|
|
The website consumes versioned artifacts; do not create independently maintained
|
|
article copies. See the website `Docs/Content.md` for publication/consumption commands.
|
|
Authentication uses the public brand in every display mode. Authenticated theme
|
|
preferences, Data Protection identity, uploads, SQL, subscriptions and users persist.
|
|
|
|
Help front matter must explicitly declare visibility: public, administrator or internal. Public publication includes only public. Administrator help requires the existing AdminOnly policy in the application. Generate separate public/application audience artifacts; never select an application artifact for the website. Missing classifications fail closed.
|
|
|
|
## CYJ development worker
|
|
|
|
This repository uses the **application** worker, CYJ resource **7** in PlotDirector
|
|
organisation 1. Run the shared toolkit from this repository, without changing its
|
|
development/branching/testing/deployment procedures:
|
|
|
|
```sh
|
|
/home/nick/cyj-planner/scripts/cyj-worker --worker application verify
|
|
/home/nick/cyj-planner/scripts/cyj-worker --worker application available
|
|
/home/nick/cyj-planner/scripts/cyj-worker --worker application waiting
|
|
/home/nick/cyj-planner/scripts/cyj-worker --worker application task TASK_ID
|
|
```
|
|
|
|
Read `/home/nick/cyj-planner/WORKERS.md` for the command reference, payloads and full
|
|
workflow; use command `--help` for exact arguments. The toolkit loads only
|
|
`~/.config/cyj/credentials/application.key` and verifies resource 7 before task
|
|
operations. Never use planner/other-worker credentials or display secrets/state files.
|
|
|
|
Execute only work assigned to resource 7. Retrieve the full brief before claiming;
|
|
claim only when ready. Review requirements against this file, then explicitly start
|
|
InProgress. Use exact task ETags and a distinct persisted key per logical write.
|
|
Renew the 15-minute claim every five minutes, before lengthy commands and on session
|
|
resumption; short-yield long-running tools so renewal remains possible. No background
|
|
heartbeat exists: if control cannot return before expiry, pause/split the work. Stop
|
|
at expiry, reconcile and reacquire when eligible; never blindly repeat external effects.
|
|
|
|
Report progress; request human assistance for genuine blockers, instruction conflicts
|
|
or unauthorised destructive actions. Record factual time and release while awaiting a
|
|
human. Read the response, explicitly evaluate it if required, recheck eligibility and
|
|
reclaim before resuming. Never bypass dependencies or release restrictions. Workers
|
|
cannot correct estimates through execution endpoints: propose corrections to the planner.
|
|
Do not independently edit deadlines, dependencies, assignments or resource calendars.
|
|
|
|
Implement and verify against the complete brief and existing repository gates. Record
|
|
commits, real test outcomes, artifacts/result links, limitations and actual time before
|
|
completion. Do not complete unfinished/unverified required work. Deployment requires
|
|
the task's explicit scope and the existing repository procedure; it is not automatic.
|
|
For uncertain writes use `retry ORIGINAL_KEY`, not a new key; reread/reconcile stale
|
|
ETags and expired claims using WORKERS.md. Do not create/claim tasks merely to test setup.
|
|
|
|
## CYJ automatic controller claim ownership
|
|
|
|
For automatic `application` executions launched by `cyj-controller.service`, the
|
|
controller acquires the claim and renews it every four minutes independently of
|
|
Codex. This overrides the manual claim/renewal/no-heartbeat instructions above for
|
|
controller-launched executions only. Do not acquire or renew a competing claim,
|
|
including through retry. Retrieve and review the complete brief and responses,
|
|
verify the inherited lease, then explicitly start InProgress. Complete or release
|
|
normally; exit after blocking assistance. Stop/reconcile on lost ownership.
|
|
Read `/home/nick/cyj-planner/CONTROLLER.md` for recovery, emergency stop and authority.
|
|
Manual sessions retain their existing claim maintenance responsibilities.
|
|
|
|
## Unattended Development acceptance
|
|
|
|
Development deployment is required before CYJ user acceptance readiness, except
|
|
where the brief explicitly defines a later acceptance milestone. After testing and
|
|
committing, follow `Docs/Codex/Deployment.md` and the shared toolkit's `DEPLOYMENT.md`.
|
|
In a controller execution use `deployment-request` / `deployment-result` for the
|
|
configured `application-development` target. Never bypass no_new_privs or expose
|
|
signing keys. Verify the deployed full commit, perform the brief's live acceptance
|
|
(including genuine database persistence/reload), then record receipt, tests, feature
|
|
URL and factual effort in CYJ before completion. Reconcile uncertain deployment
|
|
outcomes before retrying. Production remains separately authorised.
|
|
|
|
## Authenticated Development browser acceptance
|
|
|
|
Use `Docs/Codex/BrowserAcceptance.md` and `Tools/BrowserAcceptance/run.py` for the
|
|
permanent Application-only Development writer identity. Import the reusable
|
|
`PlotLine.Tests/Browser/dev-acceptance.cjs` helper; authenticate normally, create a
|
|
unique registered disposable project, test actual UI and server persistence after
|
|
reload/fresh login, then clean up via the ordinary scoped project lifecycle. Never
|
|
print credentials, record login traces/storageState, target Production or use SQL/
|
|
sudo for routine browser fixtures. Preserve pending run journals and use documented
|
|
resume cleanup on failure. Report deployed commit, URLs, actual checks, cleanup and
|
|
limitations in CYJ; task-specific acceptance must still be performed by its worker.
|
|
|
|
## Standing automatic Development authority (2 December 2026)
|
|
|
|
Routine Development .NET, stored procedure/function, schema and data migrations are
|
|
automatically authorised, including multiple corrective deployments in one controller
|
|
execution. Use the installed controller-mediated mechanism documented in
|
|
`Docs/Deployment/AutomaticDevelopment.md`. No individual operator SQL approval or new
|
|
worker execution is required. `failed_safe` results permit correction/new request;
|
|
uncertain live effects require reconciliation. Preserve applied hashes and migration
|
|
ordering. Functional owner acceptance remains separate. Production always needs
|
|
explicit owner approval and is unavailable through this Development path.
|