From 481bcf6e8f91afc87d8ce49e1231a6c8cf118871 Mon Sep 17 00:00:00 2001 From: Brandon Chen Date: Tue, 17 Sep 2024 14:14:04 -0700 Subject: [PATCH 1/2] fix: src import issue --- backend/README.md | 14 ++++++++++++++ backend/src/generate-knowledge-files.ts | 2 +- backend/src/main-prompt.ts | 2 +- backend/src/websockets/websocket-action.ts | 2 +- exported-tokens.json | 2 +- package.json | 1 + .../knowledge-files/cache-expiration.ts | 2 +- test/__mock-data__/knowledge-files/crawlee.ts | 6 +++--- test/__src__/generate-patch.test.ts | 2 +- 9 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 backend/README.md diff --git a/backend/README.md b/backend/README.md new file mode 100644 index 0000000000..431888fd93 --- /dev/null +++ b/backend/README.md @@ -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. diff --git a/backend/src/generate-knowledge-files.ts b/backend/src/generate-knowledge-files.ts index 63e45c5663..c5db9e5598 100644 --- a/backend/src/generate-knowledge-files.ts +++ b/backend/src/generate-knowledge-files.ts @@ -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( diff --git a/backend/src/main-prompt.ts b/backend/src/main-prompt.ts index 0a8bd8235a..b9e93b7311 100644 --- a/backend/src/main-prompt.ts +++ b/backend/src/main-prompt.ts @@ -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' diff --git a/backend/src/websockets/websocket-action.ts b/backend/src/websockets/websocket-action.ts index dc49b4e71a..01bd4f8052 100644 --- a/backend/src/websockets/websocket-action.ts +++ b/backend/src/websockets/websocket-action.ts @@ -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' diff --git a/exported-tokens.json b/exported-tokens.json index 212926ba8d..7800b8aa7c 100644 --- a/exported-tokens.json +++ b/exported-tokens.json @@ -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": { diff --git a/package.json b/package.json index 8537881b5c..dbfa185047 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "start-jpcsp": "bun --cwd npm-app start-jpcsp", "start-vscode": "bun --cwd npm-app start-vscode", "start-nushell": "bun --cwd npm-app start-nushell", + "deploy-server": "./backend/deploy.sh", "format": "prettier --write \"**/*.{ts,tsx,json,md}\"", "bump": "bun run scripts/bump-version.ts", "test:patch": "bun test test/__src__/patch.test.ts" diff --git a/test/__mock-data__/knowledge-files/cache-expiration.ts b/test/__mock-data__/knowledge-files/cache-expiration.ts index eaffdb064c..507f9297eb 100644 --- a/test/__mock-data__/knowledge-files/cache-expiration.ts +++ b/test/__mock-data__/knowledge-files/cache-expiration.ts @@ -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, diff --git a/test/__mock-data__/knowledge-files/crawlee.ts b/test/__mock-data__/knowledge-files/crawlee.ts index a65d675537..e3a68cc428 100644 --- a/test/__mock-data__/knowledge-files/crawlee.ts +++ b/test/__mock-data__/knowledge-files/crawlee.ts @@ -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, }, @@ -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 ..." 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 ..." to update what will be committed)\n (use "git restore ..." 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[]> {\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[]> {\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: @@ -1616,7 +1616,7 @@ export const messages: Message[] = [ content: [ { type: 'text', - text: "Reading the following 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\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...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\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', diff --git a/test/__src__/generate-patch.test.ts b/test/__src__/generate-patch.test.ts index f6c067acfd..eabeb13b8d 100644 --- a/test/__src__/generate-patch.test.ts +++ b/test/__src__/generate-patch.test.ts @@ -105,7 +105,7 @@ describe('generatePatch', () => { async () => { await runPatchTest( `${mockDataDir}/duplicate-imports`, - 'common/src/util/tools.ts' + 'common/util/tools.ts' ) }, CLAUDE_CALL_TIMEOUT From f473683fd91a196de1570cab1500e2623f472111 Mon Sep 17 00:00:00 2001 From: Brandon Chen Date: Tue, 17 Sep 2024 14:15:23 -0700 Subject: [PATCH 2/2] [fix]: remove unused package script --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index dbfa185047..8537881b5c 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,6 @@ "start-jpcsp": "bun --cwd npm-app start-jpcsp", "start-vscode": "bun --cwd npm-app start-vscode", "start-nushell": "bun --cwd npm-app start-nushell", - "deploy-server": "./backend/deploy.sh", "format": "prettier --write \"**/*.{ts,tsx,json,md}\"", "bump": "bun run scripts/bump-version.ts", "test:patch": "bun test test/__src__/patch.test.ts"