@darkbear9494/dsh-model-manager 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,7 +12,12 @@ decides the tier outright, and each role's failover chain wears down on its own.
12
12
  alias people type — puts the top-level session on the `planning` role for the rest of the session,
13
13
  exactly as plan mode does. Since 0.6.0 it ships one skill of its own: **`/autoplan`** turns the two
14
14
  tiers into a workflow — the plan is designed by a `plan:`-labelled fork on the planning model, and
15
- the main model implements the returned plan immediately, without stopping for approval.
15
+ the main model implements the returned plan immediately, without stopping for approval. Since 0.6.1
16
+ it also follows DSH 0.2's model-selection contract: a route is assigned with `agent.model.select()`
17
+ before the step is prepared, instead of being rewritten at request time (which 0.2 aborts). Since
18
+ 0.7.0 it registers its first real slash command: **`/readimage`** puts one message — and the images
19
+ attached to it — on the `vision` tier for that turn alone, then hands the session back to whatever
20
+ routing was in force.
16
21
 
17
22
  ## What it is
18
23
 
@@ -42,7 +47,10 @@ the intent arrived as a `/grilling` gesture in user text, as the harness's skill
42
47
  the model's own `skill` tool call — and it is read from a durable session projection, so it
43
48
  survives a restart, a resume and a fork. 0.6.0 adds a second, complementary skill: `/autoplan`
44
49
  plans on the planning tier and implements on `main` in the same turn, with no approval gate in
45
- between — the label-driven tiers become a workflow instead of a setting. It is still deliberately
50
+ between — the label-driven tiers become a workflow instead of a setting. 0.7.0 adds the first
51
+ trigger that is a real slash command: `/readimage`, registered through the harness's `commands`
52
+ service, puts the one message that carries it — image attachments included — on the `vision` tier,
53
+ and only for that turn. It is still deliberately
46
54
  small: one ESM host file, one config schema, one bundled skill body, and one hand-written client
47
55
  file that contributes a configuration card to the Plugins page. There is no build step for either
48
56
  half.
@@ -107,12 +115,14 @@ version and updates the dependency in place.
107
115
 
108
116
  ### The registry copy
109
117
 
110
- `@darkbear9494/dsh-model-manager@0.5.0` is the current release on the registry (published
111
- 2026-10-25), public access, the same 8 files as 0.2.0 (the tarball grew, not the file list: the
112
- host half, the client half and this README carry the new sections). It packs 92.1 kB (292.2 kB
113
- unpacked) with those 8 files; 0.2.0 packed 63.1 kB, and 0.1.0, the first publish, 62.3 kB. 0.6.0
114
- is the first release with a bundled skill, so it adds a ninth file —
115
- `skills/autoplan/SKILL.md` — and packs 97.1 kB (306.5 kB unpacked). The declared gate is
118
+ `@darkbear9494/dsh-model-manager@0.6.1` is the current release on the registry (published
119
+ 2026-11-06), public access, 9 files: the host half, the client half, this README, the two locale
120
+ dictionaries, the bundle patch, `package.json`, `LICENSE`, and `skills/autoplan/SKILL.md` — the
121
+ bundled skill 0.6.0 introduced. 0.6.0 (2026-11-05) was the first release with that ninth file and
122
+ packed 97.1 kB; 0.6.1 packs 102.4 kB (326.9 kB unpacked) with the DSH 0.2 model-selection fix.
123
+ Earlier: 0.5.0 packed 92.1 kB (292.2 kB unpacked) with the same 8 files as 0.2.0 (the tarball
124
+ grew, not the file list), 0.2.0 packed 63.1 kB, and 0.1.0, the first publish, 62.3 kB. The
125
+ declared gate is
116
126
  `>=0.1.7-rc.2 <0.3.0`, so every release on the 0.1.7–0.2.x runtime lines installs without an
117
127
  exemption.
118
128
 
@@ -705,6 +715,128 @@ an `Autoplan skill: registered` / `not registered (…)` line so you can tell wh
705
715
  Registering the skill is not routing: it happens even with `enabled: false`, where only the model
706
716
  switch stops.
707
717
 
