feat(ollama): enforce JSON logits & add nvim_buffer edit action

- Added format parameter to Ollama generate for JSON logit enforcement.

- Implemented safe edit action in nvim_buffer MCP tool to replace raw Lua.
This commit is contained in:
Riz Ashraf committed 2026-10-08 23:41:57 +01:00
1 parent 003b3cb2bf
commit 410b0c42ca
6 files changed
+56 -8

No files matched your search

+1 -1
View File
@@ -824,7 +824,7 @@ impl McpTool for CondenseEntityHandler {
req.entity_name,
unique_obs.join("\n- ")
);
if let Ok(summary) = state.ollama.generate(&prompt, None, None).await {
if let Ok(summary) = state.ollama.generate(&prompt, None, None, None).await {
let lines: Vec<String> = summary
.lines()
.map(|l| l.trim().trim_start_matches('-').trim().to_string())
+2 -2
View File
@@ -33,7 +33,7 @@ impl McpTool for LogErrorFixHandler {
);
if let Ok(summary) = state
.ollama
.generate(&prompt, Some(&state.ollama.reasoning_model), None)
.generate(&prompt, Some(&state.ollama.reasoning_model), None, None)
.await
{
let clean = summary.trim();
@@ -207,7 +207,7 @@ impl McpTool for LogCodeChangeHandler {
"Summarize in 1 concise sentence the architectural impact of changing file '{}': {}",
req.file_path, description
);
if let Ok(summary) = state.ollama.generate(&prompt, None, None).await {
if let Ok(summary) = state.ollama.generate(&prompt, None, None, None).await {
let clean = summary.trim();
if !clean.is_empty() {
description = format!("{} (AI Summary: {})", description, clean);
+1 -1
View File
@@ -359,7 +359,7 @@ impl McpTool for SemanticCodeSearchHandler {
);
if let Ok(summary) = state
.ollama
.generate(&prompt, None, Some("Respond clearly and concisely."))
.generate(&prompt, None, Some("Respond clearly and concisely."), None)
.await
{
out.push_str("\n\n--- Local GraphRAG Summary ---\n");
+1
View File
@@ -308,6 +308,7 @@ pub async fn memory_consolidation_worker(state: Arc<MemoryState>) {
&prompt,
None,
Some("You are a helpful JSON-only data deduplication assistant. Output only JSON."),
Some("json"),
)
.await
{
+5
View File
@@ -27,6 +27,8 @@ struct GenerateRequest<'a> {
options: Option<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
keep_alive: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
format: Option<&'a str>,
}
#[derive(Deserialize)]
@@ -113,6 +115,7 @@ impl OllamaClient {
prompt: &str,
model_override: Option<&str>,
system: Option<&str>,
format: Option<&str>,
) -> Result<String, AppError> {
let model = model_override.unwrap_or(&self.coder_model);
let url = format!("{}/api/generate", self.base_url.trim_end_matches('/'));
@@ -128,6 +131,7 @@ impl OllamaClient {
"num_predict": 4096 // Give reasoning models plenty of output room
})),
keep_alive: Some("1h"),
format,
};
let res = self
@@ -172,6 +176,7 @@ impl OllamaClient {
"num_predict": 1024
})),
keep_alive: Some("1h"),
format: None,
};
let res = self