texlite 0.18.0 → 0.19.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.
Files changed (222) hide show
  1. package/DESIGN.md +357 -21
  2. package/NPM_TESTING.md +23 -0
  3. package/OPERATIONS.md +185 -6
  4. package/README.md +4 -2
  5. package/README.zh-CN.md +3 -2
  6. package/THIRD_PARTY_NOTICES.md +73 -0
  7. package/dist/client/assets/AdminUsers-DXWi8wl0.js +1 -0
  8. package/dist/client/assets/AdminUsers-DXWi8wl0.js.br +0 -0
  9. package/dist/client/assets/AdminUsers-DXWi8wl0.js.gz +0 -0
  10. package/dist/client/assets/AgentIcon-BlHvdrRo.js +1 -0
  11. package/dist/client/assets/AgentIcon-BlHvdrRo.js.br +0 -0
  12. package/dist/client/assets/AgentIcon-BlHvdrRo.js.gz +0 -0
  13. package/dist/client/assets/AgentIcon-DE7FEpRY.css +1 -0
  14. package/dist/client/assets/AgentIcon-DE7FEpRY.css.br +0 -0
  15. package/dist/client/assets/AgentIcon-DE7FEpRY.css.gz +0 -0
  16. package/dist/client/assets/AgentManagement-CDWaxEmP.js +1 -0
  17. package/dist/client/assets/AgentManagement-CDWaxEmP.js.br +0 -0
  18. package/dist/client/assets/AgentManagement-CDWaxEmP.js.gz +0 -0
  19. package/dist/client/assets/AgentTerminal-BXH3gHWm.js +2 -0
  20. package/dist/client/assets/AgentTerminal-BXH3gHWm.js.br +0 -0
  21. package/dist/client/assets/AgentTerminal-BXH3gHWm.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-D0MLcJmw.js +16 -0
  26. package/dist/client/assets/AgentTerminalSurface-D0MLcJmw.js.br +0 -0
  27. package/dist/client/assets/AgentTerminalSurface-D0MLcJmw.js.gz +0 -0
  28. package/dist/client/assets/{AvatarSettingsDialog-CIPKapVe.js → AvatarSettingsDialog-CtbzavqH.js} +1 -1
  29. package/dist/client/assets/AvatarSettingsDialog-CtbzavqH.js.br +0 -0
  30. package/dist/client/assets/AvatarSettingsDialog-CtbzavqH.js.gz +0 -0
  31. package/dist/client/assets/{CitationLibraryDialog-BhZX8BV2.js → CitationLibraryDialog-CnQVjovw.js} +1 -1
  32. package/dist/client/assets/CitationLibraryDialog-CnQVjovw.js.br +0 -0
  33. package/dist/client/assets/CitationLibraryDialog-CnQVjovw.js.gz +0 -0
  34. package/dist/client/assets/Dashboard-Dzq1oMZU.js +5 -0
  35. package/dist/client/assets/Dashboard-Dzq1oMZU.js.br +0 -0
  36. package/dist/client/assets/Dashboard-Dzq1oMZU.js.gz +0 -0
  37. package/dist/client/assets/GitDialog-CzgguGGW.js +3 -0
  38. package/dist/client/assets/GitDialog-CzgguGGW.js.br +0 -0
  39. package/dist/client/assets/GitDialog-CzgguGGW.js.gz +0 -0
  40. package/dist/client/assets/{GitHubAccountDialog-hosK9cLW.js → GitHubAccountDialog-lRAWfkKP.js} +1 -1
  41. package/dist/client/assets/GitHubAccountDialog-lRAWfkKP.js.br +0 -0
  42. package/dist/client/assets/GitHubAccountDialog-lRAWfkKP.js.gz +0 -0
  43. package/dist/client/assets/{GitHubIcon-DNR0CleM.js → GitHubIcon-BPTVKTrM.js} +1 -1
  44. package/dist/client/assets/HistoryDialog-Bw3GHfbM.js +8 -0
  45. package/dist/client/assets/HistoryDialog-Bw3GHfbM.js.br +0 -0
  46. package/dist/client/assets/HistoryDialog-Bw3GHfbM.js.gz +0 -0
  47. package/dist/client/assets/{LatexEditor-BzAk3WQM.js → LatexEditor-BDpqgoOa.js} +2 -2
  48. package/dist/client/assets/LatexEditor-BDpqgoOa.js.br +0 -0
  49. package/dist/client/assets/LatexEditor-BDpqgoOa.js.gz +0 -0
  50. package/dist/client/assets/PdfPreview-C2puKgCh.js +1 -0
  51. package/dist/client/assets/PdfPreview-C2puKgCh.js.br +0 -0
  52. package/dist/client/assets/PdfPreview-C2puKgCh.js.gz +0 -0
  53. package/dist/client/assets/{ProjectIconPickerDialog-D8Uo4H10.js → ProjectIconPickerDialog-BzNdyAz6.js} +1 -1
  54. package/dist/client/assets/ProjectIconPickerDialog-BzNdyAz6.js.br +0 -0
  55. package/dist/client/assets/ProjectIconPickerDialog-BzNdyAz6.js.gz +0 -0
  56. package/dist/client/assets/ProjectSettings-B_y5nRgp.js +4 -0
  57. package/dist/client/assets/ProjectSettings-B_y5nRgp.js.br +0 -0
  58. package/dist/client/assets/ProjectSettings-B_y5nRgp.js.gz +0 -0
  59. package/dist/client/assets/ProjectWorkspace-BnT5JPTA.js +30 -0
  60. package/dist/client/assets/ProjectWorkspace-BnT5JPTA.js.br +0 -0
  61. package/dist/client/assets/ProjectWorkspace-BnT5JPTA.js.gz +0 -0
  62. package/dist/client/assets/{QuickOpenDialog-CyqeckBM.js → QuickOpenDialog-CEYxIk4l.js} +1 -1
  63. package/dist/client/assets/QuickOpenDialog-CEYxIk4l.js.br +0 -0
  64. package/dist/client/assets/QuickOpenDialog-CEYxIk4l.js.gz +0 -0
  65. package/dist/client/assets/SelectionHistoryDialog-DBL6vVD4.js +3 -0
  66. package/dist/client/assets/SelectionHistoryDialog-DBL6vVD4.js.br +0 -0
  67. package/dist/client/assets/SelectionHistoryDialog-DBL6vVD4.js.gz +0 -0
  68. package/dist/client/assets/SuccessNotice-C8XV7MAJ.js +1 -0
  69. package/dist/client/assets/SystemMetricsDialog-D2EQX5hh.js +1 -0
  70. package/dist/client/assets/SystemMetricsDialog-D2EQX5hh.js.br +0 -0
  71. package/dist/client/assets/SystemMetricsDialog-D2EQX5hh.js.gz +0 -0
  72. package/dist/client/assets/{TagColorSelect-D3T-rw4K.js → TagColorSelect-CfJaFovr.js} +1 -1
  73. package/dist/client/assets/TagManagementDialog-CiJ6AhVk.js +1 -0
  74. package/dist/client/assets/TagManagementDialog-CiJ6AhVk.js.br +0 -0
  75. package/dist/client/assets/TagManagementDialog-CiJ6AhVk.js.gz +0 -0
  76. package/dist/client/assets/{WordCountDialog-Bp8kYngA.js → WordCountDialog-DaHxqArj.js} +1 -1
  77. package/dist/client/assets/WordCountDialog-DaHxqArj.js.br +0 -0
  78. package/dist/client/assets/WordCountDialog-DaHxqArj.js.gz +0 -0
  79. package/dist/client/assets/arrow-down-BySB1dS6.js +1 -0
  80. package/dist/client/assets/check-B-GEn6vk.js +1 -0
  81. package/dist/client/assets/chevron-up-B0yLKMZJ.js +1 -0
  82. package/dist/client/assets/{chktex-BcGmZVUy.js → chktex-B2-niLAo.js} +1 -1
  83. package/dist/client/assets/circle-check-CfK-oqlC.js +1 -0
  84. package/dist/client/assets/{clock-3-x2vcGFSH.js → clock-3-C_8q2yLj.js} +1 -1
  85. package/dist/client/assets/{dist-D5mbpudl.js → dist-CIxSPQK5.js} +1 -1
  86. package/dist/client/assets/dist-CIxSPQK5.js.br +0 -0
  87. package/dist/client/assets/dist-CIxSPQK5.js.gz +0 -0
  88. package/dist/client/assets/{eye-CvzXPIMu.js → eye-DpIOhQ2p.js} +1 -1
  89. package/dist/client/assets/{hard-drive-BeGQ5o79.js → hard-drive-DRbINIYf.js} +1 -1
  90. package/dist/client/assets/i18n-BzlyqR_B.js +13 -0
  91. package/dist/client/assets/i18n-BzlyqR_B.js.br +0 -0
  92. package/dist/client/assets/i18n-BzlyqR_B.js.gz +0 -0
  93. package/dist/client/assets/index-BHHBwQuG.css +1 -0
  94. package/dist/client/assets/index-BHHBwQuG.css.br +0 -0
  95. package/dist/client/assets/index-BHHBwQuG.css.gz +0 -0
  96. package/dist/client/assets/index-h0BVkT8k.js +42 -0
  97. package/dist/client/assets/index-h0BVkT8k.js.br +0 -0
  98. package/dist/client/assets/index-h0BVkT8k.js.gz +0 -0
  99. package/dist/client/assets/info-DB-RajXx.js +1 -0
  100. package/dist/client/assets/{minimize-2-yYMmsVER.js → minimize-2-DtsKyo4M.js} +1 -1
  101. package/dist/client/assets/{minus-CNHOVLWS.js → minus-CdwrG9Yo.js} +1 -1
  102. package/dist/client/assets/plus-PHvPlka_.js +1 -0
  103. package/dist/client/assets/{refresh-cw-B7vZa5K2.js → refresh-cw-c6Tzy-hb.js} +1 -1
  104. package/dist/client/assets/relativeTime-Cf5dzFc9.js +1 -0
  105. package/dist/client/assets/relativeTime-Cf5dzFc9.js.br +0 -0
  106. package/dist/client/assets/relativeTime-Cf5dzFc9.js.gz +0 -0
  107. package/dist/client/assets/{search-Czv3qsBy.js → search-Cy8DgYGb.js} +1 -1
  108. package/dist/client/assets/{spellCheck-DDCaK8Yx.js → spellCheck-DEQIFH7w.js} +1 -1
  109. package/dist/client/assets/spellCheck-DEQIFH7w.js.br +0 -0
  110. package/dist/client/assets/spellCheck-DEQIFH7w.js.gz +0 -0
  111. package/dist/client/assets/{tags-CLK7WRSs.js → tags-BQ0exG-g.js} +1 -1
  112. package/dist/client/assets/terminal-DaAc1558.js +1 -0
  113. package/dist/client/assets/terminalPreferences-CgacIg2F.js +1 -0
  114. package/dist/client/assets/terminalPreferences-CgacIg2F.js.br +0 -0
  115. package/dist/client/assets/terminalPreferences-CgacIg2F.js.gz +0 -0
  116. package/dist/client/assets/{type-NT195OCy.js → type-Cm3TiSO6.js} +1 -1
  117. package/dist/client/assets/{user-plus-BRuwNzcg.js → user-plus-BLC3_SFQ.js} +1 -1
  118. package/dist/client/index.html +13 -7
  119. package/dist/server/agents/adapters/claude.js +19 -0
  120. package/dist/server/agents/adapters/codex.js +47 -0
  121. package/dist/server/agents/adapters/common.js +86 -0
  122. package/dist/server/agents/adapters/opencode.js +184 -0
  123. package/dist/server/agents/adapters/types.js +1 -0
  124. package/dist/server/agents/execution.js +147 -0
  125. package/dist/server/agents/launcher.js +57 -0
  126. package/dist/server/agents/processIdentity.js +63 -0
  127. package/dist/server/agents/registry.js +72 -0
  128. package/dist/server/agents/sessions.js +564 -0
  129. package/dist/server/agents/terminal.js +84 -0
  130. package/dist/server/agents/workspaces.js +341 -0
  131. package/dist/server/app.js +32 -1
  132. package/dist/server/cli.js +19 -47
  133. package/dist/server/collaboration.js +62 -35
  134. package/dist/server/compileArtifacts.js +11 -44
  135. package/dist/server/compiler.js +16 -38
  136. package/dist/server/config.js +8 -2
  137. package/dist/server/db.js +28 -0
  138. package/dist/server/editHistory.js +59 -65
  139. package/dist/server/history.js +28 -13
  140. package/dist/server/i18n.js +26 -8
  141. package/dist/server/latexRoot.js +4 -2
  142. package/dist/server/locales/zh-Hant.js +145 -0
  143. package/dist/server/lucideIcons.js +14 -17
  144. package/dist/server/projectMutations.js +21 -0
  145. package/dist/server/routes/agents.js +135 -0
  146. package/dist/server/routes/compile.js +23 -43
  147. package/dist/server/routes/projectHistory.js +13 -6
  148. package/dist/server/routes/projects.js +15 -23
  149. package/dist/shared/agentMessages.js +51 -0
  150. package/dist/shared/agentProtocol.js +41 -0
  151. package/dist/shared/historyFiles.js +1 -1
  152. package/dist/shared/historyTracking.js +2 -0
  153. package/dist/shared/locales.js +21 -0
  154. package/package.json +7 -3
  155. package/templates/agents/AGENTS.md +135 -0
  156. package/texlite.config.example.json +3 -2
  157. package/dist/client/assets/AdminUsers-rPpYTAU6.js +0 -1
  158. package/dist/client/assets/AdminUsers-rPpYTAU6.js.br +0 -0
  159. package/dist/client/assets/AdminUsers-rPpYTAU6.js.gz +0 -0
  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.br +0 -0
  163. package/dist/client/assets/CitationLibraryDialog-BhZX8BV2.js.gz +0 -0
  164. package/dist/client/assets/Dashboard-DppEhsjL.js +0 -5
  165. package/dist/client/assets/Dashboard-DppEhsjL.js.br +0 -0
  166. package/dist/client/assets/Dashboard-DppEhsjL.js.gz +0 -0
  167. package/dist/client/assets/GitDialog-BOu46hxA.js +0 -3
  168. package/dist/client/assets/GitDialog-BOu46hxA.js.br +0 -0
  169. package/dist/client/assets/GitDialog-BOu46hxA.js.gz +0 -0
  170. package/dist/client/assets/GitHubAccountDialog-hosK9cLW.js.br +0 -0
  171. package/dist/client/assets/GitHubAccountDialog-hosK9cLW.js.gz +0 -0
  172. package/dist/client/assets/HistoryDialog-BdkuEl8r.js +0 -8
  173. package/dist/client/assets/HistoryDialog-BdkuEl8r.js.br +0 -0
  174. package/dist/client/assets/HistoryDialog-BdkuEl8r.js.gz +0 -0
  175. package/dist/client/assets/LatexEditor-BzAk3WQM.js.br +0 -0
  176. package/dist/client/assets/LatexEditor-BzAk3WQM.js.gz +0 -0
  177. package/dist/client/assets/PdfPreview-DkjI1eCo.js +0 -1
  178. package/dist/client/assets/PdfPreview-DkjI1eCo.js.br +0 -0
  179. package/dist/client/assets/PdfPreview-DkjI1eCo.js.gz +0 -0
  180. package/dist/client/assets/ProjectIconPickerDialog-D8Uo4H10.js.br +0 -0
  181. package/dist/client/assets/ProjectIconPickerDialog-D8Uo4H10.js.gz +0 -0
  182. package/dist/client/assets/ProjectSettings-Jdr94nOc.js +0 -1
  183. package/dist/client/assets/ProjectSettings-Jdr94nOc.js.br +0 -0
  184. package/dist/client/assets/ProjectSettings-Jdr94nOc.js.gz +0 -0
  185. package/dist/client/assets/ProjectWorkspace-D9v3Jj8T.js +0 -30
  186. package/dist/client/assets/ProjectWorkspace-D9v3Jj8T.js.br +0 -0
  187. package/dist/client/assets/ProjectWorkspace-D9v3Jj8T.js.gz +0 -0
  188. package/dist/client/assets/QuickOpenDialog-CyqeckBM.js.br +0 -0
  189. package/dist/client/assets/QuickOpenDialog-CyqeckBM.js.gz +0 -0
  190. package/dist/client/assets/SelectionHistoryDialog-Dlutex-A.js +0 -3
  191. package/dist/client/assets/SelectionHistoryDialog-Dlutex-A.js.br +0 -0
  192. package/dist/client/assets/SelectionHistoryDialog-Dlutex-A.js.gz +0 -0
  193. package/dist/client/assets/SystemMetricsDialog-CCWxXw6g.js +0 -1
  194. package/dist/client/assets/SystemMetricsDialog-CCWxXw6g.js.br +0 -0
  195. package/dist/client/assets/SystemMetricsDialog-CCWxXw6g.js.gz +0 -0
  196. package/dist/client/assets/TagManagementDialog-CxjrSX-o.js +0 -1
  197. package/dist/client/assets/TagManagementDialog-CxjrSX-o.js.br +0 -0
  198. package/dist/client/assets/TagManagementDialog-CxjrSX-o.js.gz +0 -0
  199. package/dist/client/assets/WordCountDialog-Bp8kYngA.js.br +0 -0
  200. package/dist/client/assets/WordCountDialog-Bp8kYngA.js.gz +0 -0
  201. package/dist/client/assets/check-DFoA73zZ.js +0 -1
  202. package/dist/client/assets/chevron-up-C8DyKLxi.js +0 -1
  203. package/dist/client/assets/dist-D5mbpudl.js.br +0 -0
  204. package/dist/client/assets/dist-D5mbpudl.js.gz +0 -0
  205. package/dist/client/assets/i18n-CRWKZA6W.js +0 -9
  206. package/dist/client/assets/i18n-CRWKZA6W.js.br +0 -0
  207. package/dist/client/assets/i18n-CRWKZA6W.js.gz +0 -0
  208. package/dist/client/assets/index-D0eqhDpZ.js +0 -42
  209. package/dist/client/assets/index-D0eqhDpZ.js.br +0 -0
  210. package/dist/client/assets/index-D0eqhDpZ.js.gz +0 -0
  211. package/dist/client/assets/index-DnhiIb1V.css +0 -1
  212. package/dist/client/assets/index-DnhiIb1V.css.br +0 -0
  213. package/dist/client/assets/index-DnhiIb1V.css.gz +0 -0
  214. package/dist/client/assets/plus-BDquy76g.js +0 -1
  215. package/dist/client/assets/relativeTime-DuOytR_J.js +0 -1
  216. package/dist/client/assets/relativeTime-DuOytR_J.js.br +0 -0
  217. package/dist/client/assets/relativeTime-DuOytR_J.js.gz +0 -0
  218. package/dist/client/assets/sigma-CI6gmAkl.js +0 -1
  219. package/dist/client/assets/spellCheck-DDCaK8Yx.js.br +0 -0
  220. package/dist/client/assets/spellCheck-DDCaK8Yx.js.gz +0 -0
  221. package/preview-1.png +0 -0
  222. package/preview-2.png +0 -0
