Application Layer Refactor: Progress and Plan #
Status: Steps 1-4 complete (2026-10-03).
Companion docs: spec/architecture-refactoring-plan.md (original plan),
.spec/codebase-review.md (review; gitignored, kept locally).
Completed: Step 1 — Split application.odin into ownership-focused files #
Commit a8e7871. Pure move, no behavior changes; odin build green and all
153 tests pass before and after. The source of truth for chunking was a Python
script (/tmp/split_app.py) that parsed top-level declarations, verified
byte-exact reconstruction of the original file, and computed per-file imports
by tokenizing bodies (strings stripped, // comments per-line).
| File | Lines | Owns |
|---|---|---|
application.odin |
1612 -> 59 | Model, Render_State, init, LOADING_INTERVAL |
app_update.odin |
536 | update, process_terminal_input, recall, submission |
app_network.odin |
295 | network events, tool completion/progress, stream transitions |
app_render.odin |
249 | all rendering: prompt, replay, boundaries, progress |
app_compact.odin |
139 | compaction incl. COMPACT_SUMMARY_* prompts |
app_sessions.odin |
129 | session lifecycle, session picker, replay |
app_catalog.odin |
127 | model/variant catalog pickers + selection |
app_editor.odin |
78 | external editor lifecycle |
Notes and conventions:
- All files are
package maininsrc/; Odin compiles the package as a unit, so cross-file calls are free. This is the low-risk way to keep splitting. - Name collision avoided: pre-existing
app_picker.odin(picker UI glue) vs newapp_catalog.odin(model/variant pickers). Keepapp_picker.odinas-is for now; it is a candidate to absorb intoapp_catalog.odinlater. - Residual
application.odinimports were trimmed to what the residual uses (skills,session,input,picker,time). - The split preserved existing formatting drift: several files predate
current
odinfmtoutput (the originalapplication.odinwas already flagged unformatted before the split). Do not treat new-file formatting warnings as regressions.
Completed: Step 2 — Explicit request state #
Replaced the one-shot request flags in Model with Request_State: Prefix,
Editor, New_Session, Compact, Models, Sessions, or Variants, plus
Idle. The enum makes contradictory pending requests unrepresentable.
compacting remains a separate boolean for the in-flight compaction lifecycle:
the pending .Compact request is consumed before compaction starts. Picker
visibility and queued prompts remain separate state.
take_request_state consumes matching one-shot requests and returns the model
to Idle. A table-driven test covers prefix and slash-command transitions,
streaming/compacting gates, and one-shot consumption. odin test src passes all
158 tests. This step does not include effect-reducer work.
Completed: Step 3 — Stream split #
Stream now separates canonical sanitized assistant content in
Response_Accumulator from display bytes, ANSI/parser state, Markdown, terminal
geometry, and reasoning rendering state in Transcript_Render_State.
stream_response_content exposes only canonical assistant text; reasoning,
tool indicators, terminal errors, and spinner overlays remain display-only.
Session recording and tool-call context now consume canonical content in
chunks, so Session.Turn.assistant_offset and transcript-byte slicing are
removed. Tool-spinner capture reads transcript bytes without changing the
response accumulator; compaction summaries use canonical content as well.
Regression tests cover sanitization, reasoning, tool indicators, terminal
errors, tool rounds, compaction, spinner isolation, and overflow. odin test src passes all 161 tests, and odin build src succeeds.
In progress: Step 4 — Reducer producing effects (upgradable) #
Per spec/architecture-refactoring-plan.md item 2 and review item 6:
update becomes a pure-ish reducer emitting []Effect; a controller in
main.odin executes effects (catalog fetch, session save, editor open,
network start, tool execution) and sends completion messages back. This is
what makes catalog fetches and tool runs movable off the UI path without
redesigning state handling again.
Explicit Picker_Mode enum (None/Models/Sessions/Variants/Files) unifies
file autocomplete with the generic picker. This enum is now used by input state
for both file completion and the model/session/variant pickers.
update now returns effects for model, session, and variant picker catalogs;
session saves; opening the external editor; starting provider requests; tool
submission; new-session creation; session restore/replay; and compaction
preparation/finalization. The controller schedules catalogs on a worker and
sends tagged completions through the reducer. Session saves remain synchronous
so save-before-replace gates preserve their ordering, but failures return
through completion messages. Editor output, provider-start outcomes,
tool-scheduling failures, and loaded session records return through reducer
messages. The reducer applies session records; a follow-up effect synchronizes
config and paints replay. Tool execution remains on its existing worker.
New-session and compaction lifecycle helpers now run as controller effects.
Model and variant submissions produce owned selection effects; the controller
validates model-provider availability, applies the selection, writes user
config, and saves the session. Selection/config failures return through reducer
completion messages. The catalog worker keeps only the latest queued request,
while request IDs reject stale results from work already in progress. A loading
status is shown while a picker catalog is fetched. HTTP and SSE share a
reference-counted libcurl lifetime for concurrent catalog requests.
Compaction's save-and-rollback transaction deliberately remains one controller effect. Its synchronous save-before-replace sequence preserves the previous session on either save failure. Splitting it into reducer transitions would require the model to retain both old and candidate sessions across staged save completions, adding partial-commit states without improving the current correctness or effect boundary.
Reducer/effect, worker queue, ownership, error, and stale-completion tests pass
as part of the 179-test suite; odin build src succeeds.
Remaining: none for Step 4.
Also on the list (low-hanging, not architecture) #
scratchpad— completed: removed the tracked 452 KB Mach-O binary and added it to.gitignore; its local ignored copy is retained.assets/index.html— empty (0-byte), untracked, nothing links to it. Delete.- Formatting pass — several files drift from
odinfmt(mise pins OLSdev-2026-08). Runodinfmt -won flagged files, then re-run tests. Do this on a clean tree; ~357 changed lines across 16 files measured. .gitignore— replace enumerated experiment files (foo.md,models-values.md,invalid-event-stream.log,memoria.log,animation.md) with pattern-based entries (*.log), and delete the physical log files from the repo root.- Read-before-limit check (
reviewitem 4): config, session, and project instructions read the full file before enforcing size limits; migrate to a bounded reader (limit + 1bytes).