Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions .claude-plugin/marketplace.json

This file was deleted.

18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,20 @@ Restart Lucid after changing a serving model. When the endpoint reports a differ
<details>
<summary><b>Optional Claude Code assistant-response capture</b></summary>

**Existing v0.6.5 installations.** Close Lucid clients. From a full checkout of this repository, run `bash scripts/upgrade-v065-capture.sh` (on Windows, use Git Bash). This one-time migration verifies the five server source files it touches and preserves the database, profiles, dependencies and other hooks. It refuses locally edited sources. Use `--rollback` to restore the stock files after uninstalling the plugin. A fresh install from a revision containing this feature can skip the migration.

The v0.6.5 migration installs response capture only. It keeps the v0.6.5 embedding cache code. Before a newer server upgrades a shared database for endpoint-specific vectors, stop and update **every** client that uses that database. A stock or capture-only v0.6.5 server can discard other models' cached vectors when it opens the upgraded database. Use separate databases if clients must run different versions during rollout.

With an updated Lucid Memory installation, enable the first-party Claude Code plugin to save replies observed at a Claude Code Stop event. Start a new Claude session after installation.
If you select Claude Code during installation, the installer offers to capture assistant replies. You can also turn capture on or off afterward. Restart Claude Code after changing the setting.

```shell
claude plugin marketplace add JasonDocton/lucid-memory
claude plugin install claude-response-capture@lucid-memory
lucid config claude-responses on
lucid config claude-responses off
```

The plugin saves up to 2,000 Unicode characters from each nonempty final reply in the active Claude database and project. Replies are tagged as assistant conversations and can be retrieved in later sessions. Lucid's configured embedding provider may process this text. Repeated delivery of the same reply for the same prompt is ignored. A Stop hook can ask Claude to continue, so a single user prompt can produce several replies. Capture requires a Stop payload with a session ID, prompt or turn ID, working directory, and final message. Use Claude Code 2.1.258 or later for the tested hook fields. Configless installations use the shared default. For named profiles, specify an absolute or home-relative database path.
Lucid registers a command under `hooks.Stop` in your Claude Code settings. Your other Stop handlers stay in place. Turning capture off preserves replies you have already saved.

**Existing v0.6.5 installations.** Close Lucid clients and run `bash scripts/upgrade-v065-capture.sh` from a full checkout (Git Bash on Windows). It checks the five server source files, enables the direct hook, and preserves database and profile settings. Use `--rollback` to remove the hook and restore the stock files. If the server already has response capture but the CLI predates this setting, run `bun run --no-env-file --no-install ./packages/lucid-server/src/claude-hook.ts on` from the checkout instead. Use `off` to disable it. The setup migrates an enabled user-level `claude-response-capture@lucid-memory` installation to the direct hook.

The v0.6.5 migration installs response capture only. It keeps the v0.6.5 embedding cache code. Before a newer server upgrades a shared database for endpoint-specific vectors, stop and update **every** client that uses that database. A stock or capture-only v0.6.5 server can discard other models' cached vectors when it opens the upgraded database. Use separate databases if clients must run different versions during rollout.

To turn off future capture, run `claude plugin uninstall claude-response-capture@lucid-memory` and start a new session. Previously stored replies stay in Lucid. Uninstall the plugin before removing Lucid itself.
Lucid saves up to 2,000 Unicode characters from each nonempty final reply in the active Claude database and project. Replies are tagged as assistant conversations and can be retrieved in later sessions. Lucid's configured embedding provider may process this text. Repeated delivery of the same reply for the same prompt is ignored. A Stop hook can ask Claude to continue, so a single user prompt can produce several replies. Capture requires a Stop payload with a session ID, prompt or turn ID, working directory, and final message. Use Claude Code 2.1.258 or later for the tested hook fields. Configless installations use the shared default. For named profiles, specify an absolute or home-relative database path.

</details>

Expand Down
9 changes: 9 additions & 0 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,15 @@ if ($InstallClaude) {
} catch {
Write-Warn "Could not configure Claude hook in settings.json - manual setup may be needed"
}

$CaptureMode = "keep"
$Choice = Read-Host "Save Claude's assistant replies in Lucid? [y/n, Enter keeps current setting; default off]"
if ($Choice -match '^[Yy]') { $CaptureMode = "on" }
if ($Choice -match '^[Nn]') { $CaptureMode = "off" }
& bun run --cwd "$LucidDir\server" --no-env-file --no-install "$LucidDir\server\src\claude-hook.ts" $CaptureMode
if ($LASTEXITCODE -ne 0) { Write-Warn "Could not configure assistant-response capture." }
Write-Host "Manage assistant-response capture with: lucid config claude-responses on|off"

}

if ($InstallCodex) {
Expand Down
13 changes: 13 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1583,6 +1583,19 @@ if [ "$INSTALL_CLAUDE" = true ]; then
else
warn "Claude hook configuration requires manual setup"
fi

capture_mode=keep
if [ "$INTERACTIVE" = true ]; then
read -r -p "Save Claude's assistant replies in Lucid? [y/n, Enter keeps current setting; default off]: " choice || choice=
case "$choice" in
[Yy]*) capture_mode=on ;;
[Nn]*) capture_mode=off ;;
esac
fi
if ! bun run --cwd "$LUCID_DIR/server" --no-env-file --no-install "$LUCID_DIR/server/src/claude-hook.ts" "$capture_mode"; then
warn "Could not configure assistant-response capture."
fi
echo "Manage assistant-response capture with: lucid config claude-responses on|off"
fi

