From c412b65bfa90a74220e0b83de2b55607d3260c7c Mon Sep 17 00:00:00 2001 From: Day Dreamer <87640074+HugoXK@users.noreply.github.com> Date: Sat, 21 Nov 2026 09:26:11 +0800 Subject: [PATCH 1/2] Name a down capability in the system prompt, and keep its URL clean A Bot could promise work for one of its own attached MCP servers or skills before learning that it cannot be reached. The host already knew: the capability status carries `error` or `needs-approval`. A second prompt section (order 700) now names each of those in one line, built from capabilityStatusesView(), and renders to nothing while every capability is ready, so the identity section and its cached prefix stay byte-stable. From the security read at 6b401ebb: a URL such as https://alice:s3cr3t-pa55@host/mcp was accepted, the transport error quoted it verbatim, and that sentence is now printed every turn. The save refuses userinfo, and a stored error of a capability saved before the refusal has its userinfo masked before the 300-character cut. Docs-not-needed: client.js and core/src/client/i18n.js changed only to carry the zh dictionary entry for the new host refusal string from #3273; no client behaviour, API or subsystem contract changed. --- changelog.d/3273.fixed.md | 1 + core/client.js | 3 + core/src/client/i18n.js | 3 + core/src/host/capabilities.js | 16 +- core/src/host/prompt.js | 36 ++- core/test/capabilities.test.js | 51 ++++ core/test/install.test.js | 2 + core/test/prompt.test.js | 130 ++++++++- core/test/settings-error-placement.test.js | 5 +- docs/subsystems/core-host.md | 2 +- patches/ds-bot/0001-core-fixes.patch | 252 +++++++++++++++++- patches/ds-bot/0008-client-bundle.patch | 5 +- patches/ds-bot/0014-flybot-branding.patch | 53 +++- .../test/settings-error-placement.test.js | 5 +- 14 files changed, 543 insertions(+), 21 deletions(-) create mode 100644 changelog.d/3273.fixed.md diff --git a/changelog.d/3273.fixed.md b/changelog.d/3273.fixed.md new file mode 100644 index 000000000..bf7d5c151 --- /dev/null +++ b/changelog.d/3273.fixed.md @@ -0,0 +1 @@ +A Bot now learns from its system prompt that one of its own capabilities cannot be used right now, naming the capability and the reason, so it says "GitHub isn't connected (401 bad credentials)" before acting instead of agreeing to the work and failing half a turn later ([#3273](https://github.com/ThinkFlowLab/FlyBot/issues/3273)). Saving a capability URL that carries a username or password is refused, and an older error that quotes such a URL is stored with the userinfo masked, so a credential can never be printed into the Bot's system prompt ([#3273](https://github.com/ThinkFlowLab/FlyBot/issues/3273)). diff --git a/core/client.js b/core/client.js index 079761269..969d927ea 100644 --- a/core/client.js +++ b/core/client.js @@ -1912,6 +1912,9 @@ var HOST_ZH = { 'Use a capability name with lowercase letters, digits, and single hyphens; "github" and "composio" are reserved.': "能力名只能用小写字母、数字和单个连字符;「github」和「composio」是保留名。", "Enter a command for the MCP server.": "请填写 MCP 服务器的命令。", "Enter a valid HTTP or HTTPS URL.": "请填写有效的 HTTP 或 HTTPS 地址。", + // #3273: a URL carrying userinfo is refused instead of stored, so the credential never reaches + // a status line and never reaches the system prompt. + "Enter the URL without a username or password. Save the credential as a secret and reference it in a header.": "地址里不要写用户名或密码。请把凭据保存为密钥,并在请求头里引用它。", "A capability cannot change its kind. Delete it and save a new one.": "能力类型不能改。请删掉它,再新建一个。", "Environment variables must contain text values.": "环境变量里只能填文本值。", "Headers must contain text values.": "请求头里只能填文本值。" diff --git a/core/src/client/i18n.js b/core/src/client/i18n.js index 90714c873..0dbf5ba60 100644 --- a/core/src/client/i18n.js +++ b/core/src/client/i18n.js @@ -1872,6 +1872,9 @@ const HOST_ZH = { 'Use a capability name with lowercase letters, digits, and single hyphens; "github" and "composio" are reserved.': '能力名只能用小写字母、数字和单个连字符;「github」和「composio」是保留名。', 'Enter a command for the MCP server.': '请填写 MCP 服务器的命令。', 'Enter a valid HTTP or HTTPS URL.': '请填写有效的 HTTP 或 HTTPS 地址。', + // #3273: a URL carrying userinfo is refused instead of stored, so the credential never reaches + // a status line and never reaches the system prompt. + 'Enter the URL without a username or password. Save the credential as a secret and reference it in a header.': '地址里不要写用户名或密码。请把凭据保存为密钥,并在请求头里引用它。', 'A capability cannot change its kind. Delete it and save a new one.': '能力类型不能改。请删掉它,再新建一个。', 'Environment variables must contain text values.': '环境变量里只能填文本值。', 'Headers must contain text values.': '请求头里只能填文本值。', diff --git a/core/src/host/capabilities.js b/core/src/host/capabilities.js index 861a0de58..4e13a5d7d 100644 --- a/core/src/host/capabilities.js +++ b/core/src/host/capabilities.js @@ -36,6 +36,11 @@ export function expandCapabilityNames(capabilities, library) { return expanded } +// #3273: `redactSecrets` replaces saved key values, so a password written into a URL is a shape it +// cannot know. A transport error quotes that URL back verbatim, and the status line reaches the +// system prompt every turn, so userinfo is dropped before the sentence is stored. +const withoutUserinfo = text => text.replace(/([a-z][a-z0-9+.-]*:\/\/)[^/\s@]+@/gi, '$1') + const same = (a, b) => JSON.stringify(a) === JSON.stringify(b) const strings = value => { if (value === undefined) return [] @@ -112,10 +117,10 @@ export function install(rt) { Object.assign(item, { transport, command, args, env, approved: ui ? true : changed ? false : previous.approved === true }) } else { const url = String(body.url ?? '').trim() - try { - const parsed = new URL(url) - if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') throw new Error() - } catch { throw new Error('Enter a valid HTTP or HTTPS URL.') } + let parsed + try { parsed = new URL(url) } catch { throw new Error('Enter a valid HTTP or HTTPS URL.') } + if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') throw new Error('Enter a valid HTTP or HTTPS URL.') + if (parsed.username !== '' || parsed.password !== '') throw new Error('Enter the URL without a username or password. Save the credential as a secret and reference it in a header.') Object.assign(item, { transport, url, headers: stringMap(body.headers, 'Headers'), approved: true }) } } else if (kind === 'skill') { @@ -312,7 +317,8 @@ export function install(rt) { statusSet(bot.id, name, sessionId, { state: 'ready' }) } catch (error) { await drop() - const message = rt.redactSecrets([error, error?.cause].filter(Boolean).map(part => String(part?.message ?? part)).join(': ') || 'Connection failed').slice(0, 300) + const joined = [error, error?.cause].filter(Boolean).map(part => String(part?.message ?? part)).join(': ') || 'Connection failed' + const message = withoutUserinfo(rt.redactSecrets(joined)).slice(0, 300) statusSet(bot.id, name, sessionId, { state: 'error', error: message }) } } diff --git a/core/src/host/prompt.js b/core/src/host/prompt.js index 2617bd388..98fe87ac2 100644 --- a/core/src/host/prompt.js +++ b/core/src/host/prompt.js @@ -1,5 +1,7 @@ -// Prompt: one section whose text depends only on the rendering Session's own Bot -// record, so the prefix stays byte-stable across turns and roster changes. +// Prompts: two sections. The identity section's text depends only on the rendering +// Session's own Bot record, so the cached prefix stays byte-stable across turns and roster +// changes. The capability section names the attached capabilities that cannot be used right +// now; it renders to nothing while every one of them is ready. const TEAM_RULES = [ '## How your Bot team works', @@ -77,10 +79,40 @@ export function install(rt) { return '' } + // #3273: the Bot has to learn about a broken capability from its own prompt, not after it + // has already promised the work and the first call fails. Only the two states the user can + // act on are named; everything else (ready, connecting) renders to nothing. + const capabilitiesFor = (id) => { + const self = rt.selfOf(id) + const bot = rt.botOf(self) + if (bot === undefined) return '' + const statuses = (rt.capabilityStatusesView?.() ?? {})[bot.id] ?? {} + const kinds = new Map((rt.capabilityLibraryView?.() ?? []).map(item => [item.name, item.kind])) + const lines = [] + for (const [name, status] of Object.entries(statuses)) { + if (status.state !== 'error' && status.state !== 'needs-approval') continue + // The reason comes from the host already redacted and cut to 300 characters; collapse + // its whitespace so one capability stays one line. An empty reason would leave a + // dangling dash, so it falls back to a sentence of its own. + const reason = String(status.state === 'error' ? status.error ?? 'not connected' : 'needs user approval') + .replace(/\s+/g, ' ').trim() || 'not connected' + lines.push(`- ${name} (${kinds.get(name) ?? 'capability'}): ${reason} — tell the user before acting.`) + } + if (lines.length === 0) return '' + return ['# Capabilities that need attention', ...lines].join('\n') + } + ctx.effect(() => ctx.systemPrompt.section({ name: 'bot-identity', order: 640, interpolate: false, text: context => promptFor(context?.agent?.id), }), 'ds-bot: identity section') + + ctx.effect(() => ctx.systemPrompt.section({ + name: 'bot-capabilities', + order: 700, + interpolate: false, + text: context => capabilitiesFor(context?.agent?.id), + }), 'ds-bot: capability section') } diff --git a/core/test/capabilities.test.js b/core/test/capabilities.test.js index bb5f79f81..3e17153d6 100644 --- a/core/test/capabilities.test.js +++ b/core/test/capabilities.test.js @@ -466,3 +466,54 @@ test('a capability description is cut at 2000 without splitting an emoji', async assert.ok(description.startsWith(kept), 'a code-point prefix of the description the peer sent') assert.ok(kept.length <= 2000, 'the budget of 2000 UTF-16 units is unchanged') }) + +// #3273, from the security read at 6b401ebb: an inline credential in a URL is a shape +// `redactSecrets` cannot know (it replaces saved key values), so the host refuses it on the way in +// and masks userinfo on the way out — the string never reaches a status line, and therefore never +// reaches the system prompt section that prints one. +const USERINFO_REFUSAL = 'Enter the URL without a username or password. Save the credential as a secret and reference it in a header.' + +test('a capability URL that carries a username or password is refused, and nothing is stored', async t => { + const env = await setup() + t.after(() => env.dispose()) + const { rt } = env + for (const url of ['https://alice:s3cr3t-pa55@host/mcp', 'https://alice@host/mcp']) { + await assert.rejects( + rt.capabilitySave({ ...mcp('inline'), transport: 'streamable-http', url }, { ui: true }), + error => error.message === USERINFO_REFUSAL, + ) + } + assert.equal(rt.state.capabilities.items.inline, undefined, 'a refused save leaves no item') + assert.equal(JSON.stringify(rt.state).includes('s3cr3t-pa55'), false) +}) + +test('an error that quotes a URL saved before this fix stores it with the userinfo masked', async t => { + const state = team() + state.capabilities = { + items: { + inline: { + name: 'inline', kind: 'mcp', description: 'Saved before the refusal', transport: 'streamable-http', + url: 'https://alice:s3cr3t-pa55@host/mcp', headers: {}, approved: true, createdBy: 'worker', createdAt: 1, updatedAt: 1, + }, + }, + } + const env = await setup({ state }) + t.after(() => env.dispose()) + const { ctx, rt, mounts, skills } = env + await rt.changeCapabilityAttachment('attach', { name: 'inline' }, 'worker') + const quoted = 'Request cannot be constructed from a URL that includes credentials: https://alice:s3cr3t-pa55@host/mcp' + ctx.emit('agent/created', { agent: testAgent('worker', mounts, skills, { awaitMount: async () => { throw new TypeError(quoted) } }) }) + await rt.scheduleCapabilitiesReconcile() + const status = rt.capabilityStatusesView().worker.inline + assert.equal(status.state, 'error') + assert.equal(status.error, 'Request cannot be constructed from a URL that includes credentials: https://host/mcp', 'the exact stored sentence: the scheme and host stay, the userinfo is gone') + assert.equal(JSON.stringify(rt.capabilityStatusesView()).includes('s3cr3t-pa55'), false) +}) + +test('a plain HTTPS URL still saves', async t => { + const env = await setup() + t.after(() => env.dispose()) + const saved = await env.rt.capabilitySave({ ...mcp('plain'), transport: 'streamable-http', url: 'https://host/mcp' }, { ui: true }) + assert.equal(saved.url, 'https://host/mcp') + assert.equal(env.rt.state.capabilities.items.plain.url, 'https://host/mcp') +}) diff --git a/core/test/install.test.js b/core/test/install.test.js index 0b6fe2fc9..dd6791070 100644 --- a/core/test/install.test.js +++ b/core/test/install.test.js @@ -51,6 +51,8 @@ test('apply registers listeners, tools, and effects in a fixed order', (t) => { 'on agent/created', 'effect ds-bot: identity section', 'prompt bot-identity 640', + 'effect ds-bot: capability section', + 'prompt bot-capabilities 700', 'on agent/pre-step (prepend)', 'tool list_bots', 'tool message_bot', diff --git a/core/test/prompt.test.js b/core/test/prompt.test.js index 4a0902d9c..aa537aef4 100644 --- a/core/test/prompt.test.js +++ b/core/test/prompt.test.js @@ -3,11 +3,11 @@ import { test } from 'node:test' import { install } from '../src/host/prompt.js' import { fakeContext } from './fake-ctx.js' -function start() { +function start({ statuses = {}, library = [] } = {}) { const ctx = fakeContext() const bots = new Map([ - ['main', { name: 'Chief' }], - ['worker', { name: 'Dev', instructions: 'Check files.' }], + ['main', { id: 'main', name: 'Chief' }], + ['worker', { id: 'worker', name: 'Dev', instructions: 'Check files.' }], ]) install({ ctx, @@ -15,9 +15,19 @@ function start() { botOf: id => bots.get(id), roomOf: id => id === 'room' ? {} : undefined, isMain: id => id === 'main', + capabilityStatusesView: () => statuses, + capabilityLibraryView: () => library, }) const prompt = id => ctx.sections.get('bot-identity').text({ agent: { id } }) - return { ctx, prompt } + // The host's own join: sections in order, empty ones dropped, one blank line between + // (dsh-system-prompt renderSections). Rendering here keeps the byte-level assertion real. + const render = id => [...ctx.sections.values()] + .sort((a, b) => a.order - b.order) + .map(section => section.text({ agent: { id } })) + .filter(text => text.length > 0) + .join('\n\n') + const capabilities = id => ctx.sections.get('bot-capabilities')?.text({ agent: { id } }) + return { ctx, prompt, render, capabilities } } test('Bots get a scoped progress rule without changing the private/group prompt prefix', (t) => { @@ -80,3 +90,115 @@ test('a Bot stays idle until it is addressed or given a task (part B of #645)', const replyRule = '- When a "[Reply from …]" arrives, tell the user the outcome if it matters to them.' for (const id of ['main', 'worker']) assert.ok(prompt(id).split('\n').includes(replyRule), `${id} still answers a reply`) }) + +// #3273: a Bot must not promise work for one of its own capabilities that cannot be reached. +// The identity section stays byte-stable (the prompt prefix is cached), so the state lives in a +// second section that renders to nothing whenever every attached capability is usable. +test('#3273: a capability whose connection failed is named before the Bot acts', (t) => { + const { ctx, render, prompt, capabilities } = start({ + statuses: { worker: { github: { state: 'error', error: '401 bad credentials' } } }, + library: [{ name: 'github', kind: 'mcp' }], + }) + t.after(() => ctx.dispose()) + const text = render('worker') + assert.equal(capabilities('worker').split('\n')[0], '# Capabilities that need attention', 'the section carries its own title, so the list is not read as a continuation of the identity block') + assert.equal(capabilities('worker').split('# Capabilities that need attention').length - 1, 1, 'one title, once') + assert.ok( + text.split('\n').includes('- github (mcp): 401 bad credentials — tell the user before acting.'), + `the failed capability and its reason are on one line:\n${text}`, + ) + assert.equal(text.slice(0, prompt('worker').length), prompt('worker'), 'the identity section is untouched') + assert.doesNotMatch(prompt('worker'), /401 bad credentials/, 'the identity section stays byte-stable') +}) + +test('#3273: a capability waiting for the user is named the same way', (t) => { + const { ctx, render } = start({ + statuses: { worker: { github: { state: 'needs-approval' } } }, + library: [{ name: 'github', kind: 'mcp' }], + }) + t.after(() => ctx.dispose()) + const text = render('worker') + assert.ok( + text.split('\n').includes('- github (mcp): needs user approval — tell the user before acting.'), + `the unapproved capability asks the Bot to say so first:\n${text}`, + ) +}) + +test('#3273: only the capabilities that are not usable are listed, ready ones are silent', (t) => { + const { ctx, capabilities } = start({ + statuses: { + worker: { + github: { state: 'error', error: '401 bad credentials' }, + linear: { state: 'ready' }, + slack: { state: 'needs-approval' }, + }, + }, + library: [{ name: 'github', kind: 'mcp' }, { name: 'linear', kind: 'mcp' }, { name: 'slack', kind: 'pack' }], + }) + t.after(() => ctx.dispose()) + const listed = capabilities('worker').split('\n').filter(line => line.startsWith('- ')) + assert.deepEqual(listed, [ + '- github (mcp): 401 bad credentials — tell the user before acting.', + '- slack (pack): needs user approval — tell the user before acting.', + ]) +}) + +// Test found by mutation that a healthy render compared only against another render of the same +// code proves nothing: a trailing space added to the identity text passes both sides. The claim is +// that the healthy prompt *is* the identity text, so its exact head and its exact last line are +// pinned here as literals, and the capability section has to contribute the empty string. +const IDENTITY_LAST_RULE = '- When you cannot continue without an answer, pass ask with the one question on that task. On a group card, worked in your own chat, call ask_user for the user, and post one short question in the group only when a person there has to decide. On your own chat\'s other tasks, ask_user. When the answer arrives, pass answer with what they said and update the task. Do not leave the task waiting without that question.' +const IDENTITY_HEADS = { + main: "# Your identity\nYou are Chief, a Bot on the user's team in FlyBot.", + worker: "# Your identity\nYou are Dev, a Bot on the user's team in FlyBot.", +} + +test('#3273: a healthy Bot renders exactly the prompt it renders today', (t) => { + const healthy = start({ statuses: { main: {}, worker: { github: { state: 'ready' } } }, library: [{ name: 'github', kind: 'mcp' }] }) + const none = start() + t.after(() => healthy.ctx.dispose()) + t.after(() => none.ctx.dispose()) + assert.deepEqual([...healthy.ctx.sections.keys()].sort(), ['bot-capabilities', 'bot-identity']) + assert.equal(healthy.ctx.sections.get('bot-identity').order, 640) + assert.equal(healthy.ctx.sections.get('bot-capabilities').order, 700) + for (const id of ['main', 'worker']) { + assert.equal(healthy.capabilities(id), '', 'nothing unhealthy renders no section text at all') + const text = healthy.render(id) + assert.ok(text.startsWith(IDENTITY_HEADS[id]), `${id}: the rendered prompt starts on the identity title and the Bot's own line, byte for byte`) + assert.ok(text.endsWith(IDENTITY_LAST_RULE), `${id}: the rendered prompt ends on the last identity rule — no separator, no blank line, no trailing space`) + assert.equal(text.trimEnd(), text, `${id}: no trailing whitespace`) + assert.equal(healthy.render(id), none.render(id), 'byte for byte the prompt a Bot with no capabilities gets') + assert.equal(none.render(id), none.prompt(id), 'the rendered prompt is the identity section alone — no extra section, no blank line') + } + // A relay session is not a Bot: it never carries capability state. + assert.equal(healthy.render('room'), healthy.prompt('room')) +}) + +test('#3273: one Bot never sees another Bot\'s capability state, and a failure is whole-Bot', (t) => { + const { ctx, capabilities, render } = start({ + statuses: { + main: { github: { state: 'ready' } }, + worker: { github: { state: 'error', error: '401 bad credentials' } }, + }, + library: [{ name: 'github', kind: 'mcp' }], + }) + t.after(() => ctx.dispose()) + assert.equal(capabilities('main'), '', 'the Chief sees no line for a Worker capability that is down') + assert.equal(render('main').includes('401 bad credentials'), false) + assert.ok(capabilities('worker').includes('- github (mcp): 401 bad credentials'), 'the Bot whose capability is down sees it') + // The status view aggregates per Bot across its Sessions, the same way list_capabilities does: + // a failure reached in one Session is the whole Bot's failure, so the group Session reads it too. + assert.equal(render('group-worker'), render('worker')) +}) + +test('#3273: an error with no reason still reads as a sentence', (t) => { + const { ctx, capabilities } = start({ + statuses: { worker: { github: { state: 'error', error: ' ' }, linear: { state: 'error', error: '' } } }, + library: [{ name: 'github', kind: 'mcp' }, { name: 'linear', kind: 'mcp' }], + }) + t.after(() => ctx.dispose()) + assert.deepEqual(capabilities('worker').split('\n').filter(line => line.startsWith('- ')), [ + '- github (mcp): not connected — tell the user before acting.', + '- linear (mcp): not connected — tell the user before acting.', + ], 'an empty or whitespace-only reason becomes "not connected", never a dangling dash') +}) diff --git a/core/test/settings-error-placement.test.js b/core/test/settings-error-placement.test.js index ef0bd509d..459b3cc41 100644 --- a/core/test/settings-error-placement.test.js +++ b/core/test/settings-error-placement.test.js @@ -101,7 +101,7 @@ test('a refused write in Settings stays in view instead of scrolling away with t assert.equal(inside(alert, scrolling), false, 'the refusal must sit outside the scrolling page, not above it') }) -// #3114 cut 31: the Capabilities form and the six fixed refusals its save can leave. The page +// #3114 cut 31: the Capabilities form and the fixed refusals its save can leave. The page // already draws `t(label)` (capability-settings.js:19) and the host sentence is translated before it // is thrown (api.js:38), so the dictionary is the only place these cases can be red. const REFUSALS = [ @@ -109,6 +109,9 @@ const REFUSALS = [ '能力名只能用小写字母、数字和单个连字符;「github」和「composio」是保留名。'], ['Enter a command for the MCP server.', '请填写 MCP 服务器的命令。'], ['Enter a valid HTTP or HTTPS URL.', '请填写有效的 HTTP 或 HTTPS 地址。'], + // #3273: the seventh refusal, from the security read at 6b401ebb. + ['Enter the URL without a username or password. Save the credential as a secret and reference it in a header.', + '地址里不要写用户名或密码。请把凭据保存为密钥,并在请求头里引用它。'], ['A capability cannot change its kind. Delete it and save a new one.', '能力类型不能改。请删掉它,再新建一个。'], ['Environment variables must contain text values.', '环境变量里只能填文本值。'], ['Headers must contain text values.', '请求头里只能填文本值。'], diff --git a/docs/subsystems/core-host.md b/docs/subsystems/core-host.md index 5248547eb..4606a64e9 100644 --- a/docs/subsystems/core-host.md +++ b/docs/subsystems/core-host.md @@ -40,7 +40,7 @@ The server side of the patched `ds-bot` core (`core/`): the part of [ds-bot-core | `core/src/host/` | Host-side helpers (non-hooks). | | `core/src/host/plugins.js` | The five feature plugins' catalogue and the owner's switch for each (#2564): `FEATURE_PLUGINS` (id, name, package, purpose) and `pluginSwitches(state, bundles)` answer the rows Settings shows — `enabled` on unless `state.json` says off. `installed` is a second fact, read from the profile's `dsh.profile.bundles` through `profileBundles(profileDir)` (#2868): a switch can be on for a package this profile never got, and then the domain really is absent from the process, so the row says `installed: false` and the reader looks at that first. A host with no profile (`profileBundles` answers `undefined`) keeps the old row shape instead of claiming a plugin is missing, and an unreadable profile does the same. `setPluginSwitch` writes one known id, and flips apply at the next start (`pluginEnabledAtStart`, which reads through the same snapshot). `pluginSwitchesAtStart` reads all five from the file once at install and `pluginSwitchesPending` compares each switch with it, so `plugins/list` and `plugins/set` answer `pendingRestart` from the difference — turning a switch back to the value this start loaded clears it, since the next start would load exactly what this one did. Tests: `core/test/plugin-switches.test.js`, `core/test/plugins-list-installed.test.js`. | | `core/src/host/text.js` | The pure text helpers the host modules share: message text, names, model refs, cutting and estimating text, and the clock format of chat anchors. Since #1895 `codePoints(text)` (a step per code point, no array built since #1898) is how the host counts a limit — one character costs one whatever its UTF-16 width — and the bounds this change puts through it are: a memory entry of 300 and a `MEMORY.md` of 4,000 or a topic of 16,000 (the refusal and the size note print the code-point number), a scheduled task's name of 120, a message of 20,000, and the Project memory entry of 600 in both writers, so an emoji is never charged twice. Both cuts land on a code point boundary: `clip` and `excerpt` move back rather than keep half of a surrogate pair, so a clipped emoji reaches a UTF-8 encoder as the character and not as U+FFFD ([#1907](https://github.com/ThinkFlowLab/FlyBot/issues/1907)). Since #1912 that rule is one exported helper rather than a private detail: `cut(text, max)` answers `{ text, cut }` with the longest prefix that stops before a split pair, and the archive writers that used to `slice(0, max)` go through it — the `oneLine` of `decisions.js` and `meetings.js` (into `decisions.jsonl` and `decisions/-.md`), `claimLine` in `groups.js`, the report cap in `diagnostics.js`, `cleanLabel` in `flybot-feed.js` and `clean` in `browser.js` — so a decision or a meeting record holds the whole character instead of U+FFFD. Since #1916 the boundary rule itself lives in `core/src/shared/text-boundary.js` (`codePointStart`, `codePointEnd`, `cut`), and `host/text.js` builds its `cut` on it so a shared module can bound text too; the eight remaining `slice(0, max)` writers follow it — the claim cue's fallback reference (60), the task lead's name in a member prompt (80), a failed group Session's error text (300), `read_own_chat`'s `query` (80) and `around` (40), the open-page address and title (2000/300), the diagnostics browser-log line and its code (500/40), and `cleanPeerName` in `shared/remote-label.js` (60) — each keeping the longest prefix that stops before a split pair, `length <= max` and a byte prefix of the input. Since #1918 the memory review's own two bounds go through the same rule: its 800-character context `clip` cuts through `cut`, and its 3,000-character two-ended `ends` spends the budget in characters at both ends — `charIndex` steps whole code points to find the head's end and the tail's start, so the head is the rendered line's first 2,000 characters and the tail its last 1,000, and the text is flattened with `toWellFormed()` first as `cut` did — so the prompt and the log hold whole characters within the same character budget: a line of 3,500 emoji keeps 3,000 characters where unit arithmetic kept 1,503 ([#2553](https://github.com/ThinkFlowLab/FlyBot/issues/2553)); the exported `clip`'s reason is optional there too, so a two-argument call reads `… (cut)` instead of `… (cut; undefined)` while a call with a reason is unchanged. Since #1923 the four bounds whose text crosses an owner boundary go through the same `cut` — `cleanPublishedName` in `hooks.js` (60, into `state.flybot.remote`), the group member line's `displayName` 60 and `ownerName` 40 in `tools.js`, `label` in `reach.js` (60, the `othersInRoom` labels), and the local `clip` in `shared/room-share.js` (its per-field caps included) — so a published, listed or relayed name keeps whole characters and never reaches a UTF-8 encoder as U+FFFD ([#1923](https://github.com/ThinkFlowLab/FlyBot/issues/1923)). The same rule now covers the host's own line bounds: the busy ack's 600-unit task and 1,500-unit message text in `busy-ack.js`, the group line's notice (100), a Bot's job line (120), the group answer echo (300) and the rework line's note (200) in `tools.js`, and `cleanName`'s 60-unit peer name in `delivery.js`, which lands in `fenceUntrusted`'s `from="…"` attribute — so none of them can end in half a surrogate pair. The five bounds `turns.js` keeps go through `cut` as well: a failure's 500-unit message and the 200-unit message of its line (`turnFailure`, `failureLine`), the 79-unit step a running call shows (the `…` is appended only when `cut` dropped something, never by a length guess), an approval card's 2,000-unit description and 4,000-unit command (the card stores the command "Allow once" runs rather than a preview of it, and one that still had to be cut ends with `…` inside that bound, so the card says what it abridged and never drops the fact, [#1992](https://github.com/ThinkFlowLab/FlyBot/issues/1992)), and the 160-unit reason a failed turn leaves for the inbox. Since #1963 `cut` also flattens its input before it bounds — `String(text).toWellFormed()` first, `codePointEnd` on the flat string — so a title, a note or a name that arrives already carrying an unpaired surrogate is stored as U+FFFD instead of the lone surrogate, and U+FFFD is one UTF-16 unit for the one it replaces, so a well-formed input keeps its exact prefix and its `cut` flag ([#1963](https://github.com/ThinkFlowLab/FlyBot/issues/1963)). Since #1979 the six remaining bounds on text another home or another person supplied go through it too — a connector item name (80, `connectors.js`), a role label another home set on a face-room seat (80, `face-lead.js`), a cross-home group name (200, `project-team.js`), a capability description from a peer server (2,000, `capabilities.js`), the remote home's own error text (157, `remote-chat.js`) and an abbreviated remote reply (80, same file) — so each keeps the longest prefix that stops before a split pair, is well formed and is a code-point prefix of the input, while `remote-chat.js`'s `…` and trailing-period strip still apply to the cut value ([#1979](https://github.com/ThinkFlowLab/FlyBot/issues/1979)). The two bounds on a friend's Bot's own name in that file — the name its chat is created with (40) and the name a refresh writes (40) — go through `cut` as well, so a refresh cannot store a lone high surrogate and a create no longer hands `roster.createBot` half a pair to flatten into U+FFFD; the budget stays 40 and a shorter name is stored word for word. Since #1993 the last five bounds in `core/src/host/` go through it too — the quoted first line of a checkpoint's kept tail (80, `steward.js`), an approval record's `reason` (500, `approvals.js`), a mention receipt's reason line (240, `hooks.js`), the title given to a DSH Agent's Session (80, `AGENT_SESSION_TITLE_MAX` in `agents.js`) and a schedule run's failure `reason` (200, `schedules.js`) — so each keeps the longest prefix that stops before a split pair, is well formed and is a code-point prefix of the input, and none of the five maxima changes ([#1993](https://github.com/ThinkFlowLab/FlyBot/issues/1993)). Since #2002 the connector's own error text goes through it too: the `reason` in `core/src/host/connectors.js` — the text an MCP server's failure leaves on the owner's connector card — keeps the longest prefix that stops before a split pair, so it is well formed and a code-point prefix of what the server sent; since #2016 that prefix is 2,000 units rather than 300, and one that had to be cut ends with `…` inside the bound, so the card says what it abridged ([#2002](https://github.com/ThinkFlowLab/FlyBot/issues/2002), [#2016](https://github.com/ThinkFlowLab/FlyBot/issues/2016)). Since #2005 the five bounds the Project panels read go through it as well — the assistant card's 77-unit title in `project-assistant.js`, the board's 200-unit one-line value and a decision title's 200 in `project-board.js`, and `capped`'s name, role, persona, model and color caps plus the dossier's 4,000-unit memory head in `project-team.js`, whose head is bounded where `memoryDigest` reads it (`memory.js`), because a cut at the dossier alone could only turn half a pair into U+FFFD and never drop the character whole — so a dossier row or a board card keeps whole characters ([#2005](https://github.com/ThinkFlowLab/FlyBot/issues/2005)). Since [#2321](https://github.com/ThinkFlowLab/FlyBot/issues/2321) a bound also judges in code points, not only counts in them: `fits(text, max)` in `core/src/shared/text-boundary.js` is the one predicate — a character outside the BMP spends one of the budget and not two — and `clip` and `excerpt` judge with it while their cuts keep going through `codePointEnd`/`cut`, so a 300-character text is no longer cut by a 400-character limit on its way to `read_own_chat` and the search rows. Since [#2339](https://github.com/ThinkFlowLab/FlyBot/issues/2339) the two bounds in `core/src/host/` that still judged with `text.length` use it as well — the memory review's 3,000-character two-ended `ends` in `memory.js` and `room-context.js`'s `oneLine` (40/80/24/60) — so a user line or a board line of characters outside the BMP stays whole inside its own limit instead of being cut at half of it; both maxima are unchanged and a board line's cut stays on `cut`, so an ASCII text judges exactly as `length <= max` did. The memory review's own third `clip` is the exported one now, so its cut reads `… (cut)`, and a bound added later that judges with `text.length` fails `core/test/text-bounds.test.js` at its own `file:line`. Both render paths of the memory review flatten before they bound as well: the `fits()` answer of `ends` and the labelled Bot line on its way to `clip` pass through `toWellFormed()` first, so an unpaired surrogate that arrives in a message reaches the review prompt as U+FFFD, whole and in place, instead of as half a pair ([#2556](https://github.com/ThinkFlowLab/FlyBot/issues/2556)). Since [#2691](https://github.com/ThinkFlowLab/FlyBot/issues/2691) `normalize` is the one identity key for a name: it NFC-normalizes, drops the Unicode format characters (`\p{Cf}` — zero-width space / non-joiner / joiner, the byte-order mark, soft hyphen, the bidi controls) that `trim()` keeps, trims, lowercases and NFC-normalizes again, so either canonical spelling of one visible name is one key; `findBot` and `findRooms` compare with it, the duplicate guards in `roster.js` ask those same finds, and `createBot`, `updateBot` and `cleanRoomName` store the visible form (the format characters stripped before the 40 / `ROOM_NAME_MAX` cut) while `shared/mentions.js` `nameProblem` refuses a name that is only invisible characters. A name already in `state.json` is never rewritten: the key is computed from what is stored, so an old NFD name still resolves. Since [#2692](https://github.com/ThinkFlowLab/FlyBot/issues/2692) that one key is `nameKey` in `core/src/shared/identity.js` (`normalize` in `host/text.js` is it, so the host, a shared module and the browser bundle cannot drift apart), and three identity sites that used their own `trim().toLowerCase()` compare with it: `shared/task-board.js` `sameRole` — a member's role label and a queued card's `queueRole`, so a card reaches the carrier whose label spells the same role the other way instead of staying in the pool — and `memory.js`'s topic, where the key is also the file stem: `cleanTopic` answers the key, a topic file already on disk keeps the spelling it was written with (the key is computed from the name, so a file `가.md` is still topic `[[가]]` and remember appends to that same file), the file already in key form wins when both spellings exist, and the `## Index` link check and the link a delete removes both compare by key rather than by the text that was written. A decomposed Latin topic, refused while U+0301 was not a `\p{L}`, is accepted as its NFC form. `plugins/tree` keeps its own copy of the same function (`src/identity.js`) because it ships as its own package, and `plugins/tree/test/identity.test.js` holds the two to the same answers. Since [#2935](https://github.com/ThinkFlowLab/FlyBot/issues/2935) a name also has a drawn form: `drawnKey` in the same `shared/identity.js` is `nameKey` with the characters `shared/mentions.js` exports as `NOT_DRAWN` removed — an explicit list of the code points with no glyph of their own (the combining grapheme joiner, the Hangul fillers, the braille blank, the Mongolian free variation selectors and the variation selectors), never the whole `\p{Mn}` class, because a combining mark is drawn by the letter under it and `กิ`/`กี` are two names — so `Dev` written with a trailing U+034F has the drawn form `dev` while its key stays `dev\u034f`. `roster.js` compares it in `createBot` and `updateBot` beside the key, so a second row that reads `Dev` and that no `@Dev` can reach is refused, from either side, with the sentences already in use (`A Bot named … already exists` / `Name … is not available`). Since [#2986](https://github.com/ThinkFlowLab/FlyBot/issues/2986) the stored name also folds a run of whitespace to one plain space — `foldSpaces` in `host/text.js`, used by `createBot` and `updateBot` before the 40-character cut and by the store when a saved team is loaded, the way `cleanRoomName` folds a group's name — because every name row draws with `white-space: nowrap`, so `Dev Ops` and `Dev Ops` are one row on screen while `nameKey` keeps them apart and `@Dev Ops` reaches only the single-space Bot. `Dev Ops` is therefore stored as `Dev Ops`, and the existing sentences refuse it while that name exists (`A Bot named … already exists` / `Name … is not available`); a line break is not folded, because `nameProblem` refuses it by name. A team saved before that fold kept its run, so `load()` folds `bots[].name` once, before the room names derived from the roster are rebuilt: when the folded name is one another Bot already holds, it is left as it was saved and one warning line names that Bot, because renaming a Bot the user can see is worse than the twin; the drawn-form guard `drawnClash` folds both sides too, so no new twin can be created beside a saved one. Nothing is stripped from the stored name and a drawn form nobody holds is still a name, so `#2879`'s guard and a blank beside drawn characters are unchanged. Tests: `core/test/name-identity.test.js`, `core/test/memory.test.js`, `core/test/bot-tasks.test.js`. | -| `core/src/host/prompt.js` | The Bot system prompt; a Main Bot's section is headed `You are the Main Bot` and uses that one term, the one the UI shows (#276). The team rules state the idle default (#699): a Bot does nothing until the user addresses it, it is @-mentioned in a group, its parent gives it a task, or unfinished tasks it was already given are still on its board. It does not invent work. A coordinator acts on a user task rather than on its own initiative — an addressed Bot answers as before. | +| `core/src/host/prompt.js` | The Bot system prompt; a Main Bot's section is headed `You are the Main Bot` and uses that one term, the one the UI shows (#276). The team rules state the idle default (#699): a Bot does nothing until the user addresses it, it is @-mentioned in a group, its parent gives it a task, or unfinished tasks it was already given are still on its board. It does not invent work. A coordinator acts on a user task rather than on its own initiative — an addressed Bot answers as before. A second section (`order: 700`) tells the Bot which of its own attached capabilities cannot be used right now: one `- (): — tell the user before acting.` line for each capability in state `error` or `needs-approval`, built from `capabilityStatusesView()`, and an empty string while every capability is ready, so a healthy Bot's cached prompt prefix does not move (#3273). The identity section stays byte-stable: capability state never goes into it. A reason is one line: whitespace folded, and an empty one reads `not connected` (#3273). Because that line is printed every turn, a URL carrying userinfo is refused on save in `capabilities.js` (`Enter the URL without a username or password…`, says the credential belongs in a secret referenced by a header) and a stored transport error of a capability saved before that refusal has its userinfo masked before the 300-character cut, so neither half of the credential reaches the prompt (#3273). | | `core/src/host/health.js` | `GET /api/health` (#2128, P-392): the one answer this instance gives without a session, and exactly four fields — `ok` (always `true`), `version` (`core/package.json`), `commit` (`git rev-parse HEAD` of the clone `core/` sits in, `null` for a package or path install with no `.git`) and `startedAt` (this process's start, from `process.uptime()`, stable until a restart). It is an **exact** WebServer route, which the web server matches before the `/api` prefix whose admission is the sign-in wall, so no cookie is needed and no other `/api` route changes; outside the Web composition there is no `webServer` and the route does not exist. A method other than `GET` answers 405. Tests: `core/test/health.test.js`. | | `core/src/host/models.js` | The model surface: the provider catalog with its short caches (#409), a Bot's desired model and thinking level, the Session rebinding a group needs, and the connection test (`rt.testModel`). Every model call crosses the `llm/stream` listener installed here, which clamps an outbound output cap to 12288 (#3132) on the DashScope route alone — the `opencsitool` DSH route key whose proxy refused more (#3198), so every other provider takes the caller's request or its row's declared cap untouched: a model row may declare more than a provider endpoint accepts, and a request above that ceiling is refused whole by DashScope with a 400 (`max_completion_tokens … expected a value <= 12288`), so the step loses an answer it would otherwise give. A cap at or under the ceiling, a model that declares none, and a caller with no cap are passed through untouched — the clamp lowers a cap and never raises or invents one — and the request is re-entered with a copy rather than written to, because DSH compares a prepared call's config (`INVALID_PREPARED_CALL`). Tests: `core/test/llm-output-cap.test.js`, `core/test/install.test.js`. | | `core/src/host/room-membership.js` | Typed room participants (human / local bot / granted remote), authorship, membership-window history (#50); rooms with friends' Bots or other owners take granted local Bots only and evict a Bot that stops qualifying (#90). Face-to-face rooms (#83) reuse this model (`origin: 'face-to-face'`, room-only remotes without a person-grant, `upsertFaceRoom` / `syncFaceParticipants` / `applyFaceRoomLine`); a face-room local Bot is `viaCode` (brought by number), `evictUnshared` skips face rooms (membership is the server's), and a Bot that returns to the member list drops the empty local `left` line (#236). Refusing an ungranted local Bot next to a friend's Bot throws `ungrantedRefusal`: a message that names the Bot, the friend and the two ways out, plus `error.details` `{ reason: 'ungranted-local', bots, remotes }`; `channel.js` `fail` forwards a plain-object `details` (empty otherwise) and `client/api.js` puts it on the thrown error, where `client/new-chat.js` draws a card (**Copy invite link for {Bot}** via `__flybot__.social.createInvite`, **Leave {Bot} out**) read through `ungrantedLocalFix` in `shared/remote-label.js`; the same file's `copiedToClipboard` reports whether the invite link really reached the clipboard (none, or a refused write, is `false`), and the card then shows the link to copy by hand instead of saying it was copied. | diff --git a/patches/ds-bot/0001-core-fixes.patch b/patches/ds-bot/0001-core-fixes.patch index e7217d38d..ce5fabf66 100644 --- a/patches/ds-bot/0001-core-fixes.patch +++ b/patches/ds-bot/0001-core-fixes.patch @@ -2120,7 +2120,7 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js 'The admin must be a member of the group': '管理员必须是群成员', 'Unknown group chat': '找不到这个群聊', 'Hand the admin role to another member instead of leaving the group without one': '请把管理员交给其他成员,不要让群聊没有管理员', -@@ -905,6 +905,78 @@ const HOST_ZH = { +@@ -905,6 +905,81 @@ const HOST_ZH = { 'Write the entry to save.': '请写下要保存的内容。', 'This DeepSeek Harness has no folder chooser': '这个 DeepSeek Harness 没有文件夹选择窗口', 'This DeepSeek Harness cannot list folders': '这个 DeepSeek Harness 不能列出文件夹', @@ -2193,6 +2193,9 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js + 'Use a capability name with lowercase letters, digits, and single hyphens; "github" and "composio" are reserved.': '能力名只能用小写字母、数字和单个连字符;「github」和「composio」是保留名。', + 'Enter a command for the MCP server.': '请填写 MCP 服务器的命令。', + 'Enter a valid HTTP or HTTPS URL.': '请填写有效的 HTTP 或 HTTPS 地址。', ++ // #3273: a URL carrying userinfo is refused instead of stored, so the credential never reaches ++ // a status line and never reaches the system prompt. ++ 'Enter the URL without a username or password. Save the credential as a secret and reference it in a header.': '地址里不要写用户名或密码。请把凭据保存为密钥,并在请求头里引用它。', + 'A capability cannot change its kind. Delete it and save a new one.': '能力类型不能改。请删掉它,再新建一个。', + 'Environment variables must contain text values.': '环境变量里只能填文本值。', + 'Headers must contain text values.': '请求头里只能填文本值。', @@ -4541,6 +4544,18 @@ diff --git a/src/host/capabilities.js b/src/host/capabilities.js } return name } +@@ -33,6 +33,11 @@ export function expandCapabilityNames(capabilities, library) { + return expanded + } + ++// #3273: `redactSecrets` replaces saved key values, so a password written into a URL is a shape it ++// cannot know. A transport error quotes that URL back verbatim, and the status line reaches the ++// system prompt every turn, so userinfo is dropped before the sentence is stored. ++const withoutUserinfo = text => text.replace(/([a-z][a-z0-9+.-]*:\/\/)[^/\s@]+@/gi, '$1') ++ + const same = (a, b) => JSON.stringify(a) === JSON.stringify(b) + const strings = value => { + if (value === undefined) return [] @@ -92,7 +92,7 @@ export function install(rt) { const item = { name, @@ -4550,6 +4565,21 @@ diff --git a/src/host/capabilities.js b/src/host/capabilities.js createdBy: previous?.createdBy ?? (ui ? null : botId), createdAt: previous?.createdAt ?? now, updatedAt: now, +@@ -109,10 +109,10 @@ export function install(rt) { + Object.assign(item, { transport, command, args, env, approved: ui ? true : changed ? false : previous.approved === true }) + } else { + const url = String(body.url ?? '').trim() +- try { +- const parsed = new URL(url) +- if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') throw new Error() +- } catch { throw new Error('Enter a valid HTTP or HTTPS URL.') } ++ let parsed ++ try { parsed = new URL(url) } catch { throw new Error('Enter a valid HTTP or HTTPS URL.') } ++ if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') throw new Error('Enter a valid HTTP or HTTPS URL.') ++ if (parsed.username !== '' || parsed.password !== '') throw new Error('Enter the URL without a username or password. Save the credential as a secret and reference it in a header.') + Object.assign(item, { transport, url, headers: stringMap(body.headers, 'Headers'), approved: true }) + } + } else if (kind === 'skill') { @@ -139,7 +139,7 @@ export function install(rt) { await rt.load() writeCheck() @@ -4581,6 +4611,16 @@ diff --git a/src/host/capabilities.js b/src/host/capabilities.js } const mountOne = async (agent, bot, agentMounts, name) => { const sessionId = agent.session.id +@@ -308,7 +308,8 @@ export function install(rt) { + statusSet(bot.id, name, sessionId, { state: 'ready' }) + } catch (error) { + await drop() +- const message = rt.redactSecrets([error, error?.cause].filter(Boolean).map(part => String(part?.message ?? part)).join(': ') || 'Connection failed').slice(0, 300) ++ const joined = [error, error?.cause].filter(Boolean).map(part => String(part?.message ?? part)).join(': ') || 'Connection failed' ++ const message = withoutUserinfo(rt.redactSecrets(joined)).slice(0, 300) + statusSet(bot.id, name, sessionId, { state: 'error', error: message }) + } + } @@ -454,7 +454,7 @@ export function install(rt) { if (endpoint === 'capability-approve') { await rt.load() @@ -8248,7 +8288,14 @@ diff --git a/src/host/models.js b/src/host/models.js diff --git a/src/host/prompt.js b/src/host/prompt.js --- a/src/host/prompt.js +++ b/src/host/prompt.js -@@ -4,33 +4,46 @@ +@@ -1,36 +1,51 @@ +-// Prompt: one section whose text depends only on the rendering Session's own Bot +-// record, so the prefix stays byte-stable across turns and roster changes. ++// Prompts: two sections. The identity section's text depends only on the rendering ++// Session's own Bot record, so the cached prefix stays byte-stable across turns and roster ++// changes. The capability section names the attached capabilities that cannot be used right ++// now; it renders to nothing while every one of them is ready. + const TEAM_RULES = [ '## How your Bot team works', '- Every Bot is its own long-lived conversation with the user, with its own memory and computer.', @@ -8313,6 +8360,47 @@ diff --git a/src/host/prompt.js b/src/host/prompt.js '', rt.isMain(self) ? `${MAIN_RULES}\n\n${TEAM_RULES}` : TEAM_RULES, ].join('\n') +@@ -62,10 +62,40 @@ export function install(rt) { + return '' + } + ++ // #3273: the Bot has to learn about a broken capability from its own prompt, not after it ++ // has already promised the work and the first call fails. Only the two states the user can ++ // act on are named; everything else (ready, connecting) renders to nothing. ++ const capabilitiesFor = (id) => { ++ const self = rt.selfOf(id) ++ const bot = rt.botOf(self) ++ if (bot === undefined) return '' ++ const statuses = (rt.capabilityStatusesView?.() ?? {})[bot.id] ?? {} ++ const kinds = new Map((rt.capabilityLibraryView?.() ?? []).map(item => [item.name, item.kind])) ++ const lines = [] ++ for (const [name, status] of Object.entries(statuses)) { ++ if (status.state !== 'error' && status.state !== 'needs-approval') continue ++ // The reason comes from the host already redacted and cut to 300 characters; collapse ++ // its whitespace so one capability stays one line. An empty reason would leave a ++ // dangling dash, so it falls back to a sentence of its own. ++ const reason = String(status.state === 'error' ? status.error ?? 'not connected' : 'needs user approval') ++ .replace(/\s+/g, ' ').trim() || 'not connected' ++ lines.push(`- ${name} (${kinds.get(name) ?? 'capability'}): ${reason} — tell the user before acting.`) ++ } ++ if (lines.length === 0) return '' ++ return ['# Capabilities that need attention', ...lines].join('\n') ++ } ++ + ctx.effect(() => ctx.systemPrompt.section({ + name: 'bot-identity', + order: 640, + interpolate: false, + text: context => promptFor(context?.agent?.id), + }), 'ds-bot: identity section') ++ ++ ctx.effect(() => ctx.systemPrompt.section({ ++ name: 'bot-capabilities', ++ order: 700, ++ interpolate: false, ++ text: context => capabilitiesFor(context?.agent?.id), ++ }), 'ds-bot: capability section') + } diff --git a/src/host/resume.js b/src/host/resume.js --- a/src/host/resume.js +++ b/src/host/resume.js @@ -14061,7 +14149,7 @@ diff --git a/test/images.test.js b/test/images.test.js diff --git a/test/install.test.js b/test/install.test.js --- a/test/install.test.js +++ b/test/install.test.js -@@ -29,13 +29,23 @@ function start(state, { config = {}, services } = {}) { +@@ -29,24 +29,37 @@ function start(state, { config = {}, services } = {}) { } // Listeners run, and tools are listed, in the order they are registered. @@ -14085,7 +14173,13 @@ diff --git a/test/install.test.js b/test/install.test.js 'on session/event', 'effect ds-bot: agent tool restrict retry', 'on agent/created', -@@ -47,6 +47,7 @@ test('apply registers listeners, tools, and effects in a fixed order', (t) => { + 'effect ds-bot: identity section', + 'prompt bot-identity 640', ++ 'effect ds-bot: capability section', ++ 'prompt bot-capabilities 700', + 'on agent/pre-step (prepend)', + 'tool list_bots', + 'tool message_bot', 'tool stop_bot', 'tool create_bot', 'tool update_bot', @@ -16223,6 +16317,42 @@ diff --git a/test/models.test.js b/test/models.test.js diff --git a/test/prompt.test.js b/test/prompt.test.js --- a/test/prompt.test.js +++ b/test/prompt.test.js +@@ -3,11 +3,11 @@ import { test } from 'node:test' + import { install } from '../src/host/prompt.js' + import { fakeContext } from './fake-ctx.js' + +-function start() { ++function start({ statuses = {}, library = [] } = {}) { + const ctx = fakeContext() + const bots = new Map([ +- ['main', { name: 'Chief' }], +- ['worker', { name: 'Dev', instructions: 'Check files.' }], ++ ['main', { id: 'main', name: 'Chief' }], ++ ['worker', { id: 'worker', name: 'Dev', instructions: 'Check files.' }], + ]) + install({ + ctx, +@@ -15,9 +15,19 @@ function start() { + botOf: id => bots.get(id), + roomOf: id => id === 'room' ? {} : undefined, + isMain: id => id === 'main', ++ capabilityStatusesView: () => statuses, ++ capabilityLibraryView: () => library, + }) + const prompt = id => ctx.sections.get('bot-identity').text({ agent: { id } }) +- return { ctx, prompt } ++ // The host's own join: sections in order, empty ones dropped, one blank line between ++ // (dsh-system-prompt renderSections). Rendering here keeps the byte-level assertion real. ++ const render = id => [...ctx.sections.values()] ++ .sort((a, b) => a.order - b.order) ++ .map(section => section.text({ agent: { id } })) ++ .filter(text => text.length > 0) ++ .join('\n\n') ++ const capabilities = id => ctx.sections.get('bot-capabilities')?.text({ agent: { id } }) ++ return { ctx, prompt, render, capabilities } + } + + test('Bots get a scoped progress rule without changing the private/group prompt prefix', (t) => { @@ -25,7 +25,7 @@ test('Bots get a scoped progress rule without changing the private/group prompt t.after(() => ctx.dispose()) const rules = [ @@ -16232,7 +16362,7 @@ diff --git a/test/prompt.test.js b/test/prompt.test.js ] for (const id of ['main', 'worker']) { for (const rule of rules) { -@@ -43,3 +43,40 @@ test('the group relay and non-Bot sessions do not get progress instructions', (t +@@ -43,3 +43,152 @@ test('the group relay and non-Bot sessions do not get progress instructions', (t assert.doesNotMatch(prompt('room'), /progress|milestone/) assert.equal(prompt('outside'), '') }) @@ -16273,6 +16403,118 @@ diff --git a/test/prompt.test.js b/test/prompt.test.js + const replyRule = '- When a "[Reply from …]" arrives, tell the user the outcome if it matters to them.' + for (const id of ['main', 'worker']) assert.ok(prompt(id).split('\n').includes(replyRule), `${id} still answers a reply`) +}) ++ ++// #3273: a Bot must not promise work for one of its own capabilities that cannot be reached. ++// The identity section stays byte-stable (the prompt prefix is cached), so the state lives in a ++// second section that renders to nothing whenever every attached capability is usable. ++test('#3273: a capability whose connection failed is named before the Bot acts', (t) => { ++ const { ctx, render, prompt, capabilities } = start({ ++ statuses: { worker: { github: { state: 'error', error: '401 bad credentials' } } }, ++ library: [{ name: 'github', kind: 'mcp' }], ++ }) ++ t.after(() => ctx.dispose()) ++ const text = render('worker') ++ assert.equal(capabilities('worker').split('\n')[0], '# Capabilities that need attention', 'the section carries its own title, so the list is not read as a continuation of the identity block') ++ assert.equal(capabilities('worker').split('# Capabilities that need attention').length - 1, 1, 'one title, once') ++ assert.ok( ++ text.split('\n').includes('- github (mcp): 401 bad credentials — tell the user before acting.'), ++ `the failed capability and its reason are on one line:\n${text}`, ++ ) ++ assert.equal(text.slice(0, prompt('worker').length), prompt('worker'), 'the identity section is untouched') ++ assert.doesNotMatch(prompt('worker'), /401 bad credentials/, 'the identity section stays byte-stable') ++}) ++ ++test('#3273: a capability waiting for the user is named the same way', (t) => { ++ const { ctx, render } = start({ ++ statuses: { worker: { github: { state: 'needs-approval' } } }, ++ library: [{ name: 'github', kind: 'mcp' }], ++ }) ++ t.after(() => ctx.dispose()) ++ const text = render('worker') ++ assert.ok( ++ text.split('\n').includes('- github (mcp): needs user approval — tell the user before acting.'), ++ `the unapproved capability asks the Bot to say so first:\n${text}`, ++ ) ++}) ++ ++test('#3273: only the capabilities that are not usable are listed, ready ones are silent', (t) => { ++ const { ctx, capabilities } = start({ ++ statuses: { ++ worker: { ++ github: { state: 'error', error: '401 bad credentials' }, ++ linear: { state: 'ready' }, ++ slack: { state: 'needs-approval' }, ++ }, ++ }, ++ library: [{ name: 'github', kind: 'mcp' }, { name: 'linear', kind: 'mcp' }, { name: 'slack', kind: 'pack' }], ++ }) ++ t.after(() => ctx.dispose()) ++ const listed = capabilities('worker').split('\n').filter(line => line.startsWith('- ')) ++ assert.deepEqual(listed, [ ++ '- github (mcp): 401 bad credentials — tell the user before acting.', ++ '- slack (pack): needs user approval — tell the user before acting.', ++ ]) ++}) ++ ++// Test found by mutation that a healthy render compared only against another render of the same ++// code proves nothing: a trailing space added to the identity text passes both sides. The claim is ++// that the healthy prompt *is* the identity text, so its exact head and its exact last line are ++// pinned here as literals, and the capability section has to contribute the empty string. ++const IDENTITY_LAST_RULE = '- When you cannot continue without an answer, pass ask with the one question on that task. On a group card, worked in your own chat, call ask_user for the user, and post one short question in the group only when a person there has to decide. On your own chat\'s other tasks, ask_user. When the answer arrives, pass answer with what they said and update the task. Do not leave the task waiting without that question.' ++const IDENTITY_HEADS = { ++ main: "# Your identity\nYou are Chief, a Bot on the user's team in FlyBot.", ++ worker: "# Your identity\nYou are Dev, a Bot on the user's team in FlyBot.", ++} ++ ++test('#3273: a healthy Bot renders exactly the prompt it renders today', (t) => { ++ const healthy = start({ statuses: { main: {}, worker: { github: { state: 'ready' } } }, library: [{ name: 'github', kind: 'mcp' }] }) ++ const none = start() ++ t.after(() => healthy.ctx.dispose()) ++ t.after(() => none.ctx.dispose()) ++ assert.deepEqual([...healthy.ctx.sections.keys()].sort(), ['bot-capabilities', 'bot-identity']) ++ assert.equal(healthy.ctx.sections.get('bot-identity').order, 640) ++ assert.equal(healthy.ctx.sections.get('bot-capabilities').order, 700) ++ for (const id of ['main', 'worker']) { ++ assert.equal(healthy.capabilities(id), '', 'nothing unhealthy renders no section text at all') ++ const text = healthy.render(id) ++ assert.ok(text.startsWith(IDENTITY_HEADS[id]), `${id}: the rendered prompt starts on the identity title and the Bot's own line, byte for byte`) ++ assert.ok(text.endsWith(IDENTITY_LAST_RULE), `${id}: the rendered prompt ends on the last identity rule — no separator, no blank line, no trailing space`) ++ assert.equal(text.trimEnd(), text, `${id}: no trailing whitespace`) ++ assert.equal(healthy.render(id), none.render(id), 'byte for byte the prompt a Bot with no capabilities gets') ++ assert.equal(none.render(id), none.prompt(id), 'the rendered prompt is the identity section alone — no extra section, no blank line') ++ } ++ // A relay session is not a Bot: it never carries capability state. ++ assert.equal(healthy.render('room'), healthy.prompt('room')) ++}) ++ ++test('#3273: one Bot never sees another Bot\'s capability state, and a failure is whole-Bot', (t) => { ++ const { ctx, capabilities, render } = start({ ++ statuses: { ++ main: { github: { state: 'ready' } }, ++ worker: { github: { state: 'error', error: '401 bad credentials' } }, ++ }, ++ library: [{ name: 'github', kind: 'mcp' }], ++ }) ++ t.after(() => ctx.dispose()) ++ assert.equal(capabilities('main'), '', 'the Chief sees no line for a Worker capability that is down') ++ assert.equal(render('main').includes('401 bad credentials'), false) ++ assert.ok(capabilities('worker').includes('- github (mcp): 401 bad credentials'), 'the Bot whose capability is down sees it') ++ // The status view aggregates per Bot across its Sessions, the same way list_capabilities does: ++ // a failure reached in one Session is the whole Bot's failure, so the group Session reads it too. ++ assert.equal(render('group-worker'), render('worker')) ++}) ++ ++test('#3273: an error with no reason still reads as a sentence', (t) => { ++ const { ctx, capabilities } = start({ ++ statuses: { worker: { github: { state: 'error', error: ' ' }, linear: { state: 'error', error: '' } } }, ++ library: [{ name: 'github', kind: 'mcp' }, { name: 'linear', kind: 'mcp' }], ++ }) ++ t.after(() => ctx.dispose()) ++ assert.deepEqual(capabilities('worker').split('\n').filter(line => line.startsWith('- ')), [ ++ '- github (mcp): not connected — tell the user before acting.', ++ '- linear (mcp): not connected — tell the user before acting.', ++ ], 'an empty or whitespace-only reason becomes "not connected", never a dangling dash') ++}) diff --git a/test/schedules.test.js b/test/schedules.test.js --- a/test/schedules.test.js +++ b/test/schedules.test.js diff --git a/patches/ds-bot/0008-client-bundle.patch b/patches/ds-bot/0008-client-bundle.patch index 43d2a63b5..55582ec6b 100644 --- a/patches/ds-bot/0008-client-bundle.patch +++ b/patches/ds-bot/0008-client-bundle.patch @@ -1377,7 +1377,7 @@ diff --git a/client.js b/client.js "The admin must be a member of the group": "管理员必须是群成员", "Unknown group chat": "找不到这个群聊", "Hand the admin role to another member instead of leaving the group without one": "请把管理员交给其他成员,不要让群聊没有管理员", -@@ -951,10 +951,82 @@ var HOST_ZH = { +@@ -951,10 +951,85 @@ var HOST_ZH = { "The model wrote nothing": "模型没有输出内容", "Write the entry to save.": "请写下要保存的内容。", "This DeepSeek Harness has no folder chooser": "这个 DeepSeek Harness 没有文件夹选择窗口", @@ -1452,6 +1452,9 @@ diff --git a/client.js b/client.js + 'Use a capability name with lowercase letters, digits, and single hyphens; "github" and "composio" are reserved.': "能力名只能用小写字母、数字和单个连字符;「github」和「composio」是保留名。", + "Enter a command for the MCP server.": "请填写 MCP 服务器的命令。", + "Enter a valid HTTP or HTTPS URL.": "请填写有效的 HTTP 或 HTTPS 地址。", ++ // #3273: a URL carrying userinfo is refused instead of stored, so the credential never reaches ++ // a status line and never reaches the system prompt. ++ "Enter the URL without a username or password. Save the credential as a secret and reference it in a header.": "地址里不要写用户名或密码。请把凭据保存为密钥,并在请求头里引用它。", + "A capability cannot change its kind. Delete it and save a new one.": "能力类型不能改。请删掉它,再新建一个。", + "Environment variables must contain text values.": "环境变量里只能填文本值。", + "Headers must contain text values.": "请求头里只能填文本值。" diff --git a/patches/ds-bot/0014-flybot-branding.patch b/patches/ds-bot/0014-flybot-branding.patch index 232876648..614b00ae4 100644 --- a/patches/ds-bot/0014-flybot-branding.patch +++ b/patches/ds-bot/0014-flybot-branding.patch @@ -2047,7 +2047,7 @@ diff --git a/test/capabilities.test.js b/test/capabilities.test.js }) test('read-only secret reload does not requeue capability reconciliation', async t => { -@@ -425,3 +425,39 @@ test('mounts agent-only MCP and skills, remounts changed config, resolves scoped +@@ -425,3 +425,90 @@ test('mounts agent-only MCP and skills, remounts changed config, resolves scoped assert.equal(mounts.findLast(mount => mount.sessionId === 'chief' && mount.plugin.inject?.includes('skills')).disposed, true) assert.equal(rt.capabilityStatusesView().chief.team, undefined) }) @@ -2087,6 +2087,57 @@ diff --git a/test/capabilities.test.js b/test/capabilities.test.js + assert.ok(description.startsWith(kept), 'a code-point prefix of the description the peer sent') + assert.ok(kept.length <= 2000, 'the budget of 2000 UTF-16 units is unchanged') +}) ++ ++// #3273, from the security read at 6b401ebb: an inline credential in a URL is a shape ++// `redactSecrets` cannot know (it replaces saved key values), so the host refuses it on the way in ++// and masks userinfo on the way out — the string never reaches a status line, and therefore never ++// reaches the system prompt section that prints one. ++const USERINFO_REFUSAL = 'Enter the URL without a username or password. Save the credential as a secret and reference it in a header.' ++ ++test('a capability URL that carries a username or password is refused, and nothing is stored', async t => { ++ const env = await setup() ++ t.after(() => env.dispose()) ++ const { rt } = env ++ for (const url of ['https://alice:s3cr3t-pa55@host/mcp', 'https://alice@host/mcp']) { ++ await assert.rejects( ++ rt.capabilitySave({ ...mcp('inline'), transport: 'streamable-http', url }, { ui: true }), ++ error => error.message === USERINFO_REFUSAL, ++ ) ++ } ++ assert.equal(rt.state.capabilities.items.inline, undefined, 'a refused save leaves no item') ++ assert.equal(JSON.stringify(rt.state).includes('s3cr3t-pa55'), false) ++}) ++ ++test('an error that quotes a URL saved before this fix stores it with the userinfo masked', async t => { ++ const state = team() ++ state.capabilities = { ++ items: { ++ inline: { ++ name: 'inline', kind: 'mcp', description: 'Saved before the refusal', transport: 'streamable-http', ++ url: 'https://alice:s3cr3t-pa55@host/mcp', headers: {}, approved: true, createdBy: 'worker', createdAt: 1, updatedAt: 1, ++ }, ++ }, ++ } ++ const env = await setup({ state }) ++ t.after(() => env.dispose()) ++ const { ctx, rt, mounts, skills } = env ++ await rt.changeCapabilityAttachment('attach', { name: 'inline' }, 'worker') ++ const quoted = 'Request cannot be constructed from a URL that includes credentials: https://alice:s3cr3t-pa55@host/mcp' ++ ctx.emit('agent/created', { agent: testAgent('worker', mounts, skills, { awaitMount: async () => { throw new TypeError(quoted) } }) }) ++ await rt.scheduleCapabilitiesReconcile() ++ const status = rt.capabilityStatusesView().worker.inline ++ assert.equal(status.state, 'error') ++ assert.equal(status.error, 'Request cannot be constructed from a URL that includes credentials: https://host/mcp', 'the exact stored sentence: the scheme and host stay, the userinfo is gone') ++ assert.equal(JSON.stringify(rt.capabilityStatusesView()).includes('s3cr3t-pa55'), false) ++}) ++ ++test('a plain HTTPS URL still saves', async t => { ++ const env = await setup() ++ t.after(() => env.dispose()) ++ const saved = await env.rt.capabilitySave({ ...mcp('plain'), transport: 'streamable-http', url: 'https://host/mcp' }, { ui: true }) ++ assert.equal(saved.url, 'https://host/mcp') ++ assert.equal(env.rt.state.capabilities.items.plain.url, 'https://host/mcp') ++}) diff --git a/test/dsh-update.test.js b/test/dsh-update.test.js --- a/test/dsh-update.test.js +++ b/test/dsh-update.test.js diff --git a/patches/ds-bot/files/test/settings-error-placement.test.js b/patches/ds-bot/files/test/settings-error-placement.test.js index ef0bd509d..459b3cc41 100644 --- a/patches/ds-bot/files/test/settings-error-placement.test.js +++ b/patches/ds-bot/files/test/settings-error-placement.test.js @@ -101,7 +101,7 @@ test('a refused write in Settings stays in view instead of scrolling away with t assert.equal(inside(alert, scrolling), false, 'the refusal must sit outside the scrolling page, not above it') }) -// #3114 cut 31: the Capabilities form and the six fixed refusals its save can leave. The page +// #3114 cut 31: the Capabilities form and the fixed refusals its save can leave. The page // already draws `t(label)` (capability-settings.js:19) and the host sentence is translated before it // is thrown (api.js:38), so the dictionary is the only place these cases can be red. const REFUSALS = [ @@ -109,6 +109,9 @@ const REFUSALS = [ '能力名只能用小写字母、数字和单个连字符;「github」和「composio」是保留名。'], ['Enter a command for the MCP server.', '请填写 MCP 服务器的命令。'], ['Enter a valid HTTP or HTTPS URL.', '请填写有效的 HTTP 或 HTTPS 地址。'], + // #3273: the seventh refusal, from the security read at 6b401ebb. + ['Enter the URL without a username or password. Save the credential as a secret and reference it in a header.', + '地址里不要写用户名或密码。请把凭据保存为密钥,并在请求头里引用它。'], ['A capability cannot change its kind. Delete it and save a new one.', '能力类型不能改。请删掉它,再新建一个。'], ['Environment variables must contain text values.', '环境变量里只能填文本值。'], ['Headers must contain text values.', '请求头里只能填文本值。'], From 8d991600778474b887f01b2784b8c72327c8a109 Mon Sep 17 00:00:00 2001 From: Danyang Chen Date: Sat, 21 Nov 2026 09:27:46 +0800 Subject: [PATCH 2/2] Say in core-client.md that a capability address carries no credential #3273 refuses an MCP address carrying userinfo, and masks userinfo in a stored transport error. Both owned files it changes (core/client.js, core/src/client/i18n.js) belong to core-client, so arch-docs asks for this page. Refs #3273 Written-by: Rework --- docs/subsystems/core-client.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/subsystems/core-client.md b/docs/subsystems/core-client.md index a0baa11e1..4bde56f01 100644 --- a/docs/subsystems/core-client.md +++ b/docs/subsystems/core-client.md @@ -23,6 +23,7 @@ The browser side of the patched `ds-bot` core (`core/`): sources in `core/src/cl - A long chat message folds to a whole-line preview at the standard cap (12 lines, or 800 characters, whichever comes first) with one **Show more** control inside the bubble that opens the whole reply and becomes **Show less** (`message-fold.js` `FoldedContent`, drawn by `cells.js` for a Bot reply and by `user-message.js` for my own line; `foldingOf(roster.prefs)` reads the mode — standard by default, `none` folding nothing). A reply still streaming, and one at or under the cap, are never folded, and the preview never leaves a code block open. A reply over the standard cap that carries at least two headings, or three sections broken by `---`, is drawn as a card instead: the first heading is its title, then a `{n} sections` count and **Open beside the conversation**, which puts the whole text in the panel as the `document` view — the same subject Session, closed by × or by leaving that conversation — and **Show message text** under the card opens it in place; `none` folding draws no card and the whole text. Both are chosen in Settings → General (`Message folding`, and the `Document cards` switch, which switched off draws no card and no **Show message text** at any folding mode), written through `set-prefs`. Tests: `core/test/message-fold.test.js`. The draw reaches the bubble as the `draw` property, not as children: a cell component is expanded from its props alone (`core/test/tool-cells.test.js`). - A link picked in a chat message opens in FlyBot's own panel: a capture-phase click handler on each bubble and on the person's own line (`bubbleLinkClick` in `cells.js`; a group card's container carries none, so a reply's link opens the tab of the Bot that spoke) takes an `http(s)` anchor before the host's delegate does, puts a tab in the panel's browser view (the globe button's view) with `actions.browserNewTab` and carries the URL with `actions.browserNavigate`; `browserNewTab` answers `null` for a Bot outside the roster, and with no tab — or no Desktop bridge — the page opens in the window itself. A mention, a file link and a modified or middle click are left alone, and the bubble renders bare `MarkdownText` so the host's `openFile`/`fileImages` reach it: a nested `MarkdownDelegateProvider` replaces the host's capabilities, and one that lacked `fileImages` drew every bubble image as its alt text (#2319). Left to the host a click opened a tab in the host's right sidebar, which this panel's fixed layer covers, so the content area looked blank (#2201). Tests: `core/test/chat-link-open.test.js`. +- Settings → Capabilities' save refuses an MCP address that carries userinfo (`https://alice:s3cr3t@host/mcp`) instead of storing it: the answer is `Enter the URL without a username or password. Save the credential as a secret and reference it in a header.`, drawn in the form's existing alert row like the six refusals before it, so no visual state is new (#3273). The sentence is raised by the host save ([core-host](core-host.md), `core/src/host/capabilities.js`), its zh entry sits beside it in `core/src/client/i18n.js` and the generated `core/client.js` carries the pair, and `core/test/settings-error-placement.test.js` holds the English–Chinese correspondence while `core/test/capabilities.test.js` holds the refusal itself (nothing is stored). It is a refusal rather than a redaction at the sink because `redactSecrets` replaces saved key values and cannot know a password written into a URL, while a failed mount quotes that address back verbatim — and a transport error stored by an address saved before this refusal has its userinfo masked before the 300-character cut, so neither an old nor a new item can print the credential. ## Does not own - The server side, `core/index.js`, `core/src/host/`, `core/src/shared/` → [core-host](core-host.md).