claude-spotter 1.4.4 → 1.4.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.4.5
4
+
5
+ **Codex global tool-db を Claude global tool-db から分離**。v1.4.4 までは local DB は
6
+ `.spotter/tool-db.json` と `.spotter/tool-db.codex.json` に分かれていたが、refresh 時の
7
+ description 再利用 cache は Claude / Codex とも `~/.spotter/tool-db.json` を共有していた。
8
+ Claude 側で苦労して塞いだ「別環境の DB が監査視野に混ざる」設計事故を Codex 側で再発させないため、
9
+ host-global DB も分離した。
10
+
11
+ ### 変更点
12
+
13
+ - **編集 [src/tool-db/loader.mjs](src/tool-db/loader.mjs)**:
14
+ `globalDbPath(hostAgent)` を host-aware にし、Claude は既存互換の
15
+ `~/.spotter/tool-db.json`、Codex は `~/.spotter/tool-db.codex.json` を使うようにした。
16
+ - **編集 [src/tool-db/refresh.mjs](src/tool-db/refresh.mjs)**:
17
+ `refresh({hostAgent})` の local → global → investigate lookup が同じ host の
18
+ global cache だけを見るようにした。
19
+ - **編集 [src/cli/db-cmd.mjs](src/cli/db-cmd.mjs) / [src/cli/doctor.mjs](src/cli/doctor.mjs)**:
20
+ `spotter db refresh/rebuild --host-agent codex` と `spotter doctor` の表示・消去対象を
21
+ host-global DB に追従。
22
+ - **編集 [test/tool-db.test.mjs](test/tool-db.test.mjs)**:
23
+ Claude global cache の同名 entry が Codex refresh に write-through されず、
24
+ Codex 側では Codex global cache / investigate を使う回帰テストを追加。
25
+ - **編集 README / README.ja / CLAUDE.md / docs**:
26
+ local だけでなく global description cache も Claude / Codex で分離する設計に更新。
27
+
28
+ ### ユーザー側で必要な手順
29
+
30
+ 1. `npm install -g claude-spotter@1.4.5`
31
+ 2. 既存の shared global cache を掃除するため、各プロジェクトで
32
+ `spotter db rebuild` と `spotter db rebuild --host-agent codex` を 1 回ずつ実行
33
+ 3. 各プロジェクトで `spotter install`
34
+
3
35
  ## 1.4.4
4
36
 
5
37
  **Codex CLI auditor の default model を明示固定**。Spotter の hook 判定は高頻度・低遅延・低コストの
package/README.ja.md CHANGED
@@ -105,7 +105,7 @@ flowchart LR
105
105
  DB --> H[Haiku 監査<br/>session-scoped, preamble-once]
