millforge 0.1.0__py3-none-any.whl

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 (116) hide show
  1. millforge/__init__.py +1174 -0
  2. millforge/_forge/LICENSE +21 -0
  3. millforge/_forge/PROVENANCE.json +295 -0
  4. millforge/_forge/UPDATE_POLICY.md +24 -0
  5. millforge/_forge/__init__.py +14 -0
  6. millforge/_forge/adapter.py +2232 -0
  7. millforge/_forge/base_runner.py +121 -0
  8. millforge/_forge/clients/__init__.py +10 -0
  9. millforge/_forge/clients/base.py +200 -0
  10. millforge/_forge/context/__init__.py +23 -0
  11. millforge/_forge/context/manager.py +178 -0
  12. millforge/_forge/context/strategies.py +335 -0
  13. millforge/_forge/core/__init__.py +16 -0
  14. millforge/_forge/core/inference.py +433 -0
  15. millforge/_forge/core/messages.py +119 -0
  16. millforge/_forge/core/runner.py +479 -0
  17. millforge/_forge/core/steps.py +108 -0
  18. millforge/_forge/core/workflow.py +400 -0
  19. millforge/_forge/errors.py +222 -0
  20. millforge/_forge/guardrails/__init__.py +21 -0
  21. millforge/_forge/guardrails/error_tracker.py +71 -0
  22. millforge/_forge/guardrails/guardrails.py +194 -0
  23. millforge/_forge/guardrails/nudge.py +47 -0
  24. millforge/_forge/guardrails/response_validator.py +119 -0
  25. millforge/_forge/guardrails/step_enforcer.py +183 -0
  26. millforge/_forge/prompts/__init__.py +16 -0
  27. millforge/_forge/prompts/nudges.py +95 -0
  28. millforge/_forge/prompts/templates.py +285 -0
  29. millforge/_version.py +3 -0
  30. millforge/artifacts.py +570 -0
  31. millforge/base/__init__.py +97 -0
  32. millforge/base/composition.py +402 -0
  33. millforge/base/context.py +285 -0
  34. millforge/base/harness.py +138 -0
  35. millforge/base/identity.py +465 -0
  36. millforge/base/options.py +34 -0
  37. millforge/base/platform.py +17 -0
  38. millforge/base/prompt.py +317 -0
  39. millforge/base/runner.py +546 -0
  40. millforge/compiled_plan.py +970 -0
  41. millforge/compiler/__init__.py +231 -0
  42. millforge/compiler/artifact_validation.py +257 -0
  43. millforge/compiler/canonicalization.py +169 -0
  44. millforge/compiler/capabilities.py +66 -0
  45. millforge/compiler/catalogs.py +500 -0
  46. millforge/compiler/diagnostics.py +491 -0
  47. millforge/compiler/graph.py +678 -0
  48. millforge/compiler/lowering.py +198 -0
  49. millforge/compiler/output.py +692 -0
  50. millforge/compiler/parsing.py +1424 -0
  51. millforge/compiler/requests.py +1180 -0
  52. millforge/compiler/schema_validation.py +272 -0
  53. millforge/compiler/semantic.py +490 -0
  54. millforge/compiler/service.py +448 -0
  55. millforge/compiler/source.py +375 -0
  56. millforge/compiler/validators.py +184 -0
  57. millforge/connectors/__init__.py +95 -0
  58. millforge/connectors/admission.py +801 -0
  59. millforge/connectors/broker.py +202 -0
  60. millforge/connectors/contracts.py +1159 -0
  61. millforge/connectors/diagnostics.py +189 -0
  62. millforge/connectors/fake.py +66 -0
  63. millforge/connectors/runtime.py +236 -0
  64. millforge/contracts.py +2860 -0
  65. millforge/custom_tools/__init__.py +67 -0
  66. millforge/custom_tools/compiler.py +724 -0
  67. millforge/custom_tools/contracts.py +1093 -0
  68. millforge/custom_tools/diagnostics.py +205 -0
  69. millforge/eval_artifacts.py +952 -0
  70. millforge/eval_boundary.py +2435 -0
  71. millforge/eval_fixtures/__init__.py +1 -0
  72. millforge/eval_fixtures/default_pack/__init__.py +1 -0
  73. millforge/eval_fixtures/default_pack/fixtures/fixture.08a.bug_diagnosis.traceback.v1.json +52 -0
  74. millforge/eval_fixtures/default_pack/fixtures/fixture.08a.direct_edit.import_sort.v1.json +52 -0
  75. millforge/eval_fixtures/default_pack/fixtures/fixture.08a.evidence_discipline.no_source_change.v1.json +51 -0
  76. millforge/eval_fixtures/default_pack/fixtures/fixture.08a.false_closure.visible_green.v1.json +52 -0
  77. millforge/eval_fixtures/default_pack/fixtures/fixture.08a.multi_file.api_contract.v1.json +54 -0
  78. millforge/eval_fixtures/default_pack/fixtures/fixture.08a.recovery.malformed_artifact.v1.json +54 -0
  79. millforge/eval_fixtures/default_pack/manifest.json +12 -0
  80. millforge/eval_modes.py +1282 -0
  81. millforge/eval_presets.py +1398 -0
  82. millforge/eval_reports.py +2517 -0
  83. millforge/eval_suite.py +2429 -0
  84. millforge/eval_trials.py +2632 -0
  85. millforge/eval_workflow.py +794 -0
  86. millforge/exceptions.py +122 -0
  87. millforge/model_backend.py +2098 -0
  88. millforge/protocols.py +340 -0
  89. millforge/py.typed +0 -0
  90. millforge/runtime.py +1791 -0
  91. millforge/testing/__init__.py +1089 -0
  92. millforge/tools/__init__.py +83 -0
  93. millforge/tools/builtin_runtime.py +1339 -0
  94. millforge/tools/builtins.py +773 -0
  95. millforge/tools/execution.py +1545 -0
  96. millforge/tools/path_policy.py +155 -0
  97. millforge/tools/pi_compat/PI_LICENSE +21 -0
  98. millforge/tools/pi_compat/PROVENANCE.json +55 -0
  99. millforge/tools/pi_compat/UPDATE_POLICY.md +36 -0
  100. millforge/tools/pi_compat/__init__.py +34 -0
  101. millforge/tools/pi_compat/contracts.py +49 -0
  102. millforge/tools/pi_compat/editing.py +390 -0
  103. millforge/tools/pi_compat/mutations.py +57 -0
  104. millforge/tools/pi_compat/operations.py +401 -0
  105. millforge/tools/pi_compat/paths.py +155 -0
  106. millforge/tools/pi_compat/process.py +1375 -0
  107. millforge/tools/pi_compat/search.py +738 -0
  108. millforge/tools/pi_compat/truncation.py +267 -0
  109. millforge/tools/pi_compat_catalog.py +396 -0
  110. millforge/tools/pi_compat_runtime.py +460 -0
  111. millforge/tools/registry.py +553 -0
  112. millforge/tools/results.py +533 -0
  113. millforge-0.1.0.dist-info/METADATA +844 -0
  114. millforge-0.1.0.dist-info/RECORD +116 -0
  115. millforge-0.1.0.dist-info/WHEEL +4 -0
  116. millforge-0.1.0.dist-info/licenses/LICENSE +201 -0
