-
Notifications
You must be signed in to change notification settings - Fork 103
Add persistent Supermemory status to OpenCode #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ishaanxgupta
wants to merge
1
commit into
opencode/memory-activity
Choose a base branch
from
opencode/persistent-memory-status
base: opencode/memory-activity
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /** @jsxImportSource @opentui/solid */ | ||
| import type { | ||
| TuiPlugin, | ||
| TuiPluginModule, | ||
| } from "@opencode-ai/plugin/tui"; | ||
| import { createSignal } from "solid-js"; | ||
|
|
||
| const DEFAULT_ACTIVITY = "ready"; | ||
|
|
||
| interface RecallActivity { | ||
| count: number; | ||
| tokens: number; | ||
| } | ||
|
|
||
| function asRecord(value: unknown): Record<string, unknown> | null { | ||
| return value && typeof value === "object" | ||
| ? (value as Record<string, unknown>) | ||
| : null; | ||
| } | ||
|
|
||
| export function getRecallActivity(part: unknown): RecallActivity | null { | ||
| const value = asRecord(part); | ||
| if (!value || value.type !== "text") return null; | ||
|
|
||
| const metadata = asRecord(value.metadata); | ||
| const supermemory = asRecord(metadata?.supermemory); | ||
| if (supermemory?.activity === "recalled") { | ||
| const count = supermemory.count; | ||
| const tokens = supermemory.tokens; | ||
| if (typeof count === "number" && typeof tokens === "number") { | ||
| return { count, tokens }; | ||
| } | ||
| } | ||
|
|
||
| const text = typeof value.text === "string" ? value.text : ""; | ||
| if (!text.includes("<supermemory-context>")) return null; | ||
| const count = text.split("\n").filter((line) => line.startsWith("- ◪ ")).length; | ||
| return count > 0 | ||
| ? { count, tokens: Math.round(text.length / 4) } | ||
| : null; | ||
| } | ||
|
|
||
| function recallLabel(activity: RecallActivity): string { | ||
| return `recalled ${activity.count} ${activity.count === 1 ? "memory" : "memories"} (${activity.tokens} tok)`; | ||
| } | ||
|
|
||
| const tui: TuiPlugin = async (api) => { | ||
| const busySessions = new Set<string>(); | ||
| const [running, setRunning] = createSignal(false); | ||
| const [activity, setActivity] = createSignal(DEFAULT_ACTIVITY); | ||
|
|
||
| api.event.on("session.status", (event) => { | ||
| const { sessionID, status } = event.properties; | ||
| if (status.type === "busy" || status.type === "retry") { | ||
| busySessions.add(sessionID); | ||
| } else { | ||
| busySessions.delete(sessionID); | ||
| } | ||
| setRunning(busySessions.size > 0); | ||
| }); | ||
|
|
||
| api.event.on("session.idle", (event) => { | ||
| busySessions.delete(event.properties.sessionID); | ||
| setRunning(busySessions.size > 0); | ||
| }); | ||
|
|
||
| api.event.on("message.part.updated", (event) => { | ||
| const recalled = getRecallActivity(event.properties.part); | ||
| if (recalled) setActivity(recallLabel(recalled)); | ||
| }); | ||
|
|
||
| api.event.on("tui.toast.show", (event) => { | ||
| const message = event.properties.message; | ||
| if (!message.startsWith("◪ supermemory · ")) return; | ||
| setActivity(message.slice("◪ supermemory · ".length)); | ||
| }); | ||
|
|
||
| api.slots.register({ | ||
| slots: { | ||
| app_bottom: () => ( | ||
| <box paddingLeft={1} flexDirection="row"> | ||
| <text fg={running() ? api.theme.current.info : api.theme.current.success}> | ||
| {`◪ supermemory · ${running() ? "running" : activity()}`} | ||
| </text> | ||
| </box> | ||
| ), | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| const plugin: TuiPluginModule & { id: string } = { | ||
| id: "supermemory.status", | ||
| tui, | ||
| }; | ||
|
|
||
| export default plugin; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2 — Only install the TUI plugin after server-plugin registration succeeds. The interactive flow can decline creating/updating the main OpenCode config, and
addPluginToConfig()can also returnfalse, but this call still writes the package totui.json[c]. OpenCode loads that TUI entry independently, leaving a Supermemory footer installed even though the server plugin that provides recall/save behavior is absent. Please track the main registration result and skip or separately confirm TUI installation when it did not succeed.