@miadi/connector 0.1.38 → 0.1.39

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
@@ -16,14 +16,15 @@ import { reviewIdOf, videoIdOf } from "./reviews.js";
16
16
  import { SCOPE_APPROVE, SCOPE_CONTRIBUTE } from "./oauth.js";
17
17
  import { CIRCLES, CIRCLE_IDS, CLAIM_CATEGORIES, DOMAINS, HANDOFF_STATES, current, newRecordId, } from "./records.js";
18
18
  import { VERSION } from "./version.js";
19
- import { AlreadyDecided, DECISIONS, DecisionConflict, KIND_LABELS, ProviderChoiceRequired, STILL_RUNNING, StaleVersion, approvalStateOf, consequenceOf, decide, decisionWaitOf, isApprovable, isBeingDecided, logDecision, readQueueState, transcriptJobIo, requestProjection, settleWithin, } from "./approve.js";
19
+ import { AlreadyDecided, DECISIONS, DecisionConflict, KIND_LABELS, ModelFloorUnmet, ProviderChoiceRequired, STILL_RUNNING, StaleVersion, approvalStateOf, approverRoutingOf, consequenceOf, decide, decisionWaitOf, isApprovable, isBeingDecided, isClaudeRouted, logDecision, readQueueState, transcriptJobIo, requestProjection, settleWithin, } from "./approve.js";
20
20
  import { RevisionRefused, requestHistory, revisionRecord, supersedeRecords, versionOf } from "./revisions.js";
21
21
  import { coverage } from "./captions.js";
22
22
  import { readingRuntimeReport } from "./reading/runtime-report.js";
23
23
  import { ensureTranscript, transcriptStatus } from "./transcript-job.js";
24
24
  import { DECISIONS_CARD_EARLIER_URIS, DECISIONS_CARD_HTML, DECISIONS_CARD_URI, DECISION_TOKENS_META } from "./decisions.js";
25
- import { CLAUDE_MODELS, CLAUDE_MODELS_VERIFIED, claudeModelCandidates, claudeModelConfig, firstModelInTranscript, JEV_WITHIN_CLAUDE, MODEL_NAME, modelPlan } from "./claude-models.js";
25
+ import { applyFloor, CLAUDE_MODELS, CLAUDE_MODELS_VERIFIED, claudeModelCandidates, claudeModelConfig, firstModelInTranscript, floorOf, floorRefusal, JEV_WITHIN_CLAUDE, labelsOf, MODEL_NAME, modelPlan, modelsMeetingFloor, } from "./claude-models.js";
26
26
  import { discoverProviders, jevConfigOf, resolveProvider, routerPreflight, PROVIDERS } from "./providers.js";
27
+ import { MODEL_ASPECT } from "./mission-standard.js";
27
28
  import { authorizesActions, missionStatus, primaryIssueOf, resolveMissionSubject } from "./mission-status.js";
28
29
  import { authorizationReceipt, authorizeProvider, CHOICE_PROVIDERS, isPersonId, needsPersonChoice, providerPolicyOf } from "./provider-policy.js";
29
30
  import { candidatesFor, CRITICALITIES, jevAdapter, modelPreflight, PREFLIGHT_CONTRACT, PREFLIGHT_VERSION, TASK_TYPES, } from "./model-preflight.js";
@@ -52,7 +53,14 @@ async function standardStatus(service) {
52
53
  version: standard.version,
53
54
  source: standard.source,
54
55
  ...(standard.note ? { note: standard.note } : {}),
55
- aspects: standard.aspects.map((a) => ({ code: a.code, name: a.name, requires: a.requires, settled_by: a.settled_by })),
56
+ // S7 is checked in code while the stored standard has none of its own (jgwill/Miadi#1028).
57
+ aspects: [...standard.aspects, ...(standard.aspects.some((a) => a.code === MODEL_ASPECT.code) ? [] : [{ ...MODEL_ASPECT, checked_in: "code" }])].map((a) => ({
58
+ code: a.code,
59
+ name: a.name,
60
+ requires: a.requires,
61
+ settled_by: a.settled_by,
62
+ ...("checked_in" in a ? { checked_in: a.checked_in } : {}),
63
+ })),
56
64
  jev: service.jevConfigured ? "configured" : "unconfigured",
57
65
  };
58
66
  }
