Skip to content

[plan] 为mega-planner添加自动备份debate和consensus的功能,issue提交到fork #4

Description

@Tonny-Gu

Now I see -- there's no /mega-planner in the workflow commands mapping. This means mega-planner is likely a newer rename/replacement but the permission system still references the old ultra-planner name. The general allow-list at rules.py:100 does cover gh issue (list|view|create) so view and create work anywhere. But gh issue edit is only allowed for the ultra-planner workflow specifically.

Now I have all the context needed. Here's my synthesis:


Implementation Plan: Mega-Planner Artifact Backup and Fork-Targeted Issues

Agent Perspectives Summary

Agent Core Position Key Insight
Bold Both features: plans/ archive directory + -R flag on all gh commands Clean separation of ephemeral .tmp/ and persistent plans/ directories
Paranoia Feature 2 only: reject backup, add -R flag minimally Consensus plan is already backed up to GitHub issue body; artifacts are ephemeral
Critique Both proposals break permission system patterns; Bold violates "no code changes" principle Permission regex patterns in determine.py:568-570 will not match with -R flag inserted
Proposal Reducer Converge both to hybrid: .gitignore negation + minimal backup + -R Both proposals reduce to ~14 LOC when simplified; plans/ directory is unnecessary
Code Reducer Hybrid at +14 LOC vs Bold's +100 LOC; Paranoia's +12 LOC ignores user request Repository grows 2.7% vs 19.5% — hybrid is optimal

Goal

Add fork-targeted issue operations (via -R flag) to all gh issue commands in the mega-planner workflow, and optionally persist debate artifacts to git so they survive .tmp/ cleanup.

Out of scope:

  • Refactoring the permission system broadly
  • Changing the mega-planner's multi-agent debate structure
  • Adding new workflow modes

Codebase Analysis

File changes:

File Level Purpose
.claude-plugin/commands/mega-planner.md major Add FORK_REPO extraction and -R flag to all gh issue commands
.claude-plugin/lib/permission/rules.py minor Add gh issue edit to general allow-list OR add -R optional match
.claude-plugin/lib/permission/determine.py minor Update ultra-planner patterns to handle optional -R flag
.gitignore minor (Only if backup option chosen) Allow .tmp/issue-* tracking

Implementation Steps

Note: Steps below cover the consensus portion — Feature 2 (fork targeting) where all agents agree. Disagreement on Feature 1 (artifact backup) and permission system approach are in the Disagreement sections.

Step 1: Add FORK_REPO extraction at Step 1 of mega-planner

  • File: .claude-plugin/commands/mega-planner.md
  • Changes: Add repo slug extraction before the mode-parsing logic
Code Draft
 ### Step 1: Parse Arguments and Extract Feature Description

 Accept the $ARGUMENTS.

+**Resolve fork repository for issue targeting:**
+
+```bash
+FORK_REPO=$(git remote get-url origin | sed -E 's#.*(github\.com[:/])##; s/\.git$//')
+```
+
+Use `-R "${FORK_REPO}"` on all subsequent `gh issue` commands.
+
 **Resolve mode (fast-path):** If `--resolve` is at the beginning:

Step 2: Add -R "${FORK_REPO}" to gh issue view in resolve mode

  • File: .claude-plugin/commands/mega-planner.md (line 135)
  • Changes: Insert -R flag
Code Draft
-   gh issue view ${ISSUE_NUMBER} --json body -q '.body' > ".tmp/${FILE_PREFIX}-issue-body.md"
+   gh issue view ${ISSUE_NUMBER} -R "${FORK_REPO}" --json body -q '.body' > ".tmp/${FILE_PREFIX}-issue-body.md"

Step 3: Add -R "${FORK_REPO}" to gh issue view in refine mode

  • File: .claude-plugin/commands/mega-planner.md (lines 163, 183)
  • Changes: Insert -R flag in both the description and code block
Code Draft
-2. Fetch the issue: `gh issue view ${ISSUE_NUMBER} --json title,body`
+2. Fetch the issue: `gh issue view ${ISSUE_NUMBER} -R "${FORK_REPO}" --json title,body`
-gh issue view ${ISSUE_NUMBER} --json title,body
+gh issue view ${ISSUE_NUMBER} -R "${FORK_REPO}" --json title,body

