/sdlc-knowledge-base:kb-query <question> [--promote-to-library]from sdlc-knowledge-base
Queries the project knowledge base using a research-librarian agent that reads the shelf-index, deep-reads relevant library files, and returns structured evidence with citations. Supports retrieval and synthesis queries.
Ships in sdlc-knowledge-base. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Ask a question against the project's knowledge base. This is the query operation in the three-operations model (ingest / query / lint).
A natural-language question. Two forms:
Optional flag:
--promote-to-library — after the librarian answers, file the answer back into the library as a new page via kb-promote-answer-to-library. Use when the answer is worth keeping for future queries.research-librarian agent is available.Before running any subsequent step, verify the kb scripts package can be imported:
python3 -c "
import sys, os, importlib.util
PLUGIN_ROOT = os.environ.get('CLAUDE_PLUGIN_ROOT', '')
SCRIPTS = os.path.join(PLUGIN_ROOT, 'scripts')
INIT = os.path.join(SCRIPTS, '__init__.py')
if os.path.isfile(INIT) and 'sdlc_knowledge_base_scripts' not in sys.modules:
spec = importlib.util.spec_from_file_location(
'sdlc_knowledge_base_scripts',
INIT,
submodule_search_locations=[SCRIPTS],
)
if spec and spec.loader:
module = importlib.util.module_from_spec(spec)
sys.modules['sdlc_knowledge_base_scripts'] = module
spec.loader.exec_module(module)
try:
import sdlc_knowledge_base_scripts.registry # noqa: F401
print('OK')
except ImportError:
print('MISSING')
"
If output is MISSING, prepend this preamble to every subsequent bash snippet in this skill:
import sys, os, importlib.util
PLUGIN_ROOT = os.environ.get('CLAUDE_PLUGIN_ROOT', '')
SCRIPTS = os.path.join(PLUGIN_ROOT, 'scripts')
INIT = os.path.join(SCRIPTS, '__init__.py')
if os.path.isfile(INIT) and 'sdlc_knowledge_base_scripts' not in sys.modules:
spec = importlib.util.spec_from_file_location(
'sdlc_knowledge_base_scripts',
INIT,
submodule_search_locations=[SCRIPTS],
)
if spec and spec.loader:
module = importlib.util.module_from_spec(spec)
sys.modules['sdlc_knowledge_base_scripts'] = module
spec.loader.exec_module(module)
The CLAUDE_PLUGIN_ROOT environment variable is set by Claude Code when it loads the plugin. The scripts subdirectory is always packaged as <plugin>/scripts/. If CLAUDE_PLUGIN_ROOT is not set (running outside Claude Code), the user can either set it manually (export CLAUDE_PLUGIN_ROOT=plugins/sdlc-knowledge-base) or editable-install the plugin (pip install -e plugins/sdlc-knowledge-base).
Run the registry resolver helper to determine which sources to dispatch against:
python3 -c "
from pathlib import Path
from sdlc_knowledge_base_scripts.registry import load_global_registry, load_project_activation, resolve_dispatch_list
import json, os
global_reg = load_global_registry(Path(os.path.expanduser('~/.sdlc/global-libraries.json')))
activation = load_project_activation(Path('.sdlc/libraries.json'))
dispatch = resolve_dispatch_list(global_reg, activation, Path('library').resolve())
print(json.dumps({
'sources': [{'name': s.name, 'path': s.path} for s in dispatch.sources],
'warnings': global_reg.warnings + activation.warnings + dispatch.warnings,
'is_empty_error': dispatch.is_empty_error,
}, indent=2))
"
If is_empty_error is true and any warning starts with Local library:, Source ' or Activated source ', show ALL such warnings to the user (a library exists or was activated but was rejected, so the cause is in the warnings) and stop. Do NOT print the kb-init advice in that case.
Otherwise, if is_empty_error is true, print:
No knowledge base available. Run
/sdlc-knowledge-base:kb-initto create a local library, or register and activate an external library with/sdlc-knowledge-base:kb-register-library.
and stop.
When is_empty_error is true, warnings starting Local library:, Source ' or Activated source ' are shown to the user as above. In every other case, and when some sources succeed, print all warnings from the helper (including those) to stderr (not to user-facing output).
python3 -c "
from pathlib import Path
from sdlc_knowledge_base_scripts.priming import build_priming_bundle
import json
bundle = build_priming_bundle(question='<the user question>', project_dir=Path('.'))
print(json.dumps({
'question': bundle.question,
'local_kb_config_excerpt': bundle.local_kb_config_excerpt,
'local_shelf_index_terms': bundle.local_shelf_index_terms,
}, indent=2))
"
The bundle's contents flow into each librarian dispatch via format_dispatch_prompt
in Step 3. The librarian uses local_shelf_index_terms to bias term-matching against
its scoped shelf-index, and local_kb_config_excerpt to frame findings in the local
project's lens (see the librarian agent's PRIMING_CONTEXT documentation).
For each source in the dispatch list, render the librarian prompt via the orchestrator's
helper (it produces the exact SCOPE: / SOURCE_HANDLE: / PRIMING_CONTEXT: shape the
librarian expects):
python3 -c "
from pathlib import Path
from sdlc_knowledge_base_scripts.orchestrator import format_dispatch_prompt
from sdlc_knowledge_base_scripts.priming import PrimingBundle
from sdlc_knowledge_base_scripts.registry import LibrarySource
import json
# Reconstruct the priming bundle from the JSON produced in Step 2
priming_data = json.loads('<priming_bundle_json_from_step_2>')
priming = PrimingBundle(
question=priming_data['question'],
local_kb_config_excerpt=priming_data['local_kb_config_excerpt'],
local_shelf_index_terms=priming_data['local_shelf_index_terms'],
)
source = LibrarySource(name='<source.name>', type='filesystem', path='<source.path>')
prompt = format_dispatch_prompt(
source=source,
question='<the user question>',
priming=priming,
)
print(prompt)
"
Then use the Agent tool to invoke the research-librarian agent once per source in
the dispatch list. Issue ALL invocations in a SINGLE message so they run in parallel
(Claude's parallel tool-call capability). Pass each source's rendered prompt as the
agent's input.
The rendered prompt structure looks like:
SCOPE: <source.path>
SOURCE_HANDLE: <source.name>
PRIMING_CONTEXT:
{
"local_kb_config_excerpt": "...",
"local_shelf_index_terms": [...]
}
Question: <the user question>
Read the shelf-index at <source.path>/_shelf-index.md, identify the 2-4
most relevant library files for the question, deep-read only those, and
return findings in the retrieval format. Every finding block must include
a **Source library**: <source.name> line (see your agent prompt).
Do not read any files outside <source.path>. Do not emit --- horizontal
rules inside a finding block (they are treated as structural separators
by the post-check tokenizer).
The librarian agent's prompt spec defines how it consumes PRIMING_CONTEXT — the orchestrator
helper, the librarian prompt, and this skill stay in lockstep on the format.
Each librarian returns its findings (or "no evidence on this topic" if the scoped library has nothing, or an error). Collect each source's output, keyed by source.name.
Then run the orchestrator to apply per-source attribution post-check and render the combined output:
python3 -c "
# The orchestrator is designed to take a dispatcher callable. In this
# skill, you have already dispatched via the Agent tool and have the
# outputs in hand. Call the pure-Python post-processing directly.
from sdlc_knowledge_base_scripts.orchestrator import run_retrieval_query, DispatchRequest
from sdlc_knowledge_base_scripts.priming import PrimingBundle
from sdlc_knowledge_base_scripts.registry import LibrarySource
import json
# Reconstruct sources from the dispatch list (step 1) and build a
# pass-through dispatcher that returns the already-collected outputs.
collected = {
'local': '<output from local librarian>',
'corporate-semi': '<output from corporate-semi librarian>',
# ... one entry per source
}
def pass_through(req: DispatchRequest) -> str:
return collected[req.source.name]
sources = [
LibrarySource(name='local', type='filesystem', path='<path>'),
# ... one entry per activated source
]
# Reconstruct from Step 2's JSON output if not already in scope
priming_data = json.loads('<priming_bundle_json_from_step_2>')
priming = PrimingBundle(
question=priming_data['question'],
local_kb_config_excerpt=priming_data['local_kb_config_excerpt'],
local_shelf_index_terms=priming_data['local_shelf_index_terms'],
)
result = run_retrieval_query(
question='<the user question>',
sources=sources,
priming=priming, # built in Step 2, formatted into each dispatch by Step 3
dispatcher=pass_through,
audit_log_path=Path('library/audit.log'),
)
print(result.combined_output)
"
Alternatively, assemble the combined output manually by:
**Sources queried:**, **Sources with findings:**, **Sources that failed:** lines## [source-name] Findings section\n\n---\n\n separatorscheck_retrieval_attribution per-source to drop any untagged findingsThe orchestrator helper is the preferred approach for consistency.
--promote-to-library flag was specifiedSame behaviour as before — dispatch kb-promote-answer-to-library with the answer. Promotion writes only to the local library; external libraries are read-only from this project.
After Step 5 (retrieval is complete), decide whether to run synthesis:
Skip synthesis when:
is_synthesis_query from the orchestrator helper)Run synthesis when both conditions are met. The synthesis flow has two phases:
Use the Agent tool to invoke the synthesis-librarian agent (NOT research-librarian — synthesis-librarian has tools: [] and is dedicated to no-file-read synthesis). Pass this exact dispatch prompt as the agent's input:
MODE: SYNTHESISE-ACROSS-SOURCES
PRIMING_CONTEXT:
{
"local_kb_config_excerpt": "<the excerpt from Step 2>",
"local_shelf_index_terms": [<the terms from Step 2>]
}
Question: <the user question>
Per-source findings (your only source of facts — do not read any files):
--- [<source.name>] ---
<raw librarian output for that source from Step 4>
--- [<other source.name>] ---
<raw librarian output>
Produce a single connected argument that addresses the question, drawing on the findings above. Use the synthesis output format (Claim / Supporting evidence / Caveats / Programme application).
MANDATORY: every claim in the Supporting evidence list must carry an inline [<handle>] tag identifying which source library it came from.
When findings span multiple libraries, the Caveats section MUST explicitly name the cross-library span and the priming-influence (which findings were prioritised, which were de-emphasised, whether priming changed the synthesis outcome).
Capture the agent's response as synthesis_output (a string).
Run the orchestrator's synthesis attribution check on the captured output:
python3 -c "
import sys, os, importlib.util
PLUGIN_ROOT = os.environ.get('CLAUDE_PLUGIN_ROOT', '')
SCRIPTS = os.path.join(PLUGIN_ROOT, 'scripts')
INIT = os.path.join(SCRIPTS, '__init__.py')
if os.path.isfile(INIT) and 'sdlc_knowledge_base_scripts' not in sys.modules:
spec = importlib.util.spec_from_file_location(
'sdlc_knowledge_base_scripts',
INIT,
submodule_search_locations=[SCRIPTS],
)
if spec and spec.loader:
module = importlib.util.module_from_spec(spec)
sys.modules['sdlc_knowledge_base_scripts'] = module
spec.loader.exec_module(module)
from pathlib import Path
from datetime import datetime, timezone
from sdlc_knowledge_base_scripts.attribution import check_synthesis_attribution
from sdlc_knowledge_base_scripts.audit import AuditEvent, log_event
valid_handles = {'<source1>', '<source2>'} # the dispatch source names from Step 1
synthesis_output = '''<paste the synthesis-librarian agent's response here>'''
question = '<the user question>'
check = check_synthesis_attribution(synthesis_output, valid_handles=valid_handles)
if check.passed:
# Append synthesis to the retrieval combined output
final = '<retrieval combined output from Step 5>' + '\n\n---\n\n## Cross-library synthesis\n\n' + synthesis_output.rstrip() + '\n'
print(final)
else:
# Synthesis aborted — return retrieval output with error block
log_event(Path('library/audit.log'), AuditEvent(
timestamp=datetime.now(timezone.utc).isoformat(),
event_type='synthesis_aborted_attribution',
query=question,
source_handle=None,
reason=f'{len(check.untagged_claims)} untagged supporting-evidence claim(s)',
detail={'untagged_claims': check.untagged_claims},
))
final = (
'<retrieval combined output from Step 5>'
'\n\n---\n\n'
f'**Synthesis aborted:** attribution post-check failed. '
f'{len(check.untagged_claims)} supporting-evidence claim(s) lacked '
f'an inline source-handle tag and were not safe to publish. '
f'Per-source findings above remain valid; you can draw connections '
f'manually.\n'
)
print(final)
"
If the synthesis dispatch in Phase 6a raises an exception (e.g., agent timeout), don't run Phase 6b — instead append an error block to the retrieval output:
**Synthesis aborted:** dispatcher failed: <exception>.
Per-source findings above are complete; synthesis was not produced.
And write a synthesis_aborted_dispatcher_error audit event via the same log_event pattern.
Phase 6a is the Agent-tool call (model-driven). Phase 6b is the structural post-check (deterministic Python). They cannot be combined: the Python orchestrator's run_synthesis_query expects a synthesis_dispatcher callable but Claude Code's Agent tool is invoked, not called from Python. The two phases preserve the structural attribution guarantee while making the integration concrete.
docs/superpowers/specs/2026-04-26-tools-empty-empirical-evidence.md for the empirical validation of that constraint)Every query writes confidentiality events (attribution drops, synthesis aborts, dispatcher failures) to library/audit.log for later audit via /sdlc-knowledge-base:kb-audit-query. The audit log is project-scope (lives in this project's library/) and append-only.
/sdlc-knowledge-base:kb-ingest (local only in v1)/sdlc-knowledge-base:kb-lint (local only in v1)Retrieval query:
/sdlc-knowledge-base:kb-query "What does our research say about cycle time as a delivery metric?"
Expected response: structured findings with DORA citations, sample sizes, thresholds, library file references.
Synthesis query:
/sdlc-knowledge-base:kb-query "Build me the case for adopting trunk-based development"
Expected response: per-source findings from all activated libraries, then a cross-library synthesis section (Claim / Supporting evidence / Caveats / Programme application) drawn from both sources.
Query with promotion:
/sdlc-knowledge-base:kb-query "How do DORA metrics interact with SAFe-style PI planning?" --promote-to-library
Expected: the librarian answers; the answer is then filed back into the local library as a new file (likely dora-vs-safe-pi.md) with provenance pointing at the source files the librarian read.
Multi-source query (two activated libraries):
/sdlc-knowledge-base:kb-query "What patterns exist for platform engineering team topologies?"
Expected: two parallel research-librarian invocations — one scoped to library/, one scoped to the activated external path. Output rendered with ## [local] Findings and ## [corporate-platform] Findings sections, joined by --- separators, with header:
Sources queried: local, corporate-platform Sources with findings: local, corporate-platform
Out-of-scope query:
/sdlc-knowledge-base:kb-query "What is the airspeed velocity of an unladen swallow?"
Expected response: "The library has no evidence on this. The closest entries are . Recommendation: this query is out of scope for the project knowledge base."
/sdlc-knowledge-base:kb-init first/sdlc-knowledge-base:kb-rebuild-indexes firstsdlc-knowledge-base@ai-first-sdlclibrary/raw/ and run /sdlc-knowledge-base:kb-ingest to populate the library./sdlc-knowledge-base:kb-init or activate a library in .sdlc/libraries.json./sdlc-knowledge-base:kb-rebuild-indexes in the external library.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
16 skills in this plugin
/kb-audit-queryFilter and summarise the cross-library KB audit log. Reports confidentiality events (attribution drops, synthesis aborts, dispatcher failures, no-evidence markers, cross-library promotions) over a date range, by event type, and by source handle./kb-ingestIntegrate a new source into the project knowledge base. Wraps the agent-knowledge-updater agent. Source can be a local file path, a URL, or pasted content. The updater reads the source, classifies it, identifies which existing library files it touches, makes surgical updates or creates new files, rebuilds the shelf-index, and appends to log.md./kb-ingest-batchDrive agent-knowledge-updater over a batch of staged files in library/raw/. Tracks progress in .batch-progress.json for resume support. Sequential by default; --parallel <N> opt-in (max 5). Single shelf-index rebuild and one consolidated log.md entry at the end./kb-ingest-bulkParallel map-reduce bulk ingest for large source sets. Map phase dispatches read-only knowledge-extractor agents (≤N-wide, default Haiku) emitting per-source JSON extracts; Python routes extracts by target library file (fuzzy-merging new topics, pre-allocating new files, flagging oversized topics); reduce phase dispatches one agent-knowledge-updater per file (parallel, one writer per file); single shelf-index rebuild + one log.md entry. Resumable. Supersedes kb-ingest-batch./kb-initInitialise a project for knowledge base use. Appends the [Knowledge Base] section to the project's CLAUDE.md, creates the library/ directory structure, optionally seeds with three example library files from the Agentic SDLC research, and reports next steps. Run once after installing sdlc-knowledge-base./kb-layersManage the project's layer vocabulary — list allowed layers with file counts, add new layers, or safely remove unused layers. Reads the shelf-index for usage data; writes CLAUDE.md atomically. No agent dispatch.npx claudepluginhub stevegjones/ai-first-sdlc-practices --plugin sdlc-knowledge-baseOther plugins' skills for the same job