tools: add repl-block, check-tangle; move existing tools into memex
New tools (projects/<tool>/ — standalone, git-committed): - repl-block: extract and pipe lisp blocks from org files to the REPL - check-tangle: tangle + compile in one step, reports errors Existing tools moved from ~/.opencode/bin/ into memex (survives reinstalls): - repl, tangle, org-eval, verify-repl AGENTS.md updated: - Tool reference table with all 7 tools - Package reference table for passepartout and cl-tty - Updated tangle command to use project-local tools .opencode/commands/ added: check-parens, repl-block, check-tangle commands
This commit is contained in:
62
projects/check-tangle/check-tangle
Executable file
62
projects/check-tangle/check-tangle
Executable file
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env bash
|
||||
# Tangle an .org file and compile the resulting .lisp with SBCL.
|
||||
# Reports the first compile error with line numbers.
|
||||
#
|
||||
# Usage: check-tangle <file.org>
|
||||
# Exit 0 if compile succeeds, 1 if tangled or compilation fails
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "Usage: check-tangle <file.org>" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
ORG_FILE="$1"
|
||||
|
||||
if [ ! -f "$ORG_FILE" ]; then
|
||||
echo "Error: File not found: $ORG_FILE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Determine the tangle target from the org file
|
||||
TANGLE=$(grep -m1 'header-args.*:tangle' "$ORG_FILE" | sed 's/.*:tangle //' | head -1 || true)
|
||||
if [ -z "$TANGLE" ]; then
|
||||
echo "SKIP: $ORG_FILE — no :tangle header" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Resolve relative tangle path
|
||||
ORG_DIR=$(dirname "$ORG_FILE")
|
||||
LISP_FILE=$(cd "$ORG_DIR" && realpath -m "$TANGLE" 2>/dev/null || echo "$ORG_DIR/$TANGLE")
|
||||
|
||||
echo "Tangling: $ORG_FILE → $LISP_FILE" >&2
|
||||
|
||||
# Tangle using opencode's tangle tool
|
||||
TANGLE_CMD=$(command -v tangle 2>/dev/null || echo "/home/user/.opencode/bin/tangle")
|
||||
if ! "$TANGLE_CMD" "$ORG_FILE" 2>/dev/null; then
|
||||
echo "FAIL: Tangling $ORG_FILE failed" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$LISP_FILE" ]; then
|
||||
echo "SKIP: Tangle target $LISP_FILE not found after tangling" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Compiling: $LISP_FILE" >&2
|
||||
|
||||
# Compile with SBCL, capturing errors
|
||||
OUTPUT=$(sbcl --noinform --no-userinit --disable-debugger --quit \
|
||||
--eval "(handler-case
|
||||
(progn (compile-file \"$LISP_FILE\") (print :OK))
|
||||
(error (c) (print c) (sb-ext:exit :code 1)))" 2>&1 || true)
|
||||
|
||||
if echo "$OUTPUT" | grep -q ":OK"; then
|
||||
echo "OK: $ORG_FILE compiles cleanly" >&2
|
||||
exit 0
|
||||
else
|
||||
echo "$OUTPUT" | grep -v '^;' | grep -v '^$' | head -5
|
||||
echo "FAIL: $ORG_FILE — compilation error" >&2
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user