132 lines
7.3 KiB
Markdown
132 lines
7.3 KiB
Markdown
# Dead Code And Obsolete Functionality Audit
|
||
|
||
Reviewed on 2026-11-24 at source revision
|
||
`a42fe635064124325a35bdf972c4fa65dcda7aff`.
|
||
|
||
## Scope And Method
|
||
|
||
Reviewed repository-owned Go declarations, command registration and callbacks,
|
||
configuration fields, optional HTTP/report paths, validation branches, and
|
||
retained migration-related checks. Also checked the release launcher/profile,
|
||
hosted workflow, and example scripts for disconnected entry points. No
|
||
production code, tests, or functionality were changed.
|
||
|
||
Used codebase-memory-mcp discovery/reference searches, source inspection, and
|
||
Go's package inventory. Cross-checked the earlier package review against the
|
||
unchanged production sources. Used `golang.org/x/tools/cmd/deadcode` v0.52.0,
|
||
matching the selected tools module version, to analyze the executable's call
|
||
graph for both release targets, Linux amd64 and arm64. Also analyzed the native
|
||
test executables. Results were filtered to Scriptorium-owned packages.
|
||
|
||
The inventory contains 18 production Go files in six packages, with no ignored
|
||
Go files or cgo files in the current package selections. Inspected tracked Go
|
||
files and build/directive searches for additional constrained or generated
|
||
entry points. JSON/YAML field use, native command/definition callbacks,
|
||
interface dispatch, and observer callbacks were accounted for rather than
|
||
classified solely by direct call counts.
|
||
|
||
One low-priority redundant branch warrants consideration. No abandoned
|
||
subsystem, obsolete compatibility implementation, or wholly unused function
|
||
was identified after accounting for tests and registered execution paths.
|
||
|
||
## Current Architecture
|
||
|
||
Scriptorium remains a thin executable: the process entrypoint delegates to the
|
||
CLI, which composes native commands and starts the HTTP service. Configuration
|
||
loading/schema callbacks, HTTP transport and restricted artifact access,
|
||
application defaults, and HTTP terminal-report projection have local owners.
|
||
ConfigKit, PromptKit, CommandKit and its integrations, and ReleaseKit own their
|
||
respective upstream mechanisms. See the
|
||
[component overview](../../internal/overview.md) and
|
||
[boundary audit](11-boundaries.md).
|
||
|
||
## 1. Consolidate Optional Model Mapping Into Its Nil-Aware Converter
|
||
|
||
**Priority:** Low; optional local cleanup, not a runtime defect.
|
||
|
||
**Implementation and evidence:** `Handler.ServeHTTP`, lines 104–107 of
|
||
[handler.go](../../../internal/adapter/http/handler.go), initializes a nil
|
||
model override and calls `executionTargetOverrideFromModelOverrideDTO` only
|
||
when `req.Model != nil`. That converter, lines 195–211 of the same file,
|
||
immediately handles nil input by returning nil. Reference inspection finds
|
||
only this one call site, with no direct test calls or registration of the
|
||
converter. Its nil-return branch is consequently unreachable through current
|
||
callers, and the two layers independently express the same omission handling.
|
||
|
||
**Potential remediation:** Call the nil-aware converter unconditionally and
|
||
use its result in `RunRequest.Execution`. This removes the redundant outer
|
||
branch and gives the existing converter's nil path a purpose. Preserve the
|
||
distinction between an omitted/null model (nil override) and an explicitly
|
||
supplied empty model object (non-nil override), along with all pointer-based
|
||
field presence and explicit-zero behavior.
|
||
|
||
An alternative is to retain the caller guard and remove the converter's nil
|
||
check. That also removes the unreachable branch, but makes the private helper
|
||
require non-nil input. The unconditional nil-aware conversion is simpler and
|
||
avoids introducing that extra precondition. This does not justify changing
|
||
validation, external request fields, or the upstream request model.
|
||
|
||
**Existing verification:** `TestHandlerModelOverrideMapsAllSupportedExecutionFields`,
|
||
`TestHandlerModelOverridePreservesReasoningEffortPresence`,
|
||
`TestHandlerModelOverrideExplicitZeroTemperatureMapsAsPresent`, and
|
||
`TestHandlerModelOverrideOmittedTemperatureMapsAsAbsent` in
|
||
[handler_test.go](../../../internal/adapter/http/handler_test.go) protect
|
||
supplied-model mapping and individual-field presence. A future cleanup should
|
||
also verify the whole-model omission/null/empty-object distinction; these
|
||
field-presence tests alone do not establish all three cases.
|
||
|
||
## Investigated Candidates That Should Be Retained
|
||
|
||
- **`NewHandler`:** Production-only deadcode analysis reports this constructor
|
||
at [handler.go](../../../internal/adapter/http/handler.go), lines 32–37, on
|
||
both release targets. The server uses `NewHandlerWithOptions` to receive
|
||
resolved configuration, while numerous HTTP tests and fixture builders use
|
||
`NewHandler` to select application defaults. It therefore has a concrete
|
||
test-support purpose, not an abandoned consumer API. Analysis including tests
|
||
reports no unreachable repository functions. Retain it; production-only
|
||
reachability is insufficient grounds for deletion.
|
||
- **Native callbacks and interfaces:** CLI parsers, command handlers, ConfigKit
|
||
definition callbacks, `Handler.ServeHTTP`, the restricted reader's `Read`,
|
||
and the report observer are live through registration or interface/function
|
||
values. Graph nodes with few or no direct edges are not deletion candidates.
|
||
- **Migration checks and aliases:** `validateDocument` rejects retired
|
||
framework selectors and raw API-key fields; it does not load the old formats.
|
||
`TestDocumentRejectsRetiredAndInvalidShapes` and
|
||
`TestNativeSettingsExtensionsAndRawKeyBoundary` in
|
||
[document_test.go](../../../internal/config/document_test.go) exercise those
|
||
checks. Current CLI aliases are documented supported spellings, not dormant
|
||
legacy dispatch. See the [CLI contract](../../cli.md) and
|
||
[migration guide](../../consumers/upgrading-cli.md). Removing either would
|
||
change selected behavior rather than delete unused compatibility machinery.
|
||
- **Optional and operational functionality:** Separate CLI report files, HTTP
|
||
terminal reports, explicit zero/unlimited limits, reader sentinels, and
|
||
cancellation/error fallbacks remain connected to supported paths. The report
|
||
package's sole production consumer does not make it dead; its potential
|
||
co-location is already covered by the boundary audit. Maintainer tool
|
||
dependencies, the root release launcher, hosted workflow, and prepared-preview
|
||
example scripts have non-runtime roles and are not obsolete merely because
|
||
the executable does not invoke them.
|
||
|
||
## Validation And Limits
|
||
|
||
Successful checks:
|
||
|
||
```bash
|
||
go run golang.org/x/tools/cmd/deadcode@v0.52.0 -filter='^gitea.maximumdirect.net/eric/scriptorium(/|$)' ./cmd/scriptorium
|
||
go run -exec 'env GOOS=linux GOARCH=arm64' golang.org/x/tools/cmd/deadcode@v0.52.0 -filter='^gitea.maximumdirect.net/eric/scriptorium(/|$)' ./cmd/scriptorium
|
||
go run golang.org/x/tools/cmd/deadcode@v0.52.0 -test -filter='^gitea.maximumdirect.net/eric/scriptorium(/|$)' ./...
|
||
go test -count=1 ./...
|
||
go vet ./...
|
||
```
|
||
|
||
The arm64 check ran the analyzer on the host with an arm64 package-loading
|
||
environment; it did not execute an arm64 application binary. Standalone
|
||
`staticcheck` and `golangci-lint` were not installed. Function reachability does
|
||
not prove individual branches or fields are necessary; those were assessed
|
||
through source, references, tests, and documented purposes. Uncovered defensive
|
||
branches were not presumed dead. No guarantee is made about every possible
|
||
input, custom build selection, or future upstream behavior.
|
||
|
||
Document links and whitespace were checked. No tool dependency was added to
|
||
the repository.
|