Repository navigation
The Context
Every capability gets a Caligrafy\Context as the second argument of handle(). It says who calls, through which
channel, with which rights: a signed-in person, a token, the command line, a job or a visitor. The channels build it
(a page, REST, MCP, the command line); a capability reads it instead of the request, the session or the headers, so the
same code works for every caller. Since 2.1.0.
Say what depends on the caller:
/caligrafy-quill:new-capability my_loans loans:read read-only: the loans of the person who asks, newest first
Claude reads $context->userId() in handle(), and refuses with ServiceError::unauthenticated() when there is none.
Check before you say OK: php caligrafer.php call my_loans --guest is refused, and two people each see only their own
rows.
#[Capability(name: 'my_loans', description: 'Lists the loans of the person who asks, newest first.', scope: 'loans:read', readOnly: true)]
class MyLoans extends Service
{
public function handle(array $input, Context $context)
{
if (!$context->userId()) {
throw ServiceError::unauthenticated();
}
return Loan::where('user_id', $context->userId())->latest()->get();
}
}A capability only a job may run (it works with full access) refuses everyone else by the actor type:
if (!in_array($context->actorType(), array('queue', 'cli'), true)) {
throw ServiceError::forbidden();
}| Member | Meaning |
|---|---|
$context->channel |
web, rest, mcp or cli
|
$context->user |
the user model: signed in, or the owner of the token (null otherwise) |
$context->token |
the token row (id, name, scopes, user_id...), or null
|
$context->viaAction |
true when the call comes from Route::action (2.21.0): the only way to a web-only capability
|
$context->authenticated() |
anyone but a guest |
$context->allows('books:write', 1) |
whether this caller has that scope and level (Scopes and access) |
$context->userId() |
the user's id, signed in or owner of the token |
$context->level() |
the user's permissions column (Context::$levelAttribute), 0 without a user |
$context->actorType() |
user, token, key, cli, guest, or the system of a job or an event (schedule, queue, webhook), as written to the audit log |
$context->actorId() |
the token id or the user id as a string, or the job's name; null for the command line, the legacy key and guests |
| Caller | How the context is made | Rights |
|---|---|---|
a request with Authorization: Bearer cq_...
|
Context::fromRequest($request, $channel): the token, and its owner when it has one and authentication is on |
the token's scopes (an unknown, revoked or expired token is a guest) |
| a request with the legacy API key |
fromRequest: a full-access context |
everything (actor key) |
| a signed-in person (the session) |
fromRequest: the user |
their level |
| nobody | Context::guest($channel) |
public capabilities only |
| the command line and scripts | Context::cli() |
everything (actor cli) |
php caligrafer.php mcp without a token |
Context::local('mcp') |
everything (actor cli) |
| a scheduled job or another system task | Context::system('schedule', $jobName) |
everything; the audit log records the type and the name |
| a personal access token in code | Context::forToken($tokenRow, $channel) |
the token's scopes |
fromRequest() looks in that order: a token, then the legacy key, then the session, else a guest. The context is made
once, before the capability runs: when a web-only capability
signs someone in, it builds a new one with Context::fromRequest(request(), 'web') to call as that person.
Reference: Caligrafy\Context.
-
Reading the session or the request in a capability (G52): the channel does that, and
$contextsays who calls. Only a web-only capability may. -
A job capability that anyone may call: it runs with full access, so check
actorType()(Background jobs). - Trusting the level with an application token (G53): a token without an owner passes any level.
Caligrafy: Describe it. Approve it. Ship it. Your idea turned into a complete app: every feature built once, for web pages, Vue apps, a REST API and AI agents, and online.
Why Caligrafy: the benefits, the measurements, and what it is not yet
-
Quickstart with Claude: describe it, approve it, ship it
or the Quickstart: the same three steps by hand, in 5 minutes
- How Caligrafy works: the ideas in 5 minutes
- Your first capability: build a feature, page included
-
Capabilities in depth
-
#[Capability]: every option - Scheduled jobs: capabilities on a timer
- Notifications: web push and email
- Background jobs: capabilities run later
- Migrations: database changes, in order
- The cache
-
Testing your app
- Dependency injection
- Validation rules
-
Web pages
- Views and page components
- Design styles: another look, one setting
- Declarative routes: every request, in one line
-
Route::page·Route::form·Route::auth·Route::webhook·Route::download·Route::redirect·Route::action·Route::snap· capability routes - How to export a list as CSV
- Controllers: moving one to a declared route · how to, step by step
- Forms and helpers
-
Vue apps
-
Mobile and tablet
-
REST API
-
AI agents
-
Snap Cards and the assistant
- Payments: Stripe and crypto
- Face detection and face login
- OpenAI: chat and images · Assistants
- Open models: Llama, Mistral...
- Chatbots with Watson
- Machine learning in the browser
- Phone and tablet apps: iOS and Android
- Languages: translations, right to left
- Metadata and social cards · search and analytics
-
Putting it online: the production image, the database at every start
-
API reference: every class and method
-
Routing ·
Route·AuthRoutes· pages ·Controller· capabilities -
Data ·
Model·Query· sign-in · jobs ·Notify· payments · AI -
Interfaces · Snap ·
Snap\Cards·Snap\Conversation· testing · tooling · helper functions
-
Routing ·
-
Caligrafer: every command
- Project · build · data · agents · jobs and tests · maintenance · deploy
- Installation, configuration and Caligrafer
- Routing · Request · Controllers · Views
- Vue: flow of information · routes · validations
- Security and upgrading
- Release notes: 2.34 · 2.33 · 2.32 · 2.31 · 2.30 · 2.29 · 2.28 · 2.27 · 2.26 · 2.25 · 2.24 · 2.23 · 2.22 · 2.21 · 2.20 · 2.19 · 2.18 · 2.17 · 2.16 · 2.15 · 2.14 · 2.13 · 2.12 · 2.11 · 2.10 · 2.9 · 2.8 · 2.7 · 2.6 · 2.5 · 2.4 · 2.3 · 2.1 · October 2026 · changelog
- Testing Caligrafy (contributors)