Skip to content

feat: add deep-work automation system#1644

Merged
senamakel merged 3 commits into
tinyhumansai:mainfrom
graycyrus:feat/deep-work-automation
May 16, 2026
Merged

feat: add deep-work automation system#1644
senamakel merged 3 commits into
tinyhumansai:mainfrom
graycyrus:feat/deep-work-automation

Conversation

@graycyrus
Copy link
Copy Markdown
Contributor

@graycyrus graycyrus commented May 13, 2026

Summary

Implements full workflow automation for GitHub issues using worktrees and AI agents, following the workflow patterns documented in workflow/ directory.

Features

Core Automation

  • Complete 12-step workflow - From issue selection through PR creation
  • Worktree-based development - Parallel work on multiple issues
  • AI agent orchestration - Automatic calls to architectobot, codecrusher, memory-keeper, pr-reviewer
  • Quality gates - Blocks progression on failed checks (typecheck, lint, format, build)

Commands Added

  • pnpm deep-work start <issue> - Full workflow for specific issue
  • pnpm deep-work pick - AI-powered issue selection + start workflow
  • pnpm deep-work continue - Resume from current state with intelligent detection
  • pnpm deep-work status - Progress dashboard for all active work
  • pnpm deep-work list - Simple worktree listing
  • pnpm deep-work cleanup <issue> - Clean up completed work

Workflow Steps Automated

  1. Worktree setup → Creates ../oh-<issue> worktree with new branch
  2. Issue fetching → Validates and fetches issue details
  3. Context gathering → Reads CLAUDE.md, memory.md, recent commits
  4. Planning → Calls architectobot agent for implementation plan
  5. Implementation → Calls codecrusher agent for coding
  6. Quality checks → Runs typecheck, lint, format, build
  7. Memory updates → Calls memory-keeper agent
  8. Commit → Proper commit message with issue reference
  9. Merge main → Handles upstream sync and conflicts
  10. Push & PR → Creates draft PR with template
  11. Review cycle → Calls pr-reviewer agent for automated review
  12. User confirmations → Asks before marking ready and cleanup

Implementation

  • Script structure: scripts/deep-work/ with modular design
  • Shared utilities: Common functions in lib.sh for worktree management
  • Error handling: Graceful failures with resume capability
  • Interactive checkpoints: User approval for major decisions

Testing

  • CLI help and command dispatch working
  • Status and list commands functional
  • Worktree creation and management
  • Integration with existing pnpm script ecosystem

Breaking Changes

None - purely additive feature.

Next Steps

  • Test full workflow end-to-end with real issue
  • Gather feedback on agent integration
  • Iterate on workflow steps based on usage

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added pnpm deep-work CLI command for managing GitHub issue workflows with subcommands: start (begin new issues), pick (smart issue selection), continue (resume sessions), status (view progress), list (show active issues), and cleanup (remove sessions)

Review Change Stack

Implements full workflow automation for GitHub issues using worktrees and AI agents.

Features:
- Complete 12-step workflow automation from issue selection to PR
- Worktree-based parallel development
- AI agent orchestration (architectobot, codecrusher, memory-keeper, pr-reviewer)
- Smart issue selection with filtering
- Resume capability with state detection
- Quality gates and automated checks

Commands:
- pnpm deep-work start <issue> - Full workflow for specific issue
- pnpm deep-work pick - AI-powered issue selection + start
- pnpm deep-work continue - Resume from current state
- pnpm deep-work status - Progress dashboard
- pnpm deep-work cleanup <issue> - Clean up completed work

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7e23fec2-d6d9-4db2-9446-8a5ea8b0917a

📥 Commits

Reviewing files that changed from the base of the PR and between 574d40a and 5815b22.

📒 Files selected for processing (9)
  • package.json
  • scripts/deep-work/cleanup.sh
  • scripts/deep-work/cli.sh
  • scripts/deep-work/continue.sh
  • scripts/deep-work/lib.sh
  • scripts/deep-work/list.sh
  • scripts/deep-work/pick.sh
  • scripts/deep-work/start.sh
  • scripts/deep-work/status.sh

📝 Walkthrough

Walkthrough

