codex-sift 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/jev.js ADDED
@@ -0,0 +1,156 @@
1
+ import { redact } from "./redact.js";
2
+ import { applyPolicy, fallbackSignals } from "./policy.js";
3
+ const QUESTIONS = {
4
+ task_kind: {
5
+ type: "choice",
6
+ instructions: "What kind of coding-agent turn is this user request?",
7
+ criteria: {
8
+ ask: "Explain, search, or answer without editing code",
9
+ edit: "Localized code change in known files",
10
+ debug: "Find and fix a failure with evidence",
11
+ refactor: "Restructure existing code with similar behavior",
12
+ architecture: "Cross-cutting design or a new subsystem",
13
+ review: "Read-only review of a diff or change",
14
+ ops: "Git, install, CI, or environment plumbing",
15
+ },
16
+ },
17
+ difficulty: {
18
+ type: "score",
19
+ instructions: "How hard is this for a coding agent?",
20
+ criteria: [
21
+ "Trivial: rename, one-liner, or lookup",
22
+ "Localized: one file or a small known pattern",
23
+ "Multi-file: several modules, some ambiguity",
24
+ "Hard or novel: unclear cause, deep reasoning, high blast radius",
25
+ ],
26
+ },
27
+ needs_reasoning: {
28
+ type: "noul",
29
+ instructions: "Requires multi-step diagnosis or non-obvious design",
30
+ },
31
+ needs_planning: {
32
+ type: "noul",
33
+ instructions: "Should plan before editing",
34
+ },
35
+ high_stakes: {
36
+ type: "noul",
37
+ instructions: "Touches auth, payments, production, migrations, or secrets",
38
+ },
39
+ cross_cutting: {
40
+ type: "noul",
41
+ instructions: "Will span many files or shared contracts",
42
+ },
43
+ is_chitchat: {
44
+ type: "noul",
45
+ instructions: "This is a greeting, thanks, or small talk with no coding task",
46
+ },
47
+ };
48
+ export class JevUnavailable extends Error {
49
+ constructor(message) {
50
+ super(message);
51
+ this.name = "JevUnavailable";
52
+ }
53
+ }
54
+ function typesafeBase() {
55
+ return (process.env.TYPESAFE_BASE_URL || "https://api.typesafe.ai").replace(/\/$/, "");
56
+ }
57
+ function readNoul(answer) {
58
+ if (!answer)
59
+ return 0;
60
+ if (typeof answer.noul === "number")
61
+ return answer.noul;
62
+ return 0;
63
+ }
64
+ export function answersToSignals(answers, hasImage) {
65
+ const kind = answers.task_kind || {};
66
+ const difficulty = answers.difficulty || {};
67
+ const kindConf = typeof kind.confidence === "number" ? kind.confidence : 1;
68
+ const diffConf = typeof difficulty.confidence === "number" ? difficulty.confidence : 0;
69
+ const confidences = [kindConf];
70
+ if (diffConf > 0)
71
+ confidences.push(diffConf);
72
+ return {
73
+ task_kind: kind.choice || "edit",
74
+ task_kind_confidence: kindConf,
75
+ difficulty: typeof difficulty.score === "number" ? difficulty.score : 1,
76
+ difficulty_confidence: diffConf,
77
+ needs_reasoning: readNoul(answers.needs_reasoning),
78
+ needs_planning: readNoul(answers.needs_planning),
79
+ high_stakes: readNoul(answers.high_stakes),
80
+ cross_cutting: readNoul(answers.cross_cutting),
81
+ is_chitchat: readNoul(answers.is_chitchat),
82
+ confidence: Math.min(...confidences),
83
+ has_image: hasImage,
84
+ };
85
+ }
86
+ export async function callJev(state, policy) {
87
+ const apiKey = process.env.TYPESAFE_API_KEY;
88
+ if (!apiKey)
89
+ throw new JevUnavailable("TYPESAFE_API_KEY is not set");
90
+ const controller = new AbortController();
91
+ const timer = setTimeout(() => controller.abort(), policy.jev_timeout_ms);
92
+ try {
93
+ const res = await fetch(`${typesafeBase()}/v1/systemone`, {
94
+ method: "POST",
95
+ headers: {
96
+ authorization: `Bearer ${apiKey}`,
97
+ "content-type": "application/json",
98
+ },
99
+ body: JSON.stringify({
100
+ model: policy.jev_model,
101
+ state,
102
+ questions: QUESTIONS,
103
+ }),
104
+ signal: controller.signal,
105
+ });
106
+ if (!res.ok) {
107
+ const text = await res.text().catch(() => "");
108
+ throw new JevUnavailable(`Jev HTTP ${res.status} ${text.slice(0, 180)}`);
109
+ }
110
+ return (await res.json());
111
+ }
112
+ catch (err) {
113
+ if (err instanceof JevUnavailable)
114
+ throw err;
115
+ const message = err instanceof Error ? err.message : String(err);
116
+ throw new JevUnavailable(message);
117
+ }
118
+ finally {
119
+ clearTimeout(timer);
120
+ }
121
+ }
122
+ export async function decideTurn(policy, prompt, extras = {}) {
123
+ const redacted = redact(prompt);
124
+ const hasImage = extras.hasImage ?? false;
125
+ const started = Date.now();
126
+ try {
127
+ const response = await callJev({
128
+ task: redacted,
129
+ has_image: hasImage,
130
+ retry: Boolean(extras.retry),
131
+ previous_lane: extras.previousLane ?? null,
132
+ }, policy);
133
+ const signals = answersToSignals(response.answers || {}, hasImage);
134
+ return applyPolicy(policy, signals, {
135
+ jev_ms: Date.now() - started,
136
+ prompt_chars: redacted.length,
137
+ });
138
+ }
139
+ catch {
140
+ const signals = fallbackSignals(redacted, hasImage);
141
+ const decision = applyPolicy(policy, signals, {
142
+ jev_ms: Date.now() - started,
143
+ prompt_chars: redacted.length,
144
+ degraded: true,
145
+ });
146
+ const fallback = policy.lanes[policy.on_jev_down];
147
+ if (fallback) {
148
+ decision.lane = policy.on_jev_down;
149
+ decision.model = fallback.model;
150
+ decision.effort = fallback.effort;
151
+ }
152
+ decision.reason = ["Jev unavailable, using fallback lane", ...decision.reason];
153
+ decision.degraded = true;
154
+ return decision;
155
+ }
156
+ }
@@ -0,0 +1,4 @@
1
+ import type { Policy } from "./types.js";
2
+ export declare function resolveCodexBin(): string;
3
+ export declare function shouldProxy(argv: string[]): boolean;
4
+ export declare function launchCodex(argv: string[], policy?: Policy): Promise<number>;
package/dist/launch.js ADDED
@@ -0,0 +1,155 @@
1
+ import { spawn, spawnSync } from "node:child_process";
2
+ import { existsSync, mkdirSync, copyFileSync } from "node:fs";
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { ensureInjectedCatalog } from "./catalog.js";
6
+ import { loadLocalEnv } from "./env.js";
7
+ import { loadPolicy, siftHome } from "./policy.js";
8
+ import { startProxy } from "./proxy.js";
9
+ const NO_PROXY = new Set([
10
+ "login",
11
+ "logout",
12
+ "mcp",
13
+ "plugin",
14
+ "app",
15
+ "completion",
16
+ "update",
17
+ "features",
18
+ "sandbox",
19
+ "debug",
20
+ "help",
21
+ ]);
22
+ const here = dirname(fileURLToPath(import.meta.url));
23
+ export function resolveCodexBin() {
24
+ if (process.env.CODEX_BIN)
25
+ return process.env.CODEX_BIN;
26
+ const which = spawnSync("which", ["-a", "codex"], { encoding: "utf8" });
27
+ const candidates = (which.stdout || "")
28
+ .split("\n")
29
+ .map((s) => s.trim())
30
+ .filter(Boolean);
31
+ for (const bin of candidates) {
32
+ if (!isSelf(bin))
33
+ return bin;
34
+ }
35
+ return "codex";
36
+ }
37
+ function isSelf(bin) {
38
+ const lower = bin.toLowerCase();
39
+ return lower.includes("codex-sift") || lower.endsWith("/sift");
40
+ }
41
+ export function shouldProxy(argv) {
42
+ if (process.env.SIFT_DISABLED === "1")
43
+ return false;
44
+ if (argv.includes("--sift-off"))
45
+ return false;
46
+ const first = argv.find((a) => !a.startsWith("-"));
47
+ if (first && NO_PROXY.has(first))
48
+ return false;
49
+ return true;
50
+ }
51
+ function explicitModel(argv) {
52
+ for (let i = 0; i < argv.length; i++) {
53
+ if (argv[i] === "-m" || argv[i] === "--model")
54
+ return argv[i + 1] || null;
55
+ if (argv[i].startsWith("--model="))
56
+ return argv[i].slice("--model=".length);
57
+ }
58
+ return null;
59
+ }
60
+ function installSkill() {
61
+ const src = join(here, "..", "skills", "sift-explain", "SKILL.md");
62
+ if (!existsSync(src))
63
+ return;
64
+ const destDir = join(process.env.HOME || ".", ".codex", "skills", "sift-explain");
65
+ mkdirSync(destDir, { recursive: true });
66
+ copyFileSync(src, join(destDir, "SKILL.md"));
67
+ }
68
+ function forcedLane(argv) {
69
+ const flag = argv.find((a) => a.startsWith("--sift-lane="));
70
+ if (flag)
71
+ return flag.slice("--sift-lane=".length);
72
+ return process.env.SIFT_FORCE_LANE || null;
73
+ }
74
+ export async function launchCodex(argv, policy) {
75
+ loadLocalEnv();
76
+ const resolved = policy || loadPolicy();
77
+ const bin = resolveCodexBin();
78
+ const cleaned = argv.filter((a) => a !== "--sift-off" && !a.startsWith("--sift-lane="));
79
+ if (!shouldProxy(argv)) {
80
+ return await exec(bin, cleaned);
81
+ }
82
+ const pinLane = forcedLane(argv);
83
+ if (pinLane) {
84
+ const spec = resolved.lanes[pinLane];
85
+ if (!spec)
86
+ throw new Error(`Unknown Sift lane '${pinLane}'`);
87
+ return await exec(bin, ["-c", `model="${spec.model}"`, ...cleaned]);
88
+ }
89
+ const pinned = explicitModel(cleaned);
90
+ if (pinned && pinned !== resolved.virtual_model.slug) {
91
+ return await exec(bin, cleaned);
92
+ }
93
+ mkdirSync(siftHome(), { recursive: true });
94
+ installSkill();
95
+ const { server, url } = await startProxy(resolved);
96
+ let catalog = "";
97
+ try {
98
+ catalog = ensureInjectedCatalog(bin, resolved);
99
+ }
100
+ catch {
101
+ catalog = "";
102
+ }
103
+ const configArgs = [
104
+ "-c",
105
+ `model="${resolved.virtual_model.slug}"`,
106
+ "-c",
107
+ 'model_provider="sift"',
108
+ "-c",
109
+ 'model_providers.sift.name="Sift"',
110
+ "-c",
111
+ `model_providers.sift.base_url="${url}"`,
112
+ "-c",
113
+ 'model_providers.sift.wire_api="responses"',
114
+ "-c",
115
+ "model_providers.sift.requires_openai_auth=true",
116
+ ];
117
+ if (catalog) {
118
+ configArgs.push("-c", `model_catalog_json="${catalog}"`);
119
+ }
120
+ if (process.env.SIFT_QUIET !== "1") {
121
+ process.stderr.write(`codex-sift: routing via ${url}\n flash=${resolved.lanes.flash.model} craft=${resolved.lanes.craft.model} forge=${resolved.lanes.forge.model}\n`);
122
+ if (!existsSync(join(siftHome(), "policy.yaml"))) {
123
+ process.stderr.write("Tip: run `codex-sift setup` and pick those models with 1, 2, 3.\n");
124
+ }
125
+ }
126
+ try {
127
+ return await exec(bin, [...configArgs, ...cleaned]);
128
+ }
129
+ finally {
130
+ await new Promise((resolve) => server.close(() => resolve()));
131
+ }
132
+ }
133
+ function exec(bin, args) {
134
+ return new Promise((resolve) => {
135
+ const child = spawn(bin, args, {
136
+ stdio: "inherit",
137
+ env: { ...process.env, CODEX_SIFT_ACTIVE: "1" },
138
+ });
139
+ const stop = (signal) => {
140
+ if (!child.killed)
141
+ child.kill(signal);
142
+ };
143
+ process.on("SIGINT", stop);
144
+ process.on("SIGTERM", stop);
145
+ child.on("exit", (code, signal) => {
146
+ process.off("SIGINT", stop);
147
+ process.off("SIGTERM", stop);
148
+ if (signal) {
149
+ resolve(1);
150
+ return;
151
+ }
152
+ resolve(code ?? 0);
153
+ });
154
+ });
155
+ }
package/dist/log.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type { Decision } from "./types.js";
2
+ export type DecisionRecord = Decision & {
3
+ at: string;
4
+ prompt_preview: string;
5
+ };
6
+ export declare function lastPath(): string;
7
+ export declare function logPath(): string;
8
+ export declare function writeDecision(decision: Decision, prompt: string): DecisionRecord;
9
+ export declare function readLast(): DecisionRecord | null;
10
+ export declare function readLog(): DecisionRecord[];
package/dist/log.js ADDED
@@ -0,0 +1,33 @@
1
+ import { appendFileSync, mkdirSync, readFileSync, writeFileSync, existsSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { siftHome } from "./policy.js";
4
+ export function lastPath() {
5
+ return join(siftHome(), "last.json");
6
+ }
7
+ export function logPath() {
8
+ return join(siftHome(), "decisions.jsonl");
9
+ }
10
+ export function writeDecision(decision, prompt) {
11
+ mkdirSync(siftHome(), { recursive: true });
12
+ const record = {
13
+ ...decision,
14
+ at: new Date().toISOString(),
15
+ prompt_preview: prompt.replace(/\s+/g, " ").slice(0, 180),
16
+ };
17
+ writeFileSync(lastPath(), JSON.stringify(record, null, 2));
18
+ appendFileSync(logPath(), `${JSON.stringify(record)}\n`);
19
+ return record;
20
+ }
21
+ export function readLast() {
22
+ if (!existsSync(lastPath()))
23
+ return null;
24
+ return JSON.parse(readFileSync(lastPath(), "utf8"));
25
+ }
26
+ export function readLog() {
27
+ if (!existsSync(logPath()))
28
+ return [];
29
+ return readFileSync(logPath(), "utf8")
30
+ .split("\n")
31
+ .filter(Boolean)
32
+ .map((line) => JSON.parse(line));
33
+ }
package/dist/menu.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ export type CatalogChoice = {
2
+ slug: string;
3
+ display_name: string;
4
+ description: string;
5
+ };
6
+ export declare function listVisibleModels(catalog: {
7
+ models: Array<Record<string, unknown>>;
8
+ }): CatalogChoice[];
9
+ export declare function formatModelMenu(models: CatalogChoice[]): string;
10
+ export declare function defaultLaneIndexes(models: CatalogChoice[]): {
11
+ flash: number;
12
+ craft: number;
13
+ forge: number;
14
+ };
15
+ export declare function parsePick(raw: string, max: number, fallback: number): number;
package/dist/menu.js ADDED
@@ -0,0 +1,42 @@
1
+ export function listVisibleModels(catalog) {
2
+ const models = Array.isArray(catalog.models) ? catalog.models : [];
3
+ return models
4
+ .filter((m) => m.visibility === "list" && typeof m.slug === "string" && m.slug !== "sift")
5
+ .sort((a, b) => Number(a.priority ?? 99) - Number(b.priority ?? 99))
6
+ .map((m) => ({
7
+ slug: String(m.slug),
8
+ display_name: String(m.display_name || m.slug),
9
+ description: String(m.description || ""),
10
+ }));
11
+ }
12
+ export function formatModelMenu(models) {
13
+ return models
14
+ .map((m, i) => {
15
+ const n = String(i + 1).padStart(2, " ");
16
+ const desc = m.description ? ` ${m.description}` : "";
17
+ return `${n}. ${m.display_name} (${m.slug})${desc}`;
18
+ })
19
+ .join("\n");
20
+ }
21
+ export function defaultLaneIndexes(models) {
22
+ const index = (re) => {
23
+ const i = models.findIndex((m) => re.test(m.slug) || re.test(m.display_name));
24
+ return i >= 0 ? i + 1 : 0;
25
+ };
26
+ const n = models.length;
27
+ return {
28
+ flash: index(/luna|mini|spark/i) || 1,
29
+ craft: index(/terra/i) || Math.min(2, n) || 1,
30
+ forge: index(/sol/i) || index(/astra|flagship/i) || Math.min(3, n) || 1,
31
+ };
32
+ }
33
+ export function parsePick(raw, max, fallback) {
34
+ const text = raw.trim();
35
+ if (!text)
36
+ return fallback;
37
+ const n = Number(text);
38
+ if (!Number.isInteger(n) || n < 1 || n > max) {
39
+ throw new Error(`Pick a number between 1 and ${max}`);
40
+ }
41
+ return n;
42
+ }
@@ -0,0 +1,20 @@
1
+ import type { CatalogChoice } from "./menu.js";
2
+ import type { Decision, LaneName, Policy, Signals } from "./types.js";
3
+ export declare function bundledPolicyPath(): string;
4
+ export declare function loadPolicyFile(path: string): Policy;
5
+ export declare function loadPolicy(overridePath?: string): Policy;
6
+ export declare function siftHome(): string;
7
+ export declare function signalsToValues(signals: Signals): Record<string, string | number | boolean>;
8
+ export declare function applyPolicy(policy: Policy, signals: Signals, extras?: {
9
+ jev_ms?: number;
10
+ prompt_chars?: number;
11
+ degraded?: boolean;
12
+ }): Decision;
13
+ export declare function fallbackSignals(prompt: string, hasImage: boolean): Signals;
14
+ export declare function applyLanePicks(policy: Policy, models: CatalogChoice[], picks: {
15
+ flash: number;
16
+ craft: number;
17
+ forge: number;
18
+ }): Policy;
19
+ export declare function saveUserPolicy(policy: Policy): string;
20
+ export declare function laneFromName(policy: Policy, lane: LaneName): Decision;
package/dist/policy.js ADDED
@@ -0,0 +1,179 @@
1
+ import { readFileSync, existsSync, mkdirSync, writeFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
5
+ import { evalWhen } from "./expr.js";
6
+ const here = dirname(fileURLToPath(import.meta.url));
7
+ export function bundledPolicyPath() {
8
+ const candidates = [
9
+ join(here, "..", "policy.yaml"),
10
+ join(here, "policy.yaml"),
11
+ ];
12
+ for (const p of candidates) {
13
+ if (existsSync(p))
14
+ return p;
15
+ }
16
+ throw new Error("Bundled policy.yaml is missing");
17
+ }
18
+ export function loadPolicyFile(path) {
19
+ const raw = parseYaml(readFileSync(path, "utf8"));
20
+ return normalizePolicy(raw);
21
+ }
22
+ export function loadPolicy(overridePath) {
23
+ const bundled = loadPolicyFile(bundledPolicyPath());
24
+ const homePolicy = join(siftHome(), "policy.yaml");
25
+ const layered = [homePolicy, overridePath, process.env.SIFT_POLICY].filter((p) => Boolean(p && existsSync(p)));
26
+ let policy = bundled;
27
+ for (const path of layered) {
28
+ policy = mergePolicy(policy, loadPolicyFile(path));
29
+ }
30
+ return policy;
31
+ }
32
+ export function siftHome() {
33
+ return process.env.SIFT_HOME || join(process.env.HOME || ".", ".codex-sift");
34
+ }
35
+ function normalizePolicy(raw) {
36
+ if (!raw || typeof raw !== "object")
37
+ throw new Error("Policy must be a mapping");
38
+ const p = raw;
39
+ if (!p.lanes || !p.rules)
40
+ throw new Error("Policy needs lanes and rules");
41
+ return {
42
+ jev_model: p.jev_model || "jev-1.13.0",
43
+ jev_timeout_ms: p.jev_timeout_ms ?? 2500,
44
+ min_confidence: p.min_confidence ?? 0.55,
45
+ on_jev_down: p.on_jev_down || "craft",
46
+ virtual_model: {
47
+ slug: p.virtual_model?.slug || "sift",
48
+ display_name: p.virtual_model?.display_name || "Sift",
49
+ description: p.virtual_model?.description ||
50
+ "Cheapest Codex model that can handle this turn, judged by Jev.",
51
+ },
52
+ lanes: p.lanes,
53
+ prices_usd_per_1m: p.prices_usd_per_1m || {},
54
+ usage_weight: p.usage_weight || {},
55
+ effort_weight: p.effort_weight || {},
56
+ rules: (p.rules || []).map((rule) => ({
57
+ ...rule,
58
+ when: String(rule.when),
59
+ })),
60
+ };
61
+ }
62
+ function mergePolicy(base, overlay) {
63
+ return {
64
+ ...base,
65
+ ...overlay,
66
+ virtual_model: { ...base.virtual_model, ...overlay.virtual_model },
67
+ lanes: { ...base.lanes, ...overlay.lanes },
68
+ prices_usd_per_1m: { ...base.prices_usd_per_1m, ...overlay.prices_usd_per_1m },
69
+ usage_weight: { ...base.usage_weight, ...overlay.usage_weight },
70
+ effort_weight: { ...base.effort_weight, ...overlay.effort_weight },
71
+ rules: overlay.rules.length ? overlay.rules : base.rules,
72
+ };
73
+ }
74
+ export function signalsToValues(signals) {
75
+ return {
76
+ task_kind: signals.task_kind,
77
+ task_kind_confidence: signals.task_kind_confidence,
78
+ difficulty: signals.difficulty,
79
+ difficulty_confidence: signals.difficulty_confidence,
80
+ needs_reasoning: signals.needs_reasoning,
81
+ needs_planning: signals.needs_planning,
82
+ high_stakes: signals.high_stakes,
83
+ cross_cutting: signals.cross_cutting,
84
+ is_chitchat: signals.is_chitchat,
85
+ confidence: signals.confidence,
86
+ has_image: signals.has_image,
87
+ };
88
+ }
89
+ export function applyPolicy(policy, signals, extras) {
90
+ const values = signalsToValues(signals);
91
+ const matched = [];
92
+ let lane;
93
+ for (const rule of policy.rules) {
94
+ if (!evalWhen(rule.when, values))
95
+ continue;
96
+ if (!lane)
97
+ lane = rule.lane;
98
+ matched.push(rule.reason);
99
+ break;
100
+ }
101
+ if (!lane)
102
+ lane = policy.on_jev_down;
103
+ const spec = policy.lanes[lane];
104
+ if (!spec)
105
+ throw new Error(`Unknown lane '${lane}'`);
106
+ return {
107
+ lane,
108
+ model: spec.model,
109
+ effort: spec.effort,
110
+ reason: matched.length ? matched : ["default"],
111
+ signals,
112
+ degraded: extras?.degraded ?? false,
113
+ jev_ms: extras?.jev_ms ?? 0,
114
+ prompt_chars: extras?.prompt_chars ?? 0,
115
+ };
116
+ }
117
+ export function fallbackSignals(prompt, hasImage) {
118
+ const text = prompt.trim();
119
+ const short = text.length < 140;
120
+ const looksAsk = /^(what|why|how|where|who|explain|show|list|find)\b/i.test(text);
121
+ const looksOps = /\b(git |npm |pnpm |yarn |pip |brew |commit|push|install)\b/i.test(text);
122
+ const looksHard = /\b(architect|redesign|migrate|auth|security|race|deadlock|distributed)\b/i.test(text);
123
+ const difficulty = looksHard ? 2.4 : short ? 0.6 : 1.4;
124
+ return {
125
+ task_kind: looksAsk ? "ask" : looksOps ? "ops" : "edit",
126
+ task_kind_confidence: 0.4,
127
+ difficulty,
128
+ difficulty_confidence: 0.4,
129
+ needs_reasoning: looksHard ? 0.8 : 0.2,
130
+ needs_planning: looksHard ? 0.7 : 0.15,
131
+ high_stakes: /\b(auth|prod|producti|migrat|secret|payment)\b/i.test(text) ? 0.75 : 0.1,
132
+ cross_cutting: looksHard ? 0.7 : 0.1,
133
+ is_chitchat: /^(hola|hello|hi|hey|buenas|ok|thanks|gracias)[\s!?.]*$/i.test(text) ? 0.9 : 0.1,
134
+ confidence: 0.4,
135
+ has_image: hasImage,
136
+ };
137
+ }
138
+ export function applyLanePicks(policy, models, picks) {
139
+ const pick = (n) => {
140
+ const model = models[n - 1];
141
+ if (!model)
142
+ throw new Error(`No model at position ${n}`);
143
+ return model;
144
+ };
145
+ const flash = pick(picks.flash);
146
+ const craft = pick(picks.craft);
147
+ const forge = pick(picks.forge);
148
+ return {
149
+ ...policy,
150
+ lanes: {
151
+ ...policy.lanes,
152
+ flash: { ...policy.lanes.flash, model: flash.slug },
153
+ craft: { ...policy.lanes.craft, model: craft.slug },
154
+ forge: { ...policy.lanes.forge, model: forge.slug },
155
+ },
156
+ };
157
+ }
158
+ export function saveUserPolicy(policy) {
159
+ mkdirSync(siftHome(), { recursive: true });
160
+ const dest = join(siftHome(), "policy.yaml");
161
+ const body = stringifyYaml(policy, { lineWidth: 0 });
162
+ writeFileSync(dest, `# Written by \`codex-sift setup\`. Run setup again to pick models by number.\n${body}`);
163
+ return dest;
164
+ }
165
+ export function laneFromName(policy, lane) {
166
+ const spec = policy.lanes[lane];
167
+ if (!spec)
168
+ throw new Error(`Unknown lane '${lane}'`);
169
+ return {
170
+ lane,
171
+ model: spec.model,
172
+ effort: spec.effort,
173
+ reason: ["forced lane"],
174
+ signals: fallbackSignals("", false),
175
+ degraded: false,
176
+ jev_ms: 0,
177
+ prompt_chars: 0,
178
+ };
179
+ }
@@ -0,0 +1,7 @@
1
+ import http from "node:http";
2
+ import type { Policy } from "./types.js";
3
+ export declare function startProxy(policy: Policy): Promise<{
4
+ server: http.Server;
5
+ port: number;
6
+ url: string;
7
+ }>;