context-doctor 0.35.0 → 0.36.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/dist/doctor.js CHANGED
@@ -16,7 +16,8 @@ import { ledgerPath, readLedger } from "./ledger.js";
16
16
  import { loadConfig } from "./config.js";
17
17
  import { codexRouting } from "./codexroute.js";
18
18
  import { CURSOR_HOOK_EVENTS } from "./install.js";
19
- import { binOnPath, claudeCodeInstallsFromEnv, claudeInstalledCopies, codexMcpEntry, geminiCliPresent, geminiSettingsPath, isEmptyStub, isOurPluginKey, launcherNamesMissingPackage } from "./install.js";
19
+ import { binOnPath, claudeCodeInstallsFromEnv, claudeInstalledCopies, codexMcpEntry, copilotPresent, geminiCliPresent, geminiSettingsPath, isEmptyStub, isOurPluginKey, launcherNamesMissingPackage } from "./install.js";
20
+ import { COPILOT_HOOK_EVENT, copilotHookFilePath, copilotLegacyConfigPath, copilotMcpConfigPath, copilotSettingsPath, isOurCopilotEntry, vsCodeUserDirs } from "./copilot.js";
20
21
  import { describeDesktopUsage, desktopUsage } from "./desktopusage.js";
21
22
  import { withInvocation } from "./invocation.js";
22
23
  import { describeInstalls, modelSwitchReadiness, PRE_MODEL_SWITCH_SINCE } from "./modelswitch.js";
@@ -209,6 +210,94 @@ export function devinCheck(home = homedir()) {
209
210
  parts.push(`Devin Desktop found (${app.replace(home, "~")}): its Cascade hooks pass a transcript to one event only, after a response, too late to steer it`);
210
211
  return { label, status: "skip", detail: `${parts.join("; ")}. Not supported yet; the MCP tools work in any MCP client` };
211
212
  }
