@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.
@@ -36,11 +36,21 @@ const ROUTING_TIMEOUT_MS = 8_000;
36
36
  export const MODEL_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,79}$/;
37
37
  /** Each answered a real prompt under `--model <id>` and under its full name. */
38
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." },
39
+ { id: "opus", resolves_to: "claude-opus-5-5", rank: 3, 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", rank: 2, capability_note: "The fit for an implementation task at normal criticality." },
41
+ { id: "haiku", resolves_to: "claude-haiku-5-5", rank: 1, 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", rank: 4, capability_note: "The fit for an architecture_refactor task and for any security_critical task: the most capable model." },
43
43
  ];
44
+ /** A model's place in the family, by alias or full name; null for a name outside the catalog. */
45
+ export function modelRank(model) {
46
+ return CLAUDE_MODELS.find((m) => m.id === model || m.resolves_to === model)?.rank ?? null;
47
+ }
48
+ /** Whether a model is at or above a floor. A model outside the catalog meets no floor: its strength is not known. */
49
+ export function meetsFloor(model, floor) {
50
+ const have = modelRank(model);
51
+ const need = modelRank(floor);
52
+ return have !== null && need !== null && have >= need;
53
+ }
44
54
  /** A run under one name proves that name on that host that day, and says nothing of a sign-in elsewhere. */
45
55
  export const CLAUDE_MODELS_VERIFIED = {
46
56
  on: "2026-11-07",
@@ -67,8 +77,16 @@ export function claudeModelConfig(dir = factoryDir(), modelOf = (p) => configure
67
77
  export function isPermittedModel(model, permitted) {
68
78
  return permitted.includes(model) || CLAUDE_MODELS.some((m) => m.resolves_to === model && permitted.includes(m.id));
69
79
  }
70
- /** What a request records about its model, or why it may not be recorded. */
71
- export function modelPlan(provider, model, permitted) {
80
+ /** What a request records about its model and its floor, or why it may not be recorded. */
81
+ export function modelPlan(provider, model, permitted, floor) {
82
+ if (floor) {
83
+ if (provider !== "claude") {
84
+ return { refusal: { code: "model_provider_mismatch", message: `A model floor (${floor}) is a floor among Claude Code models and this request runs on ${provider ?? "no provider"}. Nothing was recorded; remove the floor or run it on claude.`, permitted } };
85
+ }
86
+ if (modelRank(floor) === null) {
87
+ return { refusal: { code: "model_floor_unknown", message: `${floor} is not a model this connector can place in the family (${CLAUDE_MODELS.map((m) => m.id).join(", ")}). Nothing was recorded.`, permitted } };
88
+ }
89
+ }
72
90
  if (model) {
73
91
  if (provider !== "claude") {
74
92
  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 } };
@@ -76,9 +94,18 @@ export function modelPlan(provider, model, permitted) {
76
94
  if (!isPermittedModel(model, permitted)) {
77
95
  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
96
  }
79
- return { fields: { model } };
97
+ if (floor && !meetsFloor(model, floor)) {
98
+ return { refusal: { code: "model_below_floor", message: `${model} is below the floor this request states (${floor}). Nothing was recorded; name a model at or above it, or remove one of the two.`, permitted } };
99
+ }
100
+ return { fields: { model, ...(floor ? { model_floor: floor } : {}) } };
80
101
  }
81
- return { fields: provider === "claude" ? { model_routing: JEV_WITHIN_CLAUDE } : {} };
102
+ return { fields: provider === "claude" ? { model_routing: JEV_WITHIN_CLAUDE, ...(floor ? { model_floor: floor } : {}) } : {} };
103
+ }
104
+ /** The permitted models at or above a floor, in the order a launch offers them. */
105
+ export function modelsMeetingFloor(config, floor) {
106
+ const sameAsConfigured = (name) => CLAUDE_MODELS.find((m) => m.id === name)?.resolves_to === config.configured;
107
+ const names = [...new Set([...(config.configured ? [config.configured] : []), ...config.permitted.filter((n) => !sameAsConfigured(n))])];
108
+ return names.filter((n) => meetsFloor(n, floor));
82
109
  }
83
110
  /** One candidate per permitted model, the configured one first: Jev's options, and the preflight's. */
84
111
  export function claudeModelCandidates(found, config, base) {
@@ -111,21 +138,60 @@ export function claudeModelCandidates(found, config, base) {
111
138
  };
112
139
  });
113
140
  }
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
- });
141
+ /** The effort a launch runs at is not chosen here: the seat starts at Claude Code's own setting on the host that opens it (jgwill/Miadi#1028). */
142
+ export const EFFORT_NOT_ROUTED = {
143
+ routed: false,
144
+ note: "No reasoning effort is passed with the model: the seat starts at the effortLevel of Claude Code's settings on the host that opens it (managed settings first, then the user's).",
145
+ };
146
+ /** The labels a mission's model is chosen from, and who set each: the approver's field, else the request's, else the default. */
147
+ export function labelsOf(b, approver) {
148
+ const requested = { task_type: typeof b.task_type === "string" ? b.task_type : undefined, criticality: typeof b.criticality === "string" ? b.criticality : undefined };
149
+ const type = approver?.task_type ?? requested.task_type ?? "implementation";
150
+ const criticality = approver?.criticality ?? requested.criticality ?? "normal";
151
+ return {
152
+ type,
153
+ criticality,
154
+ labels: {
155
+ task_type: approver?.task_type ? "approver" : requested.task_type ? "requester" : "default",
156
+ criticality: approver?.criticality ? "approver" : requested.criticality ? "requester" : "default",
157
+ },
158
+ };
159
+ }
160
+ /** The floor a request states in model_floor, or null. */
161
+ export function floorOf(b) {
162
+ return typeof b.model_floor === "string" && b.model_floor ? b.model_floor : null;
163
+ }
164
+ /** Candidates below a floor stay listed, ineligible, with why: Jev is offered only what meets it, and reads no words. */
165
+ export function applyFloor(candidates, floor) {
166
+ if (!floor)
167
+ return candidates;
168
+ return candidates.map((c) => (c.eligible && c.model_id && !meetsFloor(c.model_id, floor) ? { ...c, eligible: false, policy_reason: `Below the floor the request sets (${floor}).` } : c));
169
+ }
170
+ /** Why approving would launch nothing: no permitted model meets the request's floor, and the approver named none. Null when it can launch. */
171
+ export function floorRefusal(record, approver, config) {
172
+ const b = (record.body ?? {});
173
+ const floor = floorOf(b);
174
+ if (!floor || approver?.model || (typeof b.model === "string" && b.model) || b.model_routing !== JEV_WITHIN_CLAUDE)
175
+ return null;
176
+ if (modelsMeetingFloor(config, floor).length)
177
+ return null;
178
+ return `No permitted Claude Code model on this host meets the floor this request sets (${floor}); the permitted ones are ${config.permitted.join(", ")}. Nothing was approved. Name a model under Approve with my changes, send it back to change its floor, or decline.`;
179
+ }
118
180
  /**
119
181
  * The model of one mission's launch, or null when this mission's model is not routed: another
120
182
  * provider, or a request recorded before routing. Asked at most once for a version: a brief written
121
183
  * again for it (a rerun) keeps the answer, because a lost answer may already have been charged.
184
+ *
185
+ * The approver's fields (jgwill/Miadi#1029) take part: a model they name launches as theirs and Jev
186
+ * is not asked; a task type or criticality they set replaces the request's in what Jev is sent.
187
+ * Their instructions are text and do not, and the receipt says so.
122
188
  */
123
189
  export async function routeModel(record, opts, deps = {}) {
124
190
  const b = (record.body ?? {});
125
191
  const version = versionOf(record);
126
192
  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)
193
+ const requested = typeof b.model === "string" && b.model ? b.model : null;
194
+ if (!requested && b.model_routing !== JEV_WITHIN_CLAUDE)
129
195
  return null;
130
196
  if (opts.existingSession)
131
197
  return { ...base, model: null, source: "existing_session" };