106
106
  ```
107
107
 
108
- 監査対象のツール (name + description) は host-local に分離されます。Claude は `<project>/.spotter/tool-db.json`、Codex は `<project>/.spotter/tool-db.codex.json` を使います。**daemon が監査に使うのは Claude local DB のみ**で、Codex native hooks は Codex local DB を読みます。グローバル DB `~/.spotter/tool-db.json` は他プロジェクトでの description 再利用キャッシュとしてのみ機能し、監査入力には混ぜません。各 host-local DB は **その host の現時点の discovery 結果と一致** (refresh 時に prune される) するため、別プロジェクトや別 host のツールリストで上書きされることはありません。
108
+ 監査対象のツール (name + description) は host-local に分離されます。Claude は `<project>/.spotter/tool-db.json`、Codex は `<project>/.spotter/tool-db.codex.json` を使います。**daemon が監査に使うのは Claude local DB のみ**で、Codex native hooks は Codex local DB を読みます。グローバル description cache も host ごとに分離され、Claude は `~/.spotter/tool-db.json`、Codex は `~/.spotter/tool-db.codex.json` を使います。これらは同じ host の他プロジェクト間でだけ再利用され、監査入力には混ぜません。各 host-local DB は **その host の現時点の discovery 結果と一致** (refresh 時に prune される) するため、別プロジェクトや別 host のツールリストで上書きされることはありません。
109
109
 
110
110
  **`spotter install` が Claude catalog の初回 seed を自動実行し、Claude Code セッション起動ごとに SessionStart hook が bg で `spotter db refresh` を走らせる**ため、Claude 通常運用で手動コマンドを叩く必要はありません。Codex CLI が使える環境では、同じ `spotter install` が Codex native hooks も登録します。Codex `SessionStart` hook は `spotter db refresh --host-agent codex` を bg 起動して `.spotter/tool-db.codex.json` を更新します。Claude catalog には書き込みません。Claude discovery は `claude mcp list` と Claude skills / sub-agents、Codex discovery は `codex mcp list/get` と Codex skills を読むため、両 host の利用可能ツール差分を別 DB として保持できます。各 MCP サーバーの `tools/list` は JSON-RPC で取得 (HTTP / SSE / stdio transport 対応)、スキルとサブエージェントは frontmatter から直接抽出、claude.ai baseline (OAuth proxy 経由の Gmail / Calendar / Drive 25 件) は Claude 側でのみ `claude mcp list` に該当サーバーが存在する環境で注入されます。**手書きでツールリストを管理する必要はありません**。
111
111
 
@@ -132,7 +132,7 @@ spotter db refresh --host-agent codex
132
132
  # Codex MCP / スキルから description を収集して .spotter/tool-db.codex.json を更新
133
133
  # (Claude は install + Claude SessionStart、Codex は spotter install 後の
134
134
  # Codex SessionStart で自動実行されるので通常は不要)
135
- spotter db rebuild # Claude local + global DB を両方消してから refresh (カタログ設計変更時のクリーン用)
135
+ spotter db rebuild # Claude local + Claude global DB を両方消してから refresh (カタログ設計変更時のクリーン用)
136
136
  spotter status # 稼働中の daemon 一覧
137
137
  spotter doctor # 環境診断 (Node / claude CLI / Codex readiness / tool-db 整合性)
138
138
  spotter diagnostics logs # daemon log から pass=false / backend latency / anomaly signal を集計
package/README.md CHANGED
@@ -105,7 +105,7 @@ flowchart LR
105
105
  DB --> H[Haiku audit<br/>session-scoped, preamble-once]
106
106
  ```
107
107
 
108
- The audited catalog is host-local: Claude uses `<project>/.spotter/tool-db.json`, while Codex uses `<project>/.spotter/tool-db.codex.json`. **The daemon audits against the Claude local DB only**, and Codex native hooks read the Codex local DB. The global DB at `~/.spotter/tool-db.json` is a description-reuse cache shared across projects, not an audit source. Each host-local DB matches that host's **current** discovery snapshot for the project (stale entries are pruned on refresh), so tools from another project or another host cannot overwrite this session's audit catalog.
108
+ The audited catalog is host-local: Claude uses `<project>/.spotter/tool-db.json`, while Codex uses `<project>/.spotter/tool-db.codex.json`. **The daemon audits against the Claude local DB only**, and Codex native hooks read the Codex local DB. Global description caches are host-specific too: Claude uses `~/.spotter/tool-db.json`, while Codex uses `~/.spotter/tool-db.codex.json`. They are shared only across projects for the same host and are never audit sources. Each host-local DB matches that host's **current** discovery snapshot for the project (stale entries are pruned on refresh), so tools from another project or another host cannot overwrite this session's audit catalog.
109
109
 
110
110
  **`spotter install` seeds the Claude catalog automatically, and the SessionStart hook runs a background `spotter db refresh` on every Claude Code session start** — so you don't need to invoke Claude catalog commands by hand. When Codex CLI is available, the same `spotter install` registers Codex native hooks; their `SessionStart` hook starts `spotter db refresh --host-agent codex` in the background, updating `.spotter/tool-db.codex.json` without touching the Claude catalog. Claude discovery reads `claude mcp list` plus Claude skills / sub-agents; Codex discovery reads `codex mcp list/get` plus Codex skills. Each MCP server's `tools/list` is fetched via JSON-RPC (HTTP / SSE / stdio transports supported); skill and sub-agent metadata comes straight from frontmatter; the claude.ai baseline (25 hand-curated entries for Gmail / Calendar / Drive over OAuth proxy) is injected only for Claude when `claude mcp list` confirms the server is present. **You never have to maintain the tool list by hand.**
111
111
 
@@ -132,7 +132,7 @@ spotter db refresh --host-agent codex
132
132
  # rediscover Codex MCP / skills and update .spotter/tool-db.codex.json
133
133
  # (Claude refresh is automatic on install + Claude SessionStart;
134
134
  # Codex refresh is automatic on Codex SessionStart after spotter install)
