Skip to content

Commit e2158cb

Browse files
committed
feat: add Grok Build integration
Add native Grok lifecycle capture, provenance, skill installation, and explicit recall guidance while respecting passive hook stdout limits. Release adaptive memory and retention hardening as v0.1.4 with synchronized documentation and metadata.
1 parent ed7c783 commit e2158cb

24 files changed

Lines changed: 801 additions & 188 deletions

ARCHITECTURE.md

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ WikiBrain is deliberately a bridge, not a fourth knowledge database.
44

55
```text
66
Claude Code hooks ─┐
7-
─ brainctl ─ SQLite WAL (events and evidence)
8-
Codex hooks ───────┘ │
7+
Codex hooks ───────┼─ brainctl ─ SQLite WAL (events and evidence)
8+
Grok hooks ───────┘ │
99
├─ owned Markdown vault (durable truth)
1010
└─ wikimap CLI (disposable index and recall)
1111
```
@@ -26,14 +26,38 @@ Codex hooks ───────┘ │
2626

2727
## Capture and recall
2828

29-
1. `UserPromptSubmit` redacts and stores a prompt.
29+
1. `UserPromptSubmit` redacts and stores a prompt from Claude, Codex, or Grok.
3030
2. `Stop` pairs `last_assistant_message` with that prompt, writes an immutable
3131
Markdown handoff atomically, then updates Wikimap.
32-
3. `SessionStart` loads recent handoffs for the same workspace.
33-
4. `UserPromptSubmit` also searches Wikimap with the current prompt.
32+
3. On Claude and Codex, `SessionStart` loads recent handoffs for the same workspace.
33+
4. On Claude and Codex, `UserPromptSubmit` also searches Wikimap with the current
34+
prompt.
3435
5. Claude and Codex encode context with the same
3536
`hookSpecificOutput.additionalContext` contract.
3637

