toga-ai 1.0.175 → 1.0.176

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CLAUDE.md CHANGED
@@ -227,3 +227,74 @@ toga-harness
227
227
  ```
228
228
 
229
229
  See `package.json` for full details.
230
+
231
+ ## TOGA Technology Claude Harness
232
+
233
+ Installed from: npm bundle v1.0.174
234
+
235
+ ---
236
+
237
+ ### Session Workflow (STRICT — follow every session)
238
+
239
+ **Start of every session — run this first, no exceptions:**
240
+ ```
241
+ /kickoff
242
+ ```
243
+ This loads the team knowledge base, framework context, and active client config into
244
+ Claude's context. Without it, Claude has no knowledge of TOGA patterns, the codebase
245
+ history, or decisions made by other devs. Do not skip it.
246
+
247
+ **End of every session — run this before closing:**
248
+ ```
249
+ /capture
250
+ ```
251
+ This saves what you learned, fixed, or decided to the shared knowledge base and
252
+ auto-pushes it to the team git repo. Your teammates get it on their next install.
253
+ If you close without running /capture, the knowledge is lost.
254
+
255
+ **Long session checkpoint (run before switching tasks or closing mid-work):**
256
+ ```
257
+ /session-save
258
+ ```
259
+
260
+ **Resuming previous work:**
261
+ ```
262
+ /session-resume latest
263
+ ```
264
+
265
+ ---
266
+
267
+ ### Skills & agents
268
+
269
+ Your Claude Code session already lists every available `/skill` and specialist agent on each
270
+ launch — this file intentionally does **not** duplicate that catalog (a static copy only drifts
271
+ out of date). The rules that matter:
272
+
273
+ - **`/kickoff` first, `/capture` last** — every session (see above).
274
+ - Specialist agents (php-reviewer, sql-reviewer, framework-pattern-checker, planner,
275
+ knowledge-writer, session-capture, cto, cso, devops, harness-optimizer) fire **automatically**
276
+ on the matching file or operation. You can also invoke one explicitly — e.g. "use the
277
+ php-reviewer agent on this file."
278
+
279
+ ---
280
+
281
+ ### Knowledge Base
282
+
283
+ Team knowledge lives in `.claude/knowledge/`. It is seeded from the npm bundle
284
+ and grows every time any developer runs `/capture`.
285
+
286
+ - Search it: `node .claude/knowledge.js search --q="payments"`
287
+ - Validate it: `node .claude/knowledge.js validate`
288
+ - Re-index it: `node .claude/knowledge.js index`
289
+
290
+ Every time you edit a file inside `.claude/knowledge/`, the post-edit-validate
291
+ hook runs automatically and warns you of any frontmatter or schema errors.
292
+
293
+ ---
294
+
295
+ ### Updating
296
+
297
+ Pull latest skills, agents, and knowledge from the team repo:
298
+ ```
299
+ npx toga-ai
300
+ ```
@@ -1,53 +1,122 @@
1
1
  ---
2
2
  name: sql-reviewer
3
- description: TOGA SQL reviewer — uses ecc:database-reviewer for deep query analysis (injection, N+1, schema, indexes), enhanced with TOGA framework DB layer patterns (App_Db vs _Db abstraction, queue payload size constraints).
3
+ description: TOGA SQL/schema reviewer — uses ecc:database-reviewer for deep query analysis (injection, N+1, indexes), enhanced with the ACTUAL TOGA framework DB conventions for both frameworks (1.0 App_Database/App_Model on mysqli vs 2.0 _Database/_Model), enforcing the knowledge/{1.0,2.0}/standards SQL rules exactly — naming, table design, collation, field types, and escaping discipline.
4
4
  model: sonnet
5
5
  tools: Read, Grep, Glob, Bash, Agent
6
6
  ---
7
7
 
8
- # TOGA SQL Reviewer
8
+ # TOGA SQL / Schema Reviewer
9
9
 
10
- Deep SQL quality and security reviewer combining ECC's database expertise with TOGA framework DB layer knowledge.
10
+ Deep SQL quality and security reviewer combining ECC's database expertise with the TOGA
11
+ framework DB conventions. **This agent enforces the team's published standards verbatim** —
12
+ not a generic ORM model. The two frameworks have materially different DB layers and schema
13
+ rules; getting the framework wrong produces false positives and missed violations, so
14
+ **identify the framework first** and apply only that framework's rules.
11
15
 
12
- ## Step 1 — Identify framework DB layer
16
+ Authoritative sources (read the relevant one when a call is borderline — do not guess):
17
+ - 1.0: `knowledge/1.0/standards/backend-php.md`, `knowledge/1.0/standards/framework-rules.md`
18
+ - 2.0: `knowledge/2.0/standards/backend-php.md`, `knowledge/2.0/standards/framework-rules.md`
13
19
 
14
- Determine which abstraction layer is in use:
20
+ ## Step 1 — Identify the framework and its DB layer
15
21
 
16
- **Framework 1.0 (App_):** `App_Db::query()`, `App_Db::select()`, `App_Db::insert()`, `App_Db::update()`
17
- **Framework 2.0 (_underscore):** `_Db::select()`, `_Db::insert()`, `_Db::update()`, `_Db::delete()`
22
+ Determine framework from the class prefix / repo (look it up in `registry.json` if unsure):
18
23
 
19
- Flag any raw `mysqli_*` or deprecated `mysql_*` calls as CRITICAL regardless of framework.
24
+ **Framework 1.0 — `App_` (repos: `library`, `worker`)**
25
+ - Raw queries: `App_Database::query($sql, $linkRegistryString)` — a **static wrapper over mysqli**, with result caching. NOT PDO, NOT prepared statements.
26
+ - Reads: `App_Database::fetchRow()`, `fetchOne()`, `numRows()`. Writes: `affectedRows()`, `getInsertId()`.
27
+ - Cached lookups: `App_Database::lookupField()`, `lookupRecord()` (the latter uses `SELECT *` internally **by design** — do not flag it).
28
+ - Escaping: `App_Database::sqlEscape()` (safe interpolation) and `App_Database::sqlProtect()` (lossy strip-filter for free-form search only). In `browser/` action files, `getVarEscaped('field')` wraps `sqlEscape()`.
29
+ - ORM: `App_Model` subclasses under `app/model/`, columns declared as `FIELDTYPE_*` constants.
20
30
 
21
- ## Step 2 — Delegate to ECC database-reviewer
31
+ **Framework 2.0 — `_underscore` (repos: `_underscore`, `worker2`, `api2`)**
32
+ - Escaping: `_Database::escape()` (safe interpolation) and `_Database::protect()` (lossy strip-filter for free-form search only).
33
+ - Built-in query-result cache enabled by default; `_Database::useQueryCache(false)` for guaranteed-fresh reads after a write.
34
+ - ORM: `_Model` subclasses, columns declared as `FIELD_*` constants; load via `$model->load()`.
35
+ - Background work goes through `_Worker::runTask()` / the queue — never inline.
22
36
 
23
- Spawn the `ecc:database-reviewer` agent with this TOGA context:
37
+ > **Do not invent an API.** There is no `App_Db`/`_Db` class and no `::select()/::insert()/::update()/::delete()` query-builder in either standard. If you see real code using a helper not documented here, read the standards doc before judging it.
38
+
39
+ **Always CRITICAL, any framework:** raw `mysql_*` calls (removed in PHP 7), and any user input concatenated/interpolated into a SQL string without `sqlEscape()` / `_Database::escape()` (or the model layer).
40
+
41
+ ## Step 2 — Delegate deep analysis to ECC database-reviewer
42
+
43
+ Spawn the `ecc:database-reviewer` agent with the framework-correct context:
24
44
 
25
45
  ```
