workflow-coordinator 0.1.0b1__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.
- workflow_coordinator/__init__.py +1 -0
- workflow_coordinator/adapter.py +150 -0
- workflow_coordinator/claude_adapter.py +289 -0
- workflow_coordinator/codex_adapter.py +395 -0
- workflow_coordinator/codex_adapter_smoke.py +231 -0
- workflow_coordinator/commissioning.py +432 -0
- workflow_coordinator/evidence.py +481 -0
- workflow_coordinator/execution_boundary.py +187 -0
- workflow_coordinator/frontdoor/__init__.py +1 -0
- workflow_coordinator/frontdoor/archive.py +1496 -0
- workflow_coordinator/frontdoor/audit.py +589 -0
- workflow_coordinator/frontdoor/cli.py +42 -0
- workflow_coordinator/frontdoor/config.py +287 -0
- workflow_coordinator/frontdoor/init.py +228 -0
- workflow_coordinator/frontdoor/journal.py +284 -0
- workflow_coordinator/frontdoor/lifecycle.py +1093 -0
- workflow_coordinator/frontdoor/plan.py +311 -0
- workflow_coordinator/frontdoor/postrun.py +254 -0
- workflow_coordinator/frontdoor/preservation.py +132 -0
- workflow_coordinator/frontdoor/report.py +222 -0
- workflow_coordinator/frontdoor/request.py +170 -0
- workflow_coordinator/frontdoor/verify.py +137 -0
- workflow_coordinator/git_facts.py +1258 -0
- workflow_coordinator/implementation_identity.py +68 -0
- workflow_coordinator/model.py +958 -0
- workflow_coordinator/operator.py +1915 -0
- workflow_coordinator/persistence.py +599 -0
- workflow_coordinator/prompt.py +272 -0
- workflow_coordinator/proof_harness.py +295 -0
- workflow_coordinator/reducer.py +2006 -0
- workflow_coordinator/resources/agent_operating_contract_v6.txt +97 -0
- workflow_coordinator/resources/roles/reviewer.txt +41 -0
- workflow_coordinator/resources/roles/simple-self-check.txt +6 -0
- workflow_coordinator/resources/roles/worker.txt +24 -0
- workflow_coordinator/serialization.py +2392 -0
- workflow_coordinator/slice4.py +411 -0
- workflow_coordinator/structured_result_schema.py +266 -0
- workflow_coordinator/vertical.py +597 -0
- workflow_coordinator-0.1.0b1.dist-info/METADATA +120 -0
- workflow_coordinator-0.1.0b1.dist-info/RECORD +44 -0
- workflow_coordinator-0.1.0b1.dist-info/WHEEL +5 -0
- workflow_coordinator-0.1.0b1.dist-info/entry_points.txt +2 -0
- workflow_coordinator-0.1.0b1.dist-info/licenses/LICENSE +21 -0
- workflow_coordinator-0.1.0b1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
"""Closed-program, non-authoritative Commission compilation.
|
|
2
|
+
|
|
3
|
+
This module deliberately has no reducer integration and makes no provider
|
|
4
|
+
selection. It turns the small ``simple@v1``/``robust@v1`` Consumer Request
|
|
5
|
+
vocabulary into ordinary WFC governing files for the product Front Door;
|
|
6
|
+
re-verification and admission of those files live in
|
|
7
|
+
``frontdoor.verify.verify_commission`` rather than here.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import hashlib
|
|
13
|
+
import json
|
|
14
|
+
import re
|
|
15
|
+
import subprocess
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
from importlib.resources import files as _resource_files
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Any, Mapping
|
|
20
|
+
|
|
21
|
+
import yaml
|
|
22
|
+
from yaml.constructor import ConstructorError
|
|
23
|
+
|
|
24
|
+
from .implementation_identity import RESOURCE_DIGESTS as _PACKAGE_RESOURCE_DIGESTS, VERSION as _PACKAGE_VERSION
|
|
25
|
+
from .serialization import (
|
|
26
|
+
ValidationError,
|
|
27
|
+
a1_path_shape,
|
|
28
|
+
component_manifest_from_yaml,
|
|
29
|
+
repository_policy_from_yaml,
|
|
30
|
+
workflow_profile_from_yaml,
|
|
31
|
+
work_item_from_yaml,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class CommissionError(ValueError):
|
|
36
|
+
"""A fail-closed Intent, source-pin, or projection refusal."""
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
_SHA = re.compile(r"[0-9a-f]{40}\Z")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class _IntentLoader(yaml.SafeLoader):
|
|
43
|
+
"""Safe YAML with duplicate mappings refused instead of silently merged."""
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _construct_unique_mapping(loader: _IntentLoader, node: yaml.MappingNode, deep: bool = False):
|
|
47
|
+
loader.flatten_mapping(node)
|
|
48
|
+
result: dict[Any, Any] = {}
|
|
49
|
+
for key_node, value_node in node.value:
|
|
50
|
+
key = loader.construct_object(key_node, deep=deep)
|
|
51
|
+
if key in result:
|
|
52
|
+
raise ConstructorError("while constructing a mapping", node.start_mark, f"duplicate key: {key}", key_node.start_mark)
|
|
53
|
+
result[key] = loader.construct_object(value_node, deep=deep)
|
|
54
|
+
return result
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
_IntentLoader.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, _construct_unique_mapping)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _yaml_load(text: str, *, context: str) -> Any:
|
|
61
|
+
try:
|
|
62
|
+
return yaml.load(text, Loader=_IntentLoader)
|
|
63
|
+
except yaml.YAMLError as error:
|
|
64
|
+
raise CommissionError(f"invalid {context} YAML: {error}") from error
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@dataclass(frozen=True)
|
|
68
|
+
class TaskBinding:
|
|
69
|
+
title: str
|
|
70
|
+
body: str
|
|
71
|
+
acceptance: str
|
|
72
|
+
withheld_authority: str
|
|
73
|
+
escalation_default: str
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _mapping(value: Any, *, context: str, required: set[str], optional: set[str] = set()) -> dict[str, Any]:
|
|
77
|
+
if not isinstance(value, dict):
|
|
78
|
+
raise CommissionError(f"{context} must be a mapping")
|
|
79
|
+
keys = set(value)
|
|
80
|
+
unexpected = keys - required - optional
|
|
81
|
+
missing = required - keys
|
|
82
|
+
if unexpected:
|
|
83
|
+
raise CommissionError(f"{context} contains forbidden field(s): {', '.join(sorted(unexpected))}")
|
|
84
|
+
if missing:
|
|
85
|
+
raise CommissionError(f"{context} is missing required field(s): {', '.join(sorted(missing))}")
|
|
86
|
+
if any(not isinstance(key, str) for key in value):
|
|
87
|
+
raise CommissionError(f"{context} keys must be strings")
|
|
88
|
+
return value
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _text(value: Any, *, context: str) -> str:
|
|
92
|
+
if not isinstance(value, str) or not value.strip():
|
|
93
|
+
raise CommissionError(f"{context} must be a non-empty string")
|
|
94
|
+
return value
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _path(value: Any, *, context: str) -> str:
|
|
98
|
+
text = _text(value, context=context)
|
|
99
|
+
# Rendering must reject exactly the malformed paths that canonical
|
|
100
|
+
# admission rejects; otherwise it could emit a bundle guaranteed to fail
|
|
101
|
+
# later preflight. Keep that shape predicate in serialization as the
|
|
102
|
+
# single library definition rather than reproducing a near-match here.
|
|
103
|
+
if not a1_path_shape(text):
|
|
104
|
+
raise CommissionError(f"{context} must be an A1-normalized repository-relative path")
|
|
105
|
+
return text
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _git_text(repository: Path, commit: str, path: str, *, context: str) -> str:
|
|
109
|
+
path = _path(path, context=context)
|
|
110
|
+
found = subprocess.run(
|
|
111
|
+
("git", "-C", str(repository), "ls-tree", "-r", "--name-only", commit, "--", path),
|
|
112
|
+
capture_output=True, text=True,
|
|
113
|
+
)
|
|
114
|
+
if found.returncode or found.stdout.splitlines() != [path]:
|
|
115
|
+
raise CommissionError(f"{context} is absent or ambiguous at pinned source commit {commit}: {path}")
|
|
116
|
+
blob = subprocess.run(("git", "-C", str(repository), "show", f"{commit}:{path}"), capture_output=True, text=True)
|
|
117
|
+
if blob.returncode:
|
|
118
|
+
raise CommissionError(f"unable to read {context} at pinned source commit {commit}: {path}")
|
|
119
|
+
return blob.stdout
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _sha(text: str) -> str:
|
|
123
|
+
return hashlib.sha256(text.encode("utf-8")).hexdigest()
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _within(path: str, scope: tuple[str, ...]) -> bool:
|
|
127
|
+
return any(path == root or path.startswith(root.rstrip("/") + "/") for root in scope)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _robust_template() -> dict[str, Any]:
|
|
131
|
+
"""The accepted robust@v1 literal record, excluding catalogue provenance."""
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
"schema_version": 1, "program_id": "robust", "revision": "v1",
|
|
135
|
+
"roles": ["worker", "independent_reviewer"], "scope_slot": "S", "artifact_scope_slot": "A",
|
|
136
|
+
"evidence_profiles": {"task-check-v1": {"evidence": ["task-check"]}},
|
|
137
|
+
"phases": {
|
|
138
|
+
"implement": {"role": "worker", "components": {"role": ["worker"], "modifiers": [], "repository_policy": []}, "durable_artifact": "none", "scope": "S", "artifact_key": None, "authorized_actions": ["edit", "commit"], "human_gates": [], "evidence": [], "review": None, "routes": {"broad_review": {"effect": "goto", "target": "broad_review"}}},
|
|
139
|
+
"broad_review": {"role": "independent_reviewer", "components": {"role": ["reviewer"], "modifiers": [], "repository_policy": []}, "durable_artifact": "required", "scope": "A", "artifact_key": "broad_review", "authorized_actions": ["review", "edit", "commit"], "human_gates": [], "evidence": "E", "review": {"purpose": "independent adversarial full-scope review of the rendered Commission", "breadth": "broad", "authority": "gate", "context": "fresh", "blocking_policy": "blocking_only", "trigger": "profile_selected", "exit": "declared_route", "finding_authority": ["resolve"], "failed_evidence_route": "correction"}, "routes": {"accept": {"effect": "complete"}, "correction": {"effect": "goto", "target": "correct"}}},
|
|
140
|
+
"correct": {"role": "worker", "components": {"role": ["worker"], "modifiers": [], "repository_policy": []}, "durable_artifact": "none", "scope": "S", "artifact_key": None, "authorized_actions": ["edit", "commit"], "human_gates": [], "evidence": [], "review": None, "routes": {"focused_review": {"effect": "goto", "target": "focused_review"}}},
|
|
141
|
+
"focused_review": {"role": "independent_reviewer", "components": {"role": ["reviewer"], "modifiers": [], "repository_policy": []}, "durable_artifact": "required", "scope": "A", "artifact_key": "focused_review", "authorized_actions": ["review", "edit", "commit"], "human_gates": [], "evidence": "E", "review": {"purpose": "independent focused verification of correction and disposition of the prior broad/focused Findings", "breadth": "focused", "authority": "gate", "context": "fresh", "blocking_policy": "blocking_only", "trigger": "profile_selected", "exit": "declared_route", "finding_authority": ["resolve"], "failed_evidence_route": "correction"}, "routes": {"correction": {"effect": "goto", "target": "correct"}, "renew_broad_review": {"effect": "goto", "target": "broad_review"}}},
|
|
142
|
+
},
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def _simple_template() -> dict[str, Any]:
|
|
147
|
+
"""The accepted simple@v1 literal record, excluding catalogue provenance."""
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
"schema_version": 1, "program_id": "simple", "revision": "v1", "roles": ["worker"], "scope_slot": "S",
|
|
151
|
+
"evidence_profiles": {"task-check-v1": {"evidence": ["task-check"]}},
|
|
152
|
+
"phases": {
|
|
153
|
+
"implement": {"role": "worker", "components": {"role": ["worker"], "modifiers": ["simple-self-check"], "repository_policy": []}, "durable_artifact": "none", "scope": "S", "authorized_actions": ["edit", "commit"], "human_gates": [], "evidence": "E", "review": None, "routes": {"accept": {"effect": "complete"}}},
|
|
154
|
+
},
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def _yaml(data: Mapping[str, Any]) -> str:
|
|
159
|
+
return yaml.safe_dump(dict(data), sort_keys=False, allow_unicode=True)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def _task_text(request: Any) -> str:
|
|
163
|
+
task = request.task
|
|
164
|
+
return (
|
|
165
|
+
f"# {task.title}\n\n{task.body}\n\n## Acceptance\n\n{task.acceptance}\n\n"
|
|
166
|
+
f"## Withheld authority\n\n{task.withheld_authority}\n\n## Default escalation\n\n{task.escalation_default}\n"
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _tree_text(repository: Path, head: str, path: str, *, context: str) -> str:
|
|
171
|
+
return _git_text(repository, head, path, context=context)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
# ---------------------------------------------------------------------------
|
|
175
|
+
# BP2b -- consumer-neutral compilation with execution bindings kept separate.
|
|
176
|
+
#
|
|
177
|
+
# ``compile_commission`` compiles a bounded Commission for an arbitrary
|
|
178
|
+
# (non-WFC) consumer repository from package-owned product resources
|
|
179
|
+
# (``resources/roles/*.txt``, digest-checked against
|
|
180
|
+
# ``implementation_identity.RESOURCE_DIGESTS``) and a consumer-authored
|
|
181
|
+
# ``repository_policy`` guidance file already tracked in the consumer's own
|
|
182
|
+
# repository. Execution bindings are never read, written, or admitted here;
|
|
183
|
+
# ``frontdoor.config.resolve_execution`` produces a separate envelope whose
|
|
184
|
+
# identity is independent of these Commission bytes (C1). Re-verification
|
|
185
|
+
# and admission (``frontdoor.verify.verify_commission``) live in
|
|
186
|
+
# ``frontdoor`` rather than here, since that is the only BP2b step that must
|
|
187
|
+
# parse ``ConsumerRequest``/``ConsumerConfig`` text and the kernel
|
|
188
|
+
# import-direction invariant refuses any kernel module naming ``frontdoor``.
|
|
189
|
+
# ---------------------------------------------------------------------------
|
|
190
|
+
|
|
191
|
+
_CONSUMER_ROLE_RESOURCES = {
|
|
192
|
+
"worker": "roles/worker.txt",
|
|
193
|
+
"reviewer": "roles/reviewer.txt",
|
|
194
|
+
"simple-self-check": "roles/simple-self-check.txt",
|
|
195
|
+
}
|
|
196
|
+
_REPOSITORY_POLICY_COMPONENT_ID = "repository_policy"
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _package_resource_text(relative: str) -> str:
|
|
200
|
+
"""Return the reviewed bundled resource's text, digest-checked every call."""
|
|
201
|
+
|
|
202
|
+
root = Path(str(_resource_files("workflow_coordinator"))).resolve()
|
|
203
|
+
path = root / "resources" / relative
|
|
204
|
+
try:
|
|
205
|
+
data = path.read_bytes()
|
|
206
|
+
except OSError as error:
|
|
207
|
+
raise CommissionError(f"cannot read package resource {relative}: {error}") from error
|
|
208
|
+
expected = _PACKAGE_RESOURCE_DIGESTS.get(relative)
|
|
209
|
+
digest = hashlib.sha256(data).hexdigest()
|
|
210
|
+
if expected is None or digest != expected:
|
|
211
|
+
raise CommissionError(f"package resource digest mismatch or unreviewed: {relative}")
|
|
212
|
+
return data.decode("utf-8")
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def _consumer_program_template(program_id: str, program_revision: str) -> dict[str, Any]:
|
|
216
|
+
"""Return the closed simple@v1/robust@v1 literal with repository_policy filled.
|
|
217
|
+
|
|
218
|
+
``direct@v1`` is deliberately withheld from the consumer compiler. The
|
|
219
|
+
`repository_policy` slot every phase already declares (and leaves empty
|
|
220
|
+
in the self-development templates) is filled here with one shared
|
|
221
|
+
component ID so every phase binds the same consumer guidance.
|
|
222
|
+
"""
|
|
223
|
+
|
|
224
|
+
if (program_id, program_revision) == ("simple", "v1"):
|
|
225
|
+
template = _simple_template()
|
|
226
|
+
elif (program_id, program_revision) == ("robust", "v1"):
|
|
227
|
+
template = _robust_template()
|
|
228
|
+
else:
|
|
229
|
+
raise CommissionError(
|
|
230
|
+
"only the closed simple@v1 and robust@v1 programs are supported by the consumer compiler"
|
|
231
|
+
)
|
|
232
|
+
template = json.loads(json.dumps(template))
|
|
233
|
+
for phase in template["phases"].values():
|
|
234
|
+
phase["components"]["repository_policy"] = [_REPOSITORY_POLICY_COMPONENT_ID]
|
|
235
|
+
return template
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
@dataclass(frozen=True)
|
|
239
|
+
class CompiledCommission:
|
|
240
|
+
"""The deterministic, still-untrusted consumer-neutral projection."""
|
|
241
|
+
|
|
242
|
+
request: Any
|
|
243
|
+
config: Any
|
|
244
|
+
target_dir: str
|
|
245
|
+
paths: Mapping[str, str]
|
|
246
|
+
texts: Mapping[str, str]
|
|
247
|
+
manifest: Mapping[str, Any]
|
|
248
|
+
|
|
249
|
+
def write_to(self, repository: Path, *, overwrite: bool = False) -> None:
|
|
250
|
+
"""Materialize ordinary files below ``repository``; refuse to overwrite."""
|
|
251
|
+
|
|
252
|
+
for path, text in self.texts.items():
|
|
253
|
+
destination = repository / path
|
|
254
|
+
if destination.exists() and not overwrite:
|
|
255
|
+
raise CommissionError(f"refusing to overwrite existing compiled file: {path}")
|
|
256
|
+
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
257
|
+
destination.write_text(text, encoding="utf-8")
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def compile_commission(
|
|
261
|
+
request: Any, config: Any, *, repository: Path | str, target_dir: str | None = None,
|
|
262
|
+
) -> CompiledCommission:
|
|
263
|
+
"""Compile one consumer-neutral Commission without any execution binding.
|
|
264
|
+
|
|
265
|
+
``repository`` is read only to pin ``request.guidance`` at its own
|
|
266
|
+
``source_commit``; every other governing input is package-owned. No
|
|
267
|
+
``bindings``/``execution``/``provider``/``model``/``effort`` field is a
|
|
268
|
+
legal part of ``request`` or ``config`` -- their closed schemas (see
|
|
269
|
+
``frontdoor.request``/``frontdoor.config``) already refuse any such key
|
|
270
|
+
before this function ever runs.
|
|
271
|
+
"""
|
|
272
|
+
|
|
273
|
+
repository = Path(repository).resolve()
|
|
274
|
+
if not repository.is_dir():
|
|
275
|
+
raise CommissionError(f"repository is not a directory: {repository}")
|
|
276
|
+
program_id, program_revision = request.program.id, request.program.revision
|
|
277
|
+
template = _consumer_program_template(program_id, program_revision)
|
|
278
|
+
required_personas = set(template["roles"])
|
|
279
|
+
if set(request.personas) != required_personas:
|
|
280
|
+
raise CommissionError(
|
|
281
|
+
f"{program_id}@{program_revision} requires exactly " + ", ".join(sorted(required_personas)) + " personas"
|
|
282
|
+
)
|
|
283
|
+
evidence_profile_names = list(template["evidence_profiles"])
|
|
284
|
+
if len(evidence_profile_names) != 1:
|
|
285
|
+
raise CommissionError("internal: consumer programs must define exactly one evidence profile")
|
|
286
|
+
evidence_names = tuple(template["evidence_profiles"][evidence_profile_names[0]]["evidence"])
|
|
287
|
+
required_artifacts = {
|
|
288
|
+
phase["artifact_key"] for phase in template["phases"].values() if phase["durable_artifact"] == "required"
|
|
289
|
+
}
|
|
290
|
+
if set(request.durable_artifacts) != required_artifacts:
|
|
291
|
+
if not required_artifacts:
|
|
292
|
+
raise CommissionError(f"{program_id}@{program_revision} contains forbidden durable-artifact mappings")
|
|
293
|
+
raise CommissionError(
|
|
294
|
+
f"{program_id}@{program_revision} requires exactly durable-artifact mappings: "
|
|
295
|
+
+ ", ".join(sorted(required_artifacts))
|
|
296
|
+
)
|
|
297
|
+
if any(not _within(path, request.scope) for paths in request.durable_artifacts.values() for path in paths):
|
|
298
|
+
raise CommissionError("Consumer Request durable-artifact paths must be contained in Consumer Request scope")
|
|
299
|
+
if request.max_autonomous_hops > config.max_autonomous_hops:
|
|
300
|
+
raise CommissionError("Consumer Request hop limit exceeds the Consumer Config ceiling")
|
|
301
|
+
if any(not _within(path, config.work_item_scope_ceiling) for path in request.scope):
|
|
302
|
+
raise CommissionError("Consumer Request scope exceeds the Consumer Config work-item scope ceiling")
|
|
303
|
+
guidance_within_governance_dir = _within(request.guidance.path, (config.governance_dir,))
|
|
304
|
+
governance_paths = (
|
|
305
|
+
(config.governance_dir,) if guidance_within_governance_dir else (config.governance_dir, request.guidance.path)
|
|
306
|
+
)
|
|
307
|
+
if any(_within(path, governance_paths) for path in request.scope):
|
|
308
|
+
raise CommissionError("Consumer Request scope overlaps the repository_policy guidance or governance directory")
|
|
309
|
+
target_dir = _path(target_dir or f"{config.governance_dir}/{request.commission_id}", context="compile target directory")
|
|
310
|
+
if not _within(target_dir, (config.governance_dir,)):
|
|
311
|
+
raise CommissionError("compile target directory is outside the Consumer Config governance directory")
|
|
312
|
+
|
|
313
|
+
guidance_text = _git_text(repository, request.guidance.source_commit, request.guidance.path, context="consumer guidance")
|
|
314
|
+
|
|
315
|
+
role_component_ids = sorted({
|
|
316
|
+
component_id for phase in template["phases"].values() for component_id in phase["components"]["role"]
|
|
317
|
+
})
|
|
318
|
+
modifier_component_ids = sorted({
|
|
319
|
+
component_id for phase in template["phases"].values() for component_id in phase["components"]["modifiers"]
|
|
320
|
+
})
|
|
321
|
+
package_component_ids = [*role_component_ids, *modifier_component_ids]
|
|
322
|
+
component_resources: dict[str, str] = {}
|
|
323
|
+
component_texts: dict[str, str] = {}
|
|
324
|
+
for component_id in package_component_ids:
|
|
325
|
+
resource_relative = _CONSUMER_ROLE_RESOURCES.get(component_id)
|
|
326
|
+
if resource_relative is None:
|
|
327
|
+
raise CommissionError(f"internal: no package resource is bound for component: {component_id}")
|
|
328
|
+
component_resources[component_id] = resource_relative
|
|
329
|
+
component_texts[component_id] = _package_resource_text(resource_relative)
|
|
330
|
+
|
|
331
|
+
paths = {
|
|
332
|
+
"work_item": f"{target_dir}/work-item.yaml", "profile": f"{target_dir}/profile.yaml",
|
|
333
|
+
"policy": f"{target_dir}/policy.yaml", "task": f"{target_dir}/task.md",
|
|
334
|
+
"components": f"{target_dir}/components.yaml", "manifest": f"{target_dir}/commission-manifest.json",
|
|
335
|
+
}
|
|
336
|
+
component_paths = {
|
|
337
|
+
component_id: f"{target_dir}/components/{component_id}.txt" for component_id in package_component_ids
|
|
338
|
+
}
|
|
339
|
+
component_paths[_REPOSITORY_POLICY_COMPONENT_ID] = request.guidance.path
|
|
340
|
+
|
|
341
|
+
profile_phases = template["phases"]
|
|
342
|
+
for phase in profile_phases.values():
|
|
343
|
+
scope_slot = phase.pop("scope")
|
|
344
|
+
artifact_key = phase.pop("artifact_key", None)
|
|
345
|
+
if scope_slot == "S":
|
|
346
|
+
phase["authorized_scope"] = list(request.scope)
|
|
347
|
+
else:
|
|
348
|
+
phase["authorized_scope"] = list(request.durable_artifacts[artifact_key])
|
|
349
|
+
if phase["evidence"] == "E":
|
|
350
|
+
phase["evidence"] = list(evidence_names)
|
|
351
|
+
profile_data = {
|
|
352
|
+
"schema_version": 2, "profile_id": f"{request.commission_id}-{program_id}-{program_revision}",
|
|
353
|
+
"revision": "1", "phases": profile_phases,
|
|
354
|
+
}
|
|
355
|
+
policy_data = {
|
|
356
|
+
"schema_version": 3, "policy_id": "consumer-standard", "revision": "v1",
|
|
357
|
+
"scope": [config.repository_name], "governance_paths": list(governance_paths),
|
|
358
|
+
"work_item_scope_ceiling": list(config.work_item_scope_ceiling), "max_autonomous_hops": config.max_autonomous_hops,
|
|
359
|
+
"actions": ["edit", "commit", "review"],
|
|
360
|
+
"evidence_commands": {
|
|
361
|
+
"task-check": {"argv": list(request.evidence.argv), "timeout_seconds": request.evidence.timeout_seconds},
|
|
362
|
+
},
|
|
363
|
+
}
|
|
364
|
+
item_data = {
|
|
365
|
+
"schema_version": 2, "work_item_id": request.work_item_id, "authority_source": request.authority_source,
|
|
366
|
+
"profile_ref": paths["profile"], "repository": config.repository_name, "scope": list(request.scope),
|
|
367
|
+
"initial_phase": "implement", "max_autonomous_hops": request.max_autonomous_hops,
|
|
368
|
+
"personas": dict(request.personas),
|
|
369
|
+
"profile_labels": [
|
|
370
|
+
f"program_id={program_id}", f"program_revision={program_revision}", "program_source=package",
|
|
371
|
+
],
|
|
372
|
+
"durable_artifacts": {key: list(value) for key, value in request.durable_artifacts.items()},
|
|
373
|
+
}
|
|
374
|
+
texts: dict[str, str] = {
|
|
375
|
+
paths["work_item"]: _yaml(item_data), paths["profile"]: _yaml(profile_data), paths["policy"]: _yaml(policy_data),
|
|
376
|
+
paths["task"]: _task_text(request),
|
|
377
|
+
}
|
|
378
|
+
for component_id, text in component_texts.items():
|
|
379
|
+
texts[component_paths[component_id]] = text
|
|
380
|
+
components_data = {
|
|
381
|
+
"schema_version": 1,
|
|
382
|
+
"components": {component_id: {"path": path} for component_id, path in component_paths.items()},
|
|
383
|
+
}
|
|
384
|
+
texts[paths["components"]] = _yaml(components_data)
|
|
385
|
+
|
|
386
|
+
source_digests = {
|
|
387
|
+
"request": _sha(request.raw_text), "config": _sha(config.raw_text), "guidance": _sha(guidance_text),
|
|
388
|
+
**{f"component:{component_id}": _sha(text) for component_id, text in component_texts.items()},
|
|
389
|
+
}
|
|
390
|
+
manifest_data = {
|
|
391
|
+
"schema_version": 1,
|
|
392
|
+
"request": {"sha256": source_digests["request"]},
|
|
393
|
+
"config": {"sha256": source_digests["config"]},
|
|
394
|
+
"package": {
|
|
395
|
+
"version": _PACKAGE_VERSION,
|
|
396
|
+
"resources": {
|
|
397
|
+
component_resources[component_id]: source_digests[f"component:{component_id}"]
|
|
398
|
+
for component_id in package_component_ids
|
|
399
|
+
},
|
|
400
|
+
},
|
|
401
|
+
"program": {"id": program_id, "revision": program_revision},
|
|
402
|
+
"guidance": {
|
|
403
|
+
"path": request.guidance.path, "source_commit": request.guidance.source_commit,
|
|
404
|
+
"sha256": source_digests["guidance"],
|
|
405
|
+
},
|
|
406
|
+
"targets": paths,
|
|
407
|
+
"selected_components": [
|
|
408
|
+
{
|
|
409
|
+
"id": component_id,
|
|
410
|
+
"path": component_paths[component_id],
|
|
411
|
+
"origin": "guidance" if component_id == _REPOSITORY_POLICY_COMPONENT_ID else "package",
|
|
412
|
+
"sha256": (
|
|
413
|
+
source_digests["guidance"]
|
|
414
|
+
if component_id == _REPOSITORY_POLICY_COMPONENT_ID
|
|
415
|
+
else source_digests[f"component:{component_id}"]
|
|
416
|
+
),
|
|
417
|
+
}
|
|
418
|
+
for component_id in component_paths
|
|
419
|
+
],
|
|
420
|
+
"digests": {path: _sha(value) for path, value in texts.items()},
|
|
421
|
+
}
|
|
422
|
+
manifest_text = json.dumps(manifest_data, sort_keys=True, indent=2) + "\n"
|
|
423
|
+
texts[paths["manifest"]] = manifest_text
|
|
424
|
+
# Exercise the unchanged schemas now, before callers ever commit a malformed projection.
|
|
425
|
+
try:
|
|
426
|
+
work_item_from_yaml(texts[paths["work_item"]])
|
|
427
|
+
workflow_profile_from_yaml(texts[paths["profile"]])
|
|
428
|
+
repository_policy_from_yaml(texts[paths["policy"]])
|
|
429
|
+
component_manifest_from_yaml(texts[paths["components"]])
|
|
430
|
+
except ValidationError as error:
|
|
431
|
+
raise CommissionError(f"internal compiled schema refusal: {error}") from error
|
|
432
|
+
return CompiledCommission(request, config, target_dir, paths, texts, manifest_data)
|