pi-better-server 0.7.0 → 0.7.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/package.json +1 -1
- package/src/codex/return.ts +3 -2
- package/src/detach/extension.ts +20 -3
- package/src/event-log.ts +40 -12
- package/src/hosted-session.ts +11 -5
- package/src/remote-client/packages.ts +1 -4
- package/src/runtime/domain/background-service/shared-harness-settings.domain.mjs +2 -3
- package/src/runtime/domain/background-service/shared-harness-settings.ts +2 -5
- package/src/runtime/domain/background-service/shared-ssh-core/index.domain.mjs +1 -1
- package/src/runtime/domain/background-service/shared-ssh-core/index.ts +1 -1
- package/src/runtime/domain/catalog/catalog-preferences.mjs +1 -3
- package/src/runtime/domain/sandbox-policy/package.json +1 -1
- package/src/runtime/domain/sandbox-policy/shared-harness-settings.domain.mjs +2 -3
- package/src/runtime/domain/sandbox-policy/shared-harness-settings.ts +2 -5
- package/src/runtime/domain/shared-harness-settings.mjs +2 -3
- package/src/runtime/domain/subagents/catalog-preferences.domain.mjs +1 -3
- package/src/runtime/domain/subagents/catalog-preferences.ts +1 -5
- package/src/runtime/domain/subagents/config.ts +1 -1
- package/src/runtime/domain/subagents/extensions.mjs +1 -0
- package/src/runtime/domain/subagents/finalization.domain.mjs +34 -30
- package/src/runtime/domain/subagents/finalization.ts +30 -28
- package/src/runtime/domain/subagents/git-workspace.domain.mjs +51 -6
- package/src/runtime/domain/subagents/git-workspace.ts +48 -6
- package/src/runtime/domain/subagents/index.domain.mjs +58 -27
- package/src/runtime/domain/subagents/index.ts +61 -26
- package/src/runtime/domain/subagents/isolated-workspace.domain.mjs +7 -14
- package/src/runtime/domain/subagents/isolated-workspace.ts +6 -12
- package/src/runtime/domain/subagents/package.json +1 -1
- package/src/runtime/domain/subagents/registry.domain.mjs +7 -7
- package/src/runtime/domain/subagents/registry.ts +8 -8
- package/src/runtime/domain/subagents/shared-harness-settings.domain.mjs +2 -3
- package/src/runtime/domain/subagents/shared-harness-settings.ts +2 -5
- package/src/runtime/domain/subagents/workspace-prepare-worker.mjs +12 -0
- package/src/shared-ssh-core/index.ts +1 -1
- package/src/version.ts +1 -1
|
@@ -3,7 +3,7 @@ import { randomUUID } from "node:crypto";
|
|
|
3
3
|
import { execFileSync } from "node:child_process";
|
|
4
4
|
import { closeSync, existsSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync, } from "node:fs";
|
|
5
5
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
6
|
-
import { inspectGitWorkspace, syncGitRemotes } from "./git-workspace.domain.mjs";
|
|
6
|
+
import { inspectGitWorkspace, isIgnoredGitSubdirectory, syncGitRemotes } from "./git-workspace.domain.mjs";
|
|
7
7
|
import { restoreTree, snapshotTree, verifyTree } from "./workspace-files.domain.mjs";
|
|
8
8
|
import { durableSubagentRoot } from "./session-store.domain.mjs";
|
|
9
9
|
import { taskWorkspaceDir } from "./registry.domain.mjs";
|
|
@@ -63,18 +63,8 @@ export function workspaceChoice(source, owner, mode, tools, exclude) {
|
|
|
63
63
|
throw error;
|
|
64
64
|
}
|
|
65
65
|
const subdir = relative(info.repoRoot, realpathSync(source));
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (subdir) {
|
|
69
|
-
try {
|
|
70
|
-
git(info.repoRoot, ["check-ignore", "--quiet", "--", subdir]);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
if (error.status !== 1)
|
|
75
|
-
throw error;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
66
|
+
if (isIgnoredGitSubdirectory(info.repoRoot, subdir))
|
|
67
|
+
return;
|
|
78
68
|
let base;
|
|
79
69
|
try {
|
|
80
70
|
base = value(source, ["rev-parse", "--verify", "HEAD"]);
|
|
@@ -152,7 +142,6 @@ const withoutGit = new Set([".git"]);
|
|
|
152
142
|
const worktreePointers = new Set(["commondir", "gitdir"]);
|
|
153
143
|
const sharedGitEntries = new Set(["config", "objects", "packed-refs", "refs", "logs", "info", "shallow", "hooks"]);
|
|
154
144
|
const pendingOperation = [
|
|
155
|
-
"index.lock",
|
|
156
145
|
"rebase-merge",
|
|
157
146
|
"rebase-apply",
|
|
158
147
|
"MERGE_HEAD",
|
|
@@ -306,6 +295,10 @@ function checkpoint(w, attempt) {
|
|
|
306
295
|
const { root, record, store } = paths(w);
|
|
307
296
|
const info = inspectOwned(w);
|
|
308
297
|
const linked = w.mode === "worktree";
|
|
298
|
+
const indexLock = join(info.gitDir, "index.lock");
|
|
299
|
+
if (existsSync(indexLock)) {
|
|
300
|
+
throw new Error(`Git index lock blocks workspace recovery at ${indexLock}. Original checkout retained at ${root}.`);
|
|
301
|
+
}
|
|
309
302
|
if (pendingOperation.some((name) => existsSync(join(info.gitDir, name))) ||
|
|
310
303
|
existsSync(join(info.commonGitDir, "objects/info/alternates")) ||
|
|
311
304
|
(existsSync(join(info.commonGitDir, "worktrees")) && !linked)) {
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
writeFileSync,
|
|
16
16
|
} from "node:fs";
|
|
17
17
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
18
|
-
import { inspectGitWorkspace, syncGitRemotes } from "./git-workspace.ts";
|
|
18
|
+
import { inspectGitWorkspace, isIgnoredGitSubdirectory, syncGitRemotes } from "./git-workspace.ts";
|
|
19
19
|
import { restoreTree, snapshotTree, verifyTree, type SavedEntry } from "./workspace-files.ts";
|
|
20
20
|
import { durableSubagentRoot } from "./session-store.ts";
|
|
21
21
|
import { taskWorkspaceDir } from "./registry.ts";
|
|
@@ -93,16 +93,7 @@ export function workspaceChoice(
|
|
|
93
93
|
throw error;
|
|
94
94
|
}
|
|
95
95
|
const subdir = relative(info.repoRoot, realpathSync(source));
|
|
96
|
-
|
|
97
|
-
// build output) is not part of that checkout's selected Git base.
|
|
98
|
-
if (subdir) {
|
|
99
|
-
try {
|
|
100
|
-
git(info.repoRoot, ["check-ignore", "--quiet", "--", subdir]);
|
|
101
|
-
return;
|
|
102
|
-
} catch (error) {
|
|
103
|
-
if ((error as { status?: number }).status !== 1) throw error;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
96
|
+
if (isIgnoredGitSubdirectory(info.repoRoot, subdir)) return;
|
|
106
97
|
let base: string;
|
|
107
98
|
try {
|
|
108
99
|
base = value(source, ["rev-parse", "--verify", "HEAD"]);
|
|
@@ -188,7 +179,6 @@ const withoutGit = new Set([".git"]);
|
|
|
188
179
|
const worktreePointers = new Set(["commondir", "gitdir"]);
|
|
189
180
|
const sharedGitEntries = new Set(["config", "objects", "packed-refs", "refs", "logs", "info", "shallow", "hooks"]);
|
|
190
181
|
const pendingOperation = [
|
|
191
|
-
"index.lock",
|
|
192
182
|
"rebase-merge",
|
|
193
183
|
"rebase-apply",
|
|
194
184
|
"MERGE_HEAD",
|
|
@@ -355,6 +345,10 @@ function checkpoint(w: IsolatedWorkspace, attempt: string) {
|
|
|
355
345
|
const { root, record, store } = paths(w);
|
|
356
346
|
const info = inspectOwned(w);
|
|
357
347
|
const linked = w.mode === "worktree";
|
|
348
|
+
const indexLock = join(info.gitDir, "index.lock");
|
|
349
|
+
if (existsSync(indexLock)) {
|
|
350
|
+
throw new Error(`Git index lock blocks workspace recovery at ${indexLock}. Original checkout retained at ${root}.`);
|
|
351
|
+
}
|
|
358
352
|
if (
|
|
359
353
|
pendingOperation.some((name) => existsSync(join(info.gitDir, name))) ||
|
|
360
354
|
existsSync(join(info.commonGitDir, "objects/info/alternates")) ||
|
|
@@ -788,7 +788,8 @@ function takeToken(lockPath, payload, deadline, id) {
|
|
|
788
788
|
* decides who may recover or release it. A live pid — even one paused well
|
|
789
789
|
* past two seconds — is not stolen. Release renames the lock aside and deletes
|
|
790
790
|
* it only when the moved bytes are still ours, so a newer owner's lock stays.
|
|
791
|
-
* The lock is per run
|
|
791
|
+
* The lock is per run. Metadata transitions that depend on the current record
|
|
792
|
+
* use a patch so that the read and preconditions are repeated after lock loss.
|
|
792
793
|
*/
|
|
793
794
|
function withRunMetaLock(id, body) {
|
|
794
795
|
const directory = runDir(id);
|
|
@@ -1008,13 +1009,14 @@ export function writeMeta(meta, options = {}) {
|
|
|
1008
1009
|
written = true;
|
|
1009
1010
|
});
|
|
1010
1011
|
if (options.patch && !written)
|
|
1011
|
-
return;
|
|
1012
|
+
return undefined;
|
|
1012
1013
|
for (const listener of metaChangedListeners) {
|
|
1013
1014
|
try {
|
|
1014
1015
|
listener(meta);
|
|
1015
1016
|
}
|
|
1016
1017
|
catch { /* best effort */ }
|
|
1017
1018
|
}
|
|
1019
|
+
return written ? meta : undefined;
|
|
1018
1020
|
}
|
|
1019
1021
|
export function onMetaChanged(listener) {
|
|
1020
1022
|
metaChangedListeners.add(listener);
|
|
@@ -1569,11 +1571,9 @@ export function dismissRun(id, at = Date.now()) {
|
|
|
1569
1571
|
const meta = readMeta(id);
|
|
1570
1572
|
if (!meta)
|
|
1571
1573
|
return undefined;
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
}
|
|
1576
|
-
return meta;
|
|
1574
|
+
return writeMeta(meta, {
|
|
1575
|
+
patch: current => current.dismissedAt === undefined ? { dismissedAt: at } : undefined,
|
|
1576
|
+
}) ?? readMeta(id);
|
|
1577
1577
|
}
|
|
1578
1578
|
/**
|
|
1579
1579
|
* Visible navigator runs: current-parent runs that are not dismissed. This is
|
|
@@ -1092,7 +1092,8 @@ function takeToken(lockPath: string, payload: string, deadline: number, id: stri
|
|
|
1092
1092
|
* decides who may recover or release it. A live pid — even one paused well
|
|
1093
1093
|
* past two seconds — is not stolen. Release renames the lock aside and deletes
|
|
1094
1094
|
* it only when the moved bytes are still ours, so a newer owner's lock stays.
|
|
1095
|
-
* The lock is per run
|
|
1095
|
+
* The lock is per run. Metadata transitions that depend on the current record
|
|
1096
|
+
* use a patch so that the read and preconditions are repeated after lock loss.
|
|
1096
1097
|
*/
|
|
1097
1098
|
function withRunMetaLock(id: string, body: (owns: () => boolean) => void): void {
|
|
1098
1099
|
const directory = runDir(id);
|
|
@@ -1270,7 +1271,7 @@ export function writeMeta(meta: RunMeta, options: {
|
|
|
1270
1271
|
ifAbsent?: boolean;
|
|
1271
1272
|
/** Build a field update from current metadata under the existing run lock. */
|
|
1272
1273
|
patch?: (current: Readonly<RunMeta>) => Partial<RunMeta> | undefined;
|
|
1273
|
-
} = {}):
|
|
1274
|
+
} = {}): RunMeta | undefined {
|
|
1274
1275
|
if (options.patch && !readMeta(meta.id)) return;
|
|
1275
1276
|
mkdirSync(runDir(meta.id), { recursive: true });
|
|
1276
1277
|
let written = false;
|
|
@@ -1303,10 +1304,11 @@ export function writeMeta(meta: RunMeta, options: {
|
|
|
1303
1304
|
owns();
|
|
1304
1305
|
written = true;
|
|
1305
1306
|
});
|
|
1306
|
-
if (options.patch && !written) return;
|
|
1307
|
+
if (options.patch && !written) return undefined;
|
|
1307
1308
|
for (const listener of metaChangedListeners) {
|
|
1308
1309
|
try { listener(meta); } catch { /* best effort */ }
|
|
1309
1310
|
}
|
|
1311
|
+
return written ? meta : undefined;
|
|
1310
1312
|
}
|
|
1311
1313
|
|
|
1312
1314
|
export function onMetaChanged(listener: (meta?: RunMeta) => void): () => void {
|
|
@@ -1893,11 +1895,9 @@ export function isDismissed(meta: Pick<RunMeta, "dismissedAt">): boolean {
|
|
|
1893
1895
|
export function dismissRun(id: string, at: number = Date.now()): RunMeta | undefined {
|
|
1894
1896
|
const meta = readMeta(id);
|
|
1895
1897
|
if (!meta) return undefined;
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
}
|
|
1900
|
-
return meta;
|
|
1898
|
+
return writeMeta(meta, {
|
|
1899
|
+
patch: current => current.dismissedAt === undefined ? { dismissedAt: at } : undefined,
|
|
1900
|
+
}) ?? readMeta(id);
|
|
1901
1901
|
}
|
|
1902
1902
|
|
|
1903
1903
|
/**
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
// Generated from packages/harness-settings/index.ts. Do not edit directly.
|
|
3
3
|
import { existsSync, lstatSync, realpathSync, readFileSync, mkdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
|
-
import { createRequire } from "node:module";
|
|
6
5
|
import { join } from "node:path";
|
|
7
6
|
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
8
|
-
//
|
|
9
|
-
|
|
7
|
+
// A static import lets the compiled Pi loader resolve dependencies of the settings lock.
|
|
8
|
+
import lockfile from "proper-lockfile";
|
|
10
9
|
const NAMESPACE = "piBetterHarness";
|
|
11
10
|
export function harnessSettingsPath(seams = {}) {
|
|
12
11
|
return join((seams.agentDir ?? getAgentDir)(), "settings.json");
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
// Generated from packages/harness-settings/index.ts. Do not edit directly.
|
|
2
2
|
import { existsSync, lstatSync, realpathSync, readFileSync, mkdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
|
-
import { createRequire } from "node:module";
|
|
5
4
|
import { join } from "node:path";
|
|
6
5
|
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
6
|
+
// A static import lets the compiled Pi loader resolve dependencies of the settings lock.
|
|
7
|
+
import lockfile from "proper-lockfile";
|
|
7
8
|
|
|
8
|
-
// Match Pi's settings lock without depending on a private SDK import.
|
|
9
|
-
const lockfile = createRequire(import.meta.url)("proper-lockfile") as {
|
|
10
|
-
lockSync(path: string, options: { realpath: boolean }): () => void;
|
|
11
|
-
};
|
|
12
9
|
const NAMESPACE = "piBetterHarness";
|
|
13
10
|
export interface HarnessSettingsSeams { agentDir?: () => string }
|
|
14
11
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-subagents/workspace-prepare-worker.mjs. Do not edit directly.
|
|
2
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
3
|
+
import { resolveSubagentWorkspace } from "./git-workspace.domain.mjs";
|
|
4
|
+
import { createIsolatedWorkspace } from "./isolated-workspace.domain.mjs";
|
|
5
|
+
const { options, isolated } = workerData;
|
|
6
|
+
if (isolated) {
|
|
7
|
+
const cwd = createIsolatedWorkspace(isolated, true);
|
|
8
|
+
parentPort.postMessage({ cwd, requestedSandboxDir: options.sandboxEnabled ? cwd : undefined });
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
parentPort.postMessage(resolveSubagentWorkspace(options));
|
|
12
|
+
}
|
|
@@ -328,7 +328,7 @@ export function wrapRemoteBashCommand(input: RemoteBashCommandInput): string {
|
|
|
328
328
|
|
|
329
329
|
export function defaultSshControlPathRoot(): string {
|
|
330
330
|
const agentDirectory = process.env.PI_CODING_AGENT_DIR ?? join(homedir(), ".pi", "agent");
|
|
331
|
-
const root =
|
|
331
|
+
const root = resolve(agentDirectory, "ssh-control");
|
|
332
332
|
// A long agent directory would push the socket past the unix path limit; fall back to a short per-user root.
|
|
333
333
|
if (Buffer.byteLength(join(root, MUX_CONTROL_PATH_NAME_TEMPLATE)) <= MAX_SSH_CONTROL_PATH_BYTES) return root;
|
|
334
334
|
return join("/tmp", `pi-ssh-${process.getuid?.() ?? "user"}`);
|
package/src/version.ts
CHANGED