@audaxic/memory-claude 1.0.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.
- package/.claude-plugin/plugin.json +18 -0
- package/README.md +91 -0
- package/bin/install.js +113 -0
- package/hooks/hooks.json +28 -0
- package/package.json +31 -0
- package/scripts/capture.js +108 -0
- package/scripts/inject.js +126 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "audaxic-memory",
|
|
3
|
+
"description": "Saves conversation facts to Audaxic Memory and injects semantic context into prompts",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Audaxic",
|
|
7
|
+
"url": "https://memory.audaxic.com"
|
|
8
|
+
},
|
|
9
|
+
"userConfig": {
|
|
10
|
+
"apiToken": {
|
|
11
|
+
"title": "Audaxic API Key",
|
|
12
|
+
"description": "Your Audaxic Memory API key. Get one at https://memory-dashboard.audaxic.com",
|
|
13
|
+
"type": "string",
|
|
14
|
+
"required": true,
|
|
15
|
+
"sensitive": true
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# @audaxic/memory-claude
|
|
2
|
+
|
|
3
|
+
Claude Code plugin for [Audaxic Memory](https://memory.audaxic.com) — automatically saves conversation facts and injects semantic context into the agent.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx @audaxic/memory-claude install
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This will:
|
|
12
|
+
1. Prompt for your Audaxic API key (saved to `~/.config/audaxic/config.json`)
|
|
13
|
+
2. Copy the plugin to `~/.claude/skills/audaxic-memory/`
|
|
14
|
+
|
|
15
|
+
The plugin auto-loads on your next Claude Code session.
|
|
16
|
+
|
|
17
|
+
Get your API key from: https://memory-dashboard.audaxic.com
|
|
18
|
+
|
|
19
|
+
## How It Works
|
|
20
|
+
|
|
21
|
+
The plugin registers two Claude Code hooks:
|
|
22
|
+
|
|
23
|
+
### `UserPromptSubmit` → `inject.js`
|
|
24
|
+
|
|
25
|
+
When you submit a prompt, this hook:
|
|
26
|
+
1. Buffers your prompt to the plugin data directory
|
|
27
|
+
2. Searches Audaxic Memory for relevant context (`POST /search`)
|
|
28
|
+
3. Injects retrieved memories as `<audaxic_memory_context>` into Claude via `additionalContext`
|
|
29
|
+
|
|
30
|
+
### `Stop` → `capture.js`
|
|
31
|
+
|
|
32
|
+
When Claude finishes responding, this hook:
|
|
33
|
+
1. Buffers the assistant's response
|
|
34
|
+
2. When the buffer reaches 30 messages, flushes to `POST /add`
|
|
35
|
+
3. Skips captures from automatic continuations (`stop_hook_active`)
|
|
36
|
+
|
|
37
|
+
## API Key
|
|
38
|
+
|
|
39
|
+
The plugin reads your API key in this order:
|
|
40
|
+
|
|
41
|
+
1. `CLAUDE_PLUGIN_OPTION_API_TOKEN` — set via the plugin's `userConfig` prompt during `/plugin install`
|
|
42
|
+
2. `~/.config/audaxic/config.json` — shared config used by all Audaxic integrations
|
|
43
|
+
|
|
44
|
+
Both hooks fail silently if no key is found — they never block Claude Code.
|
|
45
|
+
|
|
46
|
+
## Architecture
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
┌──────────────────────────────────────────────────────────────┐
|
|
50
|
+
│ Claude Code │
|
|
51
|
+
│ │
|
|
52
|
+
│ User types prompt │
|
|
53
|
+
│ │ │
|
|
54
|
+
│ ▼ │
|
|
55
|
+
│ UserPromptSubmit ──► inject.js │
|
|
56
|
+
│ │ ├─ buffer user prompt to disk │
|
|
57
|
+
│ │ └─ POST /search → additionalContext │
|
|
58
|
+
│ ▼ │
|
|
59
|
+
│ Claude responds │
|
|
60
|
+
│ │ │
|
|
61
|
+
│ ▼ │
|
|
62
|
+
│ Stop ──────────────► capture.js │
|
|
63
|
+
│ ├─ buffer assistant msg to disk │
|
|
64
|
+
│ └─ if buffer >= 30 → POST /add │
|
|
65
|
+
└──────────────────────────────────────────────────────────────┘
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Uninstall
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
rm -rf ~/.claude/skills/audaxic-memory
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## API Endpoints
|
|
75
|
+
|
|
76
|
+
| Endpoint | Method | Description |
|
|
77
|
+
|----------|--------|-------------|
|
|
78
|
+
| `https://api.memory.audaxic.com/search` | POST | Search memories for context injection |
|
|
79
|
+
| `https://api.memory.audaxic.com/add` | POST | Save conversation messages in batch |
|
|
80
|
+
|
|
81
|
+
## Related
|
|
82
|
+
|
|
83
|
+
- [Audaxic Memory](https://memory.audaxic.com)
|
|
84
|
+
- [Audaxic Memory for OpenCode](https://www.npmjs.com/package/@audaxic/memory-opencode)
|
|
85
|
+
- [Audaxic Memory for Codex](https://www.npmjs.com/package/@audaxic/memory-codex)
|
|
86
|
+
- [Claude Code Hooks Documentation](https://code.claude.com/docs/en/hooks)
|
|
87
|
+
- [Claude Code Plugins Documentation](https://code.claude.com/docs/en/plugins)
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
MIT
|
package/bin/install.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { createInterface } from "node:readline/promises";
|
|
4
|
+
import { stdin, stdout } from "node:process";
|
|
5
|
+
import {
|
|
6
|
+
mkdir,
|
|
7
|
+
readFile,
|
|
8
|
+
writeFile,
|
|
9
|
+
copyFile,
|
|
10
|
+
access,
|
|
11
|
+
readdir,
|
|
12
|
+
} from "node:fs/promises";
|
|
13
|
+
import { join, dirname } from "node:path";
|
|
14
|
+
import { homedir } from "node:os";
|
|
15
|
+
import { fileURLToPath } from "node:url";
|
|
16
|
+
|
|
17
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
18
|
+
const __dirname = dirname(__filename);
|
|
19
|
+
|
|
20
|
+
const PACKAGE_ROOT = join(__dirname, "..");
|
|
21
|
+
const CONFIG_DIR = join(homedir(), ".config", "audaxic");
|
|
22
|
+
const CONFIG_PATH = join(CONFIG_DIR, "config.json");
|
|
23
|
+
const PLUGIN_DEST = join(homedir(), ".claude", "skills", "audaxic-memory");
|
|
24
|
+
|
|
25
|
+
const DIRS_TO_COPY = [".claude-plugin", "hooks", "scripts"];
|
|
26
|
+
|
|
27
|
+
async function pathExists(p) {
|
|
28
|
+
try {
|
|
29
|
+
await access(p);
|
|
30
|
+
return true;
|
|
31
|
+
} catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function copyDir(src, dest) {
|
|
37
|
+
await mkdir(dest, { recursive: true });
|
|
38
|
+
const entries = await readdir(src, { withFileTypes: true });
|
|
39
|
+
for (const entry of entries) {
|
|
40
|
+
const srcPath = join(src, entry.name);
|
|
41
|
+
const destPath = join(dest, entry.name);
|
|
42
|
+
if (entry.isDirectory()) {
|
|
43
|
+
await copyDir(srcPath, destPath);
|
|
44
|
+
} else {
|
|
45
|
+
await copyFile(srcPath, destPath);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function ensureApiKeyFile(rl) {
|
|
51
|
+
if (await pathExists(CONFIG_PATH)) return;
|
|
52
|
+
console.log(
|
|
53
|
+
"\nNo Audaxic config found. Get your API key from: https://memory-dashboard.audaxic.com"
|
|
54
|
+
);
|
|
55
|
+
const apiKey = await rl.question("Enter your Audaxic API Key: ");
|
|
56
|
+
if (!apiKey.trim()) {
|
|
57
|
+
console.error("\nError: API key cannot be empty.");
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
await mkdir(CONFIG_DIR, { recursive: true });
|
|
61
|
+
await writeFile(
|
|
62
|
+
CONFIG_PATH,
|
|
63
|
+
JSON.stringify({ apiKey: apiKey.trim() }, null, 2),
|
|
64
|
+
{ mode: 0o600 }
|
|
65
|
+
);
|
|
66
|
+
console.log("✓ API key saved to ~/.config/audaxic/config.json");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function main() {
|
|
70
|
+
console.log("\n╔══════════════════════════════════════════╗");
|
|
71
|
+
console.log("║ Audaxic Memory — Claude Code Setup ║");
|
|
72
|
+
console.log("╚══════════════════════════════════════════╝\n");
|
|
73
|
+
|
|
74
|
+
const rl = createInterface({ input: stdin, output: stdout });
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
await ensureApiKeyFile(rl);
|
|
78
|
+
|
|
79
|
+
const alreadyInstalled = await pathExists(PLUGIN_DEST);
|
|
80
|
+
if (alreadyInstalled) {
|
|
81
|
+
const overwrite = await rl.question(
|
|
82
|
+
"Plugin already installed at ~/.claude/skills/audaxic-memory/. Overwrite? (y/N): "
|
|
83
|
+
);
|
|
84
|
+
if (overwrite.toLowerCase() !== "y") {
|
|
85
|
+
console.log("\nSetup cancelled. Existing plugin preserved.");
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
for (const dir of DIRS_TO_COPY) {
|
|
91
|
+
await copyDir(join(PACKAGE_ROOT, dir), join(PLUGIN_DEST, dir));
|
|
92
|
+
}
|
|
93
|
+
console.log("✓ Plugin files copied to ~/.claude/skills/audaxic-memory/");
|
|
94
|
+
|
|
95
|
+
console.log("\n╔══════════════════════════════════════════╗");
|
|
96
|
+
console.log("║ Setup Complete! ║");
|
|
97
|
+
console.log("╚══════════════════════════════════════════╝\n");
|
|
98
|
+
console.log("Audaxic Memory is now active in Claude Code.");
|
|
99
|
+
console.log(" • UserPromptSubmit → searches memory + injects context");
|
|
100
|
+
console.log(" • Stop → buffers messages + auto-flushes at 30");
|
|
101
|
+
console.log("\nThe plugin auto-loads on your next Claude Code session.");
|
|
102
|
+
console.log("If the API key prompt doesn't appear, the key from");
|
|
103
|
+
console.log("~/.config/audaxic/config.json will be used automatically.\n");
|
|
104
|
+
console.log("To uninstall, delete ~/.claude/skills/audaxic-memory/\n");
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.error("\nSetup failed:", error.message);
|
|
107
|
+
process.exit(1);
|
|
108
|
+
} finally {
|
|
109
|
+
rl.close();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
main();
|
package/hooks/hooks.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"UserPromptSubmit": [
|
|
4
|
+
{
|
|
5
|
+
"hooks": [
|
|
6
|
+
{
|
|
7
|
+
"type": "command",
|
|
8
|
+
"command": "node",
|
|
9
|
+
"args": ["${CLAUDE_PLUGIN_ROOT}/scripts/inject.js"],
|
|
10
|
+
"timeout": 10
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"Stop": [
|
|
16
|
+
{
|
|
17
|
+
"hooks": [
|
|
18
|
+
{
|
|
19
|
+
"type": "command",
|
|
20
|
+
"command": "node",
|
|
21
|
+
"args": ["${CLAUDE_PLUGIN_ROOT}/scripts/capture.js"],
|
|
22
|
+
"timeout": 30
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@audaxic/memory-claude",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Claude Code plugin for Audaxic Memory — automatically saves conversation facts and injects semantic context",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"audaxic-claude-install": "./bin/install.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
".claude-plugin",
|
|
12
|
+
"hooks",
|
|
13
|
+
"scripts"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"claude",
|
|
17
|
+
"claude-code",
|
|
18
|
+
"anthropic",
|
|
19
|
+
"memory",
|
|
20
|
+
"audaxic",
|
|
21
|
+
"ai",
|
|
22
|
+
"context",
|
|
23
|
+
"hooks"
|
|
24
|
+
],
|
|
25
|
+
"author": "Audaxic",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"homepage": "https://memory.audaxic.com",
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18.0.0"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
|
|
5
|
+
const API_BASE = "https://api.memory.audaxic.com";
|
|
6
|
+
const CONFIG_PATH = join(homedir(), ".config", "audaxic", "config.json");
|
|
7
|
+
const BUFFER_DIR =
|
|
8
|
+
process.env.CLAUDE_PLUGIN_DATA || join(homedir(), ".claude", "audaxic");
|
|
9
|
+
const BUFFER_PATH = join(BUFFER_DIR, "buffer.json");
|
|
10
|
+
const BUFFER_FLUSH_SIZE = 30;
|
|
11
|
+
|
|
12
|
+
async function readStdin() {
|
|
13
|
+
const chunks = [];
|
|
14
|
+
for await (const chunk of process.stdin) {
|
|
15
|
+
chunks.push(chunk);
|
|
16
|
+
}
|
|
17
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf-8"));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function loadApiKey() {
|
|
21
|
+
const envKey = process.env.CLAUDE_PLUGIN_OPTION_API_TOKEN;
|
|
22
|
+
if (envKey && envKey.trim()) return envKey.trim();
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const raw = await readFile(CONFIG_PATH, "utf-8");
|
|
26
|
+
const config = JSON.parse(raw);
|
|
27
|
+
if (typeof config.apiKey === "string" && config.apiKey.length > 0) {
|
|
28
|
+
return config.apiKey;
|
|
29
|
+
}
|
|
30
|
+
} catch {}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function readBuffer() {
|
|
35
|
+
try {
|
|
36
|
+
const raw = await readFile(BUFFER_PATH, "utf-8");
|
|
37
|
+
const arr = JSON.parse(raw);
|
|
38
|
+
return Array.isArray(arr) ? arr : [];
|
|
39
|
+
} catch {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function writeBuffer(buffer) {
|
|
45
|
+
await mkdir(BUFFER_DIR, { recursive: true });
|
|
46
|
+
await writeFile(BUFFER_PATH, JSON.stringify(buffer, null, 2), {
|
|
47
|
+
mode: 0o600,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function flushToApi(apiKey, messages) {
|
|
52
|
+
const timestamp = new Date().toISOString().split("T")[0];
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
const response = await fetch(`${API_BASE}/add`, {
|
|
56
|
+
method: "POST",
|
|
57
|
+
headers: {
|
|
58
|
+
"Content-Type": "application/json",
|
|
59
|
+
Authorization: `Bearer ${apiKey}`,
|
|
60
|
+
},
|
|
61
|
+
body: JSON.stringify({ messages, timestamp }),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return response.ok;
|
|
65
|
+
} catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function main() {
|
|
71
|
+
try {
|
|
72
|
+
const input = await readStdin();
|
|
73
|
+
|
|
74
|
+
if (input.stop_hook_active) {
|
|
75
|
+
process.exit(0);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const assistantMessage = input.last_assistant_message;
|
|
79
|
+
if (
|
|
80
|
+
!assistantMessage ||
|
|
81
|
+
typeof assistantMessage !== "string" ||
|
|
82
|
+
!assistantMessage.trim()
|
|
83
|
+
) {
|
|
84
|
+
process.exit(0);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const apiKey = await loadApiKey();
|
|
88
|
+
if (!apiKey) {
|
|
89
|
+
process.exit(0);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const buffer = await readBuffer();
|
|
93
|
+
buffer.push(assistantMessage.trim());
|
|
94
|
+
|
|
95
|
+
if (buffer.length >= BUFFER_FLUSH_SIZE) {
|
|
96
|
+
const success = await flushToApi(apiKey, buffer);
|
|
97
|
+
await writeBuffer(success ? [] : buffer);
|
|
98
|
+
} else {
|
|
99
|
+
await writeBuffer(buffer);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
process.exit(0);
|
|
103
|
+
} catch {
|
|
104
|
+
process.exit(0);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
main();
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
|
|
5
|
+
const API_BASE = "https://api.memory.audaxic.com";
|
|
6
|
+
const CONFIG_PATH = join(homedir(), ".config", "audaxic", "config.json");
|
|
7
|
+
const BUFFER_DIR =
|
|
8
|
+
process.env.CLAUDE_PLUGIN_DATA || join(homedir(), ".claude", "audaxic");
|
|
9
|
+
const BUFFER_PATH = join(BUFFER_DIR, "buffer.json");
|
|
10
|
+
|
|
11
|
+
async function readStdin() {
|
|
12
|
+
const chunks = [];
|
|
13
|
+
for await (const chunk of process.stdin) {
|
|
14
|
+
chunks.push(chunk);
|
|
15
|
+
}
|
|
16
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf-8"));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function loadApiKey() {
|
|
20
|
+
const envKey = process.env.CLAUDE_PLUGIN_OPTION_API_TOKEN;
|
|
21
|
+
if (envKey && envKey.trim()) return envKey.trim();
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const raw = await readFile(CONFIG_PATH, "utf-8");
|
|
25
|
+
const config = JSON.parse(raw);
|
|
26
|
+
if (typeof config.apiKey === "string" && config.apiKey.length > 0) {
|
|
27
|
+
return config.apiKey;
|
|
28
|
+
}
|
|
29
|
+
} catch {}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function readBuffer() {
|
|
34
|
+
try {
|
|
35
|
+
const raw = await readFile(BUFFER_PATH, "utf-8");
|
|
36
|
+
const arr = JSON.parse(raw);
|
|
37
|
+
return Array.isArray(arr) ? arr : [];
|
|
38
|
+
} catch {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function writeBuffer(buffer) {
|
|
44
|
+
await mkdir(BUFFER_DIR, { recursive: true });
|
|
45
|
+
await writeFile(BUFFER_PATH, JSON.stringify(buffer, null, 2), {
|
|
46
|
+
mode: 0o600,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function searchMemory(apiKey, query) {
|
|
51
|
+
const controller = new AbortController();
|
|
52
|
+
const timeout = setTimeout(() => controller.abort(), 5000);
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
const response = await fetch(`${API_BASE}/search`, {
|
|
56
|
+
method: "POST",
|
|
57
|
+
headers: {
|
|
58
|
+
"Content-Type": "application/json",
|
|
59
|
+
Authorization: `Bearer ${apiKey}`,
|
|
60
|
+
},
|
|
61
|
+
body: JSON.stringify({ query, limit: 5 }),
|
|
62
|
+
signal: controller.signal,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
if (!response.ok) return [];
|
|
66
|
+
|
|
67
|
+
const data = await response.json();
|
|
68
|
+
return Array.isArray(data.results) ? data.results : [];
|
|
69
|
+
} catch {
|
|
70
|
+
return [];
|
|
71
|
+
} finally {
|
|
72
|
+
clearTimeout(timeout);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function outputJson(obj) {
|
|
77
|
+
process.stdout.write(JSON.stringify(obj));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function main() {
|
|
81
|
+
try {
|
|
82
|
+
const input = await readStdin();
|
|
83
|
+
const prompt = input.prompt;
|
|
84
|
+
|
|
85
|
+
if (!prompt || typeof prompt !== "string" || !prompt.trim()) {
|
|
86
|
+
outputJson({});
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const apiKey = await loadApiKey();
|
|
91
|
+
if (!apiKey) {
|
|
92
|
+
outputJson({});
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const buffer = await readBuffer();
|
|
97
|
+
buffer.push(prompt.trim());
|
|
98
|
+
await writeBuffer(buffer);
|
|
99
|
+
|
|
100
|
+
const results = await searchMemory(apiKey, prompt.trim());
|
|
101
|
+
if (!results.length) {
|
|
102
|
+
outputJson({});
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const memories = results
|
|
107
|
+
.map((r) => (typeof r.memory === "string" ? r.memory.trim() : ""))
|
|
108
|
+
.filter(Boolean);
|
|
109
|
+
|
|
110
|
+
if (!memories.length) {
|
|
111
|
+
outputJson({});
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
outputJson({
|
|
116
|
+
hookSpecificOutput: {
|
|
117
|
+
hookEventName: "UserPromptSubmit",
|
|
118
|
+
additionalContext: `<audaxic_memory_context>\n${memories.join("\n")}\n</audaxic_memory_context>`,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
} catch {
|
|
122
|
+
outputJson({});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
main();
|