karajan-code 2.24.0 → 2.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -345,6 +345,14 @@ Opt out: set `telemetry: false` in `~/.karajan/kj.config.yml`
345
345
 
346
346
  ## Recent releases
347
347
 
348
+ > **v2.25.0 released** — Minor. **RAG Camino B + Camino D** (KJC-PCS-0049). Closes the consumer-surface plan. Skills hosts can now invoke RAG via `/kj-rag-query` without MCP, and the pre-loop retrieval stage from v2.24.0 only fires when triage signals make it worthwhile.
349
+ >
350
+ > Camino B — `/kj-rag-query <text> [--scope <s>] [--top-k <n>]` slash command shipped by `kj init` to `.claude/commands/`. Thin wrapper over `kj rag query`; passes flags through, surfaces `empty:true` as a one-line hint, renders hits as background context rather than raw JSON. For Claude Code / Cursor instances loaded without MCP.
351
+ >
352
+ > Camino D — Brain decisor heuristic in `src/orchestrator/stages/rag-preload-decisor.js`. New `config.rag.preload.policy`: `always` (v2.24.0 behaviour, kept for back-compat), `never` (benchmarking), `auto` (default). In `auto` mode, retrieval fires when triage decomposes, level ∈ {complex, high, epic}, task body ≥ 200 chars, or `config.rag.preload.brownfield` is set. Otherwise the stage persists `{ skipped: true, reason: 'auto:low-value' }` and the pipeline pays no retrieval cost on trivial tasks.
353
+ >
354
+ > **Coming in v2.26.0+**: chokidar watcher for live re-indexing, AST source chunker (tree-sitter / `@babel/parser`), BM25 + cosine hybrid scoring.
355
+ >
348
356
  > **v2.24.0 released** — Minor. **RAG Camino C — pre-loop auto-retrieval** (KJC-PCS-0049). After v2.23.0 taught the agents that `kj_rag_query` exists, Karajan now injects prior context for them automatically: a new pre-loop stage queries the vec store with the task description and prepends the top-K chunks to the task before any LLM call.
349
357
  >
350
358
  > Opt-in: `config.rag.preload.enabled = false` by default. Five guards before the retrieval fires (`disabled`, `no-task`, empty corpus, no hits, error). The stage never throws — best-effort enrichment, opt-out by default, opt-back-out on failure. When all guards pass, the task receives an extra block:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "karajan-code",
3
- "version": "2.24.0",
3
+ "version": "2.25.0",
4
4
  "description": "Local multi-agent coding orchestrator with TDD, SonarQube, and code review pipeline",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0",
