AI
AI builder
Preview ai:build and ai:fix work today. They ask before every file write (including the files generators create) and before every command outside an exact allow-list, never run a shell, and can roll a session back. Their behaviour may change in minor releases.
php taphra ai:build turns a description in plain English into files in your app: it plans them, then writes them with your approval. Every file change (including the files a make:* generator creates), and every command that is not on a short allow-list, is shown to you first and applied only when you say yes. Every session keeps a receipt, so php taphra ai:rollback can undo it. php taphra ai:fix does the same for one error.
The AI builder is a preview feature: it works, and its behaviour may still change in minor releases. It runs code that a language model wrote, on your machine. Read what it proposes before you approve it, and use version control.
Contents
#- Commands
- Approving changes
- How a build runs
- Receipts and rollback
- What the tools may touch
- Configuration
- Known limitations
- Example session
Commands
#ai:build: build or extend an app
#php taphra ai:build
php taphra ai:build "a blog with posts, tags, and comments"| Option | Description |
|---|---|
-p, --provider=NAME |
Provider from app/Config/ai.yml to use (anthropic, openai, ollama) |
-m, --model=NAME |
Model for every call of this session |
--port=PORT |
Port of the test URL shown at the end (default 8080) |
--dontaskforpermissions |
Apply every file change without asking, and run Taphra commands and plain file tools (ls, cat, cp, mv, rm, ...) without asking, including commands that run the code just written. Any other program is refused. It prints a warning at the start and before each command. Blocked commands stay blocked. Use it only in a throwaway copy of a project. |
--continue |
Resume the most recent session instead of starting a new one |
Slash commands at the "What would you like to add?" prompt:
| Command | Effect |
|---|---|
/rollback |
Undo everything this session changed |
/receipt |
Show what this session has changed so far |
/exit |
End the session |
ai:fix: diagnose and fix an error
#php taphra ai:fix
php taphra ai:fix "Undefined variable \$post in PostController.class.php on line 42"
php taphra ai:fix "$(tail -n 40 app/tmp/Log/app.log)" --provider=openaiWithout an argument, ai:fix asks you to paste the error. It reads the files named in the error for context and proposes the smallest change that fixes it. Each change is shown and applied only when you approve it. Changed PHP files are checked with php -l, and one more correction pass runs if syntax errors remain. Fixes are recorded in a receipt too, so php taphra ai:rollback undoes them. It takes --provider, --model and --dontaskforpermissions like ai:build.
Pass the error as an argument, as above, rather than piping it in. Input on a pipe is read only with -n (--no-interaction), and with -n every change is refused, so you get the diagnosis and the proposed patch without any file being written (see Approving changes for the commands that still run).
ai:rollback: undo a session
#php taphra ai:rollback # undo the most recent session
php taphra ai:rollback 20261129143200 # undo a session by its receipt ID
php taphra ai:rollback --list # list the saved receipts and their status
php taphra ai:rollback --yes # skip the confirmation question
php taphra ai:rollback --force # also undo files you edited after the sessionApproving changes
#Before each file change the builder prints what it is about to do and asks:
Confirm: Create app/Controllers/PostController.class.php (6 lines, 110 bytes)
+ <?php
+
+ class PostController extends AppController
...
Apply? [y]es, [n]o, [a] yes to all file changes this session [n]:| Answer | Effect |
|---|---|
y |
Apply this change |
n (the default) |
Skip it; the model is told it was not approved |
a |
Apply this one and every later change of the same kind (file changes, or commands) in this session |
A new file is shown in full. An overwrite or a patch is shown as a diff of the whole file: every removed (-) and added (+) line, with three unchanged lines around each change and @@ line numbers. Commands show the exact argument list and the folder they run in. Long prompts are shown 40 lines at a time (Enter for the next page, r for the rest, n to refuse); the question comes after the last line.
A make:* generator run through run_command creates files, so it is asked as a file change too, with the exact command (Create files with a Taphra generator: ...), and a for file changes covers it. Which files it creates is decided by the generator, so the prompt cannot list them; the files it created under app/ are listed after it runs.
Control and invisible characters in anything the model wrote (terminal escape codes, bidi overrides and isolates, zero-width characters, the byte order mark, soft hyphens, line and paragraph separators, private-use characters and similar) are shown as visible escapes such as \e[2K or \u{202E}, so they cannot hide lines, move the cursor or reorder text, and the prompt title warns when a file contains them. Paths and commands that contain them are refused.
With -n (--no-interaction) every question is answered no: the builder writes no file and runs no generator. The other allow-listed commands still run; migrate among them applies migrations that were already pending, which changes the database and the migration state file.
How a build runs
#1. Plan
#One structured-output call asks the model for a build plan:
- Summary: one sentence describing what will be built
- Files: every file to create, with its kind (migration, datastore, controller, view, route, config)
- Routes: the HTTP routes the app will expose
- Out of scope: anything that needs manual steps, such as deploy settings or third-party accounts
You confirm the plan before anything is written. If it is not right, say no, change your description, and planning runs again.
2. Execute
#An AgentLoop (see AI) writes the files with the tools described below, and prints each tool call as it happens:
→ create app/Migrations/migration_20261129143200_CreatePostsTable.php
→ create app/DataStores/PostDataStore.class.php
→ run migrate
→ patch app/Config/routes.ymlEvery PHP file written or patched in the session is then checked with php -l. Syntax errors go back to the model for up to two correction passes.
3. Iterate
#After the first build, the session waits for follow-up requests:
What would you like to add? (/rollback /receipt /exit)
> add a page that lists posts by tagWhen the current history has used more than 80,000 tokens, it is replaced by a summary of what was built and counting starts again, so work can go on.
Project context
#Before every model call, the builder reads the project and adds its current state to the system prompt:
| Context | Source |
|---|---|
| Next migration ID | app/Migrations/migration_*.php (sequential or timestamp IDs) |
| Tables already created | CREATE TABLE statements and SchemaBuilder::create() calls in migrations |
| App namespace | The namespace of the app's controllers (or the app/ entry in composer.json's PSR-4 map). Namespaced apps get namespaced examples with use lines and PSR-4 file names; apps with global classes get the classmap conventions |
| Base classes | AppController, AppDataStore and the other App* base classes the project ships |
| Existing DataStores | app/DataStores/*.php and *.class.php, with the table name from $objectName |
| Existing controllers | app/Controllers/*.php and *.class.php, base classes left out |
| Current routes | app/Config/routes.yml |
| Database driver | app/Config/databases.yml or app/Config/app.yml |
| Installed packages | composer.json (taphra/* and relevant third-party packages) |
Receipts and rollback
#Every session that changes something writes a receipt to app/tmp/ai_builds/{id}.json. It is saved before the first change and again after every change, so a build that fails or is interrupted half way can still be undone; a failed build prints the receipt ID to use.
Each path is recorded once, with its state before the session first touched it:
- Created files did not exist before; rollback deletes them.
- Overwritten files existed and were replaced; the original content is kept and restored.
- Patched files existed and were changed with search and replace; the original content is kept and restored.
- Migrations run during the session are rolled back with
php taphra migration down {last ID before the session}.
Files created by commands (for example make:controller) are recorded as created files too.
Rollback is careful:
- A file you edited after the session is left as it is and listed, unless you pass
--force. - Every path in the receipt is checked again before anything is touched, and only files under
app/inside the project are restored or deleted. - A receipt that was fully rolled back is marked so, and is not offered again.
What the tools may touch
#| Tool | What it does | Limits |
|---|---|---|
create_file |
Write a new file or replace one | Asks first. Only under app/, never in app/tmp/ai_builds/ |
update_file |
Patch an existing file with search and replace | Asks first. Only under app/ |
read_file |
Read a project file | Inside the project; .env files and .git/ cannot be read |
list_files |
List a directory | Inside the project; skips .git/, vendor/, node_modules/ and .env files; links are listed, not followed |
run_command |
Run one command | See below |
What read_file returns is sent to the AI provider. Keep secrets in environment variables, not in files under app/Config/.
Paths from the model must be relative to the project root. Absolute paths, ~, stream wrappers such as phar://, NUL bytes, .. segments that climb above the project, : in a segment and Windows short names (a ~ followed by a digit, as in GIT~1) are rejected. Symbolic links are followed one component at a time, and a link that leads outside the project (or nowhere) is rejected. Missing directories are created only after the whole path has been checked.
Commands
#run_command never uses a shell. The command string is split into arguments (single quotes, double quotes and backslash escapes work as usual), and shell syntax is refused: pipes, redirections, ;, &&, $VAR, $(...), backticks, wildcards and line breaks. Each command runs with a timeout of 120 seconds.
Taphra commands may be written with or without the php taphra prefix. They run through the project's own CLI script with the PHP binary that runs the builder. Other programs run with the project root as their working directory.
| Category | Commands | Behaviour |
|---|---|---|
| Allow-list | migrate and migrate --dry-run; migration status; route:list; list; help; ls inside the project; php -l on a project file |
Runs without asking, until the builder has written a file in the session (see below) |
| Generators | make:* generators (make:controller, make:model, make:datastore, make:migration, make:crud, make:mcp, make:tool and the others) |
Create files, so they ask as a file change and run only if you approve. Those that write under app/, with plain names and options, need no other approval; any other arguments or generator ask as a command too. With -n they never run; with --dontaskforpermissions they run without asking |
| Ask | Everything else that is not blocked, for example composer show, tinker, rm, cp |
Shows the exact command and runs it only if you approve. With --dontaskforpermissions, only Taphra commands and plain file tools run; any other program is refused |
| Blocked | Shells and wrappers that run another program (sh, bash, env, xargs, nohup, timeout, flock, tmux, screen, setarch, ...); Windows scripts and shells (.bat, .cmd, .ps1, cmd.exe, powershell.exe; .exe names are matched like the plain names); interpreters and tools that run code they are given (php with a script or -r, awk, sed, perl, python, node, jq, ...); composer except read-only commands such as show and validate; build tools and package managers (make, npm, pip, ...); database shells (sqlite3, mysql, psql); archive tools (tar, unzip, zip, ...); network tools (curl, wget, ssh, nc, ...); privilege tools (sudo, su, ...); chmod, docker and similar system tools; find with -exec, -ok or -delete; git (repository config, hooks and aliases can run commands, so the builder never runs it; run git yourself); interpreters such as Rscript and erb; programs inside app/; arguments that name files that may hold secrets (.env, .git, Windows short names); and any argument that points outside the project, including values glued to short options such as -C.. |
Never runs, in any mode |
Once create_file or update_file has written a file in the session, every command asks first, including allow-listed ones: migrate loads the migrations that were written, and every Taphra command loads the app. This carries over to ai:build --continue when the earlier session wrote files.
--dontaskforpermissions turns "Ask" into "runs with a warning". It never turns "Blocked" into anything else.
Configuration
#The builder uses the providers in app/Config/ai.yml (see AI). When the file is missing, the first ai:build or ai:fix run asks three questions (provider, API key, model) and writes it:
default_provider: anthropic
providers:
anthropic:
api_key: "${ANTHROPIC_API_KEY}"
model: claude-opus-4-6
max_tokens: 4096The key itself goes to .env when it is not already in the environment. Taphra does not read .env at runtime, so export the variable in your shell before the next session.
Pass --provider=NAME to use another configured provider for one session, or --model=NAME for another model of the same provider.
Known limitations
#- The conventions the builder gives the model are those of apps with global classes in
.class.phpfiles and nonamespaceline. Apps made from the 1.0 skeleton use theApp\namespace (App\Controllers\AppController), so a generated controller or DataStore needs the matchingnamespaceline andcomposer dump-autoloadbefore it loads. Review generated classes for this before you approve them. - Migrations run during a session are found through the file state backend (
app/Migrations/migration_state.json, the default). Withstate.backend: databaseinmigrations.yml, rollback does not undo them; runphp taphra migrate:downyourself. - The test URL at the end assumes
php taphra serveon the port given with--port.
Example session
# Taphra AI Builder powered by anthropic
Type your description, then press Enter. Slash commands: /rollback /receipt /exit
What would you like to build?
> a REST API for a task manager with projects and tasks
Planning…
A task manager REST API with CRUD for projects and tasks, plus status filtering.
Files to create:
app/Migrations/migration_20261129143200_CreateProjectsTable.php migration
app/DataStores/ProjectDataStore.class.php datastore
app/Controllers/ApiProjectsController.class.php controller
Proceed with this plan? [Y/n]
Building…
Confirm: Create app/Migrations/migration_20261129143200_CreateProjectsTable.php (24 lines, 712 bytes)
+ <?php
...
Apply? [y]es, [n]o, [a] yes to all file changes this session [n]: a
→ create app/Migrations/migration_20261129143200_CreateProjectsTable.php
approved for this session: Create app/DataStores/ProjectDataStore.class.php (9 lines, 210 bytes)
→ create app/DataStores/ProjectDataStore.class.php
→ run migrate
...
Receipt: 20261129143200 (php taphra ai:rollback to undo)
Test at: http://localhost:8080/api/projectsTo serve your app's functions to AI clients instead, see MCP server.