@dooc-dev/dooc 0.0.8 → 0.0.10
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/LICENSE +21 -0
- package/README.md +18 -17
- package/dist/engine/compiler/bundle-urls.js +39 -5
- package/dist/engine/compiler/download-progress.d.ts +9 -0
- package/dist/engine/compiler/download-progress.js +12 -0
- package/dist/engine/compiler/public-file.d.ts +1 -1
- package/dist/engine/compiler/public-file.js +9 -1
- package/dist/engine/compiler/textfile-remote.js +19 -1
- package/dist/server/cli.js +87 -9
- package/dist/server/editor-tools.d.ts +36 -1
- package/dist/server/editor-tools.js +6 -1
- package/dist/server/extensions.js +5 -0
- package/dist/server/git-workspace.d.ts +8 -0
- package/dist/server/git-workspace.js +375 -0
- package/dist/server/github-archive.d.ts +1 -0
- package/dist/server/github-archive.js +92 -0
- package/dist/server/languages.js +2 -1
- package/dist/server/operation-log.d.ts +4 -0
- package/dist/server/operation-log.js +45 -0
- package/dist/server/self.js +4 -47
- package/dist/server/serve.js +19 -11
- package/dist/server/static-client.js +2 -1
- package/dist/server/terminal.d.ts +22 -0
- package/dist/server/terminal.js +131 -0
- package/dist/server/workspace-server.js +7 -2
- package/dist/server/workspace-trust.d.ts +2 -0
- package/dist/server/workspace-trust.js +2 -0
- package/dist/workspace/editor-tools.d.ts +3 -3
- package/dist/workspace/editor-tools.js +25 -16
- package/dist/workspace-worker.global.js +8 -8
- package/package.json +3 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dooc contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
# dooc
|
|
2
|
-
dooc is an orchestration tool for documentation.
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
2. Build an interface for those resources.
|
|
6
|
-
3. Distribute documentation everywhere.
|
|
3
|
+

