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

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 (82) hide show
  1. package/dist/THIRD-PARTY-NOTICES.txt +26 -1
  2. package/dist/alpd.js +11047 -3021
  3. package/dist/attachments.d.ts +25 -49
  4. package/dist/attachments.js +45 -8
  5. package/dist/build-manifest.json +14 -1
  6. package/dist/conversation.js +18 -2
  7. package/dist/disk.d.ts +67 -0
  8. package/dist/disk.js +152 -0
  9. package/dist/files.d.ts +141 -2
  10. package/dist/files.js +377 -68
  11. package/dist/git.d.ts +8 -2
  12. package/dist/git.js +111 -12
  13. package/dist/index.d.ts +1 -0
  14. package/dist/index.js +3 -0
  15. package/dist/main.js +37 -11
  16. package/dist/native-terminal.d.ts +45 -0
  17. package/dist/native-terminal.js +198 -0
  18. package/dist/operations.d.ts +8 -2
  19. package/dist/operations.js +20 -10
  20. package/dist/registry.js +1 -1
  21. package/dist/scheduler.js +8 -2
  22. package/dist/schedules.d.ts +2 -1
  23. package/dist/schedules.js +6 -4
  24. package/dist/server.d.ts +4 -2
  25. package/dist/server.js +166 -42
  26. package/dist/store.d.ts +3 -1
  27. package/dist/store.js +4 -3
  28. package/dist/terminal-native/README.md +201 -0
  29. package/dist/terminal-native/prebuilt/darwin-arm64/manifest.json +11 -0
  30. package/dist/terminal-native/prebuilt/darwin-arm64/terminal-owner +0 -0
  31. package/dist/terminal-native/prebuilt/darwin-x64/manifest.json +11 -0
  32. package/dist/terminal-native/prebuilt/darwin-x64/terminal-owner +0 -0
  33. package/dist/terminal-native/prebuilt/linux-arm64-glibc/manifest.json +10 -0
  34. package/dist/terminal-native/prebuilt/linux-arm64-glibc/terminal-owner +0 -0
  35. package/dist/terminal-native/prebuilt/linux-arm64-musl/manifest.json +10 -0
  36. package/dist/terminal-native/prebuilt/linux-arm64-musl/terminal-owner +0 -0
  37. package/dist/terminal-native/prebuilt/linux-x64-glibc/manifest.json +10 -0
  38. package/dist/terminal-native/prebuilt/linux-x64-glibc/terminal-owner +0 -0
  39. package/dist/terminal-native/prebuilt/linux-x64-musl/manifest.json +10 -0
  40. package/dist/terminal-native/prebuilt/linux-x64-musl/terminal-owner +0 -0
  41. package/dist/terminal-native/terminal-owner.c +389 -0
  42. package/dist/terminal-screen.d.ts +24 -0
  43. package/dist/terminal-screen.js +99 -0
  44. package/dist/terminals.d.ts +43 -7
  45. package/dist/terminals.js +222 -139
  46. package/dist/windows-terminal.d.ts +29 -0
  47. package/dist/windows-terminal.js +122 -0
  48. package/dist/worktrees.d.ts +25 -1
  49. package/dist/worktrees.js +74 -2
  50. package/native/README.md +201 -0
  51. package/native/prebuilt/darwin-arm64/manifest.json +11 -0
  52. package/native/prebuilt/darwin-arm64/terminal-owner +0 -0
  53. package/native/prebuilt/darwin-x64/manifest.json +11 -0
  54. package/native/prebuilt/darwin-x64/terminal-owner +0 -0
  55. package/native/prebuilt/linux-arm64-glibc/manifest.json +10 -0
  56. package/native/prebuilt/linux-arm64-glibc/terminal-owner +0 -0
  57. package/native/prebuilt/linux-arm64-musl/manifest.json +10 -0
  58. package/native/prebuilt/linux-arm64-musl/terminal-owner +0 -0
  59. package/native/prebuilt/linux-x64-glibc/manifest.json +10 -0
  60. package/native/prebuilt/linux-x64-glibc/terminal-owner +0 -0
  61. package/native/prebuilt/linux-x64-musl/manifest.json +10 -0
  62. package/native/prebuilt/linux-x64-musl/terminal-owner +0 -0
  63. package/native/terminal-owner.c +389 -0
  64. package/package.json +11 -7
  65. package/src/attachments.ts +46 -8
  66. package/src/conversation.ts +22 -2
  67. package/src/disk.ts +175 -0
  68. package/src/files.ts +505 -80
  69. package/src/git.ts +113 -18
  70. package/src/index.ts +1 -0
  71. package/src/main.ts +30 -11
  72. package/src/native-terminal.ts +122 -0
  73. package/src/operations.ts +27 -11
  74. package/src/registry.ts +1 -1
  75. package/src/scheduler.ts +13 -3
  76. package/src/schedules.ts +5 -2
  77. package/src/server.ts +157 -35
  78. package/src/store.ts +2 -1
  79. package/src/terminal-screen.ts +74 -0
  80. package/src/terminals.ts +205 -155
  81. package/src/windows-terminal.ts +123 -0
  82. package/src/worktrees.ts +97 -2
