mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-02 05:54:44 +00:00
fix(agent): activate bash tool after skill load and fix chat stream
Two bugs found while testing skill loading as a non-owner: 1. The injected bash tool was never actually usable: AgentHarness.setTools only updates the tool registry unless activeToolNames is passed, so bash was missing from the active tool set sent to the model on the next turn. Pass the full post-update tool list as activeToolNames. 2. The active_tools_change session entry (written by setTools) has no chat representation, so mapEntryToMessage fell back to fabricating an empty user message that appeared as a stray empty bubble in the chat stream. Render active_tools_change as a typed custom message and skip entry types that have no chat representation instead of emitting empty text.
This commit is contained in:
@@ -766,10 +766,14 @@ describe('createAgentSession bash restriction for non-owner users', () => {
|
||||
const readSkillTool = harness.getTools().find((t) => t.name === 'read_skill')
|
||||
expect(readSkillTool).toBeDefined()
|
||||
expect(harness.getTools().some((t) => t.name === 'bash')).toBe(false)
|
||||
expect(harness.getActiveTools().some((t) => t.name === 'bash')).toBe(false)
|
||||
|
||||
await readSkillTool!.execute('1', { skillId: skill.id }, undefined, undefined, undefined)
|
||||
|
||||
expect(harness.getTools().some((t) => t.name === 'bash')).toBe(true)
|
||||
// bash must be part of the ACTIVE tool set, not just the registry, or the model
|
||||
// would never receive it on the next turn
|
||||
expect(harness.getActiveTools().some((t) => t.name === 'bash')).toBe(true)
|
||||
})
|
||||
|
||||
it('should not inject the bash tool for restricted users when bash is in deniedTools', async () => {
|
||||
|
||||
@@ -304,7 +304,13 @@ export async function createAgentSession(params: CreateAgentSessionParams) {
|
||||
if (!harness || bashInjected || deniedTools.includes('bash')) return
|
||||
if (harness.getTools().some((t) => t.name === 'bash')) return
|
||||
bashInjected = true
|
||||
await harness.setTools([...harness.getTools(), sandboxedBash])
|
||||
// Pass the full post-update tool list as activeToolNames: setTools only updates the
|
||||
// registry otherwise, and the model would never see the bash tool on the next turn.
|
||||
const next = [...harness.getTools(), sandboxedBash]
|
||||
await harness.setTools(
|
||||
next,
|
||||
next.map((t) => t.name),
|
||||
)
|
||||
}
|
||||
const readSkill = createReadSkillTool(userId, onEnvsAdded, restricted ? onSkillLoaded : undefined)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user