@yeyuan98/opencode-bioresearcher-plugin 1.4.0 → 1.5.0-alpha.0

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 (72) hide show
  1. package/README.md +35 -20
  2. package/dist/db-tools/backends/index.d.ts +11 -0
  3. package/dist/db-tools/backends/index.js +48 -0
  4. package/dist/db-tools/backends/mongodb/backend.d.ts +15 -0
  5. package/dist/db-tools/backends/mongodb/backend.js +76 -0
  6. package/dist/db-tools/backends/mongodb/connection.d.ts +27 -0
  7. package/dist/db-tools/backends/mongodb/connection.js +107 -0
  8. package/dist/db-tools/backends/mongodb/index.d.ts +4 -0
  9. package/dist/db-tools/backends/mongodb/index.js +3 -0
  10. package/dist/db-tools/backends/mongodb/translator.d.ts +30 -0
  11. package/dist/db-tools/backends/mongodb/translator.js +407 -0
  12. package/dist/db-tools/backends/mysql/backend.d.ts +15 -0
  13. package/dist/db-tools/backends/mysql/backend.js +57 -0
  14. package/dist/db-tools/backends/mysql/connection.d.ts +25 -0
  15. package/dist/db-tools/backends/mysql/connection.js +83 -0
  16. package/dist/db-tools/backends/mysql/index.d.ts +3 -0
  17. package/dist/db-tools/backends/mysql/index.js +2 -0
  18. package/dist/db-tools/backends/mysql/translator.d.ts +7 -0
  19. package/dist/db-tools/backends/mysql/translator.js +67 -0
  20. package/dist/db-tools/core/base.d.ts +17 -0
  21. package/dist/db-tools/core/base.js +51 -0
  22. package/dist/db-tools/core/config-loader.d.ts +3 -0
  23. package/dist/db-tools/core/config-loader.js +46 -0
  24. package/dist/db-tools/core/index.d.ts +2 -0
  25. package/dist/db-tools/core/index.js +2 -0
  26. package/dist/db-tools/core/jsonc-parser.d.ts +2 -0
  27. package/dist/db-tools/core/jsonc-parser.js +77 -0
  28. package/dist/db-tools/core/validator.d.ts +16 -0
  29. package/dist/db-tools/core/validator.js +118 -0
  30. package/dist/db-tools/executor.d.ts +13 -0
  31. package/dist/db-tools/executor.js +54 -0
  32. package/dist/db-tools/index.d.ts +51 -0
  33. package/dist/db-tools/index.js +27 -0
  34. package/dist/db-tools/interface/backend.d.ts +24 -0
  35. package/dist/db-tools/interface/backend.js +1 -0
  36. package/dist/db-tools/interface/connection.d.ts +21 -0
  37. package/dist/db-tools/interface/connection.js +11 -0
  38. package/dist/db-tools/interface/index.d.ts +4 -0
  39. package/dist/db-tools/interface/index.js +4 -0
  40. package/dist/db-tools/interface/query.d.ts +60 -0
  41. package/dist/db-tools/interface/query.js +1 -0
  42. package/dist/db-tools/interface/schema.d.ts +22 -0
  43. package/dist/db-tools/interface/schema.js +1 -0
  44. package/dist/db-tools/pool.d.ts +8 -0
  45. package/dist/db-tools/pool.js +49 -0
  46. package/dist/db-tools/tools/index.d.ts +27 -0
  47. package/dist/db-tools/tools/index.js +191 -0
  48. package/dist/db-tools/tools.d.ts +27 -0
  49. package/dist/db-tools/tools.js +111 -0
  50. package/dist/db-tools/types.d.ts +94 -0
  51. package/dist/db-tools/types.js +40 -0
  52. package/dist/db-tools/utils.d.ts +33 -0
  53. package/dist/db-tools/utils.js +94 -0
  54. package/dist/index.js +2 -0
  55. package/dist/skills/bioresearcher-core/README.md +210 -210
  56. package/dist/skills/bioresearcher-core/SKILL.md +128 -128
  57. package/dist/skills/bioresearcher-core/examples/contexts.json +29 -29
  58. package/dist/skills/bioresearcher-core/examples/data-exchange-example.md +303 -303
  59. package/dist/skills/bioresearcher-core/examples/template.md +49 -49
  60. package/dist/skills/bioresearcher-core/patterns/calculator.md +215 -215
  61. package/dist/skills/bioresearcher-core/patterns/data-exchange.md +406 -406
  62. package/dist/skills/bioresearcher-core/patterns/json-tools.md +263 -263
  63. package/dist/skills/bioresearcher-core/patterns/progress.md +127 -127
  64. package/dist/skills/bioresearcher-core/patterns/retry.md +110 -110
  65. package/dist/skills/bioresearcher-core/patterns/shell-commands.md +79 -79
  66. package/dist/skills/bioresearcher-core/patterns/subagent-waves.md +186 -186
  67. package/dist/skills/bioresearcher-core/patterns/table-tools.md +260 -260
  68. package/dist/skills/bioresearcher-core/patterns/user-confirmation.md +187 -187
  69. package/dist/skills/bioresearcher-core/python/template.md +273 -273
  70. package/dist/skills/bioresearcher-core/python/template.py +323 -323
  71. package/dist/skills/env-jsonc-setup/SKILL.md +206 -0
  72. package/package.json +3 -1
@@ -1,263 +1,263 @@
1
- # JSON Tools Pattern
2
-
3
- Guide for using JSON tools (jsonExtract, jsonValidate, jsonInfer) in BioResearcher workflows.
4
-
5
- ## Overview
6
-
7
- These tools replace custom Python code for JSON operations:
8
- - **jsonExtract**: Extract JSON from files (handles markdown code blocks, raw JSON)
9
- - **jsonValidate**: Validate JSON against schemas (supports Draft-4, Draft-7, Draft-2020-12)
10
- - **jsonInfer**: Infer schemas from JSON data
11
-
12
- ## Tool: jsonExtract
13
-
14
- Extract JSON from files that may contain extra text.
15
-
16
- ### Signature
17
- ```
18
- jsonExtract(file_path: string, return_all: boolean = false)
19
- ```
20
-
21
- ### Return Format
22
- ```json
23
- {
24
- "success": true,
25
- "data": { ... } or [ ... ],
26
- "metadata": {
27
- "method": "json_code_block" | "code_block" | "object" | "array",
28
- "dataType": "object" | "array" | "mixed",
29
- "fileSize": 1234
30
- }
31
- }
32
- ```
33
-
34
- ### Extraction Methods (in order)
35
- 1. **json_code_block**: Content in ```json ... ```
36
- 2. **code_block**: Content in ``` ... ```
37
- 3. **object**: First {...} with proper brace matching
38
- 4. **array**: First [...] with proper bracket matching
39
-
40
- ### Examples
41
-
42
- ```
43
- # Extract from markdown with JSON code block
44
- jsonExtract(file_path="outputs/batch001.md")
45
-
46
- # Extract all JSON objects from file
47
- jsonExtract(file_path="outputs/all_batches.md", return_all=true)
48
- ```
49
-
50
- ### Error Codes
51
- | Code | Description |
52
- |------|-------------|
53
- | `FILE_NOT_FOUND` | File does not exist |
54
- | `FILE_TOO_LARGE` | File exceeds 200MB limit |
55
- | `BINARY_FILE` | File is binary format |
56
- | `EMPTY_FILE` | File has no content |
57
- | `NO_JSON_FOUND` | No valid JSON found |
58
-
59
- ## Tool: jsonValidate
60
-
61
- Validate JSON data against a JSON Schema.
62
-
63
- ### Signature
64
- ```
65
- jsonValidate(data: string, schema: string)
66
- ```
67
-
68
- - `data`: JSON string to validate
69
- - `schema`: JSON Schema string OR file path (auto-detected)
70
-
71
- ### Return Format (Success)
72
- ```json
73
- {
74
- "success": true,
75
- "data": { ... },
76
- "valid": true,
77
- "metadata": {
78
- "errorCount": 0,
79
- "schemaFeatures": {
80
- "validated": ["type", "properties", "required"],
81
- "ignored": ["uniqueItems"]
82
- }
83
- }
84
- }
85
- ```
86
-
87
- > **Note:** Always check `success` first, then `valid`. If `success` is true and `errorCount` is 0, the validation passed regardless of `valid` field presence.
88
-
89
- ### Return Format (Validation Errors)
90
- ```json
91
- {
92
- "success": true,
93
- "data": null,
94
- "valid": false,
95
- "errors": [
96
- {
97
- "path": "summaries.0.row_number",
98
- "message": "Expected number, received string",
99
- "code": "invalid_type",
100
- "expected": "number",
101
- "received": "string"
102
- }
103
- ],
104
- "metadata": {
105
- "errorCount": 1
106
- }
107
- }
108
- ```
109
-
110
- ### Examples
111
-
112
- ```
113
- # Validate with inline schema
114
- jsonValidate(
115
- data='{"name": "test", "age": 30}',
116
- schema='{"type": "object", "properties": {"name": {"type": "string"}, "age": {"type": "number"}}}'
117
- )
118
-
119
- # Validate with schema file
120
- jsonValidate(
121
- data='{"batch_number": 1, "summaries": [...]}',
122
- schema='./schemas/batch_output.schema.json'
123
- )
124
- ```
125
-
126
- ### Unsupported Schema Features
127
- - `not`, `unevaluatedItems`, `unevaluatedProperties`
128
- - `if`, `then`, `else`, `dependentSchemas`
129
-
130
- ### Silently Ignored Features
131
- - `uniqueItems`, `contains`, `minContains`, `maxContains`
132
-
133
- ## Tool: jsonInfer
134
-
135
- Generate a JSON Schema from example data.
136
-
137
- ### Signature
138
- ```
139
- jsonInfer(data: string, strict: boolean = false)
140
- ```
141
-
142
- - `data`: Example JSON string
143
- - `strict`: If true, all fields required at all levels; if false, only top-level required array is omitted (nested objects may still have required fields)
144
-
145
- ### Return Format
146
- ```json
147
- {
148
- "success": true,
149
- "data": {
150
- "$schema": "https://json-schema.org/draft/2020-12/schema",
151
- "type": "object",
152
- "properties": {
153
- "name": { "type": "string" },
154
- "age": { "type": "integer" }
155
- },
156
- "required": ["name", "age"]
157
- },
158
- "metadata": {
159
- "inferredType": "object",
160
- "strictMode": true
161
- }
162
- }
163
- ```
164
-
165
- ### Examples
166
-
167
- ```
168
- # Infer schema from example (optional fields)
169
- jsonInfer(data='{"name": "Alice", "age": 30}', strict=false)
170
-
171
- # Infer schema with required fields
172
- jsonInfer(data='{"batch_number": 1, "summaries": [{"row": 1, "value": "test"}]}', strict=true)
173
- ```
174
-
175
- ### Warnings
176
- - `MIXED_TYPE_ARRAY`: Array contains multiple types
177
- - `EMPTY_ARRAY`: Cannot infer element type
178
- - `PARTIAL_OBJECT_SCHEMA`: Object has many properties
179
-
180
- ### Generated Constraints
181
-
182
- jsonInfer may add the following constraints automatically:
183
-
184
- | Type | Constraint | Value | Purpose |
185
- |------|------------|-------|---------|
186
- | integer | minimum/maximum | ±9007199254740991 | JavaScript safe integer range |
187
-
188
- > **Note:** These constraints ensure JSON compatibility but may be overly restrictive for your use case. Remove them from the generated schema if not needed.
189
-
190
- ## Common Workflows
191
-
192
- ### Validate Subagent Output
193
-
194
- ```
195
- # 1. Extract JSON from output file
196
- result = jsonExtract(file_path="./outputs/batch001.md")
197
- if not result.success:
198
- log_error("Failed to extract JSON")
199
- return
200
-
201
- # 2. Validate against expected schema
202
- validation = jsonValidate(
203
- data=json.dumps(result.data),
204
- schema=batch_output_schema
205
- )
206
-
207
- if not validation.valid:
208
- log_error(f"Validation failed: {validation.errors}")
209
- return
210
-
211
- # 3. Process validated data
212
- process(result.data)
213
- ```
214
-
215
- ### Infer Schema from Example
216
-
217
- ```
218
- # 1. Get first valid output
219
- result = jsonExtract(file_path="./outputs/batch001.md")
220
-
221
- # 2. Infer schema from example
222
- schema_result = jsonInfer(
223
- data=json.dumps(result.data),
224
- strict=true
225
- )
226
-
227
- # 3. Use inferred schema for validation
228
- inferred_schema = json.dumps(schema_result.data)
229
-
230
- # 4. Validate other outputs
231
- for file in other_files:
232
- data = jsonExtract(file_path=file)
233
- validation = jsonValidate(
234
- data=json.dumps(data.data),
235
- schema=inferred_schema
236
- )
237
- ```
238
-
239
- ### Combine Multiple JSON Files
240
-
241
- ```
242
- # 1. Extract all JSON objects
243
- all_data = []
244
- for file in output_files:
245
- result = jsonExtract(file_path=file, return_all=true)
246
- if result.success:
247
- all_data.extend(result.data)
248
-
249
- # 2. Create combined output
250
- tableCreateFile(
251
- file_path="./combined.xlsx",
252
- sheet_name="Results",
253
- data=all_data
254
- )
255
- ```
256
-
257
- ## Best Practices
258
-
259
- 1. **Always check success**: Check `result.success` before using `result.data`
260
- 2. **Handle errors gracefully**: Log errors and continue with other files
261
- 3. **Use strict mode for inference**: When you know all fields are required
262
- 4. **Validate early**: Validate before processing to catch errors early
263
- 5. **Keep schemas simple**: Avoid unsupported schema features
1
+ # JSON Tools Pattern
2
+
3
+ Guide for using JSON tools (jsonExtract, jsonValidate, jsonInfer) in BioResearcher workflows.
4
+
5
+ ## Overview
6
+
7
+ These tools replace custom Python code for JSON operations:
8
+ - **jsonExtract**: Extract JSON from files (handles markdown code blocks, raw JSON)
9
+ - **jsonValidate**: Validate JSON against schemas (supports Draft-4, Draft-7, Draft-2020-12)
10
+ - **jsonInfer**: Infer schemas from JSON data
11
+
12
+ ## Tool: jsonExtract
13
+
14
+ Extract JSON from files that may contain extra text.
15
+
16
+ ### Signature
17
+ ```
18
+ jsonExtract(file_path: string, return_all: boolean = false)
19
+ ```
20
+
21
+ ### Return Format
22
+ ```json
23
+ {
24
+ "success": true,
25
+ "data": { ... } or [ ... ],
26
+ "metadata": {
27
+ "method": "json_code_block" | "code_block" | "object" | "array",
28
+ "dataType": "object" | "array" | "mixed",
29
+ "fileSize": 1234
30
+ }
31
+ }
32
+ ```
33
+
34
+ ### Extraction Methods (in order)
35
+ 1. **json_code_block**: Content in ```json ... ```
36
+ 2. **code_block**: Content in ``` ... ```
37
+ 3. **object**: First {...} with proper brace matching
38
+ 4. **array**: First [...] with proper bracket matching
39
+
40
+ ### Examples
41
+
42
+ ```
43
+ # Extract from markdown with JSON code block
44
+ jsonExtract(file_path="outputs/batch001.md")
45
+
46
+ # Extract all JSON objects from file
47
+ jsonExtract(file_path="outputs/all_batches.md", return_all=true)
48
+ ```
49
+
50
+ ### Error Codes
51
+ | Code | Description |
52
+ |------|-------------|
53
+ | `FILE_NOT_FOUND` | File does not exist |
54
+ | `FILE_TOO_LARGE` | File exceeds 200MB limit |
55
+ | `BINARY_FILE` | File is binary format |
56
+ | `EMPTY_FILE` | File has no content |
57
+ | `NO_JSON_FOUND` | No valid JSON found |
58
+
59
+ ## Tool: jsonValidate
60
+
61
+ Validate JSON data against a JSON Schema.
62
+
63
+ ### Signature
64
+ ```
65
+ jsonValidate(data: string, schema: string)
66
+ ```
67
+
68
+ - `data`: JSON string to validate
69
+ - `schema`: JSON Schema string OR file path (auto-detected)
70
+
71
+ ### Return Format (Success)
72
+ ```json
73
+ {
74
+ "success": true,
75
+ "data": { ... },
76
+ "valid": true,
77
+ "metadata": {
78
+ "errorCount": 0,
79
+ "schemaFeatures": {
80
+ "validated": ["type", "properties", "required"],
81
+ "ignored": ["uniqueItems"]
82
+ }
83
+ }
84
+ }
85
+ ```
86
+
87
+ > **Note:** Always check `success` first, then `valid`. If `success` is true and `errorCount` is 0, the validation passed regardless of `valid` field presence.
88
+
89
+ ### Return Format (Validation Errors)
90
+ ```json
91
+ {
92
+ "success": true,
93
+ "data": null,
94
+ "valid": false,
95
+ "errors": [
96
+ {
97
+ "path": "summaries.0.row_number",
98
+ "message": "Expected number, received string",
99
+ "code": "invalid_type",
100
+ "expected": "number",
101
+ "received": "string"
102
+ }
103
+ ],
104
+ "metadata": {
105
+ "errorCount": 1
106
+ }
107
+ }
108
+ ```
109
+
110
+ ### Examples
111
+
112
+ ```
113
+ # Validate with inline schema
114
+ jsonValidate(
115
+ data='{"name": "test", "age": 30}',
116
+ schema='{"type": "object", "properties": {"name": {"type": "string"}, "age": {"type": "number"}}}'
117
+ )
118
+
119
+ # Validate with schema file
120
+ jsonValidate(
121
+ data='{"batch_number": 1, "summaries": [...]}',
122
+ schema='./schemas/batch_output.schema.json'
123
+ )
124
+ ```
125
+
126
+ ### Unsupported Schema Features
127
+ - `not`, `unevaluatedItems`, `unevaluatedProperties`
128
+ - `if`, `then`, `else`, `dependentSchemas`
129
+
130
+ ### Silently Ignored Features
131
+ - `uniqueItems`, `contains`, `minContains`, `maxContains`
132
+
133
+ ## Tool: jsonInfer
134
+
135
+ Generate a JSON Schema from example data.
136
+
137
+ ### Signature
138
+ ```
139
+ jsonInfer(data: string, strict: boolean = false)
140
+ ```
141
+
142
+ - `data`: Example JSON string
143
+ - `strict`: If true, all fields required at all levels; if false, only top-level required array is omitted (nested objects may still have required fields)
144
+
145
+ ### Return Format
146
+ ```json
147
+ {
148
+ "success": true,
149
+ "data": {
150
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
151
+ "type": "object",
152
+ "properties": {
153
+ "name": { "type": "string" },
154
+ "age": { "type": "integer" }
155
+ },
156
+ "required": ["name", "age"]
157
+ },
158
+ "metadata": {
159
+ "inferredType": "object",
160
+ "strictMode": true
161
+ }
162
+ }
163
+ ```
164
+
165
+ ### Examples
166
+
167
+ ```
168
+ # Infer schema from example (optional fields)
169
+ jsonInfer(data='{"name": "Alice", "age": 30}', strict=false)
170
+
171
+ # Infer schema with required fields
172
+ jsonInfer(data='{"batch_number": 1, "summaries": [{"row": 1, "value": "test"}]}', strict=true)
173
+ ```
174
+
175
+ ### Warnings
176
+ - `MIXED_TYPE_ARRAY`: Array contains multiple types
177
+ - `EMPTY_ARRAY`: Cannot infer element type
178
+ - `PARTIAL_OBJECT_SCHEMA`: Object has many properties
179
+
180
+ ### Generated Constraints
181
+
182
+ jsonInfer may add the following constraints automatically:
183
+
184
+ | Type | Constraint | Value | Purpose |
185
+ |------|------------|-------|---------|
186
+ | integer | minimum/maximum | ±9007199254740991 | JavaScript safe integer range |
187
+
188
+ > **Note:** These constraints ensure JSON compatibility but may be overly restrictive for your use case. Remove them from the generated schema if not needed.
189
+
190
+ ## Common Workflows
191
+
192
+ ### Validate Subagent Output
193
+
194
+ ```
195
+ # 1. Extract JSON from output file
196
+ result = jsonExtract(file_path="./outputs/batch001.md")
197
+ if not result.success:
198
+ log_error("Failed to extract JSON")
199
+ return
200
+
201
+ # 2. Validate against expected schema
202
+ validation = jsonValidate(
203
+ data=json.dumps(result.data),
204
+ schema=batch_output_schema
205
+ )
206
+
207
+ if not validation.valid:
208
+ log_error(f"Validation failed: {validation.errors}")
209
+ return
210
+
211
+ # 3. Process validated data
212
+ process(result.data)
213
+ ```
214
+
215
+ ### Infer Schema from Example
216
+
217
+ ```
218
+ # 1. Get first valid output
219
+ result = jsonExtract(file_path="./outputs/batch001.md")
220
+
221
+ # 2. Infer schema from example
222
+ schema_result = jsonInfer(
223
+ data=json.dumps(result.data),
224
+ strict=true
225
+ )
226
+
227
+ # 3. Use inferred schema for validation
228
+ inferred_schema = json.dumps(schema_result.data)
229
+
230
+ # 4. Validate other outputs
231
+ for file in other_files:
232
+ data = jsonExtract(file_path=file)
233
+ validation = jsonValidate(
234
+ data=json.dumps(data.data),
235
+ schema=inferred_schema
236
+ )
237
+ ```
238
+
239
+ ### Combine Multiple JSON Files
240
+
241
+ ```
242
+ # 1. Extract all JSON objects
243
+ all_data = []
244
+ for file in output_files:
245
+ result = jsonExtract(file_path=file, return_all=true)
246
+ if result.success:
247
+ all_data.extend(result.data)
248
+
249
+ # 2. Create combined output
250
+ tableCreateFile(
251
+ file_path="./combined.xlsx",
252
+ sheet_name="Results",
253
+ data=all_data
254
+ )
255
+ ```
256
+
257
+ ## Best Practices
258
+
259
+ 1. **Always check success**: Check `result.success` before using `result.data`
260
+ 2. **Handle errors gracefully**: Log errors and continue with other files
261
+ 3. **Use strict mode for inference**: When you know all fields are required
262
+ 4. **Validate early**: Validate before processing to catch errors early
263
+ 5. **Keep schemas simple**: Avoid unsupported schema features