Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,17 @@ read from the end the same way. A body ending with a bare `<cost>.`, as written
`Cost:` marker, reads as prose: the item has no cost until it is rewritten. Each is absent
when the item has none.

A `#####` item with a prompt ends its paragraph with the ▶ button that sends it,
`[▶ <label>](…)`, and its `^<item-id>` after it on the same line; the label is read back
after the ▶.
On a vault with no Obsidian Shell commands settings ([§9.1]) there is no button to build,
and the item writes the same label in italics where the button would go, `*send to <to>*`
or its own label. Either way the paragraph never starts with the `<!--` of a dispatch
marker, which CommonMark would read as an HTML block rather than the item's paragraph:
the italic label is read back as the item's too, a marker recorded on an item whose
paragraph holds only `^<item-id>` writes the label before itself, and the next render with
a command id writes the button again.

The tier is the class of the item's work, one of the closed list in the worklog skill's tier
table ([ADR 0011]). It routes the item's prompts to a harness through config; the note never
names the harness. A prompt led by a route's command, `/<name>`, reaches a harness of kind
Expand Down
30 changes: 28 additions & 2 deletions internal/note/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ func (r Renderer) DispatchMarker(d Dispatch) string {
return m + " " + markerClose
}

// bodyEnd is where a ##### item's paragraph trailer starts: its dispatch marker, when it
// has one, else its `^<id>`.
func (it *Item) bodyEnd() int {
if it.Dispatch != nil {
return min(it.idAt, it.marker.Start)
}
return it.idAt
}

// Check reports why d cannot be written as a marker that parses back to d.
func (d Dispatch) Check() error {
if d.Pane == "" && d.Workspace == "" {
Expand Down Expand Up @@ -83,8 +92,11 @@ func parseMarker(raw string) (d Dispatch, ok bool) {
}

// SetDispatch records d on work item id of n, parsed from src, and returns the new source: it
// replaces the item's marker, or writes one just before its `^<id>`. An empty d removes the
// marker, with the space written after it. Nothing else changes.
// replaces the item's marker, or writes one just before its `^<id>`. On an item whose
// paragraph holds only `^<id>` it writes the item's ▶ label in italics first, where its button
// would go (Renderer.Item), so the paragraph never starts with the marker, which CommonMark
// would read as an HTML block. An empty d removes the marker, with the space written after it.
// Nothing else changes.
func SetDispatch(n *Note, src []byte, id string, d Dispatch) ([]byte, error) {
it := n.Item(id)
if d == (Dispatch{}) && it != nil {
Expand All @@ -107,5 +119,19 @@ func SetDispatch(n *Note, src []byte, id string, d Dispatch) ([]byte, error) {
if it.Dispatch != nil {
return Replace(src, it.marker, []byte(marker)), nil
}
if it.Heading && isBlank(string(src[it.Head.End:it.idAt])) {
to := ""
if it.Prompt != nil {
to = it.Prompt.To
}
if label := sendLabel(it.Button, to); label != "" {
ital, err := Renderer{}.italic(label)
if err != nil {
return nil, fmt.Errorf("^%s: %w", id, err)
}
return Insert(src, it.idAt, []byte(ital+" "+marker+" ")), nil
}
return nil, fmt.Errorf("^%s: its paragraph holds only ^%s, and a marker before it would read as an HTML block, not the item's paragraph: give the item a body or a prompt", id, id)
}
return Insert(src, it.idAt, []byte(marker+" ")), nil
}
95 changes: 89 additions & 6 deletions internal/note/dispatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ Port it.

> [!prompt]- Prompt sent to r
> ` + "```herdr-prompt id=d13 to=r\n> /implement\n> ```\n" + `
##### ⬜ [#15](https://github.com/o/r/issues/15): canary

^d15

> [!prompt]- Prompt sent to r
> ` + "```herdr-prompt id=d15 to=r\n> /implement\n> ```\n" + `
##### ⬜ [#16](https://github.com/o/r/issues/16): bare

^d16

##### 🔄 [#14](https://github.com/o/r/issues/14): which store?

Working on it. <!-- qm pane=w1:p5 ws=/ws/o/r/issue-14 --> ^d14
Expand Down Expand Up @@ -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{"<!-- a note -->", "<!-- qm -->", "<!-- qm pane= -->", "<!-- qm pane=p ws=/x extra -->",
for _, c := range []string{
"<!-- a note -->", "<!-- qm -->", "<!-- qm pane= -->", "<!-- qm pane=p ws=/x extra -->",
"<!-- qm pane=p pane=q ws=/x -->", "<!-- qmx pane=p ws=/x -->", "<!-- qm ws=/x ws=/y -->", "<!-- qm pane= ws=/x -->",
"<!-- qm pane=p ws=/x tab=t -->", "`<!-- qm pane=p ws=/x -->`"} {
"<!-- qm pane=p ws=/x tab=t -->", "`<!-- qm pane=p ws=/x -->`",
} {
src := []byte(strings.Replace(dispatchNote, "<!-- qm pane=w1:p3 ws=/ws/o/r/issue-11 -->", c, 1))
n, err := Parse(src)
if err != nil {
Expand Down Expand Up @@ -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)
}
Expand All @@ -164,6 +180,71 @@ func TestSetDispatch(t *testing.T) {
}
}

// TestSetDispatchOnBareID: a marker written on an item whose paragraph holds only ^<id>
// 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* <!-- qm pane=w2:p1 ws=/ws/o/r/issue-12 --> ^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) {
Expand Down Expand Up @@ -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)
}
Expand Down
12 changes: 6 additions & 6 deletions internal/note/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 `^<id>`; 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 `^<id>`; 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, ".")
Expand Down
43 changes: 31 additions & 12 deletions internal/note/item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
9 changes: 5 additions & 4 deletions internal/note/note.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ type Item struct {
Title string // the source after the icon, its lines joined by one space, without the `^<id>` 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
Expand All @@ -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 `^<id>`
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 `^<id>`
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.
Expand Down
30 changes: 22 additions & 8 deletions internal/note/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,23 +563,37 @@ 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)
p.bucket.Items = append(p.bucket.Items, it)
return it
}

