@evandu/super-pi 0.1.237 → 0.1.238

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.
@@ -8,9 +8,9 @@
8
8
  <link rel="alternate icon" href="/favicon.ico" />
9
9
  <link rel="apple-touch-icon" href="/favicon.svg" />
10
10
  <title>Super Pi</title>
11
- <script type="module" crossorigin src="/assets/index-Bolukoov.js"></script>
11
+ <script type="module" crossorigin src="/assets/index-D9r0K1_Y.js"></script>
12
12
  <link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-XKyaHtl9.js">
13
- <link rel="stylesheet" crossorigin href="/assets/index-BWLRPUnY.css">
13
+ <link rel="stylesheet" crossorigin href="/assets/index-sDaqj666.css">
14
14
  </head>
15
15
  <body>
16
16
  <div id="root"></div>
@@ -28,7 +28,7 @@ export type IndexProgress = {
28
28
  /** The answer to one question: which paths contain this needle. */
29
29
  export type NameSearchResult = {
30
30
  hits: NameEntry[];
31
- /** The exact number of matches. Equal to `hits.length` when nothing was withheld. */
31
+ /** Total matches before the result page is applied. */
32
32
  total: number;
33
33
  /** Whether the index has finished its first pass. `false` means "more may still arrive". */
34
34
  indexed: boolean;
@@ -36,6 +36,7 @@ export type NameSearchResult = {
36
36
  /** Set when the scan hit a limit. Its presence is the reason the answer is not the whole tree. */
37
37
  incomplete: boolean;
38
38
  };
39
+ export declare const QUICK_OPEN_PAGE_SIZE = 60;
39
40
  /**
40
41
  * The result ordering, and why it is not the path dictionary order.
41
42
  *
@@ -43,10 +44,10 @@ export type NameSearchResult = {
43
44
  * a whole string. In a list of two hundred that is actively hostile: the file whose name STARTS
44
45
  * with what you typed is the one you meant, and it is somewhere in the middle. So the order is:
45
46
  *
46
- * 1. the hit position inside the file name - a name that starts with the needle beats one that
47
- * merely contains it, whatever the directory;
48
- * 2. shallower directories first - `notes.md` beats `src/deep/nested/notes.md`;
49
- * 3. the path dictionary order, as the final tie-break, so the order is stable.
47
+ * 1. exact filenames;
48
+ * 2. the hit position inside the file name, so prefixes rank ahead of other substrings;
49
+ * 3. shallower directories first;
50
+ * 4. path order as the final tie-break.
50
51
  */
51
52
  export declare function compareNameHits(a: NameEntry, b: NameEntry, needle: string): number;
52
53
  /**
@@ -74,6 +75,8 @@ export declare class FileNameIndex {
74
75
  private incomplete;
75
76
  private needsScan;
76
77
  private generation;
78
+ private unread;
79
+ private hasScanned;
77
80
  private readonly removedDuringScan;
78
81
  private readonly directoriesReadDuringScan;
79
82
  constructor(workspaceId: string, cwd?: string);
@@ -88,9 +91,12 @@ export declare class FileNameIndex {
88
91
  * A scan that FAILED has not finished either - it never will be, and `failure` says why.
89
92
  */
90
93
  get indexed(): boolean;
94
+ get hasSnapshot(): boolean;
91
95
  get progress(): IndexProgress;
92
96
  /** Begin the background scan. Safe to call more than once; the second call is a no-op. */
93
97
  start(root: string): void;
98
+ /** Keep the preceding results usable while checking files written outside Super Pi. */
99
+ revalidate(root: string): void;
94
100
  markStale(): void;
95
101
  /**
96
102
  * WHY THE SCAN'S FAILURE IS RECORDED RATHER THAN THROWN.
@@ -109,8 +115,6 @@ export declare class FileNameIndex {
109
115
  get broken(): unknown;
110
116
  /** Rethrow the scan's failure, so the route can turn it into the status it deserves. */
111
117
  throwIfBroken(): void;
112
- /** Rebuild from scratch. The ↻ button. */
113
- reset(root: string): void;
114
118
  /** Record a path that appeared or changed. Used for agent writes and user saves. */
115
119
  upsert(relativePath: string, kind?: "file" | "directory", openLink?: true): void;
116
120
  /** Forget a path that is gone. */
@@ -125,6 +129,7 @@ export declare class FileNameIndex {
125
129
  * `app` return every file in `application/` as well - a result set nobody can read.
126
130
  */
127
131
  search(needle: string, linksOnly?: boolean): NameSearchResult;
132
+ searchQuickOpen(query: string, offset: number): NameSearchResult;
128
133
  /**
129
134
  * Wait until the first scan has finished, or until the deadline passes.
130
135
  *
@@ -33,7 +33,8 @@
33
33
  */
34
34
  import { readdir, stat } from "node:fs/promises";
35
35
  import { resolve } from "node:path";
36
- import { matchPathMentions } from "../shared/file-mentions.js";
36
+ import Fuse from "fuse.js";
37
+ import { matchPathMentions, rankPathMatches } from "../shared/file-mentions.js";
37
38
  import { createRootGuard, toRelative } from "./files.js";
38
39
  import { belowPath, blockedBy, inScope, matchesDirectoryReads } from "./file-index.js";
39
40
  import { explorerInternalPath } from "./workspace-file-operations.js";
@@ -67,8 +68,10 @@ export function recordWorkspacePath(indexes, workspaceId, workspaceRoot, path) {
67
68
  index.upsert(scoped);
68
69
  }
69
70
  }
71
+ export const QUICK_OPEN_PAGE_SIZE = 60;
70
72
  const MAX_DIRECTORIES = 20000;
71
- const MAX_FILES = 200000;
73
+ const MAX_ENTRIES = 200000;
74
+ const DIRECTORY_BATCH = 12;
72
75
  /**
73
76
  * The result ordering, and why it is not the path dictionary order.
74
77
  *
@@ -76,12 +79,15 @@ const MAX_FILES = 200000;
76
79
  * a whole string. In a list of two hundred that is actively hostile: the file whose name STARTS
77
80
  * with what you typed is the one you meant, and it is somewhere in the middle. So the order is:
78
81
  *
79
- * 1. the hit position inside the file name - a name that starts with the needle beats one that
80
- * merely contains it, whatever the directory;
81
- * 2. shallower directories first - `notes.md` beats `src/deep/nested/notes.md`;
82
- * 3. the path dictionary order, as the final tie-break, so the order is stable.
82
+ * 1. exact filenames;
83
+ * 2. the hit position inside the file name, so prefixes rank ahead of other substrings;
84
+ * 3. shallower directories first;
85
+ * 4. path order as the final tie-break.
83
86
  */
84
87
  export function compareNameHits(a, b, needle) {
88
+ const exact = Number(b.name.toLowerCase() === needle) - Number(a.name.toLowerCase() === needle);
89
+ if (exact !== 0)
90
+ return exact;
85
91
  const position = hitPosition(a, needle) - hitPosition(b, needle);
86
92
  if (position !== 0)
87
93
  return position;
@@ -120,6 +126,8 @@ export class FileNameIndex {
120
126
  incomplete = false;
121
127
  needsScan = false;
122
128
  generation = 0;
129
+ unread = new Set();
130
+ hasScanned = false;
123
131
  removedDuringScan = new Set();
124
132
  directoriesReadDuringScan = new Map();
125
133
  constructor(workspaceId, cwd = "") {
@@ -139,6 +147,7 @@ export class FileNameIndex {
139
147
  get indexed() {
140
148
  return !this.building && this.failure === undefined;
141
149
  }
150
+ get hasSnapshot() { return this.hasScanned; }
142
151
  get progress() {
143
152
  // The percentage is deliberately not a promise about the whole tree: the total is unknown
144
153
  // until the scan ends, so it is derived from the directory budget instead, and the UI shows
@@ -151,17 +160,28 @@ export class FileNameIndex {
151
160
  // The guard is "has a scan been started", NOT "are there any entries". An EMPTY workspace
152
161
  // finishes its scan with zero entries, and an emptiness test would restart the scan on every
153
162
  // request - so the answer to every query would be "still building" forever.
163
+ if (!this.started || this.needsScan)
164
+ this.revalidate(root);
165
+ }
166
+ /** Keep the preceding results usable while checking files written outside Super Pi. */
167
+ revalidate(root) {
154
168
  if (this.building)
155
169
  return;
156
- if (this.started) {
157
- if (this.needsScan)
158
- this.reset(root);
159
- return;
170
+ if (this.root && this.root !== root) {
171
+ this.entries.clear();
172
+ this.hasScanned = false;
160
173
  }
174
+ this.unread = new Set(this.entries.keys());
175
+ this.removedDuringScan.clear();
176
+ this.directoriesReadDuringScan.clear();
177
+ this.root = root;
161
178
  this.needsScan = false;
162
179
  this.started = true;
163
- this.root = root;
164
180
  this.building = true;
181
+ this.failure = undefined;
182
+ this.incomplete = false;
183
+ this.stopped = false;
184
+ this.scanned = 0;
165
185
  void this.scan(++this.generation);
166
186
  }
167
187
  markStale() { if (this.started)
@@ -189,19 +209,6 @@ export class FileNameIndex {
189
209
  return;
190
210
  throw this.failure;
191
211
  }
192
- /** Rebuild from scratch. The ↻ button. */
193
- reset(root) {
194
- this.entries.clear();
195
- this.removedDuringScan.clear();
196
- this.directoriesReadDuringScan.clear();
197
- this.scanned = 0;
198
- this.incomplete = false;
199
- this.stopped = false;
200
- this.building = false;
201
- this.started = false;
202
- this.failure = undefined;
203
- this.start(root);
204
- }
205
212
  /** Record a path that appeared or changed. Used for agent writes and user saves. */
206
213
  upsert(relativePath, kind = "file", openLink) {
207
214
  const path = relativePath.replace(/\\/g, "/").replace(/^\/+/, "");
@@ -210,6 +217,7 @@ export class FileNameIndex {
210
217
  const cut = path.lastIndexOf("/");
211
218
  const name = cut < 0 ? path : path.slice(cut + 1);
212
219
  const directory = cut < 0 ? "" : path.slice(0, cut);
220
+ this.unread.delete(path);
213
221
  this.entries.set(path, { path, name, directory, kind, ...(openLink ? { openLink } : {}) });
214
222
  }
215
223
  /** Forget a path that is gone. */
@@ -276,6 +284,21 @@ export class FileNameIndex {
276
284
  incomplete: this.incomplete,
277
285
  };
278
286
  }
287
+ searchQuickOpen(query, offset) {
288
+ const files = [...this.entries.values()].filter(entry => entry.kind === "file");
289
+ const ranked = query ? rankPathMatches(files, query) : files;
290
+ if (query && !ranked.length && this.indexed) {
291
+ const approximate = new Fuse(files, { keys: ["path"], threshold: 0.38, ignoreLocation: true });
292
+ ranked.push(...approximate.search(query, { limit: QUICK_OPEN_PAGE_SIZE }).map(match => match.item));
293
+ }
294
+ return {
295
+ hits: ranked.slice(offset, offset + (query ? QUICK_OPEN_PAGE_SIZE : 20)),
296
+ total: ranked.length,
297
+ indexed: this.indexed,
298
+ progress: this.progress,
299
+ incomplete: this.incomplete,
300
+ };
301
+ }
279
302
  /**
280
303
  * Wait until the first scan has finished, or until the deadline passes.
281
304
  *
@@ -311,78 +334,66 @@ export class FileNameIndex {
311
334
  * Link names can be found, and linked directories never enter this traversal's queue.
312
335
  */
313
336
  async scan(generation) {
314
- const started = Date.now();
315
337
  const guard = createRootGuard(this.root);
316
338
  const queue = [""];
317
- while (queue.length) {
339
+ let count = 0;
340
+ scan: for (let next = 0; next < queue.length;) {
318
341
  if (this.stopped || generation !== this.generation)
319
342
  return;
320
- const directory = queue.shift();
321
- if (this.scanned >= MAX_DIRECTORIES) {
343
+ const batch = queue.slice(next, Math.min(next + DIRECTORY_BATCH, MAX_DIRECTORIES));
344
+ if (!batch.length) {
322
345
  this.incomplete = true;
323
346
  break;
324
347
  }
325
- this.scanned += 1;
326
- let entries;
327
- try {
328
- entries = await readdir(await guard(directory), { withFileTypes: true });
329
- }
330
- catch (error) {
331
- if (generation !== this.generation || this.stopped)
332
- return;
333
- // THE ROOT IS NOT ONE OF THE SKIPPABLE DIRECTORIES.
334
- //
335
- // A workspace whose directory is gone must answer 404 `workspace_missing`, and the reason is
336
- // the one this file's own `incomplete` flag cannot express: "I searched and found nothing"
337
- // and "there was nothing to search" are DIFFERENT answers, and only one of them is true.
338
- // The old walk rethrew the root's failure and the route turned it into a 404; swallowing it
339
- // here would put that exact bug back - a 200 with an empty list, which is byte-for-byte the
340
- // response for "your search matched nothing".
341
- //
342
- // The failure is RECORDED, not thrown: see `failure` above for why throwing it here would
343
- // take the whole server down with it.
344
- //
345
- // A SUBDIRECTORY that cannot be read is skipped instead: one unreadable folder in a large
346
- // tree must not cost the reader every other match, and the scan says so through
347
- // `incomplete` rather than by pretending the folder was empty.
348
- if (directory === "") {
349
- this.failure = error;
350
- this.building = false;
351
- return;
352
- }
353
- this.incomplete = true;
354
- continue;
355
- }
356
- if (generation !== this.generation || this.stopped)
348
+ next += batch.length;
349
+ const listings = await Promise.allSettled(batch.map(async (directory) => readdir(await guard(directory), { withFileTypes: true })));
350
+ if (this.stopped || generation !== this.generation)
357
351
  return;
358
- for (const entry of entries) {
359
- const relative = directory ? `${directory}/${entry.name}` : entry.name;
360
- if (explorerInternalPath(this.cwd ? `${this.cwd}/${relative}` : relative) || blockedBy(relative, this.removedDuringScan)
361
- || !matchesDirectoryReads(relative, this.directoriesReadDuringScan))
362
- continue;
363
- if (entry.isDirectory()) {
364
- this.entries.set(relative, { path: relative, name: entry.name, directory, kind: "directory" });
365
- queue.push(relative);
352
+ for (const [index, listing] of listings.entries()) {
353
+ const directory = batch[index];
354
+ this.scanned += 1;
355
+ if (listing.status === "rejected") {
356
+ if (!directory) {
357
+ this.failure = listing.reason;
358
+ this.building = false;
359
+ this.unread.clear();
360
+ return;
361
+ }
362
+ this.incomplete = true;
366
363
  continue;
367
364
  }
368
- const openLink = entry.isSymbolicLink() && await stat(resolve(this.root, relative)).then(info => info.isFile(), () => false);
369
- if (generation !== this.generation || this.stopped)
370
- return;
371
- if (openLink && (blockedBy(relative, this.removedDuringScan) || !matchesDirectoryReads(relative, this.directoriesReadDuringScan)))
372
- continue;
373
- if (!entry.isFile() && !openLink)
374
- continue;
375
- if (this.entries.size >= MAX_FILES) {
376
- this.incomplete = true;
377
- break;
365
+ for (const entry of listing.value) {
366
+ const relative = directory ? `${directory}/${entry.name}` : entry.name;
367
+ if (explorerInternalPath(this.cwd ? `${this.cwd}/${relative}` : relative) || blockedBy(relative, this.removedDuringScan)
368
+ || !matchesDirectoryReads(relative, this.directoriesReadDuringScan))
369
+ continue;
370
+ const isDirectory = entry.isDirectory();
371
+ const openLink = entry.isSymbolicLink() && await stat(resolve(this.root, relative)).then(info => info.isFile(), () => false);
372
+ if (generation !== this.generation || this.stopped)
373
+ return;
374
+ if (openLink && (blockedBy(relative, this.removedDuringScan) || !matchesDirectoryReads(relative, this.directoriesReadDuringScan)))
375
+ continue;
376
+ if (!isDirectory && !entry.isFile() && !openLink)
377
+ continue;
378
+ if (count >= MAX_ENTRIES) {
379
+ this.incomplete = true;
380
+ break scan;
381
+ }
382
+ count++;
383
+ this.unread.delete(relative);
384
+ this.entries.set(relative, { path: relative, name: entry.name, directory, kind: isDirectory ? "directory" : "file",
385
+ ...(openLink ? { openLink: true } : {}) });
386
+ if (isDirectory)
387
+ queue.push(relative);
378
388
  }
379
- this.entries.set(relative, { path: relative, name: entry.name, directory, kind: "file", ...(openLink ? { openLink: true } : {}) });
380
389
  }
381
- // Yield between directories so a large tree does not monopolise the event loop and starve
382
- // the WebSocket heartbeat. `setTimeout(0)` is the cheapest yield that still lets timers run.
383
- if (Date.now() - started > 0 && queue.length)
384
- await new Promise((resolve) => setTimeout(resolve, 0));
385
390
  }
391
+ if (!this.incomplete) {
392
+ for (const path of this.unread)
393
+ this.entries.delete(path);
394
+ }
395
+ this.unread.clear();
396
+ this.hasScanned = true;
386
397
  this.building = false;
387
398
  this.removedDuringScan.clear();
388
399
  this.directoriesReadDuringScan.clear();
@@ -1,5 +1,5 @@
1
1
  import type { GitCommitDetail } from "../shared/git-commit.js";
2
- import type { GitGraphPage } from "../shared/git-graph.js";
2
+ import type { GitGraphResponse } from "../shared/git-graph.js";
3
3
  export type GitWorkspace = {
4
4
  branch: string | null;
5
5
  detached: boolean;
@@ -26,7 +26,7 @@ export declare function gitLog(root: string, limit: number, cwd?: string, query?
26
26
  }[];
27
27
  truncated: boolean;
28
28
  }>;
29
- export declare function gitGraph(root: string, limit: number, offset: number, snapshot: string, after: string): Promise<GitGraphPage>;
29
+ export declare function gitGraph(root: string, limit: number, offset: number, snapshot: string, after: string, knownSnapshot?: string): Promise<GitGraphResponse>;
30
30
  export declare function gitCommit(root: string, cwd: string, hash: string): Promise<GitCommitDetail>;
31
31
  export declare function gitCommitDiff(root: string, cwd: string, hash: string, path: string, fullContext?: boolean): Promise<{
32
32
  path: string;
@@ -83,7 +83,7 @@ function parseGitCommits(raw) {
83
83
  return commits;
84
84
  }
85
85
  const COMMIT_HASH = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i;
86
- export async function gitGraph(root, limit, offset, snapshot, after) {
86
+ export async function gitGraph(root, limit, offset, snapshot, after, knownSnapshot = "") {
87
87
  const size = pageNumber(limit, 50, 1, 100);
88
88
  const start = pageNumber(offset, 0, 0, 2_147_483_647);
89
89
  const repo = await worktreeRoot(root);
@@ -97,6 +97,8 @@ export async function gitGraph(root, limit, offset, snapshot, after) {
97
97
  const changed = () => gitFailure("提交图已变化,请刷新后继续查看。", "graph_changed");
98
98
  if (start && snapshot !== version)
99
99
  throw changed();
100
+ if (!start && knownSnapshot === version)
101
+ return { unchanged: true, snapshot: version };
100
102
  const labels = new Map();
101
103
  const mark = (hash, label) => {
102
104
  const list = labels.get(hash) ?? [];
@@ -26,7 +26,7 @@ import { MAX_WEB_REQUEST_BYTES } from "./web.js";
26
26
  import { MAX_TOOL_BODY_BYTES } from "./tool-registry.js";
27
27
  import { claimUpdateSlot, getLastUpdateOutcome, isUpdateInFlight, packageUpdateArgs, recordUpdateOutcome, releaseUpdateSlot, shellArgs } from "./update.js";
28
28
  import { FileIndex, refreshWorkspaceIndex } from "./file-index.js";
29
- import { ensureNameIndex, recordWorkspacePath } from "./file-name-index.js";
29
+ import { ensureNameIndex, QUICK_OPEN_PAGE_SIZE, recordWorkspacePath } from "./file-name-index.js";
30
30
  import { resolveFileCwd, sessionScopeKey, workspacePathFromSession } from "./session-cwd.js";
31
31
  import { explorerInternalPath, explorerPath, inspectWorkspaceUpload, listWorkspaceTrash, MAX_WORKSPACE_UPLOAD_BYTES, mutateWorkspaceTree, serializeWorkspaceWrite, uploadWorkspaceFile } from "./workspace-file-operations.js";
32
32
  import { readWorkspaceDocumentPreview, respondWithWorkspaceFile } from "./workspace-file-response.js";
@@ -1433,7 +1433,7 @@ export function createHttpServer(options) {
1433
1433
  if (op === "status")
1434
1434
  json(200, await gitStatus(workspace.path, cwd));
1435
1435
  else if (op === "graph") {
1436
- json(200, await gitGraph(workspace.path, Number(url.searchParams.get("limit") ?? 50), Number(url.searchParams.get("offset") ?? 0), url.searchParams.get("snapshot") ?? "", url.searchParams.get("after") ?? ""));
1436
+ json(200, await gitGraph(workspace.path, Number(url.searchParams.get("limit") ?? 50), Number(url.searchParams.get("offset") ?? 0), url.searchParams.get("snapshot") ?? "", url.searchParams.get("after") ?? "", url.searchParams.get("knownSnapshot") ?? ""));
1437
1437
  }
1438
1438
  else if (op === "log" || op === "branches" || op === "stash") {
1439
1439
  const query = url.searchParams.get("q") ?? "";
@@ -2973,41 +2973,34 @@ export function createHttpServer(options) {
2973
2973
  json(405, { error: "目录列表需要 GET 请求。", code: "method" });
2974
2974
  return;
2975
2975
  }
2976
- const query = url.searchParams.get("q");
2977
- if (query !== null && query.trim() !== "") {
2978
- // THE SEARCH IS AN INDEX QUERY, not a walk.
2979
- //
2980
- // The old path re-walked the entire tree on every keystroke and then reported its own
2981
- // limits ("已跳过 N 个目录", "结果不完整"). The index answers from memory - no filesystem
2982
- // access at all - and covers every directory in the workspace, so there is nothing to
2983
- // report a limit about. `truncated` and `skipped` stay in the response so the protocol
2984
- // shape does not change under the client, but they are now constants that say the
2985
- // opposite of what they used to.
2976
+ const query = url.searchParams.get("q")?.trim();
2977
+ const quick = url.searchParams.get("quick") === "1";
2978
+ if (query !== undefined && (query || quick)) {
2979
+ const page = Number(url.searchParams.get("page") ?? 0);
2980
+ if (quick && (query.length > 8192 || !Number.isSafeInteger(page) || page < 0 || page > Math.floor(Number.MAX_SAFE_INTEGER / QUICK_OPEN_PAGE_SIZE))) {
2981
+ json(400, { error: "文件查找请求无效。", code: "bad_query" });
2982
+ return;
2983
+ }
2986
2984
  const index = nameIndexFor(context, workspaceId, root, cwd);
2987
- // THE WORKSPACE MUST EXIST, AND THE INDEX IS WHAT KNOWS.
2988
- //
2989
- // The background scan records a root it could not read rather than throwing it - a scan
2990
- // has no caller to receive a rejection, and an unhandled one terminates the process. So
2991
- // the route asks the index what happened and turns the answer into the status it
2992
- // deserves. Without this a workspace whose directory is gone would answer 200 with an
2993
- // empty list, which is byte-for-byte the response for "your search matched nothing" -
2994
- // the exact confusion this endpoint is supposed to avoid.
2995
- await index.waitUntilIndexed(4000);
2985
+ const refresh = url.searchParams.get("refresh") === "1";
2986
+ if (refresh)
2987
+ index.revalidate(root);
2988
+ // A warm picker can use known results while refresh works through the remaining paths.
2989
+ if (!quick)
2990
+ await index.waitUntilIndexed(4000);
2991
+ else if (!refresh && !index.hasSnapshot)
2992
+ await index.waitUntilIndexed(800);
2996
2993
  index.throwIfBroken();
2997
- // WAIT FOR THE INDEX, briefly. A search answered from a half-built map would say "no
2998
- // matches" for files that are on disk - which is precisely the "搜不出他想搜的东西"
2999
- // failure this work exists to remove. Past the deadline the answer is still returned, with
3000
- // `indexed: false` so the UI can say the index is still building rather than pretending
3001
- // the tree is empty.
3002
2994
  const linksOnly = url.searchParams.get("links") === "1";
3003
- const result = index.search(query, linksOnly);
3004
- const hits = linksOnly ? result.hits.slice(0, 20) : result.hits;
2995
+ const offset = page * QUICK_OPEN_PAGE_SIZE;
2996
+ const result = quick ? index.searchQuickOpen(query, offset) : index.search(query, linksOnly);
2997
+ const hits = !quick && linksOnly ? result.hits.slice(0, 20) : result.hits;
3005
2998
  json(200, {
3006
2999
  mode: "search",
3007
3000
  query: query.trim(),
3008
3001
  hits: hits.map(({ path, name, directory, openLink }) => ({ path, name, directory, ...(openLink ? { openLink } : {}) })),
3009
3002
  total: result.total,
3010
- truncated: hits.length < result.total,
3003
+ truncated: (quick ? offset : 0) + hits.length < result.total,
3011
3004
  skipped: [],
3012
3005
  indexed: result.indexed,
3013
3006
  progress: result.progress,
@@ -9,6 +9,7 @@ export interface MentionToken {
9
9
  }
10
10
  /** Only a standalone @ token opens completion; email addresses and escaped @ stay literal. */
11
11
  export declare function findMentionToken(text: string, caret: number, selectionEnd?: number): MentionToken | undefined;
12
+ export declare function rankPathMatches<T extends PathMentionEntry>(entries: Iterable<T>, query: string): T[];
12
13
  export declare function matchPathMentions<T extends PathMentionEntry>(entries: Iterable<T>, query: string, limit?: number): T[];
13
14
  export declare function insertPathMention(text: string, token: MentionToken, entry: PathMentionEntry): {
14
15
  text: string;
@@ -33,19 +33,23 @@ function fuzzyScore(path, query) {
33
33
  }
34
34
  return 50 + gaps / Math.max(1, path.length);
35
35
  }
36
- export function matchPathMentions(entries, query, limit = 30) {
37
- const needle = query.trim().replaceAll("\\", "/").toLowerCase();
36
+ export function rankPathMatches(entries, query) {
37
+ const normalized = query.trim().replaceAll("\\", "/");
38
+ const needle = normalized.toLowerCase();
38
39
  const matches = [];
39
40
  for (const entry of entries) {
40
41
  if (!entry.path || entry.path.startsWith("/") || /^[a-z]:/iu.test(entry.path) || entry.path.split("/").includes(".."))
41
42
  continue;
42
43
  const path = entry.path.toLowerCase();
43
- const score = needle ? fuzzyScore(path, needle) : 0;
44
+ const score = needle ? entry.path === normalized ? -2 : fuzzyScore(path, needle) : 0;
44
45
  if (score !== undefined)
45
46
  matches.push({ entry, score, depth: entry.path.split("/").length });
46
47
  }
47
48
  matches.sort((a, b) => a.score - b.score || a.depth - b.depth || Number(b.entry.kind === "directory") - Number(a.entry.kind === "directory") || (a.entry.path < b.entry.path ? -1 : a.entry.path > b.entry.path ? 1 : 0));
48
- return matches.slice(0, Math.max(0, Math.min(100, limit))).map(item => item.entry);
49
+ return matches.map(item => item.entry);
50
+ }
51
+ export function matchPathMentions(entries, query, limit = 30) {
52
+ return rankPathMatches(entries, query).slice(0, Math.max(0, Math.min(100, limit)));
49
53
  }
50
54
  export function insertPathMention(text, token, entry) {
51
55
  const path = entry.path + (entry.kind === "directory" && !entry.path.endsWith("/") ? "/" : "");
@@ -12,6 +12,10 @@ export type GitGraphCommit = {
12
12
  date: string;
13
13
  refs: GitGraphRef[];
14
14
  };
15
+ export type GitGraphResponse = GitGraphPage | {
16
+ unchanged: true;
17
+ snapshot: string;
18
+ };
15
19
  export type GitGraphPage = {
16
20
  commits: GitGraphCommit[];
17
21
  snapshot: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evandu/super-pi",
3
- "version": "0.1.237",
3
+ "version": "0.1.238",
4
4
  "description": "Web control plane and companion for Pi",
5
5
  "license": "MIT",
6
6
  "type": "module",