@themoltnet/pi-extension 0.26.2 → 0.26.4
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/index.d.ts +14 -0
- package/dist/index.js +100 -13
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -244,6 +244,13 @@ export declare function executePiTask(claimedTask: ClaimedTask, reporter: TaskRe
|
|
|
244
244
|
export declare interface ExecutePiTaskOptions {
|
|
245
245
|
/** MoltNet agent whose credentials the VM boots with. */
|
|
246
246
|
agentName: string;
|
|
247
|
+
/**
|
|
248
|
+
* Host root that owns `.moltnet/<agentName>/`.
|
|
249
|
+
*
|
|
250
|
+
* Defaults to `mountPath`, but callers that mount scratch workspaces should
|
|
251
|
+
* pass the stable sandbox root.
|
|
252
|
+
*/
|
|
253
|
+
agentRootDir?: string;
|
|
247
254
|
/** Host cwd that the VM mounts into the guest (defaults to `process.cwd()`). */
|
|
248
255
|
mountPath?: string;
|
|
249
256
|
/** LLM selection. */
|
|
@@ -907,6 +914,13 @@ export declare interface VmConfig {
|
|
|
907
914
|
checkpointPath: string;
|
|
908
915
|
/** MoltNet agent name (used to resolve credentials). */
|
|
909
916
|
agentName: string;
|
|
917
|
+
/**
|
|
918
|
+
* Host root that owns `.moltnet/<agentName>/`.
|
|
919
|
+
*
|
|
920
|
+
* Defaults to the main git worktree for backwards compatibility. Daemon
|
|
921
|
+
* callers pass the sandbox root so non-git scratch/shared tasks can boot.
|
|
922
|
+
*/
|
|
923
|
+
agentRootDir?: string;
|
|
910
924
|
/** Host directory to mount into the VM. */
|
|
911
925
|
mountPath: string;
|
|
912
926
|
/** Effective workspace shape selected by the caller. */
|
package/dist/index.js
CHANGED
|
@@ -1257,6 +1257,32 @@ var initiateTransfer = (options) => (options.client ?? client).post({
|
|
|
1257
1257
|
}
|
|
1258
1258
|
});
|
|
1259
1259
|
/**
|
|
1260
|
+
* Delete multiple diary entries. Signed, unauthorized, and missing entries are skipped.
|
|
1261
|
+
*/
|
|
1262
|
+
var batchDeleteDiaryEntries = (options) => (options.client ?? client).delete({
|
|
1263
|
+
security: [
|
|
1264
|
+
{
|
|
1265
|
+
scheme: "bearer",
|
|
1266
|
+
type: "http"
|
|
1267
|
+
},
|
|
1268
|
+
{
|
|
1269
|
+
name: "X-Moltnet-Session-Token",
|
|
1270
|
+
type: "apiKey"
|
|
1271
|
+
},
|
|
1272
|
+
{
|
|
1273
|
+
in: "cookie",
|
|
1274
|
+
name: "ory_kratos_session",
|
|
1275
|
+
type: "apiKey"
|
|
1276
|
+
}
|
|
1277
|
+
],
|
|
1278
|
+
url: "/entries",
|
|
1279
|
+
...options,
|
|
1280
|
+
headers: {
|
|
1281
|
+
"Content-Type": "application/json",
|
|
1282
|
+
...options.headers
|
|
1283
|
+
}
|
|
1284
|
+
});
|
|
1285
|
+
/**
|
|
1260
1286
|
* Delete a diary entry.
|
|
1261
1287
|
*/
|
|
1262
1288
|
var deleteDiaryEntryById = (options) => (options.client ?? client).delete({
|
|
@@ -1866,6 +1892,32 @@ var findLatestRuntimeSlotForAttempt = (options) => (options.client ?? client).ge
|
|
|
1866
1892
|
...options
|
|
1867
1893
|
});
|
|
1868
1894
|
/**
|
|
1895
|
+
* Delete terminal tasks in bulk. Safe mode skips live, unauthorized, missing, and protected tasks.
|
|
1896
|
+
*/
|
|
1897
|
+
var batchDeleteTasks = (options) => (options.client ?? client).delete({
|
|
1898
|
+
security: [
|
|
1899
|
+
{
|
|
1900
|
+
scheme: "bearer",
|
|
1901
|
+
type: "http"
|
|
1902
|
+
},
|
|
1903
|
+
{
|
|
1904
|
+
name: "X-Moltnet-Session-Token",
|
|
1905
|
+
type: "apiKey"
|
|
1906
|
+
},
|
|
1907
|
+
{
|
|
1908
|
+
in: "cookie",
|
|
1909
|
+
name: "ory_kratos_session",
|
|
1910
|
+
type: "apiKey"
|
|
1911
|
+
}
|
|
1912
|
+
],
|
|
1913
|
+
url: "/tasks",
|
|
1914
|
+
...options,
|
|
1915
|
+
headers: {
|
|
1916
|
+
"Content-Type": "application/json",
|
|
1917
|
+
...options.headers
|
|
1918
|
+
}
|
|
1919
|
+
});
|
|
1920
|
+
/**
|
|
1869
1921
|
* List tasks for a team with optional filters.
|
|
1870
1922
|
*/
|
|
1871
1923
|
var listTasks = (options) => (options.client ?? client).get({
|
|
@@ -4661,6 +4713,13 @@ function createEntriesNamespace(context) {
|
|
|
4661
4713
|
path: { entryId }
|
|
4662
4714
|
}));
|
|
4663
4715
|
},
|
|
4716
|
+
async deleteMany(body) {
|
|
4717
|
+
return unwrapResult(await batchDeleteDiaryEntries({
|
|
4718
|
+
client,
|
|
4719
|
+
auth,
|
|
4720
|
+
body
|
|
4721
|
+
}));
|
|
4722
|
+
},
|
|
4664
4723
|
async search(body) {
|
|
4665
4724
|
return unwrapResult(await searchDiary({
|
|
4666
4725
|
client,
|
|
@@ -5140,6 +5199,13 @@ function createTasksNamespace(context) {
|
|
|
5140
5199
|
body
|
|
5141
5200
|
}));
|
|
5142
5201
|
},
|
|
5202
|
+
async deleteMany(body) {
|
|
5203
|
+
return unwrapResult(await batchDeleteTasks({
|
|
5204
|
+
client,
|
|
5205
|
+
auth,
|
|
5206
|
+
body
|
|
5207
|
+
}));
|
|
5208
|
+
},
|
|
5143
5209
|
async listAttempts(id) {
|
|
5144
5210
|
return unwrapResult(await listTaskAttempts({
|
|
5145
5211
|
client,
|
|
@@ -8716,11 +8782,20 @@ function shouldRunResumeCommand(entry, ctx) {
|
|
|
8716
8782
|
* only exists in the main worktree, not in git worktrees).
|
|
8717
8783
|
*/
|
|
8718
8784
|
function findMainWorktree() {
|
|
8719
|
-
|
|
8720
|
-
|
|
8721
|
-
"
|
|
8722
|
-
|
|
8723
|
-
|
|
8785
|
+
let output;
|
|
8786
|
+
try {
|
|
8787
|
+
output = execFileSync("git", [
|
|
8788
|
+
"worktree",
|
|
8789
|
+
"list",
|
|
8790
|
+
"--porcelain"
|
|
8791
|
+
], {
|
|
8792
|
+
encoding: "utf8",
|
|
8793
|
+
stdio: "pipe"
|
|
8794
|
+
});
|
|
8795
|
+
} catch (err) {
|
|
8796
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
8797
|
+
throw new Error(`Git worktree discovery requires a git repository: ${message}`);
|
|
8798
|
+
}
|
|
8724
8799
|
for (const block of output.split("\n\n")) {
|
|
8725
8800
|
const lines = block.split("\n");
|
|
8726
8801
|
const wt = lines.find((l) => l.startsWith("worktree "));
|
|
@@ -8728,6 +8803,10 @@ function findMainWorktree() {
|
|
|
8728
8803
|
}
|
|
8729
8804
|
throw new Error("Could not find main git worktree");
|
|
8730
8805
|
}
|
|
8806
|
+
function resolveVmAgentDir(config) {
|
|
8807
|
+
const rootDir = config.agentRootDir ?? findMainWorktree();
|
|
8808
|
+
return path.join(rootDir, ".moltnet", config.agentName);
|
|
8809
|
+
}
|
|
8731
8810
|
function loadCredentials(agentDir) {
|
|
8732
8811
|
const moltnetJson = readFileSync(path.join(agentDir, "moltnet.json"), "utf8");
|
|
8733
8812
|
const agentEnvRaw = readFileSync(path.join(agentDir, "env"), "utf8");
|
|
@@ -8826,8 +8905,7 @@ function nonErrorMessage(err) {
|
|
|
8826
8905
|
*/
|
|
8827
8906
|
async function resumeVm(config) {
|
|
8828
8907
|
throwIfAborted(config.signal, "VM resume");
|
|
8829
|
-
const
|
|
8830
|
-
const agentDir = path.join(mainRepo, ".moltnet", config.agentName);
|
|
8908
|
+
const agentDir = resolveVmAgentDir(config);
|
|
8831
8909
|
const guestWorkspace = path.resolve(config.mountPath);
|
|
8832
8910
|
if (!existsSync(agentDir)) throw new Error(`Agent directory not found: ${agentDir}. Run: moltnet register --name ${config.agentName}`);
|
|
8833
8911
|
const creds = loadCredentials(agentDir);
|
|
@@ -23442,7 +23520,7 @@ function prepareTaskWorkspace(task, requestedMountPath, executionPlan) {
|
|
|
23442
23520
|
cleanup: () => {}
|
|
23443
23521
|
};
|
|
23444
23522
|
if (workspaceMode === "scratch_mount") {
|
|
23445
|
-
const scratchDir = resolveTaskScratchPath(
|
|
23523
|
+
const scratchDir = resolveTaskScratchPath(requestedMountPath, executionPlan?.workspaceId ?? `task-${task.id}`);
|
|
23446
23524
|
const keepWorkspace = executionPlan?.workspaceScope === "session" && executionPlan.sessionKey !== null;
|
|
23447
23525
|
if (keepWorkspace) mkdirSync(scratchDir, { recursive: true });
|
|
23448
23526
|
else {
|
|
@@ -23474,7 +23552,7 @@ function prepareTaskWorkspace(task, requestedMountPath, executionPlan) {
|
|
|
23474
23552
|
branch: null,
|
|
23475
23553
|
cleanup: () => {}
|
|
23476
23554
|
};
|
|
23477
|
-
const mainRepo =
|
|
23555
|
+
const mainRepo = findMainWorktreeForDedicatedTask();
|
|
23478
23556
|
const worktreeDir = resolveTaskWorktreePath(mainRepo, executionPlan?.workspaceId ?? `task-${task.id}`);
|
|
23479
23557
|
const relMount = relative(mainRepo, requestedMountPath);
|
|
23480
23558
|
const cwdPath = relMount === "" || relMount.startsWith("..") ? worktreeDir : join(worktreeDir, relMount);
|
|
@@ -23505,8 +23583,8 @@ function prepareTaskWorkspace(task, requestedMountPath, executionPlan) {
|
|
|
23505
23583
|
function resolveTaskWorktreePath(mainRepo, workspaceId) {
|
|
23506
23584
|
return join(mainRepo, ".worktrees", workspaceId);
|
|
23507
23585
|
}
|
|
23508
|
-
function resolveTaskScratchPath(
|
|
23509
|
-
return join(
|
|
23586
|
+
function resolveTaskScratchPath(stateRoot, workspaceId) {
|
|
23587
|
+
return join(stateRoot, ".moltnet", "d", "task-workspaces", workspaceId);
|
|
23510
23588
|
}
|
|
23511
23589
|
function ensureReusableTaskWorktree(mainRepo, worktreeDir, branch, baseRefOverride = null) {
|
|
23512
23590
|
if (isRegisteredWorktree(mainRepo, worktreeDir)) return;
|
|
@@ -23577,6 +23655,14 @@ function gitRefExists(mainRepo, ref) {
|
|
|
23577
23655
|
return false;
|
|
23578
23656
|
}
|
|
23579
23657
|
}
|
|
23658
|
+
function findMainWorktreeForDedicatedTask() {
|
|
23659
|
+
try {
|
|
23660
|
+
return findMainWorktree();
|
|
23661
|
+
} catch (err) {
|
|
23662
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
23663
|
+
throw new Error(`Dedicated worktree tasks require a git repository: ${message}`);
|
|
23664
|
+
}
|
|
23665
|
+
}
|
|
23580
23666
|
function copyDirectoryContents(sourceDir, targetDir) {
|
|
23581
23667
|
if (!existsSync(sourceDir)) throw new Error(`Workspace seed source is missing: ${sourceDir}`);
|
|
23582
23668
|
if (existsSync(join(sourceDir, ".git"))) initializeScratchGitRepo(sourceDir, targetDir);
|
|
@@ -23698,6 +23784,7 @@ async function executePiTask(claimedTask, reporter, opts) {
|
|
|
23698
23784
|
const attemptN = claimedTask.attemptN;
|
|
23699
23785
|
const startTime = Date.now();
|
|
23700
23786
|
const requestedMountPath = opts.mountPath ?? process.cwd();
|
|
23787
|
+
const agentRootDir = opts.agentRootDir ?? requestedMountPath;
|
|
23701
23788
|
const executionPlan = await opts.makeExecutionPlan?.(claimedTask) ?? null;
|
|
23702
23789
|
let workspace = null;
|
|
23703
23790
|
let mountPath = requestedMountPath;
|
|
@@ -23809,6 +23896,7 @@ async function executePiTask(claimedTask, reporter, opts) {
|
|
|
23809
23896
|
managed = await resumeVm({
|
|
23810
23897
|
checkpointPath,
|
|
23811
23898
|
agentName: opts.agentName,
|
|
23899
|
+
agentRootDir,
|
|
23812
23900
|
mountPath,
|
|
23813
23901
|
workspaceMode: workspace.mode,
|
|
23814
23902
|
extraAllowedHosts: opts.extraAllowedHosts,
|
|
@@ -23826,8 +23914,7 @@ async function executePiTask(claimedTask, reporter, opts) {
|
|
|
23826
23914
|
}
|
|
23827
23915
|
const diaryId = task.diaryId ?? "";
|
|
23828
23916
|
const taskTeamId = task.teamId ?? "";
|
|
23829
|
-
|
|
23830
|
-
activateAgentEnv(managed.credentials.agentEnv, mainRepo);
|
|
23917
|
+
activateAgentEnv(managed.credentials.agentEnv, agentRootDir);
|
|
23831
23918
|
const activeWorkspace = workspace;
|
|
23832
23919
|
if (!activeWorkspace) throw new Error("task workspace not prepared");
|
|
23833
23920
|
await emit("info", {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@themoltnet/pi-extension",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "MoltNet pi extension — sandboxed tool execution in Gondolin VMs with MoltNet identity and persistent memory",
|
|
6
6
|
"keywords": [
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"@earendil-works/gondolin": "^0.9.1",
|
|
37
37
|
"@opentelemetry/api": "^1.9.0",
|
|
38
38
|
"typebox": "^1.2.8",
|
|
39
|
-
"@themoltnet/sdk": "0.
|
|
40
|
-
"@themoltnet/agent-runtime": "0.28.
|
|
39
|
+
"@themoltnet/sdk": "0.110.0",
|
|
40
|
+
"@themoltnet/agent-runtime": "0.28.1"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@earendil-works/pi-coding-agent": ">=0.74.0",
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
"vite": "^8.0.0",
|
|
62
62
|
"vite-plugin-dts": "^4.5.4",
|
|
63
63
|
"vitest": "^3.0.0",
|
|
64
|
-
"@moltnet/
|
|
65
|
-
"@moltnet/
|
|
64
|
+
"@moltnet/crypto-service": "0.1.0",
|
|
65
|
+
"@moltnet/tasks": "0.1.0"
|
|
66
66
|
},
|
|
67
67
|
"engines": {
|
|
68
68
|
"node": ">=22"
|