- Cargo.toml: alkgen 0.1.0, deps alktype 0.3.0 + handlebars 6.4 + serde_json (preserve_order) + thiserror; empty lib - AGENTS.md: family-style conventions (wasm-clean, strict templates, template-is-code, generated-code hygiene) + reference map - verified: cargo check/clippy/fmt, wasm32-unknown-unknown release build
7.1 KiB
AGENTS.md
Operating instructions for opencode agents working in this repo. opencode
auto-loads this file as instructions, overriding the built-in defaults for
this project. Custom agents in .opencode/agents/ inherit these rules
unless their own prompts say otherwise.
Git Workflow
Commit and push when reasonable. When a change is complete and
verified (build + lint + tests pass), commit and push to origin/main
without asking. This overrides the built-in default of "only commit when
explicitly asked."
The workflow:
- Make the change
- Verify:
cargo test,cargo clippy --all-targets -- -D warnings,cargo fmt --check,cargo doc --no-depsif docs changed,cargo build --target wasm32-unknown-unknown --releaseif dependency/wasm-relevant code changed - Inspect
git statusandgit diffbefore staging — stage only the intended files, never secrets - Write a concise commit message matching the repo style (see
git log --oneline -10). For multi-point changes, use a summary line plus a body with bullet points and a verification block. git push origin main- Report the commit hash and the verification summary
Exceptions — do not commit or push without asking:
- The change is exploratory / speculative (you're not sure the user wants it kept)
- The user is actively reviewing the diff and may ask for changes
- The change touches semver-relevant public API (this crate is headed to crates.io; once published, renames/removals/signature changes on public items are breaking — additive changes are fine)
- You'd be force-pushing, amending a published commit, creating an empty commit, or skipping hooks
Never commit secrets, keys, or credentials. If a commit fails or hooks reject it, fix the issue and create a new commit — do not amend the failed one.
Git identity is preconfigured (glm-5.2 <glm-5.2@alk.dev>). Do not
change git config, skip hooks, or use git commit -i.
Project Conventions (Rust / template codegen crate)
This is a template-based codegen engine: handlebars-rust templates
rendered over alktype BAST documents to produce code artifacts (binary
readers/writers/validators, protocol handlers). Conventions apply to all
work in src/ and tests/.
-
No comments in code unless the user explicitly asks. This is a project-wide convention. Doc comments (
///,//!) are fine and expected on public API. Inline//comments only when the user asks or when a non-obvious safety/correctness constraint would otherwise be missed. -
Error handling —
thiserrorfor library error types. No panics in library code. Nounwrap()orexpect()outside tests — if you reach forunwrap, the error path wasn't specified, stop and decide what should actually happen. Template registration/render failures are data, not crashes: a malformed template or BAST input must produce a typed error, never a panic (generated code feeds alkcall, which accepts BAST from arbitrary peers). -
No
async— template rendering and codegen are synchronous, CPU-bound operations. No tokio, no async/await in the core. (If a future file-watch/rebuild service is wanted, that is an assembly- layer concern, not a lib concern.) -
WASM-clean — the crate must compile to
wasm32-unknown-unknown. No filesystem access in library code (handlebarsdir_sourcefeature is off-limits in lib code; templates come from strings orinclude_str!). No threads, nostd::time, no platform deps. If you reach for a new dependency, first verify it is wasm-compatible and worth the cost. -
serde_jsonpreserve_orderis load-bearing — alktype relies on it (field order in schema JSON determines packed byte order). Do not disable it and do not sort schema keys in contexts built for templates unless the template explicitly requires a sort. -
Strict template mode —
Handlebars::set_strict_mode(true)for any registry the lib renders with. A missing variable in a codegen template must be a render error, not silently-empty output (silent gaps become compile bugs in the consumer's build, far from the cause). alkminer-v1'sShaderBuilderis the precedent. -
Templates are code — templates live as
const &str(inline) orinclude_str!files, versioned in-repo, with render tests pinning their output. Changing a template changes generated code; treat template edits with the same care as source edits (tests must pin golden output before merging). -
Generated-code hygiene — generated artifacts start with a "Auto-generated by alkgen. DO NOT EDIT." banner (typebox-rs precedent). Rendering must be deterministic: same BAST + same templates + same options → byte-identical output (no HashMap iteration order leaking into generated code).
-
Naming — Rust standard:
snake_casefor functions/variables/ modules,PascalCasefor types/traits,SCREAMING_SNAKE_CASEfor constants. Template registry names: lowercase kebab or snake, one name per template kind. -
Module structure — one module per file under
src/, re-exported fromsrc/lib.rs. Public API surface is thelib.rsre-exports. -
No
unsafe— zero unsafe blocks. If a perf argument appears, the answer lives in the template/data-model layer, not in unsafe.
Verification Commands
Run these before committing. All must pass.
cargo test # full suite
cargo clippy --all-targets -- -D warnings
cargo fmt --check
cargo doc --no-deps # if docs changed
cargo build --target wasm32-unknown-unknown --release # if deps/wasm-relevant code changed
cargo publish --dry-run --allow-dirty # before a release
Architecture Context
docs/sdd_process.md— the SDD workflow (phases, roles, task format). Phase 0 (research/POC) runs before architecture; small changes may skip the ceremony per the doc's "reasonable exceptions" clause.docs/research/phase-0.md— the current phase-0 findings + OQ list. Read it before proposing design changes; extend it when research answers questions.docs/architecture/— will exist after Phase 1; the authoritative spec once present (ADRs numbered, OQs tracked in open-questions.md).tasks/— task graph after decomposition.
Reference Material (outside this repo)
/workspace/@alkdev/alktype— the BAST engine (crates.io 0.3.0); docs/architecture/ there is the schema/layout/validation spec./workspace/@alkimiadev/typebox-rs/src/codegen— older handlebars codegen precedent (simple context structs + inline templates)./workspace/@alkminer/reference/alkminer-v1/src/compute/kernel.rs— handlebars-as-JIT precedent (strict registry, partials, render-then- compile with cache)./workspace/@alkdev/alkhttp/src/adapters—from_openapi/from_jsonschemahandler shapes the call-protocol codegen mirrors./workspace/@alkdev/alkcall— channels consumer; generated readers/writers/validators serve its channels./workspace/handlebars-rust— vendored handlebars checkout (head; crates.io 6.4.4 is the pinned stable).