# Component audit

Every production module is covered by the groups below. This is an audit of meaningful avoidable work, not a claim that no future algorithm, workload or SDK could offer another improvement.

| Group and modules | Work removed or retained deliberately |
|---|---|
| Configuration: `goal-settings.ts`, `auditor-selector.ts` | Cache layered resolution by layer identity and the five applicable environment values; invalidate on settings writes and session refresh. Return independent resolved values/provenance. Keep fresh reads, fsync and locks for settings mutations. Selector/dialog work remains driven by user interaction. |
| Task data: `goal-task-index.ts`, `goal-task-count.ts`, `goal-task-derive.ts`, `goal-record.ts` | Replace JSON serialization on index hits with field comparisons against an owned snapshot; reuse indexes across copies and usage changes. Bound cache text and entry counts. Preserve validation, recursive records and objective-derived proposals. No extra pending array when only counts are requested. |
| Task mutations: `goal-task-tools.ts`, `goal-policy.ts`, `goal-service.ts` | One location index per private batch clone; apply ordered changes directly to that clone, including replaced subtrees. Copy only changed ancestors for ordinary tree updates. Remove redundant sorting of already ordered flat-task buckets and duplicate deep clones immediately before writers that already clone/sanitize. Keep whole-batch validation, original persisted revisions and mutation locks. |
| Goal persistence: `storage/goal-files.ts`, `storage/goal-lock.ts`, `goal-pool.ts` | One stat for existence/symlink checks, linear filename-set reconciliation, correct removal of timestamped active paths from snapshots, independently owned public pool Maps. Count open goals without sorting/copying them. Keep atomic renames, symlink protection, external refresh behavior and fresh mutation reads. |
| Ledger and activity: `goal-ledger.ts`, `goal-ledger-index.ts`, `goal-activity.ts` | Preserve incremental indexes and bounded normal reads; render only the requested indexed activity tail. Append owned events without an intermediate array or argument-count-sensitive spread. Version 3 checkpoints retain reconstructed Oracle results and reject damaged derived state. Authoritative ledger format stays compatible. |
| Model context and tools: `goal-detail.ts`, `prompts/goal-prompts.ts`, `goal-core-tools.ts`, `goal-tools.ts`, `goal-tool-names.ts`, `goal-contract.ts` | Reuse prompt fragments without serializing objectives/task trees into cache keys. Cache compiled lossless pages and cursor hashes; history uses an opaque ledger generation. Preserve applicable tool profiles, summary/default pagination, full retrieval, escaping, required policy and legacy calls. Existing escaping and input validation remain explicit. |
| Auditing and advice: `goal-auditor.ts`, `goal-completion.ts`, `goal-oracle.ts` | Consolidate auditor policy before dynamic data; preserve semantic approval criteria and read-only inspection. Stream previews scan only the last nonempty lines; retain complete final reports once. Existing isolated sessions share model runtime and budget accounting and dispose on completion. Oracle's explicit configuration, retries, advice schema and blocker ordering remain intact. |
| Lifecycle and events: `goal.ts`, `goal-state.ts`, `goal-events.ts`, `goal-runtime.ts`, `network-error-backoff.ts` | Parse checkpoint messages once; preserve all ordinary message identities/order and the latest marker's position. Replace sorted open-goal counts in hooks/UI. Keep microtask UI batching, event-driven continuation, bounded timers, error recovery, focus checks and pause controls. |
| Compaction and diagnostics: `goal-compaction.ts`, `goal-session-health.ts`, `goal-recovery.ts` | Bound oversized current-task text after compaction with an explicit full-retrieval pointer. Session health parses/discards one line at a time rather than retaining every parsed message. Keep explicit recovery scans, tolerant parsing, backups and repair checks. |
| Dashboard: `widgets/goal-dashboard-model.ts`, `widgets/goal-dashboard-renderer.ts`, `widgets/goal-widget.ts`, `widgets/auditor-dashboard-model.ts`, `goal-widget.ts` | Reuse task presentation and cached ANSI-aware wrapping/truncation. Continue deriving live usage, animation and viewport bounds from fresh state. Preserve terminal-height measurements: caching another component's rendered height could reintroduce scrollback loss. SDK already caches visible widths, so no duplicate width cache was added. |
| Dialogs and drafting: `goal-draft.ts`, `goal-drafting.ts`, `goal-questionnaire.ts`, `goal-task-confirmation.ts`, `widgets/task-list-overlay.ts`, `widgets/goal-escape-dialog.ts`, `widgets/dialog-scaffold.ts`, `widgets/goal-notifications.ts`, `widgets/text-cache.ts` | Share bounded caches for pure text transforms across dialogs, task previews and widgets. Keys contain complete ANSI text and all layout arguments; callers receive independent wrapped rows. Keep drafting's persisted state, question ordering and confirmation controls. |
| Commands and reporting: `goal-commands.ts`, `goal-status.ts`, `goal-format.ts`, `goal-core.ts`, `goal-accounting.ts` | Counts avoid sorting; reporting benefits from shared activity/index paths. Keep explicit verbose reports and complete archives. Token/time accounting and lifecycle predicates already operate on constant-sized state; adding caches would create more invalidation work than calculation. |

## Retained costs and limits

- A first explicit history page/diagnostic still reads or serializes history. Normal hooks/rendering use bounded indexes. Detail sources above the 16-million-character cache allowance remain losslessly available but are rebuilt for each page to avoid unbounded retained memory. Objectives and task plans are never truncated in storage.
- Task-cache validity deliberately examines task fields so edits in place cannot serve stale instructions. It scales with task count, not with repeatedly serialized contract length. Extremely large plans can exceed the cache allowance and use the uncached path.
- File writes retain durability, conflict checks and isolation copies where callbacks or callers can retain mutable records. User-driven listings retain chronological sorting when order is visible.
- UI caches hold at most 1,024 transforms / 500,000 content characters; task and prompt caches have entry and text bounds. These are content-size allowances, not exact process-heap limits.
- Runtime timing is local evidence, especially below a millisecond. The complete matrix, operation counts, repeated samples and real-SDK measurements accompany the headline improvements.
- The new live comparison covers auditor rejection and rework. Prior task execution/Sisyphus live results and their incomplete request-capped outcomes remain in the original campaign; this pass does not claim broad model equivalence or new Oracle live coverage.