// buttonLabel is the label after the ▶ of a paragraph's button: a link to the Shell commands
// plugin reading `▶ <label>`. It is "" when the paragraph has none.
func (p *parser) buttonLabel(para *ast.Paragraph) string {
l := p.buttonLink(para)
if l == nil {
return ""
// buttonLabel is the ▶ label of a ##### item's paragraph, and where an italic label
// starts: the text after the ▶ of a link to the Shell commands plugin, or, without one,
// the label written in italics where the button would go (Renderer.Item). at is -1
// without an italic label.
func (p *parser) buttonLabel(it *Item, para *ast.Paragraph) (label string, at int) {
if l := p.buttonLink(para); l != nil {
return strings.TrimPrefix(p.inlineText(l), buttonMark), -1
}
return strings.TrimPrefix(p.inlineText(l), buttonMark)
return p.italicLabel(it, para)
}

// italicLabel reads the label written in italics where a work item's ▶ button would go,
// on a vault with no Shell commands id: `*<label>*` alone on the last line of its
// paragraph, before its dispatch marker and `^<id>`. at is where the label's first `*`
// starts, -1 when the last line is not a label.
func (p *parser) italicLabel(it *Item, para *ast.Paragraph) (label string, at int) {
last := para.Lines().At(para.Lines().Len() - 1)
line := bytes.TrimRight(p.src[last.Start:it.bodyEnd()], " \t")
if len(line) < 2 || line[0] != '*' || line[len(line)-1] != '*' || bytes.ContainsRune(line[1:len(line)-1], '*') {
return "", -1
}
return string(line[1 : len(line)-1]), last.Start
}

// buttonLink is the first of a block's inlines that is a button: a link to the Shell commands
Expand Down
Loading