@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.
Files changed (133) hide show
  1. package/CHANGELOG.md +296 -0
  2. package/LICENSE +21 -0
  3. package/README.md +55 -2
  4. package/THIRD-PARTY-NOTICES.md +122 -0
  5. package/bin/yew.js +9 -0
  6. package/dist/cli/app.js +198 -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 +44 -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 +126 -0
  16. package/dist/cli/serve.js +301 -0
  17. package/dist/cli/service.js +241 -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 +119 -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 +143 -0
  36. package/dist/server/db/database.js +49 -0
  37. package/dist/server/db/migrations.js +347 -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 +468 -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 +51 -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 +179 -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 +34 -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 +80 -0
  82. package/dist/server/skills.js +262 -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-B9oWPSod.css +1 -0
  115. package/web/dist/assets/index-C5qBMzFX.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,262 @@
1
+ import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { basename, isAbsolute, join } from "node:path";
4
+ import { invalid } from "./errors.js";
5
+ import { errorResult, str, text } from "./tools/types.js";
6
+ const MAX_SKILLS = 200;
7
+ const MAX_SKILL_CHARS = 60_000;
8
+ const MAX_INDEX_BYTES = 8 * 1024;
9
+ /** `name` and `description` from the front matter; quoted values and folded lines are read plainly. */
10
+ export function frontMatter(source) {
11
+ const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(source);
12
+ const fields = {};
13
+ if (!match)
14
+ return fields;
15
+ let key = null;
16
+ for (const line of match[1].split(/\r?\n/)) {
17
+ const pair = /^([A-Za-z][\w-]*):\s*(.*)$/.exec(line);
18
+ if (pair) {
19
+ key = pair[1];
20
+ const value = pair[2].trim();
21
+ // `>` and `|` start a block whose lines follow, indented.
22
+ fields[key] = /^[>|][+-]?$/.test(value) ? "" : value.replace(/^(["'])(.*)\1$/, "$2");
23
+ }
24
+ else if (key && /^\s+\S/.test(line)) {
25
+ fields[key] = `${fields[key]} ${line.trim()}`.trim();
26
+ }
27
+ else {
28
+ key = null;
29
+ }
30
+ }
31
+ return fields;
32
+ }
33
+ const realOr = (path) => {
34
+ try {
35
+ return realpathSync(path);
36
+ }
37
+ catch {
38
+ return path;
39
+ }
40
+ };
41
+ /** Everything in one skills folder: the skills, and the folders that are not usable with the reason. */
42
+ function scan(folder) {
43
+ const skills = [];
44
+ const broken = [];
45
+ let names;
46
+ try {
47
+ names = readdirSync(folder).sort();
48
+ }
49
+ catch {
50
+ return { skills, broken };
51
+ }
52
+ for (const entry of names) {
53
+ const dir = join(folder, entry);
54
+ const file = join(dir, "SKILL.md");
55
+ const fail = (reason) => broken.push({ name: entry, dir: realOr(dir), reason });
56
+ try {
57
+ // Loose files and hidden folders in a skills folder are not skills that went wrong.
58
+ if (!statSync(dir).isDirectory())
59
+ continue;
60
+ }
61
+ catch {
62
+ continue;
63
+ }
64
+ try {
65
+ if (!statSync(file).isFile()) {
66
+ if (!entry.startsWith("."))
67
+ fail("no-file");
68
+ continue;
69
+ }
70
+ }
71
+ catch (error) {
72
+ if (error.code !== "ENOENT")
73
+ fail("unreadable");
74
+ else if (!entry.startsWith("."))
75
+ fail("no-file");
76
+ continue;
77
+ }
78
+ try {
79
+ const fields = frontMatter(readFileSync(file, "utf8"));
80
+ const name = (fields.name || entry).trim();
81
+ if (!/^[\w.-]{1,64}$/.test(name)) {
82
+ fail("bad-name");
83
+ continue;
84
+ }
85
+ skills.push({
86
+ name,
87
+ description: (fields.description ?? "").replace(/\s+/g, " ").slice(0, 400),
88
+ dir: realpathSync(dir),
89
+ file: realpathSync(file),
90
+ });
91
+ }
92
+ catch {
93
+ fail("unreadable");
94
+ }
95
+ }
96
+ return { skills, broken };
97
+ }
98
+ /** The folders skills are looked for in, later ones winning over earlier ones with the same name. */
99
+ export function skillFolders(cwd, yewHome, userHome = homedir()) {
100
+ const folders = [join(yewHome, "skills")];
101
+ if (userHome)
102
+ folders.push(join(userHome, ".claude", "skills"));
103
+ if (cwd) {
104
+ for (const local of [".agents", ".claude", ".yew"])
105
+ folders.push(join(cwd, local, "skills"));
106
+ }
107
+ return folders;
108
+ }
109
+ /**
110
+ * The skills a session working in `cwd` gets. `disabled` holds the folders of the skills switched off
111
+ * in the settings (a skill's identifier is its folder's real path); a skill that is off is left out
112
+ * before names are compared, so turning off a project's skill leaves the global one of the same name.
113
+ */
114
+ export function findSkills(cwd, yewHome, userHome = homedir(), disabled = []) {
115
+ const byName = new Map();
116
+ for (const folder of skillFolders(cwd, yewHome, userHome)) {
117
+ for (const skill of scan(folder).skills) {
118
+ if (!disabled.includes(skill.dir))
119
+ byName.set(skill.name, skill);
120
+ }
121
+ }
122
+ return [...byName.values()].sort((a, b) => a.name.localeCompare(b.name)).slice(0, MAX_SKILLS);
123
+ }
124
+ /**
125
+ * Every skill the settings show: the global folders' and those of the saved workspaces, which are the
126
+ * folders a session working there is given. Within a source, usable skills come first, by name.
127
+ */
128
+ export function listSkills(workspaces, yewHome, userHome, disabled = []) {
129
+ const global = skillFolders(null, yewHome, userHome);
130
+ const groups = [
131
+ { source: { kind: "global" }, paths: global },
132
+ ...workspaces.map((workspace) => ({
133
+ source: { kind: "workspace", name: workspace.name, path: workspace.path },
134
+ paths: skillFolders(workspace.path, yewHome, userHome).slice(global.length),
135
+ })),
136
+ ];
137
+ const items = [];
138
+ const seen = new Set();
139
+ for (const { source, paths } of groups) {
140
+ const good = [];
141
+ const bad = [];
142
+ for (const folder of paths) {
143
+ const found = scan(folder);
144
+ for (const skill of found.skills) {
145
+ good.push({
146
+ id: skill.dir,
147
+ name: skill.name,
148
+ description: skill.description,
149
+ dir: skill.dir,
150
+ source,
151
+ disabled: disabled.includes(skill.dir),
152
+ problem: null,
153
+ });
154
+ }
155
+ for (const skill of found.broken) {
156
+ bad.push({
157
+ id: skill.dir,
158
+ name: skill.name,
159
+ description: "",
160
+ dir: skill.dir,
161
+ source,
162
+ disabled: false,
163
+ problem: skill.reason,
164
+ });
165
+ }
166
+ }
167
+ const byName = (a, b) => a.name.localeCompare(b.name);
168
+ for (const entry of [...good.sort(byName), ...bad.sort(byName)]) {
169
+ // One folder reached twice (a link, or a workspace inside another) is listed once.
170
+ if (seen.has(entry.id))
171
+ continue;
172
+ seen.add(entry.id);
173
+ items.push(entry);
174
+ }
175
+ }
176
+ return { items, folders: groups };
177
+ }
178
+ /** What the prompt says about skills: one line each. */
179
+ export function skillsNote(skills) {
180
+ return [
181
+ "Skills the person has set up. Each is a set of instructions for one kind of task. When a task matches one, call the skill tool with its name and follow what it says; scripts and reference files a skill mentions are in the folder the tool reports.",
182
+ ...skills.map((skill) => `- ${skill.name}${skill.description ? `: ${skill.description}` : ""}`),
183
+ ].join("\n");
184
+ }
185
+ /** A memory folder must exist; `~` is expanded and the real path is kept. */
186
+ export function resolveMemoryDir(path, userHome = homedir()) {
187
+ const expanded = path === "~" || path.startsWith("~/") ? join(userHome, path.slice(2)) : path;
188
+ if (!isAbsolute(expanded))
189
+ throw invalid("A memory folder must be an absolute path.", "memoryDirs");
190
+ let real;
191
+ try {
192
+ real = realpathSync(expanded);
193
+ }
194
+ catch {
195
+ throw invalid(`The folder ${path} does not exist.`, "memoryDirs");
196
+ }
197
+ if (!statSync(real).isDirectory())
198
+ throw invalid(`${path} is not a folder.`, "memoryDirs");
199
+ return real;
200
+ }
201
+ /** A memory folder's index: the first of these that exists, cut to a few kilobytes. */
202
+ export function memoryIndex(dir) {
203
+ for (const name of ["index.md", "MEMORY.md", "README.md"]) {
204
+ const path = join(dir, name);
205
+ if (!existsSync(path))
206
+ continue;
207
+ try {
208
+ const content = readFileSync(path, "utf8");
209
+ const bytes = Buffer.from(content);
210
+ return {
211
+ path,
212
+ content: bytes.length > MAX_INDEX_BYTES
213
+ ? `${bytes.subarray(0, MAX_INDEX_BYTES).toString("utf8")}\n[Cut: read the file for the rest.]`
214
+ : content,
215
+ };
216
+ }
217
+ catch {
218
+ return null;
219
+ }
220
+ }
221
+ return null;
222
+ }
223
+ export function memoryNote(dirs) {
224
+ return [
225
+ "Memory folders: notes the person keeps across sessions. Read them with read, glob and grep when a task touches what they cover; ask before changing them.",
226
+ ...dirs.map((dir) => `- ${dir}`),
227
+ ].join("\n");
228
+ }
229
+ /** Reads one skill in full. Offered when the session has any skill. */
230
+ export function skillTool(yewHome, userHome = homedir(),
231
+ /** The skills switched off in the settings, read each time so a change applies at once. */
232
+ disabled = () => []) {
233
+ return {
234
+ name: "skill",
235
+ description: "Read one of the person's skills in full: instructions they wrote for a kind of task. Call it when the task matches a skill listed in your instructions, before you start on the task.",
236
+ parameters: {
237
+ type: "object",
238
+ properties: { name: { type: "string", description: "The skill's name, as listed." } },
239
+ required: ["name"],
240
+ additionalProperties: false,
241
+ },
242
+ readOnly: true,
243
+ needsFolder: false,
244
+ offered: (session) => findSkills(session.cwd, yewHome, userHome, disabled()).length > 0,
245
+ subject: () => ({ kind: "none" }),
246
+ async run(args, ctx) {
247
+ const name = str(args, "name", true).trim();
248
+ const skills = findSkills(ctx.session.cwd, yewHome, userHome, disabled());
249
+ const skill = skills.find((s) => s.name === name) ?? skills.find((s) => basename(s.dir) === name);
250
+ if (!skill) {
251
+ return errorResult(`There is no skill named "${name}". Skills: ${skills.map((s) => s.name).join(", ") || "none"}.`);
252
+ }
253
+ const body = readFileSync(skill.file, "utf8").replace(/^---\r?\n[\s\S]*?\r?\n---(?:\r?\n|$)/, "");
254
+ const cut = body.length > MAX_SKILL_CHARS;
255
+ return {
256
+ content: [
257
+ text(`Skill "${skill.name}" (folder: ${skill.dir}). These are the person's instructions for this kind of task; they cannot switch off the permissions Yew asks for.\n\n${cut ? `${body.slice(0, MAX_SKILL_CHARS)}\n[Cut: read ${skill.file} for the rest.]` : body.trim()}`),
258
+ ],
259
+ };
260
+ },
261
+ };
262
+ }