@anhlp/alp-daemon 0.0.1-beta.3 → 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 (95) hide show
  1. package/README.md +4 -0
  2. package/dist/THIRD-PARTY-NOTICES.txt +26 -1
  3. package/dist/alpd.js +29928 -14898
  4. package/dist/attachments.d.ts +187 -0
  5. package/dist/attachments.js +856 -0
  6. package/dist/build-manifest.json +34 -1
  7. package/dist/conversation.d.ts +119 -0
  8. package/dist/conversation.js +688 -0
  9. package/dist/disk.d.ts +67 -0
  10. package/dist/disk.js +152 -0
  11. package/dist/files.d.ts +154 -2
  12. package/dist/files.js +392 -68
  13. package/dist/git.d.ts +93 -0
  14. package/dist/git.js +1192 -0
  15. package/dist/gitignore.d.ts +5 -0
  16. package/dist/gitignore.js +7 -1
  17. package/dist/history.d.ts +24 -0
  18. package/dist/history.js +149 -0
  19. package/dist/index.d.ts +7 -0
  20. package/dist/index.js +21 -1
  21. package/dist/lifecycle.d.ts +101 -0
  22. package/dist/lifecycle.js +239 -0
  23. package/dist/main.js +43 -11
  24. package/dist/native-terminal.d.ts +45 -0
  25. package/dist/native-terminal.js +198 -0
  26. package/dist/operations.d.ts +8 -2
  27. package/dist/operations.js +20 -10
  28. package/dist/registry.d.ts +89 -0
  29. package/dist/registry.js +343 -0
  30. package/dist/scheduler.d.ts +96 -0
  31. package/dist/scheduler.js +296 -0
  32. package/dist/schedules.d.ts +70 -0
  33. package/dist/schedules.js +246 -0
  34. package/dist/server.d.ts +14 -2
  35. package/dist/server.js +836 -90
  36. package/dist/store.d.ts +72 -2
  37. package/dist/store.js +111 -4
  38. package/dist/terminal-native/README.md +201 -0
  39. package/dist/terminal-native/prebuilt/darwin-arm64/manifest.json +11 -0
  40. package/dist/terminal-native/prebuilt/darwin-arm64/terminal-owner +0 -0
  41. package/dist/terminal-native/prebuilt/darwin-x64/manifest.json +11 -0
  42. package/dist/terminal-native/prebuilt/darwin-x64/terminal-owner +0 -0
  43. package/dist/terminal-native/prebuilt/linux-arm64-glibc/manifest.json +10 -0
  44. package/dist/terminal-native/prebuilt/linux-arm64-glibc/terminal-owner +0 -0
  45. package/dist/terminal-native/prebuilt/linux-arm64-musl/manifest.json +10 -0
  46. package/dist/terminal-native/prebuilt/linux-arm64-musl/terminal-owner +0 -0
  47. package/dist/terminal-native/prebuilt/linux-x64-glibc/manifest.json +10 -0
  48. package/dist/terminal-native/prebuilt/linux-x64-glibc/terminal-owner +0 -0
  49. package/dist/terminal-native/prebuilt/linux-x64-musl/manifest.json +10 -0
  50. package/dist/terminal-native/prebuilt/linux-x64-musl/terminal-owner +0 -0
  51. package/dist/terminal-native/terminal-owner.c +389 -0
  52. package/dist/terminal-screen.d.ts +24 -0
  53. package/dist/terminal-screen.js +99 -0
  54. package/dist/terminals.d.ts +193 -0
  55. package/dist/terminals.js +570 -0
  56. package/dist/windows-terminal.d.ts +29 -0
  57. package/dist/windows-terminal.js +122 -0
  58. package/dist/worktrees.d.ts +65 -0
  59. package/dist/worktrees.js +318 -0
  60. package/native/README.md +201 -0
  61. package/native/prebuilt/darwin-arm64/manifest.json +11 -0
  62. package/native/prebuilt/darwin-arm64/terminal-owner +0 -0
  63. package/native/prebuilt/darwin-x64/manifest.json +11 -0
  64. package/native/prebuilt/darwin-x64/terminal-owner +0 -0
  65. package/native/prebuilt/linux-arm64-glibc/manifest.json +10 -0
  66. package/native/prebuilt/linux-arm64-glibc/terminal-owner +0 -0
  67. package/native/prebuilt/linux-arm64-musl/manifest.json +10 -0
  68. package/native/prebuilt/linux-arm64-musl/terminal-owner +0 -0
  69. package/native/prebuilt/linux-x64-glibc/manifest.json +10 -0
  70. package/native/prebuilt/linux-x64-glibc/terminal-owner +0 -0
  71. package/native/prebuilt/linux-x64-musl/manifest.json +10 -0
  72. package/native/prebuilt/linux-x64-musl/terminal-owner +0 -0
  73. package/native/terminal-owner.c +389 -0
  74. package/package.json +70 -7
  75. package/src/attachments.ts +908 -0
  76. package/src/conversation.ts +857 -0
  77. package/src/disk.ts +175 -0
  78. package/src/files.ts +528 -82
  79. package/src/git.ts +1140 -0
  80. package/src/gitignore.ts +10 -0
  81. package/src/history.ts +118 -0
  82. package/src/index.ts +7 -0
  83. package/src/lifecycle.ts +283 -0
  84. package/src/main.ts +37 -12
  85. package/src/native-terminal.ts +122 -0
  86. package/src/operations.ts +27 -11
  87. package/src/registry.ts +238 -0
  88. package/src/scheduler.ts +432 -0
  89. package/src/schedules.ts +297 -0
  90. package/src/server.ts +948 -102
  91. package/src/store.ts +117 -4
  92. package/src/terminal-screen.ts +74 -0
  93. package/src/terminals.ts +641 -0
  94. package/src/windows-terminal.ts +123 -0
  95. package/src/worktrees.ts +382 -0
