@patronage/software-factory 1.0.0-alpha.46 → 1.0.0-alpha.48

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.
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ # Credential-free Linux tool bootstrap shared by Cursor Build and Claude
5
+ # SessionStart. Never read OP_SERVICE_ACCOUNT_TOKEN or persist resolved values.
6
+ # Archive SHA-256 pins: official 1Password 2.41.1 archives and upstream op-fast
7
+ # v0.1.1 release assets (github.com/cometkim/op-fast/releases/tag/v0.1.1).
8
+ cloud_tools_arch() {
9
+ case "$1" in
10
+ x86_64 | amd64)
11
+ printf '%s\n' amd64 x86_64 \
12
+ e52476700cba9202ac7469bdfb2648ecdbf3438ac85822010f77230139e74966 \
13
+ a480a09ef344b7503a26f3b173891350a4d3bc465f6dcdd7b0f51735554c65f8 ;;
14
+ aarch64 | arm64)
15
+ printf '%s\n' arm64 aarch64 \
16
+ 89abd60c17d5c614066c20e6abed816449eb018c5e0679ed63d57071c7bee85e \
17
+ 59622b22f76fe1ff54fec06dc214b192b6878cf6dd596a972f11e9a7d1461ca5 ;;
18
+ *) return 1 ;;
19
+ esac
20
+ }
21
+
22
+ if [ "${FACTORY_CLOUD_TOOLS_DEFINE_ONLY:-}" = "1" ]; then
23
+ return 0 2>/dev/null || exit 0
24
+ fi
25
+
26
+ [ "$(uname -s)" = Linux ] || { echo 'cloud-tools: Linux is required.' >&2; exit 1; }
27
+ tool_bin="${1:?Usage: install-cloud-secrets.sh <absolute-bin-directory>}"
28
+ [[ "$tool_bin" = /* ]] || { echo 'cloud-tools: absolute bin directory required.' >&2; exit 1; }
29
+ mkdir -p "$tool_bin"
30
+
31
+ if [ "$("$tool_bin/op" --version 2>/dev/null || true)" = '2.41.1' ] &&
32
+ [ "$("$tool_bin/op-fast" --version 2>/dev/null || true)" = 'op-fast 0.1.1' ]; then
33
+ exit 0
34
+ fi
35
+
36
+ for required in curl unzip tar sha256sum; do
37
+ command -v "$required" >/dev/null || { echo "cloud-tools: missing $required." >&2; exit 1; }
38
+ done
39
+ pins="$(cloud_tools_arch "$(uname -m)")" || { echo 'cloud-tools: unsupported architecture.' >&2; exit 1; }
40
+ op_arch="$(printf '%s\n' "$pins" | sed -n '1p')"
41
+ fast_arch="$(printf '%s\n' "$pins" | sed -n '2p')"
42
+ op_sha="$(printf '%s\n' "$pins" | sed -n '3p')"
43
+ fast_sha="$(printf '%s\n' "$pins" | sed -n '4p')"
44
+ staging="$(mktemp -d "$tool_bin/.install.XXXXXX")"
45
+ trap 'rm -rf "$staging"' EXIT
46
+ curl --proto '=https' --tlsv1.2 -fsSL --max-time 120 \
47
+ "https://cache.agilebits.com/dist/1P/op2/pkg/v2.41.1/op_linux_${op_arch}_v2.41.1.zip" -o "$staging/op.zip"
48
+ printf '%s %s\n' "$op_sha" "$staging/op.zip" | sha256sum --check --status
49
+ unzip -q "$staging/op.zip" op -d "$staging"
50
+ fast_asset="op-fast-${fast_arch}-unknown-linux-gnu"
51
+ curl --proto '=https' --tlsv1.2 -fsSL --max-time 120 \
52
+ "https://github.com/cometkim/op-fast/releases/download/v0.1.1/$fast_asset.tar.xz" -o "$staging/op-fast.tar.xz"
53
+ printf '%s %s\n' "$fast_sha" "$staging/op-fast.tar.xz" | sha256sum --check --status
54
+ tar -xJf "$staging/op-fast.tar.xz" -C "$staging"
55
+ fast_binary="$staging/$fast_asset/op-fast"
56
+ [ -f "$fast_binary" ] || { echo 'cloud-tools: unexpected op-fast archive.' >&2; exit 1; }
57
+ install -m 755 "$staging/op" "$tool_bin/op"
58
+ install -m 755 "$fast_binary" "$tool_bin/op-fast"
59
+ echo 'cloud-tools: installed checksum-pinned 1Password backend and op-fast.'
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ # The consumer launcher for Factory commands in a Claude Code cloud session
5
+ # (#1645). Claude project threads do not run a repository's SessionStart hook,
6
+ # so a consumer runs each Factory command through this instead:
7
+ #
8
+ # bash node_modules/@patronage/software-factory/dist/cloud/run.sh \
9
+ # pnpm exec psf pr:verify
10
+ #
11
+ # It sets what admission needs from the session and nothing else:
12
+ #
13
+ # - FACTORY_SESSION_ID from the cloud session id, unless already set;
14
+ # - LC_ALL/LANG to C.UTF-8, unless already set;
15
+ # - HQ access (session-env.sh): proxy-injected Access markers, the allowed HQ
16
+ # origin, the check-run relay, and NODE_USE_ENV_PROXY=1, when the egress
17
+ # proxy injects HQ's Access token;
18
+ # - the gh shim first on PATH, since the proxy refuses GitHub GraphQL.
19
+ #
20
+ # It installs no Node and no dependencies: that is the consumer's own
21
+ # credential-free environment setup, which must have run for this file to be
22
+ # in node_modules at all. It reads no credential value and writes no env file;
23
+ # the exports reach only the command it runs.
24
+
25
+ unset CDPATH
26
+
27
+ [ "${CLAUDE_CODE_REMOTE:-}" = true ] || {
28
+ echo 'factory-cloud: use this launcher in a Claude cloud session.' >&2
29
+ exit 1
30
+ }
31
+ [ "$#" -gt 0 ] || {
32
+ echo 'Usage: bash <package>/dist/cloud/run.sh <command> [args...]' >&2
33
+ exit 1
34
+ }
35
+ command -v node >/dev/null || {
36
+ echo 'factory-cloud: node is not on PATH; install the repository Node first.' >&2
37
+ exit 1
38
+ }
39
+
40
+ cloud_dir="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
41
+ # shellcheck source=./session-env.sh
42
+ . "$cloud_dir/session-env.sh"
43
+
44
+ if [ -z "${FACTORY_SESSION_ID:-}" ] && [ -n "${CLAUDE_CODE_REMOTE_SESSION_ID:-}" ]; then
45
+ FACTORY_SESSION_ID="$(claude_cloud_session_id "$CLAUDE_CODE_REMOTE_SESSION_ID")"
46
+ export FACTORY_SESSION_ID
47
+ fi
48
+ export LC_ALL="${LC_ALL:-C.UTF-8}"
49
+ export LANG="${LANG:-C.UTF-8}"
50
+
51
+ # The `gh` wrapper lives outside node_modules: a package manager may drop the
52
+ # executable bit, and the shim must be able to tell its own directory from the
53
+ # real gh's. It is rewritten on every run, so it always names this package.
54
+ # One wrapper directory per installed package, keyed by its path, so two
55
+ # checkouts pinning different versions never rewrite each other's wrapper.
56
+ shim_key="$(printf '%s' "$cloud_dir" | cksum | cut -d ' ' -f 1)"
57
+ shim_bin="${FACTORY_CLAUDE_CLOUD_CACHE:-${HOME}/.cache/software-factory}/gh-shim-bin/$shim_key"
58
+ mkdir -p "$shim_bin"
59
+ # Physical, because the shim compares it with realpath(gh) to skip itself.
60
+ shim_bin="$(cd -- "$shim_bin" && pwd -P)"
61
+ printf '#!/usr/bin/env bash\nFACTORY_GH_SHIM_DIR=%q exec node %q "$@"\n' \
62
+ "$shim_bin" "$cloud_dir/gh-shim.mjs" >"$shim_bin/gh.$$"
63
+ chmod 0755 "$shim_bin/gh.$$"
64
+ # A per-process name, so overlapping launchers never move each other's file.
65
+ mv -f "$shim_bin/gh.$$" "$shim_bin/gh"
66
+
67
+ # The package carries no 1Password resolver, so a service-account token
68
+ # changes nothing here: HQ access is whatever the egress proxy injects. A
69
+ # repository that resolves its own HQ values sets CF_ACCESS_* itself, and
70
+ # those win (session-env.sh).
71
+ hq_access="$(probe_hq_access "$FACTORY_CLOUD_HQ_ORIGIN$FACTORY_CLOUD_HQ_PROBE_PATH")"
72
+ eval "$(OP_SERVICE_ACCOUNT_TOKEN='' hq_access_exports "$hq_access" "$shim_bin")"
73
+
74
+ exec "$@"
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env bash
2
+ # HQ session environment for a Claude Code cloud session (#1645). Sourced, never
3
+ # run: it only defines functions, so both this repository's SessionStart hook
4
+ # and the packaged launcher (`run.sh`) share one definition of what a cloud
5
+ # session exports. It reads no credential value and writes nothing.
6
+
7
+ # The HQ origin the session may send its Access token to, and the
8
+ # Access-covered route the probe below reads.
9
+ FACTORY_CLOUD_HQ_ORIGIN="https://hq.patronage.com"
10
+ FACTORY_CLOUD_HQ_PROBE_PATH="/api/ingest/last-stored"
11
+
12
+ # Maps the cloud session id to the claude.ai session id. The container exposes
13
+ # `cse_<id>`; the session URL, the commit trailer, and what an operator reads
14
+ # all name `session_<id>`, so the proof records that form. An id in any other
15
+ # shape passes through unchanged.
16
+ claude_cloud_session_id() {
17
+ local raw="$1"
18
+ case "$raw" in
19
+ cse_?*) printf 'session_%s' "${raw#cse_}" ;;
20
+ *) printf '%s' "$raw" ;;
21
+ esac
22
+ }
23
+
24
+ # Answers `injected` when the egress proxy adds the HQ Access token for this
25
+ # session, and `absent` otherwise. The project's cloud environment keeps that
26
+ # token as a network secret the proxy adds for hq.patronage.com, so the session
27
+ # never holds it and cannot see whether it exists. One GET to an
28
+ # Access-covered route tells: the Worker route answers 400 to a request with no
29
+ # repository (or 200), and only Access lets a request reach it. Every other
30
+ # answer, an Access redirect or refusal, a 404 or 5xx from anywhere, a denied
31
+ # host, a timeout, or no curl at all, reads as absent.
32
+ probe_hq_access() {
33
+ local status
34
+ status="$(curl -sS -o /dev/null -w '%{http_code}' --max-time 5 "$1" 2>/dev/null || true)"
35
+ case "$status" in
36
+ 200 | 400) printf 'injected' ;;
37
+ *) printf 'absent' ;;
38
+ esac
39
+ }
40
+
41
+ # Prints the env-file lines for HQ access: `$1` is the probe's answer (or
42
+ # `service-account`), `$2` the directory holding the gh shim's `gh` wrapper.
43
+ # With an injected token it marks both Access variables present
44
+ # (CF_ACCESS_PROXY_INJECTED in hq-access.ts, so the CLI sends no Access header
45
+ # of its own), names HQ as the one allowed origin, and turns on
46
+ # NODE_USE_ENV_PROXY: Node's fetch ignores HTTPS_PROXY without it, and HQ is
47
+ # reachable only through the proxy that adds the token. It also names HQ as the
48
+ # check-run relay (check-run-relay.ts), since the proxy refuses the session's
49
+ # own check-run writes, and puts the gh shim first on PATH. A value the
50
+ # environment already sets wins, and without an injected token nothing is
51
+ # printed, so the CLI still reports missing credentials.
52
+ hq_access_exports() {
53
+ local shim_bin="${2:-}"
54
+ [ "$1" = "injected" ] || [ -n "${OP_SERVICE_ACCOUNT_TOKEN:-}" ] || return 0
55
+ if [ -n "${OP_SERVICE_ACCOUNT_TOKEN:-}" ]; then
56
+ printf 'export FACTORY_CLOUD_MACHINE=claude-cloud\n'
57
+ elif [ -z "${CF_ACCESS_CLIENT_ID:-}" ] && [ -z "${CF_ACCESS_CLIENT_SECRET:-}" ]; then
58
+ printf 'export CF_ACCESS_CLIENT_ID=proxy-injected\n'
59
+ printf 'export CF_ACCESS_CLIENT_SECRET=proxy-injected\n'
60
+ fi
61
+ if [ -z "${FACTORY_HQ_ALLOWED_ORIGINS:-}" ]; then
62
+ printf 'export FACTORY_HQ_ALLOWED_ORIGINS=%s\n' "$FACTORY_CLOUD_HQ_ORIGIN"
63
+ fi
64
+ if [ -z "${NODE_USE_ENV_PROXY:-}" ]; then
65
+ printf 'export NODE_USE_ENV_PROXY=1\n'
66
+ fi
67
+ if [ -z "${FACTORY_CHECK_RUN_RELAY_ORIGIN:-}" ]; then
68
+ printf 'export FACTORY_CHECK_RUN_RELAY_ORIGIN=%s\n' "$FACTORY_CLOUD_HQ_ORIGIN"
69
+ fi
70
+ # The proxy refuses GitHub GraphQL, which most gh pr commands use; the shim
71
+ # reads through HQ instead (gh-shim.mjs). FACTORY_GH_SHIM=0 keeps plain gh.
72
+ if [ -n "$shim_bin" ] && [ "${FACTORY_GH_SHIM:-1}" != "0" ]; then
73
+ printf 'export PATH=%q:"$PATH"\n' "$shim_bin"
74
+ fi
75
+ }