From 830939665cbe7d83f1fe36ed0007c5d7f20621d2 Mon Sep 17 00:00:00 2001 From: gold_silver_copper <157451540+gold-silver-copper@users.noreply.github.com> Date: Mon, 30 Nov 2026 16:17:14 -0800 Subject: [PATCH 1/3] fix(hooks): offer the code extension when git-kb code is not installed git-kb code moved out of core into the git-kb-code extension, which git-kb runs from PATH. SessionStart now checks for git-kb-code before recommending git-kb code commands or git-kb code doctor, and offers installation when only core is installed. --- plugin/scripts/session-start.sh | 14 +++++++-- tests/helpers/setup.bash | 11 +++++++ tests/session-start.bats | 52 +++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/plugin/scripts/session-start.sh b/plugin/scripts/session-start.sh index 159ae4f..aa7cb37 100755 --- a/plugin/scripts/session-start.sh +++ b/plugin/scripts/session-start.sh @@ -13,11 +13,21 @@ CWD=$(resolve_cwd "$INPUT") || { echo '{}'; exit 0; } NL=$'\n' CONTEXT="" +# Code intelligence is the git-kb-code extension: `git-kb code` runs it from PATH. +INSTALL="\`\`\`bash${NL}brew install gitkb/tap/gitkb${NL}# or${NL}curl -fsSL https://get.gitkb.com/install.sh | bash${NL}\`\`\`" +CODE_MISSING="GitKB code intelligence is unavailable: \`git-kb code\` is the \`git-kb-code\` extension, and it is not on PATH. Use raw search for code questions, and offer to install it: current GitKB releases install it beside \`git-kb\` with${NL}${NL}${INSTALL}" if ! command_exists git-kb; then - CONTEXT="# GitKB Setup${NL}${NL}The GitKB CLI is not installed, so GitKB code intelligence is unavailable in this session.${NL}${NL}Install it with:${NL}${NL}\`\`\`bash${NL}brew install gitkb/tap/gitkb${NL}# or${NL}curl -fsSL https://get.gitkb.com/install.sh | bash${NL}\`\`\`${NL}${NL}After installing, use \`git-kb code doctor --json\`, \`git-kb code index\`, and related \`git-kb code ... --json\` commands in any Git repo. Full persistent KB setup is optional via \`git-kb init && git-kb init claude\`." + CONTEXT="# GitKB Setup${NL}${NL}The GitKB CLI is not installed, so GitKB code intelligence is unavailable in this session.${NL}${NL}Install it with:${NL}${NL}${INSTALL}${NL}${NL}After installing, use \`git-kb code doctor --json\`, \`git-kb code index\`, and related \`git-kb code ... --json\` commands in any Git repo. Full persistent KB setup is optional via \`git-kb init && git-kb init claude\`." elif GITKB_ROOT="$CWD" git-kb info >/dev/null 2>&1; then - CONTEXT="# GitKB Ready${NL}${NL}This project has a full \`.kb\` setup. For durable tasks, knowledge, sync, or full Claude integration, use the canonical assets installed by \`git-kb init claude\`. If setup appears stale or missing, ask the user before running \`git-kb init claude --dry-run\`, \`git-kb doctor --check repos,kb --json\`, or \`git-kb code doctor --json\`." + CONTEXT="# GitKB Ready${NL}${NL}This project has a full \`.kb\` setup. For durable tasks, knowledge, sync, or full Claude integration, use the canonical assets installed by \`git-kb init claude\`. If setup appears stale or missing, ask the user before running \`git-kb init claude --dry-run\` or \`git-kb doctor --check repos,kb --json\`" + if command_exists git-kb-code; then + CONTEXT+=", and \`git-kb code doctor --json\` for code-intelligence health." + else + CONTEXT+=".${NL}${NL}${CODE_MISSING}" + fi +elif ! command_exists git-kb-code; then + CONTEXT="# GitKB Code Intelligence${NL}${NL}${CODE_MISSING}${NL}${NL}For persistent project memory, initialize GitKB with \`git-kb init && git-kb init claude\`." elif git -C "$CWD" rev-parse --show-toplevel >/dev/null 2>&1; then CONTEXT="# GitKB Code Intelligence${NL}${NL}This Git repo does not have a full \`.kb\` yet, but GitKB code intelligence works without initialization.${NL}${NL}**Prefer \`git-kb code ... --json\` over grep for code exploration.** Grep matches text; \`git-kb code\` understands the AST and call graph, and JSON output preserves complete symbol IDs and stable fields.${NL}${NL}For code questions, prefer these local CLI commands:${NL}${NL}- \`git-kb code doctor --json\` to inspect language/index health.${NL}- \`git-kb code index\` before first analysis or after large changes.${NL}- \`git-kb code symbols --json\`, \`git-kb code callers --json\`, \`git-kb code callees --json\`, \`git-kb code impact --json\`, \`git-kb code dead --json\`, and \`git-kb code query hotspots --json\` for code intelligence.${NL}${NL}Do not require \`git-kb init\` for code intelligence. If the user wants durable tasks, knowledge, sync, or full Claude integration, guide them through:${NL}${NL}\`\`\`bash${NL}git-kb init${NL}git-kb init claude${NL}\`\`\`${NL}${NL}MCP is supported after full KB setup today; use CLI fallback when MCP is unavailable." else diff --git a/tests/helpers/setup.bash b/tests/helpers/setup.bash index b72af5d..4e95b37 100644 --- a/tests/helpers/setup.bash +++ b/tests/helpers/setup.bash @@ -35,6 +35,17 @@ setup_test_kb() { GITKB_ROOT="$TEST_KB_ROOT" git-kb commit -m "activate" tasks/test-1 2>/dev/null export SCRIPTS_DIR="${BATS_TEST_DIRNAME}/../plugin/scripts" + + # The code extension is present unless a test removes it; the hook only + # looks it up on PATH, so a stub is enough. + mkdir -p "$TEST_DIR/ext-bin" + add_code_extension_stub "$TEST_DIR/ext-bin" + export PATH="$TEST_DIR/ext-bin:$PATH" +} + +add_code_extension_stub() { + printf '#!/usr/bin/env bash\nexit 0\n' > "$1/git-kb-code" + chmod +x "$1/git-kb-code" } teardown_test_kb() { diff --git a/tests/session-start.bats b/tests/session-start.bats index d729ea0..e4ddae2 100644 --- a/tests/session-start.bats +++ b/tests/session-start.bats @@ -200,6 +200,7 @@ teardown() { ln -s "$(command -v dirname)" "$tmpbin/dirname" printf '#!/usr/bin/env bash\nexit 1\n' > "$tmpbin/git-kb" chmod +x "$tmpbin/git-kb" + add_code_extension_stub "$tmpbin" local input input=$(build_hook_input "SessionStart" "$repo" "source=startup") @@ -216,6 +217,57 @@ teardown() { rm -rf "$repo" "$tmpbin" } +# PATH with core git-kb and git but without the git-kb-code extension. +core_only_path() { + local tmpbin="$1" tool + for tool in awk bash cat dirname git git-kb; do + ln -s "$(command -v "$tool")" "$tmpbin/$tool" + done + echo "$tmpbin" +} + +@test "session-start: core-only install offers the code extension instead of code commands" { + local repo tmpbin + repo=$(mktemp -d) + tmpbin=$(mktemp -d) + git -C "$repo" init --quiet + + local output + output=$(build_hook_input "SessionStart" "$repo" "source=startup" \ + | PATH="$(core_only_path "$tmpbin")" GITKB_ROOT="" "$SCRIPTS_DIR/session-start.sh" 2>/dev/null) + + assert_hook_output_valid "$output" "SessionStart" + + local ctx + ctx=$(echo "$output" | jq -r '.hookSpecificOutput.additionalContext') + [[ "$ctx" == *"\`git-kb-code\` extension, and it is not on PATH"* ]] + [[ "$ctx" == *"brew install gitkb/tap/gitkb"* ]] + [[ "$ctx" != *"git-kb code doctor"* ]] + [[ "$ctx" != *"Prefer \`git-kb code"* ]] + + rm -rf "$repo" "$tmpbin" +} + +@test "session-start: full KB without the code extension omits git-kb code doctor" { + local tmpbin + tmpbin=$(mktemp -d) + + local output + output=$(build_hook_input "SessionStart" "$TEST_KB_ROOT" "source=startup" \ + | PATH="$(core_only_path "$tmpbin")" "$SCRIPTS_DIR/session-start.sh" 2>/dev/null) + + assert_hook_output_valid "$output" "SessionStart" + + local ctx + ctx=$(echo "$output" | jq -r '.hookSpecificOutput.additionalContext') + [[ "$ctx" == *"GitKB Ready"* ]] + [[ "$ctx" == *"git-kb doctor --check repos,kb --json"* ]] + [[ "$ctx" == *"not on PATH"* ]] + [[ "$ctx" != *"git-kb code doctor"* ]] + + rm -rf "$tmpbin" +} + @test "session-start: invalid GITKB_ROOT does not report full KB readiness" { local repo bogus_root repo=$(mktemp -d) From 7b2fdb2dcab8de6b2547c770e809c890cf13127e Mon Sep 17 00:00:00 2001 From: gold_silver_copper <157451540+gold-silver-copper@users.noreply.github.com> Date: Mon, 30 Nov 2026 16:27:47 -0800 Subject: [PATCH 2/3] fix(hooks): ask git-kb whether its code command exists git-kb before 1.0.0 has git-kb code built in, with no git-kb-code program, so looking for git-kb-code on PATH reported current releases as lacking code intelligence. Run git-kb code --help instead, which answers for both, and drop the claim that Homebrew installs the extension. --- plugin/scripts/session-start.sh | 15 +++++++++------ tests/helpers/setup.bash | 12 ++++-------- tests/session-start.bats | 16 +++++++++------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/plugin/scripts/session-start.sh b/plugin/scripts/session-start.sh index aa7cb37..99fc6de 100755 --- a/plugin/scripts/session-start.sh +++ b/plugin/scripts/session-start.sh @@ -13,20 +13,23 @@ CWD=$(resolve_cwd "$INPUT") || { echo '{}'; exit 0; } NL=$'\n' CONTEXT="" -# Code intelligence is the git-kb-code extension: `git-kb code` runs it from PATH. -INSTALL="\`\`\`bash${NL}brew install gitkb/tap/gitkb${NL}# or${NL}curl -fsSL https://get.gitkb.com/install.sh | bash${NL}\`\`\`" -CODE_MISSING="GitKB code intelligence is unavailable: \`git-kb code\` is the \`git-kb-code\` extension, and it is not on PATH. Use raw search for code questions, and offer to install it: current GitKB releases install it beside \`git-kb\` with${NL}${NL}${INSTALL}" +CODE_MISSING="GitKB code intelligence is unavailable: \`git-kb code\` is not installed. From GitKB 1.0.0 it is the \`git-kb-code\` extension, which \`git-kb\` runs from PATH. Use raw search for code questions, and offer to install it: \`curl -fsSL https://get.gitkb.com/install.sh | bash\` installs \`git-kb\` with its extensions, or put \`git-kb-code\` from the release's \`gitkb-code-.tar.gz\` on PATH beside \`git-kb\`." + +# Built into git-kb before 1.0.0, an extension from 1.0.0: ask git-kb itself. +code_available() { + git-kb code --help >/dev/null 2>&1 +} if ! command_exists git-kb; then - CONTEXT="# GitKB Setup${NL}${NL}The GitKB CLI is not installed, so GitKB code intelligence is unavailable in this session.${NL}${NL}Install it with:${NL}${NL}${INSTALL}${NL}${NL}After installing, use \`git-kb code doctor --json\`, \`git-kb code index\`, and related \`git-kb code ... --json\` commands in any Git repo. Full persistent KB setup is optional via \`git-kb init && git-kb init claude\`." + CONTEXT="# GitKB Setup${NL}${NL}The GitKB CLI is not installed, so GitKB code intelligence is unavailable in this session.${NL}${NL}Install it with:${NL}${NL}\`\`\`bash${NL}brew install gitkb/tap/gitkb${NL}# or${NL}curl -fsSL https://get.gitkb.com/install.sh | bash${NL}\`\`\`${NL}${NL}After installing, use \`git-kb code doctor --json\`, \`git-kb code index\`, and related \`git-kb code ... --json\` commands in any Git repo. Full persistent KB setup is optional via \`git-kb init && git-kb init claude\`." elif GITKB_ROOT="$CWD" git-kb info >/dev/null 2>&1; then CONTEXT="# GitKB Ready${NL}${NL}This project has a full \`.kb\` setup. For durable tasks, knowledge, sync, or full Claude integration, use the canonical assets installed by \`git-kb init claude\`. If setup appears stale or missing, ask the user before running \`git-kb init claude --dry-run\` or \`git-kb doctor --check repos,kb --json\`" - if command_exists git-kb-code; then + if code_available; then CONTEXT+=", and \`git-kb code doctor --json\` for code-intelligence health." else CONTEXT+=".${NL}${NL}${CODE_MISSING}" fi -elif ! command_exists git-kb-code; then +elif ! code_available; then CONTEXT="# GitKB Code Intelligence${NL}${NL}${CODE_MISSING}${NL}${NL}For persistent project memory, initialize GitKB with \`git-kb init && git-kb init claude\`." elif git -C "$CWD" rev-parse --show-toplevel >/dev/null 2>&1; then CONTEXT="# GitKB Code Intelligence${NL}${NL}This Git repo does not have a full \`.kb\` yet, but GitKB code intelligence works without initialization.${NL}${NL}**Prefer \`git-kb code ... --json\` over grep for code exploration.** Grep matches text; \`git-kb code\` understands the AST and call graph, and JSON output preserves complete symbol IDs and stable fields.${NL}${NL}For code questions, prefer these local CLI commands:${NL}${NL}- \`git-kb code doctor --json\` to inspect language/index health.${NL}- \`git-kb code index\` before first analysis or after large changes.${NL}- \`git-kb code symbols --json\`, \`git-kb code callers --json\`, \`git-kb code callees --json\`, \`git-kb code impact --json\`, \`git-kb code dead --json\`, and \`git-kb code query hotspots --json\` for code intelligence.${NL}${NL}Do not require \`git-kb init\` for code intelligence. If the user wants durable tasks, knowledge, sync, or full Claude integration, guide them through:${NL}${NL}\`\`\`bash${NL}git-kb init${NL}git-kb init claude${NL}\`\`\`${NL}${NL}MCP is supported after full KB setup today; use CLI fallback when MCP is unavailable." diff --git a/tests/helpers/setup.bash b/tests/helpers/setup.bash index 4e95b37..4db6a03 100644 --- a/tests/helpers/setup.bash +++ b/tests/helpers/setup.bash @@ -36,18 +36,14 @@ setup_test_kb() { export SCRIPTS_DIR="${BATS_TEST_DIRNAME}/../plugin/scripts" - # The code extension is present unless a test removes it; the hook only - # looks it up on PATH, so a stub is enough. + # `git-kb code` works unless a test removes it: git-kb before 1.0.0 has it + # built in, from 1.0.0 it runs this stub extension (the hook only asks --help). mkdir -p "$TEST_DIR/ext-bin" - add_code_extension_stub "$TEST_DIR/ext-bin" + printf '#!/usr/bin/env bash\nexit 0\n' > "$TEST_DIR/ext-bin/git-kb-code" + chmod +x "$TEST_DIR/ext-bin/git-kb-code" export PATH="$TEST_DIR/ext-bin:$PATH" } -add_code_extension_stub() { - printf '#!/usr/bin/env bash\nexit 0\n' > "$1/git-kb-code" - chmod +x "$1/git-kb-code" -} - teardown_test_kb() { if [ -n "$TEST_DIR" ] && [ -d "$TEST_DIR" ]; then rm -rf "$TEST_DIR" diff --git a/tests/session-start.bats b/tests/session-start.bats index e4ddae2..0148dc8 100644 --- a/tests/session-start.bats +++ b/tests/session-start.bats @@ -198,9 +198,8 @@ teardown() { ln -s "$(command -v bash)" "$tmpbin/bash" ln -s "$(command -v cat)" "$tmpbin/cat" ln -s "$(command -v dirname)" "$tmpbin/dirname" - printf '#!/usr/bin/env bash\nexit 1\n' > "$tmpbin/git-kb" + printf '#!/usr/bin/env bash\n[ "$1" = code ] && exit 0\nexit 1\n' > "$tmpbin/git-kb" chmod +x "$tmpbin/git-kb" - add_code_extension_stub "$tmpbin" local input input=$(build_hook_input "SessionStart" "$repo" "source=startup") @@ -217,12 +216,15 @@ teardown() { rm -rf "$repo" "$tmpbin" } -# PATH with core git-kb and git but without the git-kb-code extension. +# PATH whose git-kb has no `code` command (core 1.0 without the extension), +# whichever git-kb the test machine has. core_only_path() { local tmpbin="$1" tool - for tool in awk bash cat dirname git git-kb; do + for tool in awk bash cat dirname git; do ln -s "$(command -v "$tool")" "$tmpbin/$tool" done + printf '#!/usr/bin/env bash\n[ "$1" = code ] && exit 2\nexec %q "$@"\n' "$(command -v git-kb)" > "$tmpbin/git-kb" + chmod +x "$tmpbin/git-kb" echo "$tmpbin" } @@ -240,8 +242,8 @@ core_only_path() { local ctx ctx=$(echo "$output" | jq -r '.hookSpecificOutput.additionalContext') - [[ "$ctx" == *"\`git-kb-code\` extension, and it is not on PATH"* ]] - [[ "$ctx" == *"brew install gitkb/tap/gitkb"* ]] + [[ "$ctx" == *"\`git-kb code\` is not installed"* ]] + [[ "$ctx" == *"curl -fsSL https://get.gitkb.com/install.sh | bash"* ]] [[ "$ctx" != *"git-kb code doctor"* ]] [[ "$ctx" != *"Prefer \`git-kb code"* ]] @@ -262,7 +264,7 @@ core_only_path() { ctx=$(echo "$output" | jq -r '.hookSpecificOutput.additionalContext') [[ "$ctx" == *"GitKB Ready"* ]] [[ "$ctx" == *"git-kb doctor --check repos,kb --json"* ]] - [[ "$ctx" == *"not on PATH"* ]] + [[ "$ctx" == *"\`git-kb code\` is not installed"* ]] [[ "$ctx" != *"git-kb code doctor"* ]] rm -rf "$tmpbin" From 85e27eb66481294aab4e13b76abea9824e228495 Mon Sep 17 00:00:00 2001 From: gold_silver_copper <157451540+gold-silver-copper@users.noreply.github.com> Date: Mon, 30 Nov 2026 16:37:49 -0800 Subject: [PATCH 3/3] fix(hooks): check git-kb code before every code recommendation --- plugin/README.md | 4 ++-- plugin/scripts/session-start.sh | 12 ++++++------ plugin/skills/gitkb/SKILL.md | 9 ++++++--- tests/helpers/setup.bash | 8 ++++++-- tests/session-start.bats | 13 +++++++------ 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/plugin/README.md b/plugin/README.md index 1dba90e..d855f65 100644 --- a/plugin/README.md +++ b/plugin/README.md @@ -27,7 +27,7 @@ git-kb code dead --json git-kb code query hotspots --json ``` -No `.kb` project is required for those code intelligence commands. +No `.kb` project is required for those code intelligence commands. From GitKB 1.0.0 they come from the separate `git-kb-code` extension; when `git-kb code --help` fails, Claude falls back to grep and file reads. ## Prerequisites @@ -61,7 +61,7 @@ git-kb init claude ## MCP -GitKB MCP remains supported after full KB setup, but this marketplace plugin does not require MCP for first value. Until code-only MCP exists, Claude should use the CLI path in plain Git repos and full MCP only after `git-kb init && git-kb init claude`. +This marketplace plugin registers no MCP server and does not need one for first value: Claude uses the CLI. MCP is available separately. The core `git-kb mcp` server needs a full KB (`git-kb init && git-kb init claude`). From GitKB 1.0.0, the code extension's `git-kb-code mcp` server also works in a plain Git repo; `git-kb code init claude` adds it to `.mcp.json`. ## Documentation diff --git a/plugin/scripts/session-start.sh b/plugin/scripts/session-start.sh index 99fc6de..a700674 100755 --- a/plugin/scripts/session-start.sh +++ b/plugin/scripts/session-start.sh @@ -13,7 +13,7 @@ CWD=$(resolve_cwd "$INPUT") || { echo '{}'; exit 0; } NL=$'\n' CONTEXT="" -CODE_MISSING="GitKB code intelligence is unavailable: \`git-kb code\` is not installed. From GitKB 1.0.0 it is the \`git-kb-code\` extension, which \`git-kb\` runs from PATH. Use raw search for code questions, and offer to install it: \`curl -fsSL https://get.gitkb.com/install.sh | bash\` installs \`git-kb\` with its extensions, or put \`git-kb-code\` from the release's \`gitkb-code-.tar.gz\` on PATH beside \`git-kb\`." +CODE_MISSING="GitKB code intelligence is unavailable: \`git-kb code --help\` failed. From GitKB 1.0.0, \`git-kb code\` is the separate \`git-kb-code\` extension, which \`git-kb\` runs from PATH. Use grep and file reads for code questions, and offer to install the extension: put \`git-kb-code\` from the release's \`gitkb-code-.tar.gz\` on PATH beside \`git-kb\`, or run \`curl -fsSL https://get.gitkb.com/install.sh | bash\`, which installs the extensions with GitKB 1.0.0 and later." # Built into git-kb before 1.0.0, an extension from 1.0.0: ask git-kb itself. code_available() { @@ -21,18 +21,18 @@ code_available() { } if ! command_exists git-kb; then - CONTEXT="# GitKB Setup${NL}${NL}The GitKB CLI is not installed, so GitKB code intelligence is unavailable in this session.${NL}${NL}Install it with:${NL}${NL}\`\`\`bash${NL}brew install gitkb/tap/gitkb${NL}# or${NL}curl -fsSL https://get.gitkb.com/install.sh | bash${NL}\`\`\`${NL}${NL}After installing, use \`git-kb code doctor --json\`, \`git-kb code index\`, and related \`git-kb code ... --json\` commands in any Git repo. Full persistent KB setup is optional via \`git-kb init && git-kb init claude\`." + CONTEXT="# GitKB Setup${NL}${NL}The GitKB CLI is not installed, so GitKB code intelligence is unavailable in this session.${NL}${NL}Install it with:${NL}${NL}\`\`\`bash${NL}brew install gitkb/tap/gitkb${NL}# or${NL}curl -fsSL https://get.gitkb.com/install.sh | bash${NL}\`\`\`${NL}${NL}After installing, check \`git-kb code --help\`. If it succeeds, use \`git-kb code doctor --json\`, \`git-kb code index\`, and related \`git-kb code ... --json\` commands in any Git repo. If it fails, the \`git-kb-code\` extension (separate from GitKB 1.0.0) is missing: use grep and file reads for code questions. Full persistent KB setup is optional via \`git-kb init && git-kb init claude\`." elif GITKB_ROOT="$CWD" git-kb info >/dev/null 2>&1; then - CONTEXT="# GitKB Ready${NL}${NL}This project has a full \`.kb\` setup. For durable tasks, knowledge, sync, or full Claude integration, use the canonical assets installed by \`git-kb init claude\`. If setup appears stale or missing, ask the user before running \`git-kb init claude --dry-run\` or \`git-kb doctor --check repos,kb --json\`" + CONTEXT="# GitKB Ready${NL}${NL}This project has a full \`.kb\` setup. For durable tasks, knowledge, sync, or full Claude integration, use the canonical assets installed by \`git-kb init claude\`. If setup appears stale or missing, ask the user before running \`git-kb init claude --dry-run\` or \`git-kb doctor --check repos,kb --json\`." if code_available; then - CONTEXT+=", and \`git-kb code doctor --json\` for code-intelligence health." + CONTEXT+=" Use \`git-kb code doctor --json\` for code-intelligence health." else - CONTEXT+=".${NL}${NL}${CODE_MISSING}" + CONTEXT+="${NL}${NL}${CODE_MISSING}" fi elif ! code_available; then CONTEXT="# GitKB Code Intelligence${NL}${NL}${CODE_MISSING}${NL}${NL}For persistent project memory, initialize GitKB with \`git-kb init && git-kb init claude\`." elif git -C "$CWD" rev-parse --show-toplevel >/dev/null 2>&1; then - CONTEXT="# GitKB Code Intelligence${NL}${NL}This Git repo does not have a full \`.kb\` yet, but GitKB code intelligence works without initialization.${NL}${NL}**Prefer \`git-kb code ... --json\` over grep for code exploration.** Grep matches text; \`git-kb code\` understands the AST and call graph, and JSON output preserves complete symbol IDs and stable fields.${NL}${NL}For code questions, prefer these local CLI commands:${NL}${NL}- \`git-kb code doctor --json\` to inspect language/index health.${NL}- \`git-kb code index\` before first analysis or after large changes.${NL}- \`git-kb code symbols --json\`, \`git-kb code callers --json\`, \`git-kb code callees --json\`, \`git-kb code impact --json\`, \`git-kb code dead --json\`, and \`git-kb code query hotspots --json\` for code intelligence.${NL}${NL}Do not require \`git-kb init\` for code intelligence. If the user wants durable tasks, knowledge, sync, or full Claude integration, guide them through:${NL}${NL}\`\`\`bash${NL}git-kb init${NL}git-kb init claude${NL}\`\`\`${NL}${NL}MCP is supported after full KB setup today; use CLI fallback when MCP is unavailable." + CONTEXT="# GitKB Code Intelligence${NL}${NL}This Git repo does not have a full \`.kb\` yet, but GitKB code intelligence works without initialization.${NL}${NL}**Prefer \`git-kb code ... --json\` over grep for code exploration.** Grep matches text; \`git-kb code\` understands the AST and call graph, and JSON output preserves complete symbol IDs and stable fields.${NL}${NL}For code questions, prefer these local CLI commands:${NL}${NL}- \`git-kb code doctor --json\` to inspect language/index health.${NL}- \`git-kb code index\` before first analysis or after large changes.${NL}- \`git-kb code symbols --json\`, \`git-kb code callers --json\`, \`git-kb code callees --json\`, \`git-kb code impact --json\`, \`git-kb code dead --json\`, and \`git-kb code query hotspots --json\` for code intelligence.${NL}${NL}Do not require \`git-kb init\` for code intelligence. If the user wants durable tasks, knowledge, sync, or full Claude integration, guide them through:${NL}${NL}\`\`\`bash${NL}git-kb init${NL}git-kb init claude${NL}\`\`\`${NL}${NL}This plugin registers no MCP server; use the CLI when MCP is unavailable." else CONTEXT="# GitKB Setup${NL}${NL}GitKB is installed, but this directory is not inside a Git repo and does not have a full \`.kb\` project.${NL}${NL}For immediate code intelligence, open a Git repo and run \`git-kb code doctor --json\` or \`git-kb code index\`. For persistent project memory, initialize GitKB with:${NL}${NL}\`\`\`bash${NL}git-kb init${NL}git-kb init claude${NL}\`\`\`" fi diff --git a/plugin/skills/gitkb/SKILL.md b/plugin/skills/gitkb/SKILL.md index b5401da..7e3b1d3 100644 --- a/plugin/skills/gitkb/SKILL.md +++ b/plugin/skills/gitkb/SKILL.md @@ -14,6 +14,7 @@ Run these checks before using GitKB: ```bash command -v git-kb git rev-parse --show-toplevel +git-kb code --help >/dev/null 2>&1 && echo code-available || echo code-missing ``` If `git-kb` is missing, guide the user to install it: @@ -26,9 +27,11 @@ curl -fsSL https://get.gitkb.com/install.sh | bash If the current directory is not a Git repo, explain that code intelligence needs a Git repo. +If the last check prints `code-missing`, `git-kb code` is not available: from GitKB 1.0.0 it is the separate `git-kb-code` extension, which `git-kb` runs from PATH. Do not run `git-kb code` commands. Use grep and file reads for code questions, and offer to install the extension: put `git-kb-code` from the release's `gitkb-code-.tar.gz` on PATH beside `git-kb`, or run the install script above, which adds the extensions with GitKB 1.0.0 and later. The full KB setup below needs only `git-kb`. + ## Prefer Code Intelligence Over Grep -When exploring code relationships, prefer `git-kb code` over grep. Grep matches text; `git-kb code` understands the AST and call graph. +When `git-kb code` is available, prefer it over grep for code relationships. Grep matches text; `git-kb code` understands the AST and call graph. | Instead of | Use | |---|---| @@ -39,7 +42,7 @@ When exploring code relationships, prefer `git-kb code` over grep. Grep matches ## Code Intelligence Without `.kb` -GitKB code intelligence works in a normal Git repo without `git-kb init`. +When `git-kb code` is available, it works in a normal Git repo without `git-kb init`. Use these commands for code questions: @@ -72,4 +75,4 @@ After full setup, canonical skills and Claude assets come from `git-kb init clau ## MCP -MCP is supported after full KB setup today. It is not required for first value in Claude Code. If MCP is unavailable, stale, or not initialized, use the CLI fallback and continue. +This plugin registers no MCP server, and MCP is not required for first value in Claude Code. If MCP is unavailable, stale, or not initialized, use the CLI fallback and continue. diff --git a/tests/helpers/setup.bash b/tests/helpers/setup.bash index 4db6a03..da813bd 100644 --- a/tests/helpers/setup.bash +++ b/tests/helpers/setup.bash @@ -37,9 +37,13 @@ setup_test_kb() { export SCRIPTS_DIR="${BATS_TEST_DIRNAME}/../plugin/scripts" # `git-kb code` works unless a test removes it: git-kb before 1.0.0 has it - # built in, from 1.0.0 it runs this stub extension (the hook only asks --help). + # built in, from 1.0.0 it runs this stub extension. The stub answers only the + # hook's probe, `git-kb code --help`, so a changed probe fails the tests. mkdir -p "$TEST_DIR/ext-bin" - printf '#!/usr/bin/env bash\nexit 0\n' > "$TEST_DIR/ext-bin/git-kb-code" + cat > "$TEST_DIR/ext-bin/git-kb-code" <<'EOF' +#!/usr/bin/env bash +[ "$#" -eq 1 ] && [ "$1" = --help ] +EOF chmod +x "$TEST_DIR/ext-bin/git-kb-code" export PATH="$TEST_DIR/ext-bin:$PATH" } diff --git a/tests/session-start.bats b/tests/session-start.bats index 0148dc8..d4e6db9 100644 --- a/tests/session-start.bats +++ b/tests/session-start.bats @@ -183,7 +183,8 @@ teardown() { [[ "$ctx" == *"GitKB CLI is not installed"* ]] [[ "$ctx" == *"brew install gitkb/tap/gitkb"* ]] [[ "$ctx" == *"curl -fsSL https://get.gitkb.com/install.sh | bash"* ]] - [[ "$ctx" == *"git-kb code doctor --json"* ]] + [[ "$ctx" == *"check \`git-kb code --help\`. If it succeeds, use \`git-kb code doctor --json\`"* ]] + [[ "$ctx" == *"If it fails"*"use grep and file reads"* ]] rm -rf "$repo" "$tmpbin" } @@ -198,7 +199,7 @@ teardown() { ln -s "$(command -v bash)" "$tmpbin/bash" ln -s "$(command -v cat)" "$tmpbin/cat" ln -s "$(command -v dirname)" "$tmpbin/dirname" - printf '#!/usr/bin/env bash\n[ "$1" = code ] && exit 0\nexit 1\n' > "$tmpbin/git-kb" + printf '#!/usr/bin/env bash\n[ "$*" = "code --help" ] && exit 0\nexit 1\n' > "$tmpbin/git-kb" chmod +x "$tmpbin/git-kb" local input @@ -217,13 +218,13 @@ teardown() { } # PATH whose git-kb has no `code` command (core 1.0 without the extension), -# whichever git-kb the test machine has. +# whichever git-kb the test machine has. Only the hook's exact probe fails. core_only_path() { local tmpbin="$1" tool for tool in awk bash cat dirname git; do ln -s "$(command -v "$tool")" "$tmpbin/$tool" done - printf '#!/usr/bin/env bash\n[ "$1" = code ] && exit 2\nexec %q "$@"\n' "$(command -v git-kb)" > "$tmpbin/git-kb" + printf '#!/usr/bin/env bash\n[ "$*" = "code --help" ] && exit 2\nexec %q "$@"\n' "$(command -v git-kb)" > "$tmpbin/git-kb" chmod +x "$tmpbin/git-kb" echo "$tmpbin" } @@ -242,7 +243,7 @@ core_only_path() { local ctx ctx=$(echo "$output" | jq -r '.hookSpecificOutput.additionalContext') - [[ "$ctx" == *"\`git-kb code\` is not installed"* ]] + [[ "$ctx" == *"\`git-kb code --help\` failed"* ]] [[ "$ctx" == *"curl -fsSL https://get.gitkb.com/install.sh | bash"* ]] [[ "$ctx" != *"git-kb code doctor"* ]] [[ "$ctx" != *"Prefer \`git-kb code"* ]] @@ -264,7 +265,7 @@ core_only_path() { ctx=$(echo "$output" | jq -r '.hookSpecificOutput.additionalContext') [[ "$ctx" == *"GitKB Ready"* ]] [[ "$ctx" == *"git-kb doctor --check repos,kb --json"* ]] - [[ "$ctx" == *"\`git-kb code\` is not installed"* ]] + [[ "$ctx" == *"\`git-kb code --help\` failed"* ]] [[ "$ctx" != *"git-kb code doctor"* ]] rm -rf "$tmpbin"