3.4.0: AI decision loop (Track κ)#42
Merged
chenliuyun merged 3 commits intomainfrom May 7, 2026
Merged
Conversation
added 3 commits
May 7, 2026 12:29
PR 1 — Decision Trace - src/rules/trace.ts: deepSortedJson, ruleVersion (sha256/8-char), TraceBuilder, shouldWriteTrace (full/sampled/off), filterTraceRecords - engine.ts: fireId before eval, TraceBuilder threaded, emitTrace closure - matcher.ts: trace? param, pushConditionTrace after eval, isLlmCondition guard - audit.ts: rule-evaluate/llm-condition/llm-budget-exceeded kinds; writeEvaluateTrace - schema v0.2.json: automation.audit block (evaluate_trace, evaluate_retention_days) - tests/rules/trace.test.ts: 30 tests PR 2 — rules explain - src/rules/explain.ts: loadTraceRecords, loadRelatedAudit, formatExplainText/Json - rules.ts: trace-explain subcommand (avoids collision with static explain) - mcp.ts: rules_explain tool - tests/rules/explain.test.ts: 19 tests PR 3 — LLM condition - src/rules/types.ts: LlmCondition interface + isLlmCondition guard; AutomationLlmBudgetConfig - llm/provider.ts: decide() + DecideResult/DecideOptions on LLMProvider interface - llm/providers/anthropic.ts: decide() via tool-use API - llm/providers/openai.ts: decide() via function-calling API - src/rules/llm-condition.ts: LlmConditionEvaluator (cache, budget, on_error) Cache key: sha256(JSON.stringify([ruleVersion, prompt, deepSortedJson(ctx)])) — fixes spec gap #5 - matcher.ts: llm condition branch with provider injection - schema: llm condition oneOf branch + automation.llm_budget - engine.ts: 4 lint rules (condition-llm-no-provider, no-cache-ttl-high-freq, budget-zero, on-error-pass) - tests/rules/llm-condition.test.ts: 22 tests PR 4 — rules simulate - src/rules/simulate.ts: simulateRule(), as-of state fetcher, against-file replay, ThrottleGate simulation, LLM skip marker - rules.ts: simulate subcommand - mcp.ts: rules_simulate tool - capabilities.ts: trace-explain + simulate entries - tests/rules/simulate.test.ts: 18 tests Spec gaps fixed: #1 canonicalize undefined → deepSortedJson() recursive key-sort #5 cache key raw concat → JSON.stringify([...]) structured array
- automation.audit.evaluate_trace records per-evaluation decisions - llm: condition type gates rules on LLM yes/no judgement (cache, budget, on_error) - rules trace-explain: inspect why a rule fired or was blocked - rules simulate: replay historical events against a rule offline - MCP: rules_explain + rules_simulate tools - 2204 tests (+245)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
automation.audit.evaluate_tracerecords per-evaluation condition breakdown, LLM results, and throttle state to the audit logllm:) — gates rule execution on an AI yes/no judgement with cache, budget, andon_errorcontrolsrules trace-explain— inspect why a specific rule evaluation fired or was blocked (by fire ID, rule name, or time window)rules simulate— replay historical events against a rule offline without starting the live enginerules_explain+rules_simulateadded to the MCP serverTest plan
npm test— 2204 tests passswitchbot rules trace-explain --rule <name> --last— returns trace record after running engine withevaluate_trace: sampledswitchbot rules simulate <rule>— reports would-fire / blocked counts from audit logllm:condition fires correctly when LLM returns yes; blocked when norules lintflags LLM condition with missing provider keyrules_explainandrules_simulatetools respond correctly viaswitchbot mcp serve