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 put a playground image into a document
LeoXing1917c80af814
diff --git a/apps/computer/local-daemon/internal/daemon/playground_tools.go b/apps/computer/local-daemon/internal/daemon/playground_tools.goindex 4b4b8be7..65e39b91 100644--- a/apps/computer/local-daemon/internal/daemon/playground_tools.go+++ b/apps/computer/local-daemon/internal/daemon/playground_tools.go@@ -36,6 +36,15 @@ type playgroundCardFile struct {Path string `json:"path"`}+type playgroundImage struct {+ OperationID string `json:"operation_id"`+ InboxID string `json:"inbox_id"`+ DocumentID string `json:"document_id"`+ AfterBlockID string `json:"after_block_id"`+ Caption string `json:"caption"`+ File playgroundCardFile `json:"file"`+}+type playgroundCard struct {OperationID string `json:"operation_id"`InboxID string `json:"inbox_id"`@@ -70,6 +79,12 @@ func (d *Daemon) callPlayground(ctx context.Context, tenantID, agentID, name strreturn map[string]any{"status": "invalid_card"}, nil}result, err = d.sendPlaygroundCard(ctx, tenantID, agentID, card)+ case "place_image":+ var image playgroundImage+ if !decodes(arguments, &image) {+ return map[string]any{"status": "invalid_image"}, nil+ }+ result, err = d.placePlaygroundImage(ctx, tenantID, agentID, image)default:return map[string]any{"status": "unavailable"}, nil}@@ -124,12 +139,59 @@ func (d *Daemon) sendPlaygroundCard(ctx context.Context, tenantID, agentID strinif err != nil {return nil, err}- return d.runCardCLI(ctx, installation, roomID, arguments, card.Content)+ stdout, err := d.runAgentCLI(ctx, installation, roomID, arguments, card.Content)+ if err != nil {+ return nil, err+ }+ return cardCommitResult(stdout)}-// runCardCLI runs the bundled CLI with a profile of its own that targets the-// card's Room. The credential stays in its file; the CLI reads it.-func (d *Daemon) runCardCLI(ctx context.Context, installation clicredential.Installation, roomID string, arguments []string, body string) (map[string]any, error) {+// placePlaygroundImage puts an image where the Agent wrote it into a+// Document after one of its blocks by running `teamhub docs image put` as the+// Agent, which stores the image in the Document first. The operation ID+// makes a repeated call place it once.+func (d *Daemon) placePlaygroundImage(ctx context.Context, tenantID, agentID string, image playgroundImage) (map[string]any, error) {+ roomID, isRoom := strings.CutPrefix(image.InboxID, "room:")+ if image.OperationID == "" || !isRoom || roomID == "" || image.DocumentID == "" || image.AfterBlockID == "" ||+ strings.ContainsAny(image.Caption, "\r\n") {+ return nil, &playgroundFailure{"invalid_image", "An image needs a Document, a block to follow and a one-line caption."}+ }+ filename, err := d.contextViews.PlaygroundFilePath(ctx, tenantID, agentID, image.File.Folder, image.File.Path)+ if err != nil {+ return nil, err+ }+ arguments := []string{"docs", "image", "put", image.DocumentID, filename, "--after", image.AfterBlockID}+ if image.Caption != "" {+ arguments = append(arguments, "--caption", image.Caption)+ }+ arguments = append(arguments, "--operation-id", image.OperationID, "--json")+ installation, err := d.agentCLICredential(tenantID, agentID)+ if err != nil {+ return nil, err+ }+ stdout, err := d.runAgentCLI(ctx, installation, roomID, arguments, "")+ if err != nil {+ return nil, err+ }+ var placed struct {+ Status string `json:"status"`+ RevisionID string `json:"revision_id"`+ ConflictReason string `json:"conflict_reason"`+ }+ if json.Unmarshal(bytes.TrimSpace(stdout), &placed) != nil || placed.Status == "" {+ return nil, &playgroundFailure{"outcome_unknown", agentCLIUnknown}+ }+ // TeamHub reads a status other than ok as a failure; a conflict is not one.+ return map[string]any{"placement": placed.Status, "revision_id": placed.RevisionID, "conflict_reason": placed.ConflictReason}, nil+}++// agentCLIUnknown is told when a CLI run may have changed something.+const agentCLIUnknown = "It may have been done; check before trying again."++// runAgentCLI runs the bundled CLI as the Agent with a profile of its own+// that targets roomID, and returns what it printed. The credential stays in+// its file; the CLI reads it.+func (d *Daemon) runAgentCLI(ctx context.Context, installation clicredential.Installation, roomID string, arguments []string, stdin string) ([]byte, error) {program, prefix, environment, ok := cardCLIProgram(d.teamhubCLIBin, runtime.GOOS)if !ok {return nil, &playgroundFailure{"cli_unavailable", "This Computer has no TeamHub CLI; update the Computer."}@@ -154,12 +216,12 @@ func (d *Daemon) runCardCLI(ctx context.Context, installation clicredential.Instcommand := exec.CommandContext(ctx, program, append(prefix, arguments...)...)command.Dir = homecommand.Env = append(append(cardCLIEnvironment(os.Environ()), environment...), "TEAMHUB_CONFIG="+configPath, "TEAMHUB_PROFILE=live")- command.Stdin = strings.NewReader(body)+ command.Stdin = strings.NewReader(stdin)var stdout, stderr bytes.Buffercommand.Stdout, command.Stderr = &stdout, &stderrrunErr := command.Run()if ctx.Err() != nil {- return nil, &playgroundFailure{"outcome_unknown", "The card may have been posted; check the chat before trying again."}+ return nil, &playgroundFailure{"outcome_unknown", agentCLIUnknown}}if runErr != nil {var exit *exec.ExitError@@ -167,9 +229,9 @@ func (d *Daemon) runCardCLI(ctx context.Context, installation clicredential.Inst// The CLI never started, so nothing was posted.return nil, &playgroundFailure{"cli_unavailable", "The TeamHub CLI could not start: " + runErr.Error()}}- return nil, cardCLIFailure(stderr.Bytes())+ return nil, agentCLIFailure(stderr.Bytes())}- return cardCommitResult(stdout.Bytes())+ return stdout.Bytes(), nil}// cardCLIProgram is how to start the bundled CLI in directory. The Computer@@ -214,9 +276,9 @@ func cardCLIEnvironment(environment []string) []string {return kept}-// cardCLIFailure tells the live model why the CLI did not post the card. A+// agentCLIFailure tells the live model why the CLI did not do its work. A// failure whose outcome the CLI could not know is never reported as refused.-func cardCLIFailure(stderr []byte) error {+func agentCLIFailure(stderr []byte) error {var envelope struct {Error struct {Code string `json:"code"`@@ -226,7 +288,7 @@ func cardCLIFailure(stderr []byte) error {_ = json.Unmarshal(bytes.TrimSpace(stderr), &envelope)switch envelope.Error.Code {case "", "connection_failed", "timeout", "outcome_unknown", "external_outcome_unknown":- return &playgroundFailure{"outcome_unknown", "The card may have been posted; check the chat before trying again."}+ return &playgroundFailure{"outcome_unknown", agentCLIUnknown}}return &playgroundFailure{"upload_failed", strings.TrimSpace(envelope.Error.Code + ": " + envelope.Error.Message)}}diff --git a/apps/computer/local-daemon/internal/daemon/playground_tools_test.go b/apps/computer/local-daemon/internal/daemon/playground_tools_test.goindex 3378f3c4..0a7489b1 100644--- a/apps/computer/local-daemon/internal/daemon/playground_tools_test.go+++ b/apps/computer/local-daemon/internal/daemon/playground_tools_test.go@@ -36,12 +36,16 @@ func TestPlaygroundCardRunsTheCLIAsTheAgentInTheRoom(t *testing.T) {t.Setenv("TEAMHUB_SECRET", "from-the-daemon")directory, record := fakeCardCLI(t, `{"accepted":true,"message_id":"message-1","resources":[{"kind":"document","segment_index":1,"status":"published","document_id":"document-1","name":"report.md"}]}`, "", 0)daemon := &Daemon{teamhubCLIBin: directory}- result, err := daemon.runCardCLI(t.Context(), cardInstallation, "room-1",+ stdout, err := daemon.runAgentCLI(t.Context(), cardInstallation, "room-1",[]string{"message", "card", "--title", "Report", "--file", "-", "--attach", "/work/playground/task-1/report.md", "--operation-id", "voice-live:abc", "--json"},`Saved to C:\new\table.xlsx`)if err != nil {t.Fatal(err)}+ result, err := cardCommitResult(stdout)+ if err != nil {+ t.Fatal(err)+ }documents := result["documents"].([]map[string]any)if result["message_id"] != "message-1" || len(documents) != 1 || documents[0]["document_id"] != "document-1" || documents[0]["filename"] != "report.md" {t.Fatalf("result=%v", result)@@ -81,7 +85,7 @@ func TestPlaygroundCardTellsWhyTheCLIFailed(t *testing.T) {`not json`: "outcome_unknown",} {directory, _ := fakeCardCLI(t, "", stderr, 2)- _, err := (&Daemon{teamhubCLIBin: directory}).runCardCLI(t.Context(), cardInstallation, "room-1", []string{"message", "card"}, "Done.")+ _, err := (&Daemon{teamhubCLIBin: directory}).runAgentCLI(t.Context(), cardInstallation, "room-1", []string{"message", "card"}, "Done.")var failure *playgroundFailureif !errors.As(err, &failure) || failure.code != want {t.Fatalf("%s: err=%v, want %s", stderr, err, want)@@ -91,7 +95,7 @@ func TestPlaygroundCardTellsWhyTheCLIFailed(t *testing.T) {}}var failure *playgroundFailure- if _, err := (&Daemon{}).runCardCLI(t.Context(), cardInstallation, "room-1", nil, ""); !errors.As(err, &failure) || failure.code != "cli_unavailable" {+ if _, err := (&Daemon{}).runAgentCLI(t.Context(), cardInstallation, "room-1", nil, ""); !errors.As(err, &failure) || failure.code != "cli_unavailable" {t.Fatalf("no CLI = %v", err)}}@@ -148,3 +152,18 @@ func TestPlaygroundCardFindsTheCLIOnEveryLayout(t *testing.T) {t.Fatal("found a CLI in an empty directory")}}++func TestPlaygroundImageRefusesAnIncompletePlacement(t *testing.T) {+ daemon := &Daemon{}+ for _, image := range []playgroundImage{+ {OperationID: "op", InboxID: "task:task-1", DocumentID: "document-1", AfterBlockID: "block-1"},+ {OperationID: "op", InboxID: "room:room-1", AfterBlockID: "block-1"},+ {OperationID: "op", InboxID: "room:room-1", DocumentID: "document-1"},+ {OperationID: "op", InboxID: "room:room-1", DocumentID: "document-1", AfterBlockID: "block-1", Caption: "two\nlines"},+ } {+ var failure *playgroundFailure+ if _, err := daemon.placePlaygroundImage(t.Context(), "tenant-1", "agent-1", image); !errors.As(err, &failure) || failure.code != "invalid_image" {+ t.Fatalf("image %+v = %v", image, err)+ }+ }+}diff --git a/apps/teamhub/internal/voice/voice_live.go b/apps/teamhub/internal/voice/voice_live.goindex 2f120203..81124428 100644--- a/apps/teamhub/internal/voice/voice_live.go+++ b/apps/teamhub/internal/voice/voice_live.go@@ -318,7 +318,7 @@ func (s *Service) executeVoiceLiveTool(ctx context.Context, session voicelive.Sereturn s.editVoiceLiveEmailCanvas(ctx, session, request)case voicelive.ToolAttachEmailFile:return s.attachVoiceLiveEmailFile(ctx, session, request)- case voicelive.ToolCreateDocument, voicelive.ToolRenameDocument, voicelive.ToolEditDocument, voicelive.ToolReplaceDocumentText,+ case voicelive.ToolCreateDocument, voicelive.ToolRenameDocument, voicelive.ToolEditDocument, voicelive.ToolReplaceDocumentText, voicelive.ToolInsertDocumentImage,voicelive.ToolListComments, voicelive.ToolAddComment, voicelive.ToolReplyComment, voicelive.ToolResolveComment:return s.runVoiceLiveDocumentTool(ctx, session, request)case voicelive.ToolListRoutines, voicelive.ToolCreateRoutine, voicelive.ToolChangeRoutine:diff --git a/apps/teamhub/internal/voice/voice_live_documents.go b/apps/teamhub/internal/voice/voice_live_documents.goindex 62edded7..22358103 100644--- a/apps/teamhub/internal/voice/voice_live_documents.go+++ b/apps/teamhub/internal/voice/voice_live_documents.go@@ -48,6 +48,8 @@ func (s *Service) runVoiceLiveDocumentTool(ctx context.Context, session voicelivreturn output, err}return voicelive.Output(map[string]string{"status": "created", "document_id": created.DocumentID, "revision_id": created.RevisionID}), nil+ case voicelive.ToolInsertDocumentImage:+ return s.insertVoiceLiveDocumentImage(ctx, session, request, args)case voicelive.ToolRenameDocument, voicelive.ToolEditDocument, voicelive.ToolReplaceDocumentText:if args.DocumentID == "" {return "", voicelive.ErrInvalid@@ -347,3 +349,49 @@ func (s *Service) resolveVoiceLiveComment(ctx context.Context, session voicelive}return voicelive.Output(map[string]string{"status": status, "thread_id": args.ThreadID}), nil}++// insertVoiceLiveDocumentImage puts a ./playground image into a Document+// below one of its blocks by running `teamhub docs image put` as the Agent on+// the user's Computer, which stores the image in the Document first: an edit+// shows only images the Document already holds.+func (s *Service) insertVoiceLiveDocumentImage(ctx context.Context, session voicelive.Session, request teamhubinternal.VoiceLiveToolCall, args voicelive.DocumentArguments) (string, error) {+ caption := strings.TrimSpace(args.Caption)+ if args.DocumentID == "" || strings.ContainsAny(caption, "\r\n") || utf8.RuneCountInString(caption) > 1000 {+ return "", voicelive.ErrInvalid+ }+ folder, inside, output, err := s.voiceLiveFilePath(ctx, session, args.Path)+ if output != "" || err != nil {+ return output, err+ }+ principal, err := s.voiceLiveAgentPrincipal(ctx, session)+ if errors.Is(err, errVoiceLiveAgentUnavailable) {+ return voicelive.ErrorOutput("agent_unavailable"), nil+ }+ if err != nil {+ return "", err+ }+ current, err := s.voiceLiveDocument(ctx, principal, args.DocumentID)+ if errors.Is(err, document.ErrNotFound) {+ return voicelive.ErrorOutput("document_not_found"), nil+ }+ if err != nil {+ return "", err+ }+ blockID, problem := voicelive.ImageAnchor(current.blocks, args.After)+ if problem != "" {+ return voicelive.ErrorOutput(problem), nil+ }+ result, err := s.callVoiceLivePlayground(ctx, session, "place_image", map[string]any{+ "operation_id": voiceLiveInvocationID(session, request), "inbox_id": "room:" + session.RoomID,+ "document_id": args.DocumentID, "after_block_id": blockID, "caption": caption,+ "file": map[string]any{"folder": folder.folder, "path": inside},+ }, voiceLiveCardDeadline)+ if err != nil {+ return voiceLiveFileError(err)+ }+ if placement, _ := result["placement"].(string); placement != "applied" {+ return voicelive.Output(map[string]any{"error": "document_changed", "detail": result["conflict_reason"],+ "next": "Read the document and call again."}), nil+ }+ return voicelive.Output(map[string]any{"status": "inserted", "document_id": args.DocumentID, "revision_id": result["revision_id"]}), nil+}diff --git a/apps/teamhub/internal/voicelive/documents.go b/apps/teamhub/internal/voicelive/documents.goindex b9539f32..240e7b38 100644--- a/apps/teamhub/internal/voicelive/documents.go+++ b/apps/teamhub/internal/voicelive/documents.go@@ -14,6 +14,7 @@ const (ToolRenameDocument = "rename_document"ToolEditDocument = "edit_document"ToolReplaceDocumentText = "replace_document_text"+ ToolInsertDocumentImage = "insert_document_image"ToolListComments = "list_comments"ToolAddComment = "add_comment"ToolReplyComment = "reply_comment"@@ -63,12 +64,25 @@ var DocumentTools = []Tool{"replace_with": stringProperty("The new text for it, one line"),}),},+ {+ Name: ToolInsertDocumentImage,+ Description: "Put an image from the user's computer, such as one a task made, into a document in this app; it shows in the side panel at once. " + documentTarget ++ "path is the image under ./playground as ls prints it. after is text copied exactly from the paragraph or heading the image goes below (read it first with read_document), long enough to occur once; leave it out to put the image at the end. " ++ "To open a document with an image, put it below the title. caption is an optional one-line caption. " ++ "text_not_found or ambiguous_text: read the document and use longer exact text. When it is in, say in one short sentence where you put it. document_not_editable means the Agent may not edit it.",+ Parameters: objectSchema([]string{"document_id", "path"}, map[string]any{+ "document_id": stringProperty("The document to put the image in"),+ "path": stringProperty("The image, ./playground/<folder>/<file>"),+ "after": stringProperty("Exact text of the paragraph or heading it goes below; empty for the end"),+ "caption": stringProperty("An optional one-line caption"),+ }),+ },{Name: ToolEditDocument,Description: "Add to a document or canvas in this app, or rewrite all of it, as the user asks; it changes in the side panel at once. " + documentTarget +"command append adds content (Markdown) at the end. command rewrite replaces the whole document with content: all of it in Markdown, keeping what the user did not ask to change. " +"A rewrite needs the revision_id of the text you rewrote: call it without revision_id first, or after document_changed, to get the latest text and revision_id, redo the change on that text and call again. " +- "To change one line, use replace_document_text instead. document_has_media (images or files) or document_locked: use append or replace_document_text, or start_task naming the document_id. " ++ "To change one line, use replace_document_text instead; to add an image, insert_document_image. document_has_media (images or files) or document_locked: use append or replace_document_text, or start_task naming the document_id. " +"For a Gmail canvas use edit_email_canvas instead. When it is changed, say in one short sentence what you changed. document_not_editable means the Agent may not edit it.",Parameters: objectSchema([]string{"document_id", "command", "content"}, map[string]any{"document_id": stringProperty("The document to change"),@@ -132,6 +146,53 @@ type DocumentArguments struct {ThreadID string `json:"thread_id"`Reopen LooseBool `json:"reopen"`Confirmed LooseBool `json:"confirmed"`+ Path string `json:"path"`+ After string `json:"after"`+ Caption string `json:"caption"`+}++// ImageAnchor is the top-level block of a Document's blocks export an image+// goes below: the one whose text holds after, or the last block when after+// is empty. problem names what the live model must fix instead.+func ImageAnchor(export []byte, after string) (blockID, problem string) {+ var document struct {+ Blocks []exportBlock `json:"blocks"`+ }+ if json.Unmarshal(export, &document) != nil || len(document.Blocks) == 0 {+ return "", "document_empty"+ }+ after = strings.TrimSpace(after)+ if after == "" {+ return document.Blocks[len(document.Blocks)-1].ID, ""+ }+ var holding, equal []string+ for _, block := range document.Blocks {+ text := strings.TrimSpace(blockText(block))+ if strings.Contains(text, after) {+ holding = append(holding, block.ID)+ }+ if text == after {+ equal = append(equal, block.ID)+ }+ }+ switch {+ case len(holding) == 1:+ return holding[0], ""+ case len(equal) == 1:+ return equal[0], ""+ case len(holding) == 0:+ return "", "text_not_found"+ }+ return "", "ambiguous_text"+}++// blockText is a block's inline text with its nested blocks' on lines below.+func blockText(block exportBlock) string {+ text := inlineText(block.Content)+ for _, child := range block.Children {+ text += "\n" + blockText(child)+ }+ return text}// DocumentEdit is the native edit operation for a change the live modeldiff --git a/apps/teamhub/internal/voicelive/playground_test.go b/apps/teamhub/internal/voicelive/playground_test.goindex b759b5c2..da6edb5d 100644--- a/apps/teamhub/internal/voicelive/playground_test.go+++ b/apps/teamhub/internal/voicelive/playground_test.go@@ -86,3 +86,29 @@ func TestPlaygroundImagesInlineOnlyPlaygroundFiles(t *testing.T) {}}}++func TestImageAnchorFindsTheBlockAnImageGoesBelow(t *testing.T) {+ export := []byte(`{"blocks":[+ {"id":"title","type":"heading","content":[{"type":"text","text":"Strawberry tattoos"}]},+ {"id":"intro","type":"paragraph","content":[{"type":"text","text":"Strawberries are "},{"type":"link","content":[{"type":"text","text":"popular"}]}]},+ {"id":"list","type":"bulletListItem","content":[{"type":"text","text":"Roman"}],"children":[{"id":"nested","type":"paragraph","content":[{"type":"text","text":"Venus"}]}]},+ {"id":"table","type":"table","content":{"type":"tableContent","rows":[]}},+ {"id":"again","type":"paragraph","content":[{"type":"text","text":"Strawberry"}]}+ ]}`)+ for after, want := range map[string][2]string{+ "": {"again", ""},+ "Strawberry tattoos": {"title", ""},+ "are popular": {"intro", ""},+ "Venus": {"list", ""},+ "Strawberry": {"again", ""},+ "Strawberr": {"", "ambiguous_text"},+ "Missing text": {"", "text_not_found"},+ } {+ if blockID, problem := ImageAnchor(export, after); blockID != want[0] || problem != want[1] {+ t.Fatalf("after %q = %q %q, want %q", after, blockID, problem, want)+ }+ }+ if _, problem := ImageAnchor([]byte(`{"blocks":[]}`), ""); problem != "document_empty" {+ t.Fatalf("empty document problem=%q", problem)+ }+}diff --git a/apps/teamhub/tests/integration/voice_live_test.go b/apps/teamhub/tests/integration/voice_live_test.goindex a4113b72..9ae4f4c7 100644--- a/apps/teamhub/tests/integration/voice_live_test.go+++ b/apps/teamhub/tests/integration/voice_live_test.go@@ -747,6 +747,12 @@ func TestVoiceLiveTasksReportResultsAndWhatTheyWaitFor(t *testing.T) {if countRows(t, env, `SELECT count(*) FROM messages WHERE room_id=$1 AND segments @> '[{"presentation":"canvas"}]'`, roomID) != 0 {t.Fatal("a document whose image was not read was opened")}+ // An image goes into an existing document from a folder the call may open.+ for path, want := range map[string]string{"./playground/workitem_unknown/a.png": "folder_not_found", image: "document_not_found"} {+ if output := tool("lt_doc", "image-"+want, "insert_document_image", map[string]any{"document_id": "document_missing", "path": path}); output["error"] != want {+ t.Fatalf("insert_document_image %s=%v, want %s", path, output, want)+ }+ }decode(t, voiceRuntimeCall(t, env, http.MethodGet, "/internal/v1/voice/sessions/"+sessionID+"/live-tasks", nil, http.StatusOK), &tasks)if len(tasks.Tasks) != 2 || tasks.Tasks[0].TaskId != first["task_id"] || *tasks.Tasks[0].Replies[0].Delivered {t.Fatalf("live tasks after an unposted card: %+v", tasks.Tasks)diff --git a/apps/voice-runtime/src/live-worker.ts b/apps/voice-runtime/src/live-worker.tsindex 64674267..c6be53e5 100644--- a/apps/voice-runtime/src/live-worker.ts+++ b/apps/voice-runtime/src/live-worker.ts@@ -70,7 +70,7 @@ const retryMs = 300;* hears its real result instead of a timeout.*/const confirmedWriteTimeoutMs = 60_000;-/** A card's files upload from the Computer for up to two minutes. */+/** A card's files, or an image put into a document, upload from the Computer for up to two minutes. */const sendCardTimeoutMs = 130_000;/** A local browser step may wake a sleeping Computer before it runs. */const browserTimeoutMs = 70_000;@@ -1575,7 +1575,7 @@ export class LiveVoiceWorker {const result = await this.client.executeLiveToolCall(request,AbortSignal.timeout(- call.name === "send_card"+ call.name === "send_card" || call.name === "insert_document_image"? sendCardTimeoutMs: parseArguments(call)?.confirmed === true? confirmedWriteTimeoutMsdiff --git a/apps/voice-runtime/src/realtime.ts b/apps/voice-runtime/src/realtime.tsindex c2fce22e..8040e8a9 100644--- a/apps/voice-runtime/src/realtime.ts+++ b/apps/voice-runtime/src/realtime.ts@@ -65,7 +65,7 @@ Pick the one place the answer or the work lives:- Chat, common knowledge, opinions, arithmetic: answer directly.${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. 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.+${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.- 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.