@darkbear9494/dsh-model-manager 0.5.0 → 0.6.1

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
@@ -10,7 +10,11 @@ Since 0.4.0 the delegation label is a contract, not a hint: a leading `plan:`/`v
10
10
  decides the tier outright, and each role's failover chain wears down on its own. Since 0.5.0 the
11
11
  *session* can also pick its own tier: invoking a thinking skill — `grilling`, or the `grill-me`
12
12
  alias people type — puts the top-level session on the `planning` role for the rest of the session,
13
- exactly as plan mode does.
13
+ exactly as plan mode does. Since 0.6.0 it ships one skill of its own: **`/autoplan`** turns the two
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. 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).
14
18
 
15
19
  ## What it is
16
20
 
@@ -38,9 +42,12 @@ mode: a session that invoked one of the skills listed in `strategy.planningSkill
38
42
  `['grill-me', 'grilling']`) runs on the planning role's models for the rest of its life, whether
39
43
  the intent arrived as a `/grilling` gesture in user text, as the harness's skill injection, or as
40
44
  the model's own `skill` tool call — and it is read from a durable session projection, so it
41
- survives a restart, a resume and a fork. It is still deliberately small: one ESM host
42
- file, one config schema, and one hand-written client file that contributes a
43
- configuration card to the Plugins page. There is no build step for either half.
45
+ survives a restart, a resume and a fork. 0.6.0 adds a second, complementary skill: `/autoplan`
46
+ plans on the planning tier and implements on `main` in the same turn, with no approval gate in
47
+ between — the label-driven tiers become a workflow instead of a setting. It is still deliberately
48
+ small: one ESM host file, one config schema, one bundled skill body, and one hand-written client
49
+ file that contributes a configuration card to the Plugins page. There is no build step for either
50
+ half.
44
51
 
45
52
  ## Install
46
53
 
@@ -102,13 +109,12 @@ version and updates the dependency in place.
102
109
 
103
110
  ### The registry copy
104
111
 
