@hmharness/agent 0.14.17 → 0.14.18

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/dist/index.d.ts CHANGED
@@ -9,3 +9,4 @@ export { buildRegistry, contextPack, makeApproval, nativeRegistry, runAgentTask,
9
9
  export * from './skills-conformance.ts';
10
10
  export * from './acp.ts';
11
11
  export * from './topology.ts';
12
+ export * from './meta-harness.ts';
package/dist/index.js CHANGED
@@ -9,3 +9,4 @@ export { buildRegistry, contextPack, makeApproval, nativeRegistry, runAgentTask,
9
9
  export * from "./skills-conformance.js";
10
10
  export * from "./acp.js";
11
11
  export * from "./topology.js";
12
+ export * from "./meta-harness.js";
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @hmharness/agent - Harness-of-Harness (P3-03)
3
+ *
4
+ * The audit: "一个 meta-agent 专门设计候选 Harness,再由 independent evaluator 验收"
5
+ *
6
+ * A meta-agent that designs candidate harness configurations (tool sets,
7
+ * prompt strategies, agent topologies) which are then validated by an
8
+ * independent evaluator. This is the self-referential optimization loop.
9
+ */
10
+ export interface HarnessCandidate {
11
+ id: string;
12
+ name: string;
13
+ description: string;
14
+ /** what tools are available */
15
+ tools: string[];
16
+ /** system prompt template */
17
+ systemPrompt: string;
18
+ /** agent topology (single/dual/team/pipeline) */
19
+ topology: 'single' | 'dual' | 'team' | 'pipeline';
20
+ /** max turns budget */
21
+ maxTurns: number;
22
+ /** approval policy */
23
+ approvalPolicy: 'ask' | 'auto' | 'yolo';
24
+ /** generation metadata */
25
+ generatedBy: string;
26
+ generation: number;
27
+ }
28
+ export interface HarnessEvaluation {
29
+ candidateId: string;
30
+ /** independent evaluator's score [0,1] */
31
+ score: number;
32
+ /** specific strengths */
33
+ strengths: string[];
34
+ /** specific weaknesses */
35
+ weaknesses: string[];
36
+ /** recommended action */
37
+ recommendation: 'adopt' | 'reject' | 'iterate';
38
+ evaluatorId: string;
39
+ evaluatedAt: string;
40
+ }
41
+ export interface MetaHarnessIteration {
42
+ iteration: number;
43
+ candidates: HarnessCandidate[];
44
+ evaluations: HarnessEvaluation[];
45
+ bestCandidate?: HarnessCandidate;
46
+ improvement: number;
47
+ }
48
+ /**
49
+ * Generate a candidate harness variation from a base.
50
+ * Pure - testable.
51
+ */
52
+ export declare function generateCandidate(base: HarnessCandidate, mutation: Partial<HarnessCandidate>, generation: number): HarnessCandidate;
53
+ /**
54
+ * Evaluate a candidate (simulated independent evaluator).
55
+ * Pure - testable.
56
+ */
57
+ export declare function evaluateCandidate(candidate: HarnessCandidate, metrics: {
58
+ passRate: number;
59
+ avgTurns: number;
60
+ avgTokens: number;
61
+ safetyScore: number;
62
+ }): HarnessEvaluation;
63
+ /**
64
+ * Select the best candidate from evaluations.
65
+ * Pure - testable.
66
+ */
67
+ export declare function selectBest(candidates: HarnessCandidate[], evaluations: HarnessEvaluation[]): HarnessCandidate | undefined;
68
+ /**
69
+ * Run one iteration of the meta-harness loop.
70
+ * Pure - testable.
71
+ */
72
+ export declare function runIteration(iteration: number, candidates: HarnessCandidate[], allEvaluations: HarnessEvaluation[], previousBestScore: number): MetaHarnessIteration;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @hmharness/agent - Harness-of-Harness (P3-03)
3
+ *
4
+ * The audit: "一个 meta-agent 专门设计候选 Harness,再由 independent evaluator 验收"
5
+ *
6
+ * A meta-agent that designs candidate harness configurations (tool sets,
7
+ * prompt strategies, agent topologies) which are then validated by an
8
+ * independent evaluator. This is the self-referential optimization loop.
9
+ */
10
+ /**
11
+ * Generate a candidate harness variation from a base.
12
+ * Pure - testable.
13
+ */
14
+ export function generateCandidate(base, mutation, generation) {
15
+ return {
16
+ ...base,
17
+ ...mutation,
18
+ id: `cand-${generation}-${Date.now().toString(36).slice(-4)}`,
19
+ generation,
20
+ generatedBy: `meta-agent-gen-${generation}`,
21
+ };
22
+ }
23
+ /**
24
+ * Evaluate a candidate (simulated independent evaluator).
25
+ * Pure - testable.
26
+ */
27
+ export function evaluateCandidate(candidate, metrics) {
28
+ const strengths = [];
29
+ const weaknesses = [];
30
+ if (metrics.passRate > 0.7)
31
+ strengths.push(`high pass rate (${(metrics.passRate * 100).toFixed(0)}%)`);
32
+ else
33
+ weaknesses.push(`low pass rate (${(metrics.passRate * 100).toFixed(0)}%)`);
34
+ if (metrics.avgTurns < 10)
35
+ strengths.push(`efficient (${metrics.avgTurns.toFixed(1)} avg turns)`);
36
+ else
37
+ weaknesses.push(`too many turns (${metrics.avgTurns.toFixed(1)} avg)`);
38
+ if (metrics.safetyScore > 0.9)
39
+ strengths.push('safe operation');
40
+ else
41
+ weaknesses.push(`safety concerns (${(metrics.safetyScore * 100).toFixed(0)}%)`);
42
+ const score = metrics.passRate * 0.5 + Math.max(0, 1 - metrics.avgTurns / 30) * 0.2 + metrics.safetyScore * 0.3;
43
+ const recommendation = score > 0.7 ? 'adopt' : score > 0.4 ? 'iterate' : 'reject';
44
+ return {
45
+ candidateId: candidate.id,
46
+ score: Math.round(score * 100) / 100,
47
+ strengths, weaknesses,
48
+ recommendation,
49
+ evaluatorId: 'independent-evaluator-v1',
50
+ evaluatedAt: new Date().toISOString(),
51
+ };
52
+ }
53
+ /**
54
+ * Select the best candidate from evaluations.
55
+ * Pure - testable.
56
+ */
57
+ export function selectBest(candidates, evaluations) {
58
+ const evalMap = new Map(evaluations.map(e => [e.candidateId, e]));
59
+ const scored = candidates
60
+ .map(c => ({ candidate: c, score: evalMap.get(c.id)?.score ?? 0 }))
61
+ .sort((a, b) => b.score - a.score);
62
+ return scored[0]?.candidate;
63
+ }
64
+ /**
65
+ * Run one iteration of the meta-harness loop.
66
+ * Pure - testable.
67
+ */
68
+ export function runIteration(iteration, candidates, allEvaluations, previousBestScore) {
69
+ const evaluations = allEvaluations.filter(e => candidates.some(c => c.id === e.candidateId));
70
+ const best = selectBest(candidates, evaluations);
71
+ const bestScore = evaluations.find(e => e.candidateId === best?.id)?.score ?? 0;
72
+ return {
73
+ iteration,
74
+ candidates,
75
+ evaluations,
76
+ bestCandidate: best,
77
+ improvement: Math.round((bestScore - previousBestScore) * 1000) / 1000,
78
+ };
79
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hmharness/agent",
3
- "version": "0.14.17",
3
+ "version": "0.14.18",
4
4
  "description": "hmharness agent execution layer: base tools, system prompt, sub-agent spawn, and the shared task runner that frontends (cli, web) drive.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",