213
+ /** "~/..." for a path under the home directory. */
214
+ function tilde(p) {
215
+ const home = homedir();
216
+ return p.startsWith(home) ? "~" + p.slice(home.length) : p;
217
+ }
218
+ /**
219
+ * The Copilot session-start hook: registered, its command resolves, hooks
220
+ * not switched off, and when it last ran (from the ledger, when there is one).
221
+ * What it does not do is said too: no size checks, since Copilot passes a
222
+ * transcript only to hooks that cannot add context.
223
+ */
224
+ function copilotHookCheck(mcp, missingHook) {
225
+ const label = "Copilot hook";
226
+ const path = copilotHookFilePath();
227
+ let config;
228
+ try {
229
+ config = readConfig(path, ["version"]);
230
+ }
231
+ catch (e) {
232
+ return { label, status: "fail", detail: `${tilde(path)} is not valid JSON (${e.message}); Copilot skips it` };
233
+ }
234
+ if (config !== undefined && (typeof config !== "object" || Array.isArray(config)))
235
+ return { label, status: "fail", detail: `${tilde(path)} is not a JSON object; Copilot skips it — delete it and re-run: context-doctor install` };
236
+ const entry = (Array.isArray(config?.hooks?.[COPILOT_HOOK_EVENT]) ? config.hooks[COPILOT_HOOK_EVENT] : []).find(isOurCopilotEntry);
237
+ if (!entry)
238
+ return missingHook(label, mcp);
239
+ // The runtime loads no hooks at all from a file whose version is not 1.
240
+ if (config?.version !== 1)
241
+ return { label, status: "fail", detail: `${tilde(path)} says "version": ${JSON.stringify(config?.version)}, and Copilot loads hooks only from version 1 files: set it to 1` };
242
+ const missing = hookBinaryMissing(String(entry.command ?? ""));
243
+ if (missing)
244
+ return { label, status: "fail", detail: `registered, but ${missing} no longer exists — re-run: context-doctor install` };
245
+ // disableAllHooks in the hook file, settings.json, or the older config.json.
246
+ const off = [path, copilotSettingsPath(), copilotLegacyConfigPath()].find((p) => {
247
+ if (p === path)
248
+ return config?.disableAllHooks === true;
249
+ try {
250
+ return JSON.parse(readFileSync(p, "utf8"))?.disableAllHooks === true;
251
+ }
252
+ catch {
253
+ return false; // absent or unreadable: hooks stay on
254
+ }
255
+ });
256
+ if (off)
257
+ return { label, status: "fail", detail: `registered, but disableAllHooks is true in ${tilde(off)}, so Copilot runs no hooks` };
258
+ // The rules name the MCP tools: without the server they point at nothing.
259
+ if (mcp.status !== "ok")
260
+ return { label, status: "warn", detail: `sessionStart in ${tilde(path)} adds the standing rules, which name context-doctor's MCP tools, but the MCP server is not wired (above): re-run context-doctor install` };
261
+ const last = readLedger().filter((e) => e.ev === "session_rules" && e.app === "copilot").pop();
262
+ const ran = last ? ` Last ran ${new Date(last.ts).toISOString().slice(0, 16).replace("T", " ")}.` : "";
263
+ return {
264
+ label,
265
+ status: "ok",
266
+ detail: `sessionStart in ${tilde(path)}: each new or resumed Copilot session gets the standing context rules.${ran} No size checks there: Copilot gives a transcript only to hooks that cannot add context`,
267
+ };
268
+ }
269
+ /**
270
+ * VS Code forwards the servers in its own user mcp.json into Copilot
271
+ * sessions, beside ~/.copilot/mcp-config.json. One that also starts
272
+ * context-doctor, under any name, can load the tools twice. VS Code's file
273
+ * may hold comments, so it is searched as text when it does not parse.
274
+ */
275
+ function vsCodeDuplicateCheck() {
276
+ for (const dir of vsCodeUserDirs()) {
277
+ const path = join(dir, "mcp.json");
278
+ let raw;
279
+ try {
280
+ raw = readFileSync(path, "utf8");
281
+ }
282
+ catch {
283
+ continue;
284
+ }
285
+ if (!raw.includes("context-doctor"))
286
+ continue;
287
+ let names = [];
288
+ try {
289
+ const servers = JSON.parse(raw)?.servers ?? {};
290
+ names = Object.entries(servers).filter(([, v]) => JSON.stringify(v).includes("context-doctor")).map(([k]) => k);
291
+ }
292
+ catch { /* JSONC: the text search above is the evidence */ }
293
+ return {
294
+ label: "Copilot MCP",
295
+ status: "warn",
296
+ detail: `VS Code's ${tilde(path)} also starts context-doctor${names.length ? ` (as ${names.map((n) => `"${n}"`).join(", ")})` : ""}; VS Code forwards it into Copilot sessions beside ${tilde(copilotMcpConfigPath())}, so the tools can load twice: remove one`,
297
+ };
298
+ }
299
+ return undefined;
300
+ }
212
301
  /** Claude Code's disableAllHooks: when true, no hook of anyone's runs. */
