@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,98 @@
1
+ 'use strict';
2
+ // The runtime lockfile's rules (the review of #42), one set for a released
3
+ // lockfile and for --unreleased-pins, since npm ci acts on what it says:
4
+ // - npm's v3 form: packages, and no legacy dependencies tree;
5
+ // - every key node_modules/<name>(/node_modules/<name>)*, scoped names
6
+ // included, and no entry with a link key of any value (npm tests it for
7
+ // truthiness; the re-check of #42);
8
+ // - a runtime package (ch-local, countinghouse) from its own tarball in the
9
+ // release directory, file:tarballs/<name>, at its pinned version, with its
10
+ // pin's integrity: always, since npm ci installs whatever tarball is there
11
+ // when the entry has none (the re-check of #42);
12
+ // - every other entry from https://registry.npmjs.org/ with a sha512, so npm
13
+ // ci checks it: its resolved a plain URL on that origin, one that is
14
+ // already normalized (no .., nothing that resolves elsewhere), and nothing
15
+ // from git or another host;
16
+ // - an entry bundled inside a runtime package's tarball is exempt only when
17
+ // its parent really bundles it, since npm acts on the parent's
18
+ // bundleDependencies, not the entry's own inBundle flag. That means no
19
+ // resolved and no link; beneath a runtime package's own node_modules; that
20
+ // package's lockfile entry listing the first name beneath it in
21
+ // bundleDependencies; and, when the tarballs are given, the package's
22
+ // verified tarball holding node_modules/<path>/package.json.
23
+ const {tarballName} = require('./unpack');
24
+ const {readMember} = require('./tar');
25
+
26
+ const REGISTRY = 'https://registry.npmjs.org/';
27
+ const SHA512 = /^sha512-[A-Za-z0-9+/]{86}==$/;
28
+ // a package name, scoped or not: no leading . or _, no path separator
29
+ const NAME = '(?:@[A-Za-z0-9~-][A-Za-z0-9._~-]*/)?[A-Za-z0-9~-][A-Za-z0-9._~-]*';
30
+ const KEY = new RegExp(`^node_modules/${NAME}(?:/node_modules/${NAME})*$`);
31
+ const own = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
32
+
33
+ // a registry tarball URL: https on registry.npmjs.org, as given already the
34
+ // URL it parses to
35
+ function onRegistry(resolved) {
36
+ if (typeof resolved !== 'string') return false;
37
+ let u;
38
+ try { u = new URL(resolved); } catch (e) { return false; }
39
+ return u.origin === new URL(REGISTRY).origin && u.href === resolved && u.username === '' && u.password === '' && resolved.startsWith(REGISTRY);
40
+ }
41
+ const isObject = (x) => x != null && typeof x === 'object' && !Array.isArray(x);
42
+
43
+ // the runtime package an entry is bundled beneath, and its path below that
44
+ // package -> {parent, below: ['@sigstore/verify', ...], first} or null
45
+ function bundledBeneath(key, runtime) {
46
+ for (const parent of runtime) {
47
+ const prefix = `node_modules/${parent}/node_modules/`;
48
+ if (!key.startsWith(prefix)) continue;
49
+ const below = key.slice(prefix.length);
50
+ const first = below.startsWith('@') ? below.split('/').slice(0, 2).join('/') : below.split('/')[0];
51
+ return {parent, below, first};
52
+ }
53
+ return null;
54
+ }
55
+
56
+ // lockfile, {runtime: [names], pins: {name: {version, integrity}}, tarballs?:
57
+ // {name: Buffer}} -> null, or what is wrong
58
+ function lockfileProblem(lockfile, {runtime, pins, tarballs = null}) {
59
+ if (!isObject(lockfile) || lockfile.lockfileVersion !== 3 || !isObject(lockfile.packages) || lockfile.dependencies !== undefined) {
60
+ return 'the runtime lockfile must be an npm v3 lockfile (lockfileVersion 3, packages, and no dependencies tree)';
61
+ }
62
+ const entries = lockfile.packages;
63
+ for (const [key, entry] of Object.entries(entries)) {
64
+ if (key === '') continue;
65
+ if (!isObject(entry)) return `the runtime lockfile's ${key} is not an entry`;
66
+ if (!KEY.test(key)) return `the runtime lockfile's ${JSON.stringify(key)} is not a node_modules path`;
67
+ if (own(entry, 'link')) return `the runtime lockfile links ${key}; nothing may be linked`;
68
+ const name = key.slice(key.lastIndexOf('node_modules/') + 'node_modules/'.length);
69
+ if (key === `node_modules/${name}` && runtime.includes(name)) {
70
+ const pin = pins[name];
71
+ const want = pin == null ? null : `file:tarballs/${tarballName(name, pin.version)}`;
72
+ if (pin == null || entry.resolved !== want) return `the runtime lockfile resolves ${name} from ${JSON.stringify(entry.resolved)}, not its tarball ${want}`;
73
+ if (entry.version !== pin.version) return `the runtime lockfile has ${name} at version ${entry.version}, not its pinned ${pin.version}`;
74
+ if (entry.integrity !== pin.integrity) return `the runtime lockfile's integrity for ${name} is not its pin's`;
75
+ continue;
76
+ }
77
+ if (entry.inBundle === true) {
78
+ const at = bundledBeneath(key, runtime);
79
+ const parent = at != null ? entries[`node_modules/${at.parent}`] : null;
80
+ if (at == null || entry.resolved !== undefined || parent == null || !Array.isArray(parent.bundleDependencies) || !parent.bundleDependencies.includes(at.first)) {
81
+ return `the runtime lockfile's ${key} says it is bundled, but no runtime package's lockfile entry bundles it (npm would fetch it)`;
82
+ }
83
+ if (tarballs != null) {
84
+ const bytes = tarballs[at.parent];
85
+ let member = null;
86
+ try { member = bytes != null ? readMember(bytes, `node_modules/${at.below}/package.json`, {}, {bundled: true}) : null; } catch (e) { member = null; }
87
+ if (member == null) return `the runtime lockfile's ${key} is bundled by ${at.parent}, but not in the tarball`;
88
+ }
89
+ continue;
90
+ }
91
+ if (!onRegistry(entry.resolved) || typeof entry.integrity !== 'string' || !SHA512.test(entry.integrity)) {
92
+ return `the runtime lockfile's ${key} must come from ${REGISTRY} with a sha512 integrity`;
93
+ }
94
+ }
95
+ return null;
96
+ }
97
+
98
+ module.exports = {lockfileProblem};
package/lib/machine.js ADDED
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+ // This machine, for telling a run directory of this machine from another's on
3
+ // a home shared between machines (lib/gc.js): a hash of the system's machine
4
+ // id where it has one, the host name, and on Linux the boot id, so a cloned
5
+ // machine (the same machine-id) and a reboot (pids reused) each differ.
6
+ const crypto = require('node:crypto');
7
+ const fs = require('node:fs');
8
+ const os = require('node:os');
9
+
10
+ const read = (file) => { try { return fs.readFileSync(file, 'utf8').trim(); } catch (err) { return ''; } };
11
+ let cached = null;
12
+ function machineId() {
13
+ if (cached != null) return cached;
14
+ const id = read('/etc/machine-id') || read('/var/lib/dbus/machine-id');
15
+ const boot = process.platform === 'linux' ? read('/proc/sys/kernel/random/boot_id') : '';
16
+ cached = 'm:' + crypto.createHash('sha256').update([id, os.hostname(), boot].join('\n')).digest('hex').slice(0, 24);
17
+ return cached;
18
+ }
19
+
20
+ module.exports = {machineId};
@@ -0,0 +1,403 @@
1
+ 'use strict';
2
+ // Credentials per module (#413 sections 6.1, 6.4, 6.7 and 10; L5a): what each
3
+ // installed module declares, what the store binds to it, whether that is
4
+ // usable, and the slots a start gives its runtime.
5
+ //
6
+ // - A module's credential is (module, variable); its destination is the
7
+ // origin of the module's one declared remote (countinghouse.remotes: one
8
+ // remote per module in release 1). `credential` is a variable's name, or
9
+ // {env, header?, scheme?}; fallbackEnv is never read here (section 6.1).
10
+ // - A binding (lib/credential-store.js) is usable when it is for the
11
+ // declared variable and the declared origin, and, for the source gh, gh
12
+ // gave a token at this start (section 6.7).
13
+ // - A start gives every installed module with a usable binding a slot,
14
+ // COUNTINGHOUSE_CREDENTIAL_<n>, whether or not it loads now, so one turned
15
+ // on later loads in place with its key (section 6.4). It first removes
16
+ // every inherited COUNTINGHOUSE_CREDENTIAL_* from the runtime's
17
+ // environment (by any case), so a planted value is never read as a key.
18
+ // The environment it is given is an allowlist already (start), so no
19
+ // client credential reaches the runtime. A slot's
20
+ // identity, (module, variable, origin, source, sha256 of the value), is
21
+ // kept in the start's memory only, never written.
22
+ const fs = require('node:fs');
23
+ const path = require('node:path');
24
+ const crypto = require('node:crypto');
25
+ const store = require('./credential-store');
26
+ const {versionDir, looksPlaced} = require('./store-paths');
27
+ const {chLocal, restartEither, restartOne} = require('./command-line');
28
+
29
+ const SLOT_PREFIX = 'COUNTINGHOUSE_CREDENTIAL_';
30
+ const SLOT = /^COUNTINGHOUSE_CREDENTIAL_[1-9][0-9]{0,3}$/;
31
+ // the one origin a gh login is offered for (section 6.8)
32
+ const GH_ORIGIN = store.GH_ORIGIN;
33
+ // the names version 1 stored a GitHub token under (section 10)
34
+ const V1_GITHUB = ['COUNTINGHOUSE_GITHUB_TOKEN', 'GITHUB_TOKEN'];
35
+ const short = (name) => String(name).replace(/^@[^/]+\//, '');
36
+ const isObject = (x) => x != null && typeof x === 'object' && !Array.isArray(x);
37
+
38
+ // A module's declared credential, from its active version's manifest in the
39
+ // store: {variable, origin, remote} | null (it declares none) | {problem}.
40
+ // The user's own modules (B-own-add; the own-modules design §2.8):
41
+ // own.json's, by name; none when it can't be read (a start loads none then).
42
+ function ownModules(where) {
43
+ try {
44
+ const r = require('./own-record').readOwnRecord(where);
45
+ return r != null ? r.modules : Object.create(null);
46
+ } catch (err) { return Object.create(null); }
47
+ }
48
+ const hasOwn = (o, k) => o != null && Object.prototype.hasOwnProperty.call(o, k) && o[k] != null;
49
+ // An installed module -> {id, label} (a pack module's version; an own
50
+ // module's code: "own:<tree>", shown "(own, <hash12>)"), or null. A pack
51
+ // module's name is the pack module's (an own module of it never loads).
52
+ function installedAt(where, record, module) {
53
+ if (record != null && hasOwn(record.modules, module)) return {id: record.modules[module].version, label: record.modules[module].version};
54
+ const o = ownModules(where);
55
+ return hasOwn(o, module) ? {id: `own:${o[module].tree}`, label: `(own, ${o[module].tree.slice(0, 12)})`} : null;
56
+ }
57
+ function declared(where, record, module) {
58
+ const e = record.modules != null ? record.modules[module] : null;
59
+ let file;
60
+ let own = null;
61
+ if (e != null) {
62
+ file = path.join(versionDir(where, module, e.version), 'package.json');
63
+ } else {
64
+ // an own module's, from its copy (what loads)
65
+ const o = ownModules(where);
66
+ if (!hasOwn(o, module)) return null;
67
+ own = o[module];
68
+ file = path.join(require('./own-tree').copyDir(where, module, own.tree), 'package.json');
69
+ }
70
+ let manifest;
71
+ try {
72
+ manifest = JSON.parse(fs.readFileSync(file, 'utf8'));
73
+ } catch (err) {
74
+ return {problem: own != null ? `its copy is missing: run \`${chLocal(where, `add-module ${require('./command-line').folderArg(own.from)}`)}\` again`
75
+ : `its files are missing; run \`${chLocal(where, 'install')}\` again`};
76
+ }
77
+ // (the one reader, describe-module's credentialOf: the Reviewer's high
78
+ // review of #98, 2)
79
+ const c = require('./describe-module').credentialOf(isObject(manifest.countinghouse) ? manifest.countinghouse.remotes : []);
80
+ // (by its code, never its words: the medium on #98's high round, 7)
81
+ if (c.problem != null) return {problem: c.code === 'multiple' ? c.problem : 'its remote declaration cannot be read'};
82
+ return c.credential;
83
+ }
84
+
85
+ // Every installed module's declared credential: Map(module -> declared()),
86
+ // only those that declare one (or whose declaration has a problem).
87
+ function declarations(where, record) {
88
+ const out = new Map();
89
+ for (const m of Object.keys(record.modules || {})) {
90
+ if (!looksPlaced(where, m, record.modules[m].version)) continue;
91
+ const d = declared(where, record, m);
92
+ if (d != null) out.set(m, d);
93
+ }
94
+ // the own modules', each by its copy; one of a pack module's name is that
95
+ // module's, never declared in its place
96
+ const own = ownModules(where);
97
+ for (const m of Object.keys(own)) {
98
+ if (hasOwn(record.modules, m) || !fs.existsSync(require('./own-tree').copyDir(where, m, own[m].tree))) continue;
99
+ const d = declared(where, record, m);
100
+ if (d != null) out.set(m, d);
101
+ }
102
+ return out;
103
+ }
104
+
105
+ // The store's bindings as Map(module -> Map(variable -> entry)). A version 1
106
+ // file reads as section 10 says: each entry a binding for its recorded
107
+ // module, to https://api.githubcopilot.com (the only origin ch-local ever sent
108
+ // it to), under whichever of its two GitHub names the installed module
109
+ // declares (else the name it was stored under), source stored.
110
+ function migrateV1(read, decls) {
111
+ const out = new Map();
112
+ for (const [variable, e] of read.values) {
113
+ const d = decls.get(e.module);
114
+ const name = d != null && d.variable != null && V1_GITHUB.includes(d.variable) && V1_GITHUB.includes(variable) ? d.variable : variable;
115
+ if (!out.has(e.module)) out.set(e.module, new Map());
116
+ out.get(e.module).set(name, {origin: GH_ORIGIN, source: 'stored', value: e.value});
117
+ }
118
+ return out;
119
+ }
120
+ // A version 2 store's GitHub key under its earlier name (the Reviewer's high
121
+ // reviews of #98, 3, and its round 2, 3): ch-access-github 0.2.0 declares
122
+ // GITHUB_TOKEN where 0.1.0 declared COUNTINGHOUSE_GITHUB_TOKEN. Only that
123
+ // rename, for GitHub's origin, as migrateV1 reads a version 1 file: a module
124
+ // that declares GITHUB_TOKEN for GH_ORIGIN and holds a binding only under
125
+ // COUNTINGHOUSE_GITHUB_TOKEN for GH_ORIGIN reads it under GITHUB_TOKEN.
126
+ // Any other rename stays "declares another credential" (L5a: the key is
127
+ // added again). Every reader sees it so, and nothing is rewritten: the
128
+ // stored name changes only when the user runs `credentials add`, so nothing
129
+ // races a remove, which deletes a module's binding whatever its name (the
130
+ // Reviewer's cut on #98's round 3).
131
+ // -> [{module, from, to, entry}], modules changed in place.
132
+ const V1_OLD = 'COUNTINGHOUSE_GITHUB_TOKEN';
133
+ const V1_NEW = 'GITHUB_TOKEN';
134
+ function carryV2(modules, decls) {
135
+ const carried = [];
136
+ for (const [m, d] of decls) {
137
+ if (d == null || d.problem != null || d.variable !== V1_NEW || d.origin !== GH_ORIGIN) continue;
138
+ const vars = modules.get(m);
139
+ if (vars == null || vars.has(V1_NEW) || !vars.has(V1_OLD) || vars.get(V1_OLD).origin !== GH_ORIGIN) continue;
140
+ const entry = vars.get(V1_OLD);
141
+ vars.set(V1_NEW, entry);
142
+ vars.delete(V1_OLD);
143
+ carried.push({module: m, from: V1_OLD, to: V1_NEW, entry});
144
+ }
145
+ return carried;
146
+ }
147
+ // -> {bindings, carried} or {problem}: the store read, its checks applied.
148
+ // decls: declarations(where, record) when the caller has them (read once:
149
+ // the medium on #98's high round, 3)
150
+ function bindings(where, record, {platform, decls = null} = {}) {
151
+ let read;
152
+ try { read = store.readStore(where.home, {platform}); } catch (err) { return {problem: err.message, transient: err.transient === true}; }
153
+ const d = decls != null ? decls : declarations(where, record);
154
+ if (read.version === 2) {
155
+ const modules = new Map([...read.modules].map(([m, v]) => [m, new Map(v)]));
156
+ return {bindings: modules, carried: carryV2(modules, d)};
157
+ }
158
+ return {bindings: migrateV1(read, d), v1: true, carried: []};
159
+ }
160
+ // What a start says of a key read from its earlier name, once per start:
161
+ // read -> [line] (the store as bindings() read it; never written); where:
162
+ // the home's layout, for the command's launcher form (lib/command-line.js)
163
+ function carriedLines(read, where) {
164
+ if (read == null || !Array.isArray(read.carried)) return [];
165
+ // (credentials add asks for the key again: it moves nothing; the medium
166
+ // on #98's cut, 2)
167
+ return read.carried.map(({module, to}) => `${short(module)}'s key is read from its earlier name; \`${chLocal(where, `credentials add ${short(module)}`)}\` stores it again under ${to}`);
168
+ }
169
+
170
+ // What a declaration changed against the key stored for the module (the
171
+ // Reviewer's high review of L5a, 5): the origin, the variable's name, or
172
+ // both. Any of them needs the key added again (the binding is all three).
173
+ // -> {reason, which}, never a value.
174
+ function declarationChange(decl, storedVariable, storedOrigin) {
175
+ const origin = storedOrigin !== decl.origin;
176
+ const variable = storedVariable !== decl.variable;
177
+ if (origin && variable) {
178
+ return {reason: `it now sends ${decl.variable} to ${decl.origin}; the stored key is ${storedVariable}, for ${storedOrigin}`,
179
+ which: 'declares another credential and address'};
180
+ }
181
+ if (origin) {
182
+ return {reason: `it sends its credential somewhere new (${decl.origin}; the stored one is for ${storedOrigin})`,
183
+ which: 'sends its credential somewhere new'};
184
+ }
185
+ return {reason: `it now names its credential ${decl.variable} (the stored key is ${storedVariable}, for the same address, ${decl.origin})`,
186
+ which: 'names its credential differently'};
187
+ }
188
+
189
+ // One module's state (section 6.7): {state: 'ok', binding} | 'none' |
190
+ // 'elsewhere' {binding} | 'gh-gave-none' {why} | 'store-problem' {problem}
191
+ // | 'unreadable' {problem}; each with the sentence a start says.
192
+ // gh: {token} or {why}, asked only when a binding's source is gh. where: the
193
+ // home's layout, for the command's launcher form (lib/command-line.js).
194
+ // gh's reason as a notice can carry it: its known ones short, any other cut
195
+ // (lib/github-token.js)
196
+ function shortGhWhy(why) {
197
+ if (/not logged in/.test(why)) return 'gh is not logged in';
198
+ if (/did not answer within/.test(why)) return 'gh did not answer';
199
+ if (/was not found/.test(why)) return 'gh was not found';
200
+ return require('./command-line').terminalText(why, 40);
201
+ }
202
+
203
+ function stateOf(module, decl, read, gh, where, shared = null) {
204
+ const m = short(module);
205
+ const add = () => chLocal(where, `credentials add ${m}`);
206
+ if (decl.problem != null) return {state: 'unreadable', reason: decl.problem};
207
+ if (read.problem != null) return {state: 'store-problem', reason: `the stored credentials are not used (${read.problem})`};
208
+ const vars = read.bindings.get(module);
209
+ const binding = vars != null ? vars.get(decl.variable) : null;
210
+ const other = vars != null ? [...vars].find(([v, b]) => v !== decl.variable || b.origin !== decl.origin) : null;
211
+ if (binding == null || binding.origin !== decl.origin) {
212
+ if (other != null) {
213
+ const what = declarationChange(decl, other[0], other[1].origin);
214
+ return {state: 'elsewhere', binding: {variable: other[0], ...other[1]},
215
+ reason: `${what.reason}. It gets no key, and is not loaded, until you run \`${add()}\` again`,
216
+ which: `${what.which}: run \`${add()}\` again`};
217
+ }
218
+ return {state: 'none', reason: `it needs a credential (${decl.variable}, sent to ${decl.origin}): run \`${add()}\``,
219
+ which: `needs a credential: run \`${add()}\``};
220
+ }
221
+ if (binding.source === 'gh' && decl.origin !== GH_ORIGIN) {
222
+ // (the store refuses such an entry; a hand-written one never gets gh's
223
+ // token: the Fable pass on L5a, F5)
224
+ return {state: 'store-problem', reason: `its stored credential uses your gh login, which is given only to ${GH_ORIGIN}: run \`${add()}\` again`,
225
+ which: `has a stored credential that cannot be used: run \`${add()}\` again`};
226
+ }
227
+ if (binding.source === 'gh' && (gh == null || gh.token == null)) {
228
+ // (inside start, where a notice is cut at 200 characters: the command
229
+ // first, gh's reason short; status, which no cut reaches, keeps the
230
+ // whole -- the reviewer's high on #147, M3)
231
+ const why = gh != null && gh.why != null ? gh.why : 'gh was not asked';
232
+ return {state: 'gh-gave-none', reason: shared != null
233
+ ? `gh gave no token: run \`${add()}\` (${shortGhWhy(why)})`
234
+ : `your gh login gave no token at this start (${why}): run \`gh auth login\` and ${restartOne(where, shared)}; or \`${add()}\``,
235
+ which: shared != null ? `has no gh token: run \`${add()}\`` : `has no token from your gh login: run \`gh auth login\`, or \`${add()}\``};
236
+ }
237
+ return {state: 'ok', binding: {variable: decl.variable, ...binding}};
238
+ }
239
+
240
+ const digest = (value) => crypto.createHash('sha256').update(String(value)).digest('hex');
241
+ // a binding as it was (never its value): origin, source and, for a stored
242
+ // one, the value's digest
243
+ const fingerprint = (b) => `${b.origin} ${b.source} ${b.source === 'stored' ? digest(b.value) : ''}`;
244
+
245
+ // What a start gives its runtime (section 6.4).
246
+ // env: the environment the runtime will get (its COUNTINGHOUSE_CREDENTIAL_*
247
+ // removed here); ghToken(): -> Promise of {token} | {why}, asked once and
248
+ // only when some binding's source is gh; acceptanceMap: under
249
+ // CH_LOCAL_REMOTE_MAP only an acceptance token (chacc_...) gets a slot.
250
+ // -> {env, file: the version 2 --remoteCredentials object, identities:
251
+ // Map(module -> {variable, origin, source, digest, slot}), states:
252
+ // Map(module -> stateOf()), gh}
253
+ async function forStart(where, record, {env, ghToken, platform, acceptanceMap = false, decls: given = null, read: readGiven = null, shared = null}) {
254
+ const decls = given != null ? given : declarations(where, record);
255
+ // env is already an allowlist (start: shim-config runtimeEnv/allowedEnv),
256
+ // so no client credential is in it; a slot name, by any case, is removed
257
+ // all the same (a planted key). Declared names are not stripped: one
258
+ // naming PATH would strip the runtime's own (the medium on the high
259
+ // round, 10).
260
+ const runEnv = {};
261
+ for (const [k, v] of Object.entries(env || {})) if (!k.toUpperCase().startsWith(SLOT_PREFIX)) runEnv[k] = v;
262
+ const read = readGiven != null ? readGiven : bindings(where, record, {platform, decls});
263
+ const needsGh = read.bindings != null && [...decls].some(([m, d]) => {
264
+ const vars = read.bindings.get(m);
265
+ const b = vars != null && d.variable != null ? vars.get(d.variable) : null;
266
+ return b != null && b.source === 'gh' && b.origin === d.origin && d.origin === GH_ORIGIN;
267
+ });
268
+ const gh = needsGh ? await ghToken() : null;
269
+ const states = new Map();
270
+ const identities = new Map();
271
+ // every binding present at this start, with or without a slot (a gh one
272
+ // gh gave nothing for, one the acceptance map kept out): applyStates says
273
+ // "restart" only of one added since (the Fable pass on L5a, F3)
274
+ const seen = new Map();
275
+ const file = {version: 2, modules: {}};
276
+ let n = 0;
277
+ for (const [m, d] of [...decls].sort(([a], [b]) => (a < b ? -1 : 1))) {
278
+ let s = stateOf(m, d, read, gh, where, shared);
279
+ const present = read.bindings != null && read.bindings.get(m) != null ? read.bindings.get(m).get(d.variable) : null;
280
+ if (present != null) seen.set(m, fingerprint(present));
281
+ if (s.state === 'ok') {
282
+ const value = s.binding.source === 'gh' ? gh.token : s.binding.value;
283
+ if (acceptanceMap && !/^chacc_/.test(value)) {
284
+ s = {state: 'none', reason: `under an acceptance run's origin map only an acceptance token is given: run \`${chLocal(where, `credentials add ${short(m)}`)}\` with one`};
285
+ } else {
286
+ n += 1;
287
+ const slot = `${SLOT_PREFIX}${n}`;
288
+ runEnv[slot] = value;
289
+ identities.set(m, {variable: d.variable, origin: d.origin, source: s.binding.source, digest: digest(value), slot});
290
+ file.modules[m] = {[d.origin]: {[d.variable]: slot}};
291
+ }
292
+ }
293
+ states.set(m, s);
294
+ }
295
+ return {env: runEnv, file, identities, states, seen, gh, decls};
296
+ }
297
+
298
+ // Whether a module's slot still matches the store as it is now (section 6.4:
299
+ // all five parts; for gh, the four the store holds): -> {ok: true} |
300
+ // {ok: false, why: 'none' | 'changed'}. Read again at each load or reload.
301
+ // read, decl: the store and the declaration already read (applyStates
302
+ // reads each once for every module)
303
+ function slotMatches(where, record, module, identity, {platform, read = null, decl} = {}) {
304
+ if (identity == null) return {ok: false, why: 'none'};
305
+ const d = decl !== undefined ? decl : declared(where, record, module);
306
+ if (d == null || d.problem != null || d.variable !== identity.variable || d.origin !== identity.origin) return {ok: false, why: 'changed'};
307
+ if (read == null) read = bindings(where, record, {platform});
308
+ if (read.problem != null) return {ok: false, why: 'changed'};
309
+ const vars = read.bindings.get(module);
310
+ const b = vars != null ? vars.get(identity.variable) : null;
311
+ if (b == null) return {ok: false, why: 'removed'};
312
+ if (b.origin !== identity.origin || b.source !== identity.source) return {ok: false, why: 'changed'};
313
+ if (b.source === 'stored' && digest(b.value) !== identity.digest) return {ok: false, why: 'changed'};
314
+ return {ok: true};
315
+ }
316
+
317
+ // Each declared module's state while a start runs (section 6.4): no new
318
+ // slot is given, so a module is usable only through the slot it was started
319
+ // with, matching the store now. -> Map(module -> state) as stateOf's, with:
320
+ // 'removed' / 'changed' (its slot no longer matches: unloaded until it
321
+ // matches again or the client restarts) and 'new' (usable in the store, but
322
+ // this runtime has no slot for it: "restart your client to load it").
323
+ // restart: true on those a restart makes usable: the store, as it is now, has
324
+ // what the declaration asks for (for gh, its entry: whether gh gives a token
325
+ // is known only when a start asks it).
326
+ // A store that could not be read decides nothing (the Reviewer's high
327
+ // review of L5a, 3): the Map comes back empty with `unreadable` set (the
328
+ // reason), and the caller keeps its last good states and reads again.
329
+ // startStates, seen: forStart's states and its bindings present at start;
330
+ // a binding without a slot that is the one present at start keeps start's
331
+ // own reason (how to provide its value), never "restart your client"
332
+ function applyStates(where, record, identities, {platform, startStates = null, seen = null, shared = null} = {}) {
333
+ const out = new Map();
334
+ const decls = declarations(where, record);
335
+ // the declarations read for this pass, for the caller (one parse of each
336
+ // package.json per pass: the Reviewer's round 3, 10)
337
+ out.decls = decls;
338
+ const read = bindings(where, record, {platform});
339
+ // (only a read that failed, not a file found wrong: that is a read, and
340
+ // decides, store-problem for every module that declares one)
341
+ if (read.problem != null && read.transient === true) { out.unreadable = read.problem; return out; }
342
+ for (const [m, d] of decls) {
343
+ const id = identities.get(m);
344
+ if (id != null) {
345
+ const match = slotMatches(where, record, m, id, {platform, read, decl: d});
346
+ const gone = match.why === 'removed';
347
+ out.set(m, match.ok ? {state: 'ok', binding: {variable: id.variable, origin: id.origin, source: id.source}}
348
+ // the text as it behaves (8): the same key added again matches its
349
+ // slot, and the module loads in place again; a new key needs a
350
+ // restart, whose start gives it a slot (which `credentials add` asks
351
+ // of a shared runtime); with no key a restart holds it back
352
+ : gone ? {state: 'removed',
353
+ reason: shared === false ? 'its credential was removed; it is unloaded here until you add the key it started with again, or add another and restart this client'
354
+ : shared === true ? `its credential was removed; it is unloaded until you add one: run \`${chLocal(where, `credentials add ${short(m)}`)}\``
355
+ : `its credential was removed; it is unloaded here until you add the key it started with again, or add another and ${restartOne(where, shared)}`,
356
+ // (what most users see: a part gets no notice of its own, its callers' do)
357
+ which: shared === true ? `has had its credential removed: run \`${chLocal(where, `credentials add ${short(m)}`)}\``
358
+ : `has had its credential removed: add the key it started with again, or another and ${restartOne(where, shared)}`}
359
+ : {state: 'changed', restart: ['ok', 'gh-gave-none'].includes(stateOf(m, d, read, {why: 'a running start asks gh only when it starts'}, where, shared).state),
360
+ reason: shared === false ? 'its credential changed; it is unloaded here until this client restarts and takes the new one (or the earlier key is added back)'
361
+ // (shared: the notice's 200 characters, a launcher path in it: M3)
362
+ : shared === true ? `its credential changed; unloaded until \`${chLocal(where, 'restart')}\` is run, or the earlier key is back`
363
+ : `its credential changed; it is unloaded here until the runtime restarts and takes the new one (${restartOne(where, shared)}), or the earlier key is added back`,
364
+ which: `has had its credential changed: ${restartOne(where, shared)}`});
365
+ continue;
366
+ }
367
+ const s = stateOf(m, d, read, {why: 'a running start asks gh only when it starts'}, where, shared);
368
+ // a binding no restart would make usable (a gh entry for another origin,
369
+ // a declaration that cannot be read, none or elsewhere) says its own
370
+ // reason, never "restart" (the Reviewer's round 3, 2); a gh one gh was
371
+ // not asked for here is usable after a restart, below
372
+ if (s.state !== 'ok' && s.state !== 'gh-gave-none') { out.set(m, s); continue; }
373
+ // usable in the store (gh's included), but this runtime was started
374
+ // without it
375
+ const vars = read.bindings != null ? read.bindings.get(m) : null;
376
+ const b = vars != null && d.variable != null ? vars.get(d.variable) : null;
377
+ if (b != null && b.origin === d.origin && seen != null && seen.get(m) === fingerprint(b) && startStates != null && startStates.get(m) != null && startStates.get(m).state !== 'ok') {
378
+ out.set(m, startStates.get(m));
379
+ continue;
380
+ }
381
+ if (b != null && b.origin === d.origin) {
382
+ out.set(m, {state: 'new', restart: true, reason: `it has a credential the running runtime was not started with; ${restartOne(where, shared)} to load it`,
383
+ which: shared === true ? `has a new credential: ${restartOne(where, shared)}` : `has a credential the running runtime was not started with: ${restartOne(where, shared)}`});
384
+ continue;
385
+ }
386
+ out.set(m, s);
387
+ }
388
+ return out;
389
+ }
390
+
391
+ // availability()'s credential seam from a start's (or an apply's) states:
392
+ // null for a module that declares none or whose binding is usable, else
393
+ // {reason, which} (lib/availability.js rule 5)
394
+ function credentialSeam(states) {
395
+ return (m, packs, unit) => {
396
+ const s = states.get(m);
397
+ if (s == null) return null;
398
+ if (s.state === 'ok') { unit.credential = s.binding.variable; return null; }
399
+ return {reason: s.reason, which: s.which != null ? s.which : `is not available (${s.reason})`};
400
+ };
401
+ }
402
+
403
+ module.exports = {ownModules, installedAt, declarationChange, applyStates, credentialSeam, declared, declarations, bindings, carriedLines, migrateV1, stateOf, forStart, slotMatches, digest, GH_ORIGIN, SLOT, SLOT_PREFIX, V1_GITHUB};