Files
wehub-resource-sync d48cda4081
CI / Test (ubuntu-latest, Node 18.x, bun) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, npm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, pnpm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, yarn) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 20.x, bun) (push) Failing after 17m13s
CI / Test (ubuntu-latest, Node 20.x, npm) (push) Failing after 18m42s
CI / Test (ubuntu-latest, Node 20.x, pnpm) (push) Failing after 15m0s
CI / Test (ubuntu-latest, Node 20.x, yarn) (push) Failing after 49m44s
CI / Test (ubuntu-latest, Node 22.x, bun) (push) Failing after 51m55s
CI / Test (ubuntu-latest, Node 22.x, pnpm) (push) Failing after 21m57s
CI / Test (ubuntu-latest, Node 22.x, npm) (push) Failing after 37m39s
CI / Test (ubuntu-latest, Node 22.x, yarn) (push) Failing after 34m7s
CI / Validate Components (push) Failing after 37m15s
CI / Python Tests (push) Failing after 10m1s
CI / Security Scan (push) Failing after 10m1s
CI / Lint (push) Failing after 17m12s
CI / Coverage (push) Failing after 20m19s
CI / Test (macos-latest, Node 18.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, yarn) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:55 +08:00

86 lines
2.9 KiB
JavaScript

#!/usr/bin/env node
'use strict';
/**
* session-start-bootstrap.js
*
* Bootstrap loader for the ECC SessionStart hook.
*
* Problem this solves: the previous approach embedded this logic as an inline
* `node -e "..."` string inside hooks.json. Characters like `!` (used in
* `!org.isDirectory()`) can trigger bash history expansion or other shell
* interpretation issues depending on the environment, causing
* "SessionStart:startup hook error" to appear in the Claude Code CLI header.
*
* By extracting to a standalone file, the shell never sees the JavaScript
* source and the `!` characters are safe. Behaviour is otherwise identical.
*
* How it works:
* 1. Reads the raw JSON event from stdin (passed by Claude Code).
* 2. Resolves the ECC plugin root directory (via CLAUDE_PLUGIN_ROOT env var
* or a set of well-known fallback paths).
* 3. Delegates to `scripts/hooks/run-with-flags.js` with the `session:start`
* event, which applies hook-profile gating and then runs session-start.js.
* 4. Passes stdout/stderr through and forwards the child exit code.
* 5. If the plugin root cannot be found, emits a warning and passes stdin
* through unchanged so Claude Code can continue normally.
*/
const fs = require('fs');
const path = require('path');
const { spawnSync } = require('child_process');
const { resolveEccRoot } = require('../lib/resolve-ecc-root');
// Read the raw JSON event from stdin
const raw = fs.readFileSync(0, 'utf8');
// Path (relative to plugin root) to the hook runner
const rel = path.join('scripts', 'hooks', 'run-with-flags.js');
// Resolve the ECC plugin root via the shared resolver, probing for the runner
// so a valid root is one that actually contains run-with-flags.js.
const root = resolveEccRoot({ probe: rel });
const script = path.join(root, rel);
if (fs.existsSync(script)) {
const result = spawnSync(
process.execPath,
[script, 'session:start', 'scripts/hooks/session-start.js', 'minimal,standard,strict'],
{
input: raw,
encoding: 'utf8',
env: process.env,
cwd: process.cwd(),
timeout: 30000,
}
);
const stdout = typeof result.stdout === 'string' ? result.stdout : '';
if (stdout) {
process.stdout.write(stdout);
} else {
process.stdout.write(raw);
}
if (result.stderr) {
process.stderr.write(result.stderr);
}
if (result.error || result.status === null || result.signal) {
const reason = result.error
? result.error.message
: result.signal
? 'signal ' + result.signal
: 'missing exit status';
process.stderr.write('[SessionStart] ERROR: session-start hook failed: ' + reason + '\n');
process.exit(1);
}
process.exit(Number.isInteger(result.status) ? result.status : 0);
}
process.stderr.write(
'[SessionStart] WARNING: could not resolve ECC plugin root; skipping session-start hook\n'
);
process.stdout.write(raw);