@miadi/connector 0.1.27 → 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/dist/tools.js CHANGED
@@ -20,12 +20,14 @@ 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 { CLAUDE_ADAPTER, DELIVERY_STATES, readSteerDelivery, revokeInInbox, settlementOf } from "./runtime-steer.js";
29
+ import { DELIVERY_STATES, readSteerDelivery, revokeInInbox, settlementOf, transcriptPathOf } from "./runtime-steer.js";
30
+ import { ADAPTERS, readFactoryConfig, runSteering, STEERING_CONTRACT_ID, steeringSupport } from "./steering-adapters.js";
29
31
  import { checkGrant, isBusy, steerAttempts, steeringGrantOf, steeringRevoked, steerSession } from "./steer.js";
30
32
  import { factoryLedgerPath, readFactoryReceipts, receiptsForRecord, recordsForSession } from "./factory-receipt.js";
31
33
  import { missionResult, redactResult } from "./mission-result.js";
@@ -175,18 +177,15 @@ export function githubGetter(fetchImpl = fetch, token = process.env.GITHUB_TOKEN
175
177
  /** A steer being sent now, by its record: a retry arriving during it waits for this answer and sends nothing (jgwill/Miadi#930). */
176
178
  const steersInFlight = new Map();
177
179
  export const STEERING_CONTRACT = {
180
+ contract: STEERING_CONTRACT_ID,
178
181
  busy_is_normal: true,
179
182
  connector: "Admits the steer, resolves mission → session → runtime, hands it to that session's inbox and reports what the runtime accepted. It does not watch tools or wait for idle.",
180
- runtime: "The agent's own lifecycle presents it to its model at the next supported continuation in the same turn.",
183
+ runtime: "The agent's own lifecycle presents it to its model at the next supported continuation. Each provider's adapter says which one, and what it was shown to do on a real session.",
181
184
  delivery_states: DELIVERY_STATES,
182
185
  provider_adapters: {
183
- claude: { route: "claude_hook_inbox", continuation: "PostToolUse, PostToolUseFailure, then Stop if no tool follows", needs: `${CLAUDE_ADAPTER}, loaded when the session started` },
184
- codex: { route: "unsupported" },
185
- copilot: { route: "unsupported" },
186
- pi: { route: "unsupported" },
186
+ ...Object.fromEntries(Object.values(ADAPTERS).map((a) => [a.provider, { route: a.route, level: "same_turn", continuation: a.continuation, idle: a.idle, needs: a.needs, tested_on: a.tested_on, limits: a.limits }])),
187
187
  gemini: { route: "unsupported" },
188
188
  },
189
- idle_seat: "An idle seat has no continuation coming, so its steer is typed into its bound pane once the prompt reads empty.",
190
189
  };
191
190
  export function steeringTransport(tmux) {
192
191
  if (!tmux)
@@ -199,6 +198,16 @@ function episodeRef(input) {
199
198
  // miadi-chronicle://316, miadi-chronicle:316, chronicle:<folder>, a folder, or a number
200
199
  return encodeURIComponent(input.replace(/^miadi-chronicle:(\/\/)?/, "").replace(/^chronicle:/, "").trim());
201
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
+ };
202
211
  export function registerTools(server, ctx) {
203
212
  const { config, miadi, reviews, ledger } = ctx;
204
213
  // One server is made per request, so the person a tool call runs for is this request's viewer.
@@ -238,7 +247,7 @@ export function registerTools(server, ctx) {
238
247
  body[k] = `${body[k].length} chars`;
239
248
  const receipt = r.completion_receipt ? { ...r.completion_receipt } : undefined;
240
249
  if (receipt)
241
- for (const k of ["to", "file", "session_id", "target", "artifact"])
250
+ for (const k of ["to", "file", "session_id", "target", "artifact", "model_routing"])
242
251
  delete receipt[k];
243
252
  // A steer's message names its target pane.
244
253
  if (receipt && r.kind === "session_steer_request")
@@ -353,6 +362,20 @@ export function registerTools(server, ctx) {
353
362
  const touching = (ref) => records().filter((r) => r.refs.includes(ref) || r.evidence_refs.includes(ref) || r.id === ref);
354
363
  /** The factory runner's delivery receipts, read fresh: operator data, for the write tier only. */
355
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 } : {});
369
+ const factoryConfig = () => readFactoryConfig(ctx.factoryDir ?? defaultFactoryDir());
370
+ /** A person's policy with what the operator's factory.json says for them. */
371
+ const policyOf = (personId) => providerPolicyOf(ledger.all(), personId, factoryConfig()?.person_default_provider);
372
+ /** What a new session of this provider on this host can promise, before anyone depends on it. */
373
+ const steeringOf = (providerId, cliVersion) => steeringSupport(providerId, cliVersion, { factory: factoryConfig(), ...ctx.steeringProbe });
374
+ const steeringOfCard = runSteering(() => discoverProviders(ctx.providersProbe), () => ({ factory: factoryConfig(), ...ctx.steeringProbe }));
375
+ const runProvider = (r) => {
376
+ const b = r.body;
377
+ return r.kind === "run_request" && typeof (b.resolved_provider ?? b.provider) === "string" ? String(b.resolved_provider ?? b.provider) : undefined;
378
+ };
356
379
  const github = githubGetter(ctx.approval?.fetchImpl ?? fetch);
357
380
  // ── reads ──────────────────────────────────────────────────────────────
358
381
  server.registerTool("get_capabilities", {
@@ -392,7 +415,13 @@ export function registerTools(server, ctx) {
392
415
  tools: TOOL_STATUS,
393
416
  mission_standard: ctx.draftReview ? await standardStatus(ctx.draftReview) : { state: "unavailable" },
394
417
  // Registered is not operational: whether a steer can reach a pane on this host now (jgwill/Miadi#909).
395
- steering: { ...steeringTransport(ctx.tmux), runtime_route: ctx.steeringRuntime ? "configured" : "not_configured", contract: STEERING_CONTRACT },
418
+ steering: {
419
+ ...steeringTransport(ctx.tmux),
420
+ runtime_route: ctx.steeringRuntime ? "configured" : "not_configured",
421
+ contract: STEERING_CONTRACT,
422
+ // Host truth, as provider_capabilities is: what this host would load into a new session.
423
+ ...(person.api_tier !== "write" ? {} : { on_this_host: Object.fromEntries(Object.values(ADAPTERS).map((a) => { const s = steeringOf(a.provider); return [a.provider, { steerable: s.steerable, adapter: s.adapter?.version ?? null, ...(s.reason ? { reason: s.reason } : {}) }]; })) }),
424
+ },
396
425
  foundation_read: {
397
426
  permission: FOUNDATIONS_PERMISSION,
398
427
  held: foundations,
@@ -846,6 +875,17 @@ export function registerTools(server, ctx) {
846
875
  queue: r.kind === "run_request" || r.kind === "work_proposal" ? readQueueState(r, ctx.factoryDir) : undefined,
847
876
  // Where a steer stands, joined to its id: operator detail, as mission_status has it (jgwill/Miadi#930).
848
877
  ...(r.kind === "session_steer_request" && ctx.steeringRuntime && person.api_tier === "write" ? { delivery: readSteerDelivery(ctx.steeringRuntime, all().find((x) => x.id === r.id) ?? r) ?? undefined } : {}),
878
+ // A run's corrections, each with where it stands; mission_status has the same with every receipt (jgwill/Miadi#942).
879
+ ...((r.kind === "run_request" || r.kind === "work_proposal") && ctx.steeringRuntime && person.api_tier === "write"
880
+ ? {
881
+ steers: all()
882
+ .filter((x) => x.kind === "session_steer_request" && x.refs.includes(r.id))
883
+ .flatMap((x) => {
884
+ const delivery = readSteerDelivery(ctx.steeringRuntime, x);
885
+ return delivery ? [{ id: x.id, at: x.created_at, by: x.actor.name, state: delivery.state, ...(delivery.continuation ? { continuation: delivery.continuation } : {}), ...(delivery.behavior ? { behavior: delivery.behavior } : {}), note: delivery.note }] : [];
886
+ }),
887
+ }
888
+ : {}),
849
889
  // Where the request stands, in the words every surface uses (jgwill/Miadi#889).
850
890
  projection: requestProjection(r, { reviewBase: ctx.approval?.config.reviewUrl, factoryDir: ctx.factoryDir }),
851
891
  ...(r.kind === "run_request" || r.kind === "work_proposal" ? { draft_review: reviewShownTo(ctx.draftReview?.stored(r), r, person) } : {}),
@@ -874,6 +914,7 @@ export function registerTools(server, ctx) {
874
914
  queueOf: (r) => (r.kind === "run_request" || r.kind === "work_proposal" ? readQueueState(r, ctx.factoryDir) : undefined),
875
915
  ...(writeTier && ctx.steeringRuntime
876
916
  ? {
917
+ steeringSupportOf: (providerId) => steeringOf(providerId, discoverProviders(ctx.providersProbe).find((p) => p.id === providerId)?.version),
877
918
  steerDeliveryOf: (r) => {
878
919
  const stored = all().find((x) => x.id === r.id) ?? r;
879
920
  return readSteerDelivery(ctx.steeringRuntime, stored);
@@ -907,6 +948,12 @@ export function registerTools(server, ctx) {
907
948
  }
908
949
  : undefined,
909
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,
910
957
  recordsBoundTo: writeTier ? (sessionId) => recordsForSession(receipts(), sessionId) : undefined,
911
958
  // What a result and a closure are checked against does not depend on who reads (#922 R5); only what is shown does.
912
959
  boundSessionIdsOf: (id) => receiptsForRecord(receipts(), id).flatMap((x) => (x.session_id ? [x.session_id] : [])),
@@ -937,7 +984,7 @@ export function registerTools(server, ctx) {
937
984
  }));
938
985
  server.registerTool("provider_capabilities", {
939
986
  title: "Which agent providers this host can launch",
940
- description: "The provider reality of the connector host (jgwill/Miadi#893): which agent CLIs are installed, their versions, whether sign-in evidence exists, the preference order (Pi, Copilot by default; Codex and Claude Code only when a request names them), 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.",
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.",
941
988
  inputSchema: {},
942
989
  annotations: READ,
943
990
  }, wrap(async (_args, extra) => {
@@ -947,16 +994,17 @@ export function registerTools(server, ctx) {
947
994
  preference_order: PROVIDERS.map((p) => p.id),
948
995
  explicit_only: PROVIDERS.filter((p) => !p.selectable_by_default).map((p) => p.id),
949
996
  needs_person_choice: [...CHOICE_PROVIDERS],
950
- your_policy: providerPolicyOf(ledger.all(), person.id),
997
+ your_policy: policyOf(person.id),
951
998
  policy_page: `${config.publicUrl}/providers`,
952
- providers: discoverProviders(ctx.providersProbe),
999
+ providers: discoverProviders(ctx.providersProbe).map((p) => ({ ...p, steering: steeringOf(p.id, p.version) })),
953
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." },
954
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.",
955
1003
  };
956
1004
  }));
957
1005
  server.registerTool("mission_model_preflight", {
958
1006
  title: "Which provider and model fits a mission, and how that is known",
959
- 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 only when named), 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.",
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.",
960
1008
  inputSchema: {
961
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)."),
962
1010
  task_type: z.enum(TASK_TYPES),
@@ -991,7 +1039,11 @@ export function registerTools(server, ctx) {
991
1039
  const provider = (typeof body.resolved_provider === "string" ? body.resolved_provider : typeof body.provider === "string" ? body.provider : null);
992
1040
  const basis = record.approval_state === "approved" ? "approved" : "requested";
993
1041
  const authorization = providerAuthorizationOf(record);
994
- const candidates = candidatesFor(discoverProviders(ctx.providersProbe), provider, ctx.modelOf, basis, authorization);
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;
995
1047
  const jevConfig = jevConfigOf(process.env);
996
1048
  const jev = a.consult_jev ? (ctx.jevAdapter ?? (jevConfig ? jevAdapter(jevConfig, ctx.approval?.fetchImpl ?? fetch) : undefined)) : undefined;
997
1049
  const configured = Boolean(jevConfig);
@@ -1329,12 +1381,20 @@ export function registerTools(server, ctx) {
1329
1381
  repo: z.string().max(120).optional(),
1330
1382
  delivery: deliveryField,
1331
1383
  person_words: personWordsField,
1384
+ ...launchModelFields,
1332
1385
  ...base,
1333
1386
  },
1334
1387
  annotations: WRITE,
1335
1388
  }, wrap(async (a, extra) => {
1336
1389
  const { person, auth } = who(extra);
1337
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 });
1338
1398
  const r = append("work_proposal", person, auth, {
1339
1399
  circle: a.circle,
1340
1400
  refs: withPrimary(a.refs, a.primary_issue),
@@ -1347,6 +1407,10 @@ export function registerTools(server, ctx) {
1347
1407
  title: a.title,
1348
1408
  desired_outcome: a.desired_outcome,
1349
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 } : {}),
1350
1414
  ...(a.primary_issue ? { primary_issue: a.primary_issue } : {}),
1351
1415
  ...(a.delivery ? { delivery: a.delivery } : {}),
1352
1416
  ...(a.person_words ? { person_words: a.person_words } : {}),
@@ -1489,13 +1553,13 @@ export function registerTools(server, ctx) {
1489
1553
  const existing = all().find(r => r.kind === "run_request" && r.actor.person_id === person.id && r.body.workflow_id === id);
1490
1554
  if (existing)
1491
1555
  return { ...redact(existing), workflow_id: id, approval_url: approvalUrl(existing.id), replayed: true, note: "This video's bounded request already exists; read or resume it. The new scope was not substituted." };
1492
- const resolution = resolveProvider(undefined, discoverProviders(ctx.providersProbe));
1556
+ const resolution = resolveProvider(undefined, discoverProviders(ctx.providersProbe), policyOf(person.id).default_provider);
1493
1557
  if (resolution.state !== "ok")
1494
1558
  return { state: resolution.state, note: "No runtime provider was verified; nothing was queued." };
1495
1559
  const r = append("run_request", person, auth, {
1496
1560
  circle: "engineering", refs: [source.id, `https://youtu.be/${video}`], intention: a.intention,
1497
1561
  idempotency_key: id, approval_state: "awaiting_approval", state: "pending",
1498
- 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) },
1499
1563
  });
1500
1564
  return { ...r, workflow_id: id, approval_url: approvalUrl(r.id), gates: ["editorial_public_import", "deep_diver", "chronicle", "cultural_reuse"] };
1501
1565
  }));
@@ -1512,7 +1576,10 @@ export function registerTools(server, ctx) {
1512
1576
  const candidate = candidates[0]?.body.reading?.artifact;
1513
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)
1514
1578
  throw new ToolRefusal("candidate_mismatch", "Read this person's staged candidate and request its exact hash and base.");
1515
- 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: { 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 } } });
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 } } });
1516
1583
  return { ...r, approval_url: approvalUrl(r.id), candidate: { sha256: candidate.sha256, bytes: candidate.bytes, diff: candidate.diffs, manifest: candidate.manifest } };
1517
1584
  }));
