@saluzi/codegraph 0.1.0 → 0.2.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 (246) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +885 -0
  3. package/package.json +42 -10
  4. package/scripts/add-lang/bench.sh +60 -0
  5. package/scripts/add-lang/check-grammar.mjs +75 -0
  6. package/scripts/add-lang/dump-ast.mjs +103 -0
  7. package/scripts/add-lang/verify-extraction.mjs +70 -0
  8. package/scripts/agent-eval/ab-adoption.sh +91 -0
  9. package/scripts/agent-eval/ab-hook.sh +86 -0
  10. package/scripts/agent-eval/ab-impl.sh +78 -0
  11. package/scripts/agent-eval/ab-new-vs-baseline.sh +102 -0
  12. package/scripts/agent-eval/ab-sufficiency.sh +78 -0
  13. package/scripts/agent-eval/arms-F.sh +21 -0
  14. package/scripts/agent-eval/arms-matrix.sh +37 -0
  15. package/scripts/agent-eval/audit.sh +68 -0
  16. package/scripts/agent-eval/bench-readme.sh +28 -0
  17. package/scripts/agent-eval/bench-why-repo.sh +22 -0
  18. package/scripts/agent-eval/block-read-hook.sh +19 -0
  19. package/scripts/agent-eval/hook-settings.json +15 -0
  20. package/scripts/agent-eval/itrun.sh +120 -0
  21. package/scripts/agent-eval/offload-eval-3arm.sh +72 -0
  22. package/scripts/agent-eval/offload-eval-cost.mjs +133 -0
  23. package/scripts/agent-eval/offload-eval-effort.mjs +108 -0
  24. package/scripts/agent-eval/offload-eval-frontload-matrix.sh +25 -0
  25. package/scripts/agent-eval/offload-eval-frontload.sh +47 -0
  26. package/scripts/agent-eval/offload-eval-ground-truth.json +18 -0
  27. package/scripts/agent-eval/offload-eval-hook.mjs +84 -0
  28. package/scripts/agent-eval/offload-eval-judge.mjs +103 -0
  29. package/scripts/agent-eval/offload-eval-matrix.sh +20 -0
  30. package/scripts/agent-eval/offload-eval-metrics.mjs +94 -0
  31. package/scripts/agent-eval/offload-eval-refs1.sh +50 -0
  32. package/scripts/agent-eval/offload-eval-setup.sh +24 -0
  33. package/scripts/agent-eval/offload-eval-styles.sh +72 -0
  34. package/scripts/agent-eval/offload-eval-summarize.mjs +68 -0
  35. package/scripts/agent-eval/offload-eval.md +76 -0
  36. package/scripts/agent-eval/parse-arms.mjs +116 -0
  37. package/scripts/agent-eval/parse-bench-readme.mjs +84 -0
  38. package/scripts/agent-eval/parse-run.mjs +45 -0
  39. package/scripts/agent-eval/parse-session.mjs +93 -0
  40. package/scripts/agent-eval/probe-context.mjs +21 -0
  41. package/scripts/agent-eval/probe-explore.mjs +40 -0
  42. package/scripts/agent-eval/probe-node.mjs +20 -0
  43. package/scripts/agent-eval/probe-sweep.mjs +119 -0
  44. package/scripts/agent-eval/probe-trace.mjs +20 -0
  45. package/scripts/agent-eval/redirect-read-hook.sh +38 -0
  46. package/scripts/agent-eval/repro-concurrent-explore.mjs +119 -0
  47. package/scripts/agent-eval/repro-daemon-clients.mjs +125 -0
  48. package/scripts/agent-eval/run-agent.sh +34 -0
  49. package/scripts/agent-eval/run-all.sh +75 -0
  50. package/scripts/agent-eval/run-arms.sh +56 -0
  51. package/scripts/agent-eval/seq-matrix.mjs +137 -0
  52. package/scripts/build-bundle.sh +123 -0
  53. package/scripts/extract-release-notes.mjs +130 -0
  54. package/scripts/local-install.sh +41 -0
  55. package/scripts/npm-sdk.js +75 -0
  56. package/scripts/npm-shim.js +275 -0
  57. package/scripts/pack-npm.sh +119 -0
  58. package/scripts/prepare-release.mjs +270 -0
  59. package/dist/bin/codegraph.d.ts +0 -25
  60. package/dist/bin/node-version-check.d.ts +0 -37
  61. package/dist/bin/uninstall.d.ts +0 -14
  62. package/dist/context/formatter.d.ts +0 -33
  63. package/dist/context/formatter.js +0 -244
  64. package/dist/context/index.d.ts +0 -117
  65. package/dist/context/index.js +0 -1050
  66. package/dist/db/index.d.ts +0 -101
  67. package/dist/db/index.js +0 -250
  68. package/dist/db/migrations.d.ts +0 -47
  69. package/dist/db/migrations.js +0 -131
  70. package/dist/db/queries.d.ts +0 -291
  71. package/dist/db/queries.js +0 -1349
  72. package/dist/db/schema.sql +0 -151
  73. package/dist/db/sqlite-adapter.d.ts +0 -49
  74. package/dist/db/sqlite-adapter.js +0 -141
  75. package/dist/directory.d.ts +0 -62
  76. package/dist/directory.js +0 -264
  77. package/dist/errors.d.ts +0 -149
  78. package/dist/errors.js +0 -219
  79. package/dist/extraction/dfm-extractor.d.ts +0 -31
  80. package/dist/extraction/dfm-extractor.js +0 -151
  81. package/dist/extraction/grammars.d.ts +0 -94
  82. package/dist/extraction/grammars.js +0 -357
  83. package/dist/extraction/index.d.ts +0 -148
  84. package/dist/extraction/index.js +0 -1286
  85. package/dist/extraction/languages/c-cpp.d.ts +0 -4
  86. package/dist/extraction/languages/c-cpp.js +0 -126
  87. package/dist/extraction/languages/csharp.d.ts +0 -3
  88. package/dist/extraction/languages/csharp.js +0 -72
  89. package/dist/extraction/languages/dart.d.ts +0 -3
  90. package/dist/extraction/languages/dart.js +0 -192
  91. package/dist/extraction/languages/go.d.ts +0 -3
  92. package/dist/extraction/languages/go.js +0 -58
  93. package/dist/extraction/languages/index.d.ts +0 -10
  94. package/dist/extraction/languages/index.js +0 -49
  95. package/dist/extraction/languages/java.d.ts +0 -3
  96. package/dist/extraction/languages/java.js +0 -64
  97. package/dist/extraction/languages/javascript.d.ts +0 -3
  98. package/dist/extraction/languages/javascript.js +0 -90
  99. package/dist/extraction/languages/kotlin.d.ts +0 -3
  100. package/dist/extraction/languages/kotlin.js +0 -253
  101. package/dist/extraction/languages/lua.d.ts +0 -3
  102. package/dist/extraction/languages/lua.js +0 -150
  103. package/dist/extraction/languages/luau.d.ts +0 -3
  104. package/dist/extraction/languages/luau.js +0 -37
  105. package/dist/extraction/languages/pascal.d.ts +0 -3
  106. package/dist/extraction/languages/pascal.js +0 -66
  107. package/dist/extraction/languages/php.d.ts +0 -3
  108. package/dist/extraction/languages/php.js +0 -107
  109. package/dist/extraction/languages/python.d.ts +0 -3
  110. package/dist/extraction/languages/python.js +0 -56
  111. package/dist/extraction/languages/ruby.d.ts +0 -3
  112. package/dist/extraction/languages/ruby.js +0 -114
  113. package/dist/extraction/languages/rust.d.ts +0 -3
  114. package/dist/extraction/languages/rust.js +0 -109
  115. package/dist/extraction/languages/scala.d.ts +0 -3
  116. package/dist/extraction/languages/scala.js +0 -139
  117. package/dist/extraction/languages/swift.d.ts +0 -3
  118. package/dist/extraction/languages/swift.js +0 -91
  119. package/dist/extraction/languages/typescript.d.ts +0 -3
  120. package/dist/extraction/languages/typescript.js +0 -129
  121. package/dist/extraction/liquid-extractor.d.ts +0 -52
  122. package/dist/extraction/liquid-extractor.js +0 -313
  123. package/dist/extraction/parse-worker.d.ts +0 -8
  124. package/dist/extraction/parse-worker.js +0 -94
  125. package/dist/extraction/svelte-extractor.d.ts +0 -56
  126. package/dist/extraction/svelte-extractor.js +0 -272
  127. package/dist/extraction/tree-sitter-helpers.d.ts +0 -39
  128. package/dist/extraction/tree-sitter-helpers.js +0 -103
  129. package/dist/extraction/tree-sitter-types.d.ts +0 -191
  130. package/dist/extraction/tree-sitter-types.js +0 -10
  131. package/dist/extraction/tree-sitter.d.ts +0 -238
  132. package/dist/extraction/tree-sitter.js +0 -2430
  133. package/dist/extraction/vue-extractor.d.ts +0 -36
  134. package/dist/extraction/vue-extractor.js +0 -163
  135. package/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
  136. package/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
  137. package/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
  138. package/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
  139. package/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
  140. package/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
  141. package/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
  142. package/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
  143. package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
  144. package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
  145. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  146. package/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
  147. package/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
  148. package/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
  149. package/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
  150. package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  151. package/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
  152. package/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
  153. package/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
  154. package/dist/extraction/wasm-runtime-flags.d.ts +0 -46
  155. package/dist/extraction/wasm-runtime-flags.js +0 -105
  156. package/dist/graph/index.d.ts +0 -8
  157. package/dist/graph/index.js +0 -13
  158. package/dist/graph/queries.d.ts +0 -109
  159. package/dist/graph/queries.js +0 -366
  160. package/dist/graph/traversal.d.ts +0 -137
  161. package/dist/graph/traversal.js +0 -528
  162. package/dist/index.d.ts +0 -509
  163. package/dist/index.js +0 -800
  164. package/dist/installer/claude-md-template.d.ts +0 -19
  165. package/dist/installer/config-writer.d.ts +0 -29
  166. package/dist/installer/index.d.ts +0 -140
  167. package/dist/installer/instructions-template.d.ts +0 -30
  168. package/dist/installer/targets/claude.d.ts +0 -55
  169. package/dist/installer/targets/codex.d.ts +0 -18
  170. package/dist/installer/targets/cursor.d.ts +0 -35
  171. package/dist/installer/targets/hermes.d.ts +0 -18
  172. package/dist/installer/targets/opencode.d.ts +0 -30
  173. package/dist/installer/targets/registry.d.ts +0 -38
  174. package/dist/installer/targets/shared.d.ts +0 -92
  175. package/dist/installer/targets/toml.d.ts +0 -64
  176. package/dist/installer/targets/types.d.ts +0 -122
  177. package/dist/mcp/index.d.ts +0 -98
  178. package/dist/mcp/server-instructions.d.ts +0 -20
  179. package/dist/mcp/tools.d.ts +0 -269
  180. package/dist/mcp/transport.d.ts +0 -117
  181. package/dist/resolution/frameworks/cargo-workspace.d.ts +0 -20
  182. package/dist/resolution/frameworks/cargo-workspace.js +0 -225
  183. package/dist/resolution/frameworks/csharp.d.ts +0 -8
  184. package/dist/resolution/frameworks/csharp.js +0 -213
  185. package/dist/resolution/frameworks/drupal.d.ts +0 -51
  186. package/dist/resolution/frameworks/drupal.js +0 -335
  187. package/dist/resolution/frameworks/express.d.ts +0 -8
  188. package/dist/resolution/frameworks/express.js +0 -225
  189. package/dist/resolution/frameworks/go.d.ts +0 -8
  190. package/dist/resolution/frameworks/go.js +0 -158
  191. package/dist/resolution/frameworks/index.d.ts +0 -52
  192. package/dist/resolution/frameworks/index.js +0 -137
  193. package/dist/resolution/frameworks/java.d.ts +0 -8
  194. package/dist/resolution/frameworks/java.js +0 -177
  195. package/dist/resolution/frameworks/laravel.d.ts +0 -13
  196. package/dist/resolution/frameworks/laravel.js +0 -248
  197. package/dist/resolution/frameworks/nestjs.d.ts +0 -26
  198. package/dist/resolution/frameworks/nestjs.js +0 -374
  199. package/dist/resolution/frameworks/python.d.ts +0 -10
  200. package/dist/resolution/frameworks/python.js +0 -278
  201. package/dist/resolution/frameworks/react.d.ts +0 -8
  202. package/dist/resolution/frameworks/react.js +0 -272
  203. package/dist/resolution/frameworks/ruby.d.ts +0 -8
  204. package/dist/resolution/frameworks/ruby.js +0 -198
  205. package/dist/resolution/frameworks/rust.d.ts +0 -8
  206. package/dist/resolution/frameworks/rust.js +0 -207
  207. package/dist/resolution/frameworks/svelte.d.ts +0 -9
  208. package/dist/resolution/frameworks/svelte.js +0 -249
  209. package/dist/resolution/frameworks/swift.d.ts +0 -10
  210. package/dist/resolution/frameworks/swift.js +0 -376
  211. package/dist/resolution/frameworks/vue.d.ts +0 -9
  212. package/dist/resolution/frameworks/vue.js +0 -306
  213. package/dist/resolution/import-resolver.d.ts +0 -61
  214. package/dist/resolution/import-resolver.js +0 -663
  215. package/dist/resolution/index.d.ts +0 -118
  216. package/dist/resolution/index.js +0 -744
  217. package/dist/resolution/lru-cache.d.ts +0 -24
  218. package/dist/resolution/lru-cache.js +0 -62
  219. package/dist/resolution/name-matcher.d.ts +0 -50
  220. package/dist/resolution/name-matcher.js +0 -384
  221. package/dist/resolution/path-aliases.d.ts +0 -72
  222. package/dist/resolution/path-aliases.js +0 -238
  223. package/dist/resolution/strip-comments.d.ts +0 -40
  224. package/dist/resolution/strip-comments.js +0 -441
  225. package/dist/resolution/types.d.ts +0 -181
  226. package/dist/resolution/types.js +0 -8
  227. package/dist/search/query-parser.d.ts +0 -61
  228. package/dist/search/query-parser.js +0 -177
  229. package/dist/search/query-utils.d.ts +0 -59
  230. package/dist/search/query-utils.js +0 -383
  231. package/dist/sync/git-hooks.d.ts +0 -54
  232. package/dist/sync/git-hooks.js +0 -223
  233. package/dist/sync/index.d.ts +0 -25
  234. package/dist/sync/index.js +0 -28
  235. package/dist/sync/watch-policy.d.ts +0 -51
  236. package/dist/sync/watch-policy.js +0 -124
  237. package/dist/sync/watcher.d.ts +0 -83
  238. package/dist/sync/watcher.js +0 -192
  239. package/dist/types.d.ts +0 -433
  240. package/dist/types.js +0 -75
  241. package/dist/ui/glyphs.d.ts +0 -42
  242. package/dist/ui/shimmer-progress.d.ts +0 -11
  243. package/dist/ui/shimmer-worker.d.ts +0 -2
  244. package/dist/ui/types.d.ts +0 -20
  245. package/dist/utils.d.ts +0 -231
  246. package/dist/utils.js +0 -549
