원클릭으로
gram-functions
A walkthrough of the Gram Functions feature in this codebase
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
A walkthrough of the Gram Functions feature in this codebase
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Rules when working with ClickHouse database in Gram for analytics and telemetry features, including editing the ClickHouse schema (server/clickhouse/schema.sql) and creating or fixing ClickHouse migrations
Rules and best practices when working on the dashboard and elements React frontend codebases
Concepts, external interfaces, and conventions for Gram's audit logging subsystem — the internal Go API for recording actor/action/subject events and the `/rpc/auditlogs.*` management API that exposes them. Activate whenever the task involves recording or exposing audit events (adding or changing audit coverage on a service, introducing a new audited subject or action, writing tests that assert an event was recorded, changing how entries are displayed or filtered).
Concepts, external interfaces, and conventions for Gram's management API — the Goa-designed HTTP-RPC surface under `/rpc/<service>.<method>` that powers the dashboard, CLI, and public SDK. Activate whenever the task involves designing, implementing, or modifying a management endpoint (new service, new method, payload/result changes, OpenAPI/SDK surface changes, CLI changes, wiring a new service into the server).
Concepts, external interfaces, and conventions for Gram's role-based access control (RBAC) subsystem — scopes, grants, principals, system roles, and the `authz.Engine.Require` enforcement path used inside handlers. Activate whenever the task involves authorization (adding or modifying a scope or resource type, declaring a new role or grant, gating a handler, changing scope inheritance, exposing RBAC state through the dashboard).
Use the Playwright MCP browser to capture a demo (screenshots or a GIF recording) of a user-visible frontend change and post it as a PR comment
| name | gram-functions |
| description | A walkthrough of the Gram Functions feature in this codebase |
| metadata | {"relevant_files":["server/internal/functions/**/*.go","server/internal/background/activities/deploy_function_runners.go","server/internal/background/activities/reap_functions.go","functions/**/*"]} |
Gram Functions is a serverless code execution feature that allows users to deploy custom JavaScript/TypeScript or Python code as callable tools within Gram deployments. Functions can be invoked by AI agents during conversations.
| Package | Purpose |
|---|---|
server/internal/functions/ | Core functions service - deployment, execution, auth |
server/internal/background/activities/ | Temporal activities for deploying/reaping function runners |
server/design/functions/ | Goa API design for functions endpoints |
server/internal/functions/)impl.go - API service, handles signed asset URL requests from runnersdeploy.go - Core interfaces: Deployer, ToolCaller, Orchestratordeploy_fly.go - Fly.io integration via Machines APImanifest.go - Manifest format (ManifestV0) describing exported tools/resourcesruntimes.go - Supported runtime definitions (JS, TS, Python)auth.go - JWT authentication for function runnersqueries.sql - SQL queries for fly_apps table managementserver/internal/background/)activities/deploy_function_runners.go - Deploys runners during deployment processingactivities/reap_functions.go - Cleans up old Fly.io appsactivities/provision_functions_access.go - Creates access credentials for runnersfunctions_reaper.go - Temporal workflow for cleanup (triggered per-project after deployments)functions/)The functions/ directory contains the source code and build configuration for the OCI images that run user functions on Fly.io. These images are built using melange and apko for reproducible, minimal container images.
| File | Purpose |
|---|---|
melange.yaml | Builds the gram-runner Go binary as an APK package |
images/nodejs22-alpine3.22.yaml | apko config for Node.js 22 runtime image |
images/python3.12-alpine3.22.yaml | apko config for Python 3.12 runtime image |
Each runtime image contains:
ca-certificates-bundle, su-exec)nodejs or python3)gram-runner binary (built from cmd/runner/main.go)Entrypoint behavior:
gram-runner -init -language <lang> - Initializes filesystem, unzips user codesu-exec gram - Drops privileges to non-root gram user (UID 10000)gram-runner -language <lang> - Starts HTTP server on port 8888cmd/runner/main.go)The gram-runner binary is an HTTP server that:
:8888 for tool call and resource requestsfunctions/internal/)| Package | Purpose |
|---|---|
auth/ | JWT authentication and request authorization middleware |
bootstrap/ | Machine initialization: unzip code, prepare entrypoints, lazy asset loading |
encryption/ | AES-GCM encryption for secure communication |
guardian/ | Process execution with resource limits |
ipc/ | Named pipe (FIFO) creation for subprocess communication |
javascript/ | JavaScript/TypeScript entrypoint script (gram-start.js) |
python/ | Python entrypoint script (gram_start.py) |
runner/ | HTTP handlers for /tool-call and /resource-request endpoints |
svc/ | Service utilities (idle tracking, secrets, errors) |
o11y/ | Observability setup (OpenTelemetry, logging) |
middleware/ | HTTP middleware (recovery, version header) |
attr/ | Structured logging attribute helpers |
POST /tool-call with JSON payload:
{"name": "tool_name", "input": {...}, "environment": {...}}
node --experimental-strip-types gram-start.js or python gram_start.pyFor large function bundles (>700KiB), the code isn't embedded in the Fly machine config. Instead:
.lazy file is written containing the asset IDbootstrap.resolveLazyFile() detects the .lazy file| Table | Purpose |
|---|---|
deployments_functions | Links functions to deployments, stores runtime/slug |
functions_access | Encryption keys and bearer token formats for auth |
fly_apps | Tracks deployed Fly.io apps (status, region, URL, reap state) |
function_tool_definitions | Tool metadata (name, description, input schema, variables) |
function_resource_definitions | Resource metadata (URI, mime type) |
manifest.jsonDeployFunctionRunners activityFlyRunner.ToolCall() sends authenticated HTTP request/tool-call endpointnode/python) with user codeserver/internal/deployments/impl.go)reaped_at in databaseFunctionsReaperScopeGlobal scope exists in the code but is not currently used/scheduled