135
- spotter db rebuild # wipe Claude local + global DBs and refresh from scratch
135
+ spotter db rebuild # wipe Claude local + Claude global DBs and refresh from scratch
136
136
  # (use after catalog-shape changes)
137
137
  spotter status # list running daemons
138
138
  spotter doctor # environment check (Node / claude CLI / Codex readiness / tool-db integrity)
@@ -189,7 +189,7 @@ those values for smoke tests or controlled experiments.
189
189
  <summary><strong>📋 Recent highlights</strong></summary>
190
190
 
191
191
  - **Plugin-scoped MCP servers** — names like `plugin:everything-claude-code:context7` (with internal colons) are now parsed correctly and their tools enter the catalog. Earlier versions silently collapsed all plugin MCP servers into a single literal `"plugin"`, dropping their tools from Bell's audit
192
- - **Per-project audit isolation** — the daemon audits against the local DB only; the global DB has been demoted to a description-reuse cache. Tools discovered in *other* projects can never bleed into this project's audit set
192
+ - **Per-project / per-host audit isolation** — the daemon audits against the local DB only; global DBs are host-specific description caches. Tools discovered in *other* projects or another host can never bleed into this project's audit set
193
193
  - **Zero-touch catalog** — `spotter install` seeds the Claude DB automatically; Claude and Codex SessionStart hooks keep their host-local DBs fresh in the background. You never have to maintain the tool list by hand
194
194
  - **Codex native hooks** — Codex host uses Codex CLI as the primary auditor backend, keeps a separate `.spotter/tool-db.codex.json`, and surfaces backend failures explicitly instead of falling back to Haiku
195
195
  - **Audit scope** — only user-added surface (MCP servers / skills / sub-agents). Claude Code's built-in tools are intentionally out of scope; Bell already uses those reliably
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-spotter",
3
- "version": "1.4.4",
3
+ "version": "1.4.5",
4
4
  "description": "Audit agent running alongside Claude Code that catches missed tool calls — 気づく役と実行する役の分離",
5
5
  "type": "module",
