-
Notifications
You must be signed in to change notification settings - Fork 0
feat: community polish — examples, badges, discussions #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #!/bin/bash | ||
| # Batch code review: review multiple files | ||
| # Usage: ./batch-review.sh src/*.rs | ||
|
|
||
| TMPFILE=$(mktemp) | ||
| for file in "$@"; do | ||
| echo "Review $file for bugs, security issues, and improvements. Be specific about line numbers." >> "$TMPFILE" | ||
| done | ||
|
|
||
| magic-code --yes --json --batch "$TMPFILE" | ||
| rm "$TMPFILE" | ||
|
Comment on lines
+5
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Check if the file exists and examine its full contents
find . -name "batch-review.sh" -type fRepository: kienbui1995/mc-code Length of output: 89 🏁 Script executed: # If file exists, read its full contents
cat examples/batch-review.sh 2>/dev/null || echo "File not found"Repository: kienbui1995/mc-code Length of output: 371 🏁 Script executed: # Verify the script's current state matches the snippet
wc -l examples/batch-review.sh 2>/dev/null || echo "Cannot determine line count"Repository: kienbui1995/mc-code Length of output: 90 Harden temp-file lifecycle and empty-args behavior. The script creates a temp file without cleanup on failure or interruption, and silently accepts zero arguments, creating an empty batch file. Add an Suggested patch #!/bin/bash
# Batch code review: review multiple files
# Usage: ./batch-review.sh src/*.rs
+set -euo pipefail
+
+if [ "$#" -eq 0 ]; then
+ echo "Usage: ./batch-review.sh <files...>" >&2
+ exit 2
+fi
TMPFILE=$(mktemp)
+trap 'rm -f "$TMPFILE"' EXIT
for file in "$@"; do
- echo "Review $file for bugs, security issues, and improvements. Be specific about line numbers." >> "$TMPFILE"
+ printf 'Review %s for bugs, security issues, and improvements. Be specific about line numbers.\n' "$file" >> "$TMPFILE"
done
magic-code --yes --json --batch "$TMPFILE"
-rm "$TMPFILE"🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,22 @@ | ||||||
| #!/bin/bash | ||||||
| # CI/CD: Auto-fix failing tests with magic-code | ||||||
| # Usage: ./ci-fix.sh | ||||||
| set -e | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||||||
|
|
||||||
| echo "Running tests..." | ||||||
| if cargo test --workspace 2>&1 | tail -5 | grep -q "FAILED"; then | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Restricting the failure check to the last 5 lines of output using
Suggested change
|
||||||
| echo "Tests failed. Asking magic-code to fix..." | ||||||
| magic-code --yes --json \ | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In an automated CI/CD context, the
Suggested change
|
||||||
| "The tests are failing. Read the test output, find the bug, and fix it. Run tests again to verify." \ | ||||||
| -o fix-result.json | ||||||
|
Comment on lines
+9
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify `--json` return path occurs before `-o` output write handling.
rg -n -C4 'if json_output|if let Some\(path\) = output_path|return Ok\(\);' mc/crates/mc-cli/src/main.rsRepository: kienbui1995/mc-code Length of output: 726
The function returns at line 1722 after printing JSON output, before reaching the 🤖 Prompt for AI Agents |
||||||
|
|
||||||
| if [ $? -eq 0 ]; then | ||||||
| echo "Fix applied. Re-running tests..." | ||||||
| cargo test --workspace | ||||||
| else | ||||||
| echo "magic-code could not fix the issue." | ||||||
| exit 1 | ||||||
| fi | ||||||
|
Comment on lines
+7
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cat -n examples/ci-fix.shRepository: kienbui1995/mc-code Length of output: 842 Failure detection via pipeline loses cargo test exit code; The pipeline on line 7 loses the Suggested patch echo "Running tests..."
-if cargo test --workspace 2>&1 | tail -5 | grep -q "FAILED"; then
+TEST_LOG=$(mktemp)
+trap 'rm -f "$TEST_LOG"' EXIT
+
+if ! cargo test --workspace >"$TEST_LOG" 2>&1; then
echo "Tests failed. Asking magic-code to fix..."
- magic-code --yes --json \
- "The tests are failing. Read the test output, find the bug, and fix it. Run tests again to verify." \
- -o fix-result.json
-
- if [ $? -eq 0 ]; then
+ if magic-code --yes --json \
+ "The tests are failing. Use this test output to find and fix the bug:
+$(tail -n 200 "$TEST_LOG")
+Run tests again to verify." \
+ -o fix-result.json; then
echo "Fix applied. Re-running tests..."
cargo test --workspace
else
echo "magic-code could not fix the issue."
exit 1
fi
else
echo "All tests pass."
fi🧰 Tools🪛 Shellcheck (0.11.0)[style] 13-13: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?. (SC2181) 🤖 Prompt for AI Agents |
||||||
| else | ||||||
| echo "All tests pass." | ||||||
| fi | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Self-hosted config: Qwen 3.5 via LiteLLM (zero cost) | ||
| # Copy to .magic-code/config.toml | ||
|
|
||
| [default] | ||
| model = "qwen3.5-9b" | ||
| provider = "litellm" | ||
| base_url = "http://localhost:4000" | ||
| max_tokens = 4096 | ||
| notifications = false | ||
|
Comment on lines
+4
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🤖 Prompt for AI Agents |
||
|
|
||
| # Memory | ||
| [memory] | ||
| max_facts = 100 | ||
|
|
||
| # Managed agents (disabled for small models) | ||
| [managed_agents] | ||
| enabled = false | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!/bin/bash | ||
| # Record a demo with: asciinema rec demo.cast | ||
| # Convert to GIF with: agg demo.cast demo.gif | ||
| # Or use: svg-term --in demo.cast --out demo.svg | ||
|
|
||
| echo "=== magic-code demo ===" | ||
| echo "" | ||
| echo "# 1. Quick fix" | ||
| echo '$ magic-code "fix the typo in src/main.rs"' | ||
| echo "" | ||
| sleep 1 | ||
|
|
||
| echo "# 2. Self-hosted (zero cost)" | ||
| echo '$ magic-code --provider ollama --model qwen3.5:9b "add error handling"' | ||
| echo "" | ||
| sleep 1 | ||
|
|
||
| echo "# 3. CI/CD integration" | ||
| echo '$ magic-code --yes --json "fix failing tests" -o result.json' | ||
| echo "" | ||
| sleep 1 | ||
|
|
||
| echo "# 4. Batch processing" | ||
| echo '$ magic-code --yes --batch tasks.txt' | ||
| echo "" | ||
| sleep 1 | ||
|
|
||
| echo "# 5. NDJSON streaming" | ||
| echo '$ magic-code --ndjson "explain auth.rs" | jq .type' | ||
| echo "" | ||
|
|
||
| echo "=== Install ===" | ||
| echo "curl -fsSL https://raw.githubusercontent.com/kienbui1995/mc-code/main/install.sh | sh" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #!/bin/bash | ||
| # NDJSON streaming: pipe magic-code events to a web app | ||
| # Usage: ./stream-to-webapp.sh "your prompt" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| magic-code --yes --ndjson "$1" | while IFS= read -r line; do | ||
|
Comment on lines
+3
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, check if examples/stream-events.sh exists and read its content
cat -n examples/stream-events.shRepository: kienbui1995/mc-code Length of output: 676 🏁 Script executed: # Check if stream-to-webapp.sh exists
fd -a "stream-to-webapp" examples/Repository: kienbui1995/mc-code Length of output: 45 🏁 Script executed: # List all files in examples directory to understand the structure
ls -la examples/Repository: kienbui1995/mc-code Length of output: 430 Fix usage string and validate prompt input. The usage line references a non-existent script name Suggested patch #!/bin/bash
# NDJSON streaming: pipe magic-code events to a web app
-# Usage: ./stream-to-webapp.sh "your prompt"
+# Usage: ./stream-events.sh "your prompt"
+set -euo pipefail
+
+if [ "$#" -lt 1 ]; then
+ echo 'Usage: ./stream-events.sh "your prompt"' >&2
+ exit 2
+fi
magic-code --yes --ndjson "$1" | while IFS= read -r line; do🤖 Prompt for AI Agents |
||
| type=$(echo "$line" | jq -r '.type // empty' 2>/dev/null) | ||
| case "$type" in | ||
| text) | ||
| echo "$line" | jq -r '.content' ;; | ||
| tool_call) | ||
| echo "[TOOL] $(echo "$line" | jq -r '.name')" ;; | ||
| tool_output) | ||
| echo "[OUTPUT] $(echo "$line" | jq -r '.content' | head -5)" ;; | ||
| esac | ||
| done | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The temporary file created with
mktempis not cleaned up if the script is interrupted (e.g., via Ctrl+C) or fails before reaching the explicitrmcommand. It is safer to use atrapto ensure the file is removed upon exit.