Skip to content

Commit e3caccb

Browse files
HugoXKBirfy
andauthored
Tell a Bot in its system prompt when one of its capabilities is down (#3274)
Fixes #3273 Written-by: FlyBot Dev-1 Owner: Dev-1 Reviewer: Reviewer Tier: T2 (`core/src/host/**` is T2 in `.github/agent/risk-rules.json`; the tests, the client dictionary, the doc and the fragment are T0/T1) Claim-Id: 996fccbc55c04237b11177afbdbbca47 Base: 4a3ad73 ## What changed A Bot agreed to work it could not do: one of its attached MCP capabilities had failed or was waiting for approval, and the only places that knew were the client badge (`channel.js:223`) and `list_capabilities`, a tool the Bot has to think to call. Nothing in the system prompt said it. `core/src/host/prompt.js` registers a second section beside `bot-identity` — `bot-capabilities`, `order: 700`, `interpolate: false` — for the rendering Session's own Bot. It reads `capabilityStatusesView()[bot.id]`, keeps the capabilities in state `error` or `needs-approval`, and renders one line each under a single heading line: ``` # Capabilities that need attention - github (mcp): 401 bad credentials — tell the user before acting. ``` The `<kind>` comes from `capabilityLibraryView()`. A capability in `error` carries the reason the host already stores — redacted and cut to 300 characters by `capabilities.js` — with its whitespace collapsed so one capability stays one line, and an empty or whitespace-only reason reads `not connected` rather than leaving a dangling dash; `needs-approval` renders `needs user approval`, the wording the capability tools already use. The heading is the only text besides those lines: a bare dash list would not say these are the Bot's own capabilities. The status view aggregates per Bot across its Sessions, so a failure reached in one Session is the whole Bot's failure — the same rule `list_capabilities` already follows — and one Bot never sees another's state. Both are asserted. When every attached capability is `ready`, or the Bot has none, the section text is `''`. DSH drops empty sections and joins the rest with a blank line (`dsh-system-prompt` `renderSections`), so the rendered prompt is byte-identical to today's; the test now pins the rendered head and last line as literals and proves the same bytes against the base source (main 11445, worker 9059, relay 272, non-Bot 0 characters). The identity section is untouched and its header comment states that capability state stays out of it. ## From the security read at `6b401ebb` One reachable path was not closed by the section itself. `capabilities.js` accepted a URL such as `https://alice:s3cr3t-pa55@host/mcp` (only the protocol was checked), `configFor` passed it through raw, and when the mount failed the transport error quoted it back verbatim — `redactSecrets` replaces saved *key values*, not an inline credential — so the sentence that would now be printed every turn carried the password. Two changes close it: - the save refuses a URL carrying userinfo: `Enter the URL without a username or password. Save the credential as a secret and reference it in a header.` (seven fixed refusals on this form now; the Chinese text is in `core/src/client/i18n.js` and `settings-error-placement.test.js` holds the pair) - a stored transport error of a capability saved before that refusal has its userinfo masked before the 300-character cut, so an old item cannot print it either `prompt.js` is unchanged by this half: the string must not exist, not be hidden at the sink. Residual, weighed and not missed: a server can echo a literal header value in its own error body (`Error POSTing to endpoint: …`). That class is already reachable today through a connected server's instructions; here it is bounded to 300 characters and one line, and it is not a shape the host can recognise as a credential. The client half is exactly that dictionary entry: `core/src/client/i18n.js` gains the zh sentence, `core/client.js` carries the same map (built with `npm run build`), and `settings-error-placement.test.js` gains the pair. No client behaviour, tool set, protocol or workflow changes, and no visual change — the refusal draws in the form's existing alert row, which already shows six other refusals — so there is no new screenshot and the prompt text stays model-facing English like every other rule in that file. 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. ## Red first The prompt section (first commit, test-only tree on base `4a3ad732`): `node --test core/test/prompt.test.js` → `# tests 7 / # pass 3 / # fail 4`, the four new cases failing on `actual: false`, `undefined`, `undefined` and `undefined !== ''`. The security fix, on the same tree with source unfixed: - `node --test core/test/capabilities.test.js` → `# tests 20 / # pass 18 / # fail 2` - `a capability URL that carries a username or password is refused, and nothing is stored` → `Missing expected rejection.` - `an error that quotes a URL saved before this fix stores it with the userinfo masked` → actual `Request cannot be constructed from a URL that includes credentials: https://alice:s3cr3t-pa55@host/mcp`, expected `…: https://host/mcp` - `node --test core/test/prompt.test.js` with the empty-reason case added → `# tests 9 / # pass 8 / # fail 1` - `an error with no reason still reads as a sentence` → the line rendered `- github (mcp): — tell the user before acting.` (double space, no reason) Green after the fix, each file run twice in a row: `prompt.test.js` `# tests 9 / # pass 9 / # fail 0`, `capabilities.test.js` `# tests 20 / # pass 20 / # fail 0`. ## Verification at the tip Tip SHA: `8d991600778474b887f01b2784b8c72327c8a109` (the author's `c412b65bfa90a74220e0b83de2b55607d3260c7c` = tree `c7ed581f` plus one docs-only commit from `Written-by: Rework` that adds the `core-client` rule; 15 files, +544/−21, on base `4a3ad73274111bba22e3e9628b7a9e5f5c7bc62b`). The readings below ran on the author's tree; the docs commit changes no code. Ran: - `TZ=UTC npm run verify` → exit 0: core 3402/3402/0, plane 25/25/0, social 758/758/0, tree 152/152/0, timeline 172/172/0, workflow 538/538/0, project 151/151/0, `.github/scripts`+`policy` 724/724/0, interop 37/37/0, live-e2e 34/34/0 - in that run: `build-client.mjs --check` rc 0, `ds-bot-patches.mjs check` three ok lines and `canonical` no-op, oxlint 0 errors (warnings 91 core, 40/9/2/16/0 across the plugins — all in files this branch does not touch) - `ARCH_DOCS_BASE=4a3ad73274111bba22e3e9628b7a9e5f5c7bc62b npm run arch-docs` (in `core/`) → the local run reported OK, but CI at `76856c3c` failed the same step: `core/client.js` and `core/src/client/i18n.js` are owned by `core-client` and the branch did not touch `docs/subsystems/core-client.md`. That page now carries the rule (+1 line, no code), so the gate has its doc at this tip. - `node scripts/ds-bot-patches.mjs generate` → rc 0, then `git status --porcelain` 0 lines - `node --test core/test/prompt.test.js` 9/9 twice, `core/test/capabilities.test.js` 20/20 twice, `core/test/settings-error-placement.test.js` 6/6, `core/test/i18n.test.js` 5/5, `core/test/install.test.js` 6/6 (all through `test/harness-resolve.mjs`, as `npm test` runs them) - the base-against-tip render probe: `installBase` from `4a3ad732`'s `prompt.js` and this tip's `install` produce identical text for main (11445), worker (9059), relay (272) and a non-Bot (0), then the probe files were deleted - `node .github/scripts/changelog.mjs check` → `1 fragment(s) in changelog.d/ are well formed` - `node .github/scripts/check-mojibake.mjs --check` → 0 occurrences of U+FFFD in 1771 text files Not run: - the `dev/bench.sh smoke` test (needs a DSH checkout and a free port); `verify` is the gate that covers this change - no screenshot: no visual state changes (the refusal uses the form's existing alert row) - the box's `TMPDIR` points at a read-only directory, so every command ran with `env -u TMPDIR` (system `/tmp`) and a workspace `npm_config_cache`; that is this machine, not the change ## Checkpoint <!-- flybot:checkpoint --> ```json { "pr": 3274, "claim": "Dev-1", "issue": 3273, "summary": "#3273: a Bot now sees its own broken capability in the system prompt, one line each for error and needs-approval, and an empty section while every capability is ready. From the security read at 6b401eb the same pass refuses a capability URL carrying userinfo and masks a stored transport error's userinfo, so a credential cannot reach that line. Tests cover the failed connection, the unapproved capability, the mixed case, one Bot's isolation from another, an empty reason, the refused save, the masked stored error, a plain URL, and the byte-identical healthy render.", "files": [ "core/src/host/prompt.js", "core/src/host/capabilities.js", "core/src/client/i18n.js", "core/client.js", "core/test/prompt.test.js", "core/test/capabilities.test.js", "core/test/settings-error-placement.test.js", "core/test/install.test.js", "changelog.d/3273.fixed.md", "docs/subsystems/core-host.md", "patches/ds-bot/0001-core-fixes.patch", "patches/ds-bot/0008-client-bundle.patch" ], "checks": { "ran": "TZ=UTC npm run verify; prompt.test.js 9/9 ×2; capabilities.test.js 20/20 ×2; ds-bot-patches generate + check + canonical; ARCH_DOCS_BASE=4a3ad7327411 arch-docs; changelog check", "result": "green", "at": "8d991600778474b887f01b2784b8c72327c8a109" }, "next": "none — ready for review" } ``` <!-- /flybot:checkpoint --> --------- Co-authored-by: Danyang Chen <birfychen@gmail.com>
1 parent 4a3ad73 commit e3caccb

15 files changed

Lines changed: 544 additions & 21 deletions

‎changelog.d/3273.fixed.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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)).

