Skip to content

Commit d8254a3

Browse files
committed
Update AI Configuration Parsing and Release Notes Prompt
Migrate from assistant::Config static methods to assistant::ConfigBuilder for more robust error handling. The ConfigBuilder returns a result object with both a config value and an error message, enabling better user feedback when configuration parsing fails. Display error dialogs to users when configuration loading fails on the main thread, and fall back to default settings. Update the git release notes prompt to instruct the AI to fetch commits directly using git commands rather than requiring pre-supplied input. Simplify the prompt structure by removing the placeholder input section. * AI configuration loading (LLMManager.cpp) * Release notes generation prompt (Prompts.cpp) * Assistant submodule update ** Generated by CodeLite. ** Signed-off-by: Eran Ifrah <eran@codelite.org>
1 parent 38f63b7 commit d8254a3

File tree

3 files changed

+36
-37
lines changed

3 files changed

+36
-37
lines changed

Plugin/ai/LLMManager.cpp

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,8 @@ assistant::Config Manager::MakeConfig()
531531
{
532532
std::call_once(config_create_once_flag, [this]() {
533533
// Should never fail.
534-
m_default_config = assistant::Config::FromContent(kDefaultSettings.ToStdString(wxConvUTF8)).value();
534+
m_default_config =
535+
assistant::ConfigBuilder::FromContent(kDefaultSettings.ToStdString(wxConvUTF8)).config_.value();
535536

536537
// Redirect the library logs to our logging machinery.
537538
assistant::SetLogSink([](assistant::LogLevel level, std::string msg) {
@@ -558,7 +559,14 @@ assistant::Config Manager::MakeConfig()
558559

559560
// Apply environment variables before we proceed
560561
EnvSetter env;
561-
return assistant::Config::FromFile(res.value().ToStdString(wxConvUTF8)).value_or(m_default_config);
562+
auto result = assistant::ConfigBuilder::FromFile(res.value().ToStdString(wxConvUTF8));
563+
if (!result.ok()) {
564+
if (::wxIsMainThread()) {
565+
::wxMessageBox(result.errmsg_, "CodeLite", wxICON_ERROR | wxOK | wxCENTER);
566+
return assistant::ConfigBuilder::FromContent(kDefaultSettings.ToStdString(wxConvUTF8)).config_.value();
567+
}
568+
}
569+
return result.config_.value();
562570
}
563571

564572
void Manager::Restart()
@@ -682,21 +690,25 @@ bool Manager::ReloadConfig(std::optional<wxString> config_content, bool prompt)
682690
}
683691

684692
EnvSetter env;
685-
auto conf = assistant::Config::FromContent(content.ToStdString(wxConvUTF8));
686-
if (conf.has_value()) {
687-
m_client_config = std::move(conf.value());
688-
// Now we can replace the client instance
689-
auto client = assistant::MakeClient(m_client_config).value_or(nullptr);
690-
if (!client) {
691-
clERROR() << "Could not create new LLM client!" << endl;
692-
return false;
693+
auto result = assistant::ConfigBuilder::FromContent(content.ToStdString(wxConvUTF8));
694+
if (!result.ok()) {
695+
if (::wxIsMainThread()) {
696+
::wxMessageBox(result.errmsg_, "CodeLite", wxICON_ERROR | wxOK | wxCENTER);
693697
}
698+
return false;
699+
}
694700

695-
// Start the new client
696-
Start(client);
697-
return true;
701+
m_client_config = std::move(result.config_.value());
702+
// Now we can replace the client instance
703+
auto client = assistant::MakeClient(m_client_config).value_or(nullptr);
704+
if (!client) {
705+
clERROR() << "Could not create new LLM client!" << endl;
706+
return false;
698707
}
699-
return false;
708+
709+
// Start the new client
710+
Start(client);
711+
return true;
700712
}
701713

702714
void Manager::ClearHistory()
@@ -973,13 +985,9 @@ clStatusOr<wxString> Manager::CreateOrOpenConfig()
973985
wxString global_config_path = FileManager::GetSettingFileFullPath(kAssistantConfigFile, opts);
974986
wxString backup_file_path = global_config_path + ".old";
975987
bool valid_file{false};
976-
try {
977-
EnvSetter env;
978-
auto conf = assistant::Config::FromFile(global_config_path.ToStdString(wxConvUTF8));
979-
valid_file = conf.has_value();
980-
} catch (const std::exception& e) {
981-
valid_file = false;
982-
}
988+
EnvSetter env;
989+
auto result = assistant::ConfigBuilder::FromFile(global_config_path.ToStdString(wxConvUTF8));
990+
valid_file = result.ok();
983991

984992
if (!valid_file) {
985993
// Backup old file

Plugin/ai/Prompts.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ const std::string PROMPT_GIT_RELEASE_NOTES =
6666
R"(You are an expert technical writer who creates concise, well‑structured release notes for public websites.
6767
6868
Your job:
69-
1. Read the raw commit list below (one commit per line).
70-
2. Group the changes into the following sections **only if there is at least one item**:
69+
1. Obtain all git commits from HEAD to the latest tag. Use `git describe --tags --abbrev=0` to find the latest tag, then `git log <tag>..HEAD --oneline` to list the commits.
70+
2. Group the commits into the following sections **only if there is at least one item**:
7171
- **✨ New Features** – new public‑facing functionality.
7272
- **🐛 Bug Fixes** – corrections of defects.
7373
- **🔧 Improvements / Refactorings** – internal enhancements, performance, code cleanup, etc.
@@ -87,20 +87,11 @@ Your job:
8787
8888
5. At the top of the document, add a title line with the release version and date, formatted exactly as:
8989
90-
```markdown
91-
# Release {{VERSION}} – {{RELEASE_DATE}}
92-
```
93-
94-
6. End the notes with a short “_Thank you for using our software!_” line.
95-
96-
---
97-
98-
### Input (replace this block with your real data)
99-
100-
```
101-
{{context}}
90+
```markdown
91+
# Release {{VERSION}} – {{RELEASE_DATE}}
10292
```
103-
)";
93+
94+
6. End the notes with a short “_Thank you for using our software!_” line.)";
10495

10596
const std::string PROMPT_GIT_RELEASE_NOTES_MERGE =
10697
R"(Rephrase the following release notes text. Remove duplicate entries and merge the sections.

0 commit comments

Comments
 (0)