@evandu/super-pi 0.1.284 → 0.1.286
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/dist/client/.super-pi-client-sources.json +12 -11
- package/dist/client/assets/{CodeMirrorEditor-6_hCAYhn.js → CodeMirrorEditor-C11ZGQn8.js} +1 -1
- package/dist/client/assets/{GitDiffEditor-VvD8axSx.js → GitDiffEditor-Bo5t2e1b.js} +1 -1
- package/dist/client/assets/index-BDvXKGtD.css +1 -0
- package/dist/client/assets/index-DeiYOY_X.js +350 -0
- package/dist/client/index.html +2 -2
- package/dist/server/application/run-service.d.ts +3 -1
- package/dist/server/application/run-service.js +14 -0
- package/dist/server/explicit-file-open.js +4 -6
- package/dist/server/git.d.ts +1 -1
- package/dist/server/git.js +5 -2
- package/dist/server/group-primary-executor.js +2 -2
- package/dist/server/http-server.js +1 -1
- package/dist/server/runtime.d.ts +2 -0
- package/dist/server/runtime.js +7 -2
- package/dist/server/workspace-file-operations.d.ts +1 -0
- package/dist/server/workspace-file-operations.js +29 -2
- package/package.json +2 -1
- package/dist/.super-pi-check-inputs.json +0 -4
- package/dist/client/assets/index-CMb8f0dS.css +0 -1
- package/dist/client/assets/index-IafH0r-m.js +0 -350
package/dist/client/index.html
CHANGED
|
@@ -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-
|
|
11
|
+
<script type="module" crossorigin src="/assets/index-DeiYOY_X.js"></script>
|
|
12
12
|
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-XKyaHtl9.js">
|
|
13
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
13
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BDvXKGtD.css">
|
|
14
14
|
</head>
|
|
15
15
|
<body>
|
|
16
16
|
<div id="root"></div>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Store } from "../store.js";
|
|
2
2
|
import { type AgentRuntime, type IsolatedExecutionEvent } from "../runtime.js";
|
|
3
3
|
import type { SubagentRunRecorder } from "../subagent-runs.js";
|
|
4
|
-
import type { Conversation, Message, MessageDeliveryMode, MessageImage, PiQueueSnapshot, QuestionAnswer, Workspace } from "../types.js";
|
|
4
|
+
import type { Conversation, Message, MessageDeliveryMode, MessageImage, ModelSelection, PiQueueSnapshot, QuestionAnswer, Workspace } from "../types.js";
|
|
5
5
|
import type { EventBroadcaster } from "../server-context.js";
|
|
6
6
|
import type { ExtensionUiService } from "./extension-ui-service.js";
|
|
7
7
|
import type { WorkflowEngine } from "../workflow-engine.js";
|
|
@@ -68,6 +68,8 @@ export declare class RunService {
|
|
|
68
68
|
private readonly extensionUiService;
|
|
69
69
|
private agentsDir;
|
|
70
70
|
private readonly workflows;
|
|
71
|
+
private readonly modelObservers;
|
|
72
|
+
observeModel(conversationId: string, observer: (model: ModelSelection) => void | Promise<void>): () => void;
|
|
71
73
|
private readonly executionObservers;
|
|
72
74
|
observeExecution(conversationId: string, observer: (event: IsolatedExecutionEvent) => void): () => void;
|
|
73
75
|
private emitExecution;
|
|
@@ -145,6 +145,14 @@ export class RunService {
|
|
|
145
145
|
extensionUiService;
|
|
146
146
|
agentsDir;
|
|
147
147
|
workflows;
|
|
148
|
+
modelObservers = new Map();
|
|
149
|
+
observeModel(conversationId, observer) {
|
|
150
|
+
const observers = this.modelObservers.get(conversationId) ?? new Set();
|
|
151
|
+
observers.add(observer);
|
|
152
|
+
this.modelObservers.set(conversationId, observers);
|
|
153
|
+
return () => { observers.delete(observer); if (!observers.size)
|
|
154
|
+
this.modelObservers.delete(conversationId); };
|
|
155
|
+
}
|
|
148
156
|
executionObservers = new Map();
|
|
149
157
|
observeExecution(conversationId, observer) {
|
|
150
158
|
const observers = this.executionObservers.get(conversationId) ?? new Set();
|
|
@@ -1656,6 +1664,12 @@ export class RunService {
|
|
|
1656
1664
|
if (acceptsEvent("transcript.file", true))
|
|
1657
1665
|
await this.store.setConversationPiSessionFile(conversation.id, path);
|
|
1658
1666
|
},
|
|
1667
|
+
onModel: async (model) => {
|
|
1668
|
+
if (!acceptsEvent("model", true))
|
|
1669
|
+
return;
|
|
1670
|
+
for (const observer of this.modelObservers.get(conversation.id) ?? [])
|
|
1671
|
+
await observer(model);
|
|
1672
|
+
},
|
|
1659
1673
|
onUsage: async (readout) => {
|
|
1660
1674
|
if (acceptsEvent("usage", true))
|
|
1661
1675
|
await this.store.recordConversationUsage(conversation.id, readout);
|
|
@@ -23,13 +23,10 @@ async function selectedFile(workspace, root, input) {
|
|
|
23
23
|
const name = posix.basename(relative);
|
|
24
24
|
if (!name || name === "." || name === "..")
|
|
25
25
|
throw new FilesError(400, "请选择一个文件。", "not_a_file");
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
if (explorerInternalPath(toRelative(workspace, file))) {
|
|
26
|
+
const file = resolve(root, relative);
|
|
27
|
+
if (contains(resolve(workspace), file) && explorerInternalPath(toRelative(workspace, file))) {
|
|
29
28
|
throw new FilesError(403, "不能直接访问应用的回收目录。", "protected_path");
|
|
30
29
|
}
|
|
31
|
-
if (!(await lstat(file)).isSymbolicLink())
|
|
32
|
-
await explorerPath(workspace, root, relative);
|
|
33
30
|
return file;
|
|
34
31
|
}
|
|
35
32
|
async function readOpenedFile(path) {
|
|
@@ -78,7 +75,8 @@ export function createExplicitFileOpen() {
|
|
|
78
75
|
if (contains(canonicalRoot, path)) {
|
|
79
76
|
const scoped = toRelative(canonicalRoot, path);
|
|
80
77
|
await explorerPath(workspace, root, scoped);
|
|
81
|
-
|
|
78
|
+
const displayPath = contains(resolve(root), selected) ? toRelative(root, selected) : scoped;
|
|
79
|
+
return { path: displayPath, name: basename(selected), ...await readOpenedFile(path) };
|
|
82
80
|
}
|
|
83
81
|
const contents = await readOpenedFile(path);
|
|
84
82
|
const ticket = randomUUID();
|
package/dist/server/git.d.ts
CHANGED
|
@@ -97,7 +97,7 @@ export declare function gitWorktreeCommittedDiff(root: string, base: GitWorktree
|
|
|
97
97
|
kind: "binary";
|
|
98
98
|
diff: null;
|
|
99
99
|
}>;
|
|
100
|
-
export declare function gitBranches(root: string, cwd: string, query: string, offset: number): Promise<{
|
|
100
|
+
export declare function gitBranches(root: string, cwd: string, query: string, offset: number, localOnly?: boolean): Promise<{
|
|
101
101
|
branches: {
|
|
102
102
|
name: string;
|
|
103
103
|
local: boolean;
|
package/dist/server/git.js
CHANGED
|
@@ -5,6 +5,7 @@ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "nod
|
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
6
|
import { mkdir, readFile, realpath, stat } from "node:fs/promises";
|
|
7
7
|
import { MAX_FILE_BYTES } from "./files.js";
|
|
8
|
+
import { ignoreWorkspaceTrash } from "./workspace-file-operations.js";
|
|
8
9
|
const exec = promisify(execFile);
|
|
9
10
|
async function git(cwd, args, options) { return exec("git", ["--literal-pathspecs", "-c", "core.quotepath=false", ...args], { cwd, windowsHide: true, maxBuffer: options?.maxBuffer ?? 8 * 1024 * 1024, timeout: options?.timeout }); }
|
|
10
11
|
function files(raw, cwd = "") {
|
|
@@ -412,12 +413,12 @@ export async function gitWorktreeCommittedDiff(root, base, path, fullContext = f
|
|
|
412
413
|
return { path, staged: false, kind: "binary", diff: null };
|
|
413
414
|
return { path, staged: false, kind: "text", diff: stdout };
|
|
414
415
|
}
|
|
415
|
-
export async function gitBranches(root, cwd, query, offset) {
|
|
416
|
+
export async function gitBranches(root, cwd, query, offset, localOnly = false) {
|
|
416
417
|
const canWrite = await canChangeWorktree(root, cwd);
|
|
417
418
|
const filter = query.trim().slice(0, 160).toLowerCase();
|
|
418
419
|
const start = pageNumber(offset, 0, 0, 1_000_000);
|
|
419
420
|
const format = "--format=%(refname)%00%(symref)%00%(HEAD)";
|
|
420
|
-
const { stdout } = await git(root, ["for-each-ref", "--sort=refname", format, "refs/heads", "refs/remotes"], { maxBuffer: 32 * 1024 * 1024 });
|
|
421
|
+
const { stdout } = await git(root, ["for-each-ref", "--sort=refname", format, "refs/heads", ...localOnly ? [] : ["refs/remotes"]], { maxBuffer: 32 * 1024 * 1024 });
|
|
421
422
|
let total = 0, matches = 0;
|
|
422
423
|
const branches = [];
|
|
423
424
|
for (const line of stdout.split(/\r?\n/)) {
|
|
@@ -833,6 +834,8 @@ function safePath(root, path) {
|
|
|
833
834
|
}
|
|
834
835
|
export async function gitMutate(root, op, path, message, cwd = "", target) {
|
|
835
836
|
safePath(root, cwd);
|
|
837
|
+
if (op === "stage" || op === "stage-all")
|
|
838
|
+
await ignoreWorkspaceTrash(root);
|
|
836
839
|
if (op === "stage-all" || op === "unstage-all") {
|
|
837
840
|
if (op === "stage-all")
|
|
838
841
|
await git(root, ["add", "--", cwd || "."]);
|
|
@@ -42,6 +42,7 @@ export function groupPrimaryExecutor(store, runs) {
|
|
|
42
42
|
await input.onConversation?.(id);
|
|
43
43
|
const before = store.conversation(id).messages.length;
|
|
44
44
|
let text = "", thinking = "";
|
|
45
|
+
const unobserveModel = runs.observeModel(id, model => input.onModel?.(model));
|
|
45
46
|
const unobserve = runs.observeExecution(id, event => { if (event.kind === "tool" && event.phase === "start")
|
|
46
47
|
input.onToolStart?.(); input.onExecution?.(event); });
|
|
47
48
|
const observe = () => {
|
|
@@ -69,14 +70,13 @@ export function groupPrimaryExecutor(store, runs) {
|
|
|
69
70
|
throw new Error(current.error ?? "群成员执行失败。");
|
|
70
71
|
if (current.status === "stopped")
|
|
71
72
|
throw new Error("群成员执行已停止或超时。");
|
|
72
|
-
if (current.model)
|
|
73
|
-
await input.onModel?.(current.model);
|
|
74
73
|
if (!text.trim())
|
|
75
74
|
throw new Error("群成员没有返回可见回答。");
|
|
76
75
|
return text;
|
|
77
76
|
}
|
|
78
77
|
finally {
|
|
79
78
|
unobserve();
|
|
79
|
+
unobserveModel();
|
|
80
80
|
clearInterval(timer);
|
|
81
81
|
clearTimeout(timeout);
|
|
82
82
|
input.signal?.removeEventListener("abort", abort);
|
|
@@ -2066,7 +2066,7 @@ export function createHttpServer(options) {
|
|
|
2066
2066
|
if (op === "log")
|
|
2067
2067
|
json(200, await gitLog(workspace.path, Number(url.searchParams.get("limit") ?? 20), cwd, query, offset));
|
|
2068
2068
|
else if (op === "branches")
|
|
2069
|
-
json(200, await gitBranches(workspace.path, cwd, query, offset));
|
|
2069
|
+
json(200, await gitBranches(workspace.path, cwd, query, offset, url.searchParams.get("local") === "1"));
|
|
2070
2070
|
else
|
|
2071
2071
|
json(200, await gitStashes(workspace.path, cwd, query, offset));
|
|
2072
2072
|
}
|
package/dist/server/runtime.d.ts
CHANGED
|
@@ -106,6 +106,8 @@ export interface AnswerInput {
|
|
|
106
106
|
* when the cached locator needs refreshing.
|
|
107
107
|
*/
|
|
108
108
|
onSessionFile?: (path: string) => void | Promise<void>;
|
|
109
|
+
/** The model resolved by the runtime before this turn is submitted. */
|
|
110
|
+
onModel?: (model: ModelSelection) => void | Promise<void>;
|
|
109
111
|
/**
|
|
110
112
|
* Called once per `tool_execution_start`, with the tool's name and the bounded label naming what it was
|
|
111
113
|
* aimed at.
|
package/dist/server/runtime.js
CHANGED
|
@@ -1239,6 +1239,9 @@ export class PiRpcRuntime {
|
|
|
1239
1239
|
session.extensionRunner?.setUIContext(uiContext, "rpc");
|
|
1240
1240
|
this.uiBoundSessions.add(session);
|
|
1241
1241
|
}
|
|
1242
|
+
const actualModel = describeModel(session.model);
|
|
1243
|
+
if (actualModel)
|
|
1244
|
+
await input.onModel?.({ provider: actualModel.provider, modelId: actualModel.modelId, label: actualModel.label });
|
|
1242
1245
|
let preflight;
|
|
1243
1246
|
const imagePayloads = this.options.uploadsDir && images?.length
|
|
1244
1247
|
? await loadConversationImages(this.options.uploadsDir, conversation.id, images, { required: true })
|
|
@@ -1684,7 +1687,7 @@ export class PiRpcRuntime {
|
|
|
1684
1687
|
* Still used for the memory review, the knowledge reranker, and as the fallback when Pi's SDK is not
|
|
1685
1688
|
* installed. The main conversation path does NOT come here - see `answer`.
|
|
1686
1689
|
*/
|
|
1687
|
-
async *answerOneShot({ conversation, prompt, signal, cwd, host, onPiQueue, onSteerDelivered, onUserEntry, onSessionFile, onToolCall, onFileWrite, onToolUpdate, onToolPreparing, onToolEnd, onThinking, onThinkingEnd, onCompaction, images, memoryReview, memorySourceConversationId, knowledgeRerank }) {
|
|
1690
|
+
async *answerOneShot({ conversation, prompt, signal, cwd, host, onPiQueue, onSteerDelivered, onUserEntry, onSessionFile, onModel, onToolCall, onFileWrite, onToolUpdate, onToolPreparing, onToolEnd, onThinking, onThinkingEnd, onCompaction, images, memoryReview, memorySourceConversationId, knowledgeRerank }) {
|
|
1688
1691
|
const latencyStartedAt = performance.now();
|
|
1689
1692
|
traceLatency(conversation.id, "answer.begin", latencyStartedAt);
|
|
1690
1693
|
await mkdir(this.sessionDir, { recursive: true });
|
|
@@ -1857,10 +1860,12 @@ export class PiRpcRuntime {
|
|
|
1857
1860
|
}
|
|
1858
1861
|
// Resumed Pi sessions can carry a different model than the global default.
|
|
1859
1862
|
// Check the real get_state result as well, before any prompt reaches the model.
|
|
1860
|
-
if (this.modelValidator || onSessionFile) {
|
|
1863
|
+
if (this.modelValidator || onSessionFile || onModel) {
|
|
1861
1864
|
const actual = await channel.request({ id: "policy_state", type: "get_state" }, SESSION_COMMAND_TIMEOUT_MS);
|
|
1862
1865
|
const model = actual.data?.model;
|
|
1863
1866
|
await this.modelValidator?.(validationId, model?.provider && model.id ? { provider: model.provider, modelId: model.id, label: model.name ?? model.id } : undefined);
|
|
1867
|
+
if (model?.provider && model.id)
|
|
1868
|
+
await onModel?.({ provider: model.provider, modelId: model.id, label: model.name ?? model.id });
|
|
1864
1869
|
const sessionFile = actual.data?.sessionFile;
|
|
1865
1870
|
if (typeof sessionFile === "string" && sessionFile)
|
|
1866
1871
|
await onSessionFile?.(sessionFile);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
declare const MAX_INITIAL_CONTENT: number;
|
|
2
|
+
export declare function ignoreWorkspaceTrash(workspace: string, forthcoming?: boolean): Promise<void>;
|
|
2
3
|
export declare function serializeWorkspaceWrite<T>(workspace: string, work: () => Promise<T>): Promise<T>;
|
|
3
4
|
export type FileTreeMutation = {
|
|
4
5
|
path: string;
|
|
@@ -1,12 +1,38 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { execFile } from "node:child_process";
|
|
3
|
+
import { promisify } from "node:util";
|
|
2
4
|
import { lstatSync, mkdirSync, renameSync, rmdirSync, unlinkSync, linkSync } from "node:fs";
|
|
3
|
-
import { lstat, mkdir, mkdtemp, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile } from "node:fs/promises";
|
|
4
|
-
import { basename, dirname, join } from "node:path";
|
|
5
|
+
import { appendFile, lstat, mkdir, mkdtemp, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile } from "node:fs/promises";
|
|
6
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
5
7
|
import { contains, fileMeta, FilesError, isTextName, resolveInsideRoot, toRelative } from "./files.js";
|
|
6
8
|
const TRASH_DIRECTORY = ".super-pi/file-trash";
|
|
7
9
|
const MAX_INITIAL_CONTENT = 32 * 1024 * 1024;
|
|
8
10
|
const trashIdFormat = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/;
|
|
9
11
|
const writeQueues = new Map();
|
|
12
|
+
const exec = promisify(execFile);
|
|
13
|
+
export async function ignoreWorkspaceTrash(workspace, forthcoming = false) {
|
|
14
|
+
if (!forthcoming && !await lstat(join(workspace, TRASH_DIRECTORY)).catch(() => undefined))
|
|
15
|
+
return;
|
|
16
|
+
let top, exclude;
|
|
17
|
+
try {
|
|
18
|
+
const options = { cwd: workspace, windowsHide: true, timeout: 5000 };
|
|
19
|
+
top = (await exec("git", ["rev-parse", "--show-toplevel"], options)).stdout.trim();
|
|
20
|
+
const path = (await exec("git", ["rev-parse", "--git-path", "info/exclude"], options)).stdout.trim();
|
|
21
|
+
exclude = resolve(workspace, path);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const relativePath = toRelative(top, join(workspace, TRASH_DIRECTORY));
|
|
27
|
+
const escaped = [...relativePath].map(char => "\\*?[]#! ".includes(char) ? `\\${char}` : char).join("");
|
|
28
|
+
const rule = `/${escaped}/`;
|
|
29
|
+
const prior = await readFile(exclude, "utf8").catch((error) => { if (error.code === "ENOENT")
|
|
30
|
+
return ""; throw error; });
|
|
31
|
+
if (!prior.split(/\r?\n/).includes(rule)) {
|
|
32
|
+
await mkdir(dirname(exclude), { recursive: true });
|
|
33
|
+
await appendFile(exclude, `\n${rule}\n`, "utf8");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
10
36
|
export async function serializeWorkspaceWrite(workspace, work) {
|
|
11
37
|
const key = await realpath(workspace);
|
|
12
38
|
const previous = writeQueues.get(key) ?? Promise.resolve();
|
|
@@ -116,6 +142,7 @@ async function trashRoot(workspace, create) {
|
|
|
116
142
|
const path = await resolveInsideRoot(workspace, TRASH_DIRECTORY);
|
|
117
143
|
const parent = dirname(path);
|
|
118
144
|
if (create) {
|
|
145
|
+
await ignoreWorkspaceTrash(workspace, true);
|
|
119
146
|
await mkdir(parent).catch((error) => { if (error.code !== "EEXIST")
|
|
120
147
|
throw error; });
|
|
121
148
|
if (!(await lstat(parent)).isDirectory())
|
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.286",
|
|
7
7
|
"description": "Web control plane and companion for Pi",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"type": "module",
|
|
@@ -336,6 +336,7 @@
|
|
|
336
336
|
"scripts/session-reminder-pmo-rights.test.mjs"
|
|
337
337
|
],
|
|
338
338
|
"check:browser": [
|
|
339
|
+
"scripts/git-panel-upgrade-browser.test.mjs",
|
|
339
340
|
"scripts/context-meter-browser.test.mjs",
|
|
340
341
|
"scripts/rsi-sidebar-browser.test.mjs",
|
|
341
342
|
"scripts/model-discovery-browser.test.mjs",
|