@ff-labs/pi-fff 0.10.5 → 0.10.6-nightly.2b89df8
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 +42 -5
- package/package.json +5 -4
- package/pi-fff.schema.json +46 -0
- package/src/config.ts +106 -0
- package/src/index.ts +265 -128
- package/src/paths.ts +1 -1
package/README.md
CHANGED
|
@@ -116,7 +116,7 @@ Parameters:
|
|
|
116
116
|
|
|
117
117
|
- `/fff-health` — show FFF status (indexed files, git info, frecency/history DB status)
|
|
118
118
|
- `/fff-rescan` — trigger a file rescan
|
|
119
|
-
- `/fff-mode <mode>` — switch mode (tool name
|
|
119
|
+
- `/fff-mode <mode>` — switch mode (tool name changes require `/reload`)
|
|
120
120
|
|
|
121
121
|
## Modes
|
|
122
122
|
|
|
@@ -124,10 +124,45 @@ Parameters:
|
|
|
124
124
|
- `tools-only`: additional tools only; keep pi's default `@` autocomplete
|
|
125
125
|
- `override`: replaces pi's built-in `find`, `grep` and adds `multi_grep` + FFF-backed `@` autocomplete
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
Startup mode precedence:
|
|
128
128
|
1. `--fff-mode <mode>` CLI flag
|
|
129
129
|
2. `PI_FFF_MODE=<mode>` environment variable
|
|
130
|
-
3.
|
|
130
|
+
3. `mode` in the global config file
|
|
131
|
+
4. default (`tools-and-ui`)
|
|
132
|
+
|
|
133
|
+
When a session resumes, its most recent `/fff-mode` selection takes precedence over the startup resolution above. Switching to or from `override` takes effect after `/reload`, when the tools are registered again.
|
|
134
|
+
|
|
135
|
+
## Configuration
|
|
136
|
+
|
|
137
|
+
For persistent global configuration, create `pi-fff.json` in pi's agent directory (`~/.pi/agent/pi-fff.json` by default; `PI_CODING_AGENT_DIR` is respected):
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"$schema": "https://raw.githubusercontent.com/dmtrKovalenko/fff/main/packages/pi-fff/pi-fff.schema.json",
|
|
142
|
+
"mode": "override",
|
|
143
|
+
"frecencyDbPath": "/path/to/frecency",
|
|
144
|
+
"historyDbPath": "/path/to/history",
|
|
145
|
+
"enableFsRootScanning": false,
|
|
146
|
+
"enableHomeDirScanning": true,
|
|
147
|
+
"warnOnHomeDirScan": true
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
All fields are optional:
|
|
152
|
+
|
|
153
|
+
| Field | Type | Default |
|
|
154
|
+
|---|---|---|
|
|
155
|
+
| `$schema` | non-empty string | none |
|
|
156
|
+
| `mode` | `tools-and-ui`, `tools-only`, or `override` | `tools-and-ui` |
|
|
157
|
+
| `frecencyDbPath` | non-empty string | See [Data](#data) |
|
|
158
|
+
| `historyDbPath` | non-empty string | See [Data](#data) |
|
|
159
|
+
| `enableFsRootScanning` | boolean | `false` |
|
|
160
|
+
| `enableHomeDirScanning` | boolean | `true` |
|
|
161
|
+
| `warnOnHomeDirScan` | boolean | `true` |
|
|
162
|
+
|
|
163
|
+
CLI flags take precedence over environment variables, which take precedence over this file. A missing file is ignored. Malformed JSON, unknown fields, and invalid values stop the extension from loading and report the file path and error. `/fff-mode` changes the current session; it does not edit this file.
|
|
164
|
+
|
|
165
|
+
The file is global only. Project-level config cannot safely control tool names because pi decides which tools an extension registers before project configuration can be trusted.
|
|
131
166
|
|
|
132
167
|
## Flags
|
|
133
168
|
|
|
@@ -136,6 +171,7 @@ Mode precedence:
|
|
|
136
171
|
- `--fff-history-db <path>` — path to query history database (also: `FFF_HISTORY_DB` env). Optional; see [Data](#data) for the default.
|
|
137
172
|
- `--fff-enable-root-scan` — allow indexing when launched from `/` (also: `FFF_ENABLE_ROOT_SCAN=1` env). FFF refuses to init at the filesystem root by default.
|
|
138
173
|
- `--fff-enable-home-scan` — index the home directory when launched from `$HOME` (also: `FFF_ENABLE_HOME_SCAN` env). Enabled by default. Disable with `--fff-enable-home-scan=false` or `FFF_ENABLE_HOME_SCAN=0` if your `$HOME` contains huge trees (toolchains, kernel sources, build outputs) that make the background index run for a long time. When launched from `$HOME` with this enabled, pi shows a warning that the whole home tree is being indexed.
|
|
174
|
+
- `--fff-warn-home-scan` — show the warning notification when `$HOME` is indexed (also: `FFF_WARN_HOME_SCAN` env). Enabled by default. Disable with `--fff-warn-home-scan=false`, `FFF_WARN_HOME_SCAN=0`, or `"warnOnHomeDirScan": false` in `pi-fff.json`. Indexing and the footer status are unaffected.
|
|
139
175
|
|
|
140
176
|
## Data
|
|
141
177
|
|
|
@@ -147,11 +183,12 @@ Each path is resolved independently, in this order:
|
|
|
147
183
|
|
|
148
184
|
1. CLI flag — `--fff-frecency-db` / `--fff-history-db`
|
|
149
185
|
2. Env var — `FFF_FRECENCY_DB` / `FFF_HISTORY_DB`
|
|
150
|
-
3.
|
|
186
|
+
3. Global config — `frecencyDbPath` / `historyDbPath`
|
|
187
|
+
4. An existing [fff.nvim](https://github.com/dmtrKovalenko/fff.nvim) database, so pi reuses the frecency you built up in your editor:
|
|
151
188
|
- frecency: `$XDG_CACHE_HOME/nvim/fff_nvim`
|
|
152
189
|
- history: `$XDG_DATA_HOME/nvim/fff_queries`
|
|
153
190
|
- `XDG_CACHE_HOME` defaults to `~/.cache` and `XDG_DATA_HOME` to `~/.local/share`; on Windows both fall back under `%LOCALAPPDATA%\nvim-data`. Only directories count — a plain file at those paths is ignored.
|
|
154
|
-
|
|
191
|
+
5. pi-local directory, created on demand — `$PI_CODING_AGENT_DIR/fff/{frecency,history}`, defaulting to `~/.pi/agent/fff/{frecency,history}`
|
|
155
192
|
|
|
156
193
|
The extension only reads these databases; it never records the agent's own searches into your Neovim history. If a database cannot be opened, the finder starts without persistence and pi shows a warning instead of failing.
|
|
157
194
|
|
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.
|
|
4
|
+
"version": "0.10.6-nightly.2b89df8",
|
|
5
5
|
"description": "pi extension: FFF-powered fuzzy file and content search",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
]
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
|
-
"src"
|
|
33
|
+
"src",
|
|
34
|
+
"pi-fff.schema.json"
|
|
34
35
|
],
|
|
35
36
|
"publishConfig": {
|
|
36
37
|
"access": "public"
|
|
@@ -40,8 +41,8 @@
|
|
|
40
41
|
"typecheck": "tsc --noEmit"
|
|
41
42
|
},
|
|
42
43
|
"dependencies": {
|
|
43
|
-
"@ff-labs/fff-bun": "0.10.
|
|
44
|
-
"@ff-labs/fff-node": "0.10.
|
|
44
|
+
"@ff-labs/fff-bun": "0.10.6-nightly.2b89df8",
|
|
45
|
+
"@ff-labs/fff-node": "0.10.6-nightly.2b89df8"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
48
|
"@earendil-works/pi-coding-agent": "*",
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://raw.githubusercontent.com/dmtrKovalenko/fff/main/packages/pi-fff/pi-fff.schema.json",
|
|
4
|
+
"title": "pi-fff configuration",
|
|
5
|
+
"description": "Global startup configuration for the pi-fff extension.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"properties": {
|
|
9
|
+
"$schema": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"minLength": 1,
|
|
12
|
+
"description": "Schema URL used by editors for validation and completion."
|
|
13
|
+
},
|
|
14
|
+
"mode": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"enum": ["tools-and-ui", "tools-only", "override"],
|
|
17
|
+
"default": "tools-and-ui",
|
|
18
|
+
"description": "Controls which FFF tools and autocomplete integrations are enabled."
|
|
19
|
+
},
|
|
20
|
+
"frecencyDbPath": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"minLength": 1,
|
|
23
|
+
"description": "Path to the frecency database."
|
|
24
|
+
},
|
|
25
|
+
"historyDbPath": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"minLength": 1,
|
|
28
|
+
"description": "Path to the query history database."
|
|
29
|
+
},
|
|
30
|
+
"enableFsRootScanning": {
|
|
31
|
+
"type": "boolean",
|
|
32
|
+
"default": false,
|
|
33
|
+
"description": "Allows indexing when pi is launched from the filesystem root."
|
|
34
|
+
},
|
|
35
|
+
"enableHomeDirScanning": {
|
|
36
|
+
"type": "boolean",
|
|
37
|
+
"default": true,
|
|
38
|
+
"description": "Allows indexing when pi is launched from the home directory."
|
|
39
|
+
},
|
|
40
|
+
"warnOnHomeDirScan": {
|
|
41
|
+
"type": "boolean",
|
|
42
|
+
"default": true,
|
|
43
|
+
"description": "Shows a warning notification when the home directory is indexed."
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { piDataDir } from "./paths";
|
|
4
|
+
|
|
5
|
+
export const CONFIG_FILE_NAME = "pi-fff.json";
|
|
6
|
+
export const VALID_MODES = ["tools-and-ui", "tools-only", "override"] as const;
|
|
7
|
+
|
|
8
|
+
export type FffMode = (typeof VALID_MODES)[number];
|
|
9
|
+
|
|
10
|
+
export interface FffConfig {
|
|
11
|
+
$schema?: string;
|
|
12
|
+
mode?: FffMode;
|
|
13
|
+
frecencyDbPath?: string;
|
|
14
|
+
historyDbPath?: string;
|
|
15
|
+
enableFsRootScanning?: boolean;
|
|
16
|
+
enableHomeDirScanning?: boolean;
|
|
17
|
+
warnOnHomeDirScan?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const CONFIG_KEYS = new Set<keyof FffConfig>([
|
|
21
|
+
"$schema",
|
|
22
|
+
"mode",
|
|
23
|
+
"frecencyDbPath",
|
|
24
|
+
"historyDbPath",
|
|
25
|
+
"enableFsRootScanning",
|
|
26
|
+
"enableHomeDirScanning",
|
|
27
|
+
"warnOnHomeDirScan",
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
export function loadConfig(agentDir = piDataDir()): FffConfig {
|
|
31
|
+
const configPath = join(agentDir, CONFIG_FILE_NAME);
|
|
32
|
+
let contents: string;
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
contents = readFileSync(configPath, "utf8");
|
|
36
|
+
} catch (error: unknown) {
|
|
37
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return {};
|
|
38
|
+
throw new Error(
|
|
39
|
+
`Could not read pi-fff config at ${configPath}: ${errorMessage(error)}`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let parsed: unknown;
|
|
44
|
+
try {
|
|
45
|
+
parsed = JSON.parse(contents);
|
|
46
|
+
} catch (error: unknown) {
|
|
47
|
+
throw invalidConfig(configPath, `not valid JSON (${errorMessage(error)})`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!isRecord(parsed)) {
|
|
51
|
+
throw invalidConfig(configPath, "expected a JSON object");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
for (const key of Object.keys(parsed)) {
|
|
55
|
+
if (!CONFIG_KEYS.has(key as keyof FffConfig)) {
|
|
56
|
+
throw invalidConfig(configPath, `unknown option "${key}"`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (parsed.mode !== undefined && !VALID_MODES.includes(parsed.mode as FffMode)) {
|
|
61
|
+
throw invalidConfig(configPath, `"mode" must be one of ${VALID_MODES.join(", ")}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
validateString(configPath, parsed, "$schema");
|
|
65
|
+
validateString(configPath, parsed, "frecencyDbPath");
|
|
66
|
+
validateString(configPath, parsed, "historyDbPath");
|
|
67
|
+
validateBoolean(configPath, parsed, "enableFsRootScanning");
|
|
68
|
+
validateBoolean(configPath, parsed, "enableHomeDirScanning");
|
|
69
|
+
validateBoolean(configPath, parsed, "warnOnHomeDirScan");
|
|
70
|
+
|
|
71
|
+
return parsed as FffConfig;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function invalidConfig(configPath: string, reason: string): Error {
|
|
75
|
+
return new Error(`Invalid pi-fff config at ${configPath}: ${reason}`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function errorMessage(error: unknown): string {
|
|
79
|
+
return error instanceof Error ? error.message : String(error);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
83
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function validateString(
|
|
87
|
+
configPath: string,
|
|
88
|
+
config: Record<string, unknown>,
|
|
89
|
+
key: "$schema" | "frecencyDbPath" | "historyDbPath",
|
|
90
|
+
): void {
|
|
91
|
+
const value = config[key];
|
|
92
|
+
if (value !== undefined && (typeof value !== "string" || value.length === 0)) {
|
|
93
|
+
throw invalidConfig(configPath, `"${key}" must be a non-empty string`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function validateBoolean(
|
|
98
|
+
configPath: string,
|
|
99
|
+
config: Record<string, unknown>,
|
|
100
|
+
key: "enableFsRootScanning" | "enableHomeDirScanning" | "warnOnHomeDirScan",
|
|
101
|
+
): void {
|
|
102
|
+
const value = config[key];
|
|
103
|
+
if (value !== undefined && typeof value !== "boolean") {
|
|
104
|
+
throw invalidConfig(configPath, `"${key}" must be a boolean`);
|
|
105
|
+
}
|
|
106
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import nodePath from "node:path";
|
|
9
|
-
import type {
|
|
9
|
+
import type {
|
|
10
|
+
ExtensionAPI,
|
|
11
|
+
ExtensionContext,
|
|
12
|
+
ToolDefinition,
|
|
13
|
+
} from "@earendil-works/pi-coding-agent";
|
|
10
14
|
import {
|
|
11
15
|
type AutocompleteItem,
|
|
12
16
|
type AutocompleteProvider,
|
|
@@ -20,8 +24,9 @@ import type {
|
|
|
20
24
|
MixedItem,
|
|
21
25
|
SearchResult,
|
|
22
26
|
} from "@ff-labs/fff-node";
|
|
23
|
-
import { Type } from "@sinclair/typebox";
|
|
27
|
+
import { Type, type TSchema } from "@sinclair/typebox";
|
|
24
28
|
import { AuxFinderPool, routePathConstraint } from "./aux-finders";
|
|
29
|
+
import { type FffMode, loadConfig, VALID_MODES } from "./config";
|
|
25
30
|
import { FilePickerFactory } from "./file-picker";
|
|
26
31
|
import { isHomeDir, resolveDbPaths } from "./paths";
|
|
27
32
|
import { buildQuery } from "./query";
|
|
@@ -45,11 +50,8 @@ const GREP_TIME_BUDGET_MS = 10_000;
|
|
|
45
50
|
const HOME_SCAN_STATUS_KEY = "fff";
|
|
46
51
|
const HOME_SCAN_POLL_MS = 1_000;
|
|
47
52
|
const HOME_SCAN_DISABLE_HINT =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
type FffMode = "tools-and-ui" | "tools-only" | "override";
|
|
51
|
-
|
|
52
|
-
const VALID_MODES: FffMode[] = ["tools-and-ui", "tools-only", "override"];
|
|
53
|
+
'You can prevent home dir indexing with --fff-enable-home-scan=false, FFF_ENABLE_HOME_SCAN=0, or "enableHomeDirScanning": false in pi-fff.json. ' +
|
|
54
|
+
'To keep indexing but silence this warning use --fff-warn-home-scan=false, FFF_WARN_HOME_SCAN=0, or "warnOnHomeDirScan": false in pi-fff.json.';
|
|
53
55
|
|
|
54
56
|
interface ToolNames {
|
|
55
57
|
grep: string;
|
|
@@ -299,52 +301,103 @@ export default function fffExtension(pi: ExtensionAPI) {
|
|
|
299
301
|
let finderPromise: Promise<FileFinderApi> | null = null;
|
|
300
302
|
let activeCwd = process.cwd();
|
|
301
303
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
});
|
|
304
|
+
const config = loadConfig();
|
|
305
|
+
|
|
306
|
+
// All startup options use the same flag > env > file > fallback order.
|
|
307
|
+
function getConfigValue<T>(
|
|
308
|
+
flagName: string,
|
|
309
|
+
envName: string,
|
|
310
|
+
fileValue: T | undefined,
|
|
311
|
+
fallback: T,
|
|
312
|
+
parse: (value: unknown) => T | undefined = (value) => value as T,
|
|
313
|
+
): T {
|
|
314
|
+
const flagValue = pi.getFlag(flagName);
|
|
315
|
+
if (flagValue !== undefined) {
|
|
316
|
+
const value = parse(flagValue);
|
|
317
|
+
if (value !== undefined) return value;
|
|
318
|
+
}
|
|
318
319
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
if (env === "0" || env === "false") return false;
|
|
327
|
-
return fallback;
|
|
320
|
+
const envValue = process.env[envName];
|
|
321
|
+
if (envValue !== undefined) {
|
|
322
|
+
const value = parse(envValue);
|
|
323
|
+
if (value !== undefined) return value;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return fileValue ?? fallback;
|
|
328
327
|
}
|
|
329
|
-
// Root scanning opt-in: FFF refuses to init at / unless this is set.
|
|
330
|
-
const enableFsRootScanning = resolveBoolOpt(
|
|
331
|
-
"fff-enable-root-scan",
|
|
332
|
-
"FFF_ENABLE_ROOT_SCAN",
|
|
333
|
-
);
|
|
334
|
-
// Home dir scanning is on by default (launching pi from $HOME is a normal
|
|
335
|
-
// flow), but configurable so users with huge $HOME trees can opt out.
|
|
336
|
-
const enableHomeDirScanning = resolveBoolOpt(
|
|
337
|
-
"fff-enable-home-scan",
|
|
338
|
-
"FFF_ENABLE_HOME_SCAN",
|
|
339
|
-
true,
|
|
340
|
-
);
|
|
341
328
|
|
|
342
|
-
function
|
|
343
|
-
return
|
|
329
|
+
function parseBoolean(value: unknown): boolean | undefined {
|
|
330
|
+
if (typeof value === "boolean") return value;
|
|
331
|
+
if (value === "1" || value === "true") return true;
|
|
332
|
+
if (value === "0" || value === "false") return false;
|
|
333
|
+
return undefined;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function parseMode(value: unknown): FffMode | undefined {
|
|
337
|
+
return typeof value === "string" && VALID_MODES.includes(value as FffMode)
|
|
338
|
+
? (value as FffMode)
|
|
339
|
+
: undefined;
|
|
344
340
|
}
|
|
345
341
|
|
|
342
|
+
let currentMode: FffMode = "tools-and-ui";
|
|
343
|
+
let toolNames = resolveToolNames(currentMode);
|
|
344
|
+
let resolvedDbPaths: ReturnType<typeof resolveDbPaths>;
|
|
345
|
+
let enableFsRootScanning = false;
|
|
346
|
+
let enableHomeDirScanning = true;
|
|
347
|
+
let warnOnHomeDirScan = true;
|
|
348
|
+
|
|
346
349
|
function setMode(mode: FffMode): void {
|
|
347
350
|
currentMode = mode;
|
|
351
|
+
toolNames = resolveToolNames(mode);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function resolveStartupConfig(): void {
|
|
355
|
+
setMode(
|
|
356
|
+
getConfigValue("fff-mode", "PI_FFF_MODE", config.mode, "tools-and-ui", parseMode),
|
|
357
|
+
);
|
|
358
|
+
resolvedDbPaths = resolveDbPaths({
|
|
359
|
+
frecency: getConfigValue(
|
|
360
|
+
"fff-frecency-db",
|
|
361
|
+
"FFF_FRECENCY_DB",
|
|
362
|
+
config.frecencyDbPath,
|
|
363
|
+
undefined,
|
|
364
|
+
),
|
|
365
|
+
history: getConfigValue(
|
|
366
|
+
"fff-history-db",
|
|
367
|
+
"FFF_HISTORY_DB",
|
|
368
|
+
config.historyDbPath,
|
|
369
|
+
undefined,
|
|
370
|
+
),
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
// Root scanning opt-in: FFF refuses to init at / unless this is set.
|
|
374
|
+
enableFsRootScanning = getConfigValue(
|
|
375
|
+
"fff-enable-root-scan",
|
|
376
|
+
"FFF_ENABLE_ROOT_SCAN",
|
|
377
|
+
config.enableFsRootScanning,
|
|
378
|
+
false,
|
|
379
|
+
parseBoolean,
|
|
380
|
+
);
|
|
381
|
+
// Home dir scanning is on by default (launching pi from $HOME is a normal
|
|
382
|
+
// flow), but configurable so users with huge $HOME trees can opt out.
|
|
383
|
+
enableHomeDirScanning = getConfigValue(
|
|
384
|
+
"fff-enable-home-scan",
|
|
385
|
+
"FFF_ENABLE_HOME_SCAN",
|
|
386
|
+
config.enableHomeDirScanning,
|
|
387
|
+
true,
|
|
388
|
+
parseBoolean,
|
|
389
|
+
);
|
|
390
|
+
warnOnHomeDirScan = getConfigValue(
|
|
391
|
+
"fff-warn-home-scan",
|
|
392
|
+
"FFF_WARN_HOME_SCAN",
|
|
393
|
+
config.warnOnHomeDirScan,
|
|
394
|
+
true,
|
|
395
|
+
parseBoolean,
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function getMode(): FffMode {
|
|
400
|
+
return currentMode;
|
|
348
401
|
}
|
|
349
402
|
|
|
350
403
|
function shouldEnableMentions(): boolean {
|
|
@@ -362,28 +415,35 @@ export default function fffExtension(pi: ExtensionAPI) {
|
|
|
362
415
|
let homeScanTimer: ReturnType<typeof setInterval> | null = null;
|
|
363
416
|
|
|
364
417
|
function warnHomeDirScan(root: string): void {
|
|
418
|
+
if (!warnOnHomeDirScan) return;
|
|
365
419
|
uiCtx?.ui.notify(
|
|
366
420
|
`(fff): Your cwd (${root}) is too large. Indexing will take additional time and resources.\n${HOME_SCAN_DISABLE_HINT}`,
|
|
367
421
|
"warning",
|
|
368
422
|
);
|
|
369
423
|
}
|
|
370
424
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
historyDbPath: resolvedDbPaths.history,
|
|
374
|
-
onDbFailure: (error) =>
|
|
375
|
-
uiCtx?.ui.notify(
|
|
376
|
-
`(fff): Failed to open frecency/history database (${error}). Continuing without frecency persistence.`,
|
|
377
|
-
"error",
|
|
378
|
-
),
|
|
379
|
-
});
|
|
425
|
+
let pickers: FilePickerFactory | null = null;
|
|
426
|
+
let auxPool: AuxFinderPool | null = null;
|
|
380
427
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
428
|
+
function initializeFinderFactories(): void {
|
|
429
|
+
if (pickers) return;
|
|
430
|
+
|
|
431
|
+
pickers = new FilePickerFactory({
|
|
432
|
+
frecencyDbPath: resolvedDbPaths.frecency,
|
|
433
|
+
historyDbPath: resolvedDbPaths.history,
|
|
434
|
+
onDbFailure: (error) =>
|
|
435
|
+
uiCtx?.ui.notify(
|
|
436
|
+
`(fff): Failed to open frecency/history database (${error}). Continuing without frecency persistence.`,
|
|
437
|
+
"error",
|
|
438
|
+
),
|
|
439
|
+
});
|
|
440
|
+
auxPool = new AuxFinderPool({
|
|
441
|
+
enableFsRootScanning,
|
|
442
|
+
enableHomeDirScanning,
|
|
443
|
+
onHomeDirScan: warnHomeDirScan,
|
|
444
|
+
pickers,
|
|
445
|
+
});
|
|
446
|
+
}
|
|
387
447
|
|
|
388
448
|
// in case cwd changes we need to figure this out
|
|
389
449
|
function ensureFinder(cwd: string): Promise<FileFinderApi> {
|
|
@@ -401,6 +461,7 @@ export default function fffExtension(pi: ExtensionAPI) {
|
|
|
401
461
|
|
|
402
462
|
// if the dbs can't be opened the factory falls back to a db-less picker,
|
|
403
463
|
// e.g. when some other process corrupts the lock
|
|
464
|
+
if (!pickers) throw new Error("FFF picker factory is not initialized");
|
|
404
465
|
mainFinder = await pickers.create({
|
|
405
466
|
basePath: cwd,
|
|
406
467
|
enableHomeDirScanning,
|
|
@@ -455,9 +516,9 @@ export default function fffExtension(pi: ExtensionAPI) {
|
|
|
455
516
|
finderCwd = null;
|
|
456
517
|
}
|
|
457
518
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
519
|
+
auxPool?.destroy();
|
|
520
|
+
auxPool = null;
|
|
521
|
+
pickers = null;
|
|
461
522
|
}
|
|
462
523
|
|
|
463
524
|
async function resolveFinderForPath(
|
|
@@ -467,6 +528,7 @@ export default function fffExtension(pi: ExtensionAPI) {
|
|
|
467
528
|
): Promise<{ finder: FileFinderApi; query: string; root: string } | null> {
|
|
468
529
|
const route = routePathConstraint(pathParam, activeCwd);
|
|
469
530
|
if (!route) return null;
|
|
531
|
+
if (!auxPool) throw new Error("FFF auxiliary finder pool is not initialized");
|
|
470
532
|
const aux = await auxPool.acquire(route.root);
|
|
471
533
|
// A broader covering picker may have been reused; rebase the suffix so the
|
|
472
534
|
// constraint stays relative to the picker's actual root.
|
|
@@ -547,6 +609,45 @@ export default function fffExtension(pi: ExtensionAPI) {
|
|
|
547
609
|
});
|
|
548
610
|
}
|
|
549
611
|
|
|
612
|
+
type PendingToolDefinition<
|
|
613
|
+
TParams extends TSchema,
|
|
614
|
+
TDetails = unknown,
|
|
615
|
+
TState = any,
|
|
616
|
+
> = Omit<
|
|
617
|
+
ToolDefinition<TParams, TDetails, TState>,
|
|
618
|
+
"name" | "label" | "promptGuidelines"
|
|
619
|
+
> & {
|
|
620
|
+
promptGuidelines?: (names: ToolNames) => string[];
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
const pendingTools: (() => string)[] = [];
|
|
624
|
+
let toolsRegistered = false;
|
|
625
|
+
|
|
626
|
+
function queueTool<TParams extends TSchema, TDetails = unknown, TState = any>(
|
|
627
|
+
resolveName: () => string,
|
|
628
|
+
definition: PendingToolDefinition<TParams, TDetails, TState>,
|
|
629
|
+
): void {
|
|
630
|
+
pendingTools.push(() => {
|
|
631
|
+
const { promptGuidelines, ...tool } = definition;
|
|
632
|
+
const resolvedName = resolveName();
|
|
633
|
+
pi.registerTool({
|
|
634
|
+
...tool,
|
|
635
|
+
name: resolvedName,
|
|
636
|
+
label: resolvedName,
|
|
637
|
+
promptGuidelines: promptGuidelines?.(toolNames),
|
|
638
|
+
});
|
|
639
|
+
return resolvedName;
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
function registerPendingTools(): void {
|
|
644
|
+
if (toolsRegistered) return;
|
|
645
|
+
|
|
646
|
+
const registeredNames = pendingTools.map((register) => register());
|
|
647
|
+
pi.setActiveTools([...new Set([...pi.getActiveTools(), ...registeredNames])]);
|
|
648
|
+
toolsRegistered = true;
|
|
649
|
+
}
|
|
650
|
+
|
|
550
651
|
// --- Flags / lifecycle ---
|
|
551
652
|
|
|
552
653
|
pi.registerFlag("fff-mode", {
|
|
@@ -576,34 +677,54 @@ export default function fffExtension(pi: ExtensionAPI) {
|
|
|
576
677
|
type: "boolean",
|
|
577
678
|
});
|
|
578
679
|
|
|
579
|
-
pi.
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
680
|
+
pi.registerFlag("fff-warn-home-scan", {
|
|
681
|
+
description:
|
|
682
|
+
"Warn when indexing $HOME (default true; silence with --fff-warn-home-scan=false or FFF_WARN_HOME_SCAN=0)",
|
|
683
|
+
type: "boolean",
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
function reportInitFailure(ctx: ExtensionContext, error: unknown): void {
|
|
687
|
+
ctx.ui.notify(
|
|
688
|
+
`FFF init failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
689
|
+
"error",
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
function prepareSession(ctx: ExtensionContext): void {
|
|
694
|
+
activeCwd = ctx.cwd;
|
|
695
|
+
uiCtx = ctx;
|
|
696
|
+
if (toolsRegistered) return;
|
|
697
|
+
|
|
698
|
+
// Pi populates extension flag values after loading extensions.
|
|
699
|
+
resolveStartupConfig();
|
|
700
|
+
|
|
701
|
+
// Restore persisted mode before registering tools so a saved override
|
|
702
|
+
// can safely change their names after /reload or session resume.
|
|
703
|
+
const entries = ctx.sessionManager?.getEntries();
|
|
704
|
+
if (entries) {
|
|
705
|
+
const modeEntry = [...entries]
|
|
706
|
+
.reverse()
|
|
707
|
+
.find(
|
|
708
|
+
(e: { type: string; customType?: string }) =>
|
|
709
|
+
e.type === "custom" && e.customType === "fff-mode",
|
|
710
|
+
);
|
|
711
|
+
if (
|
|
712
|
+
modeEntry &&
|
|
713
|
+
typeof (modeEntry as any).data?.mode === "string" &&
|
|
714
|
+
VALID_MODES.includes((modeEntry as any).data.mode as FffMode)
|
|
715
|
+
) {
|
|
716
|
+
const restored = (modeEntry as any).data.mode as FffMode;
|
|
717
|
+
if (restored !== currentMode) setMode(restored);
|
|
605
718
|
}
|
|
719
|
+
}
|
|
606
720
|
|
|
721
|
+
initializeFinderFactories();
|
|
722
|
+
registerPendingTools();
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
726
|
+
try {
|
|
727
|
+
prepareSession(ctx);
|
|
607
728
|
registerAutocompleteProvider(ctx);
|
|
608
729
|
await ensureFinder(activeCwd);
|
|
609
730
|
|
|
@@ -621,11 +742,19 @@ export default function fffExtension(pi: ExtensionAPI) {
|
|
|
621
742
|
// waitForScan() also resolves on timeout, so poll until the scan really
|
|
622
743
|
// settles before clearing the footer.
|
|
623
744
|
if (atHome) trackHomeScanStatus();
|
|
624
|
-
} catch (
|
|
625
|
-
ctx
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
745
|
+
} catch (error: unknown) {
|
|
746
|
+
reportInitFailure(ctx, error);
|
|
747
|
+
}
|
|
748
|
+
});
|
|
749
|
+
|
|
750
|
+
// SDK callers can prompt without binding session_start. Prepare on the first
|
|
751
|
+
// agent turn as a fallback so the tools still reach that turn's tool set.
|
|
752
|
+
pi.on("before_agent_start", (_event, ctx) => {
|
|
753
|
+
if (toolsRegistered) return;
|
|
754
|
+
try {
|
|
755
|
+
prepareSession(ctx);
|
|
756
|
+
} catch (error: unknown) {
|
|
757
|
+
reportInitFailure(ctx, error);
|
|
629
758
|
}
|
|
630
759
|
});
|
|
631
760
|
|
|
@@ -701,16 +830,14 @@ export default function fffExtension(pi: ExtensionAPI) {
|
|
|
701
830
|
),
|
|
702
831
|
});
|
|
703
832
|
|
|
704
|
-
|
|
705
|
-
name: toolNames.grep,
|
|
706
|
-
label: toolNames.grep,
|
|
833
|
+
queueTool(() => toolNames.grep, {
|
|
707
834
|
description: `Grep file contents. Smart-case, auto-detects regex vs literal, git-aware. Results are ranked by frecency (most-accessed files first); matches within a file stay in source order. Default limit ${DEFAULT_GREP_LIMIT}.`,
|
|
708
835
|
promptSnippet: "Grep contents",
|
|
709
|
-
promptGuidelines: [
|
|
710
|
-
`${
|
|
711
|
-
`${
|
|
712
|
-
`${
|
|
713
|
-
`${
|
|
836
|
+
promptGuidelines: (names) => [
|
|
837
|
+
`${names.grep}: prefer bare identifiers as patterns. Literal queries are most efficient.`,
|
|
838
|
+
`${names.grep}: use path for include ('src/', '*.ts') and exclude for noise ('test/,*.min.js').`,
|
|
839
|
+
`${names.grep}: caseSensitive: true when you need exact case (smart-case otherwise).`,
|
|
840
|
+
`${names.grep}: after 1-2 greps, read the top match instead of more greps.`,
|
|
714
841
|
],
|
|
715
842
|
parameters: grepSchema,
|
|
716
843
|
|
|
@@ -892,18 +1019,16 @@ export default function fffExtension(pi: ExtensionAPI) {
|
|
|
892
1019
|
),
|
|
893
1020
|
});
|
|
894
1021
|
|
|
895
|
-
|
|
896
|
-
name: toolNames.find,
|
|
897
|
-
label: toolNames.find,
|
|
1022
|
+
queueTool(() => toolNames.find, {
|
|
898
1023
|
description: `Fuzzy path search and glob search. Matches against the whole repo-relative path, not just the filename. Frecency-ranked, git-aware. Multi-word = narrower (AND). Default limit ${DEFAULT_FIND_LIMIT}.`,
|
|
899
1024
|
promptSnippet: "Find files by path or glob",
|
|
900
|
-
promptGuidelines: [
|
|
901
|
-
`${
|
|
902
|
-
`${
|
|
903
|
-
`${
|
|
904
|
-
`${
|
|
905
|
-
`${
|
|
906
|
-
`${
|
|
1025
|
+
promptGuidelines: (names) => [
|
|
1026
|
+
`${names.find}: matches the WHOLE path, not just the filename — \`profile\` hits \`chrome/browser/profiles/x.cc\` too.`,
|
|
1027
|
+
`${names.find}: keep queries to 1-2 terms; extra words narrow.`,
|
|
1028
|
+
`${names.find}: use for paths, not content. Use ${names.grep} for content.`,
|
|
1029
|
+
`${names.find}: for exact path matches use a glob in \`path\` — e.g. path: '**/profile.h' for exact filename, or path: 'src/**/profile.h' scoped to a subtree. Bare patterns are fuzzy.`,
|
|
1030
|
+
`${names.find}: to list everything inside a directory, pass path: 'dir/**' with an empty or wildcard pattern instead of using pattern alone.`,
|
|
1031
|
+
`${names.find}: use exclude: 'test/,*.min.js' to cut noise in large repos.`,
|
|
907
1032
|
],
|
|
908
1033
|
parameters: findSchema,
|
|
909
1034
|
|
|
@@ -912,10 +1037,12 @@ export default function fffExtension(pi: ExtensionAPI) {
|
|
|
912
1037
|
|
|
913
1038
|
// if resumed we use the same picker as before
|
|
914
1039
|
const resumed = params.cursor ? getFindCursor(params.cursor) : undefined;
|
|
1040
|
+
const pool = auxPool;
|
|
1041
|
+
if (!pool) throw new Error("FFF auxiliary finder pool is not initialized");
|
|
915
1042
|
const aux = resumed
|
|
916
1043
|
? resumed.auxRoot
|
|
917
1044
|
? {
|
|
918
|
-
finder: (await
|
|
1045
|
+
finder: (await pool.acquire(resumed.auxRoot, { exact: true })).finder,
|
|
919
1046
|
root: resumed.auxRoot,
|
|
920
1047
|
}
|
|
921
1048
|
: null
|
|
@@ -1032,16 +1159,14 @@ export default function fffExtension(pi: ExtensionAPI) {
|
|
|
1032
1159
|
cursor: Type.Optional(Type.String({ description: "Pagination cursor" })),
|
|
1033
1160
|
});
|
|
1034
1161
|
|
|
1035
|
-
|
|
1036
|
-
name: toolNames.multiGrep,
|
|
1037
|
-
label: toolNames.multiGrep,
|
|
1162
|
+
queueTool(() => toolNames.multiGrep, {
|
|
1038
1163
|
description:
|
|
1039
1164
|
"Search file contents for ANY of multiple literal patterns (OR, SIMD Aho-Corasick). Faster than regex alternation.",
|
|
1040
1165
|
promptSnippet: "Multi-pattern OR content search",
|
|
1041
|
-
promptGuidelines: [
|
|
1042
|
-
`${
|
|
1043
|
-
`${
|
|
1044
|
-
`${
|
|
1166
|
+
promptGuidelines: (names) => [
|
|
1167
|
+
`${names.multiGrep}: use when searching for several identifiers at once.`,
|
|
1168
|
+
`${names.multiGrep}: include all naming-convention variants (snake/camel/Pascal).`,
|
|
1169
|
+
`${names.multiGrep}: patterns are literal. Use constraints for file filters.`,
|
|
1045
1170
|
],
|
|
1046
1171
|
parameters: multiGrepSchema,
|
|
1047
1172
|
|
|
@@ -1116,6 +1241,15 @@ export default function fffExtension(pi: ExtensionAPI) {
|
|
|
1116
1241
|
pi.registerCommand("fff-mode", {
|
|
1117
1242
|
description: "Show or set FFF mode: /fff-mode [tools-and-ui | tools-only | override]",
|
|
1118
1243
|
handler: async (args, ctx) => {
|
|
1244
|
+
if (!toolsRegistered) {
|
|
1245
|
+
try {
|
|
1246
|
+
prepareSession(ctx);
|
|
1247
|
+
} catch (error: unknown) {
|
|
1248
|
+
reportInitFailure(ctx, error);
|
|
1249
|
+
return;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1119
1253
|
const arg = (args || "").trim();
|
|
1120
1254
|
|
|
1121
1255
|
// No args - show current mode
|
|
@@ -1134,15 +1268,18 @@ export default function fffExtension(pi: ExtensionAPI) {
|
|
|
1134
1268
|
|
|
1135
1269
|
const newMode = arg as FffMode;
|
|
1136
1270
|
const oldMode = getMode();
|
|
1137
|
-
setMode(newMode);
|
|
1138
|
-
|
|
1139
1271
|
pi.appendEntry("fff-mode", { mode: newMode });
|
|
1140
1272
|
|
|
1141
|
-
|
|
1142
|
-
(
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1273
|
+
if ((oldMode === "override") !== (newMode === "override")) {
|
|
1274
|
+
ctx.ui.notify(
|
|
1275
|
+
`Mode '${newMode}' saved. Run /reload to apply the tool name change.`,
|
|
1276
|
+
"info",
|
|
1277
|
+
);
|
|
1278
|
+
return;
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
setMode(newMode);
|
|
1282
|
+
ctx.ui.notify(`Mode changed: '${oldMode}' → '${newMode}'`, "info");
|
|
1146
1283
|
},
|
|
1147
1284
|
});
|
|
1148
1285
|
|
package/src/paths.ts
CHANGED
|
@@ -52,7 +52,7 @@ function nvimDataDir(): string {
|
|
|
52
52
|
return path.join(HOME_DIR, ".local", "share", "nvim");
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
function piDataDir(): string {
|
|
55
|
+
export function piDataDir(): string {
|
|
56
56
|
return process.env.PI_CODING_AGENT_DIR ?? path.join(HOME_DIR, ".pi", "agent");
|
|
57
57
|
}
|
|
58
58
|
|