Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (c *convoDB) Completions(in string) ([]string, error) {
conversations
WHERE
title glob ?
`), in, sha1short, sha1short, in+"*", sha1short, in+"*"); err != nil {
`), in, convIdShort, convIdShort, in+"*", convIdShort, in+"*"); err != nil {
return result, fmt.Errorf("Completions: %w", err)
}
return result, nil
Expand All @@ -252,7 +252,7 @@ func (c *convoDB) Find(in string) (*Conversation, error) {
var conversations []Conversation
var err error

if len(in) < sha1minLen {
if len(in) < convIdMinLen {
err = c.findByExactTitle(&conversations, in)
} else {
err = c.findByIDOrTitle(&conversations, in)
Expand Down
4 changes: 2 additions & 2 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ func TestConvoDB(t *testing.T) {
results, err := db.Completions("f")
require.NoError(t, err)
require.Equal(t, []string{
fmt.Sprintf("%s\t%s", testid1[:sha1short], title1),
fmt.Sprintf("%s\t%s", title2, testid2[:sha1short]),
fmt.Sprintf("%s\t%s", testid1[:convIdShort], title1),
fmt.Sprintf("%s\t%s", title2, testid2[:convIdShort]),
}, results)

results, err = db.Completions(testid1[:8])
Expand Down
20 changes: 20 additions & 0 deletions id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"crypto/rand"
"fmt"
"regexp"
)

const (
convIdShort = 7
convIdMinLen = 4
)

var convIdReg = regexp.MustCompile(`\b[0-9a-f]{40}\b`)

func newConversationID() string {
var b [20]byte
_, _ = rand.Read(b[:])
return fmt.Sprintf("%x", b)
}
16 changes: 8 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (
)

func buildVersion() {
if len(CommitSHA) >= sha1short {
if len(CommitSHA) >= convIdShort {
vt := rootCmd.VersionTemplate()
rootCmd.SetVersionTemplate(vt[:len(vt)-1] + " (" + CommitSHA[0:7] + ")\n")
}
Expand Down Expand Up @@ -572,7 +572,7 @@ func deleteConversationOlderThan() error {
}

if !config.Quiet {
fmt.Fprintln(os.Stderr, "Conversation deleted:", c.ID[:sha1minLen])
fmt.Fprintln(os.Stderr, "Conversation deleted:", c.ID[:convIdMinLen])
}
}

Expand Down Expand Up @@ -606,7 +606,7 @@ func deleteConversation(convo *Conversation) error {
}

if !config.Quiet {
fmt.Fprintln(os.Stderr, "Conversation deleted:", convo.ID[:sha1minLen])
fmt.Fprintln(os.Stderr, "Conversation deleted:", convo.ID[:convIdMinLen])
}
return nil
}
Expand Down Expand Up @@ -656,7 +656,7 @@ func makeOptions(conversations []Conversation) []huh.Option[string] {
opts := make([]huh.Option[string], 0, len(conversations))
for _, c := range conversations {
timea := stdoutStyles().Timeago.Render(timeago.Of(c.UpdatedAt))
left := stdoutStyles().SHA1.Render(c.ID[:sha1short])
left := stdoutStyles().Id.Render(c.ID[:convIdShort])
right := stdoutStyles().ConversationList.Render(c.Title, timea)
if c.Model != nil {
right += stdoutStyles().Comment.Render(*c.Model)
Expand Down Expand Up @@ -707,7 +707,7 @@ func printList(conversations []Conversation) {
_, _ = fmt.Fprintf(
os.Stdout,
"%s\t%s\t%s\n",
stdoutStyles().SHA1.Render(conversation.ID[:sha1short]),
stdoutStyles().Id.Render(conversation.ID[:convIdShort]),
conversation.Title,
stdoutStyles().Timeago.Render(timeago.Of(conversation.UpdatedAt)),
)
Expand All @@ -727,11 +727,11 @@ func saveConversation(mods *Mods) error {
return nil
}

// if message is a sha1, use the last prompt instead.
// if message is a conversaion id, use the last prompt instead.
id := config.cacheWriteToID
title := strings.TrimSpace(config.cacheWriteToTitle)

if sha1reg.MatchString(title) || title == "" {
if convIdReg.MatchString(title) || title == "" {
title = firstLine(lastPrompt(mods.messages))
}

Expand All @@ -757,7 +757,7 @@ func saveConversation(mods *Mods) error {
fmt.Fprintln(
os.Stderr,
"\nConversation saved:",
stderrStyles().InlineCode.Render(config.cacheWriteToID[:sha1short]),
stderrStyles().InlineCode.Render(config.cacheWriteToID[:convIdShort]),
stderrStyles().Comment.Render(title),
)
}
Expand Down
2 changes: 1 addition & 1 deletion mods.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ func (m *Mods) findCacheOpsDetails() tea.Cmd {
writeID = newConversationID()
}

if !sha1reg.MatchString(writeID) {
if !convIdReg.MatchString(writeID) {
convo, err := m.db.Find(writeID)
if err != nil {
// its a new conversation with a title
Expand Down
22 changes: 0 additions & 22 deletions sha.go

This file was deleted.

4 changes: 2 additions & 2 deletions styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type styles struct {
Pipe,
Quote,
ConversationList,
SHA1,
Id,
Timeago lipgloss.Style
}

Expand All @@ -44,7 +44,7 @@ func makeStyles(r *lipgloss.Renderer) (s styles) {
s.Quote = r.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#FF71D0", Dark: "#FF78D2"})
s.Pipe = r.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#8470FF", Dark: "#745CFF"})
s.ConversationList = r.NewStyle().Padding(0, 1)
s.SHA1 = s.Flag
s.Id = s.Flag
s.Timeago = r.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#999", Dark: "#555"})
return s
}
Expand Down