Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions agent-app/tools/src/commands/trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Fire a declared trigger of the RUNNING app — the same path the app itself
* uses (a POST into agent_requests through the in-app guard), not a side
* door: the fire proves the guard, the cooldown, and — when a CraftBot host
* is attached and has approved the app — the agent dispatch, end to end.
* is attached and the user allowed its declared requests — the agent dispatch, end to end.
* Spec TRIGGERS-PLAN: "test each trigger after launch".
*/
import { existsSync, readFileSync } from 'node:fs';
Expand Down Expand Up @@ -110,7 +110,7 @@ export async function run(args: string[]): Promise<number> {
log.ok(`Fired "${name}" — request ${row.id} is pending.`);
log.raw(
`Watch it: node tools/src/cli.ts requests ${project.dir}\n` +
'If a CraftBot host is attached (and has approved this app), the agent claims the row and writes result/status.',
'Once the user allows the app requests in CraftBot, the agent claims the row and writes result/status.',
);
return 0;
}
9 changes: 3 additions & 6 deletions agent_file_system/AGENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -1244,17 +1244,14 @@ agent_app_ops_verify(project_id, op_names?) EXTERNAL apps only: verifies operati
through the adapter (destructive ops are shape-checked).
Run during adoption after notify_ready and after every
operations.json edit; the import isn't done until it passes.
agent_app_approve_triggers(project_id) Record the USER'S consent for an app's declared agent
triggers (triggers.json — requests the app may fire at you).
Call ONLY after the user explicitly agreed in chat. Apps
built here are pre-approved; marketplace/imported apps'
fires are refused until approved.
agent_app_convert(source, ...) Rebuild a foreign app as a Agent App: fresh scaffold, original kept
in reference/source/, requirements synthesized,
supervised build dispatched. Always a native rebuild; to keep a
foreign app running as-is, use agent_app_import.
```

App-to-agent requests require user review in CraftBot's approval modal at launch or after new/changed trigger definitions are delivered. This applies to imported, marketplace, newly created, and evolved apps. Never write approval records or ask for consent after a trigger fires; direct the user to Review requests on the app page if requests are off.

### Data and ops: the agent-app CLI

Read/write a project's live data with the agent-app CLI via `run_shell` (absolute paths required):
Expand Down Expand Up @@ -1448,7 +1445,7 @@ agent_app agent_app_scaffold, agent_app_list_projects, agent_app_
agent_app_report_finding, agent_app_http, agent_app_usage,
agent_app_marketplace_list,
agent_app_marketplace_install, agent_app_import_zip, agent_app_import,
agent_app_convert, agent_app_ops_verify, agent_app_approve_triggers
agent_app_convert, agent_app_ops_verify

per-integration sets Discord, Slack, Telegram (bot/user), Notion, LinkedIn, Jira, GitHub,
Outlook, WhatsApp, Twitter, HubSpot, Stripe, LINE, Lark (+calendar/drive),
Expand Down
77 changes: 33 additions & 44 deletions app/agent_app/integration_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import logging
from pathlib import Path
from typing import TYPE_CHECKING, Dict, Optional
from typing import TYPE_CHECKING, Awaitable, Callable, Dict, Optional

from aiohttp import web
import httpx
Expand Down Expand Up @@ -79,8 +79,14 @@ class IntegrationBridge:
CraftBot validates token, injects auth, forwards to external API.
"""

def __init__(self, manager: "AgentAppManager"):
def __init__(
self,
manager: "AgentAppManager",
*,
on_trigger_blocked: Optional[Callable[[str, str, str], Awaitable[None]]] = None,
):
self._manager = manager
self._on_trigger_blocked = on_trigger_blocked
# follow_redirects is OFF for the proxy: an allowed host could 302 to an
# attacker-controlled host and the injected credentials would follow it.
self._http_client = httpx.AsyncClient(timeout=30, follow_redirects=False)
Expand Down Expand Up @@ -428,7 +434,7 @@ async def _handle_agent_request(self, request: web.Request) -> web.Response:
triggers.json on disk by the manager, so nothing app-controlled can
steer the agent beyond what its author declared at build time.

Gate order: token → capability → consent → era. Every refusal fails
Gate order: token → capability → era → reviewed definition. Every refusal fails
closed and leaves the queue row pending (harmless, inspectable)."""
project_id = self._validate_token(request)
if not project_id:
Expand Down Expand Up @@ -459,48 +465,8 @@ async def _handle_agent_request(self, request: web.Request) -> web.Response:
{"error": f"This app may not fire '{trigger}': {why}"}, status=403
)

# Gate 3 — consent. First-party builds are approved at creation;
# marketplace/imported apps need the user's explicit yes.
try:
from app.factory.host_craftbot import get_factory_host

host = get_factory_host()
if not host.is_triggers_approved(project_id):
logger.warning(
f"[INTEGRATION_BRIDGE] BLOCKED (consent) project={project_id} "
f"trigger={trigger!r}"
)
# A silent refusal reads as a broken button (observed live
# 2026-08-06: three consent-blocks, user saw nothing). Ask
# the user via the project session — at most once an hour,
# never letting the ask fail the refusal response, and never
# consuming the hourly slot on a FAILED ask (a silent
# failure once suppressed every retry for an hour).
try:
if host.consent_nudge_due(project_id):
ask = await self._manager.notify_trigger_consent_needed(
project_id, trigger
)
if ask.get("status") == "success":
host.mark_consent_nudged(project_id)
else:
logger.warning(
f"[INTEGRATION_BRIDGE] consent ask failed for "
f"{project_id}: {ask.get('message')}"
)
except Exception as e:
logger.warning(f"[INTEGRATION_BRIDGE] consent ask failed: {e}")
return web.json_response(
{
"error": (
"The user has not approved this app's agent triggers. "
"Ask them to approve via agent_app_approve_triggers."
)
},
status=403,
)

# Gate 4 — era. While a DEV environment exists, fires are
# Gate 3 — era. While a DEV environment exists, fires are
# agent/verifier test traffic (the walk verifier clicks ⚡
# buttons in the dev instance, which aliases to the real project
# id through the shared bridge token) — they must not start real
Expand Down Expand Up @@ -529,6 +495,29 @@ async def _handle_agent_request(self, request: web.Request) -> web.Response:
),
}
)
# User consent is collected in the UI at launch/update, never by
# starting an agent run to ask after the first fire.
from app.agent_app.trigger_consent import approved_trigger

project = self._manager.get_project(project_id)
if approved_trigger(project, trigger) is None:
# Notify through the host UI, without starting an agent run.
# A notification failure must never change the refusal.
callback = getattr(self, "_on_trigger_blocked", None)
if callback is not None:
try:
await callback(project_id, trigger, request_id)
except Exception as exc:
logger.warning(
f"[INTEGRATION_BRIDGE] blocked notice failed: {exc}"
)
return web.json_response(
{
"error": "Agent requests are off. Review and allow them in CraftBot.",
"code": "trigger_approval_required",
},
status=403,
)
except Exception as e:
# Fail closed: if the gates cannot be evaluated, no agent run.
logger.warning(f"[INTEGRATION_BRIDGE] trigger gates unavailable: {e}")
Expand Down
11 changes: 0 additions & 11 deletions app/agent_app/lifecycle/promoter.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,6 @@ async def promote(self, project) -> Dict[str, Any]:
ensure_baseline(project.path, verify_store_dir(project))
except Exception as e:
logger.warning(f"[AGENT_APP:PROMOTE] verify baseline not written: {e}")
# Trigger consent (spec TRIGGERS-PLAN): a supervised build or modify
# that delivered is first-party work the user asked for in chat —
# approve its declared triggers. This is also how apps built BEFORE
# the consent feature get approved (observed live 2026-08-06: a
# kanban board gained a user-requested trigger via modify and every
# fire was then consent-blocked, silently).
try:
host.set_triggers_approved(project.id)
except Exception as e:
logger.warning(f"[AGENT_APP:PROMOTE] trigger approval failed: {e}")

logger.info(
f"[AGENT_APP:PROMOTE] {project.id} promoted "
f"({'first delivery' if first else 'update'})"
Expand Down
Loading
Loading