pi-crew 0.3.2 → 0.3.4
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/package.json
CHANGED
|
@@ -69,7 +69,10 @@ const HOOK_TIMEOUT_MS = 30_000;
|
|
|
69
69
|
export function isAllowedHookPath(hookPath: string): boolean {
|
|
70
70
|
if (!hookPath || hookPath.trim().length === 0) return false;
|
|
71
71
|
if (!path.isAbsolute(hookPath)) {
|
|
72
|
-
|
|
72
|
+
// Use path.posix.normalize to ensure forward-slash normalization on all platforms.
|
|
73
|
+
// On Windows, path.normalize converts .hooks/hook.sh to .hooks\hook.sh (backslash),
|
|
74
|
+
// breaking the startsWith(".hooks/") check. path.posix.normalize always uses /.
|
|
75
|
+
const normalized = path.posix.normalize(hookPath);
|
|
73
76
|
return normalized === ".hooks" || normalized.startsWith(".hooks/");
|
|
74
77
|
}
|
|
75
78
|
// Normalize to forward slashes for consistent cross-platform comparison.
|
|
@@ -219,9 +222,16 @@ export async function runIterationHook(
|
|
|
219
222
|
});
|
|
220
223
|
});
|
|
221
224
|
|
|
222
|
-
// Write payload to stdin and close it
|
|
223
|
-
|
|
224
|
-
|
|
225
|
+
// Write payload to stdin and close it.
|
|
226
|
+
// Handle EPIPE errors gracefully (occurs if the hook script exits before
|
|
227
|
+
// reading all of stdin, which is normal for some hook scripts on certain OS).
|
|
228
|
+
child.stdin.on("error", () => { /* ignore EPIPE — hook exited early */ });
|
|
229
|
+
try {
|
|
230
|
+
child.stdin.write(stdinJson, "utf-8");
|
|
231
|
+
child.stdin.end();
|
|
232
|
+
} catch {
|
|
233
|
+
// ignore
|
|
234
|
+
}
|
|
225
235
|
});
|
|
226
236
|
}
|
|
227
237
|
|
|
@@ -77,15 +77,18 @@ function normalizeSyntheticPath(worktreePath: string, rawPath: string): string {
|
|
|
77
77
|
* @param hookPath - The hook script path to validate
|
|
78
78
|
* @returns true if the path is allowed, false otherwise
|
|
79
79
|
*/
|
|
80
|
-
function isAllowedSetupHook(hookPath: string): boolean {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
80
|
+
function isAllowedSetupHook(hookPath: string): boolean {
|
|
81
|
+
if (!hookPath || hookPath.trim().length === 0) return false;
|
|
82
|
+
if (!path.isAbsolute(hookPath)) {
|
|
83
|
+
// Use path.posix.normalize for consistent forward-slash handling on all platforms.
|
|
84
|
+
const normalized = path.posix.normalize(hookPath);
|
|
85
|
+
return normalized === ".hooks" || normalized.startsWith(".hooks/");
|
|
86
|
+
}
|
|
87
|
+
// Normalize to forward slashes for consistent cross-platform comparison.
|
|
88
|
+
const normalizedHookPath = hookPath.replace(/\\/g, "/");
|
|
89
|
+
const homeHooksNormalized = (process.env.HOME ?? "").replace(/\\/g, "/") + "/.pi/hooks";
|
|
90
|
+
return normalizedHookPath === homeHooksNormalized || normalizedHookPath.startsWith(homeHooksNormalized + "/");
|
|
85
91
|
}
|
|
86
|
-
const homeHooks = path.join(process.env.HOME ?? "", "", ".pi", "hooks");
|
|
87
|
-
return hookPath === homeHooks || hookPath.startsWith(homeHooks + path.sep);
|
|
88
|
-
}
|
|
89
92
|
|
|
90
93
|
function runSetupHook(manifest: TeamRunManifest, task: TeamTaskState, repoRoot: string, worktreePath: string, branch: string): string[] {
|
|
91
94
|
const cfg = loadConfig(manifest.cwd).config.worktree;
|
|
@@ -101,15 +104,18 @@ function runSetupHook(manifest: TeamRunManifest, task: TeamTaskState, repoRoot:
|
|
|
101
104
|
return [];
|
|
102
105
|
}
|
|
103
106
|
const nodeHook = hookPath.endsWith(".js") || hookPath.endsWith(".cjs") || hookPath.endsWith(".mjs");
|
|
107
|
+
// On Windows, set shell:true to ensure PATH resolution and .cjs/.bat file associations work.
|
|
108
|
+
const useShell = process.platform === "win32";
|
|
104
109
|
const result = spawnSync(nodeHook ? process.execPath : hookPath, nodeHook ? [hookPath] : [], {
|
|
105
110
|
cwd: worktreePath,
|
|
106
111
|
encoding: "utf-8",
|
|
107
112
|
input: JSON.stringify({ version: 1, repoRoot, worktreePath, agentCwd: worktreePath, branch, runId: manifest.runId, taskId: task.id, agent: task.agent }),
|
|
108
113
|
timeout: cfg.setupHookTimeoutMs ?? 30_000,
|
|
109
|
-
shell:
|
|
114
|
+
shell: useShell,
|
|
110
115
|
env: sanitizeEnvSecrets(process.env, {
|
|
111
116
|
allowList: ["PATH", "HOME", "USERPROFILE", "TEMP", "TMP", "TMPDIR", "LANG", "LC_ALL", "PI_*"],
|
|
112
117
|
}),
|
|
118
|
+
windowsHide: true,
|
|
113
119
|
});
|
|
114
120
|
if (result.error) throw new Error(`worktree setup hook failed: ${result.error.message}`);
|
|
115
121
|
if (result.status !== 0) throw new Error(`worktree setup hook failed with exit code ${result.status}: ${result.stderr || result.stdout || "no output"}`);
|