docks-kit 0.22.28 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +42 -89
- package/README.md +35 -72
- package/cli/docs/command-guards.md +233 -197
- package/cli/docs/flags.md +17 -65
- package/cli/docs/install.md +2 -3
- package/cli/docs/omp-context.md +79 -7
- package/cli/docs/omp-models.md +27 -12
- package/cli/docs/overview.md +7 -18
- package/cli/docs/platforms.md +2 -2
- package/cli/docs/sync-layers.md +14 -60
- package/cli/docs/toolchain.md +12 -81
- package/cli/src/argv.ts +0 -12
- package/cli/src/argvValidate.ts +3 -54
- package/cli/src/commands/docs.ts +3 -15
- package/cli/src/commands/omp.ts +1 -1
- package/cli/src/commands/scratch.ts +1 -1
- package/cli/src/commands/sync.ts +5 -120
- package/cli/src/commands/tidy.ts +1 -1
- package/cli/src/commands/toolchain.ts +4 -12
- package/cli/src/engine-native/DESIGN.md +69 -100
- package/cli/src/engine-native/deps.ts +7 -92
- package/cli/src/engine-native/engineCtx.ts +9 -103
- package/cli/src/engine-native/exec.ts +1 -18
- package/cli/src/engine-native/index.ts +6 -8
- package/cli/src/engine-native/jq.ts +4 -37
- package/cli/src/engine-native/kitDb.ts +21 -37
- package/cli/src/engine-native/modes.ts +3 -132
- package/cli/src/engine-native/ompFastMode.ts +1 -1
- package/cli/src/engine-native/ompOverlay.ts +1 -1
- package/cli/src/engine-native/ompRemovals.ts +24 -3
- package/cli/src/engine-native/ompSession.ts +67 -0
- package/cli/src/engine-native/ompSync.ts +1 -1
- package/cli/src/engine-native/os/darwin.ts +0 -4
- package/cli/src/engine-native/os/index.ts +1 -2
- package/cli/src/engine-native/os/linux.ts +0 -3
- package/cli/src/engine-native/os/posix.ts +2 -47
- package/cli/src/engine-native/os/types.ts +1 -36
- package/cli/src/engine-native/os/windows.ts +0 -50
- package/cli/src/engine-native/parseArgs.ts +7 -180
- package/cli/src/engine-native/parseHelp.ts +4 -44
- package/cli/src/engine-native/scratch.ts +1 -1
- package/cli/src/engine-native/services.ts +1 -2
- package/cli/src/engine-native/sharedTypes.d.ts +1 -41
- package/cli/src/engine-native/syncConcurrency.ts +3 -15
- package/cli/src/engine-native/syncDispatch.ts +30 -143
- package/cli/src/engine-native/toolchain.ts +6 -45
- package/cli/src/engine.ts +0 -75
- package/cli/src/generated/sotPayload.ts +14 -43
- package/cli/src/main.ts +8 -24
- package/cli/src/payload.ts +2 -8
- package/cli/tsconfig.json +1 -3
- package/package.json +3 -5
- package/cli/docs/models.md +0 -58
- package/cli/docs/modifiers.md +0 -52
- package/cli/docs/plugins.md +0 -70
- package/cli/src/checklistPrompt.ts +0 -464
- package/cli/src/commands/harnesses.ts +0 -80
- package/cli/src/commands/model.ts +0 -68
- package/cli/src/commands/models.ts +0 -75
- package/cli/src/commands/plugins.ts +0 -35
- package/cli/src/commands/skills.ts +0 -40
- package/cli/src/commands/status.ts +0 -206
- package/cli/src/efforts.ts +0 -89
- package/cli/src/engine-native/claudeLsp.ts +0 -301
- package/cli/src/engine-native/claudeOptionalPlugins.ts +0 -126
- package/cli/src/engine-native/claudePluginPasses.ts +0 -426
- package/cli/src/engine-native/claudeRemovals.ts +0 -383
- package/cli/src/engine-native/claudeRetired.ts +0 -165
- package/cli/src/engine-native/claudeRuntime.ts +0 -157
- package/cli/src/engine-native/claudeSettings.ts +0 -201
- package/cli/src/engine-native/claudeSettingsModifiers.ts +0 -115
- package/cli/src/engine-native/claudeSync.ts +0 -312
- package/cli/src/engine-native/codexConfig.ts +0 -214
- package/cli/src/engine-native/codexHooks.ts +0 -91
- package/cli/src/engine-native/codexPaths.ts +0 -14
- package/cli/src/engine-native/codexPlugins.ts +0 -315
- package/cli/src/engine-native/codexStatus.ts +0 -25
- package/cli/src/engine-native/codexSync.ts +0 -314
- package/cli/src/engine-native/codexToml.ts +0 -303
- package/cli/src/engine-native/harnesses.ts +0 -138
- package/cli/src/engine-native/liveModels.ts +0 -264
- package/cli/src/engine-native/models.ts +0 -101
- package/cli/src/engine-native/parseModifiers.ts +0 -225
- package/cli/src/engine-native/settings.ts +0 -42
- package/cli/src/engine-native/skillsInstall.ts +0 -135
- package/cli/src/engine-native/skillsLinks.ts +0 -216
- package/cli/src/engine-native/skillsManifest.ts +0 -36
- package/cli/src/engine-native/skillsPrune.ts +0 -117
- package/cli/src/engine-native/skillsRecords.ts +0 -138
- package/cli/src/engine-native/skillsSync.ts +0 -57
- package/cli/src/engine-native/tomlLines.ts +0 -92
- package/cli/src/manifests.ts +0 -145
- package/cli/src/terminalCells.ts +0 -191
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* EngineNative
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* lives there.
|
|
2
|
+
* EngineNative sync dispatch: take the sync and folder locks, run the omp
|
|
3
|
+
* pipeline, then print the summary and advice. Split from index.ts; the
|
|
4
|
+
* `sync`/`toolchain` entry routing still lives there.
|
|
6
5
|
*/
|
|
7
6
|
import { existsSync, mkdirSync, realpathSync } from "node:fs";
|
|
8
|
-
import { basename, dirname, join
|
|
7
|
+
import { basename, dirname, join } from "node:path";
|
|
9
8
|
|
|
10
|
-
import { payloadText } from "../payload";
|
|
11
|
-
import { claudeNextSteps, claudeSummary, claudeSync, type ClaudeRuntimeState } from "./claudeSync";
|
|
12
|
-
import { preflightClaudeSettings } from "./claudeSettings";
|
|
13
|
-
import { codexHome } from "./codexPaths";
|
|
14
|
-
import { codexNextSteps, codexSummary, codexSync } from "./codexSync";
|
|
15
9
|
import type { Ctx } from "./index";
|
|
16
10
|
import { compareCodepoints } from "./jq";
|
|
17
11
|
import { acquireKitLock, releaseKitLock, type KitLock } from "./kitLock";
|
|
@@ -23,17 +17,10 @@ import {
|
|
|
23
17
|
type OmpState,
|
|
24
18
|
type OmpWriteFolders,
|
|
25
19
|
} from "./ompSync";
|
|
26
|
-
import {
|
|
27
|
-
import { ExitError, parseArgs, validateModifierFlags } from "./parseArgs";
|
|
20
|
+
import { ExitError, parseArgs } from "./parseArgs";
|
|
28
21
|
import { folderSyncLockPath, syncLockPath } from "./scratch";
|
|
29
|
-
import {
|
|
30
|
-
runBounded,
|
|
31
|
-
syncConcurrencyForManifest,
|
|
32
|
-
type SyncConcurrency,
|
|
33
|
-
type SyncTask,
|
|
34
|
-
} from "./syncConcurrency";
|
|
35
22
|
|
|
36
|
-
/** The default time that a sync
|
|
23
|
+
/** The default time that a sync waits for another sync to release the sync lock. */
|
|
37
24
|
export const SYNC_LOCK_WAIT_MS = 120_000;
|
|
38
25
|
const SYNC_LOCK_WAIT_ERROR = "DOCKS_KIT_SYNC_LOCK_WAIT_MS must be a non-negative safe integer";
|
|
39
26
|
|
|
@@ -58,9 +45,8 @@ function syncLockWaitMs(err: ErrorSink): number {
|
|
|
58
45
|
|
|
59
46
|
/**
|
|
60
47
|
* The tokens that skip the sync lock. `-h` and `--help` make `parseArgs`
|
|
61
|
-
* print the usage or an error and exit before
|
|
62
|
-
* `--dry-run` sync writes no kit file
|
|
63
|
-
* `kitDb.ts` makes safe for parallel runs.
|
|
48
|
+
* print the usage or an error and exit before the sync writes a file. A
|
|
49
|
+
* `--dry-run` sync writes no kit file.
|
|
64
50
|
*/
|
|
65
51
|
const UNLOCKED_TOKENS: Record<string, true> = { "--dry-run": true, "-h": true, "--help": true };
|
|
66
52
|
|
|
@@ -107,7 +93,7 @@ async function withKitLocks(
|
|
|
107
93
|
* `UNLOCKED_TOKENS`, or `ctx.dryRun` is true. `makeCtx` sets `ctx.dryRun`
|
|
108
94
|
* from the `DRY_RUN` env global only on the channel that reads env globals.
|
|
109
95
|
*/
|
|
110
|
-
|
|
96
|
+
async function withSyncLock(
|
|
111
97
|
ctx: Ctx,
|
|
112
98
|
args: ReadonlyArray<string>,
|
|
113
99
|
body: () => Promise<number>,
|
|
@@ -143,12 +129,12 @@ export function folderLockPaths(folders: ReadonlyArray<string>): Array<string> {
|
|
|
143
129
|
|
|
144
130
|
/**
|
|
145
131
|
* Run `body` under the folder lock of each folder in `folders`. Take it after
|
|
146
|
-
* the sync lock. Syncs of different homes can share
|
|
147
|
-
*
|
|
132
|
+
* the sync lock. Syncs of different homes can share an omp folder, and
|
|
133
|
+
* their home locks differ. A missing folder is created under the
|
|
148
134
|
* locks of its ancestors in the set. A dry run takes no folder lock and
|
|
149
135
|
* creates nothing.
|
|
150
136
|
*/
|
|
151
|
-
|
|
137
|
+
async function withFolderLocks(
|
|
152
138
|
ctx: Ctx,
|
|
153
139
|
folders: ReadonlyArray<string>,
|
|
154
140
|
body: () => Promise<number>,
|
|
@@ -174,150 +160,51 @@ export async function withHomeAndFolderLocks(
|
|
|
174
160
|
}
|
|
175
161
|
|
|
176
162
|
/**
|
|
177
|
-
* Run a sync. The sync lock comes first
|
|
178
|
-
*
|
|
179
|
-
* legacy `state.json`. The folder locks come after `parseArgs` selects the
|
|
180
|
-
* targets.
|
|
163
|
+
* Run a sync. The sync lock comes first, then the folder locks of the omp
|
|
164
|
+
* folders, which `runSync` resolves after `parseArgs` reads the flags.
|
|
181
165
|
*/
|
|
182
166
|
export async function engineSync(ctx: Ctx, args: ReadonlyArray<string>): Promise<number> {
|
|
183
167
|
return await withSyncLock(ctx, args, () => runSync(ctx, args));
|
|
184
168
|
}
|
|
185
169
|
|
|
186
170
|
async function runSync(ctx: Ctx, args: ReadonlyArray<string>): Promise<number> {
|
|
187
|
-
const { err } = ctx.services.logger;
|
|
188
171
|
parseArgs(ctx, args);
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
) {
|
|
198
|
-
ctx.syncConcurrency = Number(configuredConcurrency) as SyncConcurrency;
|
|
199
|
-
} else {
|
|
200
|
-
err("DOCKS_KIT_SYNC_CONCURRENCY must be 1, 2, or 3");
|
|
201
|
-
throw new ExitError(2);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// The folders that hold ownership records or omp files. A writing pipeline
|
|
205
|
-
// creates its folders anyway, so `withFolderLocks` creates each missing one
|
|
206
|
-
// under the locks of its ancestors in the set. The omp folders are resolved
|
|
207
|
-
// once, here: the omp pipeline and its omp children use these paths, so a
|
|
208
|
-
// data root that appears after the locks cannot move them.
|
|
209
|
-
const omp = ctx.syncOmp ? ompWriteFolders(ctx) : undefined;
|
|
210
|
-
const folders = [
|
|
211
|
-
...(ctx.syncCodex ? [codexHome(ctx.home)] : []),
|
|
212
|
-
...(ctx.syncAgents ? [resolve(ctx.agentsDir)] : []),
|
|
213
|
-
...(omp === undefined ? [] : [omp.paths.agentDir, omp.intercomDir, omp.paths.dataRoot]),
|
|
214
|
-
];
|
|
215
|
-
return await withFolderLocks(ctx, folders, () => runPipelines(ctx, omp));
|
|
172
|
+
// The folders that hold omp files. A writing sync creates its folders
|
|
173
|
+
// anyway, so `withFolderLocks` creates each missing one under the locks of
|
|
174
|
+
// its ancestors in the set. The omp folders are resolved once, here: the
|
|
175
|
+
// omp pipeline and its omp children use these paths, so a data root that
|
|
176
|
+
// appears after the locks cannot move them.
|
|
177
|
+
const omp = ompWriteFolders(ctx);
|
|
178
|
+
const folders = [omp.paths.agentDir, omp.intercomDir, omp.paths.dataRoot];
|
|
179
|
+
return await withFolderLocks(ctx, folders, () => runPipeline(ctx, omp));
|
|
216
180
|
}
|
|
217
181
|
|
|
218
|
-
/** Run the
|
|
219
|
-
async function
|
|
182
|
+
/** Run the omp pipeline in the omp folders `omp`, then print the summary and advice. */
|
|
183
|
+
async function runPipeline(ctx: Ctx, omp: OmpWriteFolders): Promise<number> {
|
|
220
184
|
const { acquireTerminal, echo } = ctx.services.logger;
|
|
221
|
-
// An abort-class check runs before any pipeline starts, so the abort stops the whole sync.
|
|
222
|
-
preflightClaudeSettings(ctx);
|
|
223
|
-
|
|
224
|
-
type PipelineResult =
|
|
225
|
-
| { readonly kind: "claude"; readonly runtime: ClaudeRuntimeState }
|
|
226
|
-
| { readonly kind: "codex" }
|
|
227
|
-
| { readonly kind: "skills"; readonly state: SkillsState }
|
|
228
|
-
| { readonly kind: "omp"; readonly state: OmpState };
|
|
229
|
-
interface SelectedPipeline {
|
|
230
|
-
readonly name: string;
|
|
231
|
-
readonly run: SyncTask<PipelineResult>;
|
|
232
|
-
}
|
|
233
185
|
|
|
234
|
-
const
|
|
235
|
-
if (ctx.syncClaude) {
|
|
236
|
-
selected.push({
|
|
237
|
-
name: "Claude",
|
|
238
|
-
run: async () => ({ kind: "claude", runtime: await claudeSync(ctx) }),
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
if (ctx.syncCodex) {
|
|
242
|
-
selected.push({
|
|
243
|
-
name: "Codex",
|
|
244
|
-
run: async () => {
|
|
245
|
-
await codexSync(ctx);
|
|
246
|
-
return { kind: "codex" };
|
|
247
|
-
},
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
if (ctx.syncAgents) {
|
|
251
|
-
selected.push({
|
|
252
|
-
name: "skills",
|
|
253
|
-
run: async () => ({ kind: "skills", state: await skillsSync(ctx) }),
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
if (omp !== undefined) {
|
|
257
|
-
selected.push({
|
|
258
|
-
name: "omp",
|
|
259
|
-
run: async () => ({ kind: "omp", state: await ompSync(ctx, omp) }),
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// A populated skills manifest deploys with `-a claude-code codex`, and symlink healing also writes into Claude's tree.
|
|
264
|
-
ctx.syncConcurrency = syncConcurrencyForManifest(
|
|
265
|
-
ctx.syncConcurrency,
|
|
266
|
-
payloadText("SoT/.agents/skills.txt"),
|
|
267
|
-
ctx.syncClaude,
|
|
268
|
-
ctx.syncAgents,
|
|
269
|
-
);
|
|
270
|
-
|
|
271
|
-
const remaining = new Set(selected.map(({ name }) => name));
|
|
272
|
-
const lease = acquireTerminal(`Syncing ${[...remaining].join(", ")}...`);
|
|
186
|
+
const lease = acquireTerminal("Syncing omp...");
|
|
273
187
|
ctx.terminalLease = lease;
|
|
274
|
-
|
|
275
|
-
try {
|
|
276
|
-
return await run();
|
|
277
|
-
} finally {
|
|
278
|
-
remaining.delete(name);
|
|
279
|
-
if (remaining.size > 0) lease.update(`Syncing ${[...remaining].join(", ")}...`);
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
let results: Array<PipelineResult>;
|
|
188
|
+
let ompState: OmpState;
|
|
283
189
|
try {
|
|
284
190
|
try {
|
|
285
|
-
|
|
191
|
+
ompState = await ompSync(ctx, omp);
|
|
286
192
|
} finally {
|
|
287
193
|
lease.release();
|
|
288
194
|
ctx.terminalLease = undefined;
|
|
289
195
|
}
|
|
290
196
|
} catch (error) {
|
|
291
|
-
// A rejected pipeline skips the summary. Print the failures that
|
|
197
|
+
// A rejected pipeline skips the summary. Print the failures that it recorded before it stopped.
|
|
292
198
|
printFailures(ctx);
|
|
293
199
|
throw error;
|
|
294
200
|
}
|
|
295
201
|
|
|
296
|
-
const claudeRan = ctx.syncClaude;
|
|
297
|
-
const codexRan = ctx.syncCodex;
|
|
298
|
-
let claudeRuntime: ClaudeRuntimeState | undefined;
|
|
299
|
-
let skillsState: SkillsState | undefined;
|
|
300
|
-
let ompState: OmpState | undefined;
|
|
301
|
-
for (const result of results) {
|
|
302
|
-
if (result.kind === "claude") claudeRuntime = result.runtime;
|
|
303
|
-
else if (result.kind === "skills") skillsState = result.state;
|
|
304
|
-
else if (result.kind === "omp") ompState = result.state;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
202
|
echo("");
|
|
308
203
|
echo("--- Sync complete ---");
|
|
309
204
|
echo(`Repo: ${ctx.repoDir}`);
|
|
310
|
-
|
|
311
|
-
if (codexRan) codexSummary(ctx);
|
|
312
|
-
if (skillsState !== undefined) skillsSummary(ctx, skillsState);
|
|
313
|
-
if (ompState !== undefined) ompSummary(ctx, ompState);
|
|
205
|
+
ompSummary(ctx, ompState);
|
|
314
206
|
|
|
315
|
-
const advice =
|
|
316
|
-
...(claudeRan ? claudeNextSteps(ctx) : []),
|
|
317
|
-
...(codexRan ? codexNextSteps(ctx) : []),
|
|
318
|
-
...(skillsState !== undefined ? skillsNextSteps(ctx) : []),
|
|
319
|
-
...(ompState !== undefined ? ompNextSteps(ctx) : []),
|
|
320
|
-
];
|
|
207
|
+
const advice = ompNextSteps(ctx);
|
|
321
208
|
if (advice.length > 0) {
|
|
322
209
|
echo("");
|
|
323
210
|
for (const line of advice) echo(line);
|
|
@@ -38,8 +38,8 @@ export function isNewer(a: string, b: string): boolean {
|
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* A readable installed version strictly older than the manifest floor. The
|
|
41
|
-
* doctor row and
|
|
42
|
-
*
|
|
41
|
+
* doctor row and `toolchain ensure` must agree on that judgement, so both ask
|
|
42
|
+
* here rather than re-deriving it.
|
|
43
43
|
*/
|
|
44
44
|
export function belowFloor(installed: string, floor: string): boolean {
|
|
45
45
|
return installed !== "" && floor !== "" && isNewer(floor, installed);
|
|
@@ -57,33 +57,16 @@ function firstLineField(out: string, index: number): string {
|
|
|
57
57
|
export async function installedVersion(ctx: Ctx, tool: ToolId): Promise<string> {
|
|
58
58
|
const version = () => ctx.services.deps.version(tool);
|
|
59
59
|
switch (tool) {
|
|
60
|
-
case "claude":
|
|
61
|
-
return firstLineField(await version(), 0);
|
|
62
|
-
case "codex":
|
|
63
|
-
return firstLineField(await version(), -1);
|
|
64
60
|
case "git":
|
|
65
61
|
return firstLineField(await version(), 2);
|
|
66
|
-
case "node":
|
|
67
|
-
return (await version()).replace(/^v/, "");
|
|
68
62
|
case "jq":
|
|
69
63
|
return (await version()).replace(/^jq-/, "");
|
|
70
64
|
case "curl":
|
|
71
|
-
case "tsc":
|
|
72
|
-
// `rust-analyzer --version` prints "rust-analyzer <version>", where the
|
|
73
|
-
// version tail also carries a commit and a date in parentheses.
|
|
74
|
-
case "rust-analyzer":
|
|
75
65
|
return firstLineField(await version(), 1);
|
|
76
66
|
case "bun":
|
|
77
67
|
case "omp":
|
|
78
68
|
case "npm":
|
|
79
69
|
return await version();
|
|
80
|
-
case "bwrap":
|
|
81
|
-
return firstLineField(await version(), 1);
|
|
82
|
-
case "ffplay":
|
|
83
|
-
return firstLineField(await version(), 2).replace(/-.*$/, "");
|
|
84
|
-
case "intelephense":
|
|
85
|
-
case "typescript-language-server":
|
|
86
|
-
return (await version()).trim();
|
|
87
70
|
default:
|
|
88
71
|
return "";
|
|
89
72
|
}
|
|
@@ -108,9 +91,7 @@ export async function report(ctx: Ctx): Promise<void> {
|
|
|
108
91
|
const dash = (v: string): string => (v !== "" ? v : "-");
|
|
109
92
|
if (kind === "pin") {
|
|
110
93
|
const via = field(tool, "via");
|
|
111
|
-
echo(
|
|
112
|
-
row([tool, kind, `(${via !== "" ? via : "npx"})`, dash(floor), dash(verified), "pinned"]),
|
|
113
|
-
);
|
|
94
|
+
echo(row([tool, kind, `(${via})`, dash(floor), dash(verified), "pinned"]));
|
|
114
95
|
continue;
|
|
115
96
|
}
|
|
116
97
|
let installed: string;
|
|
@@ -152,9 +133,8 @@ function upstreamSpec(tool: string): JsonObject | undefined {
|
|
|
152
133
|
}
|
|
153
134
|
|
|
154
135
|
function upstreamLabel(spec: JsonObject): string {
|
|
155
|
-
const { npm, github
|
|
156
|
-
if (typeof npm === "string")
|
|
157
|
-
return typeof line === "string" ? `npm ${npm} (${line}.x)` : `npm ${npm}`;
|
|
136
|
+
const { npm, github } = spec;
|
|
137
|
+
if (typeof npm === "string") return `npm ${npm}`;
|
|
158
138
|
return typeof github === "string" ? `github ${github}` : "-";
|
|
159
139
|
}
|
|
160
140
|
|
|
@@ -176,26 +156,7 @@ async function lookupUpstream(
|
|
|
176
156
|
fetchImpl: FetchLike,
|
|
177
157
|
env: NodeJS.ProcessEnv,
|
|
178
158
|
): Promise<UpstreamResult> {
|
|
179
|
-
const { npm,
|
|
180
|
-
if (typeof npm === "string" && typeof line === "string") {
|
|
181
|
-
// The registry rejects ranges, so read the packument and pick the newest release on the line.
|
|
182
|
-
const result = await fetchJson(fetchImpl, `https://registry.npmjs.org/${npm}`, {
|
|
183
|
-
Accept: "application/vnd.npm.install-v1+json",
|
|
184
|
-
});
|
|
185
|
-
if (!result.ok) return result;
|
|
186
|
-
const versions = result.body["versions"];
|
|
187
|
-
if (versions === undefined || !isObject(versions))
|
|
188
|
-
return { ok: false, reason: "invalid response" };
|
|
189
|
-
if (!/^\d+$/.test(line)) return { ok: false, reason: `invalid line ${line}` };
|
|
190
|
-
const pattern = new RegExp(`^${line}\\.\\d+\\.\\d+$`);
|
|
191
|
-
let newest = "";
|
|
192
|
-
for (const version of Object.keys(versions)) {
|
|
193
|
-
if (pattern.test(version) && (newest === "" || isNewer(version, newest))) newest = version;
|
|
194
|
-
}
|
|
195
|
-
return newest === ""
|
|
196
|
-
? { ok: false, reason: `no ${line}.x release` }
|
|
197
|
-
: { ok: true, version: newest };
|
|
198
|
-
}
|
|
159
|
+
const { npm, github, tagPrefix } = spec;
|
|
199
160
|
if (typeof npm === "string") {
|
|
200
161
|
const result = await fetchJson(fetchImpl, `https://registry.npmjs.org/${npm}/latest`, {
|
|
201
162
|
Accept: "application/json",
|
package/cli/src/engine.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { CliError } from "effect/cli";
|
|
2
2
|
import { Console, Effect } from "effect";
|
|
3
|
-
import { spawnSync } from "node:child_process";
|
|
4
3
|
import { runEngineNative } from "./engine-native";
|
|
5
|
-
import { ENV_GLOBAL_KEYS } from "./engine-native/engineCtx";
|
|
6
|
-
import { ExitError } from "./engine-native/parseArgs";
|
|
7
|
-
import { makeEngineServices } from "./engine-native/services";
|
|
8
4
|
import { targetForHost } from "./engine-native/os/targets";
|
|
9
|
-
import { kitHome } from "./kitHome";
|
|
10
5
|
import { DependencyManagerService, LoggerService, PlatformService } from "./services";
|
|
11
6
|
|
|
12
7
|
/**
|
|
@@ -32,17 +27,6 @@ const requireSupportedHost = () => {
|
|
|
32
27
|
// executable can be compiled, so absence means false.
|
|
33
28
|
export const compiled: boolean = typeof Bun !== "undefined" && Bun.isStandaloneExecutable === true;
|
|
34
29
|
|
|
35
|
-
export class EngineCaptureError extends ExitError {
|
|
36
|
-
constructor(
|
|
37
|
-
readonly diagnostic: string,
|
|
38
|
-
code: number,
|
|
39
|
-
) {
|
|
40
|
-
super(code);
|
|
41
|
-
this.name = "EngineCaptureError";
|
|
42
|
-
this.message = diagnostic;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
30
|
const failureMessage = (error: unknown): string => {
|
|
47
31
|
if (error instanceof Error && error.message !== "") return error.message;
|
|
48
32
|
return typeof error === "string" && error !== "" ? error : "unknown error";
|
|
@@ -70,65 +54,6 @@ export const engine = (args: ReadonlyArray<string>) =>
|
|
|
70
54
|
}
|
|
71
55
|
});
|
|
72
56
|
|
|
73
|
-
// The capture child must not inherit the env globals or a caller's channel
|
|
74
|
-
// selection in any spelling.
|
|
75
|
-
const CAPTURE_DROPPED_KEYS: ReadonlyArray<string> = [...ENV_GLOBAL_KEYS, "DOCKS_KIT_ENGINE"];
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Build the capture child environment. Windows environment names are
|
|
79
|
-
* case-insensitive, so a key such as `claude_compact_window` also matches
|
|
80
|
-
* there. POSIX names stay case-sensitive.
|
|
81
|
-
*/
|
|
82
|
-
const captureChildEnv = (): NodeJS.ProcessEnv => {
|
|
83
|
-
const foldCase = process.platform === "win32";
|
|
84
|
-
const env: NodeJS.ProcessEnv = {};
|
|
85
|
-
for (const [name, value] of Object.entries(process.env)) {
|
|
86
|
-
if (value === undefined) continue;
|
|
87
|
-
if (CAPTURE_DROPPED_KEYS.includes(foldCase ? name.toUpperCase() : name)) continue;
|
|
88
|
-
env[name] = value;
|
|
89
|
-
}
|
|
90
|
-
env["DOCKS_KIT_ENGINE"] = "native-capture";
|
|
91
|
-
return env;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
/** Run the engine capturing stdout (engine logs/warns go to stderr and pass through). */
|
|
95
|
-
export const engineCapture = (args: ReadonlyArray<string>) =>
|
|
96
|
-
Effect.gen(function* () {
|
|
97
|
-
yield* requireSupportedHost();
|
|
98
|
-
if (bashEngineRequested()) {
|
|
99
|
-
return yield* bail(bashRemovedMessage, 2);
|
|
100
|
-
}
|
|
101
|
-
// The child runs the native-capture channel, which ignores env globals even
|
|
102
|
-
// when Bun reloads them from a project `.env`. The child environment also
|
|
103
|
-
// omits them, so a captured public command behaves like an in-process one.
|
|
104
|
-
const childEnv = captureChildEnv();
|
|
105
|
-
const res = yield* Effect.sync(() =>
|
|
106
|
-
// Child process (capture channel): runEngineNative writes straight to
|
|
107
|
-
// process.stdout, so in-process capture is not possible.
|
|
108
|
-
spawnSync(
|
|
109
|
-
process.execPath,
|
|
110
|
-
compiled ? [...args] : [`${kitHome()}/cli/src/main.ts`, ...args],
|
|
111
|
-
{
|
|
112
|
-
env: childEnv,
|
|
113
|
-
encoding: "utf8",
|
|
114
|
-
stdio: ["ignore", "pipe", "inherit"],
|
|
115
|
-
},
|
|
116
|
-
),
|
|
117
|
-
);
|
|
118
|
-
if (res.error !== undefined || res.status !== 0) {
|
|
119
|
-
const reasons = new Array<string>();
|
|
120
|
-
if (typeof res.status === "number") reasons.push(`exit ${res.status}`);
|
|
121
|
-
if (res.signal !== null) reasons.push(`signal ${res.signal}`);
|
|
122
|
-
if (res.error !== undefined) reasons.push(`spawn error: ${res.error.message}`);
|
|
123
|
-
if (reasons.length === 0) reasons.push("no child status");
|
|
124
|
-
const diagnostic = `engine capture failed for '${args.join(" ") || "default"}': ${reasons.join("; ")}`;
|
|
125
|
-
makeEngineServices().logger.err(diagnostic);
|
|
126
|
-
const code = typeof res.status === "number" && res.status !== 0 ? res.status : 1;
|
|
127
|
-
return yield* Effect.fail(new EngineCaptureError(diagnostic, code));
|
|
128
|
-
}
|
|
129
|
-
return res.stdout ?? "";
|
|
130
|
-
});
|
|
131
|
-
|
|
132
57
|
/** Print a message to stderr and exit — for CLI-side validation failures. */
|
|
133
58
|
export const bail = (message: string, code = 2) =>
|
|
134
59
|
Console.error(message).pipe(Effect.andThen(Effect.sync(() => process.exit(code))));
|