Skip to content

Commit be0dc87

Browse files
authored
Merge pull request #35 from jmbish04/feat/deep-research-chat
Feat/deep research chat
2 parents b85d6ed + 8388de7 commit be0dc87

728 files changed

Lines changed: 283311 additions & 17720 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.agent/rules/000-bootstrap.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
trigger: always_on
3+
---
4+
5+
# 000: BOOTSTRAP & PROTOCOL CHECK
6+
**CRITICAL: Mandatory Pre-flight Check.**
7+
8+
Before starting any task, you must verify the following from `AGENTS.md`:
9+
10+
1. **Workspace Context**: Identify if you are working in `frontend` or `container`.
11+
2. **Installation Protocol**: You MUST use `pnpm add <pkg> --filter <package>` from the root. Never install at root without `-w`.
12+
3. **SDK Enforcement**: Verify you are using `@google/genai` (New SDK) and NOT `@google/generative-ai` (Legacy).
13+
4. **Backend/Frontend Sync**: If modifying Drizzle schemas, ensure `frontend/src/db` is the target as per the "Schema Sync" section.
14+
15+
**STOP**: If you have not explicitly read `AGENTS.md` in this session, do so now.

.agent/rules/000-core-directive.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
trigger: always_on
3+
---
4+
5+
# CORE DIRECTIVE: PROTOCOL ENFORCEMENT
6+
7+
**CRITICAL:** Before performing ANY task, you MUST synchronize your internal state with the project's specific constraints.
8+
9+
1. **Mandatory Documentation Review:**
10+
- You MUST read the `AGENTS.md` file in the root directory. It contains the workspace architecture and pnpm protocols.
11+
- You MUST read ALL files in the `.agent/rules/` directory to understand the coding standards (Drizzle, Shadcn, Astro).
12+
13+
2. **Workspace Verification:**
14+
- Confirm if the task involves the `frontend` or `root/backend`.
15+
- Apply the `pnpm --filter` protocol defined in `AGENTS.md`.
16+
17+
3. **Validation Step:**
18+
- If you have not read `AGENTS.md` in the current session, STOP and read it now.
19+
- Failure to follow the `pnpm` installation rules defined in `AGENTS.md` will result in environment corruption.
20+
21+
**DO NOT proceed with code generation until you have confirmed the pnpm workspace structure.**

.agent/rules/ai-providers.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Protocol: AI Provider Routing & Resolution
2+
3+
**MANDATORY IMPORT PATH**: Agents must _always and exclusively_ import AI functions from `@/ai/providers`.
4+
**FORBIDDEN IMPORTS**: It is _never_ acceptable to import directly from specific provider files (e.g., `ai/providers/openai`, `ai/providers/gemini`) or the index file explicitly (e.g., `ai/providers/index`).
5+
6+
**FUNCTION USAGE**: When using functions like `generateText`, `generateStructuredResponse`, etc., the agent should specify the `provider` and `model` arguments when known.
7+
8+
**FALLBACK BEHAVIOR**:
9+
10+
- If no provider or model is provided by the caller, the system relies on the `index.ts` routing to default to `worker-ai`, which then utilizes its internal business logic to select the correct fallback model.
11+
- Similarly, if a provider is specified but no model is provided, the specific provider module's logic determines the default model.
12+
- Agents should not hardcode default models unless explicitly required by the business logic.

.agent/rules/ai-rules.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Rule: AI Provider & Structured Responses
2+
3+
## 1. Structured Output Mandate
4+
5+
- **CRYSTAL CLEAR RULE**: ANYTIME the AI model is being instructed to respond with a structured response (JSON), you **MUST** use `generateStructuredResponse` or `generateStructuredWithTools` exported from `@/ai/providers`.
6+
- **FORBIDDEN**: Do not rely on native Agent SDK schemas (e.g. `outputType: MySchema as any` in `@openai/agents`). These frequently fail to map correctly through the Cloudflare AI Gateway or result in brittle string parsing.
7+
8+
## 2. The Extraction Pattern (Agents with Tools)
9+
10+
If you are running an autonomous Agent that requires tool usage (e.g., `HealthDiagnostician` or `ResearchAgent`):
11+
12+
1. Configure the Agent to output standard text/markdown (`outputType` must NOT be explicitly defined).
13+
2. Await the Agent's `finalOutput` inside the execution loop.
14+
3. Pass that string into `generateStructuredResponse` along with your Zod schema (converted via `zodToJsonSchema`) to strictly extract and type the final JSON object. This ensures Gateway compatibility while guaranteeing Zod-verified JSON.

.agent/rules/architecture.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
trigger: always_on
3+
---
4+
5+
# Rule: Architectural Integrity & Communication
6+
7+
## 1. Data Layer Isolation
8+
- **Backend Only**: Drizzle ORM, D1 bindings, and database migrations MUST reside exclusively in the `backend/` or `packages/db` directory.
9+
- **Frontend Prohibition**: The `frontend/` folder is strictly forbidden from importing `drizzle-orm`, `drizzle-kit`, or any direct database drivers.
10+
- **Action**: If the agent detects a database-related install in the frontend, it must immediately abort and move the logic to a Hono route.
11+
12+
## 2. Communication Standards
13+
- **Primary Protocol**: Use **Hono RPC** (`hc`) for all standard API interactions. This ensures shared type definitions between the Hono `AppType` and the Astro/React frontend.
14+
- **Real-time Status**: For long-running tasks (e.g., AI generation, PR creation), use **WebSockets** (via Durable Objects) or **Server-Sent Events (SSE)**.
15+
- **Type Safety**: Never manually redefine backend response types in the frontend. Always export the `AppType` from the backend and import it into the frontend's API client.
16+
17+
## 3. Operational Flow
18+
- All frontend data fetching must go through a centralized `src/lib/api-client.ts` that initializes the Hono RPC client.
19+
- Status updates for background jobs must be pushed from the backend to the frontend, rather than the frontend polling the database.

