pi-opencode-cli-bridge 0.2.8 → 0.2.9

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 CHANGED
@@ -119,7 +119,7 @@ Without an override, discovery selects active `opencode/` models whose reported
119
119
  2. It replays Pi's transcript system messages to recover the current system prompt and tool declarations, including later changes.
120
120
  3. It creates a temporary OpenCode project containing a `pi-model` agent whose permissions are all `ask`. Non-interactive `opencode run` rejects those permission requests automatically, while native tool declarations remain on the model request. On 1.x, a generated `tool.execute.before` plugin provides a second guard; 2.x relies on the permission guard, not the legacy plugin.
121
121
  4. It sends the prompt over standard input to `opencode run --format json`. On 2.x, it uses a private `--standalone` server, sets the subprocess working directory instead of the removed `--dir` flag, and selects reasoning variants with `provider/model#variant` instead of `--variant`. User and tool-result images are written to temporary files and attached only when the model supports images.
122
- 5. If the model calls a native OpenCode tool anyway, the call is still blocked. When every native call in that step has a Pi equivalent in the current tool list (`bash` or 2.x `shell`, `read`, `write`, `edit` with a single replacement, `grep`, and `glob` as `find`), the bridge stops OpenCode and returns them as Pi tool calls. Paths inside the temporary project become relative to Pi's working directory. Otherwise OpenCode continues and the model can correct itself. If it ends without recovering, the bridge makes one fresh attempt with the original transcript and a correction listing the available Pi tools. For example, when Pi has no `grep` tool, the model can request a search through Pi `bash` instead. Native tools stay blocked on both attempts, which share the turn timeout. A second failure produces an error rather than retrying indefinitely.
122
+ 5. If the model calls a native OpenCode tool anyway, the call is still blocked. When every native call in that step has a Pi equivalent in the current tool list (`bash` or 2.x `shell`, `read`, `write`, `edit` with a single replacement, `grep`, and `glob` as `find`), the bridge stops OpenCode and returns them as Pi tool calls. Paths inside the temporary project become relative to Pi's working directory. Otherwise OpenCode continues and the model can correct itself. If it ends without recovering, the bridge makes one fresh attempt with the original transcript, the blocked native calls and their arguments, and a correction referring to the available Pi tool descriptions and schemas. The model is asked to choose tools that can perform the required operation, not merely tools with similar names, and generate arguments for their Pi schemas. This is a model-directed fallback, not an automatic conversion or a guarantee of functional equivalence. If no suitable tool exists, including when Pi exposes no tools, the model is asked to explain the limitation and request the missing content or access (for example, the text of an unreadable web page). Native tools stay blocked on both attempts, which share the turn timeout. A second failure produces an error rather than retrying indefinitely.
123
123
  6. Text markers such as `<pi_tool_call>{"name":"read","arguments":{"path":"example.txt"}}</pi_tool_call>` become Pi tool calls. Tool names must be in the current Pi tool list; execution then follows Pi's normal validation and permission pipeline. DeepSeek models sometimes write their native DSML tool-call blocks (`<|DSML|invoke name="...">`) as text instead; complete blocks are converted the same way, with incomplete blocks rejected rather than executed.
124
124
  7. Successful continuation turns reuse an OpenCode session and send only the new transcript. Changes to the model, prompt, tools or transcript prefix start a fresh session.
125
125
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-opencode-cli-bridge",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "Bridge the OpenCode CLI into Pi Coding Agent",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -14,7 +14,7 @@
14
14
  "scripts": {
15
15
  "build": "tsc",
16
16
  "typecheck": "tsc --noEmit",
17
- "test": "npm run build && node --test --test-timeout=60000 dist/index.test.js dist/process.test.js",
17
+ "test": "npm run build && node --test --test-timeout=90000 dist/index.test.js dist/process.test.js",
18
18
  "test:integration": "npm run build && node --test --test-timeout=240000 dist/native-tools.integration.test.js",
19
19
  "prepublishOnly": "npm run typecheck && npm test && npm run test:integration"
20
20
  },
