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
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* EngineNative `sync claude` settings materialization and merge. Step order
|
|
3
|
-
* with the runtime cutover and deploy-time modifiers is load-bearing and
|
|
4
|
-
* golden-tested; message strings and JSON semantics are part of the contract.
|
|
5
|
-
*/
|
|
6
|
-
import { copyFileSync, existsSync, readFileSync } from "node:fs";
|
|
7
|
-
import { replaceFile } from "./atomicWrite";
|
|
8
|
-
import { p } from "./exec";
|
|
9
|
-
import type { Ctx } from "./index";
|
|
10
|
-
import { isObject, jqStringify, parseJson, type Json } from "./jq";
|
|
11
|
-
import { ExitError } from "./parseArgs";
|
|
12
|
-
import { mergeSettings, reconcileSettings } from "./settings";
|
|
13
|
-
import { payloadDisplayPath } from "../payload";
|
|
14
|
-
import type { JsonObject } from "./sharedTypes";
|
|
15
|
-
|
|
16
|
-
export interface PreparedClaudeSettings {
|
|
17
|
-
readonly path: string;
|
|
18
|
-
readonly bytes: string;
|
|
19
|
-
readonly previousBytes: string | undefined;
|
|
20
|
-
readonly changed: boolean;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function assertMaterializedSettings(bytes: string): void {
|
|
24
|
-
if (bytes.includes("__DOCKS_KIT_"))
|
|
25
|
-
throw new Error("Claude settings contain unresolved runtime sentinels");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Read the deployed settings document. An unparsable or non-object document
|
|
30
|
-
* aborts the sync, because a merge would replace the user's settings.
|
|
31
|
-
*/
|
|
32
|
-
function readDeployedSettings(ctx: Ctx, path: string): { text: string; doc: JsonObject } {
|
|
33
|
-
const text = readFileSync(path, "utf8");
|
|
34
|
-
const doc = parseJson(text);
|
|
35
|
-
if (doc === undefined || !isObject(doc)) {
|
|
36
|
-
const reason = doc === undefined ? "is not valid JSON" : "must contain a JSON object";
|
|
37
|
-
ctx.services.logger.err(
|
|
38
|
-
`Aborting sync: ${path} ${reason}. Fix it manually or delete it to reinstall.`,
|
|
39
|
-
);
|
|
40
|
-
throw new ExitError(1);
|
|
41
|
-
}
|
|
42
|
-
return { text, doc };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Check the deployed settings before any sync pipeline starts. A document
|
|
47
|
-
* that cannot merge stops the whole sync, so no other harness changes first.
|
|
48
|
-
*/
|
|
49
|
-
export function preflightClaudeSettings(ctx: Ctx): void {
|
|
50
|
-
if (!ctx.syncClaude) return;
|
|
51
|
-
const path = p(ctx.home, ".claude", "settings.json");
|
|
52
|
-
if (existsSync(path)) readDeployedSettings(ctx, path);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** Build the candidate settings bytes before the readiness-gated runtime cutover mutates disk. */
|
|
56
|
-
export function prepareClaudeSettings(
|
|
57
|
-
ctx: Ctx,
|
|
58
|
-
claudeDir: string,
|
|
59
|
-
repo: Json,
|
|
60
|
-
): PreparedClaudeSettings {
|
|
61
|
-
const path = p(claudeDir, "settings.json");
|
|
62
|
-
if (!existsSync(path)) {
|
|
63
|
-
// Write the form the next sync produces, so a second sync finds no change.
|
|
64
|
-
const canonical = ctx.reconcile ? reconcileSettings(repo, {}) : mergeSettings(repo, {});
|
|
65
|
-
const bytes = jqStringify(canonical);
|
|
66
|
-
assertMaterializedSettings(bytes);
|
|
67
|
-
return { path, bytes, previousBytes: undefined, changed: true };
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// engineSync runs this check in preflightClaudeSettings; it stays here for other callers.
|
|
71
|
-
const { text: previousBytes, doc: user } = readDeployedSettings(ctx, path);
|
|
72
|
-
const merged = ctx.reconcile ? reconcileSettings(repo, user) : mergeSettings(repo, user);
|
|
73
|
-
const bytes = jqStringify(merged);
|
|
74
|
-
assertMaterializedSettings(bytes);
|
|
75
|
-
return { path, bytes, previousBytes, changed: bytes !== previousBytes };
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Commit a fully prepared document; callers must finish runtime preparation first.
|
|
80
|
-
* Returns true when the commit copied the previous settings to settings.json.bak.
|
|
81
|
-
*/
|
|
82
|
-
export function commitClaudeSettings(ctx: Ctx, prepared: PreparedClaudeSettings): boolean {
|
|
83
|
-
const { change, verbose } = ctx.services.logger;
|
|
84
|
-
if (!prepared.changed) {
|
|
85
|
-
verbose("Settings already in sync");
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const backedUp = prepared.previousBytes !== undefined;
|
|
90
|
-
if (backedUp) copyFileSync(prepared.path, `${prepared.path}.bak`);
|
|
91
|
-
replaceFile(prepared.path, prepared.bytes);
|
|
92
|
-
ctx.nextStepTriggers.claudeRestart = true;
|
|
93
|
-
if (prepared.previousBytes === undefined) {
|
|
94
|
-
change("Settings installed");
|
|
95
|
-
} else if (ctx.reconcile) {
|
|
96
|
-
change(
|
|
97
|
-
"Settings reconciled (backup at settings.json.bak; user-only keys preserved, permissions arrays replaced by SoT)",
|
|
98
|
-
);
|
|
99
|
-
} else {
|
|
100
|
-
change("Settings merged (backup at settings.json.bak)");
|
|
101
|
-
}
|
|
102
|
-
return backedUp;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function describeSettingsSync(ctx: Ctx, claudeDir: string): void {
|
|
106
|
-
const { echo } = ctx.services.logger;
|
|
107
|
-
const repoSettings = payloadDisplayPath("SoT/.claude/settings.json");
|
|
108
|
-
const userSettings = p(claudeDir, "settings.json");
|
|
109
|
-
|
|
110
|
-
if (!existsSync(userSettings)) {
|
|
111
|
-
echo(`[dry-run] install ${repoSettings} -> ${userSettings}`);
|
|
112
|
-
} else if (ctx.reconcile) {
|
|
113
|
-
echo(
|
|
114
|
-
`[dry-run] reconcile ${repoSettings} -> ${userSettings} (SoT keys win; permissions arrays replaced; user-only keys preserved)`,
|
|
115
|
-
);
|
|
116
|
-
} else {
|
|
117
|
-
echo(
|
|
118
|
-
`[dry-run] merge ${repoSettings} -> ${userSettings} (SoT keys win; permissions arrays unioned; user-only keys preserved)`,
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/** Shared shape of the three jq-edit modifiers (compact window, permissive). */
|
|
124
|
-
function jqEditSettings(
|
|
125
|
-
ctx: Ctx,
|
|
126
|
-
claudeDir: string,
|
|
127
|
-
tag: string,
|
|
128
|
-
edit: (doc: Json) => void,
|
|
129
|
-
): boolean {
|
|
130
|
-
const { err, warn } = ctx.services.logger;
|
|
131
|
-
const userSettings = p(claudeDir, "settings.json");
|
|
132
|
-
if (!existsSync(userSettings)) {
|
|
133
|
-
warn(`(${tag}) ${userSettings} missing — skipped`);
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
const before = readFileSync(userSettings, "utf8");
|
|
137
|
-
const doc = parseJson(before);
|
|
138
|
-
if (doc === undefined) {
|
|
139
|
-
err(`(${tag}) ${userSettings} is not valid JSON — skipped`);
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
edit(doc);
|
|
143
|
-
const out = jqStringify(doc);
|
|
144
|
-
if (out === before) return false;
|
|
145
|
-
replaceFile(userSettings, out);
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export function syncCompactWindow(ctx: Ctx, claudeDir: string): void {
|
|
150
|
-
const { change, echo, verbose } = ctx.services.logger;
|
|
151
|
-
if (ctx.claudeCompactWindow === "") return;
|
|
152
|
-
|
|
153
|
-
if (ctx.dryRun) {
|
|
154
|
-
echo(
|
|
155
|
-
`[dry-run] (--claude-compact-window) set env.CLAUDE_CODE_AUTO_COMPACT_WINDOW=${ctx.claudeCompactWindow} in ${p(claudeDir, "settings.json")}`,
|
|
156
|
-
);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const changed = jqEditSettings(ctx, claudeDir, "--claude-compact-window", (doc) => {
|
|
161
|
-
if (!isObject(doc)) return;
|
|
162
|
-
const env = isObject(doc["env"]) ? doc["env"] : {};
|
|
163
|
-
env["CLAUDE_CODE_AUTO_COMPACT_WINDOW"] = ctx.claudeCompactWindow;
|
|
164
|
-
doc["env"] = env;
|
|
165
|
-
});
|
|
166
|
-
if (changed) {
|
|
167
|
-
change(
|
|
168
|
-
`Compact window: set to ${ctx.claudeCompactWindow} tokens in deployed settings (SoT and model unchanged; flag-less sync reverts)`,
|
|
169
|
-
);
|
|
170
|
-
ctx.nextStepTriggers.claudeRestart = true;
|
|
171
|
-
} else
|
|
172
|
-
verbose(
|
|
173
|
-
`Compact window: already set to ${ctx.claudeCompactWindow} tokens in deployed settings`,
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export function syncPermissive(ctx: Ctx, claudeDir: string): void {
|
|
178
|
-
const { change, echo, verbose } = ctx.services.logger;
|
|
179
|
-
if (!ctx.claudePermissive) return;
|
|
180
|
-
|
|
181
|
-
if (ctx.dryRun) {
|
|
182
|
-
echo(
|
|
183
|
-
`[dry-run] (--claude-permissive) empty permissions.ask and permissions.deny in ${p(claudeDir, "settings.json")}`,
|
|
184
|
-
);
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const changed = jqEditSettings(ctx, claudeDir, "--claude-permissive", (doc) => {
|
|
189
|
-
if (!isObject(doc)) return;
|
|
190
|
-
const permissions = isObject(doc["permissions"]) ? doc["permissions"] : {};
|
|
191
|
-
permissions["ask"] = [];
|
|
192
|
-
permissions["deny"] = [];
|
|
193
|
-
doc["permissions"] = permissions;
|
|
194
|
-
});
|
|
195
|
-
if (changed) {
|
|
196
|
-
change(
|
|
197
|
-
"Permissive mode: permissions.ask/deny emptied in deployed settings (sandbox use; SoT unchanged)",
|
|
198
|
-
);
|
|
199
|
-
ctx.nextStepTriggers.claudeRestart = true;
|
|
200
|
-
} else verbose("Permissive mode: permissions.ask/deny already empty in deployed settings");
|
|
201
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/** Atomic top-level Claude settings modifiers, including direct model mode. */
|
|
2
|
-
import { p } from "./exec";
|
|
3
|
-
import { readFileSync } from "node:fs";
|
|
4
|
-
import { replaceFile } from "./atomicWrite";
|
|
5
|
-
|
|
6
|
-
import { resolveEffort } from "../efforts";
|
|
7
|
-
import type { Ctx } from "./index";
|
|
8
|
-
import { ExitError } from "./parseArgs";
|
|
9
|
-
import { isObject, jqStringify, parseJson } from "./jq";
|
|
10
|
-
import type { SettingEdit } from "./sharedTypes";
|
|
11
|
-
|
|
12
|
-
interface ClaudeSettingEdit extends SettingEdit<"model" | "effortLevel" | "advisorModel"> {
|
|
13
|
-
readonly dryRun: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function syncClaudeSetting(ctx: Ctx, edit: ClaudeSettingEdit): void {
|
|
17
|
-
const { change, echo, err, verbose, warn } = ctx.services.logger;
|
|
18
|
-
const userSettings = p(ctx.home, ".claude", "settings.json");
|
|
19
|
-
|
|
20
|
-
let text: string;
|
|
21
|
-
try {
|
|
22
|
-
text = readFileSync(userSettings, "utf8");
|
|
23
|
-
} catch (error) {
|
|
24
|
-
if (error !== null && typeof error === "object" && "code" in error && error.code === "ENOENT") {
|
|
25
|
-
// A dry-run sync writes nothing, so an absent file here does not mean the
|
|
26
|
-
// edit is skipped: the same run already previewed installing the file,
|
|
27
|
-
// and the real run applies the edit to it. Outside a sync, such as
|
|
28
|
-
// `docks-kit model claude <m>`, nothing creates the file and the skip
|
|
29
|
-
// stands.
|
|
30
|
-
if (ctx.dryRun && ctx.syncClaude) {
|
|
31
|
-
echo(`[dry-run] (${edit.tag}) ${edit.dryRun} in ${userSettings}`);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
warn(`(${edit.tag}) ${userSettings} missing — skipped`);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const cause = error instanceof Error ? error.message : String(error);
|
|
38
|
-
err(`(${edit.tag}) could not read ${userSettings}: ${cause}`);
|
|
39
|
-
throw new ExitError(1);
|
|
40
|
-
}
|
|
41
|
-
const doc = parseJson(text);
|
|
42
|
-
if (doc === undefined) {
|
|
43
|
-
err(`(${edit.tag}) ${userSettings} is not valid JSON — skipped`);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
if (!isObject(doc)) {
|
|
47
|
-
err(`(${edit.tag}) ${userSettings} must contain a JSON object — aborting`);
|
|
48
|
-
throw new ExitError(1);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (ctx.dryRun) {
|
|
52
|
-
echo(`[dry-run] (${edit.tag}) ${edit.dryRun} in ${userSettings}`);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (edit.value === undefined) delete doc[edit.key];
|
|
57
|
-
else doc[edit.key] = edit.value;
|
|
58
|
-
const out = jqStringify(doc);
|
|
59
|
-
if (out === text) {
|
|
60
|
-
verbose(edit.unchanged);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
replaceFile(userSettings, out);
|
|
64
|
-
change(edit.changed);
|
|
65
|
-
ctx.nextStepTriggers.claudeRestart = true;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function syncClaudeModel(ctx: Ctx, model: string): void {
|
|
69
|
-
if (model === "") return;
|
|
70
|
-
const unset = model === "default";
|
|
71
|
-
syncClaudeSetting(ctx, {
|
|
72
|
-
tag: "--claude-model",
|
|
73
|
-
key: "model",
|
|
74
|
-
value: unset ? undefined : model,
|
|
75
|
-
dryRun: unset ? "delete .model (account default applies)" : `set .model=${model}`,
|
|
76
|
-
changed: `Model: deployed settings model set to ${model} (SoT unchanged; flag-less sync reverts)`,
|
|
77
|
-
unchanged: `Model: deployed settings model already ${unset ? "unset (account default)" : model}`,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function syncClaudeEffort(ctx: Ctx, effort: string): void {
|
|
82
|
-
if (effort === "") return;
|
|
83
|
-
const resolved = resolveEffort("claude", effort);
|
|
84
|
-
const useDefault = effort === "default";
|
|
85
|
-
syncClaudeSetting(ctx, {
|
|
86
|
-
tag: "--claude-effort",
|
|
87
|
-
key: "effortLevel",
|
|
88
|
-
value: resolved,
|
|
89
|
-
dryRun: `set .effortLevel=${resolved}`,
|
|
90
|
-
changed: useDefault
|
|
91
|
-
? `Effort: deployed settings effortLevel set to ${resolved} (SoT default)`
|
|
92
|
-
: `Effort: deployed settings effortLevel set to ${resolved} (SoT unchanged; flag-less sync reverts)`,
|
|
93
|
-
unchanged: `Effort: deployed settings effortLevel already ${resolved}`,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function syncClaudeAdvisor(ctx: Ctx, state: string): void {
|
|
98
|
-
if (state === "") return;
|
|
99
|
-
const enabled = state === "on";
|
|
100
|
-
const useDefault = state === "default";
|
|
101
|
-
syncClaudeSetting(ctx, {
|
|
102
|
-
tag: "--claude-advisor",
|
|
103
|
-
key: "advisorModel",
|
|
104
|
-
value: enabled ? "opus" : undefined,
|
|
105
|
-
dryRun: enabled ? "set .advisorModel=opus" : "delete .advisorModel (advisor disabled)",
|
|
106
|
-
changed: enabled
|
|
107
|
-
? "Advisor: deployed settings advisorModel set to opus (SoT unchanged; flag-less sync reverts)"
|
|
108
|
-
: useDefault
|
|
109
|
-
? "Advisor: deployed settings advisorModel unset (SoT default: off)"
|
|
110
|
-
: "Advisor: deployed settings advisorModel unset (--claude-advisor=off; SoT unchanged)",
|
|
111
|
-
unchanged: enabled
|
|
112
|
-
? "Advisor: deployed settings advisorModel already opus"
|
|
113
|
-
: `Advisor: deployed settings advisorModel already unset (${useDefault ? "SoT default: off" : "advisor off"})`,
|
|
114
|
-
});
|
|
115
|
-
}
|
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* EngineNative `sync claude` pipeline. Step order is load-bearing: the Bun
|
|
3
|
-
* bootstrap BEFORE the settings merge, modifiers after it, removals before
|
|
4
|
-
* plugins. Message strings, guard order, JSON semantics, and spawned argv are
|
|
5
|
-
* golden-tested.
|
|
6
|
-
*/
|
|
7
|
-
import { appendFileSync, copyFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
8
|
-
import { replaceFile } from "./atomicWrite";
|
|
9
|
-
import { bunBootstrap } from "./bun";
|
|
10
|
-
import { syncClaudeAdvisor, syncClaudeEffort, syncClaudeModel } from "./claudeSettingsModifiers";
|
|
11
|
-
import {
|
|
12
|
-
claudeRuntimePaths,
|
|
13
|
-
materializeClaudeSettings,
|
|
14
|
-
type ClaudeRuntimePaths,
|
|
15
|
-
} from "./claudeRuntime";
|
|
16
|
-
import {
|
|
17
|
-
commitClaudeSettings,
|
|
18
|
-
describeSettingsSync,
|
|
19
|
-
prepareClaudeSettings,
|
|
20
|
-
syncCompactWindow,
|
|
21
|
-
syncPermissive,
|
|
22
|
-
} from "./claudeSettings";
|
|
23
|
-
import { syncRemovals } from "./claudeRemovals";
|
|
24
|
-
import { syncPlugins } from "./claudePluginPasses";
|
|
25
|
-
import { syncOptionalPlugins } from "./claudeOptionalPlugins";
|
|
26
|
-
import { syncLspServers } from "./claudeLsp";
|
|
27
|
-
import { p, spawnProcess, writeBytesIfChanged, writeTextIfChanged } from "./exec";
|
|
28
|
-
import type { Ctx } from "./index";
|
|
29
|
-
import { deepMerge, isObject, jqStringify, parseJson, readJsonFile, type Json } from "./jq";
|
|
30
|
-
import { ExitError } from "./parseArgs";
|
|
31
|
-
import { hostOs } from "./os";
|
|
32
|
-
import { payloadBytes, payloadText } from "../payload";
|
|
33
|
-
import type { JsonObject } from "./sharedTypes";
|
|
34
|
-
export type { PreparedClaudeSettings } from "./claudeSettings";
|
|
35
|
-
export { commitClaudeSettings, prepareClaudeSettings } from "./claudeSettings";
|
|
36
|
-
|
|
37
|
-
export type ClaudeRuntimeState =
|
|
38
|
-
| { readonly kind: "ready"; readonly paths: ClaudeRuntimePaths }
|
|
39
|
-
| { readonly kind: "deferred"; readonly reason: "bun-unavailable" };
|
|
40
|
-
|
|
41
|
-
export async function claudeSync(ctx: Ctx): Promise<ClaudeRuntimeState> {
|
|
42
|
-
const { err, warn } = ctx.services.logger;
|
|
43
|
-
const claudeDir = p(ctx.home, ".claude");
|
|
44
|
-
|
|
45
|
-
if (!ctx.dryRun) mkdirSync(claudeDir, { recursive: true });
|
|
46
|
-
|
|
47
|
-
if (ctx.services.deps.probe("claude").state === "missing") {
|
|
48
|
-
warn(
|
|
49
|
-
`claude CLI not found - config deploys, but plugin passes are skipped. Install Claude Code: ${ctx.services.deps.spec("claude").installHint()} | docs: https://code.claude.com/docs/en/setup`,
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const bun = await bunBootstrap(ctx, ctx.services);
|
|
54
|
-
const runtime: ClaudeRuntimeState =
|
|
55
|
-
bun.kind === "ready"
|
|
56
|
-
? { kind: "ready", paths: claudeRuntimePaths(claudeDir, bun.executable) }
|
|
57
|
-
: { kind: "deferred", reason: "bun-unavailable" };
|
|
58
|
-
const template = parseJson(payloadText("SoT/.claude/settings.json"));
|
|
59
|
-
if (template === undefined) {
|
|
60
|
-
err("Embedded SoT/.claude/settings.json is not valid JSON");
|
|
61
|
-
throw new ExitError(1);
|
|
62
|
-
}
|
|
63
|
-
const materialized = materializeClaudeSettings(
|
|
64
|
-
template,
|
|
65
|
-
runtime.kind === "ready" ? runtime.paths : undefined,
|
|
66
|
-
);
|
|
67
|
-
const prepared = prepareClaudeSettings(ctx, claudeDir, materialized);
|
|
68
|
-
|
|
69
|
-
syncClaudeRuntime(ctx, runtime);
|
|
70
|
-
syncClaudeMd(ctx, claudeDir);
|
|
71
|
-
let settingsBackedUp = false;
|
|
72
|
-
if (ctx.dryRun) {
|
|
73
|
-
describeSettingsSync(ctx, claudeDir);
|
|
74
|
-
} else {
|
|
75
|
-
settingsBackedUp = commitClaudeSettings(ctx, prepared);
|
|
76
|
-
}
|
|
77
|
-
syncRemovals(ctx, claudeDir, runtime, settingsBackedUp);
|
|
78
|
-
syncCompactWindow(ctx, claudeDir);
|
|
79
|
-
syncPermissive(ctx, claudeDir);
|
|
80
|
-
syncClaudeModel(ctx, ctx.claudeModel);
|
|
81
|
-
syncClaudeEffort(ctx, ctx.claudeEffort);
|
|
82
|
-
syncClaudeAdvisor(ctx, ctx.claudeAdvisor);
|
|
83
|
-
syncClaudeJson(ctx);
|
|
84
|
-
await syncConnectorEnv(ctx);
|
|
85
|
-
await syncPlugins(ctx, claudeDir);
|
|
86
|
-
await syncOptionalPlugins(ctx, claudeDir);
|
|
87
|
-
await syncLspServers(ctx);
|
|
88
|
-
return runtime;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// ----------------------------------------------------------- runtime ----
|
|
92
|
-
|
|
93
|
-
function syncClaudeRuntime(ctx: Ctx, runtime: ClaudeRuntimeState): void {
|
|
94
|
-
const { change, echo, verbose, warn } = ctx.services.logger;
|
|
95
|
-
if (runtime.kind === "deferred") {
|
|
96
|
-
warn(
|
|
97
|
-
"Bun unavailable — Claude statusline/hooks migration deferred; install Bun, then re-run sync claude",
|
|
98
|
-
);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
if (ctx.dryRun) {
|
|
102
|
-
echo("[dry-run] install statusline.mjs, session-start.mjs, notify.mjs, notification.mp3");
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
mkdirSync(p(ctx.home, ".claude", "bin"), { recursive: true });
|
|
107
|
-
let changed = false;
|
|
108
|
-
for (const [path, source] of [
|
|
109
|
-
[runtime.paths.statusline, "SoT/.claude/bin/statusline.mjs"],
|
|
110
|
-
[runtime.paths.sessionStart, "SoT/.claude/bin/session-start.mjs"],
|
|
111
|
-
[runtime.paths.notify, "SoT/.claude/bin/notify.mjs"],
|
|
112
|
-
] as const) {
|
|
113
|
-
if (writeTextIfChanged(path, payloadText(source))) changed = true;
|
|
114
|
-
}
|
|
115
|
-
if (
|
|
116
|
-
writeBytesIfChanged(
|
|
117
|
-
p(ctx.home, ".claude", "notification.mp3"),
|
|
118
|
-
payloadBytes("notification.mp3"),
|
|
119
|
-
)
|
|
120
|
-
)
|
|
121
|
-
changed = true;
|
|
122
|
-
if (changed) {
|
|
123
|
-
change("Claude runtime synced (statusline, session-start, notify, notification)");
|
|
124
|
-
ctx.nextStepTriggers.claudeRestart = true;
|
|
125
|
-
} else {
|
|
126
|
-
verbose("Claude runtime already in sync (statusline, session-start, notify, notification)");
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function syncClaudeMd(ctx: Ctx, claudeDir: string): void {
|
|
131
|
-
const { change, echo, verbose } = ctx.services.logger;
|
|
132
|
-
if (ctx.dryRun) {
|
|
133
|
-
echo("[dry-run] cp SoT/.claude/CLAUDE.md -> ~/.claude/CLAUDE.md");
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const source = payloadText("SoT/.claude/CLAUDE.md");
|
|
138
|
-
const target = p(claudeDir, "CLAUDE.md");
|
|
139
|
-
// A first sync can find the user's own global instructions here; keep them.
|
|
140
|
-
const replaced = existsSync(target) && readFileSync(target, "utf8") !== source;
|
|
141
|
-
if (replaced) copyFileSync(target, `${target}.bak`);
|
|
142
|
-
if (writeTextIfChanged(target, source)) {
|
|
143
|
-
change(`CLAUDE.md synced${replaced ? " (backup at CLAUDE.md.bak)" : ""}`);
|
|
144
|
-
} else {
|
|
145
|
-
verbose("CLAUDE.md already in sync");
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// ---------------------------------------------------------- claude.json ----
|
|
150
|
-
|
|
151
|
-
function syncClaudeJson(ctx: Ctx): void {
|
|
152
|
-
const { change, echo, err, verbose } = ctx.services.logger;
|
|
153
|
-
const claudeJson = p(ctx.home, ".claude.json");
|
|
154
|
-
|
|
155
|
-
const mcp: Json | undefined = parseJson(payloadText("SoT/.claude/mcp-servers.json"));
|
|
156
|
-
const haveMcp = mcp !== undefined;
|
|
157
|
-
|
|
158
|
-
if (ctx.dryRun) {
|
|
159
|
-
echo("[dry-run] set showTurnDuration=true in ~/.claude.json");
|
|
160
|
-
if (haveMcp)
|
|
161
|
-
echo("[dry-run] merge mcpServers from SoT/.claude/mcp-servers.json into ~/.claude.json");
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const applyFilter = (doc: JsonObject): void => {
|
|
166
|
-
doc["showTurnDuration"] = true;
|
|
167
|
-
if (haveMcp) {
|
|
168
|
-
const sotServers = isObject(mcp!) ? (mcp!["mcpServers"] ?? {}) : {};
|
|
169
|
-
doc["mcpServers"] = deepMerge(
|
|
170
|
-
isObject(doc["mcpServers"]) ? doc["mcpServers"] : {},
|
|
171
|
-
sotServers,
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
let changed = true;
|
|
177
|
-
if (existsSync(claudeJson)) {
|
|
178
|
-
const before = readFileSync(claudeJson, "utf8");
|
|
179
|
-
const doc = parseJson(before);
|
|
180
|
-
if (doc === undefined || !isObject(doc)) {
|
|
181
|
-
const reason = doc === undefined ? "not valid JSON" : "root must be a JSON object";
|
|
182
|
-
err(`Skipping ~/.claude.json edit: ${reason}. Fix or delete it.`);
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
const obj = doc;
|
|
186
|
-
applyFilter(obj);
|
|
187
|
-
const out = jqStringify(obj);
|
|
188
|
-
if (out === before) {
|
|
189
|
-
changed = false;
|
|
190
|
-
} else {
|
|
191
|
-
replaceFile(claudeJson, out);
|
|
192
|
-
}
|
|
193
|
-
} else {
|
|
194
|
-
const obj: JsonObject = {};
|
|
195
|
-
applyFilter(obj);
|
|
196
|
-
// The file holds MCP server credentials, so a new file is private to the user.
|
|
197
|
-
replaceFile(claudeJson, jqStringify(obj), { mode: 0o600 });
|
|
198
|
-
}
|
|
199
|
-
if (changed) {
|
|
200
|
-
change(`~/.claude.json updated (showTurnDuration${haveMcp ? ", mcpServers" : ""})`);
|
|
201
|
-
ctx.nextStepTriggers.claudeRestart = true;
|
|
202
|
-
} else
|
|
203
|
-
verbose(`~/.claude.json already in sync (showTurnDuration${haveMcp ? ", mcpServers" : ""})`);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// -------------------------------------------------------- connector env ----
|
|
207
|
-
|
|
208
|
-
async function syncConnectorEnv(ctx: Ctx): Promise<void> {
|
|
209
|
-
const { change, echo, verbose, warn } = ctx.services.logger;
|
|
210
|
-
const name = "ENABLE_CLAUDEAI_MCP_SERVERS";
|
|
211
|
-
const setting = hostOs().environmentSetting(name, "false");
|
|
212
|
-
|
|
213
|
-
switch (setting.kind) {
|
|
214
|
-
case "profile": {
|
|
215
|
-
const marker = "# docks-kit: disable claude.ai cloud MCP connectors (set =true to keep them)";
|
|
216
|
-
const candidates = setting.candidates.map((candidate) => p(ctx.home, candidate));
|
|
217
|
-
|
|
218
|
-
for (const f of candidates) {
|
|
219
|
-
if (existsSync(f) && readFileSync(f, "utf8").includes(name)) {
|
|
220
|
-
if (ctx.dryRun) {
|
|
221
|
-
echo(`[dry-run] ${name} already in ${f} — would skip`);
|
|
222
|
-
} else {
|
|
223
|
-
verbose(`claude.ai connectors: ${name} already set in ${f} (left as-is)`);
|
|
224
|
-
}
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const target = p(
|
|
230
|
-
ctx.home,
|
|
231
|
-
setting.target(process.env["SHELL"], (f) => existsSync(p(ctx.home, f))),
|
|
232
|
-
);
|
|
233
|
-
if (ctx.dryRun) {
|
|
234
|
-
echo(`[dry-run] append '${setting.line}' to ${target}`);
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
appendFileSync(target, `\n${marker}\n${setting.line}\n`);
|
|
239
|
-
change(`claude.ai connectors disabled via ${target} (start a new shell to apply)`);
|
|
240
|
-
ctx.nextStepTriggers.claudeRestart = true;
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
case "command": {
|
|
244
|
-
const existing = await spawnProcess(setting.probe.command, setting.probe.args, {
|
|
245
|
-
stdio: "ignore",
|
|
246
|
-
});
|
|
247
|
-
if (existing.error === undefined && existing.exitCode === 0) {
|
|
248
|
-
if (ctx.dryRun) echo(`[dry-run] ${name} already in ${setting.location} — would skip`);
|
|
249
|
-
else
|
|
250
|
-
verbose(`claude.ai connectors: ${name} already set in ${setting.location} (left as-is)`);
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const applyCommand = [setting.apply.command, ...setting.apply.args].join(" ");
|
|
255
|
-
if (ctx.dryRun) {
|
|
256
|
-
echo(`[dry-run] ${applyCommand} (${setting.location})`);
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const applied = await spawnProcess(setting.apply.command, setting.apply.args, {
|
|
261
|
-
stdio: "ignore",
|
|
262
|
-
});
|
|
263
|
-
if (applied.error === undefined && applied.exitCode === 0) {
|
|
264
|
-
change(
|
|
265
|
-
`claude.ai connectors disabled via ${setting.apply.command} (open a new terminal to apply)`,
|
|
266
|
-
);
|
|
267
|
-
ctx.nextStepTriggers.claudeRestart = true;
|
|
268
|
-
} else {
|
|
269
|
-
warn(`${applyCommand} failed — ${setting.manualHint}`);
|
|
270
|
-
}
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// -------------------------------------------------------------- summary ----
|
|
277
|
-
|
|
278
|
-
export function claudeSummary(ctx: Ctx, runtime: ClaudeRuntimeState): void {
|
|
279
|
-
const { echo } = ctx.services.logger;
|
|
280
|
-
const claudeDir = p(ctx.home, ".claude");
|
|
281
|
-
echo(`Claude: ${claudeDir}`);
|
|
282
|
-
if (!ctx.dryRun) {
|
|
283
|
-
if (runtime.kind === "ready") {
|
|
284
|
-
echo("Hooks: Bun (statusline, session-start, notify)");
|
|
285
|
-
} else {
|
|
286
|
-
echo(
|
|
287
|
-
"Hooks: migration deferred (Bun unavailable; existing hook/statusline settings preserved)",
|
|
288
|
-
);
|
|
289
|
-
}
|
|
290
|
-
if (ctx.services.deps.probe("claude").state === "present") {
|
|
291
|
-
const installed = readJsonFile(p(claudeDir, "plugins", "installed_plugins.json"));
|
|
292
|
-
const count =
|
|
293
|
-
installed !== undefined && isObject(installed) && isObject(installed["plugins"])
|
|
294
|
-
? Object.keys(installed["plugins"]).length
|
|
295
|
-
: 0;
|
|
296
|
-
echo(`Plugins: ${count} installed (from SoT enabledPlugins + Anthropic auto-installs)`);
|
|
297
|
-
} else {
|
|
298
|
-
echo("Plugins: skipped - claude CLI not installed");
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
export function claudeNextSteps(ctx: Ctx): Array<string> {
|
|
304
|
-
const lines: Array<string> = [];
|
|
305
|
-
if (ctx.verbose || ctx.nextStepTriggers.claudePlugins) {
|
|
306
|
-
lines.push("In a Claude Code session, run /reload-plugins to pick up newly installed plugins.");
|
|
307
|
-
}
|
|
308
|
-
if (ctx.verbose || ctx.nextStepTriggers.claudeRestart) {
|
|
309
|
-
lines.push("Restart Claude Code for hook/env-var changes to take effect.");
|
|
310
|
-
}
|
|
311
|
-
return lines;
|
|
312
|
-
}
|