Default a bare-link draft to the freeform template

A third of the freeform notes in the backlog are nothing but a pasted
URL, and the capture screen still offered them the seven-step spec
stepper. NoteTemplate.forDraft now picks `blank` for a draft that is
only links, so filing a link costs one paste.

The switch runs on every raw keystroke and is lossless in both
directions — it only ever fires while the raw body is the source, so
there are no section values to convert. Type prose alongside the link
and the spec template comes straight back. An explicit choice from the
dropdown or the guided wizard sets _templatePickedByUser and is never
overridden.

isBareLink is deliberately strict: one word of context ("read this
https://…") means the note has prose in it and keeps the spec template.

Verified on the phone (release APK, adb install -r): typing a bare URL
flips Template to Blank and drops the Guided segment; appending " port
this to Dart" restores LLM design spec and Guided. Test note created by
that check was deleted and the deletion synced (back to 49 notes).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Krzysztof Rudnicki 2026-07-26 22:13:26 +02:00
parent a874e09b65
commit 72c5c21d9a
5 changed files with 131 additions and 2 deletions

View File

@ -186,7 +186,12 @@ the *only* new section and stops there.
The leverage is therefore not at capture time:
- **Capture stays cheap.** The evidence supports fewer fields, not more. Median
opening prompt is 363 chars and that is fine.
opening prompt is 363 chars and that is fine. Implemented: a draft that is
nothing but a pasted link now selects the freeform `blank` template
automatically (`NoteTemplate.forDraft`), so filing a link costs one paste
instead of a seven-step stepper — a third of the freeform backlog is exactly
that. Typing any prose alongside the link restores the spec template, and an
explicit pick from the dropdown or wizard is never overridden.
- **Per-repo constants belong in that repo's `CLAUDE.md`, written once** — never
re-typed per note. `verify` exists for the exception, not the rule.
- **The real cost centre is the turn-24 fork**, which no prompt could have

View File

@ -192,6 +192,28 @@ class NoteTemplate {
/// The default template applied to new notes.
static const NoteTemplate defaultTemplate = llmDesignSpec;
/// The template a *draft* of [text] should be authored with.
///
/// A bare link gets [blank]: a third of the freeform notes in the backlog are
/// nothing but a pasted URL, and walking a seven-step spec stepper to file a
/// link is pure friction. Everything else keeps [defaultTemplate].
static NoteTemplate forDraft(String text) =>
isBareLink(text) ? blank : defaultTemplate;
}
/// Matches a single `http(s)://…` token.
final RegExp _linkPattern = RegExp(r'^https?://\S+$');
/// Whether [text] is nothing but one or more links.
///
/// Deliberately strict: one word of context ("read this https://…") means the
/// note has prose in it and is no longer a bare link.
bool isBareLink(String text) {
final tokens = text.trim().split(RegExp(r'\s+'))
..removeWhere((t) => t.isEmpty);
if (tokens.isEmpty) return false;
return tokens.every(_linkPattern.hasMatch);
}
/// Result of parsing stored text against a template.

View File

@ -115,6 +115,10 @@ class _NoteEditorState extends State<NoteEditor> {
/// One controller per structured section (keyed by section key).
final Map<String, TextEditingController> _section = {};
/// Set once the user picks a template themselves, which stops
/// [_retemplateDraft] from overriding that choice as they keep typing.
bool _templatePickedByUser = false;
/// Single field used for the freeform [NoteTemplate.blank] body and for raw
/// mode of a structured template.
final TextEditingController _body = TextEditingController();
@ -236,6 +240,24 @@ class _NoteEditorState extends State<NoteEditor> {
void _emit() => widget.onChanged(_currentText());
/// Re-picks the draft's template from what has been typed so far, unless the
/// user has chosen one explicitly.
///
/// Only ever runs while the raw body *is* the source, so there are no section
/// values to convert and the switch is lossless in both directions: paste a
/// link and Guided drops away, write a sentence under it and the spec
/// template comes back.
void _retemplateDraft() {
if (_templatePickedByUser || !_rawSource) return;
final next = NoteTemplate.forDraft(_body.text);
if (next.id == _template.id) return;
setState(() {
_template = next;
_currentStep = 0;
_mode = _resolveMode(_mode);
});
}
void _switchTemplate(NoteTemplate next) {
if (next.id == _template.id) return;
final text = _currentText();
@ -306,6 +328,8 @@ class _NoteEditorState extends State<NoteEditor> {
/// is unchanged, which would skip flipping out of the wizard here.
void _enterGuidedWithTemplate(NoteTemplate template) {
final text = _currentText();
// Choosing a template in the wizard is as explicit as using the dropdown.
_templatePickedByUser = true;
setState(() {
_template = template;
_currentStep = 0;
@ -363,6 +387,7 @@ class _NoteEditorState extends State<NoteEditor> {
],
onChanged: (id) {
if (id == null) return;
_templatePickedByUser = true;
_switchTemplate(NoteTemplate.all.firstWhere((t) => t.id == id));
},
),
@ -538,7 +563,10 @@ class _NoteEditorState extends State<NoteEditor> {
border: InputBorder.none,
hintText: 'Write your idea…',
),
onChanged: (_) => _emit(),
onChanged: (_) {
_retemplateDraft();
_emit();
},
),
),
);

View File

@ -101,6 +101,57 @@ void main() {
expect(find.text('Next'), findsNothing);
});
testWidgets('pasting a bare link drops the draft to the blank template', (
tester,
) async {
await pumpEditor(
tester,
initialTemplate: spec,
initialMode: NoteEditorMode.raw,
);
expect(find.text('LLM design spec'), findsOneWidget);
await tester.enterText(
find.byType(TextField).first,
'https://example.com/x',
);
await tester.pump();
// Freeform now, so there is no seven-step stepper to walk for a link.
expect(find.text('Blank'), findsOneWidget);
expect(find.text('Guided'), findsNothing);
// Adding prose puts the spec template back — lossless in both directions.
await tester.enterText(
find.byType(TextField).first,
'https://example.com/x — port this to Dart',
);
await tester.pump();
expect(find.text('LLM design spec'), findsOneWidget);
expect(find.text('Guided'), findsOneWidget);
});
testWidgets('an explicit template choice survives further typing', (
tester,
) async {
await pumpEditor(
tester,
initialTemplate: spec,
initialMode: NoteEditorMode.raw,
);
await tester.tap(find.text('LLM design spec'));
await tester.pumpAndSettle();
await tester.tap(find.text('Blank').last);
await tester.pumpAndSettle();
expect(find.text('Blank'), findsOneWidget);
// Prose would normally re-select the spec template; an explicit pick wins.
await tester.enterText(find.byType(TextField).first, 'build a thing');
await tester.pump();
expect(find.text('Blank'), findsOneWidget);
});
testWidgets('switching to View renders the note as Markdown', (tester) async {
await pumpEditor(
tester,

View File

@ -140,6 +140,29 @@ void main() {
});
});
group('bare-link drafts', () {
test('isBareLink accepts only link-only text', () {
expect(isBareLink('https://example.com/a'), isTrue);
expect(isBareLink(' http://example.com '), isTrue);
// Several pasted links are still just links.
expect(isBareLink('https://a.example\nhttps://b.example'), isTrue);
// One word of context means the note has prose in it.
expect(isBareLink('read this https://example.com'), isFalse);
expect(isBareLink('https://example.com — do the thing'), isFalse);
expect(isBareLink('just a title'), isFalse);
expect(isBareLink(''), isFalse);
expect(isBareLink(' \n '), isFalse);
// Not a URL scheme we recognise.
expect(isBareLink('ftp://example.com/x'), isFalse);
});
test('forDraft picks blank for a link and the spec otherwise', () {
expect(NoteTemplate.forDraft('https://example.com').id, 'blank');
expect(NoteTemplate.forDraft('build a thing').id, 'llm-design-spec');
expect(NoteTemplate.forDraft('').id, 'llm-design-spec');
});
});
group('noteTitle', () {
test('strips the leading # from a heading', () {
expect(noteTitle('# My title\n\n## what\nx'), 'My title');