6
6
  "bin": {
@@ -2,7 +2,7 @@
2
2
  //
3
3
  // spotter db list — print the LOCAL tool-db (what the daemon actually audits)
4
4
  // spotter db refresh — discover available tools and update DB (3-tier resolve)
5
- // spotter db rebuild — wipe local + global DBs then refresh (forces re-investigation)
5
+ // spotter db rebuild — wipe host-local + host-global DBs then refresh
6
6
  //
7
7
  // Run inside a project that has been `spotter install`-ed.
8
8
 
@@ -52,20 +52,19 @@ export async function runDbRefresh({ argv = [] } = {}) {
52
52
  process.stdout.write(
53
53
  `${resolved.size} tool(s) resolved (local=${counts.local}, global=${counts.global}, investigated=${counts.investigated})\n`
54
54
  + `local DB: ${localDbPath(projectRoot, opts.hostAgent)}\n`
55
- + `global DB: ${globalDbPath()}\n`
55
+ + `global DB: ${globalDbPath(opts.hostAgent)}\n`
56
56
  );
57
57
  }
58
58
 
59
59
  export async function runDbRebuild({ argv = [] } = {}) {
60
60
  const projectRoot = requireProjectRoot();
61
61
  const opts = parseDbArgs(argv);
62
- // v1.0.0: wipe BOTH local and global DB. Rationale: the catalog scope changed in
63
- // v1.0.0 (Claude Code built-ins removed; skills + sub-agents added). Stale entries
64
- // from older versions would otherwise linger in the global DB since `refresh` only
65
- // touches names currently produced by investigation. Users need a clean slate.
62
+ // Wipe BOTH host-local and host-global DB. Rationale: catalog scope changes and
63
+ // description drift must not leak between Claude and Codex; each host cache is a
64
+ // separate clean-slate unit.
66
65
  await saveDb(localDbPath(projectRoot, opts.hostAgent), emptyDb());
67
- await saveDb(globalDbPath(), emptyDb());
68
- process.stderr.write(`spotter db rebuild: cleared ${opts.hostAgent} local + global DB, refreshing...\n`);
66
+ await saveDb(globalDbPath(opts.hostAgent), emptyDb());
67
+ process.stderr.write(`spotter db rebuild: cleared ${opts.hostAgent} local + ${opts.hostAgent} global DB, refreshing...\n`);
69
68
  await runDbRefresh({ argv });
70
69
  }
71
70
 
@@ -78,15 +78,18 @@ export async function runDoctor() {
78
78
  if (!sidecar.ok) warnings += 1;
79
79
  }
80
80
 
81
- // tool-db (global cache). Since v1.2.0 this is not part of daemon audit input;
82
- // the daemon audits the project-local DB only. Empty global cache is fine.
83
- try {
84
- const global = await loadDb(globalDbPath());
85
- const count = Object.keys(global.tools).length;
86
- mark(true, `global cache DB: ${count} tools at ${globalDbPath()}`);
87
- } catch (err) {
88
- mark(false, 'global cache DB', `${err.message} (cache only; daemon audits local DB)`);
89
- warnings += 1;
81
+ // tool-db (host-specific global caches). Since v1.2.0 these are not part of
82
+ // audit input; each host audits its project-local DB only. Empty caches are fine.
83
+ for (const hostAgent of ['claude', 'codex']) {
84
+ try {
85
+ const path = globalDbPath(hostAgent);
86
+ const global = await loadDb(path);
87
+ const count = Object.keys(global.tools).length;
88
+ mark(true, `${hostAgent} global cache DB: ${count} tools at ${path}`);
89
+ } catch (err) {
90
+ mark(false, `${hostAgent} global cache DB`, `${err.message} (cache only; audit uses local DB)`);
91
+ warnings += 1;
92
+ }
90
93
  }
91
94
 
92
95
  // tool-db (local) if cwd is inside a Spotter project. Claude and Codex use
@@ -143,7 +143,7 @@ export async function runInstall({
143
143
  const resolved = await refreshFn({ projectRoot: cwd, hostAgent: 'claude', logFn: log });
144
144
  console.log(` ${resolved.size} tool(s) resolved`);
145
145
  console.log(` local DB: ${localDbPath(cwd, 'claude')}`);
146
- console.log(` global DB: ${globalDbPath()}`);
146
+ console.log(` global DB: ${globalDbPath('claude')}`);
147
147
  } catch (err) {
148
148
  // §0: throw (fallback 禁止). But surface the recovery path so the user isn't
149
149
  // left with "hooks registered, tool-db missing" and no clue what to run.
@@ -3,7 +3,8 @@
3
3
  // Two layers:
4
4
  // - local: <project>/.spotter/tool-db.json (Claude host)
5
5
  // <project>/.spotter/tool-db.codex.json (Codex host)
6
- // - global: ~/.spotter/tool-db.json
6
+ // - global: ~/.spotter/tool-db.json (Claude host)
7
+ // ~/.spotter/tool-db.codex.json (Codex host)
7
8
  //
8
9
  // Both have the same shape:
9
10
  // { "version": 1, "tools": { "<name>": "<description>", ... } }
@@ -22,8 +23,10 @@ export class ToolDbSchemaError extends Error {
22
23
  }
23
24
  }
24
25
 
25
- export function globalDbPath() {
26
- return join(homedir(), '.spotter', 'tool-db.json');
26
+ export function globalDbPath(hostAgent = 'claude') {
27
+ const host = normalizeToolDbHostAgent(hostAgent);
28
+ const file = host === 'claude' ? 'tool-db.json' : `tool-db.${host}.json`;
29
+ return join(homedir(), '.spotter', file);
27
30
  }
28
31
 
29
32
  export function localDbPath(projectRoot, hostAgent = 'claude') {
@@ -101,14 +101,14 @@ export async function refresh({
101
101
  return resolveAll({
102
102
  toolNames,
103
103
  localPath: localDbPath(projectRoot, toolDbHostAgent),
104
- globalPath: globalDbPath(),
104
+ globalPath: globalDbPath(toolDbHostAgent),
105
105
  investigate,
106
106
  logFn,
107
107
  });
108
108
  }
109
109
 
110
110
  // Read-only: load the LOCAL tool-db only — the daemon's audit must reflect what this
111
- // specific project can actually use. The global DB is a knowledge store written by
111
+ // specific project can actually use. The host-specific global DB is a cache written by
112
112
  // `refresh` (so other projects can pick up descriptions cheaply) but is NEVER mixed
113
113
  // into the daemon's audit catalog. Mixing global in caused phantom-tool suggestions
114
114
  // from previously-visited projects bleeding into unrelated ones.