Skip to content

Commit 3a73135

Browse files
author
Jaakko Heusala
committed
Improved bitnet gguf parsing, etc.
1 parent 78f88fd commit 3a73135

103 files changed

Lines changed: 10203 additions & 5639 deletions

File tree

Some content is hidden

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

.cursor/rules/go-autonomous.mdc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
description: "Instruct Cursor to act autonomously toward the goal without prompting for confirmation."
3+
globs:
4+
alwaysApply: false
5+
---
6+
7+
# Autonomous Execution Rule
8+
9+
**Purpose:** Enable Cursor IDE to take initiative on achieving a defined goal--performing analysis, refactoring, or fixes--without asking follow-up questions.
10+
11+
## Guidelines
12+
13+
1. **Immediate Action**
14+
15+
* Upon recognizing the goal, proceed with all detection, analysis, and corrective steps automatically.
16+
* Do not prompt the user for intermediate approvals or clarifications.
17+
18+
2. **Continuous Context Usage**
19+
20+
* Leverage available context (task descriptions, code comments, existing rules) to make informed decisions.
21+
* Assume sufficient knowledge; refrain from asking questions about scope or next steps.
22+
23+
3. **End-to-End Completion**
24+
25+
* Execute the full workflow: detect issues, apply minimal fixes, verify results, and summarize actions.
26+
* Complete each phase in sequence without interruption.
27+
28+
4. **Concise Reporting**
29+
30+
* After finishing, provide a brief summary of actions taken, remaining tasks (if any), and verification outcomes.
31+
* Avoid intermediate or verbose prompts during execution.

.cursor/rules/go-context.mdc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
description: "Ensure that a feature branch's changes implement the intended BitNet issue"
3+
globs: **/*.go
4+
alwaysApply: false
5+
---
6+
7+
**Purpose:** Ensure that a feature branch's changes strictly implement the intended BitNet issue and introduce no unrelated modifications.
8+
9+
To learn more about current context, run this command:
10+
11+
`./scripts/get-current-context.sh|cat`

.cursor/rules/go-refactor.mdc

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
description: "Detect duplicated logic and refactor large functions into reusable, tested utility functions."
3+
globs: *.go, pkg/**/*.go
4+
alwaysApply: false
5+
---
6+
7+
# Utility Extraction & Function Decomposition Rule
8+
9+
**Purpose:** Identify repeating patterns and overly complex functions in Go
10+
code, extract shared logic into small, semantic utility functions, and
11+
decompose large functions for readability and maintainability. Ensure all new
12+
utilities have independent unit tests.
13+
14+
## 1. Detect Duplication & Complexity
15+
16+
* **Search for repeated code blocks:** Use `grep`, `git diff`, or IDE "Find
17+
Duplicates" features to locate similar logic across files.
18+
19+
* **Identify large functions:** Functions exceeding \~50 lines or containing
20+
multiple distinct responsibilities.
21+
22+
## 2. Extract Utility Functions
23+
24+
1. **Define a clear purpose:** Name utilities descriptively (e.g.,
25+
`ParseConfigField`, `ValidateUserInput`).
26+
27+
2. **Move shared logic:** Extract common code into a new function in an
28+
appropriate package (e.g., `internal/util`).
29+
30+
3. **Update callers:** Replace inlined code in each original location with
31+
calls to the new utility.
32+
33+
```go
34+
// Before: repeated parsing logic in multiple handlers
35+
field, err := strconv.Atoi(params["count"])
36+
if err != nil {
37+
return fmt.Errorf("invalid count: %v", err)
38+
}
39+
40+
// After: single utility
41+
field, err := util.ParseIntParam(params, "count")
42+
if err != nil {
43+
return err
44+
}
45+
```
46+
47+
## 3. Decompose Large Functions
48+
49+
* **Single Responsibility:** Split functions that perform multiple tasks (e.g.,
50+
parsing, validation, storage) into smaller helper or utility calls.
51+
52+
* **Maintain clear flow:** Orchestrator functions should focus on high-level
53+
logic, delegating details to extracted utilities.
54+
55+
## 4. Unit Test Utilities Independently
56+
57+
* **Create dedicated `*_test.go` files** for each new utility.
58+
59+
* **Cover edge cases and error paths** using table-driven tests.
60+
61+
* **Use `b.ReportAllocs()`** in benchmarks for performance-sensitive utilities.
62+
63+
```go
64+
func TestParseIntParam(t *testing.T) {
65+
tests := []struct { key, want string; wantErr bool }{
66+
{"count", "5", false},
67+
{"missing", "", true},
68+
{"bad", "abc", true},
69+
}
70+
for _, tc := range tests {
71+
t.Run(tc.key, func(t *testing.T) {
72+
_, err := ParseIntParam(map[string]string{tc.key: tc.want}, tc.key)
73+
if (err != nil) != tc.wantErr {
74+
t.Fatalf("ParseIntParam error = %v, wantErr %v", err, tc.wantErr)
75+
}
76+
})
77+
}
78+
}
79+
```
80+
81+
## 5. Verify and Clean Up
82+
83+
* **Run coverage:** Ensure utilities are fully covered.
84+
85+
* **Run linters and formatters:** Maintain code style.
86+
87+
* **Refactor call sites:** Remove any remaining duplication and update imports.
88+
89+
---
90+
91+
*Apply this rule to improve code reuse, readability, and testability across Go
92+
modules.*

