@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,235 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
// The plugin's entry: runs the installed launcher, <home>/bin/ch-local.js, with
|
|
4
|
+
// this process's arguments and stdio. On POSIX it becomes the launcher
|
|
5
|
+
// (process.execve), so a session is one process (the launcher then becomes
|
|
6
|
+
// the shim): no Node of this script stays beside it (the Reviewer on #123).
|
|
7
|
+
// Elsewhere, or on a Node with no execve, it runs the launcher as a child,
|
|
8
|
+
// passes a stop on to it, and ends the way it ended. It fetches and installs nothing. The plugin is copied on its own,
|
|
9
|
+
// so the home rule is repeated from lib/home.js (a test checks they agree).
|
|
10
|
+
// Plain require names, so a Node too old for 'node:' still gets the one-line
|
|
11
|
+
// message below.
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const os = require('os');
|
|
14
|
+
const path = require('path');
|
|
15
|
+
const {spawn} = require('child_process');
|
|
16
|
+
|
|
17
|
+
const FLOOR = [22, 16];
|
|
18
|
+
|
|
19
|
+
function nodeOk(version) {
|
|
20
|
+
const [major, minor] = String(version).replace(/^v/, '').split('.').map(Number);
|
|
21
|
+
return major > FLOOR[0] || (major === FLOOR[0] && minor >= FLOOR[1]);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function isFullPath(p, platform = process.platform) {
|
|
25
|
+
if (platform === 'win32') return /^(?:[A-Za-z]:[\\/]|[\\/]{2}[^\\/])/.test(p);
|
|
26
|
+
return path.posix.isAbsolute(p);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// The default home, as lib/home.js defaultHome has it: on Windows %LOCALAPPDATA%\countinghouse, never a folder directly in the
|
|
30
|
+
// profile (Codex's Windows sandbox gives its identities access to each one, every time it runs a command); LOCALAPPDATA from the
|
|
31
|
+
// environment, refused when missing or not absolute (a thrown error, its words lib/home.js's)
|
|
32
|
+
function defaultHome(env, platform = process.platform, homedir = os.homedir) {
|
|
33
|
+
if (platform !== 'win32') return path.join(homedir(), '.countinghouse');
|
|
34
|
+
const local = env.LOCALAPPDATA;
|
|
35
|
+
if (typeof local !== 'string' || local === '' || !isFullPath(local, 'win32')) {
|
|
36
|
+
const err = new Error(`LOCALAPPDATA is ${typeof local !== 'string' || local === '' ? 'not set' : `not an absolute path ("${local}")`}, so the home's place (%LOCALAPPDATA%\\countinghouse) is not known: set COUNTINGHOUSE_HOME to an absolute path`);
|
|
37
|
+
err.code = 'HOME_NO_LOCALAPPDATA';
|
|
38
|
+
throw err;
|
|
39
|
+
}
|
|
40
|
+
return path.win32.join(local, 'countinghouse');
|
|
41
|
+
}
|
|
42
|
+
function whereIs(env, platform = process.platform, homedir = os.homedir) {
|
|
43
|
+
const set = env.COUNTINGHOUSE_HOME;
|
|
44
|
+
const p = platform === 'win32' ? path.win32 : path;
|
|
45
|
+
if (typeof set !== 'string' || set === '') return p.join(defaultHome(env, platform, homedir), 'bin', 'ch-local.js');
|
|
46
|
+
if (!isFullPath(set, platform)) return null;
|
|
47
|
+
return p.join(p.normalize(set), 'bin', 'ch-local.js');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// POSIX, a Node with execve, and its own executable runnable -> true
|
|
51
|
+
function canExec(platform, execve, execPath) {
|
|
52
|
+
if (platform === 'win32' || typeof execve !== 'function') return false;
|
|
53
|
+
try { fs.accessSync(execPath, fs.constants.X_OK); return true; } catch { return false; }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const fail = (line, code = 1) => { process.stderr.write(`ch-packs: ${line}\n`); process.exit(code); };
|
|
57
|
+
|
|
58
|
+
// A home, its bin/ or the launcher itself that another user could change ->
|
|
59
|
+
// the line that says so, with the fix; null when all three are this user's
|
|
60
|
+
// alone (the reviewer's pre-work high, A-home-check, 1). Checked here, before
|
|
61
|
+
// anything of the home runs: the home's own code can't vouch for itself.
|
|
62
|
+
// POSIX: each this user's, and not group- or world-writable. Windows: each
|
|
63
|
+
// with a private DACL, by the plugin's own copy of lib/win-acl.js (a test
|
|
64
|
+
// checks the two agree). fileAcl: a test's.
|
|
65
|
+
const OPEN = 'so another user could change what runs from it';
|
|
66
|
+
// a path for a command to copy: quoted when plain, else the placeholder (no
|
|
67
|
+
// control, bidi or shell characters reach the terminal or the paste). The
|
|
68
|
+
// rule is lib/command-line.js UNSAFE_ANY's, copied (a test checks the two
|
|
69
|
+
// agree: the reviewer's high on #126, L8); built when used, so a Node too old
|
|
70
|
+
// for its \p{} still gets the one-line message below.
|
|
71
|
+
const UNSAFE_SOURCE = "[\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180f\"`$\\\\%!^\\u2018-\\u201f\\u200b-\\u200f\\u2028\\u2029\\u202a-\\u202e\\u2060-\\u2069\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff0-\\ufffb\\u{e0000}-\\u{e007f}]|[\\p{Cc}\\p{Cf}\\p{Zl}\\p{Zp}]";
|
|
72
|
+
const plain = (p, platform = process.platform) => !new RegExp(UNSAFE_SOURCE, 'u').test(platform === 'win32' ? p.replace(/\\/g, '/') : p);
|
|
73
|
+
const shown = (p, platform = process.platform) => (plain(p, platform) ? `"${p}"` : '"<its folder>"');
|
|
74
|
+
// The folders above a home (POSIX, as lib/home.js aboveProblem says it; the reviewer on #126 (a)), by countinghouse
|
|
75
|
+
// #520's rule for its sqlite store's: along the path as given and its real
|
|
76
|
+
// path, each this user's or root's, writable by no other unless sticky (as
|
|
77
|
+
// /tmp: no one else can rename what this user owns there), nor by a group
|
|
78
|
+
// other than this user's own primary group (a user-private group, as a umask
|
|
79
|
+
// of 0002 leaves a home's folders). Otherwise another user could move the
|
|
80
|
+
// home away and put one of theirs in its place. Windows: the ancestors' DACLs
|
|
81
|
+
// are not checked. -> {why, fix} | null
|
|
82
|
+
function aboveProblemWith(home, QUOTE) {
|
|
83
|
+
const given = path.resolve(home);
|
|
84
|
+
// (a home not made yet: the path as given, its folders that are there)
|
|
85
|
+
let real = null;
|
|
86
|
+
try { real = fs.realpathSync.native(given); } catch (e) { if (e.code !== 'ENOENT') return {why: `it could not be read (${e.code || e.message})`, fix: null}; }
|
|
87
|
+
const uid = typeof process.geteuid === 'function' ? process.geteuid() : null;
|
|
88
|
+
const gid = typeof process.getegid === 'function' ? process.getegid() : null;
|
|
89
|
+
for (const start of real != null ? [given, real] : [given]) {
|
|
90
|
+
for (let at = path.dirname(start); ; at = path.dirname(at)) {
|
|
91
|
+
let st;
|
|
92
|
+
try { st = fs.statSync(at); } catch (e) {
|
|
93
|
+
if (real == null && e.code === 'ENOENT' && path.dirname(at) !== at) continue;
|
|
94
|
+
return {why: `it is under ${at}, which could not be checked (${e.code || e.message})`, fix: null};
|
|
95
|
+
}
|
|
96
|
+
if (uid != null && st.uid !== uid && st.uid !== 0) return {why: `it is under ${at}, which is not yours (nor root's); another user could move the home away and put theirs in its place`, fix: null};
|
|
97
|
+
const sticky = (st.mode & 0o1000) !== 0;
|
|
98
|
+
const others = (st.mode & 0o002) !== 0 && !sticky;
|
|
99
|
+
const group = (st.mode & 0o020) !== 0 && !sticky && st.gid !== gid;
|
|
100
|
+
if (others || group) {
|
|
101
|
+
const mine = uid != null && st.uid === uid;
|
|
102
|
+
const q = QUOTE(at);
|
|
103
|
+
return {why: `it is under ${at}, and group or others can write in it (mode ${(st.mode & 0o7777).toString(8)}); another user could move the home away and put theirs in its place`, fix: mine && q !== '"<its folder>"' ? `run \`chmod go-w ${q}\`` : null};
|
|
104
|
+
}
|
|
105
|
+
if (path.dirname(at) === at) break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
function aboveProblem(home) {
|
|
111
|
+
return aboveProblemWith(home, shown);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// home, launcher: as found by the home rule -> {problem} (the line, with the
|
|
115
|
+
// fix) | {launcher} (the launcher's real path, the one checked and the one to
|
|
116
|
+
// run: the medium on A-home-check, 3). fileAcls: a test's.
|
|
117
|
+
function homeProblem(home, launcher, {platform = process.platform, fileAcls = null} = {}) {
|
|
118
|
+
const items = [[home, true], [path.dirname(launcher), true], [launcher, false]];
|
|
119
|
+
const reals = [];
|
|
120
|
+
// (a launcher that is a link: its real folder is not the one checked, and
|
|
121
|
+
// a write through it lands elsewhere: refused, L3)
|
|
122
|
+
try {
|
|
123
|
+
if (fs.lstatSync(launcher).isSymbolicLink()) return {problem: `${launcher} is a link, ${OPEN}; install again to put a file there`};
|
|
124
|
+
} catch (err) { return {problem: `${launcher} could not be read (${err.code || err.message})`}; }
|
|
125
|
+
for (let i = 0; i < items.length; i++) {
|
|
126
|
+
const [p, directory] = items[i];
|
|
127
|
+
let real;
|
|
128
|
+
try { real = fs.realpathSync.native(p); } catch (err) { return {problem: `${p} could not be read (${err.code || err.message})`}; }
|
|
129
|
+
let st;
|
|
130
|
+
try { st = fs.statSync(real); } catch (err) { return {problem: `${real} could not be read (${err.code || err.message})`}; }
|
|
131
|
+
// (a wrong type is a broken install, not another user's: L8)
|
|
132
|
+
if (directory ? !st.isDirectory() : !st.isFile()) return {problem: `${real} is not a ${directory ? 'folder' : 'file'}; install again`};
|
|
133
|
+
reals.push(real);
|
|
134
|
+
if (platform === 'win32') continue;
|
|
135
|
+
const euid = typeof process.geteuid === 'function' ? process.geteuid() : null;
|
|
136
|
+
if (euid != null && st.uid !== euid) return {problem: `${real} is owned by uid ${st.uid}, not you, ${OPEN}; use a home only you own`};
|
|
137
|
+
// (writable by others: it may already have been changed, so never
|
|
138
|
+
// trusted after a chmod: moved aside and installed again, F2)
|
|
139
|
+
if ((st.mode & 0o022) !== 0) {
|
|
140
|
+
const homeReal = reals[0];
|
|
141
|
+
const move = shown(homeReal) !== '"<its folder>"' && shown(`${homeReal}.suspect`) !== '"<its folder>"' ? ` (\`mv ${shown(homeReal)} ${shown(`${homeReal}.suspect`)}\`)` : '';
|
|
142
|
+
return {problem: `${real} is group- or world-writable (mode ${(st.mode & 0o777).toString(8).padStart(4, '0')}), ${OPEN}; the home may already have been changed: move it aside${move} and install again`};
|
|
143
|
+
}
|
|
144
|
+
// (the home itself private, as install makes it: its app and module
|
|
145
|
+
// store run with the keys, M2)
|
|
146
|
+
if (i === 0 && (st.mode & 0o077) !== 0) return {problem: `${real} is open to group or others (mode ${(st.mode & 0o777).toString(8).padStart(4, '0')}), and its folders may be too, ${OPEN}; run \`chmod 700 ${shown(real)}\``};
|
|
147
|
+
}
|
|
148
|
+
if (platform !== 'win32') {
|
|
149
|
+
const above = aboveProblem(home);
|
|
150
|
+
if (above != null) return {problem: `${home}: ${above.why}, ${OPEN}${above.fix != null ? `; ${above.fix}` : ''}`};
|
|
151
|
+
}
|
|
152
|
+
if (platform === 'win32') {
|
|
153
|
+
// (the three in one PowerShell run, which costs 1 to 10 s: the medium, 2)
|
|
154
|
+
const winAcl = require('./win-acl');
|
|
155
|
+
let acls;
|
|
156
|
+
try { acls = (fileAcls || winAcl.fileAcls)(reals); } catch (err) { return {problem: `the access lists of ${reals[0]} could not be read (${err.code || err.message}), ${OPEN}`}; }
|
|
157
|
+
for (let i = 0; i < items.length; i++) {
|
|
158
|
+
const directory = items[i][1];
|
|
159
|
+
const why = winAcl.privateProblem(reals[i], acls[i], {directory});
|
|
160
|
+
if (why == null) continue;
|
|
161
|
+
// (owned by another: never /setowner, which would take what is theirs:
|
|
162
|
+
// remove it and install again, L8)
|
|
163
|
+
const a = acls[i];
|
|
164
|
+
if (a != null && typeof a.owner === 'string' && ![a.user, winAcl.SYSTEM, winAcl.ADMINISTRATORS].includes(a.owner)) return {problem: `${why}, ${OPEN}; remove it and install again`};
|
|
165
|
+
// another account holding more than it may (privateProblem's "accessible by"): every one holding the strongest right, by SID
|
|
166
|
+
// (no name lookup on the way to a start), and the verb that right takes, as lib/home.js says it: changeable, or readable
|
|
167
|
+
const open = winAcl.openPrincipals(a);
|
|
168
|
+
const said = open.length > 0 && why === `${reals[i]} is accessible by ${open[0].sid}`;
|
|
169
|
+
const change = said && open.some((p) => p.change);
|
|
170
|
+
const who = said ? open.filter((p) => p.change === change).map((p) => p.sid) : [];
|
|
171
|
+
const list = who.length <= 1 ? who.join('') : `${who.slice(0, -1).join(', ')} and ${who[who.length - 1]}`;
|
|
172
|
+
const lead = !said ? `${why}, ${OPEN}`
|
|
173
|
+
: change ? `${reals[i]} can be changed by ${list}, so another account could change what runs from it`
|
|
174
|
+
: `${reals[i]} is readable by ${list}, ${i === 0 ? 'so another account could read what is stored in it, its credentials included' : 'so it is not yours alone'}`;
|
|
175
|
+
// (anyone else able to change it, or what was made in it: it may already have been changed, so the home is moved aside, never
|
|
176
|
+
// repaired, as lib/home.js has it)
|
|
177
|
+
if (winAcl.foreignChange(a)) return {problem: `${lead}; it may already have been changed: move the home aside and install again`};
|
|
178
|
+
const hint = plain(reals[i], 'win32') ? winAcl.fixHint(reals[i], acls[i], {directory}) : null;
|
|
179
|
+
return {problem: `${lead}; make it a ${directory ? 'folder' : 'file'} only you can ${said ? 'read' : 'change'}${hint != null ? `, in Windows PowerShell (powershell.exe): ${hint.split('\n').map((l) => l.trim()).join(', then ')}` : ''}`};
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return {launcher: reals[2]};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function main() {
|
|
186
|
+
if (!nodeOk(process.version)) fail(`needs Node 22.16 or later; this is ${process.version} (the \`node\` on the PATH Claude Code sees)`);
|
|
187
|
+
let launcher;
|
|
188
|
+
try { launcher = whereIs(process.env); } catch (err) { fail(err.message); }
|
|
189
|
+
if (launcher == null) fail(`COUNTINGHOUSE_HOME must be an absolute path, not "${process.env.COUNTINGHOUSE_HOME}"`);
|
|
190
|
+
// (COUNTINGHOUSE_HOME set: the home in words, on every platform, or the
|
|
191
|
+
// install goes to the default home -- the closing pass on release 1, L3)
|
|
192
|
+
// (normalized; not said for the default home; one a terminal would
|
|
193
|
+
// misshow -- a control, bidi or invisible character -- said as the folder
|
|
194
|
+
// it names, never printed: the medium on the closing pass, 4)
|
|
195
|
+
const set = process.env.COUNTINGHOUSE_HOME != null && process.env.COUNTINGHOUSE_HOME !== '' ? path.normalize(process.env.COUNTINGHOUSE_HOME) : null;
|
|
196
|
+
let def = null;
|
|
197
|
+
try { def = defaultHome(process.env); } catch (err) { def = null; }
|
|
198
|
+
const same = (a, b) => (process.platform === 'win32' ? path.resolve(a).toLowerCase() === path.resolve(b).toLowerCase() : path.resolve(a) === path.resolve(b));
|
|
199
|
+
const isDefault = set != null && def != null && same(set, def);
|
|
200
|
+
const shown = set == null || isDefault ? null : /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u180e\u200b-\u200f\u2028-\u202e\u2060-\u206f\ufeff]/.test(set) ? 'the folder it names now' : set;
|
|
201
|
+
const named = shown != null ? ` (with COUNTINGHOUSE_HOME set to ${shown})` : '';
|
|
202
|
+
if (!fs.existsSync(launcher)) fail(`the launcher is not installed at ${launcher}; install it with: npx @countinghouse/ch-local@latest install --pack ci-failure-triage${named}`);
|
|
203
|
+
// (nothing runs from a home another user could change: exit 2)
|
|
204
|
+
const checked = homeProblem(path.dirname(path.dirname(launcher)), launcher);
|
|
205
|
+
if (checked.problem != null) fail(`${checked.problem}; nothing was started`, 2);
|
|
206
|
+
// (the path checked is the one run)
|
|
207
|
+
const run = checked.launcher;
|
|
208
|
+
// (a failed execve ends Node 22 and 24 outright, so only a call that can't
|
|
209
|
+
// fail is made: POSIX, this Node's own executable, runnable from where it
|
|
210
|
+
// is. And nothing touches stdin, stdout or stderr before it, so the pipes
|
|
211
|
+
// reach the launcher, and the shim after it, as the client gave them.)
|
|
212
|
+
if (canExec(process.platform, process.execve, process.execPath)) {
|
|
213
|
+
process.execve(process.execPath, [process.execPath, run, ...process.argv.slice(2)], process.env);
|
|
214
|
+
}
|
|
215
|
+
const child = spawn(process.execPath, [run, ...process.argv.slice(2)], {stdio: 'inherit'});
|
|
216
|
+
child.on('error', (err) => fail(`could not start ${launcher} (${err.code || err.message})`));
|
|
217
|
+
const forward = (signal) => {
|
|
218
|
+
if (child.exitCode != null || child.signalCode != null) return;
|
|
219
|
+
// Windows cannot send every signal (SIGHUP throws ENOSYS): stop it plainly.
|
|
220
|
+
try { child.kill(signal); } catch { child.kill(); }
|
|
221
|
+
};
|
|
222
|
+
for (const signal of ['SIGTERM', 'SIGINT', 'SIGHUP']) process.on(signal, forward);
|
|
223
|
+
child.on('exit', (code, signal) => {
|
|
224
|
+
if (signal != null) {
|
|
225
|
+
// End the way the launcher ended, so a clean stop does not read as a failure.
|
|
226
|
+
process.removeAllListeners(signal);
|
|
227
|
+
try { process.kill(process.pid, signal); } catch { /* fall through */ }
|
|
228
|
+
}
|
|
229
|
+
process.exit(code != null ? code : 1);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (require.main === module) main();
|
|
234
|
+
|
|
235
|
+
module.exports = {whereIs, defaultHome, nodeOk, isFullPath, canExec, homeProblem, aboveProblem, UNSAFE_SOURCE};
|