@@ -221,8 +229,16 @@ const launchModelFields = {
221
229
  .regex(MODEL_NAME)
222
230
  .optional()
223
231
  .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."),
224
- 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."),
225
- criticality: z.enum(CRITICALITIES).optional().describe("Default normal."),
232
+ task_type: z
233
+ .enum(TASK_TYPES)
234
+ .optional()
235
+ .describe("The kind of task, which with criticality is all Jev learns of it when it chooses the model. Set it: left out, the task is labelled implementation, which the fit notes give to Sonnet, and the draft review and the approval page say the label was a default."),
236
+ criticality: z.enum(CRITICALITIES).optional().describe("Left out, normal, and the approval page says it was a default."),
237
+ model_floor: z
238
+ .string()
239
+ .regex(MODEL_NAME)
240
+ .optional()
241
+ .describe("The weakest Claude Code model this mission may run on (opus, sonnet, haiku or fable), when the person's words set a floor such as \"needs a high-reasoning model\" or \"at least opus\". Jev then chooses only among permitted models at or above it, and reads no words. When no permitted model meets it, approving is refused and the approval page says so before the click."),
226
242
  };
227
243
  export function registerTools(server, ctx) {
228
244
  const { config, miadi, reviews, ledger } = ctx;
@@ -382,6 +398,19 @@ export function registerTools(server, ctx) {
382
398
  const receipts = () => readFactoryReceipts(factoryLedgerPath(ctx.factoryDir ?? defaultFactoryDir()));
383
399
  /** The Claude Code models this host permits, and the one it falls back to (jgwill/Miadi#943). */
384
400
  const modelConfig = () => claudeModelConfig(ctx.factoryDir ?? defaultFactoryDir(), ctx.modelOf);
401
+ /** What the card offers a person approving with changes, and what the mission is chosen from now (jgwill/Miadi#1029). */
402
+ const modelChoiceOf = (r) => {
403
+ const b = r.body;
404
+ const config = modelConfig();
405
+ const t = labelsOf(b);
406
+ const floor = floorOf(b);
407
+ const named = typeof b.model === "string" && b.model ? b.model : null;
408
+ return {
409
+ permitted: config.permitted,
410
+ ...(named ? { requested_model: named } : { task_types: TASK_TYPES, criticalities: CRITICALITIES, labels: { task_type: { value: t.type, set_by: t.labels.task_type }, criticality: { value: t.criticality, set_by: t.labels.criticality } } }),
411
+ ...(floor ? { floor, met_by: modelsMeetingFloor(config, floor) } : {}),
412
+ };
413
+ };
385
414
  /** The body mark of a request whose model Jev chooses, when it runs on Claude Code. */
386
415
  const routedOn = (provider) => (provider === "claude" ? { model_routing: JEV_WITHIN_CLAUDE } : {});
387
416
  const factoryConfig = () => readFactoryConfig(ctx.factoryDir ?? defaultFactoryDir());
@@ -1183,8 +1212,8 @@ export function registerTools(server, ctx) {
1183
1212
  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.",
1184
1213
  inputSchema: {
1185
1214
  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)."),
1186
- task_type: z.enum(TASK_TYPES),
1187
- criticality: z.enum(CRITICALITIES).default("normal"),
1215
+ task_type: z.enum(TASK_TYPES).optional().describe("Left out, the mission's own: the approver's when they set one, else the requester's, else the default a launch uses. labels says which (jgwill/Miadi#1028)."),
1216
+ criticality: z.enum(CRITICALITIES).optional().describe("Left out, the mission's own, as task_type."),
1188
1217
  consult_jev: z.boolean().default(false).describe("Ask Jev to choose among the eligible options. Charged by Jev; off by default."),
1189
1218
  launch: z
1190
1219
  .object({
@@ -1219,12 +1248,16 @@ export function registerTools(server, ctx) {
1219
1248
  const listed = candidatesFor(onHost, provider, ctx.modelOf, basis, authorization);
1220
1249
  const claudeRow = listed.find((c) => c.provider === "claude");
1221
1250
  // The same options a launch offers Jev, so a consult here is a dry run of it (jgwill/Miadi#943).
1222
- const candidates = claudeRow?.installed ? [...claudeModelCandidates(onHost, modelConfig(), claudeRow), ...listed.filter((c) => c.provider !== "claude")] : listed;
1251
+ // The mission's own floor narrows the Claude Code options as it does at launch (jgwill/Miadi#1028).
1252
+ const candidates = claudeRow?.installed ? [...applyFloor(claudeModelCandidates(onHost, modelConfig(), claudeRow), floorOf(body)), ...listed.filter((c) => c.provider !== "claude")] : listed;
1253
+ // The labels a launch reads, unless the caller names its own: the approver's fields, else the requester's, else the default.
1254
+ const changes = record.completion_receipt?.routing_changes;
1255
+ const own = labelsOf(body, changes);
1223
1256
  const jevConfig = jevConfigOf(process.env);
1224
1257
  const jev = a.consult_jev ? (ctx.jevAdapter ?? (jevConfig ? jevAdapter(jevConfig, ctx.approval?.fetchImpl ?? fetch) : undefined)) : undefined;
1225
1258
  const configured = Boolean(jevConfig);
1226
1259
  const primary = primaryIssueOf(record);
1227
- return modelPreflight({
1260
+ const answer = await modelPreflight({
1228
1261
  mission: {
1229
1262
  id: record.id,
1230
1263
  resolution: found.resolution,
@@ -1233,13 +1266,14 @@ export function registerTools(server, ctx) {
1233
1266
  },
1234
1267
  approved_provider: provider,
1235
1268
  provider_basis: basis,
1236
- task: a.task_type,
1237
- criticality: a.criticality,
1269
+ task: a.task_type ?? own.type,
1270
+ criticality: a.criticality ?? own.criticality,
1238
1271
  candidates,
1239
1272
  ...(authorization ? { provider_authorization: authorizationOut(authorization) } : {}),
1240
1273
  ...(a.launch ? { launch: a.launch } : {}),
1241
1274
  ...(jev ? { adapter: jev } : { routerWhenAbsent: configured ? "not_requested" : "router_unconfigured" }),
1242
1275
  });
1276
+ return { ...answer, labels: { task_type: a.task_type ? "caller" : own.labels.task_type, criticality: a.criticality ? "caller" : own.labels.criticality } };
1243
1277
  }));
1244
1278
  // search / fetch: the pair ChatGPT uses for connectors in search and deep research.
1245
1279
  server.registerTool("search", {
@@ -1582,7 +1616,7 @@ export function registerTools(server, ctx) {
1582
1616
  const resolution = resolveProvider(undefined, discoverProviders(ctx.providersProbe), policyOf(person.id).default_provider);
1583
1617
  if (resolution.state !== "ok")
1584
1618
  return { state: resolution.state, message: resolution.message, available: resolution.available, note: "Nothing was recorded; the proposal is unstarted." };
1585
- const plan = modelPlan(resolution.provider.id, a.model, modelConfig().permitted);
1619
+ const plan = modelPlan(resolution.provider.id, a.model, modelConfig().permitted, a.model_floor);
1586
1620
  if ("refusal" in plan)
1587
1621
  throw new ToolRefusal(plan.refusal.code, plan.refusal.message, { permitted: plan.refusal.permitted });
1588
1622
  const capabilities = a.capabilities?.length ? declareCapabilities(a.capabilities) : undefined;
@@ -1851,7 +1885,7 @@ export function registerTools(server, ctx) {
1851
1885
  if (resolution.state !== "ok") {
1852
1886
  return { state: resolution.state, message: resolution.message, available: resolution.available, note: "Nothing was recorded or queued; the mission is unstarted." };
1853
1887
  }
1854
- const plan = modelPlan(resolution.provider.id, a.model, modelConfig().permitted);
1888
+ const plan = modelPlan(resolution.provider.id, a.model, modelConfig().permitted, a.model_floor);
1855
1889
  if ("refusal" in plan)
1856
1890
  throw new ToolRefusal(plan.refusal.code, plan.refusal.message, { permitted: plan.refusal.permitted });
1857
1891
  const capabilities = a.capabilities?.length ? declareCapabilities(a.capabilities) : undefined;
@@ -1893,7 +1927,9 @@ export function registerTools(server, ctx) {
1893
1927
  // Known before anyone depends on it: whether a person can steer this run once it works (jgwill/Miadi#942).
1894
1928
  steering: steeringOf(resolution.provider.id, resolution.provider.version),
1895
1929
  },
1896
- ...(resolution.provider.id === "claude" ? { model: { requested: a.model ?? null, chosen_by: a.model ? "request" : "jev_when_approved", permitted: modelConfig().permitted } } : {}),
1930
+ ...(resolution.provider.id === "claude"
1931
+ ? { model: { requested: a.model ?? null, chosen_by: a.model ? "request" : "jev_when_approved", permitted: modelConfig().permitted, ...(a.model_floor ? { floor: a.model_floor, met_by: modelsMeetingFloor(modelConfig(), a.model_floor) } : {}) } }
1932
+ : {}),
1897
1933
  approval_url: approvalUrl(r.id),
1898
1934
  ...(authorization.authorized
1899
1935
  ? {}
@@ -1939,6 +1975,7 @@ export function registerTools(server, ctx) {
1939
1975
  cwd: z.string().max(300).optional(),
1940
1976
  provider: z.enum(["codex", "pi", "copilot", "claude"]).optional().describe("Verified installed on the connector host again, as request_authorized_run does."),
1941
1977
  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."),
1978
+ model_floor: z.string().regex(MODEL_NAME).nullable().optional().describe("The weakest Claude Code model the mission may run on, as request_authorized_run takes it. null removes it."),
1942
1979
  task_type: z.enum(TASK_TYPES).optional(),
1943
1980
  criticality: z.enum(CRITICALITIES).optional(),
1944
1981
  steering: z
@@ -1990,12 +2027,14 @@ export function registerTools(server, ctx) {
1990
2027
  for (const k of ["task_type", "criticality"])
1991
2028
  if (c[k] !== undefined)
1992
2029
  body[k] = c[k];
1993
- if (c.model !== undefined || c.provider !== undefined) {
1994
- const plan = modelPlan((body.resolved_provider ?? body.provider ?? null), c.model === undefined ? body.model : c.model, modelConfig().permitted);
2030
+ if (c.model !== undefined || c.provider !== undefined || c.model_floor !== undefined) {
2031
+ const floor = c.model_floor === undefined ? body.model_floor : c.model_floor;
2032
+ const plan = modelPlan((body.resolved_provider ?? body.provider ?? null), c.model === undefined ? body.model : c.model, modelConfig().permitted, floor);
1995
2033
  if ("refusal" in plan)
1996
2034
  throw new ToolRefusal(plan.refusal.code, plan.refusal.message, { permitted: plan.refusal.permitted, ...(live ? revisionOut(live) : {}) });
1997
2035
  delete body.model;
1998
2036
  delete body.model_routing;
2037
+ delete body.model_floor;
1999
2038
  Object.assign(body, plan.fields);
2000
2039
  }
2001
2040
  }
@@ -2721,7 +2760,7 @@ export function registerTools(server, ctx) {
2721
2760
  created_at: r.created_at,
2722
2761
  circle: r.circle,
2723
2762
  intention: r.intention,
2724
- consequence: consequenceOf(r, providerAuthorizationOf(r), records(), runProvider(r) ? steeringOfCard(runProvider(r)) : undefined),
2763
+ consequence: consequenceOf(r, providerAuthorizationOf(r), records(), runProvider(r) ? steeringOfCard(runProvider(r)) : undefined, Boolean(floorRefusal(r, undefined, modelConfig()))),
2725
2764
  detail: detailOf(r),
2726
2765
  ...(r.kind === "run_request" || r.kind === "work_proposal"
2727
2766
  ? {
@@ -2730,6 +2769,7 @@ export function registerTools(server, ctx) {
2730
2769
  draft_review: ctx.draftReview?.stored(r) ?? null,
2731
2770
  }
2732
2771
  : {}),
2772
+ ...(isClaudeRouted(r) ? { model_choice: modelChoiceOf(r) } : {}),
2733
2773
  ...(r.kind === "run_request" ? { provider_authorization: authorizationOut(providerAuthorizationOf(r)) } : {}),
2734
2774
  approval_url: approvalUrl(r.id),
2735
2775
  projection: requestProjection(r, { reviewBase: ctx.approval?.config.reviewUrl, factoryDir: ctx.factoryDir }),
@@ -2765,6 +2805,9 @@ export function registerTools(server, ctx) {
2765
2805
  record_id: z.string().min(1),
2766
2806
  decision: z.enum(DECISIONS),
2767
2807
  instructions: z.string().max(20000).optional(),
2808
+ model: z.string().max(80).optional().describe("Approve with my changes: the Claude Code model this mission runs on, from the permitted list. It wins over the request's model and over Jev."),
2809
+ task_type: z.enum(TASK_TYPES).optional().describe("Approve with my changes: the task type Jev chooses the model from, in place of the request's."),
2810
+ criticality: z.enum(CRITICALITIES).optional().describe("Approve with my changes: the criticality Jev chooses the model from, in place of the request's."),
2768
2811
  decision_token: z.string().min(10).max(200),
2769
2812
  },
2770
2813
  annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true },
@@ -2799,14 +2842,21 @@ export function registerTools(server, ctx) {
2799
2842
  if (check !== "ok")
2800
2843
  throw new ToolRefusal("invalid_token", "This decision did not come from the person's card.");
2801
2844
  const instructions = a.instructions?.trim() || undefined;
2802
- if (r.approval_state === "awaiting_approval" && !isBeingDecided(r.id) && (a.decision === "approve_with_changes" || a.decision === "request_revision") && !instructions) {
2803
- throw new ToolRefusal("instructions_required", a.decision === "request_revision" ? "Say what to revise." : "Write the changes to apply.");
2845
+ // The model fields take part in the choice, checked as the approval page checks them (jgwill/Miadi#1029).
2846
+ const fields = approverRoutingOf(r, { model: a.model, task_type: a.task_type, criticality: a.criticality }, modelConfig().permitted);
2847
+ if ("refusal" in fields)
2848
+ throw new ToolRefusal(fields.refusal.code, fields.refusal.message, fields.refusal.permitted ? { permitted: fields.refusal.permitted } : undefined);
2849
+ if (fields.routing && a.decision !== "approve_with_changes")
2850
+ throw new ToolRefusal("fields_need_changes", "A model field changes the request: decide it with approve_with_changes.");
2851
+ const routing = fields.routing;
2852
+ if (r.approval_state === "awaiting_approval" && !isBeingDecided(r.id) && ((a.decision === "approve_with_changes" && !routing) || a.decision === "request_revision") && !instructions) {
2853
+ throw new ToolRefusal("instructions_required", a.decision === "request_revision" ? "Say what to revise." : "Write the changes to apply, or set a model field.");
2804
2854
  }
2805
2855
  const client = ctx.oauthState.read().clients[auth.clientId];
2806
2856
  const via = `card:${String(client?.client_name ?? auth.clientId).slice(0, 50)}`;
2807
2857
  let decided;
2808
2858
  try {
2809
- const running = decide(r, person, a.decision, ctx.approval, { instructions, via, expectedVersion: versionOf(r) });
2859
+ const running = decide(r, person, a.decision, ctx.approval, { instructions, ...(routing ? { routing } : {}), via, expectedVersion: versionOf(r) });
2810
2860
  // A host gives up on a call after about a minute and may send it again; a review create can take longer.
2811
2861
  // Past the bound the answer is the decision, recorded and running, and the card follows it to its outcome (#924).
2812
2862
  const settled = await settleWithin(running, decisionWaitOf(ctx.approval));
@@ -2836,6 +2886,8 @@ export function registerTools(server, ctx) {
2836
2886
  }
2837
2887
  if (error instanceof StaleVersion)
2838
2888
  throw new ToolRefusal("stale_version", error.message, { projection: projectionNow(), approval_url: approvalUrl(r.id) });
2889
+ if (error instanceof ModelFloorUnmet)
2890
+ throw new ToolRefusal("model_floor_unmet", error.message, { approval_url: approvalUrl(r.id) });
2839
2891
  // A different decision recorded a moment earlier, by another click or client, is reported with where it stands.
2840
2892
  if (error instanceof DecisionConflict)
2841
2893
  throw new ToolRefusal("decision_conflict", error.message, { projection: projectionNow() });
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.1.38";
1
+ export declare const VERSION = "0.1.39";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.1.38";
1
+ export const VERSION = "0.1.39";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miadi/connector",
3
- "version": "0.1.38",
3
+ "version": "0.1.39",
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",
@@ -51,7 +51,7 @@
51
51
  "STEERING.md"
52
52
  ],
53
53
  "dependencies": {
54
- "@miadi/hooks-core": "^0.6.1",
54
+ "@miadi/hooks-core": "^0.6.2",
55
55
  "@miadi/hooks-gateway": "^0.2.1",
56
56
  "@miadi/inquiry-weave": "0.18.14",
57
57
  "@miadi/node-service-kit": "0.1.2",