@miadi/connector 0.1.28 → 0.1.29
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 +7 -1
- package/STEERING.md +1 -1
- package/dist/approve.d.ts +3 -0
- package/dist/approve.js +33 -10
- 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/server.d.ts +1 -1
- package/dist/server.js +1 -0
- package/dist/tools.js +75 -8
- 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
|
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,6 +26,7 @@ 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";
|
|
31
32
|
import { canReadReading } from "./reading/privacy.js";
|
|
@@ -98,12 +99,14 @@ function attr(v) {
|
|
|
98
99
|
function text(v) {
|
|
99
100
|
return String(v ?? "").replace(/<(?=[\/!?]?[A-Za-z])/g, "‹");
|
|
100
101
|
}
|
|
102
|
+
/** How a proposal launches, which the brief's attributes carry: not part of the work (jgwill/Miadi#943). */
|
|
103
|
+
const LAUNCH_FIELDS = new Set(["resolved_provider", "model", "model_routing", "task_type", "criticality"]);
|
|
101
104
|
/** The task a work proposal asks for, written from the proposal's own fields. */
|
|
102
105
|
export function proposalTask(record) {
|
|
103
106
|
const b = record.body;
|
|
104
107
|
const lines = ["Carry out this approved work proposal, within its own scope and constraints.", ""];
|
|
105
108
|
for (const [k, v] of Object.entries(b)) {
|
|
106
|
-
if (v === undefined || v === null || v === "")
|
|
109
|
+
if (v === undefined || v === null || v === "" || LAUNCH_FIELDS.has(k))
|
|
107
110
|
continue;
|
|
108
111
|
lines.push(`${k.replace(/_/g, " ")}: ${typeof v === "string" ? v : JSON.stringify(v)}`);
|
|
109
112
|
}
|
|
@@ -112,7 +115,8 @@ export function proposalTask(record) {
|
|
|
112
115
|
export function runBrief(record, approver, sessions, instructions, providerAttrs = {}, openAspects = []) {
|
|
113
116
|
const body = (record.kind === "work_proposal" ? { task: proposalTask(record) } : record.body);
|
|
114
117
|
// A request recorded before providers were resolved (jgwill/Miadi#893) names only what was asked (#926 review RR7).
|
|
115
|
-
|
|
118
|
+
// A work proposal resolves its provider too, and one recorded before that names none (jgwill/Miadi#943).
|
|
119
|
+
const provider = record.body.resolved_provider ?? body.provider;
|
|
116
120
|
const short = record.id.split(":")[1]?.slice(0, 8) ?? "run";
|
|
117
121
|
const to = body.session && sessions.includes(body.session) ? body.session : `new:${body.session ?? `connector-${yymmdd()}-${short}`}`;
|
|
118
122
|
// A new session opens where the request says, else where the factory runner's config says (defaultCwd): no host path here (#911).
|
|
@@ -233,7 +237,7 @@ export async function executeApproved(record, approver, deps, instructions) {
|
|
|
233
237
|
const f = deps.fetchImpl ?? fetch;
|
|
234
238
|
const b = record.body;
|
|
235
239
|
const reviewCall = (method, path, payload) => callReview(deps, method, path, payload);
|
|
236
|
-
const queueBrief = () => {
|
|
240
|
+
const queueBrief = async () => {
|
|
237
241
|
// Checked again where the brief is written: an approval, and every rerun of it (jgwill/Miadi#926).
|
|
238
242
|
const authorization = record.kind === "run_request" ? authorizeProvider(record, deps.ledger.all()) : undefined;
|
|
239
243
|
if (authorization && !authorization.authorized) {
|
|
@@ -249,14 +253,30 @@ export async function executeApproved(record, approver, deps, instructions) {
|
|
|
249
253
|
catch {
|
|
250
254
|
sessions = [];
|
|
251
255
|
}
|
|
252
|
-
|
|
256
|
+
// A session already running keeps its model: a named one cannot be honoured, and Jev is not asked (jgwill/Miadi#943).
|
|
257
|
+
const existingSession = record.kind === "run_request" && typeof b.session === "string" && sessions.includes(b.session);
|
|
258
|
+
if (existingSession && typeof b.model === "string" && b.model) {
|
|
259
|
+
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.` };
|
|
260
|
+
}
|
|
261
|
+
const routing = await routeModel(record, { existingSession }, { factoryDir: deps.factoryDir, ...deps.modelRouting });
|
|
262
|
+
if (routing?.source === "unavailable") {
|
|
263
|
+
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.` };
|
|
264
|
+
}
|
|
265
|
+
const { to, brief } = runBrief(record, approver, sessions, instructions, { ...(authorization ? briefAttributes(authorization) : {}), ...modelAttributes(routing) }, deps.draftReview?.stored(record)?.needs_revision ?? []);
|
|
253
266
|
const file = runBriefFile(record);
|
|
254
|
-
|
|
267
|
+
try {
|
|
268
|
+
writeFileSync(join(queue, file), brief, { flag: "wx", mode: 0o640 });
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
// The answer stays with the failure, so running it again does not ask Jev a second time.
|
|
272
|
+
return { outcome: "failed", ...(routing ? { model_routing: routing } : {}), message: error instanceof Error ? error.message : String(error) };
|
|
273
|
+
}
|
|
255
274
|
return {
|
|
256
275
|
outcome: "queued",
|
|
257
276
|
to,
|
|
258
277
|
file,
|
|
259
278
|
...(authorization ? { provider_authorization: authorizationReceipt(authorization) } : {}),
|
|
279
|
+
...(routing ? { model_routing: routing } : {}),
|
|
260
280
|
note: "The factory intake delivers queued briefs every 5 minutes.",
|
|
261
281
|
};
|
|
262
282
|
};
|
|
@@ -589,8 +609,10 @@ export async function decide(r, person, choice, deps, opts) {
|
|
|
589
609
|
}
|
|
590
610
|
/**
|
|
591
611
|
* The kinds whose run is done at once on this host (a brief written to the
|
|
592
|
-
* factory queue, an ending recorded)
|
|
593
|
-
*
|
|
612
|
+
* factory queue, an ending recorded), so nothing is written ahead of it. A run may
|
|
613
|
+
* ask Jev for its model first, up to 8 s: a restart then loses the click and that
|
|
614
|
+
* one call, and the request still waits for its decision. Every other approved run
|
|
615
|
+
* is recorded as running first.
|
|
594
616
|
*/
|
|
595
617
|
const RUNS_AT_ONCE = new Set(["run_request", "work_proposal", "session_completion_proposal"]);
|
|
596
618
|
/** What the receipt of a run the connector lost to a restart says (jgwill/Miadi#924). */
|
|
@@ -828,6 +850,7 @@ async function decideOnce(r, person, choice, deps, opts) {
|
|
|
828
850
|
export function isApprovable(r) {
|
|
829
851
|
return Boolean(r && APPROVABLE.has(r.kind));
|
|
830
852
|
}
|
|
853
|
+
const modelWords = (b) => (typeof b.model === "string" && b.model ? ` on ${b.model}` : b.model_routing ? " on the model Jev chooses" : "");
|
|
831
854
|
/** What approving a request does, in one sentence, for the card a person decides on. */
|
|
832
855
|
export function consequenceOf(r, authorization, records = [], steering) {
|
|
833
856
|
const b = r.body;
|
|
@@ -835,9 +858,9 @@ export function consequenceOf(r, authorization, records = [], steering) {
|
|
|
835
858
|
case "run_request":
|
|
836
859
|
return authorization && !authorization.authorized
|
|
837
860
|
? `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."}`;
|
|
861
|
+
: `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
862
|
case "work_proposal":
|
|
840
|
-
return
|
|
863
|
+
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
864
|
case "review_operation_request":
|
|
842
865
|
if (b.operation === "create") {
|
|
843
866
|
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 +1552,7 @@ ${option("per_mission_choice", "Codex runs only when I choose it for that missio
|
|
|
1529
1552
|
${option("selectable", "Codex may be named for my requests without a per-mission choice.")}
|
|
1530
1553
|
</fieldset>
|
|
1531
1554
|
<fieldset class="provider-defaults"><legend>When a request in my name names no provider</legend>
|
|
1532
|
-
${defaultOption(HOST_ORDER, "The
|
|
1555
|
+
${defaultOption(HOST_ORDER, "The Factory's default, which is Claude Code today")}
|
|
1533
1556
|
${defaultOption("pi", "Pi")}
|
|
1534
1557
|
${defaultOption("copilot", "Copilot")}
|
|
1535
1558
|
${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). */
|
package/dist/mission-status.js
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
import { steerAttempts, steeringGrantOf, steeringRevoked, checkGrant } from "./steer.js";
|
|
2
|
+
import { modelMatches } from "./claude-models.js";
|
|
2
3
|
import { missionResult, redactResult, submittedWithWriteTier } from "./mission-result.js";
|
|
4
|
+
function missionModel(record, receipt, answeredOf) {
|
|
5
|
+
const routing = (record.completion_receipt ?? {}).model_routing;
|
|
6
|
+
const ran = receipt?.model;
|
|
7
|
+
if (!routing && !ran)
|
|
8
|
+
return undefined;
|
|
9
|
+
const chosen = routing?.model ?? ran?.requested ?? null;
|
|
10
|
+
const source = routing?.source ?? ran?.source ?? null;
|
|
11
|
+
// A session that was already running answers on its own model, from long before this mission.
|
|
12
|
+
const observed = source !== "existing_session" && receipt?.session_id && answeredOf ? answeredOf(receipt.session_id) : undefined;
|
|
13
|
+
return {
|
|
14
|
+
chosen,
|
|
15
|
+
source,
|
|
16
|
+
...(routing?.fallback_reasons ? { fallback_reasons: routing.fallback_reasons } : {}),
|
|
17
|
+
...(routing?.decider ? { confidence: routing.decider.confidence ?? null } : {}),
|
|
18
|
+
...(receipt ? { flag: ran?.flag ?? null } : {}),
|
|
19
|
+
...(observed !== undefined ? { observed } : {}),
|
|
20
|
+
match: chosen && observed ? modelMatches(chosen, observed) : "unknown",
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** How long a delivered session may name no model before a reader is told. */
|
|
24
|
+
const NO_ANSWER_NOTE_MS = 5 * 60 * 1000;
|
|
3
25
|
const ISSUE_REF = /^([\w.-]+)\/([\w.-]+)#(\d+)$/;
|
|
4
26
|
const SESSION_REF = /^session:([0-9a-f-]{36})$/;
|
|
5
27
|
const MISSION_KINDS = new Set(["run_request", "work_proposal"]);
|
|
@@ -109,7 +131,7 @@ function nextAction(record, standing, queue, result) {
|
|
|
109
131
|
return queue?.state === "delivered"
|
|
110
132
|
? "The brief is with its session. Follow it, or steer it with request_session_steer inside the approved grant."
|
|
111
133
|
: queue?.state === "refused"
|
|
112
|
-
? "The factory runner refused to launch
|
|
134
|
+
? "The factory runner refused to launch it, and the queue says why; nothing runs. The requester decides on a new request."
|
|
113
135
|
: "Wait for the factory intake to deliver the brief.";
|
|
114
136
|
case "failed":
|
|
115
137
|
return standing.rerun.available ? "A write-tier person may run it again with the same approval." : "Read the failure and decide.";
|
|
@@ -324,6 +346,16 @@ export async function missionStatus(ref, records, deps) {
|
|
|
324
346
|
}
|
|
325
347
|
}
|
|
326
348
|
}
|
|
349
|
+
const model = deps.factoryReceiptsOf ? missionModel(record, receipts[0], deps.modelAnsweredOf) : undefined;
|
|
350
|
+
if (model?.match === false) {
|
|
351
|
+
notes.push(`The launch asked for ${model.chosen}; the session's transcript says ${model.observed} answered. Nothing was re-run because of it.`);
|
|
352
|
+
}
|
|
353
|
+
if (model && receipts[0] && model.chosen && model.source !== "existing_session" && !model.flag) {
|
|
354
|
+
notes.push(`${model.chosen} was chosen, but the runner's receipt shows no --model: a factory runner older than 0.1.5 ignores it, so read observed for what ran.`);
|
|
355
|
+
}
|
|
356
|
+
if (model?.observed === null && receipts[0] && Date.now() - Date.parse(receipts[0].at) > NO_ANSWER_NOTE_MS) {
|
|
357
|
+
notes.push("Five minutes after delivery, the session's transcript names no model that answered. It may be slow, or its model may have been refused at launch: read the pane.");
|
|
358
|
+
}
|
|
327
359
|
const addSession = (session, association) => {
|
|
328
360
|
if (seen.has(session))
|
|
329
361
|
return;
|
|
@@ -478,6 +510,7 @@ export async function missionStatus(ref, records, deps) {
|
|
|
478
510
|
...(deps.steeringSupportOf && (provider?.actual ?? provider?.resolved) ? { support: deps.steeringSupportOf(String(provider.actual ?? provider.resolved)) } : {}),
|
|
479
511
|
},
|
|
480
512
|
...(provider ? { provider } : {}),
|
|
513
|
+
...(model ? { model } : {}),
|
|
481
514
|
stage_truth: stageTruth,
|
|
482
515
|
mission_stage: missionStage(standing ?? null, stageTruth),
|
|
483
516
|
pending_human_gates: pendingGates(record, records, result, deps.approvalUrl),
|
|
@@ -17,8 +17,8 @@ export interface ModelCandidate {
|
|
|
17
17
|
provider: ProviderId;
|
|
18
18
|
/** A concrete model id when the host shows one, else null. */
|
|
19
19
|
model_id: string | null;
|
|
20
|
-
/** configured_default: the provider's own config names it; it is not proof of what a launch will use. */
|
|
21
|
-
model_id_source: "configured_default" | "fixture" | "unknown";
|
|
20
|
+
/** configured_default: the provider's own config names it; it is not proof of what a launch will use. permitted: on this host's list of Claude Code models (claude-models.ts). */
|
|
21
|
+
model_id_source: "configured_default" | "permitted" | "fixture" | "unknown";
|
|
22
22
|
/** What is known of the model's strength, with its source; absent on a live host, where nothing is measured yet. */
|
|
23
23
|
capability_note?: string;
|
|
24
24
|
installed: boolean;
|
package/dist/model-preflight.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* how do we know?" — never an authorization.
|
|
5
5
|
*
|
|
6
6
|
* - Policy is deterministic and decided here, not by Jev: the approved provider
|
|
7
|
-
* is kept (no switching without a person), Claude Code
|
|
7
|
+
* is kept (no switching without a person), only Claude Code runs unnamed, an
|
|
8
8
|
* uninstalled or sign-in-less provider is ineligible, and a reported launch on
|
|
9
9
|
* another provider fails closed as provider_mismatch before anything is asked.
|
|
10
10
|
* - Codex is eligible only with its requester's own choice for the mission or
|
|
@@ -269,7 +269,7 @@ export async function modelPreflight(input) {
|
|
|
269
269
|
source: "static_fallback",
|
|
270
270
|
router,
|
|
271
271
|
calibration: "not_applicable",
|
|
272
|
-
derivation: approved_provider ? `deterministic policy: the ${input.provider_basis ?? "approved"} provider and its configured default model` : "deterministic policy:
|
|
272
|
+
derivation: approved_provider ? `deterministic policy: the ${input.provider_basis ?? "approved"} provider and its configured default model` : "deterministic policy: Claude Code when no provider is named; the others only by name",
|
|
273
273
|
...(detail ? { detail } : {}),
|
|
274
274
|
},
|
|
275
275
|
recommendation: {
|
|
@@ -41,7 +41,7 @@ export interface ProviderPolicy {
|
|
|
41
41
|
source: "default" | "person";
|
|
42
42
|
record?: string;
|
|
43
43
|
set_at?: string;
|
|
44
|
-
/** The provider a request of theirs runs on when it names none (jgwill/Miadi#942). Absent: the
|
|
44
|
+
/** The provider a request of theirs runs on when it names none (jgwill/Miadi#942). Absent: Claude Code, the Factory's default (jgwill/Miadi#943). */
|
|
45
45
|
default_provider?: string;
|
|
46
46
|
/** Who said so: the person on /providers, or the operator's factory.json for this person. */
|
|
47
47
|
default_provider_source?: "person" | "host_config";
|
package/dist/provider-policy.js
CHANGED
|
@@ -62,7 +62,7 @@ export function authorizeProvider(record, records, opts = {}) {
|
|
|
62
62
|
state: "not_required",
|
|
63
63
|
authorized: true,
|
|
64
64
|
explanation: provider
|
|
65
|
-
? `${provider} needs no per-mission choice; it was ${requested ? "named in the request" : "
|
|
65
|
+
? `${provider} needs no per-mission choice; it was ${requested ? "named in the request" : "the default provider"} and verified installed.`
|
|
66
66
|
: "No provider is named: the factory runner's configured default launches, and the runner never starts Codex for a connector brief without the brief's own authorization.",
|
|
67
67
|
};
|
|
68
68
|
}
|
package/dist/providers.d.ts
CHANGED
|
@@ -9,9 +9,9 @@ export interface ProviderSpec {
|
|
|
9
9
|
auth_evidence: string[];
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* that mission or their own policy (provider-policy.ts, jgwill/Miadi#926).
|
|
12
|
+
* Claude Code is what a run request that names no provider launches (jgwill/Miadi#943). Every
|
|
13
|
+
* other provider runs only when a request names it. Codex also needs the requester's own choice
|
|
14
|
+
* for that mission or their own policy (provider-policy.ts, jgwill/Miadi#926).
|
|
15
15
|
*/
|
|
16
16
|
export declare const PROVIDERS: ProviderSpec[];
|
|
17
17
|
export interface ProviderAvailability {
|
|
@@ -41,9 +41,9 @@ export type ProviderResolution = {
|
|
|
41
41
|
};
|
|
42
42
|
/**
|
|
43
43
|
* Resolve the provider a run will ask the intake for. A requested provider must
|
|
44
|
-
* be known and installed
|
|
45
|
-
*
|
|
46
|
-
*
|
|
44
|
+
* be known and installed. With no request it is Claude Code, and a host where Claude
|
|
45
|
+
* Code is missing or shows no sign-in leaves the mission unstarted: no other provider
|
|
46
|
+
* stands in for it. Whether a named Codex may run is provider-policy.ts's answer.
|
|
47
47
|
*/
|
|
48
48
|
export declare function resolveProvider(requested: string | undefined, found: ProviderAvailability[], personDefault?: string): ProviderResolution;
|
|
49
49
|
/**
|
package/dist/providers.js
CHANGED
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The connector never assumes a provider works because a task text names one:
|
|
5
5
|
* it reports what is installed on this host, what sign-in evidence exists (the
|
|
6
|
-
* presence of the provider's own config directory — never its contents
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* mission is left unstarted.
|
|
6
|
+
* presence of the provider's own config directory — never its contents, and never
|
|
7
|
+
* proof of a live sign-in), and applies one default. A request that names no provider
|
|
8
|
+
* runs on Claude Code (jgwill/Miadi#943) and on nothing else: without it the mission
|
|
9
|
+
* is left unstarted. Pi, Copilot and Codex run only when named, and Codex also needs
|
|
10
|
+
* the requester's own choice for that mission (provider-policy.ts, jgwill/Miadi#926).
|
|
12
11
|
*
|
|
13
12
|
* No bearer token is read, logged or returned here. Version probes run the
|
|
14
13
|
* provider's own `--version` with a short timeout.
|
|
@@ -18,15 +17,15 @@ import { existsSync } from "node:fs";
|
|
|
18
17
|
import { homedir } from "node:os";
|
|
19
18
|
import { join } from "node:path";
|
|
20
19
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* that mission or their own policy (provider-policy.ts, jgwill/Miadi#926).
|
|
20
|
+
* Claude Code is what a run request that names no provider launches (jgwill/Miadi#943). Every
|
|
21
|
+
* other provider runs only when a request names it. Codex also needs the requester's own choice
|
|
22
|
+
* for that mission or their own policy (provider-policy.ts, jgwill/Miadi#926).
|
|
24
23
|
*/
|
|
25
24
|
export const PROVIDERS = [
|
|
25
|
+
{ id: "claude", cli: "claude", name: "Claude Code", selectable_by_default: true, auth_evidence: [".claude"] },
|
|
26
26
|
{ id: "codex", cli: "codex", name: "Codex CLI", selectable_by_default: false, auth_evidence: [".codex"] },
|
|
27
|
-
{ id: "pi", cli: "pi", name: "Pi coding agent", selectable_by_default:
|
|
28
|
-
{ id: "copilot", cli: "copilot", name: "GitHub Copilot CLI", selectable_by_default:
|
|
29
|
-
{ id: "claude", cli: "claude", name: "Claude Code", selectable_by_default: false, auth_evidence: [".claude"] },
|
|
27
|
+
{ id: "pi", cli: "pi", name: "Pi coding agent", selectable_by_default: false, auth_evidence: [".pi", ".config/pi"] },
|
|
28
|
+
{ id: "copilot", cli: "copilot", name: "GitHub Copilot CLI", selectable_by_default: false, auth_evidence: [".copilot"] },
|
|
30
29
|
];
|
|
31
30
|
const defaultWhich = (cli) => {
|
|
32
31
|
try {
|
|
@@ -64,20 +63,20 @@ export function discoverProviders(probe = {}, specs = PROVIDERS) {
|
|
|
64
63
|
}
|
|
65
64
|
/**
|
|
66
65
|
* Resolve the provider a run will ask the intake for. A requested provider must
|
|
67
|
-
* be known and installed
|
|
68
|
-
*
|
|
69
|
-
*
|
|
66
|
+
* be known and installed. With no request it is Claude Code, and a host where Claude
|
|
67
|
+
* Code is missing or shows no sign-in leaves the mission unstarted: no other provider
|
|
68
|
+
* stands in for it. Whether a named Codex may run is provider-policy.ts's answer.
|
|
70
69
|
*/
|
|
71
70
|
export function resolveProvider(requested, found, personDefault) {
|
|
72
71
|
const installed = found.filter((p) => p.installed);
|
|
73
72
|
// A person's own default stands in for naming it, and never silently becomes another provider (jgwill/Miadi#942).
|
|
74
73
|
if (!requested && personDefault) {
|
|
75
74
|
const avail = found.find((p) => p.id === personDefault);
|
|
76
|
-
if (avail?.installed)
|
|
75
|
+
if (avail?.installed && avail.auth_evidence === "found")
|
|
77
76
|
return { state: "ok", provider: avail, explicit: false };
|
|
78
77
|
return {
|
|
79
78
|
state: "provider_unavailable",
|
|
80
|
-
message: `Your default provider, ${personDefault}, is not installed on the connector host. The mission is left unstarted; name an available provider.`,
|
|
79
|
+
message: `Your default provider, ${personDefault}, ${avail?.installed ? "shows no sign-in" : "is not installed"} on the connector host. The mission is left unstarted; name an available provider.`,
|
|
81
80
|
available: installed,
|
|
82
81
|
};
|
|
83
82
|
}
|
|
@@ -101,12 +100,19 @@ export function resolveProvider(requested, found, personDefault) {
|
|
|
101
100
|
return { state: "ok", provider: avail, explicit: true };
|
|
102
101
|
}
|
|
103
102
|
const first = PROVIDERS.map((s) => found.find((p) => p.id === s.id)).find((p) => p.installed && p.selectable_by_default);
|
|
104
|
-
if (first)
|
|
103
|
+
if (first?.auth_evidence === "found")
|
|
105
104
|
return { state: "ok", provider: first, explicit: false };
|
|
105
|
+
if (first) {
|
|
106
|
+
return {
|
|
107
|
+
state: "provider_unavailable",
|
|
108
|
+
message: `${first.name}, the default provider, shows no sign-in on the connector host. The mission is left unstarted; sign it in or name another provider.`,
|
|
109
|
+
available: installed,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
106
112
|
if (installed.length) {
|
|
107
113
|
return {
|
|
108
114
|
state: "provider_needs_explicit_selection",
|
|
109
|
-
message: `
|
|
115
|
+
message: `Claude Code, the default provider, is not installed on the connector host, and the others run only by name (${installed.map((p) => p.id).join(", ")}). Name one in the request; none is chosen silently.`,
|
|
110
116
|
available: installed,
|
|
111
117
|
};
|
|
112
118
|
}
|
|
@@ -140,7 +146,7 @@ export async function routerPreflight(env = process.env, fetchImpl = fetch) {
|
|
|
140
146
|
if (!jev) {
|
|
141
147
|
return {
|
|
142
148
|
state: "unconfigured",
|
|
143
|
-
note: `No ${JEV_KEY_NAMES.join(" or ")} in the connector's environment:
|
|
149
|
+
note: `No ${JEV_KEY_NAMES.join(" or ")} in the connector's environment: a launch uses the configured Claude Code model and says so in its receipt.`,
|
|
144
150
|
};
|
|
145
151
|
}
|
|
146
152
|
const where = { service: jev.service, key_name: jev.key_name, url: jev.base };
|
package/dist/server.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export interface ConnectorDeps {
|
|
|
33
33
|
/** A provider's configured default model and a Jev decider (jgwill/Miadi#913); tests inject fakes. */
|
|
34
34
|
modelOf?: (provider: ProviderId) => string | null;
|
|
35
35
|
jevAdapter?: JevAdapter;
|
|
36
|
-
/** The environment the draft review
|
|
36
|
+
/** The environment the draft review and the model routing read their keys from (default process.env); tests pass their own (jgwill/Miadi#939, #943). */
|
|
37
37
|
draftReviewEnv?: NodeJS.ProcessEnv;
|
|
38
38
|
/** Where the mission standard comes from (default the prompt store, then the built-in copy); tests pass their own. */
|
|
39
39
|
standardSource?: StandardSource;
|
package/dist/server.js
CHANGED
|
@@ -95,6 +95,7 @@ export function createConnectorApp(config, deps) {
|
|
|
95
95
|
...(deps.wakeRunner ? { wakeRunner: deps.wakeRunner } : {}),
|
|
96
96
|
...(deps.captions ? { captions: deps.captions } : {}),
|
|
97
97
|
log: deps.log,
|
|
98
|
+
modelRouting: { adapter: deps.jevAdapter, env: deps.draftReviewEnv, fetchImpl: deps.fetchImpl, providersProbe: deps.providersProbe, modelOf: deps.modelOf },
|
|
98
99
|
};
|
|
99
100
|
// A run the connector was recording when it last stopped is failed now, so a person may run it again (#924).
|
|
100
101
|
reconcileInterrupted(approvalDeps);
|
package/dist/tools.js
CHANGED
|
@@ -20,12 +20,13 @@ import { AlreadyDecided, DECISIONS, DecisionConflict, KIND_LABELS, ProviderChoic
|
|
|
20
20
|
import { RevisionRefused, requestHistory, revisionRecord, supersedeRecords, versionOf } from "./revisions.js";
|
|
21
21
|
import { coverage } from "./captions.js";
|
|
22
22
|
import { DECISIONS_CARD_EARLIER_URIS, DECISIONS_CARD_HTML, DECISIONS_CARD_URI, DECISION_TOKENS_META } from "./decisions.js";
|
|
23
|
+
import { CLAUDE_MODELS, CLAUDE_MODELS_VERIFIED, claudeModelCandidates, claudeModelConfig, firstModelInTranscript, JEV_WITHIN_CLAUDE, MODEL_NAME, modelPlan } from "./claude-models.js";
|
|
23
24
|
import { discoverProviders, jevConfigOf, resolveProvider, routerPreflight, PROVIDERS } from "./providers.js";
|
|
24
25
|
import { authorizesActions, missionStatus, primaryIssueOf, resolveMissionSubject } from "./mission-status.js";
|
|
25
26
|
import { authorizationReceipt, authorizeProvider, CHOICE_PROVIDERS, isPersonId, needsPersonChoice, providerPolicyOf } from "./provider-policy.js";
|
|
26
27
|
import { candidatesFor, CRITICALITIES, jevAdapter, modelPreflight, PREFLIGHT_CONTRACT, PREFLIGHT_VERSION, TASK_TYPES, } from "./model-preflight.js";
|
|
27
28
|
import { ShelfRefusal, listShelfArtefacts, readShelfArtefact } from "./research-shelf.js";
|
|
28
|
-
import { DELIVERY_STATES, readSteerDelivery, revokeInInbox, settlementOf } from "./runtime-steer.js";
|
|
29
|
+
import { DELIVERY_STATES, readSteerDelivery, revokeInInbox, settlementOf, transcriptPathOf } from "./runtime-steer.js";
|
|
29
30
|
import { ADAPTERS, readFactoryConfig, runSteering, STEERING_CONTRACT_ID, steeringSupport } from "./steering-adapters.js";
|
|
30
31
|
import { checkGrant, isBusy, steerAttempts, steeringGrantOf, steeringRevoked, steerSession } from "./steer.js";
|
|
31
32
|
import { factoryLedgerPath, readFactoryReceipts, receiptsForRecord, recordsForSession } from "./factory-receipt.js";
|
|
@@ -197,6 +198,16 @@ function episodeRef(input) {
|
|
|
197
198
|
// miadi-chronicle://316, miadi-chronicle:316, chronicle:<folder>, a folder, or a number
|
|
198
199
|
return encodeURIComponent(input.replace(/^miadi-chronicle:(\/\/)?/, "").replace(/^chronicle:/, "").trim());
|
|
199
200
|
}
|
|
201
|
+
/** How a mission's Claude Code model is named or chosen, on both kinds that launch one (jgwill/Miadi#943). */
|
|
202
|
+
const launchModelFields = {
|
|
203
|
+
model: z
|
|
204
|
+
.string()
|
|
205
|
+
.regex(MODEL_NAME)
|
|
206
|
+
.optional()
|
|
207
|
+
.describe("The Claude Code model to launch on. Name it only when the person asked for that model; leave it out and Jev chooses among the permitted Claude Code models when it is approved. A model on a mission that runs on any other provider is refused."),
|
|
208
|
+
task_type: z.enum(TASK_TYPES).optional().describe("The kind of task, which with criticality is all Jev learns of it when it chooses the model. Default implementation, which goes to Sonnet."),
|
|
209
|
+
criticality: z.enum(CRITICALITIES).optional().describe("Default normal."),
|
|
210
|
+
};
|
|
200
211
|
export function registerTools(server, ctx) {
|
|
201
212
|
const { config, miadi, reviews, ledger } = ctx;
|
|
202
213
|
// One server is made per request, so the person a tool call runs for is this request's viewer.
|
|
@@ -236,7 +247,7 @@ export function registerTools(server, ctx) {
|
|
|
236
247
|
body[k] = `${body[k].length} chars`;
|
|
237
248
|
const receipt = r.completion_receipt ? { ...r.completion_receipt } : undefined;
|
|
238
249
|
if (receipt)
|
|
239
|
-
for (const k of ["to", "file", "session_id", "target", "artifact"])
|
|
250
|
+
for (const k of ["to", "file", "session_id", "target", "artifact", "model_routing"])
|
|
240
251
|
delete receipt[k];
|
|
241
252
|
// A steer's message names its target pane.
|
|
242
253
|
if (receipt && r.kind === "session_steer_request")
|
|
@@ -351,6 +362,10 @@ export function registerTools(server, ctx) {
|
|
|
351
362
|
const touching = (ref) => records().filter((r) => r.refs.includes(ref) || r.evidence_refs.includes(ref) || r.id === ref);
|
|
352
363
|
/** The factory runner's delivery receipts, read fresh: operator data, for the write tier only. */
|
|
353
364
|
const receipts = () => readFactoryReceipts(factoryLedgerPath(ctx.factoryDir ?? defaultFactoryDir()));
|
|
365
|
+
/** The Claude Code models this host permits, and the one it falls back to (jgwill/Miadi#943). */
|
|
366
|
+
const modelConfig = () => claudeModelConfig(ctx.factoryDir ?? defaultFactoryDir(), ctx.modelOf);
|
|
367
|
+
/** The body mark of a request whose model Jev chooses, when it runs on Claude Code. */
|
|
368
|
+
const routedOn = (provider) => (provider === "claude" ? { model_routing: JEV_WITHIN_CLAUDE } : {});
|
|
354
369
|
const factoryConfig = () => readFactoryConfig(ctx.factoryDir ?? defaultFactoryDir());
|
|
355
370
|
/** A person's policy with what the operator's factory.json says for them. */
|
|
356
371
|
const policyOf = (personId) => providerPolicyOf(ledger.all(), personId, factoryConfig()?.person_default_provider);
|
|
@@ -933,6 +948,12 @@ export function registerTools(server, ctx) {
|
|
|
933
948
|
}
|
|
934
949
|
: undefined,
|
|
935
950
|
factoryReceiptsOf: writeTier ? (id) => receiptsForRecord(receipts(), id) : undefined,
|
|
951
|
+
modelAnsweredOf: writeTier && ctx.steeringRuntime
|
|
952
|
+
? (sessionId) => {
|
|
953
|
+
const path = transcriptPathOf(ctx.steeringRuntime, sessionId);
|
|
954
|
+
return path ? firstModelInTranscript(path) : null;
|
|
955
|
+
}
|
|
956
|
+
: undefined,
|
|
936
957
|
recordsBoundTo: writeTier ? (sessionId) => recordsForSession(receipts(), sessionId) : undefined,
|
|
937
958
|
// What a result and a closure are checked against does not depend on who reads (#922 R5); only what is shown does.
|
|
938
959
|
boundSessionIdsOf: (id) => receiptsForRecord(receipts(), id).flatMap((x) => (x.session_id ? [x.session_id] : [])),
|
|
@@ -963,7 +984,7 @@ export function registerTools(server, ctx) {
|
|
|
963
984
|
}));
|
|
964
985
|
server.registerTool("provider_capabilities", {
|
|
965
986
|
title: "Which agent providers this host can launch",
|
|
966
|
-
description: "The provider reality of the connector host (jgwill/Miadi#893): which agent CLIs are installed, their versions, whether sign-in evidence exists, the
|
|
987
|
+
description: "The provider reality of the connector host (jgwill/Miadi#893): which agent CLIs are installed, their versions, whether sign-in evidence exists, the default (Claude Code, on the model Jev chooses among claude_models; every other provider only when a request names it), the rule that a named Codex runs only on the requester's own choice for that mission or their own policy (jgwill/Miadi#926), your own provider policy, and the read-only Jev routing preflight. No token is read or shown. Needs Miadi's write tier: this is host truth.",
|
|
967
988
|
inputSchema: {},
|
|
968
989
|
annotations: READ,
|
|
969
990
|
}, wrap(async (_args, extra) => {
|
|
@@ -977,12 +998,13 @@ export function registerTools(server, ctx) {
|
|
|
977
998
|
policy_page: `${config.publicUrl}/providers`,
|
|
978
999
|
providers: discoverProviders(ctx.providersProbe).map((p) => ({ ...p, steering: steeringOf(p.id, p.version) })),
|
|
979
1000
|
router: await routerPreflight(process.env, ctx.approval?.fetchImpl ?? fetch),
|
|
1001
|
+
claude_models: { ...modelConfig(), verified: CLAUDE_MODELS_VERIFIED, catalog: CLAUDE_MODELS, note: "A run naming no model has Jev choose among permitted when it is approved; on any Jev failure it launches on configured and its receipt says why. It never moves to another provider. Sign-in evidence is a config directory, not a live sign-in; verified is the one run that showed these names answer." },
|
|
980
1002
|
note: "A provider name in a task's text selects nothing; request_authorized_run's provider field is verified against this list, and an unavailable provider leaves the mission unstarted. A request may name Codex, but it runs only when its requester chooses Codex for that mission on the approval page, or their own policy on the providers page says so; a generic approval, the assistant's provider field, the host's order or Jev never choose it.",
|
|
981
1003
|
};
|
|
982
1004
|
}));
|
|
983
1005
|
server.registerTool("mission_model_preflight", {
|
|
984
1006
|
title: "Which provider and model fits a mission, and how that is known",
|
|
985
|
-
description: "A typed, versioned, read-only preflight for one mission (jgwill/Miadi#913): the candidate providers with their concrete model when the host shows one, sign-in evidence (config directory only), quota unknown, policy eligibility (the approved provider is kept; Claude Code
|
|
1007
|
+
description: "A typed, versioned, read-only preflight for one mission (jgwill/Miadi#913): the candidate providers with their concrete model when the host shows one (one candidate per permitted Claude Code model), sign-in evidence (config directory only), quota unknown, policy eligibility (the approved provider is kept; only Claude Code runs unnamed), a review floor, and a recommendation or an abstention with its reasons. It says where the choice came from: static_fallback, jev or a synthetic fixture. Jev is asked only with consult_jev and a Jev key in the connector's environment; that call is charged, and it carries no task text, mission id or repository name. A reported launch on another provider than the approved one fails closed as provider_mismatch. It authorizes nothing. Needs Miadi's write tier.",
|
|
986
1008
|
inputSchema: {
|
|
987
1009
|
ref: z.string().min(1).describe("The mission: run_request:<id> or work_proposal:<id> (an issue or session ref resolves only through its primary relation)."),
|
|
988
1010
|
task_type: z.enum(TASK_TYPES),
|
|
@@ -1017,7 +1039,11 @@ export function registerTools(server, ctx) {
|
|
|
1017
1039
|
const provider = (typeof body.resolved_provider === "string" ? body.resolved_provider : typeof body.provider === "string" ? body.provider : null);
|
|
1018
1040
|
const basis = record.approval_state === "approved" ? "approved" : "requested";
|
|
1019
1041
|
const authorization = providerAuthorizationOf(record);
|
|
1020
|
-
const
|
|
1042
|
+
const onHost = discoverProviders(ctx.providersProbe);
|
|
1043
|
+
const listed = candidatesFor(onHost, provider, ctx.modelOf, basis, authorization);
|
|
1044
|
+
const claudeRow = listed.find((c) => c.provider === "claude");
|
|
1045
|
+
// The same options a launch offers Jev, so a consult here is a dry run of it (jgwill/Miadi#943).
|
|
1046
|
+
const candidates = claudeRow?.installed ? [...claudeModelCandidates(onHost, modelConfig(), claudeRow), ...listed.filter((c) => c.provider !== "claude")] : listed;
|
|
1021
1047
|
const jevConfig = jevConfigOf(process.env);
|
|
1022
1048
|
const jev = a.consult_jev ? (ctx.jevAdapter ?? (jevConfig ? jevAdapter(jevConfig, ctx.approval?.fetchImpl ?? fetch) : undefined)) : undefined;
|
|
1023
1049
|
const configured = Boolean(jevConfig);
|
|
@@ -1355,12 +1381,20 @@ export function registerTools(server, ctx) {
|
|
|
1355
1381
|
repo: z.string().max(120).optional(),
|
|
1356
1382
|
delivery: deliveryField,
|
|
1357
1383
|
person_words: personWordsField,
|
|
1384
|
+
...launchModelFields,
|
|
1358
1385
|
...base,
|
|
1359
1386
|
},
|
|
1360
1387
|
annotations: WRITE,
|
|
1361
1388
|
}, wrap(async (a, extra) => {
|
|
1362
1389
|
const { person, auth } = who(extra);
|
|
1363
1390
|
requireContribute(auth);
|
|
1391
|
+
// A proposal starts as a run does: on its requester's default, else Claude Code, and nothing stands in (jgwill/Miadi#943).
|
|
1392
|
+
const resolution = resolveProvider(undefined, discoverProviders(ctx.providersProbe), policyOf(person.id).default_provider);
|
|
1393
|
+
if (resolution.state !== "ok")
|
|
1394
|
+
return { state: resolution.state, message: resolution.message, available: resolution.available, note: "Nothing was recorded; the proposal is unstarted." };
|
|
1395
|
+
const plan = modelPlan(resolution.provider.id, a.model, modelConfig().permitted);
|
|
1396
|
+
if ("refusal" in plan)
|
|
1397
|
+
throw new ToolRefusal(plan.refusal.code, plan.refusal.message, { permitted: plan.refusal.permitted });
|
|
1364
1398
|
const r = append("work_proposal", person, auth, {
|
|
1365
1399
|
circle: a.circle,
|
|
1366
1400
|
refs: withPrimary(a.refs, a.primary_issue),
|
|
@@ -1373,6 +1407,10 @@ export function registerTools(server, ctx) {
|
|
|
1373
1407
|
title: a.title,
|
|
1374
1408
|
desired_outcome: a.desired_outcome,
|
|
1375
1409
|
repo: a.repo,
|
|
1410
|
+
resolved_provider: resolution.provider.id,
|
|
1411
|
+
...plan.fields,
|
|
1412
|
+
...(a.task_type ? { task_type: a.task_type } : {}),
|
|
1413
|
+
...(a.criticality ? { criticality: a.criticality } : {}),
|
|
1376
1414
|
...(a.primary_issue ? { primary_issue: a.primary_issue } : {}),
|
|
1377
1415
|
...(a.delivery ? { delivery: a.delivery } : {}),
|
|
1378
1416
|
...(a.person_words ? { person_words: a.person_words } : {}),
|
|
@@ -1521,7 +1559,7 @@ export function registerTools(server, ctx) {
|
|
|
1521
1559
|
const r = append("run_request", person, auth, {
|
|
1522
1560
|
circle: "engineering", refs: [source.id, `https://youtu.be/${video}`], intention: a.intention,
|
|
1523
1561
|
idempotency_key: id, approval_state: "awaiting_approval", state: "pending",
|
|
1524
|
-
body: { task: readingTask(scope), reading: scope, ...(a.companion ? { reading_companion: a.companion } : {}), session: `reading-${id.slice(8)}`, workflow_id: id, resolved_provider: resolution.provider.id },
|
|
1562
|
+
body: { task: readingTask(scope), reading: scope, ...(a.companion ? { reading_companion: a.companion } : {}), session: `reading-${id.slice(8)}`, workflow_id: id, resolved_provider: resolution.provider.id, ...routedOn(resolution.provider.id) },
|
|
1525
1563
|
});
|
|
1526
1564
|
return { ...r, workflow_id: id, approval_url: approvalUrl(r.id), gates: ["editorial_public_import", "deep_diver", "chronicle", "cultural_reuse"] };
|
|
1527
1565
|
}));
|
|
@@ -1538,7 +1576,10 @@ export function registerTools(server, ctx) {
|
|
|
1538
1576
|
const candidate = candidates[0]?.body.reading?.artifact;
|
|
1539
1577
|
if (!candidate || candidates[0].actor.person_id !== person.id || candidate.sha256 !== a.sha256 || candidate.expected_version !== a.expected_version || candidate.expected_sha256 !== a.expected_sha256)
|
|
1540
1578
|
throw new ToolRefusal("candidate_mismatch", "Read this person's staged candidate and request its exact hash and base.");
|
|
1541
|
-
const
|
|
1579
|
+
const resolution = resolveProvider(undefined, discoverProviders(ctx.providersProbe), policyOf(person.id).default_provider);
|
|
1580
|
+
if (resolution.state !== "ok")
|
|
1581
|
+
return { state: resolution.state, note: "No runtime provider was verified; nothing was queued." };
|
|
1582
|
+
const r = append("run_request", person, auth, { circle: "story", refs: [a.workflow_id], intention: a.intention, idempotency_key: `${a.workflow_id}:import:${a.sha256}`, state: "pending", approval_state: "awaiting_approval", body: { resolved_provider: resolution.provider.id, ...routedOn(resolution.provider.id), task: "Run node packages/connector/scripts/reading.mjs import <this-run-request-id>. Only import the exact typed reading_import candidate after the service proves atomic CAS and durable idempotency; read it back exactly. Stop on any mismatch. No Deep Diver or Chronicle.", reading_import: { workflow_id: a.workflow_id, sha256: a.sha256, expected_version: a.expected_version, expected_sha256: a.expected_sha256, public_release: true }, reading_preview: { markdown: candidate.markdown, diffs: candidate.diffs, manifest: candidate.manifest } } });
|
|
1542
1583
|
return { ...r, approval_url: approvalUrl(r.id), candidate: { sha256: candidate.sha256, bytes: candidate.bytes, diff: candidate.diffs, manifest: candidate.manifest } };
|
|
1543
1584
|
}));
|
|
1544
1585
|
server.registerTool("request_authorized_run", {
|
|
@@ -1556,7 +1597,8 @@ export function registerTools(server, ctx) {
|
|
|
1556
1597
|
provider: z
|
|
1557
1598
|
.enum(["codex", "pi", "copilot", "claude"])
|
|
1558
1599
|
.optional()
|
|
1559
|
-
.describe("The provider the run should launch with, verified installed on the connector host.
|
|
1600
|
+
.describe("The provider the run should launch with, verified installed on the connector host. Leave it out for Claude Code, the default. Name another only when the person asked for that provider for this mission. Codex runs only when the person also chooses Codex for this mission on the approval page (or their own policy allows it): naming it here does not choose it for them (jgwill/Miadi#926). Unknown or unavailable leaves the mission unstarted, and nothing falls back to another provider."),
|
|
1601
|
+
...launchModelFields,
|
|
1560
1602
|
steering: z
|
|
1561
1603
|
.object({
|
|
1562
1604
|
max_attempts: z.number().int().min(1).max(20).describe("How many authorized follow-up steers this approval covers."),
|
|
@@ -1579,6 +1621,9 @@ export function registerTools(server, ctx) {
|
|
|
1579
1621
|
if (resolution.state !== "ok") {
|
|
1580
1622
|
return { state: resolution.state, message: resolution.message, available: resolution.available, note: "Nothing was recorded or queued; the mission is unstarted." };
|
|
1581
1623
|
}
|
|
1624
|
+
const plan = modelPlan(resolution.provider.id, a.model, modelConfig().permitted);
|
|
1625
|
+
if ("refusal" in plan)
|
|
1626
|
+
throw new ToolRefusal(plan.refusal.code, plan.refusal.message, { permitted: plan.refusal.permitted });
|
|
1582
1627
|
const r = append("run_request", person, auth, {
|
|
1583
1628
|
circle: a.circle,
|
|
1584
1629
|
refs: withPrimary(a.refs, a.primary_issue),
|
|
@@ -1593,6 +1638,9 @@ export function registerTools(server, ctx) {
|
|
|
1593
1638
|
cwd: a.cwd,
|
|
1594
1639
|
provider: a.provider,
|
|
1595
1640
|
resolved_provider: resolution.provider.id,
|
|
1641
|
+
...plan.fields,
|
|
1642
|
+
...(a.task_type ? { task_type: a.task_type } : {}),
|
|
1643
|
+
...(a.criticality ? { criticality: a.criticality } : {}),
|
|
1596
1644
|
...(a.primary_issue ? { primary_issue: a.primary_issue } : {}),
|
|
1597
1645
|
...(a.delivery ? { delivery: a.delivery } : {}),
|
|
1598
1646
|
...(a.person_words ? { person_words: a.person_words } : {}),
|
|
@@ -1613,6 +1661,7 @@ export function registerTools(server, ctx) {
|
|
|
1613
1661
|
// Known before anyone depends on it: whether a person can steer this run once it works (jgwill/Miadi#942).
|
|
1614
1662
|
steering: steeringOf(resolution.provider.id, resolution.provider.version),
|
|
1615
1663
|
},
|
|
1664
|
+
...(resolution.provider.id === "claude" ? { model: { requested: a.model ?? null, chosen_by: a.model ? "request" : "jev_when_approved", permitted: modelConfig().permitted } } : {}),
|
|
1616
1665
|
approval_url: approvalUrl(r.id),
|
|
1617
1666
|
...(authorization.authorized
|
|
1618
1667
|
? {}
|
|
@@ -1656,6 +1705,9 @@ export function registerTools(server, ctx) {
|
|
|
1656
1705
|
session: z.string().regex(/^[A-Za-z0-9._-]{3,80}$/).optional(),
|
|
1657
1706
|
cwd: z.string().max(300).optional(),
|
|
1658
1707
|
provider: z.enum(["codex", "pi", "copilot", "claude"]).optional().describe("Verified installed on the connector host again, as request_authorized_run does."),
|
|
1708
|
+
model: z.string().regex(MODEL_NAME).nullable().optional().describe("The Claude Code model, as request_authorized_run takes it. null removes a model named earlier, so Jev chooses."),
|
|
1709
|
+
task_type: z.enum(TASK_TYPES).optional(),
|
|
1710
|
+
criticality: z.enum(CRITICALITIES).optional(),
|
|
1659
1711
|
steering: z
|
|
1660
1712
|
.object({ max_attempts: z.number().int().min(1).max(20), expires_at: z.string().optional(), pane: z.string().regex(/^\d+\.\d+$/).optional() })
|
|
1661
1713
|
.optional(),
|
|
@@ -1695,10 +1747,25 @@ export function registerTools(server, ctx) {
|
|
|
1695
1747
|
}
|
|
1696
1748
|
}
|
|
1697
1749
|
else if (live?.kind === "work_proposal") {
|
|
1750
|
+
if (c.provider !== undefined)
|
|
1751
|
+
throw new ToolRefusal("invalid_request", "A work proposal names no provider: it runs on its requester's default, else Claude Code. To run on another provider, make a run request. Nothing was recorded.");
|
|
1698
1752
|
for (const k of ["title", "desired_outcome", "repo"])
|
|
1699
1753
|
if (c[k] !== undefined)
|
|
1700
1754
|
body[k] = c[k];
|
|
1701
1755
|
}
|
|
1756
|
+
if (live?.kind === "run_request" || live?.kind === "work_proposal") {
|
|
1757
|
+
for (const k of ["task_type", "criticality"])
|
|
1758
|
+
if (c[k] !== undefined)
|
|
1759
|
+
body[k] = c[k];
|
|
1760
|
+
if (c.model !== undefined || c.provider !== undefined) {
|
|
1761
|
+
const plan = modelPlan((body.resolved_provider ?? body.provider ?? null), c.model === undefined ? body.model : c.model, modelConfig().permitted);
|
|
1762
|
+
if ("refusal" in plan)
|
|
1763
|
+
throw new ToolRefusal(plan.refusal.code, plan.refusal.message, { permitted: plan.refusal.permitted, ...(live ? revisionOut(live) : {}) });
|
|
1764
|
+
delete body.model;
|
|
1765
|
+
delete body.model_routing;
|
|
1766
|
+
Object.assign(body, plan.fields);
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1702
1769
|
if (c.primary_issue !== undefined)
|
|
1703
1770
|
body.primary_issue = c.primary_issue;
|
|
1704
1771
|
for (const k of ["delivery", "person_words"])
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.29";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.1.
|
|
1
|
+
export const VERSION = "0.1.29";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miadi/connector",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"description": "The Miadi connector: one remote MCP service through which a person signed in with their Miadi person token, from ChatGPT or any MCP client, reads sessions, reviews, episodes and circles and records observations, inquiries, handoffs and proposals with their name on each record.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Miadi",
|