microralph 0.7.2

A tiny CLI for creating and executing PRDs with coding agents
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
# microralph — cargo-make configuration
# Reference: https://github.com/twitchax/kord/blob/main/Makefile.toml

# =============================================================================
# Tool Installation
# =============================================================================

[tasks.install-cargo-binstall]
# In CI, this is installed by the cargo-bins/cargo-binstall@main action.
# Locally, users should install manually: https://github.com/cargo-bins/cargo-binstall
script = "echo 'Checking cargo-binstall availability...'"

[tasks.install-nextest]
dependencies = ["install-cargo-binstall"]
command = "cargo"
args = ["binstall", "cargo-nextest", "--no-confirm"]

[tasks.install-llvm-cov]
dependencies = ["install-cargo-binstall"]
command = "cargo"
args = ["binstall", "cargo-llvm-cov", "--no-confirm"]

[tasks.install-cargo-release]
dependencies = ["install-cargo-binstall"]
command = "cargo"
args = ["binstall", "cargo-release", "--no-confirm"]

[tasks.install-git-cliff]
dependencies = ["install-cargo-binstall"]
command = "cargo"
args = ["binstall", "git-cliff", "--no-confirm"]

[tasks.install-wkg]
dependencies = ["install-cargo-binstall"]
command = "cargo"
args = ["binstall", "wkg", "--no-confirm"]

[tasks.tools]
dependencies = ["install-nextest", "install-llvm-cov"]

# =============================================================================
# Formatting
# =============================================================================

[tasks.fmt]
cwd = "."
workspace = false
command = "cargo"
args = ["fmt"]

[tasks.fmt-check]
cwd = "."
workspace = false
command = "cargo"
args = ["fmt", "--check"]

# =============================================================================
# Linting
# =============================================================================

[tasks.clippy]
cwd = "."
workspace = false
command = "cargo"
args = ["clippy", "--all-targets", "--all-features", "--", "-D", "warnings"]

# =============================================================================
# Build
# =============================================================================

[tasks.build]
cwd = "."
workspace = false
command = "cargo"
args = ["build"]

[tasks.build-release]
cwd = "."
workspace = false
command = "cargo"
args = ["build", "--release"]

# =============================================================================
# Testing
# =============================================================================

[tasks.test]
cwd = "."
workspace = false
dependencies = ["install-nextest"]
command = "cargo"
args = ["nextest", "run"]

[tasks.test-cargo]
# Fallback for environments without nextest.
cwd = "."
workspace = false
command = "cargo"
args = ["test"]

# =============================================================================
# UAT (User Acceptance Tests)
# =============================================================================

[tasks.uat]
# The one true gate for this repo.
# Usage: cargo make uat [filter]
# Examples:
#   cargo make uat              - Run full CI pipeline
#   cargo make uat prd_new      - Run CI then tests matching "prd_new"
workspace = false
script_runner = "@shell"
script = '''
cargo make ci
if [ -n "${1:-}" ]; then
    cargo nextest run "$1"
fi
'''

# =============================================================================
# microralph Integration Tests
# =============================================================================

[tasks.mr-test]
# Integration tests for MR itself (stub for now).
cwd = "."
workspace = false
dependencies = ["test"]

[tasks.mr-uat]
# MR end-to-end acceptance tests (stub for now).
cwd = "."
workspace = false
dependencies = ["test"]

# =============================================================================
# Constitution UATs (PRD-0012)
# =============================================================================

[tasks.constitution_bootstrap]
# UAT-001: Bootstrap creates initial constitution file
workspace = false
dependencies = ["install-nextest"]
command = "cargo"
args = ["nextest", "run", "test_bootstrap_creates_constitution"]

[tasks.constitution_template]
# UAT-002: Constitution contains numbered example rules
workspace = false
dependencies = ["install-nextest"]
command = "cargo"
args = ["nextest", "run", "test_constitution_template_content"]

[tasks.constitution_prd_new]
# UAT-003: prd new reads and respects constitution
workspace = false
dependencies = ["install-nextest"]
command = "cargo"
args = ["nextest", "run", "test_constitution_prd_new"]

