-
-
Save kleneway/1fab03d81d38674951fea2357d06ea00 to your computer and use it in GitHub Desktop.
__________________START o1______________________ | |
**Plan to Address GitHub Issue: Add Research Component to Dashboard Workspace** | |
--- | |
### 1. Understand the Problem | |
- **Objective**: Add a new "Research" component to the dashboard application to display research items associated with a specific task or issue. | |
- **Key Requirements**: | |
- Create a new `Research.tsx` component in the workspace directory. | |
- Fetch research items from the database based on the task/issue ID. | |
- Render research questions and answers in markdown format. | |
- Integrate the new component into the workspace and update the sidebar. | |
- Ensure design consistency using Tailwind CSS. | |
- Update types to include a new research sidebar icon. | |
- Update an existing API router to fetch research items. | |
--- | |
### 2. Assess Available Information | |
- **Codebase Structure**: | |
- **Client-side Dashboard**: `/src/app/dashboard` | |
- Workspace components are in `/src/app/dashboard/[org]/[repo]/[developer]/components/workspace`. | |
- Sidebar component is in `/src/app/dashboard/[org]/[repo]/[developer]/components/Sidebar.tsx`. | |
- Dashboard layout is managed in `/src/app/dashboard/[org]/[repo]/[developer]/Dashboard.tsx`. | |
- **Types Definitions**: `/src/types.ts`. | |
- **API Routers**: `/src/server/api/routers`. | |
- Existing routers like `events.ts` handle data fetching. | |
- **Existing Components and Functions**: | |
- **Workspace Components**: `Code`, `Issue`, `PullRequest`, etc. | |
- **Sidebar**: Manages navigation between workspace components. | |
- **API Functions**: Fetch data related to tasks, events, and projects. | |
--- | |
### 3. Review Exit Criteria | |
- **Acceptance Criteria**: | |
- [ ] A new `Research.tsx` component is created in the `workspace` directory. | |
- [ ] The component fetches research items based on the task/issue ID. | |
- [ ] Research questions and answers are rendered, with answers displayed in markdown format. | |
- [ ] The new component is integrated into the workspace area of the dashboard. | |
- [ ] The sidebar includes an icon for the "Research" component. | |
- [ ] The new component follows existing design and styling conventions using Tailwind CSS. | |
- [ ] Types are updated to add a new research sidebar icon. | |
- [ ] An existing API router is updated to include a method for fetching research items from the database. | |
--- | |
### 4. Plan Code Changes | |
#### Step 1: Create the `Research.tsx` Component | |
- **Tool**: `CreateNewCode` | |
- **File Path**: `/src/app/dashboard/[org]/[repo]/[developer]/components/workspace/Research.tsx` | |
- **Instructions**: | |
- Create a new React component named `Research`. | |
- Use `useEffect` and `useState` hooks to fetch research items based on the current task or issue ID. | |
- Fetch data using the API method `api.events.getResearchItems`. | |
- Render a list of research questions and answers. | |
- Display answers using a markdown renderer like `react-markdown`. | |
- Apply Tailwind CSS classes to match the existing design. | |
#### Step 2: Update the API Router to Fetch Research Items | |
- **Tool**: `EditExistingCode` | |
- **File Path**: `/src/server/api/routers/events.ts` | |
- **Instructions**: | |
- Import necessary modules and the database client. | |
- Add a new method `getResearchItems` to fetch research items from the database: | |
```typescript | |
getResearchItems: publicProcedure | |
.input(z.object({ taskId: z.string() })) | |
.query(async ({ input, ctx }) => { | |
const researchItems = await ctx.db.research.findMany({ | |
where: { taskId: input.taskId }, | |
}); | |
return researchItems; | |
}), | |
``` | |
#### Step 3: Update Types to Include the Research Sidebar Icon | |
- **Tool**: `EditExistingCode` | |
- **File Path**: `/src/types.ts` | |
- **Instructions**: | |
- Update the `WorkspaceItemType` or relevant type to include `'Research'`: | |
```typescript | |
export type WorkspaceItemType = 'Code' | 'Issue' | 'PullRequest' | 'Research' | 'Todos' | 'Workspace'; | |
``` | |
- If there is an icon type or enum, add the new icon type. | |
#### Step 4: Update the Workspace Index to Export the `Research` Component | |
- **Tool**: `EditExistingCode` | |
- **File Path**: `/src/app/dashboard/[org]/[repo]/[developer]/components/workspace/index.tsx` | |
- **Instructions**: | |
- Import the `Research` component: | |
```typescript | |
import Research from './Research'; | |
``` | |
- Export the `Research` component alongside other workspace components: | |
```typescript | |
export { Code, Issue, PullRequest, Research }; | |
``` | |
#### Step 5: Integrate the `Research` Component into the Dashboard | |
- **Tool**: `EditExistingCode` | |
- **File Path**: `/src/app/dashboard/[org]/[repo]/[developer]/Dashboard.tsx` | |
- **Instructions**: | |
- Import the `Research` component: | |
```typescript | |
import { Research } from './components/workspace'; | |
``` | |
- Modify the rendering logic to include the `Research` component based on the selected workspace item: | |
```jsx | |
{selectedWorkspaceItem === 'Research' && <Research taskId={currentTaskId} />} | |
``` | |
#### Step 6: Update the Sidebar to Include the "Research" Component | |
- **Tool**: `EditExistingCode` | |
- **File Path**: `/src/app/dashboard/[org]/[repo]/[developer]/components/Sidebar.tsx` | |
- **Instructions**: | |
- Import a suitable icon for "Research", e.g., `LightBulbIcon` from Heroicons: | |
```typescript | |
import { LightBulbIcon } from '@heroicons/react/outline'; | |
``` | |
- Add a new sidebar item for "Research": | |
```typescript | |
{ | |
name: 'Research', | |
icon: LightBulbIcon, | |
workspaceType: 'Research', | |
}, | |
``` | |
- Ensure the sidebar updates the `selectedWorkspaceItem` state when "Research" is clicked. | |
#### Step 7: Ensure Styling Consistency Using Tailwind CSS | |
- **Tool**: `EditExistingCode` | |
- **File Path**: `/src/app/dashboard/[org]/[repo]/[developer]/components/workspace/Research.tsx` | |
- **Instructions**: | |
- Apply Tailwind CSS classes to match existing components. | |
- Use consistent margins, paddings, fonts, and colors. | |
- Ensure the component is responsive and accessible. | |
#### Step 8: Fetch and Display Research Items in `Research.tsx` | |
- **Tool**: `EditExistingCode` | |
- **File Path**: `/src/app/dashboard/[org]/[repo]/[developer]/components/workspace/Research.tsx` | |
- **Instructions**: | |
- Use the `useQuery` hook from `@tanstack/react-query` or the equivalent in your setup to fetch data: | |
```typescript | |
const { data: researchItems, isLoading } = api.events.getResearchItems.useQuery({ taskId }); | |
``` | |
- Handle loading and error states. | |
- Render each research item's question and answer: | |
```jsx | |
{researchItems.map((item) => ( | |
<div key={item.id} className="mb-4"> | |
<h3 className="text-lg font-semibold">{item.question}</h3> | |
<div className="prose"> | |
<ReactMarkdown>{item.answer}</ReactMarkdown> | |
</div> | |
</div> | |
))} | |
``` | |
--- | |
### 5. Finalize the Plan | |
- **Dependencies and Order of Execution**: | |
1. **CreateNewCode**: Create `Research.tsx` component. | |
2. **EditExistingCode**: Update API router in `events.ts` to provide data for the component. | |
3. **EditExistingCode**: Update types in `/src/types.ts`. | |
4. **EditExistingCode**: Export `Research` component in `workspace/index.tsx`. | |
5. **EditExistingCode**: Integrate `Research` component in `Dashboard.tsx`. | |
6. **EditExistingCode**: Update `Sidebar.tsx` to include the "Research" icon. | |
7. **EditExistingCode**: Apply Tailwind CSS styling in `Research.tsx`. | |
8. **EditExistingCode**: Fetch and display research items in `Research.tsx`. | |
- **Verification**: | |
- All acceptance criteria are addressed. | |
- All specified files are included and correctly modified. | |
- The plan follows a logical order respecting dependencies. | |
- Instructions are clear, detailed, and actionable. | |
--- | |
**Summary**: This plan outlines the steps required to add a new "Research" component to the dashboard workspace, ensuring all requirements are met and design consistency is maintained. Each step specifies the file to be modified or created, the tool to use, and detailed instructions to implement the changes effectively. | |
_____________END o1____________ | |
_____________START 4o__________ | |
### Step 1: Create Research Component | |
#### Files: | |
/src/app/dashboard/[org]/[repo]/[developer]/components/workspace/Research.tsx | |
#### Details: | |
Create a new React component named `Research.tsx` within the `/src/app/dashboard/[org]/[repo]/[developer]/components/workspace/` directory. This component should be responsible for fetching research items from the database based on the task/issue ID and rendering the research questions and answers. Ensure the answers are displayed in markdown format. Use Tailwind CSS for styling to match the existing design language of the dashboard components. | |
#### Exit Criteria | |
A new `Research.tsx` component is created and capable of fetching and displaying research items in markdown format. | |
### Step 2: Integrate Research Component into Workspace | |
#### Files: | |
/src/app/dashboard/[org]/[repo]/[developer]/components/workspace/index.tsx | |
#### Details: | |
In the file `/src/app/dashboard/[org]/[repo]/[developer]/components/workspace/index.tsx`, import the newly created `Research.tsx` component and include it in the workspace area. Ensure it is conditionally rendered based on the current selection in the sidebar. | |
#### Exit Criteria | |
The `Research.tsx` component is integrated into the workspace area of the dashboard. | |
### Step 3: Update Sidebar with Research Icon | |
#### Files: | |
/src/app/dashboard/[org]/[repo]/[developer]/components/Sidebar.tsx | |
#### Details: | |
Modify `/src/app/dashboard/[org]/[repo]/[developer]/components/Sidebar.tsx` to add a new icon for the Research component. Use an appropriate icon that matches the design and theme of the existing sidebar icons. Ensure this new icon is linked to the `Research.tsx` component, allowing users to toggle its view in the workspace area. | |
#### Exit Criteria | |
A new icon for the Research component is added to the sidebar, allowing users to toggle its view. | |
### Step 4: Add Research Sidebar Icon Type | |
#### Files: | |
/src/types.ts | |
#### Details: | |
Update `/src/types.ts` to include a new type for the research sidebar icon. This type should be used to handle the state and selection logic for displaying the Research component in the dashboard workspace. | |
#### Exit Criteria | |
A new type for the research sidebar icon is added to handle its state and selection logic. | |
### Step 5: Update Events API Router | |
#### Files: | |
/src/server/api/routers/events.ts | |
#### Details: | |
Enhance the file `/src/server/api/routers/events.ts` by adding a new method to fetch research items from the database. This method should query the research table based on the task/issue ID and return the relevant research items to the frontend. | |
#### Exit Criteria | |
A new method for fetching research items from the database is added to the Events API router. | |
### Step 6: Pass Props for Research Component | |
#### Files: | |
/src/app/dashboard/[org]/[repo]/[developer]/Dashboard.tsx | |
#### Details: | |
Modify `/src/app/dashboard/[org]/[repo]/[developer]/Dashboard.tsx` to pass necessary props to the workspace component for the Research component. These props should include the task/issue ID and any other relevant information needed to fetch and display the research items. | |
#### Exit Criteria | |
Necessary props are passed to the workspace component for the Research component. | |
_________END 4o___________ |
o1 code for Research.tsx
import React from 'react';
import { api } from '~/utils/api';
import ReactMarkdown from 'react-markdown';
interface ResearchProps {
taskId: string;
}
const Research: React.FC<ResearchProps> = ({ taskId }) => {
const { data: researchItems, isLoading, isError } = api.events.getResearchItems.useQuery({ taskId });
if (isLoading) {
return <div className="p-4">Loading research items...</div>;
}
if (isError) {
return <div className="p-4 text-red-500">Failed to load research items.</div>;
}
return (
<div className="p-4">
{researchItems && researchItems.length > 0 ? (
researchItems.map((item) => (
<div key={item.id} className="mb-8">
<h2 className="text-xl font-semibold mb-2">{item.question}</h2>
<div className="prose">
<ReactMarkdown>{item.answer}</ReactMarkdown>
</div>
</div>
))
) : (
<div>No research items available for this task.</div>
)}
</div>
);
};
export default Research;
Sonnet 3.5 code:
import React, { useEffect, useState } from "react";
import { api } from "../../../../../../../trpc/react";
import { type ResearchItem } from "@/types";
import ReactMarkdown from "react-markdown";
interface ResearchProps {
taskId: string;
}
const Research: React.FC<ResearchProps> = ({ taskId }) => {
const [researchItems, setResearchItems] = useState<ResearchItem[]>([]);
const {
data: fetchedResearchItems,
isLoading,
error,
} = api.events.getResearchItems.useQuery({ taskId });
useEffect(() => {
if (fetchedResearchItems) {
setResearchItems(fetchedResearchItems);
}
}, [fetchedResearchItems]);
if (isLoading)
return <div className="text-center">Loading research items...</div>;
if (error)
return (
<div className="text-center text-red-500">
Error loading research items
</div>
);
return (
<div className="space-y-4">
<h2 className="mb-4 text-2xl font-bold">Research</h2>
{researchItems.length === 0 ? (
<p>No research items found for this task.</p>
) : (
researchItems.map((item, index) => (
<div key={index} className="rounded-lg bg-white p-4 shadow">
<h3 className="mb-2 text-lg font-semibold">{item.question}</h3>
<div className="prose max-w-none">
<ReactMarkdown>{item.answer}</ReactMarkdown>
</div>
</div>
))
)}
</div>
);
};
export default Research;
The code produced by o1 is quite good. Notice that sonnet takes the unnecessary step of useState
when it's not needed for react query. Both handle errors well but o1 feels slightly better (using the isError bool instead of the error string, checking that researchItems
exists). Designs are similar but Sonnet is trying harder to make something look nice (using the rounded corners and shadows to make cards vs just a list of text). Both incorrectly imported the api
path but I don't believe that specific path was provided in the context. Original PR is here, I'll update JACoB with o1 in the next 24 hours to see how it performs in an agent workflow: https://github.com/kleneway/jacob/pull/84/files
o1 is better, but it is also much better at describing its reasoning. Makes me think - if it can so clearly reason, can it be persuaded towards an outcome you want by reasoning tactics, i.e. rather than describing the steps of solving a problem like how we do right now, we tell it where it failed and why, and it should self-correct much better
Here's the prompt:
Here is some information about a codebase:
(... codebase context with file names and tree-sitter info about files)
Here is a GitHub issue for this codebase:
Add Research Component to Dashboard Workspace
Description
We need to add a new "Research" component to the dashboard application to display research items. Currently, the dashboard shows items such as Prompts, Code, Issue, Pull Request, etc. With the addition of research items in the database, we should also display them in the dashboard.
For this task, we need to create a new component that displays all the research objects for a specific task/issueId. This component should:
Requirements
Research.tsx
in theworkspace
directory.New Files:
/src/app/dashboard/[org]/[repo]/[developer]/components/workspace/Research.tsx
Files to Update:
/src/app/dashboard/[org]/[repo]/[developer]/components/Sidebar.tsx
/src/types.ts
/src/app/dashboard/[org]/[repo]/[developer]/components/workspace/index.tsx
/src/app/dashboard/[org]/[repo]/[developer]/Dashboard.tsx
/src/server/api/routers/events.ts
Acceptance Criteria:
Research.tsx
component is created in theworkspace
directory.