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.
Files changed (228) hide show
  1. package/DESIGN.md +442 -26
  2. package/NPM_TESTING.md +23 -0
  3. package/OPERATIONS.md +227 -6
  4. package/README.md +8 -2
  5. package/README.zh-CN.md +6 -2
  6. package/THIRD_PARTY_NOTICES.md +73 -0
  7. package/dist/client/assets/AdminUsers-CuYfWnEk.js +1 -0
  8. package/dist/client/assets/AdminUsers-CuYfWnEk.js.br +0 -0
  9. package/dist/client/assets/AdminUsers-CuYfWnEk.js.gz +0 -0
  10. package/dist/client/assets/AgentIcon-ClP5dPRL.js +1 -0
  11. package/dist/client/assets/AgentIcon-ClP5dPRL.js.br +0 -0
  12. package/dist/client/assets/AgentIcon-ClP5dPRL.js.gz +0 -0
  13. package/dist/client/assets/AgentIcon-DxrC-zx_.css +1 -0
  14. package/dist/client/assets/AgentIcon-DxrC-zx_.css.br +0 -0
  15. package/dist/client/assets/AgentIcon-DxrC-zx_.css.gz +0 -0
  16. package/dist/client/assets/AgentManagement-jY_BF6Qy.js +1 -0
  17. package/dist/client/assets/AgentManagement-jY_BF6Qy.js.br +0 -0
  18. package/dist/client/assets/AgentManagement-jY_BF6Qy.js.gz +0 -0
  19. package/dist/client/assets/AgentTerminal-JKP2SVkZ.js +2 -0
  20. package/dist/client/assets/AgentTerminal-JKP2SVkZ.js.br +0 -0
  21. package/dist/client/assets/AgentTerminal-JKP2SVkZ.js.gz +0 -0
  22. package/dist/client/assets/AgentTerminalSurface-B5LH8GIb.css +1 -0
  23. package/dist/client/assets/AgentTerminalSurface-B5LH8GIb.css.br +0 -0
  24. package/dist/client/assets/AgentTerminalSurface-B5LH8GIb.css.gz +0 -0
  25. package/dist/client/assets/AgentTerminalSurface-CaYNNZ9A.js +16 -0
  26. package/dist/client/assets/AgentTerminalSurface-CaYNNZ9A.js.br +0 -0
  27. package/dist/client/assets/AgentTerminalSurface-CaYNNZ9A.js.gz +0 -0
  28. package/dist/client/assets/AvatarSettingsDialog-C2TACfvP.js +1 -0
  29. package/dist/client/assets/AvatarSettingsDialog-C2TACfvP.js.br +0 -0
  30. package/dist/client/assets/AvatarSettingsDialog-C2TACfvP.js.gz +0 -0
  31. package/dist/client/assets/CitationLibraryDialog-BdU9nbgG.js +1 -0
  32. package/dist/client/assets/CitationLibraryDialog-BdU9nbgG.js.br +0 -0
  33. package/dist/client/assets/CitationLibraryDialog-BdU9nbgG.js.gz +0 -0
  34. package/dist/client/assets/Dashboard-B7mMz5Gj.js +5 -0
  35. package/dist/client/assets/Dashboard-B7mMz5Gj.js.br +0 -0
  36. package/dist/client/assets/Dashboard-B7mMz5Gj.js.gz +0 -0
  37. package/dist/client/assets/GitDialog-C2H-jKVO.js +3 -0
  38. package/dist/client/assets/GitDialog-C2H-jKVO.js.br +0 -0
  39. package/dist/client/assets/GitDialog-C2H-jKVO.js.gz +0 -0
  40. package/dist/client/assets/GitHubAccountDialog-DdKiE3pw.js +1 -0
  41. package/dist/client/assets/GitHubAccountDialog-DdKiE3pw.js.br +0 -0
  42. package/dist/client/assets/GitHubAccountDialog-DdKiE3pw.js.gz +0 -0
  43. package/dist/client/assets/{GitHubIcon-DNR0CleM.js → GitHubIcon-Cjli8pd_.js} +1 -1
  44. package/dist/client/assets/HistoryDialog-CoxJ3EsK.js +8 -0
  45. package/dist/client/assets/HistoryDialog-CoxJ3EsK.js.br +0 -0
  46. package/dist/client/assets/HistoryDialog-CoxJ3EsK.js.gz +0 -0
  47. package/dist/client/assets/{LatexEditor-BzAk3WQM.js → LatexEditor-BhAKioho.js} +26 -26
  48. package/dist/client/assets/LatexEditor-BhAKioho.js.br +0 -0
  49. package/dist/client/assets/LatexEditor-BhAKioho.js.gz +0 -0
  50. package/dist/client/assets/PdfPreview-CC8KEz1Y.js +1 -0
  51. package/dist/client/assets/PdfPreview-CC8KEz1Y.js.br +0 -0
  52. package/dist/client/assets/PdfPreview-CC8KEz1Y.js.gz +0 -0
  53. package/dist/client/assets/ProjectIconPickerDialog-vi_HwlCS.js +1 -0
  54. package/dist/client/assets/ProjectIconPickerDialog-vi_HwlCS.js.br +0 -0
  55. package/dist/client/assets/ProjectIconPickerDialog-vi_HwlCS.js.gz +0 -0
  56. package/dist/client/assets/ProjectSettings-Bl1t-Gnh.js +4 -0
  57. package/dist/client/assets/ProjectSettings-Bl1t-Gnh.js.br +0 -0
  58. package/dist/client/assets/ProjectSettings-Bl1t-Gnh.js.gz +0 -0
  59. package/dist/client/assets/ProjectWorkspace-1UOdyfBq.js +30 -0
  60. package/dist/client/assets/ProjectWorkspace-1UOdyfBq.js.br +0 -0
  61. package/dist/client/assets/ProjectWorkspace-1UOdyfBq.js.gz +0 -0
  62. package/dist/client/assets/{QuickOpenDialog-CyqeckBM.js → QuickOpenDialog-BAzyrB-4.js} +1 -1
  63. package/dist/client/assets/QuickOpenDialog-BAzyrB-4.js.br +0 -0
  64. package/dist/client/assets/QuickOpenDialog-BAzyrB-4.js.gz +0 -0
  65. package/dist/client/assets/SaveButton-DkyoEu6j.js +1 -0
  66. package/dist/client/assets/SelectionHistoryDialog-DzlVKtxs.js +3 -0
  67. package/dist/client/assets/SelectionHistoryDialog-DzlVKtxs.js.br +0 -0
  68. package/dist/client/assets/SelectionHistoryDialog-DzlVKtxs.js.gz +0 -0
  69. package/dist/client/assets/SuccessNotice-ubBtzzi_.js +1 -0
  70. package/dist/client/assets/SystemMetricsDialog-C6RVZdJZ.js +1 -0
  71. package/dist/client/assets/SystemMetricsDialog-C6RVZdJZ.js.br +0 -0
  72. package/dist/client/assets/SystemMetricsDialog-C6RVZdJZ.js.gz +0 -0
  73. package/dist/client/assets/TagColorSelect-xbc2H5ou.js +1 -0
  74. package/dist/client/assets/TagManagementDialog-8pZUVaEI.js +1 -0
  75. package/dist/client/assets/TagManagementDialog-8pZUVaEI.js.br +0 -0
  76. package/dist/client/assets/TagManagementDialog-8pZUVaEI.js.gz +0 -0
  77. package/dist/client/assets/{WordCountDialog-Bp8kYngA.js → WordCountDialog-BODhL9iz.js} +1 -1
  78. package/dist/client/assets/WordCountDialog-BODhL9iz.js.br +0 -0
  79. package/dist/client/assets/WordCountDialog-BODhL9iz.js.gz +0 -0
  80. package/dist/client/assets/arrow-down-B6T7Z6IO.js +1 -0
  81. package/dist/client/assets/check-BRlv1lrZ.js +1 -0
  82. package/dist/client/assets/chevron-up-krb7w67X.js +1 -0
  83. package/dist/client/assets/{chktex-BcGmZVUy.js → chktex-Bz-LKycq.js} +1 -1
  84. package/dist/client/assets/{clock-3-x2vcGFSH.js → clock-3-Fb1_e3ec.js} +1 -1
  85. package/dist/client/assets/{dist-D5mbpudl.js → dist-CMYWzCHL.js} +1 -1
  86. package/dist/client/assets/dist-CMYWzCHL.js.br +0 -0
  87. package/dist/client/assets/dist-CMYWzCHL.js.gz +0 -0
  88. package/dist/client/assets/{eye-CvzXPIMu.js → eye-B6AX_5uX.js} +1 -1
  89. package/dist/client/assets/{hard-drive-BeGQ5o79.js → hard-drive-CBmnJ2xS.js} +1 -1
  90. package/dist/client/assets/i18n-DF6keNBA.js +13 -0
  91. package/dist/client/assets/i18n-DF6keNBA.js.br +0 -0
  92. package/dist/client/assets/i18n-DF6keNBA.js.gz +0 -0
  93. package/dist/client/assets/index-DCwfhKK9.js +42 -0
  94. package/dist/client/assets/index-DCwfhKK9.js.br +0 -0
  95. package/dist/client/assets/index-DCwfhKK9.js.gz +0 -0
  96. package/dist/client/assets/index-SVNFLCYh.css +1 -0
  97. package/dist/client/assets/index-SVNFLCYh.css.br +0 -0
  98. package/dist/client/assets/index-SVNFLCYh.css.gz +0 -0
  99. package/dist/client/assets/info-DNSAs0_-.js +1 -0
  100. package/dist/client/assets/{minimize-2-yYMmsVER.js → minimize-2-C8oL6PTV.js} +1 -1
  101. package/dist/client/assets/{minus-CNHOVLWS.js → minus-TCBOakyi.js} +1 -1
  102. package/dist/client/assets/plus-Dfkyfvvy.js +1 -0
  103. package/dist/client/assets/{refresh-cw-B7vZa5K2.js → refresh-cw-DuLtxWBX.js} +1 -1
  104. package/dist/client/assets/relativeTime-BR0CVAvz.js +1 -0
  105. package/dist/client/assets/relativeTime-BR0CVAvz.js.br +0 -0
  106. package/dist/client/assets/relativeTime-BR0CVAvz.js.gz +0 -0
  107. package/dist/client/assets/{search-Czv3qsBy.js → search-n-2tBATf.js} +1 -1
  108. package/dist/client/assets/{spellCheck-DDCaK8Yx.js → spellCheck-xzICTGx1.js} +1 -1
  109. package/dist/client/assets/spellCheck-xzICTGx1.js.br +0 -0
  110. package/dist/client/assets/spellCheck-xzICTGx1.js.gz +0 -0
  111. package/dist/client/assets/tags-Dy96boLq.js +1 -0
  112. package/dist/client/assets/terminal-C0xh8jVR.js +1 -0
  113. package/dist/client/assets/{type-NT195OCy.js → type-BjXWxrjH.js} +1 -1
  114. package/dist/client/assets/{user-plus-BRuwNzcg.js → user-plus-3oJZJXHW.js} +1 -1
  115. package/dist/client/index.html +13 -7
  116. package/dist/server/agents/adapters/claude.js +180 -0
  117. package/dist/server/agents/adapters/codex.js +47 -0
  118. package/dist/server/agents/adapters/common.js +86 -0
  119. package/dist/server/agents/adapters/opencode.js +196 -0
  120. package/dist/server/agents/adapters/types.js +1 -0
  121. package/dist/server/agents/execution.js +147 -0
  122. package/dist/server/agents/launcher.js +57 -0
  123. package/dist/server/agents/processIdentity.js +63 -0
  124. package/dist/server/agents/registry.js +72 -0
  125. package/dist/server/agents/sessions.js +574 -0
  126. package/dist/server/agents/terminal.js +84 -0
  127. package/dist/server/agents/workspaces.js +341 -0
  128. package/dist/server/app.js +32 -1
  129. package/dist/server/cli.js +19 -47
  130. package/dist/server/collaboration.js +64 -36
  131. package/dist/server/compileArtifacts.js +11 -44
  132. package/dist/server/compiler.js +16 -38
  133. package/dist/server/config.js +8 -2
  134. package/dist/server/db.js +33 -0
  135. package/dist/server/editHistory.js +59 -65
  136. package/dist/server/history.js +28 -13
  137. package/dist/server/i18n.js +26 -8
  138. package/dist/server/latexRoot.js +4 -2
  139. package/dist/server/locales/zh-Hant.js +145 -0
  140. package/dist/server/lucideIcons.js +14 -17
  141. package/dist/server/projectMutations.js +21 -0
  142. package/dist/server/routes/agents.js +135 -0
  143. package/dist/server/routes/compile.js +23 -43
  144. package/dist/server/routes/projectHistory.js +13 -6
  145. package/dist/server/routes/projectShared.js +6 -1
  146. package/dist/server/routes/projects.js +15 -23
  147. package/dist/shared/agentMessages.js +51 -0
  148. package/dist/shared/agentProtocol.js +41 -0
  149. package/dist/shared/historyFiles.js +1 -1
  150. package/dist/shared/historyTracking.js +2 -0
  151. package/dist/shared/locales.js +21 -0
  152. package/dist/shared/sourceCommentAnchors.js +52 -4
  153. package/package.json +7 -3
  154. package/templates/agents/AGENTS.md +135 -0
  155. package/texlite.config.example.json +3 -2
  156. package/dist/client/assets/AdminUsers-rPpYTAU6.js +0 -1
  157. package/dist/client/assets/AdminUsers-rPpYTAU6.js.br +0 -0
  158. package/dist/client/assets/AdminUsers-rPpYTAU6.js.gz +0 -0
  159. package/dist/client/assets/AvatarSettingsDialog-CIPKapVe.js +0 -1
  160. package/dist/client/assets/AvatarSettingsDialog-CIPKapVe.js.br +0 -0
  161. package/dist/client/assets/AvatarSettingsDialog-CIPKapVe.js.gz +0 -0
  162. package/dist/client/assets/CitationLibraryDialog-BhZX8BV2.js +0 -1
  163. package/dist/client/assets/CitationLibraryDialog-BhZX8BV2.js.br +0 -0
  164. package/dist/client/assets/CitationLibraryDialog-BhZX8BV2.js.gz +0 -0
  165. package/dist/client/assets/Dashboard-DppEhsjL.js +0 -5
  166. package/dist/client/assets/Dashboard-DppEhsjL.js.br +0 -0
  167. package/dist/client/assets/Dashboard-DppEhsjL.js.gz +0 -0
  168. package/dist/client/assets/GitDialog-BOu46hxA.js +0 -3
  169. package/dist/client/assets/GitDialog-BOu46hxA.js.br +0 -0
  170. package/dist/client/assets/GitDialog-BOu46hxA.js.gz +0 -0
  171. package/dist/client/assets/GitHubAccountDialog-hosK9cLW.js +0 -1
  172. package/dist/client/assets/GitHubAccountDialog-hosK9cLW.js.br +0 -0
  173. package/dist/client/assets/GitHubAccountDialog-hosK9cLW.js.gz +0 -0
  174. package/dist/client/assets/HistoryDialog-BdkuEl8r.js +0 -8
  175. package/dist/client/assets/HistoryDialog-BdkuEl8r.js.br +0 -0
  176. package/dist/client/assets/HistoryDialog-BdkuEl8r.js.gz +0 -0
  177. package/dist/client/assets/LatexEditor-BzAk3WQM.js.br +0 -0
  178. package/dist/client/assets/LatexEditor-BzAk3WQM.js.gz +0 -0
  179. package/dist/client/assets/PdfPreview-DkjI1eCo.js +0 -1
  180. package/dist/client/assets/PdfPreview-DkjI1eCo.js.br +0 -0
  181. package/dist/client/assets/PdfPreview-DkjI1eCo.js.gz +0 -0
  182. package/dist/client/assets/ProjectIconPickerDialog-D8Uo4H10.js +0 -1
  183. package/dist/client/assets/ProjectIconPickerDialog-D8Uo4H10.js.br +0 -0
  184. package/dist/client/assets/ProjectIconPickerDialog-D8Uo4H10.js.gz +0 -0
  185. package/dist/client/assets/ProjectSettings-Jdr94nOc.js +0 -1
  186. package/dist/client/assets/ProjectSettings-Jdr94nOc.js.br +0 -0
  187. package/dist/client/assets/ProjectSettings-Jdr94nOc.js.gz +0 -0
  188. package/dist/client/assets/ProjectWorkspace-D9v3Jj8T.js +0 -30
  189. package/dist/client/assets/ProjectWorkspace-D9v3Jj8T.js.br +0 -0
  190. package/dist/client/assets/ProjectWorkspace-D9v3Jj8T.js.gz +0 -0
  191. package/dist/client/assets/QuickOpenDialog-CyqeckBM.js.br +0 -0
  192. package/dist/client/assets/QuickOpenDialog-CyqeckBM.js.gz +0 -0
  193. package/dist/client/assets/SelectionHistoryDialog-Dlutex-A.js +0 -3
  194. package/dist/client/assets/SelectionHistoryDialog-Dlutex-A.js.br +0 -0
  195. package/dist/client/assets/SelectionHistoryDialog-Dlutex-A.js.gz +0 -0
  196. package/dist/client/assets/SystemMetricsDialog-CCWxXw6g.js +0 -1
  197. package/dist/client/assets/SystemMetricsDialog-CCWxXw6g.js.br +0 -0
  198. package/dist/client/assets/SystemMetricsDialog-CCWxXw6g.js.gz +0 -0
  199. package/dist/client/assets/TagColorSelect-D3T-rw4K.js +0 -1
  200. package/dist/client/assets/TagManagementDialog-CxjrSX-o.js +0 -1
  201. package/dist/client/assets/TagManagementDialog-CxjrSX-o.js.br +0 -0
  202. package/dist/client/assets/TagManagementDialog-CxjrSX-o.js.gz +0 -0
  203. package/dist/client/assets/WordCountDialog-Bp8kYngA.js.br +0 -0
  204. package/dist/client/assets/WordCountDialog-Bp8kYngA.js.gz +0 -0
  205. package/dist/client/assets/binary-B57nBiwS.js +0 -1
  206. package/dist/client/assets/check-DFoA73zZ.js +0 -1
  207. package/dist/client/assets/chevron-up-C8DyKLxi.js +0 -1
  208. package/dist/client/assets/dist-D5mbpudl.js.br +0 -0
  209. package/dist/client/assets/dist-D5mbpudl.js.gz +0 -0
  210. package/dist/client/assets/i18n-CRWKZA6W.js +0 -9
  211. package/dist/client/assets/i18n-CRWKZA6W.js.br +0 -0
  212. package/dist/client/assets/i18n-CRWKZA6W.js.gz +0 -0
  213. package/dist/client/assets/index-D0eqhDpZ.js +0 -42
  214. package/dist/client/assets/index-D0eqhDpZ.js.br +0 -0
  215. package/dist/client/assets/index-D0eqhDpZ.js.gz +0 -0
  216. package/dist/client/assets/index-DnhiIb1V.css +0 -1
  217. package/dist/client/assets/index-DnhiIb1V.css.br +0 -0
  218. package/dist/client/assets/index-DnhiIb1V.css.gz +0 -0
  219. package/dist/client/assets/plus-BDquy76g.js +0 -1
  220. package/dist/client/assets/relativeTime-DuOytR_J.js +0 -1
  221. package/dist/client/assets/relativeTime-DuOytR_J.js.br +0 -0
  222. package/dist/client/assets/relativeTime-DuOytR_J.js.gz +0 -0
  223. package/dist/client/assets/sigma-CI6gmAkl.js +0 -1
  224. package/dist/client/assets/spellCheck-DDCaK8Yx.js.br +0 -0
  225. package/dist/client/assets/spellCheck-DDCaK8Yx.js.gz +0 -0
  226. package/dist/client/assets/tags-CLK7WRSs.js +0 -1
  227. package/preview-1.png +0 -0
  228. package/preview-2.png +0 -0
