@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.
Files changed (42) hide show
  1. package/dist/edit.global.js +280 -260
  2. package/dist/engine/compiler/format-collections.js +1 -1
  3. package/dist/engine/core/html.js +2 -4
  4. package/dist/engine/core/icons.js +2 -2
  5. package/dist/frontend/document-application.js +160 -73
  6. package/dist/frontend/git-style.d.ts +1 -0
  7. package/dist/frontend/git-style.js +172 -0
  8. package/dist/frontend/language-picker.d.ts +5 -1
  9. package/dist/frontend/language-picker.js +19 -4
  10. package/dist/frontend/link-preview.d.ts +2 -0
  11. package/dist/frontend/link-preview.js +385 -0
  12. package/dist/frontend/locales/eng.json +137 -3
  13. package/dist/frontend/locales/jpn.json +139 -5
  14. package/dist/frontend/locales/zho.json +137 -3
  15. package/dist/frontend/resource-download.js +11 -6
  16. package/dist/frontend/scrollbars.d.ts +1 -0
  17. package/dist/frontend/scrollbars.js +9 -0
  18. package/dist/frontend/video-ui.js +9 -3
  19. package/dist/manifest.global.js +188 -186
  20. package/dist/mcp-relay.mjs +20 -1
  21. package/dist/plugins.global.js +31 -31
  22. package/dist/server/git-origin.js +1 -1
  23. package/dist/server/git.js +49 -26
  24. package/dist/server/operation-log.js +9 -1
  25. package/dist/server/serve.d.ts +1 -0
  26. package/dist/server/serve.js +18 -7
  27. package/dist/server/static-client.js +4 -14
  28. package/dist/server/workspace-server.js +2 -1
  29. package/dist/subformats.global.js +57 -57
  30. package/dist/ui.global.js +71 -69
  31. package/dist/workspace/git-review.d.ts +5 -0
  32. package/dist/workspace/git-review.js +56 -0
  33. package/dist/workspace/git-types.d.ts +29 -2
  34. package/dist/workspace/git-types.js +5 -1
  35. package/dist/workspace/github.d.ts +1 -1
  36. package/dist/workspace/github.js +73 -9
  37. package/dist/workspace/mcp-tools.js +20 -1
  38. package/dist/workspace-worker.global.js +332 -84
  39. package/package.json +1 -1
  40. package/dist/workspace-mcp-worker.global.js +0 -3263
  41. package/dist/workspace-reader-mcp-worker.global.js +0 -3263
  42. package/dist/workspace-reader-worker.global.js +0 -3263
