// To create demo_eai: paste create_script.txt into an AI CLI such as Claude Code, from the Manager root (Agent mode).
// Every plain line is a sentence to your AI assistant. Lines starting with // are notes for you; the AI ignores them.
// There are no shell commands: the AI maps each sentence to the right CLI call, and the context engineering (CE)
// in the Manager and in the created project holds the details, so the script stays short. Add words to steer it,
// for example "skip security", "(order_b2b only)" or a list of Feature names instead of "using default names".
//
// This annotated file is the single source for BOTH bare scripts - never edit the generated ones by hand.
//   Untagged lines go into both scripts.
//   "[adaptive] " lines go only into create_script.txt: use Docker or Podman if one is running, else degrade.
//   "[opt-out] " lines go only into create_script_no_container.txt: never use a container, even if one is running.
//   An "[opt-out] // ..." line keeps its // note in create_script_no_container.txt (self-documentation for that script).
// Regenerate both from this directory:
//   grep -v '^//' create_script_annotated.txt | grep -v '^\[opt-out\] ' | sed 's/^\[adaptive\] //' | cat -s | sed '/./,$!d' > create_script.txt
//   grep -v '^//' create_script_annotated.txt | grep -v '^\[adaptive\] ' | sed 's/^\[opt-out\] //' | cat -s | sed '/./,$!d' > create_script_no_container.txt

// 0 - Environment
// The script adapts to what is installed. With no running Docker or Podman it continues in DEGRADED mode: SQL
// authentication instead of Keycloak, and Kafka tested through the debug endpoint instead of a broker. You are told
// up front. Add a container later and nothing needs to change in the code (set KAFKA_SERVER and restart; run
// add-auth for Keycloak). The no-container script is the opt-out: it degrades on purpose, even when containers exist.
[opt-out] // create_script_no_container.txt: the opt-out. It never uses Docker or Podman, even when one is running.
[opt-out] // Security uses the SQL authentication provider (no Keycloak); row-level security is still tested.
[opt-out] // Kafka runs in fallback mode (KAFKA_SERVER unset): subscribe is tested through the debug endpoint
[opt-out] // (/consume_debug/order_b2b, simulated); live Kafka delivery is not verified.
[opt-out] // The main script, create_script.txt, does the same by itself when no container runtime is running.
[adaptive] Check for Docker or Podman. If neither is running, continue in degraded mode (SQL security, simulated Kafka) and tell me so up front.
[opt-out] Do not use Docker or Podman, even if one is running: continue in degraded mode (SQL security, simulated Kafka) and tell me so up front.

// A - Create Project
// Before any rules, this already gives you: a JSON:API (filtering, sorting, pagination, optimistic locking, Swagger),
// MCP-discoverable by AI agents, and a multi-table Admin App. After this line demo_eai is the active project, so the
// lines below do not repeat its name.
create project demo_eai from samples/dbs/basic_demo.sqlite

// B - Security
// Keycloak (in a container) when a container runtime is running, else the SQL authentication provider that ships in
// the project. The row-level security requirement is exercised either way. You are told which one was used.
add security (degrade to SQL if Keycloak is not available)

// C - Implement Requirements
// The build (a few minutes): the six requirements are read, copied into the project's docs/requirements/, and become
// rules, a B2B API, Kafka subscribe and publish, security grants, and an order-flow dashboard on the Admin App home page. Every artifact the Kafka subscribe guide lists is
// generated, even with no broker. The AI also writes ad-libs.md: the judgment calls it made, for you to review
// (the closing message points you at it).
implement requirements samples/requirements/demo_eai/docs/requirements/demo_eai

// C1 - Admin App
// The build added tables (the daily totals, the messages, the requests); rebuild-from-database wrote them to
// admin-merge.yaml and left admin.yaml alone, since it may hold your edits. This project has none, so replace it.
update the Admin App to show the new tables: replace ui/admin/admin.yaml with admin-merge.yaml (keep a backup), show the message and request payloads as text areas, and drop the tab groups that link a table to its daily totals

// C2 - Seed order history
// The dashboard (requirement 6) needs history to show flow. The 30 days before today are seeded through the rules (a
// script run inside the app, not SQL), so every amount, total and balance is derived and the credit limit checked. The
// shape is chosen to show what an operator looks for: normal weekday / weekend volume, one bad-data day (messages arrive,
// most rejected), and the flow stopping (no activity 3 and 2 days ago). Deterministic: a rebuild draws the same picture.
seed order history for the dashboard: the 30 days before today, through the rules (not SQL), with weekday and weekend volumes (orders arriving as B2B requests and as Kafka messages), one day with mostly rejected messages, and no activity 3 and 2 days ago

// D - Verify Kafka
// With a broker running: enables live Kafka, resets the topics first (messages left by earlier runs would otherwise be
// replayed as junk orders), sends the sample message through the debug endpoint, and confirms a processed blob and a
// new order. With no broker it verifies the simulated path and says so. "(all topics)" is the default; name one to narrow it.
verify message subscriptions (all topics)

// E - Logic Diagrams
// One SVG per use case, shown under its requirement in the report. Skipped with a one-line note if graphviz is missing;
// nothing is installed for you (optional install: brew install graphviz).
create logic diagram for each requirement (skip if graphviz is not available)

// F - Create Tests
// Behave scenarios written from the rules. "Default names" means one Feature per requirement, named exactly as its
// Feature: line in requirements.md, which is how the report ties tests to requirements. Kafka scenarios run live when a
// broker answers, else simulated; the report says which.
create tests from rules, using default names

// G - Run Tests
// Starts the server if needed, runs the suite, reports pass and fail, and stops the server it started.
run the tests

// H - Clean up
// The tests left messages on the topics. Empty them, so a restart of this demo starts from a clean queue.
empty the Kafka topics, so a server restart does not read the test messages again (skip if no broker is running)

// I - Traceability Report
// Requirements traced to rules, tests and the engine's own log of what ran. The closing message is printed last, on
// purpose (mid-run text is easy to lose): what to review (the rules, ad-libs.md) and where the report is.
run the requirements traceability report
When the report is done, print this verbatim: "Next: scan these two files: logic/logic_discovery/check_credit.py (the rules) and docs/requirements/demo_eai/ad-libs.md (the judgment calls the AI made). Then open the report: docs/requirements/Requirements Traceability Report.md (all three paths are in the project; in VS Code: open the file, then Cmd/Ctrl+Shift+V for the rendered preview)."
