@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
package/src/sessions.js
CHANGED
|
@@ -3,12 +3,27 @@ import path from 'node:path';
|
|
|
3
3
|
import { createInterface } from 'node:readline';
|
|
4
4
|
import { parseArgs } from 'node:util';
|
|
5
5
|
import { ago, duration, renderLog, renderPs } from '@anhlp/alp-client/render';
|
|
6
|
-
import { isTaskId } from '@anhlp/alp-core/tasks';
|
|
6
|
+
import { AGENT_MARKER, isAgentProcess, isTaskId } from '@anhlp/alp-core/tasks';
|
|
7
7
|
import { connect } from '@anhlp/alp-client/index';
|
|
8
8
|
import { UsageError } from './usage.js';
|
|
9
9
|
import { start, running, stop } from './daemon.js';
|
|
10
10
|
import { taskProject } from './tasks.js';
|
|
11
11
|
|
|
12
|
+
/** One line for a finished tool call: its command, or what a typed call touched (ALPD §4.2). */
|
|
13
|
+
export function toolLine(item) {
|
|
14
|
+
const detail = item.detail ?? {};
|
|
15
|
+
const first = text => String(text ?? '').split('\n')[0].slice(0, 200);
|
|
16
|
+
switch (detail.type) {
|
|
17
|
+
case 'shell': return detail.command;
|
|
18
|
+
case 'read': case 'edit': case 'write': return `${item.name} ${detail.filePath}`;
|
|
19
|
+
case 'search': return `${item.name} ${first(detail.query)}`;
|
|
20
|
+
case 'fetch': return `${item.name} ${detail.url}`;
|
|
21
|
+
case 'sub_agent': return `${item.name}${detail.description ? ` ${first(detail.description)}` : ''}`;
|
|
22
|
+
case 'plain_text': return `${item.name}${detail.label ? ` ${detail.label}` : ''}`;
|
|
23
|
+
}
|
|
24
|
+
return item.name === 'alp_delegate' ? `delegate → ${detail.input?.agent}` : item.name;
|
|
25
|
+
}
|
|
26
|
+
|
|
12
27
|
function printer(json) {
|
|
13
28
|
const depth = new Map();
|
|
14
29
|
const agents = new Map();
|
|
@@ -28,7 +43,7 @@ function printer(json) {
|
|
|
28
43
|
latest.set(item.id, { sessionId, item });
|
|
29
44
|
if (item.kind === 'tool_call' && item.status !== 'running' && !printed.has(item.id)) {
|
|
30
45
|
printed.add(item.id);
|
|
31
|
-
const detail = item
|
|
46
|
+
const detail = toolLine(item);
|
|
32
47
|
line(sessionId, ` ${item.status === 'failed' ? '✗' : '✓'} ${detail}`);
|
|
33
48
|
}
|
|
34
49
|
if (item.kind === 'notice') line(sessionId, ` ${item.level === 'error' ? '‼' : item.level === 'warning' ? '!' : 'ℹ'} ${item.text}`);
|
|
@@ -93,7 +108,7 @@ function answerer(client) {
|
|
|
93
108
|
|
|
94
109
|
/** Streams a tree until its root is idle; the first Ctrl-C interrupts it, the second detaches. */
|
|
95
110
|
|
|
96
|
-
function follow(client, rootId, print, { untilIdle, interactive = false }) {
|
|
111
|
+
function follow(client, rootId, print, { untilIdle, interactive = false, targetOnly = false, promptId }) {
|
|
97
112
|
const answering = interactive ? answerer(client) : undefined;
|
|
98
113
|
const done = new Promise((resolve, reject) => {
|
|
99
114
|
let failed = false;
|
|
@@ -106,9 +121,11 @@ function follow(client, rootId, print, { untilIdle, interactive = false }) {
|
|
|
106
121
|
client.request('session.interrupt', { sessionId: rootId }).catch(() => {});
|
|
107
122
|
};
|
|
108
123
|
process.on('SIGINT', onSignal);
|
|
109
|
-
client.onClose(error => { process.off('SIGINT', onSignal); reject(error); });
|
|
124
|
+
client.onClose(error => { process.off('SIGINT', onSignal); answering?.close(); reject(error); });
|
|
110
125
|
let rootEnded = false;
|
|
111
126
|
client.onEvent(envelope => {
|
|
127
|
+
if (targetOnly && envelope.sessionId !== rootId) return;
|
|
128
|
+
if (promptId && envelope.event.type === 'prompt.failed' && envelope.event.clientMessageId !== promptId) return;
|
|
112
129
|
print(envelope);
|
|
113
130
|
answering?.accept(envelope.event);
|
|
114
131
|
const { sessionId, event } = envelope;
|
|
@@ -192,28 +209,36 @@ async function attach(args) {
|
|
|
192
209
|
/** Steers a running root, prompts an idle one, or resumes a closed one; then follows it until idle. */
|
|
193
210
|
|
|
194
211
|
async function send(args) {
|
|
195
|
-
const { values, positionals: [sessionId, ...words] } = parseArgs({ args, allowPositionals: true, options: { json: { type: 'boolean' } } });
|
|
212
|
+
const { values, positionals: [sessionId, ...words] } = parseArgs({ args, allowPositionals: true, options: { json: { type: 'boolean' }, prompt: { type: 'boolean' } } });
|
|
196
213
|
const text = words.join(' ').trim();
|
|
197
214
|
if (!sessionId || !text) throw new UsageError();
|
|
198
215
|
const client = await connect(await start(), { name: 'alp-cli', version: '1' });
|
|
216
|
+
let subscriptionId;
|
|
199
217
|
try {
|
|
200
218
|
const { session } = await client.request('session.get', { sessionId });
|
|
201
|
-
if (session.parentId) {
|
|
219
|
+
if (session.parentId && !values.prompt) {
|
|
202
220
|
// An assignment gets the text as mail from the user, in its running turn.
|
|
203
221
|
await client.request('session.message', { sessionId, text });
|
|
204
222
|
if (!values.json) console.error(`Sent to ${session.agent} as mail from the user`);
|
|
205
223
|
return;
|
|
206
224
|
}
|
|
207
|
-
const done = follow(client, sessionId, printer(values.json), { untilIdle: true, interactive: !values.json && process.stdin.isTTY });
|
|
208
225
|
const live = session.status === 'idle' || session.status === 'running';
|
|
209
|
-
if (live)
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
226
|
+
if (values.prompt && !live) throw new Error('Explicit prompts require a live session; use default alp send to reopen a root');
|
|
227
|
+
const clientMessageId = randomUUID();
|
|
228
|
+
const done = follow(client, sessionId, printer(values.json), { untilIdle: true, interactive: !values.json && process.stdin.isTTY, targetOnly: !!session.parentId, promptId: clientMessageId });
|
|
229
|
+
if (live) {
|
|
230
|
+
const attached = await client.request('session.attach', { sessionId, replay: false });
|
|
231
|
+
subscriptionId = attached.session.id; // A child attaches its root for observation only.
|
|
232
|
+
} else {
|
|
233
|
+
await client.request('session.create', { sessionId, spec: { cwd: session.projectRoot } });
|
|
234
|
+
subscriptionId = sessionId;
|
|
235
|
+
}
|
|
236
|
+
const steer = !values.prompt && live && !!session.activeTurnId;
|
|
237
|
+
await client.request('session.prompt', { sessionId, clientMessageId, delivery: steer ? 'steer' : 'auto', content: [{ type: 'text', text }] });
|
|
238
|
+
if (!values.json) console.error(values.prompt ? 'Submitted an explicit prompt' : steer ? 'Steered the running turn' : live ? 'Started a turn' : 'Resumed the session');
|
|
214
239
|
if (!await done) process.exitCode = 1;
|
|
215
|
-
await client.request('session.release', { sessionId }).catch(() => {});
|
|
216
240
|
} finally {
|
|
241
|
+
if (subscriptionId) await client.request('session.release', { sessionId: subscriptionId }).catch(() => {});
|
|
217
242
|
client.close();
|
|
218
243
|
}
|
|
219
244
|
}
|
|
@@ -236,6 +261,8 @@ async function answer(args) {
|
|
|
236
261
|
const { values, positionals: [questionId, ...words] } = parseArgs({ args, allowPositionals: true, options: { dismiss: { type: 'boolean' }, reason: { type: 'string' } } });
|
|
237
262
|
const text = words.join(' ').trim();
|
|
238
263
|
if (!questionId || (values.dismiss ? text : !text)) throw new UsageError();
|
|
264
|
+
// An answer speaks for the user: never from a process an ALP agent started (t-ca1f).
|
|
265
|
+
if (isAgentProcess()) throw new Error(`Only the user answers a question; this process runs under an ALP agent (${AGENT_MARKER})`);
|
|
239
266
|
const client = await running();
|
|
240
267
|
const result = await client.request('question.answer', values.dismiss ? { questionId, dismiss: true, reason: values.reason } : { questionId, text }).finally(() => client.close());
|
|
241
268
|
console.log(`${values.dismiss ? 'Dismissed' : 'Answered'} ${result.questionId}`);
|
|
@@ -304,6 +331,17 @@ async function log(args) {
|
|
|
304
331
|
for (const line of renderLog(rootId, entries)) console.log(line);
|
|
305
332
|
}
|
|
306
333
|
|
|
334
|
+
/** The models alpd offers now: the live catalog (t-e5ee); --refresh asks every provider again first. */
|
|
335
|
+
async function models(args) {
|
|
336
|
+
const { values, positionals } = parseArgs({ args, allowPositionals: true, options: { refresh: { type: 'boolean' }, json: { type: 'boolean' } } });
|
|
337
|
+
if (positionals.length) throw new UsageError();
|
|
338
|
+
const client = await running();
|
|
339
|
+
const catalog = await client.request(values.refresh ? 'catalog.refresh' : 'catalog.get', {}).finally(() => client.close());
|
|
340
|
+
if (values.json) { console.log(JSON.stringify(catalog)); return; }
|
|
341
|
+
for (const [runtime, state] of Object.entries(catalog.providers ?? {})) console.log(`${runtime}: ${state.status}${state.fetchedAt ? ` (${state.fetchedAt})` : ''}${state.error ? ` — ${state.error}` : ''}`);
|
|
342
|
+
for (const model of catalog.models) console.log(`${model.id.padEnd(40)} ${model.label}`);
|
|
343
|
+
}
|
|
344
|
+
|
|
307
345
|
/** The project board every agent on the project shares: live claims, then decisions and findings. */
|
|
308
346
|
|
|
309
347
|
async function board(args) {
|
|
@@ -372,8 +410,6 @@ async function recall(args) {
|
|
|
372
410
|
console.log(answer.answer);
|
|
373
411
|
}
|
|
374
412
|
|
|
375
|
-
/** alp web: opens the web app alpd serves on 127.0.0.1, with the token in the address (ALPD §61). */
|
|
376
|
-
|
|
377
413
|
async function interrupt(args) {
|
|
378
414
|
if (args.length !== 1) throw new UsageError();
|
|
379
415
|
const client = await running();
|
|
@@ -381,4 +417,12 @@ async function interrupt(args) {
|
|
|
381
417
|
console.log('Interrupted');
|
|
382
418
|
}
|
|
383
419
|
|
|
384
|
-
|
|
420
|
+
/** alp compact <session>: compacts a root's context now, or at its next turn boundary (t-0e56). */
|
|
421
|
+
async function compact(args) {
|
|
422
|
+
if (args.length !== 1) throw new UsageError();
|
|
423
|
+
const client = await running();
|
|
424
|
+
const { status } = await client.request('session.compact', { sessionId: args[0] }).finally(() => client.close());
|
|
425
|
+
console.log(status === 'started' ? 'Compacting: main writes a checkpoint, then its context is compacted' : status === 'running' ? 'A compaction is already running' : 'Compaction queued for the next turn boundary');
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
export { printer, answerer, follow, run, ps, attach, send, questions, answer, renderStatus, top, log, board, models, printPauses, pause, resume, recall, interrupt, compact };
|
package/src/tasks.js
CHANGED
|
@@ -5,9 +5,11 @@ import { parseArgs } from 'node:util';
|
|
|
5
5
|
import { exportBeads, importBeads, parseJsonl } from '@anhlp/alp-core/beads';
|
|
6
6
|
import { findFormula, formulaDirs, listFormulas, pourFormula } from '@anhlp/alp-core/formulas';
|
|
7
7
|
import { describeVerification } from '@anhlp/alp-core/verify';
|
|
8
|
+
import { scriptCommand } from '@anhlp/alp-core/packaged';
|
|
8
9
|
import { ago } from '@anhlp/alp-client/render';
|
|
9
10
|
import { parse as toml } from 'smol-toml';
|
|
10
|
-
import { addGate, blockersOf, checkGates, childrenOf, closeTask, compactTasks, createTask, describeGate, gateOpen, epicReport, gatesOf, linkTask, listTasks, loadTasks, readyTasks, reopenTask, resolveGate, summarize, TASKS_DIR, updateTask } from '@anhlp/alp-core/tasks';
|
|
11
|
+
import { addGate, blockersOf, checkGates, childrenOf, closeTask, compactTasks, createTask, describeGate, gateOpen, epicReport, gatesOf, linkTask, listTasks, loadTasks, readyTasks, rejectGate, reopenTask, resolveGate, summarize, TASKS_DIR, updateTask, isAgentProcess, AGENT_MARKER } from '@anhlp/alp-core/tasks';
|
|
12
|
+
import { AlpError } from '@anhlp/alp-core/errors';
|
|
11
13
|
import { alpHome } from '@anhlp/alp-client/index';
|
|
12
14
|
import { UsageError } from './usage.js';
|
|
13
15
|
|
|
@@ -62,7 +64,8 @@ const gh = (args, { cwd }) => new Promise((resolve, reject) => {
|
|
|
62
64
|
const bin = process.env.ALP_GH_BIN ?? 'gh';
|
|
63
65
|
// Windows cannot exec a script by its shebang (the tests' stand-in for gh); a JavaScript one runs under this Node.
|
|
64
66
|
const script = process.platform === 'win32' && /\.[cm]?js$/i.test(bin);
|
|
65
|
-
const
|
|
67
|
+
const run = script ? scriptCommand(bin, args) : { command: bin, args };
|
|
68
|
+
const child = spawn(run.command, run.args, { cwd, ...(run.env ? { env: { ...process.env, ...run.env } } : {}), stdio: ['ignore', 'pipe', 'pipe'] });
|
|
66
69
|
let stdout = '';
|
|
67
70
|
let stderr = '';
|
|
68
71
|
child.stdout.on('data', chunk => { stdout += chunk; });
|
|
@@ -182,7 +185,7 @@ async function taskCommand([action, ...args]) {
|
|
|
182
185
|
description: { type: 'string', short: 'd' }, priority: { type: 'string', short: 'p' }, type: { type: 'string', short: 't' },
|
|
183
186
|
label: { ...repeated, short: 'l' }, path: repeated, parent: { type: 'string' }, after: repeated, related: repeated, from: { type: 'string' },
|
|
184
187
|
title: { type: 'string' }, message: { type: 'string', short: 'm' }, reason: { type: 'string' }, unverified: { type: 'string' }, project: { type: 'string' }, json: { type: 'boolean' },
|
|
185
|
-
human: { type: 'string' }, timer: { type: 'string' }, pr: { type: 'string' }, run: { type: 'string' },
|
|
188
|
+
human: { type: 'string' }, timer: { type: 'string' }, pr: { type: 'string' }, run: { type: 'string' }, option: repeated, choice: { type: 'string' },
|
|
186
189
|
} });
|
|
187
190
|
const root = await taskProject(values.project);
|
|
188
191
|
const fields = {
|
|
@@ -218,7 +221,7 @@ async function taskCommand([action, ...args]) {
|
|
|
218
221
|
task = await updateTask(root, positionals[0], { ...fields, ...(values.title !== undefined ? { title: values.title } : {}), note: values.message }, 'user');
|
|
219
222
|
} else if (action === 'close') {
|
|
220
223
|
if (positionals.length !== 1) throw new UsageError();
|
|
221
|
-
task = await closeTask(root, positionals[0], { reason: values.reason, summary: values.message, unverified: values.unverified }, 'user');
|
|
224
|
+
task = await closeTask(root, positionals[0], { reason: values.reason, summary: values.message, unverified: values.unverified, agent: isAgentProcess(), channel: 'cli' }, 'user');
|
|
222
225
|
} else if (action === 'reopen') {
|
|
223
226
|
if (positionals.length !== 1) throw new UsageError();
|
|
224
227
|
task = await reopenTask(root, positionals[0], { note: values.message }, 'user');
|
|
@@ -230,11 +233,22 @@ async function taskCommand([action, ...args]) {
|
|
|
230
233
|
} else if (action === 'gate') {
|
|
231
234
|
const [change, id, gate, ...rest] = positionals;
|
|
232
235
|
const kinds = ['human', 'timer', 'pr', 'run'].filter(kind => values[kind] !== undefined);
|
|
236
|
+
// Only the user decides a human gate: never from a process an ALP agent started (t-ca1f).
|
|
237
|
+
if (['clear', 'reject', 'rm'].includes(change) && id && gate && isAgentProcess()) {
|
|
238
|
+
const { tasks: current } = await loadTasks(root);
|
|
239
|
+
if (current.find(entry => entry.id === id)?.gates.find(entry => entry.id === gate)?.kind === 'human') throw new AlpError('GATE_USER_ONLY', `Only the user clears a human gate; this process runs under an ALP agent (${AGENT_MARKER}). Ask the user to decide it`);
|
|
240
|
+
}
|
|
233
241
|
if (change === 'add' && id && !gate && kinds.length === 1) {
|
|
234
242
|
const kind = kinds[0];
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
243
|
+
if (values.option && kind !== 'human') throw new UsageError();
|
|
244
|
+
task = await addGate(root, id, kind === 'human' ? { kind, note: values.human, ...(values.option ? { options: values.option } : {}) } : kind === 'timer' ? { kind, until: values.timer } : { kind: `gh:${kind}`, ref: values[kind] }, 'user');
|
|
245
|
+
} else if (change === 'clear' && id && gate && !rest.length && !kinds.length && !values.option) {
|
|
246
|
+
// A decision made here reaches main as mail, as one made in Paseo or ALP web does.
|
|
247
|
+
task = await resolveGate(root, id, gate, { by: 'user', note: values.message, channel: 'cli', ...(values.choice !== undefined ? { choice: values.choice } : {}) });
|
|
248
|
+
} else if (change === 'reject' && id && gate && !rest.length && !kinds.length && !values.option && values.choice === undefined) {
|
|
249
|
+
task = await rejectGate(root, id, gate, { by: 'user', reason: values.message, channel: 'cli' });
|
|
250
|
+
} else if (change === 'rm' && id && gate && !rest.length && !kinds.length && !values.option && values.choice === undefined) {
|
|
251
|
+
task = await resolveGate(root, id, gate, { by: 'user', note: values.message, remove: true, channel: 'cli' });
|
|
238
252
|
} else {
|
|
239
253
|
throw new UsageError();
|
|
240
254
|
}
|
|
@@ -261,7 +275,7 @@ function printTask(task, tasks) {
|
|
|
261
275
|
task.related.length && `related ${task.related.join(', ')}`,
|
|
262
276
|
].filter(Boolean);
|
|
263
277
|
if (relations.length) console.log(` ${relations.join('; ')}`);
|
|
264
|
-
for (const gate of task.gates) console.log(` ${gateOpen(gate) ? '⏸' : '✓'} gate ${describeGate(gate)}${gate.resolved ? ` (cleared by ${gate.resolved.by}${gate.resolved.note ? `: ${gate.resolved.note}` : ''})` : ''}`);
|
|
278
|
+
for (const gate of task.gates) console.log(` ${gateOpen(gate) ? '⏸' : '✓'} gate ${describeGate(gate)}${gate.resolved ? ` (cleared by ${gate.resolved.by}${gate.resolved.choice ? ` with "${gate.resolved.choice}"` : ''}${gate.resolved.channel ? ` in ${gate.resolved.channel}` : ''}${gate.resolved.note ? `: ${gate.resolved.note}` : ''})` : gate.rejected ? ` (rejected by ${gate.rejected.by}${gate.rejected.reason ? `: ${gate.rejected.reason}` : ''})` : ''}${gateOpen(gate) && gate.options ? ` options: ${gate.options.join(' | ')}` : ''}${gate.tampered ? ' ⚠ changed outside ALP (a task file edit cleared or removed it); reopened for you to decide' : ''}`);
|
|
265
279
|
const inherited = gatesOf(task, tasks).filter(label => label.startsWith('t-'));
|
|
266
280
|
if (task.status !== 'closed' && inherited.length) console.log(` waits on its parent's gates: ${inherited.join('; ')}`);
|
|
267
281
|
if (task.compacted) console.log(` compacted ${task.compacted.at.slice(0, 10)} from ${task.compacted.chars} characters`);
|
package/src/terminal.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { chmod, lstat, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { alpHome } from '@anhlp/alp-client/index';
|
|
6
|
+
import { UsageError } from './usage.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* `alp terminal allow|deny|status`: the host owner's switch for remote terminals
|
|
10
|
+
* (docs/protocol/alp-json-rpc-v1.md §12.10, issue #121 H). It lives in $ALP_HOME/terminal.json, a
|
|
11
|
+
* file only this user may read or write; no RPC changes it and no backup carries it.
|
|
12
|
+
*/
|
|
13
|
+
export const TERMINAL_WARNING = (user = os.userInfo().username) => [
|
|
14
|
+
`A remote terminal runs a real shell on this computer as ${user}, with that account's full access:`,
|
|
15
|
+
'every file it can read or write, any program, and the network.',
|
|
16
|
+
'A workspace only picks the directory the shell starts in. It is NOT a sandbox.',
|
|
17
|
+
'Only gateway credentials that hold the terminal.exec permission can open one (never a default);',
|
|
18
|
+
'Paseo app devices paired with this host only after alp terminal allow --paseo.',
|
|
19
|
+
].join('\n');
|
|
20
|
+
|
|
21
|
+
const file = home => path.join(home, 'terminal.json');
|
|
22
|
+
|
|
23
|
+
export async function read(home, platform = process.platform) {
|
|
24
|
+
const info = await lstat(file(home)).catch(() => undefined);
|
|
25
|
+
if (!info) return { exists: false, value: undefined, private: true };
|
|
26
|
+
const own = !process.getuid || info.uid === process.getuid();
|
|
27
|
+
const value = info.isFile() ? await readFile(file(home), 'utf8').then(JSON.parse).catch(() => undefined) : undefined;
|
|
28
|
+
// Windows has no POSIX group/other mode bits (files report 0o666/0o444).
|
|
29
|
+
return { exists: true, value, private: info.isFile() && own && (platform === 'win32' || !(info.mode & 0o077)) };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function write(home, value) {
|
|
33
|
+
await mkdir(home, { recursive: true, mode: 0o700 });
|
|
34
|
+
const temporary = `${file(home)}.${randomUUID().slice(0, 8)}.tmp`;
|
|
35
|
+
await writeFile(temporary, JSON.stringify(value, null, 2) + '\n', { mode: 0o600, flag: 'wx' });
|
|
36
|
+
await chmod(temporary, 0o600);
|
|
37
|
+
await rename(temporary, file(home)).catch(async error => { await rm(temporary, { force: true }); throw error; });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function terminalCommand(args, { home = alpHome(), out = console.log } = {}) {
|
|
41
|
+
const [action, ...rest] = args;
|
|
42
|
+
const json = rest.includes('--json');
|
|
43
|
+
const current = await read(home);
|
|
44
|
+
const limits = current.value && typeof current.value.limits === 'object' && current.value.limits ? { limits: current.value.limits } : {};
|
|
45
|
+
const paseo = rest.includes('--paseo');
|
|
46
|
+
const paseoBefore = current.private && current.value?.allowPaseoTerminal === true;
|
|
47
|
+
if (action === 'allow') {
|
|
48
|
+
if (!rest.includes('--yes')) {
|
|
49
|
+
out(`${TERMINAL_WARNING()}\n\nRun again with --yes to allow remote terminals on this host.`);
|
|
50
|
+
process.exitCode = 1;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const allowPaseoTerminal = paseo || paseoBefore;
|
|
54
|
+
await write(home, { version: 1, allowRemoteTerminal: true, ...(allowPaseoTerminal ? { allowPaseoTerminal: true } : {}), ...limits });
|
|
55
|
+
out(json ? JSON.stringify({ allowRemoteTerminal: true, allowPaseoTerminal }) : `${TERMINAL_WARNING()}\n\nRemote 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.`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (action === 'deny') {
|
|
59
|
+
if (paseo) {
|
|
60
|
+
const allowed = current.private && current.value?.allowRemoteTerminal === true;
|
|
61
|
+
await write(home, { version: 1, allowRemoteTerminal: allowed, ...limits });
|
|
62
|
+
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.');
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
await write(home, { version: 1, allowRemoteTerminal: false, ...limits });
|
|
66
|
+
out(json ? JSON.stringify({ allowRemoteTerminal: false, allowPaseoTerminal: false }) : 'Remote terminals are off on this host; alpd ends every open terminal within 5 seconds.');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (action === 'status') {
|
|
70
|
+
const allowed = current.private && current.value?.version === 1 && current.value.allowRemoteTerminal === true;
|
|
71
|
+
const allowPaseoTerminal = allowed && current.value.allowPaseoTerminal === true;
|
|
72
|
+
const problem = current.exists && !current.private ? `${file(home)} is not a private file of this user, so terminals stay off` : undefined;
|
|
73
|
+
if (json) out(JSON.stringify({ allowRemoteTerminal: allowed, allowPaseoTerminal, ...limits, ...(problem ? { problem } : {}) }));
|
|
74
|
+
else out([`Remote terminals: ${allowed ? 'allowed' : 'off'}${allowPaseoTerminal ? ' (also for paired Paseo app devices)' : ''}`, ...(problem ? [problem] : []), ...(allowed ? ['', TERMINAL_WARNING()] : [])].join('\n'));
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
throw new UsageError();
|
|
78
|
+
}
|
package/src/usage.js
CHANGED
|
@@ -2,43 +2,61 @@
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
|
|
4
4
|
const USAGE = `Usage:
|
|
5
|
-
alp <init|
|
|
5
|
+
alp <init|update-template> [directory] create a project, or upgrade an older project's ALP template (upgrade is an alias)
|
|
6
|
+
alp update [--check] [--yes] [--version X] update ALP from GitHub Releases (checksum and provenance checked)
|
|
7
|
+
alp --version
|
|
6
8
|
alp setup [directory] [--runtime codex|claude|mix] [--prefer claude|codex]
|
|
7
9
|
[--claude-model M] [--codex-model M] [--claude-supervisor M] [--codex-supervisor M]
|
|
8
10
|
[--claude-oracle M] [--codex-oracle M] write Phở/Cafe's agent profiles to .alp/settings.json
|
|
11
|
+
(keeps profiles written by hand; names other teams and the keys to edit)
|
|
9
12
|
alp daemon <start|stop|restart>
|
|
10
13
|
alp daemon status [--json] liveness and readiness; exit 0 ready, 3 not running, 4 not ready
|
|
11
14
|
alp daemon <install|uninstall> run alpd as a login service that restarts after a crash
|
|
15
|
+
alp daemon run [--detach] [--service] run alpd in this process (what services written by 0.0.1-beta.5/6 start)
|
|
12
16
|
alp acp serve ALP to an editor (Zed, JetBrains) over the Agent Client Protocol on stdio
|
|
13
|
-
alp
|
|
14
|
-
alp
|
|
17
|
+
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
|
|
18
|
+
alp dashboard --status|--stop whether alp dashboard runs (address without its token) | stop it
|
|
19
|
+
alp desktop open ALP's desktop app (ALP.app, else the checkout in ALP_DESKTOP_CHECKOUT)
|
|
20
|
+
alp dashboard serve [--service|--rotate] [--project DIR] [--port N] run alp-dashboard in this process (what alp dashboard starts)
|
|
21
|
+
alp bridge <acp|antigravity> the stdio MCP bridge an agent CLI starts to reach alpd (internal)
|
|
22
|
+
alp dashboard rotate give alp dashboard a new token: open pages lose access; prints the new address
|
|
23
|
+
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
|
|
24
|
+
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
|
|
15
25
|
alp doctor [--project DIR] [--fix] [--json] check this machine and project; --fix repairs what is safe to
|
|
16
26
|
alp backup [-o FILE] [--project DIR]... [--no-projects] [--stop] [--json] sessions, settings, library and tasks in one file
|
|
17
27
|
alp backup verify <file> [--json] | alp backup list [--json]
|
|
18
28
|
alp restore <file> [--home-only] [--dry-run] [--stop] [--replace-newer] [--json] checks the whole backup first; keeps what it replaces
|
|
19
29
|
alpd must be stopped for both; --stop stops it and starts it again after
|
|
20
30
|
alp run [--agent A] [--team pho|cafe|ID] [--model M] [--mode read-only|workspace-write|full-access] [--thinking T] [--project DIR] [--json] <prompt>
|
|
31
|
+
alp schedule create --session ID --at ISO_WITH_OFFSET --prompt TEXT [--project DIR] [--json]
|
|
32
|
+
alp schedule list [--status pending|delivered|failed|cancelled] [--project DIR] [--json]
|
|
33
|
+
alp schedule <show|cancel> ID [--project DIR] [--json] one-shot wake; timer gates only unblock tasks
|
|
21
34
|
alp ps [--all]
|
|
22
35
|
alp top [session] [--once]
|
|
23
36
|
alp attach <session> [--json]
|
|
24
|
-
alp send <session> [--json] <text>
|
|
37
|
+
alp send <session> [--prompt] [--json] <text>
|
|
38
|
+
child default: user mail; --prompt: explicit new prompt to a live root or child
|
|
25
39
|
alp questions [--json]
|
|
26
40
|
alp answer <question> <text> | alp answer <question> --dismiss [--reason R]
|
|
27
41
|
alp log <session> [--json]
|
|
28
42
|
alp board [--project DIR] [--json]
|
|
29
43
|
alp <agents|skills|mcp|hooks> [--project DIR] [--json] the library: built-in, ~/.alp and project entries
|
|
44
|
+
alp skills --retired [--json] skills alp_skill_retire moved to ~/.alp/retired-skills
|
|
30
45
|
alp providers [--json] ACP and Antigravity providers in your library
|
|
31
46
|
alp teams [--project DIR] [--json] teams sessions run in: members, delegation, house rules
|
|
47
|
+
alp packs [--project DIR] [--json] optional skill packs ALP ships (backend, frontend, architecture, ...)
|
|
48
|
+
alp pack install <id> [--project [DIR]] [--assign] [--json] copy a pack's skills, agents and teams; existing entries are kept
|
|
32
49
|
alp agent <new|edit> <name> [--project [DIR]] [--from A] [-d text] [--provider P] [--model M] [--thinking T] [--mode M]
|
|
33
50
|
[--skills a,b] [--mcp a,b] [--hooks a,b] [--instructions FILE]
|
|
34
51
|
alp team <new|edit> <id> [--project [DIR]] [--from ID] [--label L] [-d text] [--main A] [--member name=role]...
|
|
35
52
|
[--member-model name=M]... [--member-thinking name=T]... [--delegate owner=a,b]... [--max-peers N]
|
|
36
53
|
[--supervisor A] [--supervisor-model M] [--supervisor-thinking T] [--no-supervisor] [--rules FILE]
|
|
37
|
-
alp skill new <name> [--project [DIR]] [--from S] [--file FILE]
|
|
54
|
+
alp skill <new|edit> <name> [--project [DIR]] [--from S] [--file FILE]
|
|
55
|
+
alp skill check [name|DIR] [--project [DIR]] [--strict] [--json] validate skills (format, references, links); exit 1 on errors
|
|
56
|
+
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
|
|
38
57
|
alp mcp add <name> [--project [DIR]] (--command C [--arg A]... [--env K=V]... [--cwd D] | --url U [--header K=V]...)
|
|
39
58
|
alp hook add <name> [--project [DIR]] --event E --command C [--blocking] [--timeout SEC] [--match-agent A] [--match-label L]
|
|
40
59
|
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
|
|
41
|
-
alp provider edit antigravity --read-only-mode instructions|reject opt into prompt-only read-only for advisory roles
|
|
42
60
|
alp <agent|team|skill|mcp|hook|provider> <rm|show> <name> [--project [DIR]] | <cp|mv> <from> <to> [--project [DIR]]
|
|
43
61
|
alp <mcp|hook|provider> test <name> [--project [DIR]] list an MCP server's tools; run a hook once; initialize a provider
|
|
44
62
|
without --project, changes go to your library in ~/.alp; built-in agents and teams are never changed
|
|
@@ -59,13 +77,17 @@ const USAGE = `Usage:
|
|
|
59
77
|
alp verify [--project DIR] [--task ID] [--json] run the project's verify commands; --task records the result
|
|
60
78
|
alp task reopen <id> [-m note]
|
|
61
79
|
alp task dep <add|rm> <id> [--after ID]... [--parent ID] [--related ID]...
|
|
62
|
-
alp task gate add <id> --human "question" | --timer +2h|ISO | --pr N|owner/repo#N | --run N|owner/repo#N
|
|
63
|
-
alp task gate
|
|
80
|
+
alp task gate add <id> --human "question" [--option answer]... | --timer +2h|ISO | --pr N|owner/repo#N | --run N|owner/repo#N
|
|
81
|
+
alp task gate clear <id> <gate> [--choice answer] [-m note] approve; main is told by mail
|
|
82
|
+
alp task gate reject <id> <gate> [-m reason] the gate stays open; main is told by mail
|
|
83
|
+
alp task gate rm <id> <gate> [-m note]
|
|
64
84
|
alp pause [codex|claude] [--now] [-m reason] | alp pause status hold delegation; --now parks running assignments
|
|
65
85
|
alp resume [codex|claude] lift a pause; parked assignments continue
|
|
86
|
+
alp models [--refresh] [--json] the models alpd offers now, from each provider (cached; refreshed every 6 h)
|
|
66
87
|
alp language [name | --reset] the language agents and ALP write to you in; default Vietnamese
|
|
67
88
|
alp recall <assignment|task> [--project DIR] [--json] <question> ask a finished assignment about its work
|
|
68
|
-
alp interrupt <session
|
|
89
|
+
alp interrupt <session>
|
|
90
|
+
alp compact <session>`;
|
|
69
91
|
|
|
70
92
|
class UsageError extends Error {}
|
|
71
93
|
|