-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add prompt notes to track LLM context on commits #754
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
jonnii
wants to merge
2
commits into
main
from
jonnii/20260220125253/add-prompt-notes-to-track-LLM-context-on-commits
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
196 changes: 196 additions & 0 deletions
internal/actions/notes/notes.go
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,196 @@ | ||
| // Package notes implements the stackit notes command for managing contextual notes on commits. | ||
| package notes | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "github.com/getstackit/stackit/internal/app" | ||
| "github.com/getstackit/stackit/internal/errors" | ||
| "github.com/getstackit/stackit/internal/git" | ||
| "github.com/getstackit/stackit/internal/output" | ||
| "github.com/getstackit/stackit/internal/tui/style" | ||
| ) | ||
|
|
||
| // ShowOptions contains options for the show subcommand. | ||
| type ShowOptions struct { | ||
| Commit string // Commit to show note for (defaults to HEAD) | ||
| Namespace string // Namespace to read (defaults to story) | ||
| } | ||
|
|
||
| // AddOptions contains options for the add subcommand. | ||
| type AddOptions struct { | ||
| Namespace string | ||
| Prompt string | ||
| Summary string | ||
| Model string | ||
| Memory []string | ||
| JSON string // Raw JSON alternative to individual flags | ||
| } | ||
|
|
||
| // LogOptions contains options for the log subcommand. | ||
| type LogOptions struct { | ||
| Namespace string | ||
| } | ||
|
|
||
| // Show displays the note for a commit. | ||
| func Show(ctx *app.Context, opts ShowOptions) error { | ||
| out := ctx.Output | ||
|
|
||
| commit := opts.Commit | ||
| if commit == "" { | ||
| rev, err := ctx.Git().GetCurrentRevision(ctx.Context) | ||
|
Check failure on line 42 in internal/actions/notes/notes.go GitHub Actions / Lint
|
||
| if err != nil { | ||
| return fmt.Errorf("failed to get current revision: %w", err) | ||
| } | ||
| commit = rev | ||
| } | ||
|
|
||
| namespace := opts.Namespace | ||
| if namespace == "" { | ||
| namespace = git.DefaultNotesNamespace | ||
| } | ||
|
|
||
| note, err := ctx.Git().ShowPromptNote(ctx.Context, commit, namespace) | ||
|
Check failure on line 54 in internal/actions/notes/notes.go GitHub Actions / Lint
|
||
| if err != nil { | ||
| return fmt.Errorf("failed to read note: %w", err) | ||
| } | ||
|
|
||
| if note == nil { | ||
| shortSHA := commit | ||
| if len(shortSHA) > 7 { | ||
| shortSHA = shortSHA[:7] | ||
| } | ||
| out.Info("No %s note on %s.", style.ColorDim(namespace), style.ColorDim(shortSHA)) | ||
| return nil | ||
| } | ||
|
|
||
| printNote(out, note) | ||
| return nil | ||
| } | ||
|
|
||
| // Add creates or replaces a note on HEAD. | ||
| func Add(ctx *app.Context, opts AddOptions) error { | ||
| out := ctx.Output | ||
| g := ctx.Git() | ||
| namespace := opts.Namespace | ||
| if namespace == "" { | ||
| namespace = git.DefaultNotesNamespace | ||
| } | ||
|
|
||
| rev, err := g.GetCurrentRevision(ctx.Context) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get current revision: %w", err) | ||
| } | ||
|
|
||
| var note git.PromptNote | ||
|
|
||
| if opts.JSON != "" { | ||
| if err := json.Unmarshal([]byte(opts.JSON), ¬e); err != nil { | ||
| return fmt.Errorf("failed to parse JSON: %w", err) | ||
| } | ||
| } else { | ||
| if opts.Prompt == "" { | ||
| return fmt.Errorf("--prompt is required") | ||
| } | ||
| note = git.PromptNote{ | ||
| Prompt: opts.Prompt, | ||
| Summary: opts.Summary, | ||
| Model: opts.Model, | ||
| Memory: opts.Memory, | ||
| } | ||
| } | ||
|
|
||
| // Ensure notes.rewriteRef is configured so notes survive rebase | ||
| if err := g.EnsureNotesRewriteConfigured(); err != nil { | ||
| out.Debug("Failed to configure notes.rewriteRef: %v", err) | ||
| } | ||
|
|
||
| if err := g.AddPromptNote(ctx.Context, rev, namespace, ¬e); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| shortSHA := rev | ||
| if len(shortSHA) > 7 { | ||
| shortSHA = shortSHA[:7] | ||
| } | ||
| out.Info("Added %s note to %s.", style.ColorDim(namespace), style.ColorDim(shortSHA)) | ||
| return nil | ||
| } | ||
|
|
||
| // Log shows commits on the current branch with notes from the requested namespace. | ||
| func Log(ctx *app.Context, opts LogOptions) error { | ||
| eng := ctx.Engine | ||
| out := ctx.Output | ||
| namespace := opts.Namespace | ||
| if namespace == "" { | ||
| namespace = git.DefaultNotesNamespace | ||
| } | ||
|
|
||
| currentBranch := eng.CurrentBranch() | ||
| if currentBranch == nil { | ||
| return errors.ErrNotOnBranch | ||
| } | ||
|
|
||
| // Get parent branch for commit range | ||
| parent := currentBranch.GetParent() | ||
| if parent == nil { | ||
| return fmt.Errorf("branch %s has no parent; cannot determine commit range", currentBranch.GetName()) | ||
| } | ||
|
|
||
| entries, err := ctx.Git().LogWithNotes(ctx.Context, parent.GetName(), currentBranch.GetName(), namespace) | ||
|
Check failure on line 141 in internal/actions/notes/notes.go GitHub Actions / Lint
|
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if len(entries) == 0 { | ||
| out.Info("No commits between %s and %s.", parent.GetName(), currentBranch.GetName()) | ||
| return nil | ||
| } | ||
|
|
||
| for _, entry := range entries { | ||
| shortSHA := entry.SHA | ||
| if len(shortSHA) > 7 { | ||
| shortSHA = shortSHA[:7] | ||
| } | ||
| out.Info("%s %s", style.ColorDim(shortSHA), entry.Subject) | ||
| if entry.Note != nil { | ||
| out.Info(" Prompt: %s", entry.Note.Prompt) | ||
| if entry.Note.Summary != "" { | ||
| out.Info(" Summary: %s", entry.Note.Summary) | ||
| } | ||
| } else { | ||
| out.Info(" %s", style.ColorDim("(no note in namespace "+namespace+")")) | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // Push pushes notes to the remote. | ||
| func Push(ctx *app.Context) error { | ||
| out := ctx.Output | ||
|
|
||
| if err := ctx.Git().PushNotes(ctx.Context); err != nil { | ||
|
Check failure on line 174 in internal/actions/notes/notes.go GitHub Actions / Lint
|
||
| return err | ||
| } | ||
|
|
||
| out.Info("Pushed notes to remote.") | ||
| return nil | ||
| } | ||
|
|
||
| func printNote(out output.Output, note *git.PromptNote) { | ||
| out.Info("Prompt: %s", note.Prompt) | ||
| if note.Summary != "" { | ||
| out.Info("Summary: %s", note.Summary) | ||
| } | ||
| if note.Model != "" { | ||
| out.Info("Model: %s", note.Model) | ||
| } | ||
| if len(note.Memory) > 0 { | ||
| out.Info("Memory:") | ||
| for _, m := range note.Memory { | ||
| out.Info(" - %s", m) | ||
| } | ||
| } | ||
| } | ||
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
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.
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.