105
- `@darkbear9494/dsh-model-manager@0.4.0` is the current release **on the registry**, public
106
- access, the same 8 files as 0.2.0 (the tarball grew, not the file list: the host half, the client
107
- half and this README carry the new sections). The 0.5.0 planning-skill work described throughout
108
- this README is this release **in the working copy** — nothing here claims it is published, because
109
- it is not: `add @darkbear9494/dsh-model-manager@latest` still resolves 0.4.0 until someone runs
110
- `npm publish`, so 0.5.0 installs from a local path (or from git, once it is pushed there). 0.2.0
111
- packed 63.1 kB with the same 8 files, and 0.1.0, the first publish, 62.3 kB. The declared gate is
112
+ `@darkbear9494/dsh-model-manager@0.5.0` is the current release on the registry (published
113
+ 2026-10-25), public access, the same 8 files as 0.2.0 (the tarball grew, not the file list: the
114
+ host half, the client half and this README carry the new sections). It packs 92.1 kB (292.2 kB
115
+ 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
116
+ is the first release with a bundled skill, so it adds a ninth file —
117
+ `skills/autoplan/SKILL.md` — and packs 97.1 kB (306.5 kB unpacked). The declared gate is
112
118
  `>=0.1.7-rc.2 <0.3.0`, so every release on the 0.1.7–0.2.x runtime lines installs without an
113
119
  exemption.
114
120
 
@@ -649,6 +655,96 @@ you hand-picked in the composer still serves the session: the report row shows r
649
655
  with reason `explicit session selection (respected)` and your route, exactly as it does in plan
650
656
  mode. There is no exit gesture — start a new session, or set `planningSkills: []`.
651
657
 
658
+ ### The `/autoplan` skill
659
+
660
+ `grilling` makes a session *think* on the planning tier; `/autoplan` makes it *think and then act*
661
+ without a review step. It is a **bundled skill**: the plugin registers it as a DSH runtime skill
662
+ through `ctx.skills.register` at startup, so installing the plugin is the whole install. Typing
663
+ `/autoplan <task>` in a session injects its body exactly like `dsh-tool-skill` injects any other
664
+ skill (the host recognises the `/name` gesture in direct user text, and the skill is
665
+ `userInvocable`); a model can also load it through the `skill` tool when the user asks to
666
+ plan-and-implement in one shot. The body ships as `skills/autoplan/SKILL.md`, read once at apply
667
+ time.
668
+
669
+ **The two phases use the two tiers, not a model swap mid-session:**
670
+
671
+ | Phase | Who runs it | Which model |
672
+ | --- | --- | --- |
673
+ | Plan | one `subagent_fork` the top-level agent dispatches, description `plan: design the implementation plan for <task>` | the `planning` role — the `plan:` label is the existing contract |
674
+ | Implement | the top-level session itself (or plain execution-tier units, per the delegation policy) | the `main` role |
675
+
676
+ The fork inherits the conversation, so the planner starts with every fact the main model already
677
+ gathered; it returns a decision-complete plan (goal, success criteria, changes by subsystem,
678
+ edge cases, tests, assumptions). The main model then implements it and reports what changed,
679
+ what it ran, and which assumptions it made on the user's behalf. The skill explicitly forbids
680
+ the things that would turn this into an approval flow: no `ask_user_question` to approve the
681
+ plan, no entering or exiting plan mode, no waiting. `autoplan` is deliberately **not** in
682
+ `strategy.planningSkills` — that list pins the whole session to the planning tier, while here the
683
+ top level must end up on `main` to implement.
684
+
685
+ **Why not switch the session's own model?** That was the other design: escalate the session to
686
+ `planning` on the gesture, then demote it when the plan is done. It needs a phase state machine,
687
+ a durable projection to survive restart, and a demotion trigger the manager cannot actually
688
+ observe — it would depend on the model remembering to call a marker tool, and a model that
689
+ forgets it leaves the whole session stuck on the expensive tier. Routing on the delegation label
690
+ already switches models per unit, and a fork carries the full conversation, so the two-phase
691
+ workflow needs no new state at all.
692
+
693
+ **Boundaries.** `/autoplan` skips *plan review*, not safety: approval prompts for risky
694
+ operations, sandbox limits and destructive-operation confirmations still apply, and the body says
695
+ so. Inside plan mode the plan-mode rules win — there the plan still goes through `exit_plan_mode`.
696
+ If the planning role has no models, the `plan:` unit simply keeps the inherited route and the flow
697
+ still runs. If `subagent_fork` is not in scope, the body falls back to plain `subagent` with a
698
+ self-contained prompt.
699
+
700
+ **Overrides and degradation.** The built-in copy is a runtime skill at DSH's runtime rank (250):
701
+ a project-level `.dsh/skills/autoplan/SKILL.md` (rank 100) or `.agents/skills/autoplan/` (200)
702
+ overrides it, but a `~/.dsh/skills/autoplan/` copy (rank 400) does **not** — that precedence is
703
+ DSH's, and it is the one surprising part of customising this skill. Registration is optional and
704
+ never load-bearing: no skills service in the composition, a throwing `register()`, or a missing or
705
+ malformed `SKILL.md` all degrade to a logged warning, and `model_manager(action: "routes")` prints
706
+ an `Autoplan skill: registered` / `not registered (…)` line so you can tell which case you are in.
707
+ Registering the skill is not routing: it happens even with `enabled: false`, where only the model
708
+ switch stops.
709
+
710
+ ### Switching models on DSH 0.2.x
711
+
712
+ DSH 0.2 moved model selection out of the request waterfall. The loop reads
713
+ `agent.model.current()` at the start of step preparation and fixes
714
+ provider/model/reasoningEffort for that step; an `agent/request` listener that proposes another
715
+ route now **aborts the turn** with
716
+ `agent/request proposed "…" after step preparation fixed "…"; use agent.model.select() before step
717
+ preparation`. 0.6.1 follows the new contract while keeping the 0.1.x path:
718
+
719
+ | Harness | How a route is applied | `agent/request` |
720
+ | --- | --- | --- |
721
+ | 0.1.x (no `agent.model.select`) | the manager rewrites the proposed route | routing |
722
+ | 0.2.x (`agent.model.select` present) | `agent.model.select()` **before** the step is prepared | observe-only |
723
+
724
+ On 0.2.x the selection is made at `agent/inbox/claimed`, which is the one moment that beats the
725
+ fix without fighting it: the loop claims a step's input and only then reads the model, and the
726
+ claim notifications are emitted outside the session append being published — a selection made
727
+ there is accepted and lands on the request that is about to run. (A `session/event` listener
728
+ cannot do this: it runs inside the append, where a nested append is refused as reentrant.) A
729
+ second selection at `agent/pre-step` keeps later steps correct — plan mode toggled mid-turn, a
730
+ skill invoked on a later step, a child whose label was not yet known — at the price of landing on
731
+ the *next* step, which is the best any pre-step hook can do.
732
+
733
+ Consequences worth knowing:
734
+
735
+ - **A hand-picked model still wins under `hybrid`.** A route is the manager's own when it
736
+ selected it (`managerSelected`), and the deployment default when it equals the agent's creation
737
+ options; anything else is a recorded choice and is respected. Ownership is in-process, so after
738
+ a restart a session whose route the manager had selected reads as hand-picked and is left alone
739
+ until a turn actually routes it again — `managed` overrides it as always.
740
+ - **Failover cannot retry the same step on another model.** The step's route is fixed, so a
741
+ failure advances the role's cursor, selects the next model for the next request, and the failing
742
+ step ends instead of retrying a model already known to be down. The log says so; on 0.1.x the
743
+ old same-step retry is unchanged.
744
+ - **`routes` reports the transport** on its `Routing transport:` line — `agent.model.select()
745
+ before step preparation (DSH ≥ 0.2)` or `agent/request route rewrite (DSH 0.1.x)` — read from
746
+ the live agents, so it states what the running composition is actually doing.
747
+
652
748
  ### The vision → execution fallback
653
749
 
654
750
  If `vision.models` is empty when a vision request is routed, the plugin serves it from the
@@ -1397,9 +1493,9 @@ degrades to a notice or a log line.
1397
1493
  - **Every optional integration is probed and wrapped.** Plan mode, the agent list and
1398
1494
  lineage, the parent's request header, subagent listing, the allow-list service, the
1399
1495
  model-capability lookup, the `sessionProjections` registry the planning-skill fold is read
1400
- from, `tools` and `systemPrompt` are each reached through a guarded
1401
- accessor and a `try`/`catch`; a missing service means that feature is inert, not that the
1402
- plugin fails. The `agent/request` handler catches its own errors, logs one warning
1496
+ from, `tools`, `systemPrompt` and the `skills` registry the `/autoplan` skill is registered
1497
+ on are each reached through a guarded accessor and a `try`/`catch`; a missing service means
1498
+ that feature is inert, not that the plugin fails. The `agent/request` handler catches its own errors, logs one warning
1403
1499
  (`routing skipped for one request: …`) and returns the request it was given, unchanged.
1404
1500
  The `agent/pre-step` observer is observe-only: it wraps its own scan in a `try`, never
1405
1501
  touches the decision it returns, and ignores a rejected step. Without the projection registry
@@ -1451,12 +1547,12 @@ degrades to a notice or a log line.
1451
1547
  npm test
1452
1548
  ```
1453
1549
 
1454
- Runs eleven suites in child processes and aggregates the result — **949 assertions** at the time
1550
+ Runs thirteen suites in child processes and aggregates the result — **1019 assertions** at the time
1455
1551
  of writing. Each suite also runs on its own: `node test/<name>.test.mjs`.
1456
1552
 
1457
1553
  | Suite | Assertions | What it pins |
1458
1554
  | --- | --- | --- |
1459
- | `packaging.test.mjs` | 35 | The package identity that nothing else cross-checks: the scoped name is the one string the bundle patch's loader row, the client half's module id and the host half's `PACKAGE_NAME` must all agree on, while the cordis row id, the client row namespace and the locale namespace must all *stay* unscoped. Plus publishability (not private, public access, a real `@deepseek-ai/dsh` version gate, schemastery still optional) and tarball completeness — every `exports` target and every `files` pattern resolved against disk, so a published package cannot mount-less. The gate is not string-matched: a self-validating semver comparator (prerelease-aware, and checked against the ordering trap first) proves the declared range admits 0.1.7-rc.2, 0.2.0-rc.2 **and** 0.2.0 while refusing 0.1.6 and 0.3.0 — because `<0.2.0` reads as "every 0.2.0 prerelease" while excluding 0.2.0 itself. 0.3.0 also pins the release plumbing both halves share: the client's `VERSION` constant equals `package.json` (a drift would ship a lying update banner), both halves fetch the same percent-encoded packument path, and the bundle patch carries the new `autoDelegate`/`update` defaults. |
1555
+ | `packaging.test.mjs` | 37 | The package identity that nothing else cross-checks: the scoped name is the one string the bundle patch's loader row, the client half's module id and the host half's `PACKAGE_NAME` must all agree on, while the cordis row id, the client row namespace and the locale namespace must all *stay* unscoped. Plus publishability (not private, public access, a real `@deepseek-ai/dsh` version gate, schemastery still optional) and tarball completeness — every `exports` target and every `files` pattern resolved against disk, so a published package cannot mount-less. The gate is not string-matched: a self-validating semver comparator (prerelease-aware, and checked against the ordering trap first) proves the declared range admits 0.1.7-rc.2, 0.2.0-rc.2 **and** 0.2.0 while refusing 0.1.6 and 0.3.0 — because `<0.2.0` reads as "every 0.2.0 prerelease" while excluding 0.2.0 itself. 0.3.0 also pins the release plumbing both halves share: the client's `VERSION` constant equals `package.json` (a drift would ship a lying update banner), both halves fetch the same percent-encoded packument path, and the bundle patch carries the new `autoDelegate`/`update` defaults. |
1460
1556
  | `routing.test.mjs` | 10 | The four roles route as documented; label classification (including a leading `plan:` beating vision keywords under `hybrid`); an explicit child route is respected; the tool and **both** system-prompt sections register; `apply` survives malformed configs. |
1461
1557
  | `delegation.test.mjs` | 39 | The auto-delegation policy: config normalization (absent → `balanced`, unrecognised → `balanced`, volatile refs unwrapped), the schema union, section registration and its 550 order, and every rendering gate — children (by `origin` and by `delegationDepth`) get `''`, tool-less scopes get `''`, fork-only scopes still get a policy naming `subagent_fork`, the master switch suppresses it, a volatile save switches levels live, and a throwing `tools.get` degrades to `''` instead of throwing out of a prompt section. Plus tier awareness: the policy delegates the decomposition, states the prefix rule, teaches the omit-`provider` rule (dropped under `advisory`), and never advertises a `plan:` tier with no models behind it. |
1462
1558
  | `update.test.mjs` | 58 | Version parsing and semver comparison (prerelease ordering, numeric identifiers, build-metadata equality, unparseable → `undefined`), `installedVersion` against the real manifest, `profileHint` from a real chdir, update-config normalization (registry sanitization, interval semantics including explicit 0 and the one-minute floor), and the check itself end-to-end with `fetch` mocked: available / up-to-date / older-latest / HTTP failure / malformed packument / rejected fetch / disabled-never-fetches / custom registry, plus the `report`/`routes` status lines, the log levels (available → warn, failure → info), scheduling through the cordis timer API (10 s boot delay, 24 h interval, boot-only, floor, disarm), and a volatile re-arm that immediately re-checks a changed registry. |
@@ -1466,8 +1562,10 @@ of writing. Each suite also runs on its own: `node test/<name>.test.mjs`.
1466
1562
  | `client-diagnostic.test.mjs` | 17 | Every branch of `model_manager` with `action: "client"`, including the two that matter most: a bundle the Host will not serve, and a bundle that serves but registers the wrong id. |
1467
1563
  | `usage-projection.test.mjs` | 43 | The projections this plugin registers — all three of them, `modelManagerUsage`, `modelManagerSelection` and since 0.5.0 `modelManagerPlanningSkill`, each asserted to be registered under its own key — and the per-session model-usage fold: bucket sums against the harness's own field names, refusal of unsafe or fractional counts without aborting the fold, usage recovered from an embedded stream, separate attribution per provider/model, immutable state transitions, reference stability that suppresses republishing, and both schemas rejecting junk through the only method cordis calls (`.parse`). |
1468
1564
  | `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. |
1565
+ | `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. |
1469
1566
  | `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. |
1470
1567
 
1568
+ | `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. |
1471
1569
  The suites are plain Node scripts — no test framework, and no dependency beyond Node itself.
1472
1570
 
1473
1571
  Two of them optionally pin their expectations against the **real** harness internals rather
@@ -1499,6 +1597,19 @@ outside the repository.
1499
1597
  out. A skill the **model** invoked (through its `skill` tool) escalates only from the next
1500
1598
  request of that session onward — the `tool/call` event exists only once the model has emitted
1501
1599
  it, so the step that asked for the skill still runs on the route already chosen.
1600
+ - **Failover is per request, not per step, on DSH 0.2.x.** The route is fixed when a step is
1601
+ prepared, so a provider failure advances the role's cursor and selects the next model for the
1602
+ next request; the failing step ends rather than being retried on another model. On 0.1.x the
1603
+ same-step retry is unchanged. See [Switching models on DSH 0.2.x](#switching-models-on-dsh-02x).
1604
+ - **Selection ownership is in-process.** A route the manager selected reads as hand-picked after a
1605
+ restart, because 0.2 records every selection in the same durable event; `managed` overrides it,
1606
+ and the next turn that routes the session re-establishes ownership.
1607
+ - **`/autoplan` is a workflow, not enforcement.** The body is injected as instructions, so the
1608
+ model decides how faithfully to follow it: nothing forces the fork, and nothing stops a model
1609
+ from asking a question anyway. What the plugin does guarantee is the tiers — the `plan:` label
1610
+ routes the planning fork, and the top-level session stays on `main` because `autoplan` is not in
1611
+ `planningSkills`. A project-level skill file of the same name overrides the bundled body
1612
+ entirely (see the override note above).
1502
1613
  - **`hybrid` compares routes by value.** A child that deliberately names the same route as
1503
1614
  the parent's effective route is indistinguishable from one that inherited it, and will
1504
1615
  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.5.0';
67
+ const VERSION = '0.6.1';
68
68
  /**
69
69
  * Registry path of this package. The scoped name is percent-encoded the
70
70
  * way npm serves scoped packuments.
package/lib/index.js CHANGED
@@ -242,6 +242,74 @@ function skillNamesOfEvent(event) {
242
242
  return [];
243
243
  }
244
244
 
245
+ /**
246
+ * Body of the bundled `/autoplan` skill, shipped beside this file.
247
+ *
248
+ * The skill is registered as a DSH runtime skill (`ctx.skills.register`) so
249
+ * that installing this plugin is the whole install: the user types
250
+ * `/autoplan <task>` and the harness injects the body like any other skill.
251
+ * The body is read at apply time with the same self-package read the version
252
+ * check already uses, so a bad install degrades to "skill not registered".
253
+ */
254
+ const AUTOPLAN_SKILL_URL = new URL('../skills/autoplan/SKILL.md', import.meta.url);
255
+
256
+ /**
257
+ * Parse a SKILL.md document's frontmatter and body. Pure.
258
+ *
259
+ * Deliberately minimal: the frontmatter must open the document with a `---`
260
+ * line, close on a `---` line, and declare single-line `name:` and
261
+ * `description:` values. Anything else — a missing fence, an invalid name, an
262
+ * empty description or an empty body — yields `undefined`, and the caller
263
+ * degrades to "not registered" instead of registering a malformed skill.
264
+ * CRLF is tolerated so a Windows checkout still loads.
265
+ */
266
+ function parseSkillMarkdown(text) {
267
+ if (typeof text !== 'string') return undefined;
268
+ const source = text.replace(/\r\n?/g, '\n');
269
+ if (!source.startsWith('---\n')) return undefined;
270
+ let fence = source.indexOf('\n---', 4);
271
+ while (fence !== -1 && fence + 4 < source.length && source[fence + 4] !== '\n') {
272
+ fence = source.indexOf('\n---', fence + 1);
273
+ }
274
+ if (fence === -1) return undefined;
275
+ const frontmatter = source.slice(4, fence);
276
+ // Trim both edges: a body that opens with spaces would render as a Markdown
277
+ // code block in the harness's `<skill_instructions>` wrapper. Interior
278
+ // whitespace is preserved (it carries the document's structure).
279
+ const content = source.slice(fence + 4).trim();
280
+ const name = /^name:\s*(.*)$/m.exec(frontmatter)?.[1]?.trim() ?? '';
281
+ const description = /^description:\s*(.*)$/m.exec(frontmatter)?.[1]?.trim() ?? '';
282
+ if (!SKILL_NAME.test(name) || description === '' || content === '') return undefined;
283
+ return { name, description, content };
284
+ }
285
+
286
+ /**
287
+ * The runtime skill definition for `/autoplan`, or `undefined`.
288
+ *
289
+ * Shape is what `@deepseek-ai/dsh-skill`'s `register()` accepts: the body
290
+ * rides `content`, `source` is the display origin (this is a bundled provider,
291
+ * matching the harness's own `bundled` skills), and both invocation flags are
292
+ * on — a person can type `/autoplan`, and a model can load it through the
293
+ * `skill` tool when the user asks for "plan and implement in one shot".
294
+ */
295
+ function autoplanSkillDefinition() {
296
+ let text;
297
+ try {
298
+ text = readFileSync(AUTOPLAN_SKILL_URL, 'utf8');
299
+ } catch {
300
+ return undefined;
301
+ }
302
+ const parsed = parseSkillMarkdown(text);
303
+ if (parsed === undefined) return undefined;
304
+ return {
305
+ name: parsed.name,
306
+ description: parsed.description,
307
+ content: parsed.content,
308
+ source: 'bundled',
309
+ invocation: { modelInvocable: true, userInvocable: true },
310
+ };
311
+ }
312
+
245
313
  // ---------------------------------------------------------------------------
246
314
  // Config
247
315
  // ---------------------------------------------------------------------------
@@ -685,6 +753,54 @@ function planActive(ctx, agent) {
685
753
  return projected === undefined ? false : projected;
686
754
  }
687
755
 
756
+ /**
757
+ * The agent's model-selection surface, or `undefined`.
758
+ *
759
+ * DSH 0.2.x replaced the request-time model rewrite with an explicit selection
760
+ * API: `agent.model.select()` assigns the route for the next step whose
761
+ * preparation has not begun, while `agent/request` must preserve the route the
762
+ * step already fixed — proposing another one aborts the turn. Feature-detecting
763
+ * the surface keeps the 0.1.x rewrite path working on harnesses that never
764
+ * shipped it.
765
+ */
766
+ function selectionModelOf(agent) {
767
+ const model = probe(() => agent?.model);
768
+ return model !== undefined && typeof model.select === 'function' ? model : undefined;
769
+ }
770
+
771
+ /** Whether two route selections name the same provider, model and effort. */
772
+ function sameSelection(left, right) {
773
+ if (left === undefined || right === undefined) return false;
774
+ return left.provider === right.provider
775
+ && left.model === right.model
776
+ && (left.reasoningEffort ?? undefined) === (right.reasoningEffort ?? undefined);
777
+ }
778
+
779
+ /**
780
+ * The planning skill named by a batch of pending user messages, or `undefined`.
781
+ *
782
+ * The inbox is the only place a new turn's text exists before its first step is
783
+ * prepared — the harness appends `user/message` only when the step admits it,
784
+ * which is after the route is fixed. Scanning the pending messages is therefore
785
+ * what lets a `/grilling` gesture reach the FIRST request of its turn on a
786
+ * harness that fixes the route at step preparation. Recognition uses the
787
+ * harness's own `/name` grammar and only the configured planning skills match.
788
+ */
789
+ function planningSkillInMessages(messages, wanted) {
790
+ if (wanted.length === 0) return undefined;
791
+ for (const message of Array.isArray(messages) ? messages : []) {
792
+ if (message?.source?.kind !== 'user') continue;
793
+ for (const block of Array.isArray(message.content) ? message.content : []) {
794
+ if (block?.type !== 'text' || typeof block.text !== 'string') continue;
795
+ for (const match of block.text.matchAll(SKILL_GESTURE)) {
796
+ const name = match[2];
797
+ if (name !== undefined && wanted.includes(name)) return name;
798
+ }
799
+ }
800
+ }
801
+ return undefined;
802
+ }
803
+
688
804
  /** Find the delegating parent of a child session. */
689
805
  function findParent(ctx, childId) {
690
806
  return probe(() => {
@@ -943,6 +1059,17 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
943
1059
  * choice and stop managing that child permanently.
944
1060
  */
945
1061
  const managerApplied = new Map();
1062
+
1063
+ /**
1064
+ * session id -> route key this manager last assigned through
1065
+ * `agent.model.select()` (the DSH 0.2.x selection path).
1066
+ *
1067
+ * A selected route is recorded in the session log exactly like a composer
1068
+ * pick, so ownership has to be remembered here: without it the manager would
1069
+ * read back its own selection as a hand-picked model and stop routing the
1070
+ * session under `hybrid`.
1071
+ */
1072
+ const managerSelected = new Map();
946
1073
  const roundRobin = new Map();
947
1074
  /** child session id -> in-flight single-child lookup, to coalesce bursts */
948
1075
  const childLookups = new Map();
@@ -966,6 +1093,13 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
966
1093
  */
967
1094
  let toolsService;
968
1095
 
1096
+ /**
1097
+ * Whether the bundled `/autoplan` runtime skill was registered. Surfaced by
1098
+ * the `routes` action so an operator can tell "the skill exists" from "this
1099
+ * composition has no skills service, or the shipped SKILL.md is broken".
1100
+ */
1101
+ let autoplanRegistered = false;
1102
+
969
1103
  /**
970
1104
  * Latest update-check outcome. Statuses: `idle` (not yet checked), `checking`,
971
1105
  * `ok` (up to date), `available` (a newer release exists), `error` (the check
@@ -1064,7 +1198,8 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
1064
1198
  async function onPreStep(payload, next) {
1065
1199
  const decision = await next();
1066
1200
  try {
1067
- const id = typeof payload?.agent?.id === 'string' ? payload.agent.id : undefined;
1201
+ const agent = payload?.agent;
1202
+ const id = typeof agent?.id === 'string' ? agent.id : undefined;
1068
1203
  if (id !== undefined && decision?.kind !== 'reject') {
1069
1204
  for (const batch of [payload?.messages, decision?.messages]) {
1070
1205
  if (!Array.isArray(batch)) continue;
@@ -1073,6 +1208,27 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
1073
1208
  }
1074
1209
  }
1075
1210
  }
1211
+ // On a harness that fixes the route at step preparation, keep the
1212
+ // selection correct from step to step: this call lands on the NEXT step,
1213
+ // because the current step's route was read before this hook ran. The
1214
+ // claim-boundary selection in `onInboxClaimed` is what covers the request
1215
+ // that is about to run.
1216
+ if (agent !== undefined && decision?.kind !== 'reject'
1217
+ && selectionModelOf(agent) !== undefined && config.enabled) {
1218
+ const isSubagent = probe(() => agent.session?.header?.origin === 'subagent') === true;
1219
+ if (isSubagent) {
1220
+ const facts = catalog.get(agent.id);
1221
+ if (facts !== undefined) {
1222
+ applySelection(agent, classifySubagent(facts.label), undefined, facts.label, true);
1223
+ }
1224
+ } else {
1225
+ const plan = planActive(ctx, agent);
1226
+ const skill = plan ? undefined : planningSkillFor(agent);
1227
+ const trigger = skill === undefined ? (plan ? 'plan-mode' : 'main') : `skill:${skill}`;
1228
+ noteTopTrigger(agent, trigger);
1229
+ applySelection(agent, plan || skill !== undefined ? 'planning' : 'main', trigger, undefined, false);
1230
+ }
1231
+ }
1076
1232
  } catch {
1077
1233
  // Observe-only: a hostile message shape must never fail the step.
1078
1234
  }
@@ -1131,6 +1287,184 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
1131
1287
  return { route: models[at], commit() {} };
1132
1288
  }
1133
1289
 
1290
+ // -- model selection (DSH 0.2.x) ------------------------------------------
1291
+
1292
+ /**
1293
+ * Whether the agent's current selection was recorded by somebody else.
1294
+ *
1295
+ * A route the manager selected is its own; a route equal to the agent's
1296
+ * creation options is the deployment default (or the inherited parent route),
1297
+ * which the manager is allowed to replace. Anything else is a recorded choice
1298
+ * — a composer pick, a resume override, an explicit child route — and
1299
+ * `hybrid` leaves it alone, exactly when it is neither manager-owned nor the
1300
+ * deployment default.
1301
+ */
1302
+ function selectionIsForeign(agent, current) {
1303
+ if (current === undefined) return false;
1304
+ if (managerSelected.get(agent.id) === routeKey(current)) return false;
1305
+ const options = probe(() => agent?.options);
1306
+ if (options !== undefined && options.provider === current.provider && options.model === current.model) return false;
1307
+ return true;
1308
+ }
1309
+
1310
+ /**
1311
+ * The hybrid gate for a subagent's current route.
1312
+ *
1313
+ * Mirrors the request-path rule the 0.1.x engine implements: a child is
1314
+ * routed when the route is manager-owned or provably inherited from the
1315
+ * delegating parent, and respected when it names a route nobody can prove was
1316
+ * inherited (an explicit child choice, or unresolvable lineage).
1317
+ */
1318
+ function childRouteIsInherited(agent, current) {
1319
+ if (current === undefined) return true;
1320
+ if (managerSelected.get(agent.id) === routeKey(current)) return true;
1321
+ const previous = usage.get(agent.id);
1322
+ if (previous?.applied === true
1323
+ && previous.provider === current.provider
1324
+ && previous.model === current.model) return true;
1325
+ const parent = findParent(ctx, agent.id);
1326
+ const parentRoute = parent === undefined ? undefined : effectiveRouteOf(parent);
1327
+ if (parentRoute === undefined) return false;
1328
+ return parentRoute.provider === current.provider && parentRoute.model === current.model;
1329
+ }
1330
+
1331
+ /** Whether `hybrid` permits replacing the agent's current route with `route`. */
1332
+ function selectionAllowed(agent, current, isSubagent) {
1333
+ if (config.strategy.mode !== 'hybrid') return true;
1334
+ if (!isSubagent) return !selectionIsForeign(agent, current);
1335
+ return childRouteIsInherited(agent, current);
1336
+ }
1337
+
1338
+ /**
1339
+ * Assign a role's route through `agent.model.select()`.
1340
+ *
1341
+ * This is the only legal way to change a model on DSH 0.2.x: the loop fixes
1342
+ * provider/model/reasoningEffort at step preparation and rejects an
1343
+ * `agent/request` that proposes another route. Selection applies to the next
1344
+ * step whose preparation has not begun, so callers run it at `turn/start`
1345
+ * (before the first step) and at `agent/pre-step` (for the step after the one
1346
+ * in flight). Returns whether a selection was recorded; every failure is
1347
+ * contained.
1348
+ */
1349
+ function applySelection(agent, role, trigger, label, isSubagent) {
1350
+ const model = selectionModelOf(agent);
1351
+ if (model === undefined || !config.enabled) return false;
1352
+ try {
1353
+ if (config.strategy.mode === 'advisory') return false;
1354
+ const candidate = routeCandidate(role, agent.id);
1355
+ if (candidate === undefined) return false;
1356
+ const route = candidate.route;
1357
+ const current = probe(() => model.current());
1358
+ if (!selectionAllowed(agent, current, isSubagent)) {
1359
+ if (!isSubagent && current !== undefined) {
1360
+ log('info', `session ${shortId(agent.id)} keeps ${current.provider}/${current.model}: `
1361
+ + 'a hand-picked model is respected under hybrid');
1362
+ }
1363
+ return false;
1364
+ }
1365
+ if (sameSelection(current, route)) {
1366
+ managerSelected.set(agent.id, routeKey(route));
1367
+ return false;
1368
+ }
1369
+ model.select({
1370
+ provider: route.provider,
1371
+ model: route.model,
1372
+ ...(route.reasoningEffort === undefined ? {} : { reasoningEffort: route.reasoningEffort }),
1373
+ });
1374
+ candidate.commit();
1375
+ managerSelected.delete(agent.id);
1376
+ managerSelected.set(agent.id, routeKey(route));
1377
+ while (managerSelected.size > MANAGER_APPLIED_LIMIT) {
1378
+ const oldest = managerSelected.keys().next().value;
1379
+ if (oldest === undefined) break;
1380
+ managerSelected.delete(oldest);
1381
+ }
1382
+ log('info', `selected ${route.provider}/${route.model} for ${shortId(agent.id)} (${role}) `
1383
+ + `before step preparation${trigger === undefined ? '' : ` — ${trigger}`}`);
1384
+ return true;
1385
+ } catch (error) {
1386
+ log('warn', `model selection skipped: ${error?.message ?? error}`);
1387
+ return false;
1388
+ }
1389
+ }
1390
+
1391
+ /**
1392
+ * One line describing how this harness accepts a route change.
1393
+ *
1394
+ * The two supported contracts differ enough that an operator has to be able
1395
+ * to tell which one is in force: 0.1.x rewrites the `agent/request` proposal,
1396
+ * 0.2.x fixes the route at step preparation and only accepts
1397
+ * `agent.model.select()` before it. Capability is read from the live agents,
1398
+ * so this reports what the running composition actually does.
1399
+ */
1400
+ function selectionTransport() {
1401
+ const agents = probe(() => ctx.get('agents'));
1402
+ const list = typeof agents?.list === 'function' ? probe(() => agents.list()) : undefined;
1403
+ const live = Array.isArray(list) ? list : [];
1404
+ if (live.length === 0) return 'not decided yet (no live agent has been observed)';
1405
+ if (live.some((agent) => selectionModelOf(agent) !== undefined)) {
1406
+ return 'agent.model.select() before step preparation (DSH ≥ 0.2)';
1407
+ }
1408
+ return 'agent/request route rewrite (DSH 0.1.x)';
1409
+ }
1410
+
1411
+ /** The live agent a session belongs to, or `undefined`. */
1412
+ function agentForSession(session) {
1413
+ const agents = probe(() => ctx.get('agents'));
1414
+ if (agents === undefined || session === undefined) return undefined;
1415
+ const direct = typeof agents.get === 'function' ? probe(() => agents.get(session.id)) : undefined;
1416
+ if (direct !== undefined) return direct;
1417
+ if (typeof agents.list !== 'function') return undefined;
1418
+ return probe(() => agents.list().find((candidate) => candidate.session === session));
1419
+ }
1420
+
1421
+ /**
1422
+ * Decide the role for a step that is claiming its input.
1423
+ *
1424
+ * `agent/inbox/claimed` is the one moment that beats the route fix without
1425
+ * fighting it: the loop's `preStep()` claims the batch first and reads
1426
+ * `agent.model.current()` straight after, and the claim notifications are
1427
+ * emitted outside any session append — so a selection made here is accepted
1428
+ * and lands on the step that is about to run. (`session/event` cannot do
1429
+ * this: its listeners run inside the append that is being published, where a
1430
+ * nested append is refused as reentrant.)
1431
+ *
1432
+ * The claimed message is what names the intent — the `/grilling` gesture, or
1433
+ * the plain prompt that leaves the session on `main` — so this is also where
1434
+ * a turn's FIRST request gets its role. Everything is wrapped: a selection
1435
+ * hook must never fail a step.
1436
+ */
1437
+ function onInboxClaimed(payload) {
1438
+ try {
1439
+ if (!config.enabled) return;
1440
+ const agent = payload?.agent;
1441
+ const message = payload?.message;
1442
+ if (agent === undefined || selectionModelOf(agent) === undefined) return;
1443
+ const isSubagent = probe(() => agent.session?.header?.origin === 'subagent') === true;
1444
+ if (isSubagent) {
1445
+ const facts = catalog.get(agent.id);
1446
+ // The label only exists behind an async listing. A child whose facts are
1447
+ // not cached yet runs its first step on the inherited route; the
1448
+ // pre-step hook then corrects it from the second step on. The eager
1449
+ // lookup in `subagent/start` usually wins that race.
1450
+ if (facts !== undefined) {
1451
+ applySelection(agent, classifySubagent(facts.label), undefined, facts.label, true);
1452
+ }
1453
+ return;
1454
+ }
1455
+ const plan = planActive(ctx, agent);
1456
+ const skill = plan
1457
+ ? undefined
1458
+ : (planningSkillFor(agent)
1459
+ ?? planningSkillInMessages([message], config.strategy.planningSkills));
1460
+ const trigger = skill === undefined ? (plan ? 'plan-mode' : 'main') : `skill:${skill}`;
1461
+ noteTopTrigger(agent, trigger);
1462
+ applySelection(agent, plan || skill !== undefined ? 'planning' : 'main', trigger, undefined, false);
1463
+ } catch {
1464
+ /* observe-only at the claim boundary */
1465
+ }
1466
+ }
1467
+
1134
1468
  /**
1135
1469
  * Which role owns a delegated child, from its delegation label.
1136
1470
  *
@@ -1325,6 +1659,34 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
1325
1659
  return resolved;
1326
1660
  }
1327
1661
 
1662
+ // DSH 0.2.x fixes provider/model/reasoningEffort at step preparation and
1663
+ // aborts the turn when this waterfall proposes another route. Routing
1664
+ // therefore happens through `agent.model.select()` at `turn/start` and
1665
+ // `agent/pre-step`; here the manager only records what the step fixed and
1666
+ // returns it untouched.
1667
+ if (selectionModelOf(agent) !== undefined) {
1668
+ const candidate = routeCandidate(role, agent.id);
1669
+ const matches = managerSelected.get(agent.id) === routeKey(resolved)
1670
+ || (candidate !== undefined
1671
+ && candidate.route.provider === resolved.provider
1672
+ && candidate.route.model === resolved.model);
1673
+ remember(agent.id, {
1674
+ role,
1675
+ trigger,
1676
+ label,
1677
+ isSubagent,
1678
+ provider: resolved.provider,
1679
+ model: resolved.model,
1680
+ reasoningEffort: resolved.reasoningEffort,
1681
+ reason: matches
1682
+ ? 'step route selected before preparation'
1683
+ : 'step route fixed by the session',
1684
+ applied: matches,
1685
+ parentId: catalog.get(agent.id)?.parentId,
1686
+ });
1687
+ return resolved;
1688
+ }
1689
+
1328
1690
  // Record the attempt group, so the failover budget is per (turn, step).
1329
1691
  // `agent/request` re-fires for every attempt of the same step, so this
1330
1692
  // resets only when the step actually changes.
@@ -1500,6 +1862,28 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
1500
1862
 
1501
1863
  const from = models[failedAt];
1502
1864
  const to = models[nextIndex];
1865
+ // DSH 0.2.x fixes the route at step preparation, so a retry of THIS step
1866
+ // always reuses the failed model. Select the next route instead: it is
1867
+ // what the next request will use, and this step ends with its failure
1868
+ // rather than retrying a model that is already known to be down.
1869
+ const model = selectionModelOf(agent);
1870
+ if (model !== undefined) {
1871
+ try {
1872
+ model.select({
1873
+ provider: to.provider,
1874
+ model: to.model,
1875
+ ...(to.reasoningEffort === undefined ? {} : { reasoningEffort: to.reasoningEffort }),
1876
+ });
1877
+ managerSelected.delete(agent.id);
1878
+ managerSelected.set(agent.id, routeKey(to));
1879
+ } catch (error) {
1880
+ log('warn', `failover could not select the next route: ${error?.message ?? error}`);
1881
+ }
1882
+ log('warn', `failover: ${role} ${from.provider}/${from.model} failed (${failure.code}); `
1883
+ + `the step route is fixed at preparation, so nothing is retried — the next request uses `
1884
+ + `${to.provider}/${to.model} (${budget.switches}/${MAX_SWITCHES_PER_STEP} this step)`);
1885
+ return undefined;
1886
+ }
1503
1887
  log('warn', `failover: ${role} ${from.provider}/${from.model} failed (${failure.code}); `
1504
1888
  + `re-running the step on ${to.provider}/${to.model} `
1505
1889
  + `(${budget.switches}/${MAX_SWITCHES_PER_STEP} switches this step)`);
@@ -2032,6 +2416,14 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
2032
2416
  : `${config.strategy.planningSkills.join(', ')} — a top-level session that invoked one routes as `
2033
2417
  + 'planning for the rest of the session, like plan mode'}`,
2034
2418
  '',
2419
+ `Autoplan skill: ${autoplanRegistered
2420
+ ? 'registered — `/autoplan` plans on the planning tier and implements on `main` '
2421
+ + 'without an approval gate'
2422
+ : 'not registered (no skills service in this composition, or skills/autoplan/SKILL.md '
2423
+ + 'is missing or invalid in this install)'}`,
2424
+ '',
2425
+ `Routing transport: ${selectionTransport()}`,
2426
+ '',
2035
2427
  allowListBlock(),
2036
2428
  '',
2037
2429
  visionBlock,
@@ -2310,6 +2702,15 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
2310
2702
  * the manager off; the missing registration is logged at apply time.
2311
2703
  */
2312
2704
  function selectionWasExplicit(agent) {
2705
+ // On DSH 0.2.x a selection is a durable `model/selection` event regardless
2706
+ // of who wrote it, so the durable fold alone cannot tell a composer pick
2707
+ // from a route the manager itself selected. Ownership lives in
2708
+ // `managerSelected`: a route the manager does not own and that differs from
2709
+ // the agent's creation route is a hand-picked one.
2710
+ const model = selectionModelOf(agent);
2711
+ if (model !== undefined) {
2712
+ return selectionIsForeign(agent, probe(() => model.current()));
2713
+ }
2313
2714
  if (projections === undefined || typeof projections.stateOf !== 'function') return false;
2314
2715
  const state = probe(() => projections.stateOf(agent.session, SELECTION_PROJECTION_KEY));
2315
2716
  return state?.explicit === true;
@@ -2338,13 +2739,31 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
2338
2739
  stepSwitches.delete(id);
2339
2740
  liveSkills.delete(id);
2340
2741
  topTriggers.delete(id);
2742
+ managerSelected.delete(id);
2341
2743
  });