@@ -0,0 +1,5 @@
1
+ import type { GitContext, GitOrigin, GitState } from "./git-types.js";
2
+ export declare const readGitOrigin: (state: GitState, origin: GitOrigin, context: GitContext, includePullRequests: boolean, openOnly: boolean) => Promise<void>;
3
+ export declare const runGitReview: (origin: GitOrigin | undefined, context: GitContext, input: Record<string, unknown>) => Promise<import("./git-types.js").GitReviewFiles | {
4
+ ok: boolean;
5
+ }>;
@@ -0,0 +1,56 @@
1
+ export const readGitOrigin = async (state, origin, context, includePullRequests, openOnly) => {
2
+ let data = { url: "", defaultBranch: "", pullRequests: [] };
3
+ if (includePullRequests) {
4
+ try {
5
+ data = await origin.read(context, openOnly);
6
+ if (openOnly)
7
+ state.openPullRequestsOnly = true;
8
+ }
9
+ catch (error) {
10
+ state.originError = error instanceof Error ? error.message : String(error);
11
+ }
12
+ }
13
+ else
14
+ state.pullRequestsLoaded = false;
15
+ state.origin = {
16
+ ...data,
17
+ name: origin.name,
18
+ capabilities: origin.capabilities,
19
+ ...(origin.readFiles ? { canReadFiles: true } : {}),
20
+ };
21
+ };
22
+ export const runGitReview = async (origin, context, input) => {
23
+ const { number, headCommit, base, baseCommit } = input;
24
+ const oid = (value) => typeof value === "string" && /^(?:[a-f\d]{40}|[a-f\d]{64})$/i.test(value);
25
+ if (typeof number !== "number" ||
26
+ !Number.isSafeInteger(number) ||
27
+ number < 1 ||
28
+ !oid(headCommit) ||
29
+ (baseCommit !== undefined && !oid(baseCommit)) ||
30
+ typeof base !== "string" ||
31
+ !base.trim() ||
32
+ base.length > 256 ||
33
+ base.includes("\0"))
34
+ throw new Error("Invalid pull request revision");
35
+ const target = { number, headCommit, base, ...(baseCommit ? { baseCommit } : {}) };
36
+ if (input.action === "prFiles") {
37
+ const page = input.page ?? 1;
38
+ if (typeof page !== "number" || !Number.isSafeInteger(page) || page < 1)
39
+ throw new Error("Invalid pull request file page");
40
+ if (!origin?.readFiles)
41
+ throw new Error("Pull request files are unavailable");
42
+ return origin.readFiles(context, target, page);
43
+ }
44
+ const { event, body } = input;
45
+ if (!origin?.capabilities.includes("reviewPr"))
46
+ throw new Error("Pull request reviews are unavailable");
47
+ if (event !== "APPROVE" && event !== "REQUEST_CHANGES" && event !== "COMMENT")
48
+ throw new Error("Invalid review decision");
49
+ if (typeof body !== "string" ||
50
+ body.length > 65_536 ||
51
+ body.includes("\0") ||
52
+ (event !== "APPROVE" && !body.trim()))
53
+ throw new Error("Enter a review comment");
54
+ await origin.execute(context, { action: "reviewPr", ...target, event, body });
55
+ return { ok: true };
56
+ };
@@ -9,7 +9,10 @@ export interface GitPullRequest {
9
9
  body: string;
10
10
  url: string;
11
11
  head: string;
12
+ /** Qualified source branch when the pull request comes from a fork. */
13
+ forkHead?: string;
12
14
  base: string;
15
+ baseCommit?: string;
13
16
  headCommit: string;
14
17
  draft: boolean;
15
18
  status: string;
@@ -20,6 +23,19 @@ export interface GitOriginState {
20
23
  defaultBranch: string;
21
24
  pullRequests: GitPullRequest[];
22
25
  }
26
+ export type GitReviewTarget = Pick<GitPullRequest, "number" | "headCommit" | "base" | "baseCommit">;
27
+ export type GitReviewEvent = "COMMENT" | "APPROVE" | "REQUEST_CHANGES";
28
+ export interface GitReviewFiles {
29
+ files: {
30
+ path: string;
31
+ previousPath?: string;
32
+ additions: number;
33
+ deletions: number;
34
+ patch?: string;
35
+ }[];
36
+ nextPage?: number;
37
+ limited?: boolean;
38
+ }
23
39
  export type GitOriginAction = {
24
40
  action: "fetch" | "pull" | "push";
25
41
  } | {
@@ -34,7 +50,11 @@ export type GitOriginAction = {
34
50
  title: string;
35
51
  body: string;
36
52
  previous: GitPullRequest;
37
- } | {
53
+ } | ({
54
+ action: "reviewPr";
55
+ event: GitReviewEvent;
56
+ body: string;
57
+ } & GitReviewTarget) | {
38
58
  action: "mergePr";
39
59
  number: number;
40
60
  method: "merge" | "squash" | "rebase";
@@ -44,7 +64,8 @@ export type GitOriginAction = {
44
64
  export interface GitOrigin {
45
65
  name: string;
46
66
  capabilities: readonly GitOriginAction["action"][];
47
- read(context: GitContext): Promise<GitOriginState>;
67
+ read(context: GitContext, openOnly?: boolean): Promise<GitOriginState>;
68
+ readFiles?(context: GitContext, target: GitReviewTarget, page: number): Promise<GitReviewFiles>;
48
69
  execute(context: GitContext, request: GitOriginAction): Promise<void>;
49
70
  }
50
71
  export interface GitChange {
@@ -52,6 +73,8 @@ export interface GitChange {
52
73
  index: string;
53
74
  worktree: string;
54
75
  }
76
+ export type GitDiffSide = "staged" | "unstaged";
77
+ export declare const gitDiffSide: (side: unknown) => GitDiffSide | undefined;
55
78
  export interface GitState {
56
79
  repo: string;
57
80
  branch: string;
@@ -64,6 +87,7 @@ export interface GitState {
64
87
  canCreate: boolean;
65
88
  };
66
89
  changes: GitChange[];
90
+ scopedDiff?: boolean;
67
91
  localCapabilities?: string[];
68
92
  stash?: {
69
93
  id: string;
@@ -72,9 +96,12 @@ export interface GitState {
72
96
  upstream: string;
73
97
  ahead: number;
74
98
  behind: number;
99
+ pullRequestsLoaded?: false;
100
+ openPullRequestsOnly?: true;
75
101
  origin?: GitOriginState & {
76
102
  name: string;
77
103
  capabilities: readonly GitOriginAction["action"][];
104
+ canReadFiles?: boolean;
78
105
  };
79
106
  originError?: string;
80
107
  }
@@ -1 +1,5 @@
1
- export {};
1
+ export const gitDiffSide = (side) => {
2
+ if (side === undefined || side === "staged" || side === "unstaged")
3
+ return side;
4
+ throw new Error("Invalid Git diff side");
5
+ };
@@ -1,4 +1,4 @@
1
1
  import type { GitContext, GitOrigin } from "./git-types.js";
2
2
  export declare const githubRepository: (url: string) => string | undefined;
3
- export declare const createGithubOrigin: (repository: string, request: <T>(path: string, method?: string, body?: unknown) => Promise<T>, sync: (action: "fetch" | "pull" | "push", context: GitContext) => Promise<void>) => GitOrigin;
3
+ export declare const createGithubOrigin: (repository: string, request: <T>(path: string, method?: string, body?: unknown) => Promise<T>, sync: (action: "fetch" | "pull" | "push", context: GitContext) => Promise<void>, authenticated?: boolean) => GitOrigin;
4
4
  export declare const githubFetch: (token: () => string | undefined) => <T>(path: string, method?: string, body?: unknown) => Promise<T>;
@@ -5,8 +5,13 @@ const pullRequest = (pr) => ({
5
5
  body: pr.body ?? "",
6
6
  url: pr.html_url,
7
7
  head: pr.head.ref,
8
+ ...(pr.head.repo === null ||
9
+ (pr.head.repo && pr.base.repo && pr.head.repo.id !== pr.base.repo.id)
10
+ ? { forkHead: pr.head.label || `?:${pr.head.ref}` }
11
+ : {}),
8
12
  headCommit: pr.head.sha,
9
13
  base: pr.base.ref,
14
+ ...(pr.base.sha ? { baseCommit: pr.base.sha } : {}),
10
15
  draft: pr.draft,
11
16
  status: [
12
17
  pr.merged_at ? "Merged" : pr.state === "closed" ? "Closed" : "Open",
@@ -16,24 +21,72 @@ const pullRequest = (pr) => ({
16
21
  .join(" · "),
17
22
  state: pr.merged_at ? "merged" : pr.state === "closed" ? "closed" : "open",
18
23
  });
19
- export const createGithubOrigin = (repository, request, sync) => {
24
+ export const createGithubOrigin = (repository, request, sync, authenticated = false) => {
20
25
  if (!/^[\w.-]+\/[\w.-]+$/.test(repository))
21
26
  throw new Error("Invalid GitHub repository");
22
27
  const prefix = `repos/${repository}`;
28
+ const reviewed = async (target) => {
29
+ const pr = await request(`${prefix}/pulls/${target.number}`);
30
+ if (pr.head.sha !== target.headCommit ||
31
+ pr.base.ref !== target.base ||
32
+ (target.baseCommit && pr.base.sha !== target.baseCommit))
33
+ throw new Error("Pull request changed. Reload before continuing.");
34
+ return pr;
35
+ };
23
36
  return {
24
37
  name: "GitHub",
25
- capabilities: ["fetch", "pull", "push", "createPr", "updatePr", "mergePr"],
26
- async read() {
38
+ capabilities: ["fetch", "pull", "push", "createPr", "updatePr", "reviewPr", "mergePr"],
39
+ async read(_context, openOnly = false) {
27
40
  const info = await request(prefix);
28
41
  const pullRequests = [];
29
42
  for (let page = 1;; page++) {
30
- const items = await request(`${prefix}/pulls?state=all&sort=updated&direction=desc&per_page=100&page=${page}`);
31
- pullRequests.push(...items.map(pullRequest));
43
+ const items = await request(`${prefix}/pulls?state=${openOnly ? "open" : "all"}&sort=updated&direction=desc&per_page=100&page=${page}`);
44
+ const rows = items.map(pullRequest);
45
+ const ids = items.flatMap((pr) => pr.state === "open" && pr.node_id ? [pr.node_id] : []);
46
+ if (authenticated && ids.length) {
47
+ const result = await request("graphql", "POST", {
48
+ query: "query($ids: [ID!]!) { nodes(ids: $ids) { ... on PullRequest { number reviewDecision } } }",
49
+ variables: { ids },
50
+ }).catch(() => undefined);
51
+ const decisions = new Map(result?.data?.nodes?.flatMap((item) => item ? [[item.number, item.reviewDecision]] : []));
52
+ for (const row of rows) {
53
+ if (row.state !== "open")
54
+ continue;
55
+ const decision = decisions.has(row.number)
56
+ ? decisions.get(row.number)
57
+ : "REVIEW_UNAVAILABLE";
58
+ if (decision)
59
+ row.status += ` · ${decision}`;
60
+ }
61
+ }
62
+ pullRequests.push(...rows);
32
63
  if (items.length < 100)
33
64
  break;
34
65
  }
35
66
  return { url: info.html_url, defaultBranch: info.default_branch, pullRequests };
36
67
  },
68
+ async readFiles(_context, target, page) {
69
+ const size = 20;
70
+ if (page > 3000 / size)
71
+ throw new Error("GitHub's pull request file limit was reached");
72
+ const items = await request(`${prefix}/pulls/${target.number}/files?per_page=${size}&page=${page}`);
73
+ // The files endpoint tracks the live PR. Check its revisions before showing this page.
74
+ const pr = await reviewed(target);
75
+ const more = pr.changed_files === undefined
76
+ ? items.length === size
77
+ : pr.changed_files > page * size;
78
+ return {
79
+ files: items.map((file) => ({
80
+ path: file.filename,
81
+ previousPath: file.previous_filename,
82
+ additions: file.additions,
83
+ deletions: file.deletions,
84
+ patch: file.patch?.slice(0, 100_001),
85
+ })),
86
+ ...(more && page * size < 3000 ? { nextPage: page + 1 } : {}),
87
+ ...(more && page * size === 3000 ? { limited: true } : {}),
88
+ };
89
+ },
37
90
  async execute(context, input) {
38
91
  if (input.action === "fetch" || input.action === "pull" || input.action === "push")
39
92
  return sync(input.action, context);
@@ -50,11 +103,21 @@ export const createGithubOrigin = (repository, request, sync) => {
50
103
  });
51
104
  return;
52
105
  }
106
+ if (input.action === "reviewPr") {
107
+ const pr = await reviewed(input);
108
+ if (pr.state !== "open")
109
+ throw new Error("This pull request is closed");
110
+ await request(`${prefix}/pulls/${input.number}/reviews`, "POST", {
111
+ commit_id: input.headCommit,
112
+ event: input.event,
113
+ body: input.body,
114
+ });
115
+ return;
116
+ }
53
117
  if (input.action !== "updatePr" && input.action !== "mergePr")
54
118
  throw new Error("Unsupported pull request operation");
55
- const current = pullRequest(await request(`${prefix}/pulls/${input.number}`));
56
- if (current.headCommit !== input.previous.headCommit ||
57
- current.title !== input.previous.title ||
119
+ const current = pullRequest(await reviewed(input.previous));
120
+ if (current.title !== input.previous.title ||
58
121
  current.body !== input.previous.body ||
59
122
  current.state !== "open")
60
123
  throw new Error("Pull request changed. Reload before continuing.");
@@ -74,7 +137,8 @@ export const createGithubOrigin = (repository, request, sync) => {
74
137
  };
75
138
  };
76
139
  export const githubFetch = (token) => async (path, method = "GET", body) => {
77
- if (!path.startsWith("repos/") || path.includes("..") || path.startsWith("//"))
140
+ if (!(path === "graphql" && method === "POST") &&
141
+ (!path.startsWith("repos/") || path.includes("..")))
78
142
  throw new Error("Invalid GitHub API path");
79
143
  const secret = token();
80
144
  const response = await fetch(`https://api.github.com/${path}`, {
@@ -110,7 +110,7 @@ const definitions = {
110
110
  required: ["name"],
111
111
  },
112
112
  git: {
113
- description: "Git workflow in the repository containing this bundle. Read first; every other action except branches requires that state's version. diff/stage/unstage use path; commit uses message; branch creates and switches to branch; switch accepts stash=true to save dirty work in the single stash slot. Origin operations require an externally injected provider. createPr needs title/body/base/draft; updatePr needs number/title/body/revision; mergePr needs number/method/revision. PR revision must be JSON.stringify of the PR returned by read. Read again after each action.",
113
+ description: "Git workflow in the repository containing this bundle. Read first; every other action except branches requires that state's version. diff/stage/unstage use path; commit uses message; branch creates and switches to branch; switch accepts stash=true to save dirty work in the single stash slot. Use the origin capabilities returned by read. createPr needs title/body/base/draft; updatePr needs number/title/body/revision; mergePr needs number/method/revision. For updatePr and mergePr, revision must be JSON.stringify of the PR returned by read. prFiles and reviewPr take number, headCommit, base and baseCommit from that PR. prFiles accepts page, and reviewPr takes event and body. Read again after each action.",
114
114
  props: {
115
115
  action: {
116
116
  ...str,
@@ -130,11 +130,30 @@ const definitions = {
130
130
  "push",
131
131
  "createPr",
132
132
  "updatePr",
133
+ "prFiles",
134
+ "reviewPr",
133
135
  "mergePr",
134
136
  ],
135
137
  },
136
138
  version: str,
137
139
  path: str,
140
+ headCommit: str,
141
+ baseCommit: str,
142
+ page: { ...num, minimum: 1 },
143
+ event: { ...str, enum: ["COMMENT", "APPROVE", "REQUEST_CHANGES"] },
144
+ side: {
145
+ ...str,
146
+ enum: ["staged", "unstaged"],
147
+ description: "Limit a diff to one side of the index. Omit for both.",
148
+ },
149
+ includePullRequests: {
150
+ ...bool,
151
+ description: "Set to false to read local status without contacting a pull request provider.",
152
+ },
153
+ openPullRequestsOnly: {
154
+ ...bool,
155
+ description: "Limit the pull request list to open requests.",
156
+ },
138
157
  message: str,
139
158
  branch: str,
140
159
  stash: bool,