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

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 CHANGED
@@ -77,3 +77,28 @@ npx skills add https://github.com/patronage/software-factory -g --all
77
77
  They provide procedure and link back to the documentation site; they are not a second command reference.
78
78
 
79
79
  `assembleReviewPrompt` puts a repository-root `CODING_STANDARDS.md` into the correctness prompt when the file exists and is not blank. It reads the file at the candidate head, not from the working tree, and emits one `coding-standards` section that names the head SHA. A repository without the file gets an unchanged prompt. `pr:review --assemble` writes that factory-owned prompt under `.factory-memory/pr-review-prompt.json`. `pr:review --findings` copies the recorded sections onto the proof when the artifact's patch-id matches.
80
+
81
+ ## Cloud credential adapters
82
+
83
+ The `@patronage/software-factory/cloud` subpath provides `cloudCredentialEnvironment(env, references)` and `readCloudSecret(ref, env)`. Repository adapters supply an explicit map from child environment variable names to reviewed `op://vault/item/field` references. The module supplies no vault, item, runtime, command or deployment defaults. It uses only `op-fast item get`, keeps values in memory, suppresses resolver output in errors, and strips 1Password authority, reference variables and unrelated Factory HQ/D1/npm credentials from the returned child environment. The caller's environment is unchanged. This is credential delivery, not a general environment sandbox.
84
+
85
+ ```js
86
+ import { spawnSync } from "node:child_process";
87
+
88
+ import { cloudCredentialEnvironment } from "@patronage/software-factory/cloud";
89
+
90
+ // Repository-owned policy selects its runtime and approved item references.
91
+ const env = cloudCredentialEnvironment(process.env, {
92
+ CF_ACCESS_CLIENT_ID: process.env.FACTORY_HQ_CLIENT_ID_REF,
93
+ CF_ACCESS_CLIENT_SECRET: process.env.FACTORY_HQ_CLIENT_SECRET_REF,
94
+ });
95
+ const result = spawnSync("psf", ["doctor", "--preflight"], {
96
+ env,
97
+ stdio: "inherit",
98
+ });
99
+ process.exitCode = result.status ?? 1;
100
+ ```
101
+
102
+ Install tools without credentials during the environment build, after the repository's own dependency installation. Resolve the shipped installer with `import.meta.resolve("@patronage/software-factory/cloud/install-tools.sh")`, convert that file URL with `fileURLToPath`, and run it through Bash with an absolute bin directory argument. It installs checksum-pinned Linux binaries; macOS, unsupported architectures and archive mismatches fail closed. Put that bin directory on the runtime PATH using the repository's existing setup path. Never resolve secrets during the build or write resolved values to shell profiles or hook export files. The module needs Node 24 and a runtime `OP_SERVICE_ACCOUNT_TOKEN`; it does not install tools or select a runtime.
103
+
104
+ These exports ship from `1.0.0-alpha.47`; `1.0.0-alpha.46` and earlier do not have them. Consumer adoption must pin alpha.47 or later and validate its packed artifact before changing live startup paths. See the source repository's `docs/agents/cloud-setup.md` for Factory-only rollout policy and acceptance.
@@ -0,0 +1,21 @@
1
+ /** Explicit, reviewed repository policy: child environment key to op:// reference. */
2
+ export type CloudCredentialReferences = Readonly<Record<string, string>>;
3
+ export type CloudEnvironment = Record<string, string | undefined>;
4
+ export type CloudSecretReader = (
5
+ reference: string,
6
+ env: CloudEnvironment
7
+ ) => string;
8
+ export declare class CloudSecretError extends Error {
9
+ readonly name = "CloudSecretError";
10
+ }
11
+ /** op-fast item get; no kernel keyring, stock-op fallback, or output diagnostics. */
12
+ export function readCloudSecret(
13
+ reference: string,
14
+ env: CloudEnvironment
15
+ ): string;
16
+ /** Resolves selected credentials in memory, strips vault and unrelated provider authority. */
17
+ export function cloudCredentialEnvironment(
18
+ env: CloudEnvironment,
19
+ credentials: CloudCredentialReferences,
20
+ read?: CloudSecretReader
21
+ ): CloudEnvironment;
@@ -0,0 +1,136 @@
1
+ // Shared cloud credential mechanics. Callers own references and runtime policy.
2
+ import { spawnSync } from "node:child_process";
3
+
4
+ export class CloudSecretError extends Error {
5
+ name = "CloudSecretError";
6
+ }
7
+
8
+ // Capture both streams: resolver errors can quote secret material. Never attach
9
+ // an underlying error/cause or include captured output in a diagnostic.
10
+ export function readCloudSecret(reference, env) {
11
+ if (!env.OP_SERVICE_ACCOUNT_TOKEN) {
12
+ throw new CloudSecretError(
13
+ "Cloud credentials require OP_SERVICE_ACCOUNT_TOKEN."
14
+ );
15
+ }
16
+ const match =
17
+ /^op:\/\/(?<vault>[^/\r\n]+)\/(?<item>[^/\r\n]+)\/(?<field>[^/\r\n]+)$/u.exec(
18
+ reference
19
+ );
20
+ if (!match?.groups) {
21
+ throw new CloudSecretError("Invalid cloud credential reference.");
22
+ }
23
+ const { vault, item, field } = match.groups;
24
+ const resolverEnv = {
25
+ ...Object.fromEntries(
26
+ Object.entries(env).filter(
27
+ ([key]) =>
28
+ !key.startsWith("OP_SESSION") &&
29
+ !["OP_ACCOUNT", "OP_CONNECT_HOST", "OP_CONNECT_TOKEN"].includes(key)
30
+ )
31
+ ),
32
+ OP_BIOMETRIC_UNLOCK_ENABLED: "false",
33
+ };
34
+ let result;
35
+ try {
36
+ result = spawnSync(
37
+ "op-fast",
38
+ ["item", "get", item, "--vault", vault, "--format=json"],
39
+ {
40
+ encoding: "utf-8",
41
+ env: resolverEnv,
42
+ maxBuffer: 256 * 1024,
43
+ stdio: ["ignore", "pipe", "pipe"],
44
+ timeout: 10_000,
45
+ }
46
+ );
47
+ } catch {
48
+ throw new CloudSecretError(
49
+ "Cloud credential resolution failed; check op-fast, vault access and network access."
50
+ );
51
+ }
52
+ let value;
53
+ try {
54
+ const { fields } = JSON.parse(result.stdout);
55
+ const matches = fields.filter(
56
+ (candidate) => candidate.id === field || candidate.label === field
57
+ );
58
+ if (matches.length === 1) {
59
+ [{ value }] = matches;
60
+ }
61
+ } catch {
62
+ // Malformed provider output must not be included in a diagnostic.
63
+ }
64
+ if (
65
+ result.error ||
66
+ result.status !== 0 ||
67
+ typeof value !== "string" ||
68
+ !value ||
69
+ value.startsWith("op://") ||
70
+ /[\r\n\0]/u.test(value)
71
+ ) {
72
+ throw new CloudSecretError(
73
+ "Cloud credential resolution failed; check op-fast, vault access and network access."
74
+ );
75
+ }
76
+ return value;
77
+ }
78
+
79
+ // Resolve only explicitly selected references and hand a consuming child no
80
+ // vault authority or unrelated Factory provider credentials. No defaults here:
81
+ // vault/item choices and the command/purpose decision belong to the repository.
82
+ export function cloudCredentialEnvironment(
83
+ env,
84
+ credentials,
85
+ read = readCloudSecret
86
+ ) {
87
+ if (!env.OP_SERVICE_ACCOUNT_TOKEN) {
88
+ throw new CloudSecretError(
89
+ "Cloud credentials require OP_SERVICE_ACCOUNT_TOKEN."
90
+ );
91
+ }
92
+ if (env.OP_CONNECT_HOST || env.OP_CONNECT_TOKEN) {
93
+ throw new CloudSecretError(
94
+ "Remove 1Password Connect settings before using the cloud service account."
95
+ );
96
+ }
97
+ const entries = Object.entries(credentials);
98
+ if (
99
+ !entries.length ||
100
+ entries.some(
101
+ ([key, ref]) =>
102
+ !key ||
103
+ key.startsWith("OP_") ||
104
+ /^FACTORY_.*_REF$/u.test(key) ||
105
+ !/^op:\/\/[^/\r\n]+\/[^/\r\n]+\/[^/\r\n]+$/u.test(ref)
106
+ )
107
+ ) {
108
+ throw new CloudSecretError(
109
+ "Cloud credentials require explicit environment keys and op:// references."
110
+ );
111
+ }
112
+ const unrelatedCredentials = new Set([
113
+ // Legacy repository tools also read the HTTP header names from env.
114
+ "CF-Access-Client-Id",
115
+ "CF-Access-Client-Secret",
116
+ "CF_ACCESS_CLIENT_ID",
117
+ "CF_ACCESS_CLIENT_SECRET",
118
+ "CLOUDFLARE_API_TOKEN",
119
+ "CLOUDFLARE_READ_ONLY_API_TOKEN",
120
+ "NPM_TOKEN",
121
+ "NODE_AUTH_TOKEN",
122
+ "npm_config_//registry.npmjs.org/:_authToken",
123
+ ]);
124
+ const child = Object.fromEntries(
125
+ Object.entries(env).filter(
126
+ ([key]) =>
127
+ !key.startsWith("OP_") &&
128
+ !/^FACTORY_.*_REF$/u.test(key) &&
129
+ !unrelatedCredentials.has(key)
130
+ )
131
+ );
132
+ for (const [key, ref] of entries) {
133
+ child[key] = read(ref, env);
134
+ }
135
+ return child;
136
+ }
@@ -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.'