Repository navigation
Description
Part of #1840.
Scope
One shared errorMessage helper in a new leaf module src/shared/ (small
pure helpers; errorMessage is its first). Every hand-written copy of
function errorMessage(error: unknown): string under src/ is deleted, the
CLI's included, and every inline
error instanceof Error ? error.message : String(error) in non-test src/
calls the helper. A repo test refuses a new copy. No behaviour change.
It does not split: the copy check refuses every copy left, so it lands with
the last conversion. It touches 21 src/ modules (the 19 with sites, http
for its copy, and the new shared), all with the same one-line edit.
A user notices nothing; if this goes wrong, an error's text changes somewhere
(a CLI line, a log line, an HTTP message).
Technical spec
Commit 200afe5.
Rows
- Behaviours: B1, B2, B3, B4, B5, B6
- Interfaces: I1, I2
- Existing code: X1, X2, X3, X4, X5, X6, X7, X8, X9, X10
Facts
| # | Fact | Source |
|---|---|---|
| F1 | src/shared/ does not exist. A directory under src/ with an index.ts is a component from its first commit, entered only through its index. |
.dependency-cruiser.mjs:1-12, .dependency-cruiser.mjs:34-43 |
| F2 | oxlint is 1.74, and its rule set has no no-restricted-syntax, so no lint rule can match the expression. The precedent for a source-wide ban is the time outside src/ports/ in src/lint-rules.test.ts: it lists git ls-files sources, drops a directory and the tests, and matches over blankSource(text, { strings: true }), which blanks comments and string text and keeps ${} code. |
package.json:113; strings oxlint.darwin-arm64.node of @oxlint/[email protected] | grep -oE 'no-restricted-[a-z]+' → exports, imports, jest, matchers, types, vi; src/lint-rules.test.ts:920-947; src/test-support/source-text.ts:6, src/test-support/source-text.ts:30-31 |
| F3 | pnpm lint runs oxlint and dependency-cruiser over src e2e ui packages, and pnpm check runs it with the tests. The unwraps outside non-test src/: src/leasing/lease-request-book.test.ts:168, src/gateway/relay-failures.test.ts:33, ui/src/state/screen.ts:171, ui/src/data/stream.ts:414, e2e/helpers/wait.ts:47, e2e/helpers/env.ts:76 (inside a private copy at e2e/helpers/env.ts:75), packages/e2e/src/errors.ts:25. packages/ never imports src/. |
package.json:66, package.json:73; grep -rnE of the unwrap pattern over src test files, ui, e2e, packages; .dependency-cruiser.mjs:104-111 |
| F4 | The dependency rules are proved in src/lint-rules.test.ts: one dependency-cruiser run over pathCases, each a list of fails/passes imports. |
src/lint-rules.test.ts:129, src/lint-rules.test.ts:285-300 |
| F5 | Every module under src/ needs a manual with a Does: line beside a CLAUDE.md holding only @AGENTS.md, linked from the architecture map; all manuals together fit in MANUALS_TOTAL_CHARACTERS (160,000; about 144,000 used). |
src/docs-manuals.repo.test.ts:11, src/docs-manuals.repo.test.ts:117-129, src/docs-manuals.repo.test.ts:165, src/docs-manuals.repo.test.ts:214; docs/internal/ARCHITECTURE.md:35-74 |
| F6 | agent-identity imports nothing and has no rule of its own; its helper is a plain exported function, and its unit test is the model for the new one. |
src/agent-identity/AGENTS.md:7; src/agent-identity/index.test.ts |
| F7 | Nothing here touches src/contract/, so .agents/scripts/protocol-bump-check.mjs and its NOT_SHAPES are unaffected. |
protocol-bump-check.mjs counts only src/contract/*.ts |
Modules touched
Home: shared, new — src/shared/index.ts, src/shared/error-message.ts
and its unit test, AGENTS.md and CLAUDE.md. The manual holds the
admission rule:
- Does: small pure helpers two or more components use.
- A helper goes in only if it is pure (no I/O, no clock, no state), imports
nothing (no component, package or Node module; dependency rule
shared-imports-nothing), and is used by two or more components. Anything
else lives in the module that owns it. errorMessageis the one error-message unwrap; the copy check in
src/lint-rules.test.tsrefuses another.
Sites (X1, X2, X4): core, drivers, gateway, daemon, agent-device,
ports, leasing, simlock-client, tunnel, stream, lease-files,
history, cli, updater, state, modules, mcp, host-load,
fseventsd, plus http (a copy and its importer only).
Rules and docs: .dependency-cruiser.mjs (I2, X10), src/lint-rules.test.ts
(B2, B3, B4), docs/internal/ARCHITECTURE.md (a module row, a dependency
row, X7's and X10's rows), X7's manuals, and
docs/internal/agent-rules/architecture.md rule 18 with
docs/internal/agent-rules/always-in-scope.md item 9 (X9).
Untouched: ui/, e2e/, packages/ and test files (F3).
Searches: the unwrap grep of #1840's Existing code, its whitespace-tolerant
twin and the function errorMessage grep for the sites; an import scan of
errorMessage for X4; .dependency-cruiser.mjs and .oxlintrc.json for
every rule naming a site module (X5, X6); the manuals of every site module
and docs/internal/ for claims about what a module imports (X7).
Rules in play
- architecture rule 10 — "A rule is enforced in exactly one place": one
unwrap in place of ten definitions and 95 inline copies, and the copy
check keeps it one.ui/,e2e/andpackages/keep theirs (F3). - architecture rules 4 and 14 —
sharedis a component with an explicit
surface, itsindex.ts. It imports nothing, so it sits in no cycle. - architecture rule 15 —
shareddepends on nothing, so any module may
depend on it, optional or required. - architecture rule 9 — a pure function needs no port; the manual's
admission rule keeps I/O out. - architecture rule 18 — this task amends it (X9): a module that imports
nothing and that no host wires exports its pure functions directly, as
sharedandagent-identity(F6) do. - architecture rule 13 — X7's manual lines and rule comments are fixed in
the same change. - architecture rule 17 — any comment added to
.dependency-cruiser.mjsor
the test starts withwhy:. - ADR 0027 — the new rule lives in
.dependency-cruiser.mjs, and
src/lint-rules.test.tsproves each new or changed rule fires (F4). - documentation rule 7 — the new manual opens with
Does:, sits beside a
CLAUDE.mdthat holds@AGENTS.md, and fits the manuals' budget (F5). - ADR 0077 §3 —
packages/never importssrc/, so
packages/e2e/src/errors.tskeeps its unwrap (F3).
Tests
Seam: src/lint-rules.test.ts — its pathCases (F4) and
the time outside src/ports/ (F2) as models; the helper's own test is
modelled on src/agent-identity/index.test.ts.
- B1:
errorMessageof anError, aSimlockError, a string, a number and
undefined. - B2: a file in
src/shared/importing../core/index.js,zod(unbuilt)
andnode:pathfails; one importing./y.jspasses. - B3:
src/cli/errors.tsimporting../shared/index.jsand
../agent-identity/index.jspasses,../ports/index.jsfails; a file in
src/updater/and one insrc/modules/importing../shared/index.js
pass. - B4: the copy check over every
git ls-filessource undersrc/but
src/shared/and*.test.ts(x); a sample proves it counts a one-line
unwrap, one split over lines, one inside${}, and not one in a comment
or a string. - B5:
src/cli/lazy-loading.test.tspasses unchanged, and the suite under
pnpm checkpasses. - B6:
src/docs-manuals.repo.test.tspasses with the new manual; rule 18,
X7's and X10's lines read true.
Done when
src/shared/exists with anindex.tsexportingerrorMessage, an
AGENTS.mdholding the admission rule of Modules touched, and a
CLAUDE.mdholding@AGENTS.md;docs/internal/ARCHITECTURE.md's module
table has asharedrow linking that manual, and its dependency table has
ashared-imports-nothingrow..dependency-cruiser.mjshasshared-imports-nothingand
shared-imports-nothing-unresolved, and
cli-router-imports-no-component-values,updater-imports-littleand
modules-imports-littleallowsrc/shared/, and they and
host-load-imports-ports-onlysay so in their comments.- Architecture rule 18 states the exception for a module that imports
nothing and that no host wires, and always-in-scope item 9 agrees with
it. git grep -nE 'instanceof Error \? [A-Za-z_.]+\.message : String\(' -- 'src/*.ts' ':!*.test.ts'
prints exactly one line, insrc/shared/, and
git grep -n 'function errorMessage' -- 'src/*.ts'prints exactly one
line, insrc/shared/. The two test-file unwraps of F3 remain.src/mcp/connect.tscalls the shared helper and has noisSimlockError
fast path of its own.- X7's and X10's manual lines, map rows and rule comments are true of the
new imports. src/lint-rules.test.tsholds the cases and the copy check of Tests, and
src/cli/lazy-loading.test.tspasses unchanged.pnpm checkpasses.
Out of scope
ui/, e2e/, packages/ and test files (*.test.ts) keep their unwraps
and are outside the copy check (F3). No other helper moves into
src/shared/. The .catch(() => undefined) idiom is not this helper's
business.
Depends on
Written by an agent.
Activity
V3RON commentedon Nov 24, 2026
Maintainer decision (2026-11-24)
Deliver it: one
errorMessagehelper insrc/ports, the copies removed, and a lint rule. No behaviour change. Next: spec check, thentask:ready.Written by an agent.
V3RON commentedon Nov 25, 2026
Body moved to today's task template as part of #1840. The design facts now sit in #1840's rows. Changes from the design check: the
shared-imports-nothingrule has its owntoand refuses packages and Node built-ins (the contract's rule lets them through). Architecture rule 18 gains an exception for a module that imports nothing and that no host wires (maintainer decision, 2026-11-25). The host-load rule comment and map row are fixed too. The body before this edit is kept in the issue's edit history.Written by an agent.
test: no copy of the error-message unwrap outside src/shared (#1442)
refactor(shared): every error-message unwrap calls the shared errorMe…
test: the copy check counts a dotted unwrap (#1442)
docs: manuals that say a module imports only ports or nothing name sh…
refactor(shared): one errorMessage helper in a new shared module (cal…