@mhingston5/lasso 0.1.0

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.
Files changed (124) hide show
  1. package/README.md +707 -0
  2. package/docs/agent-wrangling.png +0 -0
  3. package/package.json +26 -0
  4. package/src/capabilities/matcher.ts +25 -0
  5. package/src/capabilities/registry.ts +103 -0
  6. package/src/capabilities/types.ts +15 -0
  7. package/src/cir/lower.ts +253 -0
  8. package/src/cir/optimize.ts +251 -0
  9. package/src/cir/types.ts +131 -0
  10. package/src/cir/validate.ts +265 -0
  11. package/src/compiler/compile.ts +601 -0
  12. package/src/compiler/feedback.ts +471 -0
  13. package/src/compiler/runtime-helpers.ts +455 -0
  14. package/src/composition/chain.ts +58 -0
  15. package/src/composition/conditional.ts +76 -0
  16. package/src/composition/parallel.ts +75 -0
  17. package/src/composition/types.ts +105 -0
  18. package/src/environment/analyzer.ts +56 -0
  19. package/src/environment/discovery.ts +179 -0
  20. package/src/environment/types.ts +68 -0
  21. package/src/failures/classifiers.ts +134 -0
  22. package/src/failures/generator.ts +421 -0
  23. package/src/failures/map-reference-failures.ts +23 -0
  24. package/src/failures/ontology.ts +210 -0
  25. package/src/failures/recovery.ts +214 -0
  26. package/src/failures/types.ts +14 -0
  27. package/src/index.ts +67 -0
  28. package/src/memory/advisor.ts +132 -0
  29. package/src/memory/extractor.ts +166 -0
  30. package/src/memory/store.ts +107 -0
  31. package/src/memory/types.ts +53 -0
  32. package/src/metaharness/engine.ts +256 -0
  33. package/src/metaharness/predictor.ts +168 -0
  34. package/src/metaharness/types.ts +40 -0
  35. package/src/mutation/derive.ts +308 -0
  36. package/src/mutation/diff.ts +52 -0
  37. package/src/mutation/engine.ts +256 -0
  38. package/src/mutation/types.ts +84 -0
  39. package/src/pi/command-input.ts +209 -0
  40. package/src/pi/commands.ts +351 -0
  41. package/src/pi/extension.ts +16 -0
  42. package/src/planner/synthesize.ts +83 -0
  43. package/src/planner/template-rules.ts +183 -0
  44. package/src/planner/types.ts +42 -0
  45. package/src/reference/catalog.ts +128 -0
  46. package/src/reference/patch-validation-strategies.ts +170 -0
  47. package/src/reference/patch-validation.ts +174 -0
  48. package/src/reference/pr-review-merge.ts +155 -0
  49. package/src/reference/strategies.ts +126 -0
  50. package/src/reference/types.ts +33 -0
  51. package/src/replanner/risk-rules.ts +161 -0
  52. package/src/replanner/runtime.ts +308 -0
  53. package/src/replanner/synthesize.ts +619 -0
  54. package/src/replanner/types.ts +73 -0
  55. package/src/spec/schema.ts +254 -0
  56. package/src/spec/types.ts +319 -0
  57. package/src/spec/validate.ts +296 -0
  58. package/src/state/snapshots.ts +43 -0
  59. package/src/state/types.ts +12 -0
  60. package/src/synthesis/graph-builder.ts +267 -0
  61. package/src/synthesis/harness-builder.ts +113 -0
  62. package/src/synthesis/intent-ir.ts +63 -0
  63. package/src/synthesis/policy-builder.ts +320 -0
  64. package/src/synthesis/risk-analyzer.ts +182 -0
  65. package/src/synthesis/skill-parser.ts +441 -0
  66. package/src/verification/engine.ts +230 -0
  67. package/src/versioning/file-store.ts +103 -0
  68. package/src/versioning/history.ts +43 -0
  69. package/src/versioning/store.ts +16 -0
  70. package/src/versioning/types.ts +31 -0
  71. package/test/capabilities/matcher.test.ts +67 -0
  72. package/test/capabilities/registry.test.ts +136 -0
  73. package/test/capabilities/synthesis.test.ts +264 -0
  74. package/test/cir/lower.test.ts +417 -0
  75. package/test/cir/optimize.test.ts +266 -0
  76. package/test/cir/validate.test.ts +368 -0
  77. package/test/compiler/adaptive-runtime.test.ts +157 -0
  78. package/test/compiler/compile.test.ts +1198 -0
  79. package/test/compiler/feedback.test.ts +784 -0
  80. package/test/compiler/guardrails.test.ts +191 -0
  81. package/test/compiler/trace.test.ts +404 -0
  82. package/test/composition/chain.test.ts +328 -0
  83. package/test/composition/conditional.test.ts +241 -0
  84. package/test/composition/parallel.test.ts +215 -0
  85. package/test/environment/analyzer.test.ts +204 -0
  86. package/test/environment/discovery.test.ts +149 -0
  87. package/test/failures/classifiers.test.ts +287 -0
  88. package/test/failures/generator.test.ts +203 -0
  89. package/test/failures/ontology.test.ts +439 -0
  90. package/test/failures/recovery.test.ts +300 -0
  91. package/test/helpers/createFixtureRepo.ts +84 -0
  92. package/test/helpers/createPatchValidationFixture.ts +144 -0
  93. package/test/helpers/runCompiledWorkflow.ts +208 -0
  94. package/test/memory/advisor.test.ts +332 -0
  95. package/test/memory/extractor.test.ts +295 -0
  96. package/test/memory/store.test.ts +244 -0
  97. package/test/metaharness/engine.test.ts +575 -0
  98. package/test/metaharness/predictor.test.ts +436 -0
  99. package/test/mutation/derive-failure.test.ts +209 -0
  100. package/test/mutation/engine.test.ts +622 -0
  101. package/test/package-smoke.test.ts +29 -0
  102. package/test/pi/command-input.test.ts +153 -0
  103. package/test/pi/commands.test.ts +623 -0
  104. package/test/planner/classify-template.test.ts +32 -0
  105. package/test/planner/synthesize.test.ts +901 -0
  106. package/test/reference/PatchValidation.failures.test.ts +137 -0
  107. package/test/reference/PatchValidation.test.ts +326 -0
  108. package/test/reference/PrReviewMerge.failures.test.ts +121 -0
  109. package/test/reference/PrReviewMerge.test.ts +55 -0
  110. package/test/reference/catalog-open.test.ts +70 -0
  111. package/test/replanner/runtime.test.ts +207 -0
  112. package/test/replanner/synthesize.test.ts +303 -0
  113. package/test/spec/validate.test.ts +1056 -0
  114. package/test/state/snapshots.test.ts +264 -0
  115. package/test/synthesis/custom-workflow.test.ts +264 -0
  116. package/test/synthesis/graph-builder.test.ts +370 -0
  117. package/test/synthesis/harness-builder.test.ts +128 -0
  118. package/test/synthesis/policy-builder.test.ts +149 -0
  119. package/test/synthesis/risk-analyzer.test.ts +230 -0
  120. package/test/synthesis/skill-parser.test.ts +796 -0
  121. package/test/verification/engine.test.ts +509 -0
  122. package/test/versioning/history.test.ts +144 -0
  123. package/test/versioning/store.test.ts +254 -0
  124. package/vitest.config.ts +9 -0