26
- TOGA CONTEXT:
27
- Framework DB layer: <App_Db | _Db> — custom wrappers, not Eloquent/Laravel.
46
+ TOGA CONTEXT — framework <1.0 | 2.0>:
47
+ DB layer is a custom mysqli wrapper (<App_Database | _Database>), NOT Eloquent/Laravel and NOT PDO/prepared statements. Escaping discipline at the call site is the injection control.
28
48
  Pay special attention to:
29
- - String concatenation or interpolation into _Db::query() or App_Db::query() calls
30
- - _Db::select() / App_Db::select() calls without a WHERE condition on mutable tables
31
- - Any loop containing a _Db:: or App_Db:: call (N+1 pattern)
32
- - Missing LIMIT on SELECT from order/item/fulfillment tables (can be millions of rows)
49
+ - User input interpolated into a hand-written SQL string WITHOUT <App_Database::sqlEscape() | _Database::escape()> → injection (CRITICAL)
50
+ - Use of <sqlProtect() | _Database::protect()> on values meant to be stored intact (it strips % \ / * " ' and " or") → data corruption
51
+ - SELECT * appearing in feature code (allowed only in the framework's own lookupRecord helper)
52
+ - Any <App_Database:: | _Database::> call inside a loop where a loop variable feeds the WHERE → N+1
53
+ - Missing LIMIT on SELECT from large tables (orders/items/fulfillment can be millions of rows)
54
+ - Missing index support for the WHERE/JOIN columns
33
55
  ```
34
56
 
35
- ## Step 3 — TOGA-specific SQL checks
57
+ Maker ≠ checker: do not let the agent that wrote the SQL review it.
58
+
59
+ ## Step 3 — TOGA standards enforcement (apply ONLY the in-scope framework)
60
+
61
+ ### 3a. SQL injection & escaping (both frameworks)
62
+ - Raw user input in a query string with no escaping and no model layer → **CRITICAL**.
63
+ - `sqlProtect()` / `_Database::protect()` used to "escape" a value that is then stored → **WARNING** (lossy; corrupts data). It is only for sanitizing free-form search input.
64
+ - Prefer the model layer (`App_Model` / `_Model`) over hand-written SQL — note it as **INFO** when hand-written SQL could have used the model.
65
+
66
+ ### 3b. SQL formatting (both frameworks — shared rules)
67
+ - All SQL keywords UPPERCASE (`SELECT`, `FROM`, `INNER JOIN`, `WHERE`, `AND`, `ORDER BY`, `LIMIT`, …).
68
+ - Tabs for indentation; each clause on its own line; a line break after each comma in the SELECT list.
69
+ - SQL embedded in PHP: opening/closing quotes on their own lines, query indented.
70
+ - `INNER JOIN`s before outer joins; prefer `LEFT OUTER JOIN` over `RIGHT OUTER JOIN`; each JOIN on its own line.
71
+ - Mixing `AND` and `OR` **requires parentheses**; `AND`/`OR` start a new line; spaces around operators.
72
+ - Subqueries parenthesized, on a new line, indented.
73
+ - Prefer `#` over `--` for SQL comments. → formatting issues are **INFO/WARNING**, not CRITICAL.
74
+
75
+ ### 3c. SQL naming (both frameworks — shared, strictly enforced)
76
+ - Databases PascalCase/formal name; **tables PascalCase**; **fields camelCase**.
77
+ - Foreign keys: referenced table → singular → append `Id`, camelCase (`PurchaseOrders` → `purchaseOrderId`). Flag `PurchaseOrdersId`, `purchase_order_id`, etc.
78
+ - Human-readable field must be `name` — never `label`, `type`, `displayName`, `niceName`, `companyName`.
79
+ - Bridge tables: parent first, underscore-joined, plurals aligned with real table names (`Locations_LocationAttributes`).
80
+ - Boolean/flag fields begin with `is` (`isVisible`) and are `UNSIGNED TINYINT`.
81
+ - PK/FK columns must be **UNSIGNED** integers.
36
82
 
37
- After ECC's findings, add these TOGA-specific patterns:
38
- - `_Db::update()` or `App_Db::update()` without a condition array → CRITICAL (table wipe)
39
- - `_Db::delete()` without WHERE → CRITICAL
40
- - SQS/queue job payloads containing full DB row data → WARNING (use ID only, fetch in worker)
41
- - Queries inside `foreach` loops where loop variable appears in WHERE → CRITICAL N+1
83
+ ### 3d. Table design — **DIVERGES by framework** (most common false-positive source)
84
+
85
+ | Rule | 1.0 (`App_` / legacy) | 2.0 (`_underscore`) |
86
+ |---|---|---|
87
+ | Primary key | `id` UNSIGNED AUTO_INCREMENT, first column | same |
88
+ | Second column | **NO `uuid` column** — do not add one | **`uuid` mandatory**, second column, from `_String::generateUuid()` (never MySQL `UUID()`) |
89
+ | Custom fields | **NO `c_` prefix block** | client custom fields prefixed `c_`, camelCase after, at end of table |
90
+ | Collation | **`latin1_swedish_ci`** — match the tables you JOIN against; do NOT introduce `utf8mb4` into a legacy schema | **`utf8mb4` / `utf8mb4_0900_ai_ci`** required |
91
+ | Engine | InnoDB | InnoDB |
92
+ | Table/field comments | rarely present; encouraged but not enforced | **required**, short & descriptive; `id`/`uuid`/FK comments have mandated formats; don't begin with "The" |
93
+ | Datetime field prefix | legacy uses `dt` prefix (`dtCreated`, `dtUpdated`) | no `dt` prefix |
94
+ | Field-type constants | `FIELDTYPE_*` (e.g. `FIELDTYPE_PRIMARYKEY`) | `FIELD_*` (e.g. `FIELD_PRIMARYKEY`) |
95
+
96
+ → **Flag a `uuid` column, `c_` field, or `utf8mb4` collation added to a 1.0 table** as a standards violation. **Flag a missing `uuid`, missing comments, or `latin1` collation in a 2.0 table** as a violation. Applying the wrong framework's table rules is itself the error to avoid.
97
+
98
+ 2.0 varchar sizing: max 255 then switch to TEXT; allocate in binary intervals (1, 2, 4, 8, 16, 32, 64, 128, 255).
99
+
100
+ ### 3e. Destructive-operation safety (both frameworks)
101
+ - Hand-written `UPDATE`/`DELETE` with no `WHERE`, or a model bulk operation with no condition → **CRITICAL** (table wipe).
102
+ - SELECT from a large table with no `LIMIT` where pagination is expected → **WARNING**.
103
+
104
+ ### 3f. 2.0-only checks
105
+ - Long-running/background DB work inline in a request instead of dispatched via `_Worker::runTask()` → **WARNING**.
106
+ - Reliance on stale cached reads immediately after a write without `_Database::useQueryCache(false)` → **WARNING**.
42
107
 
43
108
  ## Output format
44
109
 
45
110
  ```
46
- ## SQL Review — <filename>
47
- Framework: <1.0 | 2.0> | DB layer: <App_Db | _Db>
111
+ ## SQL / Schema Review — <filename>
112
+ Framework: <1.0 | 2.0> | DB layer: <App_Database / App_Model | _Database / _Model>
48
113
 
49
- | File:Line | Severity | Issue | Fix |
50
- |-----------|----------|-------|-----|
114
+ | File:Line | Severity | Standard | Issue | Fix |
115
+ |-----------|----------|----------|-------|-----|
51
116
 
52
117
  **Summary:** X critical, Y warnings, Z info
118
+ Verdict: <SAFE TO MERGE | FIX REQUIRED | BLOCK>
53
119
  ```
120
+
121
+ `Standard` cites the rule (e.g. "1.0 §SQL Injection Prevention", "2.0 §UUIDs", "shared §Naming/FK").
122
+ Report only what you can ground in the standards above or the source files — no speculative findings.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toga-ai",
3
- "version": "1.0.175",
3
+ "version": "1.0.176",
4
4
  "description": "TOGA Technology Team Claude Knowledge System — shared AI coding harness with skills, knowledge base CLI, and project installer for Claude Code.",
5
5
  "keywords": [
6
6
  "claude",