@damper/cli 0.2.0 → 0.2.2
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/dist/index.js +1 -1
- package/dist/services/claude.js +3 -3
- package/dist/services/worktree.js +64 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { startCommand } from './commands/start.js';
|
|
|
4
4
|
import { statusCommand } from './commands/status.js';
|
|
5
5
|
import { cleanupCommand } from './commands/cleanup.js';
|
|
6
6
|
import { setupCommand } from './commands/setup.js';
|
|
7
|
-
const VERSION = '0.2.
|
|
7
|
+
const VERSION = '0.2.2';
|
|
8
8
|
function showHelp() {
|
|
9
9
|
console.log(`
|
|
10
10
|
${pc.bold('@damper/cli')} - Agent orchestration for Damper tasks
|
package/dist/services/claude.js
CHANGED
|
@@ -97,11 +97,11 @@ export async function launchClaude(options) {
|
|
|
97
97
|
'2. Use `add_note` for important decisions',
|
|
98
98
|
'3. Call `complete_task` when done or `abandon_task` if stopping early',
|
|
99
99
|
].join('\n');
|
|
100
|
-
// Launch Claude Code
|
|
101
|
-
//
|
|
100
|
+
// Launch Claude Code in interactive mode
|
|
101
|
+
// Pass the prompt as an argument (not --print which is non-interactive)
|
|
102
102
|
// Pass API key so MCP server gets it
|
|
103
103
|
try {
|
|
104
|
-
await execa('claude', [
|
|
104
|
+
await execa('claude', [initialPrompt], {
|
|
105
105
|
cwd,
|
|
106
106
|
stdio: 'inherit',
|
|
107
107
|
env: {
|
|
@@ -126,6 +126,21 @@ function findEnvFiles(projectRoot) {
|
|
|
126
126
|
}
|
|
127
127
|
return envFiles;
|
|
128
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Check if a git branch exists
|
|
131
|
+
*/
|
|
132
|
+
async function branchExists(branchName, projectRoot) {
|
|
133
|
+
try {
|
|
134
|
+
await execa('git', ['rev-parse', '--verify', branchName], {
|
|
135
|
+
cwd: projectRoot,
|
|
136
|
+
stdio: 'pipe',
|
|
137
|
+
});
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
129
144
|
/**
|
|
130
145
|
* Create a new git worktree for a task
|
|
131
146
|
*/
|
|
@@ -144,12 +159,57 @@ export async function createWorktree(options) {
|
|
|
144
159
|
const slug = slugify(taskTitle);
|
|
145
160
|
const worktreePath = path.resolve(projectRoot, '..', `${projectName}-${slug}`);
|
|
146
161
|
const branchName = `feature/${slug}`;
|
|
162
|
+
// Check if worktree directory already exists
|
|
163
|
+
if (fs.existsSync(worktreePath)) {
|
|
164
|
+
console.log(pc.dim(`Worktree directory already exists at ${worktreePath}`));
|
|
165
|
+
// Check if it's a valid worktree and has the expected branch
|
|
166
|
+
try {
|
|
167
|
+
const { stdout } = await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {
|
|
168
|
+
cwd: worktreePath,
|
|
169
|
+
stdio: 'pipe',
|
|
170
|
+
});
|
|
171
|
+
const currentBranch = stdout.trim();
|
|
172
|
+
console.log(pc.dim(`Using existing worktree on branch ${currentBranch}`));
|
|
173
|
+
// Save to state if not tracked
|
|
174
|
+
const worktreeState = {
|
|
175
|
+
taskId,
|
|
176
|
+
path: worktreePath,
|
|
177
|
+
branch: currentBranch,
|
|
178
|
+
projectRoot,
|
|
179
|
+
createdAt: new Date().toISOString(),
|
|
180
|
+
};
|
|
181
|
+
addWorktree(worktreeState);
|
|
182
|
+
return {
|
|
183
|
+
path: worktreePath,
|
|
184
|
+
branch: currentBranch,
|
|
185
|
+
isNew: false,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
// Not a valid git worktree, remove it
|
|
190
|
+
console.log(pc.dim(`Removing invalid directory at ${worktreePath}...`));
|
|
191
|
+
fs.rmSync(worktreePath, { recursive: true });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Check if branch already exists
|
|
195
|
+
const branchAlreadyExists = await branchExists(branchName, projectRoot);
|
|
147
196
|
// Create worktree
|
|
148
197
|
console.log(pc.dim(`Creating worktree at ${worktreePath}...`));
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
198
|
+
if (branchAlreadyExists) {
|
|
199
|
+
// Use existing branch
|
|
200
|
+
console.log(pc.dim(`Using existing branch ${branchName}`));
|
|
201
|
+
await execa('git', ['worktree', 'add', worktreePath, branchName], {
|
|
202
|
+
cwd: projectRoot,
|
|
203
|
+
stdio: 'pipe',
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
// Create new branch
|
|
208
|
+
await execa('git', ['worktree', 'add', worktreePath, '-b', branchName], {
|
|
209
|
+
cwd: projectRoot,
|
|
210
|
+
stdio: 'pipe',
|
|
211
|
+
});
|
|
212
|
+
}
|
|
153
213
|
// Symlink node_modules
|
|
154
214
|
const nodeModulesDirs = findNodeModulesDirs(projectRoot);
|
|
155
215
|
for (const dir of nodeModulesDirs) {
|