@foldrun/core 14.1.0 → 14.2.1

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.
@@ -0,0 +1,24 @@
1
+ /** foldrun's effort words, low to high (frontmatter-fields EFFORT_LEVELS). */
2
+ export declare const EFFORT_ORDER: readonly ["low", "medium", "high", "xhigh", "max"];
3
+ /**
4
+ * The reasoning-effort words each model takes on an OpenAI-shaped endpoint
5
+ * (Chat Completions' reasoning_effort, Responses' reasoning.effort), from
6
+ * the providers' own pages; the first match wins. A model not listed gets
7
+ * low | medium | high, which every reasoning model there has taken — a
8
+ * word it might not know is never sent on a guess. Add a row when a model
9
+ * documents more (or fewer).
10
+ */
11
+ export declare const MODEL_EFFORTS: readonly {
12
+ match: RegExp;
13
+ levels: readonly string[];
14
+ source: string;
15
+ }[];
16
+ /** The levels a model takes, by its id (a provider prefix ignored). */
17
+ export declare function effortsOf(model: string): readonly string[];
18
+ /**
19
+ * A foldrun effort word as this model takes it: the word itself when the
20
+ * model has it, else the nearest level below that it has (xhigh on a model
21
+ * that stops at high runs as high), else its lowest. Null for a word that
22
+ * is not one of ours.
23
+ */
24
+ export declare function fitEffort(model: string, word: string): string | null;
@@ -0,0 +1,52 @@
1
+ // Which reasoning-effort levels each model takes, and how a foldrun level
2
+ // runs on it. One table for the translator (what is sent), the gateway's
3
+ // reshaping and the checks (what a developer is told), so the warning and
4
+ // the wire never disagree. Pure: no network, no platform.
5
+ /** foldrun's effort words, low to high (frontmatter-fields EFFORT_LEVELS). */
6
+ export const EFFORT_ORDER = ["low", "medium", "high", "xhigh", "max"];
7
+ /**
8
+ * The reasoning-effort words each model takes on an OpenAI-shaped endpoint
9
+ * (Chat Completions' reasoning_effort, Responses' reasoning.effort), from
10
+ * the providers' own pages; the first match wins. A model not listed gets
11
+ * low | medium | high, which every reasoning model there has taken — a
12
+ * word it might not know is never sent on a guess. Add a row when a model
13
+ * documents more (or fewer).
14
+ */
15
+ export const MODEL_EFFORTS = [
16
+ {
17
+ // "reasoning.effort supports low, medium (default), high, xhigh, and max"
18
+ // (Luna also none, which no foldrun word asks for).
19
+ match: /^gpt-6(?:\.\d+)?-(?:astra|sol|luna)(?:$|-)/,
20
+ levels: ["low", "medium", "high", "xhigh", "max"],
21
+ source: "developers.openai.com/api/docs/models, 3 Nov 2026",
22
+ },
23
+ {
24
+ // reasoning_effort minimal | low | medium | high; thinking cannot be
25
+ // turned off on Gemini 3 and later.
26
+ match: /^gemini-/,
27
+ levels: ["low", "medium", "high"],
28
+ source: "ai.google.dev/gemini-api/docs/openai, 3 Nov 2026",
29
+ },
30
+ ];
31
+ const DEFAULT_EFFORTS = ["low", "medium", "high"];
32
+ /** The levels a model takes, by its id (a provider prefix ignored). */
33
+ export function effortsOf(model) {
34
+ const id = String(model).split("/").pop()?.toLowerCase() ?? "";
35
+ return MODEL_EFFORTS.find((m) => m.match.test(id))?.levels ?? DEFAULT_EFFORTS;
36
+ }
37
+ /**
38
+ * A foldrun effort word as this model takes it: the word itself when the
39
+ * model has it, else the nearest level below that it has (xhigh on a model
40
+ * that stops at high runs as high), else its lowest. Null for a word that
41
+ * is not one of ours.
42
+ */
43
+ export function fitEffort(model, word) {
44
+ const want = EFFORT_ORDER.indexOf(word);
45
+ if (want < 0)
46
+ return null;
47
+ const levels = effortsOf(model);
48
+ for (let i = want; i >= 0; i--)
49
+ if (levels.includes(EFFORT_ORDER[i]))
50
+ return EFFORT_ORDER[i];
51
+ return EFFORT_ORDER.find((l) => levels.includes(l)) ?? null;
52
+ }
@@ -35,6 +35,13 @@ export interface SendShape {
35
35
  thinking?: string[] | null;
36
36
  /** `output_config.effort`, as this provider spells it. */
37
37
  effort?: Record<string, string>;
38
+ /** A `system` message inside `messages` (Anthropic's mid-conversation
39
+ * instructions, which the SDK sends) folded into the user turn before
40
+ * it: the endpoint documents user and assistant roles only. */
41
+ mergeSystemMessages?: boolean;
42
+ /** Tools deferred for Anthropic's tool search (`defer_loading`; the SDK
43
+ * always sends a placeholder) dropped: the endpoint cannot load them. */
44
+ dropDeferredTools?: boolean;
38
45
  }
39
46
  export declare const SUPPLY_PROVIDERS: Record<SupplyProviderName, SupplyProvider>;
40
47
  export declare const SUPPLY_PROVIDER_NAMES: SupplyProviderName[];
