markback 0.1.2__tar.gz → 0.1.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- markback-0.1.5/.claude/settings.local.json +23 -0
- {markback-0.1.2 → markback-0.1.5}/.ishipped/card.md +1 -0
- {markback-0.1.2 → markback-0.1.5}/PKG-INFO +8 -1
- {markback-0.1.2 → markback-0.1.5}/README.md +7 -0
- {markback-0.1.2 → markback-0.1.5}/SPEC.md +85 -20
- markback-0.1.5/markback/cli.py +122 -0
- {markback-0.1.2 → markback-0.1.5}/markback/linter.py +32 -7
- {markback-0.1.2 → markback-0.1.5}/markback/parser.py +6 -2
- {markback-0.1.2 → markback-0.1.5}/markback/types.py +34 -9
- {markback-0.1.2 → markback-0.1.5}/markback/writer.py +10 -3
- {markback-0.1.2 → markback-0.1.5}/packages/markbackjs/package.json +1 -1
- {markback-0.1.2 → markback-0.1.5}/packages/markbackjs/src/linter.ts +31 -6
- {markback-0.1.2 → markback-0.1.5}/packages/markbackjs/src/parser.ts +6 -2
- {markback-0.1.2 → markback-0.1.5}/packages/markbackjs/src/types.ts +42 -7
- {markback-0.1.2 → markback-0.1.5}/packages/markbackjs/src/writer.ts +6 -0
- {markback-0.1.2 → markback-0.1.5}/packages/markbackjs/test/linter.test.js +104 -0
- {markback-0.1.2 → markback-0.1.5}/pyproject.toml +3 -2
- markback-0.1.5/scripts/publish-npm.sh +11 -0
- markback-0.1.5/scripts/publish-pypi.sh +14 -0
- markback-0.1.5/scripts/publish.sh +16 -0
- {markback-0.1.2 → markback-0.1.5}/tests/test_linter.py +127 -0
- markback-0.1.2/.claude/settings.local.json +0 -13
- markback-0.1.2/markback/cli.py +0 -435
- {markback-0.1.2 → markback-0.1.5}/.gitignore +0 -0
- {markback-0.1.2 → markback-0.1.5}/IMPLEMENTATION_NOTES.md +0 -0
- {markback-0.1.2 → markback-0.1.5}/LICENSE +0 -0
- {markback-0.1.2 → markback-0.1.5}/markback/__init__.py +0 -0
- {markback-0.1.2 → markback-0.1.5}/markback/config.py +0 -0
- {markback-0.1.2 → markback-0.1.5}/markback/llm.py +0 -0
- {markback-0.1.2 → markback-0.1.5}/markback/workflow.py +0 -0
- {markback-0.1.2 → markback-0.1.5}/packages/markbackjs/LICENSE +0 -0
- {markback-0.1.2 → markback-0.1.5}/packages/markbackjs/README.md +0 -0
- {markback-0.1.2 → markback-0.1.5}/packages/markbackjs/package-lock.json +0 -0
- {markback-0.1.2 → markback-0.1.5}/packages/markbackjs/src/index.ts +0 -0
- {markback-0.1.2 → markback-0.1.5}/packages/markbackjs/tsconfig.json +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/__init__.py +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/fixtures/compact_source.mb +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/fixtures/errors/content_with_source.mb +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/fixtures/errors/empty_feedback.mb +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/fixtures/errors/malformed_uri.mb +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/fixtures/errors/missing_feedback.mb +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/fixtures/errors/multiple_feedback.mb +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/fixtures/essay.label.txt +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/fixtures/essay.txt +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/fixtures/external_source.mb +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/fixtures/freeform_feedback.mb +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/fixtures/json_feedback.mb +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/fixtures/label_list.mb +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/fixtures/minimal.mb +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/fixtures/multi_record.mb +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/fixtures/with_uri.mb +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/test_cli.py +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/test_config.py +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/test_parser.py +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/test_types.py +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/test_workflow.py +0 -0
- {markback-0.1.2 → markback-0.1.5}/tests/test_writer.py +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(python -m pytest:*)",
|
|
5
|
+
"Bash(npm test:*)",
|
|
6
|
+
"Bash(npm install)",
|
|
7
|
+
"Bash(npm run build:*)",
|
|
8
|
+
"Bash(echo:*)",
|
|
9
|
+
"Bash(python -m markback lint:*)",
|
|
10
|
+
"Bash(python:*)",
|
|
11
|
+
"Bash(python3 -m pytest:*)",
|
|
12
|
+
"Bash(pip3 install:*)",
|
|
13
|
+
"Bash(.venv/bin/python -m pytest:*)",
|
|
14
|
+
"Bash(chmod:*)",
|
|
15
|
+
"Bash(grep:*)",
|
|
16
|
+
"Bash(wc:*)",
|
|
17
|
+
"Bash(ls:*)",
|
|
18
|
+
"Bash(pip install:*)",
|
|
19
|
+
"Bash(PYTHONPATH=/src/markback EDITOR=cat python3:*)",
|
|
20
|
+
"Bash(PYTHONPATH=/src/markback python3:*)"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: markback
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.5
|
|
4
4
|
Summary: A compact, human-writable format for storing content paired with feedback/labels
|
|
5
5
|
Project-URL: Homepage, https://github.com/dandriscoll/markback
|
|
6
6
|
Project-URL: Repository, https://github.com/dandriscoll/markback
|
|
@@ -95,10 +95,17 @@ if result.has_errors:
|
|
|
95
95
|
|
|
96
96
|
## CLI Usage
|
|
97
97
|
|
|
98
|
+
The CLI is available via two commands:
|
|
99
|
+
- `markback` - Full command name
|
|
100
|
+
- `mb` - Convenient shorthand (works on all platforms including Windows)
|
|
101
|
+
|
|
102
|
+
Both commands are functionally identical. Examples below use `markback`, but you can substitute `mb` anywhere.
|
|
103
|
+
|
|
98
104
|
### Initialize configuration
|
|
99
105
|
|
|
100
106
|
```bash
|
|
101
107
|
markback init
|
|
108
|
+
# or: mb init
|
|
102
109
|
```
|
|
103
110
|
|
|
104
111
|
Creates a `.env` file with all configuration options.
|
|
@@ -60,10 +60,17 @@ if result.has_errors:
|
|
|
60
60
|
|
|
61
61
|
## CLI Usage
|
|
62
62
|
|
|
63
|
+
The CLI is available via two commands:
|
|
64
|
+
- `markback` - Full command name
|
|
65
|
+
- `mb` - Convenient shorthand (works on all platforms including Windows)
|
|
66
|
+
|
|
67
|
+
Both commands are functionally identical. Examples below use `markback`, but you can substitute `mb` anywhere.
|
|
68
|
+
|
|
63
69
|
### Initialize configuration
|
|
64
70
|
|
|
65
71
|
```bash
|
|
66
72
|
markback init
|
|
73
|
+
# or: mb init
|
|
67
74
|
```
|
|
68
75
|
|
|
69
76
|
Creates a `.env` file with all configuration options.
|
|
@@ -27,6 +27,7 @@ A MarkBack **record** is the fundamental unit. Every record has:
|
|
|
27
27
|
| `content` | Yes* | The content being labeled (inline or referenced) |
|
|
28
28
|
| `feedback` | Yes | Text after the `<<<` delimiter (always one line) |
|
|
29
29
|
| `uri` | No | Unique identifier for the item |
|
|
30
|
+
| `by` | No | Freeform identifier for who provided the feedback |
|
|
30
31
|
| `source` | No | Reference to external content (when content is not inline) |
|
|
31
32
|
| `prior` | No | Reference to an item that precedes the source (e.g., a prompt that generated the content) |
|
|
32
33
|
|
|
@@ -66,6 +67,7 @@ Header lines appear at the start of a record and begin with `@`. They define met
|
|
|
66
67
|
|
|
67
68
|
```
|
|
68
69
|
@uri <uri-value>
|
|
70
|
+
@by <freeform-text>
|
|
69
71
|
@source <path-or-uri>
|
|
70
72
|
@prior <path-or-uri>
|
|
71
73
|
```
|
|
@@ -95,7 +97,23 @@ Defines the unique identifier for this record.
|
|
|
95
97
|
|
|
96
98
|
**Validation:** URI MUST be valid per RFC 3986. Parsers MUST reject malformed URIs as errors.
|
|
97
99
|
|
|
98
|
-
#### 3.1.2 `@
|
|
100
|
+
#### 3.1.2 `@by` Header
|
|
101
|
+
|
|
102
|
+
Identifies who provided the feedback. The value is freeform text.
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
@by dan@example.com
|
|
106
|
+
@by Dan Driscoll
|
|
107
|
+
@by reviewer-42
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Rules:**
|
|
111
|
+
- Value is freeform text extending to end of line (trailing whitespace trimmed)
|
|
112
|
+
- Can contain any characters including spaces, special characters, etc.
|
|
113
|
+
- Commonly used for email addresses, usernames, or full names
|
|
114
|
+
- Optional - records without `@by` are valid
|
|
115
|
+
|
|
116
|
+
#### 3.1.3 `@source` Header
|
|
99
117
|
|
|
100
118
|
References external content instead of inline content.
|
|
101
119
|
|
|
@@ -111,7 +129,7 @@ References external content instead of inline content.
|
|
|
111
129
|
- When `@source` is present, inline content MUST be empty (or contain only whitespace)
|
|
112
130
|
- Parsers MUST verify referenced files exist (warning if missing)
|
|
113
131
|
|
|
114
|
-
#### 3.1.
|
|
132
|
+
#### 3.1.4 `@prior` Header
|
|
115
133
|
|
|
116
134
|
References an item that precedes the source material. For example, if the source is an image generated by an LLM, the prior could be the prompt that was used to create it.
|
|
117
135
|
|
|
@@ -127,26 +145,36 @@ References an item that precedes the source material. For example, if the source
|
|
|
127
145
|
- `@prior` does not affect content handling (inline content or `@source` rules still apply)
|
|
128
146
|
- Parsers SHOULD verify referenced files exist (warning if missing)
|
|
129
147
|
|
|
130
|
-
#### 3.1.
|
|
148
|
+
#### 3.1.5 Line and Character Range Specification
|
|
131
149
|
|
|
132
|
-
Both `@source` and `@prior` headers support optional line range specifications using colon notation. This allows referencing specific
|
|
150
|
+
Both `@source` and `@prior` headers support optional line and character range specifications using colon notation. This allows referencing specific positions within a file.
|
|
133
151
|
|
|
134
|
-
**Syntax:**
|
|
152
|
+
**Syntax:**
|
|
153
|
+
- Line only: `<path-or-uri>:<line>` or `<path-or-uri>:<start-line>-<end-line>`
|
|
154
|
+
- With columns: `<path-or-uri>:<line>:<col>` or `<path-or-uri>:<start-line>:<start-col>-<end-line>:<end-col>`
|
|
135
155
|
|
|
136
156
|
```
|
|
137
157
|
@source ./code.py:42
|
|
138
158
|
@source ./code.py:42-50
|
|
159
|
+
@source ./code.py:42:10
|
|
160
|
+
@source ./code.py:42:10-42:25
|
|
161
|
+
@source ./code.py:10:5-15:20
|
|
139
162
|
@prior ./prompts/template.txt:1-20
|
|
140
163
|
@source https://example.com/file.txt:100-150
|
|
141
164
|
```
|
|
142
165
|
|
|
143
166
|
**Rules:**
|
|
144
|
-
- Line numbers are 1-indexed (first line is
|
|
167
|
+
- Line and column numbers are 1-indexed (first line/column is 1)
|
|
145
168
|
- Single line: `:N` references line N only
|
|
146
169
|
- Line range: `:N-M` references lines N through M (inclusive)
|
|
147
|
-
-
|
|
148
|
-
-
|
|
170
|
+
- Single position: `:N:C` references line N, column C
|
|
171
|
+
- Character range: `:N:C-M:D` references from line N column C to line M column D (inclusive)
|
|
172
|
+
- End position must be greater than or equal to start position (E011 error otherwise)
|
|
173
|
+
- If on same line: end column must be >= start column
|
|
174
|
+
- If on different lines: end line must be >= start line
|
|
175
|
+
- Ranges are informational metadata; parsers do not validate that referenced positions exist in the file
|
|
149
176
|
- Windows drive letters (e.g., `C:\path`) are not confused with line ranges because scheme detection requires length > 1
|
|
177
|
+
- Column specification is optional; you can specify `:10:5-20` (start with column, end without)
|
|
150
178
|
|
|
151
179
|
### 3.2 Content Block
|
|
152
180
|
|
|
@@ -481,7 +509,7 @@ Canonical form ensures consistent output for comparison and version control.
|
|
|
481
509
|
### 5.2 Canonicalization Rules
|
|
482
510
|
|
|
483
511
|
1. **Line endings:** Normalize to `\n` (LF)
|
|
484
|
-
2. **Header order:** `@uri` before `@prior` before `@source` before unknown headers (alphabetical)
|
|
512
|
+
2. **Header order:** `@uri` before `@by` before `@prior` before `@source` before unknown headers (alphabetical)
|
|
485
513
|
3. **Header spacing:** Exactly one space after keyword
|
|
486
514
|
4. **Trailing whitespace:** Remove from all lines
|
|
487
515
|
5. **Content whitespace:** Preserve internal whitespace; trim leading/trailing blank lines
|
|
@@ -678,7 +706,42 @@ Spring whispers goodbye.
|
|
|
678
706
|
<<< creative; follows haiku structure; quality=excellent
|
|
679
707
|
```
|
|
680
708
|
|
|
681
|
-
### 8.5
|
|
709
|
+
### 8.5 Record with Attribution
|
|
710
|
+
|
|
711
|
+
```
|
|
712
|
+
@uri local:review-001
|
|
713
|
+
@by dan@example.com
|
|
714
|
+
|
|
715
|
+
This code needs better error handling.
|
|
716
|
+
<<< actionable; priority=high
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
Or with a full name:
|
|
720
|
+
```
|
|
721
|
+
@uri local:review-002
|
|
722
|
+
@by Dan Driscoll
|
|
723
|
+
@source ./src/app.py
|
|
724
|
+
<<< approved; good code quality
|
|
725
|
+
```
|
|
726
|
+
|
|
727
|
+
### 8.6 Character-Level References
|
|
728
|
+
|
|
729
|
+
Reference a specific position in a file:
|
|
730
|
+
```
|
|
731
|
+
@source ./code.py:42:10 <<< potential bug at this position
|
|
732
|
+
```
|
|
733
|
+
|
|
734
|
+
Reference a character range on a single line:
|
|
735
|
+
```
|
|
736
|
+
@source ./code.py:42:10-42:25 <<< consider renaming this variable
|
|
737
|
+
```
|
|
738
|
+
|
|
739
|
+
Reference a multi-line character range:
|
|
740
|
+
```
|
|
741
|
+
@source ./code.py:10:5-15:20 <<< this function needs refactoring
|
|
742
|
+
```
|
|
743
|
+
|
|
744
|
+
### 8.7 Single-File Example
|
|
682
745
|
|
|
683
746
|
**File:** `question.mb`
|
|
684
747
|
```
|
|
@@ -688,7 +751,7 @@ Explain quantum entanglement in simple terms.
|
|
|
688
751
|
<<< quality=excellent; accuracy=high; clarity=good
|
|
689
752
|
```
|
|
690
753
|
|
|
691
|
-
### 8.
|
|
754
|
+
### 8.8 Label List Example (Compact Format)
|
|
692
755
|
|
|
693
756
|
**File:** `image-annotations.mb`
|
|
694
757
|
```
|
|
@@ -720,7 +783,7 @@ Explain quantum entanglement in simple terms.
|
|
|
720
783
|
@source ./batch1/item3.txt <<< positive; excellent clarity
|
|
721
784
|
```
|
|
722
785
|
|
|
723
|
-
### 8.
|
|
786
|
+
### 8.9 Multi-Record Example (Mixed Freeform and Structured)
|
|
724
787
|
|
|
725
788
|
**File:** `training-data.mb`
|
|
726
789
|
```
|
|
@@ -751,7 +814,7 @@ Please write a formal letter requesting a meeting.
|
|
|
751
814
|
@source ./audio/sample-005.wav <<< transcription="Hello world"; quality=clear; language=en
|
|
752
815
|
```
|
|
753
816
|
|
|
754
|
-
### 8.
|
|
817
|
+
### 8.10 Paired-File Example
|
|
755
818
|
|
|
756
819
|
**Content file:** `essay.txt`
|
|
757
820
|
```
|
|
@@ -767,7 +830,7 @@ agriculture, manufacturing, mining, and transport.
|
|
|
767
830
|
<<< good; grade=B+; well structured but needs more specific examples
|
|
768
831
|
```
|
|
769
832
|
|
|
770
|
-
### 8.
|
|
833
|
+
### 8.11 Freeform Feedback Examples
|
|
771
834
|
|
|
772
835
|
Various styles of freeform feedback:
|
|
773
836
|
|
|
@@ -790,7 +853,7 @@ Explain machine learning to a child.
|
|
|
790
853
|
<<< needs work; the explanation assumes too much prior knowledge
|
|
791
854
|
```
|
|
792
855
|
|
|
793
|
-
### 8.
|
|
856
|
+
### 8.12 Complex Structured Feedback (JSON)
|
|
794
857
|
|
|
795
858
|
```
|
|
796
859
|
@uri local:complex-example
|
|
@@ -799,7 +862,7 @@ Multi-attribute content with special characters.
|
|
|
799
862
|
<<< json:{"rating":4.5,"tags":["important","review"],"notes":"Contains \"quoted\" text and; semicolons","scores":{"accuracy":0.9,"relevance":0.85}}
|
|
800
863
|
```
|
|
801
864
|
|
|
802
|
-
### 8.
|
|
865
|
+
### 8.13 Image with MarkBack Sidecar
|
|
803
866
|
|
|
804
867
|
**Content file:** `diagram.png` (binary)
|
|
805
868
|
|
|
@@ -882,13 +945,15 @@ feedback = "<<<" SP feedback-content LF
|
|
|
882
945
|
feedback-content = *VCHAR ; no LF allowed
|
|
883
946
|
|
|
884
947
|
; Compact record (single line, external source only)
|
|
885
|
-
compact-record = [uri-line] source-feedback-line
|
|
948
|
+
compact-record = [uri-line] [by-line] [prior-line] source-feedback-line
|
|
886
949
|
compact-list = compact-record *(1*blank-line compact-record)
|
|
887
950
|
uri-line = "@uri" SP value LF
|
|
951
|
+
by-line = "@by" SP value LF
|
|
952
|
+
prior-line = "@prior" SP path-with-range LF
|
|
888
953
|
source-feedback-line = "@source" SP path-with-range SP "<<<" SP feedback-content LF
|
|
889
|
-
path-with-range = path [
|
|
890
|
-
path = 1*VCHAR ; ends at space before <<< or
|
|
891
|
-
|
|
954
|
+
path-with-range = path [position-range] ; path with optional position range
|
|
955
|
+
path = 1*VCHAR ; ends at space before <<< or position-range
|
|
956
|
+
position-range = ":" 1*DIGIT [":" 1*DIGIT] ["-" 1*DIGIT [":" 1*DIGIT]]
|
|
892
957
|
|
|
893
958
|
LOWER = %x61-7A ; a-z
|
|
894
959
|
SP = %x20 ; space
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""MarkBack command-line interface."""
|
|
2
|
+
|
|
3
|
+
import glob
|
|
4
|
+
import os
|
|
5
|
+
import shutil
|
|
6
|
+
import subprocess
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Annotated
|
|
10
|
+
|
|
11
|
+
import typer
|
|
12
|
+
from rich.console import Console
|
|
13
|
+
|
|
14
|
+
from .writer import write_file
|
|
15
|
+
|
|
16
|
+
err_console = Console(stderr=True)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def get_mb_path(target: Path) -> Path:
|
|
20
|
+
"""Get the .mb file path for a target file."""
|
|
21
|
+
return target.with_suffix(target.suffix + ".mb")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def get_feedback_path(directory: Path) -> Path:
|
|
25
|
+
"""Get a non-colliding feedback.mb path in the given directory."""
|
|
26
|
+
candidate = directory / "feedback.mb"
|
|
27
|
+
if not candidate.exists():
|
|
28
|
+
return candidate
|
|
29
|
+
counter = 1
|
|
30
|
+
while True:
|
|
31
|
+
candidate = directory / f"feedback-{counter}.mb"
|
|
32
|
+
if not candidate.exists():
|
|
33
|
+
return candidate
|
|
34
|
+
counter += 1
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def collect_glob(pattern: str) -> None:
|
|
38
|
+
"""Expand a glob pattern and write all matches into a single .mb file."""
|
|
39
|
+
from .types import Record, SourceRef
|
|
40
|
+
|
|
41
|
+
matches = sorted(glob.glob(pattern))
|
|
42
|
+
if not matches:
|
|
43
|
+
err_console.print(f"[red]No files match pattern: {pattern}[/red]")
|
|
44
|
+
raise typer.Exit(1)
|
|
45
|
+
|
|
46
|
+
records = [Record(source=SourceRef(f), feedback="") for f in matches]
|
|
47
|
+
|
|
48
|
+
# Determine output directory from the pattern's parent, defaulting to cwd
|
|
49
|
+
pattern_parent = Path(pattern).parent
|
|
50
|
+
output_dir = pattern_parent if pattern_parent != Path("") else Path(".")
|
|
51
|
+
output_path = get_feedback_path(output_dir)
|
|
52
|
+
|
|
53
|
+
write_file(output_path, records)
|
|
54
|
+
err_console.print(f"Created {output_path} with {len(records)} source(s)")
|
|
55
|
+
open_editor(output_path)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def open_editor(path: Path) -> None:
|
|
59
|
+
"""Open the file in the user's editor."""
|
|
60
|
+
editor = os.environ.get("EDITOR") or os.environ.get("VISUAL")
|
|
61
|
+
|
|
62
|
+
if editor:
|
|
63
|
+
subprocess.run([editor, str(path)])
|
|
64
|
+
elif sys.platform == "win32":
|
|
65
|
+
os.startfile(path)
|
|
66
|
+
elif sys.platform == "darwin":
|
|
67
|
+
subprocess.run(["open", str(path)])
|
|
68
|
+
else:
|
|
69
|
+
# Try xdg-open first, then fall back to common editors
|
|
70
|
+
if shutil.which("xdg-open"):
|
|
71
|
+
result = subprocess.run(["xdg-open", str(path)], capture_output=True)
|
|
72
|
+
if result.returncode == 0:
|
|
73
|
+
return
|
|
74
|
+
for fallback in ("nano", "vi"):
|
|
75
|
+
if shutil.which(fallback):
|
|
76
|
+
subprocess.run([fallback, str(path)])
|
|
77
|
+
return
|
|
78
|
+
err_console.print(
|
|
79
|
+
f"[red]No editor found. Set the EDITOR environment variable, e.g.:[/red]\n"
|
|
80
|
+
f" export EDITOR=nano"
|
|
81
|
+
)
|
|
82
|
+
raise typer.Exit(1)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def main(
|
|
86
|
+
target: Annotated[
|
|
87
|
+
str,
|
|
88
|
+
typer.Argument(help="Target file or glob pattern to manage feedback for"),
|
|
89
|
+
],
|
|
90
|
+
):
|
|
91
|
+
"""MarkBack: Create or view feedback for a target file."""
|
|
92
|
+
# Check if target is a glob pattern
|
|
93
|
+
if any(c in target for c in ('*', '?', '[')):
|
|
94
|
+
collect_glob(target)
|
|
95
|
+
return
|
|
96
|
+
|
|
97
|
+
target = Path(target)
|
|
98
|
+
mb_path = get_mb_path(target)
|
|
99
|
+
|
|
100
|
+
if not mb_path.exists():
|
|
101
|
+
# Create new .mb file
|
|
102
|
+
if not target.exists():
|
|
103
|
+
err_console.print(f"[red]Target file not found: {target}[/red]")
|
|
104
|
+
raise typer.Exit(1)
|
|
105
|
+
|
|
106
|
+
from .types import Record
|
|
107
|
+
record = Record(
|
|
108
|
+
source=target,
|
|
109
|
+
feedback="",
|
|
110
|
+
)
|
|
111
|
+
write_file(mb_path, [record])
|
|
112
|
+
|
|
113
|
+
open_editor(mb_path)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def cli():
|
|
117
|
+
"""Entry point for the CLI."""
|
|
118
|
+
typer.run(main)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
if __name__ == "__main__":
|
|
122
|
+
cli()
|
|
@@ -137,36 +137,61 @@ def lint_prior_exists(
|
|
|
137
137
|
return diagnostics
|
|
138
138
|
|
|
139
139
|
|
|
140
|
+
def _is_position_invalid(source_ref) -> tuple[bool, str]:
|
|
141
|
+
"""Check if a SourceRef has an invalid position range.
|
|
142
|
+
|
|
143
|
+
Returns (is_invalid, error_message).
|
|
144
|
+
Position is invalid if:
|
|
145
|
+
- end_line < start_line
|
|
146
|
+
- end_line == start_line and end_column < start_column
|
|
147
|
+
"""
|
|
148
|
+
if source_ref.start_line is None or source_ref.end_line is None:
|
|
149
|
+
return False, ""
|
|
150
|
+
|
|
151
|
+
if source_ref.end_line < source_ref.start_line:
|
|
152
|
+
return True, f"end line {source_ref.end_line} is less than start line {source_ref.start_line}"
|
|
153
|
+
|
|
154
|
+
if source_ref.end_line == source_ref.start_line:
|
|
155
|
+
if (source_ref.start_column is not None and
|
|
156
|
+
source_ref.end_column is not None and
|
|
157
|
+
source_ref.end_column < source_ref.start_column):
|
|
158
|
+
return True, f"end column {source_ref.end_column} is less than start column {source_ref.start_column} on line {source_ref.start_line}"
|
|
159
|
+
|
|
160
|
+
return False, ""
|
|
161
|
+
|
|
162
|
+
|
|
140
163
|
def lint_line_range(
|
|
141
164
|
record: Record,
|
|
142
165
|
record_idx: int,
|
|
143
166
|
) -> list[Diagnostic]:
|
|
144
|
-
"""Check if line ranges are valid (end >= start)."""
|
|
167
|
+
"""Check if line/character ranges are valid (end position >= start position)."""
|
|
145
168
|
diagnostics: list[Diagnostic] = []
|
|
146
169
|
|
|
147
|
-
# Check @source
|
|
170
|
+
# Check @source range
|
|
148
171
|
if record.source and record.source.start_line is not None:
|
|
149
|
-
|
|
172
|
+
is_invalid, error_msg = _is_position_invalid(record.source)
|
|
173
|
+
if is_invalid:
|
|
150
174
|
diagnostics.append(Diagnostic(
|
|
151
175
|
file=record._source_file,
|
|
152
176
|
line=record._start_line,
|
|
153
177
|
column=None,
|
|
154
178
|
severity=Severity.ERROR,
|
|
155
179
|
code=ErrorCode.E011,
|
|
156
|
-
message=f"Invalid
|
|
180
|
+
message=f"Invalid range in @source: {error_msg}",
|
|
157
181
|
record_index=record_idx,
|
|
158
182
|
))
|
|
159
183
|
|
|
160
|
-
# Check @prior
|
|
184
|
+
# Check @prior range
|
|
161
185
|
if record.prior and record.prior.start_line is not None:
|
|
162
|
-
|
|
186
|
+
is_invalid, error_msg = _is_position_invalid(record.prior)
|
|
187
|
+
if is_invalid:
|
|
163
188
|
diagnostics.append(Diagnostic(
|
|
164
189
|
file=record._source_file,
|
|
165
190
|
line=record._start_line,
|
|
166
191
|
column=None,
|
|
167
192
|
severity=Severity.ERROR,
|
|
168
193
|
code=ErrorCode.E011,
|
|
169
|
-
message=f"Invalid
|
|
194
|
+
message=f"Invalid range in @prior: {error_msg}",
|
|
170
195
|
record_index=record_idx,
|
|
171
196
|
))
|
|
172
197
|
|
|
@@ -17,7 +17,7 @@ from .types import (
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
# Known header keywords
|
|
20
|
-
KNOWN_HEADERS = {"uri", "source", "prior"}
|
|
20
|
+
KNOWN_HEADERS = {"uri", "by", "source", "prior"}
|
|
21
21
|
|
|
22
22
|
# Patterns
|
|
23
23
|
HEADER_PATTERN = re.compile(r"^@([a-z]+)\s+(.+)$")
|
|
@@ -145,6 +145,7 @@ def parse_string(
|
|
|
145
145
|
nonlocal pending_uri, in_content, had_blank_line
|
|
146
146
|
|
|
147
147
|
uri = current_headers.get("uri") or pending_uri
|
|
148
|
+
by = current_headers.get("by")
|
|
148
149
|
source_str = current_headers.get("source")
|
|
149
150
|
source = SourceRef(source_str) if source_str else None
|
|
150
151
|
prior_str = current_headers.get("prior")
|
|
@@ -164,6 +165,7 @@ def parse_string(
|
|
|
164
165
|
record = Record(
|
|
165
166
|
feedback=feedback,
|
|
166
167
|
uri=uri,
|
|
168
|
+
by=by,
|
|
167
169
|
source=source,
|
|
168
170
|
prior=prior,
|
|
169
171
|
content=content,
|
|
@@ -242,14 +244,16 @@ def parse_string(
|
|
|
242
244
|
line_num,
|
|
243
245
|
)
|
|
244
246
|
|
|
245
|
-
# Use any pending @uri from previous line and @prior if present
|
|
247
|
+
# Use any pending @uri from previous line and @by, @prior if present
|
|
246
248
|
uri = pending_uri or current_headers.get("uri")
|
|
249
|
+
by = current_headers.get("by")
|
|
247
250
|
prior_str = current_headers.get("prior")
|
|
248
251
|
prior = SourceRef(prior_str) if prior_str else None
|
|
249
252
|
|
|
250
253
|
record = Record(
|
|
251
254
|
feedback=feedback or "",
|
|
252
255
|
uri=uri,
|
|
256
|
+
by=by,
|
|
253
257
|
source=source,
|
|
254
258
|
prior=prior,
|
|
255
259
|
content=None,
|
|
@@ -78,8 +78,9 @@ class Diagnostic:
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
|
|
81
|
-
# Regex to parse line range from a path
|
|
82
|
-
|
|
81
|
+
# Regex to parse line/character range from a path
|
|
82
|
+
# Supports: path:line, path:line:col, path:line-line, path:line:col-line:col
|
|
83
|
+
_LINE_RANGE_PATTERN = re.compile(r'^(.+?):(\d+)(?::(\d+))?(?:-(\d+)(?::(\d+))?)?$')
|
|
83
84
|
|
|
84
85
|
|
|
85
86
|
@dataclass
|
|
@@ -89,6 +90,8 @@ class SourceRef:
|
|
|
89
90
|
is_uri: bool = False
|
|
90
91
|
start_line: Optional[int] = None
|
|
91
92
|
end_line: Optional[int] = None
|
|
93
|
+
start_column: Optional[int] = None
|
|
94
|
+
end_column: Optional[int] = None
|
|
92
95
|
_path_only: str = ""
|
|
93
96
|
|
|
94
97
|
def __post_init__(self):
|
|
@@ -102,16 +105,21 @@ class SourceRef:
|
|
|
102
105
|
self.is_uri = bool(parsed.scheme) and len(parsed.scheme) > 1
|
|
103
106
|
|
|
104
107
|
def _parse_line_range(self):
|
|
105
|
-
"""Parse optional line range from value."""
|
|
108
|
+
"""Parse optional line/character range from value."""
|
|
106
109
|
match = _LINE_RANGE_PATTERN.match(self.value)
|
|
107
110
|
if match:
|
|
108
111
|
self._path_only = match.group(1)
|
|
109
112
|
self.start_line = int(match.group(2))
|
|
110
113
|
if match.group(3):
|
|
111
|
-
self.
|
|
114
|
+
self.start_column = int(match.group(3))
|
|
115
|
+
if match.group(4):
|
|
116
|
+
self.end_line = int(match.group(4))
|
|
117
|
+
if match.group(5):
|
|
118
|
+
self.end_column = int(match.group(5))
|
|
112
119
|
else:
|
|
113
|
-
# Single line reference: start and end are the same
|
|
120
|
+
# Single line/position reference: start and end are the same
|
|
114
121
|
self.end_line = self.start_line
|
|
122
|
+
self.end_column = self.start_column
|
|
115
123
|
else:
|
|
116
124
|
self._path_only = self.value
|
|
117
125
|
|
|
@@ -122,12 +130,27 @@ class SourceRef:
|
|
|
122
130
|
|
|
123
131
|
@property
|
|
124
132
|
def line_range_str(self) -> Optional[str]:
|
|
125
|
-
"""Return formatted line range string, or None if no range."""
|
|
133
|
+
"""Return formatted line/character range string, or None if no range."""
|
|
126
134
|
if self.start_line is None:
|
|
127
135
|
return None
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
136
|
+
|
|
137
|
+
# Build start position
|
|
138
|
+
if self.start_column is not None:
|
|
139
|
+
start = f":{self.start_line}:{self.start_column}"
|
|
140
|
+
else:
|
|
141
|
+
start = f":{self.start_line}"
|
|
142
|
+
|
|
143
|
+
# Check if end is the same as start (single position)
|
|
144
|
+
if self.start_line == self.end_line and self.start_column == self.end_column:
|
|
145
|
+
return start
|
|
146
|
+
|
|
147
|
+
# Build end position
|
|
148
|
+
if self.end_column is not None:
|
|
149
|
+
end = f"-{self.end_line}:{self.end_column}"
|
|
150
|
+
else:
|
|
151
|
+
end = f"-{self.end_line}"
|
|
152
|
+
|
|
153
|
+
return f"{start}{end}"
|
|
131
154
|
|
|
132
155
|
def resolve(self, base_path: Optional[Path] = None) -> Path:
|
|
133
156
|
"""Resolve to a file path (relative paths resolved against base_path)."""
|
|
@@ -162,6 +185,7 @@ class Record:
|
|
|
162
185
|
"""A MarkBack record containing content and feedback."""
|
|
163
186
|
feedback: str
|
|
164
187
|
uri: Optional[str] = None
|
|
188
|
+
by: Optional[str] = None
|
|
165
189
|
source: Optional[SourceRef] = None
|
|
166
190
|
prior: Optional[SourceRef] = None
|
|
167
191
|
content: Optional[str] = None
|
|
@@ -195,6 +219,7 @@ class Record:
|
|
|
195
219
|
"""Convert to JSON-serializable dict."""
|
|
196
220
|
return {
|
|
197
221
|
"uri": self.uri,
|
|
222
|
+
"by": self.by,
|
|
198
223
|
"source": str(self.source) if self.source else None,
|
|
199
224
|
"prior": str(self.prior) if self.prior else None,
|
|
200
225
|
"content": self.content,
|
|
@@ -38,17 +38,21 @@ def write_record_canonical(
|
|
|
38
38
|
)
|
|
39
39
|
|
|
40
40
|
if use_compact:
|
|
41
|
-
# Compact format: @uri on
|
|
41
|
+
# Compact format: @uri, @by, @prior on own lines (if present), then @source ... <<<
|
|
42
42
|
if record.uri:
|
|
43
43
|
lines.append(f"@uri {record.uri}")
|
|
44
|
+
if record.by:
|
|
45
|
+
lines.append(f"@by {record.by}")
|
|
44
46
|
if record.prior:
|
|
45
47
|
lines.append(f"@prior {record.prior}")
|
|
46
48
|
lines.append(f"@source {record.source} <<< {record.feedback}")
|
|
47
49
|
else:
|
|
48
50
|
# Full format
|
|
49
|
-
# Headers: @uri first, then @prior, then @source
|
|
51
|
+
# Headers: @uri first, then @by, then @prior, then @source
|
|
50
52
|
if record.uri:
|
|
51
53
|
lines.append(f"@uri {record.uri}")
|
|
54
|
+
if record.by:
|
|
55
|
+
lines.append(f"@by {record.by}")
|
|
52
56
|
if record.prior:
|
|
53
57
|
lines.append(f"@prior {record.prior}")
|
|
54
58
|
if record.source:
|
|
@@ -151,7 +155,10 @@ def write_label_file(record: Record) -> str:
|
|
|
151
155
|
|
|
152
156
|
if record.uri:
|
|
153
157
|
lines.append(f"@uri {record.uri}")
|
|
154
|
-
|
|
158
|
+
|
|
159
|
+
if record.by:
|
|
160
|
+
lines.append(f"@by {record.by}")
|
|
161
|
+
|
|
155
162
|
if record.prior:
|
|
156
163
|
lines.append(f"@prior {record.prior}")
|
|
157
164
|
|