@narumitw/pi-sync 0.68.0 → 0.69.0
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 +21 -0
- package/README.md +35 -21
- package/dist/chunks/{chunk-AYGMIMCV.ts → chunk-4KGDPLQ4.ts} +2 -2
- package/dist/chunks/chunk-4KGDPLQ4.ts.map +7 -0
- package/dist/chunks/{chunk-FR6A7ASZ.ts → chunk-EG6BUOUQ.ts} +3 -3
- package/dist/chunks/{chunk-YV2R5SJU.ts → chunk-EI2J5Z4Q.ts} +17 -8
- package/dist/chunks/chunk-EI2J5Z4Q.ts.map +7 -0
- package/dist/chunks/{chunk-BCDBT4X3.ts → chunk-GXB74FYB.ts} +4 -4
- package/dist/chunks/{chunk-J52GYZO6.ts → chunk-LNZRNXNQ.ts} +2 -4
- package/dist/chunks/{chunk-FQKWGVMA.ts → chunk-OWSKD5XG.ts} +10 -7
- package/dist/chunks/chunk-OWSKD5XG.ts.map +7 -0
- package/dist/chunks/{chunk-WCGLU526.ts → chunk-RXZVLBPU.ts} +3 -3
- package/dist/chunks/{chunk-KAIVTJIQ.ts → chunk-RZB2DPVU.ts} +2 -2
- package/dist/chunks/{chunk-335XTMMZ.ts → chunk-VQTYTUBU.ts} +24 -26
- package/dist/chunks/chunk-VQTYTUBU.ts.map +7 -0
- package/dist/chunks/{chunk-TLYT6HVI.ts → chunk-YX6DCQ7P.ts} +2 -2
- package/dist/chunks/{command-handler-S6BRZMPW.ts → command-handler-ZR26OSBX.ts} +39 -143
- package/dist/chunks/command-handler-ZR26OSBX.ts.map +7 -0
- package/dist/chunks/{conflict-review-3XMYDJIK.ts → conflict-review-W5BCZIZG.ts} +2 -2
- package/dist/chunks/{file-selection-4BOQBXS7.ts → file-selection-STCIRKF6.ts} +3 -3
- package/dist/chunks/{manager-result-dispatcher-A4IWLS4J.ts → manager-result-dispatcher-MPLPDR2P.ts} +5 -5
- package/dist/chunks/{manager-ui-KHMCSLLV.ts → manager-ui-OMZOBGYT.ts} +99 -96
- package/dist/chunks/manager-ui-OMZOBGYT.ts.map +7 -0
- package/dist/chunks/{merge-review-LWMUE5IW.ts → merge-review-KTIQBRLL.ts} +2 -2
- package/dist/chunks/{remote-selection-ui-F6NJBQ3Y.ts → remote-selection-ui-CCHMCAHQ.ts} +4 -4
- package/dist/chunks/{setup-switch-7LMIRMZ7.ts → setup-switch-J3YLBB6N.ts} +4 -4
- package/dist/chunks/{setup-wizard-2NRPR433.ts → setup-wizard-J3YOR7BR.ts} +3 -4
- package/dist/chunks/{setup-wizard-2NRPR433.ts.map → setup-wizard-J3YOR7BR.ts.map} +1 -1
- package/dist/chunks/{sync-inspection-QGM54YCM.ts → sync-inspection-7OADBR57.ts} +3 -3
- package/dist/chunks/{sync-operations-DTQMKVRQ.ts → sync-operations-3K6WLPXY.ts} +2 -10
- package/dist/chunks/{sync-operations-DTQMKVRQ.ts.map → sync-operations-3K6WLPXY.ts.map} +2 -2
- package/dist/daemon/dist/build-id.json +1 -1
- package/dist/daemon/dist/engine/backends/git/git-backend.js +1 -1
- package/dist/daemon/dist/engine/backends/s3/s3-backend.js +2 -2
- package/dist/daemon/dist/engine/backends/webdav/webdav-backend.js +67 -6
- package/dist/daemon/dist/engine/debug-check.js +59 -0
- package/dist/daemon/dist/engine/debug-log.js +100 -1
- package/dist/daemon/dist/engine/sync/directional-conflict.js +31 -0
- package/dist/daemon/dist/engine/sync/push-review.js +1 -1
- package/dist/daemon/dist/engine/sync/sync-error-guidance.js +6 -5
- package/dist/daemon/dist/engine/sync/sync-inspection.js +5 -1
- package/dist/daemon/dist/engine/sync/sync-mutations.js +40 -7
- package/dist/daemon/dist/engine/sync/sync-queries.js +179 -82
- package/dist/daemon/dist/engine/sync/sync-state.js +1 -1
- package/dist/daemon/dist/engine/ui/sync-format.js +1 -1
- package/dist/daemon/dist/engine/ui/transfer-review.js +2 -3
- package/dist/daemon/dist/engine-service.js +100 -25
- package/dist/daemon/dist/foreground-transfer.js +10 -0
- package/dist/daemon/dist/index.js +1 -0
- package/dist/daemon/dist/server.js +2 -1
- package/dist/daemon/dist/service-host.js +1 -1
- package/dist/daemon/package.json +1 -1
- package/dist/index.ts +111 -10
- package/dist/index.ts.map +3 -3
- package/docs/daemon-migration.md +2 -2
- package/docs/tui-contract.md +7 -7
- package/package.json +7 -4
- package/skills/configure-pi-sync/SKILL.md +4 -7
- package/skills/configure-pi-sync/references/configuration.md +20 -19
- package/src/commands/command-execution.ts +36 -136
- package/src/commands/command-handler.ts +3 -3
- package/src/commands/command.ts +28 -26
- package/src/daemon/directional-recovery.ts +3 -1
- package/src/daemon/pi-client.ts +14 -2
- package/src/sync/debug-tool.ts +96 -0
- package/src/sync/startup-check.ts +1 -1
- package/src/sync/sync-operations.ts +0 -6
- package/src/sync-extension.ts +13 -1
- package/src/ui/cancellable-operation.ts +11 -4
- package/src/ui/manager-state.ts +13 -12
- package/src/ui/manager-ui.ts +96 -81
- package/src/ui/operation-dialogs.ts +1 -1
- package/src/ui/settings-ui.ts +2 -3
- package/src/ui/setup/webdav-ui.ts +1 -1
- package/dist/chunks/chunk-335XTMMZ.ts.map +0 -7
- package/dist/chunks/chunk-AYGMIMCV.ts.map +0 -7
- package/dist/chunks/chunk-ECYCNZOE.ts +0 -12
- package/dist/chunks/chunk-ECYCNZOE.ts.map +0 -7
- package/dist/chunks/chunk-FQKWGVMA.ts.map +0 -7
- package/dist/chunks/chunk-YV2R5SJU.ts.map +0 -7
- package/dist/chunks/command-handler-S6BRZMPW.ts.map +0 -7
- package/dist/chunks/manager-ui-KHMCSLLV.ts.map +0 -7
- /package/dist/chunks/{chunk-FR6A7ASZ.ts.map → chunk-EG6BUOUQ.ts.map} +0 -0
- /package/dist/chunks/{chunk-BCDBT4X3.ts.map → chunk-GXB74FYB.ts.map} +0 -0
- /package/dist/chunks/{chunk-J52GYZO6.ts.map → chunk-LNZRNXNQ.ts.map} +0 -0
- /package/dist/chunks/{chunk-WCGLU526.ts.map → chunk-RXZVLBPU.ts.map} +0 -0
- /package/dist/chunks/{chunk-KAIVTJIQ.ts.map → chunk-RZB2DPVU.ts.map} +0 -0
- /package/dist/chunks/{chunk-TLYT6HVI.ts.map → chunk-YX6DCQ7P.ts.map} +0 -0
- /package/dist/chunks/{conflict-review-3XMYDJIK.ts.map → conflict-review-W5BCZIZG.ts.map} +0 -0
- /package/dist/chunks/{file-selection-4BOQBXS7.ts.map → file-selection-STCIRKF6.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-A4IWLS4J.ts.map → manager-result-dispatcher-MPLPDR2P.ts.map} +0 -0
- /package/dist/chunks/{merge-review-LWMUE5IW.ts.map → merge-review-KTIQBRLL.ts.map} +0 -0
- /package/dist/chunks/{remote-selection-ui-F6NJBQ3Y.ts.map → remote-selection-ui-CCHMCAHQ.ts.map} +0 -0
- /package/dist/chunks/{setup-switch-7LMIRMZ7.ts.map → setup-switch-J3YLBB6N.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-QGM54YCM.ts.map → sync-inspection-7OADBR57.ts.map} +0 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { StringEnum } from "@earendil-works/pi-ai";
|
|
2
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { debugCheckFailure, summarizeDebugInspection } from "@narumitw/pi-sync-daemon/engine/debug-check";
|
|
4
|
+
import { readLatestDebugCheck } from "@narumitw/pi-sync-daemon/engine/debug-log";
|
|
5
|
+
import { Type } from "typebox";
|
|
6
|
+
import type { PiDaemonClient } from "../daemon/pi-client.js";
|
|
7
|
+
import { configFromSettings, syncCheckConfigFingerprint, syncConfigReviewFingerprint } from "../settings/config.js";
|
|
8
|
+
|
|
9
|
+
const TOOL_NAME = "pi_sync_debug";
|
|
10
|
+
const RECHECK_TIMEOUT_MS = 30_000;
|
|
11
|
+
type DebugOwner = { client: PiDaemonClient; signal: AbortSignal };
|
|
12
|
+
|
|
13
|
+
function toolResult(value: unknown) {
|
|
14
|
+
return { content: [{ type: "text" as const, text: JSON.stringify(value) }], details: {} };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function registerPiSyncDebug(pi: ExtensionAPI, getOwner: (ctx: ExtensionContext) => DebugOwner | undefined) {
|
|
18
|
+
pi.registerTool({
|
|
19
|
+
name: TOOL_NAME,
|
|
20
|
+
label: "Pi Sync debug",
|
|
21
|
+
description:
|
|
22
|
+
"Read the latest sanitized Pi Sync check from the local log (latest), or read configured remote storage without confirmation to return a fresh sanitized summary (recheck). Does not publish or apply files.",
|
|
23
|
+
parameters: Type.Object({ action: StringEnum(["latest", "recheck"]) }, { additionalProperties: false }),
|
|
24
|
+
defaultActive: false,
|
|
25
|
+
exposure: "direct",
|
|
26
|
+
executionMode: "sequential",
|
|
27
|
+
async execute(_id, { action }, toolSignal, _update, ctx) {
|
|
28
|
+
const owner = getOwner(ctx);
|
|
29
|
+
if (!owner || !ctx.hasUI || (ctx.mode !== "tui" && ctx.mode !== "rpc"))
|
|
30
|
+
throw new Error("Pi Sync debug requires an interactive session started with Debug mode on.");
|
|
31
|
+
const { client } = owner;
|
|
32
|
+
const signal = toolSignal ? AbortSignal.any([owner.signal, toolSignal]) : owner.signal;
|
|
33
|
+
const validate = () => {
|
|
34
|
+
signal.throwIfAborted();
|
|
35
|
+
if (getOwner(ctx)?.client !== client) throw new Error("Pi Sync session was replaced.");
|
|
36
|
+
try {
|
|
37
|
+
client.validateDebugTool();
|
|
38
|
+
} catch {
|
|
39
|
+
throw new Error("The Pi Sync debug session is no longer available.");
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
async function readSetup() {
|
|
43
|
+
validate();
|
|
44
|
+
try {
|
|
45
|
+
const { settings } = await client.readStartupSettings(signal);
|
|
46
|
+
validate();
|
|
47
|
+
if (settings) return configFromSettings(settings);
|
|
48
|
+
} catch {
|
|
49
|
+
validate();
|
|
50
|
+
}
|
|
51
|
+
throw new Error("The current Pi Sync setup is not available. Review /sync → Settings.");
|
|
52
|
+
}
|
|
53
|
+
const setup = await readSetup();
|
|
54
|
+
validate();
|
|
55
|
+
if (action === "latest") {
|
|
56
|
+
const last = readLatestDebugCheck(client.root, syncConfigReviewFingerprint(setup));
|
|
57
|
+
if (last.kind === "unavailable") throw new Error("The private Pi Sync debug log is unavailable.");
|
|
58
|
+
if (last.kind === "no-record") return toolResult({ kind: "no-record" });
|
|
59
|
+
return toolResult({ kind: "historical", ...last.check });
|
|
60
|
+
}
|
|
61
|
+
if (action !== "recheck") throw new Error("Choose latest or recheck.");
|
|
62
|
+
if (client.ownershipCleanupRequired) throw new Error("Pi Sync needs recovery. Open /sync daemon status.");
|
|
63
|
+
const fingerprint = syncCheckConfigFingerprint(setup);
|
|
64
|
+
const deadline = AbortSignal.timeout(RECHECK_TIMEOUT_MS);
|
|
65
|
+
const recheckSignal = AbortSignal.any([signal, deadline]);
|
|
66
|
+
let result: unknown;
|
|
67
|
+
try {
|
|
68
|
+
result = await client.run(
|
|
69
|
+
"inspect",
|
|
70
|
+
{ setup: setup.setupName, fingerprint, origin: "recheck" },
|
|
71
|
+
recheckSignal,
|
|
72
|
+
ctx,
|
|
73
|
+
);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
validate();
|
|
76
|
+
const { reason } = debugCheckFailure(deadline.aborted ? deadline.reason : error);
|
|
77
|
+
throw new Error(`Pi Sync recheck failed: ${reason}.`);
|
|
78
|
+
}
|
|
79
|
+
validate();
|
|
80
|
+
if (deadline.aborted) throw new Error("Pi Sync recheck failed: timeout.");
|
|
81
|
+
const latest = await readSetup();
|
|
82
|
+
validate();
|
|
83
|
+
if (fingerprint !== syncCheckConfigFingerprint(latest))
|
|
84
|
+
throw new Error("Pi Sync setup changed during recheck. Ask to recheck the new setup.");
|
|
85
|
+
const summary = summarizeDebugInspection(result);
|
|
86
|
+
if (!summary) throw new Error("Pi Sync did not return a valid check result.");
|
|
87
|
+
return toolResult({ kind: "fresh", time: new Date().toISOString(), origin: "recheck", summary });
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return (enabled: boolean) => {
|
|
92
|
+
const active = pi.getActiveTools();
|
|
93
|
+
if (active.includes(TOOL_NAME) === enabled) return;
|
|
94
|
+
pi.setActiveTools(enabled ? [...active, TOOL_NAME] : active.filter((name) => name !== TOOL_NAME));
|
|
95
|
+
};
|
|
96
|
+
}
|
|
@@ -170,7 +170,7 @@ export function createStartupCheck(
|
|
|
170
170
|
ctx.ui.notify(
|
|
171
171
|
config && startupTransferEnabled(config)
|
|
172
172
|
? `pi-sync automatic transfer stopped: ${safeTerminalText(errorMessage(error))}. Run /sync to review or reconcile retained recovery evidence. No resources were reloaded.`
|
|
173
|
-
: `pi-sync startup check skipped: ${safeTerminalText(errorMessage(error))}.
|
|
173
|
+
: `pi-sync startup check skipped: ${safeTerminalText(errorMessage(error))}. Use View differences in /sync, or ask Pi to recheck in Debug mode. No startup transfer was performed.`,
|
|
174
174
|
"warning",
|
|
175
175
|
);
|
|
176
176
|
} finally {
|
|
@@ -27,15 +27,9 @@ export async function syncBoth(ctx: ExtensionContext, options: CommandOptions) {
|
|
|
27
27
|
export async function rollback(ctx: ExtensionContext, options: CommandOptions) {
|
|
28
28
|
await remoteOperation(ctx, "rollback", options);
|
|
29
29
|
}
|
|
30
|
-
export async function status(ctx: ExtensionContext, options: CommandOptions) {
|
|
31
|
-
await remoteOperation(ctx, "status", options);
|
|
32
|
-
}
|
|
33
30
|
export async function diff(ctx: ExtensionContext, options: CommandOptions) {
|
|
34
31
|
await remoteOperation(ctx, "diff", options);
|
|
35
32
|
}
|
|
36
|
-
export async function doctor(ctx: ExtensionContext, options: CommandOptions) {
|
|
37
|
-
await remoteOperation(ctx, "doctor", options);
|
|
38
|
-
}
|
|
39
33
|
export async function history(ctx: ExtensionContext, options: CommandOptions) {
|
|
40
34
|
await remoteOperation(ctx, "history", options);
|
|
41
35
|
}
|
package/src/sync-extension.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { completeSyncArguments, splitArgs } from "./commands/command.js";
|
|
2
|
+
import { completeSyncArguments, retiredSyncCommandGuidance, splitArgs } from "./commands/command.js";
|
|
3
3
|
import {
|
|
4
4
|
bindPiDaemonClient,
|
|
5
5
|
installPiDaemonHost,
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import type { AnySyncConfig } from "./settings/settings-types.js";
|
|
10
10
|
import { startupTransferEnabled } from "./sync/agent-policy.js";
|
|
11
11
|
import { autoPushSessions, startSession } from "./sync/automatic-sync.js";
|
|
12
|
+
import { registerPiSyncDebug } from "./sync/debug-tool.js";
|
|
12
13
|
import { combineSignals } from "./sync/signals.js";
|
|
13
14
|
import { createStartupCheck } from "./sync/startup-check.js";
|
|
14
15
|
import { errorMessage } from "./sync/sync-errors.js";
|
|
@@ -30,12 +31,22 @@ export default function sync(pi: ExtensionAPI, dependencies: Partial<SyncDepende
|
|
|
30
31
|
let initialization = Promise.resolve<AnySyncConfig | false | undefined>(undefined);
|
|
31
32
|
let owner: PiDaemonClient | undefined;
|
|
32
33
|
let ownerManager: ExtensionContext["sessionManager"] | undefined;
|
|
34
|
+
const exposeDebugTool = registerPiSyncDebug(pi, (ctx) =>
|
|
35
|
+
owner?.debugEnabled && !sessionAbort.signal.aborted && ownerManager === ctx.sessionManager
|
|
36
|
+
? { client: owner, signal: sessionAbort.signal }
|
|
37
|
+
: undefined,
|
|
38
|
+
);
|
|
33
39
|
|
|
34
40
|
pi.registerCommand("sync", {
|
|
35
41
|
description: "Sync Pi settings through Git, WebDAV, R2, or S3-compatible storage",
|
|
36
42
|
getArgumentCompletions: completeSyncArguments,
|
|
37
43
|
handler: async (args, ctx) => {
|
|
38
44
|
if (!ctx.hasUI) throw new Error("/sync requires TUI or RPC mode so results and safety prompts are observable.");
|
|
45
|
+
const retired = retiredSyncCommandGuidance(splitArgs(args)[0]);
|
|
46
|
+
if (retired) {
|
|
47
|
+
ctx.ui.notify(retired, "warning");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
39
50
|
status.bind(ctx);
|
|
40
51
|
const signal = sessionAbort.signal;
|
|
41
52
|
const client = owner;
|
|
@@ -193,6 +204,7 @@ export default function sync(pi: ExtensionAPI, dependencies: Partial<SyncDepende
|
|
|
193
204
|
});
|
|
194
205
|
try {
|
|
195
206
|
const ready = await initialization;
|
|
207
|
+
if (!signal.aborted && owner === client) exposeDebugTool(client.debugEnabled);
|
|
196
208
|
if (ready === false) {
|
|
197
209
|
client.disableQueueReleaseUI();
|
|
198
210
|
releaseStatus();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BorderedLoader, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { isKeyRelease, Key, matchesKey, truncateToWidth } from "@earendil-works/pi-tui";
|
|
3
|
+
import type { ForegroundTransferIntent } from "@narumitw/pi-sync-daemon";
|
|
3
4
|
import { formatInteractionHints, runCustomInteraction } from "@narumitw/pi-tui-kit";
|
|
4
5
|
import type { SetupPullOutcome } from "../sync/setup-switch.js";
|
|
5
6
|
import type { SyncDecision } from "../sync/sync-decision.js";
|
|
@@ -9,8 +10,14 @@ export type RunRouteResult =
|
|
|
9
10
|
| { kind: "completed"; outcome?: SetupPullOutcome }
|
|
10
11
|
| { kind: "decision-required"; decision: SyncDecision }
|
|
11
12
|
| { kind: "remote-selection-required"; decision: RemoteSelectionDecision }
|
|
13
|
+
| { kind: "destination-conflict" }
|
|
12
14
|
| { kind: "failed" };
|
|
13
15
|
|
|
16
|
+
export interface DirectionalIntent {
|
|
17
|
+
fingerprint: string;
|
|
18
|
+
intent: ForegroundTransferIntent;
|
|
19
|
+
}
|
|
20
|
+
|
|
14
21
|
export type RunRoute = (
|
|
15
22
|
route: string,
|
|
16
23
|
signal?: AbortSignal,
|
|
@@ -18,7 +25,7 @@ export type RunRoute = (
|
|
|
18
25
|
target?: string,
|
|
19
26
|
onDialog?: (active: boolean) => void,
|
|
20
27
|
retryRefusal?: boolean,
|
|
21
|
-
|
|
28
|
+
directional?: DirectionalIntent,
|
|
22
29
|
) => Promise<RunRouteResult | undefined>;
|
|
23
30
|
|
|
24
31
|
export type CancellableOperationResult = RunRouteResult | { kind: "closed" } | { kind: "cancelled" };
|
|
@@ -28,7 +35,7 @@ interface CancellableOperationOptions {
|
|
|
28
35
|
cancelAcrossDialogs?: boolean;
|
|
29
36
|
cancelledMessage?: string | null;
|
|
30
37
|
target?: string;
|
|
31
|
-
|
|
38
|
+
directional?: DirectionalIntent;
|
|
32
39
|
signal?: AbortSignal;
|
|
33
40
|
isCurrent?: () => boolean;
|
|
34
41
|
}
|
|
@@ -44,7 +51,7 @@ export async function runCancellableOperation(
|
|
|
44
51
|
ctx,
|
|
45
52
|
message,
|
|
46
53
|
(signal, onCommit, onDialog) =>
|
|
47
|
-
runRoute(route, signal, onCommit, options.target, onDialog, undefined, options.
|
|
54
|
+
runRoute(route, signal, onCommit, options.target, onDialog, undefined, options.directional),
|
|
48
55
|
options,
|
|
49
56
|
);
|
|
50
57
|
return result.kind === "completed" ? (result.value ?? { kind: "failed" }) : result;
|
|
@@ -64,7 +71,7 @@ export async function runCancellableTask<Value>(
|
|
|
64
71
|
onCommit?: () => void,
|
|
65
72
|
onDialog?: (active: boolean) => void,
|
|
66
73
|
) => Promise<Value>,
|
|
67
|
-
options: Omit<CancellableOperationOptions, "target" | "
|
|
74
|
+
options: Omit<CancellableOperationOptions, "target" | "directional"> = {},
|
|
68
75
|
): Promise<CancellableTaskResult<Value>> {
|
|
69
76
|
const {
|
|
70
77
|
commitAware = false,
|
package/src/ui/manager-state.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { stripVTControlCharacters } from "node:util";
|
|
1
2
|
import { truncateToWidth } from "@earendil-works/pi-tui";
|
|
2
3
|
import { createSettingsConfigView, syncCheckConfigFingerprint } from "../settings/config.js";
|
|
3
4
|
import { type LocalConfigDocument, readActiveLocalConfigDocumentForRepair } from "../settings/config-file.js";
|
|
@@ -28,10 +29,8 @@ export const MAIN_MENU_ACTIONS = [
|
|
|
28
29
|
"Pull from remote",
|
|
29
30
|
"Push to remote",
|
|
30
31
|
"View differences",
|
|
31
|
-
"Check remote status",
|
|
32
32
|
"Settings",
|
|
33
33
|
"History",
|
|
34
|
-
"Diagnostics",
|
|
35
34
|
] as const;
|
|
36
35
|
|
|
37
36
|
export interface ManagerDescription {
|
|
@@ -132,13 +131,11 @@ export async function describeManagerState(
|
|
|
132
131
|
syncStateFingerprint(syncState) === observation.inspection.stateIdentity
|
|
133
132
|
? observation
|
|
134
133
|
: undefined;
|
|
135
|
-
const lastAppliedSnapshot =
|
|
136
|
-
?
|
|
137
|
-
: syncState
|
|
138
|
-
?
|
|
139
|
-
:
|
|
140
|
-
? "Never synced"
|
|
141
|
-
: "Unavailable";
|
|
134
|
+
const lastAppliedSnapshot = syncState?.lastAppliedSnapshot
|
|
135
|
+
? truncatePlainText(syncState.lastAppliedSnapshot, 40)
|
|
136
|
+
: syncState
|
|
137
|
+
? "Never synced"
|
|
138
|
+
: "Unavailable";
|
|
142
139
|
const canSwitch = !changesBlocked && (alternateUsable || (await hasAnotherSwitchableSetup(view, signal)));
|
|
143
140
|
signal?.throwIfAborted();
|
|
144
141
|
const mainActions: string[] = [...MAIN_MENU_ACTIONS];
|
|
@@ -168,7 +165,7 @@ export async function describeManagerState(
|
|
|
168
165
|
: currentObservation
|
|
169
166
|
? [`Observed ${safeTerminalText(currentObservation.checkedAt)}: ${observationSummary(currentObservation)}`]
|
|
170
167
|
: ["Remote status: Not checked"]),
|
|
171
|
-
`Last applied: ${lastAppliedSnapshot}`,
|
|
168
|
+
`Last applied snapshot: ${lastAppliedSnapshot}`,
|
|
172
169
|
...(config.automaticTransfer || (config.automatic && syncSessionsSelected(config))
|
|
173
170
|
? ["Automatic transfer permission: On · see Settings"]
|
|
174
171
|
: []),
|
|
@@ -226,7 +223,6 @@ function operationActions(
|
|
|
226
223
|
"Settings",
|
|
227
224
|
...(canSwitch ? ["Switch sync setup"] : []),
|
|
228
225
|
"History",
|
|
229
|
-
"Diagnostics",
|
|
230
226
|
]
|
|
231
227
|
: mainActions;
|
|
232
228
|
}
|
|
@@ -236,7 +232,7 @@ function operationStatusLines(operation: OperationAvailability): string[] {
|
|
|
236
232
|
case "free":
|
|
237
233
|
return [];
|
|
238
234
|
case "live": {
|
|
239
|
-
const command =
|
|
235
|
+
const command = truncatePlainText(operation.lock.command, 16);
|
|
240
236
|
return [
|
|
241
237
|
`Running: ${command} (pid ${operation.lock.pid}). Wait, then refresh; Transfer actions and Settings return.`,
|
|
242
238
|
];
|
|
@@ -258,6 +254,11 @@ function operationStatusLines(operation: OperationAvailability): string[] {
|
|
|
258
254
|
}
|
|
259
255
|
}
|
|
260
256
|
|
|
257
|
+
function truncatePlainText(value: string, width: number) {
|
|
258
|
+
const text = safeTerminalText(stripVTControlCharacters(value));
|
|
259
|
+
return stripVTControlCharacters(truncateToWidth(text, width, "…"));
|
|
260
|
+
}
|
|
261
|
+
|
|
261
262
|
export function backendStorageDescription(config: AnySyncConfig) {
|
|
262
263
|
const connection = safeTerminalText(config.connectionName);
|
|
263
264
|
switch (config.backend.type) {
|
package/src/ui/manager-ui.ts
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from "./manager-attention.js";
|
|
14
14
|
import { recoverSyncAccess } from "./manager-recovery.js";
|
|
15
15
|
import { dispatchManagerResult } from "./manager-result-dispatcher.js";
|
|
16
|
-
import {
|
|
16
|
+
import { describeManagerState } from "./manager-state.js";
|
|
17
17
|
import { showSyncSettings } from "./settings-ui.js";
|
|
18
18
|
import { showSyncSetupManager } from "./setup/setup-actions.js";
|
|
19
19
|
import { showSetupSwitcher } from "./setup/setup-switcher.js";
|
|
@@ -52,12 +52,10 @@ export async function showSyncManager(
|
|
|
52
52
|
| "pull"
|
|
53
53
|
| "push"
|
|
54
54
|
| "diff"
|
|
55
|
-
| "status"
|
|
56
55
|
| "setups"
|
|
57
56
|
| "connections"
|
|
58
57
|
| "history"
|
|
59
58
|
| "conflicts"
|
|
60
|
-
| "doctor"
|
|
61
59
|
| "recover"
|
|
62
60
|
| "daemon-recovery"
|
|
63
61
|
| "refresh"
|
|
@@ -69,20 +67,37 @@ export async function showSyncManager(
|
|
|
69
67
|
const directionalAction = async (direction: "push" | "pull", state: State, signal: AbortSignal) => {
|
|
70
68
|
const review = state.manager.configReview;
|
|
71
69
|
if (!review) return { kind: "stay" as const };
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
70
|
+
const run = (intent: "reject-conflicts" | "review-force") =>
|
|
71
|
+
runCancellableOperation(
|
|
72
|
+
ctx,
|
|
73
|
+
intent === "review-force"
|
|
74
|
+
? `Preparing Force ${direction} preview…`
|
|
75
|
+
: direction === "push"
|
|
76
|
+
? "Pushing to remote…"
|
|
77
|
+
: "Pulling from remote…",
|
|
78
|
+
direction,
|
|
79
|
+
runRoute,
|
|
80
|
+
{
|
|
81
|
+
commitAware: true,
|
|
82
|
+
cancelAcrossDialogs: intent === "review-force",
|
|
83
|
+
cancelledMessage: direction === "push" ? "Push cancellation requested." : "Pull cancellation requested.",
|
|
84
|
+
target: review.setupName,
|
|
85
|
+
directional: { fingerprint: review.fingerprint, intent },
|
|
86
|
+
signal,
|
|
87
|
+
isCurrent,
|
|
88
|
+
},
|
|
89
|
+
);
|
|
90
|
+
let result = await run("reject-conflicts");
|
|
91
|
+
if (signal.aborted || !isCurrent()) return { kind: "close" as const };
|
|
92
|
+
if (result.kind === "destination-conflict") {
|
|
93
|
+
const choice = await showDirectionalConflict(menuContext, direction, review.setupName, signal, isCurrent);
|
|
94
|
+
if (signal.aborted || !isCurrent() || choice === "close") return { kind: "close" as const };
|
|
95
|
+
if (choice === "back") return { kind: "stay" as const };
|
|
96
|
+
if (!(await matchesManagerReview(review.fingerprint, signal)))
|
|
97
|
+
return { kind: signal.aborted || !isCurrent() ? ("close" as const) : ("stay" as const) };
|
|
98
|
+
result = await run("review-force");
|
|
99
|
+
if (signal.aborted || !isCurrent()) return { kind: "close" as const };
|
|
100
|
+
}
|
|
86
101
|
const done =
|
|
87
102
|
result.kind === "closed" ||
|
|
88
103
|
(result.kind === "completed" && result.outcome === "applied") ||
|
|
@@ -116,13 +131,11 @@ export async function showSyncManager(
|
|
|
116
131
|
id: item.id,
|
|
117
132
|
label: ctx.mode === "tui" && item.id === "sync" ? "Sync…" : item.label,
|
|
118
133
|
details: [item.description ?? "Review synced content."],
|
|
119
|
-
searchText: `${item.label} ${item.description ?? ""}`,
|
|
120
134
|
disabled: item.disabled,
|
|
121
135
|
disabledReason: item.disabledReason,
|
|
122
136
|
})),
|
|
123
137
|
action: "activate",
|
|
124
|
-
|
|
125
|
-
viewportSize: 5,
|
|
138
|
+
viewportSize: 6,
|
|
126
139
|
hint: "close",
|
|
127
140
|
};
|
|
128
141
|
},
|
|
@@ -211,7 +224,7 @@ export async function showSyncManager(
|
|
|
211
224
|
commitAware: true,
|
|
212
225
|
cancelAcrossDialogs: true,
|
|
213
226
|
target: state.manager.configReview?.setupName,
|
|
214
|
-
cancelledMessage: "History review cancelled
|
|
227
|
+
cancelledMessage: "History review cancelled.",
|
|
215
228
|
});
|
|
216
229
|
return { kind: result.kind === "closed" ? "close" : "stay" };
|
|
217
230
|
},
|
|
@@ -222,38 +235,6 @@ export async function showSyncManager(
|
|
|
222
235
|
});
|
|
223
236
|
return { kind: result.kind === "closed" ? "close" : "stay" };
|
|
224
237
|
},
|
|
225
|
-
status: async ({ state }) => {
|
|
226
|
-
const result = await runCancellableOperation(ctx, "Checking remote status…", "status", runRoute, {
|
|
227
|
-
target: state.manager.configReview?.setupName,
|
|
228
|
-
signal: sessionSignal,
|
|
229
|
-
});
|
|
230
|
-
return { kind: result.kind === "closed" ? "close" : "stay" };
|
|
231
|
-
},
|
|
232
|
-
doctor: async ({ state, signal: actionSignal }) => {
|
|
233
|
-
const signal = sessionSignal ? AbortSignal.any([sessionSignal, actionSignal]) : actionSignal;
|
|
234
|
-
const validate = captureMutationOwner(ctx, signal);
|
|
235
|
-
const config = await loadConfig(state.manager.configReview?.setupName);
|
|
236
|
-
validate();
|
|
237
|
-
const confirmed = await ctx.ui.confirm(
|
|
238
|
-
"Run diagnostics?",
|
|
239
|
-
`Setup: ${safeTerminalText(config.setupName)}\nStorage: ${backendStorageDescription(config)}\nS3/R2 reads the latest pointer without writing. Git reads remote snapshots and checks its cache. WebDAV probes conditional writes and cleanup, and can repair a missing history entry. Possible-secret checks still run. This is not the read-only Check remote status action.`,
|
|
240
|
-
{ signal },
|
|
241
|
-
);
|
|
242
|
-
if (signal.aborted) return { kind: "close" };
|
|
243
|
-
validate();
|
|
244
|
-
if (!confirmed) return { kind: "stay" };
|
|
245
|
-
const latest = await loadConfig();
|
|
246
|
-
validate();
|
|
247
|
-
if (syncCheckConfigFingerprint(config) !== syncCheckConfigFingerprint(latest)) {
|
|
248
|
-
ctx.ui.notify("Setup changed during diagnostics review; reopen Diagnostics.", "warning");
|
|
249
|
-
return { kind: "stay" };
|
|
250
|
-
}
|
|
251
|
-
const result = await runCancellableOperation(ctx, "Checking setup access…", "doctor", runRoute, {
|
|
252
|
-
signal,
|
|
253
|
-
target: config.setupName,
|
|
254
|
-
});
|
|
255
|
-
return { kind: result.kind === "closed" ? "close" : "stay" };
|
|
256
|
-
},
|
|
257
238
|
"daemon-recovery": async ({ signal }) => {
|
|
258
239
|
await runRoute("daemon recover", signal);
|
|
259
240
|
return { kind: "stay" };
|
|
@@ -282,6 +263,21 @@ export async function showSyncManager(
|
|
|
282
263
|
},
|
|
283
264
|
},
|
|
284
265
|
});
|
|
266
|
+
async function matchesManagerReview(fingerprint: string | undefined, signal: AbortSignal, settings = false) {
|
|
267
|
+
try {
|
|
268
|
+
const config = await (settings ? loadSettingsConfig() : loadConfig());
|
|
269
|
+
validateOwner();
|
|
270
|
+
signal.throwIfAborted();
|
|
271
|
+
if (fingerprint === syncCheckConfigFingerprint(config)) return true;
|
|
272
|
+
} catch {
|
|
273
|
+
if (!isCurrent() || signal.aborted) return false;
|
|
274
|
+
}
|
|
275
|
+
ctx.ui.notify(
|
|
276
|
+
"Sync setup changed while the manager was open. Review the refreshed setup before continuing.",
|
|
277
|
+
"warning",
|
|
278
|
+
);
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
285
281
|
// Setup-specific actions must use the configuration shown by this screen, not
|
|
286
282
|
// an active setup selected by another process while the menu was open.
|
|
287
283
|
for (const action of [
|
|
@@ -292,31 +288,15 @@ export async function showSyncManager(
|
|
|
292
288
|
"push",
|
|
293
289
|
"history",
|
|
294
290
|
"diff",
|
|
295
|
-
"status",
|
|
296
|
-
"doctor",
|
|
297
291
|
"conflicts",
|
|
298
292
|
] as const) {
|
|
299
293
|
const activate = menu.actions[action];
|
|
300
294
|
menu.actions[action] = async (invocation) => {
|
|
301
295
|
validateOwner();
|
|
302
296
|
const review = invocation.state.manager.configReview;
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
validateOwner();
|
|
307
|
-
invocation.signal.throwIfAborted();
|
|
308
|
-
current = review?.fingerprint === syncCheckConfigFingerprint(config);
|
|
309
|
-
} catch {
|
|
310
|
-
if (!isCurrent() || invocation.signal.aborted) return { kind: "close" };
|
|
311
|
-
}
|
|
312
|
-
if (!current) {
|
|
313
|
-
ctx.ui.notify(
|
|
314
|
-
"Sync setup changed while the manager was open. Review the refreshed setup before continuing.",
|
|
315
|
-
"warning",
|
|
316
|
-
);
|
|
317
|
-
return { kind: "stay" };
|
|
318
|
-
}
|
|
319
|
-
return activate(invocation);
|
|
297
|
+
const matches = await matchesManagerReview(review?.fingerprint, invocation.signal, action === "settings");
|
|
298
|
+
if (invocation.signal.aborted || !isCurrent()) return { kind: "close" };
|
|
299
|
+
return matches ? activate(invocation) : { kind: "stay" };
|
|
320
300
|
};
|
|
321
301
|
}
|
|
322
302
|
const menuContext: ExtensionCommandContext = {
|
|
@@ -370,6 +350,47 @@ export async function showSyncManager(
|
|
|
370
350
|
});
|
|
371
351
|
}
|
|
372
352
|
|
|
353
|
+
async function showDirectionalConflict(
|
|
354
|
+
ctx: ExtensionCommandContext,
|
|
355
|
+
direction: "push" | "pull",
|
|
356
|
+
setup: string,
|
|
357
|
+
signal: AbortSignal,
|
|
358
|
+
isCurrent: () => boolean,
|
|
359
|
+
): Promise<"review" | "back" | "close"> {
|
|
360
|
+
let selected = false;
|
|
361
|
+
const menu = defineMenu<undefined, "conflict", "choose", ExtensionCommandContext>({
|
|
362
|
+
start: "conflict",
|
|
363
|
+
screens: {
|
|
364
|
+
conflict: () => ({
|
|
365
|
+
kind: "choice",
|
|
366
|
+
title: `${direction === "push" ? "Push" : "Pull"} stopped · ${safeTerminalText(setup)}`,
|
|
367
|
+
lines: [
|
|
368
|
+
direction === "push"
|
|
369
|
+
? "Push would overwrite remote changes since the last accepted sync."
|
|
370
|
+
: "Pull would overwrite local changes since the last accepted sync.",
|
|
371
|
+
"No content was written.",
|
|
372
|
+
],
|
|
373
|
+
items: [
|
|
374
|
+
{ id: "back", label: "Back" },
|
|
375
|
+
{ id: "review", label: `Review Force ${direction}…` },
|
|
376
|
+
],
|
|
377
|
+
action: "choose",
|
|
378
|
+
initialItemId: "back",
|
|
379
|
+
hint: ctx.mode === "rpc" ? "close" : "back",
|
|
380
|
+
}),
|
|
381
|
+
},
|
|
382
|
+
actions: {
|
|
383
|
+
choose: ({ itemId }) => {
|
|
384
|
+
selected = itemId === "review";
|
|
385
|
+
return { kind: "back" };
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
});
|
|
389
|
+
const result = await runMenu(ctx, menu, { getState: () => undefined, signal, isCurrent });
|
|
390
|
+
if (signal.aborted || !isCurrent() || result.kind !== "closed" || result.reason === "close") return "close";
|
|
391
|
+
return selected ? "review" : "back";
|
|
392
|
+
}
|
|
393
|
+
|
|
373
394
|
function syncMainMenuItem(
|
|
374
395
|
label: string,
|
|
375
396
|
): ActionMenuItem<
|
|
@@ -378,14 +399,12 @@ function syncMainMenuItem(
|
|
|
378
399
|
| "pull"
|
|
379
400
|
| "push"
|
|
380
401
|
| "diff"
|
|
381
|
-
| "status"
|
|
382
402
|
| "switch"
|
|
383
403
|
| "settings"
|
|
384
404
|
| "setups"
|
|
385
405
|
| "connections"
|
|
386
406
|
| "history"
|
|
387
407
|
| "conflicts"
|
|
388
|
-
| "doctor"
|
|
389
408
|
| "recover"
|
|
390
409
|
| "daemon-recovery"
|
|
391
410
|
| "refresh"
|
|
@@ -397,11 +416,9 @@ function syncMainMenuItem(
|
|
|
397
416
|
"Pull from remote": "pull",
|
|
398
417
|
"Push to remote": "push",
|
|
399
418
|
"View differences": "diff",
|
|
400
|
-
"Check remote status": "status",
|
|
401
419
|
"Switch sync setup": "switch",
|
|
402
420
|
Settings: "settings",
|
|
403
421
|
History: "history",
|
|
404
|
-
Diagnostics: "doctor",
|
|
405
422
|
"Review unresolved conflicts": "conflicts",
|
|
406
423
|
"Restore sync access… (recommended)": "recover",
|
|
407
424
|
"Stop daemon for recovery…": "daemon-recovery",
|
|
@@ -420,13 +437,11 @@ function syncMainMenuItem(
|
|
|
420
437
|
action,
|
|
421
438
|
description: {
|
|
422
439
|
sync: "Merge changes on both sides.",
|
|
423
|
-
pull: "Remote → this device;
|
|
424
|
-
push: "This device → remote;
|
|
440
|
+
pull: "Remote → this device; stops before overwriting local changes.",
|
|
441
|
+
push: "This device → remote; stops before overwriting remote changes.",
|
|
425
442
|
diff: "Inspect changes; no transfer.",
|
|
426
|
-
status: "Check remote; no transfer.",
|
|
427
443
|
settings: "Edit settings, setups, and storage connections.",
|
|
428
|
-
history: "Review snapshots and
|
|
429
|
-
doctor: "Review backend diagnostics.",
|
|
444
|
+
history: "Review snapshots and recovery options.",
|
|
430
445
|
switch: "Choose another sync setup.",
|
|
431
446
|
conflicts: "Review unresolved file groups.",
|
|
432
447
|
recover: "Review local lock recovery.",
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
|
|
3
|
-
/** Track History's Pi-owned selector/confirmation lifetime without inspecting renderer internals. */
|
|
4
3
|
export function trackOperationDialogs<Context extends ExtensionContext>(
|
|
5
4
|
ctx: Context,
|
|
6
5
|
onDialog?: (active: boolean) => void,
|
|
@@ -18,6 +17,7 @@ export function trackOperationDialogs<Context extends ExtensionContext>(
|
|
|
18
17
|
...ctx.ui,
|
|
19
18
|
select: (...args) => runDialog(() => ctx.ui.select(...args)),
|
|
20
19
|
confirm: (...args) => runDialog(() => ctx.ui.confirm(...args)),
|
|
20
|
+
custom: (factory, options) => runDialog(() => ctx.ui.custom(factory, options)),
|
|
21
21
|
};
|
|
22
22
|
// Forward live context properties: copying the context would hide session
|
|
23
23
|
// replacement from mutation-owner revalidation after a dialog settles.
|
package/src/ui/settings-ui.ts
CHANGED
|
@@ -283,7 +283,7 @@ export async function showSyncSettings(
|
|
|
283
283
|
id: "skipSecretScan",
|
|
284
284
|
label: "Skip secret scan",
|
|
285
285
|
description:
|
|
286
|
-
"All setups on this device: skip possible-secret checks on subsequent pushes, including automatic pushes. Other safety checks remain.
|
|
286
|
+
"All setups on this device: skip possible-secret checks on subsequent pushes, including automatic pushes. Other push safety checks remain.",
|
|
287
287
|
currentValue: state.skipSecretScan ? "On" : "Off",
|
|
288
288
|
values: ["On", "Off"],
|
|
289
289
|
action: "skip-secret-scan",
|
|
@@ -300,8 +300,7 @@ export async function showSyncSettings(
|
|
|
300
300
|
{
|
|
301
301
|
id: "debug",
|
|
302
302
|
label: "Debug mode",
|
|
303
|
-
description:
|
|
304
|
-
"Write startup timings and sync events to the local pi-sync.log. Pi applies this at the next session start; the daemon applies it at its next settings check.",
|
|
303
|
+
description: "Next session: log to pi-sync.log and let the model recheck remote storage without asking.",
|
|
305
304
|
currentValue: state.debug ? "On" : "Off",
|
|
306
305
|
values: ["On", "Off"],
|
|
307
306
|
action: "debug",
|
|
@@ -43,7 +43,7 @@ export async function showWebDavSetup(ctx: ExtensionCommandContext, targetName:
|
|
|
43
43
|
"Username and password: stored privately (values hidden)",
|
|
44
44
|
...policy.lines,
|
|
45
45
|
`Automatic sync: ${automaticSyncSummary(policy.sync.automatic)}`,
|
|
46
|
-
"
|
|
46
|
+
"Before publishing a snapshot, Pi Sync checks WebDAV conditional writes with a temporary probe.",
|
|
47
47
|
"Saving does not contact remote storage or start syncing.",
|
|
48
48
|
],
|
|
49
49
|
"Save setup",
|