opencode-irf 0.0.11 → 0.0.12-next.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.
Files changed (49) hide show
  1. package/README.md +128 -33
  2. package/dist/{irf.d.ts → sat.d.ts} +1 -1
  3. package/dist/sat.d.ts.map +1 -0
  4. package/dist/sat.js +62 -0
  5. package/dist/sat.js.map +1 -0
  6. package/dist/src/append.js +4 -4
  7. package/dist/src/append.js.map +1 -1
  8. package/dist/src/discover.d.ts.map +1 -1
  9. package/dist/src/discover.js +18 -11
  10. package/dist/src/discover.js.map +1 -1
  11. package/dist/src/format-prompt.d.ts +3 -0
  12. package/dist/src/format-prompt.d.ts.map +1 -0
  13. package/dist/src/format-prompt.js +90 -0
  14. package/dist/src/format-prompt.js.map +1 -0
  15. package/dist/src/process-prompt.d.ts +21 -0
  16. package/dist/src/process-prompt.d.ts.map +1 -0
  17. package/dist/src/process-prompt.js +20 -0
  18. package/dist/src/process-prompt.js.map +1 -0
  19. package/dist/src/process.js +15 -15
  20. package/dist/src/process.js.map +1 -1
  21. package/dist/src/prompt-prompt.d.ts +3 -0
  22. package/dist/src/prompt-prompt.d.ts.map +1 -0
  23. package/dist/src/prompt-prompt.js +47 -0
  24. package/dist/src/prompt-prompt.js.map +1 -0
  25. package/dist/src/prompt-schema.d.ts +22 -0
  26. package/dist/src/prompt-schema.d.ts.map +1 -0
  27. package/dist/src/prompt-schema.js +33 -0
  28. package/dist/src/prompt-schema.js.map +1 -0
  29. package/dist/src/prompt.js +1 -1
  30. package/dist/src/prompt.js.map +1 -1
  31. package/dist/src/{schema.d.ts → rule-schema.d.ts} +1 -1
  32. package/dist/src/rule-schema.d.ts.map +1 -0
  33. package/dist/src/{schema.js → rule-schema.js} +1 -2
  34. package/dist/src/rule-schema.js.map +1 -0
  35. package/dist/src/tools.d.ts +59 -0
  36. package/dist/src/tools.d.ts.map +1 -0
  37. package/dist/src/tools.js +221 -0
  38. package/dist/src/tools.js.map +1 -0
  39. package/dist/src/utils/safe.d.ts +4 -2
  40. package/dist/src/utils/safe.d.ts.map +1 -1
  41. package/dist/src/utils/safe.js.map +1 -1
  42. package/dist/src/utils/validate.js +3 -3
  43. package/dist/src/utils/validate.js.map +1 -1
  44. package/package.json +5 -5
  45. package/dist/irf.d.ts.map +0 -1
  46. package/dist/irf.js +0 -183
  47. package/dist/irf.js.map +0 -1
  48. package/dist/src/schema.d.ts.map +0 -1
  49. package/dist/src/schema.js.map +0 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Instruction Rule Formatter (IRF)
1
+ # OpenCode SAT - Speech Act Theory
2
2
 
3
- An OpenCode plugin that converts unstructured instruction text into structured, consistent rules using speech act theory and deontic logic.
3
+ An OpenCode plugin that converts unstructured text into structured, consistent formats using speech act theory.
4
4
 
5
5
  <img width="612" height="256" alt="image" src="https://github.com/user-attachments/assets/51edf4b5-831a-4e13-96de-8cad453ea13e" />
6
6
 
@@ -9,14 +9,85 @@ An OpenCode plugin that converts unstructured instruction text into structured,
9
9
  Once installed, just tell OpenCode what you want:
10
10
 
11
11
  ```
12
- Use IRF to rewrite my instruction files
13
- Rewrite instructions.md with IRF in verbose mode
14
- Use IRF to add a rule about using early returns
12
+ Rewrite my instruction files
13
+ Rewrite instructions.md in verbose mode
14
+ Add a rule about using early returns
15
15
  ```
16
16
 
