reasonally 0.2.0 → 0.4.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 +137 -5
- package/dist/agent/accumulate.js +150 -0
- package/dist/agent/client.js +176 -0
- package/dist/agent/compact.js +79 -0
- package/dist/agent/cost.js +22 -0
- package/dist/agent/loop-constants.js +11 -0
- package/dist/agent/loop.js +734 -0
- package/dist/agent/mcp-config.js +72 -0
- package/dist/agent/mcp.js +195 -0
- package/dist/agent/permissions.js +153 -0
- package/dist/agent/prompt.js +112 -0
- package/dist/agent/readonly-command.js +315 -0
- package/dist/agent/session.js +417 -0
- package/dist/agent/sse.js +46 -0
- package/dist/agent/tools/bash.js +196 -0
- package/dist/agent/tools/diff.js +33 -0
- package/dist/agent/tools/files.js +270 -0
- package/dist/agent/tools/index.js +23 -0
- package/dist/agent/tools/paths.js +43 -0
- package/dist/agent/tools/plan.js +101 -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 +8 -2
- package/dist/catalog.js +12 -0
- package/dist/cli.js +37 -3
- package/dist/config.js +17 -4
- package/dist/login.js +41 -13
- package/dist/tui/app.js +1010 -0
- package/dist/tui/args.js +43 -0
- package/dist/tui/commands.js +42 -0
- package/dist/tui/components.js +479 -0
- package/dist/tui/external-editor.js +103 -0
- package/dist/tui/format.js +124 -0
- package/dist/tui/node-version.js +7 -0
- package/dist/tui/start.js +139 -0
- package/dist/tui/theme.js +36 -0
- package/package.json +8 -3
package/dist/login.js
CHANGED
|
@@ -13,6 +13,8 @@ export function authorizeUrl(appUrl, params) {
|
|
|
13
13
|
state: params.state,
|
|
14
14
|
device: params.device,
|
|
15
15
|
});
|
|
16
|
+
if (params.client)
|
|
17
|
+
query.set("client", params.client);
|
|
16
18
|
return `${appUrl}/cli/authorize?${query}`;
|
|
17
19
|
}
|
|
18
20
|
/** Interprets a request to the loopback server. Only `/callback` with our `state` counts. */
|
|
@@ -43,10 +45,35 @@ function openBrowser(url) {
|
|
|
43
45
|
// same
|
|
44
46
|
}
|
|
45
47
|
}
|
|
48
|
+
/** Thrown when the caller's `signal` stops a login that was waiting for the browser. */
|
|
49
|
+
export class LoginCancelled extends Error {
|
|
50
|
+
constructor() {
|
|
51
|
+
super("Login was cancelled.");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Thrown when the user pressed Cancel on the approval page. */
|
|
55
|
+
export class LoginDenied extends Error {
|
|
56
|
+
constructor() {
|
|
57
|
+
super("Login was cancelled in the browser.");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** Thrown when nobody approved in the browser in time. */
|
|
61
|
+
export class LoginTimedOut extends Error {
|
|
62
|
+
constructor() {
|
|
63
|
+
super("Timed out waiting for approval in the browser. Run the login again.");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
46
66
|
/** Waits for the browser to come back to the loopback server with a code (or a refusal). */
|
|
47
|
-
function waitForCallback(server, state) {
|
|
67
|
+
function waitForCallback(server, state, { signal, returnTo = "your terminal" } = {}) {
|
|
48
68
|
return new Promise((resolve, reject) => {
|
|
49
|
-
const timer = setTimeout(() => reject(new
|
|
69
|
+
const timer = setTimeout(() => reject(new LoginTimedOut()), LOGIN_TIMEOUT_MS);
|
|
70
|
+
const onAbort = () => {
|
|
71
|
+
clearTimeout(timer);
|
|
72
|
+
reject(new LoginCancelled());
|
|
73
|
+
};
|
|
74
|
+
if (signal?.aborted)
|
|
75
|
+
return onAbort();
|
|
76
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
50
77
|
server.on("request", (req, res) => {
|
|
51
78
|
const result = readCallback(req.url ?? "/", state);
|
|
52
79
|
const reply = (status, title, body) => {
|
|
@@ -56,26 +83,24 @@ function waitForCallback(server, state) {
|
|
|
56
83
|
if (result.kind === "ignore")
|
|
57
84
|
return reply(404, "Not found", "Nothing to see here.");
|
|
58
85
|
clearTimeout(timer);
|
|
86
|
+
signal?.removeEventListener("abort", onAbort);
|
|
59
87
|
if (result.kind === "code") {
|
|
60
|
-
reply(200, "You're logged in",
|
|
88
|
+
reply(200, "You're logged in", `You can close this tab and go back to ${returnTo}.`);
|
|
61
89
|
resolve(result.code);
|
|
62
90
|
}
|
|
63
91
|
else if (result.kind === "denied") {
|
|
64
92
|
reply(200, "Login cancelled", "You can close this tab.");
|
|
65
|
-
reject(new
|
|
93
|
+
reject(new LoginDenied());
|
|
66
94
|
}
|
|
67
95
|
else {
|
|
68
|
-
reply(400, "Login failed",
|
|
96
|
+
reply(400, "Login failed", `This response didn't match the login in ${returnTo}.`);
|
|
69
97
|
reject(new Error("The browser returned an unexpected response. Run the login again."));
|
|
70
98
|
}
|
|
71
99
|
});
|
|
72
100
|
});
|
|
73
101
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
* exchanges it (with the PKCE verifier) for an API key.
|
|
77
|
-
*/
|
|
78
|
-
export async function browserLogin(appUrl, log, { open = true } = {}) {
|
|
102
|
+
export async function browserLogin(appUrl, log, options = {}) {
|
|
103
|
+
const { open = true } = options;
|
|
79
104
|
const pkce = createPkce();
|
|
80
105
|
const server = createServer();
|
|
81
106
|
await new Promise((resolve, reject) => {
|
|
@@ -89,21 +114,24 @@ export async function browserLogin(appUrl, log, { open = true } = {}) {
|
|
|
89
114
|
redirectUri,
|
|
90
115
|
challenge: pkce.challenge,
|
|
91
116
|
state: pkce.state,
|
|
92
|
-
device: hostname().replace(/\.local$/, ""),
|
|
117
|
+
device: options.device ?? hostname().replace(/\.local$/, ""),
|
|
118
|
+
client: options.client,
|
|
93
119
|
});
|
|
120
|
+
options.onUrl?.(url);
|
|
94
121
|
if (open) {
|
|
95
122
|
log("Opening your browser to approve this computer…");
|
|
96
123
|
log(`If it doesn't open, visit:\n\n ${url}\n`);
|
|
97
|
-
openBrowser(url);
|
|
124
|
+
(options.openUrl ?? openBrowser)(url);
|
|
98
125
|
}
|
|
99
126
|
else {
|
|
100
127
|
log(`Open this link in the browser where you're signed in, on this computer:\n\n ${url}\n`);
|
|
101
128
|
}
|
|
102
|
-
const code = await waitForCallback(server, pkce.state);
|
|
129
|
+
const code = await waitForCallback(server, pkce.state, options);
|
|
103
130
|
return await exchangeCode(appUrl, {
|
|
104
131
|
code,
|
|
105
132
|
code_verifier: pkce.verifier,
|
|
106
133
|
redirect_uri: redirectUri,
|
|
134
|
+
client: options.client,
|
|
107
135
|
});
|
|
108
136
|
}
|
|
109
137
|
finally {
|