@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/dist/files.d.ts CHANGED
@@ -66,6 +66,19 @@ export declare function relativeSegments(relative: unknown): string[];
66
66
  */
67
67
  /** Test probes: called between the checks of a read, where a racing writer could change the file. */
68
68
  export type FileProbe = (step: 'checked' | 'read' | 'listed') => Promise<void> | void;
69
+ /**
70
+ * The bytes of the file at `segments` under the real root `root`, confined as readWorkspaceFile
71
+ * confines a read (every directory on the way a real directory reached by name and the same after
72
+ * the read; the file a regular file with one name, opened without following a link, the same by
73
+ * handle and by name), or `too_large` past `maxBytes`. Throws FileAccessError `linked` or
74
+ * `not_found` (its message names only `relative`). No block list or .gitignore check: the caller
75
+ * decides what may be read (workspace.git.diff, docs/protocol/alp-json-rpc-v1.md §12.5).
76
+ */
77
+ export declare function readConfinedFile(root: string, segments: readonly string[], relative: string, maxBytes: number): Promise<Buffer | 'too_large'>;
78
+ /** Paseo's isLikelyBinary (file-explorer/service.ts at b63a325): a NUL byte, or over 30% control characters. */
79
+ export declare function likelyBinary(buffer: Buffer): boolean;
80
+ /** PEM, OpenSSH and PuTTY private-key headers: a file holding one is refused whatever its name. */
81
+ export declare const PRIVATE_KEY: RegExp;
69
82
  export type ListedEntry = {
70
83
  name: string;
71
84
  path: string;
package/dist/files.js CHANGED
@@ -249,6 +249,18 @@ async function readConfined(file, maxBytes, probe) {
249
249
  await handle.close();
250
250
  }
251
251
  }
