@tyvm/knowhow 0.0.35 → 0.0.37

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.
Files changed (99) hide show
  1. package/package.json +1 -1
  2. package/src/agents/tools/aiClient.ts +36 -0
  3. package/src/agents/tools/lintFile.ts +1 -1
  4. package/src/agents/tools/list.ts +34 -0
  5. package/src/agents/tools/ycmd/tools/diagnostics.ts +2 -0
  6. package/src/ai.ts +5 -4
  7. package/src/auth/browserLogin.ts +283 -0
  8. package/src/auth/errors.ts +6 -0
  9. package/src/auth/spinner.ts +23 -0
  10. package/src/chat/CliChatService.ts +25 -6
  11. package/src/chat/modules/AgentModule.ts +1 -2
  12. package/src/chat/modules/AskModule.ts +1 -2
  13. package/src/chat/types.ts +14 -4
  14. package/src/chat-old.ts +446 -0
  15. package/src/chat.ts +48 -433
  16. package/src/cli.ts +5 -12
  17. package/src/embeddings.ts +1 -1
  18. package/src/index.ts +0 -8
  19. package/src/login.ts +14 -1
  20. package/src/microphone.ts +0 -1
  21. package/src/plugins/downloader/downloader.ts +34 -122
  22. package/src/services/KnowhowClient.ts +3 -0
  23. package/src/services/index.ts +1 -2
  24. package/tests/manual/browser-login/README.md +189 -0
  25. package/tests/manual/browser-login/test_browser_login_basic.ts +115 -0
  26. package/tests/manual/browser-login/test_cli_integration.ts +169 -0
  27. package/tests/manual/browser-login/test_cross_platform_browser.ts +186 -0
  28. package/tests/manual/browser-login/test_error_scenarios.ts +223 -0
  29. package/tests/manual/cli/no-env.sh +256 -0
  30. package/ts_build/src/agents/tools/aiClient.d.ts +2 -0
  31. package/ts_build/src/agents/tools/aiClient.js +21 -1
  32. package/ts_build/src/agents/tools/aiClient.js.map +1 -1
  33. package/ts_build/src/agents/tools/lintFile.js +1 -1
  34. package/ts_build/src/agents/tools/lintFile.js.map +1 -1
  35. package/ts_build/src/agents/tools/list.js +32 -0
  36. package/ts_build/src/agents/tools/list.js.map +1 -1
  37. package/ts_build/src/agents/tools/ycmd/tools/diagnostics.js +1 -0
  38. package/ts_build/src/agents/tools/ycmd/tools/diagnostics.js.map +1 -1
  39. package/ts_build/src/ai.d.ts +1 -1
  40. package/ts_build/src/ai.js +2 -1
  41. package/ts_build/src/ai.js.map +1 -1
  42. package/ts_build/src/auth/browserLogin.d.ts +11 -0
  43. package/ts_build/src/auth/browserLogin.js +197 -0
  44. package/ts_build/src/auth/browserLogin.js.map +1 -0
  45. package/ts_build/src/auth/errors.d.ts +4 -0
  46. package/ts_build/src/auth/errors.js +13 -0
  47. package/ts_build/src/auth/errors.js.map +1 -0
  48. package/ts_build/src/auth/spinner.d.ts +7 -0
  49. package/ts_build/src/auth/spinner.js +23 -0
  50. package/ts_build/src/auth/spinner.js.map +1 -0
  51. package/ts_build/src/chat/CliChatService.d.ts +4 -3
  52. package/ts_build/src/chat/CliChatService.js +18 -4
  53. package/ts_build/src/chat/CliChatService.js.map +1 -1
  54. package/ts_build/src/chat/modules/AgentModule.d.ts +1 -1
  55. package/ts_build/src/chat/modules/AgentModule.js +1 -2
  56. package/ts_build/src/chat/modules/AgentModule.js.map +1 -1
  57. package/ts_build/src/chat/modules/AskModule.js +1 -2
  58. package/ts_build/src/chat/modules/AskModule.js.map +1 -1
  59. package/ts_build/src/chat/types.d.ts +5 -3
  60. package/ts_build/src/chat-old.d.ts +13 -0
  61. package/ts_build/src/chat-old.js +340 -0
  62. package/ts_build/src/chat-old.js.map +1 -0
  63. package/ts_build/src/chat.d.ts +3 -13
  64. package/ts_build/src/chat.js +38 -331
  65. package/ts_build/src/chat.js.map +1 -1
  66. package/ts_build/src/chat2.d.ts +1 -1
  67. package/ts_build/src/chat2.js +2 -2
  68. package/ts_build/src/chat2.js.map +1 -1
  69. package/ts_build/src/cli.js +3 -9
  70. package/ts_build/src/cli.js.map +1 -1
  71. package/ts_build/src/embeddings.js.map +1 -1
  72. package/ts_build/src/index.d.ts +0 -2
  73. package/ts_build/src/index.js +1 -9
  74. package/ts_build/src/index.js.map +1 -1
  75. package/ts_build/src/login.d.ts +1 -1
  76. package/ts_build/src/login.js +14 -0
  77. package/ts_build/src/login.js.map +1 -1
  78. package/ts_build/src/microphone.js.map +1 -1
  79. package/ts_build/src/plugins/downloader/downloader.d.ts +1 -6
  80. package/ts_build/src/plugins/downloader/downloader.js +26 -97
  81. package/ts_build/src/plugins/downloader/downloader.js.map +1 -1
  82. package/ts_build/src/services/KnowhowClient.js +3 -0
  83. package/ts_build/src/services/KnowhowClient.js.map +1 -1
  84. package/ts_build/src/services/index.js +1 -2
  85. package/ts_build/src/services/index.js.map +1 -1
  86. package/ts_build/tests/manual/browser-login/test_browser_login_basic.d.ts +2 -0
  87. package/ts_build/tests/manual/browser-login/test_browser_login_basic.js +108 -0
  88. package/ts_build/tests/manual/browser-login/test_browser_login_basic.js.map +1 -0
  89. package/ts_build/tests/manual/browser-login/test_cli_integration.d.ts +2 -0
  90. package/ts_build/tests/manual/browser-login/test_cli_integration.js +153 -0
  91. package/ts_build/tests/manual/browser-login/test_cli_integration.js.map +1 -0
  92. package/ts_build/tests/manual/browser-login/test_cross_platform_browser.d.ts +2 -0
  93. package/ts_build/tests/manual/browser-login/test_cross_platform_browser.js +159 -0
  94. package/ts_build/tests/manual/browser-login/test_cross_platform_browser.js.map +1 -0
  95. package/ts_build/tests/manual/browser-login/test_error_scenarios.d.ts +2 -0
  96. package/ts_build/tests/manual/browser-login/test_error_scenarios.js +197 -0
  97. package/ts_build/tests/manual/browser-login/test_error_scenarios.js.map +1 -0
  98. package/src/agents/vim/vim.ts +0 -152
  99. package/src/chat2.ts +0 -62