This PR introduces a comprehensive Bash CLI system for managing AI-assisted GitHub issue resolution workflows. It includes CLI dispatch, shared worktree/repository utilities, smart issue picking with scoring, full end-to-end workflow automation (planning, implementation, quality checks, PR creation), session resumption logic, and worktree lifecycle management.

Changes

Deep Work Issue Automation

Layer / File(s) Summary
CLI entry point and dispatcher
package.json, scripts/deep-work/cli.sh
New deep-work npm script routes pnpm deep-work <cmd> to subcommand scripts via dispatcher with usage/help output.
Shared utility library for workflows
scripts/deep-work/lib.sh
Provides worktree directory/branch naming, worktree creation/listing/cleanup, repository resolution via environment variables, upstream/origin synchronization, and automated quality check orchestration (typecheck, lint, format, build).
Smart issue selection and scoring
scripts/deep-work/pick.sh
Fetches open unassigned issues from GitHub, scores candidates by label boosts (bug/enhancement/good-first-issue), penalties (large/epic/major), and description length; displays top 10 and prompts user to select or browse.
Full issue workflow orchestration
scripts/deep-work/start.sh
End-to-end automation: validates issue, syncs upstream, creates per-issue worktree, runs Claude architecture planning and code implementation tasks, executes quality checks, commits with attributed messages, merges main, pushes to origin, creates draft PR with GitHub auth, runs PR review task, and optionally cleans up worktree.
Resume interrupted workflow sessions
scripts/deep-work/continue.sh
Resumes in-progress work by analyzing Git state; offers context-specific actions: (1) if uncommitted changes exist, prompt to continue coding via Claude, run checks, commit, or review files; (2) if unpushed commits exist, prompt to push/create PR, check quality, or update memory; (3) if clean, prompt to view PR status, final checks, or cleanup.
Session status reporting and cleanup
scripts/deep-work/list.sh, scripts/deep-work/status.sh, scripts/deep-work/cleanup.sh
list.sh enumerates worktrees with git branch and cleanliness status; status.sh generates formatted report of active sessions including PR state, draft status, and progress; cleanup.sh prompts for confirmation, detects uncommitted changes, queries GitHub PR status, and removes local worktree/branch while preserving remote PR.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

A rabbit scripts the deepest work,
With Claude's tasks through features lurk—
Pick issues smart, start workflows tight,
Continue sessions through the night,
Until the PR sees the light! 🐰✨


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

Scripts should be in scripts/deep-work/ not directly in scripts/
Copy link
Copy Markdown
Contributor Author

@graycyrus graycyrus left a comment

Choose a reason for hiding this comment

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

Walkthrough

This PR adds a pnpm deep-work command suite — eight shell scripts under scripts/deep-work/ — that automates the full GitHub issue workflow: syncing upstream, creating a git worktree, calling AI agents for planning and implementation, running quality checks, committing, pushing, creating a PR, and running an automated review. The modular layout (shared lib.sh, individual verb scripts, cli.sh dispatcher) is consistent with the existing scripts/work/ and scripts/review/ structure.

However, the PR has several correctness and security problems that need to be addressed before merging.

Change Summary

File Summary
package.json Registers deep-work as bash scripts/deep-work/cli.sh
scripts/deep-work/cli.sh Dispatcher: routes start, pick, continue, status, list, cleanup
scripts/deep-work/lib.sh Shared helpers: worktree management, repo resolution, quality checks
scripts/deep-work/start.sh Full 12-step workflow: sync → worktree → plan → implement → QC → commit → push → PR → review
scripts/deep-work/continue.sh Resume from current state with interactive branch detection
scripts/deep-work/pick.sh Smart issue selection via jq scoring, then delegates to start.sh
scripts/deep-work/status.sh Progress dashboard over all active worktrees
scripts/deep-work/list.sh Simple worktree listing
scripts/deep-work/cleanup.sh Guided worktree teardown with PR status awareness

Verified / Looks Good

  • cli.sh dispatch pattern is correct; exec hand-off means no dangling shell processes
  • lib.sh sourcing of scripts/review/lib.sh and layered env-var resolution is sensible
  • pick.sh jq scoring logic is sound
  • cleanup.sh double-confirmation flow is good UX
  • status.sh uses process substitution correctly
  • worktree_branch_for_issue slug generation matches existing patterns

