@elvis1513/auto-coding-skill 4.1.9 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -5
- package/cli/assets/managed-install.json +1 -1
- package/cli/assets/skill/SKILL.md +11 -3
- package/cli/assets/skill/data/policies/workflow-migrations-v1.json +2 -2
- package/cli/assets/skill/data/templates/ENGINEERING.md +2 -20
- package/cli/assets/skill/data/templates/bridges/AGENTS.md +9 -1
- package/cli/assets/skill/scripts/ap.py +567 -54
- package/cli/tests/ap_concurrency_test.py +311 -6
- package/cli/tests/ap_profiles_test.py +3 -3
- package/cli/tests/index.test.js +17 -17
- package/package.json +1 -1
|
@@ -44,10 +44,12 @@ _AGENT_CONTRACT_VERSION = 1
|
|
|
44
44
|
_AGENT_CONTRACT_SCHEMA = "data/contracts/orchestration-v1.schema.json"
|
|
45
45
|
_RECOMMENDED_FINAL_COMMAND_SECONDS = 120.0
|
|
46
46
|
_RECOMMENDED_FINAL_TOTAL_SECONDS = 180.0
|
|
47
|
+
_FINAL_GATE_CACHE_SCHEMA = 1
|
|
48
|
+
_FINAL_GATE_CACHE_ALGORITHM = "final-gate-v1"
|
|
47
49
|
_WORKFLOW_MIGRATION_POLICY = Path("data/policies/workflow-migrations-v1.json")
|
|
48
50
|
_FALLBACK_WORKFLOW_MIGRATION_POLICY = {
|
|
49
51
|
"schema_version": 1,
|
|
50
|
-
"managed_versions": {"agents": "4.
|
|
52
|
+
"managed_versions": {"agents": "4.2.0", "engineering": "4.2.0"},
|
|
51
53
|
"known_official_engineering_body_sha256": [
|
|
52
54
|
"d1306cc626e8baf8c83c953b760fd771066de2bf125168eca3a7b7d6ff2b87a2",
|
|
53
55
|
"305931c6edef770033a4f1970b00e5fb1c1728351856a173dbfa497daf563021",
|
|
@@ -960,8 +962,8 @@ def _migrate_fast_development_defaults(cfg: dict, repo: Path) -> list[str]:
|
|
|
960
962
|
if _text(workflow_cfg.get("completion")).lower() != "push":
|
|
961
963
|
workflow_cfg["completion"] = "push"
|
|
962
964
|
changed.append("workflow.completion")
|
|
963
|
-
if _text(workflow_cfg.get("skill_version")) != "4.
|
|
964
|
-
workflow_cfg["skill_version"] = "4.
|
|
965
|
+
if _text(workflow_cfg.get("skill_version")) != "4.2.0":
|
|
966
|
+
workflow_cfg["skill_version"] = "4.2.0"
|
|
965
967
|
changed.append("workflow.skill_version")
|
|
966
968
|
|
|
967
969
|
commands_cfg = cfg.setdefault("commands", {})
|
|
@@ -1274,16 +1276,16 @@ def cmd_upgrade(args: argparse.Namespace) -> None:
|
|
|
1274
1276
|
if current_agents:
|
|
1275
1277
|
archive_dir = repo / "docs" / "archive" / "workflow"
|
|
1276
1278
|
archive_header = (
|
|
1277
|
-
"# Archived AGENTS.md before auto-coding-skill 4.
|
|
1279
|
+
"# Archived AGENTS.md before auto-coding-skill 4.2.0\n\n"
|
|
1278
1280
|
"This file is historical and non-authoritative. The root AGENTS.md is fully managed.\n"
|
|
1279
1281
|
"Move any still-current project facts into docs/ENGINEERING.md or docs/project/,\n"
|
|
1280
1282
|
"without copying workflow rules back into the root AGENTS.md.\n\n---\n\n"
|
|
1281
1283
|
)
|
|
1282
1284
|
archive_content = archive_header + current_agents
|
|
1283
|
-
archive = archive_dir / "AGENTS.pre-4.
|
|
1285
|
+
archive = archive_dir / "AGENTS.pre-4.2.0.md"
|
|
1284
1286
|
if archive.exists() and archive.read_text(encoding="utf-8") != archive_content:
|
|
1285
1287
|
digest = hashlib.sha256(current_agents.encode("utf-8")).hexdigest()[:12]
|
|
1286
|
-
archive = archive_dir / f"AGENTS.pre-4.
|
|
1288
|
+
archive = archive_dir / f"AGENTS.pre-4.2.0-{digest}.md"
|
|
1287
1289
|
if not archive.exists():
|
|
1288
1290
|
add_action("policy", archive, "archive", "historical and non-authoritative")
|
|
1289
1291
|
if write:
|
|
@@ -2296,6 +2298,19 @@ def _validate_task_manifest(repo: Path, manifest: dict, expected_task_id: str =
|
|
|
2296
2298
|
review_required = manifest.get("review_required", schema < 3)
|
|
2297
2299
|
if not isinstance(review_required, bool):
|
|
2298
2300
|
raise APError(f"Task {task_id} has an invalid review_required flag.")
|
|
2301
|
+
try:
|
|
2302
|
+
scope_revision = int(manifest.get("scope_revision") or 1)
|
|
2303
|
+
except (TypeError, ValueError) as exc:
|
|
2304
|
+
raise APError(f"Task {task_id} has an invalid scope_revision.") from exc
|
|
2305
|
+
if scope_revision < 1:
|
|
2306
|
+
raise APError(f"Task {task_id} has an invalid scope_revision.")
|
|
2307
|
+
effective_profile = _text(manifest.get("effective_profile"))
|
|
2308
|
+
if effective_profile and effective_profile not in (_WORKFLOW_PROFILES - {"auto"}):
|
|
2309
|
+
raise APError(f"Task {task_id} has an invalid effective_profile.")
|
|
2310
|
+
if "design_required" in manifest and not isinstance(manifest.get("design_required"), bool):
|
|
2311
|
+
raise APError(f"Task {task_id} has an invalid design_required flag.")
|
|
2312
|
+
if "scope_history" in manifest and not isinstance(manifest.get("scope_history"), list):
|
|
2313
|
+
raise APError(f"Task {task_id} has an invalid scope_history.")
|
|
2299
2314
|
return manifest
|
|
2300
2315
|
|
|
2301
2316
|
|
|
@@ -2309,7 +2324,7 @@ def _load_task_manifest(repo: Path, task_id: str) -> dict:
|
|
|
2309
2324
|
return _validate_task_manifest(repo, manifest, task_id)
|
|
2310
2325
|
|
|
2311
2326
|
|
|
2312
|
-
def _save_task_manifest(repo: Path, manifest: dict) -> None:
|
|
2327
|
+
def _save_task_manifest(repo: Path, manifest: dict, *, strict_worktree: bool = False) -> None:
|
|
2313
2328
|
_validate_task_manifest(repo, manifest)
|
|
2314
2329
|
task_id = _validate_task_id(_text(manifest.get("task_id")))
|
|
2315
2330
|
manifest["updated_at"] = _now_iso()
|
|
@@ -2321,11 +2336,15 @@ def _save_task_manifest(repo: Path, manifest: dict) -> None:
|
|
|
2321
2336
|
try:
|
|
2322
2337
|
_write_json_object(_worktree_manifest_path(worktree), manifest)
|
|
2323
2338
|
except APError:
|
|
2324
|
-
|
|
2339
|
+
if strict_worktree:
|
|
2340
|
+
raise
|
|
2325
2341
|
|
|
2326
2342
|
|
|
2327
2343
|
def _delete_task_manifest(repo: Path, manifest: dict) -> None:
|
|
2328
2344
|
task_id = _validate_task_id(_text(manifest.get("task_id")))
|
|
2345
|
+
worktree_value = _text(manifest.get("worktree_path"))
|
|
2346
|
+
if worktree_value and Path(worktree_value).exists():
|
|
2347
|
+
_clear_final_gate_receipt(Path(worktree_value))
|
|
2329
2348
|
_task_registry_path(repo, task_id).unlink(missing_ok=True)
|
|
2330
2349
|
|
|
2331
2350
|
|
|
@@ -2373,13 +2392,13 @@ def _working_tree_paths(repo: Path) -> list[str]:
|
|
|
2373
2392
|
paths.update(
|
|
2374
2393
|
_git_z_paths(
|
|
2375
2394
|
repo,
|
|
2376
|
-
["git", "diff", "--name-only", "-z", "--diff-filter=ACDMRTUXB"],
|
|
2395
|
+
["git", "diff", "--no-renames", "--name-only", "-z", "--diff-filter=ACDMRTUXB"],
|
|
2377
2396
|
)
|
|
2378
2397
|
)
|
|
2379
2398
|
paths.update(
|
|
2380
2399
|
_git_z_paths(
|
|
2381
2400
|
repo,
|
|
2382
|
-
["git", "diff", "--cached", "--name-only", "-z", "--diff-filter=ACDMRTUXB"],
|
|
2401
|
+
["git", "diff", "--cached", "--no-renames", "--name-only", "-z", "--diff-filter=ACDMRTUXB"],
|
|
2383
2402
|
)
|
|
2384
2403
|
)
|
|
2385
2404
|
paths.update(
|
|
@@ -2444,13 +2463,13 @@ def _task_content_fingerprint(repo: Path, cfg: dict, manifest: Optional[dict]) -
|
|
|
2444
2463
|
if not batch:
|
|
2445
2464
|
continue
|
|
2446
2465
|
cached = run(
|
|
2447
|
-
["git", "diff", "--cached", "--binary", "--no-ext-diff", "--", *batch],
|
|
2466
|
+
["git", "diff", "--cached", "--no-renames", "--binary", "--no-ext-diff", "--", *batch],
|
|
2448
2467
|
cwd=repo,
|
|
2449
2468
|
check=False,
|
|
2450
2469
|
)
|
|
2451
2470
|
digest.update(cached.stdout.encode("utf-8", errors="surrogateescape"))
|
|
2452
2471
|
unstaged = run(
|
|
2453
|
-
["git", "diff", "--binary", "--no-ext-diff", "--", *batch],
|
|
2472
|
+
["git", "diff", "--no-renames", "--binary", "--no-ext-diff", "--", *batch],
|
|
2454
2473
|
cwd=repo,
|
|
2455
2474
|
check=False,
|
|
2456
2475
|
)
|
|
@@ -2464,11 +2483,140 @@ def _task_content_fingerprint(repo: Path, cfg: dict, manifest: Optional[dict]) -
|
|
|
2464
2483
|
return digest.hexdigest()
|
|
2465
2484
|
|
|
2466
2485
|
|
|
2467
|
-
def
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2486
|
+
def _final_gate_receipt_path(repo: Path) -> Path:
|
|
2487
|
+
return _git_dir(repo) / "auto-coding-skill-final-gate.json"
|
|
2488
|
+
|
|
2489
|
+
|
|
2490
|
+
def _clear_final_gate_receipt(repo: Path) -> None:
|
|
2491
|
+
try:
|
|
2492
|
+
_final_gate_receipt_path(repo).unlink(missing_ok=True)
|
|
2493
|
+
except APError:
|
|
2494
|
+
return
|
|
2495
|
+
|
|
2496
|
+
|
|
2497
|
+
def _final_gate_identity(
|
|
2498
|
+
repo: Path,
|
|
2499
|
+
cfg: dict,
|
|
2500
|
+
manifest: dict,
|
|
2501
|
+
plan: dict,
|
|
2502
|
+
base_ref: str,
|
|
2503
|
+
) -> tuple[dict, str]:
|
|
2504
|
+
paths = list(plan.get("changed_files") or [])
|
|
2505
|
+
validation_plan = _validation_plan(cfg, paths)
|
|
2506
|
+
_validate_validation_plan(cfg, validation_plan)
|
|
2507
|
+
command_hashes = {
|
|
2508
|
+
name: hashlib.sha256(_configured_command(cfg, name).encode("utf-8")).hexdigest()
|
|
2509
|
+
for name in validation_plan["commands"]
|
|
2510
|
+
}
|
|
2511
|
+
plan_payload = {
|
|
2512
|
+
"scope": plan.get("selected_scope"),
|
|
2513
|
+
"profile": plan.get("profile"),
|
|
2514
|
+
"effective_mode": plan.get("effective_mode"),
|
|
2515
|
+
"paths": validation_plan["paths"],
|
|
2516
|
+
"commands": validation_plan["commands"],
|
|
2517
|
+
"command_hashes": command_hashes,
|
|
2518
|
+
"command_timeouts": validation_plan["command_timeouts"],
|
|
2519
|
+
"matched_routes": validation_plan["matched_routes"],
|
|
2520
|
+
"coverage": validation_plan["coverage"],
|
|
2521
|
+
"unmapped": validation_plan["unmapped"],
|
|
2522
|
+
"docs_only": validation_plan["docs_only"],
|
|
2523
|
+
"compatibility_fallback": validation_plan["compatibility_fallback"],
|
|
2524
|
+
"on_unmapped": _text(_validation_cfg(cfg).get("on_unmapped")).lower() or "error",
|
|
2525
|
+
"budget": _final_gate_budget(cfg),
|
|
2526
|
+
"diff_check": "working-index-base-v1",
|
|
2527
|
+
}
|
|
2528
|
+
plan_sha256 = hashlib.sha256(
|
|
2529
|
+
json.dumps(plan_payload, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode("utf-8")
|
|
2530
|
+
).hexdigest()
|
|
2531
|
+
resolved_base = _resolve_commit(repo, base_ref or _text(manifest.get("base_sha")) or "HEAD")
|
|
2532
|
+
identity = {
|
|
2533
|
+
"algorithm": _FINAL_GATE_CACHE_ALGORITHM,
|
|
2534
|
+
"skill_version": _text((cfg.get("workflow") or {}).get("skill_version")),
|
|
2535
|
+
"task_id": _text(manifest.get("task_id")),
|
|
2536
|
+
"task_uuid": _text(manifest.get("task_uuid")),
|
|
2537
|
+
"worktree_path": str(repo.resolve()),
|
|
2538
|
+
"branch": _current_branch(repo),
|
|
2539
|
+
"base_sha": resolved_base,
|
|
2540
|
+
"head_sha": _resolve_commit(repo, "HEAD"),
|
|
2541
|
+
"scope_revision": int(manifest.get("scope_revision") or 1),
|
|
2542
|
+
"owned_paths": sorted(manifest.get("owned_paths") or []),
|
|
2543
|
+
"writer_generation": int((manifest.get("writer_lease") or {}).get("generation") or 0),
|
|
2544
|
+
"plan_sha256": plan_sha256,
|
|
2545
|
+
}
|
|
2546
|
+
return identity, _task_content_fingerprint(repo, cfg, manifest)
|
|
2547
|
+
|
|
2548
|
+
|
|
2549
|
+
def _record_final_gate_receipt(
|
|
2550
|
+
repo: Path,
|
|
2551
|
+
cfg: dict,
|
|
2552
|
+
manifest: dict,
|
|
2553
|
+
plan: dict,
|
|
2554
|
+
base_ref: str,
|
|
2555
|
+
executed: list[str],
|
|
2556
|
+
) -> None:
|
|
2557
|
+
identity, fingerprint = _final_gate_identity(repo, cfg, manifest, plan, base_ref)
|
|
2558
|
+
_write_json_object(
|
|
2559
|
+
_final_gate_receipt_path(repo),
|
|
2560
|
+
{
|
|
2561
|
+
"schema": _FINAL_GATE_CACHE_SCHEMA,
|
|
2562
|
+
"kind": "final_changed_scope_gate",
|
|
2563
|
+
"status": "pass",
|
|
2564
|
+
"identity": identity,
|
|
2565
|
+
"content_fingerprints": [fingerprint],
|
|
2566
|
+
"executed": list(executed),
|
|
2567
|
+
"passed_at": _now_iso(),
|
|
2568
|
+
},
|
|
2569
|
+
)
|
|
2570
|
+
|
|
2571
|
+
|
|
2572
|
+
def _reuse_final_gate_receipt(
|
|
2573
|
+
repo: Path,
|
|
2574
|
+
cfg: dict,
|
|
2575
|
+
manifest: dict,
|
|
2576
|
+
plan: dict,
|
|
2577
|
+
base_ref: str,
|
|
2578
|
+
) -> Optional[dict]:
|
|
2579
|
+
receipt = _read_json_object(_final_gate_receipt_path(repo)) or {}
|
|
2580
|
+
if (
|
|
2581
|
+
int(receipt.get("schema") or 0) != _FINAL_GATE_CACHE_SCHEMA
|
|
2582
|
+
or _text(receipt.get("kind")) != "final_changed_scope_gate"
|
|
2583
|
+
or _text(receipt.get("status")) != "pass"
|
|
2584
|
+
):
|
|
2585
|
+
return None
|
|
2586
|
+
identity, fingerprint = _final_gate_identity(repo, cfg, manifest, plan, base_ref)
|
|
2587
|
+
if receipt.get("identity") != identity:
|
|
2588
|
+
return None
|
|
2589
|
+
allowed = receipt.get("content_fingerprints") or []
|
|
2590
|
+
if not isinstance(allowed, list) or fingerprint not in allowed:
|
|
2591
|
+
return None
|
|
2592
|
+
return receipt
|
|
2593
|
+
|
|
2594
|
+
|
|
2595
|
+
def _extend_final_gate_receipt(
|
|
2596
|
+
repo: Path,
|
|
2597
|
+
cfg: dict,
|
|
2598
|
+
manifest: dict,
|
|
2599
|
+
plan: dict,
|
|
2600
|
+
base_ref: str,
|
|
2601
|
+
) -> None:
|
|
2602
|
+
receipt = _read_json_object(_final_gate_receipt_path(repo)) or {}
|
|
2603
|
+
identity, fingerprint = _final_gate_identity(repo, cfg, manifest, plan, base_ref)
|
|
2604
|
+
if (
|
|
2605
|
+
int(receipt.get("schema") or 0) != _FINAL_GATE_CACHE_SCHEMA
|
|
2606
|
+
or _text(receipt.get("kind")) != "final_changed_scope_gate"
|
|
2607
|
+
or _text(receipt.get("status")) != "pass"
|
|
2608
|
+
or receipt.get("identity") != identity
|
|
2609
|
+
):
|
|
2610
|
+
raise APError("The successful final-gate receipt no longer matches the staged task state.")
|
|
2611
|
+
allowed = list(receipt.get("content_fingerprints") or [])
|
|
2612
|
+
if fingerprint not in allowed:
|
|
2613
|
+
allowed.append(fingerprint)
|
|
2614
|
+
receipt["content_fingerprints"] = allowed
|
|
2615
|
+
_write_json_object(_final_gate_receipt_path(repo), receipt)
|
|
2616
|
+
|
|
2617
|
+
|
|
2618
|
+
def _staged_paths(repo: Path) -> list[str]:
|
|
2619
|
+
return sorted(
|
|
2472
2620
|
set(
|
|
2473
2621
|
_checked_git_z_paths(
|
|
2474
2622
|
repo,
|
|
@@ -2476,6 +2624,7 @@ def _stage_exact_paths(repo: Path, paths: list[str]) -> list[str]:
|
|
|
2476
2624
|
"git",
|
|
2477
2625
|
"diff",
|
|
2478
2626
|
"--cached",
|
|
2627
|
+
"--no-renames",
|
|
2479
2628
|
"--name-only",
|
|
2480
2629
|
"-z",
|
|
2481
2630
|
"--diff-filter=ACDMRTUXB",
|
|
@@ -2484,6 +2633,36 @@ def _stage_exact_paths(repo: Path, paths: list[str]) -> list[str]:
|
|
|
2484
2633
|
)
|
|
2485
2634
|
)
|
|
2486
2635
|
)
|
|
2636
|
+
|
|
2637
|
+
|
|
2638
|
+
def _exact_stage_plan(repo: Path, paths: list[str], *, dry_run: bool) -> tuple[list[str], list[str]]:
|
|
2639
|
+
expected = sorted(set(path for path in paths if path))
|
|
2640
|
+
expected_set = set(expected)
|
|
2641
|
+
staged = _staged_paths(repo)
|
|
2642
|
+
pending = _unstaged_task_paths(repo)
|
|
2643
|
+
unexpected = sorted((set(staged) | set(pending)) - expected_set)
|
|
2644
|
+
if unexpected:
|
|
2645
|
+
raise APError(
|
|
2646
|
+
"Refusing to commit paths outside the current task:\n- " + "\n- ".join(unexpected)
|
|
2647
|
+
)
|
|
2648
|
+
if dry_run:
|
|
2649
|
+
for start in range(0, len(pending), 100):
|
|
2650
|
+
run(
|
|
2651
|
+
["git", "add", "--dry-run", "-A", "--", *pending[start : start + 100]],
|
|
2652
|
+
cwd=repo,
|
|
2653
|
+
)
|
|
2654
|
+
return expected, pending
|
|
2655
|
+
|
|
2656
|
+
|
|
2657
|
+
def _preflight_exact_paths(repo: Path, paths: list[str]) -> None:
|
|
2658
|
+
_exact_stage_plan(repo, paths, dry_run=True)
|
|
2659
|
+
|
|
2660
|
+
|
|
2661
|
+
def _stage_exact_paths(repo: Path, paths: list[str]) -> list[str]:
|
|
2662
|
+
expected, pending = _exact_stage_plan(repo, paths, dry_run=False)
|
|
2663
|
+
for start in range(0, len(pending), 100):
|
|
2664
|
+
run(["git", "add", "-A", "--", *pending[start : start + 100]], cwd=repo)
|
|
2665
|
+
staged = _staged_paths(repo)
|
|
2487
2666
|
unexpected = sorted(set(staged) - set(expected))
|
|
2488
2667
|
if unexpected:
|
|
2489
2668
|
raise APError(
|
|
@@ -2569,7 +2748,16 @@ def _task_changed_paths_from_base(repo: Path, base_sha: str) -> list[str]:
|
|
|
2569
2748
|
paths = set(
|
|
2570
2749
|
_checked_git_z_paths(
|
|
2571
2750
|
repo,
|
|
2572
|
-
[
|
|
2751
|
+
[
|
|
2752
|
+
"git",
|
|
2753
|
+
"diff",
|
|
2754
|
+
"--no-renames",
|
|
2755
|
+
"--name-only",
|
|
2756
|
+
"-z",
|
|
2757
|
+
"--diff-filter=ACDMRTUXB",
|
|
2758
|
+
base_sha,
|
|
2759
|
+
"--",
|
|
2760
|
+
],
|
|
2573
2761
|
"task diff paths",
|
|
2574
2762
|
)
|
|
2575
2763
|
)
|
|
@@ -2593,6 +2781,20 @@ def _task_unowned_paths(repo: Path, cfg: dict, manifest: dict) -> list[str]:
|
|
|
2593
2781
|
]
|
|
2594
2782
|
|
|
2595
2783
|
|
|
2784
|
+
def _task_staging_paths(repo: Path, cfg: dict, manifest: dict) -> list[str]:
|
|
2785
|
+
paths = _task_commit_paths(repo)
|
|
2786
|
+
owned = [_normalize_owned_path(item) for item in manifest.get("owned_paths") or []]
|
|
2787
|
+
managed = set(_task_managed_paths(cfg, manifest))
|
|
2788
|
+
unowned = [
|
|
2789
|
+
path
|
|
2790
|
+
for path in paths
|
|
2791
|
+
if path not in managed and not _path_is_owned(path, owned)
|
|
2792
|
+
]
|
|
2793
|
+
if unowned:
|
|
2794
|
+
raise APError("Changes outside task owned_paths:\n- " + "\n- ".join(unowned))
|
|
2795
|
+
return paths
|
|
2796
|
+
|
|
2797
|
+
|
|
2596
2798
|
def _task_review_fingerprint(repo: Path, manifest: dict, cfg: Optional[dict] = None) -> str:
|
|
2597
2799
|
base_sha = _text(manifest.get("base_sha"))
|
|
2598
2800
|
owned = [_normalize_owned_path(item) for item in manifest.get("owned_paths") or []]
|
|
@@ -2603,7 +2805,14 @@ def _task_review_fingerprint(repo: Path, manifest: dict, cfg: Optional[dict] = N
|
|
|
2603
2805
|
if path not in managed and _path_is_owned(path, owned)
|
|
2604
2806
|
]
|
|
2605
2807
|
digest = hashlib.sha256()
|
|
2606
|
-
digest.update(
|
|
2808
|
+
digest.update(
|
|
2809
|
+
(
|
|
2810
|
+
f"contract:{_AGENT_CONTRACT_VERSION}\nbase:{base_sha}\n"
|
|
2811
|
+
f"scope_revision:{int(manifest.get('scope_revision') or 1)}\n"
|
|
2812
|
+
).encode("utf-8")
|
|
2813
|
+
)
|
|
2814
|
+
for owned_path in owned:
|
|
2815
|
+
digest.update(f"owned:{owned_path}\0".encode("utf-8", errors="surrogateescape"))
|
|
2607
2816
|
for rel in paths:
|
|
2608
2817
|
digest.update(f"path:{rel}\0".encode("utf-8", errors="surrogateescape"))
|
|
2609
2818
|
path = repo / rel
|
|
@@ -2691,11 +2900,50 @@ def _require_approved_review(repo: Path, cfg: dict, manifest: dict) -> str:
|
|
|
2691
2900
|
return fingerprint
|
|
2692
2901
|
|
|
2693
2902
|
|
|
2903
|
+
def _reconcile_task_risk(repo: Path, cfg: dict, manifest: dict) -> None:
|
|
2904
|
+
changed_paths = _task_changed_paths_from_base(repo, _text(manifest.get("base_sha")))
|
|
2905
|
+
plan = _resolve_execution_plan(
|
|
2906
|
+
cfg,
|
|
2907
|
+
repo,
|
|
2908
|
+
changed_paths=changed_paths,
|
|
2909
|
+
planned_paths=list(manifest.get("owned_paths") or []),
|
|
2910
|
+
requested_task_kind="change",
|
|
2911
|
+
)
|
|
2912
|
+
old_profile = _text(manifest.get("effective_profile")) or (
|
|
2913
|
+
"high-risk" if bool(manifest.get("review_required")) else "standard"
|
|
2914
|
+
)
|
|
2915
|
+
planned_profile = _text(plan.get("profile")) or "standard"
|
|
2916
|
+
effective_profile = (
|
|
2917
|
+
planned_profile
|
|
2918
|
+
if _PROFILE_RANK[planned_profile] > _PROFILE_RANK[old_profile]
|
|
2919
|
+
else old_profile
|
|
2920
|
+
)
|
|
2921
|
+
review_required = bool(manifest.get("review_required") or plan.get("review_required"))
|
|
2922
|
+
design_required = bool(manifest.get("design_required") or plan.get("design_required"))
|
|
2923
|
+
escalated = (
|
|
2924
|
+
effective_profile != old_profile
|
|
2925
|
+
or review_required != bool(manifest.get("review_required"))
|
|
2926
|
+
or design_required != bool(manifest.get("design_required"))
|
|
2927
|
+
)
|
|
2928
|
+
if not escalated:
|
|
2929
|
+
return
|
|
2930
|
+
manifest["effective_profile"] = effective_profile
|
|
2931
|
+
manifest["review_required"] = review_required
|
|
2932
|
+
manifest["design_required"] = design_required
|
|
2933
|
+
_invalidate_task_review(manifest, "actual changed paths raised task risk; review again")
|
|
2934
|
+
_clear_final_gate_receipt(repo)
|
|
2935
|
+
_save_task_manifest(repo, manifest)
|
|
2936
|
+
raise APError(
|
|
2937
|
+
"Actual changed paths raised task risk. Complete any necessary design/review and retry "
|
|
2938
|
+
f"commit-push: profile={effective_profile}, review_required={str(review_required).lower()}."
|
|
2939
|
+
)
|
|
2940
|
+
|
|
2941
|
+
|
|
2694
2942
|
def _unstaged_task_paths(repo: Path) -> list[str]:
|
|
2695
2943
|
paths = set(
|
|
2696
2944
|
_checked_git_z_paths(
|
|
2697
2945
|
repo,
|
|
2698
|
-
["git", "diff", "--name-only", "-z", "--diff-filter=ACDMRTUXB"],
|
|
2946
|
+
["git", "diff", "--no-renames", "--name-only", "-z", "--diff-filter=ACDMRTUXB"],
|
|
2699
2947
|
"unstaged task paths",
|
|
2700
2948
|
)
|
|
2701
2949
|
)
|
|
@@ -2732,7 +2980,14 @@ def _require_task_context(repo: Path, cfg: dict, task_id: str) -> dict:
|
|
|
2732
2980
|
registered = _read_json_object(_task_registry_path(repo, expected_task))
|
|
2733
2981
|
if not registered:
|
|
2734
2982
|
raise APError(f"Task registry entry is missing for {expected_task}; refusing to recreate it implicitly.")
|
|
2735
|
-
for field in (
|
|
2983
|
+
for field in (
|
|
2984
|
+
"task_id",
|
|
2985
|
+
"task_uuid",
|
|
2986
|
+
"task_branch",
|
|
2987
|
+
"worktree_path",
|
|
2988
|
+
"base_sha",
|
|
2989
|
+
"scope_revision",
|
|
2990
|
+
):
|
|
2736
2991
|
if _text(registered.get(field)) != _text(manifest.get(field)):
|
|
2737
2992
|
raise APError(f"Task manifest/registry mismatch for {expected_task}: {field}")
|
|
2738
2993
|
manifest = registered
|
|
@@ -3044,7 +3299,7 @@ def _run_configured_command_list(
|
|
|
3044
3299
|
remaining = deadline - time.monotonic()
|
|
3045
3300
|
if remaining <= 0:
|
|
3046
3301
|
raise APError(
|
|
3047
|
-
"Final changed-scope gate exceeded its total time budget before "
|
|
3302
|
+
"Final changed-scope gate timed out: exceeded its total time budget before "
|
|
3048
3303
|
f"commands.{name}; narrow validation.routes"
|
|
3049
3304
|
)
|
|
3050
3305
|
timeout_s = min(timeout_s, remaining) if timeout_s is not None else remaining
|
|
@@ -3108,9 +3363,9 @@ def _changed_files(repo: Path, base_ref: str = "") -> list[str]:
|
|
|
3108
3363
|
manifest = _active_task_manifest(repo)
|
|
3109
3364
|
effective_base = base_ref or (_text(manifest.get("base_sha")) if manifest else "") or _default_base_ref(repo)
|
|
3110
3365
|
if effective_base:
|
|
3111
|
-
paths.extend(_git_lines(repo, ["git", "diff", "--name-only", "--diff-filter=ACDMRTUXB", f"{effective_base}...HEAD"]))
|
|
3112
|
-
paths.extend(_git_lines(repo, ["git", "diff", "--name-only", "--diff-filter=ACDMRTUXB"]))
|
|
3113
|
-
paths.extend(_git_lines(repo, ["git", "diff", "--cached", "--name-only", "--diff-filter=ACDMRTUXB"]))
|
|
3366
|
+
paths.extend(_git_lines(repo, ["git", "diff", "--no-renames", "--name-only", "--diff-filter=ACDMRTUXB", f"{effective_base}...HEAD"]))
|
|
3367
|
+
paths.extend(_git_lines(repo, ["git", "diff", "--no-renames", "--name-only", "--diff-filter=ACDMRTUXB"]))
|
|
3368
|
+
paths.extend(_git_lines(repo, ["git", "diff", "--cached", "--no-renames", "--name-only", "--diff-filter=ACDMRTUXB"]))
|
|
3114
3369
|
paths.extend(_git_lines(repo, ["git", "ls-files", "--others", "--exclude-standard"]))
|
|
3115
3370
|
return _unique_paths(paths)
|
|
3116
3371
|
|
|
@@ -3123,9 +3378,10 @@ def _commit_changed_files(repo: Path, ref: str) -> list[str]:
|
|
|
3123
3378
|
"diff-tree",
|
|
3124
3379
|
"--root",
|
|
3125
3380
|
"--no-commit-id",
|
|
3381
|
+
"--no-renames",
|
|
3126
3382
|
"--name-only",
|
|
3127
3383
|
"-r",
|
|
3128
|
-
"--diff-filter=
|
|
3384
|
+
"--diff-filter=ACDMRTUXB",
|
|
3129
3385
|
commit_ref,
|
|
3130
3386
|
],
|
|
3131
3387
|
cwd=repo,
|
|
@@ -5899,6 +6155,11 @@ def cmd_light_gate(args: argparse.Namespace) -> None:
|
|
|
5899
6155
|
light_gate_start = time.time()
|
|
5900
6156
|
monotonic_start = time.monotonic()
|
|
5901
6157
|
cfg = _load_cfg(repo)
|
|
6158
|
+
manifest = _active_task_manifest(repo)
|
|
6159
|
+
if manifest:
|
|
6160
|
+
manifest = _require_task_context(repo, cfg, _text(manifest.get("task_id")))
|
|
6161
|
+
_clear_final_gate_receipt(repo)
|
|
6162
|
+
before_fingerprint = _task_content_fingerprint(repo, cfg, manifest)
|
|
5902
6163
|
budget = _final_gate_budget(cfg)
|
|
5903
6164
|
deadline = monotonic_start + budget["total_seconds"]
|
|
5904
6165
|
requested_scope = _text(getattr(args, "scope", "")).lower()
|
|
@@ -5933,10 +6194,23 @@ def cmd_light_gate(args: argparse.Namespace) -> None:
|
|
|
5933
6194
|
_run_git_diff_check(repo, cfg)
|
|
5934
6195
|
if time.monotonic() > deadline:
|
|
5935
6196
|
raise APError(
|
|
5936
|
-
f"Final changed-scope gate
|
|
6197
|
+
f"Final changed-scope gate timed out after {budget['total_seconds']:.0f}s; "
|
|
5937
6198
|
"narrow validation.routes and keep slower checks explicit"
|
|
5938
6199
|
)
|
|
5939
6200
|
executed.append("diff_check")
|
|
6201
|
+
after_fingerprint = _task_content_fingerprint(repo, cfg, manifest)
|
|
6202
|
+
if after_fingerprint != before_fingerprint:
|
|
6203
|
+
_clear_final_gate_receipt(repo)
|
|
6204
|
+
raise APError("The final gate changed task content; inspect the diff before retrying.")
|
|
6205
|
+
if manifest:
|
|
6206
|
+
_record_final_gate_receipt(
|
|
6207
|
+
repo,
|
|
6208
|
+
cfg,
|
|
6209
|
+
manifest,
|
|
6210
|
+
plan,
|
|
6211
|
+
_text(getattr(args, "base", "")) or _text(manifest.get("base_sha")),
|
|
6212
|
+
executed,
|
|
6213
|
+
)
|
|
5940
6214
|
duration_s = time.time() - light_gate_start
|
|
5941
6215
|
_record_gate_profile(repo, cfg, "light_gate", "pass", duration_s, scope=selected_scope, detail=", ".join(executed))
|
|
5942
6216
|
_record_evidence(
|
|
@@ -7732,6 +8006,10 @@ def cmd_task_start(args: argparse.Namespace) -> None:
|
|
|
7732
8006
|
"created_at": _now_iso(),
|
|
7733
8007
|
"initial_untracked": [],
|
|
7734
8008
|
"owned_paths": owned_paths,
|
|
8009
|
+
"scope_revision": 1,
|
|
8010
|
+
"effective_profile": plan["profile"],
|
|
8011
|
+
"design_required": bool(plan["design_required"]),
|
|
8012
|
+
"scope_history": [],
|
|
7735
8013
|
"depends_on": depends_on,
|
|
7736
8014
|
"prerequisite_shas": prerequisite_shas,
|
|
7737
8015
|
"writer_lease": {
|
|
@@ -7813,6 +8091,10 @@ def cmd_task_start(args: argparse.Namespace) -> None:
|
|
|
7813
8091
|
"created_at": _now_iso(),
|
|
7814
8092
|
"initial_untracked": [],
|
|
7815
8093
|
"owned_paths": owned_paths,
|
|
8094
|
+
"scope_revision": 1,
|
|
8095
|
+
"effective_profile": plan["profile"],
|
|
8096
|
+
"design_required": bool(plan["design_required"]),
|
|
8097
|
+
"scope_history": [],
|
|
7816
8098
|
"depends_on": depends_on,
|
|
7817
8099
|
"prerequisite_shas": prerequisite_shas,
|
|
7818
8100
|
"writer_lease": {
|
|
@@ -7942,6 +8224,171 @@ def _task_lifecycle_context(repo: Path, cfg: dict, task_id: str) -> tuple[Path,
|
|
|
7942
8224
|
return repo, Path(_text(manifest.get("worktree_path"))).resolve(), manifest
|
|
7943
8225
|
|
|
7944
8226
|
|
|
8227
|
+
def cmd_task_scope_add(args: argparse.Namespace) -> None:
|
|
8228
|
+
repo = Path(args.repo).resolve()
|
|
8229
|
+
ensure_git_repo(repo)
|
|
8230
|
+
cfg = _load_cfg(repo)
|
|
8231
|
+
task_id = _validate_task_id(args.task_id)
|
|
8232
|
+
additions = sorted({_normalize_owned_path(item) for item in (args.owned_path or [])})
|
|
8233
|
+
if not additions:
|
|
8234
|
+
raise APError("task-scope-add requires at least one --owned-path.")
|
|
8235
|
+
control_repo, worktree, _ = _task_lifecycle_context(repo, cfg, task_id)
|
|
8236
|
+
timeout_s = float(_concurrency_cfg(cfg).get("lock_timeout_sec") or 30)
|
|
8237
|
+
result: dict = {}
|
|
8238
|
+
with (
|
|
8239
|
+
_repo_lock(control_repo, "integration", timeout_s=timeout_s),
|
|
8240
|
+
_repo_lock(control_repo, "task-registry", timeout_s=timeout_s),
|
|
8241
|
+
_repo_lock(control_repo, "direct-claim", timeout_s=timeout_s),
|
|
8242
|
+
_repo_lock(control_repo, f"task-{task_id}", timeout_s=timeout_s),
|
|
8243
|
+
):
|
|
8244
|
+
manifest = _load_task_manifest(control_repo, task_id)
|
|
8245
|
+
_require_current_writer(manifest, args)
|
|
8246
|
+
if int(manifest.get("schema") or 0) < 3:
|
|
8247
|
+
raise APError("task-scope-add requires a schema-3 task created by the current workflow.")
|
|
8248
|
+
if _text(manifest.get("state")) != "active":
|
|
8249
|
+
raise APError(
|
|
8250
|
+
f"Task {task_id} cannot expand scope in state={manifest.get('state')}; start a new task."
|
|
8251
|
+
)
|
|
8252
|
+
lease_generation = int((manifest.get("writer_lease") or {}).get("generation") or 0)
|
|
8253
|
+
requested_generation = getattr(args, "lease_generation", None)
|
|
8254
|
+
if requested_generation is not None and requested_generation != lease_generation:
|
|
8255
|
+
raise APError(
|
|
8256
|
+
f"Writer lease generation changed: expected={requested_generation}, current={lease_generation}."
|
|
8257
|
+
)
|
|
8258
|
+
if not worktree.exists():
|
|
8259
|
+
raise APError(f"Task worktree is missing: {worktree}")
|
|
8260
|
+
if _resolve_commit(worktree, "HEAD") != _text(manifest.get("base_sha")):
|
|
8261
|
+
raise APError("task-scope-add is allowed only before the task creates a commit.")
|
|
8262
|
+
if _text(manifest.get("last_commit")) or _text(manifest.get("remote_task_tip")):
|
|
8263
|
+
raise APError("task-scope-add cannot extend a task that already committed or pushed work.")
|
|
8264
|
+
|
|
8265
|
+
current = sorted({_normalize_owned_path(item) for item in manifest.get("owned_paths") or []})
|
|
8266
|
+
new_paths = [path for path in additions if not _path_is_owned(path, current)]
|
|
8267
|
+
if not new_paths:
|
|
8268
|
+
result = {
|
|
8269
|
+
"task_id": task_id,
|
|
8270
|
+
"status": "noop",
|
|
8271
|
+
"scope_revision": int(manifest.get("scope_revision") or 1),
|
|
8272
|
+
"owned_paths": current,
|
|
8273
|
+
}
|
|
8274
|
+
else:
|
|
8275
|
+
proposed = sorted(set(current) | set(new_paths))
|
|
8276
|
+
for claim in _active_direct_claims(control_repo):
|
|
8277
|
+
claim_paths = list(claim.get("owned_paths") or [])
|
|
8278
|
+
if _owned_paths_overlap(proposed, claim_paths):
|
|
8279
|
+
raise APError(
|
|
8280
|
+
"Expanded scope overlaps active direct claim held by "
|
|
8281
|
+
f"{_text(claim.get('owner')) or '(unknown)'}: "
|
|
8282
|
+
+ ", ".join(claim_paths)
|
|
8283
|
+
)
|
|
8284
|
+
registry_dir = _task_state_root(control_repo) / "tasks"
|
|
8285
|
+
for path in sorted(registry_dir.glob("*.json")) if registry_dir.exists() else []:
|
|
8286
|
+
other = _read_json_object(path) or {}
|
|
8287
|
+
if _text(other.get("task_id")) == task_id:
|
|
8288
|
+
continue
|
|
8289
|
+
if _text(other.get("state")) in {"", "integrated", "cleanup-pending"}:
|
|
8290
|
+
continue
|
|
8291
|
+
other_owned = other.get("owned_paths") or []
|
|
8292
|
+
if isinstance(other_owned, list) and _owned_paths_overlap(proposed, other_owned):
|
|
8293
|
+
raise APError(
|
|
8294
|
+
f"Expanded scope overlaps active task {_text(other.get('task_id')) or path.stem}: "
|
|
8295
|
+
+ ", ".join(other_owned)
|
|
8296
|
+
)
|
|
8297
|
+
|
|
8298
|
+
worktree_cfg = _load_cfg(worktree)
|
|
8299
|
+
existing_unowned = _task_unowned_paths(worktree, worktree_cfg, manifest)
|
|
8300
|
+
implicit_adoptions = sorted(path for path in existing_unowned if path not in set(new_paths))
|
|
8301
|
+
if implicit_adoptions:
|
|
8302
|
+
raise APError(
|
|
8303
|
+
"Existing unowned changes must be added as exact --owned-path values before scope expansion:\n- "
|
|
8304
|
+
+ "\n- ".join(implicit_adoptions)
|
|
8305
|
+
)
|
|
8306
|
+
changed_paths = _task_changed_paths_from_base(
|
|
8307
|
+
worktree,
|
|
8308
|
+
_text(manifest.get("base_sha")),
|
|
8309
|
+
)
|
|
8310
|
+
plan = _resolve_execution_plan(
|
|
8311
|
+
worktree_cfg,
|
|
8312
|
+
worktree,
|
|
8313
|
+
changed_paths=changed_paths,
|
|
8314
|
+
planned_paths=proposed,
|
|
8315
|
+
intent=_text(getattr(args, "intent", "")),
|
|
8316
|
+
requested_task_kind="change",
|
|
8317
|
+
)
|
|
8318
|
+
old_profile = _text(manifest.get("effective_profile")) or (
|
|
8319
|
+
"high-risk" if bool(manifest.get("review_required")) else "standard"
|
|
8320
|
+
)
|
|
8321
|
+
planned_profile = _text(plan.get("profile")) or "standard"
|
|
8322
|
+
effective_profile = (
|
|
8323
|
+
planned_profile
|
|
8324
|
+
if _PROFILE_RANK[planned_profile] > _PROFILE_RANK[old_profile]
|
|
8325
|
+
else old_profile
|
|
8326
|
+
)
|
|
8327
|
+
old_manifest = json.loads(json.dumps(manifest))
|
|
8328
|
+
revision = int(manifest.get("scope_revision") or 1) + 1
|
|
8329
|
+
manifest["owned_paths"] = proposed
|
|
8330
|
+
manifest["scope_revision"] = revision
|
|
8331
|
+
manifest["effective_profile"] = effective_profile
|
|
8332
|
+
manifest["review_required"] = bool(
|
|
8333
|
+
manifest.get("review_required")
|
|
8334
|
+
or plan.get("review_required")
|
|
8335
|
+
or bool(getattr(args, "review_required", False))
|
|
8336
|
+
)
|
|
8337
|
+
manifest["design_required"] = bool(
|
|
8338
|
+
manifest.get("design_required") or plan.get("design_required")
|
|
8339
|
+
)
|
|
8340
|
+
manifest["claimed_paths"] = []
|
|
8341
|
+
history = list(manifest.get("scope_history") or [])
|
|
8342
|
+
history.append(
|
|
8343
|
+
{
|
|
8344
|
+
"revision": revision,
|
|
8345
|
+
"added_paths": new_paths,
|
|
8346
|
+
"adopted_dirty_paths": existing_unowned,
|
|
8347
|
+
"actor": _text(getattr(args, "writer", ""))
|
|
8348
|
+
or _text(os.environ.get("CODEX_THREAD_ID")),
|
|
8349
|
+
"updated_at": _now_iso(),
|
|
8350
|
+
"previous_profile": old_profile,
|
|
8351
|
+
"effective_profile": effective_profile,
|
|
8352
|
+
}
|
|
8353
|
+
)
|
|
8354
|
+
manifest["scope_history"] = history
|
|
8355
|
+
_invalidate_task_review(manifest, "task scope expanded; review and final gate must run again")
|
|
8356
|
+
_clear_final_gate_receipt(worktree)
|
|
8357
|
+
try:
|
|
8358
|
+
_save_task_manifest(control_repo, manifest, strict_worktree=True)
|
|
8359
|
+
except Exception:
|
|
8360
|
+
_save_task_manifest(control_repo, old_manifest)
|
|
8361
|
+
raise
|
|
8362
|
+
registered = _load_task_manifest(control_repo, task_id)
|
|
8363
|
+
mirrored = _read_json_object(_worktree_manifest_path(worktree)) or {}
|
|
8364
|
+
for field in ("task_uuid", "scope_revision", "owned_paths", "review_required"):
|
|
8365
|
+
if registered.get(field) != mirrored.get(field):
|
|
8366
|
+
raise APError(f"Task scope manifest synchronization failed for field: {field}")
|
|
8367
|
+
result = {
|
|
8368
|
+
"task_id": task_id,
|
|
8369
|
+
"status": "expanded",
|
|
8370
|
+
"scope_revision": revision,
|
|
8371
|
+
"owned_paths": proposed,
|
|
8372
|
+
"added_paths": new_paths,
|
|
8373
|
+
"effective_profile": effective_profile,
|
|
8374
|
+
"review_required": manifest["review_required"],
|
|
8375
|
+
"design_required": manifest["design_required"],
|
|
8376
|
+
}
|
|
8377
|
+
if bool(getattr(args, "json", False)):
|
|
8378
|
+
print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
8379
|
+
elif result["status"] == "noop":
|
|
8380
|
+
print(
|
|
8381
|
+
f"[task-scope-add] NOOP task={task_id} "
|
|
8382
|
+
f"scope_revision={result['scope_revision']}"
|
|
8383
|
+
)
|
|
8384
|
+
else:
|
|
8385
|
+
print(
|
|
8386
|
+
f"[task-scope-add] OK task={task_id} scope_revision={result['scope_revision']} "
|
|
8387
|
+
f"profile={result['effective_profile']} review_required="
|
|
8388
|
+
f"{str(result['review_required']).lower()} added={','.join(result['added_paths'])}"
|
|
8389
|
+
)
|
|
8390
|
+
|
|
8391
|
+
|
|
7945
8392
|
def cmd_task_review(args: argparse.Namespace) -> None:
|
|
7946
8393
|
repo = Path(args.repo).resolve()
|
|
7947
8394
|
ensure_git_repo(repo)
|
|
@@ -8266,11 +8713,17 @@ def cmd_task_finish(args: argparse.Namespace) -> None:
|
|
|
8266
8713
|
task_id = _validate_task_id(args.task_id)
|
|
8267
8714
|
manifest = _load_task_manifest(repo, task_id)
|
|
8268
8715
|
if _text(manifest.get("execution_mode")).lower() == "direct":
|
|
8269
|
-
|
|
8270
|
-
|
|
8271
|
-
|
|
8272
|
-
|
|
8273
|
-
|
|
8716
|
+
timeout_s = float(_concurrency_cfg(cfg).get("lock_timeout_sec") or 30)
|
|
8717
|
+
with (
|
|
8718
|
+
_repo_lock(repo, "integration", timeout_s=timeout_s),
|
|
8719
|
+
_repo_lock(repo, f"task-{task_id}", timeout_s=timeout_s),
|
|
8720
|
+
):
|
|
8721
|
+
manifest = _load_task_manifest(repo, task_id)
|
|
8722
|
+
if repo.resolve() != Path(_text(manifest.get("worktree_path"))).resolve():
|
|
8723
|
+
raise APError("Run task-finish for a direct task from its current checkout.")
|
|
8724
|
+
if _task_commit_paths(repo) or _resolve_commit(repo, "HEAD") != _text(manifest.get("base_sha")):
|
|
8725
|
+
raise APError("Direct task still has changes or commits; use commit-push instead of task-finish.")
|
|
8726
|
+
_clear_direct_task(repo, manifest)
|
|
8274
8727
|
print(f"[task-finish] OK task={task_id} execution_mode=direct no temporary branch existed")
|
|
8275
8728
|
return
|
|
8276
8729
|
_require_control_checkout(repo, manifest)
|
|
@@ -8675,6 +9128,7 @@ def _cmd_direct_commit_push_locked(
|
|
|
8675
9128
|
) -> None:
|
|
8676
9129
|
_require_current_writer(manifest, args)
|
|
8677
9130
|
_require_dependencies(repo, manifest, _text(manifest.get("base_sha")))
|
|
9131
|
+
_reconcile_task_risk(repo, cfg, manifest)
|
|
8678
9132
|
_require_approved_review(repo, cfg, manifest)
|
|
8679
9133
|
branch = _current_branch(repo)
|
|
8680
9134
|
target = _text(manifest.get("target_branch"))
|
|
@@ -8696,6 +9150,8 @@ def _cmd_direct_commit_push_locked(
|
|
|
8696
9150
|
commit_sha = pending_commit
|
|
8697
9151
|
plan = _resolve_execution_plan(cfg, repo, base_ref=_text(manifest.get("base_sha")))
|
|
8698
9152
|
else:
|
|
9153
|
+
task_paths = _task_staging_paths(repo, cfg, manifest)
|
|
9154
|
+
_preflight_exact_paths(repo, task_paths)
|
|
8699
9155
|
cmd_doctor(
|
|
8700
9156
|
argparse.Namespace(
|
|
8701
9157
|
repo=str(repo),
|
|
@@ -8711,23 +9167,36 @@ def _cmd_direct_commit_push_locked(
|
|
|
8711
9167
|
base_ref=_text(manifest.get("base_sha")),
|
|
8712
9168
|
)
|
|
8713
9169
|
before_gate = _task_content_fingerprint(repo, cfg, manifest)
|
|
8714
|
-
|
|
8715
|
-
|
|
8716
|
-
|
|
8717
|
-
|
|
8718
|
-
|
|
8719
|
-
|
|
8720
|
-
base=_text(manifest.get("base_sha")),
|
|
8721
|
-
explain=False,
|
|
8722
|
-
)
|
|
9170
|
+
receipt = _reuse_final_gate_receipt(
|
|
9171
|
+
repo,
|
|
9172
|
+
cfg,
|
|
9173
|
+
manifest,
|
|
9174
|
+
plan,
|
|
9175
|
+
_text(manifest.get("base_sha")),
|
|
8723
9176
|
)
|
|
9177
|
+
if receipt:
|
|
9178
|
+
print(
|
|
9179
|
+
"[light-gate] REUSED task="
|
|
9180
|
+
f"{manifest['task_id']} passed_at={receipt.get('passed_at')}"
|
|
9181
|
+
)
|
|
9182
|
+
else:
|
|
9183
|
+
cmd_light_gate(
|
|
9184
|
+
argparse.Namespace(
|
|
9185
|
+
repo=str(repo),
|
|
9186
|
+
scope="changed",
|
|
9187
|
+
profile=plan["profile"],
|
|
9188
|
+
mode="dev",
|
|
9189
|
+
base=_text(manifest.get("base_sha")),
|
|
9190
|
+
explain=False,
|
|
9191
|
+
)
|
|
9192
|
+
)
|
|
8724
9193
|
after_gate = _task_content_fingerprint(repo, cfg, manifest)
|
|
8725
9194
|
if after_gate != before_gate:
|
|
8726
9195
|
raise APError("The final gate changed direct-task files; inspect them and retry commit-push.")
|
|
8727
9196
|
manifest = _require_task_context(repo, cfg, args.task_id)
|
|
8728
9197
|
_require_current_writer(manifest, args)
|
|
8729
9198
|
_require_approved_review(repo, cfg, manifest)
|
|
8730
|
-
task_paths =
|
|
9199
|
+
task_paths = _task_staging_paths(repo, cfg, manifest)
|
|
8731
9200
|
staged = _stage_exact_paths(repo, task_paths)
|
|
8732
9201
|
if not staged:
|
|
8733
9202
|
_clear_direct_task(repo, manifest)
|
|
@@ -8736,6 +9205,13 @@ def _cmd_direct_commit_push_locked(
|
|
|
8736
9205
|
unstaged = _unstaged_task_paths(repo)
|
|
8737
9206
|
if unstaged:
|
|
8738
9207
|
raise APError("Direct-task files changed while staging; refusing to commit:\n- " + "\n- ".join(unstaged))
|
|
9208
|
+
_extend_final_gate_receipt(
|
|
9209
|
+
repo,
|
|
9210
|
+
cfg,
|
|
9211
|
+
manifest,
|
|
9212
|
+
plan,
|
|
9213
|
+
_text(manifest.get("base_sha")),
|
|
9214
|
+
)
|
|
8739
9215
|
commit_sha = _commit_exact_index(repo, args.msg)
|
|
8740
9216
|
manifest["state"] = "push-pending"
|
|
8741
9217
|
manifest["last_commit"] = commit_sha
|
|
@@ -8783,7 +9259,23 @@ def _cmd_commit_push_locked(
|
|
|
8783
9259
|
_save_task_manifest(repo, manifest)
|
|
8784
9260
|
_require_current_writer(manifest, args)
|
|
8785
9261
|
_require_dependencies(repo, manifest, _text(manifest.get("base_sha")))
|
|
9262
|
+
_reconcile_task_risk(repo, cfg, manifest)
|
|
8786
9263
|
_require_approved_review(repo, cfg, manifest)
|
|
9264
|
+
working_paths = _task_commit_paths(repo)
|
|
9265
|
+
head = _resolve_commit(repo, "HEAD")
|
|
9266
|
+
pending_commit = _text(manifest.get("last_commit"))
|
|
9267
|
+
if pending_commit and pending_commit == head and not working_paths:
|
|
9268
|
+
plan = _resolve_execution_plan(cfg, repo, base_ref=_text(manifest.get("base_sha")))
|
|
9269
|
+
_push_current_task(repo, manifest, pending_commit)
|
|
9270
|
+
print(
|
|
9271
|
+
f"[commit-push] OK - profile={plan['profile']} mode={plan['effective_mode']} "
|
|
9272
|
+
f"scope={plan['selected_scope']} commit={pending_commit}"
|
|
9273
|
+
)
|
|
9274
|
+
return
|
|
9275
|
+
protected = set(manifest.get("initial_untracked") or [])
|
|
9276
|
+
_cleanup_generated_noise(repo, protected_paths=protected)
|
|
9277
|
+
task_paths = _task_staging_paths(repo, cfg, manifest)
|
|
9278
|
+
_preflight_exact_paths(repo, task_paths)
|
|
8787
9279
|
cmd_doctor(
|
|
8788
9280
|
argparse.Namespace(
|
|
8789
9281
|
repo=str(repo),
|
|
@@ -8807,16 +9299,23 @@ def _cmd_commit_push_locked(
|
|
|
8807
9299
|
|
|
8808
9300
|
msg = args.msg
|
|
8809
9301
|
before_gate = _task_content_fingerprint(repo, cfg, manifest)
|
|
8810
|
-
|
|
8811
|
-
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
|
|
8815
|
-
|
|
8816
|
-
|
|
8817
|
-
|
|
9302
|
+
receipt = _reuse_final_gate_receipt(repo, cfg, manifest, plan, base_ref)
|
|
9303
|
+
if receipt:
|
|
9304
|
+
print(
|
|
9305
|
+
"[light-gate] REUSED task="
|
|
9306
|
+
f"{manifest['task_id']} passed_at={receipt.get('passed_at')}"
|
|
9307
|
+
)
|
|
9308
|
+
else:
|
|
9309
|
+
cmd_light_gate(
|
|
9310
|
+
argparse.Namespace(
|
|
9311
|
+
repo=str(repo),
|
|
9312
|
+
scope="changed",
|
|
9313
|
+
profile=plan["profile"],
|
|
9314
|
+
mode="dev",
|
|
9315
|
+
base=base_ref,
|
|
9316
|
+
explain=False,
|
|
9317
|
+
)
|
|
8818
9318
|
)
|
|
8819
|
-
)
|
|
8820
9319
|
|
|
8821
9320
|
after_gate = _task_content_fingerprint(repo, cfg, manifest)
|
|
8822
9321
|
if after_gate != before_gate:
|
|
@@ -8834,15 +9333,13 @@ def _cmd_commit_push_locked(
|
|
|
8834
9333
|
"no files were staged or restored."
|
|
8835
9334
|
)
|
|
8836
9335
|
|
|
8837
|
-
protected = set(manifest.get("initial_untracked") or [])
|
|
8838
|
-
_cleanup_generated_noise(repo, protected_paths=protected)
|
|
8839
9336
|
pre_stage_fingerprint = _task_content_fingerprint(repo, cfg, manifest)
|
|
8840
9337
|
manifest = _require_task_context(repo, cfg, args.task_id)
|
|
8841
9338
|
_require_current_writer(manifest, args)
|
|
8842
9339
|
_require_approved_review(repo, cfg, manifest)
|
|
8843
9340
|
if _task_content_fingerprint(repo, cfg, manifest) != pre_stage_fingerprint:
|
|
8844
9341
|
raise APError("Task-owned files changed immediately before staging; refusing to commit.")
|
|
8845
|
-
task_paths =
|
|
9342
|
+
task_paths = _task_staging_paths(repo, cfg, manifest)
|
|
8846
9343
|
staged = _stage_exact_paths(repo, task_paths)
|
|
8847
9344
|
if not staged:
|
|
8848
9345
|
raise APError("Nothing to commit.")
|
|
@@ -8852,8 +9349,12 @@ def _cmd_commit_push_locked(
|
|
|
8852
9349
|
"Task-owned files changed while staging; refusing to commit:\n- " + "\n- ".join(unstaged)
|
|
8853
9350
|
)
|
|
8854
9351
|
manifest = _require_task_context(repo, cfg, args.task_id)
|
|
9352
|
+
_extend_final_gate_receipt(repo, cfg, manifest, plan, base_ref)
|
|
8855
9353
|
|
|
8856
9354
|
committed_sha = _commit_exact_index(repo, msg)
|
|
9355
|
+
manifest["state"] = "push-pending"
|
|
9356
|
+
manifest["last_commit"] = committed_sha
|
|
9357
|
+
_save_task_manifest(repo, manifest)
|
|
8857
9358
|
_push_current_task(repo, manifest, committed_sha)
|
|
8858
9359
|
print(f"[commit-push] OK - profile={plan['profile']} mode={mode} scope={plan['selected_scope']}")
|
|
8859
9360
|
|
|
@@ -8868,6 +9369,8 @@ def cmd_commit_push(args: argparse.Namespace) -> None:
|
|
|
8868
9369
|
lock_name = f"task-{_validate_task_id(args.task_id)}"
|
|
8869
9370
|
timeout_s = float(_concurrency_cfg(cfg).get("lock_timeout_sec") or 30)
|
|
8870
9371
|
with _repo_lock(repo, lock_name, timeout_s=timeout_s):
|
|
9372
|
+
manifest = _require_task_context(repo, cfg, args.task_id)
|
|
9373
|
+
_require_current_writer(manifest, args)
|
|
8871
9374
|
_cmd_commit_push_locked(args, repo, cfg, manifest)
|
|
8872
9375
|
|
|
8873
9376
|
|
|
@@ -9076,6 +9579,16 @@ def main(argv: Optional[List[str]] = None) -> int:
|
|
|
9076
9579
|
s.add_argument("--json", action="store_true")
|
|
9077
9580
|
s.set_defaults(func=cmd_task_status)
|
|
9078
9581
|
|
|
9582
|
+
s = sp.add_parser("task-scope-add")
|
|
9583
|
+
s.add_argument("task_id")
|
|
9584
|
+
s.add_argument("--owned-path", action="append", required=True)
|
|
9585
|
+
s.add_argument("--writer")
|
|
9586
|
+
s.add_argument("--lease-generation", type=int)
|
|
9587
|
+
s.add_argument("--intent")
|
|
9588
|
+
s.add_argument("--review-required", action="store_true")
|
|
9589
|
+
s.add_argument("--json", action="store_true")
|
|
9590
|
+
s.set_defaults(func=cmd_task_scope_add)
|
|
9591
|
+
|
|
9079
9592
|
s = sp.add_parser("task-submodule-sync")
|
|
9080
9593
|
s.add_argument("task_id")
|
|
9081
9594
|
s.set_defaults(func=cmd_task_submodule_sync)
|