Step 4: Add -R "${FORK_REPO}" to gh issue view in from-issue mode

  • File: .claude-plugin/commands/mega-planner.md (line 193)
  • Changes: Insert -R flag
Code Draft
-gh issue view <issue-no> --json title,body
+gh issue view <issue-no> -R "${FORK_REPO}" --json title,body

Step 5: Add -R "${FORK_REPO}" to gh issue create in Step 3

  • File: .claude-plugin/commands/mega-planner.md (line 240)
  • Changes: Insert -R flag
Code Draft
 ISSUE_URL=$(gh issue create \
+    -R "${FORK_REPO}" \
     --title "[plan] ${FEATURE_DESC}" \

Step 6: Add -R "${FORK_REPO}" to gh issue edit in Steps 8 and 9

  • File: .claude-plugin/commands/mega-planner.md (lines 470, 491, 497)
  • Changes: Insert -R flag on all edit commands
Code Draft
-gh issue edit ${ISSUE_NUMBER} --body-file "${CONSENSUS_PLAN_FILE}"
+gh issue edit ${ISSUE_NUMBER} -R "${FORK_REPO}" --body-file "${CONSENSUS_PLAN_FILE}"
-gh issue edit ${ISSUE_NUMBER} --add-label "agentize:plan"
+gh issue edit ${ISSUE_NUMBER} -R "${FORK_REPO}" --add-label "agentize:plan"
-gh issue edit ${ISSUE_NUMBER} --remove-label "agentize:feat-request"
+gh issue edit ${ISSUE_NUMBER} -R "${FORK_REPO}" --remove-label "agentize:feat-request"

Step 7: Update permission patterns to handle -R flag

  • File: .claude-plugin/lib/permission/rules.py (line 100)
  • Changes: Add gh issue edit to the general allow-list (since it's also needed by mega-planner, not just ultra-planner)
Code Draft
-        ('Bash', r'^gh issue (list|view|create)'),
+        ('Bash', r'^gh issue (list|view|create|edit)'),
  • File: .claude-plugin/lib/permission/determine.py (lines 568-570)
  • Changes: Update patterns to optionally match -R flag before other flags
Code Draft
         issue_creation_patterns = [
-            r'^gh issue create\s+--title\s+.*--body\s+.*',  # gh issue create with title and body
-            r'^gh issue edit\s+\d+\s+--title\s+.*',         # gh issue edit with title
-            r'^gh issue edit\s+\d+\s+--body\s+.*',          # gh issue edit with body
+            r'^gh issue create\s+(-R\s+\S+\s+)?--title\s+.*--body\s+.*',  # gh issue create with title and body
+            r'^gh issue edit\s+\d+\s+(-R\s+\S+\s+)?--title\s+.*',         # gh issue edit with title
+            r'^gh issue edit\s+\d+\s+(-R\s+\S+\s+)?--body\s+.*',          # gh issue edit with body
         ]

Overall Recommendation

Disagreement Summary

# Topic Options AI Recommendation
1 Artifact Backup Strategy A (No backup), B (.gitignore negation + commit), C (plans/ directory) Option 1B
2 FORK_REPO Extraction Method A (git remote sed), B (gh repo view) Option 2A

Suggested Combination

Suggested combination: 1B + 2A because .gitignore negation is minimal and avoids duplicate storage, while sed-based extraction is more reliable offline and avoids an extra API call.

Alternative combinations:

  • All Conservative (1A + 2A): No backup, just fork targeting — fastest to implement, ignores user request
  • All Aggressive (1C + 2B): Full plans/ directory + gh repo view — most infrastructure, cleanest abstraction

Disagreement 1: Artifact Backup Strategy

Agent Perspectives

Agent Position Rationale
Bold Create plans/ directory with copied artifacts Clean separation of ephemeral and persistent; follows project README convention
Paranoia No backup at all Consensus already on GitHub; .tmp/ persists locally; committing generated files pollutes git
Critique Bold's approach violates "no code changes" principle; Paranoia ignores user request Both have valid points; hybrid needed
Proposal Reducer .gitignore negation to track .tmp/issue-* files directly Eliminates duplication; same result with ~3 lines vs ~80 lines
Code Reducer Hybrid at +3 LOC for backup vs Bold's +88 LOC plans/ has zero downstream consumers

Resolution Options

Option 1A: No Backup (Conservative)

Summary: Reject artifact backup entirely. Consensus plan is already backed up to GitHub issue body. Individual agent reports remain ephemeral in .tmp/.
Source: Paranoia

File Changes:

File Level Purpose
(none) No changes needed

Implementation Steps:

No additional steps beyond the consensus fork-targeting changes.

Risks and Mitigations:

Risk Likelihood Impact Mitigation
Lost debate context on .tmp/ cleanup M M Re-run --from-issue to regenerate
User expectation not met H L Document that consensus is persisted via GitHub issue

Option 1B: .gitignore Negation + Minimal Commit (Balanced)

Summary: Modify .gitignore to allow .tmp/issue-* files to be tracked, then git add and commit them after consensus. No new directories, no file copying.
Source: Proposal Reducer + Code Reducer (hybrid)

File Changes:

File Level Purpose
.gitignore minor Add negation pattern for .tmp/issue-*
.claude-plugin/commands/mega-planner.md minor Append 3 lines to Step 9

Implementation Steps:

Step 1: Update .gitignore

  • File: .gitignore
  • Changes: Add negation pattern
Code Draft
 .tmp/*
+!.tmp/issue-*
 trees/

Step 2: Append artifact commit to Step 9

  • File: .claude-plugin/commands/mega-planner.md (after line 497)
  • Changes: Add git add/commit after label operations
Code Draft
 gh issue edit ${ISSUE_NUMBER} -R "${FORK_REPO}" --remove-label "agentize:feat-request"
 ```

+**Archive debate artifacts to git:**
+
+```bash
+git add .tmp/issue-${ISSUE_NUMBER}-*.md
+git commit -m "[plan] Archive debate artifacts for #${ISSUE_NUMBER}"
+```
+
 **Expected output:**

Risks and Mitigations:

Risk Likelihood Impact Mitigation
Violates "no code changes" principle M L Archival commit is metadata, not code change; add clarifying comment
Git history growth L L ~9 files per planning session, each <50KB
.tmp/issue-* pattern too broad L M Pattern only matches issue- prefixed files which are all mega-planner artifacts

Option 1C: Dedicated plans/ Directory (Aggressive)

Summary: Create plans/issue-{N}/ directory structure with copied artifacts and a README. Full separation of working and archived files.
Source: Bold

File Changes:

File Level Purpose
.claude-plugin/commands/mega-planner.md major Add new Step 10 with copy + commit logic (~40 LOC)
plans/README.md minor New file documenting directory purpose (~30 LOC)

Implementation Steps:

Step 1: Add Step 10 to mega-planner

  • File: .claude-plugin/commands/mega-planner.md
  • Changes: New step after Step 9 with artifact copy and commit
Code Draft
+### Step 10: Backup Debate Artifacts to Git
+
+```bash
+mkdir -p "plans/issue-${ISSUE_NUMBER}"
+
+for ARTIFACT in context bold paranoia critique proposal-reducer code-reducer debate consensus history; do
+    SRC=".tmp/issue-${ISSUE_NUMBER}-${ARTIFACT}.md"
+    if [ -f "$SRC" ]; then
+        cp "$SRC" "plans/issue-${ISSUE_NUMBER}/${ARTIFACT}.md"
+    fi
+done
+
+git add "plans/issue-${ISSUE_NUMBER}/"
+git commit -m "[#${ISSUE_NUMBER}][plan] Archive debate artifacts"
+```

Step 2: Create plans/README.md

  • File: plans/README.md
  • Changes: New file
Code Draft
# Plans Directory

Archived debate artifacts from the mega-planner workflow.

## Organization

```
plans/
  issue-{N}/
    context.md          - Understander context summary
    bold.md             - Bold proposer report
    paranoia.md         - Paranoia proposer report
    critique.md         - Critique agent report
    proposal-reducer.md - Proposal reducer report
    code-reducer.md     - Code reducer report
    debate.md           - Combined multi-agent debate report
    consensus.md        - Final consensus plan
    history.md          - Selection and refine history
```

Risks and Mitigations:

Risk Likelihood Impact Mitigation
Duplicate storage (.tmp/ + plans/) H L Accept as cost of clean separation
Violates "no code changes" principle M M Frame as post-planning archival action
+100 LOC for a backup mechanism M L Directory is self-documenting
No downstream consumer H L Future --resolve could read from plans/

AI Recommendation: Option 1B because it fulfills the user's backup request with minimal code (+6 LOC across 2 files), avoids duplicate storage, and doesn't introduce new directories or workflow steps. The .gitignore negation pattern is the standard git approach for exceptions.


Disagreement 2: FORK_REPO Extraction Method

Agent Perspectives

Agent Position Rationale
Bold sed on git remote get-url origin Matches Python server pattern; works offline
Paranoia sed on git remote get-url origin (same, slightly different regex) Minimal, no API calls
Critique Bold's regex is less robust than Paranoia's Both work for this repo; Paranoia handles edge cases better
Proposal Reducer gh repo view --json nameWithOwner Simpler, no regex parsing
Code Reducer gh repo view --json nameWithOwner One canonical command, no regex

Resolution Options

Option 2A: sed-based extraction (Conservative)

Summary: Parse git remote get-url origin with sed. Works offline, no API call, matches the pattern already used in python/agentize/server/github.py.
Source: Bold + Paranoia (both agree on mechanism, differ in regex)

File Changes:

File Level Purpose
.claude-plugin/commands/mega-planner.md minor Add 1-line extraction

Implementation Steps:

Step 1: Add extraction

  • File: .claude-plugin/commands/mega-planner.md
  • Changes: (already included in consensus Step 1)
Code Draft
FORK_REPO=$(git remote get-url origin | sed -E 's#.*(github\.com[:/])##; s/\.git$//')

Risks and Mitigations:

Risk Likelihood Impact Mitigation
Regex doesn't handle non-GitHub remotes L H This project is GitHub-only
Fails if no origin remote L H Error message from git is descriptive enough

Option 2B: gh repo view extraction (Aggressive)

Summary: Use gh repo view --json nameWithOwner to get the repo slug. Cleaner, no regex, but requires network access and authenticated gh session.
Source: Proposal Reducer + Code Reducer

File Changes:

File Level Purpose
.claude-plugin/commands/mega-planner.md minor Add 1-line extraction

Implementation Steps:

Step 1: Add extraction

  • File: .claude-plugin/commands/mega-planner.md
  • Changes: Replace sed-based extraction
Code Draft
FORK_REPO=$(gh repo view --json nameWithOwner -q '.nameWithOwner')

Risks and Mitigations:

Risk Likelihood Impact Mitigation
Requires network for extraction (before any gh commands) L L All subsequent commands also need network
gh repo view may resolve to upstream (same priority as gh issue) M H Would defeat the purpose; needs testing
Extra API call at workflow start L L One additional call is negligible

AI Recommendation: Option 2A because gh repo view has the same remote-resolution priority problem as gh issue — it may resolve to upstream rather than origin, defeating the purpose. The sed approach explicitly targets the origin remote, which is guaranteed to be the fork.


Success Criteria

  • gh issue create targets the fork repository (origin), not upstream
  • gh issue edit commands target the fork repository
  • gh issue view commands target the fork repository
  • Permission patterns in determine.py match commands with -R flag
  • General allow-list in rules.py covers gh issue edit
  • (If backup chosen) Debate artifacts persist in git after mega-planner completes

Risks and Mitigations

Risk Likelihood Impact Mitigation
Permission patterns block -R flagged commands H H Update regex patterns (consensus Step 7)
origin remote doesn't exist or isn't GitHub L H Git error message is descriptive; this is a GitHub-only project
gh issue edit added to general allow-list too broadly M M Only list/view/create/edit — no destructive operations
Workflow name mismatch (mega-planner vs ultra-planner) M M Verify which workflow name triggers the permission path

Selection History

Timestamp Disagreement Options Summary Selected Option User Comments

Refine History

Timestamp Summary

Option Compatibility Check

Status: VALIDATED

All option combinations (1A/1B/1C with 2A/2B) are architecturally compatible. No conflicting file modifications or design decisions detected between the disagreement points.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    agentize:planImplementation plan from mega-planner

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions