@tyvm/knowhow 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +14 -0
- package/CONFIG.md +336 -0
- package/README.md +49 -0
- package/autodoc/chat.mdx +20 -0
- package/autodoc/cli.mdx +11 -0
- package/autodoc/plugins/asana.mdx +47 -0
- package/autodoc/plugins/downloader/downloader.mdx +38 -0
- package/autodoc/plugins/downloader/plugin.mdx +37 -0
- package/autodoc/plugins/downloader/types.mdx +42 -0
- package/autodoc/plugins/embedding.mdx +41 -0
- package/autodoc/plugins/figma.mdx +45 -0
- package/autodoc/plugins/github.mdx +40 -0
- package/autodoc/plugins/jira.mdx +46 -0
- package/autodoc/plugins/language.mdx +37 -0
- package/autodoc/plugins/linear.mdx +35 -0
- package/autodoc/plugins/notion.mdx +38 -0
- package/autodoc/plugins/plugins.mdx +59 -0
- package/autodoc/plugins/types.mdx +51 -0
- package/autodoc/plugins/vim.mdx +39 -0
- package/autodoc/tools/addInternalTools.mdx +1 -0
- package/autodoc/tools/agentCall.mdx +1 -0
- package/autodoc/tools/asana/definitions.mdx +10 -0
- package/autodoc/tools/asana/index.mdx +12 -0
- package/autodoc/tools/askHuman.mdx +1 -0
- package/autodoc/tools/callPlugin.mdx +1 -0
- package/autodoc/tools/embeddingSearch.mdx +1 -0
- package/autodoc/tools/execCommand.mdx +1 -0
- package/autodoc/tools/fileSearch.mdx +1 -0
- package/autodoc/tools/finalAnswer.mdx +1 -0
- package/autodoc/tools/github/definitions.mdx +6 -0
- package/autodoc/tools/github/index.mdx +8 -0
- package/autodoc/tools/index.mdx +14 -0
- package/autodoc/tools/lintFile.mdx +7 -0
- package/autodoc/tools/list.mdx +16 -0
- package/autodoc/tools/modifyFile.mdx +7 -0
- package/autodoc/tools/patch.mdx +9 -0
- package/autodoc/tools/readBlocks.mdx +1 -0
- package/autodoc/tools/readFile.mdx +1 -0
- package/autodoc/tools/scanFile.mdx +1 -0
- package/autodoc/tools/textSearch.mdx +6 -0
- package/autodoc/tools/types/fileblock.mdx +1 -0
- package/autodoc/tools/visionTool.mdx +1 -0
- package/autodoc/tools/writeFile.mdx +1 -0
- package/jest.config.js +18 -0
- package/package.json +89 -0
- package/src/agents/base/base.ts +619 -0
- package/src/agents/base/prompt.ts +26 -0
- package/src/agents/configurable/ConfigAgent.ts +23 -0
- package/src/agents/developer/developer.ts +69 -0
- package/src/agents/index.ts +8 -0
- package/src/agents/interface.ts +11 -0
- package/src/agents/patcher/codebase.md +27 -0
- package/src/agents/patcher/patcher.ts +110 -0
- package/src/agents/researcher/researcher.ts +109 -0
- package/src/agents/tools/addInternalTools.ts +21 -0
- package/src/agents/tools/agentCall.ts +18 -0
- package/src/agents/tools/aiClient.ts +36 -0
- package/src/agents/tools/asana/definitions.ts +199 -0
- package/src/agents/tools/asana/index.ts +108 -0
- package/src/agents/tools/askHuman.ts +8 -0
- package/src/agents/tools/callPlugin.ts +4 -0
- package/src/agents/tools/embeddingSearch.ts +5 -0
- package/src/agents/tools/execCommand.ts +26 -0
- package/src/agents/tools/fileSearch.ts +33 -0
- package/src/agents/tools/finalAnswer.ts +4 -0
- package/src/agents/tools/github/definitions.ts +89 -0
- package/src/agents/tools/github/index.ts +67 -0
- package/src/agents/tools/googleSearch.ts +242 -0
- package/src/agents/tools/index.ts +24 -0
- package/src/agents/tools/language/definitions.ts +97 -0
- package/src/agents/tools/language/index.ts +19 -0
- package/src/agents/tools/lintFile.ts +17 -0
- package/src/agents/tools/list.ts +514 -0
- package/src/agents/tools/loadWebpage.ts +129 -0
- package/src/agents/tools/modifyFile.ts +53 -0
- package/src/agents/tools/patch.ts +672 -0
- package/src/agents/tools/readBlocks.ts +41 -0
- package/src/agents/tools/readFile.ts +39 -0
- package/src/agents/tools/scanFile.ts +16 -0
- package/src/agents/tools/textSearch.ts +21 -0
- package/src/agents/tools/types/fileblock.ts +5 -0
- package/src/agents/tools/visionTool.ts +5 -0
- package/src/agents/tools/writeFile.ts +46 -0
- package/src/agents/vim/vim.ts +153 -0
- package/src/ai.ts +167 -0
- package/src/chat.ts +412 -0
- package/src/cli.ts +85 -0
- package/src/clients/anthropic.ts +399 -0
- package/src/clients/gemini.ts +486 -0
- package/src/clients/http.ts +107 -0
- package/src/clients/index.ts +183 -0
- package/src/clients/knowhow.ts +33 -0
- package/src/clients/openai.ts +253 -0
- package/src/clients/types.ts +91 -0
- package/src/clients/xai.ts +132 -0
- package/src/config.ts +211 -0
- package/src/conversion.ts +140 -0
- package/src/dataset/diffs/README.md +12 -0
- package/src/dataset/diffs/debug-errors.ts +29 -0
- package/src/dataset/diffs/debug.ts +64 -0
- package/src/dataset/diffs/generate.ts +71 -0
- package/src/dataset/diffs/jsonl.ts +54 -0
- package/src/dataset/diffs/test.ts +193 -0
- package/src/embeddings.ts +411 -0
- package/src/hashes.ts +67 -0
- package/src/index.ts +376 -0
- package/src/login.ts +78 -0
- package/src/microphone.ts +136 -0
- package/src/modules/index.ts +37 -0
- package/src/modules/types.ts +48 -0
- package/src/plugins/asana.ts +134 -0
- package/src/plugins/downloader/downloader.ts +204 -0
- package/src/plugins/downloader/plugin.ts +85 -0
- package/src/plugins/downloader/types.ts +85 -0
- package/src/plugins/embedding.ts +42 -0
- package/src/plugins/figma.ts +137 -0
- package/src/plugins/github.ts +153 -0
- package/src/plugins/jira.ts +104 -0
- package/src/plugins/language.ts +100 -0
- package/src/plugins/linear.ts +219 -0
- package/src/plugins/notion.ts +170 -0
- package/src/plugins/plugins.ts +56 -0
- package/src/plugins/types.ts +5 -0
- package/src/plugins/url.ts +63 -0
- package/src/plugins/vim.ts +73 -0
- package/src/prompts/BasicCodeDocumenter.ts +1 -0
- package/src/prompts/BasicProjectDocumenter.ts +1 -0
- package/src/prompts/EmbeddingSeachHelper.ts +1 -0
- package/src/prompts/index.ts +9 -0
- package/src/server/index.ts +14 -0
- package/src/services/AgentService.ts +98 -0
- package/src/services/EmbeddingService.ts +410 -0
- package/src/services/EventService.ts +20 -0
- package/src/services/GitHub.ts +60 -0
- package/src/services/KnowhowClient.ts +113 -0
- package/src/services/Mcp.ts +270 -0
- package/src/services/McpServer.ts +119 -0
- package/src/services/McpWebsocketTransport.ts +64 -0
- package/src/services/S3.ts +126 -0
- package/src/services/Tools.ts +65 -0
- package/src/services/flags.ts +52 -0
- package/src/services/index.ts +8 -0
- package/src/types.ts +225 -0
- package/src/utils/index.ts +108 -0
- package/src/worker.ts +80 -0
- package/tests/integration/figma.test.ts +70 -0
- package/tests/integration/fileblocks/readwrite.test.ts +95 -0
- package/tests/integration/patching/input.txt +145 -0
- package/tests/integration/patching/output.txt +145 -0
- package/tests/integration/patching/patch.txt +15 -0
- package/tests/integration/patching/unseen.txt +80 -0
- package/tests/integration/patching.test.ts +136 -0
- package/tests/languagePlugin.test.ts +74 -0
- package/tests/patching/corrupted.test.ts +78 -0
- package/tests/patching/imports.patch.txt +11 -0
- package/tests/patching/imports.test.ts +43 -0
- package/tests/patching/imports.txt +11 -0
- package/tests/patching/interface.patch.txt +15 -0
- package/tests/patching/interface.txt +7 -0
- package/tests/test.spec.ts +132 -0
- package/ts_build/src/agents/base/base.d.ts +88 -0
- package/ts_build/src/agents/base/base.js +464 -0
- package/ts_build/src/agents/base/base.js.map +1 -0
- package/ts_build/src/agents/base/prompt.d.ts +1 -0
- package/ts_build/src/agents/base/prompt.js +30 -0
- package/ts_build/src/agents/base/prompt.js.map +1 -0
- package/ts_build/src/agents/configurable/ConfigAgent.d.ts +10 -0
- package/ts_build/src/agents/configurable/ConfigAgent.js +25 -0
- package/ts_build/src/agents/configurable/ConfigAgent.js.map +1 -0
- package/ts_build/src/agents/configurable/OpenAIAgent.d.ts +0 -0
- package/ts_build/src/agents/configurable/OpenAIAgent.js +1 -0
- package/ts_build/src/agents/configurable/OpenAIAgent.js.map +1 -0
- package/ts_build/src/agents/developer/developer.d.ts +9 -0
- package/ts_build/src/agents/developer/developer.js +69 -0
- package/ts_build/src/agents/developer/developer.js.map +1 -0
- package/ts_build/src/agents/index.d.ts +7 -0
- package/ts_build/src/agents/index.js +38 -0
- package/ts_build/src/agents/index.js.map +1 -0
- package/ts_build/src/agents/interface.d.ts +10 -0
- package/ts_build/src/agents/interface.js +3 -0
- package/ts_build/src/agents/interface.js.map +1 -0
- package/ts_build/src/agents/patcher/patcher.d.ts +9 -0
- package/ts_build/src/agents/patcher/patcher.js +106 -0
- package/ts_build/src/agents/patcher/patcher.js.map +1 -0
- package/ts_build/src/agents/researcher/researcher.d.ts +9 -0
- package/ts_build/src/agents/researcher/researcher.js +107 -0
- package/ts_build/src/agents/researcher/researcher.js.map +1 -0
- package/ts_build/src/agents/tools/addInternalTools.d.ts +5 -0
- package/ts_build/src/agents/tools/addInternalTools.js +18 -0
- package/ts_build/src/agents/tools/addInternalTools.js.map +1 -0
- package/ts_build/src/agents/tools/agentCall.d.ts +1 -0
- package/ts_build/src/agents/tools/agentCall.js +21 -0
- package/ts_build/src/agents/tools/agentCall.js.map +1 -0
- package/ts_build/src/agents/tools/aiClient.d.ts +6 -0
- package/ts_build/src/agents/tools/aiClient.js +25 -0
- package/ts_build/src/agents/tools/aiClient.js.map +1 -0
- package/ts_build/src/agents/tools/asana/definitions.d.ts +202 -0
- package/ts_build/src/agents/tools/asana/definitions.js +197 -0
- package/ts_build/src/agents/tools/asana/definitions.js.map +1 -0
- package/ts_build/src/agents/tools/asana/index.d.ts +8 -0
- package/ts_build/src/agents/tools/asana/index.js +98 -0
- package/ts_build/src/agents/tools/asana/index.js.map +1 -0
- package/ts_build/src/agents/tools/askHuman.d.ts +1 -0
- package/ts_build/src/agents/tools/askHuman.js +15 -0
- package/ts_build/src/agents/tools/askHuman.js.map +1 -0
- package/ts_build/src/agents/tools/callPlugin.d.ts +1 -0
- package/ts_build/src/agents/tools/callPlugin.js +9 -0
- package/ts_build/src/agents/tools/callPlugin.js.map +1 -0
- package/ts_build/src/agents/tools/client.d.ts +5 -0
- package/ts_build/src/agents/tools/client.js +21 -0
- package/ts_build/src/agents/tools/client.js.map +1 -0
- package/ts_build/src/agents/tools/embeddingSearch.d.ts +1 -0
- package/ts_build/src/agents/tools/embeddingSearch.js +9 -0
- package/ts_build/src/agents/tools/embeddingSearch.js.map +1 -0
- package/ts_build/src/agents/tools/execCommand.d.ts +1 -0
- package/ts_build/src/agents/tools/execCommand.js +25 -0
- package/ts_build/src/agents/tools/execCommand.js.map +1 -0
- package/ts_build/src/agents/tools/fileSearch.d.ts +1 -0
- package/ts_build/src/agents/tools/fileSearch.js +31 -0
- package/ts_build/src/agents/tools/fileSearch.js.map +1 -0
- package/ts_build/src/agents/tools/finalAnswer.d.ts +1 -0
- package/ts_build/src/agents/tools/finalAnswer.js +8 -0
- package/ts_build/src/agents/tools/finalAnswer.js.map +1 -0
- package/ts_build/src/agents/tools/github/definitions.d.ts +47 -0
- package/ts_build/src/agents/tools/github/definitions.js +86 -0
- package/ts_build/src/agents/tools/github/definitions.js.map +1 -0
- package/ts_build/src/agents/tools/github/index.d.ts +789 -0
- package/ts_build/src/agents/tools/github/index.js +56 -0
- package/ts_build/src/agents/tools/github/index.js.map +1 -0
- package/ts_build/src/agents/tools/googleSearch.d.ts +93 -0
- package/ts_build/src/agents/tools/googleSearch.js +117 -0
- package/ts_build/src/agents/tools/googleSearch.js.map +1 -0
- package/ts_build/src/agents/tools/googleSearchTypes.d.ts +74 -0
- package/ts_build/src/agents/tools/googleSearchTypes.js +3 -0
- package/ts_build/src/agents/tools/googleSearchTypes.js.map +1 -0
- package/ts_build/src/agents/tools/index.d.ts +24 -0
- package/ts_build/src/agents/tools/index.js +41 -0
- package/ts_build/src/agents/tools/index.js.map +1 -0
- package/ts_build/src/agents/tools/language/definitions.d.ts +89 -0
- package/ts_build/src/agents/tools/language/definitions.js +95 -0
- package/ts_build/src/agents/tools/language/definitions.js.map +1 -0
- package/ts_build/src/agents/tools/language/index.d.ts +4 -0
- package/ts_build/src/agents/tools/language/index.js +22 -0
- package/ts_build/src/agents/tools/language/index.js.map +1 -0
- package/ts_build/src/agents/tools/lintFile.d.ts +1 -0
- package/ts_build/src/agents/tools/lintFile.js +22 -0
- package/ts_build/src/agents/tools/lintFile.js.map +1 -0
- package/ts_build/src/agents/tools/list.d.ts +2 -0
- package/ts_build/src/agents/tools/list.js +505 -0
- package/ts_build/src/agents/tools/list.js.map +1 -0
- package/ts_build/src/agents/tools/loadWebpage.d.ts +8 -0
- package/ts_build/src/agents/tools/loadWebpage.js +97 -0
- package/ts_build/src/agents/tools/loadWebpage.js.map +1 -0
- package/ts_build/src/agents/tools/modifyFile.d.ts +2 -0
- package/ts_build/src/agents/tools/modifyFile.js +74 -0
- package/ts_build/src/agents/tools/modifyFile.js.map +1 -0
- package/ts_build/src/agents/tools/patch.d.ts +21 -0
- package/ts_build/src/agents/tools/patch.js +443 -0
- package/ts_build/src/agents/tools/patch.js.map +1 -0
- package/ts_build/src/agents/tools/readBlocks.d.ts +2 -0
- package/ts_build/src/agents/tools/readBlocks.js +59 -0
- package/ts_build/src/agents/tools/readBlocks.js.map +1 -0
- package/ts_build/src/agents/tools/readFile.d.ts +1 -0
- package/ts_build/src/agents/tools/readFile.js +46 -0
- package/ts_build/src/agents/tools/readFile.js.map +1 -0
- package/ts_build/src/agents/tools/scanFile.d.ts +1 -0
- package/ts_build/src/agents/tools/scanFile.js +36 -0
- package/ts_build/src/agents/tools/scanFile.js.map +1 -0
- package/ts_build/src/agents/tools/textSearch.d.ts +1 -0
- package/ts_build/src/agents/tools/textSearch.js +22 -0
- package/ts_build/src/agents/tools/textSearch.js.map +1 -0
- package/ts_build/src/agents/tools/types/fileblock.d.ts +5 -0
- package/ts_build/src/agents/tools/types/fileblock.js +3 -0
- package/ts_build/src/agents/tools/types/fileblock.js.map +1 -0
- package/ts_build/src/agents/tools/visionTool.d.ts +1 -0
- package/ts_build/src/agents/tools/visionTool.js +9 -0
- package/ts_build/src/agents/tools/visionTool.js.map +1 -0
- package/ts_build/src/agents/tools/writeFile.d.ts +2 -0
- package/ts_build/src/agents/tools/writeFile.js +61 -0
- package/ts_build/src/agents/tools/writeFile.js.map +1 -0
- package/ts_build/src/agents/vim/vim.d.ts +14 -0
- package/ts_build/src/agents/vim/vim.js +171 -0
- package/ts_build/src/agents/vim/vim.js.map +1 -0
- package/ts_build/src/ai.d.ts +10 -0
- package/ts_build/src/ai.js +102 -0
- package/ts_build/src/ai.js.map +1 -0
- package/ts_build/src/chat.d.ts +13 -0
- package/ts_build/src/chat.js +319 -0
- package/ts_build/src/chat.js.map +1 -0
- package/ts_build/src/cli.d.ts +2 -0
- package/ts_build/src/cli.js +98 -0
- package/ts_build/src/cli.js.map +1 -0
- package/ts_build/src/clients/anthropic.d.ts +31 -0
- package/ts_build/src/clients/anthropic.js +344 -0
- package/ts_build/src/clients/anthropic.js.map +1 -0
- package/ts_build/src/clients/gemini.d.ts +20 -0
- package/ts_build/src/clients/gemini.js +347 -0
- package/ts_build/src/clients/gemini.js.map +1 -0
- package/ts_build/src/clients/http.d.ts +12 -0
- package/ts_build/src/clients/http.js +91 -0
- package/ts_build/src/clients/http.js.map +1 -0
- package/ts_build/src/clients/index.d.ts +47 -0
- package/ts_build/src/clients/index.js +143 -0
- package/ts_build/src/clients/index.js.map +1 -0
- package/ts_build/src/clients/knowhow.d.ts +10 -0
- package/ts_build/src/clients/knowhow.js +24 -0
- package/ts_build/src/clients/knowhow.js.map +1 -0
- package/ts_build/src/clients/openai.d.ts +20 -0
- package/ts_build/src/clients/openai.js +221 -0
- package/ts_build/src/clients/openai.js.map +1 -0
- package/ts_build/src/clients/types.d.ts +89 -0
- package/ts_build/src/clients/types.js +3 -0
- package/ts_build/src/clients/types.js.map +1 -0
- package/ts_build/src/clients/xai.d.ts +22 -0
- package/ts_build/src/clients/xai.js +108 -0
- package/ts_build/src/clients/xai.js.map +1 -0
- package/ts_build/src/config.d.ts +9 -0
- package/ts_build/src/config.js +216 -0
- package/ts_build/src/config.js.map +1 -0
- package/ts_build/src/conversion.d.ts +7 -0
- package/ts_build/src/conversion.js +114 -0
- package/ts_build/src/conversion.js.map +1 -0
- package/ts_build/src/dataset/diffs/debug-errors.d.ts +1 -0
- package/ts_build/src/dataset/diffs/debug-errors.js +28 -0
- package/ts_build/src/dataset/diffs/debug-errors.js.map +1 -0
- package/ts_build/src/dataset/diffs/debug.d.ts +1 -0
- package/ts_build/src/dataset/diffs/debug.js +50 -0
- package/ts_build/src/dataset/diffs/debug.js.map +1 -0
- package/ts_build/src/dataset/diffs/generate.d.ts +1 -0
- package/ts_build/src/dataset/diffs/generate.js +70 -0
- package/ts_build/src/dataset/diffs/generate.js.map +1 -0
- package/ts_build/src/dataset/diffs/jsonl.d.ts +1 -0
- package/ts_build/src/dataset/diffs/jsonl.js +47 -0
- package/ts_build/src/dataset/diffs/jsonl.js.map +1 -0
- package/ts_build/src/dataset/diffs/test.d.ts +1 -0
- package/ts_build/src/dataset/diffs/test.js +114 -0
- package/ts_build/src/dataset/diffs/test.js.map +1 -0
- package/ts_build/src/embeddings.d.ts +19 -0
- package/ts_build/src/embeddings.js +322 -0
- package/ts_build/src/embeddings.js.map +1 -0
- package/ts_build/src/hashes.d.ts +6 -0
- package/ts_build/src/hashes.js +78 -0
- package/ts_build/src/hashes.js.map +1 -0
- package/ts_build/src/index.d.ts +14 -0
- package/ts_build/src/index.js +258 -0
- package/ts_build/src/index.js.map +1 -0
- package/ts_build/src/login.d.ts +2 -0
- package/ts_build/src/login.js +63 -0
- package/ts_build/src/login.js.map +1 -0
- package/ts_build/src/microphone.d.ts +9 -0
- package/ts_build/src/microphone.js +131 -0
- package/ts_build/src/microphone.js.map +1 -0
- package/ts_build/src/modules/index.d.ts +3 -0
- package/ts_build/src/modules/index.js +34 -0
- package/ts_build/src/modules/index.js.map +1 -0
- package/ts_build/src/modules/types.d.ts +37 -0
- package/ts_build/src/modules/types.js +3 -0
- package/ts_build/src/modules/types.js.map +1 -0
- package/ts_build/src/plugins/asana.d.ts +16 -0
- package/ts_build/src/plugins/asana.js +114 -0
- package/ts_build/src/plugins/asana.js.map +1 -0
- package/ts_build/src/plugins/downloader/downloader.d.ts +12 -0
- package/ts_build/src/plugins/downloader/downloader.js +174 -0
- package/ts_build/src/plugins/downloader/downloader.js.map +1 -0
- package/ts_build/src/plugins/downloader/index.d.ts +3 -0
- package/ts_build/src/plugins/downloader/index.js +41 -0
- package/ts_build/src/plugins/downloader/index.js.map +1 -0
- package/ts_build/src/plugins/downloader/plugin.d.ts +8 -0
- package/ts_build/src/plugins/downloader/plugin.js +83 -0
- package/ts_build/src/plugins/downloader/plugin.js.map +1 -0
- package/ts_build/src/plugins/downloader/types.d.ts +82 -0
- package/ts_build/src/plugins/downloader/types.js +79 -0
- package/ts_build/src/plugins/downloader/types.js.map +1 -0
- package/ts_build/src/plugins/embedding.d.ts +5 -0
- package/ts_build/src/plugins/embedding.js +28 -0
- package/ts_build/src/plugins/embedding.js.map +1 -0
- package/ts_build/src/plugins/figma.d.ts +20 -0
- package/ts_build/src/plugins/figma.js +94 -0
- package/ts_build/src/plugins/figma.js.map +1 -0
- package/ts_build/src/plugins/github.d.ts +1223 -0
- package/ts_build/src/plugins/github.js +115 -0
- package/ts_build/src/plugins/github.js.map +1 -0
- package/ts_build/src/plugins/jira.d.ts +15 -0
- package/ts_build/src/plugins/jira.js +94 -0
- package/ts_build/src/plugins/jira.js.map +1 -0
- package/ts_build/src/plugins/language.d.ts +8 -0
- package/ts_build/src/plugins/language.js +69 -0
- package/ts_build/src/plugins/language.js.map +1 -0
- package/ts_build/src/plugins/linear.d.ts +23 -0
- package/ts_build/src/plugins/linear.js +184 -0
- package/ts_build/src/plugins/linear.js.map +1 -0
- package/ts_build/src/plugins/notion.d.ts +32 -0
- package/ts_build/src/plugins/notion.js +131 -0
- package/ts_build/src/plugins/notion.js.map +1 -0
- package/ts_build/src/plugins/plugins.d.ts +11 -0
- package/ts_build/src/plugins/plugins.js +51 -0
- package/ts_build/src/plugins/plugins.js.map +1 -0
- package/ts_build/src/plugins/types.d.ts +5 -0
- package/ts_build/src/plugins/types.js +3 -0
- package/ts_build/src/plugins/types.js.map +1 -0
- package/ts_build/src/plugins/url.d.ts +8 -0
- package/ts_build/src/plugins/url.js +50 -0
- package/ts_build/src/plugins/url.js.map +1 -0
- package/ts_build/src/plugins/vim.d.ts +11 -0
- package/ts_build/src/plugins/vim.js +63 -0
- package/ts_build/src/plugins/vim.js.map +1 -0
- package/ts_build/src/prompts/BasicCodeDocumenter.d.ts +2 -0
- package/ts_build/src/prompts/BasicCodeDocumenter.js +4 -0
- package/ts_build/src/prompts/BasicCodeDocumenter.js.map +1 -0
- package/ts_build/src/prompts/BasicProjectDocumenter.d.ts +2 -0
- package/ts_build/src/prompts/BasicProjectDocumenter.js +4 -0
- package/ts_build/src/prompts/BasicProjectDocumenter.js.map +1 -0
- package/ts_build/src/prompts/EmbeddingSeachHelper.d.ts +2 -0
- package/ts_build/src/prompts/EmbeddingSeachHelper.js +4 -0
- package/ts_build/src/prompts/EmbeddingSeachHelper.js.map +1 -0
- package/ts_build/src/prompts/index.d.ts +13 -0
- package/ts_build/src/prompts/index.js +15 -0
- package/ts_build/src/prompts/index.js.map +1 -0
- package/ts_build/src/server/index.d.ts +1 -0
- package/ts_build/src/server/index.js +17 -0
- package/ts_build/src/server/index.js.map +1 -0
- package/ts_build/src/services/AgentService.d.ts +14 -0
- package/ts_build/src/services/AgentService.js +87 -0
- package/ts_build/src/services/AgentService.js.map +1 -0
- package/ts_build/src/services/EmbeddingService.d.ts +39 -0
- package/ts_build/src/services/EmbeddingService.js +307 -0
- package/ts_build/src/services/EmbeddingService.js.map +1 -0
- package/ts_build/src/services/EventService.d.ts +9 -0
- package/ts_build/src/services/EventService.js +20 -0
- package/ts_build/src/services/EventService.js.map +1 -0
- package/ts_build/src/services/GitHub.d.ts +11 -0
- package/ts_build/src/services/GitHub.js +52 -0
- package/ts_build/src/services/GitHub.js.map +1 -0
- package/ts_build/src/services/KnowhowClient.d.ts +18 -0
- package/ts_build/src/services/KnowhowClient.js +85 -0
- package/ts_build/src/services/KnowhowClient.js.map +1 -0
- package/ts_build/src/services/Mcp.d.ts +377 -0
- package/ts_build/src/services/Mcp.js +221 -0
- package/ts_build/src/services/Mcp.js.map +1 -0
- package/ts_build/src/services/McpServer.d.ts +19 -0
- package/ts_build/src/services/McpServer.js +104 -0
- package/ts_build/src/services/McpServer.js.map +1 -0
- package/ts_build/src/services/McpWebsocketTransport.d.ts +13 -0
- package/ts_build/src/services/McpWebsocketTransport.js +59 -0
- package/ts_build/src/services/McpWebsocketTransport.js.map +1 -0
- package/ts_build/src/services/S3.d.ts +9 -0
- package/ts_build/src/services/S3.js +116 -0
- package/ts_build/src/services/S3.js.map +1 -0
- package/ts_build/src/services/Tools.d.ts +19 -0
- package/ts_build/src/services/Tools.js +51 -0
- package/ts_build/src/services/Tools.js.map +1 -0
- package/ts_build/src/services/flags.d.ts +13 -0
- package/ts_build/src/services/flags.js +48 -0
- package/ts_build/src/services/flags.js.map +1 -0
- package/ts_build/src/services/index.d.ts +8 -0
- package/ts_build/src/services/index.js +38 -0
- package/ts_build/src/services/index.js.map +1 -0
- package/ts_build/src/terminal.d.ts +1 -0
- package/ts_build/src/terminal.js +35 -0
- package/ts_build/src/terminal.js.map +1 -0
- package/ts_build/src/types.d.ts +181 -0
- package/ts_build/src/types.js +94 -0
- package/ts_build/src/types.js.map +1 -0
- package/ts_build/src/utils/index.d.ts +24 -0
- package/ts_build/src/utils/index.js +116 -0
- package/ts_build/src/utils/index.js.map +1 -0
- package/ts_build/src/worker.d.ts +1 -0
- package/ts_build/src/worker.js +68 -0
- package/ts_build/src/worker.js.map +1 -0
- package/ts_build/tests/integration/figma.test.d.ts +1 -0
- package/ts_build/tests/integration/figma.test.js +47 -0
- package/ts_build/tests/integration/figma.test.js.map +1 -0
- package/ts_build/tests/integration/fileblocks/readwrite.test.d.ts +1 -0
- package/ts_build/tests/integration/fileblocks/readwrite.test.js +95 -0
- package/ts_build/tests/integration/fileblocks/readwrite.test.js.map +1 -0
- package/ts_build/tests/integration/patching.test.d.ts +1 -0
- package/ts_build/tests/integration/patching.test.js +117 -0
- package/ts_build/tests/integration/patching.test.js.map +1 -0
- package/ts_build/tests/languagePlugin.test.d.ts +1 -0
- package/ts_build/tests/languagePlugin.test.js +78 -0
- package/ts_build/tests/languagePlugin.test.js.map +1 -0
- package/ts_build/tests/patching/corrupted.test.d.ts +1 -0
- package/ts_build/tests/patching/corrupted.test.js +53 -0
- package/ts_build/tests/patching/corrupted.test.js.map +1 -0
- package/ts_build/tests/patching/imports.test.d.ts +1 -0
- package/ts_build/tests/patching/imports.test.js +61 -0
- package/ts_build/tests/patching/imports.test.js.map +1 -0
- package/ts_build/tests/test.spec.d.ts +1 -0
- package/ts_build/tests/test.spec.js +101 -0
- package/ts_build/tests/test.spec.js.map +1 -0
- package/tsconfig.json +31 -0
- package/tslint.json +11 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChatCompletionMessageParam,
|
|
3
|
+
ChatCompletionToolMessageParam,
|
|
4
|
+
ChatCompletionMessageToolCall,
|
|
5
|
+
} from "openai/resources/chat";
|
|
6
|
+
import { openai } from "../../ai";
|
|
7
|
+
import {
|
|
8
|
+
searchFiles,
|
|
9
|
+
scanFile,
|
|
10
|
+
writeFile,
|
|
11
|
+
applyPatchFile,
|
|
12
|
+
execCommand,
|
|
13
|
+
readFile,
|
|
14
|
+
finalAnswer,
|
|
15
|
+
addInternalTools,
|
|
16
|
+
callPlugin,
|
|
17
|
+
testPatch,
|
|
18
|
+
} from "../tools";
|
|
19
|
+
import { Tools } from "../tools/list";
|
|
20
|
+
|
|
21
|
+
const availableFunctions = addInternalTools({
|
|
22
|
+
testPatch,
|
|
23
|
+
applyPatchFile,
|
|
24
|
+
callPlugin,
|
|
25
|
+
execCommand,
|
|
26
|
+
finalAnswer,
|
|
27
|
+
readFile,
|
|
28
|
+
scanFile,
|
|
29
|
+
searchFiles,
|
|
30
|
+
writeFile,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export class CodebaseAgent {
|
|
34
|
+
getInitialMessages(user_input: string) {
|
|
35
|
+
return [
|
|
36
|
+
{
|
|
37
|
+
role: "system",
|
|
38
|
+
content:
|
|
39
|
+
"Codebase Agent. You use the tools to read and write code, to help the developer implement features faster. Call final answer once you have finished implementing what is requested. As an agent you will receive multiple rounds of input until you call final answer. You are not able to request feedback from the user, so proceed with your plans and the developer will contact you afterwards if they need more help.",
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
{ role: "user", content: user_input },
|
|
43
|
+
] as Array<ChatCompletionMessageParam>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async getToolMessages(toolCall: ChatCompletionMessageToolCall) {
|
|
47
|
+
const functionName = toolCall.function.name;
|
|
48
|
+
const functionToCall = availableFunctions[functionName];
|
|
49
|
+
const functionArgs = JSON.parse(toolCall.function.arguments);
|
|
50
|
+
const positionalArgs = Object.values(functionArgs);
|
|
51
|
+
|
|
52
|
+
console.log(
|
|
53
|
+
`Calling function ${functionName} with args:`,
|
|
54
|
+
JSON.stringify(positionalArgs, null, 2)
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const functionResponse = await functionToCall(...positionalArgs);
|
|
58
|
+
|
|
59
|
+
if (functionName === "multi_tool_use.parallel") {
|
|
60
|
+
const args = positionalArgs[0] as {
|
|
61
|
+
recipient_name: string;
|
|
62
|
+
parameters: any;
|
|
63
|
+
}[];
|
|
64
|
+
|
|
65
|
+
return args.map((call, index) => {
|
|
66
|
+
return {
|
|
67
|
+
tool_call_id: toolCall.id + "_" + index,
|
|
68
|
+
role: "tool",
|
|
69
|
+
name: call.recipient_name.split(".").pop(),
|
|
70
|
+
content: functionResponse[index] || "Done",
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const toolMessage = {
|
|
76
|
+
tool_call_id: toolCall.id,
|
|
77
|
+
role: "tool",
|
|
78
|
+
name: functionName,
|
|
79
|
+
content: functionResponse || "Done",
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return [toolMessage];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
logMessages(messages: Array<ChatCompletionMessageParam>) {
|
|
86
|
+
for (const message of messages) {
|
|
87
|
+
if (message.role == "assistant") {
|
|
88
|
+
console.log(message.content);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async call(
|
|
94
|
+
user_input: string,
|
|
95
|
+
_messages?: Array<ChatCompletionMessageParam>
|
|
96
|
+
) {
|
|
97
|
+
const model = "gpt-4-1106-preview";
|
|
98
|
+
const messages = _messages || this.getInitialMessages(user_input);
|
|
99
|
+
|
|
100
|
+
const response = await openai.chat.completions.create({
|
|
101
|
+
model,
|
|
102
|
+
messages: messages,
|
|
103
|
+
tools: Tools,
|
|
104
|
+
tool_choice: "auto",
|
|
105
|
+
});
|
|
106
|
+
this.logMessages(response.choices.map((c) => c.message));
|
|
107
|
+
const responseMessage = response.choices[0].message;
|
|
108
|
+
|
|
109
|
+
const toolCalls = responseMessage.tool_calls;
|
|
110
|
+
if (responseMessage.tool_calls) {
|
|
111
|
+
// extend conversation with assistant's reply
|
|
112
|
+
messages.push(responseMessage);
|
|
113
|
+
|
|
114
|
+
for (const toolCall of toolCalls) {
|
|
115
|
+
const toolMessages = await this.getToolMessages(toolCall);
|
|
116
|
+
// Add the tool responses to the thread
|
|
117
|
+
messages.push(
|
|
118
|
+
...(toolMessages as Array<ChatCompletionToolMessageParam>)
|
|
119
|
+
);
|
|
120
|
+
const finalMessage = toolMessages.find((m) => m.name === "finalAnswer");
|
|
121
|
+
if (finalMessage) {
|
|
122
|
+
return finalMessage.content;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Send the tool responses back to the model
|
|
127
|
+
const secondResponse = await openai.chat.completions.create({
|
|
128
|
+
model,
|
|
129
|
+
messages: messages,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const aiResp = secondResponse.choices.map((c) => c.message);
|
|
133
|
+
this.logMessages(aiResp);
|
|
134
|
+
messages.push(...aiResp);
|
|
135
|
+
|
|
136
|
+
return this.call(user_input, messages);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (responseMessage.content) {
|
|
140
|
+
return responseMessage.content;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export const Developer = new CodebaseAgent();
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChatCompletionMessageParam,
|
|
3
|
+
ChatCompletionToolMessageParam,
|
|
4
|
+
ChatCompletionMessageToolCall,
|
|
5
|
+
} from "openai/resources/chat";
|
|
6
|
+
import { openai } from "../../ai";
|
|
7
|
+
import {
|
|
8
|
+
searchFiles,
|
|
9
|
+
scanFile,
|
|
10
|
+
writeFile,
|
|
11
|
+
applyPatchFile,
|
|
12
|
+
execCommand,
|
|
13
|
+
readFile,
|
|
14
|
+
finalAnswer,
|
|
15
|
+
addInternalTools,
|
|
16
|
+
callPlugin,
|
|
17
|
+
testPatch,
|
|
18
|
+
} from "../tools";
|
|
19
|
+
import { Tools } from "../tools/list";
|
|
20
|
+
|
|
21
|
+
const availableFunctions = addInternalTools({
|
|
22
|
+
testPatch,
|
|
23
|
+
applyPatchFile,
|
|
24
|
+
callPlugin,
|
|
25
|
+
execCommand,
|
|
26
|
+
finalAnswer,
|
|
27
|
+
readFile,
|
|
28
|
+
scanFile,
|
|
29
|
+
searchFiles,
|
|
30
|
+
writeFile,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export class CodebaseAgent {
|
|
34
|
+
getInitialMessages(user_input: string) {
|
|
35
|
+
return [
|
|
36
|
+
{
|
|
37
|
+
role: "system",
|
|
38
|
+
content:
|
|
39
|
+
"Codebase Agent. You use the tools to read and write code, to help the developer implement features faster. Call final answer once you have finished implementing what is requested. As an agent you will receive multiple rounds of input until you call final answer. You are not able to request feedback from the user, so proceed with your plans and the developer will contact you afterwards if they need more help.",
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
{ role: "user", content: user_input },
|
|
43
|
+
] as Array<ChatCompletionMessageParam>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async getToolMessages(toolCall: ChatCompletionMessageToolCall) {
|
|
47
|
+
const functionName = toolCall.function.name;
|
|
48
|
+
const functionToCall = availableFunctions[functionName];
|
|
49
|
+
const functionArgs = JSON.parse(toolCall.function.arguments);
|
|
50
|
+
const positionalArgs = Object.values(functionArgs);
|
|
51
|
+
|
|
52
|
+
console.log(
|
|
53
|
+
`Calling function ${functionName} with args:`,
|
|
54
|
+
JSON.stringify(positionalArgs, null, 2)
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const functionResponse = await functionToCall(...positionalArgs);
|
|
58
|
+
|
|
59
|
+
if (functionName === "multi_tool_use.parallel") {
|
|
60
|
+
const args = positionalArgs[0] as {
|
|
61
|
+
recipient_name: string;
|
|
62
|
+
parameters: any;
|
|
63
|
+
}[];
|
|
64
|
+
|
|
65
|
+
return args.map((call, index) => {
|
|
66
|
+
return {
|
|
67
|
+
tool_call_id: toolCall.id + "_" + index,
|
|
68
|
+
role: "tool",
|
|
69
|
+
name: call.recipient_name.split(".").pop(),
|
|
70
|
+
content: functionResponse[index] || "Done",
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const toolMessage = {
|
|
76
|
+
tool_call_id: toolCall.id,
|
|
77
|
+
role: "tool",
|
|
78
|
+
name: functionName,
|
|
79
|
+
content: functionResponse || "Done",
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return [toolMessage];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
logMessages(messages: Array<ChatCompletionMessageParam>) {
|
|
86
|
+
for (const message of messages) {
|
|
87
|
+
if (message.role == "assistant") {
|
|
88
|
+
console.log(message.content);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async call(
|
|
94
|
+
user_input: string,
|
|
95
|
+
_messages?: Array<ChatCompletionMessageParam>
|
|
96
|
+
) {
|
|
97
|
+
const model = "gpt-4-1106-preview";
|
|
98
|
+
const messages = _messages || this.getInitialMessages(user_input);
|
|
99
|
+
|
|
100
|
+
const response = await openai.chat.completions.create({
|
|
101
|
+
model,
|
|
102
|
+
messages: messages,
|
|
103
|
+
tools: Tools,
|
|
104
|
+
tool_choice: "auto",
|
|
105
|
+
});
|
|
106
|
+
this.logMessages(response.choices.map((c) => c.message));
|
|
107
|
+
const responseMessage = response.choices[0].message;
|
|
108
|
+
|
|
109
|
+
const toolCalls = responseMessage.tool_calls;
|
|
110
|
+
if (responseMessage.tool_calls) {
|
|
111
|
+
// extend conversation with assistant's reply
|
|
112
|
+
messages.push(responseMessage);
|
|
113
|
+
|
|
114
|
+
for (const toolCall of toolCalls) {
|
|
115
|
+
const toolMessages = await this.getToolMessages(toolCall);
|
|
116
|
+
// Add the tool responses to the thread
|
|
117
|
+
messages.push(
|
|
118
|
+
...(toolMessages as Array<ChatCompletionToolMessageParam>)
|
|
119
|
+
);
|
|
120
|
+
const finalMessage = toolMessages.find((m) => m.name === "FinalAnswer");
|
|
121
|
+
if (finalMessage) {
|
|
122
|
+
return finalMessage.content;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Send the tool responses back to the model
|
|
127
|
+
const secondResponse = await openai.chat.completions.create({
|
|
128
|
+
model,
|
|
129
|
+
messages: messages,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const aiResp = secondResponse.choices.map((c) => c.message);
|
|
133
|
+
this.logMessages(aiResp);
|
|
134
|
+
messages.push(...aiResp);
|
|
135
|
+
|
|
136
|
+
return this.call(user_input, messages);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (responseMessage.content) {
|
|
140
|
+
return responseMessage.content;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export const Developer = new CodebaseAgent();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Index: tests/integration/patching/input.txt
|
|
2
|
+
===================================================================
|
|
3
|
+
--- tests/integration/patching/input.txt
|
|
4
|
+
+++ tests/integration/patching/input.txt
|
|
5
|
+
@@ -116,9 +116,9 @@
|
|
6
|
+
// Add the tool responses to the thread
|
|
7
|
+
messages.push(
|
|
8
|
+
...(toolMessages as Array<ChatCompletionToolMessageParam>)
|
|
9
|
+
);
|
|
10
|
+
- const finalMessage = toolMessages.find((m) => m.name === "finalAnswer");
|
|
11
|
+
+ const finalMessage = toolMessages.find((m) => m.name === "FinalAnswer");
|
|
12
|
+
if (finalMessage) {
|
|
13
|
+
return finalMessage.content;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Octokit } from "@octokit/rest";
|
|
2
|
+
import { Plugin } from "./types";
|
|
3
|
+
import parseDiff from "parse-diff";
|
|
4
|
+
import { MinimalEmbedding } from "../types";
|
|
5
|
+
|
|
6
|
+
export class GitHubPlugin implements Plugin {
|
|
7
|
+
octokit: Octokit;
|
|
8
|
+
|
|
9
|
+
constructor() {
|
|
10
|
+
this.octokit = new Octokit({
|
|
11
|
+
auth: process.env.GITHUB_TOKEN,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async embed(userPrompt: string): Promise<MinimalEmbedding[]> {
|
|
16
|
+
const urls = this.extractUrls(userPrompt);
|
|
17
|
+
const diffs = await this.getParsedDiffs(urls);
|
|
18
|
+
const diffsFiltered = diffs.filter((diff) => diff !== null);
|
|
19
|
+
|
|
20
|
+
return diffsFiltered.map((diff, index) => {
|
|
21
|
+
return {
|
|
22
|
+
id: urls[index],
|
|
23
|
+
text: JSON.stringify(diff),
|
|
24
|
+
metadata: {},
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
extractUrls(userPrompt: string): string[] {
|
|
30
|
+
const prUrlRegex =
|
|
31
|
+
/https:\/\/github\.com\/([\w-]+)\/([\w-]+)\/pull\/(\d+)/g;
|
|
32
|
+
const matches = userPrompt.match(prUrlRegex);
|
|
33
|
+
return matches;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async getDiff(url: string) {
|
|
37
|
+
const [owner, repo, _, pull_number] = url.split("/").slice(-4);
|
|
38
|
+
console.log(`Loading diff for ${owner}/${repo}#${pull_number}`);
|
|
39
|
+
const { data: diff } = await this.octokit.rest.pulls.get({
|
|
40
|
+
owner,
|
|
41
|
+
repo,
|
|
42
|
+
pull_number: parseInt(pull_number),
|
|
43
|
+
mediaType: {
|
|
44
|
+
format: "diff",
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return diff;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async getParsedDiffs(urls: string[]) {
|
|
52
|
+
return Promise.all(
|
|
53
|
+
urls.map(async (url) => {
|
|
54
|
+
const diff = await this.getDiff(url);
|
|
55
|
+
let parsed = parseDiff(diff.toString());
|
|
56
|
+
|
|
57
|
+
parsed = parsed.filter((file) => {
|
|
58
|
+
return file.additions < 200 && file.deletions < 200;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return parsed;
|
|
62
|
+
})
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async call(userPrompt: string): Promise<string> {
|
|
67
|
+
const urls = this.extractUrls(userPrompt);
|
|
68
|
+
|
|
69
|
+
if (urls) {
|
|
70
|
+
const responses = await this.getParsedDiffs(urls);
|
|
71
|
+
// Format the diffs in Markdown
|
|
72
|
+
const markdownDiffs = responses
|
|
73
|
+
.map((diff) => `\`\`\`diff\n${JSON.stringify(diff)}\n\`\`\``)
|
|
74
|
+
.join("\n\n");
|
|
75
|
+
return `GITHUB PLUGIN: ${urls} loaded:\n\n${markdownDiffs}`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return "GITHUB PLUGIN: No pull request URLs detected.";
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { readFile, writeFile } from "../../src/utils";
|
|
2
|
+
import { createPatch, applyPatch } from "diff";
|
|
3
|
+
import { scanFile } from "../../src/agents/tools";
|
|
4
|
+
import { patchFile } from "../../src/agents/tools/patch";
|
|
5
|
+
import { Agents } from "../../src/services/AgentService";
|
|
6
|
+
import { Patcher } from "../../src/agents";
|
|
7
|
+
import { Tools } from "../../src/services";
|
|
8
|
+
import { includedTools } from "../../src/agents/tools/list";
|
|
9
|
+
import * as allTools from "../../src/agents/tools";
|
|
10
|
+
|
|
11
|
+
const inputPath = "tests/integration/patching/input.txt";
|
|
12
|
+
const outputPath = "tests/integration/patching/output.txt";
|
|
13
|
+
const patchPath = "tests/integration/patching/patch.txt";
|
|
14
|
+
|
|
15
|
+
const brokenPatch = `Index: tests/integration/patching/input.txt
|
|
16
|
+
===================================================================
|
|
17
|
+
--- tests/integration/patching/input.txt
|
|
18
|
+
+++ tests/integration/patching/input.txt
|
|
19
|
+
@@ -116,9 +116,9 @@
|
|
20
|
+
// Add the tool responses to the thread
|
|
21
|
+
messages.push(
|
|
22
|
+
...(toolMessages as Array<ChatCompletionToolMessageParam>)
|
|
23
|
+
);
|
|
24
|
+
- const finalMessage = toolMessages.find((m) => m.name === "finalAnswer");
|
|
25
|
+
+ const finalMessage = toolMessages.find((m) => m.name === "FinalAnswer");
|
|
26
|
+
if (finalMessage) {
|
|
27
|
+
return finalMessage.content;
|
|
28
|
+
}
|
|
29
|
+
}\n`;
|
|
30
|
+
|
|
31
|
+
describe("Patcher", () => {
|
|
32
|
+
beforeAll(async () => {
|
|
33
|
+
Agents.registerAgent(Patcher);
|
|
34
|
+
Tools.addTools(includedTools);
|
|
35
|
+
const toolFunctions = Object.entries(allTools)
|
|
36
|
+
.filter(([_, value]) => typeof value === 'function')
|
|
37
|
+
.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
|
|
38
|
+
Tools.addFunctions(toolFunctions);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("should be able to apply actual patch", async () => {
|
|
42
|
+
const oldString = (await readFile(inputPath)).toString();
|
|
43
|
+
const newString = (await readFile(outputPath)).toString();
|
|
44
|
+
const workingPatch = (await readFile(patchPath)).toString();
|
|
45
|
+
|
|
46
|
+
const applied = await applyPatch(oldString, patchPath);
|
|
47
|
+
|
|
48
|
+
// Expect this not to work
|
|
49
|
+
expect(applied).toBe(oldString);
|
|
50
|
+
|
|
51
|
+
// Expect this to work
|
|
52
|
+
const workingApply = applyPatch(oldString, workingPatch);
|
|
53
|
+
expect(workingApply).toBe(newString);
|
|
54
|
+
|
|
55
|
+
console.log({
|
|
56
|
+
brokenPatch: Buffer.from(brokenPatch),
|
|
57
|
+
workingPatch: Buffer.from(workingPatch),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const buffer1 = Buffer.from(brokenPatch);
|
|
61
|
+
const buffer2 = Buffer.from(workingPatch);
|
|
62
|
+
|
|
63
|
+
console.log("bufferLength", buffer1.length, buffer2.length);
|
|
64
|
+
const length = Math.max(buffer1.length, buffer2.length);
|
|
65
|
+
for (let i = 0; i < length; i++) {
|
|
66
|
+
if (buffer1[i] !== buffer2[i]) {
|
|
67
|
+
console.log("not equal", i, buffer1[i], buffer2[i]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
expect(brokenPatch).toBe(workingPatch);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("should generate the diff", async () => {
|
|
75
|
+
const oldString = (await readFile(inputPath)).toString();
|
|
76
|
+
const newString = (await readFile(outputPath)).toString();
|
|
77
|
+
|
|
78
|
+
const patch = createPatch(inputPath, oldString, newString);
|
|
79
|
+
await writeFile(patchPath, patch);
|
|
80
|
+
|
|
81
|
+
// const actualPatch = (await readFile(patchPath)).toString();
|
|
82
|
+
|
|
83
|
+
console.log(patch);
|
|
84
|
+
|
|
85
|
+
const scanned = await scanFile(inputPath, 120, 120);
|
|
86
|
+
console.log(JSON.parse(scanned));
|
|
87
|
+
|
|
88
|
+
expect(patch).toBe(brokenPatch);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("should be able to patch a codebase", async () => {
|
|
92
|
+
const originalText = (await readFile(inputPath)).toString();
|
|
93
|
+
console.log(
|
|
94
|
+
await Agents.callAgent(
|
|
95
|
+
"Patcher",
|
|
96
|
+
`Update the file in ${inputPath} change the string "finalAnswer" to "FinalAnswer", as we are changing the tool name to be FinalAnswer instead of finalAnswer. This should be around line 120. Do not modify anything else. Treat this file as a typescript file. Only try one patch. If it fails stop`
|
|
97
|
+
)
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const updatedText = (await readFile(inputPath)).toString();
|
|
101
|
+
await writeFile(inputPath, originalText);
|
|
102
|
+
|
|
103
|
+
expect(updatedText).toBe(
|
|
104
|
+
originalText.replace(`"finalAnswer"`, `"FinalAnswer"`)
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("should be able to patch when given the answer", async () => {
|
|
109
|
+
const originalText = (await readFile(inputPath)).toString();
|
|
110
|
+
await Agents.callAgent(
|
|
111
|
+
"Patcher",
|
|
112
|
+
`Update the file in ${inputPath} change the string "finalAnswer" to "FinalAnswer" on line 120. Do not modify anything else. Heres the answer: ${brokenPatch}.`
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const updatedText = (await readFile(inputPath)).toString();
|
|
116
|
+
await writeFile(inputPath, originalText);
|
|
117
|
+
|
|
118
|
+
expect(updatedText).toBe(
|
|
119
|
+
originalText.replace(`"finalAnswer"`, `"FinalAnswer"`)
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("should be able to update the unseen file", async () => {
|
|
124
|
+
const unseenPath = "tests/integration/patching/unseen.txt";
|
|
125
|
+
const originalText = (await readFile(unseenPath)).toString();
|
|
126
|
+
await Agents.callAgent(
|
|
127
|
+
"Patcher",
|
|
128
|
+
`Update the file in ${unseenPath} change the file additions and deletions count from 200 to 300. Do not modify anything else. Treat this file as a typescript file.`
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const updatedText = (await readFile(unseenPath)).toString();
|
|
132
|
+
await writeFile(unseenPath, originalText);
|
|
133
|
+
|
|
134
|
+
expect(updatedText).toBe(originalText.replaceAll("200", "300"));
|
|
135
|
+
});
|
|
136
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
jest.mock("../src/utils", () => ({
|
|
2
|
+
readFile: jest.fn().mockReturnValue(Buffer.from("test")),
|
|
3
|
+
fileExists: jest.fn().mockReturnValue(true),
|
|
4
|
+
fileStat: jest.fn(),
|
|
5
|
+
}));
|
|
6
|
+
|
|
7
|
+
jest.mock("../src/config", () => ({
|
|
8
|
+
getConfig: jest.fn(),
|
|
9
|
+
getLanguageConfig: jest.fn(),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
jest.mock("../src/plugins/plugins", () => ({
|
|
13
|
+
Plugins: {
|
|
14
|
+
call: jest.fn().mockReturnValue("test"),
|
|
15
|
+
listPlugins: jest.fn().mockReturnValue(["github", "asana"]),
|
|
16
|
+
},
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
import { LanguagePlugin } from "../src/plugins/language";
|
|
20
|
+
import { Config } from "../src/types";
|
|
21
|
+
import * as utils from "../src/utils";
|
|
22
|
+
import { getConfig, getLanguageConfig } from "../src/config";
|
|
23
|
+
import { Plugins } from "../src/plugins/plugins";
|
|
24
|
+
|
|
25
|
+
const mockedConfig = getConfig as jest.MockedFunction<typeof getConfig>;
|
|
26
|
+
const mockedLanguageConfig = getLanguageConfig as jest.MockedFunction<
|
|
27
|
+
typeof getLanguageConfig
|
|
28
|
+
>;
|
|
29
|
+
|
|
30
|
+
describe("LanguagePlugin", () => {
|
|
31
|
+
const userPrompt = "test prompt including terms";
|
|
32
|
+
|
|
33
|
+
test("should call the correct plugins based on the user prompt", async () => {
|
|
34
|
+
mockedConfig.mockResolvedValue({ plugins: ["github", "asana"] } as Config);
|
|
35
|
+
mockedLanguageConfig.mockResolvedValue({
|
|
36
|
+
test: {
|
|
37
|
+
sources: [
|
|
38
|
+
{ kind: "github", data: ["http://github.com/test"] },
|
|
39
|
+
{ kind: "asana", data: ["http://asana.com/test"] },
|
|
40
|
+
{ kind: "file", data: ["../.knowhow/knowhow.json"] },
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const mockedPlugins = jest.mocked(Plugins);
|
|
46
|
+
const languagePlugin = new LanguagePlugin(mockedPlugins);
|
|
47
|
+
const pluginResponse = await languagePlugin.call(userPrompt);
|
|
48
|
+
|
|
49
|
+
expect(utils.fileExists).toHaveBeenCalled();
|
|
50
|
+
expect(utils.readFile).toHaveBeenCalled();
|
|
51
|
+
expect(mockedPlugins.listPlugins).toHaveBeenCalled();
|
|
52
|
+
expect(mockedPlugins.call).toHaveBeenCalledWith(
|
|
53
|
+
"github",
|
|
54
|
+
expect.any(String)
|
|
55
|
+
);
|
|
56
|
+
expect(mockedPlugins.call).toHaveBeenCalledWith(
|
|
57
|
+
"asana",
|
|
58
|
+
expect.any(String)
|
|
59
|
+
);
|
|
60
|
+
expect(pluginResponse).toContain(
|
|
61
|
+
"LANGUAGE PLUGIN: The following terms triggered expansions"
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("should return a message if no matching terms found", async () => {
|
|
66
|
+
mockedConfig.mockResolvedValue({ plugins: ["github"] } as Config);
|
|
67
|
+
mockedLanguageConfig.mockResolvedValue({});
|
|
68
|
+
|
|
69
|
+
const languagePlugin = new LanguagePlugin(Plugins);
|
|
70
|
+
const pluginResponse = await languagePlugin.call(userPrompt);
|
|
71
|
+
|
|
72
|
+
expect(pluginResponse).toEqual("LANGUAGE PLUGIN: No matching terms found");
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { fixPatch, hunksToPatch } from "../../src/agents/tools/patch";
|
|
2
|
+
import { createTwoFilesPatch, applyPatch } from "diff";
|
|
3
|
+
|
|
4
|
+
describe("fixPatch", () => {
|
|
5
|
+
it("should fix corrupted patches", async () => {
|
|
6
|
+
const original =
|
|
7
|
+
Array(10)
|
|
8
|
+
.fill(null)
|
|
9
|
+
.map(() => Math.random().toString(36).substring(2, 15))
|
|
10
|
+
.join("\n") + "\n";
|
|
11
|
+
|
|
12
|
+
// Create random change
|
|
13
|
+
const modified = original.split("\n");
|
|
14
|
+
modified[Math.floor(Math.random() * 10)] += "_changed";
|
|
15
|
+
const newString = modified.join("\n");
|
|
16
|
+
|
|
17
|
+
// Create patch
|
|
18
|
+
const patch = createTwoFilesPatch(
|
|
19
|
+
"file.txt",
|
|
20
|
+
"file.txt",
|
|
21
|
+
original,
|
|
22
|
+
newString
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
// Corrupt the header
|
|
26
|
+
let corruptedPatch = patch.replace(/@@.*/, "@@ -1000,1 +1000,1 @@");
|
|
27
|
+
const corruptedPatchLines = corruptedPatch.split("\n");
|
|
28
|
+
|
|
29
|
+
let incorrectLine = true;
|
|
30
|
+
let missingLine = true;
|
|
31
|
+
let sawSubtraction = false;
|
|
32
|
+
for (let i = 4; i < corruptedPatchLines.length; i++) {
|
|
33
|
+
const line = corruptedPatchLines[i];
|
|
34
|
+
|
|
35
|
+
if (line.startsWith("-")) {
|
|
36
|
+
sawSubtraction = true;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (line.startsWith(" ") && incorrectLine) {
|
|
41
|
+
corruptedPatchLines[i] = "XXXX";
|
|
42
|
+
incorrectLine = false;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (line.startsWith(" ") && missingLine) {
|
|
47
|
+
delete corruptedPatchLines[i];
|
|
48
|
+
missingLine = false;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
corruptedPatch = corruptedPatchLines.join("\n");
|
|
54
|
+
|
|
55
|
+
// Try applying corrupted patch (should fail)
|
|
56
|
+
const attempt = applyPatch(original, corruptedPatch);
|
|
57
|
+
// expect(attempt).toBeUndefined();
|
|
58
|
+
|
|
59
|
+
// Fix the patch
|
|
60
|
+
console.log({ patch, corruptedPatch });
|
|
61
|
+
let fixedPatch = fixPatch(original, corruptedPatch);
|
|
62
|
+
console.log({ patch, corruptedPatch, attempt, fixedPatch });
|
|
63
|
+
|
|
64
|
+
// Apply fixed patch
|
|
65
|
+
const result = applyPatch(original, fixedPatch);
|
|
66
|
+
|
|
67
|
+
const header = fixedPatch.split("\n")[0];
|
|
68
|
+
const originalHeader = patch
|
|
69
|
+
.split("\n")
|
|
70
|
+
.find((line) => line.startsWith("@@"));
|
|
71
|
+
|
|
72
|
+
if (result !== newString) {
|
|
73
|
+
fixedPatch = fixPatch(original, corruptedPatch);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
expect(result).toBe(newString);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
@@ -5,7 +6,7 @@
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Col, Row } from 'react-bootstrap';
|
|
4
|
+
|
|
5
|
+
-import { NameValueRow, NameValueRowWithBottomBorder } from '~/components/NameValueRow';
|
|
6
|
+
+import { NameValueRow } from '~/components/NameValueRow';
|
|
7
|
+
import { BOTTOM_BORDER_CONTAINER_STYLE } from '~/components/NameValueRow/NameValueRowWithBottomBorder';
|
|
8
|
+
import { NotesPopoverWrapper } from '~/components/Notes';
|
|
9
|
+
import { TokenAgreementRowAssetUnion, UpdateTokenAgreement, UpdateTokenAgreementVariables } from '~/generated/schema';
|
|
10
|
+
|
|
11
|
+
|