@@ -0,0 +1,275 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ //
4
+ // npm thin-installer launcher for CodeGraph.
5
+ //
6
+ // The heavy artifact (a vendored Node runtime + the app) ships as a per-platform
7
+ // optionalDependency: @colbymchenry/codegraph-<platform>-<arch>. npm installs
8
+ // only the one matching the host, via each package's `os`/`cpu` fields (the
9
+ // esbuild pattern). This shim — run by the user's OWN Node — locates that bundle
10
+ // and execs its launcher, so the real work always runs on the bundled Node 24
11
+ // (with node:sqlite), regardless of the user's Node version. The user's Node is
12
+ // only ever a launcher; even an ancient version can run this file.
13
+ //
14
+ // Self-heal (issue #303): some registries — notably the npmmirror/cnpm mirrors,
15
+ // and some corporate proxies — don't reliably mirror the per-platform
16
+ // optionalDependencies. npm treats an unfetchable optional dep as success and
17
+ // silently skips it, so the bundle goes missing and every command fails. When
18
+ // the installed bundle can't be resolved, this shim falls back to downloading
19
+ // the matching bundle straight from GitHub Releases — the very archive
20
+ // install.sh uses — into a cache dir, then runs that. Knobs:
21
+ // CODEGRAPH_NO_DOWNLOAD=1 disable the network fallback (print guidance)
22
+ // CODEGRAPH_INSTALL_DIR=DIR cache location (default: ~/.codegraph)
23
+ // CODEGRAPH_DOWNLOAD_BASE=URL release-download base (for mirrors/air-gapped)
24
+ //
25
+ // Wired up at release time as the main package's `bin`:
26
+ // "bin": { "codegraph": "npm-shim.js" }
27
+ // with the platform packages listed in `optionalDependencies`.
28
+
29
+ var childProcess = require('child_process');
30
+ var fs = require('fs');
31
+ var os = require('os');
32
+ var path = require('path');
33
+
34
+ var target = process.platform + '-' + process.arch; // e.g. darwin-arm64, linux-x64
35
+ var pkg = '@colbymchenry/codegraph-' + target;
36
+ var isWindows = process.platform === 'win32';
37
+ var REPO = 'colbymchenry/codegraph';
38
+
39
+ main().catch(function (e) {
40
+ process.stderr.write('codegraph: ' + (e && e.message ? e.message : String(e)) + '\n');
41
+ process.exit(1);
42
+ });
43
+
44
+ async function main() {
45
+ // Happy path: the npm-installed optional dependency. Fall back to a download
46
+ // when the registry didn't deliver it.
47
+ var resolved = resolveInstalledBundle() || (await selfHealBundle());
48
+ // Thread the MCP host's pid (our parent) down to the bundled server so its
49
+ // orphan watchdog can poll the host directly. Without this, the server can
50
+ // only watch THIS shim — and a shim killed during the server's first ~100ms
51
+ // of startup used to leave the server orphaned forever (issue #1185). An
52
+ // already-set value (an outer launcher) wins.
53
+ var env = Object.assign({}, process.env);
54
+ if (!env.CODEGRAPH_HOST_PPID) env.CODEGRAPH_HOST_PPID = String(process.ppid);
55
+ var res = childProcess.spawnSync(resolved.command, resolved.args, { stdio: 'inherit', windowsHide: true, env: env });
56
+ if (res.error) {
57
+ process.stderr.write('codegraph: ' + res.error.message + '\n');
58
+ process.exit(1);
59
+ }
60
+ process.exit(res.status === null ? 1 : res.status);
61
+ }
62
+
63
+ // Resolve the launcher from the installed per-platform optionalDependency.
64
+ // Returns {command, args} or null if the package isn't installed.
65
+ function resolveInstalledBundle() {
66
+ try {
67
+ if (isWindows) {
68
+ // Modern Node refuses to spawn the bundle's .cmd directly (EINVAL, the
69
+ // CVE-2024-27980 hardening on Node 24), so invoke the bundled node.exe
70
+ // against the app entry point and pass --liftoff-only here.
71
+ var nodeExe = require.resolve(pkg + '/node.exe');
72
+ var entry = require.resolve(pkg + '/lib/dist/bin/codegraph.js');
73
+ return { command: nodeExe, args: liftoff(entry) };
74
+ }
75
+ return { command: require.resolve(pkg + '/bin/codegraph'), args: process.argv.slice(2) };
76
+ } catch (e) {
77
+ return null;
78
+ }
79
+ }
80
+
81
+ // Locate the launcher inside an extracted GitHub bundle directory (same
82
+ // node/lib/bin layout as the npm platform package). Returns {command, args} or
83
+ // null when the directory doesn't hold a usable bundle yet.
84
+ function launcherIn(dir) {
85
+ if (isWindows) {
86
+ var nodeExe = path.join(dir, 'node.exe');
87
+ var entry = path.join(dir, 'lib', 'dist', 'bin', 'codegraph.js');
88
+ if (fs.existsSync(nodeExe) && fs.existsSync(entry)) {
89
+ return { command: nodeExe, args: liftoff(entry) };
90
+ }
91
+ } else {
92
+ var launcher = path.join(dir, 'bin', 'codegraph');
93
+ if (fs.existsSync(launcher)) return { command: launcher, args: process.argv.slice(2) };
94
+ }
95
+ return null;
96
+ }
97
+
98
+ // --liftoff-only keeps tree-sitter's WASM grammars off V8's turboshaft tier to
99
+ // avoid the Zone OOM on Node >= 22 (issues #293/#298). The unix bin/codegraph
100
+ // launcher already passes it; on Windows we invoke node.exe directly so add it.
101
+ function liftoff(entry) {
102
+ return ['--liftoff-only', entry].concat(process.argv.slice(2));
103
+ }
104
+
105
+ // Download + cache the platform bundle from GitHub Releases. Returns
106
+ // {command, args}; exits the process with guidance if it can't.
107
+ async function selfHealBundle() {
108
+ var version = readVersion();
109
+ var bundlesDir = path.join(process.env.CODEGRAPH_INSTALL_DIR || path.join(os.homedir(), '.codegraph'), 'bundles');
110
+ var dest = path.join(bundlesDir, target + '-' + version);
111
+
112
+ // Already downloaded by a previous run? Use it even when downloads are
113
+ // disabled — CODEGRAPH_NO_DOWNLOAD blocks fetching, not a cached bundle.
114
+ var cached = launcherIn(dest);
115
+ if (cached) { pruneOldBundles(bundlesDir, dest); return cached; }
116
+
117
+ if (process.env.CODEGRAPH_NO_DOWNLOAD) {
118
+ fail('the network fallback is disabled (CODEGRAPH_NO_DOWNLOAD is set).');
119
+ }
120
+
121
+ var asset = 'codegraph-' + target + (isWindows ? '.zip' : '.tar.gz');
122
+ var base = process.env.CODEGRAPH_DOWNLOAD_BASE || ('https://github.com/' + REPO + '/releases/download');
123
+ var url = base + '/v' + version + '/' + asset;
124
+
125
+ process.stderr.write(
126
+ 'codegraph: platform bundle missing (registry did not provide ' + pkg + ').\n' +
127
+ 'codegraph: downloading ' + asset + ' from GitHub Releases (' + version + ')...\n'
128
+ );
129
+
130
+ // Stage inside bundlesDir so the final rename is on the same filesystem (atomic,
131
+ // no EXDEV across tmpfs). Strip the archive's top-level codegraph-<target>/ dir.
132
+ fs.mkdirSync(bundlesDir, { recursive: true });
133
+ var stage = fs.mkdtempSync(path.join(bundlesDir, '.dl-'));
134
+ try {
135
+ var archivePath = path.join(stage, asset);
136
+ await download(url, archivePath, 6);
137
+ await verifyChecksum(archivePath, asset, base, version);
138
+ var extracted = path.join(stage, 'bundle');
139
+ fs.mkdirSync(extracted);
140
+ extract(archivePath, extracted);
141
+
142
+ var raced = launcherIn(dest); // another process may have finished meanwhile
143
+ if (raced) { rmrf(stage); return raced; }
144
+ try {
145
+ fs.renameSync(extracted, dest);
146
+ } catch (e) {
147
+ var other = launcherIn(dest); // lost the race but theirs is valid
148
+ if (other) { rmrf(stage); return other; }
149
+ throw e;
150
+ }
151
+ } catch (e) {
152
+ rmrf(stage);
153
+ fail('download failed (' + e.message + ').\n URL: ' + url);
154
+ }
155
+ rmrf(stage);
156
+
157
+ var ready = launcherIn(dest);
158
+ if (!ready) fail('downloaded bundle is missing its launcher under ' + dest + '.');
159
+ pruneOldBundles(bundlesDir, dest);
160
+ process.stderr.write('codegraph: bundle ready.\n');
161
+ return ready;
162
+ }
163
+
164
+ function readVersion() {
165
+ try {
166
+ return require(path.join(__dirname, 'package.json')).version;
167
+ } catch (e) {
168
+ fail('could not read this package\'s version to locate a matching release.');
169
+ }
170
+ }
171
+
172
+ // GET with manual redirect following (GitHub release URLs redirect to a CDN).
173
+ function download(url, dest, redirectsLeft) {
174
+ return new Promise(function (resolve, reject) {
175
+ var https = require('https');
176
+ // timeout is an idle/inactivity timeout — it won't kill a slow-but-progressing
177
+ // download, only a stalled connection (so a blocked mirror fails fast with
178
+ // guidance instead of hanging the user's command forever).
179
+ var req = https.get(url, { headers: { 'User-Agent': 'codegraph-npm-shim' }, timeout: 30000 }, function (res) {
180
+ var status = res.statusCode;
181
+ if (status >= 300 && status < 400 && res.headers.location) {
182
+ res.resume();
183
+ if (redirectsLeft <= 0) { reject(new Error('too many redirects')); return; }
184
+ download(new URL(res.headers.location, url).toString(), dest, redirectsLeft - 1).then(resolve, reject);
185
+ return;
186
+ }
187
+ if (status !== 200) { res.resume(); reject(new Error('HTTP ' + status)); return; }
188
+ var file = fs.createWriteStream(dest);
189
+ res.on('error', reject);
190
+ res.pipe(file);
191
+ file.on('error', reject);
192
+ file.on('finish', function () { file.close(function () { resolve(); }); });
193
+ });
194
+ req.on('timeout', function () { req.destroy(new Error('connection timed out')); });
195
+ req.on('error', reject);
196
+ });
197
+ }
198
+
199
+ // Best-effort integrity check. When the release publishes a SHA256SUMS file, the
200
+ // downloaded archive MUST match its listed hash or we abort. When that file is
201
+ // absent (older releases) or simply unreachable, we proceed — the archive still
202
+ // arrived from GitHub over TLS. So tampering/corruption is caught, while a
203
+ // missing checksum never breaks an install.
204
+ async function verifyChecksum(archivePath, asset, base, version) {
205
+ var sumsPath = archivePath + '.SHA256SUMS';
206
+ try {
207
+ await download(base + '/v' + version + '/SHA256SUMS', sumsPath, 6);
208
+ } catch (e) {
209
+ return; // not published / unreachable → skip
210
+ }
211
+ var expected = null;
212
+ var lines = fs.readFileSync(sumsPath, 'utf8').split('\n');
213
+ for (var i = 0; i < lines.length; i++) {
214
+ var m = lines[i].trim().match(/^([0-9a-fA-F]{64})\s+\*?(.+)$/);
215
+ if (m && path.basename(m[2].trim()) === asset) { expected = m[1].toLowerCase(); break; }
216
+ }
217
+ if (!expected) return; // asset not listed → nothing to check
218
+ var actual = require('crypto').createHash('sha256').update(fs.readFileSync(archivePath)).digest('hex');
219
+ if (actual !== expected) {
220
+ throw new Error('checksum mismatch for ' + asset +
221
+ ' (expected ' + expected.slice(0, 12) + '…, got ' + actual.slice(0, 12) + '…)');
222
+ }
223
+ process.stderr.write('codegraph: checksum verified.\n');
224
+ }
225
+
226
+ // Extract via the system tar — present on macOS, Linux, and Windows 10+
227
+ // (bsdtar reads .zip too). No third-party dependency in the shim.
228
+ function extract(archive, destDir) {
229
+ var args = isWindows
230
+ ? ['-xf', archive, '-C', destDir, '--strip-components=1']
231
+ : ['-xzf', archive, '-C', destDir, '--strip-components=1'];
232
+ var res = childProcess.spawnSync('tar', args, { stdio: 'ignore', windowsHide: true });
233
+ if (res.error) throw new Error('tar unavailable: ' + res.error.message);
234
+ if (res.status !== 0) throw new Error('tar exited ' + res.status);
235
+ }
236
+
237
+ function rmrf(p) {
238
+ try { fs.rmSync(p, { recursive: true, force: true }); } catch (e) { /* best effort */ }
239
+ }
240
+
241
+ // Drop sibling bundles for OTHER versions of this same platform target, keeping
242
+ // only keepDir. The self-heal cache otherwise accumulates a full ~50 MB bundle
243
+ // per version forever (issue #1074). Best-effort: a locked/busy dir (a
244
+ // concurrent run still mapping an older node.exe on Windows) just stays — rmrf
245
+ // already swallows its own errors, and the readdir is guarded — so cleanup can
246
+ // never break a working command. Only this target's "<target>-<version>" dirs
247
+ // are touched; other platforms' bundles and the ".dl-*" staging dirs are left
248
+ // alone.
249
+ function pruneOldBundles(bundlesDir, keepDir) {
250
+ var keep = path.basename(keepDir);
251
+ try {
252
+ var names = fs.readdirSync(bundlesDir);
253
+ for (var i = 0; i < names.length; i++) {
254
+ var name = names[i];
255
+ if (name === keep) continue;
256
+ if (name.indexOf(target + '-') !== 0) continue;
257
+ rmrf(path.join(bundlesDir, name));
258
+ }
259
+ } catch (e) { /* best effort — never break a working run over cleanup */ }
260
+ }
261
+
262
+ function fail(reason) {
263
+ process.stderr.write(
264
+ 'codegraph: no prebuilt bundle for ' + target + '.\n' +
265
+ (reason ? 'codegraph: ' + reason + '\n' : '') +
266
+ 'Expected the optional package ' + pkg + ' to be installed.\n' +
267
+ 'A registry mirror (e.g. npmmirror/cnpm) that did not mirror the per-platform\n' +
268
+ 'package is the usual cause. Fixes:\n' +
269
+ ' - install from the official registry:\n' +
270
+ ' npm i -g @colbymchenry/codegraph --registry=https://registry.npmjs.org\n' +
271
+ ' - or use the standalone installer (no Node required):\n' +
272
+ ' curl -fsSL https://raw.githubusercontent.com/' + REPO + '/main/install.sh | sh\n'
273
+ );
274
+ process.exit(1);
275
+ }
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # Assemble the npm thin-installer packages from built bundles (esbuild pattern).
4
+ #
5
+ # Produces, under release/npm/:
6
+ # codegraph-<target>/ one per built bundle — the vendored Node + app, tagged
7
+ # with os/cpu so npm installs only the matching one.
8
+ # main/ the @colbymchenry/codegraph shim package: a tiny bin
9
+ # that execs the matching platform bundle, with every
10
+ # platform package in optionalDependencies.
11
+ #
12
+ # The release pipeline then `npm publish`es each dir. This does NOT touch the
13
+ # repo's package.json — the dev/from-source path keeps working; the *published*
14
+ # main package's shape is generated here.
15
+ #
16
+ # Prereq: run build-bundle.sh for each target first (release/codegraph-*.tar.gz).
17
+ # Usage: scripts/pack-npm.sh [version] (default: version from package.json)
18
+ set -euo pipefail
19
+
20
+ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
21
+ VERSION="${1:-$(node -p "require('$ROOT/package.json').version")}"
22
+ SCOPE="@colbymchenry"
23
+ REL="$ROOT/release"
24
+ NPM="$REL/npm"
25
+
26
+ rm -rf "$NPM"
27
+ mkdir -p "$NPM/main"
28
+
29
+ shopt -s nullglob
30
+ archives=("$REL"/codegraph-*.tar.gz "$REL"/codegraph-*.zip)
31
+ [ ${#archives[@]} -gt 0 ] || { echo "[pack-npm] no bundles in $REL — run build-bundle.sh first" >&2; exit 1; }
32
+
33
+ targets=()
34
+ for archive in "${archives[@]}"; do
35
+ fname="$(basename "$archive")"
36
+ case "$fname" in
37
+ *.tar.gz) base="${fname%.tar.gz}" ;; # codegraph-<target>
38
+ *.zip) base="${fname%.zip}" ;;
39
+ esac
40
+ target="${base#codegraph-}" # <target>, e.g. darwin-arm64 / win32-x64
41
+ os="${target%-*}" # darwin | linux | win32
42
+ arch="${target##*-}" # arm64 | x64
43
+ pkgdir="$NPM/$base"
44
+ mkdir -p "$pkgdir"
45
+ case "$fname" in
46
+ *.zip)
47
+ tmpx="$(mktemp -d)"
48
+ unzip -q "$archive" -d "$tmpx"
49
+ mv "$tmpx/codegraph-${target}"/* "$pkgdir"/
50
+ rm -rf "$tmpx"
51
+ nodefile="node.exe"
52
+ ;;
53
+ *)
54
+ tar -xzf "$archive" -C "$pkgdir" --strip-components=1
55
+ nodefile="node"
56
+ ;;
57
+ esac
58
+ VERSION="$VERSION" SCOPE="$SCOPE" TARGET="$target" OSV="$os" ARCHV="$arch" NODEFILE="$nodefile" \
59
+ node -e '
60
+ const fs=require("fs");
61
+ fs.writeFileSync(process.argv[1], JSON.stringify({
62
+ name: `${process.env.SCOPE}/codegraph-${process.env.TARGET}`,
63
+ version: process.env.VERSION,
64
+ description: `CodeGraph self-contained bundle for ${process.env.TARGET}`,
65
+ os: [process.env.OSV], cpu: [process.env.ARCHV],
66
+ files: [process.env.NODEFILE, "lib", "bin"],
67
+ license: "MIT"
68
+ }, null, 2) + "\n");
69
+ ' "$pkgdir/package.json"
70
+ targets+=("$target")
71
+ echo "[pack-npm] ${SCOPE}/codegraph-${target}@${VERSION}"
72
+ done
73
+
74
+ # Main shim package.
75
+ # npm-shim.js CLI/MCP launcher (execs the bundled Node) — the `bin`.
76
+ # npm-sdk.js programmatic/embedded entry (#354): re-exports the installed
77
+ # platform bundle's compiled library — the `main`.
78
+ # dist/ the .d.ts tree only (types). The runtime .js stays in the
79
+ # per-platform bundle so its deps aren't duplicated here.
80
+ cp "$ROOT/scripts/npm-shim.js" "$NPM/main/npm-shim.js"
81
+ cp "$ROOT/scripts/npm-sdk.js" "$NPM/main/npm-sdk.js"
82
+ [ -f "$ROOT/README.md" ] && cp "$ROOT/README.md" "$NPM/main/README.md"
83
+
84
+ # Ship the type declarations so `types`/`exports.types` resolve. Built from this
85
+ # same release, so they can't skew from the runtime npm-sdk.js re-exports.
86
+ [ -f "$ROOT/dist/index.d.ts" ] || ( echo "[pack-npm] building dist for .d.ts" >&2 && cd "$ROOT" && npm run build >/dev/null )
87
+ ROOT="$ROOT" DEST="$NPM/main" node -e '
88
+ const fs=require("fs"), path=require("path");
89
+ const src=path.join(process.env.ROOT,"dist"), dest=path.join(process.env.DEST,"dist");
90
+ fs.cpSync(src, dest, { recursive:true, filter(s){
91
+ try { return fs.statSync(s).isDirectory() || s.endsWith(".d.ts"); } catch (e) { return false; }
92
+ }});
93
+ '
94
+
95
+ VERSION="$VERSION" SCOPE="$SCOPE" TARGETS="${targets[*]}" \
96
+ node -e '
97
+ const fs=require("fs");
98
+ const opt={};
99
+ for (const t of process.env.TARGETS.split(/\s+/).filter(Boolean))
100
+ opt[`${process.env.SCOPE}/codegraph-${t}`]=process.env.VERSION;
101
+ fs.writeFileSync(process.argv[1], JSON.stringify({
102
+ name: `${process.env.SCOPE}/codegraph`,
103
+ version: process.env.VERSION,
104
+ description: "Local-first code intelligence for AI agents (MCP). Self-contained — bundles its own runtime.",
105
+ bin: { codegraph: "npm-shim.js" },
106
+ main: "npm-sdk.js",
107
+ types: "dist/index.d.ts",
108
+ exports: {
109
+ ".": { types: "./dist/index.d.ts", default: "./npm-sdk.js" },
110
+ "./package.json": "./package.json"
111
+ },
112
+ optionalDependencies: opt,
113
+ files: ["npm-shim.js","npm-sdk.js","dist","README.md"],
114
+ license: "MIT"
115
+ }, null, 2) + "\n");
116
+ ' "$NPM/main/package.json"
117
+
118
+ echo "[pack-npm] ${SCOPE}/codegraph@${VERSION} (${#targets[@]} platform packages in optionalDependencies)"
119
+ echo "[pack-npm] output: $NPM"
@@ -0,0 +1,270 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Promote `## [Unreleased]` content into `## [<version>]` in CHANGELOG.md
4
+ * so the release.yml workflow's `extract-release-notes.mjs <version>` call
5
+ * picks up everything that landed since the last release.
6
+ *
7
+ * **Why this exists:** the release workflow used to do a literal
8
+ * `extract-release-notes.mjs <version>` lookup with an `[Unreleased]`
9
+ * fallback. The fallback only triggers if the `[<version>]` block
10
+ * doesn't exist at all — and in practice maintainers sometimes had a
11
+ * sparse `[<version>]` block pre-populated (e.g. one early fix
12
+ * documented before the rest of the work landed). The workflow then
13
+ * extracted that sparse block, ignoring the much larger `[Unreleased]`
14
+ * section above it — so the published release notes were missing most
15
+ * of what shipped. See v0.9.5 for the canonical post-mortem.
16
+ *
17
+ * **What it does**, idempotently:
18
+ *
19
+ * Case A — `[<version>]` does not exist yet:
20
+ * Rename the `[Unreleased]` header to `[<version>] - <YYYY-MM-DD>`
21
+ * and add a fresh empty `## [Unreleased]` block above it. This is
22
+ * the common case.
23
+ *
24
+ * Case B — `[<version>]` exists AND `[Unreleased]` has content:
25
+ * Merge `[Unreleased]`'s sub-sections (### Added / ### Fixed /
26
+ * ### Changed / ### Removed / ### Deprecated / ### Security) into
27
+ * the corresponding sub-sections of `[<version>]`. Unmatched
28
+ * sub-sections are appended to `[<version>]`. The `[Unreleased]`
29
+ * block is then emptied.
30
+ *
31
+ * Case C — `[Unreleased]` has no content:
32
+ * No-op. Exit 0. Re-runs of the workflow are safe.
33
+ *
34
+ * **Where the date comes from:** for Case A, `<YYYY-MM-DD>` is the
35
+ * UTC date at run time. Matches the existing CHANGELOG convention.
36
+ *
37
+ * **Usage:**
38
+ *
39
+ * node scripts/prepare-release.mjs # reads version from package.json
40
+ * node scripts/prepare-release.mjs 1.2.3 # explicit version
41
+ *
42
+ * **Output:**
43
+ *
44
+ * Writes CHANGELOG.md in place. Prints a summary line to stdout
45
+ * like `prepare-release: 0.9.5 — promoted 6 Unreleased entries`.
46
+ * Exits non-zero on parse failures.
47
+ */
48
+
49
+ import { readFileSync, writeFileSync } from 'node:fs';
50
+ import { resolve } from 'node:path';
51
+
52
+ const CHANGELOG_PATH = resolve(process.cwd(), 'CHANGELOG.md');
53
+
54
+ function readPackageVersion() {
55
+ const pkg = JSON.parse(readFileSync(resolve(process.cwd(), 'package.json'), 'utf8'));
56
+ if (!pkg.version) throw new Error('package.json has no "version" field');
57
+ return pkg.version;
58
+ }
59
+
60
+ function todayUtcIsoDate() {
61
+ // YYYY-MM-DD in UTC. Matches the CHANGELOG's existing convention
62
+ // (the existing dated entries don't disclose a timezone, but UTC is
63
+ // stable across runners and is what the workflow's runner produces
64
+ // by default anyway).
65
+ return new Date().toISOString().slice(0, 10);
66
+ }
67
+
68
+ /**
69
+ * Split the CHANGELOG into a header preface + an ordered list of
70
+ * version blocks `{ header, body[] }`, preserving line content
71
+ * verbatim so we can re-join without surprises.
72
+ */
73
+ function parseChangelog(text) {
74
+ const lines = text.split('\n');
75
+ const versionHeaderRe = /^## \[([^\]]+)\](?:\s+-\s+(.+))?\s*$/;
76
+ const preface = [];
77
+ const blocks = []; // { header: string, name: string, body: string[] }
78
+ let cur = null;
79
+ for (const line of lines) {
80
+ const m = line.match(versionHeaderRe);
81
+ if (m) {
82
+ if (cur) blocks.push(cur);
83
+ cur = { header: line, name: m[1], date: m[2] ?? null, body: [] };
84
+ } else if (cur) {
85
+ cur.body.push(line);
86
+ } else {
87
+ preface.push(line);
88
+ }
89
+ }
90
+ if (cur) blocks.push(cur);
91
+ return { preface, blocks };
92
+ }
93
+
94
+ function joinChangelog({ preface, blocks }) {
95
+ const parts = [preface.join('\n')];
96
+ for (const b of blocks) {
97
+ // Reconstruct: header + body. The block body INCLUDES the blank
98
+ // line after the header (it was captured verbatim).
99
+ parts.push([b.header, ...b.body].join('\n'));
100
+ }
101
+ return parts.join('\n');
102
+ }
103
+
104
+ /**
105
+ * Split a block body into ordered sub-sections keyed by their
106
+ * `### Heading`. Lines before the first `### Heading` go in
107
+ * `leading`. Preserves the original (line-array) body inside each
108
+ * sub-section so we can splice cleanly when merging.
109
+ */
110
+ function splitSubsections(body) {
111
+ const subsectionRe = /^### (\w+)\s*$/;
112
+ const leading = [];
113
+ const subs = []; // { heading: 'Added' | 'Fixed' | …, headerLine: string, body: string[] }
114
+ let cur = null;
115
+ for (const line of body) {
116
+ const m = line.match(subsectionRe);
117
+ if (m) {
118
+ if (cur) subs.push(cur);
119
+ cur = { heading: m[1], headerLine: line, body: [] };
120
+ } else if (cur) {
121
+ cur.body.push(line);
122
+ } else {
123
+ leading.push(line);
124
+ }
125
+ }
126
+ if (cur) subs.push(cur);
127
+ return { leading, subs };
128
+ }
129
+
130
+ function rebuildBody({ leading, subs }) {
131
+ const parts = [];
132
+ if (leading.length) parts.push(leading.join('\n'));
133
+ for (const s of subs) {
134
+ parts.push([s.headerLine, ...s.body].join('\n'));
135
+ }
136
+ return parts.join('\n').split('\n');
137
+ }
138
+
139
+ /**
140
+ * Return true when the block has any meaningful entries (a bullet line
141
+ * starting with `-`, `*`, or a digit) — vs. being empty / just
142
+ * whitespace / just sub-section headers with nothing under them.
143
+ */
144
+ function blockHasContent(body) {
145
+ for (const line of body) {
146
+ if (/^\s*([-*]|\d+\.)\s+/.test(line)) return true;
147
+ }
148
+ return false;
149
+ }
150
+
151
+ /**
152
+ * Trim trailing blank lines from an array of lines, then return.
153
+ * Keeps the output tidy when merging.
154
+ */
155
+ function trimTrailingBlank(arr) {
156
+ let i = arr.length;
157
+ while (i > 0 && /^\s*$/.test(arr[i - 1])) i--;
158
+ return arr.slice(0, i);
159
+ }
160
+
161
+ function main() {
162
+ const versionArg = process.argv[2];
163
+ const version = versionArg || readPackageVersion();
164
+
165
+ const text = readFileSync(CHANGELOG_PATH, 'utf8');
166
+ const parsed = parseChangelog(text);
167
+
168
+ const unrelIdx = parsed.blocks.findIndex((b) => b.name === 'Unreleased');
169
+ const verIdx = parsed.blocks.findIndex((b) => b.name === version);
170
+
171
+ if (unrelIdx === -1) {
172
+ console.log(`prepare-release: no [Unreleased] block — nothing to do`);
173
+ return;
174
+ }
175
+
176
+ const unrel = parsed.blocks[unrelIdx];
177
+ if (!blockHasContent(unrel.body)) {
178
+ console.log(`prepare-release: [Unreleased] is empty — nothing to do`);
179
+ return;
180
+ }
181
+
182
+ if (verIdx === -1) {
183
+ // Case A — promote Unreleased → [version].
184
+ const today = todayUtcIsoDate();
185
+ const promoted = {
186
+ header: `## [${version}] - ${today}`,
187
+ name: version,
188
+ date: today,
189
+ body: trimTrailingBlank(unrel.body).concat(['']), // single trailing blank
190
+ };
191
+ const emptied = {
192
+ header: `## [Unreleased]`,
193
+ name: 'Unreleased',
194
+ date: null,
195
+ body: ['', ''], // two blank lines for the next round of entries
196
+ };
197
+ parsed.blocks.splice(unrelIdx, 1, emptied, promoted);
198
+ const next = joinChangelog(parsed);
199
+ writeFileSync(CHANGELOG_PATH, appendLinkRef(next, version));
200
+ console.log(`prepare-release: ${version} — renamed [Unreleased] to [${version}] - ${today}`);
201
+ return;
202
+ }
203
+
204
+ // Case B — merge Unreleased sub-sections into the existing
205
+ // [version] sub-sections. New sub-section headings encountered in
206
+ // Unreleased that don't exist in [version] get appended.
207
+ const ver = parsed.blocks[verIdx];
208
+ const unrelSubs = splitSubsections(unrel.body);
209
+ const verSubs = splitSubsections(ver.body);
210
+
211
+ let merged = 0;
212
+ for (const us of unrelSubs.subs) {
213
+ const target = verSubs.subs.find((s) => s.heading === us.heading);
214
+ const usBody = trimTrailingBlank(us.body);
215
+ if (usBody.length === 0) continue;
216
+ if (target) {
217
+ // Append Unreleased's entries to the end of the version's matching
218
+ // sub-section, keeping their original ordering. Insert a separating
219
+ // blank line if the existing sub-section doesn't already end in one.
220
+ const existing = trimTrailingBlank(target.body);
221
+ const sep = existing.length && !/^\s*$/.test(existing[existing.length - 1]) ? [''] : [];
222
+ target.body = existing.concat(sep, usBody, ['']);
223
+ } else {
224
+ // Append the whole sub-section to the end.
225
+ verSubs.subs.push({
226
+ heading: us.heading,
227
+ headerLine: us.headerLine,
228
+ body: usBody.concat(['']),
229
+ });
230
+ }
231
+ merged += usBody.filter((l) => /^\s*([-*]|\d+\.)\s+/.test(l)).length;
232
+ }
233
+
234
+ ver.body = rebuildBody(verSubs);
235
+ // Empty out Unreleased.
236
+ unrel.body = ['', ''];
237
+
238
+ const merged_text = joinChangelog(parsed);
239
+ writeFileSync(CHANGELOG_PATH, appendLinkRef(merged_text, version));
240
+ console.log(`prepare-release: ${version} — merged ${merged} Unreleased entries into existing [${version}] block`);
241
+ }
242
+
243
+ /**
244
+ * Append a `[X.Y.Z]: https://github.com/colbymchenry/codegraph/releases/tag/vX.Y.Z`
245
+ * link reference at the end of the file IF one doesn't already exist. The
246
+ * link ref is what makes `## [X.Y.Z]` heading text auto-link to its tag in
247
+ * GitHub's renderer; without it the heading still renders, just unlinked.
248
+ *
249
+ * Idempotent. The existing CHANGELOG mixes link refs scattered through the
250
+ * file and a sorted block at the bottom — we just append at the very end,
251
+ * which CommonMark accepts regardless.
252
+ */
253
+ function appendLinkRef(text, version) {
254
+ const refLine = `[${version}]: https://github.com/colbymchenry/codegraph/releases/tag/v${version}`;
255
+ // Already there? Look for a line that EQUALS this (anywhere in the file)
256
+ // to keep idempotency robust against the scattered-vs-block layout.
257
+ const lines = text.split('\n');
258
+ if (lines.some((l) => l.trim() === refLine)) return text;
259
+ // Append, separated by a blank line from the prior content. Preserve a
260
+ // single trailing newline at EOF.
261
+ const trailingNewline = text.endsWith('\n') ? '' : '\n';
262
+ return text + trailingNewline + refLine + '\n';
263
+ }
264
+
265
+ try {
266
+ main();
267
+ } catch (err) {
268
+ console.error(`prepare-release: ${err?.message ?? err}`);
269
+ process.exit(1);
270
+ }