9.5 KiB
Package Cohesion And Architectural Boundaries Audit
Reviewed on 2026-11-24 at source revision
1c88483e1b778815f34c48ad711440d360031f6d.
Scope And Method
Reviewed all 18 production Go files across the six repository-owned production
packages, their exported types and functions, local imports, composition paths,
and representative boundary tests. The module root and internal/adapter have
tests but no production Go files. Third-party implementation packages were not
audited.
Used codebase-memory-mcp for package/symbol discovery and call tracing, then
checked actual source imports and go list output. Graph-derived edges can
confuse identically named functions or include test relationships; they were
not treated as authoritative production dependencies. Compared the allocation
with the architecture policy, ADRs
0002,
0004,
0005, and
0006, and the
current internal documentation.
The production package graph is acyclic and broadly coherent. One optional ownership refinement warrants consideration; no import-direction violation or major overlapping responsibility was found. This is not a proposal to add application layers or expand Scriptorium's product scope.
Current Responsibility Allocation
| Package | Implemented responsibility | Local production dependencies |
|---|---|---|
cmd/scriptorium |
Process streams, signal cancellation, version identity handoff, and exit status. | CLI adapter |
internal/adapter/cli |
Native command composition, input/configuration selection mapping, acquisition callbacks, engine construction, run/report effects, and HTTP server lifecycle. | HTTP adapter, config, defaults |
internal/adapter/http |
Routing, strict DTO decoding, request/result/error mapping, transport limits, and restricted artifact access. | Defaults, report |
internal/config |
Application schema, defaults, normalization and validation callbacks, discovery choices, and native shared loading/secrets bootstrap. | Defaults |
internal/defaults |
Small, shared set of application HTTP/server defaults. | None |
internal/report |
Terminal observation collection and the HTTP execution-report projection. | None |
External libraries retain their selected ownership: ConfigKit resolves the configuration document, PromptKit prepares and executes prompts, CommandKit and its integrations supply native operator workflows, and ReleaseKit supplies release mechanics/version identity. Local code composes those public APIs; there is no local framework or durable workflow layer. See the component overview and adapter internals.
1. Make HTTP Execution-Report Ownership Explicit
Category: Fragmented adapter responsibility / optional package-boundary simplification. Priority: Low; not a release blocker.
Relevant Implementation
- internal/report/report.go, lines 6–38,
defines
Execution,Usage, andTokenCount, including HTTP JSON member names and omission rules. Lines 47–104 select terminal events, convert durations to milliseconds, and bound the outcome/failure vocabulary. - internal/adapter/http/dto.go, lines
41–47 and 104–107, embeds
report.Executionin the success and error envelopes alongside the adapter's other private DTOs. Handler.ServeHTTP, lines 123–132 of handler.go, creates the per-request collector, attaches its observer, and obtains the report.writeRunFailure, lines 187–193, attaches that same representation to execution failures.- The HTTP adapter is the report package's only production consumer, confirmed
by the source imports,
go list, and inbound call tracing. CLI delivery.go instead sends the native RunResult to CommandKit; it does not use this representation.
Basis For The Finding
The report package is internally cohesive, and its dependency direction is
valid. The concern is narrower: a public HTTP representation and its shaping
policy are split between the HTTP adapter and a generically named sibling
package. The latter's Execution comment describes opt-in adapters generally,
while its current fields, vocabulary, consumers, and canonical contract are
specifically HTTP. HTTP report changes therefore cross a package API even
though no second interface needs that API.
This is not a finding that a single-consumer package is inherently wrong. It is an opportunity to align the ownership of this small, 104-line wire projection with the interface whose contract it implements. It confirms complexity audit finding 3, rather than identifying a separate runtime defect.
The tests reinforce the existing boundary and behavior to preserve:
TestCollectorProjectsOnlyTerminalAggregatesandTestCollectorHandlesUnknownValuesAndKeepsInvocationsSeparatein report_test.go exercise the projection, JSON shape, terminal-only selection, unknown values, and detached snapshots.TestCollectorReceivesRealEngineTerminalEventin the same file checks the observer integration with a real engine.TestHandlerExecutionReportOptInAndResultShapes,TestHandlerExecutionReportFailureAndAbsence,TestHandlerExecutionReportResponseLimit, andTestHandlerConcurrentExecutionReportsAreIsolatedin handler_test.go exercise opt-in attachment, error responses, encoded-size policy, and per-request isolation.
Potential Remediation And Tradeoffs
The preferred simplification, when this area is next changed, is to move the
collector, projection types, and focused tests into a dedicated execution-report
file pair in internal/adapter/http. Make implementation names private where
practical and remove the unused sibling package. Keep the HTTP wire format and
the existing observer lifecycle unchanged; retain focused projection tests
alongside handler integration tests. Update the component inventory and source
references if the layout changes.
This removes a package dependency and puts the complete HTTP representation under one owner. It adds code to an already substantial adapter package, but separate files and focused tests can preserve readability without requiring an exported cross-package API.
A viable alternative is to retain the isolated projection package and clarify its HTTP-specific purpose in its name/comments and component inventory. That preserves a small testable package with no HTTP transport dependency, at the cost of retaining the boundary and exported internal API. Keeping the current layout is also reasonable if that isolation is judged more useful than co-location. No new shared reporting framework, CLI report conversion, or speculative multi-consumer interface is justified by current usage.
Boundaries That Do Not Warrant Reallocation
- Configuration and CLI acquisition:
internal/configreturns the actual ConfigKit result and bootstrap report. CLIselection.gomaps operator choices to load options/overrides;bootstrap.goandoutcomes.gopresent evidence. Application definition callbacks remain in config, and native inspection remains upstream-owned. This is a coherent processing/presentation split, not fragmented effective-configuration ownership. - CLI and HTTP composition: CLI
server.goconstructs the restricted reader, one engine, handler, and listener forserve. HTTP owns request handling and artifact-access policy; it does not import CLI or config. CLI-to-HTTP wiring is application composition, not a transport dependency cycle. Moving this small lifecycle into a new service package or adding a reusable Scriptorium engine facade is not warranted. - Restricted artifact access: The file reader has filesystem mechanics, but its root/limit policy and error identities serve the HTTP deployment boundary. Its placement in the HTTP adapter is deliberate. Configuration path normalization and request-artifact path handling have different purposes; similar filesystem operations do not establish shared ownership.
- Defaults and adapter mappings: The defaults package is small and supplies application HTTP/server values to config and construction sites without importing either adapter. CLI outcomes and HTTP statuses, DTOs, and usage projections have different contracts. They do not need a common error or result model. The duplicated CLI diagnostic bridge recorded in 10-equivalence.md is a within-package helper opportunity, not evidence for another package.
Validation And Limits
go test -count=1 ./... passed, including TestApplicationBoundary, its import
scanner tests, and the collector/HTTP integration tests. The architecture guard
checks forbidden framework imports and removed implementation families; it does
not by itself prove that every responsibility has an appropriate owner.
This audit changes only this document. No new tests or production changes were made. Package imports, source locations, linked documents, and whitespace were checked. The assessment concerns current implemented responsibilities, not hypothetical future consumers or a guarantee that no other design opportunity exists.