@anhlp/alp-daemon 0.0.1-beta.3 → 0.0.1-beta.4

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 (51) hide show
  1. package/README.md +4 -0
  2. package/dist/alpd.js +10350 -3346
  3. package/dist/attachments.d.ts +211 -0
  4. package/dist/attachments.js +819 -0
  5. package/dist/build-manifest.json +21 -1
  6. package/dist/conversation.d.ts +119 -0
  7. package/dist/conversation.js +672 -0
  8. package/dist/files.d.ts +13 -0
  9. package/dist/files.js +15 -0
  10. package/dist/git.d.ts +87 -0
  11. package/dist/git.js +1093 -0
  12. package/dist/gitignore.d.ts +5 -0
  13. package/dist/gitignore.js +7 -1
  14. package/dist/history.d.ts +24 -0
  15. package/dist/history.js +149 -0
  16. package/dist/index.d.ts +6 -0
  17. package/dist/index.js +18 -1
  18. package/dist/lifecycle.d.ts +101 -0
  19. package/dist/lifecycle.js +239 -0
  20. package/dist/main.js +9 -3
  21. package/dist/registry.d.ts +89 -0
  22. package/dist/registry.js +343 -0
  23. package/dist/scheduler.d.ts +96 -0
  24. package/dist/scheduler.js +290 -0
  25. package/dist/schedules.d.ts +69 -0
  26. package/dist/schedules.js +244 -0
  27. package/dist/server.d.ts +11 -1
  28. package/dist/server.js +698 -76
  29. package/dist/store.d.ts +69 -1
  30. package/dist/store.js +109 -3
  31. package/dist/terminals.d.ts +157 -0
  32. package/dist/terminals.js +487 -0
  33. package/dist/worktrees.d.ts +41 -0
  34. package/dist/worktrees.js +246 -0
  35. package/package.json +64 -5
  36. package/src/attachments.ts +870 -0
  37. package/src/conversation.ts +837 -0
  38. package/src/files.ts +23 -2
  39. package/src/git.ts +1045 -0
  40. package/src/gitignore.ts +10 -0
  41. package/src/history.ts +118 -0
  42. package/src/index.ts +6 -0
  43. package/src/lifecycle.ts +283 -0
  44. package/src/main.ts +9 -3
  45. package/src/registry.ts +238 -0
  46. package/src/scheduler.ts +422 -0
  47. package/src/schedules.ts +294 -0
  48. package/src/server.ts +810 -86
  49. package/src/store.ts +115 -3
  50. package/src/terminals.ts +591 -0
  51. package/src/worktrees.ts +287 -0
package/src/files.ts CHANGED
@@ -327,8 +327,29 @@ async function readConfined(file: string, maxBytes: number, probe?: FileProbe):
327
327
  }
328
328
  }
329
329
 
330
+ /**
331
+ * The bytes of the file at `segments` under the real root `root`, confined as readWorkspaceFile
332
+ * confines a read (every directory on the way a real directory reached by name and the same after
333
+ * the read; the file a regular file with one name, opened without following a link, the same by
334
+ * handle and by name), or `too_large` past `maxBytes`. Throws FileAccessError `linked` or
335
+ * `not_found` (its message names only `relative`). No block list or .gitignore check: the caller
336
+ * decides what may be read (workspace.git.diff, docs/protocol/alp-json-rpc-v1.md §12.5).
337
+ */
338
+ export async function readConfinedFile(root: string, segments: readonly string[], relative: string, maxBytes: number): Promise<Buffer | 'too_large'> {
339
+ const chain = await directoryChain(root, segments.slice(0, -1), relative);
340
+ let read: { bytes: Buffer } | undefined;
341
+ try {
342
+ read = await readConfined(path.join(root, ...segments), maxBytes);
343
+ } catch (error) {
344
+ if ((error as { linked?: boolean }).linked) throw linked(relative);
345
+ throw notFound(relative);
346
+ }
347
+ await sameChain(chain, relative);
348
+ return read === undefined ? 'too_large' : read.bytes;
349
+ }
350
+
330
351
  /** Paseo's isLikelyBinary (file-explorer/service.ts at b63a325): a NUL byte, or over 30% control characters. */
331
- function likelyBinary(buffer: Buffer): boolean {
352
+ export function likelyBinary(buffer: Buffer): boolean {
332
353
  if (!buffer.length) return false;
333
354
  let suspicious = 0;
334
355
  for (const byte of buffer) {
@@ -340,7 +361,7 @@ function likelyBinary(buffer: Buffer): boolean {
340
361
 
341
362
  // The BOM is kept: the content is the file's bytes, decoded.
342
363
  /** PEM, OpenSSH and PuTTY private-key headers: a file holding one is refused whatever its name. */
343
- const PRIVATE_KEY = /-----BEGIN (?:[A-Z0-9]+ )*PRIVATE KEY(?: BLOCK)?-----|PuTTY-User-Key-File-\d+:/;
364
+ export const PRIVATE_KEY = /-----BEGIN (?:[A-Z0-9]+ )*PRIVATE KEY(?: BLOCK)?-----|PuTTY-User-Key-File-\d+:/;
344
365
 
345
366
  const UTF8 = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
346
367