38+
[Grok Build hooks](https://docs.x.ai/build/features/hooks) provide the five
39+
events WikiBrain consumes and can discover Claude Code hooks and skills. Grok
40+
sets `GROK_HOOK_EVENT` and `GROK_SESSION_ID`; WikiBrain uses these variables to
41+
attribute Claude-compatible hook invocations to provider `grok`. Native Grok
42+
hooks can instead be installed under `${GROK_HOME:-~/.grok}/hooks/` for a
43+
Grok-only setup. The two discovery paths should not be enabled together because
44+
Grok can execute both definitions for one event.
45+
46+
Grok's passive events ignore hook stdout. WikiBrain therefore captures and
47+
archives Grok events, but deliberately skips hook-time recall and context-usage
48+
accounting for Grok. This prevents evidence that Grok never received from being
49+
counted toward adaptive-memory promotion. Grok recall remains explicit through
50+
the installed skill or `brainctl recall` until the host exposes a supported
51+
context-injection result.
52+
53+
The observed Grok binary sends lowercase event values such as
54+
`user_prompt_submit` and `stop`; the adapter maps these to canonical names and
55+
uses `promptId` as the turn identifier. `UserPromptSubmit` includes `prompt`.
56+
The observed `Stop` payload includes `transcriptPath` and `reason` but no
57+
assistant body. WikiBrain records the lifecycle turn with an explicit
58+
unavailable placeholder and deliberately does not parse the external transcript
59+
without a separate bounded, redacted transcript contract.
60+
3761
Workspace identity is the nearest Git root inside an allowlisted root. This
3862
keeps two repositories isolated even when the allowlist is the user's home
3963
directory. Only a manual `brainctl remember --global` crosses that boundary.
@@ -64,8 +88,8 @@ dirty, recall searches live Markdown instead of trusting stale index results.
6488
An index generation counter prevents an update that raced with a newer write
6589
from clearing that dirty state. Source-specific deletion tombstones reject late
6690
prompt, response, and compaction retries, so an erased page cannot silently
67-
recreate itself. Session tombstones are keyed by provider plus session ID, so a
68-
Claude deletion cannot erase an unrelated Codex session with the same ID.
91+
recreate itself. Session tombstones are keyed by provider plus session ID, so a Claude deletion
92+
cannot erase an unrelated Codex or Grok session with the same ID.
6993

7094
## Memory quality
7195

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,19 @@ The project follows [Semantic Versioning](https://semver.org/).
66

77
## [Unreleased]
88

9+
## [0.1.4] - 2026-07-22
10+
911
### Added
1012

13+
- Official Grok Build CLI support with native lifecycle-hook installation,
14+
provider/session/workspace provenance, a Grok skill target, and explicit
15+
`brainctl recall` and `brainctl remember` workflows.
16+
- Runtime-verified Grok payload normalization for lowercase event values such as
17+
`user_prompt_submit` and `stop`, including `promptId`, `transcriptPath`,
18+
timestamp, and termination-reason provenance.
19+
- English, Korean, Japanese, and Simplified Chinese Grok setup documentation,
20+
including the official executable installer, native and Claude-compatible
21+
hook paths, duplicate-hook avoidance, and passive-stdout limitations.
1122
- Adaptive long-term memory promotion for session and handoff evidence actually
1223
injected across three distinct consumer provider/session pairs, three UTC
1324
days, and two provider/session/day uses within a rolling 60-day window.
@@ -32,6 +43,11 @@ The project follows [Semantic Versioning](https://semver.org/).
3243

3344
### Changed
3445

46+
- Grok passive hooks now skip automatic recall computation and injection-usage
47+
accounting because Grok ignores passive stdout. This prevents undelivered
48+
evidence from contributing to adaptive-memory promotion. Grok `Stop` archives
49+
an explicit unavailable-response placeholder rather than reading the external
50+
transcript without a bounded redaction contract.
3551
- Retention now uses conversation capture/completion time rather than Markdown
3652
registration time and no longer lets stale promotion work protect expired
3753
turns indefinitely.

README.ja.md

Lines changed: 77 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<a href="README.zh-CN.md">简体中文</a>
1414
</p>
1515

16-
WikiBrain は、Claude CodeCodex のための [MIT ライセンス](LICENSE)の共有セカンドブレインです。ライフサイクルフックを通じて機密情報をマスキングした会話の引き継ぎを取得し、永続的なコンテキストを読みやすい Markdown として保存し、ローカルで出典を認識した情報の呼び出しに [Wikimap](https://github.com/dhha22/wikimap) を使用します。
16+
WikiBrain は、Claude CodeCodex、Grok Build のための [MIT ライセンス](LICENSE)の共有セカンドブレインです。ライフサイクルフックを通じて機密情報をマスキングした会話の引き継ぎを取得し、永続的なコンテキストを読みやすい Markdown として保存し、ローカルで出典を認識した情報の呼び出しに [Wikimap](https://github.com/dhha22/wikimap) を使用します。
1717

1818
## 目次
1919

@@ -33,7 +33,7 @@ WikiBrain は、Claude Code と Codex のための [MIT ライセンス](LICENSE
3333

3434
| ニーズ | WikiBrain が提供するもの |
3535
| --- | --- |
36-
| エージェントをまたいで作業を継続 | ClaudeCodex が同じプロジェクトスコープのコンテキストを復元できます。 |
36+
| エージェントをまたいで作業を継続 | ClaudeCodex、Grok が同じプロジェクトスコープのコンテキストを復元できます。 |
3737
| 証拠と記憶を分離 | 90 日の証拠、適応型記憶、明示的な長期記憶を区別して保持します。 |
3838
| ユーザーの所有権を維持 | Markdown が永続的な正本であり、Wikimap インデックスは破棄して再生成できます。 |
3939
| 一時的な障害から復旧 | アーカイブ、昇格、リレーション整理の各アウトボックスが中断した処理を再試行します。 |
@@ -64,6 +64,8 @@ brainctl doctor
6464
| Claude Code の自動記憶 | 新しいセッションで利用可能 | なし。確認には `/hooks` を使用できます。 |
6565
| Codex の手動記憶 | すぐに利用可能 | `brainctl remember``brainctl recall` を使用します。 |
6666
| Codex の自動取得と呼び出し | 定義はインストールされますが、最初は信頼されていません | 新しいセッションを開始し、`/hooks` を開いて、WikiBrain の 5 つのフックを確認し、現在のハッシュを信頼してください。 |
67+
| Grok の自動取得 | Grok の Claude フック互換機能で利用可能。ネイティブ設定も対応 | デフォルト設定では追加操作不要。Grok 専用の場合だけ `brainctl setup --clients grok` を使用します。 |
68+
| Grok の呼び出し | インストール済みスキルと `brainctl recall` が利用可能 | Grok は passive hook の stdout を無視するため、フックによる自動コンテキスト注入には対応しません。 |
6769

6870
### 3. スモークテストを実行
6971

@@ -85,8 +87,8 @@ brainctl forget --document DOCUMENT_ID --apply
8587

8688
```text
8789
Claude Code hooks ─┐
88-
─ brainctl ─┬─ SQLite WAL: receipts, queues, relations
89-
Codex hooks ───────┘ ├─ Markdown vault: durable readable truth
90+
Codex hooks ───────┼─ brainctl ─┬─ SQLite WAL: receipts, queues, relations
91+
Grok hooks ───────┘ ├─ Markdown vault: durable readable truth
9092
└─ Wikimap: disposable local search index
9193
```
9294

@@ -96,6 +98,27 @@ Codex hooks ───────┘ ├─ Markdown vault: durable r
9698
4. `SessionStart` は同じ Git ワークスペースについて、最近のコンテキストとクエリに関連するコンテキストを復元します。
9799
5. 型付きの `relates-to` および `supersedes` リンクは証拠を接続し、その出所を削除することなく古いガイダンスを抑制します。
98100

101+
[Grok Build 公式フック文書](https://docs.x.ai/build/features/hooks)
102+
`SessionStart``UserPromptSubmit``PostToolUse``Stop`
103+
`PostCompact` をサポートし、Claude Code のフックとスキルも自動的に読み込みます。
104+
WikiBrain は Grok のフック環境を検出し、Claude 互換経路のイベントも provider
105+
`grok` として記録します。ただし Grok は passive hook の stdout を無視します。
106+
そのため Grok の証拠は自動取得しますが、届いていない呼び出しをコンテキスト注入として
107+
数えたり、自動呼び出しと主張したりしません。以前のコンテキストが必要なときは、
108+
Grok に WikiBrain スキルを使わせるか、`brainctl recall` を実行してください。
109+
実測 runtime payload の event 値は `user_prompt_submit``stop` のような
110+
lowercase で、WikiBrain が内部 lifecycle 名へ正規化します。`UserPromptSubmit`
111+
`prompt``promptId` を提供します。実測 `Stop` payload には `transcriptPath`
112+
`promptId``reason` がありますが assistant 本文はありません。そのため WikiBrain
113+
は利用不可の placeholder を保存し、外部 transcript を自動では読みません。
114+
115+
Grok 専用の設定では、まず [Grok Build overview](https://docs.x.ai/build/overview)
116+
に従って公式 `grok` 実行ファイルをインストールします。xAI の現在のコマンドは
117+
`curl -fsSL https://x.ai/cli/install.sh | bash` です。リモート install script は
118+
実行前に確認してください。その後 `brainctl init --clients grok` を使用します。Grok の Claude
119+
フックスキャナーを無効にしていない限り、ネイティブ Grok フックと Claude フックを
120+
同時にインストールしないでください。同じイベントで両方が実行される可能性があります。
121+
99122
各 Git リポジトリは独立した記憶スコープです。プロジェクトの境界を意図的に越えるのは `brainctl remember --global` だけです。フックはフェイルオープンです。不正な形式のイベント、ビジー状態のデータベース、Wikimap 実行ファイルの欠落、タイムアウトがコーディングエージェントを妨げることはありません。
100123

101124
永続化、削除、再試行、信頼境界の詳細は [ARCHITECTURE.md](ARCHITECTURE.md) を参照してください。
@@ -110,29 +133,53 @@ Codex hooks ───────┘ ├─ Markdown vault: durable r
110133
| 適応型長期記憶 | エージェントのコンテキストへ繰り返し渡された証拠の、長さを制限したマスキング済みスナップショット | 通常の retention 後も保持し、`adaptive` と表示 |
111134
| 明示的な長期記憶 | 「覚えて」または `brainctl remember` でユーザーが指定した事実や設定 | 通常の retention 後も保持し、`explicit` と表示 |
112135

113-
適応型昇格は直近 60 日のスライディングウィンドウを使います。session または
114-
handoff が異なる UTC 日付で 3 日以上、異なる consumer provider/session pair で
115-
3 件以上、実際の最終コンテキストに含まれ、provider/session/day 単位の注入が
116-
2 回以上である場合に限り対象になります。同じ provider/session pair・同じ日の
117-
再実行は 1 回として数えます。実際の consumer session identity がない手動
118-
`brainctl recall` は数えません。最終 `<memory-data>` に届かなかった検索結果は
119-
数えず、memory ページ
120-
自身は昇格スコアを増やしません。superseded の証拠は対象外で、workspace 間で
121-
利用回数を合算することもありません。昇格後に source が superseded された場合、
122-
派生した adaptive memory も recall から隠します。
123-
124-
これらのハードゲートを満たすだけでは昇格しません。WikiBrain は、説明可能な昇格
125-
スコアがデフォルトの `0.65` 以上であることも要求します。スコアは session の多様性
126-
30%、異なる UTC 日にわたる継続性 25%、最終コンテキストへの反復注入 25%、明示的な
127-
query に基づく consumer session の割合 10%、consumer provider の多様性 10%を
128-
合算します。反復要素は設定したハード最小値の 2 倍で飽和し、provider の多様性は
129-
2 provider で飽和します。最終コンテキストに注入されなかった検索結果は寄与しません。
130-
昇格ページと document metadata にはスコア、しきい値、重み付き要素を記録し、
131-
`adaptive_memory_min_score` で 0 から 1 のしきい値を調整できます。query-backed として
132-
数えるのは明示的な検索の direct hit だけで、related と recent fallback は数えません。
133-
デフォルト値は学習済み確率ではなく、決定的な初期ポリシーです。既存 config にも `0.65`
134-
が適用されます。以前の hard-gate-only 動作を維持するには、しきい値を `0` にします。
135-
pending candidate は次回の利用時に再評価されます。
136+
### 適応型昇格の条件とスコア
137+
138+
自動昇格の対象は `session``handoff` の証拠だけです。ユーザーが明示的に
139+
「覚えて」と指定した内容は、このスコアを経由せず `explicit` 長期記憶になります。
140+
適応型候補はまず、直近 60 日以内に次のハードゲートをすべて満たす必要があります。
141+
142+
| ハードゲート | デフォルト |
143+
| --- | ---: |
144+
| 証拠を受け取った異なる consumer provider/session pair | 3 |
145+
| 証拠が注入された異なる UTC 日 | 3 |
146+
| 重複を除いた provider/session/day 単位の注入 | 2 |
147+
148+
ハードゲートを満たすだけでは昇格しません。WikiBrain は次の式を計算します。
149+
150+
```text
151+
score = 0.30 * min(S / 6, 1)
152+
+ 0.25 * min(D / 6, 1)
153+
+ 0.25 * min(I / 4, 1)
154+
+ 0.10 * (Q / S)
155+
+ 0.10 * min(P / 2, 1)
156+
```
157+
158+
| 記号 | 意味 |
159+
| --- | --- |
160+
| `S` | 証拠を受け取った異なる consumer provider/session pair 数 |
161+
| `D` | 証拠が注入された異なる UTC 日数 |
162+
| `I` | 重複を除いた provider/session/day 単位の注入数 |
163+
| `Q` | 明示的 query の direct hit により証拠が注入された異なる consumer session 数 |
164+
| `P` | 異なる consumer provider 数 |
165+
166+
分母の `6``6``4` は、それぞれデフォルトのハード最小値の 2 倍です。反復に関する
167+
点数は利用に応じて徐々に増え、その値で飽和します。Provider の多様性は 2 provider
168+
で飽和します。デフォルトの昇格条件は `score >= 0.65` です。
169+
`adaptive_memory_min_score` でしきい値を 0 から 1 の範囲で変更でき、`0` にすると
170+
従来のハードゲートのみの動作になります。
171+
172+
同じ provider/session pair が同じ UTC 日に証拠を再度受け取っても 1 回として数えます。
173+
実際の consumer session identity がない手動 `brainctl recall` は数えません。最終
174+
`<memory-data>` に入った証拠だけが点数に寄与し、query-backed の点数は明示的検索の
175+
direct hit にだけ与えます。Related と recent fallback は含めません。Memory ページは
176+
自身の昇格点数を増やせず、workspace 間の利用回数も合算しません。Superseded の証拠は
177+
対象外です。昇格後に source が superseded された場合、派生した adaptive memory も
178+
recall から隠します。
179+
180+
この式は学習済み確率ではなく、決定的な初期ポリシーです。昇格ページと document
181+
metadata には合計点、しきい値、重み付き要素を記録します。しきい値未満の候補は
182+
pending のまま残り、次回の利用時に再評価されます。
136183

137184
昇格では source で確認した証拠を最大 2,000 文字だけ新しい Markdown ページへ
138185
保存し、source 文書 ID、利用回数、昇格時刻、`memory_kind: adaptive` を記録します。
@@ -254,7 +301,7 @@ AI が提示した計画と権限要求を確認してから進めてくださ
254301
```powershell
255302
$installer = Join-Path $env:TEMP "install-wikibrain.ps1"
256303
Invoke-WebRequest `
257-
"https://raw.githubusercontent.com/hungrytech/wikibrain/v0.1.3/scripts/install-windows.ps1" `
304+
"https://raw.githubusercontent.com/hungrytech/wikibrain/v0.1.4/scripts/install-windows.ps1" `
258305
-OutFile $installer
259306
Get-Content $installer
260307
powershell.exe -NoProfile -ExecutionPolicy Bypass `
@@ -291,7 +338,9 @@ brainctl recall "that durable fact"
291338
| Brain の状態 | `~/.local/share/wikibrain/` | `%LOCALAPPDATA%\WikiBrain\` |
292339
| Claude フック | `~/.claude/settings.json` | `%USERPROFILE%\.claude\settings.json` |
293340
| Codex フック | `~/.codex/hooks.json` | `%USERPROFILE%\.codex\hooks.json` |
341+
| Grok フック(Grok 専用 opt-in) | `${GROK_HOME:-~/.grok}/hooks/wikibrain.json` | `%GROK_HOME%\hooks\wikibrain.json` または `%USERPROFILE%\.grok\hooks\wikibrain.json` |
294342
| Claude スキル | `~/.claude/skills/wikibrain/` | `%USERPROFILE%\.claude\skills\wikibrain\` |
343+
| Grok スキル(Grok 専用 opt-in) | `${GROK_HOME:-~/.grok}/skills/wikibrain/` | `%GROK_HOME%\skills\wikibrain\` または `%USERPROFILE%\.grok\skills\wikibrain\` |
295344
| Codex/Agents スキル | `~/.agents/skills/wikibrain/` | `%USERPROFILE%\.agents\skills\wikibrain\` |
296345

297346
| イベント | WikiBrain の動作 |

0 commit comments

Comments
 (0)