@mumbrane/arrakis 0.4.0 → 0.6.0
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 +54 -1
- package/package.json +1 -1
- package/src/agent.js +49 -7
- package/src/checkpoints.js +83 -0
- package/src/cli.js +346 -11
- package/src/config.js +11 -0
- package/src/hooks.js +114 -0
- package/src/input.js +71 -1
- package/src/jobs.js +97 -0
- package/src/mcp.js +343 -0
- package/src/permissions.js +5 -1
- package/src/session.js +1 -1
- package/src/tools.js +29 -5
- package/src/tui.js +812 -0
- package/src/ui.js +33 -7
- package/src/update.js +33 -0
package/src/ui.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import readline from 'node:readline';
|
|
2
|
+
import fs from 'node:fs';
|
|
2
3
|
import os from 'node:os';
|
|
3
4
|
import { MarkdownStream, visibleLength } from './markdown.js';
|
|
4
5
|
|
|
@@ -62,9 +63,21 @@ export class UI {
|
|
|
62
63
|
|
|
63
64
|
start() {
|
|
64
65
|
if (this.rl || this.closed) return;
|
|
65
|
-
const rl = readline.createInterface({
|
|
66
|
+
const rl = readline.createInterface({
|
|
67
|
+
input: process.stdin,
|
|
68
|
+
output: process.stdout,
|
|
69
|
+
terminal: !!process.stdin.isTTY,
|
|
70
|
+
historySize: 1000,
|
|
71
|
+
removeHistoryDuplicates: true,
|
|
72
|
+
completer: this.completer ? (line) => this.completer(line) : undefined,
|
|
73
|
+
});
|
|
66
74
|
this.rl = rl;
|
|
67
75
|
if (this.history) rl.history = this.history;
|
|
76
|
+
else if (this.historyFile && this.fancy) {
|
|
77
|
+
try {
|
|
78
|
+
rl.history = fs.readFileSync(this.historyFile, 'utf8').split('\n').filter(Boolean).reverse().slice(0, 1000);
|
|
79
|
+
} catch {}
|
|
80
|
+
}
|
|
68
81
|
// While the agent works, typed text is queued but not echoed over its output.
|
|
69
82
|
if (typeof rl._writeToOutput === 'function') {
|
|
70
83
|
const write = rl._writeToOutput.bind(rl);
|
|
@@ -179,6 +192,11 @@ export class UI {
|
|
|
179
192
|
text = text.slice(0, -1) + '\n' + next;
|
|
180
193
|
}
|
|
181
194
|
if (text !== null && this.fancy) this.echoUser(text, queued);
|
|
195
|
+
if (text?.trim() && this.historyFile && this.fancy) {
|
|
196
|
+
try {
|
|
197
|
+
fs.appendFileSync(this.historyFile, text.replace(/\n/g, ' ') + '\n', { mode: 0o600 });
|
|
198
|
+
} catch {}
|
|
199
|
+
}
|
|
182
200
|
this.atLineStart = true;
|
|
183
201
|
return text;
|
|
184
202
|
}
|
|
@@ -231,8 +249,9 @@ export class UI {
|
|
|
231
249
|
};
|
|
232
250
|
const draw = () => {
|
|
233
251
|
const secs = Math.floor((Date.now() - spinner.started) / 1000);
|
|
234
|
-
|
|
235
|
-
|
|
252
|
+
let line = `${lc.accent(SPINNER[spinner.frame++ % SPINNER.length])} ${lc.sand(spinner.label + '…')} ${lc.gray(`(${secs}s · esc to interrupt)`)}`;
|
|
253
|
+
if (spinner.detail) line += lc.gray(` ${spinner.detail}`);
|
|
254
|
+
stream.write(`\r\x1b[2K${truncate(line, this.width)}`);
|
|
236
255
|
spinner.drawn = true;
|
|
237
256
|
};
|
|
238
257
|
spinner.timer = setInterval(draw, 90);
|
|
@@ -241,6 +260,10 @@ export class UI {
|
|
|
241
260
|
draw();
|
|
242
261
|
}
|
|
243
262
|
|
|
263
|
+
spinnerDetail(text) {
|
|
264
|
+
if (this.spinner) this.spinner.detail = String(text).replace(/\x1b\[[0-9;]*[A-Za-z]/g, '').slice(0, 200);
|
|
265
|
+
}
|
|
266
|
+
|
|
244
267
|
clearSpinnerLine() {
|
|
245
268
|
if (this.spinner?.drawn) {
|
|
246
269
|
this.spinner.stream.write('\r\x1b[2K');
|
|
@@ -294,7 +317,7 @@ export class UI {
|
|
|
294
317
|
const lc = this.lc;
|
|
295
318
|
const s = String(summary ?? '').split('\n')[0];
|
|
296
319
|
const label = TOOL_LABELS[name] ?? name;
|
|
297
|
-
const head = prefix ? ` ${lc.gray('⎿')} ${lc.gray(prefix)} ` : `${this.atLineStart ? '' : '\n'}${lc.accent('
|
|
320
|
+
const head = prefix ? ` ${lc.gray('⎿')} ${lc.gray(prefix)} ` : `${this.atLineStart ? '' : '\n'}${lc.accent('⏺')} `;
|
|
298
321
|
this.write(this.log, truncate(`${head}${lc.bold(label)}${s ? lc.gray(`(${s})`) : ''}`, this.width) + '\n');
|
|
299
322
|
}
|
|
300
323
|
|
|
@@ -340,7 +363,7 @@ export class UI {
|
|
|
340
363
|
return 'no';
|
|
341
364
|
}
|
|
342
365
|
|
|
343
|
-
banner({ version, model, provider, cwd, instructions = [], resumed }) {
|
|
366
|
+
banner({ version, model, provider, cwd, instructions = [], resumed, mcp = [], hooks = 0, update }) {
|
|
344
367
|
const c = this.c;
|
|
345
368
|
if (!this.fancy) {
|
|
346
369
|
this.write(this.out, `\n${c.accent(c.bold(' ◆ arrakis'))} ${c.dim(`v${version}`)}\n`);
|
|
@@ -357,12 +380,15 @@ export class UI {
|
|
|
357
380
|
];
|
|
358
381
|
if (instructions.length) rows.push(`${c.gray('notes ')} ${instructions.map((f) => tildify(f)).join(', ')}`);
|
|
359
382
|
if (resumed) rows.push(`${c.gray('session ')} ${resumed}`);
|
|
360
|
-
rows.push(
|
|
383
|
+
if (mcp.length) rows.push(`${c.gray('mcp ')} ${mcp.map((s) => (s.status === 'connected' ? `${s.name} ${c.gray(`(${s.tools.length})`)}` : c.red(`${s.name} ✗`))).join(', ')}`);
|
|
384
|
+
if (hooks) rows.push(`${c.gray('hooks ')} ${hooks} active`);
|
|
385
|
+
rows.push('', c.gray('/help commands · @file attach · /plan plan first · /undo revert · esc interrupt'));
|
|
361
386
|
const inner = Math.min(this.width - 4, Math.max(...rows.map(visibleLength)) + 2);
|
|
362
387
|
const line = (s) => `${c.accent('│')} ${truncate(s, inner)}${' '.repeat(Math.max(0, inner - visibleLength(truncate(s, inner))))} ${c.accent('│')}`;
|
|
363
388
|
const out = [c.accent(`╭${'─'.repeat(inner + 2)}╮`), ...rows.map(line), c.accent(`╰${'─'.repeat(inner + 2)}╯`)];
|
|
364
389
|
this.write(this.out, '\n' + out.join('\n') + '\n');
|
|
365
|
-
if (
|
|
390
|
+
if (update) this.write(this.out, ` ${c.accent('↑')} ${c.bold(`arrakis ${update} is available`)} ${c.gray('· npm install -g @mumbrane/arrakis')}\n`);
|
|
391
|
+
else if (!instructions.length) this.write(this.out, c.gray(' Tip: run /init to have arrakis write project notes (ARRAKIS.md) for this folder.\n'));
|
|
366
392
|
}
|
|
367
393
|
|
|
368
394
|
info(msg) {
|
package/src/update.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Once a day, check npm for a newer arrakis and tell the user.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { HOME_DIR } from './config.js';
|
|
5
|
+
import { VERSION } from './version.js';
|
|
6
|
+
|
|
7
|
+
const STATE = path.join(HOME_DIR, 'state.json');
|
|
8
|
+
const DAY = 24 * 60 * 60 * 1000;
|
|
9
|
+
|
|
10
|
+
const newer = (a, b) => {
|
|
11
|
+
const pa = a.split(/[.-]/).map(Number);
|
|
12
|
+
const pb = b.split(/[.-]/).map(Number);
|
|
13
|
+
for (let i = 0; i < 3; i++) if ((pa[i] || 0) !== (pb[i] || 0)) return (pa[i] || 0) > (pb[i] || 0);
|
|
14
|
+
return false;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export async function checkForUpdate() {
|
|
18
|
+
if (process.env.ARRAKIS_NO_UPDATE_CHECK || process.env.CI) return null;
|
|
19
|
+
let state = {};
|
|
20
|
+
try {
|
|
21
|
+
state = JSON.parse(fs.readFileSync(STATE, 'utf8'));
|
|
22
|
+
} catch {}
|
|
23
|
+
if (!state.lastCheck || Date.now() - state.lastCheck > DAY) {
|
|
24
|
+
try {
|
|
25
|
+
const res = await fetch('https://registry.npmjs.org/@mumbrane/arrakis/latest', { signal: AbortSignal.timeout(2000) });
|
|
26
|
+
if (res.ok) state.latest = (await res.json()).version;
|
|
27
|
+
state.lastCheck = Date.now();
|
|
28
|
+
fs.mkdirSync(HOME_DIR, { recursive: true });
|
|
29
|
+
fs.writeFileSync(STATE, JSON.stringify(state));
|
|
30
|
+
} catch {}
|
|
31
|
+
}
|
|
32
|
+
return state.latest && newer(state.latest, VERSION) ? state.latest : null;
|
|
33
|
+
}
|