@tenonai/yew 0.0.0-stage → 1.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/CHANGELOG.md +296 -0
- package/LICENSE +21 -0
- package/README.md +55 -2
- package/THIRD-PARTY-NOTICES.md +122 -0
- package/bin/yew.js +9 -0
- package/dist/cli/app.js +198 -0
- package/dist/cli/export.js +57 -0
- package/dist/cli/io.js +65 -0
- package/dist/cli/key.js +113 -0
- package/dist/cli/main.js +44 -0
- package/dist/cli/mcp.js +76 -0
- package/dist/cli/remote.js +116 -0
- package/dist/cli/run.js +72 -0
- package/dist/cli/schedule.js +123 -0
- package/dist/cli/send.js +126 -0
- package/dist/cli/serve.js +301 -0
- package/dist/cli/service.js +241 -0
- package/dist/cli/system.js +44 -0
- package/dist/remote/access.js +107 -0
- package/dist/remote/connector.js +278 -0
- package/dist/remote/identity.js +71 -0
- package/dist/remote/noise.js +287 -0
- package/dist/remote/protocol.js +51 -0
- package/dist/remote/push.js +37 -0
- package/dist/server/agent/compaction.js +242 -0
- package/dist/server/agent/context.js +119 -0
- package/dist/server/agent/held.js +48 -0
- package/dist/server/agent/helper.js +122 -0
- package/dist/server/agent/mailroom.js +510 -0
- package/dist/server/agent/prompt.js +268 -0
- package/dist/server/agent/runner.js +1159 -0
- package/dist/server/artifacts.js +216 -0
- package/dist/server/budget.js +88 -0
- package/dist/server/data-export.js +105 -0
- package/dist/server/data-usage.js +143 -0
- package/dist/server/db/database.js +49 -0
- package/dist/server/db/migrations.js +347 -0
- package/dist/server/errors.js +16 -0
- package/dist/server/events.js +17 -0
- package/dist/server/export.js +378 -0
- package/dist/server/folder-picker.js +32 -0
- package/dist/server/from-jig.js +98 -0
- package/dist/server/http/agents.js +78 -0
- package/dist/server/http/api.js +468 -0
- package/dist/server/http/app.js +111 -0
- package/dist/server/http/artifacts.js +53 -0
- package/dist/server/http/data.js +54 -0
- package/dist/server/http/devices.js +47 -0
- package/dist/server/http/events.js +134 -0
- package/dist/server/http/idempotency.js +53 -0
- package/dist/server/http/input.js +106 -0
- package/dist/server/http/mail.js +52 -0
- package/dist/server/http/mcp.js +134 -0
- package/dist/server/http/notes.js +91 -0
- package/dist/server/http/problem.js +55 -0
- package/dist/server/http/providers.js +131 -0
- package/dist/server/http/schedules.js +58 -0
- package/dist/server/http/search.js +42 -0
- package/dist/server/http/security.js +168 -0
- package/dist/server/http/skills.js +53 -0
- package/dist/server/http/system.js +26 -0
- package/dist/server/ids.js +30 -0
- package/dist/server/keys.js +51 -0
- package/dist/server/mail/envelope.js +152 -0
- package/dist/server/mail/post.js +603 -0
- package/dist/server/mail/store.js +279 -0
- package/dist/server/manage.js +601 -0
- package/dist/server/mcp-builtin.js +179 -0
- package/dist/server/mcp-config.js +305 -0
- package/dist/server/mcp-oauth.js +448 -0
- package/dist/server/mcp.js +668 -0
- package/dist/server/model/gateway.js +410 -0
- package/dist/server/paths.js +34 -0
- package/dist/server/permissions/engine.js +249 -0
- package/dist/server/permissions/paths.js +93 -0
- package/dist/server/permissions/shell.js +635 -0
- package/dist/server/push.js +345 -0
- package/dist/server/reveal.js +36 -0
- package/dist/server/runtime.js +17 -0
- package/dist/server/schedules.js +356 -0
- package/dist/server/settings.js +80 -0
- package/dist/server/skills.js +262 -0
- package/dist/server/store.js +1077 -0
- package/dist/server/tools/files.js +318 -0
- package/dist/server/tools/html.js +221 -0
- package/dist/server/tools/jobs.js +38 -0
- package/dist/server/tools/mail.js +680 -0
- package/dist/server/tools/match.js +81 -0
- package/dist/server/tools/misc.js +253 -0
- package/dist/server/tools/process.js +128 -0
- package/dist/server/tools/read-state.js +40 -0
- package/dist/server/tools/registry.js +43 -0
- package/dist/server/tools/search.js +175 -0
- package/dist/server/tools/shell.js +124 -0
- package/dist/server/tools/types.js +43 -0
- package/dist/server/tools/web-search.js +198 -0
- package/dist/server/tools/web.js +240 -0
- package/dist/shared/cron.js +105 -0
- package/dist/shared/mcp-presets.js +170 -0
- package/dist/shared/messages.js +45 -0
- package/dist/shared/policy.js +42 -0
- package/dist/shared/types.js +34 -0
- package/dist/shared/version.js +8 -0
- package/mcp-builtin/package-lock.json +3398 -0
- package/mcp-builtin/package.json +14 -0
- package/mcp-builtin/presets/gitee/package-lock.json +105 -0
- package/mcp-builtin/presets/gitee/package.json +10 -0
- package/mcp-builtin/presets/notion/package-lock.json +2243 -0
- package/mcp-builtin/presets/notion/package.json +10 -0
- package/mcp-builtin/presets/sentry/package-lock.json +28 -0
- package/mcp-builtin/presets/sentry/package.json +10 -0
- package/package.json +75 -5
- package/web/dist/THIRD-PARTY-NOTICES.txt +1944 -0
- package/web/dist/assets/index-B9oWPSod.css +1 -0
- package/web/dist/assets/index-C5qBMzFX.js +68 -0
- package/web/dist/icons/app-icon.png +0 -0
- package/web/dist/icons/apple-touch-icon.png +0 -0
- package/web/dist/icons/favicon-16.png +0 -0
- package/web/dist/icons/favicon-32.png +0 -0
- package/web/dist/icons/favicon-64.png +0 -0
- package/web/dist/icons/tenon-mark.svg +1 -0
- package/web/dist/icons/yew-mark.svg +1 -0
- package/web/dist/index.html +18 -0
- package/web/dist/mascot/gift.webp +0 -0
- package/web/dist/mascot/greeting.webp +0 -0
- package/web/dist/mascot/happy.webp +0 -0
- package/web/dist/mascot/lost.webp +0 -0
- package/web/dist/mascot/shush.webp +0 -0
- package/web/dist/mascot/sleepy.webp +0 -0
- package/web/dist/mascot/sorry.webp +0 -0
- package/web/dist/mascot/thinking.webp +0 -0
- package/web/dist/mascot/waking.webp +0 -0
- package/web/dist/mascot/writing.webp +0 -0
package/dist/cli/app.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { chmodSync, existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { homedir, tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { parseArgs } from "node:util";
|
|
7
|
+
import { VERSION } from "../shared/version.js";
|
|
8
|
+
import { EXIT_ERROR, EXIT_OK, UsageError } from "./io.js";
|
|
9
|
+
const HELP = `Usage: yew app <install|uninstall|status> [options]
|
|
10
|
+
|
|
11
|
+
Put a Yew icon in your Applications folder (macOS). Clicking it starts Yew in
|
|
12
|
+
the background if it is not running, then opens the web interface, signed in.
|
|
13
|
+
|
|
14
|
+
The icon is a small launcher for this installation of Yew: it runs the same
|
|
15
|
+
yew you run in a terminal, with the Node.js found now. Run install again after
|
|
16
|
+
you move or update Node.js or Yew.
|
|
17
|
+
|
|
18
|
+
Commands:
|
|
19
|
+
install Create ~/Applications/Yew.app
|
|
20
|
+
uninstall Remove it; Yew itself and your data stay
|
|
21
|
+
status Show whether it is there
|
|
22
|
+
|
|
23
|
+
Options:
|
|
24
|
+
--json Print as JSON
|
|
25
|
+
-h, --help Show this help
|
|
26
|
+
`;
|
|
27
|
+
export function realAppHost() {
|
|
28
|
+
const here = (path) => fileURLToPath(new URL(path, import.meta.url));
|
|
29
|
+
const icon = ["../../web/dist/icons/app-icon.png", "../../web/public/icons/app-icon.png"]
|
|
30
|
+
.map(here)
|
|
31
|
+
.find((path) => existsSync(path));
|
|
32
|
+
return {
|
|
33
|
+
platform: process.platform,
|
|
34
|
+
homeDir: homedir(),
|
|
35
|
+
node: process.execPath,
|
|
36
|
+
entry: here(import.meta.url.endsWith(".ts") ? "./main.ts" : "./main.js"),
|
|
37
|
+
icon: icon ?? null,
|
|
38
|
+
run: (command, args) => spawnSync(command, args, { stdio: "ignore" }).status,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const xml = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
42
|
+
/** A value inside single quotes in a shell script. */
|
|
43
|
+
const quoted = (value) => `'${value.replace(/'/g, `'\\''`)}'`;
|
|
44
|
+
export function infoPlist() {
|
|
45
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
46
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
47
|
+
<plist version="1.0">
|
|
48
|
+
<dict>
|
|
49
|
+
<key>CFBundleName</key>
|
|
50
|
+
<string>Yew</string>
|
|
51
|
+
<key>CFBundleDisplayName</key>
|
|
52
|
+
<string>Yew</string>
|
|
53
|
+
<key>CFBundleIdentifier</key>
|
|
54
|
+
<string>cn.tenonai.apps.yew.launcher</string>
|
|
55
|
+
<key>CFBundleExecutable</key>
|
|
56
|
+
<string>yew-launcher</string>
|
|
57
|
+
<key>CFBundleIconFile</key>
|
|
58
|
+
<string>AppIcon</string>
|
|
59
|
+
<key>CFBundlePackageType</key>
|
|
60
|
+
<string>APPL</string>
|
|
61
|
+
<key>CFBundleShortVersionString</key>
|
|
62
|
+
<string>${xml(VERSION)}</string>
|
|
63
|
+
<key>CFBundleVersion</key>
|
|
64
|
+
<string>${xml(VERSION)}</string>
|
|
65
|
+
<key>LSMinimumSystemVersion</key>
|
|
66
|
+
<string>12.0</string>
|
|
67
|
+
<key>NSHighResolutionCapable</key>
|
|
68
|
+
<true/>
|
|
69
|
+
</dict>
|
|
70
|
+
</plist>
|
|
71
|
+
`;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The launcher: open Yew's interface; when Yew is not running, start it in the background first
|
|
75
|
+
* and wait until it answers. Its log goes where the login service's does.
|
|
76
|
+
*/
|
|
77
|
+
export function launcherScript(host, env, log) {
|
|
78
|
+
const yew = `${quoted(host.node)} ${quoted(host.entry)}`;
|
|
79
|
+
return `#!/bin/sh
|
|
80
|
+
# Yew's launcher, written by 'yew app install'. Run that again after moving Node.js or Yew.
|
|
81
|
+
${Object.entries(env)
|
|
82
|
+
.map(([key, value]) => `export ${key}=${quoted(value)}`)
|
|
83
|
+
.join("\n")}
|
|
84
|
+
if ${yew} open >/dev/null 2>&1; then exit 0; fi
|
|
85
|
+
mkdir -p ${quoted(join(log, ".."))}
|
|
86
|
+
nohup ${yew} serve >> ${quoted(log)} 2>&1 &
|
|
87
|
+
tries=0
|
|
88
|
+
while [ "$tries" -lt 60 ]; do
|
|
89
|
+
sleep 0.25
|
|
90
|
+
if ${yew} open >/dev/null 2>&1; then exit 0; fi
|
|
91
|
+
tries=$((tries + 1))
|
|
92
|
+
done
|
|
93
|
+
osascript -e 'display alert "Yew did not start" message "Run yew serve in a terminal to see why."' >/dev/null 2>&1
|
|
94
|
+
exit 1
|
|
95
|
+
`;
|
|
96
|
+
}
|
|
97
|
+
const SIZES = [16, 32, 128, 256, 512];
|
|
98
|
+
/** Where the launcher goes: the person's own Applications folder. */
|
|
99
|
+
export const appPath = (host) => join(host.homeDir, "Applications", "Yew.app");
|
|
100
|
+
export const appInstalled = (host) => existsSync(join(appPath(host), "Contents", "MacOS", "yew-launcher"));
|
|
101
|
+
/** Makes Yew.app; returns whether its icon could be made (the app works without it). */
|
|
102
|
+
export function installApp(host, home, env) {
|
|
103
|
+
const app = appPath(host);
|
|
104
|
+
// Sessions' commands need your PATH; an app starts with a bare one.
|
|
105
|
+
const vars = { PATH: env.PATH ?? "/usr/bin:/bin" };
|
|
106
|
+
if (env.YEW_HOME)
|
|
107
|
+
vars.YEW_HOME = home;
|
|
108
|
+
rmSync(app, { recursive: true, force: true });
|
|
109
|
+
const contents = join(app, "Contents");
|
|
110
|
+
mkdirSync(join(contents, "MacOS"), { recursive: true });
|
|
111
|
+
mkdirSync(join(contents, "Resources"), { recursive: true });
|
|
112
|
+
writeFileSync(join(contents, "Info.plist"), infoPlist());
|
|
113
|
+
const launcher = join(contents, "MacOS", "yew-launcher");
|
|
114
|
+
writeFileSync(launcher, launcherScript(host, vars, join(home, "logs", "serve.log")));
|
|
115
|
+
chmodSync(launcher, 0o755);
|
|
116
|
+
// The icon: macOS's own tools make the sizes and the .icns. Without it the app still works.
|
|
117
|
+
let icon = false;
|
|
118
|
+
if (host.icon) {
|
|
119
|
+
const work = mkdtempSync(join(tmpdir(), "yew-icon-"));
|
|
120
|
+
const set = join(work, "AppIcon.iconset");
|
|
121
|
+
mkdirSync(set);
|
|
122
|
+
const made = SIZES.every((size) => [1, 2].every((factor) => host.run("sips", [
|
|
123
|
+
"-z",
|
|
124
|
+
String(size * factor),
|
|
125
|
+
String(size * factor),
|
|
126
|
+
host.icon,
|
|
127
|
+
"--out",
|
|
128
|
+
join(set, `icon_${size}x${size}${factor === 2 ? "@2x" : ""}.png`),
|
|
129
|
+
]) === 0));
|
|
130
|
+
icon =
|
|
131
|
+
made &&
|
|
132
|
+
host.run("iconutil", [
|
|
133
|
+
"-c",
|
|
134
|
+
"icns",
|
|
135
|
+
set,
|
|
136
|
+
"-o",
|
|
137
|
+
join(contents, "Resources", "AppIcon.icns"),
|
|
138
|
+
]) === 0;
|
|
139
|
+
rmSync(work, { recursive: true, force: true });
|
|
140
|
+
}
|
|
141
|
+
// Tells Finder and the Dock about the new app and its icon.
|
|
142
|
+
host.run("touch", [app]);
|
|
143
|
+
return { app, icon };
|
|
144
|
+
}
|
|
145
|
+
export function uninstallApp(host) {
|
|
146
|
+
rmSync(appPath(host), { recursive: true, force: true });
|
|
147
|
+
}
|
|
148
|
+
export function appCommand(host = realAppHost()) {
|
|
149
|
+
return {
|
|
150
|
+
name: "app",
|
|
151
|
+
summary: "Put a Yew icon in Applications (macOS)",
|
|
152
|
+
async run(args, io) {
|
|
153
|
+
const { values, positionals } = parseArgs({
|
|
154
|
+
args,
|
|
155
|
+
options: { json: { type: "boolean" }, help: { type: "boolean", short: "h" } },
|
|
156
|
+
allowPositionals: true,
|
|
157
|
+
strict: true,
|
|
158
|
+
});
|
|
159
|
+
if (values.help) {
|
|
160
|
+
io.stdout.write(HELP);
|
|
161
|
+
return EXIT_OK;
|
|
162
|
+
}
|
|
163
|
+
const action = positionals[0];
|
|
164
|
+
if (positionals.length !== 1 || !["install", "uninstall", "status"].includes(action ?? "")) {
|
|
165
|
+
throw new UsageError("yew app needs one of install, uninstall or status");
|
|
166
|
+
}
|
|
167
|
+
if (host.platform !== "darwin")
|
|
168
|
+
throw new Error("yew app works on macOS.");
|
|
169
|
+
const app = appPath(host);
|
|
170
|
+
const installed = appInstalled(host);
|
|
171
|
+
if (action === "status") {
|
|
172
|
+
if (values.json)
|
|
173
|
+
io.stdout.write(`${JSON.stringify({ installed, app })}\n`);
|
|
174
|
+
else
|
|
175
|
+
io.stdout.write(`Yew icon: ${installed ? app : "not installed"}\n`);
|
|
176
|
+
return EXIT_OK;
|
|
177
|
+
}
|
|
178
|
+
if (action === "uninstall") {
|
|
179
|
+
uninstallApp(host);
|
|
180
|
+
if (values.json)
|
|
181
|
+
io.stdout.write(`${JSON.stringify({ installed: false, app })}\n`);
|
|
182
|
+
else
|
|
183
|
+
io.stdout.write(installed ? `Removed ${app}.\n` : "The Yew icon was not installed.\n");
|
|
184
|
+
return EXIT_OK;
|
|
185
|
+
}
|
|
186
|
+
const { yewHome } = await import("../server/paths.js");
|
|
187
|
+
const { icon } = installApp(host, yewHome(io.env), io.env);
|
|
188
|
+
if (values.json)
|
|
189
|
+
io.stdout.write(`${JSON.stringify({ installed: true, app, icon })}\n`);
|
|
190
|
+
else {
|
|
191
|
+
io.stdout.write(`Yew is in your Applications folder: ${app}\nOpen it from Launchpad or Spotlight, or drag it to the Dock.\n`);
|
|
192
|
+
if (!icon)
|
|
193
|
+
io.stderr.write("yew: the icon could not be made; the app has a plain one.\n");
|
|
194
|
+
}
|
|
195
|
+
return icon || !host.icon ? EXIT_OK : EXIT_ERROR;
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { parseArgs } from "node:util";
|
|
3
|
+
import { EXIT_OK, UsageError } from "./io.js";
|
|
4
|
+
const HELP = `Usage: yew export <folder> [options]
|
|
5
|
+
|
|
6
|
+
Write everything Yew keeps into a folder, as files you can read without Yew:
|
|
7
|
+
each session as Markdown; letters, decision cards, scheduled tasks and
|
|
8
|
+
settings as JSON; and every version of every artifact. The folder must be new
|
|
9
|
+
or empty.
|
|
10
|
+
|
|
11
|
+
API keys stay in the system keychain and are not exported; neither are paired
|
|
12
|
+
phones or sign-in tokens.
|
|
13
|
+
|
|
14
|
+
Options:
|
|
15
|
+
--json Print what was written as JSON
|
|
16
|
+
-h, --help Show this help
|
|
17
|
+
`;
|
|
18
|
+
export function exportCommand() {
|
|
19
|
+
return {
|
|
20
|
+
name: "export",
|
|
21
|
+
summary: "Write all of Yew's data into a folder",
|
|
22
|
+
async run(args, io) {
|
|
23
|
+
const { values, positionals } = parseArgs({
|
|
24
|
+
args,
|
|
25
|
+
options: { json: { type: "boolean" }, help: { type: "boolean", short: "h" } },
|
|
26
|
+
allowPositionals: true,
|
|
27
|
+
strict: true,
|
|
28
|
+
});
|
|
29
|
+
if (values.help) {
|
|
30
|
+
io.stdout.write(HELP);
|
|
31
|
+
return EXIT_OK;
|
|
32
|
+
}
|
|
33
|
+
if (positionals.length !== 1)
|
|
34
|
+
throw new UsageError("yew export needs one folder");
|
|
35
|
+
const folder = resolve(positionals[0]);
|
|
36
|
+
const { yewHome, dbPath } = await import("../server/paths.js");
|
|
37
|
+
const { openDatabase } = await import("../server/db/database.js");
|
|
38
|
+
const { EventBus } = await import("../server/events.js");
|
|
39
|
+
const { Store } = await import("../server/store.js");
|
|
40
|
+
const { exportAll } = await import("../server/data-export.js");
|
|
41
|
+
const home = yewHome(io.env);
|
|
42
|
+
const db = openDatabase(dbPath(home));
|
|
43
|
+
try {
|
|
44
|
+
const counts = exportAll(new Store(db, new EventBus()), folder, Date.now(), home);
|
|
45
|
+
if (values.json)
|
|
46
|
+
io.stdout.write(`${JSON.stringify({ folder, ...counts })}\n`);
|
|
47
|
+
else {
|
|
48
|
+
io.stdout.write(`Exported ${counts.sessions} sessions, ${counts.letters} letters, ${counts.cards} decision cards, ${counts.schedules} scheduled tasks and ${counts.artifacts} artifacts to ${folder} (${counts.files} files).\n`);
|
|
49
|
+
}
|
|
50
|
+
return EXIT_OK;
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
db.close();
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
package/dist/cli/io.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
|
+
export const EXIT_OK = 0;
|
|
3
|
+
export const EXIT_ERROR = 1;
|
|
4
|
+
export const EXIT_USAGE = 2;
|
|
5
|
+
/** Thrown for bad arguments; the runner prints it with a pointer to --help and exits with 2. */
|
|
6
|
+
export class UsageError extends Error {
|
|
7
|
+
}
|
|
8
|
+
/** clig.dev and spec 20.5: no ANSI colors when NO_COLOR is non-empty or the stream is not a terminal. */
|
|
9
|
+
export function wantsColor(stream, env) {
|
|
10
|
+
if (env.NO_COLOR)
|
|
11
|
+
return false;
|
|
12
|
+
if (env.TERM === "dumb")
|
|
13
|
+
return false;
|
|
14
|
+
return stream.isTTY === true;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Reads a secret. On a terminal it prompts on stderr and reads without echo; otherwise it reads all of
|
|
18
|
+
* standard input, so `pbpaste | yew key set deepseek` works. Never takes the secret from arguments.
|
|
19
|
+
*/
|
|
20
|
+
export async function readSecret(io, prompt) {
|
|
21
|
+
const stdin = io.stdin;
|
|
22
|
+
if (!stdin.isTTY || !stdin.setRawMode) {
|
|
23
|
+
let data = "";
|
|
24
|
+
for await (const chunk of stdin)
|
|
25
|
+
data += chunk.toString();
|
|
26
|
+
return data.trim();
|
|
27
|
+
}
|
|
28
|
+
io.stderr.write(prompt);
|
|
29
|
+
stdin.setRawMode(true);
|
|
30
|
+
let value = "";
|
|
31
|
+
try {
|
|
32
|
+
for await (const chunk of stdin) {
|
|
33
|
+
for (const char of chunk.toString()) {
|
|
34
|
+
if (char === "\r" || char === "\n") {
|
|
35
|
+
io.stderr.write("\n");
|
|
36
|
+
return value.trim();
|
|
37
|
+
}
|
|
38
|
+
if (char === "\u0003" || char === "\u0004") {
|
|
39
|
+
io.stderr.write("\n");
|
|
40
|
+
throw new Error("Cancelled.");
|
|
41
|
+
}
|
|
42
|
+
if (char === "\u007f" || char === "\b")
|
|
43
|
+
value = value.slice(0, -1);
|
|
44
|
+
else
|
|
45
|
+
value += char;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return value.trim();
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
stdin.setRawMode(false);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Asks a yes/no question on a terminal; anything but y or yes means no. */
|
|
55
|
+
export async function confirm(io, question) {
|
|
56
|
+
io.stderr.write(`${question} [y/N] `);
|
|
57
|
+
for await (const chunk of io.stdin) {
|
|
58
|
+
const answer = chunk.toString().split(/\r?\n/)[0]?.trim().toLowerCase() ?? "";
|
|
59
|
+
return answer === "y" || answer === "yes";
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
export function paint(format, text, stream, env) {
|
|
64
|
+
return wantsColor(stream, env) ? styleText(format, text, { validateStream: false }) : text;
|
|
65
|
+
}
|
package/dist/cli/key.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { confirm, EXIT_ERROR, EXIT_OK, EXIT_USAGE, readSecret, UsageError, } from "./io.js";
|
|
3
|
+
const HELP = `Usage: yew key <command> [options]
|
|
4
|
+
|
|
5
|
+
Manage API keys for model providers. Keys are kept in the system keychain only.
|
|
6
|
+
|
|
7
|
+
Commands:
|
|
8
|
+
set <provider> Save a key. On a terminal it is read without echo;
|
|
9
|
+
otherwise it is read from standard input.
|
|
10
|
+
delete <provider> Remove a saved key. Asks first; --yes skips the question.
|
|
11
|
+
list Show every provider and whether it has a key.
|
|
12
|
+
|
|
13
|
+
Options:
|
|
14
|
+
--json With list, print JSON
|
|
15
|
+
-y, --yes With delete, do not ask
|
|
16
|
+
-h, --help Show this help
|
|
17
|
+
|
|
18
|
+
Examples:
|
|
19
|
+
yew key set deepseek
|
|
20
|
+
pbpaste | yew key set deepseek
|
|
21
|
+
`;
|
|
22
|
+
const REGION_ORDER = { cn: 0, custom: 1, global: 2 };
|
|
23
|
+
function findProvider(deps, id) {
|
|
24
|
+
if (!id)
|
|
25
|
+
throw new UsageError("missing provider. Run 'yew key list' to see them.");
|
|
26
|
+
const provider = deps.providers.find((p) => p.id === id);
|
|
27
|
+
if (!provider)
|
|
28
|
+
throw new UsageError(`unknown provider '${id}'. Run 'yew key list' to see them.`);
|
|
29
|
+
return provider;
|
|
30
|
+
}
|
|
31
|
+
export function keyCommand(load) {
|
|
32
|
+
return {
|
|
33
|
+
name: "key",
|
|
34
|
+
summary: "Manage API keys for model providers",
|
|
35
|
+
async run(args, io) {
|
|
36
|
+
const { values, positionals } = parseArgs({
|
|
37
|
+
args,
|
|
38
|
+
options: {
|
|
39
|
+
help: { type: "boolean", short: "h" },
|
|
40
|
+
json: { type: "boolean" },
|
|
41
|
+
yes: { type: "boolean", short: "y" },
|
|
42
|
+
},
|
|
43
|
+
allowPositionals: true,
|
|
44
|
+
strict: true,
|
|
45
|
+
});
|
|
46
|
+
if (values.help) {
|
|
47
|
+
io.stdout.write(HELP);
|
|
48
|
+
return EXIT_OK;
|
|
49
|
+
}
|
|
50
|
+
const [sub, id, extra] = positionals;
|
|
51
|
+
if (!sub) {
|
|
52
|
+
io.stderr.write(HELP);
|
|
53
|
+
return EXIT_USAGE;
|
|
54
|
+
}
|
|
55
|
+
if (extra !== undefined)
|
|
56
|
+
throw new UsageError(`unexpected argument '${extra}'`);
|
|
57
|
+
const deps = await load();
|
|
58
|
+
try {
|
|
59
|
+
if (sub === "list") {
|
|
60
|
+
const rows = await Promise.all([...deps.providers]
|
|
61
|
+
.sort((a, b) => REGION_ORDER[a.region] - REGION_ORDER[b.region] || a.id.localeCompare(b.id))
|
|
62
|
+
.map(async (p) => ({
|
|
63
|
+
id: p.id,
|
|
64
|
+
name: p.name,
|
|
65
|
+
region: p.region,
|
|
66
|
+
hasKey: !p.keyRequired || (await deps.keys.get(p.id)) !== null,
|
|
67
|
+
})));
|
|
68
|
+
if (values.json) {
|
|
69
|
+
io.stdout.write(`${JSON.stringify(rows)}\n`);
|
|
70
|
+
return EXIT_OK;
|
|
71
|
+
}
|
|
72
|
+
const width = Math.max(...rows.map((row) => row.id.length));
|
|
73
|
+
for (const row of rows) {
|
|
74
|
+
io.stdout.write(`${row.id.padEnd(width)} ${row.hasKey ? "key saved" : "no key"} ${row.name}\n`);
|
|
75
|
+
}
|
|
76
|
+
return EXIT_OK;
|
|
77
|
+
}
|
|
78
|
+
if (sub === "set") {
|
|
79
|
+
const provider = findProvider(deps, id);
|
|
80
|
+
const key = await readSecret(io, `API key for ${provider.name} (input hidden): `);
|
|
81
|
+
if (!key) {
|
|
82
|
+
io.stderr.write("yew: no key was entered; nothing saved.\n");
|
|
83
|
+
return EXIT_ERROR;
|
|
84
|
+
}
|
|
85
|
+
await deps.keys.set(provider.id, key);
|
|
86
|
+
io.stdout.write(`Saved the API key for ${provider.name} in the system keychain.\n`);
|
|
87
|
+
return EXIT_OK;
|
|
88
|
+
}
|
|
89
|
+
if (sub === "delete") {
|
|
90
|
+
const provider = findProvider(deps, id);
|
|
91
|
+
if (!values.yes) {
|
|
92
|
+
if (!io.stdin.isTTY) {
|
|
93
|
+
throw new UsageError("refusing to delete without a terminal; pass --yes to confirm.");
|
|
94
|
+
}
|
|
95
|
+
if (!(await confirm(io, `Delete the API key for ${provider.name} from the keychain?`))) {
|
|
96
|
+
io.stderr.write("Nothing deleted.\n");
|
|
97
|
+
return EXIT_ERROR;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const removed = await deps.keys.delete(provider.id);
|
|
101
|
+
io.stdout.write(removed
|
|
102
|
+
? `Deleted the API key for ${provider.name}.\n`
|
|
103
|
+
: `There was no API key for ${provider.name}.\n`);
|
|
104
|
+
return EXIT_OK;
|
|
105
|
+
}
|
|
106
|
+
throw new UsageError(`unknown key command '${sub}'`);
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
deps.close?.();
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
package/dist/cli/main.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { appCommand } from "./app.js";
|
|
3
|
+
import { exportCommand } from "./export.js";
|
|
4
|
+
import { keyCommand } from "./key.js";
|
|
5
|
+
import { mcpCommand } from "./mcp.js";
|
|
6
|
+
import { remoteCommand } from "./remote.js";
|
|
7
|
+
import { run } from "./run.js";
|
|
8
|
+
import { scheduleCommand } from "./schedule.js";
|
|
9
|
+
import { sendCommand } from "./send.js";
|
|
10
|
+
import { openCommand, serveCommand } from "./serve.js";
|
|
11
|
+
import { serviceCommand } from "./service.js";
|
|
12
|
+
const commands = [
|
|
13
|
+
serveCommand(),
|
|
14
|
+
openCommand(),
|
|
15
|
+
sendCommand(),
|
|
16
|
+
scheduleCommand(),
|
|
17
|
+
remoteCommand(),
|
|
18
|
+
serviceCommand(),
|
|
19
|
+
appCommand(),
|
|
20
|
+
exportCommand(),
|
|
21
|
+
mcpCommand(),
|
|
22
|
+
keyCommand(async () => {
|
|
23
|
+
const { openRuntime } = await import("../server/runtime.js");
|
|
24
|
+
const runtime = openRuntime();
|
|
25
|
+
const { SEARCH_SERVICES } = await import("../server/tools/web-search.js");
|
|
26
|
+
return {
|
|
27
|
+
keys: runtime.keys,
|
|
28
|
+
// Search services keep their keys the same way: yew key set search-bocha.
|
|
29
|
+
providers: [
|
|
30
|
+
...runtime.gateway.providers(),
|
|
31
|
+
...SEARCH_SERVICES.map((service) => ({
|
|
32
|
+
id: service.id,
|
|
33
|
+
name: service.name,
|
|
34
|
+
region: service.region,
|
|
35
|
+
baseUrl: service.origin,
|
|
36
|
+
keyRequired: true,
|
|
37
|
+
custom: false,
|
|
38
|
+
})),
|
|
39
|
+
],
|
|
40
|
+
close: runtime.close,
|
|
41
|
+
};
|
|
42
|
+
}),
|
|
43
|
+
];
|
|
44
|
+
process.exitCode = await run(process.argv.slice(2), { stdout: process.stdout, stderr: process.stderr, stdin: process.stdin, env: process.env }, commands);
|
package/dist/cli/mcp.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { VERSION } from "../shared/version.js";
|
|
3
|
+
import { EXIT_OK, UsageError } from "./io.js";
|
|
4
|
+
const HELP = `Usage: yew mcp list [options]
|
|
5
|
+
|
|
6
|
+
Show the MCP servers set up in mcp.json in Yew's data folder: whether each one
|
|
7
|
+
connects, and the tools it offers. The file uses the usual shape:
|
|
8
|
+
|
|
9
|
+
{ "mcpServers": {
|
|
10
|
+
"files": { "command": "npx", "args": ["some-mcp-server"], "env": { "KEY": "\${KEY}" } },
|
|
11
|
+
"search": { "url": "https://example.com/mcp", "headers": { "Authorization": "Bearer \${TOKEN}" } } } }
|
|
12
|
+
|
|
13
|
+
\${NAME} is taken from the environment Yew runs in. Sessions ask you before
|
|
14
|
+
they use a tool of a server for the first time. A server with "disabled": true
|
|
15
|
+
stays in the file and is not started. A project's own .mcp.json is not read.
|
|
16
|
+
Servers can also be added, disabled and removed in the settings of the web
|
|
17
|
+
interface.
|
|
18
|
+
|
|
19
|
+
Options:
|
|
20
|
+
--json Print as JSON
|
|
21
|
+
-h, --help Show this help
|
|
22
|
+
`;
|
|
23
|
+
export function mcpCommand() {
|
|
24
|
+
return {
|
|
25
|
+
name: "mcp",
|
|
26
|
+
summary: "Show the MCP servers and their tools",
|
|
27
|
+
async run(args, io) {
|
|
28
|
+
const { values, positionals } = parseArgs({
|
|
29
|
+
args,
|
|
30
|
+
options: { json: { type: "boolean" }, help: { type: "boolean", short: "h" } },
|
|
31
|
+
allowPositionals: true,
|
|
32
|
+
strict: true,
|
|
33
|
+
});
|
|
34
|
+
if (values.help) {
|
|
35
|
+
io.stdout.write(HELP);
|
|
36
|
+
return EXIT_OK;
|
|
37
|
+
}
|
|
38
|
+
if (positionals.length !== 1 || positionals[0] !== "list") {
|
|
39
|
+
throw new UsageError("yew mcp needs list");
|
|
40
|
+
}
|
|
41
|
+
const { yewHome } = await import("../server/paths.js");
|
|
42
|
+
const { McpHub } = await import("../server/mcp.js");
|
|
43
|
+
const { builtinInstaller, builtinMcp } = await import("../server/mcp-builtin.js");
|
|
44
|
+
const home = yewHome(io.env);
|
|
45
|
+
const hub = new McpHub({
|
|
46
|
+
yewHome: home,
|
|
47
|
+
version: VERSION,
|
|
48
|
+
env: io.env,
|
|
49
|
+
log: () => { },
|
|
50
|
+
builtin: builtinMcp(home, io.env),
|
|
51
|
+
prepare: builtinInstaller({ yewHome: home, env: io.env }),
|
|
52
|
+
});
|
|
53
|
+
try {
|
|
54
|
+
await hub.refresh();
|
|
55
|
+
const servers = hub.status();
|
|
56
|
+
if (values.json) {
|
|
57
|
+
io.stdout.write(`${JSON.stringify(servers)}\n`);
|
|
58
|
+
return EXIT_OK;
|
|
59
|
+
}
|
|
60
|
+
if (servers.length === 0) {
|
|
61
|
+
io.stdout.write("No MCP servers are set up. See 'yew mcp --help'.\n");
|
|
62
|
+
return EXIT_OK;
|
|
63
|
+
}
|
|
64
|
+
for (const server of servers) {
|
|
65
|
+
io.stdout.write(`${server.name} (${server.kind}): ${server.state === "ready" ? `${server.tools.length} tools` : server.state === "disabled" ? "disabled" : `not connected: ${server.error ?? "unknown"}`}\n`);
|
|
66
|
+
for (const tool of server.tools)
|
|
67
|
+
io.stdout.write(` ${tool}\n`);
|
|
68
|
+
}
|
|
69
|
+
return EXIT_OK;
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
hub.stop();
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { RELAY_URL } from "../remote/protocol.js";
|
|
3
|
+
import { EXIT_ERROR, EXIT_OK, UsageError } from "./io.js";
|
|
4
|
+
import { serviceRunning } from "./serve.js";
|
|
5
|
+
const HELP = `Usage: yew remote <on|off|status|pair> [options]
|
|
6
|
+
|
|
7
|
+
Let your phone reach Yew on this Mac through Yew's relay. Both sides connect
|
|
8
|
+
out to the relay, so this Mac opens no port; everything between them is
|
|
9
|
+
end-to-end encrypted, and the relay sees only ciphertext.
|
|
10
|
+
|
|
11
|
+
Commands:
|
|
12
|
+
on Turn on phone access
|
|
13
|
+
off Turn it off; paired phones stay paired
|
|
14
|
+
status Show whether it is on, the relay and the paired phones
|
|
15
|
+
pair Show a QR code to pair a phone (valid for 5 minutes, once)
|
|
16
|
+
|
|
17
|
+
Options:
|
|
18
|
+
--relay <url> With on: the relay to use (default wss://relay.tenonai.cn)
|
|
19
|
+
--json Print as JSON
|
|
20
|
+
-h, --help Show this help
|
|
21
|
+
`;
|
|
22
|
+
export function remoteCommand() {
|
|
23
|
+
return {
|
|
24
|
+
name: "remote",
|
|
25
|
+
summary: "Let your phone reach this Mac",
|
|
26
|
+
async run(args, io) {
|
|
27
|
+
const { values, positionals } = parseArgs({
|
|
28
|
+
args,
|
|
29
|
+
options: {
|
|
30
|
+
relay: { type: "string" },
|
|
31
|
+
json: { type: "boolean" },
|
|
32
|
+
help: { type: "boolean", short: "h" },
|
|
33
|
+
},
|
|
34
|
+
allowPositionals: true,
|
|
35
|
+
strict: true,
|
|
36
|
+
});
|
|
37
|
+
if (values.help) {
|
|
38
|
+
io.stdout.write(HELP);
|
|
39
|
+
return EXIT_OK;
|
|
40
|
+
}
|
|
41
|
+
const action = positionals[0];
|
|
42
|
+
if (positionals.length !== 1 || !["on", "off", "status", "pair"].includes(action ?? "")) {
|
|
43
|
+
throw new UsageError("yew remote needs one of on, off, status or pair");
|
|
44
|
+
}
|
|
45
|
+
const relay = values.relay;
|
|
46
|
+
if (relay !== undefined && !RELAY_URL.test(relay)) {
|
|
47
|
+
throw new UsageError("--relay must be a wss:// address (ws:// only inside this network)");
|
|
48
|
+
}
|
|
49
|
+
const { yewHome, dbPath } = await import("../server/paths.js");
|
|
50
|
+
const { openDatabase } = await import("../server/db/database.js");
|
|
51
|
+
const { EventBus } = await import("../server/events.js");
|
|
52
|
+
const { Store } = await import("../server/store.js");
|
|
53
|
+
const { readSettings } = await import("../server/settings.js");
|
|
54
|
+
const home = yewHome(io.env);
|
|
55
|
+
const db = openDatabase(dbPath(home));
|
|
56
|
+
try {
|
|
57
|
+
const store = new Store(db, new EventBus());
|
|
58
|
+
const settings = readSettings(store).remote;
|
|
59
|
+
const running = serviceRunning(home);
|
|
60
|
+
if (action === "on" || action === "off") {
|
|
61
|
+
const next = {
|
|
62
|
+
...settings,
|
|
63
|
+
enabled: action === "on",
|
|
64
|
+
...(relay ? { relayUrl: relay } : {}),
|
|
65
|
+
};
|
|
66
|
+
store.setSetting("remote", next);
|
|
67
|
+
if (values.json)
|
|
68
|
+
io.stdout.write(`${JSON.stringify(next)}\n`);
|
|
69
|
+
else
|
|
70
|
+
io.stdout.write(`Phone access is ${next.enabled ? "on" : "off"} (${next.relayUrl}).\n`);
|
|
71
|
+
// The running service picks the setting up within a few seconds.
|
|
72
|
+
if (!running)
|
|
73
|
+
io.stderr.write("yew: Yew is not running; start it with 'yew serve'.\n");
|
|
74
|
+
return EXIT_OK;
|
|
75
|
+
}
|
|
76
|
+
if (action === "status") {
|
|
77
|
+
const devices = store.listDevices();
|
|
78
|
+
if (values.json) {
|
|
79
|
+
io.stdout.write(`${JSON.stringify({ ...settings, running, devices })}\n`);
|
|
80
|
+
return EXIT_OK;
|
|
81
|
+
}
|
|
82
|
+
io.stdout.write(`Phone access: ${settings.enabled ? "on" : "off"}\nRelay: ${settings.relayUrl}\nYew service: ${running ? "running" : "not running"}\nPaired phones: ${devices.length}\n`);
|
|
83
|
+
for (const device of devices) {
|
|
84
|
+
const seen = device.lastSeenAt ? new Date(device.lastSeenAt).toISOString() : "never";
|
|
85
|
+
io.stdout.write(` ${device.name} (last seen ${seen})\n`);
|
|
86
|
+
}
|
|
87
|
+
return EXIT_OK;
|
|
88
|
+
}
|
|
89
|
+
if (!settings.enabled) {
|
|
90
|
+
io.stderr.write("yew: turn on phone access first: yew remote on\n");
|
|
91
|
+
return EXIT_ERROR;
|
|
92
|
+
}
|
|
93
|
+
const { systemKeys } = await import("../server/keys.js");
|
|
94
|
+
const { loadIdentity, createPairing } = await import("../remote/identity.js");
|
|
95
|
+
const { desktopName } = await import("../remote/access.js");
|
|
96
|
+
const identity = await loadIdentity(systemKeys("remote"));
|
|
97
|
+
const { link, expiresAt } = createPairing(store, identity, {
|
|
98
|
+
relay: settings.relayUrl,
|
|
99
|
+
name: desktopName(),
|
|
100
|
+
});
|
|
101
|
+
if (values.json) {
|
|
102
|
+
io.stdout.write(`${JSON.stringify({ link, expiresAt })}\n`);
|
|
103
|
+
return EXIT_OK;
|
|
104
|
+
}
|
|
105
|
+
const { renderUnicodeCompact } = await import("uqr");
|
|
106
|
+
io.stdout.write(`${renderUnicodeCompact(link)}\nScan this with Yew on your phone within 5 minutes.\n`);
|
|
107
|
+
if (!running)
|
|
108
|
+
io.stderr.write("yew: Yew is not running; start it with 'yew serve'.\n");
|
|
109
|
+
return EXIT_OK;
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
db.close();
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|