@patronage/software-factory 1.0.0-alpha.48 → 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 +8 -6
- 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 +7 -18
- package/dist/cloud/session-env.sh +12 -7
- package/dist/index.d.ts +55 -2
- package/dist/index.js +7615 -5815
- package/package.json +8 -3
- package/dist/cloud/gh-shim.mjs +0 -1026
|
@@ -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"
|
package/dist/cloud/run.sh
CHANGED
|
@@ -15,7 +15,11 @@ set -euo pipefail
|
|
|
15
15
|
# - HQ access (session-env.sh): proxy-injected Access markers, the allowed HQ
|
|
16
16
|
# origin, the check-run relay, and NODE_USE_ENV_PROXY=1, when the egress
|
|
17
17
|
# proxy injects HQ's Access token;
|
|
18
|
-
# - the
|
|
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.
|
|
19
23
|
#
|
|
20
24
|
# It installs no Node and no dependencies: that is the consumer's own
|
|
21
25
|
# credential-free environment setup, which must have run for this file to be
|
|
@@ -48,27 +52,12 @@ fi
|
|
|
48
52
|
export LC_ALL="${LC_ALL:-C.UTF-8}"
|
|
49
53
|
export LANG="${LANG:-C.UTF-8}"
|
|
50
54
|
|
|
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
55
|
# The package carries no 1Password resolver, so a service-account token
|
|
68
56
|
# changes nothing here: HQ access is whatever the egress proxy injects. A
|
|
69
57
|
# repository that resolves its own HQ values sets CF_ACCESS_* itself, and
|
|
70
58
|
# those win (session-env.sh).
|
|
71
59
|
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"
|
|
60
|
+
eval "$(OP_SERVICE_ACCOUNT_TOKEN='' hq_access_exports "$hq_access")"
|
|
61
|
+
eval "$(github_lane_exports)"
|
|
73
62
|
|
|
74
63
|
exec "$@"
|
|
@@ -39,18 +39,17 @@ probe_hq_access() {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
# Prints the env-file lines for HQ access: `$1` is the probe's answer (or
|
|
42
|
-
# `service-account`)
|
|
42
|
+
# `service-account`).
|
|
43
43
|
# With an injected token it marks both Access variables present
|
|
44
44
|
# (CF_ACCESS_PROXY_INJECTED in hq-access.ts, so the CLI sends no Access header
|
|
45
45
|
# of its own), names HQ as the one allowed origin, and turns on
|
|
46
46
|
# NODE_USE_ENV_PROXY: Node's fetch ignores HTTPS_PROXY without it, and HQ is
|
|
47
47
|
# reachable only through the proxy that adds the token. It also names HQ as the
|
|
48
48
|
# check-run relay (check-run-relay.ts), since the proxy refuses the session's
|
|
49
|
-
# own check-run writes
|
|
49
|
+
# own check-run writes. A value the
|
|
50
50
|
# environment already sets wins, and without an injected token nothing is
|
|
51
51
|
# printed, so the CLI still reports missing credentials.
|
|
52
52
|
hq_access_exports() {
|
|
53
|
-
local shim_bin="${2:-}"
|
|
54
53
|
[ "$1" = "injected" ] || [ -n "${OP_SERVICE_ACCOUNT_TOKEN:-}" ] || return 0
|
|
55
54
|
if [ -n "${OP_SERVICE_ACCOUNT_TOKEN:-}" ]; then
|
|
56
55
|
printf 'export FACTORY_CLOUD_MACHINE=claude-cloud\n'
|
|
@@ -67,9 +66,15 @@ hq_access_exports() {
|
|
|
67
66
|
if [ -z "${FACTORY_CHECK_RUN_RELAY_ORIGIN:-}" ]; then
|
|
68
67
|
printf 'export FACTORY_CHECK_RUN_RELAY_ORIGIN=%s\n' "$FACTORY_CLOUD_HQ_ORIGIN"
|
|
69
68
|
fi
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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'
|
|
74
79
|
fi
|
|
75
80
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { PreviewProofRegistration } from "@patronage/factory-ci";
|
|
4
3
|
import { existsSync, readFileSync, rmSync } from "node:fs";
|
|
5
4
|
/**
|
|
6
5
|
* The opt-in broker permission set (#1360): `actions: read`, `checks: read`,
|
|
@@ -2295,7 +2294,7 @@ declare const isHostedVerifyCheck: (check: StatusCheckRollup) => boolean;
|
|
|
2295
2294
|
* The workflow renames that job so the pinned `verify` context does not exist
|
|
2296
2295
|
* while the candidate is a draft. The generator that emits the workflow owns
|
|
2297
2296
|
* the literal; this is the reader's copy of it, and
|
|
2298
|
-
* `software-factory-hq/
|
|
2297
|
+
* `software-factory-hq/workflow-tests/verify-workflow.test.ts` pins the two equal.
|
|
2299
2298
|
*/
|
|
2300
2299
|
declare const HOSTED_VERIFY_DRAFT_CHECK_NAME = "verify (draft)";
|
|
2301
2300
|
/**
|
|
@@ -2676,6 +2675,60 @@ interface GitHubCheckRunMergeFreezeApi {
|
|
|
2676
2675
|
}) => unknown;
|
|
2677
2676
|
}
|
|
2678
2677
|
export declare function createGitHubCheckRunMergeFreezeStore(api: GitHubCheckRunMergeFreezeApi): MergeFreezeAuthority;
|
|
2678
|
+
declare const localPreviewStageBrand: unique symbol;
|
|
2679
|
+
type LocalPreviewStage = string & {
|
|
2680
|
+
readonly [localPreviewStageBrand]: true;
|
|
2681
|
+
};
|
|
2682
|
+
/**
|
|
2683
|
+
* Preview-proof lifecycle: admit a disposable preview, register envelope-bound
|
|
2684
|
+
* proof at head, and record cleanup. One `transition` path owns those state
|
|
2685
|
+
* changes. Recovery (#766) re-enters cleanup through the same event. Hosted
|
|
2686
|
+
* inventory listing and cleanup-outcome persistence live in
|
|
2687
|
+
* `previewProofInventory`, which sits on the registration read model `resolve`
|
|
2688
|
+
* already returns.
|
|
2689
|
+
*
|
|
2690
|
+
* Proof sits entirely on one side of GitHub's draft/ready boundary
|
|
2691
|
+
* (paitronage#1089): a draft candidate cannot begin or register. Machine
|
|
2692
|
+
* evidence is the envelope at head (#355), never a PR comment. The SHA and
|
|
2693
|
+
* repository bind that proof (#1312): a detached HEAD or a branch name that
|
|
2694
|
+
* differs from the PR head is the same commit, and the registration records
|
|
2695
|
+
* `branch: "(detached)"`.
|
|
2696
|
+
*/
|
|
2697
|
+
type PreviewProofCleanupStatus = "failed" | "passed" | "pending";
|
|
2698
|
+
interface PreviewProofRegistration {
|
|
2699
|
+
/**
|
|
2700
|
+
* Present only when the checkout is detached or its branch name is not the
|
|
2701
|
+
* PR head. The `(detached)` sentinel is on the lifecycle registration
|
|
2702
|
+
* `transition` returns, and `previewProofInventory` does not persist it.
|
|
2703
|
+
* It is not a branch to check out.
|
|
2704
|
+
*/
|
|
2705
|
+
readonly branch?: "(detached)";
|
|
2706
|
+
readonly cleanup: {
|
|
2707
|
+
readonly evidence: readonly string[];
|
|
2708
|
+
readonly outcome: PreviewProofCleanupStatus;
|
|
2709
|
+
readonly runUrl?: string;
|
|
2710
|
+
};
|
|
2711
|
+
readonly convergence: {
|
|
2712
|
+
readonly detail: string;
|
|
2713
|
+
readonly status: "passed";
|
|
2714
|
+
};
|
|
2715
|
+
readonly headSha: string;
|
|
2716
|
+
readonly pr: number;
|
|
2717
|
+
readonly proof: {
|
|
2718
|
+
readonly check: string;
|
|
2719
|
+
readonly headSha: string;
|
|
2720
|
+
readonly mergeBaseSha: string;
|
|
2721
|
+
readonly patchId: string;
|
|
2722
|
+
};
|
|
2723
|
+
readonly smoke: {
|
|
2724
|
+
readonly detail: string;
|
|
2725
|
+
readonly outcome: "passed";
|
|
2726
|
+
};
|
|
2727
|
+
readonly source: "local-self-certified";
|
|
2728
|
+
readonly stack: string;
|
|
2729
|
+
readonly stage: LocalPreviewStage;
|
|
2730
|
+
readonly url: string;
|
|
2731
|
+
}
|
|
2679
2732
|
/**
|
|
2680
2733
|
* Read a branch tip from GitHub rather than a checkout's cached remote ref.
|
|
2681
2734
|
* `gh` is injectable so a test can hand the real read a fake GitHub.
|