2342
2744
 
2745
+ // Claim-boundary selection (DSH 0.2.x): the loop claims a step's input and
2746
+ // only then reads `agent.model.current()`, and the claim notifications are
2747
+ // emitted outside any session append — the one moment a role change can
2748
+ // reach the request that is about to run.
2749
+ ctx.on('agent/inbox/claimed', onInboxClaimed);
2750
+
2343
2751
  // Resolve a newly published child's label immediately, and targeted rather
2344
2752
  // than by sweeping every live agent.
2345
2753
  ctx.on('subagent/start', (info) => {
2346
2754
  const childId = info?.id;
2347
- if (childId !== undefined) void lookupChild(childId).catch(() => {});
2755
+ if (childId === undefined) return;
2756
+ void lookupChild(childId).then(() => {
2757
+ // DSH 0.2.x: the child's route has to be selected before its first
2758
+ // step is prepared, and the label only exists behind that async
2759
+ // listing. If this loses the race, the pre-step hook corrects the
2760
+ // route from the child's second step.
2761
+ const agent = agentForSession({ id: childId });
2762
+ const facts = catalog.get(childId);
2763
+ if (agent !== undefined && facts !== undefined) {
2764
+ applySelection(agent, classifySubagent(facts.label), undefined, facts.label, true);
2765
+ }
2766
+ }).catch(() => {});
2348
2767
  });
