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,287 @@
|
|
|
1
|
+
"""Bounded consumer repository configuration and execution resolution (BP2b).
|
|
2
|
+
|
|
3
|
+
``ConsumerConfig`` is the durable, per-repository half of a BP2b compile
|
|
4
|
+
input (governance target, scope ceiling, hop ceiling, and default execution
|
|
5
|
+
bindings). ``resolve_execution`` turns a config, an explicit per-role
|
|
6
|
+
override mapping, and the role set a chosen program actually uses into one
|
|
7
|
+
``RunExecutionConfiguration`` with its own stable digest -- entirely outside
|
|
8
|
+
the Commission's own immutable bytes, per C1.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import hashlib
|
|
14
|
+
import os
|
|
15
|
+
from dataclasses import dataclass
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
from typing import Any, Mapping
|
|
18
|
+
|
|
19
|
+
import yaml
|
|
20
|
+
|
|
21
|
+
from ..commissioning import CommissionError, _mapping, _path, _text, _yaml_load
|
|
22
|
+
from ..model import ExecutionBinding, RunExecutionConfiguration, WorkflowRole
|
|
23
|
+
|
|
24
|
+
_ADAPTERS = {"codex_cli", "claude_cli"}
|
|
25
|
+
|
|
26
|
+
EVIDENCE_RAW_CHOICES = ("local", "commit", "discard")
|
|
27
|
+
_DEFAULT_EVIDENCE_RAW = "local"
|
|
28
|
+
|
|
29
|
+
# The managed block ``wfc init`` writes into a new Evidence repository's root
|
|
30
|
+
# ``.gitignore``. Content-style globs (``**`` suffix, not a trailing-slash
|
|
31
|
+
# directory match) so a per-Attempt ``commit``-mode archive can still
|
|
32
|
+
# re-include its own raw files with a nested ``!`` negation -- a
|
|
33
|
+
# directory-match pattern (``archive/**/run/``) would make Git refuse to
|
|
34
|
+
# traverse into ``run/`` at all, and no later rule could ever re-include a
|
|
35
|
+
# file beneath it.
|
|
36
|
+
EVIDENCE_GITIGNORE_MARKER_BEGIN = "# >>> wfc managed evidence raw-retention block (do not edit by hand) >>>"
|
|
37
|
+
EVIDENCE_GITIGNORE_MARKER_END = "# <<< wfc managed evidence raw-retention block <<<"
|
|
38
|
+
EVIDENCE_GITIGNORE_PATTERNS = ("archive/**/manifest.json", "archive/**/run/**", "archive/**/ops/**")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def evidence_gitignore_block() -> str:
|
|
42
|
+
"""The exact managed block text ``wfc init`` writes into a fresh Evidence repository."""
|
|
43
|
+
|
|
44
|
+
lines = (EVIDENCE_GITIGNORE_MARKER_BEGIN, *EVIDENCE_GITIGNORE_PATTERNS, EVIDENCE_GITIGNORE_MARKER_END)
|
|
45
|
+
return "\n".join(lines) + "\n"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@dataclass(frozen=True)
|
|
49
|
+
class ExecutionBindingValue:
|
|
50
|
+
adapter: str
|
|
51
|
+
model: str
|
|
52
|
+
reasoning: str
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@dataclass(frozen=True)
|
|
56
|
+
class EvidenceConfigValue:
|
|
57
|
+
"""The parsed, optional ``evidence`` block of a Consumer Config.
|
|
58
|
+
|
|
59
|
+
``repository`` is ``None`` when the author omitted the key (the default
|
|
60
|
+
location applies); when present it is stored exactly as authored --
|
|
61
|
+
resolution against the payload repository root happens in
|
|
62
|
+
``resolve_evidence``, never here.
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
repository: str | None
|
|
66
|
+
raw: str
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@dataclass(frozen=True)
|
|
70
|
+
class EvidenceSettings:
|
|
71
|
+
"""The resolved Evidence destination and raw-retention mode for one repository."""
|
|
72
|
+
|
|
73
|
+
path: Path
|
|
74
|
+
raw: str
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@dataclass(frozen=True)
|
|
78
|
+
class ConsumerConfig:
|
|
79
|
+
schema_version: int
|
|
80
|
+
repository_name: str
|
|
81
|
+
governance_dir: str
|
|
82
|
+
work_item_scope_ceiling: tuple[str, ...]
|
|
83
|
+
max_autonomous_hops: int
|
|
84
|
+
default_execution: Mapping[str, ExecutionBindingValue]
|
|
85
|
+
raw_text: str
|
|
86
|
+
evidence: EvidenceConfigValue | None = None
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@dataclass(frozen=True)
|
|
90
|
+
class ExecutionEnvelope:
|
|
91
|
+
"""An execution binding set with an identity independent of the Commission."""
|
|
92
|
+
|
|
93
|
+
configuration: RunExecutionConfiguration
|
|
94
|
+
text: str
|
|
95
|
+
digest: str
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _execution_value(value: Any, *, context: str) -> str:
|
|
99
|
+
text = _text(value, context=context)
|
|
100
|
+
if text.splitlines() != [text]:
|
|
101
|
+
raise CommissionError(f"{context} must be a single-line value")
|
|
102
|
+
return text
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _evidence_config_value(value: Any, *, context: str) -> EvidenceConfigValue:
|
|
106
|
+
data = _mapping(value, context=context, required=set(), optional={"repository", "raw"})
|
|
107
|
+
repository = None
|
|
108
|
+
if "repository" in data:
|
|
109
|
+
repository = _execution_value(data["repository"], context=f"{context}.repository")
|
|
110
|
+
raw = _DEFAULT_EVIDENCE_RAW
|
|
111
|
+
if "raw" in data:
|
|
112
|
+
raw_value = data["raw"]
|
|
113
|
+
if raw_value not in EVIDENCE_RAW_CHOICES:
|
|
114
|
+
raise CommissionError(
|
|
115
|
+
f"{context}.raw must be one of: {', '.join(EVIDENCE_RAW_CHOICES)}"
|
|
116
|
+
)
|
|
117
|
+
raw = raw_value
|
|
118
|
+
return EvidenceConfigValue(repository=repository, raw=raw)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _execution_binding_value(value: Any, *, context: str) -> ExecutionBindingValue:
|
|
122
|
+
data = _mapping(value, context=context, required={"adapter", "model", "reasoning"})
|
|
123
|
+
adapter = _text(data["adapter"], context=f"{context}.adapter")
|
|
124
|
+
if adapter not in _ADAPTERS:
|
|
125
|
+
raise CommissionError(f"{context}.adapter must be one of: {', '.join(sorted(_ADAPTERS))}")
|
|
126
|
+
return ExecutionBindingValue(
|
|
127
|
+
adapter=adapter,
|
|
128
|
+
model=_execution_value(data["model"], context=f"{context}.model"),
|
|
129
|
+
reasoning=_execution_value(data["reasoning"], context=f"{context}.reasoning"),
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def consumer_config_from_yaml(text: str) -> ConsumerConfig:
|
|
134
|
+
"""Parse the deliberately small per-repository consumer-config vocabulary."""
|
|
135
|
+
|
|
136
|
+
raw = _yaml_load(text, context="Consumer Config")
|
|
137
|
+
data = _mapping(
|
|
138
|
+
raw,
|
|
139
|
+
context="Consumer Config",
|
|
140
|
+
required={
|
|
141
|
+
"schema_version", "repository_name", "governance_dir", "work_item_scope_ceiling",
|
|
142
|
+
"max_autonomous_hops", "default_execution",
|
|
143
|
+
},
|
|
144
|
+
optional={"evidence"},
|
|
145
|
+
)
|
|
146
|
+
if data["schema_version"] != 1:
|
|
147
|
+
raise CommissionError("Consumer Config.schema_version must be 1")
|
|
148
|
+
governance_dir = _path(data["governance_dir"], context="Consumer Config.governance_dir")
|
|
149
|
+
if not isinstance(data["work_item_scope_ceiling"], list) or not data["work_item_scope_ceiling"]:
|
|
150
|
+
raise CommissionError("Consumer Config.work_item_scope_ceiling must be a non-empty list")
|
|
151
|
+
ceiling = tuple(_path(value, context="Consumer Config.work_item_scope_ceiling") for value in data["work_item_scope_ceiling"])
|
|
152
|
+
if len(set(ceiling)) != len(ceiling):
|
|
153
|
+
raise CommissionError("Consumer Config.work_item_scope_ceiling must not contain duplicates")
|
|
154
|
+
hops = data["max_autonomous_hops"]
|
|
155
|
+
if not isinstance(hops, int) or isinstance(hops, bool) or hops <= 0:
|
|
156
|
+
raise CommissionError("Consumer Config.max_autonomous_hops must be a positive integer")
|
|
157
|
+
default_execution_raw = data["default_execution"]
|
|
158
|
+
if not isinstance(default_execution_raw, dict):
|
|
159
|
+
raise CommissionError("Consumer Config.default_execution must be a mapping")
|
|
160
|
+
default_execution: dict[str, ExecutionBindingValue] = {}
|
|
161
|
+
for role_name, binding_value in default_execution_raw.items():
|
|
162
|
+
if not isinstance(role_name, str):
|
|
163
|
+
raise CommissionError("Consumer Config.default_execution keys must be strings")
|
|
164
|
+
try:
|
|
165
|
+
WorkflowRole(role_name)
|
|
166
|
+
except ValueError as error:
|
|
167
|
+
raise CommissionError(f"Consumer Config.default_execution names an unknown role: {role_name}") from error
|
|
168
|
+
default_execution[role_name] = _execution_binding_value(
|
|
169
|
+
binding_value, context=f"Consumer Config.default_execution.{role_name}"
|
|
170
|
+
)
|
|
171
|
+
evidence = None
|
|
172
|
+
if "evidence" in data:
|
|
173
|
+
evidence = _evidence_config_value(data["evidence"], context="Consumer Config.evidence")
|
|
174
|
+
return ConsumerConfig(
|
|
175
|
+
schema_version=1,
|
|
176
|
+
repository_name=_text(data["repository_name"], context="Consumer Config.repository_name"),
|
|
177
|
+
governance_dir=governance_dir,
|
|
178
|
+
work_item_scope_ceiling=ceiling,
|
|
179
|
+
max_autonomous_hops=hops,
|
|
180
|
+
default_execution=default_execution,
|
|
181
|
+
raw_text=text,
|
|
182
|
+
evidence=evidence,
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def _execution_yaml(bindings: Mapping[str, ExecutionBindingValue]) -> str:
|
|
187
|
+
payload = {
|
|
188
|
+
"schema_version": 1,
|
|
189
|
+
"bindings": {
|
|
190
|
+
role: {"adapter": binding.adapter, "model": binding.model, "reasoning": binding.reasoning}
|
|
191
|
+
for role, binding in sorted(bindings.items())
|
|
192
|
+
},
|
|
193
|
+
}
|
|
194
|
+
return yaml.safe_dump(payload, sort_keys=False, allow_unicode=True)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def resolve_execution(
|
|
198
|
+
config: ConsumerConfig,
|
|
199
|
+
overrides: Mapping[str, Mapping[str, str]],
|
|
200
|
+
roles: tuple[str, ...],
|
|
201
|
+
) -> ExecutionEnvelope:
|
|
202
|
+
"""Resolve one explicit, authority-neutral execution envelope for ``roles``.
|
|
203
|
+
|
|
204
|
+
``overrides`` wins field-by-field over ``config.default_execution`` for the
|
|
205
|
+
same role; every field named by either source for an unselected role is a
|
|
206
|
+
refusal, never a silent ignore -- execution scope cannot be widened past
|
|
207
|
+
what the chosen program actually uses.
|
|
208
|
+
"""
|
|
209
|
+
|
|
210
|
+
required_roles = set(roles)
|
|
211
|
+
unknown_roles = sorted(set(overrides) - required_roles)
|
|
212
|
+
if unknown_roles:
|
|
213
|
+
raise CommissionError(
|
|
214
|
+
"execution overrides name roles the selected program does not use: " + ", ".join(unknown_roles)
|
|
215
|
+
)
|
|
216
|
+
unknown_default_roles = sorted(set(config.default_execution) - required_roles)
|
|
217
|
+
if unknown_default_roles:
|
|
218
|
+
raise CommissionError(
|
|
219
|
+
"execution config defaults name roles the selected program does not use: "
|
|
220
|
+
+ ", ".join(unknown_default_roles)
|
|
221
|
+
)
|
|
222
|
+
bindings: dict[str, ExecutionBindingValue] = {}
|
|
223
|
+
for role in required_roles:
|
|
224
|
+
base = config.default_execution.get(role)
|
|
225
|
+
override = overrides.get(role)
|
|
226
|
+
merged = {
|
|
227
|
+
"adapter": (base.adapter if base else None),
|
|
228
|
+
"model": (base.model if base else None),
|
|
229
|
+
"reasoning": (base.reasoning if base else None),
|
|
230
|
+
}
|
|
231
|
+
if override is not None:
|
|
232
|
+
for key in ("adapter", "model", "reasoning"):
|
|
233
|
+
if key in override:
|
|
234
|
+
merged[key] = override[key]
|
|
235
|
+
missing = sorted(key for key, value in merged.items() if value is None)
|
|
236
|
+
if missing:
|
|
237
|
+
raise CommissionError(
|
|
238
|
+
f"execution binding for role {role} is missing: " + ", ".join(missing)
|
|
239
|
+
)
|
|
240
|
+
bindings[role] = _execution_binding_value(merged, context=f"resolved execution binding for role {role}")
|
|
241
|
+
text = _execution_yaml(bindings)
|
|
242
|
+
digest = hashlib.sha256(text.encode("utf-8")).hexdigest()
|
|
243
|
+
configuration = RunExecutionConfiguration(
|
|
244
|
+
schema_version=1,
|
|
245
|
+
bindings={
|
|
246
|
+
WorkflowRole(role): ExecutionBinding(adapter=binding.adapter, model=binding.model, reasoning=binding.reasoning)
|
|
247
|
+
for role, binding in bindings.items()
|
|
248
|
+
},
|
|
249
|
+
)
|
|
250
|
+
return ExecutionEnvelope(configuration=configuration, text=text, digest=digest)
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def resolve_evidence(
|
|
254
|
+
config: ConsumerConfig,
|
|
255
|
+
repository_root: Path | str,
|
|
256
|
+
environ: Mapping[str, str] | None = None,
|
|
257
|
+
) -> EvidenceSettings:
|
|
258
|
+
"""Resolve the Evidence destination and raw-retention mode for ``config``.
|
|
259
|
+
|
|
260
|
+
Absent an ``evidence`` block, the default applies: raw retention
|
|
261
|
+
``local`` and a repository at ``<data home>/wfc/evidence/<repository_name>``,
|
|
262
|
+
where data home is ``$XDG_DATA_HOME`` falling back to ``~/.local/share``.
|
|
263
|
+
An explicit ``repository`` is resolved against ``repository_root`` when
|
|
264
|
+
relative (including one that escapes it with ``..``, as self-development
|
|
265
|
+
does); an absolute ``repository`` is used as given.
|
|
266
|
+
"""
|
|
267
|
+
|
|
268
|
+
env = os.environ if environ is None else environ
|
|
269
|
+
repository_root = Path(repository_root)
|
|
270
|
+
evidence = config.evidence
|
|
271
|
+
raw = evidence.raw if evidence is not None else _DEFAULT_EVIDENCE_RAW
|
|
272
|
+
repository_setting = evidence.repository if evidence is not None else None
|
|
273
|
+
|
|
274
|
+
if repository_setting is not None:
|
|
275
|
+
candidate = Path(repository_setting)
|
|
276
|
+
path = candidate if candidate.is_absolute() else Path(os.path.normpath(repository_root / candidate))
|
|
277
|
+
else:
|
|
278
|
+
data_home = env.get("XDG_DATA_HOME")
|
|
279
|
+
if data_home:
|
|
280
|
+
base = Path(data_home)
|
|
281
|
+
else:
|
|
282
|
+
home = env.get("HOME")
|
|
283
|
+
if not home:
|
|
284
|
+
raise CommissionError("cannot resolve the default Evidence location: HOME is not set")
|
|
285
|
+
base = Path(home) / ".local" / "share"
|
|
286
|
+
path = base / "wfc" / "evidence" / config.repository_name
|
|
287
|
+
return EvidenceSettings(path=path, raw=raw)
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"""Installed ``wfc init`` -- create a neutral consumer's Consumer Config,
|
|
2
|
+
and (BP6b, additive) create or adopt the Evidence repository.
|
|
3
|
+
|
|
4
|
+
The Consumer Config write is unchanged from BP3: it is never committed and
|
|
5
|
+
never overwrites an existing file. The Evidence-repository step that follows
|
|
6
|
+
it never touches the payload repository -- it only creates or adopts a
|
|
7
|
+
separate Git repository at the resolved Evidence location, with one initial
|
|
8
|
+
commit and no remote.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import os
|
|
15
|
+
import subprocess
|
|
16
|
+
import sys
|
|
17
|
+
from pathlib import Path, PurePosixPath
|
|
18
|
+
|
|
19
|
+
import yaml
|
|
20
|
+
|
|
21
|
+
from ..commissioning import CommissionError
|
|
22
|
+
from ..git_facts import GitPreflightError, repository_identity
|
|
23
|
+
from .config import (
|
|
24
|
+
EVIDENCE_RAW_CHOICES,
|
|
25
|
+
consumer_config_from_yaml,
|
|
26
|
+
evidence_gitignore_block,
|
|
27
|
+
resolve_evidence,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
DEFAULT_CONFIG_PATH = ".wfc/config.yaml"
|
|
31
|
+
DEFAULT_GOVERNANCE_DIR = ".wfc/governance"
|
|
32
|
+
_DEFAULT_EVIDENCE_RAW = "local"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _validated_config_destination(repository: Path, config_path: str) -> Path:
|
|
36
|
+
"""Resolve ``--config-path`` strictly inside ``repository``, before any mutation.
|
|
37
|
+
|
|
38
|
+
Refuses an absolute path, a ``..``-escaping path, and a symlink escape (an
|
|
39
|
+
existing parent component that resolves outside the repository) up front --
|
|
40
|
+
none of those may ever reach ``mkdir``/``write_text`` below.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
if not config_path or config_path != config_path.strip() or "\\" in config_path:
|
|
44
|
+
raise CommissionError("--config-path must be a normalized repository-relative path")
|
|
45
|
+
candidate = PurePosixPath(config_path)
|
|
46
|
+
if candidate.is_absolute() or any(part in {"", ".", ".."} for part in candidate.parts):
|
|
47
|
+
raise CommissionError("--config-path must be a repository-relative path that does not escape the repository")
|
|
48
|
+
destination = repository / candidate
|
|
49
|
+
try:
|
|
50
|
+
resolved = destination.resolve()
|
|
51
|
+
resolved.relative_to(repository)
|
|
52
|
+
except ValueError as error:
|
|
53
|
+
raise CommissionError("--config-path must resolve inside the repository") from error
|
|
54
|
+
return destination
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _trusted_bootstrap_environment() -> dict[str, str]:
|
|
58
|
+
return {name: value for name, value in os.environ.items() if not name.startswith("GIT_")}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _run_bootstrap_git(repository: Path, *args: str) -> subprocess.CompletedProcess[str]:
|
|
62
|
+
"""One Evidence-repository bootstrap Git command, under the same trusted
|
|
63
|
+
execution policy ``git_facts`` uses for Coordinator commits (no hooks, no
|
|
64
|
+
signing, no fsmonitor) -- duplicated here rather than imported, because
|
|
65
|
+
this creates a brand-new repository's very first commit, before any HEAD
|
|
66
|
+
exists for ``bounded_path_commit``/``trusted_commit`` to anchor on.
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
configuration = ("-c", f"core.hooksPath={os.devnull}", "-c", "commit.gpgSign=false", "-c", "core.fsmonitor=false")
|
|
70
|
+
return subprocess.run(
|
|
71
|
+
("git", "-C", str(repository), *configuration, *args),
|
|
72
|
+
check=False, text=True, capture_output=True, env=_trusted_bootstrap_environment(),
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _create_evidence_repository(path: Path) -> None:
|
|
77
|
+
archive_dir = path / "archive"
|
|
78
|
+
archive_dir.mkdir(parents=True, exist_ok=True)
|
|
79
|
+
(archive_dir / ".gitkeep").write_text("", encoding="utf-8")
|
|
80
|
+
(path / ".gitignore").write_text(evidence_gitignore_block(), encoding="utf-8")
|
|
81
|
+
|
|
82
|
+
result = _run_bootstrap_git(path, "init", "-q", "-b", "main")
|
|
83
|
+
if result.returncode:
|
|
84
|
+
raise CommissionError(f"failed to initialize Evidence repository at {path}: {result.stderr.strip()}")
|
|
85
|
+
result = _run_bootstrap_git(path, "add", "--", "archive/.gitkeep", ".gitignore")
|
|
86
|
+
if result.returncode:
|
|
87
|
+
raise CommissionError(f"failed to stage the new Evidence repository's content: {result.stderr.strip()}")
|
|
88
|
+
result = _run_bootstrap_git(path, "commit", "--no-verify", "-m", "chore: initialize WFC Evidence repository")
|
|
89
|
+
if result.returncode:
|
|
90
|
+
raise CommissionError(f"failed to create the initial Evidence repository commit: {result.stderr.strip()}")
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def ensure_evidence_repository(path: Path) -> str:
|
|
94
|
+
"""Create a new Evidence repository at ``path``, or adopt an existing valid one.
|
|
95
|
+
|
|
96
|
+
Returns ``"created"`` or ``"reused"``. A path that exists, is non-empty,
|
|
97
|
+
and is not already a WFC Evidence repository (a Git repository root with
|
|
98
|
+
an ``archive/`` directory) is refused before anything is written.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
if path.exists():
|
|
102
|
+
if not path.is_dir():
|
|
103
|
+
raise CommissionError(f"Evidence location exists and is not a directory: {path}")
|
|
104
|
+
if (path / "archive").is_dir() and (path / ".git").exists():
|
|
105
|
+
try:
|
|
106
|
+
identity = repository_identity(path)
|
|
107
|
+
except GitPreflightError as error:
|
|
108
|
+
raise CommissionError(
|
|
109
|
+
f"Evidence location is not a usable Git repository: {path}: {error}"
|
|
110
|
+
) from error
|
|
111
|
+
if identity != path.resolve():
|
|
112
|
+
raise CommissionError(f"Evidence location is not a Git repository root: {path}")
|
|
113
|
+
return "reused"
|
|
114
|
+
if any(path.iterdir()):
|
|
115
|
+
raise CommissionError(
|
|
116
|
+
f"refusing: Evidence location {path} exists, is non-empty, and is not a WFC "
|
|
117
|
+
"Evidence repository (no Git repository root with an archive/ directory); "
|
|
118
|
+
"nothing was written"
|
|
119
|
+
)
|
|
120
|
+
else:
|
|
121
|
+
path.mkdir(parents=True)
|
|
122
|
+
_create_evidence_repository(path)
|
|
123
|
+
return "created"
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _parse_args(argv: list[str]) -> argparse.Namespace:
|
|
127
|
+
parser = argparse.ArgumentParser(
|
|
128
|
+
prog="wfc init",
|
|
129
|
+
description=(
|
|
130
|
+
"Create the per-repository Consumer Config a future `wfc plan`/compile "
|
|
131
|
+
"needs. Writes exactly one new file; never commits it, never runs a "
|
|
132
|
+
"project command."
|
|
133
|
+
),
|
|
134
|
+
)
|
|
135
|
+
parser.add_argument("--repository", default=".", help="consumer repository root (default: current directory)")
|
|
136
|
+
parser.add_argument(
|
|
137
|
+
"--scope-ceiling", action="append", default=[], required=True, metavar="PATH",
|
|
138
|
+
help="repository-relative path a future Commission's scope may never exceed (repeatable, at least one)",
|
|
139
|
+
)
|
|
140
|
+
parser.add_argument(
|
|
141
|
+
"--governance-dir", default=DEFAULT_GOVERNANCE_DIR,
|
|
142
|
+
help=f"directory a compiled Commission is later written under (default: {DEFAULT_GOVERNANCE_DIR})",
|
|
143
|
+
)
|
|
144
|
+
parser.add_argument("--repository-name", help="defaults to the repository directory name")
|
|
145
|
+
parser.add_argument("--max-autonomous-hops", type=int, default=5)
|
|
146
|
+
parser.add_argument(
|
|
147
|
+
"--config-path", default=DEFAULT_CONFIG_PATH,
|
|
148
|
+
help=f"where to write the Consumer Config, relative to --repository (default: {DEFAULT_CONFIG_PATH})",
|
|
149
|
+
)
|
|
150
|
+
parser.add_argument(
|
|
151
|
+
"--evidence-repository", default=None, metavar="PATH",
|
|
152
|
+
help="Evidence repository location, absolute or relative to --repository "
|
|
153
|
+
"(default: <data home>/wfc/evidence/<repository-name>)",
|
|
154
|
+
)
|
|
155
|
+
parser.add_argument(
|
|
156
|
+
"--evidence-raw", choices=EVIDENCE_RAW_CHOICES, default=None,
|
|
157
|
+
help=f"raw-file retention mode (default: {_DEFAULT_EVIDENCE_RAW})",
|
|
158
|
+
)
|
|
159
|
+
parser.add_argument(
|
|
160
|
+
"--no-evidence-repository", action="store_true",
|
|
161
|
+
help="write the Consumer Config only; do not create or adopt an Evidence repository",
|
|
162
|
+
)
|
|
163
|
+
return parser.parse_args(argv)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def main(argv: list[str] | None = None) -> int:
|
|
167
|
+
args = _parse_args(sys.argv[1:] if argv is None else argv)
|
|
168
|
+
try:
|
|
169
|
+
repository = repository_identity(Path(args.repository))
|
|
170
|
+
except GitPreflightError as error:
|
|
171
|
+
print(f"wfc init: {error}", file=sys.stderr)
|
|
172
|
+
return 2
|
|
173
|
+
|
|
174
|
+
try:
|
|
175
|
+
destination = _validated_config_destination(repository, args.config_path)
|
|
176
|
+
except CommissionError as error:
|
|
177
|
+
print(f"wfc init: {error}", file=sys.stderr)
|
|
178
|
+
return 2
|
|
179
|
+
if destination.exists():
|
|
180
|
+
print(f"wfc init: refusing to overwrite existing Consumer Config: {destination}", file=sys.stderr)
|
|
181
|
+
return 2
|
|
182
|
+
|
|
183
|
+
config_data = {
|
|
184
|
+
"schema_version": 1,
|
|
185
|
+
"repository_name": args.repository_name or repository.name,
|
|
186
|
+
"governance_dir": args.governance_dir,
|
|
187
|
+
"work_item_scope_ceiling": list(args.scope_ceiling),
|
|
188
|
+
"max_autonomous_hops": args.max_autonomous_hops,
|
|
189
|
+
"default_execution": {},
|
|
190
|
+
}
|
|
191
|
+
evidence_overrides: dict[str, str] = {}
|
|
192
|
+
if args.evidence_repository is not None:
|
|
193
|
+
evidence_overrides["repository"] = args.evidence_repository
|
|
194
|
+
if args.evidence_raw is not None and args.evidence_raw != _DEFAULT_EVIDENCE_RAW:
|
|
195
|
+
evidence_overrides["raw"] = args.evidence_raw
|
|
196
|
+
if evidence_overrides:
|
|
197
|
+
config_data["evidence"] = evidence_overrides
|
|
198
|
+
|
|
199
|
+
text = yaml.safe_dump(config_data, sort_keys=False, allow_unicode=True)
|
|
200
|
+
try:
|
|
201
|
+
config = consumer_config_from_yaml(text)
|
|
202
|
+
except CommissionError as error:
|
|
203
|
+
print(f"wfc init: generated Consumer Config is invalid: {error}", file=sys.stderr)
|
|
204
|
+
return 2
|
|
205
|
+
|
|
206
|
+
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
207
|
+
destination.write_text(text, encoding="utf-8")
|
|
208
|
+
relative = destination.relative_to(repository) if destination.is_relative_to(repository) else destination
|
|
209
|
+
print(f"wrote Consumer Config: {relative}")
|
|
210
|
+
print(
|
|
211
|
+
"NEXT EXPLICIT ACTION: review this file, fill in default_execution for your "
|
|
212
|
+
"roles, and commit it yourself -- `wfc init` never commits it."
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
if args.no_evidence_repository:
|
|
216
|
+
return 0
|
|
217
|
+
|
|
218
|
+
try:
|
|
219
|
+
settings = resolve_evidence(config, repository, os.environ)
|
|
220
|
+
outcome = ensure_evidence_repository(settings.path)
|
|
221
|
+
except CommissionError as error:
|
|
222
|
+
print(f"wfc init: {error}", file=sys.stderr)
|
|
223
|
+
return 2
|
|
224
|
+
|
|
225
|
+
verb = "created new" if outcome == "created" else "reusing existing"
|
|
226
|
+
print(f"Evidence repository ({verb}): {settings.path} (raw retention: {settings.raw})")
|
|
227
|
+
print("NOTHING WAS PUSHED: the Evidence repository has no remote configured.")
|
|
228
|
+
return 0
|