memex-mvp 0.6.1 → 0.8.1

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/HELP.md CHANGED
@@ -293,6 +293,84 @@ Memex по дефолту сортирует по **релевантности**
293
293
 
294
294
  ---
295
295
 
296
+ ## 💻 Терминальный CLI (v0.7+) — когда MCP не работает
297
+
298
+ Если MCP-интеграция не подцепилась к твоему агенту (или ты в агенте без MCP-поддержки, но с shell-доступом) — у memex есть **terminal-режим** на том же бинаре. Один пакет, два режима.
299
+
300
+ ```bash
301
+ memex search "Postgres миграция" # FTS5 поиск
302
+ memex search "Q2 deck" --chat "Memex Bot" # фильтр по title чата
303
+ memex search "auth" --source claude-code --limit 5 --sort date_desc
304
+ memex search "JWT" --as-of 2026-05-01 # time-travel (v0.8.1+) — только до даты
305
+
306
+ memex when "Brian Chesky" # «когда мы об этом говорили»
307
+ memex when "JWT decision" --limit 5 # → chronological list of chats, без snippets
308
+
309
+ memex recent --limit 5 # последние сообщения
310
+ memex recent --source telegram
311
+
312
+ memex list # все conversations
313
+ memex list --source web # только сохранённые URL'ы
314
+
315
+ memex get web-1582ab51a7b7 # полный контент conversation
316
+
317
+ memex overview # snapshot корпуса (+ capture streak v0.8.1+)
318
+ memex projects # уникальные project_paths
319
+ memex help # эта инструкция в терминале
320
+ memex --help # справка по командам
321
+ memex --version
322
+ ```
323
+
324
+ **Все query-команды поддерживают `--json`** для пайпов и скриптов:
325
+
326
+ ```bash
327
+ memex search "TODO" --json | jq '.results[].snippet'
328
+ memex list --source telegram --json | jq -r '.conversations[].title'
329
+ memex get web-1582ab51a7b7 --json > backup.json
330
+ ```
331
+
332
+ **БД открывается read-only** — безопасно запускать пока daemon-writer работает.
333
+
334
+ **Когда использовать CLI вместо MCP:**
335
+
336
+ - MCP-интеграция в твоём агенте не подключилась → `memex overview` подтвердит что сам memex здоров, проблема в MCP-config'е клиента
337
+ - Агент без MCP-поддержки (OpenCode + Kimi, любые CLI-only агенты), но с shell-доступом
338
+ - Shell-скрипты / автоматизация
339
+ - Дебаг: «вижу ли я свою историю напрямую?»
340
+
341
+ **`memex` (без аргументов)** — это MCP stdio-сервер. Это поведение по умолчанию для Claude Code / Cursor / Cline через их MCP-config'и. CLI-команды активируются только при наличии распознанного subcommand'a.
342
+
343
+ ---
344
+
345
+ ## 🪄 Auto-context (v0.8+) — Brian Chesky moment
346
+
347
+ Magic-фича. Когда ты открываешь Claude Code в проекте, Claude **сам** инжектит 500-1500 токенов контекста про этот проект — что ты делал недавно, какие conversations касались темы. Ты ещё ничего не спросил, а AI **уже знает**.
348
+
349
+ **Технически:** SessionStart hook в `~/.claude/settings.json`. При старте каждой Claude Code сессии хук вызывает `memex context` → memex выдаёт markdown summary → Claude получает его как system message _до_ твоего первого вопроса.
350
+
351
+ **Установка:** во время `memex-sync install` будет промпт `[Y/n]` — соглашайся (Y по default'у). Или установи позже:
352
+
353
+ ```bash
354
+ memex hook install # добавить хук
355
+ memex hook uninstall # удалить (только memex-запись, другие хуки сохраняются)
356
+ memex hook status # узнать текущее состояние
357
+ ```
358
+
359
+ **Посмотреть что будет инжектиться** (dry-run в текущей директории):
360
+
361
+ ```bash
362
+ memex context # markdown как для хука
363
+ memex context --json # структурированный
364
+ memex context --no-source telegram # исключить telegram (privacy)
365
+ memex context --freshness-days 30 # только последние 30 дней
366
+ ```
367
+
368
+ **Privacy:** хук ничего не отправляет наружу — это локальная инъекция в локальную Claude-сессию. Но в context могут попасть фрагменты из любых indexed sources (включая Telegram). Чтобы исключить — добавь `--no-source telegram` в команду хука (правится в `~/.claude/settings.json`).
369
+
370
+ **Где это пока не работает:** Cursor, Cline, Continue, Zed — у них нет native SessionStart hook'а. Fallback через MCP-tool — в roadmap v0.9.0. Сейчас auto-context работает только в **Claude Code и OpenClaw**.
371
+
372
+ ---
373
+
296
374
  ## Если что-то не работает
297
375
 
298
376
  ### Поиск пустой
package/README.md CHANGED
@@ -100,6 +100,52 @@ For a fully-automated install across all detected MCP clients, see [the AI-drive
100
100
 
101
101
  ---
102
102
 
103
+ ## Terminal CLI (v0.7+) — query memex without MCP
104
+
105
+ The same `memex` binary that runs as an MCP server also has a terminal mode for direct queries. Useful when MCP isn't wired up, when you want to pipe results into shell scripts, or when debugging MCP-config issues:
106
+
107
+ ```sh
108
+ memex search "Postgres migration" # full-text search
109
+ memex search "Q2 deck" --chat "Memex Bot" # scope to one conversation by title
110
+ memex search "JWT" --as-of 2026-05-01 # v0.8.1: time-travel — only msgs before date
111
+ memex when "Brian Chesky" # v0.8.1: "when did we talk about X" — dates + chats
112
+ memex recent --limit 5 # last 5 messages across all sources
113
+ memex list --source web # all saved URLs
114
+ memex get web-1582ab51a7b7 # full content of one conversation
115
+ memex overview # snapshot of corpus + v0.8.1: capture streak
116
+ memex projects # distinct project_paths captured
117
+ memex help # full user guide (HELP.md)
118
+ memex --help # command reference
119
+ ```
120
+
121
+ Every query supports `--json` for machine-readable output: `memex search foo --json | jq '.results[].snippet'`. The DB is opened **read-only** — safe to run while `memex-sync` daemon is writing.
122
+
123
+ When called **without arguments** (`memex`), the binary still runs as an MCP stdio server (the way Claude Code / Cursor / Cline launch it). CLI mode and MCP mode are the same package — no extra install.
124
+
125
+ ---
126
+
127
+ ## Auto-context (v0.8+) — Claude already knows what you were doing
128
+
129
+ After `memex-sync install`, you're prompted to enable **auto-context**. When yes, memex adds a SessionStart hook to `~/.claude/settings.json` so that **every time you open Claude Code in a project**, Claude gets injected with ~500-1500 tokens of relevant context — what you did recently in this project, which conversations touched it, which related topics came up. No prompts. No tool calls. Just memory.
130
+
131
+ ```sh
132
+ # Adding/removing the hook outside the install flow:
133
+ memex hook install # add SessionStart hook (idempotent)
134
+ memex hook uninstall # remove only the memex entry, preserves other hooks
135
+ memex hook status # show current state
136
+
137
+ # Inspecting what gets injected:
138
+ memex context # dry-run the hook output for the current dir
139
+ memex context --pwd /path # for a different project
140
+ memex context --no-source telegram # exclude a source
141
+ ```
142
+
143
+ The hook respects existing hooks (e.g. `gstack`, custom user hooks) — they're preserved untouched.
144
+
145
+ **Currently only Claude Code has native SessionStart hooks.** For Cursor / Cline / Continue / Zed, MCP-tool-based fallback is on the v0.9.0 roadmap.
146
+
147
+ ---
148
+
103
149
  ## Save URLs into memex (v0.6+)
104
150
 
105
151
  Once memex is installed, any MCP-aware agent can also save **web pages, AI chat shares, and pasted text** into your memex memory — searchable from any other AI chat later. In Claude Code, Cursor, Cline, …:
package/README.ru.md CHANGED
@@ -136,6 +136,54 @@ curl -fsSL https://raw.githubusercontent.com/parallelclaw/memex-mvp/main/skills/
136
136
 
137
137
  Полное руководство и edge cases (private Perplexity, paywall, login-walls): [HELP.md §8](HELP.md).
138
138
 
139
+ ### Терминальный CLI (v0.7+) — запросы к memex без MCP
140
+
141
+ Тот же бинарь `memex`, который работает как MCP-сервер, имеет **terminal-режим** для прямых запросов. Полезно когда MCP не настроен, когда хочешь пайпить результаты в shell-скрипты, или дебажить MCP-конфиг:
142
+
143
+ ```bash
144
+ memex search "Postgres миграция" # полнотекстовый поиск
145
+ memex search "Q2 deck" --chat "Memex Bot" # сузить до конкретного чата по title
146
+ memex search "JWT" --as-of 2026-05-01 # v0.8.1: time-travel — только до даты
147
+ memex when "Brian Chesky" # v0.8.1: «когда мы это обсуждали» — даты + чаты
148
+ memex recent --limit 5 # последние 5 сообщений из всех источников
149
+ memex list --source web # все сохранённые URL'ы
150
+ memex get web-1582ab51a7b7 # полный контент одной conversation
151
+ memex overview # snapshot корпуса + v0.8.1: capture streak
152
+ memex projects # уникальные project_paths
153
+ memex help # полное руководство (HELP.md)
154
+ memex --help # справка по командам
155
+ ```
156
+
157
+ У каждого query-subcommand'a есть `--json` для machine-readable вывода: `memex search foo --json | jq '.results[].snippet'`. БД открывается **read-only** — безопасно запускать пока daemon пишет.
158
+
159
+ При запуске **без аргументов** (`memex`) бинарь по-прежнему работает как MCP stdio server (как и вызывают его Claude Code / Cursor / Cline из своих конфигов). CLI-режим и MCP-режим — один и тот же пакет, без дополнительной установки.
160
+
161
+ **Использовать CLI, когда:**
162
+ - MCP-интеграция не подцепилась к твоему агенту → `memex overview` подтвердит что сам memex здоров
163
+ - Агент без MCP-поддержки, но с shell-доступом
164
+ - Хочешь пайпить результаты: `memex search foo --json | jq ...`
165
+ - Хочешь сдампить полный transcript в stdout для context'a
166
+
167
+ ### Auto-context (v0.8+) — Claude уже знает что ты делал
168
+
169
+ После `memex-sync install` появляется промпт про **auto-context**. Если согласишься — memex добавит SessionStart хук в `~/.claude/settings.json`. Когда ты потом открываешь Claude Code в каком-то проекте, Claude **сам подгружает 500-1500 токенов контекста** про этот проект — что ты делал недавно, какие conversations его касались, какие связанные темы всплывали. Никаких вопросов, никаких tool-call'ов, просто Claude **знает**.
170
+
171
+ ```bash
172
+ # Добавить/удалить хук вне install-flow:
173
+ memex hook install # добавить SessionStart хук (idempotent)
174
+ memex hook uninstall # удалить только memex-запись, остальные хуки не трогает
175
+ memex hook status # показать текущее состояние
176
+
177
+ # Посмотреть что будет инжектиться:
178
+ memex context # dry-run для текущей директории
179
+ memex context --pwd /path # для другого проекта
180
+ memex context --no-source telegram # исключить источник
181
+ ```
182
+
183
+ Хук **сохраняет существующие хуки** (gstack, твои кастомные) — добавляет только свою запись.
184
+
185
+ **Сейчас native SessionStart есть только в Claude Code.** Для Cursor / Cline / Continue / Zed fallback через MCP-tool — в roadmap v0.9.0.
186
+
139
187
  ### Подключение к Claude Code
140
188
 
141
189
  Сначала возьми **два абсолютных пути** в терминале:
package/ingest.js CHANGED
@@ -61,6 +61,8 @@ import {
61
61
  vaultSlug,
62
62
  shouldSkipPath,
63
63
  } from './lib/parse-obsidian.js';
64
+ import { installHook as installSessionStartHook } from './lib/hook/install.js';
65
+ import { createInterface } from 'node:readline';
64
66
  import {
65
67
  CONFIG_PATH,
66
68
  KNOWN_SOURCES,
@@ -137,7 +139,12 @@ if (subcommand && subcommand !== '--help' && subcommand.startsWith('-') === fals
137
139
  console.error(`usage: memex-sync [install|uninstall|status|logs|serve]`);
138
140
  process.exit(2);
139
141
  }
140
- handler();
142
+ // Handlers may be sync (most) or async (cmdInstall after v0.8 — needs readline
143
+ // for the auto-context prompt). Promise.resolve() normalises both.
144
+ Promise.resolve(handler()).catch((e) => {
145
+ console.error(`error in ${subcommand}: ${e.stack || e.message}`);
146
+ process.exit(1);
147
+ });
141
148
  // CLI handlers either exit themselves or fall through to daemon mode (cmdServe)
142
149
  } else if (subcommand === '--help' || subcommand === '-h') {
143
150
  console.log(`memex-sync — auto-capture daemon for memex memory
@@ -185,7 +192,7 @@ paths:
185
192
 
186
193
  // -------------------- CLI command handlers --------------------
187
194
 
188
- function cmdInstall() {
195
+ async function cmdInstall() {
189
196
  if (platform() !== 'darwin') {
190
197
  console.error('install: macOS-only for now (LaunchAgent). Linux systemd-user support pending.');
191
198
  console.error('on Linux you can run: nohup memex-sync &');
@@ -243,6 +250,18 @@ function cmdInstall() {
243
250
  console.log(` log: ${LOG_PATH}`);
244
251
  console.log('');
245
252
 
253
+ // ── Auto-context prompt (v0.8+) ─────────────────────────────────────
254
+ // Bundle Claude Code SessionStart hook install into the same flow
255
+ // the user is already running. Single [Y/n] beats a separate command
256
+ // they'd never remember.
257
+ //
258
+ // Honor non-interactive flags / env for CI:
259
+ // --auto-context yes explicit opt-in
260
+ // --auto-context no explicit opt-out
261
+ // --yes / -y accept all defaults (yes)
262
+ // $MEMEX_AUTO_CONTEXT=yes|no env override
263
+ await maybeInstallAutoContextHook();
264
+
246
265
  // Show what daemon will actually capture, based on current config.
247
266
  const cfg = loadConfig();
248
267
  console.log('memex-sync will capture from these sources:');
@@ -277,6 +296,97 @@ function cmdInstall() {
277
296
  process.exit(0);
278
297
  }
279
298
 
299
+ // ──────────────────────────────────────────────────────────────────
300
+ // Auto-context hook prompt — bundled into `memex-sync install` so the
301
+ // user doesn't need to remember an extra `memex hook install` step.
302
+ //
303
+ // Decision priority:
304
+ // 1. CLI flag --auto-context=yes|no (explicit)
305
+ // 2. CLI flag --yes / -y (accept all defaults: yes)
306
+ // 3. env MEMEX_AUTO_CONTEXT=yes|no (for CI / scripts)
307
+ // 4. Interactive [Y/n] prompt (TTY only)
308
+ // 5. Default: SKIP if no TTY (don't hang on stdin in non-TTY contexts)
309
+ async function maybeInstallAutoContextHook() {
310
+ const argv = process.argv.slice(3); // drop ["node", "ingest.js", "install"]
311
+
312
+ // Parse flags
313
+ let explicit = null; // 'yes' | 'no' | null
314
+ for (let i = 0; i < argv.length; i++) {
315
+ const a = argv[i];
316
+ if (a === '--auto-context') {
317
+ const v = (argv[++i] || '').toLowerCase();
318
+ if (v === 'yes' || v === 'y' || v === 'true') explicit = 'yes';
319
+ else if (v === 'no' || v === 'n' || v === 'false') explicit = 'no';
320
+ } else if (a === '--auto-context=yes') explicit = 'yes';
321
+ else if (a === '--auto-context=no') explicit = 'no';
322
+ else if (a === '--yes' || a === '-y') explicit = 'yes';
323
+ }
324
+
325
+ // Env fallback
326
+ if (explicit === null) {
327
+ const env = (process.env.MEMEX_AUTO_CONTEXT || '').toLowerCase();
328
+ if (env === 'yes' || env === 'y' || env === 'true' || env === '1') explicit = 'yes';
329
+ else if (env === 'no' || env === 'n' || env === 'false' || env === '0') explicit = 'no';
330
+ }
331
+
332
+ // Interactive prompt as last resort
333
+ if (explicit === null) {
334
+ if (!process.stdin.isTTY) {
335
+ // Non-interactive (CI, scripts, install-skill flows that don't pipe stdin):
336
+ // skip silently. User can run `memex hook install` later.
337
+ console.log('Auto-context hook: skipped (non-interactive). Enable with: memex hook install');
338
+ console.log('');
339
+ return;
340
+ }
341
+ explicit = await promptYesNo(
342
+ `Auto-context (Brian Chesky mode):\n` +
343
+ ` When you open Claude Code in a project, memex can inject 500-1500 tokens\n` +
344
+ ` of relevant context so Claude knows what you were doing — without you\n` +
345
+ ` having to ask. Adds a SessionStart hook to ~/.claude/settings.json.\n` +
346
+ ` Other hooks (e.g. gstack) are preserved.\n\n` +
347
+ ` Enable?`,
348
+ 'yes' // default Y
349
+ );
350
+ }
351
+
352
+ if (explicit !== 'yes') {
353
+ console.log('Auto-context hook: skipped. Enable later with: memex hook install');
354
+ console.log('');
355
+ return;
356
+ }
357
+
358
+ const r = installSessionStartHook();
359
+ if (r.error) {
360
+ console.log(`Auto-context hook: ✗ ${r.error}`);
361
+ console.log(' (memex-sync daemon still works — only the auto-context hook failed)');
362
+ console.log('');
363
+ return;
364
+ }
365
+ if (r.alreadyPresent) {
366
+ console.log('Auto-context hook: already installed (no-op).');
367
+ } else {
368
+ console.log('Auto-context hook: ✓ installed.');
369
+ console.log(` settings: ${r.settingsPath}`);
370
+ console.log(` command: ${r.command}`);
371
+ console.log(' Restart Claude Code (Cmd+Q + reopen) to activate.');
372
+ }
373
+ console.log('');
374
+ }
375
+
376
+ function promptYesNo(question, defaultAnswer) {
377
+ return new Promise((resolve) => {
378
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
379
+ const suffix = defaultAnswer === 'yes' ? ' [Y/n] ' : ' [y/N] ';
380
+ rl.question(question + suffix, (answer) => {
381
+ rl.close();
382
+ const v = (answer || '').trim().toLowerCase();
383
+ if (v === 'y' || v === 'yes') resolve('yes');
384
+ else if (v === 'n' || v === 'no') resolve('no');
385
+ else resolve(defaultAnswer); // empty enter → default
386
+ });
387
+ });
388
+ }
389
+
280
390
  function cmdUninstall() {
281
391
  if (platform() !== 'darwin') {
282
392
  console.error('uninstall: macOS-only for now.');