@miadi/connector 0.1.28 → 0.1.30
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 +11 -1
- package/STEERING.md +1 -1
- package/dist/approve.d.ts +3 -0
- package/dist/approve.js +46 -12
- package/dist/claude-models.d.ts +95 -0
- package/dist/claude-models.js +227 -0
- package/dist/factory-receipt.d.ts +8 -0
- package/dist/factory-receipt.js +1 -0
- package/dist/mission-status.d.ts +19 -0
- package/dist/mission-status.js +34 -1
- package/dist/model-preflight.d.ts +2 -2
- package/dist/model-preflight.js +2 -2
- package/dist/provider-policy.d.ts +1 -1
- package/dist/provider-policy.js +1 -1
- package/dist/providers.d.ts +6 -6
- package/dist/providers.js +26 -20
- package/dist/request-state.js +2 -0
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -0
- package/dist/source-words.d.ts +13 -0
- package/dist/source-words.js +21 -0
- package/dist/tools.js +84 -14
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -95,10 +95,16 @@ An idle seat takes the same inbox, and the connector types into no session that
|
|
|
95
95
|
|
|
96
96
|
Rollback: run the connector version before this one (`git checkout` of its `dist`, then `systemctl --user restart miadi-connector`). A steer to a Pi, Copilot or Codex session then answers `unsupported` again and nothing else changes. To stop an adapter, follow [`STEERING.md`](STEERING.md#rollback); a new session then has no `adapter.json` and answers `unsupported`. Envelopes already queued stay on disk, unread.
|
|
97
97
|
|
|
98
|
-
`request_authorized_run` may name a `provider` (`codex`, `pi`, `copilot`, `claude`). The connector verifies it is installed on the host before recording anything; an unknown or unavailable provider answers `provider_unavailable` and the mission stays unstarted. With no provider named,
|
|
98
|
+
`request_authorized_run` may name a `provider` (`codex`, `pi`, `copilot`, `claude`). The connector verifies it is installed on the host before recording anything; an unknown or unavailable provider answers `provider_unavailable` and the mission stays unstarted. With no provider named, a person's own default applies, then one the operator set for them, then Claude Code, and the result is named in the brief. A default that is missing or shows no sign-in leaves the mission unstarted, and no other provider stands in for it. Pi, Copilot and Codex otherwise run only when named. `provider_capabilities` (write tier) reports what the host has installed, the sign-in evidence, the preference order, and the read-only Jev check: `unconfigured` without `JEV_AI_API_KEY` or `TYPESAFE_API_KEY` in the connector's environment, else the models Jev lists for the key (no charge). A provider name inside a task's text selects nothing.
|
|
99
99
|
|
|
100
100
|
**Codex runs only on its requester's own choice (jgwill/Miadi#926).** The provider field is the caller's: the connector cannot read the chat, so `provider: "codex"` chooses nothing for the person. A run that names Codex is recorded, and its answer says it `needs_person_choice`. The approval page then shows no Approve button. Only the requester, signed in there with their own Miadi person token, can tick and send "Choose codex for this mission". That `provider_choice` record is bound to the request id, its version and its content hash, must be under 24 hours old when the request is approved, and covers that one mission. A revision makes it stale. A generic Approve, on the page or on a card, is refused as `provider_choice_required`, and so is a choice by any other person or by a service token. The requester can instead set their own policy at `/providers` so their requests may name Codex without a per-mission choice; that policy is theirs only and revisable. The check runs at request, revision, approval, and where the brief is written (approval and every rerun). The brief carries `provider_authorization` and `provider_choice` (or `provider_policy`), and the factory runner refuses to launch Codex for a connector brief without them. `request_authorized_run`, `revise_pending_request`, `mission_status`, `show_decisions` and `mission_model_preflight` show `provider_authorization`; after approval it is also in the request's `completion_receipt`, which `get_run_result` returns. A Codex launch without it is named on the mission and fails the preflight closed as `provider_not_authorized`. A brief the runner refuses goes to `queue/refused/` with its reason, and the request shows it. Other providers keep their regular policy, and nothing falls back to Codex. What this does not cover: anyone who can write `/srv/miadi/factory/queue` or the connector's state directory can forge a brief or a record (the folder's permissions are the boundary); a configured launcher that runs Codex behind a wrapper whose name does not say codex is trusted as configured; a brief to an existing session reaches only an idle Claude Code agent today, so it is not checked; and an agent that starts `codex` itself from inside its session is outside the connector's reach.
|
|
101
101
|
|
|
102
|
+
**Which Claude Code model a run launches on.** `request_authorized_run` and `propose_work` may name a `model`, and that model is used. It must be on the host's permitted list, and a model named with any other provider is refused, so a model never moves a mission to a provider nobody chose. With none named, Jev chooses among the permitted models once, when the run is approved. It is sent the task type and criticality (`task_type`, `criticality`; default `implementation`, `normal`) and the candidates, never task text, a mission id or a repository name, and its choice authorizes nothing. If Jev has no key, is down, abstains, answers below the 0.8 floor or breaks the answer contract, the launch uses the configured Claude Code model, and the receipt's `fallback_reasons` says why. Jev knows these models only through the fit notes in `claude-models.ts`, which are the Factory's reading of Anthropic's descriptions and not a measurement: `implementation` fits Sonnet, `file_relevance` and normal `review` fit Opus, `architecture_refactor` and anything `security_critical` fit Fable. Its confidence is uncalibrated. A request that fills no `task_type` counts as `implementation`, so it goes to Sonnet even where Claude Code's own setting says Opus.
|
|
103
|
+
|
|
104
|
+
A session already running keeps its model: Jev is not asked, and a named model fails the run rather than being ignored. A request recorded before this behaviour launches as it was approved. If Claude Code is missing or shows no sign-in when a run is approved, the run fails with no brief and can be run again. The brief carries `model` and `model_source`, and the factory runner passes `--model`; publish the runner first, because a runner older than 0.1.5 ignores it. `mission_status` shows the choice, its source, the flag, the model the session's own transcript says answered, read when asked, and whether they match. A mismatch or an old runner is a note, and nothing is re-run. A config directory is sign-in evidence only: only the transcript shows a launch worked.
|
|
105
|
+
|
|
106
|
+
`factory.json` narrows the list and sets the fallback: `"claudeModels": ["opus", "sonnet"]`, `"claudeDefaultModel": "opus"`. Without them every model in `claude-models.ts` is permitted, and the fallback is the `model` in Claude Code's own settings. A list that leaves that setting out wins over it, and the fallback is then the first listed. A name goes on that list after a real answer shows it: `claude -p "Reply with OK." --model <name> --output-format json` names the model that answered under `modelUsage`, and an unknown name exits 1.
|
|
107
|
+
|
|
102
108
|
`mission_model_preflight` (write tier) answers, for one mission, which provider and model fit its task type and criticality, and how that is known: contract `miadi.mission_model_preflight` v1, candidates with their configured default model, sign-in evidence (config directory only), quota `unknown`, policy eligibility, a review floor, and a recommendation or an abstention with reasons. Its `decider.source` is `static_fallback`, `jev` or `synthetic_fixture`. Jev is asked only with `consult_jev: true` and a key on the host; it is sent task type, criticality and candidates, never task text, mission id or repository, and its answer is advisory: uncalibrated, below 0.8 or outside the contract, the preflight abstains. A reported `launch` on another provider than the approved one answers `provider_mismatch` before anything is asked. It authorizes nothing. `bench/model-preflight-bench.mjs` compares the 0.1.12 baseline, the static preflight and Jev on synthetic scenarios; `bench/results/` keeps the runs.
|
|
103
109
|
|
|
104
110
|
### The mission standard
|
|
@@ -139,6 +145,10 @@ Earned 2026-11-06: 0.1.22 moved the card to `decisions-v2.html` and stopped serv
|
|
|
139
145
|
|
|
140
146
|
A decision is recorded once. An approved run that calls another service (a review operation, Deep Diver, an episode door, a steer) is written to the ledger as approved and running before the call, so a restart can never offer the request for a second approval; a run the connector was recording when it stopped reads as failed and may be run again. A decision whose run takes longer than `MIADI_CONNECTOR_DECISION_WAIT_MS` is answered as recorded and running, and the card reads `get_run_result` every 3 seconds until the outcome is in. The same decision sent again (a host retrying a call, a second click, the page form sent twice) answers with the first one's receipt, marked `replayed`, and runs nothing. A different decision is refused as `decision_conflict`, with where the request stands. When the host gives up on a call, the card reads where the request stands before it offers the buttons again.
|
|
141
147
|
|
|
148
|
+
**A person mentioned and a person on the record (jgwill/Miadi#962).** A person mentioned, by name or as a kind of user, holds nothing back: a spoken name is never a reason to withhold a source or to ask anyone. A person on the record, meaning filmed or with their own voice, words or screens shown, has a release agreed at the start of the production. Nothing but the owner's `withheld` registration holds a source back, and no code counts names. `request_participant_consent` is the door for a person on the record who has no release yet.
|
|
149
|
+
|
|
150
|
+
**An approved create sends the person's words (jgwill/Miadi#963).** `POST /api/reviews` carries `source: { title, description, boundaries }` from the `source_intent`: its own fields, or the `TITLE:`, `DESCRIPTION` and `Review boundaries:` lines of its intention. The review service uses them once `packages/review-service/prompts/261107-review-source-words.md` is applied in v0. Until then it ignores them, writes from the video alone, and the receipt says so (`source_words.title_taken: false`).
|
|
151
|
+
|
|
142
152
|
**A created review gets its transcript (jgwill/Miadi#925).** An approved `create` calls the review service, then reads the video's original-language YouTube captions with a local `uvx yt-dlp` and stores them on the review as `[mm:ss] text`, so an agent reads them through `fetch` and the factory's kind briefs find them with `miadi_review.py transcript`. No model is called for the transcript. The service answers an empty `POST /api/reviews/:id/transcript` by asking Gemini, so an empty one is never sent. `completion_receipt.transcript` says where it stands, and the card and the approval page say the same:
|
|
143
153
|
|
|
144
154
|
| outcome | meaning |
|
package/STEERING.md
CHANGED
|
@@ -80,7 +80,7 @@ What this keeps:
|
|
|
80
80
|
|
|
81
81
|
## Which provider a request runs on
|
|
82
82
|
|
|
83
|
-
A named provider is used, or the request is left unstarted. With none named, a person's own default from `/providers` applies, then one the operator set for them in `factory.json` (`person_default_provider`), then
|
|
83
|
+
A named provider is used, or the request is left unstarted. With none named, a person's own default from `/providers` applies, then one the operator set for them in `factory.json` (`person_default_provider`), then Claude Code. A default that is not installed or shows no sign-in leaves the mission unstarted and is never replaced. Codex is never a default (#926). The answer to `request_authorized_run`, the decision card and `mission_status` say whether a session of that provider could be corrected before anyone depends on it.
|
|
84
84
|
|
|
85
85
|
## Rollback
|
|
86
86
|
|
package/dist/approve.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { type RequestProjection } from "./request-state.js";
|
|
|
19
19
|
import type { DraftReviewService } from "./draft-review.js";
|
|
20
20
|
import { type RuntimeDeps } from "./runtime-steer.js";
|
|
21
21
|
import { type TmuxLike } from "./steer.js";
|
|
22
|
+
import { type ModelRoutingDeps } from "./claude-models.js";
|
|
22
23
|
import { type FetchCaptions } from "./captions.js";
|
|
23
24
|
import { type ProviderAuthorization } from "./provider-policy.js";
|
|
24
25
|
export { factoryDir, runBriefFile, readQueueState } from "./queue-state.js";
|
|
@@ -47,6 +48,8 @@ export interface ApprovalDeps {
|
|
|
47
48
|
steeringRuntime?: RuntimeDeps;
|
|
48
49
|
/** Asks the factory runner for a pass now. Its timer is the net (jgwill/Miadi#942). */
|
|
49
50
|
wakeRunner?: () => void;
|
|
51
|
+
/** How a run's Claude Code model is chosen when its brief is written (jgwill/Miadi#943). */
|
|
52
|
+
modelRouting?: ModelRoutingDeps;
|
|
50
53
|
/** Reads a video's captions for an approved create; without it a create stores no transcript (tests, other embedders). */
|
|
51
54
|
captions?: FetchCaptions;
|
|
52
55
|
/** The link a named person decides a consent request on; set where the decision secret is held. */
|
package/dist/approve.js
CHANGED
|
@@ -26,8 +26,10 @@ import { readSteerDelivery } from "./runtime-steer.js";
|
|
|
26
26
|
import { adapterOfRoute, readFactoryConfig } from "./steering-adapters.js";
|
|
27
27
|
import { steerAttempts, steerSession, tmuxAdapter } from "./steer.js";
|
|
28
28
|
import { contentHash, versionOf } from "./revisions.js";
|
|
29
|
+
import { modelAttributes, routeModel } from "./claude-models.js";
|
|
29
30
|
import { TRANSCRIPT_RETRY_MS, transcriptStep } from "./captions.js";
|
|
30
31
|
import { ReviewClient } from "./reviews.js";
|
|
32
|
+
import { sourceWordsOf } from "./source-words.js";
|
|
31
33
|
import { canReadReading } from "./reading/privacy.js";
|
|
32
34
|
import { authorizationReceipt, authorizeProvider, briefAttributes, CHOICE_TTL_MS, CODEX_POLICIES, isPersonId, needsPersonChoice, HOST_ORDER, providerPolicyOf, } from "./provider-policy.js";
|
|
33
35
|
export { factoryDir, runBriefFile, readQueueState } from "./queue-state.js";
|
|
@@ -98,12 +100,14 @@ function attr(v) {
|
|
|
98
100
|
function text(v) {
|
|
99
101
|
return String(v ?? "").replace(/<(?=[\/!?]?[A-Za-z])/g, "‹");
|
|
100
102
|
}
|
|
103
|
+
/** How a proposal launches, which the brief's attributes carry: not part of the work (jgwill/Miadi#943). */
|
|
104
|
+
const LAUNCH_FIELDS = new Set(["resolved_provider", "model", "model_routing", "task_type", "criticality"]);
|
|
101
105
|
/** The task a work proposal asks for, written from the proposal's own fields. */
|
|
102
106
|
export function proposalTask(record) {
|
|
103
107
|
const b = record.body;
|
|
104
108
|
const lines = ["Carry out this approved work proposal, within its own scope and constraints.", ""];
|
|
105
109
|
for (const [k, v] of Object.entries(b)) {
|
|
106
|
-
if (v === undefined || v === null || v === "")
|
|
110
|
+
if (v === undefined || v === null || v === "" || LAUNCH_FIELDS.has(k))
|
|
107
111
|
continue;
|
|
108
112
|
lines.push(`${k.replace(/_/g, " ")}: ${typeof v === "string" ? v : JSON.stringify(v)}`);
|
|
109
113
|
}
|
|
@@ -112,7 +116,8 @@ export function proposalTask(record) {
|
|
|
112
116
|
export function runBrief(record, approver, sessions, instructions, providerAttrs = {}, openAspects = []) {
|
|
113
117
|
const body = (record.kind === "work_proposal" ? { task: proposalTask(record) } : record.body);
|
|
114
118
|
// A request recorded before providers were resolved (jgwill/Miadi#893) names only what was asked (#926 review RR7).
|
|
115
|
-
|
|
119
|
+
// A work proposal resolves its provider too, and one recorded before that names none (jgwill/Miadi#943).
|
|
120
|
+
const provider = record.body.resolved_provider ?? body.provider;
|
|
116
121
|
const short = record.id.split(":")[1]?.slice(0, 8) ?? "run";
|
|
117
122
|
const to = body.session && sessions.includes(body.session) ? body.session : `new:${body.session ?? `connector-${yymmdd()}-${short}`}`;
|
|
118
123
|
// A new session opens where the request says, else where the factory runner's config says (defaultCwd): no host path here (#911).
|
|
@@ -233,7 +238,7 @@ export async function executeApproved(record, approver, deps, instructions) {
|
|
|
233
238
|
const f = deps.fetchImpl ?? fetch;
|
|
234
239
|
const b = record.body;
|
|
235
240
|
const reviewCall = (method, path, payload) => callReview(deps, method, path, payload);
|
|
236
|
-
const queueBrief = () => {
|
|
241
|
+
const queueBrief = async () => {
|
|
237
242
|
// Checked again where the brief is written: an approval, and every rerun of it (jgwill/Miadi#926).
|
|
238
243
|
const authorization = record.kind === "run_request" ? authorizeProvider(record, deps.ledger.all()) : undefined;
|
|
239
244
|
if (authorization && !authorization.authorized) {
|
|
@@ -249,14 +254,30 @@ export async function executeApproved(record, approver, deps, instructions) {
|
|
|
249
254
|
catch {
|
|
250
255
|
sessions = [];
|
|
251
256
|
}
|
|
252
|
-
|
|
257
|
+
// A session already running keeps its model: a named one cannot be honoured, and Jev is not asked (jgwill/Miadi#943).
|
|
258
|
+
const existingSession = record.kind === "run_request" && typeof b.session === "string" && sessions.includes(b.session);
|
|
259
|
+
if (existingSession && typeof b.model === "string" && b.model) {
|
|
260
|
+
return { outcome: "failed", message: `No brief was written. Session ${b.session} is already running on its own model, so ${b.model} cannot apply. Run it again once that session has ended, or make a new request with another session name.` };
|
|
261
|
+
}
|
|
262
|
+
const routing = await routeModel(record, { existingSession }, { factoryDir: deps.factoryDir, ...deps.modelRouting });
|
|
263
|
+
if (routing?.source === "unavailable") {
|
|
264
|
+
return { outcome: "failed", model_routing: routing, message: `No brief was written. ${routing.why}, and no other provider stands in for it. Run it again once it is back.` };
|
|
265
|
+
}
|
|
266
|
+
const { to, brief } = runBrief(record, approver, sessions, instructions, { ...(authorization ? briefAttributes(authorization) : {}), ...modelAttributes(routing) }, deps.draftReview?.stored(record)?.needs_revision ?? []);
|
|
253
267
|
const file = runBriefFile(record);
|
|
254
|
-
|
|
268
|
+
try {
|
|
269
|
+
writeFileSync(join(queue, file), brief, { flag: "wx", mode: 0o640 });
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
// The answer stays with the failure, so running it again does not ask Jev a second time.
|
|
273
|
+
return { outcome: "failed", ...(routing ? { model_routing: routing } : {}), message: error instanceof Error ? error.message : String(error) };
|
|
274
|
+
}
|
|
255
275
|
return {
|
|
256
276
|
outcome: "queued",
|
|
257
277
|
to,
|
|
258
278
|
file,
|
|
259
279
|
...(authorization ? { provider_authorization: authorizationReceipt(authorization) } : {}),
|
|
280
|
+
...(routing ? { model_routing: routing } : {}),
|
|
260
281
|
note: "The factory intake delivers queued briefs every 5 minutes.",
|
|
261
282
|
};
|
|
262
283
|
};
|
|
@@ -265,14 +286,24 @@ export async function executeApproved(record, approver, deps, instructions) {
|
|
|
265
286
|
return queueBrief();
|
|
266
287
|
case "review_operation_request": {
|
|
267
288
|
const url = b.video_id ? `https://youtu.be/${b.video_id}` : undefined;
|
|
289
|
+
// The person's title, description and boundaries go with the URL, so generation does not read the video alone (jgwill/Miadi#963).
|
|
290
|
+
const words = b.operation === "create" ? sourceWordsOf(current(deps.ledger.all()).find((x) => x.kind === "source_intent" && x.body.video_id === b.video_id)) : null;
|
|
268
291
|
const r = b.operation === "create"
|
|
269
|
-
? await reviewCall("POST", "/api/reviews", { url })
|
|
292
|
+
? await reviewCall("POST", "/api/reviews", { url, ...(words ? { source: words } : {}) })
|
|
270
293
|
: b.operation === "import_markdown"
|
|
271
294
|
? await reviewCall("POST", "/api/reviews/import", { url, markdown: b.markdown })
|
|
272
295
|
: b.operation === "new_version"
|
|
273
296
|
? await reviewCall("POST", `/api/reviews/${b.review_id}/versions`, b.transcript ? { transcript: b.transcript } : {})
|
|
274
297
|
: await reviewCall("POST", `/api/reviews/${b.review_id}/transcript`, { transcript: b.transcript });
|
|
275
|
-
const
|
|
298
|
+
const answeredTitle = r.response?.title;
|
|
299
|
+
const result = {
|
|
300
|
+
outcome: r.ok ? "done" : "failed",
|
|
301
|
+
operation: b.operation,
|
|
302
|
+
status: r.status,
|
|
303
|
+
response: r.response,
|
|
304
|
+
// Whether the service used them is read from its answer: a service without the field ignores it and writes its own title.
|
|
305
|
+
...(words ? { source_words: { sent: Object.keys(words), title_taken: words.title ? answeredTitle === words.title : null } } : {}),
|
|
306
|
+
};
|
|
276
307
|
if (b.operation !== "create" || !deps.captions)
|
|
277
308
|
return result;
|
|
278
309
|
const transcript = await transcriptStep({ video_id: b.video_id, review_id: await reviewLeftBy(deps, r.response, b.video_id), since: new Date().toISOString(), ...(b.transcript ? { supplied: b.transcript } : {}) }, transcriptIo(deps));
|
|
@@ -589,8 +620,10 @@ export async function decide(r, person, choice, deps, opts) {
|
|
|
589
620
|
}
|
|
590
621
|
/**
|
|
591
622
|
* The kinds whose run is done at once on this host (a brief written to the
|
|
592
|
-
* factory queue, an ending recorded)
|
|
593
|
-
*
|
|
623
|
+
* factory queue, an ending recorded), so nothing is written ahead of it. A run may
|
|
624
|
+
* ask Jev for its model first, up to 8 s: a restart then loses the click and that
|
|
625
|
+
* one call, and the request still waits for its decision. Every other approved run
|
|
626
|
+
* is recorded as running first.
|
|
594
627
|
*/
|
|
595
628
|
const RUNS_AT_ONCE = new Set(["run_request", "work_proposal", "session_completion_proposal"]);
|
|
596
629
|
/** What the receipt of a run the connector lost to a restart says (jgwill/Miadi#924). */
|
|
@@ -828,6 +861,7 @@ async function decideOnce(r, person, choice, deps, opts) {
|
|
|
828
861
|
export function isApprovable(r) {
|
|
829
862
|
return Boolean(r && APPROVABLE.has(r.kind));
|
|
830
863
|
}
|
|
864
|
+
const modelWords = (b) => (typeof b.model === "string" && b.model ? ` on ${b.model}` : b.model_routing ? " on the model Jev chooses" : "");
|
|
831
865
|
/** What approving a request does, in one sentence, for the card a person decides on. */
|
|
832
866
|
export function consequenceOf(r, authorization, records = [], steering) {
|
|
833
867
|
const b = r.body;
|
|
@@ -835,9 +869,9 @@ export function consequenceOf(r, authorization, records = [], steering) {
|
|
|
835
869
|
case "run_request":
|
|
836
870
|
return authorization && !authorization.authorized
|
|
837
871
|
? `Approving is refused until ${r.actor.name} chooses ${authorization.provider} for this mission on its approval page; approving does not choose it. Declining or sending it back stays possible.`
|
|
838
|
-
: `Approving queues a brief for the factory intake, which opens or reaches an agent session within minutes${authorization?.provider ? ` with ${authorization.provider}` : ""}.${!steering ? "" : !steering.steerable ? ` This session could not be corrected once it works: ${steering.reason ?? "no steering adapter."}` : steering.basis === "tested" ? " A person can correct it while it works." : " A person can correct it while it works, though this version of the agent has not been tested on it."}`;
|
|
872
|
+
: `Approving queues a brief for the factory intake, which opens or reaches an agent session within minutes${authorization?.provider ? ` with ${authorization.provider}` : ""}${modelWords(b)}.${!steering ? "" : !steering.steerable ? ` This session could not be corrected once it works: ${steering.reason ?? "no steering adapter."}` : steering.basis === "tested" ? " A person can correct it while it works." : " A person can correct it while it works, though this version of the agent has not been tested on it."}`;
|
|
839
873
|
case "work_proposal":
|
|
840
|
-
return
|
|
874
|
+
return `Approving starts the work: a brief written from the proposal and your instructions is queued for an agent session${typeof b.resolved_provider === "string" ? ` with ${b.resolved_provider}` : ""}${modelWords(b)}.`;
|
|
841
875
|
case "review_operation_request":
|
|
842
876
|
if (b.operation === "create") {
|
|
843
877
|
return `Approving calls the review service once to create the review, then stores the video's YouTube captions as its transcript, with no model call for the transcript. ${sourceWithheld(records, b.video_id)
|
|
@@ -1529,7 +1563,7 @@ ${option("per_mission_choice", "Codex runs only when I choose it for that missio
|
|
|
1529
1563
|
${option("selectable", "Codex may be named for my requests without a per-mission choice.")}
|
|
1530
1564
|
</fieldset>
|
|
1531
1565
|
<fieldset class="provider-defaults"><legend>When a request in my name names no provider</legend>
|
|
1532
|
-
${defaultOption(HOST_ORDER, "The
|
|
1566
|
+
${defaultOption(HOST_ORDER, "The Factory's default, which is Claude Code today")}
|
|
1533
1567
|
${defaultOption("pi", "Pi")}
|
|
1534
1568
|
${defaultOption("copilot", "Copilot")}
|
|
1535
1569
|
${defaultOption("claude", "Claude Code")}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { type Criticality, type JevAdapter, type ModelCandidate, type TaskType } from "./model-preflight.js";
|
|
2
|
+
import { type DiscoveryProbe, type ProviderAvailability, type ProviderId } from "./providers.js";
|
|
3
|
+
import type { ConnectorRecord } from "./records.js";
|
|
4
|
+
export declare const MODEL_ROUTING_CONTRACT = "miadi.claude_model_routing";
|
|
5
|
+
/** The body mark of a request whose model Jev chooses when its brief is written. */
|
|
6
|
+
export declare const JEV_WITHIN_CLAUDE = "jev_within_claude";
|
|
7
|
+
/** Typed into a shell by the factory runner, so one plain word. The runner checks it again. */
|
|
8
|
+
export declare const MODEL_NAME: RegExp;
|
|
9
|
+
export interface ClaudeModel {
|
|
10
|
+
id: string;
|
|
11
|
+
/** What the alias named when it was checked; the runner's receipt says what it names now. */
|
|
12
|
+
resolves_to: string;
|
|
13
|
+
/** What Jev reads: which task this model fits. The Factory's reading of Anthropic's model descriptions, not a measurement. */
|
|
14
|
+
capability_note: string;
|
|
15
|
+
}
|
|
16
|
+
/** Each answered a real prompt under `--model <id>` and under its full name. */
|
|
17
|
+
export declare const CLAUDE_MODELS: readonly ClaudeModel[];
|
|
18
|
+
/** A run under one name proves that name on that host that day, and says nothing of a sign-in elsewhere. */
|
|
19
|
+
export declare const CLAUDE_MODELS_VERIFIED: {
|
|
20
|
+
on: string;
|
|
21
|
+
cli: string;
|
|
22
|
+
how: string;
|
|
23
|
+
};
|
|
24
|
+
export interface ClaudeModelConfig {
|
|
25
|
+
/** The names a request may use and Jev may choose among (factory.json claudeModels; default: CLAUDE_MODELS), always with the fallback. */
|
|
26
|
+
permitted: string[];
|
|
27
|
+
/** The fallback: factory.json claudeDefaultModel, else Claude Code's own setting when the list allows it, else the first listed, else none. */
|
|
28
|
+
configured: string | null;
|
|
29
|
+
}
|
|
30
|
+
export declare function claudeModelConfig(dir?: string, modelOf?: (p: ProviderId) => string | null): ClaudeModelConfig;
|
|
31
|
+
/** A permitted name, or the full name of a permitted alias. */
|
|
32
|
+
export declare function isPermittedModel(model: string, permitted: string[]): boolean;
|
|
33
|
+
export type ModelPlan = {
|
|
34
|
+
fields: Record<string, string>;
|
|
35
|
+
} | {
|
|
36
|
+
refusal: {
|
|
37
|
+
code: "model_provider_mismatch" | "model_not_permitted";
|
|
38
|
+
message: string;
|
|
39
|
+
permitted: string[];
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
/** What a request records about its model, or why it may not be recorded. */
|
|
43
|
+
export declare function modelPlan(provider: string | null | undefined, model: string | null | undefined, permitted: string[]): ModelPlan;
|
|
44
|
+
/** One candidate per permitted model, the configured one first: Jev's options, and the preflight's. */
|
|
45
|
+
export declare function claudeModelCandidates(found: ProviderAvailability[], config: ClaudeModelConfig, base?: Pick<ModelCandidate, "eligible" | "policy_reason">): ModelCandidate[];
|
|
46
|
+
export type ModelSource = "request" | "jev" | "configured_fallback" | "cli_default" | "existing_session" | "unavailable";
|
|
47
|
+
export interface ModelRouting {
|
|
48
|
+
contract: typeof MODEL_ROUTING_CONTRACT;
|
|
49
|
+
version: 1;
|
|
50
|
+
decided_for: {
|
|
51
|
+
record: string;
|
|
52
|
+
version: number;
|
|
53
|
+
};
|
|
54
|
+
provider: "claude";
|
|
55
|
+
/** What the launch passes as --model. null: no flag, Claude Code's own default. */
|
|
56
|
+
model: string | null;
|
|
57
|
+
/** request: the request named it. configured_fallback and cli_default: Jev did not choose, and fallback_reasons says why. existing_session: the session keeps its model. unavailable: nothing launches, and why says so. */
|
|
58
|
+
source: ModelSource;
|
|
59
|
+
why?: string;
|
|
60
|
+
fallback_reasons?: string[];
|
|
61
|
+
task?: {
|
|
62
|
+
type: TaskType;
|
|
63
|
+
criticality: Criticality;
|
|
64
|
+
};
|
|
65
|
+
eligible?: string[];
|
|
66
|
+
decider?: Record<string, unknown>;
|
|
67
|
+
authorizes: false;
|
|
68
|
+
}
|
|
69
|
+
export interface ModelRoutingDeps {
|
|
70
|
+
/** A decider for tests. Absent, the environment's Jev key decides. */
|
|
71
|
+
adapter?: JevAdapter;
|
|
72
|
+
env?: NodeJS.ProcessEnv;
|
|
73
|
+
fetchImpl?: typeof fetch;
|
|
74
|
+
providersProbe?: DiscoveryProbe;
|
|
75
|
+
modelOf?: (p: ProviderId) => string | null;
|
|
76
|
+
factoryDir?: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The model of one mission's launch, or null when this mission's model is not routed: another
|
|
80
|
+
* provider, or a request recorded before routing. Asked at most once for a version: a brief written
|
|
81
|
+
* again for it (a rerun) keeps the answer, because a lost answer may already have been charged.
|
|
82
|
+
*/
|
|
83
|
+
export declare function routeModel(record: ConnectorRecord, opts: {
|
|
84
|
+
existingSession: boolean;
|
|
85
|
+
}, deps?: ModelRoutingDeps): Promise<ModelRouting | null>;
|
|
86
|
+
/** What the brief carries. */
|
|
87
|
+
export declare function modelAttributes(routing: ModelRouting | null): Record<string, string>;
|
|
88
|
+
/**
|
|
89
|
+
* The model that first answered in a session's own transcript, or null when none has yet. A launched
|
|
90
|
+
* session's id is its own, so anything answering in it is this launch. "<synthetic>" is Claude Code's
|
|
91
|
+
* own line, and a sidechain is a subagent: neither is the session's model.
|
|
92
|
+
*/
|
|
93
|
+
export declare function firstModelInTranscript(path: string): string | null;
|
|
94
|
+
/** Whether a model answered under a name: the name itself, or the alias of its family (opus answers as claude-opus-5-5). */
|
|
95
|
+
export declare function modelMatches(requested: string, observed: string): boolean;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which Claude Code model a new mission launches on (jgwill/Miadi#943).
|
|
3
|
+
*
|
|
4
|
+
* - A request that names a model launches on it. A model is a Claude Code model only: a request
|
|
5
|
+
* for another provider that names one is refused, so a model never moves a mission to a
|
|
6
|
+
* provider nobody chose.
|
|
7
|
+
* - A request that names none has Jev choose among the permitted models, once, when its brief is
|
|
8
|
+
* written. Jev sees the task type, the criticality and the candidates: no task text, mission id
|
|
9
|
+
* or repository. It authorizes nothing and never chooses a provider.
|
|
10
|
+
* - When Jev is unconfigured, down, abstains, answers below the floor or breaks the answer
|
|
11
|
+
* contract, the launch uses the configured Claude Code model and the receipt says why. It never
|
|
12
|
+
* falls back to another provider.
|
|
13
|
+
* - Jev knows only the fit notes below about these models. Told only what each model is, it answered
|
|
14
|
+
* below the floor on every task type (0.37 to 0.74, 2026-11-07); told what each fits, 0.96 to 1.
|
|
15
|
+
* So the notes carry the judgment, Jev applies them to the task, and its confidence is
|
|
16
|
+
* uncalibrated. A wrong note is changed here.
|
|
17
|
+
* - A request recorded before this carries no routing mark and launches as it was approved.
|
|
18
|
+
*
|
|
19
|
+
* The brief carries the choice as model= and model_source=. The factory runner passes it as
|
|
20
|
+
* --model and its receipt names the flag. Which model answered is read from the session's own
|
|
21
|
+
* transcript whenever someone asks (firstModelInTranscript, mission_status): that is the proof,
|
|
22
|
+
* and a session slow to answer is only not known yet.
|
|
23
|
+
*/
|
|
24
|
+
import { closeSync, openSync, readFileSync, readSync } from "node:fs";
|
|
25
|
+
import { join } from "node:path";
|
|
26
|
+
import { configuredModel, jevAdapter, modelPreflight, } from "./model-preflight.js";
|
|
27
|
+
import { discoverProviders, jevConfigOf, PROVIDERS } from "./providers.js";
|
|
28
|
+
import { factoryDir } from "./queue-state.js";
|
|
29
|
+
import { versionOf } from "./revisions.js";
|
|
30
|
+
export const MODEL_ROUTING_CONTRACT = "miadi.claude_model_routing";
|
|
31
|
+
/** The body mark of a request whose model Jev chooses when its brief is written. */
|
|
32
|
+
export const JEV_WITHIN_CLAUDE = "jev_within_claude";
|
|
33
|
+
/** Jev answered in 239 to 1321 ms when measured. A person pressing Approve waits at most this, and then the configured model launches. */
|
|
34
|
+
const ROUTING_TIMEOUT_MS = 8_000;
|
|
35
|
+
/** Typed into a shell by the factory runner, so one plain word. The runner checks it again. */
|
|
36
|
+
export const MODEL_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,79}$/;
|
|
37
|
+
/** Each answered a real prompt under `--model <id>` and under its full name. */
|
|
38
|
+
export const CLAUDE_MODELS = [
|
|
39
|
+
{ id: "opus", resolves_to: "claude-opus-5-5", capability_note: "The fit for a file_relevance task, which needs high recall, and for a review task at normal criticality." },
|
|
40
|
+
{ id: "sonnet", resolves_to: "claude-sonnet-5-5", capability_note: "The fit for an implementation task at normal criticality." },
|
|
41
|
+
{ id: "haiku", resolves_to: "claude-haiku-5-5", capability_note: "The cheapest model; it misses files on wide searches, so it fits none of these task types unless a task is trivially narrow." },
|
|
42
|
+
{ id: "fable", resolves_to: "claude-fable-5-1", capability_note: "The fit for an architecture_refactor task and for any security_critical task: the most capable model." },
|
|
43
|
+
];
|
|
44
|
+
/** A run under one name proves that name on that host that day, and says nothing of a sign-in elsewhere. */
|
|
45
|
+
export const CLAUDE_MODELS_VERIFIED = {
|
|
46
|
+
on: "2026-11-07",
|
|
47
|
+
cli: "2.1.319",
|
|
48
|
+
how: "claude -p <prompt> --model <name> --output-format json: modelUsage named the model that answered; an unknown name failed with exit 1",
|
|
49
|
+
};
|
|
50
|
+
const plainName = (v) => (typeof v === "string" && MODEL_NAME.test(v) ? v : null);
|
|
51
|
+
export function claudeModelConfig(dir = factoryDir(), modelOf = (p) => configuredModel(p)) {
|
|
52
|
+
let file = {};
|
|
53
|
+
try {
|
|
54
|
+
file = JSON.parse(readFileSync(join(dir, "factory.json"), "utf8"));
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
file = {};
|
|
58
|
+
}
|
|
59
|
+
const listed = Array.isArray(file.claudeModels) ? file.claudeModels.map(plainName).filter((m) => Boolean(m)) : [];
|
|
60
|
+
const base = listed.length ? listed : CLAUDE_MODELS.map((m) => m.id);
|
|
61
|
+
// A setting that is not one plain word (opus[1m]) is left to Claude Code, which reads it itself. A list that leaves the setting out wins over it.
|
|
62
|
+
const setting = plainName(modelOf("claude"));
|
|
63
|
+
const configured = plainName(file.claudeDefaultModel) ?? (setting && (!listed.length || isPermittedModel(setting, listed)) ? setting : (listed[0] ?? null));
|
|
64
|
+
return { permitted: configured && !isPermittedModel(configured, base) ? [configured, ...base] : base, configured };
|
|
65
|
+
}
|
|
66
|
+
/** A permitted name, or the full name of a permitted alias. */
|
|
67
|
+
export function isPermittedModel(model, permitted) {
|
|
68
|
+
return permitted.includes(model) || CLAUDE_MODELS.some((m) => m.resolves_to === model && permitted.includes(m.id));
|
|
69
|
+
}
|
|
70
|
+
/** What a request records about its model, or why it may not be recorded. */
|
|
71
|
+
export function modelPlan(provider, model, permitted) {
|
|
72
|
+
if (model) {
|
|
73
|
+
if (provider !== "claude") {
|
|
74
|
+
return { refusal: { code: "model_provider_mismatch", message: `${model} is a Claude Code model and this request runs on ${provider ?? "no provider"}. Nothing was recorded; remove the model or run it on claude.`, permitted } };
|
|
75
|
+
}
|
|
76
|
+
if (!isPermittedModel(model, permitted)) {
|
|
77
|
+
return { refusal: { code: "model_not_permitted", message: `${model} is not a permitted Claude Code model on this host (${permitted.join(", ")}). Nothing was recorded.`, permitted } };
|
|
78
|
+
}
|
|
79
|
+
return { fields: { model } };
|
|
80
|
+
}
|
|
81
|
+
return { fields: provider === "claude" ? { model_routing: JEV_WITHIN_CLAUDE } : {} };
|
|
82
|
+
}
|
|
83
|
+
/** One candidate per permitted model, the configured one first: Jev's options, and the preflight's. */
|
|
84
|
+
export function claudeModelCandidates(found, config, base) {
|
|
85
|
+
const a = found.find((p) => p.id === "claude");
|
|
86
|
+
const installed = Boolean(a?.installed);
|
|
87
|
+
const auth = a?.auth_evidence === "found" ? "config_dir_only" : "none";
|
|
88
|
+
// A configured full name stands for its alias, so one model is not offered twice.
|
|
89
|
+
const sameModel = (name) => CLAUDE_MODELS.find((m) => m.id === name)?.resolves_to === config.configured;
|
|
90
|
+
const names = [...new Set([...(config.configured ? [config.configured] : []), ...config.permitted.filter((name) => !sameModel(name))])];
|
|
91
|
+
return names.map((model) => {
|
|
92
|
+
let eligible = base?.eligible ?? true;
|
|
93
|
+
let reason = base?.policy_reason ?? "Installed, with sign-in evidence (config directory only; quota unknown).";
|
|
94
|
+
if (!installed)
|
|
95
|
+
[eligible, reason] = [false, "Not installed on the connector host."];
|
|
96
|
+
else if (auth === "none")
|
|
97
|
+
[eligible, reason] = [false, "No sign-in evidence on this host."];
|
|
98
|
+
const note = CLAUDE_MODELS.find((m) => m.id === model || m.resolves_to === model)?.capability_note;
|
|
99
|
+
return {
|
|
100
|
+
option: `claude:${model}`,
|
|
101
|
+
provider: "claude",
|
|
102
|
+
model_id: model,
|
|
103
|
+
model_id_source: model === config.configured ? "configured_default" : "permitted",
|
|
104
|
+
...(note ? { capability_note: note } : {}),
|
|
105
|
+
installed,
|
|
106
|
+
...(a?.version ? { version: a.version } : {}),
|
|
107
|
+
auth,
|
|
108
|
+
quota: "unknown",
|
|
109
|
+
eligible,
|
|
110
|
+
policy_reason: reason,
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const taskOf = (b) => ({
|
|
115
|
+
type: (typeof b.task_type === "string" ? b.task_type : "implementation"),
|
|
116
|
+
criticality: (typeof b.criticality === "string" ? b.criticality : "normal"),
|
|
117
|
+
});
|
|
118
|
+
/**
|
|
119
|
+
* The model of one mission's launch, or null when this mission's model is not routed: another
|
|
120
|
+
* provider, or a request recorded before routing. Asked at most once for a version: a brief written
|
|
121
|
+
* again for it (a rerun) keeps the answer, because a lost answer may already have been charged.
|
|
122
|
+
*/
|
|
123
|
+
export async function routeModel(record, opts, deps = {}) {
|
|
124
|
+
const b = (record.body ?? {});
|
|
125
|
+
const version = versionOf(record);
|
|
126
|
+
const base = { contract: MODEL_ROUTING_CONTRACT, version: 1, decided_for: { record: record.id, version }, provider: "claude", authorizes: false };
|
|
127
|
+
const explicit = typeof b.model === "string" && b.model ? b.model : null;
|
|
128
|
+
if (!explicit && b.model_routing !== JEV_WITHIN_CLAUDE)
|
|
129
|
+
return null;
|
|
130
|
+
if (opts.existingSession)
|
|
131
|
+
return { ...base, model: null, source: "existing_session" };
|
|
132
|
+
// The request was checked when it was made. A launch is checked again, because nothing stands in for Claude Code.
|
|
133
|
+
const found = discoverProviders(deps.providersProbe, PROVIDERS.filter((p) => p.id === "claude"));
|
|
134
|
+
const missing = !found[0]?.installed ? "is not installed" : found[0].auth_evidence !== "found" ? "shows no sign-in" : null;
|
|
135
|
+
if (missing)
|
|
136
|
+
return { ...base, model: null, source: "unavailable", why: `Claude Code ${missing} on the connector host` };
|
|
137
|
+
if (explicit)
|
|
138
|
+
return { ...base, model: explicit, source: "request" };
|
|
139
|
+
const prior = record.completion_receipt?.model_routing;
|
|
140
|
+
if (prior?.decided_for?.record === record.id && prior.decided_for.version === version && prior.source !== "unavailable" && prior.source !== "existing_session")
|
|
141
|
+
return prior;
|
|
142
|
+
const config = claudeModelConfig(deps.factoryDir ?? factoryDir(), deps.modelOf);
|
|
143
|
+
const candidates = claudeModelCandidates(found, config);
|
|
144
|
+
const task = taskOf(b);
|
|
145
|
+
const jev = deps.adapter ? null : jevConfigOf(deps.env ?? process.env);
|
|
146
|
+
const adapter = deps.adapter ?? (jev ? jevAdapter(jev, deps.fetchImpl ?? fetch, ROUTING_TIMEOUT_MS) : undefined);
|
|
147
|
+
const answer = await modelPreflight({
|
|
148
|
+
mission: { id: record.id, resolution: "launch", authorizes_actions: false },
|
|
149
|
+
approved_provider: "claude",
|
|
150
|
+
task: task.type,
|
|
151
|
+
criticality: task.criticality,
|
|
152
|
+
candidates,
|
|
153
|
+
...(adapter ? { adapter } : { routerWhenAbsent: "router_unconfigured" }),
|
|
154
|
+
});
|
|
155
|
+
const chosen = answer.state === "recommended" && answer.decider.router === "answered" ? (answer.recommendation.model_id ?? null) : null;
|
|
156
|
+
const reasons = chosen ? [] : answer.recommendation.abstain_reasons.length ? answer.recommendation.abstain_reasons : [answer.decider.router];
|
|
157
|
+
return {
|
|
158
|
+
...base,
|
|
159
|
+
model: chosen ?? config.configured,
|
|
160
|
+
source: chosen ? "jev" : config.configured ? "configured_fallback" : "cli_default",
|
|
161
|
+
...(chosen ? {} : { fallback_reasons: reasons }),
|
|
162
|
+
task,
|
|
163
|
+
eligible: candidates.filter((c) => c.eligible).map((c) => c.model_id),
|
|
164
|
+
decider: {
|
|
165
|
+
source: answer.decider.source,
|
|
166
|
+
router: answer.decider.router,
|
|
167
|
+
...(answer.decider.model ? { model: answer.decider.model } : {}),
|
|
168
|
+
calibration: answer.decider.calibration,
|
|
169
|
+
...(answer.decider.confidence_floor !== undefined ? { confidence_floor: answer.decider.confidence_floor } : {}),
|
|
170
|
+
confidence: answer.recommendation.confidence,
|
|
171
|
+
review_tier: answer.recommendation.review_tier,
|
|
172
|
+
input_hash: answer.input_hash,
|
|
173
|
+
explanation: answer.recommendation.explanation,
|
|
174
|
+
...(answer.decider.detail ? { detail: answer.decider.detail } : {}),
|
|
175
|
+
...(answer.evidence.latency_ms !== undefined ? { latency_ms: answer.evidence.latency_ms } : {}),
|
|
176
|
+
// What this call cost and how to find it; the account's balances stay out of a receipt others read.
|
|
177
|
+
...(answer.evidence.jev_billing ? { billing: { credits_charged: answer.evidence.jev_billing.credits_charged, run_id: answer.evidence.jev_billing.run_id } } : {}),
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/** What the brief carries. */
|
|
182
|
+
export function modelAttributes(routing) {
|
|
183
|
+
if (!routing || routing.source === "existing_session" || routing.source === "unavailable")
|
|
184
|
+
return {};
|
|
185
|
+
return { ...(routing.model ? { model: routing.model } : {}), model_source: routing.source };
|
|
186
|
+
}
|
|
187
|
+
const TRANSCRIPT_HEAD_BYTES = 4 * 1024 * 1024;
|
|
188
|
+
/**
|
|
189
|
+
* The model that first answered in a session's own transcript, or null when none has yet. A launched
|
|
190
|
+
* session's id is its own, so anything answering in it is this launch. "<synthetic>" is Claude Code's
|
|
191
|
+
* own line, and a sidechain is a subagent: neither is the session's model.
|
|
192
|
+
*/
|
|
193
|
+
export function firstModelInTranscript(path) {
|
|
194
|
+
let head;
|
|
195
|
+
try {
|
|
196
|
+
const fd = openSync(path, "r");
|
|
197
|
+
try {
|
|
198
|
+
const buf = Buffer.alloc(TRANSCRIPT_HEAD_BYTES);
|
|
199
|
+
head = buf.subarray(0, readSync(fd, buf, 0, TRANSCRIPT_HEAD_BYTES, 0)).toString("utf8");
|
|
200
|
+
}
|
|
201
|
+
finally {
|
|
202
|
+
closeSync(fd);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
for (const line of head.split("\n")) {
|
|
209
|
+
if (!line.includes('"assistant"'))
|
|
210
|
+
continue;
|
|
211
|
+
let r;
|
|
212
|
+
try {
|
|
213
|
+
r = JSON.parse(line);
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
const model = r.type === "assistant" && !r.isSidechain ? r.message?.model : undefined;
|
|
219
|
+
if (typeof model === "string" && model && model !== "<synthetic>")
|
|
220
|
+
return model;
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
/** Whether a model answered under a name: the name itself, or the alias of its family (opus answers as claude-opus-5-5). */
|
|
225
|
+
export function modelMatches(requested, observed) {
|
|
226
|
+
return observed === requested || observed.startsWith(`claude-${requested}-`);
|
|
227
|
+
}
|
|
@@ -17,6 +17,14 @@ export interface FactoryReceipt {
|
|
|
17
17
|
launcher?: string;
|
|
18
18
|
/** The brief file the line pointed the seat at. */
|
|
19
19
|
brief?: string;
|
|
20
|
+
/** What the launch asked of the model (jgwill/Miadi#943). */
|
|
21
|
+
model?: FactoryModelReceipt;
|
|
22
|
+
}
|
|
23
|
+
export interface FactoryModelReceipt {
|
|
24
|
+
requested: string | null;
|
|
25
|
+
source: string | null;
|
|
26
|
+
/** The flag on the launch line. Which model answered is in the session's transcript, not here. */
|
|
27
|
+
flag: string | null;
|
|
20
28
|
}
|
|
21
29
|
/** The runner's ledger file: MIADI_FACTORY_LEDGER, else `<factory>/delivered.jsonl`, as the runner resolves it. */
|
|
22
30
|
export declare function factoryLedgerPath(dir?: string, env?: NodeJS.ProcessEnv): string;
|
package/dist/factory-receipt.js
CHANGED
|
@@ -55,6 +55,7 @@ export function readFactoryReceipts(file) {
|
|
|
55
55
|
...(str(r.provider) ? { provider: str(r.provider) } : {}),
|
|
56
56
|
...(str(r.launcher) ? { launcher: str(r.launcher) } : {}),
|
|
57
57
|
...(str(r.brief) ? { brief: str(r.brief) } : {}),
|
|
58
|
+
...(r.model && typeof r.model === "object" ? { model: r.model } : {}),
|
|
58
59
|
});
|
|
59
60
|
}
|
|
60
61
|
return out;
|
package/dist/mission-status.d.ts
CHANGED
|
@@ -58,6 +58,21 @@ export interface MissionSession {
|
|
|
58
58
|
/** Present when Miadi's session view was joined (write tier). */
|
|
59
59
|
miadi?: unknown;
|
|
60
60
|
}
|
|
61
|
+
/** The model a mission's launch used: who chose it, what the launch line asked, and which model answered (jgwill/Miadi#943). */
|
|
62
|
+
export interface MissionModel {
|
|
63
|
+
/** What the launch was told to use; null when it passed no flag. */
|
|
64
|
+
chosen: string | null;
|
|
65
|
+
/** request, jev, configured_fallback, cli_default, existing_session or unavailable. */
|
|
66
|
+
source: string | null;
|
|
67
|
+
fallback_reasons?: string[];
|
|
68
|
+
confidence?: number | null;
|
|
69
|
+
/** The flag on the launch line, from the runner's receipt, once it delivered. */
|
|
70
|
+
flag?: string | null;
|
|
71
|
+
/** The model the session's own transcript says answered, read now. null: none has yet. */
|
|
72
|
+
observed?: string | null;
|
|
73
|
+
/** False when another model answered than the one chosen. */
|
|
74
|
+
match: boolean | "unknown";
|
|
75
|
+
}
|
|
61
76
|
/** The provider the mission asked for, the one resolved on the host, and the one that ran. */
|
|
62
77
|
export interface MissionProvider {
|
|
63
78
|
requested: string | null;
|
|
@@ -159,6 +174,8 @@ export interface MissionIdentity {
|
|
|
159
174
|
candidates: MissionCandidate[];
|
|
160
175
|
}
|
|
161
176
|
export interface MissionStatus {
|
|
177
|
+
/** The model its launch used, for the write tier. */
|
|
178
|
+
model?: MissionModel;
|
|
162
179
|
ref: string;
|
|
163
180
|
found: boolean;
|
|
164
181
|
via?: string;
|
|
@@ -235,6 +252,8 @@ export interface MissionStatusDeps {
|
|
|
235
252
|
steeringSupportOf?: (provider: string) => SteeringSupport;
|
|
236
253
|
/** Whether the tmux session still holds the pane id (write tier only); undefined when it cannot be listed. */
|
|
237
254
|
panePresent?: (session: string, paneId: string) => boolean | undefined;
|
|
255
|
+
/** The model that first answered in a session, from its own transcript (write tier only). */
|
|
256
|
+
modelAnsweredOf?: (sessionId: string) => string | null;
|
|
238
257
|
/** The factory runner's delivery receipts for one record, newest first (write tier only). */
|
|
239
258
|
factoryReceiptsOf?: (recordId: string) => FactoryReceipt[];
|
|
240
259
|
/** The records the factory delivered to one Claude Code session id (write tier only). */
|