@@ -544,7 +544,7 @@ async function installSkills(logger, interactive) {
544
544
 
545
545
  if (installed > 0) {
546
546
  logger.info(`Installed ${installed} Karajan skill(s) in .claude/commands/`);
547
- logger.info("Available as slash commands: /kj-run, /kj-code, /kj-review, /kj-test, /kj-security, /kj-discover, /kj-architect, /kj-sonar");
547
+ logger.info("Available as slash commands: /kj-run, /kj-code, /kj-review, /kj-test, /kj-security, /kj-discover, /kj-architect, /kj-sonar, /kj-rag-query");
548
548
  } else {
549
549
  logger.info("All skills already installed.");
550
550
  }
@@ -41,6 +41,7 @@ import {
41
41
  runDiscoverStage, runHuReviewerStage,
42
42
  } from "../pre-loop-stages.js";
43
43
  import { runRagContextStage } from "../stages/rag-context-stage.js";
44
+ import { shouldPreloadRag } from "../stages/rag-preload-decisor.js";
44
45
  // TSK-0336: triage goes through the StageRegistry / StageExecutor contract
45
46
  // so canRun / execute / onFailure are actually exercised in production.
46
47
  // The registry is a singleton with TriageStage / CoderStage / ReviewerStage
@@ -131,10 +132,24 @@ export async function runPreLoopStages({ config, logger, emitter, eventBase, ses
131
132
  // all see prior context without having to call kj_rag_query themselves.
132
133
  // Empty store / network / etc. degrade to no-op via the stage itself.
133
134
  if (!resumeSkip("ragPreload")) {
134
- const ragRes = await runRagContextStage({ config, logger, emitter, eventBase, task });
135
- if (!ragRes.skipped && ragRes.contextBlock) {
136
- task = `${task}\n\n${ragRes.contextBlock}`;
137
- await persistStage("ragPreload", { hits: ragRes.hits.length, scope: config?.rag?.preload?.scope || "all" });
135
+ // KJC-TSK-0434 (Camino D): Brain decisor heuristic — skip retrieval
136
+ // when triage + task shape say it would be low-value. Defaults to
137
+ // policy=auto; `always`/`never` are escape hatches.
138
+ const decision = shouldPreloadRag({ triage: triageResult.stageResult, task, config });
139
+ if (!decision.pull) {
140
+ await persistStage("ragPreload", { skipped: true, reason: decision.reason });
141
+ } else {
142
+ const ragRes = await runRagContextStage({ config, logger, emitter, eventBase, task });
143
+ if (!ragRes.skipped && ragRes.contextBlock) {
144
+ task = `${task}\n\n${ragRes.contextBlock}`;
145
+ await persistStage("ragPreload", {
146
+ hits: ragRes.hits.length,
147
+ scope: config?.rag?.preload?.scope || "all",
148
+ decisor: decision.reason,
149
+ });
150
+ } else {
151
+ await persistStage("ragPreload", { skipped: true, reason: ragRes.reason, decisor: decision.reason });
152
+ }
138
153
  }
139
154
  }
140
155
 
@@ -0,0 +1,58 @@
1
+ // KJC-TSK-0434 — RAG Camino D: Brain decisor heuristic for retrieval.
2
+ // Decides WHETHER to pay the cost of running the RAG preload stage based
3
+ // on signals from triage + task shape, instead of pre-fetching every run.
4
+ //
5
+ // Returns `{ pull: boolean, reason: string }`. The pre-loop driver
6
+ // skips `runRagContextStage` when `pull === false`.
7
+ //
8
+ // Policies (config.rag.preload.policy):
9
+ // - "always" : pull regardless (back-compat with v2.24.0 behaviour)
10
+ // - "never" : never pull (useful for benchmarking, debugging)
11
+ // - "auto" : heuristic — pull only when triage signals complexity,
12
+ // decomposition, or when the task body is long enough
13
+ // to suggest non-trivial scope. Default.
14
+
15
+ const DEFAULT_POLICY = "auto";
16
+ const COMPLEX_LEVELS = new Set(["complex", "high", "epic"]);
17
+ const LONG_TASK_CHARS = 200;
18
+
19
+ /**
20
+ * @param {object} params
21
+ * @param {object} [params.triage] - triage stage result (may be null)
22
+ * @param {string} [params.task] - the user task text
23
+ * @param {object} [params.config] - full karajan config
24
+ * @returns {{ pull: boolean, reason: string }}
25
+ */
26
+ export function shouldPreloadRag({ triage, task, config } = {}) {
27
+ const policy = config?.rag?.preload?.policy || DEFAULT_POLICY;
28
+
29
+ if (policy === "always") return { pull: true, reason: "policy:always" };
30
+ if (policy === "never") return { pull: false, reason: "policy:never" };
31
+
32
+ // policy === "auto" — apply heuristic.
33
+ // Brownfield is an explicit user signal — if onboarding produced a
34
+ // brief and config marks the project as brownfield, prior context is
35
+ // almost always worth pulling.
36
+ if (config?.rag?.preload?.brownfield === true) {
37
+ return { pull: true, reason: "auto:brownfield" };
38
+ }
39
+
40
+ // Triage said this is big enough to decompose → multi-HU run benefits
41
+ // from prior context fed to researcher/architect/planner.
42
+ if (triage?.shouldDecompose === true) {
43
+ return { pull: true, reason: "auto:decompose" };
44
+ }
45
+
46
+ // Triage classified the task as complex / high-effort.
47
+ if (triage?.level && COMPLEX_LEVELS.has(String(triage.level).toLowerCase())) {
48
+ return { pull: true, reason: "auto:complex" };
49
+ }
50
+
51
+ // Long task body usually means a brief with context, motivation and
52
+ // non-trivial scope — worth checking the RAG.
53
+ if (typeof task === "string" && task.length >= LONG_TASK_CHARS) {
54
+ return { pull: true, reason: "auto:long-task" };
55
+ }
56
+
57
+ return { pull: false, reason: "auto:low-value" };
58
+ }
@@ -0,0 +1,50 @@
1
+ # kj-rag-query — Query Project RAG index
2
+
3
+ Query the Project RAG (vector store + embedder) and return the top-K most relevant chunks of the indexed project: plans, onboarding briefs, and (optionally) source code.
4
+
5
+ Use this when you need prior context about the project before deciding, refactoring, planning, or coding — without scanning the filesystem manually.
6
+
7
+ ## Your task
8
+
9
+ $ARGUMENTS
10
+
11
+ ## How it works
12
+
13
+ This skill is a thin wrapper over the Karajan CLI:
14
+
15
+ ```
16
+ kj rag query "<text>" [--scope <all|plans|onboarding|code>] [--top-k <n>] [--json]
17
+ ```
18
+
19
+ Parse `$ARGUMENTS` as the natural-language query plus optional flags:
20
+
21
+ - `--scope <s>`: restrict retrieval to one source bucket. Default: `all`.
22
+ - `plans` → indexed plan JSON files (HU titles, scope, blocked_by).
23
+ - `onboarding` → onboarding briefs from `~/.karajan/onboarding/`.
24
+ - `code` → indexed source files (only present if user ran `kj rag index --with-sources`).
25
+ - `--top-k <n>`: number of chunks to return. Default: 3. Max recommended: 10.
26
+ - `--json`: emit raw JSON (use when piping into another tool).
27
+
28
+ If `$ARGUMENTS` is empty, print a one-line usage hint and stop.
29
+
30
+ ## Behavior contract
31
+
32
+ 1. **Empty store**: if the CLI replies with `empty: true`, do NOT block the conversation. Tell the user once: "RAG index is empty — run `kj rag index` to seed it" and continue without prior context.
33
+ 2. **Zero hits**: if the store has chunks but no match scored above threshold, say "no relevant prior context" and continue.
34
+ 3. **Hits returned**: render each as a short block — `[score] source — snippet` — and use them as background context for the user's actual question. Do NOT dump raw JSON unless `--json` was passed.
35
+ 4. **Never re-validate flags**. Pass `--scope`/`--top-k` straight to the CLI; the CLI is the source of truth.
36
+
37
+ ## Examples
38
+
39
+ User: `/kj-rag-query how does the retriever rank chunks`
40
+ → `kj rag query "how does the retriever rank chunks"`
41
+
42
+ User: `/kj-rag-query auth flow --scope plans --top-k 5`
43
+ → `kj rag query "auth flow" --scope plans --top-k 5`
44
+
45
+ User: `/kj-rag-query --scope onboarding architecture`
46
+ → `kj rag query "architecture" --scope onboarding`
47
+
48
+ ## Why this exists (Camino B)
49
+
50
+ Hosts that load Karajan as Skills (Claude Code without MCP, Cursor without MCP) cannot reach the `kj_rag_query` MCP tool. This skill bridges that gap with the same retrieval contract.