# AGENTS.md Rules for developing Classic ASP applications that run on **AxonASP** (Go-based Classic ASP / VBScript 5.8 runtime, https://github.com/guimaraeslucas/axonasp). Sources: the AxonASP manual (in the container at `/opt/axonasp/www/manual/md`, notably `authoring/llm-classic-asp-coding.md`, `asp/*`, `asp-modernization/*`, `runtime/*`, `config/*`, `libraries/*`) plus problems verified while porting this project. Items marked **[verified here]** were reproduced in this repo's container; the rest come from the manual. When unsure about an object, ProgID, method or config key, check `/opt/axonasp/www/manual/md` in the container before guessing. Do not invent APIs. --- ## 1. Project layout and how to run it ``` (repo root) the application (MVC starter, "RouteKit"), also the git repo root public/ web root (Default.asp front controller + routes, web.config, api/*.openapi.json specs) core/ framework code (autoload_core.asp, mvc.asp, lib.*.asp incl. lib.JsonLite.asp, helpers.asp) app/ controllers/ (HTML: Controller, JSON: ApiController), models/ (POBO_, Repository), views// db/ app.sqlite (SQLite, git-ignored) and migrations/ scripts/ migrate.cmd/.asp, gen.cmd (generators: migration, repo, controller, api), templates/ (POBO, Repository, Api). Run through the AxonASP CLI in the container. docker-compose.yml the AxonASP container (stock image ghcr.io/guimaraeslucas/axonasp) api-tests/ created by `gen.cmd api`: .http sample requests (VS Code REST Client) ``` - Run: `docker compose up -d` from the repo root -> http://localhost:8801 - Compose mounts the whole repo at `/opt/axonasp/site` and sets `SERVER_WEB_ROOT=/opt/axonasp/site/public`. This keeps `../core`, `../app`, `../db` reachable from `public/`, and is the layout `gen.cmd` / `migrate.cmd` expect (container name must be `axonasp`). - Migrations: `scripts\migrate.cmd status|up|down` (runs `axonasp-cli` inside the container). - Swagger UI for the JSON APIs: http://localhost:8801/api/docs (needs internet: loads Swagger UI from the jsDelivr CDN). - The AxonASP manual is inside the container: `docker exec axonasp ls /opt/axonasp/www/manual/md` (libraries/, asp/, runtime/, ...). There is no `deploy/` folder in this repo. ### Memory API (Phase 1) workflow - Provision with `scripts\provision.cmd` (tenant, principal -> API key printed once, namespace, grant, revoke, list, purge). API calls use `Authorization: Bearer `; the tenant comes from the key. - Controllers `ApiMemoriesController`, `ApiSessionsController`, `ApiHealthController` are hand-written (the generators cover one-table CRUD only); routes under `/api/v1/...` are in `public/Default.asp`. - Regression suite: `bash tests/phase1-api.sh` (needs the container running; creates and purges its own tenants; ends with a container restart). - Phase 2 (documents): `ApiDocumentsController` (ingestion/jobs, jobs, documents, chunks, search) plus `POST /recall` and `POST /memories/:id/verifications` in `ApiMemoriesController`; chunker and FTS5 indexing live in `core/lib.Search.asp`. Regression suite: `bash tests/phase2-api.sh`. OpenAPI: `public/api/memory-v1.openapi.json`. A caller without the needed namespace permission gets 404, never 403. ### Adding a table end to end (the workflow that was verified) 1. `scripts\gen.cmd migration create_
_table`, then fill in `Migration_Up`/`Migration_Down` by hand (the generator leaves TODOs), then `scripts\migrate.cmd up`. 2. JSON API: `scripts\gen.cmd api /table:
/pk:Id`. One run writes the POBO + repository, `Api
Controller.asp`, the includes, the controller whitelist entry, six routes under `/api/
`, `public/api/
.openapi.json` (shows up in the `/api/docs` dropdown) and `api-tests/
.http`. Validation comes from column types and NOT NULL/DEFAULT, `CreatedAt`/`UpdatedAt` text/date columns are set by the server, and an existing controller is never overwritten. Business rules (ranges, formats) are added by hand. 3. HTML pages: `scripts\gen.cmd controller Index "Show(id)" NewForm Create "Edit(id)" "Update(id)" "Delete(id)"` writes a stub controller and wires it (include, whitelist, routes: Index/NewForm/Create/Show/Edit/Update/Delete get REST routes, any other action gets `GET ///:param`). The actions and `app/views//{index,show,form}.asp` are filled in by hand. Pattern used by the (removed) sample CRUD: list with `?q=` search and `?page=` paging via the repository's `SearchTablePaged`; forms carry `HTMLSecurity().GetAntiCSRFToken(name)` as a hidden `csrf_token` and POST actions check `IsValidAntiCSRFToken` (failure: flash error + redirect); validation errors re-render the form with status 422; deletes are POSTs; all output goes through `Server.HTMLEncode`; the layout header is already buffered, so `Response.Clear` before `Response.Redirect`. Put `Const` values outside the class (section 8). 4. `docker restart axonasp`, then test (section 10). Add a nav link in `app/views/shared/header.asp` for new HTML pages. - Run `gen.cmd controller` from PowerShell or cmd, **not Git Bash** (quotes such as `"Show(id)"` reach the script literally; the generator strips them now, but cmd quoting is still the reliable path). Generators run inside the container with the framework folder as web root, so they use paths like `/public/...`, `/app/...`. --- ## 2. Language rules (strict Classic ASP / VBScript 5.8) 1. `Option Explicit` in every page and include that owns top-level code. 2. **Never single-line `If`.** Always `If ... Then` / `End If`. 3. Declare and assign separately. No `Dim x = 1`. No `As Type` unless deliberately using an AxonASP extension (section 4). 4. `Set` for every object assignment. Release long-lived objects with `Set obj = Nothing`. 5. Calling a Sub or method with no return value: no parentheses, or `Call name(args)`. `Foo(a, b)` as a statement is wrong. Calling a Function and using its result: parentheses required. 6. **No short-circuit `And`/`Or`.** Both sides are always evaluated, so `If Not rs.EOF And rs("x") = 1` and `If s = "" Or CDbl(s) > 1` both fail. Nest the `If`s. (`AndAlso`/`OrElse` are AxonASP extensions; see section 4.) 7. Concatenate with `&`, never `+`. 8. `=` is both assignment and comparison. String `=` comparison is case-insensitive. 9. Line continuation is ` _` at end of line. Statements do not wrap otherwise. 10. Error handling: `On Error Resume Next`, check `Err.Number`, then `Err.Clear` / `On Error GoTo 0`. Keep the scope of `Resume Next` small and check errors right after the risky statement. Never use it to hide failures: report the error (number, description, and the SQL or input involved). 11. Directives: `<%@Language="VBSCRIPT" CodePage="65001"%>` on the very first line, compact, one line. Never leave `<%` or `%>` unclosed. 12. Procedure arguments are **ByRef by default**. Use `ByVal` when the caller's variable must not change. 13. Names are case-insensitive. Do not let a local variable or parameter share a name with a class member or a Sub/Function (see gotchas). 14. Always HTML-encode output: `Server.HTMLEncode(value)`. Always URL-encode query values: `Server.URLEncode`. 15. `Application` writes must be wrapped in `Application.Lock` / `Application.Unlock`. Never `Response.Redirect` or `Response.End` while locked. 16. Do not store large objects in `Application`/`Session`. --- ## 3. Includes, paths and files - `` is textual and resolved **before** execution. The path cannot be a variable. - The manual says `file=` is relative to the including file and must not use `..`; `virtual=` is relative to the web root and is the preferred form. This project's framework uses `file="../core/..."` and it works on this build **[verified here]**, but prefer `virtual=` for anything under the web root, and keep includes that cross out of `public/` consistent. - **Linux is case-sensitive.** Include paths must match the real file name case exactly (`../core/` not `../Core/`, `lib.Collections.asp` not `lib.collections.asp`). Check this whenever you add or move a file. - Includes inside a `Sub` are allowed here (the MVC dispatcher does it) but inject the file text at that spot. - `Server.MapPath("/x")` is relative to the web root. A relative path is relative to the current script's directory. Under the CLI the web root and script directory can differ from the web server; see section 8. - `Scripting.FileSystemObject` is limited to the web root unless `server.allow_external_filesystem_access = true` in `axonasp.toml`. Keep new file access inside the web root (or the mounted framework folder when running the CLI with that as root). - `global.asa` lives at the web root. It is compiled at startup; restart to pick up changes. Request/Response are not available in Application events. --- ## 4. AxonASP extensions (use deliberately, and only in new code) AxonASP adds VB6/VB.NET-style features. They make code non-portable to IIS, so use them only when the project has chosen AxonASP permanently, and note it in a comment. - Short-circuit `AndAlso`, `OrElse`; `IsNot`; `<<` / `>>`. - `On Error GoTo
.http` and the Swagger page `/api/docs`. - Clean up test data and throwaway tables/migrations/generated files you created while experimenting (roll back with `migrate.cmd down` first), and leave the database as you found it. - When a bug does not make sense, stop patching around it: reduce it to a small page, change one variable at a time, and write the finding into section 8. - Do not add `On Error Resume Next` to silence an error. Surface it. - Keep new code to the portable subset in section 2 unless the user asks for AxonASP extensions. - Do not modify anything under `/opt/axonasp` in the container except the mounted `site/` folder. - Ask before deleting migrations, the database file, or anything under `db/`.