@evandu/super-pi 0.1.273 → 0.1.274
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/group-rsi.md +18 -0
- package/agents/super-pi-task/core.ts +7 -7
- package/bin/completion.js +19 -5
- package/bin/super-pi.js +3 -0
- package/desktop/runtime.cjs +28 -4
- package/dist/client/.super-pi-client-sources.json +24 -16
- package/dist/client/assets/CodeMirrorEditor-DjMbNm7l.js +2 -0
- package/dist/client/assets/GitDiffEditor-Cwim9Ua1.js +29 -0
- package/dist/client/assets/{dist-DGBjhKI9.js → dist-AW5lyI3I.js} +1 -1
- package/dist/client/assets/dist-B3-a6uF0.js +7 -0
- package/dist/client/assets/dist-BGxkyh6e.js +1 -0
- package/dist/client/assets/dist-BJxfd7yb.js +11 -0
- package/dist/client/assets/{dist-BvjUKkwy.js → dist-BRVQKlcp.js} +1 -1
- package/dist/client/assets/dist-BV64A9Ji.js +1 -0
- package/dist/client/assets/{dist-BlRuQIg1.js → dist-BXAOrsjq.js} +1 -1
- package/dist/client/assets/dist-CKF2Jksy.js +1 -0
- package/dist/client/assets/dist-CX_Hm4GS.js +1 -0
- package/dist/client/assets/{dist-i79xiXVk.js → dist-Cus6_oaF.js} +2 -2
- package/dist/client/assets/dist-Cx00EZKR.js +23 -0
- package/dist/client/assets/dist-D71y2EI1.js +1 -0
- package/dist/client/assets/dist-Dc1MBGAG.js +1 -0
- package/dist/client/assets/dist-Dds-qLxY.js +9 -0
- package/dist/client/assets/dist-DeD9copn.js +1 -0
- package/dist/client/assets/dist-DuvGReu-.js +6 -0
- package/dist/client/assets/{dist-D5u1uPmZ.js → dist-Dvb0SqcK.js} +2 -2
- package/dist/client/assets/dist-J6XWqRpB.js +3 -0
- package/dist/client/assets/{dist-CQncCwUc.js → dist-QzbOCAU6.js} +1 -1
- package/dist/client/assets/{dist-DjI7p99D.js → dist-moiMRpw_.js} +1 -1
- package/dist/client/assets/dist-scBkrwv-.js +2 -0
- package/dist/client/assets/index-BL9o4WZN.js +350 -0
- package/dist/client/assets/index-D1qJmoVY.css +1 -0
- package/dist/client/index.html +2 -2
- package/dist/server/application/conversation-service.d.ts +1 -1
- package/dist/server/application/conversation-service.js +3 -2
- package/dist/server/application/group-chat-service.d.ts +17 -0
- package/dist/server/application/group-chat-service.js +168 -3
- package/dist/server/application/group-rsi.d.ts +13 -0
- package/dist/server/application/group-rsi.js +69 -0
- package/dist/server/application/worktree-service.js +6 -2
- package/dist/server/http-server.js +22 -0
- package/dist/server/index.js +15 -2
- package/dist/server/managed-http.js +2 -1
- package/dist/server/managed-model-adapter.d.ts +4 -0
- package/dist/server/managed-model-relay.d.ts +1 -1
- package/dist/server/managed-model-relay.js +18 -15
- package/dist/server/managed-servers.d.ts +10 -1
- package/dist/server/managed-servers.js +63 -4
- package/dist/server/remote-bootstrap.d.ts +11 -0
- package/dist/server/remote-bootstrap.js +105 -29
- package/dist/shared/group-chat.d.ts +40 -0
- package/package.json +2 -1
- package/dist/client/assets/CodeMirrorEditor-D8MjtASz.js +0 -2
- package/dist/client/assets/GitDiffEditor-DFJmhUHc.js +0 -29
- package/dist/client/assets/dist-3qQVP6l8.js +0 -6
- package/dist/client/assets/dist-CZ4PyxQu.js +0 -9
- package/dist/client/assets/dist-CfTFp0AF.js +0 -2
- package/dist/client/assets/dist-CxmJXjJI.js +0 -1
- package/dist/client/assets/dist-D8HpMxmZ.js +0 -1
- package/dist/client/assets/dist-DRBIy9A1.js +0 -1
- package/dist/client/assets/dist-Dcww9FSw.js +0 -1
- package/dist/client/assets/dist-DlPa5gNa.js +0 -7
- package/dist/client/assets/dist-DxPJ1PN-.js +0 -1
- package/dist/client/assets/dist-HXD8sSA4.js +0 -23
- package/dist/client/assets/dist-LbeLCeoq.js +0 -1
- package/dist/client/assets/dist-ONdtnupI.js +0 -1
- package/dist/client/assets/dist-YqmXusLA.js +0 -11
- package/dist/client/assets/dist-ZAR1Tu2c.js +0 -3
- package/dist/client/assets/index-Bqutm6qV.js +0 -350
- package/dist/client/assets/index-DV3qc1Hh.css +0 -1
|
@@ -2,10 +2,18 @@ import { type IncomingMessage, type ServerResponse } from "node:http";
|
|
|
2
2
|
import type { Duplex } from "node:stream";
|
|
3
3
|
import type { Client } from "ssh2";
|
|
4
4
|
import type { ManagedServerInput, ManagedServerProfile, SshVerification } from "../shared/managed-servers.js";
|
|
5
|
+
interface EntryIntegrations {
|
|
6
|
+
available(): {
|
|
7
|
+
web: boolean;
|
|
8
|
+
feishu: boolean;
|
|
9
|
+
};
|
|
10
|
+
invoke(kind: "web" | "feishu", body: Record<string, unknown>, signal: AbortSignal): Promise<unknown>;
|
|
11
|
+
}
|
|
5
12
|
export declare class ManagedServers {
|
|
6
13
|
private readonly directory;
|
|
7
14
|
private readonly packageRoot;
|
|
8
15
|
private readonly defaultModel;
|
|
16
|
+
private readonly integrations?;
|
|
9
17
|
private readonly records;
|
|
10
18
|
private readonly clients;
|
|
11
19
|
private readonly secrets;
|
|
@@ -30,7 +38,7 @@ export declare class ManagedServers {
|
|
|
30
38
|
constructor(directory: string, packageRoot: string, defaultModel: () => {
|
|
31
39
|
provider: string;
|
|
32
40
|
modelId: string;
|
|
33
|
-
} | undefined);
|
|
41
|
+
} | undefined, integrations?: EntryIntegrations | undefined);
|
|
34
42
|
initialize(): Promise<void>;
|
|
35
43
|
list(): {
|
|
36
44
|
id: string;
|
|
@@ -129,3 +137,4 @@ export declare class ManagedServers {
|
|
|
129
137
|
upgrade(id: string, path: string, request: IncomingMessage, socket: Duplex, head: Buffer): Promise<void>;
|
|
130
138
|
close(): Promise<void>;
|
|
131
139
|
}
|
|
140
|
+
export {};
|
|
@@ -19,6 +19,7 @@ export class ManagedServers {
|
|
|
19
19
|
directory;
|
|
20
20
|
packageRoot;
|
|
21
21
|
defaultModel;
|
|
22
|
+
integrations;
|
|
22
23
|
records = new Map();
|
|
23
24
|
clients = new Map();
|
|
24
25
|
secrets = new Map();
|
|
@@ -40,10 +41,11 @@ export class ManagedServers {
|
|
|
40
41
|
maintaining = false;
|
|
41
42
|
persistence = Promise.resolve();
|
|
42
43
|
artifact;
|
|
43
|
-
constructor(directory, packageRoot, defaultModel) {
|
|
44
|
+
constructor(directory, packageRoot, defaultModel, integrations) {
|
|
44
45
|
this.directory = directory;
|
|
45
46
|
this.packageRoot = packageRoot;
|
|
46
47
|
this.defaultModel = defaultModel;
|
|
48
|
+
this.integrations = integrations;
|
|
47
49
|
this.vault = new ManagerVault(join(directory, "credentials"));
|
|
48
50
|
}
|
|
49
51
|
async initialize() {
|
|
@@ -83,7 +85,45 @@ export class ManagedServers {
|
|
|
83
85
|
const expected = Buffer.from(token);
|
|
84
86
|
return supplied.length === expected.length && timingSafeEqual(supplied, expected);
|
|
85
87
|
});
|
|
86
|
-
if (
|
|
88
|
+
if (!valid) {
|
|
89
|
+
response.writeHead(403).end();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (["/integration/web", "/integration/feishu"].includes(request.url ?? "") && this.integrations) {
|
|
93
|
+
const kind = request.url === "/integration/web" ? "web" : "feishu";
|
|
94
|
+
const controller = new AbortController();
|
|
95
|
+
response.once("close", () => { if (!response.writableEnded)
|
|
96
|
+
controller.abort(); });
|
|
97
|
+
void (async () => {
|
|
98
|
+
try {
|
|
99
|
+
if (request.method !== "POST" || !this.integrations.available()[kind]) {
|
|
100
|
+
response.writeHead(503).end();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const parts = [];
|
|
104
|
+
let size = 0;
|
|
105
|
+
for await (const part of request) {
|
|
106
|
+
size += part.length;
|
|
107
|
+
if (size > 4 * 1024 * 1024) {
|
|
108
|
+
response.writeHead(413).end();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
parts.push(part);
|
|
112
|
+
}
|
|
113
|
+
const body = JSON.parse(Buffer.concat(parts).toString("utf8"));
|
|
114
|
+
if (!body || typeof body !== "object" || Array.isArray(body))
|
|
115
|
+
throw new Error("入口服务请求格式无效");
|
|
116
|
+
const result = await this.integrations.invoke(kind, body, controller.signal);
|
|
117
|
+
response.writeHead(200, { "content-type": "application/json" }).end(JSON.stringify(result));
|
|
118
|
+
}
|
|
119
|
+
catch (cause) {
|
|
120
|
+
if (!response.headersSent)
|
|
121
|
+
response.writeHead(400, { "content-type": "application/json" }).end(JSON.stringify({ error: cause instanceof Error ? cause.message : "入口服务调用失败" }));
|
|
122
|
+
}
|
|
123
|
+
})();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (request.url !== "/model") {
|
|
87
127
|
response.writeHead(403).end();
|
|
88
128
|
return;
|
|
89
129
|
}
|
|
@@ -358,7 +398,7 @@ export class ManagedServers {
|
|
|
358
398
|
if (reload && entry.profile.modelTransport === "direct" && relay?.readyState !== WebSocket.OPEN)
|
|
359
399
|
throw new Error("服务端口的模型通道正在连接,请稍后重试");
|
|
360
400
|
if (reload && entry.installation && secret && relay?.readyState === WebSocket.OPEN && entry.profile.serviceUrl) {
|
|
361
|
-
const body = JSON.stringify({ models: await this.gateway.catalog(force), defaultModel: this.defaultModel() });
|
|
401
|
+
const body = JSON.stringify({ models: await this.gateway.catalog(force), defaultModel: this.defaultModel(), entryIntegrations: this.integrations?.available() });
|
|
362
402
|
const hash = createHash("sha256").update(body).digest("hex");
|
|
363
403
|
if (!force && this.syncedRelays.get(relay) === hash)
|
|
364
404
|
return;
|
|
@@ -659,7 +699,26 @@ export class ManagedServers {
|
|
|
659
699
|
if ((state.conversations ?? []).some((conversation) => ["running", "waiting", "awaiting_background"].includes(conversation.status)))
|
|
660
700
|
throw new Error("远端仍有进行中的任务,请完成后再重新部署");
|
|
661
701
|
}
|
|
662
|
-
|
|
702
|
+
let installation = entry.installation;
|
|
703
|
+
let reusable = false;
|
|
704
|
+
if (installation && installation.archiveHash && installation.archiveHash === artifact.shasum) {
|
|
705
|
+
try {
|
|
706
|
+
const files = [posix.join(installation.packageRoot, "dist/server/index.js"), posix.join(installation.packageRoot, "dist/client/index.html"), posix.join(installation.packageRoot, "agents/super-pi-managed-model/index.ts"), installation.piCommand];
|
|
707
|
+
const probe = `import{readFileSync,accessSync}from'node:fs';import{fileURLToPath}from'node:url';const[v,m]=process.versions.node.split('.').map(Number);if(!(v>22||(v===22&&m>=19)))throw Error('Unsupported Node runtime');const pkg=JSON.parse(readFileSync(${JSON.stringify(posix.join(installation.packageRoot, "package.json"))},'utf8'));if(pkg.name!=='@evandu/super-pi-server'||pkg.version!==${JSON.stringify(artifact.version)})throw Error('Unexpected installation');for(const file of ${JSON.stringify(files)})accessSync(file);accessSync(fileURLToPath(import.meta.resolve('@earendil-works/pi-coding-agent')));`;
|
|
708
|
+
await sshExec(client, `cd ${sh(installation.packageRoot)} && ${sh(installation.node)} --input-type=module -e ${sh(probe)}`);
|
|
709
|
+
reusable = true;
|
|
710
|
+
this.progress(entry, "复用已完成的同版本远端安装");
|
|
711
|
+
}
|
|
712
|
+
catch {
|
|
713
|
+
delete installation.archiveHash;
|
|
714
|
+
this.progress(entry, "已有安装不完整,正在修复");
|
|
715
|
+
await this.persist();
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
if (!reusable)
|
|
719
|
+
installation = await installRemote({ client, id, archive: artifact.path, archiveHash: artifact.shasum, cacheDir: join(this.directory, "cache"), progress: (step, output) => this.progress(entry, step, output) });
|
|
720
|
+
if (!installation)
|
|
721
|
+
throw new Error("远端安装未完成");
|
|
663
722
|
entry.installation = installation;
|
|
664
723
|
entry.profile.remoteRoot = installation.root;
|
|
665
724
|
entry.profile.identity ??= randomUUID();
|
|
@@ -5,8 +5,18 @@ export interface RemoteInstallation {
|
|
|
5
5
|
packageRoot: string;
|
|
6
6
|
node: string;
|
|
7
7
|
piCommand: string;
|
|
8
|
+
archiveHash?: string;
|
|
8
9
|
}
|
|
9
10
|
export declare function uploadFile(client: Client, local: string, remote: string): Promise<void>;
|
|
11
|
+
interface NodeDownloadOptions {
|
|
12
|
+
fetch?: typeof fetch;
|
|
13
|
+
fallbackDelayMs?: number;
|
|
14
|
+
progress?: (step: string) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare const NODE_RUNTIME_VERSION = "v22.20.0";
|
|
17
|
+
export declare const NODE_RUNTIME_CHECKSUMS: Readonly<Record<string, string>>;
|
|
18
|
+
export declare function nodeArchive(platform: string, arch: string, directory: string, options?: NodeDownloadOptions): Promise<string>;
|
|
19
|
+
export declare function downloadVerifiedNodeArchive(filename: string, expected: string, directory: string, options?: NodeDownloadOptions): Promise<string>;
|
|
10
20
|
export declare function installRemote(options: {
|
|
11
21
|
client: Client;
|
|
12
22
|
id: string;
|
|
@@ -17,3 +27,4 @@ export declare function installRemote(options: {
|
|
|
17
27
|
}): Promise<RemoteInstallation>;
|
|
18
28
|
export declare function remoteStartScript(installation: RemoteInstallation, port: number, host?: ServiceListenHost): string;
|
|
19
29
|
export declare function startRemote(client: Client, installation: RemoteInstallation, port: number, host?: ServiceListenHost): Promise<void>;
|
|
30
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { mkdir, readFile,
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { mkdir, readFile, open, rename, rm } from "node:fs/promises";
|
|
3
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
3
4
|
import { join, basename, posix } from "node:path";
|
|
4
5
|
import { sh, sshExec, sshSftp, sshWrite } from "./managed-ssh.js";
|
|
5
6
|
import { isServiceListenHost } from "../shared/managed-servers.js";
|
|
@@ -12,30 +13,93 @@ export async function uploadFile(client, local, remote) {
|
|
|
12
13
|
sftp.end();
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
export const NODE_RUNTIME_VERSION = "v22.20.0";
|
|
17
|
+
// Pinned from https://nodejs.org/dist/v22.20.0/SHASUMS256.txt.
|
|
18
|
+
export const NODE_RUNTIME_CHECKSUMS = Object.freeze({
|
|
19
|
+
"darwin-arm64": "cc04a76a09f79290194c0646f48fec40354d88969bec467789a5d55dd097f949",
|
|
20
|
+
"darwin-x64": "00df9c5df3e4ec6848c26b70fb47bf96492f342f4bed6b17f12d99b3a45eeecc",
|
|
21
|
+
"linux-arm64": "4181609e03dcb9880e7e5bf956061ecc0503c77a480c6631d868cb1f65a2c7dd",
|
|
22
|
+
"linux-x64": "eeaccb0378b79406f2208e8b37a62479c70595e20be6b659125eb77dd1ab2a29",
|
|
23
|
+
});
|
|
24
|
+
export async function nodeArchive(platform, arch, directory, options = {}) {
|
|
25
|
+
const expected = NODE_RUNTIME_CHECKSUMS[`${platform}-${arch}`];
|
|
23
26
|
if (!expected)
|
|
24
27
|
throw new Error("Node.js 官方未提供该平台的安装包");
|
|
28
|
+
return downloadVerifiedNodeArchive(`node-${NODE_RUNTIME_VERSION}-${platform}-${arch}.tar.gz`, expected, directory, options);
|
|
29
|
+
}
|
|
30
|
+
export async function downloadVerifiedNodeArchive(filename, expected, directory, options = {}) {
|
|
31
|
+
if (basename(filename) !== filename || !/^node-v\d+\.\d+\.\d+-(linux|darwin)-(x64|arm64)\.tar\.gz$/.test(filename)
|
|
32
|
+
|| !/^[a-f0-9]{64}$/i.test(expected))
|
|
33
|
+
throw new Error("Node.js 安装包或校验值无效");
|
|
34
|
+
expected = expected.toLowerCase();
|
|
35
|
+
const request = options.fetch ?? globalThis.fetch;
|
|
36
|
+
const version = NODE_RUNTIME_VERSION;
|
|
37
|
+
const path = join(directory, filename);
|
|
38
|
+
await mkdir(directory, { recursive: true });
|
|
25
39
|
try {
|
|
26
40
|
const bytes = await readFile(path);
|
|
27
41
|
if (createHash("sha256").update(bytes).digest("hex") === expected)
|
|
28
42
|
return path;
|
|
29
43
|
}
|
|
30
44
|
catch { }
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
45
|
+
const sources = [
|
|
46
|
+
[`https://nodejs.org/dist/${version}/${filename}`, "官方源"],
|
|
47
|
+
[`https://npmmirror.com/mirrors/node/${version}/${filename}`, "备用源 1"],
|
|
48
|
+
[`https://mirrors.huaweicloud.com/nodejs/${version}/${filename}`, "备用源 2"],
|
|
49
|
+
];
|
|
50
|
+
const stop = new AbortController(), temporaries = [];
|
|
51
|
+
const signal = AbortSignal.any([stop.signal, AbortSignal.timeout(10 * 60_000)]);
|
|
52
|
+
const maximum = 150 * 1024 * 1024;
|
|
53
|
+
const downloads = sources.map(async ([url, label], index) => {
|
|
54
|
+
// A slow first source must not consume the entire deployment deadline.
|
|
55
|
+
if (index)
|
|
56
|
+
await delay(index * (options.fallbackDelayMs ?? 15_000), undefined, { signal });
|
|
57
|
+
signal.throwIfAborted();
|
|
58
|
+
options.progress?.(`下载并校验 Node.js · ${label}`);
|
|
59
|
+
const response = await request(url, { signal });
|
|
60
|
+
if (!response.ok || !response.body)
|
|
61
|
+
throw new Error(`Node.js ${label}下载失败(${response.status})`);
|
|
62
|
+
if (Number(response.headers.get("content-length")) > maximum) {
|
|
63
|
+
await response.body.cancel();
|
|
64
|
+
throw new Error("Node.js 安装包超过大小上限");
|
|
65
|
+
}
|
|
66
|
+
const temporary = `${path}.download-${randomUUID()}`;
|
|
67
|
+
temporaries.push(temporary);
|
|
68
|
+
const file = await open(temporary, "wx", 0o600);
|
|
69
|
+
const hash = createHash("sha256");
|
|
70
|
+
let bytes = 0;
|
|
71
|
+
try {
|
|
72
|
+
for await (const chunk of response.body) {
|
|
73
|
+
signal.throwIfAborted();
|
|
74
|
+
bytes += chunk.length;
|
|
75
|
+
if (bytes > maximum)
|
|
76
|
+
throw new Error("Node.js 安装包超过大小上限");
|
|
77
|
+
hash.update(chunk);
|
|
78
|
+
await file.writeFile(chunk);
|
|
79
|
+
}
|
|
80
|
+
if (hash.digest("hex") !== expected.toLowerCase())
|
|
81
|
+
throw new Error("Node.js 安装包校验失败");
|
|
82
|
+
return temporary;
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
await file.close();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
try {
|
|
89
|
+
const verified = await Promise.any(downloads);
|
|
90
|
+
stop.abort();
|
|
91
|
+
await Promise.allSettled(downloads);
|
|
92
|
+
await rename(verified, path);
|
|
93
|
+
return path;
|
|
94
|
+
}
|
|
95
|
+
catch (cause) {
|
|
96
|
+
throw new Error("下载 Node.js 失败:官方源及备用源未返回校验通过的完整文件,请检查入口网络后重试", { cause });
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
stop.abort();
|
|
100
|
+
await Promise.allSettled(downloads);
|
|
101
|
+
await Promise.all(temporaries.map(temporary => rm(temporary, { force: true })));
|
|
102
|
+
}
|
|
39
103
|
}
|
|
40
104
|
export async function installRemote(options) {
|
|
41
105
|
const { client, progress } = options;
|
|
@@ -52,17 +116,24 @@ export async function installRemote(options) {
|
|
|
52
116
|
const root = posix.join(home, ".super-pi", "managed", options.id);
|
|
53
117
|
await sshExec(client, `umask 077; mkdir -p ${sh(root)} ${sh(posix.join(root, "data"))} ${sh(posix.join(root, "agent"))}`);
|
|
54
118
|
let node = "", npm = "";
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
119
|
+
for (const executable of [sh(posix.join(root, "node", "bin", "node")), "node"]) {
|
|
120
|
+
try {
|
|
121
|
+
const found = JSON.parse((await sshExec(client, `${executable} -p 'JSON.stringify({version:process.versions.node,path:process.execPath})'`)).trim());
|
|
122
|
+
const [major, minor] = String(found.version).split(".").map(Number);
|
|
123
|
+
if (!(major > 22 || (major === 22 && minor >= 19)))
|
|
124
|
+
continue;
|
|
125
|
+
const adjacentNpm = posix.join(posix.dirname(found.path), "npm");
|
|
126
|
+
npm = (await sshExec(client, `if [ -x ${sh(adjacentNpm)} ]; then printf '%s' ${sh(adjacentNpm)}; else command -v npm; fi`)).trim();
|
|
127
|
+
if (npm) {
|
|
128
|
+
node = found.path;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch { /* Bootstrap only when neither the private nor login runtime is usable. */ }
|
|
61
133
|
}
|
|
62
|
-
catch { /* A private Node runtime is installed when the login environment lacks a usable one. */ }
|
|
63
134
|
if (!node || !npm) {
|
|
64
135
|
progress("下载并校验 Node.js(仅首次需要)");
|
|
65
|
-
const local = await nodeArchive(platform, arch, options.cacheDir), remote = posix.join(root, basename(local));
|
|
136
|
+
const local = await nodeArchive(platform, arch, options.cacheDir, { progress: step => progress(step) }), remote = posix.join(root, basename(local));
|
|
66
137
|
await uploadFile(client, local, remote);
|
|
67
138
|
const nodeRoot = posix.join(root, "node");
|
|
68
139
|
progress("安装用户目录内的 Node.js,无需管理员权限");
|
|
@@ -74,10 +145,15 @@ export async function installRemote(options) {
|
|
|
74
145
|
progress("上传纯服务安装包");
|
|
75
146
|
const remoteArchive = posix.join(root, "server.tgz");
|
|
76
147
|
await uploadFile(client, options.archive, remoteArchive);
|
|
77
|
-
|
|
148
|
+
// A repair must not depend on npm noticing missing files in an existing package.
|
|
149
|
+
const runtimeTag = createHash("sha256").update(options.archiveHash + randomUUID()).digest("hex").slice(0, 16);
|
|
150
|
+
const runtime = posix.join(root, `runtime-${runtimeTag}`);
|
|
78
151
|
const packageRoot = posix.join(runtime, "node_modules", "@evandu", "super-pi-server");
|
|
152
|
+
const policy = `const{execFileSync}=require('node:child_process');const keys=['ONNXRUNTIME_NODE_INSTALL','ONNXRUNTIME_NODE_INSTALL_CUDA','npm_config_onnxruntime_node_install','npm_config_onnxruntime_node_install_cuda'];const configured=name=>{try{const value=execFileSync(${JSON.stringify(npm)},['config','get',name],{encoding:'utf8',stdio:['ignore','pipe','ignore']}).trim();return value!==''&&value!=='undefined'&&value!=='null';}catch{return false;}};process.stdout.write(keys.some(key=>Boolean(process.env[key]))||configured('onnxruntime-node-install')||configured('onnxruntime-node-install-cuda')?'configured':'cpu');`;
|
|
153
|
+
const mode = (await sshExec(client, `export PATH=${sh(posix.dirname(node))}:"$PATH"; ${sh(node)} -e ${sh(policy)}`)).trim();
|
|
154
|
+
const cpuRuntime = mode === "cpu" ? "ONNXRUNTIME_NODE_INSTALL=skip " : "";
|
|
79
155
|
progress("安装远端服务依赖");
|
|
80
|
-
await sshExec(client, `umask 077; export PATH=${sh(posix.dirname(node))}:"$PATH"; ${sh(npm)} install --prefix ${sh(runtime)} --omit=dev --no-audit --no-fund --fetch-timeout=900000 --fetch-retries=3 ${sh(remoteArchive)}`, { timeout: 20 * 60_000, onOutput: output => progress("安装远端服务依赖", output) });
|
|
156
|
+
await sshExec(client, `umask 077; export PATH=${sh(posix.dirname(node))}:"$PATH"; ${cpuRuntime}${sh(npm)} install --prefix ${sh(runtime)} --omit=dev --no-audit --no-fund --fetch-timeout=900000 --fetch-retries=3 ${sh(remoteArchive)}`, { timeout: 20 * 60_000, onOutput: output => progress("安装远端服务依赖", output) });
|
|
81
157
|
const piCommand = posix.join(root, "pi-managed");
|
|
82
158
|
progress("配置远端 Pi 启动器");
|
|
83
159
|
const resolvePi = `import{fileURLToPath}from'node:url';import{dirname,resolve,join}from'node:path';import{readFileSync,accessSync}from'node:fs';const root=resolve(dirname(fileURLToPath(import.meta.resolve('@earendil-works/pi-coding-agent'))),'..');const bin=JSON.parse(readFileSync(join(root,'package.json'),'utf8')).bin.pi;const cli=resolve(root,bin);accessSync(cli);process.stdout.write(cli);`;
|
|
@@ -86,7 +162,7 @@ export async function installRemote(options) {
|
|
|
86
162
|
throw new Error("远端 Pi 安装不完整,请重试部署");
|
|
87
163
|
const extension = posix.join(packageRoot, "agents", "super-pi-managed-model", "index.ts");
|
|
88
164
|
await sshWrite(client, piCommand, `#!/bin/sh\nexec ${sh(node)} ${sh(piCli)} --extension ${sh(extension)} "$@"\n`, 0o700);
|
|
89
|
-
return { root, packageRoot, node, piCommand };
|
|
165
|
+
return { root, packageRoot, node, piCommand, archiveHash: options.archiveHash };
|
|
90
166
|
}
|
|
91
167
|
export function remoteStartScript(installation, port, host = "127.0.0.1") {
|
|
92
168
|
if (!isServiceListenHost(host) || !Number.isInteger(port) || port < 1 || port > 65535)
|
|
@@ -4,6 +4,45 @@ export type GroupModel = {
|
|
|
4
4
|
modelId: string;
|
|
5
5
|
label: string;
|
|
6
6
|
};
|
|
7
|
+
export type GroupRsiCategory = "division" | "prompt" | "tools" | "mechanism" | "execution";
|
|
8
|
+
export type GroupRsiFinding = {
|
|
9
|
+
id: string;
|
|
10
|
+
category: GroupRsiCategory;
|
|
11
|
+
priority: "high" | "medium" | "low";
|
|
12
|
+
observation: string;
|
|
13
|
+
evidence: {
|
|
14
|
+
messageId: string;
|
|
15
|
+
quote: string;
|
|
16
|
+
}[];
|
|
17
|
+
recommendation: string;
|
|
18
|
+
verification: string;
|
|
19
|
+
applicability: string;
|
|
20
|
+
disposition?: "accepted" | "dismissed";
|
|
21
|
+
feedback?: string;
|
|
22
|
+
};
|
|
23
|
+
export type GroupRsiReport = {
|
|
24
|
+
id: string;
|
|
25
|
+
createdAt: string;
|
|
26
|
+
sourceKey: string;
|
|
27
|
+
observedMessages: number;
|
|
28
|
+
totalMessages: number;
|
|
29
|
+
compressed: boolean;
|
|
30
|
+
summary: string;
|
|
31
|
+
retrospective: string;
|
|
32
|
+
findings: GroupRsiFinding[];
|
|
33
|
+
model?: GroupModel;
|
|
34
|
+
};
|
|
35
|
+
export type GroupRsi = {
|
|
36
|
+
enabled: boolean;
|
|
37
|
+
model?: GroupModel;
|
|
38
|
+
prompt: string;
|
|
39
|
+
status: "idle" | "running" | "completed" | "failed" | "interrupted";
|
|
40
|
+
error?: string;
|
|
41
|
+
startedAt?: string;
|
|
42
|
+
sourceKey?: string;
|
|
43
|
+
reports: GroupRsiReport[];
|
|
44
|
+
pending?: boolean;
|
|
45
|
+
};
|
|
7
46
|
export type GroupModerator = {
|
|
8
47
|
model?: GroupModel;
|
|
9
48
|
prompt: string;
|
|
@@ -128,6 +167,7 @@ export type GroupRoom = GroupIdentity & {
|
|
|
128
167
|
revision: number;
|
|
129
168
|
messages: GroupMessage[];
|
|
130
169
|
cloneRequests?: GroupCloneRequest[];
|
|
170
|
+
rsi?: GroupRsi;
|
|
131
171
|
};
|
|
132
172
|
export type GroupSnapshot = Omit<GroupRoom, "revision"> & {
|
|
133
173
|
revision: string;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"superPi": {
|
|
4
4
|
"managedDirectListener": true
|
|
5
5
|
},
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.274",
|
|
7
7
|
"description": "Web control plane and companion for Pi",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"type": "module",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"node": ">=22.19.0"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
|
+
"postinstall": "node --input-type=module -e \"import('./bin/completion.js').then(m => m.installGlobalCompletion()).catch(() => console.warn('Super Pi shell completion registration could not finish.'))\"",
|
|
40
41
|
"prepack": "node scripts/clean-build.mjs",
|
|
41
42
|
"prepublishOnly": "node scripts/clean-build.mjs && cross-env SUPER_PI_REQUIRE_REAL_PI=1 node scripts/extension-load.test.mjs",
|
|
42
43
|
"dev": "concurrently --kill-others-on-fail \"npm:dev:server\" \"npm:dev:client\"",
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-ZAR1Tu2c.js","assets/rolldown-runtime-XKyaHtl9.js","assets/dist-i79xiXVk.js","assets/dist-D978o95T.js","assets/dist-DlPa5gNa.js","assets/dist-DRBIy9A1.js","assets/dist-BlRuQIg1.js","assets/dist-HXD8sSA4.js","assets/dist-DjI7p99D.js","assets/dist-CZ4PyxQu.js","assets/dist-DGBjhKI9.js","assets/dist-LbeLCeoq.js","assets/dist-D8HpMxmZ.js","assets/dist-Dcww9FSw.js","assets/dist-D5u1uPmZ.js","assets/dist-CxmJXjJI.js","assets/dist-ONdtnupI.js","assets/dist-CQncCwUc.js","assets/dist-3qQVP6l8.js","assets/dist-BvjUKkwy.js","assets/dist-YqmXusLA.js","assets/dist-DxPJ1PN-.js","assets/dist-CfTFp0AF.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{c as t,l as n,n as r,r as i,t as a}from"./index-Bqutm6qV.js";var o=e(n(),1);async function s(e,t){let[{StreamLanguage:n},r]=await Promise.all([i(()=>import(`./dist-ZAR1Tu2c.js`).then(e=>e.d),__vite__mapDeps([0,1,2,3,4])),e()]),a=r[t]??r.default??r;return n.define(a)}var c={cpp:()=>i(()=>import(`./dist-DRBIy9A1.js`).then(e=>e.cpp()),__vite__mapDeps([5,6,2,1,0,3,4])),cc:()=>i(()=>import(`./dist-DRBIy9A1.js`).then(e=>e.cpp()),__vite__mapDeps([5,6,2,1,0,3,4])),cxx:()=>i(()=>import(`./dist-DRBIy9A1.js`).then(e=>e.cpp()),__vite__mapDeps([5,6,2,1,0,3,4])),hpp:()=>i(()=>import(`./dist-DRBIy9A1.js`).then(e=>e.cpp()),__vite__mapDeps([5,6,2,1,0,3,4])),hh:()=>i(()=>import(`./dist-DRBIy9A1.js`).then(e=>e.cpp()),__vite__mapDeps([5,6,2,1,0,3,4])),hxx:()=>i(()=>import(`./dist-DRBIy9A1.js`).then(e=>e.cpp()),__vite__mapDeps([5,6,2,1,0,3,4])),c:()=>i(()=>import(`./dist-DRBIy9A1.js`).then(e=>e.cpp()),__vite__mapDeps([5,6,2,1,0,3,4])),h:()=>i(()=>import(`./dist-DRBIy9A1.js`).then(e=>e.cpp()),__vite__mapDeps([5,6,2,1,0,3,4])),cu:()=>i(()=>import(`./dist-DRBIy9A1.js`).then(e=>e.cpp()),__vite__mapDeps([5,6,2,1,0,3,4])),cuh:()=>i(()=>import(`./dist-DRBIy9A1.js`).then(e=>e.cpp()),__vite__mapDeps([5,6,2,1,0,3,4])),js:()=>i(()=>import(`./dist-HXD8sSA4.js`).then(e=>e.t).then(e=>e.javascript()),__vite__mapDeps([7,1,6,2,0,3,4,8])),jsx:()=>i(()=>import(`./dist-HXD8sSA4.js`).then(e=>e.t).then(e=>e.javascript({jsx:!0})),__vite__mapDeps([7,1,6,2,0,3,4,8])),mjs:()=>i(()=>import(`./dist-HXD8sSA4.js`).then(e=>e.t).then(e=>e.javascript()),__vite__mapDeps([7,1,6,2,0,3,4,8])),cjs:()=>i(()=>import(`./dist-HXD8sSA4.js`).then(e=>e.t).then(e=>e.javascript()),__vite__mapDeps([7,1,6,2,0,3,4,8])),ts:()=>i(()=>import(`./dist-HXD8sSA4.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0})),__vite__mapDeps([7,1,6,2,0,3,4,8])),tsx:()=>i(()=>import(`./dist-HXD8sSA4.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0,jsx:!0})),__vite__mapDeps([7,1,6,2,0,3,4,8])),mts:()=>i(()=>import(`./dist-HXD8sSA4.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0})),__vite__mapDeps([7,1,6,2,0,3,4,8])),cts:()=>i(()=>import(`./dist-HXD8sSA4.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0})),__vite__mapDeps([7,1,6,2,0,3,4,8])),py:()=>i(()=>import(`./dist-CZ4PyxQu.js`).then(e=>e.python()),__vite__mapDeps([9,6,2,1,0,3,4,8])),pyi:()=>i(()=>import(`./dist-CZ4PyxQu.js`).then(e=>e.python()),__vite__mapDeps([9,6,2,1,0,3,4,8])),java:()=>i(()=>import(`./dist-DGBjhKI9.js`).then(e=>e.java()),__vite__mapDeps([10,6,2,1,0,3,4])),php:()=>i(()=>import(`./dist-LbeLCeoq.js`).then(e=>e.php()),__vite__mapDeps([11,6,2,1,12,13,0,3,4,7,8])),sql:()=>i(()=>import(`./dist-D5u1uPmZ.js`).then(e=>e.sql()),__vite__mapDeps([14,0,1,2,3,4,6,8])),yaml:()=>i(()=>import(`./dist-CxmJXjJI.js`).then(e=>e.yaml()),__vite__mapDeps([15,6,2,1,0,3,4])),yml:()=>i(()=>import(`./dist-CxmJXjJI.js`).then(e=>e.yaml()),__vite__mapDeps([15,6,2,1,0,3,4])),xml:()=>i(()=>import(`./dist-ONdtnupI.js`).then(e=>e.xml()),__vite__mapDeps([16,6,2,1,0,3,4])),json:()=>i(()=>import(`./dist-CQncCwUc.js`).then(e=>e.json()),__vite__mapDeps([17,6,2,1,0,3,4])),jsonc:()=>i(()=>import(`./dist-CQncCwUc.js`).then(e=>e.json()),__vite__mapDeps([17,6,2,1,0,3,4])),json5:()=>i(()=>import(`./dist-CQncCwUc.js`).then(e=>e.json()),__vite__mapDeps([17,6,2,1,0,3,4])),html:()=>i(()=>import(`./dist-D8HpMxmZ.js`).then(e=>e.html()),__vite__mapDeps([12,6,2,1,13,0,3,4,7,8])),htm:()=>i(()=>import(`./dist-D8HpMxmZ.js`).then(e=>e.html()),__vite__mapDeps([12,6,2,1,13,0,3,4,7,8])),vue:()=>i(()=>import(`./dist-D8HpMxmZ.js`).then(e=>e.html()),__vite__mapDeps([12,6,2,1,13,0,3,4,7,8])),svelte:()=>i(()=>import(`./dist-D8HpMxmZ.js`).then(e=>e.html()),__vite__mapDeps([12,6,2,1,13,0,3,4,7,8])),css:()=>i(()=>import(`./dist-Dcww9FSw.js`).then(e=>e.r).then(e=>e.css()),__vite__mapDeps([13,1,6,2,0,3,4])),md:()=>i(()=>import(`./dist-3qQVP6l8.js`).then(e=>e.markdown()),__vite__mapDeps([18,3,1,4,0,2,8,12,6,13,7])),markdown:()=>i(()=>import(`./dist-3qQVP6l8.js`).then(e=>e.markdown()),__vite__mapDeps([18,3,1,4,0,2,8,12,6,13,7])),mdx:()=>i(()=>import(`./dist-3qQVP6l8.js`).then(e=>e.markdown()),__vite__mapDeps([18,3,1,4,0,2,8,12,6,13,7])),rs:()=>i(()=>import(`./dist-BvjUKkwy.js`).then(e=>e.rust()),__vite__mapDeps([19,6,2,1,0,3,4])),go:()=>i(()=>import(`./dist-YqmXusLA.js`).then(e=>e.go()),__vite__mapDeps([20,6,2,1,0,3,4,8])),sh:()=>s(()=>i(()=>import(`./shell-DwuoZtxw.js`),[]),`shell`),bash:()=>s(()=>i(()=>import(`./shell-DwuoZtxw.js`),[]),`shell`),zsh:()=>s(()=>i(()=>import(`./shell-DwuoZtxw.js`),[]),`shell`),fish:()=>s(()=>i(()=>import(`./shell-DwuoZtxw.js`),[]),`shell`),ps1:()=>s(()=>i(()=>import(`./powershell-D8WpQPaX.js`),[]),`powershell`),psm1:()=>s(()=>i(()=>import(`./powershell-D8WpQPaX.js`),[]),`powershell`),rb:()=>s(()=>i(()=>import(`./ruby-ChfNwlCY.js`),[]),`ruby`),swift:()=>s(()=>i(()=>import(`./swift-DKB6_1j6.js`),[]),`swift`),toml:()=>s(()=>i(()=>import(`./toml-BPTmHmyx.js`),[]),`toml`),ini:()=>s(()=>i(()=>import(`./properties-C357ku5U.js`),[]),`properties`),cfg:()=>s(()=>i(()=>import(`./properties-C357ku5U.js`),[]),`properties`),conf:()=>s(()=>i(()=>import(`./properties-C357ku5U.js`),[]),`properties`),properties:()=>s(()=>i(()=>import(`./properties-C357ku5U.js`),[]),`properties`),dockerfile:()=>s(()=>i(()=>import(`./dockerfile-BDePf5PZ.js`),[]),`dockerfile`),diff:()=>s(()=>i(()=>import(`./diff-ChtP43wD.js`),[]),`diff`),patch:()=>s(()=>i(()=>import(`./diff-ChtP43wD.js`),[]),`diff`)},l={cpp:`C++`,cc:`C++`,cxx:`C++`,hpp:`C++`,hh:`C++`,hxx:`C++`,cu:`CUDA C++`,cuh:`CUDA C++`,c:`C`,h:`C/C++ Header`,js:`JavaScript`,jsx:`JSX`,mjs:`JavaScript`,cjs:`JavaScript`,ts:`TypeScript`,tsx:`TSX`,mts:`TypeScript`,cts:`TypeScript`,py:`Python`,pyi:`Python Stub`,java:`Java`,php:`PHP`,sql:`SQL`,yaml:`YAML`,yml:`YAML`,xml:`XML`,json:`JSON`,jsonc:`JSON with Comments`,json5:`JSON5`,css:`CSS`,md:`Markdown`,markdown:`Markdown`,mdx:`MDX`,rs:`Rust`,go:`Go`,html:`HTML`,htm:`HTML`,vue:`Vue`,svelte:`Svelte`,sh:`Shell`,bash:`Bash`,zsh:`Zsh`,fish:`Fish`,ps1:`PowerShell`,psm1:`PowerShell`,rb:`Ruby`,swift:`Swift`,toml:`TOML`,ini:`INI`,cfg:`Config`,conf:`Config`,properties:`Properties`,dockerfile:`Dockerfile`,diff:`Diff`,patch:`Patch`};function u(e){return c[e.toLowerCase()]}function d(e){return l[e.toLowerCase()]}var f=t(),p=262144,m=131072;function h(e){return e.split(`.`).pop()?.toLowerCase()??``}function g(e){return getComputedStyle(document.documentElement).getPropertyValue(e).trim()}function _(e,t){return e.HighlightStyle.define([{tag:t.tags.keyword,color:g(`--cm-keyword`)},{tag:t.tags.string,color:g(`--cm-string`)},{tag:t.tags.number,color:g(`--cm-number`)},{tag:t.tags.comment,color:g(`--cm-comment`),fontStyle:`italic`},{tag:t.tags.function(t.tags.variableName),color:g(`--cm-function`)},{tag:t.tags.typeName,color:g(`--cm-type`)},{tag:t.tags.className,color:g(`--cm-type`)},{tag:t.tags.propertyName,color:g(`--cm-property`)},{tag:t.tags.operator,color:g(`--cm-operator`)},{tag:t.tags.variableName,color:g(`--cm-variable`)}])}function v({path:e,value:t,onChange:n,jumpToLine:s,onSave:c,workspaceId:l,blame:g,onPosition:v,readOnly:y=!1}){let b=(0,o.useRef)(null),x=(0,o.useRef)(null),S=(0,o.useRef)(null),C=(0,o.useRef)(null),w=(0,o.useRef)(null),T=(0,o.useRef)(null),E=(0,o.useRef)(null),D=(0,o.useRef)(null),O=(0,o.useRef)(n),k=(0,o.useRef)(c);O.current=n,k.current=c;let[A,j]=(0,o.useState)(!1),[M,N]=(0,o.useState)(!1),[P,F]=(0,o.useState)(`0,0`),[I,L]=(0,o.useState)(0);(0,o.useEffect)(()=>{let n=!1,a,o,s,c,l;return(async()=>{try{let d=h(e),f=u(d),[m,g,v,A,M,P,I,R]=await Promise.all([i(()=>import(`./dist-D978o95T.js`).then(e=>e.S),__vite__mapDeps([3,1])),i(()=>import(`./dist-DlPa5gNa.js`).then(e=>e.s),__vite__mapDeps([4,1,3])),i(()=>import(`./dist-DxPJ1PN-.js`),__vite__mapDeps([21,3,1,4,0,2])),i(()=>import(`./dist-CfTFp0AF.js`),__vite__mapDeps([22,4,1,3])),i(()=>import(`./dist-ZAR1Tu2c.js`).then(e=>e.d),__vite__mapDeps([0,1,2,3,4])),i(()=>import(`./dist-i79xiXVk.js`).then(e=>e.n),__vite__mapDeps([2,1])),f?f().catch(e=>(console.warn(`[CodeMirror] Failed to load language for .${d}:`,e),null)):Promise.resolve(null),r().catch(e=>(console.warn(`[CodeMirror] Failed to build the blame extension:`,e),null))]);if(n||!b.current)return;c=M,l=P,C.current=m.Annotation.define(),w.current=m.Transaction.addToHistory;let z=t.length<=p&&I!==null;o=new m.Compartment;let B=[g.lineNumbers(),g.highlightActiveLine(),g.drawSelection(),v.history(),g.keymap.of([v.indentWithTab,...v.defaultKeymap,...v.historyKeymap,...A.searchKeymap,{key:`Mod-s`,run:()=>(k.current(),!0)}]),g.EditorView.updateListener.of(e=>{e.docChanged&&!(C.current&&e.transactions.some(e=>e.annotation(C.current)===!0))&&O.current(e.state.doc.toString()),e.selectionSet&&F(`${e.state.selection.main.from},${e.state.selection.main.to}`)}),g.EditorView.domEventHandlers({mousedown:(e,t)=>(t.focus(),!1)})];if(y&&B.push(m.EditorState.readOnly.of(!0),g.EditorView.editable.of(!1)),R&&!y&&(s=new m.Compartment,B.splice(1,0,s.of([])),B.push(R.base)),I)try{B.push(I)}catch(e){console.warn(`[CodeMirror] Failed to apply language extension for .${d}:`,e),z=!1}if(z&&o&&c&&l)try{B.push(o.of(c.syntaxHighlighting(_(c,l))))}catch(e){console.warn(`[CodeMirror] Failed to attach syntaxHighlighting for .${d}:`,e),z=!1}if(a=new g.EditorView({state:m.EditorState.create({doc:t,extensions:B}),parent:b.current}),n){a.destroy();return}x.current=a,j(z),N(!0),T.current=R,E.current=s??null,D.current=null,L(e=>e+1);let V=new MutationObserver(()=>{let e=x.current;if(e&&z&&o&&c&&l)try{e.dispatch({effects:o.reconfigure(c.syntaxHighlighting(_(c,l)))})}catch{}});S.current=V,V.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`]})}catch(e){console.error(`[CodeMirror] Fatal editor initialization error:`,e),n||N(!0)}})(),()=>{n=!0,S.current?.disconnect(),S.current=null,a?.destroy(),x.current=null,N(!1),b.current&&(b.current.textContent=``)}},[e,y]),(0,o.useEffect)(()=>{let e=x.current;if(!e)return;let n=e.state.doc.toString();n!==t&&e.dispatch({changes:{from:0,to:n.length,insert:t},annotations:C.current?C.current.of(!0):void 0})},[t]),(0,o.useEffect)(()=>{let e=x.current;if(!e||!s)return;let t=e.state.doc.line(Math.min(Math.max(1,s.line),e.state.doc.lines)),n=Math.min(t.to,t.from+(s.column??1)-1);e.dispatch({selection:{anchor:t.to,head:n},scrollIntoView:!0}),e.focus()},[s,M]);let R=!!(g&&g.state===`ready`&&g.response&&g.path===e&&g.workspaceId===l);(0,o.useEffect)(()=>{let t=x.current,n=T.current,r=E.current;if(!t||!n||!r)return;let i=g&&g.state===`ready`&&g.response&&g.path===e&&g.workspaceId===l?g.response:null,o=i?a(i):null;D.current!==o&&(D.current=o,t.dispatch({effects:[n.setBlame.of(o),r.reconfigure(o?n.gutter:[])]}))},[g?.state,g?.response,g?.path,g?.workspaceId,e,l,I]);let z=x.current?.state.doc.toString()??t,B=z.length<=m?z:z.slice(0,m),V=h(e),H=d(V),U=x.current?.state,W=U?.selection.main.head,G=W===void 0?void 0:U?.doc.lineAt(W),K=G?.number,q=W!==void 0&&G?W-G.from+1:void 0;return(0,o.useEffect)(()=>{M&&K!==void 0&&q!==void 0&&v?.({line:K,column:q,language:A&&H||`纯文本`,highlight:A?V:`plain`})},[M,K,q,A,H,V,v]),(0,o.useEffect)(()=>()=>v?.(),[v]),(0,f.jsxs)(`div`,{className:`file-cm-wrap`,"data-file-text":e,"data-file-content":B,"data-file-content-truncated":z.length>m?`1`:`0`,"data-file-selection":P,"data-file-editor-ready":M?`1`:`0`,"data-file-blame-gutter":R?`1`:void 0,onMouseDown:()=>x.current?.focus(),children:[(0,f.jsx)(`div`,{className:`file-cm`,ref:b,"aria-label":`${y?`查看`:`编辑`} ${e}`}),(!M||!v)&&(0,f.jsxs)(`div`,{className:`file-editor-status`,children:[!M&&(0,f.jsx)(`span`,{"data-file-editor-loading":`1`,children:`正在加载编辑器…`}),M&&W!==void 0&&G&&(0,f.jsxs)(`span`,{children:[`第 `,G.number,` 行,第 `,W-G.from+1,` 列`]}),M&&!A&&(0,f.jsx)(`span`,{"data-file-highlight-status":`plain`,children:`纯文本`}),M&&A&&H&&(0,f.jsx)(`span`,{"data-file-highlight-status":V,children:H})]})]})}export{v as CodeMirrorEditor,u as t,_ as themeHighlightStyle};
|