jonsoc 1.1.47 → 1.1.48

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 (45) hide show
  1. package/Dockerfile +18 -18
  2. package/bin/jonsoc +265 -265
  3. package/bunfig.toml +7 -7
  4. package/package.json +23 -23
  5. package/src/agent/generate.txt +75 -75
  6. package/src/agent/prompt/compaction.txt +12 -12
  7. package/src/agent/prompt/explore.txt +18 -18
  8. package/src/agent/prompt/summary.txt +11 -11
  9. package/src/agent/prompt/title.txt +44 -44
  10. package/src/command/template/initialize.txt +10 -10
  11. package/src/command/template/review.txt +99 -99
  12. package/src/session/prompt/anthropic-20250930.txt +168 -168
  13. package/src/session/prompt/anthropic.txt +99 -99
  14. package/src/session/prompt/anthropic_spoof.txt +1 -1
  15. package/src/session/prompt/beast.txt +149 -149
  16. package/src/session/prompt/build-switch.txt +5 -5
  17. package/src/session/prompt/codex_header.txt +81 -81
  18. package/src/session/prompt/copilot-gpt-5.txt +145 -145
  19. package/src/session/prompt/gemini.txt +157 -157
  20. package/src/session/prompt/max-steps.txt +15 -15
  21. package/src/session/prompt/plan-reminder-anthropic.txt +67 -67
  22. package/src/session/prompt/plan.txt +26 -26
  23. package/src/session/prompt/qwen.txt +111 -111
  24. package/src/tool/apply_patch.txt +33 -33
  25. package/src/tool/bash.txt +115 -115
  26. package/src/tool/batch.txt +23 -23
  27. package/src/tool/codesearch.txt +12 -12
  28. package/src/tool/edit.txt +10 -10
  29. package/src/tool/glob.txt +6 -6
  30. package/src/tool/grep.txt +8 -8
  31. package/src/tool/ls.txt +1 -1
  32. package/src/tool/lsp.txt +19 -19
  33. package/src/tool/multiedit.txt +41 -41
  34. package/src/tool/plan-enter.txt +14 -14
  35. package/src/tool/plan-exit.txt +13 -13
  36. package/src/tool/question.txt +10 -10
  37. package/src/tool/read.txt +12 -12
  38. package/src/tool/task.txt +60 -60
  39. package/src/tool/todoread.txt +14 -14
  40. package/src/tool/todowrite.txt +167 -167
  41. package/src/tool/webfetch.txt +13 -13
  42. package/src/tool/websearch.txt +14 -14
  43. package/src/tool/write.txt +8 -8
  44. package/test/fixture/lsp/fake-lsp-server.js +77 -77
  45. package/test/tool/__snapshots__/tool.test.ts.snap +9 -9