2349
2768
 
2350
2769
  // A volatile-only Settings edit is committed in place: the loader returns
@@ -2521,6 +2940,38 @@ function createEngine(initialConfig, ctx, log, rawConfig) {
2521
2940
  log('warn', `system prompt section not registered: ${error?.message ?? error}`);
2522
2941
  }
2523
2942
  });
2943
+
2944
+ // The bundled `/autoplan` skill. Registration is a workflow concern, not
2945
+ // routing: it is deliberately independent of `config.enabled`, because a
2946
+ // manager that is observing only still ships the plan-then-implement
2947
+ // gesture, it simply stops moving the planning fork onto another model.
2948
+ // A composition without the skills service never runs this callback at
2949
+ // all, and every failure inside degrades to a warning.
2950
+ ctx.inject(['skills'], (scoped) => {
2951
+ try {
2952
+ const skills = scoped?.skills;
2953
+ if (skills === undefined || typeof skills.register !== 'function') {
2954
+ log('warn', 'the skills service is present but exposes no register(); /autoplan is unavailable');
2955
+ return;
2956
+ }
2957
+ const register = () => {
2958
+ const definition = autoplanSkillDefinition();
2959
+ if (definition === undefined) {
2960
+ log('warn', '/autoplan skill not registered: skills/autoplan/SKILL.md is missing or invalid');
2961
+ return () => {};
2962
+ }
2963
+ const dispose = skills.register(definition);
2964
+ autoplanRegistered = true;
2965
+ log('info', `registered the /autoplan skill — ${definition.description}`);
2966
+ return typeof dispose === 'function' ? dispose : () => {};
2967
+ };
2968
+ if (typeof scoped.effect === 'function') scoped.effect(register);
2969
+ else register();
2970
+ } catch (error) {
2971
+ autoplanRegistered = false;
2972
+ log('warn', `/autoplan skill not registered: ${error?.message ?? error}`);
2973
+ }
2974
+ });
2524
2975
  }
