From 70c04d9e94023fd0f3513cb605760c2ffe0f03e5 Mon Sep 17 00:00:00 2001 From: tfarcraw <123211521@163.com> Date: Thu, 19 Nov 2026 01:22:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=85=A5=E9=99=90=E6=97=B6=E5=A4=8D?= =?UTF-8?q?=E6=A3=80=E7=95=8C=E9=9D=A2=E5=B9=B6=E5=8C=BA=E5=88=86=E8=B7=B3?= =?UTF-8?q?=E8=BF=87=E4=B8=8E=E6=95=B4=E8=BD=AE=E5=90=88=E6=A0=BC=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Training/SopVideoFlowTest.cs | 13 ++++---- .../VVMs/RecipeEditor/EditorNodes.cs | 8 +++++ .../VVMs/RecipeEditor/RecipeEditor.axaml | 9 ++++++ .../RecipeEditor/SopVideoAgentViewModel.cs | 3 +- .../VVMs/SopPage/SopPage.axaml | 1 + .../VVMs/SopPage/SopPageViewModel.cs | 10 ++++--- .../Sop/SopEngine.ContinuousChecks.cs | 30 +++++++++++++++---- .../Sop/VisionDecision.cs | 6 ++-- .../SopAgent/SopDraftVerification.cs | 2 +- .../SopAgent/SopStepDesignPrompt.cs | 1 + .../SopAgent/SopVideoDraftClient.cs | 2 +- tests/VideoFlowTest.Smoke/Program.cs | 7 ++++- .../SequenceTrialChecks.cs | 3 +- .../ContinuousCheckTests.cs | 10 +++++++ 14 files changed, 83 insertions(+), 22 deletions(-) diff --git a/src/SopHelper.Avalonia/Training/SopVideoFlowTest.cs b/src/SopHelper.Avalonia/Training/SopVideoFlowTest.cs index 62451cc..3beb2ab 100644 --- a/src/SopHelper.Avalonia/Training/SopVideoFlowTest.cs +++ b/src/SopHelper.Avalonia/Training/SopVideoFlowTest.cs @@ -28,14 +28,15 @@ public sealed class SopVideoFlowTest : IDisposable public event Action? DecisionEvaluated; public IReadOnlyList StepResults { - get { lock (_gate) return _steps.Values.OrderBy(s => s.StepId).Select(s => new SopHelper.Engine.SopAgent.SopDraftVerificationStep(s.StepId, s.Name, s.IsMet, s.Message)).ToArray(); } + get { lock (_gate) return _steps.Values.OrderBy(s => s.StepId).Select(s => new SopHelper.Engine.SopAgent.SopDraftVerificationStep(s.StepId, s.Name, s.IsMet, s.Message, s.IsSkipped)).ToArray(); } } - public bool IsCompleted => _engine.State == EngineState.Completed; + public bool IsCompleted => _engine.RoundPassed; + public bool IsFinished => _engine.State == EngineState.Completed; public IReadOnlyDictionary Regions => _engine.Config.Sop.Regions; public string Details { get { lock (_gate) return string.Join(Environment.NewLine, _steps.Values.OrderBy(s => s.StepId) - .Select(s => $"{(s.IsMet ? "✓" : s.IsCurrent ? "▶" : "○")} {s.StepId} {s.Name}:{s.Message}" + .Select(s => $"{(s.IsMet ? "✓" : s.IsSkipped ? "✕" : s.IsCurrent ? "▶" : "○")} {s.StepId} {s.Name}:{s.Message}" + (!s.IsMet && _lastAiFailures.TryGetValue(s.StepId, out var failure) && failure != s.Message ? $"(最近判定:{failure})" : ""))); } } public string Progress { get { lock (_gate) return $"已完成 {_steps.Values.Count(s => s.IsMet)}/{_steps.Count} 步"; } } @@ -55,12 +56,13 @@ public sealed class SopVideoFlowTest : IDisposable _engine.DecisionEvaluated += (request, result, accepted) => DecisionEvaluated?.Invoke(request, result, accepted); _engine.StepSnapshotChanged += step => { - if (_steps.TryGetValue(step.StepId, out var previous) && previous.IsMet && !step.IsMet) return; + if (_steps.TryGetValue(step.StepId, out var previous) && (previous.IsMet || previous.IsSkipped) && !step.IsMet && !step.IsSkipped) return; _steps[step.StepId] = step; if (step.Message.StartsWith("AI 未确认完成")) _lastAiFailures[step.StepId] = step.Message; Changed?.Invoke(IsCompleted ? $"流程检测通过,{Progress}" : $"正在测试流程,{Progress}", Details); }; - _engine.Completed += () => Changed?.Invoke($"流程检测通过,{Progress}", Details); + _engine.RoundStarted += () => { _steps.Clear(); _lastAiFailures.Clear(); }; + _engine.RoundFinished += passed => Changed?.Invoke(passed ? $"流程检测通过,{Progress}" : $"本轮结束,有步骤未通过并跳过,{Progress}", Details); _engine.Load(snapshot); } @@ -124,6 +126,7 @@ public sealed class SopVideoFlowTest : IDisposable { lock (_gate) return IsCompleted ? $"{reason};流程检测通过,{Progress}" + : IsFinished ? $"{reason};本轮结束,有步骤未通过并跳过,{Progress}" : $"{reason};流程未完成,{Progress},停在步骤 {_engine.CurrentStep?.Id}「{_engine.CurrentStep?.Name}」"; } diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs b/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs index 672b3b0..b53ac7b 100644 --- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs +++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/EditorNodes.cs @@ -424,6 +424,7 @@ public class RecipeNode : EditorNode AiConfirmation = step.AiConfirmation is null ? null : new AiConfirmation { MinConfidence = step.AiConfirmation.MinConfidence, + CheckWindowMs = step.AiConfirmation.CheckWindowMs, MaxChecks = step.AiConfirmation.MaxChecks, CheckSettleMs = step.AiConfirmation.CheckSettleMs, EvidenceMode = step.AiConfirmation.EvidenceMode, ObservationPreRollMs = step.AiConfirmation.ObservationPreRollMs, ObservationMinMs = step.AiConfirmation.ObservationMinMs, ObservationMaxMs = step.AiConfirmation.ObservationMaxMs, ObservationSampleMs = step.AiConfirmation.ObservationSampleMs, @@ -492,6 +493,7 @@ public class RecipeNode : EditorNode AiConfirmation = new AiConfirmation { MinConfidence = step.AiMinConfidence, + CheckWindowMs = step.AiCheckWindowMs, MaxChecks = step.AiMaxChecks, CheckSettleMs = step.AiCheckSettleMs, EvidenceMode = step.AiEvidenceMode, ObservationPreRollMs = step.AiObservationPreRollMs, ObservationMinMs = step.AiObservationMinMs, ObservationMaxMs = step.AiObservationMaxMs, ObservationSampleMs = step.AiObservationSampleMs, ObservationMaxFrames = step.AiObservationMaxFrames, @@ -778,6 +780,11 @@ public class RegionNode : EditorNode /// public class StepNode : EditorNode { + private int _aiCheckWindowMs, _aiMaxChecks = 3, _aiCheckSettleMs = 350; + public int AiCheckWindowMs { get => _aiCheckWindowMs; set { if (SetProperty(ref _aiCheckWindowMs, value)) RaisePropertyChanged(nameof(AiContinueAfterWindow)); } } + public bool AiContinueAfterWindow { get => AiCheckWindowMs > 0; set { if (value != AiContinueAfterWindow) AiCheckWindowMs = value ? 10000 : 0; } } + public int AiMaxChecks { get => _aiMaxChecks; set => SetProperty(ref _aiMaxChecks, value); } + public int AiCheckSettleMs { get => _aiCheckSettleMs; set => SetProperty(ref _aiCheckSettleMs, value); } private string _aiEvidenceMode = VisionEvidenceMode.SingleFrame; private int _aiObservationPreRollMs = 1000, _aiObservationMinMs = 2400, _aiObservationMaxMs = 10000, _aiObservationSampleMs = 400, _aiObservationMaxFrames = 24; @@ -815,6 +822,7 @@ public class StepNode : EditorNode { if (value is null) return; AiMinConfidence = value.MinConfidence; + AiCheckWindowMs = value.CheckWindowMs; AiMaxChecks = value.MaxChecks; AiCheckSettleMs = value.CheckSettleMs; AiEvidenceMode = value.EvidenceMode; AiObservationPreRollMs = value.ObservationPreRollMs; AiObservationMinMs = value.ObservationMinMs; AiObservationMaxMs = value.ObservationMaxMs; AiObservationSampleMs = value.ObservationSampleMs; AiObservationMaxFrames = value.ObservationMaxFrames; diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml b/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml index 69f5209..cf2b8cc 100644 --- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml +++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/RecipeEditor.axaml @@ -150,6 +150,15 @@ + + + + + + + + + diff --git a/src/SopHelper.Avalonia/VVMs/RecipeEditor/SopVideoAgentViewModel.cs b/src/SopHelper.Avalonia/VVMs/RecipeEditor/SopVideoAgentViewModel.cs index 59b3e01..d8d2cec 100644 --- a/src/SopHelper.Avalonia/VVMs/RecipeEditor/SopVideoAgentViewModel.cs +++ b/src/SopHelper.Avalonia/VVMs/RecipeEditor/SopVideoAgentViewModel.cs @@ -418,7 +418,8 @@ public partial class RecipeEditorViewModel var existing = index < _agentAppliedNodes.Count ? _agentAppliedNodes[index] : null; return new SopAgentImageScope(index + 1, existing?.AiImageMode ?? VisionImageMode.FixedRegion, existing?.AiImageRegion ?? (row.Step.Method == ConditionMethod.HandMove ? row.Step.ToRegion : row.Step.Region), - existing?.AiHandPadding ?? 160, existing?.AiHandMinSize ?? 320, existing?.AiHandMemoryMs ?? 3000, existing?.AiEvidenceMode ?? VisionEvidenceMode.SingleFrame); + existing?.AiHandPadding ?? 160, existing?.AiHandMinSize ?? 320, existing?.AiHandMemoryMs ?? 3000, existing?.AiEvidenceMode ?? VisionEvidenceMode.SingleFrame, + existing?.AiCheckWindowMs ?? 0, existing?.AiMaxChecks ?? 3, existing?.AiCheckSettleMs ?? 350); }).ToArray(); private void ClearAgentConversation() { _agentPromptSession = null; _agentConversation.Clear(); AgentChatMessages.Clear(); } diff --git a/src/SopHelper.Avalonia/VVMs/SopPage/SopPage.axaml b/src/SopHelper.Avalonia/VVMs/SopPage/SopPage.axaml index 81ea240..034fa19 100644 --- a/src/SopHelper.Avalonia/VVMs/SopPage/SopPage.axaml +++ b/src/SopHelper.Avalonia/VVMs/SopPage/SopPage.axaml @@ -124,6 +124,7 @@ + diff --git a/src/SopHelper.Avalonia/VVMs/SopPage/SopPageViewModel.cs b/src/SopHelper.Avalonia/VVMs/SopPage/SopPageViewModel.cs index 10b0d73..c74edc0 100644 --- a/src/SopHelper.Avalonia/VVMs/SopPage/SopPageViewModel.cs +++ b/src/SopHelper.Avalonia/VVMs/SopPage/SopPageViewModel.cs @@ -128,7 +128,7 @@ public class SopPageViewModel : ViewModelBase _engine.ViolationRaised += violation => _dispatcher.BeginInvoke(() => AppendViolation(violation)); _engine.StepSnapshotChanged += OnStepSnapshot; _engine.RoundStarted += OnRoundStarted; - _engine.Completed += OnCompleted; + _engine.RoundFinished += OnRoundFinished; LoadRecipes(); @@ -441,7 +441,7 @@ public class SopPageViewModel : ViewModelBase { _statisticsTimer.Stop(); _engine.Stop(); - _engine.Completed -= OnCompleted; + _engine.RoundFinished -= OnRoundFinished; _camera.FrameArrived -= OnCameraFrame; _pipeline.ResultFrameArrived -= OnResultFrame; _engine.StepSnapshotChanged -= OnStepSnapshot; @@ -871,7 +871,7 @@ public class SopPageViewModel : ViewModelBase else _dispatcher.BeginInvoke(() => { if (!_destroyed) { ClearProcessImages(); RefreshStatistics(); } }); } - private void OnCompleted() => _dispatcher.BeginInvoke(() => { if (!_destroyed) { StatusText = "本轮完成"; RefreshStatistics(); } }); + private void OnRoundFinished(bool passed) => _dispatcher.BeginInvoke(() => { if (!_destroyed) { StatusText = passed ? "本轮完成,全部通过" : "本轮结束,有步骤未通过并跳过"; RefreshStatistics(); } }); private void RefreshStatistics() { @@ -977,6 +977,7 @@ public class SopPageViewModel : ViewModelBase card.IsCurrent = snapshot.IsCurrent; card.IsMet = snapshot.IsMet; + card.IsSkipped = snapshot.IsSkipped; card.Message = snapshot.Message; if (snapshot.Elapsed is { } elapsed) card.ElapsedText = FormatDuration(elapsed); using var aiEvidence = snapshot.IsMet && snapshot.EvidenceJpeg is { } jpeg @@ -1079,7 +1080,8 @@ public class StepCard : ViewModelBase public bool IsWaitingForImage => !HasCompletionImage; private bool _isCurrent; - private bool _isMet; + private bool _isMet, _isSkipped; + public bool IsSkipped { get => _isSkipped; set => SetProperty(ref _isSkipped, value); } private string _message = ""; /// 步骤 Id diff --git a/src/SopHelper.CrossPlatform.Engine/Sop/SopEngine.ContinuousChecks.cs b/src/SopHelper.CrossPlatform.Engine/Sop/SopEngine.ContinuousChecks.cs index f1a30c5..db9c740 100644 --- a/src/SopHelper.CrossPlatform.Engine/Sop/SopEngine.ContinuousChecks.cs +++ b/src/SopHelper.CrossPlatform.Engine/Sop/SopEngine.ContinuousChecks.cs @@ -17,8 +17,8 @@ public partial class SopEngine ObservationMaxMs = Math.Max(step.AiConfirmation.ObservationMaxMs, step.AiConfirmation.CheckWindowMs), ObservationMaxFrames = step.AiConfirmation.ObservationMaxFrames, }); - public bool Triggered; - public long LastFrame = -1, StartedAt, LastSubmittedAt, FinishedAt; + public bool Triggered, SawQuiet; + public long LastFrame = -1, SentFrame = -1, StartedAt, LastSubmittedAt, FinishedAt; public double TriggerSeconds, LatestSeconds, LastMotionSeconds; public int Attempts, SentVersion; public Dictionary Anchors = []; @@ -39,6 +39,7 @@ public partial class SopEngine Func? capture, Func? crop) { if (capture is null && crop is null || state.LastFrame == frame.FrameId) return; + var firstObservation = state.LastFrame == -1; state.LastFrame = frame.FrameId; var seconds = frame.SourceSeconds ?? (frame.Timestamp - DateTime.UnixEpoch).TotalSeconds; state.LatestSeconds = seconds; @@ -49,11 +50,20 @@ public partial class SopEngine _ => true, }).GroupBy(h => h.HandType).ToDictionary(g => g.Key, g => ((double)g.First().Center.Cx, (double)g.First().Center.Cy)); var movement = Math.Max(1, Math.Sqrt((double)frame.Size.W * frame.Size.W + (double)frame.Size.H * frame.Size.H) * .01); - if (selected.Count != state.Anchors.Count || selected.Any(h => !state.Anchors.TryGetValue(h.Key, out var prior) - || Math.Sqrt(Math.Pow(h.Value.Item1 - prior.X, 2) + Math.Pow(h.Value.Item2 - prior.Y, 2)) > movement)) + var moved = selected.Count != state.Anchors.Count || selected.Any(h => !state.Anchors.TryGetValue(h.Key, out var prior) + || Math.Sqrt(Math.Pow(h.Value.Item1 - prior.X, 2) + Math.Pow(h.Value.Item2 - prior.Y, 2)) > movement); + if (!state.Triggered && state.Gate.RequireRelease && state.SawQuiet && moved && selected.Count > 0) + { + // 连续工序可以始终位于同一操作区;“停稳后重新运动”也是新动作边界。 + state.Gate.RequireRelease = false; state.Gate.Evaluator.Reset(); + Log("info", $"步骤 {state.Step.Id} 检测到停稳后的新运动,重新启用区域触发"); + } + if (firstObservation || moved) { state.LastMotionSeconds = seconds; state.Anchors = selected; } + else if ((seconds - state.LastMotionSeconds) * 1000 >= state.Step.AiConfirmation!.CheckSettleMs) + state.SawQuiet = true; var trigger = EvaluateCaptureGate(state.Step, frame, state.Gate, "continuous"); if (!state.Triggered && trigger.IsMet) { @@ -122,7 +132,15 @@ public partial class SopEngine var timeToCheck = state.Attempts == 0 ? quiet || sinceRequest >= interval : sinceRequest >= interval; var frames = state.Window.Frames.Where(f => !_acceptedEvidenceTimes.TryGetValue(_index - 1, out var prior) || ObservationEvidenceWindow.Time(f) >= prior).ToArray(); - if (!timeToCheck || state.Window.Version <= state.SentVersion || frames.Length == 0 + if (!timeToCheck) return new() { Message = $"等待下一次检查时机(已送检 {state.Attempts}/{options.MaxChecks} 次)" }; + if (options.EvidenceMode == VisionEvidenceMode.SingleFrame && (capture is not null || crop is not null)) + { + // 停稳事件可能处于抽样间隔之间;单帧检查必须取该事件当下的图。 + var current = CaptureDecision(step, frame, state.Gate.HandRegion, capture, crop, out _, notify: false); + if (current is not null) frames = [new(frame.FrameId, frame.Timestamp, current.Request.Jpeg, frame.SourceSeconds)]; + } + if (frames.Length == 0 || frames[^1].FrameId == state.SentFrame + || options.EvidenceMode == VisionEvidenceMode.Sequence && state.Window.Version <= state.SentVersion || options.EvidenceMode == VisionEvidenceMode.Sequence && (frames.Length < 3 || !state.Window.Ready)) return new() { Message = $"窗口内观察,优先在手部停稳或离开后检查(已送检 {state.Attempts}/{options.MaxChecks} 次)" }; var last = frames[^1]; @@ -131,7 +149,7 @@ public partial class SopEngine options.EvidenceMode == VisionEvidenceMode.Sequence ? frames : null, last.SourceSeconds); var remaining = Math.Max(1, options.CheckWindowMs - state.ElapsedMs); var cancellation = new CancellationTokenSource(TimeSpan.FromMilliseconds(Math.Min(options.TimeoutSeconds * 1000d, remaining))); - state.Attempts++; state.SentVersion = state.Window.Version; state.LastSubmittedAt = Environment.TickCount64; + state.Attempts++; state.SentVersion = state.Window.Version; state.SentFrame = last.FrameId; state.LastSubmittedAt = Environment.TickCount64; state.FinishedAt = long.MaxValue; async Task CheckAsync() { diff --git a/src/SopHelper.CrossPlatform.Engine/Sop/VisionDecision.cs b/src/SopHelper.CrossPlatform.Engine/Sop/VisionDecision.cs index af82b75..25a6242 100644 --- a/src/SopHelper.CrossPlatform.Engine/Sop/VisionDecision.cs +++ b/src/SopHelper.CrossPlatform.Engine/Sop/VisionDecision.cs @@ -33,9 +33,11 @@ public static class VisionEvidenceMode public const string SingleFrame = "single_frame", Sequence = "sequence"; public static bool IsCheckPolicyValid(AiConfirmation options) => options.CheckWindowMs == 0 || options.CheckWindowMs is >= 500 and <= 60000 && options.MaxChecks is >= 1 and <= 20 - && options.CheckSettleMs is >= 100 and <= 3000 && options.CheckSettleMs < options.CheckWindowMs; + && options.CheckSettleMs is >= 100 and <= 3000 && options.CheckSettleMs < options.CheckWindowMs + && IsObservationValid(options); public static bool IsValid(AiConfirmation options) => options.EvidenceMode == SingleFrame - || options.EvidenceMode == Sequence && options.ObservationPreRollMs is >= 0 and <= 5000 + || options.EvidenceMode == Sequence && IsObservationValid(options); + private static bool IsObservationValid(AiConfirmation options) => options.ObservationPreRollMs is >= 0 and <= 5000 && options.ObservationMinMs is >= 200 and <= 30000 && options.ObservationMaxMs >= options.ObservationMinMs && options.ObservationMaxMs <= 60000 && options.ObservationSampleMs is >= 100 and <= 2000 && options.ObservationMaxFrames is >= 3 and <= 32; diff --git a/src/SopHelper.CrossPlatform.Engine/SopAgent/SopDraftVerification.cs b/src/SopHelper.CrossPlatform.Engine/SopAgent/SopDraftVerification.cs index f30c59b..3f43644 100644 --- a/src/SopHelper.CrossPlatform.Engine/SopAgent/SopDraftVerification.cs +++ b/src/SopHelper.CrossPlatform.Engine/SopAgent/SopDraftVerification.cs @@ -5,7 +5,7 @@ using SopHelper.Engine.Sop; namespace SopHelper.Engine.SopAgent; -public sealed record SopDraftVerificationStep(int Id, string Name, bool Completed, string Message); +public sealed record SopDraftVerificationStep(int Id, string Name, bool Completed, string Message, bool Skipped = false); public sealed record SopDraftVerificationImage(int StepId, long FrameId, double Seconds, string Scope, double? Confidence, bool? Accepted, string Reason, [property: JsonIgnore] byte[] Jpeg, string EvidenceMode = VisionEvidenceMode.SingleFrame, diff --git a/src/SopHelper.CrossPlatform.Engine/SopAgent/SopStepDesignPrompt.cs b/src/SopHelper.CrossPlatform.Engine/SopAgent/SopStepDesignPrompt.cs index b3ad45d..7da9019 100644 --- a/src/SopHelper.CrossPlatform.Engine/SopAgent/SopStepDesignPrompt.cs +++ b/src/SopHelper.CrossPlatform.Engine/SopAgent/SopStepDesignPrompt.cs @@ -15,6 +15,7 @@ public static class SopStepDesignPrompt - 相邻步骤应有可区分的可见变化,前一步结果不应直接满足后一步判据。 触发与取图: + - step_image_context 的 CheckWindowMs>0 表示连续操作限时复检:事件开启窗口,优先在手停稳/离开后检查,失败使用新画面重试,到期未确认会记录未通过并跳过继续。跳过不等于完成;不能通过放宽判据来掩盖跳过,也不能要求操作员等待模型返回。手部触发区应对应本步实际操作,不宜扩大到无关动作区域。 - method 只决定取图时机,不证明完成。选择结果已形成且关键部位尽量无遮挡的时机,不机械地统一规则。 - hand_in_region:指定手中心在主区域内达到稳定帧数,停留时仍可重试;不能把进入区域当作完成证据。 - hand_leave_region:先检测指定手接触主区域,再等区域内不再检测到匹配手。 diff --git a/src/SopHelper.CrossPlatform.Engine/SopAgent/SopVideoDraftClient.cs b/src/SopHelper.CrossPlatform.Engine/SopAgent/SopVideoDraftClient.cs index 4e9fabb..0bb3149 100644 --- a/src/SopHelper.CrossPlatform.Engine/SopAgent/SopVideoDraftClient.cs +++ b/src/SopHelper.CrossPlatform.Engine/SopAgent/SopVideoDraftClient.cs @@ -20,7 +20,7 @@ public sealed record SopVideoAnalysisRequest(string Recipe, string Instructions, public sealed record SopAgentPrompt(int Round, long EstimatedTokens, int ContextLength, string Compression, string Text); public sealed record SopAgentTrace(string Kind, int Round, string Text, IReadOnlyList? Images = null); public sealed record SopAgentTraceImage(string Name, byte[] Jpeg); -public sealed record SopAgentImageScope(int StepIndex, string Mode, string Region, int HandPadding, int HandMinSize, int HandMemoryMs, string EvidenceMode = VisionEvidenceMode.SingleFrame); +public sealed record SopAgentImageScope(int StepIndex, string Mode, string Region, int HandPadding, int HandMinSize, int HandMemoryMs, string EvidenceMode = VisionEvidenceMode.SingleFrame, int CheckWindowMs = 0, int MaxChecks = 3, int CheckSettleMs = 350); public sealed record SopAgentChatTurn(string Role, string Text); public sealed record SopAgentChatResult(string Reply, SopVideoDraft? Draft, IReadOnlyList ObservedFrames); public sealed class SopVideoDraft diff --git a/tests/VideoFlowTest.Smoke/Program.cs b/tests/VideoFlowTest.Smoke/Program.cs index f645305..6dbe65f 100644 --- a/tests/VideoFlowTest.Smoke/Program.cs +++ b/tests/VideoFlowTest.Smoke/Program.cs @@ -49,12 +49,17 @@ internal static class Program { var config = new SopConfig(); config.Sop.Steps.Add(new() { Id = 1, Description = "状态变化", AiConfirmation = new() - { EvidenceMode = VisionEvidenceMode.Sequence, ObservationMinMs = 1800, ObservationMaxFrames = 13, ObservationSampleMs = 300 } }); + { EvidenceMode = VisionEvidenceMode.Sequence, ObservationMinMs = 1800, ObservationMaxFrames = 13, ObservationSampleMs = 300, + CheckWindowMs = 7000, MaxChecks = 4, CheckSettleMs = 450 } }); var editor = RecipeNode.From(config, "试验.yaml", false); Check(editor.Steps[0].UsesSequenceEvidence, "编辑器须识别过程时序模式"); var restored = SopConfigLoader.Parse(SopConfigLoader.ToYaml(editor.ToConfig())).Sop.Steps[0].AiConfirmation!; Check(restored.EvidenceMode == VisionEvidenceMode.Sequence && restored.ObservationMinMs == 1800 && restored.ObservationMaxFrames == 13 && restored.ObservationSampleMs == 300, "编辑保存不得丢失时序模式与窗口参数"); + Check(editor.Steps[0].AiContinueAfterWindow && restored.CheckWindowMs == 7000 && restored.MaxChecks == 4 + && restored.CheckSettleMs == 450, "编辑保存须保留连续操作限时复检参数"); + editor.Steps[0].AiContinueAfterWindow = false; + Check(editor.ToConfig().Sop.Steps[0].AiConfirmation!.CheckWindowMs == 0, "关闭限时复检须恢复原等待策略"); Console.WriteLine("PASS: 编辑器过程时序模式及观察参数往返保留"); } diff --git a/tests/VideoFlowTest.Smoke/SequenceTrialChecks.cs b/tests/VideoFlowTest.Smoke/SequenceTrialChecks.cs index 27006c6..2262248 100644 --- a/tests/VideoFlowTest.Smoke/SequenceTrialChecks.cs +++ b/tests/VideoFlowTest.Smoke/SequenceTrialChecks.cs @@ -69,7 +69,8 @@ internal static class SequenceTrialChecks File.WriteAllText(Path.Combine(reportPath, "result.json"), JsonSerializer.Serialize(new { Config = configPath, Video = videoPath, StopSeconds = double.IsFinite(stopSeconds) ? (double?)stopSeconds : null, - Completed = test.IsCompleted, Summary = summary, test.Details, Observed = observed, LatestSeconds = latestSeconds, + Completed = test.IsCompleted, Finished = test.IsFinished, Steps = test.StepResults, + Summary = summary, test.Details, Observed = observed, LatestSeconds = latestSeconds, WallSeconds = watch.Elapsed.TotalSeconds, Requests = requests, Verdicts = verdicts, Triggers = triggers, ConfigUnchanged = original.SequenceEqual(File.ReadAllBytes(configPath)) }, new JsonSerializerOptions { WriteIndented = true })); diff --git a/tests/VisionDecision.Smoke/ContinuousCheckTests.cs b/tests/VisionDecision.Smoke/ContinuousCheckTests.cs index 8c8cd2a..31863d7 100644 --- a/tests/VisionDecision.Smoke/ContinuousCheckTests.cs +++ b/tests/VisionDecision.Smoke/ContinuousCheckTests.cs @@ -77,6 +77,16 @@ internal static class ContinuousCheckTests timed.ProcessFrame(Frame(5, 2.1, 120)); await Until(() => slow.Calls.Count == 2); Check(timed.CurrentStep?.Id == 2 && timed.SkippedSteps.Contains(1), "已跳过步骤的迟到结果不能放行后续步骤"); timed.Stop(); Check(!timed.HasPendingDecision, "停止必须取消限时检查和未来步骤缓存"); + var sameRegion = Config(); sameRegion.Sop.Steps[1].Detection!.Region = "r0"; + var same = new SopEngine { VisionDecisionClient = new Client() }; same.Load(sameRegion); same.Start(); + var secondTriggered = false; + same.TriggerEvaluated += (id, _, result, _) => { if (id == 2 && result.IsMet) secondTriggered = true; }; + void SameFeed(int id, double seconds, int x) => same.ProcessFrame(Frame(id, seconds, x), () => [(byte)id]); + SameFeed(1, 0, 10); SameFeed(2, .1, 10); SameFeed(3, .3, 10); + Check(!secondTriggered, "同区域持续停留不得直接触发下一步"); + SameFeed(4, .5, 35); + Check(secondTriggered, "同区域停稳后开始新运动,应能触发下一步,不能强求手离开操作区"); + same.Stop(); Console.WriteLine("PASS: 停稳触发、新帧重试、限时跳过、后续动作持续取证、挂起硬截止、迟到结果隔离和非合格整轮统计"); } }