@yuriai/web 0.2.8-beta.1 → 0.2.8-beta.3
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/dist/assets/{AgentAvatar-MzDm6uBf.js → AgentAvatar--DsfGfhZ.js} +1 -1
- package/dist/assets/{AssistantView-Df-G2DX8.js → AssistantView-Bf19-qvJ.js} +3 -3
- package/dist/assets/{DiagramView-BoVqJRQb.js → DiagramView-UvYyjtWA.js} +1 -1
- package/dist/assets/{FadeInOnReveal-DkmfVoTO.js → FadeInOnReveal-NAFOww9Y.js} +1 -1
- package/dist/assets/{GuiPluginSurface-DxLoeTDb.js → GuiPluginSurface-DNzJNcMh.js} +1 -1
- package/dist/assets/{GuiPluginWindow-dDG5Uyqb.js → GuiPluginWindow-C73klYx3.js} +1 -1
- package/dist/assets/{Icon-BjiyvtB2.js → Icon-Cy25fgQb.js} +1 -1
- package/dist/assets/{ImageLoadingPlaceholder-CUKFQTAG.js → ImageLoadingPlaceholder-DGRjdn_K.js} +1 -1
- package/dist/assets/{LoadingImage-B7cT_4Oe.js → LoadingImage-2pPdTFHh.js} +1 -1
- package/dist/assets/{MarkdownRenderer-DYi_qpYy.js → MarkdownRenderer-GuwP9qiJ.js} +2 -2
- package/dist/assets/{MarkdownRendererImpl-CMxRMFqp.js → MarkdownRendererImpl-tHItN1IG.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-DQ4urBZW.js → MarkstreamRendererImpl-Dh13e1UE.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-C4fJlKdu.js → MobileDetailNavigation-CSxBgVuQ.js} +1 -1
- package/dist/assets/{MobileResizableSheet-C9YzOQis.js → MobileResizableSheet-BN07cmQQ.js} +1 -1
- package/dist/assets/{MobileShareBridge-DLC-TdRy.js → MobileShareBridge-7SAELdqu.js} +1 -1
- package/dist/assets/MobileTabPageHeader-Bbb36BtD.js +2 -0
- package/dist/assets/{MultiRunWindow-Cwp8-_Wh.js → MultiRunWindow-DbI9KTph.js} +1 -1
- package/dist/assets/{OnboardingScreen-D6iQ5qjF.js → OnboardingScreen-rp0qwvgz.js} +1 -1
- package/dist/assets/{OverlayScrollbar-Dbx1atD-.js → OverlayScrollbar-B--v-oQW.js} +1 -1
- package/dist/assets/{SettingsView-CYDk0wpN.js → SettingsView-C1AQoEIQ.js} +1 -1
- package/dist/assets/{SettingsWindow-Vuzphf9b.js → SettingsWindow-6M0ssWHM.js} +1 -1
- package/dist/assets/{TerminalView-Dhalx6_Z.js → TerminalView-bhL6Ccen.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DBxSxWNh.js → ToolOutputDialog-BaLKI3Yc.js} +1 -1
- package/dist/assets/{YuriLogo-DvRSd5NN.js → YuriLogo-kwLWc5Hi.js} +1 -1
- package/dist/assets/{appThemeRegistry-JEhMXHGF.js → appThemeRegistry-Bk_N8btz.js} +1 -1
- package/dist/assets/{button-BSFWH-Ok.js → button-Dodw6LWV.js} +1 -1
- package/dist/assets/{capgoAdapter-BgD0wyhC.js → capgoAdapter-DqHX7fkj.js} +1 -1
- package/dist/assets/{collapsible-DaevjAvt.js → collapsible-C9kOfVDe.js} +1 -1
- package/dist/assets/{diagram-7OgmyecX.js → diagram-CfBQ9Icg.js} +1 -1
- package/dist/assets/{dialog-D1pXn_b9.js → dialog-D0bq7nr2.js} +1 -1
- package/dist/assets/{dropdown-menu.styles-CGHPvEgD.js → dropdown-menu.styles-CLxDPSrk.js} +1 -1
- package/dist/assets/{es-DJzbuYpv.js → es-Diy_UpPF.js} +1 -1
- package/dist/assets/{fileMentionTouchSelection-BQdfRBkk.js → fileMentionTouchSelection-C16Q21Ht.js} +1 -1
- package/dist/assets/{fr-YDYbYIZQ.js → fr-CPRTMaky.js} +1 -1
- package/dist/assets/{gitApi-DhDVqj9b.js → gitApi-_yKaBF0a.js} +1 -1
- package/dist/assets/{input-BhHXFla6.js → input-HddqDhRi.js} +1 -1
- package/dist/assets/{insertionBoundaries-BMe1F3uB.js → insertionBoundaries-CHqJLwJg.js} +1 -1
- package/dist/assets/{ja-SjX3NBJz.js → ja-Cc1jn0Ag.js} +1 -1
- package/dist/assets/{ko-BxcUEWjB.js → ko-CfHUuNNe.js} +1 -1
- package/dist/assets/{main-DXlMu2LF.js → main-Bja5DG1P.js} +2 -2
- package/dist/assets/{main-CfOYzhn0.js → main-njE9rVzm.js} +4 -4
- package/dist/assets/{markdownHeightCache-DV2j4PlS.js → markdownHeightCache-BQiIj0aM.js} +1 -1
- package/dist/assets/{mcpQueries-vxcQAIGB.js → mcpQueries-uM1Chfdc.js} +1 -1
- package/dist/assets/{miniChat-D48iGEEW.js → miniChat-DAwBa-3U.js} +2 -2
- package/dist/assets/{mobile-Cy5qSiDY.js → mobile-BQmrdXmD.js} +2 -2
- package/dist/assets/{mobileBackNavigation-QtBK9OSb.js → mobileBackNavigation-DsU3qQ8W.js} +1 -1
- package/dist/assets/{multirun-BR9a6EBo.js → multirun-DRL1Wf-K.js} +1 -1
- package/dist/assets/{native-config-CHySeHif.js → native-config-BMflOjo8.js} +1 -1
- package/dist/assets/{pl-vh0XFuDb.js → pl-mUyhvp8O.js} +1 -1
- package/dist/assets/{projectMeta-Bn2vBNDe.js → projectMeta-DK-kl6vM.js} +1 -1
- package/dist/assets/{pt-BR-Cv5tssQz.js → pt-BR-D3E4Wxao.js} +1 -1
- package/dist/assets/{readiness-BAssoNVf.js → readiness-CMHDs1YN.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-B9Kci_8q.js → renderElectronMiniChatApp-CkSP0eQz.js} +2 -2
- package/dist/assets/{renderMobileApp-CBivL8Ps.js → renderMobileApp-wELnHLDT.js} +4 -4
- package/dist/assets/{runtimeConfig-COdEwlK-.js → runtimeConfig-KpW0l510.js} +1 -1
- package/dist/assets/{runtimeEndpointReset-D3x76Qpf.js → runtimeEndpointReset-BBxpXfkE.js} +3 -3
- package/dist/assets/{scheduledTaskNavigation-BZ3B5bpN.js → scheduledTaskNavigation-CyPkVBKs.js} +1 -1
- package/dist/assets/{sessionChangeSummary-Dtgq0CWg.js → sessionChangeSummary-Bb7dqAie.js} +1 -1
- package/dist/assets/{sessionLookup--Wlr3e8X.js → sessionLookup-D_P3C7rX.js} +1 -1
- package/dist/assets/{sortable-tabs-strip-BnTV_KYG.js → sortable-tabs-strip-C-qSUWlr.js} +1 -1
- package/dist/assets/{speechSettingsQueries-D3fc_4Iy.js → speechSettingsQueries-BSBjx3wG.js} +1 -1
- package/dist/assets/src-CbY9YJrh.css +2 -0
- package/dist/assets/{store-CgQdmzpX.js → store-FxBFwq--.js} +2 -2
- package/dist/assets/{textarea-Deh9E1KP.js → textarea-BvfW0tsL.js} +1 -1
- package/dist/assets/{tooltip-DygQ-2xe.js → tooltip-BmKpb74n.js} +1 -1
- package/dist/assets/{types-D8_26ZKT.js → types-rJezumB4.js} +1 -1
- package/dist/assets/{uk-3a9vdLJ-.js → uk-D9iQbGbr.js} +1 -1
- package/dist/assets/{useAppFontEffects-DLT9jVl1.js → useAppFontEffects-DZ1W3_cy.js} +5 -5
- package/dist/assets/{useDesktopWindowControlsLayout-BNAZWH9L.js → useDesktopWindowControlsLayout-D_1DLCOD.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-D2_-KCB7.js → useEffectiveDirectory-joUiryc3.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-DJwk64Po.js → useMobileNavigationStore-BaQ7TIpx.js} +6 -6
- package/dist/assets/{useWorkerHighlightedLines-k48txabk.js → useWorkerHighlightedLines-CiU1xPjX.js} +1 -1
- package/dist/assets/{zh-CN-kwaUr5W5.js → zh-CN-mNVX6pMK.js} +1 -1
- package/dist/assets/{zh-TW-BBs44W7l.js → zh-TW-B7T0e-Qv.js} +1 -1
- package/dist/index.html +6 -6
- package/dist/mini-chat.html +6 -6
- package/dist/mobile.html +6 -6
- package/package.json +1 -1
- package/server/lib/assistants/DOCUMENTATION.md +18 -15
- package/server/lib/assistants/bubbles.js +0 -14
- package/server/lib/assistants/bubbles.test.js +1 -18
- package/server/lib/assistants/contact-tools.js +179 -211
- package/server/lib/assistants/contact-tools.test.js +35 -161
- package/server/lib/assistants/harness.js +76 -238
- package/server/lib/assistants/harness.test.js +255 -279
- package/server/lib/assistants/memory.http.test.js +2 -2
- package/server/lib/assistants/pi-tools.js +1 -54
- package/server/lib/assistants/pi-tools.test.js +5 -9
- package/server/lib/assistants/routes.js +1 -0
- package/server/lib/assistants/service.js +66 -1
- package/server/lib/assistants/service.test.js +60 -42
- package/server/lib/llm/DOCUMENTATION.md +3 -0
- package/server/lib/llm/completions.js +2 -1
- package/server/lib/llm/completions.test.js +9 -0
- package/server/lib/opencode/feature-routes-runtime.js +1 -0
- package/server/lib/scheduled-tasks/runtime.test.js +3 -3
- package/dist/assets/MobileTabPageHeader-CMbbtHh7.js +0 -2
- package/dist/assets/src-NlrSCyPZ.css +0 -2
|
@@ -30,6 +30,8 @@ export const ARCHIVE_SESSION_TOOL_NAME = 'archive_session';
|
|
|
30
30
|
export const DELETE_SESSION_TOOL_NAME = 'delete_session';
|
|
31
31
|
export const CREATE_ASSISTANT_TOOL_NAME = 'create_assistant';
|
|
32
32
|
export const SCHEDULE_TASK_TOOL_NAME = 'schedule_task';
|
|
33
|
+
const LIST_SCHEDULED_TASKS_TOOL_NAME = 'list_scheduled_tasks';
|
|
34
|
+
const UPDATE_SCHEDULED_TASK_TOOL_NAME = 'update_scheduled_task';
|
|
33
35
|
export const MESSAGE_ASSISTANT_TOOL_NAME = 'message_assistant';
|
|
34
36
|
export const NEW_CONVERSATION_TOOL_NAME = 'new_conversation';
|
|
35
37
|
export const CLEAR_CHAT_HISTORY_TOOL_NAME = 'clear_chat_history';
|
|
@@ -50,7 +52,42 @@ const AVATAR_GUIDE = [
|
|
|
50
52
|
'Only seed is editable here; style, colors, facial features, custom URLs and uploaded images are not supported.',
|
|
51
53
|
'Keep the current avatarSeed to restore it later. Avatar changes preserve identity and conversations.',
|
|
52
54
|
].join('\n');
|
|
53
|
-
const
|
|
55
|
+
export const NOTIFY_USER_TOOL_NAME = 'notify_user';
|
|
56
|
+
export const STAY_SILENT_TOOL_NAME = 'stay_silent';
|
|
57
|
+
export const NOTIFY_USER_MAX_CHARS = 2000;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Harness-owned conversation tools. notify_user is the only mid-turn channel to
|
|
61
|
+
* the user; plain text beside other tool calls stays private. The stream function
|
|
62
|
+
* publishes notify_user text when the response arrives, so execution only
|
|
63
|
+
* acknowledges it. stay_silent lets a background review finish without a reply.
|
|
64
|
+
*/
|
|
65
|
+
export function createNotifyUserTool() {
|
|
66
|
+
return {
|
|
67
|
+
name: NOTIFY_USER_TOOL_NAME,
|
|
68
|
+
label: 'Notify user',
|
|
69
|
+
description: 'Send the user a short progress message while you keep working; batch it with your next tool call. Use only when it tells them something they do not already know: a direction they may want to correct, a finding that matters, a blocker, or that the work will take a while. Never use it to announce the next step or repeat the plan. The final answer is your plain reply, not this tool.',
|
|
70
|
+
parameters: typeboxObject({ text: typeboxString('Short message in the user language.') }),
|
|
71
|
+
execute: async (_toolCallId, params) => {
|
|
72
|
+
const text = typeof params?.text === 'string' ? params.text.trim() : '';
|
|
73
|
+
if (!text || text.length > NOTIFY_USER_MAX_CHARS) {
|
|
74
|
+
return { content: [{ type: 'text', text: `notify_user needs 1-${NOTIFY_USER_MAX_CHARS} characters of text.` }], details: { error: 'validation_error' }, terminate: false };
|
|
75
|
+
}
|
|
76
|
+
return { content: [{ type: 'text', text: 'Delivered.' }], details: { delivered: true }, terminate: false };
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function createStaySilentTool() {
|
|
82
|
+
return {
|
|
83
|
+
name: STAY_SILENT_TOOL_NAME,
|
|
84
|
+
label: 'Stay silent',
|
|
85
|
+
description: 'End this background review without replying to the user. Call it alone, only when no reply is needed.',
|
|
86
|
+
parameters: typeboxObject({}),
|
|
87
|
+
execute: async () => ({ content: [{ type: 'text', text: 'Silent.' }], details: { silent: true }, terminate: true }),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
54
91
|
export const ASSIGNED_SESSION_FALLBACK_BUBBLE = 'Opened a coding session.';
|
|
55
92
|
export const WATCHED_SESSION_FALLBACK_BUBBLE = 'Watching that coding session.';
|
|
56
93
|
export const STOPPED_SESSION_FALLBACK_BUBBLE = '已停止该会话。';
|
|
@@ -90,11 +127,38 @@ export function normalizeAssignRequestKey(params = {}) {
|
|
|
90
127
|
});
|
|
91
128
|
}
|
|
92
129
|
|
|
93
|
-
|
|
130
|
+
// Common shell-style tool names that models emit from other harnesses. They run
|
|
131
|
+
// through the real bash tool instead of being rejected.
|
|
132
|
+
const BASH_ALIAS_TOOLS = new Set(['shell', 'powershell', 'grep', 'glob', 'find', 'ls']);
|
|
133
|
+
const shellQuote = (value) => `'${String(value).replace(/'/g, `'\\''`)}'`;
|
|
134
|
+
const aliasString = (args, ...keys) => {
|
|
135
|
+
for (const key of keys) {
|
|
136
|
+
if (typeof args?.[key] === 'string' && args[key].trim()) return args[key].trim();
|
|
137
|
+
}
|
|
138
|
+
return null;
|
|
139
|
+
};
|
|
140
|
+
const bashAliasCommand = (name, args = {}) => {
|
|
141
|
+
const command = aliasString(args, 'command', 'cmd', 'script');
|
|
142
|
+
if (command) return command;
|
|
143
|
+
const target = shellQuote(aliasString(args, 'path', 'directory', 'dir', 'cwd') || '.');
|
|
144
|
+
const pattern = aliasString(args, 'pattern', 'query', 'regex', 'name', 'glob');
|
|
145
|
+
if (name === 'ls') return `ls -la ${target}`;
|
|
146
|
+
if (!pattern) return null;
|
|
147
|
+
if (name === 'grep') {
|
|
148
|
+
const include = aliasString(args, 'include', 'glob', 'filePattern');
|
|
149
|
+
const quoted = shellQuote(pattern);
|
|
150
|
+
return include && include !== pattern
|
|
151
|
+
? `if command -v rg >/dev/null 2>&1; then rg -n -g ${shellQuote(include)} -e ${quoted} ${target}; else grep -rnE --include=${shellQuote(include)} -e ${quoted} ${target}; fi`
|
|
152
|
+
: `if command -v rg >/dev/null 2>&1; then rg -n -e ${quoted} ${target}; else grep -rnE -e ${quoted} ${target}; fi`;
|
|
153
|
+
}
|
|
154
|
+
return `if command -v rg >/dev/null 2>&1; then rg --files -g ${shellQuote(pattern)} ${target}; else find ${target} -name ${shellQuote(pattern)}; fi`;
|
|
155
|
+
};
|
|
94
156
|
|
|
95
|
-
export const MISSED_FENCE_RETRY_USER_TEXT = '
|
|
157
|
+
export const MISSED_FENCE_RETRY_USER_TEXT = 'Call the requested tool now; do not claim success without its result.';
|
|
96
158
|
|
|
97
159
|
const CREATE_ASSISTANT_INTENT = /建助理|新建[^。\n!]{0,24}助理|创建[^。\n!]{0,24}助理|加一个助理|create (?:an |a new )?assistant|new assistant/iu;
|
|
160
|
+
// Changing or reviewing existing tasks starts with list_scheduled_tasks, not schedule_task.
|
|
161
|
+
const UPDATE_SCHEDULED_TASK_INTENT = /(?:改|修改|更新|换|切换|暂停|停用|启用|查看|看看|列出)[^。\n]{0,24}定时任务|定时任务[^。\n]{0,40}(?:改|换成|换为|切换|暂停|停用|启用|有哪些|列表)|(?:update|change|edit|pause|disable|enable|list)[^.\n]{0,24}scheduled tasks?/iu;
|
|
98
162
|
const SCHEDULE_TASK_INTENT = /排定时任务|排个?定时任务|定时任务|schedule (?:a )?(?:daily )?(?:task|ping)|scheduled task|排个?(?:每日)?(?:任务|ping)/iu;
|
|
99
163
|
const ASSIGN_SESSION_INTENT = /(?:建|开)(?:一个|个)?(?:新)?(?:编码\s*)?(?:session|会话)|继续(?:这个|该|那个)?(?:编码\s*)?(?:session|会话)|open (?:a )?(?:coding )?session|continue (?:the |this |that )?(?:coding )?session|assign_session/giu;
|
|
100
164
|
const WATCH_SESSION_INTENT = /监听(?:这个|该|那个)?(?:编码\s*)?(?:session|会话)|关注(?:这个|该|那个)?(?:编码\s*)?(?:session|会话)|watch (?:the |this |that )?(?:coding )?session|monitor (?:the |this |that )?(?:coding )?session|watch_session/giu;
|
|
@@ -170,6 +234,28 @@ const scheduleTaskParameters = typeboxObject({
|
|
|
170
234
|
model: typeboxOptional(typeboxString('Optional provider/model string such as opencode-go/deepseek-v4-flash.')),
|
|
171
235
|
});
|
|
172
236
|
|
|
237
|
+
const listScheduledTasksParameters = typeboxObject({
|
|
238
|
+
projectPath: typeboxOptional(typeboxString('Registered project path or id to limit the listing. Omit to list every registered project.')),
|
|
239
|
+
query: typeboxOptional(typeboxString('Optional filter against task name, id, prompt, or provider/model.')),
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
const updateScheduledTaskParameters = typeboxObject({
|
|
243
|
+
taskID: typeboxString('Exact task id from list_scheduled_tasks.'),
|
|
244
|
+
projectID: typeboxString('Exact project id from list_scheduled_tasks.'),
|
|
245
|
+
name: typeboxOptional(typeboxString('New task name.')),
|
|
246
|
+
enabled: typeboxOptional(typeboxString('"true" or "false" to enable or pause the task.')),
|
|
247
|
+
prompt: typeboxOptional(typeboxString('New prompt for the scheduled run.')),
|
|
248
|
+
providerID: typeboxOptional(typeboxString('New OpenCode provider ID from the connected catalog.')),
|
|
249
|
+
modelID: typeboxOptional(typeboxString('New OpenCode model ID from the connected catalog.')),
|
|
250
|
+
model: typeboxOptional(typeboxString('New provider/model string from the connected catalog.')),
|
|
251
|
+
kind: typeboxOptional(typeboxString('New schedule kind: daily, weekly, once, or cron.')),
|
|
252
|
+
time: typeboxOptional(typeboxString('New HH:mm local time.')),
|
|
253
|
+
timezone: typeboxOptional(typeboxString('New IANA timezone.')),
|
|
254
|
+
date: typeboxOptional(typeboxString('YYYY-MM-DD for kind=once.')),
|
|
255
|
+
weekdays: typeboxOptional(typeboxString('Comma-separated 0-6 weekdays for kind=weekly.')),
|
|
256
|
+
cron: typeboxOptional(typeboxString('Cron expression for kind=cron.')),
|
|
257
|
+
});
|
|
258
|
+
|
|
173
259
|
const messageAssistantParameters = typeboxObject({
|
|
174
260
|
text: typeboxString('Read-only message to insert into the other assistant contact transcript.'),
|
|
175
261
|
to: typeboxOptional(typeboxString('Recipient assistant display name, e.g. PeerQA.')),
|
|
@@ -349,148 +435,46 @@ export function boundSessionListLimit(value) {
|
|
|
349
435
|
const allowedToolName = (name, allowedNames) => {
|
|
350
436
|
if (typeof name !== 'string' || !name.trim()) return false;
|
|
351
437
|
const next = name.trim();
|
|
352
|
-
if (
|
|
353
|
-
return
|
|
438
|
+
if (allowedNames.has(next)) return true;
|
|
439
|
+
return BASH_ALIAS_TOOLS.has(next) && allowedNames.has('bash');
|
|
354
440
|
};
|
|
355
441
|
|
|
356
|
-
const
|
|
357
|
-
let parsed;
|
|
358
|
-
try {
|
|
359
|
-
parsed = JSON.parse(raw);
|
|
360
|
-
} catch {
|
|
361
|
-
return null;
|
|
362
|
-
}
|
|
363
|
-
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return null;
|
|
364
|
-
const name = typeof parsed.name === 'string' ? parsed.name.trim() : '';
|
|
442
|
+
const normalizeToolCall = (name, args, allowedNames) => {
|
|
365
443
|
if (!allowedToolName(name, allowedNames)) return null;
|
|
366
|
-
|
|
367
|
-
if (
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
if (text[start] !== '{') return null;
|
|
373
|
-
let depth = 0;
|
|
374
|
-
let inString = false;
|
|
375
|
-
let escape = false;
|
|
376
|
-
for (let index = start; index < text.length; index += 1) {
|
|
377
|
-
const character = text[index];
|
|
378
|
-
if (inString) {
|
|
379
|
-
if (escape) {
|
|
380
|
-
escape = false;
|
|
381
|
-
continue;
|
|
382
|
-
}
|
|
383
|
-
if (character === '\\') {
|
|
384
|
-
escape = true;
|
|
385
|
-
continue;
|
|
386
|
-
}
|
|
387
|
-
if (character === '"') inString = false;
|
|
388
|
-
continue;
|
|
389
|
-
}
|
|
390
|
-
if (character === '"') {
|
|
391
|
-
inString = true;
|
|
392
|
-
continue;
|
|
393
|
-
}
|
|
394
|
-
if (character === '{') depth += 1;
|
|
395
|
-
else if (character === '}') {
|
|
396
|
-
depth -= 1;
|
|
397
|
-
if (depth === 0) return text.slice(start, index + 1);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
return null;
|
|
401
|
-
};
|
|
402
|
-
|
|
403
|
-
const findToolFenceEnd = (text, start) => {
|
|
404
|
-
let inString = false;
|
|
405
|
-
let escaped = false;
|
|
406
|
-
for (let index = start; index < text.length; index += 1) {
|
|
407
|
-
const character = text[index];
|
|
408
|
-
if (inString) {
|
|
409
|
-
if (escaped) escaped = false;
|
|
410
|
-
else if (character === '\\') escaped = true;
|
|
411
|
-
else if (character === '"') inString = false;
|
|
412
|
-
} else if (character === '"') {
|
|
413
|
-
inString = true;
|
|
414
|
-
} else if (text.startsWith('```', index)) {
|
|
415
|
-
return index;
|
|
416
|
-
}
|
|
444
|
+
if (args == null || typeof args !== 'object' || Array.isArray(args)) return null;
|
|
445
|
+
if (!allowedNames.has(name) && BASH_ALIAS_TOOLS.has(name)) {
|
|
446
|
+
const command = bashAliasCommand(name, args);
|
|
447
|
+
if (!command) return null;
|
|
448
|
+
const timeout = typeof args.timeout === 'number' ? { timeout: args.timeout } : {};
|
|
449
|
+
return { name: 'bash', arguments: { command, ...timeout } };
|
|
417
450
|
}
|
|
418
|
-
return
|
|
451
|
+
return { name, arguments: args };
|
|
419
452
|
};
|
|
420
453
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
const allowed = new Set(
|
|
428
|
-
(Array.isArray(allowedNames) ? allowedNames : [])
|
|
429
|
-
.filter((name) => typeof name === 'string' && name.trim() && !DENIED_CODING_TOOLS.has(name.trim()))
|
|
430
|
-
.map((name) => name.trim()),
|
|
431
|
-
);
|
|
432
|
-
const raw = typeof text === 'string' ? text : '';
|
|
454
|
+
/**
|
|
455
|
+
* Normalize native function calls: shell-style aliases run through bash, and an
|
|
456
|
+
* unavailable or malformed call becomes an actionable correction for the model.
|
|
457
|
+
*/
|
|
458
|
+
export function parseContactNativeToolCalls(calls, allowedNames) {
|
|
459
|
+
const allowed = new Set(allowedNames);
|
|
433
460
|
const toolCalls = [];
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
: raw.indexOf('```', payloadStart);
|
|
448
|
-
if (explicit) {
|
|
449
|
-
if (end < 0) {
|
|
450
|
-
return { chatText: '', toolCalls: [], protocolError: 'Unclosed yuri-tool fence' };
|
|
451
|
-
}
|
|
452
|
-
const toolCall = parseToolPayload(raw.slice(payloadStart, end).trim(), allowed);
|
|
453
|
-
if (!toolCall) {
|
|
454
|
-
return { chatText: '', toolCalls: [], protocolError: 'Invalid or unavailable tool in yuri-tool fence' };
|
|
455
|
-
}
|
|
456
|
-
toolCalls.push(toolCall);
|
|
457
|
-
visible.push(raw.slice(visibleStart, index));
|
|
458
|
-
visibleStart = end + 3;
|
|
459
|
-
}
|
|
460
|
-
if (!explicit && genericJson && end >= 0) {
|
|
461
|
-
const toolCall = parseToolPayload(raw.slice(payloadStart, end).trim(), allowed);
|
|
462
|
-
if (toolCall) {
|
|
463
|
-
toolCalls.push(toolCall);
|
|
464
|
-
visible.push(raw.slice(visibleStart, index));
|
|
465
|
-
visibleStart = end + 3;
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
// Other fenced prose/examples and final declarations are not tool invocations.
|
|
469
|
-
index = end < 0 ? raw.length : end + 3;
|
|
470
|
-
continue;
|
|
471
|
-
}
|
|
472
|
-
if (raw[index] !== '{') {
|
|
473
|
-
index += 1;
|
|
474
|
-
continue;
|
|
475
|
-
}
|
|
476
|
-
const snippet = extractJsonObjectAt(raw, index);
|
|
477
|
-
if (!snippet) {
|
|
478
|
-
// Do not reinterpret a nested object from malformed outer JSON as an
|
|
479
|
-
// operation, or repeatedly scan the same unfinished suffix.
|
|
480
|
-
return { chatText: '', toolCalls: [], protocolError: 'Unclosed JSON object in tool response' };
|
|
461
|
+
for (const call of calls) {
|
|
462
|
+
const name = typeof call?.function?.name === 'string' ? call.function.name.trim() : '';
|
|
463
|
+
let args;
|
|
464
|
+
try { args = JSON.parse(call?.function?.arguments || '{}'); }
|
|
465
|
+
catch { return { toolCalls: [], protocolError: `Arguments for "${name.slice(0, 80)}" must be valid JSON.` }; }
|
|
466
|
+
const normalized = normalizeToolCall(name, args, allowed);
|
|
467
|
+
if (!normalized) {
|
|
468
|
+
return {
|
|
469
|
+
toolCalls: [],
|
|
470
|
+
protocolError: name && !allowedToolName(name, allowed)
|
|
471
|
+
? `"${name.slice(0, 80)}" is not an available tool. Use only: ${[...allowed].join(', ')}. If no available tool can do the task, say so in your reply.`
|
|
472
|
+
: `Invalid arguments for "${name.slice(0, 80)}".`,
|
|
473
|
+
};
|
|
481
474
|
}
|
|
482
|
-
|
|
483
|
-
if (toolCall) {
|
|
484
|
-
toolCalls.push(toolCall);
|
|
485
|
-
visible.push(raw.slice(visibleStart, index));
|
|
486
|
-
visibleStart = index + snippet.length;
|
|
487
|
-
}
|
|
488
|
-
// Consume the whole outer object even if it is ordinary JSON. Its nested
|
|
489
|
-
// arguments or example objects must never become additional operations.
|
|
490
|
-
index += snippet.length;
|
|
475
|
+
toolCalls.push({ ...normalized, id: call.id });
|
|
491
476
|
}
|
|
492
|
-
|
|
493
|
-
return { chatText: visible.join('').trim(), toolCalls };
|
|
477
|
+
return { toolCalls, protocolError: '' };
|
|
494
478
|
}
|
|
495
479
|
|
|
496
480
|
const isNegatedAt = (text, index) => INTENT_NEGATION.test(text.slice(Math.max(0, index - 12), index));
|
|
@@ -524,7 +508,7 @@ const hasNewConversationIntent = (text) => hasIntentMatch(NEW_CONVERSATION_INTEN
|
|
|
524
508
|
export function detectRequestedContactTools(userText, allowedNames = []) {
|
|
525
509
|
const allowed = new Set(
|
|
526
510
|
(Array.isArray(allowedNames) ? allowedNames : [])
|
|
527
|
-
.filter((name) => typeof name === 'string' && name.trim()
|
|
511
|
+
.filter((name) => typeof name === 'string' && name.trim())
|
|
528
512
|
.map((name) => name.trim()),
|
|
529
513
|
);
|
|
530
514
|
const text = typeof userText === 'string' ? userText : '';
|
|
@@ -558,7 +542,9 @@ export function detectRequestedContactTools(userText, allowedNames = []) {
|
|
|
558
542
|
if (allowed.has(CREATE_ASSISTANT_TOOL_NAME) && CREATE_ASSISTANT_INTENT.test(text)) {
|
|
559
543
|
requested.push(CREATE_ASSISTANT_TOOL_NAME);
|
|
560
544
|
}
|
|
561
|
-
if (allowed.has(
|
|
545
|
+
if (allowed.has(LIST_SCHEDULED_TASKS_TOOL_NAME) && UPDATE_SCHEDULED_TASK_INTENT.test(text)) {
|
|
546
|
+
requested.push(LIST_SCHEDULED_TASKS_TOOL_NAME);
|
|
547
|
+
} else if (allowed.has(SCHEDULE_TASK_TOOL_NAME) && SCHEDULE_TASK_INTENT.test(text)) {
|
|
562
548
|
requested.push(SCHEDULE_TASK_TOOL_NAME);
|
|
563
549
|
}
|
|
564
550
|
// Prefer explicit stop/watch over generic continue/assign when both could match.
|
|
@@ -582,7 +568,9 @@ export function detectRequestedContactTools(userText, allowedNames = []) {
|
|
|
582
568
|
}
|
|
583
569
|
|
|
584
570
|
export function contactTurnHasToolResult(messages) {
|
|
585
|
-
return (Array.isArray(messages) ? messages : []).some((message) =>
|
|
571
|
+
return (Array.isArray(messages) ? messages : []).some((message) => (
|
|
572
|
+
message?.role === 'toolResult' && message.toolName !== NOTIFY_USER_TOOL_NAME
|
|
573
|
+
));
|
|
586
574
|
}
|
|
587
575
|
|
|
588
576
|
const trim = (value, max = 10_000) => {
|
|
@@ -592,6 +580,17 @@ const trim = (value, max = 10_000) => {
|
|
|
592
580
|
return next;
|
|
593
581
|
};
|
|
594
582
|
|
|
583
|
+
/** Model-facing scheduled-task summary: identity, schedule, model, bounded prompt preview. */
|
|
584
|
+
export function summarizeScheduledTask(task, projectID) {
|
|
585
|
+
const prompt = typeof task?.execution?.prompt === 'string' ? task.execution.prompt : '';
|
|
586
|
+
return {
|
|
587
|
+
id: task?.id ?? null, projectID, name: task?.name ?? null,
|
|
588
|
+
enabled: task?.enabled !== false, schedule: task?.schedule ?? null,
|
|
589
|
+
providerID: task?.execution?.providerID ?? null, modelID: task?.execution?.modelID ?? null,
|
|
590
|
+
promptPreview: prompt.length > 200 ? `${prompt.slice(0, 200)}…` : prompt,
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
|
|
595
594
|
/** Resolve OpenCode provider/model from tool args or the current contact. */
|
|
596
595
|
export function resolveContactProviderModel(params = {}, fallback = {}) {
|
|
597
596
|
const providerID = trim(params.providerID, 256);
|
|
@@ -679,38 +678,9 @@ export function resolveAssistantTarget(params = {}, assistants = []) {
|
|
|
679
678
|
return matches[0];
|
|
680
679
|
}
|
|
681
680
|
|
|
682
|
-
/**
|
|
683
|
-
* Serialize a tool parameter schema for the contact system prompt.
|
|
684
|
-
* Accepts plain JSON-schema-like objects and TypeBox schemas (JSON.stringify).
|
|
685
|
-
* Strips non-enumerable TypeBox markers (~kind / ~optional).
|
|
686
|
-
*/
|
|
687
|
-
export function serializeToolParametersForPrompt(parameters) {
|
|
688
|
-
if (parameters == null) return '{"type":"object","properties":{}}';
|
|
689
|
-
try {
|
|
690
|
-
const text = JSON.stringify(parameters, (_key, value) => {
|
|
691
|
-
if (typeof value === 'function' || typeof value === 'symbol') return undefined;
|
|
692
|
-
return value;
|
|
693
|
-
});
|
|
694
|
-
if (typeof text === 'string' && text.trim() && text !== 'undefined') return text;
|
|
695
|
-
} catch {
|
|
696
|
-
// Fall through to empty object schema.
|
|
697
|
-
}
|
|
698
|
-
return '{"type":"object","properties":{}}';
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
/** One catalog line: name, description, and full arguments schema. */
|
|
702
|
-
export function formatApplicationToolCatalogEntry(tool) {
|
|
703
|
-
if (!tool || typeof tool.name !== 'string' || !tool.name.trim()) return '';
|
|
704
|
-
const name = tool.name.trim();
|
|
705
|
-
const description = typeof tool.description === 'string' && tool.description.trim()
|
|
706
|
-
? tool.description.trim()
|
|
707
|
-
: (typeof tool.label === 'string' && tool.label.trim() ? tool.label.trim() : name);
|
|
708
|
-
return `- ${name}: ${description}\n arguments schema: ${serializeToolParametersForPrompt(tool.parameters)}`;
|
|
709
|
-
}
|
|
710
|
-
|
|
711
681
|
export function formatContactToolsPrompt(tools) {
|
|
712
682
|
const list = Array.isArray(tools)
|
|
713
|
-
? tools.filter((tool) => tool?.name && !
|
|
683
|
+
? tools.filter((tool) => tool?.name && !isPiCodingToolName(tool.name))
|
|
714
684
|
: [];
|
|
715
685
|
if (list.length === 0) return '';
|
|
716
686
|
return [
|
|
@@ -729,43 +699,7 @@ export function formatContactToolsPrompt(tools) {
|
|
|
729
699
|
'When they want to stop/abort a running coding session (停止会话 / stop session), call stop_session with sessionID — that calls real OpenCode session.abort.',
|
|
730
700
|
'When they want a scheduled task (排定时任务 / schedule daily ping), call schedule_task.',
|
|
731
701
|
'When they want to tell another assistant (给 PeerQA 说一声 / message PeerQA), call message_assistant.',
|
|
732
|
-
|
|
733
|
-
`\`\`\`${CONTACT_TOOL_FENCE}`,
|
|
734
|
-
`{"name":"${NEW_CONVERSATION_TOOL_NAME}","arguments":{}}`,
|
|
735
|
-
'```',
|
|
736
|
-
`\`\`\`${CONTACT_TOOL_FENCE}`,
|
|
737
|
-
`{"name":"${CLEAR_CHAT_HISTORY_TOOL_NAME}","arguments":{}}`,
|
|
738
|
-
'```',
|
|
739
|
-
`\`\`\`${CONTACT_TOOL_FENCE}`,
|
|
740
|
-
`{"name":"${LIST_PROJECTS_TOOL_NAME}","arguments":{"query":"yuri yee"}}`,
|
|
741
|
-
'```',
|
|
742
|
-
`\`\`\`${CONTACT_TOOL_FENCE}`,
|
|
743
|
-
`{"name":"${LIST_SESSIONS_TOOL_NAME}","arguments":{"projectPath":"/path/to/repo","query":"login"}}`,
|
|
744
|
-
'```',
|
|
745
|
-
`\`\`\`${CONTACT_TOOL_FENCE}`,
|
|
746
|
-
`{"name":"${GET_ASSISTANT_SETTINGS_TOOL_NAME}","arguments":{}}`,
|
|
747
|
-
'```',
|
|
748
|
-
`\`\`\`${CONTACT_TOOL_FENCE}`,
|
|
749
|
-
`{"name":"${UPDATE_DEFAULT_PROMPT_TOOL_NAME}","arguments":{"to":"OpenCode 配置助手","prompt":"Be terse and reply in Chinese."}}`,
|
|
750
|
-
'```',
|
|
751
|
-
`\`\`\`${CONTACT_TOOL_FENCE}`,
|
|
752
|
-
`{"name":"${CREATE_ASSISTANT_TOOL_NAME}","arguments":{"name":"FlowQA","model":"opencode-go/deepseek-v4-flash"}}`,
|
|
753
|
-
'```',
|
|
754
|
-
`\`\`\`${CONTACT_TOOL_FENCE}`,
|
|
755
|
-
`{"name":"${SCHEDULE_TASK_TOOL_NAME}","arguments":{"name":"Daily ping","prompt":"ping","time":"18:00","timezone":"Asia/Shanghai"}}`,
|
|
756
|
-
'```',
|
|
757
|
-
`\`\`\`${CONTACT_TOOL_FENCE}`,
|
|
758
|
-
`{"name":"${MESSAGE_ASSISTANT_TOOL_NAME}","arguments":{"to":"PeerQA","text":"hello-from-assistant 写好了"}}`,
|
|
759
|
-
'```',
|
|
760
|
-
`\`\`\`${CONTACT_TOOL_FENCE}`,
|
|
761
|
-
`{"name":"${ASSIGN_SESSION_TOOL_NAME}","arguments":{"prompt":"...","projectPath":"...","model":"provider/model-id"}}`,
|
|
762
|
-
'```',
|
|
763
|
-
`\`\`\`${CONTACT_TOOL_FENCE}`,
|
|
764
|
-
`{"name":"${WATCH_SESSION_TOOL_NAME}","arguments":{"sessionID":"ses_example"}}`,
|
|
765
|
-
'```',
|
|
766
|
-
`\`\`\`${CONTACT_TOOL_FENCE}`,
|
|
767
|
-
`{"name":"${STOP_SESSION_TOOL_NAME}","arguments":{"sessionID":"ses_example"}}`,
|
|
768
|
-
'```',
|
|
702
|
+
'Call exactly one Yuri operation tool per response; coding tools may be batched.',
|
|
769
703
|
'If the user asked for more than one of these, do them in that order across turns: new_conversation or clear_chat_history, then list_projects, then list_sessions, then get_assistant_settings or update_default_prompt, then create_assistant, then schedule_task, then message_assistant, then watch_session or stop_session, then assign_session.',
|
|
770
704
|
'Prerequisite lookups (list_projects / list_sessions) may run before assign_session / watch_session / stop_session in the same turn. After a successful assign_session or watch_session the turn ends — never call them again in that turn, and do not keep looping tools.',
|
|
771
705
|
'new_conversation advances this contact\'s LLM context boundary only. Stored messages and watches remain. It never calls session/new or createNew.',
|
|
@@ -779,16 +713,14 @@ export function formatContactToolsPrompt(tools) {
|
|
|
779
713
|
'steer_session sends text into an existing session with delivery=steer, preserving its model. archive_session archives an existing session; delete_session permanently deletes it. Use exact sessionID from history, references or list_sessions; ask if the target is ambiguous. Only delete when the user requested deletion. These operations call real APIs; never claim success from a spoken promise. assign_session creates a new session when sessionID is omitted, or continues an existing session when supplied.',
|
|
780
714
|
'stop_session calls real OpenCode session.abort for that sessionID and returns the true result. Directory comes from authoritative session metadata. A failure is not a silent success. Do not claim stopped unless the tool returned success.',
|
|
781
715
|
'create_assistant reuses already-connected OpenCode providers (providerID/modelID). Mode is continuous.',
|
|
782
|
-
'schedule_task writes the same payload as PUT /api/projects/:id/scheduled-tasks onto a registered project.',
|
|
716
|
+
'schedule_task writes the same payload as PUT /api/projects/:id/scheduled-tasks onto a registered project. It only creates new tasks.',
|
|
717
|
+
'To review or change existing scheduled tasks, call list_scheduled_tasks, then update_scheduled_task with the exact taskID and projectID it returned. Update one task per call and pass only the fields to change.',
|
|
783
718
|
'message_assistant is read-only: it inserts into the other contact transcript. It never runs promptAsync or mutates sessions or files. Never assign through a peer message.',
|
|
784
719
|
'A reply without the tool call does nothing — agreeing in Chinese (好的 / 我来创建 / 我去说一声) is not sending.',
|
|
785
|
-
'A yuri-message prefix is not required before a tool fence; publish one only when it tells the user something new. Keep private reasoning, tool names, and raw traces out of public messages.',
|
|
786
720
|
'Never say 已创建, 已发送, 已停止, created, scheduled, opened, watched, stopped, or sent unless the tool already returned success.',
|
|
787
721
|
'With an empty registered catalog, first discover the relevant existing workspace through list_sessions and directory lookups, then ask the user to register that workspace in Settings before assignment.',
|
|
788
722
|
'After a tool that changes state succeeds, confirm in one short bubble; lookups need no separate confirmation. The user sees a contact card, not tool traces. After successful assign_session or watch_session the session card plus that short confirm is enough — stop.',
|
|
789
|
-
'These are application-owned Yuri contact tools (not OpenCode native tools, not MCP, not skill directory entries). Use only the names and
|
|
790
|
-
'Available Yuri tools:',
|
|
791
|
-
...list.map((tool) => formatApplicationToolCatalogEntry(tool)).filter(Boolean),
|
|
723
|
+
'These are application-owned Yuri contact tools (not OpenCode native tools, not MCP, not skill directory entries). Use only the provided tool names and their schemas.',
|
|
792
724
|
].join('\n');
|
|
793
725
|
}
|
|
794
726
|
|
|
@@ -917,6 +849,8 @@ export function createContactTools({
|
|
|
917
849
|
deleteSession,
|
|
918
850
|
createAssistant,
|
|
919
851
|
scheduleTask,
|
|
852
|
+
listScheduledTasks,
|
|
853
|
+
updateScheduledTask,
|
|
920
854
|
deliverPeerMessage,
|
|
921
855
|
clearContactMemory,
|
|
922
856
|
resetContact,
|
|
@@ -1410,6 +1344,40 @@ export function createContactTools({
|
|
|
1410
1344
|
}
|
|
1411
1345
|
},
|
|
1412
1346
|
},
|
|
1347
|
+
{
|
|
1348
|
+
name: LIST_SCHEDULED_TASKS_TOOL_NAME,
|
|
1349
|
+
label: 'List scheduled tasks',
|
|
1350
|
+
description: 'List scheduled tasks across registered projects with id, projectID, name, enabled, schedule, provider/model, and a prompt preview. Partial failures list failed projects.',
|
|
1351
|
+
parameters: listScheduledTasksParameters,
|
|
1352
|
+
execute: async (_toolCallId, params) => {
|
|
1353
|
+
try {
|
|
1354
|
+
if (typeof listScheduledTasks !== 'function') throw new AssignError('upstream_error', 'Listing scheduled tasks is unavailable.');
|
|
1355
|
+
const result = await listScheduledTasks(params || {});
|
|
1356
|
+
return { content: [{ type: 'text', text: JSON.stringify(result) }], details: result, terminate: false };
|
|
1357
|
+
} catch (error) { return toolFailure(error, 'list_scheduled_tasks_failed', 'Could not list scheduled tasks.'); }
|
|
1358
|
+
},
|
|
1359
|
+
},
|
|
1360
|
+
{
|
|
1361
|
+
name: UPDATE_SCHEDULED_TASK_TOOL_NAME,
|
|
1362
|
+
label: 'Update scheduled task',
|
|
1363
|
+
description: 'Update one existing scheduled task by exact taskID + projectID from list_scheduled_tasks. Pass only fields to change. An explicit model must exist in the connected catalog. Emits a schedule card.',
|
|
1364
|
+
parameters: updateScheduledTaskParameters,
|
|
1365
|
+
execute: async (_toolCallId, params) => {
|
|
1366
|
+
try {
|
|
1367
|
+
if (typeof updateScheduledTask !== 'function') throw new AssignError('upstream_error', 'Updating a scheduled task is unavailable.');
|
|
1368
|
+
const taskID = trim(params?.taskID, 256);
|
|
1369
|
+
const projectID = trim(params?.projectID, 256);
|
|
1370
|
+
if (!taskID || !projectID) throw new AssignError('validation_error', 'update_scheduled_task requires taskID and projectID from list_scheduled_tasks.');
|
|
1371
|
+
const updated = await updateScheduledTask({ ...params, taskID, projectID });
|
|
1372
|
+
const task = updated?.task || {};
|
|
1373
|
+
const card = createScheduleCardPart({ taskID: task.id || taskID, projectID, name: task.name || taskID,
|
|
1374
|
+
kind: task.schedule?.kind, time: task.schedule?.time || task.schedule?.times?.[0],
|
|
1375
|
+
timezone: task.schedule?.timezone, prompt: task.execution?.prompt });
|
|
1376
|
+
emitCard(card);
|
|
1377
|
+
return { content: [{ type: 'text', text: JSON.stringify({ updated: true, task: summarizeScheduledTask(task, projectID) }) }], details: { card, updated }, terminate: false };
|
|
1378
|
+
} catch (error) { return toolFailure(error, 'update_scheduled_task_failed', 'Could not update that scheduled task.'); }
|
|
1379
|
+
},
|
|
1380
|
+
},
|
|
1413
1381
|
{
|
|
1414
1382
|
name: MESSAGE_ASSISTANT_TOOL_NAME,
|
|
1415
1383
|
label: 'Message assistant',
|