@evandu/super-pi 0.1.232 → 0.1.234
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agents/super-pi-task/core.ts +38 -0
- package/agents/super-pi-task/index.ts +17 -0
- package/dist/client/.super-pi-client-sources.json +9 -9
- package/dist/client/assets/CodeMirrorEditor-Bghp-U4C.js +2 -0
- package/dist/client/assets/{dist-C7VEKkD-.js → dist-B8NaV9Cv.js} +1 -1
- package/dist/client/assets/{dist-Bv4wCENt.js → dist-BESOLyaG.js} +1 -1
- package/dist/client/assets/{dist-BFeunbEX.js → dist-BNTyu0GR.js} +1 -1
- package/dist/client/assets/{dist-BKp3q2wn.js → dist-BOLAeWpo.js} +1 -1
- package/dist/client/assets/{dist-C31-s_h7.js → dist-BXS7H8-R.js} +1 -1
- package/dist/client/assets/{dist-D8RY2jNq.js → dist-BfJ86nxw.js} +1 -1
- package/dist/client/assets/{dist-Dfq0xUba.js → dist-Bs7CHuCU.js} +1 -1
- package/dist/client/assets/{dist-BIy5crB3.js → dist-C7Frt-j5.js} +1 -1
- package/dist/client/assets/{dist-BpINRZym.js → dist-CWI_J8Y8.js} +1 -1
- package/dist/client/assets/{dist-UKx13tHO.js → dist-CXgcMgdt.js} +1 -1
- package/dist/client/assets/{dist-C6wg16BA.js → dist-CeyskXU5.js} +1 -1
- package/dist/client/assets/{dist-B9BbvWot.js → dist-CpJDmC2s.js} +1 -1
- package/dist/client/assets/{dist-DEKenQm-.js → dist-DDQEsi6d.js} +1 -1
- package/dist/client/assets/{dist-znfz-BcE.js → dist-DkGaMCuB.js} +1 -1
- package/dist/client/assets/{dist-a2NOYHv3.js → dist-DzEYlfwN.js} +1 -1
- package/dist/client/assets/{dist-H6BCSlev.js → dist-Ka-oeqiz.js} +1 -1
- package/dist/client/assets/{dist-IEeNkSQA.js → dist-Zo5WaMe0.js} +1 -1
- package/dist/client/assets/{dist-BJ6foecv.js → dist-gzowmwC2.js} +1 -1
- package/dist/client/assets/{dist-Ydfp2kM0.js → dist-jtZ_yT6e.js} +1 -1
- package/dist/client/assets/{dist-DXa_Ik6q.js → dist-pz-FtJ-_.js} +1 -1
- package/dist/client/assets/{dist-C0RopB4q.js → dist-qY4JuH16.js} +1 -1
- package/dist/client/assets/{dist-Opwy6jSg.js → dist-vqHBACjg.js} +1 -1
- package/dist/client/assets/{index-P5ei_l2b.css → index-CYevEn2Z.css} +1 -1
- package/dist/client/assets/{index-DREwHzYy.js → index-_JUMqd3d.js} +59 -58
- package/dist/client/index.html +2 -2
- package/dist/server/application/worktree-service.d.ts +13 -0
- package/dist/server/application/worktree-service.js +76 -0
- package/dist/server/explicit-file-open.d.ts +34 -0
- package/dist/server/explicit-file-open.js +105 -0
- package/dist/server/file-name-index.d.ts +5 -5
- package/dist/server/file-name-index.js +22 -19
- package/dist/server/files.d.ts +5 -0
- package/dist/server/files.js +12 -6
- package/dist/server/git.d.ts +23 -0
- package/dist/server/git.js +234 -18
- package/dist/server/http-server.js +129 -6
- package/dist/server/model-filter.js +2 -2
- package/dist/server/runtime.js +3 -3
- package/dist/server/store.d.ts +2 -1
- package/dist/server/store.js +19 -3
- package/dist/server/task-tool.d.ts +1 -0
- package/dist/server/task-tool.js +1 -0
- package/dist/server/types.d.ts +3 -0
- package/dist/server/workspace-file-response.d.ts +6 -2
- package/dist/server/workspace-file-response.js +6 -6
- package/dist/shared/git-commit.d.ts +11 -0
- package/dist/shared/git-commit.js +1 -0
- package/dist/shared/git-graph.d.ts +38 -0
- package/dist/shared/git-graph.js +30 -0
- package/package.json +1 -1
- package/dist/client/assets/CodeMirrorEditor-UhCYm5Wx.js +0 -2
package/dist/server/git.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { execFile, spawn } from "node:child_process";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import { promisify } from "node:util";
|
|
4
|
-
import { basename, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
|
-
import { readFile, realpath, stat } from "node:fs/promises";
|
|
6
|
+
import { mkdir, readFile, realpath, stat } from "node:fs/promises";
|
|
7
7
|
const exec = promisify(execFile);
|
|
8
8
|
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 }); }
|
|
9
9
|
function files(raw, cwd = "") {
|
|
@@ -82,16 +82,208 @@ function parseGitCommits(raw) {
|
|
|
82
82
|
}
|
|
83
83
|
return commits;
|
|
84
84
|
}
|
|
85
|
+
const COMMIT_HASH = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i;
|
|
86
|
+
export async function gitGraph(root, limit, offset, snapshot, after) {
|
|
87
|
+
const size = pageNumber(limit, 50, 1, 100);
|
|
88
|
+
const start = pageNumber(offset, 0, 0, 2_147_483_647);
|
|
89
|
+
const repo = await worktreeRoot(root);
|
|
90
|
+
const [refs, checkout] = await Promise.all([
|
|
91
|
+
git(repo, ["for-each-ref", "--format=%(refname)%00%(objectname)%00%(*objectname)%00%(symref)"], { maxBuffer: 32 * 1024 * 1024, timeout: 12_000 }),
|
|
92
|
+
gitWorktrees(repo),
|
|
93
|
+
]);
|
|
94
|
+
const worktrees = checkout.worktrees.filter(entry => !entry.missing && COMMIT_HASH.test(entry.head) && !/^0+$/.test(entry.head));
|
|
95
|
+
const heads = worktrees.map(({ id, branch, head, current, name }) => ({ id, branch, head, current, name }));
|
|
96
|
+
const version = createHash("sha256").update(refs.stdout).update(JSON.stringify(heads)).digest("hex");
|
|
97
|
+
const changed = () => gitFailure("提交图已变化,请刷新后继续查看。", "graph_changed");
|
|
98
|
+
if (start && snapshot !== version)
|
|
99
|
+
throw changed();
|
|
100
|
+
const labels = new Map();
|
|
101
|
+
const mark = (hash, label) => {
|
|
102
|
+
const list = labels.get(hash) ?? [];
|
|
103
|
+
list.push(label);
|
|
104
|
+
labels.set(hash, list);
|
|
105
|
+
};
|
|
106
|
+
for (const entry of worktrees) {
|
|
107
|
+
if (entry.current)
|
|
108
|
+
mark(entry.head, { kind: "head", name: entry.branch ? `HEAD → ${entry.branch}` : "HEAD" });
|
|
109
|
+
else {
|
|
110
|
+
const repeatedName = worktrees.some(other => other.id !== entry.id && other.name === entry.name);
|
|
111
|
+
const name = entry.branch ?? (repeatedName ? `${basename(dirname(entry.path))}/${entry.name}` : entry.name);
|
|
112
|
+
mark(entry.head, { kind: "worktree", name, checkoutId: entry.id });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
for (const line of refs.stdout.split(/\r?\n/)) {
|
|
116
|
+
const [ref, hash, peeled, symbolic] = line.split("\0");
|
|
117
|
+
if (!ref || symbolic)
|
|
118
|
+
continue;
|
|
119
|
+
if (ref.startsWith("refs/heads/"))
|
|
120
|
+
mark(hash, { kind: "branch", name: ref.slice("refs/heads/".length) });
|
|
121
|
+
else if (ref.startsWith("refs/remotes/"))
|
|
122
|
+
mark(hash, { kind: "remote", name: ref.slice("refs/remotes/".length) });
|
|
123
|
+
else if (ref.startsWith("refs/tags/"))
|
|
124
|
+
mark(peeled || hash, { kind: "tag", name: ref.slice("refs/tags/".length) });
|
|
125
|
+
else if (ref === "refs/stash")
|
|
126
|
+
mark(hash, { kind: "stash", name: "Stash" });
|
|
127
|
+
}
|
|
128
|
+
const overlap = start ? 1 : 0;
|
|
129
|
+
const detached = worktrees.filter(entry => !entry.branch).map(entry => entry.head);
|
|
130
|
+
const format = "--format=%H%x00%h%x00%P%x00%s%x00%an%x00%aI";
|
|
131
|
+
const { stdout } = await git(repo, ["-c", "log.showSignature=false", "log", "--all", "--topo-order", "--no-notes", "--no-decorate",
|
|
132
|
+
"--no-patch", "--encoding=UTF-8", "-z", `--skip=${start - overlap}`, `-${size + 1 + overlap}`, format, ...detached, "--"], { timeout: 12_000 });
|
|
133
|
+
const parts = stdout.split("\0");
|
|
134
|
+
const commits = [];
|
|
135
|
+
for (let index = 0; index + 5 < parts.length; index += 6) {
|
|
136
|
+
const [hash, short, parents, subject, author, date] = parts.slice(index, index + 6);
|
|
137
|
+
commits.push({ hash, short, parents: parents ? parents.split(" ") : [], subject, author, date, refs: labels.get(hash) ?? [] });
|
|
138
|
+
}
|
|
139
|
+
if (overlap && commits.shift()?.hash !== after)
|
|
140
|
+
throw changed();
|
|
141
|
+
return { commits: commits.slice(0, size), snapshot: version, hasMore: commits.length > size };
|
|
142
|
+
}
|
|
143
|
+
const HISTORY_DIFF_OPTIONS = ["--no-color", "--no-ext-diff", "--no-textconv", "--submodule=short", "--find-renames"];
|
|
144
|
+
async function readCommitDiff(repo, args) {
|
|
145
|
+
try {
|
|
146
|
+
return (await git(repo, args, { timeout: 12_000 })).stdout;
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
if (error.code === "ERR_CHILD_PROCESS_STDIO_MAXBUFFER") {
|
|
150
|
+
throw gitFailure("该提交的文件列表或差异超过了查看上限。", "commit_diff_too_large");
|
|
151
|
+
}
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
async function commitSnapshot(root, cwd, revision) {
|
|
156
|
+
if (!COMMIT_HASH.test(revision))
|
|
157
|
+
throw gitFailure("请选择有效的提交哈希。", "bad_revision");
|
|
158
|
+
const hash = revision.toLowerCase();
|
|
159
|
+
const [repo, session] = await Promise.all([worktreeRoot(root).then(path => realpath(path)), realpath(resolve(root, cwd))]);
|
|
160
|
+
const scope = relative(repo, session).split(sep).join("/");
|
|
161
|
+
if (scope === ".." || scope.startsWith("../") || isAbsolute(scope)) {
|
|
162
|
+
throw gitFailure("会话目录位于 Git 仓库之外。", "outside_scope");
|
|
163
|
+
}
|
|
164
|
+
const type = await git(repo, ["cat-file", "-t", hash], { timeout: 12_000 }).then(result => result.stdout.trim()).catch(() => "");
|
|
165
|
+
if (type !== "commit")
|
|
166
|
+
throw gitFailure("找不到这个 Git 提交。", "not_found");
|
|
167
|
+
const raw = await readCommitDiff(repo, ["cat-file", "commit", hash]);
|
|
168
|
+
const messageOffset = raw.indexOf("\n\n");
|
|
169
|
+
const message = messageOffset < 0 ? "" : raw.slice(messageOffset + 2).trimEnd();
|
|
170
|
+
const parents = (messageOffset < 0 ? raw : raw.slice(0, messageOffset)).split("\n")
|
|
171
|
+
.filter(line => line.startsWith("parent ")).map(line => line.slice(7));
|
|
172
|
+
if (parents.some(parent => !COMMIT_HASH.test(parent)))
|
|
173
|
+
throw gitFailure("这个提交的父版本记录无效。", "bad_revision");
|
|
174
|
+
const firstParent = parents[0];
|
|
175
|
+
const diff = (options, paths, exact = false) => {
|
|
176
|
+
const flags = [...HISTORY_DIFF_OPTIONS, scope ? `--relative=${scope}` : "--no-relative", ...options];
|
|
177
|
+
// An escaped glob matches the file itself, even when that path was a directory in one tree.
|
|
178
|
+
const specs = exact ? paths.map(path => `:(top,glob)${path.replace(/[^/]/gu, "\\$&")}`) : paths;
|
|
179
|
+
const args = firstParent
|
|
180
|
+
? ["diff", ...flags, firstParent, hash, "--", ...specs]
|
|
181
|
+
: ["diff-tree", "--root", "--no-commit-id", "-r", ...flags, hash, "--", ...specs];
|
|
182
|
+
return readCommitDiff(repo, exact ? ["--no-literal-pathspecs", ...args] : args);
|
|
183
|
+
};
|
|
184
|
+
// Read the parent from the stored commit. A shallow boundary is not a root commit.
|
|
185
|
+
if (firstParent && !await git(repo, ["cat-file", "-e", firstParent], { timeout: 12_000 }).then(() => true, () => false)) {
|
|
186
|
+
throw gitFailure("这个提交的父版本不在本地仓库中。", "not_found");
|
|
187
|
+
}
|
|
188
|
+
const records = (await diff(["--name-status", "-z"], scope ? [scope] : [])).split("\0");
|
|
189
|
+
const files = [];
|
|
190
|
+
for (let index = 0; index + 1 < records.length;) {
|
|
191
|
+
const status = records[index++];
|
|
192
|
+
const firstPath = records[index++];
|
|
193
|
+
if (status.startsWith("R") || status.startsWith("C")) {
|
|
194
|
+
files.push({ status, previousPath: firstPath, path: records[index++] });
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
files.push({ status, path: firstPath });
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return { detail: { hash, parents, message, files }, scope, diff };
|
|
201
|
+
}
|
|
202
|
+
export async function gitCommit(root, cwd, hash) {
|
|
203
|
+
return (await commitSnapshot(root, cwd, hash)).detail;
|
|
204
|
+
}
|
|
205
|
+
export async function gitCommitDiff(root, cwd, hash, path) {
|
|
206
|
+
if (!path || path.includes("\0"))
|
|
207
|
+
throw gitFailure("请选择提交中的变更文件。", "path");
|
|
208
|
+
const { detail, scope, diff } = await commitSnapshot(root, cwd, hash);
|
|
209
|
+
// Match exact Git paths from the scoped tree diff. No live filesystem lookup is needed.
|
|
210
|
+
const file = detail.files.find(entry => entry.path === path);
|
|
211
|
+
if (!file)
|
|
212
|
+
throw gitFailure("这个提交在当前目录内没有该文件的差异。", "not_found");
|
|
213
|
+
const paths = (file.previousPath === undefined ? [file.path] : [file.previousPath, file.path])
|
|
214
|
+
.map(name => scope ? `${scope}/${name}` : name);
|
|
215
|
+
const patch = await diff(["--patch"], paths, true);
|
|
216
|
+
const binary = /^Binary files .* differ$/m.test(patch);
|
|
217
|
+
return { path, staged: false, kind: binary ? "binary" : "text", diff: binary ? null : patch };
|
|
218
|
+
}
|
|
85
219
|
const normalizedPath = (path) => process.platform === "win32" ? resolve(path).toLowerCase() : resolve(path);
|
|
86
220
|
async function worktreeRoot(root) {
|
|
87
|
-
return (await git(root, ["rev-parse", "--show-toplevel"])).stdout.
|
|
221
|
+
return (await git(root, ["rev-parse", "--show-toplevel"])).stdout.replace(/\r?\n$/, "");
|
|
88
222
|
}
|
|
89
223
|
async function canChangeWorktree(root, cwd) {
|
|
90
224
|
return normalizedPath(resolve(root, cwd)) === normalizedPath(await worktreeRoot(root));
|
|
91
225
|
}
|
|
92
226
|
async function gitCommonDir(root) {
|
|
93
|
-
const { stdout } = await git(root, ["rev-parse", "--
|
|
94
|
-
return realpath(stdout.
|
|
227
|
+
const { stdout } = await git(root, ["rev-parse", "--git-common-dir"]);
|
|
228
|
+
return realpath(resolve(root, stdout.replace(/\r?\n$/, "")));
|
|
229
|
+
}
|
|
230
|
+
let supportsNulWorktrees;
|
|
231
|
+
async function gitWorktreeList(root) {
|
|
232
|
+
const args = ["worktree", "list", "--porcelain"];
|
|
233
|
+
if (supportsNulWorktrees === false)
|
|
234
|
+
return { raw: (await git(root, args)).stdout, nul: false };
|
|
235
|
+
try {
|
|
236
|
+
const { stdout } = await git(root, [...args, "-z"]);
|
|
237
|
+
supportsNulWorktrees = true;
|
|
238
|
+
return { raw: stdout, nul: true };
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
if (error?.code !== 129)
|
|
242
|
+
throw error;
|
|
243
|
+
const { stdout } = await git(root, args);
|
|
244
|
+
supportsNulWorktrees = false;
|
|
245
|
+
return { raw: stdout, nul: false };
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const gitEscapes = {
|
|
249
|
+
a: "\x07", b: "\b", f: "\f", n: "\n", r: "\r", t: "\t", v: "\v", "\\": "\\", '"': '"',
|
|
250
|
+
};
|
|
251
|
+
function unquoteWorktreePath(field) {
|
|
252
|
+
if (!field.startsWith('"') || !field.endsWith('"'))
|
|
253
|
+
return field;
|
|
254
|
+
const quoted = field.slice(1, -1);
|
|
255
|
+
const chunks = [];
|
|
256
|
+
let from = 0;
|
|
257
|
+
for (const escape of quoted.matchAll(/\\([0-7]{1,3}|.)/gs)) {
|
|
258
|
+
chunks.push(Buffer.from(quoted.slice(from, escape.index)));
|
|
259
|
+
const code = escape[1];
|
|
260
|
+
chunks.push(/^[0-7]/.test(code) ? Buffer.from([parseInt(code, 8)]) : Buffer.from(gitEscapes[code] ?? code));
|
|
261
|
+
from = escape.index + escape[0].length;
|
|
262
|
+
}
|
|
263
|
+
chunks.push(Buffer.from(quoted.slice(from)));
|
|
264
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
265
|
+
}
|
|
266
|
+
export function parseWorktreePorcelain(raw, nul) {
|
|
267
|
+
return raw.split(nul ? "\0\0" : /\r?\n\r?\n/).flatMap((record, index) => {
|
|
268
|
+
const fields = new Map();
|
|
269
|
+
let ambiguous = false;
|
|
270
|
+
for (const field of record.split(nul ? "\0" : /\r?\n/).filter(Boolean)) {
|
|
271
|
+
const separator = field.indexOf(" ");
|
|
272
|
+
const key = separator < 0 ? field : field.slice(0, separator);
|
|
273
|
+
if (fields.has(key))
|
|
274
|
+
ambiguous = true;
|
|
275
|
+
fields.set(key, separator < 0 ? "" : field.slice(separator + 1));
|
|
276
|
+
}
|
|
277
|
+
const path = fields.get("worktree");
|
|
278
|
+
const head = fields.get("HEAD");
|
|
279
|
+
if (ambiguous || !path || !head || !/^[a-f0-9]{40}([a-f0-9]{24})?$/.test(head) || fields.has("bare"))
|
|
280
|
+
return [];
|
|
281
|
+
return [{
|
|
282
|
+
path: nul ? path : unquoteWorktreePath(path), head, index,
|
|
283
|
+
branch: fields.get("branch")?.replace(/^refs\/heads\//, "") ?? null,
|
|
284
|
+
locked: fields.has("locked"), prunable: fields.has("prunable"),
|
|
285
|
+
}];
|
|
286
|
+
});
|
|
95
287
|
}
|
|
96
288
|
export async function gitWorktrees(root) {
|
|
97
289
|
const rootPath = await realpath(root);
|
|
@@ -100,23 +292,15 @@ export async function gitWorktrees(root) {
|
|
|
100
292
|
throw gitFailure("在仓库根目录工作区中查看工作树", "outside_scope");
|
|
101
293
|
}
|
|
102
294
|
const [commonDir, result] = await Promise.all([
|
|
103
|
-
gitCommonDir(rootPath),
|
|
295
|
+
gitCommonDir(rootPath), gitWorktreeList(rootPath),
|
|
104
296
|
]);
|
|
105
297
|
const worktrees = [];
|
|
106
|
-
for (const
|
|
107
|
-
const fields = new Map(record.split("\0").map(field => {
|
|
108
|
-
const delimiter = field.indexOf(" ");
|
|
109
|
-
return delimiter < 0 ? [field, ""] : [field.slice(0, delimiter), field.slice(delimiter + 1)];
|
|
110
|
-
}));
|
|
111
|
-
const path = fields.get("worktree");
|
|
112
|
-
if (!path || fields.has("bare"))
|
|
113
|
-
continue;
|
|
298
|
+
for (const { path, head, index, branch, locked, prunable } of parseWorktreePorcelain(result.raw, result.nul)) {
|
|
114
299
|
const pathKey = normalizedPath(path);
|
|
115
300
|
const id = createHash("sha256").update(normalizedPath(commonDir)).update("\0").update(pathKey).digest("hex");
|
|
116
301
|
worktrees.push({
|
|
117
|
-
id, path, name: basename(path), branch:
|
|
118
|
-
|
|
119
|
-
locked: fields.has("locked"), missing: fields.has("prunable") || !existsSync(path),
|
|
302
|
+
id, path, name: basename(path), branch, head, primary: index === 0, current: pathKey === normalizedPath(rootPath),
|
|
303
|
+
locked, missing: prunable || !existsSync(path),
|
|
120
304
|
});
|
|
121
305
|
}
|
|
122
306
|
return { worktrees, commonDir };
|
|
@@ -130,7 +314,39 @@ export async function resolveGitWorktree(root, id) {
|
|
|
130
314
|
if (!checked || normalizedPath(checked[0]) !== normalizedPath(checked[1]) || normalizedPath(checked[2]) !== normalizedPath(commonDir)) {
|
|
131
315
|
throw gitFailure("该目录已失效或不属于当前仓库", "not_found");
|
|
132
316
|
}
|
|
133
|
-
return { path: checked[0], base: worktrees.find(item => item.primary && !item.missing) ?? worktrees.find(item => item.current) };
|
|
317
|
+
return { path: checked[0], entry, base: worktrees.find(item => item.primary && !item.missing) ?? worktrees.find(item => item.current) };
|
|
318
|
+
}
|
|
319
|
+
export async function createGitWorktree(root, storage, requestKey, options) {
|
|
320
|
+
const { worktrees, commonDir } = await gitWorktrees(root);
|
|
321
|
+
const project = createHash("sha256").update(normalizedPath(commonDir)).digest("hex").slice(0, 18);
|
|
322
|
+
const slot = createHash("sha256").update(requestKey).digest("hex").slice(0, 18);
|
|
323
|
+
const directory = join(storage, project, slot);
|
|
324
|
+
const path = join(directory, basename(root));
|
|
325
|
+
const known = worktrees.find(item => normalizedPath(item.path) === normalizedPath(path));
|
|
326
|
+
if (known) {
|
|
327
|
+
if (options.branch && known.branch !== options.branch)
|
|
328
|
+
throw gitFailure("该创建请求已绑定到另一分支", "bad_message");
|
|
329
|
+
return (await resolveGitWorktree(root, known.id)).entry;
|
|
330
|
+
}
|
|
331
|
+
if (options.branch) {
|
|
332
|
+
const valid = await git(root, ["check-ref-format", `refs/heads/${options.branch}`]).then(() => true).catch(() => false);
|
|
333
|
+
if (!valid || options.branch.startsWith("-"))
|
|
334
|
+
throw gitFailure("分支名不符合 Git 规范", "bad_message");
|
|
335
|
+
}
|
|
336
|
+
if (options.base && !await git(root, ["check-ref-format", `refs/heads/${options.base}`]).then(() => true).catch(() => false)) {
|
|
337
|
+
throw gitFailure("工作树起点须为本地分支名", "bad_revision");
|
|
338
|
+
}
|
|
339
|
+
const startRef = options.base ? `refs/heads/${options.base}` : "HEAD";
|
|
340
|
+
const { stdout } = await git(root, ["rev-parse", "--verify", `${startRef}^{commit}`]).catch(() => {
|
|
341
|
+
throw gitFailure("找不到工作树的起点,请选择已有提交的本地分支", "bad_revision");
|
|
342
|
+
});
|
|
343
|
+
await mkdir(directory, { recursive: true });
|
|
344
|
+
const checkout = options.branch ? ["-b", options.branch] : ["--detach"];
|
|
345
|
+
await git(root, ["worktree", "add", ...checkout, "--", path, stdout.trim()], { timeout: 60_000 });
|
|
346
|
+
const created = (await gitWorktrees(root)).worktrees.find(item => normalizedPath(item.path) === normalizedPath(path));
|
|
347
|
+
if (!created)
|
|
348
|
+
throw gitFailure("Git 未登记新工作树", "not_found");
|
|
349
|
+
return (await resolveGitWorktree(root, created.id)).entry;
|
|
134
350
|
}
|
|
135
351
|
const WORKTREE_COMMIT_LIMIT = 20;
|
|
136
352
|
async function worktreeComparisonBase(path, base) {
|
|
@@ -12,7 +12,7 @@ import { describe as describeFilesError, FilesError, fileMeta, listDirectory, MA
|
|
|
12
12
|
import { findUploadFile, MAX_UPLOAD_BODY_BYTES, saveUpload } from "./upload.js";
|
|
13
13
|
import { describeThrown } from "./failure-text.js";
|
|
14
14
|
import { checkDiskVersion } from "./version.js";
|
|
15
|
-
import { gitBlame, gitBranches, gitDiff, gitLog, gitMutate, gitStagedDraftInput, gitStashes, gitStatus, gitWorktrees, resolveGitWorktree, inspectGitWorktree, gitWorktreeCommittedDiff } from "./git.js";
|
|
15
|
+
import { gitBlame, gitBranches, gitCommit, gitCommitDiff, gitDiff, gitGraph, gitLog, gitMutate, gitStagedDraftInput, gitStashes, gitStatus, gitWorktrees, resolveGitWorktree, inspectGitWorktree, gitWorktreeCommittedDiff } from "./git.js";
|
|
16
16
|
import { computeFileDiff } from "./file-diff.js";
|
|
17
17
|
import { verifyCapability } from "./capability.js";
|
|
18
18
|
import { conversationWorkspace } from "./model-filter.js";
|
|
@@ -20,6 +20,7 @@ import { describeSchedule } from "./scheduled-tasks.js";
|
|
|
20
20
|
import { MAX_KNOWLEDGE_REQUEST_BYTES } from "./knowledge.js";
|
|
21
21
|
import { MAX_DOCUMENT_REQUEST_BYTES } from "./application/document-service.js";
|
|
22
22
|
import { parseMessageDeliveryMode } from "./application/run-service.js";
|
|
23
|
+
import { createWorktreeService } from "./application/worktree-service.js";
|
|
23
24
|
import { MAX_FEISHU_REQUEST_BYTES } from "./application/feishu-service.js";
|
|
24
25
|
import { MAX_WEB_REQUEST_BYTES } from "./web.js";
|
|
25
26
|
import { MAX_TOOL_BODY_BYTES } from "./tool-registry.js";
|
|
@@ -29,6 +30,7 @@ import { ensureNameIndex, recordWorkspacePath } from "./file-name-index.js";
|
|
|
29
30
|
import { resolveFileCwd, sessionScopeKey, workspacePathFromSession } from "./session-cwd.js";
|
|
30
31
|
import { explorerInternalPath, explorerPath, inspectWorkspaceUpload, listWorkspaceTrash, MAX_WORKSPACE_UPLOAD_BYTES, mutateWorkspaceTree, serializeWorkspaceWrite, uploadWorkspaceFile } from "./workspace-file-operations.js";
|
|
31
32
|
import { readWorkspaceDocumentPreview, respondWithWorkspaceFile } from "./workspace-file-response.js";
|
|
33
|
+
import { createExplicitFileOpen } from "./explicit-file-open.js";
|
|
32
34
|
import { updateExplorerIndexes } from "./workspace-file-indexes.js";
|
|
33
35
|
import { readMessageMedia } from "./message-media.js";
|
|
34
36
|
import { MESSAGE_FRAME_CSP, MESSAGE_HTML_CSP } from "../shared/message-media.js";
|
|
@@ -353,6 +355,8 @@ export function createHttpServer(options) {
|
|
|
353
355
|
const { store, paths, accessToken, broadcaster, runService, catalogService, execService, toolRegistry, toolRunner } = context;
|
|
354
356
|
const { uploadsDir, clientDir, rootDir } = paths;
|
|
355
357
|
const gitDrafts = new Set();
|
|
358
|
+
const manageWorktree = createWorktreeService(context);
|
|
359
|
+
const explicitFileOpen = createExplicitFileOpen();
|
|
356
360
|
return createServer(async (request, response) => {
|
|
357
361
|
// Every HTTP request gets one stable id. It is returned to the browser and
|
|
358
362
|
// included in the server log, so a report containing a status code or a
|
|
@@ -1273,6 +1277,33 @@ export function createHttpServer(options) {
|
|
|
1273
1277
|
return;
|
|
1274
1278
|
}
|
|
1275
1279
|
const op = url.searchParams.get("op") ?? "status";
|
|
1280
|
+
const requestedCwd = url.searchParams.get("cwd");
|
|
1281
|
+
if (op.startsWith("worktree") && requestedCwd !== null)
|
|
1282
|
+
await resolveFileCwd(workspace.path, requestedCwd);
|
|
1283
|
+
if (op === "worktree-manage") {
|
|
1284
|
+
if (request.method !== "POST") {
|
|
1285
|
+
json(405, { error: "工作树操作需要 POST 请求", code: "method" });
|
|
1286
|
+
return;
|
|
1287
|
+
}
|
|
1288
|
+
const origin = request.headers.origin;
|
|
1289
|
+
const fetchSite = request.headers["sec-fetch-site"];
|
|
1290
|
+
if (!isLocalOrPrivateAddress(remote) || (origin && (fetchSite ? fetchSite !== "same-origin" : origin !== url.origin))) {
|
|
1291
|
+
json(403, { error: "工作树操作需要来自同源的本机或局域网请求" });
|
|
1292
|
+
return;
|
|
1293
|
+
}
|
|
1294
|
+
const payload = await readRequestText(request, 16 * 1024);
|
|
1295
|
+
if (payload.tooLarge) {
|
|
1296
|
+
json(413, { error: "工作树请求过大" });
|
|
1297
|
+
return;
|
|
1298
|
+
}
|
|
1299
|
+
const body = JSON.parse(payload.text);
|
|
1300
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) {
|
|
1301
|
+
json(400, { error: "工作树请求参数无效" });
|
|
1302
|
+
return;
|
|
1303
|
+
}
|
|
1304
|
+
json(200, await manageWorktree(workspace, body));
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1276
1307
|
if (op === "worktrees" || op === "worktree-inspect" || op === "worktree-diff") {
|
|
1277
1308
|
if (request.method !== "GET") {
|
|
1278
1309
|
json(405, { error: "查看工作树需要 GET 请求", code: "method" });
|
|
@@ -1303,11 +1334,28 @@ export function createHttpServer(options) {
|
|
|
1303
1334
|
: await gitDiff(checkout.path, path, url.searchParams.get("staged") === "1"));
|
|
1304
1335
|
return;
|
|
1305
1336
|
}
|
|
1306
|
-
const sessionRoot = await resolveFileCwd(workspace.path,
|
|
1337
|
+
const sessionRoot = await resolveFileCwd(workspace.path, requestedCwd);
|
|
1307
1338
|
const cwd = relative(resolve(workspace.path), sessionRoot).replaceAll("\\", "/");
|
|
1339
|
+
if (op === "commit-detail" || op === "commit-diff") {
|
|
1340
|
+
if (request.method !== "GET") {
|
|
1341
|
+
json(405, { error: "查看提交需要 GET 请求", code: "method" });
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1344
|
+
const worktreeId = url.searchParams.get("worktreeId");
|
|
1345
|
+
if (worktreeId !== null && !/^[a-f0-9]{64}$/.test(worktreeId)) {
|
|
1346
|
+
json(400, { error: "请先选择有效工作树", code: "bad_worktree" });
|
|
1347
|
+
return;
|
|
1348
|
+
}
|
|
1349
|
+
const root = worktreeId ? (await resolveGitWorktree(workspace.path, worktreeId)).path : workspace.path;
|
|
1350
|
+
const directory = worktreeId ? "" : cwd;
|
|
1351
|
+
const hash = url.searchParams.get("hash") ?? "";
|
|
1352
|
+
json(200, op === "commit-detail" ? await gitCommit(root, directory, hash)
|
|
1353
|
+
: await gitCommitDiff(root, directory, hash, url.searchParams.get("path") ?? ""));
|
|
1354
|
+
return;
|
|
1355
|
+
}
|
|
1308
1356
|
// Blame is a read with a GET shape: every other verb is refused HERE, before the POST branch
|
|
1309
1357
|
// could ever route the op into gitMutate and before any body is read.
|
|
1310
|
-
if (op === "blame" && request.method !== "GET") {
|
|
1358
|
+
if ((op === "blame" || op === "graph") && request.method !== "GET") {
|
|
1311
1359
|
json(405, { error: "Git 请求方法不支持", code: "method" });
|
|
1312
1360
|
return;
|
|
1313
1361
|
}
|
|
@@ -1383,6 +1431,9 @@ export function createHttpServer(options) {
|
|
|
1383
1431
|
}
|
|
1384
1432
|
if (op === "status")
|
|
1385
1433
|
json(200, await gitStatus(workspace.path, cwd));
|
|
1434
|
+
else if (op === "graph") {
|
|
1435
|
+
json(200, await gitGraph(workspace.path, Number(url.searchParams.get("limit") ?? 50), Number(url.searchParams.get("offset") ?? 0), url.searchParams.get("snapshot") ?? "", url.searchParams.get("after") ?? ""));
|
|
1436
|
+
}
|
|
1386
1437
|
else if (op === "log" || op === "branches" || op === "stash") {
|
|
1387
1438
|
const query = url.searchParams.get("q") ?? "";
|
|
1388
1439
|
const offset = Number(url.searchParams.get("offset") ?? 0);
|
|
@@ -1436,6 +1487,10 @@ export function createHttpServer(options) {
|
|
|
1436
1487
|
}
|
|
1437
1488
|
else if (code === "not_found")
|
|
1438
1489
|
json(404, { error: message, code: "not_found" });
|
|
1490
|
+
else if (code === "commit_diff_too_large")
|
|
1491
|
+
json(413, { error: message, code });
|
|
1492
|
+
else if (code === "graph_changed")
|
|
1493
|
+
json(409, { error: message, code });
|
|
1439
1494
|
else if (code === "bad_range" || code === "bad_revision")
|
|
1440
1495
|
json(400, { error: message, code });
|
|
1441
1496
|
else if (["outside_scope", "empty_index", "empty_worktree", "bad_message", "bad_op"].includes(String(code)))
|
|
@@ -1965,6 +2020,17 @@ export function createHttpServer(options) {
|
|
|
1965
2020
|
return;
|
|
1966
2021
|
}
|
|
1967
2022
|
const action = (body.action || "").trim();
|
|
2023
|
+
if (action === "worktree") {
|
|
2024
|
+
const caller = context.store.conversation(callerConversationId);
|
|
2025
|
+
const workspace = body.workspaceId && body.workspaceId === caller?.workspaceId && context.store.workspace(body.workspaceId);
|
|
2026
|
+
if (!workspace) {
|
|
2027
|
+
json(403, { error: "工作树操作需要使用调用方自己的工作区" });
|
|
2028
|
+
return;
|
|
2029
|
+
}
|
|
2030
|
+
const result = await manageWorktree(workspace, { ...body, action: body.worktreeAction }, callerConversationId);
|
|
2031
|
+
json(200, result);
|
|
2032
|
+
return;
|
|
2033
|
+
}
|
|
1968
2034
|
if ((action === "spawn" || action === "dispatch") && context.projectService?.projectForSession?.(callerConversationId)) {
|
|
1969
2035
|
json(403, { error: "项目分工必须使用 project 派发,以遵守资源准入限制" });
|
|
1970
2036
|
return;
|
|
@@ -2558,6 +2624,61 @@ export function createHttpServer(options) {
|
|
|
2558
2624
|
}
|
|
2559
2625
|
return;
|
|
2560
2626
|
}
|
|
2627
|
+
const openFileRoute = /^\/api\/files\/(open|open-asset|open-document)$/.exec(url.pathname)?.[1];
|
|
2628
|
+
if (openFileRoute) {
|
|
2629
|
+
try {
|
|
2630
|
+
const origin = request.headers.origin;
|
|
2631
|
+
const fetchSite = request.headers["sec-fetch-site"];
|
|
2632
|
+
if (!isLocalOrPrivateAddress(remote) || (fetchSite && fetchSite !== "same-origin" && fetchSite !== "none")
|
|
2633
|
+
|| (origin && (fetchSite ? fetchSite !== "same-origin" : origin !== url.origin))) {
|
|
2634
|
+
throw new FilesError(403, "打开外部文件需要来自同源的本机或局域网请求。", "denied");
|
|
2635
|
+
}
|
|
2636
|
+
const workspaceId = url.searchParams.get("workspaceId")?.trim();
|
|
2637
|
+
const workspace = workspaceId ? store.workspace(workspaceId) : undefined;
|
|
2638
|
+
if (!workspaceId || !workspace || workspace.closedAt)
|
|
2639
|
+
throw new FilesError(404, "请先选择有效工作区。", "no_workspace");
|
|
2640
|
+
const root = await resolveFileCwd(workspace.path, url.searchParams.get("cwd"));
|
|
2641
|
+
if (openFileRoute === "open" && request.method === "POST") {
|
|
2642
|
+
const body = await readRequestText(request, 16 * 1024);
|
|
2643
|
+
if (body.tooLarge)
|
|
2644
|
+
throw new FilesError(413, "文件打开请求过大。", "too_large");
|
|
2645
|
+
let path;
|
|
2646
|
+
try {
|
|
2647
|
+
path = JSON.parse(body.text)?.path;
|
|
2648
|
+
}
|
|
2649
|
+
catch {
|
|
2650
|
+
throw new FilesError(400, "需要有效的文件打开请求。", "bad_request");
|
|
2651
|
+
}
|
|
2652
|
+
if (typeof path !== "string" || !path.trim())
|
|
2653
|
+
throw new FilesError(400, "请提供文件路径。", "bad_path");
|
|
2654
|
+
json(200, await explicitFileOpen.open(workspaceId, workspace.path, root, path));
|
|
2655
|
+
return;
|
|
2656
|
+
}
|
|
2657
|
+
const asset = openFileRoute === "open-asset" && (request.method === "GET" || request.method === "HEAD");
|
|
2658
|
+
const document = openFileRoute === "open-document" && request.method === "GET";
|
|
2659
|
+
if (!asset && !document)
|
|
2660
|
+
throw new FilesError(405, "不支持此文件操作。", "method");
|
|
2661
|
+
const path = await explicitFileOpen.target(workspaceId, root, url.searchParams.get("ticket") ?? "");
|
|
2662
|
+
if (asset)
|
|
2663
|
+
await respondWithWorkspaceFile(request, response, path, url.searchParams.has("download"), { noFollow: true });
|
|
2664
|
+
else
|
|
2665
|
+
json(200, await readWorkspaceDocumentPreview(path, { noFollow: true }));
|
|
2666
|
+
}
|
|
2667
|
+
catch (error) {
|
|
2668
|
+
if (response.headersSent) {
|
|
2669
|
+
response.destroy();
|
|
2670
|
+
return;
|
|
2671
|
+
}
|
|
2672
|
+
const code = error?.code;
|
|
2673
|
+
if (code === "ENOENT" || code === "ENOTDIR") {
|
|
2674
|
+
json(404, { error: "文件不存在或已被移动。", code: "not_found" });
|
|
2675
|
+
return;
|
|
2676
|
+
}
|
|
2677
|
+
const described = describeFilesError(error);
|
|
2678
|
+
json(described.status, described.body);
|
|
2679
|
+
}
|
|
2680
|
+
return;
|
|
2681
|
+
}
|
|
2561
2682
|
const explorerRoute = /^\/api\/files\/(tree|upload|upload-check|asset|document)$/.exec(url.pathname)?.[1];
|
|
2562
2683
|
if (explorerRoute) {
|
|
2563
2684
|
try {
|
|
@@ -2858,13 +2979,15 @@ export function createHttpServer(options) {
|
|
|
2858
2979
|
// failure this work exists to remove. Past the deadline the answer is still returned, with
|
|
2859
2980
|
// `indexed: false` so the UI can say the index is still building rather than pretending
|
|
2860
2981
|
// the tree is empty.
|
|
2861
|
-
const
|
|
2982
|
+
const linksOnly = url.searchParams.get("links") === "1";
|
|
2983
|
+
const result = index.search(query, linksOnly);
|
|
2984
|
+
const hits = linksOnly ? result.hits.slice(0, 20) : result.hits;
|
|
2862
2985
|
json(200, {
|
|
2863
2986
|
mode: "search",
|
|
2864
2987
|
query: query.trim(),
|
|
2865
|
-
hits:
|
|
2988
|
+
hits: hits.map(({ path, name, directory, openLink }) => ({ path, name, directory, ...(openLink ? { openLink } : {}) })),
|
|
2866
2989
|
total: result.total,
|
|
2867
|
-
truncated:
|
|
2990
|
+
truncated: hits.length < result.total,
|
|
2868
2991
|
skipped: [],
|
|
2869
2992
|
indexed: result.indexed,
|
|
2870
2993
|
progress: result.progress,
|
|
@@ -6,8 +6,8 @@ export function applicableRules(rules, workspace) {
|
|
|
6
6
|
try {
|
|
7
7
|
const workspaceRegex = new RegExp(rule.workspacePattern, "i");
|
|
8
8
|
const modelRegex = new RegExp(rule.modelPattern, "i");
|
|
9
|
-
const
|
|
10
|
-
return workspaceRegex.test(
|
|
9
|
+
const paths = [workspace.path, ...(workspace.worktreeProjectPath ? [workspace.worktreeProjectPath] : [])];
|
|
10
|
+
return paths.some(path => workspaceRegex.test(path.replace(/[\\/]+/g, "/"))) ? [{ rule, modelRegex }] : [];
|
|
11
11
|
}
|
|
12
12
|
catch (error) {
|
|
13
13
|
console.warn(`模型过滤规则 ${rule.id} 无效,已跳过:${rule.workspacePattern} → ${rule.modelPattern}:${String(error)}`);
|
package/dist/server/runtime.js
CHANGED
|
@@ -26,7 +26,7 @@ import { LengthExceededError } from "./turn-failure.js";
|
|
|
26
26
|
// paths recognise a delivery identically. Re-exported because they were part of this module's surface.
|
|
27
27
|
export { describeDeliveredUserMessage, describePiQueue } from "./pi-session-events.js";
|
|
28
28
|
import { createPiSession, createSdkCatalog, piSdkAvailable, resolveTranscriptFile, superPiExtensionPaths } from "./pi-session.js";
|
|
29
|
-
import { TASK_CONVERSATION_ENV, PARENT_CONVERSATION_ENV, TASK_DEPTH_ENV, TASK_ENDPOINT_ENV, TASK_EXEC_ENDPOINT_ENV, TASK_ROSTER_ENV, TASK_TOOL_NAME, TODO_ENDPOINT_ENV, TODO_TOOL_NAME, PROJECT_TOOL_NAME, PROJECT_ENDPOINT_ENV, SCHEDULED_TASK_ENDPOINT_ENV, SCHEDULED_TASK_TOOL_NAME, WORKFLOW_ENDPOINT_ENV, WORKFLOW_TOOL_NAME, RUN_ASYNC_TOOL_NAME, ORCHESTRATOR_ENDPOINT_ENV, ORCHESTRATOR_WORKSPACE_ENV, SESSION_SPAWN_TOOL_NAME, SESSION_STATUS_TOOL_NAME, SESSION_DISPATCH_TOOL_NAME, SESSION_STOP_TOOL_NAME, SESSION_REPORT_TOOL_NAME, SESSION_STOP_SUBTREE_TOOL_NAME, SESSION_REMOVE_TOOL_NAME, SESSION_REMINDER_TOOL_NAME, rosterPayload, } from "./task-tool.js";
|
|
29
|
+
import { TASK_CONVERSATION_ENV, PARENT_CONVERSATION_ENV, TASK_DEPTH_ENV, TASK_ENDPOINT_ENV, TASK_EXEC_ENDPOINT_ENV, TASK_ROSTER_ENV, TASK_TOOL_NAME, TODO_ENDPOINT_ENV, TODO_TOOL_NAME, PROJECT_TOOL_NAME, PROJECT_ENDPOINT_ENV, SCHEDULED_TASK_ENDPOINT_ENV, SCHEDULED_TASK_TOOL_NAME, WORKFLOW_ENDPOINT_ENV, WORKFLOW_TOOL_NAME, RUN_ASYNC_TOOL_NAME, ORCHESTRATOR_ENDPOINT_ENV, ORCHESTRATOR_WORKSPACE_ENV, WORKTREE_TOOL_NAME, SESSION_SPAWN_TOOL_NAME, SESSION_STATUS_TOOL_NAME, SESSION_DISPATCH_TOOL_NAME, SESSION_STOP_TOOL_NAME, SESSION_REPORT_TOOL_NAME, SESSION_STOP_SUBTREE_TOOL_NAME, SESSION_REMOVE_TOOL_NAME, SESSION_REMINDER_TOOL_NAME, rosterPayload, } from "./task-tool.js";
|
|
30
30
|
import { BLOCKING_UI_METHODS, EXTENSION_UI_METHODS, } from "./types.js";
|
|
31
31
|
import { loadConversationImages } from "./upload.js";
|
|
32
32
|
import { describeToolCall, describeToolCallArgs, describeToolCallInProgress, extractPartialResultText, extractToolResultText, readQuestionCall } from "./tool-calls.js";
|
|
@@ -1268,7 +1268,7 @@ export class PiRpcRuntime {
|
|
|
1268
1268
|
if (this.options.orchestratorEndpoint)
|
|
1269
1269
|
names.push(PROJECT_TOOL_NAME);
|
|
1270
1270
|
if (this.options.orchestratorEndpoint)
|
|
1271
|
-
names.push(SESSION_SPAWN_TOOL_NAME, SESSION_STATUS_TOOL_NAME, SESSION_DISPATCH_TOOL_NAME, SESSION_STOP_TOOL_NAME, SESSION_REPORT_TOOL_NAME, SESSION_STOP_SUBTREE_TOOL_NAME, SESSION_REMOVE_TOOL_NAME);
|
|
1271
|
+
names.push(WORKTREE_TOOL_NAME, SESSION_SPAWN_TOOL_NAME, SESSION_STATUS_TOOL_NAME, SESSION_DISPATCH_TOOL_NAME, SESSION_STOP_TOOL_NAME, SESSION_REPORT_TOOL_NAME, SESSION_STOP_SUBTREE_TOOL_NAME, SESSION_REMOVE_TOOL_NAME);
|
|
1272
1272
|
// THE REMINDER TOOL IS A SESSION TOOL, SO IT IS NAMED WHERE THE OTHER SESSION TOOLS ARE
|
|
1273
1273
|
// NAMED - on its own line, because the line above is a pinned list and this one belongs to it.
|
|
1274
1274
|
if (this.options.orchestratorEndpoint)
|
|
@@ -1491,7 +1491,7 @@ export class PiRpcRuntime {
|
|
|
1491
1491
|
// allowlist and naming a tool Pi has not registered would change the spawn line for every other
|
|
1492
1492
|
// mode. The prompt asks for a bare JSON array and nothing else; if the model spends a turn on a
|
|
1493
1493
|
// tool call anyway the reranker times out and falls back to the lexical order.
|
|
1494
|
-
const agentArgs = memoryReview ? ["--no-extensions", "--no-skills", "--no-mcp", "--no-context-files", "--no-prompt-templates", "--tools", "memory,skill_manage,session_search"] : knowledgeRerank ? ["--no-extensions", "--no-skills", "--no-mcp", "--no-context-files", "--no-prompt-templates"] : await agentSpawnArgs(this.agents.promptDir, agent, { extraAllowedTools: [...(extensionArgs.length ? [TASK_TOOL_NAME, TODO_TOOL_NAME, PROJECT_TOOL_NAME, WORKFLOW_TOOL_NAME, RUN_ASYNC_TOOL_NAME, SCHEDULED_TASK_TOOL_NAME, "question", "tool_register", ...(this.options.orchestratorEndpoint ? [SESSION_SPAWN_TOOL_NAME, SESSION_STATUS_TOOL_NAME, SESSION_DISPATCH_TOOL_NAME, SESSION_STOP_TOOL_NAME, SESSION_REPORT_TOOL_NAME, SESSION_STOP_SUBTREE_TOOL_NAME, SESSION_REMOVE_TOOL_NAME, SESSION_REMINDER_TOOL_NAME] : [])] : []), ...(memoryEnabled ? ["memory", "skill_manage", "session_search"] : []), ...(knowledgeEnabled ? [KNOWLEDGE_TOOL_NAME, KNOWLEDGE_IMPORT_TOOL_NAME] : []), ...(documentsEnabled ? [DOCUMENT_READ_TOOL_NAME, DOCUMENT_WRITE_TOOL_NAME] : []), ...(webEnabled ? [WEB_SEARCH_TOOL_NAME, WEB_FETCH_TOOL_NAME] : []), ...(feishuEnabled ? [FEISHU_READ_TOOL_NAME, FEISHU_WRITE_TOOL_NAME] : [])] });
|
|
1494
|
+
const agentArgs = memoryReview ? ["--no-extensions", "--no-skills", "--no-mcp", "--no-context-files", "--no-prompt-templates", "--tools", "memory,skill_manage,session_search"] : knowledgeRerank ? ["--no-extensions", "--no-skills", "--no-mcp", "--no-context-files", "--no-prompt-templates"] : await agentSpawnArgs(this.agents.promptDir, agent, { extraAllowedTools: [...(extensionArgs.length ? [TASK_TOOL_NAME, TODO_TOOL_NAME, PROJECT_TOOL_NAME, WORKFLOW_TOOL_NAME, RUN_ASYNC_TOOL_NAME, SCHEDULED_TASK_TOOL_NAME, "question", "tool_register", ...(this.options.orchestratorEndpoint ? [WORKTREE_TOOL_NAME, SESSION_SPAWN_TOOL_NAME, SESSION_STATUS_TOOL_NAME, SESSION_DISPATCH_TOOL_NAME, SESSION_STOP_TOOL_NAME, SESSION_REPORT_TOOL_NAME, SESSION_STOP_SUBTREE_TOOL_NAME, SESSION_REMOVE_TOOL_NAME, SESSION_REMINDER_TOOL_NAME] : [])] : []), ...(memoryEnabled ? ["memory", "skill_manage", "session_search"] : []), ...(knowledgeEnabled ? [KNOWLEDGE_TOOL_NAME, KNOWLEDGE_IMPORT_TOOL_NAME] : []), ...(documentsEnabled ? [DOCUMENT_READ_TOOL_NAME, DOCUMENT_WRITE_TOOL_NAME] : []), ...(webEnabled ? [WEB_SEARCH_TOOL_NAME, WEB_FETCH_TOOL_NAME] : []), ...(feishuEnabled ? [FEISHU_READ_TOOL_NAME, FEISHU_WRITE_TOOL_NAME] : [])] });
|
|
1495
1495
|
// Refused here, with the reason, rather than handed to the spawn: an ENOENT from `spawn` reads as
|
|
1496
1496
|
// "the app is broken" and hides the one fact that matters, which is where it looked for Pi.
|
|
1497
1497
|
if (!this.pi.found)
|
package/dist/server/store.d.ts
CHANGED
|
@@ -226,7 +226,7 @@ export declare class Store {
|
|
|
226
226
|
* So the same folder always means the same workspace id, and the id is what the conversations
|
|
227
227
|
* point at.
|
|
228
228
|
*/
|
|
229
|
-
createWorkspace(name: string, path?: string): Promise<Workspace>;
|
|
229
|
+
createWorkspace(name: string, path?: string, project?: Workspace): Promise<Workspace>;
|
|
230
230
|
renameWorkspace(workspaceId: string, name: string): Promise<Workspace>;
|
|
231
231
|
/**
|
|
232
232
|
* Replaces the workspace's two defaults. `undefined` DELETES the key rather than storing Pi's
|
|
@@ -446,6 +446,7 @@ export declare class Store {
|
|
|
446
446
|
* the Archived group renders the same name.
|
|
447
447
|
*/
|
|
448
448
|
renameConversation(conversationId: string, name: string): Promise<Conversation>;
|
|
449
|
+
followConversationWorktree(conversationId: string, worktreeId: string): Promise<void>;
|
|
449
450
|
/**
|
|
450
451
|
* Writes ONE user message into the transcript - the single place a user utterance comes into being.
|
|
451
452
|
*
|
package/dist/server/store.js
CHANGED
|
@@ -1150,7 +1150,7 @@ export class Store {
|
|
|
1150
1150
|
* So the same folder always means the same workspace id, and the id is what the conversations
|
|
1151
1151
|
* point at.
|
|
1152
1152
|
*/
|
|
1153
|
-
async createWorkspace(name, path) {
|
|
1153
|
+
async createWorkspace(name, path, project) {
|
|
1154
1154
|
const cleanName = name.trim();
|
|
1155
1155
|
if (!cleanName || cleanName.length > 80)
|
|
1156
1156
|
throw new Error("工作区名称需要 1-80 个字符。");
|
|
@@ -1163,14 +1163,23 @@ export class Store {
|
|
|
1163
1163
|
// workspace because someone typed a name into the add dialog would be its own surprise).
|
|
1164
1164
|
const existing = this.state.workspaces.find((item) => workspacePathKey(item.path) === workspacePathKey(cleanPath));
|
|
1165
1165
|
if (existing) {
|
|
1166
|
-
|
|
1166
|
+
const open = Boolean(existing.closedAt);
|
|
1167
|
+
const attach = project && project.id !== existing.id && (existing.worktreeOf !== project.id || existing.worktreeProjectPath !== project.path);
|
|
1168
|
+
if (attach) {
|
|
1169
|
+
existing.worktreeOf = project.id;
|
|
1170
|
+
existing.worktreeProjectPath = project.path;
|
|
1171
|
+
}
|
|
1172
|
+
if (open || attach) {
|
|
1167
1173
|
delete existing.closedAt;
|
|
1168
1174
|
existing.updatedAt = now();
|
|
1169
1175
|
await this.persist();
|
|
1170
1176
|
}
|
|
1171
1177
|
return structuredClone(existing);
|
|
1172
1178
|
}
|
|
1173
|
-
const workspace = { id: id("workspace"), name: cleanName, path: cleanPath, updatedAt: now()
|
|
1179
|
+
const workspace = { id: id("workspace"), name: cleanName, path: cleanPath, updatedAt: now(), ...(project ? {
|
|
1180
|
+
worktreeOf: project.id, worktreeProjectPath: project.path, defaultModel: project.defaultModel,
|
|
1181
|
+
defaultThinkingLevel: project.defaultThinkingLevel, defaultAgentId: project.defaultAgentId,
|
|
1182
|
+
} : {}) };
|
|
1174
1183
|
this.state.workspaces.push(workspace);
|
|
1175
1184
|
await this.persist();
|
|
1176
1185
|
return structuredClone(workspace);
|
|
@@ -1841,6 +1850,13 @@ export class Store {
|
|
|
1841
1850
|
await this.persistMetadata(conversationId);
|
|
1842
1851
|
return structuredClone(conversation);
|
|
1843
1852
|
}
|
|
1853
|
+
async followConversationWorktree(conversationId, worktreeId) {
|
|
1854
|
+
const conversation = this.requireConversation(conversationId);
|
|
1855
|
+
if (conversation.followedWorktreeId === worktreeId)
|
|
1856
|
+
return;
|
|
1857
|
+
conversation.followedWorktreeId = worktreeId;
|
|
1858
|
+
await this.persistMetadata(conversationId);
|
|
1859
|
+
}
|
|
1844
1860
|
/**
|
|
1845
1861
|
* Writes ONE user message into the transcript - the single place a user utterance comes into being.
|
|
1846
1862
|
*
|
|
@@ -25,6 +25,7 @@ import type { AgentDefinition, TodoItem } from "./types.js";
|
|
|
25
25
|
*/
|
|
26
26
|
/** The name the model calls. Also the key Pi's tool allowlist matches on, and the deny key in `tools:`. */
|
|
27
27
|
export declare const TASK_TOOL_NAME = "task";
|
|
28
|
+
export declare const WORKTREE_TOOL_NAME = "worktree";
|
|
28
29
|
/**
|
|
29
30
|
* The independent background-command tool. NOT a sub-agent dispatch.
|
|
30
31
|
*
|
package/dist/server/task-tool.js
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
*/
|
|
25
25
|
/** The name the model calls. Also the key Pi's tool allowlist matches on, and the deny key in `tools:`. */
|
|
26
26
|
export const TASK_TOOL_NAME = "task";
|
|
27
|
+
export const WORKTREE_TOOL_NAME = "worktree";
|
|
27
28
|
/**
|
|
28
29
|
* The independent background-command tool. NOT a sub-agent dispatch.
|
|
29
30
|
*
|