Skip to content

feat(command-center): autofill empty cells with recent active tasks#2212

Open
richardsolomou wants to merge 2 commits into
mainfrom
posthog-code/command-center-autofill-recent-tasks
Open

feat(command-center): autofill empty cells with recent active tasks#2212
richardsolomou wants to merge 2 commits into
mainfrom
posthog-code/command-center-autofill-recent-tasks

Conversation

@richardsolomou
Copy link
Copy Markdown
Member

@richardsolomou richardsolomou commented May 19, 2026

Problem

When opening the Command Center with no tasks attached, users have to manually re-pick the same tasks they were just working on. This adds friction every time they return to the view.

Closes #1630

Changes

  • commandCenterStore.ts — new autofillCells(taskIds) action; no-op if any cell is already populated.
  • useAutofillCommandCenter.ts — new hook that, on mount, finds tasks updated within the last 2 hours (max of task.updated_at and latest_run.updated_at), filters to non-archived tasks with a workspace, sorts by most recent activity, and assigns up to the grid size into the empty cells.
  • CommandCenterView.tsx — calls the hook on mount. A useRef guard runs the autofill at most once per mount, so manually clearing cells mid-session does not re-trigger it; navigating away and back does.
  • commandCenterStore.test.ts — 5 unit tests covering the empty-cell guard, full-cell short-circuit, cell-count cap, empty-input no-op, and active-task-id non-effect.

How did you test this?

  • pnpm --filter code typecheck — passes.
  • pnpm --filter code test commandCenterStore — 5/5 tests pass.
  • pnpm lint — clean (biome auto-formatted one file).

Manual UI verification not run — flagging explicitly per the agent guidelines.

Publish to changelog?

no


Created with PostHog Code

When the user opens the Command Center and no tasks are attached,
populate empty cells with their tasks updated in the past 2 hours,
ordered by most recent activity.

Generated-By: PostHog Code
Task-Id: 427c51ec-695b-4203-9ac2-bb79ea575422
@richardsolomou richardsolomou requested a review from a team May 19, 2026 03:27
@richardsolomou richardsolomou marked this pull request as ready for review May 19, 2026 03:28
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 19, 2026

Prompt To Fix All With AI
Fix the following 3 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 3
apps/code/src/renderer/features/command-center/hooks/useAutofillCommandCenter.ts:19-20
The hook guards on `workspacesFetched` but has no equivalent guard for the tasks query. `useTasks()` returns its data defaulted to `[]`, so if workspaces resolve first (common when they are cached from a previous mount), the effect fires immediately with an empty `tasks` array, finds zero candidates, sets `hasRunRef.current = true`, and exits. When the tasks response eventually arrives, the dependency change re-runs the effect — but `hasRunRef.current` is already `true`, so it bails. The autofill silently never runs.

```suggestion
  const { data: tasks = [], isFetched: tasksFetched } = useTasks();
  const { data: workspaces, isFetched: workspacesFetched } = useWorkspaces();
```

### Issue 2 of 3
apps/code/src/renderer/features/command-center/hooks/useAutofillCommandCenter.ts:30
The `workspacesFetched` guard needs a parallel `tasksFetched` guard so the effect waits for both data sources before proceeding.

```suggestion
    if (!workspacesFetched || !workspaces) return;
    if (!tasksFetched) return;
```

### Issue 3 of 3
apps/code/src/renderer/features/command-center/stores/commandCenterStore.test.ts:26-73
The five `autofillCells` tests share the same pattern — `setState`, call `autofillCells(input)`, assert `cells`. The team's preference is parameterised tests. The first, third, fourth, and fifth cases could be collapsed into a single `it.each` table covering `(input, expectedCells, expectedActiveTaskId)`, reducing duplication and making it easy to add edge cases in future.

Reviews (1): Last reviewed commit: "feat(command-center): autofill empty cel..." | Re-trigger Greptile

Comment on lines +19 to +20
const { data: tasks = [] } = useTasks();
const { data: workspaces, isFetched: workspacesFetched } = useWorkspaces();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 The hook guards on workspacesFetched but has no equivalent guard for the tasks query. useTasks() returns its data defaulted to [], so if workspaces resolve first (common when they are cached from a previous mount), the effect fires immediately with an empty tasks array, finds zero candidates, sets hasRunRef.current = true, and exits. When the tasks response eventually arrives, the dependency change re-runs the effect — but hasRunRef.current is already true, so it bails. The autofill silently never runs.

