@runfusion/fusion 0.1.2 → 0.2.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 +2 -0
- package/dist/bin.js +4055 -1755
- package/dist/client/assets/AgentDetailView-CDZED6Dy.css +1 -0
- package/dist/client/assets/AgentDetailView-zycSdnO8.js +28 -0
- package/dist/client/assets/AgentsView-DoQkkDLf.css +1 -0
- package/dist/client/assets/AgentsView-pO7WiBS5.js +522 -0
- package/dist/client/assets/ChatView-BOd-sxbT.js +1 -0
- package/dist/client/assets/DevServerView-09GQf34f.js +11 -0
- package/dist/client/assets/DevServerView-ZeBGQkLI.css +1 -0
- package/dist/client/assets/DirectoryPicker-CcdN1Zs7.js +1 -0
- package/dist/client/assets/DocumentsView-CS8aiwtz.js +1 -0
- package/dist/client/assets/DocumentsView-Co9to4Zp.css +1 -0
- package/dist/client/assets/InsightsView-Bu9Cv8Ol.js +11 -0
- package/dist/client/assets/InsightsView-Egu71gmh.css +1 -0
- package/dist/client/assets/MemoryView-CtqgDtV9.js +2 -0
- package/dist/client/assets/MemoryView-DhinauGs.css +1 -0
- package/dist/client/assets/NodesView-BInPcedy.js +14 -0
- package/dist/client/assets/NodesView-DlQZHGXA.css +1 -0
- package/dist/client/assets/PiExtensionsManager-COxkYM2m.js +11 -0
- package/dist/client/assets/PiExtensionsManager-CPgmJgDk.css +1 -0
- package/dist/client/assets/PluginManager-CXUWZBOc.js +1 -0
- package/dist/client/assets/PluginManager-D64RIzmL.css +1 -0
- package/dist/client/assets/RoadmapsView-BOYnyMCh.css +1 -0
- package/dist/client/assets/RoadmapsView-BbCexaoi.js +6 -0
- package/dist/client/assets/SetupWizardModal-Cakxqkad.js +1 -0
- package/dist/client/assets/SkillsView-Cytf009Z.css +1 -0
- package/dist/client/assets/SkillsView-D3iqYCVf.js +1 -0
- package/dist/client/assets/folder-open-kO5Hsk66.js +6 -0
- package/dist/client/assets/index-BiSuUXCa.css +1 -0
- package/dist/client/assets/index-y194HxzU.js +644 -0
- package/dist/client/assets/upload-DHBQat92.js +6 -0
- package/dist/client/index.html +2 -2
- package/dist/client/sw.js +45 -1
- package/dist/client/theme-data.css +109 -0
- package/dist/extension.js +969 -408
- package/dist/pi-claude-cli/index.ts +131 -0
- package/dist/pi-claude-cli/package.json +39 -0
- package/dist/pi-claude-cli/src/__tests__/control-handler.test.ts +191 -0
- package/dist/pi-claude-cli/src/__tests__/event-bridge.test.ts +1244 -0
- package/dist/pi-claude-cli/src/__tests__/mcp-config.test.ts +272 -0
- package/dist/pi-claude-cli/src/__tests__/process-manager.test.ts +619 -0
- package/dist/pi-claude-cli/src/__tests__/prompt-builder.test.ts +1067 -0
- package/dist/pi-claude-cli/src/__tests__/provider.test.ts +1902 -0
- package/dist/pi-claude-cli/src/__tests__/stream-parser.test.ts +188 -0
- package/dist/pi-claude-cli/src/__tests__/thinking-config.test.ts +141 -0
- package/dist/pi-claude-cli/src/__tests__/tool-mapping.test.ts +252 -0
- package/dist/pi-claude-cli/src/control-handler.ts +68 -0
- package/dist/pi-claude-cli/src/event-bridge.ts +386 -0
- package/dist/pi-claude-cli/src/mcp-config.ts +111 -0
- package/dist/pi-claude-cli/src/mcp-schema-server.cjs +49 -0
- package/dist/pi-claude-cli/src/process-manager.ts +218 -0
- package/dist/pi-claude-cli/src/prompt-builder.ts +536 -0
- package/dist/pi-claude-cli/src/provider.ts +354 -0
- package/dist/pi-claude-cli/src/stream-parser.ts +37 -0
- package/dist/pi-claude-cli/src/thinking-config.ts +83 -0
- package/dist/pi-claude-cli/src/tool-mapping.ts +147 -0
- package/dist/pi-claude-cli/src/types.ts +87 -0
- package/package.json +11 -4
- package/skill/fusion/SKILL.md +5 -3
- package/skill/fusion/references/cli-commands.md +22 -22
- package/skill/fusion/references/extension-tools.md +3 -1
- package/skill/fusion/references/fusion-capabilities.md +28 -35
- package/skill/fusion/references/task-structure.md +4 -4
- package/skill/fusion/workflows/dashboard-cli.md +6 -6
- package/skill/fusion/workflows/specifications.md +5 -3
- package/skill/fusion/workflows/task-lifecycle.md +1 -1
- package/skill/fusion/workflows/task-management.md +3 -1
- package/dist/client/assets/index-Djv5vKo0.css +0 -1
- package/dist/client/assets/index-zfXYuUXG.js +0 -1241
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process manager for spawning and managing Claude CLI subprocesses.
|
|
3
|
+
*
|
|
4
|
+
* Handles subprocess lifecycle: spawn with correct CLI flags, write NDJSON
|
|
5
|
+
* messages to stdin, force-kill after result (CLI hangs bug), and stderr capture.
|
|
6
|
+
* Also provides startup validation for CLI presence and authentication.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import spawn from "cross-spawn";
|
|
10
|
+
import { execSync } from "node:child_process";
|
|
11
|
+
import { writeFileSync, unlinkSync } from "node:fs";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
import { tmpdir } from "node:os";
|
|
14
|
+
import type { ChildProcess } from "node:child_process";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Spawn a Claude CLI subprocess with all required flags for stream-json communication.
|
|
18
|
+
*
|
|
19
|
+
* @param modelId - The model ID to pass via --model flag
|
|
20
|
+
* @param systemPrompt - Optional system prompt appended via --append-system-prompt
|
|
21
|
+
* @param options - Optional cwd, AbortSignal, and effort level
|
|
22
|
+
* @returns The spawned ChildProcess with piped stdin/stdout/stderr
|
|
23
|
+
*/
|
|
24
|
+
export function spawnClaude(
|
|
25
|
+
modelId: string,
|
|
26
|
+
systemPrompt?: string,
|
|
27
|
+
options?: {
|
|
28
|
+
cwd?: string;
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
effort?: string;
|
|
31
|
+
mcpConfigPath?: string;
|
|
32
|
+
resumeSessionId?: string;
|
|
33
|
+
newSessionId?: string;
|
|
34
|
+
},
|
|
35
|
+
): ChildProcess {
|
|
36
|
+
const args = [
|
|
37
|
+
"-p",
|
|
38
|
+
"--input-format",
|
|
39
|
+
"stream-json",
|
|
40
|
+
"--output-format",
|
|
41
|
+
"stream-json",
|
|
42
|
+
"--verbose",
|
|
43
|
+
"--include-partial-messages",
|
|
44
|
+
"--model",
|
|
45
|
+
modelId,
|
|
46
|
+
"--permission-prompt-tool",
|
|
47
|
+
"stdio",
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
if (options?.resumeSessionId) {
|
|
51
|
+
// Resume an existing session — CLI loads prior conversation from disk
|
|
52
|
+
args.push("--resume", options.resumeSessionId);
|
|
53
|
+
} else if (options?.newSessionId) {
|
|
54
|
+
// First turn: create session with this ID so subsequent turns can --resume it
|
|
55
|
+
args.push("--session-id", options.newSessionId);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (systemPrompt) {
|
|
59
|
+
// Write system prompt to a temp file to avoid ENAMETOOLONG on Windows.
|
|
60
|
+
// Claude CLI's --append-system-prompt accepts a file path or literal text.
|
|
61
|
+
const tmpFile = join(
|
|
62
|
+
tmpdir(),
|
|
63
|
+
`pi-claude-cli-sysprompt-${process.pid}.txt`,
|
|
64
|
+
);
|
|
65
|
+
writeFileSync(tmpFile, systemPrompt, "utf-8");
|
|
66
|
+
args.push("--append-system-prompt", tmpFile);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (options?.effort) {
|
|
70
|
+
args.push("--effort", options.effort);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (options?.mcpConfigPath) {
|
|
74
|
+
args.push("--mcp-config", options.mcpConfigPath);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const proc = spawn("claude", args, {
|
|
78
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
79
|
+
cwd: options?.cwd ?? process.cwd(),
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return proc as ChildProcess;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Clean up the temp system prompt file created by spawnClaude.
|
|
87
|
+
* Safe to call multiple times or when no file exists.
|
|
88
|
+
*/
|
|
89
|
+
export function cleanupSystemPromptFile(): void {
|
|
90
|
+
try {
|
|
91
|
+
unlinkSync(join(tmpdir(), `pi-claude-cli-sysprompt-${process.pid}.txt`));
|
|
92
|
+
} catch {
|
|
93
|
+
// File doesn't exist or already deleted — ignore
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Write a user message to the subprocess stdin as NDJSON.
|
|
99
|
+
* Does NOT call stdin.end() -- stdin stays open for control_response in Phase 2.
|
|
100
|
+
*
|
|
101
|
+
* Accepts both string (text-only prompt) and array (ContentBlock[] with images)
|
|
102
|
+
* content. JSON.stringify handles both natively. The stream-json protocol
|
|
103
|
+
* supports either format in the content field.
|
|
104
|
+
*
|
|
105
|
+
* @param proc - The Claude subprocess
|
|
106
|
+
* @param prompt - The prompt text or ContentBlock[] to send
|
|
107
|
+
*/
|
|
108
|
+
export function writeUserMessage(
|
|
109
|
+
proc: ChildProcess,
|
|
110
|
+
prompt: string | unknown[],
|
|
111
|
+
): void {
|
|
112
|
+
const message = {
|
|
113
|
+
type: "user",
|
|
114
|
+
message: {
|
|
115
|
+
role: "user",
|
|
116
|
+
content: prompt,
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
proc.stdin!.write(JSON.stringify(message) + "\n");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Force-kill a subprocess immediately via SIGKILL.
|
|
124
|
+
* No-ops if the process is already dead (killed or exited).
|
|
125
|
+
* Cross-platform safe: Node.js treats SIGKILL as forceful termination on Windows.
|
|
126
|
+
*
|
|
127
|
+
* @param proc - The subprocess to force-kill
|
|
128
|
+
*/
|
|
129
|
+
export function forceKillProcess(proc: ChildProcess): void {
|
|
130
|
+
if (proc.killed || proc.exitCode !== null) return;
|
|
131
|
+
proc.kill("SIGKILL");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Registry of active subprocesses for cleanup on teardown. */
|
|
135
|
+
const activeProcesses = new Set<ChildProcess>();
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Register a subprocess in the global process registry.
|
|
139
|
+
* The process is automatically removed from the registry when it exits.
|
|
140
|
+
*
|
|
141
|
+
* @param proc - The subprocess to track
|
|
142
|
+
*/
|
|
143
|
+
export function registerProcess(proc: ChildProcess): void {
|
|
144
|
+
activeProcesses.add(proc);
|
|
145
|
+
proc.on("exit", () => activeProcesses.delete(proc));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Force-kill all registered subprocesses and clear the registry.
|
|
150
|
+
* Safe to call multiple times -- no-ops on already-dead processes.
|
|
151
|
+
*/
|
|
152
|
+
export function killAllProcesses(): void {
|
|
153
|
+
for (const proc of activeProcesses) {
|
|
154
|
+
forceKillProcess(proc);
|
|
155
|
+
}
|
|
156
|
+
activeProcesses.clear();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Force-kill the subprocess after a 500ms grace period.
|
|
161
|
+
* The Claude CLI hangs after emitting the result message (known bug).
|
|
162
|
+
* Brief grace period allows final stdout flushing before force-kill.
|
|
163
|
+
*
|
|
164
|
+
* @param proc - The Claude subprocess to clean up
|
|
165
|
+
*/
|
|
166
|
+
export function cleanupProcess(proc: ChildProcess): void {
|
|
167
|
+
setTimeout(() => {
|
|
168
|
+
forceKillProcess(proc);
|
|
169
|
+
}, 500);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Attach a data listener to stderr and accumulate output into a buffer.
|
|
174
|
+
*
|
|
175
|
+
* @param proc - The Claude subprocess
|
|
176
|
+
* @returns A function that returns the accumulated stderr string
|
|
177
|
+
*/
|
|
178
|
+
export function captureStderr(proc: ChildProcess): () => string {
|
|
179
|
+
let buffer = "";
|
|
180
|
+
proc.stderr!.on("data", (data: Buffer) => {
|
|
181
|
+
buffer += data.toString();
|
|
182
|
+
});
|
|
183
|
+
return () => buffer;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Validate that the Claude CLI is installed and on PATH.
|
|
188
|
+
* Throws with install instructions if not found.
|
|
189
|
+
*/
|
|
190
|
+
export function validateCliPresence(): void {
|
|
191
|
+
try {
|
|
192
|
+
execSync("claude --version", { stdio: "pipe", timeout: 5000 });
|
|
193
|
+
} catch {
|
|
194
|
+
throw new Error(
|
|
195
|
+
"Claude Code CLI not found. Install it: npm install -g @anthropic-ai/claude-code\n" +
|
|
196
|
+
"Then authenticate: claude auth login",
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Validate that the Claude CLI is authenticated.
|
|
203
|
+
* Returns false and warns if not authenticated.
|
|
204
|
+
*
|
|
205
|
+
* @returns true if authenticated, false otherwise
|
|
206
|
+
*/
|
|
207
|
+
export function validateCliAuth(): boolean {
|
|
208
|
+
try {
|
|
209
|
+
execSync("claude auth status", { stdio: "pipe", timeout: 5000 });
|
|
210
|
+
return true;
|
|
211
|
+
} catch {
|
|
212
|
+
console.warn(
|
|
213
|
+
"[pi-claude-cli] Claude CLI is not authenticated. " +
|
|
214
|
+
"Run 'claude auth login' to authenticate.",
|
|
215
|
+
);
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
}
|