hermesdesk-agent 0.0.0-stage → 0.1.0-alpha.2
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 +21 -0
- package/README.md +92 -3
- package/THIRD_PARTY_NOTICES.md +26 -0
- package/bin/hermesdesk.js +295 -0
- package/npm-shrinkwrap.json +1573 -0
- package/package.json +48 -6
- package/src/agent.js +239 -0
- package/src/config.js +122 -0
- package/src/connection.js +45 -0
- package/src/credentials.js +133 -0
- package/src/policy.js +155 -0
- package/src/search.js +107 -0
- package/src/transport.js +293 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nash Kocur
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,92 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# HermesDesk Agent
|
|
2
|
+
|
|
3
|
+
[](https://github.com/NKocur/hermesdesk-agent/actions/workflows/ci.yml)
|
|
4
|
+
|
|
5
|
+
**Windows alpha: 0.1.0-alpha.2.** Community client built on Pi; not affiliated with or endorsed by Earendil Works or Nous Research.
|
|
6
|
+
|
|
7
|
+
A running HermesDesk inference gateway is required. This client does not include a hosted model service, server access, or API keys.
|
|
8
|
+
|
|
9
|
+
An initial Windows-first coding CLI built on the pinned Pi 1.5.0 SDK. The model runs on your HermesDesk/Strata server; coding tools run on the computer where you start this client.
|
|
10
|
+
|
|
11
|
+
## Install on a Windows computer
|
|
12
|
+
|
|
13
|
+
Install Node.js 22.19 or newer (Node 24 recommended), then install the alpha from npm:
|
|
14
|
+
|
|
15
|
+
```powershell
|
|
16
|
+
npm.cmd install -g --ignore-scripts hermesdesk-agent@alpha
|
|
17
|
+
hermesdesk.cmd connect
|
|
18
|
+
hermesdesk.cmd doctor
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Alternatively, download and extract a Windows alpha bundle from [Releases](https://github.com/NKocur/hermesdesk-agent/releases) and run `Install Agent.cmd`. A tarball can also be installed directly with `npm.cmd install -g --ignore-scripts ./hermesdesk-agent-0.1.0-alpha.2.tgz`.
|
|
22
|
+
|
|
23
|
+
There is no default server address. `connect` asks for your HTTPS inference endpoint ending in `/v1`; for a server on this computer, loopback HTTP is also accepted. Enter a per-computer inference API key created in HermesDesk Settings > Connect coding tools. Use the Hermes/OpenAI-compatible key option; all current inference keys work with this client. The model is discovered automatically if the configured ID is unavailable. No keys are included in the package.
|
|
24
|
+
|
|
25
|
+
For an Access-protected Worker, select **HermesDesk Agent** in the server's **Connect coding tools** settings and create a connection. Run `hermesdesk.cmd connect --code`, then paste its private connection code at the hidden prompt. The code contains both model and Cloudflare Access credentials: treat it like a password. It is never passed as a command-line argument or saved in plain text. The server's normal key expiry and revocation still apply. The package also provides `hermesdesk-agent` as an alias for `hermesdesk`.
|
|
26
|
+
|
|
27
|
+
Manual Access setup is available with `hermesdesk connect --url https://your-worker.example/v1 --cloudflare-access`; all credentials are prompted privately. For session-only authentication, set `HERMESDESK_API_KEY`, `HERMESDESK_ACCESS_CLIENT_ID` and `HERMESDESK_ACCESS_CLIENT_SECRET`. Non-interactive setup on Windows can use `HERMESDESK_CONNECTION_CODE` with `connect --code`. The agent clears these variables before launching coding tools. Saved Access credentials are bound to the endpoint and removed by logout along with the model key.
|
|
28
|
+
|
|
29
|
+
On Windows, saved keys are encrypted using DPAPI for the signed-in Windows user and bound to the configured endpoint. Configuration and sessions are stored under `%LOCALAPPDATA%\HermesDeskAgent`. The key is not written to Pi's auth JSON or passed on a command line. `HERMESDESK_API_KEY` supports session-only authentication; the client removes it from its environment before coding tools run. `hermesdesk logout` deletes the saved credential, but does not revoke it on the server.
|
|
30
|
+
|
|
31
|
+
## Work on a project
|
|
32
|
+
|
|
33
|
+
```powershell
|
|
34
|
+
cd C:\Projects\MyProject
|
|
35
|
+
hermesdesk.cmd chat
|
|
36
|
+
hermesdesk.cmd chat --continue
|
|
37
|
+
hermesdesk.cmd sessions
|
|
38
|
+
hermesdesk.cmd chat --session SESSION_ID
|
|
39
|
+
hermesdesk.cmd chat --read-only
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The interactive terminal uses Pi's UI, streaming, diffs, tool displays, session history and compaction. Escape interrupts work. `/quit` exits; `/new` starts a new conversation and `/resume` opens Pi's session selector. The first interactive startup may download Pi's `fd` helper to this client's own Pi cache. Windows Terminal is recommended. Pi's inherited help and exit hints may still mention `pi`; resume this client with `hermesdesk chat --continue` or `--session ID`.
|
|
43
|
+
|
|
44
|
+
File tools are restricted to the chosen project and reject outside links and protected paths such as `.env`, `.git`, credential files and agent configurations. Each edit and shell command asks for approval. Shell commands execute as your user and are **not OS-sandboxed**; after approval they can access anything your account can access. Direct `!` shell shortcuts are disabled so commands use the managed approval path. Project JavaScript extensions, MCP servers and packages are not automatically loaded.
|
|
45
|
+
|
|
46
|
+
The root project's `AGENTS.md` is included as instructions when it is an ordinary allowed file under 64 KiB. Existing global Pi/Claude settings are not imported. This first version does not synchronize HermesDesk chats, workspace memory or Hermes's skill-learning loop.
|
|
47
|
+
|
|
48
|
+
## One-shot requests
|
|
49
|
+
|
|
50
|
+
```powershell
|
|
51
|
+
hermesdesk.cmd run "Explain this repository" --read-only
|
|
52
|
+
hermesdesk.cmd run "Create a small example file" --approve-writes
|
|
53
|
+
hermesdesk.cmd run "Summarize README.md" --json
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
One-shot operation denies writes unless `--approve-writes` is explicitly provided. It never approves shell commands without interactive confirmation. JSON mode streams `text`, `tool` and `done` records to stdout; diagnostics go to stderr.
|
|
57
|
+
|
|
58
|
+
## Settings
|
|
59
|
+
|
|
60
|
+
```powershell
|
|
61
|
+
hermesdesk.cmd config
|
|
62
|
+
hermesdesk.cmd config set thinking true
|
|
63
|
+
hermesdesk.cmd config set context 131072
|
|
64
|
+
hermesdesk.cmd config set maxTokens 4096
|
|
65
|
+
hermesdesk.cmd config set temperature 0.7
|
|
66
|
+
hermesdesk.cmd config set topP 0.95
|
|
67
|
+
hermesdesk.cmd config set topK 20
|
|
68
|
+
hermesdesk.cmd config set maxRequests 64
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Changes apply to the next launch. Context is client metadata, not a request to allocate more server context: keep it at or below the server's configured capacity. Output is capped at 8192 by the gateway. The default request budget is 64 per message and can be set from 1 to 512. Pi's in-chat settings are session-only in this version. Change the server using `hermesdesk connect --url https://your-server/v1`. HTTP is accepted only on loopback addresses.
|
|
72
|
+
|
|
73
|
+
Windows uses its built-in `curl.exe` for model HTTP requests because the retained Cloudflare bot filter challenged Node fetch and a native Node follow-up request during testing. TLS verification stays enabled, redirects are not followed, credentials are sent through stdin rather than command-line arguments, and disconnects cancel the request. `doctor` checks the connection without loading the model. A browser challenge from zone-wide Bot Fight Mode cannot be solved by an API client; the server owner must configure API-compatible protection. Transport compatibility alone does not guarantee that every computer will be accepted. Cold Strata startup can still take minutes; the client cannot remove server warm-up costs. A Cloudflare 403 is a connection failure, not a model error.
|
|
74
|
+
|
|
75
|
+
## Optional private Worker gateway
|
|
76
|
+
|
|
77
|
+
The generic Worker source and deployment notes are in [worker/](worker/README.md). It requires Cloudflare Access authentication for its configured application and proxies only model discovery and chat completions to a single private VPC Service. It exposes no desktop tools, file APIs, application sessions, or arbitrary destinations. Website Bot Fight Mode can remain enabled when the agent uses a separate `workers.dev` endpoint. Workers VPC is beta; check Cloudflare's current availability, pricing and limits before adopting it.
|
|
78
|
+
|
|
79
|
+
## Develop
|
|
80
|
+
|
|
81
|
+
```powershell
|
|
82
|
+
npm.cmd ci --ignore-scripts
|
|
83
|
+
npm.cmd test
|
|
84
|
+
node bin/hermesdesk.js --help
|
|
85
|
+
npm.cmd pack --ignore-scripts
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The client is a standalone project. Use the GitHub alpha release assets for the Windows installer or tarball. The `.tgz` contains no local credentials, test transcripts or model files. Pi's MIT license is retained in `THIRD_PARTY_NOTICES.md`; dependency licenses remain in the installed packages.
|
|
89
|
+
|
|
90
|
+
## License and contributing
|
|
91
|
+
|
|
92
|
+
MIT. Pi is also MIT-licensed; see [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md). See [CONTRIBUTING.md](CONTRIBUTING.md) for development and [SECURITY.md](SECURITY.md) for reporting security issues.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
This client uses Pi 1.5.0 by Mario Zechner / Earendil Works, from https://github.com/earendil-works/pi, under the MIT license.
|
|
4
|
+
|
|
5
|
+
MIT License
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2025 Mario Zechner
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
|
26
|
+
Other dependency licenses are supplied with their npm packages.
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import readline from "node:readline/promises";
|
|
5
|
+
import { parseArgs } from "node:util";
|
|
6
|
+
import {
|
|
7
|
+
VERSION,
|
|
8
|
+
supportedNode,
|
|
9
|
+
configHome,
|
|
10
|
+
loadConfig,
|
|
11
|
+
saveConfig,
|
|
12
|
+
validateConfig,
|
|
13
|
+
projectSessionDir,
|
|
14
|
+
} from "../src/config.js";
|
|
15
|
+
import {
|
|
16
|
+
getConnection,
|
|
17
|
+
saveCredential,
|
|
18
|
+
hiddenInput,
|
|
19
|
+
logout,
|
|
20
|
+
} from "../src/credentials.js";
|
|
21
|
+
import { parseConnectionCode, validateAccess } from "../src/connection.js";
|
|
22
|
+
const privateValues = new Set();
|
|
23
|
+
const protect = (value) => {
|
|
24
|
+
if (value) privateValues.add(value);
|
|
25
|
+
return value;
|
|
26
|
+
};
|
|
27
|
+
const clearAuthEnv = () => {
|
|
28
|
+
for (const key of [
|
|
29
|
+
"HERMESDESK_API_KEY",
|
|
30
|
+
"HERMESDESK_ACCESS_CLIENT_ID",
|
|
31
|
+
"HERMESDESK_ACCESS_CLIENT_SECRET",
|
|
32
|
+
"HERMESDESK_CONNECTION_CODE",
|
|
33
|
+
])
|
|
34
|
+
delete process.env[key];
|
|
35
|
+
};
|
|
36
|
+
import { discover } from "../src/transport.js";
|
|
37
|
+
const help = `HermesDesk Agent ${VERSION} (Pi-based, Windows first)
|
|
38
|
+
|
|
39
|
+
hermesdesk connect [--code | --url https://your-server.example/v1] [--cloudflare-access]
|
|
40
|
+
hermesdesk doctor
|
|
41
|
+
hermesdesk chat [--cwd PATH] [--continue | --session ID] [--read-only]
|
|
42
|
+
hermesdesk run "REQUEST" [--cwd PATH] [--json] [--read-only]
|
|
43
|
+
hermesdesk sessions [--cwd PATH]
|
|
44
|
+
hermesdesk config [set KEY VALUE]
|
|
45
|
+
hermesdesk logout
|
|
46
|
+
|
|
47
|
+
Edits and shell commands ask for approval in interactive chat.
|
|
48
|
+
One-shot runs deny changes by default; --approve-writes permits workspace file edits.
|
|
49
|
+
Shell commands always require interactive approval. This is not an OS sandbox.
|
|
50
|
+
Settings: model, context, maxTokens, thinking, temperature, topP, topK, maxRequests.
|
|
51
|
+
`;
|
|
52
|
+
async function main() {
|
|
53
|
+
const { values: v, positionals: p } = parseArgs({
|
|
54
|
+
allowPositionals: true,
|
|
55
|
+
options: {
|
|
56
|
+
url: { type: "string" },
|
|
57
|
+
code: { type: "boolean" },
|
|
58
|
+
"cloudflare-access": { type: "boolean" },
|
|
59
|
+
cwd: { type: "string" },
|
|
60
|
+
session: { type: "string" },
|
|
61
|
+
continue: { type: "boolean" },
|
|
62
|
+
"read-only": { type: "boolean" },
|
|
63
|
+
"approve-writes": { type: "boolean" },
|
|
64
|
+
json: { type: "boolean" },
|
|
65
|
+
help: { type: "boolean", short: "h" },
|
|
66
|
+
version: { type: "boolean" },
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
if (v.help) {
|
|
70
|
+
console.log(help);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (v.version) {
|
|
74
|
+
console.log(VERSION);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (!supportedNode())
|
|
78
|
+
throw Error(
|
|
79
|
+
"Node.js " +
|
|
80
|
+
process.versions.node +
|
|
81
|
+
" is too old. Install Node.js 24 (minimum supported: 22.19.0), close this terminal and open a new one, then run node --version before trying again.",
|
|
82
|
+
);
|
|
83
|
+
const command = p.shift() || "chat",
|
|
84
|
+
home = configHome();
|
|
85
|
+
process.env.PI_CODING_AGENT_DIR = path.join(home, "pi");
|
|
86
|
+
let config = loadConfig(home);
|
|
87
|
+
if (command === "connect") {
|
|
88
|
+
let imported;
|
|
89
|
+
if (v.code || process.env.HERMESDESK_CONNECTION_CODE) {
|
|
90
|
+
if (v.url || v["cloudflare-access"])
|
|
91
|
+
throw Error(
|
|
92
|
+
"Use --code on its own; the private code includes the endpoint and credentials.",
|
|
93
|
+
);
|
|
94
|
+
imported = parseConnectionCode(
|
|
95
|
+
protect(
|
|
96
|
+
process.env.HERMESDESK_CONNECTION_CODE ||
|
|
97
|
+
(await hiddenInput(
|
|
98
|
+
"Private HermesDesk connection code (hidden): ",
|
|
99
|
+
)),
|
|
100
|
+
),
|
|
101
|
+
);
|
|
102
|
+
config = validateConfig({ ...config, baseUrl: imported.baseUrl });
|
|
103
|
+
console.log("Connecting to " + config.baseUrl);
|
|
104
|
+
}
|
|
105
|
+
if (v.url) config = validateConfig({ ...config, baseUrl: v.url });
|
|
106
|
+
const rl = readline.createInterface({
|
|
107
|
+
input: process.stdin,
|
|
108
|
+
output: process.stdout,
|
|
109
|
+
});
|
|
110
|
+
if (!imported && !v.url && process.stdin.isTTY) {
|
|
111
|
+
const answer = await rl.question(
|
|
112
|
+
config.baseUrl
|
|
113
|
+
? "Server [" + config.baseUrl + "]: "
|
|
114
|
+
: "HermesDesk server URL (https://.../v1): ",
|
|
115
|
+
);
|
|
116
|
+
if (answer.trim())
|
|
117
|
+
config = validateConfig({ ...config, baseUrl: answer.trim() });
|
|
118
|
+
}
|
|
119
|
+
rl.close();
|
|
120
|
+
if (!config.baseUrl)
|
|
121
|
+
throw Error(
|
|
122
|
+
"Enter your server URL, or use hermesdesk connect --url https://your-server.example/v1.",
|
|
123
|
+
);
|
|
124
|
+
const token = protect(
|
|
125
|
+
imported?.token ||
|
|
126
|
+
process.env.HERMESDESK_API_KEY ||
|
|
127
|
+
(await hiddenInput("HermesDesk API key (hidden): ")),
|
|
128
|
+
);
|
|
129
|
+
let access = imported?.access;
|
|
130
|
+
if (
|
|
131
|
+
!access &&
|
|
132
|
+
(v["cloudflare-access"] ||
|
|
133
|
+
process.env.HERMESDESK_ACCESS_CLIENT_ID ||
|
|
134
|
+
process.env.HERMESDESK_ACCESS_CLIENT_SECRET)
|
|
135
|
+
) {
|
|
136
|
+
access = validateAccess({
|
|
137
|
+
clientId:
|
|
138
|
+
process.env.HERMESDESK_ACCESS_CLIENT_ID ||
|
|
139
|
+
(await hiddenInput("Cloudflare Access client ID (hidden): ")),
|
|
140
|
+
clientSecret:
|
|
141
|
+
process.env.HERMESDESK_ACCESS_CLIENT_SECRET ||
|
|
142
|
+
(await hiddenInput("Cloudflare Access client secret (hidden): ")),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
protect(access?.clientSecret);
|
|
146
|
+
clearAuthEnv();
|
|
147
|
+
const models = await discover(config, token, access);
|
|
148
|
+
if (!models.length) throw Error("No models are available.");
|
|
149
|
+
if (!models.includes(config.model)) config.model = models[0];
|
|
150
|
+
await saveCredential(home, config.baseUrl, token, access);
|
|
151
|
+
saveConfig(config, home);
|
|
152
|
+
console.log(
|
|
153
|
+
"Connected. Credential protected for your Windows account.\nModel: " +
|
|
154
|
+
config.model +
|
|
155
|
+
"\nRun hermesdesk chat from your project directory.",
|
|
156
|
+
);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (command === "logout") {
|
|
160
|
+
logout(home);
|
|
161
|
+
console.log(
|
|
162
|
+
"Saved credential removed. Any HERMESDESK_API_KEY environment variable still applies until cleared.",
|
|
163
|
+
);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (command === "config") {
|
|
167
|
+
if (p[0] === "set") {
|
|
168
|
+
const key = p[1];
|
|
169
|
+
if (!Object.hasOwn(config, key) || key === "baseUrl")
|
|
170
|
+
throw Error(
|
|
171
|
+
"Choose a supported setting; use connect --url to change servers.",
|
|
172
|
+
);
|
|
173
|
+
const raw = p.slice(2).join(" ");
|
|
174
|
+
if (!raw) throw Error("Provide a setting value.");
|
|
175
|
+
let value = raw;
|
|
176
|
+
if (key !== "model") {
|
|
177
|
+
try {
|
|
178
|
+
value = JSON.parse(raw);
|
|
179
|
+
} catch {
|
|
180
|
+
throw Error("Use a number or true/false for this setting.");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
config = saveConfig({ ...config, [key]: value }, home);
|
|
184
|
+
}
|
|
185
|
+
console.log(JSON.stringify(config, null, 2));
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (command === "sessions") {
|
|
189
|
+
const { SessionManager } = await import("@earendil-works/pi-coding-agent");
|
|
190
|
+
const cwd = fs.realpathSync.native(v.cwd || process.cwd());
|
|
191
|
+
const rows = await SessionManager.list(cwd, projectSessionDir(home, cwd));
|
|
192
|
+
const selected = rows.filter(
|
|
193
|
+
(r) => r.cwd.toLowerCase() === cwd.toLowerCase(),
|
|
194
|
+
);
|
|
195
|
+
console.log(
|
|
196
|
+
selected.length
|
|
197
|
+
? selected
|
|
198
|
+
.map(
|
|
199
|
+
(r) =>
|
|
200
|
+
r.id +
|
|
201
|
+
" " +
|
|
202
|
+
(r.name || r.firstMessage || "Untitled")
|
|
203
|
+
.replace(/\s+/g, " ")
|
|
204
|
+
.slice(0, 90),
|
|
205
|
+
)
|
|
206
|
+
.join("\n")
|
|
207
|
+
: "No saved sessions for this project.",
|
|
208
|
+
);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (!["doctor", "chat", "run"].includes(command))
|
|
212
|
+
throw Error("Unknown command. Use hermesdesk --help.");
|
|
213
|
+
if (!config.baseUrl || !config.model)
|
|
214
|
+
throw Error("Not connected. Run hermesdesk connect first.");
|
|
215
|
+
const { token, access } = await getConnection(home, config.baseUrl);
|
|
216
|
+
protect(token);
|
|
217
|
+
protect(access?.clientSecret);
|
|
218
|
+
clearAuthEnv();
|
|
219
|
+
if (command === "doctor") {
|
|
220
|
+
const models = await discover(config, token, access);
|
|
221
|
+
console.log(
|
|
222
|
+
JSON.stringify(
|
|
223
|
+
{
|
|
224
|
+
connected: true,
|
|
225
|
+
endpoint: config.baseUrl,
|
|
226
|
+
model: config.model,
|
|
227
|
+
available: models.includes(config.model),
|
|
228
|
+
models,
|
|
229
|
+
settingsDirectory: home,
|
|
230
|
+
node: process.version,
|
|
231
|
+
platform: process.platform,
|
|
232
|
+
},
|
|
233
|
+
null,
|
|
234
|
+
2,
|
|
235
|
+
),
|
|
236
|
+
);
|
|
237
|
+
if (!models.includes(config.model)) process.exitCode = 1;
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const cwd = fs.realpathSync.native(v.cwd || process.cwd());
|
|
241
|
+
if (command === "chat" && (!process.stdin.isTTY || !process.stdout.isTTY))
|
|
242
|
+
throw Error(
|
|
243
|
+
'Interactive chat needs a terminal. Use hermesdesk run "request" for one-shot operation.',
|
|
244
|
+
);
|
|
245
|
+
if (command === "run" && !p.length)
|
|
246
|
+
throw Error('Provide a request: hermesdesk run "Inspect this project".');
|
|
247
|
+
const { createRuntime, runPrompt } = await import("../src/agent.js");
|
|
248
|
+
const runtime = await createRuntime({
|
|
249
|
+
config,
|
|
250
|
+
home,
|
|
251
|
+
token,
|
|
252
|
+
access,
|
|
253
|
+
cwd,
|
|
254
|
+
readOnly: !!v["read-only"],
|
|
255
|
+
approveWrites: !!v["approve-writes"],
|
|
256
|
+
continueSession: !!v.continue,
|
|
257
|
+
sessionId: v.session,
|
|
258
|
+
});
|
|
259
|
+
const cancel = () => {
|
|
260
|
+
void runtime.session.abort();
|
|
261
|
+
};
|
|
262
|
+
process.on("SIGINT", cancel);
|
|
263
|
+
try {
|
|
264
|
+
if (command === "run") {
|
|
265
|
+
await runPrompt(runtime, p.join(" "), { json: !!v.json });
|
|
266
|
+
} else {
|
|
267
|
+
const { InteractiveMode } = await import(
|
|
268
|
+
"@earendil-works/pi-coding-agent"
|
|
269
|
+
);
|
|
270
|
+
const ui = new InteractiveMode(runtime, {
|
|
271
|
+
verbose: false,
|
|
272
|
+
initialMessage: p.length ? p.join(" ") : undefined,
|
|
273
|
+
});
|
|
274
|
+
await ui.run();
|
|
275
|
+
}
|
|
276
|
+
} finally {
|
|
277
|
+
process.off("SIGINT", cancel);
|
|
278
|
+
await runtime.dispose();
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
main().catch((e) => {
|
|
282
|
+
let message = e.message || "Operation failed.";
|
|
283
|
+
for (const secret of [
|
|
284
|
+
...privateValues,
|
|
285
|
+
process.env.HERMESDESK_API_KEY,
|
|
286
|
+
process.env.HERMESDESK_ACCESS_CLIENT_SECRET,
|
|
287
|
+
process.env.HERMESDESK_CONNECTION_CODE,
|
|
288
|
+
])
|
|
289
|
+
if (secret) message = message.split(secret).join("[redacted]");
|
|
290
|
+
if (/<!doctype|<html/i.test(message))
|
|
291
|
+
message =
|
|
292
|
+
"Cloudflare rejected the API request. Run hermesdesk doctor to check the connection.";
|
|
293
|
+
console.error("HermesDesk: " + message.slice(0, 1200));
|
|
294
|
+
process.exitCode = 1;
|
|
295
|
+
});
|