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(teamhub): run Linear reads without a confirmation card
muterCa1b4d19c2319
diff --git a/apps/teamhub-cli/README.md b/apps/teamhub-cli/README.mdindex fa900aef..df21db8a 100644--- a/apps/teamhub-cli/README.md+++ b/apps/teamhub-cli/README.md@@ -60,6 +60,6 @@ Mail `--markdown` is converted to HTML by TeamHub; only `--attach` adds attachmeGitHub reads the connected account, its repositories, issues and pull requests at once; `github comment` and `github create-issue` wait for the sponsor's confirmation card.-Other Connected Apps (such as Canva or Linear) have no dedicated commands and are called through `teamhub apps search/execute`.+Other Connected Apps (such as Canva or Linear) have no dedicated commands and are called through `teamhub apps search/execute`. TeamHub runs the tools it knows as reads at once, including Linear's list, get and search tools and a `LINEAR_RUN_QUERY_OR_MUTATION` document that declares only queries; every other call waits for the sponsor's confirmation card.`teamhub apps connect <app-key>` asks for access to any Connected App that supports Agent tools; without an authorized account it posts an authorization card in the current chat. `teamhub apps auto-reminders list|set` lists or toggles automatic reminders for the Sponsor's own connections.diff --git a/apps/teamhub/go.mod b/apps/teamhub/go.modindex f292af12..86e8fe58 100644--- a/apps/teamhub/go.mod+++ b/apps/teamhub/go.mod@@ -40,6 +40,7 @@ require (github.com/riverqueue/river/riverdriver/riverpgxv5 v0.49.0github.com/riverqueue/river/rivertype v0.49.0github.com/twitchtv/twirp v8.1.3+incompatible+ github.com/vektah/gqlparser/v2 v2.5.64google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaagoogle.golang.org/grpc v1.81.1)diff --git a/apps/teamhub/go.sum b/apps/teamhub/go.sumindex 5f3b410e..e50da31e 100644--- a/apps/teamhub/go.sum+++ b/apps/teamhub/go.sum@@ -14,6 +14,8 @@ github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEAgithub.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=github.com/adrg/frontmatter v0.2.0 h1:/DgnNe82o03riBd1S+ZDjd43wAmC6W35q67NHeLkPd4=github.com/adrg/frontmatter v0.2.0/go.mod h1:93rQCj3z3ZlwyxxpQioRKC1wDLto4aXHrbqIsnH9wmE=+github.com/agnivade/levenshtein v1.2.2 h1:fI8RgiztYX1Nn5pBHHqQ9EMCCklhrmXqPRIedFmx5M4=+github.com/agnivade/levenshtein v1.2.2/go.mod h1:QVVI16kDrtSuwcpd0p1+xMC6Z/VfhtCyDIjcwga4/DU=github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ=github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw=github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=@@ -291,6 +293,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkSgithub.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=+github.com/vektah/gqlparser/v2 v2.5.64 h1:N32yM6hQ6Kd5RdjCCEJsUrbCebVoA9yLLMOIa88Mkk0=+github.com/vektah/gqlparser/v2 v2.5.64/go.mod h1:nILRSUbsWDTuf8hSmAgFxuYh0SaMZdkvl6JSEbkJX8g=github.com/wlynxg/anet v0.0.5 h1:J3VJGi1gvo0JwZ/P1/Yc/8p63SoW98B5dHkYDmpgvvU=github.com/wlynxg/anet v0.0.5/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=github.com/yuin/goldmark v1.7.16 h1:n+CJdUxaFMiDUNnWC3dMWCIQJSkxH4uz3ZwQBkAlVNE=diff --git a/apps/teamhub/internal/agentconnectedapps/access.go b/apps/teamhub/internal/agentconnectedapps/access.goindex 8eab990a..85d7e343 100644--- a/apps/teamhub/internal/agentconnectedapps/access.go+++ b/apps/teamhub/internal/agentconnectedapps/access.go@@ -3,6 +3,11 @@// sponsor's confirmation.package agentconnectedapps+import (+ "github.com/vektah/gqlparser/v2/ast"+ "github.com/vektah/gqlparser/v2/parser"+)+// toolAccess is how TeamHub admits one provider tool call. The// generic `teamhub apps execute` and the wrapped connector commands submit// their calls to the same Execute, which decides here; neither the CLI nor@@ -22,23 +27,50 @@ const (accessWrite)-// accessOf classifies a provider tool by its exact slug.-func accessOf(slug string) toolAccess {+// linearGraphQLTool runs any GraphQL document against Linear, so its slug+// alone cannot say whether a call reads or writes.+const linearGraphQLTool = "LINEAR_RUN_QUERY_OR_MUTATION"++// accessOf classifies a provider tool call by its exact slug, and a Linear+// GraphQL call by the operations its document declares.+func accessOf(slug string, arguments map[string]any) toolAccess {switch {case readTools[slug]:return accessReadcase directWriteTools[slug]:return accessWrite+ case slug == linearGraphQLTool && onlyQueries(arguments["query_or_mutation"]):+ return accessReaddefault:return accessConfirm}}+// onlyQueries reports whether document is a GraphQL document whose operations+// are all queries. A document that does not parse, declares no operation, or+// declares a mutation or subscription is held like any other write.+func onlyQueries(document any) bool {+ text, ok := document.(string)+ if !ok {+ return false+ }+ parsed, err := parser.ParseQuery(&ast.Source{Input: text})+ if err != nil || len(parsed.Operations) == 0 {+ return false+ }+ for _, operation := range parsed.Operations {+ if operation.Operation != ast.Query {+ return false+ }+ }+ return true+}+// readTools are the provider reads the wrapped connector commands make,// including the draft reads TeamHub makes to build a send-draft card, plus the// Slack reads Agents make through the generic execute to find direct messages-// and the people in them. A read the generic execute names outside this list-// is held like a write.+// and the people in them, and the Linear reads, which have no wrapped command.+// A read the generic execute names outside this list is held like a write.var readTools = map[string]bool{"FAL_AI_GET_MODELS": true,"FAL_AI_GET_PRICING": true,@@ -74,6 +106,29 @@ var readTools = map[string]bool{"GOOGLEDRIVE_GET_FILE_METADATA": true,"HIGGSFIELD_MCP_JOB_STATUS": true,"HIGGSFIELD_MCP_MODELS_EXPLORE": true,+ "LINEAR_GET_ALL_LINEAR_TEAMS": true,+ "LINEAR_GET_ATTACHMENT": true,+ "LINEAR_GET_COMMENT": true,+ "LINEAR_GET_CURRENT_USER": true,+ "LINEAR_GET_CYCLES_BY_TEAM_ID": true,+ "LINEAR_GET_ISSUE_DEFAULTS": true,+ "LINEAR_GET_LINEAR_ISSUE": true,+ "LINEAR_GET_LINEAR_PROJECT": true,+ "LINEAR_GET_PROJECT_UPDATE": true,+ "LINEAR_LIST_COMMENTS": true,+ "LINEAR_LIST_ISSUES_BY_TEAM_ID": true,+ "LINEAR_LIST_ISSUE_DRAFTS": true,+ "LINEAR_LIST_LINEAR_CYCLES": true,+ "LINEAR_LIST_LINEAR_ISSUES": true,+ "LINEAR_LIST_LINEAR_LABELS": true,+ "LINEAR_LIST_LINEAR_PROJECTS": true,+ "LINEAR_LIST_LINEAR_STATES": true,+ "LINEAR_LIST_LINEAR_TEAMS": true,+ "LINEAR_LIST_LINEAR_USERS": true,+ "LINEAR_LIST_PROJECT_UPDATES": true,+ "LINEAR_SEARCH_ISSUES": true,+ "LINEAR_VALIDATE_CREDENTIAL": true,+ "LINEAR_WHO_AM_I": true,"NOTION_GET_PAGE_MARKDOWN": true,"NOTION_RETRIEVE_PAGE": true,"NOTION_SEARCH_NOTION_PAGE": true,diff --git a/apps/teamhub/internal/agentconnectedapps/access_test.go b/apps/teamhub/internal/agentconnectedapps/access_test.goindex 67a0fba6..064f1d74 100644--- a/apps/teamhub/internal/agentconnectedapps/access_test.go+++ b/apps/teamhub/internal/agentconnectedapps/access_test.go@@ -142,6 +142,64 @@ func TestExecuteRunsGitHubReadsAtOnce(t *testing.T) {}}+// Linear has no wrapped command, so Agents read it through the generic+// execute; each listed read runs without a card.+func TestExecuteRunsLinearReadsAtOnce(t *testing.T) {+ for _, slug := range []string{+ "LINEAR_LIST_LINEAR_PROJECTS", "LINEAR_LIST_LINEAR_ISSUES", "LINEAR_LIST_LINEAR_USERS",+ "LINEAR_GET_LINEAR_ISSUE", "LINEAR_SEARCH_ISSUES", "LINEAR_LIST_LINEAR_TEAMS",+ } {+ provider, ran, err := executeForTest(t, slug, "linear", map[string]any{})+ if err != nil || ran.Confirmation != nil || len(provider.executed) != 1 {+ t.Fatalf("%s: result=%+v err=%v executed=%v", slug, ran, err, provider.executed)+ }+ }+}++func TestExecuteRunsAReadOnlyLinearGraphQLDocumentAtOnce(t *testing.T) {+ for name, document := range map[string]string{+ "introspection": `query { __type(name: "Team") { fields { name } } }`,+ "shorthand": `{ viewer { id name } }`,+ "named with variables and a fragment": `+ query Members($team: String!) { team(id: $team) { members { nodes { ...person } } } }+ fragment person on User { id displayName active }`,+ "mutation only inside a string": `query { searchIssues(term: "mutation { issueDelete }") { nodes { id } } }`,+ "two queries": `query A { viewer { id } } query B { teams { nodes { id } } }`,+ } {+ provider, ran, err := executeForTest(t, linearGraphQLTool, "linear", map[string]any{"query_or_mutation": document, "variables": map[string]any{}})+ if err != nil || ran.Confirmation != nil || len(provider.executed) != 1 {+ t.Fatalf("%s: result=%+v err=%v executed=%v", name, ran, err, provider.executed)+ }+ }+}++func TestExecuteHoldsALinearGraphQLDocumentThatMayWrite(t *testing.T) {+ for name, arguments := range map[string]map[string]any{+ "mutation": {"query_or_mutation": `mutation { commentCreate(input: {issueId: "WHI-1", body: "hi"}) { success } }`},+ "query and mutation": {"query_or_mutation": `query A { viewer { id } } mutation B { issueArchive(id: "WHI-1") { success } }`},+ "subscription": {"query_or_mutation": `subscription { issueUpdated { id } }`},+ "commented keyword": {"query_or_mutation": "# query\nmutation { issueArchive(id: \"WHI-1\") { success } }"},+ "unparseable": {"query_or_mutation": `query { viewer { id }`},+ "fragment only": {"query_or_mutation": `fragment person on User { id }`},+ "not a string": {"query_or_mutation": map[string]any{"query": "{ viewer { id } }"}},+ "missing document": {"query": `{ viewer { id } }`},+ } {+ provider, held, err := executeForTest(t, linearGraphQLTool, "linear", arguments)+ if err != nil || held.Confirmation == nil || len(provider.executed) != 0 {+ t.Fatalf("%s: result=%+v err=%v executed=%v", name, held, err, provider.executed)+ }+ }+}++func TestExecuteHoldsLinearWritesForTheSponsorsCard(t *testing.T) {+ for _, slug := range []string{"LINEAR_CREATE_LINEAR_ISSUE", "LINEAR_CREATE_LINEAR_COMMENT", "LINEAR_UPDATE_ISSUE"} {+ provider, held, err := executeForTest(t, slug, "linear", map[string]any{"issue_id": "WHI-1", "body": "hi"})+ if err != nil || held.Confirmation == nil || len(provider.executed) != 0 {+ t.Fatalf("%s: result=%+v err=%v executed=%v", slug, held, err, provider.executed)+ }+ }+}+// cardTools are the final writes of the CLI's "confirm" commands. The// generic execute and the wrapped commands must both hold them.var cardTools = []string{@@ -154,7 +212,7 @@ var cardTools = []string{func TestAccessListsKeepConfirmedWritesHeld(t *testing.T) {for _, slug := range cardTools {- if accessOf(slug) != accessConfirm {+ if accessOf(slug, nil) != accessConfirm {t.Errorf("%s must wait for confirmation", slug)}}@@ -164,7 +222,7 @@ func TestAccessListsKeepConfirmedWritesHeld(t *testing.T) {}}for _, slug := range []string{"GMAIL_GET_DRAFT", "OUTLOOK_GET_MESSAGE", "OUTLOOK_LIST_OUTLOOK_ATTACHMENTS"} {- if accessOf(slug) != accessRead {+ if accessOf(slug, nil) != accessRead {t.Errorf("%s reads a draft for its card and must run at once", slug)}}diff --git a/apps/teamhub/internal/agentconnectedapps/service.go b/apps/teamhub/internal/agentconnectedapps/service.goindex 691936e4..6df0e74a 100644--- a/apps/teamhub/internal/agentconnectedapps/service.go+++ b/apps/teamhub/internal/agentconnectedapps/service.go@@ -306,7 +306,7 @@ func (s *Service) execute(ctx context.Context, input ExecuteInput, authorize funif _, err := s.pinnedTool(ctx, connection, input.ToolSlug, input.ToolVersion, "execute"); err != nil {return Result{}, err}- if accessOf(input.ToolSlug) == accessConfirm {+ if accessOf(input.ToolSlug, input.Arguments) == accessConfirm {return s.prepareConfirmation(ctx, connection, confirmationAction{ToolSlug: input.ToolSlug, ToolVersion: input.ToolVersion, Arguments: input.Arguments,})