2525
2976
 
2526
2977
  // Boot diagnostic: tell the operator about role routes the delegation tool
@@ -2618,6 +3069,11 @@ export {
2618
3069
  profileHint,
2619
3070
  delegationPolicyText,
2620
3071
  skillNamesOfEvent,
3072
+ parseSkillMarkdown,
3073
+ autoplanSkillDefinition,
3074
+ selectionModelOf,
3075
+ sameSelection,
3076
+ planningSkillInMessages,
2621
3077
  DEFAULT_PLANNING_KEYWORDS,
2622
3078
  DEFAULT_PLANNING_SKILLS,
2623
3079
  DEFAULT_VISION_KEYWORDS,
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@darkbear9494/dsh-model-manager",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
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, 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, 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
+ "autoplan",
10
11
  "deepseek-harness",
11
12
  "cordis",
12
13
  "model-routing",
@@ -34,7 +35,7 @@
34
35
  },
35
36
  "meta": {
36
37
  "title": "Model manager",
37
- "description": "Assign models to planning, execution, vision and main roles, see which model each subagent used, auto-delegate, and get update notices."
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."
38
39
  },
39
40
  "exports": {
40
41
  ".": "./lib/index.js",
@@ -47,6 +48,7 @@
47
48
  "client.js",
48
49
  "locale/*.json",
49
50
  "cordis.patch.yml",
51
+ "skills",
50
52
  "README.md"
51
53
  ],
