MCPcopy Create free account
hub / github.com/cortexkit/magic-context / runDoctor

Function runDoctor

packages/cli/src/commands/doctor.ts:33–68  ·  view source on GitHub ↗
(options: RunDoctorOptions)

Source from the content-addressed store, hash-verified

31}
32
33export async function runDoctor(options: RunDoctorOptions): Promise<number> {
34 if (options.clear) return runClear();
35
36 const argv = options.argv ?? [];
37 const adapters = await resolveAdaptersForCommand(argv, {
38 allowMulti: true,
39 verb: "diagnose",
40 });
41
42 if (adapters.length === 0) {
43 log.warn("No harness selected.");
44 return 0;
45 }
46
47 // The v22 backfill commands operate on the SHARED cortexkit DB (harness-
48 // agnostic — there is no per-harness shard for backfill state). Run them
49 // exactly ONCE here, not once per adapter: dispatching to both an OpenCode
50 // and a Pi adapter would run the same rekey/retry/check against the same
51 // physical DB twice, producing confusing doubled output (e.g. the second
52 // pass reports "Re-keyed 0 row(s)" because the first already moved them).
53 if (hasV22Command(options)) {
54 const result = await runV22BackfillCommands(
55 { name: "Magic Context", openDatabase, closeDatabase, log },
56 options,
57 );
58 if (result.handled) return result.exitCode;
59 }
60
61 let anyFailure = false;
62 for (const adapter of adapters) {
63 log.step(`Running doctor for ${adapter.displayName}…`);
64 const code = await dispatchDoctor(adapter, options);
65 if (code !== 0) anyFailure = true;
66 }
67 return anyFailure ? 1 : 0;
68}
69
70async function dispatchDoctor(adapter: HarnessAdapter, options: RunDoctorOptions): Promise<number> {
71 switch (adapter.kind) {

Callers 1

mainFunction · 0.50

Calls 7

hasV22CommandFunction · 0.90
runV22BackfillCommandsFunction · 0.90
runClearFunction · 0.85
dispatchDoctorFunction · 0.85
stepMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected