feat: implement AI-assisted rename prompting feature

- Added data model for AI-assisted renaming including structures for prompts, responses, and policies.
- Created implementation plan detailing the integration of Google Genkit into the CLI for renaming tasks.
- Developed quickstart guide for setting up and using the new AI rename functionality.
- Documented research decisions regarding Genkit orchestration and prompt composition.
- Established tasks for phased implementation, including setup, foundational work, and user stories.
- Implemented contract tests to ensure AI rename policies and ledger metadata are correctly applied.
- Developed integration tests for validating AI rename flows, including preview, apply, and undo functionalities.
- Added tooling to pin Genkit dependency for consistent builds.
This commit is contained in:
2025-11-03 18:08:14 +08:00
parent aa377bc7ed
commit 3867736858
41 changed files with 4082 additions and 9 deletions

View File

@@ -3,6 +3,7 @@ package output
import (
"fmt"
"io"
"strings"
)
// plainFormatter emits one entry per line suitable for piping into other tools.
@@ -26,3 +27,41 @@ func (plainFormatter) WriteSummary(w io.Writer, summary Summary) error {
_, err := fmt.Fprintln(w, DefaultSummaryLine(summary))
return err
}
// WriteAIPlanDebug emits prompt hashes and warnings to the provided writer.
func WriteAIPlanDebug(w io.Writer, promptHash string, warnings []string) {
if w == nil {
return
}
if promptHash != "" {
fmt.Fprintf(w, "Prompt hash: %s\n", promptHash)
}
for _, warning := range warnings {
if strings.TrimSpace(warning) == "" {
continue
}
fmt.Fprintf(w, "%s\n", warning)
}
}
// PolicyViolationMessage describes a single policy failure for display purposes.
type PolicyViolationMessage struct {
Original string
Proposed string
Rule string
Message string
}
// WritePolicyViolations prints detailed policy failure information to the writer.
func WritePolicyViolations(w io.Writer, violations []PolicyViolationMessage) {
if w == nil {
return
}
for _, violation := range violations {
rule := violation.Rule
if rule == "" {
rule = "policy"
}
fmt.Fprintf(w, "Policy violation (%s): %s -> %s (%s)\n", rule, violation.Original, violation.Proposed, violation.Message)
}
}

View File

@@ -46,3 +46,53 @@ func (f *tableFormatter) WriteSummary(w io.Writer, summary Summary) error {
_, err := fmt.Fprintln(w, DefaultSummaryLine(summary))
return err
}
// AIPlanRow represents a single AI plan preview row.
type AIPlanRow struct {
Sequence string
Original string
Proposed string
Sanitized string
}
// AIPlanTable renders AI plan previews in a tabular format.
type AIPlanTable struct {
writer *tabwriter.Writer
}
// NewAIPlanTable constructs a table for AI plan previews.
func NewAIPlanTable() *AIPlanTable {
return &AIPlanTable{}
}
// Begin writes the header for the AI plan table.
func (t *AIPlanTable) Begin(w io.Writer) error {
if t.writer != nil {
return fmt.Errorf("ai plan table already initialized")
}
t.writer = tabwriter.NewWriter(w, 0, 4, 2, ' ', 0)
_, err := fmt.Fprintln(t.writer, "SEQ\tORIGINAL\tPROPOSED\tSANITIZED")
return err
}
// WriteRow appends a plan row to the table.
func (t *AIPlanTable) WriteRow(row AIPlanRow) error {
if t.writer == nil {
return fmt.Errorf("ai plan table not initialized")
}
_, err := fmt.Fprintf(t.writer, "%s\t%s\t%s\t%s\n", row.Sequence, row.Original, row.Proposed, row.Sanitized)
return err
}
// End flushes the table to the underlying writer.
func (t *AIPlanTable) End(w io.Writer) error {
if t.writer == nil {
return fmt.Errorf("ai plan table not initialized")
}
if err := t.writer.Flush(); err != nil {
return err
}
_, err := fmt.Fprintln(w)
t.writer = nil
return err
}