snipara-companion 0.1.2 → 0.2.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 (4) hide show
  1. package/README.md +77 -306
  2. package/dist/index.d.ts +264 -26
  3. package/dist/index.js +1099 -253
  4. package/package.json +10 -5
package/README.md CHANGED
@@ -1,22 +1,27 @@
1
1
  # snipara-companion
2
2
 
3
- Legacy hook-oriented CLI package kept in the monorepo for older `rlm-hook` workflows.
3
+ `snipara-companion` is Snipara's local companion CLI.
4
4
 
5
- Current automation source-of-truth docs are:
5
+ In this repository, the source currently lives in `packages/cli`, and the installed executable is `rlm-hook`.
6
6
 
7
- - `docs/guides/AUTOMATION_HOOKS.md`
8
- - `docs/guides/OPENCLAW_HOOKS.md`
9
- - `docs/operations/REPO_CHANGES_AND_AUTOMATIONS.md`
7
+ This package complements `snipara-mcp`. It does not replace it.
10
8
 
11
- The local CLI also acts as an optional thin companion for common hosted workflows such as
12
- querying context, generating plans, uploading docs, fetching chunks, bootstrapping sessions, and
13
- committing end-of-task outcomes.
9
+ ## When To Use It
14
10
 
15
- For workflow commands, the CLI now treats durable memory and short-lived session context as
16
- separate lanes. `session-bootstrap` loads durable memory by default and only includes transient
17
- carryover when you ask for it explicitly.
11
+ | If you need... | Install... |
12
+ | --------------------------------------------------------- | ------------------------ |
13
+ | MCP tools, OAuth login, project-scoped context and memory | `snipara-mcp` |
14
+ | One-command setup for `snipara-mcp` + `rlm-runtime` | `create-snipara` |
15
+ | Optional local helper CLI and hook-oriented automation | `snipara-companion` |
16
+ | OpenClaw-specific automation hooks | `snipara-openclaw-hooks` |
18
17
 
19
- The current hosted API base is `https://api.snipara.com`.
18
+ ### Codex Note
19
+
20
+ For Codex, the primary integration remains `mcp.json` plus `AGENTS.md`.
21
+
22
+ - `snipara-companion` is optional for Codex.
23
+ - This package does not currently scaffold a Codex-specific preset.
24
+ - Use it for shared local helper workflows only when that is explicitly useful.
20
25
 
21
26
  ## Installation
22
27
 
@@ -28,108 +33,52 @@ pnpm add -g snipara-companion
28
33
  yarn global add snipara-companion
29
34
  ```
30
35
 
31
- ## Quick Start
32
-
33
- ### 1. Initialize Configuration
36
+ ## Installed Command
34
37
 
35
38
  ```bash
