todo-app/lib/cli/note_lookup.dart
Krzysztof kuhy Rudnicki 9349747629
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Repo tasks: repo/done_check/by/evidence fields, filter chips, CLI close/list/search
Four optional note fields (repo, done_check, by, evidence) in the crdt_sync
record, written only when set, so editing a plain idea stays wire-identical
to v3 (note_repository_sync_compat_test). The log is schemaless: no stored
schema version; the legacy sqlite reader stays at v3.

NoteFilter gains a sources facet (ideas / every repo task / one repo);
search also matches the repo. The notes list shows only open ideas by
default (no badge); the filter sheet adds Ideas, Repo tasks and one chip
per repo when repo tasks exist. The per-note sheet shows the task fields
read-only. BACKLOG.md markers carry the new attributes, entity-escaped.

CLI: --repo --done-check --by on add, --close <id> --evidence (refused
without), --list [--repo] [--status], --search, and every id flag takes a
unique 8-character prefix. --list prints id8, status, priority, repo, title.

install_hooks.sh: the wrapper finds pre-commit's generated hook next to
itself, so commits from a git worktree (where .git is a file) work.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 08:26:26 +01:00

48 lines
1.4 KiB
Dart

import 'package:todo/cli/cli_args.dart';
import 'package:todo/data/note.dart';
const _minPrefix = 8;
/// No note, or more than one, matches an id argument; [message] says which.
class NoteLookupError extends FormatException {
NoteLookupError._(super.message);
@override
String toString() => message;
}
/// The note with id [ref], else the only one whose id starts with [ref].
Note findNote(Iterable<Note> notes, String ref) {
final exact = notes.where((n) => n.id == ref).firstOrNull;
if (exact != null) return exact;
if (ref.length < _minPrefix) {
throw NoteLookupError._(
'no live note with id $ref (an id prefix needs at least '
'$_minPrefix characters)',
);
}
final matches = notes.where((n) => n.id.startsWith(ref)).toList();
if (matches.isEmpty) throw NoteLookupError._('no live note with id $ref');
if (matches.length > 1) {
throw NoteLookupError._(
'id prefix $ref matches ${matches.length} notes; give more of the id:\n'
'${matches.map((n) => ' ${n.id} ${_title(n)}').join('\n')}',
);
}
return matches.single;
}
/// `<8-char id>\t<status>\t<priority>\t<repo or ->\t<title>`.
String listLine(Note note) => [
if (note.id.length <= _minPrefix)
note.id
else
note.id.substring(0, _minPrefix),
CliArgs.statusName(note.status),
note.priority.name,
note.repo ?? '-',
_title(note),
].join('\t');
String _title(Note note) => note.text.split('\n').first;