llm-wiki-kit 0.2.6 โ†’ 0.2.8

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
@@ -86,10 +86,11 @@ Use Claude Code or Codex normally.
86
86
 
87
87
  The installed hooks:
88
88
 
89
- - inject `wiki/memory.md`, `wiki/index.md`, and relevant wiki context at session start, instructions loaded, prompt submit, and post-compact time
89
+ - inject functional compact context at session start, instructions loaded, prompt submit, and post-compact time. The hook still uses `wiki/memory.md`, `wiki/index.md`, relevant wiki search results, maintenance signals, and update status; it formats only the useful parts so user-visible hook context does not look like a raw debug dump.
90
90
  - remove Codex-facing legacy `oh-my-codex:wiki`/`omx_wiki` surfaces at session start so `llm-wiki/` remains the active wiki implementation
91
91
  - record small redacted raw event envelopes and per-turn state
92
92
  - capture decision points, debugging findings, changed files, and verification notes
93
+ - before compaction, classify the current turn and save a redacted checkpoint for meaningful or durable work; durable candidates also get a maintenance queue item
93
94
  - allow tool calls to proceed without secret/PII-based hook blocking
94
95
  - update `llm-wiki/outputs/questions/YYYY-MM-DD-live-qa.md` only for meaningful work turns
95
96
  - avoid automatic `wiki/queries/` and `wiki/decisions/` promotion in the default answer-first mode
@@ -100,6 +101,7 @@ The installed hooks:
100
101
 
101
102
  If you need to think about saving every answer manually, the setup has failed.
102
103
  If wiki maintenance delays the actual answer, the setup is being used wrong. The default capture mode is `LLM_WIKI_KIT_CAPTURE_MODE=answer-first`; the old eager query/decision capture path remains only as deprecated compatibility mode via `LLM_WIKI_KIT_CAPTURE_MODE=legacy-eager`.
104
+ Pre-compact preservation uses `LLM_WIKI_KIT_PRECOMPACT_ENFORCEMENT=limited|soft|off` with default `limited`. It reads only a bounded transcript tail controlled by `LLM_WIKI_KIT_PRECOMPACT_TRANSCRIPT_TAIL_BYTES`; the raw transcript path and authentication values are redacted before any checkpoint is written.
103
105
 
104
106
  ## Operational Commands
105
107
 
@@ -119,11 +121,11 @@ Most users should not need these during daily Claude Code/Codex work. They exist
119
121
 
120
122
  `llm-wiki update` upgrades the global npm package when npm has a newer target, reinstalls the hook entries, and reapplies safe managed template updates across known project roots. If the installed runtime already satisfies the registry target, it skips `npm install -g` and still runs post-update maintenance. Use `--current-only` when you intentionally want to update only the supplied workspace. Existing wiki content is not overwritten. The command prints step progress to stderr, including registry lookup, npm install, post-update, and project discovery. Use `--timeout-ms <ms>` to bound external commands and `--max-dirs <n>` to bound project discovery under large or slow roots such as WSL `/mnt/*` trees.
121
123
 
122
- Installed npm runtimes also perform a cached update notice check from hooks while the user works. This does not install anything automatically. When a newer npm release is detected, the injected hook context gives the active agent a Korean update reminder and tells it to offer `llm-wiki update --workspace <project-or-search-root>`. The cache is scoped to the npm command used for lookup so test/fake npm checks do not leak into normal hook sessions. Set `LLM_WIKI_KIT_UPDATE_NOTICE=0` only when diagnosing or suppressing that reminder.
124
+ Installed npm runtimes also perform a cached update notice check from hooks while the user works. This does not install anything automatically. When a newer npm release is detected, Codex and Claude receive the same passive runtime update status in hook context: current runtime, npm registry target, and the manual command to use when the user asks for update or maintenance work. It is not an instruction to interrupt the current answer or to sell the update to the user. The cache is scoped to the npm command used for lookup so test/fake npm checks do not leak into normal hook sessions. Set `LLM_WIKI_KIT_UPDATE_NOTICE=0` only when diagnosing or suppressing that status block.
123
125
 
124
126
  `llm-wiki post-update --workspace <project>` reapplies the current runtime's hook entries and safe managed template updates without running `npm install -g`. Use `post-update --all --workspace <search-root>` to reapply templates across discovered project roots.
125
127
 
126
- `llm-wiki context "<query>"` prints the same layered context used by hooks. It is mainly for debugging what Codex/Claude Code will see; daily use should rely on hook injection. By default, episodic `wiki/queries/` pages are excluded from search unless they were promoted with `memory_type: semantic` or `procedural` and `importance >= 4`; use `--include-episodic` only when debugging old automatic query records.
128
+ `llm-wiki context "<query>"` prints the full debug view of the layered context sources used by hooks. Hook injection may render those sources as functional compact context for Codex and Claude, but this CLI stays verbose so maintainers can inspect retrieval, snippets, memory, index, and expansion behavior. Daily use should rely on hook injection. By default, episodic `wiki/queries/` pages are excluded from search unless they were promoted with `memory_type: semantic` or `procedural` and `importance >= 4`; use `--include-episodic` only when debugging old automatic query records.
127
129
 
128
130
  `llm-wiki lint` checks wiki health and detects outdated managed rules from older kit versions. Agents may use it before/after meaningful wiki maintenance.
129
131
 
@@ -171,6 +173,7 @@ llm-wiki hook claude Stop
171
173
  ## Security Defaults
172
174
 
173
175
  - Full raw transcript capture is disabled by default.
176
+ - PreCompact may read a small bounded transcript tail to create a redacted checkpoint, but it does not store the full transcript or raw `transcript_path`.
174
177
  - Tool calls are not blocked only because inputs look sensitive.
175
178
  - Authentication values such as tokens, passwords, and private keys are redacted before durable summaries are written.
176
179
  - Hook payloads are stored only as redacted event envelopes.
@@ -42,13 +42,14 @@ when no project `CLAUDE.md` exists. Existing `CLAUDE.md` files are not overwritt
42
42
 
43
43
  The hook records redacted turn summaries but does not deny tool calls only because an input looks sensitive. Hook payloads are stored as small redacted event envelopes rather than full transcripts, and context output is redacted field by field before it is returned to Claude Code.
44
44
 
45
- At `SessionStart`/`InstructionsLoaded`, the hook first attempts a safe managed-template refresh, recovers stale turn state into `outputs/maintenance/queue.md`, performs a cached npm update notice check for npm installs, then injects `llm-wiki/wiki/memory.md`, `llm-wiki/wiki/index.md`, recent log context, operating rules, a one-item maintenance summary when needed, any Korean update notice, and any maintenance note for outdated or customized managed rules. At `UserPromptSubmit`, it recovers stale turn state, searches wiki pages with MiniSearch or substring fallback, expands one-hop wikilinks, redacts context fields, performs the same cached update notice check, and injects the smallest useful context set. Update notice cache is scoped by npm command, and maintenance reminders are shown only when the prompt is wiki/maintenance related or matches a queue topic.
45
+ At `SessionStart`/`InstructionsLoaded`, the hook first attempts a safe managed-template refresh, recovers stale turn state into `outputs/maintenance/queue.md`, performs a cached npm update notice check for npm installs, then injects functional compact context. The context still uses `llm-wiki/wiki/memory.md`, `llm-wiki/wiki/index.md`, relevant wiki/search state, operating rules, maintenance signals, passive runtime update status, and managed-template cleanup notes; the hook formats those signals so they are usable if shown in the Claude Code UI. At `UserPromptSubmit`, it recovers stale turn state, searches wiki pages with MiniSearch or substring fallback, expands one-hop wikilinks, redacts context fields, performs the same cached update notice check, and injects the smallest useful functional compact context set. Update notice cache is scoped by npm command, and maintenance reminders are shown only when the prompt is wiki/maintenance related or matches a queue topic.
46
46
 
47
- `PostToolUse` and `PostToolBatch` record redacted tool summaries in the same turn buffer. `PreCompact` records a compaction note, and `PostCompact` records the note and returns fresh wiki context. In the default `answer-first` mode, `SubagentStop` does not create live Q&A, query, decision, or maintenance files. `Stop` and `SessionEnd` append live Q&A only for meaningful work turns and do not auto-create `wiki/queries/` or `wiki/decisions/`. If the user explicitly asked to record or document durable knowledge and no durable wiki update is detected, `Stop`/`SessionEnd` queue a pending maintenance item for agent review. `Stop` and `SessionEnd` then clear the per-session turn buffer; `SubagentStop` does not.
47
+ `PostToolUse` and `PostToolBatch` record redacted tool summaries in the same turn buffer. `PreCompact` classifies the current turn before compaction: simple turns record only a context note, meaningful work writes a live Q&A checkpoint, and durable candidates write both a checkpoint and a maintenance queue item. The checkpoint can include only a bounded redacted transcript tail, never the full raw transcript or raw `transcript_path`. `PostCompact` stores the redacted compact summary as a context note and returns fresh wiki context. In the default `answer-first` mode, `SubagentStop` does not create live Q&A, query, decision, or maintenance files. `Stop` and `SessionEnd` append live Q&A only for meaningful work turns and do not auto-create `wiki/queries/` or `wiki/decisions/`. If the user explicitly asked to record or document durable knowledge and no durable wiki update is detected, `Stop`/`SessionEnd` queue a pending maintenance item for agent review. `Stop` and `SessionEnd` then clear the per-session turn buffer; `SubagentStop` does not.
48
48
 
