Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
8b99a13
tools: red tests for the default model's words, the URL and "(your pa…
jonathan308 Nov 8, 2026
112bf1f
tools: say what happened to your default model, name the URL and "(yo…
jonathan308 Nov 8, 2026
b5cbb93
docs: the tools' default-model lines, the URL a start names, "(your p…
jonathan308 Nov 8, 2026
222c66f
tools: pin that a pair's models are served here in all but their name
jonathan308 Nov 8, 2026
e124080
Merge #1904's head (6f0e0e9130: its refactor pass) into fix/tools-def…
jonathan308 Nov 8, 2026
7b40562
Merge #1904's head (103e4cd0cd: dev 8d545e85a8, #1893, #1897, #1890) …
jonathan308 Nov 8, 2026
94fc79f
tools: OpenCode's config order in one place, from its source; the inv…
jonathan308 Nov 8, 2026
d7af782
tools: say "served here" by name, not by the tools' order
jonathan308 Nov 8, 2026
3b09e1c
Merge #1904's head (10093d776c: its review fixes, dev c76445a61e) int…
jonathan308 Nov 8, 2026
a0e0dad
Merge #1904's head (2a9158e875: dev 344fd29b3e, #1908, #1902, #1903) …
jonathan308 Nov 8, 2026
af948d7
Merge origin/dev (efb61cc2f1: #1914, #1912, #1910, #1916) into fix/to…
jonathan308 Nov 9, 2026
cc00019
tools: red tests for #1911's review: OpenCode's remembered pick, a me…
jonathan308 Nov 9, 2026
b46587e
tools: leave OpenCode's remembered pick alone, name a member's relay …
jonathan308 Nov 9, 2026
ebfff8a
docs: OpenCode's remembered pick, the way back from Darkbloom's defau…
jonathan308 Nov 9, 2026
ca8a57b
Merge origin/dev (5347bc3b81: #1894) into fix/tools-default-model-and…
jonathan308 Nov 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog.d/tools-say-the-default-and-the-pair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### `darkbloom --opencode` and `--hermes` say what happened to your default model, and where the models run

- OpenCode: Darkbloom's model becomes OpenCode's default only when OpenCode has none: neither of its global config files sets one (`opencode.json`, `opencode.jsonc`; OpenCode 2 doesn't read OpenCode 1's `config.json`), and its TUI remembers no model you picked with `/models` (`~/.local/state/opencode/model.json`). Its own line says so, and how to go back for good: ``New OpenCode sessions now use Darkbloom's Qwen 3.8 27B. To go back, remove "model" from ~/.config/opencode/opencode.jsonc or run the Undo below.`` When a file sets one, nothing is written for it, and the line names it: ``Your default stays exo/llama-3.3-70b; pick Darkbloom with /models.`` When OpenCode remembers a pick: ``Pick Darkbloom once with /models; OpenCode remembers it.`` The `Undo:` line stays.
- Hermes: Darkbloom still becomes the main model, and the line names the one it replaced: ``New Hermes chats now use Darkbloom's Qwen 3.8 27B (before: gpt-6-astra via opencodex). Switch back: hermes model``. Its headline matches OpenCode's (``✓ Hermes can use Darkbloom: 1 model.``).
- A start with a tool flag beside a local API that already serves names the URL the tools use, not the address it listens on: ``Darkbloom already serves at http://127.0.0.1:8001/v1; setting up OpenCode for it.`` (it said `0.0.0.0:8001` for a pair's).
- On a Mac whose local API is its pair's (the leading Mac's, or a member's relay), the tools name the pair's models ``Qwen 3.8 27B (your pair)``, not `(this Mac)`, for a pair of any size; a run again changes nothing. Hermes makes the pair's model its main one, as it does this Mac's, and a pair's models take their engine's word on image input and reasoning, as this Mac's do.
77 changes: 57 additions & 20 deletions docs/architecture/tool-integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ flowchart LR
(`provider-swift/Sources/ProviderCore/Server/LocalEndpoint.swift`): the file that holds exactly the key the
discovery record names for that port. That is this Mac's own `local_token` whatever serves here: a pair's API
takes it beside the pair's key, and on a pair's other Macs the relay's record names it too (it passes requests on
with the pair's key). Only a pair API an older build started names `cluster_local_token`.
with the pair's key). Only a pair API an older build started names `cluster_local_token`. The endpoint serves the
pair (`servesThePair`) when `local.json`'s pid is one of this Mac's running pair's processes
(`ClusterPairSummary.runningPairProcesses()`): its part's, as `status` decides whose API it is, or, while the part
runs, the cluster service's own, whose relays answer a member's local API for the pair (`ClusterService.relayTick`,
and `relayDiscovery` for Both, write `local.json` with the service's pid).
2. **Models.** `IntegrationModels.fetch` asks the endpoint's `GET /v1/models` with that key; `resolve` names each
chat model from the catalog (`display_name`, with where it runs: this Mac, your Macs, the network), takes its
chat model from the catalog (`display_name`, with where it runs: this Mac, or your pair when the endpoint serves
it, whatever its size; your Macs; the network), takes its
context from the endpoint, else the catalog's maximum, its output cap as `min(max output, context / 4)` with
`defaultOutputCap = 32_768`, and its capabilities from the catalog's names (tools on and text-only input when the
catalog is unreachable). Image input for a model served here (this Mac, or the pair it leads or relays to) is its
Expand Down Expand Up @@ -93,20 +98,29 @@ flowchart LR
`providers.<id>` value, or appends it in the file's indentation and trailing-comma style. The block has the base
URL, `apiKey: "{file:<key file>}"` (under `~` in the home directory), `compatibility.maxTokensField: "max_tokens"`
(OpenCode otherwise sends `max_completion_tokens`, which the engine ignores) and each model's name, `limit` and
`capabilities`. The top-level `model` is set only when no global config file sets one
(`OpenCodeConfigPlan.otherGlobalConfigSetsModel`): OpenCode loads `opencode.json`, then `opencode.jsonc`, and
Darkbloom edits the last that exists, so a `model` added to `.jsonc` would override the owner's in `.json`.
Project, system and managed configs load after the global ones and win over them, so a global `model` never
replaces theirs.
`capabilities`. The top-level `model` is set only when OpenCode has no default: no global config file sets one,
and its TUI remembers no model picked with `/models` (`OpenCodeConfigPlan.rememberedPick`). So Darkbloom never
sets a default over the owner's: Darkbloom edits the global file OpenCode loads last, where a `model` would win
over the other one's, and at every launch over the remembered pick ([OpenCode's config order](#opencodes-config-order)).
The edited file's own `model` wins over the other file's (`OpenCodeConfigPlan.otherGlobalDefault`, merged by
`GlobalDefault.merged`): a name stays and is named (`ToolConfigSummary.keptDefault`); `""`, `null`, two `model`
keys or a file that can't be read stays without a name. A remembered pick stays too
(`ToolConfigSummary.rememberedPick`), and the start says to pick Darkbloom once with `/models`. When Darkbloom
sets `model`, the start says how to go back for good: remove `model`, or run the undo (`/models` lasts only until
OpenCode quits).
4. **Hermes.** `HermesConfigPlan.plan` splices two top-level sections of `config.yaml` by lines: `providers.<id>`
(`api`, `key_cmd: "/bin/cat <key file>"`, `transport`, `default_model`, `extra_body.max_tokens` and each model's
`context_length` / `supports_vision`) and `model` (`provider: "custom:<id>"` and `default`; the previous endpoint's
pins, `previousEndpointKeys`, go). Models under `minimumContext = 64_000`, Hermes' own floor, are left out;
`extra_body.max_tokens` is the smallest output cap of the rest. Lists at their key's own indent, as PyYAML writes
them (so oMLX's `omlx launch hermes`, and Hermes up to v0.17), are part of that key. The block says nothing of
reasoning, which Hermes doesn't read there ([Hermes versions and limits](#hermes-versions-and-limits)).
them (so oMLX's `omlx launch hermes`, and Hermes up to v0.17), are part of that key. The main model is the one
already set when it is Darkbloom's and still usable, else the nearest usable one that isn't on the network (this
Mac or its pair, then your Macs); the one it replaces is named with its provider
(`ToolConfigSummary.replacedDefault`, `gpt-6-astra via opencodex`). The block says nothing of reasoning, which
Hermes doesn't read there ([Hermes versions and limits](#hermes-versions-and-limits)).
5. **Write.** `ToolConfigWriter.apply` makes the planned edit (invariants below) and returns the file, the backup
and the exact undo command.
and the exact undo command. `ToolIntegrationStep.lines` says them, with the default model on a line of its own
(`openCodeDefault`; Hermes' names the main model before).
6. **Follow the address.** A start without a tool flag that serves a local API reads each tool's provider block back
(`OpenCodeConfigPlan.pointer`, `HermesConfigPlan.pointer`: the base URL, and the file `{file:}` or
`key_cmd: /bin/cat <file>` reads) and compares it with that API: its base URL and `LocalEndpoint.tokenPath()`, or
Expand All @@ -117,29 +131,51 @@ flowchart LR
(`Local.localHostName()`, with `.local`) for an API on every address (`ToolAddress.thisMacsNames`). Single-Mac
only: a paired Mac's start starts the pair and doesn't compare.

### OpenCode's config order

What Darkbloom relies on about the order OpenCode 2 reads its configs in, from its source at release `v2.2.6`
([`dc2ffcf8bf`](https://github.com/anomalyco/opencode/tree/dc2ffcf8bf26f9e669b6aa22b95f50e12be15e06)). The code
keeps it in one place too: `OpenCodeConfigPlan.globalFileNames`.

| OpenCode 2 | Its source | Darkbloom |
|---|---|---|
| Loads `opencode.json`, then `opencode.jsonc`, from its global folder, and not OpenCode 1's `config.json` | [`discovery.ts`](https://github.com/anomalyco/opencode/blob/dc2ffcf8bf26f9e669b6aa22b95f50e12be15e06/packages/core/src/config/discovery.ts) (`names`), [`config.ts`](https://github.com/anomalyco/opencode/blob/dc2ffcf8bf26f9e669b6aa22b95f50e12be15e06/packages/core/src/config.ts) (`loadDirectory`); test "does not load legacy config.json files" in [`config.test.ts`](https://github.com/anomalyco/opencode/blob/dc2ffcf8bf26f9e669b6aa22b95f50e12be15e06/packages/core/test/config/config.test.ts) | `globalFileNames` |
| The default model is the `model` of the last config loaded that sets one | [`provider.ts`](https://github.com/anomalyco/opencode/blob/dc2ffcf8bf26f9e669b6aa22b95f50e12be15e06/packages/core/src/config/plugin/provider.ts) (`Config.latest(loaded.entries, "model")`) | `GlobalDefault.merged` |
| Saves to the last of the two files that exists, else to a new `opencode.jsonc` | [`config.ts`](https://github.com/anomalyco/opencode/blob/dc2ffcf8bf26f9e669b6aa22b95f50e12be15e06/packages/core/src/config.ts) (`update`) | `configFile` edits the same file: the global one loaded last |
| Loads remote (`.well-known/opencode`) and integration configs before the global files, and `OPENCODE_CONFIG`'s file, a project's `opencode.json`, `opencode.jsonc` and `.opencode` folder, `OPENCODE_CONFIG_CONTENT` and the managed files after them | [`config.ts`](https://github.com/anomalyco/opencode/blob/dc2ffcf8bf26f9e669b6aa22b95f50e12be15e06/packages/core/src/config.ts) (`load`) | Reads only the global files: a `model` loaded after them wins over Darkbloom's too, and Darkbloom's wins over a remote or integration one |
| A new TUI session starts on `--model`, else the config's `model`, else the first valid model you picked with `/models` (`recent`, which `/models` adds to and OpenCode keeps in `model.json` in its state folder, `$XDG_STATE_HOME/opencode`, else `~/.local/state/opencode`), else the first model listed | [`local.tsx`](https://github.com/anomalyco/opencode/blob/dc2ffcf8bf26f9e669b6aa22b95f50e12be15e06/packages/tui/src/context/local.tsx) (`fallbackModel`; `path.join(paths.state, "model.json")`), [`model-preference.ts`](https://github.com/anomalyco/opencode/blob/dc2ffcf8bf26f9e669b6aa22b95f50e12be15e06/packages/tui/src/model-preference.ts) (`addRecent`, `decodeModelPreference`), [`dialog-model.tsx`](https://github.com/anomalyco/opencode/blob/dc2ffcf8bf26f9e669b6aa22b95f50e12be15e06/packages/tui/src/component/dialog-model.tsx), [`global-roots.ts`](https://github.com/anomalyco/opencode/blob/dc2ffcf8bf26f9e669b6aa22b95f50e12be15e06/packages/util/src/global-roots.ts); test "uses the last configured model and variant ahead of recents" in [`local-selection.test.tsx`](https://github.com/anomalyco/opencode/blob/dc2ffcf8bf26f9e669b6aa22b95f50e12be15e06/packages/tui/test/context/local-selection.test.tsx) | `rememberedPick` reads that file: a pick there stays the default, and no `model` is written over it |
| With `OPENCODE_CONFIG_DIR` set, reads that folder as its global one | [`global.ts`](https://github.com/anomalyco/opencode/blob/dc2ffcf8bf26f9e669b6aa22b95f50e12be15e06/packages/util/src/global.ts) | Not followed: `configFile` reads `$XDG_CONFIG_HOME/opencode`, else `~/.config/opencode` |

## Invariants

1. No tool file holds the key: the planners take a key file's path, never a key; OpenCode's `{file:}` and Hermes'
`key_cmd` read it at request time (`OpenCodeConfigPlan.keyReference`, `HermesConfigPlan.plan`).
2. Bytes outside the owned value or lines are unchanged: other providers, a V1 `provider` map, the owner's default
model in OpenCode, every other Hermes section and the owner's comments. Comments inside a replaced value or on a
replaced line are counted (`ToolConfigSummary.droppedComments`); the backup keeps them.
3. The `darkbloom` block is Darkbloom's whole: a run that changes it rewrites all of it, so a key the owner added
3. OpenCode's default is never set over one the owner set in a global file or by a `/models` pick OpenCode remembers:
`model` is written only when there is neither (`OpenCodeConfigPlan.plan`, `GlobalDefault.merged`,
`rememberedPick`), and the start names the one that stays. Hermes is the
exception: its main model is always Darkbloom's, as `ollama launch` and `omlx launch` make theirs, and the start
names the one it replaced (`ToolConfigSummary.replacedDefault`).
4. The `darkbloom` block is Darkbloom's whole: a run that changes it rewrites all of it, so a key the owner added
inside it is replaced too (only comments are counted); the backup keeps it.
4. An edit is idempotent: the planners render deterministically, and equal bytes give `.unchanged`, with no backup and
5. An edit is idempotent: the planners render deterministically, and equal bytes give `.unchanged`, with no backup and
no write (`ToolConfigWriter.apply`). That holds without the catalog too: the file's own entries stand in for it, so
a run offline never downgrades what a run online wrote.
5. A file a splice can't edit safely is refused before anything is written: malformed or ambiguous JSONC, a root or
a run offline never downgrades what a run online wrote. A model's name says where it runs, and is read back
without it (`IntegrationModel.displayName(in:)`), so it stays the same while the model runs in the same place
(`(your pair)` included). A default Darkbloom set is found again and left alone.
6. A file a splice can't edit safely is refused before anything is written: malformed or ambiguous JSONC, a root or
`providers` that isn't an object, and in YAML several documents, tab indentation, anchors, aliases or merge keys,
block text, inline or multi-line values in `providers` or `model` (`JSONCDocument`, `HermesEdit.checkSection`).
6. Each identity writes its own provider (`IntegrationProvider.current`: `darkbloom`, `darkbloom-dev`), so a test
7. Each identity writes its own provider (`IntegrationProvider.current`: `darkbloom`, `darkbloom-dev`), so a test
build beside the production one adds a second block.
7. Before a change the exact bytes are copied to `<install dir>/integrations/backups/<tool>/<file>.<UTC time>`
8. Before a change the exact bytes are copied to `<install dir>/integrations/backups/<tool>/<file>.<UTC time>`
(folder 0700, file 0600); `keptBackups = 5` of each file name stay, so two Hermes homes share the five
`config.yaml` slots. The new bytes replace the file in one rename
through `AtomicFile.write` (`provider-swift/Sources/ProviderCore/Service/AtomicFile.swift`) with the file's own
mode; a symlinked config is written through and stays a link.
8. One lock, `<install dir>/integrations/.lock`, serialises Darkbloom's own runs; the file is read again just before
9. One lock, `<install dir>/integrations/.lock`, serialises Darkbloom's own runs; the file is read again just before
the rename, and a change by the tool's own writer re-plans the edit once and refuses the second time.

## Failure modes
Expand Down Expand Up @@ -168,9 +204,10 @@ flowchart LR

| Concern | File, symbol |
|---|---|
| Entry point, endpoint, identity, paths | `provider-swift/Sources/darkbloom/ToolIntegration/ToolIntegration.swift` (`ToolIntegration.configure`, `IntegrationEndpoint.live`, `IntegrationProvider`) |
| Models | `provider-swift/Sources/darkbloom/ToolIntegration/IntegrationModels.swift` (`IntegrationModels.fetch`, `resolve`) |
| OpenCode | `provider-swift/Sources/darkbloom/ToolIntegration/OpenCodeConfigPlan.swift`, `provider-swift/Sources/darkbloom/ToolIntegration/JSONCDocument.swift` |
| Entry point, endpoint, identity, paths | `provider-swift/Sources/darkbloom/ToolIntegration/ToolIntegration.swift` (`ToolIntegration.configure`, `IntegrationEndpoint.live`, `servesThePair`, `IntegrationProvider`) |
| Models | `provider-swift/Sources/darkbloom/ToolIntegration/IntegrationModels.swift` (`IntegrationModels.fetch`, `resolve`, `IntegrationModel.Location`) |
| OpenCode | `provider-swift/Sources/darkbloom/ToolIntegration/OpenCodeConfigPlan.swift` (`plan`, `globalFileNames`: OpenCode's config order; `GlobalDefault.merged`, `otherGlobalDefault`, `globalDefault(in:)`), `provider-swift/Sources/darkbloom/ToolIntegration/JSONCDocument.swift` |
| What a start says | `provider-swift/Sources/darkbloom/ToolIntegration/ToolIntegrationStep.swift` (`lines`, `changed`, `openCodeDefault`, `alreadyServes`) |
| Hermes | `provider-swift/Sources/darkbloom/ToolIntegration/HermesConfigPlan.swift` (`HermesConfigPlan.plan`, `previousEndpointKeys`), `provider-swift/Sources/darkbloom/ToolIntegration/HermesVersion.swift` (`HermesVersion.keyCommandWarning`) |
| Plans and refusals | `provider-swift/Sources/darkbloom/ToolIntegration/ToolConfigPlan.swift` |
| The wait for this Mac's models | `provider-swift/Sources/darkbloom/ToolIntegration/ModelLoadWait.swift` (`ModelLoadWait`, `ModelLoads`, `LiveLine`, `InterruptWatch`) |
Expand Down
Loading
Loading