From bb1773692e224673ed6e2d43297b9392a837f414 Mon Sep 17 00:00:00 2001 From: nodemode-ai Date: Wed, 25 Nov 2026 21:20:37 -0500 Subject: [PATCH 1/4] feat(propose): plan runs the generator with no token, changed lists the plans, apply re-checks a plan and proposes it without running target code --- .github/workflows/propose.yml | 111 -------------- scripts/HASHOUT_LOG.md | 19 +++ scripts/propose.py | 263 ++++++++++++++++++++++++++++++++++ 3 files changed, 282 insertions(+), 111 deletions(-) delete mode 100644 .github/workflows/propose.yml diff --git a/.github/workflows/propose.yml b/.github/workflows/propose.yml deleted file mode 100644 index e46e2fa..0000000 --- a/.github/workflows/propose.yml +++ /dev/null @@ -1,111 +0,0 @@ -name: propose - -on: - workflow_call: - inputs: - target: - type: string - required: false - default: "" - secrets: - FORMADAPTOR_APP_ID: - required: true - FORMADAPTOR_APP_PRIVATE_KEY: - required: true - workflow_dispatch: - inputs: - target: - description: "One target name from targets.json; empty for every enabled target" - required: false - default: "" - -permissions: - contents: read - -concurrency: - group: propose - cancel-in-progress: false - -jobs: - targets: - if: github.repository == 'nodemode-dev/formadaptor' && github.ref == 'refs/heads/main' - runs-on: ubuntu-24.04 - timeout-minutes: 5 - outputs: - matrix: ${{ steps.list.outputs.matrix }} - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - name: The enabled targets - id: list - run: echo "matrix=$(python3 -I scripts/propose.py matrix)" >> "$GITHUB_OUTPUT" - - propose: - needs: targets - if: github.repository == 'nodemode-dev/formadaptor' && github.ref == 'refs/heads/main' && needs.targets.outputs.matrix != '[]' - runs-on: ubuntu-24.04 - timeout-minutes: 30 - strategy: - fail-fast: false - matrix: - include: ${{ fromJSON(needs.targets.outputs.matrix) }} - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - if: inputs.target == '' || inputs.target == matrix.name - with: - path: adaptor - persist-credentials: false - - name: The family spec - if: inputs.target == '' || inputs.target == matrix.name - env: - GH_TOKEN: ${{ github.token }} - run: python3 -I adaptor/scripts/spec.py fetch --out "$RUNNER_TEMP/family.json" --previous-out "$RUNNER_TEMP/previous.json" - - name: App token for this target only - id: app-token - if: inputs.target == '' || inputs.target == matrix.name - continue-on-error: true - uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 - with: - client-id: ${{ secrets.FORMADAPTOR_APP_ID }} - private-key: ${{ secrets.FORMADAPTOR_APP_PRIVATE_KEY }} - owner: nodemode-dev - repositories: ${{ matrix.repo }} - permission-contents: write - permission-pull-requests: write - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - id: target - if: (inputs.target == '' || inputs.target == matrix.name) && steps.app-token.outcome == 'success' - continue-on-error: true - with: - repository: ${{ matrix.repository }} - ref: main - path: target - token: ${{ steps.app-token.outputs.token }} - persist-credentials: false - - name: Is the target reachable - id: reach - if: inputs.target == '' || inputs.target == matrix.name - env: - TOKEN_OUTCOME: ${{ steps.app-token.outcome }} - CHECKOUT_OUTCOME: ${{ steps.target.outcome }} - TARGET: ${{ matrix.name }} - REPOSITORY: ${{ matrix.repository }} - run: | - if [ "$TOKEN_OUTCOME" = success ] && [ "$CHECKOUT_OUTCOME" = success ]; then - echo "ok=true" >> "$GITHUB_OUTPUT" - else - echo "$TARGET: $REPOSITORY is not reachable (not created yet, no main, or the App is not installed on it), skipped" | tee -a "$GITHUB_STEP_SUMMARY" - echo "ok=false" >> "$GITHUB_OUTPUT" - fi - - name: The apps at their released tags, where the target's generator reads them - if: steps.reach.outputs.ok == 'true' - env: - TARGET: ${{ matrix.name }} - run: python3 -I adaptor/scripts/propose.py checkouts --target "$TARGET" --checkout target --family "$RUNNER_TEMP/family.json" - - name: Run the target's generator and propose the difference - if: steps.reach.outputs.ok == 'true' - env: - FORMADAPTOR_TARGET_TOKEN: ${{ steps.app-token.outputs.token }} - TARGET: ${{ matrix.name }} - run: python3 -I adaptor/scripts/propose.py run --target "$TARGET" --checkout target --family "$RUNNER_TEMP/family.json" --previous "$RUNNER_TEMP/previous.json" diff --git a/scripts/HASHOUT_LOG.md b/scripts/HASHOUT_LOG.md index 735c3ee..cb65112 100644 --- a/scripts/HASHOUT_LOG.md +++ b/scripts/HASHOUT_LOG.md @@ -5,6 +5,25 @@ Living log of all comment content, explainers, rationale, TODOs and removed code Current build version: v0.2.3 Last updated: 2026-11-25 · FormCraft's and FormRig's id pairs (v0.2.3) +### propose.py · plan, changed and apply; no secret in this repository +- refers-to: scripts/propose.py :: plan_command, write_plan, changed_plans, checked_plan, apply_plan, apply_command; .github/workflows/hourly.yml; tests/test_workflows.py :: test_no_workflow_holds_a_secret +- kind: change +- logged: v0.3.0 · 2026-11-26 + +The owner ruled that formadaptor holds no secret. Proposing moves to formcompiler's `adaptor.yml`, which holds formcompiler's release App. formcompiler's rule is that a job holding its release credential never runs another repository's code, and a target's generator is exactly that, so `run` is split in two. `run` stays, for a local dry run and for anything that still calls it. + +`plan` does what `run` does up to `plan(...)` and writes the result into a new, empty folder: `proposal.json` (format `formadaptor-plan`, version 1) and `files/`, a byte copy of each changed file that still exists. The proposal dict now carries `change_hash`, the full digest the branch name is cut from, so `apply` can compare without running anything. In the plan file the changed paths are `paths` and `files` is the list of `{path, sha256}` or `{path, deleted: true}`. `base` is the checkout's HEAD before the generator ran; a generator that moves HEAD is refused. A file the generator leaves as a link, or a path that goes through a link in the checkout, is refused rather than copied. It writes `changed=true|false`; nothing to propose writes no plan. + +`changed --plans DIR` lists, as `matrix` does, the enabled targets that have a `plan-/proposal.json` naming that target. Anything else is skipped with a `::warning::` on stderr, never a failure, and a missing or empty folder is `[]`. + +`apply` trusts nothing in the plan, because the job that wrote it ran the target's code. Before it touches the checkout it checks: format and version; target and repository against targets.json; base a 40-hex sha and change hash a 64-hex sha; the branch is the target's `branch_prefix` and the first 10 characters of that hash (stricter than "starts with the prefix", and it is what `plan` writes); every path relative, without `..`, `.` or empty parts, backslash or control character, and `allowed` by the target's files; `paths` exactly the sorted listed files; every entry under `files/` a plain file that is listed and matches its sha256, no link anywhere, and every listed copy present. Title and body are passed on as text, cut at 200 and 60,000 characters. Untrusted values in error lines are quoted with `repr`, so a name with a newline cannot start a workflow command; the plan's warning reaches the summary with control characters replaced and is not printed as `::warning::` (the plan job already did that). + +If the checkout's HEAD is not the plan's base, `apply` writes one summary line, `proposed=false`, exits 0 and pushes nothing. Otherwise it refuses a dirty checkout or a path that goes through a link in the checkout, copies and deletes, and refuses unless `git status` names exactly the plan's paths and `change_hash` over them equals the plan's. Then `propose(...)` as `run` calls it, with the same summary lines and `proposed` output. It runs no generator and nothing from the checkout. + +hourly.yml loses its `propose` job and propose.yml is gone; the workflow test that read propose.yml's App token now checks that no workflow here names a secret. + +Rehearsed 2026-11-26 in a scratch folder with a local bare repository as the target, `FORMADAPTOR_GIT_BASE` pointing at it and a local stand-in for the API: plan wrote two files and `changed=true`; changed listed the one good plan and warned on four bad entries; apply refused a path outside the target's files, a wrong sha256, a link in the plan, another repository, a `..` path and a branch outside the prefix, each before touching the checkout; the real apply pushed `bot/formadaptor-b61b29ee1d` as nodemode-ai and opened the stand-in pull request; after main moved it wrote the one line and `proposed=false`. The suite: 82 passed. + ### ids.json · rows 36 and 37, FormCraft and FormRig - refers-to: spec/ids.json; tests/test_sources.py :: test_ids_file_pairs_every_registry_entry_once - kind: fix diff --git a/scripts/propose.py b/scripts/propose.py index 3527213..850d72c 100644 --- a/scripts/propose.py +++ b/scripts/propose.py @@ -21,6 +21,12 @@ APP_CHECKOUTS = re.compile(r"^\.\./(?!\.{1,2}$)[A-Za-z0-9._-]+$") APP_REPO = re.compile(r"^[A-Za-z0-9._-]+$") APP_TAG = re.compile(r"^v\d+\.\d+\.\d+$") +CONTROL = re.compile(r"[\x00-\x1f\x7f-\x9f]") +HEX40 = re.compile(r"^[0-9a-f]{40}$") +HEX64 = re.compile(r"^[0-9a-f]{64}$") +PLAN_FORMAT = "formadaptor-plan" +TITLE_LIMIT = 200 +BODY_LIMIT = 60000 BASE = "main" IDENTITY = ("nodemode-ai", "mackin@nodemode.ai") GENERATOR_TIMEOUT = 600 @@ -236,6 +242,7 @@ def plan(target, checkout, family, previous=None): "target": target["name"], "repository": target["repository"], "branch": f"{target['branch_prefix']}{digest[:10]}", + "change_hash": digest, "files": paths, "title": spec.title(previous_doc, family_doc), "body": body_of(target, family_doc, previous_doc, paths), @@ -280,6 +287,240 @@ def propose(gh, checkout, target, proposal, token): return pull, closed +def sha256_of(path): + return hashlib.sha256(Path(path).read_bytes()).hexdigest() + + +def head(checkout): + return git(checkout, "rev-parse", "--verify", "HEAD^{commit}").strip() + + +def plain_path(path, files): + return (isinstance(path, str) and 0 < len(path) <= 1024 and not path.startswith("/") and "\\" not in path and not CONTROL.search(path) + and all(part not in ("", ".", "..") for part in path.split("/")) and allowed(path, files)) + + +def write_plan(target, checkout, proposal, base, out): + out = Path(out) + if out.is_symlink() or (out.exists() and (not out.is_dir() or any(out.iterdir()))): + raise ProposeError(f"{target['name']}: {out} is not a new, empty folder for the plan") + entries = [] + for path in proposal["files"]: + source = Path(checkout) / path + if not inside(checkout, path): + raise ProposeError(f"{target['name']}: the generator left {path!r} as a link; only plain files are proposed") + if source.is_file(): + copy = out / "files" / path + copy.parent.mkdir(parents=True, exist_ok=True) + copy.write_bytes(source.read_bytes()) + entries.append({"path": path, "sha256": sha256_of(copy)}) + elif source.exists(): + raise ProposeError(f"{target['name']}: {path!r} is not a plain file") + else: + entries.append({"path": path, "deleted": True}) + doc = { + "format": PLAN_FORMAT, "format_version": 1, "target": target["name"], "repository": target["repository"], "base": base, + "branch": proposal["branch"], "change_hash": proposal["change_hash"], "paths": proposal["files"], + "title": proposal["title"], "body": proposal["body"], "warning": proposal["warning"], "files": entries, + } + out.mkdir(parents=True, exist_ok=True) + (out / "proposal.json").write_text(json.dumps(doc, indent=2, ensure_ascii=False) + "\n", encoding="utf-8") + return doc + + +def read_plan_doc(plandir): + plandir = Path(plandir) + if plandir.is_symlink() or not plandir.is_dir(): + raise ProposeError(f"{str(plandir)!r} is not a plan folder") + doc_path = plandir / "proposal.json" + if doc_path.is_symlink() or not doc_path.is_file(): + raise ProposeError(f"{str(plandir)!r} holds no plain proposal.json") + try: + doc = json.loads(doc_path.read_text(encoding="utf-8")) + except (OSError, UnicodeDecodeError, json.JSONDecodeError) as error: + raise ProposeError(f"proposal.json does not load: {str(error)[:200]!r}") from None + if not isinstance(doc, dict) or doc.get("format") != PLAN_FORMAT or doc.get("format_version") != 1: + raise ProposeError(f"proposal.json is not a {PLAN_FORMAT} version 1 file") + return doc + + +def checked_plan(target, plandir): + plandir = Path(plandir) + doc = read_plan_doc(plandir) + name = target["name"] + if doc.get("target") != name: + raise ProposeError(f"{name}: the plan names the target {str(doc.get('target'))[:60]!r}") + if doc.get("repository") != target["repository"]: + raise ProposeError(f"{name}: the plan names the repository {str(doc.get('repository'))[:100]!r}, not {target['repository']}") + base, digest, branch = doc.get("base"), doc.get("change_hash"), doc.get("branch") + if not (isinstance(base, str) and HEX40.match(base)): + raise ProposeError(f"{name}: the plan's base is not a commit sha") + if not (isinstance(digest, str) and HEX64.match(digest)): + raise ProposeError(f"{name}: the plan's change hash is not a sha256") + if not (isinstance(branch, str) and branch.startswith(target["branch_prefix"]) and branch == f"{target['branch_prefix']}{digest[:10]}"): + raise ProposeError(f"{name}: the plan's branch {str(branch)[:100]!r} is not {target['branch_prefix']} and its change hash") + title, body, warning = doc.get("title"), doc.get("body"), doc.get("warning") + if not isinstance(title, str) or not title.strip() or not isinstance(body, str) or not (warning is None or isinstance(warning, str)): + raise ProposeError(f"{name}: the plan's title, body or warning is not text") + paths, entries = doc.get("paths"), doc.get("files") + if not isinstance(paths, list) or not paths or not isinstance(entries, list) or len(entries) != len(paths): + raise ProposeError(f"{name}: the plan lists no files, or its paths and files differ") + copied, deleted = {}, set() + for entry in entries: + path = entry.get("path") if isinstance(entry, dict) else None + if not plain_path(path, target["files"]): + raise ProposeError(f"{name}: the plan names {str(path)[:200]!r}, which is not one of the target's files") + if path in copied or path in deleted: + raise ProposeError(f"{name}: the plan names {path!r} twice") + if set(entry) == {"path", "deleted"} and entry["deleted"] is True: + deleted.add(path) + elif set(entry) == {"path", "sha256"} and isinstance(entry["sha256"], str) and HEX64.match(entry["sha256"]): + copied[path] = entry["sha256"] + else: + raise ProposeError(f"{name}: the plan's entry for {path!r} is neither a copied file with its sha256 nor a deletion") + if paths != sorted(set(copied) | deleted) or not all(isinstance(p, str) for p in paths): + raise ProposeError(f"{name}: the plan's paths are not exactly its files, in order") + root = plandir / "files" + found = set() + if root.is_symlink() or (root.exists() and not root.is_dir()): + raise ProposeError(f"{name}: the plan's files folder is a link or not a folder") + for folder, dirs, names in os.walk(root, followlinks=False): + for entry in dirs + names: + full = Path(folder) / entry + rel = full.relative_to(root).as_posix() + if full.is_symlink(): + raise ProposeError(f"{name}: the plan holds a link, {rel[:200]!r}") + if full.is_dir(): + continue + if not full.is_file() or rel not in copied: + raise ProposeError(f"{name}: the plan holds {rel[:200]!r}, which it does not list as a copied file") + if sha256_of(full) != copied[rel]: + raise ProposeError(f"{name}: {rel!r} in the plan does not match its listed sha256") + found.add(rel) + if found != set(copied): + raise ProposeError(f"{name}: the plan lists {', '.join(sorted(set(copied) - found))[:300]!r} but does not hold them") + return { + "base": base, + "plandir": plandir, + "deleted": sorted(deleted), + "proposal": {"warning": warning, "target": name, "repository": target["repository"], "branch": branch, "change_hash": digest, + "files": paths, "title": title[:TITLE_LIMIT], "body": body[:BODY_LIMIT]}, + } + + +def inside(checkout, path): + root = Path(checkout).resolve() + current = root + for part in path.split("/"): + current = current / part + if current.is_symlink(): + return False + return root in (root / path).resolve().parents + + +def apply_plan(target, checkout, checked): + checkout = Path(checkout) + for path in checked["proposal"]["files"]: + if not inside(checkout, path): + raise ProposeError(f"{target['name']}: {path!r} would be written through a link in the checkout") + for path in checked["proposal"]["files"]: + full = checkout / path + if path in checked["deleted"]: + if full.is_file(): + full.unlink() + elif full.exists(): + raise ProposeError(f"{target['name']}: {path!r} is not a plain file in the checkout") + else: + if full.exists() and not full.is_file(): + raise ProposeError(f"{target['name']}: {path!r} is not a plain file in the checkout") + full.parent.mkdir(parents=True, exist_ok=True) + full.write_bytes((checked["plandir"] / "files" / path).read_bytes()) + + +def changed_plans(plans, targets): + enabled = {t["name"]: t for t in targets if t["enabled"]} + rows = [] + root = Path(plans) + if not root.is_dir(): + return rows + for folder in sorted(root.iterdir()): + label = repr(folder.name[:80]) + if folder.is_symlink() or not folder.is_dir() or not folder.name.startswith("plan-"): + print(f"::warning::{label} is not a plan folder, skipped", file=sys.stderr) + continue + name = folder.name[len("plan-"):] + if name not in enabled: + print(f"::warning::{label} names no enabled target, skipped", file=sys.stderr) + continue + try: + doc = read_plan_doc(folder) + except ProposeError as error: + print(f"::warning::{label}: {error}, skipped", file=sys.stderr) + continue + if doc.get("target") != name: + print(f"::warning::{label}: its proposal.json names another target, skipped", file=sys.stderr) + continue + target = enabled[name] + rows.append({"name": name, "repository": target["repository"], "repo": target["repository"].split("/", 1)[1]}) + return rows + + +def plan_command(target, args): + if not target["enabled"]: + print(f"{target['name']}: disabled in targets.json, nothing to do") + output("changed", "false") + return 0 + checkout = Path(args.checkout) + base = head(checkout) + proposal = plan(target, checkout, args.family, args.previous) + if proposal is None: + summary(f"{target['name']}: in step with the family spec, nothing to propose\n") + output("changed", "false") + return 0 + if head(checkout) != base: + raise ProposeError(f"{target['name']}: the generator moved the checkout's HEAD") + if proposal["warning"]: + print(f"::warning::{proposal['warning']}") + summary(f"Warning: {proposal['warning']}. The proposal is not held back.\n") + doc = write_plan(target, checkout, proposal, base, args.out) + print(f"{target['name']}: planned {proposal['branch']} on {base[:10]}, {len(doc['files'])} files") + output("changed", "true") + return 0 + + +def apply_command(target, args): + if not target["enabled"]: + print(f"{target['name']}: disabled in targets.json, nothing to do") + output("proposed", "false") + return 0 + token = os.environ.get("FORMADAPTOR_TARGET_TOKEN", "").strip() + if not token: + raise ProposeError("FORMADAPTOR_TARGET_TOKEN is not set") + checked = checked_plan(target, args.plan) + proposal = checked["proposal"] + checkout = Path(args.checkout) + if head(checkout) != checked["base"]: + summary(f"{target['name']}: main moved since the plan was made on {checked['base'][:10]}; nothing is pushed, the next run proposes again\n") + output("proposed", "false") + return 0 + if git(checkout, "status", "--porcelain").strip(): + raise ProposeError(f"{target['name']}: the checkout is not clean before the plan is applied") + apply_plan(target, checkout, checked) + if changed_files(checkout) != proposal["files"] or change_hash(checkout, proposal["files"]) != proposal["change_hash"]: + raise ProposeError(f"{target['name']}: the applied files do not give the plan's change hash") + if proposal["warning"]: + summary(f"Warning: {CONTROL.sub(' ', proposal['warning'])[:1000]}. The proposal is not held back.\n") + pull, closed = propose(GitHub(token=token), checkout, target, proposal, token) + if pull is None: + summary(f"{target['name']}: {proposal['branch']} is already open, nothing new to propose\n") + output("proposed", "false") + return 0 + summary(f"{target['name']}: opened {pull.get('html_url', '#' + str(pull['number']))} from {proposal['branch']}" + + (f", closed {', '.join('#' + str(n) for n in closed)} as superseded" if closed else "") + "\n") + output("proposed", "true") + return 0 + + def main(): parser = argparse.ArgumentParser(description="run a target's generator against the family spec and propose the difference") sub = parser.add_subparsers(dest="command", required=True) @@ -296,6 +537,21 @@ def main(): apps.add_argument("--checkout", required=True, help="the checkout of the target repository the generator will run in") apps.add_argument("--family", required=True) apps.add_argument("--targets", default=str(TARGETS)) + planned = sub.add_parser("plan", help="run the target's generator and write what it would propose into a plan folder; no token") + planned.add_argument("--target", required=True) + planned.add_argument("--checkout", required=True, help="a clean checkout of the target repository at main") + planned.add_argument("--family", required=True) + planned.add_argument("--previous", help="the spec before this one, for the title") + planned.add_argument("--out", required=True, help="a new folder for proposal.json and files/") + planned.add_argument("--targets", default=str(TARGETS)) + found = sub.add_parser("changed", help="the enabled targets that have a plan, as a JSON list for a workflow matrix") + found.add_argument("--plans", required=True, help="one plan- folder per plan") + found.add_argument("--targets", default=str(TARGETS)) + applied = sub.add_parser("apply", help="check a plan, copy its files into the checkout and propose them; runs no target code") + applied.add_argument("--target", required=True) + applied.add_argument("--checkout", required=True, help="a clean checkout of the target repository at main") + applied.add_argument("--plan", required=True) + applied.add_argument("--targets", default=str(TARGETS)) args = parser.parse_args() try: if args.command == "matrix": @@ -313,7 +569,14 @@ def main(): fetched = fetch_apps(target, Path(args.checkout), family_doc) print(f"{target['name']}: {len(fetched)} public apps at their released tags in {target['app_checkouts']}") return 0 + if args.command == "changed": + print(json.dumps(changed_plans(args.plans, load_targets(args.targets)), separators=(",", ":"))) + return 0 target = find(load_targets(args.targets), args.target) + if args.command == "plan": + return plan_command(target, args) + if args.command == "apply": + return apply_command(target, args) if not target["enabled"]: print(f"{target['name']}: disabled in targets.json, nothing to do") output("proposed", "false") From 5b0daa1ac7a0ea40cc9defc55970d1a688a928ab Mon Sep 17 00:00:00 2001 From: nodemode-ai Date: Wed, 25 Nov 2026 21:20:37 -0500 Subject: [PATCH 2/4] ci: formadaptor proposes nothing itself; the hourly run builds and publishes the spec, and propose.yml is gone --- .github/workflows/hourly.yml | 10 ---------- tests/test_workflows.py | 24 +++++++----------------- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/.github/workflows/hourly.yml b/.github/workflows/hourly.yml index a646c3c..f34dab1 100644 --- a/.github/workflows/hourly.yml +++ b/.github/workflows/hourly.yml @@ -70,13 +70,3 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: python3 -I scripts/spec.py publish --file "$RUNNER_TEMP/spec/family.json" - - propose: - needs: publish - if: github.repository == 'nodemode-dev/formadaptor' && github.ref == 'refs/heads/main' - permissions: - contents: read - uses: ./.github/workflows/propose.yml - secrets: - FORMADAPTOR_APP_ID: ${{ secrets.FORMADAPTOR_APP_ID }} - FORMADAPTOR_APP_PRIVATE_KEY: ${{ secrets.FORMADAPTOR_APP_PRIVATE_KEY }} diff --git a/tests/test_workflows.py b/tests/test_workflows.py index 2b8712d..05230b0 100644 --- a/tests/test_workflows.py +++ b/tests/test_workflows.py @@ -49,7 +49,7 @@ def test_scripts_run_isolated(path): pytest.fail(line) -@pytest.mark.parametrize("name", ["hourly.yml", "propose.yml"]) +@pytest.mark.parametrize("name", ["hourly.yml"]) def test_every_job_that_publishes_or_proposes_is_guarded(name): for job, body in jobs((REPO / ".github" / "workflows" / name).read_text()).items(): assert GUARD in body and "github.ref == 'refs/heads/main'" in body, f"{name}: {job}" @@ -67,22 +67,12 @@ def test_the_hourly_run_is_at_minute_33(): assert 'cron: "33 * * * *"' in (REPO / ".github" / "workflows" / "hourly.yml").read_text() -def test_the_app_token_is_for_one_repository(): - text = (REPO / ".github" / "workflows" / "propose.yml").read_text() - assert "repositories: ${{ matrix.repo }}" in text - assert "client-id: ${{ secrets.FORMADAPTOR_APP_ID }}" in text and "private-key: ${{ secrets.FORMADAPTOR_APP_PRIVATE_KEY }}" in text - assert text.count("persist-credentials: false") == text.count("actions/checkout@") - - -def test_a_target_that_cannot_be_reached_is_a_skip_and_its_apps_are_fetched_first(): - steps = (REPO / ".github" / "workflows" / "propose.yml").read_text().split("\n - ") - token = next(s for s in steps if "id: app-token" in s) - fetch = next(s for s in steps if "propose.py checkouts" in s) - run = next(s for s in steps if "propose.py run" in s) - assert "continue-on-error: true" in token - assert "is not reachable" in next(s for s in steps if "id: reach" in s) - assert all("if: steps.reach.outputs.ok == 'true'" in s for s in (fetch, run)) - assert steps.index(fetch) < steps.index(run) and "FORMADAPTOR_TARGET_TOKEN" not in fetch +def test_no_workflow_holds_a_secret(): + assert [p.name for p in WORKFLOWS] == ["hourly.yml", "self-check.yml"] + for path in WORKFLOWS: + text = path.read_text() + assert "secrets." not in text and "FORMADAPTOR_APP" not in text, path.name + assert text.count("persist-credentials: false") == text.count("actions/checkout@"), path.name def test_every_version_site_agrees(): From 058ed9295c4661f9e96461a45b07cc217c8752d3 Mon Sep 17 00:00:00 2001 From: nodemode-ai Date: Wed, 25 Nov 2026 21:21:47 -0500 Subject: [PATCH 3/4] docs: formadaptor holds no secret; formcompiler's adaptor.yml proposes with its release App, planning with no secret and applying with no target code --- CONTRIBUTING.md | 2 +- README.md | 4 +++- SECURITY.md | 6 +++--- docs/OWNER_SETUP.md | 12 ++++++------ docs/TARGETS.md | 6 +++--- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f52e3be..69a0eb5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,7 +14,7 @@ You need Python 3.11 or newer. The scripts use the standard library only; the te | Folder | What is there | | --- | --- | -| `.github/workflows` | hourly, propose and self-check | +| `.github/workflows` | hourly and self-check; proposing is formcompiler's `adaptor.yml`, which runs `propose.py plan`, `changed` and `apply` | | `scripts` | github_api, registry, visibility, releases, manifest, spec and propose | | `spec` | the id pairs and the two schemas | | `docs` | the spec, the target contract and the owner setup | diff --git a/README.md b/README.md index c983e1a..cb110bc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ One family spec for the Form apps, and pull requests that keep every repository that lists the apps in step with it. -formadaptor reads formcompiler's registry, asks GitHub which app repositories are public and which release each public app last published, and writes `family.json`. It then runs each target repository's own generator against that file and opens a pull request in the target when its committed files differ. The targets are formMCP, formskills, form.ext and formai-templates (the organisation profile is listed and off); formai-templates gathers each public app's templates and demos, so before its generator runs formadaptor puts a shallow clone of each public app at its released tag beside the checkout. Each target keeps a copy of the spec its files were generated from and checks itself against it in its own CI. A target's generated files change only when something that target shows changes: they never carry the registry version, the spec's build time or its hash, so a compiler release that changes nothing a target shows proposes nothing, and a run warns when a generator records anything else. Every hour formadaptor also reports, without acting, where an app's `main` offers agents something its newest release does not. It never pushes to `main` anywhere and never runs app code. +formadaptor reads formcompiler's registry, asks GitHub which app repositories are public and which release each public app last published, and writes `family.json`. Its `scripts/propose.py` then runs each target repository's own generator against that file and opens a pull request in the target when its committed files differ; formcompiler's `adaptor.yml` runs it in two jobs, `plan` with no secret and `apply` with the token and no target code, and formadaptor itself holds no secret. The targets are formMCP, formskills, form.ext and formai-templates (the organisation profile is listed and off); formai-templates gathers each public app's templates and demos, so before its generator runs formadaptor puts a shallow clone of each public app at its released tag beside the checkout. Each target keeps a copy of the spec its files were generated from and checks itself against it in its own CI. A target's generated files change only when something that target shows changes: they never carry the registry version, the spec's build time or its hash, so a compiler release that changes nothing a target shows proposes nothing, and a run warns when a generator records anything else. Every hour formadaptor also reports, without acting, where an app's `main` offers agents something its newest release does not. It never pushes to `main` anywhere and never runs app code. - The spec and the agent manifest the apps write: [docs/SPEC.md](docs/SPEC.md) - The contract each target's generator meets: [docs/TARGETS.md](docs/TARGETS.md) @@ -13,6 +13,8 @@ python3 -I scripts/spec.py build --compiler ../formcompiler --out family.json python3 -I scripts/propose.py run --target formmcp --checkout ../formMCP --family family.json --dry-run python3 -I scripts/propose.py checkouts --target formai-templates --checkout ../formai-templates --family family.json python3 -I scripts/propose.py run --target formai-templates --checkout ../formai-templates --family family.json --dry-run +python3 -I scripts/propose.py plan --target formmcp --checkout ../formMCP --family family.json --out plans/plan-formmcp +python3 -I scripts/propose.py changed --plans plans python3 -I scripts/advisory.py --family family.json ``` diff --git a/SECURITY.md b/SECURITY.md index b334f08..3e766c9 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -8,7 +8,7 @@ Use **Report a vulnerability** on this repository's Security tab (GitHub's priva ## What formadaptor holds -- A GitHub App's client ID and private key (`FORMADAPTOR_APP_ID`, `FORMADAPTOR_APP_PRIVATE_KEY`). Each run mints a token for one target repository at a time, with Contents and Pull requests write only. +- No secret and no App key. Pull requests in the targets are opened by formcompiler's `adaptor.yml` with formcompiler's release App, which mints a token for one target repository at a time; the scripts it runs are this repository's `scripts/propose.py plan`, `changed` and `apply`. - The built-in workflow token, which writes only this repository's `spec` branch. ## In scope @@ -16,9 +16,9 @@ Use **Report a vulnerability** on this repository's Security tab (GitHub's priva | Threat | What stops it | |---|---| | An outside pull request runs code in CI | Pull requests run only `self-check.yml`: no secret, a read-only token, `persist-credentials: false`. | -| A fork runs the hourly or propose workflows | Every job that publishes or proposes is guarded by `github.repository == 'nodemode-dev/formadaptor'` on `main` (tested in `tests/test_workflows.py`). | +| A fork runs the hourly workflow | Every job that publishes is guarded by `github.repository == 'nodemode-dev/formadaptor'` on `main` (tested in `tests/test_workflows.py`). | | A private app reaches a public file | A private repository's app is an id with `public: false`; nothing else about it is read or written. | -| A target's generator misuses the token | The generator runs with a minimal environment and no token; the checkout keeps no credential; a change outside the target's declared files is refused. | +| A target's generator misuses the token | The generator runs with `plan`, in a job with no secret and no environment, with a minimal environment and no token; a change outside the target's declared files is refused. The job that holds the token runs `apply`: it runs no target code and re-checks every planned file (its path against the target's files, its sha256, no link, the repository, the branch, the base commit and the change hash) before anything is pushed. | | A change reaches a target's main unreviewed | formadaptor only opens pull requests from `bot/formadaptor-*` branches; a person merges them. | | A compromised action | Actions are pinned to full commit SHAs. | diff --git a/docs/OWNER_SETUP.md b/docs/OWNER_SETUP.md index a8e1597..898e482 100644 --- a/docs/OWNER_SETUP.md +++ b/docs/OWNER_SETUP.md @@ -3,13 +3,13 @@ Nothing here has run on GitHub yet. In order: 1. Create the empty public repository `nodemode-dev/formadaptor`. Push `main` once, then push `feat/first-build-0.1.0` and open its pull request. Merge with a merge commit (no squash) so each commit and its signature stay. -2. Settings, Actions, General: allow GitHub Actions; Workflow permissions "Read repository contents" (the workflows widen it per job). Do not allow Actions to create or approve pull requests here; formadaptor opens them only in the targets, with the App. -3. Create a GitHub App owned by `nodemode-dev`, for example `formadaptor-bot`: no webhook; repository permissions Contents read and write, Pull requests read and write, Metadata read. Install it on the target repositories only: formMCP, formskills, form.ext and formai-templates (step 11) now; .github when the profile target is switched on (step 6). Not on formtray: it is not a target (its app list is your dated release schedule, kept by hand). Generate a private key and note the client ID. -4. In formadaptor: Settings, Secrets and variables, Actions: `FORMADAPTOR_APP_ID` (the client ID, `Iv...`; the numeric App ID also works) and `FORMADAPTOR_APP_PRIVATE_KEY` (the whole `.pem` file). The workflows mint a token per target repository, for that one repository. -5. In each target: if `main` has a ruleset, make sure it does not stop the App from pushing `bot/*` branches (a branch ruleset that restricts creation must list the App as a bypass actor for `bot/**`). Pull requests opened with the App token start the target's checks, unlike those opened with the built-in token. +2. Settings, Actions, General: allow GitHub Actions; Workflow permissions "Read repository contents" (the workflows widen it per job). Do not allow Actions to create or approve pull requests here; formadaptor opens none; formcompiler's `adaptor.yml` opens them in the targets. +3. formadaptor holds no secret: add none here, and create no App for it. Proposing is formcompiler's `adaptor.yml`, which signs in with formcompiler's release App from formcompiler's `release` environment. Its plan job runs each target's generator with `scripts/propose.py plan` and holds no secret and no environment; its apply job holds the token, runs no target code, and re-checks every planned file with `scripts/propose.py apply`. +4. On formcompiler's release App: add the Repository permission "Pull requests: read and write" beside Contents, and install it on each target repository in targets.json: formMCP, formskills, form.ext and formai-templates (step 11) now; .github when the profile target is switched on (step 6). Not on formtray: it is not a target (its app list is your dated release schedule, kept by hand). Each run mints a token for one target repository at a time. +5. In each target: if `main` has a ruleset, make sure it does not stop that App from pushing `bot/*` branches (a branch ruleset that restricts creation must list the App as a bypass actor for `bot/**`). Pull requests opened with the App token start the target's checks, unlike those opened with the built-in token. 6. Merge the target changes (docs/TARGETS.md) in formMCP, formskills and form.ext, each with its generated files regenerated from the current spec and its copy of that spec committed beside them (`setup/family.spec.json` in all three), so the first proposal finds nothing to change. The profile target (.github) is disabled in `targets.json`: it is switched on when the page's listing rule is chosen. The page lists apps whose registry `state` is `live`; six apps formai.studio shows as live are `public` or `prelaunch` in the registry, so decide first which is right (fix the registry's `catalog.state`, or change the page's listing rule in .github), make .github's generator write its copy at `scripts/family.spec.json`, regenerate the page, then set `"enabled": true` for `profile` here and install the App on .github. -7. Run `hourly` by hand once (Actions, hourly, Run workflow). It creates the `spec` branch with `family.json`. Then run `propose` by hand to see every enabled target answer "in step". +7. Run `hourly` by hand once (Actions, hourly, Run workflow). It creates the `spec` branch with `family.json`. Then run formcompiler's `adaptor` by hand to see every enabled target answer "in step". 8. form.ext is enabled here with the three files its generator writes (`.claude/skills/HOSTS.md`, `setup/hosts.json`, `setup/family.spec.json`); its generator must be on form.ext's `main` before the first run, or that one job fails (the others go on). The hourly summary's advisory section names apps whose `main` offers agents something their newest release does not; it never fails the run and needs nothing from you except, when you want it, a release. 9. formai.studio is private: the App needs access there for a site target, or the site's own CI runs the generator's `--check` against `family.json`. Not configured in 0.1.0. 10. In formcompiler's `formai-build` list of repositories it does not build, add formadaptor (it is not an app and has no registry entry). -11. formai-templates (since 0.2.0): create the empty public repository `nodemode-dev/formai-templates` and push its `main` from the local build (no squash). Add it to the App's installation (Settings of the App, Install App, `nodemode-dev`, the selected repositories); no new secret, the same `FORMADAPTOR_APP_ID` and `FORMADAPTOR_APP_PRIVATE_KEY` mint its token, for that one repository. Step 5 applies to it as to the others. Until it exists and the App is installed, its propose job is a skip with one line in the summary and nothing fails. The apps' own repositories need nothing: formadaptor clones the public ones at their released tags with no token. +11. formai-templates (since 0.2.0): create the empty public repository `nodemode-dev/formai-templates` and push its `main` from the local build (no squash). Add it to the installation of formcompiler's release App (Settings of the App, Install App, `nodemode-dev`, the selected repositories); no new secret, the same App mints its token, for that one repository. Step 5 applies to it as to the others. Until it exists and the App is installed, its job in `adaptor.yml` is a skip with one line in the summary and nothing fails. The apps' own repositories need nothing: formadaptor clones the public ones at their released tags with no token. diff --git a/docs/TARGETS.md b/docs/TARGETS.md index 7b8557f..916ab82 100644 --- a/docs/TARGETS.md +++ b/docs/TARGETS.md @@ -28,8 +28,8 @@ formadaptor also watches the first rule. Before the generator writes, it reads t | Field | Meaning | | --- | --- | -| `name` | Short name, used in the workflow and in `propose.yml`'s `target` input. | -| `repository` | `nodemode-dev/`. The App token is minted for this one repository. | +| `name` | Short name, used in formcompiler's `adaptor.yml` matrix and in each plan's folder name, `plan-`. | +| `repository` | `nodemode-dev/`. formcompiler's release App mints its token for this one repository, and `apply` refuses a plan that names another. | | `enabled` | `false` skips the target. | | `command` | The generator as an argument list (no shell), for example `["python3", "-I", "setup/family.py"]`. `--family ` and `--check` are appended. | | `files` | The paths the generator may change, the copy of the spec included; a path ending in `/` allows any file under it. | @@ -51,6 +51,6 @@ When the first rule of the contract was written, formMCP, formskills and form.ex formtray is not a target: its bundled app list is the owner's dated release schedule, kept by hand, because it carries release dates for apps that are not public yet. -A target that cannot be reached (not created yet, no `main`, or the App not installed on it) is a skip in propose.yml: one line in the run summary, and the other targets go on. +Proposing runs in formcompiler's `adaptor.yml`, in two jobs per target. `propose.py plan` runs the generator in a job with no secret and writes `proposal.json` and a copy of each changed file; `propose.py changed` lists the targets that have a plan; `propose.py apply` holds the token, runs nothing from the target, re-checks every planned file and opens the pull request. When the target's `main` has moved since the plan, apply pushes nothing and the next run proposes again. Whether a target that cannot be reached (not created yet, no `main`, or the App not installed on it) is a skip is up to that workflow. formportal, formai.studio and formcompiler's README are listed in the design as later targets; they are not in targets.json yet. From c5d2014dda4db85176fbd5b31cde8a20e927e488 Mon Sep 17 00:00:00 2001 From: nodemode-ai Date: Wed, 25 Nov 2026 21:22:41 -0500 Subject: [PATCH 4/4] chore(release): 0.3.0 --- CHANGELOG.md | 7 +++++++ README.md | 2 +- VERSION | 2 +- scripts/HASHOUT_LOG.md | 4 ++-- tests/test_workflows.py | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d731d17..e8bcd32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## v0.3.0 · 2026-11-26 + +- formadaptor holds no secret. Proposing moves to formcompiler's `adaptor.yml`, with formcompiler's release App from its `release` environment; hourly.yml now builds and publishes the spec only, and propose.yml is gone. +- `scripts/propose.py plan` runs a target's generator as `run` does, needs no token, and writes `proposal.json` (format `formadaptor-plan`, version 1) with a byte copy of each changed file and its sha256; nothing to propose writes nothing. `changed --plans DIR` lists the enabled targets with a plan, as `matrix` does, and skips a malformed one with a warning. `apply` needs the token, runs no target code, re-checks every planned file (paths against the target's files, sha256, no link, repository, branch, base commit and change hash), and opens the pull request as `run` did; when the target's `main` has moved since the plan it pushes nothing and the next run proposes again. +- docs/OWNER_SETUP.md steps 3 and 4: no App and no secret here; formcompiler's release App needs "Pull requests: read and write" beside Contents and an installation on each target. +- 82 tests in 5 files. + ## v0.2.3 · 2026-11-25 - `spec/ids.json` gains FormCraft (`nodemode-dev/formcraft`, catalogue and site id `formcraft`) and FormRig (`nodemode-dev/formrig`, catalogue and site id `formrig`), rows 36 and 37. formcompiler's `main` registers both, and `ids --check` compares every registry entry, so the `lint` job failed on the two names and the hourly build would have stopped on them. The file now pairs all 37 registry entries. diff --git a/README.md b/README.md index cb110bc..9e7d5e0 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,4 @@ python3 -I scripts/propose.py changed --plans plans python3 -I scripts/advisory.py --family family.json ``` -Version 0.2.3. Licence: GPL-3.0-only (see LICENSE and NOTICE). +Version 0.3.0. Licence: GPL-3.0-only (see LICENSE and NOTICE). diff --git a/VERSION b/VERSION index 7179039..0d91a54 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.3 +0.3.0 diff --git a/scripts/HASHOUT_LOG.md b/scripts/HASHOUT_LOG.md index cb65112..8632ec5 100644 --- a/scripts/HASHOUT_LOG.md +++ b/scripts/HASHOUT_LOG.md @@ -2,8 +2,8 @@ Living log of all comment content, explainers, rationale, TODOs and removed code for the adaptor (the scripts and the workflows). The source files stay comment-free per dev-rules `sub-skills/hashout-log/SUB-SKILL.md`; everything they would have said lives here, indexed. Read this first, then edit code surgically. -Current build version: v0.2.3 -Last updated: 2026-11-25 · FormCraft's and FormRig's id pairs (v0.2.3) +Current build version: v0.3.0 +Last updated: 2026-11-26 · plan, changed and apply; no secret in this repository (v0.3.0) ### propose.py · plan, changed and apply; no secret in this repository - refers-to: scripts/propose.py :: plan_command, write_plan, changed_plans, checked_plan, apply_plan, apply_command; .github/workflows/hourly.yml; tests/test_workflows.py :: test_no_workflow_holds_a_secret diff --git a/tests/test_workflows.py b/tests/test_workflows.py index 05230b0..f5c2c7e 100644 --- a/tests/test_workflows.py +++ b/tests/test_workflows.py @@ -81,4 +81,4 @@ def test_every_version_site_agrees(): match = re.search(pattern, (REPO / name).read_text(encoding="utf-8"), re.M) assert match, name found[name] = match.group(1) - assert set(found.values()) == {"0.2.3"}, found + assert set(found.values()) == {"0.3.0"}, found