@evandu/super-pi 0.1.252 → 0.1.254

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.
@@ -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-D2IVVBA_.js"></script>
11
+ <script type="module" crossorigin src="/assets/index-WcUajwk6.js"></script>
12
12
  <link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-XKyaHtl9.js">
13
- <link rel="stylesheet" crossorigin href="/assets/index-CAB3S_vd.css">
13
+ <link rel="stylesheet" crossorigin href="/assets/index-BvAvBj_1.css">
14
14
  </head>
15
15
  <body>
16
16
  <div id="root"></div>
@@ -1602,11 +1602,34 @@ export function createHttpServer(options) {
1602
1602
  json(403, { error: "Git 写操作只允许来自本机或局域网的请求。" });
1603
1603
  return;
1604
1604
  }
1605
- const asked = await readRequestText(request, 512000);
1605
+ const asked = await readRequestText(request, op === "diff-edit-save" ? MAX_FILE_BYTES * 2 : 512000);
1606
1606
  if (asked.tooLarge) {
1607
1607
  json(413, { error: "请求过大" });
1608
1608
  return;
1609
1609
  }
1610
+ if (op === "diff-edit-save") {
1611
+ const body = asked.text ? JSON.parse(asked.text) : {};
1612
+ if (!body || typeof body !== "object" || Array.isArray(body)
1613
+ || typeof body.path !== "string" || typeof body.content !== "string"
1614
+ || typeof body.baseEtag !== "string") {
1615
+ json(400, { error: "差异保存需要 path、content 和 baseEtag", code: "bad_request" });
1616
+ return;
1617
+ }
1618
+ const worktreeId = url.searchParams.get("worktreeId");
1619
+ if (worktreeId !== null && !/^[a-f0-9]{64}$/.test(worktreeId)) {
1620
+ json(400, { error: "请先选择有效工作树", code: "bad_worktree" });
1621
+ return;
1622
+ }
1623
+ const checkout = worktreeId ? await resolveGitWorktree(workspace.path, worktreeId) : undefined;
1624
+ const editRoot = checkout?.path ?? workspace.path;
1625
+ const editSession = checkout?.path ?? sessionRoot;
1626
+ await explorerPath(editRoot, editSession, body.path, true);
1627
+ const path = await workspacePathFromSession(editRoot, editSession, body.path);
1628
+ const saved = await serializeWorkspaceWrite(workspace.path, () => writeWorkspaceFile(editRoot, path, body.content, body.baseEtag));
1629
+ broadcaster.broadcast({ type: "files.invalidated", workspaceId: workspace.id, paths: checkout ? [] : [path] });
1630
+ json(200, saved);
1631
+ return;
1632
+ }
1610
1633
  if (op === "draft") {
1611
1634
  if (!context.runtime?.askOnce) {
1612
1635
  json(503, { error: "未配置可生成提交说明的模型" });
@@ -1690,11 +1713,19 @@ export function createHttpServer(options) {
1690
1713
  json(400, { error: "差异编辑需要 path", code: "bad_path" });
1691
1714
  return;
1692
1715
  }
1693
- await explorerPath(workspace.path, sessionRoot, requested, true);
1694
- const path = await workspacePathFromSession(workspace.path, sessionRoot, requested);
1716
+ const worktreeId = url.searchParams.get("worktreeId");
1717
+ if (worktreeId !== null && !/^[a-f0-9]{64}$/.test(worktreeId)) {
1718
+ json(400, { error: "请先选择有效工作树", code: "bad_worktree" });
1719
+ return;
1720
+ }
1721
+ const checkout = worktreeId ? await resolveGitWorktree(workspace.path, worktreeId) : undefined;
1722
+ const editRoot = checkout?.path ?? workspace.path;
1723
+ const editSession = checkout?.path ?? sessionRoot;
1724
+ await explorerPath(editRoot, editSession, requested, true);
1725
+ const path = await workspacePathFromSession(editRoot, editSession, requested);
1695
1726
  const [original, file] = await Promise.all([
1696
- gitIndexFileContent(workspace.path, path),
1697
- readWorkspaceFile(workspace.path, path),
1727
+ gitIndexFileContent(editRoot, path),
1728
+ readWorkspaceFile(editRoot, path),
1698
1729
  ]);
1699
1730
  json(200, { path: file.path, original, content: file.content, eol: file.eol, bom: file.bom, meta: file.meta });
1700
1731
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evandu/super-pi",
3
- "version": "0.1.252",
3
+ "version": "0.1.254",
4
4
  "description": "Web control plane and companion for Pi",
5
5
  "license": "MIT",
6
6
  "type": "module",