@ebowwa/glm-daemon 0.1.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.md +264 -0
- package/dist/agent.d.ts +37 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +97 -0
- package/dist/agent.js.map +1 -0
- package/dist/daemon.d.ts +91 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +449 -0
- package/dist/daemon.js.map +1 -0
- package/dist/hooks.d.ts +34 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +82 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/state.d.ts +31 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +67 -0
- package/dist/state.js.map +1 -0
- package/dist/tools.d.ts +42 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +110 -0
- package/dist/tools.js.map +1 -0
- package/dist/types.d.ts +222 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +19 -0
- package/dist/types.js.map +1 -0
- package/dist/worktree.d.ts +42 -0
- package/dist/worktree.d.ts.map +1 -0
- package/dist/worktree.js +86 -0
- package/dist/worktree.js.map +1 -0
- package/package.json +70 -0
- package/src/agent.js +166 -0
- package/src/agent.ts +110 -0
- package/src/daemon.js +591 -0
- package/src/daemon.ts +529 -0
- package/src/hooks.js +145 -0
- package/src/hooks.ts +94 -0
- package/src/index.js +105 -0
- package/src/index.ts +43 -0
- package/src/state.js +168 -0
- package/src/state.ts +77 -0
- package/src/tools.js +192 -0
- package/src/tools.ts +134 -0
- package/src/types.js +21 -0
- package/src/types.ts +249 -0
- package/src/worktree.js +195 -0
- package/src/worktree.ts +122 -0
package/src/worktree.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GLM Daemon - Worktree Manager
|
|
3
|
+
*
|
|
4
|
+
* Handles git worktree isolation for parallel task execution.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { exec } from "child_process";
|
|
8
|
+
import { promisify } from "util";
|
|
9
|
+
import { join } from "path";
|
|
10
|
+
import type { GLMDaemonConfig } from "./types.js";
|
|
11
|
+
|
|
12
|
+
const execAsync = promisify(exec);
|
|
13
|
+
|
|
14
|
+
export class WorktreeManager {
|
|
15
|
+
private config: GLMDaemonConfig;
|
|
16
|
+
private worktreePath: string | null = null;
|
|
17
|
+
|
|
18
|
+
constructor(config: GLMDaemonConfig) {
|
|
19
|
+
this.config = config;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Create a new worktree for isolation
|
|
24
|
+
*/
|
|
25
|
+
async createWorktree(): Promise<string> {
|
|
26
|
+
if (!this.config.enableWorktree) {
|
|
27
|
+
return this.config.cwd;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const timestamp = Date.now();
|
|
31
|
+
const worktreeName = `glm-${timestamp}`;
|
|
32
|
+
this.worktreePath = join(this.config.cwd, "worktrees", worktreeName);
|
|
33
|
+
|
|
34
|
+
// Create worktrees directory
|
|
35
|
+
await execAsync(`mkdir -p ${join(this.config.cwd, "worktrees")}`);
|
|
36
|
+
|
|
37
|
+
// Create worktree
|
|
38
|
+
await execAsync(
|
|
39
|
+
`git worktree add -b ${worktreeName} ${this.worktreePath}`
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
return this.worktreePath;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Create a feature branch in the worktree
|
|
47
|
+
*/
|
|
48
|
+
async createBranch(): Promise<string> {
|
|
49
|
+
if (!this.worktreePath) {
|
|
50
|
+
throw new Error("No worktree created");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const branchName = `feat/glm-${Date.now()}`;
|
|
54
|
+
await execAsync(`cd ${this.worktreePath} && git checkout -b ${branchName}`);
|
|
55
|
+
|
|
56
|
+
return branchName;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Commit changes in the worktree
|
|
61
|
+
*/
|
|
62
|
+
async commitChanges(options: {
|
|
63
|
+
message: string;
|
|
64
|
+
files: string[];
|
|
65
|
+
}): Promise<string> {
|
|
66
|
+
const cwd = this.worktreePath || this.config.cwd;
|
|
67
|
+
|
|
68
|
+
// Stage files
|
|
69
|
+
for (const file of options.files) {
|
|
70
|
+
await execAsync(`cd ${cwd} && git add ${file}`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Commit
|
|
74
|
+
const { stdout } = await execAsync(
|
|
75
|
+
`cd ${cwd} && git commit -m "${options.message}"`
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
return stdout.trim();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Create a pull request
|
|
83
|
+
*/
|
|
84
|
+
async createPullRequest(options: {
|
|
85
|
+
title: string;
|
|
86
|
+
body: string;
|
|
87
|
+
}): Promise<void> {
|
|
88
|
+
const cwd = this.worktreePath || this.config.cwd;
|
|
89
|
+
|
|
90
|
+
// Push branch
|
|
91
|
+
await execAsync(`cd ${cwd} && git push -u origin HEAD`);
|
|
92
|
+
|
|
93
|
+
// Create PR using gh CLI
|
|
94
|
+
await execAsync(
|
|
95
|
+
`cd ${cwd} && gh pr create --title "${options.title}" --body "${options.body}"`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Clean up worktree
|
|
101
|
+
*/
|
|
102
|
+
async cleanup(): Promise<void> {
|
|
103
|
+
if (!this.worktreePath) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Remove worktree
|
|
108
|
+
await execAsync(`git worktree remove ${this.worktreePath}`);
|
|
109
|
+
|
|
110
|
+
// Delete directory
|
|
111
|
+
await execAsync(`rm -rf ${this.worktreePath}`);
|
|
112
|
+
|
|
113
|
+
this.worktreePath = null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Get worktree path
|
|
118
|
+
*/
|
|
119
|
+
getPath(): string | null {
|
|
120
|
+
return this.worktreePath;
|
|
121
|
+
}
|
|
122
|
+
}
|