larkin 0.5.1 → 0.5.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/CHANGELOG.md +8 -0
- package/dist/dashboard/dashboard-config-controller.mjs +2 -3
- package/dist/feishu/host-shell.cjs +47 -14
- package/dist/feishu/host-shell.mjs +47 -14
- package/dist/runtime/pi-compaction-recovery.cjs +46 -27
- package/dist/runtime/pi-compaction-recovery.mjs +45 -26
- package/dist/runtime/pi-model-catalog.cjs +3 -39
- package/dist/runtime/pi-model-catalog.mjs +3 -6
- package/dist/runtime/pi-subagent-injection.mjs +42 -14
- package/dist/runtime/provider-error-classifier.cjs +14 -0
- package/dist/runtime/provider-error-classifier.mjs +13 -0
- package/dist/runtime/runtime-adapters.mjs +69 -56
- package/dist/runtime/runtime-host.cjs +46 -26
- package/dist/runtime/runtime-host.mjs +46 -26
- package/dist/runtime/runtime-readiness.cjs +2 -0
- package/dist/runtime/runtime-readiness.mjs +2 -0
- package/package.json +1 -1
- package/dist/runtime/pi-artifact-provenance.mjs +0 -139
|
@@ -237,6 +237,8 @@ function executableVersion(executable, env, commandArgs = []) {
|
|
|
237
237
|
/** Resolve and handshake through each runtime's structured native control protocol. */
|
|
238
238
|
async function probeNativeRuntimeReadiness(options) {
|
|
239
239
|
const env = { ...process.env, ...options.env };
|
|
240
|
+
if (options.runtime === "pi")
|
|
241
|
+
delete env.PI_CODING_AGENT_DIR;
|
|
240
242
|
const command = selectedCommand(options);
|
|
241
243
|
const executable = resolveRuntimeExecutable(command, env);
|
|
242
244
|
if (!executable) {
|
|
@@ -184,6 +184,8 @@ function executableVersion(executable, env, commandArgs = []) {
|
|
|
184
184
|
/** Resolve and handshake through each runtime's structured native control protocol. */
|
|
185
185
|
export async function probeNativeRuntimeReadiness(options) {
|
|
186
186
|
const env = { ...process.env, ...options.env };
|
|
187
|
+
if (options.runtime === "pi")
|
|
188
|
+
delete env.PI_CODING_AGENT_DIR;
|
|
187
189
|
const command = selectedCommand(options);
|
|
188
190
|
const executable = resolveRuntimeExecutable(command, env);
|
|
189
191
|
if (!executable) {
|
package/package.json
CHANGED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import crypto from "node:crypto";
|
|
2
|
-
import fs from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { exactMode } from "../platform/secure-metadata.mjs";
|
|
5
|
-
export const PI_RUNTIME_ARTIFACT_MANIFEST = ".larkin-pi-owned-artifacts.json";
|
|
6
|
-
export const PI_RUNTIME_ARTIFACT_NAMES = ["models-store.json", "npm"];
|
|
7
|
-
const MAX_FILE_BYTES = 256 * 1024 * 1024;
|
|
8
|
-
const MAX_ENTRIES = 4096;
|
|
9
|
-
function digest(value) {
|
|
10
|
-
return crypto.createHash("sha256").update(value).digest("hex");
|
|
11
|
-
}
|
|
12
|
-
function assertSafeEntry(file, label) {
|
|
13
|
-
const stat = fs.lstatSync(file);
|
|
14
|
-
if (stat.isSymbolicLink())
|
|
15
|
-
throw new Error(`${label} must not be a symlink`);
|
|
16
|
-
if (typeof process.getuid === "function" && stat.uid !== process.getuid())
|
|
17
|
-
throw new Error(`${label} owner is unsafe`);
|
|
18
|
-
return stat;
|
|
19
|
-
}
|
|
20
|
-
function identity(file, label) {
|
|
21
|
-
const stat = assertSafeEntry(file, label);
|
|
22
|
-
const mode = stat.mode & 0o777;
|
|
23
|
-
if (stat.isFile()) {
|
|
24
|
-
if (stat.size > MAX_FILE_BYTES)
|
|
25
|
-
throw new Error(`${label} is too large`);
|
|
26
|
-
const bytes = fs.readFileSync(file);
|
|
27
|
-
return { kind: "file", mode, device: String(stat.dev), inode: String(stat.ino), bytes: bytes.length, digest: digest(bytes) };
|
|
28
|
-
}
|
|
29
|
-
if (!stat.isDirectory())
|
|
30
|
-
throw new Error(`${label} has an unsupported type`);
|
|
31
|
-
const entries = fs.readdirSync(file).sort();
|
|
32
|
-
if (entries.length > MAX_ENTRIES)
|
|
33
|
-
throw new Error(`${label} has too many entries`);
|
|
34
|
-
const children = entries.map((name) => {
|
|
35
|
-
if (name === "." || name === ".." || name.includes("/"))
|
|
36
|
-
throw new Error(`${label} contains an unsafe entry`);
|
|
37
|
-
const child = identity(path.join(file, name), `${label} child`);
|
|
38
|
-
return [name, child.kind, child.mode, child.device, child.inode, child.bytes, child.digest];
|
|
39
|
-
});
|
|
40
|
-
return {
|
|
41
|
-
kind: "directory", mode, device: String(stat.dev), inode: String(stat.ino),
|
|
42
|
-
bytes: children.reduce((sum, child) => sum + Number(child[5]), 0), digest: digest(JSON.stringify(children)),
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
function sameIdentity(actual, expected) {
|
|
46
|
-
return actual.kind === expected.kind && actual.mode === expected.mode
|
|
47
|
-
&& actual.device === expected.device && actual.inode === expected.inode
|
|
48
|
-
&& actual.bytes === expected.bytes && actual.digest === expected.digest;
|
|
49
|
-
}
|
|
50
|
-
function readManifest(file) {
|
|
51
|
-
try {
|
|
52
|
-
const stat = assertSafeEntry(file, "Pi artifact provenance manifest");
|
|
53
|
-
if (!stat.isFile() || !exactMode(stat, 0o600) || stat.size > 1024 * 1024)
|
|
54
|
-
throw new Error("Pi artifact provenance manifest is unsafe");
|
|
55
|
-
const value = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
56
|
-
if (value?.version !== 1 || (value.owner !== "larkin-pi" && value.owner !== "larkin-builtin-pi") || !value.directory || !value.artifacts)
|
|
57
|
-
throw new Error("Pi artifact provenance manifest is invalid");
|
|
58
|
-
return value;
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
if (error.code === "ENOENT")
|
|
62
|
-
return null;
|
|
63
|
-
throw error;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
function writeManifest(file, value) {
|
|
67
|
-
const temp = `${file}.tmp-${process.pid}`;
|
|
68
|
-
const fd = fs.openSync(temp, "wx", 0o600);
|
|
69
|
-
try {
|
|
70
|
-
fs.writeFileSync(fd, `${JSON.stringify(value, null, 2)}\n`);
|
|
71
|
-
fs.fsyncSync(fd);
|
|
72
|
-
}
|
|
73
|
-
finally {
|
|
74
|
-
fs.closeSync(fd);
|
|
75
|
-
}
|
|
76
|
-
fs.renameSync(temp, file);
|
|
77
|
-
}
|
|
78
|
-
/** Record only allowed entries that were absent at the runtime spawn boundary. */
|
|
79
|
-
export function recordPiRuntimeArtifactProvenance(targetDir, beforeEntries, boundaryAt = Date.now()) {
|
|
80
|
-
const target = assertSafeEntry(targetDir, "Pi provider target");
|
|
81
|
-
if (!target.isDirectory() || !exactMode(target, 0o700))
|
|
82
|
-
throw new Error("Pi provider target is unsafe");
|
|
83
|
-
const manifestFile = path.join(targetDir, PI_RUNTIME_ARTIFACT_MANIFEST);
|
|
84
|
-
const existing = readManifest(manifestFile);
|
|
85
|
-
const manifest = existing ?? {
|
|
86
|
-
version: 1, owner: "larkin-pi", directory: { device: String(target.dev), inode: String(target.ino) },
|
|
87
|
-
recordedAt: new Date(boundaryAt).toISOString(), artifacts: {},
|
|
88
|
-
};
|
|
89
|
-
if (manifest.directory.device !== String(target.dev) || manifest.directory.inode !== String(target.ino))
|
|
90
|
-
throw new Error("Pi artifact provenance target identity changed");
|
|
91
|
-
let changed = false;
|
|
92
|
-
for (const [name, expected] of Object.entries(manifest.artifacts)) {
|
|
93
|
-
if (!PI_RUNTIME_ARTIFACT_NAMES.includes(name) || name.includes("/") || !expected)
|
|
94
|
-
throw new Error("Pi artifact provenance entry is invalid");
|
|
95
|
-
const actual = identity(path.join(targetDir, name), `Pi artifact ${name}`);
|
|
96
|
-
const sameOwner = actual.kind === expected.kind && actual.mode === expected.mode
|
|
97
|
-
&& actual.device === expected.device && actual.inode === expected.inode;
|
|
98
|
-
if (!sameOwner)
|
|
99
|
-
throw new Error(`Pi artifact ${name} provenance identity changed`);
|
|
100
|
-
if (!sameIdentity(actual, expected)) {
|
|
101
|
-
manifest.artifacts[name] = actual;
|
|
102
|
-
changed = true;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
for (const name of PI_RUNTIME_ARTIFACT_NAMES) {
|
|
106
|
-
if (beforeEntries.has(name) || manifest.artifacts[name])
|
|
107
|
-
continue;
|
|
108
|
-
const file = path.join(targetDir, name);
|
|
109
|
-
if (!fs.existsSync(file))
|
|
110
|
-
continue;
|
|
111
|
-
const actual = identity(file, `Pi artifact ${name}`);
|
|
112
|
-
const stat = fs.lstatSync(file);
|
|
113
|
-
if (stat.birthtimeMs + 1 < boundaryAt && stat.mtimeMs + 1 < boundaryAt)
|
|
114
|
-
throw new Error(`Pi artifact ${name} predates runtime provenance boundary`);
|
|
115
|
-
manifest.artifacts[name] = actual;
|
|
116
|
-
changed = true;
|
|
117
|
-
}
|
|
118
|
-
if (changed)
|
|
119
|
-
writeManifest(manifestFile, manifest);
|
|
120
|
-
}
|
|
121
|
-
/** Return the names that are both explicitly attested and unchanged. */
|
|
122
|
-
export function attestedPiRuntimeArtifactNames(targetDir) {
|
|
123
|
-
const target = assertSafeEntry(targetDir, "Pi provider target");
|
|
124
|
-
if (!target.isDirectory())
|
|
125
|
-
throw new Error("Pi provider target is unsafe");
|
|
126
|
-
const manifest = readManifest(path.join(targetDir, PI_RUNTIME_ARTIFACT_MANIFEST));
|
|
127
|
-
if (!manifest || manifest.directory.device !== String(target.dev) || manifest.directory.inode !== String(target.ino))
|
|
128
|
-
return new Set();
|
|
129
|
-
const names = new Set();
|
|
130
|
-
for (const [name, expected] of Object.entries(manifest.artifacts)) {
|
|
131
|
-
if (!PI_RUNTIME_ARTIFACT_NAMES.includes(name) || !expected)
|
|
132
|
-
continue;
|
|
133
|
-
const actual = identity(path.join(targetDir, name), `Pi artifact ${name}`);
|
|
134
|
-
if (!sameIdentity(actual, expected))
|
|
135
|
-
throw new Error(`Pi artifact ${name} provenance changed`);
|
|
136
|
-
names.add(name);
|
|
137
|
-
}
|
|
138
|
-
return names;
|
|
139
|
-
}
|