.agent/rules/config-standards.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Configuration Standards
2+
3+
- **KV First**: Always attempt to retrieve configuration from `KV_CONFIGS` via the `ConfigManager` before falling back to `c.env`.
4+
- **Type Safety**: Any new configuration key MUST be added to the `ConfigSchema` in `src/lib/config.ts`.
5+
- **Validation**: Use Zod for all incoming config updates.
6+
- **Sensitive Data**: Never log the actual values of keys retrieved from KV or Env.

.agent/rules/durable_objects.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Rule: Durable Object & Agent Migration Strategy
2+
3+
## 1. Definition
4+
5+
- **Requirement**: All new Agents and Durable Objects must be explicitly defined in `durable_objects.bindings`.
6+
- **Constraint**: ALL new classes must be registered in the `migrations` block of `wrangler.jsonc`.
7+
8+
## 2. Deployment Lifecycle Rules
9+
10+
### A. Fresh Deployment (Never Deployed)
11+
12+
- If the worker has **never** been deployed to production, you MAY add new classes to `migrations.v1`.
13+
14+
### B. Standard Deployment (Already Live)
15+
16+
- If the worker **has** been deployed, you **MUST** create a new migration version (e.g., `v2` -> `v3`).
17+
- **Forbidden**: Do NOT add new classes to existing/previous migration tags (e.g., do not retroactively add to `v1`).
18+
19+
## 3. Configuration Format
20+
21+
- **Field**: Always use `new_sqlite_classes` for Agents/DOs.
22+
- **Documentation**: Use a docstring comment to explain the purpose of the new class.
23+
24+
### Example
25+
26+
```jsonc
27+
"migrations": [
28+
{
29+
"tag": "v1",
30+
"new_sqlite_classes": ["ExistingAgent"]
31+
},
32+
{
33+
"tag": "v2",
34+
"new_sqlite_classes": [
35+
// Specialized agent for handling X
36+
"NewSpecializedAgent"
37+
]
38+
}
39+
]
40+
```
41+
42+
## 4. Checklist
43+
44+
1. [ ] Defined in `durable_objects.bindings`?
45+
2. [ ] Added to `migrations`?
46+
3. [ ] Is the migration tag incremented (if live)?
47+
4. [ ] Is the class name docstringed?

.agent/rules/globals.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Rule: Global Env Type Enforcement
2+
3+
## 1. Global Definition
4+
5+
- **Requirement**: `Env` is a globally available type generated by `wrangler types`.
6+
- **Constraint**: DO NOT import `Env` from `worker-configuration` or via relative paths (e.g., `../../../worker-configuration`).
7+
8+
## 2. Type Resolution
9+
10+
- The `Env` interface is automatically augmented by `wrangler types` into `worker-configuration.d.ts`.
11+
- `tsconfig.json` acts as the source of truth for including these types globally.
12+
- Usage: simply use `Env` in function signatures or class definitions without imports.
13+
14+
## 3. Forbidden Patterns
15+
16+
-`import type { Env } from "../../../worker-configuration";`
17+
-`import { Env } from "@/worker-configuration";`
18+
19+
## 4. Correct Usage
20+
21+
```typescript
22+
// ✅ Correct
23+
export class MyAgent extends WorkerEntrypoint<Env> {
24+
// ...
25+
}
26+
27+
// ✅ Correct
28+
const handleRequest = async (
29+
request: Request,
30+
env: Env,
31+
ctx: ExecutionContext,
32+
) => {
33+
// ...
34+
};
35+
```

.agent/rules/paths.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
trigger: always_on
3+
---
4+
5+
# Rule: Absolute Pathing & Alias Standards
6+
7+
## 1. Path Definition
8+
- ALWAYS use defined path aliases for cross-module imports.
9+
- **Forbidden**: `import { ... } from "../../../db"`
10+
- **Required**: `import { ... } from "@db/schema"`
11+
12+
## 2. Standard Aliases
13+
- `@/*`: Maps to the local `src` directory.
14+
- `@db/*`: Maps to the Drizzle/D1 data layer in the backend.
15+
- `@api/*`: Maps to the Hono RPC definitions/AppType.
16+
- `@ui/*`: Maps to the Shadcn component registry.
17+
- `@shared/*`: Maps to shared Zod schemas and utility functions.
18+
19+
## 3. Configuration Maintenance
20+
- If the agent creates a new top-level directory (e.g., `services/`), it MUST immediately update `tsconfig.json` and the corresponding bundler config (Vite/Astro) to include the new alias.
21+
- All path aliases must be reflected in the `backend/` and `frontend/` tsconfigs to ensure the RPC client (`hc`) resolves types without internal relative path leakage.

.agent/rules/realtime.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Rule: Real-time Communication Standards
2+
3+
- **WebSocket First**: Any UI component requiring a "progress bar" or "agent status" must use WebSockets via Cloudflare Durable Objects.
4+
- **RPC Only**: Standard REST calls MUST use the Hono RPC client. Manual `fetch('/api/...')` is deprecated and will be flagged as an error.
5+
- **Shared Schemas**: Input validation schemas (Zod) must live in a shared `packages/schema` or `backend/src/schemas` and be used by both the Hono validator and the RPC client.

0 commit comments

Comments
 (0)