From 6eb8076861ba1e23db43960344df3b0cfbd813ce Mon Sep 17 00:00:00 2001 From: Yann Hodique Date: Tue, 10 Nov 2026 17:14:29 +0100 Subject: [PATCH] fix(note): write a prompt item's label in italics where its button would go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A vault without Obsidian Shell commands settings renders no ▶ button, so a prompt item's paragraph held only ^: a dispatch marker written there started the line, CommonMark read an HTML block, not a paragraph, and the engine's parse check refused the write, leaving the pane unrecorded (#168). An item with a prompt now ends its paragraph with its button label in italics where the button goes, its own or send to , marker or not, so the paragraph never starts with ^d14 @@ -63,9 +73,11 @@ func TestParseDispatch(t *testing.T) { // one, or one in a code span, which is code, not HTML. func TestParseDispatchIgnoresOtherComments(t *testing.T) { t.Parallel() - for _, c := range []string{"", "", "", "", + for _, c := range []string{ + "", "", "", "", "", "", "", "", - "", "``"} { + "", "``", + } { src := []byte(strings.Replace(dispatchNote, "", c, 1)) n, err := Parse(src) if err != nil { @@ -153,8 +165,12 @@ func TestSetDispatch(t *testing.T) { if out, err = SetDispatch(n, src, "d12", Dispatch{}); err != nil || string(out) != dispatchNote { t.Errorf("no marker to remove: %v\n%s", err, out) } - for _, bad := range []Dispatch{{Pane: "a b", Workspace: "/x"}, {Pane: "p", Workspace: "/a b"}, - {Pane: "p", Workspace: "/a-->"}, {Pane: "p", Workspace: "relative"}} { + for _, bad := range []Dispatch{ + {Pane: "a b", Workspace: "/x"}, + {Pane: "p", Workspace: "/a b"}, + {Pane: "p", Workspace: "/a-->"}, + {Pane: "p", Workspace: "relative"}, + } { if _, err := SetDispatch(n, src, "d12", bad); err == nil { t.Errorf("%+v: no error", bad) } @@ -164,6 +180,71 @@ func TestSetDispatch(t *testing.T) { } } +// TestSetDispatchOnBareID: a marker written on an item whose paragraph holds only ^ +// would start the paragraph, and CommonMark would read the line as an HTML block, not a +// paragraph: the item's ▶ label is written in italics before the marker, where its button +// would go, and the write is refused when there is no label to write (#168). +func TestSetDispatchOnBareID(t *testing.T) { + t.Parallel() + src := []byte(dispatchNote) + n, err := Parse(src) + if err != nil { + t.Fatal(err) + } + d := Dispatch{Pane: "w2:p1", Workspace: "/ws/o/r/issue-12"} + out, err := SetDispatch(n, src, "d15", d) + if err != nil { + t.Fatal(err) + } + want := strings.Replace(dispatchNote, "\n^d15\n", + "\n*send to r* ^d15\n", 1) + if string(out) != want { + t.Errorf("bare ^d15:\n%s", out) + } + if _, err = Parse(out); err != nil { + t.Errorf("the note no longer parses: %v", err) + } + n, _ = Parse(src) + if _, err = SetDispatch(n, src, "d16", d); err == nil { + t.Error("no prompt, no prose, no label: no error") + } +} + +// TestSetDispatchMatchesRender: on an item with a prompt and nothing else, SetDispatch and +// the renderer write the same paragraph, marker and all (#168). +func TestSetDispatchMatchesRender(t *testing.T) { + t.Parallel() + nob := testRenderer + nob.CommandID = "" + d := Dispatch{Pane: "w1:p1", Workspace: "/ws/o/r/issue-1"} + item := func(dispatch bool) string { + u := ItemUnit{ + ID: "a", Icon: IconTodo, Heading: true, Title: "A", + Button: "send to r", Prompt: &PromptUnit{To: "r", Body: "go"}, + } + if dispatch { + u.Dispatch = &d + } + b, err := nob.Item(u) + if err != nil { + t.Fatal(err) + } + return string(b) + } + src := []byte("# Worklog — 2026-10-18\n\n**09:00 UTC:** x.\n\n## ⬜ o/r\n\n### ⬜ What remains\n\n#### ⬜ Agent queue\n\n" + item(false)) + n, err := Parse(src) + if err != nil { + t.Fatal(err) + } + out, err := SetDispatch(n, src, "a", d) + if err != nil { + t.Fatal(err) + } + if want := strings.Replace(string(src), item(false), item(true), 1); string(out) != want { + t.Errorf("SetDispatch:\n%s\nwant\n%s", out, want) + } +} + // TestItemsByRef finds work items by the ref link leading their title, an issue or a PR, // whatever the link's label. func TestItemsByRef(t *testing.T) { @@ -207,8 +288,10 @@ func TestRenderDispatch(t *testing.T) { t.Errorf("list form %q", list) } for _, body := range []string{"", "Some prose."} { - heading, err := testRenderer.Item(ItemUnit{ID: "b", Icon: IconInProgress, Title: "heading", Heading: true, Body: body, - Prompt: &PromptUnit{To: "r", Body: "go"}, Button: "send to r", Dispatch: d}) + heading, err := testRenderer.Item(ItemUnit{ + ID: "b", Icon: IconInProgress, Title: "heading", Heading: true, Body: body, + Prompt: &PromptUnit{To: "r", Body: "go"}, Button: "send to r", Dispatch: d, + }) if err != nil { t.Fatal(err) } diff --git a/internal/note/fields.go b/internal/note/fields.go index 904a536..c7174f9 100644 --- a/internal/note/fields.go +++ b/internal/note/fields.go @@ -21,21 +21,21 @@ const ( // Renderer.Item), and the title they leave, as written. A list item's are read from the end of its // title line before its sent status and summary: the tier the code span ending it, the route the // one ending what is left, the cost what follows its first ` · `, which no title holds. A ##### -// item's cost, route and tier are its body's last sentences, before its button, dispatch marker -// and `^`; block is its paragraph. +// item's cost, route and tier are its body's last sentences, before its button, its label in +// italics, dispatch marker and `^`; block is its paragraph. func (p *parser) fields(it *Item, block ast.Node) { head, _ := SplitSummary(it.Title) if it.Sent != nil { head = it.Sent.Title } if it.Heading { - end := it.idAt - if it.Dispatch != nil { - end = min(end, it.marker.Start) - } + end := it.bodyEnd() if l := p.buttonLink(block); l != nil { end = min(end, l.Pos()) } + if it.labelAt >= 0 { + end = min(end, it.labelAt) + } body := strings.TrimRight(string(p.src[block.Lines().At(0).Start:end]), " \t\r\n") rest, tier := cutField(body, tierMark, ".") rest, route := cutField(rest, routeMark, ".") diff --git a/internal/note/item_test.go b/internal/note/item_test.go index fe95465..ec21db6 100644 --- a/internal/note/item_test.go +++ b/internal/note/item_test.go @@ -27,6 +27,12 @@ Unblocks #15. > [!prompt]- Prompt sent to r > ` + "```herdr-prompt id=store to=r\n> /grill-with-docs\n> ```\n" + ` +##### ⬜ send the canary + +*send to r* ^canary-send + +> [!prompt]- Prompt sent to r +> ` + "```herdr-prompt id=canary-send to=r\n> /grill-with-docs\n> ```\n" + ` - ⬜ [#16](https://github.com/o/r/issues/16): drop IE11, or keep it? ^ie11 - a step @@ -49,11 +55,16 @@ func TestItemHead(t *testing.T) { for _, w := range []struct { id, head, icon, title, button string }{ - {"store", "##### ⬜ [#14](https://github.com/o/r/issues/14): which store?\n", "⬜", - "[#14](https://github.com/o/r/issues/14): which store?", "grill in r"}, - {"ie11", "- ⬜ [#16](https://github.com/o/r/issues/16): drop IE11,\n or keep it? ^ie11\n", "⬜", - "[#16](https://github.com/o/r/issues/16): drop IE11, or keep it?", ""}, + { + "store", "##### ⬜ [#14](https://github.com/o/r/issues/14): which store?\n", "⬜", + "[#14](https://github.com/o/r/issues/14): which store?", "grill in r", + }, + { + "ie11", "- ⬜ [#16](https://github.com/o/r/issues/16): drop IE11,\n or keep it? ^ie11\n", "⬜", + "[#16](https://github.com/o/r/issues/16): drop IE11, or keep it?", "", + }, {"nested", " - 🔄 nested — PR up ^nested\n", "🔄", "nested — PR up", ""}, + {"canary-send", "##### ⬜ send the canary\n", "⬜", "send the canary", "send to r"}, } { it := n.Item(w.id) if it == nil { @@ -85,25 +96,33 @@ func TestItemFields(t *testing.T) { t.Parallel() d := &Dispatch{Pane: "w1:p3", Workspace: "/ws/o/r/issue-14"} items := []ItemUnit{ - {ID: "store", Icon: IconInProgress, Heading: true, Repo: "o/r", Ref: Ref{Repo: "o/r", N: 14}, Title: "which store?", + { + ID: "store", Icon: IconInProgress, Heading: true, Repo: "o/r", Ref: Ref{Repo: "o/r", N: 14}, Title: "which store?", Body: "Unblocks #15.", Cost: "10 min", Route: "/grill-with-docs", Summary: "grilling", Dispatch: d, - Button: "grill in r", Prompt: &PromptUnit{To: "r", Body: "/grill-with-docs"}}, + Button: "grill in r", Prompt: &PromptUnit{To: "r", Body: "/grill-with-docs"}, + }, {ID: "route-only", Icon: IconTodo, Heading: true, Title: "X", Route: "/triage"}, {ID: "cost-only", Icon: IconTodo, Heading: true, Title: "Y", Body: "Two lines\nof prose.", Cost: "1.5 h"}, {ID: "prose", Icon: IconTodo, Heading: true, Title: "Z", Body: "Done in 5 min."}, - {ID: "login", Icon: IconInReview, Repo: "o/r", Ref: Ref{Repo: "acme/IaC", N: 7}, Title: "login form", - Cost: "20 min", Route: "/implement", Summary: "PR up", Dispatch: d}, + { + ID: "login", Icon: IconInReview, Repo: "o/r", Ref: Ref{Repo: "acme/IaC", N: 7}, Title: "login form", + Cost: "20 min", Route: "/implement", Summary: "PR up", Dispatch: d, + }, {ID: "cost-line", Icon: IconTodo, Title: "a, b", Cost: "5 min"}, {ID: "route-line", Icon: IconTodo, Title: "c", Route: "/implement"}, {ID: "bare", Icon: IconTodo, Title: "plain"}, } - sent := []ItemUnit{{ID: "grant", Icon: IconTodo, Repo: "o/r", Ref: Ref{Repo: "acme/IaC", N: 8}, Title: "grant", - Cost: "5 min", Route: "/implement", Sent: &SentUnit{To: "IaC", Status: SentAcked, Note: "[#9](u)"}}} - src, err := testRenderer.Note(Day{Date: "2026-10-18", Status: StatusUnit{Time: "09:30", Text: "open."}, + sent := []ItemUnit{{ + ID: "grant", Icon: IconTodo, Repo: "o/r", Ref: Ref{Repo: "acme/IaC", N: 8}, Title: "grant", + Cost: "5 min", Route: "/implement", Sent: &SentUnit{To: "IaC", Status: SentAcked, Note: "[#9](u)"}, + }} + src, err := testRenderer.Note(Day{ + Date: "2026-10-18", Status: StatusUnit{Time: "09:30", Text: "open."}, Projects: []ProjectUnit{{Icon: IconTodo, Repo: "o/r", Remains: IconTodo, Buckets: []BucketUnit{ {Icon: IconTodo, Name: "Decisions for you", Items: items}, {Icon: IconTodo, Name: SentBucket, Items: sent}, - }}}}) + }}}, + }) if err != nil { t.Fatal(err) } diff --git a/internal/note/note.go b/internal/note/note.go index 8f24d99..a30fd88 100644 --- a/internal/note/note.go +++ b/internal/note/note.go @@ -203,7 +203,7 @@ type Item struct { Title string // the source after the icon, its lines joined by one space, without the `^` or a list item's dispatch marker Bare string // its title as item_upsert takes it: Title without its ref link, cost, route, tier, sent status and summary Heading bool - Button string // a ##### item's ▶ label, after the ▶; "" without a button + Button string // a ##### item's ▶ label, after the ▶ or, in italics, where its button would go on a vault with no Shell commands id; "" with neither Prompt *Prompt Dispatch *Dispatch // where task_dispatch started an agent on it; nil when it has no marker Sent *Sent // in *Sent to other repos*, its sent status; nil without one @@ -212,9 +212,10 @@ type Item struct { Route string // the next skill that moves it, as `/implement`; "" without one Tier string // the class of its work, which routes its prompts (ADR 0011), as `design`; "" without one - idAt int // the offset of the `^` of its `^` - marker Span // its dispatch marker's own bytes, when it has one - lead string // its title as written before its cost, route, tier, sent status and summary + idAt int // the offset of the `^` of its `^` + marker Span // its dispatch marker's own bytes, when it has one + labelAt int // the offset of its italic label's first `*`; -1 when it has none. Only a ##### item's is set or read + lead string // its title as written before its cost, route, tier, sent status and summary } // PromptFence is the info string's first word on a prompt block: the name the renderer writes. diff --git a/internal/note/parse.go b/internal/note/parse.go index d0ff99c..e542d08 100644 --- a/internal/note/parse.go +++ b/internal/note/parse.go @@ -563,8 +563,8 @@ func (p *parser) itemParagraph(para *ast.Paragraph) *Item { } it.ID = id it.End = p.nodeEnd(para) - it.Button = p.buttonLabel(para) p.dispatch(it, para) + it.Button, it.labelAt = p.buttonLabel(it, para) p.sent(it) p.fields(it, para) p.addItem(it) @@ -572,14 +572,28 @@ func (p *parser) itemParagraph(para *ast.Paragraph) *Item { return it } -// buttonLabel is the label after the ▶ of a paragraph's button: a link to the Shell commands -// plugin reading `▶