π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(agent-share): tell visitor runs up front that lh is unavailable (#21300)
YuTengjing1ee143900cdf
diff --git a/apps/server/src/services/aiAgent/shareGate/README.md b/apps/server/src/services/aiAgent/shareGate/README.mdindex 712cb1cbdb6..149461570d2 100644--- a/apps/server/src/services/aiAgent/shareGate/README.md+++ b/apps/server/src/services/aiAgent/shareGate/README.md@@ -114,7 +114,11 @@ absence of a known exploit.`agentShareVisitor` runs (`serverRuntimes/cloudSandbox.ts`), and`lobe-creds` stays denied above so nothing ever writes `~/.creds/env`into that session either. No creator credential or JWT is therefore- reachable from inside a visitor's sandbox command.+ reachable from inside a visitor's sandbox command. The kept manifest's+ `systemRole` also gets `shareVisitorSystemPrompt` appended+ (`applyShareGateToCloudSandbox` in `toolSet.ts`), so the model knows `lh`+ is refused before it plans a flow the agent prompt or a skill routes+ through the CLI.- `lobe-activator`: widens the run's tool surface at runtime, so it isallowed only because every source it reads is already the gated set.diff --git a/apps/server/src/services/aiAgent/shareGate/toolSet.cloudSandbox.test.ts b/apps/server/src/services/aiAgent/shareGate/toolSet.cloudSandbox.test.tsnew file mode 100644index 00000000000..2506a91f9f7--- /dev/null+++ b/apps/server/src/services/aiAgent/shareGate/toolSet.cloudSandbox.test.ts@@ -0,0 +1,58 @@+import {+ CloudSandboxIdentifier,+ shareVisitorSystemPrompt,+ systemPrompt as cloudSandboxSystemPrompt,+} from '@lobechat/builtin-tool-cloud-sandbox';+import { describe, expect, it } from 'vitest';++import { applyShareGateToToolSet } from '.';+import { buildGate, buildToolSet } from './testUtils';++describe('applyShareGateToToolSet β lobe-cloud-sandbox', () => {+ const buildSandboxToolSet = (systemRole?: string) => {+ const toolSet = buildToolSet([+ { apis: [{ name: 'runCommand' }], identifier: CloudSandboxIdentifier },+ ]);+ toolSet.manifestMap[CloudSandboxIdentifier].systemRole = systemRole;+ return toolSet;+ };++ const gate = buildGate({ toolGrants: [{ identifier: CloudSandboxIdentifier }] });++ it('tells the model up front that lh is unavailable, keeping the default guidance', () => {+ const toolSet = buildSandboxToolSet(cloudSandboxSystemPrompt);++ applyShareGateToToolSet(toolSet, gate);++ const { systemRole } = toolSet.manifestMap[CloudSandboxIdentifier];+ expect(systemRole).toBe(`${cloudSandboxSystemPrompt}\n\n${shareVisitorSystemPrompt}`);+ expect(systemRole).toContain('`lh`');+ });++ it('still adds the notice when the manifest carries no systemRole', () => {+ const toolSet = buildSandboxToolSet();++ applyShareGateToToolSet(toolSet, gate);++ expect(toolSet.manifestMap[CloudSandboxIdentifier].systemRole).toBe(shareVisitorSystemPrompt);+ });++ it('does not repeat the notice when the gate runs again', () => {+ const toolSet = buildSandboxToolSet(cloudSandboxSystemPrompt);++ applyShareGateToToolSet(toolSet, gate);+ applyShareGateToToolSet(toolSet, gate);++ expect(toolSet.manifestMap[CloudSandboxIdentifier].systemRole).toBe(+ `${cloudSandboxSystemPrompt}\n\n${shareVisitorSystemPrompt}`,+ );+ });++ it('adds nothing when the sandbox is not granted', () => {+ const toolSet = buildSandboxToolSet(cloudSandboxSystemPrompt);++ applyShareGateToToolSet(toolSet, buildGate({ toolGrants: [] }));++ expect(toolSet.manifestMap[CloudSandboxIdentifier]).toBeUndefined();+ });+});diff --git a/apps/server/src/services/aiAgent/shareGate/toolSet.ts b/apps/server/src/services/aiAgent/shareGate/toolSet.tsindex fbc6e998fd2..7e57fbca807 100644--- a/apps/server/src/services/aiAgent/shareGate/toolSet.ts+++ b/apps/server/src/services/aiAgent/shareGate/toolSet.ts@@ -2,6 +2,10 @@ import {getSystemPromptForShareVisitor as getActivatorSystemPromptForShareVisitor,LobeActivatorIdentifier,} from '@lobechat/builtin-tool-activator';+import {+ CloudSandboxIdentifier,+ shareVisitorSystemPrompt as cloudSandboxShareVisitorSystemPrompt,+} from '@lobechat/builtin-tool-cloud-sandbox';import { SkillsIdentifier } from '@lobechat/builtin-tool-skills';import { hasShareToolGrant, PLUGIN_SCHEMA_SEPARATOR, type ShareToolGrant } from '@lobechat/const';import { isDeviceOnlyMcpEndpoint } from '@lobechat/utils/mcpEndpoint';@@ -143,6 +147,27 @@ export const applyShareGateToToolSet = (toolSet: ShareGateToolSet, gate: AgentShapplyShareGateToDataToolAccess(toolSet, gate);applyShareGateToPerApiGrants(toolSet, grants);applyShareGateToActivator(toolSet);+ applyShareGateToCloudSandbox(toolSet);+};++/**+ * Tell a kept cloud sandbox's model up front that `lh` is refused here, so a+ * flow the agent prompt or a skill routes through the CLI is redirected to a+ * granted native tool, or declared out of scope before the visitor invests in+ * its earlier steps. Appended rather than substituted: the default sandbox+ * guidance still applies, and a partial API strip may already have replaced+ * the `systemRole` with a narrower one.+ */+const applyShareGateToCloudSandbox = (toolSet: ShareGateToolSet): void => {+ const manifest = toolSet.manifestMap[CloudSandboxIdentifier];+ if (!manifest || manifest.systemRole?.includes(cloudSandboxShareVisitorSystemPrompt)) return;++ toolSet.manifestMap[CloudSandboxIdentifier] = {+ ...manifest,+ systemRole: [manifest.systemRole, cloudSandboxShareVisitorSystemPrompt]+ .filter(Boolean)+ .join('\n\n'),+ };};/**diff --git a/packages/builtin-tool-cloud-sandbox/src/systemRole.ts b/packages/builtin-tool-cloud-sandbox/src/systemRole.tsindex 0f1b0e8205b..a270e265af7 100644--- a/packages/builtin-tool-cloud-sandbox/src/systemRole.ts+++ b/packages/builtin-tool-cloud-sandbox/src/systemRole.ts@@ -238,3 +238,17 @@ When generating PDFs with Chinese text, you MUST:- Use visual indicators (β π₯ π) to make exported files stand out</response_format>`;++/**+ * Appended to the sandbox `systemRole` for Agent Share visitor runs, where every+ * `lh` invocation is refused so a visitor-controlled shell never receives the+ * creator's JWT. Without it the model only learns this when the command fails,+ * often after the visitor has already worked through earlier steps of a flow+ * that the agent prompt or a skill routed through `lh` (LOBE-14770).+ */+export const shareVisitorSystemPrompt = `<shared_conversation>+This is a shared conversation: the user is a visitor of an agent that someone else published.+- The LobeHub CLI (\`lh\`) cannot run in this sandbox. Every \`lh\` command is refused, so do not run, retry, or probe it.+- When the agent instructions or a skill route a capability through \`lh\` (for example \`lh gen video\` or \`lh gen image\`), use the matching tool you were given instead, such as a video or image generation tool, when one is available.+- When no available tool covers a requested capability, tell the user before starting the work which part cannot be delivered in this conversation, then continue only with the parts you can deliver. Do not hand the user a command to run elsewhere as a substitute for the deliverable.+</shared_conversation>`;