pks brain synth

stable

Cluster per-session extracts by theme and narrate the cross-session story into themes.md, bad-habits.md, and the clusters.json that wiki and adr read.

Author: Poul Kjeldager
Usage: pks brain synth [options]
Category: infrastructure

Examples

$ pks brain synth --dry-run

List eligible clusters and the estimated cost

$ pks brain synth --no-ai

Write clusters.json and a skeleton without spending

$ pks brain synth --max-clusters 10

Narrate only the ten largest themes

Synth is phase 3. It reads every per-session extract in the current repository, groups them into thematic clusters, and writes the cross-session story: ./.pks/brain/synthesis/themes.md, bad-habits.md, and the machine-readable clusters.json that both wiki and adr consume.

One session is a memory. A cluster is a pattern — which is why the default --min-cluster-size is 2 and singletons are left out.

1. Prerequisites

  • A git repository. Output goes to ./.pks/brain/synthesis/, so the command exits with code 1 outside a repo.
  • pks brain extract must have written at least one extract. With none, synth tells you to run extract and exits 0 — this is not an error.

2. Plan the run

pks brain synth --dry-run

Eligible clusters and an estimated cost are printed, and no model is called.

3. Synthesize

pks brain synth

Each qualifying cluster gets an AI-written narrative; the remainder still appear in clusters.json. Clusters are narrated ten at a time by default.

The confirmation gate fires when the run needs at least 10 model calls and is estimated at $1.00 or more. --no-ai and -y both bypass it.

4. Get the cluster index without spending

pks brain synth --no-ai

This writes clusters.json and a deterministic themes.md skeleton with no model calls. It is enough to unblock pks brain adr, which only needs the cluster index.

5. Tune the clustering

pks brain synth --min-cluster-size 3 --max-clusters 10

Raise --min-cluster-size on a busy repository to surface only substantial themes; lower it on a small one when nothing qualifies. --max-clusters caps how many clusters get a narrative, which is the cheapest lever on cost.

6. Verify

cat ./.pks/brain/synthesis/themes.md

Each section corresponds to a cluster in clusters.json. bad-habits.md holds the recurring anti-patterns found across sessions.

Options

FlagDefaultDescription
--model <name>haikuModel name passed to the backend.
--parallel <n>10Maximum parallel model invocations.
--max-clusters <n>Cap how many clusters receive an AI narrative. Others remain in clusters.json.
--min-cluster-size <n>2Minimum sessions per cluster before it is surfaced.
--no-aifalseSkip model calls. Writes clusters.json and a deterministic themes.md only.
--max-budget-usd <amount>Hard dollar cap per invocation.
--dry-runfalsePlan only — print eligible clusters and the estimate.
-y, --yesfalseSkip the cost-confirmation prompt for large runs.

Troubleshooting

"Run pks brain extract first" and exit 0. No extracts exist in this repository yet.

No cluster met the threshold. The exit code is 0 and a hint is printed. Lower --min-cluster-size, or extract more sessions first.

Exit code 1 immediately. The working directory is not inside a git repository.

Wiki and adr say clusters.json is missing. Synth did not complete. pks brain synth --no-ai is the cheapest way to produce that file.

See also