Notify link=: a stage's public/ file sets the phone tap target

A stage's notify block may name `link=<pattern>` (validated like `open=`).
When the hook fires, the newest public/ match is read (at most 4 KiB); its
first non-empty line, if an absolute http(s) URL ntfy accepts as a click,
becomes the ntfy Click and the app notification click, with the run kept
as the app's run action and ntfy's browser view. A missing file or invalid
URL keeps today's tap target and is noted on the receipt diagnostic.

Android opens such an http(s) click in the browser (after clearing the
notification) instead of handing it to Flutter as a route.
This commit is contained in:
2026-12-02 12:20:22 +00:00
parent 26b1c00094
commit f5f31b7bcd
12 changed files with 355 additions and 55 deletions
+55 -29
View File
@@ -76,6 +76,19 @@ func (r *runner) notifyStep(id int64, name, workspace string, policy *protocol.N
// the first ntfy publication; artifacts stay ntfy attachments.
appEvent, appKind := stageNotification(event, step.Target)
appArtifact, appPreview := r.resolveNotificationArtifact(id, step.Sequence, policy.Open)
// A `link=` file decides the tap target (ntfy and app alike); the run stays
// reachable through the app's run action and ntfy's browser view.
click := runAttentionClick(id)
link, linkDiagnostic := r.resolveNotificationLink(id, policy.Link)
if link != "" {
click = link
}
note := func(diagnostic string) string {
if linkDiagnostic == "" || diagnostic == "" {
return diagnostic + linkDiagnostic
}
return diagnostic + "; " + linkDiagnostic
}
recorded := false
ntfyOn := ntfyEnabled(ctx, r.settingsStore())
send := func(filename string, data []byte) {
@@ -86,20 +99,25 @@ func (r *runner) notifyStep(id int64, name, workspace string, policy *protocol.N
receipt := &receipts[len(receipts)-1]
if !recorded {
recorded = true
r.notes.record(ctx, runNotificationRecord(id, step.Sequence, appEvent, appKind, title, summary, appArtifact, appPreview))
record := runNotificationRecord(id, step.Sequence, appEvent, appKind, title, summary, appArtifact, appPreview)
if link != "" {
record.Click, record.RunClick = link, runAttentionClick(id)
}
r.notes.record(ctx, record)
}
if !ntfyOn {
receipt.Status = "sent"
receipt.Diagnostic = "ntfy disabled; delivered to app clients only"
receipt.Diagnostic = note("ntfy disabled; delivered to app clients only")
persist()
return
}
result, err := ntfyPublish(ctx, "system", title, summary, filename, data, runAttentionClick(id), runAttentionViews(id)...)
result, err := ntfyPublish(ctx, "system", title, summary, filename, data, click, runAttentionViews(id)...)
if err != nil {
receipt.Status = "failed"
receipt.Diagnostic = err.Error()
receipt.Diagnostic = note(err.Error())
} else {
receipt.Status = "sent"
receipt.Diagnostic = note("")
receipt.MessageID, _ = result["message_id"].(string)
receipt.AttachmentURL, _ = result["attachment_url"].(string)
}
@@ -560,6 +578,36 @@ func notificationClick(runID int64, sequence int, artifact *protocol.Notificatio
// resolveNotificationArtifact selects only files in the run's shared public/.
// It is deliberately independent of the ntfy attachment policy.
func (r *runner) resolveNotificationArtifact(runID int64, sequence int, pattern string) (*protocol.NotificationArtifact, string) {
selected := r.publicNotificationFile(runID, pattern)
if selected == "" {
return nil, ""
}
full := filepath.Join(r.artifactsRoot, fmt.Sprint(runID), "public", filepath.FromSlash(selected))
file, err := os.Open(full)
if err != nil {
return nil, ""
}
defer file.Close()
data, err := io.ReadAll(io.LimitReader(file, 64<<10))
if err != nil {
return nil, ""
}
media := mime.TypeByExtension(filepath.Ext(selected))
if media == "" {
sample := data
if len(sample) > 512 {
sample = sample[:512]
}
media = http.DetectContentType(sample)
}
a := &protocol.NotificationArtifact{RunID: runID, Sequence: sequence, Path: selected, Name: filepath.Base(selected), URL: artifactURL(runID, sequence, "public/"+selected), MediaType: media}
return a, notificationPreview(data, media, filepath.Ext(selected))
}
// publicNotificationFile picks a regular, non-hidden, non-symlinked file in the
// run's shared public/ as a slash path: the most recently modified match of
// pattern, or without a pattern the only file there. "" when none qualifies.
func (r *runner) publicNotificationFile(runID int64, pattern string) string {
root := filepath.Join(r.artifactsRoot, fmt.Sprint(runID), "public")
type candidate struct {
path string
@@ -602,11 +650,8 @@ func (r *runner) resolveNotificationArtifact(runID int64, sequence int, pattern
candidates = append(candidates, candidate{rel, info})
return nil
})
if pattern == "" && len(candidates) != 1 {
return nil, ""
}
if len(candidates) == 0 {
return nil, ""
if (pattern == "" && len(candidates) != 1) || len(candidates) == 0 {
return ""
}
selected := candidates[0]
for _, c := range candidates[1:] {
@@ -614,26 +659,7 @@ func (r *runner) resolveNotificationArtifact(runID int64, sequence int, pattern
selected = c
}
}
full := filepath.Join(root, filepath.FromSlash(selected.path))
file, err := os.Open(full)
if err != nil {
return nil, ""
}
defer file.Close()
data, err := io.ReadAll(io.LimitReader(file, 64<<10))
if err != nil {
return nil, ""
}
media := mime.TypeByExtension(filepath.Ext(selected.path))
if media == "" {
sample := data
if len(sample) > 512 {
sample = sample[:512]
}
media = http.DetectContentType(sample)
}
a := &protocol.NotificationArtifact{RunID: runID, Sequence: sequence, Path: selected.path, Name: filepath.Base(selected.path), URL: artifactURL(runID, sequence, "public/"+selected.path), MediaType: media}
return a, notificationPreview(data, media, filepath.Ext(selected.path))
return selected.path
}
var markdownSyntax = regexp.MustCompile(`[*_` + "`" + `>#\[\]()]`)