self-evolving-workflow 0.0.0-stage → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +27 -0
- package/README.md +90 -2
- package/dist/agent-memory-prompts.d.ts +13 -0
- package/dist/agent-memory-prompts.js +55 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +6 -0
- package/dist/closeout.d.ts +105 -0
- package/dist/closeout.js +479 -0
- package/dist/code.d.ts +39 -0
- package/dist/code.js +124 -0
- package/dist/common.d.ts +9 -0
- package/dist/common.js +42 -0
- package/dist/context-envelope.d.ts +59 -0
- package/dist/context-envelope.js +23 -0
- package/dist/host-adapters.d.ts +34 -0
- package/dist/host-adapters.js +151 -0
- package/dist/http.d.ts +3 -0
- package/dist/http.js +90 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +13 -0
- package/dist/knowledge-cli.d.ts +183 -0
- package/dist/knowledge-cli.js +654 -0
- package/dist/knowledge-reads.d.ts +71 -0
- package/dist/knowledge-reads.js +193 -0
- package/dist/memory.d.ts +97 -0
- package/dist/memory.js +250 -0
- package/dist/retrospective.d.ts +57 -0
- package/dist/retrospective.js +248 -0
- package/dist/search.d.ts +36 -0
- package/dist/search.js +112 -0
- package/dist/skill-addition.d.ts +25 -0
- package/dist/skill-addition.js +89 -0
- package/dist/skill-design.d.ts +96 -0
- package/dist/skill-design.js +226 -0
- package/dist/skill-replay.d.ts +55 -0
- package/dist/skill-replay.js +451 -0
- package/dist/skill-route.d.ts +30 -0
- package/dist/skill-route.js +75 -0
- package/dist/transcript-evidence.d.ts +3 -0
- package/dist/transcript-evidence.js +58 -0
- package/dist/upstream/chunker.d.ts +24 -0
- package/dist/upstream/chunker.js +96 -0
- package/dist/upstream/file-protocol.d.ts +45 -0
- package/dist/upstream/file-protocol.js +117 -0
- package/dist/upstream/frontmatter.d.ts +47 -0
- package/dist/upstream/frontmatter.js +86 -0
- package/dist/upstream/graph-search.d.ts +33 -0
- package/dist/upstream/graph-search.js +67 -0
- package/dist/upstream/l1-extraction.d.ts +26 -0
- package/dist/upstream/l1-extraction.js +405 -0
- package/dist/upstream/llm.d.ts +8 -0
- package/dist/upstream/llm.js +1 -0
- package/dist/upstream/merge.d.ts +50 -0
- package/dist/upstream/merge.js +153 -0
- package/dist/upstream/prompts.d.ts +53 -0
- package/dist/upstream/prompts.js +185 -0
- package/dist/upstream/search-utils.d.ts +34 -0
- package/dist/upstream/search-utils.js +55 -0
- package/dist/upstream/slug.d.ts +26 -0
- package/dist/upstream/slug.js +103 -0
- package/dist/upstream/template.d.ts +29 -0
- package/dist/upstream/template.js +80 -0
- package/dist/upstream/tokenize.d.ts +4 -0
- package/dist/upstream/tokenize.js +29 -0
- package/dist/wiki-change.d.ts +76 -0
- package/dist/wiki-change.js +299 -0
- package/dist/wiki-entry.d.ts +26 -0
- package/dist/wiki-entry.js +93 -0
- package/dist/wiki-ingest.d.ts +12 -0
- package/dist/wiki-ingest.js +126 -0
- package/dist/wiki-migration.d.ts +16 -0
- package/dist/wiki-migration.js +268 -0
- package/dist/wiki-tokens.d.ts +1 -0
- package/dist/wiki-tokens.js +46 -0
- package/dist/wiki.d.ts +103 -0
- package/dist/wiki.js +330 -0
- package/dist/workflow-cli.d.ts +2 -0
- package/dist/workflow-cli.js +258 -0
- package/dist/workflow-install.d.ts +36 -0
- package/dist/workflow-install.js +148 -0
- package/dist/workflow-knowledge.d.ts +16 -0
- package/dist/workflow-knowledge.js +24 -0
- package/dist/workflow-mcp.d.ts +2 -0
- package/dist/workflow-mcp.js +144 -0
- package/dist/workflow-names.d.ts +4 -0
- package/dist/workflow-names.js +18 -0
- package/dist/workflow-runtime.d.ts +622 -0
- package/dist/workflow-runtime.js +627 -0
- package/dist/workflow-skills.d.ts +48 -0
- package/dist/workflow-skills.js +141 -0
- package/package.json +76 -4
- package/skills/ew-odyssey/SKILL.md +237 -0
- package/skills/ew-odyssey/references/audit-artifacts.md +7 -0
- package/skills/ew-odyssey/references/odyssey-base-codex.md +3 -0
- package/skills/ew-odyssey/references/odyssey-base.md +278 -0
- package/skills/ew-odyssey/references/odyssey-debug.codex.md +305 -0
- package/skills/ew-odyssey/references/odyssey-debug.md +283 -0
- package/skills/ew-odyssey/references/odyssey-defensive.codex.md +395 -0
- package/skills/ew-odyssey/references/odyssey-defensive.md +369 -0
- package/skills/ew-odyssey/references/odyssey-improve.codex.md +270 -0
- package/skills/ew-odyssey/references/odyssey-improve.md +248 -0
- package/skills/ew-odyssey/references/odyssey-planex.codex.md +352 -0
- package/skills/ew-odyssey/references/odyssey-planex.md +312 -0
- package/skills/ew-odyssey/references/odyssey-review.codex.md +283 -0
- package/skills/ew-odyssey/references/odyssey-review.md +251 -0
- package/skills/ew-odyssey/references/odyssey-security.md +249 -0
- package/skills/ew-odyssey/references/odyssey-ui.codex.md +294 -0
- package/skills/ew-odyssey/references/odyssey-ui.md +250 -0
- package/skills/ew-odyssey/references/prepare/odyssey-debug.md +105 -0
- package/skills/ew-odyssey/references/prepare/odyssey-defensive.md +121 -0
- package/skills/ew-odyssey/references/prepare/odyssey-improve.md +93 -0
- package/skills/ew-odyssey/references/prepare/odyssey-planex.md +104 -0
- package/skills/ew-odyssey/references/prepare/odyssey-review.md +98 -0
- package/skills/ew-odyssey/references/prepare/odyssey-security.md +94 -0
- package/skills/ew-odyssey/references/prepare/odyssey-ui.md +87 -0
- package/skills/ew-orchestrate/SKILL.md +236 -0
- package/skills/ew-orchestrate/references/auto-policy.md +165 -0
- package/skills/ew-orchestrate/references/companion-route.md +52 -0
- package/skills/ew-orchestrate/references/ew-orchestrate.md +27 -0
- package/skills/ew-orchestrate/references/goal.md +53 -0
- package/skills/ew-orchestrate/references/knowledge-route.md +163 -0
- package/skills/ew-orchestrate/references/orchestrator-run-loop.md +36 -0
- package/skills/ew-orchestrate/references/planning.md +137 -0
- package/skills/ew-orchestrate/steps/ew-analyze/SKILL.md +62 -0
- package/skills/ew-orchestrate/steps/ew-analyze/references/boundary-grill.md +50 -0
- package/skills/ew-orchestrate/steps/ew-analyze/references/issue-gaps-analyze.md +59 -0
- package/skills/ew-orchestrate/steps/ew-analyze/references/prepare.md +42 -0
- package/skills/ew-orchestrate/steps/ew-analyze/references/workflow.md +401 -0
- package/skills/ew-orchestrate/steps/ew-brainstorm/SKILL.md +32 -0
- package/skills/ew-orchestrate/steps/ew-companion/SKILL.md +9 -0
- package/skills/ew-orchestrate/steps/ew-execute/SKILL.md +71 -0
- package/skills/ew-orchestrate/steps/ew-execute/references/prepare.md +69 -0
- package/skills/ew-orchestrate/steps/ew-execute/references/workflow.md +373 -0
- package/skills/ew-orchestrate/steps/ew-plan/SKILL.md +102 -0
- package/skills/ew-orchestrate/steps/ew-plan/references/boundary-grill.md +50 -0
- package/skills/ew-orchestrate/steps/ew-plan/references/prepare.md +51 -0
- package/skills/ew-orchestrate/steps/ew-plan/references/tdd.md +53 -0
- package/skills/ew-orchestrate/steps/ew-plan/references/workflow.md +278 -0
- package/skills/ew-orchestrate/steps/ew-review/SKILL.md +44 -0
- package/skills/ew-orchestrate/steps/ew-review/references/odyssey-base-codex.md +3 -0
- package/skills/ew-orchestrate/steps/ew-review/references/prepare.md +76 -0
- package/skills/ew-orchestrate/steps/ew-review/references/workflow.md +283 -0
- package/skills/ew-skill-design/SKILL.md +28 -0
- package/skills/ew-skill-design/references/package-contract.md +28 -0
- package/skills/ew-skill-design/references/validation.md +7 -0
- package/skills/team-swarm/SKILL.md +231 -0
- package/skills/team-swarm/references/mcp-coordination.md +10 -0
- package/skills/team-swarm/roles/analyst/role.md +181 -0
- package/skills/team-swarm/roles/ant/role.md +149 -0
- package/skills/team-swarm/roles/coordinator/commands/converge.md +154 -0
- package/skills/team-swarm/roles/coordinator/commands/init-swarm.md +134 -0
- package/skills/team-swarm/roles/coordinator/commands/iterate.md +202 -0
- package/skills/team-swarm/roles/coordinator/role.md +228 -0
- package/skills/team-swarm/roles/scorer/role.md +150 -0
- package/skills/team-swarm/scripts/aco.py +646 -0
- package/skills/team-swarm/scripts/pheromone.py +144 -0
- package/skills/team-swarm/scripts/scoring.py +111 -0
- package/skills/team-swarm/scripts/test_aco.py +606 -0
- package/skills/team-swarm/specs/ant-output-schema.md +127 -0
- package/skills/team-swarm/specs/convergence-criteria.md +108 -0
- package/skills/team-swarm/specs/pheromone-schema.md +125 -0
- package/skills/team-swarm/specs/swarm-config-template.json +71 -0
- package/skills/team-swarm/specs/swarm-protocol.md +123 -0
- package/skills/workflow-closeout/SKILL.md +10 -0
- package/skills/workflow-evolve/SKILL.md +79 -0
- package/skills/workflow-evolve/references/agy-gate.md +27 -0
- package/skills/workflow-evolve/references/auto-loop.md +20 -0
- package/skills/workflow-evolve/references/history-review.md +14 -0
- package/skills/workflow-evolve/scripts/codex-memory-replay.mjs +76 -0
- package/skills/workflow-evolve/scripts/codex-replay.mjs +1 -0
- package/skills/workflow-evolve/scripts/evolve-loop.mjs +259 -0
- package/skills/workflow-evolve/scripts/memory-codex-mcp.mjs +124 -0
- package/workflows/index.json +23 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"""Pheromone matrix module - state representation, update, evaporation.
|
|
2
|
+
|
|
3
|
+
Format spec: ../specs/pheromone-schema.md
|
|
4
|
+
"""
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
import math
|
|
9
|
+
from dataclasses import dataclass, field
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Dict, List, Optional
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def edge_key(a: str, b: str) -> str:
|
|
15
|
+
"""Lexically-ordered edge key (undirected)."""
|
|
16
|
+
return f"{a}::{b}" if a <= b else f"{b}::{a}"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class PheromoneState:
|
|
21
|
+
iteration: int = 0
|
|
22
|
+
n_nodes: int = 0
|
|
23
|
+
matrix_type: str = "edge_weighted_sparse"
|
|
24
|
+
tau: Dict[str, float] = field(default_factory=dict)
|
|
25
|
+
node_tau: Dict[str, float] = field(default_factory=dict)
|
|
26
|
+
metadata: Dict[str, float] = field(default_factory=dict)
|
|
27
|
+
|
|
28
|
+
@classmethod
|
|
29
|
+
def initialize(cls, nodes: List[str], aco_config: dict) -> "PheromoneState":
|
|
30
|
+
tau_init = aco_config.get("tau_init", 1.0)
|
|
31
|
+
tau = {}
|
|
32
|
+
for i, a in enumerate(nodes):
|
|
33
|
+
for b in nodes[i + 1:]:
|
|
34
|
+
tau[edge_key(a, b)] = tau_init
|
|
35
|
+
return cls(
|
|
36
|
+
iteration=0,
|
|
37
|
+
n_nodes=len(nodes),
|
|
38
|
+
tau=tau,
|
|
39
|
+
node_tau={n: tau_init for n in nodes},
|
|
40
|
+
metadata={
|
|
41
|
+
"alpha": aco_config.get("alpha", 1.0),
|
|
42
|
+
"beta": aco_config.get("beta", 2.0),
|
|
43
|
+
"rho": aco_config.get("rho", 0.2),
|
|
44
|
+
"q": aco_config.get("q", 1.0),
|
|
45
|
+
"tau_init": tau_init,
|
|
46
|
+
"tau_min": aco_config.get("tau_min", 0.01),
|
|
47
|
+
"tau_max": aco_config.get("tau_max", 10.0),
|
|
48
|
+
},
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
def evaporate(self) -> None:
|
|
52
|
+
rho = self.metadata["rho"]
|
|
53
|
+
for k in list(self.tau.keys()):
|
|
54
|
+
self.tau[k] = max(self.metadata["tau_min"], (1 - rho) * self.tau[k])
|
|
55
|
+
|
|
56
|
+
def deposit(self, path: List[str], score: float) -> None:
|
|
57
|
+
q = self.metadata["q"]
|
|
58
|
+
delta = q * score
|
|
59
|
+
for a, b in zip(path[:-1], path[1:]):
|
|
60
|
+
k = edge_key(a, b)
|
|
61
|
+
self.tau[k] = self.tau.get(k, self.metadata["tau_init"]) + delta
|
|
62
|
+
for node in path:
|
|
63
|
+
self.node_tau[node] = self.node_tau.get(node, self.metadata["tau_init"]) + delta * 0.5
|
|
64
|
+
|
|
65
|
+
def clip(self) -> None:
|
|
66
|
+
lo, hi = self.metadata["tau_min"], self.metadata["tau_max"]
|
|
67
|
+
for k in self.tau:
|
|
68
|
+
self.tau[k] = max(lo, min(hi, self.tau[k]))
|
|
69
|
+
for n in self.node_tau:
|
|
70
|
+
self.node_tau[n] = max(lo, min(hi, self.node_tau[n]))
|
|
71
|
+
|
|
72
|
+
def stats(self) -> Dict[str, float]:
|
|
73
|
+
if not self.tau:
|
|
74
|
+
return {"mean": 0.0, "max": 0.0, "min": 0.0, "entropy": 0.0, "n_edges_active": 0}
|
|
75
|
+
vals = list(self.tau.values())
|
|
76
|
+
total = sum(vals)
|
|
77
|
+
active = [v for v in vals if v > self.metadata["tau_min"] * 1.01]
|
|
78
|
+
entropy = 0.0
|
|
79
|
+
if total > 0:
|
|
80
|
+
for v in vals:
|
|
81
|
+
p = v / total
|
|
82
|
+
if p > 0:
|
|
83
|
+
entropy -= p * math.log2(p)
|
|
84
|
+
return {
|
|
85
|
+
"mean": sum(vals) / len(vals),
|
|
86
|
+
"max": max(vals),
|
|
87
|
+
"min": min(vals),
|
|
88
|
+
"entropy": entropy,
|
|
89
|
+
"n_edges_active": len(active),
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
def to_dict(self) -> dict:
|
|
93
|
+
return {
|
|
94
|
+
"version": "1.0",
|
|
95
|
+
"iteration": self.iteration,
|
|
96
|
+
"n_nodes": self.n_nodes,
|
|
97
|
+
"matrix_type": self.matrix_type,
|
|
98
|
+
"tau": self.tau,
|
|
99
|
+
"node_tau": self.node_tau,
|
|
100
|
+
"metadata": self.metadata,
|
|
101
|
+
"stats": self.stats(),
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@classmethod
|
|
105
|
+
def from_dict(cls, d: dict) -> "PheromoneState":
|
|
106
|
+
return cls(
|
|
107
|
+
iteration=d["iteration"],
|
|
108
|
+
n_nodes=d["n_nodes"],
|
|
109
|
+
matrix_type=d.get("matrix_type", "edge_weighted_sparse"),
|
|
110
|
+
tau=d.get("tau", {}),
|
|
111
|
+
node_tau=d.get("node_tau", {}),
|
|
112
|
+
metadata=d["metadata"],
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
def save(self, path: Path) -> None:
|
|
116
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
117
|
+
path.write_text(json.dumps(self.to_dict(), indent=2, ensure_ascii=False), encoding="utf-8")
|
|
118
|
+
|
|
119
|
+
@classmethod
|
|
120
|
+
def load(cls, path: Path) -> "PheromoneState":
|
|
121
|
+
return cls.from_dict(json.loads(path.read_text(encoding="utf-8")))
|
|
122
|
+
|
|
123
|
+
def select_neighbors(
|
|
124
|
+
self,
|
|
125
|
+
current: str,
|
|
126
|
+
candidates: List[str],
|
|
127
|
+
heuristic: Optional[Dict[str, float]] = None,
|
|
128
|
+
) -> Dict[str, float]:
|
|
129
|
+
"""Return probability distribution over candidates given current node."""
|
|
130
|
+
alpha = self.metadata["alpha"]
|
|
131
|
+
beta = self.metadata["beta"]
|
|
132
|
+
heuristic = heuristic or {}
|
|
133
|
+
weights = {}
|
|
134
|
+
for c in candidates:
|
|
135
|
+
if c == current:
|
|
136
|
+
continue
|
|
137
|
+
tau_val = self.tau.get(edge_key(current, c), self.metadata["tau_init"])
|
|
138
|
+
eta = heuristic.get(c, 1.0)
|
|
139
|
+
weights[c] = (tau_val ** alpha) * (eta ** beta)
|
|
140
|
+
total = sum(weights.values())
|
|
141
|
+
if total == 0:
|
|
142
|
+
n = len(weights)
|
|
143
|
+
return {c: 1.0 / n for c in weights} if n else {}
|
|
144
|
+
return {c: w / total for c, w in weights.items()}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"""Pluggable scoring module.
|
|
2
|
+
|
|
3
|
+
Two scorer types:
|
|
4
|
+
- ScriptScorer: runs user-defined Python rule on ant artifacts (deterministic)
|
|
5
|
+
- FallbackScorer: derives effective_score from self_score * self_confidence
|
|
6
|
+
|
|
7
|
+
LLM scorer is handled by the scorer worker role, not this script.
|
|
8
|
+
This module is invoked by aco.py when scoring.mode = "script" or as fallback.
|
|
9
|
+
|
|
10
|
+
Spec: ../specs/ant-output-schema.md (two-layer scoring)
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import importlib.util
|
|
15
|
+
import json
|
|
16
|
+
import math
|
|
17
|
+
import sys
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Dict, Optional
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class BaseScorer:
|
|
23
|
+
def score(self, ant_artifact: dict) -> Optional[float]: # noqa: ARG002
|
|
24
|
+
raise NotImplementedError
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class FallbackScorer(BaseScorer):
|
|
28
|
+
"""Used when no verified_scores file exists.
|
|
29
|
+
|
|
30
|
+
effective_score = self_score * self_confidence * discount
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__(self, discount: float = 0.5):
|
|
34
|
+
self.discount = discount
|
|
35
|
+
|
|
36
|
+
def score(self, ant_artifact: dict) -> float:
|
|
37
|
+
s = ant_artifact.get("self_score", 0.0)
|
|
38
|
+
c = ant_artifact.get("self_confidence", 0.5)
|
|
39
|
+
return s * c * self.discount
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class ScriptScorer(BaseScorer):
|
|
43
|
+
"""Loads user-defined scoring rule from a Python file.
|
|
44
|
+
|
|
45
|
+
The rule file must define: `def score(ant_artifact: dict) -> float`
|
|
46
|
+
Returns a value in [0.0, 1.0].
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
def __init__(self, rule_path: Path):
|
|
50
|
+
spec = importlib.util.spec_from_file_location("user_score_rule", rule_path)
|
|
51
|
+
if spec is None or spec.loader is None:
|
|
52
|
+
raise ValueError(f"cannot load scoring rule from {rule_path}")
|
|
53
|
+
self.module = importlib.util.module_from_spec(spec)
|
|
54
|
+
spec.loader.exec_module(self.module)
|
|
55
|
+
if not hasattr(self.module, "score"):
|
|
56
|
+
raise ValueError(f"{rule_path} must define `score(ant_artifact) -> float`")
|
|
57
|
+
|
|
58
|
+
def score(self, ant_artifact: dict) -> float:
|
|
59
|
+
value = float(self.module.score(ant_artifact))
|
|
60
|
+
if not math.isfinite(value):
|
|
61
|
+
raise ValueError("script score must be finite")
|
|
62
|
+
return max(0.0, min(1.0, value))
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def load_verified_scores(scores_file: Path, *, iteration: Optional[int] = None) -> Dict[str, float]:
|
|
66
|
+
"""Load pre-computed verified_scores from scorer role output (if exists)."""
|
|
67
|
+
if not scores_file.exists():
|
|
68
|
+
return {}
|
|
69
|
+
data = json.loads(scores_file.read_text(encoding="utf-8"))
|
|
70
|
+
if iteration is not None:
|
|
71
|
+
if (not isinstance(data, dict) or type(data.get("iteration")) is not int
|
|
72
|
+
or data["iteration"] != iteration or data.get("scorer_type") != "llm"
|
|
73
|
+
or not isinstance(data.get("scores"), dict)):
|
|
74
|
+
raise ValueError(f"invalid LLM scores file for iteration {iteration}: {scores_file.name}")
|
|
75
|
+
verified = {}
|
|
76
|
+
for ant_id, entry in data["scores"].items():
|
|
77
|
+
score = entry.get("verified_score") if isinstance(entry, dict) else None
|
|
78
|
+
if type(score) not in (int, float) or not 0 <= score <= 1:
|
|
79
|
+
raise ValueError(f"invalid verified score for {ant_id} in iteration {iteration}")
|
|
80
|
+
rationale = entry.get("rationale")
|
|
81
|
+
if not isinstance(rationale, str) or not rationale.strip():
|
|
82
|
+
raise ValueError(f"missing score rationale for {ant_id} in iteration {iteration}")
|
|
83
|
+
verified[ant_id] = score
|
|
84
|
+
return verified
|
|
85
|
+
return {
|
|
86
|
+
ant_id: entry["verified_score"]
|
|
87
|
+
for ant_id, entry in data.get("scores", {}).items()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def resolve_score(
|
|
92
|
+
ant_artifact: dict,
|
|
93
|
+
verified_scores: Dict[str, float],
|
|
94
|
+
script_scorer: Optional[ScriptScorer],
|
|
95
|
+
fallback: FallbackScorer,
|
|
96
|
+
) -> tuple[float, str]:
|
|
97
|
+
"""Return (score, source) using priority: verified > script > fallback."""
|
|
98
|
+
ant_id = ant_artifact.get("ant_id", "")
|
|
99
|
+
if ant_id in verified_scores:
|
|
100
|
+
return verified_scores[ant_id], "verified_llm"
|
|
101
|
+
if script_scorer is not None:
|
|
102
|
+
try:
|
|
103
|
+
return script_scorer.score(ant_artifact), "verified_script"
|
|
104
|
+
except Exception as e:
|
|
105
|
+
print(f"warning: script scorer failed for {ant_id}: {e}", file=sys.stderr)
|
|
106
|
+
return fallback.score(ant_artifact), "fallback_self"
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def hallucination_check(self_score: float, verified_score: float, threshold: float = 0.4) -> bool:
|
|
110
|
+
"""True if self vs verified divergence exceeds threshold."""
|
|
111
|
+
return abs(self_score - verified_score) > threshold
|