Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

fix(computer): publish the receipt of a step that creates a Task

LeoXing74a59c5bf9ea
diff --git a/apps/computer/local-daemon/internal/provider/activity_status.go b/apps/computer/local-daemon/internal/provider/activity_status.go
index a44096f4..d46e5d08 100644
--- a/apps/computer/local-daemon/internal/provider/activity_status.go
+++ b/apps/computer/local-daemon/internal/provider/activity_status.go
@@ -33,12 +33,7 @@ func activityPresentation(message native.Event) (string, map[string]any, activit
if kind == "" {
kind = native.ActivityTool
}
- key := "command"
- command, _ := input[key].(string)
- if command == "" {
- key = "cmd"
- command, _ = input[key].(string)
- }
+ key, command := inputCommand(input)
if script := shellScript(command); script != command {
input = maps.Clone(input)
input[key], command = script, script
@@ -67,6 +62,17 @@ func activityPresentation(message native.Event) (string, map[string]any, activit
return kind, input, status
}
+// inputCommand is the shell command a tool call's input runs, under the key
+// its Runtime uses.
+func inputCommand(input map[string]any) (key, command string) {
+ for _, key := range []string{"command", "cmd"} {
+ if command, _ := input[key].(string); command != "" {
+ return key, command
+ }
+ }
+ return "command", ""
+}
+
// step is one thing a tool call does, as the Room status line names it.
type step struct {
kind string
diff --git a/apps/computer/local-daemon/internal/provider/command_activity.go b/apps/computer/local-daemon/internal/provider/command_activity.go
index effa6ad9..11165c50 100644
--- a/apps/computer/local-daemon/internal/provider/command_activity.go
+++ b/apps/computer/local-daemon/internal/provider/command_activity.go
@@ -271,6 +271,17 @@ var commandWord = regexp.MustCompile(`^[a-z][a-z0-9-]*$`)
// messageSends post to the Room, which shows the message itself.
var messageSends = map[string]bool{"send": true, "direct": true, "emoji": true, "sequence": true}
+// createsTask reports a script that is one `teamhub task create` call. Its
+// receipt names the Task it created, which the Room links the step to.
+func createsTask(script string) bool {
+ commands := simpleCommands(script)
+ if len(commands) != 1 || filepath.Base(commands[0].words[0]) != "teamhub" {
+ return false
+ }
+ path := teamhubPath(commands[0].words[1:])
+ return len(path) >= 2 && path[0] == "task" && path[1] == "create"
+}
+
// teamhubPath is the leading command words of a TeamHub CLI call, at most
// three, so an operand may follow the command.
func teamhubPath(args []string) []string {
diff --git a/apps/computer/local-daemon/internal/provider/event_projection.go b/apps/computer/local-daemon/internal/provider/event_projection.go
index 219e38fc..3676f352 100644
--- a/apps/computer/local-daemon/internal/provider/event_projection.go
+++ b/apps/computer/local-daemon/internal/provider/event_projection.go
@@ -15,7 +15,10 @@ type eventProjection struct {
operationID string
tools map[string]string
// quiet holds tool calls that stay in history without a Room activity.
- quiet map[string]bool
+ quiet map[string]bool
+ // receipts holds the tool calls that create a Task, whose output is
+ // published so the Room can link the step to that Task.
+ receipts map[string]bool
thinking bool
thinkingTitle string
// reasoning collects thinking a Runtime streams without titles until a
@@ -126,6 +129,12 @@ func (projection *eventProjection) projectActivity(message native.Event) []any {
projection.quiet[callID] = true
return []any{event}
}
+ if _, command := inputCommand(input); createsTask(command) {
+ if projection.receipts == nil {
+ projection.receipts = make(map[string]bool)
+ }
+ projection.receipts[callID] = true
+ }
activity := map[string]any{"type": "activity.started", "activity_id": stableEventID("activity", projection.operationID+"\x00"+callID), "kind": kind, "title": event["tool_name"]}
if content := activityInput(input, status); len(content) > 0 {
activity["content"] = content
@@ -141,16 +150,26 @@ func (projection *eventProjection) projectActivity(message native.Event) []any {
}
if _, started := projection.tools[callID]; started {
delete(projection.tools, callID)
+ receipt := projection.receipts[callID]
+ delete(projection.receipts, callID)
outcome := "succeeded"
if event["is_error"] == true {
outcome = "failed"
}
finished := map[string]any{"type": "activity.finished", "activity_id": stableEventID("activity", projection.operationID+"\x00"+callID), "outcome": outcome}
- // A failure's text tells the user why the step failed. Successful
+ // A failure's text tells the user why the step failed, and a Task's
+ // creation receipt names the Task the step links to. Other successful
// outputs stay private: they can be whole files or accessibility trees.
- if output, _ := event["output"].(string); outcome == "failed" {
+ label := ""
+ switch {
+ case outcome == "failed":
+ label = "Error"
+ case receipt:
+ label = "Output"
+ }
+ if output, _ := event["output"].(string); label != "" {
if text := strings.TrimSpace(toolResultText(output)); text != "" {
- finished["content"] = []map[string]any{{"label": "Error", "format": "text", "content": clip(redact.Text(text), 500)}}
+ finished["content"] = []map[string]any{{"label": label, "format": "text", "content": clip(redact.Text(text), 500)}}
}
}
return []any{event, finished}
diff --git a/apps/computer/local-daemon/internal/provider/events_regression_test.go b/apps/computer/local-daemon/internal/provider/events_regression_test.go
index 92a6f25d..43e01e8b 100644
--- a/apps/computer/local-daemon/internal/provider/events_regression_test.go
+++ b/apps/computer/local-daemon/internal/provider/events_regression_test.go
@@ -68,6 +68,26 @@ func TestFailedActivityPublishesItsRedactedError(t *testing.T) {
}
}
+func TestTaskCreationPublishesItsReceipt(t *testing.T) {
+ finish := func(command, output string) map[string]any {
+ projection := eventProjection{operationID: "operation"}
+ projection.project(native.Event{Kind: native.EventToolCall, InvocationID: "tool-1", ToolName: "Bash", ActivityKind: native.ActivityCommand, Input: map[string]any{"command": command}})
+ events := projection.project(native.Event{Kind: native.EventToolOutput, InvocationID: "tool-1", Status: "completed", Output: output})
+ return events[len(events)-1].(map[string]any)
+ }
+ receipt := "Task created and running\nTask ID: workitem_0123456789abcdef0123456789abcdef"
+ content, _ := finish(`teamhub task create --name "Rivals" --requirement "Compare"`, receipt)["content"].([]map[string]any)
+ if len(content) != 1 || content[0]["label"] != "Output" || content[0]["content"] != receipt {
+ t.Fatalf("task creation lost its receipt: %v", content)
+ }
+ // Any other output, including a script that also creates a Task, stays private.
+ for _, command := range []string{"teamhub task check", `teamhub task create --name x && cat notes.md`} {
+ if event := finish(command, receipt); event["content"] != nil {
+ t.Fatalf("published the output of %q: %v", command, event)
+ }
+ }
+}
+
func TestEventProjectionSplitsLongUnicodeRepliesWithoutLosingContent(t *testing.T) {
projection := eventProjection{operationID: "operation"}
content := strings.Repeat("\u4e2d", 100_000)