@floydous/pi-agent-kernel 0.4.0 → 0.4.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/AGENT_KERNEL_SYS_PROMPT.md +8 -4
- package/CHANGELOG.md +40 -87
- package/README.md +39 -74
- package/config.example.toml +1 -1
- package/docs/retrieval.md +2 -0
- package/package.json +7 -6
- package/src/config/agent_kernel_command.ts +29 -14
- package/src/config/kernel_config.ts +175 -30
- package/src/context/session_repair.ts +166 -85
- package/src/editing/patch.ts +28 -16
- package/src/editing/smart_anchor.ts +13 -29
- package/src/editing/syntax-verify.ts +35 -11
- package/src/index.ts +161 -141
- package/src/lsp/lsp_client.ts +101 -20
- package/src/lsp/lsp_formatter.ts +57 -22
- package/src/lsp/lsp_installer.ts +272 -487
- package/src/lsp/lsp_manager.ts +1 -1
- package/src/lsp/lsp_registry.ts +75 -46
- package/src/retrieval/search_bm25.ts +5 -2
- package/src/retrieval/search_cache.ts +69 -0
- package/src/retrieval/search_chunker.ts +12 -9
- package/src/retrieval/search_config.ts +20 -8
- package/src/retrieval/search_embedder.ts +8 -16
- package/src/retrieval/search_index.ts +552 -121
- package/src/safety/atomic_write.ts +59 -20
- package/src/safety/epistemic_guard.ts +440 -67
- package/src/safety/output_clamper.ts +316 -76
- package/src/tools/code_search_output.ts +59 -23
- package/src/tools/code_search_tool.ts +42 -46
- package/src/tools/context.ts +15 -1
- package/src/tools/edit_tool.ts +114 -36
- package/src/tools/lsp_tool.ts +5 -2
- package/src/tools/read_tool.ts +44 -3
|
@@ -1,26 +1,65 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { randomBytes } from "node:crypto";
|
|
2
4
|
import { kernelDebug } from "./kernel_debug";
|
|
3
5
|
|
|
6
|
+
function syncDirectory(directory: string): void {
|
|
7
|
+
if (process.platform === "win32") return;
|
|
8
|
+
try {
|
|
9
|
+
const fd = fs.openSync(directory, fs.constants.O_RDONLY);
|
|
10
|
+
try {
|
|
11
|
+
fs.fsyncSync(fd);
|
|
12
|
+
} finally {
|
|
13
|
+
fs.closeSync(fd);
|
|
14
|
+
}
|
|
15
|
+
} catch (error) {
|
|
16
|
+
// Directory fsync is not available on every filesystem; rename is still
|
|
17
|
+
// atomic, and the failure is intentionally non-fatal after the rename.
|
|
18
|
+
kernelDebug(error);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
4
22
|
/**
|
|
5
|
-
* Write a file
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* holds the old complete file or the new complete file, never a partial one.
|
|
23
|
+
* Write a file through an exclusive sibling temp file, preserving metadata
|
|
24
|
+
* where the platform exposes it. A plain writeFileSync can leave a truncated
|
|
25
|
+
* destination after a crash; fsync + rename prevents that partial state.
|
|
9
26
|
*/
|
|
10
|
-
export function writeFileSyncAtomic(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
export function writeFileSyncAtomic(filePath: string, data: string | Buffer): void {
|
|
28
|
+
const target = path.resolve(filePath);
|
|
29
|
+
let targetStat: fs.Stats | undefined;
|
|
30
|
+
try {
|
|
31
|
+
targetStat = fs.lstatSync(target);
|
|
32
|
+
if (targetStat.isSymbolicLink()) {
|
|
33
|
+
throw new Error("Refusing to atomically replace a symbolic-link target");
|
|
34
|
+
}
|
|
35
|
+
} catch (error: any) {
|
|
36
|
+
if (error?.code !== "ENOENT") throw error;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const mode = targetStat ? (targetStat.mode & 0o7777) : 0o600;
|
|
40
|
+
const temp = `${target}.${process.pid}.${Date.now()}.${randomBytes(6).toString("hex")}.tmp`;
|
|
41
|
+
let fd: number | undefined;
|
|
42
|
+
try {
|
|
43
|
+
fd = fs.openSync(temp, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL, mode);
|
|
44
|
+
fs.writeFileSync(fd, data);
|
|
45
|
+
fs.fsyncSync(fd);
|
|
46
|
+
fs.closeSync(fd);
|
|
47
|
+
fd = undefined;
|
|
48
|
+
|
|
49
|
+
if (targetStat && process.platform !== "win32") {
|
|
50
|
+
fs.chmodSync(temp, mode);
|
|
51
|
+
if (targetStat.uid !== process.getuid?.() || targetStat.gid !== process.getgid?.()) {
|
|
52
|
+
fs.chownSync(temp, targetStat.uid, targetStat.gid);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
fs.renameSync(temp, target);
|
|
57
|
+
syncDirectory(path.dirname(target));
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (fd !== undefined) {
|
|
60
|
+
try { fs.closeSync(fd); } catch (closeError) { kernelDebug(closeError); }
|
|
61
|
+
}
|
|
62
|
+
try { fs.unlinkSync(temp); } catch (cleanupError) { kernelDebug(cleanupError); }
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
26
65
|
}
|