feat(tasks): add GET /api/tasks/by-key/:key endpoint#233
Merged
Conversation
Adds a direct lookup of a Task by its human-readable issueKey (e.g.
DEV-42, PERS-7) instead of having to round-trip through /api/search
and client-side filter the results.
Why now: flow-tasks-agent (companion repo) needs by-key lookups in its
`get_task_by_key` LLM tool. Without this endpoint, it has to call
/api/search?q=KEY and filter on issueKey === KEY in JS — works but
imprecise (search matches title/description/comments too, limit caps at
10) and slower. This endpoint resolves the workaround.
Changes:
- tasks.dto.ts: new `issueKeyParamDto` (Zod, path-param). Pattern is
`^[A-Z][A-Z0-9]{1,9}-\d+$` — letter-led alphanumeric prefix to match
how board.prefix is generated (alphanumeric, 2-10 chars).
- tasks.service.ts: new `getTaskByIssueKey(key, userId)`. Resolves
issueKey → id, then delegates to the existing `getTask(id, userId)`
which already enforces workspace access (returns 404 cross-workspace
to avoid leaking existence).
- tasks.router.ts: `GET /api/tasks/by-key/:key`. Mounted BEFORE
`router.use('/:id', taskMfaGuard)` so 'by-key' doesn't get caught
as id='by-key'.
- tests/tasks-by-key.test.ts: 5 cases — happy path, unknown key (404),
malformed key (400) × 3 sub-cases, cross-workspace (404 not 403 to
avoid information leak), unauthenticated (401).
Verify:
- npx tsc --noEmit ✓ (scoped to tasks module; pre-existing unrelated TS
errors in permissions-loader.ts and admin-permissions.test.ts are
not touched by this PR)
- npx eslint src/modules/tasks src/__tests__/tasks-by-key.test.ts ✓
- npx vitest run src/__tests__/tasks-by-key.test.ts ✓ — 5/5 passing
Companion follow-up (in flow-tasks-agent repo):
- Replace search-based workaround in get_task_by_key tool with this
new endpoint, remove client-side issueKey regex filter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Что
Прямой lookup задачи по issueKey (DEV-42, PERS-7) — вместо обходного пути через
/api/search?q=KEY+ client-side фильтр.Зачем
В companion-репо
flow-tasks-agentLLM-тулget_task_by_keyсейчас работает через workaround: search + JS-фильтр по точному совпадению issueKey. Это:С этим endpoint'ом будет один прямой запрос. После мерджа закрою workaround отдельным PR в
flow-tasks-agent.Изменения
tasks.dto.ts: новыйissueKeyParamDto(Zod path-param). Regex^[A-Z][A-Z0-9]{1,9}-\d+$— буквоведущий alphanumeric prefix (соответствует тому как генерируются board prefixes).tasks.service.ts:getTaskByIssueKey(key, userId)— резолвит issueKey → id и делегирует в существующийgetTask(уже проверяет workspace access, возвращает 404 cross-workspace без раскрытия существования).tasks.router.ts:GET /api/tasks/by-key/:key. Зарегистрирован доrouter.use('/:id', taskMfaGuard)— иначе 'by-key' попадал бы в:idmatcher.tests/tasks-by-key.test.ts: 5 кейсов.Тесты
/api/tasks/:idnpx vitest run src/__tests__/tasks-by-key.test.ts→ 5/5 ✓Verify
npx tsc --noEmit✓ для модуля tasks. Pre-existing TS errors вpermissions-loader.tsиadmin-permissions.test.tsэтим PR не затронуты.npx eslint src/modules/tasks src/__tests__/tasks-by-key.test.ts✓Что НЕ в скоупе
🤖 Generated with Claude Code