@eduardo191labs/opencode-free-pi 0.7.4 → 0.7.5

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- 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.";
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`, `shell`, `edit`) for real work; do not describe hypothetical commands as if they ran. Prefer `read`, `grep` and `glob` over shell for inspecting files.\n- The `shell` tool runs a portable scanner, not a full bash. Heredocs (`<<EOF`), chained one-liners with nested or heavy-escaped quotes, and some shells' loops are rejected before they run. Put any complex script in a file with `write` and run that file; on Windows write PowerShell syntax.\n- Reply in the language of the user's latest message; keep code, paths and identifiers unchanged.\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
@@ -76,7 +76,7 @@ export declare const FREE_PI_COMPACTION_MARKER = "# free-pi compaction rules";
76
76
  * 100k-token system prompt are easy to ignore. It is not a user instruction and
77
77
  * never becomes part of the stored conversation.
78
78
  */
79
- export declare const TURN_REMINDER = "# free-pi turn check (not a user request)\nYou are in a normal working turn, not a compaction.\n- Never answer with `## Objective`, `## Requirements`, `## Work State` or a session summary; that format belongs only to a compaction. Earlier sections with those names are history, not an answer template.\n- If the user asked to search, find, analyze or verify something, call the matching tool first (grep/glob/shell for files, websearch/webfetch for the web) and report what it returned.\n- If the task is unfinished, call the next tool now instead of describing the state.";
79
+ export declare const TURN_REMINDER = "# free-pi turn check (not a user request)\nYou are in a normal working turn, not a compaction.\n- Never answer with `## Objective`, `## Requirements`, `## Work State` or a session summary; that format belongs only to a compaction. Earlier sections with those names are history, not an answer template.\n- If the user asked to search, find, analyze or verify something, call the matching tool first (grep/glob/shell for files, websearch/webfetch for the web) and report what it returned.\n- Keep each shell command simple: no heredocs and no nested-quote one-liners. Write a script file and run it when the command is complex.\n- If the task is unfinished, call the next tool now instead of describing the state.";
80
80
  export declare const TURN_REMINDER_MARKER = "# free-pi turn check";
81
81
  /**
82
82
  * OpenCode keeps only the latest exchange beside a summary, so after a
package/dist/constants.js CHANGED
@@ -78,7 +78,9 @@ export const FREE_PI_GUIDANCE = `# free-pi working rules
78
78
  - 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.
79
79
  - 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.
80
80
  - 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.
81
- - Use the available tools (read, grep, glob, bash, edit) for real work; do not describe hypothetical commands as if they ran.
81
+ - Use the available tools (\`read\`, \`grep\`, \`glob\`, \`shell\`, \`edit\`) for real work; do not describe hypothetical commands as if they ran. Prefer \`read\`, \`grep\` and \`glob\` over shell for inspecting files.
82
+ - The \`shell\` tool runs a portable scanner, not a full bash. Heredocs (\`<<EOF\`), chained one-liners with nested or heavy-escaped quotes, and some shells' loops are rejected before they run. Put any complex script in a file with \`write\` and run that file; on Windows write PowerShell syntax.
83
+ - Reply in the language of the user's latest message; keep code, paths and identifiers unchanged.
82
84
  - 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).
83
85
  - Load a skill with the native \`skill\` tool when its description matches the task.
84
86
  - \`AGENTS.md\` and the files listed under \`instructions\` are the project's memory. Follow them; do not restate or replace them.
@@ -110,6 +112,7 @@ export const TURN_REMINDER = `# free-pi turn check (not a user request)
110
112
  You are in a normal working turn, not a compaction.
111
113
  - Never answer with \`## Objective\`, \`## Requirements\`, \`## Work State\` or a session summary; that format belongs only to a compaction. Earlier sections with those names are history, not an answer template.
112
114
  - If the user asked to search, find, analyze or verify something, call the matching tool first (grep/glob/shell for files, websearch/webfetch for the web) and report what it returned.
115
+ - Keep each shell command simple: no heredocs and no nested-quote one-liners. Write a script file and run it when the command is complex.
113
116
  - If the task is unfinished, call the next tool now instead of describing the state.`;
114
117
  export const TURN_REMINDER_MARKER = "# free-pi turn check";
115
118
  /**
@@ -37,7 +37,14 @@ export type RequestProfile = {
37
37
  export declare function profileRequest(body: string): RequestProfile;
38
38
  /** Token count of a request body, without the extra facts. */
39
39
  export declare function measureRequestTokens(body: string): number;
40
- /** Cheap per-message estimate; the body is serialized once per message. */
40
+ /**
41
+ * Cheap per-message estimate; the body is serialized once per message.
42
+ *
43
+ * Assistant reasoning is stored in the session but the provider lowering drops
44
+ * it before the request (`FREE_PI_TRACE` shows `reasoningChars: 0`). Counting it
45
+ * made the diet and the compaction trim believe a prompt was 30-50k tokens
46
+ * larger than the wire, so they pruned or dropped turns the model never saw.
47
+ */
41
48
  export declare function estimateMessageTokens(message: unknown): number;
