@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.
- package/README.md +4 -0
- package/dist/THIRD-PARTY-NOTICES.txt +26 -1
- package/dist/alpd.js +29928 -14898
- package/dist/attachments.d.ts +187 -0
- package/dist/attachments.js +856 -0
- package/dist/build-manifest.json +34 -1
- package/dist/conversation.d.ts +119 -0
- package/dist/conversation.js +688 -0
- package/dist/disk.d.ts +67 -0
- package/dist/disk.js +152 -0
- package/dist/files.d.ts +154 -2
- package/dist/files.js +392 -68
- package/dist/git.d.ts +93 -0
- package/dist/git.js +1192 -0
- package/dist/gitignore.d.ts +5 -0
- package/dist/gitignore.js +7 -1
- package/dist/history.d.ts +24 -0
- package/dist/history.js +149 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +21 -1
- package/dist/lifecycle.d.ts +101 -0
- package/dist/lifecycle.js +239 -0
- package/dist/main.js +43 -11
- package/dist/native-terminal.d.ts +45 -0
- package/dist/native-terminal.js +198 -0
- package/dist/operations.d.ts +8 -2
- package/dist/operations.js +20 -10
- package/dist/registry.d.ts +89 -0
- package/dist/registry.js +343 -0
- package/dist/scheduler.d.ts +96 -0
- package/dist/scheduler.js +296 -0
- package/dist/schedules.d.ts +70 -0
- package/dist/schedules.js +246 -0
- package/dist/server.d.ts +14 -2
- package/dist/server.js +836 -90
- package/dist/store.d.ts +72 -2
- package/dist/store.js +111 -4
- package/dist/terminal-native/README.md +201 -0
- package/dist/terminal-native/prebuilt/darwin-arm64/manifest.json +11 -0
- package/dist/terminal-native/prebuilt/darwin-arm64/terminal-owner +0 -0
- package/dist/terminal-native/prebuilt/darwin-x64/manifest.json +11 -0
- package/dist/terminal-native/prebuilt/darwin-x64/terminal-owner +0 -0
- package/dist/terminal-native/prebuilt/linux-arm64-glibc/manifest.json +10 -0
- package/dist/terminal-native/prebuilt/linux-arm64-glibc/terminal-owner +0 -0
- package/dist/terminal-native/prebuilt/linux-arm64-musl/manifest.json +10 -0
- package/dist/terminal-native/prebuilt/linux-arm64-musl/terminal-owner +0 -0
- package/dist/terminal-native/prebuilt/linux-x64-glibc/manifest.json +10 -0
- package/dist/terminal-native/prebuilt/linux-x64-glibc/terminal-owner +0 -0
- package/dist/terminal-native/prebuilt/linux-x64-musl/manifest.json +10 -0
- package/dist/terminal-native/prebuilt/linux-x64-musl/terminal-owner +0 -0
- package/dist/terminal-native/terminal-owner.c +389 -0
- package/dist/terminal-screen.d.ts +24 -0
- package/dist/terminal-screen.js +99 -0
- package/dist/terminals.d.ts +193 -0
- package/dist/terminals.js +570 -0
- package/dist/windows-terminal.d.ts +29 -0
- package/dist/windows-terminal.js +122 -0
- package/dist/worktrees.d.ts +65 -0
- package/dist/worktrees.js +318 -0
- package/native/README.md +201 -0
- package/native/prebuilt/darwin-arm64/manifest.json +11 -0
- package/native/prebuilt/darwin-arm64/terminal-owner +0 -0
- package/native/prebuilt/darwin-x64/manifest.json +11 -0
- package/native/prebuilt/darwin-x64/terminal-owner +0 -0
- package/native/prebuilt/linux-arm64-glibc/manifest.json +10 -0
- package/native/prebuilt/linux-arm64-glibc/terminal-owner +0 -0
- package/native/prebuilt/linux-arm64-musl/manifest.json +10 -0
- package/native/prebuilt/linux-arm64-musl/terminal-owner +0 -0
- package/native/prebuilt/linux-x64-glibc/manifest.json +10 -0
- package/native/prebuilt/linux-x64-glibc/terminal-owner +0 -0
- package/native/prebuilt/linux-x64-musl/manifest.json +10 -0
- package/native/prebuilt/linux-x64-musl/terminal-owner +0 -0
- package/native/terminal-owner.c +389 -0
- package/package.json +70 -7
- package/src/attachments.ts +908 -0
- package/src/conversation.ts +857 -0
- package/src/disk.ts +175 -0
- package/src/files.ts +528 -82
- package/src/git.ts +1140 -0
- package/src/gitignore.ts +10 -0
- package/src/history.ts +118 -0
- package/src/index.ts +7 -0
- package/src/lifecycle.ts +283 -0
- package/src/main.ts +37 -12
- package/src/native-terminal.ts +122 -0
- package/src/operations.ts +27 -11
- package/src/registry.ts +238 -0
- package/src/scheduler.ts +432 -0
- package/src/schedules.ts +297 -0
- package/src/server.ts +948 -102
- package/src/store.ts +117 -4
- package/src/terminal-screen.ts +74 -0
- package/src/terminals.ts +641 -0
- package/src/windows-terminal.ts +123 -0
- package/src/worktrees.ts +382 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { nativeTerminalCapability, type CleanupResult } from './native-terminal.js';
|
|
2
|
+
import type { TerminalInfo, TerminalLimits } from '@anhlp/alp-protocol/rpc';
|
|
3
|
+
/**
|
|
4
|
+
* Terminals (capability `terminal`, docs/protocol/alp-json-rpc-v1.md §12.10, issue #121 H): a real
|
|
5
|
+
* PTY running a shell on this host **as the daemon's account**. A workspace chooses only where the
|
|
6
|
+
* shell starts and who sees the terminal; it is not a sandbox. alpd serves terminals only while the
|
|
7
|
+
* host owner opted in (`<ALP_HOME>/terminal.json` `allowRemoteTerminal`, an owner-private file no RPC
|
|
8
|
+
* writes), on macOS and Linux when the shipped native owner validates its capability (Linux may be
|
|
9
|
+
* best-effort `root-only`), and on Windows through node-pty/ConPTY (best-effort, `protection: 'none'`). Lifecycle is audited;
|
|
10
|
+
* input, output and the environment never are.
|
|
11
|
+
*/
|
|
12
|
+
/** Who a call acts for, as for attachments: a gateway's credential and grant epoch, or the owner. */
|
|
13
|
+
export type TerminalPrincipal = {
|
|
14
|
+
id: string;
|
|
15
|
+
epoch: string;
|
|
16
|
+
roots?: readonly string[];
|
|
17
|
+
};
|
|
18
|
+
/** The connection a terminal streams to: alpd's own IPC connection object. */
|
|
19
|
+
export type TerminalSink = {
|
|
20
|
+
send(message: unknown): void;
|
|
21
|
+
socket?: {
|
|
22
|
+
writableLength: number;
|
|
23
|
+
destroyed?: boolean;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
type Disposable = {
|
|
27
|
+
dispose(): void;
|
|
28
|
+
};
|
|
29
|
+
/** Native owner interface; injected owners are used only by tests. */
|
|
30
|
+
export type PtyProcess = {
|
|
31
|
+
pid: number;
|
|
32
|
+
/** The PTY's device (node-pty's UnixTerminal), such as /dev/ttys004 or /dev/pts/3. */
|
|
33
|
+
readonly ptsName?: string;
|
|
34
|
+
write(data: string): void;
|
|
35
|
+
resize(cols: number, rows: number): void;
|
|
36
|
+
kill(signal?: string): void;
|
|
37
|
+
cleanup?: () => Promise<CleanupResult>;
|
|
38
|
+
onData(listener: (data: string) => void): Disposable;
|
|
39
|
+
onExit(listener: (event: {
|
|
40
|
+
exitCode: number | null;
|
|
41
|
+
signal?: number;
|
|
42
|
+
}) => void): Disposable;
|
|
43
|
+
};
|
|
44
|
+
/** Absent: full native protection. root-only: best-effort Linux. none: Windows platform PTY. */
|
|
45
|
+
export type TerminalProtection = 'root-only' | 'none';
|
|
46
|
+
export type PtySpawn = (file: string, args: string[], options: {
|
|
47
|
+
name: string;
|
|
48
|
+
cols: number;
|
|
49
|
+
rows: number;
|
|
50
|
+
cwd: string;
|
|
51
|
+
env: Record<string, string>;
|
|
52
|
+
killGraceMs?: number;
|
|
53
|
+
signal?: AbortSignal;
|
|
54
|
+
protection?: TerminalProtection;
|
|
55
|
+
}) => PtyProcess | Promise<PtyProcess>;
|
|
56
|
+
/** One process: ids, (Linux) session, controlling tty, age, and the terminal markers in its environment. */
|
|
57
|
+
export type ProcessRow = {
|
|
58
|
+
pid: number;
|
|
59
|
+
ppid: number;
|
|
60
|
+
pgid: number;
|
|
61
|
+
sid?: number;
|
|
62
|
+
tty?: string;
|
|
63
|
+
elapsedMs: number;
|
|
64
|
+
markers?: string[];
|
|
65
|
+
};
|
|
66
|
+
type Log = {
|
|
67
|
+
info(message: string, fields?: Record<string, unknown>): void;
|
|
68
|
+
warn(message: string, fields?: Record<string, unknown>): void;
|
|
69
|
+
};
|
|
70
|
+
export type TerminalServiceOptions = {
|
|
71
|
+
home: string;
|
|
72
|
+
/** The canonical directory of a registry workspace, or a RegistryError-like refusal. */
|
|
73
|
+
resolveWorkspace(workspaceId: string): Promise<string>;
|
|
74
|
+
log: Log;
|
|
75
|
+
/** Lower limits (tests, an embedding host); never higher than TERMINAL. */
|
|
76
|
+
limits?: Partial<TerminalLimits>;
|
|
77
|
+
now?: () => number;
|
|
78
|
+
platform?: NodeJS.Platform;
|
|
79
|
+
/** Test hook: the PTY owner; production uses only the identity-bound native owner. */
|
|
80
|
+
spawn?: PtySpawn;
|
|
81
|
+
/** Test hook: capability result; production always verifies the shipped helper. */
|
|
82
|
+
capability?: typeof nativeTerminalCapability;
|
|
83
|
+
/** Test hook: the process table; default `ps`. */
|
|
84
|
+
processes?: () => Promise<ProcessRow[]>;
|
|
85
|
+
sweepMs?: number;
|
|
86
|
+
killGraceMs?: number;
|
|
87
|
+
/** Bytes of terminal events waiting on a connection's socket before it counts as a slow consumer. */
|
|
88
|
+
maxBufferedBytes?: number;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* The host switch and the operator's lower limits. Anything but a regular, owner-private file of
|
|
92
|
+
* this user saying `"allowRemoteTerminal": true` is off.
|
|
93
|
+
*/
|
|
94
|
+
export declare function readTerminalConfig(home: string, log?: Log, platform?: NodeJS.Platform): Promise<{
|
|
95
|
+
enabled: boolean;
|
|
96
|
+
reason?: string;
|
|
97
|
+
limits: TerminalLimits;
|
|
98
|
+
paseo: boolean;
|
|
99
|
+
}>;
|
|
100
|
+
/**
|
|
101
|
+
* The process table: pid, parent, group, (Linux) session, controlling tty, age, and the terminal
|
|
102
|
+
* markers in each process's environment (macOS: `ps -E`, this user's processes only; Linux:
|
|
103
|
+
* /proc/<pid>/environ, readable for this user's processes).
|
|
104
|
+
*/
|
|
105
|
+
export declare function psProcesses(platform?: NodeJS.Platform, options?: {
|
|
106
|
+
/** Controlled filesystem seam; production always reads the actual proc entry asynchronously. */
|
|
107
|
+
readEnvironment?: (pid: number) => Promise<string>;
|
|
108
|
+
}): () => Promise<ProcessRow[]>;
|
|
109
|
+
/** Splits output into frames of at most `max` UTF-8 bytes, never inside a character. */
|
|
110
|
+
export declare function frames(data: string, max: number): string[];
|
|
111
|
+
export declare function createTerminalService(options: TerminalServiceOptions): {
|
|
112
|
+
/** `terminalLimits` for daemon.hello while terminals are served, else undefined. */
|
|
113
|
+
advertised(): Promise<TerminalLimits | undefined>;
|
|
114
|
+
create(principal: TerminalPrincipal, params: {
|
|
115
|
+
workspaceId: string;
|
|
116
|
+
cols: number;
|
|
117
|
+
rows: number;
|
|
118
|
+
requestId: string;
|
|
119
|
+
protectionAcknowledgment?: "linux-root-only-v1";
|
|
120
|
+
}): Promise<{
|
|
121
|
+
terminal: TerminalInfo;
|
|
122
|
+
}>;
|
|
123
|
+
list(principal: TerminalPrincipal, params: {
|
|
124
|
+
workspaceId?: string;
|
|
125
|
+
}): Promise<{
|
|
126
|
+
terminals: TerminalInfo[];
|
|
127
|
+
}>;
|
|
128
|
+
watch(principal: TerminalPrincipal, sink: TerminalSink, params: {
|
|
129
|
+
workspaceId?: string;
|
|
130
|
+
after?: string;
|
|
131
|
+
}): Promise<{
|
|
132
|
+
terminals: TerminalInfo[];
|
|
133
|
+
watchId: string;
|
|
134
|
+
cursor: string;
|
|
135
|
+
reset: boolean;
|
|
136
|
+
}>;
|
|
137
|
+
unwatch(sink: TerminalSink): Promise<{
|
|
138
|
+
closed: true;
|
|
139
|
+
}>;
|
|
140
|
+
capture(principal: TerminalPrincipal, params: {
|
|
141
|
+
terminalId: string;
|
|
142
|
+
start?: number;
|
|
143
|
+
end?: number;
|
|
144
|
+
stripAnsi?: boolean;
|
|
145
|
+
}): Promise<{
|
|
146
|
+
lines: string[];
|
|
147
|
+
totalLines: number;
|
|
148
|
+
}>;
|
|
149
|
+
attach(principal: TerminalPrincipal, sink: TerminalSink, params: {
|
|
150
|
+
terminalId: string;
|
|
151
|
+
after?: number;
|
|
152
|
+
protectionAcknowledgment?: "linux-root-only-v1";
|
|
153
|
+
}): Promise<{
|
|
154
|
+
gap?: {
|
|
155
|
+
fromSeq: number;
|
|
156
|
+
toSeq: number;
|
|
157
|
+
} | undefined;
|
|
158
|
+
terminal: TerminalInfo;
|
|
159
|
+
nextSeq: number;
|
|
160
|
+
}>;
|
|
161
|
+
input(principal: TerminalPrincipal, sink: TerminalSink, params: {
|
|
162
|
+
terminalId: string;
|
|
163
|
+
data: string;
|
|
164
|
+
}): Promise<{
|
|
165
|
+
bytes: number;
|
|
166
|
+
}>;
|
|
167
|
+
resize(principal: TerminalPrincipal, sink: TerminalSink, params: {
|
|
168
|
+
terminalId: string;
|
|
169
|
+
cols: number;
|
|
170
|
+
rows: number;
|
|
171
|
+
}): Promise<{
|
|
172
|
+
cols: number;
|
|
173
|
+
rows: number;
|
|
174
|
+
}>;
|
|
175
|
+
close(principal: TerminalPrincipal, params: {
|
|
176
|
+
terminalId: string;
|
|
177
|
+
}): Promise<{
|
|
178
|
+
closed: true;
|
|
179
|
+
}>;
|
|
180
|
+
/** Every terminal of a principal, any epoch: a gateway's revocation. */
|
|
181
|
+
revoke(principalId: string): Promise<{
|
|
182
|
+
closed: number;
|
|
183
|
+
}>;
|
|
184
|
+
/** A connection closed: its terminals keep running for reconnectMs. */
|
|
185
|
+
disconnect(sink: TerminalSink): void;
|
|
186
|
+
sweep: () => Promise<void>;
|
|
187
|
+
/** alpd stops: every terminal ends (reason `shutdown`) and its tree is killed. */
|
|
188
|
+
shutdown(): Promise<void>;
|
|
189
|
+
/** Test hook: pids of every running terminal's shell. */
|
|
190
|
+
pids(): number[];
|
|
191
|
+
};
|
|
192
|
+
export type TerminalService = ReturnType<typeof createTerminalService>;
|
|
193
|
+
export {};
|