@countinghouse/ch-local 0.0.0-stage → 1.0.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 (262) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +361 -2
  3. package/bin/ch-local.js +472 -0
  4. package/clients/claude-code/.claude-plugin/plugin.json +6 -0
  5. package/clients/claude-code/.mcp.json +11 -0
  6. package/clients/claude-code/bin/launch.js +235 -0
  7. package/clients/claude-code/bin/win-acl.js +420 -0
  8. package/clients/claude-code/skills/ci-failure-triage/SKILL.md +21 -0
  9. package/clients/claude-code/skills/countinghouse-module/SKILL.md +177 -0
  10. package/clients/claude-code/skills/countinghouse-setup/SKILL.md +74 -0
  11. package/lib/allowlist.js +65 -0
  12. package/lib/aside.js +16 -0
  13. package/lib/atomic.js +45 -0
  14. package/lib/auto-apply.js +245 -0
  15. package/lib/auto-upgrade.js +98 -0
  16. package/lib/availability.js +307 -0
  17. package/lib/ceiling.js +280 -0
  18. package/lib/clean-text.js +20 -0
  19. package/lib/cli-change.js +38 -0
  20. package/lib/client-conditions-fixtures.js +143 -0
  21. package/lib/client-conditions.js +656 -0
  22. package/lib/clients.js +179 -0
  23. package/lib/command-line.js +202 -0
  24. package/lib/conditions-command.js +116 -0
  25. package/lib/control.js +134 -0
  26. package/lib/credential-store.js +414 -0
  27. package/lib/credentials-command.js +344 -0
  28. package/lib/daemon-requests.js +137 -0
  29. package/lib/daemon.js +888 -0
  30. package/lib/describe-module.js +137 -0
  31. package/lib/description-check.js +175 -0
  32. package/lib/failed-json.js +43 -0
  33. package/lib/gc.js +274 -0
  34. package/lib/github-token.js +57 -0
  35. package/lib/handoff-io.js +73 -0
  36. package/lib/held-back.js +116 -0
  37. package/lib/hidden-input.js +64 -0
  38. package/lib/history.js +49 -0
  39. package/lib/home.js +372 -0
  40. package/lib/in-place.js +1036 -0
  41. package/lib/install-plan.js +142 -0
  42. package/lib/install.js +846 -0
  43. package/lib/installed-description.js +153 -0
  44. package/lib/integrity.js +7 -0
  45. package/lib/lock.js +456 -0
  46. package/lib/lockfile-rules.js +98 -0
  47. package/lib/machine.js +20 -0
  48. package/lib/module-credentials.js +403 -0
  49. package/lib/module-record.js +298 -0
  50. package/lib/module-roles.js +44 -0
  51. package/lib/module-seams.js +26 -0
  52. package/lib/module-store.js +202 -0
  53. package/lib/module-values.js +334 -0
  54. package/lib/names.js +31 -0
  55. package/lib/next-steps.js +8 -0
  56. package/lib/node-check.js +56 -0
  57. package/lib/npm-fetch.js +123 -0
  58. package/lib/npm-release.js +99 -0
  59. package/lib/npm-upgrade.js +146 -0
  60. package/lib/npm.js +41 -0
  61. package/lib/outside-edits.js +162 -0
  62. package/lib/own-applied.js +175 -0
  63. package/lib/own-command.js +380 -0
  64. package/lib/own-file.js +120 -0
  65. package/lib/own-record.js +96 -0
  66. package/lib/own-tree.js +336 -0
  67. package/lib/pack-table.js +290 -0
  68. package/lib/packs-command.js +570 -0
  69. package/lib/packs.js +219 -0
  70. package/lib/pins.js +64 -0
  71. package/lib/pipe-probe.js +82 -0
  72. package/lib/plain-read.js +63 -0
  73. package/lib/private-file.js +90 -0
  74. package/lib/private-write.js +33 -0
  75. package/lib/provenance.js +234 -0
  76. package/lib/record.js +82 -0
  77. package/lib/registry.js +22 -0
  78. package/lib/release-pins.js +350 -0
  79. package/lib/release-pins.json +4225 -0
  80. package/lib/release-tags.js +12 -0
  81. package/lib/release.js +36 -0
  82. package/lib/restart-command.js +161 -0
  83. package/lib/rollback.js +227 -0
  84. package/lib/run-liveness.js +15 -0
  85. package/lib/runtime-log.js +287 -0
  86. package/lib/sandbox-support.js +17 -0
  87. package/lib/semver-order.js +40 -0
  88. package/lib/session-socket.js +69 -0
  89. package/lib/session-table.js +238 -0
  90. package/lib/session.js +281 -0
  91. package/lib/settings-command.js +82 -0
  92. package/lib/settings.js +564 -0
  93. package/lib/shim-binary.js +152 -0
  94. package/lib/shim-config.js +159 -0
  95. package/lib/shim-install.js +365 -0
  96. package/lib/sigstore/README.md +44 -0
  97. package/lib/sigstore/npm-keys.json +18 -0
  98. package/lib/sigstore/trusted-root.json +126 -0
  99. package/lib/snippets.js +76 -0
  100. package/lib/start.js +721 -0
  101. package/lib/store-files.js +48 -0
  102. package/lib/store-paths.js +33 -0
  103. package/lib/swap-preload.js +38 -0
  104. package/lib/tar.js +220 -0
  105. package/lib/uninstall.js +314 -0
  106. package/lib/unpack.js +41 -0
  107. package/lib/upgrade-stamp.js +63 -0
  108. package/lib/upgrade.js +281 -0
  109. package/lib/watch.js +40 -0
  110. package/lib/win-acl.js +420 -0
  111. package/node_modules/@sigstore/bundle/LICENSE +202 -0
  112. package/node_modules/@sigstore/bundle/README.md +19 -0
  113. package/node_modules/@sigstore/bundle/dist/build.d.ts +18 -0
  114. package/node_modules/@sigstore/bundle/dist/build.js +100 -0
  115. package/node_modules/@sigstore/bundle/dist/bundle.d.ts +74 -0
  116. package/node_modules/@sigstore/bundle/dist/bundle.js +24 -0
  117. package/node_modules/@sigstore/bundle/dist/error.d.ts +4 -0
  118. package/node_modules/@sigstore/bundle/dist/error.js +25 -0
  119. package/node_modules/@sigstore/bundle/dist/index.d.ts +8 -0
  120. package/node_modules/@sigstore/bundle/dist/index.js +43 -0
  121. package/node_modules/@sigstore/bundle/dist/serialized.d.ts +74 -0
  122. package/node_modules/@sigstore/bundle/dist/serialized.js +49 -0
  123. package/node_modules/@sigstore/bundle/dist/utility.d.ts +14 -0
  124. package/node_modules/@sigstore/bundle/dist/utility.js +2 -0
  125. package/node_modules/@sigstore/bundle/dist/validate.d.ts +7 -0
  126. package/node_modules/@sigstore/bundle/dist/validate.js +199 -0
  127. package/node_modules/@sigstore/bundle/package.json +35 -0
  128. package/node_modules/@sigstore/core/LICENSE +202 -0
  129. package/node_modules/@sigstore/core/README.md +10 -0
  130. package/node_modules/@sigstore/core/dist/asn1/error.d.ts +4 -0
  131. package/node_modules/@sigstore/core/dist/asn1/error.js +24 -0
  132. package/node_modules/@sigstore/core/dist/asn1/index.d.ts +1 -0
  133. package/node_modules/@sigstore/core/dist/asn1/index.js +20 -0
  134. package/node_modules/@sigstore/core/dist/asn1/length.d.ts +3 -0
  135. package/node_modules/@sigstore/core/dist/asn1/length.js +62 -0
  136. package/node_modules/@sigstore/core/dist/asn1/obj.d.ts +14 -0
  137. package/node_modules/@sigstore/core/dist/asn1/obj.js +155 -0
  138. package/node_modules/@sigstore/core/dist/asn1/parse.d.ts +6 -0
  139. package/node_modules/@sigstore/core/dist/asn1/parse.js +124 -0
  140. package/node_modules/@sigstore/core/dist/asn1/tag.d.ts +16 -0
  141. package/node_modules/@sigstore/core/dist/asn1/tag.js +89 -0
  142. package/node_modules/@sigstore/core/dist/crypto.d.ts +6 -0
  143. package/node_modules/@sigstore/core/dist/crypto.js +69 -0
  144. package/node_modules/@sigstore/core/dist/dsse.d.ts +1 -0
  145. package/node_modules/@sigstore/core/dist/dsse.js +29 -0
  146. package/node_modules/@sigstore/core/dist/encoding.d.ts +2 -0
  147. package/node_modules/@sigstore/core/dist/encoding.js +27 -0
  148. package/node_modules/@sigstore/core/dist/index.d.ts +9 -0
  149. package/node_modules/@sigstore/core/dist/index.js +66 -0
  150. package/node_modules/@sigstore/core/dist/json.d.ts +1 -0
  151. package/node_modules/@sigstore/core/dist/json.js +60 -0
  152. package/node_modules/@sigstore/core/dist/oid.d.ts +3 -0
  153. package/node_modules/@sigstore/core/dist/oid.js +20 -0
  154. package/node_modules/@sigstore/core/dist/pem.d.ts +2 -0
  155. package/node_modules/@sigstore/core/dist/pem.js +43 -0
  156. package/node_modules/@sigstore/core/dist/rfc3161/error.d.ts +2 -0
  157. package/node_modules/@sigstore/core/dist/rfc3161/error.js +21 -0
  158. package/node_modules/@sigstore/core/dist/rfc3161/index.d.ts +1 -0
  159. package/node_modules/@sigstore/core/dist/rfc3161/index.js +20 -0
  160. package/node_modules/@sigstore/core/dist/rfc3161/timestamp.d.ts +36 -0
  161. package/node_modules/@sigstore/core/dist/rfc3161/timestamp.js +212 -0
  162. package/node_modules/@sigstore/core/dist/rfc3161/tstinfo.d.ts +12 -0
  163. package/node_modules/@sigstore/core/dist/rfc3161/tstinfo.js +72 -0
  164. package/node_modules/@sigstore/core/dist/stream.d.ts +21 -0
  165. package/node_modules/@sigstore/core/dist/stream.js +117 -0
  166. package/node_modules/@sigstore/core/dist/x509/cert.d.ts +43 -0
  167. package/node_modules/@sigstore/core/dist/x509/cert.js +245 -0
  168. package/node_modules/@sigstore/core/dist/x509/ext.d.ts +41 -0
  169. package/node_modules/@sigstore/core/dist/x509/ext.js +146 -0
  170. package/node_modules/@sigstore/core/dist/x509/index.d.ts +2 -0
  171. package/node_modules/@sigstore/core/dist/x509/index.js +23 -0
  172. package/node_modules/@sigstore/core/dist/x509/sct.d.ts +25 -0
  173. package/node_modules/@sigstore/core/dist/x509/sct.js +158 -0
  174. package/node_modules/@sigstore/core/package.json +31 -0
  175. package/node_modules/@sigstore/protobuf-specs/LICENSE +202 -0
  176. package/node_modules/@sigstore/protobuf-specs/README.md +5 -0
  177. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/envelope.d.ts +44 -0
  178. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/envelope.js +59 -0
  179. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/events.d.ts +64 -0
  180. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/events.js +174 -0
  181. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/api/field_behavior.d.ts +74 -0
  182. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/api/field_behavior.js +141 -0
  183. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/any.d.ts +74 -0
  184. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/any.js +35 -0
  185. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/descriptor.d.ts +1309 -0
  186. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/descriptor.js +2191 -0
  187. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/timestamp.d.ts +113 -0
  188. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/timestamp.js +29 -0
  189. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/dsse.d.ts +23 -0
  190. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/dsse.js +55 -0
  191. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/entry.d.ts +43 -0
  192. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/entry.js +81 -0
  193. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/hashedrekord.d.ts +22 -0
  194. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/hashedrekord.js +56 -0
  195. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/verifier.d.ts +35 -0
  196. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/verifier.js +74 -0
  197. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_bundle.d.ts +146 -0
  198. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_bundle.js +103 -0
  199. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_common.d.ts +304 -0
  200. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_common.js +612 -0
  201. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_monitor.d.ts +33 -0
  202. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_monitor.js +55 -0
  203. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_rekor.d.ts +144 -0
  204. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_rekor.js +137 -0
  205. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_trustroot.d.ts +386 -0
  206. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_trustroot.js +284 -0
  207. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_verification.d.ts +191 -0
  208. package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_verification.js +281 -0
  209. package/node_modules/@sigstore/protobuf-specs/dist/index.d.ts +6 -0
  210. package/node_modules/@sigstore/protobuf-specs/dist/index.js +37 -0
  211. package/node_modules/@sigstore/protobuf-specs/dist/rekor/v2/index.d.ts +4 -0
  212. package/node_modules/@sigstore/protobuf-specs/dist/rekor/v2/index.js +35 -0
  213. package/node_modules/@sigstore/protobuf-specs/package.json +35 -0
  214. package/node_modules/@sigstore/verify/README.md +9 -0
  215. package/node_modules/@sigstore/verify/dist/bundle/dsse.d.ts +12 -0
  216. package/node_modules/@sigstore/verify/dist/bundle/dsse.js +44 -0
  217. package/node_modules/@sigstore/verify/dist/bundle/index.d.ts +4 -0
  218. package/node_modules/@sigstore/verify/dist/bundle/index.js +59 -0
  219. package/node_modules/@sigstore/verify/dist/bundle/message.d.ts +13 -0
  220. package/node_modules/@sigstore/verify/dist/bundle/message.js +54 -0
  221. package/node_modules/@sigstore/verify/dist/error.d.ts +16 -0
  222. package/node_modules/@sigstore/verify/dist/error.js +34 -0
  223. package/node_modules/@sigstore/verify/dist/index.d.ts +6 -0
  224. package/node_modules/@sigstore/verify/dist/index.js +28 -0
  225. package/node_modules/@sigstore/verify/dist/key/certificate.d.ts +21 -0
  226. package/node_modules/@sigstore/verify/dist/key/certificate.js +216 -0
  227. package/node_modules/@sigstore/verify/dist/key/index.d.ts +10 -0
  228. package/node_modules/@sigstore/verify/dist/key/index.js +75 -0
  229. package/node_modules/@sigstore/verify/dist/key/sct.d.ts +4 -0
  230. package/node_modules/@sigstore/verify/dist/key/sct.js +78 -0
  231. package/node_modules/@sigstore/verify/dist/policy.d.ts +5 -0
  232. package/node_modules/@sigstore/verify/dist/policy.js +50 -0
  233. package/node_modules/@sigstore/verify/dist/shared.types.d.ts +50 -0
  234. package/node_modules/@sigstore/verify/dist/shared.types.js +2 -0
  235. package/node_modules/@sigstore/verify/dist/timestamp/index.d.ts +11 -0
  236. package/node_modules/@sigstore/verify/dist/timestamp/index.js +24 -0
  237. package/node_modules/@sigstore/verify/dist/timestamp/tsa.d.ts +3 -0
  238. package/node_modules/@sigstore/verify/dist/timestamp/tsa.js +63 -0
  239. package/node_modules/@sigstore/verify/dist/tlog/checkpoint.d.ts +11 -0
  240. package/node_modules/@sigstore/verify/dist/tlog/checkpoint.js +154 -0
  241. package/node_modules/@sigstore/verify/dist/tlog/dsse.d.ts +6 -0
  242. package/node_modules/@sigstore/verify/dist/tlog/dsse.js +106 -0
  243. package/node_modules/@sigstore/verify/dist/tlog/hashedrekord.d.ts +6 -0
  244. package/node_modules/@sigstore/verify/dist/tlog/hashedrekord.js +94 -0
  245. package/node_modules/@sigstore/verify/dist/tlog/index.d.ts +5 -0
  246. package/node_modules/@sigstore/verify/dist/tlog/index.js +92 -0
  247. package/node_modules/@sigstore/verify/dist/tlog/intoto.d.ts +3 -0
  248. package/node_modules/@sigstore/verify/dist/tlog/intoto.js +62 -0
  249. package/node_modules/@sigstore/verify/dist/tlog/merkle.d.ts +3 -0
  250. package/node_modules/@sigstore/verify/dist/tlog/merkle.js +104 -0
  251. package/node_modules/@sigstore/verify/dist/tlog/set.d.ts +3 -0
  252. package/node_modules/@sigstore/verify/dist/tlog/set.js +60 -0
  253. package/node_modules/@sigstore/verify/dist/trust/filter.d.ts +8 -0
  254. package/node_modules/@sigstore/verify/dist/trust/filter.js +23 -0
  255. package/node_modules/@sigstore/verify/dist/trust/index.d.ts +5 -0
  256. package/node_modules/@sigstore/verify/dist/trust/index.js +90 -0
  257. package/node_modules/@sigstore/verify/dist/trust/trust.types.d.ts +29 -0
  258. package/node_modules/@sigstore/verify/dist/trust/trust.types.js +2 -0
  259. package/node_modules/@sigstore/verify/dist/verifier.d.ts +31 -0
  260. package/node_modules/@sigstore/verify/dist/verifier.js +160 -0
  261. package/node_modules/@sigstore/verify/package.json +36 -0
  262. package/package.json +37 -4
