Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Manicode Backend

## Deployment

To deploy the Manicode backend to Google Cloud Platform, follow these steps:

1. Set up a Google Cloud Platform project and enable the necessary APIs. See: https://cloud.google.com/sdk/docs/install.
2. Login to the Google Cloud Platform CLI with the command:
`gcloud auth login`.
3. Set your project ID: to `manicode-430317`
`gcloud config set project manicode-430317`
4. Configure Docker to push to gcloud.
`gcloud auth configure-docker`
5. Run ./deploy.sh to build and push the Docker image to Google Container Registry.
2 changes: 1 addition & 1 deletion backend/src/generate-knowledge-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { parseFileBlocks, ProjectFileContext } from 'common/util/file'
import { processFileBlock } from './main-prompt'
import { promptClaude } from './claude'
import { getRelevantFilesPrompt, knowledgeFilesPrompt } from './system-prompt'
import { DEFAULT_TOOLS } from 'common/src/util/tools'
import { DEFAULT_TOOLS } from 'common/util/tools'
import { debugLog } from './util/debug'

export async function generateKnowledgeFiles(
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main-prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { match, P } from 'ts-pattern'

import { promptClaudeStream } from './claude'
import { createFileBlock, ProjectFileContext } from 'common/util/file'
import { didClientUseTool, DEFAULT_TOOLS } from 'common/src/util/tools'
import { didClientUseTool, DEFAULT_TOOLS } from 'common/util/tools'
import { getSearchSystemPrompt, getAgentSystemPrompt } from './system-prompt'
import { STOP_MARKER } from 'common/constants'
import { FileChange, Message } from 'common/actions'
Expand Down
2 changes: 1 addition & 1 deletion backend/src/websockets/websocket-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { sendMessage } from './server'
import { isEqual } from 'lodash'
import fs from 'fs'
import path from 'path'
import { getTools } from 'common/src/util/tools'
import { getTools } from 'common/util/tools'
import { getSearchSystemPrompt } from '../system-prompt'
import { promptClaude, models } from '../claude'

Expand Down
2 changes: 1 addition & 1 deletion exported-tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"backend/src/system-prompt.ts": {
"getSystemPrompt": 10.768293153451244
},
"common/src/util/tools.ts": {
"common/util/tools.ts": {
"getTools": 3.9295594162366996
},
"backend/src/util/debug.ts": {
Expand Down
2 changes: 1 addition & 1 deletion test/__mock-data__/knowledge-files/cache-expiration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ export const mockFileContext: ProjectFileContext = {
'common/src/util/promise.ts': {
mapAsync: 1.1183569906194901,
},
'common/src/util/tools.ts': {
'common/util/tools.ts': {
didClientUseTool: 1.278283318562035,
getTools: 1.8015919171240695,
DEFAULT_TOOLS: 0.7549747200000004,
Expand Down
6 changes: 3 additions & 3 deletions test/__mock-data__/knowledge-files/crawlee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ export const mockFileContext: ProjectFileContext = {
knowledgeFilesPrompt: 2.000555504129951,
getRelevantFilesPrompt: 3.3872349113713067,
},
'common/src/util/tools.ts': {
'common/util/tools.ts': {
getTools: 2.6053777856571236,
DEFAULT_TOOLS: 0.9984440607850333,
},
Expand Down Expand Up @@ -1596,7 +1596,7 @@ export const mockFileContext: ProjectFileContext = {
gitChanges: {
status:
'On branch me/knowledge-files\nYour branch is ahead of \'origin/me/knowledge-files\' by 1 commit.\n (use "git push" to publish your local commits)\n\nChanges to be committed:\n (use "git restore --staged <file>..." to unstage)\n\tmodified: test/__mock-data__/knowledge-files/cache-expiration.ts\n\tmodified: test/__src__/generate-knowledge-files.test.ts\n\nChanges not staged for commit:\n (use "git add <file>..." to update what will be committed)\n (use "git restore <file>..." to discard changes in working directory)\n\tmodified: backend/src/generate-knowledge-files.ts\n\tmodified: bun.lockb\n\tmodified: npm-app/package.json\n\tmodified: npm-app/src/web-scraper.ts\n\n',
diff: 'diff --git a/backend/src/generate-knowledge-files.ts b/backend/src/generate-knowledge-files.ts\nindex a4c3c71..a09a5e2 100644\n--- a/backend/src/generate-knowledge-files.ts\n+++ b/backend/src/generate-knowledge-files.ts\n@@ -5,6 +5,7 @@ import { processFileBlock } from \'./main-prompt\'\n import { promptClaude } from \'./claude\'\n import { getRelevantFilesPrompt, knowledgeFilesPrompt } from \'./system-prompt\'\n import { DEFAULT_TOOLS } from \'common/src/util/tools\'\n+import { debugLog } from \'./util/debug\'\n \n export async function generateKnowledgeFiles(\n userId: string,\n@@ -13,6 +14,11 @@ export async function generateKnowledgeFiles(\n fileContext: ProjectFileContext,\n initialMessages: Message[]\n ): Promise<Promise<FileChange>[]> {\n+ debugLog(\'generateKnowledgeFiles\', {\n+ fullResponse,\n+ fileContext,\n+ initialMessages,\n+ })\n const systemPrompt = `\n You are an assistant that helps developers create knowledge files for their codebase. You are helpful and concise, knowing exactly when enough information has been gathered to create a knowledge file. Here\'s some more information on knowledge files:\n ${knowledgeFilesPrompt}\ndiff --git a/bun.lockb b/bun.lockb\nindex 618be04..2122b7e 100755\nBinary files a/bun.lockb and b/bun.lockb differ\ndiff --git a/npm-app/package.json b/npm-app/package.json\nindex 4ac3233..75cb609 100644\n--- a/npm-app/package.json\n+++ b/npm-app/package.json\n@@ -32,8 +32,8 @@\n ],\n "dependencies": {\n "@types/diff": "5.2.1",\n- "axios": "1.7.4",\n "cheerio": "1.0.0",\n+ "crawlee": "^3.11.3",\n "diff": "5.2.0",\n "ignore": "5.3.2",\n "lodash": "*",\ndiff --git a/npm-app/src/web-scraper.ts b/npm-app/src/web-scraper.ts\nindex ce679ce..8bf5d82 100644\n--- a/npm-app/src/web-scraper.ts\n+++ b/npm-app/src/web-scraper.ts\n@@ -1,4 +1,4 @@\n-import axios from \'axios\'\n+import { CheerioCrawler, Dataset } from \'crawlee\'\n import * as cheerio from \'cheerio\'\n \n // Global cache for scraped web pages\n@@ -11,17 +11,28 @@ export async function scrapeWebPage(url: string) {\n }\n \n try {\n- const response = await axios.get(url)\n- const html = response.data\n- const $ = cheerio.load(html)\n+ const crawler = new CheerioCrawler({\n+ maxRequestsPerCrawl: 1,\n+ async requestHandler({ $, request }) {\n+ const content = $(\'body\').text()\n+ await Dataset.pushData({ url: request.url, content })\n+ },\n+ })\n \n- // Extract the main content (you may need to adjust this selector based on the target websites)\n- const content = $(\'body\').text()\n+ await crawler.run([url])\n \n- // Store the scraped content in the cache\n- scrapedPagesCache[url] = content\n+ const dataset = await Dataset.open()\n+ const { items } = await dataset.getData()\n \n- return content\n+ // Extract the main content (you may need to adjust this selector based on the target websites)\n+ if (items.length > 0) {\n+ const content = items[0].content as string\n+ // Store the scraped content in the cache\n+ scrapedPagesCache[url] = content\n+ return content\n+ }\n+\n+ return \'\'\n } catch (error) {\n // console.error(\n // `Error scraping web page ${url}:`,\n',
diff: 'diff --git a/backend/src/generate-knowledge-files.ts b/backend/src/generate-knowledge-files.ts\nindex a4c3c71..a09a5e2 100644\n--- a/backend/src/generate-knowledge-files.ts\n+++ b/backend/src/generate-knowledge-files.ts\n@@ -5,6 +5,7 @@ import { processFileBlock } from \'./main-prompt\'\n import { promptClaude } from \'./claude\'\n import { getRelevantFilesPrompt, knowledgeFilesPrompt } from \'./system-prompt\'\n import { DEFAULT_TOOLS } from \'common/util/tools\'\n+import { debugLog } from \'./util/debug\'\n \n export async function generateKnowledgeFiles(\n userId: string,\n@@ -13,6 +14,11 @@ export async function generateKnowledgeFiles(\n fileContext: ProjectFileContext,\n initialMessages: Message[]\n ): Promise<Promise<FileChange>[]> {\n+ debugLog(\'generateKnowledgeFiles\', {\n+ fullResponse,\n+ fileContext,\n+ initialMessages,\n+ })\n const systemPrompt = `\n You are an assistant that helps developers create knowledge files for their codebase. You are helpful and concise, knowing exactly when enough information has been gathered to create a knowledge file. Here\'s some more information on knowledge files:\n ${knowledgeFilesPrompt}\ndiff --git a/bun.lockb b/bun.lockb\nindex 618be04..2122b7e 100755\nBinary files a/bun.lockb and b/bun.lockb differ\ndiff --git a/npm-app/package.json b/npm-app/package.json\nindex 4ac3233..75cb609 100644\n--- a/npm-app/package.json\n+++ b/npm-app/package.json\n@@ -32,8 +32,8 @@\n ],\n "dependencies": {\n "@types/diff": "5.2.1",\n- "axios": "1.7.4",\n "cheerio": "1.0.0",\n+ "crawlee": "^3.11.3",\n "diff": "5.2.0",\n "ignore": "5.3.2",\n "lodash": "*",\ndiff --git a/npm-app/src/web-scraper.ts b/npm-app/src/web-scraper.ts\nindex ce679ce..8bf5d82 100644\n--- a/npm-app/src/web-scraper.ts\n+++ b/npm-app/src/web-scraper.ts\n@@ -1,4 +1,4 @@\n-import axios from \'axios\'\n+import { CheerioCrawler, Dataset } from \'crawlee\'\n import * as cheerio from \'cheerio\'\n \n // Global cache for scraped web pages\n@@ -11,17 +11,28 @@ export async function scrapeWebPage(url: string) {\n }\n \n try {\n- const response = await axios.get(url)\n- const html = response.data\n- const $ = cheerio.load(html)\n+ const crawler = new CheerioCrawler({\n+ maxRequestsPerCrawl: 1,\n+ async requestHandler({ $, request }) {\n+ const content = $(\'body\').text()\n+ await Dataset.pushData({ url: request.url, content })\n+ },\n+ })\n \n- // Extract the main content (you may need to adjust this selector based on the target websites)\n- const content = $(\'body\').text()\n+ await crawler.run([url])\n \n- // Store the scraped content in the cache\n- scrapedPagesCache[url] = content\n+ const dataset = await Dataset.open()\n+ const { items } = await dataset.getData()\n \n- return content\n+ // Extract the main content (you may need to adjust this selector based on the target websites)\n+ if (items.length > 0) {\n+ const content = items[0].content as string\n+ // Store the scraped content in the cache\n+ scrapedPagesCache[url] = content\n+ return content\n+ }\n+\n+ return \'\'\n } catch (error) {\n // console.error(\n // `Error scraping web page ${url}:`,\n',
diffCached:
"diff --git a/test/__mock-data__/knowledge-files/cache-expiration.ts b/test/__mock-data__/knowledge-files/cache-expiration.ts\nindex cc2af1c..e5c74e1 100644\n--- a/test/__mock-data__/knowledge-files/cache-expiration.ts\n+++ b/test/__mock-data__/knowledge-files/cache-expiration.ts\n@@ -1,4 +1,4 @@\n-import { Message } from 'common/src/actions'\n+import { FileChange, Message } from 'common/src/actions'\n import { ProjectFileContext } from 'common/src/util/file'\n \n export const mockFileContext: ProjectFileContext = {\n@@ -1617,3 +1617,5 @@ export const messages: Message[] = [\n content: \"now let's update it to every 4 hours\\n\\n\",\n },\n ]\n+\n+export const expectedFiles: FileChange[] = []\ndiff --git a/test/__src__/generate-knowledge-files.test.ts b/test/__src__/generate-knowledge-files.test.ts\nindex 1dd0a8e..7dd9b6e 100644\n--- a/test/__src__/generate-knowledge-files.test.ts\n+++ b/test/__src__/generate-knowledge-files.test.ts\n@@ -3,8 +3,9 @@ import { WebSocket } from 'ws'\n \n import { generateKnowledgeFiles } from 'backend/generate-knowledge-files'\n import {\n- messages,\n- mockFileContext,\n+ messages as cacheExpirationMessages,\n+ mockFileContext as cacheExpirationFileContext,\n+ expectedFiles as cacheExpirationExpectedFiles,\n } from 'test/__mock-data__/knowledge-files/cache-expiration'\n import { ProjectFileContext } from 'common/util/file'\n import { FileChange, Message } from 'common/actions'\n@@ -32,7 +33,19 @@ const runGenKnowledgeFilesTest = async (\n \n describe('generateKnowledgeFiles', () => {\n it(\n- 'should not generate knowledge files for a cache change',\n+ 'should not generate knowledge files for a cache expiration change',\n+ async () => {\n+ await runGenKnowledgeFilesTest(\n+ cacheExpirationFileContext,\n+ cacheExpirationMessages,\n+ cacheExpirationExpectedFiles\n+ )\n+ },\n+ CLAUDE_CALL_TIMEOUT\n+ )\n+\n+ it(\n+ 'should generate a knowledge file for web scraping library change',\n async () => {\n await runGenKnowledgeFilesTest(mockFileContext, messages, [])\n },\n",
lastCommitMessages:
Expand All @@ -1616,7 +1616,7 @@ export const messages: Message[] = [
content: [
{
type: 'text',
text: "Reading the following files...<files>npm-app/src/web-scraper.ts, npm-app/package.json, npm-app/src/tool-handlers.ts, npm-app/src/index.ts, npm-app/src/project-files.ts, npm-app/src/client.ts, npm-app/src/chat-storage.ts, npm-app/src/config.ts, backend/src/claude.ts, test/__mock-data__/app/expected.ts, scripts/generate-fine-tuning-dataset.ts, test/__src__/generate-knowledge-files.test.ts, common/src/project-file-tree.ts, common/src/util/file.ts, common/src/util/tools.ts, test/__src__/process-stream.test.ts</files>\n\nCertainly! I'll help you replace the axios call with a crawlee invocation in the `npm-app/web-scraper.ts` file. First, let's update the file to use crawlee instead of axios. We'll need to install the crawlee package and make some changes to the code.\n\nLet's start by installing the crawlee package:",
text: "Reading the following files...<files>npm-app/src/web-scraper.ts, npm-app/package.json, npm-app/src/tool-handlers.ts, npm-app/src/index.ts, npm-app/src/project-files.ts, npm-app/src/client.ts, npm-app/src/chat-storage.ts, npm-app/src/config.ts, backend/src/claude.ts, test/__mock-data__/app/expected.ts, scripts/generate-fine-tuning-dataset.ts, test/__src__/generate-knowledge-files.test.ts, common/src/project-file-tree.ts, common/src/util/file.ts, common/util/tools.ts, test/__src__/process-stream.test.ts</files>\n\nCertainly! I'll help you replace the axios call with a crawlee invocation in the `npm-app/web-scraper.ts` file. First, let's update the file to use crawlee instead of axios. We'll need to install the crawlee package and make some changes to the code.\n\nLet's start by installing the crawlee package:",
},
{
type: 'tool_use',
Expand Down
2 changes: 1 addition & 1 deletion test/__src__/generate-patch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('generatePatch', () => {
async () => {
await runPatchTest(
`${mockDataDir}/duplicate-imports`,
'common/src/util/tools.ts'
'common/util/tools.ts'
)
},
CLAUDE_CALL_TIMEOUT
Expand Down