Two reversible migrations: tenants/principals/api_keys/namespaces/ access_grants, then memory_types/memories/memory_revisions/ idempotency_keys/sessions/checkpoints/audit_events. Verification is per revision. Document migrator one-per-process quirk in AGENTS.md. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>pull/1/head
| @@ -153,6 +153,7 @@ Create objects with `Server.CreateObject("ProgID")` using exact ProgIDs from `/o | |||||
| - **Dynamic Eval/Execute in classes is unreliable.** `Eval`/`Execute` inside a Class method cannot see global functions; with a runtime-built string they re-emit a method's inline HTML twice (second copy after the footer); `CallByName` is a silent no-op. Do not dispatch with them. | - **Dynamic Eval/Execute in classes is unreliable.** `Eval`/`Execute` inside a Class method cannot see global functions; with a runtime-built string they re-emit a method's inline HTML twice (second copy after the footer); `CallByName` is a silent no-op. Do not dispatch with them. | ||||
| - **Call sites bind to the first class.** `CurrentController.Invoke ...` in one place was bound to the first controller's `Invoke` and reused for every later controller (the first dispatched action's body appeared on every route; title/layout were right). Each controller therefore exposes a global `<Name>Controller_Invoke(actionName, args)` and the dispatcher calls it through `GetRef` (`MVC_InvokeAction`). New controllers must define `Invoke` and `<Name>Controller_Invoke` (the generators emit both). | - **Call sites bind to the first class.** `CurrentController.Invoke ...` in one place was bound to the first controller's `Invoke` and reused for every later controller (the first dispatched action's body appeared on every route; title/layout were right). Each controller therefore exposes a global `<Name>Controller_Invoke(actionName, args)` and the dispatcher calls it through `GetRef` (`MVC_InvokeAction`). New controllers must define `Invoke` and `<Name>Controller_Invoke` (the generators emit both). | ||||
| - **Single-line `If x Then a = b Else a = c` swallowed the rest of a Sub** under `On Error Resume Next`. Always use multi-line `If`. | - **Single-line `If x Then a = b Else a = c` swallowed the rest of a Sub** under `On Error Resume Next`. Always use multi-line `If`. | ||||
| - **Migrator: one migration per process.** `migrate.cmd up` with two or more pending migrations failed on the second one (`Runtime error: Migrator '800A0002'`; an AxonASP VM panic "assignment to entry in nil map" when reproduced in a plain script). Run `migrate.cmd up` once per pending migration. Even a successful apply/rollback currently ends with `Object required` from `core/helpers.asp` and exit code 1 (reproduced on the original unmodified framework, so not caused by local changes); check `migrate.cmd status` rather than the exit code. | |||||
| - **Class member vs local name clash.** Avoid a local `Dim controllerName` inside a class that also has a `ControllerName` property. | - **Class member vs local name clash.** Avoid a local `Dim controllerName` inside a class that also has a `ControllerName` property. | ||||
| - **`Empty Is Nothing` raises "Object required".** Test with `IsObject` / `IsEmpty` first, then `Is Nothing`. | - **`Empty Is Nothing` raises "Object required".** Test with `IsObject` / `IsEmpty` first, then `Is Nothing`. | ||||
| - **`Server.Execute(file)` runs the file as a separate page.** It does not define procedures in the caller's scope. To load a script's Subs, read the file and `ExecuteGlobal` the text (strip `<%`/`%>`), as the migrator does. | - **`Server.Execute(file)` runs the file as a separate page.** It does not define procedures in the caller's scope. To load a script's Subs, read the file and `ExecuteGlobal` the text (strip `<%`/`%>`), as the migrator does. | ||||
| @@ -0,0 +1,90 @@ | |||||
| <% | |||||
| '======================================================================================================================= | |||||
| ' MIGRATION: create_core_identity_tables | |||||
| '======================================================================================================================= | |||||
| ' This migration was auto-generated. Add your migration logic below. | |||||
| ' | |||||
| ' The migration object provides these helper methods: | |||||
| ' - migration.ExecuteSQL(sql) - Execute raw SQL | |||||
| ' - migration.CreateTable(name, columns) - Create a table | |||||
| ' - migration.DropTable(name) - Drop a table | |||||
| ' - migration.AddColumn(table, column, type) - Add a column | |||||
| ' - migration.DropColumn(table, column) - Drop a column | |||||
| ' - migration.CreateIndex(name, table, columns) - Create an index | |||||
| ' - migration.DropIndex(name, table) - Drop an index | |||||
| ' | |||||
| ' For complex operations, use migration.DB to access the database directly: | |||||
| ' migration.DB.Execute "INSERT INTO users (name) VALUES (?)", Array("John") | |||||
| ' | |||||
| '----------------------------------------------------------------------------------------------------------------------- | |||||
| ' UP - Apply the migration | |||||
| '----------------------------------------------------------------------------------------------------------------------- | |||||
| Sub Migration_Up(migration) | |||||
| ' Identity and scoping (spec section 8: Tenant, Principal, Access grant, Namespace). | |||||
| ' IDs are opaque UUID text, timestamps are UTC ISO text ('YYYY-MM-DD HH:MM:SS'). | |||||
| migration.ExecuteSQL "CREATE TABLE tenants (" & _ | |||||
| "id TEXT PRIMARY KEY, " & _ | |||||
| "name TEXT NOT NULL, " & _ | |||||
| "status TEXT NOT NULL DEFAULT 'active', " & _ | |||||
| "created_at TEXT NOT NULL)" | |||||
| migration.ExecuteSQL "CREATE TABLE principals (" & _ | |||||
| "id TEXT PRIMARY KEY, " & _ | |||||
| "tenant_id TEXT NOT NULL REFERENCES tenants(id), " & _ | |||||
| "type TEXT NOT NULL CHECK (type IN ('human','agent','service')), " & _ | |||||
| "name TEXT NOT NULL, " & _ | |||||
| "status TEXT NOT NULL DEFAULT 'active', " & _ | |||||
| "created_at TEXT NOT NULL)" | |||||
| migration.CreateIndex "idx_principals_tenant", "principals", "tenant_id" | |||||
| ' Only the SHA-256 of a key is stored; the plain key is shown once at creation. | |||||
| migration.ExecuteSQL "CREATE TABLE api_keys (" & _ | |||||
| "id TEXT PRIMARY KEY, " & _ | |||||
| "principal_id TEXT NOT NULL REFERENCES principals(id), " & _ | |||||
| "key_hash TEXT NOT NULL UNIQUE, " & _ | |||||
| "key_prefix TEXT NOT NULL, " & _ | |||||
| "status TEXT NOT NULL DEFAULT 'active', " & _ | |||||
| "created_at TEXT NOT NULL, " & _ | |||||
| "expires_at TEXT, " & _ | |||||
| "last_used_at TEXT)" | |||||
| migration.CreateIndex "idx_api_keys_principal", "api_keys", "principal_id" | |||||
| ' path is the full slash-separated path ('/dev/project-x'); parent chain must be acyclic, | |||||
| ' which holds because a namespace is only created under an existing parent. | |||||
| migration.ExecuteSQL "CREATE TABLE namespaces (" & _ | |||||
| "id TEXT PRIMARY KEY, " & _ | |||||
| "tenant_id TEXT NOT NULL REFERENCES tenants(id), " & _ | |||||
| "parent_id TEXT REFERENCES namespaces(id), " & _ | |||||
| "name TEXT NOT NULL, " & _ | |||||
| "path TEXT NOT NULL, " & _ | |||||
| "owner_principal_id TEXT REFERENCES principals(id), " & _ | |||||
| "created_at TEXT NOT NULL, " & _ | |||||
| "UNIQUE (tenant_id, path))" | |||||
| migration.CreateIndex "idx_namespaces_parent", "namespaces", "parent_id" | |||||
| ' Scope is not permission: access exists only through an explicit grant. | |||||
| ' inherit = 1 extends the grant to descendant namespaces. | |||||
| migration.ExecuteSQL "CREATE TABLE access_grants (" & _ | |||||
| "id TEXT PRIMARY KEY, " & _ | |||||
| "principal_id TEXT NOT NULL REFERENCES principals(id), " & _ | |||||
| "namespace_id TEXT NOT NULL REFERENCES namespaces(id), " & _ | |||||
| "permissions TEXT NOT NULL, " & _ | |||||
| "inherit INTEGER NOT NULL DEFAULT 1, " & _ | |||||
| "created_at TEXT NOT NULL, " & _ | |||||
| "expires_at TEXT)" | |||||
| migration.CreateIndex "idx_grants_principal", "access_grants", "principal_id" | |||||
| migration.CreateIndex "idx_grants_namespace", "access_grants", "namespace_id" | |||||
| End Sub | |||||
| '----------------------------------------------------------------------------------------------------------------------- | |||||
| ' DOWN - Rollback the migration | |||||
| '----------------------------------------------------------------------------------------------------------------------- | |||||
| Sub Migration_Down(migration) | |||||
| migration.DropTable "access_grants" | |||||
| migration.DropTable "namespaces" | |||||
| migration.DropTable "api_keys" | |||||
| migration.DropTable "principals" | |||||
| migration.DropTable "tenants" | |||||
| End Sub | |||||
| %> | |||||
| @@ -0,0 +1,135 @@ | |||||
| <% | |||||
| '======================================================================================================================= | |||||
| ' MIGRATION: create_memory_and_session_tables | |||||
| '======================================================================================================================= | |||||
| ' This migration was auto-generated. Add your migration logic below. | |||||
| ' | |||||
| ' The migration object provides these helper methods: | |||||
| ' - migration.ExecuteSQL(sql) - Execute raw SQL | |||||
| ' - migration.CreateTable(name, columns) - Create a table | |||||
| ' - migration.DropTable(name) - Drop a table | |||||
| ' - migration.AddColumn(table, column, type) - Add a column | |||||
| ' - migration.DropColumn(table, column) - Drop a column | |||||
| ' - migration.CreateIndex(name, table, columns) - Create an index | |||||
| ' - migration.DropIndex(name, table) - Drop an index | |||||
| ' | |||||
| ' For complex operations, use migration.DB to access the database directly: | |||||
| ' migration.DB.Execute "INSERT INTO users (name) VALUES (?)", Array("John") | |||||
| ' | |||||
| '----------------------------------------------------------------------------------------------------------------------- | |||||
| ' UP - Apply the migration | |||||
| '----------------------------------------------------------------------------------------------------------------------- | |||||
| Sub Migration_Up(migration) | |||||
| ' Canonical memory (spec section 8: Memory type, Memory, Memory revision) plus sessions, | |||||
| ' checkpoints, idempotency records and the audit trail. Verification is stored per revision, | |||||
| ' never per memory, so editing content cannot carry verification forward (spec 8.1). | |||||
| migration.ExecuteSQL "CREATE TABLE memory_types (" & _ | |||||
| "code TEXT PRIMARY KEY, " & _ | |||||
| "description TEXT NOT NULL)" | |||||
| migration.ExecuteSQL "INSERT INTO memory_types (code, description) VALUES " & _ | |||||
| "('working','Current task state, checkpoints')," & _ | |||||
| "('episodic','Time-bound experience and outcome')," & _ | |||||
| "('semantic','Facts and concepts')," & _ | |||||
| "('procedural','Reusable instructions and skills')," & _ | |||||
| "('preference','User or organization preferences')," & _ | |||||
| "('decision','Recorded choices and rationale')," & _ | |||||
| "('constraint','Applicable requirements or rules')," & _ | |||||
| "('lesson','Generalized learning from evidence')," & _ | |||||
| "('hypothesis','Unverified proposed explanation')," & _ | |||||
| "('goal','Desired outcome')," & _ | |||||
| "('solution','Reusable problem resolution')" | |||||
| migration.ExecuteSQL "CREATE TABLE memories (" & _ | |||||
| "id TEXT PRIMARY KEY, " & _ | |||||
| "tenant_id TEXT NOT NULL REFERENCES tenants(id), " & _ | |||||
| "namespace_id TEXT NOT NULL REFERENCES namespaces(id), " & _ | |||||
| "type TEXT NOT NULL REFERENCES memory_types(code), " & _ | |||||
| "current_revision INTEGER NOT NULL DEFAULT 1, " & _ | |||||
| "lifecycle_status TEXT NOT NULL DEFAULT 'active' CHECK (lifecycle_status IN ('active','retired','superseded')), " & _ | |||||
| "valid_from TEXT, " & _ | |||||
| "valid_until TEXT, " & _ | |||||
| "creator_principal_id TEXT NOT NULL REFERENCES principals(id), " & _ | |||||
| "created_at TEXT NOT NULL, " & _ | |||||
| "updated_at TEXT NOT NULL)" | |||||
| migration.CreateIndex "idx_memories_namespace", "memories", "tenant_id, namespace_id, lifecycle_status" | |||||
| migration.CreateIndex "idx_memories_type", "memories", "tenant_id, type" | |||||
| migration.ExecuteSQL "CREATE TABLE memory_revisions (" & _ | |||||
| "id TEXT PRIMARY KEY, " & _ | |||||
| "memory_id TEXT NOT NULL REFERENCES memories(id), " & _ | |||||
| "revision INTEGER NOT NULL, " & _ | |||||
| "title TEXT NOT NULL, " & _ | |||||
| "summary TEXT, " & _ | |||||
| "content TEXT NOT NULL, " & _ | |||||
| "attributes TEXT, " & _ | |||||
| "tags TEXT, " & _ | |||||
| "confidence REAL, " & _ | |||||
| "importance REAL, " & _ | |||||
| "content_hash TEXT NOT NULL, " & _ | |||||
| "change_reason TEXT, " & _ | |||||
| "verification_status TEXT NOT NULL DEFAULT 'unverified' CHECK (verification_status IN ('unverified','verified','disputed','rejected')), " & _ | |||||
| "created_by TEXT NOT NULL REFERENCES principals(id), " & _ | |||||
| "created_at TEXT NOT NULL, " & _ | |||||
| "UNIQUE (memory_id, revision))" | |||||
| migration.CreateIndex "idx_revisions_hash", "memory_revisions", "content_hash" | |||||
| ' Replays of the same Idempotency-Key return the stored response; a different request body | |||||
| ' with the same key is a conflict (spec 9.1). | |||||
| migration.ExecuteSQL "CREATE TABLE idempotency_keys (" & _ | |||||
| "tenant_id TEXT NOT NULL REFERENCES tenants(id), " & _ | |||||
| "idem_key TEXT NOT NULL, " & _ | |||||
| "request_hash TEXT NOT NULL, " & _ | |||||
| "status_code INTEGER NOT NULL, " & _ | |||||
| "response_body TEXT NOT NULL, " & _ | |||||
| "created_at TEXT NOT NULL, " & _ | |||||
| "PRIMARY KEY (tenant_id, idem_key))" | |||||
| migration.ExecuteSQL "CREATE TABLE sessions (" & _ | |||||
| "id TEXT PRIMARY KEY, " & _ | |||||
| "tenant_id TEXT NOT NULL REFERENCES tenants(id), " & _ | |||||
| "namespace_id TEXT NOT NULL REFERENCES namespaces(id), " & _ | |||||
| "principal_id TEXT NOT NULL REFERENCES principals(id), " & _ | |||||
| "objective TEXT NOT NULL, " & _ | |||||
| "status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active','completed','abandoned')), " & _ | |||||
| "outcome TEXT, " & _ | |||||
| "created_at TEXT NOT NULL, " & _ | |||||
| "updated_at TEXT NOT NULL, " & _ | |||||
| "completed_at TEXT)" | |||||
| migration.CreateIndex "idx_sessions_tenant", "sessions", "tenant_id, status" | |||||
| migration.ExecuteSQL "CREATE TABLE checkpoints (" & _ | |||||
| "id TEXT PRIMARY KEY, " & _ | |||||
| "session_id TEXT NOT NULL REFERENCES sessions(id), " & _ | |||||
| "revision INTEGER NOT NULL, " & _ | |||||
| "state TEXT NOT NULL, " & _ | |||||
| "created_by TEXT NOT NULL REFERENCES principals(id), " & _ | |||||
| "created_at TEXT NOT NULL, " & _ | |||||
| "UNIQUE (session_id, revision))" | |||||
| migration.ExecuteSQL "CREATE TABLE audit_events (" & _ | |||||
| "id TEXT PRIMARY KEY, " & _ | |||||
| "tenant_id TEXT, " & _ | |||||
| "principal_id TEXT, " & _ | |||||
| "action TEXT NOT NULL, " & _ | |||||
| "resource_type TEXT, " & _ | |||||
| "resource_id TEXT, " & _ | |||||
| "outcome TEXT NOT NULL, " & _ | |||||
| "request_id TEXT, " & _ | |||||
| "created_at TEXT NOT NULL)" | |||||
| migration.CreateIndex "idx_audit_tenant", "audit_events", "tenant_id, created_at" | |||||
| End Sub | |||||
| '----------------------------------------------------------------------------------------------------------------------- | |||||
| ' DOWN - Rollback the migration | |||||
| '----------------------------------------------------------------------------------------------------------------------- | |||||
| Sub Migration_Down(migration) | |||||
| migration.DropTable "audit_events" | |||||
| migration.DropTable "checkpoints" | |||||
| migration.DropTable "sessions" | |||||
| migration.DropTable "idempotency_keys" | |||||
| migration.DropTable "memory_revisions" | |||||
| migration.DropTable "memories" | |||||
| migration.DropTable "memory_types" | |||||
| End Sub | |||||
| %> | |||||
Powered by TurnKey Linux.