diff --git a/go.sum b/go.sum index 7a01a2ac2..603941f7e 100644 --- a/go.sum +++ b/go.sum @@ -8,12 +8,14 @@ code.gitea.io/sdk/gitea v0.25.1 h1:yywxWwoV+SdjHtbC6unBiXojWdZOtoHuGhEazEXeWuE= code.gitea.io/sdk/gitea v0.25.1/go.mod h1:uDFWYBU8dgZsgOHwe6C/6olxvf8FHguNB3wW1i83fgg= github.com/42wim/httpsig v1.2.4 h1:mI5bH0nm4xn7K18fo1K3okNDRq8CCJ0KbBYWyA6r8lU= github.com/42wim/httpsig v1.2.4/go.mod h1:yKsYfSyTBEohkPik224QPFylmzEBtda/kjyIAJjh3ps= +github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk= github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/ProtonMail/go-crypto v1.4.1 h1:9RfcZHqEQUvP8RzecWEUafnZVtEvrBVL9BiF67IQOfM= github.com/ProtonMail/go-crypto v1.4.1/go.mod h1:e1OaTyu5SYVrO9gKOEhTc+5UcXtTUa+P3uLudwcgPqo= +github.com/a-h/templ v0.3.1020/go.mod h1:A2DlK61v+K+NRoGnhmYbNYVmtYHcFO5/AisMvBdDxTM= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= github.com/antithesishq/antithesis-sdk-go v0.8.0 h1:bVV5ZAuwaREn4klRSJusYaA+A7NXq8Qi9C/knCaQ2N4= @@ -22,6 +24,7 @@ github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYW github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= +github.com/bwesterb/go-ristretto v1.2.4/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cloudflare/circl v1.6.5 h1:O64F26HEqNhznd/hrC5KZXVKYuKM2rx4deZDTc4ihQA= @@ -30,6 +33,8 @@ github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG github.com/containerd/errdefs v1.0.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M= github.com/containerd/errdefs/pkg v0.3.0 h1:9IKJ06FvyNlexW690DXuQNx2KA2cUJXx151Xdx3ZPPE= github.com/containerd/errdefs/pkg v0.3.0/go.mod h1:NJw6s9HwNuRhnjJhM7pylWwMyAkmCQvQ4GpJHEqRLVk= +github.com/containerd/typeurl/v2 v2.2.0/go.mod h1:8XOOxnyatxSWuG8OfsZXVnAF4iZfedjS/8UHSPJnX4g= +github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454WvHn0= @@ -63,8 +68,11 @@ github.com/go-logr/logr v1.4.4 h1:tG4xh9yMsRCAiodLVTxyrkzSZ9+o0L1Kg/+cPVcbP/8= github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow= github.com/go-telegram/bot v1.25.0 h1:C072msZtr+GjJiQsX/UJLirz+jzSNZVWkckxWufR7Ww= github.com/go-telegram/bot v1.25.0/go.mod h1:i2TRs7fXWIeaceF3z7KzsMt/he0TwkVC680mvdTFYeM= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/codesearch v1.3.0-rc.1 h1:vSFGuF5wS3sjimuLzqPG+PGjWQ9VvEtPFbxdZD7YuuQ= github.com/google/codesearch v1.3.0-rc.1/go.mod h1:hKdpx7wOsvk2WLT/D6NLPxFeLT8jKCehZu21JpA2rIY= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= @@ -76,6 +84,7 @@ github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfh github.com/google/go-querystring v1.2.0/go.mod h1:8IFJqpSRITyJ8QhQ13bmbeMBDfmeEJZD5A0egEOmkqU= github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo= github.com/google/go-tpm v0.9.8/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY= +github.com/google/go-tpm-tools v0.3.13-0.20230620182252-4639ecce2aba/go.mod h1:EFYHy8/1y2KfgTAsx7Luu7NGhoxtuVHnNo8jE7FikKc= github.com/google/pprof v0.0.0-20260802141513-ef3492d7dac3 h1:LMLX+LgTNWpfvCBdFebv6EsYotImrt/Ppc5cXIriCSo= github.com/google/pprof v0.0.0-20260802141513-ef3492d7dac3/go.mod h1:jl5iWTm0/hd5PjEYEOuwAJ57L/CibdZfrqZ5XA5GrCk= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -111,6 +120,7 @@ github.com/moby/moby/client v0.5.1 h1:tYNaJno4c0HXz12y5BiqEDy0rVTYkWzI26lGvnTMiJ github.com/moby/moby/client v0.5.1/go.mod h1:odLstlZ6uSnfvAgVxMpvgmb8SUdd+siH2T0GBuxVAlM= github.com/moby/moby/client v0.6.0 h1:AJjEB21QPbXSXjDsZorFBoDZPhMrfbpaPLgSMAW9Bgs= github.com/moby/moby/client v0.6.0/go.mod h1:OCo00wNRyA3m4lmJ228W3JbyCN4ZNNYjpOXiJydBdcQ= +github.com/moby/term v0.5.2/go.mod h1:d3djjFCrjnB+fl8NJux+EJzu0msscUP+f8it8hPkFLc= github.com/nats-io/jwt/v2 v2.8.2 h1:XXRgB60MSTnqsRwejQurVDs/hcv2dkt+86GjI+I/bMc= github.com/nats-io/jwt/v2 v2.8.2/go.mod h1:Ag/56sq9OblL4JgdYufDd16Egb17Kr/8WwwuO/forVc= github.com/nats-io/nats-server/v2 v2.14.6 h1:dHjEHa49lUTxIb5jrsk5kz/AmOyOQ4T9ti8djcBumDQ= @@ -136,10 +146,13 @@ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94 github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= +github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY= github.com/samcharles93/ai-sdk v0.1.32 h1:rfBpWUOADuRTaq2kyCnMjdhtlFfaqUbsyL5DbIluqmA= github.com/samcharles93/ai-sdk v0.1.32/go.mod h1:u4zrQ9/Q58L5mNEut4bNQ1ks+RCKq71LN5EDz2N/0Zk= +github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY= github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw= github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE= @@ -174,6 +187,7 @@ golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa/go.mod h1:zeBbvyFKDaLwa7CH/z golang.org/x/mod v0.38.0 h1:MECBjubtXD7yj4HrhIUcywNaGeNVUdfVnxmPajOk4yk= golang.org/x/mod v0.38.0/go.mod h1:V6Xz0pq8TQ3dGqVQ1FVHuelZpAL0uNhSkk9ogYP3c40= golang.org/x/mod v0.39.0 h1:UF5zwQdCRRUpHfyPwr7d4UrGiVeldIsogtzWVnczL74= +golang.org/x/mod v0.39.0/go.mod h1:bvIbwjQ0HUFFf5AKukeeYQG4ZBUG9yxQbR9aEweIwYY= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.58.0 h1:ynWG7rqYi4ccpTEuPZ2QGWHktVEM9DMCj9yzDE0Q7To= @@ -200,6 +214,9 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.48.0 h1:3+hClM1aLL5mjMKm5ovokw9epgRXPuu2tILgismM6RE= golang.org/x/tools v0.48.0/go.mod h1:08xX0orndb/F7jJxGDicx061tyd5pcMto75YMAXr6lk= golang.org/x/tools v0.49.0 h1:3NI7VXzL9+1WZD52Dx2ttoPwD5DWrFGpl9mFZDlmisI= +golang.org/x/tools v0.49.0/go.mod h1:SJNXV9DBKT0UbdttsQjbfJlAE/q+y36++zo3uL3N0Oo= +golang.org/x/tools/go/expect v0.1.1-deprecated/go.mod h1:eihoPOH+FgIqa3FpoTwguz/bVUSGBlGQU67vpBeOrBY= +golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated/go.mod h1:RVAQXBGNv1ib0J382/DPCRS/BPnsGebyM1Gj5VSDpG8= google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 h1:YcyjlL1PRr2Q17/I0dPk2JmYS5CDXfcdb2Z3YRioEbw= google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7/go.mod h1:OCdP9MfskevB/rbYvHTsXTtKC+3bHWajPdoKgjcYkfo= google.golang.org/genproto/googleapis/api v0.0.0-20260904194346-d0f1323225a4 h1:NCe/UiklGd/9xjT+ROBVhJ1kf6TRQaFedsR+z7u1gvo= @@ -208,6 +225,7 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1: google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= google.golang.org/genproto/googleapis/rpc v0.0.0-20260904194346-d0f1323225a4 h1:5t+ZydAFj5kGVLrgCvLmpmCf9ylGRd64hpEronfRaws= google.golang.org/genproto/googleapis/rpc v0.0.0-20260904194346-d0f1323225a4/go.mod h1:DjtHYE8FKJLivXcBEjGwndXfIC23G0VpXiXKqG179uA= +google.golang.org/grpc v1.83.1/go.mod h1:kDyl6SKsiHKt0uylY5gtn5cEjkrIOhQOGDgIc4JGwzQ= google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE= google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc= diff --git a/internal/app/archied/chat_env_test.go b/internal/app/archied/chat_env_test.go new file mode 100644 index 000000000..e027c1e17 --- /dev/null +++ b/internal/app/archied/chat_env_test.go @@ -0,0 +1,76 @@ +package archied + +import ( + "testing" + + "github.com/samcharles93/archie-core/internal/config" +) + +func TestChatRepoEnvSingleIdentity(t *testing.T) { + cfg := config.Config{ + Forge: config.Forge{Host: "https://github.com", Type: "github"}, + Repos: []config.Repo{ + {Owner: "my-org", Name: "frontend-app", Base: "develop"}, + {Owner: "my-org", Name: "backend-api"}, + }, + } + got := chatRepoEnv(cfg, "") + if len(got) != 2 { + t.Fatalf("expected 2 repos, got %d", len(got)) + } + if got[0].FullName != "my-org/frontend-app" || got[0].Forge != "https://github.com" || got[0].DefaultBranch != "develop" { + t.Errorf("repo 0 mismatch: %+v", got[0]) + } + // Base empty -> the daemon's effective default branch (main), not a guess. + if got[1].DefaultBranch != "main" { + t.Errorf("expected default branch main, got %q", got[1]) + } +} + +func TestChatRepoEnvMultiIdentityMatchesActive(t *testing.T) { + cfg := config.Config{ + Identities: []config.IdentityConfig{ + {Name: "alpha", Forge: config.Forge{Host: "https://gitea.example.com"}, Repos: []config.Repo{{Owner: "alpha", Name: "app"}}}, + {Name: "beta", Forge: config.Forge{Host: "https://github.com"}, Repos: []config.Repo{{Owner: "beta", Name: "svc"}}}, + }, + } + got := chatRepoEnv(cfg, "beta") + if len(got) != 1 || got[0].FullName != "beta/svc" || got[0].Forge != "https://github.com" { + t.Fatalf("expected the active identity's scope, got %+v", got) + } +} + +func TestChatRepoEnvMultiIdentityFallsBackToFirstWithRepos(t *testing.T) { + cfg := config.Config{ + Identities: []config.IdentityConfig{ + {Name: "a", Forge: config.Forge{}, Repos: nil}, + {Name: "b", Forge: config.Forge{Host: "https://github.com"}, Repos: []config.Repo{{Owner: "b", Name: "svc"}}}, + }, + } + got := chatRepoEnv(cfg, "no-such-identity") + if len(got) != 1 || got[0].FullName != "b/svc" { + t.Fatalf("expected fallback to the first identity with repos, got %+v", got) + } +} + +func TestChatRepoEnvPreservesEmptyForge(t *testing.T) { + cfg := config.Config{ + Repos: []config.Repo{{Owner: "acme", Name: "widgets"}}, + } + got := chatRepoEnv(cfg, "") + if len(got) != 1 { + t.Fatalf("expected 1 repo, got %d", len(got)) + } + if got[0].Forge != "" { + t.Errorf("expected empty forge to be preserved (so the prompt renders 'forge unknown'), got %q", got[0].Forge) + } + if got[0].DefaultBranch != "main" { + t.Errorf("expected default branch main, got %q", got[0].DefaultBranch) + } +} + +func TestChatRepoEnvEmpty(t *testing.T) { + if got := chatRepoEnv(config.Config{}, ""); len(got) != 0 { + t.Fatalf("expected no repos, got %+v", got) + } +} diff --git a/internal/app/archied/telegram_setup.go b/internal/app/archied/telegram_setup.go index ba91a5dba..f88953ce5 100644 --- a/internal/app/archied/telegram_setup.go +++ b/internal/app/archied/telegram_setup.go @@ -332,6 +332,8 @@ func newChatTurnRunner( BotUser: cfg.BotUser, Channel: channel, Operator: cfg.Chat.Operator, + Workspace: cfg.Chat.Workspace, + Repos: chatRepoEnv(cfg, s.DefaultChatIdentity), Log: s.Log, }) if err := runner.Recover(ctx); err != nil && s.Log != nil { @@ -340,6 +342,38 @@ func newChatTurnRunner( return runner } +// chatRepoEnv renders the repositories the chat agent manages, with their +// forge host and default branch, into the prompt's block so the agent +// knows its scope without probing the filesystem. It follows the same +// identity resolution as chatTaskProfiles: when identities are configured, +// the one matching the active chat identity wins (falling back to the first +// identity with repositories, which is what chatTaskProfiles selects as the +// default); otherwise the single-identity repositories are used. +func chatRepoEnv(cfg config.Config, identity string) []gateway.RepoEnv { + repos, forge := cfg.Repos, cfg.Forge + if len(cfg.Identities) > 0 { + repos, forge = nil, config.Forge{} + for _, id := range cfg.Identities { + if id.Name == identity { + repos, forge = id.Repos, id.Forge + break + } + if len(repos) == 0 && len(id.Repos) > 0 { + repos, forge = id.Repos, id.Forge + } + } + } + env := make([]gateway.RepoEnv, 0, len(repos)) + for _, repo := range repos { + env = append(env, gateway.RepoEnv{ + FullName: repo.FullName(), + Forge: forge.Host, + DefaultBranch: repo.BaseBranch(), + }) + } + return env +} + func sendChatTurn(ctx context.Context, llm *runtime.Runtime, chatModel string, options core.GenerateOptions, turn gateway.TurnStream) (string, error) { if turn == nil { result, err := llm.Chat(ctx, chatModel, options) diff --git a/internal/gateway/prompt.go b/internal/gateway/prompt.go index 19ff480f1..e7c51c572 100644 --- a/internal/gateway/prompt.go +++ b/internal/gateway/prompt.go @@ -17,6 +17,22 @@ type ToolSummary struct { Description string } +// RepoEnv is the runtime-metadata summary of one repository under +// management, rendered into the chat prompt's block so the agent knows +// which checkouts it is responsible for without probing the filesystem. It is +// built only from live configuration; it never names a repository the daemon +// cannot confirm. +type RepoEnv struct { + // FullName is the configured owner/name. + FullName string + // Forge is the forge host the repository lives on (forge.host). Empty + // means no forge is configured for the active identity. + Forge string + // DefaultBranch is the branch PRs target (repos[].base, "main" when + // unset) -- the branch the daemon actually uses, not a guess. + DefaultBranch string +} + // SystemPromptConfig holds the inputs for one rendered system prompt. type SystemPromptConfig struct { // Persona is the active persona prompt. @@ -35,6 +51,19 @@ type SystemPromptConfig struct { Page string // Now stamps the prompt's date. Now time.Time + // Workspace is the directory the chat agent's file and shell tools are + // rooted at (chat.workspace). Empty means the agent has no rooted + // workspace: a real fact the prompt must say explicitly ("unknown") so the + // agent does not guess a path the daemon never granted it. + Workspace string + // Repos lists the repositories under management with their forge host and + // default branch. Rendered from live configuration (repos entries) so the + // agent knows its scope without probing the filesystem. + Repos []RepoEnv + // Operator is the display name of the person this deployment assists + // (chat.operator). Rendered so the agent knows the identity context it + // serves under; empty means unconfigured and must be said explicitly. + Operator string } // promptData is the template execution context. It exists so the template @@ -73,6 +102,9 @@ func BuildSystemPrompt(cfg SystemPromptConfig) string { Page: cfg.Page, Now: cfg.Now, Date: cfg.Now.Format("2006-01-02"), + Workspace: cfg.Workspace, + Repos: cfg.Repos, + Operator: cfg.Operator, } var buf strings.Builder if err := archiePromptTemplate.Execute(&buf, data); err != nil { diff --git a/internal/gateway/prompt_test.go b/internal/gateway/prompt_test.go index 9dafbd1d6..f3ced52c1 100644 --- a/internal/gateway/prompt_test.go +++ b/internal/gateway/prompt_test.go @@ -120,6 +120,55 @@ func TestBuildSystemPromptSections(t *testing.T) { "Current page:", }, }, + { + name: "env block carries workspace, managed repositories and operator", + cfg: SystemPromptConfig{ + Now: fixedTime(t), + Channel: "telegram", + Workspace: "/work/apps/archie-core", + Operator: "Sam", + Repos: []RepoEnv{ + {FullName: "samcharles93/archie-core", Forge: "https://github.com", DefaultBranch: "main"}, + {FullName: "my-org/frontend-app", Forge: "https://github.com", DefaultBranch: "develop"}, + }, + }, + contains: []string{ + " diff --git a/internal/gateway/turn.go b/internal/gateway/turn.go index cf9b11a37..22f5176d6 100644 --- a/internal/gateway/turn.go +++ b/internal/gateway/turn.go @@ -90,7 +90,13 @@ type TurnRunnerConfig struct { BotUser string Channel string Operator string - Log *slog.Logger + // Workspace is the directory the chat agent's file and shell tools are + // rooted at (chat.workspace). Passed into the prompt's block. + Workspace string + // Repos lists the repositories under management with their forge host and + // default branch, rendered into the prompt's block. + Repos []RepoEnv + Log *slog.Logger } // TurnRunner owns one chat turn from session resolution through model @@ -313,6 +319,9 @@ func (r *TurnRunner) prepareTurn(ctx context.Context, sessionID string, msg Mess SessionID: sessionID, Now: time.Now(), Page: msg.Page, + Workspace: r.Workspace, + Repos: r.Repos, + Operator: r.Operator, }) compression, err := CompressionConfigForModel( modelDetails,