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.

feat(voice): let Live check a task in full and list only running ones

LeoXinge2efc3d9fa36
diff --git a/apps/teamhub/internal/store/queries/voice_live_tasks.sql b/apps/teamhub/internal/store/queries/voice_live_tasks.sql
index 093ad294..a8e9b5db 100644
--- a/apps/teamhub/internal/store/queries/voice_live_tasks.sql
+++ b/apps/teamhub/internal/store/queries/voice_live_tasks.sql
@@ -158,3 +158,10 @@ WHERE decision.alter_ego_task_id=ANY(sqlc.arg(task_ids)::text[])
AND (decision.expires_at IS NULL OR decision.expires_at>clock_timestamp())
AND decision.kind IN ('connector_write','runtime_permission','agent_change')
ORDER BY decision.created_at,decision.id;
+
+-- name: ListVoiceLiveTaskReports :many
+-- What a voice task sent back to its coordinator, newest first.
+SELECT body,created_at FROM task_meta_callback_messages
+WHERE task_id=sqlc.arg(task_id)::text AND tenant_id=sqlc.arg(tenant_id)::text
+ORDER BY meta_seq DESC
+LIMIT sqlc.arg(row_limit)::int;
diff --git a/apps/teamhub/internal/store/voice_live_tasks.sql.go b/apps/teamhub/internal/store/voice_live_tasks.sql.go
index 48ec67f9..d20a552a 100644
--- a/apps/teamhub/internal/store/voice_live_tasks.sql.go
+++ b/apps/teamhub/internal/store/voice_live_tasks.sql.go
@@ -368,6 +368,45 @@ func (q *Queries) ListVoiceLiveRoomPendingWakes(ctx context.Context, roomID stri
return items, nil
}
+const listVoiceLiveTaskReports = `-- name: ListVoiceLiveTaskReports :many
+SELECT body,created_at FROM task_meta_callback_messages
+WHERE task_id=$1::text AND tenant_id=$2::text
+ORDER BY meta_seq DESC
+LIMIT $3::int
+`
+
+type ListVoiceLiveTaskReportsParams struct {
+ TaskID string `json:"task_id"`
+ TenantID string `json:"tenant_id"`
+ RowLimit int32 `json:"row_limit"`
+}
+
+type ListVoiceLiveTaskReportsRow struct {
+ Body string `json:"body"`
+ CreatedAt pgtype.Timestamptz `json:"created_at"`
+}
+
+// What a voice task sent back to its coordinator, newest first.
+func (q *Queries) ListVoiceLiveTaskReports(ctx context.Context, arg ListVoiceLiveTaskReportsParams) ([]ListVoiceLiveTaskReportsRow, error) {
+ rows, err := q.db.Query(ctx, listVoiceLiveTaskReports, arg.TaskID, arg.TenantID, arg.RowLimit)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ items := []ListVoiceLiveTaskReportsRow{}
+ for rows.Next() {
+ var i ListVoiceLiveTaskReportsRow
+ if err := rows.Scan(&i.Body, &i.CreatedAt); err != nil {
+ return nil, err
+ }
+ items = append(items, i)
+ }
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
+ return items, nil
+}
+
const listVoiceLiveTasks = `-- name: ListVoiceLiveTasks :many
SELECT task.ordinal,task.goal,task.surface,task.work_item_id,task.canceled_at,item.title,
(task.voice_session_id IS NOT DISTINCT FROM $1::text)::boolean AS started_here,
diff --git a/apps/teamhub/internal/voice/voice_live.go b/apps/teamhub/internal/voice/voice_live.go
index 81124428..20e9c847 100644
--- a/apps/teamhub/internal/voice/voice_live.go
+++ b/apps/teamhub/internal/voice/voice_live.go
@@ -221,6 +221,8 @@ func (s *Service) executeVoiceLiveTool(ctx context.Context, session voicelive.Se
return s.sendVoiceLiveCard(ctx, session, request)
case voicelive.ToolListTasks:
return s.listVoiceLiveTasks(ctx, session, request)
+ case voicelive.ToolCheckTask:
+ return s.checkVoiceLiveTask(ctx, session, request)
case voicelive.ToolDecideApproval:
return s.decideVoiceLiveApproval(ctx, session, request)
case voicelive.ToolCheckReminders:
diff --git a/apps/teamhub/internal/voice/voice_live_tasks.go b/apps/teamhub/internal/voice/voice_live_tasks.go
index 62052393..a378b95b 100644
--- a/apps/teamhub/internal/voice/voice_live_tasks.go
+++ b/apps/teamhub/internal/voice/voice_live_tasks.go
@@ -390,13 +390,69 @@ func (s *Service) listVoiceLiveTasks(ctx context.Context, session voicelive.Sess
}
tasks := make([]voicelive.ProgressTask, 0, len(background))
for _, row := range background {
- tasks = append(tasks, voicelive.ProgressTask{Title: row.Title, Status: row.TaskExecutionStatus.String, CreatedAt: row.CreatedAt.Time})
+ status := row.TaskExecutionStatus.String
+ if !args.RunningOnly || status == "running" || status == "waiting_for_approval" {
+ tasks = append(tasks, voicelive.ProgressTask{Title: row.Title, Status: status, CreatedAt: row.CreatedAt.Time})
+ }
+ }
+ if args.RunningOnly {
+ views = slices.DeleteFunc(views, func(view voicelive.TaskView) bool { return !voicelive.Unfinished(view.State) })
}
output := voicelive.TaskListOutput(views)
output["background_tasks"] = voicelive.TaskProgress(time.Now(), tasks)
return voicelive.Output(output), nil
}
+// checkVoiceLiveTask reads one of the user's voice tasks as a Meta's task
+// check does, with every report it sent back.
+func (s *Service) checkVoiceLiveTask(ctx context.Context, session voicelive.Session, request teamhubinternal.VoiceLiveToolCall) (string, error) {
+ var args voicelive.CheckTaskArguments
+ if voicelive.DecodeArguments(request.Arguments, &args) != nil {
+ return "", voicelive.ErrInvalid
+ }
+ ordinal, ok := voicelive.TaskOrdinal(args.TaskID)
+ if !ok {
+ return "", voicelive.ErrInvalid
+ }
+ task, err := s.queries.GetVoiceLiveTask(ctx, store.GetVoiceLiveTaskParams{RoomID: session.RoomID, OwnerActorID: session.HumanActorID, Ordinal: ordinal})
+ if errors.Is(err, pgx.ErrNoRows) {
+ return voicelive.ErrorOutput("task_not_found"), nil
+ }
+ if err != nil {
+ return "", err
+ }
+ view, err := taskexecution.ReadTask(ctx, s.queries, task.WorkItemID)
+ if errors.Is(err, taskexecution.ErrNotFound) {
+ return voicelive.ErrorOutput("task_not_found"), nil
+ }
+ if err != nil {
+ return "", err
+ }
+ reports, err := s.queries.ListVoiceLiveTaskReports(ctx, store.ListVoiceLiveTaskReportsParams{
+ TaskID: task.WorkItemID, TenantID: session.TenantID, RowLimit: voicelive.MaxCheckedReports,
+ })
+ if err != nil {
+ return "", err
+ }
+ checked := voicelive.CheckedTask{
+ TaskID: args.TaskID, Goal: task.Goal, Folder: voicelive.PlaygroundRoot + task.WorkItemID + "/",
+ Status: view.Status, Reason: view.ReasonCode, StatusSince: view.StatusSince, QueuedMessages: view.QueuedMessageCount,
+ }
+ if task.CanceledAt.Valid {
+ checked.Status = "canceled"
+ }
+ for _, step := range view.RecentActivity {
+ checked.Activity = append(checked.Activity, voicelive.CheckedActivity{At: step.At, Kind: step.Kind, Text: step.Summary})
+ }
+ for _, approval := range view.PendingApprovals {
+ checked.Approvals = append(checked.Approvals, approval.Title)
+ }
+ for index := len(reports) - 1; index >= 0; index-- {
+ checked.Reports = append(checked.Reports, voicelive.CheckedActivity{At: reports[index].CreatedAt.Time, Text: reports[index].Body})
+ }
+ return voicelive.Output(voicelive.CheckTaskOutput(time.Now(), checked)), nil
+}
+
// LiveTasks lists the live call's Tasks and the event alerts waiting for it,
// and renews the call's foreground lease. Updates still arrive while the
// last answer of a just-closed call plays.
diff --git a/apps/teamhub/internal/voicelive/progress.go b/apps/teamhub/internal/voicelive/progress.go
index b9a5f758..b674e73b 100644
--- a/apps/teamhub/internal/voicelive/progress.go
+++ b/apps/teamhub/internal/voicelive/progress.go
@@ -16,8 +16,9 @@ const (
// ProgressArguments selects the task or Room progress to report.
type ProgressArguments struct {
- Scope string `json:"scope"`
- RoomID string `json:"room_id"`
+ Scope string `json:"scope"`
+ RoomID string `json:"room_id"`
+ RunningOnly LooseBool `json:"running_only"`
}
// RecentRunWindow is how far back a Room report looks for finished Runs.
diff --git a/apps/teamhub/internal/voicelive/tasks.go b/apps/teamhub/internal/voicelive/tasks.go
index 8590a652..3a17a730 100644
--- a/apps/teamhub/internal/voicelive/tasks.go
+++ b/apps/teamhub/internal/voicelive/tasks.go
@@ -17,6 +17,7 @@ const (
ToolReplyToTask = "reply_to_task"
ToolCancelTask = "cancel_task"
ToolListTasks = "list_tasks"
+ ToolCheckTask = "check_task"
)
// Surfaces say where the Agent works.
@@ -64,6 +65,17 @@ type CancelTaskArguments struct {
TaskID string `json:"task_id"`
}
+// CheckTaskArguments identifies the task the live model reads in full.
+type CheckTaskArguments struct {
+ TaskID string `json:"task_id"`
+}
+
+// Unfinished reports whether a task in state is still being done or waits
+// for the user, the tasks list_tasks running_only keeps.
+func Unfinished(state string) bool {
+ return state == TaskPending || state == TaskWorking || state == TaskWaitingForApproval
+}
+
var taskIDPattern = regexp.MustCompile(`^t([1-9][0-9]{0,5})$`)
// TaskID is the short handle the live model uses for a task.
@@ -120,14 +132,24 @@ var taskTools = []Tool{
Name: ToolListTasks,
Description: "See the user's tasks in this room: those of this call, and earlier ones still working or reported within the last day. Each task's goal, state (pending, working, waiting_for_approval, reported with its latest report, which may be a result or something it needs from the user, failed, canceled) and the latest steps. When asked how things are going, give the state of every task, canceled and finished ones included. Only pending and working mean something is being done right now; never say a task is still doing something in any other state. " +
"Call it when the user asks how far along something is, whether it is done or what is being worked on, and to find a task_id or the folder its files are in; never answer progress from impression. " +
- "scope=room instead reports every Agent still working in this room, the last ones that finished and background Tasks; for another room, get its room_id with find_rooms and pass it. " +
+ "running_only=true keeps only the tasks still under way or waiting for approval. scope=room instead reports every Agent still working in this room, the last ones that finished and background Tasks; for another room, get its room_id with find_rooms and pass it. " +
"The work is yours to the user: speak of it in the first person, picking the one or two lines that matter.",
Parameters: objectSchema([]string{}, map[string]any{
"scope": map[string]any{
"type": "string", "enum": []string{ProgressScopeMyRequests, ProgressScopeRoom},
"description": "Optional, defaults to my_requests: the user's tasks",
},
- "room_id": stringProperty("Optional ID of another room to check, from find_rooms"),
+ "room_id": stringProperty("Optional ID of another room to check, from find_rooms"),
+ "running_only": map[string]any{"type": "boolean", "description": "Optional: only tasks still pending, working or waiting for approval"},
+ }),
+ },
+ {
+ Name: ToolCheckTask,
+ Description: "Read one of the user's tasks in full, as its coordinator does: its state and since when, the latest steps, the approvals it waits on, how many messages wait for it, and every report it sent back, oldest first and each up to 4000 characters. " +
+ "list_tasks shows only the start of the latest report: use this when the user asks for details it left out (which models, what each option costs, what exactly it found or why it stopped), or before saying how a task really stands. " +
+ "A report may hold lines addressed to you, such as how to deliver its files; those are not for the user. Speak of the work in the first person.",
+ Parameters: objectSchema([]string{"task_id"}, map[string]any{
+ "task_id": stringProperty("The task, such as t2, from list_tasks"),
}),
},
}
@@ -256,3 +278,48 @@ func TaskRequirement(goal, surface string) string {
func TaskAnswer(details string) string {
return "The user said this about your task by voice; take it into account and go on: " + details
}
+
+// MaxCheckedReports is how many of a task's latest reports check_task shows.
+const MaxCheckedReports = 10
+
+// checkedReportRunes bounds each report check_task shows, as task check does.
+const checkedReportRunes = 4000
+
+// CheckedTask is one task as check_task reads it: its Task's state and the
+// reports it sent back, oldest first.
+type CheckedTask struct {
+ TaskID, Goal, Folder, Status, Reason string
+ StatusSince time.Time
+ Activity []CheckedActivity
+ Approvals []string
+ QueuedMessages int
+ Reports []CheckedActivity
+}
+
+// CheckedActivity is one dated step or report.
+type CheckedActivity struct {
+ At time.Time
+ Kind, Text string
+}
+
+// CheckTaskOutput is what check_task returns to the live model.
+func CheckTaskOutput(now time.Time, task CheckedTask) map[string]any {
+ activity := make([]map[string]string, 0, len(task.Activity))
+ for _, step := range task.Activity {
+ activity = append(activity, map[string]string{"ago": SpokenDuration(now.Sub(step.At)), "kind": step.Kind, "summary": step.Text})
+ }
+ reports := make([]map[string]string, 0, len(task.Reports))
+ for _, report := range task.Reports {
+ reports = append(reports, map[string]string{"ago": SpokenDuration(now.Sub(report.At)), "text": truncateRunes(report.Text, checkedReportRunes)})
+ }
+ output := map[string]any{
+ "task_id": task.TaskID, "goal": truncateRunes(task.Goal, 300), "folder": task.Folder,
+ "status": task.Status, "status_for": SpokenDuration(now.Sub(task.StatusSince)),
+ "recent_activity": activity, "reports": reports,
+ "pending_approvals": task.Approvals, "queued_messages": task.QueuedMessages,
+ }
+ if task.Reason != "" {
+ output["reason"] = task.Reason
+ }
+ return output
+}
diff --git a/apps/teamhub/tests/integration/voice_live_test.go b/apps/teamhub/tests/integration/voice_live_test.go
index 9ae4f4c7..871e967a 100644
--- a/apps/teamhub/tests/integration/voice_live_test.go
+++ b/apps/teamhub/tests/integration/voice_live_test.go
@@ -684,6 +684,21 @@ func TestVoiceLiveTasksReportResultsAndWhatTheyWaitFor(t *testing.T) {
if _, err := env.pool.Exec(t.Context(), `UPDATE work_items SET task_execution_status='waiting_for_approval' WHERE id=$1`, waiting); err != nil {
t.Fatal(err)
}
+ // check_task reads one task as its coordinator does, every report included.
+ checked := tool("lt_check", "check-1", "check_task", map[string]any{"task_id": first["task_id"]})
+ reports, _ := checked["reports"].([]any)
+ if checked["status"] != "idle" || checked["folder"] != "./playground/"+workItem(first["task_id"])+"/" || len(reports) != 1 ||
+ reports[0].(map[string]any)["text"] != "Sony at 1899 is the best fit, added to the cart." {
+ t.Fatalf("check_task=%v", checked)
+ }
+ if missing := tool("lt_check", "check-2", "check_task", map[string]any{"task_id": "t99"}); missing["error"] != "task_not_found" {
+ t.Fatalf("check_task of an unknown task=%v", missing)
+ }
+ // running_only keeps the tasks still under way or waiting for the user.
+ listed := tool("lt_check", "list-1", "list_tasks", map[string]any{"running_only": true})
+ if items, _ := listed["tasks"].([]any); len(items) != 1 || items[0].(map[string]any)["task_id"] != second["task_id"] {
+ t.Fatalf("running_only list_tasks=%v", listed)
+ }
if _, err := env.pool.Exec(t.Context(), `UPDATE work_items SET task_execution_updated_at=now()-interval '25 hours' WHERE id=ANY($1)`,
[]string{workItem(first["task_id"]), waiting}); err != nil {
t.Fatal(err)
diff --git a/apps/voice-runtime/src/realtime.ts b/apps/voice-runtime/src/realtime.ts
index 8040e8a9..8814bda9 100644
--- a/apps/voice-runtime/src/realtime.ts
+++ b/apps/voice-runtime/src/realtime.ts
@@ -66,7 +66,7 @@ Pick the one place the answer or the work lives:
${webSearch ? "- A live fact one sentence answers (weather, news, an exchange rate, a stock price): web_search on the spot and give the one or two lines that matter. Never search the web for chat or recommendations, for research, comparisons or prices of several things, or to look at a particular website (GitHub, a store, a booking or ticket site): " + (localBrowser ? "that is computer_browser, or start_task with surface web for long work" : "that is start_task with surface web") + ".\n" : ""}${localBrowser ? "- A website the user wants to open, browse, search or read together with you, or a site they name (“open Xiaohongshu”, “search it on Bing”): computer_browser, yourself, in the browser on their own computer. Long work across many pages, comparing several things or anything that ends in a document is start_task.\n" : ""}- The user's own past and anything about them (who they are, their work and people, what was discussed or decided, their Wiki, notes, daily or weekly reports, someone's page): recall_memory, also when that page is open on the screen. If it finds nothing, say you found nothing; say what the screen shows only if the user asks about the screen.
- This app's window, which the user is looking at: page_action to operate it (open a room, click, scroll, close, type, search) and read_page when they ask about what is on it (“this page”, “here”, “this on the screen”). It reaches nothing outside this app.
${has("page_action") && has("search_documents") ? "- A file, deck or document the user wants opened or shown: search_documents with their words for its document_id, unless a message in context is plainly that very file, then page_action open_document with it; it opens beside the chat when this room has it and in the Library otherwise. Check the title in its result before you say it is open. Never hop rooms or click Attach file for this.\n" : ""}${has("create_document") ? "- A new document the user wants (notes, a plan, a checklist, a draft): create_document, written from what they said; it opens beside the chat.\n" : ""}${documentEdits ? "- A document, canvas or file in this app the user wants renamed or changed (its title, a sentence, a section, all of it): rename_document, replace_document_text or edit_document yourself, on the spot, reading it first with read_document when you need its text" + (has("insert_document_image") ? "; an image into it, such as a task's output, is insert_document_image" : "") + ". Its comments: list_comments to read them; add_comment, reply_comment and resolve_comment act as the user. Deleting or moving it is start_task.\n" : ""}${appReads.length ? `- What is in ${appReads.join(", ")}: look it up yourself on the spot and say the one or two things that matter. ${slackSend ? "Sending a Slack message is send_slack, also with a file (a document here or a task's output) and to the user's own DM: call it as soon as the user wants it sent. " : ""}Replying to email, booking or changing anything else there is start_task with surface apps.\n` : ""}${has("create_routine") ? "- A reminder at a set time or work on a schedule (“remind me at eight to call mom”, “every weekday at nine tell me my day”): create_routine; which ones exist is list_routines; pausing, resuming, running or deleting one is change_routine. It reminds in this chat, with no phone notification.\n" : ""}${has("create_agent") ? "- A new Agent the user wants made (a teammate for a job): create_agent, with complete instructions written from what they said.\n" : ""}${emailCanvas ? `- A new email the user wants written: open_email_canvas at once; it opens beside the chat for them to read and edit. Changing it is edit_email_canvas; ${has("attach_email_file") ? "attaching a file to it (a document or file in this app, or a task's output) is attach_email_file; " : ""}${emailDelivery ? "saving it in Gmail is save_email_draft, and sending it is send_email_canvas: call it as soon as the user wants it sent" : "saving it in Gmail or sending it is start_task"}.\n` : ""}- Everything else that takes time or happens outside this app: start_task, with surface web for websites and anything “in the browser”, desktop for apps and files on their computer (WeChat, the Feishu or Slack app, Excel, Figma, Downloads, a window on their screen), apps for their connected email, calendar or Slack, workspace for research, reports and multi-step work here. Several pieces of work are several start_task calls. Say one short line and keep talking; the result comes back by itself. Never say work is started unless start_task returned started.
-- While work is running: what the user answers to it or changes about it goes to reply_to_task; stopping it is cancel_task; how far it is, list_tasks; an approval it waits on is decide_approval, only after the user agrees to that answer.
+- While work is running: what the user answers to it or changes about it goes to reply_to_task; stopping it is cancel_task; how far it is, list_tasks${has("check_task") ? ", and what exactly one found or needs, check_task" : ""}; an approval it waits on is decide_approval, only after the user agrees to that answer.
- Messages, Pocket Notes and rooms in this app: the matching tool. send_message and find_rooms reach only rooms in this app; ${slackSend ? "Slack is send_slack, and " : ""}replying or posting in ${slackSend ? "" : "Slack, "}Feishu, WeChat or email is start_task. A change (send, note, create, delete) is restated in one sentence and done with confirmed=true only after the user agrees. A message body holds only what the user wants to say.
${pageChainRule(tools)}- If a search finds nothing, the name may have been misheard (“level eight” may be “Lev8”): try a close spelling once more, then ask how to spell it.
- When the user wants to hang up or says goodbye: end_voice_mode and a very short goodbye in the same reply; never ask whether they are sure.