[tasks.constitution_prd_finalize]
# UAT-004: prd finalize reads and respects constitution
workspace = false
dependencies = ["install-nextest"]
command = "cargo"
args = ["nextest", "run", "test_constitution_prd_finalize"]

[tasks.constitution_edit]
# UAT-005: constitution edit command updates via LLM
workspace = false
dependencies = ["install-nextest"]
command = "cargo"
args = ["nextest", "run", "test_constitution_edit"]

[tasks.constitution_violation_logging]
# UAT-006: Runner logs violations in PRD history
workspace = false
dependencies = ["install-nextest"]
command = "cargo"
args = ["nextest", "run", "test_constitution_violation_logging"]

# =============================================================================
# CI Pipeline
# =============================================================================

[tasks.ci]
# The full CI pipeline: fmt, clippy, test.
workspace = false
dependencies = ["fmt-check", "clippy", "test"]

[tasks.check-all]
workspace = false
dependencies = ["fmt", "test"]

# =============================================================================
# Code Coverage
# =============================================================================

[tasks.codecov]
cwd = "."
workspace = false
clear = true
dependencies = ["tools"]
command = "cargo"
args = ["llvm-cov", "nextest", "--lcov", "--output-path", "coverage.lcov"]

[tasks.codecov-html]
cwd = "."
workspace = false
clear = true
dependencies = ["tools"]
command = "cargo"
args = ["llvm-cov", "nextest", "--html"]

# =============================================================================
# Platform Builds (for CI artifact generation)
# =============================================================================

[tasks.build-linux]
cwd = "."
workspace = false
command = "cargo"
args = ["build", "--target", "x86_64-unknown-linux-gnu", "--release"]

[tasks.build-windows]
cwd = "."
workspace = false
command = "cargo"
args = ["build", "--target", "x86_64-pc-windows-gnu", "--release"]

[tasks.build-macos]
cwd = "."
workspace = false
command = "cargo"
args = ["build", "--target", "aarch64-apple-darwin", "--release"]

[tasks.build-wasm]
cwd = "."
workspace = false
command = "cargo"
args = ["build", "--target", "wasm32-wasip2", "--release"]

[tasks.build-oci]
# Alias for build-wasm (OCI publishing uses the same WASM binary)
cwd = "."
workspace = false
dependencies = ["build-wasm"]

[tasks.publish-oci]
# Publish WASM binary to GitHub Container Registry
# Prerequisites:
#   - Install wkg: cargo binstall wkg
#   - Authenticate: docker login ghcr.io -u USERNAME
#   - Build: cargo make build-oci
dependencies = ["build-oci", "install-wkg"]
cwd = "."
workspace = false
command = "wkg"
args = [
    "oci",
    "push",
    "ghcr.io/twitchax/microralph:latest",
    "--file",
    "target/wasm32-wasip2/release/mr.wasm",
]

# =============================================================================
# Publishing
# =============================================================================

[tasks.release-bump]
cwd = "."
workspace = false
dependencies = ["install-cargo-release"]
command = "cargo"
args = ["release", "--workspace", "--no-publish", "--execute"]

[tasks.release-builds]
cwd = "."
workspace = false
run_task = { name = [
    "changelog",
    "build-linux",
    "build-macos",
    "build-windows",
    "build-wasm",
], fork = false }

