-
Notifications
You must be signed in to change notification settings - Fork 0
Ledger corrections: fix a record's wording while it keeps its id #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
39bcad2
feat(ledger): read and validate correction lines
NovusEdge 9d4fedc
feat(ledger): fold corrections into projected records
NovusEdge e1e4c21
feat(ledger): allocate corrections under the lock and refuse echoes
NovusEdge d51b4e7
feat(cli): docket correct, and show for corrections
NovusEdge 410573b
feat: check and rebase understand correction lines
NovusEdge b4b7586
style: satisfy ruff import order and unused-import lint
NovusEdge 63f2ffb
feat(context): tag corrected records and report corrections in the delta
NovusEdge b93d250
docs: document ledger corrections
NovusEdge 3d2bb2b
fix(corrections): drop no-op fields, split decision-only refusal, ski…
NovusEdge d0b6dc3
fix(cli): tighten correct's refusals, check's record count, and show'…
NovusEdge c43e18e
docket: record why rebased corrections skip the write-time refusals
NovusEdge ca50548
fix: satisfy ruff format and pyrefly on the corrections branch
NovusEdge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,7 @@ | |
| "claim", | ||
| "decision", | ||
| "question", | ||
| "correct", | ||
| "list", | ||
| "show", | ||
| "graph", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import argparse | ||
| import sys | ||
|
|
||
| from docket import corrections, env | ||
| from docket.ledger import ID_RE, LedgerError, append, parse_evidence | ||
|
|
||
| # Flags that change what a record commits to. Accepted by the parser only so | ||
| # the refusal can name supersession instead of argparse's generic error. | ||
| FIXED_FLAGS = { | ||
| "choice": "--choice", | ||
| "state": "--state", | ||
| "supports": "--supports", | ||
| "depends_on": "--depends-on", | ||
| "answers": "--answers", | ||
| "supersedes": "--supersedes", | ||
| } | ||
| CLEARABLE = ("scope", "evidence", "alternatives") | ||
| CLEAR_FLAGS = {"scope": "--scope", "evidence": "--evidence", "alternatives": "--alternative"} | ||
|
|
||
|
|
||
| def _fields(args: argparse.Namespace) -> dict: | ||
| fields: dict = {} | ||
| if args.text is not None: | ||
| fields["text"] = args.text | ||
| if args.rationale is not None: | ||
| fields["rationale"] = args.rationale | ||
| if args.scope: | ||
| fields["scope"] = args.scope | ||
| if args.evidence: | ||
| fields["evidence"] = [parse_evidence(item) for item in args.evidence] | ||
| if args.revisit is not None: | ||
| fields["revisit"] = args.revisit | ||
| if args.cost is not None: | ||
| fields["cost_if_wrong"] = args.cost | ||
| if args.pin: | ||
| fields["pinned"] = True | ||
| if args.unpin: | ||
| fields["pinned"] = False | ||
| if args.alternative: | ||
| fields["alternatives"] = args.alternative | ||
| if args.decided_by is not None: | ||
| fields["decided_by"] = args.decided_by | ||
| for name in args.clear: | ||
| if name in fields: | ||
| raise LedgerError(f"docket: --clear {name} and {CLEAR_FLAGS[name]} conflict") | ||
| fields[name] = [] | ||
| return fields | ||
|
|
||
|
|
||
| def cmd_correct(args: argparse.Namespace) -> int: | ||
| if not ID_RE.fullmatch(args.id): | ||
| print("docket: correct names a claim, decision, or question id", file=sys.stderr) | ||
| return 1 | ||
| fixed = [flag for dest, flag in FIXED_FLAGS.items() if getattr(args, dest) is not None] | ||
| if fixed: | ||
| print( | ||
| f"docket: a correction cannot change {', '.join(fixed)}; record a " | ||
| f"restatement with --supersedes {args.id} instead", | ||
| file=sys.stderr, | ||
| ) | ||
| return 1 | ||
| try: | ||
| fields = _fields(args) | ||
| if not fields: | ||
| raise LedgerError("docket: name at least one field to correct") | ||
| entry = append( | ||
| env.ledger_path(), | ||
| corrections.make( | ||
| args.id, | ||
| fields, | ||
| reason=args.reason, | ||
| author=env.resolved_author(), | ||
| session=env.session_id(), | ||
| branch=env.branch(env.project_root()), | ||
| ), | ||
| ) | ||
| except (LedgerError, OSError) as exc: | ||
| print(str(exc), file=sys.stderr) | ||
| return 1 | ||
| print(f"{entry['id']} corrects {entry['corrects']}: {', '.join(sorted(fields))}") | ||
| return 0 | ||
|
|
||
|
|
||
| def add_correct_parser(sub) -> None: | ||
| co = sub.add_parser("correct", help="fix a record's wording or metadata, keeping its id") | ||
| co.add_argument("id", help="the claim, decision, or question to correct") | ||
| co.add_argument("--text") | ||
| co.add_argument("--rationale") | ||
| co.add_argument("--scope", action="append", default=[]) | ||
| co.add_argument("--evidence", action="append", default=[]) | ||
| co.add_argument("--revisit") | ||
| co.add_argument("--cost") | ||
| pin = co.add_mutually_exclusive_group() | ||
| pin.add_argument("--pin", action="store_true") | ||
| pin.add_argument("--unpin", action="store_true") | ||
| co.add_argument("--alternative", action="append", default=[]) | ||
| co.add_argument("--decided-by") | ||
| co.add_argument( | ||
| "--clear", action="append", default=[], choices=CLEARABLE, help="set a list field to empty" | ||
| ) | ||
| co.add_argument("--reason", default="", help="why the record was wrong") | ||
| for dest, flag in FIXED_FLAGS.items(): | ||
| co.add_argument(flag, dest=dest, help=argparse.SUPPRESS) | ||
| co.set_defaults(func=cmd_correct) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: NovusEdge/docket
Length of output: 533
🏁 Script executed:
Repository: NovusEdge/docket
Length of output: 42616
🏁 Script executed:
Repository: NovusEdge/docket
Length of output: 42763
🏁 Script executed:
Repository: NovusEdge/docket
Length of output: 42361
🏁 Script executed:
Repository: NovusEdge/docket
Length of output: 42266
🏁 Script executed:
Repository: NovusEdge/docket
Length of output: 42598
🏁 Script executed:
Repository: NovusEdge/docket
Length of output: 19665
🏁 Script executed:
Repository: NovusEdge/docket
Length of output: 19665
Normalize corrected path scopes before storing them.
_fieldscopies each--scopevalue into the correction unchanged, and the correction persists that value. The ledger documentation requires path scopes to be normalized repository-relative paths. The shared matcher strips./before comparison, so the claimed mismatch inscope_strengthand feature briefs is not established. The stored value still violates the documented format.🤖 Prompt for AI Agents