Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 115 additions & 19 deletions .github/workflows/requirements-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ name: Requirements Sync
#
# It detects drift between the committed requirements DB (requirements/seed.sql +
# migrations) and the live state of GitHub Project #43, then has Claude write a new
# numbered migration capturing the delta and open a PR for human review. Nothing is
# committed to the source of truth without that review.
# numbered migration capturing the delta and commit it straight to master.
#
# There is no PR and no human review on this path — deliberately. PR merges on this
# repo are blocked by an org-level required-review ruleset that the bot cannot satisfy
# and cannot bypass, so nightly sync PRs simply accumulated unmerged. Direct pushes to
# master are not gated by that ruleset, so the bot pushes. The safety net is therefore
# entirely pre-push: the "Independent build & integrity gate" step below builds the DB and
# runs integrity + foreign-key checks BEFORE the commit reaches master, and hard-fails the
# run without pushing if anything is wrong. Keep that gate ahead of the push — moving it
# after would mean a bad migration lands on master and only then goes red.
#
# Drift in scope:
# (a) new requirements — issues that have newly reached "Refined Tickets" or beyond
Expand All @@ -20,7 +28,9 @@ on:

permissions:
contents: write
pull-requests: write
# Read-only: the job reads each issue's merged closing PRs to derive impl_commit_sha /
# impl_paths, but no longer opens or merges any PR of its own.
pull-requests: read
id-token: write

env:
Expand Down Expand Up @@ -170,33 +180,40 @@ jobs:
version once, and put all the change rows at that same new version (one logical edit).
NEVER delete a requirement or move it to a lower status, even if an issue dropped
below the gate or was removed — refs are never reused. If you see such a case, note
it in the PR body for a human to handle (do not change the row).
it in your final output for a human to handle (do not change the row).

## 6. Verify before opening a PR
## 6. Verify your own work
Run `yarn requirements:build` — it must succeed. Then run
`sqlite3 requirements/requirements.db "PRAGMA integrity_check; PRAGMA foreign_key_check;"`
— integrity must be 'ok' and foreign_key_check must be empty. If either fails, fix
the migration; if you cannot, do NOT open a PR — exit with an error instead.

## 7. Open (or update) the PR
First check for an existing open PR from a branch matching `chore/requirements-sync-*`
(`gh pr list --state open --head ...`). If one exists, commit onto THAT branch and
push (do not open a duplicate). Otherwise create branch
`chore/requirements-sync-<YYYY-MM-DD>`, commit only the new migration file, push, and
`gh pr create` against master. The PR body must summarise the delta: counts of new /
status-changed / impl-changed requirements with their REQ refs, and any
below-the-gate cases noted for a human.
the migration. If you cannot fix it, DELETE the migration file you scaffolded and
exit with an error. Do not leave a broken migration in the working tree: a later
step in this workflow commits whatever migration it finds there.

## 7. Stop — do NOT commit, push, branch, or open a PR
Leave the new migration file in the working tree, uncommitted. A later step in this
workflow re-verifies it independently and commits it straight to master. You have no
git or gh write access in this job, by design — do not create a branch, do not commit,
do not push, do not open a PR.

Finish by printing a summary of the delta to stdout: counts of new / status-changed /
impl-changed requirements with their REQ refs, and any below-the-gate cases a human
needs to look at. Nobody reviews a PR on this path, so that output is the run's only
human-readable audit record — make it complete.
claude_args: |
--dangerously-skip-permissions
--append-system-prompt "You are running in a scheduled GitHub Action to sync the requirements database. Read @CLAUDE.md and the requirements/ SQL files. Be precise: this is an append-only audit log. If there is no drift, do nothing and open no PR. Never hard-delete or down-status a requirement."
--allowedTools "Read,Glob,Grep,Write,Edit,Bash(corepack:*),Bash(yarn:*),Bash(git:*),Bash(gh:*),Bash(sqlite3:*),Bash(./requirements/scripts/new_migration.sh:*)"
--append-system-prompt "You are running in a scheduled GitHub Action to sync the requirements database. Read @CLAUDE.md and the requirements/ SQL files. Be precise: this is an append-only audit log. If there is no drift, do nothing and write no migration. Never hard-delete or down-status a requirement. You do not commit or push: leave the migration file uncommitted in the working tree and a later workflow step verifies and commits it."
--allowedTools "Read,Glob,Grep,Write,Edit,Bash(corepack:*),Bash(yarn:*),Bash(git status:*),Bash(git diff:*),Bash(gh api:*),Bash(sqlite3:*),Bash(./requirements/scripts/new_migration.sh:*)"
Comment on lines 203 to +206

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

