context-doctor 0.31.1 → 0.33.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.
Files changed (81) hide show
  1. package/README.md +96 -706
  2. package/dist/autoclear.d.ts +58 -7
  3. package/dist/autoclear.js +159 -31
  4. package/dist/autopilot.d.ts +43 -3
  5. package/dist/autopilot.js +169 -35
  6. package/dist/cache.d.ts +6 -2
  7. package/dist/cache.js +48 -23
  8. package/dist/cacheplan.d.ts +5 -3
  9. package/dist/cacheplan.js +46 -8
  10. package/dist/calibration.d.ts +7 -2
  11. package/dist/calibration.js +14 -3
  12. package/dist/ci.js +34 -6
  13. package/dist/cli.js +416 -271
  14. package/dist/clihelp.d.ts +24 -0
  15. package/dist/clihelp.js +116 -0
  16. package/dist/coldresume.d.ts +32 -7
  17. package/dist/coldresume.js +148 -34
  18. package/dist/compactquality.d.ts +1 -1
  19. package/dist/compactquality.js +37 -14
  20. package/dist/compactwindow.d.ts +29 -5
  21. package/dist/compactwindow.js +104 -47
  22. package/dist/config.d.ts +6 -0
  23. package/dist/config.js +4 -1
  24. package/dist/cursor.d.ts +9 -0
  25. package/dist/cursor.js +53 -22
  26. package/dist/dashboard.d.ts +10 -0
  27. package/dist/dashboard.js +27 -2
  28. package/dist/diff.js +33 -4
  29. package/dist/doctor.d.ts +3 -2
  30. package/dist/doctor.js +199 -34
  31. package/dist/embed.d.ts +9 -0
  32. package/dist/embed.js +40 -5
  33. package/dist/experiment.d.ts +1 -0
  34. package/dist/experiment.js +6 -3
  35. package/dist/hook.js +23 -4
  36. package/dist/impact.d.ts +32 -0
  37. package/dist/impact.js +45 -6
  38. package/dist/install.d.ts +59 -2
  39. package/dist/install.js +458 -57
  40. package/dist/invocation.d.ts +18 -0
  41. package/dist/invocation.js +49 -0
  42. package/dist/ledger.js +9 -2
  43. package/dist/mcp.d.ts +6 -3
  44. package/dist/mcp.js +93 -299
  45. package/dist/mcpclient.js +45 -0
  46. package/dist/mcpschema.d.ts +17 -2
  47. package/dist/mcpschema.js +100 -26
  48. package/dist/optimize.d.ts +2 -0
  49. package/dist/optimize.js +151 -64
  50. package/dist/overhead.d.ts +12 -1
  51. package/dist/overhead.js +88 -34
  52. package/dist/pack.d.ts +11 -0
  53. package/dist/pack.js +75 -12
  54. package/dist/parse.js +42 -18
  55. package/dist/preferences.d.ts +1 -1
  56. package/dist/preferences.js +5 -5
  57. package/dist/pricing.d.ts +57 -5
  58. package/dist/pricing.js +94 -8
  59. package/dist/proxy.d.ts +13 -2
  60. package/dist/proxy.js +258 -43
  61. package/dist/reads.d.ts +1 -1
  62. package/dist/reads.js +61 -24
  63. package/dist/report.d.ts +10 -0
  64. package/dist/report.js +12 -4
  65. package/dist/savings.d.ts +23 -8
  66. package/dist/savings.js +88 -37
  67. package/dist/session.d.ts +52 -0
  68. package/dist/session.js +186 -6
  69. package/dist/split.js +6 -1
  70. package/dist/statusline.d.ts +3 -1
  71. package/dist/statusline.js +29 -17
  72. package/dist/subagentpay.d.ts +6 -3
  73. package/dist/subagentpay.js +53 -18
  74. package/dist/subagents.d.ts +7 -3
  75. package/dist/subagents.js +28 -8
  76. package/dist/tasks.d.ts +22 -7
  77. package/dist/tasks.js +47 -20
  78. package/dist/wrap.d.ts +6 -0
  79. package/dist/wrap.js +142 -6
  80. package/package.json +5 -8
  81. package/skills/context-doctor/SKILL.md +3 -3