‎core/client.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,9 @@ var HOST_ZH = {
19121912
'Use a capability name with lowercase letters, digits, and single hyphens; "github" and "composio" are reserved.': "能力名只能用小写字母、数字和单个连字符;「github」和「composio」是保留名。",
19131913
"Enter a command for the MCP server.": "请填写 MCP 服务器的命令。",
19141914
"Enter a valid HTTP or HTTPS URL.": "请填写有效的 HTTP 或 HTTPS 地址。",
1915+
// #3273: a URL carrying userinfo is refused instead of stored, so the credential never reaches
1916+
// a status line and never reaches the system prompt.
1917+
"Enter the URL without a username or password. Save the credential as a secret and reference it in a header.": "地址里不要写用户名或密码。请把凭据保存为密钥,并在请求头里引用它。",
19151918
"A capability cannot change its kind. Delete it and save a new one.": "能力类型不能改。请删掉它,再新建一个。",
19161919
"Environment variables must contain text values.": "环境变量里只能填文本值。",
19171920
"Headers must contain text values.": "请求头里只能填文本值。"

‎core/src/client/i18n.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,6 +1872,9 @@ const HOST_ZH = {
18721872
'Use a capability name with lowercase letters, digits, and single hyphens; "github" and "composio" are reserved.': '能力名只能用小写字母、数字和单个连字符;「github」和「composio」是保留名。',
18731873
'Enter a command for the MCP server.': '请填写 MCP 服务器的命令。',
18741874
'Enter a valid HTTP or HTTPS URL.': '请填写有效的 HTTP 或 HTTPS 地址。',
1875+
// #3273: a URL carrying userinfo is refused instead of stored, so the credential never reaches
1876+
// a status line and never reaches the system prompt.
1877+
'Enter the URL without a username or password. Save the credential as a secret and reference it in a header.': '地址里不要写用户名或密码。请把凭据保存为密钥,并在请求头里引用它。',
18751878
'A capability cannot change its kind. Delete it and save a new one.': '能力类型不能改。请删掉它,再新建一个。',
18761879
'Environment variables must contain text values.': '环境变量里只能填文本值。',
18771880
'Headers must contain text values.': '请求头里只能填文本值。',

‎core/src/host/capabilities.js‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ export function expandCapabilityNames(capabilities, library) {
3636
return expanded
3737
}
3838

39+
// #3273: `redactSecrets` replaces saved key values, so a password written into a URL is a shape it
40+
// cannot know. A transport error quotes that URL back verbatim, and the status line reaches the
41+
// system prompt every turn, so userinfo is dropped before the sentence is stored.
42+
const withoutUserinfo = text => text.replace(/([a-z][a-z0-9+.-]*:\/\/)[^/\s@]+@/gi, '$1')
43+
3944
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b)
4045
const strings = value => {
4146
if (value === undefined) return []
@@ -112,10 +117,10 @@ export function install(rt) {
112117
Object.assign(item, { transport, command, args, env, approved: ui ? true : changed ? false : previous.approved === true })
113118
} else {
114119
const url = String(body.url ?? '').trim()
115-
try {
116-
const parsed = new URL(url)
117-
if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') throw new Error()
118-
} catch { throw new Error('Enter a valid HTTP or HTTPS URL.') }
120+
let parsed
121+
try { parsed = new URL(url) } catch { throw new Error('Enter a valid HTTP or HTTPS URL.') }
122+
if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') throw new Error('Enter a valid HTTP or HTTPS URL.')
123+
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.')
119124
Object.assign(item, { transport, url, headers: stringMap(body.headers, 'Headers'), approved: true })
120125
}
121126
} else if (kind === 'skill') {
@@ -312,7 +317,8 @@ export function install(rt) {
312317
statusSet(bot.id, name, sessionId, { state: 'ready' })
313318
} catch (error) {
314319
await drop()
315-
const message = rt.redactSecrets([error, error?.cause].filter(Boolean).map(part => String(part?.message ?? part)).join(': ') || 'Connection failed').slice(0, 300)
320+
const joined = [error, error?.cause].filter(Boolean).map(part => String(part?.message ?? part)).join(': ') || 'Connection failed'
321+
const message = withoutUserinfo(rt.redactSecrets(joined)).slice(0, 300)
316322
statusSet(bot.id, name, sessionId, { state: 'error', error: message })
317323
}
318324
}

‎core/src/host/prompt.js‎

Lines changed: 34 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎core/test/capabilities.test.js‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,3 +466,54 @@ test('a capability description is cut at 2000 without splitting an emoji', async
466466
assert.ok(description.startsWith(kept), 'a code-point prefix of the description the peer sent')
467467
assert.ok(kept.length <= 2000, 'the budget of 2000 UTF-16 units is unchanged')
468468
})
469+
470+
// #3273, from the security read at 6b401ebb: an inline credential in a URL is a shape
471+
// `redactSecrets` cannot know (it replaces saved key values), so the host refuses it on the way in
472+
// and masks userinfo on the way out — the string never reaches a status line, and therefore never
473+
// reaches the system prompt section that prints one.
474+
const USERINFO_REFUSAL = 'Enter the URL without a username or password. Save the credential as a secret and reference it in a header.'
475+
476+
test('a capability URL that carries a username or password is refused, and nothing is stored', async t => {
477+
const env = await setup()
478+
t.after(() => env.dispose())
479+
const { rt } = env
480+
for (const url of ['https://alice:s3cr3t-pa55@host/mcp', 'https://alice@host/mcp']) {
481+
await assert.rejects(
482+
rt.capabilitySave({ ...mcp('inline'), transport: 'streamable-http', url }, { ui: true }),
483+
error => error.message === USERINFO_REFUSAL,
484+
)
485+
}
486+
assert.equal(rt.state.capabilities.items.inline, undefined, 'a refused save leaves no item')
487+
assert.equal(JSON.stringify(rt.state).includes('s3cr3t-pa55'), false)
488+
})
489+
490+
test('an error that quotes a URL saved before this fix stores it with the userinfo masked', async t => {
491+
const state = team()
492+
state.capabilities = {
493+
items: {
494+
inline: {
495+
name: 'inline', kind: 'mcp', description: 'Saved before the refusal', transport: 'streamable-http',
496+
url: 'https://alice:s3cr3t-pa55@host/mcp', headers: {}, approved: true, createdBy: 'worker', createdAt: 1, updatedAt: 1,
497+
},
498+
},
499+
}
500+
const env = await setup({ state })
501+
t.after(() => env.dispose())
502+
const { ctx, rt, mounts, skills } = env
503+
await rt.changeCapabilityAttachment('attach', { name: 'inline' }, 'worker')
504+
const quoted = 'Request cannot be constructed from a URL that includes credentials: https://alice:s3cr3t-pa55@host/mcp'
505+
ctx.emit('agent/created', { agent: testAgent('worker', mounts, skills, { awaitMount: async () => { throw new TypeError(quoted) } }) })
506+
await rt.scheduleCapabilitiesReconcile()
507+
const status = rt.capabilityStatusesView().worker.inline
508+
assert.equal(status.state, 'error')
509+
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')
510+
assert.equal(JSON.stringify(rt.capabilityStatusesView()).includes('s3cr3t-pa55'), false)
511+
})
512+
513+
test('a plain HTTPS URL still saves', async t => {
514+
const env = await setup()
515+
t.after(() => env.dispose())
516+
const saved = await env.rt.capabilitySave({ ...mcp('plain'), transport: 'streamable-http', url: 'https://host/mcp' }, { ui: true })
517+
assert.equal(saved.url, 'https://host/mcp')
518+
assert.equal(env.rt.state.capabilities.items.plain.url, 'https://host/mcp')
519+
})

