Skip to content

feat(pip): share prompt excerpts from local OpenCode sessions - #335

Merged
maxthomas95 merged 2 commits into
mainfrom
feat/pip-opencode-prompts
Nov 12, 2026
Merged

maxthomas95 merged 2 commits into
mainfrom
feat/pip-opencode-prompts

Conversation

@maxthomas95

Copy link
Copy Markdown
Owner

Pip plan PR 7, plus the Sonar follow-up for #334, which merged before its fix commit landed.

OpenCode prompt excerpts

With Share submitted prompts on, local OpenCode sessions now give Pip the same bounded excerpt as Claude and Codex.

  • Source: OpenCode's own database, opened read-only, and only once native usage has attributed it to the session (usageService.getLocalOpenCodeDatabase).
  • Bounded: two indexed queries. The first finds the newest user message from the past five minutes (message_session_time_created_id_idx); the second reads that message's text parts (at most 50, 4000 characters each). Synthetic parts (OpenCode's reminders and attachments) and non-text parts are skipped, and only typed scalars leave SQLite.
  • Same limits: 400 characters and the same scrubbing, now shared as scrubPromptExcerpt.
  • Not opencode export: it serialises the whole session (1.5 MB for a 101-message session here) and runs CLI middleware first.
  • Still excluded: SSH and Coder sessions, Copilot and Custom share activity only.
  • Refactor: prompt routing moves into readSessionPrompt in pip-handlers.ts. readRecentPrompt loses its existing Sonar warnings (complexity, misleading reverse, nested ternary, a duplicate character class under the i flag).

Live check against the real DB on OpenCode 1.19.5: the newest prompt came back in 3 ms, and the same read with the real clock returned null because the prompt was stale.

#334 follow-up

<output> replaces role="status" in two places (S6819), and the last attempt is read with .at(-1) (S7755).

Docs

src/docs/settings.md (Share submitted prompts) and docs/ARCHITECTURE.md. The panel help text now names OpenCode.

Tests

New: OpenCode excerpt tests against a temporary SQLite DB, covering session isolation, synthetic and non-text parts, stale and malformed rows, bounds, and no writes. Also handler routing for OpenCode, remote, Copilot and Custom (these use hello so the cooldown can't hide a call), and the usage-service accessor. Full vitest passes (2797) and tsc --noEmit is clean. Lint is clean on the changed Pip files.

🤖 Generated with Claude Code

maxthomas95 and others added 2 commits November 12, 2026 16:05
With Share submitted prompts on, Pip could only quote local Claude and
Codex prompts. OpenCode sessions were quip subjects with activity only.
Local OpenCode sessions now contribute the same bounded excerpt, so all
three first-class CLIs get the same outcome.

The excerpt comes from OpenCode's own database, which native usage has
already attributed to the session, opened read-only. It takes two
bounded, indexed queries: the newest user message from the past five
minutes, then that message's text parts. Synthetic parts (OpenCode's
reminders and attachments) and non-text parts are skipped, and only
typed scalars leave SQLite. The same 400-character limit and scrubbing
apply, now shared as scrubPromptExcerpt.

`opencode export` was considered and rejected: it serialises the whole
session (1.5 MB for a 101-message session here) and runs CLI middleware
first, just to read one prompt.

SSH and Coder sessions, Copilot and Custom still share activity only.
The prompt routing moves into readSessionPrompt, and readRecentPrompt
loses its existing Sonar warnings along the way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…st attempt

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@maxthomas95
maxthomas95 merged commit 2d8d7d7 into main Nov 12, 2026
11 checks passed
@maxthomas95
maxthomas95 deleted the feat/pip-opencode-prompts branch November 12, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant