AGENTS.md 8.8 KB

Prod2U CPLD Operating Rules

This checkout implements the Prod2U door-temperature controller. The active product contract is projects/prod2u-door-temp/project.json, projects/prod2u-door-temp/requirements.zh-CN.md, and docs/prod2u-door-temp-protocol.zh-CN.md. Generated contracts, constraints, source manifests, tests, TD inputs, and packages must derive from that contract.

Current authority is limited to the above contract files, this AGENTS.md, and generated artifacts. Historical design documents are not active authority.

Execution priorities

  1. Core limit one-shot behavior and startup calibration (seek-close then measure-open) first.
  2. Keep behavior simple and deterministic inside the declared constraints.
  3. Form a minimally usable, synthesizable version quickly.
  4. Reduce LUT and Slice after core function is correct.
  5. Reduce LUT and Packed Slice after core function is correct.
  6. Generalization, security, exception coverage, compatibility, long-term maintenance, performance tuning, and perfect documentation are lower priority.

"Reliable" means deterministic under these assumptions: host may send a new door percent while an axis is moving (latest-wins; at most one already-started STEP finishes); duty and door percent are 0..100; mid positions are open-loop estimates from gated STEP rises and startup-measured travel; no undeclared command queue; hardware wiring matches the current project/ADC.

Model and effort policy

  • MODEL_POLICY=unconstrained.
  • REASONING_EFFORT_POLICY=unconstrained.
  • MODEL_OR_EFFORT_IS_ACCEPTANCE_GATE=false.

Dynamic agent rules

  • No fixed sub-agent roster, fixed Team A/B/C/D, fixed agent count, agent registry, message bus, dedicated agent database, complex run-state, role definitions copied for every tool, or heavy JSON evidence.
  • The root AGENTS.md is the single long-term, tool-independent rule source.
  • Tool-specific rules (.devin/, .cursor/, .codex/, .agents/) are only kept if they are thin tool adapters that point here; they must not reproduce the full product contract or define a static team.
  • Sub-agents are created dynamically only for independent, temporary tasks and end when that task ends. Different writers never modify the same file or logic without coordination.

Git and worktree rules

  • Do not reset, clean, stash, restore, overwrite, or delete changes from unknown sources.
  • Work directly on dev only when it is clean and no other session is touching the same files.
  • When dev is dirty or another session is active, use a temporary branch/worktree.
  • Temporary branches/worktrees are conflict-prevention measures, not a long-lived branch system.
  • All accepted production code, tests, and docs must end up in dev.
  • The final state of every task is a clean dev working tree with accepted changes committed/merged.
  • Delete temporary branches/worktrees created for this task once they are no longer needed.

Product contract

破坏性协议迁移(勿按旧上位机假设发帧)
旧合同:门字节 00=不启动 jog / 心跳,01=开 450 步,02=关 450 步;busy 忽略新门命令;watchdog 10 s → FAN 20;startup 关门寻限 + 未命中则 500 步 backoff。
新合同:门字节为闭合百分比 00=全开 … 64=全关;合法 SET_ALL latest-wins;位置按 gated STEP 计数;标定先 seek-close 再 measure-open;watchdog 30 s → PTC 0 / FAN 10;新增 GET_MOTOR_STATUS 0x03 / MOTOR_STATUS_DATA 0x83(31 字节 payload)。无 ACK / 无命令队列。旧上位机若继续把三门填 00 当心跳,将驱动三轴核对并运行到全开限位。

  • UART: 25 MHz, 115200 8N1, 217 clocks/bit, A5 5A framing, CRC-16/CCITT-FALSE.
  • Supported frame types: 0x01 SET_ALL, 0x02 GET_TEMPERATURE, 0x03 GET_MOTOR_STATUS, 0x82 TEMPERATURE_DATA, 0x83 MOTOR_STATUS_DATA.
  • SET_ALL payload: 4 FAN + 4 chamber PTC (each duplicated to 2 physical PTC PWM) + Z/X/Y door percent bytes (11 bytes total).
  • Door byte 0..100: close-percent target (0=full open, 100=full close). Values 101..255 reject the whole frame.
  • After startup_complete: each valid SET_ALL commits thermal + three axis requested percents atomically and feeds the watchdog (including identical repeats). Different percent → latest-wins replan.
  • PTC active high; FAN active low at FPGA output.
  • PWM ~20 Hz.
  • Watchdog 30 s -> PTC 0, FAN 10 (enabled only after startup_complete).
  • Motion: open-loop percent positioning from startup-measured travel_steps; mid targets use half-up clamp to 1..travel-1; endpoints 0/100 complete only on real open/close limits. X, Y, and Z may overlap.
  • Motor EN: CON120.2 / C11, NPN invert at board; FPGA constant 1 (permanent_high).
  • No ACK, BUSY, ERROR, command queue, legacy jog compatibility, background temperature scan, or solenoid actuator.