49
49
  Set `LLM_WIKI_KIT_AUTO_PROJECT_UPDATE=0` only while diagnosing automatic managed-template refresh behavior.
50
- Set `LLM_WIKI_KIT_UPDATE_NOTICE=0` only while suppressing the cached npm update reminder.
50
+ Set `LLM_WIKI_KIT_UPDATE_NOTICE=0` only while suppressing the cached passive runtime update status.
51
51
  Set `LLM_WIKI_KIT_CAPTURE_MODE=legacy-eager` only as deprecated compatibility mode for the old eager query/decision capture behavior.
52
+ Set `LLM_WIKI_KIT_PRECOMPACT_ENFORCEMENT=limited|soft|off` to tune pre-compact failure handling; default `limited` blocks only when checkpoint/queue preservation fails on providers with block support. `LLM_WIKI_KIT_PRECOMPACT_TRANSCRIPT_TAIL_BYTES` controls the bounded tail size.
52
53
 
53
54
  After installation or update, run:
54
55
 
@@ -29,20 +29,22 @@ Handled events:
29
29
 
30
30
  Expected behavior:
31
31
 
32
- - `SessionStart` first attempts a safe managed-template refresh, removes Codex-facing legacy `oh-my-codex:wiki`/`omx_wiki` surfaces when they reappear, recovers stale turn state into `outputs/maintenance/queue.md`, performs a cached npm update notice check for npm installs, then injects `llm-wiki/wiki/memory.md`, `llm-wiki/wiki/index.md`, recent log context, operating rules, a one-item maintenance summary when needed, any Korean update notice, and any maintenance note for outdated or customized managed rules.
33
- - `UserPromptSubmit` recovers stale turn state, searches project wiki pages with MiniSearch or substring fallback, expands one-hop wikilinks, redacts context fields, performs the same cached update notice check, and injects the smallest useful context set. Update notice cache is scoped by npm command, and maintenance reminders are shown only when the prompt is wiki/maintenance related or matches a queue topic.
32
+ - `SessionStart` first attempts a safe managed-template refresh, removes Codex-facing legacy `oh-my-codex:wiki`/`omx_wiki` surfaces when they reappear, recovers stale turn state into `outputs/maintenance/queue.md`, performs a cached npm update notice check for npm installs, then injects functional compact context. The context still uses `llm-wiki/wiki/memory.md`, `llm-wiki/wiki/index.md`, relevant wiki/search state, operating rules, maintenance signals, passive runtime update status, and managed-template cleanup notes; the hook formats those signals so they are usable if shown in the Codex UI.
33
+ - `UserPromptSubmit` recovers stale turn state, searches project wiki pages with MiniSearch or substring fallback, expands one-hop wikilinks, redacts context fields, performs the same cached update notice check, and injects the smallest useful functional compact context set. Update notice cache is scoped by npm command, and maintenance reminders are shown only when the prompt is wiki/maintenance related or matches a queue topic.
34
34
  - `PreToolUse` records redacted tool summaries without blocking tool calls.
35
35
  - `PostToolUse` records redacted tool summaries in a turn buffer.
36
- - `PreCompact` records a compaction note; `PostCompact` records the note and returns fresh wiki context.
36
+ - `PreCompact` classifies the current turn before compaction. Simple turns record only a context note; meaningful work writes a live Q&A checkpoint; durable candidates write both a checkpoint and a maintenance queue item. The checkpoint can include only a bounded redacted transcript tail, never the full raw transcript or raw `transcript_path`.
37
+ - `PostCompact` stores the redacted compact summary as a context note and returns fresh wiki context.
37
38
  - In the default `answer-first` mode, `SubagentStop` does not create live Q&A, query, decision, or maintenance files. `Stop` appends live Q&A only for meaningful work turns and does not auto-create `wiki/queries/` or `wiki/decisions/`.
38
39
  - If the user explicitly asked to record or document durable knowledge and no durable wiki update is detected, `Stop` queues a pending maintenance item for agent review.
39
40
  - `Stop` clears the per-session turn buffer after recording. `SubagentStop` leaves the parent turn buffer available for the final stop event.
40
41
 
41
- Hook payloads are stored as small redacted event envelopes rather than full transcripts. Context output is also redacted field by field before it is returned to Codex.
42
+ Hook payloads are stored as small redacted event envelopes rather than full transcripts. Context output is also redacted field by field before it is returned to Codex. Functional compact context is a presentation policy, not a feature reduction: Codex still receives the wiki memory, search, maintenance, and passive update signals needed for the hook workflow.
42
43
 
43
44
  Set `LLM_WIKI_KIT_AUTO_PROJECT_UPDATE=0` only while diagnosing automatic managed-template refresh behavior.
44
- Set `LLM_WIKI_KIT_UPDATE_NOTICE=0` only while suppressing the cached npm update reminder.
45
+ Set `LLM_WIKI_KIT_UPDATE_NOTICE=0` only while suppressing the cached passive runtime update status.
45
46
  Set `LLM_WIKI_KIT_CAPTURE_MODE=legacy-eager` only as deprecated compatibility mode for the old eager query/decision capture behavior.
47
+ Set `LLM_WIKI_KIT_PRECOMPACT_ENFORCEMENT=limited|soft|off` to tune pre-compact failure handling; default `limited` blocks only on supported providers when checkpoint/queue preservation fails. `LLM_WIKI_KIT_PRECOMPACT_TRANSCRIPT_TAIL_BYTES` controls the bounded tail size.
46
48
 
47
49
  Run these after install:
48
50
 
package/docs/manual.md CHANGED
@@ -50,7 +50,7 @@ llm-wiki/
50
50
  โ””โ”€โ”€ procedures/
