Skip to content

feat: patch-based custom fork system with 4 patches#1

Merged
paoloanzn merged 9 commits intomainfrom
feat/patch-system-scaffold
Mar 17, 2026
Merged

feat: patch-based custom fork system with 4 patches#1
paoloanzn merged 9 commits intomainfrom
feat/patch-system-scaffold

Conversation

@paoloanzn
Copy link
Owner

@paoloanzn paoloanzn commented Mar 17, 2026

Summary

Complete patch-based fork management system for maintaining custom modifications on top of upstream sipeed/picoclaw, following the git-patches masterclass methodology.

Infrastructure

  • UPSTREAM.conf — pinned upstream version (v0.2.3, SHA 6f30436)
  • PATCHES.md — human + AI-readable patch registry with intent, scope, and risk
  • scripts/apply-patches.sh, generate-patches.sh, upgrade-upstream.sh, ai-regenerate-patch.sh
  • CI workflowspatch-ci.yml (validation), upstream-watch.yml (daily cron), patch-autofix.yml (AI auto-fix)

Patches

# Patch Risk Description
001 add-sop-framework LOW SOP-driven execution in workspace template + system prompt
002 relax-exec-guard MEDIUM Relaxed exec guard for usable workspace restriction
003 ci-autofix-agent-sdk LOW Cloud-based AI patch regeneration via Claude Agent SDK
004 fix-subagent-tools LOW Fix subagents having no tools (empty registry bug)

Patch 004 upstream PR

  • Submitted as sipeed/picoclaw#1711
  • If merged upstream, patch 004 becomes redundant and can be dropped on next upgrade

Test plan

  • All 26 shell tool tests pass (patch 002)
  • All 19 registry tests pass including 3 new Clone tests (patch 004)
  • pkg/tools and pkg/agent packages build cleanly
  • Patch files apply cleanly via scripts/apply-patches.sh
  • CI workflows (003) require ANTHROPIC_API_KEY secret — test after merge

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Automated upstream release monitoring with daily checks
    • AI-powered patch regeneration when upstream updates
    • Standard Operating Procedures (SOPs) framework for the workspace
    • Subagents can now access all inherited tools
  • Bug Fixes

    • Fixed subagent tool registry isolation preventing tool access
  • Chores

    • Relaxed development tool restrictions while maintaining security safeguards
    • Enhanced upstream configuration management

paoloanzn and others added 9 commits March 17, 2026 17:17
Add the complete infrastructure for maintaining custom patches on top
of upstream sipeed/picoclaw, following a patch-based fork workflow
instead of a long-lived divergent fork.

Structure:
- UPSTREAM.conf: pins upstream repo, tag (v0.2.3), and SHA
- patches/: directory for .patch files (applied in lexicographic order)
- PATCHES.md: human + AI-readable registry of patch intent and risk
- scripts/apply-patches.sh: clone upstream + apply all patches
- scripts/generate-patches.sh: export commits as format-patch files
- scripts/upgrade-upstream.sh: test patches against a new upstream tag
- scripts/ai-regenerate-patch.sh: Claude Code-powered patch regeneration
- .github/workflows/patch-ci.yml: validate patches on push/PR
- .github/workflows/upstream-watch.yml: daily cron to detect new releases

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…em prompt

Add SOPs (Standard Operating Procedures) as a first-class concept:

- Add sops/ directory with README.md to the default workspace template,
  so new installations include the SOP folder structure out of the box.
- Add SOP instructions as rule sipeed#5 in the agent system prompt, making the
  agent check for and follow relevant SOPs before executing any task.
- Add SOPs path to the workspace directory listing in the identity block.

This hardcodes SOP-aware behavior into the agent rather than relying on
per-user memory.md configuration, ensuring consistent SOP-driven execution
across all installations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add the generated .patch file and update PATCHES.md with the intent,
scope, and risk documentation for the SOP framework patch.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The exec tool's safety guard was overly aggressive, blocking normal shell
features (command substitution, variable expansion, heredocs, eval, source)
and standard dev tools (git push, ssh, chmod, kill) making the tool
nearly unusable when workspace restriction was enabled.

