image.domain\self_evolve\auto_decide.mbt

70.6% · 24 / 34 points · 134 lines

Background color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.

  1. 1///|
  2. 2/// # 自动决策 self_evolve/auto_decide
  3. 3///
  4. 4/// 图像处理库子模块
  5. 5/// 图像处理库子模块 Image processing library submodule
  6. 6// 自主决策引擎 — 根据预测结果自主决策演化方向
  7. 7// Autonomous decision engine: decide evolution direction based on predictions
  8. 8//
  9. 9// Phase 10 v306: 将演化从"预测"推向"自主决策" — 根据预测结果自动决定演化动作。
  10. 10
  11. 11///|
  12. 12/// 决策动作类型。
  13. 13/// 描述 Decision action type.
  14. 14/// `#non_exhaustive` 表示未来可能添加新构造器
  15. 15#derive(Eq, @debug.Debug)
  16. 16#non_exhaustive
  17. 17pub(all) enum DecisionAction {
  18. 18 EvolveNow
  19. 19 DeferEvolution
  20. 20 SkipEvolution
  21. 21 EscalateToManual
  22. 22}
  23. 23
  24. 24///|
  25. 25pub extend DecisionAction with @debug.Debug::{to_repr}
  26. 26
  27. 27///|
  28. 28pub extend DecisionAction with Eq::{not_equal, equal}
  29. 29
  30. 30///|
  31. 31/// 单算子自主决策。
  32. 32/// 描述 Autonomous decision for a single op.
  33. 33#derive(Eq, @debug.Debug)
  34. 34pub(all) struct AutoDecision {
  35. 35 op_tag : String
  36. 36 action : DecisionAction
  37. 37 confidence : Int32
  38. 38 rationale : String
  39. 39}
  40. 40
  41. 41///|
  42. 42pub extend AutoDecision with @debug.Debug::{to_repr}
  43. 43
  44. 44///|
  45. 45pub extend AutoDecision with Eq::{not_equal, equal}
  46. 46
  47. 47///|
  48. 48/// 决策报告。
  49. 49/// 描述 Decision report.
  50. 50#derive(Eq, @debug.Debug)
  51. 51pub(all) struct DecisionReport {
  52. 52 decisions : Array[AutoDecision]
  53. 53 total : Int32
  54. 54 auto_count : Int32
  55. 55 deferred_count : Int32
  56. 56 summary : String
  57. 57}
  58. 58
  59. 59///|
  60. 60pub extend DecisionReport with @debug.Debug::{to_repr}
  61. 61
  62. 62///|
  63. 63pub extend DecisionReport with Eq::{not_equal, equal}
  64. 64
  65. 65///|
  66. 66/// 为单个算子做自主决策。
  67. 67/// 描述 Make autonomous decision for a single op.
  68. 68pub fn decide_op(op : @imgir.IROp) -> AutoDecision {
  69. 69● let tag = op.tag()
  70. 70● let pred = predict_op(op)
  71. 71
  72. 72● let action = match pred.kind {
  73. 73○ HighRisk => if pred.confidence >= 80 { EvolveNow } else { EscalateToManual }
  74. 74 DegradationLikely =>
  75. 75● if pred.confidence >= 60 {
  76. 76● EvolveNow
  77. 77 } else {
  78. 78○ DeferEvolution
  79. 79 }
  80. 80● TestGrowthExpected => DeferEvolution
  81. 81○ StableOp => SkipEvolution
  82. 82 }
  83. 83● let rationale = match action {
  84. 84 EvolveNow =>
  85. 85● tag + " 立即演化: 预测 " + pred.confidence.to_string() + "% 置信"
  86. 86● DeferEvolution => tag + " 推迟演化: 预期改善,非紧急"
  87. 87○ SkipEvolution => tag + " 跳过演化: 稳定无风险"
  88. 88 EscalateToManual =>
  89. 89○ tag +
  90. 90 " 升级人工: 置信度不足 (" +
  91. 91○ pred.confidence.to_string() +
  92. 92 "%)"
  93. 93 }
  94. 94 { op_tag: tag, action, confidence: pred.confidence, rationale, }
  95. 95}
  96. 96
  97. 97///|
  98. 98/// 为所有算子做自主决策。
  99. 99/// 描述 Make autonomous decisions for all ops.
  100. 100pub fn decide_all() -> DecisionReport {
  101. 101● let decisions : Array[AutoDecision] = []
  102. 102 let mut auto_count = 0
  103. 103 let mut deferred_count = 0
  104. 104● for op in all_ops() {
  105. 105● let d = decide_op(op)
  106. 106 if d.action is EvolveNow {
  107. 107○ auto_count = auto_count + 1
  108. 108● } else if d.action is DeferEvolution {
  109. 109● deferred_count = deferred_count + 1
  110. 110 }
  111. 111● decisions.push(d)
  112. 112 }
  113. 113● let total = decisions.length()
  114. 114 let summary = "自主决策: " +
  115. 115● total.to_string() +
  116. 116 " 算子, " +
  117. 117● auto_count.to_string() +
  118. 118 " 自主演化, " +
  119. 119● deferred_count.to_string() +
  120. 120 " 推迟"
  121. 121 { decisions, total, auto_count, deferred_count, summary, }
  122. 122}
  123. 123
  124. 124///|
  125. 125/// 决策报告是否可以全自主执行(无人工升级)。
  126. 126/// 描述 Whether decision report can be fully auto-run (no manual escalation).
  127. 127pub fn DecisionReport::can_auto_run(self : DecisionReport) -> Bool {
  128. 128● for d in self.decisions {
  129. 129● if d.action is EscalateToManual {
  130. 130○ return false
  131. 131 }
  132. 132 }
  133. 133 true
  134. 134}