@dooc-dev/dooc 0.0.26 → 0.0.27
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/edit.global.js +280 -260
- package/dist/engine/compiler/format-collections.js +1 -1
- package/dist/engine/core/html.js +2 -4
- package/dist/engine/core/icons.js +2 -2
- package/dist/frontend/document-application.js +160 -73
- package/dist/frontend/git-style.d.ts +1 -0
- package/dist/frontend/git-style.js +172 -0
- package/dist/frontend/language-picker.d.ts +5 -1
- package/dist/frontend/language-picker.js +19 -4
- package/dist/frontend/link-preview.d.ts +2 -0
- package/dist/frontend/link-preview.js +385 -0
- package/dist/frontend/locales/eng.json +137 -3
- package/dist/frontend/locales/jpn.json +139 -5
- package/dist/frontend/locales/zho.json +137 -3
- package/dist/frontend/resource-download.js +11 -6
- package/dist/frontend/scrollbars.d.ts +1 -0
- package/dist/frontend/scrollbars.js +9 -0
- package/dist/frontend/video-ui.js +9 -3
- package/dist/manifest.global.js +188 -186
- package/dist/mcp-relay.mjs +20 -1
- package/dist/plugins.global.js +31 -31
- package/dist/server/git-origin.js +1 -1
- package/dist/server/git.js +49 -26
- package/dist/server/operation-log.js +9 -1
- package/dist/server/serve.d.ts +1 -0
- package/dist/server/serve.js +18 -7
- package/dist/server/static-client.js +4 -14
- package/dist/server/workspace-server.js +2 -1
- package/dist/subformats.global.js +57 -57
- package/dist/ui.global.js +71 -69
- package/dist/workspace/git-review.d.ts +5 -0
- package/dist/workspace/git-review.js +56 -0
- package/dist/workspace/git-types.d.ts +29 -2
- package/dist/workspace/git-types.js +5 -1
- package/dist/workspace/github.d.ts +1 -1
- package/dist/workspace/github.js +73 -9
- package/dist/workspace/mcp-tools.js +20 -1
- package/dist/workspace-worker.global.js +332 -84
- package/package.json +1 -1
- package/dist/workspace-mcp-worker.global.js +0 -3263
- package/dist/workspace-reader-mcp-worker.global.js +0 -3263
- package/dist/workspace-reader-worker.global.js +0 -3263
package/dist/server/git.js
CHANGED
|
@@ -3,6 +3,8 @@ import { createHash } from "node:crypto";
|
|
|
3
3
|
import { lstat, readFile, readlink, stat } from "node:fs/promises";
|
|
4
4
|
import { basename, join, relative } from "node:path";
|
|
5
5
|
import { manifestFile } from "../engine/compiler/manifest.js";
|
|
6
|
+
import { readGitOrigin, runGitReview } from "../workspace/git-review.js";
|
|
7
|
+
import { gitDiffSide } from "../workspace/git-types.js";
|
|
6
8
|
import { nativeGitOrigin } from "./git-origin.js";
|
|
7
9
|
import { readWorkspaceSource } from "./workspace.js";
|
|
8
10
|
export const git = (root, args, input = "") => new Promise((resolve, reject) => {
|
|
@@ -75,8 +77,9 @@ export const validateGitOrigin = (value) => {
|
|
|
75
77
|
!origin.name.trim() ||
|
|
76
78
|
typeof origin.read !== "function" ||
|
|
77
79
|
typeof origin.execute !== "function" ||
|
|
80
|
+
(origin.readFiles !== undefined && typeof origin.readFiles !== "function") ||
|
|
78
81
|
!Array.isArray(origin.capabilities) ||
|
|
79
|
-
origin.capabilities.some((action) => !["fetch", "pull", "push", "createPr", "updatePr", "mergePr"].includes(action)))
|
|
82
|
+
origin.capabilities.some((action) => !["fetch", "pull", "push", "createPr", "updatePr", "reviewPr", "mergePr"].includes(action)))
|
|
80
83
|
throw new Error("Git origin requires a name, capabilities, read and execute handlers");
|
|
81
84
|
return origin;
|
|
82
85
|
};
|
|
@@ -133,8 +136,22 @@ export const createGitHandler = (documentRoot, getOrigin) => {
|
|
|
133
136
|
hash.update(`deleted:${change.path}`);
|
|
134
137
|
}
|
|
135
138
|
}
|
|
136
|
-
const
|
|
137
|
-
|
|
139
|
+
const tracking = upstream ||
|
|
140
|
+
(branch && head && remote
|
|
141
|
+
? await git(root, [
|
|
142
|
+
"show-ref",
|
|
143
|
+
"--verify",
|
|
144
|
+
"--quiet",
|
|
145
|
+
`refs/remotes/origin/${branch}`,
|
|
146
|
+
]).then(() => `origin/${branch}`, () => "")
|
|
147
|
+
: "");
|
|
148
|
+
const counts = tracking && head
|
|
149
|
+
? (await git(root, [
|
|
150
|
+
"rev-list",
|
|
151
|
+
"--left-right",
|
|
152
|
+
"--count",
|
|
153
|
+
upstream ? "HEAD...@{upstream}" : `HEAD...refs/remotes/origin/${branch}`,
|
|
154
|
+
]))
|
|
138
155
|
.trim()
|
|
139
156
|
.split(/\s+/)
|
|
140
157
|
: [];
|
|
@@ -152,6 +169,7 @@ export const createGitHandler = (documentRoot, getOrigin) => {
|
|
|
152
169
|
version: hash.digest("hex"),
|
|
153
170
|
branches: branches.trim().split("\n").filter(Boolean),
|
|
154
171
|
changes,
|
|
172
|
+
scopedDiff: true,
|
|
155
173
|
...(stash
|
|
156
174
|
? {
|
|
157
175
|
stash: {
|
|
@@ -160,7 +178,7 @@ export const createGitHandler = (documentRoot, getOrigin) => {
|
|
|
160
178
|
},
|
|
161
179
|
}
|
|
162
180
|
: {}),
|
|
163
|
-
upstream,
|
|
181
|
+
upstream: tracking,
|
|
164
182
|
ahead: Number(counts[0] ?? 0),
|
|
165
183
|
behind: Number(counts[1] ?? 0),
|
|
166
184
|
},
|
|
@@ -190,30 +208,17 @@ export const createGitHandler = (documentRoot, getOrigin) => {
|
|
|
190
208
|
canCreate: await hasGitManifest(context.root, manifest, "HEAD"),
|
|
191
209
|
};
|
|
192
210
|
}
|
|
193
|
-
if (origin && input.action === "read")
|
|
194
|
-
|
|
195
|
-
state.origin = {
|
|
196
|
-
...(await origin.read(context)),
|
|
197
|
-
name: origin.name,
|
|
198
|
-
capabilities: origin.capabilities,
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
catch (error) {
|
|
202
|
-
state.origin = {
|
|
203
|
-
name: origin.name,
|
|
204
|
-
capabilities: origin.capabilities,
|
|
205
|
-
url: "",
|
|
206
|
-
defaultBranch: "",
|
|
207
|
-
pullRequests: [],
|
|
208
|
-
};
|
|
209
|
-
state.originError =
|
|
210
|
-
error instanceof Error ? error.message : "Origin unavailable";
|
|
211
|
-
}
|
|
212
|
-
}
|
|
211
|
+
if (origin && input.action === "read")
|
|
212
|
+
await readGitOrigin(state, origin, context, input.includePullRequests !== false, input.openPullRequestsOnly === true);
|
|
213
213
|
return state;
|
|
214
214
|
}
|
|
215
215
|
if (input.version !== state.version)
|
|
216
216
|
throw new Error("Repository changed. Reload before continuing.");
|
|
217
|
+
if (input.action === "prFiles" || input.action === "reviewPr") {
|
|
218
|
+
if (getOrigin() !== configuredOrigin)
|
|
219
|
+
throw new Error("Origin changed. Reload before continuing.");
|
|
220
|
+
return await runGitReview(origin, context, input);
|
|
221
|
+
}
|
|
217
222
|
const stashChanges = async () => {
|
|
218
223
|
if (state.stash)
|
|
219
224
|
throw new Error("Stash is occupied. Restore it before stashing more changes.");
|
|
@@ -241,7 +246,10 @@ export const createGitHandler = (documentRoot, getOrigin) => {
|
|
|
241
246
|
if (!change)
|
|
242
247
|
throw new Error("Changed file not found");
|
|
243
248
|
if (input.action === "diff") {
|
|
249
|
+
const side = gitDiffSide(input.side);
|
|
244
250
|
if (change.index === "?") {
|
|
251
|
+
if (side === "staged")
|
|
252
|
+
return { diff: "" };
|
|
245
253
|
const absolute = join(context.root, path);
|
|
246
254
|
const stat = await lstat(absolute);
|
|
247
255
|
if (stat.size > 1024 * 1024)
|
|
@@ -251,7 +259,15 @@ export const createGitHandler = (documentRoot, getOrigin) => {
|
|
|
251
259
|
: await readFile(absolute);
|
|
252
260
|
return { diff: data.includes(0) ? "Binary file" : data.toString("utf8") };
|
|
253
261
|
}
|
|
254
|
-
const args = ["--no-ext-diff", "--no-textconv", "--", path];
|
|
262
|
+
const args = ["--no-color", "--no-ext-diff", "--no-textconv", "--", path];
|
|
263
|
+
if (side)
|
|
264
|
+
return {
|
|
265
|
+
diff: await git(context.root, [
|
|
266
|
+
"diff",
|
|
267
|
+
...(side === "staged" ? ["--cached"] : []),
|
|
268
|
+
...args,
|
|
269
|
+
]),
|
|
270
|
+
};
|
|
255
271
|
const [staged, working] = await Promise.all([
|
|
256
272
|
git(context.root, ["diff", "--cached", ...args]),
|
|
257
273
|
git(context.root, ["diff", ...args]),
|
|
@@ -285,6 +301,13 @@ export const createGitHandler = (documentRoot, getOrigin) => {
|
|
|
285
301
|
if (!state.changes.some((change) => ![" ", "?"].includes(change.index)))
|
|
286
302
|
throw new Error("No staged changes");
|
|
287
303
|
await git(context.root, ["commit", "--file=-"], message);
|
|
304
|
+
return {
|
|
305
|
+
ok: true,
|
|
306
|
+
head: await git(context.root, [
|
|
307
|
+
"rev-parse",
|
|
308
|
+
context.branch ? `refs/heads/${context.branch}` : "HEAD",
|
|
309
|
+
]).then((value) => value.trim(), () => ""),
|
|
310
|
+
};
|
|
288
311
|
}
|
|
289
312
|
else if (input.action === "switch" || input.action === "branch") {
|
|
290
313
|
const branch = text(input.branch, 256);
|
|
@@ -341,7 +364,7 @@ export const createGitHandler = (documentRoot, getOrigin) => {
|
|
|
341
364
|
else if (input.action === "updatePr" || input.action === "mergePr") {
|
|
342
365
|
if (!Number.isSafeInteger(input.number) || Number(input.number) < 1)
|
|
343
366
|
throw new Error("Invalid pull request number");
|
|
344
|
-
const previous = (await origin.read(context)).pullRequests.find((pr) => pr.number === input.number);
|
|
367
|
+
const previous = (await origin.read(context, true)).pullRequests.find((pr) => pr.number === input.number);
|
|
345
368
|
if (!previous || JSON.stringify(previous) !== input.revision)
|
|
346
369
|
throw new Error("Pull request changed. Reload before continuing.");
|
|
347
370
|
if (input.action === "updatePr") {
|
|
@@ -22,7 +22,15 @@ export const loggedWorkspaceOps = (ops) => Object.fromEntries(Object.entries(ops
|
|
|
22
22
|
async (input, session) => {
|
|
23
23
|
const action = typeof input.action === "string" ? input.action : "";
|
|
24
24
|
const visible = ["files", "git", "history", "workspaces"].includes(name) &&
|
|
25
|
-
![
|
|
25
|
+
![
|
|
26
|
+
"read",
|
|
27
|
+
"list",
|
|
28
|
+
"complete",
|
|
29
|
+
"diff",
|
|
30
|
+
"prFiles",
|
|
31
|
+
"branches",
|
|
32
|
+
"contribute",
|
|
33
|
+
].includes(action);
|
|
26
34
|
try {
|
|
27
35
|
const result = await operation(input, session);
|
|
28
36
|
if (name === "http" && result && typeof result === "object") {
|
package/dist/server/serve.d.ts
CHANGED
|
@@ -63,6 +63,7 @@ export interface BundleCache {
|
|
|
63
63
|
clear: () => void;
|
|
64
64
|
}
|
|
65
65
|
export declare const createBundleCache: () => BundleCache;
|
|
66
|
+
export declare const bundleWorkspace: (readOnly?: boolean, mcp?: boolean) => Promise<Buffer>;
|
|
66
67
|
/** Minified client bundle shared by local viewing and published HTML. */
|
|
67
68
|
export declare const bundleClient: (entry: string) => Promise<string>;
|
|
68
69
|
/** Shared ESM diagram chunks for local readers and split publications. */
|
package/dist/server/serve.js
CHANGED
|
@@ -86,25 +86,36 @@ const PREBUILT = {
|
|
|
86
86
|
"edit-client.ts": "edit.global.js",
|
|
87
87
|
"manifest-client.ts": "manifest.global.js",
|
|
88
88
|
"client-entry.ts": "client.global.js",
|
|
89
|
-
"workspace-worker.ts": "workspace-worker.global.js",
|
|
90
89
|
"ui-client.ts": "ui.global.js",
|
|
91
90
|
"code-highlight.ts": "code.global.js",
|
|
92
91
|
"code-worker.ts": "code-worker.global.js",
|
|
93
92
|
"published-plugins.ts": "plugins.global.js",
|
|
94
93
|
"published-subformats.ts": "subformats.global.js",
|
|
95
94
|
};
|
|
95
|
+
export const bundleWorkspace = async (readOnly = false, mcp = false) => {
|
|
96
|
+
if (usePrebuiltAssets) {
|
|
97
|
+
// Fix capabilities in the generated script, never in client initialization messages.
|
|
98
|
+
return Buffer.concat([
|
|
99
|
+
Buffer.from(`const DOOC_READ_ONLY=${readOnly === true},DOOC_MCP=${mcp === true};\n`),
|
|
100
|
+
readReaderAsset("workspace-worker.global.js"),
|
|
101
|
+
]);
|
|
102
|
+
}
|
|
103
|
+
const script = new URL("../../../scripts/build/client.mjs", import.meta.url).href;
|
|
104
|
+
const { buildBrowserWorkspace } = await import(script);
|
|
105
|
+
const result = await buildBrowserWorkspace({
|
|
106
|
+
write: false,
|
|
107
|
+
define: { DOOC_READ_ONLY: String(readOnly === true), DOOC_MCP: String(mcp === true) },
|
|
108
|
+
});
|
|
109
|
+
return Buffer.from(result.outputFiles[0].contents);
|
|
110
|
+
};
|
|
96
111
|
/** Minified client bundle shared by local viewing and published HTML. */
|
|
97
112
|
export const bundleClient = async (entry) => {
|
|
113
|
+
if (entry === "workspace-worker.ts")
|
|
114
|
+
return (await bundleWorkspace()).toString("utf8");
|
|
98
115
|
const prebuilt = PREBUILT[entry];
|
|
99
116
|
if (usePrebuiltAssets && prebuilt) {
|
|
100
117
|
return readReaderAsset(prebuilt).toString("utf8");
|
|
101
118
|
}
|
|
102
|
-
if (entry === "workspace-worker.ts") {
|
|
103
|
-
const script = new URL("../../../scripts/build/client.mjs", import.meta.url).href;
|
|
104
|
-
const { buildBrowserWorkspace } = await import(script);
|
|
105
|
-
const result = await buildBrowserWorkspace({ write: false });
|
|
106
|
-
return result.outputFiles[0].text;
|
|
107
|
-
}
|
|
108
119
|
const esbuild = await import("esbuild");
|
|
109
120
|
const out = await esbuild.build({
|
|
110
121
|
entryPoints: [join(frontendRoot, entry)],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { validateRelayUrl } from "../workspace/mcp-relay.js";
|
|
2
2
|
import { prebuilt, readReaderAsset } from "./assets.js";
|
|
3
|
-
import { bundleClient, clientShell } from "./serve.js";
|
|
3
|
+
import { bundleClient, bundleWorkspace, clientShell } from "./serve.js";
|
|
4
4
|
export const validateServerUrl = (value) => {
|
|
5
5
|
const url = new URL(value);
|
|
6
6
|
if (url.protocol === "http:")
|
|
@@ -62,31 +62,21 @@ export const clientAssets = async (server, options = {}) => {
|
|
|
62
62
|
files.set(`assets/${name}.js`, Buffer.from(await bundleClient(entry)));
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
+
if (options.worker !== false)
|
|
66
|
+
files.set("assets/workspace-worker.js", await bundleWorkspace(options.readOnly, !!(options.mcp || options.relayUrl)));
|
|
65
67
|
if (prebuilt) {
|
|
66
68
|
if (options.client !== false && (options.mcp || options.relayUrl))
|
|
67
69
|
files.set("assets/mcp.js", readReaderAsset("mcp-client.js"));
|
|
68
70
|
if (options.client !== false)
|
|
69
71
|
files.set("assets/client.js", readReaderAsset("client.global.js"));
|
|
70
|
-
if (options.worker !== false)
|
|
71
|
-
files.set("assets/workspace-worker.js", readReaderAsset(`workspace-${options.readOnly ? "reader-" : ""}${options.mcp || options.relayUrl ? "mcp-" : ""}worker.global.js`));
|
|
72
72
|
}
|
|
73
73
|
else {
|
|
74
74
|
const buildScript = new URL("../../../scripts/build/client.mjs", import.meta.url).href;
|
|
75
|
-
const {
|
|
75
|
+
const { buildClientEntry, buildMcpClient } = await import(buildScript);
|
|
76
76
|
if (options.client !== false && (options.mcp || options.relayUrl)) {
|
|
77
77
|
const mcp = await buildMcpClient({ write: false });
|
|
78
78
|
files.set("assets/mcp.js", Buffer.from(mcp.outputFiles[0].contents));
|
|
79
79
|
}
|
|
80
|
-
if (options.worker !== false) {
|
|
81
|
-
const worker = await buildBrowserWorkspace({
|
|
82
|
-
write: false,
|
|
83
|
-
define: {
|
|
84
|
-
DOOC_READ_ONLY: String(options.readOnly === true),
|
|
85
|
-
DOOC_MCP: String(!!(options.mcp || options.relayUrl)),
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
files.set("assets/workspace-worker.js", Buffer.from(worker.outputFiles[0].contents));
|
|
89
|
-
}
|
|
90
80
|
if (options.client !== false) {
|
|
91
81
|
const client = await buildClientEntry({ write: false });
|
|
92
82
|
files.set("assets/client.js", Buffer.from(client.outputFiles[0].contents));
|
|
@@ -383,7 +383,8 @@ export const nodeWorkspaceOperations = async (manifest, pluginModule, notify = (
|
|
|
383
383
|
};
|
|
384
384
|
const reading = (name === "http" && input.method === "GET") ||
|
|
385
385
|
(name === "files" && ["read", "complete"].includes(String(input.action))) ||
|
|
386
|
-
(name === "git" &&
|
|
386
|
+
(name === "git" &&
|
|
387
|
+
["read", "branches", "diff", "prFiles"].includes(String(input.action)));
|
|
387
388
|
const active = reads.get(id) ?? new Set();
|
|
388
389
|
reads.set(id, active);
|
|
389
390
|
// Reads share a snapshot between writes; slow remote Git reads do not hold up navigation.
|