From 86f70090012ad0edc06122dd3714812bd3067f8c Mon Sep 17 00:00:00 2001 From: Matt Walters Date: Tue, 19 May 2026 13:00:41 -0500 Subject: [PATCH] docs: prefer json gitkb commands for agent guidance [[prefer-json-output-in-claude-plugin-guidance]] --- plugin/README.md | 14 +++++++------- plugin/scripts/session-start.sh | 8 ++++---- plugin/skills/gitkb/SKILL.md | 26 +++++++++++++------------- tests/helpers/setup.bash | 3 ++- tests/session-start.bats | 8 +++++++- 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/plugin/README.md b/plugin/README.md index 10b1dd4..1dba90e 100644 --- a/plugin/README.md +++ b/plugin/README.md @@ -17,14 +17,14 @@ Install the plugin, open a Git repo, and ask Claude about the code: Claude will use local commands such as: ```bash -git-kb code doctor +git-kb code doctor --json git-kb code index -git-kb code symbols -git-kb code callers "" -git-kb code callees "" -git-kb code impact path/to/file -git-kb code dead -git-kb code query +git-kb code symbols --json +git-kb code callers "" --json +git-kb code callees "" --json +git-kb code impact path/to/file --json +git-kb code dead --json +git-kb code query hotspots --json ``` No `.kb` project is required for those code intelligence commands. diff --git a/plugin/scripts/session-start.sh b/plugin/scripts/session-start.sh index 64b28f0..e4363c8 100755 --- a/plugin/scripts/session-start.sh +++ b/plugin/scripts/session-start.sh @@ -15,13 +15,13 @@ NL=$'\n' CONTEXT="" 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\`, \`git-kb code index\`, and related \`git-kb code ...\` 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,code,kb\`." + 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,code,kb --json\`." 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\` over grep for code exploration.** Grep matches text; \`git-kb code\` understands the AST and call graph.${NL}${NL}For code questions, prefer these local CLI commands:${NL}${NL}- \`git-kb code doctor\` to inspect language/index health.${NL}- \`git-kb code index\` before first analysis or after large changes.${NL}- \`git-kb code symbols\`, \`git-kb code callers\`, \`git-kb code callees\`, \`git-kb code impact\`, \`git-kb code dead\`, and \`git-kb code query\` 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}MCP is supported after full KB setup today; use CLI fallback 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\` 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}\`\`\`" + 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 CONTEXT_JSON=$(json_escape "$CONTEXT") diff --git a/plugin/skills/gitkb/SKILL.md b/plugin/skills/gitkb/SKILL.md index 73b8e49..b5401da 100644 --- a/plugin/skills/gitkb/SKILL.md +++ b/plugin/skills/gitkb/SKILL.md @@ -32,10 +32,10 @@ When exploring code relationships, prefer `git-kb code` over grep. Grep matches | Instead of | Use | |---|---| -| grep for function callers | `git-kb code callers ""` | -| grep for definitions | `git-kb code symbols --file ` | -| grep to assess change impact | `git-kb code impact ` | -| manual dead code search | `git-kb code dead` | +| grep for function callers | `git-kb code callers "" --json` | +| grep for definitions | `git-kb code symbols --file --json` | +| grep to assess change impact | `git-kb code impact --json` | +| manual dead code search | `git-kb code dead --json` | ## Code Intelligence Without `.kb` @@ -44,18 +44,18 @@ GitKB code intelligence works in a normal Git repo without `git-kb init`. Use these commands for code questions: ```bash -git-kb code doctor +git-kb code doctor --json git-kb code index -git-kb code symbols -git-kb code symbols --file path/to/file -git-kb code callers "" -git-kb code callees "" -git-kb code impact path/to/file -git-kb code dead -git-kb code query +git-kb code symbols --json +git-kb code symbols --file path/to/file --json +git-kb code callers "" --json +git-kb code callees "" --json +git-kb code impact path/to/file --json +git-kb code dead --json +git-kb code query hotspots --json ``` -Run `git-kb code doctor` first when you need to understand index health or language support. Run `git-kb code index` before first analysis or after large code changes. +Run `git-kb code doctor --json` first when you need to understand index health or language support. Run `git-kb code index` before first analysis or after large code changes. Use GitKB code intelligence before broad refactors, symbol renames, dead-code removal, dependency cleanup, service-edge analysis, or questions about how code flows through the repository. diff --git a/tests/helpers/setup.bash b/tests/helpers/setup.bash index 5c56ed5..b72af5d 100644 --- a/tests/helpers/setup.bash +++ b/tests/helpers/setup.bash @@ -25,7 +25,8 @@ setup_test_kb() { GITKB_ROOT="$TEST_KB_ROOT" git-kb create \ --type task \ --slug tasks/test-1 \ - --title "Test Task" 2>/dev/null + --title "Test Task" \ + --json 2>/dev/null GITKB_ROOT="$TEST_KB_ROOT" git-kb commit -m "test task" tasks/test-1 2>/dev/null diff --git a/tests/session-start.bats b/tests/session-start.bats index 529f5bb..5761465 100644 --- a/tests/session-start.bats +++ b/tests/session-start.bats @@ -22,6 +22,7 @@ teardown() { ctx=$(echo "$output" | jq -r '.hookSpecificOutput.additionalContext') [[ "$ctx" == *"GitKB Ready"* ]] [[ "$ctx" == *"git-kb init claude"* ]] + [[ "$ctx" == *"git-kb doctor --check repos,code,kb --json"* ]] [[ "$ctx" != *"tasks/test-1"* ]] local wp @@ -102,8 +103,12 @@ teardown() { ctx=$(echo "$output" | jq -r '.hookSpecificOutput.additionalContext') [[ "$ctx" == *"GitKB Code Intelligence"* ]] [[ "$ctx" == *"works without initialization"* ]] - [[ "$ctx" == *"git-kb code doctor"* ]] + [[ "$ctx" == *"git-kb code doctor --json"* ]] [[ "$ctx" == *"git-kb code index"* ]] + [[ "$ctx" == *"git-kb code symbols --json"* ]] + [[ "$ctx" == *"git-kb code callers --json"* ]] + [[ "$ctx" == *"git-kb code query hotspots --json"* ]] + [[ "$ctx" == *"JSON output preserves complete symbol IDs and stable fields"* ]] [[ "$ctx" == *"Do not require \`git-kb init\` for code intelligence"* ]] [[ "$ctx" != *"Repository root:"* ]] [[ "$ctx" != *"$repo"* ]] @@ -177,6 +182,7 @@ 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"* ]] rm -rf "$repo" "$tmpbin" }