@audaxic/memory-claude 1.1.0 → 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 +3 -3
- package/package.json +1 -1
- package/scripts/capture.mjs +4 -4
- package/scripts/inject.mjs +4 -8
- package/scripts/parking.mjs +58 -38
package/README.md
CHANGED
|
@@ -31,10 +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
36
|
|
|
37
|
-
Saving is
|
|
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.
|
|
38
38
|
|
|
39
39
|
## API Key
|
|
40
40
|
|
package/package.json
CHANGED
package/scripts/capture.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
|
-
import {
|
|
4
|
+
import { parkMessage, drainStale, migrateLegacy } from "./parking.mjs";
|
|
5
5
|
|
|
6
6
|
const CONFIG_PATH = join(homedir(), ".config", "audaxic", "config.json");
|
|
7
7
|
const BUFFER_DIR =
|
|
@@ -53,10 +53,10 @@ async function main() {
|
|
|
53
53
|
process.exit(0);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
await migrateLegacy(
|
|
56
|
+
await migrateLegacy(LEGACY_BUFFER_PATH, PENDING_DIR);
|
|
57
57
|
|
|
58
|
-
await
|
|
59
|
-
await drainStale(apiKey, PENDING_DIR);
|
|
58
|
+
await parkMessage(PENDING_DIR, assistantMessage.trim());
|
|
59
|
+
await drainStale(apiKey, PENDING_DIR, { limit: 3, timeoutMs: 25000 });
|
|
60
60
|
|
|
61
61
|
process.exit(0);
|
|
62
62
|
} catch {
|
package/scripts/inject.mjs
CHANGED
|
@@ -2,7 +2,7 @@ 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 {
|
|
5
|
+
import { parkMessage, drainStale, migrateLegacy } from "./parking.mjs";
|
|
6
6
|
|
|
7
7
|
setDefaultResultOrder("ipv4first");
|
|
8
8
|
|
|
@@ -89,11 +89,6 @@ async function searchMemory(apiKey, query) {
|
|
|
89
89
|
return [];
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
async function saveAndDrain(apiKey, message) {
|
|
93
|
-
await saveMessage(apiKey, PENDING_DIR, message);
|
|
94
|
-
await drainStale(apiKey, PENDING_DIR);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
92
|
function outputJson(obj) {
|
|
98
93
|
process.stdout.write(JSON.stringify(obj));
|
|
99
94
|
}
|
|
@@ -114,10 +109,11 @@ async function main() {
|
|
|
114
109
|
return;
|
|
115
110
|
}
|
|
116
111
|
|
|
117
|
-
await migrateLegacy(
|
|
112
|
+
await migrateLegacy(LEGACY_BUFFER_PATH, PENDING_DIR);
|
|
113
|
+
await parkMessage(PENDING_DIR, prompt.trim());
|
|
118
114
|
|
|
119
115
|
const [, searchResult] = await Promise.allSettled([
|
|
120
|
-
|
|
116
|
+
drainStale(apiKey, PENDING_DIR, { limit: 1, timeoutMs: 15000 }),
|
|
121
117
|
searchMemory(apiKey, prompt.trim()),
|
|
122
118
|
]);
|
|
123
119
|
|
package/scripts/parking.mjs
CHANGED
|
@@ -10,9 +10,10 @@ import {
|
|
|
10
10
|
import { join } from "node:path";
|
|
11
11
|
|
|
12
12
|
const API_BASE = "https://api.memory.audaxic.com";
|
|
13
|
-
export const SEND_TIMEOUT_MS =
|
|
13
|
+
export const SEND_TIMEOUT_MS = 25000;
|
|
14
14
|
export const DRAIN_STALE_MS = 60000;
|
|
15
|
-
export const
|
|
15
|
+
export const CLAIM_STALE_MS = 300000;
|
|
16
|
+
export const DRAIN_LIMIT = 3;
|
|
16
17
|
|
|
17
18
|
function today() {
|
|
18
19
|
return new Date().toISOString().split("T")[0];
|
|
@@ -22,9 +23,9 @@ function randomSuffix() {
|
|
|
22
23
|
return Math.random().toString(36).slice(2, 10);
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
async function postAdd(apiKey, messages, date, timeoutMs = SEND_TIMEOUT_MS) {
|
|
26
27
|
const controller = new AbortController();
|
|
27
|
-
const timeout = setTimeout(() => controller.abort(),
|
|
28
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
28
29
|
|
|
29
30
|
try {
|
|
30
31
|
const response = await fetch(`${API_BASE}/add`, {
|
|
@@ -45,7 +46,7 @@ export async function postAdd(apiKey, messages, date) {
|
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
async function sendParked(apiKey, file) {
|
|
49
|
+
async function sendParked(apiKey, file, timeoutMs) {
|
|
49
50
|
let payload;
|
|
50
51
|
try {
|
|
51
52
|
payload = JSON.parse(await readFile(file, "utf-8"));
|
|
@@ -61,14 +62,14 @@ async function sendParked(apiKey, file) {
|
|
|
61
62
|
return false;
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
const ok = await postAdd(apiKey, [message], payload.date);
|
|
65
|
+
const ok = await postAdd(apiKey, [message], payload.date, timeoutMs);
|
|
65
66
|
if (ok) await unlink(file).catch(() => {});
|
|
66
67
|
return ok;
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
export async function
|
|
70
|
+
export async function parkMessage(pendingDir, message) {
|
|
70
71
|
const text = typeof message === "string" ? message.trim() : "";
|
|
71
|
-
if (!text) return
|
|
72
|
+
if (!text) return null;
|
|
72
73
|
|
|
73
74
|
const file = join(pendingDir, `${Date.now()}-${randomSuffix()}.json`);
|
|
74
75
|
try {
|
|
@@ -76,39 +77,61 @@ export async function saveMessage(apiKey, pendingDir, message) {
|
|
|
76
77
|
await writeFile(file, JSON.stringify({ message: text, date: today() }), {
|
|
77
78
|
mode: 0o600,
|
|
78
79
|
});
|
|
80
|
+
return file;
|
|
79
81
|
} catch {
|
|
80
|
-
return
|
|
82
|
+
return null;
|
|
81
83
|
}
|
|
82
|
-
|
|
83
|
-
return sendParked(apiKey, file);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
async function healClaimOrphans(pendingDir) {
|
|
87
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;
|
|
88
106
|
|
|
89
|
-
|
|
107
|
+
await healClaimOrphans(pendingDir);
|
|
108
|
+
|
|
109
|
+
const entries = await readdir(pendingDir).catch(() => []);
|
|
110
|
+
const stale = [];
|
|
90
111
|
for (const entry of entries) {
|
|
91
|
-
if (
|
|
112
|
+
if (stale.length >= limit) break;
|
|
92
113
|
if (!entry.endsWith(".json")) continue;
|
|
93
|
-
|
|
94
114
|
const file = join(pendingDir, entry);
|
|
95
115
|
const info = await stat(file).catch(() => null);
|
|
96
116
|
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++;
|
|
117
|
+
stale.push(file);
|
|
108
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
|
+
);
|
|
109
132
|
}
|
|
110
133
|
|
|
111
|
-
export async function migrateLegacy(
|
|
134
|
+
export async function migrateLegacy(legacyPath, pendingDir) {
|
|
112
135
|
try {
|
|
113
136
|
const raw = await readFile(legacyPath, "utf-8");
|
|
114
137
|
const parsed = JSON.parse(raw);
|
|
@@ -117,17 +140,14 @@ export async function migrateLegacy(apiKey, legacyPath, pendingDir) {
|
|
|
117
140
|
: [];
|
|
118
141
|
|
|
119
142
|
if (messages.length > 0) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
{ mode: 0o600 }
|
|
129
|
-
);
|
|
130
|
-
}
|
|
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
|
+
);
|
|
131
151
|
}
|
|
132
152
|
}
|
|
133
153
|
|