directionallylocal 0.4.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/LICENSE +202 -0
- package/README.md +4 -0
- package/dist/cli.js +20 -2
- package/dist/doctor.js +6 -3
- package/dist/laptop/commands.js +12 -2
- package/dist/laptop/credentials.js +5 -5
- package/dist/laptop/session-store.js +62 -0
- package/dist/laptop/session.js +279 -0
- package/dist/laptop/setup.js +92 -63
- package/dist/laptop/tunnel.js +8 -0
- package/dist/layout.js +4 -0
- package/dist/local/cli.js +4 -1
- package/dist/local/layout.js +3 -0
- package/dist/local/setup.js +14 -6
- package/dist/local/test-support/fake-computer.js +7 -0
- package/dist/model-prices.js +119 -0
- package/dist/prompt.js +333 -16
- package/dist/up.js +10 -1
- package/package.json +5 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
package/dist/cli.js
CHANGED
|
@@ -7,6 +7,7 @@ import { briefStatus, connectLaptop, laptopsCommand, logsCommand, pairLaptop, se
|
|
|
7
7
|
import { cancel, connect, describeError, laptopHome, pull, run, runs, servers, use, watch } from "./laptop/commands.js";
|
|
8
8
|
import { loadRemotes } from "./laptop/config.js";
|
|
9
9
|
import { keys } from "./laptop/keys.js";
|
|
10
|
+
import { projectSession } from "./laptop/session.js";
|
|
10
11
|
import { setup } from "./laptop/setup.js";
|
|
11
12
|
import { localCommand } from "./local/cli.js";
|
|
12
13
|
import { setUpOnThisComputer } from "./local/setup.js";
|
|
@@ -23,6 +24,9 @@ Send a task; it runs in its own sandbox and comes back as a pull request.
|
|
|
23
24
|
On your laptop:
|
|
24
25
|
dl set up the first time; afterwards, an overview
|
|
25
26
|
dl setup set up or repair where your agents run (safe to re-run)
|
|
27
|
+
dl (in a GitHub repo) talk to the repository's agent; it keeps running when you leave
|
|
28
|
+
dl new in a GitHub repo: start a fresh conversation for it
|
|
29
|
+
dl status where your agents run and what they're doing (works anywhere)
|
|
26
30
|
dl connect URL connect to a server someone else set up (approve the code it shows)
|
|
27
31
|
dl run "TASK" run a task, from inside a GitHub repository
|
|
28
32
|
(your uncommitted changes go along; Ctrl-C stops watching, not the task)
|
|
@@ -206,8 +210,15 @@ export async function main(argv, io = {
|
|
|
206
210
|
if (!state) {
|
|
207
211
|
if (values.brief)
|
|
208
212
|
return 0;
|
|
209
|
-
//
|
|
210
|
-
if (!command && await
|
|
213
|
+
// Inside a GitHub repository, that repository's conversation; elsewhere, the laptop's home.
|
|
214
|
+
if (!command && terminal && (await loadRemotes()).length > 0) {
|
|
215
|
+
const code = await projectSession({ cwd: process.cwd(), ...(values.server ? { server: values.server } : {}), ...(values.model ? { model: values.model } : {}) }, laptopIO);
|
|
216
|
+
if (code !== undefined)
|
|
217
|
+
return code;
|
|
218
|
+
}
|
|
219
|
+
// A laptop connected to servers gets its own home (`dl status` shows it from anywhere);
|
|
220
|
+
// otherwise, what this is and how to start.
|
|
221
|
+
if ((!command || command === "status") && await laptopHome(laptopIO))
|
|
211
222
|
return 0;
|
|
212
223
|
// A laptop with nothing set up yet: the wizard (it needs someone to answer it).
|
|
213
224
|
if (!command && terminal && !isRoot() && (await loadRemotes()).length === 0)
|
|
@@ -271,6 +282,13 @@ export async function main(argv, io = {
|
|
|
271
282
|
await pull({ id, cwd: process.cwd(), ...server }, laptopIO);
|
|
272
283
|
return 0;
|
|
273
284
|
}
|
|
285
|
+
case "new": {
|
|
286
|
+
const code = await projectSession({ cwd: process.cwd(), fresh: true, ...(values.server ? { server: values.server } : {}), ...(values.model ? { model: values.model } : {}) }, laptopIO);
|
|
287
|
+
if (code !== undefined)
|
|
288
|
+
return code;
|
|
289
|
+
io.err(` dl new starts a fresh conversation from inside a GitHub repository (with something set up: dl setup).\n`);
|
|
290
|
+
return 1;
|
|
291
|
+
}
|
|
274
292
|
case "servers":
|
|
275
293
|
return await servers(parsed.positionals.slice(1), laptopIO);
|
|
276
294
|
case "use":
|
package/dist/doctor.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { detectHost, MIN_DISK_GB } from "./detect.js";
|
|
2
2
|
import { nodeAdvisory } from "./node-advisory.js";
|
|
3
3
|
import { AUTOPILOT_PORT, AUTO_UPGRADES, HOTCELL_PORT, NODE_AUTO_UPDATES, PATHS, SERVICES, parseEnvFile } from "./layout.js";
|
|
4
|
+
import { fileMtime, modelPricesHealth } from "./model-prices.js";
|
|
4
5
|
import { describeAccess, readState } from "./state.js";
|
|
5
6
|
import { palette } from "./ui.js";
|
|
6
7
|
/** `directionallylocal doctor`: every moving part, with a fix for each failure. */
|
|
7
|
-
export async function doctor(system) {
|
|
8
|
+
export async function doctor(system, now = new Date()) {
|
|
8
9
|
const checks = [];
|
|
9
10
|
const add = (check) => checks.push(check);
|
|
10
11
|
const state = await readState(system);
|
|
@@ -45,6 +46,8 @@ export async function doctor(system) {
|
|
|
45
46
|
const keys = await system.probe("runuser", ["-u", "hotcell", "--", "env", `HOTCELL_HOME=${PATHS.hotcellHome}`, "HOTCELL_KEYSTORE=file", "/usr/bin/node", `${PATHS.current}/node_modules/hotcell/dist/index.js`, "keys", "ls"]);
|
|
46
47
|
const hasModelKey = keys.code === 0 && /^\s*openrouter\b/m.test(keys.stdout);
|
|
47
48
|
add({ name: "model key", ok: hasModelKey, detail: hasModelKey ? "OpenRouter key in Hotcell" : "no OpenRouter key in Hotcell", fix: "sudo dl up (asks for it)" });
|
|
49
|
+
const prices = modelPricesHealth(await system.readFile(PATHS.modelPrices), await fileMtime(system, PATHS.modelPrices), now, "dl up");
|
|
50
|
+
add({ name: "model prices", ok: prices.ok, ...(prices.warn ? { warn: true } : {}), detail: prices.detail, fix: "sudo dl up (downloads them from openrouter.ai)" });
|
|
48
51
|
const github = Boolean(parseEnvFile(await system.readFile(PATHS.githubEnv)).GITHUB_TOKEN);
|
|
49
52
|
add({ name: "github", ok: github, detail: github ? "token configured" : "no token; runs can't push or open PRs", fix: "sudo dl up (asks for it)" });
|
|
50
53
|
const autopilot = (await system.probe("curl", ["-s", "-o", "/dev/null", "-w", "%{http_code}", `http://127.0.0.1:${AUTOPILOT_PORT}/api/v1/health`])).stdout.trim();
|
|
@@ -63,9 +66,9 @@ export function formatChecks(checks, color = false) {
|
|
|
63
66
|
const c = palette(color);
|
|
64
67
|
const width = Math.max(...checks.map((check) => check.name.length)) + 2;
|
|
65
68
|
const rows = checks.map((check) => {
|
|
66
|
-
const glyph = check.ok ? c.
|
|
69
|
+
const glyph = !check.ok ? c.red("✗") : check.warn ? c.yellow("!") : c.green("✓");
|
|
67
70
|
const fix = !check.ok && check.fix ? `\n ${c.dim(`fix: ${check.fix}`)}` : "";
|
|
68
|
-
return ` ${glyph} ${check.name.padEnd(width)}${check.ok ? c.
|
|
71
|
+
return ` ${glyph} ${check.name.padEnd(width)}${!check.ok ? c.red(check.detail) : check.warn ? c.yellow(check.detail) : c.dim(check.detail)}${fix}`;
|
|
69
72
|
});
|
|
70
73
|
const failed = checks.filter((check) => !check.ok).length;
|
|
71
74
|
const verdict = failed === 0 ? `${c.green("✓")} ${c.bold("All good")}` : `${c.red("✗")} ${c.bold(`${failed} to fix`)}`;
|
package/dist/laptop/commands.js
CHANGED
|
@@ -3,6 +3,7 @@ import { randomUUID } from "node:crypto";
|
|
|
3
3
|
import { readFile } from "node:fs/promises";
|
|
4
4
|
import { homedir, hostname } from "node:os";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
|
+
import { isModelNotPriced } from "../model-prices.js";
|
|
6
7
|
import { palette } from "../ui.js";
|
|
7
8
|
import { RemoteApiError, RemoteClient, TERMINAL_STATUSES } from "./client.js";
|
|
8
9
|
import { defaultRemoteName, loadRemotes, loadRemotesFile, normalizeServerUrl, recordLastUsed, REMOTE_NAME_RE, removeRemote, renameRemote, resolveRemote, resolveTarget, saveRemote, setDefaultRemote, } from "./config.js";
|
|
@@ -282,7 +283,8 @@ export async function laptopHome(io = processIO, open) {
|
|
|
282
283
|
io.out(" Coding agents that run on this computer or your own server: send a task, get a pull request back.\n\n");
|
|
283
284
|
io.out(` ${c.dim("Runs on".padEnd(11))}${remotes.map((remote) => `${mark(remote, current, c)} ${remote.name} ${c.dim(where(remote))}`).join(", ")} ${c.dim(remotes.length > 1 ? "dl servers · dl use NAME" : "dl servers")}\n`);
|
|
284
285
|
io.out(` ${c.dim("Tasks".padEnd(11))}${running} running · ${total} in all ${c.dim("dl runs")}\n\n`);
|
|
285
|
-
io.out(` ${c.dim("
|
|
286
|
+
io.out(` ${c.dim("Start a session: cd into a GitHub repository, then type")} ${c.bold("dl")}\n`);
|
|
287
|
+
io.out(` ${c.dim("Or hand off a one-off task:")} ${c.bold('dl run "fix the flaky checkout test"')}\n\n`);
|
|
286
288
|
return true;
|
|
287
289
|
}
|
|
288
290
|
async function follow(client, remote, conversationId, cursor, signal, io, replayUntil) {
|
|
@@ -323,7 +325,11 @@ async function follow(client, remote, conversationId, cursor, signal, io, replay
|
|
|
323
325
|
io.err("\n");
|
|
324
326
|
return 0;
|
|
325
327
|
}
|
|
326
|
-
io.err(`\n ${c.red("✗")} ${id} ${outcome}\n
|
|
328
|
+
io.err(`\n ${c.red("✗")} ${id} ${outcome}\n`);
|
|
329
|
+
if (renderer.unpriced || isModelNotPriced(JSON.stringify(final))) {
|
|
330
|
+
io.err(` This model isn't in your server's price list yet. Run ${c.bold("dl setup")} to refresh it, or pick another model with -m.\n`);
|
|
331
|
+
}
|
|
332
|
+
io.err("\n");
|
|
327
333
|
return 1;
|
|
328
334
|
}
|
|
329
335
|
/** Writes the agent's text as it streams and one line per tool call. */
|
|
@@ -331,12 +337,16 @@ class EventRenderer {
|
|
|
331
337
|
io;
|
|
332
338
|
c;
|
|
333
339
|
midLine = false;
|
|
340
|
+
/** Hotcell refused the model for lack of a price (a stale price list on the server). */
|
|
341
|
+
unpriced = false;
|
|
334
342
|
constructor(io, c) {
|
|
335
343
|
this.io = io;
|
|
336
344
|
this.c = c;
|
|
337
345
|
}
|
|
338
346
|
render(event) {
|
|
339
347
|
const data = event.data;
|
|
348
|
+
if (event.type !== "assistant.delta" && !this.unpriced && isModelNotPriced(JSON.stringify(data)))
|
|
349
|
+
this.unpriced = true;
|
|
340
350
|
if (event.type === "assistant.delta") {
|
|
341
351
|
const text = typeof data.text === "string" ? data.text : typeof data.delta === "string" ? data.delta : "";
|
|
342
352
|
if (!text)
|
|
@@ -45,14 +45,14 @@ export async function gatherKeys(needs, input) {
|
|
|
45
45
|
const wanted = needs.filter((need) => need === "github" || need === "openrouter");
|
|
46
46
|
if (wanted.length === 0)
|
|
47
47
|
return answers;
|
|
48
|
-
ui.questions(`${wanted.length === 1 ? "1 key" : "2 keys"}, kept on your server only; then it sets itself up.`);
|
|
48
|
+
ui.questions(`${wanted.length === 1 ? "1 key" : "2 keys"}, kept on ${input.place ?? "your server"} only; then it sets itself up.`);
|
|
49
49
|
if (wanted.includes("github"))
|
|
50
50
|
answers.githubToken = await githubToken(input);
|
|
51
51
|
if (wanted.includes("openrouter"))
|
|
52
52
|
answers.openrouterKey = await openrouterKey(input);
|
|
53
53
|
return answers;
|
|
54
54
|
}
|
|
55
|
-
export async function githubToken({ ui, prompter, sources }) {
|
|
55
|
+
export async function githubToken({ ui, prompter, sources, place = "your server" }) {
|
|
56
56
|
const fromCli = (await sources.gh().catch(() => undefined))?.trim();
|
|
57
57
|
if (fromCli) {
|
|
58
58
|
const checked = await validateGitHubToken(fromCli, sources.fetch);
|
|
@@ -61,7 +61,7 @@ export async function githubToken({ ui, prompter, sources }) {
|
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
63
63
|
const who = checked.login ? ` (${checked.login})` : "";
|
|
64
|
-
if (await confirm(ui, prompter, `Use your GitHub CLI login${who}? It stays on
|
|
64
|
+
if (await confirm(ui, prompter, `Use your GitHub CLI login${who}? It stays on ${place}.`)) {
|
|
65
65
|
ui.answered("GitHub", `${checked.login ? `signed in as ${checked.login} · ` : ""}from the GitHub CLI`);
|
|
66
66
|
return fromCli;
|
|
67
67
|
}
|
|
@@ -73,7 +73,7 @@ export async function githubToken({ ui, prompter, sources }) {
|
|
|
73
73
|
return { value: token, ...(checked.problem ? { problem: checked.problem } : {}), ...(checked.login ? { detail: `signed in as ${checked.login}` } : {}) };
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
|
-
export async function openrouterKey({ ui, prompter, sources }) {
|
|
76
|
+
export async function openrouterKey({ ui, prompter, sources, place = "your server" }) {
|
|
77
77
|
const candidates = [];
|
|
78
78
|
const fromEnv = sources.env.OPENROUTER_API_KEY?.trim();
|
|
79
79
|
if (fromEnv)
|
|
@@ -88,7 +88,7 @@ export async function openrouterKey({ ui, prompter, sources }) {
|
|
|
88
88
|
ui.warn(`The OpenRouter key ${candidate.from} didn't work (${problem})`);
|
|
89
89
|
continue;
|
|
90
90
|
}
|
|
91
|
-
if (await confirm(ui, prompter, `${candidate.question} It stays on
|
|
91
|
+
if (await confirm(ui, prompter, `${candidate.question} It stays on ${place}.`)) {
|
|
92
92
|
ui.answered("OpenRouter", candidate.from);
|
|
93
93
|
return candidate.key;
|
|
94
94
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { chmod, mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
export function sessionsPath(env = process.env) {
|
|
5
|
+
const configHome = env.XDG_CONFIG_HOME?.trim() || join(homedir(), ".config");
|
|
6
|
+
return join(configHome, "directionallylocal", "sessions.json");
|
|
7
|
+
}
|
|
8
|
+
export async function loadSessions(path = sessionsPath()) {
|
|
9
|
+
let raw;
|
|
10
|
+
try {
|
|
11
|
+
raw = await readFile(path, "utf8");
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (error.code === "ENOENT")
|
|
15
|
+
return [];
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const parsed = JSON.parse(raw);
|
|
20
|
+
return Array.isArray(parsed.sessions) ? parsed.sessions.filter(isEntry) : [];
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// A damaged file only costs a new conversation; it gets rewritten on the next save.
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export async function findSession(key, path = sessionsPath()) {
|
|
28
|
+
return (await loadSessions(path)).find((entry) => sameKey(entry, key));
|
|
29
|
+
}
|
|
30
|
+
/** Remembers (or replaces) the conversation for this place + repository + checkout. */
|
|
31
|
+
export async function rememberSession(entry, path = sessionsPath()) {
|
|
32
|
+
const kept = (await loadSessions(path)).filter((existing) => !sameKey(existing, entry));
|
|
33
|
+
kept.push({ ...entry, updatedAt: new Date().toISOString() });
|
|
34
|
+
await writeSessions(kept, path);
|
|
35
|
+
}
|
|
36
|
+
/** Forgets this key's conversation (it keeps running on the place); true when there was one. */
|
|
37
|
+
export async function forgetSession(key, path = sessionsPath()) {
|
|
38
|
+
const sessions = await loadSessions(path);
|
|
39
|
+
const kept = sessions.filter((entry) => !sameKey(entry, key));
|
|
40
|
+
if (kept.length === sessions.length)
|
|
41
|
+
return false;
|
|
42
|
+
await writeSessions(kept, path);
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
function sameKey(a, b) {
|
|
46
|
+
return a.place === b.place && a.repository === b.repository && a.root === b.root;
|
|
47
|
+
}
|
|
48
|
+
async function writeSessions(sessions, path) {
|
|
49
|
+
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
50
|
+
const temp = `${path}.${process.pid}.tmp`;
|
|
51
|
+
const body = { version: 1, sessions };
|
|
52
|
+
await writeFile(temp, `${JSON.stringify(body, null, 2)}\n`, { mode: 0o600 });
|
|
53
|
+
await chmod(temp, 0o600);
|
|
54
|
+
await rename(temp, path);
|
|
55
|
+
}
|
|
56
|
+
function isEntry(value) {
|
|
57
|
+
if (!value || typeof value !== "object")
|
|
58
|
+
return false;
|
|
59
|
+
const entry = value;
|
|
60
|
+
return ["place", "repository", "root", "conversationId", "updatedAt"].every((key) => typeof entry[key] === "string") &&
|
|
61
|
+
(entry.branch === undefined || typeof entry.branch === "string");
|
|
62
|
+
}
|