@patronage/software-factory 1.0.0-alpha.47 → 1.0.0-alpha.49
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 +9 -5
- package/dist/ci.d.ts +1888 -0
- package/dist/ci.js +4519 -0
- package/dist/cloud/review.sh +76 -0
- package/dist/cloud/run.sh +63 -0
- package/dist/cloud/session-env.sh +80 -0
- package/dist/index.d.ts +125 -403
- package/dist/index.js +7716 -5806
- package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
- package/dist/schemas.d.ts +8 -0
- package/dist/schemas.js +66 -63
- package/package.json +21 -15
- package/dist/rolldown-runtime-D8jQpDG7.js +0 -12
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
# The clean review session for a Claude Code cloud lane: hands the assembled
|
|
5
|
+
# `pr:review --assemble` prompt to a new Claude session and waits for its
|
|
6
|
+
# findings file, which `pr:review --findings` then records. Run it from the
|
|
7
|
+
# repository being admitted (it reviews `git rev-parse --show-toplevel`):
|
|
8
|
+
#
|
|
9
|
+
# bash node_modules/@patronage/software-factory/dist/cloud/review.sh [findings-path]
|
|
10
|
+
#
|
|
11
|
+
# It ships in the package (#1643) so a consumer lane needs no hand-written
|
|
12
|
+
# reviewer command and no software-factory checkout.
|
|
13
|
+
#
|
|
14
|
+
# - A new `--session-id`, so the review session differs from the authoring
|
|
15
|
+
# session the verify proof recorded. Without it `claude -p` reuses the
|
|
16
|
+
# parent's id.
|
|
17
|
+
# - `--setting-sources user` skips the repository's SessionStart hook, which
|
|
18
|
+
# would re-bootstrap the worktree inside the reviewer.
|
|
19
|
+
# - The reviewer may read and run read-only git, and write only the findings
|
|
20
|
+
# file. File writes are granted by an `Edit(//<absolute path>)` rule: a
|
|
21
|
+
# `Write(...)` rule does not match them, and `bypassPermissions` is refused
|
|
22
|
+
# in auto mode.
|
|
23
|
+
# - The prompt goes on stdin, because `--allowedTools` takes every argument
|
|
24
|
+
# after it.
|
|
25
|
+
#
|
|
26
|
+
# FACTORY_REVIEW_MODEL picks the model (default claude-fable-5-2); the findings
|
|
27
|
+
# file records it for audit.
|
|
28
|
+
|
|
29
|
+
unset CDPATH
|
|
30
|
+
|
|
31
|
+
repo_root="$(git rev-parse --show-toplevel)"
|
|
32
|
+
prompt_json="$repo_root/.factory-memory/pr-review-prompt.json"
|
|
33
|
+
model="${FACTORY_REVIEW_MODEL:-claude-fable-5-2}"
|
|
34
|
+
|
|
35
|
+
if [ ! -f "$prompt_json" ]; then
|
|
36
|
+
echo "review.sh: no $prompt_json; run pr:review --assemble first" >&2
|
|
37
|
+
exit 2
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
session_id="$(node -e 'console.log(crypto.randomUUID())')"
|
|
41
|
+
findings="${1:-$repo_root/.factory-memory/review-findings-$session_id.json}"
|
|
42
|
+
# Absolute and normalized, so the Edit rule names the path the reviewer's
|
|
43
|
+
# write resolves to (`./out` or `../x` would otherwise stay in the rule).
|
|
44
|
+
findings="$(node -e 'console.log(require("node:path").resolve(process.argv[1]))' "$findings")"
|
|
45
|
+
mkdir -p "$(dirname "$findings")"
|
|
46
|
+
rm -f "$findings"
|
|
47
|
+
|
|
48
|
+
prompt="$(mktemp)"
|
|
49
|
+
trap 'rm -f "$prompt"' EXIT
|
|
50
|
+
node - "$prompt_json" >"$prompt" <<'EOF'
|
|
51
|
+
const { reviews } = JSON.parse(require("node:fs").readFileSync(process.argv[2]));
|
|
52
|
+
console.log(
|
|
53
|
+
reviews
|
|
54
|
+
.map(({ kind, prompt }) =>
|
|
55
|
+
reviews.length > 1 ? `# Review: ${kind}\n\n${prompt}` : prompt
|
|
56
|
+
)
|
|
57
|
+
.join("\n\n")
|
|
58
|
+
);
|
|
59
|
+
EOF
|
|
60
|
+
cat >>"$prompt" <<EOF
|
|
61
|
+
|
|
62
|
+
Dispatch instructions: you are a clean, independent review session. Your session id is $session_id and your model is $model. Read the candidate with \`git diff origin/main...HEAD\` (or the base named in Review scope) in $repo_root, and any surrounding code you need. Write the findings file to $findings; that is the only file you may write. Do not modify the repository.
|
|
63
|
+
EOF
|
|
64
|
+
|
|
65
|
+
started="$(date +%s)"
|
|
66
|
+
claude -p --model "$model" --session-id "$session_id" \
|
|
67
|
+
--setting-sources user \
|
|
68
|
+
"--allowedTools=Read,Grep,Glob,Bash(git diff:*),Bash(git grep:*),Bash(git log:*),Bash(git merge-base:*),Bash(git rev-parse:*),Bash(git show:*),Edit(/$findings)" \
|
|
69
|
+
<"$prompt"
|
|
70
|
+
|
|
71
|
+
if [ ! -s "$findings" ]; then
|
|
72
|
+
echo "review.sh: session $session_id wrote no findings to $findings" >&2
|
|
73
|
+
exit 1
|
|
74
|
+
fi
|
|
75
|
+
echo "review.sh: session $session_id ($model) wrote $findings in $(($(date +%s) - started))s"
|
|
76
|
+
echo "next: psf pr:review --findings $findings"
|
|
@@ -0,0 +1,63 @@
|
|
|
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 Factory CLI's claude-cloud GitHub lane, since the proxy refuses
|
|
19
|
+
# GitHub GraphQL (github-api.ts, #1646).
|
|
20
|
+
#
|
|
21
|
+
# It puts no `gh` wrapper on PATH: the session's own `gh` porcelain still
|
|
22
|
+
# meets the proxy's GraphQL refusal, so use `gh api` REST there.
|
|
23
|
+
#
|
|
24
|
+
# It installs no Node and no dependencies: that is the consumer's own
|
|
25
|
+
# credential-free environment setup, which must have run for this file to be
|
|
26
|
+
# in node_modules at all. It reads no credential value and writes no env file;
|
|
27
|
+
# the exports reach only the command it runs.
|
|
28
|
+
|
|
29
|
+
unset CDPATH
|
|
30
|
+
|
|
31
|
+
[ "${CLAUDE_CODE_REMOTE:-}" = true ] || {
|
|
32
|
+
echo 'factory-cloud: use this launcher in a Claude cloud session.' >&2
|
|
33
|
+
exit 1
|
|
34
|
+
}
|
|
35
|
+
[ "$#" -gt 0 ] || {
|
|
36
|
+
echo 'Usage: bash <package>/dist/cloud/run.sh <command> [args...]' >&2
|
|
37
|
+
exit 1
|
|
38
|
+
}
|
|
39
|
+
command -v node >/dev/null || {
|
|
40
|
+
echo 'factory-cloud: node is not on PATH; install the repository Node first.' >&2
|
|
41
|
+
exit 1
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
cloud_dir="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
|
45
|
+
# shellcheck source=./session-env.sh
|
|
46
|
+
. "$cloud_dir/session-env.sh"
|
|
47
|
+
|
|
48
|
+
if [ -z "${FACTORY_SESSION_ID:-}" ] && [ -n "${CLAUDE_CODE_REMOTE_SESSION_ID:-}" ]; then
|
|
49
|
+
FACTORY_SESSION_ID="$(claude_cloud_session_id "$CLAUDE_CODE_REMOTE_SESSION_ID")"
|
|
50
|
+
export FACTORY_SESSION_ID
|
|
51
|
+
fi
|
|
52
|
+
export LC_ALL="${LC_ALL:-C.UTF-8}"
|
|
53
|
+
export LANG="${LANG:-C.UTF-8}"
|
|
54
|
+
|
|
55
|
+
# The package carries no 1Password resolver, so a service-account token
|
|
56
|
+
# changes nothing here: HQ access is whatever the egress proxy injects. A
|
|
57
|
+
# repository that resolves its own HQ values sets CF_ACCESS_* itself, and
|
|
58
|
+
# those win (session-env.sh).
|
|
59
|
+
hq_access="$(probe_hq_access "$FACTORY_CLOUD_HQ_ORIGIN$FACTORY_CLOUD_HQ_PROBE_PATH")"
|
|
60
|
+
eval "$(OP_SERVICE_ACCOUNT_TOKEN='' hq_access_exports "$hq_access")"
|
|
61
|
+
eval "$(github_lane_exports)"
|
|
62
|
+
|
|
63
|
+
exec "$@"
|
|
@@ -0,0 +1,80 @@
|
|
|
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`).
|
|
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. 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
|
+
[ "$1" = "injected" ] || [ -n "${OP_SERVICE_ACCOUNT_TOKEN:-}" ] || return 0
|
|
54
|
+
if [ -n "${OP_SERVICE_ACCOUNT_TOKEN:-}" ]; then
|
|
55
|
+
printf 'export FACTORY_CLOUD_MACHINE=claude-cloud\n'
|
|
56
|
+
elif [ -z "${CF_ACCESS_CLIENT_ID:-}" ] && [ -z "${CF_ACCESS_CLIENT_SECRET:-}" ]; then
|
|
57
|
+
printf 'export CF_ACCESS_CLIENT_ID=proxy-injected\n'
|
|
58
|
+
printf 'export CF_ACCESS_CLIENT_SECRET=proxy-injected\n'
|
|
59
|
+
fi
|
|
60
|
+
if [ -z "${FACTORY_HQ_ALLOWED_ORIGINS:-}" ]; then
|
|
61
|
+
printf 'export FACTORY_HQ_ALLOWED_ORIGINS=%s\n' "$FACTORY_CLOUD_HQ_ORIGIN"
|
|
62
|
+
fi
|
|
63
|
+
if [ -z "${NODE_USE_ENV_PROXY:-}" ]; then
|
|
64
|
+
printf 'export NODE_USE_ENV_PROXY=1\n'
|
|
65
|
+
fi
|
|
66
|
+
if [ -z "${FACTORY_CHECK_RUN_RELAY_ORIGIN:-}" ]; then
|
|
67
|
+
printf 'export FACTORY_CHECK_RUN_RELAY_ORIGIN=%s\n' "$FACTORY_CLOUD_HQ_ORIGIN"
|
|
68
|
+
fi
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
# Prints the env-file line that puts the Factory CLI's GitHub client on the
|
|
72
|
+
# claude-cloud lane (github-api.ts, #1646): GraphQL reads through HQ's read
|
|
73
|
+
# relay, and ready-for-review and auto-merge through the session proxy's
|
|
74
|
+
# routes, since the proxy refuses GitHub GraphQL. A value the environment
|
|
75
|
+
# already sets wins.
|
|
76
|
+
github_lane_exports() {
|
|
77
|
+
if [ -z "${FACTORY_GITHUB_LANE:-}" ]; then
|
|
78
|
+
printf 'export FACTORY_GITHUB_LANE=claude-cloud\n'
|
|
79
|
+
fi
|
|
80
|
+
}
|