51
51
  ```
52
52
 
53
- `wiki/memory.md`๋Š” hook context์— ๋“ค์–ด๊ฐ€๋Š” ์งง์€ hot index๋‹ค. ๊ธด ์„ค๋ช…์„ ๋ณต์‚ฌํ•˜์ง€ ๋ง๊ณ  ์ค‘์š”ํ•œ entry point๋งŒ ๋‘”๋‹ค.
53
+ `wiki/memory.md`๋Š” hook context์— ๋“ค์–ด๊ฐ€๋Š” ์งง์€ hot index๋‹ค. hook์€ ๊ธฐ๋Šฅ์„ ์œ ์ง€ํ•˜๋˜ ์‚ฌ์šฉ์ž ํ™”๋ฉด์— ๋ณด์ผ ์ˆ˜ ์žˆ๋Š” ๋ถ€๋ถ„์„ functional compact context๋กœ ์ •์ œํ•˜๋ฏ€๋กœ, ๊ธด ์„ค๋ช…์„ ๋ณต์‚ฌํ•˜์ง€ ๋ง๊ณ  ์ค‘์š”ํ•œ entry point๋งŒ ๋‘”๋‹ค.
54
54
 
55
55
  `wiki/index.md`๋Š” wiki ์ „์ฒด์˜ navigation map์ด๋‹ค. agent๋Š” ๋„“์€ ์งˆ๋ฌธ์„ ๋ฐ›์œผ๋ฉด ์—ฌ๊ธฐ์™€ `memory.md`์—์„œ ์‹œ์ž‘ํ•œ๋‹ค.
56
56
 
@@ -62,7 +62,8 @@ llm-wiki/
62
62
 
63
63
  ์„ค์น˜๋œ hook์€ ๋‹ค์Œ ์ผ์„ ์ž๋™์œผ๋กœ ์ˆ˜ํ–‰ํ•œ๋‹ค.
64
64
 
65
- - session start, prompt submit, post compact ์‹œ์ ์— `wiki/memory.md`, `wiki/index.md`, ๊ด€๋ จ wiki ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ context๋กœ ์ฃผ์ž…ํ•œ๋‹ค.
65
+ - session start, prompt submit, post compact ์‹œ์ ์— functional compact context๋ฅผ ์ฃผ์ž…ํ•œ๋‹ค. `wiki/memory.md`, `wiki/index.md`, ๊ด€๋ จ wiki ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ, maintenance signal, update status๋Š” ๊ณ„์† ์‚ฌ์šฉํ•˜๋˜ ์‚ฌ์šฉ์ž ํ™”๋ฉด์— ๋ณด์ผ ์ˆ˜ ์žˆ๋Š” hook context๋Š” ํ•„์š”ํ•œ ์ •๋ณด ์ค‘์‹ฌ์œผ๋กœ ์ •์ œํ•œ๋‹ค.
66
+ - pre compact ์‹œ์ ์—๋Š” ํ˜„์žฌ turn์„ ๋ถ„๋ฅ˜ํ•˜๊ณ , simple turn์€ context note๋งŒ ๋‚จ๊ธฐ๋ฉฐ, meaningful/durable turn์€ redacted live Q&A checkpoint์™€ ํ•„์š”ํ•œ maintenance queue ํ›„๋ณด๋ฅผ ๋‚จ๊ธด๋‹ค.
66
67
  - prompt/tool/result summary๋ฅผ redactionํ•œ ๋’ค turn buffer์— ๊ธฐ๋กํ•œ๋‹ค.
67
68
  - ์˜๋ฏธ ์žˆ๋Š” ์ž‘์—… turn๋งŒ `outputs/questions/YYYY-MM-DD-live-qa.md`์— live Q&A๋กœ ๋‚จ๊ธด๋‹ค.
68
69
  - ๊ธฐ๋ณธ answer-first mode์—์„œ๋Š” `wiki/queries/`์™€ `wiki/decisions/`๋ฅผ ๋งค turn ์ž๋™ ์ƒ์„ฑํ•˜์ง€ ์•Š๋Š”๋‹ค.
@@ -71,6 +72,8 @@ llm-wiki/
71
72
  - ์ƒˆ runtime์ด ์˜ค๋ž˜๋œ project rules/templates๋ฅผ ๋ฐœ๊ฒฌํ•˜๋ฉด ์•ˆ์ „ํ•˜๊ฒŒ ๊ฐฑ์‹  ๊ฐ€๋Šฅํ•œ managed file๋งŒ refreshํ•œ๋‹ค.
72
73
  - `SessionStart`/`InstructionsLoaded`์—์„œ Codex-facing legacy `oh-my-codex:wiki`/`omx_wiki` ์„ค์ •๊ณผ ์Šคํ‚ฌ ํ‘œ๋ฉด์ด ๋˜์‚ด์•„๋‚ฌ๋Š”์ง€ ํ™•์ธํ•˜๊ณ  ์ œ๊ฑฐํ•œ๋‹ค. wiki ๊ธฐ๋Šฅ์€ `llm-wiki/`๊ฐ€ ๋‹จ์ผ ํ™œ์„ฑ ๊ตฌํ˜„์ด๋‹ค.
73
74
 
75
+ hook UX ์ •์ฑ…์€ ๊ธฐ๋Šฅ ๋ณด์กด์ด ์šฐ์„ ์ด๋‹ค. Codex์™€ Claude Code ๋ชจ๋‘ ๊ฐ™์€ ๊ธฐ๋Šฅ ์‹ ํ˜ธ๋ฅผ ๋ฐ›์œผ๋ฉฐ, ์ฐจ์ด๋Š” raw dump๊ฐ€ ์•„๋‹ˆ๋ผ ์ฝ๊ธฐ ์‰ฌ์šด functional compact formatting์œผ๋กœ ๋ณด์—ฌ์ฃผ๋Š” ๊ฒƒ์ด๋‹ค.
76
+
74
77
  ๋งค๋ฒˆ ์ €์žฅ ์—ฌ๋ถ€๋ฅผ ์‚ฌ์šฉ์ž๊ฐ€ ๊ณ ๋ฏผํ•ด์•ผ ํ•œ๋‹ค๋ฉด ์ž˜๋ชป ์“ฐ๊ณ  ์žˆ๋Š” ๊ฒƒ์ด๋‹ค. ๋‹ต๋ณ€๋ณด๋‹ค wiki maintenance๊ฐ€ ๋จผ์ € ์˜ค๋ฉด ์•ˆ ๋œ๋‹ค. ํ˜„์žฌ ์‚ฌ์šฉ์ž ์š”์ฒญ์„ ๋จผ์ € ์ฒ˜๋ฆฌํ•˜๊ณ , ์˜ค๋ž˜ ์“ธ ์ง€์‹๋งŒ ํ•„์š”ํ•œ ๋งŒํผ ์ •๋ฆฌํ•œ๋‹ค.
75
78
 
76
79
  ## Capture Modes
@@ -161,7 +164,7 @@ llm-wiki update --workspace /path/to/search-root --timeout-ms 120000 --max-dirs
161
164
 
162
165
  `update`๋Š” source checkout์—์„œ self-updateํ•˜์ง€ ์•Š๋Š”๋‹ค. source checkout ๊ฐœ๋ฐœ ์ค‘์—๋Š” npm package๋‚˜ local tarball๋กœ global installํ•œ ๋’ค update behavior๋ฅผ ํ…Œ์ŠคํŠธํ•œ๋‹ค.
163
166
 
164
- global npm runtime์œผ๋กœ ์„ค์น˜๋œ ๊ฒฝ์šฐ hook์€ ์‚ฌ์šฉ ํ๋ฆ„ ์ค‘ cached update notice check๋ฅผ ์ˆ˜ํ–‰ํ•œ๋‹ค. ์ž๋™ ์„ค์น˜๋Š” ํ•˜์ง€ ์•Š๋Š”๋‹ค. ์ƒˆ npm release๊ฐ€ ๊ฐ์ง€๋˜๋ฉด hook context๊ฐ€ active agent์—๊ฒŒ ํ•œ๊ตญ์–ด๋กœ โ€œ์—…๋ฐ์ดํŠธ ๊ฐ€๋Šฅโ€์„ ์งง๊ฒŒ ์•Œ๋ฆฌ๊ณ  `llm-wiki update --workspace <project-or-search-root>` ์‹คํ–‰์„ ์ œ์•ˆํ•˜๊ฒŒ ํ•œ๋‹ค. cache๋Š” lookup์— ์‚ฌ์šฉํ•œ npm command๋ณ„๋กœ ๋ถ„๋ฆฌ๋˜์–ด test/fake npm ๊ฒฐ๊ณผ๊ฐ€ ์ผ๋ฐ˜ hook session์— ์„ž์ด์ง€ ์•Š๋Š”๋‹ค. `LLM_WIKI_KIT_UPDATE_NOTICE=0`์œผ๋กœ ์ด reminder๋งŒ ๋Œ ์ˆ˜ ์žˆ๋‹ค.
167
+ global npm runtime์œผ๋กœ ์„ค์น˜๋œ ๊ฒฝ์šฐ hook์€ ์‚ฌ์šฉ ํ๋ฆ„ ์ค‘ cached update notice check๋ฅผ ์ˆ˜ํ–‰ํ•œ๋‹ค. ์ž๋™ ์„ค์น˜๋Š” ํ•˜์ง€ ์•Š๋Š”๋‹ค. ์ƒˆ npm release๊ฐ€ ๊ฐ์ง€๋˜๋ฉด hook context์—๋Š” passive runtime update status๊ฐ€ ๋“ค์–ด๊ฐ„๋‹ค. ์ด block์€ ํ˜„์žฌ runtime, npm registry target, ์—…๋ฐ์ดํŠธ/์ •๋น„ ์š”์ฒญ์ด ์žˆ์„ ๋•Œ ์“ธ ์ˆ˜ ์žˆ๋Š” `llm-wiki update --workspace <project-or-search-root>` ๋ช…๋ น์„ ์งง๊ฒŒ ๋ณด์—ฌ์ฃผ๋Š” ์ƒํƒœ ์ •๋ณด๋‹ค. ํ˜„์žฌ ๋‹ต๋ณ€์„ ์ค‘๋‹จํ•˜๊ฑฐ๋‚˜ ์—…๋ฐ์ดํŠธ ๊ถŒ์œ ๋ฅผ ํ•˜๋ผ๋Š” ์ง€์‹œ๋ฌธ์ด ์•„๋‹ˆ๋‹ค. cache๋Š” lookup์— ์‚ฌ์šฉํ•œ npm command๋ณ„๋กœ ๋ถ„๋ฆฌ๋˜์–ด test/fake npm ๊ฒฐ๊ณผ๊ฐ€ ์ผ๋ฐ˜ hook session์— ์„ž์ด์ง€ ์•Š๋Š”๋‹ค. `LLM_WIKI_KIT_UPDATE_NOTICE=0`์œผ๋กœ ์ด status block๋งŒ ๋Œ ์ˆ˜ ์žˆ๋‹ค.
165
168
 
166
169
  ### `llm-wiki post-update`
167
170
 
@@ -260,7 +263,7 @@ older OMX/OMC/`omx_wiki/` material์€ migration input์ผ ๋ฟ์ด๋‹ค. ํ˜„์žฌ proje
260
263
 
261
264
  ### `llm-wiki context`
262
265
 
263
- hook์ด ์ฃผ์ž…ํ•˜๋Š” layered context๋ฅผ ์ˆ˜๋™์œผ๋กœ ํ™•์ธํ•œ๋‹ค.
266
+ hook์ด ์‚ฌ์šฉํ•˜๋Š” layered context source๋ฅผ full debug ํ˜•ํƒœ๋กœ ์ˆ˜๋™ ํ™•์ธํ•œ๋‹ค. Codex/Claude hook์€ ๊ฐ™์€ source๋ฅผ functional compact context๋กœ ์ •์ œํ•ด ์ฃผ์ž…ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ์ด CLI๋Š” retrieval๊ณผ formatting ๋ฌธ์ œ๋ฅผ ์ ๊ฒ€ํ•  ์ˆ˜ ์žˆ๋„๋ก verbose debug ์ถœ๋ ฅ์„ ์œ ์ง€ํ•œ๋‹ค.
264
267
 
265
268
  ```bash
266
269
  llm-wiki context "auth architecture" --workspace /path/to/project
@@ -382,7 +385,11 @@ Claude Code handled events:
382
385
  - `Stop`
