@audaxic/memory-claude 1.0.5 → 1.1.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/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 +14 -23
- package/scripts/parking.mjs +156 -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`: parks your prompt to disk (no save wait) and injects context via `additionalContext` (a passive enhancement — injection may be deprioritized by Claude Code, which is why the skill + MCP path exists). Drains one stale parked message alongside the search.
|
|
35
|
+
- `Stop` → `capture.mjs`: parks the assistant's response, then drains up to 3 stale parked messages (25s timeout each, within the hook's 30s budget).
|
|
36
|
+
|
|
37
|
+
Saving is park-only and crash-safe: each message is written to its own parking file under `${CLAUDE_PLUGIN_DATA}/pending/` and delivered by drain cycles; a file is deleted only after `POST /add` confirms receipt. Failed sends stay parked and retry on subsequent hooks (stale files >60s, atomic rename claims, abandoned claims healed after 5 minutes). 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 { parkMessage, 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(LEGACY_BUFFER_PATH, PENDING_DIR);
|
|
94
57
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
await writeBuffer(success ? [] : buffer);
|
|
98
|
-
} else {
|
|
99
|
-
await writeBuffer(buffer);
|
|
100
|
-
}
|
|
58
|
+
await parkMessage(PENDING_DIR, assistantMessage.trim());
|
|
59
|
+
await drainStale(apiKey, PENDING_DIR, { limit: 3, timeoutMs: 25000 });
|
|
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 { parkMessage, 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);
|
|
@@ -124,11 +109,17 @@ async function main() {
|
|
|
124
109
|
return;
|
|
125
110
|
}
|
|
126
111
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
112
|
+
await migrateLegacy(LEGACY_BUFFER_PATH, PENDING_DIR);
|
|
113
|
+
await parkMessage(PENDING_DIR, prompt.trim());
|
|
114
|
+
|
|
115
|
+
const [, searchResult] = await Promise.allSettled([
|
|
116
|
+
drainStale(apiKey, PENDING_DIR, { limit: 1, timeoutMs: 15000 }),
|
|
117
|
+
searchMemory(apiKey, prompt.trim()),
|
|
118
|
+
]);
|
|
119
|
+
|
|
120
|
+
const results =
|
|
121
|
+
searchResult.status === "fulfilled" ? searchResult.value : [];
|
|
130
122
|
|
|
131
|
-
const results = await searchMemory(apiKey, prompt.trim());
|
|
132
123
|
if (!results.length) {
|
|
133
124
|
outputJson({});
|
|
134
125
|
return;
|
|
@@ -0,0 +1,156 @@
|
|
|
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 = 25000;
|
|
14
|
+
export const DRAIN_STALE_MS = 60000;
|
|
15
|
+
export const CLAIM_STALE_MS = 300000;
|
|
16
|
+
export const DRAIN_LIMIT = 3;
|
|
17
|
+
|
|
18
|
+
function today() {
|
|
19
|
+
return new Date().toISOString().split("T")[0];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function randomSuffix() {
|
|
23
|
+
return Math.random().toString(36).slice(2, 10);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function postAdd(apiKey, messages, date, timeoutMs = SEND_TIMEOUT_MS) {
|
|
27
|
+
const controller = new AbortController();
|
|
28
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const response = await fetch(`${API_BASE}/add`, {
|
|
32
|
+
method: "POST",
|
|
33
|
+
headers: {
|
|
34
|
+
"Content-Type": "application/json",
|
|
35
|
+
Authorization: `Bearer ${apiKey}`,
|
|
36
|
+
},
|
|
37
|
+
body: JSON.stringify({ messages, timestamp: date || today() }),
|
|
38
|
+
signal: controller.signal,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return response.ok;
|
|
42
|
+
} catch {
|
|
43
|
+
return false;
|
|
44
|
+
} finally {
|
|
45
|
+
clearTimeout(timeout);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function sendParked(apiKey, file, timeoutMs) {
|
|
50
|
+
let payload;
|
|
51
|
+
try {
|
|
52
|
+
payload = JSON.parse(await readFile(file, "utf-8"));
|
|
53
|
+
} catch {
|
|
54
|
+
await unlink(file).catch(() => {});
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const message =
|
|
59
|
+
typeof payload?.message === "string" ? payload.message.trim() : "";
|
|
60
|
+
if (!message) {
|
|
61
|
+
await unlink(file).catch(() => {});
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const ok = await postAdd(apiKey, [message], payload.date, timeoutMs);
|
|
66
|
+
if (ok) await unlink(file).catch(() => {});
|
|
67
|
+
return ok;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function parkMessage(pendingDir, message) {
|
|
71
|
+
const text = typeof message === "string" ? message.trim() : "";
|
|
72
|
+
if (!text) return null;
|
|
73
|
+
|
|
74
|
+
const file = join(pendingDir, `${Date.now()}-${randomSuffix()}.json`);
|
|
75
|
+
try {
|
|
76
|
+
await mkdir(pendingDir, { recursive: true });
|
|
77
|
+
await writeFile(file, JSON.stringify({ message: text, date: today() }), {
|
|
78
|
+
mode: 0o600,
|
|
79
|
+
});
|
|
80
|
+
return file;
|
|
81
|
+
} catch {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function healClaimOrphans(pendingDir) {
|
|
87
|
+
const entries = await readdir(pendingDir).catch(() => []);
|
|
88
|
+
for (const entry of entries) {
|
|
89
|
+
const idx = entry.indexOf(".json.claim-");
|
|
90
|
+
if (idx === -1) continue;
|
|
91
|
+
const file = join(pendingDir, entry);
|
|
92
|
+
const info = await stat(file).catch(() => null);
|
|
93
|
+
if (!info || Date.now() - info.mtimeMs < CLAIM_STALE_MS) continue;
|
|
94
|
+
const base = join(pendingDir, entry.slice(0, idx + 5));
|
|
95
|
+
await rename(file, base).catch(() => {});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function drainStale(
|
|
100
|
+
apiKey,
|
|
101
|
+
pendingDir,
|
|
102
|
+
options = {}
|
|
103
|
+
) {
|
|
104
|
+
const limit = options.limit ?? DRAIN_LIMIT;
|
|
105
|
+
const timeoutMs = options.timeoutMs ?? SEND_TIMEOUT_MS;
|
|
106
|
+
|
|
107
|
+
await healClaimOrphans(pendingDir);
|
|
108
|
+
|
|
109
|
+
const entries = await readdir(pendingDir).catch(() => []);
|
|
110
|
+
const stale = [];
|
|
111
|
+
for (const entry of entries) {
|
|
112
|
+
if (stale.length >= limit) break;
|
|
113
|
+
if (!entry.endsWith(".json")) continue;
|
|
114
|
+
const file = join(pendingDir, entry);
|
|
115
|
+
const info = await stat(file).catch(() => null);
|
|
116
|
+
if (!info || Date.now() - info.mtimeMs < DRAIN_STALE_MS) continue;
|
|
117
|
+
stale.push(file);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
await Promise.all(
|
|
121
|
+
stale.map(async (file) => {
|
|
122
|
+
const claim = `${file}.claim-${randomSuffix()}`;
|
|
123
|
+
try {
|
|
124
|
+
await rename(file, claim);
|
|
125
|
+
} catch {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const ok = await sendParked(apiKey, claim, timeoutMs);
|
|
129
|
+
if (!ok) await rename(claim, file).catch(() => {});
|
|
130
|
+
})
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export async function migrateLegacy(legacyPath, pendingDir) {
|
|
135
|
+
try {
|
|
136
|
+
const raw = await readFile(legacyPath, "utf-8");
|
|
137
|
+
const parsed = JSON.parse(raw);
|
|
138
|
+
const messages = Array.isArray(parsed)
|
|
139
|
+
? parsed.filter((m) => typeof m === "string" && m.trim())
|
|
140
|
+
: [];
|
|
141
|
+
|
|
142
|
+
if (messages.length > 0) {
|
|
143
|
+
await mkdir(pendingDir, { recursive: true });
|
|
144
|
+
for (const message of messages) {
|
|
145
|
+
const file = join(pendingDir, `${Date.now()}-${randomSuffix()}.json`);
|
|
146
|
+
await writeFile(
|
|
147
|
+
file,
|
|
148
|
+
JSON.stringify({ message, date: today() }),
|
|
149
|
+
{ mode: 0o600 }
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
await unlink(legacyPath).catch(() => {});
|
|
155
|
+
} catch {}
|
|
156
|
+
}
|