‎core/test/install.test.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ test('apply registers listeners, tools, and effects in a fixed order', (t) => {
5151
'on agent/created',
5252
'effect ds-bot: identity section',
5353
'prompt bot-identity 640',
54+
'effect ds-bot: capability section',
55+
'prompt bot-capabilities 700',
5456
'on agent/pre-step (prepend)',
5557
'tool list_bots',
5658
'tool message_bot',

‎core/test/prompt.test.js‎

Lines changed: 126 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,31 @@ import { test } from 'node:test'
33
import { install } from '../src/host/prompt.js'
44
import { fakeContext } from './fake-ctx.js'
55

6-
function start() {
6+
function start({ statuses = {}, library = [] } = {}) {
77
const ctx = fakeContext()
88
const bots = new Map([
9-
['main', { name: 'Chief' }],
10-
['worker', { name: 'Dev', instructions: 'Check files.' }],
9+
['main', { id: 'main', name: 'Chief' }],
10+
['worker', { id: 'worker', name: 'Dev', instructions: 'Check files.' }],
1111
])
1212
install({
1313
ctx,
1414
selfOf: id => id === 'group-worker' ? 'worker' : id,
1515
botOf: id => bots.get(id),
1616
roomOf: id => id === 'room' ? {} : undefined,
1717
isMain: id => id === 'main',
18+
capabilityStatusesView: () => statuses,
19+
capabilityLibraryView: () => library,
1820
})
1921
const prompt = id => ctx.sections.get('bot-identity').text({ agent: { id } })
20-
return { ctx, prompt }
22+
// The host's own join: sections in order, empty ones dropped, one blank line between
23+
// (dsh-system-prompt renderSections). Rendering here keeps the byte-level assertion real.
24+
const render = id => [...ctx.sections.values()]
25+
.sort((a, b) => a.order - b.order)
26+
.map(section => section.text({ agent: { id } }))
27+
.filter(text => text.length > 0)
28+
.join('\n\n')
29+
const capabilities = id => ctx.sections.get('bot-capabilities')?.text({ agent: { id } })
30+
return { ctx, prompt, render, capabilities }
2131
}
2232

2333
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)',
8090
const replyRule = '- When a "[Reply from …]" arrives, tell the user the outcome if it matters to them.'
8191
for (const id of ['main', 'worker']) assert.ok(prompt(id).split('\n').includes(replyRule), `${id} still answers a reply`)
8292
})
93+
94+
// #3273: a Bot must not promise work for one of its own capabilities that cannot be reached.
95+
// The identity section stays byte-stable (the prompt prefix is cached), so the state lives in a
96+
// second section that renders to nothing whenever every attached capability is usable.
97+
test('#3273: a capability whose connection failed is named before the Bot acts', (t) => {
98+
const { ctx, render, prompt, capabilities } = start({
99+
statuses: { worker: { github: { state: 'error', error: '401 bad credentials' } } },
100+
library: [{ name: 'github', kind: 'mcp' }],
101+
})
102+
t.after(() => ctx.dispose())
103+
const text = render('worker')
104+
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')
105+
assert.equal(capabilities('worker').split('# Capabilities that need attention').length - 1, 1, 'one title, once')
106+
assert.ok(
107+
text.split('\n').includes('- github (mcp): 401 bad credentials — tell the user before acting.'),
108+
`the failed capability and its reason are on one line:\n${text}`,
109+
)
110+
assert.equal(text.slice(0, prompt('worker').length), prompt('worker'), 'the identity section is untouched')
111+
assert.doesNotMatch(prompt('worker'), /401 bad credentials/, 'the identity section stays byte-stable')
112+
})
113+
114+
test('#3273: a capability waiting for the user is named the same way', (t) => {
115+
const { ctx, render } = start({
116+
statuses: { worker: { github: { state: 'needs-approval' } } },
117+
library: [{ name: 'github', kind: 'mcp' }],
118+
})
119+
t.after(() => ctx.dispose())
120+
const text = render('worker')
121+
assert.ok(
122+
text.split('\n').includes('- github (mcp): needs user approval — tell the user before acting.'),
123+
`the unapproved capability asks the Bot to say so first:\n${text}`,
124+
)
125+
})
126+
127+
test('#3273: only the capabilities that are not usable are listed, ready ones are silent', (t) => {
128+
const { ctx, capabilities } = start({
129+
statuses: {
130+
worker: {
131+
github: { state: 'error', error: '401 bad credentials' },
132+
linear: { state: 'ready' },
133+
slack: { state: 'needs-approval' },
134+
},
135+
},
136+
library: [{ name: 'github', kind: 'mcp' }, { name: 'linear', kind: 'mcp' }, { name: 'slack', kind: 'pack' }],
137+
})
138+
t.after(() => ctx.dispose())
139+
const listed = capabilities('worker').split('\n').filter(line => line.startsWith('- '))
140+
assert.deepEqual(listed, [
141+
'- github (mcp): 401 bad credentials — tell the user before acting.',
142+
'- slack (pack): needs user approval — tell the user before acting.',
143+
])
144+
})
145+
146+
// Test found by mutation that a healthy render compared only against another render of the same
147+
// code proves nothing: a trailing space added to the identity text passes both sides. The claim is
148+
// that the healthy prompt *is* the identity text, so its exact head and its exact last line are
149+
// pinned here as literals, and the capability section has to contribute the empty string.
150+
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.'
151+
const IDENTITY_HEADS = {
152+
main: "# Your identity\nYou are Chief, a Bot on the user's team in FlyBot.",
153+
worker: "# Your identity\nYou are Dev, a Bot on the user's team in FlyBot.",
154+
}
155+
156+
test('#3273: a healthy Bot renders exactly the prompt it renders today', (t) => {
157+
const healthy = start({ statuses: { main: {}, worker: { github: { state: 'ready' } } }, library: [{ name: 'github', kind: 'mcp' }] })
158+
const none = start()
159+
t.after(() => healthy.ctx.dispose())
160+
t.after(() => none.ctx.dispose())
161+
assert.deepEqual([...healthy.ctx.sections.keys()].sort(), ['bot-capabilities', 'bot-identity'])
162+
assert.equal(healthy.ctx.sections.get('bot-identity').order, 640)
163+
assert.equal(healthy.ctx.sections.get('bot-capabilities').order, 700)
164+
for (const id of ['main', 'worker']) {
165+
assert.equal(healthy.capabilities(id), '', 'nothing unhealthy renders no section text at all')
166+
const text = healthy.render(id)
167+
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`)
168+
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`)
169+
assert.equal(text.trimEnd(), text, `${id}: no trailing whitespace`)
170+
assert.equal(healthy.render(id), none.render(id), 'byte for byte the prompt a Bot with no capabilities gets')
171+
assert.equal(none.render(id), none.prompt(id), 'the rendered prompt is the identity section alone — no extra section, no blank line')
172+
}
173+
// A relay session is not a Bot: it never carries capability state.
174+
assert.equal(healthy.render('room'), healthy.prompt('room'))
175+
})
176+
177+
test('#3273: one Bot never sees another Bot\'s capability state, and a failure is whole-Bot', (t) => {
178+
const { ctx, capabilities, render } = start({
179+
statuses: {
180+
main: { github: { state: 'ready' } },
181+
worker: { github: { state: 'error', error: '401 bad credentials' } },
182+
},
183+
library: [{ name: 'github', kind: 'mcp' }],
184+
})
185+
t.after(() => ctx.dispose())
186+
assert.equal(capabilities('main'), '', 'the Chief sees no line for a Worker capability that is down')
187+
assert.equal(render('main').includes('401 bad credentials'), false)
188+
assert.ok(capabilities('worker').includes('- github (mcp): 401 bad credentials'), 'the Bot whose capability is down sees it')
189+
// The status view aggregates per Bot across its Sessions, the same way list_capabilities does:
190+
// a failure reached in one Session is the whole Bot's failure, so the group Session reads it too.
191+
assert.equal(render('group-worker'), render('worker'))
192+
})
193+
194+
test('#3273: an error with no reason still reads as a sentence', (t) => {
195+
const { ctx, capabilities } = start({
196+
statuses: { worker: { github: { state: 'error', error: ' ' }, linear: { state: 'error', error: '' } } },
197+
library: [{ name: 'github', kind: 'mcp' }, { name: 'linear', kind: 'mcp' }],
198+
})
199+
t.after(() => ctx.dispose())
200+
assert.deepEqual(capabilities('worker').split('\n').filter(line => line.startsWith('- ')), [
201+
'- github (mcp): not connected — tell the user before acting.',
202+
'- linear (mcp): not connected — tell the user before acting.',
203+
], 'an empty or whitespace-only reason becomes "not connected", never a dangling dash')
204+
})

0 commit comments

Comments
 (0)