@crewhaus/model-service 0.6.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/LICENSE +201 -0
- package/NOTICE +29 -0
- package/README.md +246 -0
- package/dist/index.d.ts +545 -0
- package/dist/index.js +522 -0
- package/dist/side-calls.d.ts +103 -0
- package/dist/side-calls.js +592 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
CrewHaus Factory
|
|
2
|
+
Copyright 2026 Max Meier
|
|
3
|
+
|
|
4
|
+
This product includes software developed by Max Meier
|
|
5
|
+
(operating as StudioMax — https://studiomax.io) and contributors.
|
|
6
|
+
|
|
7
|
+
The CrewHaus name and logo are trademarks of Max Meier. See
|
|
8
|
+
TRADEMARK.md for the use-of-marks policy.
|
|
9
|
+
|
|
10
|
+
================================================================
|
|
11
|
+
This product also includes the following third-party software,
|
|
12
|
+
licensed under their respective licenses. See the package's
|
|
13
|
+
license file for full terms.
|
|
14
|
+
|
|
15
|
+
[As of the launch, fill in the third-party software list. Common
|
|
16
|
+
ones likely to apply, depending on what packages actually ship:]
|
|
17
|
+
|
|
18
|
+
- Bun runtime (MIT)
|
|
19
|
+
- TypeScript (Apache-2.0)
|
|
20
|
+
- Zod (MIT)
|
|
21
|
+
- Anthropic TypeScript SDK (MIT)
|
|
22
|
+
- OpenAI TypeScript SDK (Apache-2.0)
|
|
23
|
+
- yaml (ISC)
|
|
24
|
+
- Various other npm packages — see package.json files
|
|
25
|
+
|
|
26
|
+
For the complete attribution, run:
|
|
27
|
+
bun run licenses
|
|
28
|
+
|
|
29
|
+
================================================================
|
package/README.md
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# @crewhaus/model-service
|
|
2
|
+
|
|
3
|
+
The **composition root for model routing** (0.6.0 design §2 stance 4, module
|
|
4
|
+
brief 308) — the `wireMemory` precedent applied to models. Every consumer of
|
|
5
|
+
the model-routing IR makes one stable call instead of hand-mirroring the
|
|
6
|
+
`runChatLoop` fields per emitter:
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { modelWiringFragmentFromIr, wireModels } from "@crewhaus/model-service";
|
|
10
|
+
import { runChatLoop } from "@crewhaus/runtime-core";
|
|
11
|
+
|
|
12
|
+
const routing = wireModels(modelWiringFragmentFromIr(ir.agent), {});
|
|
13
|
+
|
|
14
|
+
await runChatLoop({
|
|
15
|
+
model, instructions, tools,
|
|
16
|
+
...routing, // modelFallbacks / circuitBreaker / modelTiers / modelPool
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Before this package, ten emitters (cli, channel, managed, workflow, crew,
|
|
21
|
+
graph, pipeline, research, batch, browser) and two `crewhaus run` interpreter
|
|
22
|
+
sites each rendered the same four fields with a "keep the N copies in sync"
|
|
23
|
+
comment — and two of those copies had already drifted. Emitters now emit
|
|
24
|
+
through **one** renderer (typed IR in, one call out — Pillar 1), the
|
|
25
|
+
interpreter spreads **one** call, and runtime-core keeps receiving plain
|
|
26
|
+
options. Every later routing feature lands here, not in codegen.
|
|
27
|
+
|
|
28
|
+
## What lands when
|
|
29
|
+
|
|
30
|
+
| PR | This package gains |
|
|
31
|
+
|---|---|
|
|
32
|
+
| **8a** | `wireModels`, the fragment, and `renderModelWiringFields` — wrapping today's emitted routing fragments **byte-identically**. `runChatLoop` still resolves candidate adapters, opens the scoreboard and builds the `PolicyRouter` from these four options exactly as before. |
|
|
33
|
+
| **8b (this cut)** | the `Consult` / `Escalate` tools (`@crewhaus/tool-consult`) constructed under `strategy.model_directed` and returned as the `hybridTools` / `escalation` options; the Consult runner is a nested single-turn `runChatLoop` on a child run context whose model events are re-published on the parent bus (see below) |
|
|
34
|
+
| 9a–9d | per-candidate plans, the `preRoute` inputs, cascade wiring, the guide / shadow / committee side-call closures with their child buses |
|
|
35
|
+
| **9e** | `wireHybrid` — every runtime CLOSURE a pool declares, in one call — and its codegen twin `renderHybridWiringFields`, so a COMPILED bundle constructs them too instead of carrying the blob without the behaviour |
|
|
36
|
+
| **9f** | `HYBRID_FAMILIES_BY_SHAPE` — plan §11.3, the per-shape carry/emit/ignore matrix, in code — plus the `hybridFamilies` narrowing every emitter passes for its own shape, so the last four pool-bearing emitters (pipeline, research, batch, browser) wire the closures and a shape the table marks `—` for a family (today: `pipeline` × Consult / Escalate) constructs nothing for it on either path |
|
|
37
|
+
| 10 | candidate adapter resolution with per-profile chains and breakers, the scoreboard and priors, the router built with rules / classifier / eligibility, judge metering on the run bus |
|
|
38
|
+
|
|
39
|
+
## `wireModels(fragment, deps)`
|
|
40
|
+
|
|
41
|
+
### The fragment
|
|
42
|
+
|
|
43
|
+
The model-routing slice of one lowered model-bearing block — an `IrV0` agent,
|
|
44
|
+
a workflow step, a crew role, a graph node, or a pooled single-agent block.
|
|
45
|
+
Every such IR block satisfies the shape structurally, so callers pass the
|
|
46
|
+
block itself; `modelWiringFragmentFromIr(block)` picks the slice exactly as
|
|
47
|
+
the retired renderers read it (an empty `modelFallbacks` is absent).
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
type ModelWiringFragment = {
|
|
51
|
+
modelFallbacks?: readonly string[]; // spec model_fallbacks
|
|
52
|
+
circuitBreaker?: IrCircuitBreaker; // spec circuit_breaker
|
|
53
|
+
modelTiers?: IrModelTiers; // spec model_tiers
|
|
54
|
+
modelPool?: IrModelPool; // spec model_pool — carried WHOLE
|
|
55
|
+
};
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`modelPool` is the whole `IrModelPool`, not an allow-list of its keys. The
|
|
59
|
+
pool travels to runtime as one blob (`JSON.stringify(modelPool)` in a bundle,
|
|
60
|
+
the object itself in the interpreter), so every per-candidate setting, rule,
|
|
61
|
+
strategy and reward key the compiler lowers reaches `runChatLoop` verbatim.
|
|
62
|
+
The test suite pins one new key per level (profile → candidate → pool) as
|
|
63
|
+
observable on the option object, so a later PR cannot drop a key silently.
|
|
64
|
+
|
|
65
|
+
### The deps
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
type WireModelsDeps = {
|
|
69
|
+
modelOverride?: string; // a caller-forced primary (the interpreter's --model)
|
|
70
|
+
sessionName?: string; // label for the nested consult loops' sessions (<name>:consult)
|
|
71
|
+
sessionRootDir?: string; // where those loops persist session / event-log files
|
|
72
|
+
_consultAdapters?: ReadonlyMap<string, ProviderAdapter>; // test injection, keyed by spec model string
|
|
73
|
+
_consultRunner?: ConsultRunner; // test injection: a scripted side call
|
|
74
|
+
};
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
A flag-forced model is an explicit routing decision and the spec's chain,
|
|
78
|
+
tiers and pool were authored against the spec's primary, so under an override
|
|
79
|
+
they are dropped (and with the pool, its hybrid tools); `circuitBreaker` is
|
|
80
|
+
kept — declared alone it breaker-wraps whichever primary serves. The
|
|
81
|
+
adapters, the scoreboard root, the bus and the tool catalog join the deps as
|
|
82
|
+
the root starts constructing them.
|
|
83
|
+
|
|
84
|
+
### The output
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
type ModelWiringRunOptions = {
|
|
88
|
+
modelFallbacks?: readonly string[];
|
|
89
|
+
circuitBreaker?: IrCircuitBreaker;
|
|
90
|
+
modelTiers?: IrModelTiers;
|
|
91
|
+
modelPool?: IrModelPool;
|
|
92
|
+
hybridTools?: ReadonlyArray<RegisteredTool>; // Consult + Escalate, under strategy.model_directed
|
|
93
|
+
escalation?: EscalationLatch; // the Escalate tool's latch the loop consumes
|
|
94
|
+
};
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The `runChatLoop` options fragment under runtime-core's own option names.
|
|
98
|
+
Since PR 8b this package depends on `@crewhaus/runtime-core` (the Consult
|
|
99
|
+
runner is a nested `runChatLoop`), so the type is pinned assignable to
|
|
100
|
+
`Pick<RunChatLoopOptions, keyof ModelWiringRunOptions>` right in `src/` — a
|
|
101
|
+
rename or reshaping in runtime-core fails `tsc -b` here — and the cli's
|
|
102
|
+
`modelRoutingRunOptions` carries the same pin at the interpreter seam.
|
|
103
|
+
Spread-return-`{}`: an empty fragment yields `{}`, values are carried by
|
|
104
|
+
reference, keys come out in the order every emitter has always written them
|
|
105
|
+
(`MODEL_WIRING_KEYS`), followed by `HYBRID_WIRING_KEYS` when constructed.
|
|
106
|
+
|
|
107
|
+
## The model-directed pair (`strategy.model_directed: true`)
|
|
108
|
+
|
|
109
|
+
`wireModelDirected(pool, deps)` builds the two tools from
|
|
110
|
+
[`@crewhaus/tool-consult`](../tool-consult):
|
|
111
|
+
|
|
112
|
+
- the **roster** is the pool's enabled candidates (`enabled: false` never
|
|
113
|
+
becomes a Consult target);
|
|
114
|
+
- the **escalation target** is `strategy.cascade.escalate_to` resolved
|
|
115
|
+
against the roster (a tag, a profile, or a model string), else the
|
|
116
|
+
strongest candidate (first `routing.strongTag`-tagged, else the last
|
|
117
|
+
declared — the router's `escalation()` convention); `strategy.
|
|
118
|
+
max_escalations` (default 1) bounds the latch;
|
|
119
|
+
- the **Consult runner** (`buildConsultRunner`) runs the target through
|
|
120
|
+
`runChatLoop({ singleTurn: true, tools: [], sessionTarget: "consult",
|
|
121
|
+
modelRole: "consult" })` — never `adapter.stream` — on a **child**
|
|
122
|
+
`RunContext` whose `TraceEventBus` inherits the parent's trace, and whose
|
|
123
|
+
`model_request` / `model_response` events are re-published on the parent
|
|
124
|
+
bus under the parent's envelope with `role: "consult"`. That is what makes
|
|
125
|
+
the parent's cost-tracker price the call, its budget meter count it under
|
|
126
|
+
`budget.judge_share`, and its session mirror persist it. The child is
|
|
127
|
+
minted rather than shared because the singleTurn path mutates
|
|
128
|
+
`runContext.turnNumber`; sharing would inject phantom turns into the parent.
|
|
129
|
+
The reply text is returned raw — classification at TrustOrigin `"consult"`
|
|
130
|
+
(`classifyBoundary` + `tagContent`) happens exactly once, inside the tool.
|
|
131
|
+
|
|
132
|
+
runtime-core appends `hybridTools` to the effective tool list (first-party
|
|
133
|
+
wins a name collision) and consumes `escalation` at its next model call: the
|
|
134
|
+
rest of the turn is served by the request's target when it is a roster
|
|
135
|
+
candidate, else the strongest; the `model_route` line names the receipt. The
|
|
136
|
+
clean-prompt re-run (`runOneTurn(messages, { force })`) lands with the
|
|
137
|
+
cascade (PR 9c) on the same seam.
|
|
138
|
+
|
|
139
|
+
## The side calls (`strategy.guide` / `strategy.shadow` / `strategy.committee`) — PR 9d
|
|
140
|
+
|
|
141
|
+
`wireSideCalls(pool, deps)` builds the closures runtime-core consumes through
|
|
142
|
+
`RunChatLoopOptions.sideCalls` (plan §7.4, §7.6, §7.8); `wireModels` appends
|
|
143
|
+
the `sideCalls` key after the routing and hybrid keys when the pool's strategy
|
|
144
|
+
declares one of the three, and nothing otherwise. runtime-core owns each
|
|
145
|
+
closure's **lifecycle** (when it runs, what its text does, the `model_stage`
|
|
146
|
+
events, the scoreboard fold); this package owns the **model calls**, all of
|
|
147
|
+
which go through one nested runner, `runNestedSingleTurn`: a tool-less
|
|
148
|
+
`runChatLoop({ singleTurn: true })` on the target, on its own child
|
|
149
|
+
`RunContext` and child bus, with its `model_request` / `model_response`
|
|
150
|
+
re-published on the parent bus under the side call's `role` / `stage`, and
|
|
151
|
+
with `persistSession: false` (§16 Q6) — no child session file, no child event
|
|
152
|
+
log. The Consult runner rides the same runner.
|
|
153
|
+
|
|
154
|
+
- **guide** — a bounded call on the guide model (`max_tokens`, default 400;
|
|
155
|
+
`budget_usd` caps the guide's own spend inside the run) that reads the
|
|
156
|
+
executor's instructions and the text-only transcript and returns guidance;
|
|
157
|
+
runtime-core appends it as a `<guide>` block in the volatile system region
|
|
158
|
+
(after the continuity tail, after the cache marker), classified at
|
|
159
|
+
TrustOrigin `"consult"` and lineage-tagged. `every: first_turn` is
|
|
160
|
+
plan-execute: the block stays for the run and the plan is written to the
|
|
161
|
+
continuity plan store when `continuity.savePlan` is wired.
|
|
162
|
+
- **shadow** — the same request on the shadow candidate after the primary has
|
|
163
|
+
answered, graded blind with `judgePairwise` (order-swapped) against the
|
|
164
|
+
primary's text on `grade_with` (default: the strongest roster member);
|
|
165
|
+
returns only the verdict. runtime-core samples turns deterministically at
|
|
166
|
+
`sample_rate`, never changes the served text, and records both arms under
|
|
167
|
+
`shadow:<scope>/<band>` (`@crewhaus/routing-store`'s `shadowRouteKey`).
|
|
168
|
+
- **committee** (single-turn hosts only) — members run one after another
|
|
169
|
+
(never a parallel `runOneTurn`), `judgeSelect` (`@crewhaus/eval-judge`, two
|
|
170
|
+
order-controlled calls for any N) picks; on disagreement the
|
|
171
|
+
`escalate_on_disagreement` member answers as the tie-breaker, else the
|
|
172
|
+
strongest survivor's answer stands with the disagreement recorded; a failed
|
|
173
|
+
member is excluded, a lone survivor stands, none surviving throws (runtime-
|
|
174
|
+
core then runs the plain turn). The run's total cap gates every call the
|
|
175
|
+
committee makes: runtime-core gates the committee before it starts, and the
|
|
176
|
+
closure re-reads `SideCallTurnContext.budgetGate` before every member and
|
|
177
|
+
before the tie-breaker — past the cap the calls not yet made are excluded
|
|
178
|
+
(`skipped`, cause `budget`), never opened.
|
|
179
|
+
|
|
180
|
+
The side calls reach a bundle through `wireHybrid` (below), not through a
|
|
181
|
+
renderer of their own. Crew roles reach them through the orchestrator's
|
|
182
|
+
`composeSideCalls`.
|
|
183
|
+
|
|
184
|
+
## `wireHybrid(pool, deps)` — the closures, and how they reach a bundle (PR 9e)
|
|
185
|
+
|
|
186
|
+
Everything above — `Consult` / `Escalate`, the `policy: classifier` label
|
|
187
|
+
call, the guide / shadow / committee — is a **function**, so none of it can
|
|
188
|
+
ride the `JSON.stringify(modelPool)` blob every emitter writes. Until 9e that
|
|
189
|
+
meant a compiled bundle had the pool and none of the behaviour: no Consult, a
|
|
190
|
+
classifier pool routing heuristically with `reason: "classifier failed: no
|
|
191
|
+
classifier wired"`, and no guide outside the workflow / graph / crew hosts,
|
|
192
|
+
while `crewhaus run` had all three.
|
|
193
|
+
|
|
194
|
+
`wireHybrid(pool, deps)` is exactly what `wireModels` appends beyond the four
|
|
195
|
+
literal routing fields, factored out so a bundle can call it directly:
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
poolNeedsHybridWiring(pool) // strategy.model_directed | policy: classifier
|
|
199
|
+
// + classifier: | strategy.{guide,shadow,committee}
|
|
200
|
+
wireHybrid(pool, deps) // → { hybridTools?, escalation?, routeClassifier?, sideCalls? }
|
|
201
|
+
renderHybridWiringFields(fragment, indent, sessionName)
|
|
202
|
+
// → "\n<indent>...wireHybrid({…}, { sessionName: \"…\" }),"
|
|
203
|
+
HYBRID_WIRING_IMPORT // the one import line the six emitters render
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
The cli, channel-bot and managed emitters render the field beside the literal
|
|
207
|
+
routing fields; the workflow and graph emitters render it per pooled step /
|
|
208
|
+
node; the crew orchestrator calls `wireHybrid` per role activation. The
|
|
209
|
+
emitted `dist/package.json` lists `@crewhaus/model-service` because the
|
|
210
|
+
manifest is collected from the bundle's own import strings. Both the field and
|
|
211
|
+
the import gate on the same `poolNeedsHybridWiring` predicate, so a pool that
|
|
212
|
+
declares none of the closure-shaped keys renders nothing and imports nothing —
|
|
213
|
+
pre-0.6.0 bundles stay byte-identical.
|
|
214
|
+
|
|
215
|
+
## `renderModelWiringFields(fragment, indent)` — the codegen twin
|
|
216
|
+
|
|
217
|
+
What an emitter writes into a generated `runChatLoop({...})` call (or a crew
|
|
218
|
+
`RoleDefinition`): byte-for-byte the strings the ten emitters used to build
|
|
219
|
+
by hand —
|
|
220
|
+
|
|
221
|
+
```
|
|
222
|
+
\n<indent>modelFallbacks: ["a", "b"],
|
|
223
|
+
\n<indent>circuitBreaker: {"failureThreshold":2},
|
|
224
|
+
\n<indent>modelTiers: {"fast":"…","default":"…"},
|
|
225
|
+
\n<indent>modelPool: {"candidates":[…],"policy":"heuristic"},
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
— and `""` when the fragment declares nothing, so pre-existing bundles stay
|
|
229
|
+
byte-identical. Parsing the rendered fields back yields exactly
|
|
230
|
+
`wireModels(fragment, {})`; the test suite pins that equivalence, which is
|
|
231
|
+
what makes a compiled bundle and the interpreter one code path rather than a
|
|
232
|
+
mirror.
|
|
233
|
+
|
|
234
|
+
## Equivalence guarantees (the PR 8a refactor contract)
|
|
235
|
+
|
|
236
|
+
- Every existing spec compiles to a **byte-identical** bundle (the compiler's
|
|
237
|
+
`pre-continuity` pins plus the new per-shape `model-wiring` pins, generated
|
|
238
|
+
on the pre-refactor tree, all pass unchanged; the demos corpus was diffed
|
|
239
|
+
end to end when the PR landed).
|
|
240
|
+
- The `crewhaus run` interpreter spreads the same call at both of its
|
|
241
|
+
routing sites. One drift closed in passing: the single-turn (`serve`)
|
|
242
|
+
path previously dropped `circuitBreaker` under `--model` while the REPL
|
|
243
|
+
path kept it; both now keep it.
|
|
244
|
+
|
|
245
|
+
See the 0.6.0 design in `design/` and module brief 308 in
|
|
246
|
+
[crewhaus/docs](https://github.com/crewhaus/docs).
|