@gi4nks/ph 1.5.0 → 1.6.0

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/README.md +118 -152
  3. package/dist/cli.js +2049 -1055
  4. package/dist/cli.js.map +1 -1
  5. package/docs/evals/context-retrieval-golden.json +26 -0
  6. package/docs/evals/context-retrieval.md +27 -0
  7. package/docs/hooks.md +13 -7
  8. package/docs/ph-analysis.html +145 -0
  9. package/docs/ph-manual.md +337 -376
  10. package/docs/specs/SPEC-001-architecture-cli.md +82 -0
  11. package/docs/specs/SPEC-002-database-layer.md +105 -0
  12. package/docs/specs/SPEC-003-capture-modes.md +110 -0
  13. package/docs/specs/SPEC-004-filter-metadata.md +82 -0
  14. package/docs/specs/SPEC-005-search.md +102 -0
  15. package/docs/specs/SPEC-006-analysis-pipeline.md +98 -0
  16. package/docs/specs/SPEC-007-memory-summaries.md +96 -0
  17. package/docs/specs/SPEC-008-embeddings.md +90 -0
  18. package/docs/specs/SPEC-009-retention-archive.md +91 -0
  19. package/docs/specs/SPEC-010-remote-sync.md +106 -0
  20. package/docs/specs/SPEC-011-mcp-server.md +94 -0
  21. package/docs/specs/SPEC-012-tui-browser.md +98 -0
  22. package/docs/specs/SPEC-013-importers.md +109 -0
  23. package/docs/specs/SPEC-014-analytics-commands.md +109 -0
  24. package/docs/specs/SPEC-015-config-env.md +85 -0
  25. package/docs/specs/SPEC-INDEX.md +35 -0
  26. package/docs/specs/SPEC-ISSUES.md +122 -0
  27. package/docs/specs/_TEMPLATE.md +65 -0
  28. package/docs/superpowers/plans/2026-06-12-ph-evolution-phase1.md +466 -0
  29. package/docs/superpowers/plans/2026-06-12-ph-evolution-phase2.md +351 -0
  30. package/docs/superpowers/specs/2026-06-12-ph-evolution-design.md +173 -0
  31. package/hooks/codex/README.md +54 -0
  32. package/hooks/codex/ph-hook.sh +14 -0
  33. package/hooks/opencode/ph-plugin.ts +60 -57
  34. package/package.json +13 -12
package/CHANGELOG.md CHANGED
@@ -1,9 +1,9 @@
1
- # [1.5.0](https://github.com/gi4nks/ph/compare/v1.4.0...v1.5.0) (2026-05-16)
1
+ # [1.6.0](https://github.com/gi4nks/ph/compare/v1.5.0...v1.6.0) (2026-10-09)
2
2
 
3
3
 
4
4
  ### Features
5
5
 
