@evandu/super-pi 0.1.288 → 0.1.289

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 (32) hide show
  1. package/desktop/main.cjs +14 -2
  2. package/desktop/notification-routing.cjs +45 -0
  3. package/desktop/notifications.cjs +1 -1
  4. package/desktop/pet-preload.cjs +11 -0
  5. package/desktop/pet-renderer.js +34 -0
  6. package/desktop/pet.cjs +77 -0
  7. package/desktop/pet.css +26 -0
  8. package/desktop/pet.html +32 -0
  9. package/desktop/preload.cjs +4 -1
  10. package/dist/.super-pi-check-inputs.json +2 -2
  11. package/dist/client/.super-pi-client-sources.json +15 -14
  12. package/dist/client/assets/{CodeMirrorEditor-CWtrW4l8.js → CodeMirrorEditor-BQEK9QVa.js} +1 -1
  13. package/dist/client/assets/{GitDiffEditor-as0g7l10.js → GitDiffEditor-jen_6W68.js} +1 -1
  14. package/dist/client/assets/index-C7o39I4j.js +350 -0
  15. package/dist/client/assets/index-dkbN-Swt.css +1 -0
  16. package/dist/client/index.html +2 -2
  17. package/dist/server/application/catalog-service.js +1 -0
  18. package/dist/server/application/run-service.d.ts +1 -0
  19. package/dist/server/application/run-service.js +26 -1
  20. package/dist/server/command-handler.js +35 -0
  21. package/dist/server/pi-session-pool.d.ts +1 -0
  22. package/dist/server/pi-session-pool.js +1 -0
  23. package/dist/server/pi-session.d.ts +8 -0
  24. package/dist/server/pi-session.js +19 -1
  25. package/dist/server/runtime.d.ts +2 -0
  26. package/dist/server/runtime.js +13 -0
  27. package/dist/server/types.d.ts +3 -0
  28. package/dist/shared/slash-commands.d.ts +7 -0
  29. package/dist/shared/slash-commands.js +18 -0
  30. package/package.json +1 -1
  31. package/dist/client/assets/index-CA58HvxO.css +0 -1
  32. package/dist/client/assets/index-CtgkiwLi.js +0 -350
@@ -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-CtgkiwLi.js"></script>
11
+ <script type="module" crossorigin src="/assets/index-C7o39I4j.js"></script>
12
12
  <link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-XKyaHtl9.js">
13
- <link rel="stylesheet" crossorigin href="/assets/index-CA58HvxO.css">
13
+ <link rel="stylesheet" crossorigin href="/assets/index-dkbN-Swt.css">
14
14
  </head>
15
15
  <body>
16
16
  <div id="root"></div>