213
302
  function hooksDisabled(layers) {
214
303
  return layers.reduce((off, s) => (typeof s.disableAllHooks === "boolean" ? s.disableAllHooks : off), false);
@@ -409,6 +498,30 @@ export async function runDoctor() {
409
498
  checks.push({ label: "Gemini CLI", status: "skip", detail: "not detected" });
410
499
  }
411
500
  checks.push(devinCheck());
501
+ // GitHub Copilot (CLI, app, VS Code): MCP in ~/.copilot/mcp-config.json,
502
+ // the sessionStart hook in a hook file of our own.
503
+ if (copilotPresent()) {
504
+ const mcpPath = copilotMcpConfigPath();
505
+ let copilotMcp;
506
+ try {
507
+ copilotMcp = readConfig(mcpPath) === undefined
508
+ ? { label: "Copilot MCP", status: "skip", detail: NOT_INSTALLED }
509
+ : checkMcpEntry("Copilot MCP", mcpPath);
510
+ }
511
+ catch (e) {
512
+ copilotMcp = { label: "Copilot MCP", status: "fail", detail: `${tilde(mcpPath)} is not valid JSON (${e.message})` };
513
+ }
514
+ if (copilotMcp.status === "ok")
515
+ copilotMcp.detail += ` in ${tilde(mcpPath)} (Copilot CLI, the Copilot app and VS Code's Copilot sessions)`;
516
+ checks.push(copilotMcp);
517
+ const duplicate = copilotMcp.status === "ok" ? vsCodeDuplicateCheck() : undefined;
518
+ if (duplicate)
519
+ checks.push(duplicate);
520
+ checks.push(copilotHookCheck(copilotMcp, missingHook));
521
+ }
522
+ else {
523
+ checks.push({ label: "GitHub Copilot", status: "skip", detail: "not detected (Copilot CLI, the GitHub Copilot app, or VS Code)" });
524
+ }
412
525
  // Cursor: its agent gets the guidance through native hooks (the Claude
413
526
  // Code hook it also runs cannot add context there). Whether the text then
414
527
  // reaches the model depends on the Cursor version, and Cursor logs only
package/dist/hook.d.ts CHANGED
@@ -29,4 +29,4 @@ export interface HookInput {
29
29
  * DeprecationWarning into the user's session (and will throw on a later one).
30
30
  */
31
31
  export declare function hookInput(raw: unknown): HookInput;
32
- export declare function runHook(): Promise<void>;
32
+ export declare function runHook(app?: "copilot"): Promise<void>;
package/dist/hook.js CHANGED
@@ -14,8 +14,9 @@
14
14
  import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
15
15
  import { createHash } from "node:crypto";
16
16
  import { homedir } from "node:os";
17
- import { join } from "node:path";
18
- import { recordLedger, statePath } from "./ledger.js";
17
+ import { dirname, join } from "node:path";
18
+ import { ledgerPath, recordLedger, statePath } from "./ledger.js";
19
+ import { copilotSessionStartOutput } from "./copilot.js";
19
20
  import { parseConversation } from "./parse.js";
20
21
  import { profileConversation } from "./profile.js";
21
22
  import { parseSessionFile } from "./session.js";
@@ -164,9 +165,30 @@ export function hookInput(raw) {
164
165
  delete out.workspace_roots;
165
166
  return out;
166
167
  }
167
- export async function runHook() {
168
+ export async function runHook(app) {
168
169
  // A hook must never break the user's prompt: any failure exits silently.
169
170
  try {
171
+ // GitHub Copilot (`hook copilot`, its sessionStart): the standing rules,
172
+ // nothing else. No Copilot hook that can add context gets a transcript,
173
+ // and Copilot never routes through autopilot, so there is no self-heal.
174
+ if (app === "copilot") {
175
+ // An input that does not parse (empty, a BOM, cut short) is still a
176
+ // session start: the rules go in rather than nothing.
177
+ let input = {};
178
+ try {
179
+ input = JSON.parse((await readStdin()).replace(/^\uFEFF/, ""));
180
+ }
181
+ catch { /* not JSON: answer as for an empty input */ }
182
+ const out = copilotSessionStartOutput(input);
183
+ if (out) {
184
+ process.stdout.write(out + "\n");
185
+ // Evidence for `doctor`, only where the ledger's folder already is:
186
+ // creating ~/.claude would make install and doctor see Claude Code.
187
+ if (existsSync(dirname(ledgerPath())))
188
+ recordLedger({ ev: "session_rules", app: "copilot" });
189
+ }
190
+ return;
191
+ }
170
192
  // Autopilot self-heal: this prompt's request is about to go to the proxy,
171
193
  // so if the proxy died, start it now. One existsSync when autopilot is
172
194
  // off; a ~1ms localhost health check when it is on and healthy.
package/dist/index.d.ts CHANGED
@@ -40,3 +40,5 @@ export * from "./compactquality.js";
40
40
  export * from "./precompact.js";
41
41
  export * from "./cachemisses.js";
42
42
  export * from "./modelswitch.js";
43
+ export * from "./ab.js";
44
+ export * from "./abtasks.js";
package/dist/index.js CHANGED
@@ -35,3 +35,5 @@ export * from "./compactquality.js";
35
35
  export * from "./precompact.js";
36
36
  export * from "./cachemisses.js";
37
37
  export * from "./modelswitch.js";
38
+ export * from "./ab.js";
39
+ export * from "./abtasks.js";
package/dist/install.d.ts CHANGED
@@ -137,6 +137,22 @@ export declare function codexMcpEntry(toml: string): {
137
137
  command?: string;
138
138
  args: string[];
139
139
  } | undefined;
140
+ /** Copilot is here: its home exists, its CLI is on PATH, or VS Code (which ships Copilot) is installed. */
141
+ export declare function copilotPresent(): boolean;
142
+ /**
143
+ * The hook entry. `command` is the cross-platform field both harnesses read
144
+ * (Copilot copies it to bash and powershell). PowerShell runs a quoted path
145
+ * only after `&`, so a quoted global binary gets its own powershell line.
146
+ */
147
+ export declare function copilotHookEntry(): Record<string, unknown>;
148
+ /** A JSON value that is an object (not an array, null or a scalar). */
149
+ export declare function isPlainObject(v: unknown): v is Record<string, any>;
150
+ /**
151
+ * readJson, refusing anything but an object: `[1]` or `"x"` read fine as
152
+ * JSON, and fields set on them vanish when the file is written back, so
153
+ * install reported ✓ over a file it had left as it was.
154
+ */
155
+ export declare function readJsonObject(path: string): Record<string, any>;
140
156
  /** Outcome of an install run, so the CLI can set a truthful exit code. */
141
157
  export interface InstallResult {
142
158
  /** Detected targets that could not be configured, with the reason. */
package/dist/install.js CHANGED
@@ -12,6 +12,7 @@ import { delimiter, dirname, join, sep } from "node:path";
12
12
  import { fileURLToPath } from "node:url";
13
13
  import { selfCommand, withInvocation } from "./invocation.js";
14
14
  import { claudeCodeInstalls, describeInstalls, modelSwitchReadiness, PRE_MODEL_SWITCH_SINCE } from "./modelswitch.js";
15
+ import { COPILOT_HOOK_EVENT, copilotHome, copilotHookFilePath, copilotMcpConfigPath, isOurCopilotEntry, vsCodePresent } from "./copilot.js";
15
16
  function claudeDesktopConfigPath() {
16
17
  switch (platform()) {
17
18
  case "darwin": return join(homedir(), "Library", "Application Support", "Claude", "claude_desktop_config.json");
@@ -701,6 +702,170 @@ function uninstallCodex() {
701
702
  }
702
703
  removeSkill(join(dir, "skills", "context-doctor"), "Codex skill");
703
704
  }
705
+ // -- GitHub Copilot: the Copilot CLI, the GitHub Copilot app, and VS Code's
706
+ // agent sessions (see copilot.ts for what was verified and where). Two files:
707
+ // the MCP server in ~/.copilot/mcp-config.json, and a hook file of our own,
708
+ // ~/.copilot/hooks/context-doctor.json, whose sessionStart adds the standing
709
+ // context rules to each new session. No size check: no Copilot hook that can
710
+ // add context is given a transcript to measure.
711
+ /** Copilot is here: its home exists, its CLI is on PATH, or VS Code (which ships Copilot) is installed. */
712
+ export function copilotPresent() {
713
+ return existsSync(copilotHome()) || binOnPath("copilot") !== null || vsCodePresent();
714
+ }
715
+ /** The MCP entry in Copilot's portable format. */
716
+ function copilotMcpEntry(entry) {
717
+ return { type: "local", command: entry.command, args: entry.args, tools: ["*"] };
718
+ }
719
+ /**
720
+ * The hook entry. `command` is the cross-platform field both harnesses read
721
+ * (Copilot copies it to bash and powershell). PowerShell runs a quoted path
722
+ * only after `&`, so a quoted global binary gets its own powershell line.
723
+ */
724
+ export function copilotHookEntry() {
725
+ const command = cliCommand("hook copilot");
726
+ return { type: "command", command, ...(command.startsWith('"') ? { powershell: `& ${command}` } : {}), timeoutSec: 10 };
727
+ }
728
+ /** A JSON value that is an object (not an array, null or a scalar). */
729
+ export function isPlainObject(v) {
730
+ return v !== null && typeof v === "object" && !Array.isArray(v);
731
+ }
732
+ /**
733
+ * readJson, refusing anything but an object: `[1]` or `"x"` read fine as
734
+ * JSON, and fields set on them vanish when the file is written back, so
735
+ * install reported ✓ over a file it had left as it was.
736
+ */
737
+ export function readJsonObject(path) {
738
+ const config = readJson(path);
739
+ if (!isPlainObject(config))
740
+ throw new Error(`${path} is not a JSON object; fix or remove it, then re-run. Nothing was changed.`);
741
+ return config;
742
+ }
743
+ /**
744
+ * Folders install created in Copilot's home, recorded in a marker there so
745
+ * uninstall removes only those (a ~/.copilot that was already there, even
746
+ * empty, is the user's): "" for the home itself, "hooks" for its hooks folder.
747
+ */
748
+ const COPILOT_MARKER = ".context-doctor-created.json";
749
+ function copilotCreated() {
750
+ try {
751
+ const raw = JSON.parse(readFileSync(join(copilotHome(), COPILOT_MARKER), "utf8"));
752
+ return Array.isArray(raw?.created) ? raw.created.filter((d) => d === "" || d === "hooks") : [];
753
+ }
754
+ catch {
755
+ return [];
756
+ }
757
+ }
758
+ function installCopilot(entry, failures) {
759
+ if (!copilotPresent())
760
+ return;
761
+ const home = copilotHome();
762
+ const created = ["", "hooks"].filter((d) => !existsSync(join(home, d)));
763
+ const remember = () => {
764
+ const made = created.filter((d) => existsSync(join(home, d)));
765
+ if (made.length === 0)
766
+ return;
767
+ const all = [...new Set([...copilotCreated(), ...made])];
768
+ writeFileSync(join(home, COPILOT_MARKER), JSON.stringify({ created: all }) + "\n");
769
+ };
770
+ let mcpOk = false;
771
+ try {
772
+ const path = copilotMcpConfigPath();
773
+ const config = readJsonObject(path);
774
+ if (config.mcpServers !== undefined && !isPlainObject(config.mcpServers)) {
775
+ throw new Error(`"mcpServers" in ${path} is not an object; fix it, then re-run. Nothing was changed.`);
776
+ }
777
+ config.mcpServers = config.mcpServers ?? {};
778
+ const want = copilotMcpEntry(entry);
779
+ if (JSON.stringify(config.mcpServers["context-doctor"]) !== JSON.stringify(want)) {
780
+ config.mcpServers["context-doctor"] = want;
781
+ writeJsonWithBackup(path, config);
782
+ }
783
+ mcpOk = true;
784
+ console.log(`✓ GitHub Copilot: MCP server added (${path})`);
785
+ }
786
+ catch (e) {
787
+ console.error(`✗ GitHub Copilot MCP: ${e.message}`);
788
+ failures.push("GitHub Copilot MCP");
789
+ }
790
+ // The hook's rules name the MCP tools: without the server they would
791
+ // point the model at tools that are not there, so no hook without it.
792
+ if (!mcpOk) {
793
+ console.log("– GitHub Copilot session-start hook not written: its rules name the MCP tools, which could not be added. Fix the file above and re-run install.");
794
+ remember();
795
+ return;
796
+ }
797
+ try {
798
+ const path = copilotHookFilePath();
799
+ // The file is ours, so it is never backed up; entries someone added to it are kept.
800
+ const config = readJsonObject(path);
801
+ if (config.version !== undefined && config.version !== 1) {
802
+ throw new Error(`${path} says "version": ${JSON.stringify(config.version)}; Copilot loads hooks only from version 1 files. Set it to 1 or delete the file, then re-run.`);
803
+ }
804
+ if (config.hooks !== undefined && !isPlainObject(config.hooks))
805
+ throw new Error(`"hooks" in ${path} is not an object; fix it or delete the file, then re-run. Nothing was changed.`);
806
+ const current = config.hooks?.[COPILOT_HOOK_EVENT];
807
+ if (current !== undefined && !Array.isArray(current)) {
808
+ throw new Error(`"hooks.${COPILOT_HOOK_EVENT}" in ${path} is not a list; fix it or delete the file, then re-run. Nothing was changed.`);
809
+ }
810
+ config.version = 1;
811
+ config.hooks = config.hooks ?? {};
812
+ const entries = current ?? [];
813
+ const want = copilotHookEntry();
814
+ const ours = entries.filter(isOurCopilotEntry);
815
+ if (!(ours.length === 1 && JSON.stringify(ours[0]) === JSON.stringify(want))) {
816
+ config.hooks[COPILOT_HOOK_EVENT] = [...entries.filter((e) => !isOurCopilotEntry(e)), want];
817
+ mkdirSync(dirname(path), { recursive: true });
818
+ writeFileSync(path, JSON.stringify(config, null, 2));
819
+ }
820
+ console.log(`✓ GitHub Copilot session-start hook installed (${path}): each new or resumed session gets the standing context rules`);
821
+ }
822
+ catch (e) {
823
+ console.error(`✗ GitHub Copilot hook: ${e.message}`);
824
+ failures.push("GitHub Copilot hook");
825
+ }
826
+ remember();
827
+ }
828
+ function uninstallCopilotMcp() {
829
+ const mcp = copilotMcpConfigPath();
830
+ if (!existsSync(mcp))
831
+ return;
832
+ const config = readJson(mcp);
833
+ if (isPlainObject(config) && isPlainObject(config.mcpServers) && config.mcpServers["context-doctor"]) {
834
+ delete config.mcpServers["context-doctor"];
835
+ writeUninstalled(mcp, config);
836
+ done("✓ GitHub Copilot: MCP server removed");
837
+ }
838
+ }
839
+ function uninstallCopilotHook() {
840
+ const hookFile = copilotHookFilePath();
841
+ if (!existsSync(hookFile))
842
+ return;
843
+ const config = readJson(hookFile);
844
+ const entries = isPlainObject(config) && isPlainObject(config.hooks) && Array.isArray(config.hooks[COPILOT_HOOK_EVENT]) ? config.hooks[COPILOT_HOOK_EVENT] : undefined;
845
+ const kept = entries?.filter((e) => !isOurCopilotEntry(e));
846
+ if (entries && kept && kept.length !== entries.length) {
847
+ if (kept.length > 0)
848
+ config.hooks[COPILOT_HOOK_EVENT] = kept;
849
+ else
850
+ delete config.hooks[COPILOT_HOOK_EVENT];
851
+ if (isEmptyStub(config, ["version"]))
852
+ rmSync(hookFile);
853
+ else
854
+ writeFileSync(hookFile, JSON.stringify(config, null, 2));
855
+ done("✓ GitHub Copilot session-start hook removed");
856
+ }
857
+ }
858
+ /** The folders install created (from its marker), once nothing is left in them. */
859
+ function uninstallCopilotFolders() {
860
+ const home = copilotHome();
861
+ const created = copilotCreated();
862
+ rmSync(join(home, COPILOT_MARKER), { force: true });
863
+ for (const d of ["hooks", ""].filter((x) => created.includes(x))) {
864
+ const dir = join(home, d);
865
+ if (existsSync(dir) && readdirSync(dir).length === 0)
866
+ rmSync(dir, { recursive: true });
867
+ }
868
+ }
704
869
  /**
705
870
  * Install into every detected app.
706
871
  *
@@ -714,8 +879,8 @@ function uninstallCodex() {
714
879
  export function runInstall(options = {}) {
715
880
  const entry = serverEntry();
716
881
  const found = targets().filter((t) => t.detect());
717
- if (found.length === 0 && !existsSync(codexDir())) {
718
- console.log("No supported AI apps detected (Claude Desktop, Claude Code, Cursor, Codex, Gemini CLI).");
882
+ if (found.length === 0 && !existsSync(codexDir()) && !copilotPresent()) {
883
+ console.log("No supported AI apps detected (Claude Desktop, Claude Code, Cursor, Codex, Gemini CLI, GitHub Copilot).");
719
884
  console.log("Manual setup — add to your app's MCP config:");
720
885
  console.log(JSON.stringify({ mcpServers: { "context-doctor": entry } }, null, 2));
721
886
  return { failures: [] };
@@ -738,7 +903,9 @@ export function runInstall(options = {}) {
738
903
  if (viaPlugin && target.name === "Claude Code")
739
904
  continue;
740
905
  try {
741
- const config = readJson(target.configPath);
906
+ const config = readJsonObject(target.configPath);
907
+ if (config.mcpServers !== undefined && !isPlainObject(config.mcpServers))
908
+ throw new Error(`"mcpServers" in ${target.configPath} is not an object; fix it, then re-run. Nothing was changed.`);
742
909
  config.mcpServers = config.mcpServers ?? {};
743
910
  // Always overwrite: re-running install is how a stale entry gets repaired.
744
911
  config.mcpServers["context-doctor"] = entry;
@@ -807,6 +974,7 @@ export function runInstall(options = {}) {
807
974
  failures.push("Cursor hook");
808
975
  }
809
976
  installCodex(entry, failures);
977
+ installCopilot(entry, failures);
810
978
  if (geminiCliPresent()) {
811
979
  try {
812
980
  const hook = installHookInto(geminiSettingsPath(), join(homedir(), ".gemini"), "BeforeAgent");
@@ -1002,6 +1170,7 @@ function configPaths() {
1002
1170
  join(codexDir(), "config.toml"),
1003
1171
  join(codexDir(), "hooks.json"),
1004
1172
  geminiSettingsPath(),
1173
+ copilotMcpConfigPath(),
1005
1174
  ].filter((p, i, all) => all.indexOf(p) === i);
1006
1175
  }
1007
1176
  /** "~/..." for a path under the home directory. */
@@ -1069,6 +1238,10 @@ export async function runUninstall() {
1069
1238
  uninstallHook(attempt);
1070
1239
  attempt("Claude Code status line", () => uninstallStatusLine());
1071
1240
  attempt("Codex", () => uninstallCodex());
1241
+ // One step per file: a malformed mcp-config.json must not keep the hook file installed.
1242
+ attempt(`GitHub Copilot MCP server (${tilde(copilotMcpConfigPath())})`, () => uninstallCopilotMcp());
1243
+ attempt(`GitHub Copilot hook (${tilde(copilotHookFilePath())})`, () => uninstallCopilotHook());
1244
+ attempt("GitHub Copilot folders", () => uninstallCopilotFolders());
1072
1245
  // Remove our bookkeeping files too — uninstall means gone. The hook's
1073
1246
  // per-session state is a directory, one small file per session.
1074
1247
  for (const file of OUR_CLAUDE_FILES) {
package/dist/ledger.d.ts CHANGED
@@ -9,6 +9,7 @@
9
9
  * optimize — an optimization was applied {ev: "optimize", src: "cli"|"mcp", saved, model?}
10
10
  * proxy — proxy savings checkpoint {ev: "proxy", saved, usd?, requests?}
11
11
  * rollup — totals folded in on rotation {ev: "rollup", ...carried sums}
12
+ * session_rules — a Copilot session start got the standing rules {ev: "session_rules", app}
12
13
  *
13
14
  * The ledger is capped, and everything it feeds is a LIFETIME total. Simply
14
15
  * dropping old lines made those totals go backwards — measured: 1,692,000
@@ -17,7 +18,7 @@
17
18
  */
18
19
  export interface LedgerEntry {
19
20
  ts: number;
20
- ev?: "check" | "optimize" | "proxy" | "rollup" | "cold_resume" | "precompact";
21
+ ev?: "check" | "optimize" | "proxy" | "rollup" | "cold_resume" | "precompact" | "session_rules";
21
22
  sid?: string;
22
23
  tok?: number;
23
24
  warn?: boolean;
@@ -28,6 +29,8 @@ export interface LedgerEntry {
28
29
  model?: string;
29
30
  /** The Cursor version that ran the hook (its input's cursor_version), for `doctor`. */
30
31
  cv?: string;
32
+ /** session_rules only: the app whose session start got the standing rules ("copilot"). */
33
+ app?: string;
31
34
  /** rollup only: sums carried forward from entries rotation removed. */
32
35
  carried?: CarriedTotals;
33
36
  }
package/dist/ledger.js CHANGED
@@ -9,6 +9,7 @@
9
9
  * optimize — an optimization was applied {ev: "optimize", src: "cli"|"mcp", saved, model?}
10
10
  * proxy — proxy savings checkpoint {ev: "proxy", saved, usd?, requests?}
11
11
  * rollup — totals folded in on rotation {ev: "rollup", ...carried sums}
12
+ * session_rules — a Copilot session start got the standing rules {ev: "session_rules", app}
12
13
  *
13
14
  * The ledger is capped, and everything it feeds is a LIFETIME total. Simply
14
15
  * dropping old lines made those totals go backwards — measured: 1,692,000