dmux 5.6.3 → 5.7.0
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/README.ja.md +93 -0
- package/README.md +7 -1
- package/dist/DmuxApp.d.ts.map +1 -1
- package/dist/DmuxApp.js +273 -35
- package/dist/DmuxApp.js.map +1 -1
- package/dist/actions/implementations/closeAction.d.ts.map +1 -1
- package/dist/actions/implementations/closeAction.js +85 -70
- package/dist/actions/implementations/closeAction.js.map +1 -1
- package/dist/actions/implementations/createPullRequestAction.d.ts +4 -0
- package/dist/actions/implementations/createPullRequestAction.d.ts.map +1 -0
- package/dist/actions/implementations/createPullRequestAction.js +218 -0
- package/dist/actions/implementations/createPullRequestAction.js.map +1 -0
- package/dist/actions/implementations/index.d.ts +1 -0
- package/dist/actions/implementations/index.d.ts.map +1 -1
- package/dist/actions/implementations/index.js +1 -0
- package/dist/actions/implementations/index.js.map +1 -1
- package/dist/actions/implementations/mergeAction.js +8 -3
- package/dist/actions/implementations/mergeAction.js.map +1 -1
- package/dist/actions/index.d.ts.map +1 -1
- package/dist/actions/index.js +2 -0
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/paneActions.d.ts +1 -1
- package/dist/actions/paneActions.d.ts.map +1 -1
- package/dist/actions/paneActions.js +1 -1
- package/dist/actions/paneActions.js.map +1 -1
- package/dist/actions/types.d.ts +11 -2
- package/dist/actions/types.d.ts.map +1 -1
- package/dist/actions/types.js +9 -0
- package/dist/actions/types.js.map +1 -1
- package/dist/components/inputs/CleanTextInput.d.ts +1 -0
- package/dist/components/inputs/CleanTextInput.d.ts.map +1 -1
- package/dist/components/inputs/CleanTextInput.js +40 -42
- package/dist/components/inputs/CleanTextInput.js.map +1 -1
- package/dist/components/panes/PaneCard.d.ts +3 -1
- package/dist/components/panes/PaneCard.d.ts.map +1 -1
- package/dist/components/panes/PaneCard.js +14 -4
- package/dist/components/panes/PaneCard.js.map +1 -1
- package/dist/components/panes/PanesGrid.d.ts +4 -1
- package/dist/components/panes/PanesGrid.d.ts.map +1 -1
- package/dist/components/panes/PanesGrid.js +27 -15
- package/dist/components/panes/PanesGrid.js.map +1 -1
- package/dist/components/popups/config.d.ts +4 -4
- package/dist/components/popups/config.js +6 -6
- package/dist/components/popups/config.js.map +1 -1
- package/dist/components/popups/inputPopup.js +3 -3
- package/dist/components/popups/inputPopup.js.map +1 -1
- package/dist/components/popups/prReviewPopup.d.ts +12 -0
- package/dist/components/popups/prReviewPopup.d.ts.map +1 -0
- package/dist/components/popups/prReviewPopup.js +278 -0
- package/dist/components/popups/prReviewPopup.js.map +1 -0
- package/dist/components/popups/reopenWorktreePopup.js +1 -1
- package/dist/components/popups/reopenWorktreePopup.js.map +1 -1
- package/dist/components/popups/settingsPopup.js +72 -6
- package/dist/components/popups/settingsPopup.js.map +1 -1
- package/dist/components/ui/FooterHelp.d.ts.map +1 -1
- package/dist/components/ui/FooterHelp.js +5 -4
- package/dist/components/ui/FooterHelp.js.map +1 -1
- package/dist/hooks/useActionSystem.d.ts +12 -2
- package/dist/hooks/useActionSystem.d.ts.map +1 -1
- package/dist/hooks/useActionSystem.js +19 -1
- package/dist/hooks/useActionSystem.js.map +1 -1
- package/dist/hooks/useInputHandling.d.ts +2 -1
- package/dist/hooks/useInputHandling.d.ts.map +1 -1
- package/dist/hooks/useInputHandling.js +84 -18
- package/dist/hooks/useInputHandling.js.map +1 -1
- package/dist/hooks/usePaneLoading.d.ts.map +1 -1
- package/dist/hooks/usePaneLoading.js +28 -3
- package/dist/hooks/usePaneLoading.js.map +1 -1
- package/dist/hooks/usePaneSync.d.ts.map +1 -1
- package/dist/hooks/usePaneSync.js +8 -5
- package/dist/hooks/usePaneSync.js.map +1 -1
- package/dist/hooks/usePanes.d.ts.map +1 -1
- package/dist/hooks/usePanes.js +8 -1
- package/dist/hooks/usePanes.js.map +1 -1
- package/dist/hooks/useShellDetection.d.ts.map +1 -1
- package/dist/hooks/useShellDetection.js +7 -1
- package/dist/hooks/useShellDetection.js.map +1 -1
- package/dist/index.js +35 -9
- package/dist/index.js.map +1 -1
- package/dist/panes/decorative-pane.js +57 -27
- package/dist/panes/decorative-pane.js.map +1 -1
- package/dist/services/DmuxFocusService.d.ts.map +1 -1
- package/dist/services/DmuxFocusService.js +19 -14
- package/dist/services/DmuxFocusService.js.map +1 -1
- package/dist/services/PaneEventService.d.ts +11 -0
- package/dist/services/PaneEventService.d.ts.map +1 -1
- package/dist/services/PaneEventService.js +31 -3
- package/dist/services/PaneEventService.js.map +1 -1
- package/dist/services/PaneWorkerManager.d.ts.map +1 -1
- package/dist/services/PaneWorkerManager.js +1 -0
- package/dist/services/PaneWorkerManager.js.map +1 -1
- package/dist/services/PopupManager.d.ts +17 -5
- package/dist/services/PopupManager.d.ts.map +1 -1
- package/dist/services/PopupManager.js +140 -30
- package/dist/services/PopupManager.js.map +1 -1
- package/dist/services/StatusDetector.d.ts +1 -0
- package/dist/services/StatusDetector.d.ts.map +1 -1
- package/dist/services/StatusDetector.js +44 -0
- package/dist/services/StatusDetector.js.map +1 -1
- package/dist/services/TmuxHookManager.d.ts.map +1 -1
- package/dist/services/TmuxHookManager.js +3 -2
- package/dist/services/TmuxHookManager.js.map +1 -1
- package/dist/services/TmuxService.d.ts +7 -0
- package/dist/services/TmuxService.d.ts.map +1 -1
- package/dist/services/TmuxService.js +15 -1
- package/dist/services/TmuxService.js.map +1 -1
- package/dist/theme/colors.d.ts +24 -10
- package/dist/theme/colors.d.ts.map +1 -1
- package/dist/theme/colors.js +143 -19
- package/dist/theme/colors.js.map +1 -1
- package/dist/theme/themePalette.d.ts +6 -0
- package/dist/theme/themePalette.d.ts.map +1 -0
- package/dist/theme/themePalette.js +18 -0
- package/dist/theme/themePalette.js.map +1 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/agentLaunch.d.ts +2 -0
- package/dist/utils/agentLaunch.d.ts.map +1 -1
- package/dist/utils/agentLaunch.js +10 -9
- package/dist/utils/agentLaunch.js.map +1 -1
- package/dist/utils/aiMerge.d.ts +4 -0
- package/dist/utils/aiMerge.d.ts.map +1 -1
- package/dist/utils/aiMerge.js +7 -4
- package/dist/utils/aiMerge.js.map +1 -1
- package/dist/utils/asciiArt.d.ts.map +1 -1
- package/dist/utils/asciiArt.js +2 -1
- package/dist/utils/asciiArt.js.map +1 -1
- package/dist/utils/attachAgent.d.ts.map +1 -1
- package/dist/utils/attachAgent.js +20 -1
- package/dist/utils/attachAgent.js.map +1 -1
- package/dist/utils/codexHooks.d.ts +25 -0
- package/dist/utils/codexHooks.d.ts.map +1 -0
- package/dist/utils/codexHooks.js +131 -0
- package/dist/utils/codexHooks.js.map +1 -0
- package/dist/utils/conflictResolutionPane.d.ts.map +1 -1
- package/dist/utils/conflictResolutionPane.js +4 -0
- package/dist/utils/conflictResolutionPane.js.map +1 -1
- package/dist/utils/generated-agents-doc.d.ts +1 -1
- package/dist/utils/generated-agents-doc.js +1 -1
- package/dist/utils/githubPullRequest.d.ts +18 -0
- package/dist/utils/githubPullRequest.d.ts.map +1 -0
- package/dist/utils/githubPullRequest.js +196 -0
- package/dist/utils/githubPullRequest.js.map +1 -0
- package/dist/utils/input.d.ts +7 -6
- package/dist/utils/input.d.ts.map +1 -1
- package/dist/utils/input.js +47 -24
- package/dist/utils/input.js.map +1 -1
- package/dist/utils/paneColors.d.ts +7 -0
- package/dist/utils/paneColors.d.ts.map +1 -0
- package/dist/utils/paneColors.js +42 -0
- package/dist/utils/paneColors.js.map +1 -0
- package/dist/utils/paneCreation.d.ts.map +1 -1
- package/dist/utils/paneCreation.js +103 -34
- package/dist/utils/paneCreation.js.map +1 -1
- package/dist/utils/paneTitle.d.ts +1 -0
- package/dist/utils/paneTitle.d.ts.map +1 -1
- package/dist/utils/paneTitle.js +5 -1
- package/dist/utils/paneTitle.js.map +1 -1
- package/dist/utils/paneTitlePrefix.d.ts +8 -0
- package/dist/utils/paneTitlePrefix.d.ts.map +1 -0
- package/dist/utils/paneTitlePrefix.js +20 -0
- package/dist/utils/paneTitlePrefix.js.map +1 -0
- package/dist/utils/popup.d.ts +1 -0
- package/dist/utils/popup.d.ts.map +1 -1
- package/dist/utils/popup.js +9 -2
- package/dist/utils/popup.js.map +1 -1
- package/dist/utils/prSummary.d.ts +34 -0
- package/dist/utils/prSummary.d.ts.map +1 -0
- package/dist/utils/prSummary.js +130 -0
- package/dist/utils/prSummary.js.map +1 -0
- package/dist/utils/projectActions.d.ts +6 -0
- package/dist/utils/projectActions.d.ts.map +1 -1
- package/dist/utils/projectActions.js +46 -0
- package/dist/utils/projectActions.js.map +1 -1
- package/dist/utils/reopenWorktree.d.ts.map +1 -1
- package/dist/utils/reopenWorktree.js +37 -5
- package/dist/utils/reopenWorktree.js.map +1 -1
- package/dist/utils/resumeBranches.d.ts.map +1 -1
- package/dist/utils/resumeBranches.js +9 -3
- package/dist/utils/resumeBranches.js.map +1 -1
- package/dist/utils/settingsManager.d.ts +11 -3
- package/dist/utils/settingsManager.d.ts.map +1 -1
- package/dist/utils/settingsManager.js +96 -21
- package/dist/utils/settingsManager.js.map +1 -1
- package/dist/utils/sidebarProjects.d.ts +10 -3
- package/dist/utils/sidebarProjects.d.ts.map +1 -1
- package/dist/utils/sidebarProjects.js +125 -10
- package/dist/utils/sidebarProjects.js.map +1 -1
- package/dist/utils/tmuxHookCommands.d.ts +6 -0
- package/dist/utils/tmuxHookCommands.d.ts.map +1 -1
- package/dist/utils/tmuxHookCommands.js +12 -0
- package/dist/utils/tmuxHookCommands.js.map +1 -1
- package/dist/utils/tmuxSendKeys.d.ts +2 -0
- package/dist/utils/tmuxSendKeys.d.ts.map +1 -0
- package/dist/utils/tmuxSendKeys.js +8 -0
- package/dist/utils/tmuxSendKeys.js.map +1 -0
- package/dist/utils/toastLayout.d.ts +10 -0
- package/dist/utils/toastLayout.d.ts.map +1 -0
- package/dist/utils/toastLayout.js +24 -0
- package/dist/utils/toastLayout.js.map +1 -0
- package/dist/utils/welcomePane.d.ts +5 -1
- package/dist/utils/welcomePane.d.ts.map +1 -1
- package/dist/utils/welcomePane.js +33 -3
- package/dist/utils/welcomePane.js.map +1 -1
- package/dist/utils/welcomePaneManager.d.ts +3 -1
- package/dist/utils/welcomePaneManager.d.ts.map +1 -1
- package/dist/utils/welcomePaneManager.js +40 -2
- package/dist/utils/welcomePaneManager.js.map +1 -1
- package/dist/workers/PaneWorker.js +77 -0
- package/dist/workers/PaneWorker.js.map +1 -1
- package/dist/workers/WorkerMessages.d.ts +9 -1
- package/dist/workers/WorkerMessages.d.ts.map +1 -1
- package/dist/workers/WorkerMessages.js.map +1 -1
- package/dist/workers/panePollingWorker.js +33 -2
- package/dist/workers/panePollingWorker.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* Auto-generated AGENTS.md content
|
|
3
3
|
* DO NOT EDIT MANUALLY - run 'pnpm generate:hooks-docs' to regenerate
|
|
4
4
|
*/
|
|
5
|
-
export declare const AGENTS_MD = "# dmux Hooks System - Agent Reference\n\n**Auto-generated documentation for AI agents**\n\nThis document contains everything an AI agent needs to create, modify, and understand dmux hooks. It is automatically generated from the dmux source code and embedded in the binary.\n\n## What You're Working On\n\nYou are editing hooks for **dmux**, a tmux pane manager that creates AI-powered development workflows. Each pane runs in its own git worktree with an AI agent.\n\n## Your Goal\n\nCreate executable bash scripts in `.dmux-hooks/` that run automatically at key lifecycle events.\n\n## Quick Start\n\n1. **Create a hook file**: `touch .dmux-hooks/worktree_created`\n2. **Make it executable**: `chmod +x .dmux-hooks/worktree_created`\n3. **Add shebang**: Start with `#!/bin/bash`\n4. **Use environment variables**: Access `$DMUX_ROOT`, `$DMUX_WORKTREE_PATH`, etc.\n5. **Test it**: Set env vars manually and run the script\n\n## Hook Execution Model\n\n- **Non-blocking**: Hooks run in background (detached processes)\n- **Silent failures**: Hook errors are logged but don't stop dmux\n- **Environment-based**: All context passed via environment variables\n- **Version controlled**: Hooks in `.dmux-hooks/` are shared with team\n- **Priority resolution**: `.dmux-hooks/` \u2192 `.dmux/hooks/` \u2192 `~/.dmux/hooks/`\n\n## Available Hooks\n\n### Pane Lifecycle Hooks\n\n| Hook | When | Common Use Cases |\n|------|------|------------------|\n| `before_pane_create` | Before pane creation | Validation, notifications, pre-flight checks |\n| `pane_created` | After pane, before worktree | Configure tmux settings, prepare environment |\n| `worktree_created` | After full setup | Install deps, copy configs, setup git |\n| `before_pane_close` | Before closing | Save state, backup uncommitted work |\n| `pane_closed` | After closed | Cleanup resources, analytics, notifications |\n\n### Worktree Lifecycle Hooks\n\n| Hook | When | Common Use Cases |\n|------|------|------------------|\n| `before_worktree_remove` | Before worktree removal | Archive worktree, save artifacts |\n| `worktree_removed` | After worktree removed | Cleanup external references |\n\n### Merge Lifecycle Hooks\n\n| Hook | When | Common Use Cases |\n|------|------|------------------|\n| `pre_merge` | Before merge operation | Run final tests, create backups |\n| `post_merge` | After successful merge | Deploy, close issues, notify team |\n\n### Interactive Hooks (with HTTP callbacks)\n\n| Hook | When | Common Use Cases |\n|------|------|------------------|\n| `run_test` | When tests triggered | Run test suite, report status via HTTP |\n| `run_dev` | When dev server triggered | Start dev server, create tunnel, report URL |\n\n\n## Environment Variables\n\n### Always Available\n```bash\nDMUX_ROOT=\"/path/to/project\" # Project root directory\nDMUX_SERVER_PORT=\"3142\" # HTTP server port\n```\n\n### Pane Context (most hooks)\n```bash\nDMUX_PANE_ID=\"dmux-1234567890\" # dmux pane identifier\nDMUX_SLUG=\"fix-auth-bug\" # Branch/worktree name\nDMUX_PROMPT=\"Fix authentication bug\" # User's prompt\nDMUX_AGENT=\"claude\" # Agent type (registry id, e.g. claude, codex, opencode)\nDMUX_TMUX_PANE_ID=\"%38\" # tmux pane ID\n```\n\n### Worktree Context\n```bash\nDMUX_WORKTREE_PATH=\"/path/.dmux/worktrees/fix-auth-bug\"\nDMUX_BRANCH=\"fix-auth-bug\" # Same as slug\n```\n\n### Merge Context\n```bash\nDMUX_TARGET_BRANCH=\"main\" # Branch being merged into\n```\n\n## HTTP Callback API\n\nInteractive hooks (`run_test` and `run_dev`) can update dmux UI via HTTP.\n\n### Update Test Status\n```bash\ncurl -X PUT \"http://localhost:$DMUX_SERVER_PORT/api/panes/$DMUX_PANE_ID/test\" -H \"Content-Type: application/json\" -d '{\"status\": \"running\", \"output\": \"optional test output\"}'\n\n# Status values: \"running\" | \"passed\" | \"failed\"\n```\n\n### Update Dev Server\n```bash\ncurl -X PUT \"http://localhost:$DMUX_SERVER_PORT/api/panes/$DMUX_PANE_ID/dev\" -H \"Content-Type: application/json\" -d '{\"status\": \"running\", \"url\": \"http://localhost:3000\"}'\n\n# Status values: \"running\" | \"stopped\"\n# url: Can be localhost or tunnel URL (ngrok, cloudflared, etc.)\n```\n\n## Common Patterns\n\n### Pattern 1: Install Dependencies\n```bash\n#!/bin/bash\n# .dmux-hooks/worktree_created\n\ncd \"$DMUX_WORKTREE_PATH\"\n\nif [ -f \"pnpm-lock.yaml\" ]; then\n pnpm install --prefer-offline &\nelif [ -f \"package-lock.json\" ]; then\n npm install &\nelif [ -f \"yarn.lock\" ]; then\n yarn install &\nelif [ -f \"Gemfile\" ]; then\n bundle install &\nelif [ -f \"requirements.txt\" ]; then\n pip install -r requirements.txt &\nelif [ -f \"Cargo.toml\" ]; then\n cargo build &\nfi\n```\n\n### Pattern 2: Copy Configuration\n```bash\n#!/bin/bash\n# .dmux-hooks/worktree_created\n\n# Copy environment file\nif [ -f \"$DMUX_ROOT/.env.local\" ]; then\n cp \"$DMUX_ROOT/.env.local\" \"$DMUX_WORKTREE_PATH/.env.local\"\nfi\n\n# Copy other config files\nfor file in .env.development .npmrc .yarnrc; do\n if [ -f \"$DMUX_ROOT/$file\" ]; then\n cp \"$DMUX_ROOT/$file\" \"$DMUX_WORKTREE_PATH/$file\"\n fi\ndone\n```\n\n### Pattern 3: Run Tests with Status Updates\n```bash\n#!/bin/bash\n# .dmux-hooks/run_test\n\nset -e\ncd \"$DMUX_WORKTREE_PATH\"\nAPI=\"http://localhost:$DMUX_SERVER_PORT/api/panes/$DMUX_PANE_ID/test\"\n\n# Update: starting\ncurl -s -X PUT \"$API\" -H \"Content-Type: application/json\" -d '{\"status\": \"running\"}' > /dev/null\n\n# Run tests and capture output\nOUTPUT_FILE=\"/tmp/dmux-test-$DMUX_PANE_ID.txt\"\nif pnpm test > \"$OUTPUT_FILE\" 2>&1; then\n STATUS=\"passed\"\nelse\n STATUS=\"failed\"\nfi\n\n# Get output (truncate if too long)\nOUTPUT=$(head -c 5000 \"$OUTPUT_FILE\")\n\n# Update: complete\ncurl -s -X PUT \"$API\" -H \"Content-Type: application/json\" -d \"$(jq -n --arg status \"$STATUS\" --arg output \"$OUTPUT\" '{status: $status, output: $output}')\" > /dev/null\n\nrm -f \"$OUTPUT_FILE\"\n```\n\n### Pattern 4: Dev Server with Tunnel\n```bash\n#!/bin/bash\n# .dmux-hooks/run_dev\n\nset -e\ncd \"$DMUX_WORKTREE_PATH\"\nAPI=\"http://localhost:$DMUX_SERVER_PORT/api/panes/$DMUX_PANE_ID/dev\"\n\n# Start dev server in background\nLOG_FILE=\"/tmp/dmux-dev-$DMUX_PANE_ID.log\"\npnpm dev > \"$LOG_FILE\" 2>&1 &\nDEV_PID=$!\n\n# Wait for server to start\nsleep 5\n\n# Detect port from logs\nPORT=$(grep -oP 'localhost:Kd+' \"$LOG_FILE\" | head -1)\n[ -z \"$PORT\" ] && PORT=3000\n\n# Optional: Create tunnel with cloudflared\nif command -v cloudflared &> /dev/null; then\n TUNNEL=$(cloudflared tunnel --url \"http://localhost:$PORT\" 2>&1 | grep -oP 'https://[a-z0-9-]+.trycloudflare.com' | head -1)\n URL=\"${TUNNEL:-http://localhost:$PORT}\"\nelse\n URL=\"http://localhost:$PORT\"\nfi\n\n# Report status\ncurl -s -X PUT \"$API\" -H \"Content-Type: application/json\" -d \"{\"status\": \"running\", \"url\": \"$URL\"}\" > /dev/null\n\necho \"[Hook] Dev server running at $URL (PID: $DEV_PID)\"\n```\n\n### Pattern 5: Post-Merge Deployment\n```bash\n#!/bin/bash\n# .dmux-hooks/post_merge\n\nset -e\ncd \"$DMUX_ROOT\"\n\n# Only deploy from main/master\nif [ \"$DMUX_TARGET_BRANCH\" != \"main\" ] && [ \"$DMUX_TARGET_BRANCH\" != \"master\" ]; then\n exit 0\nfi\n\n# Push to remote\ngit push origin \"$DMUX_TARGET_BRANCH\"\n\n# Trigger deployment (example: Vercel)\nif [ -n \"$VERCEL_TOKEN\" ]; then\n curl -s -X POST \"https://api.vercel.com/v1/deployments\" -H \"Authorization: Bearer $VERCEL_TOKEN\" -H \"Content-Type: application/json\" -d '{\"name\": \"my-project\"}' > /dev/null\nfi\n\n# Close GitHub issue if prompt contains #123\nISSUE=$(echo \"$DMUX_PROMPT\" | grep -oP '#Kd+' | head -1)\nif [ -n \"$ISSUE\" ] && command -v gh &> /dev/null; then\n gh issue close \"$ISSUE\" -c \"Resolved in $DMUX_SLUG, merged to $DMUX_TARGET_BRANCH\" 2>/dev/null || true\nfi\n```\n\n## Best Practices\n\n1. **Always start with shebang**: `#!/bin/bash`\n2. **Set error handling**: `set -e` (exit on error)\n3. **Make executable**: `chmod +x .dmux-hooks/hook_name`\n4. **Background long operations**: Append `&` to avoid blocking\n5. **Check for required tools**: `command -v tool &> /dev/null`\n6. **Log for debugging**: `echo \"[Hook] message\" >> \"$DMUX_ROOT/.dmux/hooks.log\"`\n7. **Handle missing vars gracefully**: `[ -z \"$VAR\" ] && exit 0`\n8. **Use silent curl**: `curl -s` to avoid noise in logs\n9. **Clean up temp files**: Remove files in `/tmp/`\n10. **Test before committing**: Run hooks manually with mock env vars\n\n## Testing Hooks\n\n### Manual Testing\n```bash\n# 1. Set environment variables\nexport DMUX_ROOT=\"$(pwd)\"\nexport DMUX_PANE_ID=\"test-pane\"\nexport DMUX_SLUG=\"test-branch\"\nexport DMUX_WORKTREE_PATH=\"$(pwd)\"\nexport DMUX_SERVER_PORT=\"3142\"\nexport DMUX_AGENT=\"claude\"\nexport DMUX_PROMPT=\"Test prompt\"\n\n# 2. Run hook directly\n./.dmux-hooks/worktree_created\n\n# 3. Check exit code\necho $? # Should be 0 for success\n```\n\n### Syntax Check\n```bash\n# Check for syntax errors without running\nbash -n ./.dmux-hooks/worktree_created\n```\n\n### Shellcheck (if available)\n```bash\nshellcheck ./.dmux-hooks/worktree_created\n```\n\n## Project Context Analysis\n\nBefore creating hooks, analyze these files in the project:\n\n### Package Manager Detection\n```bash\n# Check which package manager is used\nif [ -f \"pnpm-lock.yaml\" ]; then\n # Use: pnpm install, pnpm test, pnpm dev\nelif [ -f \"package-lock.json\" ]; then\n # Use: npm install, npm test, npm run dev\nelif [ -f \"yarn.lock\" ]; then\n # Use: yarn install, yarn test, yarn dev\nfi\n```\n\n### Test Command Discovery\n```bash\n# Read package.json to find test command\ncat package.json | grep '\"test\"'\n# Or with jq:\njq -r '.scripts.test' package.json\n```\n\n### Dev Command Discovery\n```bash\n# Read package.json to find dev command\ncat package.json | grep '\"dev\"'\n# Or with jq:\njq -r '.scripts.dev' package.json\n```\n\n### Environment Variables\n```bash\n# Check for .env files to copy\nls -la | grep '.env'\n```\n\n### Build System\n```bash\n# Detect build system\nif [ -f \"vite.config.ts\" ]; then\n # Vite project\nelif [ -f \"next.config.js\" ]; then\n # Next.js project\nelif [ -f \"nuxt.config.ts\" ]; then\n # Nuxt project\nfi\n```\n\n## Common Mistakes to Avoid\n\n\u274C **Blocking operations**: `sleep 60` (blocks dmux)\n\u2705 **Background long tasks**: `slow_operation &`\n\n\u274C **Hardcoded paths**: `/Users/me/project`\n\u2705 **Use variables**: `\"$DMUX_ROOT\"`\n\n\u274C **Assuming tools exist**: `pnpm install`\n\u2705 **Check first**: `command -v pnpm && pnpm install`\n\n\u274C **No error handling**: Script fails silently\n\u2705 **Set error mode**: `set -e` or check exit codes\n\n\u274C **Forgetting executable bit**: Hook won't run\n\u2705 **Make executable**: `chmod +x`\n\n\u274C **Noisy output**: Clutters dmux logs\n\u2705 **Silent operations**: `curl -s`, `> /dev/null 2>&1`\n\n\u274C **Not testing**: Deploy and hope\n\u2705 **Test manually**: Run with mock env vars first\n\n## Debugging\n\nIf a hook isn't working:\n\n1. **Check if file exists**: `ls -la .dmux-hooks/`\n2. **Check permissions**: Should show `x` in `rwxr-xr-x`\n3. **Check syntax**: `bash -n .dmux-hooks/hook_name`\n4. **Test manually**: Set env vars and run\n5. **Check logs**: dmux logs to stderr with `[Hooks]` prefix\n6. **Simplify**: Remove complex parts, test basic version\n7. **Check tool availability**: `command -v required_tool`\n\n### Debug Mode\n```bash\n#!/bin/bash\n# Add to top of hook for debugging\nset -x # Print each command before executing\nset -e # Exit on error\n\n# Your hook logic here\n```\n\n## Summary Checklist\n\nWhen creating a new hook:\n\n- [ ] Create file in `.dmux-hooks/`\n- [ ] Add shebang: `#!/bin/bash`\n- [ ] Make executable: `chmod +x`\n- [ ] Add `set -e` for error handling\n- [ ] Use environment variables (never hardcode paths)\n- [ ] Background long operations with `&`\n- [ ] Check for required tools before using\n- [ ] Test manually with mock env vars\n- [ ] Add comments explaining what it does\n- [ ] Commit to version control\n\n## Getting Help\n\n- **Full documentation**: See `HOOKS.md` in project root\n- **Claude-specific tips**: See `CLAUDE.md` in `.dmux-hooks/`\n- **Examples**: Check `.dmux-hooks/examples/` directory\n- **dmux API**: See `API.md` for REST endpoints\n\n---\n\n*This documentation was auto-generated from dmux source code.*\n*Version: 2026-03-21*\n";
|
|
5
|
+
export declare const AGENTS_MD = "# dmux Hooks System - Agent Reference\n\n**Auto-generated documentation for AI agents**\n\nThis document contains everything an AI agent needs to create, modify, and understand dmux hooks. It is automatically generated from the dmux source code and embedded in the binary.\n\n## What You're Working On\n\nYou are editing hooks for **dmux**, a tmux pane manager that creates AI-powered development workflows. Each pane runs in its own git worktree with an AI agent.\n\n## Your Goal\n\nCreate executable bash scripts in `.dmux-hooks/` that run automatically at key lifecycle events.\n\n## Quick Start\n\n1. **Create a hook file**: `touch .dmux-hooks/worktree_created`\n2. **Make it executable**: `chmod +x .dmux-hooks/worktree_created`\n3. **Add shebang**: Start with `#!/bin/bash`\n4. **Use environment variables**: Access `$DMUX_ROOT`, `$DMUX_WORKTREE_PATH`, etc.\n5. **Test it**: Set env vars manually and run the script\n\n## Hook Execution Model\n\n- **Non-blocking**: Hooks run in background (detached processes)\n- **Silent failures**: Hook errors are logged but don't stop dmux\n- **Environment-based**: All context passed via environment variables\n- **Version controlled**: Hooks in `.dmux-hooks/` are shared with team\n- **Priority resolution**: `.dmux-hooks/` \u2192 `.dmux/hooks/` \u2192 `~/.dmux/hooks/`\n\n## Available Hooks\n\n### Pane Lifecycle Hooks\n\n| Hook | When | Common Use Cases |\n|------|------|------------------|\n| `before_pane_create` | Before pane creation | Validation, notifications, pre-flight checks |\n| `pane_created` | After pane, before worktree | Configure tmux settings, prepare environment |\n| `worktree_created` | After full setup | Install deps, copy configs, setup git |\n| `before_pane_close` | Before closing | Save state, backup uncommitted work |\n| `pane_closed` | After closed | Cleanup resources, analytics, notifications |\n\n### Worktree Lifecycle Hooks\n\n| Hook | When | Common Use Cases |\n|------|------|------------------|\n| `before_worktree_remove` | Before worktree removal | Archive worktree, save artifacts |\n| `worktree_removed` | After worktree removed | Cleanup external references |\n\n### Merge Lifecycle Hooks\n\n| Hook | When | Common Use Cases |\n|------|------|------------------|\n| `pre_merge` | Before merge operation | Run final tests, create backups |\n| `post_merge` | After successful merge | Deploy, close issues, notify team |\n\n### Interactive Hooks (with HTTP callbacks)\n\n| Hook | When | Common Use Cases |\n|------|------|------------------|\n| `run_test` | When tests triggered | Run test suite, report status via HTTP |\n| `run_dev` | When dev server triggered | Start dev server, create tunnel, report URL |\n\n\n## Environment Variables\n\n### Always Available\n```bash\nDMUX_ROOT=\"/path/to/project\" # Project root directory\nDMUX_SERVER_PORT=\"3142\" # HTTP server port\n```\n\n### Pane Context (most hooks)\n```bash\nDMUX_PANE_ID=\"dmux-1234567890\" # dmux pane identifier\nDMUX_SLUG=\"fix-auth-bug\" # Branch/worktree name\nDMUX_PROMPT=\"Fix authentication bug\" # User's prompt\nDMUX_AGENT=\"claude\" # Agent type (registry id, e.g. claude, codex, opencode)\nDMUX_TMUX_PANE_ID=\"%38\" # tmux pane ID\n```\n\n### Worktree Context\n```bash\nDMUX_WORKTREE_PATH=\"/path/.dmux/worktrees/fix-auth-bug\"\nDMUX_BRANCH=\"fix-auth-bug\" # Same as slug\n```\n\n### Merge Context\n```bash\nDMUX_TARGET_BRANCH=\"main\" # Branch being merged into\n```\n\n## HTTP Callback API\n\nInteractive hooks (`run_test` and `run_dev`) can update dmux UI via HTTP.\n\n### Update Test Status\n```bash\ncurl -X PUT \"http://localhost:$DMUX_SERVER_PORT/api/panes/$DMUX_PANE_ID/test\" -H \"Content-Type: application/json\" -d '{\"status\": \"running\", \"output\": \"optional test output\"}'\n\n# Status values: \"running\" | \"passed\" | \"failed\"\n```\n\n### Update Dev Server\n```bash\ncurl -X PUT \"http://localhost:$DMUX_SERVER_PORT/api/panes/$DMUX_PANE_ID/dev\" -H \"Content-Type: application/json\" -d '{\"status\": \"running\", \"url\": \"http://localhost:3000\"}'\n\n# Status values: \"running\" | \"stopped\"\n# url: Can be localhost or tunnel URL (ngrok, cloudflared, etc.)\n```\n\n## Common Patterns\n\n### Pattern 1: Install Dependencies\n```bash\n#!/bin/bash\n# .dmux-hooks/worktree_created\n\ncd \"$DMUX_WORKTREE_PATH\"\n\nif [ -f \"pnpm-lock.yaml\" ]; then\n pnpm install --prefer-offline &\nelif [ -f \"package-lock.json\" ]; then\n npm install &\nelif [ -f \"yarn.lock\" ]; then\n yarn install &\nelif [ -f \"Gemfile\" ]; then\n bundle install &\nelif [ -f \"requirements.txt\" ]; then\n pip install -r requirements.txt &\nelif [ -f \"Cargo.toml\" ]; then\n cargo build &\nfi\n```\n\n### Pattern 2: Copy Configuration\n```bash\n#!/bin/bash\n# .dmux-hooks/worktree_created\n\n# Copy environment file\nif [ -f \"$DMUX_ROOT/.env.local\" ]; then\n cp \"$DMUX_ROOT/.env.local\" \"$DMUX_WORKTREE_PATH/.env.local\"\nfi\n\n# Copy other config files\nfor file in .env.development .npmrc .yarnrc; do\n if [ -f \"$DMUX_ROOT/$file\" ]; then\n cp \"$DMUX_ROOT/$file\" \"$DMUX_WORKTREE_PATH/$file\"\n fi\ndone\n```\n\n### Pattern 3: Run Tests with Status Updates\n```bash\n#!/bin/bash\n# .dmux-hooks/run_test\n\nset -e\ncd \"$DMUX_WORKTREE_PATH\"\nAPI=\"http://localhost:$DMUX_SERVER_PORT/api/panes/$DMUX_PANE_ID/test\"\n\n# Update: starting\ncurl -s -X PUT \"$API\" -H \"Content-Type: application/json\" -d '{\"status\": \"running\"}' > /dev/null\n\n# Run tests and capture output\nOUTPUT_FILE=\"/tmp/dmux-test-$DMUX_PANE_ID.txt\"\nif pnpm test > \"$OUTPUT_FILE\" 2>&1; then\n STATUS=\"passed\"\nelse\n STATUS=\"failed\"\nfi\n\n# Get output (truncate if too long)\nOUTPUT=$(head -c 5000 \"$OUTPUT_FILE\")\n\n# Update: complete\ncurl -s -X PUT \"$API\" -H \"Content-Type: application/json\" -d \"$(jq -n --arg status \"$STATUS\" --arg output \"$OUTPUT\" '{status: $status, output: $output}')\" > /dev/null\n\nrm -f \"$OUTPUT_FILE\"\n```\n\n### Pattern 4: Dev Server with Tunnel\n```bash\n#!/bin/bash\n# .dmux-hooks/run_dev\n\nset -e\ncd \"$DMUX_WORKTREE_PATH\"\nAPI=\"http://localhost:$DMUX_SERVER_PORT/api/panes/$DMUX_PANE_ID/dev\"\n\n# Start dev server in background\nLOG_FILE=\"/tmp/dmux-dev-$DMUX_PANE_ID.log\"\npnpm dev > \"$LOG_FILE\" 2>&1 &\nDEV_PID=$!\n\n# Wait for server to start\nsleep 5\n\n# Detect port from logs\nPORT=$(grep -oP 'localhost:Kd+' \"$LOG_FILE\" | head -1)\n[ -z \"$PORT\" ] && PORT=3000\n\n# Optional: Create tunnel with cloudflared\nif command -v cloudflared &> /dev/null; then\n TUNNEL=$(cloudflared tunnel --url \"http://localhost:$PORT\" 2>&1 | grep -oP 'https://[a-z0-9-]+.trycloudflare.com' | head -1)\n URL=\"${TUNNEL:-http://localhost:$PORT}\"\nelse\n URL=\"http://localhost:$PORT\"\nfi\n\n# Report status\ncurl -s -X PUT \"$API\" -H \"Content-Type: application/json\" -d \"{\"status\": \"running\", \"url\": \"$URL\"}\" > /dev/null\n\necho \"[Hook] Dev server running at $URL (PID: $DEV_PID)\"\n```\n\n### Pattern 5: Post-Merge Deployment\n```bash\n#!/bin/bash\n# .dmux-hooks/post_merge\n\nset -e\ncd \"$DMUX_ROOT\"\n\n# Only deploy from main/master\nif [ \"$DMUX_TARGET_BRANCH\" != \"main\" ] && [ \"$DMUX_TARGET_BRANCH\" != \"master\" ]; then\n exit 0\nfi\n\n# Push to remote\ngit push origin \"$DMUX_TARGET_BRANCH\"\n\n# Trigger deployment (example: Vercel)\nif [ -n \"$VERCEL_TOKEN\" ]; then\n curl -s -X POST \"https://api.vercel.com/v1/deployments\" -H \"Authorization: Bearer $VERCEL_TOKEN\" -H \"Content-Type: application/json\" -d '{\"name\": \"my-project\"}' > /dev/null\nfi\n\n# Close GitHub issue if prompt contains #123\nISSUE=$(echo \"$DMUX_PROMPT\" | grep -oP '#Kd+' | head -1)\nif [ -n \"$ISSUE\" ] && command -v gh &> /dev/null; then\n gh issue close \"$ISSUE\" -c \"Resolved in $DMUX_SLUG, merged to $DMUX_TARGET_BRANCH\" 2>/dev/null || true\nfi\n```\n\n## Best Practices\n\n1. **Always start with shebang**: `#!/bin/bash`\n2. **Set error handling**: `set -e` (exit on error)\n3. **Make executable**: `chmod +x .dmux-hooks/hook_name`\n4. **Background long operations**: Append `&` to avoid blocking\n5. **Check for required tools**: `command -v tool &> /dev/null`\n6. **Log for debugging**: `echo \"[Hook] message\" >> \"$DMUX_ROOT/.dmux/hooks.log\"`\n7. **Handle missing vars gracefully**: `[ -z \"$VAR\" ] && exit 0`\n8. **Use silent curl**: `curl -s` to avoid noise in logs\n9. **Clean up temp files**: Remove files in `/tmp/`\n10. **Test before committing**: Run hooks manually with mock env vars\n\n## Testing Hooks\n\n### Manual Testing\n```bash\n# 1. Set environment variables\nexport DMUX_ROOT=\"$(pwd)\"\nexport DMUX_PANE_ID=\"test-pane\"\nexport DMUX_SLUG=\"test-branch\"\nexport DMUX_WORKTREE_PATH=\"$(pwd)\"\nexport DMUX_SERVER_PORT=\"3142\"\nexport DMUX_AGENT=\"claude\"\nexport DMUX_PROMPT=\"Test prompt\"\n\n# 2. Run hook directly\n./.dmux-hooks/worktree_created\n\n# 3. Check exit code\necho $? # Should be 0 for success\n```\n\n### Syntax Check\n```bash\n# Check for syntax errors without running\nbash -n ./.dmux-hooks/worktree_created\n```\n\n### Shellcheck (if available)\n```bash\nshellcheck ./.dmux-hooks/worktree_created\n```\n\n## Project Context Analysis\n\nBefore creating hooks, analyze these files in the project:\n\n### Package Manager Detection\n```bash\n# Check which package manager is used\nif [ -f \"pnpm-lock.yaml\" ]; then\n # Use: pnpm install, pnpm test, pnpm dev\nelif [ -f \"package-lock.json\" ]; then\n # Use: npm install, npm test, npm run dev\nelif [ -f \"yarn.lock\" ]; then\n # Use: yarn install, yarn test, yarn dev\nfi\n```\n\n### Test Command Discovery\n```bash\n# Read package.json to find test command\ncat package.json | grep '\"test\"'\n# Or with jq:\njq -r '.scripts.test' package.json\n```\n\n### Dev Command Discovery\n```bash\n# Read package.json to find dev command\ncat package.json | grep '\"dev\"'\n# Or with jq:\njq -r '.scripts.dev' package.json\n```\n\n### Environment Variables\n```bash\n# Check for .env files to copy\nls -la | grep '.env'\n```\n\n### Build System\n```bash\n# Detect build system\nif [ -f \"vite.config.ts\" ]; then\n # Vite project\nelif [ -f \"next.config.js\" ]; then\n # Next.js project\nelif [ -f \"nuxt.config.ts\" ]; then\n # Nuxt project\nfi\n```\n\n## Common Mistakes to Avoid\n\n\u274C **Blocking operations**: `sleep 60` (blocks dmux)\n\u2705 **Background long tasks**: `slow_operation &`\n\n\u274C **Hardcoded paths**: `/Users/me/project`\n\u2705 **Use variables**: `\"$DMUX_ROOT\"`\n\n\u274C **Assuming tools exist**: `pnpm install`\n\u2705 **Check first**: `command -v pnpm && pnpm install`\n\n\u274C **No error handling**: Script fails silently\n\u2705 **Set error mode**: `set -e` or check exit codes\n\n\u274C **Forgetting executable bit**: Hook won't run\n\u2705 **Make executable**: `chmod +x`\n\n\u274C **Noisy output**: Clutters dmux logs\n\u2705 **Silent operations**: `curl -s`, `> /dev/null 2>&1`\n\n\u274C **Not testing**: Deploy and hope\n\u2705 **Test manually**: Run with mock env vars first\n\n## Debugging\n\nIf a hook isn't working:\n\n1. **Check if file exists**: `ls -la .dmux-hooks/`\n2. **Check permissions**: Should show `x` in `rwxr-xr-x`\n3. **Check syntax**: `bash -n .dmux-hooks/hook_name`\n4. **Test manually**: Set env vars and run\n5. **Check logs**: dmux logs to stderr with `[Hooks]` prefix\n6. **Simplify**: Remove complex parts, test basic version\n7. **Check tool availability**: `command -v required_tool`\n\n### Debug Mode\n```bash\n#!/bin/bash\n# Add to top of hook for debugging\nset -x # Print each command before executing\nset -e # Exit on error\n\n# Your hook logic here\n```\n\n## Summary Checklist\n\nWhen creating a new hook:\n\n- [ ] Create file in `.dmux-hooks/`\n- [ ] Add shebang: `#!/bin/bash`\n- [ ] Make executable: `chmod +x`\n- [ ] Add `set -e` for error handling\n- [ ] Use environment variables (never hardcode paths)\n- [ ] Background long operations with `&`\n- [ ] Check for required tools before using\n- [ ] Test manually with mock env vars\n- [ ] Add comments explaining what it does\n- [ ] Commit to version control\n\n## Getting Help\n\n- **Full documentation**: See `HOOKS.md` in project root\n- **Claude-specific tips**: See `CLAUDE.md` in `.dmux-hooks/`\n- **Examples**: Check `.dmux-hooks/examples/` directory\n- **dmux API**: See `API.md` for REST endpoints\n\n---\n\n*This documentation was auto-generated from dmux source code.*\n*Version: 2026-04-17*\n";
|
|
6
6
|
//# sourceMappingURL=generated-agents-doc.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface GitHubPullRequestResult {
|
|
2
|
+
url: string;
|
|
3
|
+
created: boolean;
|
|
4
|
+
remoteName: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function getGitHubCliInstallCommand(platform?: NodeJS.Platform, hasCommand?: (command: string) => boolean): string | null;
|
|
7
|
+
export declare function buildMissingGitHubCliMessage(platform?: NodeJS.Platform, hasCommand?: (command: string) => boolean): string;
|
|
8
|
+
export declare function getPreferredPushRemote(repoPath: string): string;
|
|
9
|
+
export declare function findExistingPullRequestUrl(repoPath: string, sourceBranch: string): string | null;
|
|
10
|
+
export declare function createGitHubPullRequest(options: {
|
|
11
|
+
repoPath: string;
|
|
12
|
+
sourceBranch: string;
|
|
13
|
+
targetBranch: string;
|
|
14
|
+
remoteName?: string;
|
|
15
|
+
title?: string;
|
|
16
|
+
body?: string;
|
|
17
|
+
}): GitHubPullRequestResult;
|
|
18
|
+
//# sourceMappingURL=githubPullRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"githubPullRequest.d.ts","sourceRoot":"","sources":["../../src/utils/githubPullRequest.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,uBAAuB;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB;AAqBD,wBAAgB,0BAA0B,CACxC,QAAQ,GAAE,MAAM,CAAC,QAA2B,EAC5C,UAAU,GAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAuB,GACvD,MAAM,GAAG,IAAI,CA4Cf;AAED,wBAAgB,4BAA4B,CAC1C,QAAQ,GAAE,MAAM,CAAC,QAA2B,EAC5C,UAAU,GAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAuB,GACvD,MAAM,CAQR;AAkED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAiC/D;AAED,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,GACnB,MAAM,GAAG,IAAI,CASf;AAgBD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,uBAAuB,CAmE1B"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { spawnSync } from 'child_process';
|
|
2
|
+
function commandExists(command) {
|
|
3
|
+
const result = process.platform === 'win32'
|
|
4
|
+
? spawnSync('where', [command], {
|
|
5
|
+
encoding: 'utf-8',
|
|
6
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
7
|
+
})
|
|
8
|
+
: spawnSync('sh', ['-lc', `command -v "${command}" >/dev/null 2>&1`], {
|
|
9
|
+
encoding: 'utf-8',
|
|
10
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
11
|
+
});
|
|
12
|
+
return !result.error && result.status === 0;
|
|
13
|
+
}
|
|
14
|
+
export function getGitHubCliInstallCommand(platform = process.platform, hasCommand = commandExists) {
|
|
15
|
+
if (platform === 'darwin') {
|
|
16
|
+
if (hasCommand('brew'))
|
|
17
|
+
return 'brew install gh';
|
|
18
|
+
if (hasCommand('port'))
|
|
19
|
+
return 'sudo port install gh';
|
|
20
|
+
if (hasCommand('conda'))
|
|
21
|
+
return 'conda install gh --channel conda-forge';
|
|
22
|
+
return 'brew install gh';
|
|
23
|
+
}
|
|
24
|
+
if (platform === 'win32') {
|
|
25
|
+
if (hasCommand('winget'))
|
|
26
|
+
return 'winget install --id GitHub.cli';
|
|
27
|
+
if (hasCommand('scoop'))
|
|
28
|
+
return 'scoop install gh';
|
|
29
|
+
if (hasCommand('choco'))
|
|
30
|
+
return 'choco install gh';
|
|
31
|
+
if (hasCommand('conda'))
|
|
32
|
+
return 'conda install gh --channel conda-forge';
|
|
33
|
+
return 'winget install --id GitHub.cli';
|
|
34
|
+
}
|
|
35
|
+
if (hasCommand('brew'))
|
|
36
|
+
return 'brew install gh';
|
|
37
|
+
if (hasCommand('apt-get') || hasCommand('apt')) {
|
|
38
|
+
return '(type -p wget >/dev/null || (sudo apt update && sudo apt install wget -y)) && sudo mkdir -p -m 755 /etc/apt/keyrings && out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg && cat $out | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null && sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg && sudo mkdir -p -m 755 /etc/apt/sources.list.d && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null && sudo apt update && sudo apt install gh -y';
|
|
39
|
+
}
|
|
40
|
+
if (hasCommand('dnf5')) {
|
|
41
|
+
return 'sudo dnf install dnf5-plugins && sudo dnf config-manager addrepo --from-repofile=https://cli.github.com/packages/rpm/gh-cli.repo && sudo dnf install gh --repo gh-cli';
|
|
42
|
+
}
|
|
43
|
+
if (hasCommand('dnf')) {
|
|
44
|
+
return "sudo dnf install 'dnf-command(config-manager)' && sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo && sudo dnf install gh --repo gh-cli";
|
|
45
|
+
}
|
|
46
|
+
if (hasCommand('yum')) {
|
|
47
|
+
return 'type -p yum-config-manager >/dev/null || sudo yum install yum-utils && sudo yum-config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo && sudo yum install gh';
|
|
48
|
+
}
|
|
49
|
+
if (hasCommand('zypper')) {
|
|
50
|
+
return 'sudo zypper addrepo https://cli.github.com/packages/rpm/gh-cli.repo && sudo zypper ref && sudo zypper install gh';
|
|
51
|
+
}
|
|
52
|
+
if (hasCommand('pacman'))
|
|
53
|
+
return 'sudo pacman -S github-cli';
|
|
54
|
+
if (hasCommand('apk'))
|
|
55
|
+
return 'apk add github-cli';
|
|
56
|
+
if (hasCommand('pkg'))
|
|
57
|
+
return 'pkg install gh';
|
|
58
|
+
if (hasCommand('conda'))
|
|
59
|
+
return 'conda install gh --channel conda-forge';
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
export function buildMissingGitHubCliMessage(platform = process.platform, hasCommand = commandExists) {
|
|
63
|
+
const installCommand = getGitHubCliInstallCommand(platform, hasCommand);
|
|
64
|
+
if (!installCommand) {
|
|
65
|
+
return 'GitHub CLI (gh) is required to create pull requests from dmux. Install it from https://github.com/cli/cli#installation and then try again.';
|
|
66
|
+
}
|
|
67
|
+
return `GitHub CLI (gh) is required to create pull requests from dmux. Install it first with:\n${installCommand}`;
|
|
68
|
+
}
|
|
69
|
+
function runCommandText(command, args, options) {
|
|
70
|
+
const result = spawnSync(command, args, {
|
|
71
|
+
cwd: options.cwd,
|
|
72
|
+
encoding: 'utf-8',
|
|
73
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
74
|
+
});
|
|
75
|
+
if (result.error) {
|
|
76
|
+
if (options.allowFailure) {
|
|
77
|
+
return '';
|
|
78
|
+
}
|
|
79
|
+
throw result.error;
|
|
80
|
+
}
|
|
81
|
+
if (result.status !== 0) {
|
|
82
|
+
if (options.allowFailure) {
|
|
83
|
+
return '';
|
|
84
|
+
}
|
|
85
|
+
const stderr = result.stderr?.trim();
|
|
86
|
+
const stdout = result.stdout?.trim();
|
|
87
|
+
throw new Error(stderr || stdout || `${command} exited with status ${result.status}`);
|
|
88
|
+
}
|
|
89
|
+
return result.stdout.trim();
|
|
90
|
+
}
|
|
91
|
+
function runGit(repoPath, args, options = {}) {
|
|
92
|
+
return runCommandText('git', args, { cwd: repoPath, ...options });
|
|
93
|
+
}
|
|
94
|
+
function runGh(repoPath, args, options = {}) {
|
|
95
|
+
return runCommandText('gh', args, { cwd: repoPath, ...options });
|
|
96
|
+
}
|
|
97
|
+
function ensureGitHubCliAvailable(repoPath) {
|
|
98
|
+
try {
|
|
99
|
+
runGh(repoPath, ['--version']);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
throw new Error(buildMissingGitHubCliMessage());
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function listGitRemotes(repoPath) {
|
|
106
|
+
const output = runGit(repoPath, ['remote'], { allowFailure: true });
|
|
107
|
+
return output
|
|
108
|
+
.split('\n')
|
|
109
|
+
.map((line) => line.trim())
|
|
110
|
+
.filter(Boolean);
|
|
111
|
+
}
|
|
112
|
+
export function getPreferredPushRemote(repoPath) {
|
|
113
|
+
const upstream = runGit(repoPath, ['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{upstream}'], { allowFailure: true });
|
|
114
|
+
if (upstream.includes('/')) {
|
|
115
|
+
return upstream.split('/')[0];
|
|
116
|
+
}
|
|
117
|
+
const currentBranch = runGit(repoPath, ['branch', '--show-current'], {
|
|
118
|
+
allowFailure: true,
|
|
119
|
+
});
|
|
120
|
+
if (currentBranch && currentBranch !== 'HEAD') {
|
|
121
|
+
const configuredRemote = runGit(repoPath, ['config', `branch.${currentBranch}.remote`], { allowFailure: true });
|
|
122
|
+
if (configuredRemote) {
|
|
123
|
+
return configuredRemote;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const remotes = listGitRemotes(repoPath);
|
|
127
|
+
if (remotes.length === 0) {
|
|
128
|
+
throw new Error('No git remote is configured for this repository.');
|
|
129
|
+
}
|
|
130
|
+
return remotes.includes('origin') ? 'origin' : remotes[0];
|
|
131
|
+
}
|
|
132
|
+
export function findExistingPullRequestUrl(repoPath, sourceBranch) {
|
|
133
|
+
const output = runGh(repoPath, ['pr', 'view', sourceBranch, '--json', 'url', '--jq', '.url'], { allowFailure: true });
|
|
134
|
+
const url = output.trim();
|
|
135
|
+
return url || null;
|
|
136
|
+
}
|
|
137
|
+
function ensureRemoteBranchExists(repoPath, remoteName, branchName) {
|
|
138
|
+
const output = runGit(repoPath, ['ls-remote', '--heads', remoteName, branchName]);
|
|
139
|
+
if (!output.trim()) {
|
|
140
|
+
throw new Error(`Remote branch ${remoteName}/${branchName} was not found. Push or create a PR for the parent branch first.`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
export function createGitHubPullRequest(options) {
|
|
144
|
+
const { repoPath, sourceBranch, targetBranch, remoteName = getPreferredPushRemote(repoPath), title, body, } = options;
|
|
145
|
+
ensureGitHubCliAvailable(repoPath);
|
|
146
|
+
const existingUrl = findExistingPullRequestUrl(repoPath, sourceBranch);
|
|
147
|
+
if (existingUrl) {
|
|
148
|
+
return {
|
|
149
|
+
url: existingUrl,
|
|
150
|
+
created: false,
|
|
151
|
+
remoteName,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
ensureRemoteBranchExists(repoPath, remoteName, targetBranch);
|
|
155
|
+
runGit(repoPath, ['push', '--set-upstream', remoteName, sourceBranch]);
|
|
156
|
+
const hasExplicitTitle = typeof title === 'string' && title.trim().length > 0;
|
|
157
|
+
const createArgs = [
|
|
158
|
+
'pr',
|
|
159
|
+
'create',
|
|
160
|
+
'--base',
|
|
161
|
+
targetBranch,
|
|
162
|
+
'--head',
|
|
163
|
+
sourceBranch,
|
|
164
|
+
];
|
|
165
|
+
if (hasExplicitTitle) {
|
|
166
|
+
createArgs.push('--title', title.trim());
|
|
167
|
+
createArgs.push('--body', (body ?? '').trim());
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
createArgs.push('--fill');
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
runGh(repoPath, createArgs);
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
const existingAfterCreate = findExistingPullRequestUrl(repoPath, sourceBranch);
|
|
177
|
+
if (existingAfterCreate) {
|
|
178
|
+
return {
|
|
179
|
+
url: existingAfterCreate,
|
|
180
|
+
created: false,
|
|
181
|
+
remoteName,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
186
|
+
const createdUrl = findExistingPullRequestUrl(repoPath, sourceBranch);
|
|
187
|
+
if (!createdUrl) {
|
|
188
|
+
throw new Error('Pull request was created but the resulting URL could not be determined.');
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
url: createdUrl,
|
|
192
|
+
created: true,
|
|
193
|
+
remoteName,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=githubPullRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"githubPullRequest.js","sourceRoot":"","sources":["../../src/utils/githubPullRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAa1C,SAAS,aAAa,CAAC,OAAe;IACpC,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO;QACzC,CAAC,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE;YAC5B,QAAQ,EAAE,OAAO;YACjB,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;SAClC,CAAC;QACJ,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,eAAe,OAAO,mBAAmB,CAAC,EAAE;YAClE,QAAQ,EAAE,OAAO;YACjB,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;SAClC,CAAC,CAAC;IAEP,OAAO,CAAC,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,WAA4B,OAAO,CAAC,QAAQ,EAC5C,aAA2C,aAAa;IAExD,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC1B,IAAI,UAAU,CAAC,MAAM,CAAC;YAAE,OAAO,iBAAiB,CAAC;QACjD,IA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C,QAAQ,CAAC,CAAC;IAC5B,CAAC;IAED,IAAI,CAAC;QACH,KAAK,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAC9B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,mBAAmB,GAAG,0BAA0B,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAC/E,IAAI,mBAAmB,EAAE,CAAC;YACxB,OAAO;gBACL,GAAG,EAAE,mBAAmB;gBACxB,OAAO,EAAE,KAAK;gBACd,UAAU;aACX,CAAC;QACJ,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;IAED,MAAM,UAAU,GAAG,0BAA0B,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IACtE,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC;IAC7F,CAAC;IAED,OAAO;QACL,GAAG,EAAE,UAAU;QACf,OAAO,EAAE,IAAI;QACb,UAAU;KACX,CAAC;AACJ,CAAC"}
|
package/dist/utils/input.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
export declare const findCharIndexAtWidth: (str: string, targetWidth: number) => number;
|
|
1
2
|
export declare const preprocessPastedContent: (input: string) => string;
|
|
2
|
-
export
|
|
3
|
+
export interface WrappedLine {
|
|
3
4
|
line: string;
|
|
4
5
|
isHardBreak: boolean;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
/** Number of characters consumed at the break that don't belong to either line (0 or 1). */
|
|
7
|
+
gapSize: number;
|
|
8
|
+
}
|
|
9
|
+
export declare const wrapText: (text: string, width: number) => WrappedLine[];
|
|
10
|
+
export declare const findCursorInWrappedLines: (wrappedLines: WrappedLine[], absoluteCursor: number) => {
|
|
10
11
|
line: number;
|
|
11
12
|
col: number;
|
|
12
13
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/utils/input.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/utils/input.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,oBAAoB,GAAI,KAAK,MAAM,EAAE,aAAa,MAAM,KAAG,MAUvE,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,OAAO,MAAM,KAAG,MA+BvD,CAAC;AAEF,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,OAAO,CAAC;IACrB,4FAA4F;IAC5F,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,EAAE,OAAO,MAAM,KAAG,WAAW,EAsCjE,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,cAAc,WAAW,EAAE,EAC3B,gBAAgB,MAAM;;;CAsBvB,CAAC"}
|
package/dist/utils/input.js
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
import stringWidth from 'string-width';
|
|
2
|
+
const graphemeSegmenter = typeof Intl !== 'undefined' && 'Segmenter' in Intl
|
|
3
|
+
? new Intl.Segmenter(undefined, { granularity: 'grapheme' })
|
|
4
|
+
: null;
|
|
5
|
+
const getGraphemes = (str) => (graphemeSegmenter
|
|
6
|
+
? Array.from(graphemeSegmenter.segment(str), ({ segment }) => segment)
|
|
7
|
+
: Array.from(str));
|
|
8
|
+
// Find the UTF-16 string index where cumulative display width would exceed targetWidth.
|
|
9
|
+
// Returns the string index for the last whole grapheme that fits within targetWidth columns.
|
|
10
|
+
export const findCharIndexAtWidth = (str, targetWidth) => {
|
|
11
|
+
let width = 0;
|
|
12
|
+
let stringIndex = 0;
|
|
13
|
+
for (const grapheme of getGraphemes(str)) {
|
|
14
|
+
const cw = stringWidth(grapheme);
|
|
15
|
+
if (width + cw > targetWidth)
|
|
16
|
+
return stringIndex;
|
|
17
|
+
width += cw;
|
|
18
|
+
stringIndex += grapheme.length;
|
|
19
|
+
}
|
|
20
|
+
return str.length;
|
|
21
|
+
};
|
|
1
22
|
export const preprocessPastedContent = (input) => {
|
|
2
23
|
let cleaned = input.replace(/\x1b\[[0-9;]*m/g, '');
|
|
3
24
|
cleaned = cleaned.replace(/\x1b\[[\d;]*[A-Za-z]/g, '');
|
|
@@ -32,37 +53,42 @@ export const preprocessPastedContent = (input) => {
|
|
|
32
53
|
};
|
|
33
54
|
export const wrapText = (text, width) => {
|
|
34
55
|
if (!text)
|
|
35
|
-
return [{ line: '', isHardBreak: false }];
|
|
56
|
+
return [{ line: '', isHardBreak: false, gapSize: 0 }];
|
|
36
57
|
const hardLines = text.split('\n');
|
|
37
58
|
const wrappedLines = [];
|
|
38
59
|
for (let i = 0; i < hardLines.length; i++) {
|
|
39
60
|
const hardLine = hardLines[i];
|
|
40
61
|
const isLastHardLine = i === hardLines.length - 1;
|
|
41
|
-
if (hardLine
|
|
42
|
-
wrappedLines.push({ line: hardLine, isHardBreak: !isLastHardLine });
|
|
62
|
+
if (stringWidth(hardLine) <= width) {
|
|
63
|
+
wrappedLines.push({ line: hardLine, isHardBreak: !isLastHardLine, gapSize: !isLastHardLine ? 1 : 0 });
|
|
43
64
|
}
|
|
44
65
|
else {
|
|
45
66
|
let remaining = hardLine;
|
|
46
67
|
while (remaining.length > 0) {
|
|
47
|
-
if (remaining
|
|
48
|
-
wrappedLines.push({ line: remaining, isHardBreak: !isLastHardLine });
|
|
68
|
+
if (stringWidth(remaining) <= width) {
|
|
69
|
+
wrappedLines.push({ line: remaining, isHardBreak: !isLastHardLine, gapSize: !isLastHardLine ? 1 : 0 });
|
|
49
70
|
break;
|
|
50
71
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
72
|
+
// Find how many characters fit within the display width
|
|
73
|
+
const maxCharIdx = findCharIndexAtWidth(remaining, width);
|
|
74
|
+
// Try to break at a space within the fitting range
|
|
75
|
+
let breakPoint = maxCharIdx;
|
|
76
|
+
const lastSpace = remaining.lastIndexOf(' ', maxCharIdx - 1);
|
|
77
|
+
if (lastSpace > 0) {
|
|
54
78
|
breakPoint = lastSpace;
|
|
79
|
+
}
|
|
55
80
|
else {
|
|
56
81
|
const firstSpace = remaining.indexOf(' ');
|
|
57
|
-
if (firstSpace > 0 && firstSpace <
|
|
82
|
+
if (firstSpace > 0 && firstSpace < maxCharIdx)
|
|
58
83
|
breakPoint = firstSpace;
|
|
59
84
|
else
|
|
60
|
-
breakPoint = Math.
|
|
85
|
+
breakPoint = Math.max(1, maxCharIdx); // ensure at least 1 char progress
|
|
61
86
|
}
|
|
62
87
|
const segment = remaining.slice(0, breakPoint);
|
|
63
|
-
wrappedLines.push({ line: segment.trimEnd(), isHardBreak: false });
|
|
64
88
|
const nextChar = remaining[breakPoint];
|
|
65
|
-
|
|
89
|
+
const spaceBreak = nextChar === ' ';
|
|
90
|
+
wrappedLines.push({ line: segment.trimEnd(), isHardBreak: false, gapSize: spaceBreak ? 1 : 0 });
|
|
91
|
+
if (spaceBreak)
|
|
66
92
|
remaining = remaining.slice(breakPoint + 1);
|
|
67
93
|
else
|
|
68
94
|
remaining = remaining.slice(breakPoint);
|
|
@@ -78,21 +104,18 @@ export const findCursorInWrappedLines = (wrappedLines, absoluteCursor) => {
|
|
|
78
104
|
for (let lineIndex = 0; lineIndex < wrappedLines.length; lineIndex++) {
|
|
79
105
|
const wrappedLine = wrappedLines[lineIndex];
|
|
80
106
|
const lineLength = wrappedLine.line.length;
|
|
81
|
-
|
|
107
|
+
const isLastLine = lineIndex === wrappedLines.length - 1;
|
|
108
|
+
// For forced breaks (gapSize=0, not last line), cursor at the boundary
|
|
109
|
+
// belongs to the NEXT line since no gap character was consumed.
|
|
110
|
+
// For gap breaks (gapSize>0) or last line, cursor at boundary stays here.
|
|
111
|
+
const endInclusive = wrappedLine.gapSize > 0 || isLastLine;
|
|
112
|
+
if (endInclusive
|
|
113
|
+
? absoluteCursor <= currentPos + lineLength
|
|
114
|
+
: absoluteCursor < currentPos + lineLength) {
|
|
82
115
|
const colInLine = absoluteCursor - currentPos;
|
|
83
116
|
return { line: lineIndex, col: Math.max(0, Math.min(colInLine, lineLength)) };
|
|
84
117
|
}
|
|
85
|
-
currentPos += lineLength;
|
|
86
|
-
if (wrappedLine.isHardBreak) {
|
|
87
|
-
currentPos++;
|
|
88
|
-
if (absoluteCursor === currentPos - 1)
|
|
89
|
-
return { line: lineIndex, col: lineLength };
|
|
90
|
-
}
|
|
91
|
-
else if (lineIndex < wrappedLines.length - 1) {
|
|
92
|
-
currentPos++;
|
|
93
|
-
if (absoluteCursor === currentPos - 1)
|
|
94
|
-
return { line: lineIndex, col: lineLength };
|
|
95
|
-
}
|
|
118
|
+
currentPos += lineLength + wrappedLine.gapSize;
|
|
96
119
|
}
|
|
97
120
|
const lastLine = wrappedLines[wrappedLines.length - 1];
|
|
98
121
|
return { line: wrappedLines.length - 1, col: lastLine ? lastLine.line.length : 0 };
|
package/dist/utils/input.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../src/utils/input.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAAa,EAAU,EAAE;IAC/D,IAAI,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;IACnD,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;IACvD,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAE9D,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,C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3C,MAAM,UAAU,GAAG,SAAS,KAAK,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC;QACzD,uEAAuE;QACvE,gEAAgE;QAChE,0EAA0E;QAC1E,MAAM,YAAY,GAAG,WAAW,CAAC,OAAO,GAAG,CAAC,IAAI,UAAU,CAAC;QAC3D,IAAI,YAAY;YACd,CAAC,CAAC,cAAc,IAAI,UAAU,GAAG,UAAU;YAC3C,CAAC,CAAC,cAAc,GAAG,UAAU,GAAG,UAAU,EAAE,CAAC;YAC7C,MAAM,SAAS,GAAG,cAAc,GAAG,UAAU,CAAC;YAC9C,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC;QAChF,CAAC;QACD,UAAU,IAAI,UAAU,GAAG,WAAW,CAAC,OAAO,CAAC;IACjD,CAAC;IACD,MAAM,QAAQ,GAAG,YAAY,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvD,OAAO,EAAE,IAAI,EAAE,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACrF,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DmuxPane, DmuxThemeName, SidebarProject } from '../types.js';
|
|
2
|
+
type ProjectThemeCache = Map<string, DmuxThemeName>;
|
|
3
|
+
export declare function resolveProjectColorTheme(projectRoot: string, sidebarProjects: SidebarProject[], cache?: ProjectThemeCache): DmuxThemeName;
|
|
4
|
+
export declare function getPaneColorTheme(pane: DmuxPane, sidebarProjects: SidebarProject[], fallbackProjectRoot: string, cache?: ProjectThemeCache): DmuxThemeName;
|
|
5
|
+
export declare function syncPaneColorThemes(panes: DmuxPane[], sidebarProjects: SidebarProject[], fallbackProjectRoot: string): DmuxPane[];
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=paneColors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paneColors.d.ts","sourceRoot":"","sources":["../../src/utils/paneColors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAM3E,KAAK,iBAAiB,GAAG,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAMpD,wBAAgB,wBAAwB,CACtC,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,cAAc,EAAE,EACjC,KAAK,GAAE,iBAA6B,GACnC,aAAa,CAYf;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,QAAQ,EACd,eAAe,EAAE,cAAc,EAAE,EACjC,mBAAmB,EAAE,MAAM,EAC3B,KAAK,GAAE,iBAA6B,GACnC,aAAa,CAUf;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,QAAQ,EAAE,EACjB,eAAe,EAAE,cAAc,EAAE,EACjC,mBAAmB,EAAE,MAAM,GAC1B,QAAQ,EAAE,CAuBZ"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { isDmuxThemeName, normalizeDmuxTheme } from '../theme/themePalette.js';
|
|
3
|
+
import { getPaneProjectRoot } from './paneProject.js';
|
|
4
|
+
import { getSidebarProjectColorTheme } from './sidebarProjects.js';
|
|
5
|
+
import { SettingsManager } from './settingsManager.js';
|
|
6
|
+
function getCacheKey(projectRoot) {
|
|
7
|
+
return path.resolve(projectRoot);
|
|
8
|
+
}
|
|
9
|
+
export function resolveProjectColorTheme(projectRoot, sidebarProjects, cache = new Map()) {
|
|
10
|
+
const cacheKey = getCacheKey(projectRoot);
|
|
11
|
+
const cachedTheme = cache.get(cacheKey);
|
|
12
|
+
if (cachedTheme) {
|
|
13
|
+
return cachedTheme;
|
|
14
|
+
}
|
|
15
|
+
const resolvedTheme = getSidebarProjectColorTheme(sidebarProjects, projectRoot)
|
|
16
|
+
|| normalizeDmuxTheme(new SettingsManager(projectRoot).getSettings().colorTheme);
|
|
17
|
+
cache.set(cacheKey, resolvedTheme);
|
|
18
|
+
return resolvedTheme;
|
|
19
|
+
}
|
|
20
|
+
export function getPaneColorTheme(pane, sidebarProjects, fallbackProjectRoot, cache = new Map()) {
|
|
21
|
+
if (isDmuxThemeName(pane.colorTheme)) {
|
|
22
|
+
return pane.colorTheme;
|
|
23
|
+
}
|
|
24
|
+
return resolveProjectColorTheme(getPaneProjectRoot(pane, fallbackProjectRoot), sidebarProjects, cache);
|
|
25
|
+
}
|
|
26
|
+
export function syncPaneColorThemes(panes, sidebarProjects, fallbackProjectRoot) {
|
|
27
|
+
const projectThemeCache = new Map();
|
|
28
|
+
let changed = false;
|
|
29
|
+
const updatedPanes = panes.map((pane) => {
|
|
30
|
+
const colorTheme = resolveProjectColorTheme(getPaneProjectRoot(pane, fallbackProjectRoot), sidebarProjects, projectThemeCache);
|
|
31
|
+
if (pane.colorTheme === colorTheme) {
|
|
32
|
+
return pane;
|
|
33
|
+
}
|
|
34
|
+
changed = true;
|
|
35
|
+
return {
|
|
36
|
+
...pane,
|
|
37
|
+
colorTheme,
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
return changed ? updatedPanes : panes;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=paneColors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paneColors.js","sourceRoot":"","sources":["../../src/utils/paneColors.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,2BAA2B,EAAE,MAAM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AAE,EAAE;QACtC,MAAM,UAAU,GAAG,wBAAwB,CACzC,kBAAkB,CAAC,IAAI,EAAE,mBAAmB,CAAC,EAC7C,eAAe,EACf,iBAAiB,CAClB,CAAC;QAEF,IAAI,IAAI,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;YACnC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,GAAG,IAAI,CAAC;QACf,OAAO;YACL,GAAG,IAAI;YACP,UAAU;SACX,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC;AACxC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paneCreation.d.ts","sourceRoot":"","sources":["../../src/utils/paneCreation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAc,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAe9E,OAAO,EAUL,KAAK,SAAS,EACf,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"paneCreation.d.ts","sourceRoot":"","sources":["../../src/utils/paneCreation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAc,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAe9E,OAAO,EAUL,KAAK,SAAS,EACf,MAAM,kBAAkB,CAAC;AAiB1B,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE,oBAAoB,EAAE,CA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