reasonally 0.3.0 → 0.5.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 +33 -7
- package/dist/agent/accumulate.js +4 -0
- package/dist/agent/client.js +53 -1
- package/dist/agent/loop-constants.js +8 -0
- package/dist/agent/loop.js +243 -34
- package/dist/agent/mcp.js +3 -2
- package/dist/agent/permissions.js +99 -3
- package/dist/agent/prompt.js +16 -2
- package/dist/agent/readonly-command.js +315 -0
- package/dist/agent/session.js +234 -12
- package/dist/agent/tools/bash.js +22 -2
- package/dist/agent/tools/index.js +11 -0
- package/dist/agent/tools/plan.js +101 -0
- package/dist/agent/tools/task.js +2 -2
- package/dist/agent/tools/web/ddg.js +131 -0
- package/dist/agent/tools/web/dom.js +9 -0
- package/dist/agent/tools/web/html.js +90 -0
- package/dist/agent/tools/web/page.js +218 -0
- package/dist/agent/tools/web-fetch.js +175 -0
- package/dist/agent/tools/web-search.js +158 -0
- package/dist/api.js +3 -1
- package/dist/cli.js +1 -1
- package/dist/login.js +41 -13
- package/dist/tui/app.js +176 -30
- package/dist/tui/args.js +16 -1
- package/dist/tui/commands.js +5 -1
- package/dist/tui/components.js +105 -1
- package/dist/tui/external-editor.js +103 -0
- package/dist/tui/format.js +9 -1
- package/dist/tui/start.js +10 -4
- package/package.json +5 -2
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Editing a plan in the person's own editor (`$VISUAL`, then `$EDITOR`, then nano or vi; Notepad
|
|
3
|
+
* on Windows), the way `git commit` does. The plan goes in a private temporary file, deleted
|
|
4
|
+
* afterwards whatever happens.
|
|
5
|
+
*/
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
import { constants } from "node:fs";
|
|
8
|
+
import { access, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
9
|
+
import { tmpdir } from "node:os";
|
|
10
|
+
import { delimiter, join } from "node:path";
|
|
11
|
+
const isWindows = process.platform === "win32";
|
|
12
|
+
/** An editor that returns sooner than this without a change probably didn't wait for you. */
|
|
13
|
+
const QUICK_MS = 1000;
|
|
14
|
+
async function onPath(name, env) {
|
|
15
|
+
for (const dir of (env.PATH ?? "").split(delimiter)) {
|
|
16
|
+
if (!dir)
|
|
17
|
+
continue;
|
|
18
|
+
try {
|
|
19
|
+
await access(join(dir, name), constants.X_OK);
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// keep looking
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
/** The editor command line to run: the person's choice, else one that's sure to exist. */
|
|
29
|
+
export async function editorCommand(env) {
|
|
30
|
+
const chosen = env.VISUAL?.trim() || env.EDITOR?.trim();
|
|
31
|
+
if (chosen)
|
|
32
|
+
return chosen;
|
|
33
|
+
if (isWindows)
|
|
34
|
+
return "notepad";
|
|
35
|
+
return (await onPath("nano", env)) ? "nano" : "vi";
|
|
36
|
+
}
|
|
37
|
+
/** Runs `editor` on `file` with the terminal handed over, until it exits. */
|
|
38
|
+
function runEditor(editor, file, env) {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
// Through the shell, so EDITOR="code --wait" works; the file is passed as $1, never parsed.
|
|
41
|
+
const child = isWindows
|
|
42
|
+
? spawn(editor, [file], { stdio: "inherit", env, shell: true })
|
|
43
|
+
: spawn(env.SHELL || "/bin/sh", ["-c", `${editor} "$1"`, "reasonally-editor", file], {
|
|
44
|
+
stdio: "inherit",
|
|
45
|
+
env,
|
|
46
|
+
});
|
|
47
|
+
child.on("error", reject);
|
|
48
|
+
child.on("exit", (code) => resolve(code));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/** Opens `text` in the person's editor and reports what they did with it. */
|
|
52
|
+
export async function editInEditor(text, options = {}) {
|
|
53
|
+
const env = options.env ?? process.env;
|
|
54
|
+
const now = options.now ?? Date.now;
|
|
55
|
+
const dir = await mkdtemp(join(tmpdir(), "reasonally-plan-"));
|
|
56
|
+
const file = join(dir, "plan.md");
|
|
57
|
+
// Ctrl+C meant for the editor shouldn't stop us too while it has the terminal.
|
|
58
|
+
const ignore = () => { };
|
|
59
|
+
process.on("SIGINT", ignore);
|
|
60
|
+
try {
|
|
61
|
+
await writeFile(file, `${text}\n`, { mode: 0o600 });
|
|
62
|
+
const editor = await editorCommand(env);
|
|
63
|
+
const started = now();
|
|
64
|
+
let code;
|
|
65
|
+
try {
|
|
66
|
+
code = await runEditor(editor, file, env);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
return { kind: "failed", message: error.message };
|
|
70
|
+
}
|
|
71
|
+
// 126/127: the shell couldn't run it (not found, not executable).
|
|
72
|
+
if (code === 126 || code === 127)
|
|
73
|
+
return { kind: "failed", message: `${editor} didn't start.` };
|
|
74
|
+
if (code !== 0)
|
|
75
|
+
return { kind: "unchanged", quick: false };
|
|
76
|
+
const edited = (await readFile(file, "utf8")).trim();
|
|
77
|
+
if (!edited)
|
|
78
|
+
return { kind: "empty" };
|
|
79
|
+
if (edited === text.trim())
|
|
80
|
+
return { kind: "unchanged", quick: now() - started < QUICK_MS };
|
|
81
|
+
return { kind: "edited", text: edited };
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
process.off("SIGINT", ignore);
|
|
85
|
+
await rm(dir, { recursive: true, force: true });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** How many lines differ between two versions (each line counted once, moved lines aside). */
|
|
89
|
+
export function changedLines(before, after) {
|
|
90
|
+
const left = new Map();
|
|
91
|
+
for (const line of before.split("\n"))
|
|
92
|
+
left.set(line, (left.get(line) ?? 0) + 1);
|
|
93
|
+
let added = 0;
|
|
94
|
+
for (const line of after.split("\n")) {
|
|
95
|
+
const n = left.get(line) ?? 0;
|
|
96
|
+
if (n > 0)
|
|
97
|
+
left.set(line, n - 1);
|
|
98
|
+
else
|
|
99
|
+
added++;
|
|
100
|
+
}
|
|
101
|
+
const removed = [...left.values()].reduce((a, b) => a + b, 0);
|
|
102
|
+
return Math.max(added, removed);
|
|
103
|
+
}
|
package/dist/tui/format.js
CHANGED
|
@@ -13,9 +13,11 @@ export function formatTokens(n) {
|
|
|
13
13
|
return `${+(n / 1000).toFixed(1)}K`;
|
|
14
14
|
return String(n);
|
|
15
15
|
}
|
|
16
|
+
/** The mode as the status line names it; Plan mode gets its pause sign. */
|
|
17
|
+
export const modeStatus = (mode) => `${mode === "plan" ? "⏸ " : ""}${MODE_LABELS[mode]} (shift+tab)`;
|
|
16
18
|
/** "Ask before edits (shift+tab) · 12% context · ~$0.04 · $18.20 left" */
|
|
17
19
|
export function statusLine(s) {
|
|
18
|
-
const parts = [
|
|
20
|
+
const parts = [modeStatus(s.mode)];
|
|
19
21
|
if (s.contextTokens !== null) {
|
|
20
22
|
const pct = Math.min(100, Math.round((s.contextTokens / s.contextLength) * 100));
|
|
21
23
|
parts.push(`${pct === 0 && s.contextTokens > 0 ? "<1" : pct}% context`);
|
|
@@ -114,3 +116,9 @@ export function compactionNote(before, after, contextLength) {
|
|
|
114
116
|
: `${formatTokens(before)} → ${formatTokens(after)} tokens`;
|
|
115
117
|
return `Summarized earlier conversation to free up context (${change}).`;
|
|
116
118
|
}
|
|
119
|
+
/** Where a saved conversation is open right now, when it can't be continued here. */
|
|
120
|
+
export function openElsewhere(holder) {
|
|
121
|
+
return holder.surface === "desktop"
|
|
122
|
+
? "That conversation is open in the Reasonally app."
|
|
123
|
+
: "That conversation is open in another terminal.";
|
|
124
|
+
}
|
package/dist/tui/start.js
CHANGED
|
@@ -6,10 +6,12 @@ import { agentModels, findModel } from "../catalog.js";
|
|
|
6
6
|
import { loginAndSave } from "../cli.js";
|
|
7
7
|
import { configDir, readCredentials, readLastModel, resolveSession, writeLastModel, } from "../config.js";
|
|
8
8
|
import { mcpConfigPath, readMcpConfig } from "../agent/mcp-config.js";
|
|
9
|
+
import { DEFAULT_WEB_POLICY, WEB_OFF } from "../agent/permissions.js";
|
|
9
10
|
import { gitBranch, loadInstructions, systemPrompt } from "../agent/prompt.js";
|
|
10
|
-
import { listSessions, loadSession, sessionsDir } from "../agent/session.js";
|
|
11
|
+
import { listSessions, loadSession, sessionHolder, sessionsDir, } from "../agent/session.js";
|
|
11
12
|
import { shellFor } from "../agent/tools/bash.js";
|
|
12
13
|
import { App } from "./app.js";
|
|
14
|
+
import { openElsewhere } from "./format.js";
|
|
13
15
|
/** The key the agent's last model is remembered under in state.json (not a harness id). */
|
|
14
16
|
export const MODEL_MEMORY_KEY = "tui";
|
|
15
17
|
async function currentSession() {
|
|
@@ -71,8 +73,11 @@ export async function startTui(args, log) {
|
|
|
71
73
|
let startNotice;
|
|
72
74
|
if (args.continue) {
|
|
73
75
|
const [latest] = await listSessions(sessions);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
const holder = latest ? await sessionHolder(latest.path) : null;
|
|
77
|
+
resume = latest && !holder ? await loadSession(latest.path) : null;
|
|
78
|
+
if (holder)
|
|
79
|
+
startNotice = `${openElsewhere(holder)} Starting a new one here.`;
|
|
80
|
+
else if (!resume)
|
|
76
81
|
startNotice = "No saved conversation in this folder yet; starting a new one.";
|
|
77
82
|
// Continue with the conversation's own model unless one was asked for.
|
|
78
83
|
else if (!args.model)
|
|
@@ -108,7 +113,8 @@ export async function startTui(args, log) {
|
|
|
108
113
|
resume,
|
|
109
114
|
pickSession: args.resume,
|
|
110
115
|
startNotice,
|
|
111
|
-
mode: args.yes ? "full" : "ask",
|
|
116
|
+
mode: args.plan ? "plan" : args.yes ? "full" : "ask",
|
|
117
|
+
web: args.noWeb ? WEB_OFF : DEFAULT_WEB_POLICY,
|
|
112
118
|
systemPrompt: promptFor,
|
|
113
119
|
fetchBalance: balanceOf,
|
|
114
120
|
login: async (report) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reasonally",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Reasonally's coding agent in your terminal, plus the coding agents you already use, on Reasonally models.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -15,8 +15,11 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@earendil-works/pi-tui": "1.5.0",
|
|
17
17
|
"@modelcontextprotocol/sdk": "1.32.2",
|
|
18
|
+
"@mozilla/readability": "0.6.0",
|
|
18
19
|
"diff": "9.0.0",
|
|
19
|
-
"
|
|
20
|
+
"linkedom": "0.18.15",
|
|
21
|
+
"playwright-core": "1.64.1",
|
|
22
|
+
"turndown": "7.2.5"
|
|
20
23
|
},
|
|
21
24
|
"scripts": {
|
|
22
25
|
"build": "tsc -p tsconfig.build.json",
|