@@ -1,167 +1,167 @@
1
- Use this tool to create and manage a structured task list for your current coding session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
2
- It also helps the user understand the progress of the task and overall progress of their requests.
3
-
4
- ## When to Use This Tool
5
- Use this tool proactively in these scenarios:
6
-
7
- 1. Complex multistep tasks - When a task requires 3 or more distinct steps or actions
8
- 2. Non-trivial and complex tasks - Tasks that require careful planning or multiple operations
9
- 3. User explicitly requests todo list - When the user directly asks you to use the todo list
10
- 4. User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
11
- 5. After receiving new instructions - Immediately capture user requirements as todos. Feel free to edit the todo list based on new information.
12
- 6. After completing a task - Mark it complete and add any new follow-up tasks
13
- 7. When you start working on a new task, mark the todo as in_progress. Ideally you should only have one todo as in_progress at a time. Complete existing tasks before starting new ones.
14
-
15
- ## When NOT to Use This Tool
16
-
17
- Skip using this tool when:
18
- 1. There is only a single, straightforward task
19
- 2. The task is trivial and tracking it provides no organizational benefit
20
- 3. The task can be completed in less than 3 trivial steps
21
- 4. The task is purely conversational or informational
22
-
23
- NOTE that you should not use this tool if there is only one trivial task to do. In this case you are better off just doing the task directly.
24
-
25
- ## Examples of When to Use the Todo List
26
-
27
- <example>
28
- User: I want to add a dark mode toggle to the application settings. Make sure you run the tests and build when you're done!
29
- Assistant: I'll help add a dark mode toggle to your application settings. Let me create a todo list to track this implementation.
30
- *Creates todo list with the following items:*
31
- 1. Create dark mode toggle component in Settings page
32
- 2. Add dark mode state management (context/store)
33
- 3. Implement CSS-in-JS styles for dark theme
34
- 4. Update existing components to support theme switching
35
- 5. Run tests and build process, addressing any failures or errors that occur
36
- *Begins working on the first task*
37
-
38
- <reasoning>
39
- The assistant used the todo list because:
40
- 1. Adding dark mode is a multi-step feature requiring UI, state management, and styling changes
41
- 2. The user explicitly requested tests and build be run afterward
42
- 3. The assistant inferred that tests and build need to pass by adding "Ensure tests and build succeed" as the final task
43
- </reasoning>
44
- </example>
45
-
46
- <example>
47
- User: Help me rename the function getCwd to getCurrentWorkingDirectory across my project
48
- Assistant: Let me first search through your codebase to find all occurrences of 'getCwd'.
49
- *Uses grep or search tools to locate all instances of getCwd in the codebase*
50
- Assistant: I've found 15 instances of 'getCwd' across 8 different files. Let me create a todo list to track these changes.
51
- *Creates todo list with specific items for each file that needs updating*
52
-
53
- <reasoning>
54
- The assistant used the todo list because:
55
- 1. First, the assistant searched to understand the scope of the task
56
- 2. Upon finding multiple occurrences across different files, it determined this was a complex task with multiple steps
57
- 3. The todo list helps ensure every instance is tracked and updated systematically
58
- 4. This approach prevents missing any occurrences and maintains code consistency
59
- </reasoning>
60
- </example>
61
-
62
-
63
- <example>
64
- User: I need to implement these features for my e-commerce site: user registration, product catalog, shopping cart, and checkout flow.
65
- Assistant: I'll help implement these features. First, let's add all the features to the todo list.
66
- *Creates a todo list breaking down each feature into specific tasks based on the project architecture*
67
- Assistant: Let's start with user registration. This will involve creating database models, API endpoints, and frontend forms that integrate with your existing authentication system.
68
-
69
- <reasoning>
70
- The assistant used the todo list because:
71
- 1. The user provided multiple complex features to implement in a comma separated list
72
- 2. The todo list helps organize these large features into manageable tasks
73
- 3. This approach allows for tracking progress across the entire implementation
74
- </reasoning>
75
- </example>
76
-
77
- <example>
78
- User: Can you help optimize my React application? It's rendering slowly and has performance issues.</user>
79
- Assistant: I'll help optimize your React application. First, let me examine your codebase to identify potential performance bottlenecks.
80
- *Reviews component structure, render patterns, state management, and data fetching*
81
- Assistant: After analyzing your codebase, I've identified several performance issues. Let me create a todo list to track our optimization efforts.
82
- *Creates todo list with items like: 1) Implement memoization for expensive calculations in ProductList, 2) Add virtualization for long lists in Dashboard, 3) Optimize image loading in Gallery component, 4) Fix state update loops in ShoppingCart, 5) Review bundle size and implement code splitting*
83
- Let's start by implementing memoization for the expensive calculations in your ProductList component.</assistant>
84
-
85
- <reasoning>
86
- The assistant used the todo list because:
87
- 1. First, the assistant examined the codebase to identify specific performance issues
88
- 2. Based on this analysis, it identified multiple optimization opportunities
89
- 3. Performance optimization is a non-trivial task requiring multiple steps
90
- 4. The todo list helps methodically track improvements across different components
91
- 5. This systematic approach ensures all performance bottlenecks are addressed
92
- </reasoning>
93
- </example>
94
-
95
- ## Examples of When NOT to Use the Todo List
96
-
97
- <example>
98
- User: How do I print 'Hello World' in Python?
99
- Assistant: In Python, you can print "Hello World" with this simple code:
100
-
101
- python
102
- print("Hello World")
103
-
104
- This will output the text "Hello World" to the console when executed.</assistant>
105
-
106
- <reasoning>
107
- The assistant did not use the todo list because this is a single, trivial task that can be completed in one step. There's no need to track multiple tasks or steps for such a straightforward request.
108
- </reasoning>
109
- </example>
110
-
111
- <example>
112
- User: What does the git status command do?
113
- Assistant: The git status command shows the current state of your working directory and staging area. It displays which changes have been staged, which haven't, and which files aren't being tracked by Git. This is a fundamental command for understanding the current state of your repository before making commits.
114
-
115
- <reasoning>
116
- The assistant did not use the todo list because this is an informational request with no actual coding task to complete. The user is simply asking for an explanation, not for the assistant to perform multiple steps or tasks.
117
- </reasoning>
118
- </example>
119
-
120
- <example>
121
- User: Can you add a comment to the calculateTotal function to explain what it does?
122
- Assistant: Sure, let me add a comment to the calculateTotal function to explain what it does.
123
- * Uses the Edit tool to add a comment to the calculateTotal function *
124
-
125
- <reasoning>
126
- The assistant did not use the todo list because this is a single, straightforward task confined to one location in the code. Adding a comment doesn't require tracking multiple steps or systematic organization.
127
- </reasoning>
128
- </example>
129
-
130
- <example>
131
- User: Run npm install for me and tell me what happens.
132
- Assistant: I'll run the npm install command for you.
133
-
134
- *Executes: npm install*
135
-
136
- The command completed successfully. Here's the output:
137
- [Output of npm install command]
138
-
139
- All dependencies have been installed according to your package.json file.
140
-
141
- <reasoning>
142
- The assistant did not use the todo list because this is a single command execution with immediate results. There are no multiple steps to track or organize, making the todo list unnecessary for this straightforward task.
143
- </reasoning>
144
- </example>
145
-
146
- ## Task States and Management
147
-
148
- 1. **Task States**: Use these states to track progress:
149
- - pending: Task not yet started
150
- - in_progress: Currently working on (limit to ONE task at a time)
151
- - completed: Task finished successfully
152
- - cancelled: Task no longer needed
153
-
154
- 2. **Task Management**:
155
- - Update task status in real-time as you work
156
- - Mark tasks complete IMMEDIATELY after finishing (don't batch completions)
157
- - Only have ONE task in_progress at any time
158
- - Complete current tasks before starting new ones
159
- - Cancel tasks that become irrelevant
160
-
161
- 3. **Task Breakdown**:
162
- - Create specific, actionable items
163
- - Break complex tasks into smaller, manageable steps
164
- - Use clear, descriptive task names
165
-
166
- When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully.
167
-
1
+ Use this tool to create and manage a structured task list for your current coding session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
2
+ It also helps the user understand the progress of the task and overall progress of their requests.
3
+
4
+ ## When to Use This Tool
5
+ Use this tool proactively in these scenarios:
6
+
7
+ 1. Complex multistep tasks - When a task requires 3 or more distinct steps or actions
8
+ 2. Non-trivial and complex tasks - Tasks that require careful planning or multiple operations
9
+ 3. User explicitly requests todo list - When the user directly asks you to use the todo list
10
+ 4. User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
11
+ 5. After receiving new instructions - Immediately capture user requirements as todos. Feel free to edit the todo list based on new information.
12
+ 6. After completing a task - Mark it complete and add any new follow-up tasks
13
+ 7. When you start working on a new task, mark the todo as in_progress. Ideally you should only have one todo as in_progress at a time. Complete existing tasks before starting new ones.
14
+
15
+ ## When NOT to Use This Tool
16
+
17
+ Skip using this tool when:
18
+ 1. There is only a single, straightforward task
19
+ 2. The task is trivial and tracking it provides no organizational benefit
20
+ 3. The task can be completed in less than 3 trivial steps
21
+ 4. The task is purely conversational or informational
22
+
23
+ NOTE that you should not use this tool if there is only one trivial task to do. In this case you are better off just doing the task directly.
24
+
25
+ ## Examples of When to Use the Todo List
26
+
27
+ <example>
28
+ User: I want to add a dark mode toggle to the application settings. Make sure you run the tests and build when you're done!
29
+ Assistant: I'll help add a dark mode toggle to your application settings. Let me create a todo list to track this implementation.
30
+ *Creates todo list with the following items:*
31
+ 1. Create dark mode toggle component in Settings page
32
+ 2. Add dark mode state management (context/store)
33
+ 3. Implement CSS-in-JS styles for dark theme
34
+ 4. Update existing components to support theme switching
35
+ 5. Run tests and build process, addressing any failures or errors that occur
36
+ *Begins working on the first task*
37
+
38
+ <reasoning>
39
+ The assistant used the todo list because:
40
+ 1. Adding dark mode is a multi-step feature requiring UI, state management, and styling changes
41
+ 2. The user explicitly requested tests and build be run afterward
42
+ 3. The assistant inferred that tests and build need to pass by adding "Ensure tests and build succeed" as the final task
43
+ </reasoning>
44
+ </example>
45
+
46
+ <example>
47
+ User: Help me rename the function getCwd to getCurrentWorkingDirectory across my project
48
+ Assistant: Let me first search through your codebase to find all occurrences of 'getCwd'.
49
+ *Uses grep or search tools to locate all instances of getCwd in the codebase*
50
+ Assistant: I've found 15 instances of 'getCwd' across 8 different files. Let me create a todo list to track these changes.
51
+ *Creates todo list with specific items for each file that needs updating*
52
+
53
+ <reasoning>
54
+ The assistant used the todo list because:
55
+ 1. First, the assistant searched to understand the scope of the task
56
+ 2. Upon finding multiple occurrences across different files, it determined this was a complex task with multiple steps
57
+ 3. The todo list helps ensure every instance is tracked and updated systematically
58
+ 4. This approach prevents missing any occurrences and maintains code consistency
59
+ </reasoning>
60
+ </example>
61
+
62
+
63
+ <example>
64
+ User: I need to implement these features for my e-commerce site: user registration, product catalog, shopping cart, and checkout flow.
65
+ Assistant: I'll help implement these features. First, let's add all the features to the todo list.
66
+ *Creates a todo list breaking down each feature into specific tasks based on the project architecture*
67
+ Assistant: Let's start with user registration. This will involve creating database models, API endpoints, and frontend forms that integrate with your existing authentication system.
68
+
69
+ <reasoning>
70
+ The assistant used the todo list because:
71
+ 1. The user provided multiple complex features to implement in a comma separated list
72
+ 2. The todo list helps organize these large features into manageable tasks
73
+ 3. This approach allows for tracking progress across the entire implementation
74
+ </reasoning>
75
+ </example>
76
+
77
+ <example>
78
+ User: Can you help optimize my React application? It's rendering slowly and has performance issues.</user>
79
+ Assistant: I'll help optimize your React application. First, let me examine your codebase to identify potential performance bottlenecks.
80
+ *Reviews component structure, render patterns, state management, and data fetching*
81
+ Assistant: After analyzing your codebase, I've identified several performance issues. Let me create a todo list to track our optimization efforts.
82
+ *Creates todo list with items like: 1) Implement memoization for expensive calculations in ProductList, 2) Add virtualization for long lists in Dashboard, 3) Optimize image loading in Gallery component, 4) Fix state update loops in ShoppingCart, 5) Review bundle size and implement code splitting*
83
+ Let's start by implementing memoization for the expensive calculations in your ProductList component.</assistant>
84
+
85
+ <reasoning>
86
+ The assistant used the todo list because:
87
+ 1. First, the assistant examined the codebase to identify specific performance issues
88
+ 2. Based on this analysis, it identified multiple optimization opportunities
89
+ 3. Performance optimization is a non-trivial task requiring multiple steps
90
+ 4. The todo list helps methodically track improvements across different components
91
+ 5. This systematic approach ensures all performance bottlenecks are addressed
92
+ </reasoning>
93
+ </example>
94
+
95
+ ## Examples of When NOT to Use the Todo List
96
+
97
+ <example>
98
+ User: How do I print 'Hello World' in Python?
99
+ Assistant: In Python, you can print "Hello World" with this simple code:
100
+
101
+ python
102
+ print("Hello World")
103
+
104
+ This will output the text "Hello World" to the console when executed.</assistant>
105
+
106
+ <reasoning>
107
+ The assistant did not use the todo list because this is a single, trivial task that can be completed in one step. There's no need to track multiple tasks or steps for such a straightforward request.
108
+ </reasoning>
109
+ </example>
110
+
111
+ <example>
112
+ User: What does the git status command do?
113
+ Assistant: The git status command shows the current state of your working directory and staging area. It displays which changes have been staged, which haven't, and which files aren't being tracked by Git. This is a fundamental command for understanding the current state of your repository before making commits.
114
+
115
+ <reasoning>
116
+ The assistant did not use the todo list because this is an informational request with no actual coding task to complete. The user is simply asking for an explanation, not for the assistant to perform multiple steps or tasks.
117
+ </reasoning>
118
+ </example>
119
+
120
+ <example>
121
+ User: Can you add a comment to the calculateTotal function to explain what it does?
122
+ Assistant: Sure, let me add a comment to the calculateTotal function to explain what it does.
123
+ * Uses the Edit tool to add a comment to the calculateTotal function *
124
+
125
+ <reasoning>
126
+ The assistant did not use the todo list because this is a single, straightforward task confined to one location in the code. Adding a comment doesn't require tracking multiple steps or systematic organization.
127
+ </reasoning>
128
+ </example>
129
+
130
+ <example>
131
+ User: Run npm install for me and tell me what happens.
132
+ Assistant: I'll run the npm install command for you.
133
+
134
+ *Executes: npm install*
135
+
136
+ The command completed successfully. Here's the output:
137
+ [Output of npm install command]
138
+
139
+ All dependencies have been installed according to your package.json file.
140
+
141
+ <reasoning>
142
+ The assistant did not use the todo list because this is a single command execution with immediate results. There are no multiple steps to track or organize, making the todo list unnecessary for this straightforward task.
143
+ </reasoning>
144
+ </example>
145
+
146
+ ## Task States and Management
147
+
148
+ 1. **Task States**: Use these states to track progress:
149
+ - pending: Task not yet started
150
+ - in_progress: Currently working on (limit to ONE task at a time)
151
+ - completed: Task finished successfully
152
+ - cancelled: Task no longer needed
153
+
154
+ 2. **Task Management**:
155
+ - Update task status in real-time as you work
156
+ - Mark tasks complete IMMEDIATELY after finishing (don't batch completions)
157
+ - Only have ONE task in_progress at any time
158
+ - Complete current tasks before starting new ones
159
+ - Cancel tasks that become irrelevant
160
+
161
+ 3. **Task Breakdown**:
162
+ - Create specific, actionable items
163
+ - Break complex tasks into smaller, manageable steps
164
+ - Use clear, descriptive task names
165
+
166
+ When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully.
167
+
@@ -1,13 +1,13 @@
1
- - Fetches content from a specified URL
2
- - Takes a URL and optional format as input
3
- - Fetches the URL content, converts to requested format (markdown by default)
4
- - Returns the content in the specified format
5
- - Use this tool when you need to retrieve and analyze web content
6
-
7
- Usage notes:
8
- - IMPORTANT: if another tool is present that offers better web fetching capabilities, is more targeted to the task, or has fewer restrictions, prefer using that tool instead of this one.
9
- - The URL must be a fully-formed valid URL
10
- - HTTP URLs will be automatically upgraded to HTTPS
11
- - Format options: "markdown" (default), "text", or "html"
12
- - This tool is read-only and does not modify any files
13
- - Results may be summarized if the content is very large
1
+ - Fetches content from a specified URL
2
+ - Takes a URL and optional format as input
3
+ - Fetches the URL content, converts to requested format (markdown by default)
4
+ - Returns the content in the specified format
5
+ - Use this tool when you need to retrieve and analyze web content
6
+
7
+ Usage notes:
8
+ - IMPORTANT: if another tool is present that offers better web fetching capabilities, is more targeted to the task, or has fewer restrictions, prefer using that tool instead of this one.
9
+ - The URL must be a fully-formed valid URL
10
+ - HTTP URLs will be automatically upgraded to HTTPS
11
+ - Format options: "markdown" (default), "text", or "html"
12
+ - This tool is read-only and does not modify any files
13
+ - Results may be summarized if the content is very large
@@ -1,14 +1,14 @@
1
- - Search the web using Exa AI - performs real-time web searches and can scrape content from specific URLs
2
- - Provides up-to-date information for current events and recent data
3
- - Supports configurable result counts and returns the content from the most relevant websites
4
- - Use this tool for accessing information beyond knowledge cutoff
5
- - Searches are performed automatically within a single API call
6
-
7
- Usage notes:
8
- - Supports live crawling modes: 'fallback' (backup if cached unavailable) or 'preferred' (prioritize live crawling)
9
- - Search types: 'auto' (balanced), 'fast' (quick results), 'deep' (comprehensive search)
10
- - Configurable context length for optimal LLM integration
11
- - Domain filtering and advanced search options available
12
-
13
- Today's date is {{date}}. You MUST use this year when searching for recent information or current events
14
- - Example: If today is 2025-07-15 and the user asks for "latest AI news", search for "AI news 2025", NOT "AI news 2024"
1
+ - Search the web using Exa AI - performs real-time web searches and can scrape content from specific URLs
2
+ - Provides up-to-date information for current events and recent data
3
+ - Supports configurable result counts and returns the content from the most relevant websites
4
+ - Use this tool for accessing information beyond knowledge cutoff
5
+ - Searches are performed automatically within a single API call
6
+
7
+ Usage notes:
8
+ - Supports live crawling modes: 'fallback' (backup if cached unavailable) or 'preferred' (prioritize live crawling)
9
+ - Search types: 'auto' (balanced), 'fast' (quick results), 'deep' (comprehensive search)
10
+ - Configurable context length for optimal LLM integration
11
+ - Domain filtering and advanced search options available
12
+
13
+ Today's date is {{date}}. You MUST use this year when searching for recent information or current events
14
+ - Example: If today is 2025-07-15 and the user asks for "latest AI news", search for "AI news 2025", NOT "AI news 2024"
@@ -1,8 +1,8 @@
1
- Writes a file to the local filesystem.
2
-
3
- Usage:
4
- - This tool will overwrite the existing file if there is one at the provided path.
5
- - If this is an existing file, you MUST use the Read tool first to read the file's contents. This tool will fail if you did not read the file first.
6
- - ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.
7
- - NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User.
8
- - Only use emojis if the user explicitly requests it. Avoid writing emojis to files unless asked.
1
+ Writes a file to the local filesystem.
2
+
3
+ Usage:
4
+ - This tool will overwrite the existing file if there is one at the provided path.
5
+ - If this is an existing file, you MUST use the Read tool first to read the file's contents. This tool will fail if you did not read the file first.
6
+ - ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.
7
+ - NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User.
8
+ - Only use emojis if the user explicitly requests it. Avoid writing emojis to files unless asked.
@@ -1,77 +1,77 @@
1
- // Simple JSON-RPC 2.0 LSP-like fake server over stdio
2
- // Implements a minimal LSP handshake and triggers a request upon notification
3
-
4
- const net = require("net")
5
-
6
- let nextId = 1
7
-
8
- function encode(message) {
9
- const json = JSON.stringify(message)
10
- const header = `Content-Length: ${Buffer.byteLength(json, "utf8")}\r\n\r\n`
11
- return Buffer.concat([Buffer.from(header, "utf8"), Buffer.from(json, "utf8")])
12
- }
13
-
14
- function decodeFrames(buffer) {
15
- const results = []
16
- let idx
17
- while ((idx = buffer.indexOf("\r\n\r\n")) !== -1) {
18
- const header = buffer.slice(0, idx).toString("utf8")
19
- const m = /Content-Length:\s*(\d+)/i.exec(header)
20
- const len = m ? parseInt(m[1], 10) : 0
21
- const bodyStart = idx + 4
22
- const bodyEnd = bodyStart + len
23
- if (buffer.length < bodyEnd) break
24
- const body = buffer.slice(bodyStart, bodyEnd).toString("utf8")
25
- results.push(body)
26
- buffer = buffer.slice(bodyEnd)
27
- }
28
- return { messages: results, rest: buffer }
29
- }
30
-
31
- let readBuffer = Buffer.alloc(0)
32
-
33
- process.stdin.on("data", (chunk) => {
34
- readBuffer = Buffer.concat([readBuffer, chunk])
35
- const { messages, rest } = decodeFrames(readBuffer)
36
- readBuffer = rest
37
- for (const m of messages) handle(m)
38
- })
39
-
40
- function send(msg) {
41
- process.stdout.write(encode(msg))
42
- }
43
-
44
- function sendRequest(method, params) {
45
- const id = nextId++
46
- send({ jsonrpc: "2.0", id, method, params })
47
- return id
48
- }
49
-
50
- function handle(raw) {
51
- let data
52
- try {
53
- data = JSON.parse(raw)
54
- } catch {
55
- return
56
- }
57
- if (data.method === "initialize") {
58
- send({ jsonrpc: "2.0", id: data.id, result: { capabilities: {} } })
59
- return
60
- }
61
- if (data.method === "initialized") {
62
- return
63
- }
64
- if (data.method === "workspace/didChangeConfiguration") {
65
- return
66
- }
67
- if (data.method === "test/trigger") {
68
- const method = data.params && data.params.method
69
- if (method) sendRequest(method, {})
70
- return
71
- }
72
- if (typeof data.id !== "undefined") {
73
- // Respond OK to any request from client to keep transport flowing
74
- send({ jsonrpc: "2.0", id: data.id, result: null })
75
- return
76
- }
77
- }
1
+ // Simple JSON-RPC 2.0 LSP-like fake server over stdio
2
+ // Implements a minimal LSP handshake and triggers a request upon notification
3
+
4
+ const net = require("net")
5
+
6
+ let nextId = 1
7
+
8
+ function encode(message) {
9
+ const json = JSON.stringify(message)
10
+ const header = `Content-Length: ${Buffer.byteLength(json, "utf8")}\r\n\r\n`
11
+ return Buffer.concat([Buffer.from(header, "utf8"), Buffer.from(json, "utf8")])
12
+ }
13
+
14
+ function decodeFrames(buffer) {
15
+ const results = []
16
+ let idx
17
+ while ((idx = buffer.indexOf("\r\n\r\n")) !== -1) {
18
+ const header = buffer.slice(0, idx).toString("utf8")
19
+ const m = /Content-Length:\s*(\d+)/i.exec(header)
20
+ const len = m ? parseInt(m[1], 10) : 0
21
+ const bodyStart = idx + 4
22
+ const bodyEnd = bodyStart + len
23
+ if (buffer.length < bodyEnd) break
24
+ const body = buffer.slice(bodyStart, bodyEnd).toString("utf8")
25
+ results.push(body)
26
+ buffer = buffer.slice(bodyEnd)
27
+ }
28
+ return { messages: results, rest: buffer }
29
+ }
30
+
31
+ let readBuffer = Buffer.alloc(0)
32
+
33
+ process.stdin.on("data", (chunk) => {
34
+ readBuffer = Buffer.concat([readBuffer, chunk])
35
+ const { messages, rest } = decodeFrames(readBuffer)
36
+ readBuffer = rest
37
+ for (const m of messages) handle(m)
38
+ })
39
+
40
+ function send(msg) {
41
+ process.stdout.write(encode(msg))
42
+ }
43
+
44
+ function sendRequest(method, params) {
45
+ const id = nextId++
46
+ send({ jsonrpc: "2.0", id, method, params })
47
+ return id
48
+ }
49
+
50
+ function handle(raw) {
51
+ let data
52
+ try {
53
+ data = JSON.parse(raw)
54
+ } catch {
55
+ return
56
+ }
57
+ if (data.method === "initialize") {
58
+ send({ jsonrpc: "2.0", id: data.id, result: { capabilities: {} } })
59
+ return
60
+ }
61
+ if (data.method === "initialized") {
62
+ return
63
+ }
64
+ if (data.method === "workspace/didChangeConfiguration") {
65
+ return
66
+ }
67
+ if (data.method === "test/trigger") {
68
+ const method = data.params && data.params.method
69
+ if (method) sendRequest(method, {})
70
+ return
71
+ }
72
+ if (typeof data.id !== "undefined") {
73
+ // Respond OK to any request from client to keep transport flowing
74
+ send({ jsonrpc: "2.0", id: data.id, result: null })
75
+ return
76
+ }
77
+ }
@@ -1,9 +1,9 @@
1
- // Bun Snapshot v1, https://bun.sh/docs/test/snapshots
2
-
3
- exports[`tool.ls basic 1`] = `
4
- "packages/opencode/test/fixtures/example/
5
- broken.ts
6
- cli.ts
7
- ink.tsx
8
- "
9
- `;
1
+ // Bun Snapshot v1, https://bun.sh/docs/test/snapshots
2
+
3
+ exports[`tool.ls basic 1`] = `
4
+ "packages/opencode/test/fixtures/example/
5
+ broken.ts
6
+ cli.ts
7
+ ink.tsx
8
+ "
9
+ `;