@narumitw/pi-sync 0.50.0 → 0.50.2
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/README.md +5 -4
- package/dist/chunks/attention-widget-Z7G3SYYJ.ts +9 -0
- package/dist/chunks/attention-widget-Z7G3SYYJ.ts.map +7 -0
- package/dist/chunks/{chunk-YKJHPTGO.ts → chunk-4CHTZMEO.ts} +2 -2
- package/dist/chunks/{chunk-6UHKGALE.ts → chunk-5B3FXBLE.ts} +51 -17
- package/dist/chunks/chunk-5B3FXBLE.ts.map +7 -0
- package/dist/chunks/{chunk-JSYMGJQQ.ts → chunk-CCSN3F47.ts} +4 -4
- package/dist/chunks/{chunk-GWMHAQG4.ts → chunk-ETTRJDNP.ts} +2 -2
- package/dist/chunks/{chunk-X5OM6GXT.ts → chunk-G4RNQQZS.ts} +2 -2
- package/dist/chunks/{chunk-AXXS2BPA.ts → chunk-IJ6FJFA5.ts} +2 -2
- package/dist/chunks/{chunk-OUHGBFYF.ts → chunk-KW7YQEZN.ts} +4 -4
- package/dist/chunks/{chunk-XBX4HBLG.ts → chunk-SZWBGPID.ts} +5 -5
- package/dist/chunks/{chunk-L7TBO32M.ts → chunk-T2B5IU74.ts} +3 -3
- package/dist/chunks/{git-backend-OQW46G2X.ts → git-backend-GMVS4PD4.ts} +8 -8
- package/dist/chunks/{manager-result-dispatcher-U23ODD32.ts → manager-result-dispatcher-FKIBM3GO.ts} +4 -4
- package/dist/chunks/{manager-ui-ABATHC36.ts → manager-ui-5KLKVMRC.ts} +18 -18
- package/dist/chunks/{remote-selection-ui-ZE3TY67S.ts → remote-selection-ui-D7RBRJNL.ts} +3 -3
- package/dist/chunks/{s3-backend-3P33LQHU.ts → s3-backend-66O4FGBH.ts} +6 -6
- package/dist/chunks/{setup-wizard-VB3VDOV5.ts → setup-wizard-IUB6ESEU.ts} +3 -3
- package/dist/chunks/{sync-inspection-FEP4L5TR.ts → sync-inspection-CST2KL65.ts} +5 -5
- package/dist/chunks/{sync-operations-ONJ27QRL.ts → sync-operations-LBX3GKCM.ts} +23 -23
- package/dist/index.ts +20 -20
- package/dist/index.ts.map +2 -2
- package/package.json +1 -1
- package/src/commands/command-handler.ts +2 -2
- package/src/sync/startup-check.ts +1 -1
- package/src/ui/attention-widget.ts +1 -0
- package/src/ui/sync-attention.ts +65 -23
- package/dist/chunks/chunk-6UHKGALE.ts.map +0 -7
- /package/dist/chunks/{chunk-YKJHPTGO.ts.map → chunk-4CHTZMEO.ts.map} +0 -0
- /package/dist/chunks/{chunk-JSYMGJQQ.ts.map → chunk-CCSN3F47.ts.map} +0 -0
- /package/dist/chunks/{chunk-GWMHAQG4.ts.map → chunk-ETTRJDNP.ts.map} +0 -0
- /package/dist/chunks/{chunk-X5OM6GXT.ts.map → chunk-G4RNQQZS.ts.map} +0 -0
- /package/dist/chunks/{chunk-AXXS2BPA.ts.map → chunk-IJ6FJFA5.ts.map} +0 -0
- /package/dist/chunks/{chunk-OUHGBFYF.ts.map → chunk-KW7YQEZN.ts.map} +0 -0
- /package/dist/chunks/{chunk-XBX4HBLG.ts.map → chunk-SZWBGPID.ts.map} +0 -0
- /package/dist/chunks/{chunk-L7TBO32M.ts.map → chunk-T2B5IU74.ts.map} +0 -0
- /package/dist/chunks/{git-backend-OQW46G2X.ts.map → git-backend-GMVS4PD4.ts.map} +0 -0
- /package/dist/chunks/{manager-result-dispatcher-U23ODD32.ts.map → manager-result-dispatcher-FKIBM3GO.ts.map} +0 -0
- /package/dist/chunks/{manager-ui-ABATHC36.ts.map → manager-ui-5KLKVMRC.ts.map} +0 -0
- /package/dist/chunks/{remote-selection-ui-ZE3TY67S.ts.map → remote-selection-ui-D7RBRJNL.ts.map} +0 -0
- /package/dist/chunks/{s3-backend-3P33LQHU.ts.map → s3-backend-66O4FGBH.ts.map} +0 -0
- /package/dist/chunks/{setup-wizard-VB3VDOV5.ts.map → setup-wizard-IUB6ESEU.ts.map} +0 -0
- /package/dist/chunks/{sync-inspection-FEP4L5TR.ts.map → sync-inspection-CST2KL65.ts.map} +0 -0
- /package/dist/chunks/{sync-operations-ONJ27QRL.ts.map → sync-operations-LBX3GKCM.ts.map} +0 -0
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
// @generated by scripts/build-runtime.mjs; do not edit.
|
|
2
2
|
// @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
|
|
3
|
+
import {
|
|
4
|
+
formatRemoteSelectionStatus,
|
|
5
|
+
readRemoteSnapshot,
|
|
6
|
+
readSnapshotForHead,
|
|
7
|
+
requireCompatibleRemoteSelection
|
|
8
|
+
} from "./chunk-HUDQATCL.ts";
|
|
3
9
|
import {
|
|
4
10
|
inspectSync
|
|
5
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-SZWBGPID.ts";
|
|
12
|
+
import {
|
|
13
|
+
createSyncBackend
|
|
14
|
+
} from "./chunk-T2B5IU74.ts";
|
|
6
15
|
import {
|
|
7
16
|
canPullRemoteSessionsOnFirstSync,
|
|
8
17
|
canPullRemoteSettingsOnFirstSync,
|
|
@@ -19,38 +28,20 @@ import {
|
|
|
19
28
|
import {
|
|
20
29
|
applySnapshotTransaction,
|
|
21
30
|
recoverPendingSnapshotTransactions
|
|
22
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-IJ6FJFA5.ts";
|
|
23
32
|
import {
|
|
24
33
|
inspectLock,
|
|
25
34
|
isLockGuardHeld,
|
|
26
35
|
isStaleLock,
|
|
27
36
|
withLock
|
|
28
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-ETTRJDNP.ts";
|
|
29
38
|
import {
|
|
30
39
|
throwIfAborted
|
|
31
40
|
} from "./chunk-NJFUIVYL.ts";
|
|
32
41
|
import {
|
|
33
42
|
readStateForConfig,
|
|
34
43
|
writeStateForConfig
|
|
35
|
-
} from "./chunk-
|
|
36
|
-
import {
|
|
37
|
-
encodeSnapshot
|
|
38
|
-
} from "./chunk-Q2TUM5X6.ts";
|
|
39
|
-
import {
|
|
40
|
-
stateDir
|
|
41
|
-
} from "./chunk-ZI5MXMEX.ts";
|
|
42
|
-
import {
|
|
43
|
-
expectedRemoteHead
|
|
44
|
-
} from "./chunk-D5X27LCA.ts";
|
|
45
|
-
import {
|
|
46
|
-
formatRemoteSelectionStatus,
|
|
47
|
-
readRemoteSnapshot,
|
|
48
|
-
readSnapshotForHead,
|
|
49
|
-
requireCompatibleRemoteSelection
|
|
50
|
-
} from "./chunk-HUDQATCL.ts";
|
|
51
|
-
import {
|
|
52
|
-
createSyncBackend
|
|
53
|
-
} from "./chunk-L7TBO32M.ts";
|
|
44
|
+
} from "./chunk-CCSN3F47.ts";
|
|
54
45
|
import {
|
|
55
46
|
safeTerminalText
|
|
56
47
|
} from "./chunk-LTBWGSBV.ts";
|
|
@@ -60,7 +51,16 @@ import {
|
|
|
60
51
|
syncSessionsWarnings
|
|
61
52
|
} from "./chunk-C7XY5NF5.ts";
|
|
62
53
|
import "./chunk-6LP3MCR2.ts";
|
|
54
|
+
import {
|
|
55
|
+
encodeSnapshot
|
|
56
|
+
} from "./chunk-Q2TUM5X6.ts";
|
|
57
|
+
import {
|
|
58
|
+
stateDir
|
|
59
|
+
} from "./chunk-ZI5MXMEX.ts";
|
|
63
60
|
import "./chunk-TEN2ZBJV.ts";
|
|
61
|
+
import {
|
|
62
|
+
expectedRemoteHead
|
|
63
|
+
} from "./chunk-D5X27LCA.ts";
|
|
64
64
|
import {
|
|
65
65
|
SyncDecisionRequiredError,
|
|
66
66
|
errorMessage
|
|
@@ -1191,4 +1191,4 @@ export {
|
|
|
1191
1191
|
status,
|
|
1192
1192
|
syncBoth
|
|
1193
1193
|
};
|
|
1194
|
-
//# sourceMappingURL=sync-operations-
|
|
1194
|
+
//# sourceMappingURL=sync-operations-LBX3GKCM.ts.map
|
package/dist/index.ts
CHANGED
|
@@ -4,14 +4,14 @@ import {
|
|
|
4
4
|
createSyncAttentionController,
|
|
5
5
|
observationMatchesConfig,
|
|
6
6
|
syncAttentionMatchesConfig
|
|
7
|
-
} from "./chunks/chunk-
|
|
7
|
+
} from "./chunks/chunk-5B3FXBLE.ts";
|
|
8
8
|
import {
|
|
9
9
|
recoverSnapshotTransactionsOnStartup
|
|
10
|
-
} from "./chunks/chunk-
|
|
10
|
+
} from "./chunks/chunk-IJ6FJFA5.ts";
|
|
11
11
|
import {
|
|
12
12
|
unlock,
|
|
13
13
|
withLock
|
|
14
|
-
} from "./chunks/chunk-
|
|
14
|
+
} from "./chunks/chunk-ETTRJDNP.ts";
|
|
15
15
|
import {
|
|
16
16
|
combineSignals,
|
|
17
17
|
throwIfAborted
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
ensureStateDir,
|
|
21
21
|
readStateForConfig,
|
|
22
22
|
syncStateFingerprint
|
|
23
|
-
} from "./chunks/chunk-
|
|
23
|
+
} from "./chunks/chunk-CCSN3F47.ts";
|
|
24
24
|
import {
|
|
25
25
|
automaticSyncSummary
|
|
26
26
|
} from "./chunks/chunk-Z4DQF6L3.ts";
|
|
@@ -33,14 +33,6 @@ import {
|
|
|
33
33
|
usage,
|
|
34
34
|
validateCommandOptions
|
|
35
35
|
} from "./chunks/chunk-CHH26D4F.ts";
|
|
36
|
-
import {
|
|
37
|
-
migrateLegacyStateDirectory,
|
|
38
|
-
stateDirectoryMigrationNotice,
|
|
39
|
-
withStateDirectoryAccess
|
|
40
|
-
} from "./chunks/chunk-ZI5MXMEX.ts";
|
|
41
|
-
import {
|
|
42
|
-
syncErrorGuidance
|
|
43
|
-
} from "./chunks/chunk-CPEHGXJV.ts";
|
|
44
36
|
import {
|
|
45
37
|
safeTerminalText
|
|
46
38
|
} from "./chunks/chunk-LTBWGSBV.ts";
|
|
@@ -60,7 +52,15 @@ import {
|
|
|
60
52
|
syncSessionsWarnings
|
|
61
53
|
} from "./chunks/chunk-C7XY5NF5.ts";
|
|
62
54
|
import "./chunks/chunk-6LP3MCR2.ts";
|
|
55
|
+
import {
|
|
56
|
+
migrateLegacyStateDirectory,
|
|
57
|
+
stateDirectoryMigrationNotice,
|
|
58
|
+
withStateDirectoryAccess
|
|
59
|
+
} from "./chunks/chunk-ZI5MXMEX.ts";
|
|
63
60
|
import "./chunks/chunk-TEN2ZBJV.ts";
|
|
61
|
+
import {
|
|
62
|
+
syncErrorGuidance
|
|
63
|
+
} from "./chunks/chunk-CPEHGXJV.ts";
|
|
64
64
|
import {
|
|
65
65
|
SetupPullRequiresUiError,
|
|
66
66
|
errorMessage,
|
|
@@ -264,7 +264,7 @@ async function initConfig(ctx, signal) {
|
|
|
264
264
|
return;
|
|
265
265
|
}
|
|
266
266
|
if (ctx.mode === "tui") {
|
|
267
|
-
const { showSetupWizard } = await import("./chunks/setup-wizard-
|
|
267
|
+
const { showSetupWizard } = await import("./chunks/setup-wizard-IUB6ESEU.ts");
|
|
268
268
|
throwIfAborted(signal);
|
|
269
269
|
await showSetupWizard(ctx, signal);
|
|
270
270
|
return;
|
|
@@ -368,7 +368,7 @@ async function handleCommand(rawArgs, ctx, sessionSignal, loaders, attention) {
|
|
|
368
368
|
);
|
|
369
369
|
if (!rawArgs.trim()) {
|
|
370
370
|
try {
|
|
371
|
-
const { showSyncManager } = await import("./chunks/manager-ui-
|
|
371
|
+
const { showSyncManager } = await import("./chunks/manager-ui-5KLKVMRC.ts");
|
|
372
372
|
if (sessionSignal.aborted) return;
|
|
373
373
|
await showSyncManager(ctx, run, sessionSignal, {
|
|
374
374
|
getAttention: () => attention.current(),
|
|
@@ -384,7 +384,7 @@ async function handleCommand(rawArgs, ctx, sessionSignal, loaders, attention) {
|
|
|
384
384
|
ctx.ui.notify(errorMessage(error), "error");
|
|
385
385
|
}
|
|
386
386
|
await reconcileObservation(attention, sessionSignal);
|
|
387
|
-
if (!sessionSignal.aborted) attention.publish(ctx);
|
|
387
|
+
if (!sessionSignal.aborted) await attention.publish(ctx, sessionSignal);
|
|
388
388
|
return;
|
|
389
389
|
}
|
|
390
390
|
const result = await run(rawArgs);
|
|
@@ -410,7 +410,7 @@ async function handleCommand(rawArgs, ctx, sessionSignal, loaders, attention) {
|
|
|
410
410
|
await clearAttentionAfterCompletedOperation(rawArgs, result, ctx, attention, sessionSignal);
|
|
411
411
|
await reconcileSelectionAttention(ctx, attention, sessionSignal);
|
|
412
412
|
await reconcileObservation(attention, sessionSignal);
|
|
413
|
-
if (!sessionSignal.aborted) attention.publish(ctx);
|
|
413
|
+
if (!sessionSignal.aborted) await attention.publish(ctx, sessionSignal);
|
|
414
414
|
}
|
|
415
415
|
function observationCommitCallback(attention, sessionSignal, onCommit) {
|
|
416
416
|
const observed = attention.observation();
|
|
@@ -470,7 +470,7 @@ function directSelectionOrigin(rawArgs) {
|
|
|
470
470
|
async function resolveSelectionAttention(ctx, attention, signal, loaders, options = {}) {
|
|
471
471
|
const current = attention.current();
|
|
472
472
|
if (!current || signal.aborted) return;
|
|
473
|
-
const { dispatchManagerResult } = await import("./chunks/manager-result-dispatcher-
|
|
473
|
+
const { dispatchManagerResult } = await import("./chunks/manager-result-dispatcher-FKIBM3GO.ts");
|
|
474
474
|
if (signal.aborted || attention.current() !== current) return;
|
|
475
475
|
await dispatchManagerResult(
|
|
476
476
|
ctx,
|
|
@@ -653,7 +653,7 @@ function createStartupCheck(loaders, attention, timeoutMs = 3e4) {
|
|
|
653
653
|
);
|
|
654
654
|
} finally {
|
|
655
655
|
clearTimeout(timer);
|
|
656
|
-
if (isCurrent() && checking) attention.publish(ctx);
|
|
656
|
+
if (isCurrent() && checking) await attention.publish(ctx, sessionSignal);
|
|
657
657
|
if (active === task) active = void 0;
|
|
658
658
|
}
|
|
659
659
|
}).catch(() => {
|
|
@@ -674,7 +674,7 @@ function createStartupCheck(loaders, attention, timeoutMs = 3e4) {
|
|
|
674
674
|
function createSyncLoaders(dependencies) {
|
|
675
675
|
const loaders = {
|
|
676
676
|
inspection: cachedModuleLoader(
|
|
677
|
-
dependencies.loadSyncInspection ?? (() => import("./chunks/sync-inspection-
|
|
677
|
+
dependencies.loadSyncInspection ?? (() => import("./chunks/sync-inspection-CST2KL65.ts"))
|
|
678
678
|
),
|
|
679
679
|
setupSwitch: cachedModuleLoader(
|
|
680
680
|
dependencies.loadSetupSwitch ?? (() => import("./chunks/setup-switch-IS2PEZ3J.ts"))
|
|
@@ -684,7 +684,7 @@ function createSyncLoaders(dependencies) {
|
|
|
684
684
|
),
|
|
685
685
|
syncState: cachedModuleLoader(dependencies.loadSyncState ?? (() => import("./chunks/sync-state-Q2FTXTW6.ts"))),
|
|
686
686
|
operations: cachedModuleLoader(
|
|
687
|
-
dependencies.loadSyncOperations ?? (() => import("./chunks/sync-operations-
|
|
687
|
+
dependencies.loadSyncOperations ?? (() => import("./chunks/sync-operations-LBX3GKCM.ts"))
|
|
688
688
|
)
|
|
689
689
|
};
|
|
690
690
|
return loaders;
|
package/dist/index.ts.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/commands/command-execution.ts", "../src/commands/command-handler.ts", "../src/settings/config-errors.ts", "../src/sync/automatic-sync.ts", "../src/sync/startup-check.ts", "../src/sync/sync-loaders.ts", "../src/sync-extension.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ExtensionCommandContext, ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { loadConfig, sessionTokenWarnings, syncSessionsWarnings } from \"../settings/config.js\";\nimport {\n\tactiveLocalConfigPath,\n\tcreateLocalConfigDocument,\n\tlocalConfigPath,\n} from \"../settings/config-file.js\";\nimport { localConfigTemplate, readLocalConfigObject } from \"../settings/settings-store.js\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport { unlock, withLock } from \"../state/lock.js\";\nimport {\n\tmigrateLegacyStateDirectory,\n\tstateDirectoryMigrationNotice,\n} from \"../state/state-directory.js\";\nimport { throwIfAborted } from \"../sync/signals.js\";\nimport { syncErrorGuidance } from \"../sync/sync-error-guidance.js\";\nimport { isSyncDecisionRequiredError, SetupPullRequiresUiError } from \"../sync/sync-errors.js\";\nimport type { SyncLoaders } from \"../sync/sync-loaders.js\";\nimport { RemoteSelectionMismatchError } from \"../sync/sync-policy.js\";\nimport { automaticSyncSummary } from \"../ui/automatic-sync-summary.js\";\nimport type { RunRouteResult } from \"../ui/cancellable-operation.js\";\nimport {\n\tparseOptions,\n\tresolveSyncCommand,\n\tsplitArgs,\n\tusage,\n\tvalidateCommandOptions,\n} from \"./command.js\";\nimport type { CommandOptions } from \"./command-types.js\";\n\nconst STATUS_KEY = \"sync\";\n\nexport async function executeRecoveryCommand(\n\trawArgs: string,\n\tctx: ExtensionContext,\n\tsignal: AbortSignal | undefined,\n\tloaders: SyncLoaders,\n\tonCommit?: () => void,\n\tsetup?: string,\n): Promise<RunRouteResult> {\n\ttry {\n\t\tconst [subcommand, ...rest] = splitArgs(rawArgs);\n\t\tif (subcommand !== \"sync\" && subcommand !== \"pull\" && subcommand !== \"push\") {\n\t\t\tthrow new Error(`Unsupported sync recovery route: ${subcommand ?? \"missing\"}`);\n\t\t}\n\t\tconst options = parseOptions(rest);\n\t\tif (setup !== undefined) options.setup = setup;\n\t\tif (signal) options.signal = signal;\n\t\tif (onCommit) options.onCommit = onCommit;\n\t\toptions.reload = false;\n\t\toptions.auto = false;\n\t\tvalidateCommandOptions(subcommand, options);\n\t\tconst operations = await loaders.operations();\n\t\tthrowIfAborted(options.signal);\n\t\tif (subcommand === \"push\") {\n\t\t\tconst outcome = await withLock(\"push\", () => operations.push(ctx, options));\n\t\t\treturn { kind: \"completed\", ...(outcome ? { outcome } : {}) };\n\t\t}\n\t\tif (subcommand === \"pull\") {\n\t\t\tconst outcome = await withLock(\"pull\", () => operations.pull(ctx, options));\n\t\t\treturn { kind: \"completed\", ...(outcome ? { outcome } : {}) };\n\t\t}\n\t\tawait withLock(\"sync\", () => operations.syncBoth(ctx, options));\n\t\treturn { kind: \"completed\" };\n\t} catch (error) {\n\t\tif (signal?.aborted) return { kind: \"failed\" };\n\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t\tif (error instanceof RemoteSelectionMismatchError) {\n\t\t\treturn { kind: \"remote-selection-required\", decision: error.decision };\n\t\t}\n\t\tif (isSyncDecisionRequiredError(error)) {\n\t\t\treturn { kind: \"decision-required\", decision: error.decision };\n\t\t}\n\t\tctx.ui.notify(syncErrorGuidance(error), \"error\");\n\t\treturn { kind: \"failed\" };\n\t}\n}\n\nexport async function executeCommand(\n\trawArgs: string,\n\tctx: ExtensionCommandContext,\n\tsignal: AbortSignal | undefined,\n\tloaders: SyncLoaders,\n\tonCommit?: () => void,\n\tsetup?: string,\n): Promise<RunRouteResult> {\n\ttry {\n\t\tconst command = await resolveSyncCommand(rawArgs, ctx);\n\t\tif (signal?.aborted || !command) return { kind: \"completed\" };\n\t\tconst { subcommand, rest } = command;\n\t\tconst options = parseOptions(rest);\n\t\tif (setup !== undefined) options.setup = setup;\n\t\tif (signal) options.signal = signal;\n\t\tif (onCommit) options.onCommit = onCommit;\n\t\tvalidateCommandOptions(subcommand, options);\n\n\t\tswitch (subcommand) {\n\t\t\tcase \"help\":\n\t\t\t\tctx.ui.notify(usage(), \"info\");\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\tcase \"use\": {\n\t\t\t\tconst { useSyncSetup } = await loaders.setupSwitch();\n\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\tawait useSyncSetup(\n\t\t\t\t\tctx,\n\t\t\t\t\toptions.args[0] ?? \"\",\n\t\t\t\t\tasync (selectedSetup) => {\n\t\t\t\t\t\tconst operations = await loaders.operations();\n\t\t\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\t\t\treturn withLock(\"pull\", () =>\n\t\t\t\t\t\t\toperations.pull(ctx, { ...options, setup: selectedSetup }),\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t\tundefined,\n\t\t\t\t\toptions.signal,\n\t\t\t\t);\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\t}\n\t\t\tcase \"init\":\n\t\t\t\tawait initConfig(ctx, signal);\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\tcase \"config\":\n\t\t\t\tawait showConfig(ctx, options);\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\tcase \"files\": {\n\t\t\t\tconst { showFileSelection } = await import(\"../ui/file-selection.js\");\n\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\tawait showFileSelection(ctx, options.setup, options.signal);\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\t}\n\t\t\tcase \"status\": {\n\t\t\t\tconst operations = await loaders.operations();\n\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\tawait operations.status(ctx, options);\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\t}\n\t\t\tcase \"diff\": {\n\t\t\t\tconst operations = await loaders.operations();\n\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\tawait operations.diff(ctx, options);\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\t}\n\t\t\tcase \"doctor\": {\n\t\t\t\tconst operations = await loaders.operations();\n\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\tawait operations.doctor(ctx, options);\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\t}\n\t\t\tcase \"push\": {\n\t\t\t\tconst operations = await loaders.operations();\n\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\tconst outcome = await withLock(\"push\", () => operations.push(ctx, options));\n\t\t\t\treturn { kind: \"completed\", ...(outcome ? { outcome } : {}) };\n\t\t\t}\n\t\t\tcase \"pull\": {\n\t\t\t\tconst operations = await loaders.operations();\n\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\tconst outcome = await withLock(\"pull\", () => operations.pull(ctx, options));\n\t\t\t\treturn { kind: \"completed\", ...(outcome ? { outcome } : {}) };\n\t\t\t}\n\t\t\tcase \"sync\": {\n\t\t\t\tconst operations = await loaders.operations();\n\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\tawait withLock(\"sync\", () => operations.syncBoth(ctx, options));\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\t}\n\t\t\tcase \"history\": {\n\t\t\t\tconst operations = await loaders.operations();\n\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\tawait operations.history(ctx, options);\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\t}\n\t\t\tcase \"rollback\": {\n\t\t\t\tconst operations = await loaders.operations();\n\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\tawait withLock(\"rollback\", () => operations.rollback(ctx, options));\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\t}\n\t\t\tcase \"migrate-state\":\n\t\t\t\tawait migrateStateDirectory(ctx, options);\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\tcase \"unlock\":\n\t\t\t\tawait unlock(ctx, options);\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\tdefault:\n\t\t\t\tctx.ui.notify(`Unknown /sync command: ${subcommand}\\n\\n${usage()}`, \"warning\");\n\t\t\t\treturn { kind: \"failed\" };\n\t\t}\n\t} catch (error) {\n\t\tif (signal?.aborted) return { kind: \"failed\" };\n\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t\tif (error instanceof SetupPullRequiresUiError) throw error;\n\t\tif (error instanceof RemoteSelectionMismatchError) {\n\t\t\treturn { kind: \"remote-selection-required\", decision: error.decision };\n\t\t}\n\t\tif (isSyncDecisionRequiredError(error)) {\n\t\t\treturn { kind: \"decision-required\", decision: error.decision };\n\t\t}\n\t\tctx.ui.notify(syncErrorGuidance(error), \"error\");\n\t\treturn { kind: \"failed\" };\n\t}\n}\n\nasync function migrateStateDirectory(ctx: ExtensionCommandContext, options: CommandOptions) {\n\tconst notice = stateDirectoryMigrationNotice();\n\tif (!notice) {\n\t\tctx.ui.notify(\"pi-sync already uses the canonical pi-sync/ state directory.\", \"info\");\n\t\treturn;\n\t}\n\tif (\n\t\t!options.yes &&\n\t\t!(await ctx.ui.confirm(\n\t\t\t\"Migrate pi-sync state directory\",\n\t\t\t\"Confirm that every other Pi process is closed. pi-sync will atomically rename .pisync/ to pi-sync/ without merging or deleting either root.\",\n\t\t\t{ signal: options.signal },\n\t\t))\n\t) {\n\t\tctx.ui.notify(\"pi-sync state migration cancelled.\", \"info\");\n\t\treturn;\n\t}\n\tthrowIfAborted(options.signal);\n\tconst result = await migrateLegacyStateDirectory();\n\tthrowIfAborted(options.signal);\n\tif (result.status === \"ready\") {\n\t\tctx.ui.notify(\"pi-sync already uses the canonical pi-sync/ state directory.\", \"info\");\n\t\treturn;\n\t}\n\tctx.ui.notify(result.message, result.status === \"migrated\" ? \"info\" : \"warning\");\n}\n\nasync function initConfig(ctx: ExtensionCommandContext, signal?: AbortSignal) {\n\tconst configPath = localConfigPath();\n\tif (await readLocalConfigObject()) {\n\t\tctx.ui.notify(`Config already exists: ${await activeLocalConfigPath()}`, \"info\");\n\t\treturn;\n\t}\n\n\tif (ctx.mode === \"tui\") {\n\t\tconst { showSetupWizard } = await import(\"../ui/setup/setup-wizard.js\");\n\t\tthrowIfAborted(signal);\n\t\tawait showSetupWizard(ctx, signal);\n\t\treturn;\n\t}\n\tawait createLocalConfigDocument(localConfigTemplate());\n\tctx.ui.notify(\n\t\t`Created ${configPath}. Add a storage connection and sync setup before syncing.`,\n\t\t\"info\",\n\t);\n}\n\nasync function showConfig(ctx: ExtensionCommandContext, options: CommandOptions) {\n\tconst config = await loadConfig(options.setup);\n\tconst warnings = [\n\t\t...(config.backend.type === \"s3\" ? sessionTokenWarnings(config.backend.profile) : []),\n\t\t...syncSessionsWarnings(config),\n\t];\n\tconst storageLines = configStorageLines(config);\n\tctx.ui.notify(\n\t\t[\n\t\t\t\"pi-sync config:\",\n\t\t\t`sync setup: ${config.setupName}`,\n\t\t\t`storage connection: ${config.connectionName}`,\n\t\t\t...storageLines,\n\t\t\t`storage path: ${config.storagePath}`,\n\t\t\t`automatic sync: ${automaticSyncSummary(config.automatic)}`,\n\t\t\t`included content: ${config.include.join(\", \") || \"none\"}`,\n\t\t\t`sessions: ${config.include.includes(\"sessions\") ? \"included\" : \"not included\"}`,\n\t\t\t`settings file: ${localConfigPath()}`,\n\t\t\t...warnings,\n\t\t].join(\"\\n\"),\n\t\twarnings.length > 0 ? \"warning\" : \"info\",\n\t);\n}\n\nfunction configStorageLines(config: AnySyncConfig) {\n\tswitch (config.backend.type) {\n\t\tcase \"git\":\n\t\t\treturn [\n\t\t\t\t\"kind: git\",\n\t\t\t\t`remote: ${displayGitRemote(config.backend.profile.remote)}`,\n\t\t\t\t\"authentication: existing Git/SSH credentials (not stored)\",\n\t\t\t\t`branch: ${config.backend.destination.branch}`,\n\t\t\t];\n\t\tcase \"webdav\":\n\t\t\treturn [\n\t\t\t\t\"kind: webdav\",\n\t\t\t\t`url: ${displayWebDavUrl(config.backend.profile.url, config.backend.profile.username)}`,\n\t\t\t\t\"username: configured (value hidden)\",\n\t\t\t\t\"password: configured\",\n\t\t\t];\n\t\tcase \"s3\":\n\t\t\treturn [\n\t\t\t\t\"kind: s3\",\n\t\t\t\t`endpoint: ${config.backend.profile.endpoint}`,\n\t\t\t\t`bucket: ${config.backend.destination.bucket}`,\n\t\t\t\t`region: ${config.backend.profile.region}`,\n\t\t\t\t\"access key id: configured\",\n\t\t\t\t\"secret access key: configured\",\n\t\t\t\t`session token: ${config.backend.profile.sessionToken ? \"configured\" : \"not configured\"}`,\n\t\t\t];\n\t}\n}\n\nfunction displayGitRemote(value: string | undefined) {\n\tif (!value) return \"missing\";\n\ttry {\n\t\tconst url = new URL(value);\n\t\turl.username = \"\";\n\t\turl.password = \"\";\n\t\turl.search = \"\";\n\t\turl.hash = \"\";\n\t\treturn url.toString();\n\t} catch {\n\t\treturn value.replace(/^(?:[^@\\s]+@)?(?<host>[^:]+):.+$/u, \"$<host>:\u2026\");\n\t}\n}\n\nfunction displayWebDavUrl(value: string | undefined, username: string | undefined) {\n\tif (!value) return \"missing\";\n\ttry {\n\t\tconst url = new URL(value);\n\t\turl.username = \"\";\n\t\turl.password = \"\";\n\t\turl.search = \"\";\n\t\turl.hash = \"\";\n\t\treturn username ? `${url.origin}/\u2026` : `${url.origin}${url.pathname}`;\n\t} catch {\n\t\treturn \"invalid (value hidden)\";\n\t}\n}\n", "import type { ExtensionCommandContext, ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { loadConfig } from \"../settings/config.js\";\nimport { readStateForConfig, syncStateFingerprint } from \"../state/sync-state-store.js\";\nimport { combineSignals } from \"../sync/signals.js\";\nimport { errorMessage } from \"../sync/sync-errors.js\";\nimport type { SyncLoaders } from \"../sync/sync-loaders.js\";\nimport { formatRemoteSelectionMismatch } from \"../sync/sync-policy.js\";\nimport type { RunRouteResult } from \"../ui/cancellable-operation.js\";\nimport {\n\tobservationMatchesConfig,\n\ttype SyncAttentionController,\n\ttype SyncAttentionOrigin,\n\tsyncAttentionMatchesConfig,\n} from \"../ui/sync-attention.js\";\nimport { parseOptions, splitArgs } from \"./command.js\";\nimport { executeCommand, executeRecoveryCommand } from \"./command-execution.js\";\n\nconst STATUS_KEY = \"sync\";\n\nexport async function handleCommand(\n\trawArgs: string,\n\tctx: ExtensionCommandContext,\n\tsessionSignal: AbortSignal,\n\tloaders: SyncLoaders,\n\tattention: SyncAttentionController,\n) {\n\tawait reconcileObservation(attention, sessionSignal);\n\tif (sessionSignal.aborted) return;\n\tconst run = (route: string, signal?: AbortSignal, onCommit?: () => void, target?: string) =>\n\t\texecuteCommand(\n\t\t\troute,\n\t\t\tctx,\n\t\t\tcombineSignals(sessionSignal, signal),\n\t\t\tloaders,\n\t\t\tobservationCommitCallback(attention, sessionSignal, onCommit),\n\t\t\ttarget,\n\t\t);\n\tif (!rawArgs.trim()) {\n\t\ttry {\n\t\t\tconst { showSyncManager } = await import(\"../ui/manager-ui.js\");\n\t\t\tif (sessionSignal.aborted) return;\n\t\t\tawait showSyncManager(ctx, run, sessionSignal, {\n\t\t\t\tgetAttention: () => attention.current(),\n\t\t\t\tgetObservation: () => attention.observation(),\n\t\t\t\tonObservationInvalidated: () => attention.clearObservation(),\n\t\t\t\tonSelectionResolved: (expected) => {\n\t\t\t\t\tif (attention.current() === expected) attention.clear(ctx);\n\t\t\t\t},\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tif (sessionSignal.aborted) return;\n\t\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t\t\tctx.ui.notify(errorMessage(error), \"error\");\n\t\t}\n\t\tawait reconcileObservation(attention, sessionSignal);\n\t\tif (!sessionSignal.aborted) attention.publish(ctx);\n\t\treturn;\n\t}\n\tconst result = await run(rawArgs);\n\tif (result.kind === \"decision-required\") {\n\t\tctx.ui.notify(result.decision.directMessage, \"error\");\n\t} else if (result.kind === \"remote-selection-required\") {\n\t\tconst origin = directSelectionOrigin(rawArgs);\n\t\tif (origin) attention.set(result.decision, origin);\n\t\tconst deterministic = splitArgs(rawArgs).some((arg) => arg === \"--yes\" || arg === \"-y\");\n\t\tif (origin && ctx.mode === \"tui\" && !deterministic) {\n\t\t\tawait resolveSelectionAttention(ctx, attention, sessionSignal, loaders);\n\t\t} else {\n\t\t\tctx.ui.notify(\n\t\t\t\tformatRemoteSelectionMismatch(\n\t\t\t\t\tresult.decision.setupName,\n\t\t\t\t\tresult.decision.localInclude,\n\t\t\t\t\tresult.decision.remoteInclude,\n\t\t\t\t),\n\t\t\t\t\"error\",\n\t\t\t);\n\t\t}\n\t}\n\tawait clearAttentionAfterCompletedOperation(rawArgs, result, ctx, attention, sessionSignal);\n\tawait reconcileSelectionAttention(ctx, attention, sessionSignal);\n\tawait reconcileObservation(attention, sessionSignal);\n\tif (!sessionSignal.aborted) attention.publish(ctx);\n}\n\nfunction observationCommitCallback(\n\tattention: SyncAttentionController,\n\tsessionSignal: AbortSignal,\n\tonCommit?: () => void,\n) {\n\tconst observed = attention.observation();\n\treturn () => {\n\t\t// Opening or cancelling a review changes nothing. A commit may change data\n\t\t// even if later publication/baseline cleanup fails; never restore old hints.\n\t\tif (!sessionSignal.aborted && attention.observation() === observed)\n\t\t\tattention.clearObservation();\n\t\tonCommit?.();\n\t};\n}\n\nasync function reconcileObservation(attention: SyncAttentionController, signal: AbortSignal) {\n\tconst observed = attention.observation();\n\tif (!observed || signal.aborted) return;\n\ttry {\n\t\tconst config = await loadConfig();\n\t\tif (signal.aborted || attention.observation() !== observed) return;\n\t\tif (!observationMatchesConfig(observed, config)) {\n\t\t\tattention.clearObservation();\n\t\t\treturn;\n\t\t}\n\t\tconst state = await readStateForConfig(config);\n\t\tif (signal.aborted || attention.observation() !== observed) return;\n\t\tif (syncStateFingerprint(state) !== observed.inspection.stateIdentity)\n\t\t\tattention.clearObservation();\n\t} catch {\n\t\tif (!signal.aborted && attention.observation() === observed) attention.clearObservation();\n\t}\n}\n\nasync function clearAttentionAfterCompletedOperation(\n\trawArgs: string,\n\tresult: RunRouteResult,\n\tctx: ExtensionContext,\n\tattention: SyncAttentionController,\n\tsignal: AbortSignal,\n) {\n\tif (result.kind !== \"completed\" || result.outcome === \"cancelled\" || signal.aborted) return;\n\tconst [command, ...rest] = splitArgs(rawArgs);\n\tif (command !== \"sync\" && command !== \"pull\" && command !== \"push\") return;\n\tconst current = attention.current();\n\tif (!current) return;\n\ttry {\n\t\tconst options = parseOptions(rest);\n\t\tconst setupName = options.setup ?? (await loadConfig()).setupName;\n\t\tif (signal.aborted || attention.current() !== current) return;\n\t\tif (current.decision.setupName === setupName) attention.clear(ctx);\n\t} catch {\n\t\t// Attention reconciliation below owns malformed or concurrently changed settings.\n\t}\n}\n\nasync function reconcileSelectionAttention(\n\tctx: ExtensionContext,\n\tattention: SyncAttentionController,\n\tsignal: AbortSignal,\n) {\n\tconst current = attention.current();\n\tif (!current || signal.aborted) return;\n\ttry {\n\t\tconst config = await loadConfig(current.decision.setupName);\n\t\tif (signal.aborted || attention.current() !== current) return;\n\t\tif (!syncAttentionMatchesConfig(current, config)) attention.clear(ctx);\n\t} catch {\n\t\tif (!signal.aborted && attention.current() === current) attention.clear(ctx);\n\t}\n}\n\nfunction directSelectionOrigin(rawArgs: string): SyncAttentionOrigin | undefined {\n\tconst command = splitArgs(rawArgs)[0];\n\treturn command === \"sync\" || command === \"pull\" || command === \"push\" ? command : undefined;\n}\n\nexport async function resolveSelectionAttention(\n\tctx: ExtensionContext,\n\tattention: SyncAttentionController,\n\tsignal: AbortSignal,\n\tloaders: SyncLoaders,\n\toptions: {\n\t\tcancelLabel?: string;\n\t\twithStateAccess?: <T>(task: () => Promise<T>) => Promise<T>;\n\t} = {},\n) {\n\tconst current = attention.current();\n\tif (!current || signal.aborted) return;\n\tconst { dispatchManagerResult } = await import(\"../ui/manager-result-dispatcher.js\");\n\tif (signal.aborted || attention.current() !== current) return;\n\tawait dispatchManagerResult(\n\t\tctx,\n\t\t{ kind: \"remote-selection-required\", decision: current.decision },\n\t\tcurrent.origin,\n\t\t(route, actionSignal, onCommit, target) => {\n\t\t\tconst execute = () =>\n\t\t\t\texecuteRecoveryCommand(\n\t\t\t\t\troute,\n\t\t\t\t\tctx,\n\t\t\t\t\tcombineSignals(signal, actionSignal),\n\t\t\t\t\tloaders,\n\t\t\t\t\tobservationCommitCallback(attention, signal, onCommit),\n\t\t\t\t\ttarget,\n\t\t\t\t);\n\t\t\treturn options.withStateAccess ? options.withStateAccess(execute) : execute();\n\t\t},\n\t\tsignal,\n\t\t{\n\t\t\tcancelLabel: options.cancelLabel,\n\t\t\twithStateAccess: options.withStateAccess,\n\t\t\tonSelectionResolved: () => {\n\t\t\t\tif (attention.current() === current) attention.clear(ctx);\n\t\t\t},\n\t\t},\n\t);\n}\n", "export function isMissingConfigError(error: unknown) {\n\treturn (\n\t\terror instanceof Error &&\n\t\t(error.message.startsWith(\"Missing pi-sync settings.\") ||\n\t\t\terror.message === \"No sync setups are configured.\")\n\t);\n}\n", "import type { ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { setSyncSetupCompletions } from \"../commands/command.js\";\nimport type { CommandOptions } from \"../commands/command-types.js\";\nimport { loadConfig, loadPartialConfig } from \"../settings/config.js\";\nimport { isMissingConfigError } from \"../settings/config-errors.js\";\nimport { consumeLocalConfigMigrationNotice } from \"../settings/config-file.js\";\nimport { configuredSyncSetupNames } from \"../settings/settings-store.js\";\nimport { snapshotOptionsForContext } from \"../snapshot/session-paths.js\";\nimport { recoverSnapshotTransactionsOnStartup } from \"../snapshot/snapshot-transaction.js\";\nimport { withLock } from \"../state/lock.js\";\nimport { stateDirectoryMigrationNotice } from \"../state/state-directory.js\";\nimport { ensureStateDir, readStateForConfig } from \"../state/sync-state-store.js\";\nimport { safeTerminalText } from \"../ui/terminal-text.js\";\nimport { throwIfAborted } from \"./signals.js\";\nimport { errorMessage } from \"./sync-errors.js\";\nimport type { SyncLoaders } from \"./sync-loaders.js\";\n\nconst AUTO_SYNC_OPTIONS: CommandOptions = {\n\tyes: true,\n\tforce: false,\n\tstale: false,\n\tsilent: true,\n\treload: false,\n\tauto: true,\n\targs: [],\n};\n\nconst STATUS_KEY = \"sync\";\n\nexport async function startSession(ctx: ExtensionContext, signal: AbortSignal) {\n\tthrowIfAborted(signal);\n\tconst stateNotice = stateDirectoryMigrationNotice();\n\tif (stateNotice && ctx.hasUI) ctx.ui.notify(stateNotice, \"warning\");\n\t// Recovery can restore managed files: finish it before Pi accepts user edits.\n\t// Unlike remote inspection, it must never be detached behind startup.\n\tawait recoverSnapshotTransactionsOnStartup();\n\tthrowIfAborted(signal);\n\ttry {\n\t\tconst names = await configuredSyncSetupNames();\n\t\tthrowIfAborted(signal);\n\t\tsetSyncSetupCompletions(names);\n\t} catch {\n\t\tif (signal.aborted) return;\n\t\tsetSyncSetupCompletions([]);\n\t}\n\tconst migrationNotice = consumeLocalConfigMigrationNotice();\n\tif (migrationNotice && ctx.hasUI) ctx.ui.notify(migrationNotice, \"warning\");\n\tthrowIfAborted(signal);\n\tif (!ctx.hasUI) return;\n\ttry {\n\t\tconst config = await loadConfig();\n\t\tthrowIfAborted(signal);\n\t\treturn config.automatic ? config : undefined;\n\t} catch (error) {\n\t\tthrowIfAborted(signal);\n\t\tif (!isMissingConfigError(error)) {\n\t\t\tctx.ui.notify(\n\t\t\t\t`pi-sync startup check skipped: ${safeTerminalText(errorMessage(error))}`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t}\n\t}\n}\n\nexport async function autoPushSessions(\n\tctx: ExtensionContext,\n\tsignal: AbortSignal,\n\tloaders: SyncLoaders,\n) {\n\ttry {\n\t\tconst partial = await loadPartialConfig();\n\t\tthrowIfAborted(signal);\n\t\tif (!partial.automatic) return;\n\t\tif (!partial.include.includes(\"sessions\")) return;\n\t\tawait ensureStateDir();\n\t\tthrowIfAborted(signal);\n\t\tconst config = await loadConfig();\n\t\tthrowIfAborted(signal);\n\t\tif (!config.include.includes(\"sessions\")) return;\n\t\tconst [operations, snapshotModule, syncStateModule] = await Promise.all([\n\t\t\tloaders.operations(),\n\t\t\tloaders.snapshot(),\n\t\t\tloaders.syncState(),\n\t\t]);\n\t\tthrowIfAborted(signal);\n\t\tawait withLock(\"auto-session-push\", async () => {\n\t\t\tthrowIfAborted(signal);\n\t\t\tconst state = await readStateForConfig(config);\n\t\t\tthrowIfAborted(signal);\n\t\t\tconst local = await snapshotModule.createSnapshot(config.snapshotIdentity, {\n\t\t\t\t...snapshotOptionsForContext(ctx, config),\n\t\t\t\tsignal,\n\t\t\t});\n\t\t\tthrowIfAborted(signal);\n\t\t\tif (!syncStateModule.hasLocalChanges(local, state, config)) return;\n\t\t\tawait operations.push(ctx, { ...AUTO_SYNC_OPTIONS, signal }, { config, state, local });\n\t\t});\n\t} catch (error) {\n\t\tif (signal.aborted || isMissingConfigError(error)) return;\n\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t\tctx.ui.notify(`pi-sync session push skipped: ${errorMessage(error)}`, \"warning\");\n\t}\n}\n", "import type { ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { loadConfigForCheck, syncCheckConfigFingerprint } from \"../settings/config.js\";\nimport { isMissingConfigError } from \"../settings/config-errors.js\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport { snapshotOptionsForContext } from \"../snapshot/session-paths.js\";\nimport { withLock } from \"../state/lock.js\";\nimport { withStateDirectoryAccess } from \"../state/state-directory.js\";\nimport { readStateForConfig, syncStateFingerprint } from \"../state/sync-state-store.js\";\nimport type { SyncAttentionController } from \"../ui/sync-attention.js\";\nimport { safeTerminalText } from \"../ui/terminal-text.js\";\nimport { combineSignals, throwIfAborted } from \"./signals.js\";\nimport { errorMessage } from \"./sync-errors.js\";\nimport type { SyncLoaders } from \"./sync-loaders.js\";\n\nconst STATUS_KEY = \"sync\";\n\n/** One owned task per extension session, never keyed by the shared headless UI. */\nexport function createStartupCheck(\n\tloaders: SyncLoaders,\n\tattention: SyncAttentionController,\n\ttimeoutMs = 30_000,\n) {\n\tlet active:\n\t\t| {\n\t\t\t\tcontroller: AbortController;\n\t\t\t\tpromise: Promise<void>;\n\t\t\t\towner: ExtensionContext[\"sessionManager\"];\n\t\t }\n\t\t| undefined;\n\n\treturn {\n\t\tstart(ctx: ExtensionContext, sessionSignal: AbortSignal, initialConfig?: AnySyncConfig) {\n\t\t\tif (!ctx.hasUI || sessionSignal.aborted) return;\n\t\t\tif (active) throw new Error(\"Previous startup check has not been drained.\");\n\t\t\tconst controller = new AbortController();\n\t\t\tconst signal = combineSignals(sessionSignal, controller.signal);\n\t\t\tconst task = { controller, owner: ctx.sessionManager, promise: Promise.resolve() };\n\t\t\tactive = task;\n\t\t\tconst isCurrent = () =>\n\t\t\t\t!sessionSignal.aborted && active === task && task.owner === ctx.sessionManager;\n\t\t\tconst timer = setTimeout(\n\t\t\t\t() => controller.abort(new DOMException(\"Startup check timed out\", \"TimeoutError\")),\n\t\t\t\ttimeoutMs,\n\t\t\t);\n\t\t\tlet config: AnySyncConfig | undefined;\n\t\t\tlet checking = false;\n\t\t\t// Handle every detached rejection here; Pi's awaited event runner cannot catch it.\n\t\t\ttask.promise = Promise.resolve()\n\t\t\t\t.then(async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\t\tconfig = initialConfig ?? (await loadConfigForCheck());\n\t\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\t\tif (!config.automatic) return;\n\t\t\t\t\t\tconst captured = config;\n\t\t\t\t\t\tconst identity = syncCheckConfigFingerprint(captured);\n\t\t\t\t\t\tchecking = true;\n\t\t\t\t\t\tctx.ui.setStatus(STATUS_KEY, \"checking in background\");\n\t\t\t\t\t\tconst { inspectSync } = await loaders.inspection();\n\t\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\t\tconst currentConfig = await loadConfigForCheck();\n\t\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\t\tif (syncCheckConfigFingerprint(currentConfig) !== identity) return;\n\t\t\t\t\t\t// Lock order: state migration guard \u2192 sync operation \u2192 backend cache.\n\t\t\t\t\t\t// Read heads may write only private cache data. Never call doctor/syncBoth.\n\t\t\t\t\t\tconst inspection = await withStateDirectoryAccess(() => {\n\t\t\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\t\t\treturn withLock(\"startup-check\", () => {\n\t\t\t\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\t\t\t\treturn inspectSync(captured, snapshotOptionsForContext(ctx, captured), signal);\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t});\n\t\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\t\tconst latest = await loadConfigForCheck();\n\t\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\t\tif (syncCheckConfigFingerprint(latest) !== identity) return;\n\t\t\t\t\t\tconst state = await withStateDirectoryAccess(() => readStateForConfig(latest));\n\t\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\t\tif (syncStateFingerprint(state) !== inspection.stateIdentity || !isCurrent()) return;\n\t\t\t\t\t\tattention.observe({\n\t\t\t\t\t\t\tsetupName: captured.setupName,\n\t\t\t\t\t\t\tconfigIdentity: identity,\n\t\t\t\t\t\t\tcheckedAt: new Date().toISOString(),\n\t\t\t\t\t\t\tinspection,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (ctx.mode === \"rpc\") attention.notifyObservation(ctx);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (!isCurrent() || sessionSignal.aborted || isMissingConfigError(error)) return;\n\t\t\t\t\t\tif (signal.aborted && controller.signal.reason?.name !== \"TimeoutError\") return;\n\t\t\t\t\t\t// A settings edit invalidates failures as well as successful observations.\n\t\t\t\t\t\tif (config) {\n\t\t\t\t\t\t\tconst latest = await loadConfigForCheck().catch(() => undefined);\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t!isCurrent() ||\n\t\t\t\t\t\t\t\t(signal.aborted && controller.signal.reason?.name !== \"TimeoutError\")\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t!latest ||\n\t\t\t\t\t\t\t\tsyncCheckConfigFingerprint(latest) !== syncCheckConfigFingerprint(config)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\t`pi-sync startup check skipped: ${safeTerminalText(errorMessage(error))}. Run /sync status to retry. No startup transfer was performed.`,\n\t\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t\t);\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\t\tif (isCurrent() && checking) attention.publish(ctx);\n\t\t\t\t\t\tif (active === task) active = undefined;\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\t// UI teardown can itself throw. No unhandled rejection or retained timer.\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tif (active === task) active = undefined;\n\t\t\t\t});\n\t\t},\n\t\tasync stop() {\n\t\t\tconst task = active;\n\t\t\tif (!task) return;\n\t\t\ttask.controller.abort(new DOMException(\"Startup check cancelled\", \"AbortError\"));\n\t\t\t// Drain the actual work, including child/ref cleanup, before foreground guards.\n\t\t\tawait task.promise;\n\t\t},\n\t};\n}\n", "type SetupSwitchModule = Pick<typeof import(\"./setup-switch.js\"), \"useSyncSetup\">;\ntype SnapshotModule = Pick<typeof import(\"../snapshot/snapshot.js\"), \"createSnapshot\">;\ntype SyncStateModule = Pick<typeof import(\"./sync-state.js\"), \"hasLocalChanges\">;\ntype SyncOperations = typeof import(\"./sync-operations.js\");\n\ntype SyncInspectionModule = Pick<typeof import(\"./sync-inspection.js\"), \"inspectSync\">;\n\nexport interface SyncDependencies {\n\tloadSyncInspection(): Promise<SyncInspectionModule>;\n\tloadSetupSwitch(): Promise<SetupSwitchModule>;\n\tloadSnapshot(): Promise<SnapshotModule>;\n\tloadSyncState(): Promise<SyncStateModule>;\n\tloadSyncOperations(): Promise<SyncOperations>;\n}\n\nexport interface SyncLoaders {\n\tinspection(): Promise<SyncInspectionModule>;\n\tsetupSwitch(): Promise<SetupSwitchModule>;\n\tsnapshot(): Promise<SnapshotModule>;\n\tsyncState(): Promise<SyncStateModule>;\n\toperations(): Promise<SyncOperations>;\n}\n\nexport function createSyncLoaders(dependencies: Partial<SyncDependencies>): SyncLoaders {\n\tconst loaders: SyncLoaders = {\n\t\tinspection: cachedModuleLoader(\n\t\t\tdependencies.loadSyncInspection ?? (() => import(\"./sync-inspection.js\")),\n\t\t),\n\t\tsetupSwitch: cachedModuleLoader(\n\t\t\tdependencies.loadSetupSwitch ?? (() => import(\"./setup-switch.js\")),\n\t\t),\n\t\tsnapshot: cachedModuleLoader(\n\t\t\tdependencies.loadSnapshot ?? (() => import(\"../snapshot/snapshot.js\")),\n\t\t),\n\t\tsyncState: cachedModuleLoader(dependencies.loadSyncState ?? (() => import(\"./sync-state.js\"))),\n\t\toperations: cachedModuleLoader(\n\t\t\tdependencies.loadSyncOperations ?? (() => import(\"./sync-operations.js\")),\n\t\t),\n\t};\n\treturn loaders;\n}\n\nfunction cachedModuleLoader<Module>(load: () => Promise<Module>): () => Promise<Module> {\n\tlet pending: Promise<Module> | undefined;\n\treturn () => {\n\t\tif (!pending) {\n\t\t\tpending = load().catch((error) => {\n\t\t\t\tpending = undefined;\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t}\n\t\treturn pending;\n\t};\n}\n", "import type { ExtensionAPI } from \"@earendil-works/pi-coding-agent\";\nimport { completeSyncArguments, splitArgs } from \"./commands/command.js\";\nimport { handleCommand } from \"./commands/command-handler.js\";\nimport type { AnySyncConfig } from \"./settings/settings-types.js\";\nimport { withStateDirectoryAccess } from \"./state/state-directory.js\";\nimport { autoPushSessions, startSession } from \"./sync/automatic-sync.js\";\nimport { combineSignals } from \"./sync/signals.js\";\nimport { createStartupCheck } from \"./sync/startup-check.js\";\nimport { errorMessage } from \"./sync/sync-errors.js\";\nimport { createSyncLoaders, type SyncDependencies } from \"./sync/sync-loaders.js\";\nimport { createSyncAttentionController } from \"./ui/sync-attention.js\";\nimport { safeTerminalText } from \"./ui/terminal-text.js\";\n\nconst STATUS_KEY = \"sync\";\n\nexport default function sync(pi: ExtensionAPI, dependencies: Partial<SyncDependencies> = {}) {\n\tconst loaders = createSyncLoaders(dependencies);\n\tconst attention = createSyncAttentionController();\n\tconst check = createStartupCheck(loaders, attention);\n\tlet sessionAbort = new AbortController();\n\tlet shutdownAbort: AbortController | undefined;\n\tlet initialization = Promise.resolve<AnySyncConfig | false | undefined>(undefined);\n\n\tpi.registerCommand(\"sync\", {\n\t\tdescription: \"Sync Pi settings through Git, WebDAV, R2, or S3-compatible storage\",\n\t\tgetArgumentCompletions: completeSyncArguments,\n\t\thandler: async (args, ctx) => {\n\t\t\tif (!ctx.hasUI) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"/sync requires TUI or RPC mode so results and safety prompts are observable.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst signal = sessionAbort.signal;\n\t\t\tconst ready = await initialization;\n\t\t\tif (signal.aborted) return;\n\t\t\tawait check.stop();\n\t\t\tif (signal.aborted) return;\n\t\t\tconst command = splitArgs(args)[0];\n\t\t\tif (\n\t\t\t\tready === false &&\n\t\t\t\tcommand !== \"help\" &&\n\t\t\t\tcommand !== \"unlock\" &&\n\t\t\t\tcommand !== \"migrate-state\"\n\t\t\t) {\n\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\"pi-sync recovery required. Repair the startup error, then /reload before syncing. Use /sync help for recovery guidance.\",\n\t\t\t\t\t\"error\",\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst run = () => handleCommand(args, ctx, signal, loaders, attention);\n\t\t\t// Drain background cache/child cleanup before entering any foreground guard.\n\t\t\t// Help must remain reachable when the state roots themselves need repair.\n\t\t\tif (command === \"migrate-state\" || command === \"help\") await run();\n\t\t\telse await withStateDirectoryAccess(run);\n\t\t},\n\t});\n\n\tpi.on(\"session_start\", async (_event, ctx) => {\n\t\tshutdownAbort?.abort(new DOMException(\"Session replaced\", \"AbortError\"));\n\t\tshutdownAbort = undefined;\n\t\tsessionAbort.abort(new DOMException(\"Session replaced\", \"AbortError\"));\n\t\tsessionAbort = new AbortController();\n\t\tconst signal = sessionAbort.signal;\n\t\tattention.reset(ctx);\n\t\tconst previous = initialization;\n\t\tinitialization = (async () => {\n\t\t\tawait previous;\n\t\t\tif (signal.aborted) return false;\n\t\t\tawait check.stop();\n\t\t\tif (signal.aborted) return false;\n\t\t\ttry {\n\t\t\t\tconst config = await withStateDirectoryAccess(() => startSession(ctx, signal));\n\t\t\t\treturn signal.aborted ? false : config;\n\t\t\t} catch (error) {\n\t\t\t\tif (!signal.aborted && ctx.hasUI) {\n\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t`pi-sync recovery required: ${safeTerminalText(errorMessage(error))}`,\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t})();\n\t\tconst ready = await initialization;\n\t\tif (ready && !signal.aborted) check.start(ctx, signal, ready);\n\t});\n\n\tpi.on(\"session_shutdown\", async (event, ctx) => {\n\t\tsessionAbort.abort(new DOMException(\"Session shut down\", \"AbortError\"));\n\t\tattention.reset(ctx);\n\t\tshutdownAbort?.abort(new DOMException(\"Session shut down again\", \"AbortError\"));\n\t\tconst controller = new AbortController();\n\t\tshutdownAbort = controller;\n\t\tconst signal = combineSignals(controller.signal, AbortSignal.timeout(30_000));\n\t\tconst reason =\n\t\t\ttypeof event === \"object\" && event ? (event as { reason?: string }).reason : undefined;\n\t\ttry {\n\t\t\tconst ready = await initialization;\n\t\t\tif (signal.aborted) return;\n\t\t\tawait check.stop();\n\t\t\tif (signal.aborted) return;\n\t\t\tif (ready !== false && reason !== \"reload\") {\n\t\t\t\tawait withStateDirectoryAccess(async () => {\n\t\t\t\t\tif (signal.aborted) return;\n\t\t\t\t\tawait autoPushSessions(ctx, signal, loaders);\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (!signal.aborted) {\n\t\t\t\tctx.ui.notify(`pi-sync session push skipped: ${errorMessage(error)}`, \"warning\");\n\t\t\t}\n\t\t} finally {\n\t\t\tif (shutdownAbort === controller) shutdownAbort = undefined;\n\t\t}\n\t\tif (signal.aborted) return;\n\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t});\n}\n\nexport type { SyncDependencies } from \"./sync/sync-loaders.js\";\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAM,aAAa;AAEnB,eAAsB,uBACrB,SACA,KACA,QACA,SACA,UACA,OAC0B;AAC1B,MAAI;AACH,UAAM,CAAC,YAAY,GAAG,IAAI,IAAI,UAAU,OAAO;AAC/C,QAAI,eAAe,UAAU,eAAe,UAAU,eAAe,QAAQ;AAC5E,YAAM,IAAI,MAAM,oCAAoC,cAAc,SAAS,EAAE;AAAA,IAC9E;AACA,UAAM,UAAU,aAAa,IAAI;AACjC,QAAI,UAAU,OAAW,SAAQ,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QAAI,GAAG,UAAUA,aAAY,MAAS;AAAA,EACvC,CAAC;AACF;",
|
|
4
|
+
"sourcesContent": ["import type { ExtensionCommandContext, ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { loadConfig, sessionTokenWarnings, syncSessionsWarnings } from \"../settings/config.js\";\nimport {\n\tactiveLocalConfigPath,\n\tcreateLocalConfigDocument,\n\tlocalConfigPath,\n} from \"../settings/config-file.js\";\nimport { localConfigTemplate, readLocalConfigObject } from \"../settings/settings-store.js\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport { unlock, withLock } from \"../state/lock.js\";\nimport {\n\tmigrateLegacyStateDirectory,\n\tstateDirectoryMigrationNotice,\n} from \"../state/state-directory.js\";\nimport { throwIfAborted } from \"../sync/signals.js\";\nimport { syncErrorGuidance } from \"../sync/sync-error-guidance.js\";\nimport { isSyncDecisionRequiredError, SetupPullRequiresUiError } from \"../sync/sync-errors.js\";\nimport type { SyncLoaders } from \"../sync/sync-loaders.js\";\nimport { RemoteSelectionMismatchError } from \"../sync/sync-policy.js\";\nimport { automaticSyncSummary } from \"../ui/automatic-sync-summary.js\";\nimport type { RunRouteResult } from \"../ui/cancellable-operation.js\";\nimport {\n\tparseOptions,\n\tresolveSyncCommand,\n\tsplitArgs,\n\tusage,\n\tvalidateCommandOptions,\n} from \"./command.js\";\nimport type { CommandOptions } from \"./command-types.js\";\n\nconst STATUS_KEY = \"sync\";\n\nexport async function executeRecoveryCommand(\n\trawArgs: string,\n\tctx: ExtensionContext,\n\tsignal: AbortSignal | undefined,\n\tloaders: SyncLoaders,\n\tonCommit?: () => void,\n\tsetup?: string,\n): Promise<RunRouteResult> {\n\ttry {\n\t\tconst [subcommand, ...rest] = splitArgs(rawArgs);\n\t\tif (subcommand !== \"sync\" && subcommand !== \"pull\" && subcommand !== \"push\") {\n\t\t\tthrow new Error(`Unsupported sync recovery route: ${subcommand ?? \"missing\"}`);\n\t\t}\n\t\tconst options = parseOptions(rest);\n\t\tif (setup !== undefined) options.setup = setup;\n\t\tif (signal) options.signal = signal;\n\t\tif (onCommit) options.onCommit = onCommit;\n\t\toptions.reload = false;\n\t\toptions.auto = false;\n\t\tvalidateCommandOptions(subcommand, options);\n\t\tconst operations = await loaders.operations();\n\t\tthrowIfAborted(options.signal);\n\t\tif (subcommand === \"push\") {\n\t\t\tconst outcome = await withLock(\"push\", () => operations.push(ctx, options));\n\t\t\treturn { kind: \"completed\", ...(outcome ? { outcome } : {}) };\n\t\t}\n\t\tif (subcommand === \"pull\") {\n\t\t\tconst outcome = await withLock(\"pull\", () => operations.pull(ctx, options));\n\t\t\treturn { kind: \"completed\", ...(outcome ? { outcome } : {}) };\n\t\t}\n\t\tawait withLock(\"sync\", () => operations.syncBoth(ctx, options));\n\t\treturn { kind: \"completed\" };\n\t} catch (error) {\n\t\tif (signal?.aborted) return { kind: \"failed\" };\n\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t\tif (error instanceof RemoteSelectionMismatchError) {\n\t\t\treturn { kind: \"remote-selection-required\", decision: error.decision };\n\t\t}\n\t\tif (isSyncDecisionRequiredError(error)) {\n\t\t\treturn { kind: \"decision-required\", decision: error.decision };\n\t\t}\n\t\tctx.ui.notify(syncErrorGuidance(error), \"error\");\n\t\treturn { kind: \"failed\" };\n\t}\n}\n\nexport async function executeCommand(\n\trawArgs: string,\n\tctx: ExtensionCommandContext,\n\tsignal: AbortSignal | undefined,\n\tloaders: SyncLoaders,\n\tonCommit?: () => void,\n\tsetup?: string,\n): Promise<RunRouteResult> {\n\ttry {\n\t\tconst command = await resolveSyncCommand(rawArgs, ctx);\n\t\tif (signal?.aborted || !command) return { kind: \"completed\" };\n\t\tconst { subcommand, rest } = command;\n\t\tconst options = parseOptions(rest);\n\t\tif (setup !== undefined) options.setup = setup;\n\t\tif (signal) options.signal = signal;\n\t\tif (onCommit) options.onCommit = onCommit;\n\t\tvalidateCommandOptions(subcommand, options);\n\n\t\tswitch (subcommand) {\n\t\t\tcase \"help\":\n\t\t\t\tctx.ui.notify(usage(), \"info\");\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\tcase \"use\": {\n\t\t\t\tconst { useSyncSetup } = await loaders.setupSwitch();\n\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\tawait useSyncSetup(\n\t\t\t\t\tctx,\n\t\t\t\t\toptions.args[0] ?? \"\",\n\t\t\t\t\tasync (selectedSetup) => {\n\t\t\t\t\t\tconst operations = await loaders.operations();\n\t\t\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\t\t\treturn withLock(\"pull\", () =>\n\t\t\t\t\t\t\toperations.pull(ctx, { ...options, setup: selectedSetup }),\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t\tundefined,\n\t\t\t\t\toptions.signal,\n\t\t\t\t);\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\t}\n\t\t\tcase \"init\":\n\t\t\t\tawait initConfig(ctx, signal);\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\tcase \"config\":\n\t\t\t\tawait showConfig(ctx, options);\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\tcase \"files\": {\n\t\t\t\tconst { showFileSelection } = await import(\"../ui/file-selection.js\");\n\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\tawait showFileSelection(ctx, options.setup, options.signal);\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\t}\n\t\t\tcase \"status\": {\n\t\t\t\tconst operations = await loaders.operations();\n\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\tawait operations.status(ctx, options);\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\t}\n\t\t\tcase \"diff\": {\n\t\t\t\tconst operations = await loaders.operations();\n\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\tawait operations.diff(ctx, options);\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\t}\n\t\t\tcase \"doctor\": {\n\t\t\t\tconst operations = await loaders.operations();\n\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\tawait operations.doctor(ctx, options);\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\t}\n\t\t\tcase \"push\": {\n\t\t\t\tconst operations = await loaders.operations();\n\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\tconst outcome = await withLock(\"push\", () => operations.push(ctx, options));\n\t\t\t\treturn { kind: \"completed\", ...(outcome ? { outcome } : {}) };\n\t\t\t}\n\t\t\tcase \"pull\": {\n\t\t\t\tconst operations = await loaders.operations();\n\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\tconst outcome = await withLock(\"pull\", () => operations.pull(ctx, options));\n\t\t\t\treturn { kind: \"completed\", ...(outcome ? { outcome } : {}) };\n\t\t\t}\n\t\t\tcase \"sync\": {\n\t\t\t\tconst operations = await loaders.operations();\n\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\tawait withLock(\"sync\", () => operations.syncBoth(ctx, options));\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\t}\n\t\t\tcase \"history\": {\n\t\t\t\tconst operations = await loaders.operations();\n\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\tawait operations.history(ctx, options);\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\t}\n\t\t\tcase \"rollback\": {\n\t\t\t\tconst operations = await loaders.operations();\n\t\t\t\tthrowIfAborted(options.signal);\n\t\t\t\tawait withLock(\"rollback\", () => operations.rollback(ctx, options));\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\t}\n\t\t\tcase \"migrate-state\":\n\t\t\t\tawait migrateStateDirectory(ctx, options);\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\tcase \"unlock\":\n\t\t\t\tawait unlock(ctx, options);\n\t\t\t\treturn { kind: \"completed\" };\n\t\t\tdefault:\n\t\t\t\tctx.ui.notify(`Unknown /sync command: ${subcommand}\\n\\n${usage()}`, \"warning\");\n\t\t\t\treturn { kind: \"failed\" };\n\t\t}\n\t} catch (error) {\n\t\tif (signal?.aborted) return { kind: \"failed\" };\n\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t\tif (error instanceof SetupPullRequiresUiError) throw error;\n\t\tif (error instanceof RemoteSelectionMismatchError) {\n\t\t\treturn { kind: \"remote-selection-required\", decision: error.decision };\n\t\t}\n\t\tif (isSyncDecisionRequiredError(error)) {\n\t\t\treturn { kind: \"decision-required\", decision: error.decision };\n\t\t}\n\t\tctx.ui.notify(syncErrorGuidance(error), \"error\");\n\t\treturn { kind: \"failed\" };\n\t}\n}\n\nasync function migrateStateDirectory(ctx: ExtensionCommandContext, options: CommandOptions) {\n\tconst notice = stateDirectoryMigrationNotice();\n\tif (!notice) {\n\t\tctx.ui.notify(\"pi-sync already uses the canonical pi-sync/ state directory.\", \"info\");\n\t\treturn;\n\t}\n\tif (\n\t\t!options.yes &&\n\t\t!(await ctx.ui.confirm(\n\t\t\t\"Migrate pi-sync state directory\",\n\t\t\t\"Confirm that every other Pi process is closed. pi-sync will atomically rename .pisync/ to pi-sync/ without merging or deleting either root.\",\n\t\t\t{ signal: options.signal },\n\t\t))\n\t) {\n\t\tctx.ui.notify(\"pi-sync state migration cancelled.\", \"info\");\n\t\treturn;\n\t}\n\tthrowIfAborted(options.signal);\n\tconst result = await migrateLegacyStateDirectory();\n\tthrowIfAborted(options.signal);\n\tif (result.status === \"ready\") {\n\t\tctx.ui.notify(\"pi-sync already uses the canonical pi-sync/ state directory.\", \"info\");\n\t\treturn;\n\t}\n\tctx.ui.notify(result.message, result.status === \"migrated\" ? \"info\" : \"warning\");\n}\n\nasync function initConfig(ctx: ExtensionCommandContext, signal?: AbortSignal) {\n\tconst configPath = localConfigPath();\n\tif (await readLocalConfigObject()) {\n\t\tctx.ui.notify(`Config already exists: ${await activeLocalConfigPath()}`, \"info\");\n\t\treturn;\n\t}\n\n\tif (ctx.mode === \"tui\") {\n\t\tconst { showSetupWizard } = await import(\"../ui/setup/setup-wizard.js\");\n\t\tthrowIfAborted(signal);\n\t\tawait showSetupWizard(ctx, signal);\n\t\treturn;\n\t}\n\tawait createLocalConfigDocument(localConfigTemplate());\n\tctx.ui.notify(\n\t\t`Created ${configPath}. Add a storage connection and sync setup before syncing.`,\n\t\t\"info\",\n\t);\n}\n\nasync function showConfig(ctx: ExtensionCommandContext, options: CommandOptions) {\n\tconst config = await loadConfig(options.setup);\n\tconst warnings = [\n\t\t...(config.backend.type === \"s3\" ? sessionTokenWarnings(config.backend.profile) : []),\n\t\t...syncSessionsWarnings(config),\n\t];\n\tconst storageLines = configStorageLines(config);\n\tctx.ui.notify(\n\t\t[\n\t\t\t\"pi-sync config:\",\n\t\t\t`sync setup: ${config.setupName}`,\n\t\t\t`storage connection: ${config.connectionName}`,\n\t\t\t...storageLines,\n\t\t\t`storage path: ${config.storagePath}`,\n\t\t\t`automatic sync: ${automaticSyncSummary(config.automatic)}`,\n\t\t\t`included content: ${config.include.join(\", \") || \"none\"}`,\n\t\t\t`sessions: ${config.include.includes(\"sessions\") ? \"included\" : \"not included\"}`,\n\t\t\t`settings file: ${localConfigPath()}`,\n\t\t\t...warnings,\n\t\t].join(\"\\n\"),\n\t\twarnings.length > 0 ? \"warning\" : \"info\",\n\t);\n}\n\nfunction configStorageLines(config: AnySyncConfig) {\n\tswitch (config.backend.type) {\n\t\tcase \"git\":\n\t\t\treturn [\n\t\t\t\t\"kind: git\",\n\t\t\t\t`remote: ${displayGitRemote(config.backend.profile.remote)}`,\n\t\t\t\t\"authentication: existing Git/SSH credentials (not stored)\",\n\t\t\t\t`branch: ${config.backend.destination.branch}`,\n\t\t\t];\n\t\tcase \"webdav\":\n\t\t\treturn [\n\t\t\t\t\"kind: webdav\",\n\t\t\t\t`url: ${displayWebDavUrl(config.backend.profile.url, config.backend.profile.username)}`,\n\t\t\t\t\"username: configured (value hidden)\",\n\t\t\t\t\"password: configured\",\n\t\t\t];\n\t\tcase \"s3\":\n\t\t\treturn [\n\t\t\t\t\"kind: s3\",\n\t\t\t\t`endpoint: ${config.backend.profile.endpoint}`,\n\t\t\t\t`bucket: ${config.backend.destination.bucket}`,\n\t\t\t\t`region: ${config.backend.profile.region}`,\n\t\t\t\t\"access key id: configured\",\n\t\t\t\t\"secret access key: configured\",\n\t\t\t\t`session token: ${config.backend.profile.sessionToken ? \"configured\" : \"not configured\"}`,\n\t\t\t];\n\t}\n}\n\nfunction displayGitRemote(value: string | undefined) {\n\tif (!value) return \"missing\";\n\ttry {\n\t\tconst url = new URL(value);\n\t\turl.username = \"\";\n\t\turl.password = \"\";\n\t\turl.search = \"\";\n\t\turl.hash = \"\";\n\t\treturn url.toString();\n\t} catch {\n\t\treturn value.replace(/^(?:[^@\\s]+@)?(?<host>[^:]+):.+$/u, \"$<host>:\u2026\");\n\t}\n}\n\nfunction displayWebDavUrl(value: string | undefined, username: string | undefined) {\n\tif (!value) return \"missing\";\n\ttry {\n\t\tconst url = new URL(value);\n\t\turl.username = \"\";\n\t\turl.password = \"\";\n\t\turl.search = \"\";\n\t\turl.hash = \"\";\n\t\treturn username ? `${url.origin}/\u2026` : `${url.origin}${url.pathname}`;\n\t} catch {\n\t\treturn \"invalid (value hidden)\";\n\t}\n}\n", "import type { ExtensionCommandContext, ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { loadConfig } from \"../settings/config.js\";\nimport { readStateForConfig, syncStateFingerprint } from \"../state/sync-state-store.js\";\nimport { combineSignals } from \"../sync/signals.js\";\nimport { errorMessage } from \"../sync/sync-errors.js\";\nimport type { SyncLoaders } from \"../sync/sync-loaders.js\";\nimport { formatRemoteSelectionMismatch } from \"../sync/sync-policy.js\";\nimport type { RunRouteResult } from \"../ui/cancellable-operation.js\";\nimport {\n\tobservationMatchesConfig,\n\ttype SyncAttentionController,\n\ttype SyncAttentionOrigin,\n\tsyncAttentionMatchesConfig,\n} from \"../ui/sync-attention.js\";\nimport { parseOptions, splitArgs } from \"./command.js\";\nimport { executeCommand, executeRecoveryCommand } from \"./command-execution.js\";\n\nconst STATUS_KEY = \"sync\";\n\nexport async function handleCommand(\n\trawArgs: string,\n\tctx: ExtensionCommandContext,\n\tsessionSignal: AbortSignal,\n\tloaders: SyncLoaders,\n\tattention: SyncAttentionController,\n) {\n\tawait reconcileObservation(attention, sessionSignal);\n\tif (sessionSignal.aborted) return;\n\tconst run = (route: string, signal?: AbortSignal, onCommit?: () => void, target?: string) =>\n\t\texecuteCommand(\n\t\t\troute,\n\t\t\tctx,\n\t\t\tcombineSignals(sessionSignal, signal),\n\t\t\tloaders,\n\t\t\tobservationCommitCallback(attention, sessionSignal, onCommit),\n\t\t\ttarget,\n\t\t);\n\tif (!rawArgs.trim()) {\n\t\ttry {\n\t\t\tconst { showSyncManager } = await import(\"../ui/manager-ui.js\");\n\t\t\tif (sessionSignal.aborted) return;\n\t\t\tawait showSyncManager(ctx, run, sessionSignal, {\n\t\t\t\tgetAttention: () => attention.current(),\n\t\t\t\tgetObservation: () => attention.observation(),\n\t\t\t\tonObservationInvalidated: () => attention.clearObservation(),\n\t\t\t\tonSelectionResolved: (expected) => {\n\t\t\t\t\tif (attention.current() === expected) attention.clear(ctx);\n\t\t\t\t},\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tif (sessionSignal.aborted) return;\n\t\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t\t\tctx.ui.notify(errorMessage(error), \"error\");\n\t\t}\n\t\tawait reconcileObservation(attention, sessionSignal);\n\t\tif (!sessionSignal.aborted) await attention.publish(ctx, sessionSignal);\n\t\treturn;\n\t}\n\tconst result = await run(rawArgs);\n\tif (result.kind === \"decision-required\") {\n\t\tctx.ui.notify(result.decision.directMessage, \"error\");\n\t} else if (result.kind === \"remote-selection-required\") {\n\t\tconst origin = directSelectionOrigin(rawArgs);\n\t\tif (origin) attention.set(result.decision, origin);\n\t\tconst deterministic = splitArgs(rawArgs).some((arg) => arg === \"--yes\" || arg === \"-y\");\n\t\tif (origin && ctx.mode === \"tui\" && !deterministic) {\n\t\t\tawait resolveSelectionAttention(ctx, attention, sessionSignal, loaders);\n\t\t} else {\n\t\t\tctx.ui.notify(\n\t\t\t\tformatRemoteSelectionMismatch(\n\t\t\t\t\tresult.decision.setupName,\n\t\t\t\t\tresult.decision.localInclude,\n\t\t\t\t\tresult.decision.remoteInclude,\n\t\t\t\t),\n\t\t\t\t\"error\",\n\t\t\t);\n\t\t}\n\t}\n\tawait clearAttentionAfterCompletedOperation(rawArgs, result, ctx, attention, sessionSignal);\n\tawait reconcileSelectionAttention(ctx, attention, sessionSignal);\n\tawait reconcileObservation(attention, sessionSignal);\n\tif (!sessionSignal.aborted) await attention.publish(ctx, sessionSignal);\n}\n\nfunction observationCommitCallback(\n\tattention: SyncAttentionController,\n\tsessionSignal: AbortSignal,\n\tonCommit?: () => void,\n) {\n\tconst observed = attention.observation();\n\treturn () => {\n\t\t// Opening or cancelling a review changes nothing. A commit may change data\n\t\t// even if later publication/baseline cleanup fails; never restore old hints.\n\t\tif (!sessionSignal.aborted && attention.observation() === observed)\n\t\t\tattention.clearObservation();\n\t\tonCommit?.();\n\t};\n}\n\nasync function reconcileObservation(attention: SyncAttentionController, signal: AbortSignal) {\n\tconst observed = attention.observation();\n\tif (!observed || signal.aborted) return;\n\ttry {\n\t\tconst config = await loadConfig();\n\t\tif (signal.aborted || attention.observation() !== observed) return;\n\t\tif (!observationMatchesConfig(observed, config)) {\n\t\t\tattention.clearObservation();\n\t\t\treturn;\n\t\t}\n\t\tconst state = await readStateForConfig(config);\n\t\tif (signal.aborted || attention.observation() !== observed) return;\n\t\tif (syncStateFingerprint(state) !== observed.inspection.stateIdentity)\n\t\t\tattention.clearObservation();\n\t} catch {\n\t\tif (!signal.aborted && attention.observation() === observed) attention.clearObservation();\n\t}\n}\n\nasync function clearAttentionAfterCompletedOperation(\n\trawArgs: string,\n\tresult: RunRouteResult,\n\tctx: ExtensionContext,\n\tattention: SyncAttentionController,\n\tsignal: AbortSignal,\n) {\n\tif (result.kind !== \"completed\" || result.outcome === \"cancelled\" || signal.aborted) return;\n\tconst [command, ...rest] = splitArgs(rawArgs);\n\tif (command !== \"sync\" && command !== \"pull\" && command !== \"push\") return;\n\tconst current = attention.current();\n\tif (!current) return;\n\ttry {\n\t\tconst options = parseOptions(rest);\n\t\tconst setupName = options.setup ?? (await loadConfig()).setupName;\n\t\tif (signal.aborted || attention.current() !== current) return;\n\t\tif (current.decision.setupName === setupName) attention.clear(ctx);\n\t} catch {\n\t\t// Attention reconciliation below owns malformed or concurrently changed settings.\n\t}\n}\n\nasync function reconcileSelectionAttention(\n\tctx: ExtensionContext,\n\tattention: SyncAttentionController,\n\tsignal: AbortSignal,\n) {\n\tconst current = attention.current();\n\tif (!current || signal.aborted) return;\n\ttry {\n\t\tconst config = await loadConfig(current.decision.setupName);\n\t\tif (signal.aborted || attention.current() !== current) return;\n\t\tif (!syncAttentionMatchesConfig(current, config)) attention.clear(ctx);\n\t} catch {\n\t\tif (!signal.aborted && attention.current() === current) attention.clear(ctx);\n\t}\n}\n\nfunction directSelectionOrigin(rawArgs: string): SyncAttentionOrigin | undefined {\n\tconst command = splitArgs(rawArgs)[0];\n\treturn command === \"sync\" || command === \"pull\" || command === \"push\" ? command : undefined;\n}\n\nexport async function resolveSelectionAttention(\n\tctx: ExtensionContext,\n\tattention: SyncAttentionController,\n\tsignal: AbortSignal,\n\tloaders: SyncLoaders,\n\toptions: {\n\t\tcancelLabel?: string;\n\t\twithStateAccess?: <T>(task: () => Promise<T>) => Promise<T>;\n\t} = {},\n) {\n\tconst current = attention.current();\n\tif (!current || signal.aborted) return;\n\tconst { dispatchManagerResult } = await import(\"../ui/manager-result-dispatcher.js\");\n\tif (signal.aborted || attention.current() !== current) return;\n\tawait dispatchManagerResult(\n\t\tctx,\n\t\t{ kind: \"remote-selection-required\", decision: current.decision },\n\t\tcurrent.origin,\n\t\t(route, actionSignal, onCommit, target) => {\n\t\t\tconst execute = () =>\n\t\t\t\texecuteRecoveryCommand(\n\t\t\t\t\troute,\n\t\t\t\t\tctx,\n\t\t\t\t\tcombineSignals(signal, actionSignal),\n\t\t\t\t\tloaders,\n\t\t\t\t\tobservationCommitCallback(attention, signal, onCommit),\n\t\t\t\t\ttarget,\n\t\t\t\t);\n\t\t\treturn options.withStateAccess ? options.withStateAccess(execute) : execute();\n\t\t},\n\t\tsignal,\n\t\t{\n\t\t\tcancelLabel: options.cancelLabel,\n\t\t\twithStateAccess: options.withStateAccess,\n\t\t\tonSelectionResolved: () => {\n\t\t\t\tif (attention.current() === current) attention.clear(ctx);\n\t\t\t},\n\t\t},\n\t);\n}\n", "export function isMissingConfigError(error: unknown) {\n\treturn (\n\t\terror instanceof Error &&\n\t\t(error.message.startsWith(\"Missing pi-sync settings.\") ||\n\t\t\terror.message === \"No sync setups are configured.\")\n\t);\n}\n", "import type { ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { setSyncSetupCompletions } from \"../commands/command.js\";\nimport type { CommandOptions } from \"../commands/command-types.js\";\nimport { loadConfig, loadPartialConfig } from \"../settings/config.js\";\nimport { isMissingConfigError } from \"../settings/config-errors.js\";\nimport { consumeLocalConfigMigrationNotice } from \"../settings/config-file.js\";\nimport { configuredSyncSetupNames } from \"../settings/settings-store.js\";\nimport { snapshotOptionsForContext } from \"../snapshot/session-paths.js\";\nimport { recoverSnapshotTransactionsOnStartup } from \"../snapshot/snapshot-transaction.js\";\nimport { withLock } from \"../state/lock.js\";\nimport { stateDirectoryMigrationNotice } from \"../state/state-directory.js\";\nimport { ensureStateDir, readStateForConfig } from \"../state/sync-state-store.js\";\nimport { safeTerminalText } from \"../ui/terminal-text.js\";\nimport { throwIfAborted } from \"./signals.js\";\nimport { errorMessage } from \"./sync-errors.js\";\nimport type { SyncLoaders } from \"./sync-loaders.js\";\n\nconst AUTO_SYNC_OPTIONS: CommandOptions = {\n\tyes: true,\n\tforce: false,\n\tstale: false,\n\tsilent: true,\n\treload: false,\n\tauto: true,\n\targs: [],\n};\n\nconst STATUS_KEY = \"sync\";\n\nexport async function startSession(ctx: ExtensionContext, signal: AbortSignal) {\n\tthrowIfAborted(signal);\n\tconst stateNotice = stateDirectoryMigrationNotice();\n\tif (stateNotice && ctx.hasUI) ctx.ui.notify(stateNotice, \"warning\");\n\t// Recovery can restore managed files: finish it before Pi accepts user edits.\n\t// Unlike remote inspection, it must never be detached behind startup.\n\tawait recoverSnapshotTransactionsOnStartup();\n\tthrowIfAborted(signal);\n\ttry {\n\t\tconst names = await configuredSyncSetupNames();\n\t\tthrowIfAborted(signal);\n\t\tsetSyncSetupCompletions(names);\n\t} catch {\n\t\tif (signal.aborted) return;\n\t\tsetSyncSetupCompletions([]);\n\t}\n\tconst migrationNotice = consumeLocalConfigMigrationNotice();\n\tif (migrationNotice && ctx.hasUI) ctx.ui.notify(migrationNotice, \"warning\");\n\tthrowIfAborted(signal);\n\tif (!ctx.hasUI) return;\n\ttry {\n\t\tconst config = await loadConfig();\n\t\tthrowIfAborted(signal);\n\t\treturn config.automatic ? config : undefined;\n\t} catch (error) {\n\t\tthrowIfAborted(signal);\n\t\tif (!isMissingConfigError(error)) {\n\t\t\tctx.ui.notify(\n\t\t\t\t`pi-sync startup check skipped: ${safeTerminalText(errorMessage(error))}`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t}\n\t}\n}\n\nexport async function autoPushSessions(\n\tctx: ExtensionContext,\n\tsignal: AbortSignal,\n\tloaders: SyncLoaders,\n) {\n\ttry {\n\t\tconst partial = await loadPartialConfig();\n\t\tthrowIfAborted(signal);\n\t\tif (!partial.automatic) return;\n\t\tif (!partial.include.includes(\"sessions\")) return;\n\t\tawait ensureStateDir();\n\t\tthrowIfAborted(signal);\n\t\tconst config = await loadConfig();\n\t\tthrowIfAborted(signal);\n\t\tif (!config.include.includes(\"sessions\")) return;\n\t\tconst [operations, snapshotModule, syncStateModule] = await Promise.all([\n\t\t\tloaders.operations(),\n\t\t\tloaders.snapshot(),\n\t\t\tloaders.syncState(),\n\t\t]);\n\t\tthrowIfAborted(signal);\n\t\tawait withLock(\"auto-session-push\", async () => {\n\t\t\tthrowIfAborted(signal);\n\t\t\tconst state = await readStateForConfig(config);\n\t\t\tthrowIfAborted(signal);\n\t\t\tconst local = await snapshotModule.createSnapshot(config.snapshotIdentity, {\n\t\t\t\t...snapshotOptionsForContext(ctx, config),\n\t\t\t\tsignal,\n\t\t\t});\n\t\t\tthrowIfAborted(signal);\n\t\t\tif (!syncStateModule.hasLocalChanges(local, state, config)) return;\n\t\t\tawait operations.push(ctx, { ...AUTO_SYNC_OPTIONS, signal }, { config, state, local });\n\t\t});\n\t} catch (error) {\n\t\tif (signal.aborted || isMissingConfigError(error)) return;\n\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t\tctx.ui.notify(`pi-sync session push skipped: ${errorMessage(error)}`, \"warning\");\n\t}\n}\n", "import type { ExtensionContext } from \"@earendil-works/pi-coding-agent\";\nimport { loadConfigForCheck, syncCheckConfigFingerprint } from \"../settings/config.js\";\nimport { isMissingConfigError } from \"../settings/config-errors.js\";\nimport type { AnySyncConfig } from \"../settings/settings-types.js\";\nimport { snapshotOptionsForContext } from \"../snapshot/session-paths.js\";\nimport { withLock } from \"../state/lock.js\";\nimport { withStateDirectoryAccess } from \"../state/state-directory.js\";\nimport { readStateForConfig, syncStateFingerprint } from \"../state/sync-state-store.js\";\nimport type { SyncAttentionController } from \"../ui/sync-attention.js\";\nimport { safeTerminalText } from \"../ui/terminal-text.js\";\nimport { combineSignals, throwIfAborted } from \"./signals.js\";\nimport { errorMessage } from \"./sync-errors.js\";\nimport type { SyncLoaders } from \"./sync-loaders.js\";\n\nconst STATUS_KEY = \"sync\";\n\n/** One owned task per extension session, never keyed by the shared headless UI. */\nexport function createStartupCheck(\n\tloaders: SyncLoaders,\n\tattention: SyncAttentionController,\n\ttimeoutMs = 30_000,\n) {\n\tlet active:\n\t\t| {\n\t\t\t\tcontroller: AbortController;\n\t\t\t\tpromise: Promise<void>;\n\t\t\t\towner: ExtensionContext[\"sessionManager\"];\n\t\t }\n\t\t| undefined;\n\n\treturn {\n\t\tstart(ctx: ExtensionContext, sessionSignal: AbortSignal, initialConfig?: AnySyncConfig) {\n\t\t\tif (!ctx.hasUI || sessionSignal.aborted) return;\n\t\t\tif (active) throw new Error(\"Previous startup check has not been drained.\");\n\t\t\tconst controller = new AbortController();\n\t\t\tconst signal = combineSignals(sessionSignal, controller.signal);\n\t\t\tconst task = { controller, owner: ctx.sessionManager, promise: Promise.resolve() };\n\t\t\tactive = task;\n\t\t\tconst isCurrent = () =>\n\t\t\t\t!sessionSignal.aborted && active === task && task.owner === ctx.sessionManager;\n\t\t\tconst timer = setTimeout(\n\t\t\t\t() => controller.abort(new DOMException(\"Startup check timed out\", \"TimeoutError\")),\n\t\t\t\ttimeoutMs,\n\t\t\t);\n\t\t\tlet config: AnySyncConfig | undefined;\n\t\t\tlet checking = false;\n\t\t\t// Handle every detached rejection here; Pi's awaited event runner cannot catch it.\n\t\t\ttask.promise = Promise.resolve()\n\t\t\t\t.then(async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\t\tconfig = initialConfig ?? (await loadConfigForCheck());\n\t\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\t\tif (!config.automatic) return;\n\t\t\t\t\t\tconst captured = config;\n\t\t\t\t\t\tconst identity = syncCheckConfigFingerprint(captured);\n\t\t\t\t\t\tchecking = true;\n\t\t\t\t\t\tctx.ui.setStatus(STATUS_KEY, \"checking in background\");\n\t\t\t\t\t\tconst { inspectSync } = await loaders.inspection();\n\t\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\t\tconst currentConfig = await loadConfigForCheck();\n\t\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\t\tif (syncCheckConfigFingerprint(currentConfig) !== identity) return;\n\t\t\t\t\t\t// Lock order: state migration guard \u2192 sync operation \u2192 backend cache.\n\t\t\t\t\t\t// Read heads may write only private cache data. Never call doctor/syncBoth.\n\t\t\t\t\t\tconst inspection = await withStateDirectoryAccess(() => {\n\t\t\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\t\t\treturn withLock(\"startup-check\", () => {\n\t\t\t\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\t\t\t\treturn inspectSync(captured, snapshotOptionsForContext(ctx, captured), signal);\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t});\n\t\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\t\tconst latest = await loadConfigForCheck();\n\t\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\t\tif (syncCheckConfigFingerprint(latest) !== identity) return;\n\t\t\t\t\t\tconst state = await withStateDirectoryAccess(() => readStateForConfig(latest));\n\t\t\t\t\t\tthrowIfAborted(signal);\n\t\t\t\t\t\tif (syncStateFingerprint(state) !== inspection.stateIdentity || !isCurrent()) return;\n\t\t\t\t\t\tattention.observe({\n\t\t\t\t\t\t\tsetupName: captured.setupName,\n\t\t\t\t\t\t\tconfigIdentity: identity,\n\t\t\t\t\t\t\tcheckedAt: new Date().toISOString(),\n\t\t\t\t\t\t\tinspection,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (ctx.mode === \"rpc\") attention.notifyObservation(ctx);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (!isCurrent() || sessionSignal.aborted || isMissingConfigError(error)) return;\n\t\t\t\t\t\tif (signal.aborted && controller.signal.reason?.name !== \"TimeoutError\") return;\n\t\t\t\t\t\t// A settings edit invalidates failures as well as successful observations.\n\t\t\t\t\t\tif (config) {\n\t\t\t\t\t\t\tconst latest = await loadConfigForCheck().catch(() => undefined);\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t!isCurrent() ||\n\t\t\t\t\t\t\t\t(signal.aborted && controller.signal.reason?.name !== \"TimeoutError\")\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t!latest ||\n\t\t\t\t\t\t\t\tsyncCheckConfigFingerprint(latest) !== syncCheckConfigFingerprint(config)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\t`pi-sync startup check skipped: ${safeTerminalText(errorMessage(error))}. Run /sync status to retry. No startup transfer was performed.`,\n\t\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t\t);\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\t\tif (isCurrent() && checking) await attention.publish(ctx, sessionSignal);\n\t\t\t\t\t\tif (active === task) active = undefined;\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\t// UI teardown can itself throw. No unhandled rejection or retained timer.\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tif (active === task) active = undefined;\n\t\t\t\t});\n\t\t},\n\t\tasync stop() {\n\t\t\tconst task = active;\n\t\t\tif (!task) return;\n\t\t\ttask.controller.abort(new DOMException(\"Startup check cancelled\", \"AbortError\"));\n\t\t\t// Drain the actual work, including child/ref cleanup, before foreground guards.\n\t\t\tawait task.promise;\n\t\t},\n\t};\n}\n", "type SetupSwitchModule = Pick<typeof import(\"./setup-switch.js\"), \"useSyncSetup\">;\ntype SnapshotModule = Pick<typeof import(\"../snapshot/snapshot.js\"), \"createSnapshot\">;\ntype SyncStateModule = Pick<typeof import(\"./sync-state.js\"), \"hasLocalChanges\">;\ntype SyncOperations = typeof import(\"./sync-operations.js\");\n\ntype SyncInspectionModule = Pick<typeof import(\"./sync-inspection.js\"), \"inspectSync\">;\n\nexport interface SyncDependencies {\n\tloadSyncInspection(): Promise<SyncInspectionModule>;\n\tloadSetupSwitch(): Promise<SetupSwitchModule>;\n\tloadSnapshot(): Promise<SnapshotModule>;\n\tloadSyncState(): Promise<SyncStateModule>;\n\tloadSyncOperations(): Promise<SyncOperations>;\n}\n\nexport interface SyncLoaders {\n\tinspection(): Promise<SyncInspectionModule>;\n\tsetupSwitch(): Promise<SetupSwitchModule>;\n\tsnapshot(): Promise<SnapshotModule>;\n\tsyncState(): Promise<SyncStateModule>;\n\toperations(): Promise<SyncOperations>;\n}\n\nexport function createSyncLoaders(dependencies: Partial<SyncDependencies>): SyncLoaders {\n\tconst loaders: SyncLoaders = {\n\t\tinspection: cachedModuleLoader(\n\t\t\tdependencies.loadSyncInspection ?? (() => import(\"./sync-inspection.js\")),\n\t\t),\n\t\tsetupSwitch: cachedModuleLoader(\n\t\t\tdependencies.loadSetupSwitch ?? (() => import(\"./setup-switch.js\")),\n\t\t),\n\t\tsnapshot: cachedModuleLoader(\n\t\t\tdependencies.loadSnapshot ?? (() => import(\"../snapshot/snapshot.js\")),\n\t\t),\n\t\tsyncState: cachedModuleLoader(dependencies.loadSyncState ?? (() => import(\"./sync-state.js\"))),\n\t\toperations: cachedModuleLoader(\n\t\t\tdependencies.loadSyncOperations ?? (() => import(\"./sync-operations.js\")),\n\t\t),\n\t};\n\treturn loaders;\n}\n\nfunction cachedModuleLoader<Module>(load: () => Promise<Module>): () => Promise<Module> {\n\tlet pending: Promise<Module> | undefined;\n\treturn () => {\n\t\tif (!pending) {\n\t\t\tpending = load().catch((error) => {\n\t\t\t\tpending = undefined;\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t}\n\t\treturn pending;\n\t};\n}\n", "import type { ExtensionAPI } from \"@earendil-works/pi-coding-agent\";\nimport { completeSyncArguments, splitArgs } from \"./commands/command.js\";\nimport { handleCommand } from \"./commands/command-handler.js\";\nimport type { AnySyncConfig } from \"./settings/settings-types.js\";\nimport { withStateDirectoryAccess } from \"./state/state-directory.js\";\nimport { autoPushSessions, startSession } from \"./sync/automatic-sync.js\";\nimport { combineSignals } from \"./sync/signals.js\";\nimport { createStartupCheck } from \"./sync/startup-check.js\";\nimport { errorMessage } from \"./sync/sync-errors.js\";\nimport { createSyncLoaders, type SyncDependencies } from \"./sync/sync-loaders.js\";\nimport { createSyncAttentionController } from \"./ui/sync-attention.js\";\nimport { safeTerminalText } from \"./ui/terminal-text.js\";\n\nconst STATUS_KEY = \"sync\";\n\nexport default function sync(pi: ExtensionAPI, dependencies: Partial<SyncDependencies> = {}) {\n\tconst loaders = createSyncLoaders(dependencies);\n\tconst attention = createSyncAttentionController();\n\tconst check = createStartupCheck(loaders, attention);\n\tlet sessionAbort = new AbortController();\n\tlet shutdownAbort: AbortController | undefined;\n\tlet initialization = Promise.resolve<AnySyncConfig | false | undefined>(undefined);\n\n\tpi.registerCommand(\"sync\", {\n\t\tdescription: \"Sync Pi settings through Git, WebDAV, R2, or S3-compatible storage\",\n\t\tgetArgumentCompletions: completeSyncArguments,\n\t\thandler: async (args, ctx) => {\n\t\t\tif (!ctx.hasUI) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"/sync requires TUI or RPC mode so results and safety prompts are observable.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst signal = sessionAbort.signal;\n\t\t\tconst ready = await initialization;\n\t\t\tif (signal.aborted) return;\n\t\t\tawait check.stop();\n\t\t\tif (signal.aborted) return;\n\t\t\tconst command = splitArgs(args)[0];\n\t\t\tif (\n\t\t\t\tready === false &&\n\t\t\t\tcommand !== \"help\" &&\n\t\t\t\tcommand !== \"unlock\" &&\n\t\t\t\tcommand !== \"migrate-state\"\n\t\t\t) {\n\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\"pi-sync recovery required. Repair the startup error, then /reload before syncing. Use /sync help for recovery guidance.\",\n\t\t\t\t\t\"error\",\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst run = () => handleCommand(args, ctx, signal, loaders, attention);\n\t\t\t// Drain background cache/child cleanup before entering any foreground guard.\n\t\t\t// Help must remain reachable when the state roots themselves need repair.\n\t\t\tif (command === \"migrate-state\" || command === \"help\") await run();\n\t\t\telse await withStateDirectoryAccess(run);\n\t\t},\n\t});\n\n\tpi.on(\"session_start\", async (_event, ctx) => {\n\t\tshutdownAbort?.abort(new DOMException(\"Session replaced\", \"AbortError\"));\n\t\tshutdownAbort = undefined;\n\t\tsessionAbort.abort(new DOMException(\"Session replaced\", \"AbortError\"));\n\t\tsessionAbort = new AbortController();\n\t\tconst signal = sessionAbort.signal;\n\t\tattention.reset(ctx);\n\t\tconst previous = initialization;\n\t\tinitialization = (async () => {\n\t\t\tawait previous;\n\t\t\tif (signal.aborted) return false;\n\t\t\tawait check.stop();\n\t\t\tif (signal.aborted) return false;\n\t\t\ttry {\n\t\t\t\tconst config = await withStateDirectoryAccess(() => startSession(ctx, signal));\n\t\t\t\treturn signal.aborted ? false : config;\n\t\t\t} catch (error) {\n\t\t\t\tif (!signal.aborted && ctx.hasUI) {\n\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t`pi-sync recovery required: ${safeTerminalText(errorMessage(error))}`,\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t})();\n\t\tconst ready = await initialization;\n\t\tif (ready && !signal.aborted) check.start(ctx, signal, ready);\n\t});\n\n\tpi.on(\"session_shutdown\", async (event, ctx) => {\n\t\tsessionAbort.abort(new DOMException(\"Session shut down\", \"AbortError\"));\n\t\tattention.reset(ctx);\n\t\tshutdownAbort?.abort(new DOMException(\"Session shut down again\", \"AbortError\"));\n\t\tconst controller = new AbortController();\n\t\tshutdownAbort = controller;\n\t\tconst signal = combineSignals(controller.signal, AbortSignal.timeout(30_000));\n\t\tconst reason =\n\t\t\ttypeof event === \"object\" && event ? (event as { reason?: string }).reason : undefined;\n\t\ttry {\n\t\t\tconst ready = await initialization;\n\t\t\tif (signal.aborted) return;\n\t\t\tawait check.stop();\n\t\t\tif (signal.aborted) return;\n\t\t\tif (ready !== false && reason !== \"reload\") {\n\t\t\t\tawait withStateDirectoryAccess(async () => {\n\t\t\t\t\tif (signal.aborted) return;\n\t\t\t\t\tawait autoPushSessions(ctx, signal, loaders);\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (!signal.aborted) {\n\t\t\t\tctx.ui.notify(`pi-sync session push skipped: ${errorMessage(error)}`, \"warning\");\n\t\t\t}\n\t\t} finally {\n\t\t\tif (shutdownAbort === controller) shutdownAbort = undefined;\n\t\t}\n\t\tif (signal.aborted) return;\n\t\tctx.ui.setStatus(STATUS_KEY, undefined);\n\t});\n}\n\nexport type { SyncDependencies } from \"./sync/sync-loaders.js\";\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAM,aAAa;AAEnB,eAAsB,uBACrB,SACA,KACA,QACA,SACA,UACA,OAC0B;AAC1B,MAAI;AACH,UAAM,CAAC,YAAY,GAAG,IAAI,IAAI,UAAU,OAAO;AAC/C,QAAI,eAAe,UAAU,eAAe,UAAU,eAAe,QAAQ;AAC5E,YAAM,IAAI,MAAM,oCAAoC,cAAc,SAAS,EAAE;AAAA,IAC9E;AACA,UAAM,UAAU,aAAa,IAAI;AACjC,QAAI,UAAU,OAAW,SAAQ,QAAQ;AACzC,QAAI,OAAQ,SAAQ,SAAS;AAC7B,QAAI,SAAU,SAAQ,WAAW;AACjC,YAAQ,SAAS;AACjB,YAAQ,OAAO;AACf,2BAAuB,YAAY,OAAO;AAC1C,UAAM,aAAa,MAAM,QAAQ,WAAW;AAC5C,mBAAe,QAAQ,MAAM;AAC7B,QAAI,eAAe,QAAQ;AAC1B,YAAM,UAAU,MAAM,SAAS,QAAQ,MAAM,WAAW,KAAK,KAAK,OAAO,CAAC;AAC1E,aAAO,EAAE,MAAM,aAAa,GAAI,UAAU,EAAE,QAAQ,IAAI,CAAC,EAAG;AAAA,IAC7D;AACA,QAAI,eAAe,QAAQ;AAC1B,YAAM,UAAU,MAAM,SAAS,QAAQ,MAAM,WAAW,KAAK,KAAK,OAAO,CAAC;AAC1E,aAAO,EAAE,MAAM,aAAa,GAAI,UAAU,EAAE,QAAQ,IAAI,CAAC,EAAG;AAAA,IAC7D;AACA,UAAM,SAAS,QAAQ,MAAM,WAAW,SAAS,KAAK,OAAO,CAAC;AA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gBAAgB;AACvC,oBAAgB;AAChB,UAAM,SAAS,eAAe,WAAW,QAAQ,YAAY,QAAQ,GAAM,CAAC;AAC5E,UAAM,SACL,OAAO,UAAU,YAAY,QAAS,MAA8B,SAAS;AAC9E,QAAI;AACH,YAAM,QAAQ,MAAM;AACpB,UAAI,OAAO,QAAS;AACpB,YAAM,MAAM,KAAK;AACjB,UAAI,OAAO,QAAS;AACpB,UAAI,UAAU,SAAS,WAAW,UAAU;AAC3C,cAAM,yBAAyB,YAAY;AAC1C,cAAI,OAAO,QAAS;AACpB,gBAAM,iBAAiB,KAAK,QAAQ,OAAO;AAAA,QAC5C,CAAC;AAAA,MACF;AAAA,IACD,SAAS,OAAO;AACf,UAAI,CAAC,OAAO,SAAS;AACpB,YAAI,GAAG,OAAO,iCAAiC,aAAa,KAAK,CAAC,IAAI,SAAS;AAAA,MAChF;AAAA,IACD,UAAE;AACD,UAAI,kBAAkB,WAAY,iBAAgB;AAAA,IACnD;AACA,QAAI,OAAO,QAAS;AACpB,QAAI,GAAG,UAAUA,aAAY,MAAS;AAAA,EACvC,CAAC;AACF;",
|
|
6
6
|
"names": ["STATUS_KEY", "STATUS_KEY", "STATUS_KEY", "STATUS_KEY"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -53,7 +53,7 @@ export async function handleCommand(
|
|
|
53
53
|
ctx.ui.notify(errorMessage(error), "error");
|
|
54
54
|
}
|
|
55
55
|
await reconcileObservation(attention, sessionSignal);
|
|
56
|
-
if (!sessionSignal.aborted) attention.publish(ctx);
|
|
56
|
+
if (!sessionSignal.aborted) await attention.publish(ctx, sessionSignal);
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
59
|
const result = await run(rawArgs);
|
|
@@ -79,7 +79,7 @@ export async function handleCommand(
|
|
|
79
79
|
await clearAttentionAfterCompletedOperation(rawArgs, result, ctx, attention, sessionSignal);
|
|
80
80
|
await reconcileSelectionAttention(ctx, attention, sessionSignal);
|
|
81
81
|
await reconcileObservation(attention, sessionSignal);
|
|
82
|
-
if (!sessionSignal.aborted) attention.publish(ctx);
|
|
82
|
+
if (!sessionSignal.aborted) await attention.publish(ctx, sessionSignal);
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
function observationCommitCallback(
|
|
@@ -107,7 +107,7 @@ export function createStartupCheck(
|
|
|
107
107
|
);
|
|
108
108
|
} finally {
|
|
109
109
|
clearTimeout(timer);
|
|
110
|
-
if (isCurrent() && checking) attention.publish(ctx);
|
|
110
|
+
if (isCurrent() && checking) await attention.publish(ctx, sessionSignal);
|
|
111
111
|
if (active === task) active = undefined;
|
|
112
112
|
}
|
|
113
113
|
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { EditorStatusWidget } from "@narumitw/pi-tui-kit";
|