@audaxic/memory-claude 1.0.5 → 1.1.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/README.md +11 -8
- package/bin/install.js +1 -1
- package/package.json +1 -1
- package/scripts/capture.mjs +7 -48
- package/scripts/inject.mjs +18 -23
- package/scripts/parking.mjs +136 -0
package/README.md
CHANGED
|
@@ -31,8 +31,10 @@ The plugin bundles the Audaxic MCP server (`.mcp.json`), giving Claude `search_m
|
|
|
31
31
|
|
|
32
32
|
### Hooks → background saving
|
|
33
33
|
|
|
34
|
-
- `UserPromptSubmit` → `inject.mjs`:
|
|
35
|
-
- `Stop` → `capture.mjs`:
|
|
34
|
+
- `UserPromptSubmit` → `inject.mjs`: saves your prompt immediately and injects context via `additionalContext` (a passive enhancement — injection may be deprioritized by Claude Code, which is why the skill + MCP path exists)
|
|
35
|
+
- `Stop` → `capture.mjs`: saves the assistant's response immediately
|
|
36
|
+
|
|
37
|
+
Saving is crash-safe and parallel-safe: each message is written to its own parking file under `${CLAUDE_PLUGIN_DATA}/pending/` and deleted only after `POST /add` confirms receipt. Failed saves stay parked and are retried automatically (stale files, older than 60s, are claimed atomically). Multiple simultaneous Claude Code sessions never share or overwrite files.
|
|
36
38
|
|
|
37
39
|
## API Key
|
|
38
40
|
|
|
@@ -54,16 +56,17 @@ All scripts fail silently if no key is found — they never block Claude Code.
|
|
|
54
56
|
│ User types prompt │
|
|
55
57
|
│ │ │
|
|
56
58
|
│ ▼ │
|
|
57
|
-
│ UserPromptSubmit ──► inject.
|
|
58
|
-
│ │ ├─
|
|
59
|
+
│ UserPromptSubmit ──► inject.mjs │
|
|
60
|
+
│ │ ├─ park + POST /add (immediate) │
|
|
59
61
|
│ │ └─ POST /search → additionalContext │
|
|
60
62
|
│ ▼ │
|
|
61
63
|
│ Claude responds │
|
|
62
64
|
│ │ │
|
|
63
65
|
│ ▼ │
|
|
64
|
-
│ Stop ──────────────► capture.
|
|
65
|
-
│
|
|
66
|
-
│
|
|
66
|
+
│ Stop ──────────────► capture.mjs │
|
|
67
|
+
│ └─ park + POST /add (immediate) │
|
|
68
|
+
│ │
|
|
69
|
+
│ pending/ → per-message parking files, retried when stale │
|
|
67
70
|
└──────────────────────────────────────────────────────────────┘
|
|
68
71
|
```
|
|
69
72
|
|
|
@@ -78,7 +81,7 @@ rm -rf ~/.claude/skills/audaxic-memory
|
|
|
78
81
|
| Endpoint | Method | Description |
|
|
79
82
|
|----------|--------|-------------|
|
|
80
83
|
| `https://api.memory.audaxic.com/search` | POST | Search memories for context injection |
|
|
81
|
-
| `https://api.memory.audaxic.com/add` | POST | Save conversation messages
|
|
84
|
+
| `https://api.memory.audaxic.com/add` | POST | Save conversation messages |
|
|
82
85
|
|
|
83
86
|
## Related
|
|
84
87
|
|
package/bin/install.js
CHANGED
|
@@ -143,7 +143,7 @@ async function main() {
|
|
|
143
143
|
console.log("Audaxic Memory is now active in Claude Code.");
|
|
144
144
|
console.log(" • Skill → auto-searches memory for your questions");
|
|
145
145
|
console.log(" • MCP tools → search_memories / add_memory");
|
|
146
|
-
console.log(" • Hooks →
|
|
146
|
+
console.log(" • Hooks → saves every message immediately (parallel-safe)");
|
|
147
147
|
console.log("\nThe plugin auto-loads on your next Claude Code session.");
|
|
148
148
|
console.log("If the API key prompt doesn't appear, the key from");
|
|
149
149
|
console.log("~/.config/audaxic/config.json will be used automatically.\n");
|
package/package.json
CHANGED
package/scripts/capture.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { readFile
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
|
+
import { saveMessage, drainStale, migrateLegacy } from "./parking.mjs";
|
|
4
5
|
|
|
5
|
-
const API_BASE = "https://api.memory.audaxic.com";
|
|
6
6
|
const CONFIG_PATH = join(homedir(), ".config", "audaxic", "config.json");
|
|
7
7
|
const BUFFER_DIR =
|
|
8
8
|
process.env.CLAUDE_PLUGIN_DATA || join(homedir(), ".claude", "audaxic");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const PENDING_DIR = join(BUFFER_DIR, "pending");
|
|
10
|
+
const LEGACY_BUFFER_PATH = join(BUFFER_DIR, "buffer.json");
|
|
11
11
|
|
|
12
12
|
async function readStdin() {
|
|
13
13
|
const chunks = [];
|
|
@@ -31,42 +31,6 @@ async function loadApiKey() {
|
|
|
31
31
|
return null;
|
|
32
32
|
}
|
|
33
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
34
|
async function main() {
|
|
71
35
|
try {
|
|
72
36
|
const input = await readStdin();
|
|
@@ -89,15 +53,10 @@ async function main() {
|
|
|
89
53
|
process.exit(0);
|
|
90
54
|
}
|
|
91
55
|
|
|
92
|
-
|
|
93
|
-
buffer.push(assistantMessage.trim());
|
|
56
|
+
await migrateLegacy(apiKey, LEGACY_BUFFER_PATH, PENDING_DIR);
|
|
94
57
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
await writeBuffer(success ? [] : buffer);
|
|
98
|
-
} else {
|
|
99
|
-
await writeBuffer(buffer);
|
|
100
|
-
}
|
|
58
|
+
await saveMessage(apiKey, PENDING_DIR, assistantMessage.trim());
|
|
59
|
+
await drainStale(apiKey, PENDING_DIR);
|
|
101
60
|
|
|
102
61
|
process.exit(0);
|
|
103
62
|
} catch {
|
package/scripts/inject.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { readFile,
|
|
1
|
+
import { readFile, appendFile, mkdir } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { setDefaultResultOrder } from "node:dns";
|
|
5
|
+
import { saveMessage, drainStale, migrateLegacy } from "./parking.mjs";
|
|
5
6
|
|
|
6
7
|
setDefaultResultOrder("ipv4first");
|
|
7
8
|
|
|
@@ -9,7 +10,8 @@ const API_BASE = "https://api.memory.audaxic.com";
|
|
|
9
10
|
const CONFIG_PATH = join(homedir(), ".config", "audaxic", "config.json");
|
|
10
11
|
const BUFFER_DIR =
|
|
11
12
|
process.env.CLAUDE_PLUGIN_DATA || join(homedir(), ".claude", "audaxic");
|
|
12
|
-
const
|
|
13
|
+
const PENDING_DIR = join(BUFFER_DIR, "pending");
|
|
14
|
+
const LEGACY_BUFFER_PATH = join(BUFFER_DIR, "buffer.json");
|
|
13
15
|
const LOG_PATH = join(BUFFER_DIR, "hook.log");
|
|
14
16
|
const SEARCH_TIMEOUT_MS = 8000;
|
|
15
17
|
const SEARCH_ATTEMPTS = 2;
|
|
@@ -47,23 +49,6 @@ async function loadApiKey() {
|
|
|
47
49
|
return null;
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
async function readBuffer() {
|
|
51
|
-
try {
|
|
52
|
-
const raw = await readFile(BUFFER_PATH, "utf-8");
|
|
53
|
-
const arr = JSON.parse(raw);
|
|
54
|
-
return Array.isArray(arr) ? arr : [];
|
|
55
|
-
} catch {
|
|
56
|
-
return [];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async function writeBuffer(buffer) {
|
|
61
|
-
await mkdir(BUFFER_DIR, { recursive: true });
|
|
62
|
-
await writeFile(BUFFER_PATH, JSON.stringify(buffer, null, 2), {
|
|
63
|
-
mode: 0o600,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
52
|
async function searchOnce(apiKey, query) {
|
|
68
53
|
const controller = new AbortController();
|
|
69
54
|
const timeout = setTimeout(() => controller.abort(), SEARCH_TIMEOUT_MS);
|
|
@@ -104,6 +89,11 @@ async function searchMemory(apiKey, query) {
|
|
|
104
89
|
return [];
|
|
105
90
|
}
|
|
106
91
|
|
|
92
|
+
async function saveAndDrain(apiKey, message) {
|
|
93
|
+
await saveMessage(apiKey, PENDING_DIR, message);
|
|
94
|
+
await drainStale(apiKey, PENDING_DIR);
|
|
95
|
+
}
|
|
96
|
+
|
|
107
97
|
function outputJson(obj) {
|
|
108
98
|
process.stdout.write(JSON.stringify(obj));
|
|
109
99
|
}
|
|
@@ -124,11 +114,16 @@ async function main() {
|
|
|
124
114
|
return;
|
|
125
115
|
}
|
|
126
116
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
await
|
|
117
|
+
await migrateLegacy(apiKey, LEGACY_BUFFER_PATH, PENDING_DIR);
|
|
118
|
+
|
|
119
|
+
const [, searchResult] = await Promise.allSettled([
|
|
120
|
+
saveAndDrain(apiKey, prompt.trim()),
|
|
121
|
+
searchMemory(apiKey, prompt.trim()),
|
|
122
|
+
]);
|
|
123
|
+
|
|
124
|
+
const results =
|
|
125
|
+
searchResult.status === "fulfilled" ? searchResult.value : [];
|
|
130
126
|
|
|
131
|
-
const results = await searchMemory(apiKey, prompt.trim());
|
|
132
127
|
if (!results.length) {
|
|
133
128
|
outputJson({});
|
|
134
129
|
return;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readFile,
|
|
3
|
+
writeFile,
|
|
4
|
+
mkdir,
|
|
5
|
+
unlink,
|
|
6
|
+
rename,
|
|
7
|
+
readdir,
|
|
8
|
+
stat,
|
|
9
|
+
} from "node:fs/promises";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
|
|
12
|
+
const API_BASE = "https://api.memory.audaxic.com";
|
|
13
|
+
export const SEND_TIMEOUT_MS = 6000;
|
|
14
|
+
export const DRAIN_STALE_MS = 60000;
|
|
15
|
+
export const DRAIN_LIMIT = 2;
|
|
16
|
+
|
|
17
|
+
function today() {
|
|
18
|
+
return new Date().toISOString().split("T")[0];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function randomSuffix() {
|
|
22
|
+
return Math.random().toString(36).slice(2, 10);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function postAdd(apiKey, messages, date) {
|
|
26
|
+
const controller = new AbortController();
|
|
27
|
+
const timeout = setTimeout(() => controller.abort(), SEND_TIMEOUT_MS);
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const response = await fetch(`${API_BASE}/add`, {
|
|
31
|
+
method: "POST",
|
|
32
|
+
headers: {
|
|
33
|
+
"Content-Type": "application/json",
|
|
34
|
+
Authorization: `Bearer ${apiKey}`,
|
|
35
|
+
},
|
|
36
|
+
body: JSON.stringify({ messages, timestamp: date || today() }),
|
|
37
|
+
signal: controller.signal,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return response.ok;
|
|
41
|
+
} catch {
|
|
42
|
+
return false;
|
|
43
|
+
} finally {
|
|
44
|
+
clearTimeout(timeout);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function sendParked(apiKey, file) {
|
|
49
|
+
let payload;
|
|
50
|
+
try {
|
|
51
|
+
payload = JSON.parse(await readFile(file, "utf-8"));
|
|
52
|
+
} catch {
|
|
53
|
+
await unlink(file).catch(() => {});
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const message =
|
|
58
|
+
typeof payload?.message === "string" ? payload.message.trim() : "";
|
|
59
|
+
if (!message) {
|
|
60
|
+
await unlink(file).catch(() => {});
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const ok = await postAdd(apiKey, [message], payload.date);
|
|
65
|
+
if (ok) await unlink(file).catch(() => {});
|
|
66
|
+
return ok;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function saveMessage(apiKey, pendingDir, message) {
|
|
70
|
+
const text = typeof message === "string" ? message.trim() : "";
|
|
71
|
+
if (!text) return false;
|
|
72
|
+
|
|
73
|
+
const file = join(pendingDir, `${Date.now()}-${randomSuffix()}.json`);
|
|
74
|
+
try {
|
|
75
|
+
await mkdir(pendingDir, { recursive: true });
|
|
76
|
+
await writeFile(file, JSON.stringify({ message: text, date: today() }), {
|
|
77
|
+
mode: 0o600,
|
|
78
|
+
});
|
|
79
|
+
} catch {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return sendParked(apiKey, file);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function drainStale(apiKey, pendingDir, limit = DRAIN_LIMIT) {
|
|
87
|
+
const entries = await readdir(pendingDir).catch(() => []);
|
|
88
|
+
|
|
89
|
+
let drained = 0;
|
|
90
|
+
for (const entry of entries) {
|
|
91
|
+
if (drained >= limit) break;
|
|
92
|
+
if (!entry.endsWith(".json")) continue;
|
|
93
|
+
|
|
94
|
+
const file = join(pendingDir, entry);
|
|
95
|
+
const info = await stat(file).catch(() => null);
|
|
96
|
+
if (!info || Date.now() - info.mtimeMs < DRAIN_STALE_MS) continue;
|
|
97
|
+
|
|
98
|
+
const claim = `${file}.claim-${randomSuffix()}`;
|
|
99
|
+
try {
|
|
100
|
+
await rename(file, claim);
|
|
101
|
+
} catch {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const ok = await sendParked(apiKey, claim);
|
|
106
|
+
if (!ok) await rename(claim, file).catch(() => {});
|
|
107
|
+
drained++;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export async function migrateLegacy(apiKey, legacyPath, pendingDir) {
|
|
112
|
+
try {
|
|
113
|
+
const raw = await readFile(legacyPath, "utf-8");
|
|
114
|
+
const parsed = JSON.parse(raw);
|
|
115
|
+
const messages = Array.isArray(parsed)
|
|
116
|
+
? parsed.filter((m) => typeof m === "string" && m.trim())
|
|
117
|
+
: [];
|
|
118
|
+
|
|
119
|
+
if (messages.length > 0) {
|
|
120
|
+
const ok = await postAdd(apiKey, messages, today());
|
|
121
|
+
if (!ok) {
|
|
122
|
+
await mkdir(pendingDir, { recursive: true });
|
|
123
|
+
for (const message of messages) {
|
|
124
|
+
const file = join(pendingDir, `${Date.now()}-${randomSuffix()}.json`);
|
|
125
|
+
await writeFile(
|
|
126
|
+
file,
|
|
127
|
+
JSON.stringify({ message, date: today() }),
|
|
128
|
+
{ mode: 0o600 }
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
await unlink(legacyPath).catch(() => {});
|
|
135
|
+
} catch {}
|
|
136
|
+
}
|