codex-sift 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +252 -2
- package/dist/catalog.d.ts +19 -0
- package/dist/catalog.js +68 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +108 -0
- package/dist/demo.d.ts +2 -0
- package/dist/demo.js +33 -0
- package/dist/doctor.d.ts +1 -0
- package/dist/doctor.js +49 -0
- package/dist/e2e.d.ts +24 -0
- package/dist/e2e.js +225 -0
- package/dist/env.d.ts +3 -0
- package/dist/env.js +42 -0
- package/dist/explain.d.ts +1 -0
- package/dist/explain.js +29 -0
- package/dist/expr.d.ts +2 -0
- package/dist/expr.js +210 -0
- package/dist/jev.d.ts +23 -0
- package/dist/jev.js +156 -0
- package/dist/launch.d.ts +4 -0
- package/dist/launch.js +155 -0
- package/dist/log.d.ts +10 -0
- package/dist/log.js +33 -0
- package/dist/menu.d.ts +15 -0
- package/dist/menu.js +42 -0
- package/dist/policy.d.ts +20 -0
- package/dist/policy.js +179 -0
- package/dist/proxy.d.ts +7 -0
- package/dist/proxy.js +132 -0
- package/dist/redact.d.ts +1 -0
- package/dist/redact.js +21 -0
- package/dist/report.d.ts +1 -0
- package/dist/report.js +38 -0
- package/dist/setup.d.ts +10 -0
- package/dist/setup.js +125 -0
- package/dist/turns.d.ts +15 -0
- package/dist/turns.js +137 -0
- package/dist/types.d.ts +56 -0
- package/dist/types.js +2 -0
- package/dist/upstream.d.ts +16 -0
- package/dist/upstream.js +120 -0
- package/dist/usage.d.ts +21 -0
- package/dist/usage.js +62 -0
- package/package.json +59 -4
- package/policy.yaml +76 -0
- package/scripts/statusline.js +13 -0
- package/skills/sift-explain/SKILL.md +16 -0
package/dist/usage.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Policy } from "./types.js";
|
|
2
|
+
export type UsageRow = {
|
|
3
|
+
lane: string;
|
|
4
|
+
model: string;
|
|
5
|
+
effort?: string;
|
|
6
|
+
degraded?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type UsageSummary = {
|
|
9
|
+
turns: number;
|
|
10
|
+
liveTurns: number;
|
|
11
|
+
degraded: number;
|
|
12
|
+
mix: Record<string, number>;
|
|
13
|
+
alwaysForge: number;
|
|
14
|
+
actual: number;
|
|
15
|
+
saved: number;
|
|
16
|
+
savedPct: number;
|
|
17
|
+
forgeModel: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function turnCost(policy: Policy, model: string, effort?: string): number;
|
|
20
|
+
export declare function summarizeUsage(policy: Policy, rows: UsageRow[]): UsageSummary;
|
|
21
|
+
export declare function formatUsage(summary: UsageSummary): string;
|
package/dist/usage.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const DEFAULT_USAGE = {
|
|
2
|
+
"gpt-5.6-luna": 0.25,
|
|
3
|
+
"gpt-5.6-terra": 0.55,
|
|
4
|
+
"gpt-5.6-sol": 1,
|
|
5
|
+
"gpt-6-astra": 1.6,
|
|
6
|
+
"gpt-5.5": 1.1,
|
|
7
|
+
};
|
|
8
|
+
const DEFAULT_EFFORT = {
|
|
9
|
+
low: 0.7,
|
|
10
|
+
medium: 1,
|
|
11
|
+
high: 1.35,
|
|
12
|
+
xhigh: 1.7,
|
|
13
|
+
};
|
|
14
|
+
export function turnCost(policy, model, effort) {
|
|
15
|
+
const modelW = policy.usage_weight[model] ?? DEFAULT_USAGE[model] ?? 1;
|
|
16
|
+
const effortW = policy.effort_weight[effort || "medium"] ?? DEFAULT_EFFORT[effort || "medium"] ?? 1;
|
|
17
|
+
return modelW * effortW;
|
|
18
|
+
}
|
|
19
|
+
export function summarizeUsage(policy, rows) {
|
|
20
|
+
const forgeModel = policy.lanes.forge?.model || "gpt-5.6-sol";
|
|
21
|
+
const forgeEffort = policy.lanes.forge?.effort || "high";
|
|
22
|
+
const alwaysUnit = turnCost(policy, forgeModel, forgeEffort);
|
|
23
|
+
const mix = {};
|
|
24
|
+
let actual = 0;
|
|
25
|
+
let liveTurns = 0;
|
|
26
|
+
let degraded = 0;
|
|
27
|
+
for (const row of rows) {
|
|
28
|
+
mix[row.lane] = (mix[row.lane] || 0) + 1;
|
|
29
|
+
if (row.degraded) {
|
|
30
|
+
degraded += 1;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
liveTurns += 1;
|
|
34
|
+
actual += turnCost(policy, row.model, row.effort);
|
|
35
|
+
}
|
|
36
|
+
const alwaysForge = liveTurns * alwaysUnit;
|
|
37
|
+
const saved = Math.max(0, alwaysForge - actual);
|
|
38
|
+
const savedPct = alwaysForge > 0 ? (saved / alwaysForge) * 100 : 0;
|
|
39
|
+
return {
|
|
40
|
+
turns: rows.length,
|
|
41
|
+
liveTurns,
|
|
42
|
+
degraded,
|
|
43
|
+
mix,
|
|
44
|
+
alwaysForge,
|
|
45
|
+
actual,
|
|
46
|
+
saved,
|
|
47
|
+
savedPct,
|
|
48
|
+
forgeModel,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export function formatUsage(summary) {
|
|
52
|
+
const mix = Object.entries(summary.mix)
|
|
53
|
+
.sort((a, b) => b[1] - a[1])
|
|
54
|
+
.map(([lane, n]) => `${lane} ${n} (${((n / Math.max(1, summary.turns)) * 100).toFixed(0)}%)`)
|
|
55
|
+
.join(" ");
|
|
56
|
+
return [
|
|
57
|
+
`turns: ${summary.turns} (Jev live: ${summary.liveTurns}, degraded: ${summary.degraded})`,
|
|
58
|
+
`mix: ${mix || "(none)"}`,
|
|
59
|
+
`usage vs always-${summary.forgeModel}: ${summary.alwaysForge.toFixed(2)} -> ${summary.actual.toFixed(2)} (${summary.savedPct.toFixed(0)}% less Codex quota)`,
|
|
60
|
+
`baseline is "every live turn on the forge lane". Weights are in policy.yaml (usage_weight × effort_weight).`,
|
|
61
|
+
].join("\n");
|
|
62
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codex-sift",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Model router for OpenAI Codex CLI. Choose a model per coding task to manage token, credit, and quota usage.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"codex-sift": "dist/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"policy.yaml",
|
|
12
|
+
"skills",
|
|
13
|
+
"scripts",
|
|
14
|
+
"README.md",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc && node -e \"require('fs').chmodSync('dist/cli.js',0o755)\"",
|
|
19
|
+
"prepare": "npm run build",
|
|
20
|
+
"prepublishOnly": "npm run build",
|
|
21
|
+
"dev": "tsx src/cli.ts",
|
|
22
|
+
"test": "tsx --test src/*.test.ts",
|
|
23
|
+
"e2e": "tsx src/cli.ts e2e",
|
|
24
|
+
"e2e:report": "node dist/cli.js e2e --out reports/e2e-routing.md --json-out reports/e2e-routing.json",
|
|
25
|
+
"start": "node dist/cli.js"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=20"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"codex",
|
|
32
|
+
"openai-codex",
|
|
33
|
+
"codex-cli",
|
|
34
|
+
"model-routing",
|
|
35
|
+
"model-router",
|
|
36
|
+
"codex-model-routing",
|
|
37
|
+
"token-usage",
|
|
38
|
+
"cost-optimization",
|
|
39
|
+
"cli",
|
|
40
|
+
"typesafe",
|
|
41
|
+
"jev"
|
|
42
|
+
],
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"author": "Roman Meclazcke",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/romanmeclazcke/codex-sift.git"
|
|
48
|
+
},
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/romanmeclazcke/codex-sift/issues"
|
|
51
|
+
},
|
|
52
|
+
"homepage": "https://codex-sift.vercel.app",
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"yaml": "^2.8.1"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/node": "^20.19.17",
|
|
58
|
+
"tsx": "^4.20.5",
|
|
59
|
+
"typescript": "^5.9.2"
|
|
60
|
+
}
|
|
61
|
+
}
|
package/policy.yaml
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Sift policy. Copy to ~/.codex-sift/policy.yaml to override.
|
|
2
|
+
# Jev returns signals. These rules pick a lane. First match wins.
|
|
3
|
+
|
|
4
|
+
jev_model: jev-1.13.0
|
|
5
|
+
jev_timeout_ms: 2500
|
|
6
|
+
min_confidence: 0.55
|
|
7
|
+
on_jev_down: craft
|
|
8
|
+
|
|
9
|
+
virtual_model:
|
|
10
|
+
slug: sift
|
|
11
|
+
display_name: Sift
|
|
12
|
+
description: Cheapest Codex model that can handle this turn, judged by Jev.
|
|
13
|
+
|
|
14
|
+
lanes:
|
|
15
|
+
flash:
|
|
16
|
+
model: gpt-5.6-luna
|
|
17
|
+
effort: low
|
|
18
|
+
craft:
|
|
19
|
+
model: gpt-5.6-terra
|
|
20
|
+
effort: medium
|
|
21
|
+
forge:
|
|
22
|
+
model: gpt-5.6-sol
|
|
23
|
+
effort: high
|
|
24
|
+
|
|
25
|
+
prices_usd_per_1m:
|
|
26
|
+
gpt-5.6-luna: 0.4
|
|
27
|
+
gpt-5.6-terra: 1.2
|
|
28
|
+
gpt-5.6-sol: 3.6
|
|
29
|
+
gpt-6-astra: 6.0
|
|
30
|
+
gpt-5.5: 4.0
|
|
31
|
+
|
|
32
|
+
# Relative Codex quota vs forge. Tune with your /usage observations.
|
|
33
|
+
usage_weight:
|
|
34
|
+
gpt-5.6-luna: 0.25
|
|
35
|
+
gpt-5.6-terra: 0.55
|
|
36
|
+
gpt-5.6-sol: 1.0
|
|
37
|
+
gpt-6-astra: 1.6
|
|
38
|
+
gpt-5.5: 1.1
|
|
39
|
+
|
|
40
|
+
effort_weight:
|
|
41
|
+
low: 0.7
|
|
42
|
+
medium: 1.0
|
|
43
|
+
high: 1.35
|
|
44
|
+
xhigh: 1.7
|
|
45
|
+
|
|
46
|
+
rules:
|
|
47
|
+
- when: "is_chitchat > 0.7"
|
|
48
|
+
lane: flash
|
|
49
|
+
reason: greeting or chitchat
|
|
50
|
+
- when: "task_kind in [ask, ops] and difficulty < 1.3 and high_stakes < 0.4"
|
|
51
|
+
lane: flash
|
|
52
|
+
reason: lookup or plumbing
|
|
53
|
+
- when: "task_kind == edit and difficulty < 1.3 and high_stakes < 0.4"
|
|
54
|
+
lane: flash
|
|
55
|
+
reason: localized cheap edit
|
|
56
|
+
- when: "confidence < 0.55 and (difficulty >= 1.5 or high_stakes > 0.4)"
|
|
57
|
+
lane: forge
|
|
58
|
+
reason: Jev was unsure on non-trivial work, escalate
|
|
59
|
+
- when: "high_stakes > 0.7"
|
|
60
|
+
lane: forge
|
|
61
|
+
reason: high-stakes surface
|
|
62
|
+
- when: "difficulty >= 2.2"
|
|
63
|
+
lane: forge
|
|
64
|
+
reason: hard or novel work
|
|
65
|
+
- when: "needs_planning > 0.7 and cross_cutting > 0.6"
|
|
66
|
+
lane: forge
|
|
67
|
+
reason: cross-cutting design
|
|
68
|
+
- when: "needs_reasoning > 0.6 and difficulty >= 1.3"
|
|
69
|
+
lane: craft
|
|
70
|
+
reason: needs real diagnosis
|
|
71
|
+
- when: "difficulty < 1.5"
|
|
72
|
+
lane: craft
|
|
73
|
+
reason: everyday implementation
|
|
74
|
+
- when: "true"
|
|
75
|
+
lane: craft
|
|
76
|
+
reason: default balanced lane
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
const path = join(process.env.SIFT_HOME || process.env.HOME || ".", ".codex-sift", "last.json");
|
|
6
|
+
if (!existsSync(path)) {
|
|
7
|
+
process.stdout.write("Sift");
|
|
8
|
+
process.exit(0);
|
|
9
|
+
}
|
|
10
|
+
const last = JSON.parse(readFileSync(path, "utf8"));
|
|
11
|
+
const lane = last.lane || "?";
|
|
12
|
+
const model = last.model || "";
|
|
13
|
+
process.stdout.write(`Sift · ${lane} · ${model}`);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sift-explain
|
|
3
|
+
description: Explain why Codex Sift chose the current model lane for the last user turn
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
When the user asks why Sift picked a model, or invokes `$sift-explain`, read `~/.codex-sift/last.json`.
|
|
7
|
+
|
|
8
|
+
Summarize, without inventing numbers:
|
|
9
|
+
|
|
10
|
+
- lane and target Codex model
|
|
11
|
+
- effort
|
|
12
|
+
- the `reason` list
|
|
13
|
+
- task_kind, difficulty, needs_reasoning, high_stakes
|
|
14
|
+
- whether `degraded` is true (Jev was unavailable)
|
|
15
|
+
|
|
16
|
+
If the file is missing, say no turn has been routed yet and suggest `codex-sift route "..."`.
|