@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.
- package/LICENSE +202 -0
- package/README.md +361 -2
- package/bin/ch-local.js +472 -0
- package/clients/claude-code/.claude-plugin/plugin.json +6 -0
- package/clients/claude-code/.mcp.json +11 -0
- package/clients/claude-code/bin/launch.js +235 -0
- package/clients/claude-code/bin/win-acl.js +420 -0
- package/clients/claude-code/skills/ci-failure-triage/SKILL.md +21 -0
- package/clients/claude-code/skills/countinghouse-module/SKILL.md +177 -0
- package/clients/claude-code/skills/countinghouse-setup/SKILL.md +74 -0
- package/lib/allowlist.js +65 -0
- package/lib/aside.js +16 -0
- package/lib/atomic.js +45 -0
- package/lib/auto-apply.js +245 -0
- package/lib/auto-upgrade.js +98 -0
- package/lib/availability.js +307 -0
- package/lib/ceiling.js +280 -0
- package/lib/clean-text.js +20 -0
- package/lib/cli-change.js +38 -0
- package/lib/client-conditions-fixtures.js +143 -0
- package/lib/client-conditions.js +656 -0
- package/lib/clients.js +179 -0
- package/lib/command-line.js +202 -0
- package/lib/conditions-command.js +116 -0
- package/lib/control.js +134 -0
- package/lib/credential-store.js +414 -0
- package/lib/credentials-command.js +344 -0
- package/lib/daemon-requests.js +137 -0
- package/lib/daemon.js +888 -0
- package/lib/describe-module.js +137 -0
- package/lib/description-check.js +175 -0
- package/lib/failed-json.js +43 -0
- package/lib/gc.js +274 -0
- package/lib/github-token.js +57 -0
- package/lib/handoff-io.js +73 -0
- package/lib/held-back.js +116 -0
- package/lib/hidden-input.js +64 -0
- package/lib/history.js +49 -0
- package/lib/home.js +372 -0
- package/lib/in-place.js +1036 -0
- package/lib/install-plan.js +142 -0
- package/lib/install.js +846 -0
- package/lib/installed-description.js +153 -0
- package/lib/integrity.js +7 -0
- package/lib/lock.js +456 -0
- package/lib/lockfile-rules.js +98 -0
- package/lib/machine.js +20 -0
- package/lib/module-credentials.js +403 -0
- package/lib/module-record.js +298 -0
- package/lib/module-roles.js +44 -0
- package/lib/module-seams.js +26 -0
- package/lib/module-store.js +202 -0
- package/lib/module-values.js +334 -0
- package/lib/names.js +31 -0
- package/lib/next-steps.js +8 -0
- package/lib/node-check.js +56 -0
- package/lib/npm-fetch.js +123 -0
- package/lib/npm-release.js +99 -0
- package/lib/npm-upgrade.js +146 -0
- package/lib/npm.js +41 -0
- package/lib/outside-edits.js +162 -0
- package/lib/own-applied.js +175 -0
- package/lib/own-command.js +380 -0
- package/lib/own-file.js +120 -0
- package/lib/own-record.js +96 -0
- package/lib/own-tree.js +336 -0
- package/lib/pack-table.js +290 -0
- package/lib/packs-command.js +570 -0
- package/lib/packs.js +219 -0
- package/lib/pins.js +64 -0
- package/lib/pipe-probe.js +82 -0
- package/lib/plain-read.js +63 -0
- package/lib/private-file.js +90 -0
- package/lib/private-write.js +33 -0
- package/lib/provenance.js +234 -0
- package/lib/record.js +82 -0
- package/lib/registry.js +22 -0
- package/lib/release-pins.js +350 -0
- package/lib/release-pins.json +4225 -0
- package/lib/release-tags.js +12 -0
- package/lib/release.js +36 -0
- package/lib/restart-command.js +161 -0
- package/lib/rollback.js +227 -0
- package/lib/run-liveness.js +15 -0
- package/lib/runtime-log.js +287 -0
- package/lib/sandbox-support.js +17 -0
- package/lib/semver-order.js +40 -0
- package/lib/session-socket.js +69 -0
- package/lib/session-table.js +238 -0
- package/lib/session.js +281 -0
- package/lib/settings-command.js +82 -0
- package/lib/settings.js +564 -0
- package/lib/shim-binary.js +152 -0
- package/lib/shim-config.js +159 -0
- package/lib/shim-install.js +365 -0
- package/lib/sigstore/README.md +44 -0
- package/lib/sigstore/npm-keys.json +18 -0
- package/lib/sigstore/trusted-root.json +126 -0
- package/lib/snippets.js +76 -0
- package/lib/start.js +721 -0
- package/lib/store-files.js +48 -0
- package/lib/store-paths.js +33 -0
- package/lib/swap-preload.js +38 -0
- package/lib/tar.js +220 -0
- package/lib/uninstall.js +314 -0
- package/lib/unpack.js +41 -0
- package/lib/upgrade-stamp.js +63 -0
- package/lib/upgrade.js +281 -0
- package/lib/watch.js +40 -0
- package/lib/win-acl.js +420 -0
- package/node_modules/@sigstore/bundle/LICENSE +202 -0
- package/node_modules/@sigstore/bundle/README.md +19 -0
- package/node_modules/@sigstore/bundle/dist/build.d.ts +18 -0
- package/node_modules/@sigstore/bundle/dist/build.js +100 -0
- package/node_modules/@sigstore/bundle/dist/bundle.d.ts +74 -0
- package/node_modules/@sigstore/bundle/dist/bundle.js +24 -0
- package/node_modules/@sigstore/bundle/dist/error.d.ts +4 -0
- package/node_modules/@sigstore/bundle/dist/error.js +25 -0
- package/node_modules/@sigstore/bundle/dist/index.d.ts +8 -0
- package/node_modules/@sigstore/bundle/dist/index.js +43 -0
- package/node_modules/@sigstore/bundle/dist/serialized.d.ts +74 -0
- package/node_modules/@sigstore/bundle/dist/serialized.js +49 -0
- package/node_modules/@sigstore/bundle/dist/utility.d.ts +14 -0
- package/node_modules/@sigstore/bundle/dist/utility.js +2 -0
- package/node_modules/@sigstore/bundle/dist/validate.d.ts +7 -0
- package/node_modules/@sigstore/bundle/dist/validate.js +199 -0
- package/node_modules/@sigstore/bundle/package.json +35 -0
- package/node_modules/@sigstore/core/LICENSE +202 -0
- package/node_modules/@sigstore/core/README.md +10 -0
- package/node_modules/@sigstore/core/dist/asn1/error.d.ts +4 -0
- package/node_modules/@sigstore/core/dist/asn1/error.js +24 -0
- package/node_modules/@sigstore/core/dist/asn1/index.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/asn1/index.js +20 -0
- package/node_modules/@sigstore/core/dist/asn1/length.d.ts +3 -0
- package/node_modules/@sigstore/core/dist/asn1/length.js +62 -0
- package/node_modules/@sigstore/core/dist/asn1/obj.d.ts +14 -0
- package/node_modules/@sigstore/core/dist/asn1/obj.js +155 -0
- package/node_modules/@sigstore/core/dist/asn1/parse.d.ts +6 -0
- package/node_modules/@sigstore/core/dist/asn1/parse.js +124 -0
- package/node_modules/@sigstore/core/dist/asn1/tag.d.ts +16 -0
- package/node_modules/@sigstore/core/dist/asn1/tag.js +89 -0
- package/node_modules/@sigstore/core/dist/crypto.d.ts +6 -0
- package/node_modules/@sigstore/core/dist/crypto.js +69 -0
- package/node_modules/@sigstore/core/dist/dsse.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/dsse.js +29 -0
- package/node_modules/@sigstore/core/dist/encoding.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/encoding.js +27 -0
- package/node_modules/@sigstore/core/dist/index.d.ts +9 -0
- package/node_modules/@sigstore/core/dist/index.js +66 -0
- package/node_modules/@sigstore/core/dist/json.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/json.js +60 -0
- package/node_modules/@sigstore/core/dist/oid.d.ts +3 -0
- package/node_modules/@sigstore/core/dist/oid.js +20 -0
- package/node_modules/@sigstore/core/dist/pem.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/pem.js +43 -0
- package/node_modules/@sigstore/core/dist/rfc3161/error.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/rfc3161/error.js +21 -0
- package/node_modules/@sigstore/core/dist/rfc3161/index.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/rfc3161/index.js +20 -0
- package/node_modules/@sigstore/core/dist/rfc3161/timestamp.d.ts +36 -0
- package/node_modules/@sigstore/core/dist/rfc3161/timestamp.js +212 -0
- package/node_modules/@sigstore/core/dist/rfc3161/tstinfo.d.ts +12 -0
- package/node_modules/@sigstore/core/dist/rfc3161/tstinfo.js +72 -0
- package/node_modules/@sigstore/core/dist/stream.d.ts +21 -0
- package/node_modules/@sigstore/core/dist/stream.js +117 -0
- package/node_modules/@sigstore/core/dist/x509/cert.d.ts +43 -0
- package/node_modules/@sigstore/core/dist/x509/cert.js +245 -0
- package/node_modules/@sigstore/core/dist/x509/ext.d.ts +41 -0
- package/node_modules/@sigstore/core/dist/x509/ext.js +146 -0
- package/node_modules/@sigstore/core/dist/x509/index.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/x509/index.js +23 -0
- package/node_modules/@sigstore/core/dist/x509/sct.d.ts +25 -0
- package/node_modules/@sigstore/core/dist/x509/sct.js +158 -0
- package/node_modules/@sigstore/core/package.json +31 -0
- package/node_modules/@sigstore/protobuf-specs/LICENSE +202 -0
- package/node_modules/@sigstore/protobuf-specs/README.md +5 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/envelope.d.ts +44 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/envelope.js +59 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/events.d.ts +64 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/events.js +174 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/api/field_behavior.d.ts +74 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/api/field_behavior.js +141 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/any.d.ts +74 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/any.js +35 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/descriptor.d.ts +1309 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/descriptor.js +2191 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/timestamp.d.ts +113 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/timestamp.js +29 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/dsse.d.ts +23 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/dsse.js +55 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/entry.d.ts +43 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/entry.js +81 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/hashedrekord.d.ts +22 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/hashedrekord.js +56 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/verifier.d.ts +35 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/verifier.js +74 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_bundle.d.ts +146 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_bundle.js +103 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_common.d.ts +304 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_common.js +612 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_monitor.d.ts +33 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_monitor.js +55 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_rekor.d.ts +144 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_rekor.js +137 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_trustroot.d.ts +386 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_trustroot.js +284 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_verification.d.ts +191 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_verification.js +281 -0
- package/node_modules/@sigstore/protobuf-specs/dist/index.d.ts +6 -0
- package/node_modules/@sigstore/protobuf-specs/dist/index.js +37 -0
- package/node_modules/@sigstore/protobuf-specs/dist/rekor/v2/index.d.ts +4 -0
- package/node_modules/@sigstore/protobuf-specs/dist/rekor/v2/index.js +35 -0
- package/node_modules/@sigstore/protobuf-specs/package.json +35 -0
- package/node_modules/@sigstore/verify/README.md +9 -0
- package/node_modules/@sigstore/verify/dist/bundle/dsse.d.ts +12 -0
- package/node_modules/@sigstore/verify/dist/bundle/dsse.js +44 -0
- package/node_modules/@sigstore/verify/dist/bundle/index.d.ts +4 -0
- package/node_modules/@sigstore/verify/dist/bundle/index.js +59 -0
- package/node_modules/@sigstore/verify/dist/bundle/message.d.ts +13 -0
- package/node_modules/@sigstore/verify/dist/bundle/message.js +54 -0
- package/node_modules/@sigstore/verify/dist/error.d.ts +16 -0
- package/node_modules/@sigstore/verify/dist/error.js +34 -0
- package/node_modules/@sigstore/verify/dist/index.d.ts +6 -0
- package/node_modules/@sigstore/verify/dist/index.js +28 -0
- package/node_modules/@sigstore/verify/dist/key/certificate.d.ts +21 -0
- package/node_modules/@sigstore/verify/dist/key/certificate.js +216 -0
- package/node_modules/@sigstore/verify/dist/key/index.d.ts +10 -0
- package/node_modules/@sigstore/verify/dist/key/index.js +75 -0
- package/node_modules/@sigstore/verify/dist/key/sct.d.ts +4 -0
- package/node_modules/@sigstore/verify/dist/key/sct.js +78 -0
- package/node_modules/@sigstore/verify/dist/policy.d.ts +5 -0
- package/node_modules/@sigstore/verify/dist/policy.js +50 -0
- package/node_modules/@sigstore/verify/dist/shared.types.d.ts +50 -0
- package/node_modules/@sigstore/verify/dist/shared.types.js +2 -0
- package/node_modules/@sigstore/verify/dist/timestamp/index.d.ts +11 -0
- package/node_modules/@sigstore/verify/dist/timestamp/index.js +24 -0
- package/node_modules/@sigstore/verify/dist/timestamp/tsa.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/timestamp/tsa.js +63 -0
- package/node_modules/@sigstore/verify/dist/tlog/checkpoint.d.ts +11 -0
- package/node_modules/@sigstore/verify/dist/tlog/checkpoint.js +154 -0
- package/node_modules/@sigstore/verify/dist/tlog/dsse.d.ts +6 -0
- package/node_modules/@sigstore/verify/dist/tlog/dsse.js +106 -0
- package/node_modules/@sigstore/verify/dist/tlog/hashedrekord.d.ts +6 -0
- package/node_modules/@sigstore/verify/dist/tlog/hashedrekord.js +94 -0
- package/node_modules/@sigstore/verify/dist/tlog/index.d.ts +5 -0
- package/node_modules/@sigstore/verify/dist/tlog/index.js +92 -0
- package/node_modules/@sigstore/verify/dist/tlog/intoto.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/tlog/intoto.js +62 -0
- package/node_modules/@sigstore/verify/dist/tlog/merkle.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/tlog/merkle.js +104 -0
- package/node_modules/@sigstore/verify/dist/tlog/set.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/tlog/set.js +60 -0
- package/node_modules/@sigstore/verify/dist/trust/filter.d.ts +8 -0
- package/node_modules/@sigstore/verify/dist/trust/filter.js +23 -0
- package/node_modules/@sigstore/verify/dist/trust/index.d.ts +5 -0
- package/node_modules/@sigstore/verify/dist/trust/index.js +90 -0
- package/node_modules/@sigstore/verify/dist/trust/trust.types.d.ts +29 -0
- package/node_modules/@sigstore/verify/dist/trust/trust.types.js +2 -0
- package/node_modules/@sigstore/verify/dist/verifier.d.ts +31 -0
- package/node_modules/@sigstore/verify/dist/verifier.js +160 -0
- package/node_modules/@sigstore/verify/package.json +36 -0
- package/package.json +37 -4
|
@@ -0,0 +1,570 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const {notAllowed, ceilingFor, forbiddenBy, startUnderCeiling} = require('./ceiling');
|
|
3
|
+
// Many packs in one home (plan Task 12b; spec §2, "Packs after the first
|
|
4
|
+
// release"; reviewer, 2026-11-12):
|
|
5
|
+
// ch-local add-pack <name> --from <dir> [--unreleased-pins <file>]
|
|
6
|
+
// ch-local remove-pack <name>
|
|
7
|
+
// ch-local status
|
|
8
|
+
// No client file is touched: a client's entry runs `start`, which loads every
|
|
9
|
+
// installed pack.
|
|
10
|
+
const fs = require('node:fs');
|
|
11
|
+
const path = require('node:path');
|
|
12
|
+
const {ALLOWLIST} = require('./allowlist');
|
|
13
|
+
const {layout} = require('./home');
|
|
14
|
+
const {own} = require('./record');
|
|
15
|
+
const {readModulesRecord, writeModulesRecord, livePacks, activeVersions, compareVersions} = require('./module-record');
|
|
16
|
+
const {placeModule, wholeAt} = require('./module-store');
|
|
17
|
+
const {versionDir} = require('./store-paths');
|
|
18
|
+
const {availability, short} = require('./availability');
|
|
19
|
+
const {readSettings, valueOf} = require('./settings');
|
|
20
|
+
const {outsideEdits} = require('./outside-edits');
|
|
21
|
+
const {ghToken} = require('./github-token');
|
|
22
|
+
const {withLock} = require('./lock');
|
|
23
|
+
const {effectiveAllow, UNRELEASED_LINE} = require('./pins');
|
|
24
|
+
const {collectStore, liveRuns, onThisMachine} = require('./gc');
|
|
25
|
+
const {loadTarballs} = require('./install');
|
|
26
|
+
const table = require('./pack-table');
|
|
27
|
+
const plan = require('./install-plan');
|
|
28
|
+
const {installedPacks, withdrawnNames, withdrawnStatusLine, releaseOf, recordRelease, staleLine, installLine, entryOf} = require('./packs');
|
|
29
|
+
const {chLocal, chLocalSelf, homeNote, terminalText, folderArg, hintCommand} = require('./command-line');
|
|
30
|
+
const {readOwnRecord} = require('./own-record');
|
|
31
|
+
const {copyDir} = require('./own-tree');
|
|
32
|
+
const {enforceAvailable} = require('./sandbox-support');
|
|
33
|
+
|
|
34
|
+
// The home's record (modules.json), or null after printing why it cannot be
|
|
35
|
+
// read (an earlier ch-local's packs.json: install migrates it).
|
|
36
|
+
function recordOf(where, io) {
|
|
37
|
+
try {
|
|
38
|
+
return {record: readModulesRecord(where)};
|
|
39
|
+
} catch (err) {
|
|
40
|
+
io.stderr.write(`ch-local: ${err.message}\n`);
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Whether a pack meets section 9.4's table: a live installed pack comes from
|
|
46
|
+
// other pins than this one (a development home's from its pins file). In a
|
|
47
|
+
// released home of one release the pins decide, and nothing is asked.
|
|
48
|
+
function tableApplies(record, allow, eff, pack) {
|
|
49
|
+
return table.fromOtherPins(record, plan.fromRelease(allow, eff), {except: [pack]});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// what add-pack's released refusals tell the user to do (where: the home's
|
|
53
|
+
// layout, for the command's launcher form: lib/command-line.js)
|
|
54
|
+
// (add-pack runs only with --from, so its refusals keep the folder: the
|
|
55
|
+
// medium on A11, 1-3; both commands are the CLI's own forms)
|
|
56
|
+
// (the newer release installed by THIS ch-local, never the home's older
|
|
57
|
+
// launcher; the add-pack after it by the home's, which that install made
|
|
58
|
+
// the newer one -- the closing pass, nit)
|
|
59
|
+
// (this ch-local's own path names no home, so on Windows the home is said
|
|
60
|
+
// after it, as installLine does -- the medium on the closing pass, 1)
|
|
61
|
+
const reinstallHint = (record, pack, where, platform = process.platform) => `install the newer release with \`${chLocalSelf(where, `install --pack ${Object.keys(record.packs)[0] || pack} --from <its directory>`, platform)}\`${homeNote(where, platform)}, then add the pack with \`${chLocal(where, `add-pack ${pack} --from <its directory>`, platform)}\``;
|
|
62
|
+
|
|
63
|
+
// What add-pack refuses whatever the table says: run before any question
|
|
64
|
+
// and again under the lock. -> null | ALREADY | the refusal's text.
|
|
65
|
+
const ALREADY = Symbol('already installed');
|
|
66
|
+
function addRefusal(record, pack, spec, allow, where, platform = process.platform) {
|
|
67
|
+
if (record == null) return `nothing is installed yet; run ${hintCommand(where, `install --pack ${pack} --from <dir>`, platform)} first`;
|
|
68
|
+
if (own(record.packs, pack)) return ALREADY;
|
|
69
|
+
if (!spec.modules.every((name) => allow.pins[name] != null)) return `no release of the pack "${pack}" is pinned in this ch-local yet`;
|
|
70
|
+
// A pack is built against its release's runtime: the pins in use must name the installed one.
|
|
71
|
+
const reinstall = reinstallHint(record, pack, where, platform);
|
|
72
|
+
for (const name of allow.runtime.packages) {
|
|
73
|
+
const installedVersion = record.runtime.versions[name];
|
|
74
|
+
if (allow.pins[name] != null && installedVersion != null && allow.pins[name].version !== installedVersion) {
|
|
75
|
+
return `this release pins ${name} ${allow.pins[name].version}, but the installed runtime is ${installedVersion}; ${reinstall}`;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
for (const name of spec.modules) {
|
|
79
|
+
if (record.runtime.versions[name] != null) return `${name} is part of the runtime, not a pack's; run \`${chLocal(where, 'install')}\` again`;
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// report: {added}, set when the pack was added (the CLI's "next" line)
|
|
85
|
+
async function addPack({pack, from, unreleasedPins, report = null}, io, release = ALLOWLIST) {
|
|
86
|
+
const say = (s) => io.stdout.write(s + '\n');
|
|
87
|
+
const fail = (s, code = 1) => { io.stderr.write(`ch-local: ${s}\n`); return code; };
|
|
88
|
+
const spec = own(release.packs, pack) ? release.packs[pack] : null;
|
|
89
|
+
if (spec == null) return fail(`the pack "${pack}" is not in this ch-local release's allowlist; one of: ${Object.keys(release.packs).join(', ')}`, 2);
|
|
90
|
+
// the operator's allowlist of packs (start enforces it as well)
|
|
91
|
+
const unlisted = notAllowed(layout(io.env, io.homedir), pack, io, spec.modules);
|
|
92
|
+
if (unlisted != null) return fail(unlisted, 2);
|
|
93
|
+
// (from npm, install --pack adds a pack: A11)
|
|
94
|
+
if (from == null) {
|
|
95
|
+
const here = layout(io.env, io.homedir);
|
|
96
|
+
return fail(`add-pack adds a pack from tarballs on disk (--from <directory of tarballs>); to add one from npm, run ${hintCommand(here, `install --pack ${pack}`, io.platform)}`, 2);
|
|
97
|
+
}
|
|
98
|
+
const eff = effectiveAllow(release, unreleasedPins, io.env);
|
|
99
|
+
if (eff.problem != null) return fail(eff.problem, 2);
|
|
100
|
+
const allow = eff.allow;
|
|
101
|
+
const where = layout(io.env, io.homedir);
|
|
102
|
+
// Between packs from different pins (#413 section 9.4; L1b-2): the
|
|
103
|
+
// table's questions, every one asked before anything is written and
|
|
104
|
+
// before the lock is taken (no one holds it while someone types); any No
|
|
105
|
+
// ends the operation. The answers are checked again under the lock: a home
|
|
106
|
+
// that changed meanwhile is refused, never taken as answered.
|
|
107
|
+
let asked = null;
|
|
108
|
+
const pre = recordOf(where, io);
|
|
109
|
+
if (pre == null) return 1;
|
|
110
|
+
// what the lock would refuse is refused first: no one answers a question
|
|
111
|
+
// for an add that cannot happen, and no answer is written for it (the
|
|
112
|
+
// high review of #94, 6). Already installed: the lock says so.
|
|
113
|
+
const refusedPre = addRefusal(pre.record, pack, spec, allow, where, io.platform);
|
|
114
|
+
if (refusedPre != null && refusedPre !== ALREADY) return fail(refusedPre);
|
|
115
|
+
// the tarballs read now, each once, are the locked path's too
|
|
116
|
+
let preBytes = {};
|
|
117
|
+
if (refusedPre == null && tableApplies(pre.record, allow, eff, pack)) {
|
|
118
|
+
const before = table.decideBeforeLock(where, pre.record, pack, spec, allow.pins, (names) => loadTarballs(from, names, allow.pins));
|
|
119
|
+
if (before.problems != null) {
|
|
120
|
+
for (const p of before.problems) fail(p);
|
|
121
|
+
return fail('nothing was added');
|
|
122
|
+
}
|
|
123
|
+
preBytes = before.bytes;
|
|
124
|
+
const got = await table.askAll(where, before.decided, pack, io, (s) => fail(s));
|
|
125
|
+
if (got.code != null) return got.code;
|
|
126
|
+
asked = got.signature;
|
|
127
|
+
}
|
|
128
|
+
// (whether the pack was added: one already installed answers 0 too; said
|
|
129
|
+
// to the caller through report, for the CLI's "next" line)
|
|
130
|
+
const done = report != null ? report : {added: false};
|
|
131
|
+
const code = await withLock(where, io, () => addPackLocked({pack, from, spec, eff, allow, where, asked, preBytes, done}, io, {say, fail}));
|
|
132
|
+
// each of its modules that needs a credential and has none stored (#413
|
|
133
|
+
// section 6.2): after the lock, never holding it while someone types
|
|
134
|
+
if (code === 0) await require('./credentials-command').askMissing(io, spec.modules);
|
|
135
|
+
return code;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Released, the pins decide (#413 section 9.4): each of the pack's modules
|
|
139
|
+
// at this release's pin, placed in the store or, when an installed pack
|
|
140
|
+
// records it there already, skipped ("it shares ..."). Between packs from
|
|
141
|
+
// different pins, section 9.4's table (lib/pack-table.js), its questions
|
|
142
|
+
// answered before the lock.
|
|
143
|
+
async function addPackLocked({pack, from, spec, eff, allow, where, asked = null, preBytes = {}, done = null}, io, {say, fail}) {
|
|
144
|
+
const got = recordOf(where, io);
|
|
145
|
+
if (got == null) return 1;
|
|
146
|
+
const {record} = got;
|
|
147
|
+
const refused = addRefusal(record, pack, spec, allow, where, io.platform);
|
|
148
|
+
if (refused === ALREADY) { say(`the pack "${pack}" is already installed`); return 0; }
|
|
149
|
+
if (refused != null) return fail(refused);
|
|
150
|
+
const reinstall = reinstallHint(record, pack, where, io.platform);
|
|
151
|
+
// Between packs from different pins: section 9.4's table, as decided and
|
|
152
|
+
// answered before the lock (a change since is refused). Released, the
|
|
153
|
+
// pins decide: a module a live pack has must be at the pin (a runtime
|
|
154
|
+
// holds one version of a module: countinghouse's PART_VERSION_CONFLICT;
|
|
155
|
+
// a withdrawn pack never loads, so its versions are no conflict: #83's
|
|
156
|
+
// high review, 3).
|
|
157
|
+
let rows = null;
|
|
158
|
+
if (tableApplies(record, allow, eff, pack)) {
|
|
159
|
+
const again = table.recheck(where, record, pack, spec, allow.pins, asked);
|
|
160
|
+
if (again.problem != null) return fail(again.problem);
|
|
161
|
+
rows = again.rows;
|
|
162
|
+
} else {
|
|
163
|
+
const live = activeVersions(livePacks(record.packs, record.withdrawn), []);
|
|
164
|
+
rows = [];
|
|
165
|
+
for (const name of spec.modules) {
|
|
166
|
+
const pinned = allow.pins[name].version;
|
|
167
|
+
const active = own(live, name) ? live[name] : null;
|
|
168
|
+
if (active != null && active !== pinned) return fail(`${name} is installed at ${active}, but this release pins ${pinned} for "${pack}"; ${reinstall}`);
|
|
169
|
+
// (the pack is not installed: the active version is the other packs')
|
|
170
|
+
rows.push({module: name, a: active, p: pinned, case: active == null ? 'new' : 'same', place: active == null, recordAs: pinned, callers: [], question: null, othersAt: active});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// only what the store lacks at its pin is read
|
|
174
|
+
// a marker that cannot be read fails the add cleanly, never out of the lock
|
|
175
|
+
let toPlace;
|
|
176
|
+
try {
|
|
177
|
+
toPlace = rows.filter((r) => r.place || r.case === 'same').map((r) => r.module).filter((m) => !wholeAt(where, m, allow.pins[m]));
|
|
178
|
+
} catch (err) {
|
|
179
|
+
return fail(`${err.message}; nothing was added`);
|
|
180
|
+
}
|
|
181
|
+
// (a tarball read before the lock is not read or hashed again)
|
|
182
|
+
const loaded = loadTarballs(from, toPlace.filter((m) => preBytes[m] == null), allow.pins);
|
|
183
|
+
if (loaded.problems.length > 0) {
|
|
184
|
+
for (const p of loaded.problems) fail(p);
|
|
185
|
+
return fail('nothing was added');
|
|
186
|
+
}
|
|
187
|
+
const bytes = {...preBytes, ...loaded.bytes};
|
|
188
|
+
// each module as the pins describe it (#413 section 9.3; L5b), before
|
|
189
|
+
// anything is placed
|
|
190
|
+
// (at the version the table records each at: one kept installed at
|
|
191
|
+
// another version is not the pinned bytes, so not compared)
|
|
192
|
+
const recordAs = Object.fromEntries(rows.map((r) => [r.module, r.recordAs]));
|
|
193
|
+
// (calls resolve to what a start would load once the pack is added, by
|
|
194
|
+
// start's own rule: the Reviewer's high review of #98's round 2, 1 and 5)
|
|
195
|
+
const versionOf = (m) => (Object.prototype.hasOwnProperty.call(recordAs, m) ? recordAs[m] : allow.pins[m].version);
|
|
196
|
+
// (its withdrawn list as the write derives it from the release, never
|
|
197
|
+
// the record's present one; development pins as install takes them: the
|
|
198
|
+
// medium on round 2, 2 and 9)
|
|
199
|
+
const added = {...record, unreleased: eff.unreleased === true || (record != null && record.unreleased === true),
|
|
200
|
+
packs: {...((record && record.packs) || {}), [pack]: {modules: Object.fromEntries(spec.modules.map((m) => [m, versionOf(m)]))}}};
|
|
201
|
+
const afterAdd = {...added, withdrawn: require('./module-record').withdrawnOf(added, allow)};
|
|
202
|
+
const afterContext = require('./description-check').activeContext(afterAdd, allow);
|
|
203
|
+
const notDescribed = require('./description-check').descriptionRefusal(where, spec.modules, allow, bytes, versionOf,
|
|
204
|
+
afterContext, {live: new Set(Object.keys(afterContext))});
|
|
205
|
+
if (notDescribed != null) return fail(`${notDescribed}; nothing was added`);
|
|
206
|
+
try {
|
|
207
|
+
const inUse = plan.inUseFor(where, io);
|
|
208
|
+
for (const m of toPlace) placeModule(where, m, bytes[m], allow.pins[m], {inUse});
|
|
209
|
+
} catch (err) {
|
|
210
|
+
return fail(`${err.message}; nothing was added`);
|
|
211
|
+
}
|
|
212
|
+
const modules = Object.fromEntries(rows.map((r) => [r.module, r.recordAs]));
|
|
213
|
+
const shared = table.sharedOf(rows);
|
|
214
|
+
const held = {...(record.held || {})};
|
|
215
|
+
delete held[pack];
|
|
216
|
+
writeModulesRecord(where, {...record, packs: {...record.packs, [pack]: {from: plan.fromRelease(allow, eff), modules}}, held, unreleased: record.unreleased || eff.unreleased},
|
|
217
|
+
{roleOf: plan.roleFor(where), release: allow});
|
|
218
|
+
collectStore(where, {alive: io.alive, hostname: io.hostname});
|
|
219
|
+
if (done != null) done.added = true;
|
|
220
|
+
say(`added the pack "${pack}"${shared.length > 0 ? `; ${table.sharesText(shared)}` : ''}`);
|
|
221
|
+
// what the table changed, and how to go back (section 9.4)
|
|
222
|
+
for (const line of table.changedLines(rows, pack, where)) say(line);
|
|
223
|
+
if (record.unreleased || eff.unreleased) io.stderr.write(`ch-local: ${UNRELEASED_LINE}\n`);
|
|
224
|
+
return 0;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async function removePack({pack}, io) {
|
|
228
|
+
const where = layout(io.env, io.homedir);
|
|
229
|
+
return withLock(where, io, () => removePackLocked({pack, where}, io));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// The pack leaves the record, and each of its module versions no other pack
|
|
233
|
+
// records goes with collection, once no running start uses it and the
|
|
234
|
+
// rollback's kept record does not name it (#413 sections 9.5, 9.10).
|
|
235
|
+
async function removePackLocked({pack, where}, io) {
|
|
236
|
+
const say = (s) => io.stdout.write(s + '\n');
|
|
237
|
+
const got = recordOf(where, io);
|
|
238
|
+
if (got == null) return 1;
|
|
239
|
+
const {record} = got;
|
|
240
|
+
const release = releaseOf(io);
|
|
241
|
+
if (record != null && !own(record.packs, pack) && own(record.held, pack)) {
|
|
242
|
+
// held after a rollback: nothing of it is in this release's record
|
|
243
|
+
const held = {...record.held};
|
|
244
|
+
delete held[pack];
|
|
245
|
+
writeModulesRecord(where, {...record, held}, {roleOf: plan.roleFor(where), release});
|
|
246
|
+
collectStore(where, {alive: io.alive, hostname: io.hostname});
|
|
247
|
+
say(`removed the held pack "${pack}"; nothing of it was installed under this release`);
|
|
248
|
+
return 0;
|
|
249
|
+
}
|
|
250
|
+
if (record == null || !own(record.packs, pack)) { io.stderr.write(`ch-local: the pack "${pack}" is not installed\n`); return 1; }
|
|
251
|
+
const withdrawn = withdrawnNames(record, [{name: pack}], release).has(pack);
|
|
252
|
+
const others = Object.fromEntries(Object.entries(record.packs).filter(([name]) => name !== pack));
|
|
253
|
+
const stillRecorded = new Set(Object.values(others).flatMap((p) => Object.keys(p.modules)));
|
|
254
|
+
const own_ = Object.entries(record.packs[pack].modules).filter(([m]) => !stillRecorded.has(m));
|
|
255
|
+
// the active versions before and after (rule 2: the highest any pack
|
|
256
|
+
// records), for the way back (section 9.5); a removed module's stored
|
|
257
|
+
// credential, read before the record changes
|
|
258
|
+
const before = activeVersions(livePacks(record.packs, record.withdrawn), []);
|
|
259
|
+
const after = activeVersions(livePacks(others, record.withdrawn), []);
|
|
260
|
+
let storedFor = new Set();
|
|
261
|
+
try {
|
|
262
|
+
const read = require('./module-credentials').bindings(where, record, {platform: io.platform || process.platform});
|
|
263
|
+
if (read.bindings != null) storedFor = new Set(own_.map(([m]) => m).filter((m) => read.bindings.get(m) != null && read.bindings.get(m).size > 0));
|
|
264
|
+
} catch (err) { /* the store is read again by credentials; nothing said here */ }
|
|
265
|
+
writeModulesRecord(where, {...record, packs: others}, {roleOf: plan.roleFor(where), release});
|
|
266
|
+
// a withdrawn pack leaves the rollback's kept record too, so a rollback
|
|
267
|
+
// never brings back what the user removed (the deep review of #77); that
|
|
268
|
+
// record keeps its own derived fields, less this pack's
|
|
269
|
+
if (withdrawn) {
|
|
270
|
+
try {
|
|
271
|
+
const {readModulesRecord: readKept, writeRecordAsIs, derive} = require('./module-record');
|
|
272
|
+
const kept = readKept({modulesRecord: where.previousModulesRecord});
|
|
273
|
+
if (kept != null && own(kept.packs, pack)) {
|
|
274
|
+
const rest = Object.fromEntries(Object.entries(kept.packs).filter(([n]) => n !== pack));
|
|
275
|
+
const recorded = new Set(Object.values(rest).flatMap((p) => Object.keys(p.modules)));
|
|
276
|
+
const withdrawn = kept.withdrawn.filter((m) => recorded.has(m));
|
|
277
|
+
const modules = derive(rest, (m, v) => { const e = entryOf(kept, m); return e != null && e.version === v ? e.role : plan.roleFor(where)(m, v); }, withdrawn);
|
|
278
|
+
writeRecordAsIs(where.previousModulesRecord, {...kept, packs: rest, modules, withdrawn});
|
|
279
|
+
}
|
|
280
|
+
} catch (err) { /* no kept record, or one rollback refuses anyway */ }
|
|
281
|
+
}
|
|
282
|
+
const {kept} = collectStore(where, {alive: io.alive, hostname: io.hostname});
|
|
283
|
+
// why its own versions stay, if they do
|
|
284
|
+
const dirs = new Set(own_.map(([m, v]) => require('./store-paths').versionDir(where, m, v)));
|
|
285
|
+
const why = ((kept || []).find((k) => dirs.has(k.dir)) || {}).why;
|
|
286
|
+
say(`removed the ${withdrawn ? 'withdrawn ' : ''}pack "${pack}"${why === 'rollback' ? `; its files stay while \`${chLocal(where, 'rollback')}\` can return to the release that had it`
|
|
287
|
+
: why === 'running' ? '; its files go once no running client uses them'
|
|
288
|
+
: why != null && why !== 'current' ? `; its files were not removed (${why}): \`${chLocal(where, 'install')}\` or the next clean-up removes them` : ''}`);
|
|
289
|
+
// Between packs from different pins, the way back (section 9.5): a module
|
|
290
|
+
// this pack raised goes back to the highest the remaining packs record;
|
|
291
|
+
// one a remaining pack was installed with at the same version stays, and
|
|
292
|
+
// which pack is said. In a released home the pins decide, and a shared
|
|
293
|
+
// module is simply unchanged: nothing is said.
|
|
294
|
+
const mixed = table.fromOtherPins(record, null);
|
|
295
|
+
const liveOthers = livePacks(others, record.withdrawn);
|
|
296
|
+
if (mixed) {
|
|
297
|
+
for (const [m, v] of Object.entries(record.packs[pack].modules)) {
|
|
298
|
+
if (!stillRecorded.has(m) || before[m] == null || after[m] == null) continue;
|
|
299
|
+
if (compareVersions(after[m], before[m]) < 0) {
|
|
300
|
+
say(`put back ${short(m)} ${before[m]} -> ${after[m]} (it was updated when ${pack} was installed)`);
|
|
301
|
+
} else if (v === before[m]) {
|
|
302
|
+
// a live pack (a withdrawn one never loads)
|
|
303
|
+
const q = Object.entries(liveOthers).find(([, e]) => e.modules[m] === before[m]);
|
|
304
|
+
if (q != null) say(`${short(m)} stays at ${before[m]}: the pack ${q[0]} was installed with it`);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
// a module that left the record keeps its stored credential (section 9.5)
|
|
309
|
+
for (const m of storedFor) say(`the credential stored for ${short(m)} is kept: \`${chLocal(where, `credentials remove ${short(m)}`)}\` removes it`);
|
|
310
|
+
return 0;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// A scenario's tools: its listed actions (those with a description), by name.
|
|
314
|
+
function toolsOf(dir) {
|
|
315
|
+
let api;
|
|
316
|
+
try { api = JSON.parse(fs.readFileSync(path.join(dir, 'api.json'), 'utf8')); } catch (err) { return []; }
|
|
317
|
+
const services = api != null && api.device != null && api.device.serviceList != null && typeof api.device.serviceList === 'object' ? Object.values(api.device.serviceList) : [];
|
|
318
|
+
return services.flatMap((s) => (s != null && Array.isArray(s.actionList) ? s.actionList : []))
|
|
319
|
+
.filter((a) => a != null && typeof a.name === 'string' && typeof a.description === 'string' && a.description.trim() !== '')
|
|
320
|
+
.map((a) => a.name);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// `status` by module (#413 section 9.9; L1b-1): the modules first, each with
|
|
324
|
+
// what it is (on, with its tools; a part; or why it would not load, in the
|
|
325
|
+
// sentence a start says: lib/availability.js), its credential, and a running
|
|
326
|
+
// client's word on it (a module it stopped for good); then the packs as what
|
|
327
|
+
// they are, by their module count; then the held packs, as before.
|
|
328
|
+
// The settings as a start takes them, without writing anything: a file
|
|
329
|
+
// that cannot be used stops a start (and so is a problem here); an outside
|
|
330
|
+
// loosening the ceiling forbids is not applied; the values the ceiling
|
|
331
|
+
// bounds are bounded. -> {settings} | {problem}
|
|
332
|
+
function statusSettings(where, ceiling) {
|
|
333
|
+
const settings = readSettings(where);
|
|
334
|
+
if (settings.error != null) return {problem: `${settings.error}: no client starts until it is fixed (\`${chLocal(where, 'settings reset')}\` replaces every setting with its default, asking first if that loosens one)`};
|
|
335
|
+
const refused = forbiddenBy(ceiling);
|
|
336
|
+
for (const e of outsideEdits(where, settings)) {
|
|
337
|
+
// (as start's reportOutsideEdits: only a loosening is refused)
|
|
338
|
+
if (!e.loosened || refused(e.setting, e.new) == null) continue;
|
|
339
|
+
if (valueOf({values: {}}, e.setting) === e.old) delete settings.values[e.setting]; else settings.values[e.setting] = e.old;
|
|
340
|
+
}
|
|
341
|
+
const bounded = startUnderCeiling(settings, ceiling, {where});
|
|
342
|
+
if (bounded.problem != null) return {problem: bounded.problem.replace(/: not starting;/, ': no client starts;')};
|
|
343
|
+
return {settings: Object.assign({}, settings, {values: bounded.values})};
|
|
344
|
+
}
|
|
345
|
+
const OLDER = '\0older';
|
|
346
|
+
|
|
347
|
+
// A recorded UTC stamp as the user's local time with its offset, in ISO form
|
|
348
|
+
// (2026-11-21T02:00:00-08:00: business on #136); history.jsonl stays UTC.
|
|
349
|
+
// timeZone: an IANA name (the command's TZ), else this machine's. A stamp
|
|
350
|
+
// that isn't a time, or a zone Intl doesn't know: the stamp, cleaned.
|
|
351
|
+
function localIso(at, timeZone) {
|
|
352
|
+
const d = new Date(at);
|
|
353
|
+
if (Number.isNaN(d.getTime())) return terminalText(at, 40);
|
|
354
|
+
let parts;
|
|
355
|
+
try {
|
|
356
|
+
parts = Object.fromEntries(new Intl.DateTimeFormat('en-US', {timeZone: timeZone || undefined, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit',
|
|
357
|
+
second: '2-digit', hourCycle: 'h23', timeZoneName: 'longOffset'}).formatToParts(d).map((x) => [x.type, x.value]));
|
|
358
|
+
} catch (err) {
|
|
359
|
+
return terminalText(at, 40);
|
|
360
|
+
}
|
|
361
|
+
const offset = parts.timeZoneName === 'GMT' ? '+00:00' : String(parts.timeZoneName).replace('GMT', '');
|
|
362
|
+
return `${parts.year}-${parts.month}-${parts.day}T${parts.hour}:${parts.minute}:${parts.second}${offset}`;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// the shared runtime as status says it: serving, restarting, gave up (with
|
|
366
|
+
// failed.json's reason, as restart words it), can't be told, or not running
|
|
367
|
+
async function sharedState(where, io) {
|
|
368
|
+
const runDir = path.join(where.run, 'daemon');
|
|
369
|
+
const opts = {platform: io.platform, probePipe: io.probePipe || null, ...(typeof io.alive === 'function' ? {alive: io.alive} : {})};
|
|
370
|
+
let s;
|
|
371
|
+
// (a check that could not be made is said as that, naming its code --
|
|
372
|
+
// never blamed on daemon.json: the medium on the closing pass, 6)
|
|
373
|
+
try { s = await require('./daemon').daemonServing(where.home, opts); } catch (e) { return `can't be told (the check could not be made: ${e.code || 'failed'})`; }
|
|
374
|
+
if (s.serving && s.by === 'socket') return `serving (pid ${s.pid})`;
|
|
375
|
+
if (s.serving && s.by === 'pid') return `restarting (pid ${s.pid}; its socket does not answer yet)`;
|
|
376
|
+
if (s.serving) return `can't be told (${path.join(runDir, 'daemon.json')} can't be read)`;
|
|
377
|
+
const failed = require('./restart-command').readFailed(runDir);
|
|
378
|
+
if (failed != null) return `gave up (${failed}); the sessions run their own runtimes for now`;
|
|
379
|
+
return 'not running; the next session starts it';
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
async function status(_, io) {
|
|
383
|
+
const say = (s) => io.stdout.write(s + '\n');
|
|
384
|
+
const where = layout(io.env, io.homedir);
|
|
385
|
+
const got = recordOf(where, io);
|
|
386
|
+
if (got == null) return 1;
|
|
387
|
+
const {record} = got;
|
|
388
|
+
if (record == null) { say(`nothing is installed; run ${hintCommand(where, 'install --pack <name>', io.platform)}`); return 1; }
|
|
389
|
+
if (record.unreleased) io.stderr.write(`ch-local: ${UNRELEASED_LINE}\n`);
|
|
390
|
+
const versions = (record.runtime && record.runtime.versions) || {};
|
|
391
|
+
const installedSelf = versions['@countinghouse/ch-local'];
|
|
392
|
+
say(`ch-local ${installedSelf || '(unknown)'}, countinghouse ${versions.countinghouse || '(unknown)'}`);
|
|
393
|
+
// (which shim the shared runtime runs, as the record names it: F2)
|
|
394
|
+
// (as the record names it: a session still checks the file before it
|
|
395
|
+
// runs it, and says when it doesn't -- the medium on the round, 4)
|
|
396
|
+
say(record.shim != null ? `the shared runtime's shim, as recorded: ${record.shim.version}` : 'the shared runtime\'s shim: none recorded (each session runs its own runtime)');
|
|
397
|
+
// (where the shared runtime logs: the daemon's file, which the shim's
|
|
398
|
+
// discarded output never reaches -- C-daemon-log; a session on its own
|
|
399
|
+
// runtime logs to its client's MCP log)
|
|
400
|
+
if (record.shim != null) {
|
|
401
|
+
const log = path.join(where.run, 'daemon', 'runtime.log');
|
|
402
|
+
say(`the shared runtime's log: ${log}${fs.existsSync(log) ? '' : ' (none yet: it is made when the shared runtime first starts)'}`);
|
|
403
|
+
// (and how it is, from daemon.json and failed.json, so the shim's "run
|
|
404
|
+
// status to see why" is true -- the closing pass, L5)
|
|
405
|
+
say(`the shared runtime: ${await sharedState(where, io)}`);
|
|
406
|
+
}
|
|
407
|
+
// (a store file the runtime can't read as its own: one line each, naming
|
|
408
|
+
// it and what to do; lib/store-files.js)
|
|
409
|
+
for (const line of require('./store-files').storeLines(where.store, versions.countinghouse)) say(line);
|
|
410
|
+
// the live starts (as collection reads them): a module one stopped for
|
|
411
|
+
// good (module-stopped, section 7.3), and one still on another ch-local.
|
|
412
|
+
// None read when they cannot be: status still says the rest
|
|
413
|
+
const stoppedIn = new Map();
|
|
414
|
+
// (a module stopped in a running client comes back when that client's
|
|
415
|
+
// runtime restarts: the client's, or with the shared runtime \`restart\` --
|
|
416
|
+
// the reviewer's high on #147, L2)
|
|
417
|
+
const stopRestart = `restart that client, or with the shared runtime run \`${chLocal(where, 'restart')}\``;
|
|
418
|
+
const refusedIn = new Map(); // own modules the running starts' runtimes refused: each one's refusals (F9)
|
|
419
|
+
const otherSelf = new Set();
|
|
420
|
+
const liveNow = [];
|
|
421
|
+
const liveHere = []; // this machine's
|
|
422
|
+
// an own module a running start has not loaded, as add-module's line says
|
|
423
|
+
// it (lib/own-applied.js): refused by its runtime, its sandbox, or taken up
|
|
424
|
+
// only when it restarts
|
|
425
|
+
const notLoaded = (m, e) => require('./own-applied').notLoadedOf(liveNow, liveHere, m, e);
|
|
426
|
+
try {
|
|
427
|
+
for (const r of liveRuns(where, {alive: io.alive, hostname: io.hostname})) {
|
|
428
|
+
liveNow.push(r);
|
|
429
|
+
if (onThisMachine(r, io.hostname)) liveHere.push(r);
|
|
430
|
+
for (const [m, code] of Object.entries(r.stopped || {})) if (!stoppedIn.has(m)) stoppedIn.set(m, code);
|
|
431
|
+
for (const [m, x] of Object.entries(r.refused || {})) if (x != null && typeof x.code === 'string') refusedIn.set(m, [...(refusedIn.get(m) || []), x]);
|
|
432
|
+
// a run with no chLocal was started by a ch-local before L1b-1 (an
|
|
433
|
+
// older one); null: one not run from the home (a checkout), unknown
|
|
434
|
+
if (r.chLocal === undefined) otherSelf.add(OLDER);
|
|
435
|
+
else if (typeof r.chLocal === 'string' && installedSelf != null && r.chLocal !== installedSelf) otherSelf.add(r.chLocal);
|
|
436
|
+
}
|
|
437
|
+
} catch (err) { /* unknown: nothing said about running clients */ }
|
|
438
|
+
// (a shared runtime restarts with `ch-local restart`, never a client's: A5)
|
|
439
|
+
const restartIt = `restart it, or with the shared runtime run \`${chLocal(where, 'restart')}\``;
|
|
440
|
+
for (const v of otherSelf) say(v === OLDER ? `a running client is still on an older ch-local; ${restartIt}` : `a running client is still on ch-local ${v}; ${restartIt}`);
|
|
441
|
+
// the last automatic upgrade notice, as it was told (applied with the way
|
|
442
|
+
// back, paused, failed): a session that opened after it was told never
|
|
443
|
+
// heard it (a notice reaches only the sessions open then -- the reviewer
|
|
444
|
+
// on #136). A notice, not the last check: a quiet outcome (up to date,
|
|
445
|
+
// declined) records nothing (the closing pass, L1)
|
|
446
|
+
const last = require('./history').lastHistory(where, (e) => e.by === 'auto-upgrade' && e.change === 'upgrade check' && typeof e.notice === 'string' && typeof e.at === 'string');
|
|
447
|
+
if (last != null) say(`the last automatic upgrade notice (${localIso(last.at, io.env != null ? io.env.TZ : undefined)}): ${terminalText(last.notice, 300)}`);
|
|
448
|
+
// each installed module's credential, from the store (#413 section 6.7)
|
|
449
|
+
const read = require('./module-credentials').bindings(where, record, {platform: io.platform || process.platform});
|
|
450
|
+
if (read.problem != null) say(`the stored credentials are not used (${read.problem})`);
|
|
451
|
+
// what a start decides, by the same rules (section 5.2): the settings as
|
|
452
|
+
// a start takes them (statusSettings), the ceiling now, and each
|
|
453
|
+
// credential's state, the gh login asked only when a binding uses it, as
|
|
454
|
+
// a start asks it
|
|
455
|
+
const ceiling = ceilingFor(where, {platform: io.platform || process.platform, env: io.env});
|
|
456
|
+
const taken = statusSettings(where, ceiling);
|
|
457
|
+
if (taken.problem != null) {
|
|
458
|
+
// a start would not run: nothing would load, and nothing is guessed
|
|
459
|
+
say(taken.problem);
|
|
460
|
+
for (const m of Object.keys(record.modules || {})) say(` ${short(m)} ${record.modules[m].version}: not loaded (no client starts until that is fixed)`);
|
|
461
|
+
return 0;
|
|
462
|
+
}
|
|
463
|
+
const mc = require('./module-credentials');
|
|
464
|
+
const decls = mc.declarations(where, record);
|
|
465
|
+
const usesGh = read.bindings != null && [...decls].some(([m, d]) => {
|
|
466
|
+
const vars = read.bindings.get(m);
|
|
467
|
+
const b = vars != null && d.variable != null ? vars.get(d.variable) : null;
|
|
468
|
+
// (as forStart asks it: only a gh binding gh could serve)
|
|
469
|
+
return b != null && b.source === 'gh' && b.origin === d.origin && d.origin === mc.GH_ORIGIN;
|
|
470
|
+
});
|
|
471
|
+
const gh = usesGh ? await ghToken(io, where.home) : null;
|
|
472
|
+
const states = new Map([...decls].map(([m, d]) => [m, mc.stateOf(m, d, read, gh, where)]));
|
|
473
|
+
// (the record too: a module's enabled.* is read beside pack.<name>, off
|
|
474
|
+
// winning, as start reads it: L3)
|
|
475
|
+
const seams = Object.assign(require('./module-seams').moduleSeams({settings: taken.settings, ceiling, record, where}), {credential: mc.credentialSeam(states)});
|
|
476
|
+
// whose record this is, said as a start says it (lib/packs.js)
|
|
477
|
+
const whose = recordRelease(record, io, where);
|
|
478
|
+
if (whose.state === 'stale') say(staleLine(whose.installed, whose.how, where));
|
|
479
|
+
if (whose.state === 'other') say(installLine(whose.ours, where, record, whose.fromHome));
|
|
480
|
+
// the user's own modules (B-own-add), as a start reads them: one that
|
|
481
|
+
// can't be read is said, and the packs listed still; the sandbox as the
|
|
482
|
+
// settings set it (a client passing its own is not known here)
|
|
483
|
+
let ownRecord = null;
|
|
484
|
+
try { ownRecord = readOwnRecord(where); } catch (err) { say(`your own modules could not be listed: ${err.message}`); }
|
|
485
|
+
const ownSandboxOk = enforceAvailable(where, io.platform || process.platform) && valueOf(taken.settings, 'moduleSandbox') !== 'audit';
|
|
486
|
+
const av = availability(where, record, {release: releaseOf(io), pins: whose.state !== 'stale', seams, own: {record: ownRecord, sandboxOk: ownSandboxOk}});
|
|
487
|
+
const dirOf = new Map(av.units.map((u) => [u.name, u.dir]));
|
|
488
|
+
// a module's credential as it is stored, whatever the module's state (a
|
|
489
|
+
// module turned off still has its binding)
|
|
490
|
+
const credentialOf = (m) => {
|
|
491
|
+
const st = states.get(m);
|
|
492
|
+
const b = st != null && st.binding != null ? st.binding : null;
|
|
493
|
+
if (b == null || st.state === 'elsewhere') return null;
|
|
494
|
+
return `credential ${b.variable} -> ${b.origin} (${b.source === 'gh' ? 'gh login' : 'stored'})`;
|
|
495
|
+
};
|
|
496
|
+
// a start's reason, said of the module named on its line: "it is turned
|
|
497
|
+
// off ..." reads "turned off ...", "it calls ..." reads "calls ..."
|
|
498
|
+
const why = (reason) => String(reason).replace(/^it (is )?/, '');
|
|
499
|
+
const rows = Object.keys(record.modules || {}).map((m) => {
|
|
500
|
+
const v = record.modules[m].version;
|
|
501
|
+
const s = av.states.get(m) || {ok: true};
|
|
502
|
+
const parts = [];
|
|
503
|
+
if (!av.tops.has(m)) {
|
|
504
|
+
parts.push(s.ok ? 'part' : `part; not available: ${why(s.reason)}`);
|
|
505
|
+
} else if (!s.ok) {
|
|
506
|
+
parts.push(`not loaded: ${why(s.reason)}`);
|
|
507
|
+
} else if (stoppedIn.has(m)) {
|
|
508
|
+
parts.push(`on; stopped in a running client (${stoppedIn.get(m)}): ${stopRestart}`);
|
|
509
|
+
} else {
|
|
510
|
+
const tools = toolsOf(dirOf.get(m) || versionDir(where, m, v));
|
|
511
|
+
parts.push(`on; tools: ${tools.length > 0 ? tools.join(', ') : `(none found: run \`${chLocal(where, 'install')}\` again)`}`);
|
|
512
|
+
}
|
|
513
|
+
const c = credentialOf(m);
|
|
514
|
+
if (c != null) parts.push(c);
|
|
515
|
+
return [`${short(m)} ${v}`, parts.join('; ')];
|
|
516
|
+
});
|
|
517
|
+
// each own module (§5 line 11): by its code's short hash; on with its
|
|
518
|
+
// tools, or why a start would not load it
|
|
519
|
+
const ownRows = Object.entries(ownRecord != null ? ownRecord.modules : {}).map(([m, e]) => {
|
|
520
|
+
const label = `${short(m)} (own, unpinned, ${e.tree.slice(0, 12)})`;
|
|
521
|
+
const held = av.shadowed.get(m) || av.unavailable.get(m);
|
|
522
|
+
// (never "serving the code you confirmed": a worker that starts again
|
|
523
|
+
// reads the copy as it is now)
|
|
524
|
+
if (held != null && require('./own-applied').servedBy(liveHere, m, e)) return [label, `still on in the running runtime; ${held.reason}`];
|
|
525
|
+
if (held != null) return [label, `not loaded: ${why(held.reason)}`];
|
|
526
|
+
// (of the code it refused only: one added again since is not said so)
|
|
527
|
+
const there = notLoaded(m, e);
|
|
528
|
+
const refusedNow = (refusedIn.get(m) || []).find((x) => x.tree == null || x.tree === e.tree) || (there != null && there.code != null ? there : null);
|
|
529
|
+
if (refusedNow != null) return [label, `not loaded: this release's runtime refuses it (${refusedNow.code}); fix it and add it again with \`${chLocal(where, `add-module ${folderArg(e.from, io.platform)}`)}\`, or remove it with \`${chLocal(where, `remove-module ${m}`)}\``];
|
|
530
|
+
if (stoppedIn.has(m)) return [label, `on; stopped in a running client (${stoppedIn.get(m)}): ${stopRestart}`];
|
|
531
|
+
if (there != null && there.sandbox === true) return [label, `not loaded: ${require('./availability').SANDBOX_LINE}`];
|
|
532
|
+
if (there != null && there.restart === true) {
|
|
533
|
+
const when = there.shared ? `taken up when the runtime restarts: \`${chLocal(where, 'restart', io.platform)}\`` : 'taken up when your client restarts';
|
|
534
|
+
return [label, there.earlier === true ? `the earlier code is still on; this one is ${when}` : `on; ${when}`];
|
|
535
|
+
}
|
|
536
|
+
const tools = toolsOf(copyDir(where, m, e.tree));
|
|
537
|
+
return [label, `on; tools: ${tools.length > 0 ? tools.join(', ') : '(none described)'}`];
|
|
538
|
+
});
|
|
539
|
+
const packs = installedPacks(where, record, io);
|
|
540
|
+
const gone = withdrawnNames(record, packs, releaseOf(io));
|
|
541
|
+
const width = Math.max(0, ...rows.map(([l]) => l.length), ...ownRows.map(([l]) => l.length), ...packs.map((p) => p.name.length)) + 3;
|
|
542
|
+
if (rows.length > 0) {
|
|
543
|
+
say('modules:');
|
|
544
|
+
for (const [l, r] of rows) say(` ${l.padEnd(width)}${r}`);
|
|
545
|
+
}
|
|
546
|
+
if (packs.length === 0 && Object.keys(record.held || {}).length === 0) say(`no pack is installed; add one with \`${chLocal(where, 'install --pack <name>')}\``);
|
|
547
|
+
if (packs.length > 0) {
|
|
548
|
+
say('packs:');
|
|
549
|
+
for (const p of packs) {
|
|
550
|
+
if (gone.has(p.name)) { say(` ${withdrawnStatusLine(p.name, where)}`); continue; }
|
|
551
|
+
const n = Object.keys((record.packs[p.name] && record.packs[p.name].modules) || {}).length;
|
|
552
|
+
say(` ${p.name.padEnd(width)}${n} module${n === 1 ? '' : 's'}`);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
if (ownRows.length > 0) {
|
|
556
|
+
say('own modules:');
|
|
557
|
+
for (const [l, r] of ownRows) say(` ${l.padEnd(width)}${r}`);
|
|
558
|
+
}
|
|
559
|
+
const running = releaseOf(io);
|
|
560
|
+
for (const [name, h] of Object.entries(record.held || {})) {
|
|
561
|
+
// listed by this release: add-pack brings it back (the medium review of
|
|
562
|
+
// L1a-2, 3); otherwise it needs the release it was installed under
|
|
563
|
+
if (running != null && running.packs != null && own(running.packs, name)) { say(require('./packs').relistedStatusLine(name, where)); continue; }
|
|
564
|
+
const under = h.from != null && typeof h.from.release === 'string' ? h.from.release : 'another release';
|
|
565
|
+
say(`${name}: installed under ch-local ${under}; this release does not have it, so it is not loaded`);
|
|
566
|
+
}
|
|
567
|
+
return 0;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
module.exports = {addPack, removePack, status, toolsOf};
|