opencode-worker 0.1.9 → 0.1.10
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 +1 -1
- package/lib/worker.mjs +10 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ Exit codes: `0` ok, `1` worker failed (timeout, nonzero exit, error event, model
|
|
|
69
69
|
| `opencode` | `{bin, version}` |
|
|
70
70
|
| `requested` | `{model, variant, agent, timeoutSec}` |
|
|
71
71
|
| `actual` | provider/model/variant recorded in the isolated session DB (needs `sqlite3`; `null` if unavailable) |
|
|
72
|
-
| `text` | worker's final text |
|
|
72
|
+
| `text` | worker's final answer: the text after its last tool call, without narration like "I'll read the file." (all text, joined by blank lines, if nothing follows the last tool call). Safe to paste into the next job's prompt; workers never see each other's results otherwise |
|
|
73
73
|
| `tools[]` | `{tool, status, input, exit, output, error}` per tool call; `exit` is the bash exit code (else `null`), `output` capped at 4000 chars |
|
|
74
74
|
| `cost`, `tokens` | summed from `step_finish` events |
|
|
75
75
|
| `diff` | unified diff of `<dir>` before vs after. Excludes `.opencode-worker/` and tool caches (`__pycache__`, `*.pyc`, `.pytest_cache`, `.mypy_cache`, `.ruff_cache`, `.cache`); the worker also runs with `PYTHONDONTWRITEBYTECODE=1`, so test runs don't show up as changes |
|
package/lib/worker.mjs
CHANGED
|
@@ -113,16 +113,24 @@ function unifiedDiff(before, dir) {
|
|
|
113
113
|
return { diff: body.replaceAll(dir + "/", "after/"), error: null };
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
/**
|
|
117
|
+
* `text` is the worker's final answer: text emitted after its last tool call.
|
|
118
|
+
* Narration before tool calls ("I'll read the file.") is dropped so the answer can be
|
|
119
|
+
* handed to the next job verbatim. If nothing follows the last tool call, all text is kept.
|
|
120
|
+
*/
|
|
116
121
|
function parseEvents(stdout) {
|
|
117
122
|
const out = { text: "", tools: [], cost: 0, tokens: { input: 0, output: 0, reasoning: 0, cacheRead: 0, cacheWrite: 0 }, errors: [], sessionID: null };
|
|
123
|
+
const allText = [];
|
|
124
|
+
let finalText = [];
|
|
118
125
|
for (const line of stdout.split("\n")) {
|
|
119
126
|
if (!line.trim()) continue;
|
|
120
127
|
let ev;
|
|
121
128
|
try { ev = JSON.parse(line); } catch { out.errors.push({ type: "unparsed_line", detail: line.slice(0, 300) }); continue; }
|
|
122
129
|
out.sessionID ??= ev.sessionID ?? null;
|
|
123
130
|
const p = ev.part ?? {};
|
|
124
|
-
if (ev.type === "text"
|
|
131
|
+
if (ev.type === "text" && p.text) { allText.push(p.text); finalText.push(p.text); }
|
|
125
132
|
else if (ev.type === "tool_use") {
|
|
133
|
+
finalText = [];
|
|
126
134
|
const s = p.state ?? {};
|
|
127
135
|
const output = typeof s.output === "string" ? s.output : s.output == null ? null : JSON.stringify(s.output);
|
|
128
136
|
out.tools.push({
|
|
@@ -144,6 +152,7 @@ function parseEvents(stdout) {
|
|
|
144
152
|
out.tokens.cacheWrite += t.cache?.write ?? 0;
|
|
145
153
|
} else if (ev.type === "error") out.errors.push({ type: "event_error", detail: ev.error ?? p });
|
|
146
154
|
}
|
|
155
|
+
out.text = (finalText.length ? finalText : allText).join("\n\n").trim();
|
|
147
156
|
return out;
|
|
148
157
|
}
|
|
149
158
|
|