# === Add to PATH ===
Expand Down

This file was deleted.

22 changes: 0 additions & 22 deletions packages/lucid-server/claude-response-capture/capture.ts

This file was deleted.

23 changes: 0 additions & 23 deletions packages/lucid-server/claude-response-capture/hooks/hooks.json

This file was deleted.

156 changes: 156 additions & 0 deletions packages/lucid-server/src/claude-hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// This file also runs from ~/.lucid/hooks on v0.6.5 installations.
import { randomUUID } from "node:crypto"
import {
link,
lstat,
mkdir,
readFile,
realpath,
rename,
rm,
stat,
writeFile,
} from "node:fs/promises"
import { homedir } from "node:os"
import { dirname, join } from "node:path"
import { pathToFileURL } from "node:url"

const lucid = join(homedir(), ".lucid")
const installedHook = join(lucid, "hooks", "claude-stop.ts")
const handler = join(lucid, "server", "src", "claude-stop.ts")
const args = [
"run",
"--cwd",
dirname(installedHook),
"--no-env-file",
"--no-install",
installedHook,
]
const byteOrderMark = /^\uFEFF/
const oldPlugin = "claude-response-capture@lucid-memory"

function object(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value)
}

async function readOptional(path: string) {
try {
return await readFile(path, "utf8")
} catch (error) {
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error
return undefined
}
}

async function replaceFile(
path: string,
contents: string,
previous: string | undefined,
mode: number
) {
const temporary = `${path}.${randomUUID()}.tmp`
await mkdir(dirname(path), { recursive: true })
try {
await writeFile(temporary, contents, { flag: "wx", mode })
if ((await readOptional(path)) !== previous)
throw new Error(`File changed during update: ${path}`)
if (previous === undefined) await link(temporary, path)
else await rename(temporary, path)
} finally {
await rm(temporary, { force: true })
}
}

export async function configureClaudeHook(action: "on" | "off" | "keep") {
const location = join(
// biome-ignore lint/style/noProcessEnv: Claude honors a custom configuration directory.
process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"),
"settings.json"
)
const entry = await lstat(location).catch((error: NodeJS.ErrnoException) => {
if (error.code !== "ENOENT") throw error
return undefined
})
const path = entry ? await realpath(location) : location
const previous = await readOptional(path)
const config: unknown =
previous === undefined
? {}
: JSON.parse(previous.replace(byteOrderMark, ""))
if (!object(config)) throw new Error("Invalid Claude settings")
const original = JSON.stringify(config)
const hooks = config.hooks === undefined ? {} : config.hooks
if (!object(hooks)) throw new Error("Invalid Claude hooks")
const groups = hooks.Stop === undefined ? [] : hooks.Stop
if (!Array.isArray(groups)) throw new Error("Invalid Claude Stop hooks")

const plugins = config.enabledPlugins
const priorOptIn = object(plugins) && plugins[oldPlugin] === true
let found = false
const updated = groups.flatMap((group: unknown) => {
if (!object(group) || !Array.isArray(group.hooks))
throw new Error("Invalid Claude Stop handler group")
const remaining = group.hooks.filter((hook: unknown) => {
if (
!object(hook) ||
hook.type !== "command" ||
hook.command !== "bun" ||
JSON.stringify(hook.args) !== JSON.stringify(args)
)
return true
const retain = action !== "off" && !found
found = true
return retain
})
if (remaining.length === group.hooks.length) return [group]
return remaining.length ? [{ ...group, hooks: remaining }] : []
})
const enable = action === "on" || (action === "keep" && (priorOptIn || found))
if (enable) {
if (!(await Bun.file(handler).exists()))
throw new Error(
"Update the Lucid server before enabling response capture"
)
const source = await readFile(import.meta.path, "utf8")
const existing = await readOptional(installedHook)
if (source !== existing)
await replaceFile(installedHook, source, existing, 0o600)
if (!found)
updated.push({
hooks: [{ type: "command", command: "bun", args, timeout: 10 }],
})
}
if (JSON.stringify(updated) !== JSON.stringify(groups)) {
config.hooks = hooks
if (updated.length) hooks.Stop = updated
else delete hooks.Stop
}
if (object(plugins) && priorOptIn) plugins[oldPlugin] = false
if (JSON.stringify(config) === original) return
await replaceFile(
path,
`${JSON.stringify(config, null, 2)}\n`,
previous,
entry ? (await stat(path)).mode & 0o777 : 0o600
)
}

if (import.meta.main) {
const action = process.argv[2]
try {
if (action === "on" || action === "off" || action === "keep")
await configureClaudeHook(action)
else if (action !== undefined) throw new Error("Expected on, off, or keep")
else if (await Bun.file(join(lucid, "server", "package.json")).exists()) {
const { captureStop } = await import(pathToFileURL(handler).href)
await captureStop(await Bun.stdin.text())
}
} catch (error) {
console.error(
action
? `Lucid could not update Claude's Stop hook: ${error instanceof Error ? error.message : String(error)}`
: "Lucid could not store the response. Check the Claude profile and database."
)
process.exitCode = 1
}
}
Loading
Loading