---
name: evolution-ai-product-coding
description: "AI Product Coding project (ticket #1308) — rules-driven product code/name generator on Add/Edit Item; scope doc at evolution/audits/AI_PRODUCT_CODING_PROJECT.md"
metadata: 
  node_type: memory
  type: project
  originSessionId: 44063be7-fbb8-422a-ac53-564b06349905
  modified: 2026-07-28T07:23:38.802Z
---

Ticket #1308 (BioAction, companyid `85-1701079776`, raised 2026-07-28): build an in-system
equivalent of their Google AI Studio product-code generator. Scope doc:
`evolution/audits/AI_PRODUCT_CODING_PROJECT.md`. Source ruleset attachment lives at prod
`./companies/support/tickets/1308/cc63620b1fee02d4.txt` (uploads.id 586) — "Industrial Component
Categorization & Coding Standard Ver. 2026.1".

**Status as of 2026-07-28: scoped only, no code written.**

Core architecture decision: **AI extracts, code assembles.** Claude (Haiku 4.5, forced tool_use
JSON) turns a messy description into category + typed attribute values; a deterministic PHP
builder (`library/invCodeBuilder.php`, no API calls) assembles the Standardized Name and Product
Code. Never let the model produce the final code string — `inventory.code` is varchar(30) UNIQUE,
so the 30-char limit and compression protocol are schema constraints, and they must be
reproducible and unit-testable.

Reuses the existing attribute system (`inv_spec_def` / `cat_spec` / `inv_spec_values`) as the slot
vocabulary — that persistence is the whole advantage over the Playground. Five new tenant tables
proposed: `inv_code_profile` / `_template` / `_token` / `_rule` / `_log`. Extends, does not
replace, the client-side `autocode()` in invadd.inc:16-71 and `categories.autocode`.

Phase 1 is the deterministic engine + fixture tests BEFORE any AI — if the rules engine can't
reproduce the standard from hand-coded fixtures, AI won't save it.

Prereqs (Phase 0): run the unrun `migrations/claude_usage_tracker.sql`; fix four defects in
`inveditspecs.inc` — `$_REQUEST['id']` interpolated into SQL (SQLi, lines 4 and 7), inv_spec_values.id
compared against inv_spec_def.id at line 29, `$value` leaking between iterations, and the text
input hardcoding `value=''` at line 47 so saved text attributes never render back.

Related: [[evolution-ai-quote-notes]] (reference implementation + UI convention),
[[claude-usage-tracker]] (mandatory metering choke point), [[evolution-ajax-save-auth-gate]],
[[feature-release-docs-policy]], [[evolution-getfieldarray-deprecated]].