claude code CLI --dangerously-skip-permissions ignores --allowedTools restriction documented behavior

💡 Result:

In the Claude Code CLI, the flag --dangerously-skip-permissions (and its equivalent, --permission-mode bypassPermissions) effectively bypasses the permission prompt system entirely [1][2][3]. Users and security researchers have reported that when these bypass flags are active, the --allowedTools restriction is not enforced, meaning the model can execute tools not included in the allowed list [4][5]. Although the official CLI documentation lists --allowedTools as a mechanism to specify tools that execute without prompting [1][6], it does not explicitly state that this restriction is guaranteed to be enforced when permission bypass flags are engaged. In practice, this creates a behavior where the bypass mode overrides the tool allow-listing, rendering --allowedTools ineffective at restricting tool access in those sessions [4][5]. Consequently, using --dangerously-skip-permissions is considered a high-risk configuration that removes the safety layer provided by tool restrictions [7][2][8]. Some users have suggested using --disallowedTools as a potential alternative for restricting specific actions in bypass mode, though this is also subject to the limitations of the bypass configuration [9].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== workflow excerpt =="
sed -n '180,215p' .github/workflows/requirements-sync.yml || true

echo
echo "== action/version references =="
rg -n "claude-code|dangerously-skip-permissions|allowedTools|permissions|GITHUB_TOKEN|claude_args" .github/workflows . || true

echo
echo "== package/action manifests with version context =="
for f in $(git ls-files | rg '(^|/)(package\.json|pnpm-lock\.yaml|yarn\.lock|package-lock\.json|Dockerfile|actions/.*\.ya?ml)$'); do
  if rg -q "claude" "$f"; then
    echo "--- $f"
    rg -n -C 2 "claude" "$f" || true
  fi
done

Repository: hmcts/cath-service

Length of output: 13645


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== workflow permissions and token handling =="
sed -n '1,110p' .github/workflows/requirements-sync.yml
echo
echo "== workflow commit/push steps =="
sed -n '215,270p' .github/workflows/requirements-sync.yml || true
echo
echo "== CLI/dependency lockfiles with claude references =="
for f in pnpm-lock.yaml yarn.lock package-lock.json package.json; do
  if [ -f "$f" ]; then
    echo "--- $f"
    rg -n -C 3 "claude|node-version|npm_node_execpath|Claude Code" "$f" || true
  fi
done

