@evandu/super-pi 0.1.214 → 0.1.215
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/agents/super-pi-task/core.ts +1 -0
- package/dist/client/.super-pi-client-sources.json +10 -7
- package/dist/client/assets/{CodeMirrorEditor-oBE41c_Z.js → CodeMirrorEditor-BtFqRtwL.js} +2 -2
- package/dist/client/assets/{dist-BlvdNlom.js → dist-3j9lY0e9.js} +1 -1
- package/dist/client/assets/{dist-BI2bdKJA.js → dist-6R_r8mV7.js} +1 -1
- package/dist/client/assets/{dist-CtUGT7X0.js → dist-B4xD1_9l.js} +1 -1
- package/dist/client/assets/{dist-XMoaVV0I.js → dist-B7GfFh8D.js} +1 -1
- package/dist/client/assets/{dist-JTV0mw7o.js → dist-BM_t0r0o.js} +1 -1
- package/dist/client/assets/{dist-6bnqbsrS.js → dist-Bclz0zcg.js} +1 -1
- package/dist/client/assets/{dist-DRxZv53M.js → dist-BfUltWFm.js} +1 -1
- package/dist/client/assets/{dist-Ma_x_86x.js → dist-BmwYtlA6.js} +1 -1
- package/dist/client/assets/{dist-CxnNjCu8.js → dist-C2AL8qpk.js} +1 -1
- package/dist/client/assets/{dist-ngDl1jAo.js → dist-C7kG2EMV.js} +1 -1
- package/dist/client/assets/{dist-Cz-vfmbM.js → dist-C8NpJn6C.js} +1 -1
- package/dist/client/assets/{dist-_7n_HjfY.js → dist-CKFlYN5n.js} +1 -1
- package/dist/client/assets/{dist-C1-ktLo2.js → dist-Ch7vccWx.js} +1 -1
- package/dist/client/assets/{dist-CNbHHAt6.js → dist-ChCJkzFm.js} +1 -1
- package/dist/client/assets/{dist-BrVjpF77.js → dist-D2KUrSnq.js} +1 -1
- package/dist/client/assets/{dist-BymRxGJs.js → dist-D2lQWc-w.js} +1 -1
- package/dist/client/assets/{dist--5c7s7ln.js → dist-DBuM8N0c.js} +1 -1
- package/dist/client/assets/{dist-BpOjt7NU.js → dist-DbQeb6jo.js} +1 -1
- package/dist/client/assets/{dist-B5QNxRTR.js → dist-DcfNMoeZ.js} +1 -1
- package/dist/client/assets/{dist-2xQtdGkL.js → dist-he8VswUy.js} +1 -1
- package/dist/client/assets/{dist-BZccKPV5.js → dist-lh3aOKa3.js} +1 -1
- package/dist/client/assets/{dist-iTOgXvhM.js → dist-qLCMPuHc.js} +1 -1
- package/dist/client/assets/index-CakWERUJ.js +103 -0
- package/dist/client/assets/{index-CxXBIQ2J.css → index-bS4bISZo.css} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/server/http-server.js +33 -0
- package/dist/shared/file-mentions.d.ts +16 -0
- package/dist/shared/file-mentions.js +53 -0
- package/package.json +5 -1
- package/dist/client/assets/index-Chz3LHRc.js +0 -103
package/dist/client/index.html
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
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-
|
|
12
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
11
|
+
<script type="module" crossorigin src="/assets/index-CakWERUJ.js"></script>
|
|
12
|
+
<link rel="stylesheet" crossorigin href="/assets/index-bS4bISZo.css">
|
|
13
13
|
</head>
|
|
14
14
|
<body>
|
|
15
15
|
<div id="root"></div>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createReadStream, existsSync } from "node:fs";
|
|
2
|
+
import { matchPathMentions } from "../shared/file-mentions.js";
|
|
2
3
|
import { spawn } from "node:child_process";
|
|
3
4
|
import { randomUUID } from "node:crypto";
|
|
4
5
|
import { readdir, rm, stat } from "node:fs/promises";
|
|
@@ -2500,6 +2501,38 @@ export function createHttpServer(options) {
|
|
|
2500
2501
|
}
|
|
2501
2502
|
return;
|
|
2502
2503
|
}
|
|
2504
|
+
if (url.pathname === "/api/files/mentions") {
|
|
2505
|
+
const json = (status, body) => { response.writeHead(status, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(body)); };
|
|
2506
|
+
try {
|
|
2507
|
+
if (request.method !== "GET") {
|
|
2508
|
+
json(405, { error: "文件引用需要 GET 请求。" });
|
|
2509
|
+
return;
|
|
2510
|
+
}
|
|
2511
|
+
const workspaceId = url.searchParams.get("workspaceId")?.trim();
|
|
2512
|
+
const workspace = workspaceId ? store.workspace(workspaceId) : undefined;
|
|
2513
|
+
if (!workspaceId || !workspace) {
|
|
2514
|
+
json(404, { error: "请先选择有效工作区。", code: "no_workspace" });
|
|
2515
|
+
return;
|
|
2516
|
+
}
|
|
2517
|
+
const query = url.searchParams.get("q") ?? "";
|
|
2518
|
+
if (query.length > 512) {
|
|
2519
|
+
json(400, { error: "搜索内容过长。" });
|
|
2520
|
+
return;
|
|
2521
|
+
}
|
|
2522
|
+
const root = await resolveInsideRoot(workspace.path, url.searchParams.get("cwd") ?? "");
|
|
2523
|
+
const cwd = relative(resolve(workspace.path), root).replaceAll("\\", "/");
|
|
2524
|
+
const index = nameIndexFor(context, workspaceId, root, cwd);
|
|
2525
|
+
await index.waitUntilIndexed(4000);
|
|
2526
|
+
index.throwIfBroken();
|
|
2527
|
+
const entries = function* () { yield { path: ".", kind: "directory" }; yield* index.entries.values(); };
|
|
2528
|
+
json(200, { hits: matchPathMentions(entries(), query), indexed: index.indexed, incomplete: index.search("").incomplete });
|
|
2529
|
+
}
|
|
2530
|
+
catch (error) {
|
|
2531
|
+
const described = describeFilesError(error);
|
|
2532
|
+
json(described.status, described.body);
|
|
2533
|
+
}
|
|
2534
|
+
return;
|
|
2535
|
+
}
|
|
2503
2536
|
if (url.pathname === "/api/files/index") {
|
|
2504
2537
|
const json = (status, body) => {
|
|
2505
2538
|
const raw = Buffer.from(JSON.stringify(body), "utf8");
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface PathMentionEntry {
|
|
2
|
+
path: string;
|
|
3
|
+
kind: "file" | "directory";
|
|
4
|
+
}
|
|
5
|
+
export interface MentionToken {
|
|
6
|
+
start: number;
|
|
7
|
+
end: number;
|
|
8
|
+
query: string;
|
|
9
|
+
}
|
|
10
|
+
/** Only a standalone @ token opens completion; email addresses and escaped @ stay literal. */
|
|
11
|
+
export declare function findMentionToken(text: string, caret: number, selectionEnd?: number): MentionToken | undefined;
|
|
12
|
+
export declare function matchPathMentions(entries: Iterable<PathMentionEntry>, query: string, limit?: number): PathMentionEntry[];
|
|
13
|
+
export declare function insertPathMention(text: string, token: MentionToken, entry: PathMentionEntry): {
|
|
14
|
+
text: string;
|
|
15
|
+
caret: number;
|
|
16
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Only a standalone @ token opens completion; email addresses and escaped @ stay literal. */
|
|
2
|
+
export function findMentionToken(text, caret, selectionEnd = caret) {
|
|
3
|
+
if (caret !== selectionEnd || caret < 0 || caret > text.length)
|
|
4
|
+
return undefined;
|
|
5
|
+
const match = /(?:^|[\s([{])@(?:"([^"\n]*)|([^\s@"\n]*))$/u.exec(text.slice(0, caret));
|
|
6
|
+
if (!match)
|
|
7
|
+
return undefined;
|
|
8
|
+
const start = match.index + match[0].indexOf("@");
|
|
9
|
+
const tail = text.slice(caret);
|
|
10
|
+
const remaining = match[1] !== undefined ? /^[^"\n]*(?:"|$)/u.exec(tail)?.[0] : /^[^\s@"\n]*/u.exec(tail)?.[0];
|
|
11
|
+
return { start, end: caret + (remaining?.length ?? 0), query: match[1] ?? match[2] ?? "" };
|
|
12
|
+
}
|
|
13
|
+
/** Ordered-character matching supports abbreviations such as sct -> src/client/theme.tsx. */
|
|
14
|
+
function fuzzyScore(path, query) {
|
|
15
|
+
const name = path.slice(path.lastIndexOf("/") + 1);
|
|
16
|
+
if (name === query)
|
|
17
|
+
return 0;
|
|
18
|
+
if (name.startsWith(query))
|
|
19
|
+
return 10 + name.length / 1000;
|
|
20
|
+
if (name.includes(query))
|
|
21
|
+
return 20 + name.indexOf(query) / 100;
|
|
22
|
+
if (path.includes(query))
|
|
23
|
+
return 30 + path.indexOf(query) / 100;
|
|
24
|
+
let position = -1, gaps = 0;
|
|
25
|
+
for (const character of query) {
|
|
26
|
+
const next = path.indexOf(character, position + 1);
|
|
27
|
+
if (next < 0)
|
|
28
|
+
return undefined;
|
|
29
|
+
gaps += next - position - 1;
|
|
30
|
+
position = next;
|
|
31
|
+
}
|
|
32
|
+
return 50 + gaps / Math.max(1, path.length);
|
|
33
|
+
}
|
|
34
|
+
export function matchPathMentions(entries, query, limit = 30) {
|
|
35
|
+
const needle = query.trim().replaceAll("\\", "/").toLowerCase();
|
|
36
|
+
const matches = [];
|
|
37
|
+
for (const entry of entries) {
|
|
38
|
+
if (!entry.path || entry.path.startsWith("/") || /^[a-z]:/iu.test(entry.path) || entry.path.split("/").includes(".."))
|
|
39
|
+
continue;
|
|
40
|
+
const path = entry.path.toLowerCase();
|
|
41
|
+
const score = needle ? fuzzyScore(path, needle) : 0;
|
|
42
|
+
if (score !== undefined)
|
|
43
|
+
matches.push({ entry, score, depth: entry.path.split("/").length });
|
|
44
|
+
}
|
|
45
|
+
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));
|
|
46
|
+
return matches.slice(0, Math.max(0, Math.min(100, limit))).map(item => item.entry);
|
|
47
|
+
}
|
|
48
|
+
export function insertPathMention(text, token, entry) {
|
|
49
|
+
const path = entry.path + (entry.kind === "directory" && !entry.path.endsWith("/") ? "/" : "");
|
|
50
|
+
const reference = "@" + (/^[^\s@"\\]+$/u.test(path) ? path : JSON.stringify(path));
|
|
51
|
+
const insertion = reference + " ";
|
|
52
|
+
return { text: text.slice(0, token.start) + insertion + text.slice(token.end), caret: token.start + insertion.length };
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evandu/super-pi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.215",
|
|
4
4
|
"description": "Web control plane and companion for Pi",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -43,6 +43,8 @@
|
|
|
43
43
|
"test": "node scripts/test.mjs"
|
|
44
44
|
},
|
|
45
45
|
"check:logic": [
|
|
46
|
+
"scripts/markdown-syntax.test.mjs",
|
|
47
|
+
"scripts/file-mentions.test.mjs",
|
|
46
48
|
"scripts/sidebar-refresh.test.mjs",
|
|
47
49
|
"scripts/provider-network.test.mjs",
|
|
48
50
|
"scripts/project-overview.test.mjs",
|
|
@@ -283,6 +285,8 @@
|
|
|
283
285
|
"scripts/session-reminder-pmo-rights.test.mjs"
|
|
284
286
|
],
|
|
285
287
|
"check:browser": [
|
|
288
|
+
"scripts/markdown-syntax-browser.test.mjs",
|
|
289
|
+
"scripts/file-mentions-browser.test.mjs",
|
|
286
290
|
"scripts/message-actions-browser.test.mjs",
|
|
287
291
|
"scripts/sidebar-refresh-browser.test.mjs",
|
|
288
292
|
"scripts/provider-network-browser.test.mjs",
|