@narumitw/pi-sync 0.57.12 → 0.58.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/CHANGELOG.md +16 -0
- package/README.md +5 -1
- package/dist/chunks/{agent-sync-P6AWQXGK.ts → agent-sync-2R4GG2MF.ts} +3 -3
- package/dist/chunks/{chunk-ZDDBZH72.ts → chunk-JYILGR3K.ts} +2 -2
- package/dist/chunks/{chunk-OKPPZA4D.ts → chunk-MG66XM5U.ts} +3 -3
- package/dist/chunks/{chunk-OKPPZA4D.ts.map → chunk-MG66XM5U.ts.map} +2 -2
- package/dist/chunks/{chunk-Q23JJW7E.ts → chunk-REMGB255.ts} +32 -11
- package/dist/chunks/chunk-REMGB255.ts.map +7 -0
- package/dist/chunks/{chunk-ZC3IHFNM.ts → chunk-WQMYV4DW.ts} +3 -3
- package/dist/chunks/chunk-WQMYV4DW.ts.map +7 -0
- package/dist/chunks/chunk-YIPK23JW.ts +171 -0
- package/dist/chunks/chunk-YIPK23JW.ts.map +7 -0
- package/dist/chunks/{command-handler-VKLZBRLO.ts → command-handler-MRXE5AKK.ts} +7 -6
- package/dist/chunks/{command-handler-VKLZBRLO.ts.map → command-handler-MRXE5AKK.ts.map} +2 -2
- package/dist/chunks/{continuous-sync-TTOSJCQU.ts → continuous-sync-FAFNLEUW.ts} +18 -10
- package/dist/chunks/continuous-sync-FAFNLEUW.ts.map +7 -0
- package/dist/chunks/{manager-result-dispatcher-6W52NM7F.ts → manager-result-dispatcher-XCYPW7RC.ts} +4 -4
- package/dist/chunks/{manager-ui-INVMAFEN.ts → manager-ui-AY34N4UY.ts} +8 -8
- package/dist/chunks/{remote-selection-ui-TD4C4W3J.ts → remote-selection-ui-MYM2YCPF.ts} +3 -3
- package/dist/chunks/{sync-operations-TMGQHBF5.ts → sync-operations-45APGOL3.ts} +6 -6
- package/dist/chunks/sync-operations-45APGOL3.ts.map +7 -0
- package/dist/index.ts +78 -63
- package/dist/index.ts.map +2 -2
- package/docs/tui-contract.md +37 -0
- package/package.json +2 -2
- package/skills/configure-pi-sync/references/configuration.md +13 -1
- package/src/commands/command-handler.ts +1 -0
- package/src/sync/agent-sync.ts +1 -1
- package/src/sync/continuous-sync.ts +15 -6
- package/src/sync/startup-check.ts +1 -1
- package/src/sync/sync-mutations.ts +2 -2
- package/src/sync/sync-queries.ts +2 -2
- package/src/sync-extension.ts +71 -57
- package/src/ui/remote-selection-ui.ts +1 -1
- package/src/ui/sync-attention.ts +36 -12
- package/src/ui/sync-status.ts +214 -3
- package/dist/chunks/chunk-K3RIEL6J.ts +0 -20
- package/dist/chunks/chunk-K3RIEL6J.ts.map +0 -7
- package/dist/chunks/chunk-Q23JJW7E.ts.map +0 -7
- package/dist/chunks/chunk-ZC3IHFNM.ts.map +0 -7
- package/dist/chunks/continuous-sync-TTOSJCQU.ts.map +0 -7
- package/dist/chunks/sync-operations-TMGQHBF5.ts.map +0 -7
- /package/dist/chunks/{agent-sync-P6AWQXGK.ts.map → agent-sync-2R4GG2MF.ts.map} +0 -0
- /package/dist/chunks/{chunk-ZDDBZH72.ts.map → chunk-JYILGR3K.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-6W52NM7F.ts.map → manager-result-dispatcher-XCYPW7RC.ts.map} +0 -0
- /package/dist/chunks/{manager-ui-INVMAFEN.ts.map → manager-ui-AY34N4UY.ts.map} +0 -0
- /package/dist/chunks/{remote-selection-ui-TD4C4W3J.ts.map → remote-selection-ui-MYM2YCPF.ts.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @narumitw/pi-sync
|
|
2
2
|
|
|
3
|
+
## 0.58.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- cf7b63d: Put editor widget names and short current count/state summaries in their divider lines. Remove duplicate body titles while retaining safety text, detail rows, privacy modes, and standalone RPC/tool output. In fullscreen Pi, click anywhere in a widget to collapse it to one named line, then click that line to restore the latest content. Preserve independent, session-local disclosure through updates without taking editor focus, changing domain data, or stopping background work. Existing owner controls provide keyboard restoration; regular-mode mouse input remains terminal-owned.
|
|
8
|
+
|
|
9
|
+
The Kit minor release supplies the named widget state and publisher disclosure APIs. Changesets raises all adopting consumers' Kit dependency floors in the same Version PR. Publish and verify the exact Kit artifact before its consumers.
|
|
10
|
+
- Updated dependencies [cf7b63d]
|
|
11
|
+
- @narumitw/pi-tui-kit@0.70.0
|
|
12
|
+
|
|
13
|
+
## 0.58.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- 379ebee: Add optional, extension-neutral status metadata v1 and a quiet footer presentation. Hide normal standby, shorten activity markers, and retain safe retry and blocked reasons while preserving configured icons and readable raw-status fallback. Keep sync authorization, scheduling, request limits, settings, notifications, and recovery behavior unchanged.
|
|
18
|
+
|
|
3
19
|
## 0.57.12
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -150,6 +150,8 @@ Back returns to the sync manager, and Ctrl+C closes the complete flow.
|
|
|
150
150
|
Startup checks never open a dialog. While checking, TUI and RPC status show **sync ...**. With a sync baseline and no content-list mismatch, they use **sync ⇡** for local changes to push and **sync ⇣** for remote changes to pull. Review conditions use **sync ⇕**; in TUI, a persistent widget above the editor also identifies both sides changing, first sync with an existing remote snapshot, a differing content list (including order-only differences), or a missing remote snapshot despite an existing baseline. Both sides changing is a reason to review, not a confirmed file conflict.
|
|
151
151
|
No selected content and first sync with an empty remote stay quiet outside `/sync`, which provides setup or initialization guidance. Legacy remote metadata without an authoritative content list does not independently trigger a widget for observation-only checks. With **Startup transfer** enabled, an established legacy remote instead shows review attention and requires an explicit direction to adopt the content policy; no automatic transfer runs. An included-content mismatch puts **Review synced content (recommended)** in the manager, where a fresh review verifies the remote snapshot before offering changes.
|
|
152
152
|
Check results are advisory observations against the last sync baseline, not proof of a file conflict or current equality. Opening the manager uses local information and shows when the check completed; it does not contact remote storage. Transfer actions recheck current content.
|
|
153
|
+
In fullscreen TUI mode, click anywhere in **Sync** to collapse or expand the widget without moving keyboard focus. Attention updates keep the collapse state. Open and close `/sync` to restore the body with the keyboard; a new session resets the state.
|
|
154
|
+
|
|
153
155
|
The widget has no expiry timer. Attention stays in memory and is invalidated by relevant settings/state changes or a foreground transfer's commit boundary, and cleared on session replacement or shutdown. A newer observation replaces the presentation, clearing the widget when only status or no reminder is needed. Cancelling a review or a failure before commit preserves a still-valid observation and its appropriate presentation.
|
|
154
156
|
|
|
155
157
|
Interactive TUI `/sync sync`, `/sync pull`, and `/sync push` routes without `--yes` open the same review flow when they detect the mismatch.
|
|
@@ -228,6 +230,8 @@ Partial sync keeps each side's unresolved versions, preserves their previous acc
|
|
|
228
230
|
|
|
229
231
|
**Settings → Show sync status** defaults to **On**. Turning it Off immediately clears and suppresses pi-sync status text for background checks, transfers, and review attention; widgets and notifications remain available.
|
|
230
232
|
|
|
233
|
+
With a footer that supports the [public semantic status protocol](https://github.com/narumiruna/pi-extensions/blob/main/packages/pi-statusline/docs/extension-status-protocol.md), normal standby—including another local monitoring owner—is hidden. Pi Statusline shows short static markers for checking, transfers, model resolution, and review, while retry/blocked states keep short reasons. Configured icons remain effective. Native Pi footers, RPC observers, and older or absent consumers retain the existing readable raw status; Sync needs no other extension to operate. See [Status display](./skills/configure-pi-sync/references/configuration.md#status-display) for reason labels and unchanged recovery behavior.
|
|
234
|
+
|
|
231
235
|
**Settings → Skip secret scan** defaults to **Off**; enable it only after reviewing the destination and selected content because it disables push scanning for every setup.
|
|
232
236
|
See [Secret scanning](./skills/configure-pi-sync/references/configuration.md#secret-scanning) for the setting and diagnostic behavior.
|
|
233
237
|
|
|
@@ -369,7 +373,7 @@ Preserve both roots before manual recovery; with every Pi process closed and no
|
|
|
369
373
|
Pi exposes terminal components rather than a semantic or ARIA tree.
|
|
370
374
|
Release checks cover textual state, keyboard operation, Escape and Back behavior, control escaping, and narrow rendering.
|
|
371
375
|
Critical meaning appears in text such as `(current)`, `Review needed`, `No startup transfer`, `Warning`, `Invalid`, `Saved`, `Cancelled`, and `Applied`.
|
|
372
|
-
Color is supplementary
|
|
376
|
+
Color is supplementary. The attention widget's mouse control changes only its presentation; `/sync` provides keyboard access to review actions.
|
|
373
377
|
|
|
374
378
|
## 🗂️ Package layout
|
|
375
379
|
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
|
|
3
3
|
import {
|
|
4
4
|
withAgentSyncLock
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-WQMYV4DW.ts";
|
|
6
6
|
import "./chunk-3ST7RSYN.ts";
|
|
7
|
-
import "./chunk-
|
|
7
|
+
import "./chunk-YIPK23JW.ts";
|
|
8
8
|
import "./chunk-6O3EDBRL.ts";
|
|
9
9
|
import "./chunk-PWMWOJP4.ts";
|
|
10
10
|
import "./chunk-DN4IA7MR.ts";
|
|
@@ -19,4 +19,4 @@ import "./chunk-PRUEIIK7.ts";
|
|
|
19
19
|
export {
|
|
20
20
|
withAgentSyncLock
|
|
21
21
|
};
|
|
22
|
-
//# sourceMappingURL=agent-sync-
|
|
22
|
+
//# sourceMappingURL=agent-sync-2R4GG2MF.ts.map
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import {
|
|
4
4
|
runCancellableOperation,
|
|
5
5
|
showRemoteSelectionReview
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-MG66XM5U.ts";
|
|
7
7
|
import {
|
|
8
8
|
safeTerminalText
|
|
9
9
|
} from "./chunk-AMJRUXFT.ts";
|
|
@@ -206,4 +206,4 @@ async function dispatchManagerResult(ctx, initialResult, origin, runRoute, signa
|
|
|
206
206
|
export {
|
|
207
207
|
dispatchManagerResult
|
|
208
208
|
};
|
|
209
|
-
//# sourceMappingURL=chunk-
|
|
209
|
+
//# sourceMappingURL=chunk-JYILGR3K.ts.map
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
} from "./chunk-AMJRUXFT.ts";
|
|
19
19
|
import {
|
|
20
20
|
setSyncStatus
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-YIPK23JW.ts";
|
|
22
22
|
import {
|
|
23
23
|
errorMessage
|
|
24
24
|
} from "./chunk-7D5SF7P3.ts";
|
|
@@ -521,7 +521,7 @@ async function inspectConfiguredRemoteSelection(ctx, setupName, signal, factory,
|
|
|
521
521
|
const config = await loadConfig(setupName);
|
|
522
522
|
if (signal?.aborted) return void 0;
|
|
523
523
|
validateOwner();
|
|
524
|
-
setSyncStatus(ctx, `checking synced content for ${safeTerminalText(config.setupName)}
|
|
524
|
+
setSyncStatus(ctx, `checking synced content for ${safeTerminalText(config.setupName)}`, { activity: "checking" });
|
|
525
525
|
const backend = await factory(config);
|
|
526
526
|
if (signal?.aborted) return void 0;
|
|
527
527
|
validateOwner();
|
|
@@ -684,4 +684,4 @@ export {
|
|
|
684
684
|
runCancellableOperation,
|
|
685
685
|
showRemoteSelectionReview
|
|
686
686
|
};
|
|
687
|
-
//# sourceMappingURL=chunk-
|
|
687
|
+
//# sourceMappingURL=chunk-MG66XM5U.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/ui/remote-selection-ui.ts", "../../src/ui/cancellable-operation.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { defineMenu, runMenu } from \"@narumitw/pi-tui-kit\";\nimport { createSyncBackend, type SyncBackendFactory } from \"../backends/backend-factory.js\";\nimport type { RemoteHead, SyncBackend } from \"../backends/sync-backend.js\";\nimport { loadConfig, syncCheckConfigFingerprint, syncConfigReviewFingerprint } from \"../settings/config.js\";\nimport { SyncSetupReviewChangedError, updateSyncSetup } from \"../settings/settings-management.js\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport { readSnapshotForHead } from \"../sync/remote-snapshot.js\";\nimport { throwIfAborted } from \"../sync/signals.js\";\nimport { errorMessage } from \"../sync/sync-errors.js\";\nimport { captureMutationOwner } from \"../sync/sync-local.js\";\nimport {\n compareSyncInclude,\n inspectRemoteSelection,\n type RemoteSelectionDecision,\n type RemoteSelectionState,\n sameSyncInclude,\n} from \"../sync/sync-policy.js\";\nimport {\n type RunRoute,\n type RunRouteResult,\n runCancellableOperation,\n runCancellableTask,\n} from \"./cancellable-operation.js\";\nimport { setSyncStatus } from \"./sync-status.js\";\nimport { safeTerminalText } from \"./terminal-text.js\";\n\nexport type RemoteSelectionOrigin = \"settings\" | \"sync\" | \"pull\" | \"push\";\n\nexport interface RemoteSelectionReviewOptions {\n decision?: RemoteSelectionDecision;\n origin?: RemoteSelectionOrigin;\n runRoute?: RunRoute;\n cancelLabel?: string;\n /** The explicit mismatch is resolved or superseded; this does not imply file equality. */\n onSelectionResolved?: () => void;\n withStateAccess?: <T>(task: () => Promise<T>) => Promise<T>;\n}\n\nexport type RemoteSelectionReviewResult =\n | { kind: \"back\" }\n | { kind: \"closed\" }\n | { kind: \"done\" }\n | { kind: \"stale\" }\n | { kind: \"route-result\"; result: RunRouteResult; route: \"sync\" | \"pull\" | \"push\" };\n\nexport async function showRemoteSelectionReview(\n ctx: ExtensionContext,\n setupName?: string,\n signal?: AbortSignal,\n factory: SyncBackendFactory = createSyncBackend,\n options: RemoteSelectionReviewOptions = {},\n): Promise<RemoteSelectionReviewResult> {\n const validateOwner = captureMutationOwner(ctx, signal);\n const isCurrent = () => isReviewOwnerCurrent(validateOwner);\n try {\n validateOwner();\n let decision = options.decision;\n if (!decision) {\n const inspection = await runCancellableTask(\n ctx,\n \"Checking remote content list\u2026\",\n (workSignal) => inspectConfiguredRemoteSelection(ctx, setupName, workSignal, factory, validateOwner),\n { signal, isCurrent, cancelledMessage: null },\n );\n if (!isCurrent()) return { kind: \"stale\" };\n if (inspection.kind !== \"completed\") return { kind: inspection.kind === \"cancelled\" ? \"back\" : \"closed\" };\n validateOwner();\n const inspected = inspection.value;\n if (!inspected) return { kind: \"stale\" };\n // A successful fresh read can supersede an old explicit mismatch without\n // changing local settings. This is not user cancellation or proof of file equality.\n if (inspected.kind === \"empty\" || inspected.state.kind !== \"different\") {\n options.onSelectionResolved?.();\n }\n if (inspected.kind === \"empty\") {\n ctx.ui.notify(\"Remote storage has no snapshot or synced-content list yet.\", \"info\");\n return { kind: \"back\" };\n }\n if (inspected.state.kind === \"same\") {\n ctx.ui.notify(\"Remote synced content already matches this sync setup.\", \"info\");\n return { kind: \"back\" };\n }\n if (inspected.state.kind === \"legacy\") {\n if (ctx.mode !== \"tui\") {\n ctx.ui.notify(formatLegacySummary(inspected.config, inspected.state.discovered), \"info\");\n return { kind: \"back\" };\n }\n await showLegacyDiscovery(ctx, inspected.config, inspected.state.discovered, signal);\n return signal?.aborted ? { kind: \"stale\" } : { kind: \"back\" };\n }\n decision = decisionFromState(inspected.config, inspected.state);\n }\n\n if (ctx.mode !== \"tui\") {\n ctx.ui.notify(formatRemoteSelectionSummary(decision), \"warning\");\n return { kind: \"back\" };\n }\n\n let currentDecision = decision;\n for (;;) {\n if (signal?.aborted) return { kind: \"stale\" };\n const result = await showSelectionDifference(\n ctx,\n currentDecision,\n options.origin ?? \"settings\",\n options.runRoute,\n signal,\n factory,\n options,\n validateOwner,\n );\n if (result.kind !== \"refresh\") return result;\n const refresh = await runCancellableTask(\n ctx,\n \"Refreshing remote content list\u2026\",\n (workSignal) =>\n runWithOptionalStateAccess(options, () =>\n inspectConfiguredRemoteSelection(ctx, currentDecision.setupName, workSignal, factory, validateOwner),\n ),\n { signal, isCurrent, cancelledMessage: null },\n );\n if (!isCurrent()) return { kind: \"stale\" };\n if (refresh.kind !== \"completed\") return { kind: refresh.kind === \"cancelled\" ? \"back\" : \"closed\" };\n validateOwner();\n const refreshed = refresh.value;\n if (!refreshed) return { kind: \"stale\" };\n if (refreshed.kind === \"empty\") {\n options.onSelectionResolved?.();\n ctx.ui.notify(\"Remote storage no longer has a snapshot or synced-content list.\", \"warning\");\n return { kind: \"back\" };\n }\n if (refreshed.state.kind !== \"different\") {\n ctx.ui.notify(\n refreshed.state.kind === \"same\"\n ? \"Remote synced content now matches this sync setup.\"\n : \"The refreshed legacy snapshot has no authoritative synced-content list.\",\n \"info\",\n );\n options.onSelectionResolved?.();\n return { kind: \"done\" };\n }\n currentDecision = decisionFromState(refreshed.config, refreshed.state);\n }\n } catch (error) {\n if (!isCurrent()) return { kind: \"stale\" };\n ctx.ui.notify(`Could not review synced content: ${errorMessage(error)}`, \"error\");\n return { kind: \"back\" };\n } finally {\n if (isCurrent()) setSyncStatus(ctx, undefined);\n }\n}\n\ntype DifferenceFlowResult = RemoteSelectionReviewResult | { kind: \"refresh\" };\n\nasync function showSelectionDifference(\n ctx: ExtensionContext,\n initialDecision: RemoteSelectionDecision,\n origin: RemoteSelectionOrigin,\n runRoute: RunRoute | undefined,\n sessionSignal: AbortSignal | undefined,\n factory: SyncBackendFactory,\n options: Pick<RemoteSelectionReviewOptions, \"cancelLabel\" | \"onSelectionResolved\" | \"withStateAccess\">,\n validateOwner: () => void,\n): Promise<DifferenceFlowResult> {\n type Screen = \"choice\" | \"review\" | \"saved\";\n type Action = \"adopt\" | \"keep\" | \"cancel\" | \"continue\" | \"done\";\n interface FlowState {\n decision: RemoteSelectionDecision;\n saved: boolean;\n }\n const isCurrent = () => isReviewOwnerCurrent(validateOwner);\n let flowState: FlowState = { decision: initialDecision, saved: false };\n let continuationFingerprint: string | undefined;\n let nextResult: RemoteSelectionReviewResult | undefined;\n let refreshRequested = false;\n const route = origin === \"settings\" ? \"sync\" : origin;\n const menu = defineMenu<FlowState, Screen, Action, ExtensionContext>({\n start: \"choice\",\n screens: {\n choice: ({ state }) => ({\n kind: \"actions\",\n title: \"Synced content differs\",\n lines: selectionSummaryLines(state.decision),\n items: [\n {\n id: \"review\",\n label: \"Review all paths (recommended)\",\n description: \"Compare exact remote-only, device-only, and ordered lists.\",\n to: \"review\",\n },\n {\n id: \"adopt\",\n label: \"Use remote content list\",\n description: \"Save the reviewed list on this device without pulling files.\",\n action: \"adopt\",\n },\n {\n id: \"keep\",\n label: \"Keep this device's content list and update remote\u2026\",\n description: \"Open the existing exact force-push preview without skipping confirmation.\",\n action: \"keep\",\n },\n { id: \"cancel\", label: options.cancelLabel ?? \"Cancel\", action: \"cancel\" },\n ],\n hint: \"back\",\n }),\n review: ({ state }) => ({\n kind: \"review\",\n title: `Review synced content \u00B7 ${safeTerminalText(state.decision.setupName)}`,\n content: formatSelectionDifference(state.decision),\n format: { kind: \"text\" },\n viewportSize: \"adaptive\",\n hint: \"back\",\n }),\n saved: ({ state }) => ({\n kind: \"actions\",\n title: \"Remote content list saved\",\n lines: [\n `Sync setup: ${safeTerminalText(state.decision.setupName)}`,\n \"Only the included-content setting was saved.\",\n \"No files were pulled and sync state was not changed.\",\n ],\n items: [\n ...(runRoute\n ? [\n {\n id: \"continue\",\n label: continueLabel(origin),\n description: \"Start a fresh check and exact preview for this sync setup.\",\n action: \"continue\" as const,\n },\n ]\n : []),\n { id: \"done\", label: \"Done\", action: \"done\" },\n ],\n hint: \"close\",\n }),\n },\n actions: {\n adopt: async ({ state, signal: actionSignal }) => {\n const signal = combineSignals(sessionSignal, actionSignal);\n try {\n const adoption = await runCancellableTask(\n ctx,\n \"Checking and saving remote content list\u2026\",\n async (workSignal, _onCommit, onDialog) => {\n const ownedSignal = workSignal ?? signal;\n const currentConfig = await loadConfig(state.decision.setupName);\n ownedSignal.throwIfAborted();\n validateOwner();\n assertLocalSelectionCurrent(currentConfig, state.decision);\n if (!currentConfig.include.includes(\"sessions\") && state.decision.remoteInclude.includes(\"sessions\")) {\n onDialog?.(true);\n let acknowledged: boolean;\n try {\n acknowledged = await ctx.ui.confirm(\n \"Use a content list that includes session conversations?\",\n \"Session JSONL may contain prompts, tool output, file paths, images, and secrets. This saves the list only; it does not pull files.\",\n { signal: ownedSignal },\n );\n } finally {\n onDialog?.(false);\n }\n ownedSignal.throwIfAborted();\n validateOwner();\n if (!acknowledged) return undefined;\n }\n return runWithOptionalStateAccess(options, async () => {\n const loaded = await loadAdoptionReview(state.decision, ownedSignal, factory, validateOwner);\n ownedSignal.throwIfAborted();\n validateOwner();\n await revalidateAndAdopt(loaded, state.decision, ownedSignal, validateOwner);\n return loaded;\n });\n },\n {\n signal,\n isCurrent,\n cancelAcrossDialogs: true,\n cancelledMessage: \"Remote content-list adoption cancelled.\",\n },\n );\n if (signal.aborted || adoption.kind === \"closed\") return { kind: \"close\" as const };\n if (adoption.kind === \"cancelled\" || !adoption.value) return { kind: \"stay\" as const };\n validateOwner();\n options.onSelectionResolved?.();\n continuationFingerprint = syncCheckConfigFingerprint({\n ...adoption.value.config,\n include: [...state.decision.remoteInclude],\n });\n flowState = { decision: state.decision, saved: true };\n return { kind: \"to\" as const, screen: \"saved\" as const };\n } catch (error) {\n if (signal.aborted || !isCurrent()) return { kind: \"close\" as const };\n if (isStaleReviewError(error)) {\n ctx.ui.notify(`${errorMessage(error)} Refreshing the comparison.`, \"warning\");\n refreshRequested = true;\n return { kind: \"close\" as const };\n }\n ctx.ui.notify(`Could not save the remote content list: ${errorMessage(error)}`, \"error\");\n return { kind: \"stay\" as const };\n }\n },\n keep: async ({ state, signal: actionSignal }) => {\n if (!runRoute) {\n ctx.ui.notify(\"The reviewed update-remote route is unavailable.\", \"error\");\n return { kind: \"stay\" as const };\n }\n const signal = combineSignals(sessionSignal, actionSignal);\n try {\n const latest = await loadConfig(state.decision.setupName);\n if (signal.aborted) return { kind: \"close\" as const };\n validateOwner();\n assertLocalSelectionCurrent(latest, state.decision);\n const result = await runCancellableOperation(\n ctx,\n \"Preparing this device's push preview\u2026\",\n \"push --force\",\n runRoute,\n {\n commitAware: true,\n cancelledMessage: \"Push preparation cancelled; no remote files were changed.\",\n target: state.decision.setupName,\n signal,\n },\n );\n return handleNestedRouteResult(result, \"push\");\n } catch (error) {\n if (signal.aborted || !isCurrent()) return { kind: \"close\" as const };\n if (isStaleReviewError(error)) {\n ctx.ui.notify(`${errorMessage(error)} Refreshing the comparison.`, \"warning\");\n refreshRequested = true;\n return { kind: \"close\" as const };\n }\n ctx.ui.notify(`Could not prepare the remote update: ${errorMessage(error)}`, \"error\");\n return { kind: \"stay\" as const };\n }\n },\n continue: async ({ state, signal: actionSignal }) => {\n if (!runRoute || !continuationFingerprint) return { kind: \"stay\" as const };\n const signal = combineSignals(sessionSignal, actionSignal);\n try {\n const latest = await loadConfig(state.decision.setupName);\n if (signal.aborted) return { kind: \"close\" as const };\n validateOwner();\n if (syncCheckConfigFingerprint(latest) !== continuationFingerprint) {\n throw new StaleRemoteSelectionReviewError(\n `Sync setup \u201C${safeTerminalText(state.decision.setupName)}\u201D changed after the remote content list was saved.`,\n );\n }\n const result = await runCancellableOperation(ctx, continueBusyLabel(origin), route, runRoute, {\n commitAware: true,\n cancelledMessage: continuationCancelledMessage(route),\n target: state.decision.setupName,\n signal,\n });\n return handleNestedRouteResult(result, route);\n } catch (error) {\n if (signal.aborted || !isCurrent()) return { kind: \"close\" as const };\n ctx.ui.notify(`Could not continue: ${errorMessage(error)}`, \"error\");\n return { kind: \"stay\" as const };\n }\n },\n cancel: async () => ({ kind: \"back\" }),\n done: async () => {\n nextResult = { kind: \"done\" };\n return { kind: \"close\" };\n },\n },\n });\n\n function handleNestedRouteResult(\n result: Awaited<ReturnType<typeof runCancellableOperation>>,\n nestedRoute: \"sync\" | \"pull\" | \"push\",\n ) {\n if (result.kind === \"completed\" && result.outcome === \"applied\") {\n options.onSelectionResolved?.();\n }\n if (result.kind === \"closed\") {\n nextResult = { kind: \"closed\" };\n return { kind: \"close\" as const };\n }\n if (\n result.kind === \"cancelled\" ||\n (result.kind === \"completed\" && result.outcome === \"cancelled\") ||\n result.kind === \"failed\"\n ) {\n return { kind: \"stay\" as const };\n }\n nextResult = { kind: \"route-result\", result, route: nestedRoute };\n return { kind: \"close\" as const };\n }\n\n const menuResult = await runMenu(ctx, menu, {\n getState: () => flowState,\n signal: sessionSignal,\n isCurrent,\n onError: (_menuCtx, error) => ctx.ui.notify(errorMessage(error), \"error\"),\n });\n if (!isCurrent() || menuResult.kind === \"stale\") return { kind: \"stale\" };\n if (refreshRequested) return { kind: \"refresh\" };\n if (nextResult) return nextResult;\n if (menuResult.kind === \"closed\") {\n return menuResult.reason === \"back\" ? { kind: \"back\" } : { kind: \"closed\" };\n }\n return { kind: \"closed\" };\n}\n\ninterface AdoptionReview {\n config: AnySyncConfig;\n backend: SyncBackend;\n reviewedHead: RemoteHead;\n}\n\nasync function loadAdoptionReview(\n decision: RemoteSelectionDecision,\n signal: AbortSignal,\n factory: SyncBackendFactory,\n validateOwner: () => void,\n): Promise<AdoptionReview> {\n const config = await loadConfig(decision.setupName);\n throwIfAborted(signal);\n validateOwner();\n assertLocalSelectionCurrent(config, decision);\n const backend = await factory(config);\n throwIfAborted(signal);\n validateOwner();\n const reviewedHead = await backend.readHead(signal);\n throwIfAborted(signal);\n validateOwner();\n if (!reviewedHead) {\n throw new StaleRemoteSelectionReviewError(\"Remote storage changed while the comparison was open.\");\n }\n const snapshot = await readSnapshotForHead(backend, reviewedHead, signal);\n throwIfAborted(signal);\n validateOwner();\n const state = inspectRemoteSelection(config.include, snapshot);\n if (state.kind !== \"different\" || !sameSyncInclude(state.include, decision.remoteInclude)) {\n throw new StaleRemoteSelectionReviewError(\"Remote synced content changed while the comparison was open.\");\n }\n return { config, backend, reviewedHead };\n}\n\nasync function revalidateAndAdopt(\n review: AdoptionReview,\n decision: RemoteSelectionDecision,\n signal: AbortSignal,\n validateOwner: () => void,\n) {\n const currentHead = await review.backend.readHead(signal);\n throwIfAborted(signal);\n validateOwner();\n if (!currentHead || !review.backend.sameRevision(review.reviewedHead.revision, currentHead.revision)) {\n throw new StaleRemoteSelectionReviewError(\"Remote storage changed while the comparison was open.\");\n }\n const currentSnapshot = await readSnapshotForHead(review.backend, currentHead, signal);\n throwIfAborted(signal);\n validateOwner();\n const currentState = inspectRemoteSelection(review.config.include, currentSnapshot);\n if (currentState.kind !== \"different\" || !sameSyncInclude(currentState.include, decision.remoteInclude)) {\n throw new StaleRemoteSelectionReviewError(\"Remote synced content changed while the comparison was open.\");\n }\n await updateSyncSetup(\n decision.setupName,\n (setup) => {\n validateOwner();\n return { ...setup, sync: { ...setup.sync, include: [...decision.remoteInclude] } };\n },\n {\n expectedConfigFingerprint: syncCheckConfigFingerprint(review.config),\n expectedInclude: decision.localInclude,\n signal,\n },\n );\n}\n\nasync function inspectConfiguredRemoteSelection(\n ctx: ExtensionContext,\n setupName: string | undefined,\n signal: AbortSignal | undefined,\n factory: SyncBackendFactory,\n validateOwner: () => void,\n): Promise<\n | { kind: \"empty\"; config: AnySyncConfig }\n | { kind: \"selection\"; config: AnySyncConfig; state: RemoteSelectionState }\n | undefined\n> {\n const config = await loadConfig(setupName);\n if (signal?.aborted) return undefined;\n validateOwner();\n setSyncStatus(ctx, `checking synced content for ${safeTerminalText(config.setupName)}`);\n const backend = await factory(config);\n if (signal?.aborted) return undefined;\n validateOwner();\n const head = await backend.readHead(signal);\n if (signal?.aborted) return undefined;\n validateOwner();\n if (!head) return { kind: \"empty\", config };\n const snapshot = await readSnapshotForHead(backend, head, signal);\n if (signal?.aborted) return undefined;\n validateOwner();\n return {\n kind: \"selection\",\n config,\n state: inspectRemoteSelection(config.include, snapshot),\n };\n}\n\nasync function showLegacyDiscovery(\n ctx: ExtensionContext,\n config: AnySyncConfig,\n discovered: string[],\n signal?: AbortSignal,\n) {\n const menu = defineMenu<undefined, \"choice\" | \"review\", \"back\", ExtensionContext>({\n start: \"choice\",\n screens: {\n choice: () => ({\n kind: \"actions\",\n title: `Compare synced content \u00B7 ${safeTerminalText(config.setupName)}`,\n lines: [\n \"This legacy snapshot has no portable synced-content list.\",\n \"Discovered paths are partial and read-only; preserved files may not have been selected.\",\n ],\n items: [\n { id: \"review\", label: \"Review discovered paths\", to: \"review\" },\n { id: \"back\", label: \"Back\", action: \"back\" },\n ],\n hint: \"close\",\n }),\n review: () => ({\n kind: \"review\",\n title: \"Partial discovery from legacy snapshot\",\n content: [\n \"Partial discovery only \u2014 not an authoritative selection.\",\n \"\",\n ...(discovered.length > 0\n ? discovered.map((item) => `Discovered: ${safeTerminalText(item)}`)\n : [\"No safe paths were discovered.\"]),\n \"\",\n \"Use Add custom path\u2026 in the local Included Content editor if needed.\",\n ].join(\"\\n\"),\n format: { kind: \"text\" },\n viewportSize: \"adaptive\",\n hint: \"back\",\n }),\n },\n actions: { back: async () => ({ kind: \"close\" }) },\n });\n await runMenu(ctx, menu, {\n getState: () => undefined,\n signal,\n isCurrent: () => !signal?.aborted,\n });\n}\n\nfunction selectionSummaryLines(decision: RemoteSelectionDecision) {\n const comparison = compareSyncInclude(decision.localInclude, decision.remoteInclude);\n return [\n `Sync setup: ${safeTerminalText(decision.setupName)}`,\n \"Nothing changed. Review both lists before choosing what happens next.\",\n ...(comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0\n ? [\"Only the ordering differs; membership is the same.\"]\n : [`Remote-only paths: ${comparison.remoteOnly.length} \u00B7 Device-only paths: ${comparison.localOnly.length}`]),\n ];\n}\n\nfunction formatSelectionDifference(decision: RemoteSelectionDecision) {\n const comparison = compareSyncInclude(decision.localInclude, decision.remoteInclude);\n return [\n ...(comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0\n ? [\"Only ordering differs; both lists contain the same paths.\", \"\"]\n : []),\n \"Remote-only paths:\",\n ...(comparison.remoteOnly.length > 0\n ? comparison.remoteOnly.map((item) => `+ ${safeTerminalText(item)}`)\n : [\"(none)\"]),\n \"\",\n \"Device-only paths:\",\n ...(comparison.localOnly.length > 0\n ? comparison.localOnly.map((item) => `- ${safeTerminalText(item)}`)\n : [\"(none)\"]),\n \"\",\n \"Remote ordered list:\",\n ...(decision.remoteInclude.length > 0\n ? decision.remoteInclude.map((item, index) => `${index + 1}. ${safeTerminalText(item)}`)\n : [\"(none)\"]),\n \"\",\n \"This device's ordered list:\",\n ...(decision.localInclude.length > 0\n ? decision.localInclude.map((item, index) => `${index + 1}. ${safeTerminalText(item)}`)\n : [\"(none)\"]),\n \"\",\n \"Using the remote list saves settings only and does not pull files.\",\n ].join(\"\\n\");\n}\n\nfunction formatRemoteSelectionSummary(decision: RemoteSelectionDecision) {\n const comparison = compareSyncInclude(decision.localInclude, decision.remoteInclude);\n return [\n `Synced content for \u201C${safeTerminalText(decision.setupName)}\u201D differs from this device.`,\n `Remote-only: ${safeList(comparison.remoteOnly)}`,\n `Device-only: ${safeList(comparison.localOnly)}`,\n ...(comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0\n ? [\n \"Only ordering differs.\",\n `Remote order: ${safeList(decision.remoteInclude)}`,\n `Device order: ${safeList(decision.localInclude)}`,\n ]\n : []),\n \"Run /sync in TUI to choose a content list; RPC review is read-only.\",\n ].join(\"\\n\");\n}\n\nfunction formatLegacySummary(config: AnySyncConfig, discovered: readonly string[]) {\n return `Remote snapshot for \u201C${safeTerminalText(config.setupName)}\u201D has no portable synced-content list; ${discovered.length} safe path${discovered.length === 1 ? \" was\" : \"s were\"} discovered, but the result is partial and read-only.`;\n}\n\nfunction decisionFromState(\n config: AnySyncConfig,\n state: Extract<RemoteSelectionState, { kind: \"different\" }>,\n): RemoteSelectionDecision {\n return {\n setupName: config.setupName,\n configIdentity: syncConfigReviewFingerprint(config),\n localInclude: [...config.include],\n remoteInclude: [...state.include],\n };\n}\n\nfunction assertLocalSelectionCurrent(config: AnySyncConfig, decision: RemoteSelectionDecision) {\n if (\n syncConfigReviewFingerprint(config) === decision.configIdentity &&\n sameSyncInclude(config.include, decision.localInclude)\n ) {\n return;\n }\n throw new StaleRemoteSelectionReviewError(\n `Sync setup \u201C${safeTerminalText(config.setupName)}\u201D changed while the comparison was open.`,\n );\n}\n\nfunction continueLabel(origin: RemoteSelectionOrigin) {\n if (origin === \"pull\") return \"Continue Pull now\u2026\";\n if (origin === \"push\") return \"Continue Push now\u2026\";\n return \"Continue Sync now\u2026\";\n}\n\nfunction continueBusyLabel(origin: RemoteSelectionOrigin) {\n if (origin === \"pull\") return \"Checking remote changes\u2026\";\n if (origin === \"push\") return \"Preparing push preview\u2026\";\n return \"Checking current sync setup\u2026\";\n}\n\nfunction continuationCancelledMessage(route: \"sync\" | \"pull\" | \"push\") {\n if (route === \"pull\") return \"Pull check cancelled; no local files were changed.\";\n if (route === \"push\") return \"Push preparation cancelled; no remote files were changed.\";\n return \"Sync check cancelled; no settings or files were changed.\";\n}\n\nfunction safeList(values: readonly string[]) {\n return values.length > 0 ? values.map(safeTerminalText).join(\", \") : \"none\";\n}\n\nclass StaleRemoteSelectionReviewError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"StaleRemoteSelectionReviewError\";\n }\n}\n\nfunction isStaleReviewError(error: unknown) {\n return error instanceof StaleRemoteSelectionReviewError || error instanceof SyncSetupReviewChangedError;\n}\n\nfunction runWithOptionalStateAccess<T>(\n options: Pick<RemoteSelectionReviewOptions, \"withStateAccess\">,\n task: () => Promise<T>,\n) {\n return options.withStateAccess ? options.withStateAccess(task) : task();\n}\n\nfunction isReviewOwnerCurrent(validateOwner: () => void) {\n try {\n validateOwner();\n return true;\n } catch {\n return false;\n }\n}\n\nfunction combineSignals(sessionSignal: AbortSignal | undefined, actionSignal: AbortSignal) {\n return sessionSignal ? AbortSignal.any([sessionSignal, actionSignal]) : actionSignal;\n}\n", "import { BorderedLoader, type ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { isKeyRelease, Key, matchesKey, truncateToWidth } from \"@earendil-works/pi-tui\";\nimport { formatInteractionHints, runCustomInteraction } from \"@narumitw/pi-tui-kit\";\nimport type { SetupPullOutcome } from \"../sync/setup-switch.js\";\nimport type { SyncDecision } from \"../sync/sync-decision.js\";\nimport type { RemoteSelectionDecision } from \"../sync/sync-policy.js\";\n\nexport type RunRouteResult =\n | { kind: \"completed\"; outcome?: SetupPullOutcome }\n | { kind: \"decision-required\"; decision: SyncDecision }\n | { kind: \"remote-selection-required\"; decision: RemoteSelectionDecision }\n | { kind: \"failed\" };\n\nexport type RunRoute = (\n route: string,\n signal?: AbortSignal,\n onCommit?: () => void,\n target?: string,\n onDialog?: (active: boolean) => void,\n retryRefusal?: boolean,\n) => Promise<RunRouteResult | undefined>;\n\nexport type CancellableOperationResult = RunRouteResult | { kind: \"closed\" } | { kind: \"cancelled\" };\n\ninterface CancellableOperationOptions {\n commitAware?: boolean;\n cancelAcrossDialogs?: boolean;\n cancelledMessage?: string | null;\n target?: string;\n signal?: AbortSignal;\n isCurrent?: () => boolean;\n}\n\nexport async function runCancellableOperation(\n ctx: ExtensionContext,\n message: string,\n route: string,\n runRoute: RunRoute,\n options: CancellableOperationOptions = {},\n): Promise<CancellableOperationResult> {\n const result = await runCancellableTask(\n ctx,\n message,\n (signal, onCommit, onDialog) => runRoute(route, signal, onCommit, options.target, onDialog),\n options,\n );\n return result.kind === \"completed\" ? (result.value ?? { kind: \"failed\" }) : result;\n}\n\nexport type CancellableTaskResult<Value> =\n | { kind: \"completed\"; value: Value }\n | { kind: \"closed\" }\n | { kind: \"cancelled\" };\n\n/** Keep non-route work under the same cancellation and drain owner as transfers. */\nexport async function runCancellableTask<Value>(\n ctx: ExtensionContext,\n message: string,\n task: (\n signal: AbortSignal | undefined,\n onCommit?: () => void,\n onDialog?: (active: boolean) => void,\n ) => Promise<Value>,\n options: Omit<CancellableOperationOptions, \"target\"> = {},\n): Promise<CancellableTaskResult<Value>> {\n const {\n commitAware = false,\n cancelAcrossDialogs = false,\n cancelledMessage = \"Check cancelled; no settings or files were changed.\",\n signal,\n isCurrent = () => true,\n } = options;\n if (signal?.aborted || !isCurrent()) return { kind: \"closed\" };\n if (ctx.mode !== \"tui\") return { kind: \"completed\", value: await task(signal) };\n let commitStarted = false;\n let taskResult!: Value;\n const interaction = await runCustomInteraction<{ cancelled?: boolean; error?: unknown }, ExtensionContext>(ctx, {\n signal,\n isCurrent: () => !signal?.aborted && isCurrent(),\n create: ({ tui, theme, keybindings, signal: interactionSignal, complete }) => {\n const loader = new BorderedLoader(tui, theme, message, { cancellable: false });\n const cancelHint = formatInteractionHints(keybindings, [\n {\n keys: [...keybindings.getKeys(\"tui.select.cancel\").filter((key) => !hasControlCharacter(key)), \"ctrl+c\"],\n label: \"cancel\",\n },\n ]);\n const cancel = (data: string) => {\n // Raw terminal listeners run before Pi filters Kitty key releases.\n if (isKeyRelease(data)) return false;\n if (!matchesKey(data, Key.ctrl(\"c\")) && !keybindings.matches(data, \"tui.select.cancel\")) return false;\n if (commitStarted) {\n ctx.ui.notify(\"Applying or publishing has started and cannot be cancelled safely.\", \"warning\");\n } else complete({ cancelled: true });\n return true;\n };\n // Pi dialogs replace this loader and restore the normal editor. Defer\n // ordinary keys while they are open; retain raw cancellation afterward.\n // Ctrl+C remains the root flow's hard-cancel path regardless of focus.\n let activeDialogs = 0;\n const unsubscribe = cancelAcrossDialogs\n ? ctx.ui.onTerminalInput((data) => {\n if (isKeyRelease(data)) return;\n if (activeDialogs > 0 && !matchesKey(data, Key.ctrl(\"c\"))) return;\n return cancel(data) ? { consume: true } : undefined;\n })\n : undefined;\n let pendingTask: Promise<Value>;\n try {\n pendingTask = task(\n interactionSignal,\n commitAware ? () => (commitStarted = true) : undefined,\n cancelAcrossDialogs\n ? (active) => {\n activeDialogs += active ? 1 : -1;\n }\n : undefined,\n );\n } catch (error) {\n unsubscribe?.();\n loader.dispose();\n throw error;\n }\n const operation = pendingTask.then(\n (result) => {\n taskResult = result;\n complete({});\n },\n (error: unknown) => complete({ error }),\n );\n return {\n render(width: number) {\n if (width <= 0) return [];\n const safeWidth = Math.max(1, width);\n const lines = loader.render(safeWidth);\n const bottomBorder = lines.at(-1);\n return [\n ...lines.slice(0, -1),\n truncateToWidth(theme.fg(\"dim\", cancelHint), safeWidth, \"\"),\n ...(bottomBorder === undefined ? [] : [bottomBorder]),\n ];\n },\n invalidate: () => loader.invalidate(),\n handleInput: cancel,\n dispose() {\n unsubscribe?.();\n loader.dispose();\n },\n waitForPending: () => operation,\n };\n },\n });\n if (interaction.kind === \"error\") throw interaction.error;\n if (interaction.kind !== \"completed\") return { kind: \"closed\" };\n if (interaction.value.cancelled) {\n if (cancelledMessage) ctx.ui.notify(cancelledMessage, \"info\");\n return { kind: \"cancelled\" };\n }\n if (interaction.value.error) throw interaction.value.error;\n return { kind: \"completed\", value: taskResult };\n}\n\nfunction hasControlCharacter(value: string) {\n // biome-ignore lint/suspicious/noControlCharactersInRegex: Unsafe key labels must be omitted.\n return /[\\u0000-\\u001f\\u007f-\\u009f]/u.test(value);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAAS,YAAY,eAAe;;;ACDpC,SAAS,sBAA6C;AACtD,SAAS,cAAc,KAAK,YAAY,uBAAuB;AAC/D,SAAS,wBAAwB,4BAA4B;AA+B7D,eAAsB,wBACpB,KACA,SACA,OACA,UACA,UAAuC,CAAC,GACH;AACrC,QAAM,SAAS,MAAM;AAAA,IACnB;AAAA,IACA;AAAA,IACA,CAAC,QAAQ,UAAU,aAAa,SAAS,OAAO,QAAQ,UAAU,QAAQ,QAAQ,QAAQ;AAAA,IAC1F;AAAA,EACF;AACA,SAAO,OAAO,SAAS,cAAe,OAAO,SAAS,EAAE,MAAM,SAAS,IAAK;AAC9E;AAQA,eAAsB,mBACpB,KACA,SACA,MAKA,UAAuD,CAAC,GACjB;AACvC,QAAM;AAAA,IACJ,cAAc;AAAA,IACd,sBAAsB;AAAA,IACtB,mBAAmB;AAAA,IACnB;AAAA,IACA,YAAY,MAAM;AAAA,EACpB,IAAI;AACJ,MAAI,QAAQ,WAAW,CAAC,UAAU,EAAG,QAAO,EAAE,MAAM,SAAS;AAC7D,MAAI,IAAI,SAAS,MAAO,QAAO,EAAE,MAAM,aAAa,OAAO,MAAM,KAAK,MAAM,EAAE;AAC9E,MAAI,gBAAgB;AACpB,MAAI;AACJ,QAAM,cAAc,MAAM,qBAAiF,KAAK;AAAA,IAC9G;AAAA,IACA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AO;AAAA,EACT;AACF;AAEA,SAAS,eAAe,eAAwC,cAA2B;AACzF,SAAO,gBAAgB,YAAY,IAAI,CAAC,eAAe,YAAY,CAAC,IAAI;AAC1E;",
|
|
4
|
+
"sourcesContent": ["import type { ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { defineMenu, runMenu } from \"@narumitw/pi-tui-kit\";\nimport { createSyncBackend, type SyncBackendFactory } from \"../backends/backend-factory.js\";\nimport type { RemoteHead, SyncBackend } from \"../backends/sync-backend.js\";\nimport { loadConfig, syncCheckConfigFingerprint, syncConfigReviewFingerprint } from \"../settings/config.js\";\nimport { SyncSetupReviewChangedError, updateSyncSetup } from \"../settings/settings-management.js\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport { readSnapshotForHead } from \"../sync/remote-snapshot.js\";\nimport { throwIfAborted } from \"../sync/signals.js\";\nimport { errorMessage } from \"../sync/sync-errors.js\";\nimport { captureMutationOwner } from \"../sync/sync-local.js\";\nimport {\n compareSyncInclude,\n inspectRemoteSelection,\n type RemoteSelectionDecision,\n type RemoteSelectionState,\n sameSyncInclude,\n} from \"../sync/sync-policy.js\";\nimport {\n type RunRoute,\n type RunRouteResult,\n runCancellableOperation,\n runCancellableTask,\n} from \"./cancellable-operation.js\";\nimport { setSyncStatus } from \"./sync-status.js\";\nimport { safeTerminalText } from \"./terminal-text.js\";\n\nexport type RemoteSelectionOrigin = \"settings\" | \"sync\" | \"pull\" | \"push\";\n\nexport interface RemoteSelectionReviewOptions {\n decision?: RemoteSelectionDecision;\n origin?: RemoteSelectionOrigin;\n runRoute?: RunRoute;\n cancelLabel?: string;\n /** The explicit mismatch is resolved or superseded; this does not imply file equality. */\n onSelectionResolved?: () => void;\n withStateAccess?: <T>(task: () => Promise<T>) => Promise<T>;\n}\n\nexport type RemoteSelectionReviewResult =\n | { kind: \"back\" }\n | { kind: \"closed\" }\n | { kind: \"done\" }\n | { kind: \"stale\" }\n | { kind: \"route-result\"; result: RunRouteResult; route: \"sync\" | \"pull\" | \"push\" };\n\nexport async function showRemoteSelectionReview(\n ctx: ExtensionContext,\n setupName?: string,\n signal?: AbortSignal,\n factory: SyncBackendFactory = createSyncBackend,\n options: RemoteSelectionReviewOptions = {},\n): Promise<RemoteSelectionReviewResult> {\n const validateOwner = captureMutationOwner(ctx, signal);\n const isCurrent = () => isReviewOwnerCurrent(validateOwner);\n try {\n validateOwner();\n let decision = options.decision;\n if (!decision) {\n const inspection = await runCancellableTask(\n ctx,\n \"Checking remote content list\u2026\",\n (workSignal) => inspectConfiguredRemoteSelection(ctx, setupName, workSignal, factory, validateOwner),\n { signal, isCurrent, cancelledMessage: null },\n );\n if (!isCurrent()) return { kind: \"stale\" };\n if (inspection.kind !== \"completed\") return { kind: inspection.kind === \"cancelled\" ? \"back\" : \"closed\" };\n validateOwner();\n const inspected = inspection.value;\n if (!inspected) return { kind: \"stale\" };\n // A successful fresh read can supersede an old explicit mismatch without\n // changing local settings. This is not user cancellation or proof of file equality.\n if (inspected.kind === \"empty\" || inspected.state.kind !== \"different\") {\n options.onSelectionResolved?.();\n }\n if (inspected.kind === \"empty\") {\n ctx.ui.notify(\"Remote storage has no snapshot or synced-content list yet.\", \"info\");\n return { kind: \"back\" };\n }\n if (inspected.state.kind === \"same\") {\n ctx.ui.notify(\"Remote synced content already matches this sync setup.\", \"info\");\n return { kind: \"back\" };\n }\n if (inspected.state.kind === \"legacy\") {\n if (ctx.mode !== \"tui\") {\n ctx.ui.notify(formatLegacySummary(inspected.config, inspected.state.discovered), \"info\");\n return { kind: \"back\" };\n }\n await showLegacyDiscovery(ctx, inspected.config, inspected.state.discovered, signal);\n return signal?.aborted ? { kind: \"stale\" } : { kind: \"back\" };\n }\n decision = decisionFromState(inspected.config, inspected.state);\n }\n\n if (ctx.mode !== \"tui\") {\n ctx.ui.notify(formatRemoteSelectionSummary(decision), \"warning\");\n return { kind: \"back\" };\n }\n\n let currentDecision = decision;\n for (;;) {\n if (signal?.aborted) return { kind: \"stale\" };\n const result = await showSelectionDifference(\n ctx,\n currentDecision,\n options.origin ?? \"settings\",\n options.runRoute,\n signal,\n factory,\n options,\n validateOwner,\n );\n if (result.kind !== \"refresh\") return result;\n const refresh = await runCancellableTask(\n ctx,\n \"Refreshing remote content list\u2026\",\n (workSignal) =>\n runWithOptionalStateAccess(options, () =>\n inspectConfiguredRemoteSelection(ctx, currentDecision.setupName, workSignal, factory, validateOwner),\n ),\n { signal, isCurrent, cancelledMessage: null },\n );\n if (!isCurrent()) return { kind: \"stale\" };\n if (refresh.kind !== \"completed\") return { kind: refresh.kind === \"cancelled\" ? \"back\" : \"closed\" };\n validateOwner();\n const refreshed = refresh.value;\n if (!refreshed) return { kind: \"stale\" };\n if (refreshed.kind === \"empty\") {\n options.onSelectionResolved?.();\n ctx.ui.notify(\"Remote storage no longer has a snapshot or synced-content list.\", \"warning\");\n return { kind: \"back\" };\n }\n if (refreshed.state.kind !== \"different\") {\n ctx.ui.notify(\n refreshed.state.kind === \"same\"\n ? \"Remote synced content now matches this sync setup.\"\n : \"The refreshed legacy snapshot has no authoritative synced-content list.\",\n \"info\",\n );\n options.onSelectionResolved?.();\n return { kind: \"done\" };\n }\n currentDecision = decisionFromState(refreshed.config, refreshed.state);\n }\n } catch (error) {\n if (!isCurrent()) return { kind: \"stale\" };\n ctx.ui.notify(`Could not review synced content: ${errorMessage(error)}`, \"error\");\n return { kind: \"back\" };\n } finally {\n if (isCurrent()) setSyncStatus(ctx, undefined);\n }\n}\n\ntype DifferenceFlowResult = RemoteSelectionReviewResult | { kind: \"refresh\" };\n\nasync function showSelectionDifference(\n ctx: ExtensionContext,\n initialDecision: RemoteSelectionDecision,\n origin: RemoteSelectionOrigin,\n runRoute: RunRoute | undefined,\n sessionSignal: AbortSignal | undefined,\n factory: SyncBackendFactory,\n options: Pick<RemoteSelectionReviewOptions, \"cancelLabel\" | \"onSelectionResolved\" | \"withStateAccess\">,\n validateOwner: () => void,\n): Promise<DifferenceFlowResult> {\n type Screen = \"choice\" | \"review\" | \"saved\";\n type Action = \"adopt\" | \"keep\" | \"cancel\" | \"continue\" | \"done\";\n interface FlowState {\n decision: RemoteSelectionDecision;\n saved: boolean;\n }\n const isCurrent = () => isReviewOwnerCurrent(validateOwner);\n let flowState: FlowState = { decision: initialDecision, saved: false };\n let continuationFingerprint: string | undefined;\n let nextResult: RemoteSelectionReviewResult | undefined;\n let refreshRequested = false;\n const route = origin === \"settings\" ? \"sync\" : origin;\n const menu = defineMenu<FlowState, Screen, Action, ExtensionContext>({\n start: \"choice\",\n screens: {\n choice: ({ state }) => ({\n kind: \"actions\",\n title: \"Synced content differs\",\n lines: selectionSummaryLines(state.decision),\n items: [\n {\n id: \"review\",\n label: \"Review all paths (recommended)\",\n description: \"Compare exact remote-only, device-only, and ordered lists.\",\n to: \"review\",\n },\n {\n id: \"adopt\",\n label: \"Use remote content list\",\n description: \"Save the reviewed list on this device without pulling files.\",\n action: \"adopt\",\n },\n {\n id: \"keep\",\n label: \"Keep this device's content list and update remote\u2026\",\n description: \"Open the existing exact force-push preview without skipping confirmation.\",\n action: \"keep\",\n },\n { id: \"cancel\", label: options.cancelLabel ?? \"Cancel\", action: \"cancel\" },\n ],\n hint: \"back\",\n }),\n review: ({ state }) => ({\n kind: \"review\",\n title: `Review synced content \u00B7 ${safeTerminalText(state.decision.setupName)}`,\n content: formatSelectionDifference(state.decision),\n format: { kind: \"text\" },\n viewportSize: \"adaptive\",\n hint: \"back\",\n }),\n saved: ({ state }) => ({\n kind: \"actions\",\n title: \"Remote content list saved\",\n lines: [\n `Sync setup: ${safeTerminalText(state.decision.setupName)}`,\n \"Only the included-content setting was saved.\",\n \"No files were pulled and sync state was not changed.\",\n ],\n items: [\n ...(runRoute\n ? [\n {\n id: \"continue\",\n label: continueLabel(origin),\n description: \"Start a fresh check and exact preview for this sync setup.\",\n action: \"continue\" as const,\n },\n ]\n : []),\n { id: \"done\", label: \"Done\", action: \"done\" },\n ],\n hint: \"close\",\n }),\n },\n actions: {\n adopt: async ({ state, signal: actionSignal }) => {\n const signal = combineSignals(sessionSignal, actionSignal);\n try {\n const adoption = await runCancellableTask(\n ctx,\n \"Checking and saving remote content list\u2026\",\n async (workSignal, _onCommit, onDialog) => {\n const ownedSignal = workSignal ?? signal;\n const currentConfig = await loadConfig(state.decision.setupName);\n ownedSignal.throwIfAborted();\n validateOwner();\n assertLocalSelectionCurrent(currentConfig, state.decision);\n if (!currentConfig.include.includes(\"sessions\") && state.decision.remoteInclude.includes(\"sessions\")) {\n onDialog?.(true);\n let acknowledged: boolean;\n try {\n acknowledged = await ctx.ui.confirm(\n \"Use a content list that includes session conversations?\",\n \"Session JSONL may contain prompts, tool output, file paths, images, and secrets. This saves the list only; it does not pull files.\",\n { signal: ownedSignal },\n );\n } finally {\n onDialog?.(false);\n }\n ownedSignal.throwIfAborted();\n validateOwner();\n if (!acknowledged) return undefined;\n }\n return runWithOptionalStateAccess(options, async () => {\n const loaded = await loadAdoptionReview(state.decision, ownedSignal, factory, validateOwner);\n ownedSignal.throwIfAborted();\n validateOwner();\n await revalidateAndAdopt(loaded, state.decision, ownedSignal, validateOwner);\n return loaded;\n });\n },\n {\n signal,\n isCurrent,\n cancelAcrossDialogs: true,\n cancelledMessage: \"Remote content-list adoption cancelled.\",\n },\n );\n if (signal.aborted || adoption.kind === \"closed\") return { kind: \"close\" as const };\n if (adoption.kind === \"cancelled\" || !adoption.value) return { kind: \"stay\" as const };\n validateOwner();\n options.onSelectionResolved?.();\n continuationFingerprint = syncCheckConfigFingerprint({\n ...adoption.value.config,\n include: [...state.decision.remoteInclude],\n });\n flowState = { decision: state.decision, saved: true };\n return { kind: \"to\" as const, screen: \"saved\" as const };\n } catch (error) {\n if (signal.aborted || !isCurrent()) return { kind: \"close\" as const };\n if (isStaleReviewError(error)) {\n ctx.ui.notify(`${errorMessage(error)} Refreshing the comparison.`, \"warning\");\n refreshRequested = true;\n return { kind: \"close\" as const };\n }\n ctx.ui.notify(`Could not save the remote content list: ${errorMessage(error)}`, \"error\");\n return { kind: \"stay\" as const };\n }\n },\n keep: async ({ state, signal: actionSignal }) => {\n if (!runRoute) {\n ctx.ui.notify(\"The reviewed update-remote route is unavailable.\", \"error\");\n return { kind: \"stay\" as const };\n }\n const signal = combineSignals(sessionSignal, actionSignal);\n try {\n const latest = await loadConfig(state.decision.setupName);\n if (signal.aborted) return { kind: \"close\" as const };\n validateOwner();\n assertLocalSelectionCurrent(latest, state.decision);\n const result = await runCancellableOperation(\n ctx,\n \"Preparing this device's push preview\u2026\",\n \"push --force\",\n runRoute,\n {\n commitAware: true,\n cancelledMessage: \"Push preparation cancelled; no remote files were changed.\",\n target: state.decision.setupName,\n signal,\n },\n );\n return handleNestedRouteResult(result, \"push\");\n } catch (error) {\n if (signal.aborted || !isCurrent()) return { kind: \"close\" as const };\n if (isStaleReviewError(error)) {\n ctx.ui.notify(`${errorMessage(error)} Refreshing the comparison.`, \"warning\");\n refreshRequested = true;\n return { kind: \"close\" as const };\n }\n ctx.ui.notify(`Could not prepare the remote update: ${errorMessage(error)}`, \"error\");\n return { kind: \"stay\" as const };\n }\n },\n continue: async ({ state, signal: actionSignal }) => {\n if (!runRoute || !continuationFingerprint) return { kind: \"stay\" as const };\n const signal = combineSignals(sessionSignal, actionSignal);\n try {\n const latest = await loadConfig(state.decision.setupName);\n if (signal.aborted) return { kind: \"close\" as const };\n validateOwner();\n if (syncCheckConfigFingerprint(latest) !== continuationFingerprint) {\n throw new StaleRemoteSelectionReviewError(\n `Sync setup \u201C${safeTerminalText(state.decision.setupName)}\u201D changed after the remote content list was saved.`,\n );\n }\n const result = await runCancellableOperation(ctx, continueBusyLabel(origin), route, runRoute, {\n commitAware: true,\n cancelledMessage: continuationCancelledMessage(route),\n target: state.decision.setupName,\n signal,\n });\n return handleNestedRouteResult(result, route);\n } catch (error) {\n if (signal.aborted || !isCurrent()) return { kind: \"close\" as const };\n ctx.ui.notify(`Could not continue: ${errorMessage(error)}`, \"error\");\n return { kind: \"stay\" as const };\n }\n },\n cancel: async () => ({ kind: \"back\" }),\n done: async () => {\n nextResult = { kind: \"done\" };\n return { kind: \"close\" };\n },\n },\n });\n\n function handleNestedRouteResult(\n result: Awaited<ReturnType<typeof runCancellableOperation>>,\n nestedRoute: \"sync\" | \"pull\" | \"push\",\n ) {\n if (result.kind === \"completed\" && result.outcome === \"applied\") {\n options.onSelectionResolved?.();\n }\n if (result.kind === \"closed\") {\n nextResult = { kind: \"closed\" };\n return { kind: \"close\" as const };\n }\n if (\n result.kind === \"cancelled\" ||\n (result.kind === \"completed\" && result.outcome === \"cancelled\") ||\n result.kind === \"failed\"\n ) {\n return { kind: \"stay\" as const };\n }\n nextResult = { kind: \"route-result\", result, route: nestedRoute };\n return { kind: \"close\" as const };\n }\n\n const menuResult = await runMenu(ctx, menu, {\n getState: () => flowState,\n signal: sessionSignal,\n isCurrent,\n onError: (_menuCtx, error) => ctx.ui.notify(errorMessage(error), \"error\"),\n });\n if (!isCurrent() || menuResult.kind === \"stale\") return { kind: \"stale\" };\n if (refreshRequested) return { kind: \"refresh\" };\n if (nextResult) return nextResult;\n if (menuResult.kind === \"closed\") {\n return menuResult.reason === \"back\" ? { kind: \"back\" } : { kind: \"closed\" };\n }\n return { kind: \"closed\" };\n}\n\ninterface AdoptionReview {\n config: AnySyncConfig;\n backend: SyncBackend;\n reviewedHead: RemoteHead;\n}\n\nasync function loadAdoptionReview(\n decision: RemoteSelectionDecision,\n signal: AbortSignal,\n factory: SyncBackendFactory,\n validateOwner: () => void,\n): Promise<AdoptionReview> {\n const config = await loadConfig(decision.setupName);\n throwIfAborted(signal);\n validateOwner();\n assertLocalSelectionCurrent(config, decision);\n const backend = await factory(config);\n throwIfAborted(signal);\n validateOwner();\n const reviewedHead = await backend.readHead(signal);\n throwIfAborted(signal);\n validateOwner();\n if (!reviewedHead) {\n throw new StaleRemoteSelectionReviewError(\"Remote storage changed while the comparison was open.\");\n }\n const snapshot = await readSnapshotForHead(backend, reviewedHead, signal);\n throwIfAborted(signal);\n validateOwner();\n const state = inspectRemoteSelection(config.include, snapshot);\n if (state.kind !== \"different\" || !sameSyncInclude(state.include, decision.remoteInclude)) {\n throw new StaleRemoteSelectionReviewError(\"Remote synced content changed while the comparison was open.\");\n }\n return { config, backend, reviewedHead };\n}\n\nasync function revalidateAndAdopt(\n review: AdoptionReview,\n decision: RemoteSelectionDecision,\n signal: AbortSignal,\n validateOwner: () => void,\n) {\n const currentHead = await review.backend.readHead(signal);\n throwIfAborted(signal);\n validateOwner();\n if (!currentHead || !review.backend.sameRevision(review.reviewedHead.revision, currentHead.revision)) {\n throw new StaleRemoteSelectionReviewError(\"Remote storage changed while the comparison was open.\");\n }\n const currentSnapshot = await readSnapshotForHead(review.backend, currentHead, signal);\n throwIfAborted(signal);\n validateOwner();\n const currentState = inspectRemoteSelection(review.config.include, currentSnapshot);\n if (currentState.kind !== \"different\" || !sameSyncInclude(currentState.include, decision.remoteInclude)) {\n throw new StaleRemoteSelectionReviewError(\"Remote synced content changed while the comparison was open.\");\n }\n await updateSyncSetup(\n decision.setupName,\n (setup) => {\n validateOwner();\n return { ...setup, sync: { ...setup.sync, include: [...decision.remoteInclude] } };\n },\n {\n expectedConfigFingerprint: syncCheckConfigFingerprint(review.config),\n expectedInclude: decision.localInclude,\n signal,\n },\n );\n}\n\nasync function inspectConfiguredRemoteSelection(\n ctx: ExtensionContext,\n setupName: string | undefined,\n signal: AbortSignal | undefined,\n factory: SyncBackendFactory,\n validateOwner: () => void,\n): Promise<\n | { kind: \"empty\"; config: AnySyncConfig }\n | { kind: \"selection\"; config: AnySyncConfig; state: RemoteSelectionState }\n | undefined\n> {\n const config = await loadConfig(setupName);\n if (signal?.aborted) return undefined;\n validateOwner();\n setSyncStatus(ctx, `checking synced content for ${safeTerminalText(config.setupName)}`, { activity: \"checking\" });\n const backend = await factory(config);\n if (signal?.aborted) return undefined;\n validateOwner();\n const head = await backend.readHead(signal);\n if (signal?.aborted) return undefined;\n validateOwner();\n if (!head) return { kind: \"empty\", config };\n const snapshot = await readSnapshotForHead(backend, head, signal);\n if (signal?.aborted) return undefined;\n validateOwner();\n return {\n kind: \"selection\",\n config,\n state: inspectRemoteSelection(config.include, snapshot),\n };\n}\n\nasync function showLegacyDiscovery(\n ctx: ExtensionContext,\n config: AnySyncConfig,\n discovered: string[],\n signal?: AbortSignal,\n) {\n const menu = defineMenu<undefined, \"choice\" | \"review\", \"back\", ExtensionContext>({\n start: \"choice\",\n screens: {\n choice: () => ({\n kind: \"actions\",\n title: `Compare synced content \u00B7 ${safeTerminalText(config.setupName)}`,\n lines: [\n \"This legacy snapshot has no portable synced-content list.\",\n \"Discovered paths are partial and read-only; preserved files may not have been selected.\",\n ],\n items: [\n { id: \"review\", label: \"Review discovered paths\", to: \"review\" },\n { id: \"back\", label: \"Back\", action: \"back\" },\n ],\n hint: \"close\",\n }),\n review: () => ({\n kind: \"review\",\n title: \"Partial discovery from legacy snapshot\",\n content: [\n \"Partial discovery only \u2014 not an authoritative selection.\",\n \"\",\n ...(discovered.length > 0\n ? discovered.map((item) => `Discovered: ${safeTerminalText(item)}`)\n : [\"No safe paths were discovered.\"]),\n \"\",\n \"Use Add custom path\u2026 in the local Included Content editor if needed.\",\n ].join(\"\\n\"),\n format: { kind: \"text\" },\n viewportSize: \"adaptive\",\n hint: \"back\",\n }),\n },\n actions: { back: async () => ({ kind: \"close\" }) },\n });\n await runMenu(ctx, menu, {\n getState: () => undefined,\n signal,\n isCurrent: () => !signal?.aborted,\n });\n}\n\nfunction selectionSummaryLines(decision: RemoteSelectionDecision) {\n const comparison = compareSyncInclude(decision.localInclude, decision.remoteInclude);\n return [\n `Sync setup: ${safeTerminalText(decision.setupName)}`,\n \"Nothing changed. Review both lists before choosing what happens next.\",\n ...(comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0\n ? [\"Only the ordering differs; membership is the same.\"]\n : [`Remote-only paths: ${comparison.remoteOnly.length} \u00B7 Device-only paths: ${comparison.localOnly.length}`]),\n ];\n}\n\nfunction formatSelectionDifference(decision: RemoteSelectionDecision) {\n const comparison = compareSyncInclude(decision.localInclude, decision.remoteInclude);\n return [\n ...(comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0\n ? [\"Only ordering differs; both lists contain the same paths.\", \"\"]\n : []),\n \"Remote-only paths:\",\n ...(comparison.remoteOnly.length > 0\n ? comparison.remoteOnly.map((item) => `+ ${safeTerminalText(item)}`)\n : [\"(none)\"]),\n \"\",\n \"Device-only paths:\",\n ...(comparison.localOnly.length > 0\n ? comparison.localOnly.map((item) => `- ${safeTerminalText(item)}`)\n : [\"(none)\"]),\n \"\",\n \"Remote ordered list:\",\n ...(decision.remoteInclude.length > 0\n ? decision.remoteInclude.map((item, index) => `${index + 1}. ${safeTerminalText(item)}`)\n : [\"(none)\"]),\n \"\",\n \"This device's ordered list:\",\n ...(decision.localInclude.length > 0\n ? decision.localInclude.map((item, index) => `${index + 1}. ${safeTerminalText(item)}`)\n : [\"(none)\"]),\n \"\",\n \"Using the remote list saves settings only and does not pull files.\",\n ].join(\"\\n\");\n}\n\nfunction formatRemoteSelectionSummary(decision: RemoteSelectionDecision) {\n const comparison = compareSyncInclude(decision.localInclude, decision.remoteInclude);\n return [\n `Synced content for \u201C${safeTerminalText(decision.setupName)}\u201D differs from this device.`,\n `Remote-only: ${safeList(comparison.remoteOnly)}`,\n `Device-only: ${safeList(comparison.localOnly)}`,\n ...(comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0\n ? [\n \"Only ordering differs.\",\n `Remote order: ${safeList(decision.remoteInclude)}`,\n `Device order: ${safeList(decision.localInclude)}`,\n ]\n : []),\n \"Run /sync in TUI to choose a content list; RPC review is read-only.\",\n ].join(\"\\n\");\n}\n\nfunction formatLegacySummary(config: AnySyncConfig, discovered: readonly string[]) {\n return `Remote snapshot for \u201C${safeTerminalText(config.setupName)}\u201D has no portable synced-content list; ${discovered.length} safe path${discovered.length === 1 ? \" was\" : \"s were\"} discovered, but the result is partial and read-only.`;\n}\n\nfunction decisionFromState(\n config: AnySyncConfig,\n state: Extract<RemoteSelectionState, { kind: \"different\" }>,\n): RemoteSelectionDecision {\n return {\n setupName: config.setupName,\n configIdentity: syncConfigReviewFingerprint(config),\n localInclude: [...config.include],\n remoteInclude: [...state.include],\n };\n}\n\nfunction assertLocalSelectionCurrent(config: AnySyncConfig, decision: RemoteSelectionDecision) {\n if (\n syncConfigReviewFingerprint(config) === decision.configIdentity &&\n sameSyncInclude(config.include, decision.localInclude)\n ) {\n return;\n }\n throw new StaleRemoteSelectionReviewError(\n `Sync setup \u201C${safeTerminalText(config.setupName)}\u201D changed while the comparison was open.`,\n );\n}\n\nfunction continueLabel(origin: RemoteSelectionOrigin) {\n if (origin === \"pull\") return \"Continue Pull now\u2026\";\n if (origin === \"push\") return \"Continue Push now\u2026\";\n return \"Continue Sync now\u2026\";\n}\n\nfunction continueBusyLabel(origin: RemoteSelectionOrigin) {\n if (origin === \"pull\") return \"Checking remote changes\u2026\";\n if (origin === \"push\") return \"Preparing push preview\u2026\";\n return \"Checking current sync setup\u2026\";\n}\n\nfunction continuationCancelledMessage(route: \"sync\" | \"pull\" | \"push\") {\n if (route === \"pull\") return \"Pull check cancelled; no local files were changed.\";\n if (route === \"push\") return \"Push preparation cancelled; no remote files were changed.\";\n return \"Sync check cancelled; no settings or files were changed.\";\n}\n\nfunction safeList(values: readonly string[]) {\n return values.length > 0 ? values.map(safeTerminalText).join(\", \") : \"none\";\n}\n\nclass StaleRemoteSelectionReviewError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"StaleRemoteSelectionReviewError\";\n }\n}\n\nfunction isStaleReviewError(error: unknown) {\n return error instanceof StaleRemoteSelectionReviewError || error instanceof SyncSetupReviewChangedError;\n}\n\nfunction runWithOptionalStateAccess<T>(\n options: Pick<RemoteSelectionReviewOptions, \"withStateAccess\">,\n task: () => Promise<T>,\n) {\n return options.withStateAccess ? options.withStateAccess(task) : task();\n}\n\nfunction isReviewOwnerCurrent(validateOwner: () => void) {\n try {\n validateOwner();\n return true;\n } catch {\n return false;\n }\n}\n\nfunction combineSignals(sessionSignal: AbortSignal | undefined, actionSignal: AbortSignal) {\n return sessionSignal ? AbortSignal.any([sessionSignal, actionSignal]) : actionSignal;\n}\n", "import { BorderedLoader, type ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { isKeyRelease, Key, matchesKey, truncateToWidth } from \"@earendil-works/pi-tui\";\nimport { formatInteractionHints, runCustomInteraction } from \"@narumitw/pi-tui-kit\";\nimport type { SetupPullOutcome } from \"../sync/setup-switch.js\";\nimport type { SyncDecision } from \"../sync/sync-decision.js\";\nimport type { RemoteSelectionDecision } from \"../sync/sync-policy.js\";\n\nexport type RunRouteResult =\n | { kind: \"completed\"; outcome?: SetupPullOutcome }\n | { kind: \"decision-required\"; decision: SyncDecision }\n | { kind: \"remote-selection-required\"; decision: RemoteSelectionDecision }\n | { kind: \"failed\" };\n\nexport type RunRoute = (\n route: string,\n signal?: AbortSignal,\n onCommit?: () => void,\n target?: string,\n onDialog?: (active: boolean) => void,\n retryRefusal?: boolean,\n) => Promise<RunRouteResult | undefined>;\n\nexport type CancellableOperationResult = RunRouteResult | { kind: \"closed\" } | { kind: \"cancelled\" };\n\ninterface CancellableOperationOptions {\n commitAware?: boolean;\n cancelAcrossDialogs?: boolean;\n cancelledMessage?: string | null;\n target?: string;\n signal?: AbortSignal;\n isCurrent?: () => boolean;\n}\n\nexport async function runCancellableOperation(\n ctx: ExtensionContext,\n message: string,\n route: string,\n runRoute: RunRoute,\n options: CancellableOperationOptions = {},\n): Promise<CancellableOperationResult> {\n const result = await runCancellableTask(\n ctx,\n message,\n (signal, onCommit, onDialog) => runRoute(route, signal, onCommit, options.target, onDialog),\n options,\n );\n return result.kind === \"completed\" ? (result.value ?? { kind: \"failed\" }) : result;\n}\n\nexport type CancellableTaskResult<Value> =\n | { kind: \"completed\"; value: Value }\n | { kind: \"closed\" }\n | { kind: \"cancelled\" };\n\n/** Keep non-route work under the same cancellation and drain owner as transfers. */\nexport async function runCancellableTask<Value>(\n ctx: ExtensionContext,\n message: string,\n task: (\n signal: AbortSignal | undefined,\n onCommit?: () => void,\n onDialog?: (active: boolean) => void,\n ) => Promise<Value>,\n options: Omit<CancellableOperationOptions, \"target\"> = {},\n): Promise<CancellableTaskResult<Value>> {\n const {\n commitAware = false,\n cancelAcrossDialogs = false,\n cancelledMessage = \"Check cancelled; no settings or files were changed.\",\n signal,\n isCurrent = () => true,\n } = options;\n if (signal?.aborted || !isCurrent()) return { kind: \"closed\" };\n if (ctx.mode !== \"tui\") return { kind: \"completed\", value: await task(signal) };\n let commitStarted = false;\n let taskResult!: Value;\n const interaction = await runCustomInteraction<{ cancelled?: boolean; error?: unknown }, ExtensionContext>(ctx, {\n signal,\n isCurrent: () => !signal?.aborted && isCurrent(),\n create: ({ tui, theme, keybindings, signal: interactionSignal, complete }) => {\n const loader = new BorderedLoader(tui, theme, message, { cancellable: false });\n const cancelHint = formatInteractionHints(keybindings, [\n {\n keys: [...keybindings.getKeys(\"tui.select.cancel\").filter((key) => !hasControlCharacter(key)), \"ctrl+c\"],\n label: \"cancel\",\n },\n ]);\n const cancel = (data: string) => {\n // Raw terminal listeners run before Pi filters Kitty key releases.\n if (isKeyRelease(data)) return false;\n if (!matchesKey(data, Key.ctrl(\"c\")) && !keybindings.matches(data, \"tui.select.cancel\")) return false;\n if (commitStarted) {\n ctx.ui.notify(\"Applying or publishing has started and cannot be cancelled safely.\", \"warning\");\n } else complete({ cancelled: true });\n return true;\n };\n // Pi dialogs replace this loader and restore the normal editor. Defer\n // ordinary keys while they are open; retain raw cancellation afterward.\n // Ctrl+C remains the root flow's hard-cancel path regardless of focus.\n let activeDialogs = 0;\n const unsubscribe = cancelAcrossDialogs\n ? ctx.ui.onTerminalInput((data) => {\n if (isKeyRelease(data)) return;\n if (activeDialogs > 0 && !matchesKey(data, Key.ctrl(\"c\"))) return;\n return cancel(data) ? { consume: true } : undefined;\n })\n : undefined;\n let pendingTask: Promise<Value>;\n try {\n pendingTask = task(\n interactionSignal,\n commitAware ? () => (commitStarted = true) : undefined,\n cancelAcrossDialogs\n ? (active) => {\n activeDialogs += active ? 1 : -1;\n }\n : undefined,\n );\n } catch (error) {\n unsubscribe?.();\n loader.dispose();\n throw error;\n }\n const operation = pendingTask.then(\n (result) => {\n taskResult = result;\n complete({});\n },\n (error: unknown) => complete({ error }),\n );\n return {\n render(width: number) {\n if (width <= 0) return [];\n const safeWidth = Math.max(1, width);\n const lines = loader.render(safeWidth);\n const bottomBorder = lines.at(-1);\n return [\n ...lines.slice(0, -1),\n truncateToWidth(theme.fg(\"dim\", cancelHint), safeWidth, \"\"),\n ...(bottomBorder === undefined ? [] : [bottomBorder]),\n ];\n },\n invalidate: () => loader.invalidate(),\n handleInput: cancel,\n dispose() {\n unsubscribe?.();\n loader.dispose();\n },\n waitForPending: () => operation,\n };\n },\n });\n if (interaction.kind === \"error\") throw interaction.error;\n if (interaction.kind !== \"completed\") return { kind: \"closed\" };\n if (interaction.value.cancelled) {\n if (cancelledMessage) ctx.ui.notify(cancelledMessage, \"info\");\n return { kind: \"cancelled\" };\n }\n if (interaction.value.error) throw interaction.value.error;\n return { kind: \"completed\", value: taskResult };\n}\n\nfunction hasControlCharacter(value: string) {\n // biome-ignore lint/suspicious/noControlCharactersInRegex: Unsafe key labels must be omitted.\n return /[\\u0000-\\u001f\\u007f-\\u009f]/u.test(value);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAAS,YAAY,eAAe;;;ACDpC,SAAS,sBAA6C;AACtD,SAAS,cAAc,KAAK,YAAY,uBAAuB;AAC/D,SAAS,wBAAwB,4BAA4B;AA+B7D,eAAsB,wBACpB,KACA,SACA,OACA,UACA,UAAuC,CAAC,GACH;AACrC,QAAM,SAAS,MAAM;AAAA,IACnB;AAAA,IACA;AAAA,IACA,CAAC,QAAQ,UAAU,aAAa,SAAS,OAAO,QAAQ,UAAU,QAAQ,QAAQ,QAAQ;AAAA,IAC1F;AAAA,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AAO;AAC7B,MAAI,UAAU,OAAQ,QAAO;AAC7B,SAAO;AACT;AAEA,SAAS,SAAS,QAA2B;AAC3C,SAAO,OAAO,SAAS,IAAI,OAAO,IAAI,gBAAgB,EAAE,KAAK,IAAI,IAAI;AACvE;AAEA,IAAM,kCAAN,cAA8C,MAAM;AAAA,EAClD,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEA,SAAS,mBAAmB,OAAgB;AAC1C,SAAO,iBAAiB,mCAAmC,iBAAiB;AAC9E;AAEA,SAAS,2BACP,SACA,MACA;AACA,SAAO,QAAQ,kBAAkB,QAAQ,gBAAgB,IAAI,IAAI,KAAK;AACxE;AAEA,SAAS,qBAAqB,eAA2B;AACvD,MAAI;AACF,kBAAc;AACd,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,eAAe,eAAwC,cAA2B;AACzF,SAAO,gBAAgB,YAAY,IAAI,CAAC,eAAe,YAAY,CAAC,IAAI;AAC1E;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from "./chunk-AMJRUXFT.ts";
|
|
6
6
|
import {
|
|
7
7
|
setSyncStatus
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-YIPK23JW.ts";
|
|
9
9
|
import {
|
|
10
10
|
syncCheckConfigFingerprint,
|
|
11
11
|
syncConfigReviewFingerprint
|
|
@@ -25,6 +25,7 @@ function createSyncAttentionController() {
|
|
|
25
25
|
let state;
|
|
26
26
|
let observation;
|
|
27
27
|
let generation = 0;
|
|
28
|
+
let widgetState = { collapsed: false };
|
|
28
29
|
return {
|
|
29
30
|
observe(value) {
|
|
30
31
|
generation++;
|
|
@@ -63,8 +64,12 @@ function createSyncAttentionController() {
|
|
|
63
64
|
generation++;
|
|
64
65
|
state = void 0;
|
|
65
66
|
observation = void 0;
|
|
67
|
+
widgetState = { collapsed: false };
|
|
66
68
|
clearAttentionPresentation(ctx);
|
|
67
69
|
},
|
|
70
|
+
expand() {
|
|
71
|
+
widgetState.collapsed = false;
|
|
72
|
+
},
|
|
68
73
|
async publish(ctx, signal) {
|
|
69
74
|
const currentGeneration = ++generation;
|
|
70
75
|
if (signal?.aborted || !ctx.hasUI) return;
|
|
@@ -75,16 +80,15 @@ function createSyncAttentionController() {
|
|
|
75
80
|
}
|
|
76
81
|
if (!state && classification === "status") {
|
|
77
82
|
ctx.ui.setWidget(WIDGET_KEY, void 0);
|
|
78
|
-
setSyncStatus(ctx, observation?.inspection.remoteChanged ? "sync \u21E3" : "sync \u21E1"
|
|
83
|
+
setSyncStatus(ctx, observation?.inspection.remoteChanged ? "sync \u21E3" : "sync \u21E1", {
|
|
84
|
+
activity: observation?.inspection.remoteChanged ? "remote-change" : "local-change"
|
|
85
|
+
});
|
|
79
86
|
return;
|
|
80
87
|
}
|
|
81
|
-
const presentation = state ? attentionPresentation(state.decision) :
|
|
82
|
-
status: "sync \u21D5",
|
|
83
|
-
lines: observationLines(observation)
|
|
84
|
-
};
|
|
88
|
+
const presentation = state ? attentionPresentation(state.decision) : observationPresentation(observation);
|
|
85
89
|
if (ctx.mode !== "tui") {
|
|
86
90
|
ctx.ui.setWidget(WIDGET_KEY, void 0);
|
|
87
|
-
setSyncStatus(ctx, presentation.status);
|
|
91
|
+
setSyncStatus(ctx, presentation.status, { activity: "review" });
|
|
88
92
|
return;
|
|
89
93
|
}
|
|
90
94
|
const { EditorStatusWidget } = await import("./attention-widget-Z7G3SYYJ.ts").catch((error) => {
|
|
@@ -92,11 +96,15 @@ function createSyncAttentionController() {
|
|
|
92
96
|
throw error;
|
|
93
97
|
});
|
|
94
98
|
if (generation !== currentGeneration || signal?.aborted) return;
|
|
95
|
-
setSyncStatus(ctx, presentation.status);
|
|
99
|
+
setSyncStatus(ctx, presentation.status, { activity: "review" });
|
|
100
|
+
const presentationState = widgetState;
|
|
96
101
|
ctx.ui.setWidget(
|
|
97
102
|
WIDGET_KEY,
|
|
98
103
|
(_tui, theme) => new EditorStatusWidget({
|
|
99
104
|
theme,
|
|
105
|
+
name: "Sync",
|
|
106
|
+
summary: "Needs review",
|
|
107
|
+
state: presentationState,
|
|
100
108
|
renderBody: (width) => presentation.lines.map(
|
|
101
109
|
(line, index) => width === 0 ? "" : truncateToWidth(theme.fg(index === 0 ? "warning" : "muted", line), width, "\u2026")
|
|
102
110
|
)
|
|
@@ -108,10 +116,23 @@ function createSyncAttentionController() {
|
|
|
108
116
|
function attentionPresentation(decision) {
|
|
109
117
|
const setupName = safeTerminalText(decision.setupName);
|
|
110
118
|
const comparison = compareSyncInclude(decision.localInclude, decision.remoteInclude);
|
|
111
|
-
const difference = comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0 ? "Only list order differs" : `Remote ${comparison.remoteOnly.length} \xB7 Device ${comparison.localOnly.length}`;
|
|
112
119
|
return {
|
|
113
120
|
status: "sync \u21D5",
|
|
114
|
-
lines: [`
|
|
121
|
+
lines: [`Setup: ${setupName}`, selectionDifference(comparison), "No transfer performed \xB7 Run /sync to review"]
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function selectionDifference(comparison) {
|
|
125
|
+
return comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0 ? "Selection: only list order differs" : `Selection: ${comparison.remoteOnly.length} remote-only \xB7 ${comparison.localOnly.length} device-only`;
|
|
126
|
+
}
|
|
127
|
+
function observationPresentation(observation) {
|
|
128
|
+
const selection = observation.inspection.selectionState;
|
|
129
|
+
return {
|
|
130
|
+
status: "sync \u21D5",
|
|
131
|
+
lines: [
|
|
132
|
+
`Setup: ${safeTerminalText(observation.setupName)}`,
|
|
133
|
+
selection?.kind === "different" ? selectionDifference(selection) : observationSummary(observation),
|
|
134
|
+
"No transfer performed \xB7 Run /sync to review"
|
|
135
|
+
]
|
|
115
136
|
};
|
|
116
137
|
}
|
|
117
138
|
function observationMatchesConfig(observation, config) {
|
|
@@ -164,4 +185,4 @@ export {
|
|
|
164
185
|
observationMatchesConfig,
|
|
165
186
|
observationSummary
|
|
166
187
|
};
|
|
167
|
-
//# sourceMappingURL=chunk-
|
|
188
|
+
//# sourceMappingURL=chunk-REMGB255.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/ui/sync-attention.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { truncateToWidth } from \"@earendil-works/pi-tui\";\nimport type { EditorStatusWidgetState } from \"@narumitw/pi-tui-kit/editor-status-widget\";\nimport { syncCheckConfigFingerprint, syncConfigReviewFingerprint } from \"../settings/config.js\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport type { StartupObservation } from \"../sync/sync-inspection.js\";\nimport { compareSyncInclude, type RemoteSelectionDecision, sameSyncInclude } from \"../sync/sync-policy.js\";\nimport { setSyncStatus } from \"./sync-status.js\";\nimport { safeTerminalText } from \"./terminal-text.js\";\n\nconst WIDGET_KEY = \"sync:attention\";\n\nexport type SyncAttentionOrigin = \"sync\" | \"pull\" | \"push\";\n\nexport interface SyncAttentionState {\n decision: RemoteSelectionDecision;\n origin: SyncAttentionOrigin;\n offered: boolean;\n}\n\nexport function syncAttentionMatchesConfig(attention: SyncAttentionState, config: AnySyncConfig) {\n return (\n attention.decision.setupName === config.setupName &&\n attention.decision.configIdentity === syncConfigReviewFingerprint(config) &&\n sameSyncInclude(attention.decision.localInclude, config.include)\n );\n}\n\nexport interface SyncAttentionController {\n observe(observation: StartupObservation): void;\n observation(): StartupObservation | undefined;\n clearObservation(): void;\n notifyObservation(ctx: ExtensionContext): void;\n set(decision: RemoteSelectionDecision, origin: SyncAttentionOrigin): void;\n current(): SyncAttentionState | undefined;\n markOffered(): boolean;\n clear(ctx: ExtensionContext): void;\n reset(ctx: ExtensionContext): void;\n expand(): void;\n publish(ctx: ExtensionContext, signal?: AbortSignal): Promise<void>;\n}\n\nexport function createSyncAttentionController(): SyncAttentionController {\n let state: SyncAttentionState | undefined;\n let observation: StartupObservation | undefined;\n let generation = 0;\n let widgetState: EditorStatusWidgetState = { collapsed: false };\n\n return {\n observe(value) {\n generation++;\n observation = value;\n },\n observation() {\n return observation;\n },\n clearObservation() {\n generation++;\n observation = undefined;\n },\n notifyObservation(ctx) {\n if (ctx.hasUI && observation && observationNeedsAttention(observation)) {\n ctx.ui.notify(observationLines(observation).join(\"\\n\"), \"warning\");\n }\n },\n set(decision, origin) {\n generation++;\n state = { decision, origin, offered: false };\n },\n current() {\n return state;\n },\n markOffered() {\n if (!state || state.offered) return false;\n state = { ...state, offered: true };\n return true;\n },\n clear(ctx) {\n generation++;\n state = undefined;\n clearAttentionPresentation(ctx);\n },\n reset(ctx) {\n generation++;\n state = undefined;\n observation = undefined;\n widgetState = { collapsed: false };\n clearAttentionPresentation(ctx);\n },\n expand() {\n widgetState.collapsed = false;\n },\n async publish(ctx, signal) {\n const currentGeneration = ++generation;\n if (signal?.aborted || !ctx.hasUI) return;\n const classification = observation ? classifyObservation(observation) : \"none\";\n if (!state && (classification === \"none\" || classification === \"guidance\")) {\n clearAttentionPresentation(ctx);\n return;\n }\n if (!state && classification === \"status\") {\n ctx.ui.setWidget(WIDGET_KEY, undefined);\n setSyncStatus(ctx, observation?.inspection.remoteChanged ? \"sync \u21E3\" : \"sync \u21E1\", {\n activity: observation?.inspection.remoteChanged ? \"remote-change\" : \"local-change\",\n });\n return;\n }\n const presentation = state\n ? attentionPresentation(state.decision)\n : observationPresentation(observation as StartupObservation);\n if (ctx.mode !== \"tui\") {\n ctx.ui.setWidget(WIDGET_KEY, undefined);\n setSyncStatus(ctx, presentation.status, { activity: \"review\" });\n return;\n }\n // Keep Kit outside the eager startup graph; module loading owns no cancellable resources.\n const { EditorStatusWidget } = await import(\"./attention-widget.js\").catch((error) => {\n if (generation === currentGeneration && !signal?.aborted) clearAttentionPresentation(ctx);\n throw error;\n });\n if (generation !== currentGeneration || signal?.aborted) return;\n setSyncStatus(ctx, presentation.status, { activity: \"review\" });\n const presentationState = widgetState;\n ctx.ui.setWidget(\n WIDGET_KEY,\n (_tui, theme) =>\n new EditorStatusWidget({\n theme,\n name: \"Sync\",\n summary: \"Needs review\",\n state: presentationState,\n renderBody: (width) =>\n presentation.lines.map((line, index) =>\n width === 0 ? \"\" : truncateToWidth(theme.fg(index === 0 ? \"warning\" : \"muted\", line), width, \"\u2026\"),\n ),\n }),\n );\n },\n };\n}\n\nfunction attentionPresentation(decision: RemoteSelectionDecision) {\n const setupName = safeTerminalText(decision.setupName);\n const comparison = compareSyncInclude(decision.localInclude, decision.remoteInclude);\n return {\n status: \"sync \u21D5\",\n lines: [`Setup: ${setupName}`, selectionDifference(comparison), \"No transfer performed \u00B7 Run /sync to review\"],\n };\n}\n\nfunction selectionDifference(comparison: { remoteOnly: readonly string[]; localOnly: readonly string[] }) {\n return comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0\n ? \"Selection: only list order differs\"\n : `Selection: ${comparison.remoteOnly.length} remote-only \u00B7 ${comparison.localOnly.length} device-only`;\n}\n\nfunction observationPresentation(observation: StartupObservation) {\n const selection = observation.inspection.selectionState;\n return {\n status: \"sync \u21D5\",\n lines: [\n `Setup: ${safeTerminalText(observation.setupName)}`,\n selection?.kind === \"different\" ? selectionDifference(selection) : observationSummary(observation),\n \"No transfer performed \u00B7 Run /sync to review\",\n ],\n };\n}\n\nexport function observationMatchesConfig(observation: StartupObservation, config: AnySyncConfig) {\n return observation.configIdentity === syncCheckConfigFingerprint(config);\n}\n\nexport function observationSummary(observation: StartupObservation) {\n const result = observation.inspection;\n if (result.emptyInclude) return \"No included content selected\";\n if (result.selectionState?.kind === \"different\") return \"Synced-content list differs; review needed\";\n if (result.firstSync)\n return result.head ? \"No sync baseline; review remote and local content\" : \"Remote empty; no sync baseline\";\n if (!result.head) return \"Remote snapshot missing; review needed\";\n if (observation.automaticTransfer && result.selectionState?.kind === \"legacy\")\n return \"Legacy remote has no authoritative content list; review /sync and choose an explicit direction to adopt policy\";\n if (result.localChanged && result.remoteChanged) return \"Local and remote changed since last sync; review needed\";\n if (result.remoteChanged) return \"Remote changed since last sync\";\n if (result.localChanged) return \"Local content changed since last sync\";\n if (result.selectionState?.kind === \"legacy\") return \"Legacy remote has no authoritative content list\";\n return \"No changes detected since last sync\";\n}\n\nexport type ObservationClassification = \"none\" | \"guidance\" | \"status\" | \"review\";\n\n/** Presentation only: never discard an observation or authorize a transfer here. */\nexport function classifyObservation(observation: StartupObservation): ObservationClassification {\n const result = observation.inspection;\n // Sync now exits before reading remote content when nothing is selected.\n if (result.emptyInclude) return \"guidance\";\n // Ordering is part of the existing transfer policy, not merely display order.\n if (result.selectionState?.kind === \"different\") return \"review\";\n if (result.firstSync) return result.head ? \"review\" : \"guidance\";\n if (!result.head || (result.localChanged && result.remoteChanged)) return \"review\";\n if (observation.automaticTransfer && result.selectionState?.kind === \"legacy\") return \"review\";\n if (result.localChanged || result.remoteChanged) return \"status\";\n // Legacy metadata alone requires no scope confirmation in transfer operations.\n return \"none\";\n}\n\nexport function observationNeedsAttention(observation: StartupObservation) {\n return classifyObservation(observation) === \"review\";\n}\n\nfunction observationLines(observation: StartupObservation) {\n return [\n `Pi Sync check \u00B7 ${safeTerminalText(observation.setupName)}`,\n observationSummary(observation),\n \"No startup transfer \u00B7 Run /sync to review\",\n ];\n}\n\nfunction clearAttentionPresentation(ctx: ExtensionContext) {\n if (!ctx.hasUI) return;\n setSyncStatus(ctx, undefined);\n ctx.ui.setWidget(WIDGET_KEY, undefined);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AACA,SAAS,uBAAuB;AAShC,IAAM,aAAa;AAUZ,SAAS,2BAA2B,WAA+B,QAAuB;AAC/F,SACE,UAAU,SAAS,cAAc,OAAO,aACxC,UAAU,SAAS,mBAAmB,4BAA4B,MAAM,KACxE,gBAAgB,UAAU,SAAS,cAAc,OAAO,OAAO;AAEnE;A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,gBAAgB,OAAO,cAAe,QAAO;AAExD,SAAO;AACT;AAEO,SAAS,0BAA0B,aAAiC;AACzE,SAAO,oBAAoB,WAAW,MAAM;AAC9C;AAEA,SAAS,iBAAiB,aAAiC;AACzD,SAAO;AAAA,IACL,sBAAmB,iBAAiB,YAAY,SAAS,CAAC;AAAA,IAC1D,mBAAmB,WAAW;AAAA,IAC9B;AAAA,EACF;AACF;AAEA,SAAS,2BAA2B,KAAuB;AACzD,MAAI,CAAC,IAAI,MAAO;AAChB,gBAAc,KAAK,MAAS;AAC5B,MAAI,GAAG,UAAU,YAAY,MAAS;AACxC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from "./chunk-3ST7RSYN.ts";
|
|
6
6
|
import {
|
|
7
7
|
setSyncStatus
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-YIPK23JW.ts";
|
|
9
9
|
import {
|
|
10
10
|
withLock
|
|
11
11
|
} from "./chunk-6O3EDBRL.ts";
|
|
@@ -56,7 +56,7 @@ async function withAgentSyncLock(ctx, options, run) {
|
|
|
56
56
|
signal?.throwIfAborted();
|
|
57
57
|
});
|
|
58
58
|
await validate();
|
|
59
|
-
setSyncStatus(ctx, "sync resolving");
|
|
59
|
+
setSyncStatus(ctx, "sync resolving", { activity: "resolving" });
|
|
60
60
|
const cached = await withLock("agent-cache-read", async () => {
|
|
61
61
|
await assertOwner();
|
|
62
62
|
options.signal?.throwIfAborted();
|
|
@@ -137,4 +137,4 @@ async function withAgentSyncLock(ctx, options, run) {
|
|
|
137
137
|
export {
|
|
138
138
|
withAgentSyncLock
|
|
139
139
|
};
|
|
140
|
-
//# sourceMappingURL=chunk-
|
|
140
|
+
//# sourceMappingURL=chunk-WQMYV4DW.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/sync/agent-sync.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport type { CommandOptions } from \"../commands/command-types.js\";\nimport { withLock } from \"../state/lock.js\";\nimport { setSyncStatus } from \"../ui/sync-status.js\";\nimport { AGENT_MAX_ATTEMPTS } from \"./agent-policy.js\";\nimport { type AgentAcceptance, AgentResolutionRequired } from \"./agent-request.js\";\nimport { ContinuousError } from \"./continuous-errors.js\";\n\n/** All callers retain their existing state-directory access guard. Off stays lazy. */\nexport async function withAgentSyncLock<T>(\n ctx: ExtensionContext,\n options: CommandOptions,\n run: (options: CommandOptions) => Promise<T>,\n): Promise<T | \"cancelled\"> {\n let request: AgentResolutionRequired;\n const background = options.background;\n const retry = Boolean(options.agentRetryRefusal);\n if (retry && (options.auto || background || !ctx.hasUI || (ctx.mode !== \"tui\" && ctx.mode !== \"rpc\")))\n throw new Error(\"A refused-model retry requires a foreground TUI or RPC manager review.\");\n try {\n return await withLock(\"sync\", () => run(options));\n } catch (error) {\n if (!(error instanceof AgentResolutionRequired)) throw error;\n request = error;\n }\n const { withAgentClaim, readAgentCandidate, saveAgentCandidate, replaceRefusedAgentCandidate } = await import(\n \"./agent-store.js\"\n );\n const { parseAgentCandidate } = await import(\"./agent-candidate.js\");\n const { runAgentResolver } = await import(\"./agent-runner.js\");\n return withAgentClaim(async (assertOwner) => {\n const clearStatus = () => setSyncStatus(ctx, undefined);\n const onAbort = () => {\n try {\n clearStatus();\n } catch {\n /* UI can already be disposed. */\n }\n };\n options.signal?.addEventListener(\"abort\", onAbort, { once: true });\n try {\n options.signal?.throwIfAborted();\n for (let attempt = 0; attempt < AGENT_MAX_ATTEMPTS; attempt++) {\n let expectedRefusal: ReturnType<typeof parseAgentCandidate> | undefined;\n const validate = (signal = options.signal) =>\n withLock(\"agent-validate\", async () => {\n signal?.throwIfAborted();\n await assertOwner();\n signal?.throwIfAborted();\n if (\n expectedRefusal &&\n JSON.stringify(await readAgentCandidate(request.key)) !== JSON.stringify(expectedRefusal)\n )\n throw new Error(\"Cached refusal changed during review; reopen the manager.\");\n signal?.throwIfAborted();\n await request.validate(signal);\n signal?.throwIfAborted();\n });\n await validate();\n setSyncStatus(ctx, \"sync resolving\", { activity: \"resolving\" });\n const cached = await withLock(\"agent-cache-read\", async () => {\n await assertOwner();\n options.signal?.throwIfAborted();\n return readAgentCandidate(request.key);\n });\n options.signal?.throwIfAborted();\n if (retry) {\n if (cached === undefined)\n throw new Error(\"No eligible cached refusal for the current evidence. Use Sync now first.\");\n expectedRefusal = parseAgentCandidate(JSON.stringify(cached), request.evidence);\n if (!expectedRefusal.results.some((row) => \"refuse\" in row))\n throw new Error(\"The current cached result is not a refusal. Use Sync now.\");\n const { confirmAgentRefusalRetry } = await import(\"./agent-refusal-retry.js\");\n options.signal?.throwIfAborted();\n if (!(await confirmAgentRefusalRetry(ctx, options.setup, request.evidence, validate, options.signal)))\n return \"cancelled\" as const;\n }\n const raw =\n cached === undefined || retry\n ? await runAgentResolver(\n ctx,\n request.evidence,\n validate,\n options.signal,\n background ? (signal) => background.reserve(request.key, signal) : undefined,\n )\n : JSON.stringify(cached);\n let candidate: ReturnType<typeof parseAgentCandidate>;\n try {\n candidate = parseAgentCandidate(raw, request.evidence);\n } catch {\n throw new ContinuousError(\"model\", \"Autonomous sync paused: invalid resolver output; evidence retained.\");\n }\n if (retry && candidate.results.some((row) => \"refuse\" in row))\n throw new ContinuousError(\"model\", \"The model refused again. The previous refusal was retained.\");\n await validate();\n const previous = expectedRefusal;\n if (!previous)\n await withLock(\"agent-cache-save\", async () => {\n await assertOwner();\n options.signal?.throwIfAborted();\n await saveAgentCandidate(request.key, candidate);\n });\n let retryCacheCommitted = false;\n const acceptance: AgentAcceptance = {\n key: request.key,\n candidate,\n ...(previous\n ? {\n commitCandidate: async () => {\n if (retryCacheCommitted) return;\n await replaceRefusedAgentCandidate(request.key, previous, candidate, async () => {\n options.signal?.throwIfAborted();\n await assertOwner();\n await request.validate(options.signal);\n options.signal?.throwIfAborted();\n });\n retryCacheCommitted = true;\n },\n }\n : {}),\n };\n try {\n return await withLock(\"sync\", async () => {\n await assertOwner();\n options.signal?.throwIfAborted();\n return run({ ...options, agentAcceptance: acceptance });\n });\n } catch (error) {\n if (!(error instanceof AgentResolutionRequired)) throw error;\n if (retry) throw new ContinuousError(\"stale\", \"Reviewed refusal evidence changed; reopen the manager.\");\n request = error;\n }\n }\n throw new ContinuousError(\"stale\", \"Autonomous sync paused: content changed repeatedly; retry later.\");\n } finally {\n options.signal?.removeEventListener(\"abort\", onAbort);\n if (!options.signal?.aborted) clearStatus();\n }\n });\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AASA,eAAsB,kBACpB,KACA,SACA,KAC0B;AAC1B,MAAI;AACJ,QAAM,aAAa,QAAQ;AAC3B,QAAM,QAAQ,QAAQ,QAAQ,iBAAiB;AAC/C,MAAI,UAAU,QAAQ,QAAQ,cAAc,CAAC,IAAI,SAAU,IAAI,SAAS,SAAS,IAAI,SAAS;AAC5F,UAAM,IAAI,MAAM,wEAAwE;AAC1F,MAAI;AACF,WAAO,MAAM,SAAS,QAAQ,MAAM,IAAI,OAAO,CAAC;AAAA,EAClD,SAAS,OAAO;AACd,QAAI,EAAE,iBAAiB,yBAA0B,OAAM;AACvD,cAAU;AAAA,EACZ;AACA,QAAM,EAAE,gBAAgB,oBAAoB,oBAAoB,6BAA6B,IAAI,MAAM,OACrG,2BACF;AACA,QAAM,EAAE,oBAAoB,IAAI,MAAM,OAAO,+BAAsB;AACnE,QAAM,EAAE,iBAAiB,IAAI,MAAM,OAAO,4BAAmB;AAC7D,SAAO,eAAe,OAAO,gBAAgB;AAC3C,UAAM,cAAc,MAAM,cAAc,KAAK,MAAS;AACtD,UAAM,UAAU,MAAM;AACpB,UAAI;AACF,oBAAY;AAAA,MACd,QAAQ;AAAA,MAER;AAAA,IACF;AACA,YAAQ,QAAQ,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;AACjE,QAAI;AAC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