@@ -1,152 +0,0 @@
1
- import * as fs from "fs";
2
- import { Message } from "../../clients/types";
3
- import { AgentContext, BaseAgent } from "../base/base";
4
- import { readFile, writeFile, execAsync, mkdir } from "../../utils";
5
- import { openai, singlePrompt, Models } from "../../ai";
6
- import { BASE_PROMPT } from "../base/prompt";
7
-
8
- export class VimAgent extends BaseAgent {
9
- name = "Vimmer";
10
- description = `This agent is prepared to modify files in the codebase by using vim`;
11
-
12
- toolPath = ".knowhow/tools/vim";
13
-
14
- constructor(context: AgentContext) {
15
- super(context);
16
- // this.disableTool("patchFile");
17
- this.setModelPreferences([
18
- { model: Models.anthropic.Sonnet4, provider: "anthropic" },
19
- ]);
20
- }
21
-
22
- async saveVimGuide() {
23
- const vimrc = await execAsync("cat ~/.vim/vimrc");
24
- await mkdir(this.toolPath, { recursive: true });
25
- const vimRcPrompt = `Extract a minimal format of commands and hotkeys that an ai could leverage from this vimrc ${vimrc.stdout}. Only output the hotkeys and commands you see, nothing else`;
26
- const extraction = await singlePrompt(vimRcPrompt);
27
- await writeFile(".knowhow/tools/vim/guide.md", extraction);
28
- }
29
-
30
- async getVimGuide() {
31
- if (!fs.existsSync(".knowhow/tools/vim/guide.md")) {
32
- await this.saveVimGuide();
33
- }
34
-
35
- const guide = await readFile(".knowhow/tools/vim/guide.md");
36
- return guide;
37
- }
38
-
39
- async getInitialMessages(userInput: string) {
40
- return [
41
- {
42
- role: "system",
43
- content: `
44
- ${BASE_PROMPT}
45
-
46
- Specialization: Vim Agent, ${this.description}
47
-
48
- # General Instructions
49
-
50
- You are a software engineering agent. You use tools to gather context on a user's request, answer questions, and create modifications to files in order to help the user work on a codebase.
51
- Some user requests require you to investigate many files, and gather context before attempting to modify anything. If a user asks a question about the codebase or if you need more context on something before making modifications, you should ask the Researcher agent for help by using the agentCall tool.
52
-
53
- You are a vim specialist, and you primarily use the VIM tools (sendVimInput) to make edits to files. You are primarily operating as a terminal app that the user runs from their current working directory.
54
- The sendVimInput function will open a blank vim process in the user's working directory.
55
- Make sure to open the file you are working on at the beginning, as you are in a blank vim session.
56
- Use :e <filename>\\n to open a file, and <ESCAPE>:w\\n to save it.
57
- Make sure to send the proper escape ('<ESCAPE>') and save commands after modifying a file.
58
- Make sure to use ESCAPE to exit insert mode before attempting to execute commands like (<ESCAPE>:w\\n).
59
- When executing commands, make sure you actually execute them by including a newline character after the command.
60
- If you do not include the newline, it will not actually execute the command.
61
- Make sure you use the typical vim keys to move and enter modes, <ESCAPE> and <ENTER> are specially supported tags, but the rest of the inputs should be the normally supported vim keys that you would press on the keyboard.
62
-
63
-
64
-
65
- # Interaction Loop
66
- Using the editor should follow an interaction loop:
67
- 1. First open the editor.
68
- 2. Attempt to open the file you want to edit.
69
- 2.a IMPORTANT: DO NOT SEND ANY OTHER COMMANDS, VERIFY THE FILE HAS OPENED CORRECTLY.
70
- 2.b If the file did not open correctly, you will need to close vim and re-open it to try again.
71
- 2.c If you expect a file to have text, and you do not get any text in the terminal output after attempting to open it, there is a high likelihood the file was not opened correctly and you should try again. If you see [No Name] that also may indicate the file was not opened correctly.
72
- 2.d After opening a file, verify that you are in the correct buffer by checking for the expected file name in the terminal output. If the output shows [No Name] or another buffer name, close Vim and retry opening the correct file.
73
- 3. Inspect the response from openFileInVim to determine if the file was opened.
74
- * Check for any errors or prompts that may have occurred, respond to them if so.
75
- 4. Use sendVimInput to modify the file in vim.
76
- * Do not use <ESCAPE> while typing, unless you want to exit insert mode.
77
- 5. Save your changes via <ESCAPE>:w\\n or saveVimFile .
78
- * From the returned terminal outputs, determine if the changes went as expected.
79
- 6. ALWAYS use readFile tool to check your work after saving.
80
- * Based off the results, you may need to undo and then save.
81
- * As long as vim has not been closed, you can send :u0 or use u to undo
82
- * You may also leverage git diff
83
- 7. If you discover there were errors to your changes, attempt to fix them by repeating steps 4-6,
84
- * After failing a twice, you should enter paste mode and output the expected contents of the file to vim.
85
- 8. After completing your task and checking your work, you MUST call finalAnswer.
86
-
87
-
88
-
89
- After each sendVimInput, the function response will contain the changes in the vim terminal. Inspect that response to get an understanding of what is happening in the editor.
90
-
91
- The vim process will remain open, and you can correct your current state by responding to the state of the terminal.
92
- It may help to execute fewer commands up front until you're confident you have opened the file you want to edit.
93
- If you check a file after your changes and find that some input has messed it up, and you've saved, you can undo your changes with :u0, or use the undo command to go back one change at a time.
94
-
95
- Use multiple interactions with sendVimInput to make changes to the file, inspecting the response each time to ensure the current state of vim is as expected.
96
- Since vim is interactive, you may be required to respond to prompts the program asks in order to proceed, you will need to monitor the response from sendVimInput to know when and how to respond to these prompts.
97
-
98
- # Using ESCAPE to change modes
99
- <ESCAPE> should only be used to change vim modes.
100
- Once you are in insert mode, be careful not to send <ESCAPE> as part of the text you are entering.
101
- When you go to exit insert mode, to save, or run some other :command, you MUST send <ESCAPE> before the command.
102
-
103
- # User's active vim plugins
104
- Here's a guide on what plugins and features are currently enabled in vim:
105
- START VIM GUIDE
106
- ${await this.getVimGuide()}
107
- END VIM GUIDE
108
-
109
- # Programming Instructions
110
- After modifying source code, you must run the auto-format before saving with gg=G or any plugin commands for formatting.
111
- All inserted code should be properly indented and styled consistently with the surrounding code.
112
- Ensure that you follow programming best practices, style best practices, and ensure that the syntax of the file is correct.
113
- Pay very close attention to text around your changes, as you may inadvertently affect or break the surrounding code if you inserted code in the wrong place.
114
-
115
- The vim plugins may include auto-completes, auto-indents etc that will impact bulk inserting of lines of text.
116
- If you do not need to leverage those features, then you should enable paste mode via :set paste and :set nopaste to disable it after inserting your fully formatted text.
117
- The editor may assume comments continue on the next line, or do other syntax auto completions, so make sure to check the actual state of a file, and make corrections if the editor over-corrected your input, or use paste mode to ensure your input goes in unaffected.
118
- Commenting out code: You may want to use I to begin inserting at the beginning of a line, that way you ensure you're commenting out the entire line.
119
- Searching to insert: Keep in mind that when you search, your cursor will be at the first character of what you searched for, so you may need to start inserting on the line below, or at the start of a line, or use movement keys after the search to ensure the cursor is in the correct location before inserting.
120
- Make sure you append <ENTER> when searching or executing commands otherwise they won't be executed.
121
- IMPORTANT: You MUST enable paste mode when inserting comments, otherwise you'll end up commenting out all your inserted code.
122
-
123
- ## Navigating / Inserting Code
124
- 1. After saving, you may see some QuickFix suggestions in the terminal output. If so, you should check your changes and see if that feedback needs to be addressed before finalizing your work.
125
- 1.a If you make unintended changes you should undo via :u0 and save to get back to a clean state before making corrections.
126
- 1.b If you see QuickFix suggestions, you likely need to close the QuickFix menu before you can save again, as that buffer will start intercepting your save requests and lead you to believe the buffer is no longer modifiable.
127
-
128
- ## Handling Quickfix Buffers
129
- When working with Vim, if a Quickfix buffer opens (e.g., after saving a file), ensure you are in the correct buffer before executing further commands. Quickfix buffers are usually non-modifiable and can intercept commands like saving, leading to errors.
130
- - Use :cclose to close the Quickfix buffer before proceeding if it opens unexpectedly.
131
- - Always verify the current buffer before making modifications by checking the filename displayed in the terminal output.
132
-
133
- # Error Handling and Recovery
134
- - If an error is encountered (e.g., "modifiable" is off), pause and diagnose the issue. Do not continue sending commands that might exacerbate the problem.
135
- - Use :u to undo the last change if it was executed incorrectly. If you’ve saved incorrect changes, use :u0 to reset to the last saved state before retrying.
136
- - If Vim enters an unexpected state (e.g., Quickfix buffer intercepts commands), close Vim and restart from a clean state to avoid compounding errors.
137
-
138
- Some QuickFix hints are only shown after saving a file. So a trick to see if a file has any suggestions, would be to open it, and then immediately save without making any changes, that way you can review the QuickFix suggestions.
139
-
140
- # Completing a task
141
- When you have completed your task make sure to call closeVim before calling finalAnswer.
142
- You may use the execCommand tool to navigate the filesystem and to create new folders if needed.
143
- You MUST eventually call finalAnswer when you are done.
144
- Accomplish the user's goal with the tools at hand, good luck!
145
-
146
- `,
147
- },
148
- { role: "user", content: userInput },
149
- ] as Message[];
150
- }
151
- }
152
-
package/src/chat2.ts DELETED
@@ -1,62 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * New Modular Chat Interface - Simplified and cleaner than original chat.ts
5
- */
6
-
7
- import { CliChatService } from "./chat/CliChatService.js";
8
- import { InternalChatModule } from "./chat/modules/InternalChatModule.js";
9
- import { getConfig } from "./config.js";
10
-
11
- async function main() {
12
- try {
13
- // Load configuration and plugins
14
- let config;
15
- try {
16
- config = await getConfig();
17
- } catch (configError) {
18
- console.warn(
19
- "Warning: Could not load config, using default plugins:",
20
- configError
21
- );
22
- config = {
23
- plugins: [
24
- "embeddings",
25
- "language",
26
- "vim",
27
- "github",
28
- "asana",
29
- "jira",
30
- "linear",
31
- "download",
32
- "figma",
33
- "url",
34
- ],
35
- };
36
- }
37
-
38
- // Create chat service with plugins
39
- const chatService = new CliChatService(config.plugins);
40
-
41
- // Load internal chat module (includes all core functionality)
42
- const internalModule = new InternalChatModule();
43
- await internalModule.initialize(chatService);
44
-
45
- // Start the chat loop
46
- await chatService.startChatLoop();
47
- } catch (error) {
48
- console.error("Error starting chat:", error);
49
- process.exit(1);
50
- }
51
- }
52
-
53
- // Check if this file is being run directly
54
- const isMainModule =
55
- (process.argv[1] && process.argv[1].endsWith("chat2.ts")) ||
56
- (process.argv[1] && process.argv[1].endsWith("chat2.js"));
57
-
58
- if (isMainModule) {
59
- main().catch(console.error);
60
- }
61
-
62
- export { main as startChat2 };