@ff-labs/pi-fff 0.10.7-nightly.e542d8a → 0.10.7-nightly.e8d80e4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/index.ts +54 -22
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ff-labs/pi-fff",
|
|
3
3
|
"public": true,
|
|
4
|
-
"version": "0.10.7-nightly.
|
|
4
|
+
"version": "0.10.7-nightly.e8d80e4",
|
|
5
5
|
"description": "pi extension: FFF-powered fuzzy file and content search",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"typecheck": "tsc --noEmit"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@ff-labs/fff-bun": "0.10.7-nightly.
|
|
45
|
-
"@ff-labs/fff-node": "0.10.7-nightly.
|
|
44
|
+
"@ff-labs/fff-bun": "0.10.7-nightly.e8d80e4",
|
|
45
|
+
"@ff-labs/fff-node": "0.10.7-nightly.e8d80e4"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@earendil-works/pi-coding-agent": "*",
|
package/src/index.ts
CHANGED
|
@@ -78,6 +78,10 @@ function resolveToolNames(mode: FffMode): ToolNames {
|
|
|
78
78
|
return mode === "override" ? OVERRIDE_TOOL_NAMES : FFF_TOOL_NAMES;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
function toolNameList(names: ToolNames): string[] {
|
|
82
|
+
return [names.grep, names.find, names.multiGrep];
|
|
83
|
+
}
|
|
84
|
+
|
|
81
85
|
// ---------------------------------------------------------------------------
|
|
82
86
|
// Cursor store — simple bounded Map for pagination cursors
|
|
83
87
|
// ---------------------------------------------------------------------------
|
|
@@ -670,11 +674,19 @@ export default function fffExtension(pi: ExtensionAPI) {
|
|
|
670
674
|
});
|
|
671
675
|
}
|
|
672
676
|
|
|
673
|
-
|
|
677
|
+
// Pi carries the active tool list across /reload, so names activated under a
|
|
678
|
+
// previously used mode stay active unless we drop them here (#855).
|
|
679
|
+
function registerPendingTools(staleNames: readonly string[]): void {
|
|
674
680
|
if (toolsRegistered) return;
|
|
675
681
|
|
|
676
|
-
const registeredNames = pendingTools.map((register) => register());
|
|
677
|
-
|
|
682
|
+
const registeredNames = new Set(pendingTools.map((register) => register()));
|
|
683
|
+
const stale = new Set(staleNames.filter((name) => !registeredNames.has(name)));
|
|
684
|
+
pi.setActiveTools([
|
|
685
|
+
...new Set([
|
|
686
|
+
...pi.getActiveTools().filter((name) => !stale.has(name)),
|
|
687
|
+
...registeredNames,
|
|
688
|
+
]),
|
|
689
|
+
]);
|
|
678
690
|
toolsRegistered = true;
|
|
679
691
|
}
|
|
680
692
|
|
|
@@ -734,24 +746,19 @@ export default function fffExtension(pi: ExtensionAPI) {
|
|
|
734
746
|
// Pi populates extension flag values after loading extensions.
|
|
735
747
|
resolveStartupConfig();
|
|
736
748
|
|
|
749
|
+
// FFF-named tools are ours alone, so they are always safe to drop. Override
|
|
750
|
+
// names collide with pi's builtins and are only stale once this session ran
|
|
751
|
+
// in override mode, which is the sole way we could have activated them.
|
|
752
|
+
const staleNames = toolNameList(FFF_TOOL_NAMES);
|
|
753
|
+
let usedOverride = currentMode === "override";
|
|
754
|
+
|
|
737
755
|
// Restore persisted mode before registering tools so a saved override
|
|
738
756
|
// can safely change their names after /reload or session resume.
|
|
739
|
-
const
|
|
740
|
-
if (
|
|
741
|
-
const
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
(e: { type: string; customType?: string }) =>
|
|
745
|
-
e.type === "custom" && e.customType === "fff-mode",
|
|
746
|
-
);
|
|
747
|
-
if (
|
|
748
|
-
modeEntry &&
|
|
749
|
-
typeof (modeEntry as any).data?.mode === "string" &&
|
|
750
|
-
VALID_MODES.includes((modeEntry as any).data.mode as FffMode)
|
|
751
|
-
) {
|
|
752
|
-
const restored = (modeEntry as any).data.mode as FffMode;
|
|
753
|
-
if (restored !== currentMode) setMode(restored);
|
|
754
|
-
}
|
|
757
|
+
const modes = sessionModes(ctx.sessionManager?.getEntries());
|
|
758
|
+
if (modes.length > 0) {
|
|
759
|
+
const restored = modes[modes.length - 1];
|
|
760
|
+
if (restored !== currentMode) setMode(restored);
|
|
761
|
+
usedOverride = usedOverride || modes.includes("override");
|
|
755
762
|
}
|
|
756
763
|
|
|
757
764
|
initializeFinderFactories();
|
|
@@ -759,10 +766,16 @@ export default function fffExtension(pi: ExtensionAPI) {
|
|
|
759
766
|
// `override` replaces pi's built-in grep/find. With the cwd opted out of
|
|
760
767
|
// indexing that would leave the session without any working workspace
|
|
761
768
|
// search, so keep the FFF names and let the built-ins stand (issue #857).
|
|
762
|
-
|
|
763
|
-
|
|
769
|
+
const keepBuiltins =
|
|
770
|
+
currentMode === "override" && scanOptOutReason(activeCwd) !== null;
|
|
771
|
+
if (keepBuiltins) toolNames = FFF_TOOL_NAMES;
|
|
772
|
+
|
|
773
|
+
// Pruning the override names here would deactivate the built-ins #857 just
|
|
774
|
+
// chose to keep, so only prune once FFF really takes those names over.
|
|
775
|
+
if (usedOverride && !keepBuiltins)
|
|
776
|
+
staleNames.push(...toolNameList(OVERRIDE_TOOL_NAMES));
|
|
764
777
|
|
|
765
|
-
registerPendingTools();
|
|
778
|
+
registerPendingTools(staleNames);
|
|
766
779
|
}
|
|
767
780
|
|
|
768
781
|
pi.on("session_start", async (_event, ctx) => {
|
|
@@ -1388,3 +1401,22 @@ export default function fffExtension(pi: ExtensionAPI) {
|
|
|
1388
1401
|
},
|
|
1389
1402
|
});
|
|
1390
1403
|
}
|
|
1404
|
+
|
|
1405
|
+
// Every mode this session selected via /fff-mode, oldest first.
|
|
1406
|
+
function sessionModes(entries: unknown): FffMode[] {
|
|
1407
|
+
if (!Array.isArray(entries)) return [];
|
|
1408
|
+
|
|
1409
|
+
const modes: FffMode[] = [];
|
|
1410
|
+
for (const entry of entries as {
|
|
1411
|
+
type?: string;
|
|
1412
|
+
customType?: string;
|
|
1413
|
+
data?: unknown;
|
|
1414
|
+
}[]) {
|
|
1415
|
+
if (entry?.type !== "custom" || entry.customType !== "fff-mode") continue;
|
|
1416
|
+
const mode = (entry.data as { mode?: unknown } | undefined)?.mode;
|
|
1417
|
+
if (typeof mode === "string" && VALID_MODES.includes(mode as FffMode)) {
|
|
1418
|
+
modes.push(mode as FffMode);
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
return modes;
|
|
1422
|
+
}
|