@slamb2k/mad-skills 2.0.7 → 2.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +11 -5
- package/.claude-plugin/plugin.json +9 -7
- package/README.md +101 -25
- package/hooks/hooks.json +26 -0
- package/hooks/session-guard-prompt.sh +59 -0
- package/hooks/session-guard.sh +155 -151
- package/package.json +2 -7
- package/skills/brace/SKILL.md +240 -14
- package/skills/brace/assets/gitignore-template +0 -3
- package/skills/brace/references/phase-prompts.md +37 -0
- package/skills/brace/references/report-template.md +5 -1
- package/skills/build/SKILL.md +292 -13
- package/skills/distil/SKILL.md +258 -7
- package/skills/manifest.json +26 -16
- package/skills/prime/SKILL.md +76 -8
- package/skills/rig/SKILL.md +165 -7
- package/skills/ship/SKILL.md +190 -19
- package/skills/speccy/SKILL.md +165 -0
- package/skills/speccy/references/interview-guide.md +96 -0
- package/skills/speccy/tests/evals.json +34 -0
- package/skills/sync/SKILL.md +175 -17
- package/commands/brace.md +0 -9
- package/commands/build.md +0 -9
- package/commands/distil.md +0 -9
- package/commands/prime.md +0 -9
- package/commands/rig.md +0 -9
- package/commands/ship.md +0 -9
- package/commands/sync.md +0 -9
- package/skills/brace/instructions.md +0 -229
- package/skills/build/instructions.md +0 -293
- package/skills/distil/instructions.md +0 -255
- package/skills/prime/instructions.md +0 -73
- package/skills/rig/instructions.md +0 -162
- package/skills/ship/instructions.md +0 -192
- package/skills/sync/instructions.md +0 -178
- package/src/cli.js +0 -482
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
# Rig Instructions
|
|
2
|
-
|
|
3
|
-
Idempotently bootstrap repositories with standard development infrastructure.
|
|
4
|
-
Prompts and report schemas are in `references/`. Configuration procedures are
|
|
5
|
-
in `references/configuration-steps.md`.
|
|
6
|
-
|
|
7
|
-
**Key principle:** Prompt user before making changes. Report findings first,
|
|
8
|
-
get approval, then act.
|
|
9
|
-
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
## Pre-flight
|
|
13
|
-
|
|
14
|
-
Before starting, check all dependencies in this table:
|
|
15
|
-
|
|
16
|
-
| Dependency | Type | Check | Required | Resolution | Detail |
|
|
17
|
-
|-----------|------|-------|----------|------------|--------|
|
|
18
|
-
| git | cli | `git --version` | yes | stop | Install from https://git-scm.com |
|
|
19
|
-
| lefthook | npm | `npx lefthook --help` | yes | install | `npm install -g lefthook` |
|
|
20
|
-
| gh | cli | `gh --version` | yes | url | https://cli.github.com |
|
|
21
|
-
|
|
22
|
-
For each row, in order:
|
|
23
|
-
1. Run the Check command (for cli/npm) or test file existence (for agent/skill)
|
|
24
|
-
2. If found: continue silently
|
|
25
|
-
3. If missing: apply Resolution strategy
|
|
26
|
-
- **stop**: notify user with Detail, halt execution
|
|
27
|
-
- **url**: notify user with Detail (install link), halt execution
|
|
28
|
-
- **install**: notify user, run the command in Detail, continue if successful
|
|
29
|
-
- **ask**: notify user, offer to run command in Detail, continue either way (or halt if required)
|
|
30
|
-
- **fallback**: notify user with Detail, continue with degraded behavior
|
|
31
|
-
4. After all checks: summarize what's available and what's degraded
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
## Phase 1: System Requirements Check
|
|
36
|
-
|
|
37
|
-
Launch **Bash subagent** (haiku — simple checks):
|
|
38
|
-
|
|
39
|
-
```
|
|
40
|
-
Task(
|
|
41
|
-
subagent_type: "Bash",
|
|
42
|
-
model: "haiku",
|
|
43
|
-
description: "Check system requirements",
|
|
44
|
-
prompt: <read from references/phase-prompts.md#phase-1>
|
|
45
|
-
)
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
Parse SYSTEM_REPORT. If any requirement fails, use **AskUserQuestion**:
|
|
49
|
-
|
|
50
|
-
Options for missing git config:
|
|
51
|
-
- "I'll configure it manually"
|
|
52
|
-
- "Configure for me with: [email] / [name]"
|
|
53
|
-
|
|
54
|
-
**Stop if user chooses manual. Configure if values provided.**
|
|
55
|
-
|
|
56
|
-
---
|
|
57
|
-
|
|
58
|
-
## Phase 2: Repository Analysis
|
|
59
|
-
|
|
60
|
-
Launch **Bash subagent** (haiku):
|
|
61
|
-
|
|
62
|
-
```
|
|
63
|
-
Task(
|
|
64
|
-
subagent_type: "Bash",
|
|
65
|
-
model: "haiku",
|
|
66
|
-
description: "Analyze repository",
|
|
67
|
-
prompt: <read from references/phase-prompts.md#phase-2>
|
|
68
|
-
)
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
Parse REPO_REPORT.
|
|
72
|
-
|
|
73
|
-
---
|
|
74
|
-
|
|
75
|
-
## Phase 3: Present Findings & Get Approval
|
|
76
|
-
|
|
77
|
-
Present analysis to user with **AskUserQuestion**:
|
|
78
|
-
|
|
79
|
-
```
|
|
80
|
-
Repository Analysis Complete
|
|
81
|
-
|
|
82
|
-
Current State:
|
|
83
|
-
Git initialized: {status}
|
|
84
|
-
Branch: {branch}
|
|
85
|
-
Lefthook: {status}
|
|
86
|
-
Commit template: {status}
|
|
87
|
-
PR template: {status}
|
|
88
|
-
CI workflow: {status}
|
|
89
|
-
{if azdo and unregistered_pipelines:}
|
|
90
|
-
Azure Pipelines: {N} YAML file(s) found, {M} not yet registered
|
|
91
|
-
|
|
92
|
-
Detected Stack:
|
|
93
|
-
Type: {project_type}
|
|
94
|
-
Components: {detected_components}
|
|
95
|
-
Available scripts: {available_scripts}
|
|
96
|
-
|
|
97
|
-
Proposed Changes:
|
|
98
|
-
{numbered list of what will be added/configured}
|
|
99
|
-
{if azdo and unregistered_pipelines: "Register Azure Pipelines: {list of YAML paths}"}
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
Options:
|
|
103
|
-
- "Yes, configure everything"
|
|
104
|
-
- "Let me choose what to configure"
|
|
105
|
-
- "Cancel"
|
|
106
|
-
|
|
107
|
-
If "Let me choose", present individual options as multi-select.
|
|
108
|
-
|
|
109
|
-
---
|
|
110
|
-
|
|
111
|
-
## Phase 4: Execute Configuration
|
|
112
|
-
|
|
113
|
-
For each approved item, follow the procedures in
|
|
114
|
-
`references/configuration-steps.md`.
|
|
115
|
-
|
|
116
|
-
---
|
|
117
|
-
|
|
118
|
-
## Phase 5: Verification
|
|
119
|
-
|
|
120
|
-
Launch **Bash subagent** (haiku):
|
|
121
|
-
|
|
122
|
-
```
|
|
123
|
-
Task(
|
|
124
|
-
subagent_type: "Bash",
|
|
125
|
-
model: "haiku",
|
|
126
|
-
description: "Verify configuration",
|
|
127
|
-
prompt: <read from references/phase-prompts.md#phase-5>
|
|
128
|
-
)
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
Parse VERIFY_REPORT.
|
|
132
|
-
|
|
133
|
-
---
|
|
134
|
-
|
|
135
|
-
## Phase 6: Final Report
|
|
136
|
-
|
|
137
|
-
Present summary using the template in `references/report-template.md`.
|
|
138
|
-
|
|
139
|
-
---
|
|
140
|
-
|
|
141
|
-
## Idempotency Rules
|
|
142
|
-
|
|
143
|
-
- **Skip** items already correctly configured
|
|
144
|
-
- **Update** items that exist but are outdated (prompt user first)
|
|
145
|
-
- **Add** items that are missing
|
|
146
|
-
- **Never delete** user's existing configuration without explicit approval
|
|
147
|
-
- **Merge** rather than replace when possible (e.g., add missing hooks)
|
|
148
|
-
|
|
149
|
-
---
|
|
150
|
-
|
|
151
|
-
## Error Handling
|
|
152
|
-
|
|
153
|
-
If any step fails:
|
|
154
|
-
1. Report the specific failure
|
|
155
|
-
2. Offer to skip and continue, or abort
|
|
156
|
-
3. Include troubleshooting suggestions
|
|
157
|
-
|
|
158
|
-
Common issues:
|
|
159
|
-
- No package manager -> suggest installing npm/bun
|
|
160
|
-
- Permission denied -> check file permissions
|
|
161
|
-
- Lefthook install fails -> try global install
|
|
162
|
-
- Git not initialized -> offer to initialize
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
# Ship Instructions
|
|
2
|
-
|
|
3
|
-
Ship changes through the complete PR lifecycle. Every stage runs in a subagent
|
|
4
|
-
to isolate context from the primary conversation. Prompts for each stage are
|
|
5
|
-
in `references/stage-prompts.md`.
|
|
6
|
-
|
|
7
|
-
## Flags
|
|
8
|
-
|
|
9
|
-
Parse optional flags from the request:
|
|
10
|
-
- `--pr-only`: Stop after creating the PR
|
|
11
|
-
- `--no-squash`: Use regular merge instead of squash
|
|
12
|
-
- `--keep-branch`: Don't delete the source branch after merge
|
|
13
|
-
|
|
14
|
-
---
|
|
15
|
-
|
|
16
|
-
## Pre-flight
|
|
17
|
-
|
|
18
|
-
Before starting, check all dependencies in this table:
|
|
19
|
-
|
|
20
|
-
| Dependency | Type | Check | Required | Resolution | Detail |
|
|
21
|
-
|-----------|------|-------|----------|------------|--------|
|
|
22
|
-
| git | cli | `git --version` | yes | stop | Install from https://git-scm.com |
|
|
23
|
-
| gh | cli | `gh --version` | yes | url | https://cli.github.com |
|
|
24
|
-
| ship-analyzer | agent | `~/.claude/agents/ship-analyzer.md` | no | fallback | Uses general-purpose agent |
|
|
25
|
-
|
|
26
|
-
For each row, in order:
|
|
27
|
-
1. Run the Check command (for cli/npm) or test file existence (for agent/skill)
|
|
28
|
-
2. If found: continue silently
|
|
29
|
-
3. If missing: apply Resolution strategy
|
|
30
|
-
- **stop**: notify user with Detail, halt execution
|
|
31
|
-
- **url**: notify user with Detail (install link), halt execution
|
|
32
|
-
- **install**: notify user, run the command in Detail, continue if successful
|
|
33
|
-
- **ask**: notify user, offer to run command in Detail, continue either way (or halt if required)
|
|
34
|
-
- **fallback**: notify user with Detail, continue with degraded behavior
|
|
35
|
-
4. After all checks: summarize what's available and what's degraded
|
|
36
|
-
|
|
37
|
-
Read `default_branch` and `remote` from Stage 1's SYNC_REPORT. These are
|
|
38
|
-
substituted into all stage prompts as `{REMOTE}` and `{DEFAULT_BRANCH}`.
|
|
39
|
-
|
|
40
|
-
### Platform Detection
|
|
41
|
-
|
|
42
|
-
After sync, detect the hosting platform from the remote URL:
|
|
43
|
-
|
|
44
|
-
```bash
|
|
45
|
-
REMOTE_URL=$(git remote get-url {REMOTE} 2>/dev/null)
|
|
46
|
-
if echo "$REMOTE_URL" | grep -qiE 'dev\.azure\.com|visualstudio\.com'; then
|
|
47
|
-
PLATFORM="azdo"
|
|
48
|
-
elif echo "$REMOTE_URL" | grep -qi 'github\.com'; then
|
|
49
|
-
PLATFORM="github"
|
|
50
|
-
else
|
|
51
|
-
PLATFORM="github" # default fallback
|
|
52
|
-
fi
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Pass `{PLATFORM}` into all stage prompts. Each stage uses the appropriate
|
|
56
|
-
CLI tool: `gh` for GitHub, `az repos`/`az pipelines` for Azure DevOps.
|
|
57
|
-
|
|
58
|
-
> **Azure DevOps prerequisite:** The `az devops` extension must be installed
|
|
59
|
-
> and configured (`az devops configure --defaults organization=... project=...`).
|
|
60
|
-
> If `az repos` commands fail, report the setup requirement to the user.
|
|
61
|
-
|
|
62
|
-
---
|
|
63
|
-
|
|
64
|
-
## Stage 1: Sync
|
|
65
|
-
|
|
66
|
-
Launch **Bash subagent** (haiku — simple git commands):
|
|
67
|
-
|
|
68
|
-
```
|
|
69
|
-
Task(
|
|
70
|
-
subagent_type: "Bash",
|
|
71
|
-
model: "haiku",
|
|
72
|
-
description: "Sync with default branch",
|
|
73
|
-
prompt: "Follow ~/.claude/skills/sync/instructions.md subagent prompt. Return SYNC_REPORT."
|
|
74
|
-
)
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
Parse SYNC_REPORT. Extract `remote` and `default_branch`. Abort if sync failed.
|
|
78
|
-
|
|
79
|
-
---
|
|
80
|
-
|
|
81
|
-
## Stage 2: Commit, Push & Create PR
|
|
82
|
-
|
|
83
|
-
This stage needs to **read and understand code** to write good commit messages
|
|
84
|
-
and PR descriptions. Use a code-aware subagent.
|
|
85
|
-
|
|
86
|
-
Launch **ship-analyzer subagent** (reads diffs + source files):
|
|
87
|
-
|
|
88
|
-
```
|
|
89
|
-
Task(
|
|
90
|
-
subagent_type: "ship-analyzer",
|
|
91
|
-
description: "Analyze, commit, push, and create PR",
|
|
92
|
-
prompt: <read from references/stage-prompts.md#stage-2>
|
|
93
|
-
)
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
> **Fallback:** If `ship-analyzer` is not available, use `subagent_type: "general-purpose"`.
|
|
97
|
-
|
|
98
|
-
Substitute `{USER_INTENT}`, `{FILES_TO_INCLUDE}`, `{FILES_TO_EXCLUDE}`,
|
|
99
|
-
`{REMOTE}`, `{DEFAULT_BRANCH}`, `{PLATFORM}` into the prompt.
|
|
100
|
-
|
|
101
|
-
Parse SHIP_REPORT. Abort if failed.
|
|
102
|
-
|
|
103
|
-
**Rollback:** If push succeeds but PR creation fails, report the error and
|
|
104
|
-
suggest the manual PR creation command. Do NOT revert the push.
|
|
105
|
-
- GitHub: `gh pr create --head {branch}`
|
|
106
|
-
- Azure DevOps: `az repos pr create --source-branch {branch} --target-branch {DEFAULT_BRANCH}`
|
|
107
|
-
|
|
108
|
-
**If `--pr-only` flag: Stop here and report PR URL to user.**
|
|
109
|
-
|
|
110
|
-
---
|
|
111
|
-
|
|
112
|
-
## Stage 3: Wait for CI
|
|
113
|
-
|
|
114
|
-
Launch **Bash subagent** in the **background** (haiku — just polling):
|
|
115
|
-
|
|
116
|
-
```
|
|
117
|
-
Task(
|
|
118
|
-
subagent_type: "Bash",
|
|
119
|
-
model: "haiku",
|
|
120
|
-
run_in_background: true,
|
|
121
|
-
description: "Monitor CI checks",
|
|
122
|
-
prompt: <read from references/stage-prompts.md#stage-3>
|
|
123
|
-
)
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
Substitute `{PR_NUMBER}` into the prompt.
|
|
127
|
-
|
|
128
|
-
While CI runs in the background, briefly inform the user:
|
|
129
|
-
```
|
|
130
|
-
CI running for PR #{pr_number}... waiting for checks.
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
When the background task completes, read the output file and parse CHECKS_REPORT.
|
|
134
|
-
|
|
135
|
-
---
|
|
136
|
-
|
|
137
|
-
## Stage 4: Fix Failing Checks (if needed)
|
|
138
|
-
|
|
139
|
-
If CHECKS_REPORT shows failures, launch **general-purpose subagent**:
|
|
140
|
-
|
|
141
|
-
```
|
|
142
|
-
Task(
|
|
143
|
-
subagent_type: "general-purpose",
|
|
144
|
-
description: "Fix CI failures",
|
|
145
|
-
prompt: <read from references/stage-prompts.md#stage-4>
|
|
146
|
-
)
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
Substitute `{PR_NUMBER}`, `{BRANCH}`, `{FAILING_CHECKS}` into the prompt.
|
|
150
|
-
|
|
151
|
-
If fixed, return to Stage 3 (run CI watch again).
|
|
152
|
-
If unable to fix after 2 attempts, report to user and stop.
|
|
153
|
-
|
|
154
|
-
---
|
|
155
|
-
|
|
156
|
-
## Stage 5: Merge & Final Sync
|
|
157
|
-
|
|
158
|
-
Launch **Bash subagent** (haiku — simple git + platform CLI commands):
|
|
159
|
-
|
|
160
|
-
```
|
|
161
|
-
Task(
|
|
162
|
-
subagent_type: "Bash",
|
|
163
|
-
model: "haiku",
|
|
164
|
-
description: "Merge PR and sync",
|
|
165
|
-
prompt: <read from references/stage-prompts.md#stage-5>
|
|
166
|
-
)
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
Substitute `{PR_NUMBER}`, `{REMOTE}`, `{DEFAULT_BRANCH}`, merge/branch flags.
|
|
170
|
-
|
|
171
|
-
Parse LAND_REPORT.
|
|
172
|
-
|
|
173
|
-
---
|
|
174
|
-
|
|
175
|
-
## Final Report to User
|
|
176
|
-
|
|
177
|
-
Compile all stage reports into a summary:
|
|
178
|
-
|
|
179
|
-
```
|
|
180
|
-
Ship complete
|
|
181
|
-
|
|
182
|
-
Branch: {branch}
|
|
183
|
-
PR: {pr_url}
|
|
184
|
-
Merged: {merge_commit} ({merge_type})
|
|
185
|
-
|
|
186
|
-
Commits:
|
|
187
|
-
{list of commit messages, indented}
|
|
188
|
-
|
|
189
|
-
Files: {count} files changed ({diff_summary})
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
If any stage failed, report the failure point and suggested resolution.
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
# Sync Instructions
|
|
2
|
-
|
|
3
|
-
Synchronize local repository with the remote default branch using a single
|
|
4
|
-
Bash subagent to isolate all git operations from the primary conversation.
|
|
5
|
-
|
|
6
|
-
## Flags
|
|
7
|
-
|
|
8
|
-
Parse optional flags from the request:
|
|
9
|
-
- `--no-stash`: Don't auto-stash uncommitted changes
|
|
10
|
-
- `--no-cleanup`: Don't delete stale local branches
|
|
11
|
-
- `--no-rebase`: Use merge instead of rebase when on a feature branch
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
## Pre-flight
|
|
16
|
-
|
|
17
|
-
Before starting, check all dependencies in this table:
|
|
18
|
-
|
|
19
|
-
| Dependency | Type | Check | Required | Resolution | Detail |
|
|
20
|
-
|-----------|------|-------|----------|------------|--------|
|
|
21
|
-
| git | cli | `git --version` | yes | stop | Install from https://git-scm.com |
|
|
22
|
-
|
|
23
|
-
For each row, in order:
|
|
24
|
-
1. Run the Check command (for cli/npm) or test file existence (for agent/skill)
|
|
25
|
-
2. If found: continue silently
|
|
26
|
-
3. If missing: apply Resolution strategy
|
|
27
|
-
- **stop**: notify user with Detail, halt execution
|
|
28
|
-
- **url**: notify user with Detail (install link), halt execution
|
|
29
|
-
- **install**: notify user, run the command in Detail, continue if successful
|
|
30
|
-
- **ask**: notify user, offer to run command in Detail, continue either way (or halt if required)
|
|
31
|
-
- **fallback**: notify user with Detail, continue with degraded behavior
|
|
32
|
-
4. After all checks: summarize what's available and what's degraded
|
|
33
|
-
|
|
34
|
-
---
|
|
35
|
-
|
|
36
|
-
## Pre-flight Detection
|
|
37
|
-
|
|
38
|
-
Before launching the subagent, detect the remote and default branch:
|
|
39
|
-
|
|
40
|
-
```
|
|
41
|
-
REMOTE=$(git remote | head -1) # usually "origin"
|
|
42
|
-
DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/$REMOTE/HEAD 2>/dev/null | sed 's|.*/||')
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
Fallback chain if `symbolic-ref` fails:
|
|
46
|
-
1. Check `git show-ref --verify refs/heads/main` → use `main`
|
|
47
|
-
2. Check `git show-ref --verify refs/heads/master` → use `master`
|
|
48
|
-
3. If neither exists, report error and stop
|
|
49
|
-
|
|
50
|
-
Pass `{REMOTE}` and `{DEFAULT_BRANCH}` into the subagent prompt.
|
|
51
|
-
|
|
52
|
-
---
|
|
53
|
-
|
|
54
|
-
## Execution
|
|
55
|
-
|
|
56
|
-
Launch a **Bash subagent** (haiku — pure git commands, no code analysis needed):
|
|
57
|
-
|
|
58
|
-
```
|
|
59
|
-
Task(
|
|
60
|
-
subagent_type: "Bash",
|
|
61
|
-
model: "haiku",
|
|
62
|
-
description: "Sync repo with {DEFAULT_BRANCH}",
|
|
63
|
-
prompt: <see prompt below>
|
|
64
|
-
)
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### Subagent Prompt
|
|
68
|
-
|
|
69
|
-
```
|
|
70
|
-
Synchronize this git repository with {REMOTE}/{DEFAULT_BRANCH}. Execute the
|
|
71
|
-
following steps in order and report results.
|
|
72
|
-
|
|
73
|
-
Limit SYNC_REPORT to 15 lines maximum.
|
|
74
|
-
|
|
75
|
-
FLAGS: {flags from request, or "none"}
|
|
76
|
-
|
|
77
|
-
## Steps
|
|
78
|
-
|
|
79
|
-
1. **Check state**
|
|
80
|
-
BRANCH=$(git branch --show-current 2>/dev/null || echo "DETACHED")
|
|
81
|
-
CHANGES=$(git status --porcelain | head -20)
|
|
82
|
-
Record: current_branch=$BRANCH, has_changes=(non-empty CHANGES)
|
|
83
|
-
|
|
84
|
-
If BRANCH == "DETACHED":
|
|
85
|
-
Record error: "Detached HEAD — cannot sync. Checkout a branch first."
|
|
86
|
-
Skip to Output.
|
|
87
|
-
|
|
88
|
-
2. **Stash changes** (skip if --no-stash or no changes)
|
|
89
|
-
If has_changes and not --no-stash:
|
|
90
|
-
git stash push -m "sync-auto-stash-$(date +%Y%m%d-%H%M%S)"
|
|
91
|
-
Record: stash_created=true
|
|
92
|
-
|
|
93
|
-
3. **Sync {DEFAULT_BRANCH}**
|
|
94
|
-
git fetch {REMOTE}
|
|
95
|
-
If BRANCH != "{DEFAULT_BRANCH}":
|
|
96
|
-
git checkout {DEFAULT_BRANCH}
|
|
97
|
-
git pull {REMOTE} {DEFAULT_BRANCH} --ff-only
|
|
98
|
-
If pull fails (diverged):
|
|
99
|
-
git pull {REMOTE} {DEFAULT_BRANCH} --rebase
|
|
100
|
-
Record: main_commit=$(git rev-parse --short HEAD)
|
|
101
|
-
Record: main_message=$(git log -1 --format=%s)
|
|
102
|
-
|
|
103
|
-
4. **Return to branch and update** (skip if already on {DEFAULT_BRANCH})
|
|
104
|
-
If current_branch != "{DEFAULT_BRANCH}":
|
|
105
|
-
git checkout $BRANCH
|
|
106
|
-
If --no-rebase:
|
|
107
|
-
git merge {DEFAULT_BRANCH} --no-edit
|
|
108
|
-
Else:
|
|
109
|
-
git rebase {DEFAULT_BRANCH}
|
|
110
|
-
If rebase fails:
|
|
111
|
-
git rebase --abort
|
|
112
|
-
Record: rebase_status="conflict — aborted, branch unchanged"
|
|
113
|
-
|
|
114
|
-
5. **Restore stash** (if created in step 2)
|
|
115
|
-
If stash_created:
|
|
116
|
-
git stash pop
|
|
117
|
-
If pop fails (conflict):
|
|
118
|
-
Record: stash="conflict — run 'git stash show' to inspect"
|
|
119
|
-
Else:
|
|
120
|
-
Record: stash="restored"
|
|
121
|
-
|
|
122
|
-
6. **Cleanup branches** (skip if --no-cleanup)
|
|
123
|
-
git fetch --prune
|
|
124
|
-
|
|
125
|
-
# Delete branches whose remote is gone
|
|
126
|
-
for branch in $(git branch -vv | grep ': gone]' | awk '{print $1}'); do
|
|
127
|
-
if [ "$branch" != "$BRANCH" ]; then
|
|
128
|
-
git branch -d "$branch" 2>/dev/null && echo "Deleted: $branch"
|
|
129
|
-
fi
|
|
130
|
-
done
|
|
131
|
-
|
|
132
|
-
# Delete branches fully merged into {DEFAULT_BRANCH} (except current)
|
|
133
|
-
for branch in $(git branch --merged {DEFAULT_BRANCH} | grep -v '^\*' | grep -v '{DEFAULT_BRANCH}'); do
|
|
134
|
-
branch=$(echo "$branch" | xargs)
|
|
135
|
-
if [ "$branch" != "$BRANCH" ] && [ -n "$branch" ]; then
|
|
136
|
-
git branch -d "$branch" 2>/dev/null && echo "Deleted: $branch"
|
|
137
|
-
fi
|
|
138
|
-
done
|
|
139
|
-
|
|
140
|
-
Record: branches_cleaned={list of deleted branches, or "none"}
|
|
141
|
-
|
|
142
|
-
7. **Final state**
|
|
143
|
-
echo "Branch: $(git branch --show-current)"
|
|
144
|
-
echo "HEAD: $(git log -1 --format='%h %s')"
|
|
145
|
-
echo "Status: $(git status --short | wc -l) modified files"
|
|
146
|
-
|
|
147
|
-
## Output Format
|
|
148
|
-
|
|
149
|
-
SYNC_REPORT:
|
|
150
|
-
- status: success|failed
|
|
151
|
-
- remote: {REMOTE}
|
|
152
|
-
- default_branch: {DEFAULT_BRANCH}
|
|
153
|
-
- main_updated_to: {commit} - {message}
|
|
154
|
-
- current_branch: {branch}
|
|
155
|
-
- stash: restored|none|conflict
|
|
156
|
-
- rebase: success|conflict|skipped
|
|
157
|
-
- branches_cleaned: {list or "none"}
|
|
158
|
-
- errors: {any errors encountered}
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
---
|
|
162
|
-
|
|
163
|
-
## Report to User
|
|
164
|
-
|
|
165
|
-
Parse the subagent's SYNC_REPORT and present a clean summary:
|
|
166
|
-
|
|
167
|
-
```
|
|
168
|
-
Sync complete
|
|
169
|
-
Main: {commit} - {message}
|
|
170
|
-
Branch: {current_branch}
|
|
171
|
-
Stash: {status}
|
|
172
|
-
Cleaned: {branches or "none"}
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
If errors occurred, report them clearly with suggested resolution:
|
|
176
|
-
- Detached HEAD → suggest `git checkout <branch>`
|
|
177
|
-
- Rebase conflict → suggest `git rebase {DEFAULT_BRANCH}` manually and resolve
|
|
178
|
-
- Stash conflict → suggest `git stash show` and `git stash pop` manually
|