@elvis1513/auto-coding-skill 4.1.2 → 4.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -3
- package/cli/assets/agents/explorer.toml +1 -1
- package/cli/assets/agents/fixer.toml +3 -3
- package/cli/assets/skill/SKILL.md +11 -13
- package/cli/assets/skill/data/contracts/orchestration-v1.schema.json +16 -0
- package/cli/assets/skill/data/policies/workflow-migrations-v1.json +2 -2
- package/cli/assets/skill/data/templates/ENGINEERING.md +2 -2
- package/cli/assets/skill/data/templates/bridges/AGENTS.md +9 -8
- package/cli/assets/skill/scripts/ap.py +591 -46
- package/cli/tests/ap_concurrency_test.py +102 -0
- package/cli/tests/ap_profiles_test.py +197 -1
- package/cli/tests/index.test.js +19 -13
- package/package.json +1 -1
|
@@ -51,7 +51,7 @@ _RECOMMENDED_FINAL_TOTAL_SECONDS = 180.0
|
|
|
51
51
|
_WORKFLOW_MIGRATION_POLICY = Path("data/policies/workflow-migrations-v1.json")
|
|
52
52
|
_FALLBACK_WORKFLOW_MIGRATION_POLICY = {
|
|
53
53
|
"schema_version": 1,
|
|
54
|
-
"managed_versions": {"agents": "4.1.
|
|
54
|
+
"managed_versions": {"agents": "4.1.4", "engineering": "4.1.4"},
|
|
55
55
|
"known_official_engineering_body_sha256": [
|
|
56
56
|
"d1306cc626e8baf8c83c953b760fd771066de2bf125168eca3a7b7d6ff2b87a2",
|
|
57
57
|
"305931c6edef770033a4f1970b00e5fb1c1728351856a173dbfa497daf563021",
|
|
@@ -178,13 +178,13 @@ def _evidence_log_path(repo: Path, cfg: dict) -> Path:
|
|
|
178
178
|
return Path(repo, task_dir, f"{manifest['task_id']}.jsonl")
|
|
179
179
|
if _bool_config(docs_cfg.get("track_evidence"), False) and _text(docs_cfg.get("evidence_log")):
|
|
180
180
|
return Path(repo, _text(docs_cfg.get("evidence_log")))
|
|
181
|
-
return
|
|
181
|
+
return _task_state_root(repo) / "evidence.jsonl"
|
|
182
182
|
|
|
183
183
|
|
|
184
184
|
def _gate_profile_path(repo: Path, cfg: dict) -> Path:
|
|
185
185
|
gate_cfg = _gate_cfg(cfg)
|
|
186
|
-
rel = _text(gate_cfg.get("profile_log"))
|
|
187
|
-
return Path(repo, rel)
|
|
186
|
+
rel = _text(gate_cfg.get("profile_log"))
|
|
187
|
+
return Path(repo, rel) if rel else _task_state_root(repo) / "gate-profile.jsonl"
|
|
188
188
|
|
|
189
189
|
|
|
190
190
|
def _record_evidence(repo: Path, cfg: dict, event: str, status: str, payload: Optional[dict] = None) -> None:
|
|
@@ -638,8 +638,8 @@ def _migrate_fast_development_defaults(cfg: dict, repo: Path) -> list[str]:
|
|
|
638
638
|
if _text(workflow_cfg.get("completion")).lower() != "push":
|
|
639
639
|
workflow_cfg["completion"] = "push"
|
|
640
640
|
changed.append("workflow.completion")
|
|
641
|
-
if _text(workflow_cfg.get("skill_version")) != "4.1.
|
|
642
|
-
workflow_cfg["skill_version"] = "4.1.
|
|
641
|
+
if _text(workflow_cfg.get("skill_version")) != "4.1.4":
|
|
642
|
+
workflow_cfg["skill_version"] = "4.1.4"
|
|
643
643
|
changed.append("workflow.skill_version")
|
|
644
644
|
|
|
645
645
|
commands_cfg = cfg.setdefault("commands", {})
|
|
@@ -952,16 +952,16 @@ def cmd_upgrade(args: argparse.Namespace) -> None:
|
|
|
952
952
|
if current_agents:
|
|
953
953
|
archive_dir = repo / "docs" / "archive" / "workflow"
|
|
954
954
|
archive_header = (
|
|
955
|
-
"# Archived AGENTS.md before auto-coding-skill 4.1.
|
|
955
|
+
"# Archived AGENTS.md before auto-coding-skill 4.1.4\n\n"
|
|
956
956
|
"This file is historical and non-authoritative. The root AGENTS.md is fully managed.\n"
|
|
957
957
|
"Move any still-current project facts into docs/ENGINEERING.md or docs/project/,\n"
|
|
958
958
|
"without copying workflow rules back into the root AGENTS.md.\n\n---\n\n"
|
|
959
959
|
)
|
|
960
960
|
archive_content = archive_header + current_agents
|
|
961
|
-
archive = archive_dir / "AGENTS.pre-4.1.
|
|
961
|
+
archive = archive_dir / "AGENTS.pre-4.1.4.md"
|
|
962
962
|
if archive.exists() and archive.read_text(encoding="utf-8") != archive_content:
|
|
963
963
|
digest = hashlib.sha256(current_agents.encode("utf-8")).hexdigest()[:12]
|
|
964
|
-
archive = archive_dir / f"AGENTS.pre-4.1.
|
|
964
|
+
archive = archive_dir / f"AGENTS.pre-4.1.4-{digest}.md"
|
|
965
965
|
if not archive.exists():
|
|
966
966
|
add_action("policy", archive, "archive", "historical and non-authoritative")
|
|
967
967
|
if write:
|
|
@@ -1662,6 +1662,7 @@ def _text(value: object) -> str:
|
|
|
1662
1662
|
|
|
1663
1663
|
|
|
1664
1664
|
_TASK_ID_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$")
|
|
1665
|
+
_DIRECT_CLAIM_ID_RE = re.compile(r"^[0-9a-f]{32}$")
|
|
1665
1666
|
|
|
1666
1667
|
|
|
1667
1668
|
def _concurrency_cfg(cfg: dict) -> dict:
|
|
@@ -1732,6 +1733,123 @@ def _task_registry_path(repo: Path, task_id: str) -> Path:
|
|
|
1732
1733
|
return _task_state_root(repo) / "tasks" / f"{_validate_task_id(task_id)}.json"
|
|
1733
1734
|
|
|
1734
1735
|
|
|
1736
|
+
def _direct_claim_path(repo: Path, claim_id: str) -> Path:
|
|
1737
|
+
value = _text(claim_id)
|
|
1738
|
+
if not _DIRECT_CLAIM_ID_RE.fullmatch(value):
|
|
1739
|
+
raise APError("Direct claim ID must be a 32-character lowercase hexadecimal token.")
|
|
1740
|
+
return _task_state_root(repo) / "direct-claims" / f"{value}.json"
|
|
1741
|
+
|
|
1742
|
+
|
|
1743
|
+
def _active_direct_claims(repo: Path) -> list[dict]:
|
|
1744
|
+
root = _task_state_root(repo) / "direct-claims"
|
|
1745
|
+
if not root.exists():
|
|
1746
|
+
return []
|
|
1747
|
+
active: list[dict] = []
|
|
1748
|
+
for path in sorted(root.glob("*.json")):
|
|
1749
|
+
payload = _read_json_object(path) or {}
|
|
1750
|
+
worktree = Path(_text(payload.get("worktree_path"))).resolve()
|
|
1751
|
+
valid_checkout = worktree.exists() and _text(payload.get("worktree_path"))
|
|
1752
|
+
if valid_checkout:
|
|
1753
|
+
try:
|
|
1754
|
+
valid_checkout = bool(
|
|
1755
|
+
_text(payload.get("base_sha")) == _resolve_commit(worktree, "HEAD")
|
|
1756
|
+
and _text(payload.get("branch")) == _current_branch(worktree)
|
|
1757
|
+
)
|
|
1758
|
+
except APError:
|
|
1759
|
+
valid_checkout = False
|
|
1760
|
+
if (
|
|
1761
|
+
int(payload.get("schema") or 0) != 1
|
|
1762
|
+
or _text(payload.get("state")) != "active"
|
|
1763
|
+
or not valid_checkout
|
|
1764
|
+
):
|
|
1765
|
+
path.unlink(missing_ok=True)
|
|
1766
|
+
continue
|
|
1767
|
+
active.append(payload)
|
|
1768
|
+
return active
|
|
1769
|
+
|
|
1770
|
+
|
|
1771
|
+
def _create_direct_claim(repo: Path, cfg: dict, owned_paths: list[str], owner: str) -> dict:
|
|
1772
|
+
normalized = sorted({_normalize_owned_path(item) for item in owned_paths if _text(item)})
|
|
1773
|
+
if not normalized:
|
|
1774
|
+
raise APError("A direct claim requires at least one planned path.")
|
|
1775
|
+
if not _text(owner):
|
|
1776
|
+
raise APError("A direct claim requires --claim-owner or CODEX_THREAD_ID.")
|
|
1777
|
+
if _task_isolation(cfg) != "adaptive":
|
|
1778
|
+
raise APError("Direct claims are available only with concurrency.isolation=adaptive.")
|
|
1779
|
+
if _working_tree_paths(repo):
|
|
1780
|
+
raise APError("A direct claim must be created while the checkout is clean, before the first write.")
|
|
1781
|
+
if _has_registered_active_task(repo):
|
|
1782
|
+
raise APError("A registered active task already owns repository writes.")
|
|
1783
|
+
branch = _current_branch(repo)
|
|
1784
|
+
if not branch:
|
|
1785
|
+
raise APError("A direct claim requires a named current branch.")
|
|
1786
|
+
timeout_s = float(_concurrency_cfg(cfg).get("lock_timeout_sec") or 30)
|
|
1787
|
+
with (
|
|
1788
|
+
_repo_lock(repo, "integration", timeout_s=timeout_s),
|
|
1789
|
+
_repo_lock(repo, "task-registry", timeout_s=timeout_s),
|
|
1790
|
+
_repo_lock(repo, "direct-claim", timeout_s=timeout_s),
|
|
1791
|
+
):
|
|
1792
|
+
if _working_tree_paths(repo):
|
|
1793
|
+
raise APError("Checkout changed while acquiring the direct claim; isolate instead.")
|
|
1794
|
+
if _has_registered_active_task(repo):
|
|
1795
|
+
raise APError("A registered active task acquired repository writes.")
|
|
1796
|
+
existing = _active_direct_claims(repo)
|
|
1797
|
+
other = [item for item in existing if _text(item.get("owner")) != _text(owner)]
|
|
1798
|
+
if other:
|
|
1799
|
+
raise APError(
|
|
1800
|
+
"Another direct writer already owns this checkout: "
|
|
1801
|
+
+ ", ".join(_text(item.get("owner")) for item in other)
|
|
1802
|
+
)
|
|
1803
|
+
for item in existing:
|
|
1804
|
+
_direct_claim_path(repo, _text(item.get("claim_id"))).unlink(missing_ok=True)
|
|
1805
|
+
claim_id = uuid.uuid4().hex
|
|
1806
|
+
payload = {
|
|
1807
|
+
"schema": 1,
|
|
1808
|
+
"claim_id": claim_id,
|
|
1809
|
+
"state": "active",
|
|
1810
|
+
"owner": _text(owner),
|
|
1811
|
+
"base_sha": _resolve_commit(repo, "HEAD"),
|
|
1812
|
+
"branch": branch,
|
|
1813
|
+
"worktree_path": str(repo.resolve()),
|
|
1814
|
+
"owned_paths": normalized,
|
|
1815
|
+
"created_at": _now_iso(),
|
|
1816
|
+
}
|
|
1817
|
+
_write_json_object(_direct_claim_path(repo, claim_id), payload)
|
|
1818
|
+
return payload
|
|
1819
|
+
|
|
1820
|
+
|
|
1821
|
+
def _require_direct_claim(repo: Path, claim_id: str, planned_paths: list[str]) -> dict:
|
|
1822
|
+
if not _text(claim_id):
|
|
1823
|
+
raise APError(
|
|
1824
|
+
"--continue-direct requires --direct-claim from a clean pre-write classify --claim-direct."
|
|
1825
|
+
)
|
|
1826
|
+
payload = _read_json_object(_direct_claim_path(repo, claim_id)) or {}
|
|
1827
|
+
normalized = sorted({_normalize_owned_path(item) for item in planned_paths if _text(item)})
|
|
1828
|
+
if int(payload.get("schema") or 0) != 1 or _text(payload.get("state")) != "active":
|
|
1829
|
+
raise APError("Direct claim is missing, consumed, or invalid.")
|
|
1830
|
+
if normalized != sorted(payload.get("owned_paths") or []):
|
|
1831
|
+
raise APError("Continued direct paths must exactly match the clean pre-write direct claim.")
|
|
1832
|
+
if _text(payload.get("base_sha")) != _resolve_commit(repo, "HEAD"):
|
|
1833
|
+
raise APError("Direct claim base HEAD changed; use an isolated task instead.")
|
|
1834
|
+
if _text(payload.get("branch")) != _current_branch(repo):
|
|
1835
|
+
raise APError("Direct claim branch changed; use an isolated task instead.")
|
|
1836
|
+
if Path(_text(payload.get("worktree_path"))).resolve() != repo.resolve():
|
|
1837
|
+
raise APError("Direct claim belongs to another checkout.")
|
|
1838
|
+
actor = _text(os.environ.get("CODEX_THREAD_ID"))
|
|
1839
|
+
if actor and actor != _text(payload.get("owner")):
|
|
1840
|
+
raise APError("Direct claim belongs to another writer.")
|
|
1841
|
+
dirty = _working_tree_paths(repo)
|
|
1842
|
+
outside = [path for path in dirty if not _path_is_owned(path, normalized)]
|
|
1843
|
+
if outside:
|
|
1844
|
+
raise APError("Changes outside the clean direct claim:\n- " + "\n- ".join(outside))
|
|
1845
|
+
return payload
|
|
1846
|
+
|
|
1847
|
+
|
|
1848
|
+
def _consume_direct_claim(repo: Path, claim_id: str) -> None:
|
|
1849
|
+
if _text(claim_id):
|
|
1850
|
+
_direct_claim_path(repo, claim_id).unlink(missing_ok=True)
|
|
1851
|
+
|
|
1852
|
+
|
|
1735
1853
|
def _has_registered_active_task(repo: Path) -> bool:
|
|
1736
1854
|
registry = _task_state_root(repo) / "tasks"
|
|
1737
1855
|
if not registry.exists():
|
|
@@ -2477,7 +2595,8 @@ def _resolve_secret(section_name: str, section_cfg: dict, field: str) -> str:
|
|
|
2477
2595
|
|
|
2478
2596
|
_GATE_SCOPES = {"auto", "changed", "standard", "full"}
|
|
2479
2597
|
_WORKFLOW_PROFILES = {"auto", "micro", "standard", "high-risk"}
|
|
2480
|
-
_TASK_KINDS = {"
|
|
2598
|
+
_TASK_KINDS = {"none", "read_only", "change", "terminal_maintenance"}
|
|
2599
|
+
_REQUESTED_TASK_KINDS = (_TASK_KINDS - {"none"}) | {"auto"}
|
|
2481
2600
|
_PROFILE_GATE_SCOPE = {"micro": "changed", "standard": "changed", "high-risk": "changed"}
|
|
2482
2601
|
_PROFILE_RANK = {"micro": 0, "standard": 1, "high-risk": 2}
|
|
2483
2602
|
_SCOPE_RANK = {"changed": 0, "standard": 1, "full": 2}
|
|
@@ -4424,9 +4543,14 @@ def _classify_paths(paths: list[str]) -> dict:
|
|
|
4424
4543
|
categories.add("db")
|
|
4425
4544
|
if any(token in lower for token in ["api", "controller", "handler", "route", "server"]):
|
|
4426
4545
|
categories.add("api")
|
|
4427
|
-
if words & {
|
|
4546
|
+
if words & {
|
|
4547
|
+
"auth", "authentication", "authorization", "permission", "permissions",
|
|
4548
|
+
"role", "roles", "tenant", "security", "login", "session", "sessions",
|
|
4549
|
+
"token", "tokens", "jwt", "oauth", "oidc", "sso", "password", "passwords",
|
|
4550
|
+
"credential", "credentials",
|
|
4551
|
+
}:
|
|
4428
4552
|
categories.add("auth")
|
|
4429
|
-
if words & {"payment", "payments", "billing", "invoice", "invoices", "checkout"
|
|
4553
|
+
if words & {"payment", "payments", "billing", "invoice", "invoices", "checkout"}:
|
|
4430
4554
|
categories.add("payment")
|
|
4431
4555
|
if words & {"upload", "uploads", "download", "downloads", "attachment", "attachments"}:
|
|
4432
4556
|
categories.add("file_transfer")
|
|
@@ -4488,23 +4612,56 @@ def _classify_intent(intent: str) -> list[str]:
|
|
|
4488
4612
|
)
|
|
4489
4613
|
|
|
4490
4614
|
|
|
4615
|
+
def _high_confidence_intent_categories(intent: str) -> set[str]:
|
|
4616
|
+
value = _text(intent).lower()
|
|
4617
|
+
signals = {
|
|
4618
|
+
"db": [
|
|
4619
|
+
"migration", "schema", "ddl", "sql", "table structure", "database migration",
|
|
4620
|
+
"数据迁移", "数据库迁移", "表结构", "数据库结构",
|
|
4621
|
+
],
|
|
4622
|
+
"auth": [
|
|
4623
|
+
"authorization", "permission", "security boundary", "token validation",
|
|
4624
|
+
"session validation", "access control", "鉴权", "权限", "安全边界",
|
|
4625
|
+
"令牌校验", "会话校验", "访问控制",
|
|
4626
|
+
],
|
|
4627
|
+
"payment": [
|
|
4628
|
+
"settlement", "refund", "charge", "transaction", "billing", "ledger",
|
|
4629
|
+
"payment idempotency", "结算", "退款", "扣款", "交易", "账单", "资金", "支付幂等",
|
|
4630
|
+
],
|
|
4631
|
+
"file_transfer": [
|
|
4632
|
+
"upload validation", "download authorization", "file validation", "path traversal",
|
|
4633
|
+
"上传校验", "下载权限", "文件校验", "路径穿越",
|
|
4634
|
+
],
|
|
4635
|
+
"gateway": [
|
|
4636
|
+
"gateway config", "ingress config", "nginx config", "reverse proxy config",
|
|
4637
|
+
"网关配置", "入口配置", "反向代理配置",
|
|
4638
|
+
],
|
|
4639
|
+
"prod_config": ["production config", "prod config", "生产配置"],
|
|
4640
|
+
"release_or_tooling": [
|
|
4641
|
+
"release pipeline", "deployment pipeline", "jenkins pipeline", "publish workflow",
|
|
4642
|
+
"发布流程", "部署流水线", "构建流水线", "发布工作流",
|
|
4643
|
+
],
|
|
4644
|
+
}
|
|
4645
|
+
return {
|
|
4646
|
+
category
|
|
4647
|
+
for category, keywords in signals.items()
|
|
4648
|
+
if any(keyword in value for keyword in keywords)
|
|
4649
|
+
}
|
|
4650
|
+
|
|
4651
|
+
|
|
4491
4652
|
def _resolve_task_kind(
|
|
4492
4653
|
requested: str,
|
|
4493
4654
|
paths: list[str],
|
|
4494
4655
|
intent: str,
|
|
4495
4656
|
) -> str:
|
|
4496
4657
|
value = _text(requested).lower().replace("-", "_") or "auto"
|
|
4497
|
-
if value not in
|
|
4498
|
-
raise APError("task kind must be one of: " + ", ".join(sorted(
|
|
4499
|
-
if value != "auto":
|
|
4500
|
-
return value
|
|
4658
|
+
if value not in _REQUESTED_TASK_KINDS:
|
|
4659
|
+
raise APError("task kind must be one of: " + ", ".join(sorted(_REQUESTED_TASK_KINDS)))
|
|
4501
4660
|
if _is_terminal_ledger_maintenance(paths):
|
|
4661
|
+
if value in {"change", "read_only"}:
|
|
4662
|
+
return value
|
|
4502
4663
|
return "terminal_maintenance"
|
|
4503
|
-
if paths:
|
|
4504
|
-
return "change"
|
|
4505
4664
|
normalized_intent = _text(intent).lower()
|
|
4506
|
-
if not normalized_intent:
|
|
4507
|
-
return "none"
|
|
4508
4665
|
terminal_action = bool(
|
|
4509
4666
|
re.search(r"\b(archive|close|reconcile)\b", normalized_intent)
|
|
4510
4667
|
or any(keyword in normalized_intent for keyword in ["归档", "对账", "收口"])
|
|
@@ -4514,7 +4671,22 @@ def _resolve_task_kind(
|
|
|
4514
4671
|
or any(keyword in normalized_intent for keyword in ["台账", "任务记录", "关闭记录"])
|
|
4515
4672
|
)
|
|
4516
4673
|
if terminal_action and terminal_subject:
|
|
4517
|
-
|
|
4674
|
+
detected = "terminal_maintenance"
|
|
4675
|
+
elif paths:
|
|
4676
|
+
detected = "change"
|
|
4677
|
+
elif not normalized_intent:
|
|
4678
|
+
detected = "none"
|
|
4679
|
+
else:
|
|
4680
|
+
detected = ""
|
|
4681
|
+
if value == "terminal_maintenance" and detected != "terminal_maintenance":
|
|
4682
|
+
raise APError(
|
|
4683
|
+
"terminal_maintenance is valid only for task ledger/closure/archive reconciliation; "
|
|
4684
|
+
"code or unrelated documentation paths require task-kind=change"
|
|
4685
|
+
)
|
|
4686
|
+
if value != "auto":
|
|
4687
|
+
return value
|
|
4688
|
+
if detected:
|
|
4689
|
+
return detected
|
|
4518
4690
|
english_change = re.search(
|
|
4519
4691
|
r"\b(add|build|change|create|delete|deploy|develop|fix|implement|migrate|optimize|publish|refactor|release|remove|rename|resolve|update|upgrade)\b",
|
|
4520
4692
|
normalized_intent,
|
|
@@ -4529,6 +4701,36 @@ def _resolve_task_kind(
|
|
|
4529
4701
|
return "change" if english_change or chinese_change else "read_only"
|
|
4530
4702
|
|
|
4531
4703
|
|
|
4704
|
+
def _optional_agent_candidates(
|
|
4705
|
+
*,
|
|
4706
|
+
task_kind: str,
|
|
4707
|
+
intent: str,
|
|
4708
|
+
categories: set[str],
|
|
4709
|
+
cross_module: bool,
|
|
4710
|
+
profile: str,
|
|
4711
|
+
) -> list[str]:
|
|
4712
|
+
if task_kind not in {"read_only", "change"}:
|
|
4713
|
+
return []
|
|
4714
|
+
value = _text(intent).lower()
|
|
4715
|
+
roles: list[str] = []
|
|
4716
|
+
if task_kind == "read_only" or cross_module or profile == "high-risk":
|
|
4717
|
+
roles.append("explorer")
|
|
4718
|
+
if any(
|
|
4719
|
+
keyword in value
|
|
4720
|
+
for keyword in [
|
|
4721
|
+
"documentation", "docs", "framework", "library", "official", "sdk", "version",
|
|
4722
|
+
"依赖", "官方", "文档", "框架", "版本",
|
|
4723
|
+
]
|
|
4724
|
+
):
|
|
4725
|
+
roles.append("docs_researcher")
|
|
4726
|
+
if "ui" in categories and any(
|
|
4727
|
+
keyword in value
|
|
4728
|
+
for keyword in ["broken", "bug", "error", "fail", "fix", "reproduce", "报错", "复现", "失败", "异常", "修复"]
|
|
4729
|
+
):
|
|
4730
|
+
roles.append("browser_debugger")
|
|
4731
|
+
return roles
|
|
4732
|
+
|
|
4733
|
+
|
|
4532
4734
|
def _normalize_workflow_profile(value: object, default: str = "auto") -> str:
|
|
4533
4735
|
profile = _text(value).lower() or default
|
|
4534
4736
|
if profile not in _WORKFLOW_PROFILES:
|
|
@@ -4605,6 +4807,154 @@ def _agent_contract_shape() -> tuple[dict, list[str]]:
|
|
|
4605
4807
|
)
|
|
4606
4808
|
|
|
4607
4809
|
|
|
4810
|
+
_ORCHESTRATION_SCHEMA_CACHE: Optional[dict] = None
|
|
4811
|
+
|
|
4812
|
+
|
|
4813
|
+
def _orchestration_schema() -> dict:
|
|
4814
|
+
global _ORCHESTRATION_SCHEMA_CACHE
|
|
4815
|
+
if _ORCHESTRATION_SCHEMA_CACHE is None:
|
|
4816
|
+
path = Path(__file__).resolve().parents[1] / _AGENT_CONTRACT_SCHEMA
|
|
4817
|
+
try:
|
|
4818
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
4819
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
4820
|
+
raise APError(f"Cannot load orchestration contract schema: {path}: {exc}") from exc
|
|
4821
|
+
if not isinstance(payload, dict):
|
|
4822
|
+
raise APError(f"Orchestration contract schema must be an object: {path}")
|
|
4823
|
+
_ORCHESTRATION_SCHEMA_CACHE = payload
|
|
4824
|
+
return _ORCHESTRATION_SCHEMA_CACHE
|
|
4825
|
+
|
|
4826
|
+
|
|
4827
|
+
def _contract_ref(root: dict, ref: str) -> dict:
|
|
4828
|
+
if not ref.startswith("#/"):
|
|
4829
|
+
raise APError(f"Unsupported orchestration contract reference: {ref}")
|
|
4830
|
+
current: object = root
|
|
4831
|
+
for token in ref[2:].split("/"):
|
|
4832
|
+
token = token.replace("~1", "/").replace("~0", "~")
|
|
4833
|
+
if not isinstance(current, dict) or token not in current:
|
|
4834
|
+
raise APError(f"Broken orchestration contract reference: {ref}")
|
|
4835
|
+
current = current[token]
|
|
4836
|
+
if not isinstance(current, dict):
|
|
4837
|
+
raise APError(f"Orchestration contract reference is not an object: {ref}")
|
|
4838
|
+
return current
|
|
4839
|
+
|
|
4840
|
+
|
|
4841
|
+
def _contract_type_matches(value: object, expected: str) -> bool:
|
|
4842
|
+
return {
|
|
4843
|
+
"object": isinstance(value, dict),
|
|
4844
|
+
"array": isinstance(value, list),
|
|
4845
|
+
"string": isinstance(value, str),
|
|
4846
|
+
"boolean": isinstance(value, bool),
|
|
4847
|
+
"null": value is None,
|
|
4848
|
+
"integer": isinstance(value, int) and not isinstance(value, bool),
|
|
4849
|
+
"number": isinstance(value, (int, float)) and not isinstance(value, bool),
|
|
4850
|
+
}.get(expected, False)
|
|
4851
|
+
|
|
4852
|
+
|
|
4853
|
+
def _contract_equal(left: object, right: object) -> bool:
|
|
4854
|
+
if isinstance(left, bool) or isinstance(right, bool):
|
|
4855
|
+
return type(left) is type(right) and left == right
|
|
4856
|
+
return left == right
|
|
4857
|
+
|
|
4858
|
+
|
|
4859
|
+
def _validate_contract_fragment(fragment: dict, value: object, root: dict, path: str) -> None:
|
|
4860
|
+
if "$ref" in fragment:
|
|
4861
|
+
_validate_contract_fragment(_contract_ref(root, _text(fragment["$ref"])), value, root, path)
|
|
4862
|
+
|
|
4863
|
+
expected_types = fragment.get("type")
|
|
4864
|
+
if expected_types is not None:
|
|
4865
|
+
choices = expected_types if isinstance(expected_types, list) else [expected_types]
|
|
4866
|
+
if not all(isinstance(item, str) for item in choices) or not any(
|
|
4867
|
+
_contract_type_matches(value, item) for item in choices
|
|
4868
|
+
):
|
|
4869
|
+
raise APError(f"Contract validation failed at {path}: expected type {choices}.")
|
|
4870
|
+
|
|
4871
|
+
if "const" in fragment and not _contract_equal(value, fragment["const"]):
|
|
4872
|
+
raise APError(f"Contract validation failed at {path}: expected constant {fragment['const']!r}.")
|
|
4873
|
+
if "enum" in fragment and not any(_contract_equal(value, item) for item in fragment["enum"]):
|
|
4874
|
+
raise APError(f"Contract validation failed at {path}: value is outside the allowed enum.")
|
|
4875
|
+
|
|
4876
|
+
if isinstance(value, str):
|
|
4877
|
+
if len(value) < int(fragment.get("minLength") or 0):
|
|
4878
|
+
raise APError(f"Contract validation failed at {path}: string is too short.")
|
|
4879
|
+
pattern = fragment.get("pattern")
|
|
4880
|
+
if pattern and not re.search(str(pattern), value):
|
|
4881
|
+
raise APError(f"Contract validation failed at {path}: string does not match {pattern!r}.")
|
|
4882
|
+
|
|
4883
|
+
if isinstance(value, list):
|
|
4884
|
+
if "maxItems" in fragment and len(value) > int(fragment["maxItems"]):
|
|
4885
|
+
raise APError(f"Contract validation failed at {path}: too many array items.")
|
|
4886
|
+
item_schema = fragment.get("items")
|
|
4887
|
+
if isinstance(item_schema, dict):
|
|
4888
|
+
for index, item in enumerate(value):
|
|
4889
|
+
_validate_contract_fragment(item_schema, item, root, f"{path}[{index}]")
|
|
4890
|
+
|
|
4891
|
+
if isinstance(value, dict):
|
|
4892
|
+
required = fragment.get("required") or []
|
|
4893
|
+
missing = [item for item in required if item not in value]
|
|
4894
|
+
if missing:
|
|
4895
|
+
raise APError(
|
|
4896
|
+
f"Contract validation failed at {path}: missing " + ", ".join(sorted(missing)) + "."
|
|
4897
|
+
)
|
|
4898
|
+
properties = fragment.get("properties") or {}
|
|
4899
|
+
if fragment.get("additionalProperties") is False:
|
|
4900
|
+
unexpected = sorted(set(value) - set(properties))
|
|
4901
|
+
if unexpected:
|
|
4902
|
+
raise APError(
|
|
4903
|
+
f"Contract validation failed at {path}: unexpected " + ", ".join(unexpected) + "."
|
|
4904
|
+
)
|
|
4905
|
+
for key, child in properties.items():
|
|
4906
|
+
if key in value and isinstance(child, dict):
|
|
4907
|
+
_validate_contract_fragment(child, value[key], root, f"{path}.{key}")
|
|
4908
|
+
|
|
4909
|
+
condition = fragment.get("if")
|
|
4910
|
+
if isinstance(condition, dict):
|
|
4911
|
+
try:
|
|
4912
|
+
_validate_contract_fragment(condition, value, root, path)
|
|
4913
|
+
except APError:
|
|
4914
|
+
pass
|
|
4915
|
+
else:
|
|
4916
|
+
then = fragment.get("then")
|
|
4917
|
+
if isinstance(then, dict):
|
|
4918
|
+
_validate_contract_fragment(then, value, root, path)
|
|
4919
|
+
|
|
4920
|
+
for child in fragment.get("allOf") or []:
|
|
4921
|
+
if isinstance(child, dict):
|
|
4922
|
+
_validate_contract_fragment(child, value, root, path)
|
|
4923
|
+
|
|
4924
|
+
|
|
4925
|
+
def _validate_orchestration_contract(kind: str, payload: dict) -> dict:
|
|
4926
|
+
definitions = {
|
|
4927
|
+
"assignment": "agentAssignment",
|
|
4928
|
+
"result": "agentResult",
|
|
4929
|
+
"agentPlan": "agentPlan",
|
|
4930
|
+
"classify": "classifyResult",
|
|
4931
|
+
}
|
|
4932
|
+
definition = definitions.get(kind)
|
|
4933
|
+
if not definition:
|
|
4934
|
+
raise APError(f"Unknown orchestration contract kind: {kind}")
|
|
4935
|
+
root = _orchestration_schema()
|
|
4936
|
+
_validate_contract_fragment(root["$defs"][definition], payload, root, "$")
|
|
4937
|
+
|
|
4938
|
+
role = _text(payload.get("role"))
|
|
4939
|
+
if kind == "assignment" and role == "reviewer":
|
|
4940
|
+
if _text(payload.get("node_id")) == _text(payload.get("owning_fixer")):
|
|
4941
|
+
raise APError("Reviewer assignment node_id must differ from owning_fixer.")
|
|
4942
|
+
if kind == "result":
|
|
4943
|
+
if role == "fixer":
|
|
4944
|
+
owned = [_normalize_owned_path(item) for item in payload.get("owned_paths") or []]
|
|
4945
|
+
outside = [
|
|
4946
|
+
path
|
|
4947
|
+
for path in payload.get("changed_paths") or []
|
|
4948
|
+
if not _path_is_owned(path, owned)
|
|
4949
|
+
]
|
|
4950
|
+
if outside:
|
|
4951
|
+
raise APError("Fixer result changed_paths exceed owned_paths: " + ", ".join(outside))
|
|
4952
|
+
if role == "reviewer" and _text(payload.get("verdict")) in {"approved", "changes-requested"}:
|
|
4953
|
+
if not re.fullmatch(r"[0-9a-f]{64}", _text(payload.get("diff_fingerprint"))):
|
|
4954
|
+
raise APError("Reviewer result must bind its verdict to a non-empty diff fingerprint.")
|
|
4955
|
+
return payload
|
|
4956
|
+
|
|
4957
|
+
|
|
4608
4958
|
def _validate_agent_plan(plan: dict) -> dict:
|
|
4609
4959
|
required = {
|
|
4610
4960
|
"contract_version",
|
|
@@ -4615,18 +4965,12 @@ def _validate_agent_plan(plan: dict) -> dict:
|
|
|
4615
4965
|
"result_contract",
|
|
4616
4966
|
"stages",
|
|
4617
4967
|
"constraints",
|
|
4968
|
+
"optional_roles",
|
|
4618
4969
|
}
|
|
4619
4970
|
missing = sorted(required - set(plan))
|
|
4620
|
-
if missing
|
|
4621
|
-
raise APError("Invalid agent plan contract: " +
|
|
4622
|
-
|
|
4623
|
-
raise APError("Invalid agent plan schema path.")
|
|
4624
|
-
if not all(
|
|
4625
|
-
isinstance(stage, dict)
|
|
4626
|
-
and {"id", "mode", "roles", "depends_on"} <= set(stage)
|
|
4627
|
-
for stage in plan.get("stages") or []
|
|
4628
|
-
):
|
|
4629
|
-
raise APError("Invalid agent plan stage contract.")
|
|
4971
|
+
if missing:
|
|
4972
|
+
raise APError("Invalid agent plan contract: " + ", ".join(missing))
|
|
4973
|
+
_validate_orchestration_contract("agentPlan", plan)
|
|
4630
4974
|
return plan
|
|
4631
4975
|
|
|
4632
4976
|
|
|
@@ -4637,11 +4981,12 @@ def _agent_execution_plan(
|
|
|
4637
4981
|
*,
|
|
4638
4982
|
parallel_writers: int = 1,
|
|
4639
4983
|
review_required: bool = False,
|
|
4984
|
+
optional_roles: Optional[list[str]] = None,
|
|
4640
4985
|
) -> dict:
|
|
4641
4986
|
assignment_contract, result_contract = _agent_contract_shape()
|
|
4642
|
-
|
|
4643
|
-
#
|
|
4644
|
-
# exceeds coordination cost.
|
|
4987
|
+
optional_roles = list(dict.fromkeys(optional_roles or []))
|
|
4988
|
+
# Optional roles are candidates, never automatic stages. The model selects
|
|
4989
|
+
# them only when expected benefit exceeds coordination cost.
|
|
4645
4990
|
discovery_roles: list[str] = []
|
|
4646
4991
|
|
|
4647
4992
|
policies = {
|
|
@@ -4694,7 +5039,7 @@ def _agent_execution_plan(
|
|
|
4694
5039
|
"depends_on": [previous],
|
|
4695
5040
|
}
|
|
4696
5041
|
)
|
|
4697
|
-
strategy = "
|
|
5042
|
+
strategy = "orchestrated-subagents"
|
|
4698
5043
|
|
|
4699
5044
|
return _validate_agent_plan({
|
|
4700
5045
|
"contract_version": _AGENT_CONTRACT_VERSION,
|
|
@@ -4703,6 +5048,7 @@ def _agent_execution_plan(
|
|
|
4703
5048
|
"policies": policies,
|
|
4704
5049
|
"assignment_contract": assignment_contract,
|
|
4705
5050
|
"result_contract": result_contract,
|
|
5051
|
+
"optional_roles": optional_roles,
|
|
4706
5052
|
"stages": stages,
|
|
4707
5053
|
"constraints": constraints,
|
|
4708
5054
|
})
|
|
@@ -4747,8 +5093,6 @@ def _mechanism_plan(
|
|
|
4747
5093
|
required.append("task_lifecycle")
|
|
4748
5094
|
if parallel_writers > 1:
|
|
4749
5095
|
required.append("parallel_fixers")
|
|
4750
|
-
else:
|
|
4751
|
-
optional.append("parallel_fixers")
|
|
4752
5096
|
if review_required:
|
|
4753
5097
|
required.append("independent_review")
|
|
4754
5098
|
else:
|
|
@@ -4768,7 +5112,8 @@ def _mechanism_plan(
|
|
|
4768
5112
|
"lifecycle_required": "task_lifecycle" in ordered,
|
|
4769
5113
|
"rule": (
|
|
4770
5114
|
"run required mechanisms; select optional mechanisms only when expected value exceeds "
|
|
4771
|
-
"coordination cost;
|
|
5115
|
+
"coordination cost; reclassify before changing writer count; do not run forbidden "
|
|
5116
|
+
"mechanisms unless the user explicitly overrides"
|
|
4772
5117
|
),
|
|
4773
5118
|
}
|
|
4774
5119
|
|
|
@@ -4786,6 +5131,8 @@ def _resolve_execution_plan(
|
|
|
4786
5131
|
intent: str = "",
|
|
4787
5132
|
parallel_writers: int = 1,
|
|
4788
5133
|
requested_task_kind: str = "",
|
|
5134
|
+
continue_direct: bool = False,
|
|
5135
|
+
direct_claim_id: str = "",
|
|
4789
5136
|
) -> dict:
|
|
4790
5137
|
impact = _impact_summary(
|
|
4791
5138
|
cfg,
|
|
@@ -4800,9 +5147,11 @@ def _resolve_execution_plan(
|
|
|
4800
5147
|
)
|
|
4801
5148
|
classification_inputs = [*paths, *normalized_planned_paths]
|
|
4802
5149
|
task_kind = _resolve_task_kind(requested_task_kind, classification_inputs, intent)
|
|
4803
|
-
|
|
5150
|
+
path_classification = _classify_paths(classification_inputs)
|
|
5151
|
+
path_categories = set(path_classification["categories"])
|
|
4804
5152
|
intent_categories = _classify_intent(intent)
|
|
4805
|
-
|
|
5153
|
+
high_confidence_intent_categories = _high_confidence_intent_categories(intent)
|
|
5154
|
+
merged_categories = path_categories | set(intent_categories)
|
|
4806
5155
|
classification = _classification_for_categories(merged_categories, len(classification_inputs))
|
|
4807
5156
|
categories = set(classification["categories"])
|
|
4808
5157
|
matching_rules = _matching_risk_rules(classification_inputs, cfg)
|
|
@@ -4851,11 +5200,37 @@ def _resolve_execution_plan(
|
|
|
4851
5200
|
"prod_config",
|
|
4852
5201
|
"release_or_tooling",
|
|
4853
5202
|
}
|
|
5203
|
+
default_high_path_categories: set[str] = set()
|
|
5204
|
+
path_category_sets: list[set[str]] = []
|
|
5205
|
+
for path in classification_inputs:
|
|
5206
|
+
per_path = set(_classify_paths([path])["categories"])
|
|
5207
|
+
path_category_sets.append(per_path)
|
|
5208
|
+
default_high_path_categories.update(
|
|
5209
|
+
per_path & {"db", "gateway", "prod_config", "release_or_tooling"}
|
|
5210
|
+
)
|
|
5211
|
+
if "ui" not in per_path:
|
|
5212
|
+
default_high_path_categories.update(
|
|
5213
|
+
per_path & {"auth", "payment", "file_transfer"}
|
|
5214
|
+
)
|
|
5215
|
+
intent_risk_candidates = sorted(set(intent_categories) & high_categories)
|
|
5216
|
+
all_planned_code_paths_are_ui = bool(path_category_sets) and all(
|
|
5217
|
+
"ui" in per_path or per_path <= {"docs", "test"}
|
|
5218
|
+
for per_path in path_category_sets
|
|
5219
|
+
)
|
|
5220
|
+
default_high_intent_categories = set(high_confidence_intent_categories)
|
|
5221
|
+
if all_planned_code_paths_are_ui:
|
|
5222
|
+
default_high_intent_categories.difference_update({"auth", "payment", "file_transfer"})
|
|
4854
5223
|
high_signals: list[str] = []
|
|
4855
|
-
if task_kind == "change" and
|
|
4856
|
-
high_signals.append(
|
|
5224
|
+
if task_kind == "change" and default_high_path_categories and not docs_or_tests_only:
|
|
5225
|
+
high_signals.append(
|
|
5226
|
+
"high-risk path category: " + ", ".join(sorted(default_high_path_categories))
|
|
5227
|
+
)
|
|
4857
5228
|
if task_kind == "change" and "high-risk" in rule_profiles:
|
|
4858
5229
|
high_signals.append("matched gate rule with profile=high-risk")
|
|
5230
|
+
if task_kind == "change" and default_high_intent_categories and not docs_or_tests_only:
|
|
5231
|
+
high_signals.append(
|
|
5232
|
+
"high-confidence risk intent: " + ", ".join(sorted(default_high_intent_categories))
|
|
5233
|
+
)
|
|
4859
5234
|
if high_signals:
|
|
4860
5235
|
detected_profile = "high-risk"
|
|
4861
5236
|
profile_reasons.extend(high_signals)
|
|
@@ -4914,11 +5289,42 @@ def _resolve_execution_plan(
|
|
|
4914
5289
|
task_kind == "change"
|
|
4915
5290
|
and (rule_design or (effective_profile == "high-risk" and cross_module))
|
|
4916
5291
|
)
|
|
4917
|
-
|
|
4918
|
-
|
|
5292
|
+
dirty_paths = _working_tree_paths(repo)
|
|
5293
|
+
workspace_dirty = bool(dirty_paths)
|
|
5294
|
+
dirty_outside_plan = [
|
|
5295
|
+
path for path in dirty_paths if not _path_is_owned(path, normalized_planned_paths)
|
|
5296
|
+
] if normalized_planned_paths else list(dirty_paths)
|
|
5297
|
+
registered_active_writer = _has_registered_active_task(repo)
|
|
4919
5298
|
configured_isolation = _task_isolation(cfg)
|
|
5299
|
+
if continue_direct and task_kind != "change":
|
|
5300
|
+
raise APError("--continue-direct is valid only for task-kind=change")
|
|
5301
|
+
if continue_direct and not normalized_planned_paths:
|
|
5302
|
+
raise APError("--continue-direct requires every current task path via --planned-path")
|
|
5303
|
+
direct_claim = (
|
|
5304
|
+
_require_direct_claim(repo, direct_claim_id, normalized_planned_paths)
|
|
5305
|
+
if continue_direct
|
|
5306
|
+
else {}
|
|
5307
|
+
)
|
|
5308
|
+
runtime_actor = _text(os.environ.get("CODEX_THREAD_ID"))
|
|
5309
|
+
other_direct_claims = [
|
|
5310
|
+
item
|
|
5311
|
+
for item in _active_direct_claims(repo)
|
|
5312
|
+
if _text(item.get("claim_id")) != _text(direct_claim_id)
|
|
5313
|
+
and (not runtime_actor or _text(item.get("owner")) != runtime_actor)
|
|
5314
|
+
]
|
|
5315
|
+
active_writer = bool(registered_active_writer or other_direct_claims)
|
|
5316
|
+
continued_direct = bool(
|
|
5317
|
+
continue_direct
|
|
5318
|
+
and direct_claim
|
|
5319
|
+
and configured_isolation == "adaptive"
|
|
5320
|
+
and writer_count == 1
|
|
5321
|
+
and not active_writer
|
|
5322
|
+
and not dirty_outside_plan
|
|
5323
|
+
)
|
|
4920
5324
|
if task_kind != "change":
|
|
4921
5325
|
execution_mode = "none"
|
|
5326
|
+
elif continued_direct:
|
|
5327
|
+
execution_mode = "direct"
|
|
4922
5328
|
elif configured_isolation == "worktree" or writer_count > 1 or workspace_dirty or active_writer:
|
|
4923
5329
|
execution_mode = "isolated"
|
|
4924
5330
|
else:
|
|
@@ -4926,17 +5332,29 @@ def _resolve_execution_plan(
|
|
|
4926
5332
|
execution_reasons.append(
|
|
4927
5333
|
"execution mode is adaptive: clean single-writer work is direct; dirty or parallel work is isolated"
|
|
4928
5334
|
)
|
|
5335
|
+
if continued_direct:
|
|
5336
|
+
execution_reasons.append(
|
|
5337
|
+
"continued direct mode: all current dirty paths are covered by declared planned paths"
|
|
5338
|
+
)
|
|
4929
5339
|
|
|
4930
5340
|
needs_jenkins = False
|
|
4931
5341
|
needs_target = False
|
|
4932
5342
|
needs_dd = design_required
|
|
4933
5343
|
|
|
5344
|
+
optional_agents = _optional_agent_candidates(
|
|
5345
|
+
task_kind=task_kind,
|
|
5346
|
+
intent=intent,
|
|
5347
|
+
categories=categories,
|
|
5348
|
+
cross_module=cross_module,
|
|
5349
|
+
profile=effective_profile,
|
|
5350
|
+
)
|
|
4934
5351
|
agent_plan = _agent_execution_plan(
|
|
4935
5352
|
effective_profile,
|
|
4936
5353
|
categories,
|
|
4937
5354
|
classification,
|
|
4938
5355
|
parallel_writers=writer_count,
|
|
4939
5356
|
review_required=review_required,
|
|
5357
|
+
optional_roles=optional_agents,
|
|
4940
5358
|
)
|
|
4941
5359
|
mechanism_plan = _mechanism_plan(
|
|
4942
5360
|
task_kind=task_kind,
|
|
@@ -4954,6 +5372,8 @@ def _resolve_execution_plan(
|
|
|
4954
5372
|
"intent_provided": bool(_text(intent)),
|
|
4955
5373
|
"task_kind": task_kind,
|
|
4956
5374
|
"intent_categories": intent_categories,
|
|
5375
|
+
"intent_risk_candidates": intent_risk_candidates,
|
|
5376
|
+
"high_confidence_intent_categories": sorted(high_confidence_intent_categories),
|
|
4957
5377
|
"reasons": execution_reasons,
|
|
4958
5378
|
"configured_profile": configured_profile,
|
|
4959
5379
|
"requested_profile": requested_profile_value or None,
|
|
@@ -4965,6 +5385,9 @@ def _resolve_execution_plan(
|
|
|
4965
5385
|
"execution_mode": execution_mode,
|
|
4966
5386
|
"terminal_maintenance": terminal_maintenance,
|
|
4967
5387
|
"workspace_dirty": workspace_dirty,
|
|
5388
|
+
"dirty_paths": dirty_paths,
|
|
5389
|
+
"dirty_outside_plan": dirty_outside_plan,
|
|
5390
|
+
"continued_direct": continued_direct,
|
|
4968
5391
|
"active_writer": active_writer,
|
|
4969
5392
|
"parallel_writers": writer_count,
|
|
4970
5393
|
"cross_module": cross_module,
|
|
@@ -4984,6 +5407,7 @@ def _resolve_execution_plan(
|
|
|
4984
5407
|
parallel_writers=writer_count,
|
|
4985
5408
|
review_required=review_required,
|
|
4986
5409
|
),
|
|
5410
|
+
"optional_agents": optional_agents,
|
|
4987
5411
|
"agent_plan": agent_plan,
|
|
4988
5412
|
"mechanism_plan": mechanism_plan,
|
|
4989
5413
|
}
|
|
@@ -5004,6 +5428,11 @@ def cmd_classify(args: argparse.Namespace) -> None:
|
|
|
5004
5428
|
intent_parts.append(path.read_text(encoding="utf-8"))
|
|
5005
5429
|
except OSError as exc:
|
|
5006
5430
|
raise APError(f"Cannot read --intent-file: {path}: {exc}") from exc
|
|
5431
|
+
claim_direct = bool(getattr(args, "claim_direct", False))
|
|
5432
|
+
continue_direct = bool(getattr(args, "continue_direct", False))
|
|
5433
|
+
direct_claim_id = _text(getattr(args, "direct_claim", ""))
|
|
5434
|
+
if claim_direct and continue_direct:
|
|
5435
|
+
raise APError("--claim-direct and --continue-direct are mutually exclusive.")
|
|
5007
5436
|
plan = _resolve_execution_plan(
|
|
5008
5437
|
cfg,
|
|
5009
5438
|
repo,
|
|
@@ -5015,7 +5444,19 @@ def cmd_classify(args: argparse.Namespace) -> None:
|
|
|
5015
5444
|
intent="\n".join(part for part in intent_parts if part),
|
|
5016
5445
|
parallel_writers=int(getattr(args, "writers", 1) or 1),
|
|
5017
5446
|
requested_task_kind=_text(getattr(args, "task_kind", "")),
|
|
5447
|
+
continue_direct=continue_direct,
|
|
5448
|
+
direct_claim_id=_text(getattr(args, "direct_claim", "")),
|
|
5018
5449
|
)
|
|
5450
|
+
direct_claim: dict = {}
|
|
5451
|
+
if claim_direct:
|
|
5452
|
+
if plan["task_kind"] != "change" or plan["execution_mode"] != "direct":
|
|
5453
|
+
raise APError("--claim-direct requires a clean adaptive single-writer change plan.")
|
|
5454
|
+
direct_claim = _create_direct_claim(
|
|
5455
|
+
repo,
|
|
5456
|
+
cfg,
|
|
5457
|
+
list(plan.get("planned_files") or []),
|
|
5458
|
+
_actor_id(args, "claim_owner"),
|
|
5459
|
+
)
|
|
5019
5460
|
risk = {"micro": "P3", "standard": "P2", "high-risk": "P1"}[plan["profile"]]
|
|
5020
5461
|
commands: list[str] = []
|
|
5021
5462
|
if plan["needs_dd"]:
|
|
@@ -5024,6 +5465,15 @@ def cmd_classify(args: argparse.Namespace) -> None:
|
|
|
5024
5465
|
**plan,
|
|
5025
5466
|
"risk": risk,
|
|
5026
5467
|
"recommended_commands": commands,
|
|
5468
|
+
"direct_claim": (
|
|
5469
|
+
{
|
|
5470
|
+
"id": _text(direct_claim.get("claim_id")),
|
|
5471
|
+
"base_sha": _text(direct_claim.get("base_sha")),
|
|
5472
|
+
"owned_paths": list(direct_claim.get("owned_paths") or []),
|
|
5473
|
+
}
|
|
5474
|
+
if direct_claim
|
|
5475
|
+
else None
|
|
5476
|
+
),
|
|
5027
5477
|
}
|
|
5028
5478
|
if args.json:
|
|
5029
5479
|
print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
@@ -5038,6 +5488,10 @@ def cmd_classify(args: argparse.Namespace) -> None:
|
|
|
5038
5488
|
print(f"[classify] selected_scope={result['selected_scope']}")
|
|
5039
5489
|
print("[classify] categories=" + (", ".join(result["categories"]) or "(none)"))
|
|
5040
5490
|
print("[classify] agents=" + (", ".join(result["recommended_agents"]) or "(main agent only)"))
|
|
5491
|
+
print(
|
|
5492
|
+
"[classify] optional_agents="
|
|
5493
|
+
+ (", ".join(result["optional_agents"]) or "(none)")
|
|
5494
|
+
)
|
|
5041
5495
|
print(f"[classify] agent_strategy={result['agent_plan']['strategy']}")
|
|
5042
5496
|
print(
|
|
5043
5497
|
"[classify] required_mechanisms="
|
|
@@ -5051,6 +5505,8 @@ def cmd_classify(args: argparse.Namespace) -> None:
|
|
|
5051
5505
|
"[classify] forbidden="
|
|
5052
5506
|
+ (", ".join(result["mechanism_plan"]["forbidden"]) or "(none)")
|
|
5053
5507
|
)
|
|
5508
|
+
if direct_claim:
|
|
5509
|
+
print(f"[classify] direct_claim={direct_claim['claim_id']}")
|
|
5054
5510
|
for stage in result["agent_plan"]["stages"]:
|
|
5055
5511
|
print(
|
|
5056
5512
|
"[classify] agent_stage="
|
|
@@ -5064,6 +5520,39 @@ def cmd_classify(args: argparse.Namespace) -> None:
|
|
|
5064
5520
|
_record_evidence(repo, cfg, "classify", "pass", result)
|
|
5065
5521
|
|
|
5066
5522
|
|
|
5523
|
+
def cmd_agent_contract_check(args: argparse.Namespace) -> None:
|
|
5524
|
+
repo = Path(args.repo).resolve()
|
|
5525
|
+
raw = _text(getattr(args, "payload", ""))
|
|
5526
|
+
source = _text(getattr(args, "file", ""))
|
|
5527
|
+
if source:
|
|
5528
|
+
if source == "-":
|
|
5529
|
+
raw = sys.stdin.read(1048577)
|
|
5530
|
+
else:
|
|
5531
|
+
path = Path(source)
|
|
5532
|
+
if not path.is_absolute():
|
|
5533
|
+
path = repo / path
|
|
5534
|
+
try:
|
|
5535
|
+
if path.stat().st_size > 1048576:
|
|
5536
|
+
raise APError("Agent contract payload is limited to 1 MiB.")
|
|
5537
|
+
raw = path.read_text(encoding="utf-8")
|
|
5538
|
+
except OSError as exc:
|
|
5539
|
+
raise APError(f"Cannot read agent contract payload: {path}: {exc}") from exc
|
|
5540
|
+
if len(raw.encode("utf-8")) > 1048576:
|
|
5541
|
+
raise APError("Agent contract payload is limited to 1 MiB.")
|
|
5542
|
+
try:
|
|
5543
|
+
payload = json.loads(raw)
|
|
5544
|
+
except json.JSONDecodeError as exc:
|
|
5545
|
+
raise APError(f"Agent contract payload is not valid JSON: {exc}") from exc
|
|
5546
|
+
if not isinstance(payload, dict):
|
|
5547
|
+
raise APError("Agent contract payload must be a JSON object.")
|
|
5548
|
+
_validate_orchestration_contract(args.kind, payload)
|
|
5549
|
+
result = {"valid": True, "kind": args.kind}
|
|
5550
|
+
if args.json:
|
|
5551
|
+
print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
5552
|
+
else:
|
|
5553
|
+
print(f"[agent-contract-check] OK kind={args.kind}")
|
|
5554
|
+
|
|
5555
|
+
|
|
5067
5556
|
def cmd_run(args: argparse.Namespace) -> None:
|
|
5068
5557
|
"""
|
|
5069
5558
|
Run any configured gate command by name.
|
|
@@ -6744,10 +7233,13 @@ def cmd_task_start(args: argparse.Namespace) -> None:
|
|
|
6744
7233
|
"task-start creates exactly one writer lease and one worktree. Start each parallel "
|
|
6745
7234
|
"writer as its own task ID; use --writers only with classify for planning."
|
|
6746
7235
|
)
|
|
7236
|
+
continue_direct = bool(getattr(args, "continue_direct", False))
|
|
7237
|
+
direct_claim_id = _text(getattr(args, "direct_claim", ""))
|
|
6747
7238
|
explicit_lifecycle = bool(
|
|
6748
7239
|
getattr(args, "isolated", False)
|
|
6749
7240
|
or getattr(args, "review_required", False)
|
|
6750
7241
|
or getattr(args, "force_lifecycle", False)
|
|
7242
|
+
or continue_direct
|
|
6751
7243
|
)
|
|
6752
7244
|
preflight_plan = _resolve_execution_plan(
|
|
6753
7245
|
cfg,
|
|
@@ -6755,7 +7247,15 @@ def cmd_task_start(args: argparse.Namespace) -> None:
|
|
|
6755
7247
|
planned_paths=owned_paths,
|
|
6756
7248
|
parallel_writers=writer_count,
|
|
6757
7249
|
requested_task_kind="change",
|
|
7250
|
+
continue_direct=continue_direct,
|
|
7251
|
+
direct_claim_id=direct_claim_id,
|
|
6758
7252
|
)
|
|
7253
|
+
if continue_direct and preflight_plan["execution_mode"] != "direct":
|
|
7254
|
+
detail = ", ".join(preflight_plan["dirty_outside_plan"]) or "policy or active-writer conflict"
|
|
7255
|
+
raise APError(
|
|
7256
|
+
"Cannot continue the existing direct task because isolation is still required: "
|
|
7257
|
+
+ detail
|
|
7258
|
+
)
|
|
6759
7259
|
if not preflight_plan["mechanism_plan"]["lifecycle_required"] and not explicit_lifecycle:
|
|
6760
7260
|
raise APError(
|
|
6761
7261
|
"This clean serial task does not need a machine task lifecycle. Work directly on "
|
|
@@ -6779,6 +7279,16 @@ def cmd_task_start(args: argparse.Namespace) -> None:
|
|
|
6779
7279
|
_repo_lock(repo, "integration", timeout_s=timeout_s),
|
|
6780
7280
|
_repo_lock(repo, "task-registry", timeout_s=timeout_s),
|
|
6781
7281
|
):
|
|
7282
|
+
for claim in _active_direct_claims(repo):
|
|
7283
|
+
if _text(claim.get("claim_id")) == direct_claim_id:
|
|
7284
|
+
continue
|
|
7285
|
+
claim_paths = list(claim.get("owned_paths") or [])
|
|
7286
|
+
if _owned_paths_overlap(owned_paths, claim_paths):
|
|
7287
|
+
raise APError(
|
|
7288
|
+
"Owned paths overlap an active direct claim held by "
|
|
7289
|
+
f"{_text(claim.get('owner')) or '(unknown)'}: "
|
|
7290
|
+
+ ", ".join(claim_paths)
|
|
7291
|
+
)
|
|
6782
7292
|
if _read_json_object(_task_registry_path(repo, task_id)):
|
|
6783
7293
|
raise APError(f"Task is already registered: {task_id}")
|
|
6784
7294
|
|
|
@@ -6827,6 +7337,8 @@ def cmd_task_start(args: argparse.Namespace) -> None:
|
|
|
6827
7337
|
planned_paths=owned_paths,
|
|
6828
7338
|
parallel_writers=writer_count,
|
|
6829
7339
|
requested_task_kind="change",
|
|
7340
|
+
continue_direct=continue_direct,
|
|
7341
|
+
direct_claim_id=direct_claim_id,
|
|
6830
7342
|
)
|
|
6831
7343
|
if not plan["mechanism_plan"]["lifecycle_required"] and not explicit_lifecycle:
|
|
6832
7344
|
raise APError(
|
|
@@ -6845,15 +7357,25 @@ def cmd_task_start(args: argparse.Namespace) -> None:
|
|
|
6845
7357
|
)
|
|
6846
7358
|
) if registry_dir.exists() else False
|
|
6847
7359
|
current_branch = _current_branch(repo)
|
|
7360
|
+
task_paths = _task_commit_paths(repo)
|
|
7361
|
+
direct_changes_owned = bool(
|
|
7362
|
+
continue_direct
|
|
7363
|
+
and all(_path_is_owned(path, owned_paths) for path in task_paths)
|
|
7364
|
+
)
|
|
6848
7365
|
direct = bool(
|
|
6849
7366
|
configured_isolation == "adaptive"
|
|
6850
7367
|
and not bool(getattr(args, "isolated", False))
|
|
6851
7368
|
and writer_count == 1
|
|
6852
7369
|
and not other_active
|
|
6853
|
-
and not
|
|
7370
|
+
and (not task_paths or direct_changes_owned)
|
|
6854
7371
|
and current_branch
|
|
6855
7372
|
and current_branch == target_branch
|
|
6856
7373
|
)
|
|
7374
|
+
if continue_direct and not direct:
|
|
7375
|
+
raise APError(
|
|
7376
|
+
"Cannot register continued direct work on this checkout; verify target branch, "
|
|
7377
|
+
"owned paths, active writers, and concurrency.isolation"
|
|
7378
|
+
)
|
|
6857
7379
|
if direct:
|
|
6858
7380
|
direct_base = _resolve_commit(repo, "HEAD")
|
|
6859
7381
|
manifest = {
|
|
@@ -6898,6 +7420,7 @@ def cmd_task_start(args: argparse.Namespace) -> None:
|
|
|
6898
7420
|
"common_submodule_config": {},
|
|
6899
7421
|
}
|
|
6900
7422
|
_save_task_manifest(repo, manifest)
|
|
7423
|
+
_consume_direct_claim(repo, direct_claim_id)
|
|
6901
7424
|
print(f"[task-start] task={task_id}")
|
|
6902
7425
|
print("[task-start] execution_mode=direct")
|
|
6903
7426
|
print(f"[task-start] branch={current_branch}")
|
|
@@ -7114,6 +7637,14 @@ def cmd_task_review(args: argparse.Namespace) -> None:
|
|
|
7114
7637
|
reviewer = _text(getattr(args, "reviewer", "")) or _text(os.environ.get("CODEX_THREAD_ID"))
|
|
7115
7638
|
if not reviewer:
|
|
7116
7639
|
raise APError("task-review requires --reviewer or CODEX_THREAD_ID.")
|
|
7640
|
+
if bool(manifest.get("review_required")):
|
|
7641
|
+
if not _text(getattr(args, "reviewer", "")):
|
|
7642
|
+
raise APError("Independent review requires an explicit --reviewer identity.")
|
|
7643
|
+
if reviewer == _text(manifest.get("owner")):
|
|
7644
|
+
raise APError("Independent reviewer identity must differ from the task lifecycle owner.")
|
|
7645
|
+
writer = _text((manifest.get("writer_lease") or {}).get("holder"))
|
|
7646
|
+
if reviewer == writer:
|
|
7647
|
+
raise APError("Independent reviewer identity must differ from the current writer lease holder.")
|
|
7117
7648
|
manifest["review"] = {
|
|
7118
7649
|
"verdict": args.verdict,
|
|
7119
7650
|
"diff_base": _text(manifest.get("base_sha")),
|
|
@@ -8068,11 +8599,23 @@ def main(argv: Optional[List[str]] = None) -> int:
|
|
|
8068
8599
|
s.add_argument("--planned-path", action="append")
|
|
8069
8600
|
s.add_argument("--intent")
|
|
8070
8601
|
s.add_argument("--intent-file")
|
|
8071
|
-
s.add_argument("--task-kind", choices=sorted(
|
|
8602
|
+
s.add_argument("--task-kind", choices=sorted(_REQUESTED_TASK_KINDS), default="auto")
|
|
8603
|
+
s.add_argument("--claim-direct", action="store_true")
|
|
8604
|
+
s.add_argument("--claim-owner")
|
|
8605
|
+
s.add_argument("--continue-direct", action="store_true")
|
|
8606
|
+
s.add_argument("--direct-claim")
|
|
8072
8607
|
s.add_argument("--writers", type=int, default=1)
|
|
8073
8608
|
s.add_argument("--json", action="store_true")
|
|
8074
8609
|
s.set_defaults(func=cmd_classify)
|
|
8075
8610
|
|
|
8611
|
+
s = sp.add_parser("agent-contract-check")
|
|
8612
|
+
s.add_argument("--kind", choices=["assignment", "result", "agentPlan", "classify"], required=True)
|
|
8613
|
+
source = s.add_mutually_exclusive_group(required=True)
|
|
8614
|
+
source.add_argument("--file")
|
|
8615
|
+
source.add_argument("--payload")
|
|
8616
|
+
s.add_argument("--json", action="store_true")
|
|
8617
|
+
s.set_defaults(func=cmd_agent_contract_check)
|
|
8618
|
+
|
|
8076
8619
|
s = sp.add_parser("validation-map-check")
|
|
8077
8620
|
s.add_argument("--base")
|
|
8078
8621
|
s.add_argument("--path", action="append")
|
|
@@ -8177,6 +8720,8 @@ def main(argv: Optional[List[str]] = None) -> int:
|
|
|
8177
8720
|
s.add_argument("--writers", type=int, default=1)
|
|
8178
8721
|
s.add_argument("--isolated", action="store_true")
|
|
8179
8722
|
s.add_argument("--review-required", action="store_true")
|
|
8723
|
+
s.add_argument("--continue-direct", action="store_true")
|
|
8724
|
+
s.add_argument("--direct-claim")
|
|
8180
8725
|
s.add_argument(
|
|
8181
8726
|
"--force-lifecycle",
|
|
8182
8727
|
action="store_true",
|