Repository navigation
Description
Context
The request: "Similarly we should track which users have created the goals, plans, automations and to-do items."
The good news is that the tracking already exists - every one of those four already stores its creator:
| Entity | Table | Column |
|---|---|---|
| Goals | goals |
owner_id, owner_login |
| Plans | task_drafts |
user_id |
| Automations | agent_definitions |
owner_id |
| To-dos | repo_todos |
user_id |
What is missing is exposure. Three of the four store only a numeric GitHub id, so no API response carries a login or an avatar, and nothing can be rendered. goals is the exception - it stores owner_login too - but even that has no avatar.
This task adds a createdBy: AttributedUser | null projection to the four list and detail responses, resolved through the profile cache from the first task. It changes no storage and no behaviour; the UI that renders it is the next task.
One thing deliberately stays out of scope: changing ownership. These are creator records, not assignments. The request asks to track who created them, and all four are already owner-scoped for authorisation, so making the creator editable would be a permissions change nobody asked for.
Requirements
- Add
packages/api/services/creatorProjection.tswithprojectCreators(ownerIds)returningMap<string, AttributedUser>from the profile cache, plusattachCreator(rows, ownerIdField)for list projections. - Goals: add
createdBytoserializeGoalinpackages/api/services/goalProjection.ts, resolved fromowner_id, falling back to a login-onlyAttributedUserbuilt fromowner_loginwhen the cache has no profile. - Plans: add
created_byto the rows returned bylistDraftsandgetDraftinpackages/api/routes/plannerRoutes.ts. - Automations: add
createdByto the agent-definition projections inpackages/api/routes/agentDefinitionRoutes.ts. - To-dos: add
createdBytotoTodoDomainand the category mapper inpackages/api/routes/repoTodoRoutes.ts, and to theRepoTododomain type. - Batch every resolution: one profile read per response, never one per row.
- Fill the profile cache at creation time, so a newly created entity has an avatar immediately: call
rememberGitHubUserProfilesfrom the goal, plan, automation and to-do creation paths using the authenticated user already on the request. - Degrade to
nullwhen no profile is known, so an unresolvable creator is an absent chip rather than a failed response. - Tests covering each of the four projections, the batching, the goal login fallback and the null case.
Implementation Specification
Files added
packages/api/services/creatorProjection.tspackages/api/test/creatorProjection.test.ts
Files modified
packages/api/services/goalProjection.tspackages/api/routes/plannerRoutes.tspackages/api/routes/agentDefinitionRoutes.tspackages/api/routes/repoTodoRoutes.tspackages/core/src/services/repoTodosTypes.ts- addcreatedBytoRepoTodo.packages/api/auth.ts- record the authenticated user's profile once per session establishment.
Step-by-step
- Write
creatorProjection.tsoverloadGitHubUserProfiles, so a list read never calls GitHub. - Goals: resolve in
serializeGoal; it already takes adb, so no signature change is needed. Keepowner(the raw login) for compatibility and addcreatedBybeside it. - Plans: after the page is sliced in
listDrafts, batch-resolve theuser_idvalues and attach; do the same for the singlegetDraft. - Automations: batch-resolve in the list handler and resolve one in the detail handler.
- To-dos:
getTodosForRepositoryreturns domain objects without the user id, so select it in the route's query and resolve there rather than changing the core service's shape. - Record the session user's profile in
packages/api/auth.tswhere the GitHub profile is already in hand, so the cache is warm for everything that user creates. - Add the tests.
Acceptance Criteria
npm run typecheck,npm run lintand the API tests pass.npm run gen:openapi:checkandnpm run check:client-contractpass, or the artifacts are regenerated.GET /api/goals,/api/planner/drafts,/api/agent-definitionsand/api/repos/todoseach carrycreatedBywith id, login, displayName and avatarUrl when the profile is known.- A goal whose creator has no cached profile still reports
createdBywith its storedowner_loginand a null avatar. - A plan, automation or to-do whose creator has no cached profile reports
createdBy: null. - A page of 50 rows issues exactly one profile query and makes no GitHub call.
- Creating a goal, plan, automation or to-do populates the profile cache for the creator, so the entity shows an avatar on the next read without a GitHub call.
- Owner scoping is unchanged: no endpoint returns another owner's rows, and the creator is not writable.
GET /api/goals/:goalIdcontinues to return the existingownerfield unchanged, for compatibility.
Created by ProPR AI Planner
Activity
propr-dev commentedon Oct 8, 2026
Suggested Implementation:
Implementation Approach
The storage work for this is already done - all four entities record their creator - so this is purely a projection problem, and the interesting decisions are about where the login and avatar come from.
Three options:
The cache only helps if it is warm, so this task also writes to it from two directions.
packages/api/auth.tsalready holds the authenticated user's GitHub profile when a session is established, so recording it there means anyone who has signed in is resolvable - which covers every creator, since you have to sign in to create any of these. The creation paths are belt and braces for the case where a session predates this change.Goals get a fallback the other three do not.
goals.owner_loginis stored, so a goal with no cached profile can still render@loginwithout an avatar. The other three store only an id, and an id with no profile renders nothing useful -createdBy: nullis honest, where a chip reading@583231would be worse than an absent one.ownerstays.serializeGoalalready exposesowneras a bare login string, read by the CLI and MCP. Replacing it would be a breaking change to a published contract for no benefit, socreatedByis added beside it.Not editable. All four are owner-scoped for authorisation (
findOwnedGoal,verifyDraftOwnership, theowner_idfilters inagentDefinitionStore, theuser_idfilters inrepoTodosService). Making the creator writable would mean changing who can read the row, which is a permissions change the request does not ask for. Creator is a record of fact.File:
packages/api/services/creatorProjection.ts(new file)Why this file: one helper for four call sites, so the batching rule and the "never call GitHub on a read" rule are stated once. Four hand-rolled resolutions would each be a place for an N+1 to appear later.
File:
packages/api/services/goalProjection.tsWhy this file:
serializeGoalis the single projection the goal console, the goal list, MCPget_goaland the CLI all read, so adding the field here reaches every surface at once. It already receivesdb, so no caller signature changes.@@ in the projection object id: row.goal_id, owner: row.owner_login, + // Kept beside `owner` rather than replacing it: `owner` is a published + // contract the CLI and MCP already read, and replacing it would break + // them for no benefit. + createdBy: creatorWithLoginFallback(creators.get(row.owner_id), row.owner_id, row.owner_login), repository: row.repository,File:
packages/api/routes/plannerRoutes.tsWhy this file:
listDraftsandgetDraftare the only reads oftask_draftsthe Plans page uses. Attaching after the page is sliced is what keeps the profile query proportional to the page rather than to the full result set, whichlistDraftsbuilds in memory before slicing.@@ in listDrafts let drafts = await timeApiStage('sql.drafts.list', () => query - .select('draft_id', 'name', 'repository', 'status', 'updated_at', 'created_at', 'initial_prompt', 'paused', 'paused_at') + // user_id is selected so the creator can be resolved; it is replaced by + // the resolved `createdBy` before the response is sent, so the raw id + // is never exposed. + .select('draft_id', 'name', 'repository', 'status', 'updated_at', 'created_at', 'initial_prompt', 'paused', 'paused_at', 'user_id') .orderBy('updated_at', 'desc')); @@ const paginatedDrafts = drafts.slice(offset, offset + limit); + // Resolved after slicing, so a 2000-draft result set still issues one + // profile query for the 10 rows actually being returned. + const withCreators = await attachCreators(paginatedDrafts, 'user_id'); + // Drop the raw id: the response carries the resolved creator instead. + const responseDrafts = withCreators.map(({ user_id: _userId, ...draft }) => draft); @@ res.json({ - drafts: paginatedDrafts, + drafts: responseDrafts, total: drafts.length,Note:
attachIssueSummariesmutates the array it is given, so it must run onpaginatedDraftsbefore the creator mapping, and the summary field will carry through the spread.@@ in getDraft, after parsing the JSON fields const parsedDraft = parseDraftJsonFields(draft) as Record<string, unknown> & { task_title?: string }; parsedDraft.task_title = draft.name; + // Single draft, single profile lookup. Replaces the raw user_id so the + // detail response matches the list response's shape. + const creators = await projectCreators([draft.user_id]); + parsedDraft.createdBy = creators.get(String(draft.user_id)) ?? null; + delete parsedDraft.user_id;File:
packages/api/routes/agentDefinitionRoutes.tsWhy this file: the automation list and detail projections are built here, and
agentDefinitionStoredeliberately returns owner-scoped rows withowner_idintact, so this is where the id becomes a renderable creator.Files:
packages/api/routes/repoTodoRoutes.ts,packages/core/src/services/repoTodosTypes.tsWhy these files:
getTodosForRepositoryreturns domain objects that intentionally omituser_id, and widening the core service's return shape would ripple into the CLI and MCP mappers. Resolving in the route instead keeps the change local to the surface that needs it.@@ in getTodos, after loading the todos const todos = isDemoMode() ? await getDemoTodosForRepository(repository) : await getTodosForRepository(req.user.id, repository); - res.json({ todos }); + // Demo mode reads across owners, so the creator is resolved from the + // rows' own user_id rather than assumed to be the requester. Outside + // demo mode every row belongs to req.user, but resolving uniformly keeps + // one code path. + const ownerIds = await db('repo_todos') + .whereIn('todo_id', todos.map(todo => todo.todoId)) + .select('todo_id', 'user_id'); + const byTodo = new Map(ownerIds.map(row => [row.todo_id as string, String(row.user_id)])); + const creators = await projectCreators([...byTodo.values()]); + res.json({ + todos: todos.map(todo => ({ + ...todo, + createdBy: creators.get(byTodo.get(todo.todoId) ?? '') ?? null, + })), + });File:
packages/api/auth.tsWhy this file: the authenticated user's GitHub login and avatar are already in hand here when a session is established, so recording them costs nothing and makes every creator resolvable - you have to sign in to create a goal, plan, automation or to-do. Without this, the cache would only fill for people who happen to be assigned to something.
The four creation paths do the same at the point of creation, so an entity created in the same session that first signed in is never missing its avatar:
The same one-line call is added to
plannerRoutes.createDraft, the agent-definitioncreatehandler andrepoTodoRoutes.createTodo.File:
packages/api/test/creatorProjection.test.ts(new file)Why this file: the two failure modes worth pinning are an N+1 appearing on a list page and a response failing because a profile is missing. Both are invisible in a single-row test, so the batching assertion counts queries and the null-case assertion uses a deliberately empty cache.
propr-dev commentedon Oct 9, 2026
🤖 AI processing has started for this issue using claude agent with claude-opus-5-5 model.
I'll analyze the problem and work on a solution. This may take a few minutes.
Processing Details:
claudeclaude-opus-5-52901/claude-opus-5-5-project-creator-attributi-20261009-1406-dlv2888-epic-task-assignment-1m4issue-2901-20261009-1406-claude-opus-5-5-dlv🔍 Track Task Execution