@narumitw/pi-sync 0.60.0 → 0.60.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 +6 -0
- package/README.md +6 -7
- package/dist/chunks/{chunk-MIXZVHFR.ts → chunk-6LHIRS5R.ts} +7 -38
- package/dist/chunks/chunk-6LHIRS5R.ts.map +7 -0
- package/dist/chunks/{command-handler-3O76V7Q5.ts → command-handler-FO4XBBHF.ts} +3 -3
- package/dist/chunks/continuous-storage-SQBAXACF.ts +27 -0
- package/dist/chunks/continuous-storage-SQBAXACF.ts.map +7 -0
- package/dist/chunks/{manager-ui-SJOBTJLY.ts → manager-ui-AY5ZU6B4.ts} +103 -44
- package/dist/chunks/manager-ui-AY5ZU6B4.ts.map +7 -0
- package/dist/index.ts +2 -2
- package/docs/tui-contract.md +12 -0
- package/package.json +1 -1
- package/src/ui/manager-state.ts +35 -23
- package/src/ui/manager-ui.ts +80 -36
- package/src/ui/sync-attention.ts +7 -49
- package/dist/chunks/chunk-MIXZVHFR.ts.map +0 -7
- package/dist/chunks/manager-ui-SJOBTJLY.ts.map +0 -7
- /package/dist/chunks/{command-handler-3O76V7Q5.ts.map → command-handler-FO4XBBHF.ts.map} +0 -0
package/src/ui/manager-state.ts
CHANGED
|
@@ -14,15 +14,13 @@ import { readStateForConfig, syncStateFingerprint } from "../state/sync-state-st
|
|
|
14
14
|
import { sameSyncExclude } from "../sync/exclude-policy.js";
|
|
15
15
|
import { errorMessage } from "../sync/sync-errors.js";
|
|
16
16
|
import type { StartupObservation } from "../sync/sync-inspection.js";
|
|
17
|
-
import { compareSyncInclude,
|
|
18
|
-
import { automaticSyncSummary } from "./automatic-sync-summary.js";
|
|
17
|
+
import { compareSyncInclude, syncSessionsSelected } from "../sync/sync-policy.js";
|
|
19
18
|
import {
|
|
20
19
|
observationMatchesConfig,
|
|
21
20
|
observationSummary,
|
|
22
21
|
type SyncAttentionState,
|
|
23
22
|
syncAttentionMatchesConfig,
|
|
24
23
|
} from "./sync-attention.js";
|
|
25
|
-
import { startupTransferSummary } from "./sync-behavior.js";
|
|
26
24
|
import { countValidSyncSetups } from "./sync-setups-ui.js";
|
|
27
25
|
import { safeTerminalText } from "./terminal-text.js";
|
|
28
26
|
|
|
@@ -99,7 +97,6 @@ export async function describeManagerState(
|
|
|
99
97
|
const config = await loadConfig();
|
|
100
98
|
const operation = await inspectOperation();
|
|
101
99
|
const changesBlocked = operationBlocksChanges(operation);
|
|
102
|
-
const selection = syncIncludeSelection(config.include);
|
|
103
100
|
let currentAttention: SyncAttentionState | undefined;
|
|
104
101
|
if (attention) {
|
|
105
102
|
try {
|
|
@@ -129,7 +126,7 @@ export async function describeManagerState(
|
|
|
129
126
|
const lastAppliedSnapshot = changesBlocked
|
|
130
127
|
? "Unavailable while operations are locked"
|
|
131
128
|
: syncState?.lastAppliedSnapshot
|
|
132
|
-
? `${truncateToWidth(safeTerminalText(syncState.lastAppliedSnapshot),
|
|
129
|
+
? `${truncateToWidth(safeTerminalText(syncState.lastAppliedSnapshot), 12, "…")} · application time unavailable`
|
|
133
130
|
: syncState
|
|
134
131
|
? "Never synced"
|
|
135
132
|
: "Unavailable";
|
|
@@ -138,17 +135,14 @@ export async function describeManagerState(
|
|
|
138
135
|
if (config.agentMode && !noSyncedContent) mainActions.splice(1, 0, "Retry refused model result…");
|
|
139
136
|
if (canSwitch) mainActions.push("Switch sync setup");
|
|
140
137
|
if (syncState?.unresolved?.length) mainActions.unshift("Review unresolved conflicts");
|
|
138
|
+
const background = changesBlocked ? [] : await backgroundSummary(config);
|
|
139
|
+
signal?.throwIfAborted();
|
|
141
140
|
const ordinaryTitle = [
|
|
142
141
|
"Manage sync",
|
|
143
|
-
"",
|
|
144
142
|
`Current sync setup: ${safeTerminalText(config.setupName)}`,
|
|
145
143
|
`Storage: ${backendStorageDescription(config)}`,
|
|
146
|
-
"CURRENT STATE",
|
|
147
144
|
...(syncState?.unresolved?.length
|
|
148
|
-
? [
|
|
149
|
-
`Unresolved: ${syncState.unresolved.length} dependency groups · choose Review unresolved conflicts`,
|
|
150
|
-
`Last observed: ${safeTerminalText(syncState.lastObservedSnapshot ?? "unknown")}`,
|
|
151
|
-
]
|
|
145
|
+
? [`Unresolved: ${syncState.unresolved.length} dependency groups · review needed`]
|
|
152
146
|
: []),
|
|
153
147
|
...(currentAttention
|
|
154
148
|
? [
|
|
@@ -160,25 +154,20 @@ export async function describeManagerState(
|
|
|
160
154
|
? "Synced-content exclusion rules differ."
|
|
161
155
|
: "Only the synced-content order differs."
|
|
162
156
|
: `Remote-only paths: ${attentionComparison?.remoteOnly.length ?? 0} · Device-only paths: ${attentionComparison?.localOnly.length ?? 0}${attentionExclusionsDiffer ? " · Exclusion rules differ." : ""}`,
|
|
163
|
-
"Nothing has been changed.",
|
|
164
157
|
]
|
|
165
158
|
: currentObservation
|
|
166
|
-
? [
|
|
167
|
-
`Startup check (${safeTerminalText(currentObservation.checkedAt)}): ${observationSummary(currentObservation)}`,
|
|
168
|
-
"Check-time observation only; synchronization rechecks current content.",
|
|
169
|
-
]
|
|
159
|
+
? [`Observed ${safeTerminalText(currentObservation.checkedAt)}: ${observationSummary(currentObservation)}`]
|
|
170
160
|
: ["Remote status: Not checked"]),
|
|
171
|
-
`Included: ${selection.builtIns.length} built-in group${selection.builtIns.length === 1 ? "" : "s"} · ${selection.custom.length} extra path${selection.custom.length === 1 ? "" : "s"} · Sessions ${syncSessionsSelected(config) ? "on" : "off"}`,
|
|
172
|
-
`Automatic sync: ${automaticSyncSummary(config.automatic)}`,
|
|
173
|
-
`Startup transfer: ${startupTransferSummary(config)}`,
|
|
174
|
-
`Autonomous sync: ${config.agentMode ? "On (autonomous merged sync)" : "Off"}`,
|
|
175
|
-
...(config.continuous ? await (await import("../sync/continuous-record.js")).continuousStatusLines(config) : []),
|
|
176
161
|
`Last applied: ${lastAppliedSnapshot}`,
|
|
162
|
+
...(config.agentMode
|
|
163
|
+
? ["Auto-apply: On · AI requests may incur costs"]
|
|
164
|
+
: config.automaticTransfer || (config.automatic && syncSessionsSelected(config))
|
|
165
|
+
? ["Automatic transfer permission: On · see Settings"]
|
|
166
|
+
: []),
|
|
167
|
+
...background,
|
|
177
168
|
...(noSyncedContent
|
|
178
169
|
? ["", "No included content is selected. Choose included content in Settings before syncing."]
|
|
179
170
|
: []),
|
|
180
|
-
"",
|
|
181
|
-
"ACTIONS · transfer, inspect, or manage",
|
|
182
171
|
];
|
|
183
172
|
return {
|
|
184
173
|
title: (changesBlocked ? ["Manage sync", ...operationStatusLines(operation)] : ordinaryTitle).join("\n"),
|
|
@@ -212,6 +201,29 @@ export async function describeManagerState(
|
|
|
212
201
|
}
|
|
213
202
|
}
|
|
214
203
|
|
|
204
|
+
async function backgroundSummary(config: AnySyncConfig): Promise<string[]> {
|
|
205
|
+
if (!config.continuous) return [];
|
|
206
|
+
if (!config.agentMode) return ["Background sync: Paused · enable Autonomous sync"];
|
|
207
|
+
try {
|
|
208
|
+
const { continuousBinding, readContinuousPrivateDocument } = await import("../sync/continuous-storage.js");
|
|
209
|
+
const recordApi: typeof import("../sync/continuous-record.js") = await import("../sync/continuous-record.js");
|
|
210
|
+
const binding = await continuousBinding(config);
|
|
211
|
+
const document = await readContinuousPrivateDocument(`${binding}.json`);
|
|
212
|
+
if (!document) return ["Background sync: Enabled · not yet observed"];
|
|
213
|
+
recordApi.validateContinuousRecord(document.value, binding);
|
|
214
|
+
const record = document.value;
|
|
215
|
+
const phases = { waiting: "Waiting", syncing: "Syncing", retry: "Retry", blocked: "Blocked" };
|
|
216
|
+
return [
|
|
217
|
+
`Background sync (recorded): ${phases[record.phase]}${record.error ? ` · ${record.error}` : ""}`,
|
|
218
|
+
...(record.transferred === undefined
|
|
219
|
+
? []
|
|
220
|
+
: [`Last background transfer: Success · ${new Date(record.transferred).toISOString()}`]),
|
|
221
|
+
];
|
|
222
|
+
} catch {
|
|
223
|
+
return ["Background sync: Unknown · open Diagnostics"];
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
215
227
|
function operationActions(
|
|
216
228
|
operation: OperationAvailability,
|
|
217
229
|
noSyncedContent: boolean,
|
package/src/ui/manager-ui.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import type { Component } from "@earendil-works/pi-tui";
|
|
3
|
-
import { type ActionMenuItem, defineMenu, runMenu } from "@narumitw/pi-tui-kit";
|
|
3
|
+
import { type ActionMenuItem, defineMenu, type MenuDefinition, runDocumentReview, runMenu } from "@narumitw/pi-tui-kit";
|
|
4
4
|
import { loadConfig, syncCheckConfigFingerprint } from "../settings/config.js";
|
|
5
5
|
import { operationBlocksChanges } from "../state/operation-availability.js";
|
|
6
6
|
import { captureMutationOwner } from "../sync/sync-local.js";
|
|
@@ -42,6 +42,7 @@ export async function showSyncManager(
|
|
|
42
42
|
};
|
|
43
43
|
type Screen = "main";
|
|
44
44
|
type Action =
|
|
45
|
+
| "activate"
|
|
45
46
|
| "review-attention"
|
|
46
47
|
| "retry-refusal"
|
|
47
48
|
| "sync"
|
|
@@ -63,29 +64,45 @@ export async function showSyncManager(
|
|
|
63
64
|
interface State {
|
|
64
65
|
manager: Awaited<ReturnType<typeof describeManagerState>>;
|
|
65
66
|
}
|
|
66
|
-
const
|
|
67
|
+
const menuItems = (manager: State["manager"]) => {
|
|
68
|
+
const attentionItems = attentionMainMenuItems(manager);
|
|
69
|
+
const managerItems = manager.actions.map((label) => blockedSyncMenuItem(label, manager) ?? syncMainMenuItem(label));
|
|
70
|
+
const operationFirst = manager.operation !== undefined && manager.operation.kind !== "free";
|
|
71
|
+
return operationFirst ? [...managerItems, ...attentionItems] : [...attentionItems, ...managerItems];
|
|
72
|
+
};
|
|
73
|
+
const menu: MenuDefinition<State, Screen, Action, ExtensionCommandContext> = defineMenu<
|
|
74
|
+
State,
|
|
75
|
+
Screen,
|
|
76
|
+
Action,
|
|
77
|
+
ExtensionCommandContext
|
|
78
|
+
>({
|
|
67
79
|
start: "main",
|
|
68
80
|
screens: {
|
|
69
|
-
main: ({ state }) => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
},
|
|
81
|
+
main: ({ state }) => ({
|
|
82
|
+
kind: "choice",
|
|
83
|
+
title: "Manage sync",
|
|
84
|
+
lines: state.manager.title.split("\n").slice(1),
|
|
85
|
+
items: menuItems(state.manager).map((item) => ({
|
|
86
|
+
id: item.id,
|
|
87
|
+
label: ctx.mode === "tui" && item.id === "sync" ? "Sync…" : item.label,
|
|
88
|
+
details: [item.description ?? "Review synced content."],
|
|
89
|
+
searchText: `${item.label} ${item.description ?? ""}`,
|
|
90
|
+
disabled: item.disabled,
|
|
91
|
+
disabledReason: item.disabledReason,
|
|
92
|
+
})),
|
|
93
|
+
action: "activate",
|
|
94
|
+
enableSearch: true,
|
|
95
|
+
viewportSize: 5,
|
|
96
|
+
hint: "close",
|
|
97
|
+
}),
|
|
87
98
|
},
|
|
88
99
|
actions: {
|
|
100
|
+
activate: async (invocation) => {
|
|
101
|
+
const item = menuItems(invocation.state.manager).find((candidate) => candidate.id === invocation.itemId);
|
|
102
|
+
if (!item || item.disabled || !("action" in item) || !item.action) return { kind: "stay" };
|
|
103
|
+
// Forward through the handlers below after their setup-ownership guards are installed.
|
|
104
|
+
return menu.actions[item.action](invocation);
|
|
105
|
+
},
|
|
89
106
|
"review-attention": async ({ state }) => {
|
|
90
107
|
const attention = state.manager.attention;
|
|
91
108
|
if (attention && options.getAttention?.() !== attention) return { kind: "stay" };
|
|
@@ -224,6 +241,30 @@ export async function showSyncManager(
|
|
|
224
241
|
const validate = captureMutationOwner(ctx, signal);
|
|
225
242
|
const config = await loadConfig(state.manager.configReview?.setupName);
|
|
226
243
|
validate();
|
|
244
|
+
if (config.continuous) {
|
|
245
|
+
const { continuousStatusLines } = await import("../sync/continuous-record.js");
|
|
246
|
+
validate();
|
|
247
|
+
const lines = await continuousStatusLines(config);
|
|
248
|
+
validate();
|
|
249
|
+
const review = await runDocumentReview(ctx, {
|
|
250
|
+
title: "Sync diagnostics",
|
|
251
|
+
lines: [`Setup: ${safeTerminalText(config.setupName)} · local observations only`],
|
|
252
|
+
content: lines.join("\n"),
|
|
253
|
+
confirmation: { label: "Continue to backend checks…" },
|
|
254
|
+
hint: "back",
|
|
255
|
+
signal,
|
|
256
|
+
isCurrent,
|
|
257
|
+
});
|
|
258
|
+
validate();
|
|
259
|
+
if (review.kind === "cancelled") return { kind: review.reason === "close" ? "close" : "stay" };
|
|
260
|
+
if (review.kind !== "confirmed") return { kind: "stay" };
|
|
261
|
+
const current = await loadConfig();
|
|
262
|
+
validate();
|
|
263
|
+
if (syncCheckConfigFingerprint(config) !== syncCheckConfigFingerprint(current)) {
|
|
264
|
+
ctx.ui.notify("Setup changed during diagnostics review; reopen Diagnostics.", "warning");
|
|
265
|
+
return { kind: "stay" };
|
|
266
|
+
}
|
|
267
|
+
}
|
|
227
268
|
const confirmed = await ctx.ui.confirm(
|
|
228
269
|
"Run diagnostics?",
|
|
229
270
|
`Setup: ${safeTerminalText(config.setupName)}\nStorage: ${backendStorageDescription(config)}\nS3/R2 reads the latest pointer without writing. Git reads remote snapshots and checks its cache. WebDAV probes conditional writes and cleanup, and can repair a missing history entry. Possible-secret checks still run. This is not the read-only Check remote status action.`,
|
|
@@ -397,21 +438,24 @@ function syncMainMenuItem(
|
|
|
397
438
|
id: action,
|
|
398
439
|
label,
|
|
399
440
|
action,
|
|
400
|
-
description:
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
441
|
+
description: {
|
|
442
|
+
sync: "Merge changes on both sides.",
|
|
443
|
+
"retry-refusal": "Retry model; may incur costs.",
|
|
444
|
+
pull: "Remote → this device.",
|
|
445
|
+
push: "This device → remote snapshot.",
|
|
446
|
+
diff: "Inspect changes; no transfer.",
|
|
447
|
+
status: "Check remote; no transfer.",
|
|
448
|
+
settings: "Change sync settings.",
|
|
449
|
+
history: "Review snapshots and rollback.",
|
|
450
|
+
doctor: "Review backend diagnostics.",
|
|
451
|
+
switch: "Choose another sync setup.",
|
|
452
|
+
conflicts: "Review unresolved file groups.",
|
|
453
|
+
recover: "Review local lock recovery.",
|
|
454
|
+
refresh: "Recheck the operation lock.",
|
|
455
|
+
setups: "Manage sync setups.",
|
|
456
|
+
connections: "Manage storage connections.",
|
|
457
|
+
help: "Read sync commands and safety.",
|
|
458
|
+
init: "Configure a sync setup.",
|
|
459
|
+
}[action],
|
|
416
460
|
};
|
|
417
461
|
}
|
package/src/ui/sync-attention.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { syncCheckConfigFingerprint, syncConfigReviewFingerprint } from "../sett
|
|
|
5
5
|
import type { AnySyncConfig } from "../settings/settings-types.js";
|
|
6
6
|
import { sameSyncExclude } from "../sync/exclude-policy.js";
|
|
7
7
|
import type { StartupObservation } from "../sync/sync-inspection.js";
|
|
8
|
-
import {
|
|
8
|
+
import { type RemoteSelectionDecision, sameSyncInclude } from "../sync/sync-policy.js";
|
|
9
9
|
import { setSyncStatus } from "./sync-status.js";
|
|
10
10
|
import { safeTerminalText } from "./terminal-text.js";
|
|
11
11
|
|
|
@@ -107,12 +107,10 @@ export function createSyncAttentionController(): SyncAttentionController {
|
|
|
107
107
|
});
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
110
|
-
const
|
|
111
|
-
? attentionPresentation(state.decision)
|
|
112
|
-
: observationPresentation(observation as StartupObservation);
|
|
110
|
+
const setupName = safeTerminalText(state?.decision.setupName ?? observation?.setupName ?? "");
|
|
113
111
|
if (ctx.mode !== "tui") {
|
|
114
112
|
ctx.ui.setWidget(WIDGET_KEY, undefined);
|
|
115
|
-
setSyncStatus(ctx,
|
|
113
|
+
setSyncStatus(ctx, "sync ⇕", { activity: "review" });
|
|
116
114
|
return;
|
|
117
115
|
}
|
|
118
116
|
// Keep Kit outside the eager startup graph; module loading owns no cancellable resources.
|
|
@@ -121,7 +119,7 @@ export function createSyncAttentionController(): SyncAttentionController {
|
|
|
121
119
|
throw error;
|
|
122
120
|
});
|
|
123
121
|
if (generation !== currentGeneration || signal?.aborted) return;
|
|
124
|
-
setSyncStatus(ctx,
|
|
122
|
+
setSyncStatus(ctx, "sync ⇕", { activity: "review" });
|
|
125
123
|
const presentationState = widgetState;
|
|
126
124
|
ctx.ui.setWidget(
|
|
127
125
|
WIDGET_KEY,
|
|
@@ -131,55 +129,15 @@ export function createSyncAttentionController(): SyncAttentionController {
|
|
|
131
129
|
name: "Sync",
|
|
132
130
|
summary: "Needs review",
|
|
133
131
|
state: presentationState,
|
|
134
|
-
renderBody: (width) =>
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
),
|
|
132
|
+
renderBody: (width) => [
|
|
133
|
+
width === 0 ? "" : truncateToWidth(theme.fg("muted", `Open /sync to review · ${setupName}`), width, "…"),
|
|
134
|
+
],
|
|
138
135
|
}),
|
|
139
136
|
);
|
|
140
137
|
},
|
|
141
138
|
};
|
|
142
139
|
}
|
|
143
140
|
|
|
144
|
-
function attentionPresentation(decision: RemoteSelectionDecision) {
|
|
145
|
-
const setupName = safeTerminalText(decision.setupName);
|
|
146
|
-
const comparison = compareSyncInclude(decision.localInclude, decision.remoteInclude);
|
|
147
|
-
return {
|
|
148
|
-
status: "sync ⇕",
|
|
149
|
-
lines: [
|
|
150
|
-
`Setup: ${setupName}`,
|
|
151
|
-
selectionDifference({
|
|
152
|
-
...comparison,
|
|
153
|
-
excludeChanged: !sameSyncExclude(decision.localExclude, decision.remoteExclude),
|
|
154
|
-
}),
|
|
155
|
-
"No transfer performed · Run /sync to review",
|
|
156
|
-
],
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function selectionDifference(comparison: {
|
|
161
|
-
remoteOnly: readonly string[];
|
|
162
|
-
localOnly: readonly string[];
|
|
163
|
-
excludeChanged?: boolean;
|
|
164
|
-
}) {
|
|
165
|
-
if (comparison.excludeChanged) return "Selection: excluded paths differ; review needed";
|
|
166
|
-
return comparison.remoteOnly.length === 0 && comparison.localOnly.length === 0
|
|
167
|
-
? "Selection: only list order differs"
|
|
168
|
-
: `Selection: ${comparison.remoteOnly.length} remote-only · ${comparison.localOnly.length} device-only`;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function observationPresentation(observation: StartupObservation) {
|
|
172
|
-
const selection = observation.inspection.selectionState;
|
|
173
|
-
return {
|
|
174
|
-
status: "sync ⇕",
|
|
175
|
-
lines: [
|
|
176
|
-
`Setup: ${safeTerminalText(observation.setupName)}`,
|
|
177
|
-
selection?.kind === "different" ? selectionDifference(selection) : observationSummary(observation),
|
|
178
|
-
"No transfer performed · Run /sync to review",
|
|
179
|
-
],
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
|
|
183
141
|
export function observationMatchesConfig(observation: StartupObservation, config: AnySyncConfig) {
|
|
184
142
|
return observation.configIdentity === syncCheckConfigFingerprint(config);
|
|
185
143
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/state/sync-state-store.ts", "../../src/ui/sync-attention.ts"],
|
|
4
|
-
"sourcesContent": ["export type * from \"@narumitw/sync-daemon/engine/state/sync-state-store\";\nexport {\n ensureStateDir,\n lockPath,\n readState,\n readStateForConfig,\n statePathForConfig,\n syncStateFingerprint,\n writeState,\n writeStateForConfig,\n} from \"@narumitw/sync-daemon/engine/state/sync-state-store\";\n", "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 { sameSyncExclude } from \"../sync/exclude-policy.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 sameSyncExclude(attention.decision.localExclude, config.exclude)\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: [\n `Setup: ${setupName}`,\n selectionDifference({\n ...comparison,\n excludeChanged: !sameSyncExclude(decision.localExclude, decision.remoteExclude),\n }),\n \"No transfer performed \u00B7 Run /sync to review\",\n ],\n };\n}\n\nfunction selectionDifference(comparison: {\n remoteOnly: readonly string[];\n localOnly: readonly string[];\n excludeChanged?: boolean;\n}) {\n if (comparison.excludeChanged) return \"Selection: excluded paths differ; review needed\";\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;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACTP,SAAS,uBAAuB;AAUhC,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,O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