Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
19 changes: 16 additions & 3 deletions plugin/scripts/session-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,26 @@ CWD=$(resolve_cwd "$INPUT") || { echo '{}'; exit 0; }

NL=$'\n'
CONTEXT=""
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-<platform>.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() {
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}\`\`\`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\`, \`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 code_available; then
CONTEXT+=" Use \`git-kb code doctor --json\` for code-intelligence health."
else
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 <symbol> --json\`, \`git-kb code callees <symbol> --json\`, \`git-kb code impact <path> --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 <symbol> --json\`, \`git-kb code callees <symbol> --json\`, \`git-kb code impact <path> --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
Expand Down
9 changes: 6 additions & 3 deletions plugin/skills/gitkb/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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-<platform>.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 |
|---|---|
Expand All @@ -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:

Expand Down Expand Up @@ -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.
11 changes: 11 additions & 0 deletions tests/helpers/setup.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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"

# `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 stub answers only the
# hook's probe, `git-kb code --help`, so a changed probe fails the tests.
mkdir -p "$TEST_DIR/ext-bin"
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"
}

teardown_test_kb() {
Expand Down
59 changes: 57 additions & 2 deletions tests/session-start.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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\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
Expand All @@ -216,6 +217,60 @@ teardown() {
rm -rf "$repo" "$tmpbin"
}

# PATH whose git-kb has no `code` command (core 1.0 without the extension),
# 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[ "$*" = "code --help" ] && exit 2\nexec %q "$@"\n' "$(command -v git-kb)" > "$tmpbin/git-kb"
chmod +x "$tmpbin/git-kb"
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 --help\` failed"* ]]
[[ "$ctx" == *"curl -fsSL https://get.gitkb.com/install.sh | bash"* ]]
[[ "$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" == *"\`git-kb code --help\` failed"* ]]
[[ "$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)
Expand Down
Loading