|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
pnpm exec dooc export zip [root] [out] # zip of the content (<root>/dist/<root name>.zip)
|
|
13
|
-
pnpm exec dooc export html [root] [out] # single HTML file with everything embedded (<root>/dist/index.html)
|
|
14
|
-
pnpm exec dooc mcp [root] # stdio MCP server (all read / write operations)
|
|
15
|
-
```
|
|
5
|
+
dooc turns a folder of Markdown, data files, and schema-backed records into one browsable document.
|
|
6
|
+
`dooc.yaml` arranges the files; dooc edits, checks, and ships them as a single HTML file.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
16
9
|
|
|
17
|
-
|
|
10
|
+
| Method | Command |
|
|
11
|
+
| -------- | -------------------------------------------------------------------------------------------- |
|
|
12
|
+
| npm | `npm install -g @dooc-dev/dooc` |
|
|
13
|
+
| curl | `curl -fsSL https://github.com/dooc-dev/dooc/releases/latest/download/install.sh \| sh` |
|
|
14
|
+
| mise | `mise use -g github:dooc-dev/dooc@latest` |
|
|
15
|
+
| Homebrew | `brew tap dooc-dev/dooc https://github.com/dooc-dev/dooc && brew install dooc-dev/dooc/dooc` |
|
|
16
|
+
|
|
17
|
+
## Documentation
|
|
18
18
|
|
|
19
19
|
```sh
|
|
20
|
-
|
|
20
|
+
dooc view dooc-docs --repo https://github.com/dooc-dev/dooc.git
|
|
21
|
+
dooc edit dooc-docs --repo https://github.com/dooc-dev/dooc.git
|
|
21
22
|
```
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
# Folder structure
|
|
24
|
+
Requires Git. `view` opens a temporary read-only copy; `edit` keeps a local clone and preserves your changes.
|
|
26
25
|
|
|
26
|
+
## License
|
|
27
27
|
|
|
28
|
+
[MIT](LICENSE)
|
|
@@ -4,6 +4,7 @@ import valueParser from "postcss-value-parser";
|
|
|
4
4
|
import { embeddedImages, parseMdast } from "../core/markdown.js";
|
|
5
5
|
import { isRemoteTextfile } from "../core/textfile.js";
|
|
6
6
|
import { collectRefs } from "./dialect.js";
|
|
7
|
+
import { reportDownloadProgress } from "./download-progress.js";
|
|
7
8
|
import { createHash, fetchPublicFile, posix, readFileSync } from "./host.js";
|
|
8
9
|
import { assertNotIgnored } from "./ignored-files.js";
|
|
9
10
|
import { readManifest } from "./manifest.js";
|
|
@@ -74,11 +75,44 @@ export const embedBundleUrls = async (root, entries, resolvePlugin) => {
|
|
|
74
75
|
if (url.protocol === "https:" && ++downloads > 256)
|
|
75
76
|
throw new Error("Bundle exceeds 256 remote assets");
|
|
76
77
|
let type = "";
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
let data;
|
|
79
|
+
if (url.protocol === "bundle:") {
|
|
80
|
+
data = readFileSync(textfilePath(root, decodeURIComponent(url.pathname.slice(1))));
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
let received = 0;
|
|
84
|
+
let length;
|
|
85
|
+
reportDownloadProgress({ url: key, state: "start", received });
|
|
86
|
+
try {
|
|
87
|
+
data = await fetchPublicFile(url.href, (value) => {
|
|
88
|
+
type = value.split(";")[0]?.trim().toLowerCase() ?? "";
|
|
89
|
+
}, (size, value) => {
|
|
90
|
+
received = size;
|
|
91
|
+
length = value;
|
|
92
|
+
reportDownloadProgress({
|
|
93
|
+
url: key,
|
|
94
|
+
state: "progress",
|
|
95
|
+
received,
|
|
96
|
+
total: length,
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
reportDownloadProgress({
|
|
100
|
+
url: key,
|
|
101
|
+
state: "complete",
|
|
102
|
+
received: data.length,
|
|
103
|
+
total: length,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
reportDownloadProgress({
|
|
108
|
+
url: key,
|
|
109
|
+
state: "error",
|
|
110
|
+
received,
|
|
111
|
+
total: length,
|
|
112
|
+
});
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
82
116
|
if (url.protocol === "https:")
|
|
83
117
|
total += data.length;
|
|
84
118
|
if (total > 64 * 1024 * 1024)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type DownloadProgress = {
|
|
2
|
+
url: string;
|
|
3
|
+
state: "start" | "progress" | "complete" | "error";
|
|
4
|
+
received: number;
|
|
5
|
+
total?: number;
|
|
6
|
+
detail?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const setDownloadProgressListener: (value?: (event: DownloadProgress) => void) => void;
|
|
9
|
+
export declare const reportDownloadProgress: (event: DownloadProgress) => void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
let listener;
|
|
2
|
+
export const setDownloadProgressListener = (value) => {
|
|
3
|
+
listener = value;
|
|
4
|
+
};
|
|
5
|
+
export const reportDownloadProgress = (event) => {
|
|
6
|
+
try {
|
|
7
|
+
listener?.(event);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
// Reporting must not interrupt downloads or replace their errors.
|
|
11
|
+
}
|
|
12
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Self-contained: the synchronous compiler also runs this function in a bounded child process. */
|
|
2
|
-
export declare function fetchPublicFile(source: string, contentType?: (type: string) => void): Promise<Buffer>;
|
|
2
|
+
export declare function fetchPublicFile(source: string, contentType?: (type: string) => void, progress?: (received: number, total?: number) => void): Promise<Buffer>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Self-contained: the synchronous compiler also runs this function in a bounded child process. */
|
|
2
|
-
export async function fetchPublicFile(source, contentType) {
|
|
2
|
+
export async function fetchPublicFile(source, contentType, progress) {
|
|
3
3
|
const { request } = await import("node:https");
|
|
4
4
|
const { lookup } = await import("node:dns/promises");
|
|
5
5
|
const { BlockList, isIP } = await import("node:net");
|
|
@@ -72,10 +72,18 @@ export async function fetchPublicFile(source, contentType) {
|
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
74
|
contentType?.(response.headers["content-type"] ?? "");
|
|
75
|
+
const length = response.headers["content-length"];
|
|
76
|
+
const total = typeof length === "string" &&
|
|
77
|
+
/^\d+$/.test(length) &&
|
|
78
|
+
Number.isSafeInteger(Number(length))
|
|
79
|
+
? Number(length)
|
|
80
|
+
: undefined;
|
|
81
|
+
progress?.(0, total);
|
|
75
82
|
const chunks = [];
|
|
76
83
|
let size = 0;
|
|
77
84
|
response.on("data", (chunk) => {
|
|
78
85
|
size += chunk.length;
|
|
86
|
+
progress?.(size, total);
|
|
79
87
|
if (size > 2 * 1024 * 1024) {
|
|
80
88
|
response.destroy();
|
|
81
89
|
reject(new Error("UNAVAILABLE"));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { allowedPreviewUrl } from "../core/previewers.js";
|
|
2
|
+
import { reportDownloadProgress } from "./download-progress.js";
|
|
2
3
|
import { execFileSync, fetchPublicFile } from "./host.js";
|
|
3
4
|
export class TextfileUnavailable extends Error {
|
|
4
5
|
reason;
|
|
@@ -65,10 +66,24 @@ export const readRemoteTextfileAsync = async (file, domains, refresh = false) =>
|
|
|
65
66
|
return active;
|
|
66
67
|
const task = (async () => {
|
|
67
68
|
let result;
|
|
69
|
+
let received = 0;
|
|
70
|
+
let total;
|
|
71
|
+
reportDownloadProgress({ url: source.url, state: "start", received });
|
|
68
72
|
try {
|
|
69
|
-
result = await fetchPublicFile(source.url)
|
|
73
|
+
result = await fetchPublicFile(source.url, undefined, (size, length) => {
|
|
74
|
+
received = size;
|
|
75
|
+
total = length;
|
|
76
|
+
reportDownloadProgress({ url: source.url, state: "progress", received, total });
|
|
77
|
+
});
|
|
78
|
+
reportDownloadProgress({
|
|
79
|
+
url: source.url,
|
|
80
|
+
state: "complete",
|
|
81
|
+
received: result.length,
|
|
82
|
+
total,
|
|
83
|
+
});
|
|
70
84
|
}
|
|
71
85
|
catch (error) {
|
|
86
|
+
reportDownloadProgress({ url: source.url, state: "error", received, total });
|
|
72
87
|
if (error.message === "BLOCKED")
|
|
73
88
|
throw new Error("External previews require a public network address");
|
|
74
89
|
result = new TextfileUnavailable(error.message === "NOT_FOUND" ? "missing" : "unreachable");
|
|
@@ -101,6 +116,7 @@ export const readRemoteTextfile = (file, domains, refresh = false) => {
|
|
|
101
116
|
return cached.result;
|
|
102
117
|
}
|
|
103
118
|
let result;
|
|
119
|
+
reportDownloadProgress({ url: source.url, state: "start", received: 0 });
|
|
104
120
|
try {
|
|
105
121
|
result = execFileSync(process.execPath, ["--input-type=module", "-e", FETCH, source.url], {
|
|
106
122
|
timeout: 12000,
|
|
@@ -108,8 +124,10 @@ export const readRemoteTextfile = (file, domains, refresh = false) => {
|
|
|
108
124
|
stdio: ["ignore", "pipe", "pipe"],
|
|
109
125
|
env: { PATH: process.env.PATH },
|
|
110
126
|
});
|
|
127
|
+
reportDownloadProgress({ url: source.url, state: "complete", received: result.length });
|
|
111
128
|
}
|
|
112
129
|
catch (error) {
|
|
130
|
+
reportDownloadProgress({ url: source.url, state: "error", received: 0 });
|
|
113
131
|
if (error.status === 45)
|
|
114
132
|
throw new Error("External previews require a public network address");
|
|
115
133
|
result = new TextfileUnavailable(error.status === 44 ? "missing" : "unreachable");
|
package/dist/server/cli.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// CLI entry shared by npx and mise. The manifest defaults to ./dooc.yaml; project paths use its parent directory.
|
|
3
|
-
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
-
import { basename, dirname, join, resolve } from "node:path";
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
5
6
|
import { parseArgs } from "node:util";
|
|
7
|
+
import { setDownloadProgressListener } from "../engine/compiler/download-progress.js";
|
|
6
8
|
import { projectRoot } from "../engine/compiler/manifest.js";
|
|
7
9
|
import { isManifestFile, MANIFEST_FILE, serializeManifest, } from "../engine/core/content-metadata.js";
|
|
8
10
|
import { prebuilt } from "./assets.js";
|
|
11
|
+
import { terminal } from "./terminal.js";
|
|
9
12
|
process.env.NODE_ENV = prebuilt ? "production" : "development";
|
|
10
13
|
const USAGE = `usage: dooc <command>
|
|
11
14
|
|
|
12
15
|
commands:
|
|
13
16
|
init [path] create a manifest in a directory or at a manifest path
|
|
14
|
-
edit [
|
|
17
|
+
edit [path] [port] edit a local workspace or a path in a Git repository
|
|
18
|
+
--repo <git-url> resolve the path inside a cloned repository
|
|
15
19
|
--viewer-plugins <module> inject an external viewer plugin module
|
|
16
20
|
--shared <branch> several people edit; snapshots are recorded on <branch>
|
|
17
21
|
--tls-cert <pem> --tls-key <pem> serve over HTTPS (or DOOC_TLS_CERT / DOOC_TLS_KEY)
|
|
@@ -19,7 +23,8 @@ commands:
|
|
|
19
23
|
--client-origin <origin> permit the static client origin (default: http://localhost:5180)
|
|
20
24
|
client [port] serve the static client only (default: 5180)
|
|
21
25
|
--server <ws-url> connect to an optional workspace server
|
|
22
|
-
view [
|
|
26
|
+
view [path] [port] view a local workspace or a path in a Git repository
|
|
27
|
+
--repo <git-url> resolve the path inside a cloned repository
|
|
23
28
|
--viewer-plugins <module> inject an external viewer plugin module
|
|
24
29
|
--tls-cert <pem> --tls-key <pem> serve over HTTPS (or DOOC_TLS_CERT / DOOC_TLS_KEY)
|
|
25
30
|
build build the selected bundle (default <project>/dist)
|
|
@@ -50,10 +55,13 @@ commands:
|
|
|
50
55
|
--git-origin <module> inject gitOrigin from an external viewer plugin module
|
|
51
56
|
help, --help, -h show this help
|
|
52
57
|
|
|
53
|
-
Details: dooc <command> --help (init, build, check, plugin, font, self, mcp).
|
|
58
|
+
Details: dooc <command> --help (init, edit, view, build, check, plugin, font, self, mcp).
|
|
54
59
|
Default manifest: ./dooc.yaml. Named manifests (<name>.dooc.yaml) are also accepted.
|
|
60
|
+
Paths use the current directory, or the repository root when --repo is given.
|
|
61
|
+
Example: dooc view dooc-docs --repo https://github.com/dooc-dev/dooc.git
|
|
55
62
|
Paths and .dooc/ are relative to the selected manifest's directory.`;
|
|
56
63
|
const fail = (message) => {
|
|
64
|
+
terminal.close();
|
|
57
65
|
console.error(message);
|
|
58
66
|
process.exit(1);
|
|
59
67
|
};
|
|
@@ -62,6 +70,8 @@ const writeOut = (out, data) => {
|
|
|
62
70
|
writeFileSync(out, data);
|
|
63
71
|
};
|
|
64
72
|
const [command, ...args] = process.argv.slice(2);
|
|
73
|
+
if (["edit", "view", "self", "build", "server"].includes(command ?? ""))
|
|
74
|
+
setDownloadProgressListener(terminal.download);
|
|
65
75
|
switch (command) {
|
|
66
76
|
case "self": {
|
|
67
77
|
try {
|
|
@@ -91,7 +101,7 @@ options:
|
|
|
91
101
|
selfUpdate();
|
|
92
102
|
}
|
|
93
103
|
else {
|
|
94
|
-
|
|
104
|
+
terminal.info("Downloading documentation from GitHub...");
|
|
95
105
|
const { root, dispose } = await prepareSelfDocs();
|
|
96
106
|
process.once("exit", dispose);
|
|
97
107
|
process.once("SIGINT", () => process.exit(130));
|
|
@@ -390,19 +400,87 @@ Report:
|
|
|
390
400
|
"tls-cert": { type: "string" },
|
|
391
401
|
"tls-key": { type: "string" },
|
|
392
402
|
shared: { type: "string" },
|
|
403
|
+
repo: { type: "string" },
|
|
404
|
+
help: { type: "boolean", short: "h" },
|
|
393
405
|
},
|
|
394
406
|
});
|
|
407
|
+
if (values.help) {
|
|
408
|
+
console.log(`usage: dooc ${command} [path] [port] [options]
|
|
409
|
+
|
|
410
|
+
path:
|
|
411
|
+
./dooc.yaml manifest (default); folders are also accepted
|
|
412
|
+
./docs folder containing dooc.yaml
|
|
413
|
+
docs/team.dooc.yaml named manifest
|
|
414
|
+
file:///home/me/docs local folder or manifest URL (without --repo)
|
|
415
|
+
|
|
416
|
+
Paths use the current directory, or the cloned repository root with --repo.
|
|
417
|
+
The repository's default branch is opened. Use the clone URL supplied by your Git host.
|
|
418
|
+
|
|
419
|
+
Remote sources require Git. Cloning finishes before the server starts.
|
|
420
|
+
Edit clones retain Git history and local changes, and reopen without fetching or resetting.
|
|
421
|
+
View clones are temporary and removed on exit.
|
|
422
|
+
|
|
423
|
+
options:
|
|
424
|
+
--repo <git-url> clone an HTTPS/SSH Git repository and resolve path inside it
|
|
425
|
+
--viewer-plugins <module> load an explicit local viewer plugin module
|
|
426
|
+
--tls-cert <pem> HTTPS certificate (requires --tls-key)
|
|
427
|
+
--tls-key <pem> HTTPS key (requires --tls-cert)
|
|
428
|
+
--shared <branch> record shared-workspace snapshots on a branch
|
|
429
|
+
--help, -h show this help
|
|
430
|
+
|
|
431
|
+
Example: dooc ${command} dooc-docs --repo https://github.com/dooc-dev/dooc.git`);
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
if (positionals.length > 2)
|
|
435
|
+
throw new Error("Too many positional arguments");
|
|
436
|
+
const port = Number(positionals[1] ?? 5179);
|
|
437
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535)
|
|
438
|
+
throw new Error("Choose a port between 0 and 65535");
|
|
395
439
|
const cert = values["tls-cert"] ?? process.env.DOOC_TLS_CERT;
|
|
396
440
|
const key = values["tls-key"] ?? process.env.DOOC_TLS_KEY;
|
|
397
441
|
if (!cert !== !key)
|
|
398
442
|
throw new Error("--tls-cert and --tls-key must be given together");
|
|
399
|
-
|
|
400
|
-
|
|
443
|
+
let source = positionals[0];
|
|
444
|
+
const remote = values.repo !== undefined;
|
|
445
|
+
if (values.repo !== undefined) {
|
|
446
|
+
// A caller's Git context must never redirect operations outside the cloned repo.
|
|
447
|
+
for (const key of Object.keys(process.env))
|
|
448
|
+
if (/^GIT_(?:DIR|WORK_TREE|COMMON_DIR|INDEX_FILE|OBJECT_DIRECTORY|ALTERNATE_OBJECT_DIRECTORIES|NAMESPACE|CEILING_DIRECTORIES|CONFIG|CONFIG_PARAMETERS|CONFIG_COUNT|CONFIG_KEY_\d+|CONFIG_VALUE_\d+)$/.test(key))
|
|
449
|
+
delete process.env[key];
|
|
450
|
+
const { prepareGitWorkspace } = await import("./git-workspace.js");
|
|
451
|
+
const workspace = await prepareGitWorkspace(values.repo, command, {
|
|
452
|
+
path: source,
|
|
453
|
+
});
|
|
454
|
+
process.once("exit", workspace.dispose);
|
|
455
|
+
process.once("SIGINT", () => process.exit(130));
|
|
456
|
+
process.once("SIGTERM", () => process.exit(143));
|
|
457
|
+
source = workspace.manifest;
|
|
458
|
+
if (command === "edit")
|
|
459
|
+
terminal.info(`${workspace.reused ? "Reusing" : "Saved"} workspace: ${workspace.root}`);
|
|
460
|
+
}
|
|
461
|
+
else if (source && /^file:/i.test(source)) {
|
|
462
|
+
const url = new URL(source);
|
|
463
|
+
if (url.username || url.password || url.search || url.hash)
|
|
464
|
+
throw new Error("Local file URLs must not contain credentials, query or fragment");
|
|
465
|
+
source = fileURLToPath(url);
|
|
466
|
+
}
|
|
467
|
+
else if (source &&
|
|
468
|
+
!isAbsolute(source) &&
|
|
469
|
+
!existsSync(resolve(source)) &&
|
|
470
|
+
/^(?:[a-z][a-z\d+.-]*:|[^/\s]+@[^/\s]+:)/i.test(source)) {
|
|
471
|
+
throw new Error("Pass Git repository URLs with --repo <git-url>");
|
|
472
|
+
}
|
|
473
|
+
if (source && existsSync(resolve(source)) && statSync(resolve(source)).isDirectory())
|
|
474
|
+
source = join(source, MANIFEST_FILE);
|
|
475
|
+
process.env.DOCS_ROOT = projectRoot(source);
|
|
476
|
+
process.env.DOCS_HMR = remote && command === "view" ? "0" : "1";
|
|
477
|
+
process.env.DOOC_REMOTE_WORKSPACE = remote ? "1" : "0";
|
|
401
478
|
// serve.ts reads DOCS_ROOT at import time, so import it after the env is set.
|
|
402
479
|
const { startServer } = await import("./serve.js");
|
|
403
|
-
await startServer(command === "view" ? "preview" : "edit",
|
|
480
|
+
await startServer(command === "view" ? "preview" : "edit", port, values["viewer-plugins"] ?? process.env.DOOC_VIEWER_PLUGINS, ...(remote || (cert && key) || values.shared !== undefined
|
|
404
481
|
? [
|
|
405
482
|
{
|
|
483
|
+
...(remote ? { open: true } : {}),
|
|
406
484
|
...(cert && key
|
|
407
485
|
? { tls: { cert: resolve(cert), key: resolve(key) } }
|
|
408
486
|
: {}),
|
|
@@ -1 +1,36 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { codeBlockAt, isLocalHost, isLocalToolRequest, requestScheme, } from "../workspace/editor-tools.js";
|
|
2
|
+
export declare const runCodeTool: (root: string, body: string, position: number, action: "format" | "lint") => Promise<{
|
|
3
|
+
findings: {
|
|
4
|
+
range: [number, number];
|
|
5
|
+
message: string;
|
|
6
|
+
ruleId: string;
|
|
7
|
+
}[];
|
|
8
|
+
change?: undefined;
|
|
9
|
+
} | {
|
|
10
|
+
change: {
|
|
11
|
+
from: number;
|
|
12
|
+
to: number;
|
|
13
|
+
insert: string;
|
|
14
|
+
};
|
|
15
|
+
findings?: undefined;
|
|
16
|
+
}>;
|
|
17
|
+
export declare const validateCodeTools: (root: string, body: string) => Promise<{
|
|
18
|
+
changes: {
|
|
19
|
+
from: number;
|
|
20
|
+
to: number;
|
|
21
|
+
insert: string;
|
|
22
|
+
}[];
|
|
23
|
+
findings: {
|
|
24
|
+
range: [number, number];
|
|
25
|
+
message: string;
|
|
26
|
+
ruleId: string;
|
|
27
|
+
}[];
|
|
28
|
+
}>;
|
|
29
|
+
export declare const validateTextfileCode: (root: string, language: string, content: string) => Promise<{
|
|
30
|
+
content: string;
|
|
31
|
+
findings: {
|
|
32
|
+
range: [number, number];
|
|
33
|
+
message: string;
|
|
34
|
+
ruleId: string;
|
|
35
|
+
}[];
|
|
36
|
+
}>;
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import * as tools from "../workspace/editor-tools.js";
|
|
2
|
+
import { allowsWorkspaceCode } from "./workspace-trust.js";
|
|
3
|
+
export { codeBlockAt, isLocalHost, isLocalToolRequest, requestScheme, } from "../workspace/editor-tools.js";
|
|
4
|
+
export const runCodeTool = (root, body, position, action) => tools.runCodeTool(root, body, position, action, allowsWorkspaceCode());
|
|
5
|
+
export const validateCodeTools = (root, body) => tools.validateCodeTools(root, body, allowsWorkspaceCode());
|
|
6
|
+
export const validateTextfileCode = (root, language, content) => tools.validateTextfileCode(root, language, content, allowsWorkspaceCode());
|
|
@@ -8,6 +8,7 @@ import { textfilePath } from "../engine/compiler/textfile.js";
|
|
|
8
8
|
import { zip } from "../engine/compiler/zip.js";
|
|
9
9
|
import { extensionFile, extensionManifest, MAX_EXTENSION_BYTES, readExtensionZip, } from "../engine/core/extension-package.js";
|
|
10
10
|
import { validateViewerPlugins, } from "./plugin-config.js";
|
|
11
|
+
import { allowsWorkspaceCode } from "./workspace-trust.js";
|
|
11
12
|
export const EXTENSIONS_DIR = ".dooc/plugins";
|
|
12
13
|
const hash = (source) => createHash("sha256").update(source).digest("hex");
|
|
13
14
|
const unpack = (data) => readExtensionZip(data, async (bytes, size) => inflateRawSync(bytes, { maxOutputLength: Math.max(1, size) }));
|
|
@@ -134,6 +135,8 @@ export const createExtensionManager = (root, registry, initial, personal) => {
|
|
|
134
135
|
return { scope, items: items.sort((a, b) => a.name.localeCompare(b.name)) };
|
|
135
136
|
};
|
|
136
137
|
const activate = async (name, data, save, base) => {
|
|
138
|
+
if (!allowsWorkspaceCode())
|
|
139
|
+
throw new Error("Workspace plugins are disabled in remote sessions; use --viewer-plugins for an explicit local module");
|
|
137
140
|
const revision = hash(data);
|
|
138
141
|
if (!save && active.get(name)?.hash === revision)
|
|
139
142
|
return;
|
|
@@ -281,6 +284,8 @@ export const createExtensionManager = (root, registry, initial, personal) => {
|
|
|
281
284
|
};
|
|
282
285
|
return Object.assign(request, {
|
|
283
286
|
async restore() {
|
|
287
|
+
if (!allowsWorkspaceCode())
|
|
288
|
+
return [];
|
|
284
289
|
const approved = approval();
|
|
285
290
|
const errors = [];
|
|
286
291
|
for (const item of (await list()).items)
|