@tenonai/yew 0.0.0-stage → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/CHANGELOG.md +273 -0
  2. package/LICENSE +21 -0
  3. package/README.md +64 -2
  4. package/THIRD-PARTY-NOTICES.md +122 -0
  5. package/bin/yew.js +9 -0
  6. package/dist/cli/app.js +211 -0
  7. package/dist/cli/export.js +57 -0
  8. package/dist/cli/io.js +65 -0
  9. package/dist/cli/key.js +113 -0
  10. package/dist/cli/main.js +58 -0
  11. package/dist/cli/mcp.js +76 -0
  12. package/dist/cli/remote.js +116 -0
  13. package/dist/cli/run.js +72 -0
  14. package/dist/cli/schedule.js +123 -0
  15. package/dist/cli/send.js +127 -0
  16. package/dist/cli/serve.js +301 -0
  17. package/dist/cli/service.js +268 -0
  18. package/dist/cli/system.js +44 -0
  19. package/dist/remote/access.js +107 -0
  20. package/dist/remote/connector.js +278 -0
  21. package/dist/remote/identity.js +71 -0
  22. package/dist/remote/noise.js +287 -0
  23. package/dist/remote/protocol.js +51 -0
  24. package/dist/remote/push.js +37 -0
  25. package/dist/server/agent/compaction.js +242 -0
  26. package/dist/server/agent/context.js +120 -0
  27. package/dist/server/agent/held.js +48 -0
  28. package/dist/server/agent/helper.js +122 -0
  29. package/dist/server/agent/mailroom.js +510 -0
  30. package/dist/server/agent/prompt.js +268 -0
  31. package/dist/server/agent/runner.js +1159 -0
  32. package/dist/server/artifacts.js +216 -0
  33. package/dist/server/budget.js +88 -0
  34. package/dist/server/data-export.js +105 -0
  35. package/dist/server/data-usage.js +144 -0
  36. package/dist/server/db/database.js +49 -0
  37. package/dist/server/db/migrations.js +343 -0
  38. package/dist/server/errors.js +16 -0
  39. package/dist/server/events.js +17 -0
  40. package/dist/server/export.js +378 -0
  41. package/dist/server/folder-picker.js +32 -0
  42. package/dist/server/from-jig.js +98 -0
  43. package/dist/server/http/agents.js +78 -0
  44. package/dist/server/http/api.js +465 -0
  45. package/dist/server/http/app.js +111 -0
  46. package/dist/server/http/artifacts.js +53 -0
  47. package/dist/server/http/data.js +54 -0
  48. package/dist/server/http/devices.js +47 -0
  49. package/dist/server/http/events.js +134 -0
  50. package/dist/server/http/idempotency.js +53 -0
  51. package/dist/server/http/input.js +106 -0
  52. package/dist/server/http/mail.js +52 -0
  53. package/dist/server/http/mcp.js +134 -0
  54. package/dist/server/http/notes.js +91 -0
  55. package/dist/server/http/problem.js +55 -0
  56. package/dist/server/http/providers.js +131 -0
  57. package/dist/server/http/schedules.js +58 -0
  58. package/dist/server/http/search.js +42 -0
  59. package/dist/server/http/security.js +168 -0
  60. package/dist/server/http/skills.js +53 -0
  61. package/dist/server/http/system.js +26 -0
  62. package/dist/server/ids.js +30 -0
  63. package/dist/server/keys.js +70 -0
  64. package/dist/server/mail/envelope.js +152 -0
  65. package/dist/server/mail/post.js +603 -0
  66. package/dist/server/mail/store.js +279 -0
  67. package/dist/server/manage.js +601 -0
  68. package/dist/server/mcp-builtin.js +180 -0
  69. package/dist/server/mcp-config.js +305 -0
  70. package/dist/server/mcp-oauth.js +448 -0
  71. package/dist/server/mcp.js +668 -0
  72. package/dist/server/model/gateway.js +410 -0
  73. package/dist/server/paths.js +43 -0
  74. package/dist/server/permissions/engine.js +249 -0
  75. package/dist/server/permissions/paths.js +93 -0
  76. package/dist/server/permissions/shell.js +635 -0
  77. package/dist/server/push.js +345 -0
  78. package/dist/server/reveal.js +36 -0
  79. package/dist/server/runtime.js +17 -0
  80. package/dist/server/schedules.js +356 -0
  81. package/dist/server/settings.js +77 -0
  82. package/dist/server/skills.js +263 -0
  83. package/dist/server/store.js +1077 -0
  84. package/dist/server/tools/files.js +318 -0
  85. package/dist/server/tools/html.js +221 -0
  86. package/dist/server/tools/jobs.js +38 -0
  87. package/dist/server/tools/mail.js +680 -0
  88. package/dist/server/tools/match.js +81 -0
  89. package/dist/server/tools/misc.js +253 -0
  90. package/dist/server/tools/process.js +128 -0
  91. package/dist/server/tools/read-state.js +40 -0
  92. package/dist/server/tools/registry.js +43 -0
  93. package/dist/server/tools/search.js +175 -0
  94. package/dist/server/tools/shell.js +124 -0
  95. package/dist/server/tools/types.js +43 -0
  96. package/dist/server/tools/web-search.js +198 -0
  97. package/dist/server/tools/web.js +240 -0
  98. package/dist/shared/cron.js +105 -0
  99. package/dist/shared/mcp-presets.js +170 -0
  100. package/dist/shared/messages.js +45 -0
  101. package/dist/shared/policy.js +42 -0
  102. package/dist/shared/types.js +34 -0
  103. package/dist/shared/version.js +8 -0
  104. package/mcp-builtin/package-lock.json +3398 -0
  105. package/mcp-builtin/package.json +14 -0
  106. package/mcp-builtin/presets/gitee/package-lock.json +105 -0
  107. package/mcp-builtin/presets/gitee/package.json +10 -0
  108. package/mcp-builtin/presets/notion/package-lock.json +2243 -0
  109. package/mcp-builtin/presets/notion/package.json +10 -0
  110. package/mcp-builtin/presets/sentry/package-lock.json +28 -0
  111. package/mcp-builtin/presets/sentry/package.json +10 -0
  112. package/package.json +75 -5
  113. package/web/dist/THIRD-PARTY-NOTICES.txt +1944 -0
  114. package/web/dist/assets/index-BtK_SzpF.css +1 -0
  115. package/web/dist/assets/index-C0rnUFI-.js +68 -0
  116. package/web/dist/icons/app-icon.png +0 -0
  117. package/web/dist/icons/apple-touch-icon.png +0 -0
  118. package/web/dist/icons/favicon-16.png +0 -0
  119. package/web/dist/icons/favicon-32.png +0 -0
  120. package/web/dist/icons/favicon-64.png +0 -0
  121. package/web/dist/icons/tenon-mark.svg +1 -0
  122. package/web/dist/icons/yew-mark.svg +1 -0
  123. package/web/dist/index.html +18 -0
  124. package/web/dist/mascot/gift.webp +0 -0
  125. package/web/dist/mascot/greeting.webp +0 -0
  126. package/web/dist/mascot/happy.webp +0 -0
  127. package/web/dist/mascot/lost.webp +0 -0
  128. package/web/dist/mascot/shush.webp +0 -0
  129. package/web/dist/mascot/sleepy.webp +0 -0
  130. package/web/dist/mascot/sorry.webp +0 -0
  131. package/web/dist/mascot/thinking.webp +0 -0
  132. package/web/dist/mascot/waking.webp +0 -0
  133. package/web/dist/mascot/writing.webp +0 -0
