opencode-leetcode-realworld 0.2.0 → 0.2.2
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/README.md +51 -17
- package/package.json +1 -1
- package/src/scaffold.ts +24 -0
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# opencode-leetcode-realworld
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/opencode-leetcode-realworld)
|
|
4
|
+
|
|
3
5
|
An [opencode](https://opencode.ai) plugin that turns a LeetCode problem into a
|
|
4
6
|
**realistic software-engineering assignment**.
|
|
5
7
|
|
|
@@ -15,6 +17,49 @@ and a test suite. The original problem is never shown to you.
|
|
|
15
17
|
/practice medium dynamic-programming python
|
|
16
18
|
```
|
|
17
19
|
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
Add the plugin to your `opencode.json` and restart opencode:
|
|
23
|
+
|
|
24
|
+
```jsonc
|
|
25
|
+
{
|
|
26
|
+
"$schema": "https://opencode.ai/config.json",
|
|
27
|
+
"plugin": ["opencode-leetcode-realworld"]
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
That's all you have to do. **You do not run `npm install` yourself** — opencode
|
|
32
|
+
reads the `plugin` list on startup and installs the package automatically with
|
|
33
|
+
Bun (cached in `~/.cache/opencode/node_modules/`). Just naming it in the config is
|
|
34
|
+
enough; the plugin then registers the `/practice` command on its own.
|
|
35
|
+
|
|
36
|
+
Prefer not to edit the file by hand? Let opencode do it:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
opencode plugin opencode-leetcode-realworld
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Use the project `opencode.json` to enable it for one repo, or
|
|
43
|
+
`~/.config/opencode/opencode.json` to enable it everywhere.
|
|
44
|
+
|
|
45
|
+
Confirm it loaded:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
opencode debug config # look for a "practice" command
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Requirements
|
|
52
|
+
|
|
53
|
+
- [opencode](https://opencode.ai) 1.x
|
|
54
|
+
- Node.js 18+ — the test runner uses Node no matter which language you pick
|
|
55
|
+
- The toolchain for your chosen language (see [Supported languages](#supported-languages))
|
|
56
|
+
|
|
57
|
+
Then, in opencode:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
/practice
|
|
61
|
+
```
|
|
62
|
+
|
|
18
63
|
## Usage
|
|
19
64
|
|
|
20
65
|
```
|
|
@@ -104,6 +149,8 @@ they tend to produce:
|
|
|
104
149
|
|
|
105
150
|
```
|
|
106
151
|
/practice
|
|
152
|
+
│
|
|
153
|
+
├─ (agent) if language/difficulty are missing, ask you via the `question` tool
|
|
107
154
|
│
|
|
108
155
|
├─ leetcode_fetch fetch a problem from the LeetCode API (private reasoning input)
|
|
109
156
|
│
|
|
@@ -135,24 +182,11 @@ node tests/runner.mjs # all cases
|
|
|
135
182
|
node tests/runner.mjs --public # visible cases only
|
|
136
183
|
```
|
|
137
184
|
|
|
138
|
-
##
|
|
139
|
-
|
|
140
|
-
### Local (development)
|
|
141
|
-
|
|
142
|
-
Clone/copy this repo, then open opencode inside it. Files under
|
|
143
|
-
`.opencode/plugins/` and `.opencode/commands/` are auto-loaded.
|
|
144
|
-
|
|
145
|
-
### From npm (once published)
|
|
146
|
-
|
|
147
|
-
```jsonc
|
|
148
|
-
// opencode.json
|
|
149
|
-
{
|
|
150
|
-
"$schema": "https://opencode.ai/config.json",
|
|
151
|
-
"plugin": ["opencode-leetcode-realworld"]
|
|
152
|
-
}
|
|
153
|
-
```
|
|
185
|
+
## Running from source
|
|
154
186
|
|
|
155
|
-
|
|
187
|
+
For plugin development, clone the repo and open opencode inside it — files under
|
|
188
|
+
`.opencode/plugins/` are auto-loaded. See [Development](#development) for the test
|
|
189
|
+
and typecheck commands.
|
|
156
190
|
|
|
157
191
|
## Tools
|
|
158
192
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-leetcode-realworld",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "OpenCode plugin that turns a LeetCode problem into a realistic software-engineering assignment, so you practice applying the underlying algorithm instead of solving the puzzle.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/src/scaffold.ts
CHANGED
|
@@ -130,6 +130,29 @@ function edgeCaseSection(spec: ScaffoldSpec): string {
|
|
|
130
130
|
return `## Edge cases to handle\n\n${edgeCases.map((edge) => `- ${edge}`).join("\n")}\n`;
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
function exampleSection(spec: ScaffoldSpec): string {
|
|
134
|
+
const tests = spec.publicTests ?? [];
|
|
135
|
+
if (tests.length === 0) return "";
|
|
136
|
+
const blocks = tests.slice(0, 3).map((test, index) => {
|
|
137
|
+
const input = json(test.input);
|
|
138
|
+
const output = json(test.expected);
|
|
139
|
+
return `### Example ${index + 1}: ${test.name}
|
|
140
|
+
|
|
141
|
+
**Input**
|
|
142
|
+
|
|
143
|
+
\`\`\`json
|
|
144
|
+
${input}
|
|
145
|
+
\`\`\`
|
|
146
|
+
|
|
147
|
+
**Output**
|
|
148
|
+
|
|
149
|
+
\`\`\`json
|
|
150
|
+
${output}
|
|
151
|
+
\`\`\``;
|
|
152
|
+
});
|
|
153
|
+
return `## Example input / output\n\nUse these to derive the logic.\n\n${blocks.join("\n\n")}\n`;
|
|
154
|
+
}
|
|
155
|
+
|
|
133
156
|
function readmeFor(names: ResolvedNames, spec: ScaffoldSpec, language: LanguageId): string {
|
|
134
157
|
const adapter = getLanguage(language);
|
|
135
158
|
const source = `src/solution.${adapter.extension}`;
|
|
@@ -176,6 +199,7 @@ function projectDoc(spec: ScaffoldSpec, names: ResolvedNames, language: Language
|
|
|
176
199
|
|
|
177
200
|
${spec.scenario.trim()}
|
|
178
201
|
|
|
202
|
+
${exampleSection(spec)}
|
|
179
203
|
${requirementsSection(spec)}
|
|
180
204
|
${edgeCaseSection(spec)}
|
|
181
205
|
## Interface
|