Skip to content

Dossier

codeknife dossier builds one compact report that an agent can read before it edits code. Use it at the start of a task: run it on the whole repository to see what to fix first, or point --target at a file or function to get everything about that one place.

A dossier has two modes:

  • Repository mode (no --target): a risk summary, the top root-cause work orders, and source excerpts around them.
  • Target mode (--target): the same summary and work orders restricted to one file or symbol, plus its metrics, blast radius, layer rules, similar existing code (“reusable peers”), refactor recipes and one source excerpt.

The work orders are the same ones codeknife plan --grouped builds. How they are clustered, ranked and enriched is explained on Work Orders (plan).

Terminal window
codeknife --no-cache --format agent dossier --top 3 --budget 900
CODEKNIFE dossier mode=repo risk=high files=8 errors=1 warnings=5 autofixable=0 judgment=6 orders=3
[WO #1] score=100.0 sev=error auto=false blast=0/0 | [security] CK_SEC_CMD_INJECTION in `src/engine.py` | src/engine.py:11-11
cause: shell command execution with shell=True / sh -c / child_process.exec
step: Pass an explicit argument array to `Command::new` / `execFile` / `subprocess.run(..., shell=False)`.
[WO #2] score=100.0 sev=warning auto=false blast=1/1 | [architecture] CK_ARCH_COGNITIVE_COMPLEXITY in `src.engine.validate_order` | src/engine.py:4-16
cause: `validate_order` cognitive complexity is 16 (limit 15) (+2 related finding(s) in same scope)
step: Flatten nested conditionals using early returns, match tables, or domain helpers.
step: Inspect 1 upstream caller(s) via `codeknife blast --symbol src.engine.validate_order` before refactoring.
[WO #3] score=81.0 sev=warning auto=false blast=0/1 | [architecture] CK_ARCH_LOW_COHESION in `shop::hub::Hub` | src/hub.rs:1-6
cause: `Hub` has LCOM4 = 2 disjoint method/field clusters
recipe: cohesion_split type `shop::hub::Hub` into 2 partitions: Billing(3m/2f) | Cache(3m/2f)
step: Recipe: cohesion_split type `shop::hub::Hub` into 2 partitions: Billing(3m/2f) | Cache(3m/2f)
step: Split along natural cohesion seams: Cluster 1: methods=[billing_add, billing_clear, billing_tax] fields=[billing_rate, billing_total] | Cluster 2: methods=[cache_grow, cache_hit, cache_ratio] fields=[cache_hits, cache_size]
EXCERPT src/engine.py:8-14
8 | if currency:
9 | if coupon:
10 | if rush:
11 | subprocess.call(cmd, shell=True)
12 | return total > 0
13 | except Exception:
14 | pass
EXCERPT src/engine.py:1-19
1 | import subprocess
2 |
3 |
4 | def validate_order(total, cmd, region, currency, coupon, rush):
...
18 |
19 | def submit_order(total):
EXCERPT src/hub.rs:1-2
1 | pub struct Hub {
2 | pub billing_total: i64,
... [truncated to --budget]
GUARDRAIL: Run `codeknife fix --write --verify` before hand-editing autofixable hygiene or dead code.
GUARDRAIL: No suppression attributes (#[allow], @ts-ignore) or .unwrap()/panic macros in production code.
GUARDRAIL: Do not weaken codeknife.toml or edit codeknife.baseline by hand; re-verify via `codeknife verify`.

The header counts cover all active findings (here 1 error and 5 warnings), even though only 3 work orders are shown. The third excerpt ran out of budget.

When the working tree has uncommitted changes, a TESTS: line lists the smart test commands for them:

TESTS: pytest -q tests/test_engine.py
Terminal window
codeknife --no-cache --format agent dossier --target validate_order --budget 400
CODEKNIFE dossier mode=target risk=high files=8 errors=1 warnings=3 autofixable=0 judgment=4 orders=2
TARGET symbol `src.engine.validate_order` (src/engine.py:4-16) lines=13 cc=7 cog=16 nesting=5 params=6
blast: callers=1 files=1 churn=5 entrypoints=[] contracts=[]
REUSABLE PEERS:
- src.helper.verify_positive_amount (src/helper.py:1, score=64.8) -> from src.helper import verify_positive_amount
- src/a/scoreOrder (src/a.ts:1, score=62.0) -> import { scoreOrder } from './src/a'
- src/index/main (src/index.ts:4, score=45.7) -> import { main } from './src/index'
- src/b/scoreInvoice (src/b.ts:1, score=29.2) -> import { scoreInvoice } from './src/b'
EXCERPT src/engine.py:4-13
4 | def validate_order(total, cmd, region, currency, coupon, rush):
5 | try:
6 | if total > 0:
7 | if region:
8 | if currency:
9 | if coupon:
10 | if rush:
11 | subprocess.call(cmd, shell=True)
12 | return total > 0
13 | except Exception:
... [truncated to --budget]
[WO #1] score=100.0 sev=error auto=false blast=0/0 | [security] CK_SEC_CMD_INJECTION in `src/engine.py` | src/engine.py:11-11
cause: shell command execution with shell=True / sh -c / child_process.exec
step: Pass an explicit argument array to `Command::new` / `execFile` / `subprocess.run(..., shell=False)`.
[WO #2] score=100.0 sev=warning auto=false blast=1/1 | [architecture] CK_ARCH_COGNITIVE_COMPLEXITY in `src.engine.validate_order` | src/engine.py:4-16
cause: `validate_order` cognitive complexity is 16 (limit 15) (+2 related finding(s) in same scope)
step: Flatten nested conditionals using early returns, match tables, or domain helpers.
step: Inspect 1 upstream caller(s) via `codeknife blast --symbol src.engine.validate_order` before refactoring.
GUARDRAIL: Run `codeknife fix --write --verify` before hand-editing autofixable hygiene or dead code.
GUARDRAIL: No suppression attributes (#[allow], @ts-ignore) or .unwrap()/panic macros in production code.
GUARDRAIL: Do not weaken codeknife.toml or edit codeknife.baseline by hand; re-verify via `codeknife verify`.

The shell-injection finding has no symbol, but its line falls inside validate_order, so it is in scope.

A file target looks like this. It also shows a refactor recipe:

Terminal window
codeknife --no-cache --format agent dossier --target hub.rs --budget 400
CODEKNIFE dossier mode=target risk=medium files=8 errors=0 warnings=1 autofixable=0 judgment=1 orders=1
TARGET file `src/hub.rs` (src/hub.rs:1-15) lang=rust lines=15 code=14 comments=0 suppressions=0
blast: callers=4 files=2 churn=1 entrypoints=[shop::main] contracts=[]
REUSABLE PEERS:
- shop::main (src/main.rs:3, score=49.5) -> use shop::main;
- src/a/scoreOrder (src/a.ts:1, score=32.7) -> import { scoreOrder } from './src/a'
- src/b/scoreInvoice (src/b.ts:1, score=32.7) -> import { scoreInvoice } from './src/b'
- src.engine.validate_order (src/engine.py:4, score=32.7) -> from src.engine import validate_order
REFACTOR RECIPES:
- cohesion_split type `shop::hub::Hub` into 2 partitions: Billing(3m/2f) | Cache(3m/2f)
EXCERPT src/hub.rs:1-10
1 | pub struct Hub {
...
Flag Default Effect
--target TARGET none Switch to target mode. See resolution rules below.
--top N 8 Maximum work orders. 0 is treated as 1.
--budget CHARS 12000 Character budget for source excerpts. Values below 400 are raised to 400.
--coverage PATH none Coverage report for CRAP scores, same fallback rules as plan. A missing file is an error.

Global flags: --changed (with an optional --since base ref) limits the static suite to changed files, and --since also feeds the test command list; --strict uses strict thresholds; --no-cache writes nothing to .codeknife/. --max-items has no effect. With --format json or --format sarif the dossier is printed as JSON (not SARIF). Every other format prints the text layout shown above.

Findings listed in codeknife.baseline are removed before anything else happens. See Ratchet Baseline.

The target string is trimmed and a leading ./ is removed. Then these checks run in order and the first hit wins:

  1. Exact file path relative to the repository root, for example src/hub.rs.
  2. Unique path suffix: exactly one file whose path ends with / plus the target, for example hub.rs.
  3. Exact qualified symbol name, for example src.engine.validate_order or shop::hub::Hub.
  4. Exact short name, for example validate_order.
  5. Case-insensitive match on the qualified name or the short name, for example SRC.ENGINE.VALIDATE_ORDER.

If nothing matches, the command fails with exit code 2:

Terminal window
codeknife --no-cache --format agent dossier --target nope
codeknife error: target `nope` did not match any file or symbol in repository

Qualified names depend on the language: in the demo they look like src.engine.validate_order (Python), src/a/scoreOrder (TypeScript) and shop::hub::Hub (Rust). Copy them from plan, check or reuse output.

Scoped findings. Only findings in the target’s file are kept. For a symbol target, a finding is kept when its symbol equals the target’s qualified name or its line range overlaps the symbol’s lines. The summary and work orders use only these findings.

Metrics (metrics_summary):

  • Symbol: lines=… cc=… cog=… nesting=… params=… (lines, cyclomatic, cognitive, max nesting, parameter count).
  • File: lang=… lines=… code=… comments=… suppressions=….

Blast radius. For a symbol, the blast cone of that symbol (callers, affected files, entrypoints, covering tests, boundary contracts). For a file, the cones of every symbol in it combined: callers are summed, affected files is the maximum, and entrypoints, tests and contracts are merged and cut to 6 each. See Blast Radius.

Churn. Commit count for the file.

Layer rules (layer_rules), read from arch.toml:

  • layer `NAME` for every [[layers]] entry with a path pattern that matches the file.
  • deny `FROM -> TO`: REASON for every [[deny]] rule whose from pattern matches the file. Without a reason, architectural boundary is used.

A pattern matches when the file starts with it, or contains / plus it, after a trailing /**, /* or * is removed. Example with an arch.toml that declares a core layer on src/** and denies src/** to app.py:

[
"layer `core`",
"deny `src/** -> app.py`: library code must not import the entrypoint"
]

Reusable peers. Up to 4 Reuse Oracle candidates from other files (the target’s own file is excluded, all languages). The query is the file path for a file target, or the symbol’s short name plus its file path for a symbol target.

Refactor recipes. Recipes from the scoped findings, as described on Work Orders (plan). Target mode can add one more, up to 3 in total:

  • If the target is a struct or class (matched by qualified or short name in its file), a type cohesion_split is tried even without a CK_ARCH_LOW_COHESION finding.
  • If the target is a file, a file cohesion_split is tried even without a CK_ARCH_LONG_FILE finding.

Excerpt. One excerpt of the symbol’s lines, or of the whole file, using the full budget.

Excerpt lines are rendered as the line number right-aligned in 4 columns, |, and the source line. Lines are added until the next one would push the excerpt past its character allowance. Then the line ... [truncated to --budget] is added and the excerpt stops. The marker itself is not counted, so the output can exceed the budget by that line.

  • Repository mode: excerpts are taken for the first 4 work orders, from 3 lines before to 3 lines after each work order’s span. They share one budget: each excerpt gets what is left, and no more excerpts are added once the budget is used up. Two work orders in the same file produce two overlapping excerpts (as in the example). The text output skips an excerpt whose file and start line were already printed; JSON keeps them all.
  • Target mode: one excerpt gets the whole budget. The top-level excerpts list is empty; the excerpt is inside target.

end_line in an excerpt is the last line printed (or the start line, if not even the first line fit).

Field Meaning
files_scanned Files in the code model
total_findings Active findings, including info (target mode: scoped findings)
errors, warnings, infos Counts by severity
autofixable_findings Non-info findings whose rule is on the autofixable list (see plan)
judgment_findings errors + warnings - autofixable_findings, not below 0
work_order_count Work orders included (at most --top)
risk_level high if any error, medium if any warning, otherwise low

Repository mode, --top 1 --budget 400, trimmed:

Terminal window
codeknife --no-cache --format json dossier --top 1 --budget 400
{
"mode": "repo",
"summary": {
"files_scanned": 8,
"total_findings": 7,
"errors": 1,
"warnings": 5,
"infos": 1,
"autofixable_findings": 0,
"judgment_findings": 6,
"work_order_count": 1,
"risk_level": "high"
},
"target": null,
"work_orders": [
...
],
"excerpts": [
{
"file": "src/engine.py",
"start_line": 8,
"end_line": 14,
"content": " 8 | if currency:\n 9 | if coupon:\n 10 | if rush:\n 11 | subprocess.call(cmd, shell=True)\n 12 | return total > 0\n 13 | except Exception:\n 14 | pass\n"
}
],
"test_commands": [],
"guardrails": [
"Run `codeknife fix --write --verify` before hand-editing autofixable hygiene or dead code.",
"No suppression attributes (#[allow], @ts-ignore) or .unwrap()/panic macros in production code.",
"Do not weaken codeknife.toml or edit codeknife.baseline by hand; re-verify via `codeknife verify`."
]
}

Target mode, --target validate_order --top 1 --budget 400, trimmed:

Terminal window
codeknife --no-cache --format json dossier --target validate_order --top 1 --budget 400
{
"mode": "target",
"summary": {
"files_scanned": 8,
"total_findings": 5,
"errors": 1,
"warnings": 3,
"infos": 1,
"autofixable_findings": 0,
"judgment_findings": 4,
"work_order_count": 1,
"risk_level": "high"
},
"target": {
"query": "validate_order",
"resolved_kind": "symbol",
"file": "src/engine.py",
"symbol": "src.engine.validate_order",
"start_line": 4,
"end_line": 16,
"metrics_summary": "lines=13 cc=7 cog=16 nesting=5 params=6",
"blast_callers": 1,
"blast_files": 1,
"entrypoints": [],
"covering_tests": [],
"boundary_contracts": [],
"churn_commits": 5,
"layer_rules": [],
"reusable_peers": [
{
"symbol": "src.helper.verify_positive_amount",
"name": "verify_positive_amount",
"kind": "fn",
"visibility": "public",
"file": "src/helper.py",
"start_line": 1,
"end_line": 3,
"language": "python",
"score": 64.82845,
"signature": "def verify_positive_amount(amount): \"\"\"Check that an order amount is positive.\"\"\"",
"doc_summary": null,
"matched_terms": [
"check",
"order",
"py",
"src"
],
"inbound_callers": 0,
"reuse_hint": "from src.helper import verify_positive_amount"
},
...
],
"excerpt": {
"file": "src/engine.py",
"start_line": 4,
"end_line": 13,
"content": " 4 | def validate_order(total, cmd, region, currency, coupon, rush):\n 5 | try:\n 6 | if total > 0:\n 7 | if region:\n 8 | if currency:\n 9 | if coupon:\n 10 | if rush:\n 11 | subprocess.call(cmd, shell=True)\n 12 | return total > 0\n 13 | except Exception:\n ... [truncated to --budget]\n"
}
},
"work_orders": [
...
],
"excerpts": [],
"test_commands": [],
"guardrails": [
...
]
}
Field Type Meaning
mode string repo or target
summary object See summary fields
target object or null Target details, null in repository mode
work_orders array Work orders, same shape as plan --grouped
excerpts array Repository-mode excerpts (file, start_line, end_line, content); empty in target mode
test_commands string array Smart test commands for changed files; empty when nothing changed
guardrails string array Three fixed reminders, shown above
Field Type Meaning
query string The --target value as given
resolved_kind string file or symbol
file string Resolved file
symbol string or null Qualified name, null for a file
start_line, end_line number Symbol span, or 1 to the file’s line count
metrics_summary string Metrics string described above
blast_callers, blast_files number Upstream callers and affected files
entrypoints, covering_tests, boundary_contracts string array From the blast cone
churn_commits number Commits touching the file
layer_rules string array Matching arch.toml rules
reusable_peers array Up to 4 reuse candidates, same fields as reuse
recipes array Refactor recipes; omitted when empty
excerpt object One excerpt

test_commands comes from Smart Test Selection. The changed-file set is the --changed set when you pass --changed, otherwise the files git reports as changed in the working tree (plus the diff against --since when given). With no git repository or no changes the list is empty and the TESTS: line is not printed.

dossier emits no findings of its own. It reuses the work-order rules from Work Orders (plan). See Rule Catalogue for the IDs the blades emit.

Code When
0 Dossier printed, whatever the findings
2 Target not found, missing coverage file, or another CodeKnife error
  • MCP tool codeknife_dossier with arguments target, top (default 8), budget (default 12000), strict, changed, since, path and no_cache. It always returns the JSON form and has no coverage argument. See MCP Tools.
  • codeknife plan --grouped prints only the work orders. See Work Orders (plan).