@eduardo191labs/opencode-free-pi 0.7.1 → 0.7.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.
@@ -59,7 +59,7 @@ export declare const DEFAULT_THINKING_LEVELS: readonly ["none", "minimal", "low"
59
59
  * models show: skipping analysis, inventing verification, and ignoring the
60
60
  * context the conversation already established.
61
61
  */
62
- export declare const FREE_PI_GUIDANCE = "# free-pi working rules\n- Answer the user's latest request and keep their constraints; do not switch to a different task.\n- Slow down on multi-step work (arithmetic, counting, logic, dates, units, planning, debugging): write out each step, recompute the result a second way, and only then answer. On those tasks a correct answer after a dozen explicit steps beats a fast guess; do not stop at the first plausible number.\n- Read the files involved before editing and run the project's checks afterwards. Never say a test, build or command passed unless you ran it and saw it pass.\n- Treat the conversation above as memory: reuse earlier decisions, file paths, identifiers and results. If something is genuinely missing, say what is missing instead of guessing.\n- Use the available tools (read, grep, glob, bash, edit) for real work; do not describe hypothetical commands as if they ran.\n- Delegate large or self-contained work with OpenCode's native `subagent` tool: `free-pi/scout` and `free-pi/planner` for read-only recon and planning, `free-pi/worker` for a full task, `free-pi/reviewer` for review. A subagent runs in its own context and reports back; never launch a subagent from inside one. The `subagent` tool returns a child `sessionID` and OpenCode injects the child's report when it goes idle; to inspect what that child actually did, call `free_pi_subagent_read` with its `sessionID` (omit it to list this session's children).\n- Load a skill with the native `skill` tool when its description matches the task.\n- `AGENTS.md` and the files listed under `instructions` are the project's memory. Follow them; do not restate or replace them.\n- Never claim to have compacted, summarized or cleared context unless that actually happened.\n- Continue until the request is finished, then report concisely what changed and what you verified.";
62
+ export declare const FREE_PI_GUIDANCE = "# free-pi working rules\n- Answer the user's latest request and keep their constraints; do not switch to a different task.\n- Slow down on multi-step work (arithmetic, counting, logic, dates, units, planning, debugging): write out each step, recompute the result a second way, and only then answer. On those tasks a correct answer after a dozen explicit steps beats a fast guess; do not stop at the first plausible number.\n- Read the files involved before editing and run the project's checks afterwards. Never say a test, build or command passed unless you ran it and saw it pass.\n- Treat the conversation above as memory: reuse earlier decisions, file paths, identifiers and results. If something is genuinely missing, say what is missing instead of guessing.\n- Use the available tools (read, grep, glob, bash, edit) for real work; do not describe hypothetical commands as if they ran.\n- Delegate large or self-contained work with OpenCode's native `subagent` tool: `free-pi/scout` and `free-pi/planner` for read-only recon and planning, `free-pi/worker` for a full task, `free-pi/reviewer` for review. A subagent runs in its own context and reports back; never launch a subagent from inside one. The `subagent` tool returns a child `sessionID` and OpenCode injects the child's report when it goes idle; to inspect what that child actually did, call `free_pi_subagent_read` with its `sessionID` (omit it to list this session's children).\n- Load a skill with the native `skill` tool when its description matches the task.\n- `AGENTS.md` and the files listed under `instructions` are the project's memory. Follow them; do not restate or replace them.\n- Never claim to have compacted, summarized or cleared context unless that actually happened.\n- Never answer with a session summary or with `## Objective` / `## Work State` blocks; that format belongs to compaction. If the work is unfinished, take the next concrete action instead of describing the state.\n- Continue until the request is finished, then report concisely what changed and what you verified.";
63
63
  export declare const FREE_PI_GUIDANCE_MARKER = "# free-pi working rules";
64
64
  /**
65
65
  * Appended to OpenCode's compaction request. Its default summary prompt asks
package/dist/constants.js CHANGED
@@ -83,6 +83,7 @@ export const FREE_PI_GUIDANCE = `# free-pi working rules
83
83
  - Load a skill with the native \`skill\` tool when its description matches the task.
84
84
  - \`AGENTS.md\` and the files listed under \`instructions\` are the project's memory. Follow them; do not restate or replace them.
85
85
  - Never claim to have compacted, summarized or cleared context unless that actually happened.
86
+ - Never answer with a session summary or with \`## Objective\` / \`## Work State\` blocks; that format belongs to compaction. If the work is unfinished, take the next concrete action instead of describing the state.
86
87
  - Continue until the request is finished, then report concisely what changed and what you verified.`;
87
88
  export const FREE_PI_GUIDANCE_MARKER = "# free-pi working rules";
88
89
  /**
@@ -58,7 +58,7 @@ function fitCompactionMessages(deps, event, reserveTokens = 0) {
58
58
  promptTokens: trimmed.tokens,
59
59
  });
60
60
  }
61
- /** Adds a system block once, even when OpenCode reuses the same event. */
61
+ /** Adds a system block once, without mutating the array OpenCode may reuse. */
62
62
  function appendSystemGuidance(event, text, marker) {
63
63
  const system = Array.isArray(event.system) ? event.system : [];
64
64
  if (system.some((part) => part?.type === "text" &&
@@ -66,8 +66,25 @@ function appendSystemGuidance(event, text, marker) {
66
66
  part.text.startsWith(marker))) {
67
67
  return;
68
68
  }
69
- system.push({ type: "text", text });
70
- event.system = system;
69
+ // A fresh array: OpenCode reuses the event across hooks, and pushing into the
70
+ // shared array would carry this block into the next, unrelated request.
71
+ event.system = [...system, { type: "text", text }];
72
+ }
73
+ /**
74
+ * Removes guidance blocks that belong to another kind of request. OpenCode can
75
+ * hand the same event to several hooks, so the compaction rules have to be
76
+ * stripped before a primary turn: otherwise the model reads them as an order to
77
+ * answer with a summary and burns the turn writing "## Objective / ## Work
78
+ * State" instead of doing the work.
79
+ */
80
+ function stripSystemGuidance(event, markers) {
81
+ if (!Array.isArray(event.system))
82
+ return;
83
+ const kept = event.system.filter((part) => !(part?.type === "text" &&
84
+ typeof part.text === "string" &&
85
+ markers.some((marker) => part.text.startsWith(marker))));
86
+ if (kept.length !== event.system.length)
87
+ event.system = kept;
71
88
  }
72
89
  /**
73
90
  * Reads the newest turns of the session from the native API. That history is
@@ -211,11 +228,13 @@ async function applyGeneration(deps, event, kind) {
211
228
  else if (kind === "primary") {
212
229
  // The free models tend to skip planning and claim work they did not do;
213
230
  // the CLI gets a much larger agent prompt. This is the compact equivalent.
231
+ stripSystemGuidance(event, [FREE_PI_COMPACTION_MARKER]);
214
232
  appendSystemGuidance(event, FREE_PI_GUIDANCE, FREE_PI_GUIDANCE_MARKER);
215
233
  applyContextDiet(deps, event);
216
234
  appendCarriedWindow(deps, event);
217
235
  }
218
236
  else {
237
+ stripSystemGuidance(event, [FREE_PI_COMPACTION_MARKER]);
219
238
  applyContextDiet(deps, event);
220
239
  }
221
240
  const agent = event.agent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eduardo191labs/opencode-free-pi",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "Ad-supported free-pi provider plugin for OpenCode on Windows, Linux, macOS and Termux",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/constants.ts CHANGED
@@ -90,6 +90,7 @@ export const FREE_PI_GUIDANCE = `# free-pi working rules
90
90
  - Load a skill with the native \`skill\` tool when its description matches the task.
91
91
  - \`AGENTS.md\` and the files listed under \`instructions\` are the project's memory. Follow them; do not restate or replace them.
92
92
  - Never claim to have compacted, summarized or cleared context unless that actually happened.
93
+ - Never answer with a session summary or with \`## Objective\` / \`## Work State\` blocks; that format belongs to compaction. If the work is unfinished, take the next concrete action instead of describing the state.
93
94
  - Continue until the request is finished, then report concisely what changed and what you verified.`;
94
95
  export const FREE_PI_GUIDANCE_MARKER = "# free-pi working rules";
95
96
 
@@ -148,7 +148,7 @@ function fitCompactionMessages(
148
148
  );
149
149
  }
150
150
 
151
- /** Adds a system block once, even when OpenCode reuses the same event. */
151
+ /** Adds a system block once, without mutating the array OpenCode may reuse. */
152
152
  function appendSystemGuidance(
153
153
  event: any,
154
154
  text: string,
@@ -165,8 +165,29 @@ function appendSystemGuidance(
165
165
  ) {
166
166
  return;
167
167
  }
168
- system.push({ type: "text", text });
169
- event.system = system;
168
+ // A fresh array: OpenCode reuses the event across hooks, and pushing into the
169
+ // shared array would carry this block into the next, unrelated request.
170
+ event.system = [...system, { type: "text", text }];
171
+ }
172
+
173
+ /**
174
+ * Removes guidance blocks that belong to another kind of request. OpenCode can
175
+ * hand the same event to several hooks, so the compaction rules have to be
176
+ * stripped before a primary turn: otherwise the model reads them as an order to
177
+ * answer with a summary and burns the turn writing "## Objective / ## Work
178
+ * State" instead of doing the work.
179
+ */
180
+ function stripSystemGuidance(event: any, markers: readonly string[]): void {
181
+ if (!Array.isArray(event.system)) return;
182
+ const kept = event.system.filter(
183
+ (part: any) =>
184
+ !(
185
+ part?.type === "text" &&
186
+ typeof part.text === "string" &&
187
+ markers.some((marker) => part.text.startsWith(marker))
188
+ ),
189
+ );
190
+ if (kept.length !== event.system.length) event.system = kept;
170
191
  }
171
192
 
172
193
  /**
@@ -345,10 +366,12 @@ async function applyGeneration(
345
366
  } else if (kind === "primary") {
346
367
  // The free models tend to skip planning and claim work they did not do;
347
368
  // the CLI gets a much larger agent prompt. This is the compact equivalent.
369
+ stripSystemGuidance(event, [FREE_PI_COMPACTION_MARKER]);
348
370
  appendSystemGuidance(event, FREE_PI_GUIDANCE, FREE_PI_GUIDANCE_MARKER);
349
371
  applyContextDiet(deps, event);
350
372
  appendCarriedWindow(deps, event);
351
373
  } else {
374
+ stripSystemGuidance(event, [FREE_PI_COMPACTION_MARKER]);
352
375
  applyContextDiet(deps, event);
353
376
  }
354
377