383
386
  - `SessionEnd`
384
387
 
385
- Hook payload๋Š” full transcript๊ฐ€ ์•„๋‹ˆ๋ผ ์ž‘์€ redacted event envelope๋‹ค. context output๋„ field๋ณ„ redaction์„ ๊ฑฐ์นœ๋‹ค.
388
+ Hook payload๋Š” full transcript๊ฐ€ ์•„๋‹ˆ๋ผ ์ž‘์€ redacted event envelope๋‹ค. context output๋„ field๋ณ„ redaction์„ ๊ฑฐ์นœ๋‹ค. `PreCompact`๋Š” checkpoint ์ƒ์„ฑ์„ ์œ„ํ•ด ์ž‘์€ bounded transcript tail๋งŒ ์ฝ์„ ์ˆ˜ ์žˆ๊ณ , ์ €์žฅ ์ „ ์ธ์ฆ๊ฐ’๊ณผ raw `transcript_path`๋ฅผ redactionํ•œ๋‹ค.
389
+
390
+ Context๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” Codex/Claude hook event๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ฑฐํ•˜์ง€ ์•Š๋Š”๋‹ค. memory hot index, navigation index, relevant wiki hits, link expansion, maintenance signal, passive runtime update status๋ฅผ ๊ณ„์† ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ณ , ์‚ฌ์šฉ์ž ํ™”๋ฉด์— ๋ณด์ผ ์ˆ˜ ์žˆ๋Š” `additionalContext`๋งŒ functional compact context๋กœ ์ •์ œํ•œ๋‹ค. `llm-wiki context` CLI์˜ full debug ์ถœ๋ ฅ์€ ์ด hook formatting ์ •์ฑ…๊ณผ ๋ณ„๋„๋กœ ์œ ์ง€ํ•œ๋‹ค.
391
+
392
+ Pre-compact ๋ณด์กด์€ ๊ธฐ๋ณธ `LLM_WIKI_KIT_PRECOMPACT_ENFORCEMENT=limited`๋กœ ๋™์ž‘ํ•œ๋‹ค. `limited`๋Š” checkpoint/queue ์ €์žฅ ์‹คํŒจ ์‹œ block์„ ์ง€์›ํ•˜๋Š” provider์—์„œ๋งŒ compact block์„ ์‹œ๋„ํ•˜๊ณ , ๊ทธ ์™ธ์—๋Š” failure context๋ฅผ ๋‚จ๊ธด๋‹ค. `soft`๋Š” blockํ•˜์ง€ ์•Š๊ณ , `off`๋Š” ์‹คํŒจ output์„ ์–ต์ œํ•œ๋‹ค. `LLM_WIKI_KIT_PRECOMPACT_TRANSCRIPT_TAIL_BYTES`๋กœ transcript tail byte ํ•œ๋„๋ฅผ ์กฐ์ •ํ•œ๋‹ค.
386
393
 
387
394
  ## Security Defaults
388
395
 
@@ -392,6 +399,7 @@ Hook payload๋Š” full transcript๊ฐ€ ์•„๋‹ˆ๋ผ ์ž‘์€ redacted event envelope๋‹ค.
392
399
  - token, password, bearer credential, private key, `.env` ์›๋ฌธ ๊ฐ™์€ authentication value๋Š” durable summary์— ์“ฐ๊ธฐ ์ „ redactionํ•œ๋‹ค.
393
400
  - phone number, email, date, business identifier๋Š” local work context๋กœ ์œ ์šฉํ•  ์ˆ˜ ์žˆ์–ด ๊ธฐ๋ณธ ๋ณด์กดํ•œ๋‹ค.
394
401
  - full raw transcript capture๋Š” ๊ธฐ๋ณธ ๊ธฐ๋Šฅ์ด ์•„๋‹ˆ๋‹ค.
402
+ - `PreCompact` checkpoint๋Š” bounded redacted transcript tail๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ full transcript์™€ raw `transcript_path`๋Š” ์ €์žฅํ•˜์ง€ ์•Š๋Š”๋‹ค.
395
403
  - `llm-wiki lint`๋Š” wiki ์•ˆ์˜ secret-like content๋ฅผ error๋กœ ๋ณด๊ณ ํ•œ๋‹ค.
396
404
 
397
405
  ๋ฏผ๊ฐํ•œ raw command output, log, screenshot, transcript๋ฅผ ์ €์žฅํ•ด์•ผ ํ•  ๋•Œ๋Š” ๋จผ์ € redactionํ•œ๋‹ค. ์ธ์ฆ๊ฐ’์€ wiki, report, live Q&A, command history์— ๋‚จ๊ธฐ์ง€ ์•Š๋Š”๋‹ค.
@@ -118,7 +118,7 @@ llm-wiki maintenance --workspace /path/to/project
118
118
 
119
119
  `update --check [--to <version-or-tag>]` is online and asks npm for the target version. It reports `update available` only when that registry target is newer than the installed version, so it does not suggest downgrades.
120
120
 
121
- Installed npm runtimes also run a cached hook-side update notice check while the user works. It never installs automatically. If npm has a newer release, `SessionStart`/`InstructionsLoaded`/`UserPromptSubmit` context gives the active agent a Korean update reminder and tells it to offer `llm-wiki update --workspace <project-or-search-root>`. The cache is scoped to the npm command used for lookup so test/fake npm checks do not leak into normal hook sessions. Set `LLM_WIKI_KIT_UPDATE_NOTICE=0` to suppress this reminder while diagnosing.
121
+ Installed npm runtimes also run a cached hook-side update notice check while the user works. It never installs automatically. If npm has a newer release, `SessionStart`/`InstructionsLoaded`/`UserPromptSubmit` context includes a passive runtime update status for both Codex and Claude: current runtime, npm registry target, and the manual `llm-wiki update --workspace <project-or-search-root>` command to use when the user asks for update or maintenance work. It is not an active instruction to interrupt the current answer or tell the user to update. The cache is scoped to the npm command used for lookup so test/fake npm checks do not leak into normal hook sessions. Set `LLM_WIKI_KIT_UPDATE_NOTICE=0` to suppress this status block while diagnosing.
122
122
 
123
123
  `projects --workspace <search-root>` lists discovered project roots that have `llm-wiki/.kit-state.json` or an older `llm-wiki/wiki/index.md`, reports whether their managed templates are current, and prints the update commands for the search root.
124
124
 
@@ -141,13 +141,15 @@ After a plain `npm install -g llm-wiki-kit@latest`, existing hooks keep working
141
141
 
142
142
  ## Context And Wiki Maintenance
143
143
 
144
- Daily use should be Claude Code/Codex first. The user should not need to run a chain of `llm-wiki` commands while working. Hooks inject context automatically, but the current user answer takes priority over wiki cleanup. The active agent updates durable wiki pages when reusable project knowledge appears and the turn's importance or user consent justifies persistence.
144
+ Daily use should be Claude Code/Codex first. The user should not need to run a chain of `llm-wiki` commands while working. Hooks inject context automatically, but the current user answer takes priority over wiki cleanup. The active agent updates durable wiki pages when reusable project knowledge appears and the turn's importance or user consent justifies persistence. Hook context policy is function-first: memory, search, maintenance, and update signals remain available, while user-visible context is formatted as functional compact context instead of a raw dump.
145
145
 
146
- In the default `LLM_WIKI_KIT_CAPTURE_MODE=answer-first` mode, `Stop` and `SessionEnd` append live Q&A only for meaningful work turns. They do not auto-create `wiki/queries/` or `wiki/decisions/`. If the user explicitly asked for recording/documentation and no durable wiki update is detected, a pending cleanup candidate is written to `llm-wiki/outputs/maintenance/queue.md`. `SessionStart` and `UserPromptSubmit` also recover stale per-turn state into the same queue when the previous stop hook did not complete. `SessionStart` injects a one-item queue summary; `UserPromptSubmit` injects a soft reminder only when the prompt is wiki/maintenance related or matches a queue topic. This is a recovery and reminder layer, not a full transcript capture path.
146
+ In the default `LLM_WIKI_KIT_CAPTURE_MODE=answer-first` mode, `Stop` and `SessionEnd` append live Q&A only for meaningful work turns. They do not auto-create `wiki/queries/` or `wiki/decisions/`. If the user explicitly asked for recording/documentation and no durable wiki update is detected, a pending cleanup candidate is written to `llm-wiki/outputs/maintenance/queue.md`. `PreCompact` performs the same answer-first classification before context compaction: simple turns get only a context note, archive-worthy turns get a live Q&A checkpoint, and durable candidates get a checkpoint plus queue item. `SessionStart` and `UserPromptSubmit` also recover stale per-turn state into the same queue when the previous stop hook did not complete. `SessionStart` injects a one-item queue summary; `UserPromptSubmit` injects a soft reminder only when the prompt is wiki/maintenance related or matches a queue topic. This is a recovery and reminder layer, not a full transcript capture path.
147
+
148
+ Pre-compact preservation defaults to `LLM_WIKI_KIT_PRECOMPACT_ENFORCEMENT=limited`. In that mode, checkpoint/queue write failures can block compact only on providers that support hook blocking; otherwise the hook returns best-effort failure context. `soft` never blocks, and `off` suppresses failure output. `LLM_WIKI_KIT_PRECOMPACT_TRANSCRIPT_TAIL_BYTES` controls the small bounded transcript tail used for checkpoint context. Authentication values and the raw transcript path are redacted before storage.
147
149
 
