Skip to content

Commit 6a4f208

Browse files
Merge pull request #350 from marvin-hansen/main
Updated algo crate
2 parents bf9338c + 5ae8cc8 commit 6a4f208

File tree

168 files changed

+9169
-2566
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+9169
-2566
lines changed

.specify/memory/constitution.md

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,55 @@
1-
# [PROJECT_NAME] Constitution
2-
<!-- Example: Spec Constitution, TaskFlow Constitution, etc. -->
1+
<!--
2+
Sync Impact Report
3+
- Version: v1.0.0 (Initial establishment of the project constitution)
4+
- Added Principles:
5+
- I. Convention and Structure
6+
- II. Rigorous Testing
7+
- III. Performance via Zero-Cost Abstractions
8+
- IV. Uncompromising Safety
9+
- V. Clear and Private APIs
10+
- Added Sections:
11+
- Development Workflow
12+
- Code Style and Formatting
13+
- Templates Requiring Updates:
14+
- ✅ .specify/templates/plan-template.md
15+
- Follow-up TODOs:
16+
- TODO(RATIFICATION_DATE): Set initial adoption date.
17+
-->
18+
19+
# deep_causality Constitution
320

421
## Core Principles
522

6-
### [PRINCIPLE_1_NAME]
7-
<!-- Example: I. Library-First -->
8-
[PRINCIPLE_1_DESCRIPTION]
9-
<!-- Example: Every feature starts as a standalone library; Libraries must be self-contained, independently testable, documented; Clear purpose required - no organizational-only libraries -->
23+
### I. Convention and Structure
24+
All contributions MUST adhere to the established conventions, style, and structure of the existing codebase. Each crate MUST follow the established `src/{errors, traits, types}` layout. Each file within these modules MUST contain only a single, corresponding definition (one type per file, one trait per file, etc.).
25+
Rationale: This ensures consistency, maintainability, and predictability across the monorepo, making it easier for contributors to navigate and understand the code.
1026

11-
### [PRINCIPLE_2_NAME]
12-
<!-- Example: II. CLI Interface -->
13-
[PRINCIPLE_2_DESCRIPTION]
14-
<!-- Example: Every library exposes functionality via CLI; Text in/out protocol: stdin/args → stdout, errors → stderr; Support JSON + human-readable formats -->
27+
### II. Rigorous Testing
28+
All new features, bug fixes, or substantial changes MUST be accompanied by corresponding tests. Crate-specific tests MUST be run via `cargo test -p <crate_name>`. Before submitting a contribution with multi-crate impact, the entire project test suite MUST pass via `make test`.
29+
Rationale: Guarantees code quality, prevents regressions, and ensures that individual components and the system as a whole behave as expected.
1530

16-
### [PRINCIPLE_3_NAME]
17-
<!-- Example: III. Test-First (NON-NEGOTIABLE) -->
18-
[PRINCIPLE_3_DESCRIPTION]
19-
<!-- Example: TDD mandatory: Tests written → User approved → Tests fail → Then implement; Red-Green-Refactor cycle strictly enforced -->
31+
### III. Performance via Zero-Cost Abstractions
32+
Code MUST prefer static dispatch over dynamic dispatch (e.g., `dyn Trait`). All abstractions should strive to be 'zero-cost,' meaning they have no runtime overhead. A functional style (e.g., `map`, `filter`) is preferred for its clarity and potential for optimization.
33+
Rationale: Aligns with Rust's core philosophy and is critical for a high-performance computational causality library. It ensures that high-level code does not compromise low-level performance.
2034

21-
### [PRINCIPLE_4_NAME]
22-
<!-- Example: IV. Integration Testing -->
23-
[PRINCIPLE_4_DESCRIPTION]
24-
<!-- Example: Focus areas requiring integration tests: New library contract tests, Contract changes, Inter-service communication, Shared schemas -->
35+
### IV. Uncompromising Safety
36+
The use of `unsafe` code is strictly prohibited in all library crates (`/src`). External dependencies should be minimized and vetted for security. All code MUST be checked with `make check` before submission.
37+
Rationale: Ensures memory safety, robustness, and security, which are non-negotiable for a foundational library intended for production-grade systems.
2538