36
- rlm-hook init
39
+ rlm-hook
37
40
  ```
38
41
 
39
- This interactive setup will:
40
-
41
- - Prompt for your RLM API key
42
- - Prompt for your project ID
43
- - Configure the API URL (default: https://api.snipara.com)
44
- - Generate Claude Code hook configuration
45
-
46
- ### 2. Configure Claude Code Hooks
47
-
48
- The `init` command generates a `.claude/settings.json` file. Copy the hooks configuration to your Claude Code settings:
49
-
50
- ```json
51
- {
52
- "hooks": {
53
- "PreToolUse": [
54
- {
55
- "matcher": "Read|Grep|Glob",
56
- "hooks": [
57
- {
58
- "type": "command",
59
- "command": "rlm-hook pre-tool \"$TOOL_INPUT\""
60
- }
61
- ]
62
- }
63
- ],
64
- "PostToolUse": [
65
- {
66
- "matcher": "Read|Edit|Write",
67
- "hooks": [
68
- {
69
- "type": "command",
70
- "command": "rlm-hook post-tool \"$TOOL_INPUT\""
71
- }
72
- ]
73
- }
74
- ],
75
- "Stop": [
76
- {
77
- "matcher": ".*",
78
- "hooks": [
79
- {
80
- "type": "command",
81
- "command": "rlm-hook session-end"
82
- }
83
- ]
84
- }
85
- ]
86
- }
87
- }
88
- ```
42
+ ## New In 0.2.0
89
43
 
90
- Note: Claude SessionStart hooks require `jq` to format the hook output JSON.
44
+ - direct `rlm-hook code` access for `callers`, `imports`, `neighbors`, and `shortest-path`
45
+ - `workflow run --mode auto|full|orchestrate` for hosted-first workflow routing
46
+ - `rlm-hook shared-context` for project-linked standards and team guidance
47
+ - automatic fallback to project token auth when a stale `SNIPARA_API_KEY` overrides a valid local login
91
48
 
92
- ### Cursor Hooks
49
+ ## Supported Client Presets Today
93
50
 
94
- ```bash
95
- rlm-hook init --with-hooks --client cursor
96
- ```
51
+ The built-in `init` flow currently supports:
97
52
 
98
- Creates:
53
+ - `claude-code`
54
+ - `cursor`
55
+ - `windsurf`
99
56
 
100
- - `.cursor/hooks.json`
101
- - `.cursor/hooks/preCompact.sh`
102
- - `.cursor/hooks/sessionStart.sh`
103
- - `.cursor/hooks/beforeReadFile.sh`
104
- - `.cursor/hooks/afterFileEdit.sh`
57
+ ## Quick Start
105
58
 
106
- ### Windsurf Hooks
59
+ ### Claude Code
107
60
 
108
61
  ```bash
109
- rlm-hook init --with-hooks --client windsurf
62
+ rlm-hook init --with-hooks --client claude-code
110
63
  ```
111
64
 
112
- Creates:
113
-
114
- - `.windsurf/cascade-hooks.json`
115
- - `.windsurf/hooks/pre-read.sh`
116
- - `.windsurf/hooks/post-read.sh`
117
- - `.windsurf/hooks/post-write.sh`
65
+ ### Cursor
118
66
 
119
- ### 3. Start Using RLM
67
+ ```bash
68
+ rlm-hook init --with-hooks --client cursor
69
+ ```
120
70
 
121
- Your Claude Code sessions will now automatically:
71
+ ### Windsurf
122
72
 
123
- - Query RLM for relevant context before file operations
124
- - Track which files are accessed during the session
125
- - Emit canonical automation events for hook activity
126
- - Persist session context when the conversation ends
73
+ ```bash
74
+ rlm-hook init --with-hooks --client windsurf
75
+ ```
127
76
 
128
77
  ## Commands
129
78
 
130
79
  ### `rlm-hook init`
131
80
 
132
- Interactive setup wizard for configuring RLM integration.
81
+ Initialize local configuration and optionally generate client hook files.
133
82
 
134
83
  ```bash
135
84
  rlm-hook init
@@ -139,69 +88,43 @@ Options:
139
88
 
140
89
  - `--api-key <key>` - Skip prompt for API key
141
90
  - `--project-id <id>` - Skip prompt for project ID
142
- - `--client <client>` - Client type (`claude-code`, `cursor`, `windsurf`)
91
+ - `--client <client>` - `claude-code`, `cursor`, or `windsurf`
143
92
  - `--with-hooks` - Install hooks automatically
144
- - `--dir <directory>` - Project directory for hooks (default: current)
145
-
146
- Examples:
147
-
148
- ```bash
149
- rlm-hook init --with-hooks --client claude-code
150
- rlm-hook init --with-hooks --client cursor
151
- rlm-hook init --with-hooks --client windsurf
152
- ```
93
+ - `--force` - Overwrite existing generated files
94
+ - `--dir <directory>` - Target directory for generated files
153
95
 
154
96
  ### `rlm-hook config`
155
97
 
156
- Display current configuration.
98
+ Show the current configuration.
157
99
 
158
100
  ```bash
159
101
  rlm-hook config
160
102
  ```
161
103
 
162
- ### `rlm-hook pre-tool <input>`
104
+ ### `rlm-hook pre-tool`
163
105
 
164
- PreToolUse hook handler. Called before Read/Grep/Glob operations.
106
+ Resolve a query from tool input and fetch relevant context.
165
107
 