@@ -0,0 +1,74 @@
1
+ import headless from '@xterm/headless';
2
+ import { ERROR } from '@anhlp/alp-protocol';
3
+ import { RpcError } from './rpc-error.js';
4
+
5
+ // Exact xterm 6.0.0, also used by Paseo 0.12. No raw replay reconstruction: one parser from spawn.
6
+ // Bound both queued work and lifetime input (including OSC/combining payloads hidden from rows).
7
+ export const SCREEN_LIMITS = Object.freeze({ scrollback: 1000, pendingBytes: 1024 * 1024, pendingOperations: 256, inputBytes: 8 * 1024 * 1024, resultBytes: 1024 * 1024, retained: 16 });
8
+ export class TerminalScreen {
9
+ #term: InstanceType<typeof headless.Terminal> | undefined;
10
+ #pending = 0;
11
+ #input = 0;
12
+ #operations = 0;
13
+ #waiters = new Set<() => void>();
14
+ constructor(cols: number, rows: number) {
15
+ this.#term = new headless.Terminal({ cols, rows, scrollback: SCREEN_LIMITS.scrollback, allowProposedApi: true, logLevel: 'off' });
16
+ }
17
+ get available() { return this.#term !== undefined; }
18
+ #unavailable() { return new RpcError(ERROR.unavailable, 'Terminal capture is unavailable: its bounded screen was released or exceeded its resource limit', { reason: 'terminal_capture_unavailable' }); }
19
+ #queue(term: InstanceType<typeof headless.Terminal>, data: string, callback: () => void) {
20
+ if (this.#operations >= SCREEN_LIMITS.pendingOperations) { this.dispose(); return; }
21
+ this.#operations++;
22
+ try {
23
+ term.write(data, () => { this.#operations--; callback(); });
24
+ } catch { this.#operations--; this.dispose(); }
25
+ }
26
+ write(data: string) {
27
+ const term = this.#term;
28
+ if (!term) return;
29
+ const bytes = Buffer.byteLength(data);
30
+ this.#input += bytes;
31
+ if (this.#input > SCREEN_LIMITS.inputBytes || this.#pending + bytes > SCREEN_LIMITS.pendingBytes) { this.dispose(); return; }
32
+ this.#pending += bytes;
33
+ this.#queue(term, data, () => { this.#pending -= bytes; });
34
+ }
35
+ resize(cols: number, rows: number) {
36
+ const term = this.#term;
37
+ // Keep resize between the old output and output caused by the new PTY size.
38
+ if (term) this.#queue(term, '', () => { if (this.#term === term) term.resize(cols, rows); });
39
+ }
40
+ capture(options: { start?: number; end?: number; stripAnsi?: boolean } = {}): Promise<{ lines: string[]; totalLines: number }> {
41
+ const term = this.#term;
42
+ if (!term) return Promise.reject(this.#unavailable());
43
+ return new Promise((resolve, reject) => {
44
+ const released = () => reject(this.#unavailable());
45
+ this.#waiters.add(released);
46
+ // The callback is a parser barrier, not a delay or a ring-buffer approximation.
47
+ this.#queue(term, '', () => {
48
+ this.#waiters.delete(released);
49
+ if (this.#term !== term) { reject(this.#unavailable()); return; }
50
+ const buffer = term.buffer.active;
51
+ const totalLines = buffer.length;
52
+ const index = (value: number | undefined, fallback: number) => value === undefined ? fallback : Math.max(0, Math.min(totalLines - 1, value < 0 ? totalLines + value : value));
53
+ const start = index(options.start, 0);
54
+ const end = index(options.end, totalLines - 1);
55
+ const lines: string[] = [];
56
+ let bytes = 0;
57
+ for (let i = start; i <= end; i++) {
58
+ // Cell text, like Paseo: styling escapes are not regenerated when stripAnsi=false.
59
+ const line = buffer.getLine(i)?.translateToString(true).trimEnd() ?? '';
60
+ bytes += Buffer.byteLength(JSON.stringify(line)) + 1;
61
+ if (bytes > SCREEN_LIMITS.resultBytes - 128) { reject(new RpcError(ERROR.unavailable, 'Terminal capture exceeds the response limit; select a smaller line range', { reason: 'terminal_capture_too_large' })); return; }
62
+ lines.push(line);
63
+ }
64
+ resolve({ lines, totalLines });
65
+ });
66
+ });
67
+ }
68
+ dispose() {
69
+ this.#term?.dispose();
70
+ this.#term = undefined;
71
+ for (const waiter of this.#waiters) waiter();
72
+ this.#waiters.clear();
73
+ }
74
+ }