@@ -0,0 +1,135 @@
1
+ import { currentUser, requireAdmin, requireUser } from "../auth.js";
2
+ import { apiError, httpError } from "../http.js";
3
+ import { isAgentId } from "../../shared/agentProtocol.js";
4
+ import { digestToken } from "../security.js";
5
+ function title(value, optional = false) {
6
+ if (optional && value === undefined)
7
+ return "";
8
+ if (typeof value !== "string" || (!optional && !value.trim()) || value.length > 160)
9
+ throw httpError(400, "REQUEST_INVALID");
10
+ return value.trim();
11
+ }
12
+ function terminalOriginAllowed(request) {
13
+ const origin = request.headers.origin;
14
+ if (!origin)
15
+ return false;
16
+ try {
17
+ const parsed = new URL(origin);
18
+ const forwarded = request.headers["x-forwarded-proto"];
19
+ const protocol = forwarded === "https" || forwarded === "http" ? forwarded : request.protocol;
20
+ return parsed.host === request.headers.host && parsed.protocol === `${protocol}:` && parsed.origin === origin;
21
+ }
22
+ catch {
23
+ return false;
24
+ }
25
+ }
26
+ /** Task owners get terminal access; administrators get separate metadata/cleanup routes. */
27
+ export function registerAgentRoutes(app, { db, agents }) {
28
+ app.get("/api/agents/access", async (request, reply) => {
29
+ const user = requireUser(request, reply, db);
30
+ if (!user)
31
+ return;
32
+ const { project } = request.query;
33
+ return agents.access(user.id, typeof project === "string" ? project : undefined);
34
+ });
35
+ app.get("/api/agents", async (request, reply) => {
36
+ if (!requireUser(request, reply, db))
37
+ return;
38
+ return agents.catalog();
39
+ });
40
+ app.get("/api/admin/agents", async (request, reply) => {
41
+ if (!requireAdmin(request, reply, db))
42
+ return;
43
+ return agents.catalog();
44
+ });
45
+ app.post("/api/admin/agents/refresh", async (request, reply) => {
46
+ if (!requireAdmin(request, reply, db))
47
+ return;
48
+ return agents.catalog(true);
49
+ });
50
+ app.patch("/api/admin/agents", async (request, reply) => {
51
+ if (!requireAdmin(request, reply, db))
52
+ return;
53
+ const body = request.body;
54
+ if (!Array.isArray(body?.allowed) || !body.allowed.every(isAgentId))
55
+ return apiError(reply, 400, "REQUEST_INVALID");
56
+ await agents.setPolicy({ allowed: body.allowed });
57
+ return agents.catalog();
58
+ });
59
+ for (const administration of [false, true]) {
60
+ const prefix = administration ? "/api/admin/agent-tasks" : "/api/agent-tasks";
61
+ app.get(prefix, async (request, reply) => {
62
+ const user = administration ? requireAdmin(request, reply, db) : requireUser(request, reply, db);
63
+ if (!user)
64
+ return;
65
+ const raw = request.query;
66
+ const query = {};
67
+ for (const key of ["project", "user", "agent", "state", "page"])
68
+ if (typeof raw[key] === "string")
69
+ query[key] = raw[key];
70
+ return agents.list(user, administration, query);
71
+ });
72
+ app.post(`${prefix}/:taskId/stop`, async (request, reply) => {
73
+ const user = administration ? requireAdmin(request, reply, db) : requireUser(request, reply, db);
74
+ if (!user)
75
+ return;
76
+ return { task: await agents.stop(request.params.taskId, user, administration) };
77
+ });
78
+ app.delete(`${prefix}/:taskId`, async (request, reply) => {
79
+ const user = administration ? requireAdmin(request, reply, db) : requireUser(request, reply, db);
80
+ if (!user)
81
+ return;
82
+ await agents.remove(request.params.taskId, user, administration);
83
+ return { ok: true };
84
+ });
85
+ }
86
+ app.post("/api/projects/:id/agent-tasks", async (request, reply) => {
87
+ const user = requireUser(request, reply, db);
88
+ if (!user)
89
+ return;
90
+ const body = request.body;
91
+ if (!isAgentId(body?.agentId))
92
+ return apiError(reply, 400, "REQUEST_INVALID");
93
+ const task = await agents.create(request.params.id, user, body.agentId, title(body.title, true));
94
+ return reply.code(201).send({ task });
95
+ });
96
+ app.get("/api/agent-tasks/:taskId", async (request, reply) => {
97
+ const user = requireUser(request, reply, db);
98
+ if (!user)
99
+ return;
100
+ return { task: agents.task(request.params.taskId, user) };
101
+ });
102
+ app.patch("/api/agent-tasks/:taskId", async (request, reply) => {
103
+ const user = requireUser(request, reply, db);
104
+ if (!user)
105
+ return;
106
+ const body = request.body;
107
+ return { task: agents.update(request.params.taskId, user, { title: title(body?.title) }) };
108
+ });
109
+ app.post("/api/agent-tasks/:taskId/start", async (request, reply) => {
110
+ const user = requireUser(request, reply, db);
111
+ if (!user)
112
+ return;
113
+ return { task: await agents.start(request.params.taskId, user) };
114
+ });
115
+ app.get("/api/agent-tasks/:taskId/terminal", { websocket: true }, (socket, request) => {
116
+ const user = currentUser(request, db);
117
+ if (!user || !terminalOriginAllowed(request)) {
118
+ socket.close(1008, "Access denied");
119
+ return;
120
+ }
121
+ const token = digestToken(request.cookies.texlite_session);
122
+ // currentUser intentionally caches one HTTP request. A WebSocket outlives
123
+ // that request, so recheck its actual session row instead of that cache.
124
+ const session = db.prepare(`SELECT 1 FROM sessions s JOIN users u ON u.id = s.user_id
125
+ WHERE s.id = ? AND s.user_id = ? AND s.expires_at > ? AND u.disabled = 0 AND u.must_change_password = 0`);
126
+ try {
127
+ agents.attach(request.params.taskId, user, socket, () => Boolean(session.get(token, user.id, new Date().toISOString())));
128
+ }
129
+ catch (error) {
130
+ const code = error instanceof Error && "code" in error ? String(error.code) : "AGENT_SESSION_BUSY";
131
+ socket.send(JSON.stringify({ type: "error", code }));
132
+ socket.close(1008, "Terminal unavailable");
133
+ }
134
+ });
135
+ }
@@ -64,13 +64,9 @@ export function registerCompileRoutes(app, context) {
64
64
  ORDER BY CASE run.status WHEN 'running' THEN 0 WHEN 'queued' THEN 1 ELSE 2 END, run.created_at DESC LIMIT 1`).get(id, mainFile);
65
65
  const latestSuccess = db.prepare(`SELECT id, finished_at FROM compile_runs
66
66
  WHERE project_id = ? AND main_file = ? AND status = 'succeeded' ORDER BY created_at DESC LIMIT 1`).get(id, mainFile);
67
- const pdf = availablePdf(config, id, mainFile, project.main_file);
68
- const published = publishedCompileArtifacts(config, id, mainFile, mainFile === project.main_file);
69
- const publishedRun = published ? db.prepare(`SELECT id, finished_at FROM compile_runs
70
- WHERE id = ? AND project_id = ? AND status = 'succeeded'`).get(published.runId, id) : undefined;
71
- // A retained legacy PDF has no run bundle, so its file version (mtime) is
72
- // the only stable token that can be resolved back to those bytes.
73
- const pdfVersion = published?.runId ?? pdf?.version;
67
+ const pdf = availablePdf(config, id, mainFile);
68
+ const publishedRun = pdf ? db.prepare(`SELECT id, finished_at FROM compile_runs
69
+ WHERE id = ? AND project_id = ? AND status = 'succeeded'`).get(pdf.version, id) : undefined;
74
70
  const pdfMetadata = pdfResponseMetadata(config, pdf?.path ?? null);
75
71
  return {
76
72
  mainFile,
@@ -85,7 +81,7 @@ export function registerCompileRoutes(app, context) {
85
81
  } : null
86
82
  } : null,
87
83
  hasPdf: Boolean(pdf),
88
- pdfUrl: pdf ? compilePdfUrl(config, id, mainFile, pdfVersion ?? pdf.version) : null,
84
+ pdfUrl: pdf ? compilePdfUrl(config, id, mainFile, pdf.version) : null,
89
85
  pdfCompiledAt: publishedRun?.finished_at ?? latestSuccess?.finished_at ?? null,
90
86
  ...pdfMetadata
91
87
  };
@@ -102,7 +98,7 @@ export function registerCompileRoutes(app, context) {
102
98
  const mainFile = compileMainFile(config, id, project.main_file, query.mainFile);
103
99
  if (!mainFile)
104
100
  return apiError(reply, 400, "MAIN_DOCUMENT_INVALID");
105
- const published = publishedCompileArtifacts(config, id, mainFile, mainFile === project.main_file);
101
+ const published = publishedCompileArtifacts(config, id, mainFile);
106
102
  if (!query.path) {
107
103
  if (!published)
108
104
  return { mainFile, runId: null, artifacts: [] };
@@ -210,7 +206,7 @@ export function registerCompileRoutes(app, context) {
210
206
  return apiError(reply, 403, "COMPILE_FORBIDDEN");
211
207
  const runs = db.prepare(`SELECT id FROM compile_runs
212
208
  WHERE project_id = ? AND main_file = ? AND status NOT IN ('queued', 'running')`).all(id, mainFile);
213
- cleanCompileArtifacts(config, id, mainFile, currentProject.main_file, runs.map((run) => run.id));
209
+ cleanCompileArtifacts(config, id, mainFile, runs.map((run) => run.id));
214
210
  db.prepare("DELETE FROM compile_runs WHERE project_id = ? AND main_file = ? AND status NOT IN ('queued', 'running')").run(id, mainFile);
215
211
  pruneCompileRuns(id);
216
212
  collaboration.signalCompileState(id, {
@@ -253,7 +249,7 @@ export function registerCompileRoutes(app, context) {
253
249
  if (!fs.existsSync(resolveSourcePath(config, id, sourcePath))) {
254
250
  return apiError(reply, 404, "SOURCE_FILE_NOT_FOUND");
255
251
  }
256
- const artifacts = syncArtifacts(config, id, mainFile, project.main_file);
252
+ const artifacts = syncArtifacts(config, id, mainFile);
257
253
  if (!artifacts)
258
254
  return apiError(reply, 409, "SYNCTEX_NOT_AVAILABLE");
259
255
  return await sourceToPdf(artifacts.source, artifacts.pdf, sourcePath, line, column);
@@ -281,7 +277,7 @@ export function registerCompileRoutes(app, context) {
281
277
  return apiError(reply, 400, "SYNC_PDF_INVALID");
282
278
  }
283
279
  return await projectMutations.runConsistentRead(id, async () => {
284
- const artifacts = syncArtifacts(config, id, mainFile, project.main_file);
280
+ const artifacts = syncArtifacts(config, id, mainFile);
285
281
  if (!artifacts)
286
282
  return apiError(reply, 409, "SYNCTEX_NOT_AVAILABLE");
287
283
  const location = await pdfToSource(artifacts.source, artifacts.pdf, page, x, y);
@@ -393,7 +389,6 @@ export function registerCompileRoutes(app, context) {
393
389
  // This key is computed before snapshot creation. The content digest
394
390
  // returned by captureCompileSnapshot is only the result revision.
395
391
  generation: admission.generation,
396
- revision: admission.generation,
397
392
  onQueued: broadcast,
398
393
  onSelected: broadcast,
399
394
  onDiscarded: () => {
@@ -419,20 +414,8 @@ export function registerCompileRoutes(app, context) {
419
414
  // in-memory collaboration revision to skip before a snapshot: it is
420
415
  // not a durable content version and can collide after a room restart
421
416
  // or reconnect.
422
- await projectMutations.runSerialized(id, () => {
423
- throwIfCompileCancelled(signal);
424
- const currentProject = accessibleProject(db, id, user);
425
- if (!currentProject || !canEdit(currentProject)) {
426
- throw new Error("Project access changed while waiting for a source snapshot");
427
- }
428
- const currentMainFile = compileMainFile(config, id, currentProject.main_file, body.mainFile);
429
- if (!currentMainFile)
430
- throw new Error("Selected main document is no longer available");
431
- if (!requestedMainFile && currentMainFile !== mainFile)
432
- throw mainDocumentChangedError();
433
- project = currentProject;
434
- mainFile = currentMainFile;
435
- });
417
+ // Flush and revalidate inside the same reservation used for capture.
418
+ // Releasing a separate validation lock first only repeats this work.
436
419
  const captured = await projectMutations.runSerialized(id, async () => {
437
420
  throwIfCompileCancelled(signal);
438
421
  const currentProject = accessibleProject(db, id, user);
@@ -506,12 +489,12 @@ export function registerCompileRoutes(app, context) {
506
489
  discardCompileSnapshot(candidate);
507
490
  }
508
491
  throw new CompileSnapshotBusyError();
509
- }, { flush: false });
492
+ });
510
493
  snapshot = captured;
511
494
  throwIfCompileCancelled(signal);
512
495
  snapshotMs = performance.now() - snapshotStartedAt;
513
496
  metrics.record("compile.snapshot", snapshotMs);
514
- const published = publishedCompileArtifacts(config, id, mainFile, mainFile === project.main_file);
497
+ const published = publishedCompileArtifacts(config, id, mainFile);
515
498
  const publishedRun = published ? db.prepare(`SELECT id, status, log, finished_at
516
499
  FROM compile_runs WHERE id = ? AND project_id = ?`).get(published.runId, id) : undefined;
517
500
  // The current queued row is intentionally excluded. It is a request
@@ -662,7 +645,7 @@ export function registerCompileRoutes(app, context) {
662
645
  const timings = result.timings
663
646
  ? { snapshotMs: result.snapshotMs ?? 0, ...result.timings, requestMs }
664
647
  : { snapshotMs: result.snapshotMs ?? 0, requestMs };
665
- const responsePdf = result.ok ? availablePdf(config, id, mainFile, project.main_file) : null;
648
+ const responsePdf = result.ok ? availablePdf(config, id, mainFile) : null;
666
649
  const pdfMetadata = pdfResponseMetadata(config, responsePdf?.path ?? null);
667
650
  reply.header("Server-Timing", [
668
651
  `snapshot;dur=${timingDuration(result.snapshotMs ?? 0)}`,
@@ -698,25 +681,22 @@ export function registerCompileRoutes(app, context) {
698
681
  if (!mainFile)
699
682
  return apiError(reply, 400, "MAIN_DOCUMENT_INVALID");
700
683
  const downloading = query.download === "1";
701
- let artifact = availablePdf(config, id, mainFile, project.main_file);
684
+ let artifact = availablePdf(config, id, mainFile);
702
685
  if (!artifact)
703
686
  return apiError(reply, 404, "PDF_NOT_FOUND");
704
687
  let versioned = false;
705
688
  if (query.run) {
706
- if (/^[a-f0-9-]{36}$/i.test(query.run)) {
707
- const run = db.prepare(`SELECT main_file, status FROM compile_runs
708
- WHERE id = ? AND project_id = ?`).get(query.run, id);
709
- if (!run || run.status !== "succeeded" || run.main_file !== mainFile) {
710
- return apiError(reply, 404, "PDF_NOT_FOUND");
711
- }
712
- artifact = compileRunPdf(config, id, mainFile, query.run);
713
- if (!artifact)
714
- return apiError(reply, 404, "PDF_NOT_FOUND");
715
- versioned = true;
716
- }
717
- else if (artifact.version !== query.run) {
689
+ if (!/^[a-f0-9-]{36}$/i.test(query.run))
690
+ return apiError(reply, 404, "PDF_NOT_FOUND");
691
+ const run = db.prepare(`SELECT main_file, status FROM compile_runs
692
+ WHERE id = ? AND project_id = ?`).get(query.run, id);
693
+ if (!run || run.status !== "succeeded" || run.main_file !== mainFile) {
718
694
  return apiError(reply, 404, "PDF_NOT_FOUND");
719
695
  }
696
+ artifact = compileRunPdf(config, id, mainFile, query.run);
697
+ if (!artifact)
698
+ return apiError(reply, 404, "PDF_NOT_FOUND");
699
+ versioned = true;
720
700
  }
721
701
  const pdf = artifact.path;
722
702
  const stat = regularFileStat(pdf);
@@ -1,5 +1,4 @@
1
1
  import fs from "node:fs";
2
- import { isUtf8 } from "node:buffer";
3
2
  import { requireUser } from "../auth.js";
4
3
  import { isCollaborativeTextFile, maxCollaborativeFileBytes } from "../collaboration.js";
5
4
  import { hashText } from "../editHistory.js";
@@ -7,7 +6,7 @@ import { HISTORY_RETENTION_DELAY_MS } from "../historyRetention.js";
7
6
  import { resolveSourcePath, safeRelativePath } from "../files.js";
8
7
  import { apiError, httpError } from "../http.js";
9
8
  import { MAX_TEXT_PREVIEW_BYTES } from "../limits.js";
10
- import { isHistoryTextFile } from "../../shared/historyFiles.js";
9
+ import { defaultHistoryTracking, historyTextCandidate } from "../../shared/historyTracking.js";
11
10
  import { accessibleProject, canEdit } from "../projects.js";
12
11
  import { commentsSummaryForProject, projectJson, projectTextSnapshot, reanchorProjectSnapshot, requireEditableProject, requireProjectOwnerPermission, tagsForProject, text, touchProject } from "./projectShared.js";
13
12
  /** Register retained project version listing, inspection, restoration, and cleanup routes. */
@@ -148,13 +147,21 @@ export function registerProjectHistoryRoutes(app, context) {
148
147
  const manifest = history.manifest(id, versionId);
149
148
  if (!version || !manifest)
150
149
  return apiError(reply, 404, "HISTORY_VERSION_NOT_FOUND");
150
+ const changedPaths = new Set(version.changedPaths);
151
+ const deletedPaths = version.changedPaths.filter((filePath) => !manifest.files[filePath]);
152
+ const previous = deletedPaths.length > 0 ? history.previousVersion(id, versionId) : null;
153
+ const previousManifest = previous ? history.manifest(id, previous.id) : null;
151
154
  return {
152
155
  version,
153
156
  scoped: Boolean(manifest.tracking),
154
157
  settings: manifest.settings,
155
158
  files: [
156
- ...Object.entries(manifest.files).map(([filePath, file]) => ({ path: filePath, size: file.size })),
157
- ...version.changedPaths.filter((filePath) => !manifest.files[filePath]).map((filePath) => ({ path: filePath, size: 0, deleted: true }))
159
+ ...Object.entries(manifest.files).map(([filePath, file]) => ({
160
+ path: filePath, size: file.size,
161
+ ...(changedPaths.has(filePath) ? { textContent: history.isTextFile(id, filePath, file) } : {})
162
+ })),
163
+ ...deletedPaths.map((filePath) => ({ path: filePath, size: 0, deleted: true,
164
+ textContent: history.isTextFile(id, filePath, previousManifest?.files[filePath]) }))
158
165
  ].sort((left, right) => left.path.localeCompare(right.path))
159
166
  };
160
167
  });
@@ -175,7 +182,7 @@ export function registerProjectHistoryRoutes(app, context) {
175
182
  if (!manifest.files[filePath] && !version.changedPaths.includes(filePath))
176
183
  return apiError(reply, 404, "HISTORY_FILE_NOT_FOUND");
177
184
  // Never decode attachment bytes as UTF-8, including direct API calls.
178
- if (!isHistoryTextFile(filePath))
185
+ if (!historyTextCandidate(filePath))
179
186
  return apiError(reply, 415, "HISTORY_FILE_PREVIEW_UNSUPPORTED", { path: filePath });
180
187
  const historical = manifest.files[filePath] ? history.readTextFile(id, versionId, filePath) : "";
181
188
  if (historical === null)
@@ -200,7 +207,7 @@ export function registerProjectHistoryRoutes(app, context) {
200
207
  if (fs.statSync(current).size > MAX_TEXT_PREVIEW_BYTES)
201
208
  return apiError(reply, 415, "HISTORY_FILE_PREVIEW_UNSUPPORTED", { path: filePath });
202
209
  const bytes = fs.readFileSync(current);
203
- if (bytes.includes(0) || !isUtf8(bytes))
210
+ if (!defaultHistoryTracking(filePath, bytes))
204
211
  return apiError(reply, 415, "HISTORY_FILE_PREVIEW_UNSUPPORTED", { path: filePath });
205
212
  comparison = bytes.toString("utf8");
206
213
  }
@@ -12,7 +12,6 @@ import { writeProjectArchive } from "../archive.js";
12
12
  import { extractProjectZip, ZipValidationError } from "../zip.js";
13
13
  import { HarperLintSupersededError, HarperUnavailableError } from "../harper.js";
14
14
  import { ChktexLintSupersededError, ChktexUnavailableError } from "../chktex.js";
15
- import { digestToken } from "../security.js";
16
15
  import { supportsChktexChecks, supportsWritingChecks } from "../../shared/writingChecks.js";
17
16
  import { unreadMentionCountsForProjects } from "../commentMentions.js";
18
17
  import { commentsSummaryForProject, commentsSummaryForProjects, dictionaryWord, escapeLikePattern, now, projectJson, requireProjectOwnerPermission, tagColors, tagsForProject, tagsForProjects, text } from "./projectShared.js";
@@ -380,13 +379,10 @@ export function registerProjectCatalogRoutes(app, context) {
380
379
  if (typeof source !== "string" || typeof sourcePath !== "string") {
381
380
  return apiError(reply, 400, "SPELLCHECK_SOURCE_INVALID");
382
381
  }
383
- // Accept already-open clients during a rolling update. Current clients
384
- // pair a page-local UUID with a monotonically increasing sequence so a
385
- // delayed HTTP request cannot replace a newer queued check.
386
- if (clientId !== undefined && (typeof clientId !== "string" || !clientIdPattern.test(clientId))) {
387
- return apiError(reply, 400, "SPELLCHECK_SOURCE_INVALID");
388
- }
389
- if (sequence !== undefined && (typeof sequence !== "number" || !Number.isSafeInteger(sequence) || sequence <= 0 || clientId === undefined)) {
382
+ if (clientId === undefined || sequence === undefined)
383
+ return apiError(reply, 409, "CLIENT_UPDATE_REQUIRED");
384
+ if (typeof clientId !== "string" || !clientIdPattern.test(clientId)
385
+ || typeof sequence !== "number" || !Number.isSafeInteger(sequence) || sequence <= 0) {
390
386
  return apiError(reply, 400, "SPELLCHECK_SOURCE_INVALID");
391
387
  }
392
388
  if (Buffer.byteLength(source, "utf8") > maxCollaborativeFileBytes(config)) {
@@ -400,17 +396,14 @@ export function registerProjectCatalogRoutes(app, context) {
400
396
  return apiError(reply, 400, "SPELLCHECK_SOURCE_INVALID");
401
397
  }
402
398
  // Bibliography files are structured reference data rather than prose.
403
- // Keep this server-side guard for legacy clients and direct API callers.
404
399
  if (!supportsWritingChecks(filePath))
405
400
  return { lints: [] };
406
401
  // A login session is shared by browser tabs. Pair the authenticated user
407
402
  // with the page-local client ID so each new editor can replace only its
408
- // own obsolete waiting work. Legacy clients retain their former session
409
- // grouping until their page is refreshed.
410
- const laneClientId = clientId ?? `legacy:${digestToken(request.cookies.texlite_session ?? "")}`;
411
- const lane = `${id}\0${user.id}\0${laneClientId}\0${filePath}`;
403
+ // own obsolete waiting work.
404
+ const lane = `${id}\0${user.id}\0${clientId}\0${filePath}`;
412
405
  try {
413
- return { lints: await harper.lint(source, filePath, lane, typeof sequence === "number" ? sequence : undefined) };
406
+ return { lints: await harper.lint(source, filePath, lane, sequence) };
414
407
  }
415
408
  catch (error) {
416
409
  if (error instanceof HarperLintSupersededError) {
@@ -433,8 +426,6 @@ export function registerProjectCatalogRoutes(app, context) {
433
426
  const project = accessibleProject(db, id, user);
434
427
  if (!project)
435
428
  return apiError(reply, 404, "PROJECT_NOT_FOUND");
436
- if (!project.chktex_enabled)
437
- return { issues: [] };
438
429
  const body = request.body;
439
430
  const source = body?.source;
440
431
  const sourcePath = body?.path;
@@ -442,12 +433,14 @@ export function registerProjectCatalogRoutes(app, context) {
442
433
  const sequence = body?.sequence;
443
434
  if (typeof source !== "string" || typeof sourcePath !== "string")
444
435
  return apiError(reply, 400, "CHK_TEX_SOURCE_INVALID");
445
- if (clientId !== undefined && (typeof clientId !== "string" || !clientIdPattern.test(clientId))) {
446
- return apiError(reply, 400, "CHK_TEX_SOURCE_INVALID");
447
- }
448
- if (sequence !== undefined && (typeof sequence !== "number" || !Number.isSafeInteger(sequence) || sequence <= 0 || clientId === undefined)) {
436
+ if (clientId === undefined || sequence === undefined)
437
+ return apiError(reply, 409, "CLIENT_UPDATE_REQUIRED");
438
+ if (typeof clientId !== "string" || !clientIdPattern.test(clientId)
439
+ || typeof sequence !== "number" || !Number.isSafeInteger(sequence) || sequence <= 0) {
449
440
  return apiError(reply, 400, "CHK_TEX_SOURCE_INVALID");
450
441
  }
442
+ if (!project.chktex_enabled)
443
+ return { issues: [] };
451
444
  if (Buffer.byteLength(source, "utf8") > maxCollaborativeFileBytes(config)) {
452
445
  return apiError(reply, 413, "CHK_TEX_SOURCE_TOO_LARGE");
453
446
  }
@@ -460,10 +453,9 @@ export function registerProjectCatalogRoutes(app, context) {
460
453
  }
461
454
  if (!supportsChktexChecks(filePath))
462
455
  return { issues: [] };
463
- const laneClientId = clientId ?? `legacy:${digestToken(request.cookies.texlite_session ?? "")}`;
464
- const lane = `${id}\0${user.id}\0${laneClientId}\0${filePath}`;
456
+ const lane = `${id}\0${user.id}\0${clientId}\0${filePath}`;
465
457
  try {
466
- return { issues: await chktex.lint(source, filePath, lane, typeof sequence === "number" ? sequence : undefined) };
458
+ return { issues: await chktex.lint(source, filePath, lane, sequence) };
467
459
  }
468
460
  catch (error) {
469
461
  if (error instanceof ChktexLintSupersededError)
@@ -0,0 +1,51 @@
1
+ /** Stable translated errors shared by HTTP responses and terminal messages. */
2
+ export const agentMessages = {
3
+ en: {
4
+ AGENT_DISABLED: "This tool is disabled or project write access is unavailable.",
5
+ AGENT_UNAVAILABLE: "This agent is not installed or cannot run on the server.",
6
+ AGENT_PTY_UNAVAILABLE: "Terminal support is unavailable. Install the optional node-pty dependency on the server and restart TexLite.",
7
+ AGENT_SESSION_NOT_FOUND: "This agent task does not exist or belongs to another user.",
8
+ AGENT_SESSION_BUSY: "Wait for the current task operation to finish.",
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
+ AGENT_SYNC_FAILED: "External file synchronization failed. The agent has been stopped; check the project files and server logs.",
11
+ 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
+ AGENT_NO_CONTEXT: "This task's saved conversation cannot be resumed. Create a new task with + to start a new conversation.",
13
+ 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.",
14
+ AGENT_START_FAILED: "The agent could not start. Check its installation and server logs.",
15
+ AGENT_STOP_FAILED: "The agent has not stopped. Retry ending execution before cleaning its files.",
16
+ AGENT_RECOVERY_FAILED: "A previous execution could not be safely recovered. Its project remains reserved. Retry ending the task; if needed, stop its processes on the host first.",
17
+ AGENT_CLEANUP_FAILED: "Task cleanup did not finish. Its record has been kept for retry."
18
+ },
19
+ zh: {
20
+ AGENT_DISABLED: "此外部工具未启用,或你已没有项目写入权限。",
21
+ AGENT_UNAVAILABLE: "服务器未安装此 agent,或该命令无法运行。",
22
+ AGENT_PTY_UNAVAILABLE: "终端支持不可用。请在服务器安装可选依赖 node-pty 后重启 TexLite。",
23
+ AGENT_SESSION_NOT_FOUND: "此 agent 任务不存在,或属于其他用户。",
24
+ AGENT_SESSION_BUSY: "请等待当前任务操作完成。",
25
+ AGENT_PROJECT_BUSY: "本项目已有 Agent 任务在运行,需先结束该任务才能启动其他任务;收起终端不会停止任务。",
26
+ AGENT_SYNC_FAILED: "外部文件同步失败,Agent 已停止。请检查项目文件和服务器日志。",
27
+ AGENT_SYNC_CONFLICT: "并发修改存在冲突。已保留编辑器版本,Agent 的文件已保存在本项目的 .texlite-agent-conflicts 目录中,Agent 已停止。",
28
+ AGENT_NO_CONTEXT: "无法恢复此任务的对话。请通过+新建任务以开始新对话。",
29
+ AGENT_CONTEXT_CHECK_FAILED: "无法确认此任务的对话状态。请重试,或检查 Agent 安装及任务数据;尚未创建新对话。",
30
+ AGENT_START_FAILED: "无法启动 agent。请检查命令安装情况及服务器日志。",
31
+ AGENT_STOP_FAILED: "Agent 尚未停止。请重试结束运行,再清理其文件。",
32
+ AGENT_RECOVERY_FAILED: "无法安全回收上一次执行,项目执行权仍被保留。请重试结束任务;必要时先在宿主机停止其进程。",
33
+ AGENT_CLEANUP_FAILED: "任务清理未完成。已保留记录,可重试清理。"
34
+ },
35
+ "zh-Hant": {
36
+ AGENT_DISABLED: "此外部工具尚未啟用,或你已沒有專案寫入權限。",
37
+ AGENT_UNAVAILABLE: "伺服器未安裝此 agent,或該命令無法執行。",
38
+ AGENT_PTY_UNAVAILABLE: "終端機支援無法使用。請在伺服器安裝選用相依套件 node-pty 後重新啟動 TexLite。",
39
+ AGENT_SESSION_NOT_FOUND: "此 agent 任務不存在,或屬於其他使用者。",
40
+ AGENT_SESSION_BUSY: "請等待目前任務操作完成。",
41
+ AGENT_PROJECT_BUSY: "此專案已有 Agent 任務正在執行,須先結束該任務才能啟動其他任務;收起終端機不會停止任務。",
42
+ AGENT_SYNC_FAILED: "外部檔案同步失敗,Agent 已停止。請檢查專案檔案與伺服器日誌。",
43
+ AGENT_SYNC_CONFLICT: "並行修改發生衝突。已保留編輯器版本,Agent 的檔案已儲存於此專案的 .texlite-agent-conflicts 目錄中,Agent 已停止。",
44
+ AGENT_NO_CONTEXT: "無法恢復此任務的對話。請透過+新增任務以開始新對話。",
45
+ AGENT_CONTEXT_CHECK_FAILED: "無法確認此任務的對話狀態。請重試,或檢查 Agent 安裝及任務資料;尚未建立新對話。",
46
+ AGENT_START_FAILED: "無法啟動 agent。請檢查命令安裝情況及伺服器日誌。",
47
+ AGENT_STOP_FAILED: "Agent 尚未停止。請重試結束執行,再清理其檔案。",
48
+ AGENT_RECOVERY_FAILED: "無法安全回收上一次執行,專案執行權仍被保留。請重試結束任務;必要時先在主機停止其處理程序。",
49
+ AGENT_CLEANUP_FAILED: "任務清理未完成。已保留記錄,可重試清理。"
50
+ }
51
+ };
@@ -0,0 +1,41 @@
1
+ /** Stable identities, rather than executable strings supplied by the browser. */
2
+ export const AGENT_IDS = ["codex", "opencode", "claude"];
3
+ export const AGENT_LABELS = { codex: "Codex", opencode: "OpenCode", claude: "Claude Code" };
4
+ export const AGENT_TASK_PAGE_SIZE = 50;
5
+ export const isAgentId = (value) => AGENT_IDS.includes(value);
6
+ const MAX_INPUT_CHARS = 64 * 1024;
7
+ /** Split large pastes into transport frames without splitting UTF-16 pairs. */
8
+ export function agentInputChunks(input) {
9
+ const chunks = [];
10
+ for (let start = 0; start < input.length;) {
11
+ let end = Math.min(input.length, start + MAX_INPUT_CHARS);
12
+ const last = input.charCodeAt(end - 1);
13
+ if (end < input.length && last >= 0xd800 && last <= 0xdbff)
14
+ end--;
15
+ chunks.push(input.slice(start, end));
16
+ start = end;
17
+ }
18
+ return chunks;
19
+ }
20
+ /** Keep terminal input and resize validation independent of the transport. */
21
+ export function parseAgentClientMessage(raw) {
22
+ let value;
23
+ try {
24
+ value = JSON.parse(raw);
25
+ }
26
+ catch {
27
+ return null;
28
+ }
29
+ if (!value || typeof value !== "object" || !("type" in value))
30
+ return null;
31
+ const message = value;
32
+ if (message.type === "takeControl")
33
+ return { type: "takeControl" };
34
+ if (message.type === "input" && typeof message.data === "string" && message.data.length <= MAX_INPUT_CHARS)
35
+ return { type: "input", data: message.data };
36
+ if (message.type === "resize" && Number.isInteger(message.cols) && Number.isInteger(message.rows)
37
+ && Number(message.cols) >= 2 && Number(message.cols) <= 500 && Number(message.rows) >= 2 && Number(message.rows) <= 300) {
38
+ return { type: "resize", cols: Number(message.cols), rows: Number(message.rows) };
39
+ }
40
+ return null;
41
+ }
@@ -2,5 +2,5 @@
2
2
  export function isHistoryTextFile(filePath) {
3
3
  const name = filePath.split("/").at(-1) ?? "";
4
4
  return /\.(?:tex|bib|bst|sty|cls|txt|md|rst|dat|csv|tsv|json|ya?ml|toml|xml|html?|css|[cm]?js|tsx?|py|sh|r|log|bbl|aux|idx|ind|gls)$/i.test(name)
5
- || /^(?:\.?latexmkrc|readme|licen[cs]e|makefile)$/i.test(name);
5
+ || /^(?:\.?latexmkrc|readme|licen[cs]e|makefile|\.git(?:ignore|attributes|modules))$/i.test(name);
6
6
  }
@@ -1,5 +1,7 @@
1
1
  import { isTextContent, resourceFileKind } from "./fileTypes.js";
2
2
  export function historyTextCandidate(filePath) {
3
+ if (!filePath)
4
+ return false;
3
5
  const kind = resourceFileKind(filePath);
4
6
  return kind === "text" || kind === "other";
5
7
  }
@@ -0,0 +1,21 @@
1
+ export const supportedLocales = ["en", "zh", "zh-Hant"];
2
+ /** Preserve the existing `zh` preference while distinguishing Chinese scripts. */
3
+ export function supportedLocale(language) {
4
+ const parts = language?.trim().toLowerCase().replaceAll("_", "-").split("-") ?? [];
5
+ if (parts[0] === "en")
6
+ return "en";
7
+ if (parts[0] !== "zh")
8
+ return null;
9
+ if (parts.includes("hant"))
10
+ return "zh-Hant";
11
+ if (parts.includes("hans"))
12
+ return "zh";
13
+ return parts.some((part) => part === "tw" || part === "hk" || part === "mo") ? "zh-Hant" : "zh";
14
+ }
15
+ export function appLocale(language) {
16
+ return supportedLocale(language) ?? "en";
17
+ }
18
+ export function documentLocale(language) {
19
+ const locale = appLocale(language);
20
+ return locale === "zh" ? "zh-CN" : locale;
21
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "texlite",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "A lightweight local-first collaborative LaTeX workspace",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {
@@ -22,6 +22,7 @@
22
22
  },
23
23
  "files": [
24
24
  "dist",
25
+ "templates/agents/AGENTS.md",
25
26
  "README.md",
26
27
  "README.zh-CN.md",
27
28
  "OPERATIONS.md",
@@ -29,8 +30,6 @@
29
30
  "NPM_TESTING.md",
30
31
  "LICENSE",
31
32
  "THIRD_PARTY_NOTICES.md",
32
- "preview-1.png",
33
- "preview-2.png",
34
33
  "texlite.config.example.json"
35
34
  ],
36
35
  "engines": {
@@ -114,6 +113,8 @@
114
113
  "@types/semver": "^7.8.0",
115
114
  "@types/ws": "^8.18.1",
116
115
  "@vitejs/plugin-react": "^6.1.2",
116
+ "@xterm/addon-fit": "^0.11.0",
117
+ "@xterm/xterm": "^6.0.0",
117
118
  "bibtex-tidy": "1.14.0",
118
119
  "happy-dom": "^21.0.4",
119
120
  "i18next": "^26.5.3",
@@ -134,5 +135,8 @@
134
135
  "y-codemirror.next": "^0.3.5",
135
136
  "y-indexeddb": "^9.0.12",
136
137
  "y-websocket": "^3.0.0"
138
+ },
139
+ "optionalDependencies": {
140
+ "node-pty": "^1.1.0"
137
141
  }
138
142
  }