-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJustfile
More file actions
635 lines (503 loc) · 16.9 KB
/
Copy pathJustfile
File metadata and controls
635 lines (503 loc) · 16.9 KB
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
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
# Trigger - Justfile with comprehensive recipes
#
# Author: hyperpolymath
#
# Just is a modern make alternative: https://github.com/casey/just
#
# Usage:
# just # Show available recipes
# just build # Build the project
# just run # Run the application (TUI mode)
# just test # Run tests
# just clean # Clean build artifacts
# just diagnose # Run self-diagnostics
# just self-heal # Attempt self-healing
# just install # Install the application
# just uninstall # Uninstall the application
# Project metadata
PROJECT_NAME := "trigger"
PROJECT_VERSION := "1.0.0"
BINARY_NAME := "trigger"
INSTALL_PREFIX := if os() == "windows" { "C:\\Program Files\\" + PROJECT_NAME } else { "/usr/local" }
INSTALL_BIN := INSTALL_PREFIX + "/bin"
INSTALL_MAN := INSTALL_PREFIX + "/share/man/man1"
# Ada/SPARK settings
ADA_COMPILER := "gprbuild"
ADA_PROJECT := "trigger.gpr"
ADA_FLAGS := ""
# Zig settings
ZIG_COMPILER := "zig"
ZIG_BUILD := "build.zig"
# Idris2 settings
IDRIS2_COMPILER := "idris2"
# Source directories
SRC_DIR := "src"
FFI_DIR := "ffi"
TESTS_DIR := "tests"
BUILD_DIR := "obj"
BIN_DIR := "bin"
# =============================================================================
# Default Recipe: Show help
# =============================================================================
default:
@just --list
# =============================================================================
# Build Recipes
# =============================================================================
# Build the project
build:
#!/usr/bin/env bash
set -euo pipefail
echo "[BUILD] Building Trigger..."
# Create build directory
mkdir -p {{BUILD_DIR}}
mkdir -p {{BIN_DIR}}
# Build with GNAT
if command -v {{ADA_COMPILER}} >/dev/null 2>&1; then
echo "[BUILD] Compiling with GNAT..."
{{ADA_COMPILER}} -P {{ADA_PROJECT}} -XLIBRARY_TYPE=static {{ADA_FLAGS}}
echo "[BUILD] GNAT compilation complete"
else
echo "[ERROR] GNAT compiler not found"
exit 1
fi
# Build Zig FFI
if command -v {{ZIG_COMPILER}} >/dev/null 2>&1; then
echo "[BUILD] Compiling Zig FFI..."
cd {{FFI_DIR}}/zig && {{ZIG_COMPILER}} build-lib -dynamic telegram.zig
cd ../../
echo "[BUILD] Zig compilation complete"
else
echo "[WARNING] Zig compiler not found, FFI will be limited"
fi
# Build Idris2 API (optional)
if command -v {{IDRIS2_COMPILER}} >/dev/null 2>&1; then
echo "[BUILD] Compiling Idris2 API..."
cd {{FFI_DIR}}/idris2 && {{IDRIS2_COMPILER}} --build TelegramAPI.ipkg
cd ../../
echo "[BUILD] Idris2 compilation complete"
else
echo "[WARNING] Idris2 compiler not found, API layer will be limited"
fi
echo "[BUILD] Build complete!"
echo "[BUILD] Binary: {{BIN_DIR}}/{{BINARY_NAME}}"
# Rebuild the project
rebuild: clean build
# Build in debug mode
debug:
#!/usr/bin/env bash
set -euo pipefail
ADA_FLAGS="-g -O0" just build
# Build in release mode
release:
#!/usr/bin/env bash
set -euo pipefail
ADA_FLAGS="-O3 -gnatn" just build
# =============================================================================
# Run Recipes
# =============================================================================
# Run the application (TUI mode)
run:
#!/usr/bin/env bash
set -euo pipefail
# Check if built
if [ -f "{{BIN_DIR}}/{{BINARY_NAME}}" ]; then
{{BIN_DIR}}/{{BINARY_NAME}}
elif [ -f "{{BINARY_NAME}}" ]; then
./{{BINARY_NAME}}
else
echo "[ERROR] Binary not found. Run 'just build' first."
exit 1
fi
# Run with specific arguments
run-cli *args:
#!/usr/bin/env bash
set -euo pipefail
if [ -f "{{BIN_DIR}}/{{BINARY_NAME}}" ]; then
{{BIN_DIR}}/{{BINARY_NAME}} "{{args}}"
elif [ -f "{{BINARY_NAME}}" ]; then
./{{BINARY_NAME}} "{{args}}"
else
echo "[ERROR] Binary not found. Run 'just build' first."
exit 1
fi
# Run with help
help:
just run-cli --help
# Run with man page
man:
just run-cli --man
# Run with version
version:
just run-cli --version
# Run diagnostics
diagnose:
just run-cli --diagnose
# Run self-healing
self-heal:
just run-cli --self-heal
# =============================================================================
# Test Recipes
# =============================================================================
test:
#!/usr/bin/env bash
set -euo pipefail
echo "[TEST] Running tests..."
# Ensure built
if [ ! -f "{{BIN_DIR}}/{{BINARY_NAME}}" ]; then
just build
fi
# Run test binary if it exists
if [ -f "{{BIN_DIR}}/test_trigger" ]; then
{{BIN_DIR}}/test_trigger
elif [ -f "tests/test_trigger.adb" ]; then
echo "[TEST] Compiling tests..."
gprbuild -P trigger.gpr tests/test_trigger.adb
echo "[TEST] Running tests..."
{{BIN_DIR}}/test_trigger
else
echo "[WARNING] No tests found"
fi
echo "[TEST] Tests complete"
# Run tests with coverage
test-coverage:
#!/usr/bin/env bash
set -euo pipefail
echo "[TEST] Running tests with coverage..."
# Requires gnatcov
if ! command -v gnatcov >/dev/null 2>&1; then
echo "[ERROR] gnatcov not found"
exit 1
fi
# Build with coverage instrumentation
gprbuild -P trigger.gpr -f -gnatg
# Run tests
if [ -f "{{BIN_DIR}}/test_trigger" ]; then
{{BIN_DIR}}/test_trigger
fi
# Generate coverage report
gnatcov *.ali
echo "[TEST] Coverage report generated"
# Run tests using the comprehensive test harness
test-harness:
#!/usr/bin/env bash
set -euo pipefail
echo "[TEST] Running comprehensive test harness..."
# Build the test runner
echo "[TEST] Compiling test runner..."
gprbuild -P trigger.gpr tests/test_runner.adb -o {{BIN_DIR}}/test_runner
# Run the test runner
echo "[TEST] Running test runner..."
{{BIN_DIR}}/test_runner
echo "[TEST] Test harness complete"
# Build all test files
build-tests:
#!/usr/bin/env bash
set -euo pipefail
echo "[BUILD] Building all test files..."
# Build test harness
gprbuild -P trigger.gpr tests/test_harness-body.adb
# Build all test suites
gprbuild -P trigger.gpr tests/unit/test_cryptography-body.adb
gprbuild -P trigger.gpr tests/unit/test_cli-body.adb
gprbuild -P trigger.gpr tests/unit/test_diagnostics-body.adb
gprbuild -P trigger.gpr tests/unit/test_tui-body.adb
gprbuild -P trigger.gpr tests/integration/test_cli_crypto_integration-body.adb
gprbuild -P trigger.gpr tests/system/test_system-body.adb
gprbuild -P trigger.gpr tests/security/test_security-body.adb
gprbuild -P trigger.gpr tests/benchmark/test_benchmark-body.adb
gprbuild -P trigger.gpr tests/test_runner.adb
echo "[BUILD] All test files built"
# Run specific test suites
test-unit:
#!/usr/bin/env bash
set -euo pipefail
echo "[TEST] Running unit tests..."
gprbuild -P trigger.gpr tests/test_runner.adb -o {{BIN_DIR}}/test_runner 2>/dev/null || true
# Run just unit tests by filtering
echo "[TEST] Running unit test suites..."
# For now, compile and run each test suite individually
gprbuild -P trigger.gpr tests/unit/test_cryptography-body.adb -o {{BIN_DIR}}/test_crypto 2>/dev/null || true
echo "[TEST] Unit tests complete"
# =============================================================================
# Clean Recipes
# =============================================================================
# Clean build artifacts
clean:
#!/usr/bin/env bash
set -euo pipefail
echo "[CLEAN] Cleaning build artifacts..."
# Remove build directories
rm -rf {{BUILD_DIR}}
rm -rf {{BIN_DIR}}
# Remove object files
find . -name "*.o" -delete
find . -name "*.ali" -delete
find . -name "*.a" -delete
# Remove test files
rm -f test_*.adb test_*.ads
# Remove temporary files
rm -f *.tmp *.swp *~ .TMP
# Remove session files (with confirmation if interactive)
if [ -t 1 ]; then
read -p "[CLEAN] Remove session directory? (y/N): " ans
if [ "$ans" = "y" ] || [ "$ans" = "Y" ]; then
rm -rf sessions/
fi
fi
echo "[CLEAN] Clean complete"
# Deep clean (removes everything including config)
deep-clean: clean
#!/usr/bin/env bash
set -euo pipefail
echo "[CLEAN] Deep cleaning..."
# Remove config files
rm -f config.json *.log
# Remove .alire and .alr if they exist
rm -rf .alire .alr
echo "[CLEAN] Deep clean complete"
# =============================================================================
# Install/Uninstall Recipes
# =============================================================================
# Install the application
install:
#!/usr/bin/env bash
set -euo pipefail
echo "[INSTALL] Installing Trigger..."
# Build first
just build
# Create install directories
echo "[INSTALL] Creating directories..."
mkdir -p "{{INSTALL_BIN}}"
mkdir -p "{{INSTALL_MAN}}"
# Install binary
echo "[INSTALL] Installing binary..."
if [ -f "{{BIN_DIR}}/{{BINARY_NAME}}" ]; then
cp "{{BIN_DIR}}/{{BINARY_NAME}}" "{{INSTALL_BIN}}/{{BINARY_NAME}}"
elif [ -f "{{BINARY_NAME}}" ]; then
cp "{{BINARY_NAME}}" "{{INSTALL_BIN}}/{{BINARY_NAME}}"
else
echo "[ERROR] Binary not found"
exit 1
fi
# Install man page
if [ -f "docs/trigger.1" ]; then
echo "[INSTALL] Installing man page..."
cp "docs/trigger.1" "{{INSTALL_MAN}}/trigger.1"
gzip "{{INSTALL_MAN}}/trigger.1"
fi
# Set permissions
chmod +x "{{INSTALL_BIN}}/{{BINARY_NAME}}"
echo "[INSTALL] Installation complete!"
echo "[INSTALL] Trigger installed to: {{INSTALL_BIN}}/{{BINARY_NAME}}"
# Uninstall the application
uninstall:
#!/usr/bin/env bash
set -euo pipefail
echo "[UNINSTALL] Uninstalling Trigger..."
# Remove binary
if [ -f "{{INSTALL_BIN}}/{{BINARY_NAME}}" ]; then
rm "{{INSTALL_BIN}}/{{BINARY_NAME}}"
echo "[UNINSTALL] Removed binary"
else
echo "[WARNING] Binary not found at {{INSTALL_BIN}}/{{BINARY_NAME}}"
fi
# Remove man page
if [ -f "{{INSTALL_MAN}}/trigger.1.gz" ]; then
rm "{{INSTALL_MAN}}/trigger.1.gz"
echo "[UNINSTALL] Removed man page"
else
echo "[WARNING] Man page not found"
fi
echo "[UNINSTALL] Uninstallation complete"
# =============================================================================
# Documentation Recipes
# =============================================================================
# Generate documentation
docs:
#!/usr/bin/env bash
set -euo pipefail
echo "[DOCS] Generating documentation..."
# Requires asciidoctor
if ! command -v asciidoctor >/dev/null 2>&1; then
echo "[ERROR] asciidoctor not found"
exit 1
fi
# Generate HTML
asciidoctor -D docs/html README.adoc
asciidoctor -D docs/html EXPLAINME.adoc
asciidoctor -D docs/html CONTRIBUTING.adoc
asciidoctor -D docs/html docs/ARCHITECTURE.adoc
# Generate man page
asciidoctor -b manpage -D docs trigger-man.adoc -o docs/trigger.1
echo "[DOCS] Documentation generated in docs/html/"
# Show README
readme:
@cat README.adoc
# Show EXPLAINME
explain:
@cat EXPLAINME.adoc
# =============================================================================
# Development Recipes
# =============================================================================
# Run all development checks
dev-check:
just lint
just format-check
just test
# Lint the code
lint:
#!/usr/bin/env bash
set -euo pipefail
echo "[LINT] Running linter..."
# Ada linting
if command -v gnatcheck >/dev/null 2>&1; then
echo "[LINT] Running gnatcheck..."
gnatcheck -P {{ADA_PROJECT}}
fi
# Zig linting
if command -v zig >/dev/null 2>&1; then
echo "[LINT] Running zig fmt check..."
cd {{FFI_DIR}}/zig
zig fmt --check *.zig
cd ../../
fi
echo "[LINT] Linting complete"
# Format the code
format:
#!/usr/bin/env bash
set -euo pipefail
echo "[FORMAT] Formatting code..."
# Zig formatting
if command -v zig >/dev/null 2>&1; then
echo "[FORMAT] Formatting Zig code..."
cd {{FFI_DIR}}/zig
zig fmt *.zig
cd ../../
fi
echo "[FORMAT] Formatting complete"
# Check formatting
format-check:
#!/usr/bin/env bash
set -euo pipefail
echo "[FORMAT] Checking code formatting..."
# Zig format check
if command -v zig >/dev/null 2>&1; then
echo "[FORMAT] Checking Zig formatting..."
cd {{FFI_DIR}}/zig
zig fmt --check *.zig
cd ../../
fi
echo "[FORMAT] Format check complete"
# =============================================================================
# Diagnostics Recipes
# =============================================================================
# Check dependencies
check-deps:
just run-cli --check-deps
# Check configuration
check-config:
just run-cli --check-config
# Check sessions
check-sessions:
just run-cli --check-sessions
# Health check
health:
just run-cli --health
# Full diagnostics
diagnostics: diagnose
# =============================================================================
# Session Management Recipes
# =============================================================================
# List all sessions
list-sessions:
just run-cli --list-sessions
# Clean invalid sessions
clean-sessions:
just run-cli --clean-sessions
# Encrypt all sessions
encrypt-sessions:
just run-cli --encrypt --all-accounts
# Decrypt all sessions
decrypt-sessions:
just run-cli --decrypt --all-accounts
# =============================================================================
# Reporting Recipes
# =============================================================================
# Report with dry run (preview)
report-dry *channel *count:
just run-cli --dry-run --channel {{channel}} --report-count {{count}}
# Report with specific account
report-account *account *channel:
just run-cli --account {{account}} --channel {{channel}}
# Report with all accounts
report-all *channel:
just run-cli --all-accounts --channel {{channel}}
# Report with custom settings
report *channel *count *delay *reason:
just run-cli --channel {{channel}} --report-count {{count}} --delay {{delay}} --reason {{reason}} --all-accounts
# =============================================================================
# Utility Recipes
# =============================================================================
# Show system information
sysinfo:
#!/usr/bin/env bash
echo "=== System Information ==="
echo "Date: $(date)"
echo "Host: $(hostname)"
echo "OS: $(uname -srm)"
echo ""
echo "=== Compiler Versions ==="
gnat --version 2>&1 | head -1 || echo "GNAT: not found"
zig version 2>&1 | head -1 || echo "Zig: not found"
idris2 --version 2>&1 | head -1 || echo "Idris2: not found"
echo ""
echo "=== Environment ==="
echo "USER: $USER"
echo "HOME: $HOME"
echo "PWD: $PWD"
# Show project information
project-info:
@echo "Project: {{PROJECT_NAME}}"
@echo "Version: {{PROJECT_VERSION}}"
@echo "Author: hyperpolymath"
@echo "URL: https://github.com/hyperpolymath/trigger"
# Edit configuration
edit-config:
#!/usr/bin/env bash
if [ -f config.json ]; then
if command -v code >/dev/null 2>&1; then
code config.json
elif command -v vim >/dev/null 2>&1; then
vim config.json
elif command -v nano >/dev/null 2>&1; then
nano config.json
else
${EDITOR:-vi} config.json
fi
else
echo "Config file not found. Run 'trigger --set-credentials' to create one."
fi
# =============================================================================
# Docker Recipes
# =============================================================================
# Build Docker image
docker-build:
docker build -t hyperpolymath/trigger:latest .
# Run Docker container
docker-run:
docker run -it hyperpolymath/trigger:latest
# Run Docker with volume mount
docker-run-dev:
docker run -it -v $(pwd):/app hyperpolymath/trigger:latest bash
# =============================================================================
# Cleanup Recipes
# =============================================================================
# Remove all build artifacts and temporary files
nuke:
just clean
rm -rf .alire .alr .zig-cache .idris2
rm -f *.log *.tmp
# Remove everything except source and git
nuke-all: nuke
rm -rf sessions/ config.json docs/html/