[tasks.release]
# Fully automated release: CI → changelog → bump → commit → push → wait for artifacts
cwd = "."
workspace = false
dependencies = ["ci", "changelog", "install-cargo-release"]
script_runner = "@shell"
script = '''#!/bin/bash
set -e

echo ""
echo "🚀 Starting automated release pipeline..."
echo ""

# Step 1: Version bump (cargo-release determines version from commits)
echo "📦 Step 1/5: Bumping version..."
cargo release --workspace --no-publish --execute

# Step 2: Extract new version from Cargo.toml
VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "   → New version: v$VERSION"

# Step 3: Commit changes
echo ""
echo "📝 Step 2/5: Committing changes..."
git add .
git commit -m "chore: release v$VERSION" || echo "   → No changes to commit (already committed by cargo-release)"

# Step 4: Push to trigger CI
echo ""
echo "🚀 Step 3/5: Pushing to remote..."
git push
git push --tags

# Step 5: Wait for CI and download artifacts
echo ""
echo "⏳ Step 4/5: Waiting for CI workflow to complete..."
echo "   This may take a few minutes..."

# Get the latest workflow run ID for the build workflow
sleep 5  # Give GitHub a moment to register the push
RUN_ID=""
for i in {1..60}; do
    RUN_ID=$(gh run list --branch main --workflow build.yml --limit 1 --json databaseId,status --jq '.[0] | select(.status != "completed") | .databaseId' 2>/dev/null || echo "")
    if [ -n "$RUN_ID" ]; then
        break
    fi
    sleep 2
done

if [ -z "$RUN_ID" ]; then
    # Try to get the most recent completed run
    RUN_ID=$(gh run list --branch main --workflow build.yml --limit 1 --json databaseId --jq '.[0].databaseId')
fi

if [ -n "$RUN_ID" ]; then
    echo "   → Workflow run ID: $RUN_ID"
    gh run watch "$RUN_ID" --exit-status || {
        echo "❌ CI failed! Check the workflow at:"
        echo "   https://github.com/twitchax/microralph/actions/runs/$RUN_ID"
        exit 1
    }
    
    echo ""
    echo "📥 Step 5/5: Downloading artifacts..."
    rm -rf target/release-artifacts
    gh run download "$RUN_ID" --dir target/release-artifacts
    echo "   → Artifacts downloaded to target/release-artifacts/"
else
    echo "⚠️  Could not find workflow run. Download artifacts manually with:"
    echo "   gh run list --branch main --workflow build.yml --limit 1 --json databaseId --jq '.[0].databaseId' | xargs -I {} gh run download {} --dir target/release-artifacts"
fi

echo ""
echo "✅ Release pipeline complete!"
echo ""
echo "Next steps:"
echo "  1. Publish: cargo make publish-all v$VERSION"
'''

[tasks.publish-all]
cwd = "."
workspace = false
script_runner = "@shell"
script = '''#!/bin/bash
set -e

TAG=${1:-}
if [ -z "$TAG" ]; then
    echo "❌ Error: Version tag required"
    echo "Usage: cargo make publish-all <tag>"
    echo "Example: cargo make publish-all v0.1.0"
    exit 1
fi
shift  # Remove TAG from args, remaining args passed to github-release

echo "🚀 Starting full release pipeline for $TAG..."
echo ""

# Step 1: Publish to crates.io
echo "📦 Step 1/2: Publishing to crates.io..."
cargo make publish-crates

# Step 2: Create GitHub release with artifacts
echo ""
echo "📦 Step 2/2: Creating GitHub release..."
cargo make github-release "$TAG" "$@"

echo ""
echo "✅ Full release pipeline complete!"
echo "   Published to crates.io: https://crates.io/crates/microralph"
echo "   GitHub release: https://github.com/twitchax/microralph/releases/tag/$TAG"
'''

[tasks.changelog]
cwd = "."
workspace = false
dependencies = ["install-git-cliff"]
command = "git-cliff"
args = ["--output", "CHANGELOG.md"]

[tasks.publish-crates]
cwd = "."
workspace = false
dependencies = ["ci"]
script_runner = "@shell"
script = '''
echo "Running pre-publish checks..."
cargo package --no-verify --list

echo ""
echo "Publishing microralph to crates.io..."
cargo publish --no-verify ${@}

if [ "${1:-}" != "--dry-run" ]; then
    echo ""
    echo "✅ Published successfully!"
fi
'''

[tasks.github-release]
cwd = "."
workspace = false
script_runner = "@shell"
script = '''#!/bin/bash
set -e

TAG=${1:-}
if [ -z "$TAG" ]; then
    echo "❌ Error: Version tag required"
    echo "Usage: cargo make github-release <tag> [--draft]"
    echo "Example: cargo make github-release v0.1.0"
    exit 1
fi

echo "📦 Creating GitHub release for $TAG..."

# Prepare release notes
TEMP_DIR=$(mktemp -d)
trap "rm -rf $TEMP_DIR" EXIT
NOTES_FILE="$TEMP_DIR/release_notes.md"

if [ -f "CHANGELOG.md" ]; then
    echo "Using changelog for release notes..."
    cp CHANGELOG.md "$NOTES_FILE"
else
    echo "## Release $TAG" > "$NOTES_FILE"
    echo "" >> "$NOTES_FILE"
    echo "See the full changelog at https://github.com/twitchax/microralph/blob/main/CHANGELOG.md" >> "$NOTES_FILE"
fi

# Check for artifacts directory and rename files for unique asset names
ARTIFACTS=""
STAGING_DIR=$(mktemp -d)
if [ -d "target/release-artifacts" ]; then
    echo "📎 Found target/release-artifacts directory"
    # Find all files recursively and rename using parent dir name
    for file in $(find target/release-artifacts -type f); do
        # Extract parent dir name (e.g., mr_x86_64-unknown-linux-gnu)
        parent_dir=$(basename "$(dirname "$file")")
        filename=$(basename "$file")
        # Get extension if any
        if [[ "$filename" == *.* ]]; then
            ext=".${filename##*.}"
            base="${filename%.*}"
        else
            ext=""
            base="$filename"
        fi
        # Create unique name: mr-x86_64-unknown-linux-gnu or mr-x86_64-pc-windows-gnu.exe
        new_name="${parent_dir}${ext}"
        staged_file="$STAGING_DIR/$new_name"
        cp "$file" "$staged_file"
        echo "  → $new_name"
        ARTIFACTS="$ARTIFACTS \"$staged_file\""
    done
fi

# Build gh release create command
GH_CMD="gh release create \"$TAG\" --title \"$TAG\" --notes-file \"$NOTES_FILE\""

# Add draft flag if requested
shift
if echo "$@" | grep -q "\-\-draft"; then
    GH_CMD="$GH_CMD --draft"
    echo "📝 Creating as draft release"
fi

# Add artifacts
if [ -n "$ARTIFACTS" ]; then
    GH_CMD="$GH_CMD $ARTIFACTS"
fi

# Execute the release creation
echo ""
echo "🚀 Creating GitHub release..."
eval $GH_CMD

echo ""
echo "✅ GitHub release created successfully!"
echo "   View at: https://github.com/twitchax/microralph/releases/tag/$TAG"
echo ""
echo "💡 To download artifacts from CI, run:"
echo "   gh run list --branch main --workflow build.yml --limit 1 --json databaseId --jq '.[0].databaseId' | xargs -I {} gh run download {} --dir target/release-artifacts"
'''

# =============================================================================
# Development Helpers
# =============================================================================

[tasks.run]
cwd = "."
workspace = false
command = "cargo"
args = ["run", "--", "${@}"]

[tasks.watch]
cwd = "."
workspace = false
script = '''
cargo watch -x "run -- status"
'''

[tasks.devcontainer]
# Start and exec into the dev container (cross-platform via duckscript)
cwd = "."
workspace = false
script_runner = "@duckscript"
script = '''
# Ensure @devcontainers/cli is installed
path = which devcontainer
if is_empty ${path}
    echo "📦 Installing @devcontainers/cli..."
    exec npm install -g @devcontainers/cli
end

# Generate config if it doesn't exist
config_exists = is_path_exists .devcontainer/devcontainer.json
if not ${config_exists}
    echo "⚠️  No devcontainer config found. Run 'cargo run -- devcontainer generate' first."
    exit 1
end

echo "🚀 Starting dev container..."
exec devcontainer up --workspace-folder . --remove-existing-container

echo "🔗 Connecting to dev container..."
exec devcontainer exec --workspace-folder . bash
'''

# =============================================================================
# Clean
# =============================================================================

[tasks.clean]
cwd = "."
workspace = false
command = "cargo"
args = ["clean"]