@@ -4,6 +4,7 @@ import { randomUUID } from "node:crypto";
4
4
  import { performance } from "node:perf_hooks";
5
5
  import { WebSocket } from "ws";
6
6
  import * as Y from "yjs";
7
+ import { makeDiff } from "@sanity/diff-match-patch";
7
8
  import * as encoding from "lib0/encoding";
8
9
  import * as decoding from "lib0/decoding";
9
10
  import * as syncProtocol from "y-protocols/sync";
@@ -11,7 +12,7 @@ import { Awareness, applyAwarenessUpdate, encodeAwarenessUpdate, modifyAwareness
11
12
  import { listProjectFilesAsync, outputRoot, resolveSourcePath, safeRelativePath, sourceRoot } from "./files.js";
12
13
  import { collaborationProjectAccessFromStatement, canEdit, prepareCollaborationProjectAccessStatement } from "./projects.js";
13
14
  import { reanchorFileComments } from "./anchors.js";
14
- import { hashText } from "./editHistory.js";
15
+ import { createEditHistorySpan, hashText } from "./editHistory.js";
15
16
  import { isEditableTextFile, isTextContent, MAX_TEXT_EDITOR_BYTES } from "../shared/fileTypes.js";
16
17
  import { COLLABORATION_PROTOCOL_VERSION, CollaborationMessageType, isCollaborationCleanMode, isCollaborationCompileStatus } from "../shared/collaborationProtocol.js";
17
18
  export { COLLABORATION_PROTOCOL_VERSION } from "../shared/collaborationProtocol.js";
@@ -38,7 +39,6 @@ const MAX_FORMAT_LEASE_WAITERS = MAX_PROJECT_SESSIONS * 2;
38
39
  // collaborator's edit, so the resulting record remains attributable.
39
40
  const EDIT_SEGMENT_IDLE_MS = 30_000;
40
41
  const MAX_EDIT_SPANS_PER_STEP = 96;
41
- const MAX_EDIT_PREVIEW_CHARS = 1_200;
42
42
  // Completion notifications are useful only to browsers that were already
43
43
  // present when the operation finished. The database and retained manifests
44
44
  // are the authority for a later workspace open.
@@ -54,6 +54,7 @@ export class CollaborationService {
54
54
  config;
55
55
  db;
56
56
  onPersist;
57
+ externalSources = new Map();
57
58
  rooms = new Map();
58
59
  maintenanceProjects = new Map();
59
60
  roomInitializations = new Map();
@@ -148,6 +149,40 @@ export class CollaborationService {
148
149
  const room = this.rooms.get(projectId);
149
150
  return room ? this.flushRoom(room) : null;
150
151
  }
152
+ /** Active external writers reconcile disk edits before an autosave can overwrite them. */
153
+ observeExternalSources(projectId, observer) {
154
+ this.externalSources.set(projectId, observer);
155
+ return () => { if (this.externalSources.get(projectId) === observer)
156
+ this.externalSources.delete(projectId); };
157
+ }
158
+ /** Apply disk edits as a real attributed Yjs delta, retaining pending human edits and anchors. */
159
+ importExternalText(projectId, filePath, content, userId) {
160
+ const room = this.rooms.get(projectId);
161
+ if (!room || !isCollaborativeTextFile(filePath))
162
+ return false;
163
+ room.allowedPaths.add(filePath);
164
+ const text = this.trackedText(room, filePath);
165
+ // A cold room may have hydrated this disk revision before the observer's
166
+ // next scan. Let its caller record that external transition. An identical
167
+ // still-dirty human draft, however, already has its own edit attribution.
168
+ if (text.toString() === content)
169
+ return room.persistedContent.get(filePath) !== content;
170
+ const diffs = makeDiff(text.toString(), content, { checkLines: true, timeout: 1 });
171
+ room.doc.transact(() => {
172
+ let offset = 0;
173
+ for (const [kind, value] of diffs) {
174
+ if (kind === -1)
175
+ text.delete(offset, value.length);
176
+ else {
177
+ if (kind === 1)
178
+ text.insert(offset, value);
179
+ offset += value.length;
180
+ }
181
+ }
182
+ }, { externalUserId: userId });
183
+ this.bumpFiles(room, { kind: "update", path: filePath });
184
+ return true;
185
+ }
151
186
  /**
152
187
  * Prevent collaboration autosaves from changing the source tree while a
153
188
  * compiler is copying an immutable snapshot. Yjs updates remain accepted in
@@ -220,6 +255,7 @@ export class CollaborationService {
220
255
  return { rooms: this.rooms.size, sessions, dirtyFiles, initializing: this.roomInitializations.size };
221
256
  }
222
257
  updateFile(projectId, filePathInput, content, userId) {
258
+ this.externalSources.get(projectId)?.written([filePathInput]);
223
259
  const room = this.rooms.get(projectId);
224
260
  if (!room) {
225
261
  this.invalidateProject(projectId);
@@ -344,6 +380,7 @@ export class CollaborationService {
344
380
  : revision === null;
345
381
  }
346
382
  movePath(projectId, sourceInput, destinationInput, userId) {
383
+ this.externalSources.get(projectId)?.written([sourceInput, destinationInput]);
347
384
  const room = this.rooms.get(projectId);
348
385
  if (!room) {
349
386
  this.invalidateProject(projectId);
@@ -371,6 +408,7 @@ export class CollaborationService {
371
408
  this.bumpFiles(room, { kind: "move", source, destination });
372
409
  }
373
410
  removePath(projectId, filePathInput) {
411
+ this.externalSources.get(projectId)?.written([filePathInput]);
374
412
  const room = this.rooms.get(projectId);
375
413
  if (!room) {
376
414
  this.invalidateProject(projectId);
@@ -391,6 +429,7 @@ export class CollaborationService {
391
429
  this.bumpFiles(room, { kind: "delete", path: filePath });
392
430
  }
393
431
  invalidateSourceTree(projectId, filePathInput) {
432
+ this.externalSources.get(projectId)?.written(filePathInput ? [filePathInput] : []);
394
433
  this.invalidateProject(projectId);
395
434
  const room = this.rooms.get(projectId);
396
435
  if (!room)
@@ -783,7 +822,7 @@ export class CollaborationService {
783
822
  // the stable identifier before getText() materializes the public type.
784
823
  const hasRecoveredText = bootstrap.recoveredState && room.doc.share.has(name);
785
824
  const text = this.trackedText(room, file.path);
786
- if (hasRecoveredText && text.toString() !== file.content) {
825
+ if (hasRecoveredText && text.toString() !== file.content && !this.externalSources.has(projectId)) {
787
826
  room.dirtyPaths.add(file.path);
788
827
  recoveredDirty = true;
789
828
  }
@@ -825,6 +864,8 @@ export class CollaborationService {
825
864
  if (origin && typeof origin === "object" && "user" in origin) {
826
865
  room.lastModifiedUserId = origin.user.id;
827
866
  }
867
+ if (isExternalOrigin(origin))
868
+ room.lastModifiedUserId = origin.externalUserId;
828
869
  this.scheduleSave(room);
829
870
  }
830
871
  });
@@ -930,7 +971,10 @@ export class CollaborationService {
930
971
  }
931
972
  if (isConnectionOrigin(transaction.origin) && before !== after) {
932
973
  const connection = transaction.origin;
933
- this.recordEditStep(room, filePath, connection, event, before, after);
974
+ this.recordEditStep(room, filePath, connection.user.id, event, before, after, this.activeFormatLease(room, filePath)?.connection === connection);
975
+ }
976
+ if (isExternalOrigin(transaction.origin) && before !== after) {
977
+ this.recordEditStep(room, filePath, transaction.origin.externalUserId, event, before, after);
934
978
  }
935
979
  if (before !== after) {
936
980
  const edits = [];
@@ -944,7 +988,8 @@ export class CollaborationService {
944
988
  offset += delta.retain;
945
989
  }
946
990
  else if (delta.delete || typeof delta.insert === "string") {
947
- pending ??= { from: offset, to: offset, insert: "", insertLength: 0 };
991
+ pending ??= { from: offset, to: offset, insert: "", insertLength: 0,
992
+ inferred: isExternalOrigin(transaction.origin) };
948
993
  if (delta.delete) {
949
994
  offset += delta.delete;
950
995
  pending.to = offset;
@@ -973,13 +1018,12 @@ export class CollaborationService {
973
1018
  * segment is only handed to the history service after `flushRoom()` has
974
1019
  * made the matching source content durable.
975
1020
  */
976
- recordEditStep(room, filePath, connection, event, before, after) {
1021
+ recordEditStep(room, filePath, authorId, event, before, after, formatted = false) {
977
1022
  const spans = editSpansFromYDelta(event.delta, before, after);
978
1023
  if (!spans.length)
979
1024
  return;
980
1025
  const createdAt = new Date().toISOString();
981
- const activeLease = this.activeFormatLease(room, filePath);
982
- const kind = activeLease?.connection === connection ? "format" : "edit";
1026
+ const kind = formatted ? "format" : "edit";
983
1027
  const step = {
984
1028
  beforeHash: hashText(before),
985
1029
  afterHash: hashText(after),
@@ -990,7 +1034,7 @@ export class CollaborationService {
990
1034
  const previousTime = previous ? Date.parse(previous.updatedAt) : Number.NaN;
991
1035
  if (previous
992
1036
  && previous.filePath === filePath
993
- && previous.authorId === connection.user.id
1037
+ && previous.authorId === authorId
994
1038
  && previous.kind === kind
995
1039
  && previous.afterHash === step.beforeHash
996
1040
  && Number.isFinite(previousTime)
@@ -1002,7 +1046,7 @@ export class CollaborationService {
1002
1046
  }
1003
1047
  room.pendingEditSegments.push({
1004
1048
  filePath,
1005
- authorId: connection.user.id,
1049
+ authorId,
1006
1050
  kind,
1007
1051
  beforeHash: step.beforeHash,
1008
1052
  afterHash: step.afterHash,
@@ -1439,6 +1483,7 @@ export class CollaborationService {
1439
1483
  room.snapshotFlushPending = true;
1440
1484
  return this.currentReceipt(room);
1441
1485
  }
1486
+ this.externalSources.get(room.projectId)?.beforeFlush([...room.dirtyPaths]);
1442
1487
  const startedAt = performance.now();
1443
1488
  if (room.saveTimer)
1444
1489
  clearTimeout(room.saveTimer);
@@ -1557,6 +1602,8 @@ export class CollaborationService {
1557
1602
  }, 2000);
1558
1603
  }
1559
1604
  const receipt = this.currentReceipt(room, ok, [...new Set(failedPaths)]);
1605
+ if (changedPaths.length)
1606
+ this.externalSources.get(room.projectId)?.written(changedPaths);
1560
1607
  room.rejectedPaths.clear();
1561
1608
  return receipt;
1562
1609
  }
@@ -1725,9 +1772,8 @@ function replaceText(text, content) {
1725
1772
  text.insert(0, content);
1726
1773
  }
1727
1774
  /**
1728
- * Turn Y.Text's transaction delta into compact positional spans. We retain
1729
- * lengths for exact range mapping, while previews keep a pasted/formatter
1730
- * change from turning the edit-history database into a second source store.
1775
+ * Turn Y.Text's transaction delta into reversible positional replacements.
1776
+ * The history service bounds total storage, not individual replacement text.
1731
1777
  */
1732
1778
  function editSpansFromYDelta(delta, before, after) {
1733
1779
  if (before === after)
@@ -1743,7 +1789,7 @@ function editSpansFromYDelta(delta, before, after) {
1743
1789
  const deletedLength = pending.deleted.length;
1744
1790
  const insertedLength = pending.inserted.length;
1745
1791
  if (deletedLength || insertedLength) {
1746
- spans.push(editSpan(pending.beforeStart, pending.beforeStart + deletedLength, pending.afterStart, pending.afterStart + insertedLength, pending.deleted, pending.inserted));
1792
+ spans.push(createEditHistorySpan(pending.beforeStart, pending.afterStart, pending.deleted, pending.inserted));
1747
1793
  }
1748
1794
  pending = null;
1749
1795
  };
@@ -1800,28 +1846,7 @@ function editSpansFromYDelta(delta, before, after) {
1800
1846
  function wholeDocumentEditSpan(before, after) {
1801
1847
  const prefix = commonPrefixLength(before, after);
1802
1848
  const suffix = commonSuffixLength(before, after, prefix);
1803
- return editSpan(prefix, before.length - suffix, prefix, after.length - suffix, before.slice(prefix, before.length - suffix), after.slice(prefix, after.length - suffix));
1804
- }
1805
- function editSpan(beforeStart, beforeEnd, afterStart, afterEnd, deleted, inserted) {
1806
- const deletedPreview = previewEditText(deleted);
1807
- const insertedPreview = previewEditText(inserted);
1808
- return {
1809
- beforeStart,
1810
- beforeEnd,
1811
- afterStart,
1812
- afterEnd,
1813
- deletedLength: deleted.length,
1814
- insertedLength: inserted.length,
1815
- deletedPreview,
1816
- insertedPreview,
1817
- truncated: deletedPreview.length < deleted.length || insertedPreview.length < inserted.length
1818
- };
1819
- }
1820
- function previewEditText(value) {
1821
- if (value.length <= MAX_EDIT_PREVIEW_CHARS)
1822
- return value;
1823
- const edge = Math.floor((MAX_EDIT_PREVIEW_CHARS - 1) / 2);
1824
- return `${value.slice(0, edge)}…${value.slice(value.length - edge)}`;
1849
+ return createEditHistorySpan(prefix, prefix, before.slice(prefix, before.length - suffix), after.slice(prefix, after.length - suffix));
1825
1850
  }
1826
1851
  function commonPrefixLength(left, right) {
1827
1852
  const max = Math.min(left.length, right.length);
@@ -1858,6 +1883,9 @@ function protocolMessage(epoch) {
1858
1883
  function isConnectionOrigin(origin) {
1859
1884
  return Boolean(origin && typeof origin === "object" && "socket" in origin);
1860
1885
  }
1886
+ function isExternalOrigin(origin) {
1887
+ return Boolean(origin && typeof origin === "object" && "externalUserId" in origin);
1888
+ }
1861
1889
  function isSharedCompileState(mainFile, value) {
1862
1890
  if (!value || typeof value !== "object" || Array.isArray(value))
1863
1891
  return false;
@@ -1,7 +1,7 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { publishedCompileArtifacts } from "./compiler.js";
4
- import { outputRoot, resolveSourcePath, safeRelativePath, sourceRoot, texFileStem } from "./files.js";
4
+ import { outputRoot, resolveSourcePath, safeRelativePath, texFileStem } from "./files.js";
5
5
  import { isMainDocumentCandidateSync } from "./latexRoot.js";
6
6
  import { MAX_TEXT_PREVIEW_BYTES } from "./limits.js";
7
7
  import { withBasePath } from "../shared/basePath.js";
@@ -11,20 +11,9 @@ export function pdfLoadingMode(config, pdfSizeBytes) {
11
11
  }
12
12
  return pdfSizeBytes > config.pdfRangeThresholdBytes ? "range" : "full";
13
13
  }
14
- export function availablePdf(config, projectId, mainFile, defaultMainFile) {
15
- const isDefault = mainFile === defaultMainFile;
16
- const published = publishedCompileArtifacts(config, projectId, mainFile, isDefault);
17
- if (published)
18
- return { path: published.pdf, version: published.runId };
19
- if (!isDefault)
20
- return null;
21
- const retained = retainedPdfPath(config, projectId);
22
- const retainedStat = regularFileStat(retained);
23
- if (retainedStat)
24
- return { path: retained, version: String(retainedStat.mtimeMs) };
25
- const legacy = path.join(outputRoot(config, projectId), `${texFileStem(mainFile)}.pdf`);
26
- const legacyStat = regularFileStat(legacy);
27
- return legacyStat ? { path: legacy, version: String(legacyStat.mtimeMs) } : null;
14
+ export function availablePdf(config, projectId, mainFile) {
15
+ const published = publishedCompileArtifacts(config, projectId, mainFile);
16
+ return published ? { path: published.pdf, version: published.runId } : null;
28
17
  }
29
18
  /** Resolve the PDF bytes belonging to one successful compile run. */
30
19
  export function compileRunPdf(config, projectId, mainFile, runId) {
@@ -34,27 +23,9 @@ export function compileRunPdf(config, projectId, mainFile, runId) {
34
23
  const pdf = path.join(output, `${texFileStem(mainFile)}.pdf`);
35
24
  return regularFileStat(pdf) ? { path: pdf, version: runId } : null;
36
25
  }
37
- export function syncArtifacts(config, projectId, mainFile, defaultMainFile) {
38
- const isDefault = mainFile === defaultMainFile;
39
- const published = publishedCompileArtifacts(config, projectId, mainFile, isDefault);
40
- if (published?.synctex)
41
- return { source: published.source, pdf: published.pdf, synctex: published.synctex };
42
- if (!isDefault)
43
- return null;
44
- const retained = {
45
- source: sourceRoot(config, projectId),
46
- pdf: retainedPdfPath(config, projectId),
47
- synctex: retainedSynctexPath(config, projectId)
48
- };
49
- if (fs.existsSync(retained.pdf) && fs.existsSync(retained.synctex))
50
- return retained;
51
- const basename = texFileStem(mainFile);
52
- const legacy = {
53
- source: sourceRoot(config, projectId),
54
- pdf: path.join(outputRoot(config, projectId), `${basename}.pdf`),
55
- synctex: path.join(outputRoot(config, projectId), `${basename}.synctex.gz`)
56
- };
57
- return fs.existsSync(legacy.pdf) && fs.existsSync(legacy.synctex) ? legacy : null;
26
+ export function syncArtifacts(config, projectId, mainFile) {
27
+ const published = publishedCompileArtifacts(config, projectId, mainFile);
28
+ return published?.synctex ? { source: published.source, pdf: published.pdf, synctex: published.synctex } : null;
58
29
  }
59
30
  export function compileMainFile(config, projectId, defaultMainFile, value) {
60
31
  let mainFile;
@@ -73,8 +44,10 @@ export function compileMainFile(config, projectId, defaultMainFile, value) {
73
44
  if (!isMainDocumentCandidateSync(config, projectId, mainFile))
74
45
  return null;
75
46
  }
76
- catch {
77
- return null;
47
+ catch (error) {
48
+ if (error.code === "ENOENT")
49
+ return null;
50
+ throw error;
78
51
  }
79
52
  return mainFile;
80
53
  }
@@ -101,12 +74,6 @@ export function listCompileArtifacts(directory) {
101
74
  export function isTextCompileArtifact(filePath) {
102
75
  return /(?:\.aux|\.bbl|\.bcf|\.blg|\.fls|\.log|\.lof|\.lot|\.nav|\.out|\.run\.xml|\.snm|\.toc|\.vrb|\.fdb_latexmk)$/i.test(filePath);
103
76
  }
104
- function retainedPdfPath(config, projectId) {
105
- return path.join(outputRoot(config, projectId), ".texlite", "latest.pdf");
106
- }
107
- function retainedSynctexPath(config, projectId) {
108
- return path.join(outputRoot(config, projectId), ".texlite", "latest.synctex.gz");
109
- }
110
77
  function regularFileStat(filePath) {
111
78
  try {
112
79
  const stat = fs.statSync(filePath);
@@ -91,9 +91,9 @@ export class ProjectCompileCoordinator {
91
91
  const targetKey = `${input.projectId}\0${input.target ?? ""}`;
92
92
  const state = this.targets.get(targetKey) ?? { active: null, pending: null };
93
93
  this.targets.set(targetKey, state);
94
- const generation = input.generation ?? input.revision;
94
+ const generation = input.generation;
95
95
  const active = state.active;
96
- if (active && (active.input.generation ?? active.input.revision) === generation) {
96
+ if (active && active.input.generation === generation) {
97
97
  const pending = state.pending;
98
98
  if (pending) {
99
99
  this.redirect(pending, active);
@@ -105,7 +105,7 @@ export class ProjectCompileCoordinator {
105
105
  return active.promise;
106
106
  }
107
107
  const pending = state.pending;
108
- if (pending && (pending.input.generation ?? pending.input.revision) === generation) {
108
+ if (pending && pending.input.generation === generation) {
109
109
  input.onDiscarded("duplicate");
110
110
  return pending.promise;
111
111
  }
@@ -191,7 +191,8 @@ function deferredJob(input) {
191
191
  function cancelledCompileResult(input) {
192
192
  return {
193
193
  runId: input.runId,
194
- revision: input.revision,
194
+ // A queued cancellation has no content snapshot yet.
195
+ revision: input.generation,
195
196
  ok: false,
196
197
  cancelled: true,
197
198
  log: new CompileCancelledError().message,
@@ -293,8 +294,8 @@ export function cleanCompileCache(config, projectId, mainFile) {
293
294
  * Remove generated output for one root document without touching project
294
295
  * source, settings, comments, history, or Git data.
295
296
  */
296
- export function cleanCompileArtifacts(config, projectId, mainFile, defaultMainFile, runIds = []) {
297
- const published = publishedCompileArtifacts(config, projectId, mainFile, mainFile === defaultMainFile);
297
+ export function cleanCompileArtifacts(config, projectId, mainFile, runIds = []) {
298
+ const published = publishedCompileArtifacts(config, projectId, mainFile);
298
299
  cleanCompileCache(config, projectId, mainFile);
299
300
  fs.rmSync(compileTargetRoot(config, projectId, mainFile), { recursive: true, force: true });
300
301
  const runIdsToRemove = new Set(runIds);
@@ -304,17 +305,6 @@ export function cleanCompileArtifacts(config, projectId, mainFile, defaultMainFi
304
305
  if (/^[a-f0-9-]{36}$/i.test(runId))
305
306
  fs.rmSync(compileRunRoot(config, projectId, runId), { recursive: true, force: true });
306
307
  }
307
- if (mainFile === defaultMainFile) {
308
- const output = outputRoot(config, projectId);
309
- for (const generated of [
310
- path.join(output, ".texlite", "latest.json"),
311
- path.join(output, ".texlite", "latest.pdf"),
312
- path.join(output, ".texlite", "latest.synctex.gz"),
313
- path.join(output, `${texFileStem(mainFile)}.pdf`),
314
- path.join(output, `${texFileStem(mainFile)}.synctex.gz`)
315
- ])
316
- fs.rmSync(generated, { force: true });
317
- }
318
308
  }
319
309
  export function publishCompileArtifacts(config, projectId, snapshot, result) {
320
310
  if (!result.ok || !result.pdfPath)
@@ -345,19 +335,9 @@ export function publishCompileArtifacts(config, projectId, snapshot, result) {
345
335
  }
346
336
  return publishedCompileArtifacts(config, projectId, snapshot.mainFile);
347
337
  }
348
- export function publishedCompileArtifacts(config, projectId, mainFile, allowLegacy = false) {
349
- if (mainFile !== undefined) {
350
- const normalized = safeRelativePath(mainFile);
351
- const targeted = readPublishedManifest(config, projectId, path.join(compileTargetRoot(config, projectId, normalized), "latest.json"), normalized);
352
- if (targeted)
353
- return targeted;
354
- return allowLegacy ? readPublishedManifest(config, projectId, path.join(compileDataRoot(config, projectId), "latest.json"), normalized, true) : null;
355
- }
356
- const legacy = readPublishedManifest(config, projectId, path.join(compileDataRoot(config, projectId), "latest.json"), "", true);
357
- if (legacy)
358
- return legacy;
359
- return listPublishedCompileArtifacts(config, projectId)
360
- .sort((left, right) => fs.statSync(right.pdf).mtimeMs - fs.statSync(left.pdf).mtimeMs)[0] ?? null;
338
+ export function publishedCompileArtifacts(config, projectId, mainFile) {
339
+ const normalized = safeRelativePath(mainFile);
340
+ return readPublishedManifest(config, projectId, path.join(compileTargetRoot(config, projectId, normalized), "latest.json"), normalized);
361
341
  }
362
342
  export function listPublishedCompileArtifacts(config, projectId) {
363
343
  const result = [];
@@ -371,9 +351,6 @@ export function listPublishedCompileArtifacts(config, projectId) {
371
351
  result.push(artifact);
372
352
  }
373
353
  }
374
- const legacy = readPublishedManifest(config, projectId, path.join(compileDataRoot(config, projectId), "latest.json"), "", true);
375
- if (legacy && !result.some((artifact) => artifact.runId === legacy.runId))
376
- result.push(legacy);
377
354
  return result;
378
355
  }
379
356
  /**
@@ -404,17 +381,18 @@ export function reconcilePublishedCompileRuns(config, db, projectId) {
404
381
  recover.run(message, finishedAt, artifact.runId, projectId);
405
382
  }
406
383
  }
407
- function readPublishedManifest(config, projectId, manifestPath, expectedMainFile, legacy = false) {
384
+ function readPublishedManifest(config, projectId, manifestPath, expectedMainFile) {
408
385
  if (!fs.existsSync(manifestPath))
409
386
  return null;
410
387
  try {
411
388
  const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
412
- const mainFile = manifest.version === 2 && typeof manifest.mainFile === "string"
413
- ? safeRelativePath(manifest.mainFile)
414
- : legacy && manifest.version === 1 ? expectedMainFile ?? "" : null;
389
+ // Per-root v2 manifests have been the published format since 0.2.0.
390
+ if (manifest.version !== 2 || typeof manifest.mainFile !== "string")
391
+ return null;
392
+ const mainFile = safeRelativePath(manifest.mainFile);
415
393
  const generation = manifest.generation === undefined || manifest.generation === null
416
394
  ? null : typeof manifest.generation === "string" ? manifest.generation : null;
417
- if (mainFile === null || (expectedMainFile !== undefined && mainFile !== expectedMainFile)
395
+ if ((expectedMainFile !== undefined && mainFile !== expectedMainFile)
418
396
  || typeof manifest.runId !== "string" || !/^[a-f0-9-]{36}$/i.test(manifest.runId)
419
397
  || typeof manifest.revision !== "string" || typeof manifest.pdf !== "string"
420
398
  || (manifest.generation !== undefined && manifest.generation !== null && generation === null)
@@ -24,10 +24,11 @@ export const CONFIG_DEFAULTS = {
24
24
  allowProjectLatexmkrc: true,
25
25
  maxFileSizeMB: 50,
26
26
  pdfLoadingStrategy: "auto",
27
- pdfRangeThresholdMB: 5,
27
+ pdfRangeThresholdMB: 2,
28
28
  historyMaxVersions: 0,
29
29
  historyMaxStorageMB: 128,
30
- editHistoryMaxStorageMB: 32,
30
+ editHistoryMaxStorageMB: 64,
31
+ editHistoryMaxSegments: 20_000,
31
32
  git: "git",
32
33
  gitOperationTimeoutSeconds: 120,
33
34
  githubApiBaseUrl: "https://api.github.com"
@@ -42,6 +43,7 @@ const CONFIG_LIMITS = {
42
43
  historyMaxVersions: [0, 50_000],
43
44
  historyMaxStorageMB: [16, 102_400],
44
45
  editHistoryMaxStorageMB: [4, 102_400],
46
+ editHistoryMaxSegments: [1, 100_000],
45
47
  gitOperationTimeoutSeconds: [1, 3_600]
46
48
  };
47
49
  export function loadConfig(configPathOverride) {
@@ -76,6 +78,7 @@ export function loadConfig(configPathOverride) {
76
78
  const historyMaxVersions = integerSetting("history.maxVersions", process.env.TEXLITE_HISTORY_MAX_VERSIONS, fileConfig.history?.maxVersions, CONFIG_DEFAULTS.historyMaxVersions, CONFIG_LIMITS.historyMaxVersions);
77
79
  const historyMaxStorageMB = integerSetting("history.maxStorageMB", process.env.TEXLITE_HISTORY_MAX_STORAGE_MB, fileConfig.history?.maxStorageMB, CONFIG_DEFAULTS.historyMaxStorageMB, CONFIG_LIMITS.historyMaxStorageMB);
78
80
  const editHistoryMaxStorageMB = integerSetting("editHistory.maxStorageMB", process.env.TEXLITE_EDIT_HISTORY_MAX_STORAGE_MB, fileConfig.editHistory?.maxStorageMB, CONFIG_DEFAULTS.editHistoryMaxStorageMB, CONFIG_LIMITS.editHistoryMaxStorageMB);
81
+ const editHistoryMaxSegments = integerSetting("editHistory.maxSegments", process.env.TEXLITE_EDIT_HISTORY_MAX_SEGMENTS, fileConfig.editHistory?.maxSegments, CONFIG_DEFAULTS.editHistoryMaxSegments, CONFIG_LIMITS.editHistoryMaxSegments);
79
82
  const gitOperationTimeoutSeconds = integerSetting("git.operationTimeoutSeconds", process.env.TEXLITE_GIT_TIMEOUT, fileConfig.git?.operationTimeoutSeconds, CONFIG_DEFAULTS.gitOperationTimeoutSeconds, CONFIG_LIMITS.gitOperationTimeoutSeconds);
80
83
  const basePath = resolveBasePath(fileConfig);
81
84
  const config = {
@@ -104,6 +107,7 @@ export function loadConfig(configPathOverride) {
104
107
  historyMaxVersions,
105
108
  historyMaxStorageBytes: historyMaxStorageMB * 1024 * 1024,
106
109
  editHistoryMaxStorageBytes: editHistoryMaxStorageMB * 1024 * 1024,
110
+ editHistoryMaxSegments,
107
111
  git: stringSetting("git.binary", process.env.TEXLITE_GIT, fileConfig.git?.binary, CONFIG_DEFAULTS.git, { min: 1, max: 256 }),
108
112
  gitOperationTimeoutMs: gitOperationTimeoutSeconds * 1000,
109
113
  githubApiBaseUrl: stringSetting("git.githubApiBaseUrl", process.env.TEXLITE_GITHUB_API_URL, fileConfig.git?.githubApiBaseUrl, CONFIG_DEFAULTS.githubApiBaseUrl, { min: 1, max: 2_048 }).replace(/\/+$/, "")
@@ -159,6 +163,7 @@ export function validateConfig(config) {
159
163
  validateInteger("history.maxVersions", config.historyMaxVersions, CONFIG_LIMITS.historyMaxVersions);
160
164
  validateInteger("history.maxStorageMB", config.historyMaxStorageBytes / (1024 * 1024), CONFIG_LIMITS.historyMaxStorageMB);
161
165
  validateInteger("editHistory.maxStorageMB", config.editHistoryMaxStorageBytes / (1024 * 1024), CONFIG_LIMITS.editHistoryMaxStorageMB);
166
+ validateInteger("editHistory.maxSegments", config.editHistoryMaxSegments, CONFIG_LIMITS.editHistoryMaxSegments);
162
167
  validateInteger("git.operationTimeoutSeconds", config.gitOperationTimeoutMs / 1000, CONFIG_LIMITS.gitOperationTimeoutSeconds);
163
168
  }
164
169
  function resolveBasePath(fileConfig) {
@@ -218,6 +223,7 @@ function validateFileConfig(config) {
218
223
  optionalInteger(history?.maxStorageMB, "history.maxStorageMB", CONFIG_LIMITS.historyMaxStorageMB);
219
224
  const editHistory = optionalSection(config.editHistory, "editHistory");
220
225
  optionalInteger(editHistory?.maxStorageMB, "editHistory.maxStorageMB", CONFIG_LIMITS.editHistoryMaxStorageMB);
226
+ optionalInteger(editHistory?.maxSegments, "editHistory.maxSegments", CONFIG_LIMITS.editHistoryMaxSegments);
221
227
  const latex = optionalSection(config.latex, "latex");
222
228
  optionalString(latex?.latexmk, "latex.latexmk", { min: 1, max: 256 });
223
229
  if (latex && Object.prototype.hasOwnProperty.call(latex, "defaultEngine") && !isEngine(latex.defaultEngine)) {
package/dist/server/db.js CHANGED
@@ -60,6 +60,39 @@ const databaseMigrations = [
60
60
  included INTEGER NOT NULL CHECK (included IN (0, 1)),
61
61
  PRIMARY KEY (project_id, path)
62
62
  )`);
63
+ } },
64
+ { version: 10, name: "add_external_agent_tasks", apply: (db) => {
65
+ db.exec(`
66
+ CREATE TABLE IF NOT EXISTS agent_policy (
67
+ id INTEGER PRIMARY KEY CHECK (id = 1),
68
+ allowed TEXT NOT NULL DEFAULT '[]'
69
+ );
70
+ INSERT OR IGNORE INTO agent_policy (id) VALUES (1);
71
+ -- Keep ownership labels and cleanup locators after a project/user is deleted.
72
+ -- External processes and native conversations cannot be removed by FK cascades.
73
+ CREATE TABLE IF NOT EXISTS agent_tasks (
74
+ id TEXT PRIMARY KEY, project_id TEXT NOT NULL, user_id TEXT NOT NULL,
75
+ project_name TEXT NOT NULL, user_name TEXT NOT NULL, agent_id TEXT NOT NULL,
76
+ title TEXT NOT NULL,
77
+ state TEXT NOT NULL DEFAULT 'ready', cleanup_state TEXT NOT NULL DEFAULT 'none',
78
+ error_code TEXT, native_session_id TEXT, ever_started INTEGER NOT NULL DEFAULT 0,
79
+ created_at TEXT NOT NULL, updated_at TEXT NOT NULL, started_at TEXT, ended_at TEXT,
80
+ exit_code INTEGER
81
+ );
82
+ CREATE INDEX IF NOT EXISTS agent_tasks_project_user ON agent_tasks(project_id, user_id, updated_at);
83
+ CREATE INDEX IF NOT EXISTS agent_tasks_user ON agent_tasks(user_id, updated_at);
84
+ CREATE INDEX IF NOT EXISTS agent_tasks_state ON agent_tasks(state, updated_at);
85
+ CREATE TABLE IF NOT EXISTS agent_cleanup_events (
86
+ id INTEGER PRIMARY KEY, task_id TEXT NOT NULL, actor_id TEXT,
87
+ project_id TEXT NOT NULL, agent_id TEXT NOT NULL,
88
+ action TEXT NOT NULL, result TEXT NOT NULL, created_at TEXT NOT NULL
89
+ );
90
+ `);
91
+ } },
92
+ { version: 11, name: "track_agent_native_cleanup_completion", apply: (db) => {
93
+ if (missingColumn(db, "agent_tasks", "native_cleanup_done")) {
94
+ db.exec("ALTER TABLE agent_tasks ADD COLUMN native_cleanup_done INTEGER NOT NULL DEFAULT 0 CHECK (native_cleanup_done IN (0, 1))");
95
+ }
63
96
  } }
64
97
  ];
65
98
  function migrateGitHubTokensToUsers(db) {