6
- * add timeline CLI command and two new MCP tools (get_project_timeline, check_project_knowledge) ([12d667c](https://github.com/gi4nks/ph/commit/12d667c69e35f4aff31a2e13018a00949587fb55))
6
+ * publish current ph snapshot against GitHub main ([943ced9](https://github.com/gi4nks/ph/commit/943ced97aa63e1c183ac029ae76833583559ce98))
7
7
 
8
8
  # [1.4.0](https://github.com/gi4nks/ph/compare/v1.3.2...v1.4.0) (2026-05-16)
9
9
 
package/README.md CHANGED
@@ -1,227 +1,193 @@
1
- # ph — Prompt History & Analysis Tool
1
+ # ph — Prompt History and Project Memory
2
2
 
3
- `ph` is a transparent observability layer for AI CLI tools. It captures every prompt+response into a local SQLite database with full-text and semantic search, automatic LLM analysis, interactive TUI browser, MCP server, and optional remote sync for cross-laptop memory sharing.
3
+ `ph` captures prompt and response history from AI command-line tools and makes it searchable from the terminal or available to agents through MCP. It stores data in a local SQLite database and can optionally analyze, archive, or synchronize that data.
4
4
 
5
- ## Key Features
5
+ ## What it does
6
6
 
7
- - 📥 **Automatic Capture**: Wrapper mode (`ph claude "..."`), hook mode (Claude/Gemini/OpenCode), or direct (`ph log`).
8
- - 🔍 **Advanced Search**: FTS5 full-text search and sqlite-vec semantic search with rich filters (tool, project, role, tag, date range).
9
- - 🧠 **Background Analysis**: Automatic prompt classification (role, tags, relevance) via Ollama or Gemini — builds project-level memories.
10
- - 🖥️ **Interactive TUI**: Full-screen browser with filter panel, preview pane, project memory viewer, and session grouping.
11
- - 🔌 **MCP Server**: Exposes prompt history and project knowledge as MCP tools (`search_prompts`, `get_prompt`, `search_project_memory`, etc.) — usable by any MCP client including OpenCode.
12
- - 🌐 **HTTP Server & Remote Sync**: `ph server` starts a REST API. `ph remote push|pull` syncs prompts across laptops. Background push after each `ph log`.
13
- - 🔗 **OpenCode Plugin**: Native plugin for real-time capture via OpenCode hooks.
7
+ - Captures conversations through a transparent command wrapper, native hooks, direct logging, or history import.
8
+ - Searches prompts and responses with SQLite FTS5, or searches by semantic similarity with Ollama embeddings and sqlite-vec.
9
+ - Groups records by project, tool, language, role, tags, time, and quality metadata.
10
+ - Builds project summaries and an append-only analysis history with optional Ollama or Gemini analysis.
11
+ - Exposes prompt history and project knowledge through an MCP server over stdio.
12
+ - Provides an interactive terminal browser for filtering, reviewing, editing metadata, starring, exporting, and rerunning prompts.
13
+ - Supports optional HTTP sync between a local database and a remote `ph` server.
14
14
 
15
- ## Installation
15
+ ## Install
16
16
 
17
- ### From npm
17
+ Install from npm:
18
18
 
19
19
  ```bash
20
20
  npm install -g @gi4nks/ph
21
21
  ```
22
22
 
23
- ### From source
23
+ Or build from source:
24
24
 
25
25
  ```bash
26
- git clone git@github.com:gi4nks/ph.git
26
+ git clone https://github.com/gi4nks/ph.git
27
27
  cd ph
28
- npm install
29
- make build
30
- make install
28
+ npm ci
29
+ npm run build
30
+ npm link
31
31
  ```
32
32
 
33
- ## Quick Start
33
+ Requires Node.js 20 or later. Ollama is optional; it is used for local analysis and semantic embeddings. Gemini can be used for analysis when configured.
34
+
35
+ ## Quick start
34
36
 
35
37
  ```bash
36
- # Wrap an AI tool
38
+ # Capture a prompt by wrapping an installed AI CLI tool
37
39
  ph claude "explain goroutines"
38
40
 
39
- # Search history
41
+ # Search prompt history
40
42
  ph search "goroutines"
41
43
  ph search --semantic "concurrency patterns"
42
- ph search --tool claude --role debug --since 2026-01-01
43
44
 
44
- # Browse with TUI
45
+ # Open the interactive browser
45
46
  ph browse
46
47
 
47
- # Start HTTP server for remote sync
48
- ph server --port 3001
49
-
50
- # Sync with another machine
51
- export PH_REMOTE_URL=http://my-server:3001
52
- ph remote push # push local prompts to server
53
- ph remote pull # pull remote prompts into local DB
48
+ # Add a record directly
49
+ ph log --tool claude --prompt "Explain this function" --response "It parses..."
54
50
  ```
55
51
 
56
- ## Configuration
52
+ ## Capture history
53
+
54
+ ### Wrapper
57
55
 
58
- Config file at `~/.ph_config.json`:
56
+ Run an installed tool through `ph` to record its prompt and response:
59
57
 
60
58
  ```bash
61
- ph config set analyze-provider ollama # or 'gemini' (default: ollama)
62
- ph config set background-analysis true # auto-analyze after each log
63
- ph config set remote-url http://server:3001 # remote sync target
59
+ ph claude "explain goroutines"
60
+ ph --ph-role debug --ph-tag auth claude "fix JWT expiration"
64
61
  ```
65
62
 
66
- Environment variable `PH_REMOTE_URL` takes precedence over config.
63
+ Interactive wrapper mode is available when the wrapped tool is run without command-line prompt arguments.
64
+
65
+ ### Native hooks
67
66
 
68
- | Option | Default | Description |
69
- |--------|---------|-------------|
70
- | `analyze-provider` | `ollama` | LLM provider for analysis (`ollama` or `gemini`) |
71
- | `gemini-api-key` | — | API key for Gemini provider |
72
- | `ollama-url` | `http://localhost:11434` | Ollama server URL |
73
- | `ollama-model` | `llama3.1:latest` | Ollama model for analysis |
74
- | `ollama-embed-model` | `nomic-embed-text-v2-moe` | Ollama model for embeddings |
75
- | `background-analysis` | `false` | Auto-analyze after each `ph log` |
76
- | `remote-url` | — | HTTP URL of remote ph server |
77
- | `remote-api-key` | — | Optional API key for remote server |
78
- | `db-path` | `~/.prompt_history.db` | Custom database path |
79
- | `filter-min-length` | `15` | Ignore prompts shorter than N chars |
80
- | `filter-min-relevance` | `3` | Minimum relevance score (0–10) |
67
+ Hooks capture completed exchanges without changing the tool invocation:
81
68
 
82
- ## Remote Server Setup
69
+ - Claude Code: [hooks/claude/ph-hook.sh](hooks/claude/ph-hook.sh)
70
+ - Codex CLI: [hooks/codex/ph-hook.sh](hooks/codex/ph-hook.sh)
71
+ - Gemini CLI: [hooks/gemini/ph-hook.sh](hooks/gemini/ph-hook.sh)
72
+ - OpenCode: [hooks/opencode/ph-plugin.ts](hooks/opencode/ph-plugin.ts)
83
73
 
84
- ### Ubuntu (systemd)
74
+ See [docs/hooks.md](docs/hooks.md) for the integration overview and [docs/ph-manual.md](docs/ph-manual.md) for setup details.
85
75
 
86
- Install ph on your remote server:
76
+ ### Direct logging and history import
87
77
 
88
78
  ```bash
89
- sudo npm install -g @gi4nks/ph
90
- ```
79
+ ph log --tool claude --prompt "Explain this function" --response "It parses..."
80
+ echo '{"tool":"claude","prompt":"Explain this function","response":"It parses..."}' | ph log --stdin
91
81
 
92
- Create `/etc/systemd/system/ph.service`:
93
-
94
- ```ini
95
- [Unit]
96
- Description=ph remote sync server
97
- After=network.target
98
-
99
- [Service]
100
- Type=simple
101
- ExecStart=<path-to-ph> server --port 3001 --host 0.0.0.0
102
- Restart=always
103
- RestartSec=5
104
- User=<your-user>
105
- Environment=NODE_ENV=production
106
- StandardOutput=append:/var/log/ph-server.log
107
- StandardError=append:/var/log/ph-server.log
108
-
109
- [Install]
110
- WantedBy=multi-user.target
82
+ ph import claude --dry-run
83
+ ph import gemini --filter
84
+ ph import opencode
85
+ ph import codex --dry-run
111
86
  ```
112
87
 
113
- Find `<path-to-ph>` with `which ph` on the server. Start the service:
88
+ Codex is also available through wrapper and context-injected modes: `ph codex exec "prompt"` and `ph chat codex exec "prompt"`. See [Codex hook setup](hooks/codex/README.md).
89
+
90
+ ## Search and project context
114
91
 
115
92
  ```bash
116
- sudo systemctl daemon-reload
117
- sudo systemctl enable --now ph.service
118
- sudo ufw allow 3001/tcp # if firewall is active
119
- ```
93
+ ph search --tool claude --role debug --since 2026-01-01
94
+ ph search --semantic "How did I configure SQLite migrations?"
95
+ ph search --archive "database migration"
120
96
 
121
- ### macOS (launchd)
122
-
123
- Create `~/Library/LaunchAgents/com.gi4nks.ph.plist`:
124
-
125
- ```xml
126
- <?xml version="1.0" encoding="UTF-8"?>
127
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
128
- <plist version="1.0">
129
- <dict>
130
- <key>Label</key>
131
- <string>com.gi4nks.ph</string>
132
- <key>ProgramArguments</key>
133
- <array>
134
- <string>/usr/local/bin/ph</string>
135
- <string>server</string>
136
- <string>--port</string>
137
- <string>3001</string>
138
- <string>--host</string>
139
- <string>0.0.0.0</string>
140
- </array>
141
- <key>RunAtLoad</key>
142
- <true/>
143
- <key>KeepAlive</key>
144
- <true/>
145
- <key>StandardOutPath</key>
146
- <string>/tmp/ph-server.log</string>
147
- <key>StandardErrorPath</key>
148
- <string>/tmp/ph-server.err</string>
149
- </dict>
150
- </plist>
97
+ # Retrieve project knowledge and related prompts for the current directory
98
+ ph context "How are database migrations handled?"
99
+
100
+ # Limit the output to project summaries and memories
101
+ ph context --memories-only --project ph
151
102
  ```
152
103
 
104
+ `ph context`, `ph chat`, and MCP project-context tools use shared retrieval and formatting. Semantic results are scoped to the requested project before the result limit is applied.
105
+
106
+ ## Project memory and analysis
107
+
108
+ Enable background analysis after each capture:
109
+
153
110
  ```bash
154
- launchctl load ~/Library/LaunchAgents/com.gi4nks.ph.plist
111
+ ph config set background-analysis true
112
+ ph config set analyze-provider ollama
113
+ ph config set ollama-model llama3.1:latest
114
+ ph config set ollama-embed-model nomic-embed-text-v2-moe
155
115
  ```
156
116
 
157
- ### Client configuration
117
+ For Gemini analysis:
158
118
 
159
119
  ```bash
160
- # Set remote URL (config or env)
161
- ph config set remote-url http://your-server:3001
162
- # export PH_REMOTE_URL=http://your-server:3001
163
-
164
- # Sync
165
- ph remote push # send local prompts to server
166
- ph remote pull # fetch server prompts locally
167
- ph remote status # check sync state
120
+ ph config set analyze-provider gemini
121
+ ph config set gemini-api-key "$GEMINI_API_KEY"
168
122
  ```
169
123
 
170
- ## How Releases Work
171
-
172
- Releases are automated via **semantic-release** on push to `main`:
124
+ Project summaries merge deduplicated insights and technical decisions. Individual analysis results remain in an append-only memory timeline. Analysis and embeddings require the corresponding provider to be available; basic capture and full-text search do not.
173
125
 
174
- 1. Push conventional commits (`feat:`, `fix:`, `chore:`, etc.) to `main`
175
- 2. GitHub Actions runs `npx semantic-release`
176
- 3. Semantic-release analyzes commits since last release
177
- 4. Bumps version automatically (major/minor/patch)
178
- 5. Generates `CHANGELOG.md`
179
- 6. Creates a git tag
180
- 7. Publishes to npm with **OIDC trusted publishing** (provenance attestation)
181
- 8. Creates a GitHub Release
126
+ ## MCP integration
182
127
 
183
- The published package is signed with provenance — you can verify it with:
128
+ Start the stdio server with:
184
129
 
185
130
  ```bash
186
- npm audit signatures
131
+ ph mcp
187
132
  ```
188
133
 
189
- ## Storage
134
+ The server exposes tools for prompt search and lookup, project context and summaries, project timelines, knowledge checks, and saving decisions. Configure `ph mcp` as a stdio server in the MCP client you use.
190
135
 
191
- | Item | Default Path | Description |
192
- |------|--------------|-------------|
193
- | Database | `~/.prompt_history.db` | SQLite with FTS5 + sqlite-vec |
194
- | Config | `~/.ph_config.json` | JSON with 0o600 permissions |
136
+ ## Remote sync
195
137
 
196
- ## Architecture
138
+ Run an HTTP server on the machine that will store the shared database:
197
139
 
140
+ ```bash
141
+ ph config set remote-api-key "$PH_REMOTE_API_KEY"
142
+ ph server --host 127.0.0.1 --port 3001
198
143
  ```
199
- Capture modes: wrapper → hook → direct → OpenCode plugin
200
- |
201
- v
202
- Local SQLite (FTS5 + vec0 + memories)
203
- |
204
- ├── MCP server (stdio) → OpenCode / any MCP client
205
- ├── HTTP server (REST) → remote ph instances
206
- └── Background analysis → memories table (append-only per project)
144
+
145
+ Set a client remote URL and synchronize:
146
+
147
+ ```bash
148
+ ph config set remote-url http://127.0.0.1:3001
149
+ ph remote push
150
+ ph remote pull
151
+ ph remote status
207
152
  ```
208
153
 
209
- ## Hooks
154
+ `PH_REMOTE_URL` overrides the configured remote URL. If `remote-api-key` is set on the server, clients must also provide that key. Use a private network or a TLS-terminating proxy when connecting across machines. Each `ph log` performs a non-blocking push when a remote is configured.
210
155
 
211
- Hooks in `hooks/` integrate with AI CLI tools natively:
156
+ ## Configuration and storage
212
157
 
213
- - **Claude Code**: `hooks/claude/ph-hook.sh` — Stop hook
214
- - **Gemini CLI**: `hooks/gemini/ph-hook.sh` — AfterAgent hook
215
- - **OpenCode**: `hooks/opencode/ph-plugin.ts` — native plugin (captures streaming responses)
158
+ Configuration is stored in `~/.ph_config.json`; the database defaults to `~/.prompt_history.db`.
159
+
160
+ | Setting | Default | Purpose |
161
+ |---|---|---|
162
+ | `db-path` | `~/.prompt_history.db` | SQLite database location |
163
+ | `analyze-provider` | `ollama` | Analysis provider: `ollama` or `gemini` |
164
+ | `ollama-url` | `http://localhost:11434` | Ollama endpoint |
165
+ | `ollama-model` | `llama3.1:latest` | Analysis model |
166
+ | `ollama-embed-model` | `nomic-embed-text-v2-moe` | Embedding model; current schema expects 768 dimensions |
167
+ | `background-analysis` | `false` | Analyze newly captured prompts asynchronously |
168
+ | `filter-min-length` | `15` | Minimum prompt length accepted by filtering |
169
+ | `filter-min-relevance` | `3` | Relevance threshold for filtered imports/analysis workflows |
170
+ | `remote-url` | unset | Remote `ph` server; `PH_REMOTE_URL` takes precedence |
171
+ | `remote-api-key` | unset | Optional server authentication key |
216
172
 
217
173
  ## Development
218
174
 
219
175
  ```bash
220
- make build # tsup build
221
- make test # vitest
222
- make lint # eslint
176
+ npm ci
177
+ npm test
178
+ npm run lint
179
+ npx tsc --noEmit
180
+ npm run build
181
+ ```
182
+
183
+ Run the optional model-backed retrieval evaluation when an Ollama embedding endpoint is available:
184
+
185
+ ```bash
186
+ npm run eval:retrieval
223
187
  ```
224
188
 
189
+ See [docs/ph-manual.md](docs/ph-manual.md), [docs/specs/SPEC-INDEX.md](docs/specs/SPEC-INDEX.md), and [docs/ph-analysis.html](docs/ph-analysis.html) for the user guide, behavior specifications, and architecture report.
190
+
225
191
  ## License
226
192
 
227
193
  MIT