@anhlp/alp-cli 0.0.0-beta.1 → 0.0.1-beta.10
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/dist/THIRD-PARTY-NOTICES.txt +52 -2
- package/dist/acp/agent.d.ts +11 -3
- package/dist/acp/agent.js +118 -19
- package/dist/acp/main.js +1 -1
- package/dist/acp.js +7898 -2238
- package/dist/alp-dashboard/THIRD-PARTY-NOTICES.txt +3256 -0
- package/dist/alp-dashboard/alp-boundary.json +16 -0
- package/dist/alp-dashboard/apple-touch-icon.png +0 -0
- package/dist/alp-dashboard/assets/TerminalPanel-D8HE9XBX.js +22 -0
- package/dist/alp-dashboard/assets/TerminalPanel-DLuoa74B.css +1 -0
- package/dist/alp-dashboard/assets/highlighter-BnicKQ_d.js +18 -0
- package/dist/alp-dashboard/assets/index-DwqDSiIi.css +1 -0
- package/dist/alp-dashboard/assets/index-YdtH3NBy.js +59 -0
- package/dist/alp-dashboard/favicon-attention.svg +6 -0
- package/dist/alp-dashboard/favicon-running.svg +6 -0
- package/dist/alp-dashboard/favicon.svg +5 -0
- package/dist/alp-dashboard/index.html +20 -0
- package/dist/alp-dashboard.js +10165 -0
- package/dist/alpd.js +39994 -16997
- package/dist/backup.js +2 -2
- package/dist/build-manifest.json +142 -3
- package/dist/cli.js +40 -6
- package/dist/daemon.d.ts +3 -3
- package/dist/daemon.js +16 -7
- package/dist/dashboard-migrate.d.ts +31 -0
- package/dist/dashboard-migrate.js +127 -0
- package/dist/dashboard-service.d.ts +69 -0
- package/dist/dashboard-service.js +141 -0
- package/dist/desktop.d.ts +56 -0
- package/dist/desktop.js +91 -0
- package/dist/interfaces.d.ts +23 -3
- package/dist/interfaces.js +277 -41
- package/dist/library.d.ts +16 -2
- package/dist/library.js +114 -7
- package/dist/paths.d.ts +6 -0
- package/dist/paths.js +4 -1
- package/dist/projects.js +2 -1
- package/dist/roles.d.ts +15 -0
- package/dist/roles.js +16 -0
- package/dist/schedules.d.ts +2 -0
- package/dist/schedules.js +45 -0
- package/dist/self-update.d.ts +151 -0
- package/dist/self-update.js +422 -0
- package/dist/sessions.d.ts +9 -2
- package/dist/sessions.js +67 -13
- package/dist/tasks.js +22 -8
- 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.d.ts +13 -0
- package/dist/terminal.js +80 -0
- package/dist/usage.d.ts +1 -1
- package/dist/usage.js +31 -9
- package/package.json +11 -4
- package/src/acp/agent.ts +111 -20
- package/src/backup.js +1 -1
- package/src/cli.js +51 -6
- package/src/daemon.js +18 -9
- package/src/dashboard-migrate.js +152 -0
- package/src/dashboard-service.js +192 -0
- package/src/desktop.js +122 -0
- package/src/interfaces.js +345 -38
- package/src/library.js +108 -9
- package/src/paths.js +9 -1
- package/src/projects.js +3 -1
- package/src/roles.js +26 -0
- package/src/schedules.js +38 -0
- package/src/self-update.js +443 -0
- package/src/sessions.js +60 -16
- package/src/tasks.js +22 -8
- package/src/terminal.js +78 -0
- package/src/usage.js +31 -9
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
/* ALP terminal owner protocol 1. Native-only spawn, lifetime acquisition, signals and reap.
|
|
2
|
+
* Linux reduced-protection mode signals only its continuously owned unreaped root. See README.md for proof obligations and platform limits. */
|
|
3
|
+
#define _GNU_SOURCE
|
|
4
|
+
#include <sys/types.h>
|
|
5
|
+
#include <sys/wait.h>
|
|
6
|
+
#include <sys/ioctl.h>
|
|
7
|
+
#include <sys/stat.h>
|
|
8
|
+
#include <poll.h>
|
|
9
|
+
#include <fcntl.h>
|
|
10
|
+
#include <signal.h>
|
|
11
|
+
#include <stdint.h>
|
|
12
|
+
#include <stdio.h>
|
|
13
|
+
#include <stdlib.h>
|
|
14
|
+
#include <string.h>
|
|
15
|
+
#include <errno.h>
|
|
16
|
+
#include <unistd.h>
|
|
17
|
+
#include <time.h>
|
|
18
|
+
#ifdef __APPLE__
|
|
19
|
+
#include <util.h>
|
|
20
|
+
#include <libproc.h>
|
|
21
|
+
#include <mach/mach.h>
|
|
22
|
+
#include <mach/mach_traps.h>
|
|
23
|
+
#include <mach/task_info.h>
|
|
24
|
+
/* Approved private ABI, XNU xnu-12377.1.9 bsd/sys/proc_info_private.h, flavor17.
|
|
25
|
+
* Keep the complete 56-byte layout; parent identity is NEVER adoption authority. */
|
|
26
|
+
struct uniqinfo { uint8_t uuid[16]; uint64_t unique, parent; int32_t version, original_parent_version; uint64_t reserved[2]; };
|
|
27
|
+
_Static_assert(sizeof(struct uniqinfo) == 56, "private ABI size");
|
|
28
|
+
#else
|
|
29
|
+
#include <pty.h>
|
|
30
|
+
#include <dirent.h>
|
|
31
|
+
#include <sys/syscall.h>
|
|
32
|
+
#include <sys/vfs.h>
|
|
33
|
+
#include <linux/magic.h>
|
|
34
|
+
#endif
|
|
35
|
+
#define MAX_TRACKED 4096
|
|
36
|
+
#define QUEUE (1024 * 1024)
|
|
37
|
+
#ifndef START_TIMEOUT_MS
|
|
38
|
+
#define START_TIMEOUT_MS 3000
|
|
39
|
+
#endif
|
|
40
|
+
typedef struct {
|
|
41
|
+
pid_t pid;
|
|
42
|
+
#ifdef __APPLE__
|
|
43
|
+
uint64_t unique;
|
|
44
|
+
#else
|
|
45
|
+
int fd;
|
|
46
|
+
#endif
|
|
47
|
+
} identity;
|
|
48
|
+
static identity known[MAX_TRACKED];
|
|
49
|
+
static size_t count;
|
|
50
|
+
static pid_t root;
|
|
51
|
+
static int scanning_failed, held = 1;
|
|
52
|
+
#ifndef __APPLE__
|
|
53
|
+
static int root_only, compatibility_available;
|
|
54
|
+
/* Exclusive natural parent retains this child (live or WNOWAIT zombie).
|
|
55
|
+
* ECHILD revokes authority permanently; never infer ownership from a PID lookup. */
|
|
56
|
+
static int root_status(void) {
|
|
57
|
+
if (!held || root <= 1) return 2;
|
|
58
|
+
siginfo_t info = {0}; int result;
|
|
59
|
+
do { result=waitid(P_PID,root,&info,WEXITED|WNOHANG|WNOWAIT); } while(result<0 && errno==EINTR);
|
|
60
|
+
if(result<0) { if(errno==ECHILD) held=0; return 2; }
|
|
61
|
+
return info.si_pid==root ? 0 : 1;
|
|
62
|
+
}
|
|
63
|
+
#endif
|
|
64
|
+
static long long clock_ms(void) { struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); return (long long)t.tv_sec*1000+t.tv_nsec/1000000; }
|
|
65
|
+
static void event(const char *s) { (void)!write(3, s, strlen(s)); }
|
|
66
|
+
#ifdef __APPLE__
|
|
67
|
+
static int unique(pid_t p, struct uniqinfo *u) { memset(u, 0, sizeof(*u)); errno = 0; return proc_pidinfo(p, 17, 0, u, sizeof(*u)) == sizeof(*u) && u->unique != 0; }
|
|
68
|
+
static int token(pid_t p, audit_token_t *t) {
|
|
69
|
+
mach_port_t task = MACH_PORT_NULL;
|
|
70
|
+
if (task_name_for_pid(mach_task_self(), p, &task) != KERN_SUCCESS) return 0;
|
|
71
|
+
mach_msg_type_number_t n = TASK_AUDIT_TOKEN_COUNT;
|
|
72
|
+
kern_return_t r = task_info(task, TASK_AUDIT_TOKEN, (task_info_t)t, &n);
|
|
73
|
+
mach_port_deallocate(mach_task_self(), task);
|
|
74
|
+
return r == KERN_SUCCESS && n == TASK_AUDIT_TOKEN_COUNT && t->val[5] == (uint32_t)p;
|
|
75
|
+
}
|
|
76
|
+
static int acquire(pid_t p, identity *out, int session) {
|
|
77
|
+
struct uniqinfo a, b; audit_token_t t;
|
|
78
|
+
if (!held || !unique(p, &a)) return 0;
|
|
79
|
+
if (session && getsid(p) != root) return 0;
|
|
80
|
+
if (!token(p, &t) || !unique(p, &b) || a.unique != b.unique || t.val[7] != (uint32_t)b.version) return 0;
|
|
81
|
+
out->pid = p; out->unique = a.unique; return 1;
|
|
82
|
+
}
|
|
83
|
+
/* 0 exited, 1 live, 2 uncertain. Never infer live from a failed task-port lookup. */
|
|
84
|
+
static int status(identity *id) {
|
|
85
|
+
if (id->pid == root) { siginfo_t info = {0}; if (waitid(P_PID, root, &info, WEXITED|WNOHANG|WNOWAIT) == 0 && info.si_pid == root) return 0; }
|
|
86
|
+
struct uniqinfo u; if (!unique(id->pid, &u)) return errno == ESRCH ? 0 : 2;
|
|
87
|
+
if (u.unique != id->unique) return 0;
|
|
88
|
+
struct proc_bsdinfo b;
|
|
89
|
+
if (proc_pidinfo(id->pid, PROC_PIDTBSDINFO, 0, &b, sizeof(b)) != sizeof(b)) return 2;
|
|
90
|
+
struct uniqinfo after; if (!unique(id->pid, &after)) return errno == ESRCH ? 0 : 2;
|
|
91
|
+
if (after.unique != id->unique) return 0;
|
|
92
|
+
return b.pbi_status == 5 /* SZOMB */ ? 0 : 1;
|
|
93
|
+
}
|
|
94
|
+
static void bound_signal(identity *id, int sig) {
|
|
95
|
+
for (int tries = 0; tries < 4; tries++) {
|
|
96
|
+
identity fresh; audit_token_t t; struct uniqinfo u;
|
|
97
|
+
if (!acquire(id->pid, &fresh, 0) || fresh.unique != id->unique || !token(id->pid, &t) || !unique(id->pid, &u) || u.unique != id->unique || t.val[7] != (uint32_t)u.version) continue;
|
|
98
|
+
int r = proc_signal_with_audittoken(&t, sig);
|
|
99
|
+
if (r == 0 || r != ESRCH) return;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
static void remember(pid_t p) {
|
|
103
|
+
identity id;
|
|
104
|
+
if (!acquire(p, &id, 1)) return;
|
|
105
|
+
for (size_t i=0; i<count; i++) if (known[i].unique == id.unique) return;
|
|
106
|
+
if (count == MAX_TRACKED) { scanning_failed = 1; return; }
|
|
107
|
+
known[count++] = id;
|
|
108
|
+
}
|
|
109
|
+
static void discover(void) {
|
|
110
|
+
if (!held) return;
|
|
111
|
+
int bytes = proc_listallpids(NULL, 0);
|
|
112
|
+
if (bytes <= 0 || bytes > 1024*1024) { scanning_failed = 1; return; }
|
|
113
|
+
/* proc_listallpids(NULL) returns estimated process COUNT, not bytes. */
|
|
114
|
+
size_t capacity = (size_t)bytes + 256;
|
|
115
|
+
pid_t *pids = calloc(capacity, sizeof(pid_t));
|
|
116
|
+
if (!pids) { scanning_failed = 1; return; }
|
|
117
|
+
int n = proc_listallpids(pids, (int)(capacity*sizeof(pid_t)));
|
|
118
|
+
if (n < 0 || (size_t)n >= capacity) scanning_failed = 1;
|
|
119
|
+
else for (int i=0; i<n; i++) if (pids[i]>1) remember(pids[i]);
|
|
120
|
+
free(pids);
|
|
121
|
+
}
|
|
122
|
+
static int capability(void) {
|
|
123
|
+
struct uniqinfo a, b; audit_token_t t;
|
|
124
|
+
return unique(getpid(), &a) && token(getpid(), &t) && unique(getpid(), &b) && a.unique == b.unique && t.val[7] == (uint32_t)b.version;
|
|
125
|
+
}
|
|
126
|
+
#else
|
|
127
|
+
static int pid_signal(int fd, int sig) { return (int)syscall(SYS_pidfd_send_signal, fd, sig, NULL, 0); }
|
|
128
|
+
static int proc_stat(int dir, pid_t *sid, char *state) {
|
|
129
|
+
int f = openat(dir, "stat", O_RDONLY|O_CLOEXEC); if (f < 0) return 0;
|
|
130
|
+
char buf[8192]; ssize_t n = read(f, buf, sizeof(buf)-1); int saved=errno; close(f); errno=saved;
|
|
131
|
+
if (n <= 0) { if(n==0) errno=EIO; return 0; } buf[n]=0;
|
|
132
|
+
char *end = strrchr(buf, ')'); int pp, pg, s;
|
|
133
|
+
if (!end || sscanf(end+1, " %c %d %d %d", state, &pp, &pg, &s) != 4) { errno=EIO; return 0; }
|
|
134
|
+
*sid = (pid_t)s; return 1;
|
|
135
|
+
}
|
|
136
|
+
static int acquire(pid_t p, identity *out, int session) {
|
|
137
|
+
if(root_only) { if(p!=root || root_status()==2) return 0; out->pid=root; out->fd=-1; return 1; }
|
|
138
|
+
if (!held) return 0;
|
|
139
|
+
char name[64]; snprintf(name, sizeof(name), "/proc/%d", p);
|
|
140
|
+
int f=open(name, O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW); if (f<0) return 0;
|
|
141
|
+
pid_t sid; char state;
|
|
142
|
+
if (!proc_stat(f, &sid, &state) || (session && sid != root)) { close(f); return 0; }
|
|
143
|
+
out->pid=p; out->fd=f; return 1;
|
|
144
|
+
}
|
|
145
|
+
static int status(identity *id) {
|
|
146
|
+
if(root_only) return id->pid==root ? root_status() : 2;
|
|
147
|
+
pid_t sid; char state;
|
|
148
|
+
if (!proc_stat(id->fd, &sid, &state)) return errno == ENOENT || errno == ESRCH ? 0 : 2;
|
|
149
|
+
return state == 'Z' || state == 'X' ? 0 : 1;
|
|
150
|
+
}
|
|
151
|
+
static void bound_signal(identity *id, int sig) {
|
|
152
|
+
if(root_only) {
|
|
153
|
+
if(id->pid!=root || root_status()!=1) return;
|
|
154
|
+
/* No reap between waitid and kill: root PID remains continuously reserved. */
|
|
155
|
+
int r; do { r=kill(root,sig); } while(r<0 && errno==EINTR);
|
|
156
|
+
if(r<0 && errno!=ESRCH) scanning_failed=1;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
(void)pid_signal(id->fd, sig);
|
|
160
|
+
}
|
|
161
|
+
static void remember(pid_t p) {
|
|
162
|
+
identity id;
|
|
163
|
+
if (!acquire(p, &id, 1)) return;
|
|
164
|
+
struct stat st, old; if (fstat(id.fd,&st)) { close(id.fd); scanning_failed=1; return; }
|
|
165
|
+
for (size_t i=0;i<count;i++) if (!fstat(known[i].fd,&old) && old.st_dev==st.st_dev && old.st_ino==st.st_ino) { close(id.fd); return; }
|
|
166
|
+
if (count==MAX_TRACKED) { scanning_failed=1; close(id.fd); return; }
|
|
167
|
+
known[count++]=id;
|
|
168
|
+
}
|
|
169
|
+
static void discover(void) {
|
|
170
|
+
if (root_only || !held) return;
|
|
171
|
+
DIR *d=opendir("/proc"); if (!d) { scanning_failed=1; return; }
|
|
172
|
+
struct dirent *e;
|
|
173
|
+
while ((e=readdir(d))) { char *end; long p=strtol(e->d_name,&end,10); if (*e->d_name && !*end && p>1 && p<=INT32_MAX) remember((pid_t)p); }
|
|
174
|
+
closedir(d);
|
|
175
|
+
}
|
|
176
|
+
static int capability(void) {
|
|
177
|
+
compatibility_available=0;
|
|
178
|
+
/* Reject a proc mount in a different PID namespace (including numeric aliases).
|
|
179
|
+
* The mount must be kernel procfs; /proc/self must report our local PID and SID. */
|
|
180
|
+
int self=open("/proc/self",O_RDONLY|O_DIRECTORY|O_CLOEXEC);
|
|
181
|
+
if(self<0) return 0;
|
|
182
|
+
struct statfs fs; pid_t sid; char state;
|
|
183
|
+
int statfd=openat(self,"stat",O_RDONLY|O_CLOEXEC); char buf[128]={0};
|
|
184
|
+
ssize_t n=statfd<0?-1:read(statfd,buf,sizeof(buf)-1);
|
|
185
|
+
if(statfd>=0) close(statfd);
|
|
186
|
+
/* NSpid lists PIDs from the procfs PID namespace down to ours: exactly one field
|
|
187
|
+
* proves this procfs is our active namespace (ancestor procfs => more fields;
|
|
188
|
+
* unrelated procfs => no /proc/self). Needs no access to PID1; missing => deny. */
|
|
189
|
+
int nspid_ok=0; int statusfd=openat(self,"status",O_RDONLY|O_CLOEXEC);
|
|
190
|
+
if(statusfd>=0) {
|
|
191
|
+
static char st[16384]; size_t len=0; ssize_t k;
|
|
192
|
+
while(len<sizeof(st)-1 && ((k=read(statusfd,st+len,sizeof(st)-1-len))>0 || (k<0 && errno==EINTR))) if(k>0) len+=(size_t)k;
|
|
193
|
+
close(statusfd); st[len]=0;
|
|
194
|
+
char *line=strstr(st,"\nNSpid:");
|
|
195
|
+
if(line && len<sizeof(st)-1) {
|
|
196
|
+
line+=7; char *eol=strchr(line,'\n');
|
|
197
|
+
if(eol) { *eol=0; int fields=0; long v=0; char *q=line, *end;
|
|
198
|
+
for(;;) { while(*q==' '||*q=='\t') q++; if(!*q) break; errno=0; long x=strtol(q,&end,10); if(end==q||errno||(*end&&*end!=' '&&*end!='\t')) { fields=-1; break; } v=x; fields++; q=end; }
|
|
199
|
+
nspid_ok=fields==1 && v==getpid(); }
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
char link[32]; ssize_t ln=readlink("/proc/self",link,sizeof(link)-1);
|
|
203
|
+
int link_ok=ln>0 && (link[ln]=0, strtol(link,NULL,10)==getpid());
|
|
204
|
+
int namespace_ok=nspid_ok && link_ok && n>0 && strtol(buf,NULL,10)==getpid() && !fstatfs(self,&fs) && fs.f_type==PROC_SUPER_MAGIC && proc_stat(self,&sid,&state) && sid==getsid(0);
|
|
205
|
+
close(self); if(!namespace_ok) return 0;
|
|
206
|
+
identity id; pid_t saved=root; root=getsid(0);
|
|
207
|
+
int ok=acquire(getpid(), &id, 1); root=saved;
|
|
208
|
+
if (!ok) return 0;
|
|
209
|
+
int r=pid_signal(id.fd, 0); close(id.fd);
|
|
210
|
+
return r==0;
|
|
211
|
+
}
|
|
212
|
+
#endif
|
|
213
|
+
static void signal_all(int sig) { for (size_t i=0;i<count;i++) if (status(&known[i]) != 0) bound_signal(&known[i], sig); }
|
|
214
|
+
static void nonblock(int f) { int flags=fcntl(f,F_GETFL); if(flags>=0) fcntl(f,F_SETFL,flags|O_NONBLOCK); }
|
|
215
|
+
static void close_extra(void) {
|
|
216
|
+
#ifdef __APPLE__
|
|
217
|
+
int n = getdtablesize();
|
|
218
|
+
for(int i=3;i<n;i++) close(i);
|
|
219
|
+
#else
|
|
220
|
+
long n=sysconf(_SC_OPEN_MAX); if(n<0) n=65536;
|
|
221
|
+
for(int i=3;i<n;i++) close(i);
|
|
222
|
+
#endif
|
|
223
|
+
}
|
|
224
|
+
/* Startup failure owns the unreaped root but must never wait indefinitely.
|
|
225
|
+
* Gate EOF prevents exec. All optional signals still use a verified identity. */
|
|
226
|
+
static int abort_start(int master, int gate) {
|
|
227
|
+
close(gate);
|
|
228
|
+
identity id;
|
|
229
|
+
if(acquire(root,&id,0)) {
|
|
230
|
+
bound_signal(&id,SIGKILL);
|
|
231
|
+
#ifndef __APPLE__
|
|
232
|
+
if(id.fd>=0) close(id.fd);
|
|
233
|
+
#endif
|
|
234
|
+
}
|
|
235
|
+
long long deadline=clock_ms()+250; int reaped=0;
|
|
236
|
+
do {
|
|
237
|
+
siginfo_t info={0};
|
|
238
|
+
if(waitid(P_PID,root,&info,WEXITED|WNOHANG|WNOWAIT)==0 && info.si_pid==root) { int r; do { r=waitpid(root,NULL,WNOHANG); } while(r<0 && errno==EINTR); reaped=r==root; break; }
|
|
239
|
+
usleep(1000);
|
|
240
|
+
} while(clock_ms()<deadline);
|
|
241
|
+
held=0; close(master);
|
|
242
|
+
event("{\"error\":\"native_identity_unavailable\"}\n");
|
|
243
|
+
char message[160]; snprintf(message,sizeof(message),"{\"cleanup\":true,\"observed\":1,\"live\":0,\"uncertain\":%d}\n",reaped?0:1); event(message);
|
|
244
|
+
return 78;
|
|
245
|
+
}
|
|
246
|
+
/* A termination signal (e.g. one sent to the daemon's process group) must start
|
|
247
|
+
* bound cleanup, not kill the owner before it reaps the session it owns. */
|
|
248
|
+
static volatile sig_atomic_t stop_requested=0;
|
|
249
|
+
static void request_stop(int sig) { (void)sig; stop_requested=1; }
|
|
250
|
+
int main(int argc, char **argv) {
|
|
251
|
+
signal(SIGPIPE,SIG_IGN);
|
|
252
|
+
struct sigaction stop_action; memset(&stop_action,0,sizeof(stop_action));
|
|
253
|
+
stop_action.sa_handler=request_stop; sigemptyset(&stop_action.sa_mask);
|
|
254
|
+
if(sigaction(SIGTERM,&stop_action,NULL) || sigaction(SIGINT,&stop_action,NULL) || sigaction(SIGHUP,&stop_action,NULL)) return 71;
|
|
255
|
+
struct sigaction child_action; memset(&child_action,0,sizeof(child_action));
|
|
256
|
+
child_action.sa_handler=SIG_DFL; sigemptyset(&child_action.sa_mask);
|
|
257
|
+
if(sigaction(SIGCHLD,&child_action,NULL)) return 71;
|
|
258
|
+
int capable=capability();
|
|
259
|
+
#ifndef __APPLE__
|
|
260
|
+
/* Linux is best-effort (user decision 2026-10-29): when identity-bound protection is
|
|
261
|
+
* unavailable for any reason, offer root-only compatibility, which only signals the
|
|
262
|
+
* unreaped session root and never trusts procfs or pidfd. The caller discloses it. */
|
|
263
|
+
compatibility_available=!capable;
|
|
264
|
+
#endif
|
|
265
|
+
#ifndef __APPLE__
|
|
266
|
+
if(argc==2 && !strcmp(argv[1],"--capability") && compatibility_available) { puts("alp-terminal-owner:1:root-only"); return 0; }
|
|
267
|
+
if(argc>1 && !strcmp(argv[1],"--root-only")) { root_only=1; argc--; argv++; }
|
|
268
|
+
if(argc>=6 && ((root_only && !compatibility_available) || (!root_only && !capable && compatibility_available))) {
|
|
269
|
+
event(!root_only ? "{\"refused\":\"terminal_protection_ack_required\"}\n" : "{\"refused\":\"terminal_unsupported\"}\n");
|
|
270
|
+
event("{\"cleanup\":true,\"observed\":0,\"live\":0,\"uncertain\":0}\n"); return 78;
|
|
271
|
+
}
|
|
272
|
+
#endif
|
|
273
|
+
if (argc==2 && !strcmp(argv[1],"--capability")) { if (!capable) return 78; puts("alp-terminal-owner:1"); return 0; }
|
|
274
|
+
if (argc<6 || (!capable
|
|
275
|
+
#ifndef __APPLE__
|
|
276
|
+
&& !(root_only && compatibility_available)
|
|
277
|
+
#endif
|
|
278
|
+
)) { event("{\"refused\":\"terminal_unsupported\"}\n"); event("{\"cleanup\":true,\"observed\":0,\"live\":0,\"uncertain\":0}\n"); return 78; }
|
|
279
|
+
int cols=atoi(argv[1]),rows=atoi(argv[2]),grace=atoi(argv[3]);
|
|
280
|
+
if(cols<1 || cols>1000 || rows<1 || rows>1000 || grace<0 || grace>10000) return 64;
|
|
281
|
+
unsigned char *out=malloc(QUEUE),*input=malloc(QUEUE);
|
|
282
|
+
if(!out || !input) { free(out); free(input); return 71; }
|
|
283
|
+
int gate[2],started[2]; if(pipe(gate)||pipe(started)) return 71;
|
|
284
|
+
struct winsize ws={.ws_col=(unsigned short)cols,.ws_row=(unsigned short)rows}; int master;
|
|
285
|
+
root=forkpty(&master,NULL,NULL,&ws);
|
|
286
|
+
if (root<0) return 71;
|
|
287
|
+
if (!root) {
|
|
288
|
+
/* The owner's stop handlers must not swallow a hang-up before exec. */
|
|
289
|
+
signal(SIGTERM,SIG_DFL); signal(SIGINT,SIG_DFL); signal(SIGHUP,SIG_DFL);
|
|
290
|
+
close(gate[1]); close(started[0]);
|
|
291
|
+
char ready=getsid(0)==getpid()?'S':'E';
|
|
292
|
+
if(write(started[1],&ready,1)!=1) _exit(126);
|
|
293
|
+
char release=0; if(read(gate[0],&release,1)!=1 || release!='G' || ready!='S') _exit(126);
|
|
294
|
+
close_extra(); signal(SIGPIPE,SIG_DFL);
|
|
295
|
+
if(chdir(argv[4])) _exit(126);
|
|
296
|
+
execv(argv[5],&argv[5]); _exit(127);
|
|
297
|
+
}
|
|
298
|
+
close(gate[0]); close(started[1]); char ready=0;
|
|
299
|
+
struct pollfd startup[3]={{started[0],POLLIN,0},{0,0,0},{4,POLLIN,0}};
|
|
300
|
+
int available=poll(startup,3,START_TIMEOUT_MS);
|
|
301
|
+
int startok=available>0 && !(startup[1].revents&(POLLHUP|POLLERR)) && !(startup[2].revents&(POLLIN|POLLHUP|POLLERR)) && (startup[0].revents&POLLIN) && read(started[0],&ready,1)==1 && ready=='S';
|
|
302
|
+
close(started[0]);
|
|
303
|
+
identity first;
|
|
304
|
+
if(!startok || !acquire(root,&first,1)) return abort_start(master,gate[1]);
|
|
305
|
+
known[count++]=first;
|
|
306
|
+
if(write(gate[1],"G",1)!=1) return abort_start(master,gate[1]);
|
|
307
|
+
close(gate[1]);
|
|
308
|
+
char msg[256]; snprintf(msg,sizeof(msg),"{\"ready\":%d,\"protocol\":1}\n",root); event(msg);
|
|
309
|
+
nonblock(master); nonblock(0); nonblock(1); nonblock(4);
|
|
310
|
+
size_t outn=0,inn=0; char commands[256]; size_t cn=0;
|
|
311
|
+
int cleaning=0, root_notified=0, code=0, sig=0, io_failed=0; long long start=0, lastscan=0;
|
|
312
|
+
for (;;) {
|
|
313
|
+
long long now=clock_ms();
|
|
314
|
+
if(now-lastscan>=20) { discover(); lastscan=now; }
|
|
315
|
+
siginfo_t info={0};
|
|
316
|
+
if(!root_notified && waitid(P_PID,root,&info,WEXITED|WNOHANG|WNOWAIT)==0 && info.si_pid==root) {
|
|
317
|
+
root_notified=1; code=info.si_code==CLD_EXITED?info.si_status:0; sig=info.si_code==CLD_EXITED?0:info.si_status;
|
|
318
|
+
snprintf(msg,sizeof(msg),"{\"exitCode\":%d,\"signal\":%d}\n",code,sig); event(msg); cleaning=cleaning?cleaning:1;
|
|
319
|
+
}
|
|
320
|
+
if((io_failed || stop_requested) && !cleaning) cleaning=1;
|
|
321
|
+
if(cleaning==1) { start=now; discover(); signal_all(SIGHUP); cleaning=2; }
|
|
322
|
+
if(cleaning>=2 && now-start>=grace) { discover(); signal_all(SIGKILL); cleaning=3; }
|
|
323
|
+
if(cleaning==3 && now-start>=grace+250) break;
|
|
324
|
+
struct pollfd fds[4]={{0,inn<QUEUE?POLLIN:0,0},{master,(short)((outn<QUEUE?POLLIN:0)|(inn?POLLOUT:0)),0},{1,outn?POLLOUT:0,0},{4,POLLIN,0}};
|
|
325
|
+
if(poll(fds,4,10)<0 && errno!=EINTR) { io_failed=1; continue; }
|
|
326
|
+
if(fds[0].revents&POLLIN) { ssize_t n=read(0,input+inn,QUEUE-inn); if(n>0) inn+=(size_t)n; else if(n==0) cleaning=cleaning?cleaning:1; }
|
|
327
|
+
if(fds[0].revents&(POLLHUP|POLLERR)) cleaning=cleaning?cleaning:1;
|
|
328
|
+
if(fds[1].revents&POLLIN) { ssize_t n=read(master,out+outn,QUEUE-outn); if(n>0) outn+=(size_t)n; }
|
|
329
|
+
if(fds[1].revents&POLLOUT) { ssize_t n=write(master,input,inn); if(n>0) {inn-=(size_t)n;memmove(input,input+n,inn);} }
|
|
330
|
+
if(fds[2].revents&POLLOUT) { ssize_t n=write(1,out,outn); if(n>0) {outn-=(size_t)n;memmove(out,out+n,outn);} else if(errno!=EAGAIN&&errno!=EINTR) io_failed=1; }
|
|
331
|
+
if(fds[2].revents&(POLLHUP|POLLERR)) io_failed=1;
|
|
332
|
+
if(fds[3].revents&POLLIN) {
|
|
333
|
+
char b[128]; ssize_t n=read(4,b,sizeof(b));
|
|
334
|
+
for(ssize_t i=0;i<n;i++) { if(b[i]=='\n') { commands[cn]=0; int c,r; if(!strcmp(commands,"C")) cleaning=cleaning?cleaning:1; else if(sscanf(commands,"R %d %d",&c,&r)==2 && c>0&&c<=1000&&r>0&&r<=1000) { ws.ws_col=(unsigned short)c;ws.ws_row=(unsigned short)r; ioctl(master,TIOCSWINSZ,&ws); } cn=0; } else if(cn<sizeof(commands)-1) commands[cn++]=b[i]; else {io_failed=1;cn=0;} }
|
|
335
|
+
}
|
|
336
|
+
if(fds[3].revents&(POLLHUP|POLLERR)) cleaning=cleaning?cleaning:1;
|
|
337
|
+
}
|
|
338
|
+
/* Last scan and verification happen BEFORE final root reap: SID still reserved. */
|
|
339
|
+
discover(); signal_all(SIGKILL); usleep(20000);
|
|
340
|
+
int live=0,uncertain=scanning_failed;
|
|
341
|
+
for(size_t i=0;i<count;i++) { int s=status(&known[i]); if(s==1) live++; else if(s==2) uncertain++; }
|
|
342
|
+
siginfo_t final={0};
|
|
343
|
+
if(waitid(P_PID,root,&final,WEXITED|WNOHANG|WNOWAIT)==0 && final.si_pid==root) {
|
|
344
|
+
int reaped; do { reaped=waitpid(root,NULL,WNOHANG); } while(reaped<0 && errno==EINTR);
|
|
345
|
+
if(reaped!=root) uncertain++;
|
|
346
|
+
held=0;
|
|
347
|
+
} else { /* Never blocking reap of a live/unverifiable root; no adoption after this point. */
|
|
348
|
+
held=0; uncertain++;
|
|
349
|
+
}
|
|
350
|
+
/* Drain all remaining PTY output and queued bytes, advancing partial writes.
|
|
351
|
+
* A stalled consumer cannot retain an owner indefinitely: undrained output is
|
|
352
|
+
* explicit uncertainty, NEVER a successful silent tail discard. No discovery
|
|
353
|
+
* or signals occur after final root reap above. */
|
|
354
|
+
long long drain_deadline=clock_ms()+1000; int master_eof=0;
|
|
355
|
+
while((!master_eof || outn) && clock_ms()<drain_deadline) {
|
|
356
|
+
struct pollfd drain[2]={{master,(!master_eof && outn<QUEUE)?POLLIN:0,0},{1,outn?POLLOUT:0,0}};
|
|
357
|
+
if(poll(drain,2,10)<0) { if(errno==EINTR) continue; io_failed=1; break; }
|
|
358
|
+
if(!master_eof && outn<QUEUE && (drain[0].revents&(POLLIN|POLLHUP|POLLERR))) {
|
|
359
|
+
ssize_t n=read(master,out+outn,QUEUE-outn);
|
|
360
|
+
if(n>0) outn+=(size_t)n;
|
|
361
|
+
else if(n==0 || errno==EIO) master_eof=1;
|
|
362
|
+
else if(errno!=EAGAIN && errno!=EINTR) { io_failed=1; master_eof=1; }
|
|
363
|
+
}
|
|
364
|
+
if(outn && (drain[1].revents&POLLOUT)) {
|
|
365
|
+
ssize_t n=write(1,out,outn);
|
|
366
|
+
if(n>0) { outn-=(size_t)n; memmove(out,out+n,outn); }
|
|
367
|
+
else if(errno!=EAGAIN && errno!=EINTR) { io_failed=1; break; }
|
|
368
|
+
}
|
|
369
|
+
if(drain[1].revents&(POLLHUP|POLLERR)) { io_failed=1; break; }
|
|
370
|
+
}
|
|
371
|
+
int limited_coverage=0;
|
|
372
|
+
#ifndef __APPLE__
|
|
373
|
+
limited_coverage=root_only;
|
|
374
|
+
#endif
|
|
375
|
+
/* An unmanaged descendant may retain the PTY indefinitely. Report this known
|
|
376
|
+
* coverage limit separately. Queued/lost bytes and adapter faults still fail. */
|
|
377
|
+
if(outn || (!master_eof && !limited_coverage)) io_failed=1;
|
|
378
|
+
close(master);
|
|
379
|
+
uncertain+=io_failed;
|
|
380
|
+
const char *coverage="";
|
|
381
|
+
#ifndef __APPLE__
|
|
382
|
+
if(root_only) coverage=master_eof ? ",\"coverage\":\"root-only\",\"outputOpen\":false" : ",\"coverage\":\"root-only\",\"outputOpen\":true";
|
|
383
|
+
#endif
|
|
384
|
+
snprintf(msg,sizeof(msg),"{\"cleanup\":true,\"observed\":%zu,\"live\":%d,\"uncertain\":%d%s}\n",count,live,uncertain,coverage); event(msg);
|
|
385
|
+
#ifndef __APPLE__
|
|
386
|
+
for(size_t i=0;i<count;i++) if(known[i].fd>=0) close(known[i].fd);
|
|
387
|
+
#endif
|
|
388
|
+
free(out);free(input); return live||uncertain?2:0;
|
|
389
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function read(home: any, platform?: NodeJS.Platform): Promise<{
|
|
2
|
+
exists: boolean;
|
|
3
|
+
value: any;
|
|
4
|
+
private: boolean;
|
|
5
|
+
}>;
|
|
6
|
+
export function terminalCommand(args: any, { home, out }?: {
|
|
7
|
+
home?: string | undefined;
|
|
8
|
+
out?: {
|
|
9
|
+
(...data: any[]): void;
|
|
10
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
11
|
+
} | undefined;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
export function TERMINAL_WARNING(user?: string): string;
|
package/dist/terminal.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// packages/cli/src/terminal.js
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { chmod, lstat, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { alpHome } from "@anhlp/alp-client/index";
|
|
7
|
+
import { UsageError } from "./usage.js";
|
|
8
|
+
var TERMINAL_WARNING = (user = os.userInfo().username) => [
|
|
9
|
+
`A remote terminal runs a real shell on this computer as ${user}, with that account's full access:`,
|
|
10
|
+
"every file it can read or write, any program, and the network.",
|
|
11
|
+
"A workspace only picks the directory the shell starts in. It is NOT a sandbox.",
|
|
12
|
+
"Only gateway credentials that hold the terminal.exec permission can open one (never a default);",
|
|
13
|
+
"Paseo app devices paired with this host only after alp terminal allow --paseo."
|
|
14
|
+
].join("\n");
|
|
15
|
+
var file = (home) => path.join(home, "terminal.json");
|
|
16
|
+
async function read(home, platform = process.platform) {
|
|
17
|
+
const info = await lstat(file(home)).catch(() => void 0);
|
|
18
|
+
if (!info) return { exists: false, value: void 0, private: true };
|
|
19
|
+
const own = !process.getuid || info.uid === process.getuid();
|
|
20
|
+
const value = info.isFile() ? await readFile(file(home), "utf8").then(JSON.parse).catch(() => void 0) : void 0;
|
|
21
|
+
return { exists: true, value, private: info.isFile() && own && (platform === "win32" || !(info.mode & 63)) };
|
|
22
|
+
}
|
|
23
|
+
async function write(home, value) {
|
|
24
|
+
await mkdir(home, { recursive: true, mode: 448 });
|
|
25
|
+
const temporary = `${file(home)}.${randomUUID().slice(0, 8)}.tmp`;
|
|
26
|
+
await writeFile(temporary, JSON.stringify(value, null, 2) + "\n", { mode: 384, flag: "wx" });
|
|
27
|
+
await chmod(temporary, 384);
|
|
28
|
+
await rename(temporary, file(home)).catch(async (error) => {
|
|
29
|
+
await rm(temporary, { force: true });
|
|
30
|
+
throw error;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async function terminalCommand(args, { home = alpHome(), out = console.log } = {}) {
|
|
34
|
+
const [action, ...rest] = args;
|
|
35
|
+
const json = rest.includes("--json");
|
|
36
|
+
const current = await read(home);
|
|
37
|
+
const limits = current.value && typeof current.value.limits === "object" && current.value.limits ? { limits: current.value.limits } : {};
|
|
38
|
+
const paseo = rest.includes("--paseo");
|
|
39
|
+
const paseoBefore = current.private && current.value?.allowPaseoTerminal === true;
|
|
40
|
+
if (action === "allow") {
|
|
41
|
+
if (!rest.includes("--yes")) {
|
|
42
|
+
out(`${TERMINAL_WARNING()}
|
|
43
|
+
|
|
44
|
+
Run again with --yes to allow remote terminals on this host.`);
|
|
45
|
+
process.exitCode = 1;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const allowPaseoTerminal = paseo || paseoBefore;
|
|
49
|
+
await write(home, { version: 1, allowRemoteTerminal: true, ...allowPaseoTerminal ? { allowPaseoTerminal: true } : {}, ...limits });
|
|
50
|
+
out(json ? JSON.stringify({ allowRemoteTerminal: true, allowPaseoTerminal }) : `${TERMINAL_WARNING()}
|
|
51
|
+
|
|
52
|
+
Remote terminals are allowed on this host (${file(home)})${allowPaseoTerminal ? ", also for every Paseo app device paired with it" : ""}. alp terminal deny turns them off and ends every open one.`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (action === "deny") {
|
|
56
|
+
if (paseo) {
|
|
57
|
+
const allowed = current.private && current.value?.allowRemoteTerminal === true;
|
|
58
|
+
await write(home, { version: 1, allowRemoteTerminal: allowed, ...limits });
|
|
59
|
+
out(json ? JSON.stringify({ allowRemoteTerminal: allowed, allowPaseoTerminal: false }) : "Paseo app devices can no longer open terminals on this host; the bridge ends the terminals it holds.");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
await write(home, { version: 1, allowRemoteTerminal: false, ...limits });
|
|
63
|
+
out(json ? JSON.stringify({ allowRemoteTerminal: false, allowPaseoTerminal: false }) : "Remote terminals are off on this host; alpd ends every open terminal within 5 seconds.");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (action === "status") {
|
|
67
|
+
const allowed = current.private && current.value?.version === 1 && current.value.allowRemoteTerminal === true;
|
|
68
|
+
const allowPaseoTerminal = allowed && current.value.allowPaseoTerminal === true;
|
|
69
|
+
const problem = current.exists && !current.private ? `${file(home)} is not a private file of this user, so terminals stay off` : void 0;
|
|
70
|
+
if (json) out(JSON.stringify({ allowRemoteTerminal: allowed, allowPaseoTerminal, ...limits, ...problem ? { problem } : {} }));
|
|
71
|
+
else out([`Remote terminals: ${allowed ? "allowed" : "off"}${allowPaseoTerminal ? " (also for paired Paseo app devices)" : ""}`, ...problem ? [problem] : [], ...allowed ? ["", TERMINAL_WARNING()] : []].join("\n"));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
throw new UsageError();
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
TERMINAL_WARNING,
|
|
78
|
+
read,
|
|
79
|
+
terminalCommand
|
|
80
|
+
};
|
package/dist/usage.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export const USAGE: "Usage:\n alp <init|
|
|
1
|
+
export const USAGE: "Usage:\n alp <init|update-template> [directory] create a project, or upgrade an older project's ALP template (upgrade is an alias)\n alp update [--check] [--yes] [--version X] update ALP from GitHub Releases (checksum and provenance checked)\n alp --version\n alp setup [directory] [--runtime codex|claude|mix] [--prefer claude|codex]\n [--claude-model M] [--codex-model M] [--claude-supervisor M] [--codex-supervisor M]\n [--claude-oracle M] [--codex-oracle M] write Ph\u1EDF/Cafe's agent profiles to .alp/settings.json\n (keeps profiles written by hand; names other teams and the keys to edit)\n alp daemon <start|stop|restart>\n alp daemon status [--json] liveness and readiness; exit 0 ready, 3 not running, 4 not ready\n alp daemon <install|uninstall> run alpd as a login service that restarts after a crash\n alp daemon run [--detach] [--service] run alpd in this process (what services written by 0.0.1-beta.5/6 start)\n alp acp serve ALP to an editor (Zed, JetBrains) over the Agent Client Protocol on stdio\n alp dashboard [--port N] [--host 127.0.0.1|localhost] [--no-open|--print] open ALP's dashboard in the browser (alp-dashboard, loopback only); --no-open/--print only print its address\n alp dashboard --status|--stop whether alp dashboard runs (address without its token) | stop it\n alp desktop open ALP's desktop app (ALP.app, else the checkout in ALP_DESKTOP_CHECKOUT)\n alp dashboard serve [--service|--rotate] [--project DIR] [--port N] run alp-dashboard in this process (what alp dashboard starts)\n alp bridge <acp|antigravity> the stdio MCP bridge an agent CLI starts to reach alpd (internal)\n alp dashboard rotate give alp dashboard a new token: open pages lose access; prints the new address\n alp dashboard pair [--on|--off] the link that pairs Paseo's app on another device through the relay; --on or --off turns the relay on or off\n alp terminal <allow [--paseo] --yes|deny [--paseo]|status> [--json] remote terminals (a shell as you on this host; a workspace is not a sandbox), off by default\n alp doctor [--project DIR] [--fix] [--json] check this machine and project; --fix repairs what is safe to\n alp backup [-o FILE] [--project DIR]... [--no-projects] [--stop] [--json] sessions, settings, library and tasks in one file\n alp backup verify <file> [--json] | alp backup list [--json]\n alp restore <file> [--home-only] [--dry-run] [--stop] [--replace-newer] [--json] checks the whole backup first; keeps what it replaces\n alpd must be stopped for both; --stop stops it and starts it again after\n alp run [--agent A] [--team pho|cafe|ID] [--model M] [--mode read-only|workspace-write|full-access] [--thinking T] [--project DIR] [--json] <prompt>\n alp schedule create --session ID --at ISO_WITH_OFFSET --prompt TEXT [--project DIR] [--json]\n alp schedule list [--status pending|delivered|failed|cancelled] [--project DIR] [--json]\n alp schedule <show|cancel> ID [--project DIR] [--json] one-shot wake; timer gates only unblock tasks\n alp ps [--all]\n alp top [session] [--once]\n alp attach <session> [--json]\n alp send <session> [--prompt] [--json] <text>\n child default: user mail; --prompt: explicit new prompt to a live root or child\n alp questions [--json]\n alp answer <question> <text> | alp answer <question> --dismiss [--reason R]\n alp log <session> [--json]\n alp board [--project DIR] [--json]\n alp <agents|skills|mcp|hooks> [--project DIR] [--json] the library: built-in, ~/.alp and project entries\n alp skills --retired [--json] skills alp_skill_retire moved to ~/.alp/retired-skills\n alp providers [--json] ACP and Antigravity providers in your library\n alp teams [--project DIR] [--json] teams sessions run in: members, delegation, house rules\n alp packs [--project DIR] [--json] optional skill packs ALP ships (backend, frontend, architecture, ...)\n alp pack install <id> [--project [DIR]] [--assign] [--json] copy a pack's skills, agents and teams; existing entries are kept\n alp agent <new|edit> <name> [--project [DIR]] [--from A] [-d text] [--provider P] [--model M] [--thinking T] [--mode M]\n [--skills a,b] [--mcp a,b] [--hooks a,b] [--instructions FILE]\n alp team <new|edit> <id> [--project [DIR]] [--from ID] [--label L] [-d text] [--main A] [--member name=role]...\n [--member-model name=M]... [--member-thinking name=T]... [--delegate owner=a,b]... [--max-peers N]\n [--supervisor A] [--supervisor-model M] [--supervisor-thinking T] [--no-supervisor] [--rules FILE]\n alp skill <new|edit> <name> [--project [DIR]] [--from S] [--file FILE]\n alp skill check [name|DIR] [--project [DIR]] [--strict] [--json] validate skills (format, references, links); exit 1 on errors\n alp skill restore <name> [--from DIR] [--roles a,b | --no-roles] bring back a retired skill; --roles needed if it was retired without retired.json\n alp mcp add <name> [--project [DIR]] (--command C [--arg A]... [--env K=V]... [--cwd D] | --url U [--header K=V]...)\n alp hook add <name> [--project [DIR]] --event E --command C [--blocking] [--timeout SEC] [--match-agent A] [--match-label L]\n alp provider add <id> --command C [--arg A]... [--env K=V]... [--label L] [-d text] [--models a,b] an ACP agent; use id antigravity for native agy\n alp <agent|team|skill|mcp|hook|provider> <rm|show> <name> [--project [DIR]] | <cp|mv> <from> <to> [--project [DIR]]\n alp <mcp|hook|provider> test <name> [--project [DIR]] list an MCP server's tools; run a hook once; initialize a provider\n without --project, changes go to your library in ~/.alp; built-in agents and teams are never changed\n alp trust [--project DIR] | --revoke [--project DIR] | --list [--json] whether the project's hooks may run\n alp permissions [--project DIR] [--json] each agent's permission profile\n alp permissions check <agent> \"<command>\" what that agent's profile says about a command\n alp tasks [ready] [--all] [--status S] [--label L] [--project DIR] [--json]\n alp tasks gates [--json] open gates; checks GitHub ones\n alp tasks compact [--days 30] [--dry-run]\n alp tasks export [-o file.jsonl] as beads JSONL\n alp tasks import [file.jsonl] [--dry-run] beads JSONL; default .beads/issues.jsonl\n alp formula list | show <name> | pour <name> [--var k=v]... [--parent ID] [--dry-run]\n alp task add <title> [-d text] [-p 0-4] [-t task|bug|feature|chore|epic] [--parent ID] [--after ID]... [-l label]... [--path P]... [--from ID]\n alp task show <id> [--json]\n alp task report <epic> [--json] what an epic came to: tasks, time, rework, verification\n alp task edit <id> [--title T] [-d text] [-p N] [-t type] [-l label]... [--path P]... [-m note]\n alp task close <id> [--reason done|wontfix|duplicate|superseded] [-m summary] [--unverified \"why\"]\n alp verify [--project DIR] [--task ID] [--json] run the project's verify commands; --task records the result\n alp task reopen <id> [-m note]\n alp task dep <add|rm> <id> [--after ID]... [--parent ID] [--related ID]...\n alp task gate add <id> --human \"question\" [--option answer]... | --timer +2h|ISO | --pr N|owner/repo#N | --run N|owner/repo#N\n alp task gate clear <id> <gate> [--choice answer] [-m note] approve; main is told by mail\n alp task gate reject <id> <gate> [-m reason] the gate stays open; main is told by mail\n alp task gate rm <id> <gate> [-m note]\n alp pause [codex|claude] [--now] [-m reason] | alp pause status hold delegation; --now parks running assignments\n alp resume [codex|claude] lift a pause; parked assignments continue\n alp models [--refresh] [--json] the models alpd offers now, from each provider (cached; refreshed every 6 h)\n alp language [name | --reset] the language agents and ALP write to you in; default Vietnamese\n alp recall <assignment|task> [--project DIR] [--json] <question> ask a finished assignment about its work\n alp interrupt <session>\n alp compact <session>";
|
|
2
2
|
export class UsageError extends Error {
|
|
3
3
|
}
|
package/dist/usage.js
CHANGED
|
@@ -1,42 +1,60 @@
|
|
|
1
1
|
// packages/cli/src/usage.js
|
|
2
2
|
var USAGE = `Usage:
|
|
3
|
-
alp <init|
|
|
3
|
+
alp <init|update-template> [directory] create a project, or upgrade an older project's ALP template (upgrade is an alias)
|
|
4
|
+
alp update [--check] [--yes] [--version X] update ALP from GitHub Releases (checksum and provenance checked)
|
|
5
|
+
alp --version
|
|
4
6
|
alp setup [directory] [--runtime codex|claude|mix] [--prefer claude|codex]
|
|
5
7
|
[--claude-model M] [--codex-model M] [--claude-supervisor M] [--codex-supervisor M]
|
|
6
8
|
[--claude-oracle M] [--codex-oracle M] write Ph\u1EDF/Cafe's agent profiles to .alp/settings.json
|
|
9
|
+
(keeps profiles written by hand; names other teams and the keys to edit)
|
|
7
10
|
alp daemon <start|stop|restart>
|
|
8
11
|
alp daemon status [--json] liveness and readiness; exit 0 ready, 3 not running, 4 not ready
|
|
9
12
|
alp daemon <install|uninstall> run alpd as a login service that restarts after a crash
|
|
13
|
+
alp daemon run [--detach] [--service] run alpd in this process (what services written by 0.0.1-beta.5/6 start)
|
|
10
14
|
alp acp serve ALP to an editor (Zed, JetBrains) over the Agent Client Protocol on stdio
|
|
11
|
-
alp
|
|
12
|
-
alp
|
|
15
|
+
alp dashboard [--port N] [--host 127.0.0.1|localhost] [--no-open|--print] open ALP's dashboard in the browser (alp-dashboard, loopback only); --no-open/--print only print its address
|
|
16
|
+
alp dashboard --status|--stop whether alp dashboard runs (address without its token) | stop it
|
|
17
|
+
alp desktop open ALP's desktop app (ALP.app, else the checkout in ALP_DESKTOP_CHECKOUT)
|
|
18
|
+
alp dashboard serve [--service|--rotate] [--project DIR] [--port N] run alp-dashboard in this process (what alp dashboard starts)
|
|
19
|
+
alp bridge <acp|antigravity> the stdio MCP bridge an agent CLI starts to reach alpd (internal)
|
|
20
|
+
alp dashboard rotate give alp dashboard a new token: open pages lose access; prints the new address
|
|
21
|
+
alp dashboard pair [--on|--off] the link that pairs Paseo's app on another device through the relay; --on or --off turns the relay on or off
|
|
22
|
+
alp terminal <allow [--paseo] --yes|deny [--paseo]|status> [--json] remote terminals (a shell as you on this host; a workspace is not a sandbox), off by default
|
|
13
23
|
alp doctor [--project DIR] [--fix] [--json] check this machine and project; --fix repairs what is safe to
|
|
14
24
|
alp backup [-o FILE] [--project DIR]... [--no-projects] [--stop] [--json] sessions, settings, library and tasks in one file
|
|
15
25
|
alp backup verify <file> [--json] | alp backup list [--json]
|
|
16
26
|
alp restore <file> [--home-only] [--dry-run] [--stop] [--replace-newer] [--json] checks the whole backup first; keeps what it replaces
|
|
17
27
|
alpd must be stopped for both; --stop stops it and starts it again after
|
|
18
28
|
alp run [--agent A] [--team pho|cafe|ID] [--model M] [--mode read-only|workspace-write|full-access] [--thinking T] [--project DIR] [--json] <prompt>
|
|
29
|
+
alp schedule create --session ID --at ISO_WITH_OFFSET --prompt TEXT [--project DIR] [--json]
|
|
30
|
+
alp schedule list [--status pending|delivered|failed|cancelled] [--project DIR] [--json]
|
|
31
|
+
alp schedule <show|cancel> ID [--project DIR] [--json] one-shot wake; timer gates only unblock tasks
|
|
19
32
|
alp ps [--all]
|
|
20
33
|
alp top [session] [--once]
|
|
21
34
|
alp attach <session> [--json]
|
|
22
|
-
alp send <session> [--json] <text>
|
|
35
|
+
alp send <session> [--prompt] [--json] <text>
|
|
36
|
+
child default: user mail; --prompt: explicit new prompt to a live root or child
|
|
23
37
|
alp questions [--json]
|
|
24
38
|
alp answer <question> <text> | alp answer <question> --dismiss [--reason R]
|
|
25
39
|
alp log <session> [--json]
|
|
26
40
|
alp board [--project DIR] [--json]
|
|
27
41
|
alp <agents|skills|mcp|hooks> [--project DIR] [--json] the library: built-in, ~/.alp and project entries
|
|
42
|
+
alp skills --retired [--json] skills alp_skill_retire moved to ~/.alp/retired-skills
|
|
28
43
|
alp providers [--json] ACP and Antigravity providers in your library
|
|
29
44
|
alp teams [--project DIR] [--json] teams sessions run in: members, delegation, house rules
|
|
45
|
+
alp packs [--project DIR] [--json] optional skill packs ALP ships (backend, frontend, architecture, ...)
|
|
46
|
+
alp pack install <id> [--project [DIR]] [--assign] [--json] copy a pack's skills, agents and teams; existing entries are kept
|
|
30
47
|
alp agent <new|edit> <name> [--project [DIR]] [--from A] [-d text] [--provider P] [--model M] [--thinking T] [--mode M]
|
|
31
48
|
[--skills a,b] [--mcp a,b] [--hooks a,b] [--instructions FILE]
|
|
32
49
|
alp team <new|edit> <id> [--project [DIR]] [--from ID] [--label L] [-d text] [--main A] [--member name=role]...
|
|
33
50
|
[--member-model name=M]... [--member-thinking name=T]... [--delegate owner=a,b]... [--max-peers N]
|
|
34
51
|
[--supervisor A] [--supervisor-model M] [--supervisor-thinking T] [--no-supervisor] [--rules FILE]
|
|
35
|
-
alp skill new <name> [--project [DIR]] [--from S] [--file FILE]
|
|
52
|
+
alp skill <new|edit> <name> [--project [DIR]] [--from S] [--file FILE]
|
|
53
|
+
alp skill check [name|DIR] [--project [DIR]] [--strict] [--json] validate skills (format, references, links); exit 1 on errors
|
|
54
|
+
alp skill restore <name> [--from DIR] [--roles a,b | --no-roles] bring back a retired skill; --roles needed if it was retired without retired.json
|
|
36
55
|
alp mcp add <name> [--project [DIR]] (--command C [--arg A]... [--env K=V]... [--cwd D] | --url U [--header K=V]...)
|
|
37
56
|
alp hook add <name> [--project [DIR]] --event E --command C [--blocking] [--timeout SEC] [--match-agent A] [--match-label L]
|
|
38
57
|
alp provider add <id> --command C [--arg A]... [--env K=V]... [--label L] [-d text] [--models a,b] an ACP agent; use id antigravity for native agy
|
|
39
|
-
alp provider edit antigravity --read-only-mode instructions|reject opt into prompt-only read-only for advisory roles
|
|
40
58
|
alp <agent|team|skill|mcp|hook|provider> <rm|show> <name> [--project [DIR]] | <cp|mv> <from> <to> [--project [DIR]]
|
|
41
59
|
alp <mcp|hook|provider> test <name> [--project [DIR]] list an MCP server's tools; run a hook once; initialize a provider
|
|
42
60
|
without --project, changes go to your library in ~/.alp; built-in agents and teams are never changed
|
|
@@ -57,13 +75,17 @@ var USAGE = `Usage:
|
|
|
57
75
|
alp verify [--project DIR] [--task ID] [--json] run the project's verify commands; --task records the result
|
|
58
76
|
alp task reopen <id> [-m note]
|
|
59
77
|
alp task dep <add|rm> <id> [--after ID]... [--parent ID] [--related ID]...
|
|
60
|
-
alp task gate add <id> --human "question" | --timer +2h|ISO | --pr N|owner/repo#N | --run N|owner/repo#N
|
|
61
|
-
alp task gate
|
|
78
|
+
alp task gate add <id> --human "question" [--option answer]... | --timer +2h|ISO | --pr N|owner/repo#N | --run N|owner/repo#N
|
|
79
|
+
alp task gate clear <id> <gate> [--choice answer] [-m note] approve; main is told by mail
|
|
80
|
+
alp task gate reject <id> <gate> [-m reason] the gate stays open; main is told by mail
|
|
81
|
+
alp task gate rm <id> <gate> [-m note]
|
|
62
82
|
alp pause [codex|claude] [--now] [-m reason] | alp pause status hold delegation; --now parks running assignments
|
|
63
83
|
alp resume [codex|claude] lift a pause; parked assignments continue
|
|
84
|
+
alp models [--refresh] [--json] the models alpd offers now, from each provider (cached; refreshed every 6 h)
|
|
64
85
|
alp language [name | --reset] the language agents and ALP write to you in; default Vietnamese
|
|
65
86
|
alp recall <assignment|task> [--project DIR] [--json] <question> ask a finished assignment about its work
|
|
66
|
-
alp interrupt <session
|
|
87
|
+
alp interrupt <session>
|
|
88
|
+
alp compact <session>`;
|
|
67
89
|
var UsageError = class extends Error {
|
|
68
90
|
};
|
|
69
91
|
export {
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anhlp/alp-cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1-beta.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "ALP cli module",
|
|
6
6
|
"files": [
|
|
7
7
|
"src",
|
|
8
|
+
"!src/dashboard",
|
|
8
9
|
"dist",
|
|
9
10
|
"NOTICE"
|
|
10
11
|
],
|
|
@@ -126,9 +127,9 @@
|
|
|
126
127
|
"node": ">=22.12"
|
|
127
128
|
},
|
|
128
129
|
"dependencies": {
|
|
129
|
-
"@anhlp/alp-core": "0.0.
|
|
130
|
-
"@anhlp/alp-client": "0.0.
|
|
131
|
-
"@anhlp/alp-protocol": "0.0.
|
|
130
|
+
"@anhlp/alp-core": "0.0.1-beta.10",
|
|
131
|
+
"@anhlp/alp-client": "0.0.1-beta.10",
|
|
132
|
+
"@anhlp/alp-protocol": "0.0.1-beta.10",
|
|
132
133
|
"smol-toml": "1.9.0",
|
|
133
134
|
"@agentclientprotocol/sdk": "1.7.0",
|
|
134
135
|
"@anthropic-ai/claude-agent-sdk": "^0.3.292"
|
|
@@ -155,5 +156,11 @@
|
|
|
155
156
|
},
|
|
156
157
|
"bin": {
|
|
157
158
|
"alp": "dist/cli.js"
|
|
159
|
+
},
|
|
160
|
+
"optionalDependencies": {
|
|
161
|
+
"node-pty": "1.2.0-beta.15"
|
|
162
|
+
},
|
|
163
|
+
"devDependencies": {
|
|
164
|
+
"@anhlp/alp-gateway": "0.0.1-beta.10"
|
|
158
165
|
}
|
|
159
166
|
}
|