166
108
  ```bash
167
- rlm-hook pre-tool '{"path": "/src/api/auth.ts"}'
109
+ rlm-hook pre-tool '{"path":"/src/api/auth.ts"}'
168
110
  ```
169
111
 
170
- Features:
171
-
172
- - Queries RLM for relevant context based on the file/search
173
- - Uses a workspace-scoped disk cache with TTL, LRU trimming, and nearby-query reuse
174
- - Emits a `tool_call` automation event for hook telemetry
175
- - Returns optimized context as a system message
112
+ ### `rlm-hook post-tool`
176
113
 
177
- ### `rlm-hook post-tool <input>`
178
-
179
- PostToolUse hook handler. Called after Read/Edit/Write operations.
114
+ Track file access for the current session.
180
115
 
181
116
  ```bash
182
- rlm-hook post-tool '{"file_path": "/src/api/auth.ts"}'
117
+ rlm-hook post-tool '{"file_path":"/src/api/auth.ts"}'
183
118
  ```
184
119
 
185
- Features:
186
-
187
- - Tracks accessed files for session persistence
188
- - Emits a `tool_result` automation event with tracked files
189
- - Non-blocking - doesn't slow down your workflow
190
-
191
120
  ### `rlm-hook session-end`
192
121
 
193
- Stop hook handler. Called when Claude Code session ends.
122
+ Persist the current session.
194
123
 
195
124
  ```bash
196
125
  rlm-hook session-end
197
126
  ```
198
127
 
199
- Features:
200
-
201
- - Emits a `session_end` automation event
202
- - Persists session context to RLM
203
- - Leaves the local cache available for future hook hits
204
-
205
128
  ### `rlm-hook session status`
206
129
 
207
130
  Show current session information.
@@ -212,7 +135,7 @@ rlm-hook session status
212
135
 
213
136
  ### `rlm-hook session reset`
214
137
 
215
- Reset session and start fresh.
138
+ Start a new session ID locally.
216
139
 
217
140
  ```bash
218
141
  rlm-hook session reset
@@ -237,6 +160,13 @@ These are thin local wrappers around hosted Snipara workflows:
237
160
 
238
161
  ```bash
239
162
  rlm-hook query --query "auth middleware"
163
+ rlm-hook query --query "who calls src.rlm_engine.RLMEngine._handle_context_query" --follow-recommendation
164
+ rlm-hook workflow run --mode auto --query "who imports src.rlm_engine"
165
+ rlm-hook workflow run --mode full --include-session-context --query "plan the auth refactor"
166
+ rlm-hook code callers --qualified-name src.rlm_engine.RLMEngine._handle_context_query
167
+ rlm-hook code imports --file-path src/rlm_engine.py
168
+ rlm-hook code neighbors --qualified-name src.rlm_engine.RLMEngine._handle_context_query
169
+ rlm-hook code shortest-path --from src.rlm_engine.RLMEngine._handle_multi_query.execute_single_query --to src.rlm_engine.RLMEngine._handle_context_query
240
170
  rlm-hook plan --query "implement OAuth device flow"
241
171
  rlm-hook upload --path docs/spec.md --file ./docs/spec.md
242
172
  rlm-hook chunk get --chunk-id chunk_123
@@ -254,6 +184,11 @@ hosted response.
254
184
 
255
185
  Semantics:
256
186
 
187
+ - `rlm-hook query --follow-recommendation` = execute the hosted recommended structural tool instead of only printing it
188
+ - `rlm-hook workflow run --mode auto` = context query plus automatic `rlm_code_*` follow-up when Snipara recommends one
189
+ - `rlm-hook workflow run --mode full` = session bootstrap + context query + automatic structural follow-up + hosted plan
190
+ - `rlm-hook workflow run --mode orchestrate` = explicit hosted orchestrator flow for deeper multi-step exploration
191
+ - `rlm-hook code *` = direct access to the code graph tools without routing through `rlm_context_query`
257
192
  - `rlm-hook session-bootstrap` = durable memory first, optional weak session carryover second
258
193
  - `rlm-hook task-commit` = durable outcomes only