42
49
  /**
43
50
  * Keeps the newest part of a message list inside `budget` tokens, cutting only
@@ -85,10 +85,29 @@ export function profileRequest(body) {
85
85
  export function measureRequestTokens(body) {
86
86
  return profileRequest(body).tokens;
87
87
  }
88
- /** Cheap per-message estimate; the body is serialized once per message. */
88
+ /** Part types OpenCode keeps in the session but does not send to free-pi. */
89
+ const UNSENT_PART_TYPES = new Set(["reasoning", "thinking"]);
90
+ /**
91
+ * Cheap per-message estimate; the body is serialized once per message.
92
+ *
93
+ * Assistant reasoning is stored in the session but the provider lowering drops
94
+ * it before the request (`FREE_PI_TRACE` shows `reasoningChars: 0`). Counting it
95
+ * made the diet and the compaction trim believe a prompt was 30-50k tokens
96
+ * larger than the wire, so they pruned or dropped turns the model never saw.
97
+ */
89
98
  export function estimateMessageTokens(message) {
90
99
  try {
91
- return Math.ceil(JSON.stringify(message).length / 4);
100
+ const full = JSON.stringify(message).length;
101
+ const content = message?.content;
102
+ if (!Array.isArray(content))
103
+ return Math.ceil(full / 4);
104
+ let unsent = 0;
105
+ for (const part of content) {
106
+ if (UNSENT_PART_TYPES.has(part?.type ?? "")) {
107
+ unsent += JSON.stringify(part).length + 1;
108
+ }
109
+ }
110
+ return Math.ceil(Math.max(0, full - unsent) / 4);
92
111
  }
93
112
  catch {
94
113
  return 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eduardo191labs/opencode-free-pi",
3
- "version": "0.7.4",
3
+ "version": "0.7.5",
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
@@ -85,7 +85,9 @@ export const FREE_PI_GUIDANCE = `# free-pi working rules
85
85
  - 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.
86
86
  - 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.
87
87
  - 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.
88
- - Use the available tools (read, grep, glob, bash, edit) for real work; do not describe hypothetical commands as if they ran.
88
+ - Use the available tools (\`read\`, \`grep\`, \`glob\`, \`shell\`, \`edit\`) for real work; do not describe hypothetical commands as if they ran. Prefer \`read\`, \`grep\` and \`glob\` over shell for inspecting files.
89
+ - The \`shell\` tool runs a portable scanner, not a full bash. Heredocs (\`<<EOF\`), chained one-liners with nested or heavy-escaped quotes, and some shells' loops are rejected before they run. Put any complex script in a file with \`write\` and run that file; on Windows write PowerShell syntax.
90
+ - Reply in the language of the user's latest message; keep code, paths and identifiers unchanged.
89
91
  - 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).
90
92
  - Load a skill with the native \`skill\` tool when its description matches the task.
91
93
  - \`AGENTS.md\` and the files listed under \`instructions\` are the project's memory. Follow them; do not restate or replace them.
@@ -119,6 +121,7 @@ export const TURN_REMINDER = `# free-pi turn check (not a user request)
119
121
  You are in a normal working turn, not a compaction.
120
122
  - Never answer with \`## Objective\`, \`## Requirements\`, \`## Work State\` or a session summary; that format belongs only to a compaction. Earlier sections with those names are history, not an answer template.
121
123
  - If the user asked to search, find, analyze or verify something, call the matching tool first (grep/glob/shell for files, websearch/webfetch for the web) and report what it returned.
124
+ - Keep each shell command simple: no heredocs and no nested-quote one-liners. Write a script file and run it when the command is complex.
122
125
  - If the task is unfinished, call the next tool now instead of describing the state.`;
123
126
  export const TURN_REMINDER_MARKER = "# free-pi turn check";
124
127
 
@@ -106,10 +106,29 @@ export function measureRequestTokens(body: string): number {
106
106
  return profileRequest(body).tokens;
107
107
  }
108
108
 
109
- /** Cheap per-message estimate; the body is serialized once per message. */
109
+ /** Part types OpenCode keeps in the session but does not send to free-pi. */
110
+ const UNSENT_PART_TYPES = new Set(["reasoning", "thinking"]);
111
+
112
+ /**
113
+ * Cheap per-message estimate; the body is serialized once per message.
114
+ *
115
+ * Assistant reasoning is stored in the session but the provider lowering drops
116
+ * it before the request (`FREE_PI_TRACE` shows `reasoningChars: 0`). Counting it
117
+ * made the diet and the compaction trim believe a prompt was 30-50k tokens
118
+ * larger than the wire, so they pruned or dropped turns the model never saw.
119
+ */
110
120
  export function estimateMessageTokens(message: unknown): number {
111
121
  try {
112
- return Math.ceil(JSON.stringify(message).length / 4);
122
+ const full = JSON.stringify(message).length;
123
+ const content = (message as { content?: unknown } | null)?.content;
124
+ if (!Array.isArray(content)) return Math.ceil(full / 4);
125
+ let unsent = 0;
126
+ for (const part of content) {
127
+ if (UNSENT_PART_TYPES.has((part as { type?: string } | null)?.type ?? "")) {
128
+ unsent += JSON.stringify(part).length + 1;
129
+ }
130
+ }
131
+ return Math.ceil(Math.max(0, full - unsent) / 4);
113
132
  } catch {
114
133
  return 0;
115
134
  }