Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(workflows): let the ai task step pick several repositories (#126157)

Harley Alexandere795bb567a2e
diff --git a/nodejs/src/cdp/templates/_destinations/posthog_tasks/posthog-create-task.template.test.ts b/nodejs/src/cdp/templates/_destinations/posthog_tasks/posthog-create-task.template.test.ts
index 3c133e3e61e3..5ddbf9f8d824 100644
--- a/nodejs/src/cdp/templates/_destinations/posthog_tasks/posthog-create-task.template.test.ts
+++ b/nodejs/src/cdp/templates/_destinations/posthog_tasks/posthog-create-task.template.test.ts
@@ -14,7 +14,7 @@ describe('posthog create task template', () => {
prompt: 'Investigate the error spike in checkout',
title: 'Checkout error spike',
model: { model: 'claude-sonnet-5', reasoning_effort: 'high' },
- repository: 'example-org/example-repo',
+ repository: ['example-org/example-repo', 'example-org/example-docs'],
connectors: ['0198c9f1-aaaa-0000-0000-000000000001'],
skills: ['error-triage', 'db-runbook'],
posthog_mcp_scopes: 'full',
@@ -77,7 +77,7 @@ describe('posthog create task template', () => {
title: 'Checkout error spike',
model: 'claude-sonnet-5',
reasoning_effort: 'high',
- repository: 'example-org/example-repo',
+ repositories: ['example-org/example-repo', 'example-org/example-docs'],
connectors: ['0198c9f1-aaaa-0000-0000-000000000001'],
skills: ['error-triage', 'db-runbook'],
posthog_mcp_scopes: 'full',
@@ -111,6 +111,12 @@ describe('posthog create task template', () => {
})
})
+ it('sends a repository saved as a single string as a one-item list', async () => {
+ const { params } = await invokeAndGetFetch({ prompt: 'Do the thing', repository: 'example-org/example-repo' })
+
+ expect(parseJSON(params.body!).repositories).toEqual(['example-org/example-repo'])
+ })
+
it('asks the agent for the fields the output variables read from the output', async () => {
const hogFlow = {
...workflowOptions.hogFlow,
diff --git a/nodejs/src/cdp/templates/_destinations/posthog_tasks/posthog-create-task.template.ts b/nodejs/src/cdp/templates/_destinations/posthog_tasks/posthog-create-task.template.ts
index b9874f969b87..13bfac08398c 100644
--- a/nodejs/src/cdp/templates/_destinations/posthog_tasks/posthog-create-task.template.ts
+++ b/nodejs/src/cdp/templates/_destinations/posthog_tasks/posthog-create-task.template.ts
@@ -34,7 +34,8 @@ if (not empty(inputs.model) and not empty(inputs.model.model)) {
}
if (not empty(inputs.repository)) {
- payload.repository := inputs.repository
+ // Steps saved before the picker allowed several repositories hold one owner/repo string.
+ payload.repositories := typeof(inputs.repository) == 'array' ? inputs.repository : [inputs.repository]
}
if (not empty(inputs.connectors)) {
@@ -110,11 +111,11 @@ return task
{
key: 'repository',
type: 'task_repository',
- label: 'Repository',
+ label: 'Repositories',
secret: false,
required: false,
description:
- 'GitHub repository the agent works in, e.g. your-org/your-repo. Leave empty for no repository.',
+ 'GitHub repositories the agent can work in, e.g. your-org/your-repo. Leave empty to give the agent no repository access.',
},
{
key: 'connectors',
diff --git a/nodejs/tests/fixtures/hog-bytecode/81ec6582e4ffd35c4cf674d8d740a091f0e384ae7c08d4ee050ed3c05bc3d2e5.json b/nodejs/tests/fixtures/hog-bytecode/81ec6582e4ffd35c4cf674d8d740a091f0e384ae7c08d4ee050ed3c05bc3d2e5.json
new file mode 100644
index 000000000000..cb61153354c0
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/81ec6582e4ffd35c4cf674d8d740a091f0e384ae7c08d4ee050ed3c05bc3d2e5.json
@@ -0,0 +1 @@
+["_H",1,32,"example-org/example-docs",38]
diff --git a/nodejs/tests/fixtures/hog-bytecode/d91c92911704734156eb330b38e1c0432ace2b4cb468a9fde0711671167ee4dc.json b/nodejs/tests/fixtures/hog-bytecode/d91c92911704734156eb330b38e1c0432ace2b4cb468a9fde0711671167ee4dc.json
new file mode 100644
index 000000000000..052e1a5e54cc
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/d91c92911704734156eb330b38e1c0432ace2b4cb468a9fde0711671167ee4dc.json
@@ -0,0 +1 @@
+["_H",1,52,"apiErrorMessage",1,0,28,36,0,32,"body",45,32,"error",45,47,9,35,36,0,32,"body",45,32,"detail",45,47,6,35,36,0,32,"body",45,38,53,0,32,"prompt",32,"inputs",1,2,2,"empty",1,40,6,32,"Instructions are required",2,"Error",1,49,32,"prompt",32,"prompt",32,"inputs",1,2,32,"event",32,"event",1,1,42,2,32,"title",32,"inputs",1,2,2,"empty",1,5,40,11,36,1,32,"title",32,"title",32,"inputs",1,2,46,32,"model",32,"inputs",1,2,2,"empty",1,5,32,"model",32,"model",32,"inputs",1,3,2,"empty",1,5,3,2,40,40,36,1,32,"model",32,"model",32,"model",32,"inputs",1,3,46,32,"reasoning_effort",32,"model",32,"inputs",1,3,2,"empty",1,5,40,13,36,1,32,"reasoning_effort",32,"reasoning_effort",32,"model",32,"inputs",1,3,46,32,"repository",32,"inputs",1,2,2,"empty",1,5,40,35,36,1,32,"repositories",32,"array",32,"repository",32,"inputs",1,2,2,"typeof",1,11,40,8,32,"repository",32,"inputs",1,2,39,8,32,"repository",32,"inputs",1,2,43,1,46,32,"connectors",32,"inputs",1,2,2,"empty",1,5,40,11,36,1,32,"connectors",32,"connectors",32,"inputs",1,2,46,32,"channel",32,"inputs",1,2,2,"empty",1,5,40,11,36,1,32,"channel",32,"channel",32,"inputs",1,2,46,32,"skills",32,"inputs",1,2,2,"empty",1,5,40,11,36,1,32,"skills",32,"skills",32,"inputs",1,2,46,32,"posthog_mcp_scopes",32,"inputs",1,2,2,"empty",1,5,40,11,36,1,32,"posthog_mcp_scopes",32,"posthog_mcp_scopes",32,"inputs",1,2,46,32,"max_parallel_tasks",32,"inputs",1,2,2,"empty",1,5,40,11,36,1,32,"max_parallel_tasks",32,"max_parallel_tasks",32,"inputs",1,2,46,30,32,"reply_in_slack_thread",32,"inputs",1,2,12,32,"$slack_message_received",32,"event",32,"event",1,2,11,32,"channel",32,"properties",32,"event",1,3,2,"empty",1,5,32,"ts",32,"properties",32,"event",1,3,2,"empty",1,5,3,4,40,102,36,1,32,"slack_context",32,"integration_id",32,"integration_id",32,"properties",32,"event",1,3,32,"channel",32,"channel",32,"properties",32,"event",1,3,32,"thread_ts",32,"thread_ts",32,"properties",32,"event",1,3,47,9,35,32,"ts",32,"properties",32,"event",1,3,32,"message_ts",32,"ts",32,"properties",32,"event",1,3,32,"slack_user_id",32,"user",32,"properties",32,"event",1,3,47,3,35,32,"",32,"slack_team_id",32,"slack_team_id",32,"properties",32,"event",1,3,47,3,35,32,"",32,"is_ext_shared_channel",32,"is_ext_shared_channel",32,"properties",32,"event",1,3,47,2,35,30,42,7,46,36,1,2,"postHogCreateTask",1,33,400,36,2,32,"status",45,14,40,22,32,"Failed to create task (",36,2,32,"status",45,32,"): ",36,2,36,0,54,1,2,"concat",4,2,"Error",1,49,36,2,32,"body",45,36,3,32,"run_id",45,2,"empty",1,5,40,15,36,3,32,"await",32,"max_wait",32,"190m",32,"label",32,"task",42,2,46,36,3,38,35,35,35,35]
diff --git a/products/cdp/backend/test/test_validation.py b/products/cdp/backend/test/test_validation.py
index fb45b2764a76..71f041a5908b 100644
--- a/products/cdp/backend/test/test_validation.py
+++ b/products/cdp/backend/test/test_validation.py
@@ -1489,7 +1489,10 @@ class TestTaskInputTypeValidation(SimpleTestCase):
@parameterized.expand(
[
("repository_string", "task_repository", "example-org/example-repo", True),
+ ("repository_list", "task_repository", ["example-org/example-repo", "example-org/example-docs"], True),
("repository_not_string", "task_repository", 123, False),
+ ("repository_list_not_strings", "task_repository", [{"name": "example-org/example-repo"}], False),
+ ("repository_list_too_long", "task_repository", [f"example-org/repo-{i}" for i in range(11)], False),
("model_full", "task_model", {"model": "claude-sonnet-5", "reasoning_effort": "high"}, True),
("model_without_effort", "task_model", {"model": "claude-sonnet-5"}, True),
("model_not_dict", "task_model", "claude-sonnet-5", False),
diff --git a/products/cdp/backend/validation.py b/products/cdp/backend/validation.py
index 25953db69c7a..eadfba5a5f2c 100644
--- a/products/cdp/backend/validation.py
+++ b/products/cdp/backend/validation.py
@@ -50,6 +50,8 @@ logger = logging.getLogger(__name__)
CORE_SUPPORTED_FUNCTIONS = {"fetch", "postHogCapture"}
MAX_WORKFLOW_EMAIL_SENDERS = 10
+# Matches the cap the tasks API puts on a task's repositories.
+MAX_TASK_REPOSITORIES = 10
# The mask the UI shows in place of a stored secret. A re-save that did not touch the secret
# sends this back, meaning "keep the stored value". It must never be persisted as a real secret.
@@ -813,8 +815,17 @@ class InputsItemSerializer(serializers.Serializer):
raise serializers.ValidationError({"input": "Value must be a list of Integration IDs."})
_validate_not_posthog_connection(value, self.context)
elif item_type == "task_repository":
- if not isinstance(value, str):
- raise serializers.ValidationError({"input": "Value must be a repository name like your-org/your-repo."})
+ repositories = [value] if isinstance(value, str) else value
+ if (
+ not isinstance(repositories, list)
+ or not all(isinstance(v, str) for v in repositories)
+ or len(repositories) > MAX_TASK_REPOSITORIES
+ ):
+ raise serializers.ValidationError(
+ {
+ "input": f"Value must be a list of up to {MAX_TASK_REPOSITORIES} repository names like your-org/your-repo."
+ }
+ )
elif item_type == "task_model":
# A non-empty value means a model was chosen (an empty value returned above as "use the
# default model"), so it must name a usable model. Otherwise the run-time consumer drops
diff --git a/products/tasks/backend/logic/services/workflow_tasks.py b/products/tasks/backend/logic/services/workflow_tasks.py
index 8f5566794104..11a186a6b60c 100644
--- a/products/tasks/backend/logic/services/workflow_tasks.py
+++ b/products/tasks/backend/logic/services/workflow_tasks.py
@@ -156,7 +156,7 @@ def create_workflow_task(
prompt: str,
title: str | None = None,
channel_ref: str | None = None,
- repository: str | None = None,
+ repositories: list[str] | None = None,
model: str | None = None,
reasoning_effort: str | None = None,
connector_ids: list[str] | None = None,
@@ -377,10 +377,10 @@ def create_workflow_task(
origin_product=Task.OriginProduct.WORKFLOW,
user_id=owner_id,
channel=channel,
- repository=repository,
+ repositories=repositories,
mode="background",
# A task with no repository has nothing to open a PR from.
- create_pr=bool(repository),
+ create_pr=bool(repositories),
posthog_mcp_scopes=posthog_mcp_scopes,
hog_flow_id=hog_flow_id,
origin_key=origin_key,
diff --git a/products/tasks/backend/tests/test_workflow_tasks_api.py b/products/tasks/backend/tests/test_workflow_tasks_api.py
index c4eebf597a3f..c2f99dec7272 100644
--- a/products/tasks/backend/tests/test_workflow_tasks_api.py
+++ b/products/tasks/backend/tests/test_workflow_tasks_api.py
@@ -35,7 +35,10 @@ from products.tasks.backend.models import Channel, Task, TaskRun
from products.tasks.backend.visibility import task_control_q, task_visibility_q
from products.workflows.backend.facade.team_extension import TeamWorkflowsConfig
from products.workflows.backend.facade.testing import create_workflow_for_test
-from products.workflows.backend.presentation.views.workflow_tasks import WorkflowTasksJWTAuthentication
+from products.workflows.backend.presentation.views.workflow_tasks import (
+ WorkflowTaskCreateSerializer,
+ WorkflowTasksJWTAuthentication,
+)
SECRET = "test-tasks-create-jwt"
@@ -595,18 +598,24 @@ class TestWorkflowTasksAPI(APIBaseTest):
assert later_run.state["config_snapshot"]["connectors"]["mcp_gateway_server_ids"] == ["server-1"]
- @parameterized.expand([("with_repository", True), ("without_repository", False)])
- def test_pr_creation_follows_the_repository(self, _name: str, with_repository: bool) -> None:
- body: dict = {}
- if with_repository:
- Integration.objects.create(team=self.team, kind="github", config={}, sensitive_config={})
- body["repository"] = "posthog/posthog"
+ @parameterized.expand(
+ [
+ ("repositories", {"repositories": ["posthog/posthog", "posthog/posthog.com"]}),
+ ("legacy_repository", {"repository": "posthog/posthog"}),
+ ("no_repository", {}),
+ ]
+ )
+ def test_the_task_works_in_the_requested_repositories(self, _name: str, body: dict) -> None:
+ Integration.objects.create(team=self.team, kind="github", config={}, sensitive_config={})
+ expected = body.get("repositories") or ([body["repository"]] if "repository" in body else [])
response = self._post(body)
assert response.status_code == status.HTTP_201_CREATED, response.json()
+ task = Task.objects.get(id=response.json()["id"])
+ assert task.repositories == expected
run = TaskRun.objects.get(id=response.json()["run_id"])
- assert run.state["pending_dispatch"]["create_pr"] is with_repository
+ assert run.state["pending_dispatch"]["create_pr"] is bool(expected)
def test_teammates_can_see_and_drive_workflow_tasks(self) -> None:
teammate = self._create_user("[email protected]")
@@ -946,6 +955,28 @@ class TestWorkflowTasksAPI(APIBaseTest):
assert mapping.mentioning_slack_user_id == "U123"
+class TestWorkflowTaskCreateRepositories(SimpleTestCase):
+ @parameterized.expand(
+ [
+ ("no_slash", {"repositories": ["just-a-name"]}, "repositories"),
+ ("too_many_slashes", {"repositories": ["org/repo/extra"]}, "repositories"),
+ ("duplicate_in_another_case", {"repositories": ["org/repo", "ORG/Repo"]}, "repositories"),
+ ("legacy_no_slash", {"repository": "just-a-name"}, "repository"),
+ ]
+ )
+ def test_rejects_repositories_the_sandbox_cannot_clone(self, _name, body, field):
+ serializer = WorkflowTaskCreateSerializer(data={"prompt": "Do the thing", **body})
+
+ assert not serializer.is_valid()
+ assert field in serializer.errors
+
+ def test_lowercases_repositories(self):
+ serializer = WorkflowTaskCreateSerializer(data={"prompt": "Do the thing", "repositories": ["Org/Repo"]})
+
+ assert serializer.is_valid(), serializer.errors
+ assert serializer.validated_data["repositories"] == ["org/repo"]
+
+
class TestWorkflowOriginIsReserved(SimpleTestCase):
def test_the_public_tasks_api_rejects_the_workflow_origin(self) -> None:
from products.tasks.backend.presentation.serializers import TaskCreateSerializer
diff --git a/products/tasks/frontend/components/TaskRepositoryPicker/CyclotronJobInputTaskRepository.tsx b/products/tasks/frontend/components/TaskRepositoryPicker/CyclotronJobInputTaskRepository.tsx
index 92088c307950..8f7772b6764d 100644
--- a/products/tasks/frontend/components/TaskRepositoryPicker/CyclotronJobInputTaskRepository.tsx
+++ b/products/tasks/frontend/components/TaskRepositoryPicker/CyclotronJobInputTaskRepository.tsx
@@ -2,19 +2,30 @@ import { useValues } from 'kea'
import { useState } from 'react'
import { IconGithub } from '@posthog/icons'
-import { LemonButton, LemonSelect } from '@posthog/lemon-ui'
+import { LemonButton, LemonSelect, LemonSnack } from '@posthog/lemon-ui'
import api from 'lib/api'
import type { CustomInputRendererProps } from 'lib/components/CyclotronJob/customInputRenderers'
import { GitHubRepositoryCombobox } from 'lib/integrations/GitHubRepositoryCombobox'
import { integrationsLogic } from 'lib/integrations/integrationsLogic'
+// Matches MAX_TASK_REPOSITORIES in products/cdp/backend/validation.py.
+const MAX_REPOSITORIES = 10
+
+function selectedRepositories(value: unknown): string[] {
+ if (typeof value === 'string') {
+ return value ? [value] : []
+ }
+ return Array.isArray(value) ? value.filter((item): item is string => typeof item === 'string' && !!item) : []
+}
+
export default function CyclotronJobInputTaskRepository({ value, onChange }: CustomInputRendererProps): JSX.Element {
const { getIntegrationsByKind, integrationsLoading } = useValues(integrationsLogic)
const githubIntegrations = getIntegrationsByKind(['github'])
+ const repositories = selectedRepositories(value)
+ const selectedKeys = new Set(repositories.map((repository) => repository.toLowerCase()))
- // Which GitHub org to browse is view state only: the saved value is the `owner/repo` string,
- // which already names the org, so the choice never needs to persist.
+ // Which GitHub org to browse is view state only: each saved `owner/repo` already names its org.
const [browsedIntegrationId, setBrowsedIntegrationId] = useState<number | null>(null)
const integrationId = browsedIntegrationId ?? githubIntegrations[0]?.id
@@ -46,25 +57,54 @@ export default function CyclotronJobInputTaskRepository({ value, onChange }: Cus
}
return (
- <div className="flex items-center gap-2 flex-wrap">
- {githubIntegrations.length > 1 && (
- <LemonSelect
- size="small"
- value={integrationId}
- options={githubIntegrations.map((integration) => ({
- value: integration.id,
- label: integration.display_name,
- }))}
- onChange={(id) => setBrowsedIntegrationId(id)}
- data-attr="task-repository-picker-integration"
- />
+ <div className="flex flex-col gap-2">
+ {repositories.length > 0 && (
+ <div className="flex flex-wrap items-center gap-1">
+ {repositories.map((repository) => (
+ <LemonSnack
+ key={repository}
+ title={`Remove ${repository}`}
+ onClose={() => onChange(repositories.filter((r) => r !== repository))}
+ data-attr="task-repository-picker-repository"
+ >
+ <span className="flex items-center gap-1 min-w-0">
+ <IconGithub className="shrink-0" />
+ <span className="truncate">{repository}</span>
+ </span>
+ </LemonSnack>
+ ))}
+ </div>
)}
- <GitHubRepositoryCombobox
- integrationId={integrationId}
- value={typeof value === 'string' ? value : ''}
- onChange={(repository) => onChange(repository ?? null)}
- showNoneOption
- />
+ <div className="flex items-center gap-2 flex-wrap">
+ {githubIntegrations.length > 1 && (
+ <LemonSelect
+ size="small"
+ value={integrationId}
+ options={githubIntegrations.map((integration) => ({
+ value: integration.id,
+ label: integration.display_name,
+ }))}
+ onChange={(id) => setBrowsedIntegrationId(id)}
+ data-attr="task-repository-picker-integration"
+ />
+ )}
+ <GitHubRepositoryCombobox
+ integrationId={integrationId}
+ value=""
+ placeholder={repositories.length ? 'Add another repository...' : 'Add a repository...'}
+ onChange={(repository) => {
+ if (repository && !selectedKeys.has(repository.toLowerCase())) {
+ onChange([...repositories, repository])
+ }
+ }}
+ repositoryFilter={(repository) => !selectedKeys.has(repository.full_name.toLowerCase())}
+ disabledReason={
+ repositories.length >= MAX_REPOSITORIES
+ ? `You can give a task up to ${MAX_REPOSITORIES} repositories`
+ : undefined
+ }
+ />
+ </div>
</div>
)
}
diff --git a/products/tasks/skills/building-loops/SKILL.md b/products/tasks/skills/building-loops/SKILL.md
index 66ada8b4f4a8..9caf90d4b20e 100644
--- a/products/tasks/skills/building-loops/SKILL.md
+++ b/products/tasks/skills/building-loops/SKILL.md
@@ -36,7 +36,7 @@ Replace only the values in angle brackets. Leave out the `notify` step and its e
"template_id": "template-posthog-create-task",
"inputs": {
"prompt": { "value": "<task prompt>" },
- "repository": { "value": "<owner/name>" },
+ "repository": { "value": ["<owner/name>"] },
"connectors": { "value": ["<mcp connection id>"] },
"skills": { "value": ["<skill name>"] },
"posthog_mcp_scopes": { "value": "read_only" },
@@ -68,7 +68,7 @@ A template renders the raw value into the instruction part of the prompt, before
Include the other inputs only when the loop needs them:
-- `repository`: the `owner/name` the user gives you, when the task works in code. Never one from memory. Check it is reachable first: `integrations-list` for GitHub, then `integrations-github-repos-retrieve` for that exact name.
+- `repository`: a list of the `owner/name` repositories the user gives you, when the task works in code. At most 10. The task gets no repository access without it. Never one from memory. Check each is reachable first: `integrations-list` for GitHub, then `integrations-github-repos-retrieve` for that exact name.
- `connectors`: ids from `mcp-connections-list`. Only connections shared with everyone in the project are accepted.
- `skills`: exact names from `skill-list`, at most 10.
- `posthog_mcp_scopes`: `read_only` by default. Use `full` only when the user asks for the task to change things in PostHog.
diff --git a/products/workflows/backend/presentation/views/hog_flow.py b/products/workflows/backend/presentation/views/hog_flow.py
index 7f1f80fa40b3..56b01c97719c 100644
--- a/products/workflows/backend/presentation/views/hog_flow.py
+++ b/products/workflows/backend/presentation/views/hog_flow.py
@@ -722,7 +722,7 @@ def _require_replay_vision_editor_access(request: Request | None, context: dict[
raise serializers.ValidationError({"variables": error})
-_REPOSITORY_SHAPE = re.compile(r"[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+")
+REPOSITORY_SHAPE = re.compile(r"[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+")
MIN_WORKFLOW_TASK_MAX_PARALLEL_TASKS = 1
MAX_WORKFLOW_TASK_MAX_PARALLEL_TASKS = 100
@@ -1703,11 +1703,14 @@ class HogFlowActionSerializer(serializers.Serializer):
except WorkflowTaskSkillsInvalid as e:
raise serializers.ValidationError({"inputs": {"skills": str(e)}})
- repository = (inputs.get("repository") or {}).get("value")
- if repository and not _REPOSITORY_SHAPE.fullmatch(repository):
+ repository_value = (inputs.get("repository") or {}).get("value") or []
+ repositories = [repository_value] if isinstance(repository_value, str) else repository_value
+ if not all(REPOSITORY_SHAPE.fullmatch(repository) for repository in repositories):
raise serializers.ValidationError(
- {"inputs": {"repository": "Repository must be an organization/repo name like your-org/your-repo."}}
+ {"inputs": {"repository": "Each repository must be an organization/repo name like your-org/your-repo."}}
)
+ if len({repository.lower() for repository in repositories}) != len(repositories):
+ raise serializers.ValidationError({"inputs": {"repository": "Each repository can only be added once."}})
model_value = (inputs.get("model") or {}).get("value") or {}
model = model_value.get("model")
diff --git a/products/workflows/backend/presentation/views/workflow_tasks.py b/products/workflows/backend/presentation/views/workflow_tasks.py
index 1ba85d55ceeb..08b8222b05cf 100644
--- a/products/workflows/backend/presentation/views/workflow_tasks.py
+++ b/products/workflows/backend/presentation/views/workflow_tasks.py
@@ -34,6 +34,7 @@ from products.workflows.backend.facade.api import (
get_workflow_task_daily_limits,
)
from products.workflows.backend.facade.service_jwt import TASKS_CREATE_PURPOSE
+from products.workflows.backend.presentation.views.hog_flow import REPOSITORY_SHAPE
from products.workflows.backend.presentation.views.workflow_step_auth import WorkflowStepJWTAuthentication
logger = structlog.get_logger(__name__)
@@ -90,7 +91,13 @@ class WorkflowTaskCreateSerializer(serializers.Serializer):
max_length=255,
required=False,
allow_blank=True,
- help_text="GitHub repository as organization/repo. Omit for a task with no code access.",
+ help_text="Deprecated: use `repositories`. One GitHub repository as organization/repo.",
+ )
+ repositories = serializers.ListField(
+ child=serializers.CharField(max_length=255),
+ required=False,
+ max_length=10,
+ help_text="GitHub repositories the agent can work in, each as organization/repo. Omit for a task with no code access.",
)
channel = serializers.CharField(
max_length=200,
@@ -149,6 +156,17 @@ class WorkflowTaskCreateSerializer(serializers.Serializer):
),
)
+ def validate_repository(self, value: str) -> str:
+ if value and not REPOSITORY_SHAPE.fullmatch(value):
+ raise serializers.ValidationError("Repository must be an organization/repo name.")
+ return value
+
+ def validate_repositories(self, value: list[str]) -> list[str]:
+ repositories = [self.validate_repository(repository).lower() for repository in value]
+ if len(set(repositories)) != len(repositories):
+ raise serializers.ValidationError("Repositories must be unique.")
+ return repositories
+
def validate_output_fields(self, value: dict[str, str] | None) -> dict[str, Any] | None:
if value is None:
return None
@@ -223,7 +241,7 @@ class WorkflowTaskViewSet(viewsets.GenericViewSet):
prompt=data["prompt"].strip(),
title=data.get("title"),
channel_ref=data.get("channel") or None,
- repository=data.get("repository") or None,
+ repositories=data.get("repositories") or ([data["repository"]] if data.get("repository") else None),
model=data.get("model") or None,
reasoning_effort=data.get("reasoning_effort") or None,
connector_ids=data.get("connectors"),
diff --git a/products/workflows/backend/tests/api/test_hog_flow.py b/products/workflows/backend/tests/api/test_hog_flow.py
index 6d9c1bb37e57..be670dfc71b8 100644
--- a/products/workflows/backend/tests/api/test_hog_flow.py
+++ b/products/workflows/backend/tests/api/test_hog_flow.py
@@ -8043,6 +8043,8 @@ class TestCreateTaskActionValidation(APIBaseTest):
("no_slash", "just-a-name"),
("too_many_slashes", "org/repo/extra"),
("whitespace_only", " "),
+ ("list_with_a_bad_entry", ["my-org/my-repo", "just-a-name"]),
+ ("duplicate_in_another_case", ["my-org/my-repo", "My-Org/My-Repo"]),
]
)
def test_rejects_a_repository_that_is_not_org_slash_repo(self, _name, repository):
@@ -8051,8 +8053,14 @@ class TestCreateTaskActionValidation(APIBaseTest):
assert response.status_code == status.HTTP_400_BAD_REQUEST, response.json()
assert response.json()["attr"] == "actions__1__inputs__repository"
- def test_accepts_an_org_slash_repo_repository(self):
- response = self._post_flow({"repository": {"value": "my-org/my-repo"}})
+ @parameterized.expand(
+ [
+ ("legacy_string", "my-org/my-repo"),
+ ("list", ["my-org/my-repo", "my-org/my-docs"]),
+ ]
+ )
+ def test_accepts_org_slash_repo_repositories(self, _name, repository):
+ response = self._post_flow({"repository": {"value": repository}})
assert response.status_code == status.HTTP_201_CREATED, response.json()
diff --git a/products/workflows/frontend/Workflows/hogflows/editor/tile-canvas/stepFacts.ts b/products/workflows/frontend/Workflows/hogflows/editor/tile-canvas/stepFacts.ts
index dbcb0a2f42ea..e2b5c718d000 100644
--- a/products/workflows/frontend/Workflows/hogflows/editor/tile-canvas/stepFacts.ts
+++ b/products/workflows/frontend/Workflows/hogflows/editor/tile-canvas/stepFacts.ts
@@ -64,14 +64,14 @@ function webhookFacts({ method, url, body }: PresentationOf<'webhook'>): StepFac
}
}
-function aiTaskFacts({ title, prompt, repository, writes }: PresentationOf<'ai-task'>): StepFacts {
+function aiTaskFacts({ title, prompt, repositories, writes }: PresentationOf<'ai-task'>): StepFacts {
const instructions = plainVariables(prompt ?? '')
return {
headline: title ? plainVariables(title) : firstSentence(instructions) || 'AI task',
detail: firstSentence(instructions) || undefined,
fields: [
['Instructions', instructions || 'Not set'],
- ...fieldIf('Repository', repository),
+ ...fieldIf(repositories.length > 1 ? 'Repositories' : 'Repository', repositories.join(', ')),
...fieldIf('Writes', joinList(writes)),
],
}
diff --git a/products/workflows/frontend/Workflows/hogflows/editor/tile-canvas/stepPresentation.ts b/products/workflows/frontend/Workflows/hogflows/editor/tile-canvas/stepPresentation.ts
index bf5f74e966be..a98a000e962b 100644
--- a/products/workflows/frontend/Workflows/hogflows/editor/tile-canvas/stepPresentation.ts
+++ b/products/workflows/frontend/Workflows/hogflows/editor/tile-canvas/stepPresentation.ts
@@ -44,7 +44,7 @@ export type StepPresentation =
| { kind: 'email'; email: EmailContent }
| { kind: 'slack'; channel: string; text: string }
| { kind: 'webhook'; method: string; url?: string; body: Record<string, unknown> }
- | { kind: 'ai-task'; title?: string; prompt?: string; repository?: string; tools: string[]; writes: string[] }
+ | { kind: 'ai-task'; title?: string; prompt?: string; repositories: string[]; tools: string[]; writes: string[] }
| { kind: 'scout'; scout?: string; writes: string[] }
| { kind: 'ticket-message'; message?: string; isNote: boolean }
| { kind: 'ticket-update'; status?: string; priority?: string; tags: string[] }
@@ -241,7 +241,7 @@ function functionPresentation(action: HogFlowAction): StepPresentation {
kind: 'ai-task',
title: textInput(action, 'title'),
prompt: textInput(action, 'prompt'),
- repository: textInput(action, 'repository'),
+ repositories: asTextList([inputValue(action, 'repository')].flat()),
tools: [...asTextList(inputValue(action, 'connectors')), ...asTextList(inputValue(action, 'skills'))],
writes: outputKeys(action),
}