@@ -134,14 +200,31 @@ export async function routeModel(record, opts, deps = {}) {
134
200
  const missing = !found[0]?.installed ? "is not installed" : found[0].auth_evidence !== "found" ? "shows no sign-in" : null;
135
201
  if (missing)
136
202
  return { ...base, model: null, source: "unavailable", why: `Claude Code ${missing} on the connector host` };
137
- if (explicit)
138
- return { ...base, model: explicit, source: "request" };
203
+ const approver = opts.approver ?? {};
204
+ const config = claudeModelConfig(deps.factoryDir ?? factoryDir(), deps.modelOf);
205
+ const floor = floorOf(b);
206
+ const said = {
207
+ ...(floor ? { floor: { model: floor, set_by: "requester", met_by: modelsMeetingFloor(config, floor) } } : {}),
208
+ ...(opts.instructions ? { instructions: { took_part: false, note: "The approver's instructions went to the agent in its brief and were not read for the model: only the model, task type and criticality fields take part." } } : {}),
209
+ effort: EFFORT_NOT_ROUTED,
210
+ };
211
+ if (approver.model)
212
+ return { ...base, model: approver.model, source: "approver", replaced: { model: requested }, ...said };
213
+ if (requested)
214
+ return { ...base, model: requested, source: "request", ...said };
139
215
  const prior = record.completion_receipt?.model_routing;
140
216
  if (prior?.decided_for?.record === record.id && prior.decided_for.version === version && prior.source !== "unavailable" && prior.source !== "existing_session")
141
217
  return prior;
142
- const config = claudeModelConfig(deps.factoryDir ?? factoryDir(), deps.modelOf);
143
- const candidates = claudeModelCandidates(found, config);
144
- const task = taskOf(b);
218
+ const candidates = applyFloor(claudeModelCandidates(found, config), floor);
219
+ if (floor && !candidates.some((c) => c.eligible)) {
220
+ return { ...base, model: null, source: "unavailable", why: `No permitted Claude Code model on the connector host meets the floor this request sets (${floor})`, ...said };
221
+ }
222
+ const { labels, ...task } = labelsOf(b, approver);
223
+ const asked = labelsOf(b);
224
+ const replaced = {
225
+ ...(labels.task_type === "approver" ? { task_type: asked.type } : {}),
226
+ ...(labels.criticality === "approver" ? { criticality: asked.criticality } : {}),
227
+ };
145
228
  const jev = deps.adapter ? null : jevConfigOf(deps.env ?? process.env);
146
229
  const adapter = deps.adapter ?? (jev ? jevAdapter(jev, deps.fetchImpl ?? fetch, ROUTING_TIMEOUT_MS) : undefined);
147
230
  const answer = await modelPreflight({
@@ -154,12 +237,18 @@ export async function routeModel(record, opts, deps = {}) {
154
237
  });
155
238
  const chosen = answer.state === "recommended" && answer.decider.router === "answered" ? (answer.recommendation.model_id ?? null) : null;
156
239
  const reasons = chosen ? [] : answer.recommendation.abstain_reasons.length ? answer.recommendation.abstain_reasons : [answer.decider.router];
240
+ // Without Jev's choice the configured model launches, unless it is below the floor: then the first permitted model at or above it.
241
+ const belowFloor = Boolean(floor && config.configured && !meetsFloor(config.configured, floor));
242
+ const fallback = belowFloor ? (candidates.find((c) => c.eligible)?.model_id ?? null) : config.configured;
157
243
  return {
158
244
  ...base,
159
- model: chosen ?? config.configured,
160
- source: chosen ? "jev" : config.configured ? "configured_fallback" : "cli_default",
161
- ...(chosen ? {} : { fallback_reasons: reasons }),
245
+ model: chosen ?? fallback,
246
+ source: chosen ? "jev" : fallback ? "configured_fallback" : "cli_default",
247
+ ...(chosen ? {} : { fallback_reasons: belowFloor ? [...reasons, "configured_below_floor"] : reasons }),
162
248
  task,
249
+ labels,
250
+ ...(Object.keys(replaced).length ? { replaced } : {}),
251
+ ...said,
163
252
  eligible: candidates.filter((c) => c.eligible).map((c) => c.model_id),
164
253
  decider: {
165
254
  source: answer.decider.source,
@@ -28,4 +28,4 @@ export declare class DecisionTokens {
28
28
  * and calls `decide_request` through the host. In a host without that bridge it
29
29
  * shows each request's approval page instead.
30
30
  */
31
- export declare const DECISIONS_CARD_HTML = "<!doctype html>\n<html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n<style>\n:root{color-scheme:light dark;--fg:#1d1b18;--muted:#5b5650;--line:#d9d4cc;--accent:#7a4a00;--ok:#1d6b3a;--err:#b00020;--chip:#f1ede6}\n@media (prefers-color-scheme:dark){:root{--fg:#ece8e1;--muted:#b3ada4;--line:#3a3631;--accent:#ffd700;--ok:#7fd49b;--err:#ff8a80;--chip:#24211d}}\n*{box-sizing:border-box}\nbody{margin:0;color:var(--fg);font:15px/1.45 system-ui,sans-serif;background:transparent}\nmain{padding:12px;display:grid;gap:12px}\n.empty,.note{color:var(--muted)}\narticle{border:1px solid var(--line);border-radius:10px;padding:12px}\nh2{font-size:15px;margin:0 0 4px}\n.kind{display:inline-block;font-size:12px;padding:1px 8px;border-radius:999px;background:var(--chip);color:var(--muted);margin-bottom:6px}\n.meta{font-size:13px;color:var(--muted);margin:0 0 6px}\n.does{margin:6px 0;font-weight:600}\ndetails{margin:6px 0}\nsummary{cursor:pointer;color:var(--muted);font-size:13px}\npre{white-space:pre-wrap;overflow-wrap:anywhere;font-size:12px;margin:6px 0 0;max-height:240px;overflow:auto}\ntextarea{width:100%;min-height:64px;padding:8px;border:1px solid var(--line);border-radius:8px;background:transparent;color:var(--fg);font:inherit;margin-top:8px}\n.row{display:flex;flex-wrap:wrap;gap:8px;margin-top:8px}\nbutton{padding:8px 12px;border-radius:8px;border:1px solid var(--line);background:transparent;color:var(--fg);font:inherit;cursor:pointer;min-height:40px}\nbutton.primary{border-color:var(--accent);outline:1px solid var(--accent)}\nbutton:focus-visible,a:focus-visible,textarea:focus-visible{outline:2px solid var(--accent);outline-offset:2px}\nbutton[disabled]{opacity:.55;cursor:default}\na{color:inherit}\n.done{color:var(--ok);font-weight:600}\n.std{border-top:1px solid var(--line);margin:8px 0;padding-top:8px;display:grid;gap:8px}\nh3{font-size:14px;margin:0;font-weight:600}\n.aspects{list-style:none;margin:4px 0;padding:0;display:grid;gap:14px}\n.asp{display:grid;grid-template-columns:16px 1fr;gap:6px;font-size:14px;overflow-wrap:anywhere}\n.asp .gl{margin-top:3px;color:var(--muted);display:block}\n.asp p{margin:1px 0}\n.asp .nm{color:var(--muted)}\n.asp .ask{font-weight:600}\n.asp details{margin:0}\n.asp details[open]{border-left:2px solid var(--accent);padding-left:8px;margin-top:2px}\n.asp summary{padding:8px 0}\n.who{display:flex;gap:8px;align-items:center}\n.who .settler{flex:1}\n.yours .settler{color:var(--fg);font-weight:600}\n.yours .gl{color:var(--accent)}\n.iconbtn{min-height:34px;width:34px;padding:0;display:inline-grid;place-items:center;flex:none;border-color:var(--accent);color:var(--accent)}\n.openL{display:none}\ndetails[open]>summary .openL{display:inline}\ndetails[open]>summary .closedL{display:none}\n.fact{margin:0;font-size:14px;overflow-wrap:anywhere}\n.code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:13px}\n.small{font-size:13px;color:var(--muted);margin:0;overflow-wrap:anywhere}\nblockquote{margin:4px 0 0;padding-left:8px;border-left:2px solid var(--line);font-size:14px;overflow-wrap:anywhere}\nsummary:focus-visible{outline:2px solid var(--accent);outline-offset:2px}\n</style></head><body><main id=\"root\" aria-live=\"polite\"><p class=\"note\">Loading requests\u2026</p></main>\n<script>\n(function(){\n var root=document.getElementById(\"root\");\n var decided={};\n // A redraw while a decision is being recorded must not offer the buttons again.\n var pending={};\n var errors={};\n // A decision still running is followed to its outcome (jgwill/Miadi#924): one read every POLL_MS, at most POLL_MAX.\n var POLL_MS=3000,POLL_MAX=100,polls={};\n // An error that leaves the request open offers its approval page under it.\n var relink={};\n function el(tag,attrs,text){var e=document.createElement(tag);if(attrs)for(var k in attrs){if(k===\"class\")e.className=attrs[k];else e.setAttribute(k,attrs[k]);}if(text!=null)e.textContent=text;return e;}\n function host(){return window.openai||null;}\n function data(){var h=host();return h&&h.toolOutput?h.toolOutput:null;}\n function tokens(){var h=host();var m=h&&h.toolResponseMetadata;return (m&&m[\"miadi/decisionTokens\"])||{};}\n function render(){\n var d=data();root.textContent=\"\";\n if(!d){root.appendChild(el(\"p\",{class:\"note\"},\"Waiting for the request list.\"));return;}\n var list=d.decisions||[];\n if(!list.length){root.appendChild(el(\"p\",{class:\"empty\"},d.message||\"No request is waiting for a decision.\"));return;}\n if(!d.can_decide_here&&d.reason){root.appendChild(el(\"p\",{class:\"note\"},d.reason));}\n var t=tokens();\n list.forEach(function(r){root.appendChild(card(r,t[r.id]));});\n }\n // Where a request stands, as the connector projected it: the label, its lines, and the review it produced.\n function decidedBlock(d){\n var box=el(\"div\",{role:\"status\",class:d.cls});\n if(d.note)box.appendChild(el(\"p\",{class:\"line\"},d.note));\n box.appendChild(el(\"p\",{class:\"label\"},d.label));\n (d.lines||[]).forEach(function(l){box.appendChild(el(\"p\",{class:\"line\"},l));});\n if(d.url){var p=el(\"p\",{class:\"line\"});p.appendChild(el(\"a\",{href:d.url,target:\"_blank\",rel:\"noopener\"},d.url));box.appendChild(p);}\n return box;\n }\n function toolResult(res){\n var out=(res&&(res.structuredContent||res.structured_content))||null;\n if(!out&&res&&res.content&&res.content[0]&&res.content[0].text){try{out=JSON.parse(res.content[0].text);}catch(e){out={message:res.content[0].text};}}\n return out;\n }\n function projectionView(p,note){return {cls:p.stage===\"failed\"?\"fail\":[\"recording\",\"dispatching\"].indexOf(p.stage)!==-1?\"note\":\"done\",stage:p.stage,label:p.label,lines:p.lines||[],url:p.receipt_url||null,note:note||null};}\n // Read where a request stands. Still running: read again later. Never decided (the call was lost on the way): offer the decision again.\n function follow(r,lost){\n if(!host()||!host().callTool)return;\n polls[r.id]=(polls[r.id]||0)+1;\n host().callTool(\"get_run_result\",{record_id:r.id}).then(function(res){\n var out=toolResult(res);var p=out&&(out.projection||(out.data&&out.data.projection));\n if(!p){if(lost){delete decided[r.id];errors[r.id]=lost;}render();return;}\n if(p.stage===\"awaiting_decision\"){delete decided[r.id];if(lost)errors[r.id]=lost+\" Nothing was decided; decide again.\";render();return;}\n var note=decided[r.id]&&decided[r.id].note;\n decided[r.id]=projectionView(p,note);delete errors[r.id];render();\n if(p.stage===\"recording\"&&polls[r.id]<POLL_MAX)setTimeout(function(){follow(r);},POLL_MS);\n },function(err){\n if(lost){decided[r.id]={cls:\"note\",stage:\"recording\",label:\"Your decision may be recorded. Checking again\u2026\",lines:[],url:null,note:null};render();}\n if(polls[r.id]<POLL_MAX)setTimeout(function(){follow(r,lost);},POLL_MS);\n });\n }\n var SETTLED={drafter:\"The drafting agent can answer this.\",person:\"Only you can answer this. Write it under Instructions.\",bystander:\"Only the person deciding can answer this, in their instructions.\",local_agent:\"A local agent can settle this from the running system.\"};\n var ARROW='<svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.9\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M12 17V3\"/><path d=\"m6 11 6 6 6-6\"/><path d=\"M19 21H5\"/></svg>';\n var DASHED='<path d=\"M10.1 2.182a10 10 0 0 1 3.8 0\"/><path d=\"M13.9 21.818a10 10 0 0 1-3.8 0\"/><path d=\"M17.609 3.721a10 10 0 0 1 2.69 2.7\"/><path d=\"M2.182 13.9a10 10 0 0 1 0-3.8\"/><path d=\"M20.279 17.609a10 10 0 0 1-2.7 2.69\"/><path d=\"M21.818 10.1a10 10 0 0 1 0 3.8\"/><path d=\"M3.721 6.391a10 10 0 0 1 2.7-2.69\"/><path d=\"M6.391 20.279a10 10 0 0 1-2.69-2.7\"/>';var EYE='<path d=\"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0\"/><circle cx=\"12\" cy=\"12\" r=\"3\"/>';\n function glyph(label,paths){return '<svg role=\"img\" aria-label=\"'+label+'\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.9\" stroke-linecap=\"round\" stroke-linejoin=\"round\">'+paths+'</svg>';}\n // A redraw rebuilds the card: what the person typed and which reasons they opened stay.\n var typed={};var whyOpen={};var boxes={};\n function stateLine(label,paths,build){var row=el(\"div\",{class:\"asp state\"});var g=el(\"span\",{class:\"gl\"});g.innerHTML=glyph(label,paths);row.appendChild(g);var t=el(\"p\",{class:\"small\"});build(t);row.appendChild(t);return row;}\n // The mission standard's open aspects, for the person deciding: what only they can answer first, and no verdict (jgwill/Miadi#939).\n function standardBlock(r,token){\n var rv=r.draft_review;\n var canAnswer=Boolean(token&&host()&&host().callTool);\n var s=el(\"section\",{class:\"std\",\"aria-label\":\"The mission standard\"});\n var list=rv?(rv.needs_revision||[]).slice().sort(function(a,b){var p=(b.settled_by===\"person\"?1:0)-(a.settled_by===\"person\"?1:0);return p||String(a.aspect).localeCompare(String(b.aspect));}):[];\n var version=rv&&rv.standard?\" v\"+rv.standard.version:\"\";\n s.appendChild(el(\"h3\",null,list.length?list.length+\" open on the mission standard\"+version:\"The mission standard\"+version));\n if(r.delivery){\n var place=el(\"p\",{class:\"fact\"});place.appendChild(el(\"span\",{class:\"small\"},\"The result lands at: \"));var disputed=list.some(function(f){return f.aspect===\"S1\";});\n place.appendChild(el(\"span\",disputed?{class:\"small\"}:null,r.delivery));\n if(disputed)place.appendChild(el(\"span\",{class:\"small\"},\" (S1 below asks about this)\"));\n s.appendChild(place);\n }\n if(r.person_words){var w=el(\"div\");w.appendChild(el(\"p\",{class:\"small\"},\"The person's words, as the drafting agent quoted them:\"));w.appendChild(el(\"blockquote\",null,r.person_words));s.appendChild(w);}\n if(!rv){s.appendChild(stateLine(\"Read it yourself\",EYE,function(t){t.textContent=\"No check ran on this version of the mission. Read it yourself.\";}));return s;}\n if(!list.length)s.appendChild(stateLine(\"Nothing flagged\",DASHED,function(t){t.textContent=\"Nothing flagged on the aspects checked.\";}));\n else{\n var ul=el(\"ul\",{class:\"aspects\"});\n list.forEach(function(f){\n var mine=f.settled_by===\"person\"&&canAnswer;\n var row=el(\"li\",{class:\"asp\"+(mine?\" yours\":\"\")});\n var g=el(\"span\",{class:\"gl\"});g.innerHTML=glyph(\"Open aspect\",DASHED);row.appendChild(g);\n var t=el(\"div\");\n var name=el(\"p\",{class:\"nm\"});name.appendChild(el(\"span\",{class:\"code\"},f.aspect));name.appendChild(el(\"span\",null,\" \"+f.name));t.appendChild(name);\n t.appendChild(el(\"p\",{class:\"ask\"},f.ask));\n if(f.span&&f.span!==r.delivery)t.appendChild(el(\"p\",{class:\"small\"},\"The mission says: \"+f.span));\n if(f.note)t.appendChild(el(\"p\",{class:\"small\"},f.note));\n var who=el(\"div\",{class:\"who\"});\n who.appendChild(el(\"p\",{class:\"small settler\"},(f.settled_by===\"person\"&&!canAnswer?SETTLED.bystander:SETTLED[f.settled_by])||f.settled_by));\n if(mine){\n var go=el(\"button\",{type:\"button\",class:\"iconbtn\",\"aria-label\":\"Go to Instructions\",title:\"Go to Instructions\"});go.innerHTML=ARROW;\n go.addEventListener(\"click\",function(){var box=boxes[r.id];if(box){if(box.scrollIntoView)box.scrollIntoView({block:\"center\"});box.focus();}});\n who.appendChild(go);\n }\n t.appendChild(who);\n var key=r.id+\"/\"+f.aspect;\n var why=el(\"details\");if(whyOpen[key])why.setAttribute(\"open\",\"\");\n why.addEventListener(\"toggle\",function(){whyOpen[key]=why.open;});\n var sum=el(\"summary\");sum.appendChild(el(\"span\",{class:\"closedL\"},\"Why\"));sum.appendChild(el(\"span\",{class:\"openL\"},\"Hide why\"));why.appendChild(sum);\n why.appendChild(el(\"p\",{class:\"small\"},f.why));\n var by=String(f.checked_by||\"\").split(\" \")[0]===\"jev\"?\"Jev\":f.checked_by===\"code\"?\"a check in code\":\"the \"+f.checked_by;\n why.appendChild(el(\"p\",{class:\"small\"},\"Flagged by \"+by+\".\"));\n t.appendChild(why);\n row.appendChild(t);ul.appendChild(row);\n });\n s.appendChild(ul);\n }\n var open={};list.forEach(function(f){open[f.aspect]=true;});\n var unseen=(rv.not_checked||[]).filter(function(n){return !open[n.aspect];});\n var rest=unseen.filter(function(n){return !n.in_part;});\n unseen.filter(function(n){return n.in_part;}).forEach(function(n){\n s.appendChild(stateLine(\"Checked in part\",EYE,function(t){t.appendChild(el(\"span\",null,\"Checked in part: \"));t.appendChild(el(\"span\",{class:\"code\"},n.aspect));t.appendChild(el(\"span\",null,\" \"+n.name+\" (\"+n.in_part+\")\"));}));\n });\n if(rest.length)s.appendChild(stateLine(\"Read it yourself\",EYE,function(t){\n t.appendChild(el(\"span\",null,\"No check covers these, so read the mission for them: \"));\n rest.forEach(function(n,i){if(i)t.appendChild(el(\"span\",null,\" \u00B7 \"));t.appendChild(el(\"span\",{class:\"code\"},n.aspect));t.appendChild(el(\"span\",null,\" \"+n.name));});\n }));\n if(canAnswer&&list.some(function(f){return f.settled_by===\"drafter\";}))s.appendChild(el(\"p\",{class:\"small\"},\"To put the drafting agent's questions to it, say what to revise under Instructions and send it back.\"));\n var refused=r.provider_authorization&&r.provider_authorization.authorized===false;\n if(canAnswer&&list.length&&!refused)s.appendChild(el(\"p\",{class:\"small\"},\"Approving as it stands starts the session, and the worker reads these questions with the task.\"));\n return s;\n }\n function card(r,token){\n var a=el(\"article\",{\"aria-label\":r.title});\n a.appendChild(el(\"span\",{class:\"kind\"},r.kind_label||r.kind));\n a.appendChild(el(\"h2\",null,r.title));\n a.appendChild(el(\"p\",{class:\"meta\"},\"Asked by \"+r.by+(r.via?\" through \"+r.via:\"\")+\" \u00B7 \"+new Date(r.created_at).toLocaleString()+(r.circle?\" \u00B7 \"+r.circle+\" circle\":\"\")));\n a.appendChild(el(\"p\",{class:\"does\"},r.consequence));\n if(r.intention)a.appendChild(el(\"p\",null,r.intention));\n if(!decided[r.id]&&!pending[r.id]&&r.projection&&r.projection.stage===\"awaiting_decision\"&&(r.kind===\"run_request\"||r.kind===\"work_proposal\"||r.draft_review||r.delivery||r.person_words))a.appendChild(standardBlock(r,token));\n var det=el(\"details\");det.appendChild(el(\"summary\",null,\"What exactly is asked\"));det.appendChild(el(\"pre\",null,r.detail||\"\"));a.appendChild(det);\n var status=el(\"p\",{role:\"status\"});\n if(r.projection&&r.projection.stage!==\"awaiting_decision\"&&(!decided[r.id]||[\"recording\",\"dispatching\"].indexOf(r.projection.stage)===-1)){decided[r.id]=projectionView(r.projection);}\n if(decided[r.id]){\n var shown=decided[r.id];a.appendChild(decidedBlock(shown));\n if(shown.stage===\"recording\"&&polls[r.id]===undefined&&host()&&host().callTool){polls[r.id]=0;setTimeout(function(){follow(r);},POLL_MS);}\n if([\"recording\",\"dispatching\"].indexOf(shown.stage)!==-1&&host()&&host().callTool){\n var refresh=el(\"button\",{type:\"button\"},\"Refresh status\");\n refresh.addEventListener(\"click\",function(){\n refresh.disabled=true;\n host().callTool(\"get_run_result\",{record_id:r.id}).then(function(res){\n var out=toolResult(res);var p=out&&(out.projection||(out.data&&out.data.projection));\n if(p){decided[r.id]=projectionView(p);delete errors[r.id];}\n else{errors[r.id]=(out&&out.message)||\"Status could not be refreshed.\";}\n render();\n },function(err){errors[r.id]=\"Status could not be refreshed: \"+String(err&&err.message||err);render();});\n });\n a.appendChild(refresh);\n }\n if(errors[r.id])a.appendChild(el(\"p\",{class:\"fail\",role:\"status\"},errors[r.id]));\n return a;\n }\n function approvalLink(){var p=el(\"p\",{class:\"note\"});p.appendChild(document.createTextNode(r.kind===\"participant_consent_request\"?\"Only the person it asks decides this. Its page: \":\"Decide on its approval page: \"));p.appendChild(el(\"a\",{href:r.approval_url,target:\"_blank\",rel:\"noopener\"},\"open the approval page\"));return p;}\n if(pending[r.id]){status.className=\"note\";status.textContent=\"Recording your decision\u2026\";a.appendChild(status);return a;}\n if(!token||!host()||!host().callTool){a.appendChild(approvalLink());return a;}\n var ta=el(\"textarea\",{\"aria-label\":\"Instructions or changes (needed to approve with changes or send back)\",placeholder:\"Instructions or changes (needed to approve with changes or send back)\"});\n ta.value=typed[r.id]||\"\";boxes[r.id]=ta;\n ta.addEventListener(\"input\",function(){typed[r.id]=ta.value;});\n a.appendChild(ta);\n var row=el(\"div\",{class:\"row\"});\n // The ring on a mission would move with its report and read as a verdict, so a mission's buttons carry none (jgwill/Miadi#939).\n var mission=r.kind===\"run_request\"||r.kind===\"work_proposal\";\n var buttons=[[\"approve\",\"Approve\",mission?\"\":\"primary\"],[\"approve_with_changes\",\"Approve with my changes\",\"\"],[\"request_revision\",\"Send back for revision\",\"\"],[\"decline\",\"Decline\",\"\"]];\n var btns=[];\n buttons.forEach(function(b){var x=el(\"button\",{type:\"button\",class:b[2]},b[1]);x.addEventListener(\"click\",function(){go(b[0]);});btns.push(x);row.appendChild(x);});\n a.appendChild(row);a.appendChild(status);\n if(errors[r.id]){status.className=\"fail\";status.textContent=errors[r.id];if(relink[r.id])a.appendChild(approvalLink());}\n function go(choice){\n var text=ta.value.trim();\n if((choice===\"approve_with_changes\"||choice===\"request_revision\")&&!text){status.className=\"fail\";status.textContent=choice===\"request_revision\"?\"Say what to revise.\":\"Write the changes to apply.\";ta.focus();return;}\n btns.forEach(function(x){x.disabled=true;});status.className=\"note\";status.textContent=\"Recording your decision\u2026\";pending[r.id]=true;delete errors[r.id];\n host().callTool(\"decide_request\",{record_id:r.id,decision:choice,instructions:text||undefined,decision_token:token}).then(function(res){\n var out=toolResult(res);\n // The connector answers with the request's projection, also when a click finds it decided already.\n var proj=out&&(out.projection||(out.detail&&out.detail.projection));\n var code=out&&out.error;\n delete pending[r.id];\n // The token expired or the request was revised, and it still awaits a decision: say so and keep it open.\n if(code&&(!proj||proj.stage===\"awaiting_decision\")){errors[r.id]=(out&&out.message)||\"Not recorded.\";relink[r.id]=true;render();return;}\n var note=out&&out.replayed?\"This decision was already recorded. Nothing ran again.\":code===\"decision_conflict\"?\"A different decision was recorded first. Here is where it stands.\":code===\"already_decided\"?\"This request was already decided. Here is where it stands.\":null;\n if(proj){decided[r.id]=projectionView(proj,note);}\n else{decided[r.id]={cls:code?\"fail\":\"done\",label:code?((out&&out.message)||\"Not recorded.\"):((out&&out.summary)||\"Recorded.\"),lines:[],url:null,note:null};}\n render();\n },function(err){\n // The host gave up waiting; the connector may still have recorded it. Read before offering the buttons again (#924).\n delete pending[r.id];\n decided[r.id]={cls:\"note\",stage:\"recording\",label:\"Checking whether your decision was recorded\u2026\",lines:[],url:null,note:null};\n polls[r.id]=0;render();\n follow(r,\"Not recorded: \"+(err&&err.message?err.message:String(err))+\".\");\n });\n }\n return a;\n }\n window.addEventListener(\"openai:set_globals\",render);\n render();\n})();\n</script></body></html>";
31
+ export declare const DECISIONS_CARD_HTML = "<!doctype html>\n<html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n<style>\n:root{color-scheme:light dark;--fg:#1d1b18;--muted:#5b5650;--line:#d9d4cc;--accent:#7a4a00;--ok:#1d6b3a;--err:#b00020;--chip:#f1ede6}\n@media (prefers-color-scheme:dark){:root{--fg:#ece8e1;--muted:#b3ada4;--line:#3a3631;--accent:#ffd700;--ok:#7fd49b;--err:#ff8a80;--chip:#24211d}}\n*{box-sizing:border-box}\nbody{margin:0;color:var(--fg);font:15px/1.45 system-ui,sans-serif;background:transparent}\nmain{padding:12px;display:grid;gap:12px}\n.empty,.note{color:var(--muted)}\narticle{border:1px solid var(--line);border-radius:10px;padding:12px}\nh2{font-size:15px;margin:0 0 4px}\n.kind{display:inline-block;font-size:12px;padding:1px 8px;border-radius:999px;background:var(--chip);color:var(--muted);margin-bottom:6px}\n.meta{font-size:13px;color:var(--muted);margin:0 0 6px}\n.does{margin:6px 0;font-weight:600}\ndetails{margin:6px 0}\nsummary{cursor:pointer;color:var(--muted);font-size:13px}\npre{white-space:pre-wrap;overflow-wrap:anywhere;font-size:12px;margin:6px 0 0;max-height:240px;overflow:auto}\ntextarea{width:100%;min-height:64px;padding:8px;border:1px solid var(--line);border-radius:8px;background:transparent;color:var(--fg);font:inherit;margin-top:8px}\n.row{display:flex;flex-wrap:wrap;gap:8px;margin-top:8px}\nbutton{padding:8px 12px;border-radius:8px;border:1px solid var(--line);background:transparent;color:var(--fg);font:inherit;cursor:pointer;min-height:40px}\nbutton.primary{border-color:var(--accent);outline:1px solid var(--accent)}\nbutton:focus-visible,a:focus-visible,textarea:focus-visible{outline:2px solid var(--accent);outline-offset:2px}\nbutton[disabled]{opacity:.55;cursor:default}\na{color:inherit}\n.done{color:var(--ok);font-weight:600}\n.std{border-top:1px solid var(--line);margin:8px 0;padding-top:8px;display:grid;gap:8px}\nh3{font-size:14px;margin:0;font-weight:600}\n.aspects{list-style:none;margin:4px 0;padding:0;display:grid;gap:14px}\n.asp{display:grid;grid-template-columns:16px 1fr;gap:6px;font-size:14px;overflow-wrap:anywhere}\n.asp .gl{margin-top:3px;color:var(--muted);display:block}\n.asp p{margin:1px 0}\n.asp .nm{color:var(--muted)}\n.asp .ask{font-weight:600}\n.asp details{margin:0}\n.asp details[open]{border-left:2px solid var(--accent);padding-left:8px;margin-top:2px}\n.asp summary{padding:8px 0}\n.who{display:flex;gap:8px;align-items:center}\n.who .settler{flex:1}\n.yours .settler{color:var(--fg);font-weight:600}\n.yours .gl{color:var(--accent)}\n.iconbtn{min-height:34px;width:34px;padding:0;display:inline-grid;place-items:center;flex:none;border-color:var(--accent);color:var(--accent)}\n.openL{display:none}\ndetails[open]>summary .openL{display:inline}\ndetails[open]>summary .closedL{display:none}\n.fact{margin:0;font-size:14px;overflow-wrap:anywhere}\n.code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:13px}\n.small{font-size:13px;color:var(--muted);margin:0;overflow-wrap:anywhere}\nblockquote{margin:4px 0 0;padding-left:8px;border-left:2px solid var(--line);font-size:14px;overflow-wrap:anywhere}\nsummary:focus-visible{outline:2px solid var(--accent);outline-offset:2px}\n.mf{border-top:1px solid var(--line);margin:8px 0 0;padding-top:8px;display:grid;gap:6px}\n.mf .pair{display:grid;grid-template-columns:96px minmax(0,18rem);gap:8px;align-items:center;font-size:14px}\n.asp.state.stopped .gl{color:var(--err)}\n.asp.state.stopped p{color:var(--fg)}\n.asp.state.set .gl{color:var(--fg)}\n.asp.state.set p{color:var(--fg)}\n.hint{margin:8px 0 0}\n.does.asreq{font-weight:400;color:var(--muted)}\n.mf select{width:100%;min-height:34px;padding:4px 8px;border:1px solid var(--line);border-radius:8px;background:transparent;color:var(--fg);font:inherit}\n.mf select:focus-visible{outline:2px solid var(--accent);outline-offset:2px}\n@media (max-width:420px){.mf .pair{grid-template-columns:minmax(0,1fr);gap:2px}}\n</style></head><body><main id=\"root\" aria-live=\"polite\"><p class=\"note\">Loading requests\u2026</p></main>\n<script>\n(function(){\n var root=document.getElementById(\"root\");\n var decided={};\n // A redraw while a decision is being recorded must not offer the buttons again.\n var pending={};\n var errors={};\n // A decision still running is followed to its outcome (jgwill/Miadi#924): one read every POLL_MS, at most POLL_MAX.\n var POLL_MS=3000,POLL_MAX=100,polls={};\n // An error that leaves the request open offers its approval page under it.\n var relink={};\n function el(tag,attrs,text){var e=document.createElement(tag);if(attrs)for(var k in attrs){if(k===\"class\")e.className=attrs[k];else e.setAttribute(k,attrs[k]);}if(text!=null)e.textContent=text;return e;}\n function host(){return window.openai||null;}\n function data(){var h=host();return h&&h.toolOutput?h.toolOutput:null;}\n function tokens(){var h=host();var m=h&&h.toolResponseMetadata;return (m&&m[\"miadi/decisionTokens\"])||{};}\n function render(){\n var d=data();root.textContent=\"\";\n if(!d){root.appendChild(el(\"p\",{class:\"note\"},\"Waiting for the request list.\"));return;}\n var list=d.decisions||[];\n if(!list.length){root.appendChild(el(\"p\",{class:\"empty\"},d.message||\"No request is waiting for a decision.\"));return;}\n if(!d.can_decide_here&&d.reason){root.appendChild(el(\"p\",{class:\"note\"},d.reason));}\n var t=tokens();\n list.forEach(function(r){root.appendChild(card(r,t[r.id]));});\n }\n // Where a request stands, as the connector projected it: the label, its lines, and the review it produced.\n function decidedBlock(d){\n var box=el(\"div\",{role:\"status\",class:d.cls});\n if(d.note)box.appendChild(el(\"p\",{class:\"line\"},d.note));\n box.appendChild(el(\"p\",{class:\"label\"},d.label));\n (d.lines||[]).forEach(function(l){box.appendChild(el(\"p\",{class:\"line\"},l));});\n if(d.url){var p=el(\"p\",{class:\"line\"});p.appendChild(el(\"a\",{href:d.url,target:\"_blank\",rel:\"noopener\"},d.url));box.appendChild(p);}\n return box;\n }\n function toolResult(res){\n var out=(res&&(res.structuredContent||res.structured_content))||null;\n if(!out&&res&&res.content&&res.content[0]&&res.content[0].text){try{out=JSON.parse(res.content[0].text);}catch(e){out={message:res.content[0].text};}}\n return out;\n }\n function projectionView(p,note){return {cls:p.stage===\"failed\"?\"fail\":[\"recording\",\"dispatching\"].indexOf(p.stage)!==-1?\"note\":\"done\",stage:p.stage,label:p.label,lines:p.lines||[],url:p.receipt_url||null,note:note||null};}\n // Read where a request stands. Still running: read again later. Never decided (the call was lost on the way): offer the decision again.\n function follow(r,lost){\n if(!host()||!host().callTool)return;\n polls[r.id]=(polls[r.id]||0)+1;\n host().callTool(\"get_run_result\",{record_id:r.id}).then(function(res){\n var out=toolResult(res);var p=out&&(out.projection||(out.data&&out.data.projection));\n if(!p){if(lost){delete decided[r.id];errors[r.id]=lost;}render();return;}\n if(p.stage===\"awaiting_decision\"){delete decided[r.id];if(lost)errors[r.id]=lost+\" Nothing was decided; decide again.\";render();return;}\n var note=decided[r.id]&&decided[r.id].note;\n decided[r.id]=projectionView(p,note);delete errors[r.id];render();\n if(p.stage===\"recording\"&&polls[r.id]<POLL_MAX)setTimeout(function(){follow(r);},POLL_MS);\n },function(err){\n if(lost){decided[r.id]={cls:\"note\",stage:\"recording\",label:\"Your decision may be recorded. Checking again\u2026\",lines:[],url:null,note:null};render();}\n if(polls[r.id]<POLL_MAX)setTimeout(function(){follow(r,lost);},POLL_MS);\n });\n }\n var SETTLED={drafter:\"The drafting agent can answer this.\",person:\"Only you can answer this. Write it under Instructions.\",bystander:\"Only the person deciding can answer this, in their instructions.\",local_agent:\"A local agent can settle this from the running system.\"};\n var ARROW='<svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.9\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M12 17V3\"/><path d=\"m6 11 6 6 6-6\"/><path d=\"M19 21H5\"/></svg>';\n var DASHED='<path d=\"M10.1 2.182a10 10 0 0 1 3.8 0\"/><path d=\"M13.9 21.818a10 10 0 0 1-3.8 0\"/><path d=\"M17.609 3.721a10 10 0 0 1 2.69 2.7\"/><path d=\"M2.182 13.9a10 10 0 0 1 0-3.8\"/><path d=\"M20.279 17.609a10 10 0 0 1-2.7 2.69\"/><path d=\"M21.818 10.1a10 10 0 0 1 0 3.8\"/><path d=\"M3.721 6.391a10 10 0 0 1 2.7-2.69\"/><path d=\"M6.391 20.279a10 10 0 0 1-2.69-2.7\"/>';var TRI='<path d=\"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3\"/><path d=\"M12 9v4\"/><path d=\"M12 17h.01\"/>';var USERCHECK='<path d=\"m16 11 2 2 4-4\"/><path d=\"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2\"/><circle cx=\"9\" cy=\"7\" r=\"4\"/>';var CPU='<path d=\"M12 20v2\"/><path d=\"M12 2v2\"/><path d=\"M17 20v2\"/><path d=\"M17 2v2\"/><path d=\"M2 12h2\"/><path d=\"M2 17h2\"/><path d=\"M2 7h2\"/><path d=\"M20 12h2\"/><path d=\"M20 17h2\"/><path d=\"M20 7h2\"/><path d=\"M7 20v2\"/><path d=\"M7 2v2\"/><rect x=\"4\" y=\"4\" width=\"16\" height=\"16\" rx=\"2\"/><rect x=\"8\" y=\"8\" width=\"8\" height=\"8\" rx=\"1\"/>';var EYE='<path d=\"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0\"/><circle cx=\"12\" cy=\"12\" r=\"3\"/>';\n function glyph(label,paths){return '<svg role=\"img\" aria-label=\"'+label+'\" viewBox=\"0 0 24 24\" width=\"16\" height=\"16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.9\" stroke-linecap=\"round\" stroke-linejoin=\"round\">'+paths+'</svg>';}\n // A redraw rebuilds the card: what the person typed and which reasons they opened stay.\n var typed={};var whyOpen={};var boxes={};\n // The model fields a person set on a card, by request: they take part in the model choice, the instructions do not (jgwill/Miadi#1029).\n var chosen={};\n function fieldsOf(id){var c=chosen[id]||{};var out={};[\"model\",\"task_type\",\"criticality\"].forEach(function(k){if(c[k])out[k]=c[k];});return out;}\n // A floor no permitted model meets, and no model named: approving as requested is refused (jgwill/Miadi#1028).\n function floorUnmet(r){var m=r.model_choice;return Boolean(m&&m.floor&&!m.requested_model&&!(m.met_by&&m.met_by.length));}\n function modelBlock(r){\n var m=r.model_choice;var box=el(\"div\",{class:\"mf\",role:\"group\",\"aria-label\":\"The model for this mission\"});\n var c=chosen[r.id]||(chosen[r.id]={});\n // What approving with these changes does, said before the click (critic U1).\n var set=fieldsOf(r.id);\n // A model named here settles the floor's refusal: the line then says what runs, once (critic U18).\n if(floorUnmet(r)&&!set.model)box.appendChild(stateLine(\"Refused\",TRI,function(t){t.textContent=\"No permitted model meets the floor (\"+m.floor+\"). Approving as requested is refused; name a model here and press Approve with my changes.\";},\"stopped\"));\n else if(m.floor&&!floorUnmet(r))box.appendChild(el(\"p\",{class:\"small\"},\"Floor set by the requester: \"+m.floor+\"; met by \"+m.met_by.join(\", \")+\".\"));\n if(set.model)box.appendChild(stateLine(\"Set by you\",USERCHECK,function(t){t.textContent=\"With your changes it runs on \"+set.model+\", set by you; Jev is not asked.\"+(m.floor&&(m.met_by||[]).indexOf(set.model)===-1?\" That is below the requester's floor (\"+m.floor+\").\":\"\");},\"set\"));\n else if(set.task_type||set.criticality)box.appendChild(stateLine(\"Set by you\",USERCHECK,function(t){t.textContent=\"With your changes Jev chooses from task type \"+(set.task_type||m.labels.task_type.value)+\" and criticality \"+(set.criticality||m.labels.criticality.value)+\".\";},\"set\"));\n box.appendChild(stateLine(\"Instructions do not choose the model\",CPU,function(t){t.textContent=\"What you write goes to the agent and does not choose the model. To change the model, set it here and press Approve with my changes.\";}));\n function pick(name,label,keep,values,noteOf){\n var row=el(\"div\",{class:\"pair\"});var id=\"mf-\"+name+\"-\"+String(r.id).replace(/[^A-Za-z0-9-]/g,\"\");\n row.appendChild(el(\"label\",{for:id},label));\n var sel=el(\"select\",{id:id,name:name});sel.appendChild(el(\"option\",{value:\"\"},keep));\n values.forEach(function(v){sel.appendChild(el(\"option\",{value:v},v+(noteOf?noteOf(v):\"\")));});\n sel.value=c[name]||\"\";\n // The card is drawn again so its lines and buttons say what is true now; focus returns to this select (critic U16).\n sel.addEventListener(\"change\",function(){c[name]=sel.value;render();var again=document.getElementById(id);if(again&&again!==root&&again.focus)again.focus();});\n row.appendChild(sel);box.appendChild(row);\n }\n var lab=function(l){return l.value+(l.set_by===\"default\"?\" (default)\":\"\");};\n var below=function(v){return m.floor&&(m.met_by||[]).indexOf(v)===-1?\" (below the floor)\":\"\";};\n pick(\"model\",\"Model\",m.requested_model?\"Keep: \"+m.requested_model:floorUnmet(r)?\"Choose a model\":\"Keep: Jev chooses\",m.permitted||[],below);\n // With a model set, Jev is not asked, so the labels it reads would change nothing (critic U17).\n if(set.model){delete c.task_type;delete c.criticality;}\n if(!m.requested_model&&m.labels&&!set.model){\n pick(\"task_type\",\"Task type\",\"Keep: \"+lab(m.labels.task_type),m.task_types||[]);\n pick(\"criticality\",\"Criticality\",\"Keep: \"+lab(m.labels.criticality),m.criticalities||[]);\n }\n return box;\n }\n function stateLine(label,paths,build,cls){var row=el(\"div\",{class:\"asp state\"+(cls?\" \"+cls:\"\")});var g=el(\"span\",{class:\"gl\"});g.innerHTML=glyph(label,paths);row.appendChild(g);var t=el(\"p\",{class:\"small\"});build(t);row.appendChild(t);return row;}\n // The mission standard's open aspects, for the person deciding: what only they can answer first, and no verdict (jgwill/Miadi#939).\n function standardBlock(r,token){\n var rv=r.draft_review;\n var canAnswer=Boolean(token&&host()&&host().callTool);\n var s=el(\"section\",{class:\"std\",\"aria-label\":\"The mission standard\"});\n var list=rv?(rv.needs_revision||[]).slice().sort(function(a,b){var p=(b.settled_by===\"person\"?1:0)-(a.settled_by===\"person\"?1:0);return p||String(a.aspect).localeCompare(String(b.aspect));}):[];\n var version=rv&&rv.standard?\" v\"+rv.standard.version:\"\";\n s.appendChild(el(\"h3\",null,list.length?list.length+\" open on the mission standard\"+version:\"The mission standard\"+version));\n if(r.delivery){\n var place=el(\"p\",{class:\"fact\"});place.appendChild(el(\"span\",{class:\"small\"},\"The result lands at: \"));var disputed=list.some(function(f){return f.aspect===\"S1\";});\n place.appendChild(el(\"span\",disputed?{class:\"small\"}:null,r.delivery));\n if(disputed)place.appendChild(el(\"span\",{class:\"small\"},\" (S1 below asks about this)\"));\n s.appendChild(place);\n }\n if(r.person_words){var w=el(\"div\");w.appendChild(el(\"p\",{class:\"small\"},\"The person's words, as the drafting agent quoted them:\"));w.appendChild(el(\"blockquote\",null,r.person_words));s.appendChild(w);}\n if(!rv){s.appendChild(stateLine(\"Read it yourself\",EYE,function(t){t.textContent=\"No check ran on this version of the mission. Read it yourself.\";}));return s;}\n if(!list.length)s.appendChild(stateLine(\"Nothing flagged\",DASHED,function(t){t.textContent=\"Nothing flagged on the aspects checked.\";}));\n else{\n var ul=el(\"ul\",{class:\"aspects\"});\n list.forEach(function(f){\n var mine=f.settled_by===\"person\"&&canAnswer;\n var row=el(\"li\",{class:\"asp\"+(mine?\" yours\":\"\")});\n var g=el(\"span\",{class:\"gl\"});g.innerHTML=glyph(\"Open aspect\",DASHED);row.appendChild(g);\n var t=el(\"div\");\n var name=el(\"p\",{class:\"nm\"});name.appendChild(el(\"span\",{class:\"code\"},f.aspect));name.appendChild(el(\"span\",null,\" \"+f.name));t.appendChild(name);\n t.appendChild(el(\"p\",{class:\"ask\"},f.ask));\n if(f.span&&f.span!==r.delivery)t.appendChild(el(\"p\",{class:\"small\"},\"The mission says: \"+f.span));\n if(f.note)t.appendChild(el(\"p\",{class:\"small\"},f.note));\n var who=el(\"div\",{class:\"who\"});\n who.appendChild(el(\"p\",{class:\"small settler\"},(f.settled_by===\"person\"&&!canAnswer?SETTLED.bystander:SETTLED[f.settled_by])||f.settled_by));\n if(mine){\n var go=el(\"button\",{type:\"button\",class:\"iconbtn\",\"aria-label\":\"Go to Instructions\",title:\"Go to Instructions\"});go.innerHTML=ARROW;\n go.addEventListener(\"click\",function(){var box=boxes[r.id];if(box){if(box.scrollIntoView)box.scrollIntoView({block:\"center\"});box.focus();}});\n who.appendChild(go);\n }\n t.appendChild(who);\n var key=r.id+\"/\"+f.aspect;\n var why=el(\"details\");if(whyOpen[key])why.setAttribute(\"open\",\"\");\n why.addEventListener(\"toggle\",function(){whyOpen[key]=why.open;});\n var sum=el(\"summary\");sum.appendChild(el(\"span\",{class:\"closedL\"},\"Why\"));sum.appendChild(el(\"span\",{class:\"openL\"},\"Hide why\"));why.appendChild(sum);\n why.appendChild(el(\"p\",{class:\"small\"},f.why));\n var by=String(f.checked_by||\"\").split(\" \")[0]===\"jev\"?\"Jev\":f.checked_by===\"code\"?\"a check in code\":\"the \"+f.checked_by;\n why.appendChild(el(\"p\",{class:\"small\"},\"Flagged by \"+by+\".\"));\n t.appendChild(why);\n row.appendChild(t);ul.appendChild(row);\n });\n s.appendChild(ul);\n }\n var open={};list.forEach(function(f){open[f.aspect]=true;});\n var unseen=(rv.not_checked||[]).filter(function(n){return !open[n.aspect];});\n var rest=unseen.filter(function(n){return !n.in_part;});\n unseen.filter(function(n){return n.in_part;}).forEach(function(n){\n s.appendChild(stateLine(\"Checked in part\",EYE,function(t){t.appendChild(el(\"span\",null,\"Checked in part: \"));t.appendChild(el(\"span\",{class:\"code\"},n.aspect));t.appendChild(el(\"span\",null,\" \"+n.name+\" (\"+n.in_part+\")\"));}));\n });\n if(rest.length)s.appendChild(stateLine(\"Read it yourself\",EYE,function(t){\n t.appendChild(el(\"span\",null,\"No check covers these, so read the mission for them: \"));\n rest.forEach(function(n,i){if(i)t.appendChild(el(\"span\",null,\" \u00B7 \"));t.appendChild(el(\"span\",{class:\"code\"},n.aspect));t.appendChild(el(\"span\",null,\" \"+n.name));});\n }));\n if(canAnswer&&list.some(function(f){return f.settled_by===\"drafter\";}))s.appendChild(el(\"p\",{class:\"small\"},\"To put the drafting agent's questions to it, say what to revise under Instructions and send it back.\"));\n var refused=r.provider_authorization&&r.provider_authorization.authorized===false;\n if(canAnswer&&list.length&&!refused)s.appendChild(el(\"p\",{class:\"small\"},\"Approving as it stands starts the session, and the worker reads these questions with the task.\"));\n return s;\n }\n function card(r,token){\n var a=el(\"article\",{\"aria-label\":r.title});\n a.appendChild(el(\"span\",{class:\"kind\"},r.kind_label||r.kind));\n a.appendChild(el(\"h2\",null,r.title));\n a.appendChild(el(\"p\",{class:\"meta\"},\"Asked by \"+r.by+(r.via?\" through \"+r.via:\"\")+\" \u00B7 \"+new Date(r.created_at).toLocaleString()+(r.circle?\" \u00B7 \"+r.circle+\" circle\":\"\")));\n // With a model field set, this sentence is what approving as requested does; the model block says what the changes do (critic U1).\n var changed=Boolean(r.model_choice&&Object.keys(fieldsOf(r.id)).length&&!floorUnmet(r));\n a.appendChild(el(\"p\",{class:changed?\"does asreq\":\"does\"},changed?\"As requested, \"+r.consequence.charAt(0).toLowerCase()+r.consequence.slice(1):r.consequence));\n if(r.intention)a.appendChild(el(\"p\",null,r.intention));\n if(!decided[r.id]&&!pending[r.id]&&r.projection&&r.projection.stage===\"awaiting_decision\"&&(r.kind===\"run_request\"||r.kind===\"work_proposal\"||r.draft_review||r.delivery||r.person_words))a.appendChild(standardBlock(r,token));\n var det=el(\"details\");det.appendChild(el(\"summary\",null,\"What exactly is asked\"));det.appendChild(el(\"pre\",null,r.detail||\"\"));a.appendChild(det);\n var status=el(\"p\",{role:\"status\"});\n if(r.projection&&r.projection.stage!==\"awaiting_decision\"&&(!decided[r.id]||[\"recording\",\"dispatching\"].indexOf(r.projection.stage)===-1)){decided[r.id]=projectionView(r.projection);}\n if(decided[r.id]){\n var shown=decided[r.id];a.appendChild(decidedBlock(shown));\n if(shown.stage===\"recording\"&&polls[r.id]===undefined&&host()&&host().callTool){polls[r.id]=0;setTimeout(function(){follow(r);},POLL_MS);}\n if([\"recording\",\"dispatching\"].indexOf(shown.stage)!==-1&&host()&&host().callTool){\n var refresh=el(\"button\",{type:\"button\"},\"Refresh status\");\n refresh.addEventListener(\"click\",function(){\n refresh.disabled=true;\n host().callTool(\"get_run_result\",{record_id:r.id}).then(function(res){\n var out=toolResult(res);var p=out&&(out.projection||(out.data&&out.data.projection));\n if(p){decided[r.id]=projectionView(p);delete errors[r.id];}\n else{errors[r.id]=(out&&out.message)||\"Status could not be refreshed.\";}\n render();\n },function(err){errors[r.id]=\"Status could not be refreshed: \"+String(err&&err.message||err);render();});\n });\n a.appendChild(refresh);\n }\n if(errors[r.id])a.appendChild(el(\"p\",{class:\"fail\",role:\"status\"},errors[r.id]));\n return a;\n }\n function approvalLink(){var p=el(\"p\",{class:\"note\"});p.appendChild(document.createTextNode(r.kind===\"participant_consent_request\"?\"Only the person it asks decides this. Its page: \":\"Decide on its approval page: \"));p.appendChild(el(\"a\",{href:r.approval_url,target:\"_blank\",rel:\"noopener\"},\"open the approval page\"));return p;}\n if(pending[r.id]){status.className=\"note\";status.textContent=\"Recording your decision\u2026\";a.appendChild(status);return a;}\n if(!token||!host()||!host().callTool){a.appendChild(approvalLink());return a;}\n // With model fields, the rule for instructions is a line of its own: a placeholder is clipped and leaves once typing starts (critic U8).\n var hintId=\"ih-\"+String(r.id).replace(/[^A-Za-z0-9-]/g,\"\");\n if(r.model_choice)a.appendChild(el(\"p\",{class:\"small hint\",id:hintId},\"Instructions are needed to send back. To approve with changes, write them or set the model below.\"));\n var hint=r.model_choice?\"Instructions or changes\":\"Instructions or changes (needed to approve with changes or send back)\";\n var ta=el(\"textarea\",r.model_choice?{\"aria-label\":hint,placeholder:hint,\"aria-describedby\":hintId}:{\"aria-label\":hint,placeholder:hint});\n ta.value=typed[r.id]||\"\";boxes[r.id]=ta;\n ta.addEventListener(\"input\",function(){typed[r.id]=ta.value;});\n a.appendChild(ta);\n if(r.model_choice)a.appendChild(modelBlock(r));\n var row=el(\"div\",{class:\"row\"});\n // The ring on a mission would move with its report and read as a verdict, so a mission's buttons carry none (jgwill/Miadi#939).\n var mission=r.kind===\"run_request\"||r.kind===\"work_proposal\";\n var buttons=[[\"approve\",\"Approve\",mission?\"\":\"primary\"],[\"approve_with_changes\",\"Approve with my changes\",\"\"],[\"request_revision\",\"Send back for revision\",\"\"],[\"decline\",\"Decline\",\"\"]];\n var btns=[];\n // A field set, or a floor no model meets, leaves only Approve with my changes: the plain Approve would be refused (critic U1, U5).\n var asRequestedOff=Boolean(r.model_choice&&(floorUnmet(r)||Object.keys(fieldsOf(r.id)).length));\n buttons.forEach(function(b){var x=el(\"button\",{type:\"button\",class:b[2]},b[1]);x.addEventListener(\"click\",function(){go(b[0]);});if(b[0]===\"approve\"&&asRequestedOff){x.disabled=true;x.setAttribute(\"title\",floorUnmet(r)?\"No permitted model meets the floor: name one and use Approve with my changes\":\"A model field is set: use Approve with my changes, or set it back to Keep\");}btns.push(x);row.appendChild(x);});\n a.appendChild(row);a.appendChild(status);\n if(errors[r.id]){status.className=\"fail\";status.textContent=errors[r.id];if(relink[r.id])a.appendChild(approvalLink());}\n function go(choice){\n var text=ta.value.trim();\n var set=r.model_choice?fieldsOf(r.id):{};var any=Object.keys(set).length>0;\n if(any&&choice===\"approve\"){status.className=\"fail\";status.textContent=\"A model field changes the request: press Approve with my changes, or set it back to Keep.\";return;}\n if((choice===\"approve_with_changes\"&&!text&&!any)||(choice===\"request_revision\"&&!text)){status.className=\"fail\";status.textContent=choice===\"request_revision\"?\"Say what to revise.\":\"Write the changes to apply, or set a model field.\";ta.focus();return;}\n btns.forEach(function(x){x.disabled=true;});status.className=\"note\";status.textContent=\"Recording your decision\u2026\";pending[r.id]=true;delete errors[r.id];\n var args={record_id:r.id,decision:choice,instructions:text||undefined,decision_token:token};\n if(choice===\"approve_with_changes\")for(var k in set)args[k]=set[k];\n host().callTool(\"decide_request\",args).then(function(res){\n var out=toolResult(res);\n // The connector answers with the request's projection, also when a click finds it decided already.\n var proj=out&&(out.projection||(out.detail&&out.detail.projection));\n var code=out&&out.error;\n delete pending[r.id];\n // The token expired or the request was revised, and it still awaits a decision: say so and keep it open.\n if(code&&(!proj||proj.stage===\"awaiting_decision\")){errors[r.id]=(out&&out.message)||\"Not recorded.\";relink[r.id]=true;render();return;}\n var note=out&&out.replayed?\"This decision was already recorded. Nothing ran again.\":code===\"decision_conflict\"?\"A different decision was recorded first. Here is where it stands.\":code===\"already_decided\"?\"This request was already decided. Here is where it stands.\":null;\n if(proj){decided[r.id]=projectionView(proj,note);}\n else{decided[r.id]={cls:code?\"fail\":\"done\",label:code?((out&&out.message)||\"Not recorded.\"):((out&&out.summary)||\"Recorded.\"),lines:[],url:null,note:null};}\n render();\n },function(err){\n // The host gave up waiting; the connector may still have recorded it. Read before offering the buttons again (#924).\n delete pending[r.id];\n decided[r.id]={cls:\"note\",stage:\"recording\",label:\"Checking whether your decision was recorded\u2026\",lines:[],url:null,note:null};\n polls[r.id]=0;render();\n follow(r,\"Not recorded: \"+(err&&err.message?err.message:String(err))+\".\");\n });\n }\n return a;\n }\n window.addEventListener(\"openai:set_globals\",render);\n render();\n})();\n</script></body></html>";
package/dist/decisions.js CHANGED
@@ -137,6 +137,17 @@ details[open]>summary .closedL{display:none}
137
137
  .small{font-size:13px;color:var(--muted);margin:0;overflow-wrap:anywhere}
138
138
  blockquote{margin:4px 0 0;padding-left:8px;border-left:2px solid var(--line);font-size:14px;overflow-wrap:anywhere}
139
139
  summary:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
140
+ .mf{border-top:1px solid var(--line);margin:8px 0 0;padding-top:8px;display:grid;gap:6px}
141
+ .mf .pair{display:grid;grid-template-columns:96px minmax(0,18rem);gap:8px;align-items:center;font-size:14px}
142
+ .asp.state.stopped .gl{color:var(--err)}
143
+ .asp.state.stopped p{color:var(--fg)}
144
+ .asp.state.set .gl{color:var(--fg)}
145
+ .asp.state.set p{color:var(--fg)}
146
+ .hint{margin:8px 0 0}
147
+ .does.asreq{font-weight:400;color:var(--muted)}
148
+ .mf select{width:100%;min-height:34px;padding:4px 8px;border:1px solid var(--line);border-radius:8px;background:transparent;color:var(--fg);font:inherit}
149
+ .mf select:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
150
+ @media (max-width:420px){.mf .pair{grid-template-columns:minmax(0,1fr);gap:2px}}
140
151
  </style></head><body><main id="root" aria-live="polite"><p class="note">Loading requests…</p></main>
141
152
  <script>
142
153
  (function(){
@@ -195,11 +206,48 @@ summary:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
195
206
  }
196
207
  var SETTLED={drafter:"The drafting agent can answer this.",person:"Only you can answer this. Write it under Instructions.",bystander:"Only the person deciding can answer this, in their instructions.",local_agent:"A local agent can settle this from the running system."};
197
208
  var ARROW='<svg aria-hidden="true" viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><path d="M12 17V3"/><path d="m6 11 6 6 6-6"/><path d="M19 21H5"/></svg>';
198
- var DASHED='<path d="M10.1 2.182a10 10 0 0 1 3.8 0"/><path d="M13.9 21.818a10 10 0 0 1-3.8 0"/><path d="M17.609 3.721a10 10 0 0 1 2.69 2.7"/><path d="M2.182 13.9a10 10 0 0 1 0-3.8"/><path d="M20.279 17.609a10 10 0 0 1-2.7 2.69"/><path d="M21.818 10.1a10 10 0 0 1 0 3.8"/><path d="M3.721 6.391a10 10 0 0 1 2.7-2.69"/><path d="M6.391 20.279a10 10 0 0 1-2.69-2.7"/>';var EYE='<path d="M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"/><circle cx="12" cy="12" r="3"/>';
209
+ var DASHED='<path d="M10.1 2.182a10 10 0 0 1 3.8 0"/><path d="M13.9 21.818a10 10 0 0 1-3.8 0"/><path d="M17.609 3.721a10 10 0 0 1 2.69 2.7"/><path d="M2.182 13.9a10 10 0 0 1 0-3.8"/><path d="M20.279 17.609a10 10 0 0 1-2.7 2.69"/><path d="M21.818 10.1a10 10 0 0 1 0 3.8"/><path d="M3.721 6.391a10 10 0 0 1 2.7-2.69"/><path d="M6.391 20.279a10 10 0 0 1-2.69-2.7"/>';var TRI='<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/><path d="M12 9v4"/><path d="M12 17h.01"/>';var USERCHECK='<path d="m16 11 2 2 4-4"/><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/>';var CPU='<path d="M12 20v2"/><path d="M12 2v2"/><path d="M17 20v2"/><path d="M17 2v2"/><path d="M2 12h2"/><path d="M2 17h2"/><path d="M2 7h2"/><path d="M20 12h2"/><path d="M20 17h2"/><path d="M20 7h2"/><path d="M7 20v2"/><path d="M7 2v2"/><rect x="4" y="4" width="16" height="16" rx="2"/><rect x="8" y="8" width="8" height="8" rx="1"/>';var EYE='<path d="M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"/><circle cx="12" cy="12" r="3"/>';
199
210
  function glyph(label,paths){return '<svg role="img" aria-label="'+label+'" viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round">'+paths+'</svg>';}
200
211
  // A redraw rebuilds the card: what the person typed and which reasons they opened stay.
201
212
  var typed={};var whyOpen={};var boxes={};
202
- function stateLine(label,paths,build){var row=el("div",{class:"asp state"});var g=el("span",{class:"gl"});g.innerHTML=glyph(label,paths);row.appendChild(g);var t=el("p",{class:"small"});build(t);row.appendChild(t);return row;}
213
+ // The model fields a person set on a card, by request: they take part in the model choice, the instructions do not (jgwill/Miadi#1029).
214
+ var chosen={};
215
+ function fieldsOf(id){var c=chosen[id]||{};var out={};["model","task_type","criticality"].forEach(function(k){if(c[k])out[k]=c[k];});return out;}
216
+ // A floor no permitted model meets, and no model named: approving as requested is refused (jgwill/Miadi#1028).
217
+ function floorUnmet(r){var m=r.model_choice;return Boolean(m&&m.floor&&!m.requested_model&&!(m.met_by&&m.met_by.length));}
218
+ function modelBlock(r){
219
+ var m=r.model_choice;var box=el("div",{class:"mf",role:"group","aria-label":"The model for this mission"});
220
+ var c=chosen[r.id]||(chosen[r.id]={});
221
+ // What approving with these changes does, said before the click (critic U1).
222
+ var set=fieldsOf(r.id);
223
+ // A model named here settles the floor's refusal: the line then says what runs, once (critic U18).
224
+ if(floorUnmet(r)&&!set.model)box.appendChild(stateLine("Refused",TRI,function(t){t.textContent="No permitted model meets the floor ("+m.floor+"). Approving as requested is refused; name a model here and press Approve with my changes.";},"stopped"));
225
+ else if(m.floor&&!floorUnmet(r))box.appendChild(el("p",{class:"small"},"Floor set by the requester: "+m.floor+"; met by "+m.met_by.join(", ")+"."));
226
+ if(set.model)box.appendChild(stateLine("Set by you",USERCHECK,function(t){t.textContent="With your changes it runs on "+set.model+", set by you; Jev is not asked."+(m.floor&&(m.met_by||[]).indexOf(set.model)===-1?" That is below the requester's floor ("+m.floor+").":"");},"set"));
227
+ else if(set.task_type||set.criticality)box.appendChild(stateLine("Set by you",USERCHECK,function(t){t.textContent="With your changes Jev chooses from task type "+(set.task_type||m.labels.task_type.value)+" and criticality "+(set.criticality||m.labels.criticality.value)+".";},"set"));
228
+ box.appendChild(stateLine("Instructions do not choose the model",CPU,function(t){t.textContent="What you write goes to the agent and does not choose the model. To change the model, set it here and press Approve with my changes.";}));
229
+ function pick(name,label,keep,values,noteOf){
230
+ var row=el("div",{class:"pair"});var id="mf-"+name+"-"+String(r.id).replace(/[^A-Za-z0-9-]/g,"");
231
+ row.appendChild(el("label",{for:id},label));
232
+ var sel=el("select",{id:id,name:name});sel.appendChild(el("option",{value:""},keep));
233
+ values.forEach(function(v){sel.appendChild(el("option",{value:v},v+(noteOf?noteOf(v):"")));});
234
+ sel.value=c[name]||"";
235
+ // The card is drawn again so its lines and buttons say what is true now; focus returns to this select (critic U16).
236
+ sel.addEventListener("change",function(){c[name]=sel.value;render();var again=document.getElementById(id);if(again&&again!==root&&again.focus)again.focus();});
237
+ row.appendChild(sel);box.appendChild(row);
238
+ }
239
+ var lab=function(l){return l.value+(l.set_by==="default"?" (default)":"");};
240
+ var below=function(v){return m.floor&&(m.met_by||[]).indexOf(v)===-1?" (below the floor)":"";};
241
+ pick("model","Model",m.requested_model?"Keep: "+m.requested_model:floorUnmet(r)?"Choose a model":"Keep: Jev chooses",m.permitted||[],below);
242
+ // With a model set, Jev is not asked, so the labels it reads would change nothing (critic U17).
243
+ if(set.model){delete c.task_type;delete c.criticality;}
244
+ if(!m.requested_model&&m.labels&&!set.model){
245
+ pick("task_type","Task type","Keep: "+lab(m.labels.task_type),m.task_types||[]);
246
+ pick("criticality","Criticality","Keep: "+lab(m.labels.criticality),m.criticalities||[]);
247
+ }
248
+ return box;
249
+ }
250
+ function stateLine(label,paths,build,cls){var row=el("div",{class:"asp state"+(cls?" "+cls:"")});var g=el("span",{class:"gl"});g.innerHTML=glyph(label,paths);row.appendChild(g);var t=el("p",{class:"small"});build(t);row.appendChild(t);return row;}
203
251
  // The mission standard's open aspects, for the person deciding: what only they can answer first, and no verdict (jgwill/Miadi#939).
204
252
  function standardBlock(r,token){
205
253
  var rv=r.draft_review;
@@ -268,7 +316,9 @@ summary:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
268
316
  a.appendChild(el("span",{class:"kind"},r.kind_label||r.kind));
269
317
  a.appendChild(el("h2",null,r.title));
270
318
  a.appendChild(el("p",{class:"meta"},"Asked by "+r.by+(r.via?" through "+r.via:"")+" · "+new Date(r.created_at).toLocaleString()+(r.circle?" · "+r.circle+" circle":"")));
271
- a.appendChild(el("p",{class:"does"},r.consequence));
319
+ // With a model field set, this sentence is what approving as requested does; the model block says what the changes do (critic U1).
320
+ var changed=Boolean(r.model_choice&&Object.keys(fieldsOf(r.id)).length&&!floorUnmet(r));
321
+ a.appendChild(el("p",{class:changed?"does asreq":"does"},changed?"As requested, "+r.consequence.charAt(0).toLowerCase()+r.consequence.slice(1):r.consequence));
272
322
  if(r.intention)a.appendChild(el("p",null,r.intention));
273
323
  if(!decided[r.id]&&!pending[r.id]&&r.projection&&r.projection.stage==="awaiting_decision"&&(r.kind==="run_request"||r.kind==="work_proposal"||r.draft_review||r.delivery||r.person_words))a.appendChild(standardBlock(r,token));
274
324
  var det=el("details");det.appendChild(el("summary",null,"What exactly is asked"));det.appendChild(el("pre",null,r.detail||""));a.appendChild(det);
@@ -296,23 +346,34 @@ summary:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
296
346
  function approvalLink(){var p=el("p",{class:"note"});p.appendChild(document.createTextNode(r.kind==="participant_consent_request"?"Only the person it asks decides this. Its page: ":"Decide on its approval page: "));p.appendChild(el("a",{href:r.approval_url,target:"_blank",rel:"noopener"},"open the approval page"));return p;}
297
347
  if(pending[r.id]){status.className="note";status.textContent="Recording your decision…";a.appendChild(status);return a;}
298
348
  if(!token||!host()||!host().callTool){a.appendChild(approvalLink());return a;}
299
- var ta=el("textarea",{"aria-label":"Instructions or changes (needed to approve with changes or send back)",placeholder:"Instructions or changes (needed to approve with changes or send back)"});
349
+ // With model fields, the rule for instructions is a line of its own: a placeholder is clipped and leaves once typing starts (critic U8).
350
+ var hintId="ih-"+String(r.id).replace(/[^A-Za-z0-9-]/g,"");
351
+ if(r.model_choice)a.appendChild(el("p",{class:"small hint",id:hintId},"Instructions are needed to send back. To approve with changes, write them or set the model below."));
352
+ var hint=r.model_choice?"Instructions or changes":"Instructions or changes (needed to approve with changes or send back)";
353
+ var ta=el("textarea",r.model_choice?{"aria-label":hint,placeholder:hint,"aria-describedby":hintId}:{"aria-label":hint,placeholder:hint});
300
354
  ta.value=typed[r.id]||"";boxes[r.id]=ta;
301
355
  ta.addEventListener("input",function(){typed[r.id]=ta.value;});
302
356
  a.appendChild(ta);
357
+ if(r.model_choice)a.appendChild(modelBlock(r));
303
358
  var row=el("div",{class:"row"});
304
359
  // The ring on a mission would move with its report and read as a verdict, so a mission's buttons carry none (jgwill/Miadi#939).
305
360
  var mission=r.kind==="run_request"||r.kind==="work_proposal";
306
361
  var buttons=[["approve","Approve",mission?"":"primary"],["approve_with_changes","Approve with my changes",""],["request_revision","Send back for revision",""],["decline","Decline",""]];
307
362
  var btns=[];
308
- buttons.forEach(function(b){var x=el("button",{type:"button",class:b[2]},b[1]);x.addEventListener("click",function(){go(b[0]);});btns.push(x);row.appendChild(x);});
363
+ // A field set, or a floor no model meets, leaves only Approve with my changes: the plain Approve would be refused (critic U1, U5).
364
+ var asRequestedOff=Boolean(r.model_choice&&(floorUnmet(r)||Object.keys(fieldsOf(r.id)).length));
365
+ buttons.forEach(function(b){var x=el("button",{type:"button",class:b[2]},b[1]);x.addEventListener("click",function(){go(b[0]);});if(b[0]==="approve"&&asRequestedOff){x.disabled=true;x.setAttribute("title",floorUnmet(r)?"No permitted model meets the floor: name one and use Approve with my changes":"A model field is set: use Approve with my changes, or set it back to Keep");}btns.push(x);row.appendChild(x);});
309
366
  a.appendChild(row);a.appendChild(status);
310
367
  if(errors[r.id]){status.className="fail";status.textContent=errors[r.id];if(relink[r.id])a.appendChild(approvalLink());}
311
368
  function go(choice){
312
369
  var text=ta.value.trim();
313
- if((choice==="approve_with_changes"||choice==="request_revision")&&!text){status.className="fail";status.textContent=choice==="request_revision"?"Say what to revise.":"Write the changes to apply.";ta.focus();return;}
370
+ var set=r.model_choice?fieldsOf(r.id):{};var any=Object.keys(set).length>0;
371
+ if(any&&choice==="approve"){status.className="fail";status.textContent="A model field changes the request: press Approve with my changes, or set it back to Keep.";return;}
372
+ if((choice==="approve_with_changes"&&!text&&!any)||(choice==="request_revision"&&!text)){status.className="fail";status.textContent=choice==="request_revision"?"Say what to revise.":"Write the changes to apply, or set a model field.";ta.focus();return;}
314
373
  btns.forEach(function(x){x.disabled=true;});status.className="note";status.textContent="Recording your decision…";pending[r.id]=true;delete errors[r.id];
315
- host().callTool("decide_request",{record_id:r.id,decision:choice,instructions:text||undefined,decision_token:token}).then(function(res){
374
+ var args={record_id:r.id,decision:choice,instructions:text||undefined,decision_token:token};
375
+ if(choice==="approve_with_changes")for(var k in set)args[k]=set[k];
376
+ host().callTool("decide_request",args).then(function(res){
316
377
  var out=toolResult(res);
317
378
  // The connector answers with the request's projection, also when a click finds it decided already.
318
379
  var proj=out&&(out.projection||(out.detail&&out.detail.projection));
@@ -1,5 +1,5 @@
1
1
  import { type JevAdapter } from "./model-preflight.js";
2
- import { type MissionStandard, type SettledBy, type StandardSource } from "./mission-standard.js";
2
+ import { type MissionStandard, type SettledBy, type StandardAspect, type StandardSource } from "./mission-standard.js";
3
3
  import type { ConnectorRecord } from "./records.js";
4
4
  /** Two rounds of report and revision, then the open aspects go on the card (D4). */
5
5
  export declare const MAX_ROUNDS = 2;
@@ -67,6 +67,8 @@ export declare function runningMissions(records: ConnectorRecord[], selfId: stri
67
67
  })[];
68
68
  /** The mission cut into sentences to choose among: Jev picks, it does not write (Episode 564, read gate F3). */
69
69
  export declare function sentencesOf(text: string, limit?: number): string[];
70
+ /** The S7 finding for a mission whose model Jev chooses: a missing task_type, and a floor in the words with no model_floor. */
71
+ export declare function modelFinding(record: ConnectorRecord, text: string, aspect: StandardAspect): Finding | null;
70
72
  export interface ReviewInput {
71
73
  record: ConnectorRecord;
72
74
  records: ConnectorRecord[];
@@ -16,7 +16,8 @@
16
16
  import { join } from "node:path";
17
17
  import { jevConfigOf } from "./providers.js";
18
18
  import { jevAdapter } from "./model-preflight.js";
19
- import { standardSource } from "./mission-standard.js";
19
+ import { MODEL_ASPECT, standardSource } from "./mission-standard.js";
20
+ import { JEV_WITHIN_CLAUDE } from "./claude-models.js";
20
21
  import { versionOf } from "./revisions.js";
21
22
  import { Ledger } from "./store.js";
22
23
  /** Two rounds of report and revision, then the open aspects go on the card (D4). */
@@ -98,6 +99,26 @@ export function sentencesOf(text, limit = 40) {
98
99
  .filter((s) => s.length >= 20)
99
100
  .slice(0, limit);
100
101
  }
102
+ /** Words that set a model or a floor for one: a model's name, a reasoning or review tier, the strongest model (jgwill/Miadi#1028). */
103
+ const FLOOR_WORDS = /\b(opus|fable|sonnet|haiku)\b|\b(?:high|higher|highest|strong|stronger|strongest|top)[- ](?:reasoning|judg(?:e)?ment|capability|model|tier)\b|\b(?:model|review|reasoning)[- ](?:floor|tier)\b|\bmost capable\b/i;
104
+ const PLAIN_FLOOR = /\b(opus|fable|sonnet|haiku|floor|tier)\b|\bmost capable\b/i;
105
+ /** The S7 finding for a mission whose model Jev chooses: a missing task_type, and a floor in the words with no model_floor. */
106
+ export function modelFinding(record, text, aspect) {
107
+ const b = record.body;
108
+ if (b.model_routing !== JEV_WITHIN_CLAUDE || (typeof b.model === "string" && b.model))
109
+ return null;
110
+ const notes = [];
111
+ if (typeof b.task_type !== "string")
112
+ notes.push("No task_type: the model is chosen as for an implementation task at normal criticality, which the fit notes give to Sonnet.");
113
+ // The sentence that sets the floor most plainly (a model's name, a floor, a tier) is the one shown.
114
+ const sentences = typeof b.model_floor === "string" ? [] : sentencesOf(text, 200).filter((s) => FLOOR_WORDS.test(s));
115
+ const said = typeof b.model_floor === "string" ? null : (sentences.find((s) => PLAIN_FLOOR.test(s)) ?? sentences[0] ?? text.match(FLOOR_WORDS)?.[0] ?? null);
116
+ if (said)
117
+ notes.push("The mission's words set a model or a floor, and no model_floor carries it to the choice: Jev never reads the words.");
118
+ if (!notes.length)
119
+ return null;
120
+ return { ...finding(aspect, "code", said ?? undefined), note: notes.join(" ") };
121
+ }
101
122
  const missionText = (r) => {
102
123
  const b = r.body;
103
124
  return b.task ?? [b.title, b.desired_outcome].filter(Boolean).join("\n\n");
@@ -119,12 +140,14 @@ export async function reviewDraft({ record, records, standard, adapter, now = Da
119
140
  const delivery = typeof body.delivery === "string" ? body.delivery.trim() : "";
120
141
  const personWords = typeof body.person_words === "string" ? body.person_words.trim() : "";
121
142
  const text = missionText(record);
122
- const aspect = (code) => standard.aspects.find((a) => a.code === code);
123
- const handledInCode = new Set(["S1", "S3", "S6"]);
143
+ // S7 is checked in code; the built-in words stand until the prompt store's standard has its own (jgwill/Miadi#1028).
144
+ const aspects = standard.aspects.some((a) => a.code === MODEL_ASPECT.code) ? standard.aspects : [...standard.aspects, MODEL_ASPECT];
145
+ const aspect = (code) => aspects.find((a) => a.code === code);
146
+ const handledInCode = new Set(["S1", "S3", "S6", "S7"]);
124
147
  // What goes to Jev: the delivery on its own when code cannot vouch for it, the mission for everything else.
125
148
  const s1 = aspect("S1");
126
149
  const askDelivery = Boolean(s1?.jev && delivery && !namesExactPlace(delivery));
127
- const onTask = standard.aspects.filter((a) => a.jev && !handledInCode.has(a.code) && !(a.code === "S5" && personWords));
150
+ const onTask = aspects.filter((a) => a.jev && !handledInCode.has(a.code) && !(a.code === "S5" && personWords));
128
151
  const asks = [];
129
152
  const paid = [];
130
153
  let jev = adapter ? { state: "ran", model: standard.jev_model, uncalibrated: true } : { state: "unconfigured" };
@@ -156,8 +179,13 @@ export async function reviewDraft({ record, records, standard, adapter, now = Da
156
179
  const needs = [];
157
180
  const notChecked = [];
158
181
  const running = runningMissions(records, record.id, now);
159
- for (const a of standard.aspects) {
160
- if (a.code === "S1") {
182
+ for (const a of aspects) {
183
+ if (a.code === "S7") {
184
+ const f = modelFinding(record, text, a);
185
+ if (f)
186
+ needs.push(f);
187
+ }
188
+ else if (a.code === "S1") {
161
189
  if (!delivery)
162
190
  needs.push(finding(a, "code"));
163
191
  else if (askDelivery) {
@@ -53,6 +53,11 @@ export interface MissionStandard {
53
53
  /** Standing preferences by person id, returned to the agent drafting for that person. */
54
54
  preferences: Record<string, string[]>;
55
55
  }
56
+ /**
57
+ * What the model of a mission is chosen from (jgwill/Miadi#1028). Checked in code, so it runs while the
58
+ * prompt store's standard has no S7: a store standard that has one replaces its words.
59
+ */
60
+ export declare const MODEL_ASPECT: StandardAspect;
56
61
  export declare const BUILT_IN_STANDARD: MissionStandard;
57
62
  /** The stored document, or an error saying what is outside the contract. A model alias is refused: one pinned version per standard. */
58
63
  export declare function parseStandard(text: string, version: number): MissionStandard;
@@ -16,6 +16,19 @@ export const STANDARD_NAME = "mission-standard";
16
16
  const CACHE_MS = 10 * 60 * 1000;
17
17
  const STORE_TIMEOUT_MS = 3000;
18
18
  const DEFAULT_STORE_URL = "https://cloud.langfuse.com";
19
+ /**
20
+ * What the model of a mission is chosen from (jgwill/Miadi#1028). Checked in code, so it runs while the
21
+ * prompt store's standard has no S7: a store standard that has one replaces its words.
22
+ */
23
+ export const MODEL_ASPECT = {
24
+ code: "S7",
25
+ name: "the model the mission needs",
26
+ requires: "A mission whose model Jev chooses says its task_type, and sets model_floor when its words set a floor or name a model.",
27
+ why: "Jev reads only the task type and criticality, never the words. A missing task type is chosen as implementation, which goes to Sonnet, and a floor written only in the text never reaches the choice.",
28
+ ask: "What kind of task is this, and what is the weakest model it may run on?",
29
+ fix: "Set task_type and criticality, and model_floor when the words set a floor (or model when the person named one).",
30
+ settled_by: "drafter",
31
+ };
19
32
  export const BUILT_IN_STANDARD = {
20
33
  name: STANDARD_NAME,
21
34
  version: 1,
@@ -100,6 +113,7 @@ export const BUILT_IN_STANDARD = {
100
113
  fix: "Name them in refs and primary_issue.",
101
114
  settled_by: "drafter",
102
115
  },
116
+ MODEL_ASPECT,
103
117
  ],
104
118
  };
105
119
  const isText = (v) => typeof v === "string" && v.trim().length > 0;