Nitpicks

  1. Every file is missing a trailing newline (POSIX requires text files to end with newline)
  2. list.sh sets worktrees_found=true in a subshell (pipe) so it's never visible — then works around it by calling list_deep_work_worktrees a second time
  3. lib.sh sync_upstream uses git merge --ff-only || git merge fallback which may produce unexpected merges on non-ff failures
  4. start.sh uses context_info+="...\n" but \n in double-quotes produces literal backslash-n, not a newline

Questions

  1. The read -r pauses after planning and implementation suggest the user must supervise each step. Is this intended as semi-automated (with checkpoints) rather than fully automated?
  2. worktree_exists only checks [ -d ] — if the dir was manually deleted without git worktree remove, stale git refs could cause issues. Should this check git worktree list instead?


# Call architectobot agent directly via claude with task flag
echo "$planning_prompt" | claude --task architectobot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[critical] claude --task architectobot is not a valid Claude Code CLI invocation. Claude Code doesn't have a --task flag. This means steps 2, 3, 6, and 10 of the workflow will error out immediately.

The same issue affects lines 181, 216, and in continue.sh at lines 111 and 236.

Suggested change
claude "$planning_prompt"


echo "[deep-work] staging changes for commit..."
git add .

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[critical] git add . blindly stages everything — could commit .env files, build artifacts, or editor swap files that happen to be in the worktree. CLAUDE.md explicitly says: "prefer adding specific files by name rather than git add -A or git add .".

Suggested change
# Stage tracked modifications only; let the user explicitly add new files
git add -u
echo "[deep-work] staged tracked changes. Untracked files (if any):"
git ls-files --others --exclude-standard

commit_message="fix(#${issue}): ${title}

${body}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[critical] The full issue body ($body) is interpolated into the commit message. This is both a security risk (crafted issue bodies could contain shell metacharacters that expand during assignment) and a usability problem (issue bodies can be many KB). The existing scripts/work/start.sh avoids this — use only the title + issue reference.

Suggested change
git commit -m "fix(#${issue}): ${title}
Closes #${issue}
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>"

Comment thread scripts/deep-work/lib.sh
worktree_dir_for_issue() {
local issue="$1"
echo "../oh-$issue"
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[major] This returns a relative path (../oh-<n>). Once start.sh does cd "$worktree_dir", any subsequent call to worktree_dir_for_issue resolves incorrectly (it would be ../../oh-<n> relative to the new CWD). Use the already-available $repo_root:

Suggested change
}
echo "${repo_root}/../oh-${issue}"

--body "$pr_body" \
--draft \
--head "$(gh auth status 2>&1 | grep 'Logged in.*as' | sed 's/.*as //' | cut -d' ' -f1):$branch" \
--base main \
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[major] gh auth status output format is not stable across gh versions and is not meant for programmatic use. If the format changes or there are multiple accounts, this silently produces a broken --head value.

Use the API instead:

Suggested change
--base main \
--head "$(gh api /user --jq '.login'):$branch" \


# Fetch main from main worktree location
cd "$repo_root"
sync_upstream
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[major] This cd $repo_root && sync_upstream && cd $worktree_dir block switches the main worktree to the main branch and runs a full fetch+submodule update — which may disturb the developer's main checkout (could be on a different branch). Step 0 already synced before creating the worktree.

Just fetch and merge from within the worktree:

git fetch origin main
if ! git merge origin/main; then

Comment thread scripts/deep-work/lib.sh
if ! pnpm format:check; then
echo "[deep-work] running formatter..."
pnpm format
fi
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[minor] If pnpm format itself fails, the function continues and reports success. Also, no indication that the formatter modified files (working tree is now dirty).

Suggested change
fi
if ! pnpm format; then
echo "[deep-work] ❌ formatter failed"
return 1
fi
echo "[deep-work] ⚠️ formatter made changes — files are now modified"

@senamakel senamakel marked this pull request as ready for review May 16, 2026 02:55
@senamakel senamakel requested a review from a team May 16, 2026 02:55
@senamakel senamakel merged commit 98b579e into tinyhumansai:main May 16, 2026
18 of 19 checks passed
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.

2 participants