From aaeabf30715fadf33223ffa55422200ceb13547d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kope=C4=87?= Date: Mon, 2 Nov 2026 19:34:30 +0100 Subject: [PATCH] Template 1.22.1: hooks start from the project root Claude Code runs a hook in the session's current directory, so the autosave Stop hook's relative script path followed the shell into subfolders: a session working inside a nested repo saved its transcript there. autosave_hook.py and start_hook.py now write `cd "${CLAUDE_PROJECT_DIR:-.}" && ...`; --check flags an entry from before the fix as outdated and --install replaces it, keeping other hooks. Smoke test fires both installed hooks from a subfolder. Co-Authored-By: Claude Opus 5.5 --- .agents/skills/ckb-add-conversation/SKILL.md | 7 +++- .../scripts/autosave_hook.py | 41 +++++++++++++++---- .agents/skills/ckb-lint/SKILL.md | 4 +- .agents/skills/ckb-lint/scripts/start_hook.py | 39 ++++++++++++++---- VERSION | 2 +- docs/CHANGELOG.md | 3 +- docs/CHANGELOG.pl.md | 3 +- tests/smoke.sh | 23 +++++++++++ 8 files changed, 103 insertions(+), 19 deletions(-) diff --git a/.agents/skills/ckb-add-conversation/SKILL.md b/.agents/skills/ckb-add-conversation/SKILL.md index 75bf908..dcdc120 100644 --- a/.agents/skills/ckb-add-conversation/SKILL.md +++ b/.agents/skills/ckb-add-conversation/SKILL.md @@ -190,7 +190,12 @@ to be brought in line separately. `scripts/autosave_hook.py` does that: `--install` takes `--python ` so the hook command uses the interpreter that actually works on this machine (resolve `` as `AGENTS.md` §3 describes and pass it). It merges into an existing file and refuses to -touch one that is not valid JSON. +touch one that is not valid JSON. The command starts with +`cd "${CLAUDE_PROJECT_DIR:-.}"`, because Claude Code runs a hook in the +session's current directory: without it, a session whose shell had moved into +a subfolder (a nested repo, say) saved its transcript there. `--check` +reports an entry installed before 1.22.1 as outdated, and `--install` +replaces it in place. **Never change machine configuration silently.** Two moments call for the check, and both end in a question, not an action: diff --git a/.agents/skills/ckb-add-conversation/scripts/autosave_hook.py b/.agents/skills/ckb-add-conversation/scripts/autosave_hook.py index 1cce3c1..9f6ce33 100644 --- a/.agents/skills/ckb-add-conversation/scripts/autosave_hook.py +++ b/.agents/skills/ckb-add-conversation/scripts/autosave_hook.py @@ -47,8 +47,24 @@ def load_settings(): sys.exit(f"error: {SETTINGS} is not valid JSON ({e}); fix it by hand before installing the hook") +# Claude Code runs a hook in the session's current directory, which need not be +# the KB root: start from the project root so the relative script path and the +# save location both resolve to this KB. +ROOT_CD = 'cd "${CLAUDE_PROJECT_DIR:-.}" && ' + + def hook_command(python: str) -> str: - return f"{python} {SCRIPT} --from-hook >/dev/null 2>&1 || true" + return f"{ROOT_CD}{python} {SCRIPT} --from-hook >/dev/null 2>&1 || true" + + +def outdated(settings) -> bool: + """An entry installed before hooks started from the project root.""" + for group in settings.get("hooks", {}).get("Stop", []) or []: + for h in group.get("hooks", []) or []: + command = str(h.get("command", "")) + if MARK in command and "CLAUDE_PROJECT_DIR" not in command: + return True + return False def installed(settings) -> bool: @@ -61,9 +77,11 @@ def installed(settings) -> bool: def install(python: str): s = load_settings() - if installed(s): + if installed(s) and not outdated(s): print(f"already installed in {SETTINGS}") return + if installed(s): + strip(s) s.setdefault("hooks", {}).setdefault("Stop", []).append( {"hooks": [{"type": "command", "command": hook_command(python)}]}) SETTINGS.parent.mkdir(parents=True, exist_ok=True) @@ -71,11 +89,8 @@ def install(python: str): print(f"installed Stop hook in {SETTINGS}: {hook_command(python)}") -def remove(): - s = load_settings() - if not installed(s): - print(f"not installed in {SETTINGS}") - return +def strip(s): + """Drop this hook's entries from settings `s`, keeping every other hook.""" groups = [] for group in s["hooks"]["Stop"]: kept = [h for h in group.get("hooks", []) if MARK not in str(h.get("command", ""))] @@ -88,6 +103,14 @@ def remove(): del s["hooks"]["Stop"] if not s["hooks"]: del s["hooks"] + + +def remove(): + s = load_settings() + if not installed(s): + print(f"not installed in {SETTINGS}") + return + strip(s) SETTINGS.write_text(json.dumps(s, indent=2) + "\n", encoding="utf-8") print(f"removed Stop hook from {SETTINGS}") @@ -101,6 +124,10 @@ def check() -> int: if not auto and have: print(f"autosave: off in ckb.yaml, but a Stop hook is still installed in {SETTINGS} — ask the user, then --remove") return 1 + if have and outdated(load_settings()): + print(f"autosave: Stop hook in {SETTINGS} does not start from the project root, so it can save into " + "the wrong folder — ask the user, then --install to replace it") + return 1 print(f"autosave: {'on, hook installed' if auto else 'off, no hook'}") return 0 diff --git a/.agents/skills/ckb-lint/SKILL.md b/.agents/skills/ckb-lint/SKILL.md index 56600f7..107f3c6 100644 --- a/.agents/skills/ckb-lint/SKILL.md +++ b/.agents/skills/ckb-lint/SKILL.md @@ -339,7 +339,9 @@ installs it as a Claude Code `SessionStart` hook, so the brief is in context before the first message and comes back after every compaction. It is opt-in per KB (`session: start_hook: true` in `ckb.yaml`) and installed per machine in the gitignored `.claude/settings.local.json`, never in a -committed settings file: a committed hook runs code on every clone. +committed settings file: a committed hook runs code on every clone. Its +command starts from `$CLAUDE_PROJECT_DIR`, so it works whatever directory +the session's shell is in. When the session-start brief prints a `start hook:` line, ask once and act only on a yes: diff --git a/.agents/skills/ckb-lint/scripts/start_hook.py b/.agents/skills/ckb-lint/scripts/start_hook.py index 39e6619..c3c4295 100644 --- a/.agents/skills/ckb-lint/scripts/start_hook.py +++ b/.agents/skills/ckb-lint/scripts/start_hook.py @@ -51,9 +51,24 @@ def load_settings(): sys.exit(f"error: {SETTINGS} is not valid JSON ({e}); fix it by hand before installing the hook") +# Claude Code runs a hook in the session's current directory, which need not be +# the KB root: start from the project root so the relative script path resolves. +ROOT_CD = 'cd "${CLAUDE_PROJECT_DIR:-.}" && ' + + def hook_command(python: str) -> str: # A failing brief must never block the session: no stderr, always exit 0. - return f"{python} {SCRIPT} --hook 2>/dev/null || true" + return f"{ROOT_CD}{python} {SCRIPT} --hook 2>/dev/null || true" + + +def outdated(settings) -> bool: + """An entry installed before hooks started from the project root.""" + for group in settings.get("hooks", {}).get(EVENT, []) or []: + for h in group.get("hooks", []) or []: + command = str(h.get("command", "")) + if MARK in command and "CLAUDE_PROJECT_DIR" not in command: + return True + return False def installed(settings) -> bool: @@ -66,9 +81,11 @@ def installed(settings) -> bool: def install(python: str): s = load_settings() - if installed(s): + if installed(s) and not outdated(s): print(f"already installed in {SETTINGS}") return + if installed(s): + strip(s) s.setdefault("hooks", {}).setdefault(EVENT, []).append( {"hooks": [{"type": "command", "command": hook_command(python)}]}) SETTINGS.parent.mkdir(parents=True, exist_ok=True) @@ -76,11 +93,8 @@ def install(python: str): print(f"installed {EVENT} hook in {SETTINGS}: {hook_command(python)}") -def remove(): - s = load_settings() - if not installed(s): - print(f"not installed in {SETTINGS}") - return +def strip(s): + """Drop this hook's entries from settings `s`, keeping every other hook.""" groups = [] for group in s["hooks"][EVENT]: kept = [h for h in group.get("hooks", []) if MARK not in str(h.get("command", ""))] @@ -93,6 +107,14 @@ def remove(): del s["hooks"][EVENT] if not s["hooks"]: del s["hooks"] + + +def remove(): + s = load_settings() + if not installed(s): + print(f"not installed in {SETTINGS}") + return + strip(s) SETTINGS.write_text(json.dumps(s, indent=2) + "\n", encoding="utf-8") print(f"removed {EVENT} hook from {SETTINGS}") @@ -106,6 +128,9 @@ def check() -> int: if not want and have: print(f"off in ckb.yaml, but a {EVENT} hook is still installed in {SETTINGS} — ask the user, then --remove") return 1 + if have and outdated(load_settings()): + print(f"{EVENT} hook in {SETTINGS} does not start from the project root — ask the user, then --install to replace it") + return 1 print(f"{'on, hook installed' if want else 'off, no hook'}") return 0 diff --git a/VERSION b/VERSION index 57807d6..6245bee 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.22.0 +1.22.1 diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4397b8a..26f0231 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -284,7 +284,8 @@ docs. Independent of the content schema above. | Version | Date | What landed | Schema | |---|---|---|---| -| **1.22.0** | 2026-11-02 | Agent-knowledge release 1: seven features from the 2026-10-31 research, no schema change. **Session-start hook (F1):** `session_start.py --hook` prints the Rule E brief as `SessionStart` `additionalContext` on startup, resume, `/clear` and after every compaction; `start_hook.py --check/--install/--remove` manages it in the gitignored `.claude/settings.local.json`; opt-in via `session: start_hook:` in `ckb.yaml`, with a `start hook:` brief line when the two disagree; Rule E stays the fallback (D-0011). **Kept answers (F2):** `ckb-retrieve` Step 8 offers to keep a substantial answer in `outputs/answers/` (`type: answer`) with fingerprinted `## Sources` and `## Gaps`, updates rather than duplicates, and files back only through ingest; lint check 16 reports kept answers whose sources moved (D-0013). **Ingest check-in (F3):** before writing, `ckb-ingest` shows its reading of each source, the pages it will touch and what it contradicts, then waits; batch mode ("ingest in batch", or a `confirm: false` routine) skips it; the ingest report gains `## Check-in`. **Open threads (F5):** `### Open threads` checkboxes in workload notes (Rule D), collected by `session_start.py` into a `threads:` line with the five oldest and a 30-day stale mark; no shared status file (D-0012). **Capture-time dedup (F6):** new `ckb-ingest/scripts/dedup_inbox.py` reports `DUPLICATE`, `SAME TEXT`, `CITED`, `SAME URL` and `INBOX TWIN` against `raw/archive/` and cited fingerprints/URLs before ingest. **Secret and privacy guards (F19):** lint check 15 scans committed text for credential shapes and `wiki/` for `` spans, masks matches, honours a line-hash `.secrets-allow`; `--quick` counts it, `--secrets` runs it alone and `ckb-sync-changes` runs it before staging; ingest drops and retrieval never quotes `` spans; `save_conversation.py` redacts them (D-0013). **Context budget (F20):** `lint_report.py --budget` estimates `AGENTS.md` plus skill descriptions at characters ÷ 4; `--quick` flags it above `budget: always_loaded_tokens` (default 9000). Baseline: ~6,620 tokens at 1.21.0, ~6,810 at 1.22.0. Bash/PowerShell quick fallbacks gain a reduced secret check; smoke test covers every new script | 1.5 | +| **1.22.1** | 2026-11-02 | Hooks start from the project root. Claude Code runs a hook in the session's current directory, so the autosave Stop hook's relative `save_conversation.py` path resolved against whatever folder the shell had moved into: a session working inside a nested repo saved its transcript there, and in a folder without the script the save failed silently. `autosave_hook.py` and `start_hook.py` now write `cd "${CLAUDE_PROJECT_DIR:-.}" && …`; `--check` reports an entry installed before this fix as outdated (the session-start brief asks once), and `--install` replaces it without touching other hooks. Smoke test runs both installed hooks from a subfolder | 1.5 | +| 1.22.0 | 2026-11-02 | Agent-knowledge release 1: seven features from the 2026-10-31 research, no schema change. **Session-start hook (F1):** `session_start.py --hook` prints the Rule E brief as `SessionStart` `additionalContext` on startup, resume, `/clear` and after every compaction; `start_hook.py --check/--install/--remove` manages it in the gitignored `.claude/settings.local.json`; opt-in via `session: start_hook:` in `ckb.yaml`, with a `start hook:` brief line when the two disagree; Rule E stays the fallback (D-0011). **Kept answers (F2):** `ckb-retrieve` Step 8 offers to keep a substantial answer in `outputs/answers/` (`type: answer`) with fingerprinted `## Sources` and `## Gaps`, updates rather than duplicates, and files back only through ingest; lint check 16 reports kept answers whose sources moved (D-0013). **Ingest check-in (F3):** before writing, `ckb-ingest` shows its reading of each source, the pages it will touch and what it contradicts, then waits; batch mode ("ingest in batch", or a `confirm: false` routine) skips it; the ingest report gains `## Check-in`. **Open threads (F5):** `### Open threads` checkboxes in workload notes (Rule D), collected by `session_start.py` into a `threads:` line with the five oldest and a 30-day stale mark; no shared status file (D-0012). **Capture-time dedup (F6):** new `ckb-ingest/scripts/dedup_inbox.py` reports `DUPLICATE`, `SAME TEXT`, `CITED`, `SAME URL` and `INBOX TWIN` against `raw/archive/` and cited fingerprints/URLs before ingest. **Secret and privacy guards (F19):** lint check 15 scans committed text for credential shapes and `wiki/` for `` spans, masks matches, honours a line-hash `.secrets-allow`; `--quick` counts it, `--secrets` runs it alone and `ckb-sync-changes` runs it before staging; ingest drops and retrieval never quotes `` spans; `save_conversation.py` redacts them (D-0013). **Context budget (F20):** `lint_report.py --budget` estimates `AGENTS.md` plus skill descriptions at characters ÷ 4; `--quick` flags it above `budget: always_loaded_tokens` (default 9000). Baseline: ~6,620 tokens at 1.21.0, ~6,810 at 1.22.0. Bash/PowerShell quick fallbacks gain a reduced secret check; smoke test covers every new script | 1.5 | | 1.21.0 | 2026-10-31 | `ABOUT.md`. New root file, written by the KB's owner, stating what the KB holds: purpose, audience, scope (in and out), owners and contacts, expected sources, sensitivity, language and terms, each shipped as a comment saying what to write; `type: about` with a `tldr`. `README.md`/`README.pl.md` link to it under the source-repo pointer, since the README itself is the template's and is overwritten on upgrade. Agents read it and never edit it unless asked; questions about the KB itself are answered from it before `wiki/overview.md`, which stays the agent's summary of what was ingested and now links to it. `ckb-ingest` Step 1 names material outside its scope or ruled out by its sensitivity section and ingests it only on the user's say-so. `ckb-init` copies the scaffold and asks one optional question for Purpose and `tldr`; `ckb-upgrade` creates it only when missing and never diffs it; `ckb-reset` never touches it. `mcp` module: `kb_overview` starts with it and the server's KB description comes from its `tldr` (the scaffold placeholder is ignored). Directory contract and manual updated. D-0010 | 1.5 | | 1.20.0 | 2026-10-30 | Ingest reports. `ckb-ingest` gains Step 8: every run that ingested something writes one file, `workload/ingest-reports/YYYY-MM-DD_HHMM__ingest.md` (`type: ingest-report`), listing raw files taken in and their archive path and fingerprint, decisions recorded, entities created/updated, other pages, graph edges, the blast radius (confirmed/extended/contradicted with owners, query gaps closed) and inbox files not ingested; every section kept with `- none` when empty. Written once, outside retrieval, no `wiki/log.md` entry, untouched by `ckb-retract`; a subfolder so `session_start.py` keeps reading only session notes. The old Step 8 (summary and sync reminder) becomes Step 9 and names the report. Directory contract, manual and `ckb-reset` tier 2 updated | 1.5 | | 1.19.0 | 2026-10-29 | Less context per session and per skill. New `ckb-lint/scripts/session_start.py` does Rule E's session start in one call (identity, `--title` stored unless one is already set, `announce_title`, git status, `lint_report.py --quick`, `autosave_hook.py --check` only when it needs action, `routines.py --due`, and the last block of the latest `workload/` note instead of the whole file); Rule E in `AGENTS.md` shrinks to the command plus what to do with each output line. The session-start read of `wiki/index.md` is dropped: every skill that needs the index reads it itself, so it was read twice. Every skill's `## Purpose` is cut to what its description does not already say (16.2k → 7.8k characters across the twenty skills). `ckb-upgrade` no longer repeats Rule B's log-entry format inline. Smoke test covers the new script. D-0009 | 1.5 | diff --git a/docs/CHANGELOG.pl.md b/docs/CHANGELOG.pl.md index a997a51..9b53c4f 100644 --- a/docs/CHANGELOG.pl.md +++ b/docs/CHANGELOG.pl.md @@ -291,7 +291,8 @@ Niezależna od schematu treści powyżej. | Wersja | Data | Co weszło | Schemat | |---|---|---|---| -| **1.22.0** | 2026-11-02 | Wiedza dla agentów, wydanie 1: siedem funkcji z badania z 2026-10-31, bez zmiany schematu. **Hook startu sesji (F1):** `session_start.py --hook` wypisuje podsumowanie z reguły E jako `additionalContext` hooka `SessionStart` przy starcie, wznowieniu, `/clear` i po każdym kompaktowaniu; `start_hook.py --check/--install/--remove` zarządza nim w ignorowanym przez gita `.claude/settings.local.json`; włączany przez `session: start_hook:` w `ckb.yaml`, z linią `start hook:` w podsumowaniu, gdy oba się nie zgadzają; reguła E zostaje jako zapas (D-0011). **Zachowane odpowiedzi (F2):** krok 8 `ckb-retrieve` proponuje zachowanie istotnej odpowiedzi w `outputs/answers/` (`type: answer`) ze skrótami w `## Sources` i sekcją `## Gaps`, aktualizuje zamiast dublować i wprowadza do wiki tylko przez ingest; kontrola 16 lintu zgłasza zachowane odpowiedzi, których źródła się zmieniły (D-0013). **Meldunek przed ingestem (F3):** zanim cokolwiek zapisze, `ckb-ingest` pokazuje, jak rozumie każde źródło, które strony zmieni i z czym jest sprzeczne, po czym czeka; tryb wsadowy („ingest in batch” albo rutyna z `confirm: false`) to pomija; raport ingestu dostaje sekcję `## Check-in`. **Otwarte wątki (F5):** pola `### Open threads` w notatkach workload (reguła D), zbierane przez `session_start.py` w linię `threads:` z pięcioma najstarszymi i znacznikiem po 30 dniach; bez wspólnego pliku statusu (D-0012). **Deduplikacja przy wejściu (F6):** nowy `ckb-ingest/scripts/dedup_inbox.py` zgłasza `DUPLICATE`, `SAME TEXT`, `CITED`, `SAME URL` i `INBOX TWIN` względem `raw/archive/` oraz cytowanych skrótów i adresów URL przed ingestem. **Ochrona sekretów i prywatności (F19):** kontrola 15 lintu szuka postaci danych uwierzytelniających w commitowanym tekście i fragmentów `` w `wiki/`, maskuje dopasowania, honoruje `.secrets-allow` oparte na skrócie linii; `--quick` ją liczy, `--secrets` uruchamia ją osobno, a `ckb-sync-changes` przed stagingiem; ingest odrzuca, a retrieval nigdy nie cytuje fragmentów ``; `save_conversation.py` je redaguje (D-0013). **Budżet kontekstu (F20):** `lint_report.py --budget` szacuje `AGENTS.md` plus opisy skilli jako znaki ÷ 4; `--quick` flaguje przekroczenie `budget: always_loaded_tokens` (domyślnie 9000). Punkt odniesienia: ~6 620 tokenów w 1.21.0, ~6 810 w 1.22.0. Zapasowe kontrole bash/PowerShell dostają okrojoną kontrolę sekretów; test dymny obejmuje każdy nowy skrypt | 1.5 | +| **1.22.1** | 2026-11-02 | Hooki startują z katalogu głównego projektu. Claude Code uruchamia hook w bieżącym katalogu sesji, więc względna ścieżka `save_conversation.py` w hooku autozapisu `Stop` rozwiązywała się względem folderu, do którego przeszła powłoka: sesja pracująca w zagnieżdżonym repozytorium zapisywała tam swój transkrypt, a w folderze bez skryptu zapis cicho się nie udawał. `autosave_hook.py` i `start_hook.py` zapisują teraz `cd "${CLAUDE_PROJECT_DIR:-.}" && …`; `--check` zgłasza wpis zainstalowany przed tą poprawką jako nieaktualny (podsumowanie startu sesji pyta raz), a `--install` podmienia go, nie ruszając innych hooków. Test dymny uruchamia oba zainstalowane hooki z podfolderu | 1.5 | +| 1.22.0 | 2026-11-02 | Wiedza dla agentów, wydanie 1: siedem funkcji z badania z 2026-10-31, bez zmiany schematu. **Hook startu sesji (F1):** `session_start.py --hook` wypisuje podsumowanie z reguły E jako `additionalContext` hooka `SessionStart` przy starcie, wznowieniu, `/clear` i po każdym kompaktowaniu; `start_hook.py --check/--install/--remove` zarządza nim w ignorowanym przez gita `.claude/settings.local.json`; włączany przez `session: start_hook:` w `ckb.yaml`, z linią `start hook:` w podsumowaniu, gdy oba się nie zgadzają; reguła E zostaje jako zapas (D-0011). **Zachowane odpowiedzi (F2):** krok 8 `ckb-retrieve` proponuje zachowanie istotnej odpowiedzi w `outputs/answers/` (`type: answer`) ze skrótami w `## Sources` i sekcją `## Gaps`, aktualizuje zamiast dublować i wprowadza do wiki tylko przez ingest; kontrola 16 lintu zgłasza zachowane odpowiedzi, których źródła się zmieniły (D-0013). **Meldunek przed ingestem (F3):** zanim cokolwiek zapisze, `ckb-ingest` pokazuje, jak rozumie każde źródło, które strony zmieni i z czym jest sprzeczne, po czym czeka; tryb wsadowy („ingest in batch” albo rutyna z `confirm: false`) to pomija; raport ingestu dostaje sekcję `## Check-in`. **Otwarte wątki (F5):** pola `### Open threads` w notatkach workload (reguła D), zbierane przez `session_start.py` w linię `threads:` z pięcioma najstarszymi i znacznikiem po 30 dniach; bez wspólnego pliku statusu (D-0012). **Deduplikacja przy wejściu (F6):** nowy `ckb-ingest/scripts/dedup_inbox.py` zgłasza `DUPLICATE`, `SAME TEXT`, `CITED`, `SAME URL` i `INBOX TWIN` względem `raw/archive/` oraz cytowanych skrótów i adresów URL przed ingestem. **Ochrona sekretów i prywatności (F19):** kontrola 15 lintu szuka postaci danych uwierzytelniających w commitowanym tekście i fragmentów `` w `wiki/`, maskuje dopasowania, honoruje `.secrets-allow` oparte na skrócie linii; `--quick` ją liczy, `--secrets` uruchamia ją osobno, a `ckb-sync-changes` przed stagingiem; ingest odrzuca, a retrieval nigdy nie cytuje fragmentów ``; `save_conversation.py` je redaguje (D-0013). **Budżet kontekstu (F20):** `lint_report.py --budget` szacuje `AGENTS.md` plus opisy skilli jako znaki ÷ 4; `--quick` flaguje przekroczenie `budget: always_loaded_tokens` (domyślnie 9000). Punkt odniesienia: ~6 620 tokenów w 1.21.0, ~6 810 w 1.22.0. Zapasowe kontrole bash/PowerShell dostają okrojoną kontrolę sekretów; test dymny obejmuje każdy nowy skrypt | 1.5 | | 1.21.0 | 2026-10-31 | `ABOUT.md`. Nowy plik w katalogu głównym, pisany przez właściciela KB, mówiący, co ta KB zawiera: cel, odbiorcy, zakres (co wchodzi, a co nie), właściciele i kontakty, oczekiwane źródła, poufność, język i terminy; każda sekcja ma komentarz, co w niej napisać; `type: about` z `tldr`. `README.md`/`README.pl.md` linkują do niego pod wskazaniem repozytorium źródłowego, bo samo README należy do szablonu i jest nadpisywane przy aktualizacji. Agenci go czytają i nie edytują bez prośby; pytania o samą KB dostają odpowiedź najpierw z niego, potem z `wiki/overview.md`, które pozostaje podsumowaniem agenta tego, co przetworzono, i teraz do niego linkuje. `ckb-ingest` w Kroku 1 wskazuje materiał spoza zakresu lub wykluczony przez sekcję poufności i przetwarza go tylko na wyraźną prośbę. `ckb-init` kopiuje szkielet i zadaje jedno opcjonalne pytanie o cel i `tldr`; `ckb-upgrade` tworzy go tylko, gdy go brak, i nigdy go nie porównuje; `ckb-reset` nigdy go nie rusza. Moduł `mcp`: `kb_overview` zaczyna się od niego, a opis KB serwera pochodzi z jego `tldr` (zastępczy tekst szkieletu jest pomijany). Zaktualizowano kontrakt katalogów i podręcznik. D-0010 | 1.5 | | 1.20.0 | 2026-10-30 | Raporty z ingestu. `ckb-ingest` dostaje Krok 8: każde uruchomienie, które coś przetworzyło, zapisuje jeden plik `workload/ingest-reports/YYYY-MM-DD_HHMM__ingest.md` (`type: ingest-report`) z listą przyjętych plików z `raw/` wraz ze ścieżką archiwum i odciskiem, zapisanych decyzji, utworzonych/zaktualizowanych encji, innych stron, krawędzi grafu, zasięgu zmian (potwierdzone/rozszerzone/sprzeczne z właścicielami, zamknięte luki w zapytaniach) oraz plików ze skrzynki, których nie przetworzono; każda sekcja zostaje, z `- none`, gdy jest pusta. Zapisywany raz, poza wyszukiwaniem, bez wpisu w `wiki/log.md`, nieruszany przez `ckb-retract`; podfolder, aby `session_start.py` nadal czytał tylko notatki sesji. Dotychczasowy Krok 8 (podsumowanie i przypomnienie o synchronizacji) staje się Krokiem 9 i wskazuje raport. Zaktualizowane: struktura katalogów, podręcznik i poziom 2 w `ckb-reset` | 1.5 | | 1.19.0 | 2026-10-29 | Mniej kontekstu na sesję i na skill. Nowy `ckb-lint/scripts/session_start.py` wykonuje start sesji z Reguły E jednym wywołaniem (tożsamość, `--title` zapisywany, chyba że tytuł już jest, `announce_title`, `git status`, `lint_report.py --quick`, `autosave_hook.py --check` tylko gdy wymaga działania, `routines.py --due` oraz ostatni blok najnowszej notatki `workload/` zamiast całego pliku); Reguła E w `AGENTS.md` skraca się do polecenia i tego, co zrobić z każdą linią wyniku. Odczyt `wiki/index.md` na starcie sesji usunięty: każdy skill, który potrzebuje indeksu, czyta go sam, więc był czytany dwa razy. `## Purpose` każdego skilla ograniczone do tego, czego nie mówi już jego opis (16,2k → 7,8k znaków w dwudziestu skillach). `ckb-upgrade` nie powtarza już formatu wpisu dziennika z Reguły B. Test dymny obejmuje nowy skrypt. D-0009 | 1.5 | diff --git a/tests/smoke.sh b/tests/smoke.sh index 26b327d..e535995 100755 --- a/tests/smoke.sh +++ b/tests/smoke.sh @@ -57,6 +57,23 @@ printf '\nsession:\n start_hook: true\n' >> "$TMP/start/ckb.yaml" HOOK=.agents/skills/ckb-lint/scripts/start_hook.py ( cd "$TMP/start" && ! python3 "$OLDPWD/$HOOK" --check >/dev/null && python3 "$OLDPWD/$HOOK" --install >/dev/null \ && python3 "$OLDPWD/$HOOK" --check >/dev/null && python3 "$OLDPWD/$HOOK" --remove >/dev/null ) > "$TMP/hook-cycle.txt" 2>&1 && echo ok >> "$TMP/hook-cycle.txt" +# Hooks run in the session's current directory: both must start from the project root. +FIXJSONL="$PWD/tests/fixtures/conversation/session.jsonl" +mkdir -p "$TMP/proj/sub" "$TMP/proj/wiki" "$TMP/proj/.claude" && ln -s "$PWD/.agents" "$TMP/proj/.agents" +OLDSTOP='python3 .agents/skills/ckb-add-conversation/scripts/save_conversation.py --from-hook >/dev/null 2>&1 || true' +python3 -c "import json,sys;json.dump({'hooks':{'Stop':[{'hooks':[{'type':'command','command':sys.argv[1]},{'type':'command','command':'keep me'}]}]}},open(sys.argv[2],'w'))" \ + "$OLDSTOP" "$TMP/proj/.claude/settings.local.json" +printf 'conversations:\n autosave: true\nsession:\n start_hook: true\n' > "$TMP/proj/ckb.yaml" +( cd "$TMP/proj" && ! python3 .agents/skills/ckb-add-conversation/scripts/autosave_hook.py --check >/dev/null \ + && python3 .agents/skills/ckb-add-conversation/scripts/autosave_hook.py --install >/dev/null \ + && python3 .agents/skills/ckb-add-conversation/scripts/autosave_hook.py --check >/dev/null \ + && python3 .agents/skills/ckb-lint/scripts/start_hook.py --install >/dev/null ) || echo "outdated hook not flagged or not replaced" > "$TMP/hookroot.err" +hookcmd() { python3 -c "import json,sys;print(next(h['command'] for g in json.load(open(sys.argv[1]))['hooks'][sys.argv[2]] for h in g['hooks'] if sys.argv[3] in h['command']))" \ + "$TMP/proj/.claude/settings.local.json" "$1" "$2"; } +STOPCMD=$(hookcmd Stop save_conversation.py 2>/dev/null) || true; STARTCMD=$(hookcmd SessionStart session_start.py 2>/dev/null) || true +( cd "$TMP/proj/sub" && echo "{\"transcript_path\": \"$FIXJSONL\"}" | CLAUDE_PROJECT_DIR="$TMP/proj" sh -c "${STOPCMD:-false}" ) || true +( cd "$TMP/proj/sub" && echo '{"source":"startup"}' | CLAUDE_PROJECT_DIR="$TMP/proj" sh -c "${STARTCMD:-false}" ) > "$TMP/hookroot.json" || true + # Secrets: two planted keys (one in a gitignored export, skipped), a private span in wiki/, then an allowlist line. mkdir -p "$TMP/sec" && cp -r "$FIX/." "$TMP/sec/" && mkdir -p "$TMP/sec/workload" "$TMP/sec/outputs/okf" echo "aws AKIAABCDEFGHIJKLMNOP here" > "$TMP/sec/workload/2026-09-01_x_summary.md" @@ -116,6 +133,12 @@ if ! diff -u "$TMP/sec.py.txt" "$TMP/sec.sh.txt"; then echo "DRIFT: lint_quick.s grep -q '\[redacted\]' "$TMP"/priv/raw/saved-conversations/"$TODAY"/*.md || { echo "save_conversation: redaction mark missing"; fail=1; } python3 -c "import json,sys;[json.loads(l) for l in open(sys.argv[1]) if l.strip()]" "$TMP"/priv/raw/saved-conversations/"$TODAY"/*.jsonl \ || { echo "save_conversation: redacted JSONL is not valid JSON"; fail=1; } +[[ ! -e "$TMP/hookroot.err" ]] || { cat "$TMP/hookroot.err"; fail=1; } +python3 -c "import json,sys;h=json.load(open(sys.argv[1]))['hooks']['Stop'];c=[x['command'] for g in h for x in g['hooks']];s=[x for x in c if 'save_conversation' in x];assert c.count('keep me')==1 and len(s)==1 and 'CLAUDE_PROJECT_DIR' in s[0]" \ + "$TMP/proj/.claude/settings.local.json" || { echo "autosave_hook --install: did not replace the outdated entry cleanly"; fail=1; } +ls "$TMP"/proj/raw/saved-conversations/*/*.md >/dev/null 2>&1 && [[ ! -e "$TMP/proj/sub/raw" ]] \ + || { echo "autosave hook: run from a subfolder, it did not save into the project root"; fail=1; } +grep -q 'ckb check:' "$TMP/hookroot.json" || { echo "start hook: run from a subfolder, it printed no brief"; fail=1; } # The template must stay inside its own context budget. python3 "$LINT" --budget > "$TMP/budget.txt" || { echo "budget: template is over its own always-loaded budget"; head -3 "$TMP/budget.txt"; fail=1; } # mcp module: what a remote client may read and write (no MCP SDK needed).