26-
### [PRINCIPLE_5_NAME]
27-
<!-- Example: V. Observability, VI. Versioning & Breaking Changes, VII. Simplicity -->
28-
[PRINCIPLE_5_DESCRIPTION]
29-
<!-- Example: Text I/O ensures debuggability; Structured logging required; Or: MAJOR.MINOR.BUILD format; Or: Start simple, YAGNI principles -->
39+
### V. Clear and Private APIs
40+
All fields in public-facing types MUST be private. Access MUST be provided through explicit constructors, getters, and setters. Internal modules MUST remain private at the crate root, and all public APIs MUST be explicitly exported from `src/lib.rs`.
41+
Rationale: Enforces strong encapsulation, creating stable and predictable public APIs while allowing internal implementation details to evolve without breaking downstream users.
3042

31-
## [SECTION_2_NAME]
32-
<!-- Example: Additional Constraints, Security Requirements, Performance Standards, etc. -->
43+
## Development Workflow
3344

34-
[SECTION_2_CONTENT]
35-
<!-- Example: Technology stack requirements, compliance standards, deployment policies, etc. -->
45+
All development follows a crate-centric model. Changes should be confined to a single crate where possible. Build and test commands (`cargo build -p <name>`, `cargo test -p <name>`) MUST be run on the affected crate. For changes spanning multiple crates, `make format && make fix` MUST be run before submission to ensure repository-wide consistency.
3646

37-
## [SECTION_3_NAME]
38-
<!-- Example: Development Workflow, Review Process, Quality Gates, etc. -->
47+
## Code Style and Formatting
3948

40-
[SECTION_3_CONTENT]
41-
<!-- Example: Code review requirements, testing gates, deployment approval process, etc. -->
49+
All code MUST be formatted using `cargo fmt` according to the `rustfmt.toml` configuration. Lints are enforced by `clippy`, and all warnings MUST be resolved by running `make fix` or addressing them manually.
4250

4351
## Governance
44-
<!-- Example: Constitution supersedes all other practices; Amendments require documentation, approval, migration plan -->
4552

46-
[GOVERNANCE_RULES]
47-
<!-- Example: All PRs/reviews must verify compliance; Complexity must be justified; Use [GUIDANCE_FILE] for runtime development guidance -->
53+
This Constitution is the single source of truth for development standards and supersedes all other practices. All contributions and reviews MUST verify compliance with these principles. Any deviation requires a formal amendment to this document. The `AGENTS.md` file provides runtime development guidance for AI agents and MUST remain in sync with these principles.
4854