Changes:
- Remove deny patterns for shell features: $(), ${}, backticks, heredocs,
  eval, source — these are core shell functionality, not security threats
- Remove deny patterns for dev tools: git push, ssh, chmod, chown, kill,
  pkill, killall — normal operations that should not be blocked
- Add safe system path prefixes (/usr/, /bin/, /sbin/, /lib/, /opt/,
  /tmp/, /proc/, /sys/, plus macOS paths) so commands referencing system
  tools and binaries are not blocked by workspace boundary checks
- Update tests to reflect the relaxed deny list and add new tests for
  system paths and shell features being allowed

Security is preserved through:
- Destructive commands still blocked (rm -rf, disk wipe, shutdown, etc.)
- Remote code execution still blocked (curl|sh, wget|sh, $(curl..))
- Privilege escalation still blocked (sudo)
- System/global package installs still blocked
- Container operations still blocked (docker run/exec)
- Workspace boundary still enforced for working directory and file tools
- Path traversal (../) still blocked

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add the generated .patch file and update PATCHES.md with intent,
scope, and risk documentation for the exec guard relaxation patch.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add cloud-based automated patch regeneration for upstream upgrades:

- patch-autofix.yml: full pipeline that tries patches against new tag,
  invokes Claude Agent SDK to regenerate failures, validates, and creates PR
- ai-regenerate-patch-ci.mjs: Node.js script using Agent SDK for headless
  CI patch regeneration (replaces CLI-based approach)
- scripts/package.json: declares @anthropic-ai/claude-agent-sdk dependency
- upstream-watch.yml: now triggers patch-autofix.yml instead of patch-ci.yml

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
SubagentManager was created with an empty ToolRegistry and SetTools()
was never called, causing all subagent tool invocations to fail with
"tool not found". This was a regression from the multi-agent refactor.

Fix: clone the parent agent's tool registry into the subagent manager
after creation but before spawn/spawn_status registration — giving
subagents access to file, exec, web, and other tools while preventing
recursive subagent spawning.

- Add ToolRegistry.Clone() for independent shallow copies
- Call subagentManager.SetTools(agent.Tools.Clone()) in registerSharedTools
- Add tests for Clone isolation, empty clone, and hidden tool state

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@paoloanzn paoloanzn merged commit 7077208 into main Mar 17, 2026
2 of 5 checks passed
@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ae635e05-4906-4b88-b928-2719035ed7fb

📥 Commits

Reviewing files that changed from the base of the PR and between f776611 and 2c0167e.

📒 Files selected for processing (23)
  • .github/workflows/patch-autofix.yml
  • .github/workflows/patch-ci.yml
  • .github/workflows/upstream-watch.yml
  • .gitignore
  • PATCHES.md
  • UPSTREAM.conf
  • patches/001-add-sop-framework.patch
  • patches/002-relax-exec-guard.patch
  • patches/003-ci-autofix-agent-sdk.patch
  • patches/004-fix-subagent-tools.patch
  • pkg/agent/context.go
  • pkg/agent/loop.go
  • pkg/tools/registry.go
  • pkg/tools/registry_test.go
  • pkg/tools/shell.go
  • pkg/tools/shell_test.go
  • scripts/ai-regenerate-patch-ci.mjs
  • scripts/ai-regenerate-patch.sh
  • scripts/apply-patches.sh
  • scripts/generate-patches.sh
  • scripts/package.json
  • scripts/upgrade-upstream.sh
  • workspace/sops/README.md

📝 Walkthrough

Walkthrough

This pull request introduces an automated upstream patch management system consisting of three new GitHub Actions workflows (upstream monitoring, patch validation, and auto-fix), AI-powered patch regeneration via Claude Agent SDK, configuration infrastructure, and Go code enhancements for SOP framework integration, execution guard relaxation, and subagent tool isolation.

Changes