Suggested change
const { data: tasks = [] } = useTasks();
const { data: workspaces, isFetched: workspacesFetched } = useWorkspaces();
const { data: tasks = [], isFetched: tasksFetched } = useTasks();
const { data: workspaces, isFetched: workspacesFetched } = useWorkspaces();
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/command-center/hooks/useAutofillCommandCenter.ts
Line: 19-20

Comment:
The hook guards on `workspacesFetched` but has no equivalent guard for the tasks query. `useTasks()` returns its data defaulted to `[]`, so if workspaces resolve first (common when they are cached from a previous mount), the effect fires immediately with an empty `tasks` array, finds zero candidates, sets `hasRunRef.current = true`, and exits. When the tasks response eventually arrives, the dependency change re-runs the effect — but `hasRunRef.current` is already `true`, so it bails. The autofill silently never runs.

```suggestion
  const { data: tasks = [], isFetched: tasksFetched } = useTasks();
  const { data: workspaces, isFetched: workspacesFetched } = useWorkspaces();
```

How can I resolve this? If you propose a fix, please make it concise.


useEffect(() => {
if (hasRunRef.current) return;
if (!workspacesFetched || !workspaces) return;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 The workspacesFetched guard needs a parallel tasksFetched guard so the effect waits for both data sources before proceeding.

Suggested change
if (!workspacesFetched || !workspaces) return;
if (!workspacesFetched || !workspaces) return;
if (!tasksFetched) return;
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/command-center/hooks/useAutofillCommandCenter.ts
Line: 30

Comment:
The `workspacesFetched` guard needs a parallel `tasksFetched` guard so the effect waits for both data sources before proceeding.

```suggestion
    if (!workspacesFetched || !workspaces) return;
    if (!tasksFetched) return;
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +26 to +73
it("fills empty cells from index 0", () => {
useCommandCenterStore.getState().autofillCells(["t1", "t2"]);
expect(useCommandCenterStore.getState().cells).toEqual([
"t1",
"t2",
null,
null,
]);
});

it("does nothing when any cell is already populated", () => {
useCommandCenterStore.setState({ cells: [null, "existing", null, null] });
useCommandCenterStore.getState().autofillCells(["t1", "t2"]);
expect(useCommandCenterStore.getState().cells).toEqual([
null,
"existing",
null,
null,
]);
});

it("ignores empty task list", () => {
useCommandCenterStore.getState().autofillCells([]);
expect(useCommandCenterStore.getState().cells).toEqual([
null,
null,
null,
null,
]);
});

it("caps fill at the number of cells", () => {
useCommandCenterStore
.getState()
.autofillCells(["t1", "t2", "t3", "t4", "t5", "t6"]);
expect(useCommandCenterStore.getState().cells).toEqual([
"t1",
"t2",
"t3",
"t4",
]);
});

it("does not set activeTaskId", () => {
useCommandCenterStore.getState().autofillCells(["t1"]);
expect(useCommandCenterStore.getState().activeTaskId).toBeNull();
});
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The five autofillCells tests share the same pattern — setState, call autofillCells(input), assert cells. The team's preference is parameterised tests. The first, third, fourth, and fifth cases could be collapsed into a single it.each table covering (input, expectedCells, expectedActiveTaskId), reducing duplication and making it easy to add edge cases in future.

Context Used: Do not attempt to comment on incorrect alphabetica... (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/command-center/stores/commandCenterStore.test.ts
Line: 26-73

Comment:
The five `autofillCells` tests share the same pattern — `setState`, call `autofillCells(input)`, assert `cells`. The team's preference is parameterised tests. The first, third, fourth, and fifth cases could be collapsed into a single `it.each` table covering `(input, expectedCells, expectedActiveTaskId)`, reducing duplication and making it easy to add edge cases in future.

**Context Used:** Do not attempt to comment on incorrect alphabetica... ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

…ests

Address Greptile review on PR #2212:
- The hook only waited on workspaces. useTasks() defaults data to [],
  so if workspaces were cached and resolved first the effect ran with
  an empty tasks array, found zero candidates, set hasRunRef true and
  bailed — the later tasks response could never trigger the autofill.
  Add a tasksFetched guard so both sources must be loaded.
- Collapse the autofillCells test trio into an it.each table per
  repo convention.

Generated-By: PostHog Code
Task-Id: 427c51ec-695b-4203-9ac2-bb79ea575422
@richardsolomou richardsolomou added the Create Release This will trigger a new release label May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Create Release This will trigger a new release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show active and recent tasks in the command center by default instead of requiring manual addition

1 participant