49-
**Version**: [CONSTITUTION_VERSION] | **Ratified**: [RATIFICATION_DATE] | **Last Amended**: [LAST_AMENDED_DATE]
50-
<!-- Example: Version: 2.1.1 | Ratified: 2025-06-13 | Last Amended: 2025-07-16 -->
55+
**Version**: v1.0.0 | **Ratified**: TODO(RATIFICATION_DATE): Set initial adoption date. | **Last Amended**: 2025-09-30
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
#!/usr/bin/env bash
2+
3+
# Consolidated prerequisite checking script
4+
#
5+
# This script provides unified prerequisite checking for Spec-Driven Development workflow.
6+
# It replaces the functionality previously spread across multiple scripts.
7+
#
8+
# Usage: ./check-prerequisites.sh [OPTIONS]
9+
#
10+
# OPTIONS:
11+
# --json Output in JSON format
12+
# --require-tasks Require tasks.md to exist (for implementation phase)
13+
# --include-tasks Include tasks.md in AVAILABLE_DOCS list
14+
# --paths-only Only output path variables (no validation)
15+
# --help, -h Show help message
16+
#
17+
# OUTPUTS:
18+
# JSON mode: {"FEATURE_DIR":"...", "AVAILABLE_DOCS":["..."]}
19+
# Text mode: FEATURE_DIR:... \n AVAILABLE_DOCS: \n ✓/✗ file.md
20+
# Paths only: REPO_ROOT: ... \n BRANCH: ... \n FEATURE_DIR: ... etc.
21+
22+
set -e
23+
24+
# Parse command line arguments
25+
JSON_MODE=false
26+
REQUIRE_TASKS=false
27+
INCLUDE_TASKS=false
28+
PATHS_ONLY=false
29+
30+
for arg in "$@"; do
31+
case "$arg" in
32+
--json)
33+
JSON_MODE=true
34+
;;
35+
--require-tasks)
36+
REQUIRE_TASKS=true
37+
;;
38+
--include-tasks)
39+
INCLUDE_TASKS=true
40+
;;
41+
--paths-only)
42+
PATHS_ONLY=true
43+
;;
44+
--help|-h)
45+
cat << 'EOF'
46+
Usage: check-prerequisites.sh [OPTIONS]
47+
48+
Consolidated prerequisite checking for Spec-Driven Development workflow.
49+
50+
OPTIONS:
51+
--json Output in JSON format
52+
--require-tasks Require tasks.md to exist (for implementation phase)
53+
--include-tasks Include tasks.md in AVAILABLE_DOCS list
54+
--paths-only Only output path variables (no prerequisite validation)
55+
--help, -h Show this help message
56+
57+
EXAMPLES:
58+
# Check task prerequisites (plan.md required)
59+
./check-prerequisites.sh --json
60+
61+
# Check implementation prerequisites (plan.md + tasks.md required)
62+
./check-prerequisites.sh --json --require-tasks --include-tasks
63+
64+
# Get feature paths only (no validation)
65+
./check-prerequisites.sh --paths-only
66+
67+
EOF
68+
exit 0
69+
;;
70+
*)
71+
echo "ERROR: Unknown option '$arg'. Use --help for usage information." >&2
72+
exit 1
73+
;;
74+
esac
75+
done
76+
77+
# Source common functions
78+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
79+
source "$SCRIPT_DIR/common.sh"
80+
81+
# Get feature paths and validate branch
82+
eval $(get_feature_paths)
83+
check_feature_branch "$CURRENT_BRANCH" "$HAS_GIT" || exit 1
84+
85+
# If paths-only mode, output paths and exit (support JSON + paths-only combined)
86+
if $PATHS_ONLY; then
87+
if $JSON_MODE; then
88+
# Minimal JSON paths payload (no validation performed)
89+
printf '{"REPO_ROOT":"%s","BRANCH":"%s","FEATURE_DIR":"%s","FEATURE_SPEC":"%s","IMPL_PLAN":"%s","TASKS":"%s"}\n' \
90+
"$REPO_ROOT" "$CURRENT_BRANCH" "$FEATURE_DIR" "$FEATURE_SPEC" "$IMPL_PLAN" "$TASKS"
91+
else
92+
echo "REPO_ROOT: $REPO_ROOT"
93+
echo "BRANCH: $CURRENT_BRANCH"
94+
echo "FEATURE_DIR: $FEATURE_DIR"
95+
echo "FEATURE_SPEC: $FEATURE_SPEC"
96+
echo "IMPL_PLAN: $IMPL_PLAN"
97+
echo "TASKS: $TASKS"
98+
fi
99+
exit 0
100+
fi
101+
102+
# Validate required directories and files
103+
if [[ ! -d "$FEATURE_DIR" ]]; then
104+
echo "ERROR: Feature directory not found: $FEATURE_DIR" >&2
105+
echo "Run /specify first to create the feature structure." >&2
106+
exit 1
107+
fi
108+
109+
if [[ ! -f "$IMPL_PLAN" ]]; then
110+
echo "ERROR: plan.md not found in $FEATURE_DIR" >&2
111+
echo "Run /plan first to create the implementation plan." >&2
112+
exit 1
113+
fi
114+
115+
# Check for tasks.md if required
116+
if $REQUIRE_TASKS && [[ ! -f "$TASKS" ]]; then
117+
echo "ERROR: tasks.md not found in $FEATURE_DIR" >&2
118+
echo "Run /tasks first to create the task list." >&2
119+
exit 1
120+
fi
121+
122+
# Build list of available documents
123+
docs=()
124+
125+
# Always check these optional docs
126+
[[ -f "$RESEARCH" ]] && docs+=("research.md")
127+
[[ -f "$DATA_MODEL" ]] && docs+=("data-model.md")
128+
129+
# Check contracts directory (only if it exists and has files)
130+
if [[ -d "$CONTRACTS_DIR" ]] && [[ -n "$(ls -A "$CONTRACTS_DIR" 2>/dev/null)" ]]; then
131+
docs+=("contracts/")
132+
fi
133+
134+
[[ -f "$QUICKSTART" ]] && docs+=("quickstart.md")
135+
136+
# Include tasks.md if requested and it exists
137+
if $INCLUDE_TASKS && [[ -f "$TASKS" ]]; then
138+
docs+=("tasks.md")
139+
fi
140+
141+
# Output results
142+
if $JSON_MODE; then
143+
# Build JSON array of documents
144+
if [[ ${#docs[@]} -eq 0 ]]; then
145+
json_docs="[]"
146+
else
147+
json_docs=$(printf '"%s",' "${docs[@]}")
148+
json_docs="[${json_docs%,}]"
149+
fi
150+
151+
printf '{"FEATURE_DIR":"%s","AVAILABLE_DOCS":%s}\n' "$FEATURE_DIR" "$json_docs"
152+
else
153+
# Text output
154+
echo "FEATURE_DIR:$FEATURE_DIR"
155+
echo "AVAILABLE_DOCS:"
156+
157+
# Show status of each potential document
158+
check_file "$RESEARCH" "research.md"
159+
check_file "$DATA_MODEL" "data-model.md"
160+
check_dir "$CONTRACTS_DIR" "contracts/"
161+
check_file "$QUICKSTART" "quickstart.md"
162+
163+
if $INCLUDE_TASKS; then
164+
check_file "$TASKS" "tasks.md"
165+
fi
166+
fi

.specify/scripts/bash/common.sh

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,103 @@
11
#!/usr/bin/env bash
2-
# (Moved to scripts/bash/) Common functions and variables for all scripts
2+
# Common functions and variables for all scripts
33

4-
get_repo_root() { git rev-parse --show-toplevel; }
5-
get_current_branch() { git rev-parse --abbrev-ref HEAD; }
4+
# Get repository root, with fallback for non-git repositories
5+
get_repo_root() {
6+
if git rev-parse --show-toplevel >/dev/null 2>&1; then
7+
git rev-parse --show-toplevel
8+
else
9+
# Fall back to script location for non-git repos
10+
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11+
(cd "$script_dir/../../.." && pwd)
12+
fi
13+
}
14+
15+
# Get current branch, with fallback for non-git repositories
16+
get_current_branch() {
17+
# First check if SPECIFY_FEATURE environment variable is set
18+
if [[ -n "${SPECIFY_FEATURE:-}" ]]; then
19+
echo "$SPECIFY_FEATURE"
20+
return
21+
fi
22+
23+
# Then check git if available
24+
if git rev-parse --abbrev-ref HEAD >/dev/null 2>&1; then
25+
git rev-parse --abbrev-ref HEAD
26+
return
27+
fi
28+
29+
# For non-git repos, try to find the latest feature directory
30+
local repo_root=$(get_repo_root)
31+
local specs_dir="$repo_root/specs"
32+
33+
if [[ -d "$specs_dir" ]]; then
34+
local latest_feature=""
35+
local highest=0
36+
37+
for dir in "$specs_dir"/*; do
38+
if [[ -d "$dir" ]]; then
39+
local dirname=$(basename "$dir")
40+
if [[ "$dirname" =~ ^([0-9]{3})- ]]; then
41+
local number=${BASH_REMATCH[1]}
42+
number=$((10#$number))
43+
if [[ "$number" -gt "$highest" ]]; then
44+
highest=$number
45+
latest_feature=$dirname
46+
fi
47+
fi
48+
fi
49+
done
50+
51+
if [[ -n "$latest_feature" ]]; then
52+
echo "$latest_feature"
53+
return
54+
fi
55+
fi
56+
57+
echo "main" # Final fallback
58+
}
59+
60+
# Check if we have git available
61+
has_git() {
62+
git rev-parse --show-toplevel >/dev/null 2>&1
63+
}
664

765
check_feature_branch() {
866
local branch="$1"
67+
local has_git_repo="$2"
68+
69+
# For non-git repos, we can't enforce branch naming but still provide output
70+
if [[ "$has_git_repo" != "true" ]]; then
71+
echo "[specify] Warning: Git repository not detected; skipped branch validation" >&2
72+
return 0
73+
fi
74+
975
if [[ ! "$branch" =~ ^[0-9]{3}- ]]; then
1076
echo "ERROR: Not on a feature branch. Current branch: $branch" >&2
1177
echo "Feature branches should be named like: 001-feature-name" >&2
1278
return 1
13-
fi; return 0
79+
fi
80+
81+
return 0
1482
}
1583

1684
get_feature_dir() { echo "$1/specs/$2"; }
1785

1886
get_feature_paths() {
1987
local repo_root=$(get_repo_root)
2088
local current_branch=$(get_current_branch)
89+
local has_git_repo="false"
90+
91+
if has_git; then
92+
has_git_repo="true"
93+
fi
94+
2195
local feature_dir=$(get_feature_dir "$repo_root" "$current_branch")
96+
2297
cat <<EOF
2398
REPO_ROOT='$repo_root'
2499
CURRENT_BRANCH='$current_branch'
100+
HAS_GIT='$has_git_repo'
25101
FEATURE_DIR='$feature_dir'
26102
FEATURE_SPEC='$feature_dir/spec.md'
27103
IMPL_PLAN='$feature_dir/plan.md'

0 commit comments

Comments
 (0)