Skip to content

refactor: move errors/redaction/device into src/kernel — Phase 5 slice 3#940

Merged
thymikee merged 2 commits into
mainfrom
refactor/phase5-kernel-primitives
Jun 30, 2026
Merged

refactor: move errors/redaction/device into src/kernel — Phase 5 slice 3#940
thymikee merged 2 commits into
mainfrom
refactor/phase5-kernel-primitives

Conversation

@thymikee

Copy link
Copy Markdown
Member

What

Relocates the foundational primitive trio — errors.ts, redaction.ts, device.ts — from src/utils/ into the kernel/ layer (joining snapshot.ts from slice 2 / #932), per the target folder DAG in plans/perfect-shape.md §5.5.

A pure path codemod, no behavior change.

Why these three, atomically

They form a closed clusterdevice → errors → redaction, with redaction a leaf — so kernel/ takes no upward dependency, and every importer becomes a clean downward import toward kernel. errors.ts is the most-imported module in the tree (321 importers); device.ts is the §5.5-named headliner (144). Moving all three in one atomic move avoids a half-state where one would import another across the utils/kernel/ boundary.

How

Imports were rewritten by a resolve-based codemod: it compares each specifier's resolved absolute path to the moved files before rewriting, so unrelated same-named files (commands/management/device.ts, etc.) are left untouched. 481 import sites across 400 files. Intra-cluster imports (device → ./errors, errors → ./redaction) need no change — the three stay co-located in kernel/.

Also updated: two platform-descriptor doc comments, the fallow health-baseline key for device.ts, and the contracts-schema-public guard (asserting the error helpers pull no diagnostics/node: deps) now reads kernel/errors.ts.

Verification

  • tsc --noEmit exit 0; kernel/ files import only within kernel (no upward deps)
  • oxfmt + oxlint src --deny-warnings clean (no unrelated drift — every changed file's diff is an import rewrite)
  • rslib build exit 0
  • full vitest run → 2870 pass. The only failures were the known-flaky android-fill timing tests under full-suite CPU load (5s timeouts); they pass 92/92 in isolation, and a pure import-path move cannot affect fill logic.
  • fallow audit --base origin/main → ✓ no issues in 406 changed files
  • Layering Guard grep empty; no stale utils/{errors,redaction,device}.ts references anywhere (src, test, configs, baselines)

Note

Large but mechanical (the inherent cost of relocating the most-imported foundational modules) — best merged promptly to avoid import-drift conflicts. kernel/ now holds snapshot · errors · redaction · device; remaining kernel members (contracts.ts, and command-result/capabilities once their core/-descriptor coupling is broken) follow in later slices.

@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown

Size Report

Metric Base Current Diff
JS raw 1.4 MB 1.4 MB 0 B
JS gzip 453.3 kB 453.3 kB -14 B
npm tarball 558.5 kB 558.6 kB +21 B
npm unpacked 2.0 MB 2.0 MB 0 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 27.4 ms 27.5 ms +0.1 ms
CLI --help 48.2 ms 48.1 ms -0.2 ms

Top changed chunks:

Chunk Raw diff Gzip diff
dist/src/9722.js 0 B +3 B
dist/src/2577.js 0 B -2 B
dist/src/cli.js 0 B +2 B
dist/src/9919.js 0 B -2 B
dist/src/apps.js 0 B -2 B

@thymikee

Copy link
Copy Markdown
Member Author

I checked the path-move surface and the source imports look mechanically clean: the three files are 100% renames into src/kernel/, git diff --check is clean, there are no remaining source/test imports of src/utils/{device,errors,redaction}.ts, and src/kernel does not import upward.

One cleanup before merge: there are still current repo guidance/doc references to the old paths:

  • AGENTS.md still names src/utils/device.ts in the Apple-family sync rule and src/utils/errors.ts for normalizeError.
  • docs/adr/0009-apple-platform-consolidation.md still points resolveApplePlatformName at src/utils/device.ts.
  • plans/apple-platform-consolidation.md still labels DeviceInfo as src/utils/device.ts.

plans/perfect-shape.md also still has a historical utils/device.ts mention; that one may be intentionally describing the pre-move diagnosis, but the current guidance files above should move to src/kernel/device.ts / src/kernel/errors.ts so future agents do not follow stale paths.

@thymikee

Copy link
Copy Markdown
Member Author

Done — pushed c2c7d56. Updated the three current guidance files to point at the new src/kernel/ paths:

  • AGENTS.md: Apple-family sync rule → src/kernel/device.ts; normalizeErrorsrc/kernel/errors.ts
  • docs/adr/0009-apple-platform-consolidation.md: resolveApplePlatformNamesrc/kernel/device.ts
  • plans/apple-platform-consolidation.md: DeviceInfosrc/kernel/device.ts

Left plans/perfect-shape.md's utils/device.ts mention as-is per your note — it's in the §3 diagnosis describing the pre-move state (the §5.5 DAG already documents the kernel destination). Happy to update that too if you'd prefer it reflect the post-move reality.

@thymikee

Copy link
Copy Markdown
Member Author

Thanks, the stale-path cleanup from the prior review is addressed in c2c7d56. One remaining sequencing blocker: GitHub now reports this branch as DIRTY against current main, so it needs a rebase/conflict cleanup before it can be considered ready-for-human. I am leaving the ready label off until the branch is clean again.

thymikee added 2 commits June 29, 2026 20:56
Relocates the foundational primitive trio from src/utils/ into the kernel/ layer
(joining snapshot.ts from slice 2), per the target folder DAG in
plans/perfect-shape.md §5.5. A pure path codemod, no behavior change.

They form a closed cluster — device -> errors -> redaction, with redaction a
leaf — so kernel/ takes no upward dependency, and every importer becomes a clean
downward import toward kernel. errors.ts is the most-imported module in the
tree; device.ts the §5.5-named headliner. Moving all three atomically avoids a
half-state where one would import another across the utils/kernel boundary.

Imports rewritten by a resolve-based codemod (compares each specifier's resolved
path to the moved files, so the unrelated commands/management/device.ts and
other same-named files are untouched): 483 sites across 402 files. The two
platform-descriptor doc comments and the fallow health baseline key for
device.ts are updated to the new path; the contracts-schema-public guard that
asserts the error helpers pull no diagnostics/node: deps now reads kernel/.

Verified: tsc --noEmit, oxfmt + oxlint --deny-warnings, rslib build, full vitest
suite (2877 pass), fallow audit clean (411 changed files), Layering Guard empty;
kernel/ files import only within kernel.
…move

AGENTS.md (Apple-family sync rule + normalizeError), ADR-0009, and
plans/apple-platform-consolidation.md still named the old src/utils/ paths.
Point them at src/kernel/. plans/perfect-shape.md's utils/device.ts mention is
left as-is — it describes the pre-move diagnosis.
@thymikee thymikee force-pushed the refactor/phase5-kernel-primitives branch from c2c7d56 to e196be5 Compare June 29, 2026 18:56
@thymikee

Copy link
Copy Markdown
Member Author

Re-checked current clean head e196be5 after the rebase. The prior stale-path cleanup is present, the PR is now CLEAN, all 21 checks are green, git diff --check is clean, and the current merge diff remains the intended mechanical utils/{device,errors,redaction}kernel/ move plus import rewrites/doc path updates. I do not see remaining actionable blockers, so I am marking this ready-for-human.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Jun 29, 2026
@thymikee

Copy link
Copy Markdown
Member Author

Rebased onto current main and force-pushed (e196be5). Because main had advanced (#933 + #936 added new files importing the old utils/{errors,device} paths), I redid the move fresh on the new base so the resolve-based codemod picked up the new importers — 483 sites across 402 files. The branch is now MERGEABLE (no longer DIRTY). Re-verified on the new base: tsc 0, oxfmt+oxlint clean, rslib build 0, full vitest 2877 pass, fallow ✓ no issues in 411 changed files, Layering Guard empty, no stale utils/{device,errors,redaction} references (except the intentional perfect-shape.md diagnosis mention).

@thymikee thymikee merged commit 7a1640e into main Jun 30, 2026
21 checks passed
@thymikee thymikee deleted the refactor/phase5-kernel-primitives branch June 30, 2026 05:25
@github-actions

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-06-30 05:25 UTC

thymikee added a commit that referenced this pull request Jun 30, 2026
The kernel move (#940) deleted src/utils/device.ts; #941's
command-output-schemas.ts (merged after #940's codemod ran) still imported the
old path. Same one-line fix as #943; de-dups once that lands.
thymikee added a commit that referenced this pull request Jun 30, 2026
…943)

#941 (MCP outputSchema) and #940 (errors/redaction/device -> src/kernel) merged
in an order where #940's import codemod never saw #941's new
command-output-schemas.ts, so it still imports '../utils/device.ts' — which no
longer exists. tsc/build on main is red. Repoint the import at
'../kernel/device.ts'. The only stale reference on main.
thymikee added a commit that referenced this pull request Jun 30, 2026
…ase 4 (#942)

* feat: leveled response views + --level knob, with a snapshot digest — Phase 4

Add the agent-cost leveled-response system: a responseLevel knob
(digest | default | full) plumbed end to end behind a global --level flag
(mirroring --cost), and a per-command ResponseView registry applied in the
router on the success path.

- contracts: RESPONSE_LEVELS/ResponseLevel + meta.responseLevel + boundary
  schema whitelist. Plumbing mirrors --cost: cli-flags FlagDefinition +
  GLOBAL_FLAG_KEYS, AgentDeviceClientConfig + overrides, buildClientConfig,
  buildMeta. ResponseLevel exported from the public root.
- src/daemon/response-views.ts: the ResponseView registry. Seeds the snapshot
  digest — the full node tree (the dominant token sink) collapses to
  { nodeCount, refs: first 12 hittable/non-occluded refs with labels } plus the
  cheap top-level signals (truncated/visibility/snapshotQuality). full returns
  today's shape (nothing richer is computed yet).
- router graft (applyResponseLevelView + applyAgentCostGrafts): composes with
  the existing cost block. With responseLevel default (or unset) AND no
  registered view AND no --cost, the original response is returned UNCHANGED —
  byte-identical to today (Maestro .ad recompare safe). cost.nodeCount reads the
  original node tree so it stays accurate even after a digest.

Tests: snapshot view unit test (digest filters hittable/occluded, drops the
tree, keeps cheap signals; default/full passthrough); router graft test via an
injected view (default identity byte-identical, digest applies, full passthrough,
digest+cost composition, unregistered-command passthrough, boundary parse).

Verified: tsc, oxfmt + oxlint --deny-warnings, fallow audit clean, rslib build,
Layering Guard empty, 1106 daemon/contracts/client tests pass (incl. the
existing cost/typed-error grafts after the restructure).

* fix: repoint MCP output-schemas import to kernel/device (rebase fixup)

The kernel move (#940) deleted src/utils/device.ts; #941's
command-output-schemas.ts (merged after #940's codemod ran) still imported the
old path. Same one-line fix as #943; de-dups once that lands.

* fix: re-classify responseLevel flag in integration-progress model

The --level/responseLevel flag is a diagnostics/output flag (not device-
observable), classified in the exclusion bucket alongside --cost. (Lost in an
earlier rebase; re-applying.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant