Skip to content

A self-organizing Obsidian vault that gives AI coding agents persistent memory.

fix: pass windowsHide on every spawn the scripts start, and scan the source so it stays that way (#394)

Brenno Ferraricf43e9cc9901
diff --git a/.claude/scripts/lib/mcp-qmd-client.ts b/.claude/scripts/lib/mcp-qmd-client.ts
index 5c809d1..cfe25b6 100644
--- a/.claude/scripts/lib/mcp-qmd-client.ts
+++ b/.claude/scripts/lib/mcp-qmd-client.ts
@@ -420,6 +420,7 @@ export function createQmdClient(vaultRoot: string, launcherPath: string | null,
const child: ChildProcess = spawnChild(process.execPath, [launcher], {
stdio: ["pipe", "pipe", "ignore"],
env: { ...process.env, CLAUDE_PROJECT_DIR: vaultRoot },
+ windowsHide: true,
});
const pending = new Map<number, Pending>();
diff --git a/.claude/scripts/lib/mcp-reason.ts b/.claude/scripts/lib/mcp-reason.ts
index 2158fe6..99e85f9 100644
--- a/.claude/scripts/lib/mcp-reason.ts
+++ b/.claude/scripts/lib/mcp-reason.ts
@@ -532,6 +532,7 @@ export function runReasoning(
timeout: SPAWN_TIMEOUT_MS,
killSignal: "SIGKILL",
stdio: ["ignore", "pipe", "pipe"],
+ windowsHide: true,
});
} catch (e) {
resolve(interpretRun("", "", e instanceof Error ? e.message : String(e), Date.now() - started));
diff --git a/.claude/scripts/lib/mcp-server.ts b/.claude/scripts/lib/mcp-server.ts
index 96bd662..05adee4 100644
--- a/.claude/scripts/lib/mcp-server.ts
+++ b/.claude/scripts/lib/mcp-server.ts
@@ -155,7 +155,7 @@ export function reindexSync(
((sub: string): boolean => {
try {
const { cmd, args: argv, shell } = buildQmdCommand(resolveQmdEntry(), qmdArgs(sub));
- const r = spawnSync(cmd, [...argv], { shell, timeout: REINDEX_TIMEOUT_MS, stdio: "ignore" });
+ const r = spawnSync(cmd, [...argv], { shell, timeout: REINDEX_TIMEOUT_MS, stdio: "ignore", windowsHide: true });
return r.status === 0;
} catch {
return false;
diff --git a/.claude/scripts/session-start.ts b/.claude/scripts/session-start.ts
index d9fa2e2..c0fc0a8 100644
--- a/.claude/scripts/session-start.ts
+++ b/.claude/scripts/session-start.ts
@@ -201,6 +201,7 @@ if (qmdIndex !== null && qmdEntry !== null) {
encoding: "utf-8",
timeout: 5_000,
shell: preflightCmd.shell,
+ windowsHide: true,
});
if (isQmdNativeAbiMismatch(preflight.stderr ?? "")) {
const pkgRoot = qmdPackageRootFromEntry(qmdEntry);
@@ -210,6 +211,7 @@ if (qmdIndex !== null && qmdEntry !== null) {
encoding: "utf-8",
timeout: 20_000,
shell: true,
+ windowsHide: true,
});
qmdSelfHealNote =
rebuild.status === 0
@@ -231,6 +233,7 @@ if (qmdMinVersion !== null && qmdEntry !== null) {
encoding: "utf-8",
timeout: 5_000,
shell: versionCmd.shell,
+ windowsHide: true,
});
if (v.status === 0 && !qmdVersionAtLeast(v.stdout ?? "", qmdMinVersion)) {
qmdVersionNote = `⚠️ Installed qmd (${(v.stdout ?? "").trim()}) is below this vault's declared minimum (${qmdMinVersion}) — semantic search may misbehave. Update: \`npm i -g @tobilu/qmd\`, then re-run the bootstrap.`;
@@ -294,6 +297,7 @@ function runCmd(
const r = spawnSync(cmd, args as string[], {
encoding: "utf-8",
timeout: timeoutMs,
+ windowsHide: true,
});
if (
r.error &&
diff --git a/.claude/scripts/tests/spawn-windows-hide.test.ts b/.claude/scripts/tests/spawn-windows-hide.test.ts
new file mode 100644
index 0000000..c37459e
--- /dev/null
+++ b/.claude/scripts/tests/spawn-windows-hide.test.ts
@@ -0,0 +1,105 @@
+/**
+ * Every process this repo's scripts start passes `windowsHide` (#390).
+ *
+ * On Windows, a console program started without it from a process that has no
+ * console of its own (a detached worker, a hook, an MCP server) opens a
+ * console window. Under Windows Terminal as the default terminal that is a
+ * visible window per spawn: a session start once flooded the screen with them
+ * (#381, #384). The flag is easy to drop and nothing else notices: the
+ * behaviour only shows on a Windows desktop. So this reads the source and
+ * checks every direct spawn call, the way mindframe's qmd extension does.
+ *
+ * A spawn that must share its parent's console (stdio inherited end to end)
+ * goes on the allowlist with its reason; the flag couldn't hide anything
+ * there, because libuv sets CREATE_NO_WINDOW only when no stdio is inherited.
+ */
+
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { readFileSync, readdirSync, statSync } from "node:fs";
+import { dirname, join, relative } from "node:path";
+import { fileURLToPath } from "node:url";
+
+const SCRIPTS = dirname(dirname(fileURLToPath(import.meta.url)));
+const REPO = dirname(dirname(SCRIPTS));
+
+/** Spawn calls that may omit the flag, by file and a snippet of the call. */
+const ALLOWED: ReadonlyArray<{ readonly file: string; readonly call: string; readonly why: string }> = [
+ {
+ file: ".claude/scripts/om-mcp.mjs",
+ call: 'stdio: "inherit"',
+ why: "the MCP server launcher: the child IS the server and speaks over the inherited stdio",
+ },
+ {
+ file: ".claude/scripts/qmd-mcp.mjs",
+ call: 'stdio: "inherit"',
+ why: "qmd's MCP stdio server: it speaks over the inherited stdio",
+ },
+];
+
+const SPAWN_NAMES = ["spawnSync", "spawn", "execSync", "execFileSync", "execFile"];
+
+/**
+ * The calls that start a process in `code`: node's spawn functions, called bare
+ * or through a namespace (`cp.spawn(`), and any seam parameter typed as one of
+ * them (`spawnChild: typeof spawn`), which is how a spawn reaches a test.
+ */
+function spawnPattern(code: string): RegExp {
+ const seams = [...code.matchAll(new RegExp(`(\\w+)\\s*:\\s*typeof\\s+(?:${SPAWN_NAMES.join("|")})\\b`, "g"))].map(
+ (m) => m[1]!,
+ );
+ return new RegExp(`(?<![\\w$])(?:\\w+\\.)?(${[...SPAWN_NAMES, ...seams].join("|")})\\(`, "g");
+}
+
+function sources(dir: string): string[] {
+ const out: string[] = [];
+ for (const name of readdirSync(dir)) {
+ if (name === "node_modules" || name === "tests") continue;
+ const path = join(dir, name);
+ if (statSync(path).isDirectory()) out.push(...sources(path));
+ else if (/\.(ts|mjs)$/.test(name) && !name.endsWith(".d.ts") && !name.endsWith(".d.mts")) out.push(path);
+ }
+ return out;
+}
+
+/** The text of the call starting at the "(" at `open`, through its matching ")". */
+function callText(text: string, open: number): string {
+ let depth = 0;
+ for (let i = open; i < text.length; i++) {
+ if (text[i] === "(") depth++;
+ else if (text[i] === ")" && --depth === 0) return text.slice(open, i + 1);
+ }
+ return text.slice(open);
+}
+
+test("every spawn in .claude/scripts and .scripts passes windowsHide, or is allowlisted with a reason", () => {
+ const missing: string[] = [];
+ const allowUsed = new Set<string>();
+ for (const file of [...sources(SCRIPTS), ...sources(join(REPO, ".scripts"))]) {
+ const rel = relative(REPO, file).replaceAll("\\", "/");
+ // Comment lines are dropped (a doc comment may quote a spawn); code lines
+ // are kept whole, since a URL inside a call holds "//".
+ const code = readFileSync(file, "utf8")
+ .split("\n")
+ .map((line) => (/^\s*(\/\/|\*|\/\*)/.test(line) ? "" : line))
+ .join("\n");
+ for (const m of code.matchAll(spawnPattern(code))) {
+ const call = callText(code, m.index! + m[0].length - 1);
+ if (/windowsHide/.test(call)) continue;
+ const allowed = ALLOWED.find((a) => a.file === rel && call.includes(a.call));
+ if (allowed) {
+ allowUsed.add(`${allowed.file} ${allowed.call}`);
+ continue;
+ }
+ const line = code.slice(0, m.index).split("\n").length;
+ missing.push(`${rel}:${line} ${m[1]}(…) has no windowsHide`);
+ }
+ }
+ assert.deepEqual(missing, [], `pass windowsHide: true, or allowlist the call with its reason:\n${missing.join("\n")}`);
+ // An allowlist entry that matches nothing has outlived its spawn.
+ assert.deepEqual(
+ ALLOWED.filter((a) => !allowUsed.has(`${a.file} ${a.call}`)).map((a) => a.file),
+ [],
+ "remove allowlist entries that no longer match a spawn",
+ );
+});
diff --git a/.claude/scripts/tidy-fix.ts b/.claude/scripts/tidy-fix.ts
index 3ed6578..c3e6da4 100644
--- a/.claude/scripts/tidy-fix.ts
+++ b/.claude/scripts/tidy-fix.ts
@@ -145,6 +145,7 @@ function moveTracked(
const git = spawnSync("git", ["mv", relSrc, relDest], {
cwd: vaultRoot,
encoding: "utf-8",
+ windowsHide: true,
});
if (git.status === 0) return true;
try {
diff --git a/.claude/scripts/upgrade-plan.ts b/.claude/scripts/upgrade-plan.ts
index 640c81d..1aeef6a 100644
--- a/.claude/scripts/upgrade-plan.ts
+++ b/.claude/scripts/upgrade-plan.ts
@@ -67,7 +67,7 @@ function fail(message: string): never {
* back to `shardmind` on PATH through the shell.
*/
function shardmindCommand(args: readonly string[]): { cmd: string; args: string[]; shell: boolean } {
- const root = spawnSync("npm root -g", { shell: true, encoding: "utf8", timeout: 10_000 }).stdout?.trim() ?? "";
+ const root = spawnSync("npm root -g", { shell: true, encoding: "utf8", timeout: 10_000, windowsHide: true }).stdout?.trim() ?? "";
const entry = root ? join(root, "shardmind", "dist", "cli.js") : "";
if (entry && existsSync(entry)) return { cmd: process.execPath, args: [entry, ...args], shell: false };
// No argument here comes from outside this script except the source ref,
@@ -85,6 +85,7 @@ function shardmind<T>(vault: string, args: readonly string[]): ShardmindEnvelope
timeout: 300_000,
input: "",
env: { ...process.env, CI: "true" },
+ windowsHide: true,
});
try {
return JSON.parse(r.stdout) as ShardmindEnvelope<T>;
@@ -111,6 +112,7 @@ function cloneRelease(source: string, version: string): string {
const r = spawnSync("git", ["clone", "-q", "--depth", "1", "--branch", `v${version}`, `https://github.com/${repo}`, dir], {
encoding: "utf8",
timeout: 120_000,
+ windowsHide: true,
});
if (r.status !== 0) fail(`could not fetch ${repo} v${version}: ${r.stderr.slice(0, 300)}`);
return dir;
@@ -119,7 +121,7 @@ function cloneRelease(source: string, version: string): string {
/** The newest stable `vX.Y.Z` tag of `source`. */
function latestRelease(source: string): string {
const repo = source.replace(/^github:/, "").replace(/[#@].*$/, "");
- const r = spawnSync("git", ["ls-remote", "--tags", `https://github.com/${repo}`], { encoding: "utf8", timeout: 60_000 });
+ const r = spawnSync("git", ["ls-remote", "--tags", `https://github.com/${repo}`], { encoding: "utf8", timeout: 60_000, windowsHide: true });
const tags = [...r.stdout.matchAll(/refs\/tags\/v(\d+)\.(\d+)\.(\d+)$/gm)].map((m) => [Number(m[1]), Number(m[2]), Number(m[3])] as const);
if (tags.length === 0) fail(`no release tags found for ${repo}`);
tags.sort((a, b) => b[0] - a[0] || b[1] - a[1] || b[2] - a[2]);
@@ -136,7 +138,7 @@ function main(): void {
const vault = resolveProjectDir(process.cwd());
const v = shardmindCommand(["--version"]);
- const ver = spawnSync(v.cmd, v.args, { shell: v.shell, encoding: "utf8", timeout: 60_000 });
+ const ver = spawnSync(v.cmd, v.args, { shell: v.shell, encoding: "utf8", timeout: 60_000, windowsHide: true });
if (ver.status !== 0) fail("ShardMind is not installed. Install it (npm i -g shardmind) or use the manual migration in /om-vault-upgrade.");
if (!versionAtLeast(ver.stdout, [0, 2, 1])) fail(`ShardMind ${ver.stdout.trim()} is too old; 0.2.1 or later is needed (--json, and an adopt that keeps a clone's .shardmind/ files if it fails). Run: npm i -g shardmind@latest`);