From 8bbd01baeefa413a7dfbb4accc5f9d5ddf46f6fa Mon Sep 17 00:00:00 2001 From: Day Dreamer <87640074+HugoXK@users.noreply.github.com> Date: Sat, 21 Nov 2026 12:29:00 +0800 Subject: [PATCH] Prove a stored capability reason has one masked source on every surface The #3278 mask is only half the guarantee: the stored reason is printed by four readers, and nothing tested them. Two fixtures saved before the fix (stdio argv plus env, and an http header) take one new start failure and assert the literal is absent from the status answer, the list_capabilities text, the prompt line and the log; the first three must repeat the same masked sentence, and detaching the item empties them, which shows they read one stored reason built at one place. --- changelog.d/3278.fixed.md | 1 + core/src/host/capabilities.js | 41 ++++- core/test/capabilities.test.js | 187 ++++++++++++++++++++- docs/subsystems/core-host.md | 2 +- patches/ds-bot/0001-core-fixes.patch | 43 ++++- patches/ds-bot/0014-flybot-branding.patch | 194 +++++++++++++++++++++- 6 files changed, 448 insertions(+), 20 deletions(-) create mode 100644 changelog.d/3278.fixed.md diff --git a/changelog.d/3278.fixed.md b/changelog.d/3278.fixed.md new file mode 100644 index 000000000..5779831d4 --- /dev/null +++ b/changelog.d/3278.fixed.md @@ -0,0 +1 @@ +A capability's stored failure reason no longer repeats a credential the user typed into the capability's own command or arguments, or under a header or environment name that promises one: a value after a credential-looking flag in a stdio server's `command`/`args` (the next token, the `--flag=value` form, or a `NAME=value` token), and the value of a header or environment name such as `sig`, `hmac` or `pass` — with `sig` and `pass` matched as whole segments, so `assign`, `compass` and `bypass` keep their values — is masked with `[hidden]` before the stored reason is cut at 300 characters, longest value first and a value under six characters left alone, so a failed server's own error line can no longer print that credential into the Bot's system prompt every turn ([#3278](https://github.com/ThinkFlowLab/FlyBot/issues/3278)). diff --git a/core/src/host/capabilities.js b/core/src/host/capabilities.js index a2bdae672..112c42b3e 100644 --- a/core/src/host/capabilities.js +++ b/core/src/host/capabilities.js @@ -48,20 +48,45 @@ const withoutUserinfo = text => text.replace(/([a-z][a-z0-9+.-]*:\/\/)[^/\s@]+@/ // value under six characters is left alone: replacing it everywhere would eat the words around it. // The literal is not refused at input instead — it is legal today, an entry saved before this exists // in the field, and what such a value may be kept at rest is the separate open question in #3276. -// `pat` counts as a whole segment: `X-Github-Pat` is a credential while `X-Patch-Id` and `X-Path-Id` -// are ordinary names that merely begin with the same three letters. -const CREDENTIAL_NAME = /(key|token|secret|auth|password|passwd|credential|signature|cookie|session|bearer)|(? { + const values = [] + const collect = (name, value) => { + if (typeof value === 'string' && value.length >= 6 && CREDENTIAL_NAME.test(name)) values.push(value) + } + for (const [name, value] of Object.entries({ ...config?.headers, ...config?.env })) collect(name, value) + const argv = [config?.command, ...(Array.isArray(config?.args) ? config.args : [])] + for (let index = 0; index < argv.length; index += 1) { + const token = argv[index] + if (typeof token !== 'string') continue + const inline = INLINE_FLAG.exec(token) + if (inline) { collect(inline[1], inline[2]); continue } + const assignment = ASSIGNMENT.exec(token) + if (assignment) { collect(assignment[1], assignment[2]); continue } + const flag = FLAG.exec(token) + const next = argv[index + 1] + if (!flag || !CREDENTIAL_NAME.test(flag[1]) || typeof next !== 'string' || next.startsWith('-')) continue + collect(flag[1], next) + index += 1 + } // Longest value first, the way `secrets.js` sorts its own before it builds one pattern: one // credential can contain another (`Bearer abc123XYZ` carries the `abc123` of the key beside it), // and replacing the short one first would leave the longer one's tail in the stored sentence. // Sorting makes the answer the same whichever order the two entries were written in. - const values = Object.entries({ ...config?.headers, ...config?.env }) - .filter(([name, value]) => CREDENTIAL_NAME.test(name) && typeof value === 'string' && value.length >= 6) - .map(([, value]) => value) - .sort((a, b) => b.length - a.length) let out = text - for (const value of values) out = out.split(value).join('[hidden]') + for (const value of [...new Set(values)].sort((a, b) => b.length - a.length)) out = out.split(value).join('[hidden]') return out } diff --git a/core/test/capabilities.test.js b/core/test/capabilities.test.js index 16ff2940c..5f19860e2 100644 --- a/core/test/capabilities.test.js +++ b/core/test/capabilities.test.js @@ -1,5 +1,5 @@ import assert from 'node:assert/strict' -import { mkdtempSync, rmSync, writeFileSync } from 'node:fs' +import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' import { test } from 'node:test' @@ -648,3 +648,188 @@ test('a plain reason is stored exactly as the transport gave it', async t => { assert.equal(status.state, 'error') assert.equal(status.error, '401 bad credentials') }) + +// #3278: a stdio server is started with the literal on its argv, and a failure to start quotes that +// argv back, so the mask reads the command and the args the way it reads a header: the token after a +// credential-looking flag is the literal, `--flag=value` is the same pair, and a `NAME=value` token is +// read as an assignment. An ordinary flag in the same argv keeps its value. +test('an error that quotes a stdio server argv stores the credential literal masked', async t => { + const state = team() + state.capabilities = { + items: { + stdio: { + name: 'stdio', kind: 'mcp', description: 'Local server', transport: 'stdio', command: 'node', + args: ['server.js', '--api-key', 'sk-live-abcdef123456', '-e', 'SERVICE_TOKEN=tok-abcdef123', '--password=hunter2-secret', '--verbose'], + env: {}, 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: 'stdio' }, 'worker') + const quoted = 'server exited: node server.js --api-key sk-live-abcdef123456 -e SERVICE_TOKEN=tok-abcdef123 --password=hunter2-secret --verbose' + ctx.emit('agent/created', { agent: testAgent('worker', mounts, skills, { awaitMount: async () => { throw new Error(quoted) } }) }) + await rt.scheduleCapabilitiesReconcile() + const status = rt.capabilityStatusesView().worker.stdio + assert.equal(status.state, 'error') + assert.equal( + status.error, + 'server exited: node server.js --api-key [hidden] -e SERVICE_TOKEN=[hidden] --password=[hidden] --verbose', + 'every argv literal is masked; the program and the ordinary flag survive', + ) + const stored = JSON.stringify(rt.capabilityStatusesView()) + assert.equal(stored.includes('sk-live-abcdef123456'), false) + assert.equal(stored.includes('tok-abcdef123'), false) + assert.equal(stored.includes('hunter2-secret'), false) +}) + +// #3278, from the security read at `48f1eb43`: `sig`, `hmac` and `pass` were still missing from the +// name list, so a body echoing `X-Sig: …`, `X-Hmac: …` or `X-Pass: …` stored the value verbatim. +// `sig` and `pass` count as a whole segment the way `pat` does, so `assign`, `compass` and `bypass` are +// ordinary names that keep their values. +test('a sig, hmac or pass header name masks its value while assign, compass and bypass keep theirs', async t => { + const state = team() + state.capabilities = quoting('name-echo', { + 'X-Sig': 'sig-abcdef123', 'X-Hmac': 'hmac-abcdef123', 'X-Pass': 'pass-abcdef123', + 'X-Assign': 'assign-9000', 'X-Compass': 'compass-9000', 'X-Bypass': 'bypass-9000', + }) + const env = await setup({ state }) + t.after(() => env.dispose()) + const { ctx, rt, mounts, skills } = env + await rt.changeCapabilityAttachment('attach', { name: 'name-echo' }, 'worker') + const quoted = 'Error POSTing to endpoint: {"sig":"sig-abcdef123","hmac":"hmac-abcdef123","pass":"pass-abcdef123","assign":"assign-9000","compass":"compass-9000","bypass":"bypass-9000"}' + ctx.emit('agent/created', { agent: testAgent('worker', mounts, skills, { awaitMount: async () => { throw new Error(quoted) } }) }) + await rt.scheduleCapabilitiesReconcile() + const status = rt.capabilityStatusesView().worker['name-echo'] + assert.equal(status.state, 'error') + assert.equal( + status.error, + 'Error POSTing to endpoint: {"sig":"[hidden]","hmac":"[hidden]","pass":"[hidden]","assign":"assign-9000","compass":"compass-9000","bypass":"bypass-9000"}', + 'the three new names mask; the three lookalike names keep their values', + ) + const stored = JSON.stringify(rt.capabilityStatusesView()) + assert.equal(stored.includes('sig-abcdef123'), false) + assert.equal(stored.includes('hmac-abcdef123'), false) + assert.equal(stored.includes('pass-abcdef123'), false) +}) + +// #3278: the two things #3275 fixed stay fixed — a value under six characters is left alone rather +// than eating the words around it, and the mask still runs before the 300-character cut, so a literal +// inside the kept part is gone and only the tail past the cut is dropped. +test('an argv literal under six characters stays and an argv literal is masked before the three-hundred cut', async t => { + const state = team() + state.capabilities = { + items: { + long: { + name: 'long', kind: 'mcp', description: 'Local server', transport: 'stdio', command: 'node', + args: ['server.js', '--pin', 'abcde', '--api-key', 'sk-live-abcdef123456'], + env: {}, 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: 'long' }, 'worker') + const quoted = `server exited: --pin abcde ${'x'.repeat(170)} --api-key sk-live-abcdef123456 ${'z'.repeat(200)}` + ctx.emit('agent/created', { agent: testAgent('worker', mounts, skills, { awaitMount: async () => { throw new Error(quoted) } }) }) + await rt.scheduleCapabilitiesReconcile() + const status = rt.capabilityStatusesView().worker.long + assert.equal(status.state, 'error') + assert.equal(status.error.length, 300, 'the stored reason is still cut at 300 characters') + assert.equal(status.error.startsWith('server exited: --pin abcde '), true, 'a five-character value is left alone') + assert.equal(status.error.includes('--api-key [hidden]'), true, 'the mask ran before the cut') + assert.equal(status.error.includes('sk-live-abcdef123456'), false) +}) + +// #3278 acceptance 2: the entry that fails here may have been saved before this fix, so the tests +// start from a store written by the old version and make one new start failure. The literal must be +// gone from every surface a reader can see — the status answer, the `list_capabilities` text, the +// system-prompt line and the log — and the first three must repeat the same masked sentence, which +// is what proves they read one stored reason built at one place (`capabilities.js:370`) instead of +// masking it four times. The saved config keeps the literal: the Settings editor reads it back by +// design, and #3276 owns that question. +const surfacesFor = async (env, name, warnings) => { + const status = env.rt.capabilityStatusesView().worker[name] ?? {} + return { + status: JSON.stringify(status), + listed: await env.ctx.registeredTools.get('list_capabilities').execute({}, { agent: { id: 'worker' } }), + prompt: env.ctx.sections.get('bot-capabilities').text({ agent: { id: 'worker' } }), + warnings: warnings.join('\n'), + } +} + +test('a stdio capability saved before this fix shows no argv or env literal on any surface', async t => { + const state = team() + state.capabilities = { + items: { + legacy: { + name: 'legacy', kind: 'mcp', description: 'Saved before this fix', transport: 'stdio', + command: 'node', args: ['server.js', '--api-key', 'sk-live-abcdef123456'], + env: { SERVICE_TOKEN: 'tok-abcdef123' }, approved: true, createdBy: 'worker', createdAt: 1, updatedAt: 1, + }, + }, + } + state.bots.worker.capabilities = ['legacy'] + const warnings = [] + const env = await setup({ state, beforeLoad: ({ ctx }) => { ctx.logger.warn = (...args) => warnings.push(args.join(' ')) } }) + t.after(() => env.dispose()) + const { ctx, rt, mounts, skills } = env + const quoted = 'server exited: node server.js --api-key sk-live-abcdef123456 -e SERVICE_TOKEN=tok-abcdef123' + ctx.emit('agent/created', { agent: testAgent('worker', mounts, skills, { awaitMount: async () => { throw new Error(quoted) } }) }) + await rt.scheduleCapabilitiesReconcile() + const masked = 'server exited: node server.js --api-key [hidden] -e SERVICE_TOKEN=[hidden]' + const surfaces = await surfacesFor(env, 'legacy', warnings) + for (const [surface, text] of Object.entries(surfaces)) { + for (const literal of ['sk-live-abcdef123456', 'tok-abcdef123']) { + assert.equal(text.includes(literal), false, `${surface} carries no literal`) + } + } + const status = rt.capabilityStatusesView().worker.legacy + assert.equal(status.state, 'error') + assert.equal(status.error, masked, 'one masked sentence, built once') + assert.equal(surfaces.listed.includes(masked), true, 'the tool listing repeats the stored reason') + assert.equal(surfaces.prompt.includes(masked), true, 'the prompt line repeats the stored reason') + // The reason is not part of the team state, so nothing rewrites it at rest and no migration exists. + await rt.save() + const saved = JSON.parse(readFileSync(join(env.home, 'state.json'), 'utf8')) + assert.equal(JSON.stringify(saved).includes('[hidden]'), false, 'the masked reason is memory-only') + assert.deepEqual(saved.capabilities.items.legacy.args, ['server.js', '--api-key', 'sk-live-abcdef123456'], 'the config itself is unchanged') + // Detaching the item empties every line, which is the proof that the store is their only source. + await rt.changeCapabilityAttachment('detach', { name: 'legacy', bot: 'Worker' }, 'chief') + await rt.scheduleCapabilitiesReconcile() + assert.equal(JSON.stringify(rt.capabilityStatusesView()).includes(masked), false) + assert.equal(ctx.sections.get('bot-capabilities').text({ agent: { id: 'worker' } }), '') +}) + +test('an http capability saved before this fix shows no header literal on any surface', async t => { + const state = team() + state.capabilities = { + items: { + legacy: { + name: 'legacy', kind: 'mcp', description: 'Saved before this fix', transport: 'streamable-http', + url: 'https://host/mcp', headers: { 'X-Sig': 'sig-abcdef123', Accept: 'application/json' }, + approved: true, createdBy: 'worker', createdAt: 1, updatedAt: 1, + }, + }, + } + state.bots.worker.capabilities = ['legacy'] + const warnings = [] + const env = await setup({ state, beforeLoad: ({ ctx }) => { ctx.logger.warn = (...args) => warnings.push(args.join(' ')) } }) + t.after(() => env.dispose()) + const { ctx, rt, mounts, skills } = env + const quoted = 'Error POSTing to endpoint: {"sig":"sig-abcdef123","accept":"application/json"}' + ctx.emit('agent/created', { agent: testAgent('worker', mounts, skills, { awaitMount: async () => { throw new Error(quoted) } }) }) + await rt.scheduleCapabilitiesReconcile() + const masked = 'Error POSTing to endpoint: {"sig":"[hidden]","accept":"application/json"}' + const surfaces = await surfacesFor(env, 'legacy', warnings) + for (const [surface, text] of Object.entries(surfaces)) { + assert.equal(text.includes('sig-abcdef123'), false, `${surface} carries no literal`) + } + const status = rt.capabilityStatusesView().worker.legacy + assert.equal(status.state, 'error') + assert.equal(status.error, masked, 'one masked sentence, built once; an ordinary header survives') + assert.equal(surfaces.listed.includes(masked), true) + assert.equal(surfaces.prompt.includes(masked), true) +}) diff --git a/docs/subsystems/core-host.md b/docs/subsystems/core-host.md index 1bdba1b7d..1e1b68ff6 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. 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). A transport builds its error from the server's own response body, so a server that echoes a request header or an environment value writes that literal into the stored reason; a configured name that promises a credential (`key`, `token`, `secret`, `auth`, `password`, `passwd`, `credential`, `signature`, `cookie`, `session`, `bearer`, and `pat` as a whole segment, so `X-Github-Pat` counts and `X-Patch-Id` does not) masks its own value wherever the body repeats it before that same cut, longest value first so one credential ends whole and never merely its head, and a value under six characters is left alone rather than replace ordinary words (#3275). | +| `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). A transport builds its error from the server's own response body, so a server that echoes a request header or an environment value writes that literal into the stored reason; a configured name that promises a credential (`key`, `token`, `secret`, `auth`, `password`, `passwd`, `credential`, `signature`, `cookie`, `session`, `bearer`, `hmac`, and `pat`, `sig` and `pass` as whole segments, so `X-Github-Pat`, `X-Sig` and `X-Pass` count while `X-Patch-Id`, `assign`, `compass` and `bypass` do not) masks its own value wherever the body repeats it before that same cut, longest value first so one credential ends whole and never merely its head, and a value under six characters is left alone rather than replace ordinary words (#3275). A stdio server is started with the literal on its argv, so the same mask reads `command` and `args` too: the token after a credential-looking flag, the `--flag=value` form and a `NAME=value` token are masked the same way, while an ordinary flag and a bare program name keep their text (#3278). | | `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 4915ccecb..3785cb28e 100644 --- a/patches/ds-bot/0001-core-fixes.patch +++ b/patches/ds-bot/0001-core-fixes.patch @@ -4544,7 +4544,7 @@ diff --git a/src/host/capabilities.js b/src/host/capabilities.js } return name } -@@ -33,6 +33,35 @@ export function expandCapabilityNames(capabilities, library) { +@@ -33,6 +33,60 @@ export function expandCapabilityNames(capabilities, library) { return expanded } @@ -4560,20 +4560,45 @@ diff --git a/src/host/capabilities.js b/src/host/capabilities.js +// value under six characters is left alone: replacing it everywhere would eat the words around it. +// The literal is not refused at input instead — it is legal today, an entry saved before this exists +// in the field, and what such a value may be kept at rest is the separate open question in #3276. -+// `pat` counts as a whole segment: `X-Github-Pat` is a credential while `X-Patch-Id` and `X-Path-Id` -+// are ordinary names that merely begin with the same three letters. -+const CREDENTIAL_NAME = /(key|token|secret|auth|password|passwd|credential|signature|cookie|session|bearer)|(? { ++ const values = [] ++ const collect = (name, value) => { ++ if (typeof value === 'string' && value.length >= 6 && CREDENTIAL_NAME.test(name)) values.push(value) ++ } ++ for (const [name, value] of Object.entries({ ...config?.headers, ...config?.env })) collect(name, value) ++ const argv = [config?.command, ...(Array.isArray(config?.args) ? config.args : [])] ++ for (let index = 0; index < argv.length; index += 1) { ++ const token = argv[index] ++ if (typeof token !== 'string') continue ++ const inline = INLINE_FLAG.exec(token) ++ if (inline) { collect(inline[1], inline[2]); continue } ++ const assignment = ASSIGNMENT.exec(token) ++ if (assignment) { collect(assignment[1], assignment[2]); continue } ++ const flag = FLAG.exec(token) ++ const next = argv[index + 1] ++ if (!flag || !CREDENTIAL_NAME.test(flag[1]) || typeof next !== 'string' || next.startsWith('-')) continue ++ collect(flag[1], next) ++ index += 1 ++ } + // Longest value first, the way `secrets.js` sorts its own before it builds one pattern: one + // credential can contain another (`Bearer abc123XYZ` carries the `abc123` of the key beside it), + // and replacing the short one first would leave the longer one's tail in the stored sentence. + // Sorting makes the answer the same whichever order the two entries were written in. -+ const values = Object.entries({ ...config?.headers, ...config?.env }) -+ .filter(([name, value]) => CREDENTIAL_NAME.test(name) && typeof value === 'string' && value.length >= 6) -+ .map(([, value]) => value) -+ .sort((a, b) => b.length - a.length) + let out = text -+ for (const value of values) out = out.split(value).join('[hidden]') ++ for (const value of [...new Set(values)].sort((a, b) => b.length - a.length)) out = out.split(value).join('[hidden]') + return out +} + diff --git a/patches/ds-bot/0014-flybot-branding.patch b/patches/ds-bot/0014-flybot-branding.patch index f2d32c7cc..5bec9402e 100644 --- a/patches/ds-bot/0014-flybot-branding.patch +++ b/patches/ds-bot/0014-flybot-branding.patch @@ -2021,6 +2021,13 @@ diff --git a/test/browser-channel.test.js b/test/browser-channel.test.js diff --git a/test/capabilities.test.js b/test/capabilities.test.js --- a/test/capabilities.test.js +++ b/test/capabilities.test.js +@@ -1,5 +1,5 @@ + import assert from 'node:assert/strict' +-import { mkdtempSync, rmSync, writeFileSync } from 'node:fs' ++import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs' + import { tmpdir } from 'node:os' + import { join } from 'node:path' + import { test } from 'node:test' @@ -88,10 +88,15 @@ async function setup({ state = team(), secret, beforeLoad } = {}) { } } @@ -2047,7 +2054,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,221 @@ test('mounts agent-only MCP and skills, remounts changed config, resolves scoped +@@ -425,3 +425,406 @@ 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) }) @@ -2269,6 +2276,191 @@ diff --git a/test/capabilities.test.js b/test/capabilities.test.js + assert.equal(status.state, 'error') + assert.equal(status.error, '401 bad credentials') +}) ++ ++// #3278: a stdio server is started with the literal on its argv, and a failure to start quotes that ++// argv back, so the mask reads the command and the args the way it reads a header: the token after a ++// credential-looking flag is the literal, `--flag=value` is the same pair, and a `NAME=value` token is ++// read as an assignment. An ordinary flag in the same argv keeps its value. ++test('an error that quotes a stdio server argv stores the credential literal masked', async t => { ++ const state = team() ++ state.capabilities = { ++ items: { ++ stdio: { ++ name: 'stdio', kind: 'mcp', description: 'Local server', transport: 'stdio', command: 'node', ++ args: ['server.js', '--api-key', 'sk-live-abcdef123456', '-e', 'SERVICE_TOKEN=tok-abcdef123', '--password=hunter2-secret', '--verbose'], ++ env: {}, 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: 'stdio' }, 'worker') ++ const quoted = 'server exited: node server.js --api-key sk-live-abcdef123456 -e SERVICE_TOKEN=tok-abcdef123 --password=hunter2-secret --verbose' ++ ctx.emit('agent/created', { agent: testAgent('worker', mounts, skills, { awaitMount: async () => { throw new Error(quoted) } }) }) ++ await rt.scheduleCapabilitiesReconcile() ++ const status = rt.capabilityStatusesView().worker.stdio ++ assert.equal(status.state, 'error') ++ assert.equal( ++ status.error, ++ 'server exited: node server.js --api-key [hidden] -e SERVICE_TOKEN=[hidden] --password=[hidden] --verbose', ++ 'every argv literal is masked; the program and the ordinary flag survive', ++ ) ++ const stored = JSON.stringify(rt.capabilityStatusesView()) ++ assert.equal(stored.includes('sk-live-abcdef123456'), false) ++ assert.equal(stored.includes('tok-abcdef123'), false) ++ assert.equal(stored.includes('hunter2-secret'), false) ++}) ++ ++// #3278, from the security read at `48f1eb43`: `sig`, `hmac` and `pass` were still missing from the ++// name list, so a body echoing `X-Sig: …`, `X-Hmac: …` or `X-Pass: …` stored the value verbatim. ++// `sig` and `pass` count as a whole segment the way `pat` does, so `assign`, `compass` and `bypass` are ++// ordinary names that keep their values. ++test('a sig, hmac or pass header name masks its value while assign, compass and bypass keep theirs', async t => { ++ const state = team() ++ state.capabilities = quoting('name-echo', { ++ 'X-Sig': 'sig-abcdef123', 'X-Hmac': 'hmac-abcdef123', 'X-Pass': 'pass-abcdef123', ++ 'X-Assign': 'assign-9000', 'X-Compass': 'compass-9000', 'X-Bypass': 'bypass-9000', ++ }) ++ const env = await setup({ state }) ++ t.after(() => env.dispose()) ++ const { ctx, rt, mounts, skills } = env ++ await rt.changeCapabilityAttachment('attach', { name: 'name-echo' }, 'worker') ++ const quoted = 'Error POSTing to endpoint: {"sig":"sig-abcdef123","hmac":"hmac-abcdef123","pass":"pass-abcdef123","assign":"assign-9000","compass":"compass-9000","bypass":"bypass-9000"}' ++ ctx.emit('agent/created', { agent: testAgent('worker', mounts, skills, { awaitMount: async () => { throw new Error(quoted) } }) }) ++ await rt.scheduleCapabilitiesReconcile() ++ const status = rt.capabilityStatusesView().worker['name-echo'] ++ assert.equal(status.state, 'error') ++ assert.equal( ++ status.error, ++ 'Error POSTing to endpoint: {"sig":"[hidden]","hmac":"[hidden]","pass":"[hidden]","assign":"assign-9000","compass":"compass-9000","bypass":"bypass-9000"}', ++ 'the three new names mask; the three lookalike names keep their values', ++ ) ++ const stored = JSON.stringify(rt.capabilityStatusesView()) ++ assert.equal(stored.includes('sig-abcdef123'), false) ++ assert.equal(stored.includes('hmac-abcdef123'), false) ++ assert.equal(stored.includes('pass-abcdef123'), false) ++}) ++ ++// #3278: the two things #3275 fixed stay fixed — a value under six characters is left alone rather ++// than eating the words around it, and the mask still runs before the 300-character cut, so a literal ++// inside the kept part is gone and only the tail past the cut is dropped. ++test('an argv literal under six characters stays and an argv literal is masked before the three-hundred cut', async t => { ++ const state = team() ++ state.capabilities = { ++ items: { ++ long: { ++ name: 'long', kind: 'mcp', description: 'Local server', transport: 'stdio', command: 'node', ++ args: ['server.js', '--pin', 'abcde', '--api-key', 'sk-live-abcdef123456'], ++ env: {}, 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: 'long' }, 'worker') ++ const quoted = `server exited: --pin abcde ${'x'.repeat(170)} --api-key sk-live-abcdef123456 ${'z'.repeat(200)}` ++ ctx.emit('agent/created', { agent: testAgent('worker', mounts, skills, { awaitMount: async () => { throw new Error(quoted) } }) }) ++ await rt.scheduleCapabilitiesReconcile() ++ const status = rt.capabilityStatusesView().worker.long ++ assert.equal(status.state, 'error') ++ assert.equal(status.error.length, 300, 'the stored reason is still cut at 300 characters') ++ assert.equal(status.error.startsWith('server exited: --pin abcde '), true, 'a five-character value is left alone') ++ assert.equal(status.error.includes('--api-key [hidden]'), true, 'the mask ran before the cut') ++ assert.equal(status.error.includes('sk-live-abcdef123456'), false) ++}) ++ ++// #3278 acceptance 2: the entry that fails here may have been saved before this fix, so the tests ++// start from a store written by the old version and make one new start failure. The literal must be ++// gone from every surface a reader can see — the status answer, the `list_capabilities` text, the ++// system-prompt line and the log — and the first three must repeat the same masked sentence, which ++// is what proves they read one stored reason built at one place (`capabilities.js:370`) instead of ++// masking it four times. The saved config keeps the literal: the Settings editor reads it back by ++// design, and #3276 owns that question. ++const surfacesFor = async (env, name, warnings) => { ++ const status = env.rt.capabilityStatusesView().worker[name] ?? {} ++ return { ++ status: JSON.stringify(status), ++ listed: await env.ctx.registeredTools.get('list_capabilities').execute({}, { agent: { id: 'worker' } }), ++ prompt: env.ctx.sections.get('bot-capabilities').text({ agent: { id: 'worker' } }), ++ warnings: warnings.join('\n'), ++ } ++} ++ ++test('a stdio capability saved before this fix shows no argv or env literal on any surface', async t => { ++ const state = team() ++ state.capabilities = { ++ items: { ++ legacy: { ++ name: 'legacy', kind: 'mcp', description: 'Saved before this fix', transport: 'stdio', ++ command: 'node', args: ['server.js', '--api-key', 'sk-live-abcdef123456'], ++ env: { SERVICE_TOKEN: 'tok-abcdef123' }, approved: true, createdBy: 'worker', createdAt: 1, updatedAt: 1, ++ }, ++ }, ++ } ++ state.bots.worker.capabilities = ['legacy'] ++ const warnings = [] ++ const env = await setup({ state, beforeLoad: ({ ctx }) => { ctx.logger.warn = (...args) => warnings.push(args.join(' ')) } }) ++ t.after(() => env.dispose()) ++ const { ctx, rt, mounts, skills } = env ++ const quoted = 'server exited: node server.js --api-key sk-live-abcdef123456 -e SERVICE_TOKEN=tok-abcdef123' ++ ctx.emit('agent/created', { agent: testAgent('worker', mounts, skills, { awaitMount: async () => { throw new Error(quoted) } }) }) ++ await rt.scheduleCapabilitiesReconcile() ++ const masked = 'server exited: node server.js --api-key [hidden] -e SERVICE_TOKEN=[hidden]' ++ const surfaces = await surfacesFor(env, 'legacy', warnings) ++ for (const [surface, text] of Object.entries(surfaces)) { ++ for (const literal of ['sk-live-abcdef123456', 'tok-abcdef123']) { ++ assert.equal(text.includes(literal), false, `${surface} carries no literal`) ++ } ++ } ++ const status = rt.capabilityStatusesView().worker.legacy ++ assert.equal(status.state, 'error') ++ assert.equal(status.error, masked, 'one masked sentence, built once') ++ assert.equal(surfaces.listed.includes(masked), true, 'the tool listing repeats the stored reason') ++ assert.equal(surfaces.prompt.includes(masked), true, 'the prompt line repeats the stored reason') ++ // The reason is not part of the team state, so nothing rewrites it at rest and no migration exists. ++ await rt.save() ++ const saved = JSON.parse(readFileSync(join(env.home, 'state.json'), 'utf8')) ++ assert.equal(JSON.stringify(saved).includes('[hidden]'), false, 'the masked reason is memory-only') ++ assert.deepEqual(saved.capabilities.items.legacy.args, ['server.js', '--api-key', 'sk-live-abcdef123456'], 'the config itself is unchanged') ++ // Detaching the item empties every line, which is the proof that the store is their only source. ++ await rt.changeCapabilityAttachment('detach', { name: 'legacy', bot: 'Worker' }, 'chief') ++ await rt.scheduleCapabilitiesReconcile() ++ assert.equal(JSON.stringify(rt.capabilityStatusesView()).includes(masked), false) ++ assert.equal(ctx.sections.get('bot-capabilities').text({ agent: { id: 'worker' } }), '') ++}) ++ ++test('an http capability saved before this fix shows no header literal on any surface', async t => { ++ const state = team() ++ state.capabilities = { ++ items: { ++ legacy: { ++ name: 'legacy', kind: 'mcp', description: 'Saved before this fix', transport: 'streamable-http', ++ url: 'https://host/mcp', headers: { 'X-Sig': 'sig-abcdef123', Accept: 'application/json' }, ++ approved: true, createdBy: 'worker', createdAt: 1, updatedAt: 1, ++ }, ++ }, ++ } ++ state.bots.worker.capabilities = ['legacy'] ++ const warnings = [] ++ const env = await setup({ state, beforeLoad: ({ ctx }) => { ctx.logger.warn = (...args) => warnings.push(args.join(' ')) } }) ++ t.after(() => env.dispose()) ++ const { ctx, rt, mounts, skills } = env ++ const quoted = 'Error POSTing to endpoint: {"sig":"sig-abcdef123","accept":"application/json"}' ++ ctx.emit('agent/created', { agent: testAgent('worker', mounts, skills, { awaitMount: async () => { throw new Error(quoted) } }) }) ++ await rt.scheduleCapabilitiesReconcile() ++ const masked = 'Error POSTing to endpoint: {"sig":"[hidden]","accept":"application/json"}' ++ const surfaces = await surfacesFor(env, 'legacy', warnings) ++ for (const [surface, text] of Object.entries(surfaces)) { ++ assert.equal(text.includes('sig-abcdef123'), false, `${surface} carries no literal`) ++ } ++ const status = rt.capabilityStatusesView().worker.legacy ++ assert.equal(status.state, 'error') ++ assert.equal(status.error, masked, 'one masked sentence, built once; an ordinary header survives') ++ assert.equal(surfaces.listed.includes(masked), true) ++ assert.equal(surfaces.prompt.includes(masked), true) ++}) 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