@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
@@ -0,0 +1,365 @@
1
+ 'use strict';
2
+ // The native shim for this platform (agreed with A and the Reviewer): the
3
+ // one @countinghouse/ch-shim-<os>-<arch> a release's shim.packages names for
4
+ // ${platform}-${arch}, fetched by its pin from the registry
5
+ // (lib/npm-fetch.js), checked by its provenance (lib/provenance.js
6
+ // verifyRelease: shim.yml, shim-v<version>), its one file bin/<exe> read by
7
+ // the strict tar reader (a regular file: the reader refuses links and
8
+ // devices), and put at <home>/shim/ch-shim (ch-shim.exe on Windows), 0755.
9
+ // - <home>/shim is checked, not only set: on POSIX it is opened without
10
+ // following a link and must be a directory this user owns, then
11
+ // fchmod 0700; on Windows it must not be a link or junction, and it is
12
+ // given an owner-only DACL, read back and checked (lib/win-acl.js).
13
+ // - No shim for the platform: 'unsupported'; none pinned in this release:
14
+ // 'unpinned'. Nothing is fetched, and the platform runs the per-session
15
+ // mode, as today.
16
+ // - The binary goes in by renames: the new one written beside it, the one
17
+ // there moved to ch-shim.previous (no .exe: it is never launched), then the
18
+ // new one renamed into place. The same binary again moves nothing.
19
+ // - Which version each binary is goes by its content: versions.json maps
20
+ // each binary's sha512 to its version, written before a binary is placed,
21
+ // read and written as this user's own file (lib/own-file.js: no link,
22
+ // owned by this user, nothing for group or others; one that isn't counts
23
+ // as knowing no version, so nothing is put in place by it). alignShim and
24
+ // setAside check <home>/shim as installShim does before moving anything.
25
+ // So alignShim (rollback) puts the restored release's shim in place by
26
+ // what is on disk, and running it twice (a resumed rollback) moves nothing
27
+ // the second time.
28
+ // - setAside: a shim that is not this release's (install from --from, or
29
+ // from npm with none for the platform, or one that could not be installed)
30
+ // is moved to ch-shim.previous, so a stale shim is never the one used.
31
+ // - Anything refused places nothing.
32
+ // Only a test's own code passes a fake registry and trust, as the rest of
33
+ // the arguments, which go on untouched.
34
+ const crypto = require('node:crypto');
35
+ const fs = require('node:fs');
36
+ const path = require('node:path');
37
+ const npmFetch = require('./npm-fetch');
38
+ const provenance = require('./provenance');
39
+ const {readMember} = require('./tar');
40
+ const {writeOwnFile} = require('./own-file');
41
+
42
+ const failure = (code, message) => Object.assign(new Error(message), {code});
43
+ const exe = (platform) => (platform === 'win32' ? 'ch-shim.exe' : 'ch-shim');
44
+ const PREVIOUS = 'ch-shim.previous';
45
+ const VERSIONS = 'versions.json';
46
+ const paths = (home, platform) => {
47
+ const dir = path.join(home, 'shim');
48
+ return {dir, target: path.join(dir, exe(platform)), previous: path.join(dir, PREVIOUS), versions: path.join(dir, VERSIONS)};
49
+ };
50
+ const exists = (p) => { try { fs.lstatSync(p); return true; } catch (e) { return false; } };
51
+ const digest = (bytes) => crypto.createHash('sha512').update(bytes).digest('hex');
52
+
53
+ // <home>/shim, made if missing, and checked: a directory, not a link, this
54
+ // user's, private
55
+ function ownedDir(dir, platform) {
56
+ try {
57
+ fs.mkdirSync(dir, {mode: 0o700});
58
+ } catch (e) {
59
+ if (e.code !== 'EEXIST') throw e;
60
+ }
61
+ const st = fs.lstatSync(dir);
62
+ if (st.isSymbolicLink() || !st.isDirectory()) throw failure('SHIM_DIR', `${dir} is not a directory (a link is refused)`);
63
+ // Windows' checks whenever the caller's platform or this system is Windows
64
+ // (a test's platform can be another's; POSIX modes mean nothing on Windows)
65
+ if (platform === 'win32' || process.platform === 'win32') {
66
+ const winAcl = require('./win-acl');
67
+ const [acl] = winAcl.makePrivateDirs([dir], [dir]);
68
+ const why = winAcl.privateProblem(dir, acl, {directory: true});
69
+ if (why != null) throw failure('SHIM_DIR', why);
70
+ return;
71
+ }
72
+ const fd = fs.openSync(dir, fs.constants.O_RDONLY | fs.constants.O_DIRECTORY | fs.constants.O_NOFOLLOW);
73
+ try {
74
+ const at = fs.fstatSync(fd);
75
+ if (!at.isDirectory()) throw failure('SHIM_DIR', `${dir} is not a directory`);
76
+ if (typeof process.getuid === 'function' && at.uid !== process.getuid()) throw failure('SHIM_DIR', `${dir} belongs to another user (uid ${at.uid})`);
77
+ fs.fchmodSync(fd, 0o700);
78
+ } finally {
79
+ fs.closeSync(fd);
80
+ }
81
+ }
82
+
83
+ // versions.json: {sha512 hex: version}; anything unreadable, or not this
84
+ // user's own, is empty
85
+ // (one reader with lib/session.js: lib/plain-read.js)
86
+ const readVersions = (file, platform = process.platform) => require('./plain-read').readVersions(file, platform);
87
+ function writeVersions(file, map) {
88
+ writeOwnFile(file, JSON.stringify(map, null, 2) + '\n');
89
+ }
90
+ // every read of ch-shim and ch-shim.previous: never through a link, never
91
+ // blocking on a FIFO (lib/plain-read.js; the reviewer's high on #120, 2, 3)
92
+ const plain = (file) => require('./plain-read').readPlain(file).bytes;
93
+ // the version of the binary at file, by its content -> version, or null
94
+ // (a link, a FIFO or anything but a plain file: none)
95
+ function versionAt(file, versions) {
96
+ const bytes = plain(file);
97
+ if (bytes == null) return null;
98
+ const v = versions[digest(bytes)];
99
+ return typeof v === 'string' ? v : null;
100
+ }
101
+ // versions.json keeps only the binaries there
102
+ function prune(p, platform) {
103
+ const map = readVersions(p.versions, platform);
104
+ const keep = new Set([p.target, p.previous].map((f) => { const b = plain(f); return b != null ? digest(b) : null; }).filter((d) => d != null));
105
+ writeVersions(p.versions, Object.fromEntries(Object.entries(map).filter(([d]) => keep.has(d))));
106
+ }
107
+
108
+ // the shim there, moved to ch-shim.previous (the one before that goes). A
109
+ // ch-shim.previous that cannot be removed (on Windows, a session started
110
+ // before the last install still running it) leaves the shim moved aside
111
+ // under another name, so it is never the one used. -> whether one moved
112
+ function setAside(home, {platform = process.platform} = {}) {
113
+ const p = paths(home, platform);
114
+ if (!exists(p.target)) return false;
115
+ ownedDir(p.dir, platform);
116
+ try {
117
+ fs.rmSync(p.previous, {force: true});
118
+ fs.renameSync(p.target, p.previous);
119
+ } catch (e) {
120
+ fs.renameSync(p.target, path.join(p.dir, `.stale-${process.pid}-${Date.now()}`));
121
+ }
122
+ return true;
123
+ }
124
+
125
+ // what earlier set-asides left: removed when they can be (one still running
126
+ // on Windows can't, until its session exits)
127
+ function clearStale(dir) {
128
+ let names = [];
129
+ try { names = fs.readdirSync(dir); } catch (e) { return; }
130
+ // (a .swap-* is what an interrupted swap left: its binary is set aside)
131
+ for (const n of names.filter((x) => x.startsWith('.stale-') || x.startsWith('.swap-'))) { try { fs.rmSync(path.join(dir, n), {force: true}); } catch (e) { /* held */ } }
132
+ }
133
+
134
+ // The network half, before the home's lock (the medium on B-shim-allow: the
135
+ // shim is placed and recorded inside install's one locked record write).
136
+ // {data (parsed release pins), record (the home's record before this
137
+ // install), home, io, platform, arch, ...fromNpm} -> never throws:
138
+ // {status: 'unsupported'} | {status: 'unpinned', package}
139
+ // | {status: 'current', name, version}: the record names this package at
140
+ // this pin and the binary there is that version's (versions.json, by
141
+ // content) -- not fetched again; placeShim checks it again under the lock
142
+ // | {status: 'ready', name, version, binary}: fetched, provenance verified
143
+ // | {status: 'failed', name, version, error}
144
+ async function prepareShim({data, record = null, home, io, platform = process.platform, arch = process.arch, ...fromNpm}) {
145
+ const key = `${platform}-${arch}`;
146
+ const name = Object.prototype.hasOwnProperty.call(data.shim.packages, key) ? data.shim.packages[key] : null;
147
+ if (name == null) return {status: 'unsupported'};
148
+ const pin = data.pins[name];
149
+ if (pin == null) return {status: 'unpinned', package: name};
150
+ // (never for an unreleased home: its shim may be a dev build, so the
151
+ // release's own is fetched and verified -- the reviewer's high, F1)
152
+ if (home != null && record != null && record.unreleased !== true && record.shim != null && record.shim.package === name && record.shim.version === pin.version) {
153
+ const p = paths(home, platform);
154
+ if (versionAt(p.target, readVersions(p.versions, platform)) === pin.version) return {status: 'current', name, version: pin.version};
155
+ }
156
+ try {
157
+ const {bytes} = await npmFetch.fetchTarball(name, pin.version, io, Object.assign({pin}, fromNpm));
158
+ const attestations = await npmFetch.attestations(name, pin.version, io, fromNpm);
159
+ provenance.verifyRelease(Object.assign({name, version: pin.version, pin, attestations}, fromNpm));
160
+ let binary;
161
+ try {
162
+ binary = readMember(bytes, `bin/${exe(platform)}`);
163
+ } catch (e) {
164
+ throw failure('SHIM_TARBALL', `${name}@${pin.version}'s tarball was refused (${e.message})`);
165
+ }
166
+ if (binary == null) throw failure('SHIM_NO_BINARY', `${name}@${pin.version} holds no bin/${exe(platform)}`);
167
+ return {status: 'ready', name, version: pin.version, binary};
168
+ } catch (error) {
169
+ // (always an Error with a code: the install reads both -- the medium's
170
+ // round 3, 2)
171
+ const err = error instanceof Error && error.code != null ? error
172
+ : failure(error != null && error.code != null ? error.code : 'SHIM_FETCH', `the shim could not be fetched (${error instanceof Error ? error.message : String(error)})`);
173
+ return {status: 'failed', name, version: pin.version, error: err};
174
+ }
175
+ }
176
+
177
+ // The same half for a prepared folder (install --from: A-shim-from, the
178
+ // reviewer, 11-21). The folder's shim tarball is trusted by the sha512 its
179
+ // pins name, exactly as its packs are (lib/install.js loadTarballs): no
180
+ // registry, no provenance, no other bytes read -- and always read and
181
+ // checked: never 'current' by a version string, which a rebuilt folder keeps
182
+ // (the medium on A-shim-from, 1-3; placeShim moves nothing for the same
183
+ // bytes). {data (the effective allowlist's {shim, pins}), from, platform,
184
+ // arch} -> never throws:
185
+ // {status: 'unsupported'} | {status: 'unpinned', package}: as prepareShim
186
+ // says them (no package for this machine, or none pinned): install says
187
+ // so and sets the one there aside, whatever other platforms' shims the
188
+ // folder holds (the reviewer's high, F4)
189
+ // | {status: 'ready', name, version, binary}: placed by placeShim under
190
+ // the lock
191
+ // | {status: 'refused', error}: install refuses, as for a pack -- this
192
+ // machine's shim pinned but not in the folder (F4, F5), a version the
193
+ // record can't hold (F3), bytes other than the pin's, no binary, or a
194
+ // binary this machine doesn't run
195
+ // unreleased: the pins are --unreleased-pins': a shim at a release's version
196
+ // is refused, so dev bytes never sit under a version a release names (the
197
+ // reviewer's high, F1)
198
+ function prepareShimFrom({data, from, unreleased = false, platform = process.platform, arch = process.arch}) {
199
+ const {tarballName} = require('./unpack');
200
+ const key = `${platform}-${arch}`;
201
+ const packages = data.shim != null && data.shim.packages != null ? data.shim.packages : {};
202
+ const name = Object.prototype.hasOwnProperty.call(packages, key) ? packages[key] : null;
203
+ if (name == null) return {status: 'unsupported'};
204
+ const pin = data.pins[name];
205
+ // (development pins with no shim, as dogfood's own install and acceptance
206
+ // build them: the one there set aside, said as before, never as "this
207
+ // release" -- the medium on the round, 7)
208
+ if (pin == null) return unreleased ? null : {status: 'unpinned', package: name};
209
+ const refused = (code, message) => ({status: 'refused', error: failure(code, message)});
210
+ const file = tarballName(name, pin.version);
211
+ // (the record holds the version, and refuses one it can't after the app
212
+ // is swapped: refused now, before anything is written -- F3)
213
+ if (!require('./names').VERSION.test(pin.version)) return refused('SHIM_VERSION', `${name}@${pin.version}: not a version a home's record can hold`);
214
+ // (dogfood's own form only: any pre-release could be a release's, 0.5.0-rc.1
215
+ // -- the medium on the round, 1)
216
+ if (unreleased && !/^\d+\.\d+\.\d+-dev\.[0-9a-f]{12}$/.test(pin.version)) return refused('SHIM_VERSION', `${name}@${pin.version}: an unreleased install's shim carries dogfood's version (<x.y.z>-dev.<12 hex>), never one a release could use`);
217
+ let files;
218
+ // (a folder that can't be listed is said as such, never as a missing
219
+ // tarball: the medium on the round, 6)
220
+ try { files = fs.readdirSync(from); } catch (e) { return refused('SHIM_TARBALL', `cannot read ${from} (${e.code || e.message})`); }
221
+ // (pinned, so the folder must hold it, as a pack's tarball: F4, F5)
222
+ if (!files.includes(file)) return refused('SHIM_MISSING', `${name}@${pin.version}: no ${file} in ${from}`);
223
+ const at = `${name}@${pin.version}`;
224
+ let bytes;
225
+ try { bytes = fs.readFileSync(require('node:path').join(from, tarballName(name, pin.version))); } catch (e) {
226
+ return refused('SHIM_TARBALL', `${at}: cannot read ${tarballName(name, pin.version)} (${e.code || e.message})`);
227
+ }
228
+ if (require('./integrity').integrityOf(bytes) !== pin.integrity) return refused('SHIM_INTEGRITY', `${at}: the tarball's integrity is not the pinned one`);
229
+ let binary;
230
+ try { binary = readMember(bytes, `bin/${exe(platform)}`); } catch (e) {
231
+ return refused('SHIM_TARBALL', `${at}'s tarball was refused (${e.message})`);
232
+ }
233
+ if (binary == null) return refused('SHIM_NO_BINARY', `${at} holds no bin/${exe(platform)}`);
234
+ // (what session would refuse to exec is refused here, before anything is
235
+ // placed: lib/session.js formatProblem)
236
+ const why = require('./session').formatProblem(binary.subarray(0, 4096), platform, arch);
237
+ if (why != null) return refused('SHIM_PLATFORM', `${at}'s bin/${exe(platform)} is not a program this machine runs (${key}: ${why})`);
238
+ return {status: 'ready', name, version: pin.version, binary};
239
+ }
240
+
241
+ // The local half, under the home's lock: a prepared shim put in place.
242
+ // ready: prepareShim's 'ready' or 'current' -> {status: 'installed', path,
243
+ // version}. Throws SHIM_DIR (the folder is not this user's private one),
244
+ // SHIM_STALE (a 'current' one no longer the version's), SHIM_BUSY (the one
245
+ // before can't be moved: a session still runs it, on Windows), or an fs error.
246
+ // fsync a directory (its entries' renames on disk). Windows can't open one
247
+ // to sync it (EPERM): judged by the host, never the platform a caller
248
+ // passes for its logic (shim-install.test on a Windows runner, #120's CI)
249
+ function syncDir(dir) {
250
+ if (process.platform === 'win32') return;
251
+ const fd = fs.openSync(dir, fs.constants.O_RDONLY);
252
+ try { fs.fsyncSync(fd); } finally { fs.closeSync(fd); }
253
+ }
254
+ function placeShim(home, ready, {platform = process.platform} = {}) {
255
+ const p = paths(home, platform);
256
+ ownedDir(p.dir, platform);
257
+ if (ready.status === 'current') {
258
+ // (checked again under the lock, the folder now known this user's own:
259
+ // a regular file, never a link, still that version's binary)
260
+ // (opened without following a link, judged and hashed on that one
261
+ // descriptor: nothing swapped in between -- the medium's round 3, 6)
262
+ // (by lstat and an O_NOFOLLOW descriptor: a link, a FIFO, anything but
263
+ // a plain file is not it -- Windows has no O_NOFOLLOW, lstat refuses there)
264
+ const versions = readVersions(p.versions, platform);
265
+ if (Object.keys(versions).length === 0) throw failure('SHIM_UNREADABLE', `${p.versions} could not be read as this user's own, so the shim in place can't be checked`);
266
+ // (one there that can't be read is said as such, with its errno: not
267
+ // "changed", which a rerun would never put right -- the medium on #120's
268
+ // high round)
269
+ const there = require('./plain-read').readPlain(p.target);
270
+ if (there.code != null) throw failure('SHIM_UNREADABLE', `${p.target} could not be read (${there.code})`);
271
+ const at = there.bytes != null ? versions[digest(there.bytes)] : undefined;
272
+ if (at !== ready.version) throw failure('SHIM_STALE', `${p.target} is no longer the verified shim ${ready.version}`);
273
+ return {status: 'installed', path: p.target, version: ready.version};
274
+ }
275
+ clearStale(p.dir);
276
+ const binary = ready.binary;
277
+ const hex = digest(binary);
278
+ // known before it is placed, so what is on disk can always be told apart
279
+ writeVersions(p.versions, Object.assign(readVersions(p.versions, platform), {[hex]: ready.version}));
280
+ // (never through a link, never a FIFO: plain)
281
+ const there = plain(p.target);
282
+ const same = there != null && digest(there) === hex;
283
+ if (!same) {
284
+ const temp = path.join(p.dir, `.${exe(platform)}.${process.pid}.tmp`);
285
+ try {
286
+ const fd = fs.openSync(temp, 'wx', 0o700);
287
+ try {
288
+ // (every byte written, and on disk before the rename: the
289
+ // reviewer's high on #120, 5)
290
+ for (let off = 0; off < binary.length;) off += fs.writeSync(fd, binary, off, binary.length - off);
291
+ fs.fchmodSync(fd, 0o755);
292
+ fs.fsyncSync(fd);
293
+ } finally {
294
+ fs.closeSync(fd);
295
+ }
296
+ const had = exists(p.target);
297
+ if (had) {
298
+ try {
299
+ fs.rmSync(p.previous, {force: true});
300
+ } catch (e) {
301
+ throw failure('SHIM_BUSY', `${p.previous} could not be removed (${e.code || e.message}); on Windows a session started before the last install may still be running it, and the new shim installs once that session exits`);
302
+ }
303
+ fs.renameSync(p.target, p.previous);
304
+ }
305
+ try {
306
+ fs.renameSync(temp, p.target);
307
+ } catch (e) {
308
+ // the one there goes back
309
+ if (had && exists(p.previous) && !exists(p.target)) fs.renameSync(p.previous, p.target);
310
+ throw e;
311
+ }
312
+ // (the renames on disk before install writes the record naming this
313
+ // shim: the directory too, where it can be opened -- not on Windows)
314
+ syncDir(p.dir);
315
+ } finally {
316
+ fs.rmSync(temp, {force: true});
317
+ }
318
+ }
319
+ prune(p, platform);
320
+ return {status: 'installed', path: p.target, version: ready.version};
321
+ }
322
+
323
+ // {home, data (parsed release pins), io, platform, arch, ...fromNpm} ->
324
+ // {status: 'installed', path, version} | {status: 'unsupported' | 'unpinned'};
325
+ // throws as before: the two halves at once (no record: always fetched)
326
+ async function installShim({home, data, io, platform = process.platform, arch = process.arch, ...fromNpm}) {
327
+ const ready = await prepareShim(Object.assign({data, home, io, platform, arch}, fromNpm));
328
+ if (ready.status === 'unsupported' || ready.status === 'unpinned') return ready.status === 'unpinned' ? {status: 'unpinned', package: ready.package} : {status: 'unsupported'};
329
+ if (ready.status === 'failed') throw ready.error;
330
+ return placeShim(home, ready, {platform});
331
+ }
332
+
333
+ // rollback: the restored release's shim ({version}, or null for none) put in
334
+ // place by what is on disk. Already in place: nothing moves (so a resumed
335
+ // rollback, or the same release reinstalled, never swaps back). At
336
+ // ch-shim.previous: the two swap. Not there, or none wanted: the shim there
337
+ // is set aside, so the restored release runs per session rather than with
338
+ // another release's shim. -> what it did
339
+ function alignShim(home, {restored, platform = process.platform}) {
340
+ const p = paths(home, platform);
341
+ const want = restored != null && typeof restored.version === 'string' ? restored.version : null;
342
+ if (!exists(p.dir)) return 'nothing';
343
+ ownedDir(p.dir, platform);
344
+ clearStale(p.dir);
345
+ const versions = readVersions(p.versions, platform);
346
+ const current = exists(p.target) ? versionAt(p.target, versions) : null;
347
+ if (want == null) return setAside(home, {platform}) ? 'set aside' : 'nothing';
348
+ if (current === want) return 'nothing';
349
+ if (exists(p.previous) && versionAt(p.previous, versions) === want) {
350
+ if (!exists(p.target)) { fs.renameSync(p.previous, p.target); return 'restored'; }
351
+ const aside = path.join(p.dir, `.swap-${process.pid}-${Date.now()}`);
352
+ fs.renameSync(p.target, aside);
353
+ try {
354
+ fs.renameSync(p.previous, p.target);
355
+ } catch (e) {
356
+ fs.renameSync(aside, p.target);
357
+ throw e;
358
+ }
359
+ fs.renameSync(aside, p.previous);
360
+ return 'swapped';
361
+ }
362
+ return setAside(home, {platform}) ? 'set aside' : 'nothing';
363
+ }
364
+
365
+ module.exports = {installShim, prepareShim, prepareShimFrom, placeShim, alignShim, setAside, PREVIOUS};
@@ -0,0 +1,44 @@
1
+ # The trust ch-local ships for upgrades from npm
2
+
3
+ `lib/provenance.js` verifies a version's attestations against these two
4
+ files and nothing else (docs/development/auto-upgrade.md, "The trusted root,
5
+ and its rotation"). No variable, argument or file replaces them. Only a
6
+ test's own code passes another root, as a function argument.
7
+
8
+ ## `trusted-root.json`: Sigstore's public-good trusted root
9
+
10
+ It holds the Fulcio CAs, the Rekor and CT log keys, and a timestamp
11
+ authority, each with its validity window.
12
+
13
+ **This copy is a bootstrap.** It is `targets/trusted_root.json` from
14
+ `sigstore/root-signing`'s `main` branch:
15
+ - git blob `effb0a19e6a0b3f69b3f0a2c72b5c2a02a0ddeea`, equal to upstream's;
16
+ - its sha256 matches the one Sigstore's `targets.json` (version 14) publishes
17
+ for it.
18
+
19
+ **What the release step's refresh must do**, before a release ships a new
20
+ copy:
21
+ 1. Use a maintained TUF client, starting from a `root.json` checked into this
22
+ repository.
23
+ 2. Walk the root chain version by version. Each new root must be signed at
24
+ threshold under both the old keys and the new ones.
25
+ 3. Accept no role version below the last one recorded. Record each role's
26
+ version here at every refresh.
27
+ 4. Require every role (root, timestamp, snapshot, targets) to be unexpired.
28
+ 5. Check the target's length and hash against `targets.json`.
29
+ 6. Show the diff in the release's pull request, reviewed: no key dropped, and
30
+ no validity window shortened.
31
+
32
+ ## `npm-keys.json`: npm's registry signing keys
33
+
34
+ It's the form `https://registry.npmjs.org/-/npm/v1/keys` serves. Each key is
35
+ valid until its `expires`, so older attestations still verify under the key
36
+ they were made with.
37
+
38
+ **At each release**, take the keys from Sigstore's TUF repository's
39
+ `registry.npmjs.org/keys.json` target, not the registry's own endpoint. That
40
+ target carries real validity windows and the `npm:attestations` usage, and
41
+ TUF verifies it as above.
42
+
43
+ **Residual:** today's current key has `expires: null`, an open window. A key
44
+ npm retires stays valid here until a release ships the window that ends it.
@@ -0,0 +1,18 @@
1
+ {
2
+ "keys": [
3
+ {
4
+ "expires": "2025-01-29T00:00:00.000Z",
5
+ "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
6
+ "keytype": "ecdsa-sha2-nistp256",
7
+ "scheme": "ecdsa-sha2-nistp256",
8
+ "key": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE1Olb3zMAFFxXKHiIkQO5cJ3Yhl5i6UPp+IhuteBJbuHcA5UogKo0EWtlWwW6KSaKoTNEYL7JlCQiVnkhBktUgg=="
9
+ },
10
+ {
11
+ "expires": null,
12
+ "keyid": "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U",
13
+ "keytype": "ecdsa-sha2-nistp256",
14
+ "scheme": "ecdsa-sha2-nistp256",
15
+ "key": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEY6Ya7W++7aUPzvMTrezH6Ycx3c+HOKYCcNGybJZSCJq/fd7Qa8uuAKtdIkUQtQiEKERhAmE5lMMJhP8OkDOa2g=="
16
+ }
17
+ ]
18
+ }
@@ -0,0 +1,126 @@
1
+ {
2
+ "mediaType": "application/vnd.dev.sigstore.trustedroot+json;version=0.1",
3
+ "tlogs": [
4
+ {
5
+ "baseUrl": "https://rekor.sigstore.dev",
6
+ "hashAlgorithm": "SHA2_256",
7
+ "publicKey": {
8
+ "rawBytes": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE2G2Y+2tabdTV5BcGiBIx0a9fAFwrkBbmLSGtks4L3qX6yYY0zufBnhC8Ur/iy55GhWP/9A/bY2LhC30M9+RYtw==",
9
+ "keyDetails": "PKIX_ECDSA_P256_SHA_256",
10
+ "validFor": {
11
+ "start": "2021-01-12T11:53:27Z"
12
+ }
13
+ },
14
+ "logId": {
15
+ "keyId": "wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="
16
+ }
17
+ },
18
+ {
19
+ "baseUrl": "https://log2025-1.rekor.sigstore.dev",
20
+ "hashAlgorithm": "SHA2_256",
21
+ "publicKey": {
22
+ "rawBytes": "MCowBQYDK2VwAyEAt8rlp1knGwjfbcXAYPYAkn0XiLz1x8O4t0YkEhie244=",
23
+ "keyDetails": "PKIX_ED25519",
24
+ "validFor": {
25
+ "start": "2025-09-23T00:00:00Z"
26
+ }
27
+ },
28
+ "logId": {
29
+ "keyId": "zxGZFVvd0FEmjR8WrFwMdcAJ9vtaY/QXf44Y1wUeP6A="
30
+ }
31
+ }
32
+ ],
33
+ "certificateAuthorities": [
34
+ {
35
+ "subject": {
36
+ "organization": "sigstore.dev",
37
+ "commonName": "sigstore"
38
+ },
39
+ "uri": "https://fulcio.sigstore.dev",
40
+ "certChain": {
41
+ "certificates": [
42
+ {
43
+ "rawBytes": "MIIB+DCCAX6gAwIBAgITNVkDZoCiofPDsy7dfm6geLbuhzAKBggqhkjOPQQDAzAqMRUwEwYDVQQKEwxzaWdzdG9yZS5kZXYxETAPBgNVBAMTCHNpZ3N0b3JlMB4XDTIxMDMwNzAzMjAyOVoXDTMxMDIyMzAzMjAyOVowKjEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MREwDwYDVQQDEwhzaWdzdG9yZTB2MBAGByqGSM49AgEGBSuBBAAiA2IABLSyA7Ii5k+pNO8ZEWY0ylemWDowOkNa3kL+GZE5Z5GWehL9/A9bRNA3RbrsZ5i0JcastaRL7Sp5fp/jD5dxqc/UdTVnlvS16an+2Yfswe/QuLolRUCrcOE2+2iA5+tzd6NmMGQwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQEwHQYDVR0OBBYEFMjFHQBBmiQpMlEk6w2uSu1KBtPsMB8GA1UdIwQYMBaAFMjFHQBBmiQpMlEk6w2uSu1KBtPsMAoGCCqGSM49BAMDA2gAMGUCMH8liWJfMui6vXXBhjDgY4MwslmN/TJxVe/83WrFomwmNf056y1X48F9c4m3a3ozXAIxAKjRay5/aj/jsKKGIkmQatjI8uupHr/+CxFvaJWmpYqNkLDGRU+9orzh5hI2RrcuaQ=="
44
+ }
45
+ ]
46
+ },
47
+ "validFor": {
48
+ "start": "2021-03-07T03:20:29Z",
49
+ "end": "2022-12-31T23:59:59.999Z"
50
+ }
51
+ },
52
+ {
53
+ "subject": {
54
+ "organization": "sigstore.dev",
55
+ "commonName": "sigstore"
56
+ },
57
+ "uri": "https://fulcio.sigstore.dev",
58
+ "certChain": {
59
+ "certificates": [
60
+ {
61
+ "rawBytes": "MIICGjCCAaGgAwIBAgIUALnViVfnU0brJasmRkHrn/UnfaQwCgYIKoZIzj0EAwMwKjEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MREwDwYDVQQDEwhzaWdzdG9yZTAeFw0yMjA0MTMyMDA2MTVaFw0zMTEwMDUxMzU2NThaMDcxFTATBgNVBAoTDHNpZ3N0b3JlLmRldjEeMBwGA1UEAxMVc2lnc3RvcmUtaW50ZXJtZWRpYXRlMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE8RVS/ysH+NOvuDZyPIZtilgUF9NlarYpAd9HP1vBBH1U5CV77LSS7s0ZiH4nE7Hv7ptS6LvvR/STk798LVgMzLlJ4HeIfF3tHSaexLcYpSASr1kS0N/RgBJz/9jWCiXno3sweTAOBgNVHQ8BAf8EBAMCAQYwEwYDVR0lBAwwCgYIKwYBBQUHAwMwEgYDVR0TAQH/BAgwBgEB/wIBADAdBgNVHQ4EFgQU39Ppz1YkEZb5qNjpKFWixi4YZD8wHwYDVR0jBBgwFoAUWMAeX5FFpWapesyQoZMi0CrFxfowCgYIKoZIzj0EAwMDZwAwZAIwPCsQK4DYiZYDPIaDi5HFKnfxXx6ASSVmERfsynYBiX2X6SJRnZU84/9DZdnFvvxmAjBOt6QpBlc4J/0DxvkTCqpclvziL6BCCPnjdlIB3Pu3BxsPmygUY7Ii2zbdCdliiow="
62
+ },
63
+ {
64
+ "rawBytes": "MIIB9zCCAXygAwIBAgIUALZNAPFdxHPwjeDloDwyYChAO/4wCgYIKoZIzj0EAwMwKjEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MREwDwYDVQQDEwhzaWdzdG9yZTAeFw0yMTEwMDcxMzU2NTlaFw0zMTEwMDUxMzU2NThaMCoxFTATBgNVBAoTDHNpZ3N0b3JlLmRldjERMA8GA1UEAxMIc2lnc3RvcmUwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAAT7XeFT4rb3PQGwS4IajtLk3/OlnpgangaBclYpsYBr5i+4ynB07ceb3LP0OIOZdxexX69c5iVuyJRQ+Hz05yi+UF3uBWAlHpiS5sh0+H2GHE7SXrk1EC5m1Tr19L9gg92jYzBhMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBRYwB5fkUWlZql6zJChkyLQKsXF+jAfBgNVHSMEGDAWgBRYwB5fkUWlZql6zJChkyLQKsXF+jAKBggqhkjOPQQDAwNpADBmAjEAj1nHeXZp+13NWBNa+EDsDP8G1WWg1tCMWP/WHPqpaVo0jhsweNFZgSs0eE7wYI4qAjEA2WB9ot98sIkoF3vZYdd3/VtWB5b9TNMea7Ix/stJ5TfcLLeABLE4BNJOsQ4vnBHJ"
65
+ }
66
+ ]
67
+ },
68
+ "validFor": {
69
+ "start": "2022-04-13T20:06:15Z"
70
+ }
71
+ }
72
+ ],
73
+ "ctlogs": [
74
+ {
75
+ "baseUrl": "https://ctfe.sigstore.dev/test",
76
+ "hashAlgorithm": "SHA2_256",
77
+ "publicKey": {
78
+ "rawBytes": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEbfwR+RJudXscgRBRpKX1XFDy3PyudDxz/SfnRi1fT8ekpfBd2O1uoz7jr3Z8nKzxA69EUQ+eFCFI3zeubPWU7w==",
79
+ "keyDetails": "PKIX_ECDSA_P256_SHA_256",
80
+ "validFor": {
81
+ "start": "2021-03-14T00:00:00Z",
82
+ "end": "2022-10-31T23:59:59.999Z"
83
+ }
84
+ },
85
+ "logId": {
86
+ "keyId": "CGCS8ChS/2hF0dFrJ4ScRWcYrBY9wzjSbea8IgY2b3I="
87
+ }
88
+ },
89
+ {
90
+ "baseUrl": "https://ctfe.sigstore.dev/2022",
91
+ "hashAlgorithm": "SHA2_256",
92
+ "publicKey": {
93
+ "rawBytes": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEiPSlFi0CmFTfEjCUqF9HuCEcYXNKAaYalIJmBZ8yyezPjTqhxrKBpMnaocVtLJBI1eM3uXnQzQGAJdJ4gs9Fyw==",
94
+ "keyDetails": "PKIX_ECDSA_P256_SHA_256",
95
+ "validFor": {
96
+ "start": "2022-10-20T00:00:00Z"
97
+ }
98
+ },
99
+ "logId": {
100
+ "keyId": "3T0wasbHETJjGR4cmWc3AqJKXrjePK3/h4pygC8p7o4="
101
+ }
102
+ }
103
+ ],
104
+ "timestampAuthorities": [
105
+ {
106
+ "subject": {
107
+ "organization": "sigstore.dev",
108
+ "commonName": "sigstore-tsa-selfsigned"
109
+ },
110
+ "uri": "https://timestamp.sigstore.dev/api/v1/timestamp",
111
+ "certChain": {
112
+ "certificates": [
113
+ {
114
+ "rawBytes": "MIICEDCCAZagAwIBAgIUOhNULwyQYe68wUMvy4qOiyojiwwwCgYIKoZIzj0EAwMwOTEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MSAwHgYDVQQDExdzaWdzdG9yZS10c2Etc2VsZnNpZ25lZDAeFw0yNTA0MDgwNjU5NDNaFw0zNTA0MDYwNjU5NDNaMC4xFTATBgNVBAoTDHNpZ3N0b3JlLmRldjEVMBMGA1UEAxMMc2lnc3RvcmUtdHNhMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE4ra2Z8hKNig2T9kFjCAToGG30jky+WQv3BzL+mKvh1SKNR/UwuwsfNCg4sryoYAd8E6isovVA3M4aoNdm9QDi50Z8nTEyvqgfDPtTIwXItfiW/AFf1V7uwkbkAoj0xxco2owaDAOBgNVHQ8BAf8EBAMCB4AwHQYDVR0OBBYEFIn9eUOHz9BlRsMCRscsc1t9tOsDMB8GA1UdIwQYMBaAFJjsAe9/u1H/1JUeb4qImFMHic6/MBYGA1UdJQEB/wQMMAoGCCsGAQUFBwMIMAoGCCqGSM49BAMDA2gAMGUCMDtpsV/6KaO0qyF/UMsX2aSUXKQFdoGTptQGc0ftq1csulHPGG6dsmyMNd3JB+G3EQIxAOajvBcjpJmKb4Nv+2Taoj8Uc5+b6ih6FXCCKraSqupe07zqswMcXJTe1cExvHvvlw=="
115
+ },
116
+ {
117
+ "rawBytes": "MIIB9zCCAXygAwIBAgIUV7f0GLDOoEzIh8LXSW80OJiUp14wCgYIKoZIzj0EAwMwOTEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MSAwHgYDVQQDExdzaWdzdG9yZS10c2Etc2VsZnNpZ25lZDAeFw0yNTA0MDgwNjU5NDNaFw0zNTA0MDYwNjU5NDNaMDkxFTATBgNVBAoTDHNpZ3N0b3JlLmRldjEgMB4GA1UEAxMXc2lnc3RvcmUtdHNhLXNlbGZzaWduZWQwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAAQUQNtfRT/ou3YATa6wB/kKTe70cfJwyRIBovMnt8RcJph/COE82uyS6FmppLLL1VBPGcPfpQPYJNXzWwi8icwhKQ6W/Qe2h3oebBb2FHpwNJDqo+TMaC/tdfkv/ElJB72jRTBDMA4GA1UdDwEB/wQEAwIBBjASBgNVHRMBAf8ECDAGAQH/AgEAMB0GA1UdDgQWBBSY7AHvf7tR/9SVHm+KiJhTB4nOvzAKBggqhkjOPQQDAwNpADBmAjEAwGEGrfGZR1cen1R8/DTVMI943LssZmJRtDp/i7SfGHmGRP6gRbuj9vOK3b67Z0QQAjEAuT2H673LQEaHTcyQSZrkp4mX7WwkmF+sVbkYY5mXN+RMH13KUEHHOqASaemYWK/E"
118
+ }
119
+ ]
120
+ },
121
+ "validFor": {
122
+ "start": "2025-07-04T00:00:00Z"
123
+ }
124
+ }
125
+ ]
126
+ }
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+ // Each client's config entry for the installed launcher (spec §3). Pure: the
3
+ // node and launcher paths come in, the text goes out. No entry sets a
4
+ // credential, and none forwards one: a credential is a module's own, in the
5
+ // store, never a client's environment (#413 section 6.9; L5a).
6
+ // One entry serves every installed pack (reviewer, 2026-11-12).
7
+ const SERVER = 'countinghouse';
8
+ // start loads every installed pack, so an entry names none.
9
+ const CLIENTS = ['claude-code', 'cursor', 'vscode', 'codex', 'claude-desktop'];
10
+
11
+ // The entry runs the home's launcher's `session`, which decides at each
12
+ // session start between the shared runtime (the native shim, countinghouse
13
+ // #236) and this session's own (lib/session.js): one decision, in the home's
14
+ // code, so an entry never names a shim that was set aside (#120).
15
+ const commandOf = ({node, launcher, home}) => ({command: node, args: [launcher, 'session', '--home', home]});
16
+ const json = (obj) => JSON.stringify(obj, null, 2) + '\n';
17
+ // A TOML basic string: JSON's escapes are TOML's.
18
+ const toml = (s) => JSON.stringify(s);
19
+ // A shell word: bare when it is plainly safe; else double-quoted, which bash,
20
+ // zsh, cmd.exe and PowerShell all read (the line has no $ of its own); a word
21
+ // holding " $ ` or ! is single-quoted, the POSIX way.
22
+ const word = (s) => {
23
+ if (/^[A-Za-z0-9_./:=%+-]+$/.test(s)) return s;
24
+ if (!/["$`!]/.test(s)) return `"${s}"`;
25
+ return `'${s.replace(/'/g, `'\\''`)}'`;
26
+ };
27
+
28
+ const RENDER = {
29
+ // https://code.claude.com/docs/en/mcp: `claude mcp add [options] <name> -- <command> [args...]`.
30
+ 'claude-code': (w) => {
31
+ const {command, args} = commandOf(w);
32
+ return ['claude mcp add --scope user', SERVER, '--', ...[command, ...args].map(word)].join(' ') + '\n';
33
+ },
34
+ // https://cursor.com/docs/context/mcp. No `type` (Cursor's docs show entries without it).
35
+ cursor: (w) => json({mcpServers: {[SERVER]: commandOf(w)}}),
36
+ // ~/.copilot/mcp-config.json, the portable format.
37
+ vscode: (w) => json({mcpServers: {[SERVER]: {type: 'stdio', ...commandOf(w)}}}),
38
+ // https://learn.chatgpt.com/docs/extend/mcp?surface=cli (no env_vars: no
39
+ // variable of Codex's own environment is forwarded). Codex's own waits:
40
+ // startup_timeout_sec (its default 10) covers a cold first start on a busy
41
+ // machine, whose first tools/list answers once the packs are loaded;
42
+ // tool_timeout_sec (its default 60) is above countinghouse's longest
43
+ // requestTimeout, 120 s, so the runtime's own limit ends a call first
44
+ // (Codex's clock starts before the call reaches the runtime).
45
+ codex: (w) => [
46
+ `[mcp_servers.${SERVER}]`,
47
+ `command = ${toml(commandOf(w).command)}`,
48
+ `args = [${commandOf(w).args.map(toml).join(', ')}]`,
49
+ 'startup_timeout_sec = 90',
50
+ 'tool_timeout_sec = 130'
51
+ ].join('\n') + '\n',
52
+ 'claude-desktop': () => ''
53
+ };
54
+
55
+ // What a client gets instead of an entry, on stderr.
56
+ const NOTES = {
57
+ 'claude-desktop': [
58
+ 'Claude Desktop has no config entry to paste.',
59
+ 'Desktop does not see your shell\'s environment, and a GitHub token is never written to a config file,',
60
+ 'so the route for Desktop is the .mcpb bundle, which keeps the token in the OS keychain.',
61
+ 'The bundle is not built yet.'
62
+ ].join('\n') + '\n'
63
+ };
64
+
65
+ // {node, launcher, home} -> {text, note?}: text is the entry to paste
66
+ // (empty when there is none), note says why there is none. home: the
67
+ // absolute home the session is given. Throws on an unknown client.
68
+ function snippet(client, {node, launcher, home}) {
69
+ if (!Object.prototype.hasOwnProperty.call(RENDER, client)) {
70
+ throw new Error(`unknown client "${client}"; one of: ${CLIENTS.join(', ')}`);
71
+ }
72
+ const text = RENDER[client]({node, launcher, home});
73
+ return NOTES[client] != null ? {text, note: NOTES[client]} : {text};
74
+ }
75
+
76
+ module.exports = {snippet, CLIENTS, SERVER};