718
+ ### The `/readimage` command
719
+
720
+ `/readimage` puts **one message** on the `vision` tier — the 图像识别 role — and only that message's
721
+ turn. It is the plugin's first **real slash command**: registered through the harness's `commands`
722
+ service, the same service `/plan` and `/compact` come from, declaring
723
+ `input: { hint: 'question about the attached image(s)', attachments: true }`, so it appears in the
724
+ composer's command autocomplete and can carry attachments. Registration needs only a composition
725
+ with a `commands` service and is independent of the model catalog; like the `/autoplan` skill, it is
726
+ not routing, so it happens even with `enabled: false`. The refusals live in the handler: with the
727
+ manager disabled, or with the vision role resolving to no models, the command returns a clear error
728
+ result instead of forwarding anything.
729
+
730
+ **Why a command and not a plain gesture.** On DSH 0.2.x the harness rejects image attachments at
731
+ prompt admission with `MODEL_DOES_NOT_SUPPORT_IMAGES` when the currently selected model declares
732
+ text-only input — *before* any plugin routing hook runs. A `/readimage` gesture typed as ordinary
733
+ text could therefore never carry an image past that gate while a text-only model is selected: the
734
+ message is refused before the manager could route it to a model that accepts images. The command
735
+ path admits attachments without the gate. The handler then forwards the original line — the
736
+ `/readimage` token included — plus the admitted image/file blocks as an ordinary user message
737
+ through `agent.followup()`, which queues a normal turn. That turn is routed by the same seams as any
738
+ other message; the token in the forwarded text is what names the intent. Bare `/readimage` with no
739
+ text and no attachments returns a usage error; bare `/readimage` with attachments forwards the token
740
+ plus the images.
741
+
742
+ **One turn, not one session.** This is the opposite of a [planning skill](#planning-skills): a skill
743
+ escalates the session for the rest of its life because its instructions stay in context, while
744
+ `/readimage` is per-message intent — the image is in *this* message, and the next message is ordinary
745
+ work again. The override is keyed to the **turn number** at the `agent/inbox/claimed` boundary — the
746
+ same seam where the 0.2.x selection reads the planning-skill gesture (see
747
+ [Switching models on DSH 0.2.x](#switching-models-on-dsh-02x)) — and maintained by `agent/pre-step`:
748
+
749
+ - Every step of the commanded turn runs on `vision`, tool-loop steps included, so the model that
750
+ sees the image keeps working with it.
751
+ - The next turn that claims a message without the gesture returns to normal routing: `main`, or
752
+ `planning` when plan mode or a planning skill is in force.
753
+ - A mid-turn steering message without the gesture does **not** cancel the override — it belongs to
754
+ the same turn.
755
+ - The override is process-live only. Nothing is folded into the durable log, so after a restart the
756
+ next message routes normally; only a fresh gesture commands a fresh turn.
757
+ - Subagent sessions are unaffected: a child's routing stays label-driven.
758
+
759
+ A short session:
760
+
761
+ ```text
762
+ you: /readimage what does this dashboard show? [screenshot attached]
763
+ → the whole turn runs on the vision role, tool-loop steps included
764
+ you: now fix the chart colours
765
+ → back on main (or planning, if plan mode or a planning skill is in force)
766
+ ```
767
+
768
+ **Precedence.** For its turn, `/readimage` outranks plan mode *and* planning skills
769
+ (`grilling` / `grill-me`): it is the most recent explicit instruction, and it names the tier for
770
+ exactly one message. Plan-mode tool restrictions still apply — they are composition-level, and only
771
+ the model changes. After the commanded turn the session returns to whatever state it was in: plan
772
+ mode, an active planning skill, or `main`.
773
+
774
+ **A hand-picked composer model yields for the turn, then comes back.** Under `hybrid` a model you
775
+ picked in the composer normally wins (see [`main` and the composer's model
776
+ picker](#main-and-the-composers-model-picker)). `/readimage` is an explicit, newer user instruction,
777
+ so it forces the vision route even over that pick — for the one turn. The pick is remembered, and
778
+ when the override ends the manager selects it back, so `hybrid` keeps respecting it on every later
779
+ turn. If you pick a *different* model in the composer after the commanded turn, that newer pick
780
+ wins over the remembered one — the restore hands back your latest choice, never a stale memory. On
781
+ the legacy DSH 0.1.x request-rewrite path nothing is durably selected in the first place, so
782
+ the pick survives automatically.
783
+
784
+ **Failover and diagnostics.** The commanded turn's role is recorded as `vision`, so in-step failover
785
+ walks the vision role's own chain — and the [image-capability warning](#vision-image-capability-check)
786
+ about text-only models in that chain still applies. The turn resolves the vision role the same way
787
+ any vision request does, including the [vision → execution fallback](#the-vision--execution-fallback)
788
+ when `vision` is empty. `model_manager(action: "report")` names the trigger `command:readimage` for
789
+ top-level turns routed this way, and `model_manager(action: "routes")` prints a line describing the
790
+ command — or saying it is disabled.
791
+
792
+ **The gesture works in plain text too.** The same word-boundary grammar that recognizes skill
793
+ gestures recognizes `/readimage` anywhere in a direct user message, so a text-only message carrying
794
+ the token routes to vision even when the command path was not used. Images still require the command
795
+ path: the admission gate above refuses them on the ordinary prompt path while a text-only model is
796
+ selected. The system-prompt cheat sheet gains one line telling the agent that you can type
797
+ `/readimage` to put one message on the vision tier.
798
+
799
+ The command name is configurable — `strategy.readImageCommand`, default `'readimage'`; an explicit
800
+ `''` disables both the command and the gesture. See [Configuration](#configuration).
801
+
802
+ ### Switching models on DSH 0.2.x
803
+
804
+ DSH 0.2 moved model selection out of the request waterfall. The loop reads
805
+ `agent.model.current()` at the start of step preparation and fixes
806
+ provider/model/reasoningEffort for that step; an `agent/request` listener that proposes another
807
+ route now **aborts the turn** with
808
+ `agent/request proposed "…" after step preparation fixed "…"; use agent.model.select() before step
809
+ preparation`. 0.6.1 follows the new contract while keeping the 0.1.x path:
810
+
811
+ | Harness | How a route is applied | `agent/request` |
812
+ | --- | --- | --- |
813
+ | 0.1.x (no `agent.model.select`) | the manager rewrites the proposed route | routing |
814
+ | 0.2.x (`agent.model.select` present) | `agent.model.select()` **before** the step is prepared | observe-only |
815
+
816
+ On 0.2.x the selection is made at `agent/inbox/claimed`, which is the one moment that beats the
817
+ fix without fighting it: the loop claims a step's input and only then reads the model, and the
818
+ claim notifications are emitted outside the session append being published — a selection made
819
+ there is accepted and lands on the request that is about to run. (A `session/event` listener
820
+ cannot do this: it runs inside the append, where a nested append is refused as reentrant.) A
821
+ second selection at `agent/pre-step` keeps later steps correct — plan mode toggled mid-turn, a
822
+ skill invoked on a later step, a child whose label was not yet known — at the price of landing on
823
+ the *next* step, which is the best any pre-step hook can do.
824
+
825
+ Consequences worth knowing:
826
+
827
+ - **A hand-picked model still wins under `hybrid`.** A route is the manager's own when it
828
+ selected it (`managerSelected`), and the deployment default when it equals the agent's creation
829
+ options; anything else is a recorded choice and is respected. Ownership is in-process, so after
830
+ a restart a session whose route the manager had selected reads as hand-picked and is left alone
831
+ until a turn actually routes it again — `managed` overrides it as always.
832
+ - **Failover cannot retry the same step on another model.** The step's route is fixed, so a
833
+ failure advances the role's cursor, selects the next model for the next request, and the failing
834
+ step ends instead of retrying a model already known to be down. The log says so; on 0.1.x the
835
+ old same-step retry is unchanged.
836
+ - **`routes` reports the transport** on its `Routing transport:` line — `agent.model.select()
837
+ before step preparation (DSH ≥ 0.2)` or `agent/request route rewrite (DSH 0.1.x)` — read from
838
+ the live agents, so it states what the running composition is actually doing.
839
+
708
840
  ### The vision → execution fallback
709
841
 
710
842
  If `vision.models` is empty when a vision request is routed, the plugin serves it from the
@@ -937,6 +1069,7 @@ Complete key set, with the schema defaults shown in comments:
937
1069
  # visionKeywords: omitted = the 20 built-ins; any list you write replaces them
938
1070
  # planningKeywords: omitted = the 24 built-ins; [] DISABLES that classifier
939
1071
  # planningSkills: omitted = ['grill-me', 'grilling']; [] DISABLES the trigger
1072
+ readImageCommand: readimage # default: readimage; '' DISABLES the command and the text gesture
940
1073
  historyLimit: 300 # default: 300; any positive value floors to at least 1
941
1074
  autoDelegate: balanced # default: balanced; "off" | "balanced" | "eager" — the delegation policy
942
1075
  update: # 0.3.0 — automatic update check
@@ -985,6 +1118,15 @@ Behaviours of `readConfig` worth knowing:
985
1118
  including one that normalizes down to empty, which is the disabled state. Membership is checked
986
1119
  against the live config on every request, so adding a skill and setting `[]` both take effect on
987
1120
  the next request with no restart.
1121
+ - `strategy.readImageCommand` is one command name, not a list: omitting the key uses `'readimage'`,
1122
+ and an explicit `''` disables the feature entirely — no command is registered and no gesture is
1123
+ recognized. The name is trimmed and lowercased and must be kebab-case **starting with a letter**
1124
+ (`[a-z][a-z0-9]*(-[a-z0-9]+)*`) — kebab-case because the `/name` gesture scanner requires it, a
1125
+ leading letter because the command registry's own `COMMAND_NAME` does — so a name failing either
1126
+ could never be invoked as a command; an invalid name logs a warning and disables the feature
1127
+ instead of failing registration at boot. A Settings save re-registers
1128
+ the command under the new name immediately. See [The `/readimage`
1129
+ command](#the-readimage-command).
988
1130
  - `historyLimit` accepts any positive number, floored to an integer and raised to a
989
1131
  minimum of 1, so a fractional value cannot floor to 0 and silently disable usage
990
1132
  tracking. `0`, a negative number, a non-number or an absent key all mean 300.
@@ -1412,7 +1554,8 @@ planning tier is missing it says so, so a `plan:` label is never a silent no-op.
1412
1554
  `planningSkills` is non-empty **and** the planning role has models, the same section adds one
1413
1555
  line saying that a top-level session which invoked one of those skills runs on the planning tier,
1414
1556
  like plan mode; with no models behind the tier it stays quiet rather than advertising a trigger
1415
- that routes nowhere.
1557
+ that routes nowhere. One further line tells the agent that the user can type `/readimage` to put a
1558
+ single message on the vision tier (see [The `/readimage` command](#the-readimage-command)).
1416
1559
 
1417
1560
  ## How it stays safe
1418
1561
 
@@ -1507,8 +1650,9 @@ degrades to a notice or a log line.
1507
1650
  npm test
1508
1651
  ```
1509
1652
 
1510
- Runs twelve suites in child processes and aggregates the result — **993 assertions** at the time
1511
- of writing. Each suite also runs on its own: `node test/<name>.test.mjs`.
1653
+ Runs the suites in child processes and aggregates the result — **1198 assertions** across
1654
+ **14 suites** at the time of writing. Each suite also runs on
1655
+ its own: `node test/<name>.test.mjs`.
1512
1656
 
1513
1657
  | Suite | Assertions | What it pins |
1514
1658
  | --- | --- | --- |
@@ -1524,6 +1668,8 @@ of writing. Each suite also runs on its own: `node test/<name>.test.mjs`.
1524
1668
  | `explicit-selection.test.mjs` | 25 | The rule that `main` yields to a hand-picked session model, and nothing else does: respected under `hybrid`, still applied under `managed`, untouched by a respected call in the round-robin rotation, and falling back to the old rewriting behaviour when the projection service is absent, when `stateOf` throws, or when the key was never registered. A disabled manager is checked too. Plus the `Top-level agents` report table: the hand-picked versus default-driven verdict, no orphaned subagent header when no subagent exists, a row that outlives its agent degrading to `unknown, agent no longer live`, and — read back out of the renderer's own source — proof that the reason column is still padded past the longest reason string it can print. |
1525
1669
  | `autoplan-skill.test.mjs` | 42 | New in 0.6.0. The bundled `/autoplan` skill: the pure frontmatter parser (`parseSkillMarkdown`) accepting exactly a well-formed SKILL.md — CRLF, edge-trimming, a `---` line inside the body preserved, a `name:` line in the body not mistaken for frontmatter — and returning `undefined` for a missing/unclosed fence, an empty body, an empty description, an invalid name, and every hostile input without throwing; the shipped definition satisfying the runtime contract `dsh-skill` validates on `get()` (kebab name, non-empty description/content, both invocation flags, a string source) and its body carrying the load-bearing instructions (the `plan:`-labelled `subagent_fork`, the no-approval rule, the plan-mode boundary, the `subagent` fallback, the main-tier implementation phase) so it cannot be silently gutted; registration through a mock skills service — exactly once, the shipped definition, an info log naming the skill — and every degradation: a throwing `register()` and a composition with no skills service both leave `apply()` working with a warning, and `routes()` distinguishing registered from not; registration independent of `config.enabled`; and the routing invariant that `/autoplan` is not a planning skill — a top-level session that invoked it stays on the `main` tier, with `/grilling` as the escalating control. The packaging suite additionally pins that `skills/` is in `files` and the body ships. |
1526
1670
  | `planning-skills.test.mjs` | 100 | New in 0.5.0. The skill → top-level `planning` escalation, in eight blocks: the pure event fold `skillNamesOfEvent` over all three records — the `skill-invocation` injection, the `/name` gesture in direct user text, and a model's `skill` `tool/call` with JSON arguments — including the gesture-boundary rules, hostile payloads that record nothing and never throw, and the grammar pinned **byte-identical against the real `dsh-tool-skill`** when a DSH install resolves; `planningSkills` configuration (absent → `grill-me`/`grilling`, explicit `[]` honoured, lowercasing/trimming/de-duplication, invalid names dropped, volatile refs unwrapped, no unknown-key warning either way, and the schema union accepting an array / rejecting anything else); the `modelManagerPlanningSkill` projection (key, `stateVersion`, `init`, folding all three event shapes, mixed-case canonicalization, same-reference returns that suppress republishing, `.parse` rejecting junk); the **live** `agent/pre-step` signal — registered prepended, routing the FIRST request of a gesture step, stickiness across later turns, non-listed skills left on `main`, `[]` disabling it, the enter/reject decision returned by identity, a dozen hostile payloads, a subagent never escalated, `agent/disposed` dropping the live signal, a volatile reload of `[]` applying to the next request, and the info notice firing once per switch; the **durable** signal (a resumed session routing planning from a logged invocation, gesture, or model tool call, a durable name inert under `[]`, and no throw when the projection service is absent); plan mode keeping its own behaviour and owning the trigger when both apply; an explicit composer pick still winning the route while the row records role `planning`; and both diagnostic surfaces — the `Planning skills:` line in `routes` and the `Planning skill trigger:` line in `report`, each in its enabled and disabled form. |
1671
+ | `model-select.test.mjs` | 26 | New in 0.6.1. DSH 0.2's selection contract: the pure helpers (`sameSelection`, `planningSkillInMessages`, `selectionModelOf`); a claimed user message selects the role's route before the step is prepared — plain prompt → `main`, `/grilling` → `planning`, `/autoplan` → `main`, plan mode → `planning`, round-robin committing only on an applied selection, and a hand-picked composer model respected under `hybrid` while `managed` overrides it; the manager's own selection is not mistaken for a hand-picked one on the next turn; `agent/request` returns the step's fixed route untouched (the 0.2 crash path); `agent/pre-step` corrects the next step; failover selects the next model and does not retry the fixed step; and a 0.1.x agent without a selection surface keeps request-time rewriting. |
1672
+ | `readimage.test.mjs` | 179 | New in 0.7.0. The `/readimage` command: the pure gesture helper `readImageGestureInMessages` (word-boundary recognition in direct user text, pinned against the real `dsh-tool-skill` grammar when a DSH install resolves) and `normalizeReadImageCommand` (the default, an explicit `''`, trimming/lowercasing, an invalid name disabling the feature with a warning), command registration through the `commands` service — name/input/handler registration, volatile rename and disable re-arming, and the handler's forwarding (frozen user message with a fresh UUID, the `/readimage` token included, attachments preserved by identity) plus every refusal path (bare command, disabled manager, advisory mode, vision-unconfigured, no inbox, throwing followup, aborted signal), the turn-keyed override lifecycle through the real seam order claim → current → pre-step → request (whole-turn vision routing including tool-loop steps, mid-turn steering not cancelling it, the next plain turn returning to normal routing, consecutive gestures), composer-pick force-then-restore — including the corner cases that the restore must hand back the user's LATEST pick (a newer composer pick made after or between commanded turns is kept, never clobbered by the stale memory) and that `main` does not eat the restored pick — precedence over plan mode and planning skills for the commanded turn only, subagent sessions never binding the override while their label routing is untouched, the legacy 0.1.x rewrite path with the explicit-selection bypass for that one turn, both diagnostic surfaces, the cheat sheet never advertising the command while disabled or advisory, and `agent/disposed` clean rebind. |
1527
1673
 
1528
1674
  The suites are plain Node scripts — no test framework, and no dependency beyond Node itself.
1529
1675
 
@@ -1556,12 +1702,29 @@ outside the repository.
1556
1702
  out. A skill the **model** invoked (through its `skill` tool) escalates only from the next
1557
1703
  request of that session onward — the `tool/call` event exists only once the model has emitted
1558
1704
  it, so the step that asked for the skill still runs on the route already chosen.
1705
+ - **Failover is per request, not per step, on DSH 0.2.x.** The route is fixed when a step is
1706
+ prepared, so a provider failure advances the role's cursor and selects the next model for the
1707
+ next request; the failing step ends rather than being retried on another model. On 0.1.x the
1708
+ same-step retry is unchanged. See [Switching models on DSH 0.2.x](#switching-models-on-dsh-02x).
1709
+ - **Selection ownership is in-process.** A route the manager selected reads as hand-picked after a
1710
+ restart, because 0.2 records every selection in the same durable event; `managed` overrides it,
1711
+ and the next turn that routes the session re-establishes ownership.
1559
1712
  - **`/autoplan` is a workflow, not enforcement.** The body is injected as instructions, so the
1560
1713
  model decides how faithfully to follow it: nothing forces the fork, and nothing stops a model
1561
1714
  from asking a question anyway. What the plugin does guarantee is the tiers — the `plan:` label
1562
1715
  routes the planning fork, and the top-level session stays on `main` because `autoplan` is not in
1563
1716
  `planningSkills`. A project-level skill file of the same name overrides the bundled body
1564
1717
  entirely (see the override note above).
1718
+ - **The `/readimage` override is process-live.** It is per-message intent, not durable session
1719
+ state: nothing is folded into the log, so a restart loses an in-flight commanded turn's routing
1720
+ and the next message routes normally. Type the gesture again to command a new turn.
1721
+ - **Images need the command path on a text-only current model.** The plain-text gesture routes
1722
+ text-only messages, but it cannot carry attachments past the admission gate: on DSH 0.2.x with a
1723
+ text-only model selected, the harness refuses the images with `MODEL_DOES_NOT_SUPPORT_IMAGES`
1724
+ before any routing hook runs. Only the registered command admits them.
1725
+ - **The command needs a `commands` service in the composition.** Older harnesses without one
1726
+ register no command, and the feature degrades to gesture-only routing for text messages — images
1727
+ then have no path at all while a text-only model is selected.
1565
1728
  - **`hybrid` compares routes by value.** A child that deliberately names the same route as
1566
1729
  the parent's effective route is indistinguishable from one that inherited it, and will
1567
1730
  be rewritten to the role route.
package/client.js CHANGED
@@ -64,7 +64,7 @@ window.__ModuleLoader__.load({
64
64
  * test/packaging.test.mjs pins it equal to package.json, so a release that
65
65
  * forgets to bump both fails the suite instead of shipping a wrong banner.
66
66
  */
67
- const VERSION = '0.6.0';
67
+ const VERSION = '0.7.0';
68
68
  /**
69
69
  * Registry path of this package. The scoped name is percent-encoded the
70
70
  * way npm serves scoped packuments.
package/cordis.patch.yml CHANGED
@@ -48,6 +48,13 @@
48
48
  # planningSkills:
49
49
  # - grill-me
50
50
  # - grilling
51
+ # Read-image command (0.7.0): the turn carrying `/readimage` runs on
52
+ # the vision role — one turn only, then the next message routes
53
+ # normally again. Registered as a real command with attachment
54
+ # support, so images pass admission even while a text-only model is
55
+ # selected. Omitting the key uses the built-in 'readimage'; an
56
+ # explicit '' disables the command and the gesture scan.
57
+ # readImageCommand: readimage
51
58
  # Auto-delegation policy (0.3.0): off | balanced | eager.
52
59
  # Adds a system-prompt section telling the top-level agent to plan
53
60
  # and dispatch subagents instead of doing everything itself.
package/lib/index.js CHANGED
@@ -25,6 +25,7 @@
25
25
  * @module @darkbear9494/dsh-model-manager
26
26
  */
27
27
 
28
+ import { randomUUID } from 'node:crypto';
28
29
  import { readFileSync } from 'node:fs';
29
30
 
30
31
  /**
@@ -52,7 +53,7 @@ const ROLE_NAMES = ['main', 'planning', 'execution', 'vision'];
52
53
  const KNOWN_TOP_KEYS = ['enabled', 'pick', 'roles', 'strategy', 'update'];
53
54
  const KNOWN_ROLE_KEYS = ['models', 'note'];
54
55
  const KNOWN_ROUTE_KEYS = ['provider', 'model', 'reasoningEffort'];
55
- const KNOWN_STRATEGY_KEYS = ['mode', 'visionKeywords', 'planningKeywords', 'planningSkills', 'historyLimit', 'autoDelegate'];
56
+ const KNOWN_STRATEGY_KEYS = ['mode', 'visionKeywords', 'planningKeywords', 'planningSkills', 'readImageCommand', 'historyLimit', 'autoDelegate'];
56
57
  const KNOWN_UPDATE_KEYS = ['enabled', 'registry', 'intervalHours'];
57
58
 
58
59
  /**
@@ -174,6 +175,20 @@ const DEFAULT_PLANNING_KEYWORDS = [
174
175
  */
175
176
  const DEFAULT_PLANNING_SKILLS = ['grill-me', 'grilling'];
176
177
 
178
+ /**
179
+ * The command that puts ONE turn on the vision role (0.7.0).
180
+ *
181
+ * Unlike a planning skill — which escalates a session for its whole life —
182
+ * `/readimage` is per-message intent: the turn carrying it runs on the vision
183
+ * tier (the 图像识别 role), and the next message without it routes normally
184
+ * again. It is registered as a real harness command declaring attachment
185
+ * support, because the ordinary prompt path refuses images outright while a
186
+ * text-only model is selected (`MODEL_DOES_NOT_SUPPORT_IMAGES`), before any
187
+ * routing hook runs; the command path admits the images and the handler
188
+ * forwards them as an ordinary user message. An empty string disables it.
189
+ */
190
+ const DEFAULT_READ_IMAGE_COMMAND = 'readimage';
191
+
177
192
  /**
178
193
  * The public DSH skill-name grammar and the `/name` gesture the harness scans
179
194
  * for in direct user text.
@@ -337,6 +352,7 @@ function buildConfigSchema(z) {
337
352
  visionKeywords: z.array(z.string()).default(DEFAULT_VISION_KEYWORDS),
338
353
  planningKeywords: z.array(z.string()).default(DEFAULT_PLANNING_KEYWORDS),
339
354
  planningSkills: z.array(z.string()).default(DEFAULT_PLANNING_SKILLS),
355
+ readImageCommand: z.string().default(DEFAULT_READ_IMAGE_COMMAND),
340
356
  historyLimit: z.number().default(300),
341
357
  autoDelegate: z.union([z.const('off'), z.const('balanced'), z.const('eager')]).default('balanced'),
342
358
  });
@@ -451,6 +467,32 @@ function normalizeSkillNames(value) {
451
467
  return names;
452
468
  }
453
469
 
470
+ /**
471
+ * Normalize `strategy.readImageCommand`.
472
+ *
473
+ * An absent or non-string value takes the built-in default (the same fail-on
474
+ * philosophy as the keyword lists: a malformed value must not silently switch
475
+ * a feature off). An explicit empty string is honoured and disables both the
476
+ * command registration and the gesture scan. A name outside the grammar logs
477
+ * a warning and disables the feature: it must be kebab-case for the gesture
478
+ * scanner AND start with a letter for the command registry's own
479
+ * `COMMAND_NAME`, so a name failing either could never be invoked as a
480
+ * command — better to refuse it at config time than fail registration at boot.
481
+ */
482
+ const READ_IMAGE_NAME = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
483
+
484
+ function normalizeReadImageCommand(value, warnings) {
485
+ const raw = readVal(value);
486
+ if (raw === undefined || raw === null || typeof raw !== 'string') return DEFAULT_READ_IMAGE_COMMAND;
487
+ const name = raw.trim().toLowerCase();
488
+ if (name === '') return '';
489
+ if (!READ_IMAGE_NAME.test(name)) {
490
+ warnings?.push(`strategy.readImageCommand "${raw}" is not a lowercase kebab-case name starting with a letter; the read-image command is disabled`);
491
+ return '';
492
+ }
493
+ return name;
494
+ }
495
+
454
496
  function normalizeRoute(raw) {
455
497
  const value = readVal(raw);
456
498
  if (value === null || typeof value !== 'object') return undefined;
@@ -677,6 +719,9 @@ function readConfig(raw) {
677
719
  // Absent/malformed -> the grill defaults; explicit [] switches the
678
720
  // skill-to-planning escalation off.
679
721
  planningSkills: normalizeSkillNames(strategyRaw.planningSkills),
722
+ // Absent/malformed -> 'readimage'; explicit '' switches the one-turn
723
+ // vision command off; an invalid name warns and disables it.
724
+ readImageCommand: normalizeReadImageCommand(strategyRaw.readImageCommand, warnings),
680
725
  // Guard against a positive fraction flooring to 0, which would evict every
681
726
  // record immediately and silently disable usage tracking.
682
727
  historyLimit: Number.isFinite(limit) && limit > 0 ? Math.max(1, Math.floor(limit)) : 300,
@@ -753,6 +798,78 @@ function planActive(ctx, agent) {
753
798
  return projected === undefined ? false : projected;
754
799
  }
755
800
 
801
+ /**
802
+ * The agent's model-selection surface, or `undefined`.
803
+ *
804
+ * DSH 0.2.x replaced the request-time model rewrite with an explicit selection
805
+ * API: `agent.model.select()` assigns the route for the next step whose
806
+ * preparation has not begun, while `agent/request` must preserve the route the
807
+ * step already fixed — proposing another one aborts the turn. Feature-detecting
808
+ * the surface keeps the 0.1.x rewrite path working on harnesses that never
809
+ * shipped it.
810
+ */
811
+ function selectionModelOf(agent) {
812
+ const model = probe(() => agent?.model);
813
+ return model !== undefined && typeof model.select === 'function' ? model : undefined;
814
+ }
815
+
816
+ /** Whether two route selections name the same provider, model and effort. */
817
+ function sameSelection(left, right) {
818
+ if (left === undefined || right === undefined) return false;
819
+ return left.provider === right.provider
820
+ && left.model === right.model
821
+ && (left.reasoningEffort ?? undefined) === (right.reasoningEffort ?? undefined);
822
+ }
823
+
824
+ /**
825
+ * The planning skill named by a batch of pending user messages, or `undefined`.
826
+ *
827
+ * The inbox is the only place a new turn's text exists before its first step is
828
+ * prepared — the harness appends `user/message` only when the step admits it,
829
+ * which is after the route is fixed. Scanning the pending messages is therefore
830
+ * what lets a `/grilling` gesture reach the FIRST request of its turn on a
831
+ * harness that fixes the route at step preparation. Recognition uses the
832
+ * harness's own `/name` grammar and only the configured planning skills match.
833
+ */
834
+ function planningSkillInMessages(messages, wanted) {
835
+ if (wanted.length === 0) return undefined;
836
+ for (const message of Array.isArray(messages) ? messages : []) {
837
+ if (message?.source?.kind !== 'user') continue;
838
+ for (const block of Array.isArray(message.content) ? message.content : []) {
839
+ if (block?.type !== 'text' || typeof block.text !== 'string') continue;
840
+ for (const match of block.text.matchAll(SKILL_GESTURE)) {
841
+ const name = match[2];
842
+ if (name !== undefined && wanted.includes(name)) return name;
843
+ }
844
+ }
845
+ }
846
+ return undefined;
847
+ }
848
+
849
+ /**
850
+ * Whether a batch of user messages carries the read-image gesture. Pure.
851
+ *
852
+ * Recognition uses the harness's own `/name` grammar (the same word-boundary
853
+ * shape tool-skill scans), so `/readimage` reads as a gesture wherever it sits
854
+ * in the sentence while file paths and fractions never match. Only direct user
855
+ * text counts — no other source can forge the gesture. The command handler
856
+ * forwards the original line, token included, so the claimed message it queues
857
+ * carries the gesture into the routing seams below.
858
+ */
859
+ function readImageGestureInMessages(messages, command) {
860
+ if (typeof command !== 'string' || command === '') return false;
861
+ for (const message of Array.isArray(messages) ? messages : []) {
862
+ if (message?.source?.kind !== 'user') continue;
863
+ for (const block of Array.isArray(message.content) ? message.content : []) {
864
+ if (block?.type !== 'text' || typeof block.text !== 'string') continue;
865
+ for (const match of block.text.matchAll(SKILL_GESTURE)) {
866
+ if (match[2] === command) return true;
867
+ }
868
+ }
869
+ }
870
+ return false;
871
+ }
872
+
756
873
  /** Find the delegating parent of a child session. */
757
874
  function findParent(ctx, childId) {
758
875
  return probe(() => {
@@ -1011,6 +1128,17 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
1011
1128
  * choice and stop managing that child permanently.
1012
1129
  */
1013
1130
  const managerApplied = new Map();
1131
+
1132
+ /**
1133
+ * session id -> route key this manager last assigned through
1134
+ * `agent.model.select()` (the DSH 0.2.x selection path).
1135
+ *
1136
+ * A selected route is recorded in the session log exactly like a composer
1137
+ * pick, so ownership has to be remembered here: without it the manager would
1138
+ * read back its own selection as a hand-picked model and stop routing the
1139
+ * session under `hybrid`.
1140
+ */
1141
+ const managerSelected = new Map();
1014
1142
  const roundRobin = new Map();
1015
1143
  /** child session id -> in-flight single-child lookup, to coalesce bursts */
1016
1144
  const childLookups = new Map();
@@ -1041,6 +1169,17 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
1041
1169
  */
1042
1170
  let autoplanRegistered = false;
1043
1171
 
1172
+ /**
1173
+ * The `commands` service, captured when its injection resolves, plus the
1174
+ * live registration of the read-image command. `readImageName` is the name
1175
+ * actually registered ('' when none), so a volatile Settings save that
1176
+ * renames the command can dispose the old registration and arm the new one,
1177
+ * and `routes` can tell "configured" from "registered in this composition".
1178
+ */
1179
+ let commandsService;
1180
+ let readImageDispose;
1181
+ let readImageName = '';
1182
+
1044
1183
  /**
1045
1184
  * Latest update-check outcome. Statuses: `idle` (not yet checked), `checking`,
1046
1185
  * `ok` (up to date), `available` (a newer release exists), `error` (the check
@@ -1082,6 +1221,23 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
1082
1221
  /** session id -> the last top-level trigger, so the info log fires once per switch. */
1083
1222
  const topTriggers = new Map();
1084
1223
 
1224
+ /**
1225
+ * session id -> `{ turn, restore }` for the ONE turn carrying `/readimage`.
1226
+ *
1227
+ * The override is keyed to the turn number that claimed the gesture, which
1228
+ * is what makes it expire by itself: every later step of that turn compares
1229
+ * equal and stays on vision, while the first claim of any other turn compares
1230
+ * different and ends it. `restore` remembers a hand-picked composer route the
1231
+ * command overrode (hybrid normally respects it), so the pick is selected
1232
+ * back when the commanded turn ends instead of being silently dropped.
1233
+ *
1234
+ * Deliberately process-live, with no durable projection: this is per-message
1235
+ * intent, not session state. After a restart the next message routes
1236
+ * normally, which is exactly the contract — only a fresh gesture commands a
1237
+ * fresh turn.
1238
+ */
1239
+ const readImageTurns = new Map();
1240
+
1085
1241
  /** Add one skill name to a session's live list, bounded and de-duplicated. */
1086
1242
  function addLiveSkill(id, name) {
1087
1243
  const normalized = typeof name === 'string' ? name.trim().toLowerCase() : '';
@@ -1139,7 +1295,11 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
1139
1295
  async function onPreStep(payload, next) {
1140
1296
  const decision = await next();
1141
1297
  try {
1142
- const id = typeof payload?.agent?.id === 'string' ? payload.agent.id : undefined;
1298
+ const agent = payload?.agent;
1299
+ const id = typeof agent?.id === 'string' ? agent.id : undefined;
1300
+ const isSubagent = agent === undefined
1301
+ ? false
1302
+ : probe(() => agent.session?.header?.origin === 'subagent') === true;
1143
1303
  if (id !== undefined && decision?.kind !== 'reject') {
1144
1304
  for (const batch of [payload?.messages, decision?.messages]) {
1145
1305
  if (!Array.isArray(batch)) continue;
@@ -1147,6 +1307,40 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
1147
1307
  for (const name of skillNamesOfMessage(message)) addLiveSkill(id, name);
1148
1308
  }
1149
1309
  }
1310
+ // The read-image override binds here too, on every transport: the
1311
+ // claim boundary covers the first step, and this scan covers a harness
1312
+ // whose claim notification predates the listener (or a batch the claim
1313
+ // seam never saw). Top-level only — a child's routing stays label-driven.
1314
+ if (!isSubagent) {
1315
+ for (const batch of [payload?.messages, decision?.messages]) {
1316
+ if (Array.isArray(batch)) noteReadImageGesture(agent, batch, payload?.turn);
1317
+ }
1318
+ endReadImageTurn(agent, payload?.turn);
1319
+ }
1320
+ }
1321
+ // On a harness that fixes the route at step preparation, keep the
1322
+ // selection correct from step to step: this call lands on the NEXT step,
1323
+ // because the current step's route was read before this hook ran. The
1324
+ // claim-boundary selection in `onInboxClaimed` is what covers the request
1325
+ // that is about to run.
1326
+ if (agent !== undefined && decision?.kind !== 'reject'
1327
+ && selectionModelOf(agent) !== undefined && config.enabled) {
1328
+ if (isSubagent) {
1329
+ const facts = catalog.get(agent.id);
1330
+ if (facts !== undefined) {
1331
+ applySelection(agent, classifySubagent(facts.label), undefined, facts.label, true);
1332
+ }
1333
+ } else {
1334
+ const readImage = readImageActive(agent, payload?.turn);
1335
+ const plan = planActive(ctx, agent);
1336
+ const skill = plan || readImage ? undefined : planningSkillFor(agent);
1337
+ const trigger = readImage
1338
+ ? `command:${config.strategy.readImageCommand}`
1339
+ : skill === undefined ? (plan ? 'plan-mode' : 'main') : `skill:${skill}`;
1340
+ noteTopTrigger(agent, trigger);
1341
+ applySelection(agent, readImage ? 'vision' : plan || skill !== undefined ? 'planning' : 'main',
1342
+ trigger, undefined, false, readImage);
1343
+ }
1150
1344
  }
1151
1345
  } catch {
1152
1346
  // Observe-only: a hostile message shape must never fail the step.
@@ -1164,6 +1358,88 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
1164
1358
  log('info', `planning skill "${trigger.slice('skill:'.length)}" is active in this session; `
1165
1359
  + 'top-level requests route as planning');
1166
1360
  }
1361
+ if (trigger.startsWith('command:')) {
1362
+ log('info', `/${trigger.slice('command:'.length)} commands this turn on the vision role; `
1363
+ + 'the next message without the gesture returns to the normal route');
1364
+ }
1365
+ }
1366
+
1367
+ /** Whether the read-image override owns the turn a step belongs to. */
1368
+ function readImageActive(agent, turn) {
1369
+ if (!Number.isSafeInteger(turn)) return false;
1370
+ const id = typeof agent?.id === 'string' ? agent.id : undefined;
1371
+ return id !== undefined && readImageTurns.get(id)?.turn === turn;
1372
+ }
1373
+
1374
+ /**
1375
+ * Bind the override to the turn whose claimed input carries the gesture.
1376
+ *
1377
+ * Called at both routing seams (the claim boundary and the pre-step batch)
1378
+ * with the turn number the harness reports, so the binding is to the turn
1379
+ * that OWNS the message — a mid-turn steering message without the gesture
1380
+ * cannot steal or cancel it. A consecutive commanded turn keeps the original
1381
+ * `restore` route: the pick to hand back is the one from before the first
1382
+ * override, never the vision route the manager itself selected.
1383
+ */
1384
+ function noteReadImageGesture(agent, messages, turn) {
1385
+ const command = config.strategy.readImageCommand;
1386
+ if (command === '' || !Number.isSafeInteger(turn)) return;
1387
+ const id = typeof agent?.id === 'string' ? agent.id : undefined;
1388
+ if (id === undefined || !readImageGestureInMessages(messages, command)) return;
1389
+ const existing = readImageTurns.get(id);
1390
+ if (existing?.turn === turn) return;
1391
+ const current = probe(() => selectionModelOf(agent)?.current());
1392
+ // A pick made after the previous commanded turn is newer than the one
1393
+ // remembered then, so it replaces the memory: what must come back is the
1394
+ // user's LATEST choice, never a stale one. When current is the manager's
1395
+ // own vision route (the ordinary case) it is not foreign and the original
1396
+ // memory stands.
1397
+ const restore = (selectionIsForeign(agent, current) ? current : undefined) ?? existing?.restore;
1398
+ readImageTurns.set(id, { turn, restore });
1399
+ }
1400
+
1401
+ /**
1402
+ * End the override when a DIFFERENT turn claims input, handing a remembered
1403
+ * composer pick back.
1404
+ *
1405
+ * The restore is selected before the normal role decision runs, so the
1406
+ * hybrid gate that follows reads the pick as foreign again and respects it —
1407
+ * ownership is dropped on purpose: a restored pick is the user's choice, not
1408
+ * a route the manager may replace with `main` on the next turn. On the 0.1.x
1409
+ * rewrite path nothing was ever durably selected, so there is nothing to
1410
+ * restore and the pick survives on its own.
1411
+ */
1412
+ function endReadImageTurn(agent, turn) {
1413
+ const id = typeof agent?.id === 'string' ? agent.id : undefined;
1414
+ if (id === undefined || !Number.isSafeInteger(turn)) return;
1415
+ const active = readImageTurns.get(id);
1416
+ if (active === undefined || active.turn === turn) return;
1417
+ readImageTurns.delete(id);
1418
+ if (active.restore === undefined) return;
1419
+ if (!config.enabled || config.strategy.mode === 'advisory') return;
1420
+ const model = selectionModelOf(agent);
1421
+ if (model === undefined) return;
1422
+ try {
1423
+ // A hand pick made AFTER the commanded turn is newer than the one
1424
+ // remembered at command time. Keep it and drop ownership so hybrid
1425
+ // respects it — restoring the stale memory would eat the user's latest
1426
+ // choice, which is exactly what the restore exists to protect.
1427
+ const current = probe(() => model.current());
1428
+ if (selectionIsForeign(agent, current)) {
1429
+ managerSelected.delete(id);
1430
+ return;
1431
+ }
1432
+ model.select({
1433
+ provider: active.restore.provider,
1434
+ model: active.restore.model,
1435
+ ...(active.restore.reasoningEffort === undefined ? {} : { reasoningEffort: active.restore.reasoningEffort }),
1436
+ });
1437
+ managerSelected.delete(id);
1438
+ log('info', `restored the hand-picked ${active.restore.provider}/${active.restore.model} `
1439
+ + `for ${shortId(id)} after the read-image turn`);
1440
+ } catch (error) {
1441
+ log('warn', `could not restore the hand-picked route: ${error?.message ?? error}`);
1442
+ }
1167
1443
  }
1168
1444
 
1169
1445
  /** The model list a role actually resolves to, including the vision fallback. */
@@ -1206,6 +1482,202 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
1206
1482
  return { route: models[at], commit() {} };
1207
1483
  }
1208
1484
 
1485
+ // -- model selection (DSH 0.2.x) ------------------------------------------
1486
+
1487
+ /**
1488
+ * Whether the agent's current selection was recorded by somebody else.
1489
+ *
1490
+ * A route the manager selected is its own; a route equal to the agent's
1491
+ * creation options is the deployment default (or the inherited parent route),
1492
+ * which the manager is allowed to replace. Anything else is a recorded choice
1493
+ * — a composer pick, a resume override, an explicit child route — and
1494
+ * `hybrid` leaves it alone, exactly when it is neither manager-owned nor the
1495
+ * deployment default.
1496
+ */
1497
+ function selectionIsForeign(agent, current) {
1498
+ if (current === undefined) return false;
1499
+ if (managerSelected.get(agent.id) === routeKey(current)) return false;
1500
+ const options = probe(() => agent?.options);
1501
+ if (options !== undefined && options.provider === current.provider && options.model === current.model) return false;
1502
+ return true;
1503
+ }
1504
+
1505
+ /**
1506
+ * The hybrid gate for a subagent's current route.
1507
+ *
1508
+ * Mirrors the request-path rule the 0.1.x engine implements: a child is
1509
+ * routed when the route is manager-owned or provably inherited from the
1510
+ * delegating parent, and respected when it names a route nobody can prove was
1511
+ * inherited (an explicit child choice, or unresolvable lineage).
1512
+ */
1513
+ function childRouteIsInherited(agent, current) {
1514
+ if (current === undefined) return true;
1515
+ if (managerSelected.get(agent.id) === routeKey(current)) return true;
1516
+ const previous = usage.get(agent.id);
1517
+ if (previous?.applied === true
1518
+ && previous.provider === current.provider
1519
+ && previous.model === current.model) return true;
1520
+ const parent = findParent(ctx, agent.id);
1521
+ const parentRoute = parent === undefined ? undefined : effectiveRouteOf(parent);
1522
+ if (parentRoute === undefined) return false;
1523
+ return parentRoute.provider === current.provider && parentRoute.model === current.model;
1524
+ }
1525
+
1526
+ /** Whether `hybrid` permits replacing the agent's current route with `route`. */
1527
+ function selectionAllowed(agent, current, isSubagent) {
1528
+ if (config.strategy.mode !== 'hybrid') return true;
1529
+ if (!isSubagent) return !selectionIsForeign(agent, current);
1530
+ return childRouteIsInherited(agent, current);
1531
+ }
1532
+
1533
+ /**
1534
+ * Assign a role's route through `agent.model.select()`.
1535
+ *
1536
+ * This is the only legal way to change a model on DSH 0.2.x: the loop fixes
1537
+ * provider/model/reasoningEffort at step preparation and rejects an
1538
+ * `agent/request` that proposes another route. Selection applies to the next
1539
+ * step whose preparation has not begun, so callers run it at `turn/start`
1540
+ * (before the first step) and at `agent/pre-step` (for the step after the one
1541
+ * in flight). Returns whether a selection was recorded; every failure is
1542
+ * contained.
1543
+ *
1544
+ * `force` is the read-image command's one-turn authority: an explicit user
1545
+ * instruction for THIS message outranks even a hand-picked composer route
1546
+ * for the turn it commands (the pick is remembered and restored afterwards
1547
+ * by `endReadImageTurn`). It never bypasses the master switch or advisory
1548
+ * mode — those mean the manager does not move routes at all.
1549
+ */
1550
+ function applySelection(agent, role, trigger, label, isSubagent, force = false) {
1551
+ const model = selectionModelOf(agent);
1552
+ if (model === undefined || !config.enabled) return false;
1553
+ try {
1554
+ if (config.strategy.mode === 'advisory') return false;
1555
+ const candidate = routeCandidate(role, agent.id);
1556
+ if (candidate === undefined) return false;
1557
+ const route = candidate.route;
1558
+ const current = probe(() => model.current());
1559
+ if (!force && !selectionAllowed(agent, current, isSubagent)) {
1560
+ if (!isSubagent && current !== undefined) {
1561
+ log('info', `session ${shortId(agent.id)} keeps ${current.provider}/${current.model}: `
1562
+ + 'a hand-picked model is respected under hybrid');
1563
+ }
1564
+ return false;
1565
+ }
1566
+ if (sameSelection(current, route)) {
1567
+ managerSelected.set(agent.id, routeKey(route));
1568
+ return false;
1569
+ }
1570
+ model.select({
1571
+ provider: route.provider,
1572
+ model: route.model,
1573
+ ...(route.reasoningEffort === undefined ? {} : { reasoningEffort: route.reasoningEffort }),
1574
+ });
1575
+ candidate.commit();
1576
+ managerSelected.delete(agent.id);
1577
+ managerSelected.set(agent.id, routeKey(route));
1578
+ while (managerSelected.size > MANAGER_APPLIED_LIMIT) {
1579
+ const oldest = managerSelected.keys().next().value;
1580
+ if (oldest === undefined) break;
1581
+ managerSelected.delete(oldest);
1582
+ }
1583
+ log('info', `selected ${route.provider}/${route.model} for ${shortId(agent.id)} (${role}) `
1584
+ + `before step preparation${trigger === undefined ? '' : ` — ${trigger}`}`);
1585
+ return true;
1586
+ } catch (error) {
1587
+ log('warn', `model selection skipped: ${error?.message ?? error}`);
1588
+ return false;
1589
+ }
1590
+ }
1591
+
1592
+ /**
1593
+ * One line describing how this harness accepts a route change.
1594
+ *
1595
+ * The two supported contracts differ enough that an operator has to be able
1596
+ * to tell which one is in force: 0.1.x rewrites the `agent/request` proposal,
1597
+ * 0.2.x fixes the route at step preparation and only accepts
1598
+ * `agent.model.select()` before it. Capability is read from the live agents,
1599
+ * so this reports what the running composition actually does.
1600
+ */
1601
+ function selectionTransport() {
1602
+ const agents = probe(() => ctx.get('agents'));
1603
+ const list = typeof agents?.list === 'function' ? probe(() => agents.list()) : undefined;
1604
+ const live = Array.isArray(list) ? list : [];
1605
+ if (live.length === 0) return 'not decided yet (no live agent has been observed)';
1606
+ if (live.some((agent) => selectionModelOf(agent) !== undefined)) {
1607
+ return 'agent.model.select() before step preparation (DSH ≥ 0.2)';
1608
+ }
1609
+ return 'agent/request route rewrite (DSH 0.1.x)';
1610
+ }
1611
+
1612
+ /** The live agent a session belongs to, or `undefined`. */
1613
+ function agentForSession(session) {
1614
+ const agents = probe(() => ctx.get('agents'));
1615
+ if (agents === undefined || session === undefined) return undefined;
1616
+ const direct = typeof agents.get === 'function' ? probe(() => agents.get(session.id)) : undefined;
1617
+ if (direct !== undefined) return direct;
1618
+ if (typeof agents.list !== 'function') return undefined;
1619
+ return probe(() => agents.list().find((candidate) => candidate.session === session));
1620
+ }
1621
+
1622
+ /**
1623
+ * Decide the role for a step that is claiming its input.
1624
+ *
1625
+ * `agent/inbox/claimed` is the one moment that beats the route fix without
1626
+ * fighting it: the loop's `preStep()` claims the batch first and reads
1627
+ * `agent.model.current()` straight after, and the claim notifications are
1628
+ * emitted outside any session append — so a selection made here is accepted
1629
+ * and lands on the step that is about to run. (`session/event` cannot do
1630
+ * this: its listeners run inside the append that is being published, where a
1631
+ * nested append is refused as reentrant.)
1632
+ *
1633
+ * The claimed message is what names the intent — the `/grilling` gesture, or
1634
+ * the plain prompt that leaves the session on `main` — so this is also where
1635
+ * a turn's FIRST request gets its role. Everything is wrapped: a selection
1636
+ * hook must never fail a step.
1637
+ */
1638
+ function onInboxClaimed(payload) {
1639
+ try {
1640
+ if (!config.enabled) return;
1641
+ const agent = payload?.agent;
1642
+ const message = payload?.message;
1643
+ if (agent === undefined || selectionModelOf(agent) === undefined) return;
1644
+ const isSubagent = probe(() => agent.session?.header?.origin === 'subagent') === true;
1645
+ if (isSubagent) {
1646
+ const facts = catalog.get(agent.id);
1647
+ // The label only exists behind an async listing. A child whose facts are
1648
+ // not cached yet runs its first step on the inherited route; the
1649
+ // pre-step hook then corrects it from the second step on. The eager
1650
+ // lookup in `subagent/start` usually wins that race.
1651
+ if (facts !== undefined) {
1652
+ applySelection(agent, classifySubagent(facts.label), undefined, facts.label, true);
1653
+ }
1654
+ return;
1655
+ }
1656
+ // The claimed message names the intent, and the payload names the turn
1657
+ // that owns it: bind the read-image override to THAT turn, end any older
1658
+ // one (handing a remembered composer pick back), then decide the role.
1659
+ // The command outranks plan mode and planning skills for its own turn —
1660
+ // it is the most recent explicit instruction — and only for that turn.
1661
+ const turn = payload?.turn;
1662
+ noteReadImageGesture(agent, [message], turn);
1663
+ endReadImageTurn(agent, turn);
1664
+ const readImage = readImageActive(agent, turn);
1665
+ const plan = planActive(ctx, agent);
1666
+ const skill = plan || readImage
1667
+ ? undefined
1668
+ : (planningSkillFor(agent)
1669
+ ?? planningSkillInMessages([message], config.strategy.planningSkills));
1670
+ const trigger = readImage
1671
+ ? `command:${config.strategy.readImageCommand}`
1672
+ : skill === undefined ? (plan ? 'plan-mode' : 'main') : `skill:${skill}`;
1673
+ noteTopTrigger(agent, trigger);
1674
+ applySelection(agent, readImage ? 'vision' : plan || skill !== undefined ? 'planning' : 'main',
1675
+ trigger, undefined, false, readImage);
1676
+ } catch {
1677
+ /* observe-only at the claim boundary */
1678
+ }
1679
+ }
1680
+
1209
1681
  /**
1210
1682
  * Which role owns a delegated child, from its delegation label.
1211
1683
  *
@@ -1363,21 +1835,26 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
1363
1835
  let role;
1364
1836
  let label;
1365
1837
  let trigger;
1838
+ let readImage = false;
1366
1839
  if (isSubagent) {
1367
1840
  const facts = await factsFor(agent.id);
1368
1841
  label = facts?.label;
1369
1842
  role = classifySubagent(label);
1370
1843
  } else {
1371
- // Plan mode is the harness's own "thinking work" mode; a planning skill
1844
+ // The read-image command owns its turn outright; below it, plan mode
1845
+ // is the harness's own "thinking work" mode and a planning skill
1372
1846
  // (`grilling` / `grill-me`) is the user's own version of the same
1373
1847
  // intent, so both put the top-level session on the planning tier.
1848
+ readImage = readImageActive(agent, payload?.turn);
1374
1849
  const plan = planActive(ctx, agent);
1375
- const skill = plan ? undefined : planningSkillFor(agent);
1376
- trigger = skill === undefined ? (plan ? 'plan-mode' : 'main') : `skill:${skill}`;
1850
+ const skill = plan || readImage ? undefined : planningSkillFor(agent);
1851
+ trigger = readImage
1852
+ ? `command:${config.strategy.readImageCommand}`
1853
+ : skill === undefined ? (plan ? 'plan-mode' : 'main') : `skill:${skill}`;
1377
1854
  // Only claim routing when routing is on; a disabled manager still records
1378
1855
  // the trigger in its observed rows, but must not log that requests route.
1379
1856
  if (config.enabled) noteTopTrigger(agent, trigger);
1380
- role = plan || skill !== undefined ? 'planning' : 'main';
1857
+ role = readImage ? 'vision' : plan || skill !== undefined ? 'planning' : 'main';
1381
1858
  }
1382
1859
 
1383
1860
  // Master switch off: observe and record, but never rewrite a route. The
@@ -1400,6 +1877,34 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
1400
1877
  return resolved;
1401
1878
  }
1402
1879
 
1880
+ // DSH 0.2.x fixes provider/model/reasoningEffort at step preparation and
1881
+ // aborts the turn when this waterfall proposes another route. Routing
1882
+ // therefore happens through `agent.model.select()` at `turn/start` and
1883
+ // `agent/pre-step`; here the manager only records what the step fixed and
1884
+ // returns it untouched.
1885
+ if (selectionModelOf(agent) !== undefined) {
1886
+ const candidate = routeCandidate(role, agent.id);
1887
+ const matches = managerSelected.get(agent.id) === routeKey(resolved)
1888
+ || (candidate !== undefined
1889
+ && candidate.route.provider === resolved.provider
1890
+ && candidate.route.model === resolved.model);
1891
+ remember(agent.id, {
1892
+ role,
1893
+ trigger,
1894
+ label,
1895
+ isSubagent,
1896
+ provider: resolved.provider,
1897
+ model: resolved.model,
1898
+ reasoningEffort: resolved.reasoningEffort,
1899
+ reason: matches
1900
+ ? 'step route selected before preparation'
1901
+ : 'step route fixed by the session',
1902
+ applied: matches,
1903
+ parentId: catalog.get(agent.id)?.parentId,
1904
+ });
1905
+ return resolved;
1906
+ }
1907
+
1403
1908
  // Record the attempt group, so the failover budget is per (turn, step).
1404
1909
  // `agent/request` re-fires for every attempt of the same step, so this
1405
1910
  // resets only when the step actually changes.
@@ -1435,13 +1940,17 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
1435
1940
  output = resolved;
1436
1941
  } else {
1437
1942
  let inherited = true;
1438
- if (mode === 'hybrid' && !isSubagent && selectionWasExplicit(agent)) {
1943
+ if (mode === 'hybrid' && !isSubagent && !readImage && selectionWasExplicit(agent)) {
1439
1944
  // `main` replaces a route the user never chose; it does not overrule
1440
1945
  // one they did choose. The proof is a durable log event, so a real
1441
1946
  // composer pick survives restart, resume and fork, while a session
1442
1947
  // still riding the deployment default is rewritten as before.
1443
1948
  // `managed` is the mode for "the manager owns every route", including a
1444
1949
  // session the user already picked, and is left untouched here.
1950
+ // The read-image command is the one exception: it is an explicit user
1951
+ // instruction for THIS turn, newer than the pick, so it rewrites for
1952
+ // that turn only — the durable selection is untouched on this path,
1953
+ // and the next turn respects the pick again by itself.
1445
1954
  inherited = false;
1446
1955
  reason = 'explicit session selection (respected)';
1447
1956
  } else if (mode === 'hybrid' && isSubagent) {
@@ -1474,6 +1983,7 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
1474
1983
  }
1475
1984
  output = inherited ? applyRoute(resolved, route) : resolved;
1476
1985
  didApply = inherited;
1986
+ if (didApply && readImage) reason = 'applied (read-image command, one turn)';
1477
1987
  }
1478
1988
 
1479
1989
  // Commit the rotation only when a route was actually applied, and record
@@ -1575,6 +2085,28 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
1575
2085
 
1576
2086
  const from = models[failedAt];
1577
2087
  const to = models[nextIndex];
2088
+ // DSH 0.2.x fixes the route at step preparation, so a retry of THIS step
2089
+ // always reuses the failed model. Select the next route instead: it is
2090
+ // what the next request will use, and this step ends with its failure
2091
+ // rather than retrying a model that is already known to be down.
2092
+ const model = selectionModelOf(agent);
2093
+ if (model !== undefined) {
2094
+ try {
2095
+ model.select({
2096
+ provider: to.provider,
2097
+ model: to.model,
2098
+ ...(to.reasoningEffort === undefined ? {} : { reasoningEffort: to.reasoningEffort }),
2099
+ });
2100
+ managerSelected.delete(agent.id);
2101
+ managerSelected.set(agent.id, routeKey(to));
2102
+ } catch (error) {
2103
+ log('warn', `failover could not select the next route: ${error?.message ?? error}`);
2104
+ }
2105
+ log('warn', `failover: ${role} ${from.provider}/${from.model} failed (${failure.code}); `
2106
+ + `the step route is fixed at preparation, so nothing is retried — the next request uses `
2107
+ + `${to.provider}/${to.model} (${budget.switches}/${MAX_SWITCHES_PER_STEP} this step)`);
2108
+ return undefined;
2109
+ }
1578
2110
  log('warn', `failover: ${role} ${from.provider}/${from.model} failed (${failure.code}); `
1579
2111
  + `re-running the step on ${to.provider}/${to.model} `
1580
2112
  + `(${budget.switches}/${MAX_SWITCHES_PER_STEP} switches this step)`);
@@ -2017,6 +2549,17 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
2017
2549
  lines.push('These sessions invoked a planning skill, so they route to the planning tier for');
2018
2550
  lines.push('the rest of the session, like plan mode; a hand-picked composer model still wins.');
2019
2551
  }
2552
+ const commandTriggers = topRows.filter((row) => typeof row.seen.trigger === 'string'
2553
+ && row.seen.trigger.startsWith('command:')
2554
+ && row.seen.reason !== 'manager disabled (observed only)');
2555
+ if (commandTriggers.length > 0) {
2556
+ lines.push('');
2557
+ lines.push('Read-image command: ' + commandTriggers
2558
+ .map((row) => `${shortId(row.sessionId)} → /${row.seen.trigger.slice('command:'.length)}`)
2559
+ .join(', '));
2560
+ lines.push('The last turn of these sessions carried the read-image gesture, so it ran on the');
2561
+ lines.push('vision role for that one turn; the next message without it routes normally again.');
2562
+ }
2020
2563
  lines.push('');
2021
2564
  }
2022
2565
  if (rows.length > 0) {
@@ -2107,12 +2650,24 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
2107
2650
  : `${config.strategy.planningSkills.join(', ')} — a top-level session that invoked one routes as `
2108
2651
  + 'planning for the rest of the session, like plan mode'}`,
2109
2652
  '',
2653
+ `Read-image command: ${config.strategy.readImageCommand === ''
2654
+ ? '(disabled) — strategy.readImageCommand is empty'
2655
+ : `/${config.strategy.readImageCommand} — the turn carrying it runs on the vision role (one turn only; `
2656
+ + 'the next message without the gesture returns to the normal route, and a hand-picked composer model '
2657
+ + 'is restored afterwards). '
2658
+ + (readImageName === config.strategy.readImageCommand
2659
+ ? 'Registered with attachment support, so images pass admission even on a text-only current model.'
2660
+ : 'NOT registered (no commands service, or registration failed — see the startup log) — '
2661
+ + 'only plain-text gestures route; images still need a current model that accepts them.')}`,
2662
+ '',
2110
2663
  `Autoplan skill: ${autoplanRegistered
2111
2664
  ? 'registered — `/autoplan` plans on the planning tier and implements on `main` '
2112
2665
  + 'without an approval gate'
2113
2666
  : 'not registered (no skills service in this composition, or skills/autoplan/SKILL.md '
2114
2667
  + 'is missing or invalid in this install)'}`,
2115
2668
  '',
2669
+ `Routing transport: ${selectionTransport()}`,
2670
+ '',
2116
2671
  allowListBlock(),
2117
2672
  '',
2118
2673
  visionBlock,
@@ -2150,12 +2705,18 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
2150
2705
  ? '\nA top-level session that invoked '
2151
2706
  + `${config.strategy.planningSkills.join(' / ')} runs on the planning tier, like plan mode.`
2152
2707
  : '';
2708
+ const readImageNote = config.enabled && config.strategy.mode !== 'advisory'
2709
+ && config.strategy.readImageCommand !== '' && effectiveModels('vision').length > 0
2710
+ ? `\nThe user can type /${config.strategy.readImageCommand} to run one message (with images) on the vision `
2711
+ + 'tier for its whole turn; the next message without it returns to the normal route. Suggest it when '
2712
+ + 'the user wants an image read but the current model cannot see images.'
2713
+ : '';
2153
2714
  return [
2154
2715
  '## Model manager',
2155
2716
  'Delegated work is routed by the label you give each delegation:',
2156
2717
  ...summary,
2157
2718
  routing,
2158
- `Call \`model_manager\` with action "report" to see which model each subagent actually used.${planningGap}${skillNote}`,
2719
+ `Call \`model_manager\` with action "report" to see which model each subagent actually used.${planningGap}${skillNote}${readImageNote}`,
2159
2720
  ].join('\n');
2160
2721
  }
2161
2722
 
@@ -2391,11 +2952,104 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
2391
2952
  * the manager off; the missing registration is logged at apply time.
2392
2953
  */
2393
2954
  function selectionWasExplicit(agent) {
2955
+ // On DSH 0.2.x a selection is a durable `model/selection` event regardless
2956
+ // of who wrote it, so the durable fold alone cannot tell a composer pick
2957
+ // from a route the manager itself selected. Ownership lives in
2958
+ // `managerSelected`: a route the manager does not own and that differs from
2959
+ // the agent's creation route is a hand-picked one.
2960
+ const model = selectionModelOf(agent);
2961
+ if (model !== undefined) {
2962
+ return selectionIsForeign(agent, probe(() => model.current()));
2963
+ }
2394
2964
  if (projections === undefined || typeof projections.stateOf !== 'function') return false;
2395
2965
  const state = probe(() => projections.stateOf(agent.session, SELECTION_PROJECTION_KEY));
2396
2966
  return state?.explicit === true;
2397
2967
  }
2398
2968
 
2969
+ /**
2970
+ * The `/readimage` command handler: forward, don't answer.
2971
+ *
2972
+ * The harness's ordinary prompt path refuses images while the selected model
2973
+ * declares text-only input (`MODEL_DOES_NOT_SUPPORT_IMAGES` in
2974
+ * dsh-api-session-controller), and it does so BEFORE any routing hook runs —
2975
+ * so a gesture scan alone could never see an image message on a text-only
2976
+ * main tier. The command path admits attachments without that gate; this
2977
+ * handler rebuilds the original line (token included, so the claim-boundary
2978
+ * gesture scan binds the turn) plus the admitted image/file blocks as an
2979
+ * ordinary user message and queues it with `agent.followup()`. The message
2980
+ * shape mirrors dsh-llm's `createUserMessage` — role, fresh UUID identity,
2981
+ * `source.kind: 'user'` — without importing a harness package, which a
2982
+ * profile-installed plugin cannot resolve. Routing then happens at the claim
2983
+ * boundary exactly as it does for any typed message.
2984
+ */
2985
+ function readImageHandler(invocation, name) {
2986
+ try {
2987
+ const agent = invocation?.agent;
2988
+ if (agent === undefined || typeof agent.followup !== 'function') {
2989
+ return { kind: 'error', text: `/${name}: this composition exposes no agent inbox to forward the message to` };
2990
+ }
2991
+ if (!config.enabled) {
2992
+ return { kind: 'error', text: `/${name}: the model manager is disabled, so the vision route cannot be selected` };
2993
+ }
2994
+ if (config.strategy.mode === 'advisory') {
2995
+ return { kind: 'error', text: `/${name}: the manager is advisory (observe-only), so it cannot switch this message to the vision model` };
2996
+ }
2997
+ if (effectiveModels('vision').length === 0) {
2998
+ return { kind: 'error', text: `/${name}: no vision model is configured — set roles.vision.models to an image-capable model` };
2999
+ }
3000
+ const rawInput = typeof invocation?.rawInput === 'string' ? invocation.rawInput : '';
3001
+ const attachments = Array.isArray(invocation?.attachments) ? invocation.attachments : [];
3002
+ if (rawInput.trim() === '' && attachments.length === 0) {
3003
+ return { kind: 'error', text: `usage: /${name} <question> — attach the image(s) to read; the message runs on the vision model for one turn` };
3004
+ }
3005
+ if (invocation?.signal?.aborted === true) {
3006
+ return { kind: 'error', text: `/${name}: cancelled before the message was forwarded` };
3007
+ }
3008
+ const line = `/${name}${rawInput}`;
3009
+ agent.followup(Object.freeze({
3010
+ role: 'user',
3011
+ id: randomUUID(),
3012
+ source: Object.freeze({ kind: 'user' }),
3013
+ content: Object.freeze([Object.freeze({ type: 'text', text: line }), ...attachments]),
3014
+ }));
3015
+ return { kind: 'success' };
3016
+ } catch (error) {
3017
+ return { kind: 'error', text: `/${name}: ${error?.message ?? error}` };
3018
+ }
3019
+ }
3020
+
3021
+ /**
3022
+ * Register (or re-register) the read-image command under the live config
3023
+ * name. Idempotent while the name is unchanged; a rename disposes the old
3024
+ * registration first. Every failure degrades to a warning — a composition
3025
+ * without the commands service simply keeps the plain-text gesture routing.
3026
+ */
3027
+ function armReadImageCommand() {
3028
+ if (commandsService === undefined || typeof commandsService.register !== 'function') return;
3029
+ const name = config.strategy.readImageCommand;
3030
+ if (readImageName === name) return;
3031
+ if (readImageDispose !== undefined) {
3032
+ try { readImageDispose(); } catch { /* a failed dispose must not block the re-arm */ }
3033
+ readImageDispose = undefined;
3034
+ }
3035
+ readImageName = '';
3036
+ if (name === '') return;
3037
+ try {
3038
+ const dispose = commandsService.register({
3039
+ name,
3040
+ description: 'Read attached images with the vision model: this message (and its turn) runs on the '
3041
+ + "manager's vision role, then the next message returns to the normal route. Accepts image attachments.",
3042
+ input: { hint: 'question about the attached image(s)', attachments: true },
3043
+ handler: (invocation) => readImageHandler(invocation, name),
3044
+ });
3045
+ readImageDispose = typeof dispose === 'function' ? dispose : () => {};
3046
+ readImageName = name;
3047
+ log('info', `registered the /${name} command — one turn on the vision role, with attachment support`);
3048
+ } catch (error) {
3049
+ log('warn', `/${name} command not registered: ${error?.message ?? error}`);
3050
+ }
3051
+ }
3052
+
2399
3053
  function attach() {
2400
3054
  ctx.on('agent/request', onAgentRequest);
2401
3055
  ctx.on('agent/request-error', onRequestError);
@@ -2419,13 +3073,32 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
2419
3073
  stepSwitches.delete(id);
2420
3074
  liveSkills.delete(id);
2421
3075
  topTriggers.delete(id);
3076
+ managerSelected.delete(id);
3077
+ readImageTurns.delete(id);
2422
3078
  });
2423
3079
 
3080
+ // Claim-boundary selection (DSH 0.2.x): the loop claims a step's input and
3081
+ // only then reads `agent.model.current()`, and the claim notifications are
3082
+ // emitted outside any session append — the one moment a role change can
3083
+ // reach the request that is about to run.
3084
+ ctx.on('agent/inbox/claimed', onInboxClaimed);
3085
+
2424
3086
  // Resolve a newly published child's label immediately, and targeted rather
2425
3087
  // than by sweeping every live agent.
2426
3088
  ctx.on('subagent/start', (info) => {
2427
3089
  const childId = info?.id;
2428
- if (childId !== undefined) void lookupChild(childId).catch(() => {});
3090
+ if (childId === undefined) return;
3091
+ void lookupChild(childId).then(() => {
3092
+ // DSH 0.2.x: the child's route has to be selected before its first
3093
+ // step is prepared, and the label only exists behind that async
3094
+ // listing. If this loses the race, the pre-step hook corrects the
3095
+ // route from the child's second step.
3096
+ const agent = agentForSession({ id: childId });
3097
+ const facts = catalog.get(childId);
3098
+ if (agent !== undefined && facts !== undefined) {
3099
+ applySelection(agent, classifySubagent(facts.label), undefined, facts.label, true);
3100
+ }
3101
+ }).catch(() => {});
2429
3102
  });
2430
3103
 
2431
3104
  // A volatile-only Settings edit is committed in place: the loader returns
@@ -2446,6 +3119,10 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
2446
3119
  };
2447
3120
  visionMatch = keywordMatcher(config.strategy.visionKeywords);
2448
3121
  planningMatch = keywordMatcher(config.strategy.planningKeywords);
3122
+ // A renamed (or disabled) read-image command takes effect on the save:
3123
+ // the gesture scan already reads the live config, and this re-arms the
3124
+ // harness command registration under the new name.
3125
+ armReadImageCommand();
2449
3126
  for (const warning of config.warnings) log('warn', warning);
2450
3127
  // The delegation policy and the update schedule both read the live
2451
3128
  // config through this closure, so they follow a save with no restart.
@@ -2453,7 +3130,8 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
2453
3130
  const updateChanged = JSON.stringify(previousUpdate) !== JSON.stringify(config.update);
2454
3131
  if (updateChanged) void checkForUpdate().catch(() => {});
2455
3132
  log('info', `settings reloaded — mode ${config.strategy.mode}, pick ${config.pick}, autoDelegate ${config.strategy.autoDelegate}, `
2456
- + `planningSkills ${config.strategy.planningSkills.join('|') || '-'}; `
3133
+ + `planningSkills ${config.strategy.planningSkills.join('|') || '-'}, `
3134
+ + `readImage ${config.strategy.readImageCommand || '-'}; `
2457
3135
  + ROLE_NAMES
2458
3136
  .map((key) => `${key}=${config.roles[key].models.length === 0 ? '-' : config.roles[key].models.map((r) => `${r.provider}/${r.model}`).join('|')}`)
2459
3137
  .join(' '));
@@ -2473,11 +3151,13 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
2473
3151
  description: 'Inspect and explain the role-based model routing configured for this harness. '
2474
3152
  + 'action "report": a Top-level agents section naming which model served each '
2475
3153
  + 'conversation, whether the manager yielded to a model a person picked in the '
2476
- + 'composer, and which planning skill (if any) put a session on the planning tier, '
3154
+ + 'composer, which planning skill (if any) put a session on the planning tier, '
3155
+ + 'and whether the last turn carried the read-image command, '
2477
3156
  + 'then one row per subagent with its label, role, reason, live status and '
2478
3157
  + 'totals. action "routes": the four role assignments '
2479
3158
  + '(including the vision->execution fallback), the shared selection strategy (first or round-robin), '
2480
3159
  + 'the active distribution mode, the auto-delegation level, the planning-skill trigger, '
3160
+ + 'the read-image command (one turn on the vision role), '
2481
3161
  + 'the update-check status, '
2482
3162
  + 'and whether each '
2483
3163
  + 'route is dispatchable by the delegation tool, with the YAML to add any that are not. '
@@ -2634,6 +3314,37 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
2634
3314
  log('warn', `/autoplan skill not registered: ${error?.message ?? error}`);
2635
3315
  }
2636
3316
  });
3317
+
3318
+ // The read-image command (0.7.0). Like /autoplan this is a workflow
3319
+ // gesture the plugin ships, but unlike a skill it must accept image
3320
+ // attachments: the command path is the only admission seam that lets
3321
+ // images through while a text-only model is selected. Registration
3322
+ // follows the live config name; a volatile save re-arms it below.
3323
+ ctx.inject(['commands'], (scoped) => {
3324
+ try {
3325
+ commandsService = scoped?.commands;
3326
+ if (commandsService === undefined || typeof commandsService.register !== 'function') {
3327
+ log('warn', 'the commands service is present but exposes no register(); the read-image command is unavailable');
3328
+ return;
3329
+ }
3330
+ if (typeof scoped.effect === 'function') {
3331
+ scoped.effect(() => {
3332
+ armReadImageCommand();
3333
+ return () => {
3334
+ if (readImageDispose !== undefined) {
3335
+ try { readImageDispose(); } catch { /* disposal is best-effort */ }
3336
+ readImageDispose = undefined;
3337
+ }
3338
+ readImageName = '';
3339
+ };
3340
+ });
3341
+ } else {
3342
+ armReadImageCommand();
3343
+ }
3344
+ } catch (error) {
3345
+ log('warn', `read-image command not registered: ${error?.message ?? error}`);
3346
+ }
3347
+ });
2637
3348
  }
2638
3349
 
2639
3350
  // Boot diagnostic: tell the operator about role routes the delegation tool
@@ -2733,7 +3444,13 @@ export {
2733
3444
  skillNamesOfEvent,
2734
3445
  parseSkillMarkdown,
2735
3446
  autoplanSkillDefinition,
3447
+ selectionModelOf,
3448
+ sameSelection,
3449
+ planningSkillInMessages,
3450
+ readImageGestureInMessages,
3451
+ normalizeReadImageCommand,
2736
3452
  DEFAULT_PLANNING_KEYWORDS,
2737
3453
  DEFAULT_PLANNING_SKILLS,
3454
+ DEFAULT_READ_IMAGE_COMMAND,
2738
3455
  DEFAULT_VISION_KEYWORDS,
2739
3456
  };
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@darkbear9494/dsh-model-manager",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
- "description": "Role-based model manager for DeepSeek Harness: assign models to planning, execution, vision and main roles, route subagent work by role, escalate sessions that invoke a planning skill (grilling / grill-me) to the planning role, report which model every subagent used, prompt the top-level agent to delegate, ship a /autoplan skill that plans on the planning tier then implements on main without stopping for approval, and check npm for updates.",
5
+ "description": "Role-based model manager for DeepSeek Harness: assign models to planning, execution, vision and main roles, route subagent work by role, escalate sessions that invoke a planning skill (grilling / grill-me) to the planning role, run /readimage messages with images on the vision role for one turn, report which model every subagent used, prompt the top-level agent to delegate, ship a /autoplan skill that plans on the planning tier then implements on main without stopping for approval, and switch models through agent.model.select() on DSH 0.2.x, and check npm for updates.",
6
6
  "license": "MIT",
7
7
  "keywords": [
8
8
  "dsh",
9
9
  "dsh-plugin",
10
10
  "autoplan",
11
+ "readimage",
11
12
  "deepseek-harness",
12
13
  "cordis",
13
14
  "model-routing",
@@ -35,7 +36,7 @@
35
36
  },
36
37
  "meta": {
37
38
  "title": "Model manager",
38
- "description": "Assign models to planning, execution, vision and main roles, see which model each subagent used, auto-delegate, run /autoplan (plan on the planning tier, then implement on main without an approval gate), and get update notices."
39
+ "description": "Assign models to planning, execution, vision and main roles, see which model each subagent used, auto-delegate, run /autoplan (plan on the planning tier, then implement on main without an approval gate), read images with /readimage (one turn on the vision tier), and get update notices."
39
40
  },
40
41
  "exports": {
41
42
  ".": "./lib/index.js",