echo
echo "== GitHub Actions workflow files using claude-code-action =="
for wf in .github/workflows/*.yml .github/workflows/*.yaml; do
  if [ -f "$wf" ] && rg -q "anthropics/claude-code-action@v1|dangerously-skip-permissions" "$wf"; then
    echo "--- $wf"
    rg -n -C 2 "anthropics/claude-code-action@v1|dangerously-skip-permissions|allowedTools|disallowedTools" "$wf" || true
  fi
done

Repository: hmcts/cath-service

Length of output: 12841


🌐 Web query:

Claude Code CLI --disallowedTools bypassPermissions --dangerously-skip-permissions documentation

💡 Result:

The --dangerously-skip-permissions flag in the Claude Code CLI is used to disable interactive permission prompts, allowing the agent to execute actions such as shell commands, file edits, and tool calls automatically without pausing for user approval [1][2]. Key points regarding this flag: Functionality: Setting this flag is equivalent to launching the CLI with --permission-mode bypassPermissions [3][4][5]. When active, Claude Code skips the evaluation layer that normally requires user confirmation for most tool uses [1]. Safety and Limitations: - Circuit Breakers: Despite the bypass, certain operations still trigger prompts as a safety measure, including removals that target the filesystem root or home directory (e.g., rm -rf / or rm -rf ~) [6][1]. - Security Restrictions: For security reasons, the flag cannot be used when running Claude Code with root or sudo privileges [4][7]. - Tool Constraints: Notably, when bypass mode is active, established tool restrictions—such as --allowedTools or --disallowedTools—may be ignored, meaning the model can potentially access and use tools that would otherwise be restricted [8]. Alternatives: Because of the risks involved, Anthropic recommends using it only in isolated environments like containers or VMs [6][9]. For scenarios where you want to reduce prompt fatigue without fully disabling safety checks, the official "auto" permission mode is recommended, as it uses a model-based classifier to approve routine actions while still flagging potentially unsafe ones [10][1][7]. Configuration: - Mode Toggling: You can use --allow-dangerously-skip-permissions to add the bypass mode to the Shift+Tab cycle, allowing you to switch into it mid-session without needing to restart [3][5]. - Prevention: To prevent the use of this mode in managed or team environments, administrators can set permissions.disableBypassPermissionsMode to "disable" in settings files [6][9]. Top results: [3][6][8][4][1][5]

Citations:


🌐 Web query:

Claude Code GitHub issue #50303 --allowedTools ignored --dangerously-skip-permissions --permission-mode bypassPermissions

💡 Result:

GitHub issue #50303 in the anthropics/claude-code repository documents a confirmed bug where the --allowedTools flag is ignored when using permission bypass flags, specifically --dangerously-skip-permissions or --permission-mode bypassPermissions [1]. Official documentation clarifies that this behavior is by design regarding the operation of bypass modes [2][3][4]. When permission mode is set to bypassPermissions, the system automatically approves every tool call that reaches the permission evaluation step, regardless of whether that tool is listed in an allowlist like --allowedTools [2]. In this mode, --allowedTools only serves to pre-approve listed tools, while unlisted tools fall through to the bypass mechanism and are subsequently approved [2]. The issue was closed as not_planned by automation [1]. If restrictive control over specific tools is required while operating in a headless or non-interactive environment, documentation suggests using --disallowedTools (blacklist) instead of --allowedTools (whitelist) [2], or utilizing the Agent SDK's canUseTool callback, which remains effective even when bypassPermissions is enabled [5]. Additional security measures include using managed settings to disable bypass modes entirely across an organization by setting permissions.disableBypassPermissionsMode to disable [3][4].

Citations:


Do not rely on --allowedTools to block git/gh write commands in bypass mode.

With --dangerously-skip-permissions, tool restrictions can be bypassed, so this job is still configured to commit uncommitted Claude output and the token remains available for git commit/git push. Remove the auto-commit from this workflow or make Claude output in an isolated location without commit privileges, then keep the commit step strictly in a separate step that does not pass Claude/GitHub token access, even as a fallback if Claude writes outside requirements/migrations.


- name: Independent build & integrity gate
if: always()
run: |
# Defense in depth: re-verify whatever migrations now exist in the working tree
# (including any Claude just wrote), independent of Claude's own checks. A bad
# migration must never sit in a green PR.
# (including any Claude just wrote), independent of Claude's own checks.
#
# This step MUST stay ahead of the push step below. It is the only thing standing
# between a bad migration and master — there is no PR review on this path, so a
# failure here has to stop the push rather than annotate it after the fact.
set -euo pipefail
yarn requirements:build
result=$(sqlite3 requirements/requirements.db "PRAGMA integrity_check;")
Expand All @@ -210,3 +227,82 @@ jobs:
exit 1
fi
echo "✓ requirements DB builds clean and passes integrity checks"

# No `if:` — defaults to success(), so this is skipped whenever the Claude step or the
# integrity gate above failed. Never weaken this to always().
- name: Commit migration to master
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
set -euo pipefail

# Only ever stage migrations — that is the source of truth this job owns.
if [ -z "$(git status --porcelain -- requirements/migrations)" ]; then
echo "No migration written — nothing to commit. This is the normal no-drift outcome."
exit 0
fi

# requirements/requirements.db is listed in .gitignore but was committed before that
# rule existed, so it is still TRACKED and every `yarn requirements:build` shows it as
# modified. Discard that churn: it is a build artefact, it must not ride along in this
# commit, and leaving the tree dirty would make the rebase below refuse to run.
git checkout -- requirements/requirements.db 2>/dev/null || true

stray=$(git status --porcelain | grep -v ' requirements/migrations/' || true)
if [ -n "$stray" ]; then
echo "::warning::ignoring unexpected working-tree changes outside requirements/migrations/:"
echo "$stray"
fi

git add -- requirements/migrations
git status --porcelain -- requirements/migrations

Comment on lines +240 to +259

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Stray working-tree changes are warned about but not discarded, and can abort the rebase.

Line 248's own comment explains that requirements/requirements.db churn must be discarded because "leaving the tree dirty would make the rebase below refuse to run." That reasoning applies equally to any other unexpected stray change, but the stray check at Lines 251-255 only prints a warning — it never discards, stashes, or fails on those changes. If anything outside requirements/migrations/ is left modified (build tooling side effect, cache file, etc.), git rebase origin/master at Line 280 will still find a dirty working tree and abort, defeating the purpose of surfacing the warning here rather than letting the job fail with a confusing generic rebase error later.

Either fail fast when stray is non-empty, or discard/stash those changes the same way the db artefact is handled before entering the rebase loop.

♻️ Suggested fix
           stray=$(git status --porcelain | grep -v ' requirements/migrations/' || true)
           if [ -n "$stray" ]; then
-            echo "::warning::ignoring unexpected working-tree changes outside requirements/migrations/:"
-            echo "$stray"
+            echo "::error::unexpected working-tree changes outside requirements/migrations/ — refusing to commit:"
+            echo "$stray"
+            exit 1
           fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [ -z "$(git status --porcelain -- requirements/migrations)" ]; then
echo "No migration written — nothing to commit. This is the normal no-drift outcome."
exit 0
fi
# requirements/requirements.db is listed in .gitignore but was committed before that
# rule existed, so it is still TRACKED and every `yarn requirements:build` shows it as
# modified. Discard that churn: it is a build artefact, it must not ride along in this
# commit, and leaving the tree dirty would make the rebase below refuse to run.
git checkout -- requirements/requirements.db 2>/dev/null || true
stray=$(git status --porcelain | grep -v ' requirements/migrations/' || true)
if [ -n "$stray" ]; then
echo "::warning::ignoring unexpected working-tree changes outside requirements/migrations/:"
echo "$stray"
fi
git add -- requirements/migrations
git status --porcelain -- requirements/migrations
if [ -z "$(git status --porcelain -- requirements/migrations)" ]; then
echo "No migration written — nothing to commit. This is the normal no-drift outcome."
exit 0
fi
# requirements/requirements.db is listed in .gitignore but was committed before that
# rule existed, so it is still TRACKED and every `yarn requirements:build` shows it as
# modified. Discard that churn: it is a build artefact, it must not ride along in this
# commit, and leaving the tree dirty would make the rebase below refuse to run.
git checkout -- requirements/requirements.db 2>/dev/null || true
stray=$(git status --porcelain | grep -v ' requirements/migrations/' || true)
if [ -n "$stray" ]; then
echo "::error::unexpected working-tree changes outside requirements/migrations/ — refusing to commit:"
echo "$stray"
exit 1
fi
git add -- requirements/migrations
git status --porcelain -- requirements/migrations

git commit -m "chore(requirements): sync github $(date -u +%F)" \
-m "Automated nightly sync of the requirements DB from GitHub Project #43.
Committed directly to master by the requirements-sync workflow: PR merges are
blocked by an org-level required-review ruleset the bot cannot satisfy. The
migration passed yarn requirements:build, PRAGMA integrity_check and
PRAGMA foreign_key_check before this commit was created.

Run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"

# master may have moved while this ~30 minute job ran. Rebase onto whatever is
# there now and re-run the integrity gate before pushing, because a migration that
# was valid against the old master can collide with one that landed since (this is
# exactly the duplicate-numbering/duplicate-id class of failure). Never force-push.
for attempt in 1 2 3; do
git fetch origin master

# The verification below rebuilds the tracked .db artefact; drop that churn so the
# next rebase attempt starts from a clean tree.
git checkout -- requirements/requirements.db 2>/dev/null || true

if ! git rebase origin/master; then
git rebase --abort || true
echo "::error::migration conflicts with master (attempt ${attempt}) — not pushing. Re-run the workflow; it will re-derive the delta against the new master."
exit 1
fi

# The rebase may have pulled in another migration alongside ours. Re-verify.
yarn requirements:build
result=$(sqlite3 requirements/requirements.db "PRAGMA integrity_check;")
if [ "$result" != "ok" ]; then
echo "::error::integrity_check failed after rebasing onto master: $result"
exit 1
fi
fk=$(sqlite3 requirements/requirements.db "PRAGMA foreign_key_check;")
if [ -n "$fk" ]; then
echo "::error::foreign_key_check failed after rebasing onto master: $fk"
exit 1
fi

if git push origin HEAD:master; then
echo "✓ pushed $(git rev-parse --short HEAD) to master"
exit 0
fi

echo "::warning::push rejected (attempt ${attempt}/3) — master moved, retrying"
done

echo "::error::could not push to master after 3 attempts"
exit 1
Loading