docks-kit 0.22.28 → 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 +31 -77
- 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-models.md +9 -0
- 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/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 +12 -39
- 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
|
@@ -8,20 +8,9 @@ import { engineHome } from "./harnesses";
|
|
|
8
8
|
import type { TerminalLease } from "./logger";
|
|
9
9
|
import type { BunRuntimeState } from "./bun";
|
|
10
10
|
import { kitHome } from "../kitHome";
|
|
11
|
-
import { ExitError, parseClaudePlugin, parseCompactWindow } from "./parseArgs";
|
|
12
11
|
import type { EngineServices } from "./services";
|
|
13
12
|
import type { SyncConcurrency } from "./syncConcurrency";
|
|
14
13
|
|
|
15
|
-
export type ModifierFlag =
|
|
16
|
-
| "--claude-model"
|
|
17
|
-
| "--claude-effort"
|
|
18
|
-
| "--claude-advisor"
|
|
19
|
-
| "--claude-compact-window"
|
|
20
|
-
| "--claude-permissive"
|
|
21
|
-
| "--claude-plugin"
|
|
22
|
-
| "--codex-model"
|
|
23
|
-
| "--codex-effort";
|
|
24
|
-
|
|
25
14
|
export interface Ctx {
|
|
26
15
|
readonly repoDir: string;
|
|
27
16
|
readonly home: string;
|
|
@@ -29,35 +18,18 @@ export interface Ctx {
|
|
|
29
18
|
readonly interactive: boolean;
|
|
30
19
|
dryRun: boolean;
|
|
31
20
|
verbose: boolean;
|
|
32
|
-
skipBubblewrap: boolean;
|
|
33
21
|
skipPluginRefresh?: boolean;
|
|
34
|
-
reconcile: boolean;
|
|
35
22
|
prune: boolean;
|
|
36
|
-
claudeCompactWindow: string;
|
|
37
|
-
claudePermissive: boolean;
|
|
38
|
-
claudePlugins: Array<string>;
|
|
39
|
-
claudeModel: string;
|
|
40
|
-
claudeEffort: string;
|
|
41
|
-
claudeAdvisor: string;
|
|
42
|
-
codexModel: string;
|
|
43
|
-
codexEffort: string;
|
|
44
|
-
/** Distinguishes an explicitly empty modifier from an option that was not supplied. */
|
|
45
|
-
modifierFlags?: Set<ModifierFlag>;
|
|
46
23
|
/** Injected capability seam (logger/deps/platform) — see services.ts. */
|
|
47
24
|
readonly services: EngineServices;
|
|
48
25
|
syncConcurrency: SyncConcurrency;
|
|
49
26
|
terminalLease?: TerminalLease;
|
|
50
27
|
bunRuntime?: Promise<BunRuntimeState>;
|
|
51
28
|
targetFilterSet: boolean;
|
|
52
|
-
syncClaude: boolean;
|
|
53
|
-
syncCodex: boolean;
|
|
54
29
|
syncAgents: boolean;
|
|
55
30
|
syncOmp: boolean;
|
|
56
31
|
/** Per-run next-step triggers (Output Policy): advice prints only when its trigger changed or --verbose. */
|
|
57
32
|
readonly nextStepTriggers: {
|
|
58
|
-
claudePlugins: boolean;
|
|
59
|
-
claudeRestart: boolean;
|
|
60
|
-
codexRestart: boolean;
|
|
61
33
|
skillsRestart: boolean;
|
|
62
34
|
ompRestart: boolean;
|
|
63
35
|
/** A marketplace plugin upgrade changed a version, so running omp sessions lost its folder. */
|
|
@@ -67,49 +39,24 @@ export interface Ctx {
|
|
|
67
39
|
readonly failures: Array<string>;
|
|
68
40
|
}
|
|
69
41
|
|
|
70
|
-
/**
|
|
71
|
-
* Unprefixed env globals that seed `Ctx` with the historical ${VAR:-default}
|
|
72
|
-
* contract. Only the harness-private native-raw channel honors them; the
|
|
73
|
-
* public CLI takes the same behavior from flags.
|
|
74
|
-
*/
|
|
75
|
-
export const ENV_GLOBAL_KEYS = [
|
|
76
|
-
"DRY_RUN",
|
|
77
|
-
"DOCKS_KIT_VERBOSE",
|
|
78
|
-
"SKIP_BUBBLEWRAP",
|
|
79
|
-
"RECONCILE",
|
|
80
|
-
"PRUNE",
|
|
81
|
-
"CLAUDE_PERMISSIVE",
|
|
82
|
-
"CLAUDE_MODEL",
|
|
83
|
-
"CODEX_MODEL",
|
|
84
|
-
"CLAUDE_PLUGINS",
|
|
85
|
-
"CLAUDE_COMPACT_WINDOW",
|
|
86
|
-
"AGENTS_DIR",
|
|
87
|
-
] as const;
|
|
88
|
-
|
|
89
42
|
export interface CtxOptions {
|
|
90
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* True only on the harness-private native-raw channel: seed `Ctx` from the
|
|
45
|
+
* unprefixed env globals DRY_RUN, DOCKS_KIT_VERBOSE, PRUNE, and AGENTS_DIR
|
|
46
|
+
* (the historical ${VAR:-default} contract). The public CLI takes the same
|
|
47
|
+
* behavior from flags.
|
|
48
|
+
*/
|
|
91
49
|
readonly envGlobals: boolean;
|
|
92
50
|
}
|
|
93
51
|
|
|
94
52
|
/**
|
|
95
53
|
* Build the run context. HOME and DOCKS_KIT_INTERACTIVE apply on every path;
|
|
96
|
-
*
|
|
54
|
+
* the env globals apply only when `options.envGlobals` is true.
|
|
97
55
|
*/
|
|
98
56
|
export function makeCtx(services: EngineServices, options: CtxOptions): Ctx {
|
|
99
57
|
const env = process.env;
|
|
100
58
|
const home = engineHome(env);
|
|
101
59
|
const globals: NodeJS.ProcessEnv = options.envGlobals ? env : {};
|
|
102
|
-
const compactWindowSource = globals["CLAUDE_COMPACT_WINDOW"] ?? "";
|
|
103
|
-
const claudeCompactWindow =
|
|
104
|
-
compactWindowSource === "" ? "" : parseCompactWindow(compactWindowSource);
|
|
105
|
-
if (claudeCompactWindow === undefined) {
|
|
106
|
-
services.logger.err("CLAUDE_COMPACT_WINDOW expects a token count (e.g. 680000 or 680k)");
|
|
107
|
-
throw new ExitError(2);
|
|
108
|
-
}
|
|
109
|
-
const claudePlugins = (globals["CLAUDE_PLUGINS"] ?? "")
|
|
110
|
-
.split(" ")
|
|
111
|
-
.filter((plugin) => plugin !== "")
|
|
112
|
-
.map((plugin) => parseClaudePlugin(plugin, services.logger.err));
|
|
113
60
|
return {
|
|
114
61
|
repoDir: kitHome(),
|
|
115
62
|
home,
|
|
@@ -124,30 +71,14 @@ export function makeCtx(services: EngineServices, options: CtxOptions): Ctx {
|
|
|
124
71
|
process.stdin.isTTY === true),
|
|
125
72
|
dryRun: globals["DRY_RUN"] === "1",
|
|
126
73
|
verbose: globals["DOCKS_KIT_VERBOSE"] === "1",
|
|
127
|
-
skipBubblewrap: globals["SKIP_BUBBLEWRAP"] === "1",
|
|
128
74
|
skipPluginRefresh: false,
|
|
129
|
-
reconcile: globals["RECONCILE"] === "1",
|
|
130
75
|
prune: globals["PRUNE"] === "1",
|
|
131
|
-
claudeCompactWindow,
|
|
132
|
-
claudePermissive: globals["CLAUDE_PERMISSIVE"] === "1",
|
|
133
|
-
claudePlugins,
|
|
134
|
-
claudeModel: globals["CLAUDE_MODEL"] ?? "",
|
|
135
|
-
claudeEffort: "",
|
|
136
|
-
claudeAdvisor: "",
|
|
137
|
-
codexModel: globals["CODEX_MODEL"] ?? "",
|
|
138
|
-
codexEffort: "",
|
|
139
|
-
modifierFlags: new Set(),
|
|
140
76
|
syncConcurrency: 3,
|
|
141
77
|
services,
|
|
142
78
|
targetFilterSet: false,
|
|
143
|
-
syncClaude: false,
|
|
144
|
-
syncCodex: false,
|
|
145
79
|
syncAgents: false,
|
|
146
80
|
syncOmp: false,
|
|
147
81
|
nextStepTriggers: {
|
|
148
|
-
claudePlugins: false,
|
|
149
|
-
claudeRestart: false,
|
|
150
|
-
codexRestart: false,
|
|
151
82
|
skillsRestart: false,
|
|
152
83
|
ompRestart: false,
|
|
153
84
|
ompPluginUpgraded: false,
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
type SpawnSyncOptionsWithStringEncoding,
|
|
13
13
|
type SpawnSyncReturns,
|
|
14
14
|
} from "node:child_process";
|
|
15
|
-
import { accessSync, constants,
|
|
15
|
+
import { accessSync, constants, statSync } from "node:fs";
|
|
16
16
|
import { delimiter, extname, isAbsolute, join } from "node:path";
|
|
17
17
|
import { hostOs, type HostOs, type Invocation } from "./os";
|
|
18
18
|
|
|
@@ -344,20 +344,3 @@ function isExecutable(
|
|
|
344
344
|
return false;
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
|
-
|
|
348
|
-
// Change-detection primitives (Output Policy in DESIGN.md): operations report
|
|
349
|
-
// changed:boolean so unchanged repeat runs log at verbose instead of [ok].
|
|
350
|
-
|
|
351
|
-
/** Write only when the content differs; returns whether a write happened. */
|
|
352
|
-
export function writeTextIfChanged(path: string, content: string): boolean {
|
|
353
|
-
if (existsSync(path) && readFileSync(path, "utf8") === content) return false;
|
|
354
|
-
writeFileSync(path, content);
|
|
355
|
-
return true;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
export function writeBytesIfChanged(path: string, content: Uint8Array): boolean {
|
|
359
|
-
const bytes = Buffer.from(content);
|
|
360
|
-
if (existsSync(path) && readFileSync(path).equals(bytes)) return false;
|
|
361
|
-
writeFileSync(path, bytes);
|
|
362
|
-
return true;
|
|
363
|
-
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Per-machine harness selection and omp session model, stored in ~/.docks-kit/kit.db (kitDb.ts).
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* A missing or unreadable store is represented by undefined so callers
|
|
4
|
+
* resolve it to DEFAULT_SELECTION.
|
|
5
5
|
*/
|
|
6
6
|
import { homedir } from "node:os";
|
|
7
7
|
|
|
8
8
|
import { inTransaction, isNonBlankString, nonBlankOrNull, withKitDb } from "./kitDb";
|
|
9
9
|
import type { OmpSessionModel } from "./sharedTypes";
|
|
10
10
|
|
|
11
|
-
export type Harness = "
|
|
11
|
+
export type Harness = "agents" | "omp";
|
|
12
12
|
|
|
13
|
-
export const HARNESSES: ReadonlyArray<Harness> = ["
|
|
14
|
-
export const
|
|
13
|
+
export const HARNESSES: ReadonlyArray<Harness> = ["agents", "omp"];
|
|
14
|
+
export const DEFAULT_SELECTION: ReadonlyArray<Harness> = ["agents", "omp"];
|
|
15
15
|
|
|
16
16
|
export type { OmpSessionModel };
|
|
17
17
|
|
|
@@ -21,7 +21,7 @@ export const DEFAULT_OMP_SESSION_MODEL: OmpSessionModel = {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
function isHarness(value: unknown): value is Harness {
|
|
24
|
-
return value === "
|
|
24
|
+
return value === "agents" || value === "omp";
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
function normalizeHarnesses(selection: ReadonlyArray<unknown>): Array<Harness> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* EngineNative — the supported sync/
|
|
2
|
+
* EngineNative — the supported sync/toolchain engine.
|
|
3
3
|
*
|
|
4
4
|
* Golden suites drive it through main.ts's harness-private `native-raw`
|
|
5
5
|
* channel, which bypasses effect/cli so tests see the internal argv
|
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
* existing import paths keep working.
|
|
12
12
|
*/
|
|
13
13
|
import { makeCtx, type Ctx } from "./engineCtx";
|
|
14
|
-
import {
|
|
14
|
+
import { modeToolchain } from "./modes";
|
|
15
15
|
import { ExitError } from "./parseArgs";
|
|
16
16
|
import { makeEngineServices, type EngineServices, type Logger } from "./services";
|
|
17
17
|
import { engineSync } from "./syncDispatch";
|
|
18
18
|
|
|
19
|
-
export type { Ctx
|
|
20
|
-
export { runBounded
|
|
19
|
+
export type { Ctx } from "./engineCtx";
|
|
20
|
+
export { runBounded } from "./syncConcurrency";
|
|
21
21
|
export type { SyncConcurrency, SyncTask } from "./syncConcurrency";
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -52,8 +52,6 @@ export async function runEngineNative(
|
|
|
52
52
|
try {
|
|
53
53
|
ctx = makeCtx(runServices, { envGlobals: options.envGlobals === true });
|
|
54
54
|
switch (argv[0]) {
|
|
55
|
-
case "model":
|
|
56
|
-
return await modeModel(ctx, argv.slice(1));
|
|
57
55
|
case "toolchain":
|
|
58
56
|
return await modeToolchain(ctx, argv.slice(1));
|
|
59
57
|
case "sync":
|
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* reproduces three jq behaviors exactly:
|
|
6
|
-
* - `*` (recursive object merge): right side wins; objects merge
|
|
7
|
-
* recursively; arrays and scalars are REPLACED, never concatenated;
|
|
8
|
-
* merged key order = left object's order, then right-only keys appended.
|
|
9
|
-
* - `unique`: sorts (jq's total order — for our string arrays, Unicode
|
|
10
|
-
* codepoint order) and deduplicates.
|
|
11
|
-
* - output formatting: 2-space indent, UTF-8 raw, trailing newline.
|
|
2
|
+
* JSON primitives for EngineNative: the `Json` value type, object narrowing,
|
|
3
|
+
* jq-compatible codepoint ordering, and a parse that yields `undefined`
|
|
4
|
+
* instead of throwing.
|
|
12
5
|
*/
|
|
13
6
|
|
|
14
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
15
7
|
import type { JsonObject } from "./sharedTypes";
|
|
16
8
|
|
|
17
9
|
export type Json = null | boolean | number | string | Array<Json> | { [key: string]: Json };
|
|
@@ -20,22 +12,7 @@ export function isObject(v: Json): v is JsonObject {
|
|
|
20
12
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
21
13
|
}
|
|
22
14
|
|
|
23
|
-
/** jq
|
|
24
|
-
export function deepMerge(left: Json, right: Json): Json {
|
|
25
|
-
if (!isObject(left) || !isObject(right)) return right;
|
|
26
|
-
const out: JsonObject = { ...left };
|
|
27
|
-
for (const [k, v] of Object.entries(right)) {
|
|
28
|
-
const lv = out[k];
|
|
29
|
-
out[k] = lv !== undefined && isObject(lv) && isObject(v) ? deepMerge(lv, v) : v;
|
|
30
|
-
}
|
|
31
|
-
return out;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** jq `unique` over an array of strings: codepoint sort + dedup. */
|
|
35
|
-
export function uniqueStrings(arr: Array<string>): Array<string> {
|
|
36
|
-
return [...new Set(arr)].sort(compareCodepoints);
|
|
37
|
-
}
|
|
38
|
-
|
|
15
|
+
/** jq's string order: compare by Unicode codepoint, not UTF-16 code unit. */
|
|
39
16
|
export function compareCodepoints(a: string, b: string): number {
|
|
40
17
|
const ia = a[Symbol.iterator]();
|
|
41
18
|
const ib = b[Symbol.iterator]();
|
|
@@ -51,11 +28,6 @@ export function compareCodepoints(a: string, b: string): number {
|
|
|
51
28
|
}
|
|
52
29
|
}
|
|
53
30
|
|
|
54
|
-
/** jq's default pretty-printer for the documents this kit writes. */
|
|
55
|
-
export function jqStringify(v: Json): string {
|
|
56
|
-
return `${JSON.stringify(v, null, 2)}\n`;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
31
|
/** jq `empty` validation: parse or null. */
|
|
60
32
|
export function parseJson(text: string): Json | undefined {
|
|
61
33
|
try {
|
|
@@ -64,8 +36,3 @@ export function parseJson(text: string): Json | undefined {
|
|
|
64
36
|
return undefined;
|
|
65
37
|
}
|
|
66
38
|
}
|
|
67
|
-
|
|
68
|
-
/** Parse a JSON file with `parseJson` semantics; a missing file is `undefined`. */
|
|
69
|
-
export function readJsonFile(file: string): Json | undefined {
|
|
70
|
-
return existsSync(file) ? parseJson(readFileSync(file, "utf8")) : undefined;
|
|
71
|
-
}
|
|
@@ -1,140 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Direct
|
|
3
|
-
*
|
|
2
|
+
* Direct mode for `toolchain`. Same public argv vocabulary, golden-tested
|
|
3
|
+
* messages, same exit codes.
|
|
4
4
|
*/
|
|
5
|
-
import { p } from "./exec";
|
|
6
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
-
import { payloadText } from "../payload";
|
|
8
|
-
|
|
9
|
-
import { codexHome } from "./codexPaths";
|
|
10
|
-
import { syncClaudeModel } from "./claudeSettingsModifiers";
|
|
11
|
-
import { syncCodexModel } from "./codexToml";
|
|
12
5
|
import type { Ctx } from "./index";
|
|
13
|
-
import { isObject, parseJson, type Json } from "./jq";
|
|
14
|
-
import { printModels, validateClaudeModel, validateCodexModel } from "./models";
|
|
15
|
-
import { defaultLiveInputs, resolveCatalog } from "./liveModels";
|
|
16
6
|
import { bunBootstrap } from "./bun";
|
|
17
|
-
import { withFolderLocks, withSyncLock } from "./syncDispatch";
|
|
18
|
-
import { upgradeLspServers } from "./claudeLsp";
|
|
19
7
|
import { belowFloor, field, installedVersion, outdatedReport, present, report } from "./toolchain";
|
|
20
|
-
import { topLevelTomlString } from "../manifests";
|
|
21
|
-
|
|
22
|
-
export async function modeModel(ctx: Ctx, args: ReadonlyArray<string>): Promise<number> {
|
|
23
|
-
const { err } = ctx.services.logger;
|
|
24
|
-
let tool: "claude" | "codex" | "" = "";
|
|
25
|
-
let value = "";
|
|
26
|
-
for (const arg of args) {
|
|
27
|
-
if (arg === "--dry-run") ctx.dryRun = true;
|
|
28
|
-
else if (arg === "--verbose") {
|
|
29
|
-
ctx.verbose = true;
|
|
30
|
-
} else if (arg === "claude" || arg === "codex") tool = arg;
|
|
31
|
-
else if (arg.startsWith("-")) {
|
|
32
|
-
err(`Unknown flag for model: ${arg}`);
|
|
33
|
-
return 2;
|
|
34
|
-
} else value = arg;
|
|
35
|
-
}
|
|
36
|
-
if (tool === "") {
|
|
37
|
-
err("Usage: model <claude|codex> [value] [--dry-run]");
|
|
38
|
-
return 2;
|
|
39
|
-
}
|
|
40
|
-
if (value === "") return await showModel(ctx, tool);
|
|
41
|
-
// A write does the same read-modify-write of settings.json and config.toml as a sync.
|
|
42
|
-
return await withSyncLock(ctx, args, async () => {
|
|
43
|
-
// `model codex` writes config.toml in the Codex folder, which syncs of
|
|
44
|
-
// other homes can share. It creates no folder, so a missing one needs no lock.
|
|
45
|
-
const codexDir = codexHome(ctx.home);
|
|
46
|
-
const folders = tool === "codex" && existsSync(codexDir) ? [codexDir] : [];
|
|
47
|
-
return await withFolderLocks(ctx, folders, () => writeModel(ctx, tool, value));
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** Print the deployed model, the SoT model, and the model catalog of `tool`. */
|
|
52
|
-
async function showModel(ctx: Ctx, tool: "claude" | "codex"): Promise<number> {
|
|
53
|
-
const { echo, err, warn } = ctx.services.logger;
|
|
54
|
-
const catalog = await resolveCatalog(tool, defaultLiveInputs(ctx.home));
|
|
55
|
-
if (tool === "claude") {
|
|
56
|
-
const deployed = p(ctx.home, ".claude", "settings.json");
|
|
57
|
-
const result = readConfig(deployed);
|
|
58
|
-
if (result.kind === "missing") {
|
|
59
|
-
warn("~/.claude/settings.json missing");
|
|
60
|
-
return 0;
|
|
61
|
-
}
|
|
62
|
-
if (result.kind === "read-error") {
|
|
63
|
-
err(`Failed to read ~/.claude/settings.json: ${String(result.error)}`);
|
|
64
|
-
return 1;
|
|
65
|
-
}
|
|
66
|
-
echo(`deployed: ${jsonModelText(result.data)}`);
|
|
67
|
-
echo(`SoT: ${jsonModelText(payloadText("SoT/.claude/settings.json"))}`);
|
|
68
|
-
} else {
|
|
69
|
-
const deployed = p(codexHome(ctx.home), "config.toml");
|
|
70
|
-
const result = readConfig(deployed);
|
|
71
|
-
if (result.kind === "missing") {
|
|
72
|
-
warn(`${deployed} missing`);
|
|
73
|
-
return 0;
|
|
74
|
-
}
|
|
75
|
-
if (result.kind === "read-error") {
|
|
76
|
-
err(`Failed to read ${deployed}: ${String(result.error)}`);
|
|
77
|
-
return 1;
|
|
78
|
-
}
|
|
79
|
-
echo(`deployed: ${topLevelTomlString(result.data, "model") ?? ""}`);
|
|
80
|
-
echo(`SoT: ${topLevelTomlString(payloadText("SoT/.codex/config.toml"), "model") ?? ""}`);
|
|
81
|
-
}
|
|
82
|
-
printModels(ctx, catalog);
|
|
83
|
-
return 0;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/** Validate `value` against the model catalog of `tool`, then write it. */
|
|
87
|
-
async function writeModel(ctx: Ctx, tool: "claude" | "codex", value: string): Promise<number> {
|
|
88
|
-
const { err } = ctx.services.logger;
|
|
89
|
-
const catalog = await resolveCatalog(tool, defaultLiveInputs(ctx.home));
|
|
90
|
-
if (tool === "claude") {
|
|
91
|
-
if (!validateClaudeModel(ctx, value, catalog)) {
|
|
92
|
-
printModels(ctx, catalog);
|
|
93
|
-
err(`Invalid Claude model '${value}'`);
|
|
94
|
-
return 2;
|
|
95
|
-
}
|
|
96
|
-
syncClaudeModel(ctx, value);
|
|
97
|
-
} else {
|
|
98
|
-
if (!validateCodexModel(ctx, value, catalog)) {
|
|
99
|
-
printModels(ctx, catalog);
|
|
100
|
-
err(`Invalid Codex model '${value}'`);
|
|
101
|
-
return 2;
|
|
102
|
-
}
|
|
103
|
-
syncCodexModel(ctx, value);
|
|
104
|
-
}
|
|
105
|
-
return 0;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
type ConfigReadResult =
|
|
109
|
-
| { readonly kind: "missing" }
|
|
110
|
-
| { readonly kind: "read-error"; readonly error: unknown }
|
|
111
|
-
| { readonly kind: "data"; readonly data: string };
|
|
112
|
-
|
|
113
|
-
function readConfig(file: string): ConfigReadResult {
|
|
114
|
-
try {
|
|
115
|
-
return { kind: "data", data: readFileSync(file, "utf8") };
|
|
116
|
-
} catch (error) {
|
|
117
|
-
const code =
|
|
118
|
-
typeof error === "object" &&
|
|
119
|
-
error !== null &&
|
|
120
|
-
"code" in error &&
|
|
121
|
-
typeof error.code === "string"
|
|
122
|
-
? error.code
|
|
123
|
-
: undefined;
|
|
124
|
-
return code === "ENOENT" ? { kind: "missing" } : { kind: "read-error", error };
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function jsonModelText(text: string): string {
|
|
129
|
-
const doc = parseJson(text);
|
|
130
|
-
if (doc === undefined) return "";
|
|
131
|
-
const v: Json | undefined = isObject(doc) ? doc["model"] : undefined;
|
|
132
|
-
if (v === undefined || v === null || v === false) return "default (unset)";
|
|
133
|
-
return typeof v === "string" ? v : JSON.stringify(v);
|
|
134
|
-
}
|
|
135
8
|
|
|
136
|
-
const TOOLCHAIN_USAGE =
|
|
137
|
-
"Usage: toolchain [check|ensure <tool> [--dry-run]|outdated [--refresh]|upgrade [--dry-run]]";
|
|
9
|
+
const TOOLCHAIN_USAGE = "Usage: toolchain [check|ensure <tool> [--dry-run]|outdated [--refresh]]";
|
|
138
10
|
|
|
139
11
|
export async function modeToolchain(ctx: Ctx, args: ReadonlyArray<string>): Promise<number> {
|
|
140
12
|
const { echo, err, verbose, warn } = ctx.services.logger;
|
|
@@ -158,7 +30,6 @@ export async function modeToolchain(ctx: Ctx, args: ReadonlyArray<string>): Prom
|
|
|
158
30
|
await outdatedReport(ctx, { refresh: args.includes("--refresh") });
|
|
159
31
|
return 0;
|
|
160
32
|
}
|
|
161
|
-
if (op === "upgrade") return await upgradeLspServers(ctx);
|
|
162
33
|
if (op !== "ensure") {
|
|
163
34
|
err(TOOLCHAIN_USAGE);
|
|
164
35
|
return 2;
|
|
@@ -4,13 +4,9 @@ import type { HostOs } from "./types";
|
|
|
4
4
|
export const darwin: HostOs = posixHost({
|
|
5
5
|
id: "darwin",
|
|
6
6
|
toolchainOs: "darwin",
|
|
7
|
-
supportsBubblewrap: false,
|
|
8
|
-
// macOS terminals start bash as a login shell. It reads the first existing file of these and never reads .bashrc.
|
|
9
|
-
bashTargets: [".bash_profile", ".bash_login", ".profile"],
|
|
10
7
|
packageManagerHints: {
|
|
11
8
|
git: "brew install git",
|
|
12
9
|
jq: "brew install jq",
|
|
13
10
|
curl: "brew install curl",
|
|
14
|
-
ffplay: "brew install ffmpeg",
|
|
15
11
|
},
|
|
16
12
|
});
|
|
@@ -22,12 +22,11 @@ export function platformName(pf: NodeJS.Platform = rawPlatform()): PlatformName
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
// An unrecognized host keeps Linux hint text
|
|
25
|
+
// An unrecognized host keeps Linux hint text and filters no toolchain row — exactly today's behavior.
|
|
26
26
|
const unknown: HostOs = {
|
|
27
27
|
...linux,
|
|
28
28
|
id: "unknown",
|
|
29
29
|
toolchainOs: "",
|
|
30
|
-
supportsBubblewrap: false,
|
|
31
30
|
};
|
|
32
31
|
|
|
33
32
|
const HOSTS: Readonly<Record<PlatformName, HostOs>> = {
|
|
@@ -4,12 +4,9 @@ import type { HostOs } from "./types";
|
|
|
4
4
|
export const linux: HostOs = posixHost({
|
|
5
5
|
id: "linux",
|
|
6
6
|
toolchainOs: "linux",
|
|
7
|
-
supportsBubblewrap: true,
|
|
8
|
-
bashTargets: [".bashrc"],
|
|
9
7
|
packageManagerHints: {
|
|
10
8
|
git: "sudo apt install -y git (or your distro's package manager)",
|
|
11
9
|
jq: "sudo apt install -y jq",
|
|
12
10
|
curl: "sudo apt install -y curl",
|
|
13
|
-
ffplay: "sudo apt install -y ffmpeg",
|
|
14
11
|
},
|
|
15
12
|
});
|
|
@@ -2,26 +2,13 @@
|
|
|
2
2
|
// through this module. A slash join keeps the same host-stable path p() would produce.
|
|
3
3
|
import type { HintedTool, HostOs } from "./types";
|
|
4
4
|
|
|
5
|
-
function posixLiteral(value: string): string {
|
|
6
|
-
return `'${value.replaceAll("'", `'"'"'`)}'`;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
5
|
/** Package-manager hints for the tools a POSIX host installs through its own package manager. */
|
|
10
|
-
export type PackageManagerHints = Readonly<Record<
|
|
11
|
-
|
|
12
|
-
const UPSTREAM_INSTALLER_HINTS: Readonly<Record<"claude" | "codex", string>> = {
|
|
13
|
-
claude: 'tmp=$(mktemp) && curl -fsSL https://claude.ai/install.sh -o "$tmp" && bash "$tmp"',
|
|
14
|
-
codex:
|
|
15
|
-
'tmp=$(mktemp) && curl -fsSL https://chatgpt.com/codex/install.sh -o "$tmp" && CODEX_NON_INTERACTIVE=1 sh "$tmp"',
|
|
16
|
-
};
|
|
6
|
+
export type PackageManagerHints = Readonly<Record<HintedTool, string>>;
|
|
17
7
|
|
|
18
8
|
interface PosixHostInputs {
|
|
19
9
|
readonly id: HostOs["id"];
|
|
20
10
|
readonly toolchainOs: HostOs["toolchainOs"];
|
|
21
|
-
readonly supportsBubblewrap: boolean;
|
|
22
11
|
readonly packageManagerHints: PackageManagerHints;
|
|
23
|
-
/** Home-relative bash startup files in read order; the first existing one gets the write, else the first entry. */
|
|
24
|
-
readonly bashTargets: readonly [string, ...string[]];
|
|
25
12
|
}
|
|
26
13
|
|
|
27
14
|
/** Members shared by every POSIX host; linux and darwin differ only in the inputs. */
|
|
@@ -29,7 +16,6 @@ export function posixHost(inputs: PosixHostInputs): HostOs {
|
|
|
29
16
|
return {
|
|
30
17
|
id: inputs.id,
|
|
31
18
|
toolchainOs: inputs.toolchainOs,
|
|
32
|
-
supportsBubblewrap: inputs.supportsBubblewrap,
|
|
33
19
|
directoryLinkKinds: ["symlink"],
|
|
34
20
|
executableSuffixes: [""],
|
|
35
21
|
invoke: (executablePath, args) => ({ command: executablePath, args }),
|
|
@@ -48,36 +34,6 @@ export function posixHost(inputs: PosixHostInputs): HostOs {
|
|
|
48
34
|
},
|
|
49
35
|
};
|
|
50
36
|
},
|
|
51
|
-
|
|
52
|
-
kind: "profile",
|
|
53
|
-
// Bash reads .bash_login only as a login file. Only a host that writes to it
|
|
54
|
-
// scans it, so a dormant copy cannot block the write to the loaded file.
|
|
55
|
-
candidates: [
|
|
56
|
-
".zshrc",
|
|
57
|
-
".bashrc",
|
|
58
|
-
".bash_profile",
|
|
59
|
-
...(inputs.bashTargets.includes(".bash_login") ? [".bash_login"] : []),
|
|
60
|
-
".profile",
|
|
61
|
-
".zshenv",
|
|
62
|
-
],
|
|
63
|
-
target: (shell, exists) => {
|
|
64
|
-
const shellPath = shell ?? "bash";
|
|
65
|
-
const shellName = shellPath.slice(shellPath.lastIndexOf("/") + 1);
|
|
66
|
-
if (shellName === "zsh") return ".zshrc";
|
|
67
|
-
if (shellName !== "bash") return ".profile";
|
|
68
|
-
return inputs.bashTargets.find(exists) ?? inputs.bashTargets[0];
|
|
69
|
-
},
|
|
70
|
-
line: `export ${name}=${value}`,
|
|
71
|
-
}),
|
|
72
|
-
statusLineCommand: (bun, script) => {
|
|
73
|
-
const bunLiteral = posixLiteral(bun);
|
|
74
|
-
const scriptLiteral = posixLiteral(script);
|
|
75
|
-
return `test -x ${bunLiteral} && test -f ${scriptLiteral} && exec ${bunLiteral} ${scriptLiteral} || true`;
|
|
76
|
-
},
|
|
77
|
-
failureHookCommand: (command) => command,
|
|
78
|
-
installHint: (tool) =>
|
|
79
|
-
tool === "claude" || tool === "codex"
|
|
80
|
-
? UPSTREAM_INSTALLER_HINTS[tool]
|
|
81
|
-
: inputs.packageManagerHints[tool],
|
|
37
|
+
installHint: (tool) => inputs.packageManagerHints[tool],
|
|
82
38
|
};
|
|
83
39
|
}
|
|
@@ -8,7 +8,7 @@ export type PlatformName = "linux" | "darwin" | "windows" | "unknown";
|
|
|
8
8
|
/** Directory-link mechanisms, tried in order before the copy fallback. */
|
|
9
9
|
export type DirectoryLinkKind = "symlink" | "junction";
|
|
10
10
|
/** Tools whose install command differs per host OS. */
|
|
11
|
-
export type HintedTool = "git" | "jq" | "curl"
|
|
11
|
+
export type HintedTool = "git" | "jq" | "curl";
|
|
12
12
|
|
|
13
13
|
/** A command plus argv, already shaped for how this host must invoke it. */
|
|
14
14
|
export interface Invocation {
|
|
@@ -18,29 +18,6 @@ export interface Invocation {
|
|
|
18
18
|
readonly windowsVerbatimArguments?: boolean;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
/** How this host persists a user-level environment variable. */
|
|
22
|
-
export type EnvironmentSetting =
|
|
23
|
-
| {
|
|
24
|
-
readonly kind: "profile";
|
|
25
|
-
/** Home-relative files scanned for an existing setting. */
|
|
26
|
-
readonly candidates: ReadonlyArray<string>;
|
|
27
|
-
/** Home-relative file that receives the write for this shell; `exists` tests a home-relative file. */
|
|
28
|
-
readonly target: (shell: string | undefined, exists: (file: string) => boolean) => string;
|
|
29
|
-
/** Line appended to the target file. */
|
|
30
|
-
readonly line: string;
|
|
31
|
-
}
|
|
32
|
-
| {
|
|
33
|
-
readonly kind: "command";
|
|
34
|
-
/** Exits zero when the variable is already persisted. */
|
|
35
|
-
readonly probe: Invocation;
|
|
36
|
-
/** Persists the variable. */
|
|
37
|
-
readonly apply: Invocation;
|
|
38
|
-
/** Where the value lands, named for the log line. */
|
|
39
|
-
readonly location: string;
|
|
40
|
-
/** Manual recovery when `apply` fails. */
|
|
41
|
-
readonly manualHint: string;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
21
|
/** The two steps that fetch and run a pinned Bun installer. */
|
|
45
22
|
export interface BunInstaller {
|
|
46
23
|
readonly scriptPath: string;
|
|
@@ -52,8 +29,6 @@ export interface HostOs {
|
|
|
52
29
|
readonly id: PlatformName;
|
|
53
30
|
/** `SoT/toolchain.json` `os` field this host matches; "" matches every row. */
|
|
54
31
|
readonly toolchainOs: string;
|
|
55
|
-
/** Bubblewrap is the Linux-only Codex sandbox runtime. */
|
|
56
|
-
readonly supportsBubblewrap: boolean;
|
|
57
32
|
/** Directory-link mechanisms tried in order before `skillsLinks.ts linkOrCopy` copies. */
|
|
58
33
|
readonly directoryLinkKinds: ReadonlyArray<DirectoryLinkKind>;
|
|
59
34
|
/** One-line install command for a tool whose package differs per OS. */
|
|
@@ -66,10 +41,4 @@ export interface HostOs {
|
|
|
66
41
|
readonly bunExecutableName: string;
|
|
67
42
|
/** Download-then-run installer for a pinned Bun version placed in `directory`. */
|
|
68
43
|
readonly bunInstaller: (pin: string, directory: string) => BunInstaller;
|
|
69
|
-
/** How this host persists a user-level environment variable. */
|
|
70
|
-
readonly environmentSetting: (name: string, value: string) => EnvironmentSetting;
|
|
71
|
-
/** Claude `statusLine.command` for a resolved bun executable and script. */
|
|
72
|
-
readonly statusLineCommand: (bun: string, script: string) => string;
|
|
73
|
-
/** Reshape the SoT `PostToolUseFailure` command for this host's shell. */
|
|
74
|
-
readonly failureHookCommand: (command: string) => string;
|
|
75
44
|
}
|