@audaxic/memory-claude 1.0.1 → 1.0.3
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/bin/install.js +4 -1
- package/hooks/hooks.json +1 -1
- package/package.json +1 -1
- package/scripts/inject.mjs +37 -6
package/bin/install.js
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
copyFile,
|
|
10
10
|
access,
|
|
11
11
|
readdir,
|
|
12
|
+
rm,
|
|
12
13
|
} from "node:fs/promises";
|
|
13
14
|
import { join, dirname } from "node:path";
|
|
14
15
|
import { homedir } from "node:os";
|
|
@@ -88,7 +89,9 @@ async function main() {
|
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
for (const dir of DIRS_TO_COPY) {
|
|
91
|
-
|
|
92
|
+
const destDir = join(PLUGIN_DEST, dir);
|
|
93
|
+
await rm(destDir, { recursive: true, force: true });
|
|
94
|
+
await copyDir(join(PACKAGE_ROOT, dir), destDir);
|
|
92
95
|
}
|
|
93
96
|
console.log("✓ Plugin files copied to ~/.claude/skills/audaxic-memory/");
|
|
94
97
|
|
package/hooks/hooks.json
CHANGED
package/package.json
CHANGED
package/scripts/inject.mjs
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
1
|
+
import { readFile, writeFile, mkdir, appendFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
|
+
import { setDefaultResultOrder } from "node:dns";
|
|
5
|
+
|
|
6
|
+
setDefaultResultOrder("ipv4first");
|
|
4
7
|
|
|
5
8
|
const API_BASE = "https://api.memory.audaxic.com";
|
|
6
9
|
const CONFIG_PATH = join(homedir(), ".config", "audaxic", "config.json");
|
|
7
10
|
const BUFFER_DIR =
|
|
8
11
|
process.env.CLAUDE_PLUGIN_DATA || join(homedir(), ".claude", "audaxic");
|
|
9
12
|
const BUFFER_PATH = join(BUFFER_DIR, "buffer.json");
|
|
13
|
+
const LOG_PATH = join(BUFFER_DIR, "hook.log");
|
|
14
|
+
const SEARCH_TIMEOUT_MS = 8000;
|
|
15
|
+
const SEARCH_ATTEMPTS = 2;
|
|
10
16
|
|
|
11
17
|
async function readStdin() {
|
|
12
18
|
const chunks = [];
|
|
@@ -16,6 +22,17 @@ async function readStdin() {
|
|
|
16
22
|
return JSON.parse(Buffer.concat(chunks).toString("utf-8"));
|
|
17
23
|
}
|
|
18
24
|
|
|
25
|
+
async function logFailure(message) {
|
|
26
|
+
try {
|
|
27
|
+
await mkdir(BUFFER_DIR, { recursive: true });
|
|
28
|
+
await appendFile(
|
|
29
|
+
LOG_PATH,
|
|
30
|
+
`${new Date().toISOString()} ${message}\n`,
|
|
31
|
+
"utf-8"
|
|
32
|
+
);
|
|
33
|
+
} catch {}
|
|
34
|
+
}
|
|
35
|
+
|
|
19
36
|
async function loadApiKey() {
|
|
20
37
|
const envKey = process.env.CLAUDE_PLUGIN_OPTION_API_TOKEN;
|
|
21
38
|
if (envKey && envKey.trim()) return envKey.trim();
|
|
@@ -47,9 +64,9 @@ async function writeBuffer(buffer) {
|
|
|
47
64
|
});
|
|
48
65
|
}
|
|
49
66
|
|
|
50
|
-
async function
|
|
67
|
+
async function searchOnce(apiKey, query) {
|
|
51
68
|
const controller = new AbortController();
|
|
52
|
-
const timeout = setTimeout(() => controller.abort(),
|
|
69
|
+
const timeout = setTimeout(() => controller.abort(), SEARCH_TIMEOUT_MS);
|
|
53
70
|
|
|
54
71
|
try {
|
|
55
72
|
const response = await fetch(`${API_BASE}/search`, {
|
|
@@ -62,17 +79,31 @@ async function searchMemory(apiKey, query) {
|
|
|
62
79
|
signal: controller.signal,
|
|
63
80
|
});
|
|
64
81
|
|
|
65
|
-
if (!response.ok)
|
|
82
|
+
if (!response.ok) {
|
|
83
|
+
await logFailure(`search http ${response.status} for: ${query.slice(0, 80)}`);
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
66
86
|
|
|
67
87
|
const data = await response.json();
|
|
68
88
|
return Array.isArray(data.results) ? data.results : [];
|
|
69
|
-
} catch {
|
|
70
|
-
|
|
89
|
+
} catch (error) {
|
|
90
|
+
await logFailure(
|
|
91
|
+
`search error ${error?.message || String(error)} for: ${query.slice(0, 80)}`
|
|
92
|
+
);
|
|
93
|
+
return null;
|
|
71
94
|
} finally {
|
|
72
95
|
clearTimeout(timeout);
|
|
73
96
|
}
|
|
74
97
|
}
|
|
75
98
|
|
|
99
|
+
async function searchMemory(apiKey, query) {
|
|
100
|
+
for (let attempt = 0; attempt < SEARCH_ATTEMPTS; attempt++) {
|
|
101
|
+
const results = await searchOnce(apiKey, query);
|
|
102
|
+
if (results !== null) return results;
|
|
103
|
+
}
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
|
|
76
107
|
function outputJson(obj) {
|
|
77
108
|
process.stdout.write(JSON.stringify(obj));
|
|
78
109
|
}
|