millforge/protocols.py ADDED
@@ -0,0 +1,340 @@
1
+ """Protocol definitions for the Millforge runtime.
2
+
3
+ Each protocol defines the interface contract that real implementations
4
+ and test doubles must satisfy. All types used in method signatures are
5
+ Millforge-owned contract types — Forge types are never exposed.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from datetime import datetime
11
+ from typing import Any, Protocol, runtime_checkable
12
+
13
+ from millforge.compiled_plan import CompiledHarnessPlan
14
+ from millforge.contracts import (
15
+ ArtifactRef,
16
+ CancellationRef,
17
+ CompiledHarnessRef,
18
+ GuardedSessionRequest,
19
+ GuardedSessionResult,
20
+ HarnessExecutionRequest,
21
+ HarnessExecutionResult,
22
+ ModelCompletionRequest,
23
+ ModelCompletionResponse,
24
+ ToolExecutionContext,
25
+ ToolExecutionResult,
26
+ ValidatedToolCall,
27
+ )
28
+
29
+
30
+ @runtime_checkable
31
+ class AsyncHttpTransport(Protocol):
32
+ """Caller-owned async HTTP transport accepted by the live factory.
33
+
34
+ ``httpx.AsyncBaseTransport`` implements this shape. Keeping the public
35
+ protocol provider-neutral preserves the package boundary that confines the
36
+ concrete HTTP dependency to ``millforge.model_backend``.
37
+ """
38
+
39
+ async def handle_async_request(self, request: Any) -> Any:
40
+ """Handle one async HTTP request."""
41
+ ...
42
+
43
+ async def aclose(self) -> None:
44
+ """Close transport resources when the caller chooses."""
45
+ ...
46
+
47
+
48
+ @runtime_checkable
49
+ class CancellationToken(Protocol):
50
+ """Protocol for cancellation tokens.
51
+
52
+ Provides an invocation-scoped identifier and synchronous check for
53
+ whether cancellation has been requested. Implementations may back
54
+ this with in-memory state, a remote signal, or a composite
55
+ of multiple sources.
56
+
57
+ This is intentionally a plain Protocol (not a Pydantic model)
58
+ to keep it independent of the Pydantic hierarchy — cancellation
59
+ state spans across run boundaries and should not be serialised
60
+ as a contract value.
61
+ """
62
+
63
+ @property
64
+ def cancellation_id(self) -> str:
65
+ """Return the cancellation identifier."""
66
+ ...
67
+
68
+ def is_cancelled(self) -> bool:
69
+ """Check whether cancellation has been requested."""
70
+ ...
71
+
72
+ async def wait(self) -> None:
73
+ """Wait until cancellation is requested."""
74
+ ...
75
+
76
+ @property
77
+ def reason(self) -> str | None:
78
+ """Return a bounded cancellation reason, when present."""
79
+ ...
80
+
81
+
82
+ @runtime_checkable
83
+ class CancellationResolver(Protocol):
84
+ """Protocol for resolving cancellation tokens by reference.
85
+
86
+ Given a cancellation reference, returns a CancellationToken
87
+ that can be polled for cancellation status. This allows
88
+ passing lightweight string refs through serialisation boundaries
89
+ and resolving them into checkable tokens at the point of use.
90
+ """
91
+
92
+ def resolve(self, ref: CancellationRef) -> CancellationToken:
93
+ """Resolve a cancellation reference into a CancellationToken.
94
+
95
+ Parameters
96
+ ----------
97
+ ref : CancellationRef
98
+ The cancellation reference to resolve.
99
+
100
+ Returns
101
+ -------
102
+ CancellationToken
103
+ A checkable cancellation token.
104
+ """
105
+ ...
106
+
107
+
108
+ @runtime_checkable
109
+ class CompiledHarnessLoader(Protocol):
110
+ """Interface for loading compiled harness plans.
111
+
112
+ Implementations load a CompiledHarnessPlan from a CompiledHarnessRef,
113
+ performing any necessary deserialization and cryptographic verification
114
+ of the plan body before returning it.
115
+ """
116
+
117
+ async def load(self, ref: CompiledHarnessRef) -> CompiledHarnessPlan:
118
+ """Load a compiled harness plan from the given reference.
119
+
120
+ Parameters
121
+ ----------
122
+ ref : CompiledHarnessRef
123
+ Reference to the compiled harness, including its identity,
124
+ filesystem path, and expected cryptographic hash.
125
+
126
+ Returns
127
+ -------
128
+ CompiledHarnessPlan
129
+ The loaded and verified compiled harness plan.
130
+ """
131
+ ...
132
+
133
+
134
+ @runtime_checkable
135
+ class RuntimeArtifactWriter(Protocol):
136
+ """Interface for writing runtime artifacts.
137
+
138
+ Implementations write the seven standard artifact types that
139
+ the runtime produces during a harness run: terminal result,
140
+ execution summary, events, tool trace, metrics, artifact
141
+ manifest, and diagnostic output.
142
+
143
+ Each method accepts an ``ArtifactRef`` identifying the target
144
+ location and a ``data`` payload. Implementations handle
145
+ serialisation, atomic writes, and error reporting internally.
146
+ """
147
+
148
+ async def write_terminal_result(self, ref: ArtifactRef, data: Any) -> None:
149
+ """Write the terminal result artifact."""
150
+ ...
151
+
152
+ async def write_execution_summary(self, ref: ArtifactRef, data: Any) -> None:
153
+ """Write the execution summary artifact."""
154
+ ...
155
+
156
+ async def write_events(self, ref: ArtifactRef, data: Any) -> None:
157
+ """Write the events artifact (JSONL format)."""
158
+ ...
159
+
160
+ async def write_tool_trace(self, ref: ArtifactRef, data: Any) -> None:
161
+ """Write the tool trace artifact (JSONL format)."""
162
+ ...
163
+
164
+ async def write_metrics(self, ref: ArtifactRef, data: Any) -> None:
165
+ """Write the metrics artifact."""
166
+ ...
167
+
168
+ async def write_artifact_manifest(self, ref: ArtifactRef, data: Any) -> None:
169
+ """Write the artifact manifest artifact."""
170
+ ...
171
+
172
+ async def write_diagnostic(self, ref: ArtifactRef, data: Any) -> None:
173
+ """Write the diagnostic artifact."""
174
+ ...
175
+
176
+
177
+ @runtime_checkable
178
+ class RuntimeClock(Protocol):
179
+ """Interface for deterministic clock operations.
180
+
181
+ Provides UTC datetime and monotonic float access in a fully
182
+ deterministic manner. Implementations are synchronous by
183
+ design — no async dependencies — so that the clock can be
184
+ used in fake implementations without requiring an event loop.
185
+ """
186
+
187
+ def utc_now(self) -> datetime:
188
+ """Return the current UTC datetime.
189
+
190
+ Returns
191
+ -------
192
+ datetime
193
+ The current UTC datetime.
194
+ """
195
+ ...
196
+
197
+ def monotonic(self) -> float:
198
+ """Return a monotonic float value (fractional seconds).
199
+
200
+ The returned value is strictly increasing across calls and
201
+ is suitable for measuring elapsed time. The absolute value
202
+ has no meaning; only differences between successive calls
203
+ are meaningful.
204
+
205
+ Returns
206
+ -------
207
+ float
208
+ Monotonic time value in fractional seconds.
209
+ """
210
+ ...
211
+
212
+
213
+ @runtime_checkable
214
+ class HarnessRuntime(Protocol):
215
+ """Interface for compiled-harness interactions.
216
+
217
+ Implementations wrap access to compiled harness runtimes, providing
218
+ identity resolution and stage execution. All types used in method
219
+ signatures are Millforge-owned contract types.
220
+ """
221
+
222
+ async def execute(self, request: HarnessExecutionRequest) -> HarnessExecutionResult:
223
+ """Execute a compiled-harness stage.
224
+
225
+ Parameters
226
+ ----------
227
+ request : HarnessExecutionRequest
228
+ The harness execution request describing which stage to run
229
+ and under what identity, with capability grants and artifacts.
230
+
231
+ Returns
232
+ -------
233
+ HarnessExecutionResult
234
+ The result of the harness execution, including execution
235
+ status, result classification, timing, and diagnostics.
236
+ """
237
+ ...
238
+
239
+
240
+ @runtime_checkable
241
+ class GuardrailBackend(Protocol):
242
+ """Interface for guardrail translation and execution.
243
+
244
+ Implementations translate requests through guardrail policies and
245
+ return verdicts wrapped in Millforge session types. All types used
246
+ in method signatures are Millforge-owned contract types.
247
+ """
248
+
249
+ async def run_session(self, request: GuardedSessionRequest) -> GuardedSessionResult:
250
+ """Evaluate guardrails against a session request.
251
+
252
+ Parameters
253
+ ----------
254
+ request : GuardedSessionRequest
255
+ The guarded session request to evaluate.
256
+
257
+ Returns
258
+ -------
259
+ GuardedSessionResult
260
+ The guardrail evaluation result, including session status,
261
+ terminal intent, events, and tool trace records.
262
+ """
263
+ ...
264
+
265
+
266
+ @runtime_checkable
267
+ class ModelClient(Protocol):
268
+ """Interface for model invocation.
269
+
270
+ Implementations wrap LLM backends (HTTP, SDK, local inference, etc.)
271
+ and expose a single ``complete`` method that accepts a validated request
272
+ and returns a validated response. All types used in method signatures
273
+ are Millforge-owned contract types.
274
+ """
275
+
276
+ async def complete(
277
+ self, request: ModelCompletionRequest
278
+ ) -> ModelCompletionResponse:
279
+ """Send a validated model request and return the response.
280
+
281
+ Parameters
282
+ ----------
283
+ request : ModelCompletionRequest
284
+ The model completion request containing messages, tools,
285
+ temperature, and other parameters.
286
+
287
+ Returns
288
+ -------
289
+ ModelCompletionResponse
290
+ The model completion response including content, tool
291
+ calls, finish reason, and usage metadata.
292
+ """
293
+ ...
294
+
295
+
296
+ @runtime_checkable
297
+ class ToolExecutor(Protocol):
298
+ """Interface for tool execution.
299
+
300
+ Implementations wrap callable tools and provide a uniform interface
301
+ for invocation and capability discovery. All types used in method
302
+ signatures are Millforge-owned contract types.
303
+ """
304
+
305
+ async def execute(
306
+ self, call: ValidatedToolCall, context: ToolExecutionContext
307
+ ) -> ToolExecutionResult:
308
+ """Execute a validated tool call with execution context and return the result.
309
+
310
+ Parameters
311
+ ----------
312
+ call : ValidatedToolCall
313
+ The validated tool call specifying the tool name, call ID,
314
+ and arguments.
315
+ context : ToolExecutionContext
316
+ The execution context including request identity, stage,
317
+ run directory, capability envelope, timeout, and cancellation.
318
+
319
+ Returns
320
+ -------
321
+ ToolExecutionResult
322
+ The tool execution result including output text, error
323
+ information, and execution duration.
324
+ """
325
+ ...
326
+
327
+ def supports_tool(self, name: str) -> bool:
328
+ """Check whether a tool is supported by this executor.
329
+
330
+ Parameters
331
+ ----------
332
+ name : str
333
+ The name of the tool to check.
334
+
335
+ Returns
336
+ -------
337
+ bool
338
+ True if the tool is supported, False otherwise.
339
+ """
340
+ ...
millforge/py.typed ADDED
File without changes