259
194
  - `--max-daily-tokens` is still accepted as a compatibility alias for `--max-context-tokens`
@@ -269,7 +204,7 @@ To test a packed tarball manually, use `npm exec --package`:
269
204
 
270
205
  ```bash
271
206
  npm pack
272
- npm exec --package ./snipara-companion-0.1.1.tgz rlm-hook -- --help
207
+ npm exec --package ./snipara-companion-0.2.0.tgz rlm-hook -- --help
273
208
  ```
274
209
 
275
210
  Do not use `npx /path/to/snipara-companion-*.tgz`. npm will try to execute the tarball itself instead of
@@ -279,6 +214,9 @@ Design rule:
279
214
 
280
215
  - local CLI = workflow facade
281
216
  - hosted Snipara = source of truth for context, chunks, plans, memory, and review policy
217
+ - use `companion` for daily coding ergonomics and auto-routing
218
+ - use `orchestrate` only when the task is genuinely multi-step and exploration-heavy
219
+ - use `snipara-orchestrator` only for proof-based validation, drift detection, and production gates
282
220
 
283
221
  ### `rlm-hook cache clear`
284
222
 
@@ -288,184 +226,17 @@ Clear the local query cache.
288
226
  rlm-hook cache clear
289
227
  ```
290
228
 
291
- ## Configuration
292
-
293
- Configuration is stored at `~/.rlmsaas/config.json`:
294
-
295
- ```json
296
- {
297
- "apiKey": "rlm_your_api_key",
298
- "projectId": "proj_abc123",
299
- "apiUrl": "https://api.snipara.com",
300
- "sessionId": "session_xyz789"
301
- }
302
- ```
303
-
304
- ### Environment Variables
305
-
306
- You can also use environment variables:
307
-
308
- | Variable | Description |
309
- | -------------------- | ----------------------------- |
310
- | `SNIPARA_API_KEY` | API key (overrides config) |
311
- | `SNIPARA_PROJECT_ID` | Project ID (overrides config) |
312
- | `SNIPARA_API_URL` | API URL (overrides config) |
313
-
314
- ## How It Works
315
-
316
- ### PreToolUse Hook
317
-
318
- When Claude Code is about to read a file or search the codebase:
319
-
320
- 1. The hook extracts the file path or search query
321
- 2. Queries RLM for relevant documentation context
322
- 3. Returns context that's injected into Claude's system message
323
- 4. Results are cached locally per workspace, with exact and nearby-query reuse
324
-
325
- ```
326
- ┌─────────────────────────────────────────────┐
327
- │ Claude Code: "Let me read auth.ts..." │
328
- ├─────────────────────────────────────────────┤
329
- │ rlm-hook pre-tool │
330
- │ ├─ Extract: "auth.ts" │
331
- │ ├─ Check cache: miss │
332
- │ ├─ Query RLM: "authentication auth.ts" │
333
- │ └─ Return: Relevant docs + standards │
334
- ├─────────────────────────────────────────────┤
335
- │ Claude: Reads file WITH context │
336
- └─────────────────────────────────────────────┘
337
- ```
338
-
339
- ### PostToolUse Hook
340
-
341
- After Claude Code reads or modifies a file:
342
-
343
- 1. The hook extracts the file path
344
- 2. Tracks the file in the current session
345
- 3. Non-blocking - returns immediately
346
-
347
- ### Stop Hook
348
-
349
- When the Claude Code session ends:
350
-
351
- 1. Persists all tracked files to RLM
352
- 2. Allows future sessions to pick up context
353
- 3. Clears local cache
354
-
355
- ## Caching
356
-
357
- The CLI includes a local cache to minimize API calls:
358
-
359
- - **Cache Location**: `~/.rlmsaas/cache/context-v2/`
360
- - **TTL**: 15 minutes per query by default
361
- - **Scope**: Workspace root + project ID + query options
362
- - **Reuse**: Exact hits first, then nearby queries in the same workspace, then session bootstrap warm context
363
- - **Bootstrap source split**: Warm snapshots can include durable memory plus optional session context
364
- - **Eviction**: LRU trimming with a persistent index
365
-
366
- Clear the cache manually:
367
-
368
- ```bash
369
- rlm-hook cache clear
370
- ```
371
-
372
- ## API Integration
373
-
374
- The CLI communicates with these RLM endpoints:
375
-
376
- | Endpoint | Purpose |
377
- | ----------------------------------------- | -------------------- |
378
- | `POST /api/v1/:projectId/context` | Query for context |
379
- | `POST /api/v1/:projectId/session/track` | Track accessed files |
380
- | `POST /api/v1/:projectId/session/persist` | Persist session |
381
- | `GET /api/v1/:projectId/health` | Test connection |
382
-
383
- ## Troubleshooting
384
-
385
- ### "API key not configured"
386
-
387
- Run `rlm-hook init` to set up your configuration.
388
-
389
- ### "Project ID not configured"
390
-
391
- Run `rlm-hook init` or set the `RLM_PROJECT_ID` environment variable.
392
-
393
- ### "Connection timeout"
394
-
395
- 1. Check your internet connection
396
- 2. Verify the API URL is correct
397
- 3. Check RLM service status
398
-
399
- ### "Invalid API key"
400
-
401
- 1. Verify your API key in the RLM dashboard
402
- 2. Ensure the key hasn't been revoked
403
- 3. Check the key has access to the project
404
-
405
- ### Hook not triggering
406
-
407
- 1. Verify hooks are configured in `.claude/settings.json`
408
- 2. Check the hook matcher patterns
409
- 3. Ensure `rlm-hook` is in your PATH
410
-
411
- ### "CLI usage/help printed during hooks"
412
-
413
- 1. Ensure the hook command includes tool input: `rlm-hook pre-tool "$TOOL_INPUT"`
414
- 2. Confirm the matcher targets the right tools (Read/Grep/Glob or Read/Edit/Write)
415
- 3. Restart Claude Code after updating `.claude/settings.json`
416
-
417
- ### "Files not tracked after edits"
418
-
419
- 1. Confirm `PostToolUse` is configured for `Read|Edit|Write`
420
- 2. Verify the hook calls `rlm-hook post-tool "$TOOL_INPUT"`
421
- 3. Run with debug output: `RLM_DEBUG=1 rlm-hook post-tool '{"file_path":"file.ts"}'`
422
-
423
- ### "Need more debug output"
424
-
425
- Set `RLM_DEBUG=1` to surface hook errors on stderr.
426
-
427
- ### Cache issues
428
-
429
- Clear the cache and try again:
430
-
431
- ```bash
432
- rlm-hook cache clear
433
- ```
434
-
435
- ## Development
436
-
437
- ### Building
438
-
439
- ```bash
440
- cd packages/cli
441
- pnpm install
442
- pnpm build
443
- ```
444
-
445
- ### Testing locally
446
-
447
- ```bash
448
- pnpm dev # Watch mode
449
- node dist/index.js init
450
- ```
451
-
452
- ### Running tests
453
-
454
- ```bash
455
- pnpm test
456
- ```
457
-
458
- ## Requirements
229
+ ## Positioning
459
230
 
460
- - Node.js 18 or later
461
- - Claude Code (or compatible MCP client)
462
- - RLM SaaS account with API key
231
+ - Use `snipara-mcp` as the main Snipara client surface.
232
+ - Use `snipara-companion` when you want local helper behavior around supported hook clients.
233
+ - Do not imply that every Snipara installation needs this package.
463
234
 
464
- ## Related
235
+ ## Related Packages
465
236
 
466
- - [RLM SaaS Documentation](https://docs.rlm.dev)
467
- - [Claude Code Hooks](https://docs.claude.ai/claude-code/hooks)
468
- - [MCP Protocol](https://modelcontextprotocol.io)
237
+ - `snipara-mcp` - core MCP client
238
+ - `create-snipara` - onboarding for `snipara-mcp` + `rlm-runtime`
239
+ - `snipara-openclaw-hooks` - OpenClaw-specific automation hooks
469
240
 
470
241
  ## License
471
242