package/dist/ci.js CHANGED
@@ -10,7 +10,7 @@
10
10
  * Base contents come from `git show <base>:<path>`; nothing is checked out.
11
11
  */
12
12
  import { execFileSync } from "node:child_process";
13
- import { existsSync, readFileSync } from "node:fs";
13
+ import { readFileSync, statSync } from "node:fs";
14
14
  import { join, posix } from "node:path";
15
15
  import { estimateTokens, formatTokens } from "./tokens.js";
16
16
  import { formatUsd, pricingFor } from "./pricing.js";
@@ -76,13 +76,41 @@ function measure(paths, read) {
76
76
  visit(p, false, 0);
77
77
  return out;
78
78
  }
79
+ /** `-z` output: without it git quotes non-ASCII paths ("caf\303\251/CLAUDE.md") and they match nothing. */
80
+ const paths0 = (out) => (out ?? "").split("\0").filter(Boolean);
81
+ /** A file on disk, not a directory: `@src/components` names a folder, which Claude Code does not load. */
82
+ function isFile(p) {
83
+ try {
84
+ return statSync(p).isFile();
85
+ }
86
+ catch {
87
+ return false;
88
+ }
89
+ }
79
90
  export function ciReport(opts = {}) {
80
91
  const cwd = opts.cwd ?? process.cwd();
81
- const root = git(["rev-parse", "--show-toplevel"], cwd)?.trim() ?? cwd;
82
- const headList = (git(["ls-files", "--cached", "--others", "--exclude-standard"], root) ?? "").split("\n").filter(Boolean);
83
- const baseList = opts.base ? (git(["ls-tree", "-r", "--name-only", opts.base], root) ?? "").split("\n").filter(Boolean) : [];
84
- const head = measure(headList.filter((p) => agentFor(p)), (p) => (existsSync(join(root, p)) ? readFileSync(join(root, p), "utf8") : undefined));
85
- const base = opts.base ? measure(baseList.filter((p) => agentFor(p)), (p) => git(["show", `${opts.base}:${p}`], root)) : new Map();
92
+ // Outside a repository `git ls-files` lists nothing, which used to read as
93
+ // "No agent memory files" with exit 0: a CI step in the wrong directory
94
+ // passed every pull request. It is an error, said as one.
95
+ const root = git(["rev-parse", "--show-toplevel"], cwd)?.trim();
96
+ if (!root) {
97
+ throw new Error(git(["--version"], cwd) === undefined
98
+ ? "ci needs git, and git is not installed or not on PATH."
99
+ : `ci compares memory files in a git repository, and ${cwd} is not inside one. Run it from the repository's checkout.`);
100
+ }
101
+ // A base git cannot resolve (a typo, or a shallow clone that never fetched
102
+ // it) would read as an empty tree: every file "new", and a failure that
103
+ // blames the PR for the whole memory set. Stop and say so instead.
104
+ if (opts.base && git(["rev-parse", "--verify", "--quiet", `${opts.base}^{commit}`], root) === undefined) {
105
+ throw new Error(`--base ${opts.base} is not a commit in ${root}: check the name, or fetch it first (a shallow clone: git fetch --depth=1 origin ${opts.base})`);
106
+ }
107
+ const headList = paths0(git(["ls-files", "-z", "--cached", "--others", "--exclude-standard"], root));
108
+ const baseList = opts.base ? paths0(git(["ls-tree", "-r", "-z", "--name-only", opts.base], root)) : [];
109
+ // ls-tree -r lists blobs only, so a path outside it (a folder, a missing file) has no base content;
110
+ // `git show base:folder` would print the folder's listing and count it as an imported file.
111
+ const baseFiles = new Set(baseList);
112
+ const head = measure(headList.filter((p) => agentFor(p)), (p) => (isFile(join(root, p)) ? readFileSync(join(root, p), "utf8") : undefined));
113
+ const base = opts.base ? measure(baseList.filter((p) => agentFor(p)), (p) => (baseFiles.has(p) ? git(["show", `${opts.base}:${p}`], root) : undefined)) : new Map();
86
114
  const files = [...new Set([...head.keys(), ...base.keys()])].sort().map((p) => ({
87
115
  path: p,
88
116
  agent: agentFor(p) ?? "Claude Code",