1518
1585
  server.registerTool("request_authorized_run", {
@@ -1530,7 +1597,8 @@ export function registerTools(server, ctx) {
1530
1597
  provider: z
1531
1598
  .enum(["codex", "pi", "copilot", "claude"])
1532
1599
  .optional()
1533
- .describe("The provider the run should launch with, verified installed on the connector host. Name it only when the person asked for that provider for this mission. Claude Code runs only when named. 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 Codex."),
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,
1534
1602
  steering: z
1535
1603
  .object({
1536
1604
  max_attempts: z.number().int().min(1).max(20).describe("How many authorized follow-up steers this approval covers."),
@@ -1546,12 +1614,16 @@ export function registerTools(server, ctx) {
1546
1614
  const { person, auth } = who(extra);
1547
1615
  requireContribute(auth);
1548
1616
  const found = discoverProviders(ctx.providersProbe);
1549
- const resolution = resolveProvider(a.provider, found);
1617
+ const policy = policyOf(person.id);
1618
+ const resolution = resolveProvider(a.provider, found, policy.default_provider);
1550
1619
  if (resolution.state === "provider_unknown")
1551
1620
  throw new ToolRefusal("invalid_request", resolution.message, { available: resolution.available });
1552
1621
  if (resolution.state !== "ok") {
1553
1622
  return { state: resolution.state, message: resolution.message, available: resolution.available, note: "Nothing was recorded or queued; the mission is unstarted." };
1554
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 });
1555
1627
  const r = append("run_request", person, auth, {
1556
1628
  circle: a.circle,
1557
1629
  refs: withPrimary(a.refs, a.primary_issue),
@@ -1566,6 +1638,9 @@ export function registerTools(server, ctx) {
1566
1638
  cwd: a.cwd,
1567
1639
  provider: a.provider,
1568
1640
  resolved_provider: resolution.provider.id,
1641
+ ...plan.fields,
1642
+ ...(a.task_type ? { task_type: a.task_type } : {}),
1643
+ ...(a.criticality ? { criticality: a.criticality } : {}),
1569
1644
  ...(a.primary_issue ? { primary_issue: a.primary_issue } : {}),
1570
1645
  ...(a.delivery ? { delivery: a.delivery } : {}),
1571
1646
  ...(a.person_words ? { person_words: a.person_words } : {}),
@@ -1580,9 +1655,13 @@ export function registerTools(server, ctx) {
1580
1655
  requested: a.provider ?? null,
1581
1656
  resolved: resolution.provider.id,
1582
1657
  explicit: resolution.explicit,
1658
+ ...(!a.provider && policy.default_provider ? { default_source: policy.default_provider_source } : {}),
1583
1659
  version: resolution.provider.version,
1584
1660
  authorization: authorizationOut(authorization),
1661
+ // Known before anyone depends on it: whether a person can steer this run once it works (jgwill/Miadi#942).
1662
+ steering: steeringOf(resolution.provider.id, resolution.provider.version),
1585
1663
  },
1664
+ ...(resolution.provider.id === "claude" ? { model: { requested: a.model ?? null, chosen_by: a.model ? "request" : "jev_when_approved", permitted: modelConfig().permitted } } : {}),
1586
1665
  approval_url: approvalUrl(r.id),
1587
1666
  ...(authorization.authorized
1588
1667
  ? {}
@@ -1626,6 +1705,9 @@ export function registerTools(server, ctx) {
1626
1705
  session: z.string().regex(/^[A-Za-z0-9._-]{3,80}$/).optional(),
1627
1706
  cwd: z.string().max(300).optional(),
1628
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(),
1629
1711
  steering: z
1630
1712
  .object({ max_attempts: z.number().int().min(1).max(20), expires_at: z.string().optional(), pane: z.string().regex(/^\d+\.\d+$/).optional() })
1631
1713
  .optional(),
@@ -1661,14 +1743,29 @@ export function registerTools(server, ctx) {
1661
1743
  return { state: resolution.state, message: resolution.message, available: resolution.available, note: "Nothing was recorded; the request stays at its version." };
1662
1744
  body.provider = c.provider;
1663
1745
  body.resolved_provider = resolution.provider.id;
1664
- provider = { requested: c.provider, resolved: resolution.provider.id, explicit: resolution.explicit, version: resolution.provider.version };
1746
+ provider = { requested: c.provider, resolved: resolution.provider.id, explicit: resolution.explicit, version: resolution.provider.version, steering: steeringOf(resolution.provider.id, resolution.provider.version) };
1665
1747
  }
1666
1748
  }
1667
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.");
1668
1752
  for (const k of ["title", "desired_outcome", "repo"])
1669
1753
  if (c[k] !== undefined)
1670
1754
  body[k] = c[k];
1671
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
+ }
1672
1769
  if (c.primary_issue !== undefined)
1673
1770
  body.primary_issue = c.primary_issue;
1674
1771
  for (const k of ["delivery", "person_words"])
@@ -1823,7 +1920,11 @@ export function registerTools(server, ctx) {
1823
1920
  }
1824
1921
  }
1825
1922
  const revoked = steeringRevoked(all(), grantRecord.id);
1826
- const covered = checkGrant(grant, priorAttempts, new Date(), revoked) === "ok";
1923
+ // A grant covers the person who asked for the run and the one who approved it, and the host's own service token.
1924
+ // Anyone else with the write tier asks: a person decides that one steer (jgwill/Miadi#942).
1925
+ const approver = (grantRecord.completion_receipt ?? {}).decided_by?.person_id;
1926
+ const theirs = person.id === grantRecord.actor.person_id || person.id === approver || !isPersonId(person.id);
1927
+ const covered = theirs && checkGrant(grant, priorAttempts, new Date(), revoked) === "ok";
1827
1928
  // The pane the factory delivered this mission to: the steer goes there and nowhere else (jgwill/Miadi#909).
1828
1929
  const bound = receiptsForRecord(receipts(), grantRecord.id)[0];
1829
1930
  const binding = bound
@@ -1852,8 +1953,8 @@ export function registerTools(server, ctx) {
1852
1953
  ...r,
1853
1954
  approval_url: approvalUrl(r.id),
1854
1955
  state: "awaiting_approval",
1855
- reason: !grant ? "no_grant" : checkGrant(grant, priorAttempts, new Date(), revoked),
1856
- message: "The approved run's steering grant does not cover this steer; a person's decision is requested, once, for exactly this instruction.",
1956
+ reason: !grant ? "no_grant" : !theirs ? "another_persons_mission" : checkGrant(grant, priorAttempts, new Date(), revoked),
1957
+ message: !theirs ? "This mission belongs to someone else, so its steering grant does not cover you; a person's decision is requested, once, for exactly this instruction." : "The approved run's steering grant does not cover this steer; a person's decision is requested, once, for exactly this instruction.",
1857
1958
  };
1858
1959
  }
1859
1960
  const r = append("session_steer_request", person, auth, { ...fields, approval_state: "not_required" });
@@ -1861,7 +1962,7 @@ export function registerTools(server, ctx) {
1861
1962
  let finishSend = () => { };
1862
1963
  steersInFlight.set(r.id, new Promise((resolve) => (finishSend = resolve)));
1863
1964
  try {
1864
- const result = await steerSession({ tmux: ctx.tmux, stateDir: config.stateDir, ...(ctx.steeringRuntime ? { runtime: ctx.steeringRuntime } : {}), ...(ctx.steerSettleMs !== undefined ? { settleMs: ctx.steerSettleMs } : {}) }, { record: r, grantRecord, priorAttempts, ...(binding ? { binding } : {}), ...(sameWords ? { sameInstructionSent: sameWords.id } : {}) });
1965
+ const result = await steerSession({ tmux: ctx.tmux, stateDir: config.stateDir, ...(ctx.steeringRuntime ? { runtime: ctx.steeringRuntime } : {}), ...(ctx.steerSettleMs !== undefined ? { settleMs: ctx.steerSettleMs } : {}), ...(ctx.wakeRunner ? { wakeRunner: ctx.wakeRunner } : {}) }, { record: r, grantRecord, priorAttempts, ...(binding ? { binding } : {}), ...(sameWords ? { sameInstructionSent: sameWords.id } : {}) });
1865
1966
  // A typed or forwarded steer is never "failed": failed is re-runnable, and that would send it twice (#922 R8).
1866
1967
  const delivered = result.typed || result.forwarded === true;
1867
1968
  ledger.append({
@@ -1884,6 +1985,7 @@ export function registerTools(server, ctx) {
1884
1985
  typed: result.typed,
1885
1986
  ...(result.forwarded ? { forwarded: true } : {}),
1886
1987
  ...(result.route ? { route: result.route } : {}),
1988
+ ...(result.runtime_session_id ? { runtime_session_id: result.runtime_session_id } : {}),
1887
1989
  ...(result.transcript_offset !== undefined ? { transcript_offset: result.transcript_offset } : {}),
1888
1990
  message: result.message,
1889
1991
  ...(result.target ? { target: result.target } : {}),
@@ -1954,7 +2056,9 @@ export function registerTools(server, ctx) {
1954
2056
  });
1955
2057
  }
1956
2058
  }
1957
- const sessions = [...new Set(receiptsForRecord(receipts(), grantRecord.id).map((x) => x.session_id).filter((x) => Boolean(x)))];
2059
+ // A session the runner could name only by its pane is known from the steers that reached it.
2060
+ const reached = all().filter((x) => x.kind === "session_steer_request" && x.refs.includes(grantRecord.id)).map((x) => x.completion_receipt?.runtime_session_id);
2061
+ const sessions = [...new Set([...receiptsForRecord(receipts(), grantRecord.id).map((x) => x.session_id), ...reached].filter((x) => typeof x === "string" && x.length > 0))];
1958
2062
  const inboxes = ctx.steeringRuntime
1959
2063
  ? sessions.map((session_id) => ({ session_id, ...revokeInInbox(ctx.steeringRuntime, session_id, { grant: grantRecord.id, ...(a.steer ? { steer: a.steer } : {}) }, a.reason) }))
1960
2064
  : [];
@@ -2363,7 +2467,7 @@ export function registerTools(server, ctx) {
2363
2467
  created_at: r.created_at,
2364
2468
  circle: r.circle,
2365
2469
  intention: r.intention,
2366
- consequence: consequenceOf(r, providerAuthorizationOf(r), records()),
2470
+ consequence: consequenceOf(r, providerAuthorizationOf(r), records(), runProvider(r) ? steeringOfCard(runProvider(r)) : undefined),
2367
2471
  detail: detailOf(r),
2368
2472
  ...(r.kind === "run_request" || r.kind === "work_proposal"
2369
2473
  ? {
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.1.27";
1
+ export declare const VERSION = "0.1.29";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.1.27";
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.27",
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",
@@ -24,6 +24,10 @@
24
24
  "types": "./dist/runtime-steer.d.ts",
25
25
  "import": "./dist/runtime-steer.js"
26
26
  },
27
+ "./steering-adapters": {
28
+ "types": "./dist/steering-adapters.d.ts",
29
+ "import": "./dist/steering-adapters.js"
30
+ },
27
31
  "./research-shelf": {
28
32
  "types": "./dist/research-shelf.d.ts",
29
33
  "import": "./dist/research-shelf.js"
@@ -35,7 +39,8 @@
35
39
  },
36
40
  "files": [
37
41
  "dist",
38
- "README.md"
42
+ "README.md",
43
+ "STEERING.md"
39
44
  ],
40
45
  "dependencies": {
41
46
  "@miadi/inquiry-weave": "0.18.10",