@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,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// The GitHub token a start gives its runtime (maintainer's decision,
|
|
3
|
+
// 2026-11-13): asked of the GitHub CLI (`gh auth token`) at start, held in
|
|
4
|
+
// memory, and handed to the
|
|
5
|
+
// runtime in its environment only, never written to a file, a client's
|
|
6
|
+
// config or a line of output. gh's own output is never repeated: on a failure
|
|
7
|
+
// it could carry anything.
|
|
8
|
+
//
|
|
9
|
+
// gh answers GH_TOKEN, GITHUB_TOKEN and the enterprise variables from its
|
|
10
|
+
// environment before its own login, so it runs without them: what it gives is
|
|
11
|
+
// its login's token, never a plaintext value passed off as gh's. A gh that
|
|
12
|
+
// does not answer within GH_TIMEOUT_MS is killed.
|
|
13
|
+
const GH_TIMEOUT_MS = 10000;
|
|
14
|
+
const GH_ENV_TOKENS = ['GH_TOKEN', 'GITHUB_TOKEN', 'GH_ENTERPRISE_TOKEN', 'GITHUB_ENTERPRISE_TOKEN'];
|
|
15
|
+
// A token as gh prints one: letters, digits and underscores.
|
|
16
|
+
const TOKEN = /^[A-Za-z0-9_]{8,255}$/;
|
|
17
|
+
|
|
18
|
+
// io -> {token} or {why}: why gh gave none, in words for the user.
|
|
19
|
+
// home: gh runs there, never in the client's directory (on Windows the
|
|
20
|
+
// search for a program looks in the current directory first)
|
|
21
|
+
async function ghToken(io, home) {
|
|
22
|
+
// a home another user could change gets no token (the reviewer's Fable
|
|
23
|
+
// high on #126, F1)
|
|
24
|
+
if (home != null) {
|
|
25
|
+
const open = require('./home').openHomeLine(home);
|
|
26
|
+
if (open != null) return {why: open};
|
|
27
|
+
}
|
|
28
|
+
const env = {...io.env};
|
|
29
|
+
// (Windows looks for a program in the current folder first: gh runs from
|
|
30
|
+
// the Windows system folder, never the home, where a gh.exe could be put)
|
|
31
|
+
let cwd = home;
|
|
32
|
+
if ((io.platform || process.platform) === 'win32') {
|
|
33
|
+
// (a system folder that can't be named is a reason, never a throw: the
|
|
34
|
+
// medium on #126's round 2)
|
|
35
|
+
try { cwd = require('path').win32.join(require('./win-acl').windowsDir(), 'System32'); } catch (err) { return {why: `the Windows system folder could not be found (${err.message}), so gh was not run`}; }
|
|
36
|
+
}
|
|
37
|
+
for (const v of GH_ENV_TOKENS) delete env[v];
|
|
38
|
+
let timer = null;
|
|
39
|
+
const late = new Promise((resolve) => { timer = setTimeout(() => resolve('timeout'), GH_TIMEOUT_MS + 1000); });
|
|
40
|
+
let r;
|
|
41
|
+
try {
|
|
42
|
+
r = await Promise.race([io.exec('gh', ['auth', 'token', '--hostname', 'github.com'], {env, timeout: GH_TIMEOUT_MS, ...(cwd != null ? {cwd} : {})}), late]);
|
|
43
|
+
} catch (err) {
|
|
44
|
+
r = {status: null};
|
|
45
|
+
} finally {
|
|
46
|
+
clearTimeout(timer);
|
|
47
|
+
}
|
|
48
|
+
if (r === 'timeout') return {why: `gh did not answer within ${GH_TIMEOUT_MS / 1000} s`};
|
|
49
|
+
if (r == null || r.status === null) {
|
|
50
|
+
return {why: 'gh, the GitHub CLI, was not found or did not answer (a client started from the dock or the Start menu may not see the PATH your shell sets)'};
|
|
51
|
+
}
|
|
52
|
+
const token = String(r.stdout || '').trim();
|
|
53
|
+
if (r.status !== 0 || !TOKEN.test(token)) return {why: 'gh is not logged in to github.com'};
|
|
54
|
+
return {token};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
module.exports = {ghToken, GH_TIMEOUT_MS, GH_ENV_TOKENS};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// The re-exec handoff's two ends (C3b; #236 section 6, "Upgrade"). The table
|
|
3
|
+
// goes on the new daemon's fd 3, never in its argv or environment, and the
|
|
4
|
+
// secret is never in it (lib/daemon.js encodeHandoff).
|
|
5
|
+
//
|
|
6
|
+
// spawnDaemon(home, args, {handoff, env, node}): runs `<node>
|
|
7
|
+
// <home>/bin/ch-local.js <args>` with its cwd the home, in its own process
|
|
8
|
+
// group (detached), stdio on null, and fd 3 a pipe that carries the bytes
|
|
9
|
+
// and then closes. Its environment is shim.json's allowlist of `env`, as the
|
|
10
|
+
// shim gives a daemon. -> whether it started.
|
|
11
|
+
//
|
|
12
|
+
// readHandoff(fd = 3, {max, ms}): fd 3 read whole -> a Buffer, or null for no
|
|
13
|
+
// pipe, an error, more than `max` bytes, or nothing whole within `ms`.
|
|
14
|
+
const fs = require('node:fs');
|
|
15
|
+
const path = require('node:path');
|
|
16
|
+
const {spawn} = require('node:child_process');
|
|
17
|
+
const {allowedEnv} = require('./shim-config');
|
|
18
|
+
|
|
19
|
+
const MAX = 32 * 1024 * 1024 + 4;
|
|
20
|
+
const READ_MS = 5000;
|
|
21
|
+
|
|
22
|
+
function spawnDaemon(home, args, {handoff, env = process.env, node = process.execPath} = {}) {
|
|
23
|
+
try {
|
|
24
|
+
const child = spawn(node, [path.join(home, 'bin', 'ch-local.js'), ...args], {
|
|
25
|
+
cwd: home, detached: true, windowsHide: true, env: allowedEnv(env), stdio: ['ignore', 'ignore', 'ignore', 'pipe']
|
|
26
|
+
});
|
|
27
|
+
child.on('error', () => {});
|
|
28
|
+
child.stdio[3].on('error', () => {});
|
|
29
|
+
child.stdio[3].end(handoff);
|
|
30
|
+
child.unref();
|
|
31
|
+
return true;
|
|
32
|
+
} catch (e) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function readHandoff(fd = 3, {max = MAX, ms = READ_MS} = {}) {
|
|
38
|
+
return new Promise((resolve) => {
|
|
39
|
+
let done = false;
|
|
40
|
+
const chunks = [];
|
|
41
|
+
let size = 0;
|
|
42
|
+
let stream = null;
|
|
43
|
+
// resolved once the stream (and fd 3) has closed, not before its
|
|
44
|
+
// asynchronous close (the review of #39)
|
|
45
|
+
const finish = (v) => {
|
|
46
|
+
if (done) return;
|
|
47
|
+
done = true;
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
if (stream == null || stream.closed) return resolve(v);
|
|
50
|
+
stream.once('close', () => resolve(v));
|
|
51
|
+
stream.destroy();
|
|
52
|
+
return undefined;
|
|
53
|
+
};
|
|
54
|
+
const timer = setTimeout(() => finish(null), ms);
|
|
55
|
+
try {
|
|
56
|
+
fs.fstatSync(fd);
|
|
57
|
+
stream = fs.createReadStream(null, {fd, autoClose: true});
|
|
58
|
+
} catch (e) {
|
|
59
|
+
return finish(null);
|
|
60
|
+
}
|
|
61
|
+
stream.on('data', (d) => {
|
|
62
|
+
size += d.length;
|
|
63
|
+
if (size > max) return finish(null);
|
|
64
|
+
chunks.push(d);
|
|
65
|
+
return undefined;
|
|
66
|
+
});
|
|
67
|
+
stream.on('end', () => finish(Buffer.concat(chunks)));
|
|
68
|
+
stream.on('error', () => finish(null));
|
|
69
|
+
return undefined;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = {spawnDaemon, readHandoff, MAX};
|
package/lib/held-back.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// The modules this start holds back, and why, for the runtime's
|
|
3
|
+
// countinghouse_overview (countinghouse #490, --heldBackFile; A-firstrun d1).
|
|
4
|
+
// Written by start before the runtime starts, and by the applier (lib/in-place.js)
|
|
5
|
+
// whenever the set changes, then re-read by the runtime on
|
|
6
|
+
// {type: 'reread', what: 'held-back'}.
|
|
7
|
+
//
|
|
8
|
+
// The file, in start's private run directory, private itself (the runtime
|
|
9
|
+
// uses it only as a regular file under one name, this user's, 0600 or a
|
|
10
|
+
// private ACL; lib/private-write.js):
|
|
11
|
+
// {"v": 1, "modules": [{"name", "reason", "root"?, "via"?}], "launcher"?}
|
|
12
|
+
// - name: a top-level module's package name;
|
|
13
|
+
// - reason: availability's kind (credential, off, ceiling, missing, pin,
|
|
14
|
+
// withdrawn or calls; an own module's changed, sandbox or collision), or
|
|
15
|
+
// the applier's: stopped or restart, or refused (an own module this
|
|
16
|
+
// release's runtime refuses at its start, with code: the runtime's code,
|
|
17
|
+
// [A-Z][A-Z0-9_]{0,63});
|
|
18
|
+
// - root and via, on calls only, together: the kind at the bottom of the
|
|
19
|
+
// chain (or not-installed) and the module there (or, not installed, the
|
|
20
|
+
// name called); via alone on a collision: the module that has the own
|
|
21
|
+
// module's name (countinghouse #499's held-back.js);
|
|
22
|
+
// - launcher: the kernel's real path of <home>/bin/ch-local.js, so the
|
|
23
|
+
// overview names a command that runs as printed; absent when there is none.
|
|
24
|
+
// Package names and reason classes only: a module that lacks its credential
|
|
25
|
+
// is said as that (reason credential), which is the point; never a
|
|
26
|
+
// credential's value, its variable, the address it goes to, or a client's
|
|
27
|
+
// environment.
|
|
28
|
+
const fs = require('node:fs');
|
|
29
|
+
const path = require('node:path');
|
|
30
|
+
const {writePrivate} = require('./private-write');
|
|
31
|
+
|
|
32
|
+
const FILE = 'held-back.json';
|
|
33
|
+
const MAX = 256;
|
|
34
|
+
// (stopped: the runtime stopped it, kept out until its version changes;
|
|
35
|
+
// restart: wanted and available, but not loaded in place -- a clash, a
|
|
36
|
+
// refused load, or another release's record or runtime -- so the client's
|
|
37
|
+
// restart loads it. Both are reasons, never roots: #490 round 2)
|
|
38
|
+
// (changed, sandbox, collision: an own module's, never roots -- B-own-add,
|
|
39
|
+
// as countinghouse #499 reads them)
|
|
40
|
+
// (refused: an own module this release's runtime refuses to load, with the
|
|
41
|
+
// runtime's code -- the feature audit, F9, as countinghouse #525 reads it;
|
|
42
|
+
// one whose code can't be named is said as stopped)
|
|
43
|
+
// (gone: an own module's copy not there at all -- E10, countinghouse #534,
|
|
44
|
+
// c313b561; scripts/describe-release.js --check refuses a release whose
|
|
45
|
+
// runtime lacks any reason here)
|
|
46
|
+
const REASONS = new Set(['credential', 'off', 'ceiling', 'missing', 'pin', 'withdrawn', 'calls', 'stopped', 'restart', 'changed', 'gone', 'sandbox', 'collision', 'refused']);
|
|
47
|
+
const CODE = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
48
|
+
const ROOTS = new Set(['credential', 'off', 'ceiling', 'missing', 'pin', 'withdrawn', 'not-installed']);
|
|
49
|
+
// npm's name rule, as the runtime checks it: lower case, an optional scope,
|
|
50
|
+
// never starting with - or ~ (#490), at most 214 characters
|
|
51
|
+
const NAME = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._~-]*$/;
|
|
52
|
+
const named = (n) => typeof n === 'string' && n.length <= 214 && NAME.test(n);
|
|
53
|
+
// a callee a module declares but nothing installed: #490's isCalleeName (a
|
|
54
|
+
// call address's module part: 1 to 64 characters, no / or ., no control
|
|
55
|
+
// character). Anything else would make the runtime refuse the whole file
|
|
56
|
+
// (the reviewer's high on #106, 3), so the entry is said as calls alone.
|
|
57
|
+
const isCalleeName = (n) => typeof n === 'string' && n.length >= 1 && n.length <= 64 && !/[/.\u0000-\u001f\u007f]/.test(n);
|
|
58
|
+
// the runtime reads at most this much (#490 MAX_FILE_BYTES)
|
|
59
|
+
const MAX_BYTES = 64 * 1024;
|
|
60
|
+
|
|
61
|
+
// The file's text for what is held back: a Map of top-level module ->
|
|
62
|
+
// {kind, root, via} (availability's unavailable, or the applier's own view of
|
|
63
|
+
// what ended up loaded). Entries stop before the text would pass MAX_BYTES
|
|
64
|
+
// (the reviewer's high on #106, 7).
|
|
65
|
+
function contentOf(where, held, platform = process.platform) {
|
|
66
|
+
const modules = [];
|
|
67
|
+
const doc = {v: 1, modules};
|
|
68
|
+
const launcher = require('./home').safeLauncher(where, platform);
|
|
69
|
+
if (launcher != null) doc.launcher = launcher;
|
|
70
|
+
// (a running count: the empty document's bytes, then each entry's and its
|
|
71
|
+
// comma; the medium on #106's round 1, 9)
|
|
72
|
+
let size = Buffer.byteLength(`${JSON.stringify(doc)}\n`);
|
|
73
|
+
for (const [name, u] of held) {
|
|
74
|
+
if (modules.length >= MAX) break;
|
|
75
|
+
if (!named(name) || !REASONS.has(u.kind)) continue;
|
|
76
|
+
const entry = {name, reason: u.kind};
|
|
77
|
+
if (u.kind === 'refused') {
|
|
78
|
+
if (typeof u.code === 'string' && CODE.test(u.code)) entry.code = u.code;
|
|
79
|
+
else entry.reason = 'stopped';
|
|
80
|
+
}
|
|
81
|
+
if (u.kind === 'calls') {
|
|
82
|
+
const root = u.root === 'not installed' ? 'not-installed' : u.root;
|
|
83
|
+
const viaOk = root === 'not-installed' ? isCalleeName(u.via) : named(u.via);
|
|
84
|
+
// (both or neither: a chain it can't name is said as calls alone)
|
|
85
|
+
if (ROOTS.has(root) && viaOk) Object.assign(entry, {root, via: u.via});
|
|
86
|
+
}
|
|
87
|
+
// a collision comes with the module that has the name, or is not said
|
|
88
|
+
// (the runtime refuses one without it)
|
|
89
|
+
if (u.kind === 'collision') {
|
|
90
|
+
if (!named(u.via)) continue;
|
|
91
|
+
entry.via = u.via;
|
|
92
|
+
}
|
|
93
|
+
const bytes = Buffer.byteLength(JSON.stringify(entry)) + (modules.length > 0 ? 1 : 0);
|
|
94
|
+
if (size + bytes > MAX_BYTES) break;
|
|
95
|
+
size += bytes;
|
|
96
|
+
modules.push(entry);
|
|
97
|
+
}
|
|
98
|
+
return `${JSON.stringify(doc)}\n`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Written whole into the run directory -> its path. The file is born
|
|
102
|
+
// private (writePrivate: 0600, or on Windows an owner-only protected DACL
|
|
103
|
+
// set as it is created). Start's run directory is made in <home>/run, which
|
|
104
|
+
// is private once the daemon has made it (its DACL then flows to each run
|
|
105
|
+
// directory); until then, as on a home without a daemon, it keeps the
|
|
106
|
+
// home's ACL, so on a home other accounts can write, one could swap the file
|
|
107
|
+
// between writes:
|
|
108
|
+
// the runtime then refuses it (not this user's own), and the overview only
|
|
109
|
+
// loses its reasons, never shows another's (A-heldback-win, the reviewer
|
|
110
|
+
// 11-20: not worth a PowerShell call on every Windows start).
|
|
111
|
+
function write(runDir, text, opts) {
|
|
112
|
+
writePrivate(runDir, FILE, text, opts || undefined);
|
|
113
|
+
return path.join(runDir, FILE);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
module.exports = {contentOf, write, FILE, REASONS};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// A line read from a terminal with nothing echoed (a credential typed or
|
|
3
|
+
// pasted at `ch-local credentials add`). The terminal is put in raw mode
|
|
4
|
+
// before the prompt is shown (so nothing typed early is echoed either), and
|
|
5
|
+
// back as it was whatever happens. Enter (or a pasted line's CR, LF or CRLF)
|
|
6
|
+
// ends it, so a trailing line ending is never part of the value; Ctrl-C or
|
|
7
|
+
// Ctrl-D aborts (ABORTED), as does the input ending, closing or failing (a
|
|
8
|
+
// terminal gone mid-prompt never leaves this waiting in raw mode); backspace
|
|
9
|
+
// takes back one character. Over MAX_CHARS is refused (TOO_LONG). Nothing
|
|
10
|
+
// read is ever written anywhere.
|
|
11
|
+
const MAX_CHARS = 4096;
|
|
12
|
+
|
|
13
|
+
// stdin: a TTY stream with setRawMode; stderr: where the prompt goes.
|
|
14
|
+
// -> Promise of the line
|
|
15
|
+
function readHidden(prompt, {stdin = process.stdin, stderr = process.stderr} = {}) {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
let value = '';
|
|
18
|
+
let settled = false;
|
|
19
|
+
const wasRaw = stdin.isRaw === true;
|
|
20
|
+
const failure = (code, message) => Object.assign(new Error(message), {code});
|
|
21
|
+
const finish = (err, v) => {
|
|
22
|
+
if (settled) return;
|
|
23
|
+
settled = true;
|
|
24
|
+
stdin.removeListener('data', onData);
|
|
25
|
+
stdin.removeListener('end', onEnd);
|
|
26
|
+
stdin.removeListener('close', onEnd);
|
|
27
|
+
stdin.removeListener('error', onEnd);
|
|
28
|
+
// a late error (the terminal gone after the answer) is no one's to
|
|
29
|
+
// throw: kept off the process
|
|
30
|
+
stdin.on('error', () => {});
|
|
31
|
+
try { stdin.setRawMode(wasRaw); } catch (e) { /* the terminal is gone */ }
|
|
32
|
+
if (typeof stdin.pause === 'function') stdin.pause();
|
|
33
|
+
try { stderr.write('\n'); } catch (e) { /* gone too */ }
|
|
34
|
+
if (err != null) reject(err); else resolve(v);
|
|
35
|
+
};
|
|
36
|
+
const onEnd = () => finish(failure('ABORTED', 'the input ended'));
|
|
37
|
+
const onData = (chunk) => {
|
|
38
|
+
for (const ch of String(chunk)) {
|
|
39
|
+
if (ch === '\u0003' || ch === '\u0004') return finish(failure('ABORTED', 'nothing was entered'));
|
|
40
|
+
if (ch === '\r' || ch === '\n') return finish(null, value);
|
|
41
|
+
if (ch === '\u007f' || ch === '\b') { value = Array.from(value).slice(0, -1).join(''); continue; }
|
|
42
|
+
value += ch;
|
|
43
|
+
if (value.length > MAX_CHARS) return finish(failure('TOO_LONG', `more than ${MAX_CHARS} characters`));
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
};
|
|
47
|
+
try {
|
|
48
|
+
stdin.setRawMode(true);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
settled = true;
|
|
51
|
+
reject(failure('NO_TERMINAL', 'the input is not a terminal'));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (typeof stdin.setEncoding === 'function') stdin.setEncoding('utf8');
|
|
55
|
+
stdin.on('data', onData);
|
|
56
|
+
stdin.on('end', onEnd);
|
|
57
|
+
stdin.on('close', onEnd);
|
|
58
|
+
stdin.on('error', onEnd);
|
|
59
|
+
stderr.write(prompt);
|
|
60
|
+
if (typeof stdin.resume === 'function') stdin.resume();
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = {readHidden, MAX_CHARS};
|
package/lib/history.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// <home>/history.jsonl (packs in place, part 2): one line per change to the
|
|
3
|
+
// packs or the settings, by whoever made it (start, cli, auto-upgrade, the
|
|
4
|
+
// settings tool), appended, never rewritten, so several writers never race.
|
|
5
|
+
// Never a value of a credential.
|
|
6
|
+
const fs = require('node:fs');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
|
|
9
|
+
// entry: {by, ...what changed}; host and pid say which start, when one did.
|
|
10
|
+
// strict: a failed append is answered false, for a caller that makes no
|
|
11
|
+
// change it cannot record. -> true when appended.
|
|
12
|
+
function appendHistory(where, entry, {host = null, pid = null, now = Date.now(), strict = false} = {}) {
|
|
13
|
+
const line = {at: new Date(now).toISOString(), ...(host != null ? {host} : {}), ...(pid != null ? {pid} : {}), ...entry};
|
|
14
|
+
try {
|
|
15
|
+
fs.appendFileSync(path.join(where.home, 'history.jsonl'), JSON.stringify(line) + '\n');
|
|
16
|
+
return true;
|
|
17
|
+
} catch (err) {
|
|
18
|
+
if (strict) return false;
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// The newest entry `pick` takes, from the file's last `max` bytes (a long
|
|
24
|
+
// history is never read whole) -> the entry, or null (none, or no file)
|
|
25
|
+
function lastHistory(where, pick, {max = 256 * 1024} = {}) {
|
|
26
|
+
let text = '';
|
|
27
|
+
let fd = null;
|
|
28
|
+
try {
|
|
29
|
+
fd = fs.openSync(path.join(where.home, 'history.jsonl'), fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW || 0));
|
|
30
|
+
const size = fs.fstatSync(fd).size;
|
|
31
|
+
const n = Math.min(size, max);
|
|
32
|
+
const buf = Buffer.alloc(n);
|
|
33
|
+
fs.readSync(fd, buf, 0, n, size - n);
|
|
34
|
+
text = buf.toString('utf8');
|
|
35
|
+
} catch (err) {
|
|
36
|
+
return null;
|
|
37
|
+
} finally {
|
|
38
|
+
if (fd != null) fs.closeSync(fd);
|
|
39
|
+
}
|
|
40
|
+
const lines = text.split('\n');
|
|
41
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
42
|
+
let e;
|
|
43
|
+
try { e = JSON.parse(lines[i]); } catch (err) { continue; }
|
|
44
|
+
if (e != null && typeof e === 'object' && pick(e)) return e;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = {appendHistory, lastHistory};
|