Route a General Chat question to the profile that fits it
This commit is contained in:
@@ -109,6 +109,51 @@ function vv_ai_chat_needs_varaverk(string $question): bool {
|
||||
|| vv_ai_resolve_run_target($question) !== '';
|
||||
}
|
||||
|
||||
// Asking for a script to be written, as opposed to asking about one that exists. The verb is
|
||||
// required: "what does arr_sync.sh do" names a script and wants documentation, "write me a script
|
||||
// that does X" names none and wants code. Getting that backwards in either direction is the whole
|
||||
// risk here, so the pattern is anchored on the request rather than on the word "script".
|
||||
function vv_ai_wants_code(string $question): bool {
|
||||
return (bool)preg_match(
|
||||
'/\b(write|create|make|draft|generate|build|give\s+me|need|want)\b[^.?!]{0,40}'
|
||||
. '\b(a\s+|an\s+|me\s+a\s+)?(bash\s+|shell\s+|sh\s+)?'
|
||||
. '(script|one[- ]?liner|cron\s?job|command|snippet)\b/i',
|
||||
$question
|
||||
);
|
||||
}
|
||||
|
||||
// Diagnostic phrasing — "why did X fail", "X is broken", "it never runs". Shared with the
|
||||
// worker's own gate so the router and the gate cannot disagree about what counts as a diagnosis.
|
||||
function vv_ai_is_diagnostic(string $question): bool {
|
||||
return (bool)preg_match(
|
||||
'/\b(why|fail(ed|ing|ure)?|error|broken?|not work|isn.t work|wrong|stuck|hang|'
|
||||
. 'never runs?|didn.t|won.t|debug|troubleshoot|diagnos)/i',
|
||||
$question
|
||||
);
|
||||
}
|
||||
|
||||
// Which profile should answer a General Chat question, or '' to leave it in chat.
|
||||
//
|
||||
// One router, ordered most specific first, because these overlap on purpose: "why did the script
|
||||
// I asked you to write fail" is diagnostic AND mentions a script, and the operator means the
|
||||
// first. The order is the policy.
|
||||
//
|
||||
// code asked for something to be written. Checked first — it is the only intent that
|
||||
// is about a thing that does not exist yet, so nothing else can claim it.
|
||||
// troubleshoot something is wrong. Requires diagnostic phrasing AND something Varaverk-shaped
|
||||
// to diagnose; "why is the sky blue" is diagnostic phrasing about nothing here.
|
||||
// varaverk about this installation, but not a fault and not a request for code.
|
||||
//
|
||||
// Deliberately conservative: an unrecognised question stays in chat, which is the profile that
|
||||
// cannot invent claims about this system. Escalation adds capability, so a wrong escalation costs
|
||||
// more than a missed one — and the worker reverts to chat anyway if retrieval comes back empty.
|
||||
function vv_ai_route_from_chat(string $question): string {
|
||||
if (vv_ai_wants_code($question)) return 'code';
|
||||
if (vv_ai_is_diagnostic($question) && vv_ai_chat_needs_varaverk($question)) return 'troubleshoot';
|
||||
if (vv_ai_chat_needs_varaverk($question)) return 'varaverk';
|
||||
return '';
|
||||
}
|
||||
|
||||
function vv_ai_config(): array {
|
||||
static $cfg = null;
|
||||
if ($cfg !== null) return $cfg;
|
||||
|
||||
Reference in New Issue
Block a user