aKode fase 3: provider locali, chiavi per provider, modelli dal server, SearXNG
- Provider: rimossi openai, Bedrock e GCP integrati e ogni fallback a OpenAI;
restano ollama, lmstudio e i provider personalizzati. Senza provider, exec e
TUI mostrano come configurarlo.
- Chiave per provider: api_key = "keyring", provider_api_key_store =
auto|keyring|file (fallback su file 0600 / ACL Windows); `codex login
--provider <id> --with-api-key`, `logout --provider`; login status e doctor
mostrano dove sta la chiave senza rivelarla.
- Modelli letti da GET {base_url}/models; contesto da config, poi dal server
(/props, meta.n_ctx), poi 32768; apply_patch come tool function; niente tool
ospitati; niente piu' avviso "metadata not found".
- Unione dei soli messaggi system/developer iniziali in un unico system;
quelli successivi restano al loro posto come user (cache del server
preservata: turno N prefisso esatto del turno N+1).
- Modelli ausiliari (memorie, guardian-v2) = modello di sessione se il
preferito gpt-* non e' nel catalogo.
- Ricerca web: crate web-tools, backend SearXNG con web_search e web_fetch
(protezione SSRF); senza backend nessuno strumento web.
- Skill: rimossa openai-docs; skill-installer punta a git.difonzo.net.
- apply_patch accetta gli header @@ -a,b +c,d @@ dei diff unificati.
- Rimossi resti: request_plugin_install, AppsInstructions, --cyber-access-program,
URL updater/realtime predefiniti.
- Fix: importazione sessioni con provider vuoto.
- Istruzioni di sistema invariate. Test: cancellati solo quelli del codice
rimosso, test di sicurezza adattati; restano solo fallimenti d'ambiente.
- Prova reale su imeAI + SearXNG: risposta, modifica file, web_search,
cache riusata, connessioni solo verso .25 e .57.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -280,8 +280,15 @@ impl StreamingPatchParser {
|
||||
}
|
||||
|
||||
if let Some(change_context) = update_line.strip_prefix(CHANGE_CONTEXT_MARKER) {
|
||||
// Local models often write unified-diff hunk headers
|
||||
// (`@@ -1,2 +1,2 @@ fn name`); the line ranges carry no context.
|
||||
let change_context = match unified_diff_range_header_rest(change_context) {
|
||||
Some("") => None,
|
||||
Some(rest) => Some(rest.to_string()),
|
||||
None => Some(change_context.to_string()),
|
||||
};
|
||||
chunks.push(UpdateFileChunk {
|
||||
change_context: Some(change_context.to_string()),
|
||||
change_context,
|
||||
..UpdateFileChunk::default()
|
||||
});
|
||||
self.state.mode = StreamingParserMode::UpdateFile { hunk_line_number };
|
||||
@@ -922,3 +929,89 @@ mod tests {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// For a unified-diff hunk header body such as `-1,2 +1,3 @@ fn name` (the part after the
|
||||
/// leading `@@ `), returns the trailing section text (`fn name`, or `""`). Returns `None`
|
||||
/// when the text is not a line-range header and so is ordinary change context.
|
||||
fn unified_diff_range_header_rest(change_context: &str) -> Option<&str> {
|
||||
fn is_range(token: &str, sign: char) -> bool {
|
||||
let Some(range) = token.strip_prefix(sign) else {
|
||||
return false;
|
||||
};
|
||||
let mut parts = range.splitn(2, ',');
|
||||
let start = parts.next().unwrap_or_default();
|
||||
let count_ok = parts
|
||||
.next()
|
||||
.is_none_or(|count| !count.is_empty() && count.bytes().all(|b| b.is_ascii_digit()));
|
||||
!start.is_empty() && start.bytes().all(|b| b.is_ascii_digit()) && count_ok
|
||||
}
|
||||
let (ranges, rest) = change_context.split_once("@@")?;
|
||||
let mut tokens = ranges.split_whitespace();
|
||||
if !is_range(tokens.next()?, '-') {
|
||||
return None;
|
||||
}
|
||||
match tokens.next() {
|
||||
None => {}
|
||||
Some(token) if is_range(token, '+') => {}
|
||||
Some(_) => return None,
|
||||
}
|
||||
if tokens.next().is_some() {
|
||||
return None;
|
||||
}
|
||||
Some(rest.trim())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod unified_diff_header_tests {
|
||||
use super::unified_diff_range_header_rest;
|
||||
use crate::parser::Hunk;
|
||||
use crate::parser::parse_patch;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
fn first_change_context(patch: &str) -> Option<String> {
|
||||
let args = parse_patch(patch).expect("patch parses");
|
||||
let Some(Hunk::UpdateFile { chunks, .. }) = args.hunks.first() else {
|
||||
panic!("expected an update hunk");
|
||||
};
|
||||
chunks[0].change_context.clone()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn range_headers_are_recognized() {
|
||||
assert_eq!(unified_diff_range_header_rest("-1,2 @@"), Some(""));
|
||||
assert_eq!(unified_diff_range_header_rest("-1,2 +1,3 @@"), Some(""));
|
||||
assert_eq!(
|
||||
unified_diff_range_header_rest("-7 +7 @@ def f():"),
|
||||
Some("def f():")
|
||||
);
|
||||
assert_eq!(unified_diff_range_header_rest("def f():"), None);
|
||||
assert_eq!(unified_diff_range_header_rest("-x @@"), None);
|
||||
assert_eq!(unified_diff_range_header_rest("-1, @@"), None);
|
||||
assert_eq!(unified_diff_range_header_rest("-1 +2 +3 @@"), None);
|
||||
assert_eq!(unified_diff_range_header_rest("-1,2"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unified_diff_hunk_header_parses_like_a_bare_marker() {
|
||||
let patch = "*** Begin Patch\n*** Update File: hello.py\n@@ -1,2 @@\n def greet(name):\n- return \"Hello \" + name\n+ return \"Ciao \" + name\n*** End Patch";
|
||||
assert_eq!(first_change_context(patch), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unified_diff_hunk_header_keeps_its_section_text_as_context() {
|
||||
let patch = "*** Begin Patch\n*** Update File: hello.py\n@@ -1,2 +1,2 @@ def greet(name):\n- return \"Hello \" + name\n+ return \"Ciao \" + name\n*** End Patch";
|
||||
assert_eq!(
|
||||
first_change_context(patch),
|
||||
Some("def greet(name):".to_string())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordinary_change_context_is_unchanged() {
|
||||
let patch = "*** Begin Patch\n*** Update File: hello.py\n@@ def greet(name):\n- return \"Hello \" + name\n+ return \"Ciao \" + name\n*** End Patch";
|
||||
assert_eq!(
|
||||
first_change_context(patch),
|
||||
Some("def greet(name):".to_string())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user