@themoltnet/pi-extension 0.26.2 → 0.26.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/dist/index.d.ts +14 -0
- package/dist/index.js +34 -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
|
@@ -8716,11 +8716,20 @@ function shouldRunResumeCommand(entry, ctx) {
|
|
|
8716
8716
|
* only exists in the main worktree, not in git worktrees).
|
|
8717
8717
|
*/
|
|
8718
8718
|
function findMainWorktree() {
|
|
8719
|
-
|
|
8720
|
-
|
|
8721
|
-
"
|
|
8722
|
-
|
|
8723
|
-
|
|
8719
|
+
let output;
|
|
8720
|
+
try {
|
|
8721
|
+
output = execFileSync("git", [
|
|
8722
|
+
"worktree",
|
|
8723
|
+
"list",
|
|
8724
|
+
"--porcelain"
|
|
8725
|
+
], {
|
|
8726
|
+
encoding: "utf8",
|
|
8727
|
+
stdio: "pipe"
|
|
8728
|
+
});
|
|
8729
|
+
} catch (err) {
|
|
8730
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
8731
|
+
throw new Error(`Git worktree discovery requires a git repository: ${message}`);
|
|
8732
|
+
}
|
|
8724
8733
|
for (const block of output.split("\n\n")) {
|
|
8725
8734
|
const lines = block.split("\n");
|
|
8726
8735
|
const wt = lines.find((l) => l.startsWith("worktree "));
|
|
@@ -8728,6 +8737,10 @@ function findMainWorktree() {
|
|
|
8728
8737
|
}
|
|
8729
8738
|
throw new Error("Could not find main git worktree");
|
|
8730
8739
|
}
|
|
8740
|
+
function resolveVmAgentDir(config) {
|
|
8741
|
+
const rootDir = config.agentRootDir ?? findMainWorktree();
|
|
8742
|
+
return path.join(rootDir, ".moltnet", config.agentName);
|
|
8743
|
+
}
|
|
8731
8744
|
function loadCredentials(agentDir) {
|
|
8732
8745
|
const moltnetJson = readFileSync(path.join(agentDir, "moltnet.json"), "utf8");
|
|
8733
8746
|
const agentEnvRaw = readFileSync(path.join(agentDir, "env"), "utf8");
|
|
@@ -8826,8 +8839,7 @@ function nonErrorMessage(err) {
|
|
|
8826
8839
|
*/
|
|
8827
8840
|
async function resumeVm(config) {
|
|
8828
8841
|
throwIfAborted(config.signal, "VM resume");
|
|
8829
|
-
const
|
|
8830
|
-
const agentDir = path.join(mainRepo, ".moltnet", config.agentName);
|
|
8842
|
+
const agentDir = resolveVmAgentDir(config);
|
|
8831
8843
|
const guestWorkspace = path.resolve(config.mountPath);
|
|
8832
8844
|
if (!existsSync(agentDir)) throw new Error(`Agent directory not found: ${agentDir}. Run: moltnet register --name ${config.agentName}`);
|
|
8833
8845
|
const creds = loadCredentials(agentDir);
|
|
@@ -23442,7 +23454,7 @@ function prepareTaskWorkspace(task, requestedMountPath, executionPlan) {
|
|
|
23442
23454
|
cleanup: () => {}
|
|
23443
23455
|
};
|
|
23444
23456
|
if (workspaceMode === "scratch_mount") {
|
|
23445
|
-
const scratchDir = resolveTaskScratchPath(
|
|
23457
|
+
const scratchDir = resolveTaskScratchPath(requestedMountPath, executionPlan?.workspaceId ?? `task-${task.id}`);
|
|
23446
23458
|
const keepWorkspace = executionPlan?.workspaceScope === "session" && executionPlan.sessionKey !== null;
|
|
23447
23459
|
if (keepWorkspace) mkdirSync(scratchDir, { recursive: true });
|
|
23448
23460
|
else {
|
|
@@ -23474,7 +23486,7 @@ function prepareTaskWorkspace(task, requestedMountPath, executionPlan) {
|
|
|
23474
23486
|
branch: null,
|
|
23475
23487
|
cleanup: () => {}
|
|
23476
23488
|
};
|
|
23477
|
-
const mainRepo =
|
|
23489
|
+
const mainRepo = findMainWorktreeForDedicatedTask();
|
|
23478
23490
|
const worktreeDir = resolveTaskWorktreePath(mainRepo, executionPlan?.workspaceId ?? `task-${task.id}`);
|
|
23479
23491
|
const relMount = relative(mainRepo, requestedMountPath);
|
|
23480
23492
|
const cwdPath = relMount === "" || relMount.startsWith("..") ? worktreeDir : join(worktreeDir, relMount);
|
|
@@ -23505,8 +23517,8 @@ function prepareTaskWorkspace(task, requestedMountPath, executionPlan) {
|
|
|
23505
23517
|
function resolveTaskWorktreePath(mainRepo, workspaceId) {
|
|
23506
23518
|
return join(mainRepo, ".worktrees", workspaceId);
|
|
23507
23519
|
}
|
|
23508
|
-
function resolveTaskScratchPath(
|
|
23509
|
-
return join(
|
|
23520
|
+
function resolveTaskScratchPath(stateRoot, workspaceId) {
|
|
23521
|
+
return join(stateRoot, ".moltnet", "d", "task-workspaces", workspaceId);
|
|
23510
23522
|
}
|
|
23511
23523
|
function ensureReusableTaskWorktree(mainRepo, worktreeDir, branch, baseRefOverride = null) {
|
|
23512
23524
|
if (isRegisteredWorktree(mainRepo, worktreeDir)) return;
|
|
@@ -23577,6 +23589,14 @@ function gitRefExists(mainRepo, ref) {
|
|
|
23577
23589
|
return false;
|
|
23578
23590
|
}
|
|
23579
23591
|
}
|
|
23592
|
+
function findMainWorktreeForDedicatedTask() {
|
|
23593
|
+
try {
|
|
23594
|
+
return findMainWorktree();
|
|
23595
|
+
} catch (err) {
|
|
23596
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
23597
|
+
throw new Error(`Dedicated worktree tasks require a git repository: ${message}`);
|
|
23598
|
+
}
|
|
23599
|
+
}
|
|
23580
23600
|
function copyDirectoryContents(sourceDir, targetDir) {
|
|
23581
23601
|
if (!existsSync(sourceDir)) throw new Error(`Workspace seed source is missing: ${sourceDir}`);
|
|
23582
23602
|
if (existsSync(join(sourceDir, ".git"))) initializeScratchGitRepo(sourceDir, targetDir);
|
|
@@ -23698,6 +23718,7 @@ async function executePiTask(claimedTask, reporter, opts) {
|
|
|
23698
23718
|
const attemptN = claimedTask.attemptN;
|
|
23699
23719
|
const startTime = Date.now();
|
|
23700
23720
|
const requestedMountPath = opts.mountPath ?? process.cwd();
|
|
23721
|
+
const agentRootDir = opts.agentRootDir ?? requestedMountPath;
|
|
23701
23722
|
const executionPlan = await opts.makeExecutionPlan?.(claimedTask) ?? null;
|
|
23702
23723
|
let workspace = null;
|
|
23703
23724
|
let mountPath = requestedMountPath;
|
|
@@ -23809,6 +23830,7 @@ async function executePiTask(claimedTask, reporter, opts) {
|
|
|
23809
23830
|
managed = await resumeVm({
|
|
23810
23831
|
checkpointPath,
|
|
23811
23832
|
agentName: opts.agentName,
|
|
23833
|
+
agentRootDir,
|
|
23812
23834
|
mountPath,
|
|
23813
23835
|
workspaceMode: workspace.mode,
|
|
23814
23836
|
extraAllowedHosts: opts.extraAllowedHosts,
|
|
@@ -23826,8 +23848,7 @@ async function executePiTask(claimedTask, reporter, opts) {
|
|
|
23826
23848
|
}
|
|
23827
23849
|
const diaryId = task.diaryId ?? "";
|
|
23828
23850
|
const taskTeamId = task.teamId ?? "";
|
|
23829
|
-
|
|
23830
|
-
activateAgentEnv(managed.credentials.agentEnv, mainRepo);
|
|
23851
|
+
activateAgentEnv(managed.credentials.agentEnv, agentRootDir);
|
|
23831
23852
|
const activeWorkspace = workspace;
|
|
23832
23853
|
if (!activeWorkspace) throw new Error("task workspace not prepared");
|
|
23833
23854
|
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.3",
|
|
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/
|
|
40
|
-
"@themoltnet/
|
|
39
|
+
"@themoltnet/agent-runtime": "0.28.0",
|
|
40
|
+
"@themoltnet/sdk": "0.109.0"
|
|
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"
|