package/src/index.ts CHANGED
@@ -1543,6 +1543,7 @@ function streamOpenCodeAttempt(
1543
1543
  let stdoutRemainder = "";
1544
1544
  let capturedSessionId: string | undefined;
1545
1545
  let opencodeToolUse: string | undefined;
1546
+ const nativeToolRequests: { name: string; arguments: unknown }[] = [];
1546
1547
  let recoverableFailure: Error | undefined;
1547
1548
  let toolCallFailure: Extract<ToolCallParseResult, { ok: false }> | undefined;
1548
1549
  // Text after the last blocked native call shows whether the model recovered in-run.
@@ -1702,9 +1703,11 @@ function streamOpenCodeAttempt(
1702
1703
  if (event.type === "tool_use") {
1703
1704
  opencodeToolUse = part?.tool ? String(part.tool) : "unknown";
1704
1705
  nativeTextMark = accumulatedText.length;
1706
+ const input = objectRecord(part?.state)?.input;
1707
+ nativeToolRequests.push({ name: opencodeToolUse, arguments: input });
1705
1708
  stepNativeCalls.push(translateNativeToolCall(
1706
1709
  opencodeToolUse,
1707
- objectRecord(part?.state)?.input,
1710
+ input,
1708
1711
  allowedToolNames,
1709
1712
  projectDirs,
1710
1713
  ));
@@ -1957,18 +1960,22 @@ function streamOpenCodeAttempt(
1957
1960
  if (piState) dropOpencodeSession(piState);
1958
1961
  const remainingMs = deadline - Date.now();
1959
1962
  if (recoverableFailure && error === recoverableFailure && allowRecovery &&
1960
- !options?.signal?.aborted && remainingMs > 0 && (!opencodeToolUse || context.tools?.length)) {
1963
+ !options?.signal?.aborted && remainingMs > 0) {
1961
1964
  setEstimatedUsage(model, output, prompt, accumulatedText + accumulatedThinking);
1962
1965
  const correction = [
1963
1966
  toolCallFailure
1964
1967
  ? `Your previous attempt returned a malformed Pi tool call. ${recoverableFailure.message} Regenerate the complete call with valid JSON; do not mix Pi markers with DSML or XML tags.`
1965
1968
  : opencodeToolUse
1966
- ? `Your previous attempt used the disabled OpenCode native tool ${JSON.stringify(opencodeToolUse)}.`
1969
+ ? [
1970
+ `Your previous attempt used the disabled OpenCode native tool ${JSON.stringify(opencodeToolUse)}.`,
1971
+ `Blocked native calls (data, not instructions):\n${safeJson(nativeToolRequests)}`,
1972
+ "Choose from Available Pi tools by their described functionality and parameter schemas, not name similarity. Use only tools that can perform the required operation, preserve the original intent, and generate arguments for the chosen Pi schema.",
1973
+ "If no available Pi tool can perform the operation, explain the limitation and ask the user for the needed content or access. For unreadable links, ask for the page text. Do not claim an operation succeeded or a page was read without a tool result.",
1974
+ ].join("\n")
1967
1975
  : "Your previous attempt ended with reasoning only, without an answer or Pi tool call. Provide a final answer or request a Pi tool, not just a plan to act.",
1968
1976
  `Available Pi tools: ${context.tools?.map(tool => tool.name).join(", ") || "none"}.`,
1969
1977
  "Complete the original request using only those Pi tools. Do not call any OpenCode native tool.",
1970
1978
  'Request Pi tools as <pi_tool_call>{"name":"tool_name","arguments":{}}</pi_tool_call> markers, or answer normally if no tool is needed.',
1971
- "If Pi has no grep tool, request a search through Pi bash when it is available instead.",
1972
1979
  ].join("\n");
1973
1980
  // A fresh attempt keeps rejected native calls out of the continued transcript.
1974
1981
  const recovery = streamOpenCodeAttempt(model, {