@@ -63,6 +63,7 @@ export class CatalogService {
63
63
  * Immediately re-reads agent definitions from disk and broadcasts catalogs.
64
64
  */
65
65
  async rescan() {
66
+ this.promptCatalogs.clear();
66
67
  await Promise.all([
67
68
  this.broadcastAgents(),
68
69
  this.broadcastSubagents(),
@@ -270,6 +270,7 @@ export declare class RunService {
270
270
  conversation: Conversation;
271
271
  cwd: string;
272
272
  }>;
273
+ reloadConversation(conversationId: string): Promise<void>;
273
274
  compactContext(conversationId: string): Promise<void>;
274
275
  cancelCompaction(conversationId: string): Promise<void>;
275
276
  /**
@@ -761,6 +761,31 @@ export class RunService {
761
761
  const { conversation, workspace } = this.turnContext(conversationId);
762
762
  return { conversation, cwd: await resolveSessionCwd(workspace.path, conversation.cwd) };
763
763
  }
764
+ async reloadConversation(conversationId) {
765
+ const { conversation, workspace } = this.turnContext(conversationId);
766
+ this.assertHistoryAvailable(conversationId);
767
+ if (conversation.archivedAt || workspace.closedAt)
768
+ throw new Error("请先恢复会话并打开工作区,再重新加载资源。");
769
+ if (this.activeRuns.has(conversationId) || this.interruptTargets.has(conversationId))
770
+ throw new Error("当前会话正在执行,请结束或停止任务后再重新加载资源。");
771
+ if (!this.runtime.reloadConversation)
772
+ throw new Error("当前运行时不支持资源重载,请升级此服务器。");
773
+ const controller = new AbortController();
774
+ this.claimRunSlot(conversationId, controller, true);
775
+ try {
776
+ const cwd = await resolveSessionCwd(workspace.path, conversation.cwd);
777
+ const file = await this.runtime.reloadConversation(conversation, cwd);
778
+ if (file)
779
+ await this.store.setConversationPiSessionFile(conversationId, file);
780
+ }
781
+ finally {
782
+ this.releaseRunSlot(conversationId, controller);
783
+ this.broadcaster.broadcastState();
784
+ const next = this.store.listWaitingMessages(conversationId).find(message => message.delivery === "waiting");
785
+ if (next)
786
+ setImmediate(() => { void this.processWaitingMessage(conversationId, next.id, { ifIdle: true }).catch(error => console.warn("Super Pi queued message after reload:", describeThrownWithStack(error))); });
787
+ }
788
+ }
764
789
  async compactContext(conversationId) {
765
790
  const { conversation, workspace } = this.turnContext(conversationId);
766
791
  this.assertHistoryAvailable(conversationId);
@@ -2051,7 +2076,7 @@ export class RunService {
2051
2076
  return this.enqueueMessage(conversationId, note, { source: "session-reminder" });
2052
2077
  }
2053
2078
  async enqueueMessage(conversationId, content, { images, attachments, clientId, mode, source, accepted }) {
2054
- const deliveryMode = parseMessageDeliveryMode(mode);
2079
+ const deliveryMode = this.maintenanceRuns.has(conversationId) ? "queue" : parseMessageDeliveryMode(mode);
2055
2080
  this.assertHistoryAvailable(conversationId);
2056
2081
  this.memory?.cancel(conversationId);
2057
2082
  if (source || !isLengthContinuation(content)) {
@@ -2,6 +2,7 @@ import { spawn } from "node:child_process";
2
2
  import { join } from "node:path";
3
3
  import { KNOWN_APIS } from "./providers.js";
4
4
  import { CHILD_SESSION_LOCK_REASON } from "../shared/child-session-lock.js";
5
+ import { parseBuiltinSlashCommand, builtinSlashHint } from "../shared/slash-commands.js";
5
6
  import { claimUpdateSlot, packageUpdateArgs, releaseUpdateSlot, shellArgs } from "./update.js";
6
7
  /**
7
8
  * Routes client commands to appropriate application services and converts results or errors.
@@ -277,6 +278,15 @@ export class CommandHandler {
277
278
  await this.runService.cancelCompaction(command.conversationId);
278
279
  return;
279
280
  }
281
+ if (command.type === "conversation.reload") {
282
+ if (this.conversationService.isReverting(command.conversationId))
283
+ throw new Error("正在回退会话,稍后再重新加载资源。");
284
+ await this.runService.reloadConversation(command.conversationId);
285
+ await this.catalogService.rescan();
286
+ const { conversation } = await this.runService.dispatchContext(command.conversationId);
287
+ await this.catalogService.broadcastPromptCatalog(conversation.workspaceId);
288
+ return;
289
+ }
280
290
  if (command.type === "conversation.thinking") {
281
291
  await this.conversationService.setThinking(command.conversationId, command.level);
282
292
  return;
@@ -315,6 +325,31 @@ export class CommandHandler {
315
325
  if (this.conversationService.isReverting(command.conversationId)) {
316
326
  throw new Error("正在撤回上一条消息,Pi 的历史还没截断完成,请等撤回结束后再发送。");
317
327
  }
328
+ const slash = parseBuiltinSlashCommand(command.content);
329
+ if (slash) {
330
+ if (slash.args || command.images?.length || command.attachments?.length)
331
+ throw new Error(`/${slash.id} 请单独执行,不要附加正文或附件。`);
332
+ if (slash.id === "reload" || slash.id === "compact" || slash.id === "stop") {
333
+ await this.handleCommand({ type: slash.id === "reload" ? "conversation.reload" : slash.id === "compact" ? "conversation.compact" : "run.stop", conversationId: command.conversationId }, sendToSocket, remoteAddress, browserAuthorized);
334
+ }
335
+ else if (slash.id === "new" || slash.id === "clear") {
336
+ const { conversation } = await this.runService.dispatchContext(command.conversationId);
337
+ const result = await this.conversationService.createConversation(conversation.workspaceId, undefined, conversation.cwd);
338
+ accepted();
339
+ return result;
340
+ }
341
+ else if (slash.id === "fork") {
342
+ const result = await this.conversationService.forkConversation(command.conversationId);
343
+ if (!result.ok)
344
+ throw new Error(result.message);
345
+ accepted();
346
+ return result.forkedId;
347
+ }
348
+ else
349
+ throw new Error(`此命令需要工作台交互。${builtinSlashHint(command.content)}`);
350
+ accepted();
351
+ return;
352
+ }
318
353
  // `attachments` was dropped here while the send path grew it, so a message carrying a skill
319
354
  // attachment lost it on arrival - the browser drew the attachment, the transcript never had it, and
320
355
  // the model was handed the bare prompt. Forwarded now because this is the one line that carries
@@ -23,6 +23,7 @@
23
23
  import { type PiSessionFactory, type PiSessionLike } from "./pi-session.js";
24
24
  /** What the pool needs to build a session for a conversation. */
25
25
  export interface SessionRequest {
26
+ refreshResources?: boolean;
26
27
  conversationId: string;
27
28
  cwd: string;
28
29
  /** The recorded transcript locator, verified against the real header before use. */
@@ -206,6 +206,7 @@ export class PiSessionPool {
206
206
  ...(request.sessionFile ? { sessionFile: request.sessionFile } : {}),
207
207
  extensionPaths: superPiExtensionPaths(this.repositoryRoot),
208
208
  skillPaths: superPiSkillPaths(this.repositoryRoot),
209
+ ...(request.refreshResources ? { refreshResources: true } : {}),
209
210
  extensionEnv: request.extensionEnv,
210
211
  ...(request.systemPromptFile ? { systemPromptFile: request.systemPromptFile } : {}),
211
212
  ...(request.systemPromptMode ? { systemPromptMode: request.systemPromptMode } : {}),
@@ -60,6 +60,12 @@ interface PiSdk {
60
60
  extensionFactories?: unknown[];
61
61
  }) => {
62
62
  reload(): Promise<void>;
63
+ getExtensions?(): {
64
+ errors: Array<{
65
+ path: string;
66
+ error: string;
67
+ }>;
68
+ };
63
69
  getPrompts?: () => {
64
70
  prompts: Array<{
65
71
  name: string;
@@ -553,6 +559,8 @@ export interface PiSessionLike {
553
559
  }
554
560
  /** How a session should be built. Everything here is decided once, at creation. */
555
561
  export interface SessionCreation {
562
+ /** Explicit user reload bypasses Pi's cross-session extension factory cache. */
563
+ refreshResources?: boolean;
556
564
  /** The workspace. Pi resolves tools and the session file against it. */
557
565
  cwd: string;
558
566
  /** The session id, which is the Super Pi conversation id. */
@@ -26,7 +26,7 @@
26
26
  import { existsSync, readdirSync, statSync } from "node:fs";
27
27
  import { open, readdir } from "node:fs/promises";
28
28
  import { StringDecoder } from "node:string_decoder";
29
- import { dirname, join, resolve } from "node:path";
29
+ import { basename, dirname, join, resolve } from "node:path";
30
30
  import { createModelResolver } from "./model-context-window.js";
31
31
  import { installProviderProxy, proxyCredentialStore, readProviderProxyEnv, withAuthProxy } from "./provider-proxy.js";
32
32
  import { fetchRemoteModels, KNOWN_APIS } from "./providers.js";
@@ -441,6 +441,24 @@ export async function createPiSession(creation) {
441
441
  ...(creation.thinkingLevel ? { thinkingLevel: creation.thinkingLevel } : {}),
442
442
  };
443
443
  const { session } = await sdk.createAgentSession(options);
444
+ if (creation.refreshResources) {
445
+ // A new loader's first pass may reuse cached extension factories for the same cwd.
446
+ // Pi's public reload performs shutdown cleanup and invalidates that cache on its second pass.
447
+ // Keep both factory passes in the same isolated credential environment.
448
+ const reload = session.reload;
449
+ try {
450
+ if (!reload)
451
+ throw new Error("当前 Pi SDK 不支持资源重新加载,请升级运行时。");
452
+ await withIsolatedSessionEnv({ ...creation.extensionEnv, ...nativeToolEnv(creation.sessionDir, nativePolicy), SUPER_PI_NATIVE_AGENT_DIR: agentDir }, () => reload.call(session));
453
+ const problems = loader.getExtensions?.().errors ?? [];
454
+ if (problems.length)
455
+ throw new Error(`资源重新加载失败:${problems.map(problem => `${basename(problem.path)}: ${problem.error}`).join(";")}`);
456
+ }
457
+ catch (error) {
458
+ session.dispose();
459
+ throw error;
460
+ }
461
+ }
444
462
  traceSession(creation.sessionId, "sdk.session.created", startedAt);
445
463
  const live = session;
446
464
  // THE WHOLE MODEL, LOOKED UP THE WAY PI LOOKS IT UP. Pi's `setModel` puts the model it is given
@@ -304,6 +304,7 @@ export interface AgentRuntime {
304
304
  cacheWarmingSettings?(): Promise<PiCacheWarmingSettings>;
305
305
  setCacheWarming?(mode: PiCacheWarmingMode): Promise<PiCacheWarmingSettings>;
306
306
  reloadNativeTools?(): void;
307
+ reloadConversation?(conversation: Conversation, cwd: string): Promise<string | undefined>;
307
308
  stop?(conversationId: string): Promise<void>;
308
309
  /**
309
310
  * Hands one message to the Pi process that is running RIGHT NOW, to be injected at its next turn
@@ -878,6 +879,7 @@ export declare class PiRpcRuntime implements AgentRuntime {
878
879
  * the old context in memory would keep answering from history the user has withdrawn.
879
880
  */
880
881
  disposeSessions(conversationId?: string): Promise<void>;
882
+ reloadConversation(conversation: Conversation, cwd: string): Promise<string | undefined>;
881
883
  compactContext(input: Pick<AnswerInput, "conversation" | "cwd" | "signal" | "onCompaction" | "onUsage" | "onSessionFile">): Promise<void>;
882
884
  private compactRpcContext;
883
885
  cacheWarmingSettings(): Promise<PiCacheWarmingSettings>;
@@ -597,6 +597,19 @@ export class PiRpcRuntime {
597
597
  await this.sessionPool.disposeAll();
598
598
  await this.backgroundUsageWrites;
599
599
  }
600
+ async reloadConversation(conversation, cwd) {
601
+ // Rebuild through the normal factory to refresh permissions, resources and isolated credentials.
602
+ // The current transcript survives; no prompt or model request is made during this operation.
603
+ const file = this.sessionPool.get(conversation.id)?.sessionFile ?? conversation.piSessionFile;
604
+ await this.disposeSessions(conversation.id);
605
+ if (this.sessionMode !== "sdk")
606
+ return file;
607
+ const configuration = await this.sessionConfiguration(conversation, cwd);
608
+ const session = await this.sessionPool.acquire({ ...configuration, refreshResources: true, conversationId: conversation.id,
609
+ cwd: resolve(cwd), agentId: conversation.agentId ?? null, ...(file ? { sessionFile: file } : {}) });
610
+ this.builtSessions.set(conversation.id, configuration);
611
+ return session.sessionFile;
612
+ }
600
613
  async compactContext(input) {
601
614
  if (this.sessionMode !== "sdk")
602
615
  return this.compactRpcContext(input);
@@ -1692,6 +1692,9 @@ export type ClientCommandBody =
1692
1692
  } | {
1693
1693
  type: "conversation.compact";
1694
1694
  conversationId: string;
1695
+ } | {
1696
+ type: "conversation.reload";
1697
+ conversationId: string;
1695
1698
  } | {
1696
1699
  type: "conversation.compact.cancel";
1697
1700
  conversationId: string;
@@ -0,0 +1,7 @@
1
+ /** Workbench commands share the same UI actions; they are never model prompts. */
2
+ export declare const BUILTIN_SLASH_COMMANDS: readonly [readonly ["help", "打开使用指南"], readonly ["model", "打开模型选择器"], readonly ["settings", "打开设置"], readonly ["clear", "新建空白会话,保留原历史"], readonly ["compact", "压缩上下文并显示进度"], readonly ["reload", "重新加载 Agent、技能和扩展,无需重启服务"], readonly ["new", "在当前目录新建会话"], readonly ["fork", "从当前上下文分叉会话"], readonly ["resume", "打开会话列表"], readonly ["stop", "停止当前任务"], readonly ["start", "在浏览器打开 Super Pi"], readonly ["restart", "重启服务(需要确认)"], readonly ["update", "打开软件更新面板"]];
3
+ export declare function parseBuiltinSlashCommand(text: string): {
4
+ id: typeof BUILTIN_SLASH_COMMANDS[number][0];
5
+ args: string;
6
+ } | undefined;
7
+ export declare function builtinSlashHint(text: string): string | undefined;
@@ -0,0 +1,18 @@
1
+ /** Workbench commands share the same UI actions; they are never model prompts. */
2
+ export const BUILTIN_SLASH_COMMANDS = [
3
+ ["help", "打开使用指南"], ["model", "打开模型选择器"], ["settings", "打开设置"],
4
+ ["clear", "新建空白会话,保留原历史"], ["compact", "压缩上下文并显示进度"],
5
+ ["reload", "重新加载 Agent、技能和扩展,无需重启服务"], ["new", "在当前目录新建会话"],
6
+ ["fork", "从当前上下文分叉会话"], ["resume", "打开会话列表"], ["stop", "停止当前任务"],
7
+ ["start", "在浏览器打开 Super Pi"], ["restart", "重启服务(需要确认)"], ["update", "打开软件更新面板"],
8
+ ];
9
+ export function parseBuiltinSlashCommand(text) {
10
+ const match = /^\/([\w-]+)(?:\s+([\s\S]*))?$/.exec(text.trim());
11
+ const entry = match && BUILTIN_SLASH_COMMANDS.find(([id]) => id === match[1]);
12
+ return entry ? { id: entry[0], args: match[2]?.trim() ?? "" } : undefined;
13
+ }
14
+ export function builtinSlashHint(text) {
15
+ const command = parseBuiltinSlashCommand(text);
16
+ const entry = command && BUILTIN_SLASH_COMMANDS.find(([id]) => id === command.id);
17
+ return entry?.[1];
18
+ }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "superPi": {
4
4
  "managedDirectListener": true
5
5
  },
6
- "version": "0.1.288",
6
+ "version": "0.1.289",
7
7
  "description": "Web control plane and companion for Pi",
8
8
  "license": "MIT",
9
9
  "type": "module",