17
+ Messy or voice-transcribed input is automatically refined into structured tasks before the agent acts on it.
18
+
19
+ ## Two Formatters
20
+
21
+ The plugin is built on [speech act theory](https://en.wikipedia.org/wiki/Speech_act) (Austin, Searle). All instructions are **directives**: speech acts that get the hearer to do something. But directives come in two forms, and each needs a different formal framework.
22
+
23
+ ### Rule Formatting (deontic logic, regulative directives)
24
+
25
+ Rules constrain ongoing behavior. They are standing obligations, prohibitions, and permissions that persist across all future actions. The formal framework is [deontic logic](https://en.wikipedia.org/wiki/Deontic_logic): what is obligatory, forbidden, and permissible.
26
+
27
+ The plugin parses unstructured rule text into structured components:
28
+
29
+ ```ts
30
+ type ParsedRule = {
31
+ strength: 'obligatory' | 'forbidden' | 'permissible' | 'optional' | 'supererogatory' | 'indifferent' | 'omissible'
32
+ action: string
33
+ target: string
34
+ context?: string
35
+ reason: string
36
+ }
37
+ ```
38
+
39
+ Then formats them into one of three output modes: verbose, balanced, or concise.
40
+
41
+ **Status: implemented.** See [Usage](#usage) below.
42
+
43
+ ### Prompt Formatting (action/planning logic, performative directives)
44
+
45
+ Prompts request a specific one-shot action. They are not standing rules but immediate instructions. The formal framework is closer to [action languages](https://en.wikipedia.org/wiki/Action_language) from AI planning (STRIPS, ADL, HTN): what the goal is, what must be true before acting, and what changes after.
46
+
47
+ A messy user prompt typically mixes three levels together:
48
+
49
+ - **Goal** (desired end state): "I want search results to show up in chat"
50
+ - **Tasks** (what to do): "add a postResult call, update the providers"
51
+ - **Constraints** (conditions/preferences): "don't break existing tests, use safeAsync"
52
+
53
+ Prompt formatting would parse raw input into structured components like:
54
+
55
+ ```ts
56
+ type ParsedTask = {
57
+ intent: string
58
+ targets: Array<string>
59
+ constraints: Array<string>
60
+ context?: string
61
+ subtasks: Array<ParsedTask>
62
+ }
63
+
64
+ type ParsedPrompt = {
65
+ tasks: Array<ParsedTask>
66
+ }
67
+ ```
68
+
69
+ The schema is recursive. A `ParsedTask` can contain subtasks, which can contain their own subtasks. This follows the HTN (Hierarchical Task Network) model where compound tasks decompose into subtask trees. A voice dump like "refactor the search module, add guards to each provider, make sure bsky and wiki get validated, then run the tests and fix anything that breaks" becomes:
70
+
71
+ ```
72
+ tasks:
73
+ - intent: refactor the search module
74
+ subtasks:
75
+ - intent: add guards to each provider
76
+ subtasks:
77
+ - intent: validate bsky responses
78
+ - intent: validate wiki responses
79
+ - intent: run the tests
80
+ subtasks:
81
+ - intent: fix any failures
82
+ ```
83
+
84
+ This is especially useful for voice input, where thoughts are unstructured, sentences run together, and a single utterance often contains an entire task tree.
85
+
86
+ **Status: implemented.** See [refine-prompt](#refine-prompt) below.
87
+
17
88
  ## Overview
18
89
 
19
- IRF takes raw instruction files and processes them through a two-step AI pipeline:
90
+ The plugin takes raw instruction files and processes them through a two-step AI pipeline:
20
91
 
21
92
  1. **Parse** - Converts raw text into structured rule components (strength, action, target, context, reason)
22
93
  2. **Format** - Converts structured rules into one of three output modes: verbose, balanced, or concise
@@ -63,11 +134,11 @@ Reason: Arrow functions provide lexical this binding and a more compact syntax.
63
134
 
64
135
  ## Installation
65
136
 
66
- Add IRF to your `opencode.json`:
137
+ Add `opencode-sat` to your `opencode.json`:
67
138
 
68
139
  ```json
69
140
  {
70
- "plugin": ["opencode-irf"]
141
+ "plugin": ["opencode-sat"]
71
142
  }
72
143
  ```
73
144
 
@@ -75,7 +146,7 @@ Restart OpenCode. The plugin will be installed automatically.
75
146
 
76
147
  ## Usage
77
148
 
78
- The `irf-rewrite` tool reads the `instructions` array from your project's `opencode.json` and processes each matched file:
149
+ The `rewrite-instructions` tool reads the `instructions` array from your project's `opencode.json` and processes each matched file:
79
150
 
80
151
  ```json
81
152
  {
@@ -83,15 +154,15 @@ The `irf-rewrite` tool reads the `instructions` array from your project's `openc
83
154
  }
84
155
  ```
85
156
 
86
- ### irf-rewrite
157
+ ### rewrite-instructions
87
158
 
88
159
  Rewrites all matched instruction files through the parse/format pipeline.
89
160
 
90
161
  ```
91
- irf-rewrite # discover from opencode.json, balanced mode
92
- irf-rewrite --mode concise # discover, concise output
93
- irf-rewrite --files fixtures/testing.md # single file, balanced mode
94
- irf-rewrite --files a.md,b.md --mode verbose # multiple files, verbose output
162
+ rewrite-instructions # discover from opencode.json, balanced mode
163
+ rewrite-instructions --mode concise # discover, concise output
164
+ rewrite-instructions --files fixtures/testing.md # single file, balanced mode
165
+ rewrite-instructions --files a.md,b.md --mode verbose # multiple files, verbose output
95
166
  ```
96
167
 
97
168
  | Parameter | Type | Required | Description |
@@ -99,14 +170,14 @@ irf-rewrite --files a.md,b.md --mode verbose # multiple files, verbose output
99
170
  | `mode` | string | No | Output format: verbose, balanced, or concise (default: balanced) |
100
171
  | `files` | string | No | Comma-separated file paths to process instead of discovering from opencode.json |
101
172
 
102
- ### irf-add
173
+ ### add-instruction
103
174
 
104
175
  Appends new rules to the end of an instruction file without rewriting existing content.
105
176
 
106
177
  ```
107
- irf-add --input "Always use early returns" # append to first discovered file, balanced mode
108
- irf-add --input "Use early returns" --mode concise
109
- irf-add --input "Use early returns" --file docs/rules.md
178
+ add-instruction --input "Always use early returns" # append to first discovered file, balanced mode
179
+ add-instruction --input "Use early returns" --mode concise
180
+ add-instruction --input "Use early returns" --file docs/rules.md
110
181
  ```
111
182
 
112
183
  | Parameter | Type | Required | Description |
@@ -115,13 +186,49 @@ irf-add --input "Use early returns" --file docs/rules.md
115
186
  | `file` | string | No | Target file path (default: first discovered instruction file) |
116
187
  | `mode` | string | No | Output format: verbose, balanced, or concise (default: balanced) |
117
188
 
189
+ ### automatic-rule
190
+
191
+ Automatically detects when the user corrects the agent's behavior or expresses a coding preference, extracts the implicit rule, and appends it to the instruction file. This tool is invoked automatically by the LLM, not by the user.
192
+
193
+ | Parameter | Type | Required | Description |
194
+ | --- | --- | --- | --- |
195
+ | `input` | string | Yes | The user's correction or feedback to extract a rule from |
196
+ | `file` | string | No | Target file path (default: first discovered instruction file) |
197
+
198
+ ### refine-prompt
199
+
200
+ Restructures messy or unstructured user input into a clear, actionable task hierarchy. Takes raw text (often from voice transcription) and decomposes it into structured tasks with intent, targets, constraints, context, and recursive subtasks. Returns a formatted prompt the agent can act on.
201
+
202
+ ```
203
+ refine-prompt --input "refactor the search module add guards to each provider make sure bsky and wiki get validated then run the tests and fix anything that breaks"
204
+ ```
205
+
206
+ Output:
207
+ ```
208
+ 1. Refactor the search module
209
+ Targets: src/search.ts
210
+ - Add guards to each provider
211
+ Targets: src/providers/
212
+ - Validate bsky responses
213
+ Targets: bsky-search.ts
214
+ - Validate wiki responses
215
+ Targets: wiki-search.ts
216
+
217
+ 2. Run the tests
218
+ Constraints: fix any failures
219
+ ```
220
+
221
+ | Parameter | Type | Required | Description |
222
+ | --- | --- | --- | --- |
223
+ | `input` | string | Yes | Raw unstructured user input to restructure |
224
+
118
225
  ## Theoretical Foundation
119
226
 
120
- IRF is grounded in [speech act theory](https://en.wikipedia.org/wiki/Speech_act) and [deontic logic](https://en.wikipedia.org/wiki/Deontic_logic).
227
+ The plugin is grounded in [speech act theory](https://en.wikipedia.org/wiki/Speech_act) and [deontic logic](https://en.wikipedia.org/wiki/Deontic_logic).
121
228
 
122
- Instructions contain performative utterances that create obligations, permissions, and prohibitions. IRF identifies the illocutionary force of each instruction by extracting action verbs, target objects, contextual conditions, and justifications.
229
+ Instructions contain performative utterances that create obligations, permissions, and prohibitions. The plugin identifies the illocutionary force of each instruction by extracting action verbs, target objects, contextual conditions, and justifications.
123
230
 
124
- Rules are categorized using deontic strength:
231
+ Deontic strengths:
125
232
 
126
233
  - **Obligatory** - Required actions that create strong obligations
127
234
  - **Forbidden** - Prohibited actions with clear boundaries
@@ -131,18 +238,6 @@ Rules are categorized using deontic strength:
131
238
  - **Indifferent** - Actions with no normative preference
132
239
  - **Omissible** - Actions that can be reasonably omitted
133
240
 
134
- ### Rule Schema
135
-
136
- ```ts
137
- type ParsedRule = {
138
- strength: 'obligatory' | 'forbidden' | 'permissible' | 'optional' | 'supererogatory' | 'indifferent' | 'omissible'
139
- action: string
140
- target: string
141
- context?: string
142
- reason: string
143
- }
144
- ```
145
-
146
241
  ### Parsed Example
147
242
 
148
243
  ```
@@ -1,4 +1,4 @@
1
1
  import type { Plugin } from '@opencode-ai/plugin';
2
2
  declare const plugin: Plugin;
3
3
  export default plugin;
4
- //# sourceMappingURL=irf.d.ts.map
4
+ //# sourceMappingURL=sat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sat.d.ts","sourceRoot":"","sources":["../sat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAGjD,QAAA,MAAM,MAAM,EAAE,MA8Db,CAAA;AAED,eAAe,MAAM,CAAA"}
package/dist/sat.js ADDED
@@ -0,0 +1,62 @@
1
+ import { createAppendTool, createRefineTool, createRewriteTool } from "./src/tools.js";
2
+ const plugin = async ({ directory, client }) => {
3
+ const deps = { directory, client };
4
+ return {
5
+ tool: {
6
+ 'rewrite-instructions': createRewriteTool({
7
+ deps,
8
+ description: [
9
+ '- Discover instruction files from opencode.json configuration.',
10
+ '- Parse discovered instruction files into structured rules.',
11
+ '- Format structured rules into human-readable rules.',
12
+ '- Write formatted rules back to the original instruction files.',
13
+ '- Optionally accept a mode parameter (verbose, balanced, or concise) to control formatting.',
14
+ '- Default to balanced mode when no mode is specified.',
15
+ '- Optionally accept a files parameter to process specific files instead of running discovery.',
16
+ ].join('\n'),
17
+ }),
18
+ 'add-instruction': createAppendTool({
19
+ deps,
20
+ toolName: 'add-instruction',
21
+ sessionTitle: 'SAT Add',
22
+ defaultMode: 'balanced',
23
+ hasMode: true,
24
+ successPrefix: 'Added',
25
+ description: [
26
+ '- Parse unstructured input into structured rules.',
27
+ '- Format parsed rules after parsing unstructured input into structured rules.',
28
+ '- Append formatted rules to the instruction file without rewriting existing content.',
29
+ '- Optionally accept a mode parameter (verbose, balanced, or concise).',
30
+ '- Default mode to balanced when no mode parameter is specified.',
31
+ '- Optionally accept a file parameter to specify the target instruction file.',
32
+ '- Append to the first discovered instruction file when no file parameter is specified.',
33
+ ].join('\n'),
34
+ }),
35
+ 'automatic-rule': createAppendTool({
36
+ deps,
37
+ toolName: 'automatic-rule',
38
+ sessionTitle: 'SAT Candidate',
39
+ defaultMode: 'balanced',
40
+ hasMode: false,
41
+ successPrefix: 'Learned',
42
+ description: [
43
+ '- Detect user corrections when the user says something was done wrong, expresses a preference about how code should be written, or gives feedback that implies a repeatable guideline.',
44
+ '- Extract the implicit rule from the correction after detecting a user correction or preference.',
45
+ '- Persist the extracted rule as a new instruction rule.',
46
+ '- Append the new rule to the instruction file.',
47
+ ].join('\n'),
48
+ }),
49
+ 'refine-prompt': createRefineTool({
50
+ deps,
51
+ description: [
52
+ '- Restructure messy, ambiguous, or voice-transcribed user input before starting work when the message is vague, run-on, contains multiple interleaved requests, or reads like unpunctuated speech.',
53
+ '- Invoke this tool BEFORE starting work on vague, run-on, multi-request, or speech-like user messages.',
54
+ '- Decompose the input into a hierarchical task breakdown when restructuring user input.',
55
+ '- Return formatted markdown after decomposing the input.',
56
+ ].join('\n'),
57
+ }),
58
+ },
59
+ };
60
+ };
61
+ export default plugin;
62
+ //# sourceMappingURL=sat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sat.js","sourceRoot":"","sources":["../sat.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAEtF,MAAM,MAAM,GAAW,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE;IACrD,MAAM,IAAI,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,CAAA;IAElC,OAAO;QACL,IAAI,EAAE;YACJ,sBAAsB,EAAE,iBAAiB,CAAC;gBACxC,IAAI;gBACJ,WAAW,EAAE;oBACX,gEAAgE;oBAChE,6DAA6D;oBAC7D,sDAAsD;oBACtD,iEAAiE;oBACjE,6FAA6F;oBAC7F,uDAAuD;oBACvD,+FAA+F;iBAChG,CAAC,IAAI,CAAC,IAAI,CAAC;aACb,CAAC;YAEF,iBAAiB,EAAE,gBAAgB,CAAC;gBAClC,IAAI;gBACJ,QAAQ,EAAE,iBAAiB;gBAC3B,YAAY,EAAE,SAAS;gBACvB,WAAW,EAAE,UAAU;gBACvB,OAAO,EAAE,IAAI;gBACb,aAAa,EAAE,OAAO;gBACtB,WAAW,EAAE;oBACX,mDAAmD;oBACnD,+EAA+E;oBAC/E,sFAAsF;oBACtF,uEAAuE;oBACvE,iEAAiE;oBACjE,8EAA8E;oBAC9E,wFAAwF;iBACzF,CAAC,IAAI,CAAC,IAAI,CAAC;aACb,CAAC;YAEF,gBAAgB,EAAE,gBAAgB,CAAC;gBACjC,IAAI;gBACJ,QAAQ,EAAE,gBAAgB;gBAC1B,YAAY,EAAE,eAAe;gBAC7B,WAAW,EAAE,UAAU;gBACvB,OAAO,EAAE,KAAK;gBACd,aAAa,EAAE,SAAS;gBACxB,WAAW,EAAE;oBACX,wLAAwL;oBACxL,kGAAkG;oBAClG,yDAAyD;oBACzD,gDAAgD;iBACjD,CAAC,IAAI,CAAC,IAAI,CAAC;aACb,CAAC;YAEF,eAAe,EAAE,gBAAgB,CAAC;gBAChC,IAAI;gBACJ,WAAW,EAAE;oBACX,oMAAoM;oBACpM,wGAAwG;oBACxG,yFAAyF;oBACzF,0DAA0D;iBAC3D,CAAC,IAAI,CAAC,IAAI,CAAC;aACb,CAAC;SACH;KACF,CAAA;AACH,CAAC,CAAA;AAED,eAAe,MAAM,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import { readFile, writeFile } from 'node:fs/promises';
2
2
  import { resolve } from 'node:path';
3
3
  import { buildFormatPrompt, buildParsePrompt } from './prompt';
4
- import { FormatResponseSchema, ParseResponseSchema } from './schema';
4
+ import { FormatResponseSchema, ParseResponseSchema } from './rule-schema';
5
5
  import { safeAsync } from './utils/safe';
6
6
  // parse unstructured input, format it, and append to end of file
7
7
  export const appendRules = async (options) => {
@@ -40,12 +40,12 @@ export const appendRules = async (options) => {
40
40
  const newRules = formatResult.data.rules.join(joiner);
41
41
  const separator = existing.data.endsWith('\n') ? '\n' : '\n\n';
42
42
  const content = existing.data + separator + newRules + '\n';
43
- const { error: writeError } = await safeAsync(() => writeFile(fullPath, content, 'utf-8'));
44
- if (writeError) {
43
+ const writeResult = await safeAsync(() => writeFile(fullPath, content, 'utf-8'));
44
+ if (writeResult.error) {
45
45
  return {
46
46
  status: 'writeError',
47
47
  path: options.filePath,
48
- error: writeError.message,
48
+ error: writeResult.error.message,
49
49
  };
50
50
  }
51
51
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"append.js","sourceRoot":"","s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,CAAA;IACH,CAAC;IAED,OAAO;QACL,MAAM,EAAE,SAAS;QACjB,IAAI,EAAE,OAAO,CAAC,QAAQ;QACtB,UAAU,EAAE,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM;KAC3C,CAAA;AACH,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"discover.d.ts","sourceRoot":"","sources":["../../src/discover.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,MAAM,EAAmB,MAAM,cAAc,CAAA;AAE3D,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,KAAK,cAAc,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC,CAAA;AA6E/C,eAAO,MAAM,aAAa,GAAU,WAAW,MAAM,EAAE,OAAO,MAAM,EAAE,KAAG,OAAO,CAAC,eAAe,EAAE,CAGjG,CAAA;AAED,eAAO,MAAM,QAAQ,GAAU,WAAW,MAAM,KAAG,OAAO,CAAC,cAAc,CAsBxE,CAAA"}
1
+ {"version":3,"file":"discover.d.ts","sourceRoot":"","sources":["../../src/discover.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,MAAM,EAAmB,MAAM,cAAc,CAAA;AAE3D,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,KAAK,cAAc,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC,CAAA;AAoF/C,eAAO,MAAM,aAAa,GAAU,WAAW,MAAM,EAAE,OAAO,MAAM,EAAE,KAAG,OAAO,CAAC,eAAe,EAAE,CAGjG,CAAA;AAED,eAAO,MAAM,QAAQ,GAAU,WAAW,MAAM,KAAG,OAAO,CAAC,cAAc,CAsBxE,CAAA"}
@@ -3,21 +3,21 @@ import { join, resolve } from 'node:path';
3
3
  import { safe, safeAsync } from './utils/safe';
4
4
  const readConfig = async (directory) => {
5
5
  const configPath = join(directory, 'opencode.json');
6
- const { data, error } = await safeAsync(() => readFile(configPath, 'utf-8'));
7
- if (error) {
6
+ const readResult = await safeAsync(() => readFile(configPath, 'utf-8'));
7
+ if (readResult.error) {
8
8
  return {
9
9
  data: null,
10
- error: 'Could not read ' + configPath + ': ' + error.message,
10
+ error: 'Could not read ' + configPath + ': ' + readResult.error.message,
11
11
  };
12
12
  }
13
- const { data: parsed, error: parseError } = safe(() => JSON.parse(data));
14
- if (parseError) {
13
+ const parseResult = safe(() => JSON.parse(readResult.data));
14
+ if (parseResult.error) {
15
15
  return {
16
16
  data: null,
17
- error: 'Invalid JSON in ' + configPath + ': ' + parseError.message,
17
+ error: 'Invalid JSON in ' + configPath + ': ' + parseResult.error.message,
18
18
  };
19
19
  }
20
- const instructions = parsed.instructions;
20
+ const instructions = parseResult.data.instructions;
21
21
  if (!instructions || !Array.isArray(instructions) || instructions.length === 0) {
22
22
  return {
23
23
  data: null,
@@ -53,12 +53,19 @@ const resolveFiles = async (directory, patterns) => {
53
53
  const readFiles = async (files) => {
54
54
  const results = [];
55
55
  for (const file of files) {
56
- const { data, error } = await safeAsync(() => readFile(file, 'utf-8'));
57
- if (error) {
58
- results.push({ path: file, content: '', error: error.message });
56
+ const readResult = await safeAsync(() => readFile(file, 'utf-8'));
57
+ if (readResult.error) {
58
+ results.push({
59
+ path: file,
60
+ content: '',
61
+ error: readResult.error.message,
62
+ });
59
63
  continue;
60
64
  }
61
- results.push({ path: file, content: data });
65
+ results.push({
66
+ path: file,
67
+ content: readResult.data,
68
+ });
62
69
  }
63
70
  return results;
64
71
  };
@@ -1 +1 @@
1
- {"version":3,"file":"discover.js","sourceRoot":"","sources":["../../src/discover.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACjD,O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OAAO;QACL,IAAI,EAAE,MAAM,SAAS,CAAC,KAAK,CAAC;QAC5B,KAAK,EAAE,IAAI;KACZ,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { ParsedPrompt } from './prompt-schema.ts';
2
+ export declare const formatPrompt: (parsed: ParsedPrompt) => string;
3
+ //# sourceMappingURL=format-prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-prompt.d.ts","sourceRoot":"","sources":["../../src/format-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,oBAAoB,CAAA;AA0GlE,eAAO,MAAM,YAAY,GAAI,QAAQ,YAAY,KAAG,MA8BnD,CAAA"}
@@ -0,0 +1,90 @@
1
+ const buildNode = (options) => {
2
+ const { task, counter } = options;
3
+ const label = String(counter.value) + '. ' + task.intent;
4
+ counter.value++;
5
+ const metaLines = [];
6
+ if (task.targets.length > 0) {
7
+ metaLines.push('> Targets: ' + task.targets.join(', '));
8
+ }
9
+ if (task.constraints.length > 0) {
10
+ metaLines.push('> Constraints: ' + task.constraints.join(', '));
11
+ }
12
+ if (task.context) {
13
+ metaLines.push('> Context: ' + task.context);
14
+ }
15
+ const children = task.subtasks.map((subtask) => {
16
+ return buildNode({ task: subtask, counter });
17
+ });
18
+ return { label, metaLines, children };
19
+ };
20
+ const flatten = (nodes) => {
21
+ const result = [];
22
+ for (const node of nodes) {
23
+ result.push({ label: node.label, metaLines: node.metaLines, children: [] });
24
+ for (const child of node.children) {
25
+ result.push(child);
26
+ }
27
+ }
28
+ return result;
29
+ };
30
+ const renderNode = (options) => {
31
+ const { node, prefix, childPrefix } = options;
32
+ const hasChildren = node.children.length > 0;
33
+ const firstLine = prefix + node.label;
34
+ const lines = [firstLine];
35
+ const numEnd = node.label.indexOf('. ') + 2;
36
+ const textStart = prefix.length + numEnd;
37
+ const pipe = hasChildren ? '│' : ' ';
38
+ const padLen = textStart - childPrefix.length - 1;
39
+ const metaPad = childPrefix + pipe + ' '.repeat(padLen > 0 ? padLen : 0);
40
+ for (const meta of node.metaLines) {
41
+ lines.push(metaPad + meta);
42
+ }
43
+ if (hasChildren) {
44
+ lines.push(childPrefix + '│');
45
+ for (let i = 0; i < node.children.length; i++) {
46
+ const child = node.children[i];
47
+ if (!child)
48
+ continue;
49
+ if (i > 0) {
50
+ lines.push(childPrefix + '│');
51
+ }
52
+ const isLast = i === node.children.length - 1;
53
+ const childHasChildren = child.children.length > 0;
54
+ const connector = (isLast ? '└──' : '├──') + (childHasChildren ? '┬ ' : ' ');
55
+ const continuation = (isLast ? ' ' : '│ ');
56
+ const childLines = renderNode({
57
+ node: child,
58
+ prefix: childPrefix + connector,
59
+ childPrefix: childPrefix + continuation,
60
+ });
61
+ lines.push(...childLines);
62
+ }
63
+ }
64
+ return lines;
65
+ };
66
+ export const formatPrompt = (parsed) => {
67
+ if (parsed.tasks.length === 0) {
68
+ return '';
69
+ }
70
+ const counter = { value: 1 };
71
+ const nodes = parsed.tasks.map((task) => buildNode({ task, counter }));
72
+ const totalNodes = counter.value - 1;
73
+ if (totalNodes === 1 && nodes[0]) {
74
+ const node = nodes[0];
75
+ const lines = [node.label];
76
+ for (const meta of node.metaLines) {
77
+ lines.push(' ' + meta);
78
+ }
79
+ return lines.join('\n');
80
+ }
81
+ const flat = flatten(nodes);
82
+ const root = {
83
+ label: flat[0]?.label ?? '',
84
+ metaLines: flat[0]?.metaLines ?? [],
85
+ children: flat.slice(1),
86
+ };
87
+ const rootPrefix = root.children.length > 0 ? '┬ ' : '';
88
+ return renderNode({ node: root, prefix: rootPrefix, childPrefix: '' }).join('\n');
89
+ };
90
+ //# sourceMappingURL=format-prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-prompt.js","sourceRoot":"","sources":["../../src/format-prompt.ts"],"names":[],"mappings":"AAeA,MAAM,SAAS,GAAG,CAAC,OAAyB,EAAY,EAAE;IACxD,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE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type PromptFn = <T>(prompt: string, schema: z.ZodType<T>) => Promise<Result<T>>;
5
+ type ProcessPromptOptions = {
6
+ input: string;
7
+ prompt: PromptFn;
8
+ };
9
+ type PromptSuccess = {
10
+ status: 'success';
11
+ formatted: string;
12
+ parsed: ParsedPrompt;
13
+ };
14
+ type PromptParseError = {
15
+ status: 'parseError';
16
+ error: string;
17
+ };
18
+ type PromptResult = PromptSuccess | PromptParseError;
19
+ export declare const processPrompt: (options: ProcessPromptOptions) => Promise<PromptResult>;
20
+ export {};
21
+ //# sourceMappingURL=process-prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-prompt.d.ts","sourceRoot":"","sources":["../../src/process-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAC5B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAKnD,KAAK,QAAQ,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AAE/E,KAAK,oBAAoB,GAAG;IAC1B,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,QAAQ,CAAA;CACjB,CAAA;AAED,KAAK,aAAa,GAAG;IACnB,MAAM,EAAE,SAAS,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,YAAY,CAAA;CACrB,CAAA;AAED,KAAK,gBAAgB,GAAG;IACtB,MAAM,EAAE,YAAY,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,KAAK,YAAY,GAAG,aAAa,GAAG,gBAAgB,CAAA;AAEpD,eAAO,MAAM,aAAa,GAAU,SAAS,oBAAoB,KAAG,OAAO,CAAC,YAAY,CAiBvF,CAAA"}
@@ -0,0 +1,20 @@
1
+ import { ParsedPromptSchema } from './prompt-schema';
2
+ import { buildPromptParsePrompt } from './prompt-prompt';
3
+ import { formatPrompt } from './format-prompt';
4
+ export const processPrompt = async (options) => {
5
+ const parsePrompt = buildPromptParsePrompt(options.input);
6
+ const parseResult = await options.prompt(parsePrompt, ParsedPromptSchema);
7
+ if (!parseResult.data) {
8
+ return {
9
+ status: 'parseError',
10
+ error: parseResult.error,
11
+ };
12
+ }
13
+ const formatted = formatPrompt(parseResult.data);
14
+ return {
15
+ status: 'success',
16
+ formatted,
17
+ parsed: parseResult.data,
18
+ };
19
+ };
20
+ //# sourceMappingURL=process-prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-prompt.js","sourceRoot":"","sources":["../../src/process-prompt.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAsB9C,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,OAA6B,EAAyB,EAAE;IAC1F,MAAM,WAAW,GAAG,sBAAsB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACzD,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAA;IACzE,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;QACtB,OAAO;YACL,MAAM,EAAE,YAAY;YACpB,KAAK,EAAE,WAAW,CAAC,KAAK;SACzB,CAAA;IACH,CAAC;IAED,MAAM,SAAS,GAAG,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;IAEhD,OAAO;QACL,MAAM,EAAE,SAAS;QACjB,SAAS;QACT,MAAM,EAAE,WAAW,CAAC,IAAI;KACzB,CAAA;AACH,CAAC,CAAA"}