一键导入
cortex-distill
Distill raw session records into refined Notes and Projects. Use when the user says "提煉", "整理 raw", "distill", or "distill raw records".
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Distill raw session records into refined Notes and Projects. Use when the user says "提煉", "整理 raw", "distill", or "distill raw records".
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Search and retrieve content from the cortex vault — the user's external memory. Use (1) when the user says "查 cortex", "之前有記過", "cortex 裡有沒有", "check my notes", "what did I write about", AND (2) PROACTIVELY — before answering any non-trivial question about ongoing projects, internal company tooling, cortex-vec, plugin development, NAS debugging, DSM workflows, or any topic that resembles prior work the user might have notes on. When the SessionStart hook lists vault topics and the user's request matches one, search cortex BEFORE asking clarifying questions or guessing. Treat the vault as authoritative prior context: searching it cheaply is always better than reinventing an answer the user already wrote down.
Use when starting any task or answering any non-trivial question in a cortex-enabled session — establishes that the cortex vault is the user's external memory and should be consulted BEFORE guessing, asking clarifying questions, or doing fresh exploration. Trigger unconditionally on conversation start, on every new user request that touches a domain the user has worked on before, and whenever the request mentions an ongoing project, internal company tooling, recurring topic, or anything that smells like prior work. If the SessionStart hook surfaced vault topics and the request matches one — search first.
llm-wiki style broadcast ingest — conversational update of related existing pages when a Raw has been distilled. Use when the user says "broadcast", "跑 broadcast", "compound this into the vault", "merge pending-merge", "process broadcast queue", or when cortex-distill invokes broadcast inline after Step 8 commit (automatic dispatch for every new / pending-merge Raw).
Create or resume a session takeoff baton — a curated, ephemeral, git-ignored hand-off note that lets the next Claude session continue a long-running task. Use when the user says "交接", "takeoff", "交棒", "context 快滿了交接給下個 session", "hand off to next session", "/cortex:takeoff", "takeoff resume", or "takeoff done". The baton is scaffolding, not knowledge: it is never committed, distilled, broadcast, or indexed.
Save knowledge to the cortex vault. Use when the user says "存到 cortex", "記一下", "save to cortex", "記到筆記", "cortex evolve", or when the session-suggest hook recommends saving content. Handles Notes and Projects.
| name | cortex-distill |
| description | Distill raw session records into refined Notes and Projects. Use when the user says "提煉", "整理 raw", "distill", or "distill raw records". |
Extract valuable knowledge from Raw/ session dumps into Notes/ and Projects/.
Read ~/.cortex/config.json to get vault_path.
If the file doesn't exist, tell the user to run /cortex:genesis first.
List the distill queue:
cortex-vec distill-queue --root <vault_path>/Raw
This is position-anchored: a Raw counts as distilled only if a
<!-- distilled: ... --> marker appears in its header (before the first
### User turn) or as its last non-empty line. Do NOT grep the
marker string — a pipeline meta-session's body quotes it dozens of times
(it printfs markers onto other files), so grep -rL '<!-- distilled:'
silently drops genuine work from the queue. To check one file, use
cortex-vec raw-state <file>.
Show the pending list count and ask to proceed.
Size the queue before opening any Raw:
cortex-vec distill-queue --root <vault_path>/Raw --stat
Partition by RAW size (the raw column) and present the plan for
approval (do not auto-run):
BUDGET_EXHAUSTED + distill-plan resume --new-session continuations.Carry remaining lanes forward with a cortex-takeoff baton. When a plan
is mid-flight, record its plan_id in the baton — machine state lives in
the plan cache, the baton only points at it.
One Raw at a time. NEVER Read the full Raw file; NEVER judge from an L3/L3* projection. All original text arrives through bounded pages.
Start (or resume) the plan:
cortex-vec distill-plan start <raw-file>
Note the returned plan_id. If it errors ANOTHER_PLAN_ACTIVE, ask
the user whether to resume that plan or distill-plan clear it —
never switch Raws silently.
Traverse the map:
cortex-vec raw-map <raw-file> --plan-id <id>
cortex-vec raw-map <raw-file> --plan-id <id> --cursor <next_cursor>
Cards show kind / size / source range / preview / lexical anchors. The map never says "valuable" or "skip" — choosing what to expand is the main session's judgment.
Expand what needs reading. prose, output_body, ambiguous,
opaque spans (and any card with preview_complete: false you need)
must be read via:
cortex-vec raw-span <raw-file> --plan-id <id> --span-id <N>
cortex-vec raw-span <raw-file> --plan-id <id> --cursor <next_cursor>
Early positive stop: once you have concrete insight evidence, record it and stop expanding —
cortex-vec distill-plan evidence-add --plan-id <id> \
--char-start <s> --char-end <e> --label "<short cite>"
(the range must already be reviewed). Full coverage is NOT required for a positive candidate.
no-insight gate is mechanical: it requires
no_insight_candidate_allowed: true from
cortex-vec distill-plan status --plan-id <id>
which means the whole map was traversed AND every semantic /
ambiguous span was expanded. Do not propose no-insight before that.
On BUDGET_EXHAUSTED: stop reading, write the takeoff baton with the
plan_id, and continue in a fresh session via
cortex-vec distill-plan resume --plan-id <id> --new-session
Then apply has_insight() (below) to what you actually read.
has_insight() ruleAnswer Yes iff at least one passage anywhere in the Raw contains one of:
src/main.rs:226, checkDockerImage(), SynoBuildConf/unit-test).Insight commonly appears in any of these locations; treat them all as first-class:
★ Insight ───── callouts inside ### Claude blocks (Claude Code
learning-mode output).## Discoveries / ## Decisions sections (manually-edited
Raws — still valid but not required).Answer No only when the entire Raw genuinely lacks concrete referents — e.g., commands executed with no surrounding analysis, or vague statements like "fixed it" / "works now" / "tested successfully" without any mechanism / file / symbol / decision rationale anywhere in the body.
The has_insight() result above is a candidate verdict, not a
dispatch decision. Always present the candidate to the user and wait
for confirmation, even when the verdict feels obvious. The user's
answer is binding regardless of the agent's tilt.
Use AskUserQuestion with:
No, note explicitly that no concrete
referent was found anywhere in the body.Yes (has insight) or No (no insight).(y)es — agree with candidate(n)o — override to opposite(s)kip-routine — Raw not worth dedup nor recording (use when the
Raw is essentially a tool-recap / git-log dump that technically
passed has_insight on a symbol but has no surrounding analysis)Yes → proceed to Step 3 (Stage 2).No → no-insight, go to Step 5 (mark) + Step 7 (log).skip-routine → skip-routine, go to Step 5 + 7 + 8.
No broadcast prompt (Step 9 is skipped for skip-routine).The plan ledger enforces the per-session raw-derived cap (default 100K
chars, session_remaining_chars in every page). When a session has spent
a few plans' worth of budget, stop: commit finished Raws (Step 8) and
hand the queue to the next session via cortex-takeoff. When Step 4
quotes Raw text into a draft, verify the quote with grep -F against the
source, and keep the evidence ranges recorded via evidence-add.
When has_insight is Yes, optionally tag the extracted content for later lint:
| Tag | Signal | Example |
|---|---|---|
| 踩坑 (gotcha) | Non-obvious behavior, hidden trap | "jsoncpp returns null for oversized doubles" |
| 慣例 (convention) | Project-specific or internal practice | "Service A reads config.json, Service B reads env vars" |
| 決策 (decision) | Why A over B, trade-off rationale | "build-history.json over PID check because..." |
These tags no longer gate extraction — they are reserved metadata for future lint capability. Safe to omit if the use case is unclear; downstream tooling treats absence as untagged.
Only runs when Stage 1 returned Yes.
Read ~/.cortex/config.json:
jq -r '.distill.dedup_threshold_new // 0.45' ~/.cortex/config.json
jq -r '.distill.dedup_threshold_pending // 0.60' ~/.cortex/config.json
Defaults: new = 0.45, pending = 0.60.
Pick the most content-ful insight passage anywhere in the Raw as the
query text — typically the densest ★ Insight ───── callout, the
clearest analysis paragraph naming specific referents, or (for legacy
Raws) the longest Discovery/Decision bullet. Aim for one self-contained
chunk that mentions the concrete symbol / mechanism / decision; trim
to roughly one paragraph. Run:
cortex-vec search "<bullet text>" --n 3
If the repo is known from Raw frontmatter, add --repo <name> when searching Projects-bound content.
--repo narrows the Projects/ partition only; cross-repo Notes/ always appear in results regardless of the filter. Safe to add when the Raw is repo-specific.
Extract top-1 score from the JSON output.
If cortex-vec is unavailable (command errors, ECONNREFUSED, etc.): treat as score = 0.0, log dedup_top1: unavailable, prefer false-positive new over losing the insight.
Always ask the user, regardless of where score falls. The threshold table below degrades from gate to candidate-outcome heuristic — it shapes the recommendation the agent surfaces, but never decides unilaterally.
Use AskUserQuestion with:
0.62).[[wikilink]] + ≤1-line excerpt from that page.(n)ew / (p)ending-merge / (s)kip-routine.| Score band | Candidate outcome to propose |
|---|---|
score < dedup_threshold_new | new (low overlap with existing pages) |
dedup_threshold_new ≤ score < dedup_threshold_pending | describe both new and pending-merge neutrally; no strong tilt |
score ≥ dedup_threshold_pending | pending-merge (strong overlap with top-1) |
When to tilt toward skip-routine (independent of score): the Raw
passed Stage 1 only because of an isolated symbol mention with no
surrounding analysis — e.g., a git-log dump that happens to name a file
path. Surface (s)kip-routine as a real candidate in such cases rather
than forcing new / pending-merge.
(n)ew → go to Step 4 (create) + Step 5 + 6 + 7 + 8.(p)ending-merge → skip Steps 4 and 6; go to Step 5 + 7 + 8 only.
Do not write any new file or touch existing pages.(s)kip-routine → skip Steps 4 and 6; go to Step 5 + 7 + 8 only.
Marker writes as (skip: routine).Projects/<repo>/ (repo from Raw file's repo: frontmatter)Notes/<category>/ (match existing categories)repos: to frontmatter if repo-specificThe marker must not be written until the plan is sealed (Notes/log all written, the user has confirmed the verdict):
cortex-vec distill-plan seal --plan-id <id> --expected-outcome <new|pending-merge|skip-routine|no-insight>
After sealing, map/span pages are rejected (PLAN_SEALED); only then
append the marker.
Append exactly one marker to the Raw file, chosen by Step 3 outcome:
| Outcome | Marker |
|---|---|
new | <!-- distilled: YYYY-MM-DD → <target-relative-path> --> |
pending-merge | <!-- distilled: YYYY-MM-DD → pending-merge: <existing-path> (<score>) --> |
skip-routine | <!-- distilled: YYYY-MM-DD → (skip: routine) --> |
no-insight | <!-- distilled: YYYY-MM-DD → (no insight) --> |
Score formatting: two decimal places (e.g., 0.62, not 0.62345).
Date: today, YYYY-MM-DD.
new outcome)Skip this step entirely for pending-merge, skip-routine, no-insight.
For each newly created file:
cortex-vec upsert <relative-path>_index.md: append row to the appropriate table (Notes or Projects section), update entries count and updated date in frontmatter.For each Raw processed (regardless of outcome), append exactly one entry to <vault>/log.md:
## [YYYY-MM-DD HH:MM] distill | <raw-filename>
- outcome: <new|pending-merge|skip-routine|no-insight>
- target: <vault-relative path | omit for skip-routine and no-insight>
- dedup_top1: <score → [[wikilink]] | "unavailable" | omit for no-insight>
- repo: <value from Raw frontmatter repo: field | "(none)">
The agent should:
<vault>/log.md using either the Edit tool (preferred — adds the entry and preserves file integrity) or bash:printf '\n%s\n' "$ENTRY" >> "<vault>/log.md"
Where $ENTRY is the fully-substituted markdown entry.
Preserve exactly one blank line between entries (achieved by the leading \n in the printf above, or by ensuring the Edit tool's new content starts with a blank line when appending).
Field rules:
target: present for new and pending-merge. Omit the line for skip-routine and no-insight.dedup_top1: include the score and top-1 page wikilink whenever Stage 2 ran (outcomes: new when score was computed, pending-merge, all interactive choices, skip-routine). Omit only for no-insight (Stage 2 did not run). For cortex-vec unavailable, write dedup_top1: unavailable.repo: use (none) if the Raw has no repo: frontmatter field.cd <vault>
git add Raw/ Notes/ Projects/ _index.md log.md
git commit -m "distill: extract N entries from Raw"
If auto_push is true in config: git push.
After the commit completes, close the plan (this verifies the only file change was the expected marker):
cortex-vec distill-plan complete --plan-id <id>
If it returns RAW_CHANGED, the Raw has changed beyond just the marker —
stop and report, do not retry.
For each Raw whose terminal outcome was new or pending-merge,
dispatch to the cortex-broadcast skill inline immediately after
Step 8's commit. Do not prompt the user — every broadcast-eligible Raw
is broadcast.
Announce before dispatching:
Dispatching broadcast for <raw-filename>...
When broadcast completes, return here and move to the next unprocessed Raw.
For outcomes skip-routine and no-insight, broadcast is skipped by
definition (those Raws are ineligible).
The broadcast skill carries its own abort semantics — there is no gate at this layer:
quit to abort
before any page commits. The Raw stays in the broadcast-eligible
queue (no | broadcast: marker is written), so it can be picked up
by a future standalone /cortex:broadcast run.abort
/ cancel to end the session. Prior committed pages stand; the Raw
marker is left unchanged.To opt out entirely at the very first prompt broadcast surfaces, the
user just types quit at the Step 7 menu.
Raws historically marked | no-broadcast: <date> (from the previous
prompt-based gate design) are still filtered out by cortex-broadcast
Step 2's queue builder. This skill no longer produces that marker, but
it remains a recognized legacy opt-out signal.