reasonally 0.1.0 → 0.3.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 +143 -5
- package/dist/agent/accumulate.js +146 -0
- package/dist/agent/client.js +174 -0
- package/dist/agent/compact.js +79 -0
- package/dist/agent/cost.js +22 -0
- package/dist/agent/loop-constants.js +3 -0
- package/dist/agent/loop.js +559 -0
- package/dist/agent/mcp-config.js +72 -0
- package/dist/agent/mcp.js +194 -0
- package/dist/agent/permissions.js +116 -0
- package/dist/agent/prompt.js +98 -0
- package/dist/agent/session.js +196 -0
- package/dist/agent/sse.js +46 -0
- package/dist/agent/tools/bash.js +176 -0
- package/dist/agent/tools/diff.js +33 -0
- package/dist/agent/tools/files.js +270 -0
- package/dist/agent/tools/index.js +21 -0
- package/dist/agent/tools/paths.js +43 -0
- package/dist/agent/tools/search.js +288 -0
- package/dist/agent/tools/task.js +42 -0
- package/dist/agent/tools/todo.js +59 -0
- package/dist/agent/tools/types.js +57 -0
- package/dist/agent/types.js +2 -0
- package/dist/api.js +5 -1
- package/dist/browser/command.js +93 -0
- package/dist/browser/guards.js +138 -0
- package/dist/browser/pairing.js +123 -0
- package/dist/browser/protocol.js +172 -0
- package/dist/browser/server.js +157 -0
- package/dist/browser/sessions.js +478 -0
- package/dist/catalog.js +12 -0
- package/dist/cli.js +43 -3
- package/dist/config.js +17 -4
- package/dist/tui/app.js +869 -0
- package/dist/tui/args.js +32 -0
- package/dist/tui/commands.js +38 -0
- package/dist/tui/components.js +375 -0
- package/dist/tui/format.js +116 -0
- package/dist/tui/node-version.js +7 -0
- package/dist/tui/start.js +135 -0
- package/dist/tui/theme.js +36 -0
- package/package.json +11 -3
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { realpath } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { ProcessTerminal } from "@earendil-works/pi-tui";
|
|
4
|
+
import { fetchAccount, fetchModels } from "../api.js";
|
|
5
|
+
import { agentModels, findModel } from "../catalog.js";
|
|
6
|
+
import { loginAndSave } from "../cli.js";
|
|
7
|
+
import { configDir, readCredentials, readLastModel, resolveSession, writeLastModel, } from "../config.js";
|
|
8
|
+
import { mcpConfigPath, readMcpConfig } from "../agent/mcp-config.js";
|
|
9
|
+
import { gitBranch, loadInstructions, systemPrompt } from "../agent/prompt.js";
|
|
10
|
+
import { listSessions, loadSession, sessionsDir } from "../agent/session.js";
|
|
11
|
+
import { shellFor } from "../agent/tools/bash.js";
|
|
12
|
+
import { App } from "./app.js";
|
|
13
|
+
/** The key the agent's last model is remembered under in state.json (not a harness id). */
|
|
14
|
+
export const MODEL_MEMORY_KEY = "tui";
|
|
15
|
+
async function currentSession() {
|
|
16
|
+
return resolveSession(process.env, await readCredentials());
|
|
17
|
+
}
|
|
18
|
+
const balanceOf = (session) => fetchAccount(session.appUrl, session.apiKey).then((account) => account.balance, () => null);
|
|
19
|
+
/** Logs in if needed, loads the catalog, then runs the agent's TUI until the user quits. */
|
|
20
|
+
export async function startTui(args, log) {
|
|
21
|
+
let session = await currentSession();
|
|
22
|
+
if (!session) {
|
|
23
|
+
log("Log in to start.");
|
|
24
|
+
await loginAndSave(log);
|
|
25
|
+
session = await currentSession();
|
|
26
|
+
if (!session)
|
|
27
|
+
throw new Error("The login didn't complete. Run `reasonally login`.");
|
|
28
|
+
log("");
|
|
29
|
+
}
|
|
30
|
+
const [catalog, balance] = await Promise.all([
|
|
31
|
+
fetchModels(session.apiBaseUrl, session.apiKey),
|
|
32
|
+
balanceOf(session),
|
|
33
|
+
]);
|
|
34
|
+
const models = agentModels(catalog);
|
|
35
|
+
let model = null;
|
|
36
|
+
if (args.model) {
|
|
37
|
+
const match = findModel(catalog, args.model);
|
|
38
|
+
if (!match.ok) {
|
|
39
|
+
log(`Unknown model "${args.model}".`);
|
|
40
|
+
if (match.suggestions.length)
|
|
41
|
+
log(`Did you mean:\n ${match.suggestions.join("\n ")}`);
|
|
42
|
+
log("See all models with `reasonally models`, or pick one in the agent with /model.");
|
|
43
|
+
return 1;
|
|
44
|
+
}
|
|
45
|
+
if (!match.model.tools) {
|
|
46
|
+
log(`${match.model.id} can't use tools, so it can't work as an agent. Pick another one.`);
|
|
47
|
+
return 1;
|
|
48
|
+
}
|
|
49
|
+
model = match.model;
|
|
50
|
+
await writeLastModel(MODEL_MEMORY_KEY, model.id).catch(() => { });
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const last = await readLastModel(MODEL_MEMORY_KEY);
|
|
54
|
+
model = models.find((m) => m.id === last) ?? null;
|
|
55
|
+
}
|
|
56
|
+
const cwd = await realpath(process.cwd());
|
|
57
|
+
const home = await realpath(homedir()).catch(() => homedir());
|
|
58
|
+
const config = configDir();
|
|
59
|
+
const [instructions, branch] = await Promise.all([
|
|
60
|
+
loadInstructions(cwd, home, config),
|
|
61
|
+
gitBranch(cwd),
|
|
62
|
+
]);
|
|
63
|
+
// MCP servers come only from the user's own config; the SDK loads only if there are any.
|
|
64
|
+
const mcpPath = mcpConfigPath(config);
|
|
65
|
+
const { servers, errors: mcpErrors } = await readMcpConfig(mcpPath);
|
|
66
|
+
const mcp = Object.keys(servers).length
|
|
67
|
+
? new (await import("../agent/mcp.js")).McpManager(servers, { cwd })
|
|
68
|
+
: null;
|
|
69
|
+
const sessions = sessionsDir(config, cwd);
|
|
70
|
+
let resume = null;
|
|
71
|
+
let startNotice;
|
|
72
|
+
if (args.continue) {
|
|
73
|
+
const [latest] = await listSessions(sessions);
|
|
74
|
+
resume = latest ? await loadSession(latest.path) : null;
|
|
75
|
+
if (!resume)
|
|
76
|
+
startNotice = "No saved conversation in this folder yet; starting a new one.";
|
|
77
|
+
// Continue with the conversation's own model unless one was asked for.
|
|
78
|
+
else if (!args.model)
|
|
79
|
+
model = models.find((m) => m.id === resume.model) ?? model;
|
|
80
|
+
}
|
|
81
|
+
const shell = shellFor(process.env).name;
|
|
82
|
+
const promptFor = (m) => systemPrompt({ cwd, home, platform: process.platform, shell, date: new Date(), model: m.id, branch }, instructions);
|
|
83
|
+
return await new Promise((resolve) => {
|
|
84
|
+
let app = null;
|
|
85
|
+
const quit = (code) => app?.exit(code);
|
|
86
|
+
const onSignal = () => quit(130);
|
|
87
|
+
const onCrash = (error) => {
|
|
88
|
+
quit(1);
|
|
89
|
+
console.error(`Reasonally's agent crashed: ${error?.stack ?? error}`);
|
|
90
|
+
};
|
|
91
|
+
process.on("SIGTERM", onSignal);
|
|
92
|
+
process.on("SIGHUP", onSignal);
|
|
93
|
+
process.on("uncaughtException", onCrash);
|
|
94
|
+
process.on("unhandledRejection", onCrash);
|
|
95
|
+
app = new App({
|
|
96
|
+
terminal: new ProcessTerminal(),
|
|
97
|
+
session: session,
|
|
98
|
+
models,
|
|
99
|
+
model,
|
|
100
|
+
balance,
|
|
101
|
+
cwd,
|
|
102
|
+
home,
|
|
103
|
+
configDir: config,
|
|
104
|
+
sessionsDir: sessions,
|
|
105
|
+
mcp,
|
|
106
|
+
mcpErrors,
|
|
107
|
+
mcpConfigPath: mcpPath,
|
|
108
|
+
resume,
|
|
109
|
+
pickSession: args.resume,
|
|
110
|
+
startNotice,
|
|
111
|
+
mode: args.yes ? "full" : "ask",
|
|
112
|
+
systemPrompt: promptFor,
|
|
113
|
+
fetchBalance: balanceOf,
|
|
114
|
+
login: async (report) => {
|
|
115
|
+
await loginAndSave(report);
|
|
116
|
+
const next = await currentSession();
|
|
117
|
+
if (!next)
|
|
118
|
+
throw new Error("The login didn't complete.");
|
|
119
|
+
return next;
|
|
120
|
+
},
|
|
121
|
+
rememberModel: (id) => writeLastModel(MODEL_MEMORY_KEY, id),
|
|
122
|
+
onExit: (code, summary) => {
|
|
123
|
+
if (summary)
|
|
124
|
+
process.stdout.write(`${summary}\n`);
|
|
125
|
+
process.off("SIGTERM", onSignal);
|
|
126
|
+
process.off("SIGHUP", onSignal);
|
|
127
|
+
process.off("uncaughtException", onCrash);
|
|
128
|
+
process.off("unhandledRejection", onCrash);
|
|
129
|
+
resolve(code);
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
app.start();
|
|
133
|
+
void mcp?.start();
|
|
134
|
+
});
|
|
135
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminal styles. Only the 16 standard colors, so text follows the user's own palette on light
|
|
3
|
+
* and dark backgrounds; `NO_COLOR` turns colors off (bold/dim stay, as the convention allows).
|
|
4
|
+
*/
|
|
5
|
+
const noColor = () => Boolean(process.env.NO_COLOR);
|
|
6
|
+
const sgr = (open, close, isColor) => (text) => isColor && noColor() ? text : `\x1b[${open}m${text}\x1b[${close}m`;
|
|
7
|
+
export const style = {
|
|
8
|
+
bold: sgr(1, 22, false),
|
|
9
|
+
dim: sgr(2, 22, false),
|
|
10
|
+
italic: sgr(3, 23, false),
|
|
11
|
+
underline: sgr(4, 24, false),
|
|
12
|
+
inverse: sgr(7, 27, false),
|
|
13
|
+
strike: sgr(9, 29, false),
|
|
14
|
+
red: sgr(31, 39, true),
|
|
15
|
+
green: sgr(32, 39, true),
|
|
16
|
+
yellow: sgr(33, 39, true),
|
|
17
|
+
blue: sgr(34, 39, true),
|
|
18
|
+
magenta: sgr(35, 39, true),
|
|
19
|
+
cyan: sgr(36, 39, true),
|
|
20
|
+
gray: sgr(90, 39, true),
|
|
21
|
+
};
|
|
22
|
+
/** Roles, so the look is decided in one place. */
|
|
23
|
+
export const theme = {
|
|
24
|
+
brand: (t) => style.bold(style.cyan(t)),
|
|
25
|
+
accent: style.cyan,
|
|
26
|
+
muted: style.gray,
|
|
27
|
+
faint: style.dim,
|
|
28
|
+
success: style.green,
|
|
29
|
+
warning: style.yellow,
|
|
30
|
+
error: style.red,
|
|
31
|
+
added: style.green,
|
|
32
|
+
removed: style.red,
|
|
33
|
+
hunk: style.cyan,
|
|
34
|
+
user: style.bold,
|
|
35
|
+
border: style.gray,
|
|
36
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reasonally",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.3.0",
|
|
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": {
|
|
7
7
|
"reasonally": "dist/index.js"
|
|
@@ -12,14 +12,22 @@
|
|
|
12
12
|
"engines": {
|
|
13
13
|
"node": ">=20"
|
|
14
14
|
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@earendil-works/pi-tui": "1.5.0",
|
|
17
|
+
"@modelcontextprotocol/sdk": "1.32.2",
|
|
18
|
+
"diff": "9.0.0",
|
|
19
|
+
"playwright-core": "1.64.1"
|
|
20
|
+
},
|
|
15
21
|
"scripts": {
|
|
16
22
|
"build": "tsc -p tsconfig.build.json",
|
|
17
23
|
"prepublishOnly": "npm run build"
|
|
18
24
|
},
|
|
19
25
|
"keywords": [
|
|
20
26
|
"llm",
|
|
21
|
-
"cli",
|
|
22
27
|
"coding-agent",
|
|
28
|
+
"tui",
|
|
29
|
+
"mcp",
|
|
30
|
+
"cli",
|
|
23
31
|
"opencode",
|
|
24
32
|
"crush",
|
|
25
33
|
"cline",
|