Skip to content

🤖 refactor: agent-loop tools read Runtime.location instead of instanceof - #7351

Merged
ThomasK33 merged 11 commits into
mainfrom
phase5/a-runtime-location
Oct 23, 2026
Merged

ThomasK33 merged 11 commits into
mainfrom
phase5/a-runtime-location

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Summary

5a PR 3 of phase 5 (Loop host I/O) of the agent-loop refactor. Agent-loop tools no longer use instanceof LocalBaseRuntime or instanceof RemoteRuntime. They read a new Runtime.location field instead. So tools/bash.ts, tools/skillFileHint.ts and tools/agent_skill_read_file.ts no longer import a runtime class, and their 3 frozen pairs of local/no-host-imports leave the allow map. On main (7265ac0) the map holds 22 pairs in 13 files. On this branch it holds 19 pairs in 11 files. Every runtime gives the same answer as instanceof did, so behavior does not change.

Order

The plan order of stack 5a is PR 1 to PR 14. This PR waited for phase 3 PR 8 (#7277, merged at 11:41 UTC), because bash.ts changed there. 5a PRs 5, 6 and 7 (#7319, #7329, #7338) merged before this PR. They change no source file of this PR. #7329 and #7338 removed neighboring allow-map lines, so merge commit d156ebc keeps the deletions of both sides. 5a PR 4 is stacked on this PR.

Implementation

  • runtime/Runtime.ts: optional readonly location?: "local" | "devcontainer" | "remote", and two helpers. isLocalBaseRuntime(runtime) is true for "local" and "devcontainer". isRemoteRuntime(runtime) is true for "remote".
  • LocalBaseRuntime.ts, DevcontainerRuntime.ts, RemoteRuntime.ts: location is a prototype getter. Subclasses and the Object.create(...prototype) doubles of tests inherit it. MultiProjectRuntime and plain object doubles leave it absent, and instanceof is false for them too.
  • tools/bash.ts:1041 and :1064, tools/skillFileHint.ts, tools/agent_skill_read_file.ts: the helpers in place of instanceof.
  • utils/ipAddress.ts: one more change (commit 4927205). The check of the impossible net.isIP answer now uses the shared assert helper instead of a hand-written throw, as the repo's assertion style asks. It changes no reachable path.
  • eslint.config.mjs, .oxlintrc.json and scripts/noHostImports.test.ts: the 3 pairs leave the allow map and the frozen list.

Validation

  • src/node/runtime/runtimeLocation.test.ts (new): a table of 12 runtime classes (the 8 runtime classes, MultiProjectRuntime and the 3 test doubles of tools/testHelpers.ts). For each class, isLocalBaseRuntime and isRemoteRuntime give the instanceof answers on an Object.create instance. A runtime without location takes neither branch.
  • bun test of the plan's list (src/node/runtime/, bash, skillFileHint, agent_skill_read_file) plus ipAddress.test.ts and scripts/noHostImports.test.ts: 760 pass, 0 fail.
  • make typecheck, make static-check, make lint-eslint.
  • make test (host suite lock), on head b2593a1 (main b3911c8 merged in, before the merge of the current main): 27765 pass, 7 skip, 0 fail, and every isolated file passes.
  • The ui line on that head: 732 pass, 0 fail.
  • Loop-test tripwire on that head, 3 runs against main: 0 trips.
  • After merging main (d156ebc): make typecheck, make static-check, make lint-eslint and the targeted list (760 pass) again. 5a PR 4 contains this tree, and its full gates ran on its final head.

Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high • Cost: $85.60

@ThomasK33
ThomasK33 added this pull request to stack #7353 October 23, 2026 14:19
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T14:22:10.070415Z d156ebc Manual request
🔒 Security Review ✅ Completed 2026-10-23T14:22:34.478166Z d156ebc Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: d156ebc9a4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: d156ebc9a4

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@github-actions

Copy link
Copy Markdown
Contributor

🟢 e2e stories (Haiku): 14 passed

27 agent steps · 7 replayed from cache · 29 model calls · 196.7k tokens (71% cached)
Spend: $0.09 of the $1.00 cap (proxy ledger)

All 14 tests in 9 files
Test Agent Time
🟢 chatRestart.e2e.ts · 1 passed 2 steps · 4 calls 24.0s
🟢 a chat survives a restart of the server 2 steps · 4 calls 24.0s
🟢 compaction.e2e.ts · 1 passed 3 steps · 6 calls 42.8s
🟢 /compact replaces the old chat with a summary 3 steps · 6 calls 42.8s
🟢 pluginTrustRestart.e2e.ts · 1 passed 4 steps · 2 calls 9.8s
🟢 a trusted plugin hook stays trusted after the server restarts 4 steps · 2 calls 9.8s
🟢 settingsRoundTrip.e2e.ts · 1 passed 3 steps · 4 calls 29.2s
🟢 a chat survives trips through Settings 3 steps · 4 calls 29.2s
🟢 sidebarPerWorkspace.e2e.ts · 1 passed 4 steps · 1 call 4.9s
🟢 a new workspace starts with its right sidebar collapsed while another keeps it open 4 steps · 1 call 4.9s
🟢 smoke.e2e.ts · 1 passed 2 steps · 1 call 3.8s
🟢 the agent opens the playground workspace 2 steps · 1 call 3.8s
🟢 streamErrors.e2e.ts · 1 passed 1 step · 1 call 8.0s
🟢 stream errors show in the chat, and the chat recovers 1 step · 1 call 8.0s
🟢 todoNudge.e2e.ts · 1 passed 2 steps · 4 calls 24.2s
🟢 the agent finishes open TODO items after the turn-end nudge 2 steps · 4 calls 24.2s
🟢 touchAlignment.e2e.ts · 6 passed 6 steps · 6 calls 29.7s
🟢 the Settings close button is level with the title on a touch screen 390px wide 1 step · 1 call 3.9s
🟢 the Settings close button is level with the title on a touch screen 768px wide 1 step · 1 call 5.9s
🟢 Backup settings checkboxes are small and level with their labels on a touch phone 1 step · 1 call 6.9s
🟢 the heartbeat checkbox is small and level with its label on a touch phone 1 step · 1 call 3.2s
🟢 a reply's model and time stay on one line on a touch phone 1 step · 1 call 3.1s
🟢 the workspace actions menu stays on the title row on a touch phone 1 step · 1 call 6.6s

e2e 0.20.0 · 3m 0s · web · run artifacts

🟢 e2e Electron stories (Haiku): 3 passed

3 agent steps · 3 model calls · 8.0k tokens (32% cached)
Spend: $0.01 of the $1.00 cap (proxy ledger)

All 3 tests in 3 files
Test Agent Time
🟢 electron/deepLink.e2e.ts · 1 passed 1 step · 1 call 7.1s
🟢 a deep link of a second launch starts a chat in the running app 1 step · 1 call 7.1s
🟢 electron/menuBar.e2e.ts · 1 passed 1 step · 1 call 13.2s
🟢 the workspace menu bar is the desktop title bar 1 step · 1 call 13.2s
🟢 electron/smoke.e2e.ts · 1 passed 1 step · 1 call 5.5s
🟢 Xum Electron opens the playground workspace 1 step · 1 call 5.5s

e2e 0.20.0 · 27.8s · electron · run artifacts

🟢 e2e agent repros (Haiku): no tests selected

Spend: $0.00 of the $1.00 cap (proxy ledger)

e2e 0.20.0 · 5.3s · 2 targets (web, phone) · run artifacts

@ThomasK33
ThomasK33 added this pull request to the merge queue Oct 23, 2026
Merged via the queue into main with commit 0856ca4 Oct 23, 2026
33 of 34 checks passed
@ThomasK33
ThomasK33 deleted the phase5/a-runtime-location branch October 23, 2026 15:40
azaj01 pushed a commit to azaj01/mux that referenced this pull request Oct 25, 2026
…ifications (coder#7352)

## Summary

5a PR 4 of phase 5 (Loop host I/O) of the agent-loop refactor. The
notify tool shows OS notifications through a new `DesktopNotifications`
service, not through its own `import("electron")`. So `tools/notify.ts`
loses its frozen `electron` pair of `local/no-host-imports`. The allow
map goes from 19 pairs in 11 files (5a PR 3) to 18 pairs in 10 files.
Outside Electron the tool returns the same result text as before.

## Order

This PR is stacked on 5a PR 3, as in the plan. It waited for phase 3 PR
8 (coder#7277, merged), because `ToolConfiguration` and
`turnRequestBuilder.ts` changed there. 5a PR 5 (coder#7319, merged) also
added tags to `StoreTags` in `di/tags.ts`. Merge commit f542862 joins
both tag lists. 5a PR 3 (coder#7351) merged at 15:40 UTC, so this PR now
targets main. Merge commit c525854 brings in main 0856ca4. It
keeps both imports and both layer entries in `di/layers/stores.ts`,
where phase 4 PR 4 (coder#7345) added `SessionLocksNode`. In the lint configs
it keeps main's lines and removes only the notify.ts pair.

## Implementation

- `desktopNotifications/desktopNotifications.ts`: the
`DesktopNotifications` interface with one method, `show({ title, body?,
workspaceId? })`, which resolves `{ success, error? }`.
- `desktopNotifications/electronDesktopNotifications.ts`: the Node
layer. `createElectronDesktopNotifications(host)` takes the Electron
check and the electron import, so tests can pass a fake electron module.
It holds the code that `notify.ts` had before (the `import("electron")`,
its eslint-disable and today's error text outside Electron). It is not
in `AGENT_LOOP_FILES`.
- `recordingDesktopNotifications.testHarness.ts`: a test layer that
records each request and returns a set result.
- `di/tags.ts`, `di/layers/stores.ts`, `di/layers/core.ts`:
`DesktopNotificationsTag` joins `StoreTags`, `StoresLive` gives the
Electron layer, and `AILive` passes it to `AIService`.
- `aiService.ts`, `turnRequestBuilder.ts`,
`common/utils/tools/tools.ts`: `AIService` takes optional loop host
services and `TurnRequestBuilder` puts `desktopNotifications` on each
`ToolConfiguration`. A config without it (tests that build one by hand)
uses the Electron layer.
- `tools/notify.ts`: calls `config.desktopNotifications.show(...)`, and
falls back to the browser notification as before when nothing shows.

## Validation

- `tools/notify.test.ts`: 2 new cases. The tool sends the trimmed title,
body and workspace ID to `config.desktopNotifications` and reports
`notifiedVia: "electron"`. When the service shows nothing, the tool
reports `notifiedVia: "browser"`.
- `electronDesktopNotifications.test.ts` (new): outside Electron the
result is today's text. In Electron (a fake electron host, commit
c27edf3), the layer cuts the title and body to the OS limits, shows
nothing on a platform without notifications, reports a failed import,
and on a click restores and focuses the first window and sends the
workspace ID. Quality / CRAP had flagged the moved function as new and
untested (CRAP 34). With these tests a local `crap-check` with coverage
no longer reports it.
- `bun test` of `notify`, `desktopNotifications/`, `turnRequestBuilder`
and `scripts/noHostImports.test.ts`: 50 pass, 0 fail.
- After merge commit c525854: `make static-check`, and the `notify`,
`desktopNotifications/`, `turnRequestBuilder`, `sessionLocks/`, `di/`
and `scripts/noHostImports.test.ts` tests (89 pass, 0 fail).
- `make typecheck`, `make static-check`, `make lint-eslint`. After
c27edf3: `make typecheck`, oxlint and eslint on the folder, and the
`notify` and `desktopNotifications/` tests (13 pass).
- `make test` (host suite lock) on head b882a24 (before c27edf3,
which changes only the Electron layer and its test): the `bun test src`
run had 27771 pass, 7 skip and 1 fail. The fail is the known flake
`BackgroundProcessManager > spawn > gives concurrent same-name spawns
from two backends distinct directories on a non-host runtime`. That file
alone then passed (163 pass, 0 fail). `make test` stops at the first
failing run, so I ran its other steps by hand: the shared
scripts/storybook/vscode run (729 pass, 0 fail) and each of the 18
isolated files (0 fail).
- The ui line on that head: 732 pass, 0 fail.
- Loop-test tripwire on that head, 3 runs against main: 0 trips.

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking:
`high` • Cost: `$85.60`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high
costs=85.60 -->
azaj01 pushed a commit to azaj01/mux that referenced this pull request Oct 25, 2026
…er#7360)

## Summary

5a PR 8 of phase 5 (Loop host I/O) of the agent-loop refactor. The
AGENTS.md tools (`xum_agents_*`), the config file helper of the config
tools and the repo-dir check of `bash.ts` make their host file calls
through `HostFiles` (5a PR 5, coder#7319). So 6 frozen pairs of
`local/no-host-imports` leave the allow map. The map goes from 18 pairs
in 10 files (5a PR 4) to 12 pairs in 5 files. Behavior does not change:
the Node layer calls the same `fs/promises` and `writeFileAtomic`
functions.

## Order

5a PR 3 (coder#7351) merged at 15:40 UTC and 5a PR 4 (coder#7352) at 17:05 UTC, so
this PR now targets main. The merge queue removed it once at 17:05 UTC:
`Test / Stories` failed because its Sonnet probe got HTTP 502 twice,
before any story ran. Merge commit 9c3218d brings in main 32b80b2.
Its only conflicts were the allow-map lines next to the notify.ts pair,
and it keeps this PR's removals. Plan order is PR 1 to PR 14, so this PR
keeps its place. It touches `bash.ts` and the allow-map lines next to
the lines that PRs 3 and 4 change, so it builds on them and does not
conflict with them.

## Implementation

- `tools/xum_agents_path.ts`, `tools/xum_agents_read.ts`,
`tools/xum_agents_write.ts`: `nodeHostFiles.promises` in place of the
`fs/promises` namespace import, as 5a PRs 6 and 7 did for the skill
tools.
- `tools/bash.ts:969`: `assertLocalRepoDirectoryExists` calls
`nodeHostFiles.promises.stat`. It was the only use of the `fs` import,
so the import goes.
- `tools/shared/configReadWrite.ts`: `readConfigDocumentUnvalidated` and
`writeConfigDocument` take a last `files: HostFiles` argument that
defaults to `nodeHostFiles`. The read, the `lstat` symlink check, the
`mkdir` and both atomic writes go through it. The callers
(`xum_config_read.ts`, `xum_config_write.ts`) do not change. The async
write passes `{ encoding: "utf-8" }` in place of the string `"utf-8"`,
because the `HostFiles` member takes only the options object.
`writeFileAtomic` resolves both forms to the same options.
- `eslint.config.mjs`, `.oxlintrc.json` and
`scripts/noHostImports.test.ts`: the 6 pairs leave the allow map and the
frozen list.

## Validation

- `tools/shared/configReadWrite.test.ts` (new): on the Node layer (a
temp dir) and on the memory layer (`createMemoryHost`), a missing file
reads as `{}`, a written `config.json` reads back with a new `writeId`,
a written `providers.jsonc` keeps its comment header and reads back, and
a write to a symlinked `config.json` throws and leaves the link's target
unchanged. 8 pass.
- `bun test` of the plan's list (`xum_agents`, `bash`,
`shared/configReadWrite`) plus `xum_config_read`, `xum_config_write` and
`scripts/noHostImports.test.ts`: 158 pass, 0 fail.
- `make static-check`, `make lint-eslint`.
- `make test` (host suite lock) on head 1ae3fe1 (before the merge of
5a PR 4): 27780 pass, 7 skip, 0 fail, then 729 pass, 0 fail, and each of
the 18 isolated files 0 fail.
- The ui line on that head: 732 pass, 0 fail.
- Loop-test tripwire on that head, 3 runs against main: 0 trips.
- After merge commit 9c3218d: `make static-check` and the targeted
list (158 pass, 0 fail). `git diff origin/main` of the three lint files
shows only the 6 pairs.
- After merge commit 7a1c206 (5a PR 4 at c525854, with main
0856ca4): `make static-check`, `make lint-eslint`, and the targeted
list plus `notify` and `desktopNotifications/` (171 pass, 0 fail). The
merge had one conflict: the `hostClock` import line of `bash.ts`, where
main added `nodeClock`. The merge keeps both imports.

---

_Generated with `xum` • Model: `anthropic:claude-opus-5-5` • Thinking:
`high` • Cost: `$90.60`_

<!-- mux-attribution: model=anthropic:claude-opus-5-5 thinking=high
costs=90.60 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant