@evandu/super-pi 0.1.260 → 0.1.262

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.
Files changed (33) hide show
  1. package/desktop/brand.svg +6 -0
  2. package/desktop/icon.png +0 -0
  3. package/desktop/main.cjs +16 -4
  4. package/desktop/preload.cjs +19 -0
  5. package/desktop/tray-icon.png +0 -0
  6. package/desktop/tray-icon@2x.png +0 -0
  7. package/desktop/tray.svg +1 -0
  8. package/dist/client/.super-pi-client-sources.json +19 -14
  9. package/dist/client/assets/{CodeMirrorEditor-mi9rGUce.js → CodeMirrorEditor-DRcRXwhV.js} +1 -1
  10. package/dist/client/assets/{GitDiffEditor-FQBfGxOY.js → GitDiffEditor-Cm0JVvdZ.js} +1 -1
  11. package/dist/client/assets/index-BZd7RTFi.js +350 -0
  12. package/dist/client/assets/index-DHTKUM97.css +1 -0
  13. package/dist/client/favicon.ico +0 -0
  14. package/dist/client/favicon.png +0 -0
  15. package/dist/client/favicon.svg +5 -9
  16. package/dist/client/index.html +2 -2
  17. package/dist/server/application/group-chat-service.d.ts +3 -0
  18. package/dist/server/application/group-chat-service.js +24 -6
  19. package/dist/server/existing-service.d.ts +12 -0
  20. package/dist/server/existing-service.js +18 -0
  21. package/dist/server/managed-http-tunnel.d.ts +2 -2
  22. package/dist/server/managed-http-tunnel.js +7 -5
  23. package/dist/server/managed-http.js +6 -2
  24. package/dist/server/managed-servers.d.ts +46 -3
  25. package/dist/server/managed-servers.js +194 -19
  26. package/dist/server/managed-ssh.d.ts +14 -1
  27. package/dist/server/managed-ssh.js +55 -5
  28. package/dist/shared/group-chat.d.ts +3 -0
  29. package/dist/shared/group-chat.js +7 -0
  30. package/dist/shared/managed-servers.d.ts +23 -2
  31. package/package.json +5 -1
  32. package/dist/client/assets/index-Cn7hdrDw.js +0 -350
  33. package/dist/client/assets/index-UfzqdECL.css +0 -1
Binary file
Binary file
@@ -1,10 +1,6 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64">
2
- <defs>
3
- <linearGradient id="orbGrad" x1="0%" y1="0%" x2="100%" y2="100%">
4
- <stop offset="0%" stop-color="#9cb4d9" />
5
- <stop offset="100%" stop-color="#8fb4e8" />
6
- </linearGradient>
7
- </defs>
8
- <rect width="64" height="64" rx="20" ry="20" fill="url(#orbGrad)" />
9
- <text x="32" y="43" text-anchor="middle" font-family="Georgia, 'Times New Roman', serif" font-weight="bold" font-size="44" fill="#05070c">π</text>
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" style="--brand-start:#526ff5;--brand-end:#6844ce;--brand-mark:#ffffff;--brand-edge:#ffffff">
2
+ <defs><linearGradient id="brand" x1="0" y1="0" x2="1" y2="1"><stop stop-color="var(--brand-start)"/><stop offset="1" stop-color="var(--brand-end)"/></linearGradient></defs>
3
+ <rect x="16" y="16" width="224" height="224" rx="52" fill="url(#brand)"/>
4
+ <rect x="17" y="17" width="222" height="222" rx="51" fill="none" stroke="var(--brand-edge)" stroke-opacity=".16" stroke-width="2"/>
5
+ <g fill="none" stroke="var(--brand-mark)" stroke-width="16" stroke-linecap="round" stroke-linejoin="round"><path d="M66 86h124"/><path d="M103 88v49c0 19-5 34-15 47"/><path d="M158 88v69c0 16 8 23 23 23h5"/></g>
10
6
  </svg>
@@ -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-Cn7hdrDw.js"></script>
11
+ <script type="module" crossorigin src="/assets/index-BZd7RTFi.js"></script>
12
12
  <link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-XKyaHtl9.js">
13
- <link rel="stylesheet" crossorigin href="/assets/index-UfzqdECL.css">
13
+ <link rel="stylesheet" crossorigin href="/assets/index-DHTKUM97.css">
14
14
  </head>
15
15
  <body>
16
16
  <div id="root"></div>
@@ -35,9 +35,11 @@ export declare class GroupChatService {
35
35
  deleteArchived(workspaceId: string, id: string): Promise<void>;
36
36
  private moderator;
37
37
  private resolveMembers;
38
+ private memberModels;
38
39
  create(workspaceId: string, input: {
39
40
  title?: unknown;
40
41
  memberIds?: unknown;
42
+ memberModels?: unknown;
41
43
  moderator?: {
42
44
  model?: unknown;
43
45
  prompt?: unknown;
@@ -52,6 +54,7 @@ export declare class GroupChatService {
52
54
  model?: unknown;
53
55
  prompt?: unknown;
54
56
  memberIds?: unknown;
57
+ memberModels?: unknown;
55
58
  cloneLimit?: unknown;
56
59
  }): Promise<GroupSnapshot>;
57
60
  send(workspaceId: string, id: string, input: {
@@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";
2
2
  import { open, readFile, realpath, writeFile } from "node:fs/promises";
3
3
  import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
4
4
  import { createGitWorktree } from "../git.js";
5
- import { DEFAULT_GROUP_MEMBER_IDS } from "../../shared/group-chat.js";
5
+ import { DEFAULT_GROUP_MEMBER_IDS, groupTimeline } from "../../shared/group-chat.js";
6
6
  import { CODING_STANDARD_REQUEST } from "../active-memory.js";
7
7
  import { applicableRules, assertModelAllowed } from "../model-filter.js";
8
8
  import { replaceFile } from "../persistence/rename.js";
@@ -350,13 +350,29 @@ export class GroupChatService {
350
350
  return { id: agent.id, name: agent.name, description: agent.description };
351
351
  }));
352
352
  }
353
+ async memberModels(workspaceId, members, input) {
354
+ if (input === undefined)
355
+ return members;
356
+ if (!input || typeof input !== "object" || Array.isArray(input))
357
+ throw new Error("成员模型设置无效。");
358
+ const entries = Object.entries(input);
359
+ if (entries.some(([id]) => !members.some(member => member.id === id)))
360
+ throw new Error("模型设置包含不在群内的成员。");
361
+ return Promise.all(members.map(async (member) => {
362
+ const entry = entries.find(([id]) => id === member.id);
363
+ if (!entry)
364
+ return member;
365
+ const model = entry[1] == null ? undefined : (await this.moderator(workspaceId, { model: entry[1] })).model;
366
+ return { ...member, model };
367
+ }));
368
+ }
353
369
  async create(workspaceId, input) {
354
370
  this.workspace(workspaceId);
355
371
  const title = inputText(input.title, 100, "群名");
356
372
  if (!title)
357
373
  throw new Error("请输入群名。");
358
374
  const id = randomUUID();
359
- const members = await this.resolveMembers(id, input.memberIds ?? DEFAULT_GROUP_MEMBER_IDS);
375
+ const members = await this.memberModels(workspaceId, await this.resolveMembers(id, input.memberIds ?? DEFAULT_GROUP_MEMBER_IDS), input.memberModels);
360
376
  const moderator = await this.moderator(workspaceId, input.moderator ?? {});
361
377
  const room = { id, workspaceId, title, updatedAt: timestamp(), revision: 0, members, moderator, messages: [] };
362
378
  await this.edit(rooms => { rooms.push(room); });
@@ -418,7 +434,8 @@ export class GroupChatService {
418
434
  async configure(workspaceId, id, input) {
419
435
  const current = this.activeRoom(this.rooms, workspaceId, id);
420
436
  const moderator = await this.moderator(workspaceId, input);
421
- const members = input.memberIds === undefined ? undefined : await this.resolveMembers(id, input.memberIds, current.members);
437
+ const members = input.memberIds === undefined && input.memberModels === undefined ? undefined
438
+ : await this.memberModels(workspaceId, input.memberIds === undefined ? current.members : await this.resolveMembers(id, input.memberIds, current.members), input.memberModels);
422
439
  await this.edit(rooms => {
423
440
  const room = this.activeRoom(rooms, workspaceId, id);
424
441
  if (members) {
@@ -723,8 +740,9 @@ export class GroupChatService {
723
740
  const topicIndex = room.messages.findIndex(post => post.id === topic.id);
724
741
  const previous = room.messages.slice(0, topicIndex).filter(post => post.role === "user" && post.status !== "cancelled");
725
742
  const topicIds = new Set(previous.map(post => post.id));
726
- const current = room.messages.filter(post => post.role === "assistant" && post.topicId === topic.id && post.status === "completed").slice(-CONTEXT_MESSAGES);
727
- const roomHistory = room.messages.filter(post => post.role === "assistant" ? topicIds.has(post.topicId) && post.status === "completed" : topicIds.has(post.id));
743
+ const timeline = groupTimeline(room.messages);
744
+ const current = timeline.filter(post => post.role === "assistant" && post.topicId === topic.id && post.status === "completed").slice(-CONTEXT_MESSAGES);
745
+ const roomHistory = timeline.filter(post => post.role === "assistant" ? topicIds.has(post.topicId) && post.status === "completed" : topicIds.has(post.id));
728
746
  const remaining = CONTEXT_MESSAGES - current.length;
729
747
  return [...(remaining ? roomHistory.slice(-remaining) : []), ...current].map(post => ({
730
748
  id: post.id, author: post.role === "user" ? "用户" : post.memberName ?? room.members.find(member => member.id === post.memberId)?.name,
@@ -893,7 +911,7 @@ export class GroupChatService {
893
911
  ].join("\n");
894
912
  const answer = await this.complete(started, {
895
913
  prompt: `群内身份:${member?.name ?? agent.name}。${member?.worktreePath ? "你在独立工作树工作;报告分支和产物供后续审查整合。" : ""}\n${prompt}`, cwd: member?.worktreePath,
896
- agent, model: agent.model && { ...agent.model, label: agent.model.modelId }, signal: memberSignal, timeoutMs: 15 * 60_000,
914
+ agent, model: member?.model ?? (agent.model && { ...agent.model, label: agent.model.modelId }), signal: memberSignal, timeoutMs: 15 * 60_000,
897
915
  onToolStart: goBackground,
898
916
  onExecution: event => {
899
917
  if (memberSignal.aborted || !execution.record(event))
@@ -0,0 +1,12 @@
1
+ import type { Client } from "ssh2";
2
+ export interface ExistingInstallation {
3
+ node: string;
4
+ cli: string;
5
+ packageName: string;
6
+ version: string;
7
+ dataDir: string;
8
+ hasData: boolean;
9
+ port?: number;
10
+ }
11
+ /** Read-only discovery; never invoke an old CLI with a flag that might start a daemon. */
12
+ export declare function discoverExistingInstallation(client: Client): Promise<ExistingInstallation | undefined>;
@@ -0,0 +1,18 @@
1
+ import { sh, sshExec } from "./managed-ssh.js";
2
+ /** Read-only discovery; never invoke an old CLI with a flag that might start a daemon. */
3
+ export async function discoverExistingInstallation(client) {
4
+ const script = `const fs=require('fs'),p=require('path'),os=require('os');const home=os.homedir(),dataDir=p.join(home,'.super-pi');const exists=x=>{try{return fs.statSync(x).isFile()}catch{return false}};const candidates=[p.join(home,'.npm-global/bin/super_pi'),p.join(home,'.local/bin/super_pi'),'/opt/homebrew/bin/super_pi','/usr/local/bin/super_pi','/usr/bin/super_pi'];try{for(const value of require('child_process').execFileSync('which',['super_pi'],{encoding:'utf8'}).trim().split('\\n'))candidates.unshift(value)}catch{};const roots=[p.join(home,'.pi/agent/npm/node_modules/@evandu/super-pi'),p.join(home,'.npm-global/lib/node_modules/@evandu/super-pi'),p.join(home,'.local/lib/node_modules/@evandu/super-pi'),'/opt/homebrew/lib/node_modules/@evandu/super-pi','/usr/local/lib/node_modules/@evandu/super-pi','/usr/lib/node_modules/@evandu/super-pi'];for(const cli of candidates){try{roots.unshift(p.resolve(fs.realpathSync(cli),'../..'))}catch{}};let config={};try{config=JSON.parse(fs.readFileSync(p.join(dataDir,'config.json'),'utf8'))}catch{};for(const root of roots){try{const pkg=JSON.parse(fs.readFileSync(p.join(root,'package.json'),'utf8'));if(!['@evandu/super-pi','@evandu/super-pi-server'].includes(pkg.name)||!exists(p.join(root,'bin/super-pi.js')))continue;console.log(JSON.stringify({node:process.execPath,cli:p.join(root,'bin/super-pi.js'),packageName:pkg.name,version:String(pkg.version),dataDir,hasData:exists(p.join(dataDir,'state.json')),port:Number.isInteger(config.port)?config.port:undefined}));process.exit(0)}catch{}};if(exists(p.join(dataDir,'state.json')))console.log(JSON.stringify({node:process.execPath,cli:'',packageName:'',version:'',dataDir,hasData:true}));`;
5
+ try {
6
+ const command = `for candidate in "$(command -v node 2>/dev/null || true)" /opt/homebrew/bin/node /usr/local/bin/node "$HOME"/.nvm/versions/node/*/bin/node; do if [ -n "$candidate" ] && [ -x "$candidate" ]; then "$candidate" -e ${sh(script)}; exit; fi; done`;
7
+ const text = (await sshExec(client, command, { timeout: 8000 })).trim();
8
+ if (!text)
9
+ return;
10
+ const value = JSON.parse(text);
11
+ if (!value.node?.startsWith("/") || !value.dataDir?.startsWith("/") || (value.cli && !value.cli.startsWith("/")) || /[\r\n\0]/.test(`${value.node}${value.dataDir}${value.cli}`))
12
+ return;
13
+ return value;
14
+ }
15
+ catch {
16
+ return;
17
+ }
18
+ }
@@ -2,5 +2,5 @@ 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
  export declare function tunnelJson(client: Client, port: number, path: string, key: string, method?: string): Promise<any>;
5
- export declare function proxyThroughSsh(client: Client, port: number, key: string, path: string, request: IncomingMessage, response: ServerResponse, basePath?: string): void;
6
- export declare function proxyWebSocketThroughSsh(client: Client, port: number, key: string, path: string, request: IncomingMessage, socket: Duplex, head: Buffer): Promise<void>;
5
+ export declare function proxyThroughSsh(client: Client, port: number, key: string, path: string, request: IncomingMessage, response: ServerResponse, basePath?: string, sameOrigin?: boolean): void;
6
+ export declare function proxyWebSocketThroughSsh(client: Client, port: number, key: string, path: string, request: IncomingMessage, socket: Duplex, head: Buffer, sameOrigin?: boolean): Promise<void>;
@@ -1,10 +1,12 @@
1
1
  import { request as httpRequest, Agent } from "node:http";
2
2
  import { sshForward } from "./managed-ssh.js";
3
- function headers(input, port, key) {
3
+ function headers(input, port, key, sameOrigin = false) {
4
4
  const next = { ...input, host: `127.0.0.1:${port}`, authorization: `Bearer ${key}` };
5
5
  delete next.cookie;
6
6
  // Only an upstream owner credential travels through the private SSH channel.
7
7
  delete next["sec-websocket-protocol"];
8
+ if (sameOrigin)
9
+ next.origin = `http://127.0.0.1:${port}`;
8
10
  return next;
9
11
  }
10
12
  function agentFor(client, port) {
@@ -44,9 +46,9 @@ export async function tunnelJson(client, port, path, key, method = "GET") {
44
46
  request.end();
45
47
  });
46
48
  }
47
- export function proxyThroughSsh(client, port, key, path, request, response, basePath = "") {
49
+ export function proxyThroughSsh(client, port, key, path, request, response, basePath = "", sameOrigin = false) {
48
50
  const agent = agentFor(client, port);
49
- const upstream = httpRequest({ hostname: "127.0.0.1", port, method: request.method, path, headers: headers(request.headers, port, key), agent }, result => {
51
+ const upstream = httpRequest({ hostname: "127.0.0.1", port, method: request.method, path, headers: headers(request.headers, port, key, sameOrigin), agent }, result => {
50
52
  const outgoing = { ...result.headers };
51
53
  delete outgoing["set-cookie"];
52
54
  // The trusted artifact wrapper uses an origin-root URL; keep its inner frame on this backend.
@@ -70,9 +72,9 @@ export function proxyThroughSsh(client, port, key, path, request, response, base
70
72
  response.once("close", () => { upstream.destroy(); agent.destroy(); });
71
73
  request.pipe(upstream);
72
74
  }
73
- export async function proxyWebSocketThroughSsh(client, port, key, path, request, socket, head) {
75
+ export async function proxyWebSocketThroughSsh(client, port, key, path, request, socket, head, sameOrigin = false) {
74
76
  const channel = await sshForward(client, port);
75
- const outgoing = headers(request.headers, port, key);
77
+ const outgoing = headers(request.headers, port, key, sameOrigin);
76
78
  channel.write(`GET ${path} HTTP/1.1\r\n${Object.entries(outgoing).filter(([, value]) => value !== undefined).map(([name, value]) => `${name}: ${Array.isArray(value) ? value.join(", ") : value}`).join("\r\n")}\r\n\r\n`);
77
79
  if (head.length)
78
80
  channel.write(head);
@@ -65,10 +65,14 @@ export async function handleManagedHttp(context, request, response, url) {
65
65
  await context.managedServers.save(body.profile);
66
66
  }
67
67
  else if (body.action === "trust")
68
- await context.managedServers.trust(body.id, body.fingerprint);
68
+ await context.managedServers.trust(body.id, body.fingerprint, true);
69
+ else if (body.action === "answerVerification")
70
+ context.managedServers.answerVerification(body.id, body.verificationId, body.answers);
71
+ else if (body.action === "cancelVerification")
72
+ await context.managedServers.cancelVerification(body.id, body.verificationId);
69
73
  else if (body.action === "syncAll") {
70
74
  for (const profile of context.managedServers.list())
71
- if (profile.enabled && profile.service === "online")
75
+ if (profile.enabled && profile.service === "online" && !profile.existingService?.attached)
72
76
  await context.managedServers.action(profile.id, "sync");
73
77
  }
74
78
  else {
@@ -1,7 +1,7 @@
1
1
  import { type IncomingMessage, type ServerResponse } from "node:http";
2
2
  import type { Duplex } from "node:stream";
3
3
  import type { Client } from "ssh2";
4
- import type { ManagedServerInput, ManagedServerProfile } from "../shared/managed-servers.js";
4
+ import type { ManagedServerInput, ManagedServerProfile, SshVerification } from "../shared/managed-servers.js";
5
5
  export declare class ManagedServers {
6
6
  private readonly directory;
7
7
  private readonly packageRoot;
@@ -10,6 +10,9 @@ export declare class ManagedServers {
10
10
  private readonly clients;
11
11
  private readonly secrets;
12
12
  private readonly connecting;
13
+ private readonly pendingConnections;
14
+ private readonly verifications;
15
+ private readonly authBlocked;
13
16
  private readonly jobs;
14
17
  private readonly recoveries;
15
18
  private readonly vault;
@@ -25,15 +28,54 @@ export declare class ManagedServers {
25
28
  modelId: string;
26
29
  } | undefined);
27
30
  initialize(): Promise<void>;
28
- list(): ManagedServerProfile[];
31
+ list(): {
32
+ id: string;
33
+ name: string;
34
+ host: string;
35
+ sshPort: number;
36
+ username: string;
37
+ servicePort: number;
38
+ authentication: "agent" | "password" | "privateKey";
39
+ identityFile?: string;
40
+ fingerprint?: string;
41
+ observedFingerprint?: string;
42
+ enabled: boolean;
43
+ identity?: string;
44
+ deployedAt?: string;
45
+ remoteRoot?: string;
46
+ ssh: "offline" | "connecting" | "online" | "needsTrust" | "awaitingVerification";
47
+ service: "unknown" | "offline" | "online";
48
+ modelChannel: "offline" | "online";
49
+ phase: "idle" | "connecting" | "needsTrust" | "awaitingVerification" | "deploying" | "ready" | "failed";
50
+ existingService?: {
51
+ running: boolean;
52
+ attached: boolean;
53
+ version?: string;
54
+ dataDirectory?: string;
55
+ hasData?: boolean;
56
+ canStart?: boolean;
57
+ requiresToken?: boolean;
58
+ };
59
+ step?: string;
60
+ error?: string;
61
+ log?: string[];
62
+ verification: SshVerification | undefined;
63
+ }[];
64
+ private cancelConnection;
65
+ private startConnection;
66
+ answerVerification(id: string, verificationId: string, answers: unknown): void;
67
+ cancelVerification(id: string, verificationId: string): Promise<void>;
29
68
  private persist;
30
69
  private entry;
31
70
  save(input: ManagedServerInput): Promise<ManagedServerProfile>;
32
- trust(id: string, fingerprint: string): Promise<ManagedServerProfile>;
71
+ trust(id: string, fingerprint: string, background?: boolean): Promise<ManagedServerProfile>;
33
72
  connect(id: string): Promise<Client>;
73
+ private openConnection;
34
74
  private reverseModelChannel;
35
75
  syncModels(id: string, force?: boolean): Promise<void>;
36
76
  private health;
77
+ private detectExisting;
78
+ private startExisting;
37
79
  private ensureService;
38
80
  private progress;
39
81
  deploy(id: string): ManagedServerProfile;
@@ -43,6 +85,7 @@ export declare class ManagedServers {
43
85
  id: string;
44
86
  managedId: string;
45
87
  managed: boolean;
88
+ legacy: boolean;
46
89
  name: string;
47
90
  url: string;
48
91
  enabled: boolean;