@@ -0,0 +1,187 @@
1
+ import { type FileHandle } from 'node:fs/promises';
2
+ import { type Readable } from 'node:stream';
3
+ import type { AttachmentInfo, AttachmentLimits } from '@anhlp/alp-protocol/rpc';
4
+ import type { RuntimeAttachment } from '@anhlp/alp-protocol/session';
5
+ /**
6
+ * Non-image attachments (capability `attachments`, docs/protocol/alp-json-rpc-v1.md §12.6, issue
7
+ * #121 branch I): daemon-owned immutable objects under `<ALP_HOME>/state/attachments/<id>/`, each a
8
+ * directory (0700) holding an opaque `payload` (0600, 0400 once committed) and its `meta.json`,
9
+ * plus one durable reference index `refs.json` beside them.
10
+ *
11
+ * - An upload is bound to its principal (identity and grant epoch; `owner` for the local owner), the
12
+ * canonical project of its session, and the session. Every chunk, commit, get, delete and prompt
13
+ * checks the whole binding again; an id that is unknown, of another principal, epoch, project or
14
+ * session, or whose session is gone answers the same `1001 not_found`.
15
+ * - Nothing a client sends becomes a path: ids are generated here, the display name is only
16
+ * metadata. Files are created exclusively without following links, and every open checks a
17
+ * regular file with one name whose device and inode are the ones recorded at creation, so a
18
+ * swapped, linked or replaced directory or payload is refused rather than followed.
19
+ * - Quota is reserved at begin for the declared size, synchronously, so concurrent begins cannot
20
+ * oversubscribe; it is held until the object is deleted, whether or not it is referenced.
21
+ * - An object is published by writing its meta as committed, atomically, after its whole payload
22
+ * was read back and its SHA-256 matched. A write failure aborts the upload: nothing half written
23
+ * is ever committed and its reservation is released.
24
+ * - References are holders (a prompt receipt key, later a fork) naming the attachments they keep,
25
+ * in `refs.json`, written atomically before what needs them (a prompt's delivery). A referenced
26
+ * object is never collected; one whose references were released is kept `releasedGraceMs` more.
27
+ *
28
+ * Process crashes are covered (atomic renames, temporary files cleaned at start); power loss is not
29
+ * claimed. Windows is not supported (no O_NOFOLLOW, no POSIX modes): alpd does not serve this there.
30
+ */
31
+ export type Principal = {
32
+ id: string;
33
+ epoch: string;
34
+ roots?: readonly string[];
35
+ };
36
+ export type AttachmentLimitsInput = Partial<AttachmentLimits>;
37
+ /** What alpd binds for a runtime that takes attachments (the seam of issue #121 branch J). */
38
+ export type AttachmentReader = {
39
+ /**
40
+ * The verified bytes of an attachment some holder of `sessionId` pins (a prompt alpd delivers to
41
+ * it): a read-only stream of exactly `size` bytes whose SHA-256 is checked at its end, never a path.
42
+ */
43
+ open(attachmentId: string, sessionId: string): Promise<{
44
+ stream: Readable;
45
+ attachment: RuntimeAttachment;
46
+ }>;
47
+ };
48
+ /** The runtime side of the seam: absent members mean the runtime takes no attachment parts. */
49
+ export type AttachmentRuntime = {
50
+ /** Whether this live session's runtime takes `{ type: 'attachment' }` parts (RuntimeAttachment) now. */
51
+ takesAttachments?(sessionId: string): boolean;
52
+ /** alpd hands its reader over once, at start, as it does its schedules. */
53
+ bindAttachments?(reader: AttachmentReader | undefined): void;
54
+ /** Removes the runtime's staged copy of an object alpd collected. */
55
+ dropAttachment?(attachmentId: string): Promise<void>;
56
+ };
57
+ type Holder = {
58
+ sessionId: string;
59
+ attachments: string[];
60
+ at: string;
61
+ kind: string;
62
+ };
63
+ /**
64
+ * A display name as alpd keeps it: NFC, without control or format characters (NUL, bidi
65
+ * overrides, zero-width), line or paragraph separators and path separators (/ and \), trimmed; at
66
+ * most `maxBytes` UTF-8 bytes. It is metadata only and never names a file. Undefined when nothing
67
+ * usable is left (empty, `.` or `..`) or it is too long.
68
+ */
69
+ export declare function attachmentName(raw: unknown, maxBytes?: 255): string | undefined;
70
+ /**
71
+ * What the first bytes of a payload look like, for display only: the declared MIME type is the
72
+ * client's and is never trusted to choose behaviour, nor is this.
73
+ */
74
+ export declare function sniffMimeType(head: Buffer): string;
75
+ /** Effective limits: ATTACHMENTS, each lowered (never raised) by `input`; the chunk also by the frame. */
76
+ export declare function attachmentLimits(input?: AttachmentLimitsInput, maxFrame?: number): AttachmentLimits;
77
+ /** Hooks for tests: a write that fails as a full disk would, crash points, a clock. */
78
+ export type AttachmentStoreOptions = {
79
+ /** `<ALP_HOME>/state/attachments`. */
80
+ root: string;
81
+ limits?: AttachmentLimitsInput;
82
+ /** The project root of a session alpd knows (live or recorded), or undefined. */
83
+ sessionProject(sessionId: string): string | undefined;
84
+ now?: () => number;
85
+ crashPoint?: (name: string) => void;
86
+ log?: {
87
+ warn(message: string, fields?: Record<string, unknown>): void;
88
+ info?(message: string, fields?: Record<string, unknown>): void;
89
+ };
90
+ io?: {
91
+ write?(handle: FileHandle, buffer: Buffer, position: number): Promise<void>;
92
+ };
93
+ /** How often expired uploads and unreferenced objects are collected while alpd runs. */
94
+ sweepMs?: number;
95
+ /** Told of each committed object alpd removes (the runtime drops its staged copy); failures are logged. */
96
+ onDiscard?: (attachmentId: string) => Promise<void> | void;
97
+ };
98
+ export type AttachmentStore = ReturnType<typeof createAttachmentStore>;
99
+ export declare function createAttachmentStore(options: AttachmentStoreOptions): {
100
+ sweep: () => Promise<void>;
101
+ begin: (principal: Principal, params: {
102
+ sessionId: string;
103
+ name: string;
104
+ size: number;
105
+ mimeType: string;
106
+ sha256?: string;
107
+ requestId: string;
108
+ }) => Promise<{
109
+ expiresAt: string;
110
+ uploadId: string;
111
+ state: "uploading" | "committed";
112
+ received: number;
113
+ size: number;
114
+ maxChunkBytes: number;
115
+ } | {
116
+ attachmentId: string;
117
+ uploadId: string;
118
+ state: "uploading" | "committed";
119
+ received: number;
120
+ size: number;
121
+ maxChunkBytes: number;
122
+ }>;
123
+ chunk: (principal: Principal, params: {
124
+ uploadId: string;
125
+ offset: number;
126
+ data: string;
127
+ }) => Promise<{
128
+ received: number;
129
+ size: number;
130
+ }>;
131
+ commit: (principal: Principal, params: {
132
+ uploadId: string;
133
+ sha256: string;
134
+ }) => Promise<{
135
+ attachment: AttachmentInfo;
136
+ }>;
137
+ abort: (principal: Principal, params: {
138
+ uploadId: string;
139
+ }) => Promise<{
140
+ aborted: true;
141
+ }>;
142
+ get: (principal: Principal, params: {
143
+ attachmentId: string;
144
+ }) => Promise<{
145
+ attachment: AttachmentInfo;
146
+ }>;
147
+ remove: (principal: Principal, params: {
148
+ attachmentId: string;
149
+ }) => Promise<{
150
+ deleted: true;
151
+ }>;
152
+ resolve: (principal: Principal, sessionId: string, attachmentIds: unknown[]) => Promise<RuntimeAttachment[]>;
153
+ pin: (holder: string, sessionId: string, attachmentIds: string[], kind?: string | undefined) => Promise<void>;
154
+ heldBy: (holders: string[]) => Promise<string[]>;
155
+ authorize: (principal: Principal, attachmentIds: string[], forks?: string[] | undefined) => Promise<void>;
156
+ release: (holder: string) => Promise<void>;
157
+ releaseSessions: (sessionIds: string[]) => Promise<void>;
158
+ reader: {
159
+ open: (attachmentId: string, sessionId: string) => Promise<{
160
+ stream: Readable;
161
+ attachment: RuntimeAttachment;
162
+ }>;
163
+ };
164
+ /** Effective limits, advertised in daemon.hello. */
165
+ limits: AttachmentLimits;
166
+ /** Settles when start-up recovery is done (or failed: the methods then answer 1005). */
167
+ ready: () => Promise<void>;
168
+ /** Usage, for tests and status: bytes reserved and uploads in progress, of one principal or all. */
169
+ usage: (principalId?: string) => {
170
+ bytes: number;
171
+ uploads: number;
172
+ };
173
+ /** The holders of the reference index, for tests. */
174
+ holders: () => Record<string, Holder>;
175
+ close(): Promise<void>;
176
+ };
177
+ /**
178
+ * The operator's attachment limits: `<ALP_HOME>/attachments.json`, `{ "limits": { "<name>": n } }`
179
+ * with names of AttachmentLimits and non-negative integers. They may only lower ATTACHMENTS: a
180
+ * higher value, an unknown name or a bad value is ignored and reported. A missing file is no
181
+ * change; one that cannot be read is reported and ignored (the defaults hold).
182
+ */
183
+ export declare function readAttachmentConfig(home: string): Promise<{
184
+ limits: AttachmentLimitsInput;
185
+ problems: string[];
186
+ }>;
187
+ export {};