Refactor to support multiple instances inside single opencode process (#2360)
This release has a bunch of minor breaking changes if you are using opencode plugins or sdk 1. storage events have been removed (we might bring this back but had some issues) 2. concept of `app` is gone - there is a new concept called `project` and endpoints to list projects and get the current project 3. plugin receives `directory` which is cwd and `worktree` which is where the root of the project is if it's a git repo 4. the session.chat function has been renamed to session.prompt in sdk. it no longer requires model to be passed in (model is now an object) 5. every endpoint takes an optional `directory` parameter to operate as though opencode is running in that directory
This commit is contained in:
@@ -160,7 +160,7 @@ func (m *editorComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
if filePath := strings.TrimSpace(strings.TrimPrefix(text, "@")); strings.HasPrefix(text, "@") && filePath != "" {
|
||||
statPath := filePath
|
||||
if !filepath.IsAbs(filePath) {
|
||||
statPath = filepath.Join(m.app.Info.Path.Cwd, filePath)
|
||||
statPath = filepath.Join(util.CwdPath, filePath)
|
||||
}
|
||||
if _, err := os.Stat(statPath); err == nil {
|
||||
attachment := m.createAttachmentFromPath(filePath)
|
||||
@@ -623,7 +623,7 @@ func (m *editorComponent) SetValueWithAttachments(value string) {
|
||||
if end > start {
|
||||
filePath := value[start:end]
|
||||
slog.Debug("test", "filePath", filePath)
|
||||
if _, err := os.Stat(filepath.Join(m.app.Info.Path.Cwd, filePath)); err == nil {
|
||||
if _, err := os.Stat(filepath.Join(util.CwdPath, filePath)); err == nil {
|
||||
slog.Debug("test", "found", true)
|
||||
attachment := m.createAttachmentFromFile(filePath)
|
||||
if attachment != nil {
|
||||
@@ -818,7 +818,7 @@ func (m *editorComponent) createAttachmentFromFile(filePath string) *attachment.
|
||||
mediaType := getMediaTypeFromExtension(ext)
|
||||
absolutePath := filePath
|
||||
if !filepath.IsAbs(filePath) {
|
||||
absolutePath = filepath.Join(m.app.Info.Path.Cwd, filePath)
|
||||
absolutePath = filepath.Join(util.CwdPath, filePath)
|
||||
}
|
||||
|
||||
// For text files, create a simple file reference
|
||||
@@ -872,7 +872,7 @@ func (m *editorComponent) createAttachmentFromPath(filePath string) *attachment.
|
||||
mediaType := getMediaTypeFromExtension(extension)
|
||||
absolutePath := filePath
|
||||
if !filepath.IsAbs(filePath) {
|
||||
absolutePath = filepath.Join(m.app.Info.Path.Cwd, filePath)
|
||||
absolutePath = filepath.Join(util.CwdPath, filePath)
|
||||
}
|
||||
return &attachment.Attachment{
|
||||
ID: uuid.NewString(),
|
||||
|
||||
@@ -55,6 +55,8 @@ func WithBackgroundColor(color compat.AdaptiveColor) renderingOption {
|
||||
func WithNoBorder() renderingOption {
|
||||
return func(c *blockRenderer) {
|
||||
c.border = false
|
||||
c.paddingLeft++
|
||||
c.paddingRight++
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,7 +187,7 @@ func renderContentBlock(
|
||||
style = style.BorderRightForeground(borderColor)
|
||||
}
|
||||
} else {
|
||||
style = style.PaddingLeft(renderer.paddingLeft + 1).PaddingRight(renderer.paddingRight + 1)
|
||||
style = style.PaddingLeft(renderer.paddingLeft).PaddingRight(renderer.paddingRight)
|
||||
}
|
||||
|
||||
content = style.Render(content)
|
||||
|
||||
@@ -769,6 +769,7 @@ func (m *messagesComponent) renderView() tea.Cmd {
|
||||
context.Background(),
|
||||
m.app.CurrentPermission.SessionID,
|
||||
m.app.CurrentPermission.MessageID,
|
||||
opencode.SessionMessageParams{},
|
||||
)
|
||||
if err != nil || response == nil {
|
||||
slog.Error("Failed to get message from child session", "error", err)
|
||||
@@ -1238,6 +1239,7 @@ func (m *messagesComponent) RedoLastMessage() (tea.Model, tea.Cmd) {
|
||||
response, err := m.app.Client.Session.Unrevert(
|
||||
context.Background(),
|
||||
m.app.Session.ID,
|
||||
opencode.SessionUnrevertParams{},
|
||||
)
|
||||
if err != nil {
|
||||
slog.Error("Failed to unrevert session", "error", err)
|
||||
|
||||
@@ -200,7 +200,7 @@ func (m *statusComponent) View() string {
|
||||
|
||||
func (m *statusComponent) startGitWatcher() tea.Cmd {
|
||||
cmd := util.CmdHandler(
|
||||
GitBranchUpdatedMsg{Branch: getCurrentGitBranch(m.app.Info.Path.Root)},
|
||||
GitBranchUpdatedMsg{Branch: getCurrentGitBranch(m.app.Project.Worktree)},
|
||||
)
|
||||
if err := m.initWatcher(); err != nil {
|
||||
return cmd
|
||||
@@ -209,7 +209,7 @@ func (m *statusComponent) startGitWatcher() tea.Cmd {
|
||||
}
|
||||
|
||||
func (m *statusComponent) initWatcher() error {
|
||||
gitDir := filepath.Join(m.app.Info.Path.Root, ".git")
|
||||
gitDir := filepath.Join(m.app.Project.Worktree, ".git")
|
||||
headFile := filepath.Join(gitDir, "HEAD")
|
||||
if info, err := os.Stat(gitDir); err != nil || !info.IsDir() {
|
||||
return err
|
||||
@@ -226,7 +226,7 @@ func (m *statusComponent) initWatcher() error {
|
||||
}
|
||||
|
||||
// Also watch the ref file if HEAD points to a ref
|
||||
refFile := getGitRefFile(m.app.Info.Path.Cwd)
|
||||
refFile := getGitRefFile(util.CwdPath)
|
||||
if refFile != headFile && refFile != "" {
|
||||
if _, err := os.Stat(refFile); err == nil {
|
||||
watcher.Add(refFile) // Ignore error, HEAD watching is sufficient
|
||||
@@ -247,7 +247,7 @@ func (m *statusComponent) watchForGitChanges() tea.Cmd {
|
||||
for {
|
||||
select {
|
||||
case event, ok := <-m.watcher.Events:
|
||||
branch := getCurrentGitBranch(m.app.Info.Path.Root)
|
||||
branch := getCurrentGitBranch(m.app.Project.Worktree)
|
||||
if !ok {
|
||||
return GitBranchUpdatedMsg{Branch: branch}
|
||||
}
|
||||
@@ -276,8 +276,8 @@ func (m *statusComponent) updateWatchedFiles() {
|
||||
if m.watcher == nil {
|
||||
return
|
||||
}
|
||||
refFile := getGitRefFile(m.app.Info.Path.Root)
|
||||
headFile := filepath.Join(m.app.Info.Path.Root, ".git", "HEAD")
|
||||
refFile := getGitRefFile(m.app.Project.Worktree)
|
||||
headFile := filepath.Join(m.app.Project.Worktree, ".git", "HEAD")
|
||||
if refFile != headFile && refFile != "" {
|
||||
if _, err := os.Stat(refFile); err == nil {
|
||||
// Try to add the new ref file (ignore error if already watching)
|
||||
@@ -330,7 +330,7 @@ func NewStatusCmp(app *app.App) StatusComponent {
|
||||
}
|
||||
|
||||
homePath, err := os.UserHomeDir()
|
||||
cwdPath := app.Info.Path.Cwd
|
||||
cwdPath := util.CwdPath
|
||||
if err == nil && homePath != "" && strings.HasPrefix(cwdPath, homePath) {
|
||||
cwdPath = "~" + cwdPath[len(homePath):]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user