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(voice): run the card CLI on Windows Desktop and scope ignored reports
LeoXinga194df36e1db
diff --git a/apps/computer/local-daemon/internal/daemon/playground_tools.go b/apps/computer/local-daemon/internal/daemon/playground_tools.goindex 57495851..4ebeab8a 100644--- a/apps/computer/local-daemon/internal/daemon/playground_tools.go+++ b/apps/computer/local-daemon/internal/daemon/playground_tools.go@@ -109,7 +109,9 @@ func (d *Daemon) sendPlaygroundCard(ctx context.Context, tenantID, agentID strinstrings.TrimSpace(card.Content) == "" || len(card.Files) > maxCardFiles {return nil, &playgroundFailure{"invalid_card", "A card needs a title, content and at most 5 files."}}- arguments := []string{"message", "card", "--title", card.Title, "--content", card.Content}+ // The body goes on stdin: the CLI decodes escapes such as \n in --content,+ // which the live model does not write for it.+ arguments := []string{"message", "card", "--title", card.Title, "--file", "-"}for _, requested := range card.Files {filename, err := d.contextViews.PlaygroundFilePath(ctx, tenantID, agentID, requested.Folder, requested.Path)if err != nil {@@ -122,19 +124,16 @@ func (d *Daemon) sendPlaygroundCard(ctx context.Context, tenantID, agentID strinif err != nil {return nil, err}- return d.runCardCLI(ctx, installation, roomID, arguments)+ return d.runCardCLI(ctx, installation, roomID, arguments, card.Content)}// 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) (map[string]any, error) {- if d.teamhubCLIBin == "" {+func (d *Daemon) runCardCLI(ctx context.Context, installation clicredential.Installation, roomID string, arguments []string, body string) (map[string]any, 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."}}- program := filepath.Join(d.teamhubCLIBin, "teamhub")- if runtime.GOOS == "windows" {- program += ".exe"- }home, err := os.MkdirTemp("", "linger-live-card-")if err != nil {return nil, err@@ -152,9 +151,10 @@ func (d *Daemon) runCardCLI(ctx context.Context, installation clicredential.Instif err := os.WriteFile(configPath, config, 0o600); err != nil {return nil, err}- command := exec.CommandContext(ctx, program, arguments...)+ command := exec.CommandContext(ctx, program, append(prefix, arguments...)...)command.Dir = home- command.Env = append(cardCLIEnvironment(os.Environ()), "TEAMHUB_CONFIG="+configPath, "TEAMHUB_PROFILE=live")+ command.Env = append(append(cardCLIEnvironment(os.Environ()), environment...), "TEAMHUB_CONFIG="+configPath, "TEAMHUB_PROFILE=live")+ command.Stdin = strings.NewReader(body)var stdout, stderr bytes.Buffercommand.Stdout, command.Stderr = &stdout, &stderrrunErr := command.Run()@@ -164,13 +164,42 @@ func (d *Daemon) runCardCLI(ctx context.Context, installation clicredential.Instif runErr != nil {var exit *exec.ExitErrorif !errors.As(runErr, &exit) {- return nil, runErr+ // 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 cardCommitResult(stdout.Bytes())}+// cardCLIProgram is how to start the bundled CLI in directory. The Computer+// bundle has a teamhub program on every platform. Desktop has only scripts on+// Windows; its teamhub.cmd is not run, since cmd.exe would parse the card's+// text, so the app it names runs teamhub.js as Node instead.+func cardCLIProgram(directory, goos string) (program string, prefix, environment []string, ok bool) {+ if directory == "" {+ return "", nil, nil, false+ }+ if goos != "windows" {+ program = filepath.Join(directory, "teamhub")+ return program, nil, nil, regularFile(program)+ }+ if program = filepath.Join(directory, "teamhub.exe"); regularFile(program) {+ return program, nil, nil, true+ }+ script := filepath.Join(directory, "teamhub.js")+ app := filepath.Join(directory, "..", "..", "..", "..", "Linger.exe")+ if !regularFile(script) || !regularFile(app) {+ return "", nil, nil, false+ }+ return filepath.Clean(app), []string{"--use-env-proxy", script}, []string{"ELECTRON_RUN_AS_NODE=1"}, true+}++func regularFile(name string) bool {+ info, err := os.Stat(name)+ return err == nil && info.Mode().IsRegular()+}+// cardCLIEnvironment is the daemon's environment without TeamHub settings,// so only the card's own profile applies; proxies still reach the CLI.func cardCLIEnvironment(environment []string) []string {diff --git a/apps/computer/local-daemon/internal/daemon/playground_tools_test.go b/apps/computer/local-daemon/internal/daemon/playground_tools_test.goindex a7921feb..3378f3c4 100644--- a/apps/computer/local-daemon/internal/daemon/playground_tools_test.go+++ b/apps/computer/local-daemon/internal/daemon/playground_tools_test.go@@ -22,7 +22,7 @@ func fakeCardCLI(t *testing.T, stdout, stderr string, exit int) (directory, recodirectory = t.TempDir()record = filepath.Join(t.TempDir(), "record")script := "#!/bin/sh\n" +- "{ printf '%s\\n' \"$@\"; echo ---; echo \"$TEAMHUB_PROFILE\"; cat \"$TEAMHUB_CONFIG\"; echo; echo ---; env | grep -c '^TEAMHUB_SECRET=' ; } > '" + record + "'\n" ++ "{ printf '%s\\n' \"$@\"; echo ---; echo \"$TEAMHUB_PROFILE\"; cat \"$TEAMHUB_CONFIG\"; echo; echo ---; env | grep -c '^TEAMHUB_SECRET=' ; echo ---; cat; } > '" + record + "'\n" +"printf '%s' '" + stdout + "'\nprintf '%s' '" + stderr + "' >&2\nexit " + string(rune('0'+exit)) + "\n"if err := os.WriteFile(filepath.Join(directory, "teamhub"), []byte(script), 0o755); err != nil {t.Fatal(err)@@ -37,7 +37,8 @@ func TestPlaygroundCardRunsTheCLIAsTheAgentInTheRoom(t *testing.T) {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",- []string{"message", "card", "--title", "Report", "--content", "Done.", "--attach", "/work/playground/task-1/report.md", "--operation-id", "voice-live:abc", "--json"})+ []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)}@@ -68,6 +69,9 @@ func TestPlaygroundCardRunsTheCLIAsTheAgentInTheRoom(t *testing.T) {if strings.TrimSpace(parts[2]) != "0" {t.Fatal("the daemon's own TeamHub settings reached the CLI")}+ if parts[3] != `Saved to C:\new\table.xlsx` {+ t.Fatalf("stdin body=%q", parts[3])+ }}func TestPlaygroundCardTellsWhyTheCLIFailed(t *testing.T) {@@ -77,7 +81,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"})+ _, err := (&Daemon{teamhubCLIBin: directory}).runCardCLI(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)@@ -87,7 +91,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{}).runCardCLI(t.Context(), cardInstallation, "room-1", nil, ""); !errors.As(err, &failure) || failure.code != "cli_unavailable" {t.Fatalf("no CLI = %v", err)}}@@ -110,3 +114,37 @@ func TestPlaygroundCardRefusesAnInvalidCardOrMissingCredential(t *testing.T) {t.Fatalf("credential = %v", err)}}++// Desktop ships only scripts beside its CLI on Windows; the card runs the app+// as Node rather than through cmd.exe.+func TestPlaygroundCardFindsTheCLIOnEveryLayout(t *testing.T) {+ touch := func(name string) {+ t.Helper()+ if err := os.MkdirAll(filepath.Dir(name), 0o700); err != nil {+ t.Fatal(err)+ }+ if err := os.WriteFile(name, nil, 0o700); err != nil {+ t.Fatal(err)+ }+ }+ bundle := t.TempDir()+ touch(filepath.Join(bundle, "teamhub.exe"))+ if program, prefix, _, ok := cardCLIProgram(bundle, "windows"); !ok || program != filepath.Join(bundle, "teamhub.exe") || prefix != nil {+ t.Fatalf("Computer bundle: %s %v %v", program, prefix, ok)+ }+ app := t.TempDir()+ desktop := filepath.Join(app, "resources", "app", "dist", "teamhub-cli")+ touch(filepath.Join(desktop, "teamhub.cmd"))+ touch(filepath.Join(desktop, "teamhub.js"))+ if _, _, _, ok := cardCLIProgram(desktop, "windows"); ok {+ t.Fatal("ran teamhub.cmd without the app beside it")+ }+ touch(filepath.Join(app, "Linger.exe"))+ program, prefix, environment, ok := cardCLIProgram(desktop, "windows")+ if !ok || program != filepath.Join(app, "Linger.exe") || len(prefix) != 2 || prefix[1] != filepath.Join(desktop, "teamhub.js") || environment[0] != "ELECTRON_RUN_AS_NODE=1" {+ t.Fatalf("Desktop: %s %v %v %v", program, prefix, environment, ok)+ }+ if _, _, _, ok := cardCLIProgram(t.TempDir(), "darwin"); ok {+ t.Fatal("found a CLI in an empty directory")+ }+}diff --git a/apps/teamhub/migrations/00862_live_voice_tells_its_task_reports.sql b/apps/teamhub/migrations/00862_live_voice_tells_its_task_reports.sqlindex 08c042ad..b8dbd325 100644--- a/apps/teamhub/migrations/00862_live_voice_tells_its_task_reports.sql+++ b/apps/teamhub/migrations/00862_live_voice_tells_its_task_reports.sql@@ -41,10 +41,16 @@ CREATE OR REPLACE FUNCTION public.agent_inbox_message_disposition(p_tenant text,FROM task_meta_messages messageWHERE starts_with(p_inbox,'meta:') AND message.id=p_message AND message.tenant_id=p_tenantUNION ALL- -- A report from a Task a call started is the live voice's to tell while the- -- call holds the Meta foreground; it never wakes the Meta as well.- SELECT CASE WHEN voice_live_owns_context(p_context)- AND EXISTS(SELECT 1 FROM voice_live_tasks task WHERE task.work_item_id=message.task_id)+ -- A report from a Task a call started is the live voice's to tell while+ -- its owner's call in that Room holds this Meta; it never wakes the Meta as+ -- well. Another user's call leaves it to the Meta.+ SELECT CASE WHEN EXISTS(SELECT 1 FROM voice_live_tasks task+ JOIN voice_sessions voice ON voice.room_id=task.room_id AND voice.created_by_actor_id=task.owner_actor_id+ JOIN agent_execution_contexts context ON context.context_key=p_context AND context.context_kind='meta'+ AND context.tenant_id=voice.tenant_id AND context.agent_actor_id=voice.live_agent_actor_id+ WHERE task.work_item_id=message.task_id AND voice.purpose='chat_live'+ AND voice.status IN ('provisioning','connected','reconnecting') AND voice.live_lease_until>now()+ AND (context.room_id=voice.room_id OR context.room_id=task.home_room_id))THEN 'ignore' ELSE 'notify' END,agent_inbox_directly_mentions(message.segments,p_agent)FROM task_meta_callback_messages messagediff --git a/apps/teamhub/tests/integration/agent_inbox_message_disposition_test.go b/apps/teamhub/tests/integration/agent_inbox_message_disposition_test.goindex 39da1e1a..5c64e291 100644--- a/apps/teamhub/tests/integration/agent_inbox_message_disposition_test.go+++ b/apps/teamhub/tests/integration/agent_inbox_message_disposition_test.go@@ -126,6 +126,15 @@ INSERT INTO task_meta_callback_messages(id,task_id,tenant_id,generation,meta_seqt.Fatal(err)}check(t, []dispositionCase{{"a call's Task report during the call", env.contextKey, "taskmeta:" + taskID, "d-callback", "ignore", true}})+ // Another user's call in the Room does not tell this Task's owner.+ seedPeerHumanActor(t, env.pool)+ if _, err := env.pool.Exec(t.Context(), `UPDATE voice_live_tasks SET owner_actor_id='actor_acme_bob' WHERE work_item_id=$1`, taskID); err != nil {+ t.Fatal(err)+ }+ check(t, []dispositionCase{{"a Task report during another user's call", env.contextKey, "taskmeta:" + taskID, "d-callback", "notify", true}})+ if _, err := env.pool.Exec(t.Context(), `UPDATE voice_live_tasks SET owner_actor_id='actor_acme_alice' WHERE work_item_id=$1`, taskID); err != nil {+ t.Fatal(err)+ }if _, err := env.pool.Exec(t.Context(), `UPDATE voice_sessions SET live_lease_until=clock_timestamp()-interval '1 second' WHERE id='voice-handover'`); err != nil {t.Fatal(err)}