Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

feat(vault): inject agent prompt guidance (#819)

Call White9f6517937fe7
diff --git a/core/system_prompt_injection.py b/core/system_prompt_injection.py
index 0a71d2c9c..6e6360a78 100644
--- a/core/system_prompt_injection.py
+++ b/core/system_prompt_injection.py
@@ -136,6 +136,64 @@ Rules:
- Use at most 2-4 buttons, each no longer than 20 characters
"""
+_VAULT_PROMPT = """\
+
+## Vault
+When a task needs API keys, access tokens, passwords, wallet private keys, or other sensitive credentials, prefer Avibe Vault: agents reference secrets by name, tag, or skill tag, and users do not need to paste plaintext into chat.
+
+Core concepts:
+- Static secret: a regular secret value, such as an API key, token, database password, or deployment credential. Use it with `vibe vault run` for environment injection or `vibe vault fetch` for authenticated HTTP egress.
+- Keypair secret: a signing key for digests or transactions, such as a wallet key or deployment signer. It cannot be exported as an environment variable and cannot be used with `run` / `fetch`; use `vibe vault sign`.
+- Standard: for lower-risk routine automation. Agents can usually use it without interrupting the user unless it is configured to ask first.
+- Protected: for high-risk secrets, such as production databases or wallet/funds keys. Because protected secrets are end-to-end encrypted, use requires browser approval and passkey unlock.
+
+Rules:
+- Refer to secrets only by secret name, tag, or skill tag.
+- Static secrets can be used with `run` / `fetch`; keypair secrets can only be used with `vibe vault sign`.
+- With `vibe vault run`, the child process receives static secrets as environment variables, so never run commands that may print env vars, debug config, or secret-bearing errors.
+- When protected `run` / `fetch` needs approval, Avibe automatically asks the user to decrypt and authorize access. After the user approves, Avibe resumes this session; it does not replay the command for you, so run the same `run` / `fetch` command again.
+- When protected `sign` needs approval, Avibe creates a browser signing request and returns immediately. Do not rerun `sign`; when Avibe resumes this session, follow the callback instruction to read the completed request result and continue with the returned signature.
+
+Common commands:
+
+Request that the user add a missing static secret. `spec-json` may contain only non-secret prefill metadata; the actual secret value is entered by the user in the browser:
+`vibe vault request OPENAI_API_KEY --reason "Need OpenAI API access" --spec-json '{"kind":"static","protection":"protected","description":"OpenAI API key","tags":["openai","prod","skill:model-work"],"policy":{"allowed_hosts":["api.openai.com"],"auth":{"type":"bearer"}}}'`
+
+For a missing keypair/signing key, ask the user to create a keypair secret in the Vault UI; do not request or store private-key material as a static secret.
+
+$web_chat_placeholder
+
+List or find existing Vault entries:
+`vibe vault list`
+`vibe vault list --tag prod`
+`vibe vault find --kind static --protection protected`
+`vibe vault find openai --tag prod`
+`vibe vault tags`
+
+Run a command with selected static secrets injected as environment variables:
+`vibe vault run --env OPENAI_API_KEY,GITHUB_TOKEN -- python script.py`
+`vibe vault run --env GITHUB_TOKEN=GH_PAT --env OPENAI_API_KEY -- python script.py`
+`vibe vault run --tag deploy -- ./deploy.sh`
+`vibe vault run --skill github-release -- ./release.sh`
+
+Make an authenticated HTTP request. The credential is attached only at egress, and the agent never sees the secret:
+`vibe vault fetch --auth GITHUB_PAT --url https://api.github.com/user`
+
+Request approval before a protected `run` with an existing static secret:
+`vibe vault access PROD_DB_URL --skill deploy --command "run database migration" --egress "connect to production database"`
+
+For protected `fetch`, run `vibe vault fetch`; it creates the correct fetch approval request when needed.
+
+Sign a 32-byte digest with a keypair secret. Standard keys may return the signature directly; protected keys create a browser approval request:
+`vibe vault sign WALLET_KEY --digest <64-hex-digest> --scheme ecdsa-secp256k1-recoverable --command "sign deployment transaction"`
+
+For more details, run `vibe vault --help`.
+"""
+
+_VAULT_WEB_CHAT_PLACEHOLDER_PROMPT = """\
+A lighter manual prompt can mention the missing secret as a clickable placeholder in your reply, for example `$<OPENAI_API_KEY>`. The user can click it and fill the secret from Web chat. This has no reason or structured prefill metadata; use `vibe vault request` when those are needed.
+"""
+
_HARNESS_PROMPT = """\
## Harness
@@ -401,6 +459,16 @@ def _build_show_pages_prompt(context: MessageContext, *, avibe_cloud_guidance: s
)
+def _build_vault_prompt(
+ context: Optional[MessageContext],
+ *,
+ fallback_platform: Optional[str] = None,
+) -> str:
+ platform = resolve_context_platform(context, fallback_platform=fallback_platform, default="")
+ web_chat_placeholder = f"\n{_VAULT_WEB_CHAT_PLACEHOLDER_PROMPT}" if _is_web_platform(platform) else ""
+ return Template(_VAULT_PROMPT).substitute(web_chat_placeholder=web_chat_placeholder)
+
+
def _build_session_end_prompt(
context: MessageContext,
*,
@@ -452,6 +520,7 @@ def build_system_prompt_injection(
prompt += _build_show_pages_prompt(context, avibe_cloud_guidance=guidance)
if include_quick_replies:
prompt += _QUICK_REPLIES_PROMPT
+ prompt += _build_vault_prompt(context, fallback_platform=fallback_platform)
if context is not None:
prompt += _build_harness_prompt(
context,
diff --git a/storage/vault_service.py b/storage/vault_service.py
index 55411f6d5..0df3d3311 100644
--- a/storage/vault_service.py
+++ b/storage/vault_service.py
@@ -1004,8 +1004,11 @@ def _build_request_callback_message(row: dict[str, Any]) -> str:
if request_type == "sign":
# The public signature is the deliverable — the agent needs it to continue. It's stored
# in the request; retrieving it by id returns immediately (the request is already done).
- retrieve = f" Retrieve the signature with: vibe vault await {request_id}." if request_id else ""
- return f"The user approved and completed your {subject}.{retrieve} Then continue the task."
+ retrieve = f" Retrieve the signature result with: vibe vault await {request_id}." if request_id else ""
+ return (
+ f"The user approved and completed your {subject}.{retrieve} "
+ "Do not rerun `vibe vault sign`; use the returned signature and continue the task."
+ )
return f"The user approved your {subject}. Continue the task."
if status == "denied":
return f"The user declined your {subject}. Do not retry — adjust your approach or ask the user how to proceed."
diff --git a/tests/test_reply_enhancer_platform.py b/tests/test_reply_enhancer_platform.py
index 8f5953adf..8c269e0fc 100644
--- a/tests/test_reply_enhancer_platform.py
+++ b/tests/test_reply_enhancer_platform.py
@@ -118,6 +118,68 @@ class ReplyEnhancerPlatformTests(unittest.IsolatedAsyncioTestCase):
self.assertIn("file:///Users/test/.codex/generated_images/thread-id/image-file.png", prompt)
self.assertIn("Never emit variables, placeholder paths, or sandbox paths like `/mnt/data/...`", prompt)
+ def test_prompt_includes_vault_guidance(self):
+ with patch.object(paths, "get_user_preferences_path", return_value=Path("/tmp/user_preferences.md")):
+ prompt = build_system_prompt_injection(include_quick_replies=False)
+
+ self.assertIn("## Vault", prompt)
+ self.assertIn("prefer Avibe Vault: agents reference secrets by name, tag, or skill tag", prompt)
+ self.assertIn("Static secret: a regular secret value", prompt)
+ self.assertIn("Keypair secret: a signing key", prompt)
+ self.assertIn("Because protected secrets are end-to-end encrypted", prompt)
+ self.assertNotIn("irreversible operations", prompt)
+ self.assertIn("never run commands that may print env vars", prompt)
+ self.assertNotIn("With `vibe vault fetch` and `vibe vault sign`, the agent does not receive", prompt)
+ self.assertIn("Avibe automatically asks the user to decrypt and authorize access", prompt)
+ self.assertIn("it does not replay the command for you", prompt)
+ self.assertIn("run the same `run` / `fetch` command again", prompt)
+ self.assertIn("Avibe creates a browser signing request and returns immediately", prompt)
+ self.assertIn("Do not rerun `sign`", prompt)
+ self.assertIn("follow the callback instruction to read the completed request result", prompt)
+ self.assertIn("vibe vault request OPENAI_API_KEY", prompt)
+ self.assertIn("Request that the user add a missing static secret.", prompt)
+ self.assertIn("ask the user to create a keypair secret in the Vault UI", prompt)
+ self.assertIn("do not request or store private-key material as a static secret", prompt)
+ self.assertNotIn("$<OPENAI_API_KEY>", prompt)
+ self.assertNotIn("clickable placeholder", prompt)
+ self.assertIn("vibe vault find --kind static --protection protected", prompt)
+ self.assertIn("vibe vault find openai --tag prod", prompt)
+ self.assertIn("vibe vault tags", prompt)
+ self.assertNotIn("vibe vault discover", prompt)
+ self.assertIn("vibe vault run --env OPENAI_API_KEY,GITHUB_TOKEN", prompt)
+ self.assertIn("vibe vault run --tag deploy", prompt)
+ self.assertIn("vibe vault fetch --auth GITHUB_PAT", prompt)
+ self.assertIn("vibe vault access PROD_DB_URL", prompt)
+ self.assertIn("Request approval before a protected `run`", prompt)
+ self.assertIn("For protected `fetch`, run `vibe vault fetch`", prompt)
+ self.assertIn("vibe vault sign WALLET_KEY", prompt)
+ self.assertNotIn("vibe vault await <request_id>", prompt)
+ self.assertNotIn("vibe vault sign WALLET_KEY --skill", prompt)
+ self.assertNotIn("vibe vault sign WALLET_KEY --tag", prompt)
+
+ def test_prompt_includes_vault_web_placeholder_only_for_web_chat(self):
+ web_context = MessageContext(
+ user_id="U1",
+ channel_id="C1",
+ platform="avibe",
+ platform_specific={"agent_session_id": "sesk8m4q2p7x"},
+ )
+ slack_context = MessageContext(
+ user_id="U1",
+ channel_id="C1",
+ platform="slack",
+ platform_specific={"agent_session_id": "sesk8m4q2p7x"},
+ )
+
+ with patch.object(paths, "get_user_preferences_path", return_value=Path("/tmp/user_preferences.md")):
+ web_prompt = build_system_prompt_injection(include_quick_replies=False, context=web_context)
+ slack_prompt = build_system_prompt_injection(include_quick_replies=False, context=slack_context)
+
+ self.assertIn("$<OPENAI_API_KEY>", web_prompt)
+ self.assertIn("clickable placeholder in your reply", web_prompt)
+ self.assertNotIn("$<OPENAI_API_KEY>", slack_prompt)
+ self.assertNotIn("clickable placeholder in your reply", slack_prompt)
+
def test_prompt_can_exclude_show_pages(self):
context = MessageContext(
user_id="U1",
diff --git a/tests/test_vault_request_callbacks.py b/tests/test_vault_request_callbacks.py
index 48b7a8cd0..a0076cc92 100644
--- a/tests/test_vault_request_callbacks.py
+++ b/tests/test_vault_request_callbacks.py
@@ -423,7 +423,9 @@ def test_sign_approved_callback_points_to_the_signature():
}
plan = vs.resolve_request_callback(row)
assert plan is not None
- assert "vrq_sig" in plan.message and "vault await" in plan.message
+ assert "vrq_sig" in plan.message
+ assert "Retrieve the signature result with: vibe vault await vrq_sig" in plan.message
+ assert "Do not rerun `vibe vault sign`" in plan.message
def test_callback_enabled_followup_does_not_suggest_await(monkeypatch):
@@ -561,4 +563,5 @@ def test_vault_callback_sweep_enqueues_protected_sign_callback(monkeypatch, tmp_
assert callback_run.source_kind == "callback"
assert callback_run.source_actor == f"vault:{req['id']}"
assert callback_run.message
- assert "vault await" in callback_run.message
+ assert "Retrieve the signature result with: vibe vault await" in callback_run.message
+ assert "Do not rerun `vibe vault sign`" in callback_run.message