docks-kit 0.22.25 → 0.23.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 +35 -81
- package/README.md +31 -58
- package/cli/docs/command-guards.md +231 -197
- package/cli/docs/flags.md +25 -55
- package/cli/docs/install.md +2 -3
- package/cli/docs/omp-context.md +5 -5
- package/cli/docs/omp-models.md +249 -48
- package/cli/docs/overview.md +4 -12
- package/cli/docs/platforms.md +2 -2
- package/cli/docs/sync-layers.md +10 -57
- package/cli/docs/toolchain.md +9 -78
- package/cli/src/argv.ts +0 -8
- package/cli/src/argvValidate.ts +2 -46
- package/cli/src/commands/docs.ts +2 -14
- package/cli/src/commands/harnesses.ts +6 -9
- package/cli/src/commands/sync.ts +5 -99
- package/cli/src/commands/toolchain.ts +4 -12
- package/cli/src/engine-native/DESIGN.md +67 -88
- package/cli/src/engine-native/deps.ts +6 -86
- package/cli/src/engine-native/engineCtx.ts +7 -76
- package/cli/src/engine-native/exec.ts +1 -18
- package/cli/src/engine-native/harnesses.ts +6 -6
- package/cli/src/engine-native/index.ts +4 -6
- package/cli/src/engine-native/jq.ts +4 -37
- package/cli/src/engine-native/modes.ts +3 -132
- package/cli/src/engine-native/ompRemovals.ts +14 -0
- 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 -46
- package/cli/src/engine-native/os/types.ts +1 -32
- package/cli/src/engine-native/os/windows.ts +0 -49
- package/cli/src/engine-native/parseArgs.ts +11 -124
- package/cli/src/engine-native/parseHelp.ts +5 -40
- 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 +0 -40
- package/cli/src/engine-native/skillsSync.ts +1 -1
- package/cli/src/engine-native/syncConcurrency.ts +3 -15
- package/cli/src/engine-native/syncDispatch.ts +10 -57
- package/cli/src/engine-native/toolchain.ts +5 -40
- package/cli/src/engine.ts +0 -75
- package/cli/src/generated/sotPayload.ts +14 -41
- package/cli/src/main.ts +7 -19
- package/cli/src/manifests.ts +1 -93
- 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/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/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/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/tomlLines.ts +0 -92
|
@@ -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
|
-
}
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Modifier and effort mapping for the EngineNative flag layer: deploy-time
|
|
3
|
-
* modifier metadata, scalar-modifier setters, compact-window and opt-in
|
|
4
|
-
* plugin parsing, and post-parse modifier validation. Pure apart from the
|
|
5
|
-
* injected ctx seam; help output and the early-exit error come from
|
|
6
|
-
* parseHelp.ts.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { Ctx, ModifierFlag } from "./index";
|
|
10
|
-
import type { ScalarModifierFlag } from "./sharedTypes";
|
|
11
|
-
import {
|
|
12
|
-
CLAUDE_ADVISOR_STATES,
|
|
13
|
-
advisorCatalog,
|
|
14
|
-
advisorValueGrammar,
|
|
15
|
-
effortCatalog,
|
|
16
|
-
effortValueGrammar,
|
|
17
|
-
isEffortModifierValue,
|
|
18
|
-
} from "../efforts";
|
|
19
|
-
import { printModels, validateClaudeModel, validateCodexModel } from "./models";
|
|
20
|
-
import { defaultLiveInputs, resolveCatalog } from "./liveModels";
|
|
21
|
-
import { ExitError, printCatalog } from "./parseHelp";
|
|
22
|
-
|
|
23
|
-
export const KNOWN_CLAUDE_OPTIN_PLUGINS = ["supabase", "n8n"];
|
|
24
|
-
|
|
25
|
-
interface ModifierMetadata {
|
|
26
|
-
readonly target: "claude" | "codex";
|
|
27
|
-
readonly ignoredWarning: string;
|
|
28
|
-
readonly hasValue: (ctx: Ctx) => boolean;
|
|
29
|
-
readonly clear: (ctx: Ctx) => void;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const MODIFIER_METADATA = {
|
|
33
|
-
"--claude-model": {
|
|
34
|
-
target: "claude",
|
|
35
|
-
ignoredWarning: "--claude-model ignored: claude target not selected",
|
|
36
|
-
hasValue: (ctx) => ctx.claudeModel !== "",
|
|
37
|
-
clear: (ctx) => {
|
|
38
|
-
ctx.claudeModel = "";
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
"--claude-effort": {
|
|
42
|
-
target: "claude",
|
|
43
|
-
ignoredWarning: "--claude-effort ignored: claude target not selected",
|
|
44
|
-
hasValue: (ctx) => ctx.claudeEffort !== "",
|
|
45
|
-
clear: (ctx) => {
|
|
46
|
-
ctx.claudeEffort = "";
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
"--claude-advisor": {
|
|
50
|
-
target: "claude",
|
|
51
|
-
ignoredWarning: "--claude-advisor ignored: claude target not selected",
|
|
52
|
-
hasValue: (ctx) => ctx.claudeAdvisor !== "",
|
|
53
|
-
clear: (ctx) => {
|
|
54
|
-
ctx.claudeAdvisor = "";
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
"--claude-compact-window": {
|
|
58
|
-
target: "claude",
|
|
59
|
-
ignoredWarning: "--claude-compact-window ignored: claude target not selected",
|
|
60
|
-
hasValue: (ctx) => ctx.claudeCompactWindow !== "",
|
|
61
|
-
clear: (ctx) => {
|
|
62
|
-
ctx.claudeCompactWindow = "";
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
"--claude-permissive": {
|
|
66
|
-
target: "claude",
|
|
67
|
-
ignoredWarning: "--claude-permissive ignored: claude target not selected",
|
|
68
|
-
hasValue: (ctx) => ctx.claudePermissive,
|
|
69
|
-
clear: (ctx) => {
|
|
70
|
-
ctx.claudePermissive = false;
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
"--claude-plugin": {
|
|
74
|
-
target: "claude",
|
|
75
|
-
ignoredWarning: "--claude-plugin ignored: claude target not selected",
|
|
76
|
-
hasValue: (ctx) => ctx.claudePlugins.length > 0,
|
|
77
|
-
clear: (ctx) => {
|
|
78
|
-
ctx.claudePlugins = [];
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
"--codex-model": {
|
|
82
|
-
target: "codex",
|
|
83
|
-
ignoredWarning: "--codex-model ignored: codex target not selected",
|
|
84
|
-
hasValue: (ctx) => ctx.codexModel !== "",
|
|
85
|
-
clear: (ctx) => {
|
|
86
|
-
ctx.codexModel = "";
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
"--codex-effort": {
|
|
90
|
-
target: "codex",
|
|
91
|
-
ignoredWarning: "--codex-effort ignored: codex target not selected",
|
|
92
|
-
hasValue: (ctx) => ctx.codexEffort !== "",
|
|
93
|
-
clear: (ctx) => {
|
|
94
|
-
ctx.codexEffort = "";
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
} satisfies Record<ModifierFlag, ModifierMetadata>;
|
|
98
|
-
|
|
99
|
-
export type { ScalarModifierFlag };
|
|
100
|
-
|
|
101
|
-
const SCALAR_MODIFIER_FLAGS: Record<ScalarModifierFlag, true> = {
|
|
102
|
-
"--claude-model": true,
|
|
103
|
-
"--claude-effort": true,
|
|
104
|
-
"--claude-advisor": true,
|
|
105
|
-
"--codex-model": true,
|
|
106
|
-
"--codex-effort": true,
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
/** common::parse_compact_window — normalized tokens or undefined on junk. */
|
|
110
|
-
export function parseCompactWindow(v: string): string | undefined {
|
|
111
|
-
if (/[kK]$/.test(v)) {
|
|
112
|
-
const n = v.slice(0, -1);
|
|
113
|
-
if (!/^[0-9]+$/.test(n)) return undefined;
|
|
114
|
-
return String(parseInt(n, 10) * 1000);
|
|
115
|
-
}
|
|
116
|
-
return /^[0-9]+$/.test(v) ? v : undefined;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export function parseClaudePlugin(name: string, err: (message: string) => void): string {
|
|
120
|
-
if (!KNOWN_CLAUDE_OPTIN_PLUGINS.includes(name)) {
|
|
121
|
-
err(`Unknown opt-in plugin '${name}'. Known: ${KNOWN_CLAUDE_OPTIN_PLUGINS.join(", ")}`);
|
|
122
|
-
throw new ExitError(2);
|
|
123
|
-
}
|
|
124
|
-
return name;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function markModifier(ctx: Ctx, flag: ModifierFlag): void {
|
|
128
|
-
const flags = ctx.modifierFlags ?? new Set<ModifierFlag>();
|
|
129
|
-
flags.add(flag);
|
|
130
|
-
ctx.modifierFlags = flags;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export function addClaudePlugin(ctx: Ctx, name: string): void {
|
|
134
|
-
if (name === "") {
|
|
135
|
-
printCatalog(
|
|
136
|
-
ctx,
|
|
137
|
-
`Available Claude optional plugins:\n${KNOWN_CLAUDE_OPTIN_PLUGINS.map((plugin) => ` ${plugin}`).join("\n")}`,
|
|
138
|
-
);
|
|
139
|
-
ctx.services.logger.err(
|
|
140
|
-
`Invalid Claude plugin '' — valid: ${KNOWN_CLAUDE_OPTIN_PLUGINS.join("|")}`,
|
|
141
|
-
);
|
|
142
|
-
throw new ExitError(2);
|
|
143
|
-
}
|
|
144
|
-
ctx.claudePlugins.push(parseClaudePlugin(name, ctx.services.logger.err));
|
|
145
|
-
markModifier(ctx, "--claude-plugin");
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export function setModifier(ctx: Ctx, flag: ScalarModifierFlag, value: string): void {
|
|
149
|
-
switch (flag) {
|
|
150
|
-
case "--claude-model":
|
|
151
|
-
ctx.claudeModel = value;
|
|
152
|
-
break;
|
|
153
|
-
case "--claude-effort":
|
|
154
|
-
ctx.claudeEffort = value;
|
|
155
|
-
break;
|
|
156
|
-
case "--claude-advisor":
|
|
157
|
-
ctx.claudeAdvisor = value;
|
|
158
|
-
break;
|
|
159
|
-
case "--codex-model":
|
|
160
|
-
ctx.codexModel = value;
|
|
161
|
-
break;
|
|
162
|
-
case "--codex-effort":
|
|
163
|
-
ctx.codexEffort = value;
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
markModifier(ctx, flag);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export function isScalarModifierFlag(value: string): value is ScalarModifierFlag {
|
|
170
|
-
return SCALAR_MODIFIER_FLAGS[value as ScalarModifierFlag] === true;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export async function validateModifierFlags(ctx: Ctx): Promise<void> {
|
|
174
|
-
const { err, warn } = ctx.services.logger;
|
|
175
|
-
const supplied = (flag: ModifierFlag): boolean =>
|
|
176
|
-
MODIFIER_METADATA[flag].hasValue(ctx) || ctx.modifierFlags?.has(flag) === true;
|
|
177
|
-
|
|
178
|
-
for (const flag of Object.keys(MODIFIER_METADATA) as Array<ModifierFlag>) {
|
|
179
|
-
const metadata = MODIFIER_METADATA[flag];
|
|
180
|
-
const targetSelected = metadata.target === "claude" ? ctx.syncClaude : ctx.syncCodex;
|
|
181
|
-
if (!targetSelected && supplied(flag)) {
|
|
182
|
-
warn(metadata.ignoredWarning);
|
|
183
|
-
metadata.clear(ctx);
|
|
184
|
-
ctx.modifierFlags?.delete(flag);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (supplied("--claude-model")) {
|
|
189
|
-
const catalog = await resolveCatalog("claude", defaultLiveInputs(ctx.home));
|
|
190
|
-
if (!validateClaudeModel(ctx, ctx.claudeModel, catalog)) {
|
|
191
|
-
printModels(ctx, catalog);
|
|
192
|
-
err(`Invalid Claude model '${ctx.claudeModel}' — use an alias above or a full claude-* ID`);
|
|
193
|
-
throw new ExitError(2);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
if (supplied("--claude-effort")) {
|
|
197
|
-
if (!isEffortModifierValue("claude", ctx.claudeEffort)) {
|
|
198
|
-
printCatalog(ctx, effortCatalog("claude"));
|
|
199
|
-
err(`Invalid Claude effort '${ctx.claudeEffort}' — valid: ${effortValueGrammar("claude")}`);
|
|
200
|
-
throw new ExitError(2);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
if (supplied("--claude-advisor")) {
|
|
204
|
-
if (!CLAUDE_ADVISOR_STATES.some((state) => state === ctx.claudeAdvisor)) {
|
|
205
|
-
printCatalog(ctx, advisorCatalog());
|
|
206
|
-
err(`Invalid Claude advisor state '${ctx.claudeAdvisor}' — valid: ${advisorValueGrammar()}`);
|
|
207
|
-
throw new ExitError(2);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
if (supplied("--codex-model")) {
|
|
211
|
-
const catalog = await resolveCatalog("codex", defaultLiveInputs(ctx.home));
|
|
212
|
-
if (!validateCodexModel(ctx, ctx.codexModel, catalog)) {
|
|
213
|
-
printModels(ctx, catalog);
|
|
214
|
-
err(`Invalid Codex model '${ctx.codexModel}' — must match ^[A-Za-z0-9._-]+$`);
|
|
215
|
-
throw new ExitError(2);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
if (supplied("--codex-effort")) {
|
|
219
|
-
if (!isEffortModifierValue("codex", ctx.codexEffort)) {
|
|
220
|
-
printCatalog(ctx, effortCatalog("codex"));
|
|
221
|
-
err(`Invalid Codex effort '${ctx.codexEffort}' — valid: ${effortValueGrammar("codex")}`);
|
|
222
|
-
throw new ExitError(2);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `~/.claude/settings.json` merge helpers. Pure functions take the two parsed
|
|
3
|
-
* documents and return the merged document; the FS step (backup, tmp+rename,
|
|
4
|
-
* log line) lives in the sync orchestrator. jq-oracle equivalence is covered by
|
|
5
|
-
* cli/test/unit/settings.test.ts and deployed behavior by the golden suites.
|
|
6
|
-
*/
|
|
7
|
-
import { deepMerge, isObject, uniqueStrings, type Json } from "./jq";
|
|
8
|
-
|
|
9
|
-
/** `$user * $repo` — SoT keys win, permissions arrays replaced wholesale. */
|
|
10
|
-
export function reconcileSettings(repo: Json, user: Json): Json {
|
|
11
|
-
return deepMerge(user, repo);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* `($user * $repo)` + permissions.{allow,deny,ask} unioned (user + repo,
|
|
16
|
-
* `unique` — i.e. codepoint-sorted and deduplicated, matching jq).
|
|
17
|
-
*/
|
|
18
|
-
export function mergeSettings(repo: Json, user: Json): Json {
|
|
19
|
-
const candidate = deepMerge(user, repo);
|
|
20
|
-
if (!isObject(candidate)) return candidate;
|
|
21
|
-
const merged = { ...candidate };
|
|
22
|
-
const permissions = isObject(merged["permissions"]) ? merged["permissions"] : {};
|
|
23
|
-
merged["permissions"] = {
|
|
24
|
-
...permissions,
|
|
25
|
-
allow: unionPermissions(user, repo, "allow"),
|
|
26
|
-
deny: unionPermissions(user, repo, "deny"),
|
|
27
|
-
ask: unionPermissions(user, repo, "ask"),
|
|
28
|
-
};
|
|
29
|
-
return merged;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function unionPermissions(user: Json, repo: Json, key: string): Array<string> {
|
|
33
|
-
return uniqueStrings([...permissionArray(user, key), ...permissionArray(repo, key)]);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function permissionArray(doc: Json, key: string): Array<string> {
|
|
37
|
-
if (!isObject(doc)) return [];
|
|
38
|
-
const permissions = doc["permissions"];
|
|
39
|
-
if (!isObject(permissions)) return [];
|
|
40
|
-
const arr = permissions[key];
|
|
41
|
-
return Array.isArray(arr) ? arr.filter((x): x is string => typeof x === "string") : [];
|
|
42
|
-
}
|