texlite 0.23.0 → 0.24.0
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 +70 -15
- package/dist/client/assets/AdminUsers-C-8tXzvj.js +1 -0
- package/dist/client/assets/AdminUsers-C-8tXzvj.js.br +0 -0
- package/dist/client/assets/AdminUsers-C-8tXzvj.js.gz +0 -0
- package/dist/client/assets/{AgentIcon-DJGGRJnV.css → AgentIcon-_B7xXJpJ.css} +1 -1
- package/dist/client/assets/AgentIcon-_B7xXJpJ.css.br +0 -0
- package/dist/client/assets/AgentIcon-_B7xXJpJ.css.gz +0 -0
- package/dist/client/assets/{AgentManagement-D-0hrv6f.js → AgentManagement-DXgfP7l_.js} +1 -1
- package/dist/client/assets/AgentManagement-DXgfP7l_.js.br +0 -0
- package/dist/client/assets/AgentManagement-DXgfP7l_.js.gz +0 -0
- package/dist/client/assets/AgentTerminal-DD4sskCS.js +2 -0
- package/dist/client/assets/AgentTerminal-DD4sskCS.js.br +0 -0
- package/dist/client/assets/AgentTerminal-DD4sskCS.js.gz +0 -0
- package/dist/client/assets/AgentTerminalSurface-DliOcop5.js +16 -0
- package/dist/client/assets/AgentTerminalSurface-DliOcop5.js.br +0 -0
- package/dist/client/assets/AgentTerminalSurface-DliOcop5.js.gz +0 -0
- package/dist/client/assets/{AvatarSettingsDialog-ChKrdDqp.js → AvatarSettingsDialog-iuEbMO4a.js} +1 -1
- package/dist/client/assets/AvatarSettingsDialog-iuEbMO4a.js.br +0 -0
- package/dist/client/assets/AvatarSettingsDialog-iuEbMO4a.js.gz +0 -0
- package/dist/client/assets/CitationBibtexEditor-CDiYDj3M.js +1 -0
- package/dist/client/assets/{CitationLibraryDialog-DqO9e0GV.js → CitationLibraryDialog-CJlL-Ytx.js} +3 -3
- package/dist/client/assets/CitationLibraryDialog-CJlL-Ytx.js.br +0 -0
- package/dist/client/assets/CitationLibraryDialog-CJlL-Ytx.js.gz +0 -0
- package/dist/client/assets/Dashboard-DqwGd9wd.js +5 -0
- package/dist/client/assets/Dashboard-DqwGd9wd.js.br +0 -0
- package/dist/client/assets/Dashboard-DqwGd9wd.js.gz +0 -0
- package/dist/client/assets/{GitDialog-CA68baSd.js → GitDialog-DUGAigLx.js} +1 -1
- package/dist/client/assets/GitDialog-DUGAigLx.js.br +0 -0
- package/dist/client/assets/GitDialog-DUGAigLx.js.gz +0 -0
- package/dist/client/assets/{GitHubAccountDialog-CnxfR0JD.js → GitHubAccountDialog-B4eD622i.js} +1 -1
- package/dist/client/assets/GitHubAccountDialog-B4eD622i.js.br +0 -0
- package/dist/client/assets/GitHubAccountDialog-B4eD622i.js.gz +0 -0
- package/dist/client/assets/HistoryDialog-upkR8E0L.js +8 -0
- package/dist/client/assets/HistoryDialog-upkR8E0L.js.br +0 -0
- package/dist/client/assets/HistoryDialog-upkR8E0L.js.gz +0 -0
- package/dist/client/assets/{InfoPopover-BJYnFn1P.js → InfoPopover-CQ3Q10tN.js} +1 -1
- package/dist/client/assets/LatexEditor-DvDYTc0r.js +25 -0
- package/dist/client/assets/LatexEditor-DvDYTc0r.js.br +0 -0
- package/dist/client/assets/LatexEditor-DvDYTc0r.js.gz +0 -0
- package/dist/client/assets/{MarkdownPreview-BJPqGTcw.js → MarkdownPreview-_AXp5G7f.js} +1 -1
- package/dist/client/assets/MarkdownPreview-_AXp5G7f.js.br +0 -0
- package/dist/client/assets/MarkdownPreview-_AXp5G7f.js.gz +0 -0
- package/dist/client/assets/{ProjectIconPickerDialog-ChiEUQ0g.js → ProjectIconPickerDialog-BxjEYsau.js} +1 -1
- package/dist/client/assets/ProjectIconPickerDialog-BxjEYsau.js.br +0 -0
- package/dist/client/assets/ProjectIconPickerDialog-BxjEYsau.js.gz +0 -0
- package/dist/client/assets/ProjectSearchDialog-BB8thfK9.js +1 -0
- package/dist/client/assets/ProjectSearchDialog-BB8thfK9.js.br +0 -0
- package/dist/client/assets/ProjectSearchDialog-BB8thfK9.js.gz +0 -0
- package/dist/client/assets/ProjectSettings-Dx-b26uN.js +4 -0
- package/dist/client/assets/ProjectSettings-Dx-b26uN.js.br +0 -0
- package/dist/client/assets/ProjectSettings-Dx-b26uN.js.gz +0 -0
- package/dist/client/assets/ProjectWorkspace-DiurYeU1.js +25 -0
- package/dist/client/assets/ProjectWorkspace-DiurYeU1.js.br +0 -0
- package/dist/client/assets/ProjectWorkspace-DiurYeU1.js.gz +0 -0
- package/dist/client/assets/{QuickOpenDialog-B7NTqOpu.js → QuickOpenDialog-HlkWqVR9.js} +1 -1
- package/dist/client/assets/QuickOpenDialog-HlkWqVR9.js.br +0 -0
- package/dist/client/assets/QuickOpenDialog-HlkWqVR9.js.gz +0 -0
- package/dist/client/assets/ReadOnlySource-BIdN1YP_.js +2 -0
- package/dist/client/assets/SelectionHistoryDialog-Cb8I-G6m.js +3 -0
- package/dist/client/assets/SelectionHistoryDialog-Cb8I-G6m.js.br +0 -0
- package/dist/client/assets/SelectionHistoryDialog-Cb8I-G6m.js.gz +0 -0
- package/dist/client/assets/SharedProjectPage-BBLOLjnD.js +2 -0
- package/dist/client/assets/SharedProjectPage-BBLOLjnD.js.br +0 -0
- package/dist/client/assets/SharedProjectPage-BBLOLjnD.js.gz +0 -0
- package/dist/client/assets/{SystemMetricsDialog-Bycm88U1.js → SystemMetricsDialog-Dr4pYWG6.js} +1 -1
- package/dist/client/assets/SystemMetricsDialog-Dr4pYWG6.js.br +0 -0
- package/dist/client/assets/SystemMetricsDialog-Dr4pYWG6.js.gz +0 -0
- package/dist/client/assets/{TagManagementDialog-DwUAA8uC.js → TagManagementDialog-D4fYVboy.js} +1 -1
- package/dist/client/assets/TagManagementDialog-D4fYVboy.js.br +0 -0
- package/dist/client/assets/TagManagementDialog-D4fYVboy.js.gz +0 -0
- package/dist/client/assets/{ThemeSwitcher-RSqZi7kx.js → ThemeSwitcher-BgzkYTeA.js} +1 -1
- package/dist/client/assets/{TikzGalleryDialog-CLAmKmS6.js → TikzGalleryDialog-cPUDQ5Wj.js} +1 -1
- package/dist/client/assets/TikzGalleryDialog-cPUDQ5Wj.js.br +0 -0
- package/dist/client/assets/TikzGalleryDialog-cPUDQ5Wj.js.gz +0 -0
- package/dist/client/assets/{WordCountDialog-ByxE-RUs.js → WordCountDialog-AiuR3rra.js} +1 -1
- package/dist/client/assets/WordCountDialog-AiuR3rra.js.br +0 -0
- package/dist/client/assets/WordCountDialog-AiuR3rra.js.gz +0 -0
- package/dist/client/assets/{chktex-22lKGvKa.js → chktex--32C-Pkl.js} +1 -1
- package/dist/client/assets/{citationLibrary-DxGdbZEQ.js → citationLibrary-BJRzAgaV.js} +1 -1
- package/dist/client/assets/citationLibrary-BJRzAgaV.js.br +0 -0
- package/dist/client/assets/citationLibrary-BJRzAgaV.js.gz +0 -0
- package/dist/client/assets/editor-CSq7NymY.js +14 -0
- package/dist/client/assets/editor-CSq7NymY.js.br +0 -0
- package/dist/client/assets/editor-CSq7NymY.js.gz +0 -0
- package/dist/client/assets/editor-languages-CKP1xVf6.js +36 -0
- package/dist/client/assets/editor-languages-CKP1xVf6.js.br +0 -0
- package/dist/client/assets/editor-languages-CKP1xVf6.js.gz +0 -0
- package/dist/client/assets/editorThemeExtension-CjBD77yn.js +1 -0
- package/dist/client/assets/editorThemeExtension-CjBD77yn.js.br +0 -0
- package/dist/client/assets/editorThemeExtension-CjBD77yn.js.gz +0 -0
- package/dist/client/assets/file-cog-D_mhAnBe.js +1 -0
- package/dist/client/assets/{generatedParser-CZa2vsK6.js → generatedParser-2izSCuvk.js} +1 -1
- package/dist/client/assets/generatedParser-2izSCuvk.js.br +0 -0
- package/dist/client/assets/generatedParser-2izSCuvk.js.gz +0 -0
- package/dist/client/assets/i18n-Dpk6KCs6.js +13 -0
- package/dist/client/assets/i18n-Dpk6KCs6.js.br +0 -0
- package/dist/client/assets/i18n-Dpk6KCs6.js.gz +0 -0
- package/dist/client/assets/index-B1vejuOw.js +2 -0
- package/dist/client/assets/index-B1vejuOw.js.br +0 -0
- package/dist/client/assets/index-B1vejuOw.js.gz +0 -0
- package/dist/client/assets/index-Blr4J_Pq.css +1 -0
- package/dist/client/assets/index-Blr4J_Pq.css.br +0 -0
- package/dist/client/assets/index-Blr4J_Pq.css.gz +0 -0
- package/dist/client/assets/{relativeTime-C-GTw3lA.js → relativeTime-CcP1IEvr.js} +1 -1
- package/dist/client/assets/relativeTime-CcP1IEvr.js.br +0 -0
- package/dist/client/assets/relativeTime-CcP1IEvr.js.gz +0 -0
- package/dist/client/assets/sourceCursorStore-EycYBVxj.js +1 -0
- package/dist/client/assets/sourceCursorStore-EycYBVxj.js.br +0 -0
- package/dist/client/assets/sourceCursorStore-EycYBVxj.js.gz +0 -0
- package/dist/client/assets/{spellCheck-kxvnxrvw.js → spellCheck-DpWPgtM7.js} +1 -1
- package/dist/client/assets/spellCheck-DpWPgtM7.js.br +0 -0
- package/dist/client/assets/spellCheck-DpWPgtM7.js.gz +0 -0
- package/dist/client/assets/textLanguageSupport-tGXUsMU9.js +1 -0
- package/dist/client/assets/textLanguages-BpqiXyQi.js +78 -0
- package/dist/client/assets/textLanguages-BpqiXyQi.js.br +0 -0
- package/dist/client/assets/textLanguages-BpqiXyQi.js.gz +0 -0
- package/dist/client/assets/useDeletionTransitions-DvxVkRuo.js +1 -0
- package/dist/client/assets/useDeletionTransitions-DvxVkRuo.js.br +0 -0
- package/dist/client/assets/useDeletionTransitions-DvxVkRuo.js.gz +0 -0
- package/dist/client/assets/{vimSupport-C-WiMLjc.js → vimSupport-DMVGjr9R.js} +6 -6
- package/dist/client/assets/vimSupport-DMVGjr9R.js.br +0 -0
- package/dist/client/assets/vimSupport-DMVGjr9R.js.gz +0 -0
- package/dist/client/index.html +3 -3
- package/dist/server/agentChanges.js +95 -7
- package/dist/server/agents/outputBuffer.js +105 -0
- package/dist/server/agents/sessions.js +33 -16
- package/dist/server/collaboration.js +9 -0
- package/dist/server/db.js +64 -0
- package/dist/server/editHistory.js +68 -20
- package/dist/server/git.js +9 -7
- package/dist/server/history.js +160 -69
- package/dist/server/i18n.js +2 -0
- package/dist/server/locales/zh-Hant.js +1 -0
- package/dist/server/projectMutations.js +4 -0
- package/dist/server/routes/comments.js +7 -2
- package/dist/server/routes/projectFiles.js +54 -0
- package/dist/server/routes/projectGit.js +1 -1
- package/dist/server/routes/projectHistory.js +19 -5
- package/dist/shared/agentMessages.js +3 -0
- package/package.json +1 -1
- package/dist/client/assets/AdminUsers-xuVuiwoh.js +0 -1
- package/dist/client/assets/AdminUsers-xuVuiwoh.js.br +0 -0
- package/dist/client/assets/AdminUsers-xuVuiwoh.js.gz +0 -0
- package/dist/client/assets/AgentIcon-DJGGRJnV.css.br +0 -0
- package/dist/client/assets/AgentIcon-DJGGRJnV.css.gz +0 -0
- package/dist/client/assets/AgentManagement-D-0hrv6f.js.br +0 -0
- package/dist/client/assets/AgentManagement-D-0hrv6f.js.gz +0 -0
- package/dist/client/assets/AgentTerminal-DZo-22RN.js +0 -2
- package/dist/client/assets/AgentTerminal-DZo-22RN.js.br +0 -0
- package/dist/client/assets/AgentTerminal-DZo-22RN.js.gz +0 -0
- package/dist/client/assets/AgentTerminalSurface-CcC17_CY.js +0 -16
- package/dist/client/assets/AgentTerminalSurface-CcC17_CY.js.br +0 -0
- package/dist/client/assets/AgentTerminalSurface-CcC17_CY.js.gz +0 -0
- package/dist/client/assets/AvatarSettingsDialog-ChKrdDqp.js.br +0 -0
- package/dist/client/assets/AvatarSettingsDialog-ChKrdDqp.js.gz +0 -0
- package/dist/client/assets/CitationBibtexEditor-BZIU4Lif.js +0 -1
- package/dist/client/assets/CitationLibraryDialog-DqO9e0GV.js.br +0 -0
- package/dist/client/assets/CitationLibraryDialog-DqO9e0GV.js.gz +0 -0
- package/dist/client/assets/Dashboard-BYgqCgBM.js +0 -5
- package/dist/client/assets/Dashboard-BYgqCgBM.js.br +0 -0
- package/dist/client/assets/Dashboard-BYgqCgBM.js.gz +0 -0
- package/dist/client/assets/GitDialog-CA68baSd.js.br +0 -0
- package/dist/client/assets/GitDialog-CA68baSd.js.gz +0 -0
- package/dist/client/assets/GitHubAccountDialog-CnxfR0JD.js.br +0 -0
- package/dist/client/assets/GitHubAccountDialog-CnxfR0JD.js.gz +0 -0
- package/dist/client/assets/HistoryDialog-c2EEaFsl.js +0 -8
- package/dist/client/assets/HistoryDialog-c2EEaFsl.js.br +0 -0
- package/dist/client/assets/HistoryDialog-c2EEaFsl.js.gz +0 -0
- package/dist/client/assets/LatexEditor-vNOVTIl7.js +0 -25
- package/dist/client/assets/LatexEditor-vNOVTIl7.js.br +0 -0
- package/dist/client/assets/LatexEditor-vNOVTIl7.js.gz +0 -0
- package/dist/client/assets/MarkdownPreview-BJPqGTcw.js.br +0 -0
- package/dist/client/assets/MarkdownPreview-BJPqGTcw.js.gz +0 -0
- package/dist/client/assets/ProjectIconPickerDialog-ChiEUQ0g.js.br +0 -0
- package/dist/client/assets/ProjectIconPickerDialog-ChiEUQ0g.js.gz +0 -0
- package/dist/client/assets/ProjectSearchDialog-DxgjbnmY.js +0 -1
- package/dist/client/assets/ProjectSearchDialog-DxgjbnmY.js.br +0 -0
- package/dist/client/assets/ProjectSearchDialog-DxgjbnmY.js.gz +0 -0
- package/dist/client/assets/ProjectSettings-BwQTbXhh.js +0 -4
- package/dist/client/assets/ProjectSettings-BwQTbXhh.js.br +0 -0
- package/dist/client/assets/ProjectSettings-BwQTbXhh.js.gz +0 -0
- package/dist/client/assets/ProjectWorkspace-C2QAb-Fc.js +0 -25
- package/dist/client/assets/ProjectWorkspace-C2QAb-Fc.js.br +0 -0
- package/dist/client/assets/ProjectWorkspace-C2QAb-Fc.js.gz +0 -0
- package/dist/client/assets/QuickOpenDialog-B7NTqOpu.js.br +0 -0
- package/dist/client/assets/QuickOpenDialog-B7NTqOpu.js.gz +0 -0
- package/dist/client/assets/ReadOnlySource-DIalHHvP.js +0 -2
- package/dist/client/assets/SelectionHistoryDialog-BhOyneNx.js +0 -3
- package/dist/client/assets/SelectionHistoryDialog-BhOyneNx.js.br +0 -0
- package/dist/client/assets/SelectionHistoryDialog-BhOyneNx.js.gz +0 -0
- package/dist/client/assets/SharedProjectPage-s-khOyvB.js +0 -2
- package/dist/client/assets/SharedProjectPage-s-khOyvB.js.br +0 -0
- package/dist/client/assets/SharedProjectPage-s-khOyvB.js.gz +0 -0
- package/dist/client/assets/SystemMetricsDialog-Bycm88U1.js.br +0 -0
- package/dist/client/assets/SystemMetricsDialog-Bycm88U1.js.gz +0 -0
- package/dist/client/assets/TagManagementDialog-DwUAA8uC.js.br +0 -0
- package/dist/client/assets/TagManagementDialog-DwUAA8uC.js.gz +0 -0
- package/dist/client/assets/TikzGalleryDialog-CLAmKmS6.js.br +0 -0
- package/dist/client/assets/TikzGalleryDialog-CLAmKmS6.js.gz +0 -0
- package/dist/client/assets/WordCountDialog-ByxE-RUs.js.br +0 -0
- package/dist/client/assets/WordCountDialog-ByxE-RUs.js.gz +0 -0
- package/dist/client/assets/citationLibrary-DxGdbZEQ.js.br +0 -0
- package/dist/client/assets/citationLibrary-DxGdbZEQ.js.gz +0 -0
- package/dist/client/assets/editor-CkUEg2La.js +0 -14
- package/dist/client/assets/editor-CkUEg2La.js.br +0 -0
- package/dist/client/assets/editor-CkUEg2La.js.gz +0 -0
- package/dist/client/assets/editor-languages-kcWr1Z3Q.js +0 -36
- package/dist/client/assets/editor-languages-kcWr1Z3Q.js.br +0 -0
- package/dist/client/assets/editor-languages-kcWr1Z3Q.js.gz +0 -0
- package/dist/client/assets/editorThemeExtension-BWtZV1Af.js +0 -1
- package/dist/client/assets/editorThemeExtension-BWtZV1Af.js.br +0 -0
- package/dist/client/assets/editorThemeExtension-BWtZV1Af.js.gz +0 -0
- package/dist/client/assets/generatedParser-CZa2vsK6.js.br +0 -0
- package/dist/client/assets/generatedParser-CZa2vsK6.js.gz +0 -0
- package/dist/client/assets/i18n-Wn96VbWM.js +0 -13
- package/dist/client/assets/i18n-Wn96VbWM.js.br +0 -0
- package/dist/client/assets/i18n-Wn96VbWM.js.gz +0 -0
- package/dist/client/assets/index-CemLYDYL.js +0 -2
- package/dist/client/assets/index-CemLYDYL.js.br +0 -0
- package/dist/client/assets/index-CemLYDYL.js.gz +0 -0
- package/dist/client/assets/index-DSF5eT29.css +0 -1
- package/dist/client/assets/index-DSF5eT29.css.br +0 -0
- package/dist/client/assets/index-DSF5eT29.css.gz +0 -0
- package/dist/client/assets/relativeTime-C-GTw3lA.js.br +0 -0
- package/dist/client/assets/relativeTime-C-GTw3lA.js.gz +0 -0
- package/dist/client/assets/sourceCursorStore-Dpoi7PAL.js +0 -1
- package/dist/client/assets/sourceCursorStore-Dpoi7PAL.js.br +0 -0
- package/dist/client/assets/sourceCursorStore-Dpoi7PAL.js.gz +0 -0
- package/dist/client/assets/spellCheck-kxvnxrvw.js.br +0 -0
- package/dist/client/assets/spellCheck-kxvnxrvw.js.gz +0 -0
- package/dist/client/assets/textLanguageSupport-Ck8lMOWz.js +0 -1
- package/dist/client/assets/textLanguages-CwWstpJ5.js +0 -78
- package/dist/client/assets/textLanguages-CwWstpJ5.js.br +0 -0
- package/dist/client/assets/textLanguages-CwWstpJ5.js.gz +0 -0
- package/dist/client/assets/useDeletionTransitions-Xlq7HabP.js +0 -1
- package/dist/client/assets/useDeletionTransitions-Xlq7HabP.js.br +0 -0
- package/dist/client/assets/useDeletionTransitions-Xlq7HabP.js.gz +0 -0
- package/dist/client/assets/vimSupport-C-WiMLjc.js.br +0 -0
- package/dist/client/assets/vimSupport-C-WiMLjc.js.gz +0 -0
- /package/dist/client/assets/{AgentIcon-qmglBc3M.js → AgentIcon-CjaO3WzI.js} +0 -0
- /package/dist/client/assets/{AgentIcon-qmglBc3M.js.br → AgentIcon-CjaO3WzI.js.br} +0 -0
- /package/dist/client/assets/{AgentIcon-qmglBc3M.js.gz → AgentIcon-CjaO3WzI.js.gz} +0 -0
package/dist/server/history.js
CHANGED
|
@@ -5,6 +5,12 @@ import { assertNoSourceSymlinks, listProjectFiles, outputRoot, projectRoot, reso
|
|
|
5
5
|
import { httpError } from "./http.js";
|
|
6
6
|
import { MAX_TEXT_PREVIEW_BYTES } from "./limits.js";
|
|
7
7
|
import { defaultHistoryTracking, historyTextCandidate, historyTrackingOverride } from "../shared/historyTracking.js";
|
|
8
|
+
/**
|
|
9
|
+
* Versions shown in the timeline and used as "previous" comparisons. Older
|
|
10
|
+
* settings-only rows are hidden; a settings-only safety checkpoint is shown.
|
|
11
|
+
*/
|
|
12
|
+
const VISIBLE_VERSION_SQL = "(json_array_length(%.changed_paths_json) > 0 OR %.reason = 'checkpoint')";
|
|
13
|
+
const visibleVersion = (alias) => VISIBLE_VERSION_SQL.replaceAll("%", alias);
|
|
8
14
|
const HOUR_MS = 60 * 60_000;
|
|
9
15
|
const DAY_MS = 24 * HOUR_MS;
|
|
10
16
|
/** Server-local hour or day, matching the local days the timeline is grouped by. */
|
|
@@ -19,10 +25,12 @@ const HISTORY_KEEP_ALL_MS = DAY_MS;
|
|
|
19
25
|
const HISTORY_KEEP_HOURLY_MS = 7 * DAY_MS;
|
|
20
26
|
/** Fixed window, from a run's first save, in which autosaves (or one user's agent writes) share a snapshot. */
|
|
21
27
|
const AUTOSAVE_COALESCE_MS = 2 * 60_000;
|
|
22
|
-
// Logical stored payload
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
// Logical stored payload: the UTF-8 bytes of a version row's text columns.
|
|
29
|
+
// SQLite pages, indexes and WAL are shared database overhead. octet_length()
|
|
30
|
+
// reads only the stored value sizes, never the manifests themselves.
|
|
31
|
+
const METADATA_BYTES_SQL = `(octet_length(id) + octet_length(project_id) + COALESCE(octet_length(author_id), 0)
|
|
32
|
+
+ octet_length(reason) + COALESCE(octet_length(label), 0) + octet_length(manifest_json)
|
|
33
|
+
+ octet_length(changed_paths_json) + octet_length(created_at))`;
|
|
26
34
|
const DEFAULT_HISTORY_PAGE_SIZE = 100;
|
|
27
35
|
const MAX_HISTORY_PAGE_SIZE = 100;
|
|
28
36
|
export class ProjectHistoryService {
|
|
@@ -46,6 +54,17 @@ export class ProjectHistoryService {
|
|
|
46
54
|
const manifest = comparable ? cloneManifest(comparable) : this.emptyManifest(project);
|
|
47
55
|
manifest.tracking = tracking;
|
|
48
56
|
manifest.settings = settings(project);
|
|
57
|
+
// The baseline assembles the new manifest, because files outside the
|
|
58
|
+
// changed roots are copied from it. Changes are reported against the
|
|
59
|
+
// newest stored version instead: the two differ after that version was
|
|
60
|
+
// deleted, and the timeline must show what changed since the snapshot a
|
|
61
|
+
// user can still see and restore.
|
|
62
|
+
const latestManifest = previous ? parseManifest(previous.manifest_json) : null;
|
|
63
|
+
const reference = latestManifest
|
|
64
|
+
? JSON.stringify(latestManifest.tracking) === JSON.stringify(tracking)
|
|
65
|
+
? latestManifest
|
|
66
|
+
: { ...latestManifest, files: this.filterTrackedObjects(projectId, latestManifest.files, tracking) }
|
|
67
|
+
: comparable;
|
|
49
68
|
if (!previousManifest || policyChanged || changedRoots === undefined) {
|
|
50
69
|
manifest.files = this.snapshotAllFiles(projectId, tracking);
|
|
51
70
|
}
|
|
@@ -60,10 +79,11 @@ export class ProjectHistoryService {
|
|
|
60
79
|
manifest.files[filePath] = file;
|
|
61
80
|
}
|
|
62
81
|
}
|
|
63
|
-
const changedPaths =
|
|
82
|
+
const changedPaths = reference ? changedManifestPaths(reference, manifest) : Object.keys(manifest.files).sort();
|
|
83
|
+
const keepSettings = Boolean(options.keepSettingsChange && reference && !sameSettings(reference.settings, manifest.settings));
|
|
64
84
|
// Settings alone do not create a file-history entry. Keep the baseline
|
|
65
85
|
// current so the next real file change captures the effective settings.
|
|
66
|
-
if (changedPaths.length === 0) {
|
|
86
|
+
if (changedPaths.length === 0 && !keepSettings) {
|
|
67
87
|
this.saveBaseline(projectId, manifest);
|
|
68
88
|
return null;
|
|
69
89
|
}
|
|
@@ -80,7 +100,22 @@ export class ProjectHistoryService {
|
|
|
80
100
|
if (!policyChanged && sameRun && previous && !previous.label
|
|
81
101
|
&& JSON.stringify(parseManifest(previous.manifest_json).tracking) === JSON.stringify(tracking)
|
|
82
102
|
&& Date.parse(createdAt) - Date.parse(previous.created_at) < AUTOSAVE_COALESCE_MS) {
|
|
83
|
-
|
|
103
|
+
// Report the run's net change against the version before it, so a file
|
|
104
|
+
// edited and then changed back is not listed as changed.
|
|
105
|
+
const beforeRun = this.previousVersion(projectId, previous.id);
|
|
106
|
+
const beforeRunFiles = beforeRun ? this.manifest(projectId, beforeRun.id)?.files ?? {} : {};
|
|
107
|
+
const merged = [...new Set([...parseStringArray(previous.changed_paths_json), ...changedPaths])]
|
|
108
|
+
.filter((filePath) => beforeRunFiles[filePath]?.digest !== manifest.files[filePath]?.digest).sort();
|
|
109
|
+
const runDigests = new Set(Object.values(parseManifest(previous.manifest_json).files).map((file) => file.digest));
|
|
110
|
+
if (merged.length === 0) {
|
|
111
|
+
// The run left every file as the previous version had it, so it is
|
|
112
|
+
// not a restore point of its own.
|
|
113
|
+
this.db.prepare("DELETE FROM project_history_versions WHERE id = ? AND project_id = ?").run(previous.id, projectId);
|
|
114
|
+
this.saveBaseline(projectId, manifest);
|
|
115
|
+
if (!options.deferRetention)
|
|
116
|
+
this.removeUnreferencedObjects(projectId, runDigests);
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
84
119
|
this.db.prepare(`UPDATE project_history_versions
|
|
85
120
|
SET manifest_json = ?, changed_paths_json = ?, author_id = ? WHERE id = ?`)
|
|
86
121
|
.run(JSON.stringify(manifest), JSON.stringify(merged), previous.author_id === authorId ? authorId : null, previous.id);
|
|
@@ -106,7 +141,7 @@ export class ProjectHistoryService {
|
|
|
106
141
|
list(projectId, limit = 100) {
|
|
107
142
|
const rows = this.db.prepare(`SELECT history.*, user.username AS author_username, user.display_name AS author_name
|
|
108
143
|
FROM project_history_versions history LEFT JOIN users user ON user.id = history.author_id
|
|
109
|
-
WHERE history.project_id = ? AND
|
|
144
|
+
WHERE history.project_id = ? AND ${visibleVersion("history")}
|
|
110
145
|
ORDER BY history.created_at DESC, history.rowid DESC LIMIT ?`)
|
|
111
146
|
.all(projectId, Math.min(200, Math.max(1, limit)));
|
|
112
147
|
return rows.map((row) => versionJson(row));
|
|
@@ -161,7 +196,7 @@ export class ProjectHistoryService {
|
|
|
161
196
|
const rows = this.db.prepare(`SELECT history.*, history.rowid AS history_rowid,
|
|
162
197
|
user.username AS author_username, user.display_name AS author_name
|
|
163
198
|
FROM project_history_versions history LEFT JOIN users user ON user.id = history.author_id
|
|
164
|
-
WHERE history.project_id = ? AND
|
|
199
|
+
WHERE history.project_id = ? AND ${visibleVersion("history")} ${cursorFilter}
|
|
165
200
|
ORDER BY history.created_at DESC, history.rowid DESC LIMIT ?`)
|
|
166
201
|
.all(...values);
|
|
167
202
|
const pageRows = rows.slice(0, limitValue);
|
|
@@ -171,29 +206,32 @@ export class ProjectHistoryService {
|
|
|
171
206
|
};
|
|
172
207
|
}
|
|
173
208
|
stats(projectId) {
|
|
174
|
-
const rows = this.db.prepare(`SELECT
|
|
175
|
-
WHERE project_id = ? ORDER BY created_at DESC, rowid DESC`)
|
|
176
|
-
|
|
177
|
-
const protectedObjects = new Map();
|
|
209
|
+
const rows = this.db.prepare(`SELECT id, reason, label, ${METADATA_BYTES_SQL} AS metadata_bytes
|
|
210
|
+
FROM project_history_versions WHERE project_id = ? ORDER BY created_at DESC, rowid DESC`)
|
|
211
|
+
.all(projectId);
|
|
178
212
|
let metadataBytes = 0;
|
|
179
213
|
let protectedMetadataBytes = 0;
|
|
180
214
|
let ordinaryVersionCount = 0;
|
|
181
215
|
let labeledVersionCount = 0;
|
|
216
|
+
const protectedIds = [];
|
|
182
217
|
for (const row of rows) {
|
|
183
218
|
const protectedVersion = row === rows[0] || row.reason === "initial" || Boolean(row.label);
|
|
184
|
-
metadataBytes +=
|
|
185
|
-
if (protectedVersion)
|
|
186
|
-
protectedMetadataBytes +=
|
|
219
|
+
metadataBytes += row.metadata_bytes;
|
|
220
|
+
if (protectedVersion) {
|
|
221
|
+
protectedMetadataBytes += row.metadata_bytes;
|
|
222
|
+
protectedIds.push(row.id);
|
|
223
|
+
}
|
|
187
224
|
if (row.label)
|
|
188
225
|
labeledVersionCount += 1;
|
|
189
226
|
else if (row.reason !== "initial")
|
|
190
227
|
ordinaryVersionCount += 1;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
228
|
+
}
|
|
229
|
+
const objects = this.objectSizes(projectId);
|
|
230
|
+
const protectedObjects = new Map();
|
|
231
|
+
const versionObjects = this.db.prepare("SELECT digest, size FROM project_history_version_objects WHERE version_id = ?");
|
|
232
|
+
for (const id of protectedIds) {
|
|
233
|
+
for (const object of versionObjects.all(id))
|
|
234
|
+
protectedObjects.set(object.digest, object.size);
|
|
197
235
|
}
|
|
198
236
|
const baseline = this.baseline(projectId);
|
|
199
237
|
if (baseline) {
|
|
@@ -221,6 +259,12 @@ export class ProjectHistoryService {
|
|
|
221
259
|
storageLimitExceeded: objectBytes + metadataBytes > this.config.historyMaxStorageBytes
|
|
222
260
|
};
|
|
223
261
|
}
|
|
262
|
+
/** Each stored content object any version refers to, with its size. */
|
|
263
|
+
objectSizes(projectId) {
|
|
264
|
+
const rows = this.db.prepare("SELECT digest, size FROM project_history_objects WHERE project_id = ?")
|
|
265
|
+
.all(projectId);
|
|
266
|
+
return new Map(rows.map((row) => [row.digest, row.size]));
|
|
267
|
+
}
|
|
224
268
|
enforceRetention(projectId) {
|
|
225
269
|
this.pruneVersions(projectId);
|
|
226
270
|
// Deferred autosave maintenance can leave an object from a coalesced
|
|
@@ -230,7 +274,8 @@ export class ProjectHistoryService {
|
|
|
230
274
|
this.removeUnreferencedObjects(projectId, this.storedObjectDigests(projectId));
|
|
231
275
|
}
|
|
232
276
|
deleteVersion(projectId, versionId) {
|
|
233
|
-
const row = this.db.prepare(
|
|
277
|
+
const row = this.db.prepare(`SELECT id, manifest_json, changed_paths_json, created_at, rowid AS history_rowid
|
|
278
|
+
FROM project_history_versions WHERE id = ? AND project_id = ?`)
|
|
234
279
|
.get(versionId, projectId);
|
|
235
280
|
if (!row)
|
|
236
281
|
return false;
|
|
@@ -295,7 +340,7 @@ export class ProjectHistoryService {
|
|
|
295
340
|
previousVersion(projectId, versionId) {
|
|
296
341
|
const row = this.db.prepare(`SELECT older.id FROM project_history_versions older
|
|
297
342
|
JOIN project_history_versions selected ON selected.id = ? AND selected.project_id = older.project_id
|
|
298
|
-
WHERE older.project_id = ? AND
|
|
343
|
+
WHERE older.project_id = ? AND ${visibleVersion("older")}
|
|
299
344
|
AND (older.created_at < selected.created_at
|
|
300
345
|
OR (older.created_at = selected.created_at AND older.rowid < selected.rowid))
|
|
301
346
|
ORDER BY older.created_at DESC, older.rowid DESC LIMIT 1`).get(versionId, projectId);
|
|
@@ -378,7 +423,7 @@ export class ProjectHistoryService {
|
|
|
378
423
|
}
|
|
379
424
|
// This policy belongs only to the safety checkpoint, not project settings.
|
|
380
425
|
// Even a legacy restore or a single excluded file must remain reversible.
|
|
381
|
-
return this.record(projectId, authorId, "checkpoint", undefined, { tracking });
|
|
426
|
+
return this.record(projectId, authorId, "checkpoint", undefined, { tracking, keepSettingsChange: selected === null });
|
|
382
427
|
}
|
|
383
428
|
assertRestoreTargetIsFile(projectId, filePath) {
|
|
384
429
|
const target = resolveSourcePath(this.config, projectId, filePath);
|
|
@@ -536,23 +581,21 @@ export class ProjectHistoryService {
|
|
|
536
581
|
return digests;
|
|
537
582
|
}
|
|
538
583
|
pruneVersions(projectId) {
|
|
539
|
-
const rows = this.db.prepare(`SELECT
|
|
584
|
+
const rows = this.db.prepare(`SELECT id, reason, label, created_at, changed_paths_json, rowid AS history_rowid,
|
|
585
|
+
${METADATA_BYTES_SQL} AS metadata_bytes
|
|
540
586
|
FROM project_history_versions WHERE project_id = ?
|
|
541
587
|
ORDER BY created_at DESC, rowid DESC`).all(projectId);
|
|
542
588
|
if (!rows.length)
|
|
543
589
|
return;
|
|
544
|
-
//
|
|
545
|
-
|
|
590
|
+
// Reference counts are kept by the database for each stored content, so
|
|
591
|
+
// retention never parses manifests; a version's objects are read only if
|
|
592
|
+
// that version is removed.
|
|
546
593
|
const refCounts = new Map();
|
|
547
594
|
const sizeMap = new Map();
|
|
548
|
-
for (const row of
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
refCounts.set(file.digest, (refCounts.get(file.digest) ?? 0) + 1);
|
|
553
|
-
if (!sizeMap.has(file.digest))
|
|
554
|
-
sizeMap.set(file.digest, file.size);
|
|
555
|
-
}
|
|
595
|
+
for (const row of this.db.prepare("SELECT digest, refs, size FROM project_history_objects WHERE project_id = ?")
|
|
596
|
+
.all(projectId)) {
|
|
597
|
+
refCounts.set(row.digest, row.refs);
|
|
598
|
+
sizeMap.set(row.digest, row.size);
|
|
556
599
|
}
|
|
557
600
|
const baseline = this.baseline(projectId);
|
|
558
601
|
if (baseline) {
|
|
@@ -562,7 +605,7 @@ export class ProjectHistoryService {
|
|
|
562
605
|
sizeMap.set(file.digest, file.size);
|
|
563
606
|
}
|
|
564
607
|
}
|
|
565
|
-
let retainedBytes = rows.reduce((sum, row) => sum +
|
|
608
|
+
let retainedBytes = rows.reduce((sum, row) => sum + row.metadata_bytes, 0)
|
|
566
609
|
+ (baseline ? Buffer.byteLength(JSON.stringify(baseline), "utf8") : 0);
|
|
567
610
|
for (const [digest, count] of refCounts.entries()) {
|
|
568
611
|
if (count > 0)
|
|
@@ -571,32 +614,31 @@ export class ProjectHistoryService {
|
|
|
571
614
|
const latestId = rows[0]?.id;
|
|
572
615
|
// Ordinary versions eligible for version count capping (ordered newest to oldest)
|
|
573
616
|
const ordinaryDesc = rows.filter((row) => row.label === null && row.reason !== "initial");
|
|
617
|
+
const overVersionLimit = this.config.historyMaxVersions > 0 && ordinaryDesc.length > this.config.historyMaxVersions;
|
|
618
|
+
if (!overVersionLimit && retainedBytes <= this.config.historyMaxStorageBytes)
|
|
619
|
+
return;
|
|
574
620
|
const toDeleteIds = new Set();
|
|
575
621
|
const rowsById = new Map(rows.map((row) => [row.id, row]));
|
|
622
|
+
const versionObjects = this.db.prepare("SELECT digest FROM project_history_version_objects WHERE version_id = ?");
|
|
576
623
|
const removeVersionRefs = (versionId) => {
|
|
577
624
|
if (toDeleteIds.has(versionId))
|
|
578
625
|
return;
|
|
579
626
|
toDeleteIds.add(versionId);
|
|
580
|
-
retainedBytes -=
|
|
581
|
-
const
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
retainedBytes -= sizeMap.get(file.digest) ?? 0;
|
|
590
|
-
}
|
|
591
|
-
else if (count > 1) {
|
|
592
|
-
refCounts.set(file.digest, count - 1);
|
|
593
|
-
}
|
|
627
|
+
retainedBytes -= rowsById.get(versionId).metadata_bytes;
|
|
628
|
+
for (const { digest } of versionObjects.all(versionId)) {
|
|
629
|
+
const count = refCounts.get(digest);
|
|
630
|
+
if (count === 1) {
|
|
631
|
+
refCounts.set(digest, 0);
|
|
632
|
+
retainedBytes -= sizeMap.get(digest) ?? 0;
|
|
633
|
+
}
|
|
634
|
+
else if (count !== undefined && count > 1) {
|
|
635
|
+
refCounts.set(digest, count - 1);
|
|
594
636
|
}
|
|
595
637
|
}
|
|
596
638
|
};
|
|
597
639
|
// 1. Cap by historyMaxVersions (prune excess ordinary versions when configured; 0 = unlimited)
|
|
598
640
|
const remainingOrdinary = () => ordinaryDesc.filter((row) => !toDeleteIds.has(row.id));
|
|
599
|
-
if (
|
|
641
|
+
if (overVersionLimit) {
|
|
600
642
|
const obsolete = ordinaryDesc.slice(this.config.historyMaxVersions);
|
|
601
643
|
for (const row of obsolete)
|
|
602
644
|
removeVersionRefs(row.id);
|
|
@@ -644,6 +686,7 @@ export class ProjectHistoryService {
|
|
|
644
686
|
this.db.transaction(() => {
|
|
645
687
|
for (const id of toDeleteIds)
|
|
646
688
|
remove.run(id, projectId);
|
|
689
|
+
this.carryChangedPaths(projectId, rows.filter((row) => toDeleteIds.has(row.id)));
|
|
647
690
|
})();
|
|
648
691
|
// 5. Remove unreferenced CAS objects on disk
|
|
649
692
|
for (const [digest, count] of refCounts.entries()) {
|
|
@@ -660,28 +703,63 @@ export class ProjectHistoryService {
|
|
|
660
703
|
candidates.add(file.digest);
|
|
661
704
|
}
|
|
662
705
|
const remove = this.db.prepare("DELETE FROM project_history_versions WHERE id = ? AND project_id = ?");
|
|
663
|
-
this.db.transaction(() => {
|
|
664
|
-
|
|
706
|
+
this.db.transaction(() => {
|
|
707
|
+
for (const row of rows)
|
|
708
|
+
remove.run(row.id, projectId);
|
|
709
|
+
this.carryChangedPaths(projectId, rows);
|
|
710
|
+
})();
|
|
665
711
|
this.removeUnreferencedObjects(projectId, candidates);
|
|
666
712
|
}
|
|
713
|
+
/**
|
|
714
|
+
* Each version lists the files changed since the version before it. When
|
|
715
|
+
* versions are removed, the next remaining version is now compared with an
|
|
716
|
+
* older one, so it takes over the removed versions' changes. Only files that
|
|
717
|
+
* still differ from the new predecessor are kept.
|
|
718
|
+
*/
|
|
719
|
+
carryChangedPaths(projectId, removed) {
|
|
720
|
+
if (!removed.length)
|
|
721
|
+
return;
|
|
722
|
+
const order = (left, right) => left.created_at < right.created_at ? -1 : left.created_at > right.created_at ? 1 : left.history_rowid - right.history_rowid;
|
|
723
|
+
const pending = [...removed].sort(order);
|
|
724
|
+
const survivors = this.db.prepare(`SELECT id, rowid AS history_rowid, created_at, changed_paths_json
|
|
725
|
+
FROM project_history_versions history WHERE project_id = ? AND ${visibleVersion("history")}
|
|
726
|
+
ORDER BY created_at ASC, rowid ASC`).all(projectId);
|
|
727
|
+
const update = this.db.prepare("UPDATE project_history_versions SET changed_paths_json = ? WHERE id = ? AND project_id = ?");
|
|
728
|
+
let next = 0;
|
|
729
|
+
let previousId = null;
|
|
730
|
+
for (const survivor of survivors) {
|
|
731
|
+
const carried = new Set();
|
|
732
|
+
while (next < pending.length && order(pending[next], survivor) < 0) {
|
|
733
|
+
for (const filePath of parseStringArray(pending[next].changed_paths_json))
|
|
734
|
+
carried.add(filePath);
|
|
735
|
+
next += 1;
|
|
736
|
+
}
|
|
737
|
+
if (carried.size) {
|
|
738
|
+
const own = parseStringArray(survivor.changed_paths_json);
|
|
739
|
+
const files = this.manifest(projectId, survivor.id).files;
|
|
740
|
+
const before = previousId ? this.manifest(projectId, previousId).files : {};
|
|
741
|
+
const differing = [...new Set([...own, ...carried])].filter((filePath) => before[filePath]?.digest !== files[filePath]?.digest).sort();
|
|
742
|
+
// An identical version keeps its old list rather than vanishing from
|
|
743
|
+
// the timeline, which hides versions without changed files.
|
|
744
|
+
const combined = differing.length ? differing : [...own].sort();
|
|
745
|
+
if (JSON.stringify(combined) !== survivor.changed_paths_json)
|
|
746
|
+
update.run(JSON.stringify(combined), survivor.id, projectId);
|
|
747
|
+
}
|
|
748
|
+
previousId = survivor.id;
|
|
749
|
+
if (next >= pending.length)
|
|
750
|
+
break;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
667
753
|
removeUnreferencedObjects(projectId, candidates) {
|
|
668
754
|
if (!candidates.size)
|
|
669
755
|
return;
|
|
670
|
-
const
|
|
671
|
-
|
|
672
|
-
for (const
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
if (!candidates.size)
|
|
676
|
-
return;
|
|
677
|
-
}
|
|
678
|
-
const baseline = this.baseline(projectId);
|
|
679
|
-
if (baseline) {
|
|
680
|
-
for (const file of Object.values(baseline.files))
|
|
681
|
-
candidates.delete(file.digest);
|
|
682
|
-
}
|
|
683
|
-
for (const digest of candidates)
|
|
756
|
+
const referenced = this.db.prepare("SELECT 1 FROM project_history_objects WHERE project_id = ? AND digest = ?");
|
|
757
|
+
const baselineDigests = new Set(Object.values(this.baseline(projectId)?.files ?? {}).map((file) => file.digest));
|
|
758
|
+
for (const digest of candidates) {
|
|
759
|
+
if (baselineDigests.has(digest) || referenced.get(projectId, digest))
|
|
760
|
+
continue;
|
|
684
761
|
fs.rmSync(this.objectPath(projectId, digest), { force: true });
|
|
762
|
+
}
|
|
685
763
|
}
|
|
686
764
|
restoreProjectTree(projectId, manifest) {
|
|
687
765
|
assertNoSourceSymlinks(this.config, projectId);
|
|
@@ -695,9 +773,18 @@ export class ProjectHistoryService {
|
|
|
695
773
|
let gitMoved = false;
|
|
696
774
|
try {
|
|
697
775
|
if (manifest.tracking) {
|
|
776
|
+
const entries = listProjectFiles(this.config, projectId);
|
|
777
|
+
// An empty folder holds nothing a snapshot records, so like other
|
|
778
|
+
// content outside the snapshot's scope it survives the restore.
|
|
779
|
+
const files = entries.filter((entry) => entry.type === "file").map((entry) => entry.path);
|
|
780
|
+
for (const folder of entries) {
|
|
781
|
+
if (folder.type !== "directory" || files.some((filePath) => filePath.startsWith(`${folder.path}/`)))
|
|
782
|
+
continue;
|
|
783
|
+
fs.mkdirSync(path.join(temporary, safeRelativePath(folder.path)), { recursive: true, mode: 0o700 });
|
|
784
|
+
}
|
|
698
785
|
// Files outside this snapshot's scope survive a project restore. Stage
|
|
699
786
|
// them before swapping trees so a copy/conflict failure is harmless.
|
|
700
|
-
for (const file of
|
|
787
|
+
for (const file of entries) {
|
|
701
788
|
if (file.type !== "file" || manifest.files[file.path])
|
|
702
789
|
continue;
|
|
703
790
|
const source = resolveSourcePath(this.config, projectId, file.path);
|
|
@@ -744,6 +831,10 @@ export class ProjectHistoryService {
|
|
|
744
831
|
function settings(project) {
|
|
745
832
|
return { mainFile: project.main_file, engine: project.engine, latexmkrc: project.latexmkrc, chktexEnabled: Boolean(project.chktex_enabled) };
|
|
746
833
|
}
|
|
834
|
+
function sameSettings(left, right) {
|
|
835
|
+
return left.mainFile === right.mainFile && left.engine === right.engine && left.latexmkrc === right.latexmkrc
|
|
836
|
+
&& Boolean(left.chktexEnabled) === Boolean(right.chktexEnabled);
|
|
837
|
+
}
|
|
747
838
|
function cloneManifest(manifest) {
|
|
748
839
|
return { ...manifest, files: { ...manifest.files }, settings: { ...manifest.settings } };
|
|
749
840
|
}
|
package/dist/server/i18n.js
CHANGED
|
@@ -39,6 +39,7 @@ const enMessages = {
|
|
|
39
39
|
CLIENT_UPDATE_REQUIRED: "This page is out of date. Save your changes and reload it to continue writing checks.",
|
|
40
40
|
COMMENT_DELETE_FORBIDDEN: "You can only delete your own comments.",
|
|
41
41
|
COMMENT_EDIT_FORBIDDEN: "You can only edit your own comments.",
|
|
42
|
+
COMMENT_RESOLVE_FORBIDDEN: "Only members who can edit this project can resolve or reopen comments.",
|
|
42
43
|
COMMENT_FILE_NOT_FOUND: "The file for this comment does not exist.",
|
|
43
44
|
COMMENT_NOT_FOUND: "The comment does not exist.",
|
|
44
45
|
COMMENT_RANGE_INVALID: "The comment source range is invalid.",
|
|
@@ -192,6 +193,7 @@ const zhMessages = {
|
|
|
192
193
|
CLIENT_UPDATE_REQUIRED: "当前页面版本过旧。请先保存修改,再刷新页面以继续写作检查。",
|
|
193
194
|
COMMENT_DELETE_FORBIDDEN: "只能删除自己的批注。",
|
|
194
195
|
COMMENT_EDIT_FORBIDDEN: "只能编辑自己的批注。",
|
|
196
|
+
COMMENT_RESOLVE_FORBIDDEN: "只有可以编辑此项目的成员才能解决或重新打开批注。",
|
|
195
197
|
COMMENT_FILE_NOT_FOUND: "批注对应的文件不存在。",
|
|
196
198
|
COMMENT_NOT_FOUND: "批注不存在。",
|
|
197
199
|
COMMENT_RANGE_INVALID: "批注的源码区间无效。",
|
|
@@ -33,6 +33,7 @@ export const zhHantMessages = {
|
|
|
33
33
|
CLIENT_UPDATE_REQUIRED: "目前頁面版本過舊。請先儲存修改,再重新整理頁面,以繼續寫作檢查。",
|
|
34
34
|
COMMENT_DELETE_FORBIDDEN: "只能刪除自己的批註。",
|
|
35
35
|
COMMENT_EDIT_FORBIDDEN: "只能編輯自己的批註。",
|
|
36
|
+
COMMENT_RESOLVE_FORBIDDEN: "只有可以編輯此專案的成員才能解決或重新開啟批註。",
|
|
36
37
|
COMMENT_FILE_NOT_FOUND: "批註對應的檔案不存在。",
|
|
37
38
|
COMMENT_NOT_FOUND: "批註不存在。",
|
|
38
39
|
COMMENT_RANGE_INVALID: "批註的原始碼範圍無效。",
|
|
@@ -38,6 +38,10 @@ export class ProjectMutationCoordinator {
|
|
|
38
38
|
flushProject(projectId) {
|
|
39
39
|
return this.requireSuccessfulFlush(this.collaboration.flushProject(projectId));
|
|
40
40
|
}
|
|
41
|
+
/** See `CollaborationService.reconcileExternalSources`; call it inside a project operation. */
|
|
42
|
+
reconcileExternalSources(projectId, paths) {
|
|
43
|
+
this.collaboration.reconcileExternalSources(projectId, paths);
|
|
44
|
+
}
|
|
41
45
|
async runExclusive(projectId, reason, operation, options = {}) {
|
|
42
46
|
this.exclusivePending.set(projectId, (this.exclusivePending.get(projectId) ?? 0) + 1);
|
|
43
47
|
const exclusion = this.beginCompileExclusion(projectId);
|
|
@@ -4,7 +4,7 @@ import { requireUser } from "../auth.js";
|
|
|
4
4
|
import { createSourceAnchor, offsetToLine } from "../anchors.js";
|
|
5
5
|
import { resolveSourcePath, safeRelativePath } from "../files.js";
|
|
6
6
|
import { apiError, httpError } from "../http.js";
|
|
7
|
-
import { accessibleProject } from "../projects.js";
|
|
7
|
+
import { accessibleProject, canEdit } from "../projects.js";
|
|
8
8
|
import { isCollaborativeTextFile } from "../collaboration.js";
|
|
9
9
|
import { attachSuggestion, suggestionReviewers, suggestionRow } from "../commentSuggestions.js";
|
|
10
10
|
import { registerSuggestionRoutes } from "./commentSuggestions.js";
|
|
@@ -201,7 +201,8 @@ export function registerCommentRoutes(app, context) {
|
|
|
201
201
|
if (!user)
|
|
202
202
|
return;
|
|
203
203
|
const { id, commentId } = request.params;
|
|
204
|
-
|
|
204
|
+
const project = accessibleProject(db, id, user);
|
|
205
|
+
if (!project)
|
|
205
206
|
return apiError(reply, 404, "PROJECT_NOT_FOUND");
|
|
206
207
|
const comment = db.prepare("SELECT author_id, resolved, content FROM comments WHERE id = ? AND project_id = ?")
|
|
207
208
|
.get(commentId, id);
|
|
@@ -217,6 +218,10 @@ export function registerCommentRoutes(app, context) {
|
|
|
217
218
|
changed = true;
|
|
218
219
|
}
|
|
219
220
|
if (typeof body.resolved === "boolean") {
|
|
221
|
+
// Read-only members may discuss, but closing or reopening a thread is a
|
|
222
|
+
// review decision for people who can change the project.
|
|
223
|
+
if (!canEdit(project))
|
|
224
|
+
return apiError(reply, 403, "COMMENT_RESOLVE_FORBIDDEN");
|
|
220
225
|
if (body.resolved) {
|
|
221
226
|
const suggestion = suggestionRow(db, id, commentId);
|
|
222
227
|
if (suggestion?.status === "pending" && (suggestion.apply_update
|
|
@@ -10,6 +10,7 @@ import { isCollaborativeTextFile, maxCollaborativeFileBytes } from "../collabora
|
|
|
10
10
|
import { compileMainFile } from "../compileArtifacts.js";
|
|
11
11
|
import { assertNoSourceSymlinks, listProjectFilesAsync, resolveSourcePath, safePathSegment, safeRelativePath, sourceRoot } from "../files.js";
|
|
12
12
|
import { apiError, contentDisposition, httpError } from "../http.js";
|
|
13
|
+
import { moveEditHistoryPaths } from "../editHistory.js";
|
|
13
14
|
import { accessibleProject, canEdit } from "../projects.js";
|
|
14
15
|
import { mainDocumentCandidates } from "../latexRoot.js";
|
|
15
16
|
import { isTextContent } from "../../shared/fileTypes.js";
|
|
@@ -230,6 +231,7 @@ export function registerProjectFileRoutes(app, context) {
|
|
|
230
231
|
hasCommentUpdates = true;
|
|
231
232
|
}
|
|
232
233
|
}
|
|
234
|
+
moveEditHistoryPaths(db, id, (filePath) => movedProjectPath(filePath, source, destination));
|
|
233
235
|
db.exec("COMMIT");
|
|
234
236
|
}
|
|
235
237
|
catch (error) {
|
|
@@ -370,6 +372,42 @@ export function registerProjectFileRoutes(app, context) {
|
|
|
370
372
|
return reply.code(201).send({ ok: true, path: filePath, comments: commentsForFile(db, config, id, filePath) });
|
|
371
373
|
}, { preflight: () => { requireEditableProject(db, id, user); } });
|
|
372
374
|
});
|
|
375
|
+
// Duplicate a file next to itself. The server chooses the name under the
|
|
376
|
+
// write lock, so two quick copies cannot race for the same "(copy)" name.
|
|
377
|
+
app.post("/api/projects/:id/file/copy", async (request, reply) => {
|
|
378
|
+
const user = requireUser(request, reply, db);
|
|
379
|
+
if (!user)
|
|
380
|
+
return;
|
|
381
|
+
const { id } = request.params;
|
|
382
|
+
if (collaboration.isMaintaining(id))
|
|
383
|
+
return apiError(reply, 409, "PROJECT_BUSY");
|
|
384
|
+
const project = accessibleProject(db, id, user);
|
|
385
|
+
if (!project || !canEdit(project))
|
|
386
|
+
return apiError(reply, 403, "PROJECT_EDIT_FORBIDDEN");
|
|
387
|
+
const body = request.body;
|
|
388
|
+
const source = safeRelativePath(typeof body.path === "string" ? body.path : "");
|
|
389
|
+
return await projectMutations.runWrite(id, () => {
|
|
390
|
+
assertNoSourceSymlinks(config, id);
|
|
391
|
+
// runWrite() has flushed live Yjs edits, so the copy has the text
|
|
392
|
+
// collaborators currently see rather than an older file on disk.
|
|
393
|
+
const sourceAbsolute = resolveSourcePath(config, id, source);
|
|
394
|
+
if (!fs.existsSync(sourceAbsolute) || !fs.statSync(sourceAbsolute).isFile()) {
|
|
395
|
+
return apiError(reply, 404, "FILE_NOT_FOUND", { path: source });
|
|
396
|
+
}
|
|
397
|
+
const destination = copiedFilePath(source, (candidate) => fs.existsSync(resolveSourcePath(config, id, candidate)));
|
|
398
|
+
const destinationAbsolute = resolveSourcePath(config, id, destination);
|
|
399
|
+
fs.copyFileSync(sourceAbsolute, destinationAbsolute, fs.constants.COPYFILE_EXCL);
|
|
400
|
+
touchProject(db, id, user.id);
|
|
401
|
+
const bytes = isCollaborativeTextFile(destination) && fs.statSync(destinationAbsolute).size <= maxCollaborativeFileBytes(config)
|
|
402
|
+
? fs.readFileSync(destinationAbsolute) : null;
|
|
403
|
+
if (bytes !== null && isTextContent(bytes))
|
|
404
|
+
collaboration.updateFile(id, destination, bytes.toString("utf8"), user.id);
|
|
405
|
+
else
|
|
406
|
+
collaboration.invalidateSourceTree(id, destination);
|
|
407
|
+
recordHistory(id, user.id, "file", [destination]);
|
|
408
|
+
return reply.code(201).send({ ok: true, path: destination });
|
|
409
|
+
}, { preflight: () => { requireEditableProject(db, id, user); } });
|
|
410
|
+
});
|
|
373
411
|
app.put("/api/projects/:id/file", async (request, reply) => {
|
|
374
412
|
const user = requireUser(request, reply, db);
|
|
375
413
|
if (!user)
|
|
@@ -569,3 +607,19 @@ export function registerProjectFileRoutes(app, context) {
|
|
|
569
607
|
}
|
|
570
608
|
});
|
|
571
609
|
}
|
|
610
|
+
/**
|
|
611
|
+
* Name a copy beside its source: `main.tex` becomes `main (copy).tex`, then
|
|
612
|
+
* `main (copy 2).tex`. A leading dot is part of the name, not an extension.
|
|
613
|
+
*/
|
|
614
|
+
export function copiedFilePath(source, exists) {
|
|
615
|
+
const slash = source.lastIndexOf("/");
|
|
616
|
+
const directory = slash < 0 ? "" : source.slice(0, slash + 1);
|
|
617
|
+
const name = source.slice(slash + 1);
|
|
618
|
+
const dot = name.lastIndexOf(".");
|
|
619
|
+
const [stem, extension] = dot > 0 ? [name.slice(0, dot), name.slice(dot)] : [name, ""];
|
|
620
|
+
for (let attempt = 1;; attempt += 1) {
|
|
621
|
+
const candidate = `${directory}${stem} (copy${attempt === 1 ? "" : ` ${attempt}`})${extension}`;
|
|
622
|
+
if (!exists(candidate))
|
|
623
|
+
return candidate;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
@@ -75,7 +75,7 @@ export function registerProjectGitRoutes(app, context) {
|
|
|
75
75
|
if (collaboration.isMaintaining(id))
|
|
76
76
|
return apiError(reply, 409, "PROJECT_BUSY");
|
|
77
77
|
const body = request.body;
|
|
78
|
-
return await projectMutations.
|
|
78
|
+
return await projectMutations.runConsistentRead(id, async () => {
|
|
79
79
|
const project = requireGitOwner(id, user);
|
|
80
80
|
const commit = await projectGit.commit(project, user, typeof body.message === "string" ? body.message : "");
|
|
81
81
|
return reply.code(201).send({ commit, status: await projectGit.status(project) });
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import { requireUser } from "../auth.js";
|
|
3
3
|
import { isCollaborativeTextFile, maxCollaborativeFileBytes } from "../collaboration.js";
|
|
4
|
-
import {
|
|
4
|
+
import { normalizeAgentChangeLineEndings } from "../agentChanges.js";
|
|
5
|
+
import { hashText, MAX_SELECTION_HISTORY_OFFSET } from "../editHistory.js";
|
|
5
6
|
import { HISTORY_RETENTION_DELAY_MS } from "../historyRetention.js";
|
|
6
7
|
import { resolveSourcePath, safeRelativePath } from "../files.js";
|
|
7
8
|
import { apiError, httpError } from "../http.js";
|
|
@@ -65,6 +66,9 @@ export function registerProjectHistoryRoutes(app, context) {
|
|
|
65
66
|
if (start === null || end === null || start === end)
|
|
66
67
|
return apiError(reply, 400, "REQUEST_INVALID");
|
|
67
68
|
const requestedLimit = parseOffset(query.limit);
|
|
69
|
+
const offset = query.offset === undefined ? 0 : parseOffset(query.offset);
|
|
70
|
+
if (offset === null || offset > MAX_SELECTION_HISTORY_OFFSET)
|
|
71
|
+
return apiError(reply, 400, "REQUEST_INVALID");
|
|
68
72
|
return await projectMutations.runConsistentRead(id, () => {
|
|
69
73
|
const source = resolveSourcePath(config, id, filePath);
|
|
70
74
|
if (!fs.existsSync(source) || !fs.statSync(source).isFile())
|
|
@@ -76,7 +80,7 @@ export function registerProjectHistoryRoutes(app, context) {
|
|
|
76
80
|
return apiError(reply, 409, "SELECTION_HISTORY_SOURCE_CHANGED");
|
|
77
81
|
if (start > end || end > content.length)
|
|
78
82
|
return apiError(reply, 400, "REQUEST_INVALID");
|
|
79
|
-
return editHistory.selectionHistory(id, filePath, content, start, end, requestedLimit ?? undefined);
|
|
83
|
+
return editHistory.selectionHistory(id, filePath, content, start, end, requestedLimit ?? undefined, offset);
|
|
80
84
|
}, { preflight: () => {
|
|
81
85
|
if (!accessibleProject(db, id, user))
|
|
82
86
|
throw httpError(404, "PROJECT_NOT_FOUND");
|
|
@@ -94,10 +98,18 @@ export function registerProjectHistoryRoutes(app, context) {
|
|
|
94
98
|
const { id } = request.params;
|
|
95
99
|
if (!accessibleProject(db, id, user))
|
|
96
100
|
return apiError(reply, 404, "PROJECT_NOT_FOUND");
|
|
97
|
-
|
|
101
|
+
// Everything below is synchronous, so no autosave can interleave with it.
|
|
102
|
+
return await projectMutations.runSnapshot(id, () => {
|
|
98
103
|
const paths = db.prepare(`SELECT DISTINCT file_path FROM project_edit_segments
|
|
99
104
|
WHERE project_id = ? AND author_id = ? AND has_agent = 1 ORDER BY file_path LIMIT ?`)
|
|
100
105
|
.all(id, user.id, MAX_AGENT_CHANGE_FILES).map((row) => row.file_path);
|
|
106
|
+
// A running agent's newest write may not have reached the edit chain yet.
|
|
107
|
+
// Its file would not match the chain's end and look as if it had no changes.
|
|
108
|
+
try {
|
|
109
|
+
projectMutations.reconcileExternalSources(id, paths);
|
|
110
|
+
}
|
|
111
|
+
catch { /* The writer's next scan reports this and stops the task. */ }
|
|
112
|
+
projectMutations.flushProject(id);
|
|
101
113
|
const files = [];
|
|
102
114
|
for (const filePath of paths) {
|
|
103
115
|
if (!isCollaborativeTextFile(filePath))
|
|
@@ -113,8 +125,10 @@ export function registerProjectHistoryRoutes(app, context) {
|
|
|
113
125
|
continue;
|
|
114
126
|
const content = fs.readFileSync(source, "utf8");
|
|
115
127
|
const changes = editHistory.agentChanges(id, filePath, content, user.id);
|
|
116
|
-
if (changes.length)
|
|
117
|
-
|
|
128
|
+
if (changes.length) {
|
|
129
|
+
const normalized = normalizeAgentChangeLineEndings(changes, content);
|
|
130
|
+
files.push({ path: filePath, sourceHash: hashText(normalized.source), changes: [...normalized.changes] });
|
|
131
|
+
}
|
|
118
132
|
}
|
|
119
133
|
return { files };
|
|
120
134
|
}, { preflight: () => {
|
|
@@ -8,6 +8,7 @@ export const agentMessages = {
|
|
|
8
8
|
AGENT_SESSION_BUSY: "Wait for the current task operation to finish.",
|
|
9
9
|
AGENT_PROJECT_BUSY: "Another agent task is active in this project. It must end before another can start; hiding the terminal does not stop it.",
|
|
10
10
|
AGENT_SYNC_FAILED: "External file synchronization failed. The agent has been stopped; check the project files and server logs.",
|
|
11
|
+
AGENT_STOPPED_BY_PROJECT_OPERATION: "A project operation ended this agent task's execution.",
|
|
11
12
|
AGENT_SYNC_CONFLICT: "Concurrent edits conflicted. The editor version was preserved and agent files were saved under .texlite-agent-conflicts in this project. The agent has been stopped.",
|
|
12
13
|
AGENT_NO_CONTEXT: "This task's saved conversation cannot be resumed. Create a new task with + to start a new conversation.",
|
|
13
14
|
AGENT_CONTEXT_CHECK_FAILED: "The task's saved conversation could not be verified. Retry, or check the agent's installation and task data. No new conversation was started.",
|
|
@@ -24,6 +25,7 @@ export const agentMessages = {
|
|
|
24
25
|
AGENT_SESSION_BUSY: "请等待当前任务操作完成。",
|
|
25
26
|
AGENT_PROJECT_BUSY: "本项目已有 Agent 任务在运行,需先结束该任务才能启动其他任务;收起终端不会停止任务。",
|
|
26
27
|
AGENT_SYNC_FAILED: "外部文件同步失败,Agent 已停止。请检查项目文件和服务器日志。",
|
|
28
|
+
AGENT_STOPPED_BY_PROJECT_OPERATION: "项目操作已结束此 Agent 任务的运行。",
|
|
27
29
|
AGENT_SYNC_CONFLICT: "并发修改存在冲突。已保留编辑器版本,Agent 的文件已保存在本项目的 .texlite-agent-conflicts 目录中,Agent 已停止。",
|
|
28
30
|
AGENT_NO_CONTEXT: "无法恢复此任务的对话。请通过+新建任务以开始新对话。",
|
|
29
31
|
AGENT_CONTEXT_CHECK_FAILED: "无法确认此任务的对话状态。请重试,或检查 Agent 安装及任务数据;尚未创建新对话。",
|
|
@@ -40,6 +42,7 @@ export const agentMessages = {
|
|
|
40
42
|
AGENT_SESSION_BUSY: "請等待目前任務操作完成。",
|
|
41
43
|
AGENT_PROJECT_BUSY: "此專案已有 Agent 任務正在執行,須先結束該任務才能啟動其他任務;收起終端機不會停止任務。",
|
|
42
44
|
AGENT_SYNC_FAILED: "外部檔案同步失敗,Agent 已停止。請檢查專案檔案與伺服器日誌。",
|
|
45
|
+
AGENT_STOPPED_BY_PROJECT_OPERATION: "專案操作已結束此 Agent 任務的執行。",
|
|
43
46
|
AGENT_SYNC_CONFLICT: "並行修改發生衝突。已保留編輯器版本,Agent 的檔案已儲存於此專案的 .texlite-agent-conflicts 目錄中,Agent 已停止。",
|
|
44
47
|
AGENT_NO_CONTEXT: "無法恢復此任務的對話。請透過+新增任務以開始新對話。",
|
|
45
48
|
AGENT_CONTEXT_CHECK_FAILED: "無法確認此任務的對話狀態。請重試,或檢查 Agent 安裝及任務資料;尚未建立新對話。",
|