@miadi/connector 0.1.38 → 0.1.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -23
- package/STEERING.md +7 -3
- package/dist/approve.d.ts +28 -3
- package/dist/approve.js +179 -25
- package/dist/claude-models.d.ts +69 -4
- package/dist/claude-models.js +111 -22
- package/dist/config.d.ts +2 -2
- package/dist/config.js +4 -2
- package/dist/decisions.d.ts +1 -1
- package/dist/decisions.js +68 -7
- package/dist/draft-review.d.ts +3 -1
- package/dist/draft-review.js +34 -6
- package/dist/mission-standard.d.ts +5 -0
- package/dist/mission-standard.js +14 -0
- package/dist/tools.js +72 -20
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
package/dist/approve.js
CHANGED
|
@@ -27,7 +27,8 @@ import { readSteerDelivery } from "./runtime-steer.js";
|
|
|
27
27
|
import { adapterOfRoute, readFactoryConfig } from "./steering-adapters.js";
|
|
28
28
|
import { steerAttempts, steerSession, tmuxAdapter } from "./steer.js";
|
|
29
29
|
import { contentHash, versionOf } from "./revisions.js";
|
|
30
|
-
import { modelAttributes, routeModel } from "./claude-models.js";
|
|
30
|
+
import { claudeModelConfig, floorOf, floorRefusal, isPermittedModel, JEV_WITHIN_CLAUDE, labelsOf, meetsFloor, modelAttributes, MODEL_NAME, modelsMeetingFloor, routeModel, } from "./claude-models.js";
|
|
31
|
+
import { CRITICALITIES, TASK_TYPES } from "./model-preflight.js";
|
|
31
32
|
import { TRANSCRIPT_RETRY_MS, transcriptStep } from "./captions.js";
|
|
32
33
|
import { reviewTranscriptService, settleTranscriptJobs } from "./transcript-job.js";
|
|
33
34
|
import { settleTranscriptRequests } from "./transcript-intake.js";
|
|
@@ -265,7 +266,46 @@ async function videoOfReview(deps, reviewId) {
|
|
|
265
266
|
return null;
|
|
266
267
|
}
|
|
267
268
|
}
|
|
268
|
-
|
|
269
|
+
/** Whether a mission's model is chosen by routing (a model named, or Jev's choice): only then do the approver's model fields apply. */
|
|
270
|
+
export function isClaudeRouted(r) {
|
|
271
|
+
const b = r.body;
|
|
272
|
+
return (r.kind === "run_request" || r.kind === "work_proposal") && ((typeof b.model === "string" && Boolean(b.model)) || b.model_routing === JEV_WITHIN_CLAUDE);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* The model fields a person sets when approving with changes, checked as a request's are: a model on the permitted
|
|
276
|
+
* list, a task type and criticality from their lists, and only on a mission whose model is routed on Claude Code
|
|
277
|
+
* (jgwill/Miadi#1029). Empty fields are no change.
|
|
278
|
+
*/
|
|
279
|
+
export function approverRoutingOf(r, fields, permitted) {
|
|
280
|
+
const text = (v) => (typeof v === "string" && v.trim() ? v.trim() : undefined);
|
|
281
|
+
const model = text(fields.model);
|
|
282
|
+
const task_type = text(fields.task_type);
|
|
283
|
+
const criticality = text(fields.criticality);
|
|
284
|
+
if (!model && !task_type && !criticality)
|
|
285
|
+
return {};
|
|
286
|
+
if (!isClaudeRouted(r)) {
|
|
287
|
+
const provider = String(r.body.resolved_provider ?? r.body.provider ?? "another provider");
|
|
288
|
+
return { refusal: { code: "model_provider_mismatch", message: `This mission runs on ${provider}, so a Claude Code model, task type or criticality cannot be set for it. Nothing was decided.` } };
|
|
289
|
+
}
|
|
290
|
+
if (model && (!MODEL_NAME.test(model) || !isPermittedModel(model, permitted))) {
|
|
291
|
+
return { refusal: { code: "model_not_permitted", message: `${model} is not a permitted Claude Code model on this host (${permitted.join(", ")}). Nothing was decided.`, permitted } };
|
|
292
|
+
}
|
|
293
|
+
if (task_type && !TASK_TYPES.includes(task_type))
|
|
294
|
+
return { refusal: { code: "invalid_request", message: `${task_type} is not a task type (${TASK_TYPES.join(", ")}). Nothing was decided.` } };
|
|
295
|
+
if (criticality && !CRITICALITIES.includes(criticality))
|
|
296
|
+
return { refusal: { code: "invalid_request", message: `${criticality} is not a criticality (${CRITICALITIES.join(", ")}). Nothing was decided.` } };
|
|
297
|
+
const named = r.body.model;
|
|
298
|
+
if (!model && typeof named === "string" && named) {
|
|
299
|
+
return { refusal: { code: "labels_take_no_part", message: `This mission names its model (${named}), so a task type or criticality would change nothing. Set the model instead. Nothing was decided.` } };
|
|
300
|
+
}
|
|
301
|
+
return { routing: { ...(model ? { model } : {}), ...(task_type ? { task_type: task_type } : {}), ...(criticality ? { criticality: criticality } : {}) } };
|
|
302
|
+
}
|
|
303
|
+
/** The model fields a decision carries, as recorded in its receipt; a rerun runs with them again. */
|
|
304
|
+
const routingOfReceipt = (receipt) => {
|
|
305
|
+
const c = receipt.routing_changes;
|
|
306
|
+
return c && typeof c === "object" && Object.keys(c).length ? c : undefined;
|
|
307
|
+
};
|
|
308
|
+
export async function executeApproved(record, approver, deps, instructions, approverRouting) {
|
|
269
309
|
const f = deps.fetchImpl ?? fetch;
|
|
270
310
|
const b = record.body;
|
|
271
311
|
const reviewCall = (method, path, payload) => callReview(deps, method, path, payload);
|
|
@@ -287,10 +327,11 @@ export async function executeApproved(record, approver, deps, instructions) {
|
|
|
287
327
|
}
|
|
288
328
|
// A session already running keeps its model: a named one cannot be honoured, and Jev is not asked (jgwill/Miadi#943).
|
|
289
329
|
const existingSession = record.kind === "run_request" && typeof b.session === "string" && sessions.includes(b.session);
|
|
290
|
-
|
|
291
|
-
|
|
330
|
+
const named = approverRouting?.model ?? (typeof b.model === "string" && b.model ? b.model : null);
|
|
331
|
+
if (existingSession && named) {
|
|
332
|
+
return { outcome: "failed", message: `No brief was written. Session ${b.session} is already running on its own model, so ${named} cannot apply. Run it again once that session has ended, or make a new request with another session name.` };
|
|
292
333
|
}
|
|
293
|
-
const routing = await routeModel(record, { existingSession }, { factoryDir: deps.factoryDir, ...deps.modelRouting });
|
|
334
|
+
const routing = await routeModel(record, { existingSession, ...(approverRouting ? { approver: approverRouting } : {}), instructions: Boolean(instructions) }, { factoryDir: deps.factoryDir, ...deps.modelRouting });
|
|
294
335
|
if (routing?.source === "unavailable") {
|
|
295
336
|
return { outcome: "failed", model_routing: routing, message: `No brief was written. ${routing.why}, and no other provider stands in for it. Run it again once it is back.` };
|
|
296
337
|
}
|
|
@@ -524,6 +565,17 @@ fieldset{border:1px solid var(--line);border-radius:.4rem;margin:1rem 0;padding:
|
|
|
524
565
|
fieldset legend{float:left;width:100%;padding:0;margin-bottom:.3rem;font-size:.95rem}
|
|
525
566
|
fieldset label{clear:both;display:flex;align-items:flex-start;gap:.5rem;min-height:34px;margin:.45rem 0;font-weight:400}
|
|
526
567
|
input[type=radio]{accent-color:var(--accent);flex:0 0 auto;margin:.3rem 0 0}
|
|
568
|
+
select{width:100%;min-width:0;max-width:100%;min-height:34px;box-sizing:border-box;padding:.4rem .5rem;border:1px solid var(--line);border-radius:.4rem;background:var(--bg);color:var(--fg);font:inherit}
|
|
569
|
+
select:focus-visible,textarea:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
|
|
570
|
+
.model-fields{margin-top:.6rem}
|
|
571
|
+
.model-fields .pair{display:grid;grid-template-columns:7.5rem minmax(0,22rem);gap:.5rem;align-items:center;margin:.45rem 0}
|
|
572
|
+
.model-fields .pair label{clear:both;margin:0;min-height:0;font-weight:400}
|
|
573
|
+
.model-fields .pair>*{min-width:0}
|
|
574
|
+
.gv{display:grid;grid-template-columns:1rem minmax(0,1fr);gap:.4rem;align-items:start}
|
|
575
|
+
.gv .glyph{margin-top:.3rem}
|
|
576
|
+
.gv.stopped .glyph{color:var(--err,#b00020)}
|
|
577
|
+
.hint{margin:.1rem 0 .4rem;font-size:.9rem}
|
|
578
|
+
@media (max-width:480px){.model-fields .pair{grid-template-columns:minmax(0,1fr);gap:.2rem}}
|
|
527
579
|
.code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:.9em}
|
|
528
580
|
.glyph{margin-top:.25rem;color:var(--muted)}
|
|
529
581
|
.wordsLabel{margin-bottom:.1rem}
|
|
@@ -585,6 +637,9 @@ export class ProviderChoiceRequired extends Error {
|
|
|
585
637
|
this.authorization = authorization;
|
|
586
638
|
}
|
|
587
639
|
}
|
|
640
|
+
/** An approval no permitted model can run: the request sets a floor none meets, and the approver named no model (jgwill/Miadi#1028). */
|
|
641
|
+
export class ModelFloorUnmet extends Error {
|
|
642
|
+
}
|
|
588
643
|
/** The decisions being recorded now, by request id: one at a time per request, in this process. */
|
|
589
644
|
const deciding = new Map();
|
|
590
645
|
/** Whether a decision on this request is being recorded now, its run may still be going. */
|
|
@@ -601,7 +656,11 @@ const APPROVAL_OF = {
|
|
|
601
656
|
export function approvalStateOf(choice) {
|
|
602
657
|
return APPROVAL_OF[choice];
|
|
603
658
|
}
|
|
604
|
-
const
|
|
659
|
+
const routingKey = (r) => {
|
|
660
|
+
const o = (r ?? {});
|
|
661
|
+
return ["model", "task_type", "criticality"].map((k) => String(o[k] ?? "")).join("|");
|
|
662
|
+
};
|
|
663
|
+
const sameDecision = (a, b) => a.choice === b.choice && String(a.instructions ?? "").trim() === String(b.instructions ?? "").trim() && routingKey(a.routing) === routingKey(b.routing);
|
|
605
664
|
/**
|
|
606
665
|
* Record a person's decision once. The page and the card (or two cards, or a host
|
|
607
666
|
* that retries a call it gave up waiting on) may send it more than once:
|
|
@@ -614,10 +673,10 @@ export async function decide(r, person, choice, deps, opts) {
|
|
|
614
673
|
// Checked again here, with no await between the check and the claim: the
|
|
615
674
|
// page and the card (or two cards) may decide the same request at once, and
|
|
616
675
|
// a revision may land between reading a version and deciding it (#919).
|
|
617
|
-
const asked = { choice, instructions: opts.instructions };
|
|
676
|
+
const asked = { choice, instructions: opts.instructions, routing: opts.routing };
|
|
618
677
|
const inflight = deciding.get(r.id);
|
|
619
678
|
if (inflight) {
|
|
620
|
-
if (inflight.promise && inflight.choice !== "rerun" && sameDecision({ choice: inflight.choice, instructions: inflight.instructions }, asked)) {
|
|
679
|
+
if (inflight.promise && inflight.choice !== "rerun" && sameDecision({ choice: inflight.choice, instructions: inflight.instructions, routing: inflight.routing }, asked)) {
|
|
621
680
|
logDecision(deps, { phase: "replay", record: r.id, correlation: inflight.correlation, via: opts.via, choice, while: "recording" });
|
|
622
681
|
return { ...(await inflight.promise), replayed: true };
|
|
623
682
|
}
|
|
@@ -633,7 +692,7 @@ export async function decide(r, person, choice, deps, opts) {
|
|
|
633
692
|
if (live.approval_state !== "awaiting_approval") {
|
|
634
693
|
const prior = (live.completion_receipt ?? {});
|
|
635
694
|
const priorVersion = typeof prior.version === "number" ? prior.version : 1;
|
|
636
|
-
if (typeof prior.decision === "string" && sameDecision({ choice: prior.decision, instructions: prior.instructions }, asked) && priorVersion === decidedVersion) {
|
|
695
|
+
if (typeof prior.decision === "string" && sameDecision({ choice: prior.decision, instructions: prior.instructions, routing: prior.routing_changes }, asked) && priorVersion === decidedVersion) {
|
|
637
696
|
logDecision(deps, { phase: "replay", record: r.id, via: opts.via, choice, while: "recorded", state: live.state });
|
|
638
697
|
return { decision: live.approval_state, state: live.state, receipt: prior, replayed: true };
|
|
639
698
|
}
|
|
@@ -650,6 +709,14 @@ export async function decide(r, person, choice, deps, opts) {
|
|
|
650
709
|
throw new ProviderChoiceRequired(authorization);
|
|
651
710
|
}
|
|
652
711
|
}
|
|
712
|
+
// A floor no permitted model meets launches nothing: refused before anything is recorded, so it still awaits a decision (jgwill/Miadi#1028).
|
|
713
|
+
if (approvalStateOf(choice) === "approved") {
|
|
714
|
+
const refused = floorRefusal(live, opts.routing, claudeModelConfig(deps.factoryDir ?? factoryDir(), deps.modelRouting?.modelOf));
|
|
715
|
+
if (refused) {
|
|
716
|
+
logDecision(deps, { phase: "model_floor_unmet", record: r.id, via: opts.via, choice });
|
|
717
|
+
throw new ModelFloorUnmet(refused);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
653
720
|
const entry = { ...asked, correlation: randomUUID(), started: Date.now() };
|
|
654
721
|
deciding.set(r.id, entry);
|
|
655
722
|
entry.promise = decideOnce(live, person, choice, deps, { ...opts, correlation: entry.correlation, started: entry.started });
|
|
@@ -820,11 +887,13 @@ export async function rerun(r, person, deps, opts) {
|
|
|
820
887
|
try {
|
|
821
888
|
const prior = (live.completion_receipt ?? {});
|
|
822
889
|
const instructions = typeof prior.instructions === "string" ? prior.instructions : undefined;
|
|
890
|
+
const routing = routingOfReceipt(prior);
|
|
823
891
|
let receipt = {
|
|
824
892
|
decided_by: prior.decided_by,
|
|
825
893
|
decided_at: prior.decided_at,
|
|
826
894
|
decision: prior.decision,
|
|
827
895
|
...(instructions ? { instructions } : {}),
|
|
896
|
+
...(routing ? { routing_changes: routing } : {}),
|
|
828
897
|
rerun_by: { person_id: person.id, name: person.name },
|
|
829
898
|
rerun_at: new Date().toISOString(),
|
|
830
899
|
via: opts.via,
|
|
@@ -832,7 +901,7 @@ export async function rerun(r, person, deps, opts) {
|
|
|
832
901
|
};
|
|
833
902
|
let state = "completed";
|
|
834
903
|
try {
|
|
835
|
-
const outcome = await executeApproved(live, person, deps, instructions);
|
|
904
|
+
const outcome = await executeApproved(live, person, deps, instructions, routing);
|
|
836
905
|
receipt = { ...receipt, ...outcome };
|
|
837
906
|
if (outcome.outcome === "failed")
|
|
838
907
|
state = "blocked";
|
|
@@ -863,7 +932,7 @@ export async function rerun(r, person, deps, opts) {
|
|
|
863
932
|
}
|
|
864
933
|
}
|
|
865
934
|
async function decideOnce(r, person, choice, deps, opts) {
|
|
866
|
-
const { instructions } = opts;
|
|
935
|
+
const { instructions, routing } = opts;
|
|
867
936
|
const decision = approvalStateOf(choice);
|
|
868
937
|
logDecision(deps, { phase: "start", record: r.id, kind: r.kind, correlation: opts.correlation, via: opts.via, choice, version: versionOf(r) });
|
|
869
938
|
let receipt = {
|
|
@@ -875,6 +944,8 @@ async function decideOnce(r, person, choice, deps, opts) {
|
|
|
875
944
|
content_hash: contentHash(r),
|
|
876
945
|
via: opts.via,
|
|
877
946
|
...(instructions ? { instructions } : {}),
|
|
947
|
+
// The model fields the approver set: they take part in the choice, and a rerun runs with them (jgwill/Miadi#1029).
|
|
948
|
+
...(routing && Object.keys(routing).length ? { routing_changes: routing } : {}),
|
|
878
949
|
note: opts.note,
|
|
879
950
|
correlation: opts.correlation,
|
|
880
951
|
};
|
|
@@ -897,12 +968,12 @@ async function decideOnce(r, person, choice, deps, opts) {
|
|
|
897
968
|
approval_state: decision,
|
|
898
969
|
state: "in_progress",
|
|
899
970
|
completion_receipt: { ...receipt, outcome: "running", started_at: new Date(opts.started).toISOString() },
|
|
900
|
-
body: { decision: choice, ...(instructions ? { instructions } : {}) },
|
|
971
|
+
body: { decision: choice, ...(instructions ? { instructions } : {}), ...(routing && Object.keys(routing).length ? { routing_changes: routing } : {}) },
|
|
901
972
|
});
|
|
902
973
|
logDecision(deps, { phase: "running", record: r.id, correlation: opts.correlation, ms: Date.now() - opts.started });
|
|
903
974
|
}
|
|
904
975
|
try {
|
|
905
|
-
const outcome = await executeApproved(r, person, deps, instructions);
|
|
976
|
+
const outcome = await executeApproved(r, person, deps, instructions, routing);
|
|
906
977
|
receipt = { ...receipt, ...outcome };
|
|
907
978
|
if (outcome.outcome === "failed")
|
|
908
979
|
state = "blocked";
|
|
@@ -926,7 +997,7 @@ async function decideOnce(r, person, choice, deps, opts) {
|
|
|
926
997
|
state,
|
|
927
998
|
...(decision === "revision_requested" ? { next_action: `Revise it in place with revise_pending_request (request_id ${r.id}, expected_version ${versionOf(r)}).` } : {}),
|
|
928
999
|
completion_receipt: receipt,
|
|
929
|
-
body: { decision: choice, ...(instructions ? { instructions } : {}) },
|
|
1000
|
+
body: { decision: choice, ...(instructions ? { instructions } : {}), ...(routing && Object.keys(routing).length ? { routing_changes: routing } : {}) },
|
|
930
1001
|
});
|
|
931
1002
|
logDecision(deps, {
|
|
932
1003
|
phase: "done",
|
|
@@ -943,10 +1014,24 @@ async function decideOnce(r, person, choice, deps, opts) {
|
|
|
943
1014
|
export function isApprovable(r) {
|
|
944
1015
|
return Boolean(r && APPROVABLE.has(r.kind));
|
|
945
1016
|
}
|
|
946
|
-
|
|
1017
|
+
/** The model in one clause: a named one, or Jev's choice with the labels it reads and whether each is a default (jgwill/Miadi#1028). */
|
|
1018
|
+
function modelWords(b) {
|
|
1019
|
+
if (typeof b.model === "string" && b.model)
|
|
1020
|
+
return ` on ${b.model}`;
|
|
1021
|
+
if (!b.model_routing)
|
|
1022
|
+
return "";
|
|
1023
|
+
const t = labelsOf(b);
|
|
1024
|
+
const d = (s) => (s === "default" ? " (the default)" : "");
|
|
1025
|
+
const floor = floorOf(b);
|
|
1026
|
+
return ` on the model Jev chooses for task type ${t.type}${d(t.labels.task_type)} and criticality ${t.criticality}${d(t.labels.criticality)}${floor ? `, at or above ${floor}` : ""}`;
|
|
1027
|
+
}
|
|
947
1028
|
/** What approving a request does, in one sentence, for the card a person decides on. */
|
|
948
|
-
export function consequenceOf(r, authorization, records = [], steering) {
|
|
1029
|
+
export function consequenceOf(r, authorization, records = [], steering, floorUnmet = false) {
|
|
949
1030
|
const b = r.body;
|
|
1031
|
+
// A floor no permitted model meets: the first thing read is that approving as requested is refused (jgwill/Miadi#1028).
|
|
1032
|
+
if (floorUnmet && (r.kind === "run_request" || r.kind === "work_proposal")) {
|
|
1033
|
+
return `Approving as requested is refused: no permitted Claude Code model meets the floor this request sets (${String(b.model_floor)}). Approving with your changes runs it on the model you name.`;
|
|
1034
|
+
}
|
|
950
1035
|
switch (r.kind) {
|
|
951
1036
|
case "run_request":
|
|
952
1037
|
return authorization && !authorization.authorized
|
|
@@ -1093,18 +1178,29 @@ export function registerApprovalRoutes(app, deps) {
|
|
|
1093
1178
|
const choice = DECISIONS.includes(String(body.decision)) ? body.decision : "decline";
|
|
1094
1179
|
const instructions = String(body.instructions ?? "").trim().slice(0, 20000) || undefined;
|
|
1095
1180
|
const via = String(body.via ?? "approval-page").slice(0, 60);
|
|
1181
|
+
// The model fields take part in the choice; they are a change, so they go with Approve with my changes (jgwill/Miadi#1029).
|
|
1182
|
+
const fieldsCheck = approverRoutingOf(r, { model: body.model, task_type: body.task_type, criticality: body.criticality }, claudeModelConfig(deps.factoryDir ?? factoryDir(), deps.modelRouting?.modelOf).permitted);
|
|
1183
|
+
// A refused form comes back as it was sent: the words and the fields stay (critic U2).
|
|
1184
|
+
const kept = { instructions, model: body.model, task_type: body.task_type, criticality: body.criticality };
|
|
1185
|
+
if ("refusal" in fieldsCheck && (choice === "approve" || choice === "approve_with_changes"))
|
|
1186
|
+
return void res.status(400).type("html").send(approvePage(deps, r, { token, error: fieldsCheck.refusal.message, kept }));
|
|
1187
|
+
const routing = "routing" in fieldsCheck && choice === "approve_with_changes" ? fieldsCheck.routing : undefined;
|
|
1188
|
+
if ("routing" in fieldsCheck && fieldsCheck.routing && choice === "approve") {
|
|
1189
|
+
return void res.status(400).type("html").send(approvePage(deps, r, { token, error: "A model field changes the request: press Approve with my changes to apply it, or set the fields back to Keep.", kept }));
|
|
1190
|
+
}
|
|
1096
1191
|
// Only a decision that would be recorded now needs its instructions; a form sent again after it was recorded is answered below (#924).
|
|
1097
|
-
if (r.approval_state === "awaiting_approval" && !isBeingDecided(r.id) && (choice === "approve_with_changes" || choice === "request_revision") && !instructions) {
|
|
1192
|
+
if (r.approval_state === "awaiting_approval" && !isBeingDecided(r.id) && ((choice === "approve_with_changes" && !routing) || choice === "request_revision") && !instructions) {
|
|
1098
1193
|
return void res
|
|
1099
1194
|
.status(400)
|
|
1100
1195
|
.type("html")
|
|
1101
|
-
.send(approvePage(deps, r, { token, error: choice === "request_revision" ? "Say what to revise." : "Write the changes to apply." }));
|
|
1196
|
+
.send(approvePage(deps, r, { token, error: choice === "request_revision" ? "Say what to revise." : "Write the changes to apply, or set a model field.", kept }));
|
|
1102
1197
|
}
|
|
1103
1198
|
let decided;
|
|
1104
1199
|
try {
|
|
1105
1200
|
const shown = Number(body.version);
|
|
1106
1201
|
const running = decide(r, person, choice, deps, {
|
|
1107
1202
|
instructions,
|
|
1203
|
+
...(routing ? { routing } : {}),
|
|
1108
1204
|
note: body.note || undefined,
|
|
1109
1205
|
via,
|
|
1110
1206
|
...(Number.isInteger(shown) && shown >= 1 ? { expectedVersion: shown } : {}),
|
|
@@ -1125,6 +1221,8 @@ export function registerApprovalRoutes(app, deps) {
|
|
|
1125
1221
|
}
|
|
1126
1222
|
if (error instanceof StaleVersion)
|
|
1127
1223
|
return void res.status(409).type("html").send(approvePage(deps, find(r.id), { token, error: error.message }));
|
|
1224
|
+
if (error instanceof ModelFloorUnmet)
|
|
1225
|
+
return void res.status(409).type("html").send(approvePage(deps, find(r.id), { token, error: error.message, kept }));
|
|
1128
1226
|
if (error instanceof AlreadyDecided)
|
|
1129
1227
|
return void res.status(409).type("html").send(approvePage(deps, find(r.id), { error: error.message }));
|
|
1130
1228
|
throw error;
|
|
@@ -1512,6 +1610,57 @@ ${canAnswer && open.some((f) => f.settled_by === "drafter") ? `<p class="muted">
|
|
|
1512
1610
|
${canAnswer && open.length ? `<p class="muted">Approving as it stands starts the session, and the worker reads these questions with the task.</p>` : ""}
|
|
1513
1611
|
</section>`;
|
|
1514
1612
|
}
|
|
1613
|
+
const CPU_PATHS = `<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"/>`;
|
|
1614
|
+
const SET_BY = { requester: "set by the requester", approver: "set by the approver", default: "the default: the request sets none" };
|
|
1615
|
+
/**
|
|
1616
|
+
* Which model a mission runs on and what it is chosen from, before the click: the floor and what meets it, the labels
|
|
1617
|
+
* and who set each, that effort is not chosen, and that instructions do not choose the model (jgwill/Miadi#1028, #1029).
|
|
1618
|
+
* Deciding, the fields to change it sit in the same section, inside the form.
|
|
1619
|
+
*/
|
|
1620
|
+
function modelBlock(r, deps, deciding, kept = {}) {
|
|
1621
|
+
if (!isClaudeRouted(r))
|
|
1622
|
+
return "";
|
|
1623
|
+
const b = r.body;
|
|
1624
|
+
const config = claudeModelConfig(deps.factoryDir ?? factoryDir(), deps.modelRouting?.modelOf);
|
|
1625
|
+
const floor = floorOf(b);
|
|
1626
|
+
const meeting = floor ? modelsMeetingFloor(config, floor) : [];
|
|
1627
|
+
const named = typeof b.model === "string" && b.model ? b.model : null;
|
|
1628
|
+
const unmet = Boolean(floor && !meeting.length && !named);
|
|
1629
|
+
const t = labelsOf(b);
|
|
1630
|
+
const valued = (label, paths, text, cls = "") => `<span class="gv${cls}">${glyph(label, paths)}<span>${escapeHtml(text)}</span></span>`;
|
|
1631
|
+
const rows = [
|
|
1632
|
+
`<dt>Model</dt><dd>${named
|
|
1633
|
+
? valued("Named", CIRCLE_CHECK_PATHS, `${named}, named by the requester; Jev is not asked`)
|
|
1634
|
+
: unmet
|
|
1635
|
+
? valued("Refused", TRIANGLE_ALERT_PATHS, "none", " stopped")
|
|
1636
|
+
: valued("Awaiting the decision", DASHED_PATHS, `chosen by Jev when it is approved, among ${(floor ? meeting : config.permitted).join(", ")}`)}</dd>`,
|
|
1637
|
+
];
|
|
1638
|
+
if (floor)
|
|
1639
|
+
rows.push(`<dt>Floor</dt><dd>${escapeHtml(floor)}, set by the requester${meeting.length ? `; met by ${escapeHtml(meeting.join(", "))}` : ""}</dd>`);
|
|
1640
|
+
if (!named) {
|
|
1641
|
+
rows.push(`<dt>Task type</dt><dd>${escapeHtml(t.type)} (${SET_BY[t.labels.task_type]})</dd>`);
|
|
1642
|
+
rows.push(`<dt>Criticality</dt><dd>${escapeHtml(t.criticality)} (${SET_BY[t.labels.criticality]})</dd>`);
|
|
1643
|
+
}
|
|
1644
|
+
rows.push(`<dt>Effort</dt><dd>not chosen here: the seat starts at Claude Code's own effort setting on the host that opens it</dd>`);
|
|
1645
|
+
const refused = unmet
|
|
1646
|
+
? `<p class="state stopped">${glyph("Refused", TRIANGLE_ALERT_PATHS)}<span>No permitted model meets the floor (${escapeHtml(floor)}). Approving as requested is refused; name a model below and press Approve with my changes.</span></p>`
|
|
1647
|
+
: "";
|
|
1648
|
+
const words = deciding
|
|
1649
|
+
? "What you write under Instructions goes to the agent and does not choose the model. To change the model, set it here and press Approve with my changes."
|
|
1650
|
+
: "What the approver writes as instructions goes to the agent and does not choose the model; only the model fields do.";
|
|
1651
|
+
let fields = "";
|
|
1652
|
+
if (deciding) {
|
|
1653
|
+
const option = (value, chosen, note = "") => `<option value="${escapeHtml(value)}"${chosen === value ? " selected" : ""}>${escapeHtml(value + note)}</option>`;
|
|
1654
|
+
const select = (id, name, label, keep, values, chosen, noteOf = () => "") => `<div class="pair"><label for="${id}">${label}</label><select id="${id}" name="${name}"><option value="">${escapeHtml(keep)}</option>${values.map((v) => option(v, chosen, noteOf(v))).join("")}</select></div>`;
|
|
1655
|
+
const below = (v) => (floor && !meetsFloor(v, floor) ? " (below the floor)" : "");
|
|
1656
|
+
fields = `<div class="model-fields" role="group" aria-label="Change the model">
|
|
1657
|
+
${select("m", "model", "Model", named ? `Keep: ${named}` : unmet ? "Choose a model" : "Keep: Jev chooses", config.permitted, kept.model, below)}
|
|
1658
|
+
${named ? "" : select("tt", "task_type", "Task type", `Keep: ${t.type}${t.labels.task_type === "default" ? " (default)" : ""}`, TASK_TYPES, kept.task_type)}
|
|
1659
|
+
${named ? "" : select("cr", "criticality", "Criticality", `Keep: ${t.criticality}${t.labels.criticality === "default" ? " (default)" : ""}`, CRITICALITIES, kept.criticality)}
|
|
1660
|
+
</div>`;
|
|
1661
|
+
}
|
|
1662
|
+
return `<section class="standard" aria-label="The model"><h2>The model</h2>${refused}<dl>${rows.join("")}</dl>${stateLine("Instructions do not choose the model", CPU_PATHS, escapeHtml(words))}${fields}</section>`;
|
|
1663
|
+
}
|
|
1515
1664
|
const FILE_PLUS_PATHS = `<path d="M11.35 22H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v5.35"/><path d="M14 2v5a1 1 0 0 0 1 1h5"/><path d="M14 19h6"/><path d="M17 16v6"/>`;
|
|
1516
1665
|
/**
|
|
1517
1666
|
* What approving does, then what declining does. An ending that files capability holdings in an episode says so on a line
|
|
@@ -1532,6 +1681,8 @@ function approvePage(deps, r, o = {}) {
|
|
|
1532
1681
|
// Freshness binds a decision still to come; a decided run shows the authorization it holds (#926 review R1).
|
|
1533
1682
|
const authorization = r.kind === "run_request" ? authorizeProvider(r, deps.ledger.all(), { requireFresh: open }) : undefined;
|
|
1534
1683
|
const blocked = Boolean(authorization && !authorization.authorized);
|
|
1684
|
+
// A floor no permitted model meets: Approve and run would be refused, so only Approve with my changes (naming a model) is offered (jgwill/Miadi#1028).
|
|
1685
|
+
const floorUnmetHere = open && Boolean(floorRefusal(r, undefined, claudeModelConfig(deps.factoryDir ?? factoryDir(), deps.modelRouting?.modelOf)));
|
|
1535
1686
|
// Signed in and able to decide: the decision comes before the record's details, and no line says it waits for someone else.
|
|
1536
1687
|
const asksSomeone = r.kind === "participant_consent_request";
|
|
1537
1688
|
const canDecideHere = Boolean(actionable && o.token && !asksSomeone);
|
|
@@ -1551,27 +1702,30 @@ ${projectionBlock(projectionOf(r, deps), open ? undefined : r.completion_receipt
|
|
|
1551
1702
|
${canDecideHere ? `<p>You are signed in. Nothing is approved until you press a button below.</p>` : ""}
|
|
1552
1703
|
${asksSomeone && open && o.token && deps.consentLink ? consentMailSection(r, deps) : ""}
|
|
1553
1704
|
${asksSomeone && open && (o.token || o.chooserToken) && deps.consentLink ? `<p><strong>The link to send ${escapeHtml(String(r.body.decider_name))}:</strong><br><a href="${escapeHtml(deps.consentLink(r.id))}" rel="noreferrer">${escapeHtml(deps.consentLink(r.id))}</a></p>` : ""}
|
|
1554
|
-
${actionable ? effectParagraphs(consequenceOf(r, authorization, current(deps.ledger.all()))) : ""}
|
|
1705
|
+
${actionable ? effectParagraphs(consequenceOf(r, authorization, current(deps.ledger.all()), undefined, floorUnmetHere)) : ""}
|
|
1555
1706
|
${runSteeringLine(r, authorization?.provider ?? undefined, deps)}
|
|
1556
1707
|
${capabilitiesSection(r, deps.config.miadiPublicUrl)}
|
|
1557
1708
|
${canDecideHere && r.intention ? `<p><strong>Intention:</strong> ${escapeHtml(r.intention)}</p>` : ""}
|
|
1558
1709
|
${authorization ? providerSection(r, authorization, actionable ? o.chooserToken : undefined) : ""}
|
|
1710
|
+
${open && o.token && !(canDecideHere && !blocked) ? modelBlock(r, deps, false) : ""}
|
|
1559
1711
|
${canDecideHere ? draftReviewSection(r, deps.draftReview?.stored(r), !blocked) : ""}
|
|
1560
|
-
${o.error ? `<p class="err" role="alert">${escapeHtml(o.error)}</p>` : ""}
|
|
1712
|
+
${o.error ? `<p class="err" role="alert" id="decide">${escapeHtml(o.error)}</p>` : ""}
|
|
1561
1713
|
${asksSomeone && open && o.token && deps.consentLink && r.body.decider_person_id && !consentMailSent(deps, r.id)
|
|
1562
1714
|
? `<form method="post"><input type="hidden" name="person_token" value="${escapeHtml(o.token)}"><div class="row"><button class="primary" type="submit" name="decision" value="send_consent_mail">Send this email</button></div></form>`
|
|
1563
1715
|
: ""}
|
|
1564
1716
|
${canDecideHere
|
|
1565
|
-
? `<form method="post">
|
|
1717
|
+
? `<form method="post" action="#decide">
|
|
1566
1718
|
<input type="hidden" name="person_token" value="${escapeHtml(o.token)}">
|
|
1567
1719
|
<input type="hidden" name="version" value="${versionOf(r)}">
|
|
1568
|
-
<label for="i">Instructions
|
|
1569
|
-
<
|
|
1720
|
+
<label for="i">Instructions</label>
|
|
1721
|
+
<p class="muted hint" id="ih">Needed to send back. To approve with changes, write them or set the model below.</p>
|
|
1722
|
+
<textarea id="i" name="instructions" rows="4" aria-describedby="ih">${escapeHtml(o.kept?.instructions ?? "")}</textarea>
|
|
1723
|
+
${blocked ? "" : modelBlock(r, deps, true, o.kept)}
|
|
1570
1724
|
<div class="row">
|
|
1571
1725
|
${blocked
|
|
1572
1726
|
? ""
|
|
1573
|
-
: `<button${r.kind === "run_request" || r.kind === "work_proposal" ? "" : ' class="primary"'} type="submit" name="decision" value="approve">Approve and run</button>
|
|
1574
|
-
<button type="submit" name="decision" value="approve_with_changes">Approve with my changes</button>`}
|
|
1727
|
+
: `${floorUnmetHere ? "" : `<button${r.kind === "run_request" || r.kind === "work_proposal" ? "" : ' class="primary"'} type="submit" name="decision" value="approve">Approve and run</button>
|
|
1728
|
+
`}<button type="submit" name="decision" value="approve_with_changes">Approve with my changes</button>`}
|
|
1575
1729
|
<button type="submit" name="decision" value="request_revision">Send back for revision</button>
|
|
1576
1730
|
<button type="submit" name="decision" value="decline">Decline</button>
|
|
1577
1731
|
</div></form>`
|
package/dist/claude-models.d.ts
CHANGED
|
@@ -12,9 +12,15 @@ export interface ClaudeModel {
|
|
|
12
12
|
resolves_to: string;
|
|
13
13
|
/** What Jev reads: which task this model fits. The Factory's reading of Anthropic's model descriptions, not a measurement. */
|
|
14
14
|
capability_note: string;
|
|
15
|
+
/** Its place in the family, weakest first, as Anthropic orders it: haiku, sonnet, opus, fable. Read only for a floor (jgwill/Miadi#1028); Jev never sees it. */
|
|
16
|
+
rank: number;
|
|
15
17
|
}
|
|
16
18
|
/** Each answered a real prompt under `--model <id>` and under its full name. */
|
|
17
19
|
export declare const CLAUDE_MODELS: readonly ClaudeModel[];
|
|
20
|
+
/** A model's place in the family, by alias or full name; null for a name outside the catalog. */
|
|
21
|
+
export declare function modelRank(model: string): number | null;
|
|
22
|
+
/** Whether a model is at or above a floor. A model outside the catalog meets no floor: its strength is not known. */
|
|
23
|
+
export declare function meetsFloor(model: string, floor: string): boolean;
|
|
18
24
|
/** A run under one name proves that name on that host that day, and says nothing of a sign-in elsewhere. */
|
|
19
25
|
export declare const CLAUDE_MODELS_VERIFIED: {
|
|
20
26
|
on: string;
|
|
@@ -34,16 +40,31 @@ export type ModelPlan = {
|
|
|
34
40
|
fields: Record<string, string>;
|
|
35
41
|
} | {
|
|
36
42
|
refusal: {
|
|
37
|
-
code: "model_provider_mismatch" | "model_not_permitted";
|
|
43
|
+
code: "model_provider_mismatch" | "model_not_permitted" | "model_floor_unknown" | "model_below_floor";
|
|
38
44
|
message: string;
|
|
39
45
|
permitted: string[];
|
|
40
46
|
};
|
|
41
47
|
};
|
|
42
|
-
/** What a request records about its model, or why it may not be recorded. */
|
|
43
|
-
export declare function modelPlan(provider: string | null | undefined, model: string | null | undefined, permitted: string[]): ModelPlan;
|
|
48
|
+
/** What a request records about its model and its floor, or why it may not be recorded. */
|
|
49
|
+
export declare function modelPlan(provider: string | null | undefined, model: string | null | undefined, permitted: string[], floor?: string | null): ModelPlan;
|
|
50
|
+
/** The permitted models at or above a floor, in the order a launch offers them. */
|
|
51
|
+
export declare function modelsMeetingFloor(config: ClaudeModelConfig, floor: string): string[];
|
|
44
52
|
/** One candidate per permitted model, the configured one first: Jev's options, and the preflight's. */
|
|
45
53
|
export declare function claudeModelCandidates(found: ProviderAvailability[], config: ClaudeModelConfig, base?: Pick<ModelCandidate, "eligible" | "policy_reason">): ModelCandidate[];
|
|
46
|
-
export type ModelSource = "request" | "jev" | "configured_fallback" | "cli_default" | "existing_session" | "unavailable";
|
|
54
|
+
export type ModelSource = "request" | "approver" | "jev" | "configured_fallback" | "cli_default" | "existing_session" | "unavailable";
|
|
55
|
+
/** Who set a label the choice was made from: the requester, the approver when approving with changes, or nobody (the default). */
|
|
56
|
+
export type LabelSource = "requester" | "approver" | "default";
|
|
57
|
+
/** What the person approving with changes set for the model, in fields; their instructions are text and are not among them (jgwill/Miadi#1029). */
|
|
58
|
+
export interface ApproverRouting {
|
|
59
|
+
model?: string;
|
|
60
|
+
task_type?: TaskType;
|
|
61
|
+
criticality?: Criticality;
|
|
62
|
+
}
|
|
63
|
+
/** 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). */
|
|
64
|
+
export declare const EFFORT_NOT_ROUTED: {
|
|
65
|
+
routed: false;
|
|
66
|
+
note: string;
|
|
67
|
+
};
|
|
47
68
|
export interface ModelRouting {
|
|
48
69
|
contract: typeof MODEL_ROUTING_CONTRACT;
|
|
49
70
|
version: 1;
|
|
@@ -62,6 +83,29 @@ export interface ModelRouting {
|
|
|
62
83
|
type: TaskType;
|
|
63
84
|
criticality: Criticality;
|
|
64
85
|
};
|
|
86
|
+
/** Who set each label the task was described with. */
|
|
87
|
+
labels?: {
|
|
88
|
+
task_type: LabelSource;
|
|
89
|
+
criticality: LabelSource;
|
|
90
|
+
};
|
|
91
|
+
/** What the approver's fields replaced: the request's labels, or its model (null: the request named none, so Jev was to choose). */
|
|
92
|
+
replaced?: {
|
|
93
|
+
model?: string | null;
|
|
94
|
+
task_type?: TaskType;
|
|
95
|
+
criticality?: Criticality;
|
|
96
|
+
};
|
|
97
|
+
/** The floor the requester set, and the permitted models that met it on this host. */
|
|
98
|
+
floor?: {
|
|
99
|
+
model: string;
|
|
100
|
+
set_by: "requester";
|
|
101
|
+
met_by: string[];
|
|
102
|
+
};
|
|
103
|
+
/** Whether what the approver wrote took part in the choice. Present only when they wrote something. */
|
|
104
|
+
instructions?: {
|
|
105
|
+
took_part: false;
|
|
106
|
+
note: string;
|
|
107
|
+
};
|
|
108
|
+
effort?: typeof EFFORT_NOT_ROUTED;
|
|
65
109
|
eligible?: string[];
|
|
66
110
|
decider?: Record<string, unknown>;
|
|
67
111
|
authorizes: false;
|
|
@@ -75,13 +119,34 @@ export interface ModelRoutingDeps {
|
|
|
75
119
|
modelOf?: (p: ProviderId) => string | null;
|
|
76
120
|
factoryDir?: string;
|
|
77
121
|
}
|
|
122
|
+
/** The labels a mission's model is chosen from, and who set each: the approver's field, else the request's, else the default. */
|
|
123
|
+
export declare function labelsOf(b: Record<string, unknown>, approver?: ApproverRouting): {
|
|
124
|
+
type: TaskType;
|
|
125
|
+
criticality: Criticality;
|
|
126
|
+
labels: {
|
|
127
|
+
task_type: LabelSource;
|
|
128
|
+
criticality: LabelSource;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
/** The floor a request states in model_floor, or null. */
|
|
132
|
+
export declare function floorOf(b: Record<string, unknown>): string | null;
|
|
133
|
+
/** Candidates below a floor stay listed, ineligible, with why: Jev is offered only what meets it, and reads no words. */
|
|
134
|
+
export declare function applyFloor(candidates: ModelCandidate[], floor: string | null): ModelCandidate[];
|
|
135
|
+
/** Why approving would launch nothing: no permitted model meets the request's floor, and the approver named none. Null when it can launch. */
|
|
136
|
+
export declare function floorRefusal(record: ConnectorRecord, approver: ApproverRouting | undefined, config: ClaudeModelConfig): string | null;
|
|
78
137
|
/**
|
|
79
138
|
* The model of one mission's launch, or null when this mission's model is not routed: another
|
|
80
139
|
* provider, or a request recorded before routing. Asked at most once for a version: a brief written
|
|
81
140
|
* again for it (a rerun) keeps the answer, because a lost answer may already have been charged.
|
|
141
|
+
*
|
|
142
|
+
* The approver's fields (jgwill/Miadi#1029) take part: a model they name launches as theirs and Jev
|
|
143
|
+
* is not asked; a task type or criticality they set replaces the request's in what Jev is sent.
|
|
144
|
+
* Their instructions are text and do not, and the receipt says so.
|
|
82
145
|
*/
|
|
83
146
|
export declare function routeModel(record: ConnectorRecord, opts: {
|
|
84
147
|
existingSession: boolean;
|
|
148
|
+
approver?: ApproverRouting;
|
|
149
|
+
instructions?: boolean;
|
|
85
150
|
}, deps?: ModelRoutingDeps): Promise<ModelRouting | null>;
|
|
86
151
|
/** What the brief carries. */
|
|
87
152
|
export declare function modelAttributes(routing: ModelRouting | null): Record<string, string>;
|