Limit and startup contract

  • Six limits (active high at FPGA, runtime_use=true):
    • X: LS CON12.1 A5, HS CON12.2 B6
    • Y: LS CON12.3 C8, HS CON12.4 A8
    • Z: LS CON129.1 K16, HS CON129.2 J15
  • Motors: X STEP/DIR CON104.2/3 C12/B12; Y CON105.2/3 L12/J11; Z CON106.2/3 L14/K14.
  • Runtime: direction-select limit hard-stop each clock; truncate current STEP high pulse immediately after synchronized limit (truncate_current_high_pulse_immediately_after_synchronized_limit). Ordinary command / watchdog / endpoint-guard stops do not truncate a high pulse; they forbid the next rise.
  • Startup calibration (once per power-on/reset/reconfig): PTC 0%, FAN 10%; each axis independently seek-close (≤5000 gated STEP) then measure-open (≤5000); travel_steps latched on success; no 500-step backoff. Failed axes FAULT-lock until reset; partial success allowed. X/Y/Z may move concurrently and stop independently.
  • startup_complete is sticky until next FPGA power-on, global hardware reset, or reconfiguration.
  • During calibration: valid SET_ALL may update FAN/PTC but ignores door percents (no cache); GET_MOTOR_STATUS allowed; GET_TEMPERATURE dropped (no response); watchdog not enabled/fed.
  • After startup_complete: host must re-send desired percents; ordinary percent motion and runtime limit policy apply; calibration FSM does not restart.

Tooling preference

  • Linux container is the authoritative execution environment for bootstrap, verification, TD, and packaging.
  • Prefer thin tools/*.sh entrypoints that call Python modules; do not use Windows PowerShell / .ps1 as the production path.
  • Container-local package installs (apt/pip/npm) are allowed when reconstructing the toolchain; do not modify the host outside the container.
  • Temporary/run state uses Linux XDG paths ($XDG_CACHE_HOME, $XDG_STATE_HOME, $XDG_RUNTIME_DIR, $TMPDIR), never Windows C:\... or Downloads as authority.
  • Durable toolchains (OSS CAD Suite archive + extract, Anlogic TD) must live on persistent volumes such as /data/prod2u/ (or OSS_CAD_SUITE_ROOT / PRODU2_TOOLCHAIN_BASE), not overlay ~/.cache which disappears on container rebuild.
  • TD command is td2026 (Anlogic TD 2026.1 SP2 Linux). Do not call td603, Windows td_commands_prompt.exe, or hard-code C:\Anlogic\....
  • Keep TD LD_LIBRARY_PATH / vendor Qt vars confined to the TD subprocess; they break apt and other tools if exported globally.
  • Final acceptance evidence must be produced by the current Linux run; historical Windows receipts are historical only.
  • Prefer Python for cross-platform scripts and deterministic automation.

Necessary tests

  • Product, protocol, generator, packaging, and Git protection Python tests.
  • Icarus testbenches for the active Prod2U top, including startup seek-close/measure-open calibration and runtime limit hard-stop / latest-wins behavior.
  • Verilator lint, cocotb UART tests, and formal checks when the environment is available and cost is reasonable.

Evidence boundaries

  • Distinguish source, simulation, formal, TD, package, and physical-hardware evidence.
  • fail, blocked, not_run, placeholder, or exploratory evidence is never a pass.
  • Receipts bind run ID, exact full commit, project hash, source-manifest hash, command, tool version, status, and applicable bitstream hash.

Remote ChatGPT adviser usage

  • If a task provides an exact ChatGPT conversation URL, the local top-level Agent may use the existing Playwright MCP / Microsoft Edge session to open that URL and continue the conversation.
  • Upload only the current core/source package; do not create new sessions, use share links, switch browsers, use the API, or send sub-agents separately.
  • Use natural language; do not force JSON, fixed turn budgets, or short timeouts.
  • If Playwright MCP is unavailable, record the blocker and continue locally; the adviser is not a hard gate.

Protected operations

  • Never access COM or JTAG, program hardware, install drivers, or modify global PATH.
  • Do not create fixed ChatGPT Adviser plugins, ledgers, or sessions.
  • Hardware validation is not_run unless explicitly authorized in a future task.