db-core-codegen
npx skills add https://github.com/pranshu-shah-at-sandbox/test --skill db-core-codegen
Agent 安装分布
Skill 文档
db-core Code Generation
Use this skill when you need to generate or update any db-core layer in a module:
- DB beans
- Document beans
- DAOs
- DB/document converters
- Procedures that call DAOs
This skill is designed to keep generation and scaffolding deterministic, schema-driven, and safe across module variants.
What this skill guarantees
- Schema-first decisions: generation inputs and converter context fields are inferred from discovered schema/model files, not script aliases alone.
- Capability-aware planning: generation resolves from module capabilities (or
generatescript), with DAO--schemasvalidation in both--plan autoand--plan chain. - Predictable converter scaffolds: defaults to
generated/beans/*imports, enforcesconvertFrom/convertTomapping rules, and preserves stable context parameter order. - Safe optional wrappers: validates and uses
src/beans/*andsrc/dao/*only when those wrappers actually exist. - Procedure-safe boundaries: procedure APIs stay DB-oriented while DAO APIs stay document-oriented, with convention-aware scaffolding defaults.
- Default audit ownership:
created_at/updated_atownership stays in DAO unless explicitly overridden. - Preflight pause/resume: pause only when
node_modulesis missing; ask the user to runnpm run install-snapshot(override script name via--install-script), then resume after user confirmation. - Self-contained execution: command usage, contracts, and post-change checks are defined in this skill without requiring external definition docs.
- Module-local context only: inference, examples, conventions, and edits are restricted to the selected
--moduleroot.
NEVER do these (anti-patterns)
- NEVER manually edit generated artifacts under
generated/beans/*orgenerated/dao/*.- Why: generators overwrite these files, so manual edits drift and are lost on regeneration.
- Correct action: change schema/model inputs and rerun generation.
- NEVER patch generated TypeScript to fix field/type/model mismatches.
- Why: generated output is derivative; schema/datamodel files are the source of truth.
- Correct action: update the schema/datamodel inputs first, then regenerate.
- NEVER write or modify code outside the target
db-corescope during this workflow.- Why: cross-scope edits create hidden coupling and unnecessary blast radius.
- Exception: update code outside
db-coreonly when the user explicitly asks for it.
- NEVER use sibling/other
db-coremodules for context inference, convention inference, or copy patterns.- Why: this introduces cross-module coupling and wrong conventions.
- Correct action: infer only from files under the selected module root.
Inputs
Collect these before making changes:
module selector: exact module path or module hint.scope:generation-only,converter-only,generation-and-converter,procedure-methods, orfull-procedure.target entities: DB bean + document + DAO + converter names.persistence contract: whether module uses directgenerated/daoor optionalsrc/daowrappers.schema locations: discover from generation scripts when not explicitly provided.
Module boundary protocol (mandatory)
- Treat the selected
--moduledirectory as the only allowed context root for module files. - Read/inspect only paths that are descendants of that module root when inferring schemas, conventions, converters, procedures, and DAO usage.
- Reject any inferred/discovered path that resolves outside module root; do not use it for decisions.
- Do not sample procedures/converters from other modules for style inference.
- If required files are missing inside module root, report and stop or continue with explicit warning; do not substitute from another module.
Reference loading protocol (mandatory)
Before any implementation, select scope and load only the required references.
generation-only:- MANDATORY – read entire
references/generation-checklist.md. - Do NOT load
references/converter-cookbook.mdorreferences/procedure-cookbook.md.
- MANDATORY – read entire
converter-only:- MANDATORY – read entire
references/converter-cookbook.md. - OPTIONAL – read
references/generation-checklist.mdonly if regeneration is also requested. - Do NOT load
references/procedure-cookbook.md.
- MANDATORY – read entire
generation-and-converter:- MANDATORY – read entire
references/generation-checklist.mdandreferences/converter-cookbook.md. - Do NOT load
references/procedure-cookbook.mdunless procedure scaffolding is explicitly requested.
- MANDATORY – read entire
procedure-methodsorfull-procedure:- MANDATORY – read entire
references/procedure-cookbook.md. - OPTIONAL – read
references/generation-checklist.mdonly when generation is in scope. - Do NOT load
references/converter-cookbook.mdunless converter changes are explicitly requested.
- MANDATORY – read entire
- Always report which references were loaded and why before running commands.
Discovery-first workflow (required)
Before creating/updating converters or procedures, do all of the following:
- Apply
Reference loading protocol (mandatory)and declare loaded files. - Parse module generation scripts and resolve schema/model paths:
- document generator (for example
json-to-schemas --datamodel ... --out ...) - DB generator (for example
jsonschema-to-typescript-objects --input ... --beans-path ...) - DAO generator (for example
pdm-to-daos --datamodel ... --schemas ... --out ...)
- document generator (for example
- Resolve all script-relative paths against module root, verify they exist, and verify each resolved path stays within module root.
- Read discovered schemas/models to capture per-entity:
- required document keys (PK/SK/index keys)
@entitydiscriminator/default- field requiredness and types
- Infer converter context fields from schema requirements:
- include required document keys not sourced from DB bean fields
- prioritize partition/sort keys, then required index keys
- keep parameter names consistent with existing module converter/procedure patterns
- If multiple context-field candidates are plausible:
- rank candidates with brief reasoning
- choose the best candidate and proceed
- surface the decision in output
- Missing discovered model/schema files should fail inference (or be surfaced as warnings when non-blocking).
Script commands
Run from repository root.
Generation
python .agents/skills/db-core-codegen/scripts/run_dbcore_codegen.py \
--module <module_root> \
--plan auto
--plan auto:
- Uses
generatescript if available. - Otherwise resolves chain by capability (DB, document, DAO, optional tx DAO).
--plan chain:
- Always resolves chain by capability.
- Requires DB + document + DAO capabilities.
- Includes tx DAO only when available or explicitly requested.
Install preflight:
- Before running generation scripts, checks
generated/beans/db,generated/beans/document, andgenerated/dao. - Also checks whether
node_modulesexists. - If
node_modulesis missing, do not run install commands automatically; pause and ask the user to runnpm run install-snapshot. - Missing/empty generated outputs are surfaced in preflight metadata, but generation still proceeds when
node_modulesexists. - Override install script name with
--install-script <script-name>.
Pause/resume protocol:
- On preflight failure, stop generation and report the exact command and module root to the user.
- Do not execute install/setup commands on behalf of the user.
- After user confirms completion, rerun the same generation command to resume.
Converter scaffolding
Flat converter layout:
python .agents/skills/db-core-codegen/scripts/generate_db_converter.py \
--module <module_root> \
--converter-dir . \
--db-type Account \
--document-type Account \
--entity-id com.example.document.account \
--with-list
Nested converter layout:
python .agents/skills/db-core-codegen/scripts/generate_db_converter.py \
--module <module_root> \
--converter-dir events/event-subscription \
--db-type EventSubscription \
--document-type EventSubscription \
--entity-id com.example.document.event_subscription \
--context-field user_id:userId
If --context-field is omitted, context fields are inferred from discovered schema/model metadata.
Procedure scaffolding
CRUD method scaffolding with convention-aware defaults:
python .agents/skills/db-core-codegen/scripts/generate_db_procedure.py \
--module <module_root> \
--db-type Link \
--document-type Link \
--methods get,post,update
Common overrides:
--timestamp-strategy procedure|daoto override timestamp ownership (default:dao).--post-generate-id always|neverto force UUID generation behavior.--beans-import-style index|entityand--dao-import-style index|entity.--dao-class <EntityDaoClass>and--dao-method-*when DAO naming differs.
Contracts
Generation contract
- Validate selected DAO/tx DAO scripts have correct
--schemasusage. - Run install preflight checks before generation; pause for manual user action only when
node_modulesis missing. - Validate generated outputs:
generated/beans/dbgenerated/beans/documentgenerated/dao
- Validate wrappers only if wrapper files exist.
- Validate package export/type contracts when present.
Converter contract
convertFrom(document)mapsDocument -> DB.convertTo(db, ...context)mapsDB -> Document.convertTomust set@entity.- Context keys must come from schema-first inference and be explicit typed parameters.
- Context parameter order should be stable:
- partition key context
- sort key context not available on DB bean
- required index context
- Failures must throw
ConverterException.
Procedure contract
- Procedure boundary accepts/returns DB objects.
- DAO boundary accepts/returns document objects.
- Procedures should use DAOs via module capability:
generated/daoby default.src/daowrappers only when that capability exists in the module.
- DAO selection must be explicit from method intent:
- Use
TableDaofor query/list/index pagination and non-atomic batch access. - Use
TransactionDaoonly when atomic all-or-nothing behavior or cross-item invariant enforcement is required. - If atomicity is not explicitly required, default to
TableDao(orEntityDaofor single-item key CRUD).
- Use
- Capture and report DAO choice inputs when scaffolding procedure methods:
- operation type (
query/list,single-item CRUD,multi-item mutation) - atomicity required (
true/false) - invariant scope (single item vs cross-item/cross-entity)
- operation type (
- Audit timestamps (
created_at/updated_atand camel variants) are DAO-managed by default.- Use
--timestamp-strategy procedureonly when a module intentionally follows that non-default pattern. - Surface the chosen strategy in output.
- Use
Output checklist
After changes:
- Generation plan is explicit and valid for detected module capabilities.
- Converter files compile and exports are updated idempotently.
- No hard failures due to absent optional wrapper files.
- Discovered schema/model paths are reported.
- Inferred context fields are reported per entity with brief reasoning.
- Dry-run output is available (human +
--jsonmodes). --jsonoutput includes:discovered_schema_pathsselected_script_pathsvalidated_schema_targetsinferred_context_fieldscontext_decisionsentity_metadatainstall_preflight(script,script_exists,command,executed,manual_action_required,missing_outputs,missing_node_modules)
- Procedure scaffold output (when used) reports:
- resolved conventions
- resolved import styles
- selected mutation strategy
- Report
loaded_referencesandreference_selection_reason. - Confirm no manual edits to generated files and no out-of-scope (
db-core) changes unless explicitly requested by the user. - Report
module_rootand confirm all module-file context paths used for inference were under that root.
References
Load these only through the Reference loading protocol (mandatory) above.
references/generation-checklist.mdreferences/converter-cookbook.mdreferences/procedure-cookbook.md