From b4e7aa471a6337205285c377f9a72ff96e9b6cef Mon Sep 17 00:00:00 2001 From: Christian Nennemann Date: Thu, 2 Apr 2026 19:36:38 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20rewrite=20hook=20in=20pure=20node=20?= =?UTF-8?q?=E2=80=94=20no=20bash/awk/sed=20portability=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hooks/session-start | 65 +++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/hooks/session-start b/hooks/session-start index b68f242..8a4cb27 100755 --- a/hooks/session-start +++ b/hooks/session-start @@ -1,41 +1,32 @@ -#!/usr/bin/env bash -# SessionStart hook for ArcheFlow plugin. -# Injects the using-archeflow skill as additional context. +#!/usr/bin/env node +// SessionStart hook for ArcheFlow plugin. +// Injects the using-archeflow skill as additional context. -PLUGIN_ROOT="$(cd "$(dirname "$0")/.." 2>/dev/null && pwd)" || { - echo '{}' - exit 0 -} +const fs = require("fs"); +const path = require("path"); -SKILL_FILE="${PLUGIN_ROOT}/skills/using-archeflow/SKILL.md" +try { + const pluginRoot = path.resolve(__dirname, ".."); + const skillFile = path.join(pluginRoot, "skills", "using-archeflow", "SKILL.md"); -if [ ! -f "$SKILL_FILE" ]; then - echo '{}' - exit 0 -fi - -# Strip YAML frontmatter (everything between first two --- lines) -CONTENT=$(awk 'BEGIN{skip=0} /^---$/{skip++; next} skip>=2{print}' "$SKILL_FILE" 2>/dev/null) || { - echo '{}' - exit 0 -} - -if [ -z "$CONTENT" ]; then - echo '{}' - exit 0 -fi - -# JSON-escape and output -if command -v node &>/dev/null; then - node -e ' - const content = require("fs").readFileSync(0, "utf8"); - console.log(JSON.stringify({ hookSpecificOutput: { additionalContext: content } })); - ' <<< "$CONTENT" -else - # Portable fallback - ESCAPED=$(printf '%s' "$CONTENT" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e ':a;N;$!ba;s/\n/\\n/g' 2>/dev/null) || { - echo '{}' - exit 0 + if (!fs.existsSync(skillFile)) { + console.log("{}"); + process.exit(0); } - printf '{"hookSpecificOutput":{"additionalContext":"%s"}}' "$ESCAPED" -fi + + const raw = fs.readFileSync(skillFile, "utf8"); + + // Strip YAML frontmatter + const stripped = raw.replace(/^---\n[\s\S]*?\n---\n?/, ""); + + if (!stripped.trim()) { + console.log("{}"); + process.exit(0); + } + + console.log(JSON.stringify({ + hookSpecificOutput: { additionalContext: stripped } + })); +} catch (e) { + console.log("{}"); +}