@patronage/software-factory 1.0.0-alpha.47 → 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.
- package/README.md +3 -1
- package/dist/cloud/gh-shim.mjs +1026 -0
- package/dist/cloud/run.sh +74 -0
- package/dist/cloud/session-env.sh +75 -0
- package/dist/index.d.ts +71 -402
- package/dist/index.js +295 -185
- package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
- package/dist/schemas.d.ts +8 -0
- package/dist/schemas.js +66 -63
- package/package.json +15 -14
- package/dist/rolldown-runtime-D8jQpDG7.js +0 -12
|
@@ -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
|
+
}
|