@@ -76,3 +83,11 @@ export declare function supplyProviderBlock(provider: SupplyProviderName, tiers:
76
83
  * sent as the nearest one it does.
77
84
  */
78
85
  export declare function shapeRequest(p: SupplyProvider, json: Record<string, unknown>): boolean;
86
+ /**
87
+ * The effort a foldrun level actually runs at on one of foldrun's models:
88
+ * the provider's own aliases (DeepSeek), its reshaping (Kimi), the model's
89
+ * levels on an OpenAI-shaped endpoint (OpenAI, Gemini), or the level itself
90
+ * (Claude takes all five). Null for a word that is not one of ours. What a
91
+ * check tells a developer, from the same tables the wire uses.
92
+ */
93
+ export declare function effortRunsAs(provider: SupplyProviderName, model: string, word: string): string | null;
@@ -13,6 +13,7 @@
13
13
  // an operator in the console, sealed in the platform's store — never in the
14
14
  // environment), the operator lists it, and the price list names the model.
15
15
  import { providerPreset } from "./providers.js";
16
+ import { fitEffort, EFFORT_ORDER } from "./effort-fit.js";
16
17
  export const SUPPLY_PROVIDERS = {
17
18
  anthropic: {
18
19
  name: "anthropic",
@@ -64,7 +65,7 @@ export const SUPPLY_PROVIDERS = {
64
65
  // enabled|disabled|adaptive (adaptive = enabled), budget_tokens ignored;
65
66
  // effort takes every word ours does (medium and xhigh = high). Context
66
67
  // editing and thinking.display are not in its schema.
67
- send: { drop: ["context_management"], thinking: ["type", "budget_tokens"] },
68
+ send: { drop: ["context_management"], thinking: ["type", "budget_tokens"], mergeSystemMessages: true, dropDeferredTools: true },
68
69
  },
69
70
  moonshot: {
70
71
  name: "moonshot",
@@ -82,6 +83,8 @@ export const SUPPLY_PROVIDERS = {
82
83
  fields: ["model", "messages", "max_tokens", "system", "stream", "stop_sequences", "tools", "tool_choice", "metadata", "cache_control", "output_config"],
83
84
  thinking: null,
84
85
  effort: { minimal: "low", low: "low", medium: "high", high: "high", xhigh: "high", max: "max" },
86
+ mergeSystemMessages: true,
87
+ dropDeferredTools: true,
85
88
  },
86
89
  },
87
90
  };
@@ -158,6 +161,34 @@ export function shapeRequest(p, json) {
158
161
  (delete t[k], (changed = true));
159
162
  }
160
163
  }
164
+ if (shape.dropDeferredTools && Array.isArray(json.tools)) {
165
+ const kept = json.tools.filter((t) => !(t && typeof t === "object" && t.defer_loading === true));
166
+ if (kept.length !== json.tools.length) {
167
+ json.tools = kept;
168
+ changed = true;
169
+ }
170
+ }
171
+ if (shape.mergeSystemMessages && Array.isArray(json.messages)) {
172
+ const out = [];
173
+ const blocksOf = (c) => typeof c === "string" ? [{ type: "text", text: c }] : Array.isArray(c) ? c : [];
174
+ for (const m of json.messages) {
175
+ if (!m || m.role !== "system") {
176
+ out.push(m);
177
+ continue;
178
+ }
179
+ changed = true;
180
+ // Its words only: an effort-only system message carries none.
181
+ const text = blocksOf(m.content).filter((b) => b && b.type === "text" && typeof b.text === "string" && b.text).map((b) => ({ type: "text", text: b.text }));
182
+ if (!text.length)
183
+ continue;
184
+ const prev = out[out.length - 1];
185
+ if (prev && prev.role === "user")
186
+ prev.content = [...blocksOf(prev.content), ...text];
187
+ else
188
+ out.push({ role: "user", content: text });
189
+ }
190
+ json.messages = out;
191
+ }
161
192
  const oc = json.output_config;
162
193
  if (shape.effort && oc && typeof oc === "object" && typeof oc.effort === "string") {
163
194
  const word = oc.effort;
@@ -173,3 +204,25 @@ export function shapeRequest(p, json) {
173
204
  }
174
205
  return changed;
175
206
  }
207
+ /** DeepSeek takes every foldrun word but runs three levels (its docs:
208
+ * "medium and xhigh both map to high"). Said, not rewritten. */
209
+ const DEEPSEEK_RUNS = { low: "low", medium: "high", high: "high", xhigh: "high", max: "max" };
210
+ /**
211
+ * The effort a foldrun level actually runs at on one of foldrun's models:
212
+ * the provider's own aliases (DeepSeek), its reshaping (Kimi), the model's
213
+ * levels on an OpenAI-shaped endpoint (OpenAI, Gemini), or the level itself
214
+ * (Claude takes all five). Null for a word that is not one of ours. What a
215
+ * check tells a developer, from the same tables the wire uses.
216
+ */
217
+ export function effortRunsAs(provider, model, word) {
218
+ if (!EFFORT_ORDER.includes(word))
219
+ return null;
220
+ const p = SUPPLY_PROVIDERS[provider];
221
+ if (p.send?.effort)
222
+ return p.send.effort[word] ?? null;
223
+ if (provider === "deepseek")
224
+ return DEEPSEEK_RUNS[word] ?? null;
225
+ if (p.format === "anthropic")
226
+ return word;
227
+ return fitEffort(model, word);
228
+ }
@@ -225,6 +225,7 @@ export const PROVIDERS = [
225
225
  maxTokensParam: "max_completion_tokens", reasoningEffort: true, promptCacheKey: true,
226
226
  note: "Reached over the Responses API (3 Nov 2026): GPT-6 Astra and GPT-6.1 Sol call tools there alone, GPT-6 Luna on Chat Completions only with reasoning off. `format: openai` still says Chat Completions, for an older model or a proxy that speaks only that.", search: "openai" },
227
227
  { name: "gemini", title: "Google Gemini", format: "openai", baseUrl: "https://generativelanguage.googleapis.com/v1beta/openai", auth: "bearer",
228
+ reasoningEffort: true,
228
229
  note: "Google's OpenAI-compatible route. Unknown parameters are ignored silently; reasoning cannot be switched off on the newest models." },
229
230
  { name: "xai", title: "xAI Grok", format: "openai", baseUrl: "https://api.x.ai/v1", auth: "bearer",
230
231
  maxTokensParam: "max_completion_tokens", reasoningEffort: true },
@@ -3954,6 +3954,11 @@ const MAX_BACKOFF_MS = 30_000;
3954
3954
  export function isTransientOverload(text) {
3955
3955
  if (/credits?\b|quota|billing|insufficient|payment|401|402|403/i.test(text))
3956
3956
  return false;
3957
+ // The platform's own answer on foldrun's models (no price, the day's cap,
3958
+ // the provider withdrawn) is a decision, not load: a retry cannot change
3959
+ // it (e2e check, 3 Nov 2026 — a cap refusal retried for minutes).
3960
+ if (/foldrun's models/i.test(text))
3961
+ return false;
3957
3962
  return /\b(429|503|529)\b|overloaded|rate.?limit|too many requests|try again/i.test(text);
3958
3963
  }
3959
3964
  /**
@@ -40,6 +40,14 @@ export interface ScanOptions {
40
40
  /** The account AGENTS.md's `network:` — the level above the workspace's,
41
41
  * which the files of one workspace do not carry. */
42
42
  accountNetwork?: unknown;
43
+ /** What an effort level runs at on the model this account's steps run on
44
+ * (a `model:` word or id, an effort word), and where — or null when that
45
+ * is not known here (the CLI, offline: it knows no account's choice). */
46
+ effortRunsAs?: (model: string, effort: string) => {
47
+ effort: string;
48
+ model: string;
49
+ on: string;
50
+ } | null;
43
51
  }
44
52
  export declare const OWASP_URL = "https://genai.owasp.org/resource/owasp-top-10-for-agentic-applications-for-2026";
45
53
  export declare const SCAN_RULES: readonly ScanRule[];
@@ -96,11 +104,6 @@ export declare function nearestField(key: string, known: readonly string[]): str
96
104
  export declare const STRICT_FRONTMATTER_PATH: RegExp;
97
105
  /** How many times one rule is listed for one file before the rest are counted. */
98
106
  export declare const PER_FILE_RULE = 100;
99
- /**
100
- * Every finding in these files, ignores applied. Findings are sorted by file
101
- * then line, and one rule says one thing once per line, and at most
102
- * PER_FILE_RULE times in one file.
103
- */
104
107
  export declare function scanFiles(files: ScanFile[], options?: ScanOptions): ScanFinding[];
105
108
  /**
106
109
  * Drop the findings a `foldrun-ignore` comment (with a reason) covers — for
package/dist/src/scan.js CHANGED
@@ -32,7 +32,7 @@ import { resolveNetwork } from "./network.js";
32
32
  import { frontmatterProblems, schemaKindOf } from "./frontmatter-schema.js";
33
33
  import { parseRemotes } from "./a2a-remotes.js";
34
34
  import { isA2aPublished } from "./a2a-publish.js";
35
- import { parseFlow } from "./store.js";
35
+ import { parseFlow, resolveEffort } from "./store.js";
36
36
  export const OWASP_URL = "https://genai.owasp.org/resource/owasp-top-10-for-agentic-applications-for-2026";
37
37
  export const SCAN_RULES = [
38
38
  {
@@ -231,6 +231,15 @@ export const SCAN_RULES = [
231
231
  {
232
232
  // 30 Oct 2026: check and the scheduler read a schedule with the same
233
233
  // cronCanFire (core cron.ts), so check says what the scheduler does.
234
+ id: "config/effort-fitted",
235
+ category: "config",
236
+ level: "warn",
237
+ title: "An effort level the model this account runs on does not have",
238
+ help: "Each model takes its own effort levels: GPT-6 and Claude take all five, Gemini stops at high, Kimi has low, high and max. " +
239
+ "The step still runs, at the nearest level the model has, and the step's log says so. Write the level it has, or choose " +
240
+ "a provider whose model has the one you want (Settings → Model provider).",
241
+ },
242
+ {
234
243
  id: "config/cron-never-fires",
235
244
  category: "config",
236
245
  level: "warn",
@@ -875,6 +884,78 @@ export const PER_FILE_RULE = 100;
875
884
  * then line, and one rule says one thing once per line, and at most
876
885
  * PER_FILE_RULE times in one file.
877
886
  */
887
+ /**
888
+ * An `effort:` the model a step will run on does not have: warned, not
889
+ * refused — the step runs at the nearest level, and a file stays valid when
890
+ * the account changes provider. Agents' own effort, a flow's default and a
891
+ * step's override, each on the model it would run with.
892
+ */
893
+ function scanEfforts(agents, flows, runsAs, push) {
894
+ const say = (file, line, effort, model, whence) => {
895
+ const r = runsAs(model, effort);
896
+ if (!r || r.effort === effort)
897
+ return;
898
+ push("config/effort-fitted", file, line, `config/effort-fitted ${file} ${whence} ${effort} ${r.model}`, `effort: ${effort}${whence} runs as ${r.effort} on ${r.on} (${r.model}) — the nearest level that model has.`);
899
+ };
900
+ // Each agent: its own effort on its own model, as the runner reads them
901
+ // (resolveEffort: MAX, maximum, extra-high … are levels too).
902
+ const byName = new Map();
903
+ const ownProvider = new Set();
904
+ for (const a of agents) {
905
+ const model = typeof a.data.model === "string" && a.data.model.trim() ? a.data.model.trim() : "default";
906
+ const effort = resolveEffort(a.data.effort);
907
+ byName.set(a.name, { model, raw: a.data.effort });
908
+ // An agent with its own provider: runs there, not on the account's choice.
909
+ if (a.data.provider) {
910
+ ownProvider.add(a.name);
911
+ continue;
912
+ }
913
+ if (effort)
914
+ say(a.file, keyLine(a.lines, "effort"), effort, model, "");
915
+ }
916
+ // Each flow step: effort and model resolved step → flow → agent, the way
917
+ // runStep does, and said where the effort was written (Codex review).
918
+ for (const fl of flows) {
919
+ let info;
920
+ try {
921
+ info = parseFlow(fl.file, fl.content);
922
+ }
923
+ catch {
924
+ continue;
925
+ }
926
+ const steps = [...(info.steps ?? [])].sort((x, y) => (x.line ?? 0) - (y.line ?? 0));
927
+ const flowEffortLine = keyLine(fl.lines, "effort");
928
+ steps.forEach((st, i) => {
929
+ if (st.subflow || ownProvider.has(st.agent))
930
+ return;
931
+ const agent = byName.get(st.agent);
932
+ // The written value that wins, then read — runStep's order: a step's
933
+ // effort (even one that names no level) is the step's (Codex review).
934
+ const from = st.effort != null ? "step" : info.effort != null ? "flow" : "agent";
935
+ const effort = resolveEffort(from === "step" ? st.effort : from === "flow" ? info.effort : agent?.raw);
936
+ if (!effort)
937
+ return;
938
+ const model = st.model ?? info.model ?? agent?.model ?? "default";
939
+ if (from === "step") {
940
+ // The step's own `effort:` line, within this step's lines.
941
+ const from = st.line ?? 1;
942
+ const to = steps[i + 1]?.line ?? fl.lines.length + 1;
943
+ let at;
944
+ for (let n = from; n < to; n++)
945
+ if (/^\s+effort\s*:/.test(fl.lines[n - 1] ?? ""))
946
+ at = n;
947
+ say(fl.file, at ?? st.line, effort, model, ` (step ${st.agent})`);
948
+ }
949
+ else if (from === "flow") {
950
+ say(fl.file, flowEffortLine, effort, model, ` (the flow's, on step ${st.agent})`);
951
+ }
952
+ else if (st.model || info.model) {
953
+ // The agent's own effort, on a model this flow chose for it.
954
+ say(fl.file, st.line, effort, model, ` (${st.agent}'s own, on this step's model)`);
955
+ }
956
+ });
957
+ }
958
+ }
878
959
  export function scanFiles(files, options = {}) {
879
960
  const want = options.only?.length ? new Set(options.only) : null;
880
961
  const enabled = (rule) => !want || want.has(rule) || want.has(scanRule(rule)?.category ?? "") || rule === "check/ignore-needs-reason";
@@ -983,6 +1064,10 @@ export function scanFiles(files, options = {}) {
983
1064
  const workspaceMd = files.find((f) => f.path === "AGENTS.md") ?? files.find((f) => f.path === "project.md");
984
1065
  const legs = scanAgents(agents, outward, toolDefs, push, { account: options.accountNetwork, workspace: workspaceMd ? frontOf(workspaceMd.content, "AGENTS.md")?.network : undefined });
985
1066
  scanPublishedFlows(flows, legs, push);
1067
+ // A workspace that names its own provider: does not run on the account's
1068
+ // choice, so the account's models say nothing about its efforts.
1069
+ if (options.effortRunsAs && !(workspaceMd && frontOf(workspaceMd.content, "AGENTS.md")?.provider))
1070
+ scanEfforts(agents, flows, options.effortRunsAs, push);
986
1071
  for (const m of more.values()) {
987
1072
  findings.push({ rule: m.rule, level: m.level ?? scanRule(m.rule)?.level ?? "warn", file: m.file, message: `and ${m.n} more like this in this file, not listed`, fingerprint: m.hash.digest("hex").slice(0, 16), truncated: true });
988
1073
  }
@@ -69,27 +69,15 @@ interface Dropped {
69
69
  lines(): string[];
70
70
  }
71
71
  /**
72
- * The reasoning-effort words each model takes on an OpenAI-shaped endpoint
73
- * (Chat Completions' reasoning_effort, Responses' reasoning.effort), from
74
- * the providers' own pages; the first match wins. A model not listed gets
75
- * low | medium | high, which every reasoning model there has taken — a
76
- * word it might not know is never sent on a guess. Add a row when a model
77
- * documents more (or fewer).
72
+ * Whether a model is one OpenAI's own endpoint refuses a reasoning-effort
73
+ * parameter for ("Unsupported parameter: 'reasoning.effort'" on gpt-4o-mini).
74
+ * A gateway in front of it ignored the field, which is how the preset's
75
+ * reasoningEffort shipped untested against the origin. The families that do
76
+ * not reason are the ones named — anything else (o-series, gpt-5, grok,
77
+ * gemini, deepseek-r, qwen thinking) keeps getting the knob, because on a
78
+ * gateway the id alone cannot say and an ignored field costs nothing.
78
79
  */
79
- export declare const MODEL_EFFORTS: readonly {
80
- match: RegExp;
81
- levels: readonly string[];
82
- source: string;
83
- }[];
84
- /** The levels a model takes, by its id (a provider prefix ignored). */
85
- export declare function effortsOf(model: string): readonly string[];
86
- /**
87
- * A foldrun effort word as this model takes it: the word itself when the
88
- * model has it, else the nearest level below that it has (xhigh on a model
89
- * that stops at high runs as high), else its lowest. Null for a word that
90
- * is not one of ours.
91
- */
92
- export declare function fitEffort(model: string, word: string): string | null;
80
+ export { MODEL_EFFORTS, effortsOf, fitEffort } from "./effort-fit.ts";
93
81
  export declare function modelRejectsReasoning(model: string): boolean;
94
82
  /**
95
83
  * An Anthropic Messages request as a Chat Completions request. Pure.
@@ -227,4 +215,3 @@ export declare function translatorSpecFor(spec: {
227
215
  reasoningEffort?: boolean;
228
216
  cacheKey?: string;
229
217
  }): TranslatorSpec | null;
230
- export {};
@@ -91,54 +91,10 @@ function stableId(id) {
91
91
  * gemini, deepseek-r, qwen thinking) keeps getting the knob, because on a
92
92
  * gateway the id alone cannot say and an ignored field costs nothing.
93
93
  */
94
- /** foldrun's effort words, low to high (frontmatter-fields EFFORT_LEVELS). */
95
- const EFFORT_ORDER = ["low", "medium", "high", "xhigh", "max"];
96
- /**
97
- * The reasoning-effort words each model takes on an OpenAI-shaped endpoint
98
- * (Chat Completions' reasoning_effort, Responses' reasoning.effort), from
99
- * the providers' own pages; the first match wins. A model not listed gets
100
- * low | medium | high, which every reasoning model there has taken — a
101
- * word it might not know is never sent on a guess. Add a row when a model
102
- * documents more (or fewer).
103
- */
104
- export const MODEL_EFFORTS = [
105
- {
106
- // "reasoning.effort supports low, medium (default), high, xhigh, and max"
107
- // (Luna also none, which no foldrun word asks for).
108
- match: /^gpt-6(?:\.\d+)?-(?:astra|sol|luna)(?:$|-)/,
109
- levels: ["low", "medium", "high", "xhigh", "max"],
110
- source: "developers.openai.com/api/docs/models, 3 Nov 2026",
111
- },
112
- {
113
- // reasoning_effort minimal | low | medium | high; thinking cannot be
114
- // turned off on Gemini 3 and later.
115
- match: /^gemini-/,
116
- levels: ["low", "medium", "high"],
117
- source: "ai.google.dev/gemini-api/docs/openai, 3 Nov 2026",
118
- },
119
- ];
120
- const DEFAULT_EFFORTS = ["low", "medium", "high"];
121
- /** The levels a model takes, by its id (a provider prefix ignored). */
122
- export function effortsOf(model) {
123
- const id = String(model).split("/").pop()?.toLowerCase() ?? "";
124
- return MODEL_EFFORTS.find((m) => m.match.test(id))?.levels ?? DEFAULT_EFFORTS;
125
- }
126
- /**
127
- * A foldrun effort word as this model takes it: the word itself when the
128
- * model has it, else the nearest level below that it has (xhigh on a model
129
- * that stops at high runs as high), else its lowest. Null for a word that
130
- * is not one of ours.
131
- */
132
- export function fitEffort(model, word) {
133
- const want = EFFORT_ORDER.indexOf(word);
134
- if (want < 0)
135
- return null;
136
- const levels = effortsOf(model);
137
- for (let i = want; i >= 0; i--)
138
- if (levels.includes(EFFORT_ORDER[i]))
139
- return EFFORT_ORDER[i];
140
- return EFFORT_ORDER.find((l) => levels.includes(l)) ?? null;
141
- }
94
+ // The effort levels each model takes live in effort-fit.ts (the scanner
95
+ // reads them too); re-exported for callers that found them here.
96
+ export { MODEL_EFFORTS, effortsOf, fitEffort } from "./effort-fit.js";
97
+ import { fitEffort } from "./effort-fit.js";
142
98
  export function modelRejectsReasoning(model) {
143
99
  const id = String(model).split("/").pop()?.toLowerCase() ?? "";
144
100
  return /^(gpt-3|gpt-4|chatgpt|gpt-5-chat|davinci|babbage)/.test(id);
@@ -251,6 +207,10 @@ export function toChatCompletions(req, opts, drop = dropped()) {
251
207
  out.messages = messages;
252
208
  const tools = [];
253
209
  for (const t of (Array.isArray(req.tools) ? req.tools : [])) {
210
+ // A tool deferred for Anthropic's tool search (the SDK always sends a
211
+ // placeholder) is not a tool this endpoint can call.
212
+ if (t.defer_loading === true)
213
+ continue;
254
214
  if (t.type && t.type !== "custom") {
255
215
  drop.add(`server-side tool ${String(t.type)}`);
256
216
  continue;
@@ -425,6 +385,10 @@ export function toResponses(req, opts, drop = dropped()) {
425
385
  out.input = input;
426
386
  const tools = [];
427
387
  for (const t of (Array.isArray(req.tools) ? req.tools : [])) {
388
+ // A tool deferred for Anthropic's tool search (the SDK always sends a
389
+ // placeholder) is not a tool this endpoint can call.
390
+ if (t.defer_loading === true)
391
+ continue;
428
392
  if (t.type && t.type !== "custom") {
429
393
  drop.add(`server-side tool ${String(t.type)}`);
430
394
  continue;
@@ -1073,6 +1037,13 @@ export async function startTranslator(spec) {
1073
1037
  }
1074
1038
  // The status crosses unchanged, so a 401 or 429 from the provider
1075
1039
  // reads as one to the SDK — and to the fallback decision upstream.
1040
+ // A refusal that says not to retry (the platform's gateway does)
1041
+ // says so to the SDK too, or it retries a decision for minutes.
1042
+ const noRetry = upstream.headers.get("x-should-retry");
1043
+ if (noRetry) {
1044
+ res.writeHead(upstream.status, { "content-type": "application/json", "x-should-retry": noRetry });
1045
+ return void res.end(errorBody(upstream.status, message));
1046
+ }
1076
1047
  return send(upstream.status, errorBody(upstream.status, message));
1077
1048
  }
1078
1049
  const model = String(body.model ?? "");
@@ -6,6 +6,9 @@ import { accountDir, workspaceDir, workspaceTools } from "./store.js";
6
6
  import { readAgentsMdKeys } from "./agents-md.js";
7
7
  import { libraryTools } from "./library.js";
8
8
  import { checkFiles, readTree } from "./deploy.js";
9
+ import { platform } from "./platform.js";
10
+ import { SUPPLY_TITLES, effortRunsAs } from "./model-supply.js";
11
+ import { resolveTier, parseProvider } from "./store.js";
9
12
  /** What the checks read of a workspace, at most. Data (state/ and memory/,
10
13
  * what agents write) past these is left out and named; the rest past its
11
14
  * budget is not read at all (TreeTooLarge). On 20 Oct 2026 the daily
@@ -26,8 +29,40 @@ export function checkOptions(tenant, workspace) {
26
29
  const tools = { ...libraryTools(tenant), ...workspaceTools(tenant, workspace) };
27
30
  const outwardTools = Object.entries(tools).filter(([, d]) => d.outward === true).map(([n]) => n);
28
31
  // AGENTS.md, or the older project.md, as the runner reads it (Codex review).
29
- const accountNetwork = readAgentsMdKeys(accountDir(tenant)).network;
30
- return { outwardTools, accountNetwork };
32
+ const accountKeys = readAgentsMdKeys(accountDir(tenant));
33
+ const accountNetwork = accountKeys.network;
34
+ return { outwardTools, accountNetwork, ...effortCheck(tenant, accountKeys.provider) };
35
+ }
36
+ /**
37
+ * What an effort level runs at on the account's choice, for
38
+ * config/effort-fitted — when that choice is foldrun's models (a provider
39
+ * and its tiers the platform knows). An account AGENTS.md provider: block
40
+ * runs instead, and its own key's models are not the platform's to say.
41
+ */
42
+ function effortCheck(tenant, accountProvider) {
43
+ if (parseProvider(accountProvider)?.baseUrl)
44
+ return {};
45
+ let answer;
46
+ try {
47
+ answer = platform.modelSupply?.(tenant);
48
+ }
49
+ catch {
50
+ return {};
51
+ }
52
+ if (!answer || answer.kind !== "foldrun")
53
+ return {};
54
+ const { provider, tiers } = answer;
55
+ const on = `foldrun's models (${SUPPLY_TITLES[provider]})`;
56
+ return {
57
+ effortRunsAs: (model, effort) => {
58
+ const tier = resolveTier(model);
59
+ const id = tier ? tiers[tier] : model;
60
+ if (!id)
61
+ return null; // a Claude tier word: Claude takes every level
62
+ const runs = effortRunsAs(provider, id, effort);
63
+ return runs ? { effort: runs, model: id, on } : null;
64
+ },
65
+ };
31
66
  }
32
67
  export function checkWorkspace(tenant, workspace, tree = checkTree(workspaceDir(tenant, workspace))) {
33
68
  return checkFiles(tree, checkOptions(tenant, workspace));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldrun/core",
3
- "version": "14.1.0",
3
+ "version": "14.2.1",
4
4
  "description": "Agents are just folders. The format, the runner, the checks.",
5
5
  "license": "FSL-1.1-ALv2",
6
6
  "type": "module",
@@ -0,0 +1,54 @@
1
+ // Which reasoning-effort levels each model takes, and how a foldrun level
2
+ // runs on it. One table for the translator (what is sent), the gateway's
3
+ // reshaping and the checks (what a developer is told), so the warning and
4
+ // the wire never disagree. Pure: no network, no platform.
5
+
6
+ /** foldrun's effort words, low to high (frontmatter-fields EFFORT_LEVELS). */
7
+ export const EFFORT_ORDER = ["low", "medium", "high", "xhigh", "max"] as const;
8
+
9
+ /**
10
+ * The reasoning-effort words each model takes on an OpenAI-shaped endpoint
11
+ * (Chat Completions' reasoning_effort, Responses' reasoning.effort), from
12
+ * the providers' own pages; the first match wins. A model not listed gets
13
+ * low | medium | high, which every reasoning model there has taken — a
14
+ * word it might not know is never sent on a guess. Add a row when a model
15
+ * documents more (or fewer).
16
+ */
17
+ export const MODEL_EFFORTS: readonly { match: RegExp; levels: readonly string[]; source: string }[] = [
18
+ {
19
+ // "reasoning.effort supports low, medium (default), high, xhigh, and max"
20
+ // (Luna also none, which no foldrun word asks for).
21
+ match: /^gpt-6(?:\.\d+)?-(?:astra|sol|luna)(?:$|-)/,
22
+ levels: ["low", "medium", "high", "xhigh", "max"],
23
+ source: "developers.openai.com/api/docs/models, 3 Nov 2026",
24
+ },
25
+ {
26
+ // reasoning_effort minimal | low | medium | high; thinking cannot be
27
+ // turned off on Gemini 3 and later.
28
+ match: /^gemini-/,
29
+ levels: ["low", "medium", "high"],
30
+ source: "ai.google.dev/gemini-api/docs/openai, 3 Nov 2026",
31
+ },
32
+ ];
33
+ const DEFAULT_EFFORTS = ["low", "medium", "high"] as const;
34
+
35
+ /** The levels a model takes, by its id (a provider prefix ignored). */
36
+ export function effortsOf(model: string): readonly string[] {
37
+ const id = String(model).split("/").pop()?.toLowerCase() ?? "";
38
+ return MODEL_EFFORTS.find((m) => m.match.test(id))?.levels ?? DEFAULT_EFFORTS;
39
+ }
40
+
41
+ /**
42
+ * A foldrun effort word as this model takes it: the word itself when the
43
+ * model has it, else the nearest level below that it has (xhigh on a model
44
+ * that stops at high runs as high), else its lowest. Null for a word that
45
+ * is not one of ours.
46
+ */
47
+ export function fitEffort(model: string, word: string): string | null {
48
+ const want = (EFFORT_ORDER as readonly string[]).indexOf(word);
49
+ if (want < 0) return null;
50
+ const levels = effortsOf(model);
51
+ for (let i = want; i >= 0; i--) if (levels.includes(EFFORT_ORDER[i]!)) return EFFORT_ORDER[i]!;
52
+ return EFFORT_ORDER.find((l) => levels.includes(l)) ?? null;
53
+ }
54
+
@@ -14,6 +14,7 @@
14
14
  // environment), the operator lists it, and the price list names the model.
15
15
 
16
16
  import { providerPreset, type WireFormat } from "./providers.ts";
17
+ import { fitEffort, EFFORT_ORDER } from "./effort-fit.ts";
17
18
 
18
19
  export type SupplyProviderName = "anthropic" | "openai" | "gemini" | "deepseek" | "moonshot";
19
20
 
@@ -50,6 +51,13 @@ export interface SendShape {
50
51
  thinking?: string[] | null;
51
52
  /** `output_config.effort`, as this provider spells it. */
52
53
  effort?: Record<string, string>;
54
+ /** A `system` message inside `messages` (Anthropic's mid-conversation
55
+ * instructions, which the SDK sends) folded into the user turn before
56
+ * it: the endpoint documents user and assistant roles only. */
57
+ mergeSystemMessages?: boolean;
58
+ /** Tools deferred for Anthropic's tool search (`defer_loading`; the SDK
59
+ * always sends a placeholder) dropped: the endpoint cannot load them. */
60
+ dropDeferredTools?: boolean;
53
61
  }
54
62
 
55
63
  export const SUPPLY_PROVIDERS: Record<SupplyProviderName, SupplyProvider> = {
@@ -103,7 +111,7 @@ export const SUPPLY_PROVIDERS: Record<SupplyProviderName, SupplyProvider> = {
103
111
  // enabled|disabled|adaptive (adaptive = enabled), budget_tokens ignored;
104
112
  // effort takes every word ours does (medium and xhigh = high). Context
105
113
  // editing and thinking.display are not in its schema.
106
- send: { drop: ["context_management"], thinking: ["type", "budget_tokens"] },
114
+ send: { drop: ["context_management"], thinking: ["type", "budget_tokens"], mergeSystemMessages: true, dropDeferredTools: true },
107
115
  },
108
116
  moonshot: {
109
117
  name: "moonshot",
@@ -121,6 +129,8 @@ export const SUPPLY_PROVIDERS: Record<SupplyProviderName, SupplyProvider> = {
121
129
  fields: ["model", "messages", "max_tokens", "system", "stream", "stop_sequences", "tools", "tool_choice", "metadata", "cache_control", "output_config"],
122
130
  thinking: null,
123
131
  effort: { minimal: "low", low: "low", medium: "high", high: "high", xhigh: "high", max: "max" },
132
+ mergeSystemMessages: true,
133
+ dropDeferredTools: true,
124
134
  },
125
135
  },
126
136
  };
@@ -209,6 +219,32 @@ export function shapeRequest(p: SupplyProvider, json: Record<string, unknown>):
209
219
  for (const k of Object.keys(t)) if (!shape.thinking.includes(k)) (delete t[k], (changed = true));
210
220
  }
211
221
  }
222
+ if (shape.dropDeferredTools && Array.isArray(json.tools)) {
223
+ const kept = (json.tools as unknown[]).filter((t) => !(t && typeof t === "object" && (t as Record<string, unknown>).defer_loading === true));
224
+ if (kept.length !== json.tools.length) {
225
+ json.tools = kept;
226
+ changed = true;
227
+ }
228
+ }
229
+ if (shape.mergeSystemMessages && Array.isArray(json.messages)) {
230
+ const out: Record<string, unknown>[] = [];
231
+ const blocksOf = (c: unknown): Record<string, unknown>[] =>
232
+ typeof c === "string" ? [{ type: "text", text: c }] : Array.isArray(c) ? (c as Record<string, unknown>[]) : [];
233
+ for (const m of json.messages as Record<string, unknown>[]) {
234
+ if (!m || m.role !== "system") {
235
+ out.push(m);
236
+ continue;
237
+ }
238
+ changed = true;
239
+ // Its words only: an effort-only system message carries none.
240
+ const text = blocksOf(m.content).filter((b) => b && b.type === "text" && typeof b.text === "string" && b.text).map((b) => ({ type: "text", text: b.text }));
241
+ if (!text.length) continue;
242
+ const prev = out[out.length - 1];
243
+ if (prev && prev.role === "user") prev.content = [...blocksOf(prev.content), ...text];
244
+ else out.push({ role: "user", content: text });
245
+ }
246
+ json.messages = out;
247
+ }
212
248
  const oc = json.output_config;
213
249
  if (shape.effort && oc && typeof oc === "object" && typeof (oc as Record<string, unknown>).effort === "string") {
214
250
  const word = (oc as Record<string, unknown>).effort as string;
@@ -223,3 +259,23 @@ export function shapeRequest(p: SupplyProvider, json: Record<string, unknown>):
223
259
  }
224
260
  return changed;
225
261
  }
262
+
263
+ /** DeepSeek takes every foldrun word but runs three levels (its docs:
264
+ * "medium and xhigh both map to high"). Said, not rewritten. */
265
+ const DEEPSEEK_RUNS: Record<string, string> = { low: "low", medium: "high", high: "high", xhigh: "high", max: "max" };
266
+
267
+ /**
268
+ * The effort a foldrun level actually runs at on one of foldrun's models:
269
+ * the provider's own aliases (DeepSeek), its reshaping (Kimi), the model's
270
+ * levels on an OpenAI-shaped endpoint (OpenAI, Gemini), or the level itself
271
+ * (Claude takes all five). Null for a word that is not one of ours. What a
272
+ * check tells a developer, from the same tables the wire uses.
273
+ */
274
+ export function effortRunsAs(provider: SupplyProviderName, model: string, word: string): string | null {
275
+ if (!(EFFORT_ORDER as readonly string[]).includes(word)) return null;
276
+ const p = SUPPLY_PROVIDERS[provider];
277
+ if (p.send?.effort) return p.send.effort[word] ?? null;
278
+ if (provider === "deepseek") return DEEPSEEK_RUNS[word] ?? null;
279
+ if (p.format === "anthropic") return word;
280
+ return fitEffort(model, word);
281
+ }
package/src/providers.ts CHANGED
@@ -440,6 +440,7 @@ export const PROVIDERS: readonly ProviderPreset[] = [
440
440
  maxTokensParam: "max_completion_tokens", reasoningEffort: true, promptCacheKey: true,
441
441
  note: "Reached over the Responses API (3 Nov 2026): GPT-6 Astra and GPT-6.1 Sol call tools there alone, GPT-6 Luna on Chat Completions only with reasoning off. `format: openai` still says Chat Completions, for an older model or a proxy that speaks only that." , search: "openai" },
442
442
  { name: "gemini", title: "Google Gemini", format: "openai", baseUrl: "https://generativelanguage.googleapis.com/v1beta/openai", auth: "bearer",
443
+ reasoningEffort: true,
443
444
  note: "Google's OpenAI-compatible route. Unknown parameters are ignored silently; reasoning cannot be switched off on the newest models." },
444
445
  { name: "xai", title: "xAI Grok", format: "openai", baseUrl: "https://api.x.ai/v1", auth: "bearer",
445
446
  maxTokensParam: "max_completion_tokens", reasoningEffort: true },
package/src/runner.ts CHANGED
@@ -4168,6 +4168,10 @@ const MAX_BACKOFF_MS = 30_000;
4168
4168
  */
4169
4169
  export function isTransientOverload(text: string): boolean {
4170
4170
  if (/credits?\b|quota|billing|insufficient|payment|401|402|403/i.test(text)) return false;
4171
+ // The platform's own answer on foldrun's models (no price, the day's cap,
4172
+ // the provider withdrawn) is a decision, not load: a retry cannot change
4173
+ // it (e2e check, 3 Nov 2026 — a cap refusal retried for minutes).
4174
+ if (/foldrun's models/i.test(text)) return false;
4171
4175
  return /\b(429|503|529)\b|overloaded|rate.?limit|too many requests|try again/i.test(text);
4172
4176
  }
4173
4177
 
package/src/scan.ts CHANGED
@@ -33,7 +33,7 @@ import { resolveNetwork } from "./network.ts";
33
33
  import { frontmatterProblems, schemaKindOf } from "./frontmatter-schema.ts";
34
34
  import { parseRemotes } from "./a2a-remotes.ts";
35
35
  import { isA2aPublished } from "./a2a-publish.ts";
36
- import { parseFlow, type FlowStep } from "./store.ts";
36
+ import { parseFlow, resolveEffort, type FlowStep } from "./store.ts";
37
37
 
38
38
  export type ScanLevel = "error" | "warn" | "info";
39
39
  export type ScanCategory = "secret" | "security" | "content" | "supply-chain" | "config";
@@ -81,6 +81,10 @@ export interface ScanOptions {
81
81
  /** The account AGENTS.md's `network:` — the level above the workspace's,
82
82
  * which the files of one workspace do not carry. */
83
83
  accountNetwork?: unknown;
84
+ /** What an effort level runs at on the model this account's steps run on
85
+ * (a `model:` word or id, an effort word), and where — or null when that
86
+ * is not known here (the CLI, offline: it knows no account's choice). */
87
+ effortRunsAs?: (model: string, effort: string) => { effort: string; model: string; on: string } | null;
84
88
  }
85
89
 
86
90
  export const OWASP_URL = "https://genai.owasp.org/resource/owasp-top-10-for-agentic-applications-for-2026";
@@ -301,6 +305,16 @@ export const SCAN_RULES: readonly ScanRule[] = [
301
305
  {
302
306
  // 30 Oct 2026: check and the scheduler read a schedule with the same
303
307
  // cronCanFire (core cron.ts), so check says what the scheduler does.
308
+ id: "config/effort-fitted",
309
+ category: "config",
310
+ level: "warn",
311
+ title: "An effort level the model this account runs on does not have",
312
+ help:
313
+ "Each model takes its own effort levels: GPT-6 and Claude take all five, Gemini stops at high, Kimi has low, high and max. " +
314
+ "The step still runs, at the nearest level the model has, and the step's log says so. Write the level it has, or choose " +
315
+ "a provider whose model has the one you want (Settings → Model provider).",
316
+ },
317
+ {
304
318
  id: "config/cron-never-fires",
305
319
  category: "config",
306
320
  level: "warn",
@@ -995,6 +1009,76 @@ export const PER_FILE_RULE = 100;
995
1009
  * then line, and one rule says one thing once per line, and at most
996
1010
  * PER_FILE_RULE times in one file.
997
1011
  */
1012
+ /**
1013
+ * An `effort:` the model a step will run on does not have: warned, not
1014
+ * refused — the step runs at the nearest level, and a file stays valid when
1015
+ * the account changes provider. Agents' own effort, a flow's default and a
1016
+ * step's override, each on the model it would run with.
1017
+ */
1018
+ function scanEfforts(agents: AgentFacts[], flows: FlowFacts[], runsAs: NonNullable<ScanOptions["effortRunsAs"]>, push: Push): void {
1019
+ const say = (file: string, line: number | undefined, effort: string, model: string, whence: string) => {
1020
+ const r = runsAs(model, effort);
1021
+ if (!r || r.effort === effort) return;
1022
+ push(
1023
+ "config/effort-fitted",
1024
+ file,
1025
+ line,
1026
+ `config/effort-fitted ${file} ${whence} ${effort} ${r.model}`,
1027
+ `effort: ${effort}${whence} runs as ${r.effort} on ${r.on} (${r.model}) — the nearest level that model has.`,
1028
+ );
1029
+ };
1030
+ // Each agent: its own effort on its own model, as the runner reads them
1031
+ // (resolveEffort: MAX, maximum, extra-high … are levels too).
1032
+ const byName = new Map<string, { model: string; raw: unknown }>();
1033
+ const ownProvider = new Set<string>();
1034
+ for (const a of agents) {
1035
+ const model = typeof a.data.model === "string" && a.data.model.trim() ? a.data.model.trim() : "default";
1036
+ const effort = resolveEffort(a.data.effort);
1037
+ byName.set(a.name, { model, raw: a.data.effort });
1038
+ // An agent with its own provider: runs there, not on the account's choice.
1039
+ if (a.data.provider) {
1040
+ ownProvider.add(a.name);
1041
+ continue;
1042
+ }
1043
+ if (effort) say(a.file, keyLine(a.lines, "effort"), effort, model, "");
1044
+ }
1045
+ // Each flow step: effort and model resolved step → flow → agent, the way
1046
+ // runStep does, and said where the effort was written (Codex review).
1047
+ for (const fl of flows) {
1048
+ let info: ReturnType<typeof parseFlow>;
1049
+ try {
1050
+ info = parseFlow(fl.file, fl.content);
1051
+ } catch {
1052
+ continue;
1053
+ }
1054
+ const steps = [...(info.steps ?? [])].sort((x, y) => (x.line ?? 0) - (y.line ?? 0));
1055
+ const flowEffortLine = keyLine(fl.lines, "effort");
1056
+ steps.forEach((st, i) => {
1057
+ if (st.subflow || ownProvider.has(st.agent)) return;
1058
+ const agent = byName.get(st.agent);
1059
+ // The written value that wins, then read — runStep's order: a step's
1060
+ // effort (even one that names no level) is the step's (Codex review).
1061
+ const from = st.effort != null ? "step" : info.effort != null ? "flow" : "agent";
1062
+ const effort = resolveEffort(from === "step" ? st.effort : from === "flow" ? info.effort : agent?.raw);
1063
+ if (!effort) return;
1064
+ const model = st.model ?? info.model ?? agent?.model ?? "default";
1065
+ if (from === "step") {
1066
+ // The step's own `effort:` line, within this step's lines.
1067
+ const from = st.line ?? 1;
1068
+ const to = steps[i + 1]?.line ?? fl.lines.length + 1;
1069
+ let at: number | undefined;
1070
+ for (let n = from; n < to; n++) if (/^\s+effort\s*:/.test(fl.lines[n - 1] ?? "")) at = n;
1071
+ say(fl.file, at ?? st.line, effort, model, ` (step ${st.agent})`);
1072
+ } else if (from === "flow") {
1073
+ say(fl.file, flowEffortLine, effort, model, ` (the flow's, on step ${st.agent})`);
1074
+ } else if (st.model || info.model) {
1075
+ // The agent's own effort, on a model this flow chose for it.
1076
+ say(fl.file, st.line, effort, model, ` (${st.agent}'s own, on this step's model)`);
1077
+ }
1078
+ });
1079
+ }
1080
+ }
1081
+
998
1082
  export function scanFiles(files: ScanFile[], options: ScanOptions = {}): ScanFinding[] {
999
1083
  const want = options.only?.length ? new Set(options.only) : null;
1000
1084
  const enabled = (rule: string) => !want || want.has(rule) || want.has(scanRule(rule)?.category ?? "") || rule === "check/ignore-needs-reason";
@@ -1096,6 +1180,9 @@ export function scanFiles(files: ScanFile[], options: ScanOptions = {}): ScanFin
1096
1180
  const workspaceMd = files.find((f) => f.path === "AGENTS.md") ?? files.find((f) => f.path === "project.md");
1097
1181
  const legs = scanAgents(agents, outward, toolDefs, push, { account: options.accountNetwork, workspace: workspaceMd ? frontOf(workspaceMd.content, "AGENTS.md")?.network : undefined });
1098
1182
  scanPublishedFlows(flows, legs, push);
1183
+ // A workspace that names its own provider: does not run on the account's
1184
+ // choice, so the account's models say nothing about its efforts.
1185
+ if (options.effortRunsAs && !(workspaceMd && frontOf(workspaceMd.content, "AGENTS.md")?.provider)) scanEfforts(agents, flows, options.effortRunsAs, push);
1099
1186
  for (const m of more.values()) {
1100
1187
  findings.push({ rule: m.rule, level: m.level ?? scanRule(m.rule)?.level ?? "warn", file: m.file, message: `and ${m.n} more like this in this file, not listed`, fingerprint: m.hash.digest("hex").slice(0, 16), truncated: true });
1101
1188
  }
package/src/translator.ts CHANGED
@@ -163,54 +163,10 @@ function stableId(id: string): string {
163
163
  * gemini, deepseek-r, qwen thinking) keeps getting the knob, because on a
164
164
  * gateway the id alone cannot say and an ignored field costs nothing.
165
165
  */
166
- /** foldrun's effort words, low to high (frontmatter-fields EFFORT_LEVELS). */
167
- const EFFORT_ORDER = ["low", "medium", "high", "xhigh", "max"] as const;
168
-
169
- /**
170
- * The reasoning-effort words each model takes on an OpenAI-shaped endpoint
171
- * (Chat Completions' reasoning_effort, Responses' reasoning.effort), from
172
- * the providers' own pages; the first match wins. A model not listed gets
173
- * low | medium | high, which every reasoning model there has taken — a
174
- * word it might not know is never sent on a guess. Add a row when a model
175
- * documents more (or fewer).
176
- */
177
- export const MODEL_EFFORTS: readonly { match: RegExp; levels: readonly string[]; source: string }[] = [
178
- {
179
- // "reasoning.effort supports low, medium (default), high, xhigh, and max"
180
- // (Luna also none, which no foldrun word asks for).
181
- match: /^gpt-6(?:\.\d+)?-(?:astra|sol|luna)(?:$|-)/,
182
- levels: ["low", "medium", "high", "xhigh", "max"],
183
- source: "developers.openai.com/api/docs/models, 3 Nov 2026",
184
- },
185
- {
186
- // reasoning_effort minimal | low | medium | high; thinking cannot be
187
- // turned off on Gemini 3 and later.
188
- match: /^gemini-/,
189
- levels: ["low", "medium", "high"],
190
- source: "ai.google.dev/gemini-api/docs/openai, 3 Nov 2026",
191
- },
192
- ];
193
- const DEFAULT_EFFORTS = ["low", "medium", "high"] as const;
194
-
195
- /** The levels a model takes, by its id (a provider prefix ignored). */
196
- export function effortsOf(model: string): readonly string[] {
197
- const id = String(model).split("/").pop()?.toLowerCase() ?? "";
198
- return MODEL_EFFORTS.find((m) => m.match.test(id))?.levels ?? DEFAULT_EFFORTS;
199
- }
200
-
201
- /**
202
- * A foldrun effort word as this model takes it: the word itself when the
203
- * model has it, else the nearest level below that it has (xhigh on a model
204
- * that stops at high runs as high), else its lowest. Null for a word that
205
- * is not one of ours.
206
- */
207
- export function fitEffort(model: string, word: string): string | null {
208
- const want = (EFFORT_ORDER as readonly string[]).indexOf(word);
209
- if (want < 0) return null;
210
- const levels = effortsOf(model);
211
- for (let i = want; i >= 0; i--) if (levels.includes(EFFORT_ORDER[i]!)) return EFFORT_ORDER[i]!;
212
- return EFFORT_ORDER.find((l) => levels.includes(l)) ?? null;
213
- }
166
+ // The effort levels each model takes live in effort-fit.ts (the scanner
167
+ // reads them too); re-exported for callers that found them here.
168
+ export { MODEL_EFFORTS, effortsOf, fitEffort } from "./effort-fit.ts";
169
+ import { fitEffort } from "./effort-fit.ts";
214
170
 
215
171
  export function modelRejectsReasoning(model: string): boolean {
216
172
  const id = String(model).split("/").pop()?.toLowerCase() ?? "";
@@ -328,6 +284,9 @@ export function toChatCompletions(
328
284
 
329
285
  const tools: Json[] = [];
330
286
  for (const t of (Array.isArray(req.tools) ? req.tools : []) as Json[]) {
287
+ // A tool deferred for Anthropic's tool search (the SDK always sends a
288
+ // placeholder) is not a tool this endpoint can call.
289
+ if (t.defer_loading === true) continue;
331
290
  if (t.type && t.type !== "custom") {
332
291
  drop.add(`server-side tool ${String(t.type)}`);
333
292
  continue;
@@ -485,6 +444,9 @@ export function toResponses(
485
444
 
486
445
  const tools: Json[] = [];
487
446
  for (const t of (Array.isArray(req.tools) ? req.tools : []) as Json[]) {
447
+ // A tool deferred for Anthropic's tool search (the SDK always sends a
448
+ // placeholder) is not a tool this endpoint can call.
449
+ if (t.defer_loading === true) continue;
488
450
  if (t.type && t.type !== "custom") {
489
451
  drop.add(`server-side tool ${String(t.type)}`);
490
452
  continue;
@@ -1133,6 +1095,13 @@ export async function startTranslator(spec: TranslatorSpec): Promise<RunningTran
1133
1095
  }
1134
1096
  // The status crosses unchanged, so a 401 or 429 from the provider
1135
1097
  // reads as one to the SDK — and to the fallback decision upstream.
1098
+ // A refusal that says not to retry (the platform's gateway does)
1099
+ // says so to the SDK too, or it retries a decision for minutes.
1100
+ const noRetry = upstream.headers.get("x-should-retry");
1101
+ if (noRetry) {
1102
+ res.writeHead(upstream.status, { "content-type": "application/json", "x-should-retry": noRetry });
1103
+ return void res.end(errorBody(upstream.status, message));
1104
+ }
1136
1105
  return send(upstream.status, errorBody(upstream.status, message));
1137
1106
  }
1138
1107
 
@@ -9,6 +9,9 @@ import { libraryTools } from "./library.ts";
9
9
  import { checkFiles, readTree } from "./deploy.ts";
10
10
  import type { DeployFile } from "./store.ts";
11
11
  import type { ScanFinding, ScanOptions } from "./scan.ts";
12
+ import { platform } from "./platform.ts";
13
+ import { SUPPLY_TITLES, effortRunsAs } from "./model-supply.ts";
14
+ import { resolveTier, parseProvider } from "./store.ts";
12
15
 
13
16
  /** What the checks read of a workspace, at most. Data (state/ and memory/,
14
17
  * what agents write) past these is left out and named; the rest past its
@@ -32,8 +35,37 @@ export function checkOptions(tenant: string, workspace: string): ScanOptions {
32
35
  const tools = { ...libraryTools(tenant), ...workspaceTools(tenant, workspace) };
33
36
  const outwardTools = Object.entries(tools).filter(([, d]) => (d as OutwardMark).outward === true).map(([n]) => n);
34
37
  // AGENTS.md, or the older project.md, as the runner reads it (Codex review).
35
- const accountNetwork = readAgentsMdKeys(accountDir(tenant)).network;
36
- return { outwardTools, accountNetwork };
38
+ const accountKeys = readAgentsMdKeys(accountDir(tenant));
39
+ const accountNetwork = accountKeys.network;
40
+ return { outwardTools, accountNetwork, ...effortCheck(tenant, accountKeys.provider) };
41
+ }
42
+
43
+ /**
44
+ * What an effort level runs at on the account's choice, for
45
+ * config/effort-fitted — when that choice is foldrun's models (a provider
46
+ * and its tiers the platform knows). An account AGENTS.md provider: block
47
+ * runs instead, and its own key's models are not the platform's to say.
48
+ */
49
+ function effortCheck(tenant: string, accountProvider: unknown): Pick<ScanOptions, "effortRunsAs"> {
50
+ if (parseProvider(accountProvider)?.baseUrl) return {};
51
+ let answer: ReturnType<NonNullable<typeof platform.modelSupply>> | undefined;
52
+ try {
53
+ answer = platform.modelSupply?.(tenant);
54
+ } catch {
55
+ return {};
56
+ }
57
+ if (!answer || answer.kind !== "foldrun") return {};
58
+ const { provider, tiers } = answer;
59
+ const on = `foldrun's models (${SUPPLY_TITLES[provider]})`;
60
+ return {
61
+ effortRunsAs: (model, effort) => {
62
+ const tier = resolveTier(model);
63
+ const id = tier ? tiers[tier as "fast" | "default" | "max"] : model;
64
+ if (!id) return null; // a Claude tier word: Claude takes every level
65
+ const runs = effortRunsAs(provider, id, effort);
66
+ return runs ? { effort: runs, model: id, on } : null;
67
+ },
68
+ };
37
69
  }
38
70
 
39
71
  export function checkWorkspace(tenant: string, workspace: string, tree: DeployFile[] = checkTree(workspaceDir(tenant, workspace))): ScanFinding[] {