agentcache 0.4.2 → 0.5.0-beta.2
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 +282 -151
- package/dist/{chunk-T4COG3XD.js → chunk-R5I6WWSD.js} +31 -14
- package/dist/chunk-RXGW4Q3G.js +109 -0
- package/dist/chunk-XRJ6QW6N.js +92 -0
- package/dist/chunk-YKG6CDGT.js +1818 -0
- package/dist/chunk-YY7QXBG5.js +6610 -0
- package/dist/cli.js +2535 -292
- package/dist/device-id-RV7RO5RB.js +7 -0
- package/dist/ide-detector-ETGAVVXO.js +8 -0
- package/dist/mcp.d.ts +734 -2
- package/dist/mcp.js +1126 -446
- package/dist/{paths-5LZRKNYY.js → paths-NTZ2357O.js} +3 -2
- package/dist/postinstall.js +1 -65
- package/dist/setup-7JJPW3VG.js +48 -0
- package/docs/compatibility.md +152 -0
- package/docs/demo-script.md +121 -0
- package/docs/launch-copy.md +125 -0
- package/docs/privacy.md +173 -0
- package/docs/troubleshooting.md +209 -0
- package/package.json +32 -14
- package/dist/3-canonicalizer-HIN2F7SZ.js +0 -11
- package/dist/chunk-5UO7NJPQ.js +0 -71
- package/dist/chunk-CUBZRYS5.js +0 -580
- package/dist/chunk-GGAATZKM.js +0 -120
- package/dist/chunk-JUDLOBOC.js +0 -77
- package/dist/chunk-KFQGP6VL.js +0 -33
- package/dist/chunk-PSASDZQE.js +0 -490
- package/dist/chunk-SLRKWMSE.js +0 -202
- package/dist/chunk-T7BJPANN.js +0 -45
- package/dist/chunk-WTXSZBQE.js +0 -388
- package/dist/compile-all-PTWTZVP5.js +0 -495
- package/dist/ide-detector-5TRCR4F5.js +0 -7
- package/dist/pre-tool-use-A4AJHZOJ.js +0 -30
- package/dist/session-start-DGMGEAJU.js +0 -78
- package/dist/setup-CVG35TUZ.js +0 -51
- package/dist/sqlite-NM2BVHUY.js +0 -7
- package/dist/stop-WGGRX6TQ.js +0 -38
- package/dist/transcript-JWSGSDSF.js +0 -24
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getDataDir
|
|
3
|
+
} from "./chunk-R5I6WWSD.js";
|
|
4
|
+
|
|
5
|
+
// src/utils/device-id.ts
|
|
6
|
+
import { randomBytes as nodeRandomBytes } from "crypto";
|
|
7
|
+
import {
|
|
8
|
+
chmodSync,
|
|
9
|
+
closeSync,
|
|
10
|
+
constants,
|
|
11
|
+
existsSync,
|
|
12
|
+
fsyncSync,
|
|
13
|
+
linkSync,
|
|
14
|
+
lstatSync,
|
|
15
|
+
mkdirSync,
|
|
16
|
+
openSync,
|
|
17
|
+
readFileSync,
|
|
18
|
+
unlinkSync,
|
|
19
|
+
writeFileSync
|
|
20
|
+
} from "fs";
|
|
21
|
+
import { join } from "path";
|
|
22
|
+
var DEVICE_ID_FILE = "device-id";
|
|
23
|
+
var DEVICE_ID_PATTERN = /^dev_[A-Za-z0-9_-]{32}$/;
|
|
24
|
+
function loadOrCreateDeviceId(options = {}) {
|
|
25
|
+
const dataDir = options.dataDir ?? getDataDir();
|
|
26
|
+
const devicePath = join(dataDir, DEVICE_ID_FILE);
|
|
27
|
+
mkdirSync(dataDir, { recursive: true, mode: 448 });
|
|
28
|
+
const directoryStat = lstatSync(dataDir);
|
|
29
|
+
if (directoryStat.isSymbolicLink()) {
|
|
30
|
+
throw new Error("AgentCache data directory must not be a symbolic link");
|
|
31
|
+
}
|
|
32
|
+
if (!directoryStat.isDirectory()) {
|
|
33
|
+
throw new Error("AgentCache data directory must be a directory");
|
|
34
|
+
}
|
|
35
|
+
chmodSync(dataDir, 448);
|
|
36
|
+
if (existsSync(devicePath)) return readStoredDeviceId(devicePath);
|
|
37
|
+
const random = options.randomBytes ?? (() => nodeRandomBytes(24));
|
|
38
|
+
const deviceId = `dev_${random().toString("base64url")}`;
|
|
39
|
+
if (!DEVICE_ID_PATTERN.test(deviceId)) {
|
|
40
|
+
throw new Error("Generated AgentCache device identity is malformed");
|
|
41
|
+
}
|
|
42
|
+
const temporaryPath = join(
|
|
43
|
+
dataDir,
|
|
44
|
+
`.device-id.${process.pid}.${nodeRandomBytes(8).toString("hex")}.tmp`
|
|
45
|
+
);
|
|
46
|
+
let descriptor;
|
|
47
|
+
try {
|
|
48
|
+
descriptor = openSync(
|
|
49
|
+
temporaryPath,
|
|
50
|
+
constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY,
|
|
51
|
+
384
|
|
52
|
+
);
|
|
53
|
+
writeFileSync(descriptor, `${deviceId}
|
|
54
|
+
`, "utf8");
|
|
55
|
+
fsyncSync(descriptor);
|
|
56
|
+
closeSync(descriptor);
|
|
57
|
+
descriptor = void 0;
|
|
58
|
+
try {
|
|
59
|
+
linkSync(temporaryPath, devicePath);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (!isAlreadyExists(error)) throw error;
|
|
62
|
+
}
|
|
63
|
+
} finally {
|
|
64
|
+
if (descriptor !== void 0) closeSync(descriptor);
|
|
65
|
+
try {
|
|
66
|
+
unlinkSync(temporaryPath);
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return readStoredDeviceId(devicePath);
|
|
71
|
+
}
|
|
72
|
+
function readStoredDeviceId(devicePath) {
|
|
73
|
+
const stat = lstatSync(devicePath);
|
|
74
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 256) {
|
|
75
|
+
throw new Error("Stored AgentCache device identity is malformed");
|
|
76
|
+
}
|
|
77
|
+
chmodSync(devicePath, 384);
|
|
78
|
+
const value = readFileSync(devicePath, "utf8").trim();
|
|
79
|
+
if (!DEVICE_ID_PATTERN.test(value)) {
|
|
80
|
+
throw new Error("Stored AgentCache device identity is malformed");
|
|
81
|
+
}
|
|
82
|
+
return value;
|
|
83
|
+
}
|
|
84
|
+
function isAlreadyExists(error) {
|
|
85
|
+
return Boolean(
|
|
86
|
+
error && typeof error === "object" && "code" in error && error.code === "EEXIST"
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export {
|
|
91
|
+
loadOrCreateDeviceId
|
|
92
|
+
};
|