Cohort / File(s) Summary
GitHub Actions Workflows
.github/workflows/patch-autofix.yml, .github/workflows/patch-ci.yml, .github/workflows/upstream-watch.yml
Introduces three new workflows: patch-autofix.yml automates patch application and regeneration on upstream upgrades; patch-ci.yml validates patches on PRs and builds upstream; upstream-watch.yml monitors upstream releases daily and triggers auto-fix workflow or creates tracking issues.
Configuration & Documentation
UPSTREAM.conf, PATCHES.md, .gitignore, workspace/sops/README.md
Adds upstream pinning configuration, patch registry documenting each custom patch's intent/risk/dates, vendor directory exclusion, and SOPs framework documentation with usage guidelines and template structure.
Patch Files
patches/001-add-sop-framework.patch, patches/002-relax-exec-guard.patch, patches/003-ci-autofix-agent-sdk.patch, patches/004-fix-subagent-tools.patch
Four cumulative patches: SOP-driven execution framework; relaxed shell execution guard allowing safe system paths and dev tools; AI-powered patch auto-fix CI pipeline; subagent tool registry cloning for isolation and safe propagation.
Automation Scripts
scripts/apply-patches.sh, scripts/generate-patches.sh, scripts/upgrade-upstream.sh, scripts/ai-regenerate-patch.sh, scripts/ai-regenerate-patch-ci.mjs, scripts/package.json
Introduces six scripts: apply-patches applies patches from UPSTREAM.conf; generate-patches exports commits to patch files; upgrade-upstream validates and applies patches for new tags; ai-regenerate-patch.sh and ai-regenerate-patch-ci.mjs regenerate failed patches using Claude via Code/Agent SDK respectively; package.json declares Claude Agent SDK dependency.
Core Go Code Changes
pkg/agent/context.go, pkg/agent/loop.go, pkg/tools/registry.go, pkg/tools/registry_test.go, pkg/tools/shell.go, pkg/tools/shell_test.go
Adds SOPs section to agent identity prompt; implements ToolRegistry.Clone() for subagent tool isolation; extends shell execution guard with safe system path prefixes and relaxed deny patterns; adds comprehensive tests for clone isolation and system-path/shell-feature allowances; renames kill-blocking test to docker-exec-blocking.

Sequence Diagram

sequenceDiagram
    participant Scheduler as Scheduler (Daily)
    participant UpstreamWatch as upstream-watch.yml
    participant GithubAPI as GitHub API
    participant PatchAutofix as patch-autofix.yml
    participant Upstream as Upstream Repo
    participant ClaudeAgent as Claude Agent SDK
    participant PatchValidation as patch-ci.yml
    participant PRSystem as PR Creation

    Scheduler->>UpstreamWatch: Trigger daily
    UpstreamWatch->>Upstream: Fetch latest tag
    UpstreamWatch->>UpstreamWatch: Compare CURRENT vs LATEST
    alt New release detected
        UpstreamWatch->>GithubAPI: Trigger patch-autofix.yml
        UpstreamWatch->>GithubAPI: Create tracking issue
    end

    GithubAPI->>PatchAutofix: Invoke with new_tag
    PatchAutofix->>Upstream: Clone at new tag
    PatchAutofix->>PatchAutofix: Apply patches sequentially
    alt All patches apply
        PatchAutofix->>PatchAutofix: Update UPSTREAM.conf
        PatchAutofix->>PRSystem: Create upgrade PR (clean)
    else Patches fail
        PatchAutofix->>ClaudeAgent: Request regeneration
        ClaudeAgent->>PatchAutofix: Return regenerated patch
        PatchAutofix->>PatchValidation: Validate patch
        alt Validation succeeds
            PatchAutofix->>PatchAutofix: Update UPSTREAM.conf
            PatchAutofix->>PRSystem: Create PR (AI-generated label)
        else Validation fails
            PatchAutofix->>PRSystem: Create PR (needs-review label)
        end
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰 Patches skip through the CI's gentle stream,
Claude Agent weaves an upgrade dream,
SOPs bloom in folders neat and tidy,
While shells run free—but safe and nifty—
A rabbit's dance of code set free!

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/patch-system-scaffold
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can enable review details to help with troubleshooting, context usage and more.

Enable the reviews.review_details setting to include review details such as the model used, the time taken for each step and more in the review comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant