Skip to content

feat: add Soroban-specific AI prompt actions#82

Merged
Atharv777 merged 4 commits intokentuckyfriedcode:mainfrom
woydarko:feat/soroban-prompt-actions
Apr 20, 2026
Merged

feat: add Soroban-specific AI prompt actions#82
Atharv777 merged 4 commits intokentuckyfriedcode:mainfrom
woydarko:feat/soroban-prompt-actions

Conversation

@woydarko
Copy link
Copy Markdown
Contributor

Summary

Closes #54

Adds 4 prebuilt Soroban-specific AI prompt templates that produce focused, domain-specific results — far better than generic AI prompts for Stellar/Soroban development.

What was added

server/utils/soroban_prompts.py (new)

4 prompt templates with carefully engineered system prompts:

ID Name Category Requires Code
generate_contract Generate Contract generation No
explain_contract Explain Contract education Yes
generate_tests Generate Tests testing Yes
security_review Security Review security Yes

Each prompt is purpose-built for Soroban:

  • generate_contract — produces complete src/lib.rs with #[contract], #[contractimpl], typed DataKey, require_auth(), and #[cfg(test)]
  • explain_contract — covers purpose, storage, functions, auth, events, limitations
  • generate_tests — uses testutils::Address, mock_all_auths(), happy + failure paths
  • security_review — 10-point checklist with severity ratings (Critical/High/Medium/Low)

Functions: list_prompt_templates(), get_prompt_template(id), build_soroban_prompt(id, description, context_code)

server/routes/soroban_prompt_routes.py (new)

4 endpoints under /api/prompts/soroban/:

GET /api/prompts/soroban — list all templates with metadata

GET /api/prompts/soroban/<id> — get single template; 404 returns available list

POST /api/prompts/soroban/build — builds full prompt text without AI call (for frontend preview)

POST /api/prompts/soroban/execute — builds prompt + calls Gemini, persists result to chat history via add_chat_message, validates session ownership

server/start.py

Registered soroban_prompts_bp blueprint

server/tests/test_soroban_prompts.py (new)

33 tests covering all components

Results

Tests: 142 passed, 0 failed (33 new + all existing)

Closes kentuckyfriedcode#48

## What was added

### server/utils/contract_templates.py (new)
Template registry and generator with 4 starter templates:
- hello_world: minimal greeting contract (beginner)
- token: fungible token with initialize/transfer/balance (intermediate)
- nft: non-fungible token with mint/transfer/owner_of/token_uri (intermediate)
- governance: DAO proposal + voting with quorum threshold (advanced)

Functions: list_templates(), get_template(id), generate_template(id, path, name)
Each template generates: Cargo.toml, src/lib.rs, README.md

### server/routes/template_routes.py (new)
Three endpoints registered under /api/templates/:

GET /api/templates
- Lists all 4 templates with id, name, description, difficulty, tags

GET /api/templates/<template_id>
- Returns metadata for one template, 404 with available list if not found

POST /api/templates/generate
- Validates session ownership and resolves instance_dir
- Validates project_name with regex (alphanumeric, hyphens, underscores)
- Blocks path traversal
- Generates template files into session workspace
- Returns files_created list and project_path

### server/start.py
Registered templates_bp blueprint

### server/tests/test_contract_templates.py (new)
28 tests covering all components:
- list_templates: count, required fields, expected IDs
- get_template: valid/invalid IDs, all templates retrievable
- generate_template: all 4 templates, Cargo.toml content, src/lib.rs has soroban_sdk,
  README mentions template name, raises for unknown template, raises if path exists,
  files_created list correct
- GET /api/templates: 200, returns 4, required fields
- GET /api/templates/<id>: 200 valid, 404 unknown, available list on 404
- POST /api/templates/generate: missing fields, session not found,
  path traversal blocked, invalid project_name, unknown template 404,
  successful generation with files on disk

## Results
Tests: 88 passed, 0 failed (full suite)
Closes kentuckyfriedcode#54

## What was added

### server/utils/soroban_prompts.py (new)
4 prebuilt Soroban prompt templates:
- generate_contract: generate complete contract from description
- explain_contract: explain contract in plain language
- generate_tests: generate Rust test suite
- security_review: security audit with severity ratings

Functions: list_prompt_templates(), get_prompt_template(id),
build_soroban_prompt(id, description, context_code)

### server/routes/soroban_prompt_routes.py (new)
4 endpoints under /api/prompts/soroban/:

GET /api/prompts/soroban — list all templates
GET /api/prompts/soroban/<id> — get template metadata
POST /api/prompts/soroban/build — build prompt text only (no AI call)
POST /api/prompts/soroban/execute — build + execute via Gemini,
  persists to chat history, validates session ownership

### server/start.py
Registered soroban_prompts_bp blueprint

### server/tests/test_soroban_prompts.py (new)
33 tests covering all components

## Results
Tests: 142 passed, 0 failed (33 new + all existing)
@Atharv777 Atharv777 merged commit 40ddd63 into kentuckyfriedcode:main Apr 20, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AI] Add Soroban-specific prompt actions

2 participants