252
+ async function readConfinedFile(root, segments, relative, maxBytes) {
253
+ const chain = await directoryChain(root, segments.slice(0, -1), relative);
254
+ let read;
255
+ try {
256
+ read = await readConfined(path.join(root, ...segments), maxBytes);
257
+ } catch (error) {
258
+ if (error.linked) throw linked(relative);
259
+ throw notFound(relative);
260
+ }
261
+ await sameChain(chain, relative);
262
+ return read === void 0 ? "too_large" : read.bytes;
263
+ }
252
264
  function likelyBinary(buffer) {
253
265
  if (!buffer.length) return false;
254
266
  let suspicious = 0;
@@ -341,8 +353,11 @@ export {
341
353
  FilesError,
342
354
  GIT_CHECK2 as GIT_CHECK,
343
355
  LIMITS,
356
+ PRIVATE_KEY,
344
357
  gitChecksRunning,
358
+ likelyBinary,
345
359
  listWorkspaceDirectory,
360
+ readConfinedFile,
346
361
  readWorkspaceFile,
347
362
  relativeSegments,
348
363
  resolveGit,
package/dist/git.d.ts ADDED
@@ -0,0 +1,87 @@
1
+ import type { GitCompare, GitDiffPage, GitStatus } from '@anhlp/alp-protocol';
2
+ /**
3
+ * `workspace.git.status` and `workspace.git.diff` (docs/protocol/alp-json-rpc-v1.md §12.5): the
4
+ * read-only Git state of a registry workspace, for Paseo's branch header and Changes panel.
5
+ *
6
+ * The workspace and its repository configuration are not trusted, so Git runs boxed in:
7
+ * - the Git found on the absolute PATH entries outside the workspace, by its real path
8
+ * (gitignore.ts resolveGit), spawned with an argument list, no shell, in the workspace's real
9
+ * path, its own process group killed at the call's deadline;
10
+ * - GIT_DIR and GIT_WORK_TREE set by alpd to the repository it checked (the workspace's `.git`,
11
+ * validated as the registry validates worktrees: core repositoryIdentity), every other GIT_*
12
+ * variable of alpd's dropped, no system or global configuration, no optional locks, no prompts,
13
+ * no lazy fetch, no replace objects, PATH without the workspace's entries;
14
+ * - configuration overrides so nothing the repository names runs: no fsmonitor, hooks to the null
15
+ * device, no pager, no colour, no external diff or textconv (flags too), every
16
+ * filter.<driver>.{clean,smudge,process} the repository's configuration names emptied and
17
+ * `required` false, no submodule recursion (`--ignore-submodules=dirty`: a gitlink's recorded
18
+ * commit only, never a Git run inside it), no network protocol, `diff.autoRefreshIndex` off (a
19
+ * porcelain `git diff` would otherwise rewrite the index even with GIT_OPTIONAL_LOCKS=0);
20
+ * - `--literal-pathspecs`: a path is never pathspec magic, and always after `--`; a base branch is
21
+ * a validated name resolved only as `refs/remotes/origin/<name>` then `refs/heads/<name>` with
22
+ * `rev-parse --verify --end-of-options`, never a revision expression;
23
+ * - every output read as a stream with a bound; at most GIT_READ.maxConcurrent Git processes at
24
+ * once in alpd.
25
+ * Content alpd shows is checked first: both sides of every file are scanned for a private key
26
+ * (files.ts PRIVATE_KEY), historical and deleted ones included; untracked files are read by alpd
27
+ * itself, confined as workspace.files.read confines a read. Errors carry fixed messages; the
28
+ * cause is logged, never answered.
29
+ */
30
+ export declare const GIT_READ: Readonly<{
31
+ /** One call (all of its Git processes, waiting for a turn included) gets this long. */
32
+ timeoutMs: 15000;
33
+ /** Git processes these reads run at once in alpd, and processes that may wait for one. */
34
+ maxConcurrent: 4;
35
+ maxQueued: 32;
36
+ maxErrorBytes: number;
37
+ /** Configuration, change list and untracked list output, at most. */
38
+ maxListBytes: number;
39
+ /** One patch stream, at most (its files are at most a window's worth of content). */
40
+ maxPatchStreamBytes: number;
41
+ /** One side of a file scanned for a private key; a larger side is `too_large`. */
42
+ maxScanBytes: number;
43
+ /** Files whose content one window reads and diffs together, and their content's total. */
44
+ windowFiles: 64;
45
+ windowBytes: number;
46
+ /** Pathspec bytes on one command line. */
47
+ maxArgBytes: number;
48
+ /** Worktree files whose size and time enter a diff's snapshot. */
49
+ maxSnapshotStats: 5000;
50
+ }>;
51
+ /** A Git read that failed: answered as `1000 git_failed` with a fixed message; `cause` is logged only. */
52
+ export declare class GitReadFailed extends Error {
53
+ readonly cause: string;
54
+ constructor(cause: string);
55
+ }
56
+ /** Git processes these reads run now, for tests. */
57
+ export declare const gitReadsRunning: () => number;
58
+ /** A branch name as `git check-ref-format --branch` accepts one, never starting with '-' (no option, no revision syntax). */
59
+ export declare function validBranchName(name: unknown): name is string;
60
+ /**
61
+ * origin's URL as a client may see it: no user, password or token, no query or fragment; a local
62
+ * path, a `file:` URL or anything unrecognized is null.
63
+ */
64
+ export declare function scrubRemoteUrl(url: string | null): string | null;
65
+ export type GitReaderOptions = {
66
+ registry: {
67
+ resolve(workspaceId: string): Promise<string>;
68
+ };
69
+ /** Which git: a name looked up on PATH (outside the workspace), or an absolute path (tests). */
70
+ binary?: string;
71
+ timeoutMs?: number;
72
+ log?: (message: string, fields: Record<string, unknown>) => void;
73
+ /** Tests only: called after a window's contents were scanned and before Git writes their patch, where a racing writer could change a file. */
74
+ probe?: (step: 'scanned') => Promise<void> | void;
75
+ };
76
+ type DiffParams = {
77
+ workspaceId: string;
78
+ compare: GitCompare;
79
+ path?: string;
80
+ cursor?: string;
81
+ };
82
+ export declare function createGitReader({ registry, binary, timeoutMs, log, probe }: GitReaderOptions): {
83
+ status: (workspaceId: unknown) => Promise<GitStatus>;
84
+ diff: (params: DiffParams) => Promise<GitDiffPage>;
85
+ };
86
+ export type GitReader = ReturnType<typeof createGitReader>;
87
+ export {};