.cursor/rules/go-repair-tests.mdc

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
description: "Automate the detection and stepwise resolution of failing tests in pkg/bitnet, starting from the lowest-level packages."
3+
globs: pkg/bitnet/**/*.go
4+
alwaysApply: false
5+
---
6+
7+
# Failing Test Resolution Rule
8+
9+
**Purpose:** Detect failing tests dynamically, order them by package dependency (leaf packages first), and guide Cursor through diagnosing and fixing each failure in turn.
10+
11+
## Steps
12+
13+
1. **Map Tests to Packages**
14+
15+
```bash
16+
go test -timeout 18s -json ./pkg/bitnet/... \
17+
| jq -r 'select(.Action=="fail" and .Test!=null) | "\(.Package):\(.Test)"' \
18+
| sort -u > tests_by_pkg.txt
19+
```
20+
21+
Captures all failed tests with their packages in one command.
22+
23+
2. **Order Packages**
24+
25+
```bash
26+
cut -d: -f1 tests_by_pkg.txt \
27+
| awk -F/ '{print NF, $0}' \
28+
| sort -n \
29+
| cut -d' ' -f2 \
30+
| uniq > ordered_pkgs.txt
31+
```
32+
33+
Sorts packages by directory depth (leaf packages first).
34+
35+
3. **Iterate and Fix**
36+
For each package in `ordered_pkgs.txt`:
37+
38+
a. Extract its failing tests:
39+
40+
```bash
41+
grep "^$pkg:" tests_by_pkg.txt | cut -d: -f2 > pkg_tests.txt
42+
```
43+
44+
b. For each test in `pkg_tests.txt`:
45+
46+
```bash
47+
go test -run $test -timeout 18s -v $pkg -race
48+
```
49+
50+
* **Diagnose:** Identify root cause from failure output.
51+
* **Check Docs:** Review comments in the related `.go` file and any linked issues (`gh issue view`).
52+
53+
* If test and docs mismatch, **update test** to align with documented behavior.
54+
* Otherwise, **fix implementation** to satisfy both test and documentation.
55+
* If unclear, skip this test and continue.
56+
57+
c. After fixes, rerun the test to confirm it passes.
58+
59+
4. **Report Progress**
60+
Summarize:
61+
62+
* [ OK ] Tests fixed per package
63+
* [WARN] Tests skipped due to unclear requirements
64+
65+
\--- **Iterate and Fix**
66+
For each package in `ordered_pkgs.txt`:
67+
68+
a. Extract its failing tests:
69+
70+
```bash
71+
grep "^$pkg:" tests_by_pkg.txt | cut -d: -f2 > pkg_tests.txt
72+
```
73+
74+
b. For each test in `pkg_tests.txt`:
75+
76+
```bash
77+
go test -run $test -timeout 18s -v $pkg -race
78+
```
79+
80+
* **Diagnose:** Identify root cause from failure output.
81+
* **Check Docs:** Review comments in the related `.go` file and any linked issues (`gh issue view`).
82+
83+
* If test and docs mismatch, **update test** to align with documented behavior.
84+
* Otherwise, **fix implementation** to satisfy both test and documentation.
85+
* If unclear, skip this test and continue.
86+
87+
c. After fixes, rerun the test to confirm it passes.
88+
89+
5. **Report Progress**
90+
After all packages are processed, summarize:
91+
92+
* [ OK ] Tests fixed per package
93+
* [WARN] Tests skipped due to unclear requirements

.cursor/rules/go-vet.mdc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
description: "Run `go vet` on the BitNet packages and correct all reported issues without committing changes."
3+
globs: pkg/bitnet/**/*.go
4+
alwaysApply: false
5+
---
6+
7+
# `go vet` Enforcement Rule
8+
9+
**Purpose:** Identify and fix suspicious code patterns in Go files under `pkg/bitnet` using `go vet`, without automating commits.
10+
11+
## Steps
12+
13+
1. **Run the Vet Tool**
14+
15+
```bash
16+
go vet ./pkg/bitnet/...
17+
```
18+
19+
Review the output for issues such as:
20+
21+
* Incorrect struct tags
22+
* Unhandled errors
23+
* Unused variables or imports
24+
* Printf-style issues
25+
26+
2. **Review Each Finding**
27+
For each reported issue (`file.go:line: description`):
28+
29+
* Open the file at the specified line.
30+
* Understand the root cause of the warning.
31+
32+
3. **Apply Minimal Fixes**
33+
34+
* Modify the code to address the vet warning.
35+
* Examples:
36+
37+
* Remove or use unused imports/variables.
38+
* Add error checks or handle returned errors.
39+
* Correct struct tag formatting (e.g., `json:"name,omitempty"`).
40+
* Use `fmt.Sprintf` placeholders correctly.
41+
42+
4. **Verify Fixes Locally**
43+
44+
* Rerun vet to confirm the issue is resolved:
45+
46+
```bash
47+
go vet ./pkg/bitnet/...
48+
```
49+
50+
## Best Practices
51+
52+
* **Granular Edits:** Only change the lines necessary to satisfy vet.
53+
* **Manual Review:** Inspect diffs before staging to avoid unintended modifications.
54+
* **Developer Control:** After fixes, manually commit and push as desired.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ profiles/
1414
tensor.test
1515

1616
# BitNet model files
17-
pkg/bitnet/internal/assets/models/
17+
pkg/bitnet/assets/models/
1818

1919
math.test
2020
coverage.html
21+
22+
*.txt

0 commit comments

Comments
 (0)