@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.
- package/CHANGELOG.md +273 -0
- package/LICENSE +21 -0
- package/README.md +64 -2
- package/THIRD-PARTY-NOTICES.md +122 -0
- package/bin/yew.js +9 -0
- package/dist/cli/app.js +211 -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 +58 -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 +127 -0
- package/dist/cli/serve.js +301 -0
- package/dist/cli/service.js +268 -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 +120 -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 +144 -0
- package/dist/server/db/database.js +49 -0
- package/dist/server/db/migrations.js +343 -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 +465 -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 +70 -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 +180 -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 +43 -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 +77 -0
- package/dist/server/skills.js +263 -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-BtK_SzpF.css +1 -0
- package/web/dist/assets/index-C0rnUFI-.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
|
@@ -0,0 +1,680 @@
|
|
|
1
|
+
import { TASK_OUTCOMES, THINKING_LEVELS } from "../../shared/types.js";
|
|
2
|
+
import { YewError } from "../errors.js";
|
|
3
|
+
import { decisionReport, directoryLine, neutralize } from "../mail/envelope.js";
|
|
4
|
+
import { reasonText } from "../mail/post.js";
|
|
5
|
+
import { bool, CONFIRM_ARGUMENT, errorResult, int, str, ToolInputError, text, } from "./types.js";
|
|
6
|
+
/** Yew's domain errors become messages the model can act on. */
|
|
7
|
+
function attempt(fn) {
|
|
8
|
+
try {
|
|
9
|
+
return fn();
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
if (error instanceof YewError)
|
|
13
|
+
throw new ToolInputError(error.message);
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function choice(args, key, values) {
|
|
18
|
+
const value = args[key];
|
|
19
|
+
if (value === undefined || value === null)
|
|
20
|
+
return undefined;
|
|
21
|
+
if (typeof value !== "string" || !values.includes(value)) {
|
|
22
|
+
throw new ToolInputError(`${key} must be one of: ${values.join(", ")}.`);
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
function nameOf(mail, id) {
|
|
27
|
+
return mail.post.sessionName(id) ?? id;
|
|
28
|
+
}
|
|
29
|
+
/** What a waiting call returns. The other session's words cannot pass for Yew's own tags. */
|
|
30
|
+
function waitText(name, result) {
|
|
31
|
+
switch (result.kind) {
|
|
32
|
+
case "letter": {
|
|
33
|
+
const letter = result.letter;
|
|
34
|
+
const words = neutralize(`${letter.summary}${letter.body ? `\n\n${letter.body}` : ""}`);
|
|
35
|
+
return {
|
|
36
|
+
content: [text(`${name} wrote back (letter ${letter.id}, ${letter.kind}):\n${words}`)],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
case "ended": {
|
|
40
|
+
const said = neutralize(result.text.trim());
|
|
41
|
+
if (result.stopped) {
|
|
42
|
+
return errorResult(`The person stopped ${name} before it finished.${said ? ` Its last reply:\n${said}` : ""} When it goes on, its reply comes to you as a letter.`);
|
|
43
|
+
}
|
|
44
|
+
if (result.status === "error") {
|
|
45
|
+
return errorResult(`${name} stopped with an error: ${result.detail ?? "unknown error"}\nWhen it goes on, its reply comes to you as a letter.`);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
content: [
|
|
49
|
+
text(`${name} finished its turn. Its last reply:\n${said || "(no written reply)"}`),
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
case "timeout":
|
|
54
|
+
return {
|
|
55
|
+
content: [
|
|
56
|
+
text(`${name} is still working after 30 minutes. Its reply will come to you as a letter.`),
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
case "cycle":
|
|
60
|
+
return {
|
|
61
|
+
content: [
|
|
62
|
+
text(`Not waiting: ${name} is already waiting for you, directly or through other sessions. The letter was sent; its reply will come to you as a letter.`),
|
|
63
|
+
],
|
|
64
|
+
};
|
|
65
|
+
case "not-running":
|
|
66
|
+
return {
|
|
67
|
+
content: [
|
|
68
|
+
text(`${name} is not running (${result.status}); the letter waits until the person continues it. Its reply will come to you as a letter.`),
|
|
69
|
+
],
|
|
70
|
+
};
|
|
71
|
+
case "stopped":
|
|
72
|
+
return errorResult(`Stopped while waiting for ${name}.`);
|
|
73
|
+
case "archived":
|
|
74
|
+
return errorResult(`${name} was archived before it read the letter; it will not answer.`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** What happened to a letter, for the sender. Undelivered letters are errors so the model notices. */
|
|
78
|
+
function sentText(mail, letter) {
|
|
79
|
+
const name = nameOf(mail, letter.toSession);
|
|
80
|
+
if (letter.status === "refused" || letter.status === "dropped") {
|
|
81
|
+
return errorResult(`Not sent to ${name}: ${reasonText(letter.statusReason)}.`);
|
|
82
|
+
}
|
|
83
|
+
if (letter.status === "held") {
|
|
84
|
+
return {
|
|
85
|
+
content: [
|
|
86
|
+
text(`Letter ${letter.id} to ${name} is held: ${reasonText(letter.statusReason)}. The person can release it in the approval center; do not send it again.`),
|
|
87
|
+
],
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
function letterDetail(mail, letter) {
|
|
93
|
+
return {
|
|
94
|
+
letterId: letter.id,
|
|
95
|
+
to: letter.toSession,
|
|
96
|
+
toName: nameOf(mail, letter.toSession),
|
|
97
|
+
kind: letter.kind,
|
|
98
|
+
status: letter.status,
|
|
99
|
+
...(letter.statusReason ? { reason: letter.statusReason } : {}),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export const listSessionsTool = {
|
|
103
|
+
name: "list_sessions",
|
|
104
|
+
description: "List the sessions (id, name, kind, status, team, model, permission mode and the first line of each role), the teams and Yew's settings.",
|
|
105
|
+
parameters: { type: "object", properties: {}, additionalProperties: false },
|
|
106
|
+
readOnly: true,
|
|
107
|
+
needsFolder: false,
|
|
108
|
+
subject() {
|
|
109
|
+
return { kind: "none" };
|
|
110
|
+
},
|
|
111
|
+
async run(_args, ctx) {
|
|
112
|
+
const post = ctx.mail.post;
|
|
113
|
+
const { sessions, groups } = post.directory();
|
|
114
|
+
const main = post.mainSessionId();
|
|
115
|
+
const lines = sessions.map((session) => directoryLine(session, {
|
|
116
|
+
you: session.id === ctx.session.id,
|
|
117
|
+
main: session.id === main,
|
|
118
|
+
parentName: session.parentId ? nameOf(ctx.mail, session.parentId) : null,
|
|
119
|
+
group: session.groupId ? (groups.get(session.groupId) ?? null) : null,
|
|
120
|
+
}));
|
|
121
|
+
const teams = [...groups].map(([id, name]) => `- ${id} · ${name}`);
|
|
122
|
+
const settings = post.settings();
|
|
123
|
+
const workspaces = settings.workspaces.map((workspace) => workspace.path).join(", ");
|
|
124
|
+
const yew = [
|
|
125
|
+
`- default model: ${settings.defaultModel.provider}/${settings.defaultModel.model} (${settings.defaultModel.thinking})`,
|
|
126
|
+
`- decision log: ${settings.decisionLog ?? "none"}`,
|
|
127
|
+
`- daily budget for all sessions: ${settings.dailyBudget ? `$${settings.dailyBudget}` : "none"}`,
|
|
128
|
+
`- workspaces: ${workspaces || "none"}`,
|
|
129
|
+
`- theme: ${settings.theme}; language: ${settings.language}`,
|
|
130
|
+
];
|
|
131
|
+
return {
|
|
132
|
+
content: [
|
|
133
|
+
text(`Sessions (id · name · kind · status · …):\n${lines.join("\n")}\n\nTeams (id · name):\n${teams.length > 0 ? teams.join("\n") : "(none)"}\n\nSettings:\n${yew.join("\n")}`),
|
|
134
|
+
],
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
export const sendLetterTool = {
|
|
139
|
+
name: "send_letter",
|
|
140
|
+
description: "Send a letter to another session. A notice is for information; a request asks the recipient to do or answer something, and its final reply comes back to you as a letter; a report gives the result of something you were asked. With wait, this call waits until the recipient replies to this letter or finishes its turn (at most 30 minutes) and returns its answer. Do not write only to acknowledge or thank.",
|
|
141
|
+
parameters: {
|
|
142
|
+
type: "object",
|
|
143
|
+
properties: {
|
|
144
|
+
to: { type: "string", description: "The recipient, by name or id." },
|
|
145
|
+
kind: { type: "string", enum: ["notice", "request", "report"] },
|
|
146
|
+
summary: { type: "string", description: "One line that makes sense on its own." },
|
|
147
|
+
body: {
|
|
148
|
+
type: "string",
|
|
149
|
+
description: "Details, if any. Plain text; refer to files by their path.",
|
|
150
|
+
},
|
|
151
|
+
reply_to: {
|
|
152
|
+
type: "string",
|
|
153
|
+
description: "The letter this answers. A report to a session whose request you have open is linked to it without this.",
|
|
154
|
+
},
|
|
155
|
+
wait: {
|
|
156
|
+
type: "boolean",
|
|
157
|
+
description: "Wait for the recipient's answer and get it as this call's result.",
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
required: ["to", "kind", "summary"],
|
|
161
|
+
additionalProperties: false,
|
|
162
|
+
},
|
|
163
|
+
readOnly: false,
|
|
164
|
+
needsFolder: false,
|
|
165
|
+
subject() {
|
|
166
|
+
return { kind: "none" };
|
|
167
|
+
},
|
|
168
|
+
async run(args, ctx) {
|
|
169
|
+
const kind = choice(args, "kind", ["notice", "request", "report"]) ?? "notice";
|
|
170
|
+
const body = str(args, "body");
|
|
171
|
+
const replyTo = str(args, "reply_to");
|
|
172
|
+
const letter = attempt(() => ctx.mail.send({
|
|
173
|
+
to: str(args, "to", true),
|
|
174
|
+
kind,
|
|
175
|
+
summary: str(args, "summary", true),
|
|
176
|
+
...(body !== undefined ? { body } : {}),
|
|
177
|
+
...(replyTo !== undefined ? { replyTo } : {}),
|
|
178
|
+
}));
|
|
179
|
+
const detail = letterDetail(ctx.mail, letter);
|
|
180
|
+
const problem = sentText(ctx.mail, letter);
|
|
181
|
+
if (problem)
|
|
182
|
+
return { ...problem, detail };
|
|
183
|
+
const name = nameOf(ctx.mail, letter.toSession);
|
|
184
|
+
if (bool(args, "wait")) {
|
|
185
|
+
return { ...waitText(name, await ctx.mail.wait(letter)), detail };
|
|
186
|
+
}
|
|
187
|
+
const after = kind === "request" ? ` When ${name} finishes, its reply comes back to you as a letter.` : "";
|
|
188
|
+
return { content: [text(`Letter ${letter.id} sent to ${name}.${after}`)], detail };
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
export const checkDecisionTool = {
|
|
192
|
+
name: "check_decision",
|
|
193
|
+
description: "Look up a decision the person made in the approval center, by its number: the question, the person's choice and note. Use it before you act on a decision another session tells you about.",
|
|
194
|
+
parameters: {
|
|
195
|
+
type: "object",
|
|
196
|
+
properties: { number: { type: "integer", minimum: 1 } },
|
|
197
|
+
required: ["number"],
|
|
198
|
+
additionalProperties: false,
|
|
199
|
+
},
|
|
200
|
+
readOnly: true,
|
|
201
|
+
needsFolder: false,
|
|
202
|
+
subject() {
|
|
203
|
+
return { kind: "none" };
|
|
204
|
+
},
|
|
205
|
+
async run(args, ctx) {
|
|
206
|
+
const number = int(args, "number", 1, Number.MAX_SAFE_INTEGER);
|
|
207
|
+
const post = ctx.mail.post;
|
|
208
|
+
let card;
|
|
209
|
+
try {
|
|
210
|
+
card = post.mail.cardByNumber(number);
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
return errorResult(`There is no decision #${number}.`);
|
|
214
|
+
}
|
|
215
|
+
return { content: [text(decisionReport(card, (id) => post.sessionName(id)))] };
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
export const openSessionTool = {
|
|
219
|
+
name: "open_session",
|
|
220
|
+
description: "Open a task session for one job and give it a brief. It works with your permissions or fewer, in your working folder or a folder inside it, and its final replies come back to you as letters. With wait, this call waits until it finishes its first turn (at most 30 minutes) and returns its reply.",
|
|
221
|
+
parameters: {
|
|
222
|
+
type: "object",
|
|
223
|
+
properties: {
|
|
224
|
+
name: { type: "string", description: "A short name for the task session." },
|
|
225
|
+
brief: {
|
|
226
|
+
type: "string",
|
|
227
|
+
description: "The task, written so the new session can work from it alone: the goal, what it needs to know, limits, and what to report.",
|
|
228
|
+
},
|
|
229
|
+
folder: {
|
|
230
|
+
type: "string",
|
|
231
|
+
description: 'Its working folder: yours (the default), a folder inside yours, or "none" for a chat without files.',
|
|
232
|
+
},
|
|
233
|
+
model: { type: "string", description: '"provider/model" to use instead of yours.' },
|
|
234
|
+
wait: { type: "boolean", description: "Wait for its first reply." },
|
|
235
|
+
fork: {
|
|
236
|
+
type: "boolean",
|
|
237
|
+
description: "Give it a copy of this conversation so far, so it knows what you know and the brief can be short. Its first request carries all of that.",
|
|
238
|
+
},
|
|
239
|
+
confirm: CONFIRM_ARGUMENT,
|
|
240
|
+
},
|
|
241
|
+
required: ["name", "brief"],
|
|
242
|
+
additionalProperties: false,
|
|
243
|
+
},
|
|
244
|
+
readOnly: false,
|
|
245
|
+
needsFolder: false,
|
|
246
|
+
subject(args) {
|
|
247
|
+
return { kind: "act", tool: "open_session", summary: str(args, "name", true) };
|
|
248
|
+
},
|
|
249
|
+
preview(args) {
|
|
250
|
+
const brief = typeof args.brief === "string" ? args.brief.trim() : "";
|
|
251
|
+
return brief ? { description: brief.length > 600 ? `${brief.slice(0, 600)}…` : brief } : {};
|
|
252
|
+
},
|
|
253
|
+
async run(args, ctx) {
|
|
254
|
+
const folder = str(args, "folder");
|
|
255
|
+
const model = str(args, "model");
|
|
256
|
+
let provider;
|
|
257
|
+
let modelId;
|
|
258
|
+
if (model) {
|
|
259
|
+
const slash = model.indexOf("/");
|
|
260
|
+
if (slash <= 0 || slash === model.length - 1) {
|
|
261
|
+
throw new ToolInputError('model must look like "provider/model".');
|
|
262
|
+
}
|
|
263
|
+
provider = model.slice(0, slash);
|
|
264
|
+
modelId = model.slice(slash + 1);
|
|
265
|
+
}
|
|
266
|
+
const opened = attempt(() => ctx.mail.open({
|
|
267
|
+
name: str(args, "name", true),
|
|
268
|
+
brief: str(args, "brief", true),
|
|
269
|
+
...(folder === undefined ? {} : { cwd: folder === "none" ? null : folder }),
|
|
270
|
+
...(provider && modelId ? { provider, model: modelId } : {}),
|
|
271
|
+
...(bool(args, "fork") ? { fork: true } : {}),
|
|
272
|
+
}));
|
|
273
|
+
const detail = {
|
|
274
|
+
sessionId: opened.session.id,
|
|
275
|
+
name: opened.session.name,
|
|
276
|
+
letterId: opened.letter.id,
|
|
277
|
+
};
|
|
278
|
+
const problem = sentText(ctx.mail, opened.letter);
|
|
279
|
+
if (problem)
|
|
280
|
+
return { ...problem, detail };
|
|
281
|
+
if (bool(args, "wait")) {
|
|
282
|
+
return { ...waitText(opened.session.name, await ctx.mail.wait(opened.letter)), detail };
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
content: [
|
|
286
|
+
text(`Opened the task session "${opened.session.name}" (id ${opened.session.id})${bool(args, "fork") ? " with a copy of this conversation so far" : ""}. It starts on the brief now; its report comes back to you as a letter.`),
|
|
287
|
+
],
|
|
288
|
+
detail,
|
|
289
|
+
};
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
const TEXT = { type: "string" };
|
|
293
|
+
/**
|
|
294
|
+
* manage_yew: the model changes Yew itself (blueprint 6.2, item 10). One call, all changes; Yew plans it
|
|
295
|
+
* to rank how far it reaches and to show the person every change, then applies all or none.
|
|
296
|
+
*/
|
|
297
|
+
export const manageJigTool = {
|
|
298
|
+
name: "manage_yew",
|
|
299
|
+
description: "Change Yew itself when the person asks or the work needs it: sessions (create a standing one, or change its name, team, role, model, working folder, permission mode, how it receives letters, letter quota, rights, pinned, archived), teams, scheduled tasks, and settings. Put every change in one call; Yew checks them, asks the person when a change needs it, and applies all or none. Sessions, teams and tasks are named by name or id. API keys, pairing and deleting data are the person's.",
|
|
300
|
+
parameters: {
|
|
301
|
+
type: "object",
|
|
302
|
+
properties: {
|
|
303
|
+
teams: {
|
|
304
|
+
type: "array",
|
|
305
|
+
description: "Teams to create (name only) or rename (team and name).",
|
|
306
|
+
items: {
|
|
307
|
+
type: "object",
|
|
308
|
+
properties: { team: TEXT, name: TEXT },
|
|
309
|
+
required: ["name"],
|
|
310
|
+
additionalProperties: false,
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
sessions: {
|
|
314
|
+
type: "array",
|
|
315
|
+
description: "One entry per session with only what changes. Leave out session to create a standing session with that name.",
|
|
316
|
+
items: {
|
|
317
|
+
type: "object",
|
|
318
|
+
properties: {
|
|
319
|
+
session: TEXT,
|
|
320
|
+
name: TEXT,
|
|
321
|
+
team: { type: "string", description: 'A team, or "none".' },
|
|
322
|
+
role: TEXT,
|
|
323
|
+
model: { type: "string", description: '"provider/model".' },
|
|
324
|
+
thinking: { type: "string", enum: [...THINKING_LEVELS] },
|
|
325
|
+
folder: { type: "string", description: 'Its working folder, or "none" for a chat.' },
|
|
326
|
+
permission: {
|
|
327
|
+
type: "string",
|
|
328
|
+
enum: ["auto", "manual", "skip"],
|
|
329
|
+
description: "auto: asks when needed; manual: asks each time; skip: full access.",
|
|
330
|
+
},
|
|
331
|
+
receive: { type: "string", enum: ["accept", "hold", "refuse"] },
|
|
332
|
+
letter_quota: {
|
|
333
|
+
type: "integer",
|
|
334
|
+
minimum: 0,
|
|
335
|
+
maximum: 100,
|
|
336
|
+
description: "Letters it may send between the person's messages; 0 for the default.",
|
|
337
|
+
},
|
|
338
|
+
daily_budget: {
|
|
339
|
+
type: "number",
|
|
340
|
+
minimum: 0,
|
|
341
|
+
description: "The most it may spend in a day, in US dollars; 0 for no limit.",
|
|
342
|
+
},
|
|
343
|
+
can_post_cards: { type: "boolean" },
|
|
344
|
+
can_manage: { type: "boolean", description: "May use manage_yew." },
|
|
345
|
+
pinned: { type: "boolean" },
|
|
346
|
+
archived: { type: "boolean" },
|
|
347
|
+
},
|
|
348
|
+
additionalProperties: false,
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
schedules: {
|
|
352
|
+
type: "array",
|
|
353
|
+
description: "Scheduled tasks: at the times of a cron expression, Yew sends a standing session a letter, and its last reply comes back to the main conversation as the report. Leave out schedule to create one; set enabled to false to turn one off.",
|
|
354
|
+
items: {
|
|
355
|
+
type: "object",
|
|
356
|
+
properties: {
|
|
357
|
+
schedule: TEXT,
|
|
358
|
+
name: TEXT,
|
|
359
|
+
cron: {
|
|
360
|
+
type: "string",
|
|
361
|
+
description: 'Five fields in this computer\'s time zone: minute, hour, day of the month, month, day of the week. "0 9 * * 1-5" is 9:00 on weekdays.',
|
|
362
|
+
},
|
|
363
|
+
session: { type: "string", description: "The standing session the letter goes to." },
|
|
364
|
+
message: { type: "string", description: "The letter: what to do each time." },
|
|
365
|
+
permission: {
|
|
366
|
+
type: "string",
|
|
367
|
+
enum: ["session", "auto", "manual", "skip"],
|
|
368
|
+
description: "Permission mode for its runs; session (the default) keeps the session's own.",
|
|
369
|
+
},
|
|
370
|
+
catch_up: {
|
|
371
|
+
type: "boolean",
|
|
372
|
+
description: "Run once after a time missed while Yew was not running (default true).",
|
|
373
|
+
},
|
|
374
|
+
enabled: { type: "boolean" },
|
|
375
|
+
},
|
|
376
|
+
additionalProperties: false,
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
settings: {
|
|
380
|
+
type: "object",
|
|
381
|
+
properties: {
|
|
382
|
+
main: { type: "string", description: "The main conversation." },
|
|
383
|
+
default_model: { type: "string", description: '"provider/model" for new sessions.' },
|
|
384
|
+
default_thinking: { type: "string", enum: [...THINKING_LEVELS] },
|
|
385
|
+
decision_log: {
|
|
386
|
+
type: "string",
|
|
387
|
+
description: 'A Markdown file every decision is added to, or "none".',
|
|
388
|
+
},
|
|
389
|
+
daily_budget: {
|
|
390
|
+
type: "number",
|
|
391
|
+
minimum: 0,
|
|
392
|
+
description: "The most all sessions may spend in a day, in US dollars; 0 for no limit.",
|
|
393
|
+
},
|
|
394
|
+
add_workspace: { type: "string", description: "A folder to add to the workspaces." },
|
|
395
|
+
remove_workspace: { type: "string", description: "A workspace, by folder or name." },
|
|
396
|
+
theme: { type: "string", enum: ["system", "light", "dark"] },
|
|
397
|
+
language: { type: "string", enum: ["system", "zh", "en"] },
|
|
398
|
+
},
|
|
399
|
+
additionalProperties: false,
|
|
400
|
+
},
|
|
401
|
+
},
|
|
402
|
+
additionalProperties: false,
|
|
403
|
+
},
|
|
404
|
+
readOnly: false,
|
|
405
|
+
needsFolder: false,
|
|
406
|
+
offered: (_session, roles) => roles.canOrganize,
|
|
407
|
+
subject(args, _session, lookup) {
|
|
408
|
+
if (!lookup)
|
|
409
|
+
return { kind: "act", tool: "manage_yew", summary: "manage_yew", always: true };
|
|
410
|
+
let plan;
|
|
411
|
+
try {
|
|
412
|
+
plan = lookup.plan(args);
|
|
413
|
+
}
|
|
414
|
+
catch (error) {
|
|
415
|
+
if (error instanceof YewError)
|
|
416
|
+
throw new ToolInputError(error.message);
|
|
417
|
+
throw error;
|
|
418
|
+
}
|
|
419
|
+
return {
|
|
420
|
+
kind: "act",
|
|
421
|
+
tool: "manage_yew",
|
|
422
|
+
summary: plan.summary.join("\n"),
|
|
423
|
+
scope: plan.tier === "widen" ? undefined : plan.tier,
|
|
424
|
+
always: plan.tier !== "organize",
|
|
425
|
+
...(plan.tier === "widen" ? { reasons: plan.reasons } : {}),
|
|
426
|
+
};
|
|
427
|
+
},
|
|
428
|
+
preview(args, _session, lookup) {
|
|
429
|
+
try {
|
|
430
|
+
return { changes: lookup.plan(args).steps };
|
|
431
|
+
}
|
|
432
|
+
catch {
|
|
433
|
+
return {};
|
|
434
|
+
}
|
|
435
|
+
},
|
|
436
|
+
async run(args, ctx) {
|
|
437
|
+
const done = attempt(() => ctx.mail.manage(args));
|
|
438
|
+
return { content: [text(done.join("\n"))] };
|
|
439
|
+
},
|
|
440
|
+
};
|
|
441
|
+
export const finishTaskTool = {
|
|
442
|
+
name: "finish_task",
|
|
443
|
+
description: "Record how your task ended: done, given_up or failed. Then end your turn with your report: the result, what changed, how you checked it, and what is left.",
|
|
444
|
+
parameters: {
|
|
445
|
+
type: "object",
|
|
446
|
+
properties: { result: { type: "string", enum: [...TASK_OUTCOMES] } },
|
|
447
|
+
required: ["result"],
|
|
448
|
+
additionalProperties: false,
|
|
449
|
+
},
|
|
450
|
+
readOnly: false,
|
|
451
|
+
needsFolder: false,
|
|
452
|
+
offered: (session) => session.kind === "task",
|
|
453
|
+
subject() {
|
|
454
|
+
return { kind: "none" };
|
|
455
|
+
},
|
|
456
|
+
async run(args, ctx) {
|
|
457
|
+
const outcome = choice(args, "result", TASK_OUTCOMES);
|
|
458
|
+
if (!outcome)
|
|
459
|
+
throw new ToolInputError("result is required.");
|
|
460
|
+
const session = ctx.mail.finish(outcome);
|
|
461
|
+
const to = session.parentId
|
|
462
|
+
? `It goes to ${nameOf(ctx.mail, session.parentId)}.`
|
|
463
|
+
: "The person reads it here.";
|
|
464
|
+
return { content: [text(`Recorded: ${outcome}. Now end your turn with your report. ${to}`)] };
|
|
465
|
+
},
|
|
466
|
+
};
|
|
467
|
+
const CARD_PROPERTIES = {
|
|
468
|
+
title: { type: "string", description: "The question to decide, short enough for one line." },
|
|
469
|
+
context: {
|
|
470
|
+
type: "string",
|
|
471
|
+
description: "What the person needs to know to decide, in two or three short sentences.",
|
|
472
|
+
},
|
|
473
|
+
options: {
|
|
474
|
+
type: "array",
|
|
475
|
+
maxItems: 6,
|
|
476
|
+
description: "The choices; the person can also answer with a note.",
|
|
477
|
+
items: {
|
|
478
|
+
type: "object",
|
|
479
|
+
properties: {
|
|
480
|
+
label: { type: "string", description: "A few words, such as the action to take." },
|
|
481
|
+
detail: {
|
|
482
|
+
type: "string",
|
|
483
|
+
description: "What happens if the person picks it, in a short sentence. Leave it out when the label says it.",
|
|
484
|
+
},
|
|
485
|
+
},
|
|
486
|
+
required: ["label"],
|
|
487
|
+
additionalProperties: false,
|
|
488
|
+
},
|
|
489
|
+
},
|
|
490
|
+
recommended: {
|
|
491
|
+
type: "integer",
|
|
492
|
+
minimum: 1,
|
|
493
|
+
description: "The option you recommend, counting from 1.",
|
|
494
|
+
},
|
|
495
|
+
deadline: {
|
|
496
|
+
type: "string",
|
|
497
|
+
description: 'When it must be decided, in a few words, such as "2026-11-12" or "before the release".',
|
|
498
|
+
},
|
|
499
|
+
sessions: {
|
|
500
|
+
type: "array",
|
|
501
|
+
items: { type: "string" },
|
|
502
|
+
description: "Ids of other sessions involved, besides the one that asked and you.",
|
|
503
|
+
},
|
|
504
|
+
undoable: {
|
|
505
|
+
type: "boolean",
|
|
506
|
+
description: "Whether the decision can be undone after it is carried out.",
|
|
507
|
+
},
|
|
508
|
+
reversible: {
|
|
509
|
+
type: "string",
|
|
510
|
+
description: "How to undo it, or what cannot be undone, in a few words. Leave it out when that is obvious.",
|
|
511
|
+
},
|
|
512
|
+
after: {
|
|
513
|
+
type: "string",
|
|
514
|
+
description: "Who does what once it is decided, when the options do not say it. Leave it out when the decision only goes back to the session that asked.",
|
|
515
|
+
},
|
|
516
|
+
};
|
|
517
|
+
function cardInput(args) {
|
|
518
|
+
const input = {};
|
|
519
|
+
for (const key of ["title", "context", "deadline", "reversible", "after"]) {
|
|
520
|
+
const value = args[key];
|
|
521
|
+
if (value !== undefined) {
|
|
522
|
+
if (typeof value !== "string")
|
|
523
|
+
throw new ToolInputError(`${key} must be text.`);
|
|
524
|
+
input[key] = value;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
if (args.options !== undefined) {
|
|
528
|
+
if (!Array.isArray(args.options))
|
|
529
|
+
throw new ToolInputError("options must be a list.");
|
|
530
|
+
input.options = args.options.map((option) => {
|
|
531
|
+
if (!option || typeof option !== "object")
|
|
532
|
+
throw new ToolInputError("Each option needs a label.");
|
|
533
|
+
const { label, detail } = option;
|
|
534
|
+
if (typeof label !== "string")
|
|
535
|
+
throw new ToolInputError("Each option needs a label.");
|
|
536
|
+
return (typeof detail === "string" && detail ? { label, detail } : { label });
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
if (args.recommended !== undefined) {
|
|
540
|
+
const value = args.recommended;
|
|
541
|
+
if (value === null)
|
|
542
|
+
input.recommended = null;
|
|
543
|
+
else if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
|
|
544
|
+
throw new ToolInputError("recommended must count from 1.");
|
|
545
|
+
}
|
|
546
|
+
else
|
|
547
|
+
input.recommended = value - 1;
|
|
548
|
+
}
|
|
549
|
+
if (args.undoable !== undefined) {
|
|
550
|
+
if (typeof args.undoable !== "boolean")
|
|
551
|
+
throw new ToolInputError("undoable must be true or false.");
|
|
552
|
+
input.undoable = args.undoable;
|
|
553
|
+
}
|
|
554
|
+
if (args.sessions !== undefined) {
|
|
555
|
+
if (!Array.isArray(args.sessions) || args.sessions.some((id) => typeof id !== "string")) {
|
|
556
|
+
throw new ToolInputError("sessions must be a list of session ids.");
|
|
557
|
+
}
|
|
558
|
+
input.sessions = args.sessions;
|
|
559
|
+
}
|
|
560
|
+
return input;
|
|
561
|
+
}
|
|
562
|
+
const maintainers = (_session, roles) => roles.canPostCards;
|
|
563
|
+
function cardText(number, title, verb) {
|
|
564
|
+
return { content: [text(`#${number} ${verb}: ${title}`)] };
|
|
565
|
+
}
|
|
566
|
+
export const postCardTool = {
|
|
567
|
+
name: "post_card",
|
|
568
|
+
description: "Put a decision card in the approval center for the person. Their decision goes to the requesting session and to you.",
|
|
569
|
+
parameters: {
|
|
570
|
+
type: "object",
|
|
571
|
+
properties: {
|
|
572
|
+
...CARD_PROPERTIES,
|
|
573
|
+
requested_by: {
|
|
574
|
+
type: "string",
|
|
575
|
+
description: "The session whose request this is; the decision goes back to it. Without it, Yew uses the one session whose request is open with you, if there is one.",
|
|
576
|
+
},
|
|
577
|
+
replaces: {
|
|
578
|
+
type: "array",
|
|
579
|
+
items: { type: "integer" },
|
|
580
|
+
description: "Numbers of waiting cards this one replaces; they are withdrawn.",
|
|
581
|
+
},
|
|
582
|
+
},
|
|
583
|
+
required: ["title", "undoable"],
|
|
584
|
+
additionalProperties: false,
|
|
585
|
+
},
|
|
586
|
+
readOnly: false,
|
|
587
|
+
needsFolder: false,
|
|
588
|
+
offered: maintainers,
|
|
589
|
+
subject() {
|
|
590
|
+
return { kind: "none" };
|
|
591
|
+
},
|
|
592
|
+
async run(args, ctx) {
|
|
593
|
+
const requestedBy = str(args, "requested_by");
|
|
594
|
+
const replaces = args.replaces;
|
|
595
|
+
if (replaces !== undefined &&
|
|
596
|
+
(!Array.isArray(replaces) || replaces.some((n) => !Number.isInteger(n)))) {
|
|
597
|
+
throw new ToolInputError("replaces must be a list of card numbers.");
|
|
598
|
+
}
|
|
599
|
+
const card = attempt(() => ctx.mail.post.postCard(ctx.session, {
|
|
600
|
+
...cardInput(args),
|
|
601
|
+
...(requestedBy ? { requestedBy } : {}),
|
|
602
|
+
...(replaces ? { replaces: replaces } : {}),
|
|
603
|
+
}));
|
|
604
|
+
return {
|
|
605
|
+
...cardText(card.number, card.title, "is in the approval center"),
|
|
606
|
+
detail: { cardNumber: card.number },
|
|
607
|
+
};
|
|
608
|
+
},
|
|
609
|
+
};
|
|
610
|
+
export const updateCardTool = {
|
|
611
|
+
name: "update_card",
|
|
612
|
+
description: "Change a card that is still waiting for the person. Give its number and only the fields that change.",
|
|
613
|
+
parameters: {
|
|
614
|
+
type: "object",
|
|
615
|
+
properties: { number: { type: "integer", minimum: 1 }, ...CARD_PROPERTIES },
|
|
616
|
+
required: ["number"],
|
|
617
|
+
additionalProperties: false,
|
|
618
|
+
},
|
|
619
|
+
readOnly: false,
|
|
620
|
+
needsFolder: false,
|
|
621
|
+
offered: maintainers,
|
|
622
|
+
subject() {
|
|
623
|
+
return { kind: "none" };
|
|
624
|
+
},
|
|
625
|
+
async run(args, ctx) {
|
|
626
|
+
const number = int(args, "number", 1, Number.MAX_SAFE_INTEGER);
|
|
627
|
+
const card = attempt(() => ctx.mail.post.updateCard(ctx.session, number, cardInput(args)));
|
|
628
|
+
return { ...cardText(card.number, card.title, "was updated"), detail: { cardNumber: number } };
|
|
629
|
+
},
|
|
630
|
+
};
|
|
631
|
+
export const withdrawCardTool = {
|
|
632
|
+
name: "withdraw_card",
|
|
633
|
+
description: "Take a card that no longer needs deciding out of the approval center, with the reason.",
|
|
634
|
+
parameters: {
|
|
635
|
+
type: "object",
|
|
636
|
+
properties: { number: { type: "integer", minimum: 1 }, reason: { type: "string" } },
|
|
637
|
+
required: ["number", "reason"],
|
|
638
|
+
additionalProperties: false,
|
|
639
|
+
},
|
|
640
|
+
readOnly: false,
|
|
641
|
+
needsFolder: false,
|
|
642
|
+
offered: maintainers,
|
|
643
|
+
subject() {
|
|
644
|
+
return { kind: "none" };
|
|
645
|
+
},
|
|
646
|
+
async run(args, ctx) {
|
|
647
|
+
const number = int(args, "number", 1, Number.MAX_SAFE_INTEGER);
|
|
648
|
+
const card = attempt(() => ctx.mail.post.withdrawCard(ctx.session, number, str(args, "reason", true)));
|
|
649
|
+
return {
|
|
650
|
+
...cardText(card.number, card.title, "was withdrawn"),
|
|
651
|
+
detail: { cardNumber: number },
|
|
652
|
+
};
|
|
653
|
+
},
|
|
654
|
+
};
|
|
655
|
+
export const listCardsTool = {
|
|
656
|
+
name: "list_cards",
|
|
657
|
+
description: "List the cards waiting in the approval center and the ten latest decisions.",
|
|
658
|
+
parameters: { type: "object", properties: {}, additionalProperties: false },
|
|
659
|
+
readOnly: true,
|
|
660
|
+
needsFolder: false,
|
|
661
|
+
offered: maintainers,
|
|
662
|
+
subject() {
|
|
663
|
+
return { kind: "none" };
|
|
664
|
+
},
|
|
665
|
+
async run(_args, ctx) {
|
|
666
|
+
const post = ctx.mail.post;
|
|
667
|
+
const names = (id) => post.sessionName(id);
|
|
668
|
+
const pending = post.mail.pendingCards();
|
|
669
|
+
const decided = post.mail.listCards({ status: "decided", limit: 10 }).items;
|
|
670
|
+
const parts = [
|
|
671
|
+
pending.length > 0
|
|
672
|
+
? `Waiting for the person:\n\n${pending.map((card) => decisionReport(card, names)).join("\n\n")}`
|
|
673
|
+
: "No cards are waiting for the person.",
|
|
674
|
+
];
|
|
675
|
+
if (decided.length > 0) {
|
|
676
|
+
parts.push(`Latest decisions:\n\n${decided.map((card) => decisionReport(card, names)).join("\n\n")}`);
|
|
677
|
+
}
|
|
678
|
+
return { content: [text(parts.join("\n\n"))] };
|
|
679
|
+
},
|
|
680
|
+
};
|