@cortexkit/pi-magic-context 0.45.0 → 0.46.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/dist/embedding-worker.js +4 -4
- package/dist/{index-j0mbc5vj.js → index-266qrgss.js} +59 -1
- package/dist/index-2p1e8706.js +30 -0
- package/dist/{index-k0yd1ph9.js → index-4vfrjwf6.js} +129 -166
- package/dist/{index-g0xfx1c2.js → index-phh7e055.js} +16 -1
- package/dist/{index-ttf0cqq8.js → index-r01b1b78.js} +25 -24
- package/dist/index-td885aah.js +576 -0
- package/dist/index-vf38qhee.js +150 -0
- package/dist/{index-2pbbk3en.js → index-wv28nczk.js} +55 -1
- package/dist/{index-vxjgsr9m.js → index-xvw8zptx.js} +3565 -3349
- package/dist/{index-2bw9k8nx.js → index-ykb8kkm3.js} +1310 -1021
- package/dist/index.js +3309 -1480
- package/dist/{message-time-backfill-g83dkh8m.js → message-time-backfill-4688z1k2.js} +2 -2
- package/dist/migration-worker.js +11 -6
- package/dist/{read-session-chunk-kmt7a6zj.js → read-session-chunk-tc6yn2pe.js} +5 -5
- package/dist/subagent-entry.js +10 -10
- package/package.json +4 -3
- package/dist/index-4d3cba70.js +0 -10
- package/dist/index-7s5yk3za.js +0 -16
- package/dist/index-e16q5sd7.js +0 -240
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// ../plugin/src/shared/storage-permissions.ts
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
3
|
+
import {
|
|
4
|
+
chmodSync,
|
|
5
|
+
closeSync,
|
|
6
|
+
createWriteStream,
|
|
7
|
+
lstatSync,
|
|
8
|
+
mkdirSync,
|
|
9
|
+
openSync,
|
|
10
|
+
readdirSync,
|
|
11
|
+
readlinkSync,
|
|
12
|
+
readSync,
|
|
13
|
+
renameSync,
|
|
14
|
+
rmSync,
|
|
15
|
+
symlinkSync,
|
|
16
|
+
writeFileSync,
|
|
17
|
+
writeSync
|
|
18
|
+
} from "node:fs";
|
|
19
|
+
import { open as openAsync, writeFile as writeFileAsync } from "node:fs/promises";
|
|
20
|
+
import { dirname, join } from "node:path";
|
|
21
|
+
var enforcePrivateStoragePermissions = true;
|
|
22
|
+
function setStoragePrivatePermissionEnforcement(enforce) {
|
|
23
|
+
enforcePrivateStoragePermissions = enforce;
|
|
24
|
+
}
|
|
25
|
+
function shouldEnforcePrivateStoragePermissions() {
|
|
26
|
+
return enforcePrivateStoragePermissions;
|
|
27
|
+
}
|
|
28
|
+
function ensureStorageDirectorySync(directory, forcePrivate = false, recursive = true) {
|
|
29
|
+
const privateMode = forcePrivate || shouldEnforcePrivateStoragePermissions();
|
|
30
|
+
mkdirSync(directory, {
|
|
31
|
+
recursive,
|
|
32
|
+
...privateMode ? { mode: 448 } : {}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function writeStorageFileSync(filePath, content, options = {}) {
|
|
36
|
+
const { forcePrivate = false, ...writeOptions } = options;
|
|
37
|
+
const privateMode = forcePrivate || shouldEnforcePrivateStoragePermissions();
|
|
38
|
+
writeFileSync(filePath, content, {
|
|
39
|
+
...writeOptions,
|
|
40
|
+
...privateMode ? { mode: 384 } : {}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function writeStorageFileAtomicSync(filePath, content, forcePrivate = false) {
|
|
44
|
+
ensureStorageDirectorySync(dirname(filePath), forcePrivate);
|
|
45
|
+
const tempPath = `${filePath}.${process.pid}.${randomBytes(6).toString("hex")}.tmp`;
|
|
46
|
+
try {
|
|
47
|
+
writeStorageFileSync(tempPath, content, { flag: "wx", forcePrivate });
|
|
48
|
+
renameSync(tempPath, filePath);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
rmSync(tempPath, { force: true });
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function copyStorageFileSync(sourcePath, destinationPath, forcePrivate = false) {
|
|
55
|
+
ensureStorageDirectorySync(dirname(destinationPath), forcePrivate);
|
|
56
|
+
const privateMode = forcePrivate || shouldEnforcePrivateStoragePermissions();
|
|
57
|
+
const sourceFd = openSync(sourcePath, "r");
|
|
58
|
+
let destinationFd;
|
|
59
|
+
try {
|
|
60
|
+
destinationFd = openSync(destinationPath, "wx", privateMode ? 384 : 438);
|
|
61
|
+
const buffer = Buffer.allocUnsafe(1024 * 1024);
|
|
62
|
+
for (;; ) {
|
|
63
|
+
const bytesRead = readSync(sourceFd, buffer, 0, buffer.length, null);
|
|
64
|
+
if (bytesRead === 0)
|
|
65
|
+
break;
|
|
66
|
+
let offset = 0;
|
|
67
|
+
while (offset < bytesRead) {
|
|
68
|
+
offset += writeSync(destinationFd, buffer, offset, bytesRead - offset);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
} catch (error) {
|
|
72
|
+
if (destinationFd !== undefined)
|
|
73
|
+
rmSync(destinationPath, { force: true });
|
|
74
|
+
throw error;
|
|
75
|
+
} finally {
|
|
76
|
+
closeSync(sourceFd);
|
|
77
|
+
if (destinationFd !== undefined)
|
|
78
|
+
closeSync(destinationFd);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function copyStorageTreeSync(sourcePath, destinationPath, forcePrivate = false) {
|
|
82
|
+
const stat = lstatSync(sourcePath);
|
|
83
|
+
if (stat.isSymbolicLink()) {
|
|
84
|
+
ensureStorageDirectorySync(dirname(destinationPath), forcePrivate);
|
|
85
|
+
symlinkSync(readlinkSync(sourcePath), destinationPath);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (!stat.isDirectory()) {
|
|
89
|
+
copyStorageFileSync(sourcePath, destinationPath, forcePrivate);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
ensureStorageDirectorySync(destinationPath, forcePrivate);
|
|
93
|
+
for (const entry of readdirSync(sourcePath)) {
|
|
94
|
+
copyStorageTreeSync(join(sourcePath, entry), join(destinationPath, entry), forcePrivate);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async function writeStorageFileAsync(filePath, content, forcePrivate = false) {
|
|
98
|
+
const privateMode = forcePrivate || shouldEnforcePrivateStoragePermissions();
|
|
99
|
+
ensureStorageDirectorySync(dirname(filePath), privateMode);
|
|
100
|
+
await writeFileAsync(filePath, content, privateMode ? { mode: 384 } : undefined);
|
|
101
|
+
}
|
|
102
|
+
async function writeStorageFileHandleAsync(handle, content) {
|
|
103
|
+
await handle.writeFile(content);
|
|
104
|
+
}
|
|
105
|
+
async function createStorageFileHandleAsync(filePath, flags, forcePrivate = false) {
|
|
106
|
+
const privateMode = forcePrivate || shouldEnforcePrivateStoragePermissions();
|
|
107
|
+
return openAsync(filePath, flags, privateMode ? 384 : undefined);
|
|
108
|
+
}
|
|
109
|
+
function tightenStorageTreeSync(root) {
|
|
110
|
+
if (!shouldEnforcePrivateStoragePermissions() || process.platform === "win32") {
|
|
111
|
+
return { tightened: 0, failures: 0 };
|
|
112
|
+
}
|
|
113
|
+
let tightened = 0;
|
|
114
|
+
let failures = 0;
|
|
115
|
+
const visit = (entryPath) => {
|
|
116
|
+
let stat;
|
|
117
|
+
try {
|
|
118
|
+
stat = lstatSync(entryPath);
|
|
119
|
+
} catch {
|
|
120
|
+
failures++;
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (stat.isSymbolicLink())
|
|
124
|
+
return;
|
|
125
|
+
const mode = stat.isDirectory() ? 448 : 384;
|
|
126
|
+
if ((stat.mode & 63) !== 0 || (stat.mode & 511) !== mode) {
|
|
127
|
+
try {
|
|
128
|
+
chmodSync(entryPath, mode);
|
|
129
|
+
tightened++;
|
|
130
|
+
} catch {
|
|
131
|
+
failures++;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (!stat.isDirectory())
|
|
135
|
+
return;
|
|
136
|
+
let entries;
|
|
137
|
+
try {
|
|
138
|
+
entries = readdirSync(entryPath);
|
|
139
|
+
} catch {
|
|
140
|
+
failures++;
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
for (const entry of entries)
|
|
144
|
+
visit(join(entryPath, entry));
|
|
145
|
+
};
|
|
146
|
+
visit(root);
|
|
147
|
+
return { tightened, failures };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export { setStoragePrivatePermissionEnforcement, shouldEnforcePrivateStoragePermissions, ensureStorageDirectorySync, writeStorageFileSync, writeStorageFileAtomicSync, copyStorageFileSync, copyStorageTreeSync, writeStorageFileAsync, writeStorageFileHandleAsync, createStorageFileHandleAsync, tightenStorageTreeSync };
|
|
@@ -168,6 +168,12 @@ function trackSqliteConnection(db, filename, options) {
|
|
|
168
168
|
...metadata,
|
|
169
169
|
reference: new WeakRef(db)
|
|
170
170
|
});
|
|
171
|
+
const prepare = db.prepare.bind(db);
|
|
172
|
+
Object.defineProperty(db, "prepare", {
|
|
173
|
+
configurable: true,
|
|
174
|
+
writable: true,
|
|
175
|
+
value: (sql) => ownPreparedStatement(db, prepare(sql))
|
|
176
|
+
});
|
|
171
177
|
return db;
|
|
172
178
|
}
|
|
173
179
|
var TrackedDatabase = new Proxy(DatabaseImpl, {
|
|
@@ -213,6 +219,54 @@ function pragmaNumber(db, name) {
|
|
|
213
219
|
return null;
|
|
214
220
|
}
|
|
215
221
|
}
|
|
222
|
+
var statementOwners = new WeakMap;
|
|
223
|
+
var FIRST_PRUNE_AT = 256;
|
|
224
|
+
function ownPreparedStatement(db, statement) {
|
|
225
|
+
const finalizable = statement;
|
|
226
|
+
if (typeof finalizable.finalize !== "function")
|
|
227
|
+
return statement;
|
|
228
|
+
let owner = statementOwners.get(db);
|
|
229
|
+
if (!owner) {
|
|
230
|
+
const references = new Set;
|
|
231
|
+
owner = { references, registered: new WeakSet, pruneAt: FIRST_PRUNE_AT };
|
|
232
|
+
statementOwners.set(db, owner);
|
|
233
|
+
const close = db.close.bind(db);
|
|
234
|
+
Object.defineProperty(db, "close", {
|
|
235
|
+
configurable: true,
|
|
236
|
+
writable: true,
|
|
237
|
+
value: (...args) => {
|
|
238
|
+
let failure;
|
|
239
|
+
for (const reference of references) {
|
|
240
|
+
try {
|
|
241
|
+
reference.deref()?.finalize();
|
|
242
|
+
} catch (error) {
|
|
243
|
+
failure ??= error;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
references.clear();
|
|
247
|
+
const result = close(...args);
|
|
248
|
+
if (failure)
|
|
249
|
+
throw failure;
|
|
250
|
+
return result;
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
if (!owner.registered.has(finalizable)) {
|
|
255
|
+
if (owner.references.size >= owner.pruneAt) {
|
|
256
|
+
for (const reference of owner.references) {
|
|
257
|
+
if (reference.deref() === undefined)
|
|
258
|
+
owner.references.delete(reference);
|
|
259
|
+
}
|
|
260
|
+
owner.pruneAt = Math.max(FIRST_PRUNE_AT, owner.references.size * 2);
|
|
261
|
+
}
|
|
262
|
+
owner.references.add(new WeakRef(finalizable));
|
|
263
|
+
owner.registered.add(finalizable);
|
|
264
|
+
}
|
|
265
|
+
return statement;
|
|
266
|
+
}
|
|
267
|
+
function prepareCachedStatement(db, sql) {
|
|
268
|
+
return ownPreparedStatement(db, db.prepare(sql));
|
|
269
|
+
}
|
|
216
270
|
var privilegeDepth = new WeakMap;
|
|
217
271
|
var transformPassScope = new AsyncLocalStorage;
|
|
218
272
|
var admissionScope = new AsyncLocalStorage;
|
|
@@ -407,4 +461,4 @@ function withPrivilegedWriter(db, operation) {
|
|
|
407
461
|
}
|
|
408
462
|
}
|
|
409
463
|
|
|
410
|
-
export { registerSlowWriteReporter, registerSqliteDiagnosticSink, detectSqliteRuntime, Database, withSqliteBackgroundWriter, withSqliteTransformPass, withoutSqliteTransformPass, isTransientSqliteError, withPrivilegedWriter };
|
|
464
|
+
export { registerSlowWriteReporter, registerSqliteDiagnosticSink, detectSqliteRuntime, Database, prepareCachedStatement, withSqliteBackgroundWriter, withSqliteTransformPass, withoutSqliteTransformPass, isTransientSqliteError, withPrivilegedWriter };
|