texlite 0.18.0 → 0.19.1
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/DESIGN.md +442 -26
- package/NPM_TESTING.md +23 -0
- package/OPERATIONS.md +227 -6
- package/README.md +8 -2
- package/README.zh-CN.md +6 -2
- package/THIRD_PARTY_NOTICES.md +73 -0
- package/dist/client/assets/AdminUsers-CuYfWnEk.js +1 -0
- package/dist/client/assets/AdminUsers-CuYfWnEk.js.br +0 -0
- package/dist/client/assets/AdminUsers-CuYfWnEk.js.gz +0 -0
- package/dist/client/assets/AgentIcon-ClP5dPRL.js +1 -0
- package/dist/client/assets/AgentIcon-ClP5dPRL.js.br +0 -0
- package/dist/client/assets/AgentIcon-ClP5dPRL.js.gz +0 -0
- package/dist/client/assets/AgentIcon-DxrC-zx_.css +1 -0
- package/dist/client/assets/AgentIcon-DxrC-zx_.css.br +0 -0
- package/dist/client/assets/AgentIcon-DxrC-zx_.css.gz +0 -0
- package/dist/client/assets/AgentManagement-jY_BF6Qy.js +1 -0
- package/dist/client/assets/AgentManagement-jY_BF6Qy.js.br +0 -0
- package/dist/client/assets/AgentManagement-jY_BF6Qy.js.gz +0 -0
- package/dist/client/assets/AgentTerminal-JKP2SVkZ.js +2 -0
- package/dist/client/assets/AgentTerminal-JKP2SVkZ.js.br +0 -0
- package/dist/client/assets/AgentTerminal-JKP2SVkZ.js.gz +0 -0
- package/dist/client/assets/AgentTerminalSurface-B5LH8GIb.css +1 -0
- package/dist/client/assets/AgentTerminalSurface-B5LH8GIb.css.br +0 -0
- package/dist/client/assets/AgentTerminalSurface-B5LH8GIb.css.gz +0 -0
- package/dist/client/assets/AgentTerminalSurface-CaYNNZ9A.js +16 -0
- package/dist/client/assets/AgentTerminalSurface-CaYNNZ9A.js.br +0 -0
- package/dist/client/assets/AgentTerminalSurface-CaYNNZ9A.js.gz +0 -0
- package/dist/client/assets/AvatarSettingsDialog-C2TACfvP.js +1 -0
- package/dist/client/assets/AvatarSettingsDialog-C2TACfvP.js.br +0 -0
- package/dist/client/assets/AvatarSettingsDialog-C2TACfvP.js.gz +0 -0
- package/dist/client/assets/CitationLibraryDialog-BdU9nbgG.js +1 -0
- package/dist/client/assets/CitationLibraryDialog-BdU9nbgG.js.br +0 -0
- package/dist/client/assets/CitationLibraryDialog-BdU9nbgG.js.gz +0 -0
- package/dist/client/assets/Dashboard-B7mMz5Gj.js +5 -0
- package/dist/client/assets/Dashboard-B7mMz5Gj.js.br +0 -0
- package/dist/client/assets/Dashboard-B7mMz5Gj.js.gz +0 -0
- package/dist/client/assets/GitDialog-C2H-jKVO.js +3 -0
- package/dist/client/assets/GitDialog-C2H-jKVO.js.br +0 -0
- package/dist/client/assets/GitDialog-C2H-jKVO.js.gz +0 -0
- package/dist/client/assets/GitHubAccountDialog-DdKiE3pw.js +1 -0
- package/dist/client/assets/GitHubAccountDialog-DdKiE3pw.js.br +0 -0
- package/dist/client/assets/GitHubAccountDialog-DdKiE3pw.js.gz +0 -0
- package/dist/client/assets/{GitHubIcon-DNR0CleM.js → GitHubIcon-Cjli8pd_.js} +1 -1
- package/dist/client/assets/HistoryDialog-CoxJ3EsK.js +8 -0
- package/dist/client/assets/HistoryDialog-CoxJ3EsK.js.br +0 -0
- package/dist/client/assets/HistoryDialog-CoxJ3EsK.js.gz +0 -0
- package/dist/client/assets/{LatexEditor-BzAk3WQM.js → LatexEditor-BhAKioho.js} +26 -26
- package/dist/client/assets/LatexEditor-BhAKioho.js.br +0 -0
- package/dist/client/assets/LatexEditor-BhAKioho.js.gz +0 -0
- package/dist/client/assets/PdfPreview-CC8KEz1Y.js +1 -0
- package/dist/client/assets/PdfPreview-CC8KEz1Y.js.br +0 -0
- package/dist/client/assets/PdfPreview-CC8KEz1Y.js.gz +0 -0
- package/dist/client/assets/ProjectIconPickerDialog-vi_HwlCS.js +1 -0
- package/dist/client/assets/ProjectIconPickerDialog-vi_HwlCS.js.br +0 -0
- package/dist/client/assets/ProjectIconPickerDialog-vi_HwlCS.js.gz +0 -0
- package/dist/client/assets/ProjectSettings-Bl1t-Gnh.js +4 -0
- package/dist/client/assets/ProjectSettings-Bl1t-Gnh.js.br +0 -0
- package/dist/client/assets/ProjectSettings-Bl1t-Gnh.js.gz +0 -0
- package/dist/client/assets/ProjectWorkspace-1UOdyfBq.js +30 -0
- package/dist/client/assets/ProjectWorkspace-1UOdyfBq.js.br +0 -0
- package/dist/client/assets/ProjectWorkspace-1UOdyfBq.js.gz +0 -0
- package/dist/client/assets/{QuickOpenDialog-CyqeckBM.js → QuickOpenDialog-BAzyrB-4.js} +1 -1
- package/dist/client/assets/QuickOpenDialog-BAzyrB-4.js.br +0 -0
- package/dist/client/assets/QuickOpenDialog-BAzyrB-4.js.gz +0 -0
- package/dist/client/assets/SaveButton-DkyoEu6j.js +1 -0
- package/dist/client/assets/SelectionHistoryDialog-DzlVKtxs.js +3 -0
- package/dist/client/assets/SelectionHistoryDialog-DzlVKtxs.js.br +0 -0
- package/dist/client/assets/SelectionHistoryDialog-DzlVKtxs.js.gz +0 -0
- package/dist/client/assets/SuccessNotice-ubBtzzi_.js +1 -0
- package/dist/client/assets/SystemMetricsDialog-C6RVZdJZ.js +1 -0
- package/dist/client/assets/SystemMetricsDialog-C6RVZdJZ.js.br +0 -0
- package/dist/client/assets/SystemMetricsDialog-C6RVZdJZ.js.gz +0 -0
- package/dist/client/assets/TagColorSelect-xbc2H5ou.js +1 -0
- package/dist/client/assets/TagManagementDialog-8pZUVaEI.js +1 -0
- package/dist/client/assets/TagManagementDialog-8pZUVaEI.js.br +0 -0
- package/dist/client/assets/TagManagementDialog-8pZUVaEI.js.gz +0 -0
- package/dist/client/assets/{WordCountDialog-Bp8kYngA.js → WordCountDialog-BODhL9iz.js} +1 -1
- package/dist/client/assets/WordCountDialog-BODhL9iz.js.br +0 -0
- package/dist/client/assets/WordCountDialog-BODhL9iz.js.gz +0 -0
- package/dist/client/assets/arrow-down-B6T7Z6IO.js +1 -0
- package/dist/client/assets/check-BRlv1lrZ.js +1 -0
- package/dist/client/assets/chevron-up-krb7w67X.js +1 -0
- package/dist/client/assets/{chktex-BcGmZVUy.js → chktex-Bz-LKycq.js} +1 -1
- package/dist/client/assets/{clock-3-x2vcGFSH.js → clock-3-Fb1_e3ec.js} +1 -1
- package/dist/client/assets/{dist-D5mbpudl.js → dist-CMYWzCHL.js} +1 -1
- package/dist/client/assets/dist-CMYWzCHL.js.br +0 -0
- package/dist/client/assets/dist-CMYWzCHL.js.gz +0 -0
- package/dist/client/assets/{eye-CvzXPIMu.js → eye-B6AX_5uX.js} +1 -1
- package/dist/client/assets/{hard-drive-BeGQ5o79.js → hard-drive-CBmnJ2xS.js} +1 -1
- package/dist/client/assets/i18n-DF6keNBA.js +13 -0
- package/dist/client/assets/i18n-DF6keNBA.js.br +0 -0
- package/dist/client/assets/i18n-DF6keNBA.js.gz +0 -0
- package/dist/client/assets/index-DCwfhKK9.js +42 -0
- package/dist/client/assets/index-DCwfhKK9.js.br +0 -0
- package/dist/client/assets/index-DCwfhKK9.js.gz +0 -0
- package/dist/client/assets/index-SVNFLCYh.css +1 -0
- package/dist/client/assets/index-SVNFLCYh.css.br +0 -0
- package/dist/client/assets/index-SVNFLCYh.css.gz +0 -0
- package/dist/client/assets/info-DNSAs0_-.js +1 -0
- package/dist/client/assets/{minimize-2-yYMmsVER.js → minimize-2-C8oL6PTV.js} +1 -1
- package/dist/client/assets/{minus-CNHOVLWS.js → minus-TCBOakyi.js} +1 -1
- package/dist/client/assets/plus-Dfkyfvvy.js +1 -0
- package/dist/client/assets/{refresh-cw-B7vZa5K2.js → refresh-cw-DuLtxWBX.js} +1 -1
- package/dist/client/assets/relativeTime-BR0CVAvz.js +1 -0
- package/dist/client/assets/relativeTime-BR0CVAvz.js.br +0 -0
- package/dist/client/assets/relativeTime-BR0CVAvz.js.gz +0 -0
- package/dist/client/assets/{search-Czv3qsBy.js → search-n-2tBATf.js} +1 -1
- package/dist/client/assets/{spellCheck-DDCaK8Yx.js → spellCheck-xzICTGx1.js} +1 -1
- package/dist/client/assets/spellCheck-xzICTGx1.js.br +0 -0
- package/dist/client/assets/spellCheck-xzICTGx1.js.gz +0 -0
- package/dist/client/assets/tags-Dy96boLq.js +1 -0
- package/dist/client/assets/terminal-C0xh8jVR.js +1 -0
- package/dist/client/assets/{type-NT195OCy.js → type-BjXWxrjH.js} +1 -1
- package/dist/client/assets/{user-plus-BRuwNzcg.js → user-plus-3oJZJXHW.js} +1 -1
- package/dist/client/index.html +13 -7
- package/dist/server/agents/adapters/claude.js +180 -0
- package/dist/server/agents/adapters/codex.js +47 -0
- package/dist/server/agents/adapters/common.js +86 -0
- package/dist/server/agents/adapters/opencode.js +196 -0
- package/dist/server/agents/adapters/types.js +1 -0
- package/dist/server/agents/execution.js +147 -0
- package/dist/server/agents/launcher.js +57 -0
- package/dist/server/agents/processIdentity.js +63 -0
- package/dist/server/agents/registry.js +72 -0
- package/dist/server/agents/sessions.js +574 -0
- package/dist/server/agents/terminal.js +84 -0
- package/dist/server/agents/workspaces.js +341 -0
- package/dist/server/app.js +32 -1
- package/dist/server/cli.js +19 -47
- package/dist/server/collaboration.js +64 -36
- package/dist/server/compileArtifacts.js +11 -44
- package/dist/server/compiler.js +16 -38
- package/dist/server/config.js +8 -2
- package/dist/server/db.js +33 -0
- package/dist/server/editHistory.js +59 -65
- package/dist/server/history.js +28 -13
- package/dist/server/i18n.js +26 -8
- package/dist/server/latexRoot.js +4 -2
- package/dist/server/locales/zh-Hant.js +145 -0
- package/dist/server/lucideIcons.js +14 -17
- package/dist/server/projectMutations.js +21 -0
- package/dist/server/routes/agents.js +135 -0
- package/dist/server/routes/compile.js +23 -43
- package/dist/server/routes/projectHistory.js +13 -6
- package/dist/server/routes/projectShared.js +6 -1
- package/dist/server/routes/projects.js +15 -23
- package/dist/shared/agentMessages.js +51 -0
- package/dist/shared/agentProtocol.js +41 -0
- package/dist/shared/historyFiles.js +1 -1
- package/dist/shared/historyTracking.js +2 -0
- package/dist/shared/locales.js +21 -0
- package/dist/shared/sourceCommentAnchors.js +52 -4
- package/package.json +7 -3
- package/templates/agents/AGENTS.md +135 -0
- package/texlite.config.example.json +3 -2
- package/dist/client/assets/AdminUsers-rPpYTAU6.js +0 -1
- package/dist/client/assets/AdminUsers-rPpYTAU6.js.br +0 -0
- package/dist/client/assets/AdminUsers-rPpYTAU6.js.gz +0 -0
- package/dist/client/assets/AvatarSettingsDialog-CIPKapVe.js +0 -1
- package/dist/client/assets/AvatarSettingsDialog-CIPKapVe.js.br +0 -0
- package/dist/client/assets/AvatarSettingsDialog-CIPKapVe.js.gz +0 -0
- package/dist/client/assets/CitationLibraryDialog-BhZX8BV2.js +0 -1
- package/dist/client/assets/CitationLibraryDialog-BhZX8BV2.js.br +0 -0
- package/dist/client/assets/CitationLibraryDialog-BhZX8BV2.js.gz +0 -0
- package/dist/client/assets/Dashboard-DppEhsjL.js +0 -5
- package/dist/client/assets/Dashboard-DppEhsjL.js.br +0 -0
- package/dist/client/assets/Dashboard-DppEhsjL.js.gz +0 -0
- package/dist/client/assets/GitDialog-BOu46hxA.js +0 -3
- package/dist/client/assets/GitDialog-BOu46hxA.js.br +0 -0
- package/dist/client/assets/GitDialog-BOu46hxA.js.gz +0 -0
- package/dist/client/assets/GitHubAccountDialog-hosK9cLW.js +0 -1
- package/dist/client/assets/GitHubAccountDialog-hosK9cLW.js.br +0 -0
- package/dist/client/assets/GitHubAccountDialog-hosK9cLW.js.gz +0 -0
- package/dist/client/assets/HistoryDialog-BdkuEl8r.js +0 -8
- package/dist/client/assets/HistoryDialog-BdkuEl8r.js.br +0 -0
- package/dist/client/assets/HistoryDialog-BdkuEl8r.js.gz +0 -0
- package/dist/client/assets/LatexEditor-BzAk3WQM.js.br +0 -0
- package/dist/client/assets/LatexEditor-BzAk3WQM.js.gz +0 -0
- package/dist/client/assets/PdfPreview-DkjI1eCo.js +0 -1
- package/dist/client/assets/PdfPreview-DkjI1eCo.js.br +0 -0
- package/dist/client/assets/PdfPreview-DkjI1eCo.js.gz +0 -0
- package/dist/client/assets/ProjectIconPickerDialog-D8Uo4H10.js +0 -1
- package/dist/client/assets/ProjectIconPickerDialog-D8Uo4H10.js.br +0 -0
- package/dist/client/assets/ProjectIconPickerDialog-D8Uo4H10.js.gz +0 -0
- package/dist/client/assets/ProjectSettings-Jdr94nOc.js +0 -1
- package/dist/client/assets/ProjectSettings-Jdr94nOc.js.br +0 -0
- package/dist/client/assets/ProjectSettings-Jdr94nOc.js.gz +0 -0
- package/dist/client/assets/ProjectWorkspace-D9v3Jj8T.js +0 -30
- package/dist/client/assets/ProjectWorkspace-D9v3Jj8T.js.br +0 -0
- package/dist/client/assets/ProjectWorkspace-D9v3Jj8T.js.gz +0 -0
- package/dist/client/assets/QuickOpenDialog-CyqeckBM.js.br +0 -0
- package/dist/client/assets/QuickOpenDialog-CyqeckBM.js.gz +0 -0
- package/dist/client/assets/SelectionHistoryDialog-Dlutex-A.js +0 -3
- package/dist/client/assets/SelectionHistoryDialog-Dlutex-A.js.br +0 -0
- package/dist/client/assets/SelectionHistoryDialog-Dlutex-A.js.gz +0 -0
- package/dist/client/assets/SystemMetricsDialog-CCWxXw6g.js +0 -1
- package/dist/client/assets/SystemMetricsDialog-CCWxXw6g.js.br +0 -0
- package/dist/client/assets/SystemMetricsDialog-CCWxXw6g.js.gz +0 -0
- package/dist/client/assets/TagColorSelect-D3T-rw4K.js +0 -1
- package/dist/client/assets/TagManagementDialog-CxjrSX-o.js +0 -1
- package/dist/client/assets/TagManagementDialog-CxjrSX-o.js.br +0 -0
- package/dist/client/assets/TagManagementDialog-CxjrSX-o.js.gz +0 -0
- package/dist/client/assets/WordCountDialog-Bp8kYngA.js.br +0 -0
- package/dist/client/assets/WordCountDialog-Bp8kYngA.js.gz +0 -0
- package/dist/client/assets/binary-B57nBiwS.js +0 -1
- package/dist/client/assets/check-DFoA73zZ.js +0 -1
- package/dist/client/assets/chevron-up-C8DyKLxi.js +0 -1
- package/dist/client/assets/dist-D5mbpudl.js.br +0 -0
- package/dist/client/assets/dist-D5mbpudl.js.gz +0 -0
- package/dist/client/assets/i18n-CRWKZA6W.js +0 -9
- package/dist/client/assets/i18n-CRWKZA6W.js.br +0 -0
- package/dist/client/assets/i18n-CRWKZA6W.js.gz +0 -0
- package/dist/client/assets/index-D0eqhDpZ.js +0 -42
- package/dist/client/assets/index-D0eqhDpZ.js.br +0 -0
- package/dist/client/assets/index-D0eqhDpZ.js.gz +0 -0
- package/dist/client/assets/index-DnhiIb1V.css +0 -1
- package/dist/client/assets/index-DnhiIb1V.css.br +0 -0
- package/dist/client/assets/index-DnhiIb1V.css.gz +0 -0
- package/dist/client/assets/plus-BDquy76g.js +0 -1
- package/dist/client/assets/relativeTime-DuOytR_J.js +0 -1
- package/dist/client/assets/relativeTime-DuOytR_J.js.br +0 -0
- package/dist/client/assets/relativeTime-DuOytR_J.js.gz +0 -0
- package/dist/client/assets/sigma-CI6gmAkl.js +0 -1
- package/dist/client/assets/spellCheck-DDCaK8Yx.js.br +0 -0
- package/dist/client/assets/spellCheck-DDCaK8Yx.js.gz +0 -0
- package/dist/client/assets/tags-CLK7WRSs.js +0 -1
- package/preview-1.png +0 -0
- package/preview-2.png +0 -0
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { makeDiff } from "@sanity/diff-match-patch";
|
|
5
|
+
import { isTextContent } from "../../shared/fileTypes.js";
|
|
6
|
+
import { isCollaborativeTextFile, maxCollaborativeFileBytes } from "../collaboration.js";
|
|
7
|
+
import { assertNoSourceSymlinks, outputRoot, resolveSourcePath, sourceRoot } from "../files.js";
|
|
8
|
+
import { httpError } from "../http.js";
|
|
9
|
+
import { requireEditableProject, touchProject } from "../routes/projectShared.js";
|
|
10
|
+
import { reanchorFileComments } from "../anchors.js";
|
|
11
|
+
import { createEditHistorySpan, hashText } from "../editHistory.js";
|
|
12
|
+
export function agentTaskRoot(config, taskId) {
|
|
13
|
+
if (!/^[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}$/i.test(taskId))
|
|
14
|
+
throw httpError(404, "AGENT_SESSION_NOT_FOUND");
|
|
15
|
+
return path.join(config.dataDir, "agent-tasks", taskId);
|
|
16
|
+
}
|
|
17
|
+
/** Same package-relative template path in the source checkout and compiled npm installation. */
|
|
18
|
+
const agentInstructionsTemplate = new URL("../../../templates/agents/AGENTS.md", import.meta.url);
|
|
19
|
+
export async function ensureAgentInstructions(context, projectId, user) {
|
|
20
|
+
const { config, db, projectMutations, collaboration, recordHistory } = context;
|
|
21
|
+
await projectMutations.runWrite(projectId, async () => {
|
|
22
|
+
const target = resolveSourcePath(config, projectId, "AGENTS.md");
|
|
23
|
+
try {
|
|
24
|
+
await fs.promises.copyFile(agentInstructionsTemplate, target, fs.constants.COPYFILE_EXCL);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (error.code === "EEXIST")
|
|
28
|
+
return;
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
collaboration.updateFile(projectId, "AGENTS.md", await fs.promises.readFile(target, "utf8"), user.id);
|
|
32
|
+
touchProject(db, projectId, user.id);
|
|
33
|
+
recordHistory(projectId, user.id, "file", ["AGENTS.md"]);
|
|
34
|
+
}, { preflight: () => { requireEditableProject(db, projectId, user); } });
|
|
35
|
+
}
|
|
36
|
+
const ignored = (name) => name === ".git" || name === ".texlite-agent-conflicts" || /\.(?:collaboration-\d+-[^.]+|agent-[^.]+)\.tmp$/.test(name);
|
|
37
|
+
function changes(before, after) {
|
|
38
|
+
const result = [];
|
|
39
|
+
let offset = 0;
|
|
40
|
+
let pending;
|
|
41
|
+
for (const [kind, text] of makeDiff(before, after, { checkLines: true, timeout: 1 })) {
|
|
42
|
+
if (kind === 0) {
|
|
43
|
+
if (pending)
|
|
44
|
+
result.push(pending);
|
|
45
|
+
pending = undefined;
|
|
46
|
+
offset += text.length;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
pending ??= { from: offset, to: offset, insert: "" };
|
|
50
|
+
if (kind === -1) {
|
|
51
|
+
offset += text.length;
|
|
52
|
+
pending.to = offset;
|
|
53
|
+
}
|
|
54
|
+
else
|
|
55
|
+
pending.insert += text;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (pending)
|
|
59
|
+
result.push(pending);
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
/** Conservative three-way merge: never fuzzy-apply overlapping replacements. */
|
|
63
|
+
export function mergeAgentText(base, editor, agent) {
|
|
64
|
+
if (base === editor || editor === agent)
|
|
65
|
+
return agent;
|
|
66
|
+
if (base === agent)
|
|
67
|
+
return editor;
|
|
68
|
+
const human = changes(base, editor);
|
|
69
|
+
const external = changes(base, agent);
|
|
70
|
+
const combined = [...human];
|
|
71
|
+
for (const edit of external) {
|
|
72
|
+
if (human.some((other) => edit.from === other.from && edit.to === other.to && edit.insert === other.insert))
|
|
73
|
+
continue;
|
|
74
|
+
if (human.some((other) => Math.max(edit.from, other.from) < Math.min(edit.to, other.to)
|
|
75
|
+
|| (edit.from === edit.to && edit.from >= other.from && edit.from <= other.to)
|
|
76
|
+
|| (other.from === other.to && other.from >= edit.from && other.from <= edit.to)))
|
|
77
|
+
return null;
|
|
78
|
+
combined.push(edit);
|
|
79
|
+
}
|
|
80
|
+
let merged = base;
|
|
81
|
+
for (const edit of combined.sort((a, b) => b.from - a.from))
|
|
82
|
+
merged = merged.slice(0, edit.from) + edit.insert + merged.slice(edit.to);
|
|
83
|
+
return merged;
|
|
84
|
+
}
|
|
85
|
+
/** A running task observes the real source tree; it owns no project copies. */
|
|
86
|
+
export class AgentSourceSync {
|
|
87
|
+
context;
|
|
88
|
+
taskId;
|
|
89
|
+
projectId;
|
|
90
|
+
userId;
|
|
91
|
+
onError;
|
|
92
|
+
known = new Map();
|
|
93
|
+
detach;
|
|
94
|
+
timer;
|
|
95
|
+
pending;
|
|
96
|
+
closed = false;
|
|
97
|
+
syncing = false;
|
|
98
|
+
constructor(context, taskId, projectId, userId, onError) {
|
|
99
|
+
this.context = context;
|
|
100
|
+
this.taskId = taskId;
|
|
101
|
+
this.projectId = projectId;
|
|
102
|
+
this.userId = userId;
|
|
103
|
+
this.onError = onError;
|
|
104
|
+
}
|
|
105
|
+
async start() {
|
|
106
|
+
const { config, projectMutations, collaboration } = this.context;
|
|
107
|
+
await projectMutations.runConsistentRead(this.projectId, async () => {
|
|
108
|
+
assertNoSourceSymlinks(config, this.projectId);
|
|
109
|
+
for (const relative of await this.files())
|
|
110
|
+
this.remember(relative);
|
|
111
|
+
this.detach = collaboration.observeExternalSources(this.projectId, {
|
|
112
|
+
beforeFlush: (paths) => this.sync(paths),
|
|
113
|
+
written: (paths) => {
|
|
114
|
+
if (this.syncing)
|
|
115
|
+
return;
|
|
116
|
+
// Ordinary browser/HTTP writes are not attributed to the agent.
|
|
117
|
+
for (const relative of paths) {
|
|
118
|
+
for (const old of this.known.keys())
|
|
119
|
+
if (old.startsWith(relative + "/"))
|
|
120
|
+
this.known.delete(old);
|
|
121
|
+
this.rememberTree(relative);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
this.schedule();
|
|
127
|
+
}
|
|
128
|
+
/** Stop polling only after the process tree is dead; reconcile its last writes first. */
|
|
129
|
+
async close() {
|
|
130
|
+
this.closed = true;
|
|
131
|
+
clearTimeout(this.timer);
|
|
132
|
+
await this.pending;
|
|
133
|
+
try {
|
|
134
|
+
await this.scan();
|
|
135
|
+
}
|
|
136
|
+
finally {
|
|
137
|
+
this.detach?.();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
schedule() {
|
|
141
|
+
if (this.closed)
|
|
142
|
+
return;
|
|
143
|
+
this.timer = setTimeout(() => {
|
|
144
|
+
this.pending = this.scan().catch((error) => this.report(error)).finally(() => { this.pending = undefined; this.schedule(); });
|
|
145
|
+
}, 750);
|
|
146
|
+
this.timer.unref();
|
|
147
|
+
}
|
|
148
|
+
async scan() {
|
|
149
|
+
const paths = await this.files();
|
|
150
|
+
await this.context.projectMutations.runSnapshot(this.projectId, () => {
|
|
151
|
+
this.sync([...new Set([...this.known.keys(), ...paths])]);
|
|
152
|
+
this.context.projectMutations.flushProject(this.projectId);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
async files() {
|
|
156
|
+
const result = [];
|
|
157
|
+
const visit = async (directory, prefix) => {
|
|
158
|
+
let entries;
|
|
159
|
+
try {
|
|
160
|
+
const stat = await fs.promises.lstat(directory);
|
|
161
|
+
if (stat.isSymbolicLink() || !stat.isDirectory())
|
|
162
|
+
throw httpError(409, "SYMLINK_FORBIDDEN", { path: prefix || "." });
|
|
163
|
+
entries = await fs.promises.readdir(directory, { withFileTypes: true });
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
if (prefix && error.code === "ENOENT")
|
|
167
|
+
return;
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
for (const entry of entries) {
|
|
171
|
+
if (ignored(entry.name))
|
|
172
|
+
continue;
|
|
173
|
+
const relative = prefix ? prefix + "/" + entry.name : entry.name;
|
|
174
|
+
if (entry.isSymbolicLink() || (!entry.isDirectory() && !entry.isFile()))
|
|
175
|
+
throw httpError(409, "SYMLINK_FORBIDDEN", { path: relative });
|
|
176
|
+
if (entry.isDirectory())
|
|
177
|
+
await visit(path.join(directory, entry.name), relative);
|
|
178
|
+
else
|
|
179
|
+
result.push(relative);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
await visit(sourceRoot(this.context.config, this.projectId), "");
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
read(relative) {
|
|
186
|
+
const { config } = this.context;
|
|
187
|
+
const filename = resolveSourcePath(config, this.projectId, relative);
|
|
188
|
+
let stat;
|
|
189
|
+
try {
|
|
190
|
+
stat = fs.lstatSync(filename);
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
if (["ENOENT", "ENOTDIR"].includes(error.code ?? ""))
|
|
194
|
+
return null;
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
if (stat.isDirectory())
|
|
198
|
+
return null;
|
|
199
|
+
if (!stat.isFile())
|
|
200
|
+
throw httpError(409, "SYMLINK_FORBIDDEN", { path: relative });
|
|
201
|
+
const signature = [stat.ino, stat.size, stat.mtimeMs, stat.ctimeMs].join(":");
|
|
202
|
+
const previous = this.known.get(relative);
|
|
203
|
+
if (previous?.signature === signature)
|
|
204
|
+
return previous;
|
|
205
|
+
const bytes = stat.size <= maxCollaborativeFileBytes(config) ? fs.readFileSync(filename) : null;
|
|
206
|
+
return { signature, text: bytes && isTextContent(bytes) ? bytes.toString("utf8") : null };
|
|
207
|
+
}
|
|
208
|
+
remember(relative) {
|
|
209
|
+
const state = this.read(relative);
|
|
210
|
+
if (state)
|
|
211
|
+
this.known.set(relative, state);
|
|
212
|
+
else
|
|
213
|
+
this.known.delete(relative);
|
|
214
|
+
}
|
|
215
|
+
rememberTree(relative) {
|
|
216
|
+
const absolute = resolveSourcePath(this.context.config, this.projectId, relative);
|
|
217
|
+
if (fs.existsSync(absolute) && fs.lstatSync(absolute).isDirectory()) {
|
|
218
|
+
for (const entry of fs.readdirSync(absolute))
|
|
219
|
+
if (!ignored(entry))
|
|
220
|
+
this.rememberTree(relative + "/" + entry);
|
|
221
|
+
}
|
|
222
|
+
else
|
|
223
|
+
this.remember(relative);
|
|
224
|
+
}
|
|
225
|
+
sync(paths) {
|
|
226
|
+
if (this.syncing)
|
|
227
|
+
return;
|
|
228
|
+
this.syncing = true;
|
|
229
|
+
const { config, db, collaboration, recordEdits, recordHistory } = this.context;
|
|
230
|
+
const changed = [];
|
|
231
|
+
let conflict = false;
|
|
232
|
+
try {
|
|
233
|
+
for (const relative of paths) {
|
|
234
|
+
if (relative.split("/").some(ignored))
|
|
235
|
+
continue;
|
|
236
|
+
const before = this.known.get(relative);
|
|
237
|
+
const after = this.read(relative);
|
|
238
|
+
if (before?.signature === after?.signature || (!before && !after))
|
|
239
|
+
continue;
|
|
240
|
+
if (before?.text === after?.text && before && after && after.text !== null) {
|
|
241
|
+
this.known.set(relative, after);
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
const live = collaboration.fileContent(this.projectId, relative);
|
|
245
|
+
let next = after?.text ?? null;
|
|
246
|
+
if (live !== null && before?.text !== null && before?.text !== undefined && live !== before.text) {
|
|
247
|
+
const merged = next === null ? null : mergeAgentText(before.text, live, next);
|
|
248
|
+
if (merged === null) {
|
|
249
|
+
// Preserve the agent's version in an editable project file, never
|
|
250
|
+
// silently discard either side of a simultaneous replacement.
|
|
251
|
+
if (after) {
|
|
252
|
+
const recovery = resolveSourcePath(config, this.projectId, ".texlite-agent-conflicts/" + this.taskId + "/" + relative);
|
|
253
|
+
fs.mkdirSync(path.dirname(recovery), { recursive: true, mode: 0o700 });
|
|
254
|
+
fs.copyFileSync(resolveSourcePath(config, this.projectId, relative), recovery);
|
|
255
|
+
}
|
|
256
|
+
this.write(relative, live);
|
|
257
|
+
this.remember(relative);
|
|
258
|
+
conflict = true;
|
|
259
|
+
collaboration.invalidateSourceTree(this.projectId);
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
next = merged;
|
|
263
|
+
}
|
|
264
|
+
if (next !== null) {
|
|
265
|
+
if (next !== after?.text)
|
|
266
|
+
this.write(relative, next);
|
|
267
|
+
if (!collaboration.importExternalText(this.projectId, relative, next, this.userId)) {
|
|
268
|
+
const previous = before?.text ?? "";
|
|
269
|
+
reanchorFileComments(db, this.projectId, relative, previous, next);
|
|
270
|
+
collaboration.updateFile(this.projectId, relative, next, this.userId);
|
|
271
|
+
if (isCollaborativeTextFile(relative) && previous !== next)
|
|
272
|
+
recordEdits(this.projectId, [externalEdit(relative, previous, next, this.userId)]);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
collaboration.removePath(this.projectId, relative);
|
|
277
|
+
if (!after) {
|
|
278
|
+
// Source deletion retains orphaned discussion instead of deleting it.
|
|
279
|
+
reanchorFileComments(db, this.projectId, relative, before?.text ?? "", "");
|
|
280
|
+
db.prepare("UPDATE projects SET latexmkrc = NULL WHERE id = ? AND latexmkrc = ?").run(this.projectId, relative);
|
|
281
|
+
}
|
|
282
|
+
collaboration.invalidateSourceTree(this.projectId, relative);
|
|
283
|
+
}
|
|
284
|
+
this.remember(relative);
|
|
285
|
+
changed.push(relative);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
finally {
|
|
289
|
+
this.syncing = false;
|
|
290
|
+
if (changed.length) {
|
|
291
|
+
touchProject(db, this.projectId, this.userId);
|
|
292
|
+
recordHistory(this.projectId, this.userId, "file", changed);
|
|
293
|
+
collaboration.signalComments(this.projectId);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (conflict)
|
|
297
|
+
this.report(httpError(409, "AGENT_SYNC_CONFLICT"));
|
|
298
|
+
}
|
|
299
|
+
report(error) {
|
|
300
|
+
this.closed = true;
|
|
301
|
+
clearTimeout(this.timer);
|
|
302
|
+
this.onError(error);
|
|
303
|
+
}
|
|
304
|
+
write(relative, content) {
|
|
305
|
+
const target = resolveSourcePath(this.context.config, this.projectId, relative);
|
|
306
|
+
fs.mkdirSync(path.dirname(target), { recursive: true, mode: 0o700 });
|
|
307
|
+
const temporary = target + ".agent-" + randomUUID() + ".tmp";
|
|
308
|
+
try {
|
|
309
|
+
fs.writeFileSync(temporary, content, { mode: 0o600 });
|
|
310
|
+
fs.renameSync(temporary, target);
|
|
311
|
+
}
|
|
312
|
+
finally {
|
|
313
|
+
fs.rmSync(temporary, { force: true });
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/** Provide logs outside the source tree without introducing generated project files. */
|
|
318
|
+
export async function writeAgentProjectContext(context, taskId, projectId) {
|
|
319
|
+
const { config, db } = context;
|
|
320
|
+
const project = db.prepare("SELECT main_file FROM projects WHERE id = ?").get(projectId);
|
|
321
|
+
const latest = db.prepare("SELECT id, status, log FROM compile_runs WHERE project_id = ? AND main_file = ? ORDER BY created_at DESC LIMIT 1")
|
|
322
|
+
.get(projectId, project.main_file);
|
|
323
|
+
const state = path.join(agentTaskRoot(config, taskId), "state");
|
|
324
|
+
await fs.promises.mkdir(state, { recursive: true, mode: 0o700 });
|
|
325
|
+
await fs.promises.writeFile(path.join(state, "compile.log"), latest?.log ?? "No compilation has been recorded.\n", { mode: 0o600 });
|
|
326
|
+
await fs.promises.writeFile(path.join(state, "project-context.json"), JSON.stringify({ sourceDirectory: sourceRoot(config, projectId),
|
|
327
|
+
mainFile: project.main_file, outputDirectory: outputRoot(config, projectId),
|
|
328
|
+
latestCompile: latest ? { runId: latest.id, status: latest.status } : null,
|
|
329
|
+
compileLog: path.join(state, "compile.log") }, null, 2), { mode: 0o600 });
|
|
330
|
+
}
|
|
331
|
+
function externalEdit(filePath, before, after, authorId) {
|
|
332
|
+
const createdAt = new Date().toISOString();
|
|
333
|
+
let shift = 0;
|
|
334
|
+
const spans = changes(before, after).map((edit) => {
|
|
335
|
+
const afterStart = edit.from + shift;
|
|
336
|
+
shift += edit.insert.length - (edit.to - edit.from);
|
|
337
|
+
return createEditHistorySpan(edit.from, afterStart, before.slice(edit.from, edit.to), edit.insert);
|
|
338
|
+
});
|
|
339
|
+
return { filePath, authorId, kind: "edit", beforeHash: hashText(before), afterHash: hashText(after), createdAt, updatedAt: createdAt,
|
|
340
|
+
steps: [{ beforeHash: hashText(before), afterHash: hashText(after), createdAt, spans }] };
|
|
341
|
+
}
|
package/dist/server/app.js
CHANGED
|
@@ -38,6 +38,8 @@ import { registerProjectCatalogRoutes } from "./routes/projects.js";
|
|
|
38
38
|
import { registerSystemRoutes } from "./routes/system.js";
|
|
39
39
|
import { registerUserManagementRoutes } from "./routes/users.js";
|
|
40
40
|
import { registerWordCountRoutes } from "./routes/wordCount.js";
|
|
41
|
+
import { registerAgentRoutes } from "./routes/agents.js";
|
|
42
|
+
import { AgentService } from "./agents/sessions.js";
|
|
41
43
|
import { HarperService } from "./harper.js";
|
|
42
44
|
import { ChktexService } from "./chktex.js";
|
|
43
45
|
import { TexcountService } from "./texcount.js";
|
|
@@ -85,7 +87,7 @@ export async function buildApp(config, db, options = {}) {
|
|
|
85
87
|
const eventLoopDelay = monitorEventLoopDelay({ resolution: EVENT_LOOP_DELAY_RESOLUTION_MS });
|
|
86
88
|
eventLoopDelay.enable();
|
|
87
89
|
const history = new ProjectHistoryService(config, db);
|
|
88
|
-
const editHistory = new ProjectEditHistoryService(db, config.editHistoryMaxStorageBytes);
|
|
90
|
+
const editHistory = new ProjectEditHistoryService(db, config.editHistoryMaxStorageBytes, config.editHistoryMaxSegments);
|
|
89
91
|
const historyRetention = new HistoryRetentionScheduler(history, {
|
|
90
92
|
onError: (error, projectId) => app.log.error({ err: error, projectId }, "Failed to enforce project history retention")
|
|
91
93
|
});
|
|
@@ -144,6 +146,31 @@ export async function buildApp(config, db, options = {}) {
|
|
|
144
146
|
metrics.record("collaboration.persist", durationMs + performance.now() - started);
|
|
145
147
|
});
|
|
146
148
|
const projectMutations = new ProjectMutationCoordinator(collaboration);
|
|
149
|
+
const agents = new AgentService({ config, db, collaboration, projectMutations, recordHistory,
|
|
150
|
+
recordEdits: (id, edits) => editRetry.save(id, edits)
|
|
151
|
+
}, { onError: (error) => app.log.error({ err: error }, "External agent operation failed"), ...options.agents });
|
|
152
|
+
await agents.ready();
|
|
153
|
+
app.addHook("onResponse", async (request) => {
|
|
154
|
+
if (request.method === "GET" || request.method === "HEAD")
|
|
155
|
+
return;
|
|
156
|
+
try {
|
|
157
|
+
await agents.reconcilePermissions(request.method === "DELETE");
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
app.log.error({ err: error }, "Failed to revoke external agent access");
|
|
161
|
+
}
|
|
162
|
+
if (request.method === "POST" && request.routeOptions.url?.includes("/compile")) {
|
|
163
|
+
const { id } = request.params;
|
|
164
|
+
if (id) {
|
|
165
|
+
try {
|
|
166
|
+
await agents.refreshProjectContext(id);
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
app.log.error({ err: error }, "Failed to refresh agent compilation context");
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
});
|
|
147
174
|
const projectGit = new ProjectGitService(config, db, options.githubFetch);
|
|
148
175
|
const loginLimiter = new LoginRateLimiter();
|
|
149
176
|
for (const row of db.prepare("SELECT id FROM projects").all()) {
|
|
@@ -236,6 +263,9 @@ export async function buildApp(config, db, options = {}) {
|
|
|
236
263
|
}
|
|
237
264
|
});
|
|
238
265
|
app.addHook("onClose", async () => collaboration.destroy());
|
|
266
|
+
// Fastify runs close hooks in reverse registration order. Drain external
|
|
267
|
+
// writers while Yjs rooms and history retry/retention services still exist.
|
|
268
|
+
app.addHook("onClose", async () => { await agents.dispose(); });
|
|
239
269
|
const indexPath = path.join(config.clientDir, "index.html");
|
|
240
270
|
const renderedIndex = fs.existsSync(indexPath)
|
|
241
271
|
? renderClientIndex(fs.readFileSync(indexPath, "utf8"), config.basePath)
|
|
@@ -266,6 +296,7 @@ export async function buildApp(config, db, options = {}) {
|
|
|
266
296
|
updates
|
|
267
297
|
});
|
|
268
298
|
registerCollaborationRoutes(routes, { db, collaboration, metrics });
|
|
299
|
+
registerAgentRoutes(routes, { db, agents });
|
|
269
300
|
registerAuthRoutes(routes, { config, db, loginLimiter });
|
|
270
301
|
registerAvatarRoutes(routes, { db, collaboration });
|
|
271
302
|
registerCitationRoutes(routes, { db });
|
package/dist/server/cli.js
CHANGED
|
@@ -11,7 +11,7 @@ import { hashPassword, MIN_PASSWORD_LENGTH } from "./security.js";
|
|
|
11
11
|
import { assertEnvironment, hostRequirementsSatisfied, inspectHostEnvironment, inspectHostRequirements } from "./environment.js";
|
|
12
12
|
import { serve } from "./index.js";
|
|
13
13
|
import { processStatus, restartManaged, startManaged, stopManaged, streamLogs, waitForOnline } from "./pm2.js";
|
|
14
|
-
import {
|
|
14
|
+
import { resolveConfigPath } from "./runtimePaths.js";
|
|
15
15
|
import { basePathHref } from "../shared/basePath.js";
|
|
16
16
|
const HELP = `TexLite ${packageVersion()}
|
|
17
17
|
|
|
@@ -87,21 +87,19 @@ function configPathFor(options) {
|
|
|
87
87
|
return resolveConfigPath(options.configPath);
|
|
88
88
|
}
|
|
89
89
|
function writeInitialConfig(configPath, siteName, adminEmail) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
:
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
90
|
+
// Validate explicit environment settings before creating a file. Defaults
|
|
91
|
+
// remain runtime defaults, not permanent overrides in a generated config.
|
|
92
|
+
const config = loadConfig(configPath);
|
|
93
|
+
const server = {
|
|
94
|
+
host: process.env.TEXLITE_HOST !== undefined ? config.host : undefined,
|
|
95
|
+
port: process.env.TEXLITE_PORT !== undefined ? config.port : undefined,
|
|
96
|
+
basePath: process.env.TEXLITE_BASE_PATH !== undefined ? config.basePath : undefined
|
|
97
|
+
};
|
|
98
98
|
fs.mkdirSync(path.dirname(configPath), { recursive: true, mode: 0o700 });
|
|
99
99
|
// Data parents are not guaranteed to exist on a fresh account. Create only
|
|
100
100
|
// the parent here; the configured data directory itself is created by
|
|
101
101
|
// openDatabase after configuration validation.
|
|
102
|
-
|
|
103
|
-
fs.mkdirSync(parent, { recursive: true, mode: 0o700 });
|
|
104
|
-
}
|
|
102
|
+
fs.mkdirSync(path.dirname(config.dataDir), { recursive: true, mode: 0o700 });
|
|
105
103
|
try {
|
|
106
104
|
fs.chmodSync(path.dirname(configPath), 0o700);
|
|
107
105
|
}
|
|
@@ -109,35 +107,8 @@ function writeInitialConfig(configPath, siteName, adminEmail) {
|
|
|
109
107
|
const configFile = {
|
|
110
108
|
siteName,
|
|
111
109
|
adminEmail,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
storage: { dataDir: configuredDataDirectory || dataDirectory },
|
|
115
|
-
uploads: { maxFileSizeMB: CONFIG_DEFAULTS.maxFileSizeMB },
|
|
116
|
-
pdf: {
|
|
117
|
-
loadingStrategy: CONFIG_DEFAULTS.pdfLoadingStrategy,
|
|
118
|
-
rangeThresholdMB: CONFIG_DEFAULTS.pdfRangeThresholdMB
|
|
119
|
-
},
|
|
120
|
-
history: {
|
|
121
|
-
maxVersions: CONFIG_DEFAULTS.historyMaxVersions,
|
|
122
|
-
maxStorageMB: CONFIG_DEFAULTS.historyMaxStorageMB
|
|
123
|
-
},
|
|
124
|
-
editHistory: {
|
|
125
|
-
maxStorageMB: CONFIG_DEFAULTS.editHistoryMaxStorageMB
|
|
126
|
-
},
|
|
127
|
-
git: {
|
|
128
|
-
binary: CONFIG_DEFAULTS.git,
|
|
129
|
-
operationTimeoutSeconds: CONFIG_DEFAULTS.gitOperationTimeoutSeconds,
|
|
130
|
-
githubApiBaseUrl: CONFIG_DEFAULTS.githubApiBaseUrl
|
|
131
|
-
},
|
|
132
|
-
latex: {
|
|
133
|
-
latexmk: CONFIG_DEFAULTS.latexmk,
|
|
134
|
-
defaultEngine: CONFIG_DEFAULTS.defaultEngine,
|
|
135
|
-
allowedEngines: CONFIG_DEFAULTS.allowedEngines,
|
|
136
|
-
extraArgs: CONFIG_DEFAULTS.extraArgs,
|
|
137
|
-
allowProjectLatexmkrc: CONFIG_DEFAULTS.allowProjectLatexmkrc,
|
|
138
|
-
compileTimeoutSeconds: CONFIG_DEFAULTS.compileTimeoutSeconds,
|
|
139
|
-
maxCompileJobs: CONFIG_DEFAULTS.maxCompileJobs
|
|
140
|
-
}
|
|
110
|
+
server: Object.values(server).some((value) => value !== undefined) ? server : undefined,
|
|
111
|
+
storage: process.env.TEXLITE_DATA_DIR !== undefined ? { dataDir: process.env.TEXLITE_DATA_DIR } : undefined
|
|
141
112
|
};
|
|
142
113
|
fs.writeFileSync(configPath, `${JSON.stringify(configFile, null, 2)}\n`, { encoding: "utf8", mode: 0o600, flag: "wx" });
|
|
143
114
|
try {
|
|
@@ -154,16 +125,16 @@ async function initialize(options) {
|
|
|
154
125
|
if (!fs.existsSync(configPath)) {
|
|
155
126
|
const configuredSiteName = process.env.TEXLITE_SITE_NAME;
|
|
156
127
|
const siteName = configuredSiteName !== undefined
|
|
157
|
-
? configuredSiteName.trim() ||
|
|
128
|
+
? configuredSiteName.trim() || undefined
|
|
158
129
|
: rl
|
|
159
|
-
? (await rl.question(`Site name [${CONFIG_DEFAULTS.siteName}]: `)).trim() ||
|
|
160
|
-
:
|
|
130
|
+
? (await rl.question(`Site name [${CONFIG_DEFAULTS.siteName}]: `)).trim() || undefined
|
|
131
|
+
: undefined;
|
|
161
132
|
const configuredAdminEmail = process.env.TEXLITE_ADMIN_EMAIL;
|
|
162
133
|
const adminEmail = configuredAdminEmail !== undefined
|
|
163
|
-
? configuredAdminEmail.trim()
|
|
134
|
+
? configuredAdminEmail.trim() || undefined
|
|
164
135
|
: rl
|
|
165
|
-
? (await rl.question("Administrator contact email (optional): ")).trim()
|
|
166
|
-
:
|
|
136
|
+
? (await rl.question("Administrator contact email (optional): ")).trim() || undefined
|
|
137
|
+
: undefined;
|
|
167
138
|
writeInitialConfig(configPath, siteName, adminEmail);
|
|
168
139
|
output(`Created configuration file: ${configPath}`);
|
|
169
140
|
}
|
|
@@ -298,6 +269,7 @@ async function printConfig(options) {
|
|
|
298
269
|
historyMaxVersions: config.historyMaxVersions,
|
|
299
270
|
historyMaxStorageBytes: config.historyMaxStorageBytes,
|
|
300
271
|
editHistoryMaxStorageBytes: config.editHistoryMaxStorageBytes,
|
|
272
|
+
editHistoryMaxSegments: config.editHistoryMaxSegments,
|
|
301
273
|
git: config.git
|
|
302
274
|
}, null, 2));
|
|
303
275
|
}
|