52
54
  "peerDependencies": {
@@ -0,0 +1,34 @@
1
+ ---
2
+ name: autoplan
3
+ description: Plan on the stronger planning tier, then implement immediately on the main tier without an approval gate. Use when the user invokes /autoplan, or asks to plan-and-implement in one shot instead of reviewing the plan first.
4
+ ---
5
+
6
+ Work the request in two phases, back to back. Do not pause between them.
7
+
8
+ ## Phase 1 — Plan (planning tier)
9
+
10
+ Gather the facts you need first — files, commands, docs. Never ask the user for anything you can look up yourself.
11
+
12
+ Dispatch the plan design as one delegation:
13
+
14
+ - Call `subagent_fork` with the description `plan: design the implementation plan for <short task name>`. The `plan:` prefix routes this unit to the planning tier's more capable model, and the fork inherits this conversation, so the planner already has the full context.
15
+ - Ask it for a decision-complete plan: the goal and success criteria, the changes grouped by file or subsystem, schema/API/data-flow impact, edge cases and failure modes, the tests to add or run, and explicit assumptions where the request was ambiguous.
16
+ - If `subagent_fork` is not available to you, use `subagent` with the same `plan:` description and a self-contained prompt carrying every fact the planner needs.
17
+ - If you are already running as a delegated subagent, do not delegate again: write the plan yourself in a few lines and move on.
18
+
19
+ Do not ask the user to approve, review, or adjust the plan. Do not enter plan mode for this, and never route it through `exit_plan_mode` — the whole point is that implementation does not wait on sign-off.
20
+
21
+ If the delegation fails or comes back empty, retry once. If it still fails, write a short plan yourself and continue. Never stall waiting for a plan.
22
+
23
+ ## Phase 2 — Implement (main tier)
24
+
25
+ Start implementing the moment the plan comes back.
26
+
27
+ - Do not ask for confirmation or permission, and do not ask the user to choose between options you can decide yourself. Make the sensible choice, record the assumption, and carry on. The user can correct course on the result.
28
+ - Implement it yourself, or dispatch independent parts as plain (execution-tier) units per the active delegation policy. Label only image, screenshot, or OCR work with `vision:`.
29
+ - Follow the plan as written. Where reality forces a deviation, deviate minimally and note it.
30
+ - Keep the harness's normal safety surface: approval prompts for risky operations, sandbox limits, and destructive-operation confirmations are not part of what this skill skips. Only plan review is.
31
+
32
+ ## Finish
33
+
34
+ Report what was implemented, the checks or tests you ran and their results, any deviation from the plan, and the assumptions the plan made on the user's behalf.