148
150
  `LLM_WIKI_KIT_CAPTURE_MODE=legacy-eager` keeps the old eager live Q&A/query/decision/maintenance behavior for compatibility only. New projects should rely on the answer-first default.
149
151
 
150
- `llm-wiki context "<query>"` is the manual debug form of hook context injection. It reads:
152
+ `llm-wiki context "<query>"` is the manual full-debug form of the context sources used by hook injection. Hook output for Codex and Claude may be functionally compact, but this command remains verbose so maintainers can inspect all source layers. It reads:
151
153
 
152
154
  - `llm-wiki/wiki/memory.md` as the short hot index
153
155
  - `llm-wiki/wiki/index.md` as the navigation map
package/docs/security.md CHANGED
@@ -13,4 +13,4 @@ Before writing durable summaries, the runtime redacts authentication values such
13
13
 
14
14
  Manual and hook context output also runs through redaction before returning excerpts or search hits. `llm-wiki lint` reports remaining secret-like wiki content as an error so it can be removed or rewritten before it becomes reusable project memory.
15
15
 
16
- Hook payloads are stored as small event envelopes, not full raw transcripts. Full transcript capture is intentionally not implemented as a default. If a project needs it, add a project-local policy and a redaction path first.
16
+ Hook payloads are stored as small event envelopes, not full raw transcripts. Full transcript capture is intentionally not implemented as a default. `PreCompact` may read a small bounded transcript tail for a redacted checkpoint, but it does not store the raw transcript path or full transcript. If a project needs raw transcript capture, add a project-local policy and a redaction path first.
@@ -242,7 +242,7 @@ If the queue is always empty during ordinary Q&A, that is normal. If you expecte
242
242
 
243
243
  The hook does not block tool calls only because inputs look sensitive. Durable summaries redact authentication values before writing, while ordinary work context such as dates, phone numbers, emails, and business identifiers is preserved by default.
244
244
 
245
- Hook payloads are stored as small redacted event envelopes rather than full transcripts. Manual and hook context output is redacted before wiki excerpts or search hits are returned.
245
+ Hook payloads are stored as small redacted event envelopes rather than full transcripts. `PreCompact` checkpoints may include a bounded redacted transcript tail, but the full transcript and raw `transcript_path` are not stored. Manual and hook context output is redacted before wiki excerpts or search hits are returned.
246
246
 
247
247
  ## Duplicate Pages Appear
248
248
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "llm-wiki-kit",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "Hook-first living LLM Wiki runtime for Codex and Claude Code.",
5
5
  "type": "module",
6
6
  "files": [
@@ -153,12 +153,5 @@ export function formatDurableCaptureGuidance(query) {
153
153
  '- ์ƒˆ ๋ฌธ์„œ๋Š” ๊ด€๋ จ ๊ธฐ์กด ๋ฌธ์„œ๊ฐ€ ์—†์„ ๋•Œ๋งŒ ๋งŒ๋“ค๊ณ , credentials/private data๋Š” ์ €์žฅํ•˜์ง€ ์•Š๋Š”๋‹ค.',
154
154
  ].join('\n');
155
155
  }
156
- if (hasDurableKeyword(text)) {
157
- return [
158
- 'LLM Wiki ์ €์žฅ ํ›„๋ณด ์•Œ๋ฆผ:',
159
- '- ํ˜„์žฌ ๋‹ต๋ณ€์„ ๋จผ์ € ํ•œ๋‹ค.',
160
- '- ๋‹ค์Œ ์„ธ์…˜์—๋„ ์žฌ์‚ฌ์šฉํ•  ๋งŒํ•œ ๋‚ด์šฉ(๊ฒฐ์ •, ์ •์ฑ…, ๋””๋ฒ„๊น… ๊ฒฐ๊ณผ, ์šด์˜ ์ ˆ์ฐจ, ๊ฒ€์ฆ๋œ ์ƒํƒœ ๋“ฑ)์ด ์žˆ์œผ๋ฉด ๋‹ต๋ณ€ ๋์—์„œ ์งง๊ฒŒ wiki ๋ฌธ์„œํ™” ์—ฌ๋ถ€๋ฅผ ๋ฌผ์–ด๋ณธ๋‹ค.',
161
- ].join('\n');
162
- }
163
156
  return '';
164
157
  }