@@ -0,0 +1,211 @@
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 { fromJigEnv, JIG_APP, JIG_LAUNCHER } from "../server/from-jig.js";
8
+ import { VERSION } from "../shared/version.js";
9
+ import { EXIT_ERROR, EXIT_OK, UsageError } from "./io.js";
10
+ const HELP = `Usage: yew app <install|uninstall|status> [options]
11
+
12
+ Put a Yew icon in your Applications folder (macOS). Clicking it starts Yew in
13
+ the background if it is not running, then opens the web interface, signed in.
14
+
15
+ The icon is a small launcher for this installation of Yew: it runs the same
16
+ yew you run in a terminal, with the Node.js found now. Run install again after
17
+ you move or update Node.js or Yew.
18
+
19
+ Commands:
20
+ install Create ~/Applications/Yew.app
21
+ uninstall Remove it; Yew itself and your data stay
22
+ status Show whether it is there
23
+
24
+ Options:
25
+ --json Print as JSON
26
+ -h, --help Show this help
27
+ `;
28
+ export function realAppHost() {
29
+ const here = (path) => fileURLToPath(new URL(path, import.meta.url));
30
+ const icon = ["../../web/dist/icons/app-icon.png", "../../web/public/icons/app-icon.png"]
31
+ .map(here)
32
+ .find((path) => existsSync(path));
33
+ return {
34
+ platform: process.platform,
35
+ homeDir: homedir(),
36
+ node: process.execPath,
37
+ entry: here(import.meta.url.endsWith(".ts") ? "./main.ts" : "./main.js"),
38
+ icon: icon ?? null,
39
+ run: (command, args) => spawnSync(command, args, { stdio: "ignore" }).status,
40
+ };
41
+ }
42
+ const xml = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
43
+ /** A value inside single quotes in a shell script. */
44
+ const quoted = (value) => `'${value.replace(/'/g, `'\\''`)}'`;
45
+ export function infoPlist() {
46
+ return `<?xml version="1.0" encoding="UTF-8"?>
47
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
48
+ <plist version="1.0">
49
+ <dict>
50
+ <key>CFBundleName</key>
51
+ <string>Yew</string>
52
+ <key>CFBundleDisplayName</key>
53
+ <string>Yew</string>
54
+ <key>CFBundleIdentifier</key>
55
+ <string>cn.tenonai.apps.yew.launcher</string>
56
+ <key>CFBundleExecutable</key>
57
+ <string>yew-launcher</string>
58
+ <key>CFBundleIconFile</key>
59
+ <string>AppIcon</string>
60
+ <key>CFBundlePackageType</key>
61
+ <string>APPL</string>
62
+ <key>CFBundleShortVersionString</key>
63
+ <string>${xml(VERSION)}</string>
64
+ <key>CFBundleVersion</key>
65
+ <string>${xml(VERSION)}</string>
66
+ <key>LSMinimumSystemVersion</key>
67
+ <string>12.0</string>
68
+ <key>NSHighResolutionCapable</key>
69
+ <true/>
70
+ </dict>
71
+ </plist>
72
+ `;
73
+ }
74
+ /**
75
+ * The launcher: open Yew's interface; when Yew is not running, start it in the background first
76
+ * and wait until it answers. Its log goes where the login service's does.
77
+ */
78
+ export function launcherScript(host, env, log) {
79
+ const yew = `${quoted(host.node)} ${quoted(host.entry)}`;
80
+ return `#!/bin/sh
81
+ # Yew's launcher, written by 'yew app install'. Run that again after moving Node.js or Yew.
82
+ ${Object.entries(env)
83
+ .map(([key, value]) => `export ${key}=${quoted(value)}`)
84
+ .join("\n")}
85
+ if ${yew} open >/dev/null 2>&1; then exit 0; fi
86
+ mkdir -p ${quoted(join(log, ".."))}
87
+ nohup ${yew} serve >> ${quoted(log)} 2>&1 &
88
+ tries=0
89
+ while [ "$tries" -lt 60 ]; do
90
+ sleep 0.25
91
+ if ${yew} open >/dev/null 2>&1; then exit 0; fi
92
+ tries=$((tries + 1))
93
+ done
94
+ osascript -e 'display alert "Yew did not start" message "Run yew serve in a terminal to see why."' >/dev/null 2>&1
95
+ exit 1
96
+ `;
97
+ }
98
+ const SIZES = [16, 32, 128, 256, 512];
99
+ /** Where the launcher goes: the person's own Applications folder. */
100
+ export const appPath = (host) => join(host.homeDir, "Applications", "Yew.app");
101
+ /**
102
+ * Jig's launcher, from before Jig was renamed Yew: taken away when Yew's is made or removed. Only when
103
+ * it is the one Jig made, by the executable it has.
104
+ */
105
+ function removeJigApp(host) {
106
+ const old = join(host.homeDir, "Applications", JIG_APP);
107
+ if (existsSync(join(old, "Contents", "MacOS", JIG_LAUNCHER))) {
108
+ rmSync(old, { recursive: true, force: true });
109
+ }
110
+ }
111
+ export const appInstalled = (host) => existsSync(join(appPath(host), "Contents", "MacOS", "yew-launcher"));
112
+ /** Makes Yew.app; returns whether its icon could be made (the app works without it). */
113
+ export function installApp(host, home, env) {
114
+ const app = appPath(host);
115
+ removeJigApp(host);
116
+ // Sessions' commands need your PATH; an app starts with a bare one.
117
+ const vars = { PATH: env.PATH ?? "/usr/bin:/bin" };
118
+ if (fromJigEnv(env, "HOME"))
119
+ vars.YEW_HOME = home;
120
+ rmSync(app, { recursive: true, force: true });
121
+ const contents = join(app, "Contents");
122
+ mkdirSync(join(contents, "MacOS"), { recursive: true });
123
+ mkdirSync(join(contents, "Resources"), { recursive: true });
124
+ writeFileSync(join(contents, "Info.plist"), infoPlist());
125
+ const launcher = join(contents, "MacOS", "yew-launcher");
126
+ writeFileSync(launcher, launcherScript(host, vars, join(home, "logs", "serve.log")));
127
+ chmodSync(launcher, 0o755);
128
+ // The icon: macOS's own tools make the sizes and the .icns. Without it the app still works.
129
+ let icon = false;
130
+ if (host.icon) {
131
+ const work = mkdtempSync(join(tmpdir(), "yew-icon-"));
132
+ const set = join(work, "AppIcon.iconset");
133
+ mkdirSync(set);
134
+ const made = SIZES.every((size) => [1, 2].every((factor) => host.run("sips", [
135
+ "-z",
136
+ String(size * factor),
137
+ String(size * factor),
138
+ host.icon,
139
+ "--out",
140
+ join(set, `icon_${size}x${size}${factor === 2 ? "@2x" : ""}.png`),
141
+ ]) === 0));
142
+ icon =
143
+ made &&
144
+ host.run("iconutil", [
145
+ "-c",
146
+ "icns",
147
+ set,
148
+ "-o",
149
+ join(contents, "Resources", "AppIcon.icns"),
150
+ ]) === 0;
151
+ rmSync(work, { recursive: true, force: true });
152
+ }
153
+ // Tells Finder and the Dock about the new app and its icon.
154
+ host.run("touch", [app]);
155
+ return { app, icon };
156
+ }
157
+ export function uninstallApp(host) {
158
+ rmSync(appPath(host), { recursive: true, force: true });
159
+ removeJigApp(host);
160
+ }
161
+ export function appCommand(host = realAppHost()) {
162
+ return {
163
+ name: "app",
164
+ summary: "Put a Yew icon in Applications (macOS)",
165
+ async run(args, io) {
166
+ const { values, positionals } = parseArgs({
167
+ args,
168
+ options: { json: { type: "boolean" }, help: { type: "boolean", short: "h" } },
169
+ allowPositionals: true,
170
+ strict: true,
171
+ });
172
+ if (values.help) {
173
+ io.stdout.write(HELP);
174
+ return EXIT_OK;
175
+ }
176
+ const action = positionals[0];
177
+ if (positionals.length !== 1 || !["install", "uninstall", "status"].includes(action ?? "")) {
178
+ throw new UsageError("yew app needs one of install, uninstall or status");
179
+ }
180
+ if (host.platform !== "darwin")
181
+ throw new Error("yew app works on macOS.");
182
+ const app = appPath(host);
183
+ const installed = appInstalled(host);
184
+ if (action === "status") {
185
+ if (values.json)
186
+ io.stdout.write(`${JSON.stringify({ installed, app })}\n`);
187
+ else
188
+ io.stdout.write(`Yew icon: ${installed ? app : "not installed"}\n`);
189
+ return EXIT_OK;
190
+ }
191
+ if (action === "uninstall") {
192
+ uninstallApp(host);
193
+ if (values.json)
194
+ io.stdout.write(`${JSON.stringify({ installed: false, app })}\n`);
195
+ else
196
+ io.stdout.write(installed ? `Removed ${app}.\n` : "The Yew icon was not installed.\n");
197
+ return EXIT_OK;
198
+ }
199
+ const { yewHome } = await import("../server/paths.js");
200
+ const { icon } = installApp(host, yewHome(io.env), io.env);
201
+ if (values.json)
202
+ io.stdout.write(`${JSON.stringify({ installed: true, app, icon })}\n`);
203
+ else {
204
+ io.stdout.write(`Yew is in your Applications folder: ${app}\nOpen it from Launchpad or Spotlight, or drag it to the Dock.\n`);
205
+ if (!icon)
206
+ io.stderr.write("yew: the icon could not be made; the app has a plain one.\n");
207
+ }
208
+ return icon || !host.icon ? EXIT_OK : EXIT_ERROR;
209
+ },
210
+ };
211
+ }
@@ -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
+ }
@@ -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
+ }
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env node
2
+ import { moveJigHome } from "../server/from-jig.js";
3
+ import { appCommand } from "./app.js";
4
+ import { exportCommand } from "./export.js";
5
+ import { keyCommand } from "./key.js";
6
+ import { mcpCommand } from "./mcp.js";
7
+ import { remoteCommand } from "./remote.js";
8
+ import { run } from "./run.js";
9
+ import { scheduleCommand } from "./schedule.js";
10
+ import { sendCommand } from "./send.js";
11
+ import { openCommand, serveCommand } from "./serve.js";
12
+ import { serviceCommand } from "./service.js";
13
+ const commands = [
14
+ serveCommand(),
15
+ openCommand(),
16
+ sendCommand(),
17
+ scheduleCommand(),
18
+ remoteCommand(),
19
+ serviceCommand(),
20
+ appCommand(),
21
+ exportCommand(),
22
+ mcpCommand(),
23
+ keyCommand(async () => {
24
+ const { openRuntime } = await import("../server/runtime.js");
25
+ const runtime = openRuntime();
26
+ const { SEARCH_SERVICES } = await import("../server/tools/web-search.js");
27
+ return {
28
+ keys: runtime.keys,
29
+ // Search services keep their keys the same way: yew key set search-bocha.
30
+ providers: [
31
+ ...runtime.gateway.providers(),
32
+ ...SEARCH_SERVICES.map((service) => ({
33
+ id: service.id,
34
+ name: service.name,
35
+ region: service.region,
36
+ baseUrl: service.origin,
37
+ keyRequired: true,
38
+ custom: false,
39
+ })),
40
+ ],
41
+ close: runtime.close,
42
+ };
43
+ }),
44
+ ];
45
+ // Jig is now Yew: its data folder moves the first time Yew runs (blueprint, section 12).
46
+ try {
47
+ const move = moveJigHome(process.env);
48
+ if (move && "moved" in move) {
49
+ process.stderr.write(`yew: Jig is now Yew. Moved its data folder ${move.moved} to ${move.to} and left a link in its place.\n`);
50
+ }
51
+ else if (move && "busy" in move) {
52
+ process.stderr.write(`yew: Jig is still running from ${move.folder} (process ${move.busy}). Stop it, then start Yew again to move its data; until then Yew uses ${move.folder}.\n`);
53
+ }
54
+ }
55
+ catch (error) {
56
+ process.stderr.write(`yew: could not move Jig's data folder: ${error.message}\n`);
57
+ }
58
+ process.exitCode = await run(process.argv.slice(2), { stdout: process.stdout, stderr: process.stderr, stdin: process.stdin, env: process.env }, commands);
@@ -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
+ }