π€― 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
refactor(creds): add local/desktop credential injection guidance (#14306)
LiJian5a15f759d626
diff --git a/packages/builtin-tool-activator/src/systemRole.ts b/packages/builtin-tool-activator/src/systemRole.tsindex e1b4a8ed177..ea617de0032 100644--- a/packages/builtin-tool-activator/src/systemRole.ts+++ b/packages/builtin-tool-activator/src/systemRole.ts@@ -83,9 +83,16 @@ export const systemPrompt = `You have access to a Tools Activator that allows yo- Never ask users to paste API keys directly in chat β always use \`lobe-creds\` to store them securely- \`lobe-creds\` works together with \`lobe-cloud-sandbox\` for secure credential injection-**Credential Injection Locations:**+**Credential Usage by Runtime:**++In cloud sandbox (\`injectCredsToSandbox\` available):- Environment-based credentials (oauth, kv-env, kv-header) β \`~/.creds/env\` β use \`runCommand\` with \`bash -c "source ~/.creds/env && your_command"\`- File-based credentials β \`~/.creds/files/{key}/{filename}\` β use file path directly in your code++On desktop/local (no sandbox, \`injectCredsToSandbox\` NOT available):+- Use \`getPlaintextCred\` to retrieve values, then pass as inline env vars in \`runCommand\`+- Example: \`runCommand({ command: "GITHUB_TOKEN='xxx' gh repo list" })\`+- File credentials: use \`getPlaintextCred\` to get the file path from the response state</credentials_management><best_practices>diff --git a/packages/builtin-tool-creds/src/manifest.ts b/packages/builtin-tool-creds/src/manifest.tsindex 4418c97cd3a..55ee30bef1a 100644--- a/packages/builtin-tool-creds/src/manifest.ts+++ b/packages/builtin-tool-creds/src/manifest.ts@@ -45,7 +45,7 @@ export const CredsManifest: BuiltinToolManifest = {},{description:- 'Retrieve the plaintext value of a stored credential by its key. Use this when you need to access a credential for making API calls or other operations. Only call this when you actually need the credential value.',+ 'Retrieve the plaintext value of a stored credential by its key. Use this when you need to access a credential for making API calls or other operations. Only call this when you actually need the credential value. On desktop/local (no sandbox), use this to retrieve credentials and pass them to runCommand as inline environment variables.',name: CredsApiName.getPlaintextCred,parameters: {additionalProperties: false,@@ -65,7 +65,7 @@ export const CredsManifest: BuiltinToolManifest = {},{description:- 'Inject credentials into the sandbox environment as environment variables. Only available when sandbox mode is enabled. Use this before running code that requires credentials.',+ 'Inject credentials into the sandbox environment as environment variables. Only available when sandbox mode is enabled β do NOT call this on desktop/local. Use this before running code that requires credentials. For desktop/local, use getPlaintextCred instead.',name: CredsApiName.injectCredsToSandbox,parameters: {additionalProperties: false,diff --git a/packages/builtin-tool-creds/src/systemRole.ts b/packages/builtin-tool-creds/src/systemRole.tsindex 92dee2c18a8..1508d68c5c8 100644--- a/packages/builtin-tool-creds/src/systemRole.ts+++ b/packages/builtin-tool-creds/src/systemRole.ts@@ -21,7 +21,7 @@ Sandbox mode: {{sandbox_enabled}}1. **Awareness**: Know what credentials the user has configured and suggest relevant ones when needed.2. **Guidance**: When you detect sensitive information (API keys, tokens, passwords) in the conversation, guide the user to save them securely in LobeHub.3. **Secure Access**: Use \`getPlaintextCred\` only when you actually need the credential value for an operation.-4. **Sandbox Integration**: When running code in sandbox, use \`injectCredsToSandbox\` to make credentials available to the sandbox environment.+4. **Runtime Integration**: When sandbox mode is enabled, use \`injectCredsToSandbox\` to inject credentials. On desktop/local (sandbox disabled), use \`getPlaintextCred\` and pass values as inline env vars to \`runCommand\`.</core_responsibilities><tooling>@@ -69,6 +69,8 @@ When suggesting to save, always:</credential_saving_triggers><sandbox_integration>+**Only applies when sandbox mode is enabled (current value: {{sandbox_enabled}}).**+When sandbox mode is enabled and you need to run code that requires credentials:1. Check if the required credential is in the available credentials list2. Use \`injectCredsToSandbox\` to inject the credential before running code@@ -93,6 +95,42 @@ When sandbox mode is enabled and you need to run code that requires credentials:- Use the file path directly in your code (e.g., \`GOOGLE_APPLICATION_CREDENTIALS=~/.creds/files/gcp-service-account/credentials.json\`)</sandbox_integration>+<local_integration>+**Only applies when sandbox mode is NOT enabled (desktop/local environment).**++When running on desktop or local (sandbox NOT enabled), use credentials with local tools:++1. Call \`getPlaintextCred\` to retrieve the credential values+ - The credential values will be available in the response state as \`values\` (Record<string, string>)+2. Use \`runCommand\` (lobe-local-system) with the \`env\` parameter:+ - Pass the credential values via the \`env\` parameter β it is merged into the child process environment+ - NEVER embed secret values in the \`command\` string β they'd be visible in the UI and logs+3. Always prefer \`getPlaintextCred\` over asking the user for credentials++**Difference from sandbox mode:**+- Sandbox: \`injectCredsToSandbox\` writes to \`~/.creds/env\`, then \`source ~/.creds/env && cmd\`+- Local: \`getPlaintextCred\` returns values in state β pass via \`runCommand\`'s \`env\` parameter++**Example for local execution:**+\`\`\`+// 1. Get credential first+const cred = getPlaintextCred({ key: "github" })+// cred.state.values = { GITHUB_TOKEN: "ghp_xxx" }++// 2. Use env parameter (NOT inline in command string)+runCommand({+ command: "gh repo list",+ env: cred.state.values,+ description: "List repos"+})+\`\`\`++**Important:**+- Never pass credential values in the \`command\` string β use the \`env\` parameter of \`runCommand\` instead+- Never pass credential values to \`executeCode\` β it runs in an isolated process without env support+- File credentials: \`getPlaintextCred\` returns a \`fileUrl\` (download URL) in state β use \`runCommand\` with \`curl\` or \`writeLocalFile\` to save the file locally first, then reference the local path+</local_integration>+<klavis_integrations>{{KLAVIS_SERVICES_LIST}}</klavis_integrations>diff --git a/packages/builtin-tool-local-system/src/manifest.ts b/packages/builtin-tool-local-system/src/manifest.tsindex 93bc062b68f..48d9c1ed4f8 100644--- a/packages/builtin-tool-local-system/src/manifest.ts+++ b/packages/builtin-tool-local-system/src/manifest.ts@@ -298,6 +298,12 @@ export const LocalSystemManifest: BuiltinToolManifest = {'Clear description of what this command does (5-10 words, in active voice). Use the same language as the user input.',type: 'string',},+ env: {+ additionalProperties: { type: 'string' },+ description:+ 'Optional environment variables to set for this command. Use this for securely passing credentials (e.g., API tokens) β do NOT embed secrets in the command string. Values are merged into the child process environment.',+ type: 'object',+ },run_in_background: {description: 'Set to true to run command in background and return shell_id',type: 'boolean',