@@ -0,0 +1,53 @@
1
+ import type { HarnessExecutionTrace } from "../versioning/types.js";
2
+ import type { HarnessSpec } from "../spec/types.js";
3
+
4
+ export interface HarnessMemory {
5
+ taskId: string;
6
+ taskEmbedding?: string;
7
+ successfulPatterns: string[];
8
+ failedPatterns: string[];
9
+ mutationHistory: MutationRecord[];
10
+ effectivenessScore: number;
11
+ lastUpdated: number;
12
+ }
13
+
14
+ export interface MutationRecord {
15
+ mutation: string;
16
+ triggeredBy: string;
17
+ timestamp: number;
18
+ outcome: "improved" | "no-change" | "worse";
19
+ }
20
+
21
+ export interface MemoryStore {
22
+ getMemory(taskId: string): Promise<HarnessMemory | null>;
23
+ saveMemory(memory: HarnessMemory): Promise<void>;
24
+ updateMemory(taskId: string, update: MemoryUpdate): Promise<HarnessMemory>;
25
+ searchMemories(query: MemoryQuery): Promise<HarnessMemory[]>;
26
+ }
27
+
28
+ export interface MemoryUpdate {
29
+ successfulPattern?: string;
30
+ failedPattern?: string;
31
+ mutation?: MutationRecord;
32
+ effectivenessDelta?: number;
33
+ }
34
+
35
+ export interface MemoryQuery {
36
+ taskSignature?: string;
37
+ minEffectiveness?: number;
38
+ limit?: number;
39
+ }
40
+
41
+ export interface MemoryAdvice {
42
+ suggestions: string[];
43
+ warnings: string[];
44
+ sourceTaskIds: string[];
45
+ aggregateEffectiveness: number;
46
+ }
47
+
48
+ export interface TaskSignatureOptions {
49
+ taskSignature?: string;
50
+ minEffectiveness?: number;
51
+ }
52
+
53
+ export { HarnessExecutionTrace, HarnessSpec };
@@ -0,0 +1,256 @@
1
+ import type { HarnessSpec } from "../spec/types.js";
2
+ import type { EnvironmentModel, EnvironmentAnalysis } from "../environment/types.js";
3
+ import type { FailureSignature } from "../failures/ontology.js";
4
+ import type { MemoryAdvice, MemoryStore } from "../memory/types.js";
5
+ import type { CapabilityRegistry } from "../capabilities/types.js";
6
+ import type { MutationPolicy, HarnessMutation } from "../mutation/types.js";
7
+ import type { MetaHarnessConfig, MetaHarnessResult, MetaHarness } from "./types.js";
8
+ import type { CompilerAnalysis } from "../compiler/feedback.js";
9
+ import type { HarnessStage, CompositionResult } from "../composition/types.js";
10
+ import { discoverEnvironment } from "../environment/discovery.js";
11
+ import { analyzeEnvironment } from "../environment/analyzer.js";
12
+ import { adviseFromMemory } from "../memory/advisor.js";
13
+ import { planWorkflowRequest } from "../planner/synthesize.js";
14
+ import { parsePromptOrSkill } from "../synthesis/skill-parser.js";
15
+ import { buildTaskGraph } from "../synthesis/graph-builder.js";
16
+ import { analyzeRisks } from "../synthesis/risk-analyzer.js";
17
+ import { synthesizeHarness } from "../synthesis/harness-builder.js";
18
+ import { compileHarnessSpec } from "../compiler/compile.js";
19
+ import { analyzeCompiledWorkflow } from "../compiler/feedback.js";
20
+ import { predictFailuresFromEnvironment } from "./predictor.js";
21
+ import { generateFailureModes } from "../failures/generator.js";
22
+ import { deriveMutationsFromFailure } from "../mutation/derive.js";
23
+ import { mutateHarness } from "../mutation/engine.js";
24
+ import { chainHarnesses } from "../composition/chain.js";
25
+ import { parallelHarnesses } from "../composition/parallel.js";
26
+ import { conditionalHarness } from "../composition/conditional.js";
27
+
28
+ export class DefaultMetaHarness implements MetaHarness {
29
+ constructor(private config: MetaHarnessConfig) {}
30
+
31
+ async discoverEnvironment(repoPath?: string): Promise<EnvironmentModel> {
32
+ return discoverEnvironment(repoPath);
33
+ }
34
+
35
+ async predictFailures(
36
+ spec: HarnessSpec,
37
+ env: EnvironmentModel,
38
+ ): Promise<FailureSignature[]> {
39
+ return predictFailuresFromEnvironment(spec, env);
40
+ }
41
+
42
+ synthesizePolicies(
43
+ spec: HarnessSpec,
44
+ failures: FailureSignature[],
45
+ ): HarnessSpec {
46
+ if (failures.length === 0) {
47
+ return spec;
48
+ }
49
+
50
+ const allMutations = [];
51
+ for (const failure of failures) {
52
+ const nodeId = extractNodeIdFromFailure(failure) ?? spec.graph.entryNodeId;
53
+ const ctx = { nodeId };
54
+ const mutations = deriveMutationsFromFailure(failure, spec, ctx);
55
+ allMutations.push(...mutations);
56
+ }
57
+
58
+ if (allMutations.length === 0) {
59
+ return spec;
60
+ }
61
+
62
+ const limitedMutations = this.config.mutationPolicy
63
+ ? enforceMutationPolicy(allMutations, this.config.mutationPolicy)
64
+ : allMutations;
65
+
66
+ const result = mutateHarness(spec, limitedMutations, this.config.mutationPolicy);
67
+ return result.spec;
68
+ }
69
+
70
+ async generateHarness(
71
+ intent: string,
72
+ config?: MetaHarnessConfig,
73
+ ): Promise<MetaHarnessResult> {
74
+ const effectiveConfig = config ?? this.config;
75
+
76
+ // 1. Discover environment (use cached if provided)
77
+ let env: EnvironmentModel;
78
+ if (effectiveConfig.environmentModel) {
79
+ env = effectiveConfig.environmentModel;
80
+ } else {
81
+ env = await this.discoverEnvironment();
82
+ }
83
+
84
+ const envAnalysis = analyzeEnvironment(env);
85
+
86
+ // 2. Query memory for advice
87
+ let memoryAdvice: MemoryAdvice | undefined;
88
+ if (effectiveConfig.memoryStore) {
89
+ memoryAdvice = await adviseFromMemory(intent, effectiveConfig.memoryStore);
90
+ if (memoryAdvice.suggestions.length === 0 && memoryAdvice.warnings.length === 0) {
91
+ memoryAdvice = undefined;
92
+ }
93
+ }
94
+
95
+ // 3. Plan workflow from intent
96
+ const plannerResult = planWorkflowRequest(
97
+ intent,
98
+ effectiveConfig.capabilityRegistry,
99
+ env,
100
+ );
101
+
102
+ let spec: HarnessSpec;
103
+ if (plannerResult.status === "draft_request") {
104
+ const parsed = parsePromptOrSkill(intent);
105
+ const taskGraph = buildTaskGraph(
106
+ parsed.success ? parsed.intent : {
107
+ family: "custom",
108
+ goal: intent,
109
+ inputs: {},
110
+ requiredTools: [],
111
+ humanCheckpoints: [],
112
+ verificationTargets: [],
113
+ },
114
+ effectiveConfig.capabilityRegistry,
115
+ env,
116
+ );
117
+ const risks = analyzeRisks(taskGraph, effectiveConfig.capabilityRegistry);
118
+ spec = synthesizeHarness(taskGraph, risks);
119
+ } else {
120
+ spec = makeFallbackSpec(intent);
121
+ }
122
+
123
+ // 4. Predict failures
124
+ const predictedFailures = await this.predictFailures(spec, env);
125
+
126
+ // 4b. Generate failure modes from task description
127
+ const generatedFailureModes = generateFailureModes(intent, env, spec);
128
+
129
+ // 5. Synthesize policies (mutate spec)
130
+ spec = this.synthesizePolicies(spec, predictedFailures);
131
+
132
+ // 6. Compile, analyze, and apply feedback loop
133
+ let optimizations: string[] = [];
134
+ let compilerOptimizations: string[] = [];
135
+ let compilerAnalysis: CompilerAnalysis | undefined;
136
+ const appliedMutations: HarnessMutation[] = [];
137
+
138
+ try {
139
+ let compiled = compileHarnessSpec(spec);
140
+ if (compiled.optimizations) {
141
+ optimizations = compiled.optimizations;
142
+ }
143
+
144
+ // Analyze the compiled workflow
145
+ compilerAnalysis = analyzeCompiledWorkflow(compiled);
146
+
147
+ // Use mutations directly from the feedback engine
148
+ const feedbackMutations = compilerAnalysis.mutations.filter(
149
+ m => m.trigger === "retry_exhausted" || m.trigger === "verification_failed" || m.trigger === "cost_high"
150
+ );
151
+
152
+ if (feedbackMutations.length > 0) {
153
+ const limitedMutations = this.config.mutationPolicy
154
+ ? enforceMutationPolicy(feedbackMutations, this.config.mutationPolicy)
155
+ : feedbackMutations;
156
+
157
+ const mutationResult = mutateHarness(spec, limitedMutations);
158
+ spec = mutationResult.spec;
159
+ appliedMutations.push(...limitedMutations);
160
+ compilerOptimizations = limitedMutations.map(m => m.description ?? m.type);
161
+
162
+ // Recompile with the modified spec
163
+ compiled = compileHarnessSpec(spec);
164
+ if (compiled.optimizations) {
165
+ optimizations = compiled.optimizations;
166
+ }
167
+
168
+ // Re-analyze after recompilation
169
+ compilerAnalysis = analyzeCompiledWorkflow(compiled);
170
+ }
171
+ } catch {
172
+ // If compilation fails, still return the spec without optimizations
173
+ }
174
+
175
+ // 7. Calculate readiness score
176
+ const readinessScore = calculateReadinessScore(envAnalysis, predictedFailures);
177
+
178
+ return {
179
+ spec,
180
+ environmentAnalysis: envAnalysis,
181
+ memoryAdvice,
182
+ predictedFailures,
183
+ generatedFailureModes,
184
+ optimizations,
185
+ readinessScore,
186
+ compilerAnalysis,
187
+ compilerOptimizations,
188
+ appliedMutations,
189
+ };
190
+ }
191
+
192
+ composeHarnesses(stages: HarnessStage[]): CompositionResult {
193
+ return chainHarnesses(stages);
194
+ }
195
+
196
+ composeParallel(harnesses: HarnessSpec[]): CompositionResult {
197
+ return parallelHarnesses(harnesses);
198
+ }
199
+
200
+ composeConditional(condition: string, trueHarness: HarnessSpec, falseHarness?: HarnessSpec): CompositionResult {
201
+ return conditionalHarness(condition, trueHarness, falseHarness);
202
+ }
203
+ }
204
+
205
+ function extractNodeIdFromFailure(failure: FailureSignature): string | undefined {
206
+ for (const evidence of failure.evidence) {
207
+ const match = evidence.match(/^node:\s*(.+)$/);
208
+ if (match) {
209
+ return match[1].trim();
210
+ }
211
+ }
212
+ return undefined;
213
+ }
214
+
215
+ function enforceMutationPolicy(
216
+ mutations: ReturnType<typeof deriveMutationsFromFailure>,
217
+ policy: MutationPolicy,
218
+ ): ReturnType<typeof deriveMutationsFromFailure> {
219
+ const allowed = new Set(policy.allowedMutations);
220
+ const filtered = mutations.filter(m => allowed.has(m.type));
221
+ return filtered.slice(0, policy.maxMutations);
222
+ }
223
+
224
+ function makeFallbackSpec(intent: string): HarnessSpec {
225
+ const safeName = intent.slice(0, 50).replace(/[^a-zA-Z0-9\s-]/g, "").trim().replace(/\s+/g, "-").toLowerCase() || "meta-harness";
226
+ return {
227
+ name: safeName,
228
+ graph: {
229
+ entryNodeId: "intent-node",
230
+ nodes: [
231
+ {
232
+ id: "intent-node",
233
+ label: intent.slice(0, 100),
234
+ kind: "tool",
235
+ tool: "echo",
236
+ args: [intent],
237
+ },
238
+ ],
239
+ edges: [],
240
+ },
241
+ };
242
+ }
243
+
244
+ function calculateReadinessScore(
245
+ envAnalysis: EnvironmentAnalysis,
246
+ predictedFailures: FailureSignature[],
247
+ ): number {
248
+ let score = envAnalysis.readinessScore;
249
+
250
+ for (const failure of predictedFailures) {
251
+ const penalty = Math.round(failure.confidence * 15);
252
+ score = Math.max(0, score - penalty);
253
+ }
254
+
255
+ return Math.min(100, Math.max(0, score));
256
+ }
@@ -0,0 +1,168 @@
1
+ import type { HarnessSpec, TaskNode } from "../spec/types.js";
2
+ import type { EnvironmentModel } from "../environment/types.js";
3
+ import type { FailureSignature } from "../failures/ontology.js";
4
+
5
+ const DISK_CRITICAL_THRESHOLD = 90;
6
+
7
+ export function predictFailuresFromEnvironment(
8
+ spec: HarnessSpec,
9
+ env: EnvironmentModel,
10
+ ): FailureSignature[] {
11
+ const failures: FailureSignature[] = [];
12
+
13
+ for (const node of spec.graph.nodes) {
14
+ const nodeFailures = predictNodeFailures(node, env);
15
+ failures.push(...nodeFailures);
16
+ }
17
+
18
+ const constraintFailures = predictConstraintFailures(env);
19
+ failures.push(...constraintFailures);
20
+
21
+ const authFailures = predictAuthFailures(spec, env);
22
+ failures.push(...authFailures);
23
+
24
+ const resourceFailures = predictResourceFailures(env);
25
+ failures.push(...resourceFailures);
26
+
27
+ return failures;
28
+ }
29
+
30
+ function predictNodeFailures(
31
+ node: TaskNode,
32
+ env: EnvironmentModel,
33
+ ): FailureSignature[] {
34
+ if (node.kind !== "tool") {
35
+ return [];
36
+ }
37
+
38
+ const toolName = node.tool;
39
+ const availableTool = env.tools.find(t => t.name === toolName);
40
+
41
+ if (!availableTool || !availableTool.available) {
42
+ return [
43
+ {
44
+ class: "tool",
45
+ confidence: 0.85,
46
+ evidence: [
47
+ `node: ${node.id}`,
48
+ `tool "${toolName}" is not available in environment`,
49
+ ],
50
+ suggestedRecovery: [
51
+ `Install "${toolName}" and ensure it is in PATH`,
52
+ "Verify tool version compatibility",
53
+ ],
54
+ retryable: false,
55
+ requiresHumanIntervention: true,
56
+ },
57
+ ];
58
+ }
59
+
60
+ return [];
61
+ }
62
+
63
+ function predictConstraintFailures(env: EnvironmentModel): FailureSignature[] {
64
+ const failures: FailureSignature[] = [];
65
+
66
+ for (const constraint of env.constraints) {
67
+ if (constraint.severity === "high") {
68
+ failures.push({
69
+ class: constraint.type === "auth" ? "auth" : "unknown",
70
+ confidence: 0.8,
71
+ evidence: [
72
+ `constraint: ${constraint.description}`,
73
+ `severity: ${constraint.severity}`,
74
+ ],
75
+ suggestedRecovery: [
76
+ `Address constraint: ${constraint.description}`,
77
+ "Review environment configuration",
78
+ ],
79
+ retryable: false,
80
+ requiresHumanIntervention: constraint.type === "auth" || constraint.type === "permission",
81
+ });
82
+ }
83
+ }
84
+
85
+ return failures;
86
+ }
87
+
88
+ function predictAuthFailures(
89
+ spec: HarnessSpec,
90
+ env: EnvironmentModel,
91
+ ): FailureSignature[] {
92
+ const failures: FailureSignature[] = [];
93
+
94
+ for (const auth of env.authState) {
95
+ if (!auth.authenticated) {
96
+ failures.push({
97
+ class: "auth",
98
+ confidence: 0.9,
99
+ evidence: [
100
+ `system "${auth.system}" is not authenticated`,
101
+ ],
102
+ suggestedRecovery: [
103
+ `Authenticate with "${auth.system}" before running harness`,
104
+ "Check token expiry and renew if necessary",
105
+ "Verify API keys or secrets are correctly configured",
106
+ ],
107
+ retryable: false,
108
+ requiresHumanIntervention: true,
109
+ });
110
+ }
111
+ }
112
+
113
+ return failures;
114
+ }
115
+
116
+ function predictResourceFailures(env: EnvironmentModel): FailureSignature[] {
117
+ const failures: FailureSignature[] = [];
118
+
119
+ for (const resource of env.resources) {
120
+ if (!resource.available) {
121
+ failures.push({
122
+ class: "resource",
123
+ confidence: 0.9,
124
+ evidence: [
125
+ `resource "${resource.name}" is not available`,
126
+ `type: ${resource.type}`,
127
+ ],
128
+ suggestedRecovery: [
129
+ `Free up or provision "${resource.name}" resource`,
130
+ "Check available disk space and clean up if necessary",
131
+ ],
132
+ retryable: true,
133
+ requiresHumanIntervention: false,
134
+ });
135
+ continue;
136
+ }
137
+
138
+ if (resource.type === "disk" && resource.usage) {
139
+ const usagePct = parseUsagePercentage(resource.usage);
140
+ if (usagePct >= DISK_CRITICAL_THRESHOLD) {
141
+ failures.push({
142
+ class: "resource",
143
+ confidence: 0.85,
144
+ evidence: [
145
+ `disk usage is critical: ${resource.usage}`,
146
+ `threshold: ${DISK_CRITICAL_THRESHOLD}%`,
147
+ ],
148
+ suggestedRecovery: [
149
+ "Clean up disk space before running harness",
150
+ "Remove temporary files and unused artifacts",
151
+ ],
152
+ retryable: true,
153
+ requiresHumanIntervention: false,
154
+ });
155
+ }
156
+ }
157
+ }
158
+
159
+ return failures;
160
+ }
161
+
162
+ function parseUsagePercentage(usage: string): number {
163
+ const match = usage.match(/(\d+)%/);
164
+ if (match) {
165
+ return parseInt(match[1], 10);
166
+ }
167
+ return 0;
168
+ }
@@ -0,0 +1,40 @@
1
+ import type { HarnessSpec } from "../spec/types.js";
2
+ import type { EnvironmentModel, EnvironmentAnalysis } from "../environment/types.js";
3
+ import type { FailureSignature } from "../failures/ontology.js";
4
+ import type { FailureModeGeneration } from "../failures/generator.js";
5
+ import type { MemoryAdvice, MemoryStore } from "../memory/types.js";
6
+ import type { CapabilityRegistry } from "../capabilities/types.js";
7
+ import type { MutationPolicy, HarnessMutation } from "../mutation/types.js";
8
+ import type { CompilerAnalysis, CompilerSuggestion } from "../compiler/feedback.js";
9
+ import type { HarnessStage, CompositionResult } from "../composition/types.js";
10
+
11
+ export interface MetaHarnessConfig {
12
+ environmentModel?: EnvironmentModel;
13
+ memoryStore?: MemoryStore;
14
+ capabilityRegistry?: CapabilityRegistry;
15
+ maxVersions?: number;
16
+ mutationPolicy?: MutationPolicy;
17
+ }
18
+
19
+ export interface MetaHarnessResult {
20
+ spec: HarnessSpec;
21
+ environmentAnalysis?: EnvironmentAnalysis;
22
+ memoryAdvice?: MemoryAdvice;
23
+ predictedFailures: FailureSignature[];
24
+ generatedFailureModes?: FailureModeGeneration;
25
+ optimizations: string[];
26
+ readinessScore: number;
27
+ compilerAnalysis?: CompilerAnalysis;
28
+ compilerOptimizations: string[];
29
+ appliedMutations: HarnessMutation[];
30
+ }
31
+
32
+ export interface MetaHarness {
33
+ discoverEnvironment(repoPath?: string): Promise<EnvironmentModel>;
34
+ predictFailures(spec: HarnessSpec, env: EnvironmentModel): Promise<FailureSignature[]>;
35
+ synthesizePolicies(spec: HarnessSpec, failures: FailureSignature[]): HarnessSpec;
36
+ generateHarness(intent: string, config?: MetaHarnessConfig): Promise<MetaHarnessResult>;
37
+ composeHarnesses(stages: HarnessStage[]): CompositionResult;
38
+ composeParallel(harnesses: HarnessSpec[]): CompositionResult;
39
+ composeConditional(condition: string, trueHarness: HarnessSpec, falseHarness?: HarnessSpec): CompositionResult;
40
+ }