docks-kit 0.22.28 → 0.24.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/AGENTS.md +42 -89
- package/README.md +35 -72
- package/cli/docs/command-guards.md +233 -197
- package/cli/docs/flags.md +17 -65
- package/cli/docs/install.md +2 -3
- package/cli/docs/omp-context.md +79 -7
- package/cli/docs/omp-models.md +27 -12
- package/cli/docs/overview.md +7 -18
- package/cli/docs/platforms.md +2 -2
- package/cli/docs/sync-layers.md +14 -60
- package/cli/docs/toolchain.md +12 -81
- package/cli/src/argv.ts +0 -12
- package/cli/src/argvValidate.ts +3 -54
- package/cli/src/commands/docs.ts +3 -15
- package/cli/src/commands/omp.ts +1 -1
- package/cli/src/commands/scratch.ts +1 -1
- package/cli/src/commands/sync.ts +5 -120
- package/cli/src/commands/tidy.ts +1 -1
- package/cli/src/commands/toolchain.ts +4 -12
- package/cli/src/engine-native/DESIGN.md +69 -100
- package/cli/src/engine-native/deps.ts +7 -92
- package/cli/src/engine-native/engineCtx.ts +9 -103
- package/cli/src/engine-native/exec.ts +1 -18
- package/cli/src/engine-native/index.ts +6 -8
- package/cli/src/engine-native/jq.ts +4 -37
- package/cli/src/engine-native/kitDb.ts +21 -37
- package/cli/src/engine-native/modes.ts +3 -132
- package/cli/src/engine-native/ompFastMode.ts +1 -1
- package/cli/src/engine-native/ompOverlay.ts +1 -1
- package/cli/src/engine-native/ompRemovals.ts +24 -3
- package/cli/src/engine-native/ompSession.ts +67 -0
- package/cli/src/engine-native/ompSync.ts +1 -1
- package/cli/src/engine-native/os/darwin.ts +0 -4
- package/cli/src/engine-native/os/index.ts +1 -2
- package/cli/src/engine-native/os/linux.ts +0 -3
- package/cli/src/engine-native/os/posix.ts +2 -47
- package/cli/src/engine-native/os/types.ts +1 -36
- package/cli/src/engine-native/os/windows.ts +0 -50
- package/cli/src/engine-native/parseArgs.ts +7 -180
- package/cli/src/engine-native/parseHelp.ts +4 -44
- package/cli/src/engine-native/scratch.ts +1 -1
- package/cli/src/engine-native/services.ts +1 -2
- package/cli/src/engine-native/sharedTypes.d.ts +1 -41
- package/cli/src/engine-native/syncConcurrency.ts +3 -15
- package/cli/src/engine-native/syncDispatch.ts +30 -143
- package/cli/src/engine-native/toolchain.ts +6 -45
- package/cli/src/engine.ts +0 -75
- package/cli/src/generated/sotPayload.ts +14 -43
- package/cli/src/main.ts +8 -24
- package/cli/src/payload.ts +2 -8
- package/cli/tsconfig.json +1 -3
- package/package.json +3 -5
- package/cli/docs/models.md +0 -58
- package/cli/docs/modifiers.md +0 -52
- package/cli/docs/plugins.md +0 -70
- package/cli/src/checklistPrompt.ts +0 -464
- package/cli/src/commands/harnesses.ts +0 -80
- package/cli/src/commands/model.ts +0 -68
- package/cli/src/commands/models.ts +0 -75
- package/cli/src/commands/plugins.ts +0 -35
- package/cli/src/commands/skills.ts +0 -40
- package/cli/src/commands/status.ts +0 -206
- package/cli/src/efforts.ts +0 -89
- package/cli/src/engine-native/claudeLsp.ts +0 -301
- package/cli/src/engine-native/claudeOptionalPlugins.ts +0 -126
- package/cli/src/engine-native/claudePluginPasses.ts +0 -426
- package/cli/src/engine-native/claudeRemovals.ts +0 -383
- package/cli/src/engine-native/claudeRetired.ts +0 -165
- package/cli/src/engine-native/claudeRuntime.ts +0 -157
- package/cli/src/engine-native/claudeSettings.ts +0 -201
- package/cli/src/engine-native/claudeSettingsModifiers.ts +0 -115
- package/cli/src/engine-native/claudeSync.ts +0 -312
- package/cli/src/engine-native/codexConfig.ts +0 -214
- package/cli/src/engine-native/codexHooks.ts +0 -91
- package/cli/src/engine-native/codexPaths.ts +0 -14
- package/cli/src/engine-native/codexPlugins.ts +0 -315
- package/cli/src/engine-native/codexStatus.ts +0 -25
- package/cli/src/engine-native/codexSync.ts +0 -314
- package/cli/src/engine-native/codexToml.ts +0 -303
- package/cli/src/engine-native/harnesses.ts +0 -138
- package/cli/src/engine-native/liveModels.ts +0 -264
- package/cli/src/engine-native/models.ts +0 -101
- package/cli/src/engine-native/parseModifiers.ts +0 -225
- package/cli/src/engine-native/settings.ts +0 -42
- package/cli/src/engine-native/skillsInstall.ts +0 -135
- package/cli/src/engine-native/skillsLinks.ts +0 -216
- package/cli/src/engine-native/skillsManifest.ts +0 -36
- package/cli/src/engine-native/skillsPrune.ts +0 -117
- package/cli/src/engine-native/skillsRecords.ts +0 -138
- package/cli/src/engine-native/skillsSync.ts +0 -57
- package/cli/src/engine-native/tomlLines.ts +0 -92
- package/cli/src/manifests.ts +0 -145
- package/cli/src/terminalCells.ts +0 -191
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Per-machine harness selection and omp session model, stored in ~/.docks-kit/kit.db (kitDb.ts).
|
|
3
|
-
* The selection keeps the omp harness opt-in. A missing or unreadable store is
|
|
4
|
-
* represented by undefined so callers resolve it to LEGACY_SELECTION.
|
|
5
|
-
*/
|
|
6
|
-
import { homedir } from "node:os";
|
|
7
|
-
|
|
8
|
-
import { inTransaction, isNonBlankString, nonBlankOrNull, withKitDb } from "./kitDb";
|
|
9
|
-
import type { OmpSessionModel } from "./sharedTypes";
|
|
10
|
-
|
|
11
|
-
export type Harness = "claude" | "codex" | "agents" | "omp";
|
|
12
|
-
|
|
13
|
-
export const HARNESSES: ReadonlyArray<Harness> = ["claude", "codex", "agents", "omp"];
|
|
14
|
-
export const LEGACY_SELECTION: ReadonlyArray<Harness> = ["claude", "codex", "agents"];
|
|
15
|
-
|
|
16
|
-
export type { OmpSessionModel };
|
|
17
|
-
|
|
18
|
-
export const DEFAULT_OMP_SESSION_MODEL: OmpSessionModel = {
|
|
19
|
-
selector: "opencode-zen/muse-spark-1.3-contributor-free",
|
|
20
|
-
thinking: "xhigh",
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
function isHarness(value: unknown): value is Harness {
|
|
24
|
-
return value === "claude" || value === "codex" || value === "agents" || value === "omp";
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function normalizeHarnesses(selection: ReadonlyArray<unknown>): Array<Harness> {
|
|
28
|
-
const selected = new Set<Harness>();
|
|
29
|
-
for (const value of selection) {
|
|
30
|
-
if (isHarness(value)) selected.add(value);
|
|
31
|
-
}
|
|
32
|
-
return HARNESSES.filter((harness) => selected.has(harness));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Resolve the engine home root the way the harnesses resolve `~`. On Windows,
|
|
37
|
-
* USERPROFILE applies and HOME is ignored. Elsewhere, HOME applies. The
|
|
38
|
-
* platform home is the fallback.
|
|
39
|
-
*/
|
|
40
|
-
export function engineHome(
|
|
41
|
-
env: NodeJS.ProcessEnv = process.env,
|
|
42
|
-
platform: NodeJS.Platform = process.platform,
|
|
43
|
-
): string {
|
|
44
|
-
const home = platform === "win32" ? env["USERPROFILE"] : env["HOME"];
|
|
45
|
-
return home !== undefined && home !== "" ? home : homedir();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** Result of a read of the stored selection that keeps the failure reason. */
|
|
49
|
-
export type StoredSelection =
|
|
50
|
-
| { kind: "stored"; selection: ReadonlyArray<Harness> }
|
|
51
|
-
| { kind: "missing" }
|
|
52
|
-
| { kind: "unreadable"; reason: string };
|
|
53
|
-
|
|
54
|
-
/** Read the stored selection; corruption, a too-new schema, or I/O errors yield "unreadable". */
|
|
55
|
-
export function loadHarnessSelection(home: string): StoredSelection {
|
|
56
|
-
try {
|
|
57
|
-
const selection = withKitDb(home, "read", (db) =>
|
|
58
|
-
normalizeHarnesses(
|
|
59
|
-
db
|
|
60
|
-
.prepare("SELECT harness FROM harness_selection")
|
|
61
|
-
.all()
|
|
62
|
-
.map((row) => row["harness"]),
|
|
63
|
-
),
|
|
64
|
-
);
|
|
65
|
-
return selection !== undefined && selection.length > 0
|
|
66
|
-
? { kind: "stored", selection }
|
|
67
|
-
: { kind: "missing" };
|
|
68
|
-
} catch (error) {
|
|
69
|
-
return {
|
|
70
|
-
kind: "unreadable",
|
|
71
|
-
reason: error instanceof Error ? error.message : String(error),
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** Read the stored selection; corruption, a too-new schema, or I/O errors yield undefined. */
|
|
77
|
-
export function readHarnessSelection(home: string): ReadonlyArray<Harness> | undefined {
|
|
78
|
-
const stored = loadHarnessSelection(home);
|
|
79
|
-
return stored.kind === "stored" ? stored.selection : undefined;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function writeHarnessSelection(home: string, selection: ReadonlyArray<Harness>): void {
|
|
83
|
-
if (selection.length === 0) {
|
|
84
|
-
throw new Error("Cannot write an empty harness selection because sync would become a no-op");
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const harnesses = normalizeHarnesses(selection);
|
|
88
|
-
if (harnesses.length === 0) {
|
|
89
|
-
throw new Error("Harness selection must contain at least one known harness name");
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
withKitDb(home, "write", (db) =>
|
|
93
|
-
inTransaction(db, () => {
|
|
94
|
-
db.exec("DELETE FROM harness_selection");
|
|
95
|
-
const insert = db.prepare("INSERT INTO harness_selection (harness) VALUES (?)");
|
|
96
|
-
for (const harness of harnesses) insert.run(harness);
|
|
97
|
-
}),
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Read the stored session model without throwing so a corrupt store falls
|
|
102
|
-
// back to the default instead of breaking sync.
|
|
103
|
-
export function readOmpSessionModel(home: string): OmpSessionModel | undefined {
|
|
104
|
-
try {
|
|
105
|
-
return withKitDb(home, "read", (db) => {
|
|
106
|
-
const row = db.prepare("SELECT selector, thinking FROM omp_session WHERE id = 1").get();
|
|
107
|
-
const selector = row?.["selector"];
|
|
108
|
-
if (!isNonBlankString(selector)) return undefined;
|
|
109
|
-
const thinking = row?.["thinking"];
|
|
110
|
-
const model: OmpSessionModel = {
|
|
111
|
-
selector,
|
|
112
|
-
...(isNonBlankString(thinking) ? { thinking } : {}),
|
|
113
|
-
};
|
|
114
|
-
return model;
|
|
115
|
-
});
|
|
116
|
-
} catch {
|
|
117
|
-
return undefined;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export function writeOmpSessionModel(home: string, model: OmpSessionModel): void {
|
|
122
|
-
// A blank selector would make omp resolve an arbitrary model, so reject it
|
|
123
|
-
// before anything reaches disk.
|
|
124
|
-
if (!isNonBlankString(model.selector)) {
|
|
125
|
-
throw new Error("Omp session model selector must be a non-empty string");
|
|
126
|
-
}
|
|
127
|
-
// Store a blank or absent level as NULL so a switch to a level-free model
|
|
128
|
-
// leaves no stale level behind.
|
|
129
|
-
const thinking = nonBlankOrNull(model.thinking);
|
|
130
|
-
withKitDb(home, "write", (db) =>
|
|
131
|
-
db
|
|
132
|
-
.prepare(
|
|
133
|
-
`INSERT INTO omp_session (id, selector, thinking) VALUES (1, ?, ?)
|
|
134
|
-
ON CONFLICT(id) DO UPDATE SET selector = excluded.selector, thinking = excluded.thinking`,
|
|
135
|
-
)
|
|
136
|
-
.run(model.selector, thinking),
|
|
137
|
-
);
|
|
138
|
-
}
|
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
|
|
3
|
-
import { codexHome } from "./codexPaths";
|
|
4
|
-
import { capture, p, which } from "./exec";
|
|
5
|
-
import { LEGACY_SELECTION, readHarnessSelection } from "./harnesses";
|
|
6
|
-
import { isObject, parseJson } from "./jq";
|
|
7
|
-
import { isNonBlankString, readCache, writeCache } from "./kitDb";
|
|
8
|
-
import { modelCatalog } from "./models";
|
|
9
|
-
import type { CatalogSource, CatalogTool, FetchLike, ResolvedCatalog } from "./sharedTypes";
|
|
10
|
-
|
|
11
|
-
export interface LiveCatalogInputs {
|
|
12
|
-
readonly home: string;
|
|
13
|
-
readonly refresh: boolean;
|
|
14
|
-
readonly fetch: FetchLike;
|
|
15
|
-
readonly which: (name: string) => string;
|
|
16
|
-
readonly capture: (cmd: string, args: ReadonlyArray<string>) => Promise<string>;
|
|
17
|
-
readonly now: () => number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const defaultLiveInputs = (home: string, refresh = false): LiveCatalogInputs => ({
|
|
21
|
-
home,
|
|
22
|
-
refresh,
|
|
23
|
-
fetch: globalThis.fetch,
|
|
24
|
-
which,
|
|
25
|
-
capture,
|
|
26
|
-
now: Date.now,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
type LiveModel = ResolvedCatalog["models"][number];
|
|
30
|
-
type LiveLookup = {
|
|
31
|
-
readonly source: Exclude<CatalogSource, "curated">;
|
|
32
|
-
readonly fetchedAt?: string;
|
|
33
|
-
readonly models: ReadonlyArray<LiveModel>;
|
|
34
|
-
};
|
|
35
|
-
type Lookup = LiveLookup | { readonly fallbackReason: string };
|
|
36
|
-
|
|
37
|
-
export function curatedCatalog(tool: CatalogTool): ResolvedCatalog {
|
|
38
|
-
if (tool === "omp") return { tool, source: "curated", verified: "?", models: [] };
|
|
39
|
-
return { tool, source: "curated", ...modelCatalog(tool) };
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function mergeCurated(curated: ResolvedCatalog, live: ReadonlyArray<LiveModel>): Array<LiveModel> {
|
|
43
|
-
const models: Array<LiveModel> = [];
|
|
44
|
-
const notes = new Map<string, string>();
|
|
45
|
-
for (const entry of curated.models) {
|
|
46
|
-
if (entry.kind === "alias") models.push(entry);
|
|
47
|
-
if (entry.note !== undefined) notes.set(entry.id, entry.note);
|
|
48
|
-
}
|
|
49
|
-
for (const entry of live) {
|
|
50
|
-
const note = notes.get(entry.id) ?? entry.note;
|
|
51
|
-
models.push(
|
|
52
|
-
note === undefined ? { id: entry.id, kind: "id" } : { id: entry.id, kind: "id", note },
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
return models;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export async function resolveCatalog(
|
|
59
|
-
tool: CatalogTool,
|
|
60
|
-
inputs: LiveCatalogInputs,
|
|
61
|
-
): Promise<ResolvedCatalog> {
|
|
62
|
-
const curated = curatedCatalog(tool);
|
|
63
|
-
if (!(readHarnessSelection(inputs.home) ?? LEGACY_SELECTION).includes(tool)) {
|
|
64
|
-
return { ...curated, fallbackReason: `${tool} harness not enabled (docks-kit harnesses)` };
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const lookup =
|
|
68
|
-
tool === "claude"
|
|
69
|
-
? await claudeCatalog(inputs)
|
|
70
|
-
: tool === "codex"
|
|
71
|
-
? codexCatalog(inputs.home)
|
|
72
|
-
: await ompCatalog(inputs);
|
|
73
|
-
if ("fallbackReason" in lookup) return { ...curated, fallbackReason: lookup.fallbackReason };
|
|
74
|
-
return {
|
|
75
|
-
...curated,
|
|
76
|
-
source: lookup.source,
|
|
77
|
-
...(lookup.fetchedAt === undefined ? {} : { fetchedAt: lookup.fetchedAt }),
|
|
78
|
-
models: tool === "omp" ? lookup.models : mergeCurated(curated, lookup.models),
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const ANTHROPIC_CACHE_KEY = "models:anthropic";
|
|
83
|
-
const ANTHROPIC_CACHE_TTL = 6 * 3600_000;
|
|
84
|
-
const NO_CLAUDE_LOGIN = "no Claude Code login found in ~/.claude/.credentials.json";
|
|
85
|
-
|
|
86
|
-
function cachedClaudeCatalog(payload: string): LiveLookup | undefined {
|
|
87
|
-
const cached = parseJson(payload);
|
|
88
|
-
if (cached === undefined || !isObject(cached)) return undefined;
|
|
89
|
-
const fetchedAt = cached["fetchedAt"];
|
|
90
|
-
const ids = cached["ids"];
|
|
91
|
-
if (typeof fetchedAt !== "string" || !Array.isArray(ids)) {
|
|
92
|
-
return undefined;
|
|
93
|
-
}
|
|
94
|
-
if (!ids.every(isNonBlankString)) return undefined;
|
|
95
|
-
const displayNames = cached["displayNames"];
|
|
96
|
-
// Names align with ids; older cache rows contain ids only.
|
|
97
|
-
const names =
|
|
98
|
-
Array.isArray(displayNames) &&
|
|
99
|
-
displayNames.length === ids.length &&
|
|
100
|
-
displayNames.every((name) => name === null || isNonBlankString(name))
|
|
101
|
-
? displayNames
|
|
102
|
-
: undefined;
|
|
103
|
-
return {
|
|
104
|
-
source: "anthropic-api",
|
|
105
|
-
fetchedAt,
|
|
106
|
-
models: ids.map((id, index) => {
|
|
107
|
-
const name = names?.[index];
|
|
108
|
-
return typeof name === "string" ? { id, kind: "id", note: name } : { id, kind: "id" };
|
|
109
|
-
}),
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
async function claudeCatalog(inputs: LiveCatalogInputs): Promise<Lookup> {
|
|
114
|
-
if (!inputs.refresh) {
|
|
115
|
-
const cached = readCache(inputs.home, ANTHROPIC_CACHE_KEY, ANTHROPIC_CACHE_TTL, inputs.now());
|
|
116
|
-
if (cached !== undefined) {
|
|
117
|
-
const catalog = cachedClaudeCatalog(cached);
|
|
118
|
-
if (catalog !== undefined) return catalog;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
let credentialsText: string;
|
|
123
|
-
try {
|
|
124
|
-
credentialsText = readFileSync(p(inputs.home, ".claude", ".credentials.json"), "utf8");
|
|
125
|
-
} catch {
|
|
126
|
-
return { fallbackReason: NO_CLAUDE_LOGIN };
|
|
127
|
-
}
|
|
128
|
-
const credentials = parseJson(credentialsText);
|
|
129
|
-
const oauth =
|
|
130
|
-
credentials !== undefined && isObject(credentials) ? credentials["claudeAiOauth"] : undefined;
|
|
131
|
-
if (oauth === undefined || !isObject(oauth)) return { fallbackReason: NO_CLAUDE_LOGIN };
|
|
132
|
-
const token = oauth["accessToken"];
|
|
133
|
-
const expiresAt = oauth["expiresAt"];
|
|
134
|
-
if (!isNonBlankString(token) || typeof expiresAt !== "number" || !Number.isFinite(expiresAt)) {
|
|
135
|
-
return { fallbackReason: NO_CLAUDE_LOGIN };
|
|
136
|
-
}
|
|
137
|
-
if (expiresAt <= inputs.now()) {
|
|
138
|
-
return { fallbackReason: "Claude Code login expired; start claude once to refresh it" };
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const models: Array<LiveModel> = [];
|
|
142
|
-
let afterId: string | undefined;
|
|
143
|
-
try {
|
|
144
|
-
for (;;) {
|
|
145
|
-
const url = `https://api.anthropic.com/v1/models?limit=1000${afterId === undefined ? "" : `&after_id=${encodeURIComponent(afterId)}`}`;
|
|
146
|
-
const response = await inputs.fetch(url, {
|
|
147
|
-
method: "GET",
|
|
148
|
-
headers: {
|
|
149
|
-
Authorization: `Bearer ${token}`,
|
|
150
|
-
"anthropic-version": "2023-06-01",
|
|
151
|
-
"anthropic-beta": "oauth-2025-04-20",
|
|
152
|
-
},
|
|
153
|
-
signal: AbortSignal.timeout(5000),
|
|
154
|
-
});
|
|
155
|
-
if (response.status !== 200) {
|
|
156
|
-
return { fallbackReason: `Anthropic API returned HTTP ${response.status}` };
|
|
157
|
-
}
|
|
158
|
-
const page: unknown = await response.json();
|
|
159
|
-
if (typeof page !== "object" || page === null || Array.isArray(page)) {
|
|
160
|
-
throw new Error("invalid response");
|
|
161
|
-
}
|
|
162
|
-
if (
|
|
163
|
-
!("data" in page) ||
|
|
164
|
-
!Array.isArray(page.data) ||
|
|
165
|
-
!("has_more" in page) ||
|
|
166
|
-
typeof page.has_more !== "boolean"
|
|
167
|
-
) {
|
|
168
|
-
throw new Error("invalid response");
|
|
169
|
-
}
|
|
170
|
-
for (const row of page.data) {
|
|
171
|
-
if (typeof row !== "object" || row === null || Array.isArray(row) || !("id" in row))
|
|
172
|
-
continue;
|
|
173
|
-
const id = row.id;
|
|
174
|
-
if (!isNonBlankString(id)) continue;
|
|
175
|
-
const name = "display_name" in row ? row.display_name : undefined;
|
|
176
|
-
models.push(isNonBlankString(name) ? { id, kind: "id", note: name } : { id, kind: "id" });
|
|
177
|
-
}
|
|
178
|
-
if (!page.has_more) break;
|
|
179
|
-
const lastId = "last_id" in page ? page.last_id : undefined;
|
|
180
|
-
if (!isNonBlankString(lastId) || lastId === afterId) throw new Error("invalid response");
|
|
181
|
-
afterId = lastId;
|
|
182
|
-
}
|
|
183
|
-
} catch (error) {
|
|
184
|
-
return {
|
|
185
|
-
fallbackReason: `Anthropic API unreachable: ${error instanceof Error ? error.message : String(error)}`,
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// An empty list would drop every curated id; never cache it.
|
|
190
|
-
if (models.length === 0) return { fallbackReason: "Anthropic API returned no models" };
|
|
191
|
-
const fetched = inputs.now();
|
|
192
|
-
const fetchedAt = new Date(fetched).toISOString();
|
|
193
|
-
writeCache(
|
|
194
|
-
inputs.home,
|
|
195
|
-
ANTHROPIC_CACHE_KEY,
|
|
196
|
-
JSON.stringify({
|
|
197
|
-
fetchedAt,
|
|
198
|
-
ids: models.map((model) => model.id),
|
|
199
|
-
displayNames: models.map((model) => model.note ?? null),
|
|
200
|
-
}),
|
|
201
|
-
fetched,
|
|
202
|
-
);
|
|
203
|
-
return { source: "anthropic-api", fetchedAt, models };
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const NO_CODEX_CACHE = "no Codex model cache (~/.codex/models_cache.json); run codex once";
|
|
207
|
-
const UNREADABLE_CODEX_CACHE = "Codex model cache is unreadable";
|
|
208
|
-
|
|
209
|
-
function codexCatalog(home: string): Lookup {
|
|
210
|
-
let text: string;
|
|
211
|
-
try {
|
|
212
|
-
text = readFileSync(p(codexHome(home), "models_cache.json"), "utf8");
|
|
213
|
-
} catch (error) {
|
|
214
|
-
const missing =
|
|
215
|
-
typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
216
|
-
return { fallbackReason: missing ? NO_CODEX_CACHE : UNREADABLE_CODEX_CACHE };
|
|
217
|
-
}
|
|
218
|
-
const cache = parseJson(text);
|
|
219
|
-
if (cache === undefined || !isObject(cache) || !Array.isArray(cache["models"])) {
|
|
220
|
-
return { fallbackReason: UNREADABLE_CODEX_CACHE };
|
|
221
|
-
}
|
|
222
|
-
const models: Array<LiveModel> = [];
|
|
223
|
-
for (const row of cache["models"]) {
|
|
224
|
-
if (!isObject(row) || row["visibility"] !== "list") continue;
|
|
225
|
-
const id = row["slug"];
|
|
226
|
-
if (!isNonBlankString(id)) continue;
|
|
227
|
-
const name = row["display_name"];
|
|
228
|
-
models.push(isNonBlankString(name) ? { id, kind: "id", note: name } : { id, kind: "id" });
|
|
229
|
-
}
|
|
230
|
-
if (models.length === 0) return { fallbackReason: "Codex model cache lists no models" };
|
|
231
|
-
const fetchedAt = cache["fetched_at"];
|
|
232
|
-
return {
|
|
233
|
-
source: "codex-cache",
|
|
234
|
-
...(typeof fetchedAt === "string" ? { fetchedAt } : {}),
|
|
235
|
-
models,
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const NO_OMP_CATALOG = "'omp models --json' returned no usable catalog";
|
|
240
|
-
|
|
241
|
-
async function ompCatalog(inputs: LiveCatalogInputs): Promise<Lookup> {
|
|
242
|
-
const omp = inputs.which("omp");
|
|
243
|
-
if (omp === "") return { fallbackReason: "omp not found on PATH" };
|
|
244
|
-
let raw: string;
|
|
245
|
-
try {
|
|
246
|
-
raw = await inputs.capture(omp, ["models", "--json"]);
|
|
247
|
-
} catch {
|
|
248
|
-
return { fallbackReason: NO_OMP_CATALOG };
|
|
249
|
-
}
|
|
250
|
-
const catalog = parseJson(raw);
|
|
251
|
-
if (catalog === undefined || !isObject(catalog) || !Array.isArray(catalog["models"])) {
|
|
252
|
-
return { fallbackReason: NO_OMP_CATALOG };
|
|
253
|
-
}
|
|
254
|
-
const models: Array<LiveModel> = [];
|
|
255
|
-
for (const row of catalog["models"]) {
|
|
256
|
-
if (!isObject(row) || row["kind"] !== "chat") continue;
|
|
257
|
-
const id = row["selector"];
|
|
258
|
-
if (!isNonBlankString(id)) continue;
|
|
259
|
-
const name = row["name"];
|
|
260
|
-
models.push(isNonBlankString(name) ? { id, kind: "id", note: name } : { id, kind: "id" });
|
|
261
|
-
}
|
|
262
|
-
if (models.length === 0) return { fallbackReason: NO_OMP_CATALOG };
|
|
263
|
-
return { source: "omp-cli", fetchedAt: new Date(inputs.now()).toISOString(), models };
|
|
264
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Model-catalog helpers: SoT parsing, listing, and Claude/Codex model validation.
|
|
3
|
-
* Curated message strings are covered by the golden suites.
|
|
4
|
-
*/
|
|
5
|
-
import { codexHome } from "./codexPaths";
|
|
6
|
-
import { p } from "./exec";
|
|
7
|
-
import type { Ctx } from "./index";
|
|
8
|
-
import { isObject, parseJson } from "./jq";
|
|
9
|
-
import { payloadDisplayPath, payloadText } from "../payload";
|
|
10
|
-
import type { CatalogSource, JsonObject, ResolvedCatalog } from "./sharedTypes";
|
|
11
|
-
|
|
12
|
-
export type ModelEntry = ResolvedCatalog["models"][number];
|
|
13
|
-
|
|
14
|
-
export interface ModelCatalog {
|
|
15
|
-
readonly verified: string;
|
|
16
|
-
readonly models: ReadonlyArray<ModelEntry>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const LIVE_SOURCE_LABELS: Record<Exclude<CatalogSource, "curated">, string> = {
|
|
20
|
-
"anthropic-api": "Anthropic API via Claude Code login",
|
|
21
|
-
"codex-cache": "models_cache.json in the Codex home",
|
|
22
|
-
"omp-cli": "omp models --json",
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
function toolEntry(tool: string): JsonObject | undefined {
|
|
26
|
-
const doc = parseJson(payloadText("SoT/models.json"));
|
|
27
|
-
if (doc === undefined || !isObject(doc)) return undefined;
|
|
28
|
-
const entry = doc[tool];
|
|
29
|
-
return entry !== undefined && isObject(entry) ? entry : undefined;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function modelEntries(entry: JsonObject | undefined): Array<JsonObject> {
|
|
33
|
-
const models = entry?.["models"];
|
|
34
|
-
return Array.isArray(models) ? models.filter(isObject) : [];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Typed view of one tool's `SoT/models.json` section. An entry whose `id` is not a
|
|
39
|
-
* string or whose `kind` is neither `alias` nor `id` is skipped; a missing section
|
|
40
|
-
* yields `verified: "?"` and no models.
|
|
41
|
-
*/
|
|
42
|
-
export function modelCatalog(tool: string): ModelCatalog {
|
|
43
|
-
const entry = toolEntry(tool);
|
|
44
|
-
const verified = entry?.["verified"];
|
|
45
|
-
const models: Array<ModelEntry> = [];
|
|
46
|
-
for (const m of modelEntries(entry)) {
|
|
47
|
-
const id = m["id"];
|
|
48
|
-
const kind = m["kind"];
|
|
49
|
-
if (typeof id !== "string" || (kind !== "alias" && kind !== "id")) continue;
|
|
50
|
-
const note = m["note"];
|
|
51
|
-
models.push(typeof note === "string" ? { id, kind, note } : { id, kind });
|
|
52
|
-
}
|
|
53
|
-
return { verified: typeof verified === "string" ? verified : "?", models };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function printModels(ctx: Ctx, catalog: ResolvedCatalog): void {
|
|
57
|
-
const { echo, warn } = ctx.services.logger;
|
|
58
|
-
const { tool, models, source, verified, fetchedAt } = catalog;
|
|
59
|
-
if (source === "curated" && models.length === 0) {
|
|
60
|
-
warn(`Model catalog unavailable (${payloadDisplayPath("SoT/models.json")})`);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
const header =
|
|
64
|
-
source === "curated"
|
|
65
|
-
? `Available ${tool} models (kit-verified ${verified} — SoT/models.json):`
|
|
66
|
-
: `Available ${tool} models (live — ${LIVE_SOURCE_LABELS[source]}, fetched ${fetchedAt ?? "?"}; aliases and notes from SoT/models.json):`;
|
|
67
|
-
echo(header);
|
|
68
|
-
for (const model of models) {
|
|
69
|
-
echo(` ${model.id}${model.note === undefined ? "" : ` — ${model.note}`}`);
|
|
70
|
-
}
|
|
71
|
-
if (tool === "claude")
|
|
72
|
-
echo(" (full claude-* model IDs outside the catalog are accepted with a warning)");
|
|
73
|
-
if (tool === "codex") echo(" (well-formed IDs outside the catalog are accepted with a warning)");
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function validateClaudeModel(ctx: Ctx, m: string, catalog: ResolvedCatalog): boolean {
|
|
77
|
-
if (m === "") return false;
|
|
78
|
-
if (catalog.models.some((entry) => entry.id === m)) return true;
|
|
79
|
-
if (m.startsWith("claude-")) {
|
|
80
|
-
ctx.services.logger.warn(
|
|
81
|
-
catalog.source === "curated"
|
|
82
|
-
? `Claude model '${m}' is not in the kit-verified catalog (SoT/models.json) — applying anyway`
|
|
83
|
-
: `Claude model '${m}' is not in the live Anthropic model list — applying anyway`,
|
|
84
|
-
);
|
|
85
|
-
return true;
|
|
86
|
-
}
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function validateCodexModel(ctx: Ctx, m: string, catalog: ResolvedCatalog): boolean {
|
|
91
|
-
if (!/^[A-Za-z0-9._-]+$/.test(m)) return false;
|
|
92
|
-
if (!catalog.models.some((entry) => entry.id === m)) {
|
|
93
|
-
const config = p(codexHome(ctx.home), "config.toml");
|
|
94
|
-
ctx.services.logger.warn(
|
|
95
|
-
catalog.source === "curated"
|
|
96
|
-
? `Codex model '${m}' is not in the kit-verified catalog (SoT/models.json) — applying anyway (check ${config} if Codex rejects it)`
|
|
97
|
-
: `Codex model '${m}' is not in the live Codex model list — applying anyway (check ${config} if Codex rejects it)`,
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
return true;
|
|
101
|
-
}
|