package/lib/upgrade.js ADDED
@@ -0,0 +1,281 @@
1
+ 'use strict';
2
+ // ch-local upgrade (spec §2, "Upgrade: easy, never silent"): shows the installed
3
+ // and available versions and asks once. `--auto on|off` stores the opt-in
4
+ // automatic-upgrade setting (off by default) and contacts nothing.
5
+ const {cleanText} = require('./clean-text');
6
+ const {layout} = require('./home');
7
+ const {latestVersions} = require('./registry');
8
+ const {readModulesRecord: readRecord, own, judgedDigest} = require('./module-record');
9
+ const {UNRELEASED_LINE} = require('./pins');
10
+ const {appendHistory} = require('./history');
11
+ const {findUpgrade, releaseAllow, SELF, pluginVersionOf, PLUGIN_MANIFEST} = require('./npm-upgrade');
12
+ const {withdrawnLine, removeHint, releaseSelection} = require('./packs');
13
+ const {short} = require('./release-pins');
14
+ const {chLocal, hintCommand} = require('./command-line');
15
+
16
+ const nums = (v) => String(v).split(/[.+-]/).slice(0, 3).map((x) => parseInt(x, 10) || 0);
17
+ function newer(a, b) {
18
+ const [x, y] = [nums(a), nums(b)];
19
+ for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return x[i] > y[i];
20
+ return false;
21
+ }
22
+
23
+ // What a release does to the installed modules (#413 rev 3 section 9.6: the
24
+ // preview, before anything is fetched), from the home's record and the new
25
+ // release's pins. packs: the record's packs (those the release lists are the
26
+ // ones it moves, a pack relisted after a withdrawal included: install's
27
+ // touchedPacks). Judged per pack, against that pack's own list in the new
28
+ // release (the medium on L4, 4 and 5); each module is told once, with every
29
+ // such pack that holds it (as additions does):
30
+ // moves: [{module, from, to, back, packs}]: a version that changes,
31
+ // back saying it moves back
32
+ // dropped: [{module, packs, keptBy}]: a module a pack no longer lists;
33
+ // keptBy, the served packs (releaseSelection's) whose new list
34
+ // keeps it (it stays running through them), or none (section 9.7:
35
+ // it stays installed and is not started; the Reviewer's high on
36
+ // L4, 6; a pack not running keeps nothing running: its medium, 6)
37
+ // A pack the release does not list is withdrawn as a whole and said so
38
+ // elsewhere; its modules are not counted here.
39
+ function releaseMoves(record, allow, packs, served = packs) {
40
+ const moved = new Map(); // module -> {from, to, packs}
41
+ const dropped = new Map(); // module -> [pack]
42
+ for (const name of packs) {
43
+ if (!own(allow.packs, name) || !own(record.packs, name)) continue;
44
+ const listed = new Set(allow.packs[name].modules || []);
45
+ for (const m of Object.keys(record.packs[name].modules || {})) {
46
+ if (!listed.has(m)) { if (!dropped.has(m)) dropped.set(m, []); dropped.get(m).push(name); continue; }
47
+ const was = own(record.modules, m) ? record.modules[m].version : null;
48
+ const to = own(allow.pins, m) ? allow.pins[m].version : null;
49
+ if (was == null || to == null || was === to) continue;
50
+ if (!moved.has(m)) moved.set(m, {from: was, to, packs: []});
51
+ moved.get(m).packs.push(name);
52
+ }
53
+ }
54
+ const keeps = (m) => served.filter((n) => own(allow.packs, n) && own(record.packs, n) && (allow.packs[n].modules || []).includes(m)).sort();
55
+ const byName = ([a], [b]) => (a < b ? -1 : 1);
56
+ return {
57
+ moves: [...moved].sort(byName).map(([m, x]) => ({module: m, from: x.from, to: x.to, back: newer(x.from, x.to), packs: x.packs.sort()})),
58
+ dropped: [...dropped].sort(byName).map(([m, ps]) => ({module: m, packs: ps.sort(), keptBy: keeps(m)}))
59
+ };
60
+ }
61
+ const droppedWhat = (x) => (x.keptBy.length > 0 ? `it stays running through ${x.keptBy.join(', ')}` : 'it stays installed and is not started');
62
+ // the preview's lines for releaseMoves()
63
+ function movesLines({moves, dropped}) {
64
+ const lines = [];
65
+ if (moves.length > 0) {
66
+ lines.push(`its modules move:\n${moves.map((x) => ` ${short(x.module)} ${x.from} -> ${x.to}${x.back ? ', back to an earlier version' : ''} (${x.packs.join(', ')})`).join('\n')}`);
67
+ }
68
+ if (dropped.length > 0) {
69
+ lines.push(`it no longer lists:\n${dropped.map((x) => ` ${short(x.module)} (${x.packs.join(', ')}): ${droppedWhat(x)}`).join('\n')}`);
70
+ }
71
+ return lines;
72
+ }
73
+ // The automatic upgrade's session line (the Reviewer's high on L4, 1): a
74
+ // module moving back and a module dropped are never silent, though neither
75
+ // holds the upgrade. -> its parts, each starting "; ".
76
+ function autoMovesText({moves, dropped}) {
77
+ return moves.filter((x) => x.back).map((x) => `; ${short(x.module)} moved back ${x.from} -> ${x.to} (${x.packs.join(', ')})`).join('') +
78
+ dropped.map((x) => `; ${short(x.module)} is no longer in ${x.packs.join(', ')}: ${droppedWhat(x)}`).join('');
79
+ }
80
+
81
+ // The development overrides (docs/development/auto-upgrade.md,
82
+ // "Development overrides never reach a real upgrade"): while one is in force,
83
+ // neither upgrade nor the automatic one runs. -> its name, or null
84
+ function devOverride(env, record) {
85
+ if (env != null && env.CH_LOCAL_DEV != null && env.CH_LOCAL_DEV !== '') return 'CH_LOCAL_DEV';
86
+ if (env != null && env.CH_LOCAL_REMOTE_MAP != null && env.CH_LOCAL_REMOTE_MAP !== '') return 'CH_LOCAL_REMOTE_MAP';
87
+ if (record != null && record.unreleased === true) return 'an unreleased install';
88
+ return null;
89
+ }
90
+
91
+ // The Claude Code plugin's version in the installed release: the home's
92
+ // installed ch-local package's manifest, else this ch-local's own (null:
93
+ // none readable)
94
+ function installedPlugin(where) {
95
+ const read = (file) => pluginVersionOf(() => require('node:fs').readFileSync(file, 'utf8'));
96
+ const app = read(require('node:path').join(where.app, 'node_modules', ...SELF.split('/'), ...PLUGIN_MANIFEST.split('/')));
97
+ return app != null ? app : read(require('node:path').join(__dirname, '..', ...PLUGIN_MANIFEST.split('/')));
98
+ }
99
+ // The plugin step, said whenever the release's plugin version differs from
100
+ // the installed release's: Claude Code's own steps, as its CLI help gives
101
+ // them (`claude plugin --help`, 2.1.329: marketplace update, then plugin
102
+ // update, "restart required to apply"). Said whether or not the user has
103
+ // updated already; no program is run to find out (the reviewer, 11-20).
104
+ // (installed: the installed release's version, read BEFORE any install: after
105
+ // it the home's app holds the new release's manifest) -> the line, or null
106
+ function pluginStep(found, installed, done) {
107
+ // (newer only: never a "move" back; the medium on the easy upgrades, 5)
108
+ if (found.plugin == null || installed == null || !newer(found.plugin, installed)) return null;
109
+ return `If you use the ch-packs plugin in Claude Code, it ${done ? 'moved' : 'moves'} with this release (${installed} -> ${found.plugin}): ${done ? '' : 'after the upgrade, '}run \`claude plugin marketplace update ch-packs\`, then \`claude plugin update ch-packs@ch-packs\`, then restart Claude Code.`;
110
+ }
111
+ // `upgrade --check`'s result, for the overview: <home>/upgrade-available.json,
112
+ // written whole (not upgrade-check.json, the automatic upgrade's own stamp,
113
+ // which decides when new code runs)
114
+ // (a result that no longer holds -- a check that could not be made, an
115
+ // install, a rollback -- is removed, never left saying an update is there:
116
+ // the medium on the easy upgrades, 3; a write that fails changes nothing the
117
+ // check says, 7)
118
+ const AVAILABLE_FILE = 'upgrade-available.json';
119
+ function writeAvailable(where, fields) {
120
+ try {
121
+ require('./atomic').writeAtomic(require('node:path').join(where.home, AVAILABLE_FILE), `${JSON.stringify(Object.assign({v: 1, checkedAt: new Date().toISOString()}, fields))}\n`);
122
+ } catch (e) { /* the overview then says nothing of it */ }
123
+ }
124
+ function forgetAvailable(where) {
125
+ try { require('node:fs').rmSync(require('node:path').join(where.home, AVAILABLE_FILE), {force: true}); } catch (e) { /* as above */ }
126
+ }
127
+
128
+ // fromNpm: {registry, trust}, passed only by a test's own code
129
+ // check: `upgrade --check`, read-only: everything upgrade shows up to its
130
+ // question, then the install line for the user's own terminal; nothing asked
131
+ // or installed, no terminal needed, nothing recorded in history; the result
132
+ // written for the overview (A-own-skill's easy upgrades)
133
+ // (a release in a later pins format: the way out, on this home: A1)
134
+ const laterWay = (where, packs) => {
135
+ const {npxLatest, homeNote} = require('./command-line');
136
+ const first = Array.isArray(packs) && require('./names').PACK.test(String(packs[0])) ? packs[0] : '<name>';
137
+ // (a fresh install, said as one: it asks again rather than comparing with
138
+ // what the home has, the reviewer on #128)
139
+ return `; this ch-local can't read that release's pins; to move to it, install it afresh: \`${npxLatest(where, `install --pack ${first}`)}\`${homeNote(where)} (a fresh install: it shows what it installs and asks you again, rather than comparing with what you have)`;
140
+ };
141
+
142
+ async function upgrade({auto, check = false}, io, fromNpm = {}) {
143
+ const say = (s) => io.stdout.write(s + '\n');
144
+ const where = layout(io.env, io.homedir);
145
+ // (a check that could not be made leaves no earlier answer standing: the
146
+ // medium on the easy upgrades, 3)
147
+ const fail = (s) => { if (check) forgetAvailable(where); io.stderr.write(`ch-local: ${s}\n`); };
148
+ if (auto !== undefined) {
149
+ if (auto !== 'on' && auto !== 'off') { fail('--auto takes on or off'); return 2; }
150
+ // turning it on loosens a guarding setting: the ceiling, and a yes at a terminal
151
+ const {code} = await require('./cli-change').cliSet(where, 'autoUpgrade', auto, io);
152
+ if (code !== 0) return code;
153
+ say(auto === 'on'
154
+ ? `automatic upgrades are on: start checks for new versions at most once a day; a new one, checked by its pins and its provenance, installs automatically ${autoWhen}, and runs new code with your keys; ${autoWaits(where, io.platform)}; ${autoBack(where, io.platform)}`
155
+ : 'automatic upgrades are off (the default): upgrade always asks');
156
+ return 0;
157
+ }
158
+ let record = null;
159
+ try { record = readRecord(where); } catch (err) { fail(err.message); return 1; }
160
+ if (record == null) { fail('nothing is installed yet'); return 1; }
161
+ const from = record.runtime != null && record.runtime.versions != null ? record.runtime.versions[SELF] : null;
162
+ const history = (outcome, fields) => { if (!check) appendHistory(where, Object.assign({kind: 'upgrade', how: 'cli', outcome, from}, fields)); };
163
+ if (record.unreleased) { history('override', {reason: 'an unreleased install'}); fail(`${UNRELEASED_LINE}: reinstall with \`${chLocal(where, 'install --pack <name> --from <release directory>')}\` first`); return 1; }
164
+ const override = devOverride(io.env, record);
165
+ if (override != null) { history('override', {reason: override}); fail(`upgrades are off while a development override is set (${override})`); return 1; }
166
+
167
+ const {ALLOWLIST} = require('./allowlist');
168
+ const data = ALLOWLIST;
169
+ const packs = Object.keys(record.packs || {});
170
+ let found;
171
+ try {
172
+ // (additions judged against what the home has installed: L4)
173
+ // (computed only once a release is found to judge: the medium on L4, 8)
174
+ // (by the home's own release's pins, whichever ch-local runs: post-rel
175
+ // L4 baseline)
176
+ const now = () => require('./installed-description').homeDescription(where, record, data);
177
+ found = await findUpgrade({data, now, installed: from, packs, io, allowMajor: true, ...fromNpm});
178
+ } catch (err) {
179
+ const to = err.version != null ? err.version : null;
180
+ fail(`${err.package != null ? err.package : SELF}${to != null ? `@${to}` : ''}: ${err.message}: not installed${err.code != null ? ` (${err.code})` : ''}${err.later === true ? laterWay(where, packs) : ''}`);
181
+ history(err.code === 'FETCH_FAILED' || err.code === 'FETCH_TOO_LARGE' ? 'unreachable' : 'refused', {to, reason: err.code || err.message});
182
+ return 1;
183
+ }
184
+ if (found.kind === 'up-to-date') {
185
+ if (check) writeAvailable(where, {installed: from, available: null, major: false, breaking: false, plugin: null});
186
+ say('everything is up to date');
187
+ return 0;
188
+ }
189
+ say(`ch-local ${from} -> ${found.to}, its provenance checked (published ${found.publishedAt.toISOString()})`);
190
+ // a major goes through every check above; it is shown so, and installed only on a yes
191
+ if (found.major === true) say(`ch-local ${found.to} is a major upgrade: it may change how things work (an automatic upgrade never takes it)`);
192
+ if (found.breaking === true) say('under semver a 0.x minor or 0.0.x patch may break what works now (an automatic upgrade never takes it)');
193
+ // (the release's security marking, as rollback says it, and its own change
194
+ // notes: text ch-local didn't write, cleaned before it reaches a terminal
195
+ // an agent may read -- the feature audit, K3)
196
+ const marking = found.data.release.security;
197
+ if (marking != null) say(`ch-local ${found.to} is a security fix: ${cleanText(marking.fixes, 500)}`);
198
+ const notes = found.data.release.notes;
199
+ if (Array.isArray(notes)) say(`changes in ${found.to}:\n${notes.map((n) => ` - ${cleanText(n)}`).join('\n')}`);
200
+ if (found.adds.length > 0) say(`it adds:\n${found.adds.map((x) => ` ${x}`).join('\n')}`);
201
+ if (found.identity.length > 0) say(`its identity changes (an automatic upgrade never takes these):\n${found.identity.map((x) => ` ${x}`).join('\n')}`);
202
+ if (found.named.length > 0) say(`for packs not installed:\n${found.named.map((x) => ` ${x}`).join('\n')}`);
203
+ // A release is a tested set, installed as one (#413 rev 3 section 9.6;
204
+ // L4): every pack the release lists moves to its pins in one operation,
205
+ // whichever way each module's version moves, and none is asked about. A
206
+ // pack the record lists as withdrawn stays recorded (section 9.7); one the
207
+ // release lists again is served again, its modules additions ("it adds"
208
+ // says so: the Reviewer's high on L4, 4); a home with no pack served
209
+ // still upgrades, runtime only (a later release may be the security fix
210
+ // it needs)
211
+ // a release that withdraws the home's pack still upgrades (maintainer's
212
+ // decision, 2026-11-17: a pack is usually withdrawn for a security problem,
213
+ // and the old release would keep running it): the runtime only, the pack's
214
+ // entry, files and data kept; start then skips it, said
215
+ const allow = releaseAllow(found.data, found.to, {found, installedSelf: ALLOWLIST.self});
216
+ // (one rule with the automatic upgrade: lib/packs.js releaseSelection)
217
+ const {withdrawn, served, target} = releaseSelection(record, allow, data);
218
+ if (withdrawn.length > 0) say(`it withdraws:\n${withdrawn.map((x) => ` ${x} (it stays installed and is not started after the upgrade; ${removeHint(x, where)})`).join('\n')}`);
219
+ // each installed module whose version changes, and each the release no
220
+ // longer lists, once each (section 9.6)
221
+ for (const line of movesLines(releaseMoves(record, allow, packs, served))) say(line);
222
+ // (the installed release's plugin version, read before anything installs)
223
+ const pluginBefore = installedPlugin(where);
224
+ const step = pluginStep(found, pluginBefore, false);
225
+ if (check) {
226
+ writeAvailable(where, {installed: from, available: found.to, major: found.major === true, breaking: found.breaking === true,
227
+ plugin: found.plugin != null ? {installed: pluginBefore, latest: found.plugin} : null});
228
+ if (step != null) say(step);
229
+ say(`To install it, run in your own terminal: \`${chLocal(where, 'upgrade')}\``);
230
+ return 0;
231
+ }
232
+ // the yes is a person's at a terminal, as for any loosening (lib/cli-change.js):
233
+ // a piped answer would take a release under 72 hours, its changes unseen
234
+ if (io.interactive !== true) { history('no-terminal', {to: found.to}); fail(`installing ${found.to} is confirmed at a terminal: run ${chLocal(where, 'upgrade')} in one; nothing changed`); return 2; }
235
+ const answer = String(await io.ask(`Upgrade to ${found.to}? (yes/no) `)).trim().toLowerCase();
236
+ if (answer !== 'yes') { history('declined', {to: found.to}); say('nothing changed'); return 0; }
237
+ // (install from a release moves every pack of the record the release
238
+ // lists, at its pins, with no version question: lib/install-plan.js
239
+ // touchedPacks; a home with none it lists is the runtime only)
240
+ // (the record this preview judged: install refuses another, under its lock)
241
+ const code = await require('./install').install({...target, judged: judgedDigest(record)}, io, allow, fromNpm);
242
+ if (code !== 0) { history('failed', {to: found.to}); fail(`the upgrade to ${found.to} failed; nothing changed`); return code; }
243
+ history('installed', {to: found.to});
244
+ const pluginMoved = pluginStep(found, pluginBefore, true);
245
+ say(`upgraded ch-local ${from} -> ${found.to}; ${chLocal(where, 'rollback')} undoes it`);
246
+ for (const name of withdrawn) {
247
+ appendHistory(where, {change: 'withdrawn', pack: name, by: 'cli', to: found.to, notice: withdrawnLine(name, where)});
248
+ say(withdrawnLine(name, where));
249
+ }
250
+ if (pluginMoved != null) say(pluginMoved);
251
+ return 0;
252
+ }
253
+
254
+ // What an automatic upgrade installs and when (lib/auto-apply.js: the wait
255
+ // from the later of publication and this home first seeing it; what it
256
+ // announces and never installs), and the way back (lib/rollback.js: one level,
257
+ // while it is kept). Said when it is turned on and when it is offered.
258
+ const autoWhen = 'at the first check 72 hours or more after it was published and first seen here';
259
+ const autoWaits = (where, platform) => `a major or breaking version, or one that adds to what you have or changes its identity, always waits for your own ${hintCommand(where, 'upgrade', platform)}`;
260
+ const autoBack = (where, platform) => `${hintCommand(where, 'rollback', platform)} returns to the version before, while it is kept`;
261
+
262
+ // After an install (docs/development/auto-upgrade.md, "Turning it on"): with
263
+ // autoUpgrade never answered, asked once, at a terminal only, through
264
+ // cliSet, whose own question under the operator's ceiling is the one asked;
265
+ // a no is kept as off, so it is never asked again; with no terminal, off,
266
+ // said so.
267
+ async function offerAuto(io) {
268
+ const say = (s) => io.stdout.write(s + '\n');
269
+ const where = layout(io.env, io.homedir);
270
+ const {readSettings, setSetting} = require('./settings');
271
+ if (readSettings(where).values.autoUpgrade !== undefined) return;
272
+ if (io.interactive !== true) { say(`automatic upgrades are off (no terminal to ask); ${chLocal(where, 'upgrade --auto on')} turns them on`); return; }
273
+ say(`Automatic upgrades install a new version of ch-local and its packs, checked by its pin and its provenance, ${autoWhen}; ${autoWaits(where, io.platform)}. ${autoBack(where, io.platform)}.`);
274
+ const {code} = await require('./cli-change').cliSet(where, 'autoUpgrade', 'on', io);
275
+ if (code === 0) { say('automatic upgrades are on'); return; }
276
+ // asked and declined: the answer is kept, never asked again
277
+ if (code === 1) { try { setSetting(where, 'autoUpgrade', 'off', {by: 'cli'}); } catch (e) { /* left unset */ } }
278
+ say(`automatic upgrades stay off; ${chLocal(where, 'upgrade --auto on')} turns them on`);
279
+ }
280
+
281
+ module.exports = {autoWaits, autoBack, laterWay, releaseMoves, movesLines, autoMovesText, upgrade, newer, devOverride, offerAuto, forgetAvailable, AVAILABLE_FILE};
package/lib/watch.js ADDED
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+ // Watching the home for pack changes (packs in place, part 2, plan Task B3):
3
+ // fs.watch on the home, filtered to the files that matter, and a poll every
4
+ // pollMs as a fallback (a watch can miss events on some file systems). A burst
5
+ // of changes is debounced into one call.
6
+ const fs = require('node:fs');
7
+ const path = require('node:path');
8
+
9
+ // -> {stop()}
10
+ function watchFiles(dir, names, onChange, {pollMs = 2000, debounceMs = 150} = {}) {
11
+ let timer = null;
12
+ let last = new Map(names.map((n) => [n, stamp(path.join(dir, n))]));
13
+ const fire = () => {
14
+ if (timer != null) return;
15
+ timer = setTimeout(() => { timer = null; onChange(); }, debounceMs);
16
+ if (typeof timer.unref === 'function') timer.unref();
17
+ };
18
+ let watcher = null;
19
+ try {
20
+ watcher = fs.watch(dir, (event, file) => { if (file == null || names.includes(String(file))) fire(); });
21
+ watcher.on('error', () => { /* the poll goes on */ });
22
+ // never what keeps start alive (its runtime child does): a start whose
23
+ // runtime has ended, or a test that failed before ending its start,
24
+ // exits instead of waiting on the watch (ch-local #21's Windows leg)
25
+ if (typeof watcher.unref === 'function') watcher.unref();
26
+ } catch (err) { watcher = null; }
27
+ const poll = setInterval(() => {
28
+ const now = new Map(names.map((n) => [n, stamp(path.join(dir, n))]));
29
+ if (names.some((n) => now.get(n) !== last.get(n))) fire();
30
+ last = now;
31
+ }, pollMs);
32
+ if (typeof poll.unref === 'function') poll.unref();
33
+ return {stop: () => { clearInterval(poll); if (timer != null) clearTimeout(timer); if (watcher != null) watcher.close(); }};
34
+ }
35
+
36
+ function stamp(file) {
37
+ try { const s = fs.statSync(file); return `${s.mtimeMs}:${s.size}:${s.ino}`; } catch (err) { return 'none'; }
38
+ }
39
+
40
+ module.exports = {watchFiles};