@@ -0,0 +1,214 @@
1
+ import { open, stat } from 'fs/promises';
2
+ import { relative } from 'path';
3
+ import { classifyTurn } from './capture-policy.js';
4
+ import { recordMaintenanceForEntry } from './maintenance.js';
5
+ import { appendContextNote, appendLiveQa, appendWikiLog } from './project.js';
6
+ import { redactText, summarizeForStorage } from './redaction.js';
7
+ import { buildEntryFromState } from './state.js';
8
+
9
+ const DEFAULT_PRECOMPACT_TAIL_BYTES = 32 * 1024;
10
+ const MAX_PRECOMPACT_TAIL_BYTES = 256 * 1024;
11
+ const ENFORCEMENT_MODES = new Set(['limited', 'soft', 'off']);
12
+
13
+ function contextOutput(eventName, context) {
14
+ if (!context) return {};
15
+ return {
16
+ hookSpecificOutput: {
17
+ hookEventName: eventName,
18
+ additionalContext: context,
19
+ },
20
+ };
21
+ }
22
+
23
+ function providerSupportsBlock(provider) {
24
+ return String(provider || '').toLowerCase() === 'claude';
25
+ }
26
+
27
+ export function preCompactEnforcementMode(env = process.env) {
28
+ const value = String(env.LLM_WIKI_KIT_PRECOMPACT_ENFORCEMENT || 'limited').toLowerCase();
29
+ return ENFORCEMENT_MODES.has(value) ? value : 'limited';
30
+ }
31
+
32
+ export function preCompactTranscriptTailBytes(env = process.env) {
33
+ const raw = env.LLM_WIKI_KIT_PRECOMPACT_TRANSCRIPT_TAIL_BYTES;
34
+ if (raw === undefined || raw === '') return DEFAULT_PRECOMPACT_TAIL_BYTES;
35
+ const parsed = Number(raw);
36
+ if (!Number.isFinite(parsed) || parsed < 0) return DEFAULT_PRECOMPACT_TAIL_BYTES;
37
+ return Math.min(Math.floor(parsed), MAX_PRECOMPACT_TAIL_BYTES);
38
+ }
39
+
40
+ export function compactSummaryText(payload) {
41
+ return summarizeForStorage(
42
+ payload.compact_summary ||
43
+ payload.compactSummary ||
44
+ payload.summary ||
45
+ payload.message ||
46
+ '',
47
+ 4000
48
+ );
49
+ }
50
+
51
+ function transcriptPath(payload) {
52
+ return payload.transcript_path || payload.transcriptPath || '';
53
+ }
54
+
55
+ function redactTranscriptPath(text, path) {
56
+ let output = String(text || '');
57
+ if (path) output = output.split(path).join('[REDACTED:transcript-path]');
58
+ output = output.replace(/("transcript_path"\s*:\s*)"[^"]*"/gi, '$1"[REDACTED:transcript-path]"');
59
+ output = output.replace(/('transcript_path'\s*:\s*)'[^']*'/gi, "$1'[REDACTED:transcript-path]'");
60
+ output = output.replace(/\btranscript_path\s*=\s*[^\s"'`]+/gi, 'transcript_path=[REDACTED:transcript-path]');
61
+ return output;
62
+ }
63
+
64
+ async function readTranscriptTail(path, maxBytes) {
65
+ if (!path) return { ok: false, reason: 'missing-transcript-path', text: '' };
66
+ if (maxBytes <= 0) return { ok: false, reason: 'transcript-tail-disabled', text: '' };
67
+
68
+ let handle = null;
69
+ try {
70
+ const info = await stat(path);
71
+ if (!info.isFile()) return { ok: false, reason: 'transcript-not-file', text: '' };
72
+ const length = Math.min(info.size, maxBytes);
73
+ const start = Math.max(0, info.size - length);
74
+ const buffer = Buffer.alloc(length);
75
+ handle = await open(path, 'r');
76
+ await handle.read(buffer, 0, length, start);
77
+ const text = summarizeForStorage(redactTranscriptPath(buffer.toString('utf8'), path), 4000);
78
+ return {
79
+ ok: true,
80
+ text,
81
+ bytesRead: length,
82
+ truncated: info.size > maxBytes,
83
+ };
84
+ } catch (error) {
85
+ return {
86
+ ok: false,
87
+ reason: summarizeForStorage(error?.code || error?.message || 'read-failed', 200),
88
+ text: '',
89
+ };
90
+ } finally {
91
+ await handle?.close().catch(() => {});
92
+ }
93
+ }
94
+
95
+ function appendToField(current, addition) {
96
+ const existing = String(current || '').trim();
97
+ if (!existing || existing === '(not captured)') return addition;
98
+ return `${existing}\n${addition}`;
99
+ }
100
+
101
+ function entryWithTranscriptTail(entry, tail) {
102
+ const next = { ...entry };
103
+ if (tail.ok && tail.text) {
104
+ const marker = tail.truncated
105
+ ? 'PreCompact transcript tail (redacted bounded excerpt; earlier transcript omitted):'
106
+ : 'PreCompact transcript tail (redacted bounded excerpt):';
107
+ next.result = appendToField(next.result, `${marker}\n${tail.text}`);
108
+ next.followUp = appendToField(
109
+ next.followUp,
110
+ 'Compact checkpoint includes only a bounded redacted transcript tail, not the raw transcript path or full transcript.'
111
+ );
112
+ } else if (tail.reason && tail.reason !== 'missing-transcript-path') {
113
+ next.followUp = appendToField(
114
+ next.followUp,
115
+ `Transcript tail unavailable during PreCompact (${tail.reason}); checkpoint used turn state only.`
116
+ );
117
+ }
118
+ return next;
119
+ }
120
+
121
+ function failureOutput(provider, eventName, message, mode) {
122
+ if (mode === 'off') return {};
123
+ const reason = summarizeForStorage(message, 1200);
124
+ if (mode === 'limited' && providerSupportsBlock(provider)) {
125
+ return {
126
+ decision: 'block',
127
+ reason,
128
+ };
129
+ }
130
+ return contextOutput(eventName, `LLM Wiki PreCompact preservation warning:\n${reason}`);
131
+ }
132
+
133
+ export async function handlePreCompactCapture(projectRoot, provider, eventName, payload) {
134
+ const mode = preCompactEnforcementMode();
135
+ const failures = [];
136
+ const tail = await readTranscriptTail(transcriptPath(payload), preCompactTranscriptTailBytes());
137
+ const stateEntry = await buildEntryFromState(projectRoot, payload, payload.last_assistant_message || payload.response || '');
138
+ const entry = entryWithTranscriptTail(stateEntry, tail);
139
+ const classification = classifyTurn(entry, eventName);
140
+
141
+ await appendContextNote(
142
+ projectRoot,
143
+ eventName,
144
+ [
145
+ `PreCompact classification: ${classification.kind}.`,
146
+ tail.ok ? `Transcript tail bytes read: ${tail.bytesRead}.` : `Transcript tail: ${tail.reason || 'not available'}.`,
147
+ 'Turn state is intentionally kept for the later Stop/SessionEnd hook.',
148
+ ].join('\n')
149
+ ).catch((error) => {
150
+ failures.push(`context note failed: ${error?.message || error}`);
151
+ });
152
+
153
+ let liveQaPath = null;
154
+ if (classification.archive) {
155
+ const checkpointEntry = {
156
+ ...entry,
157
+ followUp: appendToField(
158
+ entry.followUp,
159
+ classification.suggestDurable
160
+ ? 'PreCompact saved this checkpoint and queued durable wiki review; merge reusable facts into existing wiki pages after the current answer.'
161
+ : 'PreCompact saved this checkpoint before context compaction; reusable facts should be merged only when appropriate.'
162
+ ),
163
+ };
164
+ try {
165
+ liveQaPath = await appendLiveQa(projectRoot, checkpointEntry);
166
+ } catch (error) {
167
+ failures.push(`live Q&A checkpoint failed: ${error?.message || error}`);
168
+ }
169
+ }
170
+
171
+ if (liveQaPath && ['suggest-durable', 'explicit-durable'].includes(classification.kind)) {
172
+ try {
173
+ const result = await recordMaintenanceForEntry(projectRoot, entry, {
174
+ source: liveQaPath,
175
+ eventName,
176
+ reason: 'PreCompact durable candidate checkpoint needs review after context compaction.',
177
+ });
178
+ if (result.created === false && result.reason) {
179
+ failures.push(`maintenance queue failed: ${result.reason}`);
180
+ }
181
+ } catch (error) {
182
+ failures.push(`maintenance queue failed: ${error?.message || error}`);
183
+ }
184
+ }
185
+
186
+ if (liveQaPath) {
187
+ await appendWikiLog(
188
+ projectRoot,
189
+ `precompact checkpoint; archive=${relative(projectRoot, liveQaPath)}; classification=${classification.kind}`
190
+ ).catch((error) => {
191
+ failures.push(`wiki log failed: ${error?.message || error}`);
192
+ });
193
+ }
194
+
195
+ if (failures.length > 0) {
196
+ return failureOutput(
197
+ provider,
198
+ eventName,
199
+ `LLM Wiki PreCompact preservation did not complete. ${failures.join('; ')}`,
200
+ mode
201
+ );
202
+ }
203
+
204
+ return {};
205
+ }
206
+
207
+ export async function recordPostCompactSummary(projectRoot, eventName, payload) {
208
+ const summary = compactSummaryText(payload);
209
+ await appendContextNote(
210
+ projectRoot,
211
+ eventName,
212
+ summary ? `Compact summary:\n${redactText(summary, 4000)}` : 'Compact summary was not provided.'
213
+ );
214
+ }
package/src/hook.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { findProjectRoot } from './fs-utils.js';
2
2
  import { classifyTurn, formatDurableCaptureGuidance, hasDetectedDurableWikiChange, isLegacyEagerCaptureMode } from './capture-policy.js';
3
- import { bootstrapProject, appendContextNote, appendLiveQa, appendSessionEnvelope, appendWikiLog, buildContextBrief, writeDecisionPage, writeQueryPage } from './project.js';
3
+ import { bootstrapProject, appendLiveQa, appendSessionEnvelope, appendWikiLog, buildContextBrief, writeDecisionPage, writeQueryPage } from './project.js';
4
+ import { compactSummaryText, handlePreCompactCapture, recordPostCompactSummary } from './compact-capture.js';
4
5
  import { recoverStaleTurnStates, recordMaintenanceForEntry } from './maintenance.js';
5
6
  import { applyProjectTemplateUpdate, inspectProjectState } from './project-state.js';
6
7
  import { recordProject } from './projects.js';
@@ -156,11 +157,13 @@ export async function handleHook(provider, explicitEvent) {
156
157
  }
157
158
 
158
159
  if (eventName === 'PreCompact' || eventName === 'PostCompact') {
159
- await appendContextNote(projectRoot, eventName, 'Compaction lifecycle event captured by llm-wiki-kit.');
160
160
  if (eventName === 'PostCompact') {
161
- return contextOutput(eventName, await buildContextBrief(projectRoot, eventName));
161
+ const summary = compactSummaryText(payload);
162
+ await recordPostCompactSummary(projectRoot, eventName, payload);
163
+ const context = await hookContext(projectRoot, eventName, await buildContextBrief(projectRoot, eventName, summary), payload);
164
+ return contextOutput(eventName, context);
162
165
  }
163
- return {};
166
+ return handlePreCompactCapture(projectRoot, provider, eventName, payload);
164
167
  }
165
168
 
166
169
  if (eventName === 'Stop' || eventName === 'SubagentStop' || eventName === 'SessionEnd') {
package/src/install.js CHANGED
@@ -19,6 +19,8 @@ import { bootstrapProject } from './project.js';
19
19
  import { recordProject } from './projects.js';
20
20
  import { binPath, detectInstallSource, packageRoot, runtimeVersion } from './version.js';
21
21
 
22
+ const SESSION_START_MATCHER = 'startup|resume|clear|compact';
23
+
22
24
  export function hookCommand(provider, eventName, options = {}) {
23
25
  return commandForNodeScript(binPath, ['hook', provider, eventName], options);
24
26
  }
@@ -125,11 +127,23 @@ async function reconcileWindowsCommand() {
125
127
 
126
128
  function addHook(hooks, eventName, command, options = {}) {
127
129
  hooks[eventName] = Array.isArray(hooks[eventName]) ? hooks[eventName] : [];
128
- const already = hooks[eventName].some((entry) => (
130
+ const existing = hooks[eventName].find((entry) => (
129
131
  Array.isArray(entry?.hooks) &&
130
132
  entry.hooks.some((hook) => hook?.type === 'command' && hook?.command === command)
131
133
  ));
132
- if (already) return false;
134
+ if (existing) {
135
+ let changed = false;
136
+ if (options.matcher && existing.matcher !== options.matcher) {
137
+ existing.matcher = options.matcher;
138
+ changed = true;
139
+ }
140
+ const hook = existing.hooks.find((item) => item?.type === 'command' && item?.command === command);
141
+ if (hook && options.commandWindows && hook.commandWindows !== options.commandWindows) {
142
+ hook.commandWindows = options.commandWindows;
143
+ changed = true;
144
+ }
145
+ return changed;
146
+ }
133
147
  const entry = {
134
148
  hooks: [
135
149
  {
@@ -186,12 +200,21 @@ function unsupportedKitClaudeEvents(hooks, supportedEvents) {
186
200
  .sort();
187
201
  }
188
202
 
189
- function hookTextIncludes(text, value) {
190
- return normalizeHookPathText(text).includes(normalizeHookPathText(value));
203
+ function expectedMatcher(eventName) {
204
+ return eventName === 'SessionStart' ? SESSION_START_MATCHER : undefined;
191
205
  }
192
206
 
193
- function hookEventIncludesBin(entries) {
194
- return hookTextIncludes(JSON.stringify(entries || {}), binPath);
207
+ function hookCommandMatches(hook, command) {
208
+ return hook?.command === command || hook?.commandWindows === command;
209
+ }
210
+
211
+ function hookEventIsCurrent(entries, eventName, command) {
212
+ const matcher = expectedMatcher(eventName);
213
+ return Array.isArray(entries) && entries.some((entry) => (
214
+ (!matcher || entry.matcher === matcher) &&
215
+ Array.isArray(entry?.hooks) &&
216
+ entry.hooks.some((hook) => hook?.type === 'command' && hookCommandMatches(hook, command))
217
+ ));
195
218
  }
196
219
 
197
220
  export async function install(options = {}) {
@@ -221,7 +244,7 @@ export async function install(options = {}) {
221
244
  changed.push('codex:replaced');
222
245
  }
223
246
  for (const eventName of CODEX_EVENTS) {
224
- const matcher = eventName === 'SessionStart' ? 'startup|resume|clear' : undefined;
247
+ const matcher = expectedMatcher(eventName);
225
248
  const command = hookCommand('codex', eventName, { platform });
226
249
  const commandWindows = isWindows({ platform }) ? hookCommand('codex', eventName, { platform: 'win32' }) : undefined;
227
250
  if (addHook(codex.hooks, eventName, command, { matcher, commandWindows })) {
@@ -251,7 +274,7 @@ export async function install(options = {}) {
251
274
  changed.push(...removedUnsupported.map((eventName) => `claude:removed-unsupported:${eventName}`));
252
275
  }
253
276
  for (const eventName of claudeEvents) {
254
- const matcher = eventName === 'SessionStart' ? 'startup|resume|clear' : undefined;
277
+ const matcher = expectedMatcher(eventName);
255
278
  if (addHook(claude.hooks, eventName, hookCommand('claude', eventName, { platform }), { matcher })) {
256
279
  claudeChanged = true;
257
280
  changed.push(`claude:${eventName}`);
@@ -312,9 +335,18 @@ export async function status(options = {}) {
312
335
  const claude = await readJson(claudeSettingsPath, {});
313
336
  const claudeDetection = detectClaudeVersion();
314
337
  const claudeEvents = supportedClaudeEvents(claudeDetection);
315
- const claudeMissingEvents = claudeEvents.filter((eventName) => !hookEventIncludesBin(claude.hooks?.[eventName] || []));
338
+ const codexMissingEvents = CODEX_EVENTS.filter((eventName) => !hookEventIsCurrent(
339
+ codex.hooks?.[eventName] || [],
340
+ eventName,
341
+ hookCommand('codex', eventName, { platform })
342
+ ));
343
+ const claudeMissingEvents = claudeEvents.filter((eventName) => !hookEventIsCurrent(
344
+ claude.hooks?.[eventName] || [],
345
+ eventName,
346
+ hookCommand('claude', eventName, { platform })
347
+ ));
316
348
  const claudeUnsupportedKitEvents = unsupportedKitClaudeEvents(claude.hooks || {}, claudeEvents);
317
- const codexInstalled = hookEventIncludesBin(codex.hooks || {});
349
+ const codexInstalled = codexMissingEvents.length === 0;
318
350
  const claudeInstalled = claudeMissingEvents.length === 0 && claudeUnsupportedKitEvents.length === 0;
319
351
  const discoveredCommandPaths = await findCommandPaths('llm-wiki', { platform });
320
352
  const commandPath = discoveredCommandPaths[0] || null;
@@ -344,6 +376,7 @@ export async function status(options = {}) {
344
376
  claudeVersion: claudeDetection.version || 'unknown',
345
377
  claudeModernHooks: claudeDetection.modern,
346
378
  claudeSupportedEvents: claudeEvents,
379
+ codexMissingEvents,
347
380
  claudeMissingEvents,
348
381
  claudeUnsupportedKitEvents,
349
382
  hooksCurrent: codexInstalled && claudeInstalled,
@@ -240,15 +240,15 @@ export function formatMaintenanceContext(summary, options = {}) {
240
240
 
241
241
  const lines = [
242
242
  eventName === 'UserPromptSubmit'
243
- ? 'LLM Wiki maintenance queue soft reminder:'
244
- : 'LLM Wiki maintenance queue summary:',
245
- `- pending: ${summary.pendingCount}. ํ˜„์žฌ ์‚ฌ์šฉ์ž ์š”์ฒญ์„ ์ง€์—ฐ์‹œํ‚ค์ง€ ๋ง๊ณ , ๊ด€๋ จ ์žˆ์„ ๋•Œ๋งŒ ๊ธฐ์กด durable wiki ๋ฌธ์„œ์— ๋ณ‘ํ•ฉํ•œ๋‹ค.`,
243
+ ? 'LLM Wiki maintenance status:'
244
+ : 'LLM Wiki maintenance status:',
245
+ `- pending review items: ${summary.pendingCount}. ํ˜„์žฌ ์š”์ฒญ์ด ์šฐ์„ ์ด๋ฉฐ, ๊ด€๋ จ ์žˆ์„ ๋•Œ๋งŒ durable wiki ์ •๋ฆฌ์— ์‚ฌ์šฉํ•œ๋‹ค.`,
246
246
  ];
247
247
  for (const item of pending) {
248
- lines.push(`- ${item.topic || item.id}: source=${item.source}; target=${item.suggested_target}; reason=${item.reason}${item.result_missing ? '; result_missing=true' : ''}`);
248
+ lines.push(`- ${item.topic || item.id}: ${item.suggested_target}; source=${item.source}${item.result_missing ? '; result missing' : ''}`);
249
249
  }
250
250
  if (summary.pending.length > pending.length) {
251
- lines.push(`- ${summary.pending.length - pending.length} more pending item(s) hidden from context.`);
251
+ lines.push(`- ${summary.pending.length - pending.length} more pending item(s) available in llm-wiki/outputs/maintenance/queue.md.`);
252
252
  }
253
253
  return lines.join('\n');
254
254
  }
package/src/project.js CHANGED
@@ -13,7 +13,7 @@ import { formatMaintenanceContext, maintenanceSummary } from './maintenance.js';
13
13
  import { normalizeForStorage, redactText, summarizeForStorage } from './redaction.js';
14
14
  import { gitignore, indexPage, llmWikiAgents, logPage, memoryPage, procedure, rootAgentsPolicy } from './templates.js';
15
15
  import { formatProjectMaintenanceContext, inspectProjectState, recordManagedTemplates } from './project-state.js';
16
- import { buildContextPack, formatContextPack, searchWiki as searchWikiWithIndex } from './wiki-search.js';
16
+ import { buildContextPack, formatHookContextPack, searchWiki as searchWikiWithIndex } from './wiki-search.js';
17
17
 
18
18
  export async function bootstrapProject(projectRoot, options = {}) {
19
19
  if (process.env.LLM_WIKI_KIT_DISABLE_BOOTSTRAP === '1') return { created: false };
@@ -171,5 +171,9 @@ export async function buildContextBrief(projectRoot, eventName, query = '') {
171
171
  const wikiMaintenance = await maintenanceSummary(projectRoot)
172
172
  .then((summary) => formatMaintenanceContext(summary, { eventName, query }))
173
173
  .catch(() => '');
174
- return [formatContextPack(pack), maintenance, wikiMaintenance].filter(Boolean).join('\n\n');
174
+ return [formatHookContextPack(pack, {
175
+ eventName,
176
+ hitLimit: eventName === 'SessionStart' ? 2 : 3,
177
+ logLineLimit: eventName === 'SessionStart' ? 2 : 0,
178
+ }), maintenance, wikiMaintenance].filter(Boolean).join('\n\n');
175
179
  }
@@ -114,12 +114,11 @@ export async function updateNoticeContext(projectRoot, eventName, options = {})
114
114
  const workspace = resolve(projectRoot || process.cwd());
115
115
  const updateCommand = commandForProject('update', workspace);
116
116
  return [
117
- 'LLM Wiki ์—…๋ฐ์ดํŠธ ์•Œ๋ฆผ:',
118
- `- ์„ค์น˜๋œ llm-wiki-kit: ${notice.installedVersion}`,
119
- `- npm ์ตœ์‹  ๋ฆด๋ฆฌ์Šค: ${notice.latestVersion}`,
120
- '- hook ์‚ฌ์šฉ ์ค‘ ๋” ์ƒˆ๋กœ์šด llm-wiki-kit ๋ฆด๋ฆฌ์Šค๊ฐ€ ์ž๋™ ๊ฐ์ง€๋˜์—ˆ์Šต๋‹ˆ๋‹ค.',
121
- `- ์‚ฌ์šฉ์ž์—๊ฒŒ ์—…๋ฐ์ดํŠธ ๊ฐ€๋Šฅ ์‚ฌ์‹ค์„ ์งง๊ฒŒ ์•Œ๋ฆฌ๊ณ  ๋‹ค์Œ ๋ช…๋ น ์‹คํ–‰์„ ์ œ์•ˆํ•˜์„ธ์š”: \`${updateCommand}\``,
122
- '- ์•Œ๋ ค์ง„ ๋ชจ๋“  ํ”„๋กœ์ ํŠธ root๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๋ ค๋ฉด ๊ฐ™์€ ๋ช…๋ น์—์„œ ๋” ๋„“์€ search root๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ: `--workspace /apps`.',
123
- '- ์‚ฌ์šฉ์ž๊ฐ€ ์š”์ฒญํ•˜๊ธฐ ์ „์—๋Š” ์ž๋™ ์„ค์น˜ํ•˜์ง€ ๋งˆ์„ธ์š”.',
117
+ 'LLM Wiki runtime update status:',
118
+ `- current hook runtime: ${notice.installedVersion}; npm registry: ${notice.latestVersion}`,
119
+ '- ํ˜„์žฌ ์š”์ฒญ ์ฒ˜๋ฆฌ๊ฐ€ ์šฐ์„ ์ด๋ฉฐ, ํ˜„์žฌ runtime ๊ธฐ๋Šฅ์€ ๊ณ„์† ๋™์ž‘ํ•œ๋‹ค.',
120
+ `- ์—…๋ฐ์ดํŠธ/์ •๋น„๋ฅผ ์ˆ˜ํ–‰ํ•  ๋•Œ ์‚ฌ์šฉํ•  ๋ช…๋ น: \`${updateCommand}\``,
121
+ '- npm ์ „์—ญ ์„ค์น˜ ๊ถŒํ•œ ์˜ค๋ฅ˜๊ฐ€ ๋‚˜๋ฉด ํ™˜๊ฒฝ์— ๋งž๊ฒŒ `npm install -g llm-wiki-kit@latest` ๋˜๋Š” `sudo npm install -g llm-wiki-kit@latest` ํ›„ ๊ฐ™์€ update ๋ช…๋ น์„ ๋‹ค์‹œ ์‹คํ–‰ํ•œ๋‹ค.',
122
+ '- ์ด status๋งŒ์œผ๋กœ ์„ค์น˜๋‚˜ ์—…๋ฐ์ดํŠธ๋ฅผ ์‹คํ–‰ํ•˜์ง€ ์•Š๋Š”๋‹ค.',
124
123
  ].join('\n');
125
124
  }
@@ -5,11 +5,13 @@ import {
5
5
  buildWikiGraph,
6
6
  collectWikiPages,
7
7
  pageLookup,
8
+ parseFrontmatter,
8
9
  readMemoryExcerpt,
9
10
  } from './wiki-model.js';
10
11
 
11
12
  const DEFAULT_LIMIT = 5;
12
13
  const SNIPPET_CHARS = 350;
14
+ const HOOK_SNIPPET_CHARS = 180;
13
15
  let miniSearchLoader = null;
14
16
 
15
17
  async function loadMiniSearch() {
@@ -202,6 +204,80 @@ function redactHit(hit) {
202
204
  };
203
205
  }
204
206
 
207
+ function compactText(value, maxLength = 220) {
208
+ const text = String(value || '').replace(/\s+/g, ' ').trim();
209
+ if (text.length <= maxLength) return text;
210
+ return `${text.slice(0, Math.max(0, maxLength - 3)).trimEnd()}...`;
211
+ }
212
+
213
+ function stripGeneratedMemoryBlock(value) {
214
+ return String(value || '')
215
+ .replace(/<!-- llm-wiki-kit:memory-start -->[\s\S]*?<!-- llm-wiki-kit:memory-end -->/g, '')
216
+ .trim();
217
+ }
218
+
219
+ function sectionBody(body, heading) {
220
+ const escaped = heading.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
221
+ const match = String(body || '').match(new RegExp(`(?:^|\\n)##\\s+${escaped}\\s*\\n([\\s\\S]*?)(?=\\n##\\s+|$)`, 'i'));
222
+ return match?.[1] || '';
223
+ }
224
+
225
+ function bulletLines(value) {
226
+ return String(value || '')
227
+ .split('\n')
228
+ .map((line) => line.trim())
229
+ .filter((line) => /^-\s+/.test(line))
230
+ .map((line) => compactText(line, 240));
231
+ }
232
+
233
+ function memoryFocusLines(memoryExcerpt, limit = 6) {
234
+ const { body } = parseFrontmatter(memoryExcerpt || '');
235
+ const bodyWithoutGenerated = stripGeneratedMemoryBlock(body);
236
+ const current = bulletLines(sectionBody(bodyWithoutGenerated, 'Current Focus'));
237
+ const entries = bulletLines(sectionBody(bodyWithoutGenerated, 'Durable Entry Points')).slice(0, 2);
238
+ if (current.length > 0) {
239
+ const currentLimit = Math.max(1, limit - entries.length);
240
+ return [...current.slice(-currentLimit), ...entries].slice(0, limit);
241
+ }
242
+
243
+ const bullets = bulletLines(bodyWithoutGenerated);
244
+ if (bullets.length > 0) return bullets.slice(-limit);
245
+
246
+ const lines = bodyWithoutGenerated
247
+ .split('\n')
248
+ .map((line) => line.trim())
249
+ .filter(Boolean);
250
+
251
+ return lines
252
+ .filter((line) => !/^#+\s+/.test(line))
253
+ .map((line) => compactText(line, 240))
254
+ .slice(0, Math.max(1, Math.min(limit, 3)));
255
+ }
256
+
257
+ function logFocusLines(logExcerpt, limit = 2) {
258
+ return String(logExcerpt || '')
259
+ .split('\n')
260
+ .map((line) => line.trim())
261
+ .filter((line) => /^-\s+/.test(line))
262
+ .slice(-limit)
263
+ .map((line) => compactText(line, 220));
264
+ }
265
+
266
+ function metaWikiQuery(query) {
267
+ return /(?:llm-wiki|wiki|์œ„ํ‚ค|memory|๋ฉ”๋ชจ๋ฆฌ|๊ธฐ์–ต|index|์ธ๋ฑ์Šค|log|๋กœ๊ทธ|maintenance|queue|๋ฌธ์„œ|๋ฌธ์„œํ™”|๊ธฐ๋ก|์ •๋ฆฌ|context|์ปจํ…์ŠคํŠธ)/i.test(String(query || ''));
268
+ }
269
+
270
+ function internalContextPath(path) {
271
+ return /^(?:wiki\/)?(?:memory|index|log)\.md$/i.test(String(path || ''));
272
+ }
273
+
274
+ function hookHits(pack, options = {}) {
275
+ const allowInternal = options.includeInternalHits || metaWikiQuery(pack.query);
276
+ return (pack.hits || [])
277
+ .filter((hit) => allowInternal || !internalContextPath(hit.path))
278
+ .slice(0, options.hitLimit || 3);
279
+ }
280
+
205
281
  export async function buildContextPack(projectRoot, query, options = {}) {
206
282
  const limit = Number(options.limit || DEFAULT_LIMIT);
207
283
  const expand = options.expand !== false;
@@ -258,3 +334,45 @@ export function formatContextPack(pack) {
258
334
  }
259
335
  return lines.join('\n').trim();
260
336
  }
337
+
338
+ export function formatHookContextPack(pack, options = {}) {
339
+ const lines = [
340
+ 'LLM Wiki context (functional compact):',
341
+ '- Priority: answer the current user request first; use wiki context when it helps.',
342
+ '- ๊ธฐ๋Šฅ ์œ ์ง€: hook memory/search/capture/maintenance/update signals are active.',
343
+ '- Durable project knowledge belongs in llm-wiki/wiki; never store credentials, tokens, private keys, or .env contents.',
344
+ ];
345
+ if (pack.query) {
346
+ lines.push(`- query: "${compactText(pack.query, 180)}"`);
347
+ lines.push(`- search: ${pack.search}`);
348
+ }
349
+
350
+ const memoryLines = memoryFocusLines(pack.memoryExcerpt, options.memoryLineLimit ?? 6);
351
+ if (memoryLines.length > 0) {
352
+ lines.push('', 'Memory focus:');
353
+ lines.push(...memoryLines.map((line) => `- ${line.replace(/^-\s+/, '')}`));
354
+ } else {
355
+ lines.push('', 'Memory focus:', '- See llm-wiki/wiki/memory.md and llm-wiki/wiki/index.md when project context is needed.');
356
+ }
357
+
358
+ const hits = hookHits(pack, options);
359
+ if (hits.length > 0) {
360
+ lines.push('', 'Relevant wiki pages:');
361
+ for (const hit of hits) {
362
+ const suffix = hit.source === 'linked' && hit.via.length > 0
363
+ ? `, via ${hit.via.join(', ')}`
364
+ : '';
365
+ lines.push(`- ${hit.path} (${hit.source}${suffix}): ${compactText(hit.snippet, HOOK_SNIPPET_CHARS)}`);
366
+ }
367
+ } else if (pack.query) {
368
+ lines.push('', 'Relevant wiki pages:', '- No directly relevant durable wiki page found; answer normally and inspect files/wiki only if needed.');
369
+ }
370
+
371
+ const logLines = logFocusLines(pack.logExcerpt, options.logLineLimit ?? 2);
372
+ if (logLines.length > 0) {
373
+ lines.push('', 'Recent log:');
374
+ lines.push(...logLines.map((line) => `- ${line.replace(/^-\s+/, '')}`));
375
+ }
376
+
377
+ return lines.join('\n').trim();
378
+ }