pi-better-server 0.6.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 +4 -3
- package/scripts/measure-full-runtime/frontend.ts +10 -2
- package/scripts/measure-full-runtime.mjs +2 -0
- 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/background-tools.ts +54 -8
- package/src/runtime/background.ts +16 -4
- package/src/runtime/domain/background/process.mjs +49 -11
- package/src/runtime/domain/background/supervisor/store.mjs +3 -3
- package/src/runtime/domain/background/supervisor/supervisor.mjs +9 -3
- package/src/runtime/domain/background-service/index.domain.mjs +19 -0
- package/src/runtime/domain/background-service/index.ts +19 -0
- package/src/runtime/domain/background-service/managed-frontend.domain.mjs +87 -5
- package/src/runtime/domain/background-service/managed-frontend.ts +76 -5
- package/src/runtime/domain/background-service/navigator-provider.domain.mjs +5 -0
- package/src/runtime/domain/background-service/navigator-provider.ts +4 -0
- package/src/runtime/domain/background-service/observed-waits.domain.mjs +203 -31
- package/src/runtime/domain/background-service/observed-waits.ts +168 -24
- package/src/runtime/domain/background-service/process.domain.mjs +49 -11
- package/src/runtime/domain/background-service/process.ts +45 -11
- package/src/runtime/domain/background-service/review-settings.domain.mjs +16 -0
- package/src/runtime/domain/background-service/review-settings.ts +18 -0
- package/src/runtime/domain/background-service/runtime.domain.mjs +8 -70
- package/src/runtime/domain/background-service/runtime.ts +8 -73
- 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-navigator.domain.mjs +55 -28
- package/src/runtime/domain/background-service/shared-navigator.ts +47 -26
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.domain.mjs +7 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.ts +9 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +5 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +6 -0
- 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/background-service/stall.domain.mjs +5 -3
- package/src/runtime/domain/background-service/stall.ts +7 -4
- package/src/runtime/domain/background-service/supervised-progress.domain.mjs +42 -0
- package/src/runtime/domain/background-service/supervised-progress.ts +43 -0
- package/src/runtime/domain/background-service/supervisor/README.md +1 -4
- package/src/runtime/domain/background-service/supervisor/emit-runner.mjs +1 -0
- package/src/runtime/domain/background-service/supervisor/generated/process.mjs +49 -11
- package/src/runtime/domain/background-service/supervisor/generated/runner.mjs +47 -4
- package/src/runtime/domain/background-service/supervisor/generated/store.mjs +3 -3
- package/src/runtime/domain/background-service/supervisor/generated/watch-fingerprint.mjs +69 -0
- package/src/runtime/domain/background-service/supervisor/runner.domain.mjs +47 -4
- package/src/runtime/domain/background-service/supervisor/runner.ts +38 -3
- package/src/runtime/domain/background-service/supervisor/store.domain.mjs +3 -3
- package/src/runtime/domain/background-service/supervisor/store.ts +3 -3
- package/src/runtime/domain/background-service/supervisor/supervisor.domain.mjs +9 -3
- package/src/runtime/domain/background-service/supervisor/supervisor.ts +6 -3
- package/src/runtime/domain/background-service/tools.domain.mjs +22 -16
- package/src/runtime/domain/background-service/tools.ts +26 -16
- package/src/runtime/domain/background-service/types.ts +4 -2
- package/src/runtime/domain/background-service/watch-fingerprint.domain.mjs +67 -0
- package/src/runtime/domain/background-service/watch-fingerprint.ts +70 -0
- package/src/runtime/domain/catalog/catalog-preferences.mjs +1 -3
- package/src/runtime/domain/coordinator/src/outbox.mjs +7 -0
- package/src/runtime/domain/coordinator/src/store.mjs +5 -1
- package/src/runtime/domain/log-paths.mjs +8 -1
- package/src/runtime/domain/parse.mjs +9 -5
- package/src/runtime/domain/sandbox-policy/README.md +3 -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/session-store.mjs +7 -0
- package/src/runtime/domain/shared-harness-settings.mjs +2 -3
- package/src/runtime/domain/subagents/README.md +12 -10
- package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +2 -5
- package/src/runtime/domain/subagents/assignment-outcomes.ts +2 -5
- package/src/runtime/domain/subagents/assignment-report.domain.mjs +22 -0
- package/src/runtime/domain/subagents/assignment-report.ts +20 -0
- package/src/runtime/domain/subagents/batch.mjs +13 -5
- 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/cleanup.domain.mjs +11 -2
- package/src/runtime/domain/subagents/cleanup.ts +10 -2
- package/src/runtime/domain/subagents/config.domain.mjs +5 -0
- package/src/runtime/domain/subagents/config.ts +8 -2
- package/src/runtime/domain/subagents/continuation.domain.mjs +4 -2
- package/src/runtime/domain/subagents/continuation.ts +4 -2
- package/src/runtime/domain/subagents/extensions.mjs +1 -0
- package/src/runtime/domain/subagents/failures.domain.mjs +11 -2
- package/src/runtime/domain/subagents/failures.ts +10 -2
- package/src/runtime/domain/subagents/finalization.domain.mjs +39 -32
- package/src/runtime/domain/subagents/finalization.ts +37 -30
- 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 +208 -75
- package/src/runtime/domain/subagents/index.ts +213 -75
- package/src/runtime/domain/subagents/isolated-workspace.domain.mjs +508 -0
- package/src/runtime/domain/subagents/isolated-workspace.ts +551 -0
- package/src/runtime/domain/subagents/list.mjs +2 -2
- package/src/runtime/domain/subagents/managed-launch-client.domain.mjs +22 -5
- package/src/runtime/domain/subagents/managed-launch-client.ts +23 -6
- package/src/runtime/domain/subagents/output-payload.domain.mjs +24 -9
- package/src/runtime/domain/subagents/output-payload.ts +26 -12
- package/src/runtime/domain/subagents/package.json +4 -2
- package/src/runtime/domain/subagents/parse.domain.mjs +9 -5
- package/src/runtime/domain/subagents/parse.ts +10 -5
- package/src/runtime/domain/subagents/registry.domain.mjs +31 -25
- package/src/runtime/domain/subagents/registry.ts +31 -13
- package/src/runtime/domain/subagents/retained-result.domain.mjs +56 -0
- package/src/runtime/domain/subagents/retained-result.ts +65 -0
- package/src/runtime/domain/subagents/session-selection.domain.mjs +3 -1
- package/src/runtime/domain/subagents/session-selection.ts +2 -1
- package/src/runtime/domain/subagents/session-store.domain.mjs +7 -0
- package/src/runtime/domain/subagents/session-store.ts +9 -0
- package/src/runtime/domain/subagents/settings-page.domain.mjs +151 -107
- package/src/runtime/domain/subagents/settings-page.ts +147 -108
- package/src/runtime/domain/subagents/shared-catalog.domain.mjs +23 -7
- package/src/runtime/domain/subagents/shared-catalog.ts +23 -7
- 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/shared-navigator.domain.mjs +55 -28
- package/src/runtime/domain/subagents/shared-navigator.ts +47 -26
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.domain.mjs +7 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.ts +9 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +5 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +6 -0
- package/src/runtime/domain/subagents/task-guard.domain.mjs +14 -1
- package/src/runtime/domain/subagents/task-guard.ts +13 -1
- package/src/runtime/domain/subagents/task-policy.domain.mjs +2 -1
- package/src/runtime/domain/subagents/task-policy.ts +5 -1
- package/src/runtime/domain/subagents/tools.domain.mjs +4 -8
- package/src/runtime/domain/subagents/tools.ts +4 -7
- package/src/runtime/domain/subagents/work-observation.domain.mjs +25 -1
- package/src/runtime/domain/subagents/work-observation.ts +20 -1
- package/src/runtime/domain/subagents/workspace-files.domain.mjs +103 -0
- package/src/runtime/domain/subagents/workspace-files.ts +114 -0
- package/src/runtime/domain/subagents/workspace-prepare-worker.mjs +12 -0
- package/src/runtime/domain/subagents/workspace-scope.domain.d.mts +38 -0
- package/src/runtime/domain/subagents/workspace-scope.domain.mjs +5 -0
- package/src/runtime/domain/subagents/workspace-scope.ts +6 -0
- package/src/runtime/domain/subagents/worktree-feedback.domain.mjs +55 -0
- package/src/runtime/domain/subagents/worktree-feedback.ts +77 -0
- package/src/runtime/read-model.ts +4 -2
- package/src/runtime/root.ts +5 -2
- package/src/shared-ssh-core/index.ts +1 -1
- package/src/version.ts +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-background-tasks/src/runtime.ts. Do not edit directly.
|
|
2
|
-
import {
|
|
2
|
+
import { WATCH_FINGERPRINT_VERSION, watchOutcomeFingerprint } from "./watch-fingerprint.domain.mjs";
|
|
3
3
|
import { readFileSync, statSync } from "node:fs";
|
|
4
4
|
import { appendLine, appendTaskOutput, appendWatchResult, retainLogTail, resolveMaxLogBytes } from "./logs.domain.mjs";
|
|
5
5
|
import { evaluateCondition, validateCondition } from "./conditions.domain.mjs";
|
|
6
|
-
import { parseStepGateFailure, processExists, runCommandOnce, spawnCommand, STEP_GATE_COMMAND_ENV, stepGateScript, stopProcessGroup } from "./process.domain.mjs";
|
|
6
|
+
import { commandExecution, parseStepGateFailure, processExists, resolveWindowsLaunchShell, runCommandOnce, spawnCommand, STEP_GATE_COMMAND_ENV, stepGateScript, stopProcessGroup } from "./process.domain.mjs";
|
|
7
7
|
import { currentProcessStartToken, readProcessStartToken } from "./process-identity.domain.mjs";
|
|
8
8
|
import { DEFAULT_TMUX_BOOTSTRAP_TIMEOUT_MS, expandSshRemoteTaskPreset } from "./remote-task-preset.domain.mjs";
|
|
9
9
|
import { ensureTaskDir, logPathFor, nextTaskId, readMeta, sandboxProfilePathFor, writeMeta } from "./registry.domain.mjs";
|
|
@@ -224,6 +224,7 @@ export function createBackgroundTaskRuntime(attention = createFailureAttention()
|
|
|
224
224
|
// launch cwd is passed so a relative alias resolves where the task will run.
|
|
225
225
|
assertBackgroundExecutionAllowed(params, sandboxPlan, { remote: Boolean(params.ssh), cwd });
|
|
226
226
|
const commandLimits = backgroundExecutionLimits(sandboxPlan);
|
|
227
|
+
const resolvedWindowsShell = params.ssh ? undefined : resolveWindowsLaunchShell(pi);
|
|
227
228
|
const id = nextTaskId();
|
|
228
229
|
admission?.prepared?.(id);
|
|
229
230
|
const logPath = logPathFor(id);
|
|
@@ -239,7 +240,7 @@ export function createBackgroundTaskRuntime(attention = createFailureAttention()
|
|
|
239
240
|
remote: params.remote,
|
|
240
241
|
}, dependencies.remoteRunner)
|
|
241
242
|
: undefined;
|
|
242
|
-
const operatorSpec = remoteTask?.commandSpec ?? { ...params, cwd, shell: params.shell ?? true };
|
|
243
|
+
const operatorSpec = remoteTask?.commandSpec ?? { ...params, cwd, shell: params.shell ?? true, resolvedWindowsShell };
|
|
243
244
|
const commandSpec = withStepGate(operatorSpec, id, stepGated);
|
|
244
245
|
const sandboxNotices = [];
|
|
245
246
|
const launchSpec = remoteTask
|
|
@@ -536,6 +537,7 @@ export function createBackgroundTaskRuntime(attention = createFailureAttention()
|
|
|
536
537
|
const sandboxPlan = resolveForegroundSandboxPlan(pi, !!params.ssh, params, "bg_task_watch");
|
|
537
538
|
assertBackgroundExecutionAllowed(params, sandboxPlan, { remote: Boolean(params.ssh), cwd });
|
|
538
539
|
const commandLimits = backgroundExecutionLimits(sandboxPlan);
|
|
540
|
+
const resolvedWindowsShell = params.ssh || params.shell === false ? undefined : resolveWindowsLaunchShell(pi);
|
|
539
541
|
const id = nextTaskId();
|
|
540
542
|
admission?.prepared?.(id);
|
|
541
543
|
const now = Date.now();
|
|
@@ -550,11 +552,12 @@ export function createBackgroundTaskRuntime(attention = createFailureAttention()
|
|
|
550
552
|
remote: params.remote,
|
|
551
553
|
}, dependencies.remoteRunner)
|
|
552
554
|
: undefined;
|
|
553
|
-
const commandSpec = remoteTask?.commandSpec ?? { ...params, cwd, shell: params.shell ?? true };
|
|
555
|
+
const commandSpec = remoteTask?.commandSpec ?? { ...params, cwd, shell: params.shell ?? true, resolvedWindowsShell };
|
|
554
556
|
const sandboxNotices = [];
|
|
555
557
|
const launchSpec = remoteTask
|
|
556
558
|
? commandSpec
|
|
557
559
|
: confineCommandSpec(commandSpec, sandboxPlan, sandboxProfilePathFor(id), {}, (line) => sandboxNotices.push(line), "bg_task_watch");
|
|
560
|
+
const invocation = resolvedWindowsShell ? commandExecution(launchSpec) : undefined;
|
|
558
561
|
const meta = withCommandPolicy({
|
|
559
562
|
id,
|
|
560
563
|
name: params.name,
|
|
@@ -572,7 +575,7 @@ export function createBackgroundTaskRuntime(attention = createFailureAttention()
|
|
|
572
575
|
shell: commandSpec.shell,
|
|
573
576
|
cwd,
|
|
574
577
|
env: params.env,
|
|
575
|
-
launchArgv: launchArgvOf(commandSpec, launchSpec),
|
|
578
|
+
launchArgv: invocation ? [invocation.execPath, ...invocation.execArgs] : launchArgvOf(commandSpec, launchSpec),
|
|
576
579
|
sandbox: sandboxProvenance(sandboxPlan, !!remoteTask),
|
|
577
580
|
maxLogBytes: resolveMaxLogBytes(params.max_log_bytes),
|
|
578
581
|
spawnPid: process.pid,
|
|
@@ -1419,71 +1422,6 @@ export function createBackgroundTaskRuntime(attention = createFailureAttention()
|
|
|
1419
1422
|
return result.stdout.slice(0, 4000);
|
|
1420
1423
|
}
|
|
1421
1424
|
}
|
|
1422
|
-
/** Version tag of the watch outcome fingerprint. A value from another version is adopted, never compared. */
|
|
1423
|
-
const WATCH_FINGERPRINT_VERSION = "v1";
|
|
1424
|
-
/** OSC and CSI control sequences are display markup, not content. */
|
|
1425
|
-
const TERMINAL_ESCAPE = /\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)|\u001b\[[0-?]*[ -/]*[@-~]/g;
|
|
1426
|
-
/**
|
|
1427
|
-
* Text as the terminal would settle it. Redraw frames and control sequences are
|
|
1428
|
-
* display churn: repainting the same visible line is not a new observation.
|
|
1429
|
-
*/
|
|
1430
|
-
function settledTerminalText(text) {
|
|
1431
|
-
return text
|
|
1432
|
-
.replace(TERMINAL_ESCAPE, "")
|
|
1433
|
-
.split("\n")
|
|
1434
|
-
.map((line) => {
|
|
1435
|
-
// A CR immediately before LF ends the line; any other CR overwrites it in place.
|
|
1436
|
-
const body = line.endsWith("\r") ? line.slice(0, -1) : line;
|
|
1437
|
-
return (body.split("\r").at(-1) ?? "").replace(/[ \t]+$/, "");
|
|
1438
|
-
})
|
|
1439
|
-
.join("\n")
|
|
1440
|
-
.replace(/\n+$/, "");
|
|
1441
|
-
}
|
|
1442
|
-
/** Objects compare by content regardless of key order, so reordered keys are not progress. */
|
|
1443
|
-
function canonicalJsonText(value) {
|
|
1444
|
-
if (Array.isArray(value))
|
|
1445
|
-
return `[${value.map(canonicalJsonText).join(",")}]`;
|
|
1446
|
-
if (value && typeof value === "object") {
|
|
1447
|
-
const record = value;
|
|
1448
|
-
const entries = Object.keys(record).sort()
|
|
1449
|
-
.map((key) => `${JSON.stringify(key)}:${canonicalJsonText(record[key])}`);
|
|
1450
|
-
return `{${entries.join(",")}}`;
|
|
1451
|
-
}
|
|
1452
|
-
return JSON.stringify(value) ?? "null";
|
|
1453
|
-
}
|
|
1454
|
-
/** stdout compares as JSON content when it parses, and as settled text otherwise. */
|
|
1455
|
-
function canonicalWatchStdout(stdout) {
|
|
1456
|
-
const settled = settledTerminalText(stdout);
|
|
1457
|
-
try {
|
|
1458
|
-
return `json:${canonicalJsonText(JSON.parse(settled))}`;
|
|
1459
|
-
}
|
|
1460
|
-
catch {
|
|
1461
|
-
return `text:${settled}`;
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
/**
|
|
1465
|
-
* What a poll observed, independent of when it ran. Exit status, signal, error,
|
|
1466
|
-
* stdout content, and stderr content are included; poll metadata (start time,
|
|
1467
|
-
* end time, duration, check count) is deliberately not, so it can never hide a
|
|
1468
|
-
* watch that reports the same outcome forever. Watch stdout may carry its own
|
|
1469
|
-
* timestamps: projecting meaningful fields is the caller's job, not this
|
|
1470
|
-
* fingerprint's guess.
|
|
1471
|
-
*/
|
|
1472
|
-
function watchOutcomeFingerprint(result) {
|
|
1473
|
-
// A runner may report why the check itself could not run; that is part of the
|
|
1474
|
-
// observed outcome, not poll metadata.
|
|
1475
|
-
const reported = result.error;
|
|
1476
|
-
const error = typeof reported === "string" ? settledTerminalText(reported) : null;
|
|
1477
|
-
const payload = JSON.stringify([
|
|
1478
|
-
result.exitCode,
|
|
1479
|
-
result.signal ?? null,
|
|
1480
|
-
result.timedOut === true,
|
|
1481
|
-
error,
|
|
1482
|
-
canonicalWatchStdout(result.stdout),
|
|
1483
|
-
settledTerminalText(result.stderr),
|
|
1484
|
-
]);
|
|
1485
|
-
return `${WATCH_FINGERPRINT_VERSION}:${createHash("sha256").update(payload).digest("hex")}`;
|
|
1486
|
-
}
|
|
1487
1425
|
/**
|
|
1488
1426
|
* A watch's state clock advances only when its observed outcome changes. The
|
|
1489
1427
|
* poll itself is activity (`lastCheckedAt`), not progress, so a stationary
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WATCH_FINGERPRINT_VERSION, watchOutcomeFingerprint } from "./watch-fingerprint.js";
|
|
2
2
|
import { readFileSync, statSync } from "node:fs";
|
|
3
3
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
import { appendLine, appendTaskOutput, appendWatchResult, retainLogTail, resolveMaxLogBytes } from "./logs.js";
|
|
5
5
|
import { evaluateCondition, validateCondition } from "./conditions.js";
|
|
6
|
-
import { parseStepGateFailure, processExists, runCommandOnce, spawnCommand, STEP_GATE_COMMAND_ENV, stepGateScript, stopProcessGroup } from "./process.js";
|
|
6
|
+
import { commandExecution, parseStepGateFailure, processExists, resolveWindowsLaunchShell, runCommandOnce, spawnCommand, STEP_GATE_COMMAND_ENV, stepGateScript, stopProcessGroup } from "./process.js";
|
|
7
7
|
import { currentProcessStartToken, readProcessStartToken } from "./process-identity.js";
|
|
8
8
|
import { DEFAULT_TMUX_BOOTSTRAP_TIMEOUT_MS, expandSshRemoteTaskPreset } from "./remote-task-preset.js";
|
|
9
9
|
import type { RemoteRunner, ResolvedSshRemoteTask } from "./remote-task-preset.js";
|
|
@@ -315,6 +315,7 @@ function spawnTask(
|
|
|
315
315
|
// launch cwd is passed so a relative alias resolves where the task will run.
|
|
316
316
|
assertBackgroundExecutionAllowed(params, sandboxPlan, { remote: Boolean(params.ssh), cwd });
|
|
317
317
|
const commandLimits = backgroundExecutionLimits(sandboxPlan);
|
|
318
|
+
const resolvedWindowsShell = params.ssh ? undefined : resolveWindowsLaunchShell(pi);
|
|
318
319
|
const id = nextTaskId();
|
|
319
320
|
admission?.prepared?.(id);
|
|
320
321
|
const logPath = logPathFor(id);
|
|
@@ -330,7 +331,7 @@ function spawnTask(
|
|
|
330
331
|
remote: params.remote,
|
|
331
332
|
}, dependencies.remoteRunner)
|
|
332
333
|
: undefined;
|
|
333
|
-
const operatorSpec: CommandSpec = remoteTask?.commandSpec ?? { ...params, cwd, shell: params.shell ?? true };
|
|
334
|
+
const operatorSpec: CommandSpec = remoteTask?.commandSpec ?? { ...params, cwd, shell: params.shell ?? true, resolvedWindowsShell };
|
|
334
335
|
const commandSpec = withStepGate(operatorSpec, id, stepGated);
|
|
335
336
|
const sandboxNotices: string[] = [];
|
|
336
337
|
const launchSpec = remoteTask
|
|
@@ -629,6 +630,7 @@ function startWatchTask(
|
|
|
629
630
|
const sandboxPlan = resolveForegroundSandboxPlan(pi, !!params.ssh, params, "bg_task_watch");
|
|
630
631
|
assertBackgroundExecutionAllowed(params, sandboxPlan, { remote: Boolean(params.ssh), cwd });
|
|
631
632
|
const commandLimits = backgroundExecutionLimits(sandboxPlan);
|
|
633
|
+
const resolvedWindowsShell = params.ssh || params.shell === false ? undefined : resolveWindowsLaunchShell(pi);
|
|
632
634
|
const id = nextTaskId();
|
|
633
635
|
admission?.prepared?.(id);
|
|
634
636
|
const now = Date.now();
|
|
@@ -643,11 +645,12 @@ function startWatchTask(
|
|
|
643
645
|
remote: params.remote,
|
|
644
646
|
}, dependencies.remoteRunner)
|
|
645
647
|
: undefined;
|
|
646
|
-
const commandSpec: CommandSpec = remoteTask?.commandSpec ?? { ...params, cwd, shell: params.shell ?? true };
|
|
648
|
+
const commandSpec: CommandSpec = remoteTask?.commandSpec ?? { ...params, cwd, shell: params.shell ?? true, resolvedWindowsShell };
|
|
647
649
|
const sandboxNotices: string[] = [];
|
|
648
650
|
const launchSpec = remoteTask
|
|
649
651
|
? commandSpec
|
|
650
652
|
: confineCommandSpec(commandSpec, sandboxPlan, sandboxProfilePathFor(id), {}, (line) => sandboxNotices.push(line), "bg_task_watch");
|
|
653
|
+
const invocation = resolvedWindowsShell ? commandExecution(launchSpec) : undefined;
|
|
651
654
|
const meta = withCommandPolicy({
|
|
652
655
|
id,
|
|
653
656
|
name: params.name,
|
|
@@ -665,7 +668,7 @@ function startWatchTask(
|
|
|
665
668
|
shell: commandSpec.shell,
|
|
666
669
|
cwd,
|
|
667
670
|
env: params.env,
|
|
668
|
-
launchArgv: launchArgvOf(commandSpec, launchSpec),
|
|
671
|
+
launchArgv: invocation ? [invocation.execPath, ...invocation.execArgs] : launchArgvOf(commandSpec, launchSpec),
|
|
669
672
|
sandbox: sandboxProvenance(sandboxPlan, !!remoteTask),
|
|
670
673
|
maxLogBytes: resolveMaxLogBytes(params.max_log_bytes),
|
|
671
674
|
spawnPid: process.pid,
|
|
@@ -1540,74 +1543,6 @@ function extractLastState(result: { stdout: string }): unknown {
|
|
|
1540
1543
|
}
|
|
1541
1544
|
}
|
|
1542
1545
|
|
|
1543
|
-
/** Version tag of the watch outcome fingerprint. A value from another version is adopted, never compared. */
|
|
1544
|
-
const WATCH_FINGERPRINT_VERSION = "v1";
|
|
1545
|
-
/** OSC and CSI control sequences are display markup, not content. */
|
|
1546
|
-
const TERMINAL_ESCAPE = /\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)|\u001b\[[0-?]*[ -/]*[@-~]/g;
|
|
1547
|
-
|
|
1548
|
-
/**
|
|
1549
|
-
* Text as the terminal would settle it. Redraw frames and control sequences are
|
|
1550
|
-
* display churn: repainting the same visible line is not a new observation.
|
|
1551
|
-
*/
|
|
1552
|
-
function settledTerminalText(text: string): string {
|
|
1553
|
-
return text
|
|
1554
|
-
.replace(TERMINAL_ESCAPE, "")
|
|
1555
|
-
.split("\n")
|
|
1556
|
-
.map((line) => {
|
|
1557
|
-
// A CR immediately before LF ends the line; any other CR overwrites it in place.
|
|
1558
|
-
const body = line.endsWith("\r") ? line.slice(0, -1) : line;
|
|
1559
|
-
return (body.split("\r").at(-1) ?? "").replace(/[ \t]+$/, "");
|
|
1560
|
-
})
|
|
1561
|
-
.join("\n")
|
|
1562
|
-
.replace(/\n+$/, "");
|
|
1563
|
-
}
|
|
1564
|
-
|
|
1565
|
-
/** Objects compare by content regardless of key order, so reordered keys are not progress. */
|
|
1566
|
-
function canonicalJsonText(value: unknown): string {
|
|
1567
|
-
if (Array.isArray(value)) return `[${value.map(canonicalJsonText).join(",")}]`;
|
|
1568
|
-
if (value && typeof value === "object") {
|
|
1569
|
-
const record = value as Record<string, unknown>;
|
|
1570
|
-
const entries = Object.keys(record).sort()
|
|
1571
|
-
.map((key) => `${JSON.stringify(key)}:${canonicalJsonText(record[key])}`);
|
|
1572
|
-
return `{${entries.join(",")}}`;
|
|
1573
|
-
}
|
|
1574
|
-
return JSON.stringify(value) ?? "null";
|
|
1575
|
-
}
|
|
1576
|
-
|
|
1577
|
-
/** stdout compares as JSON content when it parses, and as settled text otherwise. */
|
|
1578
|
-
function canonicalWatchStdout(stdout: string): string {
|
|
1579
|
-
const settled = settledTerminalText(stdout);
|
|
1580
|
-
try {
|
|
1581
|
-
return `json:${canonicalJsonText(JSON.parse(settled))}`;
|
|
1582
|
-
} catch {
|
|
1583
|
-
return `text:${settled}`;
|
|
1584
|
-
}
|
|
1585
|
-
}
|
|
1586
|
-
|
|
1587
|
-
/**
|
|
1588
|
-
* What a poll observed, independent of when it ran. Exit status, signal, error,
|
|
1589
|
-
* stdout content, and stderr content are included; poll metadata (start time,
|
|
1590
|
-
* end time, duration, check count) is deliberately not, so it can never hide a
|
|
1591
|
-
* watch that reports the same outcome forever. Watch stdout may carry its own
|
|
1592
|
-
* timestamps: projecting meaningful fields is the caller's job, not this
|
|
1593
|
-
* fingerprint's guess.
|
|
1594
|
-
*/
|
|
1595
|
-
function watchOutcomeFingerprint(result: CommandResult): string {
|
|
1596
|
-
// A runner may report why the check itself could not run; that is part of the
|
|
1597
|
-
// observed outcome, not poll metadata.
|
|
1598
|
-
const reported = (result as CommandResult & { error?: unknown }).error;
|
|
1599
|
-
const error = typeof reported === "string" ? settledTerminalText(reported) : null;
|
|
1600
|
-
const payload = JSON.stringify([
|
|
1601
|
-
result.exitCode,
|
|
1602
|
-
result.signal ?? null,
|
|
1603
|
-
result.timedOut === true,
|
|
1604
|
-
error,
|
|
1605
|
-
canonicalWatchStdout(result.stdout),
|
|
1606
|
-
settledTerminalText(result.stderr),
|
|
1607
|
-
]);
|
|
1608
|
-
return `${WATCH_FINGERPRINT_VERSION}:${createHash("sha256").update(payload).digest("hex")}`;
|
|
1609
|
-
}
|
|
1610
|
-
|
|
1611
1546
|
/**
|
|
1612
1547
|
* A watch's state clock advances only when its observed outcome changes. The
|
|
1613
1548
|
* poll itself is activity (`lastCheckedAt`), not progress, so a stationary
|
|
@@ -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
|
|
|
@@ -369,7 +369,7 @@ const BACK_TO_MAIN = "← main (Esc)";
|
|
|
369
369
|
const BACK_TARGET = "back-to-main";
|
|
370
370
|
function highlightPointerTarget(theme, line, width) {
|
|
371
371
|
const colors = theme;
|
|
372
|
-
return colors?.bg?.("selectedBg", line + " ".repeat(Math.max(0, width -
|
|
372
|
+
return colors?.bg?.("selectedBg", line + " ".repeat(Math.max(0, width - piVisibleWidth(line))))
|
|
373
373
|
?? themeFgFromTheme(theme)("accent", line);
|
|
374
374
|
}
|
|
375
375
|
function createPointerNavigation(targetAt, activate) {
|
|
@@ -698,16 +698,16 @@ function formatMainListRow(row, selected, fg, width) {
|
|
|
698
698
|
const status = fg(indicator.color, indicator.glyph);
|
|
699
699
|
const elapsed = singleLine(row.elapsed || "-");
|
|
700
700
|
const available = Math.max(24, width || MAIN_LIST_FALLBACK_WIDTH);
|
|
701
|
-
const elapsedWidth = Math.min(Math.max(
|
|
701
|
+
const elapsedWidth = Math.min(Math.max(piVisibleWidth(elapsed), 4), 12);
|
|
702
702
|
const statusWidth = 2;
|
|
703
|
-
const leftPrefixWidth =
|
|
703
|
+
const leftPrefixWidth = piVisibleWidth(prefix) + statusWidth + 1;
|
|
704
704
|
const maxNameWidth = Math.max(8, Math.floor(available * 0.36));
|
|
705
705
|
const nameWidth = Math.max(8, Math.min(44, maxNameWidth, available - leftPrefixWidth - elapsedWidth - 10));
|
|
706
706
|
const rightWidth = Math.max(8, available - leftPrefixWidth - nameWidth - 1);
|
|
707
707
|
const summaryWidth = Math.max(1, rightWidth - elapsedWidth - 1);
|
|
708
708
|
const left = `${prefix}${fit(status, statusWidth)} ${fit(name, nameWidth)}`;
|
|
709
709
|
const right = `${dim(fitRight(rowSummary(row), summaryWidth), fg)} ${fitRight(elapsed, elapsedWidth)}`;
|
|
710
|
-
const gap = Math.max(1, available -
|
|
710
|
+
const gap = Math.max(1, available - piVisibleWidth(left) - piVisibleWidth(right));
|
|
711
711
|
return `${left}${" ".repeat(gap)}${right}`;
|
|
712
712
|
}
|
|
713
713
|
function statusGlyph(row) {
|
|
@@ -809,16 +809,16 @@ function rowSummary(row) {
|
|
|
809
809
|
}
|
|
810
810
|
function fit(value, width) {
|
|
811
811
|
const str = singleLine(value);
|
|
812
|
-
const visible =
|
|
813
|
-
if (visible
|
|
814
|
-
return
|
|
812
|
+
const visible = piVisibleWidth(str);
|
|
813
|
+
if (visible > width)
|
|
814
|
+
return piTruncateToWidth(str, width);
|
|
815
815
|
return str + " ".repeat(width - visible);
|
|
816
816
|
}
|
|
817
817
|
function fitRight(value, width) {
|
|
818
818
|
const str = singleLine(value);
|
|
819
|
-
const visible =
|
|
820
|
-
if (visible
|
|
821
|
-
return
|
|
819
|
+
const visible = piVisibleWidth(str);
|
|
820
|
+
if (visible > width)
|
|
821
|
+
return piTruncateToWidth(str, width);
|
|
822
822
|
return " ".repeat(width - visible) + str;
|
|
823
823
|
}
|
|
824
824
|
function singleLine(value) {
|
|
@@ -901,29 +901,49 @@ function installNavigatorEditor(ui, deps) {
|
|
|
901
901
|
function wrapEditor(inner, deps) {
|
|
902
902
|
if (inner && typeof inner.render === "function")
|
|
903
903
|
state().editorComponent = inner;
|
|
904
|
+
const methods = new Map();
|
|
905
|
+
const replacements = new Map();
|
|
904
906
|
const proxy = new Proxy(inner, {
|
|
905
907
|
get(target, prop) {
|
|
908
|
+
const value = Reflect.get(target, prop);
|
|
909
|
+
if (typeof value !== "function" || replacements.get(prop) === value)
|
|
910
|
+
return value;
|
|
911
|
+
const cached = methods.get(prop);
|
|
912
|
+
if (cached && cached.original === value)
|
|
913
|
+
return cached.exposed;
|
|
914
|
+
// Capture the method before another editor decorator replaces it.
|
|
915
|
+
// A decorator can retain this wrapper and call it as its delegate.
|
|
916
|
+
let exposed = value.bind(target);
|
|
906
917
|
if (prop === "handleInput") {
|
|
907
|
-
|
|
918
|
+
exposed = (data) => {
|
|
908
919
|
if (target.getText?.() === "" && handleMainListInput(data, deps)) {
|
|
909
920
|
return;
|
|
910
921
|
}
|
|
911
|
-
|
|
922
|
+
value.call(target, data);
|
|
912
923
|
};
|
|
913
924
|
}
|
|
914
|
-
if (prop === "render"
|
|
915
|
-
|
|
925
|
+
if (prop === "render") {
|
|
926
|
+
exposed = (...args) => {
|
|
916
927
|
const s = state();
|
|
917
928
|
if (s.editorFocusTarget === proxy)
|
|
918
929
|
s.editorRenders = (s.editorRenders ?? 0) + 1;
|
|
919
|
-
return
|
|
930
|
+
return value.apply(target, args);
|
|
920
931
|
};
|
|
921
932
|
}
|
|
922
|
-
|
|
923
|
-
return
|
|
933
|
+
methods.set(prop, { original: value, exposed });
|
|
934
|
+
return exposed;
|
|
924
935
|
},
|
|
925
936
|
set(target, prop, value) {
|
|
926
|
-
|
|
937
|
+
const cached = methods.get(prop);
|
|
938
|
+
const restoring = cached !== undefined && value === cached.exposed;
|
|
939
|
+
if (!Reflect.set(target, prop, restoring ? cached.original : value))
|
|
940
|
+
return false;
|
|
941
|
+
// Preserve replacement identity so the installing decorator can undo it.
|
|
942
|
+
if (!restoring && typeof value === "function")
|
|
943
|
+
replacements.set(prop, value);
|
|
944
|
+
else
|
|
945
|
+
replacements.delete(prop);
|
|
946
|
+
return true;
|
|
927
947
|
},
|
|
928
948
|
});
|
|
929
949
|
// Pi mounts and focuses whatever the factory returns; an extension that
|
|
@@ -1137,6 +1157,8 @@ function openNavigator() {
|
|
|
1137
1157
|
catch { /* keep foreground usable */ }
|
|
1138
1158
|
}
|
|
1139
1159
|
function createOverlayComponent(initialRows, deps, tui, theme, done, onClosed, initialDetailId) {
|
|
1160
|
+
let editorRendersSeen = state().editorRenders ?? 0;
|
|
1161
|
+
let sawLiveEditor = liveEditorMounted(tui) === true;
|
|
1140
1162
|
// The overlay only ever shows one row's detail; the rail below it is the list.
|
|
1141
1163
|
const overlayState = { rows: initialRows, selected: 0 };
|
|
1142
1164
|
let logTailRows = DEFAULT_LOG_TAIL_ROWS;
|
|
@@ -1296,19 +1318,24 @@ function createOverlayComponent(initialRows, deps, tui, theme, done, onClosed, i
|
|
|
1296
1318
|
closeArmTimer.unref?.();
|
|
1297
1319
|
requestRender();
|
|
1298
1320
|
}
|
|
1299
|
-
let editorRendersSeen;
|
|
1300
1321
|
/**
|
|
1301
|
-
*
|
|
1302
|
-
*
|
|
1303
|
-
*
|
|
1304
|
-
* rendered since the previous overlay frame (Pi renders the editor before it composites overlays).
|
|
1322
|
+
* Close when a replacement editor takes over while the sheet is open (#332).
|
|
1323
|
+
* A wrapper inside another extension's editor still counts as live if it rendered since
|
|
1324
|
+
* the last overlay frame. Pi renders the editor before it composites overlays.
|
|
1305
1325
|
*/
|
|
1306
1326
|
function closeIfEditorReplaced() {
|
|
1307
|
-
const rendersBefore = editorRendersSeen;
|
|
1308
1327
|
const renders = state().editorRenders ?? 0;
|
|
1328
|
+
const rendered = renders !== editorRendersSeen;
|
|
1309
1329
|
editorRendersSeen = renders;
|
|
1310
|
-
state().editorRenderedLastFrame =
|
|
1311
|
-
if (closed
|
|
1330
|
+
state().editorRenderedLastFrame = rendered;
|
|
1331
|
+
if (closed)
|
|
1332
|
+
return;
|
|
1333
|
+
const mounted = liveEditorMounted(tui);
|
|
1334
|
+
if (rendered || mounted === true) {
|
|
1335
|
+
sawLiveEditor = true;
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1338
|
+
if (mounted !== false || !sawLiveEditor)
|
|
1312
1339
|
return;
|
|
1313
1340
|
// Not from inside pi-tui's render pass: hiding an overlay there would change the stack it is drawing.
|
|
1314
1341
|
queueMicrotask(() => {
|
|
@@ -1839,10 +1866,10 @@ function fill(glyph, label, width) {
|
|
|
1839
1866
|
return prefix + glyph.repeat(w - visibleWidth(prefix));
|
|
1840
1867
|
}
|
|
1841
1868
|
function safeTruncate(line, width, truncate) {
|
|
1842
|
-
if (
|
|
1869
|
+
if (piVisibleWidth(line) <= width)
|
|
1843
1870
|
return line;
|
|
1844
1871
|
const cut = truncate(line, width);
|
|
1845
|
-
return
|
|
1872
|
+
return piVisibleWidth(cut) > width ? piTruncateToWidth(cut, width) : cut;
|
|
1846
1873
|
}
|
|
1847
1874
|
const ANSI_RE = new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))", "g");
|
|
1848
1875
|
const FORMATTING_PREFIX_RE = new RegExp(`^(?:${ANSI_RE.source}|<\\/?[a-zA-Z][\\w-]*>|</>)`);
|
|
@@ -460,7 +460,7 @@ const BACK_TARGET = "back-to-main";
|
|
|
460
460
|
|
|
461
461
|
function highlightPointerTarget(theme: unknown, line: string, width: number): string {
|
|
462
462
|
const colors = theme as { bg?(color: string, value: string): string } | undefined;
|
|
463
|
-
return colors?.bg?.("selectedBg", line + " ".repeat(Math.max(0, width -
|
|
463
|
+
return colors?.bg?.("selectedBg", line + " ".repeat(Math.max(0, width - piVisibleWidth(line))))
|
|
464
464
|
?? themeFgFromTheme(theme)("accent", line);
|
|
465
465
|
}
|
|
466
466
|
|
|
@@ -783,16 +783,16 @@ function formatMainListRow(row: InternalRow, selected: boolean, fg: (color: stri
|
|
|
783
783
|
const status = fg(indicator.color, indicator.glyph);
|
|
784
784
|
const elapsed = singleLine(row.elapsed || "-");
|
|
785
785
|
const available = Math.max(24, width || MAIN_LIST_FALLBACK_WIDTH);
|
|
786
|
-
const elapsedWidth = Math.min(Math.max(
|
|
786
|
+
const elapsedWidth = Math.min(Math.max(piVisibleWidth(elapsed), 4), 12);
|
|
787
787
|
const statusWidth = 2;
|
|
788
|
-
const leftPrefixWidth =
|
|
788
|
+
const leftPrefixWidth = piVisibleWidth(prefix) + statusWidth + 1;
|
|
789
789
|
const maxNameWidth = Math.max(8, Math.floor(available * 0.36));
|
|
790
790
|
const nameWidth = Math.max(8, Math.min(44, maxNameWidth, available - leftPrefixWidth - elapsedWidth - 10));
|
|
791
791
|
const rightWidth = Math.max(8, available - leftPrefixWidth - nameWidth - 1);
|
|
792
792
|
const summaryWidth = Math.max(1, rightWidth - elapsedWidth - 1);
|
|
793
793
|
const left = `${prefix}${fit(status, statusWidth)} ${fit(name, nameWidth)}`;
|
|
794
794
|
const right = `${dim(fitRight(rowSummary(row), summaryWidth), fg)} ${fitRight(elapsed, elapsedWidth)}`;
|
|
795
|
-
const gap = Math.max(1, available -
|
|
795
|
+
const gap = Math.max(1, available - piVisibleWidth(left) - piVisibleWidth(right));
|
|
796
796
|
return `${left}${" ".repeat(gap)}${right}`;
|
|
797
797
|
}
|
|
798
798
|
|
|
@@ -879,15 +879,15 @@ function rowSummary(row: InternalRow): string {
|
|
|
879
879
|
|
|
880
880
|
function fit(value: string, width: number): string {
|
|
881
881
|
const str = singleLine(value);
|
|
882
|
-
const visible =
|
|
883
|
-
if (visible
|
|
882
|
+
const visible = piVisibleWidth(str);
|
|
883
|
+
if (visible > width) return piTruncateToWidth(str, width);
|
|
884
884
|
return str + " ".repeat(width - visible);
|
|
885
885
|
}
|
|
886
886
|
|
|
887
887
|
function fitRight(value: string, width: number): string {
|
|
888
888
|
const str = singleLine(value);
|
|
889
|
-
const visible =
|
|
890
|
-
if (visible
|
|
889
|
+
const visible = piVisibleWidth(str);
|
|
890
|
+
if (visible > width) return piTruncateToWidth(str, width);
|
|
891
891
|
return " ".repeat(width - visible) + str;
|
|
892
892
|
}
|
|
893
893
|
|
|
@@ -954,28 +954,43 @@ function installNavigatorEditor(ui: any, deps: HostDeps): unknown {
|
|
|
954
954
|
|
|
955
955
|
function wrapEditor(inner: any, deps: HostDeps): unknown {
|
|
956
956
|
if (inner && typeof inner.render === "function") state().editorComponent = inner as Component;
|
|
957
|
+
const methods = new Map<PropertyKey, { original: Function; exposed: Function }>();
|
|
958
|
+
const replacements = new Map<PropertyKey, Function>();
|
|
957
959
|
const proxy: any = new Proxy(inner, {
|
|
958
960
|
get(target, prop) {
|
|
961
|
+
const value = Reflect.get(target, prop);
|
|
962
|
+
if (typeof value !== "function" || replacements.get(prop) === value) return value;
|
|
963
|
+
const cached = methods.get(prop);
|
|
964
|
+
if (cached && cached.original === value) return cached.exposed;
|
|
965
|
+
// Capture the method before another editor decorator replaces it.
|
|
966
|
+
// A decorator can retain this wrapper and call it as its delegate.
|
|
967
|
+
let exposed = value.bind(target);
|
|
959
968
|
if (prop === "handleInput") {
|
|
960
|
-
|
|
969
|
+
exposed = (data: string) => {
|
|
961
970
|
if (target.getText?.() === "" && handleMainListInput(data, deps)) {
|
|
962
971
|
return;
|
|
963
972
|
}
|
|
964
|
-
|
|
973
|
+
value.call(target, data);
|
|
965
974
|
};
|
|
966
975
|
}
|
|
967
|
-
if (prop === "render"
|
|
968
|
-
|
|
976
|
+
if (prop === "render") {
|
|
977
|
+
exposed = (...args: unknown[]) => {
|
|
969
978
|
const s = state();
|
|
970
979
|
if (s.editorFocusTarget === proxy) s.editorRenders = (s.editorRenders ?? 0) + 1;
|
|
971
|
-
return
|
|
980
|
+
return value.apply(target, args);
|
|
972
981
|
};
|
|
973
982
|
}
|
|
974
|
-
|
|
975
|
-
return
|
|
983
|
+
methods.set(prop, { original: value, exposed });
|
|
984
|
+
return exposed;
|
|
976
985
|
},
|
|
977
986
|
set(target, prop, value) {
|
|
978
|
-
|
|
987
|
+
const cached = methods.get(prop);
|
|
988
|
+
const restoring = cached !== undefined && value === cached.exposed;
|
|
989
|
+
if (!Reflect.set(target, prop, restoring ? cached.original : value)) return false;
|
|
990
|
+
// Preserve replacement identity so the installing decorator can undo it.
|
|
991
|
+
if (!restoring && typeof value === "function") replacements.set(prop, value);
|
|
992
|
+
else replacements.delete(prop);
|
|
993
|
+
return true;
|
|
979
994
|
},
|
|
980
995
|
});
|
|
981
996
|
// Pi mounts and focuses whatever the factory returns; an extension that
|
|
@@ -1174,6 +1189,8 @@ function createOverlayComponent(
|
|
|
1174
1189
|
onClosed: () => void,
|
|
1175
1190
|
initialDetailId: string,
|
|
1176
1191
|
) {
|
|
1192
|
+
let editorRendersSeen = state().editorRenders ?? 0;
|
|
1193
|
+
let sawLiveEditor = liveEditorMounted(tui) === true;
|
|
1177
1194
|
// The overlay only ever shows one row's detail; the rail below it is the list.
|
|
1178
1195
|
const overlayState: OverlayState = { rows: initialRows, selected: 0 };
|
|
1179
1196
|
let logTailRows: number = DEFAULT_LOG_TAIL_ROWS;
|
|
@@ -1331,19 +1348,23 @@ function createOverlayComponent(
|
|
|
1331
1348
|
requestRender();
|
|
1332
1349
|
}
|
|
1333
1350
|
|
|
1334
|
-
let editorRendersSeen: number | undefined;
|
|
1335
1351
|
/**
|
|
1336
|
-
*
|
|
1337
|
-
*
|
|
1338
|
-
*
|
|
1339
|
-
* rendered since the previous overlay frame (Pi renders the editor before it composites overlays).
|
|
1352
|
+
* Close when a replacement editor takes over while the sheet is open (#332).
|
|
1353
|
+
* A wrapper inside another extension's editor still counts as live if it rendered since
|
|
1354
|
+
* the last overlay frame. Pi renders the editor before it composites overlays.
|
|
1340
1355
|
*/
|
|
1341
1356
|
function closeIfEditorReplaced(): void {
|
|
1342
|
-
const rendersBefore = editorRendersSeen;
|
|
1343
1357
|
const renders = state().editorRenders ?? 0;
|
|
1358
|
+
const rendered = renders !== editorRendersSeen;
|
|
1344
1359
|
editorRendersSeen = renders;
|
|
1345
|
-
state().editorRenderedLastFrame =
|
|
1346
|
-
if (closed
|
|
1360
|
+
state().editorRenderedLastFrame = rendered;
|
|
1361
|
+
if (closed) return;
|
|
1362
|
+
const mounted = liveEditorMounted(tui);
|
|
1363
|
+
if (rendered || mounted === true) {
|
|
1364
|
+
sawLiveEditor = true;
|
|
1365
|
+
return;
|
|
1366
|
+
}
|
|
1367
|
+
if (mounted !== false || !sawLiveEditor) return;
|
|
1347
1368
|
// Not from inside pi-tui's render pass: hiding an overlay there would change the stack it is drawing.
|
|
1348
1369
|
queueMicrotask(() => {
|
|
1349
1370
|
if (closed) return;
|
|
@@ -1870,9 +1891,9 @@ function fill(glyph: string, label: string, width: number): string {
|
|
|
1870
1891
|
}
|
|
1871
1892
|
|
|
1872
1893
|
function safeTruncate(line: string, width: number, truncate: (s: string, width: number) => string): string {
|
|
1873
|
-
if (
|
|
1894
|
+
if (piVisibleWidth(line) <= width) return line;
|
|
1874
1895
|
const cut = truncate(line, width);
|
|
1875
|
-
return
|
|
1896
|
+
return piVisibleWidth(cut) > width ? piTruncateToWidth(cut, width) : cut;
|
|
1876
1897
|
}
|
|
1877
1898
|
|
|
1878
1899
|
const ANSI_RE = new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))", "g");
|
package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.domain.mjs
CHANGED
|
@@ -156,6 +156,13 @@ export function listOutbox(ctx, filter = {}) {
|
|
|
156
156
|
const where = clauses.length > 0 ? `WHERE ${clauses.join(" AND ")}` : "";
|
|
157
157
|
return getRows(ctx, `SELECT * FROM outbox_events ${where} ORDER BY created_at, event_id`, ...params).map((row) => mapOutbox(ctx, row));
|
|
158
158
|
}
|
|
159
|
+
/** Check a wait handoff without loading the retained evidence for its generations. */
|
|
160
|
+
export function hasDeliveredWaitDependency(ctx, operationId, terminalRevision, recipient) {
|
|
161
|
+
const owner = ownerClause("recipient", recipient);
|
|
162
|
+
return getRows(ctx, `SELECT 1 FROM outbox_events
|
|
163
|
+
WHERE operation_id = ? AND terminal_revision = ? AND event_type = 'dependency-ready'
|
|
164
|
+
AND delivered_at IS NOT NULL AND ${owner.sql} LIMIT 1`, requireId("operationId", operationId), requireCounter("terminalRevision", terminalRevision), ...owner.params).length > 0;
|
|
165
|
+
}
|
|
159
166
|
/** Find recipients with deliverable dependencies without loading each event's evidence. */
|
|
160
167
|
export function listDispatchableOutboxRecipients(ctx) {
|
|
161
168
|
return getRows(ctx, `SELECT recipient_kind, recipient_session_id, recipient_workspace, recipient_branch_id, recipient_goal_id,
|
|
@@ -281,6 +281,15 @@ export function listOutbox(ctx: StoreContext, filter: OutboxFilter = {}): Outbox
|
|
|
281
281
|
).map((row) => mapOutbox(ctx, row));
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
+
/** Check a wait handoff without loading the retained evidence for its generations. */
|
|
285
|
+
export function hasDeliveredWaitDependency(ctx: StoreContext, operationId: string, terminalRevision: number, recipient: OwnerIdentity): boolean {
|
|
286
|
+
const owner = ownerClause("recipient", recipient);
|
|
287
|
+
return getRows(ctx, `SELECT 1 FROM outbox_events
|
|
288
|
+
WHERE operation_id = ? AND terminal_revision = ? AND event_type = 'dependency-ready'
|
|
289
|
+
AND delivered_at IS NOT NULL AND ${owner.sql} LIMIT 1`,
|
|
290
|
+
requireId("operationId", operationId), requireCounter("terminalRevision", terminalRevision), ...owner.params).length > 0;
|
|
291
|
+
}
|
|
292
|
+
|
|
284
293
|
/** Find recipients with deliverable dependencies without loading each event's evidence. */
|
|
285
294
|
export function listDispatchableOutboxRecipients(ctx: StoreContext): Array<{ recipient: OwnerIdentity; count: number }> {
|
|
286
295
|
return getRows(
|