@simonfestl/husky-cli 0.3.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 +144 -0
- package/dist/commands/agent.d.ts +2 -0
- package/dist/commands/agent.js +279 -0
- package/dist/commands/config.d.ts +8 -0
- package/dist/commands/config.js +73 -0
- package/dist/commands/roadmap.d.ts +2 -0
- package/dist/commands/roadmap.js +325 -0
- package/dist/commands/task.d.ts +2 -0
- package/dist/commands/task.js +635 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +16 -0
- package/dist/lib/streaming.d.ts +44 -0
- package/dist/lib/streaming.js +157 -0
- package/package.json +30 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StreamClient - Sends output to Husky Dashboard via SSE
|
|
3
|
+
* Uses batching to reduce API calls
|
|
4
|
+
*/
|
|
5
|
+
export class StreamClient {
|
|
6
|
+
apiUrl;
|
|
7
|
+
sessionId;
|
|
8
|
+
apiKey;
|
|
9
|
+
buffer = [];
|
|
10
|
+
flushTimeout = null;
|
|
11
|
+
flushIntervalMs = 500; // Batch window: 500ms
|
|
12
|
+
maxBufferSize = 50; // Force flush after 50 items
|
|
13
|
+
constructor(apiUrl, sessionId, apiKey) {
|
|
14
|
+
this.apiUrl = apiUrl;
|
|
15
|
+
this.sessionId = sessionId;
|
|
16
|
+
this.apiKey = apiKey;
|
|
17
|
+
}
|
|
18
|
+
async flushBuffer() {
|
|
19
|
+
if (this.buffer.length === 0)
|
|
20
|
+
return;
|
|
21
|
+
const items = [...this.buffer];
|
|
22
|
+
this.buffer = [];
|
|
23
|
+
if (this.flushTimeout) {
|
|
24
|
+
clearTimeout(this.flushTimeout);
|
|
25
|
+
this.flushTimeout = null;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const response = await fetch(`${this.apiUrl}/api/vm-sessions/${this.sessionId}/stream`, {
|
|
29
|
+
method: "POST",
|
|
30
|
+
headers: {
|
|
31
|
+
"Content-Type": "application/json",
|
|
32
|
+
"X-API-Key": this.apiKey,
|
|
33
|
+
},
|
|
34
|
+
body: JSON.stringify({
|
|
35
|
+
batch: items.map((item) => ({
|
|
36
|
+
...item,
|
|
37
|
+
timestamp: new Date().toISOString(),
|
|
38
|
+
})),
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
console.error(`Stream error: ${response.status}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.error("Stream connection error:", error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
scheduleFlush() {
|
|
50
|
+
if (this.buffer.length >= this.maxBufferSize) {
|
|
51
|
+
// Force immediate flush if buffer is full
|
|
52
|
+
this.flushBuffer();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (!this.flushTimeout) {
|
|
56
|
+
this.flushTimeout = setTimeout(() => {
|
|
57
|
+
this.flushBuffer();
|
|
58
|
+
}, this.flushIntervalMs);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async send(content, type) {
|
|
62
|
+
this.buffer.push({ content, type });
|
|
63
|
+
this.scheduleFlush();
|
|
64
|
+
}
|
|
65
|
+
// Immediate send for important messages (system, plan)
|
|
66
|
+
async sendImmediate(content, type) {
|
|
67
|
+
this.buffer.push({ content, type });
|
|
68
|
+
await this.flushBuffer();
|
|
69
|
+
}
|
|
70
|
+
stdout(content) {
|
|
71
|
+
return this.send(content, "stdout");
|
|
72
|
+
}
|
|
73
|
+
stderr(content) {
|
|
74
|
+
return this.send(content, "stderr");
|
|
75
|
+
}
|
|
76
|
+
system(content) {
|
|
77
|
+
return this.sendImmediate(content, "system");
|
|
78
|
+
}
|
|
79
|
+
plan(content) {
|
|
80
|
+
return this.sendImmediate(content, "plan");
|
|
81
|
+
}
|
|
82
|
+
// Force flush remaining buffer (call before exit)
|
|
83
|
+
async flush() {
|
|
84
|
+
await this.flushBuffer();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Update session status in Husky Dashboard
|
|
89
|
+
*/
|
|
90
|
+
export async function updateSessionStatus(apiUrl, sessionId, apiKey, status, data) {
|
|
91
|
+
try {
|
|
92
|
+
await fetch(`${apiUrl}/api/webhooks/vm/status`, {
|
|
93
|
+
method: "POST",
|
|
94
|
+
headers: {
|
|
95
|
+
"Content-Type": "application/json",
|
|
96
|
+
"X-API-Key": apiKey,
|
|
97
|
+
},
|
|
98
|
+
body: JSON.stringify({
|
|
99
|
+
sessionId,
|
|
100
|
+
status,
|
|
101
|
+
...data,
|
|
102
|
+
}),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.error("Failed to update session status:", error);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Submit plan for approval
|
|
111
|
+
*/
|
|
112
|
+
export async function submitPlan(apiUrl, sessionId, apiKey, plan) {
|
|
113
|
+
await fetch(`${apiUrl}/api/vm-sessions/${sessionId}/plan`, {
|
|
114
|
+
method: "POST",
|
|
115
|
+
headers: {
|
|
116
|
+
"Content-Type": "application/json",
|
|
117
|
+
"X-API-Key": apiKey,
|
|
118
|
+
},
|
|
119
|
+
body: JSON.stringify({
|
|
120
|
+
...plan,
|
|
121
|
+
createdAt: new Date().toISOString(),
|
|
122
|
+
}),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Wait for plan approval from user
|
|
127
|
+
*/
|
|
128
|
+
export async function waitForApproval(apiUrl, sessionId, apiKey, timeoutMs = 1800000 // 30 minutes default
|
|
129
|
+
) {
|
|
130
|
+
const startTime = Date.now();
|
|
131
|
+
const pollInterval = 5000; // 5 seconds
|
|
132
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
133
|
+
try {
|
|
134
|
+
const response = await fetch(`${apiUrl}/api/vm-sessions/${sessionId}/approval-status`, {
|
|
135
|
+
headers: {
|
|
136
|
+
"X-API-Key": apiKey,
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
if (response.ok) {
|
|
140
|
+
const data = await response.json();
|
|
141
|
+
if (data.status === "approved") {
|
|
142
|
+
return "approved";
|
|
143
|
+
}
|
|
144
|
+
if (data.status === "rejected") {
|
|
145
|
+
return "rejected";
|
|
146
|
+
}
|
|
147
|
+
// Still pending, continue waiting
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
console.error("Error checking approval status:", error);
|
|
152
|
+
}
|
|
153
|
+
// Wait before next poll
|
|
154
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
155
|
+
}
|
|
156
|
+
return "timeout";
|
|
157
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@simonfestl/husky-cli",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "CLI for Huskyv0 Task Orchestration with Claude Agent SDK",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"husky": "./dist/index.js",
|
|
8
|
+
"husky-agent": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"dev": "tsc --watch",
|
|
13
|
+
"start": "node dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@anthropic-ai/claude-code": "^1.0.0",
|
|
17
|
+
"commander": "^12.1.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^22",
|
|
21
|
+
"typescript": "^5"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/simon-sfxecom/husky-cli.git"
|
|
29
|
+
}
|
|
30
|
+
}
|