Lines 1-31javascript
2// shine-code-submit hook 平台分发器(.cjs 强制 CommonJS,兼容所有 node,不依赖 package.json)。
3// Claude Code 经 hooks.json 以 `node launcher.cjs <Event>` 调用(exec form,不经 shell)。
4// 优先 spawn 同目录 bin/<plat>-<arch>/hook[.exe](二进制模式,本机 build 产物);
5// 不存在则 bun run src/hook/main.ts(源码模式)。源码模式需要 Bun——若没装,首次自动安装
6// (npm i -g bun → 失败回退官方脚本)。退出码恒 0——绝不影响 Claude Code 主进程。
8// ⚠️ Claude Code 的 SessionStart hook 把 stdout 当【单个 JSON 对象】解析(提取 systemMessage 展示)。
9// 所以:① 进度/提示绝不能写 stdout(混入纯文本会让整个 stdout JSON 解析失败、链接也不显示)——走 stderr + 日志。
10// ② 装完 Bun 后,把「安装完成」提示与 hook 产出的 Dashboard 链接【合并成一条 systemMessage】发 stdout,
11// 确保交互式 claude 里一定能看到(systemMessage 字段已被验证会显示)。
12const { spawn, spawnSync } = require("node:child_process");
13const readline = require("node:readline");
HighChild Process
Package source references child process execution.
bin/launcher.cjsView on unpkg · L11 14const { existsSync, mkdirSync, appendFileSync } = require("node:fs");
15const { join } = require("node:path");
16const { homedir } = require("node:os");
18const here = __dirname; // .../bin/
19const plat = process.platform === "win32" ? "windows" : process.platform; // darwin | linux | windows
HighSandbox Evasion Gated Capability
Source gates dangerous network, credential, or execution behavior behind CI, host, platform, time, or geo fingerprint checks.
bin/launcher.cjsView on unpkg · L1 20const arch = process.arch; // x64 | arm64
21const ext = process.platform === "win32" ? ".exe" : "";
22const hookBin = join(here, `${plat}-${arch}`, `hook${ext}`);
23const hookSrc = join(here, "..", "src", "hook", "main.ts"); // 源码模式入口
25const argv = process.argv.slice(2);
27const SHELL = process.platform === "win32";
29/** 找 bun:先 PATH,再常见安装位置(官方脚本装到 ~/.bun/bin,npm -g 装到全局 bin)。 */
31 // shell 模式用单字符串(避免 Node 的 "args + shell:true" 弃用警告污染 stderr)